hidden import { XOR } from './typeHelpers' ; import { SchemaChecker } from './schemaChecker' ; /**
 * 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 namespace Spec { throws export function checkDocumentSchema ( doc ) { SchemaChecker . fromData ( doc , 'Document' ) . singleObject ( ) . atLeastOneOf ( [ 'data' , 'errors' , 'meta' ] ) . allowedMembers ( [ 'data' , 'errors' , 'meta' , 'jsonapi' , 'links' , 'included' ] ) ; if ( 'data' in doc ) { if ( Array . isArray ( doc [ 'data' ] ) ) { for ( const r of doc [ 'data' ] as object [ ] ) { checkResourceObjectSchema ( r ) ; } } else if ( doc [ 'data' ] !== undefined ) { checkResourceObjectSchema ( doc [ 'data' ] ) ; } } } throws export function checkResourceObjectSchema ( res ) { if ( res === null ) { return ; } SchemaChecker . fromData ( res , 'Resource object' ) . singleObject ( ) . has ( [ 'id' , 'type' ] ) . allowedMembers ( [ 'id' , 'type' , 'attributes' , 'relationships' , 'links' , 'meta' ] ) ; } throws export function checkRelationshipObjectSchema ( rel ) { SchemaChecker . fromData ( rel , 'Relationship object' ) . singleObject ( ) . atLeastOneOf ( [ 'links' , 'data' , 'meta' ] ) ; } see https export type MetaObject = { links ? : LinksObject ; [ propName ] : any ; } ; see https export type AttributesObject = { [ attrName ] : any ; } ; see https export type LinkObject = { href : string ; meta ? : MetaObject ; } ; see https export type Link = string | LinkObject ; see https export type LinksObject = { [ linkName ] : Link ; } ; see https export type TopLevelLinksObject = { self ? : Link ; related ? : Link ; first ? : Link | null ; last ? : Link | null ; prev ? : Link | null ; next ? : Link | null ; } ; see https export type ResourceIdentifierObject = { id : string ; type : string ; meta ? : MetaObject ; } ; see https export type RelationshipObject = { links ? : LinksObject ; data ? : ResourceIdentifierObject | ResourceIdentifierObject [ ] | null ; meta ? : MetaObject ; } ; see https export type RelationshipsObject = { [ relationshipName ] : RelationshipObject ; } ; see https export type ResourceObject = { id : string ; type : string ; attributes ? : AttributesObject ; relationships ? : RelationshipsObject ; links ? : LinksObject ; meta ? : MetaObject ; } ; see https hidden export type ClientResourceObject = { id ? : string ; type : string ; attributes ? : AttributesObject ; relationships ? : RelationshipsObject ; links ? : LinksObject ; meta ? : MetaObject ; } ; see https export type ErrorObject = { id ? : string ; links ? : LinksObject ; status ? : string ; code ? : string ; title ? : string ; detail ? : string ; source ? : { pointer ? : string ; parameter ? : string ; [ propName ] : any ; } ; meta ? : MetaObject ; } ; see https export type JsonApiObject = { version ? : string ; meta ? : MetaObject ; } ; see https export type JsonApiDocument = XOR < { data : ResourceObject | ResourceObject [ ] | ResourceIdentifierObject | ResourceIdentifierObject [ ] | null ; } , { errors : ErrorObject [ ] ; } > & { meta ? : MetaObject ; jsonapi ? : JsonApiObject ; links ? : TopLevelLinksObject ; included ? : ResourceObject [ ] ; } ; see https hidden export type ClientJsonApiDocument = { data : ClientResourceObject ; included ? : ResourceObject [ ] ; } ; }