@ember-data-mirror/rest 5.3.4

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,78 @@
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
+ **Tagged Releases**
31
+
32
+ - ![NPM Canary Version](https://img.shields.io/npm/v/%40ember-data/rest/canary?label=%40canary&color=FFBF00)
33
+ - ![NPM Beta Version](https://img.shields.io/npm/v/%40ember-data/rest/beta?label=%40beta&color=ff00ff)
34
+ - ![NPM Stable Version](https://img.shields.io/npm/v/%40ember-data/rest/latest?label=%40latest&color=90EE90)
35
+ - ![NPM LTS Version](https://img.shields.io/npm/v/%40ember-data/rest/lts?label=%40lts&color=0096FF)
36
+ - ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/%40ember-data/rest/lts-4-12?label=%40lts-4-12&color=bbbbbb)
37
+
38
+
39
+ ## Getting Started
40
+
41
+ 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)
42
+
43
+ ## Request Builders
44
+
45
+ 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.
46
+
47
+ For instance, to fetch a resource from your API
48
+
49
+ ```ts
50
+ import { findRecord } from '@ember-data-mirror/rest/request';
51
+
52
+ const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
53
+
54
+ /*
55
+ => {
56
+ url: 'https://api.example.com/v1/emberDevelopers/1?include=friends,pets',
57
+ method: 'GET',
58
+ headers: <Headers>, // 'Content-Type': 'application/json;charset=utf-8'
59
+ op: 'findRecord';
60
+ records: [{ type: 'ember-developer', id: '1' }]
61
+ }
62
+ */
63
+ ```
64
+
65
+ Request builder output may be used with either `requestManager.request` or `store.request`.
66
+
67
+ URLs are stable. The same query will produce the same URL every time, even if the order of keys in
68
+ the query or values in an array changes.
69
+
70
+ URLs follow the most common REST format (camelCase pluralized resource types).
71
+
72
+ ### Available Builders
73
+
74
+ - [createRecord]()
75
+ - [deleteRecord]()
76
+ - [findRecord]()
77
+ - [query]()
78
+ - [updateRecord]()
package/addon-main.cjs ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const { addonShim } = require('@warp-drive/build-config/addon-shim.cjs');
4
+
5
+ module.exports = addonShim(__dirname);
@@ -0,0 +1,436 @@
1
+ import { buildBaseURL, buildQueryParams } from '@ember-data-mirror/request-utils';
2
+ import { pluralize, camelize } from '@ember-data-mirror/request-utils/string';
3
+ import { recordIdentifierFor } from '@ember-data-mirror/store';
4
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
5
+ function copyForwardUrlOptions(urlOptions, options) {
6
+ if ('host' in options) {
7
+ urlOptions.host = options.host;
8
+ }
9
+ if ('namespace' in options) {
10
+ urlOptions.namespace = options.namespace;
11
+ }
12
+ if ('resourcePath' in options) {
13
+ urlOptions.resourcePath = options.resourcePath;
14
+ }
15
+ }
16
+ function extractCacheOptions(options) {
17
+ const cacheOptions = {};
18
+ if ('reload' in options) {
19
+ cacheOptions.reload = options.reload;
20
+ }
21
+ if ('backgroundReload' in options) {
22
+ cacheOptions.backgroundReload = options.backgroundReload;
23
+ }
24
+ return cacheOptions;
25
+ }
26
+
27
+ /**
28
+ * @module @ember-data-mirror/rest/request
29
+ */
30
+
31
+ /**
32
+ * Builds request options to fetch a single resource by a known id or identifier
33
+ * configured for the url and header expectations of most REST APIs.
34
+ *
35
+ * **Basic Usage**
36
+ *
37
+ * ```ts
38
+ * import { findRecord } from '@ember-data-mirror/rest/request';
39
+ *
40
+ * const data = await store.request(findRecord('person', '1'));
41
+ * ```
42
+ *
43
+ * **With Options**
44
+ *
45
+ * ```ts
46
+ * import { findRecord } from '@ember-data-mirror/rest/request';
47
+ *
48
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] });
49
+ * const data = await store.request(options);
50
+ * ```
51
+ *
52
+ * **With an Identifier**
53
+ *
54
+ * ```ts
55
+ * import { findRecord } from '@ember-data-mirror/rest/request';
56
+ *
57
+ * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
58
+ * const data = await store.request(options);
59
+ * ```
60
+ *
61
+ * **Supplying Options to Modify the Request Behavior**
62
+ *
63
+ * The following options are supported:
64
+ *
65
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
66
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
67
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
68
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
69
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
70
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
71
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
72
+ * defaulting to `false` if none is configured.
73
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
74
+ *
75
+ * ```ts
76
+ * import { findRecord } from '@ember-data-mirror/rest/request';
77
+ *
78
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
79
+ * const data = await store.request(options);
80
+ * ```
81
+ *
82
+ * @method findRecord
83
+ * @public
84
+ * @static
85
+ * @for @ember-data-mirror/rest/request
86
+ * @param identifier
87
+ * @param options
88
+ */
89
+
90
+ function findRecord(arg1, arg2, arg3) {
91
+ const identifier = typeof arg1 === 'string' ? {
92
+ type: arg1,
93
+ id: arg2
94
+ } : arg1;
95
+ const options = (typeof arg1 === 'string' ? arg3 : arg2) || {};
96
+ const cacheOptions = extractCacheOptions(options);
97
+ const urlOptions = {
98
+ identifier,
99
+ op: 'findRecord',
100
+ resourcePath: pluralize(camelize(identifier.type))
101
+ };
102
+ copyForwardUrlOptions(urlOptions, options);
103
+ const url = buildBaseURL(urlOptions);
104
+ const headers = new Headers();
105
+ headers.append('Accept', 'application/json;charset=utf-8');
106
+ return {
107
+ url: options.include?.length ? `${url}?${buildQueryParams({
108
+ include: options.include
109
+ }, options.urlParamsSettings)}` : url,
110
+ method: 'GET',
111
+ headers,
112
+ cacheOptions,
113
+ op: 'findRecord',
114
+ records: [identifier]
115
+ };
116
+ }
117
+
118
+ /**
119
+ * @module @ember-data-mirror/rest/request
120
+ */
121
+
122
+ /**
123
+ * Builds request options to query for resources, usually by a primary
124
+ * type, configured for the url and header expectations of most REST APIs.
125
+ *
126
+ * **Basic Usage**
127
+ *
128
+ * ```ts
129
+ * import { query } from '@ember-data-mirror/rest/request';
130
+ *
131
+ * const data = await store.request(query('person'));
132
+ * ```
133
+ *
134
+ * **With Query Params**
135
+ *
136
+ * ```ts
137
+ * import { query } from '@ember-data-mirror/rest/request';
138
+ *
139
+ * const options = query('person', { include: ['pets', 'friends'] });
140
+ * const data = await store.request(options);
141
+ * ```
142
+ *
143
+ * **Supplying Options to Modify the Request Behavior**
144
+ *
145
+ * The following options are supported:
146
+ *
147
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
148
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
149
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
150
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
151
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
152
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
153
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
154
+ * defaulting to `false` if none is configured.
155
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
156
+ *
157
+ * ```ts
158
+ * import { query } from '@ember-data-mirror/rest/request';
159
+ *
160
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
161
+ * const data = await store.request(options);
162
+ * ```
163
+ *
164
+ * @method query
165
+ * @public
166
+ * @static
167
+ * @for @ember-data-mirror/rest/request
168
+ * @param identifier
169
+ * @param query
170
+ * @param options
171
+ */
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 CachePolicy, 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 CachePolicy,
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
+
254
+ function deleteRecord(record, options = {}) {
255
+ const identifier = recordIdentifierFor(record);
256
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
257
+ if (!test) {
258
+ throw new Error(`Expected to be given a record instance`);
259
+ }
260
+ })(identifier) : {};
261
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
262
+ if (!test) {
263
+ throw new Error(`Cannot delete a record that does not have an associated type and id.`);
264
+ }
265
+ })(isExisting(identifier)) : {};
266
+ const urlOptions = {
267
+ identifier: identifier,
268
+ op: 'deleteRecord',
269
+ resourcePath: pluralize(camelize(identifier.type))
270
+ };
271
+ copyForwardUrlOptions(urlOptions, options);
272
+ const url = buildBaseURL(urlOptions);
273
+ const headers = new Headers();
274
+ headers.append('Accept', 'application/json;charset=utf-8');
275
+ return {
276
+ url,
277
+ method: 'DELETE',
278
+ headers,
279
+ op: 'deleteRecord',
280
+ data: {
281
+ record: identifier
282
+ },
283
+ records: [identifier]
284
+ };
285
+ }
286
+
287
+ /**
288
+ * Builds request options to create new record for resources,
289
+ * configured for the url, method and header expectations of most REST APIs.
290
+ *
291
+ * **Basic Usage**
292
+ *
293
+ * ```ts
294
+ * import { createRecord } from '@ember-data-mirror/rest/request';
295
+ *
296
+ * const person = store.createRecord('person', { name: 'Ted' });
297
+ * const data = await store.request(createRecord(person));
298
+ * ```
299
+ *
300
+ * **Supplying Options to Modify the Request Behavior**
301
+ *
302
+ * The following options are supported:
303
+ *
304
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
305
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
306
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
307
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
308
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
309
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
310
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
311
+ * defaulting to `false` if none is configured.
312
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
313
+ *
314
+ * ```ts
315
+ * import { createRecord } from '@ember-data-mirror/rest/request';
316
+ *
317
+ * const person = store.createRecord('person', { name: 'Ted' });
318
+ * const options = createRecord(person, { namespace: 'api/v1' });
319
+ * const data = await store.request(options);
320
+ * ```
321
+ *
322
+ * @method createRecord
323
+ * @public
324
+ * @static
325
+ * @for @ember-data-mirror/rest/request
326
+ * @param record
327
+ * @param options
328
+ */
329
+
330
+ function createRecord(record, options = {}) {
331
+ const identifier = recordIdentifierFor(record);
332
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
333
+ if (!test) {
334
+ throw new Error(`Expected to be given a record instance`);
335
+ }
336
+ })(identifier) : {};
337
+ const urlOptions = {
338
+ identifier: identifier,
339
+ op: 'createRecord',
340
+ resourcePath: pluralize(camelize(identifier.type))
341
+ };
342
+ copyForwardUrlOptions(urlOptions, options);
343
+ const url = buildBaseURL(urlOptions);
344
+ const headers = new Headers();
345
+ headers.append('Accept', 'application/json;charset=utf-8');
346
+ return {
347
+ url,
348
+ method: 'POST',
349
+ headers,
350
+ op: 'createRecord',
351
+ data: {
352
+ record: identifier
353
+ },
354
+ records: [identifier]
355
+ };
356
+ }
357
+
358
+ /**
359
+ * Builds request options to update existing record for resources,
360
+ * configured for the url, method and header expectations of most REST APIs.
361
+ *
362
+ * **Basic Usage**
363
+ *
364
+ * ```ts
365
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
366
+ *
367
+ * const person = store.peekRecord('person', '1');
368
+ * person.name = 'Chris';
369
+ * const data = await store.request(updateRecord(person));
370
+ * ```
371
+ *
372
+ * **Supplying Options to Modify the Request Behavior**
373
+ *
374
+ * The following options are supported:
375
+ *
376
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
377
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
378
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
379
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
380
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
381
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
382
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
383
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
384
+ * defaulting to `false` if none is configured.
385
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
386
+ *
387
+ * ```ts
388
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
389
+ *
390
+ * const person = store.peekRecord('person', '1');
391
+ * person.name = 'Chris';
392
+ * const options = updateRecord(person, { patch: true });
393
+ * const data = await store.request(options);
394
+ * ```
395
+ *
396
+ * @method updateRecord
397
+ * @public
398
+ * @static
399
+ * @for @ember-data-mirror/rest/request
400
+ * @param record
401
+ * @param options
402
+ */
403
+
404
+ function updateRecord(record, options = {}) {
405
+ const identifier = recordIdentifierFor(record);
406
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
407
+ if (!test) {
408
+ throw new Error(`Expected to be given a record instance`);
409
+ }
410
+ })(identifier) : {};
411
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
412
+ if (!test) {
413
+ throw new Error(`Cannot update a record that does not have an associated type and id.`);
414
+ }
415
+ })(isExisting(identifier)) : {};
416
+ const urlOptions = {
417
+ identifier: identifier,
418
+ op: 'updateRecord',
419
+ resourcePath: pluralize(camelize(identifier.type))
420
+ };
421
+ copyForwardUrlOptions(urlOptions, options);
422
+ const url = buildBaseURL(urlOptions);
423
+ const headers = new Headers();
424
+ headers.append('Accept', 'application/json;charset=utf-8');
425
+ return {
426
+ url,
427
+ method: options.patch ? 'PATCH' : 'PUT',
428
+ headers,
429
+ op: 'updateRecord',
430
+ data: {
431
+ record: identifier
432
+ },
433
+ records: [identifier]
434
+ };
435
+ }
436
+ 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/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 { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '@ember-data-mirror/request-utils';\nimport { camelize, pluralize } from '@ember-data-mirror/request-utils/string';\nimport type { TypeFromInstance } from '@warp-drive/core-types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core-types/request';\nimport type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document';\n\nimport { copyForwardUrlOptions, extractCacheOptions } from './-utils';\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 CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@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 type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & { data: T };\n\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<T, FindRecordResultDocument<T>>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions<T>\n): FindRecordRequestOptions<T, FindRecordResultDocument<T>>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord<T>(\n arg1: TypeFromInstance<T> | RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions<T, FindRecordResultDocument<T>> {\n const identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>> =\n 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 { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '@ember-data-mirror/request-utils';\nimport { camelize, pluralize } from '@ember-data-mirror/request-utils/string';\nimport type { QueryParamsSource } from '@warp-drive/core-types/params';\nimport type { TypeFromInstance } from '@warp-drive/core-types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core-types/request';\nimport type { CollectionResourceDataDocument } from '@warp-drive/core-types/spec/document';\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 CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@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<T>(\n type: TypeFromInstance<T>,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<T, CollectionResourceDataDocument<T>>;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\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 {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '@ember-data-mirror/request-utils';\nimport { camelize, pluralize } from '@ember-data-mirror/request-utils/string';\nimport { recordIdentifierFor } from '@ember-data-mirror/store';\nimport { assert } from '@warp-drive/build-config/macros';\nimport type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/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 CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@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<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(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 CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@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<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(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 CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@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<T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(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","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","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,UAAU,CAACI,YAAY,GAAGH,OAAO,CAACG,YAAY,CAAA;AAChD,GAAA;AACF,CAAA;AAEO,SAASC,mBAAmBA,CAACJ,OAAkC,EAAE;EACtE,MAAMK,YAA0B,GAAG,EAAE,CAAA;EACrC,IAAI,QAAQ,IAAIL,OAAO,EAAE;AACvBK,IAAAA,YAAY,CAACC,MAAM,GAAGN,OAAO,CAACM,MAAM,CAAA;AACtC,GAAA;EACA,IAAI,kBAAkB,IAAIN,OAAO,EAAE;AACjCK,IAAAA,YAAY,CAACE,gBAAgB,GAAGP,OAAO,CAACO,gBAAgB,CAAA;AAC1D,GAAA;AACA,EAAA,OAAOF,YAAY,CAAA;AACrB;;ACxBA;AACA;A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KACT;IACDgB,OAAO,EAAE,CAAChB,UAAU,CAAA;GACrB,CAAA;AACH;;;;"}
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@ember-data-mirror/rest",
3
+ "description": "REST Format Support for EmberData",
4
+ "version": "5.3.4",
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.20.3"
17
+ },
18
+ "keywords": [
19
+ "ember-addon"
20
+ ],
21
+ "volta": {
22
+ "extends": "../../../../../../package.json"
23
+ },
24
+ "dependencies": {
25
+ "@embroider/macros": "^1.16.1",
26
+ "@warp-drive/build-config": "0.0.0-beta.2"
27
+ },
28
+ "peerDependencies": {
29
+ "@ember-data-mirror/request-utils": "5.3.4",
30
+ "@ember-data-mirror/store": "^4.12.0 || ^5.0.0",
31
+ "@warp-drive/core-types": "0.0.0-beta.7"
32
+ },
33
+ "files": [
34
+ "unstable-preview-types",
35
+ "addon-main.cjs",
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE.md",
39
+ "ember-data-mirror-logo-dark.svg",
40
+ "ember-data-mirror-logo-light.svg"
41
+ ],
42
+ "exports": {
43
+ "./*": {
44
+ "default": "./dist/*.js"
45
+ }
46
+ },
47
+ "scripts": {
48
+ "lint": "eslint . --quiet --cache --cache-strategy=content --report-unused-disable-directives",
49
+ "build:pkg": "vite build;",
50
+ "sync-hardlinks": "bun run sync-dependencies-meta-injected"
51
+ },
52
+ "ember-addon": {
53
+ "main": "addon-main.cjs",
54
+ "type": "addon",
55
+ "version": 2
56
+ },
57
+ "devDependencies": {
58
+ "@babel/core": "^7.24.5",
59
+ "@babel/plugin-transform-typescript": "^7.24.5",
60
+ "@babel/preset-env": "^7.24.5",
61
+ "@babel/preset-typescript": "^7.24.1",
62
+ "@ember-data-mirror/request": "5.3.4",
63
+ "@ember-data-mirror/request-utils": "5.3.4",
64
+ "@ember-data-mirror/store": "5.3.4",
65
+ "@ember-data-mirror/tracking": "5.3.4",
66
+ "@glimmer/component": "^1.1.2",
67
+ "@warp-drive/core-types": "0.0.0-beta.7",
68
+ "@warp-drive/internal-config": "5.3.4",
69
+ "ember-source": "~5.8.0",
70
+ "pnpm-sync-dependencies-meta-injected": "0.0.14",
71
+ "typescript": "^5.4.5",
72
+ "vite": "^5.2.11"
73
+ },
74
+ "ember": {
75
+ "edition": "octane"
76
+ },
77
+ "dependenciesMeta": {
78
+ "@warp-drive/core-types": {
79
+ "injected": true
80
+ },
81
+ "@ember-data-mirror/store": {
82
+ "injected": true
83
+ },
84
+ "@ember-data-mirror/request-utils": {
85
+ "injected": true
86
+ },
87
+ "@ember-data-mirror/request": {
88
+ "injected": true
89
+ },
90
+ "@ember-data-mirror/tracking": {
91
+ "injected": true
92
+ },
93
+ "@warp-drive/build-config": {
94
+ "injected": true
95
+ }
96
+ }
97
+ }
@@ -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/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,71 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/find-record' {
2
+ import type { TypeFromInstance } from '@warp-drive/core-types/record';
3
+ import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from '@warp-drive/core-types/request';
4
+ import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document';
5
+ /**
6
+ * Builds request options to fetch a single resource by a known id or identifier
7
+ * configured for the url and header expectations of most REST APIs.
8
+ *
9
+ * **Basic Usage**
10
+ *
11
+ * ```ts
12
+ * import { findRecord } from '@ember-data-mirror/rest/request';
13
+ *
14
+ * const data = await store.request(findRecord('person', '1'));
15
+ * ```
16
+ *
17
+ * **With Options**
18
+ *
19
+ * ```ts
20
+ * import { findRecord } from '@ember-data-mirror/rest/request';
21
+ *
22
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] });
23
+ * const data = await store.request(options);
24
+ * ```
25
+ *
26
+ * **With an Identifier**
27
+ *
28
+ * ```ts
29
+ * import { findRecord } from '@ember-data-mirror/rest/request';
30
+ *
31
+ * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
32
+ * const data = await store.request(options);
33
+ * ```
34
+ *
35
+ * **Supplying Options to Modify the Request Behavior**
36
+ *
37
+ * The following options are supported:
38
+ *
39
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
40
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
41
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
42
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
43
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
44
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
45
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
46
+ * defaulting to `false` if none is configured.
47
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
48
+ *
49
+ * ```ts
50
+ * import { findRecord } from '@ember-data-mirror/rest/request';
51
+ *
52
+ * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
53
+ * const data = await store.request(options);
54
+ * ```
55
+ *
56
+ * @method findRecord
57
+ * @public
58
+ * @static
59
+ * @for @ember-data-mirror/rest/request
60
+ * @param identifier
61
+ * @param options
62
+ */
63
+ export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & {
64
+ data: T;
65
+ };
66
+ export function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<T, FindRecordResultDocument<T>>;
67
+ export function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
68
+ export function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<T, FindRecordResultDocument<T>>;
69
+ export function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
70
+ }
71
+ //# 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":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAIvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAEpG,wBAAgB,UAAU,CAAC,CAAC,EAC1B,UAAU,EAAE,4BAA4B,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAC7D,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CACxB,UAAU,EAAE,4BAA4B,EACxC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,wBAAwB,CAAC;AAC5B,wBAAgB,UAAU,CAAC,CAAC,EAC1B,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,wBAAwB,CAAC"}
@@ -0,0 +1,59 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/query' {
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
+ import type { CollectionResourceDataDocument } from '@warp-drive/core-types/spec/document';
6
+ /**
7
+ * Builds request options to query for resources, usually by a primary
8
+ * type, configured for the url and header expectations of most REST APIs.
9
+ *
10
+ * **Basic Usage**
11
+ *
12
+ * ```ts
13
+ * import { query } from '@ember-data-mirror/rest/request';
14
+ *
15
+ * const data = await store.request(query('person'));
16
+ * ```
17
+ *
18
+ * **With Query Params**
19
+ *
20
+ * ```ts
21
+ * import { query } from '@ember-data-mirror/rest/request';
22
+ *
23
+ * const options = query('person', { include: ['pets', 'friends'] });
24
+ * const data = await store.request(options);
25
+ * ```
26
+ *
27
+ * **Supplying Options to Modify the Request Behavior**
28
+ *
29
+ * The following options are supported:
30
+ *
31
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
32
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
33
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
34
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
35
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
36
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
37
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
38
+ * defaulting to `false` if none is configured.
39
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
40
+ *
41
+ * ```ts
42
+ * import { query } from '@ember-data-mirror/rest/request';
43
+ *
44
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
45
+ * const data = await store.request(options);
46
+ * ```
47
+ *
48
+ * @method query
49
+ * @public
50
+ * @static
51
+ * @for @ember-data-mirror/rest/request
52
+ * @param identifier
53
+ * @param query
54
+ * @param options
55
+ */
56
+ export function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<T, CollectionResourceDataDocument<T>>;
57
+ export function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
58
+ }
59
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/-private/builders/query.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrG,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAI3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAEzB,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC,CAAC,EAAE,8BAA8B,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EAEZ,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC"}
@@ -0,0 +1,153 @@
1
+ declare module '@ember-data-mirror/rest/-private/builders/save-record' {
2
+ import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from '@warp-drive/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 CachePolicy, 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 CachePolicy,
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<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
56
+ export function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
57
+ /**
58
+ * Builds request options to create new record for resources,
59
+ * configured for the url, method and header expectations of most REST APIs.
60
+ *
61
+ * **Basic Usage**
62
+ *
63
+ * ```ts
64
+ * import { createRecord } from '@ember-data-mirror/rest/request';
65
+ *
66
+ * const person = store.createRecord('person', { name: 'Ted' });
67
+ * const data = await store.request(createRecord(person));
68
+ * ```
69
+ *
70
+ * **Supplying Options to Modify the Request Behavior**
71
+ *
72
+ * The following options are supported:
73
+ *
74
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
75
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
76
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
77
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
78
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
79
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
80
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
81
+ * defaulting to `false` if none is configured.
82
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
83
+ *
84
+ * ```ts
85
+ * import { createRecord } from '@ember-data-mirror/rest/request';
86
+ *
87
+ * const person = store.createRecord('person', { name: 'Ted' });
88
+ * const options = createRecord(person, { namespace: 'api/v1' });
89
+ * const data = await store.request(options);
90
+ * ```
91
+ *
92
+ * @method createRecord
93
+ * @public
94
+ * @static
95
+ * @for @ember-data-mirror/rest/request
96
+ * @param record
97
+ * @param options
98
+ */
99
+ export function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
100
+ export function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
101
+ /**
102
+ * Builds request options to update existing record for resources,
103
+ * configured for the url, method and header expectations of most REST APIs.
104
+ *
105
+ * **Basic Usage**
106
+ *
107
+ * ```ts
108
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
109
+ *
110
+ * const person = store.peekRecord('person', '1');
111
+ * person.name = 'Chris';
112
+ * const data = await store.request(updateRecord(person));
113
+ * ```
114
+ *
115
+ * **Supplying Options to Modify the Request Behavior**
116
+ *
117
+ * The following options are supported:
118
+ *
119
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
120
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
121
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
122
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
123
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
124
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
125
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
126
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
127
+ * defaulting to `false` if none is configured.
128
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
129
+ *
130
+ * ```ts
131
+ * import { updateRecord } from '@ember-data-mirror/rest/request';
132
+ *
133
+ * const person = store.peekRecord('person', '1');
134
+ * person.name = 'Chris';
135
+ * const options = updateRecord(person, { patch: true });
136
+ * const data = await store.request(options);
137
+ * ```
138
+ *
139
+ * @method updateRecord
140
+ * @public
141
+ * @static
142
+ * @for @ember-data-mirror/rest/request
143
+ * @param record
144
+ * @param options
145
+ */
146
+ export function updateRecord<T>(record: T, options?: ConstrainedRequestOptions & {
147
+ patch?: boolean;
148
+ }): UpdateRequestOptions<T>;
149
+ export function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
150
+ patch?: boolean;
151
+ }): UpdateRequestOptions;
152
+ }
153
+ //# 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":"AAUA,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AAQxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC;AA8BzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC;AA6BzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAC3B,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /// <reference path="./request.d.ts" />
2
+ /// <reference path="./-private/builders/-utils.d.ts" />
3
+ /// <reference path="./-private/builders/find-record.d.ts" />
4
+ /// <reference path="./-private/builders/query.d.ts" />
5
+ /// <reference path="./-private/builders/save-record.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"}