@warp-drive/legacy 5.8.0-alpha.40 → 5.8.0-alpha.41
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/declarations/adapter/error.d.ts +2 -2
- package/declarations/adapter/rest.d.ts +21 -104
- package/declarations/adapter.d.ts +2 -2
- package/declarations/model/-private/model.d.ts +10 -51
- package/declarations/model/-private/promise-many-array.d.ts +0 -18
- package/declarations/model/-private/references/belongs-to.d.ts +14 -24
- package/declarations/model/-private/references/has-many.d.ts +11 -13
- package/declarations/serializer/json-api.d.ts +4 -3
- package/declarations/serializer/json.d.ts +2 -2
- package/dist/{-private-B1pSSN52.js → -private-BG3bMiKp.js} +2 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +2 -2
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +33 -117
- package/dist/adapter.js +2 -2
- package/dist/compat/-private.js +1 -1
- package/dist/compat.js +4 -3
- package/dist/{errors-CIGPcDvd.js → errors-Cz5KrzBk.js} +29 -58
- package/dist/{hooks-QqRnX108.js → hooks-D6diaM34.js} +1 -1
- package/dist/index.js +3 -3
- package/dist/{json-BNrV8EYG.js → json-ChdEfB0X.js} +6 -19
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +7 -5
- package/dist/model.js +3 -3
- package/dist/{schema-provider-g5MfTj8n.js → schema-provider-DJCV_6AF.js} +34 -77
- package/dist/{serialize-into-hash-BnYvPex3.js → serialize-into-hash-DPZYoF-i.js} +1 -1
- package/dist/serializer/json-api.js +2 -2
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +1 -1
- package/dist/store.js +2 -1
- package/dist/unpkg/{dev-deprecated/-private-DbaSCSym.js → dev/-private-DtjBbEgy.js} +2 -1
- package/dist/unpkg/dev/adapter/-private.js +1 -1
- package/dist/unpkg/dev/adapter/error.js +2 -2
- package/dist/unpkg/dev/adapter/json-api.js +1 -1
- package/dist/unpkg/dev/adapter/rest.js +33 -117
- package/dist/unpkg/dev/adapter.js +2 -2
- package/dist/unpkg/dev/compat/-private.js +1 -1
- package/dist/unpkg/dev/compat.js +4 -3
- package/dist/unpkg/dev/{errors-DD96TBEs.js → errors-DmGGJr3T.js} +29 -58
- package/dist/unpkg/dev/{hooks-CqWjNWeL.js → hooks-CkYiE6Ud.js} +1 -1
- package/dist/unpkg/dev/index.js +3 -3
- package/dist/unpkg/{dev-deprecated/json-CCU-ZQ4b.js → dev/json-Cu1LNgmQ.js} +6 -19
- package/dist/unpkg/dev/model/-private.js +1 -1
- package/dist/unpkg/dev/model/migration-support.js +7 -5
- package/dist/unpkg/dev/model.js +3 -3
- package/dist/unpkg/dev/{schema-provider-B8jiJOYC.js → schema-provider-DDVYxmUV.js} +34 -77
- package/dist/unpkg/dev/{serialize-into-hash-CPAZXrQU.js → serialize-into-hash-B2xDbuo5.js} +1 -1
- package/dist/unpkg/dev/serializer/json-api.js +6 -5
- package/dist/unpkg/dev/serializer/json.js +1 -1
- package/dist/unpkg/dev/serializer/rest.js +1 -1
- package/dist/unpkg/dev/store.js +2 -1
- package/dist/unpkg/{dev/-private-DbaSCSym.js → dev-deprecated/-private-DtjBbEgy.js} +2 -1
- package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/adapter/error.js +2 -2
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +1 -1
- package/dist/unpkg/dev-deprecated/adapter/rest.js +33 -117
- package/dist/unpkg/dev-deprecated/adapter.js +2 -2
- package/dist/unpkg/dev-deprecated/compat/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/compat.js +4 -3
- package/dist/unpkg/dev-deprecated/{errors-DEnabIZj.js → errors-Spt6ubMd.js} +29 -58
- package/dist/unpkg/dev-deprecated/{hooks-CAll-Ets.js → hooks-DOXegvhL.js} +1 -1
- package/dist/unpkg/dev-deprecated/index.js +3 -3
- package/dist/unpkg/{dev/json-CCU-ZQ4b.js → dev-deprecated/json-Cu1LNgmQ.js} +6 -19
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/model/migration-support.js +7 -5
- package/dist/unpkg/dev-deprecated/model.js +3 -3
- package/dist/unpkg/dev-deprecated/{schema-provider-k2qXQTBg.js → schema-provider-BP6_8N-V.js} +34 -77
- package/dist/unpkg/dev-deprecated/{serialize-into-hash-CPAZXrQU.js → serialize-into-hash-B2xDbuo5.js} +1 -1
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +6 -5
- package/dist/unpkg/dev-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/dev-deprecated/serializer/rest.js +1 -1
- package/dist/unpkg/dev-deprecated/store.js +2 -1
- package/dist/unpkg/{prod-deprecated/-private-Cvf_97EG.js → prod/-private-BdyZaGEh.js} +1 -0
- package/dist/unpkg/prod/adapter/-private.js +1 -1
- package/dist/unpkg/prod/adapter/error.js +2 -2
- package/dist/unpkg/prod/adapter/json-api.js +1 -1
- package/dist/unpkg/prod/adapter/rest.js +33 -117
- package/dist/unpkg/prod/adapter.js +2 -2
- package/dist/unpkg/prod/compat/-private.js +1 -1
- package/dist/unpkg/prod/compat.js +2 -1
- package/dist/unpkg/prod/{errors-CXnfnBfQ.js → errors-BGVFCBmi.js} +29 -58
- package/dist/unpkg/prod/{hooks-DvyWhLNg.js → hooks-BztVA_x0.js} +1 -1
- package/dist/unpkg/prod/index.js +3 -3
- package/dist/unpkg/prod/{json-BYrUP8ao.js → json-BWrZ5546.js} +6 -19
- package/dist/unpkg/prod/model/-private.js +1 -1
- package/dist/unpkg/prod/model/migration-support.js +7 -5
- package/dist/unpkg/prod/model.js +3 -3
- package/dist/unpkg/prod/{schema-provider-CHujJvA9.js → schema-provider-DJtD_8jZ.js} +34 -77
- package/dist/unpkg/{prod-deprecated/serialize-into-hash-DYU2egXl.js → prod/serialize-into-hash-DGlzQteF.js} +1 -1
- package/dist/unpkg/prod/serializer/json-api.js +6 -5
- package/dist/unpkg/prod/serializer/json.js +1 -1
- package/dist/unpkg/prod/serializer/rest.js +1 -1
- package/dist/unpkg/prod/store.js +2 -1
- package/dist/unpkg/{prod/-private-Cvf_97EG.js → prod-deprecated/-private-BdyZaGEh.js} +1 -0
- package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/adapter/error.js +2 -2
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +1 -1
- package/dist/unpkg/prod-deprecated/adapter/rest.js +33 -117
- package/dist/unpkg/prod-deprecated/adapter.js +2 -2
- package/dist/unpkg/prod-deprecated/compat/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/compat.js +2 -1
- package/dist/unpkg/prod-deprecated/{errors-CG1SPYVg.js → errors-CdDaK81x.js} +29 -58
- package/dist/unpkg/prod-deprecated/{hooks-BIUBiNGR.js → hooks-yId87yyG.js} +1 -1
- package/dist/unpkg/prod-deprecated/index.js +3 -3
- package/dist/unpkg/prod-deprecated/{json-BYrUP8ao.js → json-BWrZ5546.js} +6 -19
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/model/migration-support.js +7 -5
- package/dist/unpkg/prod-deprecated/model.js +3 -3
- package/dist/unpkg/prod-deprecated/{schema-provider-BJ4TWnZf.js → schema-provider-CjX55uSY.js} +34 -77
- package/dist/unpkg/{prod/serialize-into-hash-DYU2egXl.js → prod-deprecated/serialize-into-hash-DGlzQteF.js} +1 -1
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +6 -5
- package/dist/unpkg/prod-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/prod-deprecated/serializer/rest.js +1 -1
- package/dist/unpkg/prod-deprecated/store.js +2 -1
- package/package.json +6 -6
package/dist/adapter/rest.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getOwner } from '@ember/application';
|
|
|
2
2
|
import { warn } from '@ember/debug';
|
|
3
3
|
import { computed } from '@ember/object';
|
|
4
4
|
import { Adapter, BuildURLMixin } from '../adapter.js';
|
|
5
|
-
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-
|
|
5
|
+
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-DPZYoF-i.js";
|
|
6
6
|
import { InvalidError, ServerError, ConflictError, NotFoundError, ForbiddenError, UnauthorizedError, AdapterError, TimeoutError, AbortError } from './error.js';
|
|
7
7
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
8
8
|
import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
|
|
@@ -89,7 +89,7 @@ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
|
89
89
|
Note that the object root can be pluralized for both a single-object response
|
|
90
90
|
and an array response: the REST adapter is not strict on this. Further, if the
|
|
91
91
|
HTTP server responds to a `GET` request to `/posts/1` (e.g. the response to a
|
|
92
|
-
`findRecord` query) with more than one object in the array,
|
|
92
|
+
`findRecord` query) with more than one object in the array, WarpDrive will
|
|
93
93
|
only display the object with the matching ID.
|
|
94
94
|
|
|
95
95
|
### Conventional Names
|
|
@@ -150,7 +150,7 @@ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
|
150
150
|
|
|
151
151
|
If the records in the relationship are not known when the response
|
|
152
152
|
is serialized it's also possible to represent the relationship as a
|
|
153
|
-
URL using the `links` key in the response.
|
|
153
|
+
URL using the `links` key in the response. WarpDrive will fetch
|
|
154
154
|
this URL to resolve the relationship when it is accessed for the
|
|
155
155
|
first time.
|
|
156
156
|
|
|
@@ -233,17 +233,12 @@ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
|
233
233
|
}
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
@class RESTAdapter
|
|
237
236
|
@public
|
|
238
|
-
@constructor
|
|
239
|
-
@uses BuildURLMixin
|
|
240
237
|
*/
|
|
241
238
|
class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
242
239
|
/**
|
|
243
240
|
This property allows ajax to still be used instead when `false`.
|
|
244
|
-
@
|
|
245
|
-
@type {Boolean}
|
|
246
|
-
@default true
|
|
241
|
+
@default true
|
|
247
242
|
@public
|
|
248
243
|
*/
|
|
249
244
|
useFetch = true;
|
|
@@ -291,9 +286,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
291
286
|
}
|
|
292
287
|
}
|
|
293
288
|
```
|
|
294
|
-
@
|
|
295
|
-
@return {Object}
|
|
296
|
-
@public
|
|
289
|
+
@public
|
|
297
290
|
*/
|
|
298
291
|
sortQueryParams(obj) {
|
|
299
292
|
const keys = Object.keys(obj);
|
|
@@ -342,9 +335,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
342
335
|
will also send a request to: `GET /comments?ids[]=1&ids[]=2`
|
|
343
336
|
Note: Requests coalescing rely on URL building strategy. So if you override `buildURL` in your app
|
|
344
337
|
`groupRecordsForFindMany` more likely should be overridden as well in order for coalescing to work.
|
|
345
|
-
@
|
|
346
|
-
@public
|
|
347
|
-
@type {Boolean}
|
|
338
|
+
@public
|
|
348
339
|
*/
|
|
349
340
|
get coalesceFindRequests() {
|
|
350
341
|
const coalesceFindRequests = this._coalesceFindRequests;
|
|
@@ -367,9 +358,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
367
358
|
}
|
|
368
359
|
```
|
|
369
360
|
Requests for the `Post` model would now target `/api/1/post/`.
|
|
370
|
-
@
|
|
371
|
-
@public
|
|
372
|
-
@type {String}
|
|
361
|
+
@public
|
|
373
362
|
*/
|
|
374
363
|
|
|
375
364
|
/**
|
|
@@ -381,15 +370,13 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
381
370
|
}
|
|
382
371
|
```
|
|
383
372
|
Requests for the `Post` model would now target `https://api.example.com/post/`.
|
|
384
|
-
@
|
|
385
|
-
@public
|
|
386
|
-
@type {String}
|
|
373
|
+
@public
|
|
387
374
|
*/
|
|
388
375
|
|
|
389
376
|
/**
|
|
390
377
|
Some APIs require HTTP headers, e.g. to provide an API
|
|
391
378
|
key. Arbitrary headers can be set as key/value pairs on the
|
|
392
|
-
`RESTAdapter`'s `headers` object and
|
|
379
|
+
`RESTAdapter`'s `headers` object and WarpDrive will send them
|
|
393
380
|
along with each ajax request..
|
|
394
381
|
```js [app/adapters/application.js]
|
|
395
382
|
import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
|
|
@@ -402,9 +389,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
402
389
|
}
|
|
403
390
|
}
|
|
404
391
|
```
|
|
405
|
-
@
|
|
406
|
-
@public
|
|
407
|
-
@type {Object}
|
|
392
|
+
@public
|
|
408
393
|
*/
|
|
409
394
|
|
|
410
395
|
/**
|
|
@@ -415,11 +400,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
415
400
|
This method performs an HTTP `GET` request with the id provided as part of the query string.
|
|
416
401
|
@since 1.13.0
|
|
417
402
|
@public
|
|
418
|
-
@param {Store} store
|
|
419
|
-
@param {Model} type
|
|
420
|
-
@param {String} id
|
|
421
|
-
@param {Snapshot} snapshot
|
|
422
|
-
@return {Promise} promise
|
|
423
403
|
*/
|
|
424
404
|
findRecord(store, type, id, snapshot) {
|
|
425
405
|
const url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
|
|
@@ -435,18 +415,10 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
435
415
|
The `findAll` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
|
|
436
416
|
promise for the resulting payload.
|
|
437
417
|
@public
|
|
438
|
-
@param {Store} store
|
|
439
|
-
@param {Model} type
|
|
440
|
-
@param {undefined} neverSet a value is never provided to this argument
|
|
441
|
-
@param {SnapshotRecordArray} snapshotRecordArray
|
|
442
|
-
@return {Promise} promise
|
|
443
418
|
*/
|
|
444
|
-
findAll(store, type,
|
|
419
|
+
findAll(store, type, neverUsed, snapshotRecordArray) {
|
|
445
420
|
const query = this.buildQuery(snapshotRecordArray);
|
|
446
421
|
const url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll');
|
|
447
|
-
if (sinceToken) {
|
|
448
|
-
query.since = sinceToken;
|
|
449
|
-
}
|
|
450
422
|
return this.ajax(url, 'GET', {
|
|
451
423
|
data: query
|
|
452
424
|
});
|
|
@@ -461,12 +433,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
461
433
|
The `query` argument is a simple JavaScript object that will be passed directly
|
|
462
434
|
to the server as parameters.
|
|
463
435
|
@public
|
|
464
|
-
@param {Store} store
|
|
465
|
-
@param {Model} type
|
|
466
|
-
@param {Object} query
|
|
467
|
-
@param {Collection} recordArray
|
|
468
|
-
@param {Object} adapterOptions
|
|
469
|
-
@return {Promise} promise
|
|
470
436
|
*/
|
|
471
437
|
query(store, type, query) {
|
|
472
438
|
const url = this.buildURL(type.modelName, null, null, 'query', query);
|
|
@@ -488,11 +454,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
488
454
|
to the server as parameters.
|
|
489
455
|
@since 1.13.0
|
|
490
456
|
@public
|
|
491
|
-
@param {Store} store
|
|
492
|
-
@param {Model} type
|
|
493
|
-
@param {Object} query
|
|
494
|
-
@param {Object} adapterOptions
|
|
495
|
-
@return {Promise} promise
|
|
496
457
|
*/
|
|
497
458
|
queryRecord(store, type, query, adapterOptions) {
|
|
498
459
|
const url = this.buildURL(type.modelName, null, null, 'queryRecord', query);
|
|
@@ -524,11 +485,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
524
485
|
The `findMany` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
|
|
525
486
|
promise for the resulting payload.
|
|
526
487
|
@public
|
|
527
|
-
@param {Store} store
|
|
528
|
-
@param {Model} type
|
|
529
|
-
@param {Array} ids
|
|
530
|
-
@param {Array} snapshots
|
|
531
|
-
@return {Promise} promise
|
|
532
488
|
*/
|
|
533
489
|
findMany(store, type, ids, snapshots) {
|
|
534
490
|
const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
|
|
@@ -560,11 +516,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
560
516
|
* Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
|
|
561
517
|
* Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
|
|
562
518
|
@public
|
|
563
|
-
@param {Store} store
|
|
564
|
-
@param {Snapshot} snapshot
|
|
565
|
-
@param {String} url
|
|
566
|
-
@param {Object} relationship meta object describing the relationship
|
|
567
|
-
@return {Promise} promise
|
|
568
519
|
*/
|
|
569
520
|
findHasMany(store, snapshot, url, relationship) {
|
|
570
521
|
const id = snapshot.id;
|
|
@@ -620,10 +571,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
620
571
|
See `serialize` for information on how to customize the serialized form
|
|
621
572
|
of a record.
|
|
622
573
|
@public
|
|
623
|
-
@param {Store} store
|
|
624
|
-
@param {Model} type
|
|
625
|
-
@param {Snapshot} snapshot
|
|
626
|
-
@return {Promise} promise
|
|
627
574
|
*/
|
|
628
575
|
createRecord(store, type, snapshot) {
|
|
629
576
|
const url = this.buildURL(type.modelName, null, snapshot, 'createRecord');
|
|
@@ -641,10 +588,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
641
588
|
See `serialize` for information on how to customize the serialized form
|
|
642
589
|
of a record.
|
|
643
590
|
@public
|
|
644
|
-
@param {Store} store
|
|
645
|
-
@param {Model} schema
|
|
646
|
-
@param {Snapshot} snapshot
|
|
647
|
-
@return {Promise} promise
|
|
648
591
|
*/
|
|
649
592
|
updateRecord(store, schema, snapshot) {
|
|
650
593
|
const data = serializeIntoHash(store, schema, snapshot, {});
|
|
@@ -665,10 +608,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
665
608
|
Called by the store when a record is deleted.
|
|
666
609
|
The `deleteRecord` method makes an Ajax (HTTP DELETE) request to a URL computed by `buildURL`.
|
|
667
610
|
@public
|
|
668
|
-
@param {Store} store
|
|
669
|
-
@param {Model} type
|
|
670
|
-
@param {Snapshot} snapshot
|
|
671
|
-
@return {Promise} promise
|
|
672
611
|
*/
|
|
673
612
|
deleteRecord(store, schema, snapshot) {
|
|
674
613
|
const type = snapshot.modelName;
|
|
@@ -680,6 +619,10 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
680
619
|
})(typeof id === 'string' && id.length > 0) : {};
|
|
681
620
|
return this.ajax(this.buildURL(type, id, snapshot, 'deleteRecord'), 'DELETE');
|
|
682
621
|
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
@private
|
|
625
|
+
*/
|
|
683
626
|
_stripIDFromURL(store, snapshot) {
|
|
684
627
|
const type = snapshot.modelName;
|
|
685
628
|
const id = snapshot.id;
|
|
@@ -721,10 +664,8 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
721
664
|
It does not group records that have differing base urls, such as for example: `/posts/1/comments/2`
|
|
722
665
|
and `/posts/2/comments/3`
|
|
723
666
|
@public
|
|
724
|
-
@
|
|
725
|
-
|
|
726
|
-
@return {Array} an array of arrays of records, each of which is to be
|
|
727
|
-
loaded separately by `findMany`.
|
|
667
|
+
@return an array of arrays of records, each of which is to be
|
|
668
|
+
loaded separately by `findMany`.
|
|
728
669
|
*/
|
|
729
670
|
groupRecordsForFindMany(store, snapshots) {
|
|
730
671
|
const groups = new Map();
|
|
@@ -763,11 +704,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
763
704
|
method.
|
|
764
705
|
@since 1.13.0
|
|
765
706
|
@public
|
|
766
|
-
@param {Number} status
|
|
767
|
-
@param {Object} headers
|
|
768
|
-
@param {Object} payload
|
|
769
|
-
@param {Object} requestData - the original request information
|
|
770
|
-
@return {Object | AdapterError} response
|
|
771
707
|
*/
|
|
772
708
|
handleResponse(status, headers, payload, requestData) {
|
|
773
709
|
if (this.isSuccess(status, headers, payload)) {
|
|
@@ -800,10 +736,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
800
736
|
response is a success.
|
|
801
737
|
@since 1.13.0
|
|
802
738
|
@public
|
|
803
|
-
@param {Number} status
|
|
804
|
-
@param {Object} headers
|
|
805
|
-
@param {Object} payload
|
|
806
|
-
@return {Boolean}
|
|
807
739
|
*/
|
|
808
740
|
isSuccess(status, _headers, _payload) {
|
|
809
741
|
return status >= 200 && status < 300 || status === 304;
|
|
@@ -814,10 +746,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
814
746
|
response is an invalid error.
|
|
815
747
|
@since 1.13.0
|
|
816
748
|
@public
|
|
817
|
-
@param {Number} status
|
|
818
|
-
@param {Object} headers
|
|
819
|
-
@param {Object} payload
|
|
820
|
-
@return {Boolean}
|
|
821
749
|
*/
|
|
822
750
|
isInvalid(status, _headers, _payload) {
|
|
823
751
|
return status === 422;
|
|
@@ -826,7 +754,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
826
754
|
/**
|
|
827
755
|
Takes a URL, an HTTP method and a hash of data, and makes an
|
|
828
756
|
HTTP request.
|
|
829
|
-
When the server responds with a payload,
|
|
757
|
+
When the server responds with a payload, WarpDrive will call into `extractSingle`
|
|
830
758
|
or `extractArray` (depending on whether the original query was for one record or
|
|
831
759
|
many records).
|
|
832
760
|
By default, `ajax` method has the following behavior:
|
|
@@ -837,10 +765,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
837
765
|
data is the serialized record in the case of a save.
|
|
838
766
|
* Registers success and failure handlers.
|
|
839
767
|
@private
|
|
840
|
-
@param {String} url
|
|
841
|
-
@param {String} type The request type GET, POST, PUT, DELETE etc.
|
|
842
|
-
@param {Object} options
|
|
843
|
-
@return {Promise} promise
|
|
844
768
|
*/
|
|
845
769
|
async ajax(url, type, options = {}) {
|
|
846
770
|
const requestData = {
|
|
@@ -865,7 +789,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
865
789
|
|
|
866
790
|
/**
|
|
867
791
|
@private
|
|
868
|
-
@param
|
|
792
|
+
@param options jQuery ajax options to be used for the ajax request
|
|
869
793
|
*/
|
|
870
794
|
_ajaxRequest(options) {
|
|
871
795
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -875,10 +799,16 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
875
799
|
})(typeof jQuery !== 'undefined') : {};
|
|
876
800
|
void jQuery.ajax(options);
|
|
877
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
@private
|
|
804
|
+
*/
|
|
878
805
|
_fetchRequest(options) {
|
|
879
806
|
const fetchFunction = getFetchFunction();
|
|
880
807
|
return fetchFunction(options.url, options);
|
|
881
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
@private
|
|
811
|
+
*/
|
|
882
812
|
_ajax(options) {
|
|
883
813
|
if (this.useFetch) {
|
|
884
814
|
void this._fetchRequest(options);
|
|
@@ -889,10 +819,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
889
819
|
|
|
890
820
|
/**
|
|
891
821
|
@private
|
|
892
|
-
@param {String} url
|
|
893
|
-
@param {String} type The request type GET, POST, PUT, DELETE etc.
|
|
894
|
-
@param {Object} options
|
|
895
|
-
@return {Object}
|
|
896
822
|
*/
|
|
897
823
|
ajaxOptions(url, method, options) {
|
|
898
824
|
let reqOptions = Object.assign({
|
|
@@ -937,6 +863,10 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
937
863
|
reqOptions.url = this._ajaxURL(reqOptions.url);
|
|
938
864
|
return reqOptions;
|
|
939
865
|
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* @private
|
|
869
|
+
*/
|
|
940
870
|
_ajaxURL(url) {
|
|
941
871
|
if (this.fastboot?.isFastBoot) {
|
|
942
872
|
const httpRegex = /^https?:\/\//;
|
|
@@ -949,7 +879,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
949
879
|
try {
|
|
950
880
|
return `${protocol}//${host}${url}`;
|
|
951
881
|
} catch (fbError) {
|
|
952
|
-
throw new Error('You are using
|
|
882
|
+
throw new Error('You are using WarpDrive with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
|
|
953
883
|
}
|
|
954
884
|
}
|
|
955
885
|
}
|
|
@@ -958,8 +888,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
958
888
|
|
|
959
889
|
/**
|
|
960
890
|
@private
|
|
961
|
-
@param {String} responseText
|
|
962
|
-
@return {Object}
|
|
963
891
|
*/
|
|
964
892
|
parseErrorResponse(responseText) {
|
|
965
893
|
let json = responseText;
|
|
@@ -973,10 +901,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
973
901
|
|
|
974
902
|
/**
|
|
975
903
|
@private
|
|
976
|
-
@
|
|
977
|
-
@param {Object} headers
|
|
978
|
-
@param {Object} payload
|
|
979
|
-
@return {Array} errors payload
|
|
904
|
+
@return errors payload
|
|
980
905
|
*/
|
|
981
906
|
normalizeErrorResponse(status, _headers, payload) {
|
|
982
907
|
if (payload && typeof payload === 'object' && 'errors' in payload && Array.isArray(payload.errors)) {
|
|
@@ -999,11 +924,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
999
924
|
Generates a detailed ("friendly") error message, with plenty
|
|
1000
925
|
of information for debugging (good luck!)
|
|
1001
926
|
@private
|
|
1002
|
-
@
|
|
1003
|
-
@param {Object} headers
|
|
1004
|
-
@param {Object} payload
|
|
1005
|
-
@param {Object} requestData
|
|
1006
|
-
@return {String} detailed error message
|
|
927
|
+
@return detailed error message
|
|
1007
928
|
*/
|
|
1008
929
|
generatedDetailedMessage(status, headers, payload, requestData) {
|
|
1009
930
|
let shortenedPayload;
|
|
@@ -1025,8 +946,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
1025
946
|
supplied to the ajax method.
|
|
1026
947
|
@since 2.5.0
|
|
1027
948
|
@public
|
|
1028
|
-
@param {Snapshot} snapshot
|
|
1029
|
-
@return {Object}
|
|
1030
949
|
*/
|
|
1031
950
|
buildQuery(snapshot) {
|
|
1032
951
|
const query = {};
|
|
@@ -1167,17 +1086,14 @@ function headersToObject(headers) {
|
|
|
1167
1086
|
/**
|
|
1168
1087
|
* Helper function that translates the options passed to `jQuery.ajax` into a format that `fetch` expects.
|
|
1169
1088
|
*
|
|
1170
|
-
* @param {Object} _options
|
|
1171
|
-
* @param {Adapter} adapter
|
|
1172
1089
|
* @private
|
|
1173
|
-
* @return {Object}
|
|
1174
1090
|
*/
|
|
1175
1091
|
function fetchOptions(options, adapter) {
|
|
1176
1092
|
options.credentials = options.credentials || 'same-origin';
|
|
1177
1093
|
if (options.data) {
|
|
1178
1094
|
// GET and HEAD requests can't have a `body`
|
|
1179
1095
|
if (options.method === 'GET' || options.method === 'HEAD') {
|
|
1180
|
-
// If no options are passed,
|
|
1096
|
+
// If no options are passed, WarpDrive sets `data` to an empty object, which we test for.
|
|
1181
1097
|
if (Object.keys(options.data).length && options.url) {
|
|
1182
1098
|
// Test if there are already query params in the url (mimics jQuey.ajax).
|
|
1183
1099
|
const queryParamDelimiter = options.url.includes('?') ? '&' : '?';
|
package/dist/adapter.js
CHANGED
|
@@ -949,10 +949,10 @@ class Adapter extends EmberObject {
|
|
|
949
949
|
Serializes the record update and sends it to the server.
|
|
950
950
|
The updateRecord method is expected to return a promise that will
|
|
951
951
|
resolve with the serialized record. This allows the backend to
|
|
952
|
-
inform the
|
|
952
|
+
inform the WarpDrive store the current state of this record after
|
|
953
953
|
the update. If it is not possible to return a serialized record
|
|
954
954
|
the updateRecord promise can also resolve with `undefined` and the
|
|
955
|
-
|
|
955
|
+
WarpDrive store will assume all of the updates were successfully
|
|
956
956
|
applied on the backend.
|
|
957
957
|
Example
|
|
958
958
|
```js [app/adapters/application.js]
|
package/dist/compat/-private.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-
|
|
1
|
+
export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-BG3bMiKp.js";
|
package/dist/compat.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getOwner } from '@ember/application';
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
|
-
import { assertPrivateStore,
|
|
3
|
+
import { assertPrivateStore, _deprecatingNormalize } from '@warp-drive/core/store/-private';
|
|
4
4
|
import '@warp-drive/core/reactive/-private';
|
|
5
|
-
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-
|
|
5
|
+
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-BG3bMiKp.js";
|
|
6
6
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
7
|
+
import { waitFor } from '@warp-drive/core/signals/-leaked';
|
|
7
8
|
function _findHasMany(adapter, store, identifier, link, relationship, options) {
|
|
8
9
|
const promise = Promise.resolve().then(() => {
|
|
9
10
|
const snapshot = store._fetchManager.createSnapshot(identifier, options);
|
|
@@ -162,7 +163,7 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
162
163
|
const other = data ? `<${data.type}:${data.id}>` : null;
|
|
163
164
|
const relationshipFetched = `${expectedModel}.${parentRelationship.kind}("${parentRelationship.name}")`;
|
|
164
165
|
const includedRecord = `<${type}:${id}>`;
|
|
165
|
-
const message = [`Encountered mismatched relationship:
|
|
166
|
+
const message = [`Encountered mismatched relationship: WarpDrive expected ${path} in the payload from ${relationshipFetched} to include ${expected} but got ${got} instead.\n`, `The ${includedRecord} record loaded at ${prefix} in the payload specified ${other} as its ${quotedInverse}, but should have specified ${expectedModel} (the record the relationship is being loaded from) as its ${quotedInverse} instead.`, `This could mean that the response for ${relationshipFetched} may have accidentally returned ${quotedType} records that aren't related to ${expectedModel} and could be related to a different ${parentIdentifier.type} record instead.`, `WarpDrive has corrected the ${includedRecord} record's ${quotedInverse} relationship to ${expectedModel} so that ${relationshipFetched} will include ${includedRecord}.`, `Please update the response from the server or change your serializer to either ensure that the response for only includes ${quotedType} records that specify ${expectedModel} as their ${quotedInverse}, or omit the ${quotedInverse} relationship from the response.`].join('\n');
|
|
166
167
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
167
168
|
{
|
|
168
169
|
throw new Error(message);
|