import { Spec } from './jsonapiSpec'; export { Spec }; /** * This is the main module of Grivet. * * It contains the {@link Document}, {@link Resource} and {@link Relationship} classes that * perform most of the work interpreting a JSON:API structure. * * Normally you would start by creating a {@link Document} from existing JSON:API data or using the {@link Document.fromURL} * method to fetch data from a server. Then you can examine the resources in that document ({@link Document.resource} * or {@link Document.resources}) and traverse to other related resources ({@link Resource.relatedResource} or * {@link Resource.relatedResources}). * * You have to provide an implementation of the {@link Context} interface to specify how documents should be fetched from * URLs. The documentation of the {@link Context} interface shows several possible implementations (e.g. using the Angular http client * or Axios). * * Based on version 1.0 of JSON:API. */ export declare namespace JsonApi { /** Thrown when there is mismatch between the expected resource count (one or many) and the actual resource count */ export class CardinalityError extends Error { constructor(message?: string); } /** Thrown when an explicitly provided id does not match the id received from the server */ export class IdMismatchError extends Error { constructor(message?: string); } /** * Implement this interface to define how a {@link Spec.JsonApiDocument} (the JSON:API raw data) is fetched from a given URL. * * [[include:guides/context.md]] */ export interface Context { /** * Should return a `Promise` resolving to the JSON:API document for the given `url` */ getDocument(url: URL): Promise; /** * Optional: like {@link getDocument}, but also returns the URL the document was received from, e.g. after redirects * (`Response.url` of `fetch`). If implemented, it is used instead of `getDocument`, and relative links are resolved * against that URL (see {@link Document.effectiveURL}). */ getDocumentWithURL?(url: URL): Promise; } /** A JSON:API document and the URL it was received from, see {@link Context.getDocumentWithURL} */ export interface DocumentWithURL { /** The JSON:API document */ rawData: Spec.JsonApiDocument; /** The absolute URL the document was received from, e.g. after redirects. `undefined` if unknown. */ url?: URL; } /** List of fields that should be fetched from the server */ export type FieldNames = string[]; /** Mapping from resource type to sparse fields */ export type SparseFields = { [resourceType: string]: FieldNames; }; /** Value of a query parameter, booleans are sent as `true`/`false` */ export type QueryParamValue = string | number | boolean; /** Members of the [`page` query parameter family](https://jsonapi.org/format/1.0/#fetching-pagination), e.g. `{ size: 50 }` for `page[size]=50` */ export type PageParams = { [member: string]: QueryParamValue; }; /** Thrown when a collection is paged although `allowPaging: false` was requested */ export class PagingNotAllowedError extends Error { constructor(message?: string); } /** * Builder for JSON:API query parameters. * * Standard JSON:API members (`include`, `fields[type]`, `sort`, `filter[...]`, `page[...]`) are first-class, other * parameters can be added with {@link custom}. The builder methods change this instance and return it for chaining, * {@link merge} and {@link copy} return a new instance. * * [[include:guides/queryParams.md]] */ export class QueryParams { private pairs; /** @param pairs Initial parameters as `[key, value]` pairs */ constructor(pairs?: ReadonlyArray<[string, QueryParamValue]>); /** * Adds paths to `include=path1,path2` (without duplicates, in order). * @param replace Replace the include list instead of merging. `include([''], true)` requests `include=` explicitly. */ include(paths: string[], replace?: boolean): this; /** * Adds field names to the [sparse fieldset](https://jsonapi.org/format/1.0/#fetching-sparse-fieldsets) `fields[type]=a,b`. * @param replace Replace the field list of this type instead of merging. `fields(type, [''], true)` requests `fields[type]=` explicitly. */ fields(resourceType: string, fieldNames: FieldNames, replace?: boolean): this; /** * Adds [sort fields](https://jsonapi.org/format/1.0/#fetching-sorting) to `sort=-created,title`, a `-` prefix sorts descending. * @param replace Replace the sort list instead of merging */ sort(fields: string[], replace?: boolean): this; /** * Adds `filter[key]=value`. The filter syntax depends on the server. * @param key A string, which may contain brackets itself (`'simple][primary][id__in'`), or a path of segments: * `filter(['simple', 'primary', 'id__in'], '1,2')` adds `filter[simple][primary][id__in]=1,2`. * @throws TypeError if a path is empty or a segment is not a non-empty string without brackets */ filter(key: string | ReadonlyArray, value: QueryParamValue): this; /** Adds `page[key]=value`. The page members depend on the server. */ page(key: string, value: QueryParamValue): this; /** Adds `key=value` as given */ custom(key: string, value: QueryParamValue): this; /** A new instance with the parameters of this one followed by those of `other` */ merge(other: QueryParams): QueryParams; /** An independent copy */ copy(): QueryParams; /** `true` if there are no parameters */ get isEmpty(): boolean; /** The parameters as `[key, value]` pairs */ entries(): [string, string][]; /** A copy of `url` with these parameters appended to its query, existing parameters are kept */ applyTo(url: URL): URL; /** @hidden */ private mergeList; } /** * Options for fetching the `related` link of a {@link Relationship} * * [[include:guides/paging.md]] */ export interface RelatedDocumentOptions { /** Sparse fields per type, replacing those of the referring document for these types */ sparseFields?: SparseFields; /** [Sort fields](https://jsonapi.org/format/1.0/#fetching-sorting), a `-` prefix sorts descending */ sort?: string[]; /** Members of the `page` query parameter family for the first request, e.g. `{ size: 50 }` */ page?: PageParams; /** * A non-empty `page` replaces all `page` parameters of the link (default). With `false`, it only overrides * matching members and keeps others, e.g. a cursor or starting page. */ replacePage?: boolean; } /** * Options for resolving the resources of a to-many {@link Relationship} * * [[include:guides/paging.md]] */ export interface RelatedResourcesOptions extends RelatedDocumentOptions { /** With `false`, a paged response (one with a `next` link) throws a {@link PagingNotAllowedError}. Default `true`. */ allowPaging?: boolean; /** Follow the `next` links and return the resources of all pages. Defaults to `allowPaging`. */ followPaging?: boolean; } /** * This class represents a [JSON:API resource object](https://jsonapi.org/format/1.0/#document-resource-objects) * and is used as base class for {@link PrimaryResource}s and {@link RelatedResource}s. * * The abstract {@link 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 */ export abstract class Resource { protected readonly document: Document; readonly id: string; readonly type: string; private readonly context; /** * @param document The parent document that contains this resource * @param id The id of this resource * @param type The resource type * @param context The context to use to fetch related documents */ constructor(document: Document, id: string, type: string, context: Context); protected abstract getData(): Spec.ResourceObject; /** * The raw JSON:API data of this resource * @memoized */ get rawData(): Spec.ResourceObject; /** * Object containing all [attributes](https://jsonapi.org/format/1.0/#document-resource-object-attributes) of this resource */ get attributes(): Spec.AttributesObject | undefined; /** * Object containing all {@link Relationship}s defined by this resource * @see https://jsonapi.org/format/1.0/#document-resource-object-relationships * @memoized */ get relationships(): Relationships; /** * Object containing all {@link Link}s defined by this resource * @see https://jsonapi.org/format/1.0/#document-links * @memoized */ get links(): Links; /** * Object containing all entries inside `links` of `meta` interpreted as * JSON:API Link (either string or link object) * @memoized */ get metaLinks(): Links; /** * Object containing all [meta data](https://jsonapi.org/format/1.0/#document-meta) of this resource * @memoized */ get meta(): Spec.MetaObject | undefined; /** * Self-link defined in the `links` member */ get selfLink(): Link | undefined; /** * Proxy providing all multiple {@link Resource}s reachable via relationships from this resource. * * @example * For this JSON:API document * * ```json * { * "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: * * ```typescript * { * 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 * * ```typescript * const comments = await article.relatedResources['comments']; * ``` * * is equivalent to * * ```typescript * const comments = await article.relationships['comments'].resources(); * ``` * * @remarks * As this shortcut uses the {@link Relationship.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 {@link Relationship.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 {@link RelatedResource} * instances. Only when accessing a specific related resource (e.g. calling `article.relatedResources['comments']`) * are the new resources actually constructed. */ get relatedResources(): RelationshipToResources; /** * Proxy providing all singular {@link Resource}s reachable via relationships from this resource. * * @example * For this JSON:API document * * ```json * { * "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: * * ```typescript * { * author: RelatedResource(...), * reviewer: RelatedResource(...) * } * ``` * * This accessor is a shortcut so that you do not have to go through `relationships` manually every time. * Writing * * ```typescript * const author = await article.relatedResource['author']; * ``` * * is equivalent to * * ```typescript * const author = await article.relationships['author'].resource(); * ``` * * @remarks * As this shortcut uses the {@link Relationship.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 {@link Relationship.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 {@link RelatedResource} * instances. Only when accessing a specific related resource (e.g. calling `article.relatedResource['author']`) * is the new resource actually constructed. */ get relatedResource(): RelationshipToResource; /** * Proxy providing all {@link Document}s reachable via `related` links in relationships. * * @example * For this JSON:API document * * ```json * { * "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: * * ```typescript * { * author: Document(...), * reviewer: Document(...) * } * ``` * * @remarks * 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. */ get relatedDocuments(): RelationshipToDocument; } /** * A resource contained in the top level `data` member of a {@link Document}. * * Always constructed non-lazily from raw JSON:API data. Normally this is * done automatically when accessing the {@link Document.resource} or {@link Document.resources} * accessors. * * @example * * ```typescript * // a document containing one _article_ resource * const doc = await JsonApi.Document.fromURL(new URL('http://example.com/article'), context); * const article = doc.resource; // the primary resource * ``` * * @remarks * 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. */ export class PrimaryResource extends Resource { private readonly pRawData; /** * Directly construct a primary resource. Normally a primary resource is obtained via the {@link Document.resource} * or {@link Document.resources} accessors while traversing a document structure. * @param rawData The JSON:API resource object from which to construct this primary resource * @param document The parent document that contains this primary resource * @param resourceType The type of this resource * @param context The context to use to fetch related documents * @param id The id of this resource * @throws {@link IdMismatchError} when the optional `id` argument does not match the id present in `rawData` * @throws SchemaError when `rawData` does not look like a [JSON:API resource object](https://jsonapi.org/format/1.0/#document-resource-objects) */ constructor(rawData: Spec.ResourceObject, document: Document, resourceType: string, context: Context, id?: string); protected getData(): Spec.ResourceObject; } /** * Holds an `application/vnd.api+json` [document](https://jsonapi.org/format/1.0/#document-top-level) and * provides methods to access the resources in that document. * * This is the main class that acts as an entry point to traverse to other resources. * Use the static {@link fromURL} method to fetch and construct a {@link Document} from a given URL. * * @remarks * 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-top-level */ export class Document { readonly rawData: Spec.JsonApiDocument; private readonly context; readonly url?: URL | undefined; readonly sparseFields?: SparseFields | undefined; private readonly responseURL?; /** * Fetch JSON:API data from the given URL and construct a {@link Document} from it. * * @example * ### Simplest example * * Fetching a document from a server: * ```typescript * const articleDoc = await JsonApi.Document.fromURL(new URL('http://example.com/article/1'), context); * const article = articleDoc.resource; * ``` * [[include:guides/sparseFieldsets.md]] * * [[include:guides/queryParams.md]] * * @param url The URL to fetch. It is not changed; the document gets a copy with the added query parameters. * @param context Context that will provide the JSON:API data, normally by fetching it from a server * @param sparseFields Only these fields (per type) are requested from the server. They also apply to related documents. * @param params Further query parameters for this request only, e.g. sorting, filtering or paging */ static fromURL(url: URL, context: Context, sparseFields?: SparseFields, params?: QueryParams): Promise; /** * Directly construct a {@link Document}. Does not fetch any data from a server. * @param rawData The raw JSON:API data describing the document * @param context The context to use to fetch related documents (not used during the initial construction) * @param url An optional URL can be provided to indicate where the raw data came from * @param sparseFields An object listing [sparse fieldsets](https://jsonapi.org/format/1.0/#fetching-sparse-fieldsets) for subsequent fetch operations * @param responseURL The URL the raw data was received from if it differs from `url`, e.g. after redirects * @throws SchemaError when the given rawData does not look like a JSON:API document */ constructor(rawData: Spec.JsonApiDocument, context: Context, url?: URL | undefined, sparseFields?: SparseFields | undefined, responseURL?: URL | undefined); /** * The URL this document was received from, e.g. after redirects, if the context tells it * ({@link Context.getDocumentWithURL}); otherwise {@link url}, the requested URL. Relative links of the document are * resolved against it. */ get effectiveURL(): URL | undefined; /** * All resource objects in this document with the given id and type, i.e. matching primary resources (those in * the `data` member) and matching included resources (those in the `included` member). A compliant document * contains at most one; an empty array is returned when there is none. * * The lookup is served from an index that is built on first use, so resolving many related resources of a large * compound document does not scan the whole document for each of them. Like the memoized accessors, the index * does not reflect changes made to `rawData` after it was built. * @param id The id of the resource objects to look for * @param resourceType The type of the resource objects to look for */ findResourceObjects(id: string, resourceType: string): ReadonlyArray; /** * Index of all primary and included resource objects in this document by type and id * @memoized * @hidden */ private get resourceIndex(); /** * `true` if this document's primary data is an array of resources and not just a single resource * @memoized */ get hasManyResources(): boolean; /** * Array of the primary {@link Resource}s in this document. * * @example * The JSON:API document * * ```json * { * "data": [{ * "type": "articles", * "id": "1" * }] * } * ``` * * would have a primary resource array of length 1 with one element with type "articles" and id "1". * * @returns Empty array when no primary resources are contained in the document * @throws {@link CardinalityError} if the document instead only contains a singular resource. * @memoized */ get resources(): PrimaryResource[]; /** * The primary {@link Resource} in this document. * * @example * The JSON:API document * ```json * { * "data": { * "type": "articles", * "id": "1" * } * } * ``` * * would have a primary resource with type "articles" and id "1". * * @returns Null if the primary data consists of the value `null` * @throws {@link CardinalityError} if the document instead contains an array of resources. * @memoized */ get resource(): PrimaryResource | null | undefined; /** * Map from type and id to {@link RelatedResource} for all resources under the top level `included` member. * * @example * For the JSON:API document * ```json * { * "data": null, * "included": [ * {"type": "articles", "id": "1"}, * {"type": "articles", "id": "2"}, * {"type": "people", "id": "5"} * ] * } * ``` * calling `includedResources` would produce * ```typescript * { * articles: { * '1': RelatedResource(...), * '2': RelatedResource(...), * }, * people: { * '5': RelatedResource(...) * } * } * ``` * @memoized */ get includedResources(): IncludedResourcesMap; /** * Map of link names to {@link Link}s in the top level `links` member, e.g. the * [pagination links](https://jsonapi.org/format/1.0/#fetching-pagination) `first`, `last`, `prev` and `next`. * Links with the value `null` are left out. * @memoized */ get links(): Links; /** * The next page of this paged collection, `undefined` if there is no `next` link. * The sparse fields of this document also apply to related documents of the page. * * [[include:guides/paging.md]] * @memoized */ nextPage(): Promise; /** * The previous page of this paged collection, `undefined` if there is no `prev` link * @memoized */ prevPage(): Promise; /** * The first page of this paged collection, `undefined` if there is no `first` link * @memoized */ firstPage(): Promise; /** * The last page of this paged collection, `undefined` if there is no `last` link * @memoized */ lastPage(): Promise; /** * This document followed by all pages reached through `next` links * * [[include:guides/paging.md]] */ allPages(): Promise; /** * The primary resources of this document and of all pages reached through `next` links, see {@link allPages} * @throws {@link CardinalityError} if a page only contains a singular resource. */ allResources(): Promise; /** @hidden */ private page; } /** Collection of {@link RelatedResource}s included in a compound document, organized by type and id */ export type IncludedResourcesMap = { [type: string]: { [id: string]: RelatedResource; }; }; /** Mapping from relationship name to {@link Relationship} */ export type Relationships = { [relationshipName: string]: Relationship; }; /** Mapping from link name to {@link Link} */ export type Links = { [linkName: string]: Link; }; /** @internal */ type RelationshipToResource = { [relationshipName: string]: Promise; }; /** @internal */ type RelationshipToResources = { [relationshipName: string]: Promise; }; /** @internal */ type RelationshipToDocument = { [relationshipName: string]: Promise; }; /** * A resource contained in the top level `included` member of a {@link Document} or linked via href. * * This resource is initialized lazily on demand when its {@link getData} method is first called. * The resource then looks for its id and type (given at construction) in the parent document * `data` and `included` members to find its raw data. * * Normally a related resource is obtained via the {@link Resource.relatedResource} and {@link Resource.relatedResources} * accessors or the {@link Relationship.resource} and {@link Relationship.resources} methods. * * @example * * ```typescript * // a document containing one _article_ resource with a related _author_ resource * const doc = await JsonApi.Document.fromURL(new URL('http://example.com/article'), context); * const article = doc.resource; // the primary resource * const author = await article.relatedResource['author']; // the related resource * ``` * * @remarks * 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. */ export class RelatedResource extends Resource { /** * Directly construct a related document. It will be lazily initialized from `document` on first use, * so we need to provide an id and a type here so that the resource can find itself in `document`. * @param document The parent document that contains this related resource * @param id The id of this resource * @param resourceType The type of this resource * @param context The context to use to fetch related documents * @throws {@link IdMismatchError} when `id` was not found in the given `document` */ constructor(document: Document, id: string, resourceType: string, context: Context); /** * Looks up the matching resource in the parent {@link Document}. All primary resources (those in the `data` member) * and all included resources (those in the `included` member) are searched, see {@link Document.findResourceObjects}. * @throws {@link IdMismatchError} if the resource is not found or found multiple times * @throws SchemaError when `rawData` does not look like a [JSON:API resource object](https://jsonapi.org/format/1.0/#document-resource-objects) */ protected getData(): Spec.ResourceObject; } /** * Represents a link with URL and optional meta data * @see https://jsonapi.org/format/1.0/#document-links */ export class Link { /** The complete url for this link */ readonly url: URL; /** Any additional meta data */ readonly meta?: object; /** * @param rawData Can be a string containing an href or a {@link Spec.LinkObject} * @param referringDocumentURL A relative href (e.g. `/articles/1`, `comments` or `?page[number]=2`) is resolved * against this URL as described in [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986.html#section-5), normally * the {@link Document.effectiveURL} of the document that contains the link */ constructor(rawData: Spec.Link, referringDocumentURL?: URL); } /** * Defines relations from one {@link Resource} to another (included in the document or external) and can resolve them. * * This class is normally not used directly. It is used internally in the {@link Resource.relatedResource}, {@link Resource.relatedResources} * and {@link Resource.relatedDocuments} accessors and you should use those if you just want to gain access to other resources. * * If you need to work with relationships directly (e.g. to obtain meta data about the relationship itself), you can * use the {@link Resource.relationships} accessor. * * @remarks * 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-object-relationships */ export class Relationship { private readonly referringDocument; private readonly rawData; private readonly context; /** * Directly construct a relationship * @param referringDocument The document that contains the relationship * @param rawData The JSON:API relationship object from which to construct the relationship * @param context The context to use to fetch related documents * @throws SchemaError when `rawData` does not look like a [JSON:API relationship object](https://jsonapi.org/format/1.0/#document-resource-object-relationships) */ constructor(referringDocument: Document, rawData: Spec.RelationshipObject, context: Context); /** * `true` if the relationship only contains a `meta` member and no `data` or `links` * @memoized */ get empty(): boolean; /** * Map of link names to {@link Link}s defined under the `links` member of this relationship * @memoized */ get links(): Links | undefined; /** * One or many {@link Spec.ResourceIdentifierObject}s defined in the `data` member of this relationship * @memoized */ get data(): Spec.ResourceIdentifierObject | Spec.ResourceIdentifierObject[] | undefined | null; /** @hidden */ private cachedRelatedDocument?; /** @hidden */ private cachedResources?; /** @hidden */ private cachedResourcesFromRelatedLink?; /** * The {@link Document} referred to by the `related` link in the `links` member of the relationship. * Fetches the related document from the server using the context given at construction and respecting any * sparseFields of the referring document. * * `options` can request sparse fields, sorting and a page for this request. Only the requested page is fetched; * use {@link Document.nextPage} or {@link resources} for the following pages. Query parameters of the link are kept * unless overridden. Which sort fields and page members a server supports depends on the server. * * [[include:guides/paging.md]] * * @returns `undefined` if there is no `related` link * @throws TypeError if `sort` is not an array of non-empty strings or a `page` member has no value * @remarks The result is memoized if no `sparseFields`, `sort` or `page` options are given. */ relatedDocument(options?: RelatedDocumentOptions): Promise; /** @hidden */ private fetchRelatedDocument; /** * List of {@link Resource}s referenced by this relationship (if there are many resources). * Resource linkage (resource identifiers found in the `data` member of this relationship) has priority. * If there is no resource linkage, the primary resources found in {@link relatedDocument} are used, * including those of all following pages. * * Linkage keeps the server's order and has no pages, so `sort` or `page` options always use the `related` link. * Linkage with pagination links in the relationship is not used either, since it may be incomplete. * With a `sparseFields` option, linkage is only used if the included resources contain all requested fields of * their type (an empty list only needs the identifier); documents fetched from these resources then use the * requested fields. Otherwise the `related` link is used. * * By default, the `next` links of the related document are followed until the last page. With * `followPaging: false`, only the requested page is returned. With `allowPaging: false`, a paged response * throws a {@link PagingNotAllowedError}. * * [[include:guides/paging.md]] * * @throws {@link CardinalityError} if there is only a singular resource. * @throws {@link PagingNotAllowedError} if the response is paged and `allowPaging` is `false`. * @throws SchemaError if neither a `links` nor a `data` member is present, or if `sort` or `page` is given without a `related` link * @throws TypeError if `allowPaging: false` is combined with `followPaging: true`, `sort` is not an array of * non-empty strings or a `page` member has no value * @remarks The result is memoized if no options are given. */ resources(options?: RelatedResourcesOptions): Promise; /** @hidden */ private get linkageIsPaged(); /** @hidden */ private resourcesOfRelatedDocument; /** * `true` if the referring document contains every linked resource with all fields requested for its type. * An empty field list only needs the resource identifier, like in grivetpy. * @hidden */ private linkageProvidesFields; /** @hidden */ private resolveResources; /** * The one {@link Resource} referenced by this relationship. * Resource linkage (the resource identifier found in the `data` member of this relationship) has priority. * If there is no resource linkage, the primary resource found in {@link relatedDocument} is used. * @throws {@link CardinalityError} if there are many resources. * @throws SchemaError if neither a `links` nor a `data` member is present * @memoized */ resource(): Promise; /** * Works like the {@link resources} method, but prefers the `related` link instead of resource linkage. * If no `related` link is present or if the link does not work, it falls back to the {@link resources} method. * The options and the paging behavior are the same as for {@link resources}. * @throws {@link CardinalityError} if there is only a singular resource. * @throws {@link PagingNotAllowedError} if the response is paged and `allowPaging` is `false` (without falling back). * @throws SchemaError if neither a `links` nor a `data` member is present * @remarks The result is memoized if no options are given. */ resourcesFromRelatedLink(options?: RelatedResourcesOptions): Promise; /** @hidden */ private resolveResourcesFromRelatedLink; /** * Works like the {@link resource} method, but prefers the `related` link instead of resource linkage. * If no `related` link is present or if the link does not work, it falls back to the {@link resource} method. * @throws {@link CardinalityError} if there are many resources. * @throws SchemaError if neither a `links` nor a `data` member is present * @memoized */ resourceFromRelatedLink(): Promise; } /** * Some helpers for constructing a document to POST to a server * * @experimental */ export class ClientDocument { private readonly rawData; constructor(resourceType: string, id?: string); /** Sets a primary resource attribute @experimental */ setAttribute(name: string, value: string): void; /** Adds a named relationship to a resource @experimental */ setRelationship(name: string, resourceIdentifier: Spec.ResourceIdentifierObject | Spec.ResourceIdentifierObject[]): void; /** Adds the resource to `included` @experimental */ includeResource(resource: Spec.ResourceObject): void; /** Adds the resources to `included` @experimental */ includeResources(resources: Spec.ResourceObject[]): void; /** The raw JSON:API data @experimental */ get data(): Spec.ClientJsonApiDocument; } export {}; }