@ember-data/legacy-compat 5.4.0-beta.2 → 5.4.0-beta.20
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 +19 -7
- package/README.md +10 -2
- package/addon-main.cjs +5 -0
- package/{addon/-private-1aicprWG.js → dist/-private-Dlia0pw1.js} +177 -63
- package/dist/-private-Dlia0pw1.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 +250 -84
- package/dist/index.js.map +1 -0
- package/dist/utils.js +246 -0
- package/dist/utils.js.map +1 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +55 -88
- 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/{ember-data-logo-dark.svg → logos/ember-data-logo-dark.svg} +0 -0
- /package/{ember-data-logo-light.svg → logos/ember-data-logo-light.svg} +0 -0
package/LICENSE.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Copyright (c) 2017-2025 Ember.js and contributors
|
|
4
|
+
Copyright (c) 2011-2017 Tilde, Inc. and contributors
|
|
5
|
+
Copyright (c) 2011 LivingSocial Inc.
|
|
6
6
|
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
8
13
|
|
|
9
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
10
16
|
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<img
|
|
3
3
|
class="project-logo"
|
|
4
|
-
src="./ember-data-logo-dark.svg#gh-dark-mode-only"
|
|
4
|
+
src="./logos/ember-data-logo-dark.svg#gh-dark-mode-only"
|
|
5
5
|
alt="EmberData LegacyCompat"
|
|
6
6
|
width="240px"
|
|
7
7
|
title="EmberData LegacyCompat"
|
|
8
8
|
/>
|
|
9
9
|
<img
|
|
10
10
|
class="project-logo"
|
|
11
|
-
src="./ember-data-logo-light.svg#gh-light-mode-only"
|
|
11
|
+
src="./logos/ember-data-logo-light.svg#gh-light-mode-only"
|
|
12
12
|
alt="EmberData LegacyCompat"
|
|
13
13
|
width="240px"
|
|
14
14
|
title="EmberData LegacyCompat"
|
|
@@ -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) {
|
|
@@ -276,6 +285,7 @@ class Snapshot {
|
|
|
276
285
|
the values.
|
|
277
286
|
*/
|
|
278
287
|
if (hasRecord) {
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
279
289
|
this._attributes;
|
|
280
290
|
}
|
|
281
291
|
|
|
@@ -335,7 +345,11 @@ class Snapshot {
|
|
|
335
345
|
*/
|
|
336
346
|
get record() {
|
|
337
347
|
const record = this._store.peekRecord(this.identifier);
|
|
338
|
-
|
|
348
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
349
|
+
if (!test) {
|
|
350
|
+
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`);
|
|
351
|
+
}
|
|
352
|
+
})(record !== null) : {};
|
|
339
353
|
return record;
|
|
340
354
|
}
|
|
341
355
|
get _attributes() {
|
|
@@ -346,10 +360,12 @@ class Snapshot {
|
|
|
346
360
|
const {
|
|
347
361
|
identifier
|
|
348
362
|
} = this;
|
|
349
|
-
const attrs =
|
|
363
|
+
const attrs = this._store.schema.fields(identifier);
|
|
350
364
|
const cache = this._store.cache;
|
|
351
|
-
attrs.forEach(keyName => {
|
|
352
|
-
|
|
365
|
+
attrs.forEach((field, keyName) => {
|
|
366
|
+
if (field.kind === 'attribute') {
|
|
367
|
+
attributes[keyName] = cache.getAttr(identifier, keyName);
|
|
368
|
+
}
|
|
353
369
|
});
|
|
354
370
|
return attributes;
|
|
355
371
|
}
|
|
@@ -376,7 +392,11 @@ class Snapshot {
|
|
|
376
392
|
if (keyName in this._attributes) {
|
|
377
393
|
return this._attributes[keyName];
|
|
378
394
|
}
|
|
379
|
-
|
|
395
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
396
|
+
{
|
|
397
|
+
throw new Error(`Model '${this.identifier.lid}' has no attribute named '${keyName}' defined.`);
|
|
398
|
+
}
|
|
399
|
+
})() : {};
|
|
380
400
|
}
|
|
381
401
|
|
|
382
402
|
/**
|
|
@@ -459,27 +479,35 @@ class Snapshot {
|
|
|
459
479
|
if (returnModeIsId === false && keyName in this._belongsToRelationships) {
|
|
460
480
|
return this._belongsToRelationships[keyName];
|
|
461
481
|
}
|
|
462
|
-
const relationshipMeta = store.
|
|
482
|
+
const relationshipMeta = store.schema.fields({
|
|
463
483
|
type: this.modelName
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
484
|
+
}).get(keyName);
|
|
485
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
486
|
+
if (!test) {
|
|
487
|
+
throw new Error(`Model '${this.identifier.lid}' has no belongsTo relationship named '${keyName}' defined.`);
|
|
488
|
+
}
|
|
489
|
+
})(relationshipMeta && relationshipMeta.kind === 'belongsTo') : {};
|
|
490
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
491
|
+
if (!test) {
|
|
492
|
+
throw new Error(`snapshot.belongsTo only supported when using the package @ember-data/graph`);
|
|
493
|
+
}
|
|
494
|
+
})(dependencySatisfies('@ember-data/graph', '*')) : {};
|
|
475
495
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
476
496
|
const {
|
|
477
497
|
identifier
|
|
478
498
|
} = this;
|
|
479
|
-
if (macroCondition(
|
|
499
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
480
500
|
const relationship = graphFor(this._store).get(identifier, keyName);
|
|
481
|
-
|
|
482
|
-
|
|
501
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
502
|
+
if (!test) {
|
|
503
|
+
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.`);
|
|
504
|
+
}
|
|
505
|
+
})(relationship) : {};
|
|
506
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
507
|
+
if (!test) {
|
|
508
|
+
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.`);
|
|
509
|
+
}
|
|
510
|
+
})(relationship.definition.kind === 'belongsTo') : {};
|
|
483
511
|
}
|
|
484
512
|
const value = graphFor(this._store).getData(identifier, keyName);
|
|
485
513
|
const data = value && value.data;
|
|
@@ -539,27 +567,41 @@ class Snapshot {
|
|
|
539
567
|
return cachedSnapshots;
|
|
540
568
|
}
|
|
541
569
|
const store = this._store;
|
|
542
|
-
const relationshipMeta = store.
|
|
570
|
+
const relationshipMeta = store.schema.fields({
|
|
543
571
|
type: this.modelName
|
|
544
|
-
})
|
|
545
|
-
|
|
572
|
+
}).get(keyName);
|
|
573
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
574
|
+
if (!test) {
|
|
575
|
+
throw new Error(`Model '${this.identifier.lid}' has no hasMany relationship named '${keyName}' defined.`);
|
|
576
|
+
}
|
|
577
|
+
})(relationshipMeta && relationshipMeta.kind === 'hasMany') : {};
|
|
546
578
|
|
|
547
579
|
// TODO @runspired it seems this code branch would not work with CUSTOM_MODEL_CLASSes
|
|
548
580
|
// this check is not a regression in behavior because relationships don't currently
|
|
549
581
|
// function without access to intimate API contracts between RecordData and Model.
|
|
550
582
|
// This is a requirement we should fix as soon as the relationship layer does not require
|
|
551
583
|
// this intimate API usage.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
584
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
585
|
+
if (!test) {
|
|
586
|
+
throw new Error(`snapshot.hasMany only supported when using the package @ember-data/graph`);
|
|
587
|
+
}
|
|
588
|
+
})(dependencySatisfies('@ember-data/graph', '*')) : {};
|
|
555
589
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
556
590
|
const {
|
|
557
591
|
identifier
|
|
558
592
|
} = this;
|
|
559
|
-
if (macroCondition(
|
|
593
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
560
594
|
const relationship = graphFor(this._store).get(identifier, keyName);
|
|
561
|
-
|
|
562
|
-
|
|
595
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
596
|
+
if (!test) {
|
|
597
|
+
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.`);
|
|
598
|
+
}
|
|
599
|
+
})(relationship) : {};
|
|
600
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
601
|
+
if (!test) {
|
|
602
|
+
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.`);
|
|
603
|
+
}
|
|
604
|
+
})(relationship.definition.kind === 'hasMany') : {};
|
|
563
605
|
}
|
|
564
606
|
const value = graphFor(this._store).getData(identifier, keyName);
|
|
565
607
|
if (value.data) {
|
|
@@ -602,9 +644,11 @@ class Snapshot {
|
|
|
602
644
|
@public
|
|
603
645
|
*/
|
|
604
646
|
eachAttribute(callback, binding) {
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
647
|
+
const fields = this._store.schema.fields(this.identifier);
|
|
648
|
+
fields.forEach((field, key) => {
|
|
649
|
+
if (field.kind === 'attribute') {
|
|
650
|
+
callback.call(binding, key, field);
|
|
651
|
+
}
|
|
608
652
|
});
|
|
609
653
|
}
|
|
610
654
|
|
|
@@ -623,9 +667,11 @@ class Snapshot {
|
|
|
623
667
|
@public
|
|
624
668
|
*/
|
|
625
669
|
eachRelationship(callback, binding) {
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
670
|
+
const fields = this._store.schema.fields(this.identifier);
|
|
671
|
+
fields.forEach((field, key) => {
|
|
672
|
+
if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
|
|
673
|
+
callback.call(binding, key, field);
|
|
674
|
+
}
|
|
629
675
|
});
|
|
630
676
|
}
|
|
631
677
|
|
|
@@ -653,11 +699,15 @@ class Snapshot {
|
|
|
653
699
|
serialize(options) {
|
|
654
700
|
upgradeStore(this._store);
|
|
655
701
|
const serializer = this._store.serializerFor(this.modelName);
|
|
656
|
-
|
|
702
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
703
|
+
if (!test) {
|
|
704
|
+
throw new Error(`Cannot serialize record, no serializer found`);
|
|
705
|
+
}
|
|
706
|
+
})(serializer) : {};
|
|
657
707
|
return serializer.serialize(this, options);
|
|
658
708
|
}
|
|
659
709
|
}
|
|
660
|
-
const SaveOp = Symbol('SaveOp');
|
|
710
|
+
const SaveOp = getOrSetGlobal('SaveOp', Symbol('SaveOp'));
|
|
661
711
|
class FetchManager {
|
|
662
712
|
// fetches pending in the runloop, waiting to be coalesced
|
|
663
713
|
|
|
@@ -740,11 +790,15 @@ class FetchManager {
|
|
|
740
790
|
}
|
|
741
791
|
return identifier;
|
|
742
792
|
}, error => {
|
|
743
|
-
|
|
793
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
794
|
+
if (!test) {
|
|
795
|
+
throw new Error(`Async Leak Detected: Expected the store to not be destroyed`);
|
|
796
|
+
}
|
|
797
|
+
})(!store.isDestroyed) : {};
|
|
744
798
|
const cache = store.cache;
|
|
745
799
|
if (!cache || cache.isEmpty(identifier) || isInitialLoad) {
|
|
746
800
|
let isReleasable = true;
|
|
747
|
-
if (macroCondition(
|
|
801
|
+
if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
|
|
748
802
|
if (!cache) {
|
|
749
803
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
750
804
|
const graph = graphFor(store);
|
|
@@ -779,7 +833,7 @@ class FetchManager {
|
|
|
779
833
|
fetchesById.set(identifier, requestsForIdentifier);
|
|
780
834
|
}
|
|
781
835
|
requestsForIdentifier.push(pendingFetchItem);
|
|
782
|
-
if (macroCondition(
|
|
836
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
783
837
|
if (!request.disableTestWaiter) {
|
|
784
838
|
const {
|
|
785
839
|
waitForPromise
|
|
@@ -816,7 +870,7 @@ class FetchManager {
|
|
|
816
870
|
let promise;
|
|
817
871
|
if (isEmpty) {
|
|
818
872
|
assertIdentifierHasId(identifier);
|
|
819
|
-
if (macroCondition(
|
|
873
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
820
874
|
promise = this.scheduleFetch(identifier, Object.assign({}, options, {
|
|
821
875
|
reload: true
|
|
822
876
|
}), request);
|
|
@@ -826,7 +880,11 @@ class FetchManager {
|
|
|
826
880
|
}
|
|
827
881
|
} else if (isLoading) {
|
|
828
882
|
promise = this.getPendingFetch(identifier, options);
|
|
829
|
-
|
|
883
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
884
|
+
if (!test) {
|
|
885
|
+
throw new Error(`Expected to find a pending request for a record in the loading state, but found none`);
|
|
886
|
+
}
|
|
887
|
+
})(promise) : {};
|
|
830
888
|
} else {
|
|
831
889
|
promise = Promise.resolve(identifier);
|
|
832
890
|
}
|
|
@@ -894,15 +952,31 @@ function _findMany(store, adapter, modelName, snapshots) {
|
|
|
894
952
|
const modelClass = store.modelFor(modelName); // `adapter.findMany` gets the modelClass still
|
|
895
953
|
const promise = Promise.resolve().then(() => {
|
|
896
954
|
const ids = snapshots.map(s => s.id);
|
|
897
|
-
|
|
955
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
956
|
+
if (!test) {
|
|
957
|
+
throw new Error(`Cannot fetch a record without an id`);
|
|
958
|
+
}
|
|
959
|
+
})(ids.every(v => v !== null)) : {};
|
|
898
960
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
899
|
-
|
|
961
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
962
|
+
if (!test) {
|
|
963
|
+
throw new Error(`Expected this adapter to implement findMany for coalescing`);
|
|
964
|
+
}
|
|
965
|
+
})(adapter.findMany) : {};
|
|
900
966
|
const ret = adapter.findMany(store, modelClass, ids, snapshots);
|
|
901
|
-
|
|
967
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
968
|
+
if (!test) {
|
|
969
|
+
throw new Error('adapter.findMany returned undefined, this was very likely a mistake');
|
|
970
|
+
}
|
|
971
|
+
})(ret !== undefined) : {};
|
|
902
972
|
return ret;
|
|
903
973
|
});
|
|
904
974
|
return promise.then(adapterPayload => {
|
|
905
|
-
|
|
975
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
976
|
+
if (!test) {
|
|
977
|
+
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`);
|
|
978
|
+
}
|
|
979
|
+
})(!!payloadIsNotBlank(adapterPayload)) : {};
|
|
906
980
|
const serializer = store.serializerFor(modelName);
|
|
907
981
|
const payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany');
|
|
908
982
|
return payload;
|
|
@@ -981,8 +1055,16 @@ function handleFoundRecords(store, fetchMap, snapshots, coalescedPayload) {
|
|
|
981
1055
|
function _fetchRecord(store, adapter, fetchItem) {
|
|
982
1056
|
const identifier = fetchItem.identifier;
|
|
983
1057
|
const modelName = identifier.type;
|
|
984
|
-
|
|
985
|
-
|
|
1058
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1059
|
+
if (!test) {
|
|
1060
|
+
throw new Error(`You tried to find a record but you have no adapter (for ${modelName})`);
|
|
1061
|
+
}
|
|
1062
|
+
})(adapter) : {};
|
|
1063
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1064
|
+
if (!test) {
|
|
1065
|
+
throw new Error(`You tried to find a record but your adapter (for ${modelName}) does not implement 'findRecord'`);
|
|
1066
|
+
}
|
|
1067
|
+
})(typeof adapter.findRecord === 'function') : {};
|
|
986
1068
|
const snapshot = store._fetchManager.createSnapshot(identifier, fetchItem.options);
|
|
987
1069
|
const klass = store.modelFor(identifier.type);
|
|
988
1070
|
const id = identifier.id;
|
|
@@ -990,12 +1072,28 @@ function _fetchRecord(store, adapter, fetchItem) {
|
|
|
990
1072
|
return adapter.findRecord(store, klass, identifier.id, snapshot);
|
|
991
1073
|
});
|
|
992
1074
|
promise = promise.then(adapterPayload => {
|
|
993
|
-
|
|
994
|
-
|
|
1075
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1076
|
+
if (!test) {
|
|
1077
|
+
throw new Error(`Async Leak Detected: Expected the store to not be destroyed`);
|
|
1078
|
+
}
|
|
1079
|
+
})(!(store.isDestroyed || store.isDestroying)) : {};
|
|
1080
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1081
|
+
if (!test) {
|
|
1082
|
+
throw new Error(`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`);
|
|
1083
|
+
}
|
|
1084
|
+
})(!!payloadIsNotBlank(adapterPayload)) : {};
|
|
995
1085
|
const serializer = store.serializerFor(modelName);
|
|
996
1086
|
const payload = normalizeResponseHelper(serializer, store, klass, adapterPayload, id, 'findRecord');
|
|
997
|
-
|
|
998
|
-
|
|
1087
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1088
|
+
if (!test) {
|
|
1089
|
+
throw new Error(`Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`);
|
|
1090
|
+
}
|
|
1091
|
+
})(!Array.isArray(payload.data)) : {};
|
|
1092
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1093
|
+
if (!test) {
|
|
1094
|
+
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.`);
|
|
1095
|
+
}
|
|
1096
|
+
})('data' in payload && payload.data !== null && typeof payload.data === 'object') : {};
|
|
999
1097
|
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
1098
|
id: 'ds.store.findRecord.id-mismatch'
|
|
1001
1099
|
});
|
|
@@ -1013,7 +1111,11 @@ function _processCoalescedGroup(store, fetchMap, group, adapter, modelName) {
|
|
|
1013
1111
|
} else if (group.length === 1) {
|
|
1014
1112
|
_fetchRecord(store, adapter, fetchMap.get(group[0]));
|
|
1015
1113
|
} else {
|
|
1016
|
-
|
|
1114
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1115
|
+
{
|
|
1116
|
+
throw new Error("You cannot return an empty array from adapter's method groupRecordsForFindMany");
|
|
1117
|
+
}
|
|
1118
|
+
})() : {};
|
|
1017
1119
|
}
|
|
1018
1120
|
}
|
|
1019
1121
|
function _flushPendingFetchForType(store, pendingFetchMap, modelName) {
|
|
@@ -1069,11 +1171,23 @@ function _flushPendingSave(store, pending) {
|
|
|
1069
1171
|
const operation = options[SaveOp];
|
|
1070
1172
|
const modelName = snapshot.modelName;
|
|
1071
1173
|
const modelClass = store.modelFor(modelName);
|
|
1072
|
-
|
|
1073
|
-
|
|
1174
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1175
|
+
if (!test) {
|
|
1176
|
+
throw new Error(`You tried to update a record but you have no adapter (for ${modelName})`);
|
|
1177
|
+
}
|
|
1178
|
+
})(adapter) : {};
|
|
1179
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1180
|
+
if (!test) {
|
|
1181
|
+
throw new Error(`You tried to update a record but your adapter (for ${modelName}) does not implement '${operation}'`);
|
|
1182
|
+
}
|
|
1183
|
+
})(typeof adapter[operation] === 'function') : {};
|
|
1074
1184
|
let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot));
|
|
1075
1185
|
const serializer = store.serializerFor(modelName);
|
|
1076
|
-
|
|
1186
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1187
|
+
if (!test) {
|
|
1188
|
+
throw new Error(`Your adapter's '${operation}' method must return a value, but it returned 'undefined'`);
|
|
1189
|
+
}
|
|
1190
|
+
})(promise !== undefined) : {};
|
|
1077
1191
|
promise = promise.then(adapterPayload => {
|
|
1078
1192
|
if (adapterPayload) {
|
|
1079
1193
|
return normalizeResponseHelper(serializer, store, modelClass, adapterPayload, snapshot.id, operation);
|