@warp-drive/utilities 5.6.0-alpha.13 → 5.6.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAE1G,KAAK,uBAAuB,GAAG,yBAAyB,CAAC;AAEzD,MAAM,MAAM,oBAAoB,GAC5B;IACE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACzD,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,IAAI,CAAC;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACzD,CAAC;AAEN;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC;AAChH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG;IAAE,IAAI,EAA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K,EACZ,UAAU,EAAE,sBAAsB,GAEjC;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAuChC"}
|
package/dist/json-api.js
CHANGED
|
@@ -593,11 +593,12 @@ function _serializeResource(cache, identifier) {
|
|
|
593
593
|
if (record.relationships) {
|
|
594
594
|
for (const key of Object.keys(record.relationships)) {
|
|
595
595
|
const relationship = record.relationships[key];
|
|
596
|
-
relationship.data = fixRelData(relationship.data);
|
|
597
596
|
if (Array.isArray(relationship.data)) {
|
|
598
597
|
relationship.data = relationship.data.map(ref => fixRef(ref));
|
|
599
598
|
} else if (typeof relationship.data === 'object' && relationship.data !== null) {
|
|
600
599
|
relationship.data = fixRef(relationship.data);
|
|
600
|
+
} else if (Object.keys(relationship ?? {}).length === 0) {
|
|
601
|
+
delete record.relationships[key];
|
|
601
602
|
}
|
|
602
603
|
}
|
|
603
604
|
}
|
package/dist/json-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-api.js","sources":["../src/-private/json-api/-utils.ts","../src/-private/json-api/find-record.ts","../src/-private/json-api/query.ts","../src/-private/json-api/save-record.ts","../src/-private/json-api/serialize.ts"],"sourcesContent":["import type { QueryParamsSource } from '@warp-drive/core/types/params';\n\nimport type { BuildURLConfig } from '../../index.ts';\nimport { buildQueryParams as buildParams, setBuildURLConfig as setConfig } from '../../index.ts';\n\nexport interface JSONAPIConfig extends BuildURLConfig {\n profiles?: {\n pagination?: string;\n [key: string]: string | undefined;\n };\n extensions?: {\n atomic?: string;\n [key: string]: string | undefined;\n };\n}\n\nconst JsonApiAccept = 'application/vnd.api+json';\nconst DEFAULT_CONFIG: JSONAPIConfig = { host: '', namespace: '' };\nexport let CONFIG: JSONAPIConfig = DEFAULT_CONFIG;\nexport let ACCEPT_HEADER_VALUE = 'application/vnd.api+json';\n\n/**\n * Allows setting extensions and profiles to be used in the `Accept` header.\n *\n * Extensions and profiles are keyed by their namespace with the value being\n * their URI.\n *\n * Example:\n *\n * ```ts\n * setBuildURLConfig({\n * extensions: {\n * atomic: 'https://jsonapi.org/ext/atomic'\n * },\n * profiles: {\n * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'\n * }\n * });\n * ```\n *\n * This also sets the global configuration for `buildBaseURL`\n * for host and namespace values for the global coniguration\n * done via `import { setBuildURLConfig } from '@warp-drive/utilities';`\n *\n * These values may still be overridden by passing\n * them to buildBaseURL directly.\n *\n * This method may be called as many times as needed\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * @public\n * @param {BuildURLConfig} config\n * @return {void}\n */\nexport function setBuildURLConfig(config: JSONAPIConfig): void {\n CONFIG = Object.assign({}, DEFAULT_CONFIG, config);\n\n if (config.profiles || config.extensions) {\n let accept = JsonApiAccept;\n if (config.profiles) {\n const profiles = Object.values(config.profiles);\n if (profiles.length) {\n accept += ';profile=\"' + profiles.join(' ') + '\"';\n }\n }\n if (config.extensions) {\n const extensions = Object.values(config.extensions);\n if (extensions.length) {\n accept += ';ext=' + extensions.join(' ');\n }\n }\n ACCEPT_HEADER_VALUE = accept;\n }\n\n setConfig(config);\n}\n\ninterface RelatedObject {\n [key: string]: string | string[] | RelatedObject;\n}\n\nexport type JsonApiQuery = {\n include?: string | string[] | RelatedObject;\n fields?: Record<string, string | string[]>;\n page?: {\n size?: number;\n after?: string;\n before?: string;\n };\n};\n\nfunction isJsonApiQuery(query: JsonApiQuery | QueryParamsSource): query is JsonApiQuery {\n if ('include' in query && query.include && typeof query.include === 'object') {\n return true;\n }\n if ('fields' in query || 'page' in query) {\n return true;\n }\n return false;\n}\n\nfunction collapseIncludePaths(basePath: string, include: RelatedObject, paths: string[]) {\n const keys = Object.keys(include);\n for (let i = 0; i < keys.length; i++) {\n // the key is always included too\n paths.push(`${basePath}.${keys[i]}`);\n const key = keys[i];\n const value = include[key];\n\n // include: { 'company': 'field1,field2' }\n if (typeof value === 'string') {\n value.split(',').forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': ['field1', 'field2'] }\n } else if (Array.isArray(value)) {\n value.forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': { 'nested': 'field1,field2' } }\n } else {\n collapseIncludePaths(`${basePath}.${key}`, value, paths);\n }\n }\n}\n\n/**\n * Sorts query params by both key and value, returning a query params string\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n * - If `included` is an object we build paths dynamically for you\n * Treats `fields` specially, building JSON:API partial fields params from an object\n * Treats `page` specially, building cursor-pagination profile page params from an object\n *\n * ```ts\n * const params = buildQueryParams({\n * include: {\n * company: {\n * locations: 'address'\n * }\n * },\n * fields: {\n * company: ['name', 'ticker'],\n * person: 'name'\n * },\n * page: {\n * size: 10,\n * after: 'abc',\n * }\n * });\n *\n * // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'\n * ```\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`\n *\n * @public\n * @param {URLSearchParams | Object} params\n * @param {Object} [options]\n * @return {String} A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string {\n if (query instanceof URLSearchParams) {\n return buildParams(query);\n }\n\n if (!isJsonApiQuery(query)) {\n return buildParams(query);\n }\n\n const { include, fields, page, ...rest } = query;\n const finalQuery: QueryParamsSource = {\n ...rest,\n };\n\n if ('include' in query) {\n // include: { 'company': 'field1,field2' }\n // include: { 'company': ['field1', 'field2'] }\n // include: { 'company': { 'nested': 'field1,field2' } }\n // include: { 'company': { 'nested': ['field1', 'field2'] } }\n if (include && !Array.isArray(include) && typeof include === 'object') {\n const includePaths: string[] = [];\n collapseIncludePaths('', include, includePaths);\n finalQuery.include = includePaths.sort();\n\n // include: 'field1,field2'\n // include: ['field1', 'field2']\n } else {\n finalQuery.include = include as string;\n }\n }\n\n if (fields) {\n const keys = Object.keys(fields).sort();\n for (let i = 0; i < keys.length; i++) {\n const resourceType = keys[i];\n const value = fields[resourceType];\n\n // fields: { 'company': ['field1', 'field2'] }\n if (Array.isArray(value)) {\n finalQuery[`fields[${resourceType}]`] = value.sort().join(',');\n\n // fields: { 'company': 'field1' }\n // fields: { 'company': 'field1,field2' }\n } else {\n finalQuery[`fields[${resourceType}]`] = value.split(',').sort().join(',');\n }\n }\n }\n\n if (page) {\n const keys = Object.keys(page).sort() as Array<'size' | 'after' | 'before'>;\n keys.forEach((key) => {\n const value = page[key];\n finalQuery[`page[${key}]`] = value!;\n });\n }\n\n return buildParams(finalQuery);\n}\n","import type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param options\n */\n\nexport type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & { data: T };\n\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n","import type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n CacheOptions,\n ConstrainedRequestOptions,\n PostQueryRequestOptions,\n QueryRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `postQuery` is that this method will send the query\n * as query params in the url of a \"GET\" request instead of as the JSON body of a \"POST\"\n * request.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource<T>,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `query` is that this method will send the query\n * as the JSON body of a \"POST\" request instead of as query params in the url of a \"GET\"\n * request.\n *\n * A CacheKey is generated from the url and query params, and used to cache the response\n * in the store.\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function postQuery<T>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function postQuery(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions;\nexport function postQuery(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): PostQueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: options.resourcePath ?? pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n const queryData = structuredClone(query);\n cacheOptions.key = cacheOptions.key ?? `${url}?${buildQueryParams(queryData, options.urlParamsSettings)}`;\n\n return {\n url,\n method: 'POST',\n body: JSON.stringify(query),\n headers,\n cacheOptions: cacheOptions as CacheOptions & { key: string },\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\nfunction isExisting(identifier: StableRecordIdentifier): identifier is StableExistingRecordIdentifier {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<SingleResourceDataDocument<RT>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url and header expectations of most JSON:API APIs\n * for a PATCH request.\n *\n * Note: This is a convenience method that calls `updateRecord` with the\n * supplied request with the `patch` option set to `true`.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(patchRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = patchRecord(person);\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function patchRecord<T>(record: T, options?: ConstrainedRequestOptions): UpdateRequestOptions<T>;\nexport function patchRecord(record: unknown, options?: ConstrainedRequestOptions): UpdateRequestOptions;\nexport function patchRecord(record: unknown, options: ConstrainedRequestOptions = {}): UpdateRequestOptions {\n const opts = options as ConstrainedRequestOptions & { patch: true };\n opts.patch = true;\n return updateRecord(record, opts);\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { Relationship } from '@warp-drive/core/types/cache/relationship';\nimport type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { InnerRelationshipDocument, ResourceObject } from '@warp-drive/core/types/spec/json-api-raw';\n\ntype ChangedRelationshipData = InnerRelationshipDocument;\n\nexport type JsonApiResourcePatch =\n | {\n type: string;\n id: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n }\n | {\n type: string;\n id: null;\n lid: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n };\n\n/**\n * Serializes the current state of a resource or array of resources for use with POST or PUT requests.\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): { data: ResourceObject };\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): { data: ResourceObject[] };\nexport function serializeResources(\n cache: Cache,\n identifiers: StableRecordIdentifier | StableRecordIdentifier[]\n): { data: ResourceObject | ResourceObject[] } {\n return {\n data: Array.isArray(identifiers)\n ? identifiers.map((identifier) => _serializeResource(cache, identifier))\n : _serializeResource(cache, identifiers),\n };\n}\n\ntype SerializedRef =\n | {\n id: string;\n type: string;\n }\n | { id: null; lid: string; type: string };\n\nfunction fixRef({\n id,\n lid,\n type,\n}: { id: string; lid?: string; type: string } | { id: null; lid: string; type: string }): SerializedRef {\n if (id !== null) {\n return { id, type };\n }\n return { id, lid, type };\n}\n\nfunction fixRelData(\n rel: Relationship['data'] | InnerRelationshipDocument['data']\n): SerializedRef | SerializedRef[] | null {\n if (Array.isArray(rel)) {\n return rel.map((ref) => fixRef(ref));\n } else if (typeof rel === 'object' && rel !== null) {\n return fixRef(rel);\n }\n return null;\n}\n\nfunction _serializeResource(cache: Cache, identifier: StableRecordIdentifier): ResourceObject {\n const { id, lid, type } = identifier;\n // peek gives us everything we want, but since its referentially the same data\n // as is in the cache we clone it to avoid any accidental mutations\n const record = structuredClone(cache.peek(identifier)) as ResourceObject;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n record\n );\n\n // remove lid from anything that has an ID and slice any relationship arrays\n if (record.id !== null) {\n delete record.lid;\n }\n\n if (record.relationships) {\n for (const key of Object.keys(record.relationships)) {\n const relationship = record.relationships[key];\n relationship.data = fixRelData(relationship.data);\n if (Array.isArray(relationship.data)) {\n relationship.data = relationship.data.map((ref) => fixRef(ref));\n } else if (typeof relationship.data === 'object' && relationship.data !== null) {\n relationship.data = fixRef(relationship.data);\n }\n }\n }\n\n return record;\n}\n\n/**\n * Serializes changes to a resource for use with PATCH requests.\n *\n * Only attributes which are changed are serialized.\n * Only relationships which are changed are serialized.\n *\n * Collection relationships serialize the collection as a whole.\n *\n * If you would like to serialize updates to a collection more granularly\n * (for instance, as operations) request the diff from the store and\n * serialize as desired:\n *\n * ```ts\n * const relationshipDiffMap = cache.changedRelationships(identifier);\n * ```\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializePatch(\n cache: Cache,\n identifier: StableRecordIdentifier\n // options: { include?: string[] } = {}\n): { data: JsonApiResourcePatch } {\n const { id, lid, type } = identifier;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n cache.peek(identifier)\n );\n\n const data: JsonApiResourcePatch =\n id === null\n ? { type, lid, id }\n : {\n type,\n id,\n };\n\n if (cache.hasChangedAttrs(identifier)) {\n const attrsChanges = cache.changedAttrs(identifier);\n const attributes: ResourceObject['attributes'] = {};\n\n Object.keys(attrsChanges).forEach((key) => {\n const change = attrsChanges[key];\n const newVal = change[1];\n attributes[key] = newVal === undefined ? null : structuredClone(newVal);\n });\n\n data.attributes = attributes;\n }\n\n const changedRelationships = cache.changedRelationships(identifier);\n if (changedRelationships.size) {\n const relationships: Record<string, ChangedRelationshipData> = {};\n changedRelationships.forEach((diff, key) => {\n relationships[key] = { data: fixRelData(diff.localState) } as ChangedRelationshipData;\n });\n\n data.relationships = relationships;\n }\n\n return { data };\n}\n"],"names":["JsonApiAccept","DEFAULT_CONFIG","host","namespace","ACCEPT_HEADER_VALUE","setBuildURLConfig","config","Object","assign","profiles","extensions","accept","values","length","join","setConfig","findRecord","arg1","arg2","arg3","identifier","type","id","options","cacheOptions","extractCacheOptions","urlOptions","op","resourcePath","pluralize","copyForwardUrlOptions","url","buildBaseURL","headers","Headers","append","include","buildQueryParams","urlParamsSettings","method","records","query","queryString","postQuery","queryData","structuredClone","key","body","JSON","stringify","isExisting","deleteRecord","record","recordIdentifierFor","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","data","createRecord","updateRecord","patch","serializeResources","cache","identifiers","Array","isArray","map","_serializeResource","fixRef","lid","fixRelData","rel","ref","peek","String","relationships","keys","relationship","serializePatch","hasChangedAttrs","attrsChanges","changedAttrs","attributes","forEach","change","newVal","undefined","changedRelationships","size","diff","localState"],"mappings":";;;;;;AAgBA,MAAMA,aAAa,GAAG,0BAA0B;AAChD,MAAMC,cAA6B,GAAG;AAAEC,EAAAA,IAAI,EAAE,EAAE;AAAEC,EAAAA,SAAS,EAAE;AAAG,CAAC;AAE1D,IAAIC,mBAAmB,GAAG,0BAA0B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACC,MAAqB,EAAQ;EACpDC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEP,cAAc,EAAEK,MAAM,CAAC;AAElD,EAAA,IAAIA,MAAM,CAACG,QAAQ,IAAIH,MAAM,CAACI,UAAU,EAAE;IACxC,IAAIC,MAAM,GAAGX,aAAa;IAC1B,IAAIM,MAAM,CAACG,QAAQ,EAAE;MACnB,MAAMA,QAAQ,GAAGF,MAAM,CAACK,MAAM,CAACN,MAAM,CAACG,QAAQ,CAAC;MAC/C,IAAIA,QAAQ,CAACI,MAAM,EAAE;QACnBF,MAAM,IAAI,YAAY,GAAGF,QAAQ,CAACK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AC,GAAG;AAAEe,QAAAA,IAAI,EAAEa,UAAU,CAACmB,IAAI,CAACC,UAAU;OAA8B;AACvF,KAAC,CAAC;IAEFjC,IAAI,CAACkB,aAAa,GAAGA,aAAa;AACpC;EAEA,OAAO;AAAElB,IAAAA;GAAM;AACjB;;;;"}
|
|
1
|
+
{"version":3,"file":"json-api.js","sources":["../src/-private/json-api/-utils.ts","../src/-private/json-api/find-record.ts","../src/-private/json-api/query.ts","../src/-private/json-api/save-record.ts","../src/-private/json-api/serialize.ts"],"sourcesContent":["import type { QueryParamsSource } from '@warp-drive/core/types/params';\n\nimport type { BuildURLConfig } from '../../index.ts';\nimport { buildQueryParams as buildParams, setBuildURLConfig as setConfig } from '../../index.ts';\n\nexport interface JSONAPIConfig extends BuildURLConfig {\n profiles?: {\n pagination?: string;\n [key: string]: string | undefined;\n };\n extensions?: {\n atomic?: string;\n [key: string]: string | undefined;\n };\n}\n\nconst JsonApiAccept = 'application/vnd.api+json';\nconst DEFAULT_CONFIG: JSONAPIConfig = { host: '', namespace: '' };\nexport let CONFIG: JSONAPIConfig = DEFAULT_CONFIG;\nexport let ACCEPT_HEADER_VALUE = 'application/vnd.api+json';\n\n/**\n * Allows setting extensions and profiles to be used in the `Accept` header.\n *\n * Extensions and profiles are keyed by their namespace with the value being\n * their URI.\n *\n * Example:\n *\n * ```ts\n * setBuildURLConfig({\n * extensions: {\n * atomic: 'https://jsonapi.org/ext/atomic'\n * },\n * profiles: {\n * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'\n * }\n * });\n * ```\n *\n * This also sets the global configuration for `buildBaseURL`\n * for host and namespace values for the global coniguration\n * done via `import { setBuildURLConfig } from '@warp-drive/utilities';`\n *\n * These values may still be overridden by passing\n * them to buildBaseURL directly.\n *\n * This method may be called as many times as needed\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * @public\n * @param {BuildURLConfig} config\n * @return {void}\n */\nexport function setBuildURLConfig(config: JSONAPIConfig): void {\n CONFIG = Object.assign({}, DEFAULT_CONFIG, config);\n\n if (config.profiles || config.extensions) {\n let accept = JsonApiAccept;\n if (config.profiles) {\n const profiles = Object.values(config.profiles);\n if (profiles.length) {\n accept += ';profile=\"' + profiles.join(' ') + '\"';\n }\n }\n if (config.extensions) {\n const extensions = Object.values(config.extensions);\n if (extensions.length) {\n accept += ';ext=' + extensions.join(' ');\n }\n }\n ACCEPT_HEADER_VALUE = accept;\n }\n\n setConfig(config);\n}\n\ninterface RelatedObject {\n [key: string]: string | string[] | RelatedObject;\n}\n\nexport type JsonApiQuery = {\n include?: string | string[] | RelatedObject;\n fields?: Record<string, string | string[]>;\n page?: {\n size?: number;\n after?: string;\n before?: string;\n };\n};\n\nfunction isJsonApiQuery(query: JsonApiQuery | QueryParamsSource): query is JsonApiQuery {\n if ('include' in query && query.include && typeof query.include === 'object') {\n return true;\n }\n if ('fields' in query || 'page' in query) {\n return true;\n }\n return false;\n}\n\nfunction collapseIncludePaths(basePath: string, include: RelatedObject, paths: string[]) {\n const keys = Object.keys(include);\n for (let i = 0; i < keys.length; i++) {\n // the key is always included too\n paths.push(`${basePath}.${keys[i]}`);\n const key = keys[i];\n const value = include[key];\n\n // include: { 'company': 'field1,field2' }\n if (typeof value === 'string') {\n value.split(',').forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': ['field1', 'field2'] }\n } else if (Array.isArray(value)) {\n value.forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': { 'nested': 'field1,field2' } }\n } else {\n collapseIncludePaths(`${basePath}.${key}`, value, paths);\n }\n }\n}\n\n/**\n * Sorts query params by both key and value, returning a query params string\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n * - If `included` is an object we build paths dynamically for you\n * Treats `fields` specially, building JSON:API partial fields params from an object\n * Treats `page` specially, building cursor-pagination profile page params from an object\n *\n * ```ts\n * const params = buildQueryParams({\n * include: {\n * company: {\n * locations: 'address'\n * }\n * },\n * fields: {\n * company: ['name', 'ticker'],\n * person: 'name'\n * },\n * page: {\n * size: 10,\n * after: 'abc',\n * }\n * });\n *\n * // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'\n * ```\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`\n *\n * @public\n * @param {URLSearchParams | Object} params\n * @param {Object} [options]\n * @return {String} A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string {\n if (query instanceof URLSearchParams) {\n return buildParams(query);\n }\n\n if (!isJsonApiQuery(query)) {\n return buildParams(query);\n }\n\n const { include, fields, page, ...rest } = query;\n const finalQuery: QueryParamsSource = {\n ...rest,\n };\n\n if ('include' in query) {\n // include: { 'company': 'field1,field2' }\n // include: { 'company': ['field1', 'field2'] }\n // include: { 'company': { 'nested': 'field1,field2' } }\n // include: { 'company': { 'nested': ['field1', 'field2'] } }\n if (include && !Array.isArray(include) && typeof include === 'object') {\n const includePaths: string[] = [];\n collapseIncludePaths('', include, includePaths);\n finalQuery.include = includePaths.sort();\n\n // include: 'field1,field2'\n // include: ['field1', 'field2']\n } else {\n finalQuery.include = include as string;\n }\n }\n\n if (fields) {\n const keys = Object.keys(fields).sort();\n for (let i = 0; i < keys.length; i++) {\n const resourceType = keys[i];\n const value = fields[resourceType];\n\n // fields: { 'company': ['field1', 'field2'] }\n if (Array.isArray(value)) {\n finalQuery[`fields[${resourceType}]`] = value.sort().join(',');\n\n // fields: { 'company': 'field1' }\n // fields: { 'company': 'field1,field2' }\n } else {\n finalQuery[`fields[${resourceType}]`] = value.split(',').sort().join(',');\n }\n }\n }\n\n if (page) {\n const keys = Object.keys(page).sort() as Array<'size' | 'after' | 'before'>;\n keys.forEach((key) => {\n const value = page[key];\n finalQuery[`page[${key}]`] = value!;\n });\n }\n\n return buildParams(finalQuery);\n}\n","import type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param options\n */\n\nexport type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & { data: T };\n\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n","import type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n CacheOptions,\n ConstrainedRequestOptions,\n PostQueryRequestOptions,\n QueryRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `postQuery` is that this method will send the query\n * as query params in the url of a \"GET\" request instead of as the JSON body of a \"POST\"\n * request.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource<T>,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `query` is that this method will send the query\n * as the JSON body of a \"POST\" request instead of as query params in the url of a \"GET\"\n * request.\n *\n * A CacheKey is generated from the url and query params, and used to cache the response\n * in the store.\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function postQuery<T>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function postQuery(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions;\nexport function postQuery(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): PostQueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: options.resourcePath ?? pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n const queryData = structuredClone(query);\n cacheOptions.key = cacheOptions.key ?? `${url}?${buildQueryParams(queryData, options.urlParamsSettings)}`;\n\n return {\n url,\n method: 'POST',\n body: JSON.stringify(query),\n headers,\n cacheOptions: cacheOptions as CacheOptions & { key: string },\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\nfunction isExisting(identifier: StableRecordIdentifier): identifier is StableExistingRecordIdentifier {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<SingleResourceDataDocument<RT>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url and header expectations of most JSON:API APIs\n * for a PATCH request.\n *\n * Note: This is a convenience method that calls `updateRecord` with the\n * supplied request with the `patch` option set to `true`.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(patchRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = patchRecord(person);\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function patchRecord<T>(record: T, options?: ConstrainedRequestOptions): UpdateRequestOptions<T>;\nexport function patchRecord(record: unknown, options?: ConstrainedRequestOptions): UpdateRequestOptions;\nexport function patchRecord(record: unknown, options: ConstrainedRequestOptions = {}): UpdateRequestOptions {\n const opts = options as ConstrainedRequestOptions & { patch: true };\n opts.patch = true;\n return updateRecord(record, opts);\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { Relationship } from '@warp-drive/core/types/cache/relationship';\nimport type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { InnerRelationshipDocument, ResourceObject } from '@warp-drive/core/types/spec/json-api-raw';\n\ntype ChangedRelationshipData = InnerRelationshipDocument;\n\nexport type JsonApiResourcePatch =\n | {\n type: string;\n id: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n }\n | {\n type: string;\n id: null;\n lid: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n };\n\n/**\n * Serializes the current state of a resource or array of resources for use with POST or PUT requests.\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): { data: ResourceObject };\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): { data: ResourceObject[] };\nexport function serializeResources(\n cache: Cache,\n identifiers: StableRecordIdentifier | StableRecordIdentifier[]\n): { data: ResourceObject | ResourceObject[] } {\n return {\n data: Array.isArray(identifiers)\n ? identifiers.map((identifier) => _serializeResource(cache, identifier))\n : _serializeResource(cache, identifiers),\n };\n}\n\ntype SerializedRef =\n | {\n id: string;\n type: string;\n }\n | { id: null; lid: string; type: string };\n\nfunction fixRef({\n id,\n lid,\n type,\n}: { id: string; lid?: string; type: string } | { id: null; lid: string; type: string }): SerializedRef {\n if (id !== null) {\n return { id, type };\n }\n return { id, lid, type };\n}\n\nfunction fixRelData(\n rel: Relationship['data'] | InnerRelationshipDocument['data']\n): SerializedRef | SerializedRef[] | null {\n if (Array.isArray(rel)) {\n return rel.map((ref) => fixRef(ref));\n } else if (typeof rel === 'object' && rel !== null) {\n return fixRef(rel);\n }\n return null;\n}\n\nfunction _serializeResource(cache: Cache, identifier: StableRecordIdentifier): ResourceObject {\n const { id, lid, type } = identifier;\n // peek gives us everything we want, but since its referentially the same data\n // as is in the cache we clone it to avoid any accidental mutations\n const record = structuredClone(cache.peek(identifier)) as ResourceObject;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n record\n );\n\n // remove lid from anything that has an ID and slice any relationship arrays\n if (record.id !== null) {\n delete record.lid;\n }\n\n if (record.relationships) {\n for (const key of Object.keys(record.relationships)) {\n const relationship = record.relationships[key];\n if (Array.isArray(relationship.data)) {\n relationship.data = relationship.data.map((ref) => fixRef(ref));\n } else if (typeof relationship.data === 'object' && relationship.data !== null) {\n relationship.data = fixRef(relationship.data);\n } else if (Object.keys(relationship ?? {}).length === 0) {\n delete record.relationships[key];\n }\n }\n }\n\n return record;\n}\n\n/**\n * Serializes changes to a resource for use with PATCH requests.\n *\n * Only attributes which are changed are serialized.\n * Only relationships which are changed are serialized.\n *\n * Collection relationships serialize the collection as a whole.\n *\n * If you would like to serialize updates to a collection more granularly\n * (for instance, as operations) request the diff from the store and\n * serialize as desired:\n *\n * ```ts\n * const relationshipDiffMap = cache.changedRelationships(identifier);\n * ```\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializePatch(\n cache: Cache,\n identifier: StableRecordIdentifier\n // options: { include?: string[] } = {}\n): { data: JsonApiResourcePatch } {\n const { id, lid, type } = identifier;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n cache.peek(identifier)\n );\n\n const data: JsonApiResourcePatch =\n id === null\n ? { type, lid, id }\n : {\n type,\n id,\n };\n\n if (cache.hasChangedAttrs(identifier)) {\n const attrsChanges = cache.changedAttrs(identifier);\n const attributes: ResourceObject['attributes'] = {};\n\n Object.keys(attrsChanges).forEach((key) => {\n const change = attrsChanges[key];\n const newVal = change[1];\n attributes[key] = newVal === undefined ? null : structuredClone(newVal);\n });\n\n data.attributes = attributes;\n }\n\n const changedRelationships = cache.changedRelationships(identifier);\n if (changedRelationships.size) {\n const relationships: Record<string, ChangedRelationshipData> = {};\n changedRelationships.forEach((diff, key) => {\n relationships[key] = { data: fixRelData(diff.localState) } as ChangedRelationshipData;\n });\n\n data.relationships = relationships;\n }\n\n return { data };\n}\n"],"names":["JsonApiAccept","DEFAULT_CONFIG","host","namespace","ACCEPT_HEADER_VALUE","setBuildURLConfig","config","Object","assign","profiles","extensions","accept","values","length","join","setConfig","findRecord","arg1","arg2","arg3","identifier","type","id","options","cacheOptions","extractCacheOptions","urlOptions","op","resourcePath","pluralize","copyForwardUrlOptions","url","buildBaseURL","headers","Headers","append","include","buildQueryParams","urlParamsSettings","method","records","query","queryString","postQuery","queryData","structuredClone","key","body","JSON","stringify","isExisting","deleteRecord","record","recordIdentifierFor","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","data","createRecord","updateRecord","patch","serializeResources","cache","identifiers","Array","isArray","map","_serializeResource","fixRef","lid","fixRelData","rel","ref","peek","String","relationships","keys","relationship","serializePatch","hasChangedAttrs","attrsChanges","changedAttrs","attributes","forEach","change","newVal","undefined","changedRelationships","size","diff","localState"],"mappings":";;;;;;AAgBA,MAAMA,aAAa,GAAG,0BAA0B;AAChD,MAAMC,cAA6B,GAAG;AAAEC,EAAAA,IAAI,EAAE,EAAE;AAAEC,EAAAA,SAAS,EAAE;AAAG,CAAC;AAE1D,IAAIC,mBAAmB,GAAG,0BAA0B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACC,MAAqB,EAAQ;EACpDC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEP,cAAc,EAAEK,MAAM,CAAC;AAElD,EAAA,IAAIA,MAAM,CAACG,QAAQ,IAAIH,MAAM,CAACI,UAAU,EAAE;IACxC,IAAIC,MAAM,GAAGX,aAAa;IAC1B,IAAIM,MAAM,CAACG,QAAQ,EAAE;MACnB,MAAMA,QAAQ,GAAGF,MAAM,CAACK,MAAM,CAACN,MAAM,CAACG,QAAQ,CAAC;MAC/C,IAAIA,QAAQ,CAACI,MAAM,EAAE;QACnBF,MAAM,IAAI,YAAY,GAAGF,QAAQ,CAACK,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;AACnD;AACF;IACA,IAAIR,MAAM,CAACI,UAAU,EAAE;MACrB,MAAMA,UAAU,GAAGH,MAAM,CAACK,MAAM,CAACN,MAAM,CAACI,UAAU,CAAC;MACnD,IAAIA,UAAU,CAACG,MAAM,EAAE;QACrBF,MAAM,IAAI,OAAO,GAAGD,UAAU,CAACI,IAAI,CAAC,GAAG,CAAC;AAC1C;AACF;AACAV,IAAAA,mBAAmB,GAAGO,MAAM;AAC9B;EAEAI,mBAAS,CAACT,MAAM,CAAC;AACnB;;ACpEA;AACA;AACA;AACA;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"version": "5.6.0-alpha.
|
|
3
|
+
"version": "5.6.0-alpha.15",
|
|
4
4
|
"description": "Utilities package for WarpDrive | Things your app might find useful",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@warp-drive/core": "5.6.0-alpha.
|
|
39
|
+
"@warp-drive/core": "5.6.0-alpha.15"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@embroider/macros": "^1.16.12"
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@babel/core": "^7.26.10",
|
|
46
46
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
47
47
|
"@babel/preset-typescript": "^7.27.0",
|
|
48
|
-
"@warp-drive/internal-config": "5.6.0-alpha.
|
|
49
|
-
"@warp-drive/core": "5.6.0-alpha.
|
|
48
|
+
"@warp-drive/internal-config": "5.6.0-alpha.15",
|
|
49
|
+
"@warp-drive/core": "5.6.0-alpha.15",
|
|
50
50
|
"decorator-transforms": "^2.3.0",
|
|
51
51
|
"expect-type": "^1.2.1",
|
|
52
52
|
"typescript": "^5.8.3",
|