@ember-data/legacy-compat 5.3.3 → 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/README.md +8 -0
- package/addon-main.cjs +5 -0
- package/{addon/-private-1aicprWG.js → dist/-private-DVN28hvw.js} +176 -63
- package/dist/-private-DVN28hvw.js.map +1 -0
- package/dist/-private.js +1 -0
- package/dist/builders.js +323 -0
- package/dist/builders.js.map +1 -0
- package/{addon → dist}/index.js +244 -72
- package/dist/index.js.map +1 -0
- package/dist/utils.js +246 -0
- package/dist/utils.js.map +1 -0
- package/package.json +53 -62
- package/unstable-preview-types/-private.d.ts +17 -0
- package/unstable-preview-types/-private.d.ts.map +1 -0
- package/unstable-preview-types/builders/find-all.d.ts +41 -0
- package/unstable-preview-types/builders/find-all.d.ts.map +1 -0
- package/unstable-preview-types/builders/find-record.d.ts +62 -0
- package/unstable-preview-types/builders/find-record.d.ts.map +1 -0
- package/unstable-preview-types/builders/query.d.ts +72 -0
- package/unstable-preview-types/builders/query.d.ts.map +1 -0
- package/unstable-preview-types/builders/save-record.d.ts +40 -0
- package/unstable-preview-types/builders/save-record.d.ts.map +1 -0
- package/unstable-preview-types/builders/utils.d.ts +6 -0
- package/unstable-preview-types/builders/utils.d.ts.map +1 -0
- package/unstable-preview-types/builders.d.ts +18 -0
- package/unstable-preview-types/builders.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +162 -0
- package/unstable-preview-types/index.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts +49 -0
- package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts +5 -0
- package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts +14 -0
- package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts +8 -0
- package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts +5 -0
- package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts +549 -0
- package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts +235 -0
- package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts +9 -0
- package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts +96 -0
- package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
- package/unstable-preview-types/legacy-network-handler/snapshot.d.ts +248 -0
- package/unstable-preview-types/legacy-network-handler/snapshot.d.ts.map +1 -0
- package/unstable-preview-types/utils.d.ts +161 -0
- package/unstable-preview-types/utils.d.ts.map +1 -0
- package/addon/-private-1aicprWG.js.map +0 -1
- package/addon/-private.js +0 -1
- package/addon/index.js.map +0 -1
- package/addon-main.js +0 -93
- /package/{addon → dist}/-private.js.map +0 -0
package/README.md
CHANGED
|
@@ -24,3 +24,11 @@ Install using your javascript package manager of choice. For instance with [pnpm
|
|
|
24
24
|
```no-highlight
|
|
25
25
|
pnpm add @ember-data/legacy-compat
|
|
26
26
|
```
|
|
27
|
+
|
|
28
|
+
**Tagged Releases**
|
|
29
|
+
|
|
30
|
+
- 
|
|
31
|
+
- 
|
|
32
|
+
- 
|
|
33
|
+
- 
|
|
34
|
+
- 
|
package/addon-main.cjs
ADDED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SOURCE, coerceId } from '@ember-data/store/-private';
|
|
2
|
-
import {
|
|
3
|
-
import { macroCondition,
|
|
2
|
+
import { warn } from '@ember/debug';
|
|
3
|
+
import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
|
|
4
4
|
import { createDeferred } from '@ember-data/request';
|
|
5
|
+
import { getOrSetGlobal } from '@warp-drive/core-types/-private';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
@module @ember-data/legacy-compat
|
|
@@ -10,7 +11,7 @@ import { createDeferred } from '@ember-data/request';
|
|
|
10
11
|
/**
|
|
11
12
|
SnapshotRecordArray is not directly instantiable.
|
|
12
13
|
Instances are provided to consuming application's
|
|
13
|
-
adapters for certain requests.
|
|
14
|
+
adapters for certain `findAll` requests.
|
|
14
15
|
|
|
15
16
|
@class SnapshotRecordArray
|
|
16
17
|
@public
|
|
@@ -149,13 +150,17 @@ class SnapshotRecordArray {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
function assertIdentifierHasId(identifier) {
|
|
152
|
-
|
|
153
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
154
|
+
if (!test) {
|
|
155
|
+
throw new Error(`Attempted to schedule a fetch for a record without an id.`);
|
|
156
|
+
}
|
|
157
|
+
})(identifier && identifier.id !== null) : {};
|
|
153
158
|
}
|
|
154
159
|
function iterateData(data, fn) {
|
|
155
160
|
if (Array.isArray(data)) {
|
|
156
161
|
return data.map(fn);
|
|
157
162
|
} else {
|
|
158
|
-
return fn(data);
|
|
163
|
+
return fn(data, 0);
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
166
|
function payloadIsNotBlank(adapterPayload) {
|
|
@@ -175,7 +180,7 @@ function payloadIsNotBlank(adapterPayload) {
|
|
|
175
180
|
@internal
|
|
176
181
|
*/
|
|
177
182
|
function validateDocumentStructure(doc) {
|
|
178
|
-
if (macroCondition(
|
|
183
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
179
184
|
const errors = [];
|
|
180
185
|
if (!doc || typeof doc !== 'object') {
|
|
181
186
|
errors.push('Top level of a JSON API document must be an object');
|
|
@@ -218,7 +223,11 @@ function validateDocumentStructure(doc) {
|
|
|
218
223
|
}
|
|
219
224
|
}
|
|
220
225
|
}
|
|
221
|
-
|
|
226
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
227
|
+
if (!test) {
|
|
228
|
+
throw new Error(`Response must be normalized to a valid JSON API document:\n\t* ${errors.join('\n\t* ')}`);
|
|
229
|
+
}
|
|
230
|
+
})(errors.length === 0) : {};
|
|
222
231
|
}
|
|
223
232
|
}
|
|
224
233
|
function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) {
|
|
@@ -335,7 +344,11 @@ class Snapshot {
|
|
|
335
344
|
*/
|
|
336
345
|
get record() {
|
|
337
346
|
const record = this._store.peekRecord(this.identifier);
|
|
338
|
-
|
|
347
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
348
|
+
if (!test) {
|
|
349
|
+
throw new Error(`Record ${this.identifier.type} ${this.identifier.id} (${this.identifier.lid}) is not yet loaded and thus cannot be accessed from the Snapshot during serialization`);
|
|
350
|
+
}
|
|
351
|
+
})(record !== null) : {};
|
|
339
352
|
return record;
|
|
340
353
|
}
|
|
341
354
|
get _attributes() {
|
|
@@ -346,10 +359,12 @@ class Snapshot {
|
|
|
346
359
|
const {
|
|
347
360
|
identifier
|
|
348
361
|
} = this;
|
|
349
|
-
const attrs =
|
|
362
|
+
const attrs = this._store.schema.fields(identifier);
|
|
350
363
|
const cache = this._store.cache;
|
|
351
|
-
attrs.forEach(keyName => {
|
|
352
|
-
|
|
364
|
+
attrs.forEach((field, keyName) => {
|
|
365
|
+
if (field.kind === 'attribute') {
|
|
366
|
+
attributes[keyName] = cache.getAttr(identifier, keyName);
|
|
367
|
+
}
|
|
353
368
|
});
|
|
354
369
|
return attributes;
|
|
355
370
|
}
|
|
@@ -376,7 +391,11 @@ class Snapshot {
|
|
|
376
391
|
if (keyName in this._attributes) {
|
|
377
392
|
return this._attributes[keyName];
|
|
378
393
|
}
|
|
379
|
-
|
|
394
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
395
|
+
{
|
|
396
|
+
throw new Error(`Model '${this.identifier.lid}' has no attribute named '${keyName}' defined.`);
|
|
397
|
+
}
|
|
398
|
+
})() : {};
|
|
380
399
|
}
|
|
381
400
|
|
|
382
401
|
/**
|
|
@@ -459,27 +478,35 @@ class Snapshot {
|
|
|
459
478
|
if (returnModeIsId === false && keyName in this._belongsToRelationships) {
|
|
460
479
|
return this._belongsToRelationships[keyName];
|
|
461
480
|
}
|
|
462
|
-
const relationshipMeta = store.
|
|
481
|
+
const relationshipMeta = store.schema.fields({
|
|
463
482
|
type: this.modelName
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
483
|
+
}).get(keyName);
|
|
484
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
485
|
+
if (!test) {
|
|
486
|
+
throw new Error(`Model '${this.identifier.lid}' has no belongsTo relationship named '${keyName}' defined.`);
|
|
487
|
+
}
|
|
488
|
+
})(relationshipMeta && relationshipMeta.kind === 'belongsTo') : {};
|
|
489
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
490
|
+
if (!test) {
|
|
491
|
+
throw new Error(`snapshot.belongsTo only supported when using the package @ember-data/graph`);
|
|
492
|
+
}
|
|
493
|
+
})(dependencySatisfies('@ember-data/graph', '*')) : {};
|
|
475
494
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
476
495
|
const {
|
|
477
496
|
identifier
|
|
478
497
|
} = this;
|
|
479
|
-
if (macroCondition(
|
|
498
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
480
499
|
const relationship = graphFor(this._store).get(identifier, keyName);
|
|
481
|
-
|
|
482
|
-
|
|
500
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
501
|
+
if (!test) {
|
|
502
|
+
throw new Error(`You looked up the ${keyName} belongsTo relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but no such relationship was found.`);
|
|
503
|
+
}
|
|
504
|
+
})(relationship) : {};
|
|
505
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
506
|
+
if (!test) {
|
|
507
|
+
throw new Error(`You looked up the ${keyName} belongsTo relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but that relationship is a hasMany.`);
|
|
508
|
+
}
|
|
509
|
+
})(relationship.definition.kind === 'belongsTo') : {};
|
|
483
510
|
}
|
|
484
511
|
const value = graphFor(this._store).getData(identifier, keyName);
|
|
485
512
|
const data = value && value.data;
|
|
@@ -539,27 +566,41 @@ class Snapshot {
|
|
|
539
566
|
return cachedSnapshots;
|
|
540
567
|
}
|
|
541
568
|
const store = this._store;
|
|
542
|
-
const relationshipMeta = store.
|
|
569
|
+
const relationshipMeta = store.schema.fields({
|
|
543
570
|
type: this.modelName
|
|
544
|
-
})
|
|
545
|
-
|
|
571
|
+
}).get(keyName);
|
|
572
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
573
|
+
if (!test) {
|
|
574
|
+
throw new Error(`Model '${this.identifier.lid}' has no hasMany relationship named '${keyName}' defined.`);
|
|
575
|
+
}
|
|
576
|
+
})(relationshipMeta && relationshipMeta.kind === 'hasMany') : {};
|
|
546
577
|
|
|
547
578
|
// TODO @runspired it seems this code branch would not work with CUSTOM_MODEL_CLASSes
|
|
548
579
|
// this check is not a regression in behavior because relationships don't currently
|
|
549
580
|
// function without access to intimate API contracts between RecordData and Model.
|
|
550
581
|
// This is a requirement we should fix as soon as the relationship layer does not require
|
|
551
582
|
// this intimate API usage.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
583
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
584
|
+
if (!test) {
|
|
585
|
+
throw new Error(`snapshot.hasMany only supported when using the package @ember-data/graph`);
|
|
586
|
+
}
|
|
587
|
+
})(dependencySatisfies('@ember-data/graph', '*')) : {};
|
|
555
588
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
556
589
|
const {
|
|
557
590
|
identifier
|
|
558
591
|
} = this;
|
|
559
|
-
if (macroCondition(
|
|
592
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
560
593
|
const relationship = graphFor(this._store).get(identifier, keyName);
|
|
561
|
-
|
|
562
|
-
|
|
594
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
595
|
+
if (!test) {
|
|
596
|
+
throw new Error(`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but no such relationship was found.`);
|
|
597
|
+
}
|
|
598
|
+
})(relationship) : {};
|
|
599
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
600
|
+
if (!test) {
|
|
601
|
+
throw new Error(`You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id || ''}, lid: ${identifier.lid} but that relationship is a belongsTo.`);
|
|
602
|
+
}
|
|
603
|
+
})(relationship.definition.kind === 'hasMany') : {};
|
|
563
604
|
}
|
|
564
605
|
const value = graphFor(this._store).getData(identifier, keyName);
|
|
565
606
|
if (value.data) {
|
|
@@ -602,9 +643,11 @@ class Snapshot {
|
|
|
602
643
|
@public
|
|
603
644
|
*/
|
|
604
645
|
eachAttribute(callback, binding) {
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
646
|
+
const fields = this._store.schema.fields(this.identifier);
|
|
647
|
+
fields.forEach((field, key) => {
|
|
648
|
+
if (field.kind === 'attribute') {
|
|
649
|
+
callback.call(binding, key, field);
|
|
650
|
+
}
|
|
608
651
|
});
|
|
609
652
|
}
|
|
610
653
|
|
|
@@ -623,9 +666,11 @@ class Snapshot {
|
|
|
623
666
|
@public
|
|
624
667
|
*/
|
|
625
668
|
eachRelationship(callback, binding) {
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
669
|
+
const fields = this._store.schema.fields(this.identifier);
|
|
670
|
+
fields.forEach((field, key) => {
|
|
671
|
+
if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
|
|
672
|
+
callback.call(binding, key, field);
|
|
673
|
+
}
|
|
629
674
|
});
|
|
630
675
|
}
|
|
631
676
|
|
|
@@ -653,11 +698,15 @@ class Snapshot {
|
|
|
653
698
|
serialize(options) {
|
|
654
699
|
upgradeStore(this._store);
|
|
655
700
|
const serializer = this._store.serializerFor(this.modelName);
|
|
656
|
-
|
|
701
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
702
|
+
if (!test) {
|
|
703
|
+
throw new Error(`Cannot serialize record, no serializer found`);
|
|
704
|
+
}
|
|
705
|
+
})(serializer) : {};
|
|
657
706
|
return serializer.serialize(this, options);
|
|
658
707
|
}
|
|
659
708
|
}
|
|
660
|
-
const SaveOp = Symbol('SaveOp');
|
|
709
|
+
const SaveOp = getOrSetGlobal('SaveOp', Symbol('SaveOp'));
|
|
661
710
|
class FetchManager {
|
|
662
711
|
// fetches pending in the runloop, waiting to be coalesced
|
|
663
712
|
|
|
@@ -740,11 +789,15 @@ class FetchManager {
|
|
|
740
789
|
}
|
|
741
790
|
return identifier;
|
|
742
791
|
}, error => {
|
|
743
|
-
|
|
792
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
793
|
+
if (!test) {
|
|
794
|
+
throw new Error(`Async Leak Detected: Expected the store to not be destroyed`);
|
|
795
|
+
}
|
|
796
|
+
})(!store.isDestroyed) : {};
|
|
744
797
|
const cache = store.cache;
|
|
745
798
|
if (!cache || cache.isEmpty(identifier) || isInitialLoad) {
|
|
746
799
|
let isReleasable = true;
|
|
747
|
-
if (macroCondition(
|
|
800
|
+
if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
|
|
748
801
|
if (!cache) {
|
|
749
802
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
750
803
|
const graph = graphFor(store);
|
|
@@ -779,7 +832,7 @@ class FetchManager {
|
|
|
779
832
|
fetchesById.set(identifier, requestsForIdentifier);
|
|
780
833
|
}
|
|
781
834
|
requestsForIdentifier.push(pendingFetchItem);
|
|
782
|
-
if (macroCondition(
|
|
835
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
783
836
|
if (!request.disableTestWaiter) {
|
|
784
837
|
const {
|
|
785
838
|
waitForPromise
|
|
@@ -816,7 +869,7 @@ class FetchManager {
|
|
|
816
869
|
let promise;
|
|
817
870
|
if (isEmpty) {
|
|
818
871
|
assertIdentifierHasId(identifier);
|
|
819
|
-
if (macroCondition(
|
|
872
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
820
873
|
promise = this.scheduleFetch(identifier, Object.assign({}, options, {
|
|
821
874
|
reload: true
|
|
822
875
|
}), request);
|
|
@@ -826,7 +879,11 @@ class FetchManager {
|
|
|
826
879
|
}
|
|
827
880
|
} else if (isLoading) {
|
|
828
881
|
promise = this.getPendingFetch(identifier, options);
|
|
829
|
-
|
|
882
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
883
|
+
if (!test) {
|
|
884
|
+
throw new Error(`Expected to find a pending request for a record in the loading state, but found none`);
|
|
885
|
+
}
|
|
886
|
+
})(promise) : {};
|
|
830
887
|
} else {
|
|
831
888
|
promise = Promise.resolve(identifier);
|
|
832
889
|
}
|
|
@@ -894,15 +951,31 @@ function _findMany(store, adapter, modelName, snapshots) {
|
|
|
894
951
|
const modelClass = store.modelFor(modelName); // `adapter.findMany` gets the modelClass still
|
|
895
952
|
const promise = Promise.resolve().then(() => {
|
|
896
953
|
const ids = snapshots.map(s => s.id);
|
|
897
|
-
|
|
954
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
955
|
+
if (!test) {
|
|
956
|
+
throw new Error(`Cannot fetch a record without an id`);
|
|
957
|
+
}
|
|
958
|
+
})(ids.every(v => v !== null)) : {};
|
|
898
959
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
899
|
-
|
|
960
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
961
|
+
if (!test) {
|
|
962
|
+
throw new Error(`Expected this adapter to implement findMany for coalescing`);
|
|
963
|
+
}
|
|
964
|
+
})(adapter.findMany) : {};
|
|
900
965
|
const ret = adapter.findMany(store, modelClass, ids, snapshots);
|
|
901
|
-
|
|
966
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
967
|
+
if (!test) {
|
|
968
|
+
throw new Error('adapter.findMany returned undefined, this was very likely a mistake');
|
|
969
|
+
}
|
|
970
|
+
})(ret !== undefined) : {};
|
|
902
971
|
return ret;
|
|
903
972
|
});
|
|
904
973
|
return promise.then(adapterPayload => {
|
|
905
|
-
|
|
974
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
975
|
+
if (!test) {
|
|
976
|
+
throw new Error(`You made a 'findMany' request for '${modelName}' records with ids '[${snapshots.map(s => s.id).join(',')}]', but the adapter's response did not have any data`);
|
|
977
|
+
}
|
|
978
|
+
})(!!payloadIsNotBlank(adapterPayload)) : {};
|
|
906
979
|
const serializer = store.serializerFor(modelName);
|
|
907
980
|
const payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany');
|
|
908
981
|
return payload;
|
|
@@ -981,8 +1054,16 @@ function handleFoundRecords(store, fetchMap, snapshots, coalescedPayload) {
|
|
|
981
1054
|
function _fetchRecord(store, adapter, fetchItem) {
|
|
982
1055
|
const identifier = fetchItem.identifier;
|
|
983
1056
|
const modelName = identifier.type;
|
|
984
|
-
|
|
985
|
-
|
|
1057
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1058
|
+
if (!test) {
|
|
1059
|
+
throw new Error(`You tried to find a record but you have no adapter (for ${modelName})`);
|
|
1060
|
+
}
|
|
1061
|
+
})(adapter) : {};
|
|
1062
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1063
|
+
if (!test) {
|
|
1064
|
+
throw new Error(`You tried to find a record but your adapter (for ${modelName}) does not implement 'findRecord'`);
|
|
1065
|
+
}
|
|
1066
|
+
})(typeof adapter.findRecord === 'function') : {};
|
|
986
1067
|
const snapshot = store._fetchManager.createSnapshot(identifier, fetchItem.options);
|
|
987
1068
|
const klass = store.modelFor(identifier.type);
|
|
988
1069
|
const id = identifier.id;
|
|
@@ -990,12 +1071,28 @@ function _fetchRecord(store, adapter, fetchItem) {
|
|
|
990
1071
|
return adapter.findRecord(store, klass, identifier.id, snapshot);
|
|
991
1072
|
});
|
|
992
1073
|
promise = promise.then(adapterPayload => {
|
|
993
|
-
|
|
994
|
-
|
|
1074
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1075
|
+
if (!test) {
|
|
1076
|
+
throw new Error(`Async Leak Detected: Expected the store to not be destroyed`);
|
|
1077
|
+
}
|
|
1078
|
+
})(!(store.isDestroyed || store.isDestroying)) : {};
|
|
1079
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1080
|
+
if (!test) {
|
|
1081
|
+
throw new Error(`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`);
|
|
1082
|
+
}
|
|
1083
|
+
})(!!payloadIsNotBlank(adapterPayload)) : {};
|
|
995
1084
|
const serializer = store.serializerFor(modelName);
|
|
996
1085
|
const payload = normalizeResponseHelper(serializer, store, klass, adapterPayload, id, 'findRecord');
|
|
997
|
-
|
|
998
|
-
|
|
1086
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1087
|
+
if (!test) {
|
|
1088
|
+
throw new Error(`Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`);
|
|
1089
|
+
}
|
|
1090
|
+
})(!Array.isArray(payload.data)) : {};
|
|
1091
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1092
|
+
if (!test) {
|
|
1093
|
+
throw new Error(`The 'findRecord' request for ${modelName}:${id} resolved indicating success but contained no primary data. To indicate a 404 not found you should either reject the promise returned by the adapter's findRecord method or throw a NotFoundError.`);
|
|
1094
|
+
}
|
|
1095
|
+
})('data' in payload && payload.data !== null && typeof payload.data === 'object') : {};
|
|
999
1096
|
warn(`You requested a record of type '${modelName}' with id '${id}' but the adapter returned a payload with primary data having an id of '${payload.data.id}'. Use 'store.findRecord()' when the requested id is the same as the one returned by the adapter. In other cases use 'store.queryRecord()' instead.`, coerceId(payload.data.id) === coerceId(id), {
|
|
1000
1097
|
id: 'ds.store.findRecord.id-mismatch'
|
|
1001
1098
|
});
|
|
@@ -1013,7 +1110,11 @@ function _processCoalescedGroup(store, fetchMap, group, adapter, modelName) {
|
|
|
1013
1110
|
} else if (group.length === 1) {
|
|
1014
1111
|
_fetchRecord(store, adapter, fetchMap.get(group[0]));
|
|
1015
1112
|
} else {
|
|
1016
|
-
|
|
1113
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1114
|
+
{
|
|
1115
|
+
throw new Error("You cannot return an empty array from adapter's method groupRecordsForFindMany");
|
|
1116
|
+
}
|
|
1117
|
+
})() : {};
|
|
1017
1118
|
}
|
|
1018
1119
|
}
|
|
1019
1120
|
function _flushPendingFetchForType(store, pendingFetchMap, modelName) {
|
|
@@ -1069,11 +1170,23 @@ function _flushPendingSave(store, pending) {
|
|
|
1069
1170
|
const operation = options[SaveOp];
|
|
1070
1171
|
const modelName = snapshot.modelName;
|
|
1071
1172
|
const modelClass = store.modelFor(modelName);
|
|
1072
|
-
|
|
1073
|
-
|
|
1173
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1174
|
+
if (!test) {
|
|
1175
|
+
throw new Error(`You tried to update a record but you have no adapter (for ${modelName})`);
|
|
1176
|
+
}
|
|
1177
|
+
})(adapter) : {};
|
|
1178
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1179
|
+
if (!test) {
|
|
1180
|
+
throw new Error(`You tried to update a record but your adapter (for ${modelName}) does not implement '${operation}'`);
|
|
1181
|
+
}
|
|
1182
|
+
})(typeof adapter[operation] === 'function') : {};
|
|
1074
1183
|
let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot));
|
|
1075
1184
|
const serializer = store.serializerFor(modelName);
|
|
1076
|
-
|
|
1185
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1186
|
+
if (!test) {
|
|
1187
|
+
throw new Error(`Your adapter's '${operation}' method must return a value, but it returned 'undefined'`);
|
|
1188
|
+
}
|
|
1189
|
+
})(promise !== undefined) : {};
|
|
1077
1190
|
promise = promise.then(adapterPayload => {
|
|
1078
1191
|
if (adapterPayload) {
|
|
1079
1192
|
return normalizeResponseHelper(serializer, store, modelClass, adapterPayload, snapshot.id, operation);
|