@warp-drive/utilities 5.6.0-alpha.12 → 5.6.0-alpha.14

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.
@@ -5,6 +5,10 @@ import type { RequestContext, StructuredDataDocument } from '@warp-drive/core/ty
5
5
  * If CheckFn returns false, the wrapped handler will be skipped.
6
6
  */
7
7
  type CheckFn = (context: RequestContext) => boolean;
8
+ /**
9
+ *
10
+ * @public
11
+ */
8
12
  export declare class Gate implements Handler {
9
13
  handler: Handler;
10
14
  checkFn: CheckFn;
@@ -1 +1 @@
1
- {"version":3,"file":"gated.d.ts","sourceRoot":"","sources":["../../../src/-private/handlers/gated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAE7F;;;GAGG;AACH,KAAK,OAAO,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC;AAEpD,qBAAa,IAAK,YAAW,OAAO;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;gBAEb,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO;IAK9C,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAMnH"}
1
+ {"version":3,"file":"gated.d.ts","sourceRoot":"","sources":["../../../src/-private/handlers/gated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,E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,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACzD,CAAC;AAEN;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC;AAChH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG;IAAE,IAAI,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC;AAwEpH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,sBAAsB,GAEjC;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAuChC"}
@@ -1,70 +1,3 @@
1
- /**
2
- *
3
- *
4
- *This package provides utilities for working with [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html#convention-over-configuration-in-active-record) APIs.
5
- *
6
- * ## Installation
7
- *
8
- * Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
9
- *
10
- * ::: code-group
11
- *
12
- * ```sh [pnpm]
13
- * pnpm add -E @ember-data/active-record
14
- * ```
15
- *
16
- * ```sh [npm]
17
- * npm add -E @ember-data/active-record
18
- * ```
19
- *
20
- * ```sh [yarn]
21
- * yarn add -E @ember-data/active-record
22
- * ```
23
- *
24
- * ```sh [bun]
25
- * bun add --exact @ember-data/active-record
26
- * ```
27
- *
28
- * :::
29
- *
30
- * ## Usage
31
- *
32
- * Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
33
- * They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
34
- *
35
- * For instance, to construct a request that would fetch a resource from your API:
36
- *
37
- * ```ts
38
- * import { findRecord } from '@ember-data/active-record/request';
39
- *
40
- * const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
41
- * ```
42
- *
43
- * This would produce the following request object:
44
- *
45
- * ```js
46
- * {
47
- * url: 'https://api.example.com/v1/ember_developers/1?include=friends,pets',
48
- * method: 'GET',
49
- * headers: <Headers>, // 'Accept': 'application/json;charset=utf-8'
50
- * op: 'findRecord';
51
- * records: [{ type: 'ember-developer', id: '1' }]
52
- * }
53
- * ```
54
- *
55
- * Request builder output may be used with either `requestManager.request` or `store.request`.
56
- *
57
- * ```ts
58
- * const data = await store.request(options);
59
- * ```
60
- *
61
- * URLs are stable. The same query will produce the same URL every time, even if the order of keys in
62
- * the query or values in an array changes.
63
- *
64
- * URLs follow the most common ActiveRecord format (underscored pluralized resource types).
65
- *
66
- * @module
67
- */
68
1
  export { findRecord } from './-private/active-record/find-record';
69
2
  export { query } from './-private/active-record/query';
70
3
  export { deleteRecord, createRecord, updateRecord } from './-private/active-record/save-record';
@@ -1 +1 @@
1
- {"version":3,"file":"active-record.d.ts","sourceRoot":"","sources":["../src/active-record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"active-record.d.ts","sourceRoot":"","sources":["../src/active-record.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC"}
@@ -5,4 +5,6 @@
5
5
  * @module
6
6
  */
7
7
  export { AutoCompress, SupportsRequestStreams } from './-private/handlers/auto-compress.ts';
8
+ export { Gate } from './-private/handlers/gated.ts';
9
+ export { addTraceHeader, TAB_ASSIGNED, TAB_ID, assertInvalidUrlLength, MAX_URL_LENGTH, } from './-private/handlers/utils.ts';
8
10
  //# sourceMappingURL=handlers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC5F,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACpD,OAAO,EACL,cAAc,EACd,YAAY,EACZ,MAAM,EACN,sBAAsB,EACtB,cAAc,GACf,MAAM,8BAA8B,CAAC"}
@@ -1,42 +1,8 @@
1
- import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';
2
1
  /**
3
- * Simple utility function to assist in url building,
4
- * query params, and other common request operations.
5
- *
6
- * These primitives may be used directly or composed
7
- * by request builders to provide a consistent interface
8
- * for building requests.
9
- *
10
- * For instance:
11
- *
12
- * ```ts
13
- * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
14
- *
15
- * const baseURL = buildBaseURL({
16
- * host: 'https://api.example.com',
17
- * namespace: 'api/v1',
18
- * resourcePath: 'emberDevelopers',
19
- * op: 'query',
20
- * identifier: { type: 'ember-developer' }
21
- * });
22
- * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
23
- * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'
24
- * ```
25
- *
26
- * This is useful, but not as useful as the REST request builder for query which is sugar
27
- * over this (and more!):
28
- *
29
- * ```ts
30
- * import { query } from '@ember-data/rest/request';
31
- *
32
- * const options = query('ember-developer', { name: 'Chris', include:['pets'] });
33
- * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
34
- * // Note: options will also include other request options like headers, method, etc.
35
- * ```
36
- *
37
2
  * @module
38
- * @public
3
+ * @mergeModuleWith <project>
39
4
  */
5
+ import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';
40
6
  export interface BuildURLConfig {
41
7
  host: string | null;
42
8
  namespace: string | null;
@@ -75,8 +41,6 @@ export interface BuildURLConfig {
75
41
  * ```
76
42
  *
77
43
  * @public
78
- * @param {BuildURLConfig} config
79
- * @return {void}
80
44
  */
81
45
  export declare function setBuildURLConfig(config: BuildURLConfig): void;
82
46
  export interface FindRecordUrlOptions {
@@ -200,8 +164,6 @@ export type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOpt
200
164
  * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
201
165
  *
202
166
  * @public
203
- * @param urlOptions
204
- * @return {String}
205
167
  */
206
168
  export declare function buildBaseURL(urlOptions: UrlOptions): string;
207
169
  /**
@@ -209,8 +171,8 @@ export declare function buildBaseURL(urlOptions: UrlOptions): string;
209
171
  * returning a new object with only those keys that have truthy values / non-empty arrays
210
172
  *
211
173
  * @public
212
- * @param {Record<string, Serializable>} source object to filter keys with empty values from
213
- * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
174
+ * @param source object to filter keys with empty values from
175
+ * @return A new object with the keys that contained empty values removed
214
176
  */
215
177
  export declare function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable>;
216
178
  /**
@@ -228,9 +190,7 @@ export declare function filterEmpty(source: Record<string, Serializable>): Recor
228
190
  * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
229
191
  *
230
192
  * @public
231
- * @param {URLSearchParams | object} params
232
- * @param {Object} options
233
- * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
193
+ * @return A {@link URLSearchParams} with keys inserted in sorted order
234
194
  */
235
195
  export declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams;
236
196
  /**
@@ -247,9 +207,7 @@ export declare function sortQueryParams(params: QueryParamsSource, options?: Que
247
207
  * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
248
208
  *
249
209
  * @public
250
- * @param {URLSearchParams | Object} params
251
- * @param {Object} [options]
252
- * @return {String} A sorted query params string without the leading `?`
210
+ * @return A sorted query params string without the leading `?`
253
211
  */
254
212
  export declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;
255
213
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEtH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAMH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,QAsBvD;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EA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AAE,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,UAAU,GAClB,oBAAoB,GACpB,eAAe,GACf,kBAAkB,GAClB,+BAA+B,GAC/B,6BAA6B,GAC7B,sBAAsB,GACtB,sBAAsB,GACtB,sBAAsB,GACtB,iBAAiB,CAAC;AAiCtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAsG3D;AAcD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAY9F;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,+BAA+B,GAAG,eAAe,CA0DrH;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,+BAA+B,GAAG,MAAM,CAE7G"}
@@ -1,48 +1,3 @@
1
- /**
2
- This package provides utilities for working with [JSON:API](https://json-api.org) APIs with [*Ember***Data**](https://github.com/emberjs/data/).
3
-
4
- ## Installation
5
-
6
- Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
7
-
8
- ```no-highlight
9
- pnpm add @ember-data/json-api
10
- ```
11
-
12
- ## Usage
13
-
14
- Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
15
- They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
16
-
17
- For instance, to fetch a resource from your API
18
-
19
- ```ts
20
- import { findRecord } from '@ember-data/json-api/request';
21
-
22
- const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
23
-
24
- /*
25
- {
26
- url: 'https://api.example.com/v1/ember-developers/1?include=friends,pets',
27
- method: 'GET',
28
- headers: <Headers>,
29
- // => 'Accept': 'application/vnd.api+json'
30
- // => 'Content-Type': 'application/vnd.api+json'
31
- op: 'findRecord';
32
- records: [{ type: 'ember-developer', id: '1' }]
33
- }
34
- *\
35
- ```
36
-
37
- Request builder output may be used with either `requestManager.request` or `store.request`.
38
-
39
- URLs are stable. The same query will produce the same URL every time, even if the order of keys in
40
- the query or values in an array changes.
41
-
42
- URLs follow the most common JSON:API format (dasherized pluralized resource types).
43
- *
44
- * @module
45
- */
46
1
  export { findRecord } from './-private/json-api/find-record';
47
2
  export { query, postQuery } from './-private/json-api/query';
48
3
  export { deleteRecord, createRecord, updateRecord } from './-private/json-api/save-record';
@@ -1 +1 @@
1
- {"version":3,"file":"json-api.d.ts","sourceRoot":"","sources":["../src/json-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"json-api.d.ts","sourceRoot":"","sources":["../src/json-api.ts"],"names":[],"mappings":"AAkDA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -1,50 +1,3 @@
1
- /**
2
- This package provides utilities for working with **REST**ful APIs with [*Ember***Data**](https://github.com/emberjs/data/).
3
-
4
- ## Installation
5
-
6
- Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
7
-
8
- ```no-highlight
9
- pnpm add @ember-data/json-api
10
- ```
11
-
12
- ## Usage
13
-
14
- Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
15
- They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
16
-
17
- For instance, to fetch a resource from your API
18
-
19
- ```ts
20
- import { findRecord } from '@ember-data/rest/request';
21
-
22
- const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
23
-
24
- /*
25
- => {
26
- url: 'https://api.example.com/v1/emberDevelopers/1?include=friends,pets',
27
- method: 'GET',
28
- headers: <Headers>, // 'Content-Type': 'application/json;charset=utf-8'
29
- op: 'findRecord';
30
- records: [{ type: 'ember-developer', id: '1' }]
31
- }
32
- * /
33
- ```
34
-
35
- Request builder output is ready to go for use with [store.request](https://api.emberjs.com/ember-data/release/classes/Store/methods/request?anchor=request),
36
- [manager.request](https://api.emberjs.com/ember-data/release/classes/RequestManager/methods/request?anchor=request) and most conventional REST APIs.
37
-
38
- Resource types are pluralized and camelized for the url.
39
-
40
- URLs are stable. The same query will produce the same URL every time, even if the order of keys in
41
- the query or values in an array changes.
42
-
43
- URLs follow the most common REST format (camelCase pluralized resource types).
44
-
45
- * @module
46
- * @public
47
- */
48
1
  export { findRecord } from './-private/rest/find-record';
49
2
  export { query } from './-private/rest/query';
50
3
  export { deleteRecord, createRecord, updateRecord } from './-private/rest/save-record';
@@ -1 +1 @@
1
- {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
@@ -8,6 +8,7 @@
8
8
  * using the `setMaxLRUCacheSize` function. The default size is 10,000.
9
9
  *
10
10
  * @module
11
+ * @public
11
12
  */
12
13
  export { pluralize, singularize, singular, plural, loadIrregular, loadUncountable, irregular, uncountable, resetToDefaults, clear, clearRules, } from './-private/string/inflect.ts';
13
14
  export { dasherize, camelize, capitalize, underscore, setMaxLRUCacheSize } from './-private/string/transform.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,MAAM,EACN,aAAa,EACb,eAAe,EACf,SAAS,EACT,WAAW,EACX,eAAe,EACf,KAAK,EACL,UAAU,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,MAAM,EACN,aAAa,EACb,eAAe,EACf,SAAS,EACT,WAAW,EACX,eAAe,EACf,KAAK,EACL,UAAU,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
package/dist/handlers.js CHANGED
@@ -146,4 +146,94 @@ function encodingForFormat(format) {
146
146
  return format;
147
147
  }
148
148
  }
149
- export { AutoCompress, SupportsRequestStreams };
149
+
150
+ /**
151
+ * If CheckFn returns true, the wrapped handler will be used.
152
+ * If CheckFn returns false, the wrapped handler will be skipped.
153
+ */
154
+
155
+ /**
156
+ *
157
+ * @public
158
+ */
159
+ class Gate {
160
+ constructor(handler, checkFn) {
161
+ this.handler = handler;
162
+ this.checkFn = checkFn;
163
+ }
164
+ request(context, next) {
165
+ if (this.checkFn(context)) {
166
+ return this.handler.request(context, next);
167
+ }
168
+ return next(context.request);
169
+ }
170
+ }
171
+ if (typeof FastBoot === 'undefined') {
172
+ globalThis.addEventListener('beforeunload', function () {
173
+ sessionStorage.setItem('tab-closed', 'true');
174
+ });
175
+ }
176
+ function getTabId() {
177
+ if (typeof sessionStorage === 'undefined') {
178
+ return crypto.randomUUID();
179
+ }
180
+ const tabId = sessionStorage.getItem('tab-id');
181
+ if (tabId) {
182
+ const tabClosed = sessionStorage.getItem('tab-closed');
183
+ if (tabClosed === 'true') {
184
+ return tabId;
185
+ }
186
+
187
+ // fall through to generate a new tab id
188
+ }
189
+ const newTabId = crypto.randomUUID();
190
+ sessionStorage.setItem('tab-id', newTabId);
191
+ return newTabId;
192
+ }
193
+
194
+ /**
195
+ * A unique identifier for the current browser tab
196
+ * useful for observability/tracing and deduping
197
+ * across multiple tabs.
198
+ */
199
+ const TAB_ID = getTabId();
200
+ /**
201
+ * The epoch seconds at which the tab id was generated
202
+ */
203
+ const TAB_ASSIGNED = Math.floor(Date.now() / 1000);
204
+
205
+ /**
206
+ * Adds the `X-Amzn-Trace-Id` header to support observability
207
+ * tooling around request routing.
208
+ *
209
+ * This makes use of the {@link TAB_ID} and {@link TAB_ASSIGNED}
210
+ * to enable tracking the browser tab of origin across multiple requests.
211
+ *
212
+ * Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
213
+ */
214
+ function addTraceHeader(headers) {
215
+ const now = Math.floor(Date.now() / 1000);
216
+ headers.set('X-Amzn-Trace-Id', `Root=1-${now}-${crypto.randomUUID()};TabId=1-${TAB_ASSIGNED}-${TAB_ID}`);
217
+ return headers;
218
+ }
219
+
220
+ /**
221
+ * Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
222
+ * As of 2024-12-05 the maximum URL length is 8192 bytes.
223
+ *
224
+ */
225
+ const MAX_URL_LENGTH = 8192;
226
+
227
+ /**
228
+ * This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
229
+ *
230
+ * See also {@link MAX_URL_LENGTH}
231
+ */
232
+ function assertInvalidUrlLength(url) {
233
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
234
+ if (!test) {
235
+ throw new Error(`URL length ${url?.length} exceeds the maximum URL length of ${MAX_URL_LENGTH} bytes.\n\nConsider converting this request query a \`/query\` endpoint instead of a GET, or upgrade the current endpoint to be able to receive a POST request directly (ideally specifying the header HTTP-Method-Override: QUERY)\n\nThe Invalid URL is:\n\n${url}`);
236
+ }
237
+ })(!url || url.length <= MAX_URL_LENGTH) : {};
238
+ }
239
+ export { AutoCompress, Gate, MAX_URL_LENGTH, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.js","sources":["../src/-private/handlers/auto-compress.ts"],"sourcesContent":["import { assert } from '@warp-drive/core/build-config/macros';\nimport type { Future, Handler, NextFn } from '@warp-drive/core/request';\nimport type { HTTPMethod, RequestContext } from '@warp-drive/core/types/request';\n\nfunction isCompressibleMethod(method?: HTTPMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';\n}\n\nexport const SupportsRequestStreams = (() => {\n let duplexAccessed = false;\n\n const hasContentType = new Request('', {\n body: new ReadableStream(),\n method: 'POST',\n // @ts-expect-error untyped\n get duplex() {\n duplexAccessed = true;\n return 'half';\n },\n }).headers.has('Content-Type');\n\n return duplexAccessed && !hasContentType;\n})();\n\ninterface Constraints {\n /**\n * The minimum size at which to compress blobs\n *\n * @default 1000\n */\n Blob?: number;\n /**\n * The minimum size at which to compress array buffers\n *\n * @default 1000\n */\n ArrayBuffer?: number;\n /**\n * The minimum size at which to compress typed arrays\n *\n * @default 1000\n */\n TypedArray?: number;\n /**\n * The minimum size at which to compress data views\n *\n * @default 1000\n */\n DataView?: number;\n /**\n * The minimum size at which to compress strings\n *\n * @default 1000\n */\n String?: number;\n}\n\n/**\n * Options for configuring the AutoCompress handler.\n *\n */\ninterface CompressionOptions {\n /**\n * The compression format to use. Must be a valid\n * compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The default is `gzip`.\n *\n */\n format?: CompressionFormat;\n\n /**\n * Some browsers support `ReadableStream` as a request body. This option\n * enables passing the compression stream as the request body instead of\n * the final compressed body when the browser supports doing so.\n *\n * This comes with several caveats:\n *\n * - the request will be put into `duplex: 'half'` mode. This should be\n * transparent to you, but it is worth noting.\n * - the request mode cannot be `no-cors` as requests with a `ReadableStream`\n * have no content length and thus are a new form of request that triggers\n * cors requirements and a preflight request.\n * - http/1.x is not supported.\n *\n * For additional reading about the restrictions of using `ReadableStream`\n * as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)\n *\n * Streaming can be enabled per-request in browsers which support it by\n * setting `request.options.allowStreaming` to `true`.\n *\n * Streaming can be forced even when the browser does not support it by setting\n * `request.options.forceStreaming` to `true`. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n */\n allowStreaming?: boolean;\n\n /**\n * If `true`, the request will be forced into streaming mode even\n * if the browser does not support it. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n */\n forceStreaming?: boolean;\n\n /**\n * The constraints for the request body. This is used to determine\n * whether to compress the request body or not.\n *\n * The defaults are:\n *\n * ```ts\n * {\n * Blob: 1000, // blob.size\n * ArrayBuffer: 1000, // buffer.byteLength\n * TypedArray: 1000, // array.byteLength\n * DataView: 1000, // view.byteLength\n * String: 1000, // string.length\n * }\n * ```\n *\n * The following body types are never compressed unless explicitly\n * configured by the request:\n * - `FormData`\n * - `URLSearchParams`\n * - `ReadableStream`\n *\n * A request.options.compress value of `false` will disable\n * compression for a request body of any type. While a value of\n * `true` will enable compression for the request.\n *\n * An undefined value will use the default, a value of `0` will\n * enable compression for all values, and a value of `-1` will\n * disable compression.\n *\n */\n constraints?: Constraints;\n}\n\nconst DEFAULT_CONSTRAINTS = {\n Blob: 1000,\n ArrayBuffer: 1000,\n TypedArray: 1000,\n DataView: 1000,\n String: 1000,\n};\nconst TypedArray = Object.getPrototypeOf(Uint8Array.prototype) as typeof Uint8Array;\n\n/**\n * A request handler that automatically compresses the request body\n * if the request body is a string, array buffer, blob, or form data.\n *\n * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The compression format as well as the kinds of data to compress can be\n * configured using the `format` and `constraints` options.\n *\n * ```diff\n * +import { AutoCompress } from '@ember-data/request-utils/handlers';\n * import Fetch from '@ember-data/request/fetch';\n * import RequestManager from '@ember-data/request';\n * import Store from '@ember-data/store';\n *\n * class AppStore extends Store {\n * requestManager = new RequestManager()\n * .use([\n * + new AutoCompress(),\n * Fetch\n * ]);\n * }\n * ```\n *\n * @class AutoCompress\n * @public\n * @since 5.5.0\n */\nexport class AutoCompress implements Handler {\n declare options: Required<CompressionOptions> & { constraints: Required<Constraints> };\n\n constructor(options: CompressionOptions = {}) {\n const opts = {\n format: options.format ?? 'gzip',\n constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),\n allowStreaming: options.allowStreaming ?? false,\n forceStreaming: options.forceStreaming ?? false,\n };\n this.options = opts;\n }\n\n request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T> {\n const { constraints } = this.options;\n const { body } = request;\n\n const shouldCompress =\n isCompressibleMethod(request.method) &&\n request.options?.compress !== false &&\n // prettier-ignore\n (request.options?.compress ? true\n : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length)\n : body instanceof Blob ? canCompress('Blob', constraints, body.size)\n : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength)\n : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength)\n : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength)\n : false);\n\n if (!shouldCompress) return next(request);\n\n // A convenient way to convert all of the supported body types to a readable\n // stream is to use a `Response` object body\n const response = new Response(request.body);\n const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));\n const headers = new Headers(request.headers);\n headers.set('Content-Encoding', encodingForFormat(this.options.format));\n\n //\n // For browsers that support it, `fetch` can receive a `ReadableStream` as\n // the body, so all we need to do is to create a new `ReadableStream` and\n // compress it on the fly\n //\n const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;\n const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;\n if (forceStreaming || (SupportsRequestStreams && allowStreaming)) {\n const req = Object.assign({}, request, {\n body: stream,\n headers,\n });\n if (SupportsRequestStreams) {\n // @ts-expect-error untyped\n req.duplex = 'half';\n }\n\n return next(req);\n\n //\n // For non-chromium browsers, we have to \"pull\" the stream to get the final\n // bytes and supply the final byte array as the new request body.\n //\n }\n\n // we need to pull the stream to get the final bytes\n const resp = new Response(stream);\n return resp.blob().then((blob) => {\n const req = Object.assign({}, request, {\n body: blob,\n headers,\n });\n return next(req);\n }) as Promise<T>;\n }\n}\n\nfunction canCompress(type: keyof Constraints, constraints: Required<Constraints>, size: number): boolean {\n // if we have a value of 0, we can compress anything\n if (constraints[type] === 0) return true;\n if (constraints[type] === -1) return false;\n return size >= constraints[type];\n}\n\nfunction encodingForFormat(format: CompressionFormat): string {\n switch (format) {\n case 'gzip':\n case 'deflate':\n case 'deflate-raw':\n return format;\n default:\n assert(`Unsupported compression format: ${format as unknown as string}`);\n // @ts-expect-error - unreachable code is reachable in production\n return format;\n }\n}\n"],"names":["isCompressibleMethod","method","SupportsRequestStreams","duplexAccessed","hasContentType","Request","body","ReadableStream","duplex","headers","has","DEFAULT_CONSTRAINTS","Blob","ArrayBuffer","TypedArray","DataView","String","Object","getPrototypeOf","Uint8Array","prototype","AutoCompress","constructor","options","opts","format","constraints","assign","allowStreaming","forceStreaming","request","next","shouldCompress","compress","canCompress","length","size","byteLength","response","Response","stream","pipeThrough","CompressionStream","Headers","set","encodingForFormat","req","resp","blob","then","type","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error"],"mappings":";;AAIA,SAASA,oBAAoBA,CAACC,MAAmB,EAAW;AAC1D,EAAA,OAAOA,MAAM,KAAK,MAAM,IAAIA,MAAM,KAAK,KAAK,IAAIA,MAAM,KAAK,OAAO,IAAIA,MAAM,KAAK,QAAQ;AAC3F;AAEaC,MAAAA,sBAAsB,GAAG,CAAC,MAAM;EAC3C,IAAIC,cAAc,GAAG,KAAK;AAE1B,EAAA,MAAMC,cAAc,GAAG,IAAIC,OAAO,CAAC,EAAE,EAAE;AACrCC,IAAAA,IAAI,EAAE,IAAIC,cAAc,EAAE;AAC1BN,IAAAA,MAAM,EAAE,MAAM;AACd;IACA,IAAIO,MAAMA,GAAG;AACXL,MAAAA,cAAc,GAAG,IAAI;AACrB,MAAA,OAAO,MAAM;AACf;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ACX,IAAA,KAAK,SAAS;AACd,IAAA,KAAK,aAAa;AAChB,MAAA,OAAOA,MAAM;AACf,IAAA;MACE0B,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,QAAA;AAAA,UAAA,MAAA,IAAAC,KAAA,CAAO,CAAmChC,gCAAAA,EAAAA,MAAM,CAAuB,CAAA,CAAA;AAAA;AAAA,OAAA,EAAA,CAAA,GAAA,EAAA;AACvE;AACA,MAAA,OAAOA,MAAM;AACjB;AACF;;;;"}
1
+ {"version":3,"file":"handlers.js","sources":["../src/-private/handlers/auto-compress.ts","../src/-private/handlers/gated.ts","../src/-private/handlers/utils.ts"],"sourcesContent":["import { assert } from '@warp-drive/core/build-config/macros';\nimport type { Future, Handler, NextFn } from '@warp-drive/core/request';\nimport type { HTTPMethod, RequestContext } from '@warp-drive/core/types/request';\n\nfunction isCompressibleMethod(method?: HTTPMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';\n}\n\nexport const SupportsRequestStreams = (() => {\n let duplexAccessed = false;\n\n const hasContentType = new Request('', {\n body: new ReadableStream(),\n method: 'POST',\n // @ts-expect-error untyped\n get duplex() {\n duplexAccessed = true;\n return 'half';\n },\n }).headers.has('Content-Type');\n\n return duplexAccessed && !hasContentType;\n})();\n\ninterface Constraints {\n /**\n * The minimum size at which to compress blobs\n *\n * @default 1000\n */\n Blob?: number;\n /**\n * The minimum size at which to compress array buffers\n *\n * @default 1000\n */\n ArrayBuffer?: number;\n /**\n * The minimum size at which to compress typed arrays\n *\n * @default 1000\n */\n TypedArray?: number;\n /**\n * The minimum size at which to compress data views\n *\n * @default 1000\n */\n DataView?: number;\n /**\n * The minimum size at which to compress strings\n *\n * @default 1000\n */\n String?: number;\n}\n\n/**\n * Options for configuring the AutoCompress handler.\n *\n */\ninterface CompressionOptions {\n /**\n * The compression format to use. Must be a valid\n * compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The default is `gzip`.\n *\n */\n format?: CompressionFormat;\n\n /**\n * Some browsers support `ReadableStream` as a request body. This option\n * enables passing the compression stream as the request body instead of\n * the final compressed body when the browser supports doing so.\n *\n * This comes with several caveats:\n *\n * - the request will be put into `duplex: 'half'` mode. This should be\n * transparent to you, but it is worth noting.\n * - the request mode cannot be `no-cors` as requests with a `ReadableStream`\n * have no content length and thus are a new form of request that triggers\n * cors requirements and a preflight request.\n * - http/1.x is not supported.\n *\n * For additional reading about the restrictions of using `ReadableStream`\n * as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)\n *\n * Streaming can be enabled per-request in browsers which support it by\n * setting `request.options.allowStreaming` to `true`.\n *\n * Streaming can be forced even when the browser does not support it by setting\n * `request.options.forceStreaming` to `true`. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n */\n allowStreaming?: boolean;\n\n /**\n * If `true`, the request will be forced into streaming mode even\n * if the browser does not support it. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n */\n forceStreaming?: boolean;\n\n /**\n * The constraints for the request body. This is used to determine\n * whether to compress the request body or not.\n *\n * The defaults are:\n *\n * ```ts\n * {\n * Blob: 1000, // blob.size\n * ArrayBuffer: 1000, // buffer.byteLength\n * TypedArray: 1000, // array.byteLength\n * DataView: 1000, // view.byteLength\n * String: 1000, // string.length\n * }\n * ```\n *\n * The following body types are never compressed unless explicitly\n * configured by the request:\n * - `FormData`\n * - `URLSearchParams`\n * - `ReadableStream`\n *\n * A request.options.compress value of `false` will disable\n * compression for a request body of any type. While a value of\n * `true` will enable compression for the request.\n *\n * An undefined value will use the default, a value of `0` will\n * enable compression for all values, and a value of `-1` will\n * disable compression.\n *\n */\n constraints?: Constraints;\n}\n\nconst DEFAULT_CONSTRAINTS = {\n Blob: 1000,\n ArrayBuffer: 1000,\n TypedArray: 1000,\n DataView: 1000,\n String: 1000,\n};\nconst TypedArray = Object.getPrototypeOf(Uint8Array.prototype) as typeof Uint8Array;\n\n/**\n * A request handler that automatically compresses the request body\n * if the request body is a string, array buffer, blob, or form data.\n *\n * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The compression format as well as the kinds of data to compress can be\n * configured using the `format` and `constraints` options.\n *\n * ```diff\n * +import { AutoCompress } from '@ember-data/request-utils/handlers';\n * import Fetch from '@ember-data/request/fetch';\n * import RequestManager from '@ember-data/request';\n * import Store from '@ember-data/store';\n *\n * class AppStore extends Store {\n * requestManager = new RequestManager()\n * .use([\n * + new AutoCompress(),\n * Fetch\n * ]);\n * }\n * ```\n *\n * @class AutoCompress\n * @public\n * @since 5.5.0\n */\nexport class AutoCompress implements Handler {\n declare options: Required<CompressionOptions> & { constraints: Required<Constraints> };\n\n constructor(options: CompressionOptions = {}) {\n const opts = {\n format: options.format ?? 'gzip',\n constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),\n allowStreaming: options.allowStreaming ?? false,\n forceStreaming: options.forceStreaming ?? false,\n };\n this.options = opts;\n }\n\n request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T> {\n const { constraints } = this.options;\n const { body } = request;\n\n const shouldCompress =\n isCompressibleMethod(request.method) &&\n request.options?.compress !== false &&\n // prettier-ignore\n (request.options?.compress ? true\n : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length)\n : body instanceof Blob ? canCompress('Blob', constraints, body.size)\n : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength)\n : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength)\n : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength)\n : false);\n\n if (!shouldCompress) return next(request);\n\n // A convenient way to convert all of the supported body types to a readable\n // stream is to use a `Response` object body\n const response = new Response(request.body);\n const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));\n const headers = new Headers(request.headers);\n headers.set('Content-Encoding', encodingForFormat(this.options.format));\n\n //\n // For browsers that support it, `fetch` can receive a `ReadableStream` as\n // the body, so all we need to do is to create a new `ReadableStream` and\n // compress it on the fly\n //\n const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;\n const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;\n if (forceStreaming || (SupportsRequestStreams && allowStreaming)) {\n const req = Object.assign({}, request, {\n body: stream,\n headers,\n });\n if (SupportsRequestStreams) {\n // @ts-expect-error untyped\n req.duplex = 'half';\n }\n\n return next(req);\n\n //\n // For non-chromium browsers, we have to \"pull\" the stream to get the final\n // bytes and supply the final byte array as the new request body.\n //\n }\n\n // we need to pull the stream to get the final bytes\n const resp = new Response(stream);\n return resp.blob().then((blob) => {\n const req = Object.assign({}, request, {\n body: blob,\n headers,\n });\n return next(req);\n }) as Promise<T>;\n }\n}\n\nfunction canCompress(type: keyof Constraints, constraints: Required<Constraints>, size: number): boolean {\n // if we have a value of 0, we can compress anything\n if (constraints[type] === 0) return true;\n if (constraints[type] === -1) return false;\n return size >= constraints[type];\n}\n\nfunction encodingForFormat(format: CompressionFormat): string {\n switch (format) {\n case 'gzip':\n case 'deflate':\n case 'deflate-raw':\n return format;\n default:\n assert(`Unsupported compression format: ${format as unknown as string}`);\n // @ts-expect-error - unreachable code is reachable in production\n return format;\n }\n}\n","import type { Future, Handler, NextFn } from '@warp-drive/core/request';\nimport type { RequestContext, StructuredDataDocument } from '@warp-drive/core/types/request';\n\n/**\n * If CheckFn returns true, the wrapped handler will be used.\n * If CheckFn returns false, the wrapped handler will be skipped.\n */\ntype CheckFn = (context: RequestContext) => boolean;\n\n/**\n *\n * @public\n */\nexport class Gate implements Handler {\n declare handler: Handler;\n declare checkFn: CheckFn;\n\n constructor(handler: Handler, checkFn: CheckFn) {\n this.handler = handler;\n this.checkFn = checkFn;\n }\n\n request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> {\n if (this.checkFn(context)) {\n return this.handler.request(context, next);\n }\n return next(context.request);\n }\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\n\nif (typeof FastBoot === 'undefined') {\n globalThis.addEventListener('beforeunload', function () {\n sessionStorage.setItem('tab-closed', 'true');\n });\n}\n\nfunction getTabId() {\n if (typeof sessionStorage === 'undefined') {\n return crypto.randomUUID();\n }\n\n const tabId = sessionStorage.getItem('tab-id');\n if (tabId) {\n const tabClosed = sessionStorage.getItem('tab-closed');\n if (tabClosed === 'true') {\n return tabId;\n }\n\n // fall through to generate a new tab id\n }\n\n const newTabId = crypto.randomUUID();\n sessionStorage.setItem('tab-id', newTabId);\n return newTabId;\n}\n\n/**\n * A unique identifier for the current browser tab\n * useful for observability/tracing and deduping\n * across multiple tabs.\n */\nexport const TAB_ID = getTabId();\n/**\n * The epoch seconds at which the tab id was generated\n */\nexport const TAB_ASSIGNED = Math.floor(Date.now() / 1000);\n\n/**\n * Adds the `X-Amzn-Trace-Id` header to support observability\n * tooling around request routing.\n *\n * This makes use of the {@link TAB_ID} and {@link TAB_ASSIGNED}\n * to enable tracking the browser tab of origin across multiple requests.\n *\n * Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`\n */\nexport function addTraceHeader(headers: Headers) {\n const now = Math.floor(Date.now() / 1000);\n headers.set('X-Amzn-Trace-Id', `Root=1-${now}-${crypto.randomUUID()};TabId=1-${TAB_ASSIGNED}-${TAB_ID}`);\n\n return headers;\n}\n\n/**\n * Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html\n * As of 2024-12-05 the maximum URL length is 8192 bytes.\n *\n */\nexport const MAX_URL_LENGTH = 8192;\n\n/**\n * This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.\n *\n * See also {@link MAX_URL_LENGTH}\n */\nexport function assertInvalidUrlLength(url: string | undefined) {\n assert(\n `URL length ${url?.length} exceeds the maximum URL length of ${MAX_URL_LENGTH} bytes.\\n\\nConsider converting this request query a \\`/query\\` endpoint instead of a GET, or upgrade the current endpoint to be able to receive a POST request directly (ideally specifying the header HTTP-Method-Override: QUERY)\\n\\nThe Invalid URL is:\\n\\n${url}`,\n !url || url.length <= MAX_URL_LENGTH\n );\n}\n"],"names":["isCompressibleMethod","method","SupportsRequestStreams","duplexAccessed","hasContentType","Request","body","ReadableStream","duplex","headers","has","DEFAULT_CONSTRAINTS","Blob","ArrayBuffer","TypedArray","DataView","String","Object","getPrototypeOf","Uint8Array","prototype","AutoCompress","constructor","options","opts","format","constraints","assign","allowStreaming","forceStreaming","request","next","shouldCompress","compress","canCompress","length","size","byteLength","response","Response","stream","pipeThrough","CompressionStream","Headers","set","encodingForFormat","req","resp","blob","then","type","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","Gate","handler","checkFn","context","FastBoot","globalThis","addEventListener","sessionStorage","setItem","getTabId","crypto","randomUUID","tabId","getItem","tabClosed","newTabId","TAB_ID","TAB_ASSIGNED","Math","floor","Date","now","addTraceHeader","MAX_URL_LENGTH","assertInvalidUrlLength","url"],"mappings":";;AAIA,SAASA,oBAAoBA,CAACC,MAAmB,EAAW;AAC1D,EAAA,OAAOA,MAAM,KAAK,MAAM,IAAIA,MAAM,KAAK,KAAK,IAAIA,MAAM,KAAK,OAAO,IAAIA,MAAM,KAAK,QAAQ;AAC3F;AAEaC,MAAAA,sBAAsB,GAAG,CAAC,MAAM;EAC3C,IAAIC,cAAc,GAAG,KAAK;AAE1B,EAAA,MAAMC,cAAc,GAAG,IAAIC,OAAO,CAAC,EAAE,EAAE;AACrCC,IAAAA,IAAI,EAAE,IAAIC,cAAc,EAAE;AAC1BN,IAAAA,MAAM,EAAE,MAAM;AACd;IACA,IAAIO,MAAMA,GAAG;AACXL,MAAAA,cAAc,GAAG,IAAI;AACrB,MAAA,OAAO,MAAM;AACf;AACF,GAAC,CAAC,CAACM,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;EAE9B,OAAOP,cAAc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AAAA,GAAG,CAAE,CAAA,CAAA;AAAA;AAAA,GAAA,EACnV,CAACA,GAAG,IAAIA,GAAG,CAAChD,MAAM,IAAI8C,cAAc,CAAA,GAAA,EAAA;AAExC;;;;"}
package/dist/index.js CHANGED
@@ -2,44 +2,10 @@ import { getOrSetGlobal } from '@warp-drive/core/types/-private';
2
2
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
3
3
 
4
4
  /**
5
- * Simple utility function to assist in url building,
6
- * query params, and other common request operations.
7
- *
8
- * These primitives may be used directly or composed
9
- * by request builders to provide a consistent interface
10
- * for building requests.
11
- *
12
- * For instance:
13
- *
14
- * ```ts
15
- * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
16
- *
17
- * const baseURL = buildBaseURL({
18
- * host: 'https://api.example.com',
19
- * namespace: 'api/v1',
20
- * resourcePath: 'emberDevelopers',
21
- * op: 'query',
22
- * identifier: { type: 'ember-developer' }
23
- * });
24
- * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
25
- * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'
26
- * ```
27
- *
28
- * This is useful, but not as useful as the REST request builder for query which is sugar
29
- * over this (and more!):
30
- *
31
- * ```ts
32
- * import { query } from '@ember-data/rest/request';
33
- *
34
- * const options = query('ember-developer', { name: 'Chris', include:['pets'] });
35
- * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
36
- * // Note: options will also include other request options like headers, method, etc.
37
- * ```
38
- *
39
5
  * @module
40
- * @public
6
+ * @mergeModuleWith <project>
41
7
  */
42
- // prevents the final constructed object from needing to add
8
+
43
9
  // host and namespace which are provided by the final consuming
44
10
  // class to the prototype which can result in overwrite errors
45
11
  const CONFIG = getOrSetGlobal('CONFIG', {
@@ -81,8 +47,6 @@ const CONFIG = getOrSetGlobal('CONFIG', {
81
47
  * ```
82
48
  *
83
49
  * @public
84
- * @param {BuildURLConfig} config
85
- * @return {void}
86
50
  */
87
51
  function setBuildURLConfig(config) {
88
52
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
@@ -164,8 +128,6 @@ function resourcePathForType(options) {
164
128
  * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
165
129
  *
166
130
  * @public
167
- * @param urlOptions
168
- * @return {String}
169
131
  */
170
132
  function buildBaseURL(urlOptions) {
171
133
  const options = Object.assign({
@@ -287,8 +249,8 @@ function handleInclude(include) {
287
249
  * returning a new object with only those keys that have truthy values / non-empty arrays
288
250
  *
289
251
  * @public
290
- * @param {Record<string, Serializable>} source object to filter keys with empty values from
291
- * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
252
+ * @param source object to filter keys with empty values from
253
+ * @return A new object with the keys that contained empty values removed
292
254
  */
293
255
  function filterEmpty(source) {
294
256
  const result = {};
@@ -319,9 +281,7 @@ function filterEmpty(source) {
319
281
  * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
320
282
  *
321
283
  * @public
322
- * @param {URLSearchParams | object} params
323
- * @param {Object} options
324
- * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
284
+ * @return A {@link URLSearchParams} with keys inserted in sorted order
325
285
  */
326
286
  function sortQueryParams(params, options) {
327
287
  const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);
@@ -393,9 +353,7 @@ function sortQueryParams(params, options) {
393
353
  * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
394
354
  *
395
355
  * @public
396
- * @param {URLSearchParams | Object} params
397
- * @param {Object} [options]
398
- * @return {String} A sorted query params string without the leading `?`
356
+ * @return A sorted query params string without the leading `?`
399
357
  */
400
358
  function buildQueryParams(params, options) {
401
359
  return sortQueryParams(params, options).toString();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { assert } from '@warp-drive/core/build-config/macros';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';\n\n/**\n * Simple utility function to assist in url building,\n * query params, and other common request operations.\n *\n * These primitives may be used directly or composed\n * by request builders to provide a consistent interface\n * for building requests.\n *\n * For instance:\n *\n * ```ts\n * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';\n *\n * const baseURL = buildBaseURL({\n * host: 'https://api.example.com',\n * namespace: 'api/v1',\n * resourcePath: 'emberDevelopers',\n * op: 'query',\n * identifier: { type: 'ember-developer' }\n * });\n * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;\n * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'\n * ```\n *\n * This is useful, but not as useful as the REST request builder for query which is sugar\n * over this (and more!):\n *\n * ```ts\n * import { query } from '@ember-data/rest/request';\n *\n * const options = query('ember-developer', { name: 'Chris', include:['pets'] });\n * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }\n * // Note: options will also include other request options like headers, method, etc.\n * ```\n *\n * @module\n * @public\n */\n\n// prevents the final constructed object from needing to add\n// host and namespace which are provided by the final consuming\n// class to the prototype which can result in overwrite errors\n\nexport interface BuildURLConfig {\n host: string | null;\n namespace: string | null;\n}\n\nconst CONFIG: BuildURLConfig = getOrSetGlobal('CONFIG', {\n host: '',\n namespace: '',\n});\n\n/**\n * Sets the global configuration for `buildBaseURL`\n * for host and namespace values for the application.\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 * host values of `''` or `'/'` are equivalent.\n *\n * Except for the value of `/` as host, host should not\n * end with `/`.\n *\n * namespace should not start or end with a `/`.\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * Example:\n *\n * ```ts\n * import { setBuildURLConfig } from '@ember-data/request-utils';\n *\n * setBuildURLConfig({\n * host: 'https://api.example.com',\n * namespace: 'api/v1'\n * });\n * ```\n *\n * @public\n * @param {BuildURLConfig} config\n * @return {void}\n */\nexport function setBuildURLConfig(config: BuildURLConfig) {\n assert(`setBuildURLConfig: You must pass a config object`, config);\n assert(\n `setBuildURLConfig: You must pass a config object with a 'host' or 'namespace' property`,\n 'host' in config || 'namespace' in config\n );\n\n CONFIG.host = config.host || '';\n CONFIG.namespace = config.namespace || '';\n\n assert(\n `buildBaseURL: host must NOT end with '/', received '${CONFIG.host}'`,\n CONFIG.host === '/' || !CONFIG.host.endsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT start with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.startsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT end with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.endsWith('/')\n );\n}\n\nexport interface FindRecordUrlOptions {\n op: 'findRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface QueryUrlOptions {\n op: 'query';\n identifier: { type: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface FindManyUrlOptions {\n op: 'findMany';\n identifiers: { type: string; id: string }[];\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\nexport interface FindRelatedCollectionUrlOptions {\n op: 'findRelatedCollection';\n identifier: { type: string; id: string };\n fieldPath: string;\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface FindRelatedResourceUrlOptions {\n op: 'findRelatedRecord';\n identifier: { type: string; id: string };\n fieldPath: string;\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface CreateRecordUrlOptions {\n op: 'createRecord';\n identifier: { type: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface UpdateRecordUrlOptions {\n op: 'updateRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface DeleteRecordUrlOptions {\n op: 'deleteRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface GenericUrlOptions {\n resourcePath: string;\n host?: string;\n namespace?: string;\n}\n\nexport type UrlOptions =\n | FindRecordUrlOptions\n | QueryUrlOptions\n | FindManyUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | CreateRecordUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions\n | GenericUrlOptions;\n\nconst OPERATIONS_WITH_PRIMARY_RECORDS = new Set([\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n]);\n\nfunction isOperationWithPrimaryRecord(\n options: UrlOptions\n): options is\n | FindRecordUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions {\n return 'op' in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);\n}\n\nfunction hasResourcePath(options: UrlOptions): options is GenericUrlOptions {\n return 'resourcePath' in options && typeof options.resourcePath === 'string' && options.resourcePath.length > 0;\n}\n\nfunction resourcePathForType(options: UrlOptions): string {\n assert(\n `resourcePathForType: You must pass a valid op as part of options`,\n 'op' in options && typeof options.op === 'string'\n );\n return options.op === 'findMany' ? options.identifiers[0].type : options.identifier.type;\n}\n\n/**\n * Builds a URL for a request based on the provided options.\n * Does not include support for building query params (see `buildQueryParams`)\n * so that it may be composed cleanly with other query-params strategies.\n *\n * Usage:\n *\n * ```ts\n * import { buildBaseURL } from '@ember-data/request-utils';\n *\n * const url = buildBaseURL({\n * host: 'https://api.example.com',\n * namespace: 'api/v1',\n * resourcePath: 'emberDevelopers',\n * op: 'query',\n * identifier: { type: 'ember-developer' }\n * });\n *\n * // => 'https://api.example.com/api/v1/emberDevelopers'\n * ```\n *\n * On the surface this may seem like a lot of work to do something simple, but\n * it is designed to be composable with other utilities and interfaces that the\n * average product engineer will never need to see or use.\n *\n * A few notes:\n *\n * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.\n * - `host` and `namespace` are optional, but if they are not provided, the values globally\n * configured via `setBuildURLConfig` will be used.\n * - `op` is required and must be one of the following:\n * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'\n * - Depending on the value of `op`, `identifier` or `identifiers` will be required.\n *\n * @public\n * @param urlOptions\n * @return {String}\n */\nexport function buildBaseURL(urlOptions: UrlOptions): string {\n const options = Object.assign(\n {\n host: CONFIG.host,\n namespace: CONFIG.namespace,\n },\n urlOptions\n );\n assert(\n `buildBaseURL: You must pass \\`op\\` as part of options`,\n hasResourcePath(options) || (typeof options.op === 'string' && options.op.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifier\\` as part of options`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (options.identifier && typeof options.identifier === 'object')\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (options.identifiers &&\n Array.isArray(options.identifiers) &&\n options.identifiers.length > 0 &&\n options.identifiers.every((i) => i && typeof i === 'object'))\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'id'`,\n hasResourcePath(options) ||\n !isOperationWithPrimaryRecord(options) ||\n (typeof options.identifier.id === 'string' && options.identifier.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n options.identifiers.every((i) => typeof i.id === 'string' && i.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (typeof options.identifier.type === 'string' && options.identifier.type.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifiers\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (typeof options.identifiers[0].type === 'string' && options.identifiers[0].type.length > 0)\n );\n\n // prettier-ignore\n const idPath: string =\n isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id)\n : '';\n const resourcePath = options.resourcePath || resourcePathForType(options);\n const { host, namespace } = options;\n const fieldPath = 'fieldPath' in options ? options.fieldPath : '';\n\n assert(\n `buildBaseURL: You tried to build a url for a ${String(\n 'op' in options ? options.op + ' ' : ''\n )}request to ${resourcePath} but resourcePath must be set or op must be one of \"${[\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n 'createRecord',\n 'query',\n 'findMany',\n ].join('\",\"')}\".`,\n hasResourcePath(options) ||\n [\n 'findRecord',\n 'query',\n 'findMany',\n 'findRelatedCollection',\n 'findRelatedRecord',\n 'createRecord',\n 'updateRecord',\n 'deleteRecord',\n ].includes(options.op)\n );\n\n assert(`buildBaseURL: host must NOT end with '/', received '${host}'`, host === '/' || !host.endsWith('/'));\n assert(`buildBaseURL: namespace must NOT start with '/', received '${namespace}'`, !namespace.startsWith('/'));\n assert(`buildBaseURL: namespace must NOT end with '/', received '${namespace}'`, !namespace.endsWith('/'));\n assert(\n `buildBaseURL: resourcePath must NOT start with '/', received '${resourcePath}'`,\n !resourcePath.startsWith('/')\n );\n assert(`buildBaseURL: resourcePath must NOT end with '/', received '${resourcePath}'`, !resourcePath.endsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT start with '/', received '${fieldPath}'`, !fieldPath.startsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT end with '/', received '${fieldPath}'`, !fieldPath.endsWith('/'));\n assert(`buildBaseURL: idPath must NOT start with '/', received '${idPath}'`, !idPath.startsWith('/'));\n assert(`buildBaseURL: idPath must NOT end with '/', received '${idPath}'`, !idPath.endsWith('/'));\n\n const hasHost = host !== '' && host !== '/';\n const url = [hasHost ? host : '', namespace, resourcePath, idPath, fieldPath].filter(Boolean).join('/');\n return hasHost ? url : `/${url}`;\n}\n\nconst DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS: QueryParamsSerializationOptions = {\n arrayFormat: 'comma',\n};\n\nfunction handleInclude(include: string | string[]): string[] {\n assert(\n `Expected include to be a string or array, got ${typeof include}`,\n typeof include === 'string' || Array.isArray(include)\n );\n return typeof include === 'string' ? include.split(',') : include;\n}\n\n/**\n * filter out keys of an object that have falsy values or point to empty arrays\n * returning a new object with only those keys that have truthy values / non-empty arrays\n *\n * @public\n * @param {Record<string, Serializable>} source object to filter keys with empty values from\n * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed\n */\nexport function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable> {\n const result: Record<string, Serializable> = {};\n for (const key in source) {\n const value = source[key];\n // Allow `0` and `false` but filter falsy values that indicate \"empty\"\n if (value !== undefined && value !== null && value !== '') {\n if (!Array.isArray(value) || value.length > 0) {\n result[key] = source[key];\n }\n }\n }\n return result;\n}\n\n/**\n * Sorts query params by both key and value returning a new URLSearchParams\n * object with the keys inserted in sorted order.\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\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 {URLSearchParams} A URLSearchParams with keys inserted in sorted order\n */\nexport function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams {\n const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);\n const paramsIsObject = !(params instanceof URLSearchParams);\n const urlParams = new URLSearchParams();\n const dictionaryParams: Record<string, Serializable> = paramsIsObject ? params : {};\n\n if (!paramsIsObject) {\n params.forEach((value, key) => {\n const hasExisting = key in dictionaryParams;\n if (!hasExisting) {\n dictionaryParams[key] = value;\n } else {\n const existingValue = dictionaryParams[key];\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n dictionaryParams[key] = [existingValue, value];\n }\n }\n });\n }\n\n if ('include' in dictionaryParams) {\n dictionaryParams.include = handleInclude(dictionaryParams.include as string | string[]);\n }\n\n const sortedKeys = Object.keys(dictionaryParams).sort();\n sortedKeys.forEach((key) => {\n const value = dictionaryParams[key];\n if (Array.isArray(value)) {\n value.sort();\n switch (opts.arrayFormat) {\n case 'indices':\n value.forEach((v, i) => {\n urlParams.append(`${key}[${i}]`, String(v));\n });\n return;\n case 'bracket':\n value.forEach((v) => {\n urlParams.append(`${key}[]`, String(v));\n });\n return;\n case 'repeat':\n value.forEach((v) => {\n urlParams.append(key, String(v));\n });\n return;\n case 'comma':\n default:\n urlParams.append(key, value.join(','));\n return;\n }\n } else {\n urlParams.append(key, String(value));\n }\n });\n\n return urlParams;\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 *\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(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string {\n return sortQueryParams(params, options).toString();\n}\n"],"names":["CONFIG","getOrSetGlobal","host","namespace","setBuildURLConfig","config","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","endsWith","startsWith","OPERATIONS_WITH_PRIMARY_RECORDS","Set","isOperationWithPrimaryRecord","options","has","op","hasResourcePath","resourcePath","length","resourcePathForType","identifiers","type","identifier","buildBaseURL","urlOptions","Object","assign","Array","isArray","every","i","id","idPath","encodeURIComponent","fieldPath","String","join","includes","hasHost","url","filter","Boolean","DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS","arrayFormat","handleInclude","include","split","filterEmpty","source","result","key","value","undefined","sortQueryParams","params","opts","paramsIsObject","URLSearchParams","urlParams","dictionaryParams","forEach","hasExisting","existingValue","push","sortedKeys","keys","sort","v","append","buildQueryParams","toString"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAOA,MAAMA,MAAsB,GAAGC,cAAc,CAAC,QAAQ,EAAE;AACtDC,EAAAA,IAAI,EAAE,EAAE;AACRC,EAAAA,SAAS,EAAE;AACb,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACC,MAAsB,EAAE;EACxDC,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,IAAA,IAAA,CAAAA,IAAA,EAAA;MAAA,MAAAC,IAAAA,KAAA,CAAO,CAAkD,gDAAA,CAAA,CAAA;AAAA;AAAA,GAAA,EAAEP,MAAM,CAAA,GAAA,EAAA;EACjEC,cAAA,CAAAC,eAAA,EAAAC,CAAAA,SAAA,CAAAC,GAAA,CAAAC,KAAA,CAAA,GAAA,CAAAC,IAAA,IAAA;AAAA,IAAA,IAAA,CA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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASW,gBAAgBA,CAACf,MAAyB,EAAEzC,OAAyC,EAAU;EAC7G,OAAOwC,eAAe,CAACC,MAAM,EAAEzC,OAAO,CAAC,CAACyD,QAAQ,EAAE;AACpD;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * @module\n * @mergeModuleWith <project>\n */\n\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';\n\n// prevents the final constructed object from needing to add\n// host and namespace which are provided by the final consuming\n// class to the prototype which can result in overwrite errors\n\nexport interface BuildURLConfig {\n host: string | null;\n namespace: string | null;\n}\n\nconst CONFIG: BuildURLConfig = getOrSetGlobal('CONFIG', {\n host: '',\n namespace: '',\n});\n\n/**\n * Sets the global configuration for `buildBaseURL`\n * for host and namespace values for the application.\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 * host values of `''` or `'/'` are equivalent.\n *\n * Except for the value of `/` as host, host should not\n * end with `/`.\n *\n * namespace should not start or end with a `/`.\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * Example:\n *\n * ```ts\n * import { setBuildURLConfig } from '@ember-data/request-utils';\n *\n * setBuildURLConfig({\n * host: 'https://api.example.com',\n * namespace: 'api/v1'\n * });\n * ```\n *\n * @public\n */\nexport function setBuildURLConfig(config: BuildURLConfig) {\n assert(`setBuildURLConfig: You must pass a config object`, config);\n assert(\n `setBuildURLConfig: You must pass a config object with a 'host' or 'namespace' property`,\n 'host' in config || 'namespace' in config\n );\n\n CONFIG.host = config.host || '';\n CONFIG.namespace = config.namespace || '';\n\n assert(\n `buildBaseURL: host must NOT end with '/', received '${CONFIG.host}'`,\n CONFIG.host === '/' || !CONFIG.host.endsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT start with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.startsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT end with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.endsWith('/')\n );\n}\n\nexport interface FindRecordUrlOptions {\n op: 'findRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface QueryUrlOptions {\n op: 'query';\n identifier: { type: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface FindManyUrlOptions {\n op: 'findMany';\n identifiers: { type: string; id: string }[];\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\nexport interface FindRelatedCollectionUrlOptions {\n op: 'findRelatedCollection';\n identifier: { type: string; id: string };\n fieldPath: string;\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface FindRelatedResourceUrlOptions {\n op: 'findRelatedRecord';\n identifier: { type: string; id: string };\n fieldPath: string;\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface CreateRecordUrlOptions {\n op: 'createRecord';\n identifier: { type: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface UpdateRecordUrlOptions {\n op: 'updateRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface DeleteRecordUrlOptions {\n op: 'deleteRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface GenericUrlOptions {\n resourcePath: string;\n host?: string;\n namespace?: string;\n}\n\nexport type UrlOptions =\n | FindRecordUrlOptions\n | QueryUrlOptions\n | FindManyUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | CreateRecordUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions\n | GenericUrlOptions;\n\nconst OPERATIONS_WITH_PRIMARY_RECORDS = new Set([\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n]);\n\nfunction isOperationWithPrimaryRecord(\n options: UrlOptions\n): options is\n | FindRecordUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions {\n return 'op' in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);\n}\n\nfunction hasResourcePath(options: UrlOptions): options is GenericUrlOptions {\n return 'resourcePath' in options && typeof options.resourcePath === 'string' && options.resourcePath.length > 0;\n}\n\nfunction resourcePathForType(options: UrlOptions): string {\n assert(\n `resourcePathForType: You must pass a valid op as part of options`,\n 'op' in options && typeof options.op === 'string'\n );\n return options.op === 'findMany' ? options.identifiers[0].type : options.identifier.type;\n}\n\n/**\n * Builds a URL for a request based on the provided options.\n * Does not include support for building query params (see `buildQueryParams`)\n * so that it may be composed cleanly with other query-params strategies.\n *\n * Usage:\n *\n * ```ts\n * import { buildBaseURL } from '@ember-data/request-utils';\n *\n * const url = buildBaseURL({\n * host: 'https://api.example.com',\n * namespace: 'api/v1',\n * resourcePath: 'emberDevelopers',\n * op: 'query',\n * identifier: { type: 'ember-developer' }\n * });\n *\n * // => 'https://api.example.com/api/v1/emberDevelopers'\n * ```\n *\n * On the surface this may seem like a lot of work to do something simple, but\n * it is designed to be composable with other utilities and interfaces that the\n * average product engineer will never need to see or use.\n *\n * A few notes:\n *\n * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.\n * - `host` and `namespace` are optional, but if they are not provided, the values globally\n * configured via `setBuildURLConfig` will be used.\n * - `op` is required and must be one of the following:\n * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'\n * - Depending on the value of `op`, `identifier` or `identifiers` will be required.\n *\n * @public\n */\nexport function buildBaseURL(urlOptions: UrlOptions): string {\n const options = Object.assign(\n {\n host: CONFIG.host,\n namespace: CONFIG.namespace,\n },\n urlOptions\n );\n assert(\n `buildBaseURL: You must pass \\`op\\` as part of options`,\n hasResourcePath(options) || (typeof options.op === 'string' && options.op.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifier\\` as part of options`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (options.identifier && typeof options.identifier === 'object')\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (options.identifiers &&\n Array.isArray(options.identifiers) &&\n options.identifiers.length > 0 &&\n options.identifiers.every((i) => i && typeof i === 'object'))\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'id'`,\n hasResourcePath(options) ||\n !isOperationWithPrimaryRecord(options) ||\n (typeof options.identifier.id === 'string' && options.identifier.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n options.identifiers.every((i) => typeof i.id === 'string' && i.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (typeof options.identifier.type === 'string' && options.identifier.type.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifiers\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (typeof options.identifiers[0].type === 'string' && options.identifiers[0].type.length > 0)\n );\n\n // prettier-ignore\n const idPath: string =\n isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id)\n : '';\n const resourcePath = options.resourcePath || resourcePathForType(options);\n const { host, namespace } = options;\n const fieldPath = 'fieldPath' in options ? options.fieldPath : '';\n\n assert(\n `buildBaseURL: You tried to build a url for a ${String(\n 'op' in options ? options.op + ' ' : ''\n )}request to ${resourcePath} but resourcePath must be set or op must be one of \"${[\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n 'createRecord',\n 'query',\n 'findMany',\n ].join('\",\"')}\".`,\n hasResourcePath(options) ||\n [\n 'findRecord',\n 'query',\n 'findMany',\n 'findRelatedCollection',\n 'findRelatedRecord',\n 'createRecord',\n 'updateRecord',\n 'deleteRecord',\n ].includes(options.op)\n );\n\n assert(`buildBaseURL: host must NOT end with '/', received '${host}'`, host === '/' || !host.endsWith('/'));\n assert(`buildBaseURL: namespace must NOT start with '/', received '${namespace}'`, !namespace.startsWith('/'));\n assert(`buildBaseURL: namespace must NOT end with '/', received '${namespace}'`, !namespace.endsWith('/'));\n assert(\n `buildBaseURL: resourcePath must NOT start with '/', received '${resourcePath}'`,\n !resourcePath.startsWith('/')\n );\n assert(`buildBaseURL: resourcePath must NOT end with '/', received '${resourcePath}'`, !resourcePath.endsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT start with '/', received '${fieldPath}'`, !fieldPath.startsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT end with '/', received '${fieldPath}'`, !fieldPath.endsWith('/'));\n assert(`buildBaseURL: idPath must NOT start with '/', received '${idPath}'`, !idPath.startsWith('/'));\n assert(`buildBaseURL: idPath must NOT end with '/', received '${idPath}'`, !idPath.endsWith('/'));\n\n const hasHost = host !== '' && host !== '/';\n const url = [hasHost ? host : '', namespace, resourcePath, idPath, fieldPath].filter(Boolean).join('/');\n return hasHost ? url : `/${url}`;\n}\n\nconst DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS: QueryParamsSerializationOptions = {\n arrayFormat: 'comma',\n};\n\nfunction handleInclude(include: string | string[]): string[] {\n assert(\n `Expected include to be a string or array, got ${typeof include}`,\n typeof include === 'string' || Array.isArray(include)\n );\n return typeof include === 'string' ? include.split(',') : include;\n}\n\n/**\n * filter out keys of an object that have falsy values or point to empty arrays\n * returning a new object with only those keys that have truthy values / non-empty arrays\n *\n * @public\n * @param source object to filter keys with empty values from\n * @return A new object with the keys that contained empty values removed\n */\nexport function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable> {\n const result: Record<string, Serializable> = {};\n for (const key in source) {\n const value = source[key];\n // Allow `0` and `false` but filter falsy values that indicate \"empty\"\n if (value !== undefined && value !== null && value !== '') {\n if (!Array.isArray(value) || value.length > 0) {\n result[key] = source[key];\n }\n }\n }\n return result;\n}\n\n/**\n * Sorts query params by both key and value returning a new URLSearchParams\n * object with the keys inserted in sorted order.\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\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 * @return A {@link URLSearchParams} with keys inserted in sorted order\n */\nexport function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams {\n const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);\n const paramsIsObject = !(params instanceof URLSearchParams);\n const urlParams = new URLSearchParams();\n const dictionaryParams: Record<string, Serializable> = paramsIsObject ? params : {};\n\n if (!paramsIsObject) {\n params.forEach((value, key) => {\n const hasExisting = key in dictionaryParams;\n if (!hasExisting) {\n dictionaryParams[key] = value;\n } else {\n const existingValue = dictionaryParams[key];\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n dictionaryParams[key] = [existingValue, value];\n }\n }\n });\n }\n\n if ('include' in dictionaryParams) {\n dictionaryParams.include = handleInclude(dictionaryParams.include as string | string[]);\n }\n\n const sortedKeys = Object.keys(dictionaryParams).sort();\n sortedKeys.forEach((key) => {\n const value = dictionaryParams[key];\n if (Array.isArray(value)) {\n value.sort();\n switch (opts.arrayFormat) {\n case 'indices':\n value.forEach((v, i) => {\n urlParams.append(`${key}[${i}]`, String(v));\n });\n return;\n case 'bracket':\n value.forEach((v) => {\n urlParams.append(`${key}[]`, String(v));\n });\n return;\n case 'repeat':\n value.forEach((v) => {\n urlParams.append(key, String(v));\n });\n return;\n case 'comma':\n default:\n urlParams.append(key, value.join(','));\n return;\n }\n } else {\n urlParams.append(key, String(value));\n }\n });\n\n return urlParams;\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 *\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 * @return A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string {\n return sortQueryParams(params, options).toString();\n}\n"],"names":["CONFIG","getOrSetGlobal","host","namespace","setBuildURLConfig","config","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","endsWith","startsWith","OPERATIONS_WITH_PRIMARY_RECORDS","Set","isOperationWithPrimaryRecord","options","has","op","hasResourcePath","resourcePath","length","resourcePathForType","identifiers","type","identifier","buildBaseURL","urlOptions","Object","assign","Array","isArray","every","i","id","idPath","encodeURIComponent","fieldPath","String","join","includes","hasHost","url","filter","Boolean","DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS","arrayFormat","handleInclude","include","split","filterEmpty","source","result","key","value","undefined","sortQueryParams","params","opts","paramsIsObject","URLSearchParams","urlParams","dictionaryParams","forEach","hasExisting","existingValue","push","sortedKeys","keys","sort","v","append","buildQueryParams","toString"],"mappings":";;;AAAA;AACA;AACA;AACA;;AAOA;AACA;AAOA,MAAMA,MAAsB,GAAGC,cAAc,CAAC,QAAQ,EAAE;AACtDC,EAAAA,IAAI,EAAE,EAAE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lB,EAAAA,GAAG,CAAI,EAAA,CAAA,EAAEf,MAAM,CAACgC,CAAC,CAAC,CAAC;AACzC,WAAC,CAAC;AACF,UAAA;AACF,QAAA,KAAK,QAAQ;AACXhB,UAAAA,KAAK,CAACS,OAAO,CAAEO,CAAC,IAAK;YACnBT,SAAS,CAACU,MAAM,CAAClB,GAAG,EAAEf,MAAM,CAACgC,CAAC,CAAC,CAAC;AAClC,WAAC,CAAC;AACF,UAAA;AACF,QAAA,KAAK,OAAO;AACZ,QAAA;UACET,SAAS,CAACU,MAAM,CAAClB,GAAG,EAAEC,KAAK,CAACf,IAAI,CAAC,GAAG,CAAC,CAAC;AACtC,UAAA;AACJ;AACF,KAAC,MAAM;MACLsB,SAAS,CAACU,MAAM,CAAClB,GAAG,EAAEf,MAAM,CAACgB,KAAK,CAAC,CAAC;AACtC;AACF,GAAC,CAAC;AAEF,EAAA,OAAOO,SAAS;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASW,gBAAgBA,CAACf,MAAyB,EAAEzC,OAAyC,EAAU;EAC7G,OAAOwC,eAAe,CAACC,MAAM,EAAEzC,OAAO,CAAC,CAACyD,QAAQ,EAAE;AACpD;;;;"}
package/dist/json-api.js CHANGED
@@ -593,11 +593,12 @@ function _serializeResource(cache, identifier) {
593
593
  if (record.relationships) {
594
594
  for (const key of Object.keys(record.relationships)) {
595
595
  const relationship = record.relationships[key];
596
- relationship.data = fixRelData(relationship.data);
597
596
  if (Array.isArray(relationship.data)) {
598
597
  relationship.data = relationship.data.map(ref => fixRef(ref));
599
598
  } else if (typeof relationship.data === 'object' && relationship.data !== null) {
600
599
  relationship.data = fixRef(relationship.data);
600
+ } else if (Object.keys(relationship ?? {}).length === 0) {
601
+ delete record.relationships[key];
601
602
  }
602
603
  }
603
604
  }
@@ -1 +1 @@
1
- {"version":3,"file":"json-api.js","sources":["../src/-private/json-api/-utils.ts","../src/-private/json-api/find-record.ts","../src/-private/json-api/query.ts","../src/-private/json-api/save-record.ts","../src/-private/json-api/serialize.ts"],"sourcesContent":["import type { QueryParamsSource } from '@warp-drive/core/types/params';\n\nimport type { BuildURLConfig } from '../../index.ts';\nimport { buildQueryParams as buildParams, setBuildURLConfig as setConfig } from '../../index.ts';\n\nexport interface JSONAPIConfig extends BuildURLConfig {\n profiles?: {\n pagination?: string;\n [key: string]: string | undefined;\n };\n extensions?: {\n atomic?: string;\n [key: string]: string | undefined;\n };\n}\n\nconst JsonApiAccept = 'application/vnd.api+json';\nconst DEFAULT_CONFIG: JSONAPIConfig = { host: '', namespace: '' };\nexport let CONFIG: JSONAPIConfig = DEFAULT_CONFIG;\nexport let ACCEPT_HEADER_VALUE = 'application/vnd.api+json';\n\n/**\n * Allows setting extensions and profiles to be used in the `Accept` header.\n *\n * Extensions and profiles are keyed by their namespace with the value being\n * their URI.\n *\n * Example:\n *\n * ```ts\n * setBuildURLConfig({\n * extensions: {\n * atomic: 'https://jsonapi.org/ext/atomic'\n * },\n * profiles: {\n * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'\n * }\n * });\n * ```\n *\n * This also sets the global configuration for `buildBaseURL`\n * for host and namespace values for the global coniguration\n * done via `import { setBuildURLConfig } from '@warp-drive/utilities';`\n *\n * These values may still be overridden by passing\n * them to buildBaseURL directly.\n *\n * This method may be called as many times as needed\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * @public\n * @param {BuildURLConfig} config\n * @return {void}\n */\nexport function setBuildURLConfig(config: JSONAPIConfig): void {\n CONFIG = Object.assign({}, DEFAULT_CONFIG, config);\n\n if (config.profiles || config.extensions) {\n let accept = JsonApiAccept;\n if (config.profiles) {\n const profiles = Object.values(config.profiles);\n if (profiles.length) {\n accept += ';profile=\"' + profiles.join(' ') + '\"';\n }\n }\n if (config.extensions) {\n const extensions = Object.values(config.extensions);\n if (extensions.length) {\n accept += ';ext=' + extensions.join(' ');\n }\n }\n ACCEPT_HEADER_VALUE = accept;\n }\n\n setConfig(config);\n}\n\ninterface RelatedObject {\n [key: string]: string | string[] | RelatedObject;\n}\n\nexport type JsonApiQuery = {\n include?: string | string[] | RelatedObject;\n fields?: Record<string, string | string[]>;\n page?: {\n size?: number;\n after?: string;\n before?: string;\n };\n};\n\nfunction isJsonApiQuery(query: JsonApiQuery | QueryParamsSource): query is JsonApiQuery {\n if ('include' in query && query.include && typeof query.include === 'object') {\n return true;\n }\n if ('fields' in query || 'page' in query) {\n return true;\n }\n return false;\n}\n\nfunction collapseIncludePaths(basePath: string, include: RelatedObject, paths: string[]) {\n const keys = Object.keys(include);\n for (let i = 0; i < keys.length; i++) {\n // the key is always included too\n paths.push(`${basePath}.${keys[i]}`);\n const key = keys[i];\n const value = include[key];\n\n // include: { 'company': 'field1,field2' }\n if (typeof value === 'string') {\n value.split(',').forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': ['field1', 'field2'] }\n } else if (Array.isArray(value)) {\n value.forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': { 'nested': 'field1,field2' } }\n } else {\n collapseIncludePaths(`${basePath}.${key}`, value, paths);\n }\n }\n}\n\n/**\n * Sorts query params by both key and value, returning a query params string\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n * - If `included` is an object we build paths dynamically for you\n * Treats `fields` specially, building JSON:API partial fields params from an object\n * Treats `page` specially, building cursor-pagination profile page params from an object\n *\n * ```ts\n * const params = buildQueryParams({\n * include: {\n * company: {\n * locations: 'address'\n * }\n * },\n * fields: {\n * company: ['name', 'ticker'],\n * person: 'name'\n * },\n * page: {\n * size: 10,\n * after: 'abc',\n * }\n * });\n *\n * // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'\n * ```\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`\n *\n * @public\n * @param {URLSearchParams | Object} params\n * @param {Object} [options]\n * @return {String} A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string {\n if (query instanceof URLSearchParams) {\n return buildParams(query);\n }\n\n if (!isJsonApiQuery(query)) {\n return buildParams(query);\n }\n\n const { include, fields, page, ...rest } = query;\n const finalQuery: QueryParamsSource = {\n ...rest,\n };\n\n if ('include' in query) {\n // include: { 'company': 'field1,field2' }\n // include: { 'company': ['field1', 'field2'] }\n // include: { 'company': { 'nested': 'field1,field2' } }\n // include: { 'company': { 'nested': ['field1', 'field2'] } }\n if (include && !Array.isArray(include) && typeof include === 'object') {\n const includePaths: string[] = [];\n collapseIncludePaths('', include, includePaths);\n finalQuery.include = includePaths.sort();\n\n // include: 'field1,field2'\n // include: ['field1', 'field2']\n } else {\n finalQuery.include = include as string;\n }\n }\n\n if (fields) {\n const keys = Object.keys(fields).sort();\n for (let i = 0; i < keys.length; i++) {\n const resourceType = keys[i];\n const value = fields[resourceType];\n\n // fields: { 'company': ['field1', 'field2'] }\n if (Array.isArray(value)) {\n finalQuery[`fields[${resourceType}]`] = value.sort().join(',');\n\n // fields: { 'company': 'field1' }\n // fields: { 'company': 'field1,field2' }\n } else {\n finalQuery[`fields[${resourceType}]`] = value.split(',').sort().join(',');\n }\n }\n }\n\n if (page) {\n const keys = Object.keys(page).sort() as Array<'size' | 'after' | 'before'>;\n keys.forEach((key) => {\n const value = page[key];\n finalQuery[`page[${key}]`] = value!;\n });\n }\n\n return buildParams(finalQuery);\n}\n","import type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param options\n */\n\nexport type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & { data: T };\n\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n","import type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n CacheOptions,\n ConstrainedRequestOptions,\n PostQueryRequestOptions,\n QueryRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `postQuery` is that this method will send the query\n * as query params in the url of a \"GET\" request instead of as the JSON body of a \"POST\"\n * request.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource<T>,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `query` is that this method will send the query\n * as the JSON body of a \"POST\" request instead of as query params in the url of a \"GET\"\n * request.\n *\n * A CacheKey is generated from the url and query params, and used to cache the response\n * in the store.\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function postQuery<T>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function postQuery(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions;\nexport function postQuery(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): PostQueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: options.resourcePath ?? pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n const queryData = structuredClone(query);\n cacheOptions.key = cacheOptions.key ?? `${url}?${buildQueryParams(queryData, options.urlParamsSettings)}`;\n\n return {\n url,\n method: 'POST',\n body: JSON.stringify(query),\n headers,\n cacheOptions: cacheOptions as CacheOptions & { key: string },\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\nfunction isExisting(identifier: StableRecordIdentifier): identifier is StableExistingRecordIdentifier {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<SingleResourceDataDocument<RT>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url and header expectations of most JSON:API APIs\n * for a PATCH request.\n *\n * Note: This is a convenience method that calls `updateRecord` with the\n * supplied request with the `patch` option set to `true`.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(patchRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = patchRecord(person);\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function patchRecord<T>(record: T, options?: ConstrainedRequestOptions): UpdateRequestOptions<T>;\nexport function patchRecord(record: unknown, options?: ConstrainedRequestOptions): UpdateRequestOptions;\nexport function patchRecord(record: unknown, options: ConstrainedRequestOptions = {}): UpdateRequestOptions {\n const opts = options as ConstrainedRequestOptions & { patch: true };\n opts.patch = true;\n return updateRecord(record, opts);\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { Relationship } from '@warp-drive/core/types/cache/relationship';\nimport type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { InnerRelationshipDocument, ResourceObject } from '@warp-drive/core/types/spec/json-api-raw';\n\ntype ChangedRelationshipData = InnerRelationshipDocument;\n\nexport type JsonApiResourcePatch =\n | {\n type: string;\n id: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n }\n | {\n type: string;\n id: null;\n lid: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n };\n\n/**\n * Serializes the current state of a resource or array of resources for use with POST or PUT requests.\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): { data: ResourceObject };\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): { data: ResourceObject[] };\nexport function serializeResources(\n cache: Cache,\n identifiers: StableRecordIdentifier | StableRecordIdentifier[]\n): { data: ResourceObject | ResourceObject[] } {\n return {\n data: Array.isArray(identifiers)\n ? identifiers.map((identifier) => _serializeResource(cache, identifier))\n : _serializeResource(cache, identifiers),\n };\n}\n\ntype SerializedRef =\n | {\n id: string;\n type: string;\n }\n | { id: null; lid: string; type: string };\n\nfunction fixRef({\n id,\n lid,\n type,\n}: { id: string; lid?: string; type: string } | { id: null; lid: string; type: string }): SerializedRef {\n if (id !== null) {\n return { id, type };\n }\n return { id, lid, type };\n}\n\nfunction fixRelData(\n rel: Relationship['data'] | InnerRelationshipDocument['data']\n): SerializedRef | SerializedRef[] | null {\n if (Array.isArray(rel)) {\n return rel.map((ref) => fixRef(ref));\n } else if (typeof rel === 'object' && rel !== null) {\n return fixRef(rel);\n }\n return null;\n}\n\nfunction _serializeResource(cache: Cache, identifier: StableRecordIdentifier): ResourceObject {\n const { id, lid, type } = identifier;\n // peek gives us everything we want, but since its referentially the same data\n // as is in the cache we clone it to avoid any accidental mutations\n const record = structuredClone(cache.peek(identifier)) as ResourceObject;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n record\n );\n\n // remove lid from anything that has an ID and slice any relationship arrays\n if (record.id !== null) {\n delete record.lid;\n }\n\n if (record.relationships) {\n for (const key of Object.keys(record.relationships)) {\n const relationship = record.relationships[key];\n relationship.data = fixRelData(relationship.data);\n if (Array.isArray(relationship.data)) {\n relationship.data = relationship.data.map((ref) => fixRef(ref));\n } else if (typeof relationship.data === 'object' && relationship.data !== null) {\n relationship.data = fixRef(relationship.data);\n }\n }\n }\n\n return record;\n}\n\n/**\n * Serializes changes to a resource for use with PATCH requests.\n *\n * Only attributes which are changed are serialized.\n * Only relationships which are changed are serialized.\n *\n * Collection relationships serialize the collection as a whole.\n *\n * If you would like to serialize updates to a collection more granularly\n * (for instance, as operations) request the diff from the store and\n * serialize as desired:\n *\n * ```ts\n * const relationshipDiffMap = cache.changedRelationships(identifier);\n * ```\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializePatch(\n cache: Cache,\n identifier: StableRecordIdentifier\n // options: { include?: string[] } = {}\n): { data: JsonApiResourcePatch } {\n const { id, lid, type } = identifier;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n cache.peek(identifier)\n );\n\n const data: JsonApiResourcePatch =\n id === null\n ? { type, lid, id }\n : {\n type,\n id,\n };\n\n if (cache.hasChangedAttrs(identifier)) {\n const attrsChanges = cache.changedAttrs(identifier);\n const attributes: ResourceObject['attributes'] = {};\n\n Object.keys(attrsChanges).forEach((key) => {\n const change = attrsChanges[key];\n const newVal = change[1];\n attributes[key] = newVal === undefined ? null : structuredClone(newVal);\n });\n\n data.attributes = attributes;\n }\n\n const changedRelationships = cache.changedRelationships(identifier);\n if (changedRelationships.size) {\n const relationships: Record<string, ChangedRelationshipData> = {};\n changedRelationships.forEach((diff, key) => {\n relationships[key] = { data: fixRelData(diff.localState) } as ChangedRelationshipData;\n });\n\n data.relationships = relationships;\n }\n\n return { data };\n}\n"],"names":["JsonApiAccept","DEFAULT_CONFIG","host","namespace","ACCEPT_HEADER_VALUE","setBuildURLConfig","config","Object","assign","profiles","extensions","accept","values","length","join","setConfig","findRecord","arg1","arg2","arg3","identifier","type","id","options","cacheOptions","extractCacheOptions","urlOptions","op","resourcePath","pluralize","copyForwardUrlOptions","url","buildBaseURL","headers","Headers","append","include","buildQueryParams","urlParamsSettings","method","records","query","queryString","postQuery","queryData","structuredClone","key","body","JSON","stringify","isExisting","deleteRecord","record","recordIdentifierFor","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","data","createRecord","updateRecord","patch","serializeResources","cache","identifiers","Array","isArray","map","_serializeResource","fixRef","lid","fixRelData","rel","ref","peek","String","relationships","keys","relationship","serializePatch","hasChangedAttrs","attrsChanges","changedAttrs","attributes","forEach","change","newVal","undefined","changedRelationships","size","diff","localState"],"mappings":";;;;;;AAgBA,MAAMA,aAAa,GAAG,0BAA0B;AAChD,MAAMC,cAA6B,GAAG;AAAEC,EAAAA,IAAI,EAAE,EAAE;AAAEC,EAAAA,SAAS,EAAE;AAAG,CAAC;AAE1D,IAAIC,mBAAmB,GAAG,0BAA0B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACC,MAAqB,EAAQ;EACpDC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEP,cAAc,EAAEK,MAAM,CAAC;AAElD,EAAA,IAAIA,MAAM,CAACG,QAAQ,IAAIH,MAAM,CAACI,UAAU,EAAE;IACxC,IAAIC,MAAM,GAAGX,aAAa;IAC1B,IAAIM,MAAM,CAACG,QAAQ,EAAE;MACnB,MAAMA,QAAQ,GAAGF,MAAM,CAACK,MAAM,CAACN,MAAM,CAACG,QAAQ,CAAC;MAC/C,IAAIA,QAAQ,CAACI,MAAM,EAAE;QACnBF,MAAM,IAAI,YAAY,GAAGF,QAAQ,CAACK,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;AACnD;AACF;IACA,IAAIR,MAAM,CAACI,UAAU,EAAE;MACrB,MAAMA,UAAU,GAAGH,MAAM,CAACK,MAAM,CAACN,MAAM,CAACI,UAAU,CAAC;MACnD,IAAIA,UAAU,CAACG,MAAM,EAAE;QACrBF,MAAM,IAAI,OAAO,GAAGD,UAAU,CAACI,IAAI,CAAC,GAAG,CAAC;AAC1C;AACF;AACAV,IAAAA,mBAAmB,GAAGO,MAAM;AAC9B;EAEAI,mBAAS,CAACT,MAAM,CAAC;AACnB;;ACpEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBO,SAASU,UAAUA,CACxBC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O,CAAEzC,GAAG,IAAK;AACzC,MAAA,MAAM0C,MAAM,GAAGJ,YAAY,CAACtC,GAAG,CAAC;AAChC,MAAA,MAAM2C,MAAM,GAAGD,MAAM,CAAC,CAAC,CAAC;AACxBF,MAAAA,UAAU,CAACxC,GAAG,CAAC,GAAG2C,MAAM,KAAKC,SAAS,GAAG,IAAI,GAAG7C,eAAe,CAAC4C,MAAM,CAAC;AACzE,KAAC,CAAC;IAEF5B,IAAI,CAACyB,UAAU,GAAGA,UAAU;AAC9B;AAEA,EAAA,MAAMK,oBAAoB,GAAGzB,KAAK,CAACyB,oBAAoB,CAACvE,UAAU,CAAC;EACnE,IAAIuE,oBAAoB,CAACC,IAAI,EAAE;IAC7B,MAAMb,aAAsD,GAAG,EAAE;AACjEY,IAAAA,oBAAoB,CAACJ,OAAO,CAAC,CAACM,IAAI,EAAE/C,GAAG,KAAK;MAC1CiC,aAAa,CAACjC,GAAG,CAAC,GAAG;AAAEe,QAAAA,IAAI,EAAEa,UAAU,CAACmB,IAAI,CAACC,UAAU;OAA8B;AACvF,KAAC,CAAC;IAEFjC,IAAI,CAACkB,aAAa,GAAGA,aAAa;AACpC;EAEA,OAAO;AAAElB,IAAAA;GAAM;AACjB;;;;"}
1
+ {"version":3,"file":"json-api.js","sources":["../src/-private/json-api/-utils.ts","../src/-private/json-api/find-record.ts","../src/-private/json-api/query.ts","../src/-private/json-api/save-record.ts","../src/-private/json-api/serialize.ts"],"sourcesContent":["import type { QueryParamsSource } from '@warp-drive/core/types/params';\n\nimport type { BuildURLConfig } from '../../index.ts';\nimport { buildQueryParams as buildParams, setBuildURLConfig as setConfig } from '../../index.ts';\n\nexport interface JSONAPIConfig extends BuildURLConfig {\n profiles?: {\n pagination?: string;\n [key: string]: string | undefined;\n };\n extensions?: {\n atomic?: string;\n [key: string]: string | undefined;\n };\n}\n\nconst JsonApiAccept = 'application/vnd.api+json';\nconst DEFAULT_CONFIG: JSONAPIConfig = { host: '', namespace: '' };\nexport let CONFIG: JSONAPIConfig = DEFAULT_CONFIG;\nexport let ACCEPT_HEADER_VALUE = 'application/vnd.api+json';\n\n/**\n * Allows setting extensions and profiles to be used in the `Accept` header.\n *\n * Extensions and profiles are keyed by their namespace with the value being\n * their URI.\n *\n * Example:\n *\n * ```ts\n * setBuildURLConfig({\n * extensions: {\n * atomic: 'https://jsonapi.org/ext/atomic'\n * },\n * profiles: {\n * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'\n * }\n * });\n * ```\n *\n * This also sets the global configuration for `buildBaseURL`\n * for host and namespace values for the global coniguration\n * done via `import { setBuildURLConfig } from '@warp-drive/utilities';`\n *\n * These values may still be overridden by passing\n * them to buildBaseURL directly.\n *\n * This method may be called as many times as needed\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * @public\n * @param {BuildURLConfig} config\n * @return {void}\n */\nexport function setBuildURLConfig(config: JSONAPIConfig): void {\n CONFIG = Object.assign({}, DEFAULT_CONFIG, config);\n\n if (config.profiles || config.extensions) {\n let accept = JsonApiAccept;\n if (config.profiles) {\n const profiles = Object.values(config.profiles);\n if (profiles.length) {\n accept += ';profile=\"' + profiles.join(' ') + '\"';\n }\n }\n if (config.extensions) {\n const extensions = Object.values(config.extensions);\n if (extensions.length) {\n accept += ';ext=' + extensions.join(' ');\n }\n }\n ACCEPT_HEADER_VALUE = accept;\n }\n\n setConfig(config);\n}\n\ninterface RelatedObject {\n [key: string]: string | string[] | RelatedObject;\n}\n\nexport type JsonApiQuery = {\n include?: string | string[] | RelatedObject;\n fields?: Record<string, string | string[]>;\n page?: {\n size?: number;\n after?: string;\n before?: string;\n };\n};\n\nfunction isJsonApiQuery(query: JsonApiQuery | QueryParamsSource): query is JsonApiQuery {\n if ('include' in query && query.include && typeof query.include === 'object') {\n return true;\n }\n if ('fields' in query || 'page' in query) {\n return true;\n }\n return false;\n}\n\nfunction collapseIncludePaths(basePath: string, include: RelatedObject, paths: string[]) {\n const keys = Object.keys(include);\n for (let i = 0; i < keys.length; i++) {\n // the key is always included too\n paths.push(`${basePath}.${keys[i]}`);\n const key = keys[i];\n const value = include[key];\n\n // include: { 'company': 'field1,field2' }\n if (typeof value === 'string') {\n value.split(',').forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': ['field1', 'field2'] }\n } else if (Array.isArray(value)) {\n value.forEach((field) => {\n paths.push(`${basePath}.${key}.${field}`);\n });\n\n // include: { 'company': { 'nested': 'field1,field2' } }\n } else {\n collapseIncludePaths(`${basePath}.${key}`, value, paths);\n }\n }\n}\n\n/**\n * Sorts query params by both key and value, returning a query params string\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n * - If `included` is an object we build paths dynamically for you\n * Treats `fields` specially, building JSON:API partial fields params from an object\n * Treats `page` specially, building cursor-pagination profile page params from an object\n *\n * ```ts\n * const params = buildQueryParams({\n * include: {\n * company: {\n * locations: 'address'\n * }\n * },\n * fields: {\n * company: ['name', 'ticker'],\n * person: 'name'\n * },\n * page: {\n * size: 10,\n * after: 'abc',\n * }\n * });\n *\n * // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'\n * ```\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`\n *\n * @public\n * @param {URLSearchParams | Object} params\n * @param {Object} [options]\n * @return {String} A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string {\n if (query instanceof URLSearchParams) {\n return buildParams(query);\n }\n\n if (!isJsonApiQuery(query)) {\n return buildParams(query);\n }\n\n const { include, fields, page, ...rest } = query;\n const finalQuery: QueryParamsSource = {\n ...rest,\n };\n\n if ('include' in query) {\n // include: { 'company': 'field1,field2' }\n // include: { 'company': ['field1', 'field2'] }\n // include: { 'company': { 'nested': 'field1,field2' } }\n // include: { 'company': { 'nested': ['field1', 'field2'] } }\n if (include && !Array.isArray(include) && typeof include === 'object') {\n const includePaths: string[] = [];\n collapseIncludePaths('', include, includePaths);\n finalQuery.include = includePaths.sort();\n\n // include: 'field1,field2'\n // include: ['field1', 'field2']\n } else {\n finalQuery.include = include as string;\n }\n }\n\n if (fields) {\n const keys = Object.keys(fields).sort();\n for (let i = 0; i < keys.length; i++) {\n const resourceType = keys[i];\n const value = fields[resourceType];\n\n // fields: { 'company': ['field1', 'field2'] }\n if (Array.isArray(value)) {\n finalQuery[`fields[${resourceType}]`] = value.sort().join(',');\n\n // fields: { 'company': 'field1' }\n // fields: { 'company': 'field1,field2' }\n } else {\n finalQuery[`fields[${resourceType}]`] = value.split(',').sort().join(',');\n }\n }\n }\n\n if (page) {\n const keys = Object.keys(page).sort() as Array<'size' | 'after' | 'before'>;\n keys.forEach((key) => {\n const value = page[key];\n finalQuery[`page[${key}]`] = value!;\n });\n }\n\n return buildParams(finalQuery);\n}\n","import type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/json-api';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param options\n */\n\nexport type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & { data: T };\n\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n","import type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n CacheOptions,\n ConstrainedRequestOptions,\n PostQueryRequestOptions,\n QueryRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `postQuery` is that this method will send the query\n * as query params in the url of a \"GET\" request instead of as the JSON body of a \"POST\"\n * request.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/json-api';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource<T>,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most JSON:API APIs.\n *\n * The key difference between this and `query` is that this method will send the query\n * as the JSON body of a \"POST\" request instead of as query params in the url of a \"GET\"\n * request.\n *\n * A CacheKey is generated from the url and query params, and used to cache the response\n * in the store.\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { postQuery } from '@warp-drive/utilities/json-api';\n *\n * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function postQuery<T>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions<CollectionResourceDataDocument<T>, T>;\nexport function postQuery(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): PostQueryRequestOptions;\nexport function postQuery(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): PostQueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: options.resourcePath ?? pluralize(type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n const queryData = structuredClone(query);\n cacheOptions.key = cacheOptions.key ?? `${url}?${buildQueryParams(queryData, options.urlParamsSettings)}`;\n\n return {\n url,\n method: 'POST',\n body: JSON.stringify(query),\n headers,\n cacheOptions: cacheOptions as CacheOptions & { key: string },\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/core/types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize } from '../../string.ts';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\nimport { ACCEPT_HEADER_VALUE } from './-utils.ts';\n\nfunction isExisting(identifier: StableRecordIdentifier): identifier is StableExistingRecordIdentifier {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most JSON:API APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<SingleResourceDataDocument<RT>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(identifier.type),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', ACCEPT_HEADER_VALUE);\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url and header expectations of most JSON:API APIs\n * for a PATCH request.\n *\n * Note: This is a convenience method that calls `updateRecord` with the\n * supplied request with the `patch` option set to `true`.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(patchRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { patchRecord } from '@warp-drive/utilities/json-api';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = patchRecord(person);\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function patchRecord<T>(record: T, options?: ConstrainedRequestOptions): UpdateRequestOptions<T>;\nexport function patchRecord(record: unknown, options?: ConstrainedRequestOptions): UpdateRequestOptions;\nexport function patchRecord(record: unknown, options: ConstrainedRequestOptions = {}): UpdateRequestOptions {\n const opts = options as ConstrainedRequestOptions & { patch: true };\n opts.patch = true;\n return updateRecord(record, opts);\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { Relationship } from '@warp-drive/core/types/cache/relationship';\nimport type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { InnerRelationshipDocument, ResourceObject } from '@warp-drive/core/types/spec/json-api-raw';\n\ntype ChangedRelationshipData = InnerRelationshipDocument;\n\nexport type JsonApiResourcePatch =\n | {\n type: string;\n id: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n }\n | {\n type: string;\n id: null;\n lid: string;\n attributes?: Record<string, Value>;\n relationships?: Record<string, ChangedRelationshipData>;\n };\n\n/**\n * Serializes the current state of a resource or array of resources for use with POST or PUT requests.\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): { data: ResourceObject };\nexport function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): { data: ResourceObject[] };\nexport function serializeResources(\n cache: Cache,\n identifiers: StableRecordIdentifier | StableRecordIdentifier[]\n): { data: ResourceObject | ResourceObject[] } {\n return {\n data: Array.isArray(identifiers)\n ? identifiers.map((identifier) => _serializeResource(cache, identifier))\n : _serializeResource(cache, identifiers),\n };\n}\n\ntype SerializedRef =\n | {\n id: string;\n type: string;\n }\n | { id: null; lid: string; type: string };\n\nfunction fixRef({\n id,\n lid,\n type,\n}: { id: string; lid?: string; type: string } | { id: null; lid: string; type: string }): SerializedRef {\n if (id !== null) {\n return { id, type };\n }\n return { id, lid, type };\n}\n\nfunction fixRelData(\n rel: Relationship['data'] | InnerRelationshipDocument['data']\n): SerializedRef | SerializedRef[] | null {\n if (Array.isArray(rel)) {\n return rel.map((ref) => fixRef(ref));\n } else if (typeof rel === 'object' && rel !== null) {\n return fixRef(rel);\n }\n return null;\n}\n\nfunction _serializeResource(cache: Cache, identifier: StableRecordIdentifier): ResourceObject {\n const { id, lid, type } = identifier;\n // peek gives us everything we want, but since its referentially the same data\n // as is in the cache we clone it to avoid any accidental mutations\n const record = structuredClone(cache.peek(identifier)) as ResourceObject;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n record\n );\n\n // remove lid from anything that has an ID and slice any relationship arrays\n if (record.id !== null) {\n delete record.lid;\n }\n\n if (record.relationships) {\n for (const key of Object.keys(record.relationships)) {\n const relationship = record.relationships[key];\n if (Array.isArray(relationship.data)) {\n relationship.data = relationship.data.map((ref) => fixRef(ref));\n } else if (typeof relationship.data === 'object' && relationship.data !== null) {\n relationship.data = fixRef(relationship.data);\n } else if (Object.keys(relationship ?? {}).length === 0) {\n delete record.relationships[key];\n }\n }\n }\n\n return record;\n}\n\n/**\n * Serializes changes to a resource for use with PATCH requests.\n *\n * Only attributes which are changed are serialized.\n * Only relationships which are changed are serialized.\n *\n * Collection relationships serialize the collection as a whole.\n *\n * If you would like to serialize updates to a collection more granularly\n * (for instance, as operations) request the diff from the store and\n * serialize as desired:\n *\n * ```ts\n * const relationshipDiffMap = cache.changedRelationships(identifier);\n * ```\n *\n * @public\n * @param {Cache} cache}\n * @param {StableRecordIdentifier} identifier\n * @return {Object} An object with a `data` property containing the serialized resource patch\n */\nexport function serializePatch(\n cache: Cache,\n identifier: StableRecordIdentifier\n // options: { include?: string[] } = {}\n): { data: JsonApiResourcePatch } {\n const { id, lid, type } = identifier;\n assert(\n `A record with id ${String(id)} and type ${type} for lid ${lid} was not found not in the supplied Cache.`,\n cache.peek(identifier)\n );\n\n const data: JsonApiResourcePatch =\n id === null\n ? { type, lid, id }\n : {\n type,\n id,\n };\n\n if (cache.hasChangedAttrs(identifier)) {\n const attrsChanges = cache.changedAttrs(identifier);\n const attributes: ResourceObject['attributes'] = {};\n\n Object.keys(attrsChanges).forEach((key) => {\n const change = attrsChanges[key];\n const newVal = change[1];\n attributes[key] = newVal === undefined ? null : structuredClone(newVal);\n });\n\n data.attributes = attributes;\n }\n\n const changedRelationships = cache.changedRelationships(identifier);\n if (changedRelationships.size) {\n const relationships: Record<string, ChangedRelationshipData> = {};\n changedRelationships.forEach((diff, key) => {\n relationships[key] = { data: fixRelData(diff.localState) } as ChangedRelationshipData;\n });\n\n data.relationships = relationships;\n }\n\n return { data };\n}\n"],"names":["JsonApiAccept","DEFAULT_CONFIG","host","namespace","ACCEPT_HEADER_VALUE","setBuildURLConfig","config","Object","assign","profiles","extensions","accept","values","length","join","setConfig","findRecord","arg1","arg2","arg3","identifier","type","id","options","cacheOptions","extractCacheOptions","urlOptions","op","resourcePath","pluralize","copyForwardUrlOptions","url","buildBaseURL","headers","Headers","append","include","buildQueryParams","urlParamsSettings","method","records","query","queryString","postQuery","queryData","structuredClone","key","body","JSON","stringify","isExisting","deleteRecord","record","recordIdentifierFor","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","data","createRecord","updateRecord","patch","serializeResources","cache","identifiers","Array","isArray","map","_serializeResource","fixRef","lid","fixRelData","rel","ref","peek","String","relationships","keys","relationship","serializePatch","hasChangedAttrs","attrsChanges","changedAttrs","attributes","forEach","change","newVal","undefined","changedRelationships","size","diff","localState"],"mappings":";;;;;;AAgBA,MAAMA,aAAa,GAAG,0BAA0B;AAChD,MAAMC,cAA6B,GAAG;AAAEC,EAAAA,IAAI,EAAE,EAAE;AAAEC,EAAAA,SAAS,EAAE;AAAG,CAAC;AAE1D,IAAIC,mBAAmB,GAAG,0BAA0B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACC,MAAqB,EAAQ;EACpDC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEP,cAAc,EAAEK,MAAM,CAAC;AAElD,EAAA,IAAIA,MAAM,CAACG,QAAQ,IAAIH,MAAM,CAACI,UAAU,EAAE;IACxC,IAAIC,MAAM,GAAGX,aAAa;IAC1B,IA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B,UAAU,GAAGA,UAAU;AAC9B;AAEA,EAAA,MAAMK,oBAAoB,GAAGzB,KAAK,CAACyB,oBAAoB,CAACvE,UAAU,CAAC;EACnE,IAAIuE,oBAAoB,CAACC,IAAI,EAAE;IAC7B,MAAMb,aAAsD,GAAG,EAAE;AACjEY,IAAAA,oBAAoB,CAACJ,OAAO,CAAC,CAACM,IAAI,EAAE/C,GAAG,KAAK;MAC1CiC,aAAa,CAACjC,GAAG,CAAC,GAAG;AAAEe,QAAAA,IAAI,EAAEa,UAAU,CAACmB,IAAI,CAACC,UAAU;OAA8B;AACvF,KAAC,CAAC;IAEFjC,IAAI,CAACkB,aAAa,GAAGA,aAAa;AACpC;EAEA,OAAO;AAAElB,IAAAA;GAAM;AACjB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/utilities",
3
- "version": "5.6.0-alpha.12",
3
+ "version": "5.6.0-alpha.14",
4
4
  "description": "Utilities package for WarpDrive | Things your app might find useful",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "peerDependencies": {
39
- "@warp-drive/core": "5.6.0-alpha.12"
39
+ "@warp-drive/core": "5.6.0-alpha.14"
40
40
  },
41
41
  "dependencies": {
42
42
  "@embroider/macros": "^1.16.12"
@@ -45,8 +45,8 @@
45
45
  "@babel/core": "^7.26.10",
46
46
  "@babel/plugin-transform-typescript": "^7.27.0",
47
47
  "@babel/preset-typescript": "^7.27.0",
48
- "@warp-drive/internal-config": "5.6.0-alpha.12",
49
- "@warp-drive/core": "5.6.0-alpha.12",
48
+ "@warp-drive/internal-config": "5.6.0-alpha.14",
49
+ "@warp-drive/core": "5.6.0-alpha.14",
50
50
  "decorator-transforms": "^2.3.0",
51
51
  "expect-type": "^1.2.1",
52
52
  "typescript": "^5.8.3",