@warp-drive/utilities 5.10.0-alpha.12 → 5.10.0-alpha.13
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 +9 -0
- package/cjs-dist/string.cjs +19 -0
- package/cjs-dist/string.cjs.map +1 -1
- package/dist/active-record.d.ts +21 -0
- package/dist/active-record.d.ts.map +1 -1
- package/dist/active-record.js +13 -1
- package/dist/active-record.js.map +1 -1
- package/dist/derivations.d.ts +2 -0
- package/dist/derivations.d.ts.map +1 -1
- package/dist/derivations.js +6 -0
- package/dist/derivations.js.map +1 -1
- package/dist/handlers.d.ts +15 -0
- package/dist/handlers.d.ts.map +1 -1
- package/dist/handlers.js +15 -0
- package/dist/handlers.js.map +1 -1
- package/dist/{index-D6QIwzqm.d.ts → index-Ds06tKwC.d.ts} +39 -1
- package/dist/index-Ds06tKwC.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/json-api.d.ts +36 -1
- package/dist/json-api.d.ts.map +1 -1
- package/dist/json-api.js +23 -1
- package/dist/json-api.js.map +1 -1
- package/dist/rest.d.ts +20 -0
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +13 -1
- package/dist/rest.js.map +1 -1
- package/dist/{string-CWmAluxh.js → string-BZACNuLp.js} +20 -1
- package/dist/string-BZACNuLp.js.map +1 -0
- package/dist/string.d.ts +19 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +1 -1
- package/dist/unpkg/dev/active-record.js +13 -1
- package/dist/unpkg/dev/active-record.js.map +1 -1
- package/dist/unpkg/dev/derivations.js +6 -0
- package/dist/unpkg/dev/derivations.js.map +1 -1
- package/dist/unpkg/dev/handlers.js +15 -0
- package/dist/unpkg/dev/handlers.js.map +1 -1
- package/dist/unpkg/dev/index.js +39 -0
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/dev/json-api.js +23 -1
- package/dist/unpkg/dev/json-api.js.map +1 -1
- package/dist/unpkg/dev/rest.js +13 -1
- package/dist/unpkg/dev/rest.js.map +1 -1
- package/dist/unpkg/dev/{string-j4ur-TDs.js → string-I8KHJXV7.js} +20 -1
- package/dist/unpkg/dev/string-I8KHJXV7.js.map +1 -0
- package/dist/unpkg/dev/string.js +1 -1
- package/dist/unpkg/dev-deprecated/active-record.js +13 -1
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/dev-deprecated/derivations.js +6 -0
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/dev-deprecated/handlers.js +15 -0
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/dev-deprecated/index.js +39 -0
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/dev-deprecated/json-api.js +23 -1
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/rest.js +13 -1
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{string-j4ur-TDs.js → string-I8KHJXV7.js} +20 -1
- package/dist/unpkg/dev-deprecated/string-I8KHJXV7.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -1
- package/dist/unpkg/prod/active-record.js +13 -1
- package/dist/unpkg/prod/active-record.js.map +1 -1
- package/dist/unpkg/prod/derivations.js +6 -0
- package/dist/unpkg/prod/derivations.js.map +1 -1
- package/dist/unpkg/prod/handlers.js +15 -0
- package/dist/unpkg/prod/handlers.js.map +1 -1
- package/dist/unpkg/prod/index.js +39 -0
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod/json-api.js +23 -1
- package/dist/unpkg/prod/json-api.js.map +1 -1
- package/dist/unpkg/prod/rest.js +13 -1
- package/dist/unpkg/prod/rest.js.map +1 -1
- package/dist/unpkg/prod/string-D8BEYx2W.js +302 -0
- package/dist/unpkg/prod/string-D8BEYx2W.js.map +1 -0
- package/dist/unpkg/prod/string.js +1 -1
- package/dist/unpkg/prod-deprecated/active-record.js +13 -1
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/prod-deprecated/derivations.js +6 -0
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/prod-deprecated/handlers.js +15 -0
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/prod-deprecated/index.js +39 -0
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/json-api.js +23 -1
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/rest.js +13 -1
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{string-T1ahjLdj.js → string-D8BEYx2W.js} +20 -1
- package/dist/unpkg/prod-deprecated/string-D8BEYx2W.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -1
- package/package.json +6 -6
- package/dist/index-D6QIwzqm.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/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
|
@@ -24,6 +24,7 @@ const CAPITALIZE_CACHE = new LRUCache((str) => str.replace(STRING_CAPITALIZE_REG
|
|
|
24
24
|
* dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
+
* @summary Converts camelCase, underscored, or spaced strings to dasherized form, such as `innerHTML` to `inner-html`.
|
|
27
28
|
* @public
|
|
28
29
|
* @since 4.13.0
|
|
29
30
|
*/
|
|
@@ -42,6 +43,8 @@ const dasherize$1 = dasherize;
|
|
|
42
43
|
* camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
|
|
43
44
|
* ```
|
|
44
45
|
*
|
|
46
|
+
* @summary Converts dashed, underscored, dotted, or spaced strings to lowerCamelCase, such as `action_name` to
|
|
47
|
+
* `actionName`.
|
|
45
48
|
* @public
|
|
46
49
|
* @since 4.13.0
|
|
47
50
|
*/
|
|
@@ -61,6 +64,7 @@ function camelize(str) {
|
|
|
61
64
|
* underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
|
|
62
65
|
* ```
|
|
63
66
|
*
|
|
67
|
+
* @summary Converts camelCase, dashed, or spaced strings to lowercase snake_case, such as `innerHTML` to `inner_html`.
|
|
64
68
|
* @public
|
|
65
69
|
* @since 4.13.0
|
|
66
70
|
*/
|
|
@@ -80,6 +84,7 @@ function underscore(str) {
|
|
|
80
84
|
* capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
|
|
81
85
|
* ```
|
|
82
86
|
*
|
|
87
|
+
* @summary Uppercases the first letter of a string, and of each `/`-separated path segment, leaving the rest unchanged.
|
|
83
88
|
* @public
|
|
84
89
|
* @since 4.13.0
|
|
85
90
|
*/
|
|
@@ -90,6 +95,8 @@ function capitalize(str) {
|
|
|
90
95
|
* Sets the maximum size of the LRUCache for all string transformation functions.
|
|
91
96
|
* The default size is 10,000.
|
|
92
97
|
*
|
|
98
|
+
* @summary Sets how many results the `camelize`, `underscore`, `capitalize`, and `dasherize` caches each keep (default
|
|
99
|
+
* 10,000).
|
|
93
100
|
* @public
|
|
94
101
|
* @since 4.13.0
|
|
95
102
|
*/
|
|
@@ -121,6 +128,7 @@ const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
|
|
|
121
128
|
* Marks a word as uncountable. Uncountable words are not pluralized
|
|
122
129
|
* or singularized.
|
|
123
130
|
*
|
|
131
|
+
* @summary Registers a word that `pluralize` and `singularize` should always return unchanged.
|
|
124
132
|
* @public
|
|
125
133
|
* @since 4.13.0
|
|
126
134
|
*/
|
|
@@ -131,6 +139,7 @@ function uncountable(word) {
|
|
|
131
139
|
* Marks a list of words as uncountable. Uncountable words are not pluralized
|
|
132
140
|
* or singularized.
|
|
133
141
|
*
|
|
142
|
+
* @summary Registers a list of words that `pluralize` and `singularize` should always return unchanged.
|
|
134
143
|
* @public
|
|
135
144
|
* @since 4.13.0
|
|
136
145
|
*/
|
|
@@ -143,6 +152,8 @@ function loadUncountable(uncountables) {
|
|
|
143
152
|
* Marks a word as irregular. Irregular words have unique
|
|
144
153
|
* pluralization and singularization rules.
|
|
145
154
|
*
|
|
155
|
+
* @summary Registers a singular and plural word pair that `pluralize` and `singularize` map directly instead of
|
|
156
|
+
* applying rules.
|
|
146
157
|
* @public
|
|
147
158
|
* @since 4.13.0
|
|
148
159
|
*/
|
|
@@ -156,6 +167,7 @@ function irregular(single, plur) {
|
|
|
156
167
|
* Marks a list of word pairs as irregular. Irregular words have unique
|
|
157
168
|
* pluralization and singularization rules.
|
|
158
169
|
*
|
|
170
|
+
* @summary Registers a list of singular and plural word pairs that `pluralize` and `singularize` map directly.
|
|
159
171
|
* @public
|
|
160
172
|
* @since 4.13.0
|
|
161
173
|
*/
|
|
@@ -171,6 +183,7 @@ loadIrregular(defaultRules.irregularPairs);
|
|
|
171
183
|
/**
|
|
172
184
|
* Clears the caches for singularize and pluralize.
|
|
173
185
|
*
|
|
186
|
+
* @summary Empties the cached results of `singularize` and `pluralize` while keeping all inflection rules.
|
|
174
187
|
* @public
|
|
175
188
|
* @since 4.13.0
|
|
176
189
|
*/
|
|
@@ -181,6 +194,7 @@ function clear() {
|
|
|
181
194
|
/**
|
|
182
195
|
* Resets the inflection rules to the defaults.
|
|
183
196
|
*
|
|
197
|
+
* @summary Discards all custom inflection rules and caches, then restores the built-in default rules.
|
|
184
198
|
* @public
|
|
185
199
|
* @since 4.13.0
|
|
186
200
|
*/
|
|
@@ -195,6 +209,7 @@ function resetToDefaults() {
|
|
|
195
209
|
* Clears all inflection rules
|
|
196
210
|
* and resets the caches for singularize and pluralize.
|
|
197
211
|
*
|
|
212
|
+
* @summary Removes every inflection rule, including the defaults, and empties the `singularize` and `pluralize` caches.
|
|
198
213
|
* @public
|
|
199
214
|
* @since 4.13.0
|
|
200
215
|
*/
|
|
@@ -210,6 +225,7 @@ function clearRules() {
|
|
|
210
225
|
/**
|
|
211
226
|
* Singularizes a word.
|
|
212
227
|
*
|
|
228
|
+
* @summary Returns the singular form of an English word using the registered inflection rules, with cached results.
|
|
213
229
|
* @public
|
|
214
230
|
* @since 4.13.0
|
|
215
231
|
*/
|
|
@@ -223,6 +239,7 @@ function singularize(word) {
|
|
|
223
239
|
/**
|
|
224
240
|
* Pluralizes a word.
|
|
225
241
|
*
|
|
242
|
+
* @summary Returns the plural form of an English word using the registered inflection rules, with cached results.
|
|
226
243
|
* @public
|
|
227
244
|
* @since 4.13.0
|
|
228
245
|
*/
|
|
@@ -243,6 +260,7 @@ function unshiftMap(v, map) {
|
|
|
243
260
|
/**
|
|
244
261
|
* Adds a pluralization rule.
|
|
245
262
|
*
|
|
263
|
+
* @summary Adds a regex and replacement rule that `pluralize` checks before all existing plural rules.
|
|
246
264
|
* @public
|
|
247
265
|
* @since 4.13.0
|
|
248
266
|
*/
|
|
@@ -253,6 +271,7 @@ function plural(regex, string) {
|
|
|
253
271
|
/**
|
|
254
272
|
* Adds a singularization rule.
|
|
255
273
|
*
|
|
274
|
+
* @summary Adds a regex and replacement rule that `singularize` checks before all existing singular rules.
|
|
256
275
|
* @public
|
|
257
276
|
* @since 4.13.0
|
|
258
277
|
*/
|
|
@@ -287,4 +306,4 @@ function inflect(word, typeRules, irregulars) {
|
|
|
287
306
|
|
|
288
307
|
//#endregion
|
|
289
308
|
export { loadUncountable as a, resetToDefaults as c, uncountable as d, camelize as f, underscore as g, setMaxLRUCacheSize as h, loadIrregular as i, singular as l, dasherize$1 as m, clearRules as n, plural as o, capitalize as p, irregular as r, pluralize as s, clear as t, singularize as u };
|
|
290
|
-
//# sourceMappingURL=string-
|
|
309
|
+
//# sourceMappingURL=string-BZACNuLp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-BZACNuLp.js","names":["dasherize","internalDasherize","LRUCache","defaultRules","capitalize","macroCondition","getGlobalConfig","BLANK_REGEX","LAST_WORD_DASHED_REGEX","LAST_WORD_CAMELIZED_REGEX","CAMELIZED_REGEX","SINGULARS","word","_singularize","PLURALS","_pluralize","UNCOUNTABLE","Set","uncountable","IRREGULAR","Map","INVERSE_IRREGULAR","SINGULAR_RULES","singular","reverse","PLURAL_RULES","plurals","add","toLowerCase","loadUncountable","uncountables","forEach","irregular","single","plur","set","loadIrregular","irregularPairs","pair","clear","resetToDefaults","clearRules","v","singularize","WarpDrive","env","DEBUG","test","Error","length","get","pluralize","unshiftMap","map","rules","entries","rule","plural","regex","string","has","delete","inflect","typeRules","irregulars","isBlank","lowercase","wordSplit","exec","lastWord","isCamelized","substitution","match","replace","RegExp"],"sources":["../src/-private/string/transform.ts","../src/-private/string/inflect.ts"],"sourcesContent":["import { dasherize as internalDasherize, LRUCache, STRING_DASHERIZE_CACHE } from '@warp-drive/core/utils/string';\n\n// oxlint-disable-next-line no-useless-escape\nconst STRING_CAMELIZE_REGEXP_1 = /(\\-|\\_|\\.|\\s)+(.)?/g;\nconst STRING_CAMELIZE_REGEXP_2 = /(^|\\/)([A-Z])/g;\nconst CAMELIZE_CACHE = new LRUCache<string, string>((key: string) =>\n key\n .replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr: string | null) => (chr ? chr.toUpperCase() : ''))\n .replace(STRING_CAMELIZE_REGEXP_2, (match /*, separator, chr */) => match.toLowerCase())\n);\n\nconst STRING_UNDERSCORE_REGEXP_1 = /([a-z\\d])([A-Z]+)/g;\n// oxlint-disable-next-line no-useless-escape\nconst STRING_UNDERSCORE_REGEXP_2 = /\\-|\\s+/g;\nconst UNDERSCORE_CACHE = new LRUCache<string, string>((str: string) =>\n str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase()\n);\n\nconst STRING_CAPITALIZE_REGEXP = /(^|\\/)([a-z\\u00C0-\\u024F])/g;\nconst CAPITALIZE_CACHE = new LRUCache<string, string>((str: string) =>\n str.replace(STRING_CAPITALIZE_REGEXP, (match /*, separator, chr */) => match.toUpperCase())\n);\n\n/**\n * Replaces underscores, spaces, or camelCase with dashes.\n *\n * ```js\n * import { dasherize } from '@warp-drive/utilities/string';\n *\n * dasherize('innerHTML'); // 'inner-html'\n * dasherize('action_name'); // 'action-name'\n * dasherize('css-class-name'); // 'css-class-name'\n * dasherize('my favorite items'); // 'my-favorite-items'\n * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'\n * ```\n *\n * @summary Converts camelCase, underscored, or spaced strings to dasherized form, such as `innerHTML` to `inner-html`.\n * @public\n * @since 4.13.0\n */\nexport const dasherize: (str: string) => string = internalDasherize;\n\n/**\n * Returns the lowerCamelCase form of a string.\n *\n * ```js\n * import { camelize } from '@warp-drive/utilities/string';\n *\n * camelize('innerHTML'); // 'innerHTML'\n * camelize('action_name'); // 'actionName'\n * camelize('css-class-name'); // 'cssClassName'\n * camelize('my favorite items'); // 'myFavoriteItems'\n * camelize('My Favorite Items'); // 'myFavoriteItems'\n * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'\n * ```\n *\n * @summary Converts dashed, underscored, dotted, or spaced strings to lowerCamelCase, such as `action_name` to\n * `actionName`.\n * @public\n * @since 4.13.0\n */\nexport function camelize(str: string): string {\n return CAMELIZE_CACHE.get(str);\n}\n\n/**\n * Returns the lower\\_case\\_and\\_underscored form of a string.\n *\n * ```js\n * import { underscore } from '@warp-drive/utilities/string';\n *\n * underscore('innerHTML'); // 'inner_html'\n * underscore('action_name'); // 'action_name'\n * underscore('css-class-name'); // 'css_class_name'\n * underscore('my favorite items'); // 'my_favorite_items'\n * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'\n * ```\n *\n * @summary Converts camelCase, dashed, or spaced strings to lowercase snake_case, such as `innerHTML` to `inner_html`.\n * @public\n * @since 4.13.0\n */\nexport function underscore(str: string): string {\n return UNDERSCORE_CACHE.get(str);\n}\n\n/**\n * Returns the Capitalized form of a string\n *\n * ```js\n * import { capitalize } from '@warp-drive/utilities/string';\n *\n * capitalize('innerHTML') // 'InnerHTML'\n * capitalize('action_name') // 'Action_name'\n * capitalize('css-class-name') // 'Css-class-name'\n * capitalize('my favorite items') // 'My favorite items'\n * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'\n * ```\n *\n * @summary Uppercases the first letter of a string, and of each `/`-separated path segment, leaving the rest unchanged.\n * @public\n * @since 4.13.0\n */\nexport function capitalize(str: string): string {\n return CAPITALIZE_CACHE.get(str);\n}\n\n/**\n * Sets the maximum size of the LRUCache for all string transformation functions.\n * The default size is 10,000.\n *\n * @summary Sets how many results the `camelize`, `underscore`, `capitalize`, and `dasherize` caches each keep (default\n * 10,000).\n * @public\n * @since 4.13.0\n */\nexport function setMaxLRUCacheSize(size: number): void {\n CAMELIZE_CACHE.size = size;\n UNDERSCORE_CACHE.size = size;\n CAPITALIZE_CACHE.size = size;\n STRING_DASHERIZE_CACHE.size = size;\n}\n","import { assert } from '@warp-drive/core/build-config/macros';\nimport { LRUCache } from '@warp-drive/core/utils/string';\n\nimport { defaultRules } from './inflections.ts';\nimport { capitalize } from './transform.ts';\n\nconst BLANK_REGEX = /^\\s*$/;\nconst LAST_WORD_DASHED_REGEX = /([\\w/-]+[_/\\s-])([a-z\\d]+$)/;\nconst LAST_WORD_CAMELIZED_REGEX = /([\\w/\\s-]+)([A-Z][a-z\\d]*$)/;\nconst CAMELIZED_REGEX = /[A-Z][a-z\\d]*$/;\n\nconst SINGULARS = new LRUCache<string, string>((word: string) => {\n return _singularize(word);\n});\nconst PLURALS = new LRUCache<string, string>((word: string) => {\n return _pluralize(word);\n});\nconst UNCOUNTABLE = new Set(defaultRules.uncountable);\nconst IRREGULAR: Map<string, string> = new Map();\nconst INVERSE_IRREGULAR: Map<string, string> = new Map();\nconst SINGULAR_RULES = new Map(defaultRules.singular.reverse());\nconst PLURAL_RULES = new Map(defaultRules.plurals.reverse());\n\n/**\n * Marks a word as uncountable. Uncountable words are not pluralized\n * or singularized.\n *\n * @summary Registers a word that `pluralize` and `singularize` should always return unchanged.\n * @public\n * @since 4.13.0\n */\nexport function uncountable(word: string): void {\n UNCOUNTABLE.add(word.toLowerCase());\n}\n\n/**\n * Marks a list of words as uncountable. Uncountable words are not pluralized\n * or singularized.\n *\n * @summary Registers a list of words that `pluralize` and `singularize` should always return unchanged.\n * @public\n * @since 4.13.0\n */\nexport function loadUncountable(uncountables: string[]): void {\n uncountables.forEach((word) => {\n uncountable(word);\n });\n}\n\n/**\n * Marks a word as irregular. Irregular words have unique\n * pluralization and singularization rules.\n *\n * @summary Registers a singular and plural word pair that `pluralize` and `singularize` map directly instead of\n * applying rules.\n * @public\n * @since 4.13.0\n */\nexport function irregular(single: string, plur: string): void {\n //pluralizing\n IRREGULAR.set(single.toLowerCase(), plur);\n IRREGULAR.set(plur.toLowerCase(), plur);\n\n //singularizing\n INVERSE_IRREGULAR.set(plur.toLowerCase(), single);\n INVERSE_IRREGULAR.set(single.toLowerCase(), single);\n}\n\n/**\n * Marks a list of word pairs as irregular. Irregular words have unique\n * pluralization and singularization rules.\n *\n * @summary Registers a list of singular and plural word pairs that `pluralize` and `singularize` map directly.\n * @public\n * @since 4.13.0\n */\nexport function loadIrregular(irregularPairs: Array<[string, string]>): void {\n irregularPairs.forEach((pair) => {\n //pluralizing\n IRREGULAR.set(pair[0].toLowerCase(), pair[1]);\n IRREGULAR.set(pair[1].toLowerCase(), pair[1]);\n\n //singularizing\n INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);\n INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);\n });\n}\nloadIrregular(defaultRules.irregularPairs);\n\n/**\n * Clears the caches for singularize and pluralize.\n *\n * @summary Empties the cached results of `singularize` and `pluralize` while keeping all inflection rules.\n * @public\n * @since 4.13.0\n */\nexport function clear(): void {\n SINGULARS.clear();\n PLURALS.clear();\n}\n\n/**\n * Resets the inflection rules to the defaults.\n *\n * @summary Discards all custom inflection rules and caches, then restores the built-in default rules.\n * @public\n * @since 4.13.0\n */\nexport function resetToDefaults(): void {\n clearRules();\n defaultRules.uncountable.forEach((v) => UNCOUNTABLE.add(v));\n defaultRules.singular.forEach((v) => SINGULAR_RULES.set(v[0], v[1]));\n defaultRules.plurals.forEach((v) => PLURAL_RULES.set(v[0], v[1]));\n loadIrregular(defaultRules.irregularPairs);\n}\n\n/**\n * Clears all inflection rules\n * and resets the caches for singularize and pluralize.\n *\n * @summary Removes every inflection rule, including the defaults, and empties the `singularize` and `pluralize` caches.\n * @public\n * @since 4.13.0\n */\nexport function clearRules(): void {\n SINGULARS.clear();\n PLURALS.clear();\n UNCOUNTABLE.clear();\n IRREGULAR.clear();\n INVERSE_IRREGULAR.clear();\n SINGULAR_RULES.clear();\n PLURAL_RULES.clear();\n}\n\n/**\n * Singularizes a word.\n *\n * @summary Returns the singular form of an English word using the registered inflection rules, with cached results.\n * @public\n * @since 4.13.0\n */\nexport function singularize(word: string): string {\n assert(`singularize expects to receive a non-empty string`, typeof word === 'string' && word.length > 0);\n if (!word) return '';\n return SINGULARS.get(word);\n}\n\n/**\n * Pluralizes a word.\n *\n * @summary Returns the plural form of an English word using the registered inflection rules, with cached results.\n * @public\n * @since 4.13.0\n */\nexport function pluralize(word: string): string {\n assert(`pluralize expects to receive a non-empty string`, typeof word === 'string' && word.length > 0);\n if (!word) return '';\n return PLURALS.get(word);\n}\n\nfunction unshiftMap<K, V>(v: [K, V], map: Map<K, V>) {\n // reorder\n const rules = [v, ...map.entries()];\n map.clear();\n rules.forEach((rule) => {\n map.set(rule[0], rule[1]);\n });\n}\n\n/**\n * Adds a pluralization rule.\n *\n * @summary Adds a regex and replacement rule that `pluralize` checks before all existing plural rules.\n * @public\n * @since 4.13.0\n */\nexport function plural(regex: RegExp, string: string): void {\n // rule requires reordering if exists, so remove it first\n if (PLURAL_RULES.has(regex)) {\n PLURAL_RULES.delete(regex);\n }\n\n // reorder\n unshiftMap([regex, string], PLURAL_RULES);\n}\n\n/**\n * Adds a singularization rule.\n *\n * @summary Adds a regex and replacement rule that `singularize` checks before all existing singular rules.\n * @public\n * @since 4.13.0\n */\nexport function singular(regex: RegExp, string: string): void {\n // rule requires reordering if exists, so remove it first\n if (SINGULAR_RULES.has(regex)) {\n SINGULAR_RULES.delete(regex);\n }\n\n // reorder\n unshiftMap([regex, string], SINGULAR_RULES);\n}\n\nfunction _pluralize(word: string) {\n return inflect(word, PLURAL_RULES, IRREGULAR);\n}\n\nfunction _singularize(word: string) {\n return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);\n}\n\nfunction inflect(word: string, typeRules: Map<RegExp, string>, irregulars: Map<string, string>) {\n // empty strings\n const isBlank = !word || BLANK_REGEX.test(word);\n if (isBlank) {\n return word;\n }\n\n // basic uncountables\n const lowercase = word.toLowerCase();\n if (UNCOUNTABLE.has(lowercase)) {\n return word;\n }\n\n // adv uncountables\n const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);\n const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;\n if (lastWord && UNCOUNTABLE.has(lastWord)) {\n return word;\n }\n\n // handle irregulars\n const isCamelized = CAMELIZED_REGEX.test(word);\n for (let [rule, substitution] of irregulars) {\n if (lowercase.match(rule + '$')) {\n if (isCamelized && lastWord && irregulars.has(lastWord)) {\n substitution = capitalize(substitution);\n rule = capitalize(rule);\n }\n\n return word.replace(new RegExp(rule, 'i'), substitution);\n }\n }\n\n // do the actual inflection\n for (const [rule, substitution] of typeRules) {\n if (rule.test(word)) {\n return word.replace(rule, substitution);\n }\n }\n\n return word;\n}\n"],"mappings":";;;;;AAGA,MAAM,2BAA2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nC,IAAI,GAChB,OAAOA,KAAK6D,QAAQjB,MAAMe,YAAY;CAI1C,OAAO3D;AACT"}
|
package/dist/string.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Marks a word as uncountable. Uncountable words are not pluralized
|
|
4
4
|
* or singularized.
|
|
5
5
|
*
|
|
6
|
+
* @summary Registers a word that `pluralize` and `singularize` should always return unchanged.
|
|
6
7
|
* @public
|
|
7
8
|
* @since 4.13.0
|
|
8
9
|
*/
|
|
@@ -11,6 +12,7 @@ export declare function uncountable(word: string): void;
|
|
|
11
12
|
* Marks a list of words as uncountable. Uncountable words are not pluralized
|
|
12
13
|
* or singularized.
|
|
13
14
|
*
|
|
15
|
+
* @summary Registers a list of words that `pluralize` and `singularize` should always return unchanged.
|
|
14
16
|
* @public
|
|
15
17
|
* @since 4.13.0
|
|
16
18
|
*/
|
|
@@ -19,6 +21,8 @@ export declare function loadUncountable(uncountables: string[]): void;
|
|
|
19
21
|
* Marks a word as irregular. Irregular words have unique
|
|
20
22
|
* pluralization and singularization rules.
|
|
21
23
|
*
|
|
24
|
+
* @summary Registers a singular and plural word pair that `pluralize` and `singularize` map directly instead of
|
|
25
|
+
* applying rules.
|
|
22
26
|
* @public
|
|
23
27
|
* @since 4.13.0
|
|
24
28
|
*/
|
|
@@ -27,6 +31,7 @@ export declare function irregular(single: string, plur: string): void;
|
|
|
27
31
|
* Marks a list of word pairs as irregular. Irregular words have unique
|
|
28
32
|
* pluralization and singularization rules.
|
|
29
33
|
*
|
|
34
|
+
* @summary Registers a list of singular and plural word pairs that `pluralize` and `singularize` map directly.
|
|
30
35
|
* @public
|
|
31
36
|
* @since 4.13.0
|
|
32
37
|
*/
|
|
@@ -34,6 +39,7 @@ export declare function loadIrregular(irregularPairs: Array<[string, string]>):
|
|
|
34
39
|
/**
|
|
35
40
|
* Clears the caches for singularize and pluralize.
|
|
36
41
|
*
|
|
42
|
+
* @summary Empties the cached results of `singularize` and `pluralize` while keeping all inflection rules.
|
|
37
43
|
* @public
|
|
38
44
|
* @since 4.13.0
|
|
39
45
|
*/
|
|
@@ -41,6 +47,7 @@ export declare function clear(): void;
|
|
|
41
47
|
/**
|
|
42
48
|
* Resets the inflection rules to the defaults.
|
|
43
49
|
*
|
|
50
|
+
* @summary Discards all custom inflection rules and caches, then restores the built-in default rules.
|
|
44
51
|
* @public
|
|
45
52
|
* @since 4.13.0
|
|
46
53
|
*/
|
|
@@ -49,6 +56,7 @@ export declare function resetToDefaults(): void;
|
|
|
49
56
|
* Clears all inflection rules
|
|
50
57
|
* and resets the caches for singularize and pluralize.
|
|
51
58
|
*
|
|
59
|
+
* @summary Removes every inflection rule, including the defaults, and empties the `singularize` and `pluralize` caches.
|
|
52
60
|
* @public
|
|
53
61
|
* @since 4.13.0
|
|
54
62
|
*/
|
|
@@ -56,6 +64,7 @@ export declare function clearRules(): void;
|
|
|
56
64
|
/**
|
|
57
65
|
* Singularizes a word.
|
|
58
66
|
*
|
|
67
|
+
* @summary Returns the singular form of an English word using the registered inflection rules, with cached results.
|
|
59
68
|
* @public
|
|
60
69
|
* @since 4.13.0
|
|
61
70
|
*/
|
|
@@ -63,6 +72,7 @@ export declare function singularize(word: string): string;
|
|
|
63
72
|
/**
|
|
64
73
|
* Pluralizes a word.
|
|
65
74
|
*
|
|
75
|
+
* @summary Returns the plural form of an English word using the registered inflection rules, with cached results.
|
|
66
76
|
* @public
|
|
67
77
|
* @since 4.13.0
|
|
68
78
|
*/
|
|
@@ -70,6 +80,7 @@ export declare function pluralize(word: string): string;
|
|
|
70
80
|
/**
|
|
71
81
|
* Adds a pluralization rule.
|
|
72
82
|
*
|
|
83
|
+
* @summary Adds a regex and replacement rule that `pluralize` checks before all existing plural rules.
|
|
73
84
|
* @public
|
|
74
85
|
* @since 4.13.0
|
|
75
86
|
*/
|
|
@@ -77,6 +88,7 @@ export declare function plural(regex: RegExp, string: string): void;
|
|
|
77
88
|
/**
|
|
78
89
|
* Adds a singularization rule.
|
|
79
90
|
*
|
|
91
|
+
* @summary Adds a regex and replacement rule that `singularize` checks before all existing singular rules.
|
|
80
92
|
* @public
|
|
81
93
|
* @since 4.13.0
|
|
82
94
|
*/
|
|
@@ -96,6 +108,7 @@ export declare function singular(regex: RegExp, string: string): void;
|
|
|
96
108
|
* dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
|
|
97
109
|
* ```
|
|
98
110
|
*
|
|
111
|
+
* @summary Converts camelCase, underscored, or spaced strings to dasherized form, such as `innerHTML` to `inner-html`.
|
|
99
112
|
* @public
|
|
100
113
|
* @since 4.13.0
|
|
101
114
|
*/
|
|
@@ -114,6 +127,8 @@ export declare const dasherize: (str: string) => string;
|
|
|
114
127
|
* camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
|
|
115
128
|
* ```
|
|
116
129
|
*
|
|
130
|
+
* @summary Converts dashed, underscored, dotted, or spaced strings to lowerCamelCase, such as `action_name` to
|
|
131
|
+
* `actionName`.
|
|
117
132
|
* @public
|
|
118
133
|
* @since 4.13.0
|
|
119
134
|
*/
|
|
@@ -131,6 +146,7 @@ export declare function camelize(str: string): string;
|
|
|
131
146
|
* underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
|
|
132
147
|
* ```
|
|
133
148
|
*
|
|
149
|
+
* @summary Converts camelCase, dashed, or spaced strings to lowercase snake_case, such as `innerHTML` to `inner_html`.
|
|
134
150
|
* @public
|
|
135
151
|
* @since 4.13.0
|
|
136
152
|
*/
|
|
@@ -148,6 +164,7 @@ export declare function underscore(str: string): string;
|
|
|
148
164
|
* capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
|
|
149
165
|
* ```
|
|
150
166
|
*
|
|
167
|
+
* @summary Uppercases the first letter of a string, and of each `/`-separated path segment, leaving the rest unchanged.
|
|
151
168
|
* @public
|
|
152
169
|
* @since 4.13.0
|
|
153
170
|
*/
|
|
@@ -156,6 +173,8 @@ export declare function capitalize(str: string): string;
|
|
|
156
173
|
* Sets the maximum size of the LRUCache for all string transformation functions.
|
|
157
174
|
* The default size is 10,000.
|
|
158
175
|
*
|
|
176
|
+
* @summary Sets how many results the `camelize`, `underscore`, `capitalize`, and `dasherize` caches each keep (default
|
|
177
|
+
* 10,000).
|
|
159
178
|
* @public
|
|
160
179
|
* @since 4.13.0
|
|
161
180
|
*/
|
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-BZACNuLp.js";
|
|
2
2
|
|
|
3
3
|
export { camelize, capitalize, clear, clearRules, dasherize, irregular, loadIrregular, loadUncountable, plural, pluralize, resetToDefaults, setMaxLRUCacheSize, singular, singularize, uncountable, underscore };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildBaseURL, buildQueryParams } from "./index.js";
|
|
2
|
-
import { g as underscore, s as pluralize } from "./string-
|
|
2
|
+
import { g as underscore, s as pluralize } from "./string-I8KHJXV7.js";
|
|
3
3
|
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-BkXwUT0x.js";
|
|
4
4
|
import { recordIdentifierFor } from "@warp-drive/core";
|
|
5
5
|
|
|
@@ -62,6 +62,9 @@ function isExisting(identifier) {
|
|
|
62
62
|
* Builds request options to delete record for resources,
|
|
63
63
|
* configured for the url, method and header expectations of ActiveRecord APIs.
|
|
64
64
|
*
|
|
65
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
66
|
+
* when to use one.
|
|
67
|
+
*
|
|
65
68
|
* **Basic Usage**
|
|
66
69
|
*
|
|
67
70
|
* ```ts
|
|
@@ -103,6 +106,7 @@ function isExisting(identifier) {
|
|
|
103
106
|
* const data = await store.request(options);
|
|
104
107
|
* ```
|
|
105
108
|
*
|
|
109
|
+
* @summary Builds a `DELETE` request that persists deletion of an existing record, using ActiveRecord-style URLs.
|
|
106
110
|
* @public
|
|
107
111
|
* @param record
|
|
108
112
|
* @param options
|
|
@@ -137,6 +141,9 @@ function deleteRecord(record, options = {}) {
|
|
|
137
141
|
* Builds request options to create new record for resources,
|
|
138
142
|
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
139
143
|
*
|
|
144
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
145
|
+
* when to use one.
|
|
146
|
+
*
|
|
140
147
|
* **Basic Usage**
|
|
141
148
|
*
|
|
142
149
|
* ```ts
|
|
@@ -168,6 +175,7 @@ function deleteRecord(record, options = {}) {
|
|
|
168
175
|
* const data = await store.request(options);
|
|
169
176
|
* ```
|
|
170
177
|
*
|
|
178
|
+
* @summary Builds a `POST` request that saves a newly created record, using ActiveRecord-style URLs.
|
|
171
179
|
* @public
|
|
172
180
|
* @param record
|
|
173
181
|
* @param options
|
|
@@ -199,6 +207,9 @@ function createRecord(record, options = {}) {
|
|
|
199
207
|
* Builds request options to update existing record for resources,
|
|
200
208
|
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
201
209
|
*
|
|
210
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
211
|
+
* when to use one.
|
|
212
|
+
*
|
|
202
213
|
* **Basic Usage**
|
|
203
214
|
*
|
|
204
215
|
* ```ts
|
|
@@ -233,6 +244,7 @@ function createRecord(record, options = {}) {
|
|
|
233
244
|
* const data = await store.request(options);
|
|
234
245
|
* ```
|
|
235
246
|
*
|
|
247
|
+
* @summary Builds a `PUT` (or `PATCH`) request that saves changes to an existing record, using ActiveRecord-style URLs.
|
|
236
248
|
* @public
|
|
237
249
|
* @param record
|
|
238
250
|
* @param options
|
|
@@ -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/core/reactive';\nimport 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 { Meta } from '@warp-drive/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/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/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/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/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/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';\nimport type { Meta } from '@warp-drive/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/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/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/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/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } 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 { Meta } from '@warp-drive/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/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/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/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/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/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/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,\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H;EACAH,IAAI;EACJO,MAAM,EACJZ,QAAQJ,WACV;EACAiB,SAAS,CAACjB,UAAU;CACtB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgBmB,aACdf,QACAC,UAA2D,CAAC,GACtC;CACtB,MAAML,aAAaN,oBAAoBU,MAAM;CAC7C,EAAAE,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MAAO,wCAAwC;CAAA,EAAA,CAAEP,UAAU;CAC3D,EAAAM,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MAAO,sEAAsE;CAAA,EAAA,CAAER,WAAWC,UAAU,CAAC;CAErG,MAAMQ,aAAqC;EAC7BR;EACZS,IAAI;EACJC,cAAcd,UAAUC,WAAWG,WAAWE,IAAI,CAAC;CACrD;CAEAJ,sBAAsBU,YAAYH,OAAO;CAEzC,MAAMM,MAAMhB,aAAaa,UAAU;CACnC,MAAMI,UAAU,IAAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQV,QAAQe,QAAQ,UAAU;EAClCR;EACAH,IAAI;EACJO,MAAM,EACJZ,QAAQJ,WACV;EACAiB,SAAS,CAACjB,UAAU;CACtB;AACF"}
|
|
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/core/reactive';\nimport 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 { Meta } from '@warp-drive/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/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/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/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/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/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';\nimport type { Meta } from '@warp-drive/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/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/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/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/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } 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 { Meta } from '@warp-drive/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/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/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/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/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/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/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":";;;;;;AAuFA,SAAgB,WACd,MACA,MACA,MAC0B;CAC1B,MAAM,aAA2C,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CACjH,MAAM,WAAY,OAAO,SAAS,WAAW,OAAO,SAAS,CAAC;CAC9D,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,WAAW,WAAW,IAAI,CAAC;CACrD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,QAAQ,QAAQ,GAAG,QAAQ,iBAAiB,MAClF;EACJ,QAAQ;EACR;EACA;EAC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AAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQV,QAAQe,QAAQ,UAAU;EAClCR;EACAH,IAAI;EACJO,MAAM,EACJZ,QAAQJ,WACV;EACAiB,SAAS,CAACjB,UAAU;CACtB;AACF"}
|
|
@@ -2,11 +2,17 @@ import { Type } from "@warp-drive/core/types/symbols";
|
|
|
2
2
|
|
|
3
3
|
//#region src/derivations.ts
|
|
4
4
|
/**
|
|
5
|
+
* @module
|
|
6
|
+
* @summary The `concat` derivation, which joins a record's listed fields into one string with an optional separator.
|
|
7
|
+
*/
|
|
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',
|
|
@@ -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/core/reactive';\nimport { Type } from '@warp-drive/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"}
|
|
@@ -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 = (() => {
|
|
@@ -56,6 +58,8 @@ const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
|
56
58
|
* }
|
|
57
59
|
* ```
|
|
58
60
|
*
|
|
61
|
+
* @summary Request handler that compresses large `POST`, `PUT`, `PATCH`, and `DELETE` bodies with `CompressionStream`,
|
|
62
|
+
* optionally streaming them.
|
|
59
63
|
* @group Handlers
|
|
60
64
|
* @public
|
|
61
65
|
* @since 5.5.0
|
|
@@ -125,6 +129,8 @@ function encodingForFormat(format) {
|
|
|
125
129
|
*/
|
|
126
130
|
/**
|
|
127
131
|
*
|
|
132
|
+
* @summary Request handler that wraps another handler and runs it only when a check function returns true for the
|
|
133
|
+
* request.
|
|
128
134
|
* @group Handlers
|
|
129
135
|
* @public
|
|
130
136
|
*/
|
|
@@ -190,6 +196,7 @@ var Gate = class {
|
|
|
190
196
|
* Errors are not processed by this handler, so if the request fails and the error response
|
|
191
197
|
* is not in {json:api} format additional processing may be needed.
|
|
192
198
|
*
|
|
199
|
+
* @summary Request handler that wraps the whole response body in `meta` for requests with `options.isMetaRequest` set.
|
|
193
200
|
* @group Handlers
|
|
194
201
|
*/
|
|
195
202
|
const MetaDocHandler = { request(context, next) {
|
|
@@ -222,12 +229,15 @@ function getTabId() {
|
|
|
222
229
|
* useful for observability/tracing and deduping
|
|
223
230
|
* across multiple tabs.
|
|
224
231
|
*
|
|
232
|
+
* @summary Random UUID identifying the current browser tab, kept in `sessionStorage` across reloads, for request
|
|
233
|
+
* tracing.
|
|
225
234
|
* @group Constants
|
|
226
235
|
*/
|
|
227
236
|
const TAB_ID = getTabId();
|
|
228
237
|
/**
|
|
229
238
|
* The epoch seconds at which the tab id was generated
|
|
230
239
|
*
|
|
240
|
+
* @summary Epoch seconds recorded when this module loaded, paired with `TAB_ID` in trace headers.
|
|
231
241
|
* @group Constants
|
|
232
242
|
*/
|
|
233
243
|
const TAB_ASSIGNED = Math.floor(Date.now() / 1e3);
|
|
@@ -240,6 +250,8 @@ const TAB_ASSIGNED = Math.floor(Date.now() / 1e3);
|
|
|
240
250
|
*
|
|
241
251
|
* Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
|
|
242
252
|
*
|
|
253
|
+
* @summary Sets an `X-Amzn-Trace-Id` header carrying a per-request id and the tab id, so requests can be traced to
|
|
254
|
+
* their browser tab.
|
|
243
255
|
* @group Utility Functions
|
|
244
256
|
*/
|
|
245
257
|
function addTraceHeader(headers) {
|
|
@@ -251,6 +263,7 @@ function addTraceHeader(headers) {
|
|
|
251
263
|
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
252
264
|
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
253
265
|
*
|
|
266
|
+
* @summary The 8192-byte URL length limit, taken from AWS CloudFront, that `assertInvalidUrlLength` checks against.
|
|
254
267
|
* @group Constants
|
|
255
268
|
*/
|
|
256
269
|
const MAX_URL_LENGTH = 8192;
|
|
@@ -259,6 +272,8 @@ const MAX_URL_LENGTH = 8192;
|
|
|
259
272
|
*
|
|
260
273
|
* See also {@link MAX_URL_LENGTH}
|
|
261
274
|
*
|
|
275
|
+
* @summary Dev-mode assertion that throws when a URL is longer than `MAX_URL_LENGTH`, suggesting a `POST` or `QUERY`
|
|
276
|
+
* request instead.
|
|
262
277
|
* @group Utility Functions
|
|
263
278
|
*/
|
|
264
279
|
function assertInvalidUrlLength(url) {
|