@warp-drive-mirror/utilities 5.10.0-alpha.2 → 5.10.0-alpha.21
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/README.md +92 -7
- package/cjs-dist/string.cjs +23 -8
- package/cjs-dist/string.cjs.map +1 -1
- package/dist/-private.d.ts +0 -2
- package/dist/-private.d.ts.map +1 -1
- package/dist/-private.js +1 -1
- package/dist/active-record.d.ts +21 -6
- package/dist/active-record.d.ts.map +1 -1
- package/dist/active-record.js +17 -8
- package/dist/active-record.js.map +1 -1
- package/dist/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/derivations.d.ts +3 -2
- package/dist/derivations.d.ts.map +1 -1
- package/dist/derivations.js +7 -2
- package/dist/derivations.js.map +1 -1
- package/dist/handlers.d.ts +26 -9
- package/dist/handlers.d.ts.map +1 -1
- package/dist/handlers.js +29 -9
- package/dist/handlers.js.map +1 -1
- package/dist/{index-BeMAuqgZ.d.ts → index-Dv5kZpGe.d.ts} +47 -3
- package/dist/index-Dv5kZpGe.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -8
- package/dist/index.js.map +1 -1
- package/dist/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/json-api.d.ts +51 -11
- package/dist/json-api.d.ts.map +1 -1
- package/dist/json-api.js +43 -12
- package/dist/json-api.js.map +1 -1
- package/dist/rest.d.ts +20 -6
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +17 -8
- package/dist/rest.js.map +1 -1
- package/dist/{string-CWmAluxh.js → string-DFhbMVCj.js} +23 -6
- package/dist/string-DFhbMVCj.js.map +1 -0
- package/dist/string.d.ts +19 -4
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +1 -1
- package/dist/unpkg/dev/-private.js +1 -1
- package/dist/unpkg/dev/active-record.js +17 -8
- package/dist/unpkg/dev/active-record.js.map +1 -1
- package/dist/unpkg/dev/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/unpkg/dev/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/dev/derivations.js +7 -2
- package/dist/unpkg/dev/derivations.js.map +1 -1
- package/dist/unpkg/dev/handlers.js +29 -9
- package/dist/unpkg/dev/handlers.js.map +1 -1
- package/dist/unpkg/dev/index.js +54 -8
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/dev/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/unpkg/dev/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/dev/json-api.js +43 -12
- package/dist/unpkg/dev/json-api.js.map +1 -1
- package/dist/unpkg/dev/rest.js +17 -8
- package/dist/unpkg/dev/rest.js.map +1 -1
- package/dist/unpkg/dev/{string-j4ur-TDs.js → string-D9jrClhQ.js} +23 -6
- package/dist/unpkg/dev/string-D9jrClhQ.js.map +1 -0
- package/dist/unpkg/dev/string.js +1 -1
- package/dist/unpkg/dev-deprecated/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/active-record.js +17 -8
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/unpkg/dev-deprecated/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/derivations.js +7 -2
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/dev-deprecated/handlers.js +29 -9
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/dev-deprecated/index.js +54 -8
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/unpkg/dev-deprecated/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/json-api.js +43 -12
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/rest.js +17 -8
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{string-j4ur-TDs.js → string-D9jrClhQ.js} +23 -6
- package/dist/unpkg/dev-deprecated/string-D9jrClhQ.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -1
- package/dist/unpkg/prod/-private.js +1 -1
- package/dist/unpkg/prod/active-record.js +17 -8
- package/dist/unpkg/prod/active-record.js.map +1 -1
- package/dist/unpkg/prod/builder-utils-bjXbHa-m.js +15 -0
- package/dist/unpkg/prod/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/prod/derivations.js +7 -2
- package/dist/unpkg/prod/derivations.js.map +1 -1
- package/dist/unpkg/prod/handlers.js +29 -9
- package/dist/unpkg/prod/handlers.js.map +1 -1
- package/dist/unpkg/prod/index.js +54 -8
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod/inflections-CWdUh2K_.js +79 -0
- package/dist/unpkg/prod/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/prod/json-api.js +43 -12
- package/dist/unpkg/prod/json-api.js.map +1 -1
- package/dist/unpkg/prod/rest.js +17 -8
- package/dist/unpkg/prod/rest.js.map +1 -1
- package/dist/unpkg/prod/string-Du9nRZEd.js +300 -0
- package/dist/unpkg/prod/string-Du9nRZEd.js.map +1 -0
- package/dist/unpkg/prod/string.js +1 -1
- package/dist/unpkg/prod-deprecated/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/active-record.js +17 -8
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/unpkg/prod-deprecated/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/derivations.js +7 -2
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/prod-deprecated/handlers.js +29 -9
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/prod-deprecated/index.js +54 -8
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/unpkg/prod-deprecated/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/json-api.js +43 -12
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/rest.js +17 -8
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{string-T1ahjLdj.js → string-Du9nRZEd.js} +23 -6
- package/dist/unpkg/prod-deprecated/string-Du9nRZEd.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -1
- package/logos/README.md +1 -1
- package/package.json +9 -9
- package/dist/index-BeMAuqgZ.d.ts.map +0 -1
- package/dist/string-CWmAluxh.js.map +0 -1
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +0 -1
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +0 -1
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +0 -16
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +0 -80
- package/dist/unpkg/prod/string-T1ahjLdj.js +0 -283
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +0 -1
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +0 -1
package/dist/json-api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as BuildURLConfig } from "./index-
|
|
1
|
+
import { t as BuildURLConfig } from "./index-Dv5kZpGe.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";
|
|
@@ -8,11 +8,13 @@ import { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
|
8
8
|
import { Cache } from "@warp-drive-mirror/core/types/cache";
|
|
9
9
|
import { ResourceKey } from "@warp-drive-mirror/core/types/identifier";
|
|
10
10
|
import { Value } from "@warp-drive-mirror/core/types/json/raw";
|
|
11
|
-
//#region src/-private/json-api/find-record.d.ts
|
|
12
11
|
/**
|
|
13
12
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
14
13
|
* configured for the url and header expectations of most JSON:API APIs.
|
|
15
14
|
*
|
|
15
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
16
|
+
* when to use one.
|
|
17
|
+
*
|
|
16
18
|
* :::tabs
|
|
17
19
|
*
|
|
18
20
|
* == Basic Usage
|
|
@@ -82,18 +84,20 @@ import { Value } from "@warp-drive-mirror/core/types/json/raw";
|
|
|
82
84
|
* );
|
|
83
85
|
* ```
|
|
84
86
|
*
|
|
87
|
+
* @summary Builds a JSON:API `GET` request for one resource by type and id, with optional `include`.
|
|
85
88
|
* @public
|
|
86
89
|
*/
|
|
87
90
|
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
91
|
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
89
92
|
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
93
|
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/-private/json-api/query.d.ts
|
|
93
94
|
/**
|
|
94
95
|
* Builds request options to query for resources, usually by a primary
|
|
95
96
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
96
97
|
*
|
|
98
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
99
|
+
* when to use one.
|
|
100
|
+
*
|
|
97
101
|
* The key difference between this and `postQuery` is that this method will send the query
|
|
98
102
|
* as query params in the url of a "GET" request instead of as the JSON body of a "POST"
|
|
99
103
|
* request.
|
|
@@ -136,6 +140,7 @@ export declare function findRecord(type: string, id: string, options?: FindRecor
|
|
|
136
140
|
* const data = await store.request(options);
|
|
137
141
|
* ```
|
|
138
142
|
*
|
|
143
|
+
* @summary Builds a JSON:API `GET` request that queries a resource type, sending the query as URL query params.
|
|
139
144
|
* @public
|
|
140
145
|
* @badge Builder
|
|
141
146
|
*/
|
|
@@ -145,6 +150,9 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
|
|
|
145
150
|
* Builds request options to query for resources, usually by a primary
|
|
146
151
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
147
152
|
*
|
|
153
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
154
|
+
* when to use one.
|
|
155
|
+
*
|
|
148
156
|
* The key difference between this and `query` is that this method will send the query
|
|
149
157
|
* as the JSON body of a "POST" request instead of as query params in the url of a "GET"
|
|
150
158
|
* request.
|
|
@@ -180,6 +188,8 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
|
|
|
180
188
|
* const data = await store.request(options);
|
|
181
189
|
* ```
|
|
182
190
|
*
|
|
191
|
+
* @summary Builds a JSON:API `POST` request that sends a query as the JSON body, cached under a key built from the
|
|
192
|
+
* query params.
|
|
183
193
|
* @public
|
|
184
194
|
* @param type - the name of the resource type to query
|
|
185
195
|
* @param query - the query params to send with the request
|
|
@@ -187,8 +197,6 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
|
|
|
187
197
|
*/
|
|
188
198
|
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
199
|
export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/-private/json-api/save-record.d.ts
|
|
192
200
|
/**
|
|
193
201
|
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**
|
|
194
202
|
* While this may come as a surprise, the app providing the body ensures that only
|
|
@@ -198,6 +206,9 @@ export declare function postQuery(type: string, query?: QueryParamsSource, optio
|
|
|
198
206
|
* Builds request options to delete record for resources,
|
|
199
207
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
200
208
|
*
|
|
209
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
210
|
+
* when to use one.
|
|
211
|
+
*
|
|
201
212
|
* **Basic Usage**
|
|
202
213
|
*
|
|
203
214
|
* ```ts
|
|
@@ -239,6 +250,7 @@ export declare function postQuery(type: string, query?: QueryParamsSource, optio
|
|
|
239
250
|
* const data = await store.request(options);
|
|
240
251
|
* ```
|
|
241
252
|
*
|
|
253
|
+
* @summary Builds a JSON:API `DELETE` request that persists deletion of an existing record.
|
|
242
254
|
* @public
|
|
243
255
|
* @param record
|
|
244
256
|
* @param options
|
|
@@ -254,6 +266,9 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
|
|
|
254
266
|
* Builds request options to create new record for resources,
|
|
255
267
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
256
268
|
*
|
|
269
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
270
|
+
* when to use one.
|
|
271
|
+
*
|
|
257
272
|
* **Basic Usage**
|
|
258
273
|
*
|
|
259
274
|
* ```ts
|
|
@@ -295,6 +310,7 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
|
|
|
295
310
|
* const data = await store.request(options);
|
|
296
311
|
* ```
|
|
297
312
|
*
|
|
313
|
+
* @summary Builds a JSON:API `POST` request for saving a new record; the app must set the request body itself.
|
|
298
314
|
* @public
|
|
299
315
|
* @param record
|
|
300
316
|
* @param options
|
|
@@ -310,6 +326,9 @@ export declare function createRecord(record: unknown, options?: ConstrainedReque
|
|
|
310
326
|
* Builds request options to update existing record for resources,
|
|
311
327
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
312
328
|
*
|
|
329
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
330
|
+
* when to use one.
|
|
331
|
+
*
|
|
313
332
|
* **Example Usage**
|
|
314
333
|
*
|
|
315
334
|
* ```ts
|
|
@@ -354,6 +373,8 @@ export declare function createRecord(record: unknown, options?: ConstrainedReque
|
|
|
354
373
|
* const data = await store.request(options);
|
|
355
374
|
* ```
|
|
356
375
|
*
|
|
376
|
+
* @summary Builds a JSON:API `PUT` (or `PATCH`) request for saving an existing record; the app must set the request
|
|
377
|
+
* body itself.
|
|
357
378
|
* @public
|
|
358
379
|
* @param record
|
|
359
380
|
* @param options
|
|
@@ -364,9 +385,14 @@ export declare function updateRecord<T extends TypedRecordInstance, RT extends T
|
|
|
364
385
|
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
365
386
|
patch?: boolean;
|
|
366
387
|
}): UpdateRequestOptions;
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region src/-private/json-api/serialize.d.ts
|
|
369
388
|
type ChangedRelationshipData = InnerRelationshipDocument;
|
|
389
|
+
/**
|
|
390
|
+
* The resource object {@link serializePatch} produces: the resource's `type` and `id` (or `lid`
|
|
391
|
+
* for a new record) with only its changed attributes and relationships.
|
|
392
|
+
*
|
|
393
|
+
* @summary A JSON:API resource object holding only a record's changed attributes and relationships, as produced by `serializePatch`.
|
|
394
|
+
* @public
|
|
395
|
+
*/
|
|
370
396
|
type JsonApiResourcePatch = {
|
|
371
397
|
type: string;
|
|
372
398
|
id: string;
|
|
@@ -389,6 +415,8 @@ type JsonApiResourcePatch = {
|
|
|
389
415
|
*
|
|
390
416
|
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
391
417
|
*
|
|
418
|
+
* @summary Copies the cached state of one or more resources into a JSON:API-style `{ data }` object, a starting point
|
|
419
|
+
* for request bodies.
|
|
392
420
|
* @public
|
|
393
421
|
* @param cache - the cache to serialize the resource(s) from
|
|
394
422
|
* @param identifiers - the resource(s) to serialize
|
|
@@ -429,6 +457,8 @@ export declare function serializeResources(cache: Cache, identifiers: ResourceKe
|
|
|
429
457
|
* const relationshipDiffMap = cache.changedRelationships(identifier);
|
|
430
458
|
* ```
|
|
431
459
|
*
|
|
460
|
+
* @summary Serializes only a resource's changed attributes and relationships from the cache into a JSON:API-style
|
|
461
|
+
* `{ data }` patch.
|
|
432
462
|
* @public
|
|
433
463
|
* @param cache - the cache to serialize the resource's changes from
|
|
434
464
|
* @param identifier - the resource whose changes should be serialized
|
|
@@ -440,8 +470,13 @@ export declare function serializePatch(cache: Cache, identifier: ResourceKey): {
|
|
|
440
470
|
*/
|
|
441
471
|
data: JsonApiResourcePatch;
|
|
442
472
|
};
|
|
443
|
-
|
|
444
|
-
|
|
473
|
+
/**
|
|
474
|
+
* The configuration {@link setBuildURLConfig} accepts: the {@link BuildURLConfig} fields, plus
|
|
475
|
+
* the {json:api} profile and extension URIs to send in the `Accept` header.
|
|
476
|
+
*
|
|
477
|
+
* @summary Configuration for the JSON:API request builders: host, namespace, and the profile and extension URIs for `Accept`.
|
|
478
|
+
* @public
|
|
479
|
+
*/
|
|
445
480
|
interface JSONAPIConfig extends BuildURLConfig {
|
|
446
481
|
profiles?: {
|
|
447
482
|
pagination?: string;
|
|
@@ -458,6 +493,9 @@ interface JSONAPIConfig extends BuildURLConfig {
|
|
|
458
493
|
* Extensions and profiles are keyed by their namespace with the value being
|
|
459
494
|
* their URI.
|
|
460
495
|
*
|
|
496
|
+
* The [Basic Usage](/guides/the-manual/cookbook/basic-usage#step-2-configure-some-request-defaults)
|
|
497
|
+
* guide uses it to configure a host, a namespace and a pagination profile.
|
|
498
|
+
*
|
|
461
499
|
* Example:
|
|
462
500
|
*
|
|
463
501
|
* ```ts
|
|
@@ -487,10 +525,12 @@ interface JSONAPIConfig extends BuildURLConfig {
|
|
|
487
525
|
* }
|
|
488
526
|
* ```
|
|
489
527
|
*
|
|
528
|
+
* @summary Sets the JSON:API extensions and profiles sent in the `Accept` header, plus the global URL host and
|
|
529
|
+
* namespace.
|
|
490
530
|
* @public
|
|
491
531
|
* @param {BuildURLConfig} config
|
|
492
532
|
* @return {void}
|
|
493
533
|
*/
|
|
494
534
|
export declare function setBuildURLConfig(config: JSONAPIConfig): void;
|
|
495
|
-
|
|
535
|
+
export type { JSONAPIConfig, JsonApiResourcePatch };
|
|
496
536
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8FgB,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,MACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+Ea,UAAU,GAAG,UAAU,mBAAmB,kBAAkB,mBAAmB,UAC7F,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,wBAAwB,qBAAqB,KAAK,GAAG;wBACxC,UACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCpFa,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwFpE,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2FpE,aACd,UAAU,qBACV,WAAW,sBAAsB,GACjC,UAAU,mBAAmB,kBAC7B,mBAAmB,UAEnB,QAAQ,GACR,UAAU;EAA8B;IACvC,qBAAqB,qBAAqB,IAAI,GAAG,IAAI;wBACxC,aACd,iBACA,UAAU;EAA8B;IACvC;KChRE,0BAA0B;;;;;;;;KASnB;EAEN;EACA;EACA,aAAa,eAAe;EAC5B,gBAAgB,eAAe;;EAG/B;EACA;EACA;EACA,aAAa,eAAe;EAC5B,gBAAgB,eAAe;;;;;;;;;;;;;;;;;;;wBAoBrB,mBACd,OAAO,OACP,aAAa;;;;EAKb,MAAM;;wBAEQ,mBACd,OAAO,OACP,aAAa;;;;EAKb,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuGQ,eACd,OAAO,OACP,YAAY;;;;EAMZ,MAAM;;;;;;;;;UCnKS,sBAAsB;EACrC;IACE;;;EAGF;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsDY,kBAAkB,QAAQ"}
|
package/dist/json-api.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { buildBaseURL, buildQueryParams, setBuildURLConfig as setBuildURLConfig$1 } from "./index.js";
|
|
2
|
-
import { s as pluralize } from "./string-
|
|
3
|
-
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-
|
|
2
|
+
import { s as pluralize } from "./string-DFhbMVCj.js";
|
|
3
|
+
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-bjXbHa-m.js";
|
|
4
4
|
import { getGlobalConfig, macroCondition } from "@embroider/macros";
|
|
5
5
|
import { recordIdentifierFor } from "@warp-drive-mirror/core";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/-private/json-api/-utils.ts
|
|
8
|
+
/**
|
|
9
|
+
* The configuration {@link setBuildURLConfig} accepts: the {@link BuildURLConfig} fields, plus
|
|
10
|
+
* the {json:api} profile and extension URIs to send in the `Accept` header.
|
|
11
|
+
*
|
|
12
|
+
* @summary Configuration for the JSON:API request builders: host, namespace, and the profile and extension URIs for `Accept`.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
8
15
|
const JsonApiAccept = "application/vnd.api+json";
|
|
9
16
|
const DEFAULT_CONFIG = {
|
|
10
17
|
host: "",
|
|
@@ -18,6 +25,9 @@ let ACCEPT_HEADER_VALUE = "application/vnd.api+json";
|
|
|
18
25
|
* Extensions and profiles are keyed by their namespace with the value being
|
|
19
26
|
* their URI.
|
|
20
27
|
*
|
|
28
|
+
* The [Basic Usage](/guides/the-manual/cookbook/basic-usage#step-2-configure-some-request-defaults)
|
|
29
|
+
* guide uses it to configure a host, a namespace and a pagination profile.
|
|
30
|
+
*
|
|
21
31
|
* Example:
|
|
22
32
|
*
|
|
23
33
|
* ```ts
|
|
@@ -47,6 +57,8 @@ let ACCEPT_HEADER_VALUE = "application/vnd.api+json";
|
|
|
47
57
|
* }
|
|
48
58
|
* ```
|
|
49
59
|
*
|
|
60
|
+
* @summary Sets the JSON:API extensions and profiles sent in the `Accept` header, plus the global URL host and
|
|
61
|
+
* namespace.
|
|
50
62
|
* @public
|
|
51
63
|
* @param {BuildURLConfig} config
|
|
52
64
|
* @return {void}
|
|
@@ -68,8 +80,7 @@ function setBuildURLConfig(config) {
|
|
|
68
80
|
setBuildURLConfig$1(config);
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
//#region src/-private/json-api/find-record.ts
|
|
83
|
+
// src/-private/json-api/find-record.ts
|
|
73
84
|
function findRecord(arg1, arg2, arg3) {
|
|
74
85
|
const identifier = typeof arg1 === "string" ? {
|
|
75
86
|
type: arg1,
|
|
@@ -96,8 +107,7 @@ function findRecord(arg1, arg2, arg3) {
|
|
|
96
107
|
};
|
|
97
108
|
}
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
//#region src/-private/json-api/query.ts
|
|
110
|
+
// src/-private/json-api/query.ts
|
|
101
111
|
function query(type, query = {}, options = {}) {
|
|
102
112
|
const cacheOptions = extractCacheOptions(options);
|
|
103
113
|
const urlOptions = {
|
|
@@ -141,8 +151,7 @@ function postQuery(type, query = {}, options = {}) {
|
|
|
141
151
|
};
|
|
142
152
|
}
|
|
143
153
|
|
|
144
|
-
|
|
145
|
-
//#region src/-private/json-api/save-record.ts
|
|
154
|
+
// src/-private/json-api/save-record.ts
|
|
146
155
|
function isExisting(identifier) {
|
|
147
156
|
return "id" in identifier && identifier.id !== null && "type" in identifier && identifier.type !== null;
|
|
148
157
|
}
|
|
@@ -155,6 +164,9 @@ function isExisting(identifier) {
|
|
|
155
164
|
* Builds request options to delete record for resources,
|
|
156
165
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
157
166
|
*
|
|
167
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
168
|
+
* when to use one.
|
|
169
|
+
*
|
|
158
170
|
* **Basic Usage**
|
|
159
171
|
*
|
|
160
172
|
* ```ts
|
|
@@ -196,6 +208,7 @@ function isExisting(identifier) {
|
|
|
196
208
|
* const data = await store.request(options);
|
|
197
209
|
* ```
|
|
198
210
|
*
|
|
211
|
+
* @summary Builds a JSON:API `DELETE` request that persists deletion of an existing record.
|
|
199
212
|
* @public
|
|
200
213
|
* @param record
|
|
201
214
|
* @param options
|
|
@@ -235,6 +248,9 @@ function deleteRecord(record, options = {}) {
|
|
|
235
248
|
* Builds request options to create new record for resources,
|
|
236
249
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
237
250
|
*
|
|
251
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
252
|
+
* when to use one.
|
|
253
|
+
*
|
|
238
254
|
* **Basic Usage**
|
|
239
255
|
*
|
|
240
256
|
* ```ts
|
|
@@ -276,6 +292,7 @@ function deleteRecord(record, options = {}) {
|
|
|
276
292
|
* const data = await store.request(options);
|
|
277
293
|
* ```
|
|
278
294
|
*
|
|
295
|
+
* @summary Builds a JSON:API `POST` request for saving a new record; the app must set the request body itself.
|
|
279
296
|
* @public
|
|
280
297
|
* @param record
|
|
281
298
|
* @param options
|
|
@@ -312,6 +329,9 @@ function createRecord(record, options = {}) {
|
|
|
312
329
|
* Builds request options to update existing record for resources,
|
|
313
330
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
314
331
|
*
|
|
332
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
333
|
+
* when to use one.
|
|
334
|
+
*
|
|
315
335
|
* **Example Usage**
|
|
316
336
|
*
|
|
317
337
|
* ```ts
|
|
@@ -356,6 +376,8 @@ function createRecord(record, options = {}) {
|
|
|
356
376
|
* const data = await store.request(options);
|
|
357
377
|
* ```
|
|
358
378
|
*
|
|
379
|
+
* @summary Builds a JSON:API `PUT` (or `PATCH`) request for saving an existing record; the app must set the request
|
|
380
|
+
* body itself.
|
|
359
381
|
* @public
|
|
360
382
|
* @param record
|
|
361
383
|
* @param options
|
|
@@ -387,8 +409,14 @@ function updateRecord(record, options = {}) {
|
|
|
387
409
|
};
|
|
388
410
|
}
|
|
389
411
|
|
|
390
|
-
|
|
391
|
-
|
|
412
|
+
// src/-private/json-api/serialize.ts
|
|
413
|
+
/**
|
|
414
|
+
* The resource object {@link serializePatch} produces: the resource's `type` and `id` (or `lid`
|
|
415
|
+
* for a new record) with only its changed attributes and relationships.
|
|
416
|
+
*
|
|
417
|
+
* @summary A JSON:API resource object holding only a record's changed attributes and relationships, as produced by `serializePatch`.
|
|
418
|
+
* @public
|
|
419
|
+
*/
|
|
392
420
|
/**
|
|
393
421
|
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
394
422
|
*
|
|
@@ -399,6 +427,8 @@ function updateRecord(record, options = {}) {
|
|
|
399
427
|
*
|
|
400
428
|
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
401
429
|
*
|
|
430
|
+
* @summary Copies the cached state of one or more resources into a JSON:API-style `{ data }` object, a starting point
|
|
431
|
+
* for request bodies.
|
|
402
432
|
* @public
|
|
403
433
|
* @param cache - the cache to serialize the resource(s) from
|
|
404
434
|
* @param identifiers - the resource(s) to serialize
|
|
@@ -461,6 +491,8 @@ function _serializeResource(cache, identifier) {
|
|
|
461
491
|
* const relationshipDiffMap = cache.changedRelationships(identifier);
|
|
462
492
|
* ```
|
|
463
493
|
*
|
|
494
|
+
* @summary Serializes only a resource's changed attributes and relationships from the cache into a JSON:API-style
|
|
495
|
+
* `{ data }` patch.
|
|
464
496
|
* @public
|
|
465
497
|
* @param cache - the cache to serialize the resource's changes from
|
|
466
498
|
* @param identifier - the resource whose changes should be serialized
|
|
@@ -499,6 +531,5 @@ function serializePatch(cache, identifier) {
|
|
|
499
531
|
return { data };
|
|
500
532
|
}
|
|
501
533
|
|
|
502
|
-
//#endregion
|
|
503
534
|
export { createRecord, deleteRecord, findRecord, postQuery, query, serializePatch, serializeResources, setBuildURLConfig, updateRecord };
|
|
504
535
|
//# sourceMappingURL=json-api.js.map
|
package/dist/json-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-api.js","names":["recordIdentifierFor","buildBaseURL","pluralize","copyForwardUrlOptions","ACCEPT_HEADER_VALUE","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","patchRecord","opts","serializeResources","cache","identifiers","data","Array","isArray","map","identifier","_serializeResource","fixRef","id","lid","type","fixRelData","rel","ref","record","structuredClone","peek","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","String","relationships","key","Object","keys","relationship","length","serializePatch","hasChangedAttrs","attrsChanges","changedAttrs","attributes","forEach","change","newVal","undefined","changedRelationships","size","diff","localState"],"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-mirror/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-mirror/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;\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 { 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 { ApiError } from '@warp-drive-mirror/core/types/spec/error';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\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 * :::tabs\n *\n * == Basic Usage\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const result = await store.request(\n * findRecord<Person>('person', '1')\n * );\n * ```\n *\n * == With Options\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const data = await store.request(\n * findRecord<Person>(\n * 'person', '1',\n * { include: ['pets', 'friends'] }\n * )\n * );\n * ```\n *\n * == With an Identifier\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const data = await store.request(\n * findRecord<Person>(\n * { type: 'person', id: '1' },\n * { include: ['pets', 'friends'] }\n * )\n * );\n * ```\n *\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-mirror/utilities/json-api';\n *\n * const data = await store.request(\n * findRecord(\n * 'person', '1',\n * { include: ['pets', 'friends'] },\n * { namespace: 'api/v2' }\n * )\n * );\n * ```\n *\n * @public\n */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(\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 = ApiError>(\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(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\n/** @deprecated use {@link ReactiveDataDocument} */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = ApiError,\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 { TypedRecordInstance, TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n CacheOptions,\n ConstrainedRequestOptions,\n PostQueryRequestOptions,\n QueryRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { ApiError } from '@warp-drive-mirror/core/types/spec/error';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\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-mirror/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-mirror/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-mirror/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 * @badge Builder\n */\nexport function query<\n T extends TypedRecordInstance,\n M extends Meta | undefined = Meta | undefined,\n E extends object = ApiError,\n>(\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(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-mirror/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-mirror/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 type - the name of the resource type to query\n * @param query - the query params to send with the request\n * @param options - options to modify the request behavior\n */\nexport function postQuery<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function postQuery(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions;\nexport function postQuery(\n type: string,\n // oxlint-disable-next-line 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-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 { ApiError } from '@warp-drive-mirror/core/types/spec/error';\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 } from '../../string.ts';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-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 * :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**\n * While this may come as a surprise, the app providing the body ensures that only\n * desired and correctly formatted data is sent with the request.\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-mirror/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-mirror/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 * :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**\n * While this may come as a surprise, the app providing the body ensures that only\n * desired and correctly formatted data is sent with the request.\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 { cacheKeyFor } from '@warp-drive-mirror/core';\n * import { createRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const person = store.createRecord<Person>('person', { name: 'Ted' });\n * const init = createRecord(person);\n * init.body = JSON.stringify(\n * {\n * // it's likely you will want to transform this data\n * // somewhat\n * data: store.cache.peek(cacheKeyFor(person))\n * }\n * );\n * const data = await store.request(init);\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/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 * :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**\n * While this may come as a surprise, the app providing the body ensures that only\n * desired and correctly formatted data is sent with the request.\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 * **Example Usage**\n *\n * ```ts\n * import { cacheKeyFor } from '@warp-drive-mirror/core';\n * import { updateRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { EditablePerson } from '#/data/types';\n *\n * const mutable = await checkout<EditablePerson>(person);\n * mutable.name = 'Chris';\n * const init = updateRecord(mutable);\n *\n * init.body = JSON.stringify(\n * // it's likely you will want to transform this data\n * // somewhat, or serialize only specific properties instead\n * serializePatch(store.cache, cacheKeyFor(mutable))\n * );\n * const data = await store.request(init);\n * ```\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/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<\n T extends TypedRecordInstance,\n RT extends TypedRecordInstance = T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = ApiError,\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(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-mirror/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-mirror/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-mirror/core/build-config/macros';\nimport type { Cache } from '@warp-drive-mirror/core/types/cache';\nimport type { Relationship } from '@warp-drive-mirror/core/types/cache/relationship';\nimport type { ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { Value } from '@warp-drive-mirror/core/types/json/raw';\nimport type { InnerRelationshipDocument, ResourceObject } from '@warp-drive-mirror/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 * :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**\n *\n * While this may come as a surprise, they are intended to serialize cache state for more\n * generalized usage. {json:api} has a large variance in acceptable shapes, and only your\n * app can ensure that the body is correctly formatted and contains all necessary data.\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 - the cache to serialize the resource(s) from\n * @param identifiers - the resource(s) to serialize\n * @return an object with a `data` property containing the serialized resource(s)\n */\nexport function serializeResources(\n cache: Cache,\n identifiers: ResourceKey\n): {\n /**\n * The serialized resource.\n */\n data: ResourceObject;\n};\nexport function serializeResources(\n cache: Cache,\n identifiers: ResourceKey[]\n): {\n /**\n * The serialized resources.\n */\n data: ResourceObject[];\n};\nexport function serializeResources(\n cache: Cache,\n identifiers: ResourceKey | ResourceKey[]\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: ResourceKey): 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 * :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**\n *\n * While this may come as a surprise, they are intended to serialize cache state for more\n * generalized usage. {json:api} has a large variance in acceptable shapes, and only your\n * app can ensure that the body is correctly formatted and contains all necessary data.\n * :::\n *\n * Serializes changes to a resource. Useful for use with building bodies for 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 - the cache to serialize the resource's changes from\n * @param identifier - the resource whose changes should be serialized\n * @return an object with a `data` property containing the serialized resource patch\n */\nexport function serializePatch(\n cache: Cache,\n identifier: ResourceKey\n // options: { include?: string[] } = {}\n): {\n /**\n * The serialized resource patch.\n */\n data: JsonApiResourcePatch;\n} {\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}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AA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MACE,oBAAoBC,OAAOhB,EAAE,EAAC,YAAaE,KAAI,WAAYD,IAAG,0CAA2C;CAAA,EAAA,CACzGV,MAAMiB,KAAKX,UAAU,CAAC;CAGxB,MAAMJ,OACJO,OAAO,OACH;EAAEE;EAAMD;EAAKD;CAAG,IAChB;EACEE;EACAF;CACF;CAEN,IAAIT,MAAMiC,gBAAgB3B,UAAU,GAAG;EACrC,MAAM4B,eAAelC,MAAMmC,aAAa7B,UAAU;EAClD,MAAM8B,aAA2C,CAAC;EAElDR,OAAOC,KAAKK,YAAY,CAAC,CAACG,SAASV,QAAQ;GAEzC,MAAMY,SADSL,aAAaP,IACP,CAAC;GACtBS,WAAWT,OAAOY,WAAWC,SAAY,OAAOxB,gBAAgBuB,MAAM;EACxE,CAAC;EAEDrC,KAAKkC,aAAaA;CACpB;CAEA,MAAMK,uBAAuBzC,MAAMyC,qBAAqBnC,UAAU;CAClE,IAAImC,qBAAqBC,MAAM;EAC7B,MAAMhB,gBAAyD,CAAC;EAChEe,qBAAqBJ,SAASM,MAAMhB,QAAQ;GAC1CD,cAAcC,OAAO,EAAEzB,MAAMU,WAAW+B,KAAKC,UAAU,EAAE;EAC3D,CAAC;EAED1C,KAAKwB,gBAAgBA;CACvB;CAEA,OAAO,EAAExB,KAAK;AAChB"}
|
|
1
|
+
{"version":3,"file":"json-api.js","names":["buildQueryParams","buildParams","setBuildURLConfig","setConfig","JsonApiAccept","DEFAULT_CONFIG","host","namespace","CONFIG","ACCEPT_HEADER_VALUE","config","Object","assign","profiles","extensions","accept","values","length","join","isJsonApiQuery","query","include","collapseIncludePaths","basePath","paths","keys","i","push","key","value","split","forEach","field","Array","isArray","URLSearchParams","fields","page","rest","finalQuery","includePaths","sort","resourceType","toSorted","recordIdentifierFor","buildBaseURL","pluralize","copyForwardUrlOptions","ACCEPT_HEADER_VALUE","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","patchRecord","opts","serializeResources","cache","identifiers","data","Array","isArray","map","identifier","_serializeResource","fixRef","id","lid","type","fixRelData","rel","ref","record","structuredClone","peek","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","String","relationships","key","Object","keys","relationship","length","serializePatch","hasChangedAttrs","attrsChanges","changedAttrs","attributes","forEach","change","newVal","undefined","changedRelationships","size","diff","localState"],"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-mirror/core/types/params';\n\nimport type { BuildURLConfig } from '../../index.ts';\nimport { buildQueryParams as buildParams, setBuildURLConfig as setConfig } from '../../index.ts';\n\n/**\n * The configuration {@link setBuildURLConfig} accepts: the {@link BuildURLConfig} fields, plus\n * the {json:api} profile and extension URIs to send in the `Accept` header.\n *\n * @summary Configuration for the JSON:API request builders: host, namespace, and the profile and extension URIs for `Accept`.\n * @public\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 * The [Basic Usage](/guides/the-manual/cookbook/basic-usage#step-2-configure-some-request-defaults)\n * guide uses it to configure a host, a namespace and a pagination profile.\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-mirror/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 * @summary Sets the JSON:API extensions and profiles sent in the `Accept` header, plus the global URL host and\n * namespace.\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;\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 // toSorted: `value` belongs to the caller, sorting it in place would\n // reorder whatever else they are doing with it\n finalQuery[`fields[${resourceType}]`] = value.toSorted().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 { 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 { ApiError } from '@warp-drive-mirror/core/types/spec/error';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\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 * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * :::tabs\n *\n * == Basic Usage\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const result = await store.request(\n * findRecord<Person>('person', '1')\n * );\n * ```\n *\n * == With Options\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const data = await store.request(\n * findRecord<Person>(\n * 'person', '1',\n * { include: ['pets', 'friends'] }\n * )\n * );\n * ```\n *\n * == With an Identifier\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const data = await store.request(\n * findRecord<Person>(\n * { type: 'person', id: '1' },\n * { include: ['pets', 'friends'] }\n * )\n * );\n * ```\n *\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-mirror/utilities/json-api';\n *\n * const data = await store.request(\n * findRecord(\n * 'person', '1',\n * { include: ['pets', 'friends'] },\n * { namespace: 'api/v2' }\n * )\n * );\n * ```\n *\n * @summary Builds a JSON:API `GET` request for one resource by type and id, with optional `include`.\n * @public\n */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(\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 = ApiError>(\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(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\n/** @deprecated use {@link ReactiveDataDocument} */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = ApiError,\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 { TypedRecordInstance, TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n CacheOptions,\n ConstrainedRequestOptions,\n PostQueryRequestOptions,\n QueryRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { ApiError } from '@warp-drive-mirror/core/types/spec/error';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\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 * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\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-mirror/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-mirror/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-mirror/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a JSON:API `GET` request that queries a resource type, sending the query as URL query params.\n * @public\n * @badge Builder\n */\nexport function query<\n T extends TypedRecordInstance,\n M extends Meta | undefined = Meta | undefined,\n E extends object = ApiError,\n>(\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(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 * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\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-mirror/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-mirror/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a JSON:API `POST` request that sends a query as the JSON body, cached under a key built from the\n * query params.\n * @public\n * @param type - the name of the resource type to query\n * @param query - the query params to send with the request\n * @param options - options to modify the request behavior\n */\nexport function postQuery<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function postQuery(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions;\nexport function postQuery(\n type: string,\n // oxlint-disable-next-line 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-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 { ApiError } from '@warp-drive-mirror/core/types/spec/error';\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 } from '../../string.ts';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-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 * :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**\n * While this may come as a surprise, the app providing the body ensures that only\n * desired and correctly formatted data is sent with the request.\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 * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/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-mirror/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 * @summary Builds a JSON:API `DELETE` request that persists deletion of an existing record.\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 * :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**\n * While this may come as a surprise, the app providing the body ensures that only\n * desired and correctly formatted data is sent with the request.\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 * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { cacheKeyFor } from '@warp-drive-mirror/core';\n * import { createRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { Person } from '#/data/types';\n *\n * const person = store.createRecord<Person>('person', { name: 'Ted' });\n * const init = createRecord(person);\n * init.body = JSON.stringify(\n * {\n * // it's likely you will want to transform this data\n * // somewhat\n * data: store.cache.peek(cacheKeyFor(person))\n * }\n * );\n * const data = await store.request(init);\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/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 * @summary Builds a JSON:API `POST` request for saving a new record; the app must set the request body itself.\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 * :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**\n * While this may come as a surprise, the app providing the body ensures that only\n * desired and correctly formatted data is sent with the request.\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 * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Example Usage**\n *\n * ```ts\n * import { cacheKeyFor } from '@warp-drive-mirror/core';\n * import { updateRecord } from '@warp-drive-mirror/utilities/json-api';\n * import type { EditablePerson } from '#/data/types';\n *\n * const mutable = await checkout<EditablePerson>(person);\n * mutable.name = 'Chris';\n * const init = updateRecord(mutable);\n *\n * init.body = JSON.stringify(\n * // it's likely you will want to transform this data\n * // somewhat, or serialize only specific properties instead\n * serializePatch(store.cache, cacheKeyFor(mutable))\n * );\n * const data = await store.request(init);\n * ```\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/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 * @summary Builds a JSON:API `PUT` (or `PATCH`) request for saving an existing record; the app must set the request\n * body itself.\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 = ApiError,\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(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-mirror/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-mirror/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-mirror/core/build-config/macros';\nimport type { Cache } from '@warp-drive-mirror/core/types/cache';\nimport type { Relationship } from '@warp-drive-mirror/core/types/cache/relationship';\nimport type { ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { Value } from '@warp-drive-mirror/core/types/json/raw';\nimport type { InnerRelationshipDocument, ResourceObject } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\ntype ChangedRelationshipData = InnerRelationshipDocument;\n\n/**\n * The resource object {@link serializePatch} produces: the resource's `type` and `id` (or `lid`\n * for a new record) with only its changed attributes and relationships.\n *\n * @summary A JSON:API resource object holding only a record's changed attributes and relationships, as produced by `serializePatch`.\n * @public\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 * :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**\n *\n * While this may come as a surprise, they are intended to serialize cache state for more\n * generalized usage. {json:api} has a large variance in acceptable shapes, and only your\n * app can ensure that the body is correctly formatted and contains all necessary data.\n * :::\n *\n * Serializes the current state of a resource or array of resources for use with POST or PUT requests.\n *\n * @summary Copies the cached state of one or more resources into a JSON:API-style `{ data }` object, a starting point\n * for request bodies.\n * @public\n * @param cache - the cache to serialize the resource(s) from\n * @param identifiers - the resource(s) to serialize\n * @return an object with a `data` property containing the serialized resource(s)\n */\nexport function serializeResources(\n cache: Cache,\n identifiers: ResourceKey\n): {\n /**\n * The serialized resource.\n */\n data: ResourceObject;\n};\nexport function serializeResources(\n cache: Cache,\n identifiers: ResourceKey[]\n): {\n /**\n * The serialized resources.\n */\n data: ResourceObject[];\n};\nexport function serializeResources(\n cache: Cache,\n identifiers: ResourceKey | ResourceKey[]\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: ResourceKey): 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 * :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**\n *\n * While this may come as a surprise, they are intended to serialize cache state for more\n * generalized usage. {json:api} has a large variance in acceptable shapes, and only your\n * app can ensure that the body is correctly formatted and contains all necessary data.\n * :::\n *\n * Serializes changes to a resource. Useful for use with building bodies for 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 * @summary Serializes only a resource's changed attributes and relationships from the cache into a JSON:API-style\n * `{ data }` patch.\n * @public\n * @param cache - the cache to serialize the resource's changes from\n * @param identifier - the resource whose changes should be serialized\n * @return an object with a `data` property containing the serialized resource patch\n */\nexport function serializePatch(\n cache: Cache,\n identifier: ResourceKey\n // options: { include?: string[] } = {}\n): {\n /**\n * The serialized resource patch.\n */\n data: JsonApiResourcePatch;\n} {\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"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAMI,gBAAgB;AACtB,MAAMC,iBAAgC;CAAEC,MAAM;CAAIC,WAAW;AAAG;AAChE,IAAWC,SAAwBH;AACnC,IAAWI,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CjC,SAAgBP,kBAAkBQ,QAA6B;CAC7DF,SAASG,OAAOC,OAAO,CAAC,GAAGP,gBAAgBK,MAAM;CAEjD,IAAIA,OAAOG,YAAYH,OAAOI,YAAY;EACxC,IAAIC,SAASX;EACb,IAAIM,OAAOG,UAAU;GACnB,MAAMA,WAAWF,OAAOK,OAAON,OAAOG,QAAQ;GAC9C,IAAIA,SAASI,QACXF,UAAU,gBAAeF,SAASK,KAAK,GAAG,IAAI;EAElD;EACA,IAAIR,OAAOI,YAAY;GACrB,MAAMA,aAAaH,OAAOK,OAAON,OAAOI,UAAU;GAClD,IAAIA,WAAWG,QACbF,UAAU,UAAUD,WAAWI,KAAK,GAAG;EAE3C;EACAT,sBAAsBM;CACxB;CAEAZ,oBAAUO,MAAM;AAClB;;;ACeA,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,IAAI;CACzC;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAA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