@warp-drive/legacy 5.8.0-alpha.40 → 5.8.0-alpha.42
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/index.d.ts +32 -0
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getOwner } from '@ember/application';
|
|
2
2
|
import { computed } from '@ember/object';
|
|
3
3
|
import { Adapter, BuildURLMixin } from '../adapter.js';
|
|
4
|
-
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-
|
|
4
|
+
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-B2xDbuo5.js";
|
|
5
5
|
import { InvalidError, ServerError, ConflictError, NotFoundError, ForbiddenError, UnauthorizedError, AdapterError, TimeoutError, AbortError } from './error.js';
|
|
6
6
|
import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
|
|
7
7
|
|
|
@@ -87,7 +87,7 @@ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
|
87
87
|
Note that the object root can be pluralized for both a single-object response
|
|
88
88
|
and an array response: the REST adapter is not strict on this. Further, if the
|
|
89
89
|
HTTP server responds to a `GET` request to `/posts/1` (e.g. the response to a
|
|
90
|
-
`findRecord` query) with more than one object in the array,
|
|
90
|
+
`findRecord` query) with more than one object in the array, WarpDrive will
|
|
91
91
|
only display the object with the matching ID.
|
|
92
92
|
|
|
93
93
|
### Conventional Names
|
|
@@ -148,7 +148,7 @@ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
|
148
148
|
|
|
149
149
|
If the records in the relationship are not known when the response
|
|
150
150
|
is serialized it's also possible to represent the relationship as a
|
|
151
|
-
URL using the `links` key in the response.
|
|
151
|
+
URL using the `links` key in the response. WarpDrive will fetch
|
|
152
152
|
this URL to resolve the relationship when it is accessed for the
|
|
153
153
|
first time.
|
|
154
154
|
|
|
@@ -231,17 +231,12 @@ const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
|
231
231
|
}
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
@class RESTAdapter
|
|
235
234
|
@public
|
|
236
|
-
@constructor
|
|
237
|
-
@uses BuildURLMixin
|
|
238
235
|
*/
|
|
239
236
|
class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
240
237
|
/**
|
|
241
238
|
This property allows ajax to still be used instead when `false`.
|
|
242
|
-
@
|
|
243
|
-
@type {Boolean}
|
|
244
|
-
@default true
|
|
239
|
+
@default true
|
|
245
240
|
@public
|
|
246
241
|
*/
|
|
247
242
|
useFetch = true;
|
|
@@ -289,9 +284,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
289
284
|
}
|
|
290
285
|
}
|
|
291
286
|
```
|
|
292
|
-
@
|
|
293
|
-
@return {Object}
|
|
294
|
-
@public
|
|
287
|
+
@public
|
|
295
288
|
*/
|
|
296
289
|
sortQueryParams(obj) {
|
|
297
290
|
const keys = Object.keys(obj);
|
|
@@ -340,9 +333,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
340
333
|
will also send a request to: `GET /comments?ids[]=1&ids[]=2`
|
|
341
334
|
Note: Requests coalescing rely on URL building strategy. So if you override `buildURL` in your app
|
|
342
335
|
`groupRecordsForFindMany` more likely should be overridden as well in order for coalescing to work.
|
|
343
|
-
@
|
|
344
|
-
@public
|
|
345
|
-
@type {Boolean}
|
|
336
|
+
@public
|
|
346
337
|
*/
|
|
347
338
|
get coalesceFindRequests() {
|
|
348
339
|
const coalesceFindRequests = this._coalesceFindRequests;
|
|
@@ -365,9 +356,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
365
356
|
}
|
|
366
357
|
```
|
|
367
358
|
Requests for the `Post` model would now target `/api/1/post/`.
|
|
368
|
-
@
|
|
369
|
-
@public
|
|
370
|
-
@type {String}
|
|
359
|
+
@public
|
|
371
360
|
*/
|
|
372
361
|
|
|
373
362
|
/**
|
|
@@ -379,15 +368,13 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
379
368
|
}
|
|
380
369
|
```
|
|
381
370
|
Requests for the `Post` model would now target `https://api.example.com/post/`.
|
|
382
|
-
@
|
|
383
|
-
@public
|
|
384
|
-
@type {String}
|
|
371
|
+
@public
|
|
385
372
|
*/
|
|
386
373
|
|
|
387
374
|
/**
|
|
388
375
|
Some APIs require HTTP headers, e.g. to provide an API
|
|
389
376
|
key. Arbitrary headers can be set as key/value pairs on the
|
|
390
|
-
`RESTAdapter`'s `headers` object and
|
|
377
|
+
`RESTAdapter`'s `headers` object and WarpDrive will send them
|
|
391
378
|
along with each ajax request..
|
|
392
379
|
```js [app/adapters/application.js]
|
|
393
380
|
import { RESTAdapter } from '@warp-drive/legacy/adapter/rest';
|
|
@@ -400,9 +387,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
400
387
|
}
|
|
401
388
|
}
|
|
402
389
|
```
|
|
403
|
-
@
|
|
404
|
-
@public
|
|
405
|
-
@type {Object}
|
|
390
|
+
@public
|
|
406
391
|
*/
|
|
407
392
|
|
|
408
393
|
/**
|
|
@@ -413,11 +398,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
413
398
|
This method performs an HTTP `GET` request with the id provided as part of the query string.
|
|
414
399
|
@since 1.13.0
|
|
415
400
|
@public
|
|
416
|
-
@param {Store} store
|
|
417
|
-
@param {Model} type
|
|
418
|
-
@param {String} id
|
|
419
|
-
@param {Snapshot} snapshot
|
|
420
|
-
@return {Promise} promise
|
|
421
401
|
*/
|
|
422
402
|
findRecord(store, type, id, snapshot) {
|
|
423
403
|
const url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
|
|
@@ -433,18 +413,10 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
433
413
|
The `findAll` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
|
|
434
414
|
promise for the resulting payload.
|
|
435
415
|
@public
|
|
436
|
-
@param {Store} store
|
|
437
|
-
@param {Model} type
|
|
438
|
-
@param {undefined} neverSet a value is never provided to this argument
|
|
439
|
-
@param {SnapshotRecordArray} snapshotRecordArray
|
|
440
|
-
@return {Promise} promise
|
|
441
416
|
*/
|
|
442
|
-
findAll(store, type,
|
|
417
|
+
findAll(store, type, neverUsed, snapshotRecordArray) {
|
|
443
418
|
const query = this.buildQuery(snapshotRecordArray);
|
|
444
419
|
const url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll');
|
|
445
|
-
if (sinceToken) {
|
|
446
|
-
query.since = sinceToken;
|
|
447
|
-
}
|
|
448
420
|
return this.ajax(url, 'GET', {
|
|
449
421
|
data: query
|
|
450
422
|
});
|
|
@@ -459,12 +431,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
459
431
|
The `query` argument is a simple JavaScript object that will be passed directly
|
|
460
432
|
to the server as parameters.
|
|
461
433
|
@public
|
|
462
|
-
@param {Store} store
|
|
463
|
-
@param {Model} type
|
|
464
|
-
@param {Object} query
|
|
465
|
-
@param {Collection} recordArray
|
|
466
|
-
@param {Object} adapterOptions
|
|
467
|
-
@return {Promise} promise
|
|
468
434
|
*/
|
|
469
435
|
query(store, type, query) {
|
|
470
436
|
const url = this.buildURL(type.modelName, null, null, 'query', query);
|
|
@@ -486,11 +452,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
486
452
|
to the server as parameters.
|
|
487
453
|
@since 1.13.0
|
|
488
454
|
@public
|
|
489
|
-
@param {Store} store
|
|
490
|
-
@param {Model} type
|
|
491
|
-
@param {Object} query
|
|
492
|
-
@param {Object} adapterOptions
|
|
493
|
-
@return {Promise} promise
|
|
494
455
|
*/
|
|
495
456
|
queryRecord(store, type, query, adapterOptions) {
|
|
496
457
|
const url = this.buildURL(type.modelName, null, null, 'queryRecord', query);
|
|
@@ -522,11 +483,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
522
483
|
The `findMany` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
|
|
523
484
|
promise for the resulting payload.
|
|
524
485
|
@public
|
|
525
|
-
@param {Store} store
|
|
526
|
-
@param {Model} type
|
|
527
|
-
@param {Array} ids
|
|
528
|
-
@param {Array} snapshots
|
|
529
|
-
@return {Promise} promise
|
|
530
486
|
*/
|
|
531
487
|
findMany(store, type, ids, snapshots) {
|
|
532
488
|
const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
|
|
@@ -558,11 +514,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
558
514
|
* Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
|
|
559
515
|
* Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
|
|
560
516
|
@public
|
|
561
|
-
@param {Store} store
|
|
562
|
-
@param {Snapshot} snapshot
|
|
563
|
-
@param {String} url
|
|
564
|
-
@param {Object} relationship meta object describing the relationship
|
|
565
|
-
@return {Promise} promise
|
|
566
517
|
*/
|
|
567
518
|
findHasMany(store, snapshot, url, relationship) {
|
|
568
519
|
const id = snapshot.id;
|
|
@@ -618,10 +569,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
618
569
|
See `serialize` for information on how to customize the serialized form
|
|
619
570
|
of a record.
|
|
620
571
|
@public
|
|
621
|
-
@param {Store} store
|
|
622
|
-
@param {Model} type
|
|
623
|
-
@param {Snapshot} snapshot
|
|
624
|
-
@return {Promise} promise
|
|
625
572
|
*/
|
|
626
573
|
createRecord(store, type, snapshot) {
|
|
627
574
|
const url = this.buildURL(type.modelName, null, snapshot, 'createRecord');
|
|
@@ -639,10 +586,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
639
586
|
See `serialize` for information on how to customize the serialized form
|
|
640
587
|
of a record.
|
|
641
588
|
@public
|
|
642
|
-
@param {Store} store
|
|
643
|
-
@param {Model} schema
|
|
644
|
-
@param {Snapshot} snapshot
|
|
645
|
-
@return {Promise} promise
|
|
646
589
|
*/
|
|
647
590
|
updateRecord(store, schema, snapshot) {
|
|
648
591
|
const data = serializeIntoHash(store, schema, snapshot, {});
|
|
@@ -663,10 +606,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
663
606
|
Called by the store when a record is deleted.
|
|
664
607
|
The `deleteRecord` method makes an Ajax (HTTP DELETE) request to a URL computed by `buildURL`.
|
|
665
608
|
@public
|
|
666
|
-
@param {Store} store
|
|
667
|
-
@param {Model} type
|
|
668
|
-
@param {Snapshot} snapshot
|
|
669
|
-
@return {Promise} promise
|
|
670
609
|
*/
|
|
671
610
|
deleteRecord(store, schema, snapshot) {
|
|
672
611
|
const type = snapshot.modelName;
|
|
@@ -678,6 +617,10 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
678
617
|
})(typeof id === 'string' && id.length > 0);
|
|
679
618
|
return this.ajax(this.buildURL(type, id, snapshot, 'deleteRecord'), 'DELETE');
|
|
680
619
|
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
@private
|
|
623
|
+
*/
|
|
681
624
|
_stripIDFromURL(store, snapshot) {
|
|
682
625
|
const type = snapshot.modelName;
|
|
683
626
|
const id = snapshot.id;
|
|
@@ -719,10 +662,8 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
719
662
|
It does not group records that have differing base urls, such as for example: `/posts/1/comments/2`
|
|
720
663
|
and `/posts/2/comments/3`
|
|
721
664
|
@public
|
|
722
|
-
@
|
|
723
|
-
|
|
724
|
-
@return {Array} an array of arrays of records, each of which is to be
|
|
725
|
-
loaded separately by `findMany`.
|
|
665
|
+
@return an array of arrays of records, each of which is to be
|
|
666
|
+
loaded separately by `findMany`.
|
|
726
667
|
*/
|
|
727
668
|
groupRecordsForFindMany(store, snapshots) {
|
|
728
669
|
const groups = new Map();
|
|
@@ -761,11 +702,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
761
702
|
method.
|
|
762
703
|
@since 1.13.0
|
|
763
704
|
@public
|
|
764
|
-
@param {Number} status
|
|
765
|
-
@param {Object} headers
|
|
766
|
-
@param {Object} payload
|
|
767
|
-
@param {Object} requestData - the original request information
|
|
768
|
-
@return {Object | AdapterError} response
|
|
769
705
|
*/
|
|
770
706
|
handleResponse(status, headers, payload, requestData) {
|
|
771
707
|
if (this.isSuccess(status, headers, payload)) {
|
|
@@ -798,10 +734,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
798
734
|
response is a success.
|
|
799
735
|
@since 1.13.0
|
|
800
736
|
@public
|
|
801
|
-
@param {Number} status
|
|
802
|
-
@param {Object} headers
|
|
803
|
-
@param {Object} payload
|
|
804
|
-
@return {Boolean}
|
|
805
737
|
*/
|
|
806
738
|
isSuccess(status, _headers, _payload) {
|
|
807
739
|
return status >= 200 && status < 300 || status === 304;
|
|
@@ -812,10 +744,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
812
744
|
response is an invalid error.
|
|
813
745
|
@since 1.13.0
|
|
814
746
|
@public
|
|
815
|
-
@param {Number} status
|
|
816
|
-
@param {Object} headers
|
|
817
|
-
@param {Object} payload
|
|
818
|
-
@return {Boolean}
|
|
819
747
|
*/
|
|
820
748
|
isInvalid(status, _headers, _payload) {
|
|
821
749
|
return status === 422;
|
|
@@ -824,7 +752,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
824
752
|
/**
|
|
825
753
|
Takes a URL, an HTTP method and a hash of data, and makes an
|
|
826
754
|
HTTP request.
|
|
827
|
-
When the server responds with a payload,
|
|
755
|
+
When the server responds with a payload, WarpDrive will call into `extractSingle`
|
|
828
756
|
or `extractArray` (depending on whether the original query was for one record or
|
|
829
757
|
many records).
|
|
830
758
|
By default, `ajax` method has the following behavior:
|
|
@@ -835,10 +763,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
835
763
|
data is the serialized record in the case of a save.
|
|
836
764
|
* Registers success and failure handlers.
|
|
837
765
|
@private
|
|
838
|
-
@param {String} url
|
|
839
|
-
@param {String} type The request type GET, POST, PUT, DELETE etc.
|
|
840
|
-
@param {Object} options
|
|
841
|
-
@return {Promise} promise
|
|
842
766
|
*/
|
|
843
767
|
async ajax(url, type, options = {}) {
|
|
844
768
|
const requestData = {
|
|
@@ -863,7 +787,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
863
787
|
|
|
864
788
|
/**
|
|
865
789
|
@private
|
|
866
|
-
@param
|
|
790
|
+
@param options jQuery ajax options to be used for the ajax request
|
|
867
791
|
*/
|
|
868
792
|
_ajaxRequest(options) {
|
|
869
793
|
(test => {
|
|
@@ -873,10 +797,16 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
873
797
|
})(typeof jQuery !== 'undefined');
|
|
874
798
|
void jQuery.ajax(options);
|
|
875
799
|
}
|
|
800
|
+
/**
|
|
801
|
+
@private
|
|
802
|
+
*/
|
|
876
803
|
_fetchRequest(options) {
|
|
877
804
|
const fetchFunction = getFetchFunction();
|
|
878
805
|
return fetchFunction(options.url, options);
|
|
879
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
@private
|
|
809
|
+
*/
|
|
880
810
|
_ajax(options) {
|
|
881
811
|
if (this.useFetch) {
|
|
882
812
|
void this._fetchRequest(options);
|
|
@@ -887,10 +817,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
887
817
|
|
|
888
818
|
/**
|
|
889
819
|
@private
|
|
890
|
-
@param {String} url
|
|
891
|
-
@param {String} type The request type GET, POST, PUT, DELETE etc.
|
|
892
|
-
@param {Object} options
|
|
893
|
-
@return {Object}
|
|
894
820
|
*/
|
|
895
821
|
ajaxOptions(url, method, options) {
|
|
896
822
|
let reqOptions = Object.assign({
|
|
@@ -935,6 +861,10 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
935
861
|
reqOptions.url = this._ajaxURL(reqOptions.url);
|
|
936
862
|
return reqOptions;
|
|
937
863
|
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* @private
|
|
867
|
+
*/
|
|
938
868
|
_ajaxURL(url) {
|
|
939
869
|
if (this.fastboot?.isFastBoot) {
|
|
940
870
|
const httpRegex = /^https?:\/\//;
|
|
@@ -947,7 +877,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
947
877
|
try {
|
|
948
878
|
return `${protocol}//${host}${url}`;
|
|
949
879
|
} catch (fbError) {
|
|
950
|
-
throw new Error('You are using
|
|
880
|
+
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);
|
|
951
881
|
}
|
|
952
882
|
}
|
|
953
883
|
}
|
|
@@ -956,8 +886,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
956
886
|
|
|
957
887
|
/**
|
|
958
888
|
@private
|
|
959
|
-
@param {String} responseText
|
|
960
|
-
@return {Object}
|
|
961
889
|
*/
|
|
962
890
|
parseErrorResponse(responseText) {
|
|
963
891
|
let json = responseText;
|
|
@@ -971,10 +899,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
971
899
|
|
|
972
900
|
/**
|
|
973
901
|
@private
|
|
974
|
-
@
|
|
975
|
-
@param {Object} headers
|
|
976
|
-
@param {Object} payload
|
|
977
|
-
@return {Array} errors payload
|
|
902
|
+
@return errors payload
|
|
978
903
|
*/
|
|
979
904
|
normalizeErrorResponse(status, _headers, payload) {
|
|
980
905
|
if (payload && typeof payload === 'object' && 'errors' in payload && Array.isArray(payload.errors)) {
|
|
@@ -997,11 +922,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
997
922
|
Generates a detailed ("friendly") error message, with plenty
|
|
998
923
|
of information for debugging (good luck!)
|
|
999
924
|
@private
|
|
1000
|
-
@
|
|
1001
|
-
@param {Object} headers
|
|
1002
|
-
@param {Object} payload
|
|
1003
|
-
@param {Object} requestData
|
|
1004
|
-
@return {String} detailed error message
|
|
925
|
+
@return detailed error message
|
|
1005
926
|
*/
|
|
1006
927
|
generatedDetailedMessage(status, headers, payload, requestData) {
|
|
1007
928
|
let shortenedPayload;
|
|
@@ -1023,8 +944,6 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
1023
944
|
supplied to the ajax method.
|
|
1024
945
|
@since 2.5.0
|
|
1025
946
|
@public
|
|
1026
|
-
@param {Snapshot} snapshot
|
|
1027
|
-
@return {Object}
|
|
1028
947
|
*/
|
|
1029
948
|
buildQuery(snapshot) {
|
|
1030
949
|
const query = {};
|
|
@@ -1165,17 +1084,14 @@ function headersToObject(headers) {
|
|
|
1165
1084
|
/**
|
|
1166
1085
|
* Helper function that translates the options passed to `jQuery.ajax` into a format that `fetch` expects.
|
|
1167
1086
|
*
|
|
1168
|
-
* @param {Object} _options
|
|
1169
|
-
* @param {Adapter} adapter
|
|
1170
1087
|
* @private
|
|
1171
|
-
* @return {Object}
|
|
1172
1088
|
*/
|
|
1173
1089
|
function fetchOptions(options, adapter) {
|
|
1174
1090
|
options.credentials = options.credentials || 'same-origin';
|
|
1175
1091
|
if (options.data) {
|
|
1176
1092
|
// GET and HEAD requests can't have a `body`
|
|
1177
1093
|
if (options.method === 'GET' || options.method === 'HEAD') {
|
|
1178
|
-
// If no options are passed,
|
|
1094
|
+
// If no options are passed, WarpDrive sets `data` to an empty object, which we test for.
|
|
1179
1095
|
if (Object.keys(options.data).length && options.url) {
|
|
1180
1096
|
// Test if there are already query params in the url (mimics jQuey.ajax).
|
|
1181
1097
|
const queryParamDelimiter = options.url.includes('?') ? '&' : '?';
|
|
@@ -948,10 +948,10 @@ class Adapter extends EmberObject {
|
|
|
948
948
|
Serializes the record update and sends it to the server.
|
|
949
949
|
The updateRecord method is expected to return a promise that will
|
|
950
950
|
resolve with the serialized record. This allows the backend to
|
|
951
|
-
inform the
|
|
951
|
+
inform the WarpDrive store the current state of this record after
|
|
952
952
|
the update. If it is not possible to return a serialized record
|
|
953
953
|
the updateRecord promise can also resolve with `undefined` and the
|
|
954
|
-
|
|
954
|
+
WarpDrive store will assume all of the updates were successfully
|
|
955
955
|
applied on the backend.
|
|
956
956
|
Example
|
|
957
957
|
```js [app/adapters/application.js]
|
|
@@ -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-DtjBbEgy.js";
|
|
@@ -1,8 +1,9 @@
|
|
|
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-DtjBbEgy.js";
|
|
6
|
+
import { waitFor } from '@warp-drive/core/signals/-leaked';
|
|
6
7
|
function _findHasMany(adapter, store, identifier, link, relationship, options) {
|
|
7
8
|
const promise = Promise.resolve().then(() => {
|
|
8
9
|
const snapshot = store._fetchManager.createSnapshot(identifier, options);
|
|
@@ -161,7 +162,7 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
161
162
|
const other = data ? `<${data.type}:${data.id}>` : null;
|
|
162
163
|
const relationshipFetched = `${expectedModel}.${parentRelationship.kind}("${parentRelationship.name}")`;
|
|
163
164
|
const includedRecord = `<${type}:${id}>`;
|
|
164
|
-
const message = [`Encountered mismatched relationship:
|
|
165
|
+
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');
|
|
165
166
|
(test => {
|
|
166
167
|
{
|
|
167
168
|
throw new Error(message);
|