Abstract
Private
Readonly
contextThe context to use to fetch related documents
Protected
Readonly
documentThe parent document that contains this resource
Readonly
idThe id of this resource
Readonly
typeThe resource type
Object containing all attributes of this resource
Object containing all Links defined by this resource
https://jsonapi.org/format/1.0/#document-links
Object containing all meta data of this resource
The raw JSON:API data of this resource
Proxy providing all Documents reachable via related
links in relationships.
For this JSON:API document
{
"data": {
"type": "articles",
"id": "1",
"relationships": {
"author": {
"links": {"related": "http://example.com/people/1"}
},
"reviewer": {
"links": {"related": "http://example.com/people/12"}
}
}
}
}
calling relatedDocuments
on the primary articles resource will give you access to the following data:
{
author: Document(...),
reviewer: Document(...)
}
As this is only a proxy object, calling relatedDocuments
does not yet fetch any related documents.
Only when accessing a specific related document (e.g. calling article.relatedDocuments['author']
) is the
new document actually requested from the server.
Proxy providing all singular Resources reachable via relationships from this resource.
For this JSON:API document
{
"data": {
"type": "articles",
"id": "1",
"relationships": {
"author": {
"data": {"type":"people", "id":"1"}
},
"reviewer": {
"data": {"type":"people", "id":"12"}
}
}
},
"included": [...]
}
calling relatedResource
on the primary articles resource will give you access to the following data:
{
author: RelatedResource(...),
reviewer: RelatedResource(...)
}
This accessor is a shortcut so that you do not have to go through relationships
manually every time.
Writing
const author = await article.relatedResource['author'];
is equivalent to
const author = await article.relationships['author'].resource();
As this shortcut uses the resource method, it prefers resource linkage (i.e. id/type pairs in data
)
to related
links should both be present in the relationship. You can use the resourceFromRelatedLink
method if you need to fetch a related resource via link instead of resource linkage.
As this is only a proxy object, calling relatedResource
will not yet construct any RelatedResource
instances. Only when accessing a specific related resource (e.g. calling article.relatedResource['author']
)
is the new resource actually constructed.
Proxy providing all multiple Resources reachable via relationships from this resource.
For this JSON:API document
{
"data": {
"type": "articles",
"id": "1",
"relationships": {
"comments": {
"data": [{"type":"comments", "id":"1"}, {"type":"comments", "id":"2"}]
},
"ratings": {
"data": [{"type":"ratings", "id":"1"}, {"type":"ratings", "id":"2"}]
}
}
},
"included": [...]
}
calling relatedResources
on the primary articles resource will give you access to the following data:
{
comments: [
RelatedResource(...),
RelatedResource(...)
],
ratings: [
RelatedResource(...),
RelatedResource(...)
]
}
This accessor is a shortcut so that you do not have to go through relationships
manually every time.
Writing
const comments = await article.relatedResources['comments'];
is equivalent to
const comments = await article.relationships['comments'].resources();
As this shortcut uses the resources method, it prefers resource linkage (i.e. id/type pairs in data
)
to related
links should both be present in the relationship. You can use the resourcesFromRelatedLink
method if you need to fetch related resources via link instead of resource linkage.
As this is only a proxy object, calling relatedResources
will not yet construct any RelatedResource
instances. Only when accessing a specific related resource (e.g. calling article.relatedResources['comments']
)
are the new resources actually constructed.
Object containing all Relationships defined by this resource
https://jsonapi.org/format/1.0/#document-resource-object-relationships
Protected
Abstract
getGenerated using TypeDoc
This class represents a JSON:API resource object and is used as base class for PrimaryResources and RelatedResources.
The abstract getData method is implemented in the derived classes to specify how the raw JSON:API data is obtained.
Methods and accessors marked as
memoized
are only executed once per instance (the first time they are called) and return a cached result on subsequent calls.See
https://jsonapi.org/format/1.0/#document-resource-objects