UNPKG

@ember-data/json-api

Version:

Provides a JSON:API document and resource cache implementation for EmberData

63 lines 2.34 kB
declare module '@ember-data/json-api/-private/serialize' { import type { StableRecordIdentifier } from '@warp-drive/core-types'; import type { Cache } from '@warp-drive/core-types/cache'; import type { Relationship } from '@warp-drive/core-types/cache/relationship'; import type { Value } from '@warp-drive/core-types/json/raw'; import type { ResourceObject } from '@warp-drive/core-types/spec/json-api-raw'; type ChangedRelationshipData = { data: Relationship['data']; }; export type JsonApiResourcePatch = { type: string; id: string | null; lid: string; attributes?: Record<string, Value>; relationships?: Record<string, ChangedRelationshipData>; }; /** * Serializes the current state of a resource or array of resources for use with POST or PUT requests. * * @method serializeResources * @static * @public * @for @ember-data/json-api/request * @param {Cache} cache} * @param {StableRecordIdentifier} identifier * @return {object} An object with a `data` property containing the serialized resource patch */ export function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): { data: ResourceObject; }; export function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): { data: ResourceObject[]; }; /** * Serializes changes to a resource for use with PATCH requests. * * Only attributes which are changed are serialized. * Only relationships which are changed are serialized. * * Collection relationships serialize the collection as a whole. * * If you would like to serialize updates to a collection more granularly * (for instance, as operations) request the diff from the store and * serialize as desired: * * ```ts * const relationshipDiffMap = cache.changedRelationships(identifier); * ``` * * @method serializePatch * @static * @public * @for @ember-data/json-api/request * @param {Cache} cache} * @param {StableRecordIdentifier} identifier * @return {object} An object with a `data` property containing the serialized resource patch */ export function serializePatch(cache: Cache, identifier: StableRecordIdentifier): { data: JsonApiResourcePatch; }; export {}; } //# sourceMappingURL=serialize.d.ts.map