@ember-data/legacy-compat 5.4.0-beta.2 → 5.4.0-beta.21
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/{addon → dist}/index.js
RENAMED
|
@@ -1,49 +1,81 @@
|
|
|
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,
|
|
6
|
-
import { macroCondition,
|
|
4
|
+
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-Dlia0pw1.js";
|
|
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;
|
|
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') : {};
|
|
12
21
|
return adapter.findHasMany(store, snapshot, relatedLink, relationship);
|
|
13
22
|
});
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
return promise.then(adapterPayload => {
|
|
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)) : {};
|
|
16
29
|
const modelClass = store.modelFor(relationship.type);
|
|
17
30
|
const serializer = store.serializerFor(relationship.type);
|
|
18
31
|
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findHasMany');
|
|
19
|
-
|
|
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)) : {};
|
|
20
37
|
payload = syncRelationshipDataFromLink(store, payload, identifier, relationship);
|
|
21
38
|
return store._push(payload, true);
|
|
22
|
-
}, null
|
|
23
|
-
return promise;
|
|
39
|
+
}, null);
|
|
24
40
|
}
|
|
25
41
|
function _findBelongsTo(store, identifier, link, relationship, options) {
|
|
26
|
-
|
|
42
|
+
const promise = Promise.resolve().then(() => {
|
|
27
43
|
const adapter = store.adapterFor(identifier.type);
|
|
28
|
-
|
|
29
|
-
|
|
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') : {};
|
|
30
54
|
const snapshot = store._fetchManager.createSnapshot(identifier, options);
|
|
31
55
|
const useLink = !link || typeof link === 'string';
|
|
32
56
|
const relatedLink = useLink ? link : link.href;
|
|
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) : {};
|
|
33
62
|
return adapter.findBelongsTo(store, snapshot, relatedLink, relationship);
|
|
34
63
|
});
|
|
35
|
-
|
|
64
|
+
return promise.then(adapterPayload => {
|
|
36
65
|
const modelClass = store.modelFor(relationship.type);
|
|
37
66
|
const serializer = store.serializerFor(relationship.type);
|
|
38
67
|
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo');
|
|
39
|
-
|
|
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))) : {};
|
|
40
73
|
if (!payload.data && !payload.links && !payload.meta) {
|
|
41
74
|
return null;
|
|
42
75
|
}
|
|
43
76
|
payload = syncRelationshipDataFromLink(store, payload, identifier, relationship);
|
|
44
77
|
return store._push(payload, true);
|
|
45
|
-
}, null
|
|
46
|
-
return promise;
|
|
78
|
+
}, null);
|
|
47
79
|
}
|
|
48
80
|
|
|
49
81
|
// sync
|
|
@@ -109,8 +141,8 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
109
141
|
inverseKey,
|
|
110
142
|
kind
|
|
111
143
|
} = inverse;
|
|
112
|
-
const relationshipData = relationships[inverseKey]
|
|
113
|
-
if (macroCondition(
|
|
144
|
+
const relationshipData = relationships[inverseKey]?.data;
|
|
145
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
114
146
|
if (typeof relationshipData !== 'undefined' && !relationshipDataPointsToParent(relationshipData, parentIdentifier)) {
|
|
115
147
|
const inspect = function inspect(thing) {
|
|
116
148
|
return `'${JSON.stringify(thing)}'`;
|
|
@@ -125,25 +157,39 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
|
|
|
125
157
|
const got = inspect(relationshipData);
|
|
126
158
|
const prefix = typeof index === 'number' ? `data[${index}]` : `data`;
|
|
127
159
|
const path = `${prefix}.relationships.${inverseKey}.data`;
|
|
128
|
-
const
|
|
160
|
+
const data = Array.isArray(relationshipData) ? relationshipData[0] : relationshipData;
|
|
161
|
+
const other = data ? `<${data.type}:${data.id}>` : null;
|
|
129
162
|
const relationshipFetched = `${expectedModel}.${parentRelationship.kind}("${parentRelationship.name}")`;
|
|
130
163
|
const includedRecord = `<${type}:${id}>`;
|
|
131
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');
|
|
132
|
-
|
|
165
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
166
|
+
{
|
|
167
|
+
throw new Error(message);
|
|
168
|
+
}
|
|
169
|
+
})() : {};
|
|
133
170
|
}
|
|
134
171
|
}
|
|
135
172
|
if (kind !== 'hasMany' || typeof relationshipData !== 'undefined') {
|
|
136
173
|
relationships[inverseKey] = relationships[inverseKey] || {};
|
|
137
|
-
relationships[inverseKey].data = fixRelationshipData(relationshipData, kind, parentIdentifier);
|
|
174
|
+
relationships[inverseKey].data = fixRelationshipData(relationshipData ?? null, kind, parentIdentifier);
|
|
138
175
|
}
|
|
139
176
|
}
|
|
140
177
|
}
|
|
141
178
|
function inverseForRelationship(store, identifier, key) {
|
|
142
|
-
const definition = store.
|
|
179
|
+
const definition = store.schema.fields(identifier).get(key);
|
|
143
180
|
if (!definition) {
|
|
144
181
|
return null;
|
|
145
182
|
}
|
|
146
|
-
|
|
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) : {};
|
|
147
193
|
return definition.options.inverse;
|
|
148
194
|
}
|
|
149
195
|
function getInverse(store, parentIdentifier, parentRelationship, type) {
|
|
@@ -157,15 +203,17 @@ function getInverse(store, parentIdentifier, parentRelationship, type) {
|
|
|
157
203
|
type: parentType
|
|
158
204
|
}, lhs_relationshipName);
|
|
159
205
|
if (inverseKey) {
|
|
160
|
-
const definition = store.
|
|
206
|
+
const definition = store.schema.fields({
|
|
161
207
|
type
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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')) : {};
|
|
166
214
|
return {
|
|
167
215
|
inverseKey,
|
|
168
|
-
kind
|
|
216
|
+
kind: definition.kind
|
|
169
217
|
};
|
|
170
218
|
}
|
|
171
219
|
}
|
|
@@ -196,10 +244,15 @@ function fixRelationshipData(relationshipData, relationshipKind, {
|
|
|
196
244
|
id,
|
|
197
245
|
type
|
|
198
246
|
};
|
|
199
|
-
let payload;
|
|
247
|
+
let payload = null;
|
|
200
248
|
if (relationshipKind === 'hasMany') {
|
|
201
|
-
|
|
249
|
+
const relData = relationshipData || [];
|
|
202
250
|
if (relationshipData) {
|
|
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)) : {};
|
|
203
256
|
// these arrays could be massive so this is better than filter
|
|
204
257
|
// Note: this is potentially problematic if type/id are not in the
|
|
205
258
|
// same state of normalization.
|
|
@@ -207,14 +260,16 @@ function fixRelationshipData(relationshipData, relationshipKind, {
|
|
|
207
260
|
return v.type === parentRelationshipData.type && v.id === parentRelationshipData.id;
|
|
208
261
|
});
|
|
209
262
|
if (!found) {
|
|
210
|
-
|
|
263
|
+
relData.push(parentRelationshipData);
|
|
211
264
|
}
|
|
212
265
|
} else {
|
|
213
|
-
|
|
266
|
+
relData.push(parentRelationshipData);
|
|
214
267
|
}
|
|
268
|
+
payload = relData;
|
|
215
269
|
} else {
|
|
216
|
-
|
|
217
|
-
Object.assign(
|
|
270
|
+
const relData = relationshipData || {};
|
|
271
|
+
Object.assign(relData, parentRelationshipData);
|
|
272
|
+
payload = relData;
|
|
218
273
|
}
|
|
219
274
|
return payload;
|
|
220
275
|
}
|
|
@@ -223,7 +278,7 @@ function validateRelationshipEntry({
|
|
|
223
278
|
}, {
|
|
224
279
|
id: parentModelID
|
|
225
280
|
}) {
|
|
226
|
-
return id && id.toString() === parentModelID;
|
|
281
|
+
return !!id && id.toString() === parentModelID;
|
|
227
282
|
}
|
|
228
283
|
const PotentialLegacyOperations = new Set(['findRecord', 'findAll', 'query', 'queryRecord', 'findBelongsTo', 'findHasMany', 'updateRecord', 'createRecord', 'deleteRecord']);
|
|
229
284
|
const LegacyNetworkHandler = {
|
|
@@ -283,10 +338,18 @@ function findBelongsTo(context) {
|
|
|
283
338
|
return pendingRequest;
|
|
284
339
|
}
|
|
285
340
|
if (useLink) {
|
|
286
|
-
|
|
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) : {};
|
|
287
346
|
return _findBelongsTo(store, record, links.related, field, options);
|
|
288
347
|
}
|
|
289
|
-
|
|
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) : {};
|
|
290
353
|
const manager = store._fetchManager;
|
|
291
354
|
assertIdentifierHasId(identifier);
|
|
292
355
|
return options.reload ? manager.scheduleFetch(identifier, options, context.request) : manager.fetchDataIfNeededForIdentifier(identifier, options, context.request);
|
|
@@ -317,14 +380,30 @@ function findHasMany(context) {
|
|
|
317
380
|
The usual use-case is for the server to register a URL as a link, and
|
|
318
381
|
then use that URL in the future to make a request for the relationship.
|
|
319
382
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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) : {};
|
|
323
398
|
return _findHasMany(adapter, store, record, links.related, field, options);
|
|
324
399
|
}
|
|
325
400
|
|
|
326
401
|
// identifiers case
|
|
327
|
-
|
|
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)) : {};
|
|
328
407
|
const fetches = new Array(identifiers.length);
|
|
329
408
|
const manager = store._fetchManager;
|
|
330
409
|
for (let i = 0; i < identifiers.length; i++) {
|
|
@@ -345,21 +424,12 @@ function saveRecord(context) {
|
|
|
345
424
|
options,
|
|
346
425
|
record: identifier
|
|
347
426
|
} = data;
|
|
427
|
+
store.cache.willCommit(identifier, context);
|
|
348
428
|
const saveOptions = Object.assign({
|
|
349
429
|
[SaveOp]: operation
|
|
350
430
|
}, options);
|
|
351
431
|
const fetchManagerPromise = store._fetchManager.scheduleSave(identifier, saveOptions);
|
|
352
432
|
return fetchManagerPromise.then(payload => {
|
|
353
|
-
if (macroCondition(getOwnConfig().debug.LOG_PAYLOADS)) {
|
|
354
|
-
try {
|
|
355
|
-
const payloadCopy = payload ? JSON.parse(JSON.stringify(payload)) : payload;
|
|
356
|
-
// eslint-disable-next-line no-console
|
|
357
|
-
console.log(`EmberData | Payload - ${operation}`, payloadCopy);
|
|
358
|
-
} catch (e) {
|
|
359
|
-
// eslint-disable-next-line no-console
|
|
360
|
-
console.log(`EmberData | Payload - ${operation}`, payload);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
433
|
let result;
|
|
364
434
|
store._join(() => {
|
|
365
435
|
// @ts-expect-error we don't have access to a response in legacy
|
|
@@ -371,7 +441,7 @@ function saveRecord(context) {
|
|
|
371
441
|
|
|
372
442
|
// blatantly lie if we were a createRecord request
|
|
373
443
|
// to give some semblance of cache-control to the
|
|
374
|
-
//
|
|
444
|
+
// CachePolicy while legacy is still around
|
|
375
445
|
if (store.lifetimes?.didRequest && operation === 'createRecord') {
|
|
376
446
|
store.lifetimes.didRequest(context.request, {
|
|
377
447
|
status: 201
|
|
@@ -402,7 +472,11 @@ function adapterDidInvalidate(store, identifier, error) {
|
|
|
402
472
|
}
|
|
403
473
|
const cache = store.cache;
|
|
404
474
|
if (error.errors) {
|
|
405
|
-
|
|
475
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
476
|
+
if (!test) {
|
|
477
|
+
throw new Error(`Expected the cache in use by resource ${String(identifier)} to have a getErrors(identifier) method for retrieving errors.`);
|
|
478
|
+
}
|
|
479
|
+
})(typeof cache.getErrors === 'function') : {};
|
|
406
480
|
let jsonApiErrors = error.errors;
|
|
407
481
|
if (jsonApiErrors.length === 0) {
|
|
408
482
|
jsonApiErrors = [{
|
|
@@ -472,7 +546,7 @@ function findRecord(context) {
|
|
|
472
546
|
// Refetch the record if the adapter thinks the record is stale
|
|
473
547
|
if (typeof options.reload === 'undefined' && adapter.shouldReloadRecord && adapter.shouldReloadRecord(store, snapshot = store._fetchManager.createSnapshot(identifier, options))) {
|
|
474
548
|
assertIdentifierHasId(identifier);
|
|
475
|
-
if (macroCondition(
|
|
549
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
476
550
|
promise = store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
|
|
477
551
|
reload: true
|
|
478
552
|
}), context.request);
|
|
@@ -484,7 +558,7 @@ function findRecord(context) {
|
|
|
484
558
|
// Trigger the background refetch if backgroundReload option is passed
|
|
485
559
|
if (options.backgroundReload !== false && (options.backgroundReload || !adapter.shouldBackgroundReloadRecord || adapter.shouldBackgroundReloadRecord(store, snapshot = snapshot || store._fetchManager.createSnapshot(identifier, options)))) {
|
|
486
560
|
assertIdentifierHasId(identifier);
|
|
487
|
-
if (macroCondition(
|
|
561
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
488
562
|
void store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
|
|
489
563
|
backgroundReload: true
|
|
490
564
|
}), context.request);
|
|
@@ -510,8 +584,16 @@ function findAll(context) {
|
|
|
510
584
|
options
|
|
511
585
|
} = data;
|
|
512
586
|
const adapter = store.adapterFor(type);
|
|
513
|
-
|
|
514
|
-
|
|
587
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
588
|
+
if (!test) {
|
|
589
|
+
throw new Error(`You tried to load all records but you have no adapter (for ${type})`);
|
|
590
|
+
}
|
|
591
|
+
})(adapter) : {};
|
|
592
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
593
|
+
if (!test) {
|
|
594
|
+
throw new Error(`You tried to load all records but your adapter does not implement 'findAll'`);
|
|
595
|
+
}
|
|
596
|
+
})(typeof adapter.findAll === 'function') : {};
|
|
515
597
|
|
|
516
598
|
// avoid initializing the liveArray just to set `isUpdating`
|
|
517
599
|
const maybeRecordArray = store.recordArrayManager._live.get(type);
|
|
@@ -519,11 +601,13 @@ function findAll(context) {
|
|
|
519
601
|
const shouldReload = options.reload || options.reload !== false && (adapter.shouldReloadAll && adapter.shouldReloadAll(store, snapshotArray) || !adapter.shouldReloadAll && snapshotArray.length === 0);
|
|
520
602
|
let fetch;
|
|
521
603
|
if (shouldReload) {
|
|
604
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
522
605
|
maybeRecordArray && (maybeRecordArray.isUpdating = true);
|
|
523
606
|
fetch = _findAll(adapter, store, type, snapshotArray, context.request, true);
|
|
524
607
|
} else {
|
|
525
608
|
fetch = Promise.resolve(store.peekAll(type));
|
|
526
609
|
if (options.backgroundReload || options.backgroundReload !== false && (!adapter.shouldBackgroundReloadAll || adapter.shouldBackgroundReloadAll(store, snapshotArray))) {
|
|
610
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
527
611
|
maybeRecordArray && (maybeRecordArray.isUpdating = true);
|
|
528
612
|
void _findAll(adapter, store, type, snapshotArray, context.request, false);
|
|
529
613
|
}
|
|
@@ -534,18 +618,24 @@ function _findAll(adapter, store, type, snapshotArray, request, isAsyncFlush) {
|
|
|
534
618
|
const schema = store.modelFor(type);
|
|
535
619
|
let promise = Promise.resolve().then(() => adapter.findAll(store, schema, null, snapshotArray));
|
|
536
620
|
promise = promise.then(adapterPayload => {
|
|
537
|
-
|
|
621
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
622
|
+
if (!test) {
|
|
623
|
+
throw new Error(`You made a 'findAll' request for '${type}' records, but the adapter's response did not have any data`);
|
|
624
|
+
}
|
|
625
|
+
})(payloadIsNotBlank(adapterPayload)) : {};
|
|
538
626
|
const serializer = store.serializerFor(type);
|
|
539
627
|
const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'findAll');
|
|
540
628
|
store._push(payload, isAsyncFlush);
|
|
541
629
|
snapshotArray._recordArray.isUpdating = false;
|
|
542
|
-
if (macroCondition(
|
|
543
|
-
|
|
544
|
-
|
|
630
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REQUESTS)) {
|
|
631
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
|
|
632
|
+
// eslint-disable-next-line no-console
|
|
633
|
+
console.log(`request: findAll<${type}> background reload complete`);
|
|
634
|
+
}
|
|
545
635
|
}
|
|
546
636
|
return snapshotArray._recordArray;
|
|
547
637
|
});
|
|
548
|
-
if (macroCondition(
|
|
638
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
549
639
|
if (!request.disableTestWaiter) {
|
|
550
640
|
const {
|
|
551
641
|
waitForPromise
|
|
@@ -569,13 +659,21 @@ function query(context) {
|
|
|
569
659
|
query
|
|
570
660
|
} = data;
|
|
571
661
|
const adapter = store.adapterFor(type);
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
662
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
663
|
+
if (!test) {
|
|
664
|
+
throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
|
|
665
|
+
}
|
|
666
|
+
})(adapter) : {};
|
|
667
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
668
|
+
if (!test) {
|
|
669
|
+
throw new Error(`You tried to make a query but your adapter does not implement 'query'`);
|
|
670
|
+
}
|
|
671
|
+
})(typeof adapter.query === 'function') : {};
|
|
672
|
+
const recordArray = options._recordArray || store.recordArrayManager.getCollection({
|
|
575
673
|
type,
|
|
576
674
|
query
|
|
577
675
|
});
|
|
578
|
-
if (macroCondition(
|
|
676
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
579
677
|
options = Object.assign({}, options);
|
|
580
678
|
delete options._recordArray;
|
|
581
679
|
} else {
|
|
@@ -587,13 +685,21 @@ function query(context) {
|
|
|
587
685
|
const serializer = store.serializerFor(type);
|
|
588
686
|
const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'query');
|
|
589
687
|
const identifiers = store._push(payload, true);
|
|
590
|
-
|
|
688
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
689
|
+
if (!test) {
|
|
690
|
+
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.');
|
|
691
|
+
}
|
|
692
|
+
})(Array.isArray(identifiers)) : {};
|
|
591
693
|
store.recordArrayManager.populateManagedArray(recordArray, identifiers, payload);
|
|
592
694
|
return recordArray;
|
|
593
695
|
});
|
|
594
696
|
}
|
|
595
697
|
function assertSingleResourceDocument(payload) {
|
|
596
|
-
|
|
698
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
699
|
+
if (!test) {
|
|
700
|
+
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.`);
|
|
701
|
+
}
|
|
702
|
+
})(!Array.isArray(payload.data)) : {};
|
|
597
703
|
}
|
|
598
704
|
function queryRecord(context) {
|
|
599
705
|
const {
|
|
@@ -607,8 +713,16 @@ function queryRecord(context) {
|
|
|
607
713
|
options
|
|
608
714
|
} = data;
|
|
609
715
|
const adapter = store.adapterFor(type);
|
|
610
|
-
|
|
611
|
-
|
|
716
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
717
|
+
if (!test) {
|
|
718
|
+
throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
|
|
719
|
+
}
|
|
720
|
+
})(adapter) : {};
|
|
721
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
722
|
+
if (!test) {
|
|
723
|
+
throw new Error(`You tried to make a query but your adapter does not implement 'queryRecord'`);
|
|
724
|
+
}
|
|
725
|
+
})(typeof adapter.queryRecord === 'function') : {};
|
|
612
726
|
const schema = store.modelFor(type);
|
|
613
727
|
const promise = Promise.resolve().then(() => adapter.queryRecord(store, schema, query, options));
|
|
614
728
|
return promise.then(adapterPayload => {
|
|
@@ -641,9 +755,21 @@ function queryRecord(context) {
|
|
|
641
755
|
*/
|
|
642
756
|
|
|
643
757
|
function adapterFor(modelName, _allowMissing) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
758
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
759
|
+
if (!test) {
|
|
760
|
+
throw new Error(`Attempted to call store.adapterFor(), but the store instance has already been destroyed.`);
|
|
761
|
+
}
|
|
762
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
763
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
764
|
+
if (!test) {
|
|
765
|
+
throw new Error(`You need to pass a model name to the store's adapterFor method`);
|
|
766
|
+
}
|
|
767
|
+
})(modelName) : {};
|
|
768
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
769
|
+
if (!test) {
|
|
770
|
+
throw new Error(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${modelName}`);
|
|
771
|
+
}
|
|
772
|
+
})(typeof modelName === 'string') : {};
|
|
647
773
|
this._adapterCache = this._adapterCache || Object.create(null);
|
|
648
774
|
const normalizedModelName = _deprecatingNormalize(modelName);
|
|
649
775
|
const {
|
|
@@ -669,7 +795,11 @@ function adapterFor(modelName, _allowMissing) {
|
|
|
669
795
|
_adapterCache.application = adapter;
|
|
670
796
|
return adapter;
|
|
671
797
|
}
|
|
672
|
-
|
|
798
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
799
|
+
if (!test) {
|
|
800
|
+
throw new Error(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`);
|
|
801
|
+
}
|
|
802
|
+
})(_allowMissing) : {};
|
|
673
803
|
}
|
|
674
804
|
|
|
675
805
|
/**
|
|
@@ -690,9 +820,21 @@ function adapterFor(modelName, _allowMissing) {
|
|
|
690
820
|
@return {Serializer}
|
|
691
821
|
*/
|
|
692
822
|
function serializerFor(modelName) {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
823
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
824
|
+
if (!test) {
|
|
825
|
+
throw new Error(`Attempted to call store.serializerFor(), but the store instance has already been destroyed.`);
|
|
826
|
+
}
|
|
827
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
828
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
829
|
+
if (!test) {
|
|
830
|
+
throw new Error(`You need to pass a model name to the store's serializerFor method`);
|
|
831
|
+
}
|
|
832
|
+
})(modelName) : {};
|
|
833
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
834
|
+
if (!test) {
|
|
835
|
+
throw new Error(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${modelName}`);
|
|
836
|
+
}
|
|
837
|
+
})(typeof modelName === 'string') : {};
|
|
696
838
|
this._serializerCache = this._serializerCache || Object.create(null);
|
|
697
839
|
const normalizedModelName = _deprecatingNormalize(modelName);
|
|
698
840
|
const {
|
|
@@ -743,13 +885,29 @@ function serializerFor(modelName) {
|
|
|
743
885
|
*/
|
|
744
886
|
// TODO @runspired @deprecate users should call normalize on the associated serializer directly
|
|
745
887
|
function normalize(modelName, payload) {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
888
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
889
|
+
if (!test) {
|
|
890
|
+
throw new Error(`Attempted to call store.normalize(), but the store instance has already been destroyed.`);
|
|
891
|
+
}
|
|
892
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
893
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
894
|
+
if (!test) {
|
|
895
|
+
throw new Error(`You need to pass a model name to the store's normalize method`);
|
|
896
|
+
}
|
|
897
|
+
})(modelName) : {};
|
|
898
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
899
|
+
if (!test) {
|
|
900
|
+
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${typeof modelName}`);
|
|
901
|
+
}
|
|
902
|
+
})(typeof modelName === 'string') : {};
|
|
749
903
|
const normalizedModelName = _deprecatingNormalize(modelName);
|
|
750
904
|
const serializer = this.serializerFor(normalizedModelName);
|
|
751
905
|
const schema = this.modelFor(normalizedModelName);
|
|
752
|
-
|
|
906
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
907
|
+
if (!test) {
|
|
908
|
+
throw new Error(`You must define a normalize method in your serializer in order to call store.normalize`);
|
|
909
|
+
}
|
|
910
|
+
})(typeof serializer?.normalize === 'function') : {};
|
|
753
911
|
return serializer.normalize(schema, payload);
|
|
754
912
|
}
|
|
755
913
|
|
|
@@ -811,11 +969,19 @@ function normalize(modelName, payload) {
|
|
|
811
969
|
*/
|
|
812
970
|
// TODO @runspired @deprecate pushPayload in favor of looking up the serializer
|
|
813
971
|
function pushPayload(modelName, inputPayload) {
|
|
814
|
-
|
|
972
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
973
|
+
if (!test) {
|
|
974
|
+
throw new Error(`Attempted to call store.pushPayload(), but the store instance has already been destroyed.`);
|
|
975
|
+
}
|
|
976
|
+
})(!(this.isDestroying || this.isDestroyed)) : {};
|
|
815
977
|
const payload = inputPayload || modelName;
|
|
816
978
|
const normalizedModelName = inputPayload ? _deprecatingNormalize(modelName) : 'application';
|
|
817
979
|
const serializer = this.serializerFor(normalizedModelName);
|
|
818
|
-
|
|
980
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
981
|
+
if (!test) {
|
|
982
|
+
throw new Error(`You cannot use 'store.pushPayload(<type>, <payload>)' unless the serializer for '${normalizedModelName}' defines 'pushPayload'`);
|
|
983
|
+
}
|
|
984
|
+
})(serializer && typeof serializer.pushPayload === 'function') : {};
|
|
819
985
|
serializer.pushPayload(this, payload);
|
|
820
986
|
}
|
|
821
987
|
|