@warp-drive-mirror/utilities 5.10.0-alpha.2 → 5.10.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -7
- package/cjs-dist/string.cjs +23 -8
- package/cjs-dist/string.cjs.map +1 -1
- package/dist/-private.d.ts +0 -2
- package/dist/-private.d.ts.map +1 -1
- package/dist/-private.js +1 -1
- package/dist/active-record.d.ts +21 -6
- package/dist/active-record.d.ts.map +1 -1
- package/dist/active-record.js +17 -8
- package/dist/active-record.js.map +1 -1
- package/dist/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/derivations.d.ts +3 -2
- package/dist/derivations.d.ts.map +1 -1
- package/dist/derivations.js +7 -2
- package/dist/derivations.js.map +1 -1
- package/dist/handlers.d.ts +26 -9
- package/dist/handlers.d.ts.map +1 -1
- package/dist/handlers.js +29 -9
- package/dist/handlers.js.map +1 -1
- package/dist/{index-BeMAuqgZ.d.ts → index-Dv5kZpGe.d.ts} +47 -3
- package/dist/index-Dv5kZpGe.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -8
- package/dist/index.js.map +1 -1
- package/dist/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/json-api.d.ts +51 -11
- package/dist/json-api.d.ts.map +1 -1
- package/dist/json-api.js +43 -12
- package/dist/json-api.js.map +1 -1
- package/dist/rest.d.ts +20 -6
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +17 -8
- package/dist/rest.js.map +1 -1
- package/dist/{string-CWmAluxh.js → string-DFhbMVCj.js} +23 -6
- package/dist/string-DFhbMVCj.js.map +1 -0
- package/dist/string.d.ts +19 -4
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +1 -1
- package/dist/unpkg/dev/-private.js +1 -1
- package/dist/unpkg/dev/active-record.js +17 -8
- package/dist/unpkg/dev/active-record.js.map +1 -1
- package/dist/unpkg/dev/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/unpkg/dev/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/dev/derivations.js +7 -2
- package/dist/unpkg/dev/derivations.js.map +1 -1
- package/dist/unpkg/dev/handlers.js +29 -9
- package/dist/unpkg/dev/handlers.js.map +1 -1
- package/dist/unpkg/dev/index.js +54 -8
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/dev/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/unpkg/dev/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/dev/json-api.js +43 -12
- package/dist/unpkg/dev/json-api.js.map +1 -1
- package/dist/unpkg/dev/rest.js +17 -8
- package/dist/unpkg/dev/rest.js.map +1 -1
- package/dist/unpkg/dev/{string-j4ur-TDs.js → string-D9jrClhQ.js} +23 -6
- package/dist/unpkg/dev/string-D9jrClhQ.js.map +1 -0
- package/dist/unpkg/dev/string.js +1 -1
- package/dist/unpkg/dev-deprecated/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/active-record.js +17 -8
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/unpkg/dev-deprecated/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/derivations.js +7 -2
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/dev-deprecated/handlers.js +29 -9
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/dev-deprecated/index.js +54 -8
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/unpkg/dev-deprecated/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/json-api.js +43 -12
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/rest.js +17 -8
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{string-j4ur-TDs.js → string-D9jrClhQ.js} +23 -6
- package/dist/unpkg/dev-deprecated/string-D9jrClhQ.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -1
- package/dist/unpkg/prod/-private.js +1 -1
- package/dist/unpkg/prod/active-record.js +17 -8
- package/dist/unpkg/prod/active-record.js.map +1 -1
- package/dist/unpkg/prod/builder-utils-bjXbHa-m.js +15 -0
- package/dist/unpkg/prod/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/prod/derivations.js +7 -2
- package/dist/unpkg/prod/derivations.js.map +1 -1
- package/dist/unpkg/prod/handlers.js +29 -9
- package/dist/unpkg/prod/handlers.js.map +1 -1
- package/dist/unpkg/prod/index.js +54 -8
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod/inflections-CWdUh2K_.js +79 -0
- package/dist/unpkg/prod/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/prod/json-api.js +43 -12
- package/dist/unpkg/prod/json-api.js.map +1 -1
- package/dist/unpkg/prod/rest.js +17 -8
- package/dist/unpkg/prod/rest.js.map +1 -1
- package/dist/unpkg/prod/string-Du9nRZEd.js +300 -0
- package/dist/unpkg/prod/string-Du9nRZEd.js.map +1 -0
- package/dist/unpkg/prod/string.js +1 -1
- package/dist/unpkg/prod-deprecated/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/active-record.js +17 -8
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
- package/dist/unpkg/prod-deprecated/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/derivations.js +7 -2
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/prod-deprecated/handlers.js +29 -9
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/prod-deprecated/index.js +54 -8
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
- package/dist/unpkg/prod-deprecated/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/json-api.js +43 -12
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/rest.js +17 -8
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{string-T1ahjLdj.js → string-Du9nRZEd.js} +23 -6
- package/dist/unpkg/prod-deprecated/string-Du9nRZEd.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -1
- package/logos/README.md +1 -1
- package/package.json +9 -9
- package/dist/index-BeMAuqgZ.d.ts.map +0 -1
- package/dist/string-CWmAluxh.js.map +0 -1
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +0 -1
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +0 -1
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +0 -16
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +0 -80
- package/dist/unpkg/prod/string-T1ahjLdj.js +0 -283
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +0 -1
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +0 -1
package/dist/string.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
//#region src/-private/string/inflect.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Marks a word as uncountable. Uncountable words are not pluralized
|
|
4
3
|
* or singularized.
|
|
5
4
|
*
|
|
5
|
+
* @summary Registers a word that `pluralize` and `singularize` should always return unchanged.
|
|
6
6
|
* @public
|
|
7
7
|
* @since 4.13.0
|
|
8
8
|
*/
|
|
@@ -11,6 +11,7 @@ export declare function uncountable(word: string): void;
|
|
|
11
11
|
* Marks a list of words as uncountable. Uncountable words are not pluralized
|
|
12
12
|
* or singularized.
|
|
13
13
|
*
|
|
14
|
+
* @summary Registers a list of words that `pluralize` and `singularize` should always return unchanged.
|
|
14
15
|
* @public
|
|
15
16
|
* @since 4.13.0
|
|
16
17
|
*/
|
|
@@ -19,6 +20,8 @@ export declare function loadUncountable(uncountables: string[]): void;
|
|
|
19
20
|
* Marks a word as irregular. Irregular words have unique
|
|
20
21
|
* pluralization and singularization rules.
|
|
21
22
|
*
|
|
23
|
+
* @summary Registers a singular and plural word pair that `pluralize` and `singularize` map directly instead of
|
|
24
|
+
* applying rules.
|
|
22
25
|
* @public
|
|
23
26
|
* @since 4.13.0
|
|
24
27
|
*/
|
|
@@ -27,6 +30,7 @@ export declare function irregular(single: string, plur: string): void;
|
|
|
27
30
|
* Marks a list of word pairs as irregular. Irregular words have unique
|
|
28
31
|
* pluralization and singularization rules.
|
|
29
32
|
*
|
|
33
|
+
* @summary Registers a list of singular and plural word pairs that `pluralize` and `singularize` map directly.
|
|
30
34
|
* @public
|
|
31
35
|
* @since 4.13.0
|
|
32
36
|
*/
|
|
@@ -34,6 +38,7 @@ export declare function loadIrregular(irregularPairs: Array<[string, string]>):
|
|
|
34
38
|
/**
|
|
35
39
|
* Clears the caches for singularize and pluralize.
|
|
36
40
|
*
|
|
41
|
+
* @summary Empties the cached results of `singularize` and `pluralize` while keeping all inflection rules.
|
|
37
42
|
* @public
|
|
38
43
|
* @since 4.13.0
|
|
39
44
|
*/
|
|
@@ -41,6 +46,7 @@ export declare function clear(): void;
|
|
|
41
46
|
/**
|
|
42
47
|
* Resets the inflection rules to the defaults.
|
|
43
48
|
*
|
|
49
|
+
* @summary Discards all custom inflection rules and caches, then restores the built-in default rules.
|
|
44
50
|
* @public
|
|
45
51
|
* @since 4.13.0
|
|
46
52
|
*/
|
|
@@ -49,6 +55,7 @@ export declare function resetToDefaults(): void;
|
|
|
49
55
|
* Clears all inflection rules
|
|
50
56
|
* and resets the caches for singularize and pluralize.
|
|
51
57
|
*
|
|
58
|
+
* @summary Removes every inflection rule, including the defaults, and empties the `singularize` and `pluralize` caches.
|
|
52
59
|
* @public
|
|
53
60
|
* @since 4.13.0
|
|
54
61
|
*/
|
|
@@ -56,6 +63,7 @@ export declare function clearRules(): void;
|
|
|
56
63
|
/**
|
|
57
64
|
* Singularizes a word.
|
|
58
65
|
*
|
|
66
|
+
* @summary Returns the singular form of an English word using the registered inflection rules, with cached results.
|
|
59
67
|
* @public
|
|
60
68
|
* @since 4.13.0
|
|
61
69
|
*/
|
|
@@ -63,6 +71,7 @@ export declare function singularize(word: string): string;
|
|
|
63
71
|
/**
|
|
64
72
|
* Pluralizes a word.
|
|
65
73
|
*
|
|
74
|
+
* @summary Returns the plural form of an English word using the registered inflection rules, with cached results.
|
|
66
75
|
* @public
|
|
67
76
|
* @since 4.13.0
|
|
68
77
|
*/
|
|
@@ -70,6 +79,7 @@ export declare function pluralize(word: string): string;
|
|
|
70
79
|
/**
|
|
71
80
|
* Adds a pluralization rule.
|
|
72
81
|
*
|
|
82
|
+
* @summary Adds a regex and replacement rule that `pluralize` checks before all existing plural rules.
|
|
73
83
|
* @public
|
|
74
84
|
* @since 4.13.0
|
|
75
85
|
*/
|
|
@@ -77,12 +87,11 @@ export declare function plural(regex: RegExp, string: string): void;
|
|
|
77
87
|
/**
|
|
78
88
|
* Adds a singularization rule.
|
|
79
89
|
*
|
|
90
|
+
* @summary Adds a regex and replacement rule that `singularize` checks before all existing singular rules.
|
|
80
91
|
* @public
|
|
81
92
|
* @since 4.13.0
|
|
82
93
|
*/
|
|
83
94
|
export declare function singular(regex: RegExp, string: string): void;
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/-private/string/transform.d.ts
|
|
86
95
|
/**
|
|
87
96
|
* Replaces underscores, spaces, or camelCase with dashes.
|
|
88
97
|
*
|
|
@@ -96,6 +105,7 @@ export declare function singular(regex: RegExp, string: string): void;
|
|
|
96
105
|
* dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
|
|
97
106
|
* ```
|
|
98
107
|
*
|
|
108
|
+
* @summary Converts camelCase, underscored, or spaced strings to dasherized form, such as `innerHTML` to `inner-html`.
|
|
99
109
|
* @public
|
|
100
110
|
* @since 4.13.0
|
|
101
111
|
*/
|
|
@@ -114,6 +124,8 @@ export declare const dasherize: (str: string) => string;
|
|
|
114
124
|
* camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
|
|
115
125
|
* ```
|
|
116
126
|
*
|
|
127
|
+
* @summary Converts dashed, underscored, dotted, or spaced strings to lowerCamelCase, such as `action_name` to
|
|
128
|
+
* `actionName`.
|
|
117
129
|
* @public
|
|
118
130
|
* @since 4.13.0
|
|
119
131
|
*/
|
|
@@ -131,6 +143,7 @@ export declare function camelize(str: string): string;
|
|
|
131
143
|
* underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
|
|
132
144
|
* ```
|
|
133
145
|
*
|
|
146
|
+
* @summary Converts camelCase, dashed, or spaced strings to lowercase snake_case, such as `innerHTML` to `inner_html`.
|
|
134
147
|
* @public
|
|
135
148
|
* @since 4.13.0
|
|
136
149
|
*/
|
|
@@ -148,6 +161,7 @@ export declare function underscore(str: string): string;
|
|
|
148
161
|
* capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
|
|
149
162
|
* ```
|
|
150
163
|
*
|
|
164
|
+
* @summary Uppercases the first letter of a string, and of each `/`-separated path segment, leaving the rest unchanged.
|
|
151
165
|
* @public
|
|
152
166
|
* @since 4.13.0
|
|
153
167
|
*/
|
|
@@ -156,9 +170,10 @@ export declare function capitalize(str: string): string;
|
|
|
156
170
|
* Sets the maximum size of the LRUCache for all string transformation functions.
|
|
157
171
|
* The default size is 10,000.
|
|
158
172
|
*
|
|
173
|
+
* @summary Sets how many results the `camelize`, `underscore`, `capitalize`, and `dasherize` caches each keep (default
|
|
174
|
+
* 10,000).
|
|
159
175
|
* @public
|
|
160
176
|
* @since 4.13.0
|
|
161
177
|
*/
|
|
162
178
|
export declare function setMaxLRUCacheSize(size: number): void;
|
|
163
|
-
//#endregion
|
|
164
179
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","names":[],"sources":["../src/-private/string/inflect.ts","../src/-private/string/transform.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"string.d.ts","names":[],"sources":["../src/-private/string/inflect.ts","../src/-private/string/transform.ts"],"mappings":";;;;;;;;wBA+BgB,YAAY;;;;;;;;;wBAYZ,gBAAgB;;;;;;;;;;wBAehB,UAAU,gBAAgB;;;;;;;;;wBAkB1B,cAAc,gBAAgB;;;;;;;;wBAoB9B;;;;;;;;wBAYA;;;;;;;;;wBAgBA;;;;;;;;wBAiBA,YAAY;;;;;;;;wBAaZ,UAAU;;;;;;;;wBAsBV,OAAO,OAAO,QAAQ;;;;;;;;wBAiBtB,SAAS,OAAO,QAAQ;;;;;;;;;;;;;;;;;;qBCzJ3B,YAAY;;;;;;;;;;;;;;;;;;;;wBAqBT,SAAS;;;;;;;;;;;;;;;;;;wBAqBT,WAAW;;;;;;;;;;;;;;;;;;wBAqBX,WAAW;;;;;;;;;;wBAaX,mBAAmB"}
|
package/dist/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as loadUncountable, c as resetToDefaults, d as uncountable, f as camelize, g as underscore, h as setMaxLRUCacheSize, i as loadIrregular, l as singular, m as dasherize, n as clearRules, o as plural, p as capitalize, r as irregular, s as pluralize, t as clear, u as singularize } from "./string-
|
|
1
|
+
import { a as loadUncountable, c as resetToDefaults, d as uncountable, f as camelize, g as underscore, h as setMaxLRUCacheSize, i as loadIrregular, l as singular, m as dasherize, n as clearRules, o as plural, p as capitalize, r as irregular, s as pluralize, t as clear, u as singularize } from "./string-DFhbMVCj.js";
|
|
2
2
|
|
|
3
3
|
export { camelize, capitalize, clear, clearRules, dasherize, irregular, loadIrregular, loadUncountable, plural, pluralize, resetToDefaults, setMaxLRUCacheSize, singular, singularize, uncountable, underscore };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { buildBaseURL, buildQueryParams } from "./index.js";
|
|
2
|
-
import { g as underscore, s as pluralize } from "./string-
|
|
3
|
-
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-
|
|
2
|
+
import { g as underscore, s as pluralize } from "./string-D9jrClhQ.js";
|
|
3
|
+
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-bjXbHa-m.js";
|
|
4
4
|
import { recordIdentifierFor } from "@warp-drive-mirror/core";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/-private/active-record/find-record.ts
|
|
7
7
|
function findRecord(arg1, arg2, arg3) {
|
|
8
8
|
const identifier = typeof arg1 === "string" ? {
|
|
9
9
|
type: arg1,
|
|
@@ -30,8 +30,7 @@ function findRecord(arg1, arg2, arg3) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
//#region src/-private/active-record/query.ts
|
|
33
|
+
// src/-private/active-record/query.ts
|
|
35
34
|
function query(type, query = {}, options = {}) {
|
|
36
35
|
const cacheOptions = extractCacheOptions(options);
|
|
37
36
|
const urlOptions = {
|
|
@@ -53,8 +52,7 @@ function query(type, query = {}, options = {}) {
|
|
|
53
52
|
};
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
//#region src/-private/active-record/save-record.ts
|
|
55
|
+
// src/-private/active-record/save-record.ts
|
|
58
56
|
function isExisting(identifier) {
|
|
59
57
|
return "id" in identifier && identifier.id !== null && "type" in identifier && identifier.type !== null;
|
|
60
58
|
}
|
|
@@ -62,6 +60,9 @@ function isExisting(identifier) {
|
|
|
62
60
|
* Builds request options to delete record for resources,
|
|
63
61
|
* configured for the url, method and header expectations of ActiveRecord APIs.
|
|
64
62
|
*
|
|
63
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
64
|
+
* when to use one.
|
|
65
|
+
*
|
|
65
66
|
* **Basic Usage**
|
|
66
67
|
*
|
|
67
68
|
* ```ts
|
|
@@ -103,6 +104,7 @@ function isExisting(identifier) {
|
|
|
103
104
|
* const data = await store.request(options);
|
|
104
105
|
* ```
|
|
105
106
|
*
|
|
107
|
+
* @summary Builds a `DELETE` request that persists deletion of an existing record, using ActiveRecord-style URLs.
|
|
106
108
|
* @public
|
|
107
109
|
* @param record
|
|
108
110
|
* @param options
|
|
@@ -137,6 +139,9 @@ function deleteRecord(record, options = {}) {
|
|
|
137
139
|
* Builds request options to create new record for resources,
|
|
138
140
|
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
139
141
|
*
|
|
142
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
143
|
+
* when to use one.
|
|
144
|
+
*
|
|
140
145
|
* **Basic Usage**
|
|
141
146
|
*
|
|
142
147
|
* ```ts
|
|
@@ -168,6 +173,7 @@ function deleteRecord(record, options = {}) {
|
|
|
168
173
|
* const data = await store.request(options);
|
|
169
174
|
* ```
|
|
170
175
|
*
|
|
176
|
+
* @summary Builds a `POST` request that saves a newly created record, using ActiveRecord-style URLs.
|
|
171
177
|
* @public
|
|
172
178
|
* @param record
|
|
173
179
|
* @param options
|
|
@@ -199,6 +205,9 @@ function createRecord(record, options = {}) {
|
|
|
199
205
|
* Builds request options to update existing record for resources,
|
|
200
206
|
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
201
207
|
*
|
|
208
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
209
|
+
* when to use one.
|
|
210
|
+
*
|
|
202
211
|
* **Basic Usage**
|
|
203
212
|
*
|
|
204
213
|
* ```ts
|
|
@@ -233,6 +242,7 @@ function createRecord(record, options = {}) {
|
|
|
233
242
|
* const data = await store.request(options);
|
|
234
243
|
* ```
|
|
235
244
|
*
|
|
245
|
+
* @summary Builds a `PUT` (or `PATCH`) request that saves changes to an existing record, using ActiveRecord-style URLs.
|
|
236
246
|
* @public
|
|
237
247
|
* @param record
|
|
238
248
|
* @param options
|
|
@@ -264,6 +274,5 @@ function updateRecord(record, options = {}) {
|
|
|
264
274
|
};
|
|
265
275
|
}
|
|
266
276
|
|
|
267
|
-
//#endregion
|
|
268
277
|
export { createRecord, deleteRecord, findRecord, query, updateRecord };
|
|
269
278
|
//# sourceMappingURL=active-record.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-record.js","names":["recordIdentifierFor","buildBaseURL","pluralize","underscore","copyForwardUrlOptions","isExisting","identifier","id","type","deleteRecord","record","options","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../../../src/-private/active-record/find-record.ts","../../../src/-private/active-record/query.ts","../../../src/-private/active-record/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param options\n */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n> = ReactiveDataDocument<T, M, E>;\n","import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // oxlint-disable-next-line no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(underscore(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive-mirror/core';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<\n T extends TypedRecordInstance,\n RT extends TypedRecordInstance = T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"active-record.js","names":["recordIdentifierFor","buildBaseURL","pluralize","underscore","copyForwardUrlOptions","isExisting","identifier","id","type","deleteRecord","record","options","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../../../src/-private/active-record/find-record.ts","../../../src/-private/active-record/query.ts","../../../src/-private/active-record/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most ActiveRecord APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `GET` request for one resource by type and id, using ActiveRecord-style pluralized, underscored\n * URLs.\n * @public\n * @param identifier\n * @param options\n */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n> = ReactiveDataDocument<T, M, E>;\n","import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most ActiveRecord APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/active-record';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `GET` request that queries a resource type with query params, using ActiveRecord-style URLs.\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // oxlint-disable-next-line no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(underscore(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive-mirror/core';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of ActiveRecord APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `DELETE` request that persists deletion of an existing record, using ActiveRecord-style URLs.\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most ActiveRecord APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `POST` request that saves a newly created record, using ActiveRecord-style URLs.\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most ActiveRecord APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `PUT` (or `PATCH`) request that saves changes to an existing record, using ActiveRecord-style URLs.\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<\n T extends TypedRecordInstance,\n RT extends TypedRecordInstance = T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/-private/builder-utils.ts
|
|
2
2
|
function copyForwardUrlOptions(urlOptions, options) {
|
|
3
3
|
if ("host" in options) urlOptions.host = options.host;
|
|
4
4
|
if ("namespace" in options) urlOptions.namespace = options.namespace;
|
|
@@ -11,6 +11,5 @@ function extractCacheOptions(options) {
|
|
|
11
11
|
return cacheOptions;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
//#endregion
|
|
15
14
|
export { extractCacheOptions as n, copyForwardUrlOptions as t };
|
|
16
|
-
//# sourceMappingURL=builder-utils-
|
|
15
|
+
//# sourceMappingURL=builder-utils-bjXbHa-m.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder-utils-
|
|
1
|
+
{"version":3,"file":"builder-utils-bjXbHa-m.js","names":[],"sources":["../../../src/-private/builder-utils.ts"],"sourcesContent":["import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive-mirror/core/types/request';\n\nimport type { UrlOptions } from '../index.ts';\n\nexport function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void {\n if ('host' in options) {\n urlOptions.host = options.host;\n }\n if ('namespace' in options) {\n urlOptions.namespace = options.namespace;\n }\n if ('resourcePath' in options) {\n urlOptions.resourcePath = options.resourcePath;\n }\n}\n\nexport function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions {\n const cacheOptions: CacheOptions = {};\n if ('reload' in options) {\n cacheOptions.reload = options.reload;\n }\n if ('backgroundReload' in options) {\n cacheOptions.backgroundReload = options.backgroundReload;\n }\n return cacheOptions;\n}\n"],"mappings":";AAIA,SAAgB,sBAAsB,YAAwB,SAA0C;CACtG,IAAI,UAAU,SACZ,WAAW,OAAO,QAAQ;CAE5B,IAAI,eAAe,SACjB,WAAW,YAAY,QAAQ;CAEjC,IAAI,kBAAkB,SACpB,WAAW,eAAe,QAAQ;AAEtC;AAEA,SAAgB,oBAAoB,SAAkD;CACpF,MAAM,eAA6B,CAAC;CACpC,IAAI,YAAY,SACd,aAAa,SAAS,QAAQ;CAEhC,IAAI,sBAAsB,SACxB,aAAa,mBAAmB,QAAQ;CAE1C,OAAO;AACT"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { Type } from "@warp-drive-mirror/core/types/symbols";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/derivations.ts
|
|
4
|
+
/**
|
|
5
|
+
* @module
|
|
6
|
+
* @summary The `concat` derivation, which joins a record's listed fields into one string with an optional separator.
|
|
7
|
+
*/
|
|
4
8
|
/**
|
|
5
9
|
* A derivation for use by {@link ReactiveResource} that joins the given fields
|
|
6
10
|
* with the optional separator (or '' if no separator is provided).
|
|
7
11
|
*
|
|
8
12
|
* Generally you should not need to import and use this function directly.
|
|
9
13
|
*
|
|
14
|
+
* @summary Derivation registered as `concat` that joins a record's listed `fields` into one string with an optional
|
|
15
|
+
* `separator`.
|
|
10
16
|
* @example
|
|
11
17
|
* {
|
|
12
18
|
* name: 'fullName',
|
|
@@ -25,6 +31,5 @@ const concat = (record, options, _prop) => {
|
|
|
25
31
|
};
|
|
26
32
|
concat[Type] = "concat";
|
|
27
33
|
|
|
28
|
-
//#endregion
|
|
29
34
|
export { concat };
|
|
30
35
|
//# sourceMappingURL=derivations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivations.js","names":["Type","concat","record","options","_prop","Error","opts","fields","map","field","join","separator"],"sources":["../../../src/derivations.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"derivations.js","names":["Type","concat","record","options","_prop","Error","opts","fields","map","field","join","separator"],"sources":["../../../src/derivations.ts"],"sourcesContent":["/**\n * @module\n * @summary The `concat` derivation, which joins a record's listed fields into one string with an optional separator.\n */\n\nimport type { ReactiveResource } from '@warp-drive-mirror/core/reactive';\nimport { Type } from '@warp-drive-mirror/core/types/symbols';\n\ninterface ConcatDerivation {\n (\n record: ReactiveResource & { [key: string]: unknown },\n options: Record<string, unknown> | null,\n _prop: string\n ): string;\n [Type]: 'concat';\n}\n\n/**\n * A derivation for use by {@link ReactiveResource} that joins the given fields\n * with the optional separator (or '' if no separator is provided).\n *\n * Generally you should not need to import and use this function directly.\n *\n * @summary Derivation registered as `concat` that joins a record's listed `fields` into one string with an optional\n * `separator`.\n * @example\n * {\n * name: 'fullName',\n * kind: 'derived',\n * type: 'concat',\n * options: {\n * fields: ['firstName', 'lastName'],\n * separator: ' ',\n * },\n * }\n */\nexport const concat: ConcatDerivation = (\n record: ReactiveResource & { [key: string]: unknown },\n options: Record<string, unknown> | null,\n _prop: string\n) => {\n if (!options) {\n throw new Error(`options is required`);\n }\n // SAFETY: we cast internally to a more specific type, for our own use\n // SAFETY: but provide the more general signature to the schema service\n const opts = options as { fields: string[]; separator?: string };\n return opts.fields.map((field) => record[field]).join(opts.separator ?? '');\n};\nconcat[Type] = 'concat';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAaC,UACXC,QACAC,SACAC,UACG;CACH,IAAI,CAACD,SACH,MAAM,IAAIE,MAAM,qBAAqB;CAIvC,MAAMC,OAAOH;CACb,OAAOG,KAAKC,OAAOC,KAAKC,UAAUP,OAAOO,MAAM,CAAC,CAACC,KAAKJ,KAAKK,aAAa,EAAE;AAC5E;AACAV,OAAOD,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/-private/handlers/auto-compress.ts
|
|
2
2
|
function isCompressibleMethod(method) {
|
|
3
3
|
return method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE";
|
|
4
4
|
}
|
|
@@ -6,6 +6,8 @@ function isCompressibleMethod(method) {
|
|
|
6
6
|
* Whether the browser supports `ReadableStream` as a request body
|
|
7
7
|
* in a `POST` request.
|
|
8
8
|
*
|
|
9
|
+
* @summary Whether the current browser can send a `ReadableStream` as a `fetch` request body, detected once at
|
|
10
|
+
* module load.
|
|
9
11
|
* @group Constants
|
|
10
12
|
*/
|
|
11
13
|
const SupportsRequestStreams = (() => {
|
|
@@ -21,8 +23,17 @@ const SupportsRequestStreams = (() => {
|
|
|
21
23
|
return duplexAccessed && !hasContentType;
|
|
22
24
|
})();
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
26
|
+
* The minimum body size, per body type, at which {@link AutoCompress} compresses a request
|
|
27
|
+
* body. Passed as {@link CompressionOptions.constraints}.
|
|
25
28
|
*
|
|
29
|
+
* @summary Minimum request body sizes, per body type, at which `AutoCompress` compresses a body.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Options for configuring the {@link AutoCompress} handler.
|
|
34
|
+
*
|
|
35
|
+
* @summary Options for `new AutoCompress()`: the compression format, size constraints and whether to stream the body.
|
|
36
|
+
* @public
|
|
26
37
|
*/
|
|
27
38
|
const DEFAULT_CONSTRAINTS = {
|
|
28
39
|
Blob: 1e3,
|
|
@@ -56,6 +67,8 @@ const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
|
56
67
|
* }
|
|
57
68
|
* ```
|
|
58
69
|
*
|
|
70
|
+
* @summary Request handler that compresses large `POST`, `PUT`, `PATCH`, and `DELETE` bodies with `CompressionStream`,
|
|
71
|
+
* optionally streaming them.
|
|
59
72
|
* @group Handlers
|
|
60
73
|
* @public
|
|
61
74
|
* @since 5.5.0
|
|
@@ -117,14 +130,15 @@ function encodingForFormat(format) {
|
|
|
117
130
|
}
|
|
118
131
|
}
|
|
119
132
|
|
|
120
|
-
|
|
121
|
-
//#region src/-private/handlers/gated.ts
|
|
133
|
+
// src/-private/handlers/gated.ts
|
|
122
134
|
/**
|
|
123
135
|
* If CheckFn returns true, the wrapped handler will be used.
|
|
124
136
|
* If CheckFn returns false, the wrapped handler will be skipped.
|
|
125
137
|
*/
|
|
126
138
|
/**
|
|
127
139
|
*
|
|
140
|
+
* @summary Request handler that wraps another handler and runs it only when a check function returns true for the
|
|
141
|
+
* request.
|
|
128
142
|
* @group Handlers
|
|
129
143
|
* @public
|
|
130
144
|
*/
|
|
@@ -145,8 +159,7 @@ var Gate = class {
|
|
|
145
159
|
}
|
|
146
160
|
};
|
|
147
161
|
|
|
148
|
-
|
|
149
|
-
//#region src/-private/handlers/meta-doc.ts
|
|
162
|
+
// src/-private/handlers/meta-doc.ts
|
|
150
163
|
/**
|
|
151
164
|
* MetaDocHandler processes requests that are marked as meta requests.
|
|
152
165
|
*
|
|
@@ -190,6 +203,7 @@ var Gate = class {
|
|
|
190
203
|
* Errors are not processed by this handler, so if the request fails and the error response
|
|
191
204
|
* is not in {json:api} format additional processing may be needed.
|
|
192
205
|
*
|
|
206
|
+
* @summary Request handler that wraps the whole response body in `meta` for requests with `options.isMetaRequest` set.
|
|
193
207
|
* @group Handlers
|
|
194
208
|
*/
|
|
195
209
|
const MetaDocHandler = { request(context, next) {
|
|
@@ -202,8 +216,7 @@ function processResponse(response) {
|
|
|
202
216
|
return { meta: response.content };
|
|
203
217
|
}
|
|
204
218
|
|
|
205
|
-
|
|
206
|
-
//#region src/-private/handlers/utils.ts
|
|
219
|
+
// src/-private/handlers/utils.ts
|
|
207
220
|
if (typeof FastBoot === "undefined") globalThis.addEventListener("beforeunload", function() {
|
|
208
221
|
sessionStorage.setItem("tab-closed", "true");
|
|
209
222
|
});
|
|
@@ -222,12 +235,15 @@ function getTabId() {
|
|
|
222
235
|
* useful for observability/tracing and deduping
|
|
223
236
|
* across multiple tabs.
|
|
224
237
|
*
|
|
238
|
+
* @summary Random UUID identifying the current browser tab, kept in `sessionStorage` across reloads, for request
|
|
239
|
+
* tracing.
|
|
225
240
|
* @group Constants
|
|
226
241
|
*/
|
|
227
242
|
const TAB_ID = getTabId();
|
|
228
243
|
/**
|
|
229
244
|
* The epoch seconds at which the tab id was generated
|
|
230
245
|
*
|
|
246
|
+
* @summary Epoch seconds recorded when this module loaded, paired with `TAB_ID` in trace headers.
|
|
231
247
|
* @group Constants
|
|
232
248
|
*/
|
|
233
249
|
const TAB_ASSIGNED = Math.floor(Date.now() / 1e3);
|
|
@@ -240,6 +256,8 @@ const TAB_ASSIGNED = Math.floor(Date.now() / 1e3);
|
|
|
240
256
|
*
|
|
241
257
|
* Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
|
|
242
258
|
*
|
|
259
|
+
* @summary Sets an `X-Amzn-Trace-Id` header carrying a per-request id and the tab id, so requests can be traced to
|
|
260
|
+
* their browser tab.
|
|
243
261
|
* @group Utility Functions
|
|
244
262
|
*/
|
|
245
263
|
function addTraceHeader(headers) {
|
|
@@ -251,6 +269,7 @@ function addTraceHeader(headers) {
|
|
|
251
269
|
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
252
270
|
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
253
271
|
*
|
|
272
|
+
* @summary The 8192-byte URL length limit, taken from AWS CloudFront, that `assertInvalidUrlLength` checks against.
|
|
254
273
|
* @group Constants
|
|
255
274
|
*/
|
|
256
275
|
const MAX_URL_LENGTH = 8192;
|
|
@@ -259,6 +278,8 @@ const MAX_URL_LENGTH = 8192;
|
|
|
259
278
|
*
|
|
260
279
|
* See also {@link MAX_URL_LENGTH}
|
|
261
280
|
*
|
|
281
|
+
* @summary Dev-mode assertion that throws when a URL is longer than `MAX_URL_LENGTH`, suggesting a `POST` or `QUERY`
|
|
282
|
+
* request instead.
|
|
262
283
|
* @group Utility Functions
|
|
263
284
|
*/
|
|
264
285
|
function assertInvalidUrlLength(url) {
|
|
@@ -267,6 +288,5 @@ function assertInvalidUrlLength(url) {
|
|
|
267
288
|
})(!url || url.length <= 8192);
|
|
268
289
|
}
|
|
269
290
|
|
|
270
|
-
//#endregion
|
|
271
291
|
export { AutoCompress, Gate, MAX_URL_LENGTH, MetaDocHandler, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
|
|
272
292
|
//# sourceMappingURL=handlers.js.map
|