@ember-data/legacy-compat 5.3.3 → 5.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +8 -0
  2. package/addon-main.cjs +5 -0
  3. package/{addon/-private-1aicprWG.js → dist/-private-DVN28hvw.js} +176 -63
  4. package/dist/-private-DVN28hvw.js.map +1 -0
  5. package/dist/-private.js +1 -0
  6. package/dist/builders.js +323 -0
  7. package/dist/builders.js.map +1 -0
  8. package/{addon → dist}/index.js +244 -72
  9. package/dist/index.js.map +1 -0
  10. package/dist/utils.js +246 -0
  11. package/dist/utils.js.map +1 -0
  12. package/package.json +53 -62
  13. package/unstable-preview-types/-private.d.ts +17 -0
  14. package/unstable-preview-types/-private.d.ts.map +1 -0
  15. package/unstable-preview-types/builders/find-all.d.ts +41 -0
  16. package/unstable-preview-types/builders/find-all.d.ts.map +1 -0
  17. package/unstable-preview-types/builders/find-record.d.ts +62 -0
  18. package/unstable-preview-types/builders/find-record.d.ts.map +1 -0
  19. package/unstable-preview-types/builders/query.d.ts +72 -0
  20. package/unstable-preview-types/builders/query.d.ts.map +1 -0
  21. package/unstable-preview-types/builders/save-record.d.ts +40 -0
  22. package/unstable-preview-types/builders/save-record.d.ts.map +1 -0
  23. package/unstable-preview-types/builders/utils.d.ts +6 -0
  24. package/unstable-preview-types/builders/utils.d.ts.map +1 -0
  25. package/unstable-preview-types/builders.d.ts +18 -0
  26. package/unstable-preview-types/builders.d.ts.map +1 -0
  27. package/unstable-preview-types/index.d.ts +162 -0
  28. package/unstable-preview-types/index.d.ts.map +1 -0
  29. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts +49 -0
  30. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  31. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts +5 -0
  32. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  33. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts +14 -0
  34. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  35. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts +8 -0
  36. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  37. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts +5 -0
  38. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  39. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts +549 -0
  40. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  41. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts +235 -0
  42. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  43. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts +9 -0
  44. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts.map +1 -0
  45. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts +96 -0
  46. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  47. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts +248 -0
  48. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts.map +1 -0
  49. package/unstable-preview-types/utils.d.ts +161 -0
  50. package/unstable-preview-types/utils.d.ts.map +1 -0
  51. package/addon/-private-1aicprWG.js.map +0 -1
  52. package/addon/-private.js +0 -1
  53. package/addon/index.js.map +0 -1
  54. package/addon-main.js +0 -93
  55. /package/{addon → dist}/-private.js.map +0 -0
@@ -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, a as assertIdentifierHasId, S as SaveOp, b as SnapshotRecordArray } from "./-private-1aicprWG";
6
- import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
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.js";
5
+ import { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';
7
6
  function _findHasMany(adapter, store, identifier, link, relationship, options) {
8
- let promise = Promise.resolve().then(() => {
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
- promise = promise.then(adapterPayload => {
15
- assert(`You made a 'findHasMany' request for a ${identifier.type}'s '${relationship.name}' relationship, using link '${link}' , but the adapter's response did not have any data`, payloadIsNotBlank(adapterPayload));
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
- assert(`fetched the hasMany relationship '${relationship.name}' for ${identifier.type}:${identifier.id} with link '${link}', but no data member is present in the response. If no data exists, the response should set { data: [] }`, 'data' in payload && Array.isArray(payload.data));
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, `DS: Extract payload of '${identifier.type}' : hasMany '${relationship.type}'`);
23
- return promise;
39
+ }, null);
24
40
  }
25
41
  function _findBelongsTo(store, identifier, link, relationship, options) {
26
- let promise = Promise.resolve().then(() => {
42
+ const promise = Promise.resolve().then(() => {
27
43
  const adapter = store.adapterFor(identifier.type);
28
- assert(`You tried to load a belongsTo relationship but you have no adapter (for ${identifier.type})`, adapter);
29
- assert(`You tried to load a belongsTo relationship from a specified 'link' in the original payload but your adapter does not implement 'findBelongsTo'`, typeof adapter.findBelongsTo === 'function');
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
- promise = promise.then(adapterPayload => {
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
- assert(`fetched the belongsTo relationship '${relationship.name}' for ${identifier.type}:${identifier.id} with link '${link}', but no data member is present in the response. If no data exists, the response should set { data: null }`, 'data' in payload && (payload.data === null || typeof payload.data === 'object' && !Array.isArray(payload.data)));
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, `DS: Extract payload of ${identifier.type} : ${relationship.type}`);
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] && relationships[inverseKey].data;
113
- if (macroCondition(getOwnConfig().env.DEBUG)) {
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 other = relationshipData ? `<${relationshipData.type}:${relationshipData.id}>` : null;
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
- assert(message);
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.getSchemaDefinitionService().relationshipsDefinitionFor(identifier)[key];
179
+ const definition = store.schema.fields(identifier).get(key);
143
180
  if (!definition) {
144
181
  return null;
145
182
  }
146
- assert(`Expected the relationship defintion to specify the inverse type or null.`, definition.options?.inverse === null || typeof definition.options?.inverse === 'string' && definition.options.inverse.length > 0);
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.getSchemaDefinitionService().relationshipsDefinitionFor({
206
+ const definition = store.schema.fields({
161
207
  type
162
- });
163
- const {
164
- kind
165
- } = definition[inverseKey];
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
- payload = relationshipData || [];
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
- payload.push(parentRelationshipData);
263
+ relData.push(parentRelationshipData);
211
264
  }
212
265
  } else {
213
- payload.push(parentRelationshipData);
266
+ relData.push(parentRelationshipData);
214
267
  }
268
+ payload = relData;
215
269
  } else {
216
- payload = relationshipData || {};
217
- Object.assign(payload, parentRelationshipData);
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
- assert(`Expected a related link when calling store.findBelongsTo, found ${String(links)}`, links && links.related);
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
- assert(`Expected an identifier`, Array.isArray(identifiers) && identifiers.length === 1);
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
- assert(`You tried to load a hasMany relationship but you have no adapter (for ${record.type})`, adapter);
321
- assert(`You tried to load a hasMany relationship from a specified 'link' in the original payload but your adapter does not implement 'findHasMany'`, typeof adapter.findHasMany === 'function');
322
- assert(`Expected a related link when calling store.findhasMany, found ${String(links)}`, links && links.related);
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
- assert(`Expected an array of identifiers to fetch`, Array.isArray(identifiers));
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,12 +424,13 @@ 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)) {
433
+ if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
354
434
  try {
355
435
  const payloadCopy = payload ? JSON.parse(JSON.stringify(payload)) : payload;
356
436
  // eslint-disable-next-line no-console
@@ -371,7 +451,7 @@ function saveRecord(context) {
371
451
 
372
452
  // blatantly lie if we were a createRecord request
373
453
  // to give some semblance of cache-control to the
374
- // lifetimes service while legacy is still around
454
+ // CachePolicy while legacy is still around
375
455
  if (store.lifetimes?.didRequest && operation === 'createRecord') {
376
456
  store.lifetimes.didRequest(context.request, {
377
457
  status: 201
@@ -402,7 +482,11 @@ function adapterDidInvalidate(store, identifier, error) {
402
482
  }
403
483
  const cache = store.cache;
404
484
  if (error.errors) {
405
- assert(`Expected the cache in use by resource ${String(identifier)} to have a getErrors(identifier) method for retreiving errors.`, typeof cache.getErrors === 'function');
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') : {};
406
490
  let jsonApiErrors = error.errors;
407
491
  if (jsonApiErrors.length === 0) {
408
492
  jsonApiErrors = [{
@@ -472,7 +556,7 @@ function findRecord(context) {
472
556
  // Refetch the record if the adapter thinks the record is stale
473
557
  if (typeof options.reload === 'undefined' && adapter.shouldReloadRecord && adapter.shouldReloadRecord(store, snapshot = store._fetchManager.createSnapshot(identifier, options))) {
474
558
  assertIdentifierHasId(identifier);
475
- if (macroCondition(getOwnConfig().env.DEBUG)) {
559
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
476
560
  promise = store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
477
561
  reload: true
478
562
  }), context.request);
@@ -484,7 +568,7 @@ function findRecord(context) {
484
568
  // Trigger the background refetch if backgroundReload option is passed
485
569
  if (options.backgroundReload !== false && (options.backgroundReload || !adapter.shouldBackgroundReloadRecord || adapter.shouldBackgroundReloadRecord(store, snapshot = snapshot || store._fetchManager.createSnapshot(identifier, options)))) {
486
570
  assertIdentifierHasId(identifier);
487
- if (macroCondition(getOwnConfig().env.DEBUG)) {
571
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
488
572
  void store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
489
573
  backgroundReload: true
490
574
  }), context.request);
@@ -510,8 +594,16 @@ function findAll(context) {
510
594
  options
511
595
  } = data;
512
596
  const adapter = store.adapterFor(type);
513
- assert(`You tried to load all records but you have no adapter (for ${type})`, adapter);
514
- assert(`You tried to load all records but your adapter does not implement 'findAll'`, typeof adapter.findAll === 'function');
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') : {};
515
607
 
516
608
  // avoid initializing the liveArray just to set `isUpdating`
517
609
  const maybeRecordArray = store.recordArrayManager._live.get(type);
@@ -534,18 +626,22 @@ function _findAll(adapter, store, type, snapshotArray, request, isAsyncFlush) {
534
626
  const schema = store.modelFor(type);
535
627
  let promise = Promise.resolve().then(() => adapter.findAll(store, schema, null, snapshotArray));
536
628
  promise = promise.then(adapterPayload => {
537
- assert(`You made a 'findAll' request for '${type}' records, but the adapter's response did not have any data`, payloadIsNotBlank(adapterPayload));
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)) : {};
538
634
  const serializer = store.serializerFor(type);
539
635
  const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'findAll');
540
636
  store._push(payload, isAsyncFlush);
541
637
  snapshotArray._recordArray.isUpdating = false;
542
- if (macroCondition(getOwnConfig().debug.LOG_PAYLOADS)) {
638
+ if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
543
639
  // eslint-disable-next-line no-console
544
640
  console.log(`request: findAll<${type}> background reload complete`);
545
641
  }
546
642
  return snapshotArray._recordArray;
547
643
  });
548
- if (macroCondition(getOwnConfig().env.TESTING)) {
644
+ if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
549
645
  if (!request.disableTestWaiter) {
550
646
  const {
551
647
  waitForPromise
@@ -569,13 +665,21 @@ function query(context) {
569
665
  query
570
666
  } = data;
571
667
  const adapter = store.adapterFor(type);
572
- assert(`You tried to make a query but you have no adapter (for ${type})`, adapter);
573
- assert(`You tried to make a query but your adapter does not implement 'query'`, typeof adapter.query === 'function');
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') : {};
574
678
  const recordArray = options._recordArray || store.recordArrayManager.createArray({
575
679
  type,
576
680
  query
577
681
  });
578
- if (macroCondition(getOwnConfig().env.DEBUG)) {
682
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
579
683
  options = Object.assign({}, options);
580
684
  delete options._recordArray;
581
685
  } else {
@@ -587,13 +691,21 @@ function query(context) {
587
691
  const serializer = store.serializerFor(type);
588
692
  const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'query');
589
693
  const identifiers = store._push(payload, true);
590
- assert('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.', Array.isArray(identifiers));
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)) : {};
591
699
  store.recordArrayManager.populateManagedArray(recordArray, identifiers, payload);
592
700
  return recordArray;
593
701
  });
594
702
  }
595
703
  function assertSingleResourceDocument(payload) {
596
- assert(`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.`, !Array.isArray(payload.data));
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)) : {};
597
709
  }
598
710
  function queryRecord(context) {
599
711
  const {
@@ -607,8 +719,16 @@ function queryRecord(context) {
607
719
  options
608
720
  } = data;
609
721
  const adapter = store.adapterFor(type);
610
- assert(`You tried to make a query but you have no adapter (for ${type})`, adapter);
611
- assert(`You tried to make a query but your adapter does not implement 'queryRecord'`, typeof adapter.queryRecord === 'function');
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') : {};
612
732
  const schema = store.modelFor(type);
613
733
  const promise = Promise.resolve().then(() => adapter.queryRecord(store, schema, query, options));
614
734
  return promise.then(adapterPayload => {
@@ -641,9 +761,21 @@ function queryRecord(context) {
641
761
  */
642
762
 
643
763
  function adapterFor(modelName, _allowMissing) {
644
- assert(`Attempted to call store.adapterFor(), but the store instance has already been destroyed.`, !(this.isDestroying || this.isDestroyed));
645
- assert(`You need to pass a model name to the store's adapterFor method`, modelName);
646
- assert(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
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') : {};
647
779
  this._adapterCache = this._adapterCache || Object.create(null);
648
780
  const normalizedModelName = _deprecatingNormalize(modelName);
649
781
  const {
@@ -669,7 +801,11 @@ function adapterFor(modelName, _allowMissing) {
669
801
  _adapterCache.application = adapter;
670
802
  return adapter;
671
803
  }
672
- assert(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`, _allowMissing);
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) : {};
673
809
  }
674
810
 
675
811
  /**
@@ -690,9 +826,21 @@ function adapterFor(modelName, _allowMissing) {
690
826
  @return {Serializer}
691
827
  */
692
828
  function serializerFor(modelName) {
693
- assert(`Attempted to call store.serializerFor(), but the store instance has already been destroyed.`, !(this.isDestroying || this.isDestroyed));
694
- assert(`You need to pass a model name to the store's serializerFor method`, modelName);
695
- assert(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${modelName}`, typeof modelName === 'string');
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') : {};
696
844
  this._serializerCache = this._serializerCache || Object.create(null);
697
845
  const normalizedModelName = _deprecatingNormalize(modelName);
698
846
  const {
@@ -743,13 +891,29 @@ function serializerFor(modelName) {
743
891
  */
744
892
  // TODO @runspired @deprecate users should call normalize on the associated serializer directly
745
893
  function normalize(modelName, payload) {
746
- assert(`Attempted to call store.normalize(), but the store instance has already been destroyed.`, !(this.isDestroying || this.isDestroyed));
747
- assert(`You need to pass a model name to the store's normalize method`, modelName);
748
- assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${typeof modelName}`, typeof modelName === 'string');
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') : {};
749
909
  const normalizedModelName = _deprecatingNormalize(modelName);
750
910
  const serializer = this.serializerFor(normalizedModelName);
751
911
  const schema = this.modelFor(normalizedModelName);
752
- assert(`You must define a normalize method in your serializer in order to call store.normalize`, typeof serializer?.normalize === 'function');
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') : {};
753
917
  return serializer.normalize(schema, payload);
754
918
  }
755
919
 
@@ -811,11 +975,19 @@ function normalize(modelName, payload) {
811
975
  */
812
976
  // TODO @runspired @deprecate pushPayload in favor of looking up the serializer
813
977
  function pushPayload(modelName, inputPayload) {
814
- assert(`Attempted to call store.pushPayload(), but the store instance has already been destroyed.`, !(this.isDestroying || this.isDestroyed));
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)) : {};
815
983
  const payload = inputPayload || modelName;
816
984
  const normalizedModelName = inputPayload ? _deprecatingNormalize(modelName) : 'application';
817
985
  const serializer = this.serializerFor(normalizedModelName);
818
- assert(`You cannot use 'store.pushPayload(<type>, <payload>)' unless the serializer for '${normalizedModelName}' defines 'pushPayload'`, serializer && typeof serializer.pushPayload === 'function');
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') : {};
819
991
  serializer.pushPayload(this, payload);
820
992
  }
821
993