@warp-drive-mirror/utilities 5.8.0-beta.0 → 5.8.0-beta.2
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 +16 -25
- package/declarations/-private/active-record/find-record.d.ts +5 -6
- package/declarations/-private/active-record/query.d.ts +2 -2
- package/declarations/-private/active-record/save-record.d.ts +2 -2
- package/declarations/-private/handlers/meta-doc.d.ts +1 -1
- package/declarations/-private/json-api/find-record.d.ts +37 -18
- package/declarations/-private/json-api/query.d.ts +3 -6
- package/declarations/-private/json-api/save-record.d.ts +45 -10
- package/declarations/-private/json-api/serialize.d.ts +15 -1
- package/declarations/-private/rest/find-record.d.ts +5 -8
- package/declarations/-private/rest/query.d.ts +2 -2
- package/declarations/-private/rest/save-record.d.ts +2 -2
- package/dist/active-record.js +2 -0
- package/dist/handlers.js +3 -3
- package/dist/json-api.js +94 -26
- package/dist/rest.js +2 -2
- package/dist/string.js +428 -1
- package/dist/unpkg/dev/-private.js +7 -0
- package/dist/unpkg/dev/active-record.js +394 -0
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev/derivations.js +30 -0
- package/dist/unpkg/dev/handlers.js +316 -0
- package/dist/unpkg/dev/index.js +362 -0
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +343 -0
- package/dist/unpkg/dev/json-api.js +740 -0
- package/dist/unpkg/dev/rest.js +392 -0
- package/dist/unpkg/dev/string.js +1 -0
- package/dist/unpkg/dev-deprecated/-private.js +7 -0
- package/dist/unpkg/dev-deprecated/active-record.js +394 -0
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev-deprecated/derivations.js +30 -0
- package/dist/unpkg/dev-deprecated/handlers.js +316 -0
- package/dist/unpkg/dev-deprecated/index.js +362 -0
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +343 -0
- package/dist/unpkg/dev-deprecated/json-api.js +740 -0
- package/dist/unpkg/dev-deprecated/rest.js +392 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -0
- package/dist/unpkg/prod/-private.js +7 -0
- package/dist/unpkg/prod/active-record.js +366 -0
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod/derivations.js +30 -0
- package/dist/unpkg/prod/handlers.js +305 -0
- package/dist/unpkg/prod/index.js +239 -0
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +333 -0
- package/dist/unpkg/prod/json-api.js +702 -0
- package/dist/unpkg/prod/rest.js +364 -0
- package/dist/unpkg/prod/string.js +1 -0
- package/dist/unpkg/prod-deprecated/-private.js +7 -0
- package/dist/unpkg/prod-deprecated/active-record.js +366 -0
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod-deprecated/derivations.js +30 -0
- package/dist/unpkg/prod-deprecated/handlers.js +305 -0
- package/dist/unpkg/prod-deprecated/index.js +239 -0
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +333 -0
- package/dist/unpkg/prod-deprecated/json-api.js +702 -0
- package/dist/unpkg/prod-deprecated/rest.js +364 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +13 -5
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { buildBaseURL, buildQueryParams } from './index.js';
|
|
2
|
+
import { p as pluralize, g as camelize } from "./inflect-BEv8WqY1.js";
|
|
3
|
+
import { e as extractCacheOptions, c as copyForwardUrlOptions } from "./builder-utils-Donkk-BZ.js";
|
|
4
|
+
import { recordIdentifierFor } from '@warp-drive-mirror/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Builds request options to fetch a single resource by a known id or identifier
|
|
8
|
+
* configured for the url and header expectations of most REST APIs.
|
|
9
|
+
*
|
|
10
|
+
* **Basic Usage**
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
14
|
+
*
|
|
15
|
+
* const data = await store.request(findRecord('person', '1'));
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* **With Options**
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
22
|
+
*
|
|
23
|
+
* const options = findRecord('person', '1', { include: ['pets', 'friends'] });
|
|
24
|
+
* const data = await store.request(options);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* **With an Identifier**
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
31
|
+
*
|
|
32
|
+
* const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
|
|
33
|
+
* const data = await store.request(options);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
37
|
+
*
|
|
38
|
+
* The following options are supported:
|
|
39
|
+
*
|
|
40
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
41
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
42
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
|
|
43
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
44
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
45
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
46
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
47
|
+
* defaulting to `false` if none is configured.
|
|
48
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
52
|
+
*
|
|
53
|
+
* const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
|
|
54
|
+
* const data = await store.request(options);
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
function findRecord(arg1, arg2, arg3) {
|
|
61
|
+
const identifier = typeof arg1 === 'string' ? {
|
|
62
|
+
type: arg1,
|
|
63
|
+
id: arg2
|
|
64
|
+
} : arg1;
|
|
65
|
+
const options = (typeof arg1 === 'string' ? arg3 : arg2) || {};
|
|
66
|
+
const cacheOptions = extractCacheOptions(options);
|
|
67
|
+
const urlOptions = {
|
|
68
|
+
identifier,
|
|
69
|
+
op: 'findRecord',
|
|
70
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
71
|
+
};
|
|
72
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
73
|
+
const url = buildBaseURL(urlOptions);
|
|
74
|
+
const headers = new Headers();
|
|
75
|
+
headers.append('Accept', 'application/json;charset=utf-8');
|
|
76
|
+
return {
|
|
77
|
+
url: options.include?.length ? `${url}?${buildQueryParams({
|
|
78
|
+
include: options.include
|
|
79
|
+
}, options.urlParamsSettings)}` : url,
|
|
80
|
+
method: 'GET',
|
|
81
|
+
headers,
|
|
82
|
+
cacheOptions,
|
|
83
|
+
op: 'findRecord',
|
|
84
|
+
records: [identifier]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @deprecated use {@link ReactiveDataDocument} instead */
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Builds request options to query for resources, usually by a primary
|
|
92
|
+
* type, configured for the url and header expectations of most REST APIs.
|
|
93
|
+
*
|
|
94
|
+
* **Basic Usage**
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { query } from '@warp-drive-mirror/utilities/rest';
|
|
98
|
+
*
|
|
99
|
+
* const data = await store.request(query('person'));
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* **With Query Params**
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { query } from '@warp-drive-mirror/utilities/rest';
|
|
106
|
+
*
|
|
107
|
+
* const options = query('person', { include: ['pets', 'friends'] });
|
|
108
|
+
* const data = await store.request(options);
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
112
|
+
*
|
|
113
|
+
* The following options are supported:
|
|
114
|
+
*
|
|
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 and camelCasing 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
|
+
* - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { query } from '@warp-drive-mirror/utilities/rest';
|
|
127
|
+
*
|
|
128
|
+
* const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
129
|
+
* const data = await store.request(options);
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
* @param identifier
|
|
134
|
+
* @param query
|
|
135
|
+
* @param options
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
function query(type,
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
140
|
+
query = {}, options = {}) {
|
|
141
|
+
const cacheOptions = extractCacheOptions(options);
|
|
142
|
+
const urlOptions = {
|
|
143
|
+
identifier: {
|
|
144
|
+
type
|
|
145
|
+
},
|
|
146
|
+
op: 'query',
|
|
147
|
+
resourcePath: pluralize(camelize(type))
|
|
148
|
+
};
|
|
149
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
150
|
+
const url = buildBaseURL(urlOptions);
|
|
151
|
+
const headers = new Headers();
|
|
152
|
+
headers.append('Accept', 'application/json;charset=utf-8');
|
|
153
|
+
const queryString = buildQueryParams(query, options.urlParamsSettings);
|
|
154
|
+
return {
|
|
155
|
+
url: queryString ? `${url}?${queryString}` : url,
|
|
156
|
+
method: 'GET',
|
|
157
|
+
headers,
|
|
158
|
+
cacheOptions,
|
|
159
|
+
op: 'query'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function isExisting(identifier) {
|
|
163
|
+
return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Builds request options to delete record for resources,
|
|
168
|
+
* configured for the url, method and header expectations of REST APIs.
|
|
169
|
+
*
|
|
170
|
+
* **Basic Usage**
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { deleteRecord } from '@warp-drive-mirror/utilities/rest';
|
|
174
|
+
*
|
|
175
|
+
* const person = store.peekRecord('person', '1');
|
|
176
|
+
*
|
|
177
|
+
* // mark record as deleted
|
|
178
|
+
* store.deleteRecord(person);
|
|
179
|
+
*
|
|
180
|
+
* // persist deletion
|
|
181
|
+
* const data = await store.request(deleteRecord(person));
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
185
|
+
*
|
|
186
|
+
* The following options are supported:
|
|
187
|
+
*
|
|
188
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
189
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
190
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
191
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
192
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
193
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
194
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
195
|
+
* defaulting to `false` if none is configured.
|
|
196
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
197
|
+
*
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { deleteRecord } from '@warp-drive-mirror/utilities/rest';
|
|
200
|
+
*
|
|
201
|
+
* const person = store.peekRecord('person', '1');
|
|
202
|
+
*
|
|
203
|
+
* // mark record as deleted
|
|
204
|
+
* store.deleteRecord(person);
|
|
205
|
+
*
|
|
206
|
+
* // persist deletion
|
|
207
|
+
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
208
|
+
* const data = await store.request(options);
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
* @param record
|
|
213
|
+
* @param options
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
function deleteRecord(record, options = {}) {
|
|
217
|
+
const identifier = recordIdentifierFor(record);
|
|
218
|
+
(test => {
|
|
219
|
+
if (!test) {
|
|
220
|
+
throw new Error(`Expected to be given a record instance`);
|
|
221
|
+
}
|
|
222
|
+
})(identifier);
|
|
223
|
+
(test => {
|
|
224
|
+
if (!test) {
|
|
225
|
+
throw new Error(`Cannot delete a record that does not have an associated type and id.`);
|
|
226
|
+
}
|
|
227
|
+
})(isExisting(identifier));
|
|
228
|
+
const urlOptions = {
|
|
229
|
+
identifier: identifier,
|
|
230
|
+
op: 'deleteRecord',
|
|
231
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
232
|
+
};
|
|
233
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
234
|
+
const url = buildBaseURL(urlOptions);
|
|
235
|
+
const headers = new Headers();
|
|
236
|
+
headers.append('Accept', 'application/json;charset=utf-8');
|
|
237
|
+
return {
|
|
238
|
+
url,
|
|
239
|
+
method: 'DELETE',
|
|
240
|
+
headers,
|
|
241
|
+
op: 'deleteRecord',
|
|
242
|
+
data: {
|
|
243
|
+
record: identifier
|
|
244
|
+
},
|
|
245
|
+
records: [identifier]
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Builds request options to create new record for resources,
|
|
251
|
+
* configured for the url, method and header expectations of most REST APIs.
|
|
252
|
+
*
|
|
253
|
+
* **Basic Usage**
|
|
254
|
+
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* import { createRecord } from '@warp-drive-mirror/utilities/rest';
|
|
257
|
+
*
|
|
258
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
259
|
+
* const data = await store.request(createRecord(person));
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
263
|
+
*
|
|
264
|
+
* The following options are supported:
|
|
265
|
+
*
|
|
266
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
267
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
268
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
269
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
270
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
271
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
272
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
273
|
+
* defaulting to `false` if none is configured.
|
|
274
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
275
|
+
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* import { createRecord } from '@warp-drive-mirror/utilities/rest';
|
|
278
|
+
*
|
|
279
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
280
|
+
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
281
|
+
* const data = await store.request(options);
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @public
|
|
285
|
+
* @param record
|
|
286
|
+
* @param options
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
function createRecord(record, options = {}) {
|
|
290
|
+
const identifier = recordIdentifierFor(record);
|
|
291
|
+
(test => {
|
|
292
|
+
if (!test) {
|
|
293
|
+
throw new Error(`Expected to be given a record instance`);
|
|
294
|
+
}
|
|
295
|
+
})(identifier);
|
|
296
|
+
const urlOptions = {
|
|
297
|
+
identifier: identifier,
|
|
298
|
+
op: 'createRecord',
|
|
299
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
300
|
+
};
|
|
301
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
302
|
+
const url = buildBaseURL(urlOptions);
|
|
303
|
+
const headers = new Headers();
|
|
304
|
+
headers.append('Accept', 'application/json;charset=utf-8');
|
|
305
|
+
return {
|
|
306
|
+
url,
|
|
307
|
+
method: 'POST',
|
|
308
|
+
headers,
|
|
309
|
+
op: 'createRecord',
|
|
310
|
+
data: {
|
|
311
|
+
record: identifier
|
|
312
|
+
},
|
|
313
|
+
records: [identifier]
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Builds request options to update existing record for resources,
|
|
319
|
+
* configured for the url, method and header expectations of most REST APIs.
|
|
320
|
+
*
|
|
321
|
+
* **Basic Usage**
|
|
322
|
+
*
|
|
323
|
+
* ```ts
|
|
324
|
+
* import { updateRecord } from '@warp-drive-mirror/utilities/rest';
|
|
325
|
+
*
|
|
326
|
+
* const person = store.peekRecord('person', '1');
|
|
327
|
+
* person.name = 'Chris';
|
|
328
|
+
* const data = await store.request(updateRecord(person));
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
332
|
+
*
|
|
333
|
+
* The following options are supported:
|
|
334
|
+
*
|
|
335
|
+
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
336
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
337
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
338
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
339
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
340
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
341
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
342
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
343
|
+
* defaulting to `false` if none is configured.
|
|
344
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { updateRecord } from '@warp-drive-mirror/utilities/rest';
|
|
348
|
+
*
|
|
349
|
+
* const person = store.peekRecord('person', '1');
|
|
350
|
+
* person.name = 'Chris';
|
|
351
|
+
* const options = updateRecord(person, { patch: true });
|
|
352
|
+
* const data = await store.request(options);
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @public
|
|
356
|
+
* @param record
|
|
357
|
+
* @param options
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
function updateRecord(record, options = {}) {
|
|
361
|
+
const identifier = recordIdentifierFor(record);
|
|
362
|
+
(test => {
|
|
363
|
+
if (!test) {
|
|
364
|
+
throw new Error(`Expected to be given a record instance`);
|
|
365
|
+
}
|
|
366
|
+
})(identifier);
|
|
367
|
+
(test => {
|
|
368
|
+
if (!test) {
|
|
369
|
+
throw new Error(`Cannot update a record that does not have an associated type and id.`);
|
|
370
|
+
}
|
|
371
|
+
})(isExisting(identifier));
|
|
372
|
+
const urlOptions = {
|
|
373
|
+
identifier: identifier,
|
|
374
|
+
op: 'updateRecord',
|
|
375
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
376
|
+
};
|
|
377
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
378
|
+
const url = buildBaseURL(urlOptions);
|
|
379
|
+
const headers = new Headers();
|
|
380
|
+
headers.append('Accept', 'application/json;charset=utf-8');
|
|
381
|
+
return {
|
|
382
|
+
url,
|
|
383
|
+
method: options.patch ? 'PATCH' : 'PUT',
|
|
384
|
+
headers,
|
|
385
|
+
op: 'updateRecord',
|
|
386
|
+
data: {
|
|
387
|
+
record: identifier
|
|
388
|
+
},
|
|
389
|
+
records: [identifier]
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
export { createRecord, deleteRecord, findRecord, query, updateRecord };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { g as camelize, h as capitalize, d as clear, e as clearRules, f as dasherize, i as irregular, l as loadIrregular, c as loadUncountable, b as plural, p as pluralize, r as resetToDefaults, k as setMaxLRUCacheSize, a as singular, s as singularize, u as uncountable, j as underscore } from "./inflect-BEv8WqY1.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const defaultRules = {
|
|
2
|
+
plurals: [[/$/, 's'], [/s$/i, 's'], [/^(ax|test)is$/i, '$1es'], [/(octop|vir)us$/i, '$1i'], [/(octop|vir)i$/i, '$1i'], [/(alias|status|bonus)$/i, '$1es'], [/(bu)s$/i, '$1ses'], [/(buffal|tomat)o$/i, '$1oes'], [/([ti])um$/i, '$1a'], [/([ti])a$/i, '$1a'], [/sis$/i, 'ses'], [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'], [/(hive)$/i, '$1s'], [/([^aeiouy]|qu)y$/i, '$1ies'], [/(x|ch|ss|sh)$/i, '$1es'], [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'], [/^(m|l)ouse$/i, '$1ice'], [/^(m|l)ice$/i, '$1ice'], [/^(ox)$/i, '$1en'], [/^(oxen)$/i, '$1'], [/(quiz)$/i, '$1zes']],
|
|
3
|
+
singular: [[/s$/i, ''], [/(ss)$/i, '$1'], [/(n)ews$/i, '$1ews'], [/([ti])a$/i, '$1um'], [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'], [/(^analy)(sis|ses)$/i, '$1sis'], [/([^f])ves$/i, '$1fe'], [/(hive)s$/i, '$1'], [/(tive)s$/i, '$1'], [/([lr])ves$/i, '$1f'], [/([^aeiouy]|qu)ies$/i, '$1y'], [/(s)eries$/i, '$1eries'], [/(m)ovies$/i, '$1ovie'], [/(x|ch|ss|sh)es$/i, '$1'], [/^(m|l)ice$/i, '$1ouse'], [/(bus)(es)?$/i, '$1'], [/(o)es$/i, '$1'], [/(shoe)s$/i, '$1'], [/(cris|test)(is|es)$/i, '$1is'], [/^(a)x[ie]s$/i, '$1xis'], [/(octop|vir)(us|i)$/i, '$1us'], [/(alias|status|bonus)(es)?$/i, '$1'], [/^(ox)en/i, '$1'], [/(vert|ind)ices$/i, '$1ex'], [/(matr)ices$/i, '$1ix'], [/(quiz)zes$/i, '$1'], [/(database)s$/i, '$1']],
|
|
4
|
+
irregularPairs: [['person', 'people'], ['man', 'men'], ['child', 'children'], ['sex', 'sexes'], ['move', 'moves'], ['cow', 'kine'], ['zombie', 'zombies']],
|
|
5
|
+
uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police']
|
|
6
|
+
};
|
|
7
|
+
export { defaultRules as InflectionRuleDefaults };
|