/** @hidden */ import { XOR } from './typeHelpers'; /** * Types modelling the [JSON:API v1.0](https://jsonapi.org/format/1.0/#document-structure) specification. * * The type names are chosen to correspond to the language used in the official JSON:API specification. */ export declare namespace Spec { /** * Runtime checks for basic {@link JsonApiDocument} schema * * @throws SchemaError */ function checkDocumentSchema(doc: JsonApiDocument): void; /** * Runtime checks for basic {@link ResourceObject} schema * @throws SchemaError */ function checkResourceObjectSchema(res: object | null): void; /** * Runtime checks for basic {@link RelationshipObject} schema * @throws SchemaError */ function checkRelationshipObjectSchema(rel: object): void; /** * @see https://jsonapi.org/format/1.0/#document-meta */ type MetaObject = { links?: LinksObject; [propName: string]: any; }; /** * @see https://jsonapi.org/format/1.0/#document-resource-object-attributes */ type AttributesObject = { [attrName: string]: any; }; /** * @see https://jsonapi.org/format/1.0/#document-links */ type LinkObject = { href: string; meta?: MetaObject; }; /** * @see https://jsonapi.org/format/1.0/#document-links */ type Link = string | LinkObject; /** * @see https://jsonapi.org/format/1.0/#document-links */ type LinksObject = { [linkName: string]: Link; }; /** * @see https://jsonapi.org/format/1.0/#document-top-level */ type TopLevelLinksObject = { self?: Link; related?: Link; first?: Link | null; last?: Link | null; prev?: Link | null; next?: Link | null; }; /** * @see https://jsonapi.org/format/1.0/#document-resource-identifier-objects */ type ResourceIdentifierObject = { id: string; type: string; meta?: MetaObject; }; /** * @see https://jsonapi.org/format/1.0/#document-resource-object-relationships */ type RelationshipObject = { links?: LinksObject; data?: ResourceIdentifierObject | ResourceIdentifierObject[] | null; meta?: MetaObject; }; /** * @see https://jsonapi.org/format/1.0/#document-resource-object-relationships */ type RelationshipsObject = { [relationshipName: string]: RelationshipObject; }; /** * @see https://jsonapi.org/format/1.0/#document-resource-objects */ type ResourceObject = { id: string; type: string; attributes?: AttributesObject; relationships?: RelationshipsObject; links?: LinksObject; meta?: MetaObject; }; /** * When sent by the client the id is not required * * @see https://jsonapi.org/format/1.0/#document-resource-objects * @hidden */ type ClientResourceObject = { id?: string; type: string; attributes?: AttributesObject; relationships?: RelationshipsObject; links?: LinksObject; meta?: MetaObject; }; /** * @see https://jsonapi.org/format/1.0/#error-objects */ type ErrorObject = { id?: string; links?: LinksObject; status?: string; code?: string; title?: string; detail?: string; source?: { pointer?: string; parameter?: string; [propName: string]: any; }; meta?: MetaObject; }; /** * @see https://jsonapi.org/format/1.0/#document-jsonapi-object */ type JsonApiObject = { version?: string; meta?: MetaObject; }; /** * This type looks a bit more complicated, as we require either the `data` or `errors` property, * but not both at the same time. * * @see https://jsonapi.org/format/1.0/#document-top-level */ type JsonApiDocument = XOR<{ data: ResourceObject | ResourceObject[] | ResourceIdentifierObject | ResourceIdentifierObject[] | null; }, { errors: ErrorObject[]; }> & { meta?: MetaObject; jsonapi?: JsonApiObject; links?: TopLevelLinksObject; included?: ResourceObject[]; }; /** * Some aspects of an JSON API document which are usually sufficient for client requests * * @experimental * @see https://jsonapi.org/format/1.0/#document-top-level */ type ClientJsonApiDocument = { data: ClientResourceObject; included?: ResourceObject[]; }; }