@warp-drive-mirror/utilities 5.10.0-alpha.0 → 5.10.0-alpha.2
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.
- package/dist/active-record.d.ts +14 -14
- package/dist/active-record.d.ts.map +1 -1
- package/dist/active-record.js.map +1 -1
- package/dist/derivations.d.ts +1 -2
- package/dist/derivations.d.ts.map +1 -1
- package/dist/handlers.d.ts +9 -10
- package/dist/handlers.d.ts.map +1 -1
- package/dist/json-api.d.ts +21 -21
- package/dist/json-api.d.ts.map +1 -1
- package/dist/json-api.js.map +1 -1
- package/dist/rest.d.ts +14 -14
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js.map +1 -1
- package/dist/string.d.ts +16 -17
- package/dist/string.d.ts.map +1 -1
- package/dist/unpkg/dev/active-record.js.map +1 -1
- package/dist/unpkg/dev/json-api.js.map +1 -1
- package/dist/unpkg/dev/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -1
- package/dist/unpkg/prod/active-record.js.map +1 -1
- package/dist/unpkg/prod/json-api.js.map +1 -1
- package/dist/unpkg/prod/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -1
- package/package.json +7 -7
package/dist/active-record.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
2
2
|
import { TypeFromInstance, TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
3
|
import { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, FindRecordOptions, FindRecordRequestOptions, QueryRequestOptions, RemotelyAccessibleIdentifier, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
4
|
+
import { Meta } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
4
5
|
import { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
5
6
|
//#region src/-private/active-record/find-record.d.ts
|
|
6
7
|
/**
|
|
@@ -58,10 +59,10 @@ import { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
|
58
59
|
* @param identifier
|
|
59
60
|
* @param options
|
|
60
61
|
*/
|
|
61
|
-
declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
62
|
-
declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
63
|
-
declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
64
|
-
declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
62
|
+
export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
|
|
63
|
+
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
64
|
+
export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
|
|
65
|
+
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
65
66
|
//#endregion
|
|
66
67
|
//#region src/-private/active-record/query.d.ts
|
|
67
68
|
/**
|
|
@@ -111,8 +112,8 @@ declare function findRecord(type: string, id: string, options?: FindRecordOption
|
|
|
111
112
|
* @param query
|
|
112
113
|
* @param options
|
|
113
114
|
*/
|
|
114
|
-
declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
115
|
-
declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
115
|
+
export declare function query<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;
|
|
116
|
+
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
116
117
|
//#endregion
|
|
117
118
|
//#region src/-private/active-record/save-record.d.ts
|
|
118
119
|
/**
|
|
@@ -164,8 +165,8 @@ declare function query(type: string, query?: QueryParamsSource, options?: Constr
|
|
|
164
165
|
* @param record
|
|
165
166
|
* @param options
|
|
166
167
|
*/
|
|
167
|
-
declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
168
|
-
declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
168
|
+
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
169
|
+
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
169
170
|
/**
|
|
170
171
|
* Builds request options to create new record for resources,
|
|
171
172
|
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
@@ -205,8 +206,8 @@ declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptio
|
|
|
205
206
|
* @param record
|
|
206
207
|
* @param options
|
|
207
208
|
*/
|
|
208
|
-
declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
209
|
-
declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
209
|
+
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
210
|
+
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
210
211
|
/**
|
|
211
212
|
* Builds request options to update existing record for resources,
|
|
212
213
|
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
@@ -249,12 +250,11 @@ declare function createRecord(record: unknown, options?: ConstrainedRequestOptio
|
|
|
249
250
|
* @param record
|
|
250
251
|
* @param options
|
|
251
252
|
*/
|
|
252
|
-
declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(record: T, options?: ConstrainedRequestOptions & {
|
|
253
|
+
export declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T, M extends Meta | undefined = Meta | undefined, E extends object = object>(record: T, options?: ConstrainedRequestOptions & {
|
|
253
254
|
patch?: boolean;
|
|
254
|
-
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
255
|
-
declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
255
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, T>;
|
|
256
|
+
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
256
257
|
patch?: boolean;
|
|
257
258
|
}): UpdateRequestOptions;
|
|
258
259
|
//#endregion
|
|
259
|
-
export { createRecord, deleteRecord, findRecord, query, updateRecord };
|
|
260
260
|
//# sourceMappingURL=active-record.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-record.d.ts","names":[],"sources":["../src/-private/active-record/find-record.ts","../src/-private/active-record/query.ts","../src/-private/active-record/save-record.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"active-record.d.ts","names":[],"sources":["../src/-private/active-record/find-record.ts","../src/-private/active-record/query.ts","../src/-private/active-record/save-record.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoEgB,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,2BAC3E,YAAY,6BAA6B,iBAAiB,KAC1D,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WACd,YAAY,8BACZ,UAAU,oBACT;wBACa,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,2BAC3E,MAAM,iBAAiB,IACvB,YACA,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WAAW,cAAc,YAAY,UAAU,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCxBnE,MAAM,GAAG,UAAU,mBAAmB,kBAAkB,2BACtE,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,oBAAoB,qBAAqB,KAAK,GAAG;wBACpC,MACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCSa,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqEpE,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuEpE,aACd,UAAU,qBACV,WAAW,sBAAsB,GACjC,UAAU,mBAAmB,kBAC7B,2BAEA,QAAQ,GACR,UAAU;EAA8B;IACvC,qBAAqB,qBAAqB,IAAI,GAAG,IAAI;wBACxC,aACd,iBACA,UAAU;EAA8B;IACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-record.js","names":["recordIdentifierFor","buildBaseURL","pluralize","underscore","copyForwardUrlOptions","macroCondition","getGlobalConfig","isExisting","identifier","id","type","deleteRecord","record","options","WarpDrive","env","DEBUG","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../src/-private/active-record/find-record.ts","../src/-private/active-record/query.ts","../src/-private/active-record/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core/types/request';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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 and underscoring 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-mirror/utilities/active-record';\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 */\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<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\n): FindRecordRequestOptions<ReactiveDataDocument<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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<T> = ReactiveDataDocument<T>;\n","import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core/types/request';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\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 and underscoring 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-mirror/utilities/active-record';\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>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[]>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // oxlint-disable-next-line 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(underscore(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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","import { recordIdentifierFor } from '@warp-drive-mirror/core';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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<ReactiveDataDocument<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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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"],"mappings":";;;;;;;AAiFA,SAAgB,WACd,MACA,MACA,MAC0B;CAC1B,MAAM,aAA2C,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CACjH,MAAM,WAAY,OAAO,SAAS,WAAW,OAAO,SAAS,CAAC;CAC9D,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,WAAW,WAAW,IAAI,CAAC;CACrD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,QAAQ,QAAQ,GAAG,QAAQ,iBAAiB,MAClF;EACJ,QAAQ;EACR;EACA;EACA,IAAI;EACJ,SAAS,CAAC,UAAU;CACtB;AACF;;;;AC7CA,SAAgB,MACd,MAEA,QAA2B,CAAC,GAC5B,UAAqC,CAAC,GACjB;CACrB,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAA8B;EAClC,YAAY,EAAE,KAAK;EACnB,IAAI;EACJ,cAAc,UAAU,WAAW,IAAI,CAAC;CAC1C;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CACzD,MAAM,cAAc,iBAAiB,OAAO,QAAQ,iBAAiB;CAErE,OAAO;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"}
|
|
1
|
+
{"version":3,"file":"active-record.js","names":["recordIdentifierFor","buildBaseURL","pluralize","underscore","copyForwardUrlOptions","macroCondition","getGlobalConfig","isExisting","identifier","id","type","deleteRecord","record","options","WarpDrive","env","DEBUG","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../src/-private/active-record/find-record.ts","../src/-private/active-record/query.ts","../src/-private/active-record/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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 and underscoring 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-mirror/utilities/active-record';\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 */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, 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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n> = ReactiveDataDocument<T, M, E>;\n","import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\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 and underscoring 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-mirror/utilities/active-record';\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, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // oxlint-disable-next-line 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(underscore(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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","import { recordIdentifierFor } from '@warp-drive-mirror/core';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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 ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/active-record';\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-mirror/utilities/active-record';\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<\n T extends TypedRecordInstance,\n RT extends TypedRecordInstance = T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, 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(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\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"],"mappings":";;;;;;;AAkFA,SAAgB,WACd,MACA,MACA,MAC0B;CAC1B,MAAM,aAA2C,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CACjH,MAAM,WAAY,OAAO,SAAS,WAAW,OAAO,SAAS,CAAC;CAC9D,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,WAAW,WAAW,IAAI,CAAC;CACrD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,Q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AC,IAAAC,KAAA,OAAAC,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MAAO,sEAAsE;CAAA,EAAA,CAAEX,WAAWC,UAAU,CAAC;CAErG,MAAMW,aAAqC;EAC7BX;EACZY,IAAI;EACJC,cAAcnB,UAAUC,WAAWK,WAAWE,IAAI,CAAC;CACrD;CAEAN,sBAAsBe,YAAYN,OAAO;CAEzC,MAAMS,MAAMrB,aAAakB,UAAU;CACnC,MAAMI,UAAU,IAAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQb,QAAQkB,QAAQ,UAAU;EAClCR;EACAH,IAAI;EACJO,MAAM,EACJf,QAAQJ,WACV;EACAoB,SAAS,CAACpB,UAAU;CACtB;AACF"}
|
package/dist/derivations.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivations.d.ts","names":[],"sources":["../src/derivations.ts"],"mappings":";;;UAGU;GAEN,QAAQ;;KACR,SAAS,gCACT;GAED;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"derivations.d.ts","names":[],"sources":["../src/derivations.ts"],"mappings":";;;UAGU;GAEN,QAAQ;;KACR,SAAS,gCACT;GAED;;;;;;;;;;;;;;;;;;;qBAoBU,QAAQ"}
|
package/dist/handlers.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Future, Handler, NextFn } from "@warp-drive-mirror/core/request";
|
|
|
7
7
|
*
|
|
8
8
|
* @group Constants
|
|
9
9
|
*/
|
|
10
|
-
declare const SupportsRequestStreams: boolean;
|
|
10
|
+
export declare const SupportsRequestStreams: boolean;
|
|
11
11
|
interface Constraints {
|
|
12
12
|
/**
|
|
13
13
|
* The minimum size at which to compress blobs
|
|
@@ -149,7 +149,7 @@ interface CompressionOptions {
|
|
|
149
149
|
* @public
|
|
150
150
|
* @since 5.5.0
|
|
151
151
|
*/
|
|
152
|
-
declare class AutoCompress implements Handler {
|
|
152
|
+
export declare class AutoCompress implements Handler {
|
|
153
153
|
/**
|
|
154
154
|
* The resolved options this handler was configured with, with all
|
|
155
155
|
* defaults (including `constraints` defaults) applied.
|
|
@@ -175,7 +175,7 @@ type CheckFn = (context: RequestContext) => boolean;
|
|
|
175
175
|
* @group Handlers
|
|
176
176
|
* @public
|
|
177
177
|
*/
|
|
178
|
-
declare class Gate implements Handler {
|
|
178
|
+
export declare class Gate implements Handler {
|
|
179
179
|
/**
|
|
180
180
|
* The wrapped handler to invoke when {@link Gate.checkFn | checkFn} returns `true`.
|
|
181
181
|
*/
|
|
@@ -234,7 +234,7 @@ declare class Gate implements Handler {
|
|
|
234
234
|
*
|
|
235
235
|
* @group Handlers
|
|
236
236
|
*/
|
|
237
|
-
declare const MetaDocHandler: Handler;
|
|
237
|
+
export declare const MetaDocHandler: Handler;
|
|
238
238
|
//#endregion
|
|
239
239
|
//#region src/-private/handlers/utils.d.ts
|
|
240
240
|
/**
|
|
@@ -244,13 +244,13 @@ declare const MetaDocHandler: Handler;
|
|
|
244
244
|
*
|
|
245
245
|
* @group Constants
|
|
246
246
|
*/
|
|
247
|
-
declare const TAB_ID: string;
|
|
247
|
+
export declare const TAB_ID: string;
|
|
248
248
|
/**
|
|
249
249
|
* The epoch seconds at which the tab id was generated
|
|
250
250
|
*
|
|
251
251
|
* @group Constants
|
|
252
252
|
*/
|
|
253
|
-
declare const TAB_ASSIGNED: number;
|
|
253
|
+
export declare const TAB_ASSIGNED: number;
|
|
254
254
|
/**
|
|
255
255
|
* Adds the `X-Amzn-Trace-Id` header to support observability
|
|
256
256
|
* tooling around request routing.
|
|
@@ -262,14 +262,14 @@ declare const TAB_ASSIGNED: number;
|
|
|
262
262
|
*
|
|
263
263
|
* @group Utility Functions
|
|
264
264
|
*/
|
|
265
|
-
declare function addTraceHeader(headers: Headers): Headers;
|
|
265
|
+
export declare function addTraceHeader(headers: Headers): Headers;
|
|
266
266
|
/**
|
|
267
267
|
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
268
268
|
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
269
269
|
*
|
|
270
270
|
* @group Constants
|
|
271
271
|
*/
|
|
272
|
-
declare const MAX_URL_LENGTH = 8192;
|
|
272
|
+
export declare const MAX_URL_LENGTH = 8192;
|
|
273
273
|
/**
|
|
274
274
|
* This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
|
|
275
275
|
*
|
|
@@ -277,7 +277,6 @@ declare const MAX_URL_LENGTH = 8192;
|
|
|
277
277
|
*
|
|
278
278
|
* @group Utility Functions
|
|
279
279
|
*/
|
|
280
|
-
declare function assertInvalidUrlLength(url: string | undefined): void;
|
|
280
|
+
export declare function assertInvalidUrlLength(url: string | undefined): void;
|
|
281
281
|
//#endregion
|
|
282
|
-
export { AutoCompress, Gate, MAX_URL_LENGTH, MetaDocHandler, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
|
|
283
282
|
//# sourceMappingURL=handlers.d.ts.map
|
package/dist/handlers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","names":[],"sources":["../src/-private/handlers/auto-compress.ts","../src/-private/handlers/gated.ts","../src/-private/handlers/meta-doc.ts","../src/-private/handlers/utils.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","names":[],"sources":["../src/-private/handlers/auto-compress.ts","../src/-private/handlers/gated.ts","../src/-private/handlers/meta-doc.ts","../src/-private/handlers/utils.ts"],"mappings":";;;;;;;;;qBAca;UAgBH;;;;;;EAMR;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;UAOQ;;;;;;;;EAQR,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BT;;;;;;;;EASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwCH,wBAAwB;;;;;EAKnC,SAAiB,SAAS;;;;IAIxB,aAAa,SAAS;;EAGxB,YAAY,UAAS;EAUrB,QAAQ,KAAK,WAAW,gBAAgB,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO;;;;;;;;KCxM3E,WAAW,SAAS;;;;;;qBAOZ,gBAAgB;;;;EAI3B,SAAiB;;;;EAIjB,SAAiB;EAEjB,YAAY,SAAS,SAAS,SAAS;EAKvC,QAAQ,aAAa,SAAS,gBAAgB,MAAM,OAAO,KAAK,QAAQ,IAAI,uBAAuB,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBCoBrG,gBAAgB;;;;;;;;;;qBCdhB;;;;;;qBAMA;;;;;;;;;;;;wBAaG,eAAe,SAAS,UAAU;;;;;;;qBAarC;;;;;;;;wBASG,uBAAuB"}
|
package/dist/json-api.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { t as BuildURLConfig } from "./index-BeMAuqgZ.js";
|
|
|
2
2
|
import { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
3
3
|
import { TypeFromInstance, TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
4
4
|
import { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, FindRecordOptions, FindRecordRequestOptions, PostQueryRequestOptions, QueryRequestOptions, RemotelyAccessibleIdentifier, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
5
|
+
import { InnerRelationshipDocument, Meta, ResourceObject } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
5
6
|
import { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
7
|
+
import { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
6
8
|
import { Cache } from "@warp-drive-mirror/core/types/cache";
|
|
7
9
|
import { ResourceKey } from "@warp-drive-mirror/core/types/identifier";
|
|
8
10
|
import { Value } from "@warp-drive-mirror/core/types/json/raw";
|
|
9
|
-
import { InnerRelationshipDocument, ResourceObject } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
10
11
|
//#region src/-private/json-api/find-record.d.ts
|
|
11
12
|
/**
|
|
12
13
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
@@ -83,10 +84,10 @@ import { InnerRelationshipDocument, ResourceObject } from "@warp-drive-mirror/co
|
|
|
83
84
|
*
|
|
84
85
|
* @public
|
|
85
86
|
*/
|
|
86
|
-
declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
87
|
-
declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
88
|
-
declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
89
|
-
declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
87
|
+
export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
|
|
88
|
+
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
89
|
+
export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
|
|
90
|
+
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
90
91
|
//#endregion
|
|
91
92
|
//#region src/-private/json-api/query.d.ts
|
|
92
93
|
/**
|
|
@@ -138,8 +139,8 @@ declare function findRecord(type: string, id: string, options?: FindRecordOption
|
|
|
138
139
|
* @public
|
|
139
140
|
* @badge Builder
|
|
140
141
|
*/
|
|
141
|
-
declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
142
|
-
declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
142
|
+
export declare function query<T extends TypedRecordInstance, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;
|
|
143
|
+
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
143
144
|
/**
|
|
144
145
|
* Builds request options to query for resources, usually by a primary
|
|
145
146
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
@@ -184,8 +185,8 @@ declare function query(type: string, query?: QueryParamsSource, options?: Constr
|
|
|
184
185
|
* @param query - the query params to send with the request
|
|
185
186
|
* @param options - options to modify the request behavior
|
|
186
187
|
*/
|
|
187
|
-
declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
188
|
-
declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
|
|
188
|
+
export declare function postQuery<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[], M, E>>;
|
|
189
|
+
export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
|
|
189
190
|
//#endregion
|
|
190
191
|
//#region src/-private/json-api/save-record.d.ts
|
|
191
192
|
/**
|
|
@@ -242,8 +243,8 @@ declare function postQuery(type: string, query?: QueryParamsSource, options?: Co
|
|
|
242
243
|
* @param record
|
|
243
244
|
* @param options
|
|
244
245
|
*/
|
|
245
|
-
declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
246
|
-
declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
246
|
+
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
247
|
+
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
247
248
|
/**
|
|
248
249
|
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
249
250
|
* While this may come as a surprise, the app providing the body ensures that only
|
|
@@ -298,8 +299,8 @@ declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptio
|
|
|
298
299
|
* @param record
|
|
299
300
|
* @param options
|
|
300
301
|
*/
|
|
301
|
-
declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
302
|
-
declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
302
|
+
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
303
|
+
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
303
304
|
/**
|
|
304
305
|
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
305
306
|
* While this may come as a surprise, the app providing the body ensures that only
|
|
@@ -357,10 +358,10 @@ declare function createRecord(record: unknown, options?: ConstrainedRequestOptio
|
|
|
357
358
|
* @param record
|
|
358
359
|
* @param options
|
|
359
360
|
*/
|
|
360
|
-
declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(record: T, options?: ConstrainedRequestOptions & {
|
|
361
|
+
export declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(record: T, options?: ConstrainedRequestOptions & {
|
|
361
362
|
patch?: boolean;
|
|
362
|
-
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
363
|
-
declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
363
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, T>;
|
|
364
|
+
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
364
365
|
patch?: boolean;
|
|
365
366
|
}): UpdateRequestOptions;
|
|
366
367
|
//#endregion
|
|
@@ -393,13 +394,13 @@ type JsonApiResourcePatch = {
|
|
|
393
394
|
* @param identifiers - the resource(s) to serialize
|
|
394
395
|
* @return an object with a `data` property containing the serialized resource(s)
|
|
395
396
|
*/
|
|
396
|
-
declare function serializeResources(cache: Cache, identifiers: ResourceKey): {
|
|
397
|
+
export declare function serializeResources(cache: Cache, identifiers: ResourceKey): {
|
|
397
398
|
/**
|
|
398
399
|
* The serialized resource.
|
|
399
400
|
*/
|
|
400
401
|
data: ResourceObject;
|
|
401
402
|
};
|
|
402
|
-
declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
|
|
403
|
+
export declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
|
|
403
404
|
/**
|
|
404
405
|
* The serialized resources.
|
|
405
406
|
*/
|
|
@@ -433,7 +434,7 @@ declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
|
|
|
433
434
|
* @param identifier - the resource whose changes should be serialized
|
|
434
435
|
* @return an object with a `data` property containing the serialized resource patch
|
|
435
436
|
*/
|
|
436
|
-
declare function serializePatch(cache: Cache, identifier: ResourceKey): {
|
|
437
|
+
export declare function serializePatch(cache: Cache, identifier: ResourceKey): {
|
|
437
438
|
/**
|
|
438
439
|
* The serialized resource patch.
|
|
439
440
|
*/
|
|
@@ -490,7 +491,6 @@ interface JSONAPIConfig extends BuildURLConfig {
|
|
|
490
491
|
* @param {BuildURLConfig} config
|
|
491
492
|
* @return {void}
|
|
492
493
|
*/
|
|
493
|
-
declare function setBuildURLConfig(config: JSONAPIConfig): void;
|
|
494
|
+
export declare function setBuildURLConfig(config: JSONAPIConfig): void;
|
|
494
495
|
//#endregion
|
|
495
|
-
export { createRecord, deleteRecord, findRecord, postQuery, query, serializePatch, serializeResources, setBuildURLConfig, updateRecord };
|
|
496
496
|
//# sourceMappingURL=json-api.d.ts.map
|
package/dist/json-api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-api.d.ts","names":[],"sources":["../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","../src/-private/json-api/-utils.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-api.d.ts","names":[],"sources":["../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","../src/-private/json-api/-utils.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0FgB,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,mBAAmB,UAC9F,YAAY,6BAA6B,iBAAiB,KAC1D,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WACd,YAAY,8BACZ,UAAU,oBACT;wBACa,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,mBAAmB,UAC9F,MAAM,iBAAiB,IACvB,YACA,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WAAW,cAAc,YAAY,UAAU,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCtCnE,MACd,UAAU,qBACV,UAAU,mBAAmB,kBAC7B,mBAAmB,UAEnB,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,oBAAoB,qBAAqB,KAAK,GAAG;wBACpC,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