Directly construct a primary resource. Normally a primary resource is obtained via the resource or resources accessors while traversing a document structure.
IdMismatchError when the optional id argument does not match the id present in rawData
SchemaError when rawData does not look like a JSON:API resource object
The JSON:API resource object from which to construct this primary resource
The parent document that contains this primary resource
The type of this resource
The context to use to fetch related documents
Optional id: stringThe id of this resource
Protected Readonly documentThe parent document that contains this resource
Readonly idThe id of this resource
Private Readonly pReadonly 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 getGenerated using TypeDoc
A resource contained in the top level
datamember of a Document.Always constructed non-lazily from raw JSON:API data. Normally this is done automatically when accessing the resource or resources accessors.
Example
Remarks
Methods and accessors marked as
memoizedare only executed once per instance (the first time they are called) and return a cached result on subsequent calls.