@ember-data/legacy-compat 5.4.0-alpha.64 → 5.4.0-alpha.70
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/addon-main.cjs +5 -0
- package/{addon/-private-DmhhlB_x.js → dist/-private-DVN28hvw.js} +174 -61
- package/dist/-private-DVN28hvw.js.map +1 -0
- package/dist/-private.js +1 -0
- package/{addon → dist}/builders.js +68 -19
- package/dist/builders.js.map +1 -0
- package/{addon → dist}/index.js +224 -58
- package/dist/index.js.map +1 -0
- package/{addon → dist}/utils.js +5 -5
- package/dist/utils.js.map +1 -0
- package/package.json +41 -51
- package/unstable-preview-types/-private.d.ts +3 -3
- package/unstable-preview-types/-private.d.ts.map +1 -1
- package/unstable-preview-types/builders/find-all.d.ts +4 -1
- package/unstable-preview-types/builders/find-all.d.ts.map +1 -1
- package/unstable-preview-types/builders/find-record.d.ts +5 -2
- package/unstable-preview-types/builders/find-record.d.ts.map +1 -1
- package/unstable-preview-types/builders/query.d.ts +4 -1
- package/unstable-preview-types/builders/query.d.ts.map +1 -1
- package/unstable-preview-types/builders/save-record.d.ts +3 -0
- package/unstable-preview-types/builders/save-record.d.ts.map +1 -1
- package/unstable-preview-types/builders/utils.d.ts +1 -1
- package/unstable-preview-types/builders/utils.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +16 -15
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts +8 -8
- package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts +2 -2
- package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts +8 -8
- package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts +3 -3
- package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts +2 -2
- package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts +5 -6
- package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts.map +1 -1
- package/unstable-preview-types/legacy-network-handler/snapshot.d.ts +5 -5
- package/unstable-preview-types/legacy-network-handler/snapshot.d.ts.map +1 -1
- package/unstable-preview-types/utils.d.ts.map +1 -1
- package/addon/-private-DmhhlB_x.js.map +0 -1
- package/addon/-private.js +0 -1
- package/addon/builders.js.map +0 -1
- package/addon/index.js.map +0 -1
- package/addon/utils.js.map +0 -1
- package/addon-main.js +0 -94
- /package/{addon → dist}/-private.js.map +0 -0
package/{addon → dist}/index.js
RENAMED
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
import { getOwner } from '@ember/application';
|
|
2
|
-
import { assert } from '@ember/debug';
|
|
3
2
|
import { recordIdentifierFor } from '@ember-data/store';
|
|
4
3
|
import { _deprecatingNormalize } from '@ember-data/store/-private';
|
|
5
|
-
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, a as assertIdentifierHasId, S as SaveOp, b as SnapshotRecordArray } from "./-private-
|
|
6
|
-
import { macroCondition,
|
|
4
|
+
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, a as assertIdentifierHasId, S as SaveOp, b as SnapshotRecordArray } from "./-private-DVN28hvw";
|
|
5
|
+
import { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';
|
|
7
6
|
function _findHasMany(adapter, store, identifier, link, relationship, options) {
|
|
8
7
|
const promise = Promise.resolve().then(() => {
|
|
9
8
|
const snapshot = store._fetchManager.createSnapshot(identifier, options);
|
|
10
9
|
const useLink = !link || typeof link === 'string';
|
|
11
10
|
const relatedLink = useLink ? link : link.href;
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
12
|
+
if (!test) {
|
|
13
|
+
throw new Error(`Attempted to load a hasMany relationship from a specified 'link' in the original payload, but the specified link is empty. You must provide a valid 'link' in the original payload to use 'findHasMany'`);
|
|
14
|
+
}
|
|
15
|
+
})(relatedLink) : {};
|
|
16
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
17
|
+
if (!test) {
|
|
18
|
+
throw new Error(`Expected the adapter to implement 'findHasMany' but it does not`);
|
|
19
|
+
}
|
|
20
|
+
})(typeof adapter.findHasMany === 'function') : {};
|
|
14
21
|
return adapter.findHasMany(store, snapshot, relatedLink, relationship);
|
|
15
22
|
});
|
|
16
23
|
return promise.then(adapterPayload => {
|
|
17
|
-
|
|
24
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
25
|
+
if (!test) {
|
|
26
|
+
throw new Error(`You made a 'findHasMany' request for a ${identifier.type}'s '${relationship.name}' relationship, using link '${JSON.stringify(link)}' , but the adapter's response did not have any data`);
|
|
27
|
+
}
|
|
28
|
+
})(payloadIsNotBlank(adapterPayload)) : {};
|
|
18
29
|
const modelClass = store.modelFor(relationship.type);
|
|
19
30
|
const serializer = store.serializerFor(relationship.type);
|
|
20
31
|
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findHasMany');
|
|
21
|
-
|
|
32
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
33
|
+
if (!test) {
|
|
34
|
+
throw new Error(`fetched the hasMany relationship '${relationship.name}' for ${identifier.type}:${identifier.id} with link '${JSON.stringify(link)}', but no data member is present in the response. If no data exists, the response should set { data: [] }`);
|
|
35
|
+
}
|
|
36
|
+
})('data' in payload && Array.isArray(payload.data)) : {};
|
|
22
37
|
payload = syncRelationshipDataFromLink(store, payload, identifier, relationship);
|
|
23
38
|
return store._push(payload, true);
|
|
24
39
|
}, null);
|
|
@@ -26,19 +41,35 @@ function _findHasMany(adapter, store, identifier, link, relationship, options) {
|
|
|
26
41
|
function _findBelongsTo(store, identifier, link, relationship, options) {
|
|
27
42
|
const promise = Promise.resolve().then(() => {
|
|
28
43
|
const adapter = store.adapterFor(identifier.type);
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
45
|
+
if (!test) {
|
|
46
|
+
throw new Error(`You tried to load a belongsTo relationship but you have no adapter (for ${identifier.type})`);
|
|
47
|
+
}
|
|
48
|
+
})(adapter) : {};
|
|
49
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
50
|
+
if (!test) {
|
|
51
|
+
throw new Error(`You tried to load a belongsTo relationship from a specified 'link' in the original payload but your adapter does not implement 'findBelongsTo'`);
|
|
52
|
+
}
|
|
53
|
+
})(typeof adapter.findBelongsTo === 'function') : {};
|
|
31
54
|
const snapshot = store._fetchManager.createSnapshot(identifier, options);
|
|
32
55
|
const useLink = !link || typeof link === 'string';
|
|
33
56
|
const relatedLink = useLink ? link : link.href;
|
|
34
|
-
|
|
57
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
58
|
+
if (!test) {
|
|
59
|
+
throw new Error(`Attempted to load a belongsTo relationship from a specified 'link' in the original payload, but the specified link is empty. You must provide a valid 'link' in the original payload to use 'findBelongsTo'`);
|
|
60
|
+
}
|
|
61
|
+
})(relatedLink) : {};
|
|
35
62
|
return adapter.findBelongsTo(store, snapshot, relatedLink, relationship);
|
|
36
63
|
});
|
|
37
64
|
return promise.then(adapterPayload => {
|
|
38
65
|
const modelClass = store.modelFor(relationship.type);
|
|
39
66
|
const serializer = store.serializerFor(relationship.type);
|
|
40
67
|
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo');
|
|
41
|
-
|
|
68
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
69
|
+
if (!test) {
|
|
70
|
+
throw new Error(`fetched the belongsTo relationship '${relationship.name}' for ${identifier.type}:${identifier.id} with link '${JSON.stringify(link)}', but no data member is present in the response. If no data exists, the response should set { data: null }`);
|
|
71
|
+
}
|
|
72
|
+
})('data' in payload && (payload.data === null || typeof payload.data === 'object' && !Array.isArray(payload.data))) : {};
|
|
42
73
|
if (!payload.data && !payload.links && !payload.meta) {
|
|
43
74
|
return null;
|
|
44
75
|
}
|
|
@@ -111,7 +142,7 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
111
142
|
kind
|
|
112
143
|
} = inverse;
|
|
113
144
|
const relationshipData = relationships[inverseKey]?.data;
|
|
114
|
-
if (macroCondition(
|
|
145
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
115
146
|
if (typeof relationshipData !== 'undefined' && !relationshipDataPointsToParent(relationshipData, parentIdentifier)) {
|
|
116
147
|
const inspect = function inspect(thing) {
|
|
117
148
|
return `'${JSON.stringify(thing)}'`;
|
|
@@ -131,7 +162,11 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
131
162
|
const relationshipFetched = `${expectedModel}.${parentRelationship.kind}("${parentRelationship.name}")`;
|
|
132
163
|
const includedRecord = `<${type}:${id}>`;
|
|
133
164
|
const message = [`Encountered mismatched relationship: Ember Data 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.`, `Ember Data 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');
|
|
134
|
-
|
|
165
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
166
|
+
{
|
|
167
|
+
throw new Error(message);
|
|
168
|
+
}
|
|
169
|
+
})() : {};
|
|
135
170
|
}
|
|
136
171
|
}
|
|
137
172
|
if (kind !== 'hasMany' || typeof relationshipData !== 'undefined') {
|
|
@@ -141,11 +176,20 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
141
176
|
}
|
|
142
177
|
}
|
|
143
178
|
function inverseForRelationship(store, identifier, key) {
|
|
144
|
-
const definition = store.
|
|
179
|
+
const definition = store.schema.fields(identifier).get(key);
|
|
145
180
|
if (!definition) {
|
|
146
181
|
return null;
|
|
147
182
|
}
|
|
148
|
-
|
|
183
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
184
|
+
if (!test) {
|
|
185
|
+
throw new Error(`Expected the field definition to be a relationship`);
|
|
186
|
+
}
|
|
187
|
+
})(definition.kind === 'hasMany' || definition.kind === 'belongsTo') : {};
|
|
188
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
189
|
+
if (!test) {
|
|
190
|
+
throw new Error(`Expected the relationship defintion to specify the inverse type or null.`);
|
|
191
|
+
}
|
|
192
|
+
})(definition.options?.inverse === null || typeof definition.options?.inverse === 'string' && definition.options.inverse.length > 0) : {};
|
|
149
193
|
return definition.options.inverse;
|
|
150
194
|
}
|
|
151
195
|
function getInverse(store, parentIdentifier, parentRelationship, type) {
|
|
@@ -159,15 +203,17 @@ function getInverse(store, parentIdentifier, parentRelationship, type) {
|
|
|
159
203
|
type: parentType
|
|
160
204
|
}, lhs_relationshipName);
|
|
161
205
|
if (inverseKey) {
|
|
162
|
-
const definition = store.
|
|
206
|
+
const definition = store.schema.fields({
|
|
163
207
|
type
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
208
|
+
}).get(inverseKey);
|
|
209
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
210
|
+
if (!test) {
|
|
211
|
+
throw new Error(`Expected the field definition to be a relationship`);
|
|
212
|
+
}
|
|
213
|
+
})(definition && (definition.kind === 'hasMany' || definition.kind === 'belongsTo')) : {};
|
|
168
214
|
return {
|
|
169
215
|
inverseKey,
|
|
170
|
-
kind
|
|
216
|
+
kind: definition.kind
|
|
171
217
|
};
|
|
172
218
|
}
|
|
173
219
|
}
|
|
@@ -202,7 +248,11 @@ function fixRelationshipData(relationshipData, relationshipKind, {
|
|
|
202
248
|
if (relationshipKind === 'hasMany') {
|
|
203
249
|
const relData = relationshipData || [];
|
|
204
250
|
if (relationshipData) {
|
|
205
|
-
|
|
251
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
252
|
+
if (!test) {
|
|
253
|
+
throw new Error('expected the relationship data to be an array');
|
|
254
|
+
}
|
|
255
|
+
})(Array.isArray(relationshipData)) : {};
|
|
206
256
|
// these arrays could be massive so this is better than filter
|
|
207
257
|
// Note: this is potentially problematic if type/id are not in the
|
|
208
258
|
// same state of normalization.
|
|
@@ -288,10 +338,18 @@ function findBelongsTo(context) {
|
|
|
288
338
|
return pendingRequest;
|
|
289
339
|
}
|
|
290
340
|
if (useLink) {
|
|
291
|
-
|
|
341
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
342
|
+
if (!test) {
|
|
343
|
+
throw new Error(`Expected a related link when calling store.findBelongsTo, found ${String(links)}`);
|
|
344
|
+
}
|
|
345
|
+
})(links && links.related) : {};
|
|
292
346
|
return _findBelongsTo(store, record, links.related, field, options);
|
|
293
347
|
}
|
|
294
|
-
|
|
348
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
349
|
+
if (!test) {
|
|
350
|
+
throw new Error(`Expected an identifier`);
|
|
351
|
+
}
|
|
352
|
+
})(Array.isArray(identifiers) && identifiers.length === 1) : {};
|
|
295
353
|
const manager = store._fetchManager;
|
|
296
354
|
assertIdentifierHasId(identifier);
|
|
297
355
|
return options.reload ? manager.scheduleFetch(identifier, options, context.request) : manager.fetchDataIfNeededForIdentifier(identifier, options, context.request);
|
|
@@ -322,14 +380,30 @@ function findHasMany(context) {
|
|
|
322
380
|
The usual use-case is for the server to register a URL as a link, and
|
|
323
381
|
then use that URL in the future to make a request for the relationship.
|
|
324
382
|
*/
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
383
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
384
|
+
if (!test) {
|
|
385
|
+
throw new Error(`You tried to load a hasMany relationship but you have no adapter (for ${record.type})`);
|
|
386
|
+
}
|
|
387
|
+
})(adapter) : {};
|
|
388
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
389
|
+
if (!test) {
|
|
390
|
+
throw new Error(`You tried to load a hasMany relationship from a specified 'link' in the original payload but your adapter does not implement 'findHasMany'`);
|
|
391
|
+
}
|
|
392
|
+
})(typeof adapter.findHasMany === 'function') : {};
|
|
393
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
394
|
+
if (!test) {
|
|
395
|
+
throw new Error(`Expected a related link when calling store.findHasMany, found ${String(links)}`);
|
|
396
|
+
}
|
|
397
|
+
})(links && links.related) : {};
|
|
328
398
|
return _findHasMany(adapter, store, record, links.related, field, options);
|
|
329
399
|
}
|
|
330
400
|
|
|
331
401
|
// identifiers case
|
|
332
|
-
|
|
402
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
403
|
+
if (!test) {
|
|
404
|
+
throw new Error(`Expected an array of identifiers to fetch`);
|
|
405
|
+
}
|
|
406
|
+
})(Array.isArray(identifiers)) : {};
|
|
333
407
|
const fetches = new Array(identifiers.length);
|
|
334
408
|
const manager = store._fetchManager;
|
|
335
409
|
for (let i = 0; i < identifiers.length; i++) {
|
|
@@ -356,7 +430,7 @@ function saveRecord(context) {
|
|
|
356
430
|
}, options);
|
|
357
431
|
const fetchManagerPromise = store._fetchManager.scheduleSave(identifier, saveOptions);
|
|
358
432
|
return fetchManagerPromise.then(payload => {
|
|
359
|
-
if (macroCondition(
|
|
433
|
+
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
|
|
360
434
|
try {
|
|
361
435
|
const payloadCopy = payload ? JSON.parse(JSON.stringify(payload)) : payload;
|
|
362
436
|
// eslint-disable-next-line no-console
|
|
@@ -377,7 +451,7 @@ function saveRecord(context) {
|
|
|
377
451
|
|
|
378
452
|
// blatantly lie if we were a createRecord request
|
|
379
453
|
// to give some semblance of cache-control to the
|
|
380
|
-
//
|
|
454
|
+
// CachePolicy while legacy is still around
|
|
381
455
|
if (store.lifetimes?.didRequest && operation === 'createRecord') {
|
|
382
456
|
store.lifetimes.didRequest(context.request, {
|
|
383
457
|
status: 201
|
|
@@ -408,7 +482,11 @@ function adapterDidInvalidate(store, identifier, error) {
|
|
|
408
482
|
}
|
|
409
483
|
const cache = store.cache;
|
|
410
484
|
if (error.errors) {
|
|
411
|
-
|
|
485
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
486
|
+
if (!test) {
|
|
487
|
+
throw new Error(`Expected the cache in use by resource ${String(identifier)} to have a getErrors(identifier) method for retrieving errors.`);
|
|
488
|
+
}
|
|
489
|
+
})(typeof cache.getErrors === 'function') : {};
|
|
412
490
|
let jsonApiErrors = error.errors;
|
|
413
491
|
if (jsonApiErrors.length === 0) {
|
|
414
492
|
jsonApiErrors = [{
|
|
@@ -478,7 +556,7 @@ function findRecord(context) {
|
|
|
478
556
|
// Refetch the record if the adapter thinks the record is stale
|
|
479
557
|
if (typeof options.reload === 'undefined' && adapter.shouldReloadRecord && adapter.shouldReloadRecord(store, snapshot = store._fetchManager.createSnapshot(identifier, options))) {
|
|
480
558
|
assertIdentifierHasId(identifier);
|
|
481
|
-
if (macroCondition(
|
|
559
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
482
560
|
promise = store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
|
|
483
561
|
reload: true
|
|
484
562
|
}), context.request);
|
|
@@ -490,7 +568,7 @@ function findRecord(context) {
|
|
|
490
568
|
// Trigger the background refetch if backgroundReload option is passed
|
|
491
569
|
if (options.backgroundReload !== false && (options.backgroundReload || !adapter.shouldBackgroundReloadRecord || adapter.shouldBackgroundReloadRecord(store, snapshot = snapshot || store._fetchManager.createSnapshot(identifier, options)))) {
|
|
492
570
|
assertIdentifierHasId(identifier);
|
|
493
|
-
if (macroCondition(
|
|
571
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
494
572
|
void store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
|
|
495
573
|
backgroundReload: true
|
|
496
574
|
}), context.request);
|
|
@@ -516,8 +594,16 @@ function findAll(context) {
|
|
|
516
594
|
options
|
|
517
595
|
} = data;
|
|
518
596
|
const adapter = store.adapterFor(type);
|
|
519
|
-
|
|
520
|
-
|
|
597
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
598
|
+
if (!test) {
|
|
599
|
+
throw new Error(`You tried to load all records but you have no adapter (for ${type})`);
|
|
600
|
+
}
|
|
601
|
+
})(adapter) : {};
|
|
602
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
603
|
+
if (!test) {
|
|
604
|
+
throw new Error(`You tried to load all records but your adapter does not implement 'findAll'`);
|
|
605
|
+
}
|
|
606
|
+
})(typeof adapter.findAll === 'function') : {};
|
|
521
607
|
|
|
522
608
|
// avoid initializing the liveArray just to set `isUpdating`
|
|
523
609
|
const maybeRecordArray = store.recordArrayManager._live.get(type);
|
|
@@ -540,18 +626,22 @@ function _findAll(adapter, store, type, snapshotArray, request, isAsyncFlush) {
|
|
|
540
626
|
const schema = store.modelFor(type);
|
|
541
627
|
let promise = Promise.resolve().then(() => adapter.findAll(store, schema, null, snapshotArray));
|
|
542
628
|
promise = promise.then(adapterPayload => {
|
|
543
|
-
|
|
629
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
630
|
+
if (!test) {
|
|
631
|
+
throw new Error(`You made a 'findAll' request for '${type}' records, but the adapter's response did not have any data`);
|
|
632
|
+
}
|
|
633
|
+
})(payloadIsNotBlank(adapterPayload)) : {};
|
|
544
634
|
const serializer = store.serializerFor(type);
|
|
545
635
|
const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'findAll');
|
|
546
636
|
store._push(payload, isAsyncFlush);
|
|
547
637
|
snapshotArray._recordArray.isUpdating = false;
|
|
548
|
-
if (macroCondition(
|
|
638
|
+
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
|
|
549
639
|
// eslint-disable-next-line no-console
|
|
550
640
|
console.log(`request: findAll<${type}> background reload complete`);
|
|
551
641
|
}
|
|
552
642
|
return snapshotArray._recordArray;
|
|
553
643
|
});
|
|
554
|
-
if (macroCondition(
|
|
644
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
555
645
|
if (!request.disableTestWaiter) {
|
|
556
646
|
const {
|
|
557
647
|
waitForPromise
|
|
@@ -575,13 +665,21 @@ function query(context) {
|
|
|
575
665
|
query
|
|
576
666
|
} = data;
|
|
577
667
|
const adapter = store.adapterFor(type);
|
|
578
|
-
|
|
579
|
-
|
|
668
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
669
|
+
if (!test) {
|
|
670
|
+
throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
|
|
671
|
+
}
|
|
672
|
+
})(adapter) : {};
|
|
673
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
674
|
+
if (!test) {
|
|
675
|
+
throw new Error(`You tried to make a query but your adapter does not implement 'query'`);
|
|
676
|
+
}
|
|
677
|
+
})(typeof adapter.query === 'function') : {};
|
|
580
678
|
const recordArray = options._recordArray || store.recordArrayManager.createArray({
|
|
581
679
|
type,
|
|
582
680
|
query
|
|
583
681
|
});
|
|
584
|
-
if (macroCondition(
|
|
682
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
585
683
|
options = Object.assign({}, options);
|
|
586
684
|
delete options._recordArray;
|
|
587
685
|
} else {
|
|
@@ -593,13 +691,21 @@ function query(context) {
|
|
|
593
691
|
const serializer = store.serializerFor(type);
|
|
594
692
|
const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'query');
|
|
595
693
|
const identifiers = store._push(payload, true);
|
|
596
|
-
|
|
694
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
695
|
+
if (!test) {
|
|
696
|
+
throw new Error('The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use `store.queryRecord` to query for a single record.');
|
|
697
|
+
}
|
|
698
|
+
})(Array.isArray(identifiers)) : {};
|
|
597
699
|
store.recordArrayManager.populateManagedArray(recordArray, identifiers, payload);
|
|
598
700
|
return recordArray;
|
|
599
701
|
});
|
|
600
702
|
}
|
|
601
703
|
function assertSingleResourceDocument(payload) {
|
|
602
|
-
|
|
704
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
705
|
+
if (!test) {
|
|
706
|
+
throw new Error(`Expected the primary data returned by the serializer for a 'queryRecord' response to be a single object or null but instead it was an array.`);
|
|
707
|
+
}
|
|
708
|
+
})(!Array.isArray(payload.data)) : {};
|
|
603
709
|
}
|
|
604
710
|
function queryRecord(context) {
|
|
605
711
|
const {
|
|
@@ -613,8 +719,16 @@ function queryRecord(context) {
|
|
|
613
719
|
options
|
|
614
720
|
} = data;
|
|
615
721
|
const adapter = store.adapterFor(type);
|
|
616
|
-
|
|
617
|
-
|
|
722
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
723
|
+
if (!test) {
|
|
724
|
+
throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
|
|
725
|
+
}
|
|
726
|
+
})(adapter) : {};
|
|
727
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
728
|
+
if (!test) {
|
|
729
|
+
throw new Error(`You tried to make a query but your adapter does not implement 'queryRecord'`);
|
|
730
|
+
}
|
|
731
|
+
})(typeof adapter.queryRecord === 'function') : {};
|
|
618
732
|
const schema = store.modelFor(type);
|
|
619
733
|
const promise = Promise.resolve().then(() => adapter.queryRecord(store, schema, query, options));
|
|
620
734
|
return promise.then(adapterPayload => {
|
|
@@ -647,9 +761,21 @@ function queryRecord(context) {
|
|
|
647
761
|
*/
|
|
648
762
|
|
|
649
763
|
function adapterFor(modelName, _allowMissing) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
764
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
765
|
+
if (!test) {
|
|
766
|
+
throw new Error(`Attempted to call store.adapterFor(), but the store instance has already been destroyed.`);
|
|
767
|
+
}
|
|
768
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
769
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
770
|
+
if (!test) {
|
|
771
|
+
throw new Error(`You need to pass a model name to the store's adapterFor method`);
|
|
772
|
+
}
|
|
773
|
+
})(modelName) : {};
|
|
774
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
775
|
+
if (!test) {
|
|
776
|
+
throw new Error(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${modelName}`);
|
|
777
|
+
}
|
|
778
|
+
})(typeof modelName === 'string') : {};
|
|
653
779
|
this._adapterCache = this._adapterCache || Object.create(null);
|
|
654
780
|
const normalizedModelName = _deprecatingNormalize(modelName);
|
|
655
781
|
const {
|
|
@@ -675,7 +801,11 @@ function adapterFor(modelName, _allowMissing) {
|
|
|
675
801
|
_adapterCache.application = adapter;
|
|
676
802
|
return adapter;
|
|
677
803
|
}
|
|
678
|
-
|
|
804
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
805
|
+
if (!test) {
|
|
806
|
+
throw new Error(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`);
|
|
807
|
+
}
|
|
808
|
+
})(_allowMissing) : {};
|
|
679
809
|
}
|
|
680
810
|
|
|
681
811
|
/**
|
|
@@ -696,9 +826,21 @@ function adapterFor(modelName, _allowMissing) {
|
|
|
696
826
|
@return {Serializer}
|
|
697
827
|
*/
|
|
698
828
|
function serializerFor(modelName) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
829
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
830
|
+
if (!test) {
|
|
831
|
+
throw new Error(`Attempted to call store.serializerFor(), but the store instance has already been destroyed.`);
|
|
832
|
+
}
|
|
833
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
834
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
835
|
+
if (!test) {
|
|
836
|
+
throw new Error(`You need to pass a model name to the store's serializerFor method`);
|
|
837
|
+
}
|
|
838
|
+
})(modelName) : {};
|
|
839
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
840
|
+
if (!test) {
|
|
841
|
+
throw new Error(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${modelName}`);
|
|
842
|
+
}
|
|
843
|
+
})(typeof modelName === 'string') : {};
|
|
702
844
|
this._serializerCache = this._serializerCache || Object.create(null);
|
|
703
845
|
const normalizedModelName = _deprecatingNormalize(modelName);
|
|
704
846
|
const {
|
|
@@ -749,13 +891,29 @@ function serializerFor(modelName) {
|
|
|
749
891
|
*/
|
|
750
892
|
// TODO @runspired @deprecate users should call normalize on the associated serializer directly
|
|
751
893
|
function normalize(modelName, payload) {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
894
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
895
|
+
if (!test) {
|
|
896
|
+
throw new Error(`Attempted to call store.normalize(), but the store instance has already been destroyed.`);
|
|
897
|
+
}
|
|
898
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
899
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
900
|
+
if (!test) {
|
|
901
|
+
throw new Error(`You need to pass a model name to the store's normalize method`);
|
|
902
|
+
}
|
|
903
|
+
})(modelName) : {};
|
|
904
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
905
|
+
if (!test) {
|
|
906
|
+
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${typeof modelName}`);
|
|
907
|
+
}
|
|
908
|
+
})(typeof modelName === 'string') : {};
|
|
755
909
|
const normalizedModelName = _deprecatingNormalize(modelName);
|
|
756
910
|
const serializer = this.serializerFor(normalizedModelName);
|
|
757
911
|
const schema = this.modelFor(normalizedModelName);
|
|
758
|
-
|
|
912
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
913
|
+
if (!test) {
|
|
914
|
+
throw new Error(`You must define a normalize method in your serializer in order to call store.normalize`);
|
|
915
|
+
}
|
|
916
|
+
})(typeof serializer?.normalize === 'function') : {};
|
|
759
917
|
return serializer.normalize(schema, payload);
|
|
760
918
|
}
|
|
761
919
|
|
|
@@ -817,11 +975,19 @@ function normalize(modelName, payload) {
|
|
|
817
975
|
*/
|
|
818
976
|
// TODO @runspired @deprecate pushPayload in favor of looking up the serializer
|
|
819
977
|
function pushPayload(modelName, inputPayload) {
|
|
820
|
-
|
|
978
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
979
|
+
if (!test) {
|
|
980
|
+
throw new Error(`Attempted to call store.pushPayload(), but the store instance has already been destroyed.`);
|
|
981
|
+
}
|
|
982
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
821
983
|
const payload = inputPayload || modelName;
|
|
822
984
|
const normalizedModelName = inputPayload ? _deprecatingNormalize(modelName) : 'application';
|
|
823
985
|
const serializer = this.serializerFor(normalizedModelName);
|
|
824
|
-
|
|
986
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
987
|
+
if (!test) {
|
|
988
|
+
throw new Error(`You cannot use 'store.pushPayload(<type>, <payload>)' unless the serializer for '${normalizedModelName}' defines 'pushPayload'`);
|
|
989
|
+
}
|
|
990
|
+
})(serializer && typeof serializer.pushPayload === 'function') : {};
|
|
825
991
|
serializer.pushPayload(this, payload);
|
|
826
992
|
}
|
|
827
993
|
|