@ember-data-mirror/rest 5.4.0-alpha.49

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/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2017-2023 Ember.js contributors
4
+ Portions Copyright (C) 2011-2017 Tilde, Inc. and contributors.
5
+ Portions Copyright (C) 2011 LivingSocial Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ <p align="center">
2
+ <img
3
+ class="project-logo"
4
+ src="./ember-data-logo-dark.svg#gh-dark-mode-only"
5
+ alt="EmberData REST"
6
+ width="240px"
7
+ title="EmberData REST"
8
+ />
9
+ <img
10
+ class="project-logo"
11
+ src="./ember-data-logo-light.svg#gh-light-mode-only"
12
+ alt="EmberData REST"
13
+ width="240px"
14
+ title="EmberData REST"
15
+ />
16
+ </p>
17
+
18
+ <p align="center">Elegantly composable. Made for <strong>REST</strong>ful APIs</p>
19
+
20
+ This package provides utilities for working with **REST**ful APIs with [*Ember***Data**](https://github.com/emberjs/data/).
21
+
22
+ ## Installation
23
+
24
+ Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
25
+
26
+ ```no-highlight
27
+ pnpm add @ember-data-mirror/rest
28
+ ```
29
+
30
+ ## Getting Started
31
+
32
+ If this package is how you are first learning about EmberData, we recommend starting with learning about the [Store](https://github.com/emberjs/data/blob/main/packages/store/README.md) and [Requests](https://github.com/emberjs/data/blob/main/packages/request/README.md)
33
+
34
+ ## Request Builders
35
+
36
+ Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
37
+
38
+ For instance, to fetch a resource from your API
39
+
40
+ ```ts
41
+ import { findRecord } from '@ember-data-mirror/rest/request';
42
+
43
+ const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
44
+
45
+ /*
46
+ => {
47
+ url: 'https://api.example.com/v1/emberDevelopers/1?include=friends,pets',
48
+ method: 'GET',
49
+ headers: <Headers>, // 'Content-Type': 'application/json;charset=utf-8'
50
+ op: 'findRecord';
51
+ records: [{ type: 'ember-developer', id: '1' }]
52
+ }
53
+ */
54
+ ```
55
+
56
+ Request builder output may be used with either `requestManager.request` or `store.request`.
57
+
58
+ URLs are stable. The same query will produce the same URL every time, even if the order of keys in
59
+ the query or values in an array changes.
60
+
61
+ URLs follow the most common REST format (camelCase pluralized resource types).
62
+
63
+ ### Available Builders
64
+
65
+ - [createRecord]()
66
+ - [deleteRecord]()
67
+ - [findRecord]()
68
+ - [query]()
69
+ - [updateRecord]()
@@ -0,0 +1,413 @@
1
+ import { camelize } from '@ember/string';
2
+ import { pluralize } from 'ember-inflector';
3
+ import { buildBaseURL, buildQueryParams } from '@ember-data-mirror/request-utils';
4
+ import { assert } from '@ember/debug';
5
+ import { recordIdentifierFor } from '@ember-data-mirror/store';
6
+ function copyForwardUrlOptions(urlOptions, options) {
7
+ if ('host' in options) {
8
+ urlOptions.host = options.host;
9
+ }
10
+ if ('namespace' in options) {
11
+ urlOptions.namespace = options.namespace;
12
+ }
13
+ if ('resourcePath' in options) {
14
+ urlOptions.resourcePath = options.resourcePath;
15
+ }
16
+ }
17
+ function extractCacheOptions(options) {
18
+ const cacheOptions = {};
19
+ if ('reload' in options) {
20
+ cacheOptions.reload = options.reload;
21
+ }
22
+ if ('backgroundReload' in options) {
23
+ cacheOptions.backgroundReload = options.backgroundReload;
24
+ }
25
+ return cacheOptions;
26
+ }
27
+
28
+ /**
29
+ * @module @ember-data-mirror/rest/request
30
+ */
31
+
32
+ /**
33
+ * Builds request options to fetch a single resource by a known id or identifier
34
+ * configured for the url and header expectations of most REST APIs.
35
+ *
36
+ * **Basic Usage**
37
+ *
38
+ * ```ts
39
+ * import { findRecord } from '@ember-data-mirror/rest/request';
40
+ *
41
+ * const data = await store.request(findRecord('person', '1'));
42
+ * ```
43
+ *
44
+ * **With Options**
45
+ *
46
+ * ```ts
47
+ * import { findRecord } from '@ember-data-mirror/rest/request';
48
+ *
49
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] });
50
+ * const data = await store.request(options);
51
+ * ```
52
+ *
53
+ * **With an Identifier**
54
+ *
55
+ * ```ts
56
+ * import { findRecord } from '@ember-data-mirror/rest/request';
57
+ *
58
+ * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
59
+ * const data = await store.request(options);
60
+ * ```
61
+ *
62
+ * **Supplying Options to Modify the Request Behavior**
63
+ *
64
+ * The following options are supported:
65
+ *
66
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
67
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
68
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
69
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
70
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
71
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
72
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
73
+ * defaulting to `false` if none is configured.
74
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
75
+ *
76
+ * ```ts
77
+ * import { findRecord } from '@ember-data-mirror/rest/request';
78
+ *
79
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
80
+ * const data = await store.request(options);
81
+ * ```
82
+ *
83
+ * @method findRecord
84
+ * @public
85
+ * @static
86
+ * @for @ember-data-mirror/rest/request
87
+ * @param identifier
88
+ * @param options
89
+ */
90
+
91
+ function findRecord(arg1, arg2, arg3) {
92
+ const identifier = typeof arg1 === 'string' ? {
93
+ type: arg1,
94
+ id: arg2
95
+ } : arg1;
96
+ const options = (typeof arg1 === 'string' ? arg3 : arg2) || {};
97
+ const cacheOptions = extractCacheOptions(options);
98
+ const urlOptions = {
99
+ identifier,
100
+ op: 'findRecord',
101
+ resourcePath: pluralize(camelize(identifier.type))
102
+ };
103
+ copyForwardUrlOptions(urlOptions, options);
104
+ const url = buildBaseURL(urlOptions);
105
+ const headers = new Headers();
106
+ headers.append('Accept', 'application/json;charset=utf-8');
107
+ return {
108
+ url: options.include?.length ? `${url}?${buildQueryParams({
109
+ include: options.include
110
+ }, options.urlParamsSettings)}` : url,
111
+ method: 'GET',
112
+ headers,
113
+ cacheOptions,
114
+ op: 'findRecord',
115
+ records: [identifier]
116
+ };
117
+ }
118
+
119
+ /**
120
+ * @module @ember-data-mirror/rest/request
121
+ */
122
+
123
+ /**
124
+ * Builds request options to query for resources, usually by a primary
125
+ * type, configured for the url and header expectations of most REST APIs.
126
+ *
127
+ * **Basic Usage**
128
+ *
129
+ * ```ts
130
+ * import { query } from '@ember-data-mirror/rest/request';
131
+ *
132
+ * const data = await store.request(query('person'));
133
+ * ```
134
+ *
135
+ * **With Query Params**
136
+ *
137
+ * ```ts
138
+ * import { query } from '@ember-data-mirror/rest/request';
139
+ *
140
+ * const options = query('person', { include: ['pets', 'friends'] });
141
+ * const data = await store.request(options);
142
+ * ```
143
+ *
144
+ * **Supplying Options to Modify the Request Behavior**
145
+ *
146
+ * The following options are supported:
147
+ *
148
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
149
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
150
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
151
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
152
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
153
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
154
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
155
+ * defaulting to `false` if none is configured.
156
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
157
+ *
158
+ * ```ts
159
+ * import { query } from '@ember-data-mirror/rest/request';
160
+ *
161
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
162
+ * const data = await store.request(options);
163
+ * ```
164
+ *
165
+ * @method query
166
+ * @public
167
+ * @static
168
+ * @for @ember-data-mirror/rest/request
169
+ * @param identifier
170
+ * @param query
171
+ * @param options
172
+ */
173
+ function query(type,
174
+ // eslint-disable-next-line @typescript-eslint/no-shadow
175
+ query = {}, options = {}) {
176
+ const cacheOptions = extractCacheOptions(options);
177
+ const urlOptions = {
178
+ identifier: {
179
+ type
180
+ },
181
+ op: 'query',
182
+ resourcePath: pluralize(camelize(type))
183
+ };
184
+ copyForwardUrlOptions(urlOptions, options);
185
+ const url = buildBaseURL(urlOptions);
186
+ const headers = new Headers();
187
+ headers.append('Accept', 'application/json;charset=utf-8');
188
+ const queryString = buildQueryParams(query, options.urlParamsSettings);
189
+ return {
190
+ url: queryString ? `${url}?${queryString}` : url,
191
+ method: 'GET',
192
+ headers,
193
+ cacheOptions,
194
+ op: 'query'
195
+ };
196
+ }
197
+ function isExisting(identifier) {
198
+ return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;
199
+ }
200
+
201
+ /**
202
+ * Builds request options to delete record for resources,
203
+ * configured for the url, method and header expectations of REST APIs.
204
+ *
205
+ * **Basic Usage**
206
+ *
207
+ * ```ts
208
+ * import { deleteRecord } from '@ember-data-mirror/rest/request';
209
+ *
210
+ * const person = store.peekRecord('person', '1');
211
+ *
212
+ * // mark record as deleted
213
+ * store.deleteRecord(person);
214
+ *
215
+ * // persist deletion
216
+ * const data = await store.request(deleteRecord(person));
217
+ * ```
218
+ *
219
+ * **Supplying Options to Modify the Request Behavior**
220
+ *
221
+ * The following options are supported:
222
+ *
223
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
224
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
225
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
226
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
227
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
228
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
229
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
230
+ * defaulting to `false` if none is configured.
231
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
232
+ *
233
+ * ```ts
234
+ * import { deleteRecord } from '@ember-data-mirror/rest/request';
235
+ *
236
+ * const person = store.peekRecord('person', '1');
237
+ *
238
+ * // mark record as deleted
239
+ * store.deleteRecord(person);
240
+ *
241
+ * // persist deletion
242
+ * const options = deleteRecord(person, { namespace: 'api/v1' });
243
+ * const data = await store.request(options);
244
+ * ```
245
+ *
246
+ * @method deleteRecord
247
+ * @public
248
+ * @static
249
+ * @for @ember-data-mirror/rest/request
250
+ * @param record
251
+ * @param options
252
+ */
253
+ function deleteRecord(record, options = {}) {
254
+ const identifier = recordIdentifierFor(record);
255
+ assert(`Expected to be given a record instance`, identifier);
256
+ assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));
257
+ const urlOptions = {
258
+ identifier: identifier,
259
+ op: 'deleteRecord',
260
+ resourcePath: pluralize(camelize(identifier.type))
261
+ };
262
+ copyForwardUrlOptions(urlOptions, options);
263
+ const url = buildBaseURL(urlOptions);
264
+ const headers = new Headers();
265
+ headers.append('Accept', 'application/json;charset=utf-8');
266
+ return {
267
+ url,
268
+ method: 'DELETE',
269
+ headers,
270
+ op: 'deleteRecord',
271
+ data: {
272
+ record: identifier
273
+ },
274
+ records: [identifier]
275
+ };
276
+ }
277
+
278
+ /**
279
+ * Builds request options to create new record for resources,
280
+ * configured for the url, method and header expectations of most REST APIs.
281
+ *
282
+ * **Basic Usage**
283
+ *
284
+ * ```ts
285
+ * import { createRecord } from '@ember-data-mirror/rest/request';
286
+ *
287
+ * const person = store.createRecord('person', { name: 'Ted' });
288
+ * const data = await store.request(createRecord(person));
289
+ * ```
290
+ *
291
+ * **Supplying Options to Modify the Request Behavior**
292
+ *
293
+ * The following options are supported:
294
+ *
295
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
296
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
297
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
298
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
299
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
300
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
301
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
302
+ * defaulting to `false` if none is configured.
303
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
304
+ *
305
+ * ```ts
306
+ * import { createRecord } from '@ember-data-mirror/rest/request';
307
+ *
308
+ * const person = store.createRecord('person', { name: 'Ted' });
309
+ * const options = createRecord(person, { namespace: 'api/v1' });
310
+ * const data = await store.request(options);
311
+ * ```
312
+ *
313
+ * @method createRecord
314
+ * @public
315
+ * @static
316
+ * @for @ember-data-mirror/rest/request
317
+ * @param record
318
+ * @param options
319
+ */
320
+ function createRecord(record, options = {}) {
321
+ const identifier = recordIdentifierFor(record);
322
+ assert(`Expected to be given a record instance`, identifier);
323
+ const urlOptions = {
324
+ identifier: identifier,
325
+ op: 'createRecord',
326
+ resourcePath: pluralize(camelize(identifier.type))
327
+ };
328
+ copyForwardUrlOptions(urlOptions, options);
329
+ const url = buildBaseURL(urlOptions);
330
+ const headers = new Headers();
331
+ headers.append('Accept', 'application/json;charset=utf-8');
332
+ return {
333
+ url,
334
+ method: 'POST',
335
+ headers,
336
+ op: 'createRecord',
337
+ data: {
338
+ record: identifier
339
+ },
340
+ records: [identifier]
341
+ };
342
+ }
343
+
344
+ /**
345
+ * Builds request options to update existing record for resources,
346
+ * configured for the url, method and header expectations of most REST APIs.
347
+ *
348
+ * **Basic Usage**
349
+ *
350
+ * ```ts
351
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
352
+ *
353
+ * const person = store.peekRecord('person', '1');
354
+ * person.name = 'Chris';
355
+ * const data = await store.request(updateRecord(person));
356
+ * ```
357
+ *
358
+ * **Supplying Options to Modify the Request Behavior**
359
+ *
360
+ * The following options are supported:
361
+ *
362
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
363
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
364
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
365
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
366
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
367
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
368
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
369
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
370
+ * defaulting to `false` if none is configured.
371
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
372
+ *
373
+ * ```ts
374
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
375
+ *
376
+ * const person = store.peekRecord('person', '1');
377
+ * person.name = 'Chris';
378
+ * const options = updateRecord(person, { patch: true });
379
+ * const data = await store.request(options);
380
+ * ```
381
+ *
382
+ * @method updateRecord
383
+ * @public
384
+ * @static
385
+ * @for @ember-data-mirror/rest/request
386
+ * @param record
387
+ * @param options
388
+ */
389
+ function updateRecord(record, options = {}) {
390
+ const identifier = recordIdentifierFor(record);
391
+ assert(`Expected to be given a record instance`, identifier);
392
+ assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));
393
+ const urlOptions = {
394
+ identifier: identifier,
395
+ op: 'updateRecord',
396
+ resourcePath: pluralize(camelize(identifier.type))
397
+ };
398
+ copyForwardUrlOptions(urlOptions, options);
399
+ const url = buildBaseURL(urlOptions);
400
+ const headers = new Headers();
401
+ headers.append('Accept', 'application/json;charset=utf-8');
402
+ return {
403
+ url,
404
+ method: options.patch ? 'PATCH' : 'PUT',
405
+ headers,
406
+ op: 'updateRecord',
407
+ data: {
408
+ record: identifier
409
+ },
410
+ records: [identifier]
411
+ };
412
+ }
413
+ export { createRecord, deleteRecord, findRecord, query, updateRecord };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sources":["../src/-private/builders/-utils.ts","../src/-private/builders/find-record.ts","../src/-private/builders/query.ts","../src/-private/builders/save-record.ts"],"sourcesContent":["import type { UrlOptions } from '@ember-data-mirror/request-utils';\nimport type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive-mirror/core-types/request';\n\nexport function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void {\n if ('host' in options) {\n urlOptions.host = options.host;\n }\n if ('namespace' in options) {\n urlOptions.namespace = options.namespace;\n }\n if ('resourcePath' in options) {\n urlOptions.resourcePath = options.resourcePath;\n }\n}\n\nexport function extractCacheOptions(options: ConstrainedRequestOptions) {\n const cacheOptions: CacheOptions = {};\n if ('reload' in options) {\n cacheOptions.reload = options.reload;\n }\n if ('backgroundReload' in options) {\n cacheOptions.backgroundReload = options.backgroundReload;\n }\n return cacheOptions;\n}\n","/**\n * @module @ember-data-mirror/rest/request\n */\nimport { camelize } from '@ember/string';\n\nimport { pluralize } from 'ember-inflector';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '@ember-data-mirror/request-utils';\nimport type {\n ConstrainedRequestOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core-types/request';\n\nimport { copyForwardUrlOptions, extractCacheOptions } from './-utils';\n\ntype FindRecordOptions = ConstrainedRequestOptions & {\n include?: string | string[];\n};\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 REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@ember-data-mirror/rest/request';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@ember-data-mirror/rest/request';\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 '@ember-data-mirror/rest/request';\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 camelCasing 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 lifetimes service, 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 lifetimes service,\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 '@ember-data-mirror/rest/request';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @method findRecord\n * @public\n * @static\n * @for @ember-data-mirror/rest/request\n * @param identifier\n * @param options\n */\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\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: FindRecordOptions = (typeof arg1 === 'string' ? arg3 : (arg2 as FindRecordOptions)) || {};\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(camelize(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 * @module @ember-data-mirror/rest/request\n */\nimport { camelize } from '@ember/string';\n\nimport { pluralize } from 'ember-inflector';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '@ember-data-mirror/request-utils';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core-types/params';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core-types/request';\n\nimport { copyForwardUrlOptions, extractCacheOptions } from './-utils';\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 REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@ember-data-mirror/rest/request';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@ember-data-mirror/rest/request';\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 camelCasing 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 lifetimes service, 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 lifetimes service,\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 '@ember-data-mirror/rest/request';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @method query\n * @public\n * @static\n * @for @ember-data-mirror/rest/request\n * @param identifier\n * @param query\n * @param options\n */\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(camelize(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 { assert } from '@ember/debug';\nimport { camelize } from '@ember/string';\n\nimport { pluralize } from 'ember-inflector';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '@ember-data-mirror/request-utils';\nimport { recordIdentifierFor } from '@ember-data-mirror/store';\nimport type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive-mirror/core-types/identifier';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core-types/request';\n\nimport { copyForwardUrlOptions } from './-utils';\n\nfunction isExisting(identifier: StableRecordIdentifier): identifier is StableExistingRecordIdentifier {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@ember-data-mirror/rest/request';\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 lifetimes service, 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 lifetimes service,\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 '@ember-data-mirror/rest/request';\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 * @method deleteRecord\n * @public\n * @static\n * @for @ember-data-mirror/rest/request\n * @param record\n * @param options\n */\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(camelize(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 REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@ember-data-mirror/rest/request';\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 lifetimes service, 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 lifetimes service,\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 '@ember-data-mirror/rest/request';\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 * @method createRecord\n * @public\n * @static\n * @for @ember-data-mirror/rest/request\n * @param record\n * @param options\n */\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(camelize(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 REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@ember-data-mirror/rest/request';\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 lifetimes service, 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 lifetimes service,\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 '@ember-data-mirror/rest/request';\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 * @method updateRecord\n * @public\n * @static\n * @for @ember-data-mirror/rest/request\n * @param record\n * @param options\n */\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(camelize(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"],"names":["copyForwardUrlOptions","urlOptions","options","host","namespace","resourcePath","extractCacheOptions","cacheOptions","reload","backgroundReload","findRecord","arg1","arg2","arg3","identifier","type","id","op","pluralize","camelize","url","buildBaseURL","headers","Headers","append","include","length","buildQueryParams","urlParamsSettings","method","records","query","queryString","isExisting","deleteRecord","record","recordIdentifierFor","assert","data","createRecord","updateRecord","patch"],"mappings":";;;;;;AAGO,SAASA,qBAAqBA,CAACC,UAAsB,EAAEC,OAAkC,EAAQ;EACtG,IAAI,MAAM,IAAIA,OAAO,EAAE;AACrBD,IAAAA,UAAU,CAACE,IAAI,GAAGD,OAAO,CAACC,IAAI,CAAA;AAChC,GAAA;EACA,IAAI,WAAW,IAAID,OAAO,EAAE;AAC1BD,IAAAA,UAAU,CAACG,SAAS,GAAGF,OAAO,CAACE,SAAS,CAAA;AAC1C,GAAA;EACA,IAAI,cAAc,IAAIF,OAAO,EAAE;AAC7BD,IAAAA,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,UAAU,CAACnB,UAAU,CAAC,CAAC,CAAA;AAEtG,EAAA,MAAMb,UAAkC,GAAG;AACzCa,IAAAA,UAAU,EAAEA,UAAU;AACtBG,IAAAA,EAAE,EAAE,cAAc;IAClBZ,YAAY,EAAEa,SAAS,CAACC,QAAQ,CAACL,UAAU,CAACC,IAAI,CAAC,CAAA;GAClD,CAAA;AAEDf,EAAAA,qBAAqB,CAACC,UAAU,EAAEC,OAAO,CAAC,CAAA;AAE1C,EAAA,MAAMkB,GAAG,GAAGC,YAAY,CAACpB,UAAU,CAAC,CAAA;AACpC,EAAA,MAAMqB,OAAO,GAAG,IAAIC,OAAO,EAAE,CAAA;AAC7BD,EAAAA,OAAO,CAACE,MAAM,CAAC,QAAQ,EAAE,gCAAgC,CAAC,CAAA;EAE1D,OAAO;IACLJ,GAAG;AACHS,IAAAA,MAAM,EAAE3B,OAAO,CAACuC,KAAK,GAAG,OAAO,GAAG,KAAK;IACvCnB,OAAO;AACPL,IAAAA,EAAE,EAAE,cAAc;AAClBqB,IAAAA,IAAI,EAAE;AACJH,MAAAA,MAAM,EAAErB,UAAAA;KACT;IACDgB,OAAO,EAAE,CAAChB,UAAU,CAAA;GACrB,CAAA;AACH;;;;"}
package/addon-main.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ name: require('./package.json').name,
3
+
4
+ treeForVendor() {
5
+ return;
6
+ },
7
+ treeForPublic() {
8
+ return;
9
+ },
10
+ treeForStyles() {
11
+ return;
12
+ },
13
+ treeForAddonStyles() {
14
+ return;
15
+ },
16
+ treeForApp() {
17
+ return;
18
+ },
19
+ };
package/package.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "name": "@ember-data-mirror/rest",
3
+ "description": "REST Format Support for EmberData",
4
+ "version": "5.4.0-alpha.49",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "author": "Chris Thoburn <runspired@users.noreply.github.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+ssh://git@github.com:emberjs/data.git",
11
+ "directory": "packages/rest"
12
+ },
13
+ "homepage": "https://github.com/emberjs/data",
14
+ "bugs": "https://github.com/emberjs/data/issues",
15
+ "engines": {
16
+ "node": ">= 18.19.1"
17
+ },
18
+ "keywords": [
19
+ "ember-addon"
20
+ ],
21
+ "volta": {
22
+ "extends": "../../../../../../package.json"
23
+ },
24
+ "dependencies": {
25
+ "ember-cli-babel": "^8.2.0"
26
+ },
27
+ "peerDependencies": {
28
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.49",
29
+ "@ember-data-mirror/store": "^4.12.0 || ^5.0.0",
30
+ "@ember/string": "^3.1.1",
31
+ "@warp-drive-mirror/core-types": "0.0.0-alpha.35",
32
+ "ember-inflector": "^4.0.2"
33
+ },
34
+ "files": [
35
+ "unstable-preview-types",
36
+ "addon-main.js",
37
+ "addon",
38
+ "README.md",
39
+ "LICENSE.md",
40
+ "ember-data-mirror-logo-dark.svg",
41
+ "ember-data-mirror-logo-light.svg"
42
+ ],
43
+ "scripts": {
44
+ "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives",
45
+ "build:types": "tsc --build",
46
+ "build:client": "rollup --config && babel ./addon --out-dir addon --plugins=../private-build-infra/src/transforms/babel-plugin-transform-ext.js",
47
+ "_build": "bun run build:client && bun run build:types",
48
+ "_syncPnpm": "bun run sync-dependencies-meta-injected"
49
+ },
50
+ "ember-addon": {
51
+ "main": "addon-main.js",
52
+ "type": "addon",
53
+ "version": 1
54
+ },
55
+ "devDependencies": {
56
+ "@babel/cli": "^7.24.1",
57
+ "@babel/core": "^7.24.3",
58
+ "@babel/plugin-proposal-decorators": "^7.24.1",
59
+ "@babel/plugin-transform-class-properties": "^7.24.1",
60
+ "@babel/plugin-transform-runtime": "^7.24.3",
61
+ "@babel/plugin-transform-typescript": "^7.24.1",
62
+ "@babel/preset-env": "^7.24.3",
63
+ "@babel/preset-typescript": "^7.24.1",
64
+ "@babel/runtime": "^7.24.1",
65
+ "@ember-data-mirror/request": "5.4.0-alpha.49",
66
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.49",
67
+ "@ember-data-mirror/store": "5.4.0-alpha.49",
68
+ "@ember-data-mirror/tracking": "5.4.0-alpha.49",
69
+ "@ember/string": "^3.1.1",
70
+ "@embroider/addon-dev": "^4.2.1",
71
+ "@glimmer/component": "^1.1.2",
72
+ "@rollup/plugin-babel": "^6.0.4",
73
+ "@rollup/plugin-node-resolve": "^15.2.3",
74
+ "@warp-drive-mirror/core-types": "0.0.0-alpha.35",
75
+ "@warp-drive/internal-config": "5.4.0-alpha.49",
76
+ "ember-inflector": "^4.0.2",
77
+ "ember-source": "~5.7.0",
78
+ "pnpm-sync-dependencies-meta-injected": "0.0.10",
79
+ "rollup": "^4.13.0",
80
+ "typescript": "^5.4.3",
81
+ "walk-sync": "^3.0.0"
82
+ },
83
+ "ember": {
84
+ "edition": "octane"
85
+ },
86
+ "dependenciesMeta": {
87
+ "@warp-drive-mirror/core-types": {
88
+ "injected": true
89
+ },
90
+ "@ember/string": {
91
+ "injected": true
92
+ },
93
+ "@ember-data-mirror/store": {
94
+ "injected": true
95
+ },
96
+ "@ember-data-mirror/request-utils": {
97
+ "injected": true
98
+ },
99
+ "ember-inflector": {
100
+ "injected": true
101
+ },
102
+ "@ember-data-mirror/request": {
103
+ "injected": true
104
+ },
105
+ "@ember-data-mirror/tracking": {
106
+ "injected": true
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,7 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/-utils' {
2
+ import type { UrlOptions } from '@ember-data-mirror/request-utils';
3
+ import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive-mirror/core-types/request';
4
+ export function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void;
5
+ export function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions;
6
+ }
7
+ //# sourceMappingURL=-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-utils.d.ts","sourceRoot":"","sources":["../../../src/-private/builders/-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE9F,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,yBAAyB,GAAG,IAAI,CAUtG;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,yBAAyB,gBASrE"}
@@ -0,0 +1,68 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/find-record' {
2
+ import type { ConstrainedRequestOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from '@warp-drive-mirror/core-types/request';
3
+ type FindRecordOptions = ConstrainedRequestOptions & {
4
+ include?: string | string[];
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 '@ember-data-mirror/rest/request';
14
+ *
15
+ * const data = await store.request(findRecord('person', '1'));
16
+ * ```
17
+ *
18
+ * **With Options**
19
+ *
20
+ * ```ts
21
+ * import { findRecord } from '@ember-data-mirror/rest/request';
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 '@ember-data-mirror/rest/request';
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 lifetimes service, 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 lifetimes service,
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 '@ember-data-mirror/rest/request';
52
+ *
53
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
54
+ * const data = await store.request(options);
55
+ * ```
56
+ *
57
+ * @method findRecord
58
+ * @public
59
+ * @static
60
+ * @for @ember-data-mirror/rest/request
61
+ * @param identifier
62
+ * @param options
63
+ */
64
+ export function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
65
+ export function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
66
+ export {};
67
+ }
68
+ //# sourceMappingURL=find-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-record.d.ts","sourceRoot":"","sources":["../../../src/-private/builders/find-record.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AAIxC,KAAK,iBAAiB,GAAG,yBAAyB,GAAG;IACnD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,4BAA4B,EACxC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,wBAAwB,CAAC;AAC5B,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,wBAAwB,CAAC"}
@@ -0,0 +1,56 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/query' {
2
+ import type { QueryParamsSource } from '@warp-drive-mirror/core-types/params';
3
+ import type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core-types/request';
4
+ /**
5
+ * Builds request options to query for resources, usually by a primary
6
+ * type, configured for the url and header expectations of most REST APIs.
7
+ *
8
+ * **Basic Usage**
9
+ *
10
+ * ```ts
11
+ * import { query } from '@ember-data-mirror/rest/request';
12
+ *
13
+ * const data = await store.request(query('person'));
14
+ * ```
15
+ *
16
+ * **With Query Params**
17
+ *
18
+ * ```ts
19
+ * import { query } from '@ember-data-mirror/rest/request';
20
+ *
21
+ * const options = query('person', { include: ['pets', 'friends'] });
22
+ * const data = await store.request(options);
23
+ * ```
24
+ *
25
+ * **Supplying Options to Modify the Request Behavior**
26
+ *
27
+ * The following options are supported:
28
+ *
29
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
30
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
31
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
32
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
33
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
34
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
35
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
36
+ * defaulting to `false` if none is configured.
37
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
38
+ *
39
+ * ```ts
40
+ * import { query } from '@ember-data-mirror/rest/request';
41
+ *
42
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
43
+ * const data = await store.request(options);
44
+ * ```
45
+ *
46
+ * @method query
47
+ * @public
48
+ * @static
49
+ * @for @ember-data-mirror/rest/request
50
+ * @param identifier
51
+ * @param query
52
+ * @param options
53
+ */
54
+ export function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
55
+ }
56
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/-private/builders/query.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAIrG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EAEZ,KAAK,GAAE,iBAAsB,EAC7B,OAAO,GAAE,yBAA8B,GACtC,mBAAmB,CAsBrB"}
@@ -0,0 +1,148 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/save-record' {
2
+ import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from '@warp-drive-mirror/core-types/request';
3
+ /**
4
+ * Builds request options to delete record for resources,
5
+ * configured for the url, method and header expectations of REST APIs.
6
+ *
7
+ * **Basic Usage**
8
+ *
9
+ * ```ts
10
+ * import { deleteRecord } from '@ember-data-mirror/rest/request';
11
+ *
12
+ * const person = store.peekRecord('person', '1');
13
+ *
14
+ * // mark record as deleted
15
+ * store.deleteRecord(person);
16
+ *
17
+ * // persist deletion
18
+ * const data = await store.request(deleteRecord(person));
19
+ * ```
20
+ *
21
+ * **Supplying Options to Modify the Request Behavior**
22
+ *
23
+ * The following options are supported:
24
+ *
25
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
26
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
27
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
28
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
29
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
30
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
31
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
32
+ * defaulting to `false` if none is configured.
33
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
34
+ *
35
+ * ```ts
36
+ * import { deleteRecord } from '@ember-data-mirror/rest/request';
37
+ *
38
+ * const person = store.peekRecord('person', '1');
39
+ *
40
+ * // mark record as deleted
41
+ * store.deleteRecord(person);
42
+ *
43
+ * // persist deletion
44
+ * const options = deleteRecord(person, { namespace: 'api/v1' });
45
+ * const data = await store.request(options);
46
+ * ```
47
+ *
48
+ * @method deleteRecord
49
+ * @public
50
+ * @static
51
+ * @for @ember-data-mirror/rest/request
52
+ * @param record
53
+ * @param options
54
+ */
55
+ export function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
56
+ /**
57
+ * Builds request options to create new record for resources,
58
+ * configured for the url, method and header expectations of most REST APIs.
59
+ *
60
+ * **Basic Usage**
61
+ *
62
+ * ```ts
63
+ * import { createRecord } from '@ember-data-mirror/rest/request';
64
+ *
65
+ * const person = store.createRecord('person', { name: 'Ted' });
66
+ * const data = await store.request(createRecord(person));
67
+ * ```
68
+ *
69
+ * **Supplying Options to Modify the Request Behavior**
70
+ *
71
+ * The following options are supported:
72
+ *
73
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
74
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
75
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
76
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
77
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
78
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
79
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
80
+ * defaulting to `false` if none is configured.
81
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
82
+ *
83
+ * ```ts
84
+ * import { createRecord } from '@ember-data-mirror/rest/request';
85
+ *
86
+ * const person = store.createRecord('person', { name: 'Ted' });
87
+ * const options = createRecord(person, { namespace: 'api/v1' });
88
+ * const data = await store.request(options);
89
+ * ```
90
+ *
91
+ * @method createRecord
92
+ * @public
93
+ * @static
94
+ * @for @ember-data-mirror/rest/request
95
+ * @param record
96
+ * @param options
97
+ */
98
+ export function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
99
+ /**
100
+ * Builds request options to update existing record for resources,
101
+ * configured for the url, method and header expectations of most REST APIs.
102
+ *
103
+ * **Basic Usage**
104
+ *
105
+ * ```ts
106
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
107
+ *
108
+ * const person = store.peekRecord('person', '1');
109
+ * person.name = 'Chris';
110
+ * const data = await store.request(updateRecord(person));
111
+ * ```
112
+ *
113
+ * **Supplying Options to Modify the Request Behavior**
114
+ *
115
+ * The following options are supported:
116
+ *
117
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
118
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
119
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
120
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
121
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
122
+ * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured.
123
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
124
+ * promise with the cached value, not supplying this option will delegate to the store's lifetimes service,
125
+ * defaulting to `false` if none is configured.
126
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
127
+ *
128
+ * ```ts
129
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
130
+ *
131
+ * const person = store.peekRecord('person', '1');
132
+ * person.name = 'Chris';
133
+ * const options = updateRecord(person, { patch: true });
134
+ * const data = await store.request(options);
135
+ * ```
136
+ *
137
+ * @method updateRecord
138
+ * @public
139
+ * @static
140
+ * @for @ember-data-mirror/rest/request
141
+ * @param record
142
+ * @param options
143
+ */
144
+ export function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
145
+ patch?: boolean;
146
+ }): UpdateRequestOptions;
147
+ }
148
+ //# sourceMappingURL=save-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save-record.d.ts","sourceRoot":"","sources":["../../../src/-private/builders/save-record.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AAQxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,yBAA8B,GAAG,oBAAoB,CA2B3G;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,yBAA8B,GAAG,oBAAoB,CA0B3G;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5D,oBAAoB,CA2BtB"}
@@ -0,0 +1,5 @@
1
+ /// <reference path="./request.d.ts" />
2
+ /// <reference path="./-private/builders/save-record.d.ts" />
3
+ /// <reference path="./-private/builders/find-record.d.ts" />
4
+ /// <reference path="./-private/builders/query.d.ts" />
5
+ /// <reference path="./-private/builders/-utils.d.ts" />
@@ -0,0 +1,72 @@
1
+ declare module '@ember-data-mirror/rest/request' {
2
+ /**
3
+ * <p align="center">
4
+ <img
5
+ class="project-logo"
6
+ src="https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only"
7
+ alt="EmberData"
8
+ width="240px"
9
+ title="EmberData"
10
+ />
11
+ </p>
12
+
13
+ This package provides utilities for working with **REST**ful APIs with [*Ember***Data**](https://github.com/emberjs/data/).
14
+
15
+ ## Installation
16
+
17
+ Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
18
+
19
+ ```no-highlight
20
+ pnpm add @ember-data-mirror/json-api
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
26
+ They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
27
+
28
+ For instance, to fetch a resource from your API
29
+
30
+ ```ts
31
+ import { findRecord } from '@ember-data-mirror/rest/request';
32
+
33
+ const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
34
+
35
+ /*
36
+ => {
37
+ url: 'https://api.example.com/v1/emberDevelopers/1?include=friends,pets',
38
+ method: 'GET',
39
+ headers: <Headers>, // 'Content-Type': 'application/json;charset=utf-8'
40
+ op: 'findRecord';
41
+ records: [{ type: 'ember-developer', id: '1' }]
42
+ }
43
+ * /
44
+ ```
45
+
46
+ Request builder output is ready to go for use with [store.request](https://api.emberjs.com/ember-data/release/classes/Store/methods/request?anchor=request),
47
+ [manager.request](https://api.emberjs.com/ember-data/release/classes/RequestManager/methods/request?anchor=request) and most conventional REST APIs.
48
+
49
+ Resource types are pluralized and camelized for the url.
50
+
51
+ URLs are stable. The same query will produce the same URL every time, even if the order of keys in
52
+ the query or values in an array changes.
53
+
54
+ URLs follow the most common REST format (camelCase pluralized resource types).
55
+
56
+ ### Available Builders
57
+
58
+ - [createRecord](https://api.emberjs.com/ember-data/release/functions/@ember-data%2Frest/createRecord)
59
+ - [deleteRecord](https://api.emberjs.com/ember-data/release/functions/@ember-data%2Frest/deleteRecord)
60
+ - [findRecord](https://api.emberjs.com/ember-data/release/functions/@ember-data%2Frest/findRecord)
61
+ - [query](https://api.emberjs.com/ember-data/release/functions/@ember-data%2Frest/query)
62
+ - [updateRecord](https://api.emberjs.com/ember-data/release/functions/@ember-data%2Frest/updateRecord)
63
+
64
+ * @module @ember-data-mirror/rest/request
65
+ * @main @ember-data-mirror/rest/request
66
+ * @public
67
+ */
68
+ export { findRecord } from '@ember-data-mirror/rest/-private/builders/find-record';
69
+ export { query } from '@ember-data-mirror/rest/-private/builders/query';
70
+ export { deleteRecord, createRecord, updateRecord } from '@ember-data-mirror/rest/-private/builders/save-record';
71
+ }
72
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC"}