Description
Hi,
I read the discussion about the roadmap in #19 so I'm going to create a new issue to have some space to discuss a topic that needs some more refactoring. I'm currently using this package in a small opensource client. The client makes use of HATEOAS and thus needs support for the top level link
attribute in json:api.
Currently this package only handles the data
attribute. But there is a RFC for ember-data that proposes how to implement support for more general json:api documents. If I got the idea of the RFC adapted to this package right, then you should be able to make a request to the API and get something like a DocumentModel
(instead of a JsonApiModel
) as response. The DocumentModel
gives you access to all the top level attributes of a json:api document using the following getter methods:
data(): JsonApiModel
(existing JsonApiModel)links(): LinksModel
(new model)meta(): MetaModel
(new model)
A basic query then would look like this:
this.datastoreService.query(User, {
page: { size: 10, number: 1},
include: 'roles'
}).subscribe(
(document: DocumentModel) => {
// access to the JsonApiModel
this.users = document.data();
// access to the top level links attribute
this.links = document.links();
// access to the json:api document in general
this.usersDocument = document
}
);
The response part is worth discussing. I think in the RFC they won't return a DocumentModel
like I propose. Instead they return a JsonApiModel
that has an getter method document()
to access the top level attributes. Thus the programming API does not change. But this approach has a big disadvantage when adopting the RFC to this package. Because if you want to access the top level attributes of an empty collection this package will give you just an empty array as response. This is why I would propose to return a general DocumentModel
instead of JsonApiModel
or Array<JsonApiModel>
.
All other parts of the package should not change. This means if you do peek()
then you should get an JsonApiModel
on which you can call document()
to get the coresponding document including all the top level attributes like links()
and meta()
.
For testing this approach I did a very basic implementation in my jsonapi-document
branch and also adopted this changes into the client:
I'm going to further test this implementation next week but I just wanted to hook into the discussion about the roadmap with this proposal early so that you can consider this feature in further plans.