@warp-drive/utilities 5.9.0-alpha.2 → 5.9.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/cjs-dist/string.cjs +448 -0
- package/cjs-dist/string.cjs.map +1 -0
- package/declarations/-private.d.ts +12 -1
- package/declarations/-private.d.ts.map +1 -0
- package/declarations/active-record.d.ts +260 -3
- package/declarations/active-record.d.ts.map +1 -0
- package/declarations/derivations.d.ts +26 -23
- package/declarations/derivations.d.ts.map +1 -0
- package/declarations/handlers.d.ts +282 -9
- package/declarations/handlers.d.ts.map +1 -0
- package/declarations/index-BeMAuqgZ.d.ts +462 -0
- package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
- package/declarations/index.d.ts +2 -208
- package/declarations/json-api.d.ts +496 -5
- package/declarations/json-api.d.ts.map +1 -0
- package/declarations/rest.d.ts +258 -3
- package/declarations/rest.d.ts.map +1 -0
- package/declarations/string.d.ts +164 -13
- package/declarations/string.d.ts.map +1 -0
- package/dist/-private.js +2 -6
- package/dist/active-record.js +254 -379
- package/dist/active-record.js.map +1 -0
- package/dist/builder-utils-BkXwUT0x.js +16 -0
- package/dist/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/derivations.js +26 -26
- package/dist/derivations.js.map +1 -0
- package/dist/handlers.js +240 -283
- package/dist/handlers.js.map +1 -0
- package/dist/index.js +357 -335
- package/dist/index.js.map +1 -0
- package/dist/inflections-DzBsjJqj.js +80 -0
- package/dist/inflections-DzBsjJqj.js.map +1 -0
- package/dist/json-api.js +470 -706
- package/dist/json-api.js.map +1 -0
- package/dist/rest.js +254 -377
- package/dist/rest.js.map +1 -0
- package/dist/string-CWmAluxh.js +290 -0
- package/dist/string-CWmAluxh.js.map +1 -0
- package/dist/string.js +2 -427
- package/dist/unpkg/dev/-private.js +2 -6
- package/dist/unpkg/dev/active-record.js +253 -378
- package/dist/unpkg/dev/active-record.js.map +1 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev/derivations.js +26 -26
- package/dist/unpkg/dev/derivations.js.map +1 -0
- package/dist/unpkg/dev/handlers.js +238 -282
- package/dist/unpkg/dev/handlers.js.map +1 -0
- package/dist/unpkg/dev/index.js +356 -336
- package/dist/unpkg/dev/index.js.map +1 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev/json-api.js +469 -706
- package/dist/unpkg/dev/json-api.js.map +1 -0
- package/dist/unpkg/dev/rest.js +253 -376
- package/dist/unpkg/dev/rest.js.map +1 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev/string.js +3 -1
- package/dist/unpkg/dev-deprecated/-private.js +2 -6
- package/dist/unpkg/dev-deprecated/active-record.js +253 -378
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev-deprecated/derivations.js +26 -26
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/dev-deprecated/handlers.js +238 -282
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +356 -336
- package/dist/unpkg/dev-deprecated/index.js.map +1 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev-deprecated/json-api.js +469 -706
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/dev-deprecated/rest.js +253 -376
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +3 -1
- package/dist/unpkg/prod/-private.js +2 -6
- package/dist/unpkg/prod/active-record.js +236 -351
- package/dist/unpkg/prod/active-record.js.map +1 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod/derivations.js +26 -26
- package/dist/unpkg/prod/derivations.js.map +1 -0
- package/dist/unpkg/prod/handlers.js +231 -272
- package/dist/unpkg/prod/handlers.js.map +1 -0
- package/dist/unpkg/prod/index.js +265 -215
- package/dist/unpkg/prod/index.js.map +1 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod/json-api.js +446 -669
- package/dist/unpkg/prod/json-api.js.map +1 -0
- package/dist/unpkg/prod/rest.js +236 -349
- package/dist/unpkg/prod/rest.js.map +1 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod/string.js +3 -1
- package/dist/unpkg/prod-deprecated/-private.js +2 -6
- package/dist/unpkg/prod-deprecated/active-record.js +236 -351
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod-deprecated/derivations.js +26 -26
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/prod-deprecated/handlers.js +231 -272
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +265 -215
- package/dist/unpkg/prod-deprecated/index.js.map +1 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/json-api.js +446 -669
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/prod-deprecated/rest.js +236 -349
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +3 -1
- package/package.json +11 -10
- package/declarations/-private/active-record/find-record.d.ts +0 -64
- package/declarations/-private/active-record/query.d.ts +0 -53
- package/declarations/-private/active-record/save-record.d.ts +0 -146
- package/declarations/-private/builder-utils.d.ts +0 -4
- package/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/declarations/-private/handlers/gated.d.ts +0 -19
- package/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/declarations/-private/handlers/utils.d.ts +0 -41
- package/declarations/-private/json-api/-utils.d.ts +0 -109
- package/declarations/-private/json-api/find-record.d.ts +0 -84
- package/declarations/-private/json-api/query.d.ts +0 -100
- package/declarations/-private/json-api/save-record.d.ts +0 -228
- package/declarations/-private/json-api/serialize.d.ts +0 -70
- package/declarations/-private/rest/find-record.d.ts +0 -62
- package/declarations/-private/rest/query.d.ts +0 -53
- package/declarations/-private/rest/save-record.d.ts +0 -146
- package/declarations/-private/string/inflect.d.ts +0 -82
- package/declarations/-private/string/inflections.d.ts +0 -9
- package/declarations/-private/string/transform.d.ts +0 -77
- package/dist/builder-utils-Donkk-BZ.js +0 -22
- package/dist/inflect-BSG696t-.js +0 -344
- package/dist/string.cjs +0 -430
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { t as defaultRules } from "./inflections-DzBsjJqj.js";
|
|
2
|
+
import { LRUCache, STRING_DASHERIZE_CACHE, dasherize } from "@warp-drive/core/utils/string";
|
|
3
|
+
|
|
4
|
+
//#region src/-private/string/transform.ts
|
|
5
|
+
const STRING_CAMELIZE_REGEXP_1 = /(\-|\_|\.|\s)+(.)?/g;
|
|
6
|
+
const STRING_CAMELIZE_REGEXP_2 = /(^|\/)([A-Z])/g;
|
|
7
|
+
const CAMELIZE_CACHE = new LRUCache((key) => key.replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr) => chr ? chr.toUpperCase() : "").replace(STRING_CAMELIZE_REGEXP_2, (match) => match.toLowerCase()));
|
|
8
|
+
const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
|
|
9
|
+
const STRING_UNDERSCORE_REGEXP_2 = /\-|\s+/g;
|
|
10
|
+
const UNDERSCORE_CACHE = new LRUCache((str) => str.replace(STRING_UNDERSCORE_REGEXP_1, "$1_$2").replace(STRING_UNDERSCORE_REGEXP_2, "_").toLowerCase());
|
|
11
|
+
const STRING_CAPITALIZE_REGEXP = /(^|\/)([a-z\u00C0-\u024F])/g;
|
|
12
|
+
const CAPITALIZE_CACHE = new LRUCache((str) => str.replace(STRING_CAPITALIZE_REGEXP, (match) => match.toUpperCase()));
|
|
13
|
+
/**
|
|
14
|
+
* Replaces underscores, spaces, or camelCase with dashes.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* import { dasherize } from '@warp-drive/utilities/string';
|
|
18
|
+
*
|
|
19
|
+
* dasherize('innerHTML'); // 'inner-html'
|
|
20
|
+
* dasherize('action_name'); // 'action-name'
|
|
21
|
+
* dasherize('css-class-name'); // 'css-class-name'
|
|
22
|
+
* dasherize('my favorite items'); // 'my-favorite-items'
|
|
23
|
+
* dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
* @since 4.13.0
|
|
28
|
+
*/
|
|
29
|
+
const dasherize$1 = dasherize;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the lowerCamelCase form of a string.
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* import { camelize } from '@warp-drive/utilities/string';
|
|
35
|
+
*
|
|
36
|
+
* camelize('innerHTML'); // 'innerHTML'
|
|
37
|
+
* camelize('action_name'); // 'actionName'
|
|
38
|
+
* camelize('css-class-name'); // 'cssClassName'
|
|
39
|
+
* camelize('my favorite items'); // 'myFavoriteItems'
|
|
40
|
+
* camelize('My Favorite Items'); // 'myFavoriteItems'
|
|
41
|
+
* camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @since 4.13.0
|
|
46
|
+
*/
|
|
47
|
+
function camelize(str) {
|
|
48
|
+
return CAMELIZE_CACHE.get(str);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the lower\_case\_and\_underscored form of a string.
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* import { underscore } from '@warp-drive/utilities/string';
|
|
55
|
+
*
|
|
56
|
+
* underscore('innerHTML'); // 'inner_html'
|
|
57
|
+
* underscore('action_name'); // 'action_name'
|
|
58
|
+
* underscore('css-class-name'); // 'css_class_name'
|
|
59
|
+
* underscore('my favorite items'); // 'my_favorite_items'
|
|
60
|
+
* underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
* @since 4.13.0
|
|
65
|
+
*/
|
|
66
|
+
function underscore(str) {
|
|
67
|
+
return UNDERSCORE_CACHE.get(str);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the Capitalized form of a string
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* import { capitalize } from '@warp-drive/utilities/string';
|
|
74
|
+
*
|
|
75
|
+
* capitalize('innerHTML') // 'InnerHTML'
|
|
76
|
+
* capitalize('action_name') // 'Action_name'
|
|
77
|
+
* capitalize('css-class-name') // 'Css-class-name'
|
|
78
|
+
* capitalize('my favorite items') // 'My favorite items'
|
|
79
|
+
* capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
* @since 4.13.0
|
|
84
|
+
*/
|
|
85
|
+
function capitalize(str) {
|
|
86
|
+
return CAPITALIZE_CACHE.get(str);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Sets the maximum size of the LRUCache for all string transformation functions.
|
|
90
|
+
* The default size is 10,000.
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
* @since 4.13.0
|
|
94
|
+
*/
|
|
95
|
+
function setMaxLRUCacheSize(size) {
|
|
96
|
+
CAMELIZE_CACHE.size = size;
|
|
97
|
+
UNDERSCORE_CACHE.size = size;
|
|
98
|
+
CAPITALIZE_CACHE.size = size;
|
|
99
|
+
STRING_DASHERIZE_CACHE.size = size;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/-private/string/inflect.ts
|
|
104
|
+
const BLANK_REGEX = /^\s*$/;
|
|
105
|
+
const LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
|
|
106
|
+
const LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
|
|
107
|
+
const CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
|
|
108
|
+
const SINGULARS = new LRUCache((word) => {
|
|
109
|
+
return _singularize(word);
|
|
110
|
+
});
|
|
111
|
+
const PLURALS = new LRUCache((word) => {
|
|
112
|
+
return _pluralize(word);
|
|
113
|
+
});
|
|
114
|
+
const UNCOUNTABLE = new Set(defaultRules.uncountable);
|
|
115
|
+
const IRREGULAR = /* @__PURE__ */ new Map();
|
|
116
|
+
const INVERSE_IRREGULAR = /* @__PURE__ */ new Map();
|
|
117
|
+
const SINGULAR_RULES = new Map(defaultRules.singular.reverse());
|
|
118
|
+
const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
|
|
119
|
+
/**
|
|
120
|
+
* Marks a word as uncountable. Uncountable words are not pluralized
|
|
121
|
+
* or singularized.
|
|
122
|
+
*
|
|
123
|
+
* @public
|
|
124
|
+
* @since 4.13.0
|
|
125
|
+
*/
|
|
126
|
+
function uncountable(word) {
|
|
127
|
+
UNCOUNTABLE.add(word.toLowerCase());
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Marks a list of words as uncountable. Uncountable words are not pluralized
|
|
131
|
+
* or singularized.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
* @since 4.13.0
|
|
135
|
+
*/
|
|
136
|
+
function loadUncountable(uncountables) {
|
|
137
|
+
uncountables.forEach((word) => {
|
|
138
|
+
uncountable(word);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Marks a word as irregular. Irregular words have unique
|
|
143
|
+
* pluralization and singularization rules.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
* @since 4.13.0
|
|
147
|
+
*/
|
|
148
|
+
function irregular(single, plur) {
|
|
149
|
+
IRREGULAR.set(single.toLowerCase(), plur);
|
|
150
|
+
IRREGULAR.set(plur.toLowerCase(), plur);
|
|
151
|
+
INVERSE_IRREGULAR.set(plur.toLowerCase(), single);
|
|
152
|
+
INVERSE_IRREGULAR.set(single.toLowerCase(), single);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Marks a list of word pairs as irregular. Irregular words have unique
|
|
156
|
+
* pluralization and singularization rules.
|
|
157
|
+
*
|
|
158
|
+
* @public
|
|
159
|
+
* @since 4.13.0
|
|
160
|
+
*/
|
|
161
|
+
function loadIrregular(irregularPairs) {
|
|
162
|
+
irregularPairs.forEach((pair) => {
|
|
163
|
+
IRREGULAR.set(pair[0].toLowerCase(), pair[1]);
|
|
164
|
+
IRREGULAR.set(pair[1].toLowerCase(), pair[1]);
|
|
165
|
+
INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);
|
|
166
|
+
INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
loadIrregular(defaultRules.irregularPairs);
|
|
170
|
+
/**
|
|
171
|
+
* Clears the caches for singularize and pluralize.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
* @since 4.13.0
|
|
175
|
+
*/
|
|
176
|
+
function clear() {
|
|
177
|
+
SINGULARS.clear();
|
|
178
|
+
PLURALS.clear();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Resets the inflection rules to the defaults.
|
|
182
|
+
*
|
|
183
|
+
* @public
|
|
184
|
+
* @since 4.13.0
|
|
185
|
+
*/
|
|
186
|
+
function resetToDefaults() {
|
|
187
|
+
clearRules();
|
|
188
|
+
defaultRules.uncountable.forEach((v) => UNCOUNTABLE.add(v));
|
|
189
|
+
defaultRules.singular.forEach((v) => SINGULAR_RULES.set(v[0], v[1]));
|
|
190
|
+
defaultRules.plurals.forEach((v) => PLURAL_RULES.set(v[0], v[1]));
|
|
191
|
+
loadIrregular(defaultRules.irregularPairs);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Clears all inflection rules
|
|
195
|
+
* and resets the caches for singularize and pluralize.
|
|
196
|
+
*
|
|
197
|
+
* @public
|
|
198
|
+
* @since 4.13.0
|
|
199
|
+
*/
|
|
200
|
+
function clearRules() {
|
|
201
|
+
SINGULARS.clear();
|
|
202
|
+
PLURALS.clear();
|
|
203
|
+
UNCOUNTABLE.clear();
|
|
204
|
+
IRREGULAR.clear();
|
|
205
|
+
INVERSE_IRREGULAR.clear();
|
|
206
|
+
SINGULAR_RULES.clear();
|
|
207
|
+
PLURAL_RULES.clear();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Singularizes a word.
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
* @since 4.13.0
|
|
214
|
+
*/
|
|
215
|
+
function singularize(word) {
|
|
216
|
+
if (!word) return "";
|
|
217
|
+
return SINGULARS.get(word);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Pluralizes a word.
|
|
221
|
+
*
|
|
222
|
+
* @public
|
|
223
|
+
* @since 4.13.0
|
|
224
|
+
*/
|
|
225
|
+
function pluralize(word) {
|
|
226
|
+
if (!word) return "";
|
|
227
|
+
return PLURALS.get(word);
|
|
228
|
+
}
|
|
229
|
+
function unshiftMap(v, map) {
|
|
230
|
+
const rules = [v, ...map.entries()];
|
|
231
|
+
map.clear();
|
|
232
|
+
rules.forEach((rule) => {
|
|
233
|
+
map.set(rule[0], rule[1]);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Adds a pluralization rule.
|
|
238
|
+
*
|
|
239
|
+
* @public
|
|
240
|
+
* @since 4.13.0
|
|
241
|
+
*/
|
|
242
|
+
function plural(regex, string) {
|
|
243
|
+
if (PLURAL_RULES.has(regex)) PLURAL_RULES.delete(regex);
|
|
244
|
+
unshiftMap([regex, string], PLURAL_RULES);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Adds a singularization rule.
|
|
248
|
+
*
|
|
249
|
+
* @public
|
|
250
|
+
* @since 4.13.0
|
|
251
|
+
*/
|
|
252
|
+
function singular(regex, string) {
|
|
253
|
+
if (SINGULAR_RULES.has(regex)) SINGULAR_RULES.delete(regex);
|
|
254
|
+
unshiftMap([regex, string], SINGULAR_RULES);
|
|
255
|
+
}
|
|
256
|
+
function _pluralize(word) {
|
|
257
|
+
return inflect(word, PLURAL_RULES, IRREGULAR);
|
|
258
|
+
}
|
|
259
|
+
function _singularize(word) {
|
|
260
|
+
return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);
|
|
261
|
+
}
|
|
262
|
+
function inflect(word, typeRules, irregulars) {
|
|
263
|
+
if (!word || BLANK_REGEX.test(word)) return word;
|
|
264
|
+
const lowercase = word.toLowerCase();
|
|
265
|
+
if (UNCOUNTABLE.has(lowercase)) return word;
|
|
266
|
+
const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);
|
|
267
|
+
const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;
|
|
268
|
+
if (lastWord && UNCOUNTABLE.has(lastWord)) return word;
|
|
269
|
+
const isCamelized = CAMELIZED_REGEX.test(word);
|
|
270
|
+
for (let [rule, substitution] of irregulars) if (lowercase.match(rule + "$")) {
|
|
271
|
+
if (isCamelized && lastWord && irregulars.has(lastWord)) {
|
|
272
|
+
substitution = capitalize(substitution);
|
|
273
|
+
rule = capitalize(rule);
|
|
274
|
+
}
|
|
275
|
+
return word.replace(new RegExp(rule, "i"), substitution);
|
|
276
|
+
}
|
|
277
|
+
for (const [rule, substitution] of typeRules) if (rule.test(word)) return word.replace(rule, substitution);
|
|
278
|
+
return word;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
//#endregion
|
|
282
|
+
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 };
|
|
283
|
+
//# sourceMappingURL=string-T1ahjLdj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-T1ahjLdj.js","names":["dasherize","internalDasherize","LRUCache","defaultRules","capitalize","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","get","pluralize","unshiftMap","map","rules","entries","rule","plural","regex","string","has","delete","inflect","typeRules","irregulars","isBlank","test","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// eslint-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// eslint-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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,iBAAiB,IAAI,UAA0B,QACnD,IACG,QAAQ,2BAA2B,QAAQ,YAAY,QAAwB,MAAM,IAAI,YAAY,IAAI,EAAG,CAAC,CAC7G,QAAQ,2BAA2B,UAAgC,MAAM,YAAY,CAAC,CAC3F;AAEA,MAAM,6BAA6B;AAEnC,MAAM,6BAA6B;AACnC,MAAM,mBAAmB,IAAI,UAA0B,QACrD,IAAI,QAAQ,4BAA4B,OAAO,CAAC,CAAC,QAAQ,4BAA4B,GAAG,CAAC,CAAC,YAAY,CACxG;AAEA,MAAM,2BAA2B;AACjC,MAAM,mBAAmB,IAAI,UAA0B,QACrD,IAAI,QAAQ,2BAA2B,UAAgC,MAAM,YAAY,CAAC,CAC5F;;;;;;;;;;;;;;;;;AAkBA,MAAaA,cAAqCC;;;;;;;;;;;;;;;;;;AAmBlD,SAAgB,SAAS,KAAqB;CAC5C,OAAO,eAAe,IAAI,GAAG;AAC/B;;;;;;;;;;;;;;;;;AAkBA,SAAgB,WAAW,KAAqB;CAC9C,OAAO,iBAAiB,IAAI,GAAG;AACjC;;;;;;;;;;;;;;;;;AAkBA,SAAgB,WAAW,KAAqB;CAC9C,OAAO,iBAAiB,IAAI,GAAG;AACjC;;;;;;;;AASA,SAAgB,mBAAmB,MAAoB;CACrD,eAAe,OAAO;CACtB,iBAAiB,OAAO;CACxB,iBAAiB,OAAO;CACxB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AOA,KAAKwD,QAAQlB,MAAMgB,YAAY;CAI1C,OAAOtD;AACT"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
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-T1ahjLdj.js";
|
|
2
|
+
|
|
3
|
+
export { camelize, capitalize, clear, clearRules, dasherize, irregular, loadIrregular, loadUncountable, plural, pluralize, resetToDefaults, setMaxLRUCacheSize, singular, singularize, uncountable, underscore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/utilities",
|
|
3
|
-
"version": "5.9.0-alpha.
|
|
3
|
+
"version": "5.9.0-alpha.21",
|
|
4
4
|
"description": "Utilities package for WarpDrive | Things your app might find useful",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
+
"cjs-dist",
|
|
17
18
|
"declarations",
|
|
18
19
|
"addon-main.cjs",
|
|
19
20
|
"CHANGELOG.md",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
},
|
|
33
34
|
"./*.cjs": {
|
|
34
35
|
"types": "./declarations/*.d.ts",
|
|
35
|
-
"default": "./dist/*.cjs"
|
|
36
|
+
"default": "./cjs-dist/*.cjs"
|
|
36
37
|
},
|
|
37
38
|
"./*": {
|
|
38
39
|
"unpkg-dev-deprecated": "./dist/unpkg/dev-deprecated/*.js",
|
|
@@ -44,21 +45,21 @@
|
|
|
44
45
|
}
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"@warp-drive/core": "5.9.0-alpha.
|
|
48
|
+
"@warp-drive/core": "5.9.0-alpha.21"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@embroider/macros": "^1.
|
|
51
|
+
"@embroider/macros": "^1.20.6"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@babel/core": "^7.28.3",
|
|
54
55
|
"@babel/plugin-transform-typescript": "^7.28.0",
|
|
55
56
|
"@babel/preset-typescript": "^7.27.1",
|
|
56
|
-
"@warp-drive/
|
|
57
|
-
"@warp-drive/
|
|
57
|
+
"@warp-drive/core": "5.9.0-alpha.21",
|
|
58
|
+
"@warp-drive/internal-config": "5.9.0-alpha.21",
|
|
58
59
|
"decorator-transforms": "^2.3.0",
|
|
59
60
|
"expect-type": "^1.2.2",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
61
|
+
"tsdown": "^0.22.14",
|
|
62
|
+
"typescript": "^5.9.3"
|
|
62
63
|
},
|
|
63
64
|
"volta": {
|
|
64
65
|
"extends": "../../package.json"
|
|
@@ -72,9 +73,9 @@
|
|
|
72
73
|
"edition": "octane"
|
|
73
74
|
},
|
|
74
75
|
"scripts": {
|
|
75
|
-
"build:pkg": "
|
|
76
|
+
"build:pkg": "tsdown; tsdown -c ./tsdown.config-cjs.mjs;",
|
|
76
77
|
"lint": "eslint . --quiet --cache --cache-strategy=content",
|
|
77
78
|
"sync": "echo \"syncing\"",
|
|
78
|
-
"start": "
|
|
79
|
+
"start": "tsdown --watch"
|
|
79
80
|
}
|
|
80
81
|
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { ReactiveDataDocument } from "@warp-drive/core/reactive";
|
|
2
|
-
import type { TypeFromInstance } from "@warp-drive/core/types/record";
|
|
3
|
-
import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from "@warp-drive/core/types/request";
|
|
4
|
-
/**
|
|
5
|
-
* Builds request options to fetch a single resource by a known id or identifier
|
|
6
|
-
* configured for the url and header expectations of most ActiveRecord APIs.
|
|
7
|
-
*
|
|
8
|
-
* **Basic Usage**
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
12
|
-
*
|
|
13
|
-
* const data = await store.request(findRecord('person', '1'));
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* **With Options**
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
20
|
-
*
|
|
21
|
-
* const options = findRecord('person', '1', { include: ['pets', 'friends'] });
|
|
22
|
-
* const data = await store.request(options);
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* **With an Identifier**
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
29
|
-
*
|
|
30
|
-
* const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
|
|
31
|
-
* const data = await store.request(options);
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
35
|
-
*
|
|
36
|
-
* The following options are supported:
|
|
37
|
-
*
|
|
38
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
39
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
40
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type
|
|
41
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
42
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
43
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
44
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
45
|
-
* defaulting to `false` if none is configured.
|
|
46
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
50
|
-
*
|
|
51
|
-
* const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
|
|
52
|
-
* const data = await store.request(options);
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @public
|
|
56
|
-
* @param identifier
|
|
57
|
-
* @param options
|
|
58
|
-
*/
|
|
59
|
-
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
60
|
-
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
61
|
-
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
62
|
-
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
63
|
-
/** @deprecated use {@link ReactiveDataDocument} instead */
|
|
64
|
-
export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ReactiveDataDocument } from "@warp-drive/core/reactive";
|
|
2
|
-
import type { QueryParamsSource } from "@warp-drive/core/types/params";
|
|
3
|
-
import type { TypeFromInstance } from "@warp-drive/core/types/record";
|
|
4
|
-
import type { ConstrainedRequestOptions, QueryRequestOptions } from "@warp-drive/core/types/request";
|
|
5
|
-
/**
|
|
6
|
-
* Builds request options to query for resources, usually by a primary
|
|
7
|
-
* type, configured for the url and header expectations of most ActiveRecord APIs.
|
|
8
|
-
*
|
|
9
|
-
* **Basic Usage**
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { query } from '@warp-drive/utilities/active-record';
|
|
13
|
-
*
|
|
14
|
-
* const data = await store.request(query('person'));
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* **With Query Params**
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* import { query } from '@warp-drive/utilities/active-record';
|
|
21
|
-
*
|
|
22
|
-
* const options = query('person', { include: ['pets', 'friends'] });
|
|
23
|
-
* const data = await store.request(options);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
27
|
-
*
|
|
28
|
-
* The following options are supported:
|
|
29
|
-
*
|
|
30
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
31
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
32
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type
|
|
33
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
34
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
35
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
36
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
37
|
-
* defaulting to `false` if none is configured.
|
|
38
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
39
|
-
*
|
|
40
|
-
* ```ts
|
|
41
|
-
* import { query } from '@warp-drive/utilities/active-record';
|
|
42
|
-
*
|
|
43
|
-
* const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
44
|
-
* const data = await store.request(options);
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @public
|
|
48
|
-
* @param identifier
|
|
49
|
-
* @param query
|
|
50
|
-
* @param options
|
|
51
|
-
*/
|
|
52
|
-
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
53
|
-
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { ReactiveDataDocument } from "@warp-drive/core/reactive";
|
|
2
|
-
import type { TypedRecordInstance } from "@warp-drive/core/types/record";
|
|
3
|
-
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from "@warp-drive/core/types/request";
|
|
4
|
-
/**
|
|
5
|
-
* Builds request options to delete record for resources,
|
|
6
|
-
* configured for the url, method and header expectations of ActiveRecord APIs.
|
|
7
|
-
*
|
|
8
|
-
* **Basic Usage**
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { deleteRecord } from '@warp-drive/utilities/active-record';
|
|
12
|
-
*
|
|
13
|
-
* const person = store.peekRecord('person', '1');
|
|
14
|
-
*
|
|
15
|
-
* // mark record as deleted
|
|
16
|
-
* store.deleteRecord(person);
|
|
17
|
-
*
|
|
18
|
-
* // persist deletion
|
|
19
|
-
* const data = await store.request(deleteRecord(person));
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
23
|
-
*
|
|
24
|
-
* The following options are supported:
|
|
25
|
-
*
|
|
26
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
27
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
28
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
29
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
30
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
31
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
32
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
33
|
-
* defaulting to `false` if none is configured.
|
|
34
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { deleteRecord } from '@warp-drive/utilities/active-record';
|
|
38
|
-
*
|
|
39
|
-
* const person = store.peekRecord('person', '1');
|
|
40
|
-
*
|
|
41
|
-
* // mark record as deleted
|
|
42
|
-
* store.deleteRecord(person);
|
|
43
|
-
*
|
|
44
|
-
* // persist deletion
|
|
45
|
-
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
46
|
-
* const data = await store.request(options);
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @public
|
|
50
|
-
* @param record
|
|
51
|
-
* @param options
|
|
52
|
-
*/
|
|
53
|
-
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
54
|
-
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
55
|
-
/**
|
|
56
|
-
* Builds request options to create new record for resources,
|
|
57
|
-
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
58
|
-
*
|
|
59
|
-
* **Basic Usage**
|
|
60
|
-
*
|
|
61
|
-
* ```ts
|
|
62
|
-
* import { createRecord } from '@warp-drive/utilities/active-record';
|
|
63
|
-
*
|
|
64
|
-
* const person = store.createRecord('person', { name: 'Ted' });
|
|
65
|
-
* const data = await store.request(createRecord(person));
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
69
|
-
*
|
|
70
|
-
* The following options are supported:
|
|
71
|
-
*
|
|
72
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
73
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
74
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
75
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
76
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
77
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
78
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
79
|
-
* defaulting to `false` if none is configured.
|
|
80
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
81
|
-
*
|
|
82
|
-
* ```ts
|
|
83
|
-
* import { createRecord } from '@warp-drive/utilities/active-record';
|
|
84
|
-
*
|
|
85
|
-
* const person = store.createRecord('person', { name: 'Ted' });
|
|
86
|
-
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
87
|
-
* const data = await store.request(options);
|
|
88
|
-
* ```
|
|
89
|
-
*
|
|
90
|
-
* @public
|
|
91
|
-
* @param record
|
|
92
|
-
* @param options
|
|
93
|
-
*/
|
|
94
|
-
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
95
|
-
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
96
|
-
/**
|
|
97
|
-
* Builds request options to update existing record for resources,
|
|
98
|
-
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
99
|
-
*
|
|
100
|
-
* **Basic Usage**
|
|
101
|
-
*
|
|
102
|
-
* ```ts
|
|
103
|
-
* import { updateRecord } from '@warp-drive/utilities/active-record';
|
|
104
|
-
*
|
|
105
|
-
* const person = store.peekRecord('person', '1');
|
|
106
|
-
* person.name = 'Chris';
|
|
107
|
-
* const data = await store.request(updateRecord(person));
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
111
|
-
*
|
|
112
|
-
* The following options are supported:
|
|
113
|
-
*
|
|
114
|
-
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
115
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
116
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
117
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
118
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
119
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
120
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
121
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
122
|
-
* defaulting to `false` if none is configured.
|
|
123
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
124
|
-
*
|
|
125
|
-
* ```ts
|
|
126
|
-
* import { updateRecord } from '@warp-drive/utilities/active-record';
|
|
127
|
-
*
|
|
128
|
-
* const person = store.peekRecord('person', '1');
|
|
129
|
-
* person.name = 'Chris';
|
|
130
|
-
* const options = updateRecord(person, { patch: true });
|
|
131
|
-
* const data = await store.request(options);
|
|
132
|
-
* ```
|
|
133
|
-
*
|
|
134
|
-
* @public
|
|
135
|
-
* @param record
|
|
136
|
-
* @param options
|
|
137
|
-
*/
|
|
138
|
-
export declare function updateRecord<
|
|
139
|
-
T extends TypedRecordInstance,
|
|
140
|
-
RT extends TypedRecordInstance = T
|
|
141
|
-
>(record: T, options?: ConstrainedRequestOptions & {
|
|
142
|
-
patch?: boolean;
|
|
143
|
-
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
144
|
-
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
145
|
-
patch?: boolean;
|
|
146
|
-
}): UpdateRequestOptions;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { CacheOptions, ConstrainedRequestOptions } from "@warp-drive/core/types/request";
|
|
2
|
-
import type { UrlOptions } from "../index.js";
|
|
3
|
-
export declare function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void;
|
|
4
|
-
export declare function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions;
|