@ember-data-mirror/store 5.3.8 → 5.3.10

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 (44) hide show
  1. package/addon-main.cjs +1 -1
  2. package/dist/-private.js +1 -1
  3. package/dist/{cache-handler-C5ilAUZ5.js → handler-CW2kp6Ua.js} +499 -520
  4. package/dist/handler-CW2kp6Ua.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/package.json +36 -25
  7. package/unstable-preview-types/-private/cache-handler/handler.d.ts +64 -0
  8. package/unstable-preview-types/-private/cache-handler/handler.d.ts.map +1 -0
  9. package/unstable-preview-types/-private/{cache-handler.d.ts → cache-handler/types.d.ts} +26 -63
  10. package/unstable-preview-types/-private/cache-handler/types.d.ts.map +1 -0
  11. package/unstable-preview-types/-private/cache-handler/utils.d.ts +39 -0
  12. package/unstable-preview-types/-private/cache-handler/utils.d.ts.map +1 -0
  13. package/unstable-preview-types/-private/caches/cache-utils.d.ts +2 -2
  14. package/unstable-preview-types/-private/caches/identifier-cache.d.ts +3 -3
  15. package/unstable-preview-types/-private/caches/instance-cache.d.ts +4 -4
  16. package/unstable-preview-types/-private/document.d.ts +3 -3
  17. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts +2 -2
  18. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts.map +1 -1
  19. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts +2 -2
  20. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +1 -1
  21. package/unstable-preview-types/-private/managers/cache-manager.d.ts +11 -11
  22. package/unstable-preview-types/-private/managers/cache-manager.d.ts.map +1 -1
  23. package/unstable-preview-types/-private/managers/notification-manager.d.ts +8 -3
  24. package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -1
  25. package/unstable-preview-types/-private/managers/record-array-manager.d.ts +3 -3
  26. package/unstable-preview-types/-private/network/request-cache.d.ts +1 -1
  27. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +4 -4
  28. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -1
  29. package/unstable-preview-types/-private/record-arrays/native-proxy-type-fix.d.ts +3 -3
  30. package/unstable-preview-types/-private/store-service.d.ts +33 -13
  31. package/unstable-preview-types/-private/store-service.d.ts.map +1 -1
  32. package/unstable-preview-types/-private/utils/construct-resource.d.ts +1 -1
  33. package/unstable-preview-types/-private.d.ts +3 -2
  34. package/unstable-preview-types/-private.d.ts.map +1 -1
  35. package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts +1 -1
  36. package/unstable-preview-types/-types/q/ds-model.d.ts +2 -2
  37. package/unstable-preview-types/-types/q/identifier.d.ts +1 -1
  38. package/unstable-preview-types/-types/q/record-data-json-api.d.ts +2 -2
  39. package/unstable-preview-types/-types/q/schema-service.d.ts +8 -8
  40. package/unstable-preview-types/-types/q/store.d.ts +2 -2
  41. package/unstable-preview-types/index.d.ts +25 -23
  42. package/unstable-preview-types/index.d.ts.map +1 -1
  43. package/dist/cache-handler-C5ilAUZ5.js.map +0 -1
  44. package/unstable-preview-types/-private/cache-handler.d.ts.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { deprecate, warn } from '@ember/debug';
2
2
  import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
3
- import { SkipCache, EnableHydration } from '@warp-drive/core-types/request';
4
- import { getOrSetGlobal, setTransient, peekTransient } from '@warp-drive/core-types/-private';
5
- import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '@warp-drive/core-types/identifier';
3
+ import { SkipCache, EnableHydration } from '@warp-drive-mirror/core-types/request';
4
+ import { getOrSetGlobal, setTransient, peekTransient } from '@warp-drive-mirror/core-types/-private';
5
+ import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '@warp-drive-mirror/core-types/identifier';
6
6
  import { dasherize } from '@ember-data-mirror/request-utils/string';
7
7
  import { defineSignal, createSignal, subscribe, createArrayTags, addToTransaction, addTransactionCB } from '@ember-data-mirror/tracking/-private';
8
8
  import { _backburner } from '@ember/runloop';
@@ -13,7 +13,7 @@ import { compat } from '@ember-data-mirror/tracking';
13
13
  */
14
14
 
15
15
  function coerceId(id) {
16
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_ID)) {
16
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_NON_STRICT_ID)) {
17
17
  let normalized;
18
18
  if (id === null || id === undefined || id === '') {
19
19
  normalized = null;
@@ -25,13 +25,13 @@ function coerceId(id) {
25
25
  until: '6.0',
26
26
  for: 'ember-data-mirror',
27
27
  since: {
28
- available: '5.3',
28
+ available: '4.13',
29
29
  enabled: '5.3'
30
30
  }
31
31
  });
32
32
  return normalized;
33
33
  }
34
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
34
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
35
35
  if (!test) {
36
36
  throw new Error(`Resource IDs must be a non-empty string or null. Received '${String(id)}'.`);
37
37
  }
@@ -45,7 +45,7 @@ function ensureStringId(id) {
45
45
  } else if (typeof id === 'number' && !isNaN(id)) {
46
46
  normalized = String(id);
47
47
  }
48
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
48
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
49
49
  if (!test) {
50
50
  throw new Error(`Expected id to be a string or number, received ${String(id)}`);
51
51
  }
@@ -53,14 +53,14 @@ function ensureStringId(id) {
53
53
  return normalized;
54
54
  }
55
55
  function normalizeModelName(type) {
56
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
56
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
57
57
  const result = dasherize(type);
58
58
  deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
59
59
  id: 'ember-data-mirror:deprecate-non-strict-types',
60
60
  until: '6.0',
61
61
  for: 'ember-data-mirror',
62
62
  since: {
63
- available: '5.3',
63
+ available: '4.13',
64
64
  enabled: '5.3'
65
65
  }
66
66
  });
@@ -75,7 +75,7 @@ function normalizeModelName(type) {
75
75
 
76
76
  function installPolyfill() {
77
77
  const isFastBoot = typeof FastBoot !== 'undefined';
78
- const CRYPTO = isFastBoot ? FastBoot.require('crypto') : window.crypto;
78
+ const CRYPTO = isFastBoot ? FastBoot.require('crypto') : globalThis.crypto;
79
79
  if (!CRYPTO.randomUUID) {
80
80
  // we might be able to optimize this by requesting more bytes than we need at a time
81
81
  const rng = function () {
@@ -138,12 +138,12 @@ function isDocumentIdentifier(identifier) {
138
138
  return DOCUMENTS.has(identifier);
139
139
  }
140
140
  const isFastBoot = typeof FastBoot !== 'undefined';
141
- const _crypto = isFastBoot ? FastBoot.require('crypto') : window.crypto;
142
- if (macroCondition(getGlobalConfig().WarpDrive.polyfillUUID)) {
141
+ const _crypto = isFastBoot ? FastBoot.require('crypto') : globalThis.crypto;
142
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.polyfillUUID)) {
143
143
  installPolyfill();
144
144
  }
145
145
  function uuidv4() {
146
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
146
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
147
147
  if (!test) {
148
148
  throw new Error('crypto.randomUUID needs to be avaliable. Some browsers incorrectly disallow it in insecure contexts. You maybe want to enable the polyfill: https://github.com/emberjs/data#randomuuid-polyfill');
149
149
  }
@@ -192,7 +192,7 @@ function updateTypeIdMapping(typeMap, identifier, id) {
192
192
  }
193
193
  function defaultUpdateMethod(identifier, data, bucket) {
194
194
  if (bucket === 'record') {
195
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
195
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
196
196
  if (!test) {
197
197
  throw new Error(`Expected identifier to be a StableRecordIdentifier`);
198
198
  }
@@ -206,7 +206,7 @@ function defaultKeyInfoMethod(resource, known) {
206
206
  // TODO RFC something to make this configurable
207
207
  const id = hasId(resource) ? coerceId(resource.id) : null;
208
208
  const type = hasType(resource) ? normalizeModelName(resource.type) : known ? known.type : null;
209
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
209
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
210
210
  if (!test) {
211
211
  throw new Error(`Expected keyInfoForResource to provide a type for the resource`);
212
212
  }
@@ -221,7 +221,7 @@ function defaultGenerationMethod(data, bucket) {
221
221
  if (hasLid(data)) {
222
222
  return data.lid;
223
223
  }
224
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
224
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
225
225
  if (!test) {
226
226
  throw new Error(`Cannot generate an identifier for a resource without a type`);
227
227
  }
@@ -241,7 +241,7 @@ function defaultGenerationMethod(data, bucket) {
241
241
  }
242
242
  return null;
243
243
  }
244
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
244
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
245
245
  {
246
246
  throw new Error(`Unknown bucket ${bucket}`);
247
247
  }
@@ -252,7 +252,7 @@ function defaultMergeMethod(a, _b, _c) {
252
252
  return a;
253
253
  }
254
254
  let DEBUG_MAP;
255
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
255
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
256
256
  DEBUG_MAP = getOrSetGlobal('DEBUG_MAP', new WeakMap());
257
257
  }
258
258
 
@@ -310,19 +310,19 @@ class IdentifierCache {
310
310
  */
311
311
 
312
312
  _getRecordIdentifier(resource, shouldGenerate) {
313
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
313
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
314
314
  // eslint-disable-next-line no-console
315
315
  console.groupCollapsed(`Identifiers: ${shouldGenerate ? 'Generating' : 'Peeking'} Identifier`, resource);
316
316
  }
317
317
  // short circuit if we're already the stable version
318
318
  if (isStableIdentifier(resource)) {
319
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
319
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
320
320
  // TODO should we instead just treat this case as a new generation skipping the short circuit?
321
321
  if (!this._cache.resources.has(resource.lid) || this._cache.resources.get(resource.lid) !== resource) {
322
322
  throw new Error(`The supplied identifier ${JSON.stringify(resource)} does not belong to this store instance`);
323
323
  }
324
324
  }
325
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
325
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
326
326
  // eslint-disable-next-line no-console
327
327
  console.log(`Identifiers: cache HIT - Stable ${resource.lid}`);
328
328
  // eslint-disable-next-line no-console
@@ -333,20 +333,20 @@ class IdentifierCache {
333
333
 
334
334
  // the resource is unknown, ask the application to identify this data for us
335
335
  const lid = this._generate(resource, 'record');
336
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
336
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
337
337
  // eslint-disable-next-line no-console
338
338
  console.log(`Identifiers: ${lid ? 'no ' : ''}lid ${lid ? lid + ' ' : ''}determined for resource`, resource);
339
339
  }
340
340
  let identifier = /*#__NOINLINE__*/getIdentifierFromLid(this._cache, lid, resource);
341
341
  if (identifier !== null) {
342
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
342
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
343
343
  // eslint-disable-next-line no-console
344
344
  console.groupEnd();
345
345
  }
346
346
  return identifier;
347
347
  }
348
348
  if (shouldGenerate === 0) {
349
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
349
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
350
350
  // eslint-disable-next-line no-console
351
351
  console.groupEnd();
352
352
  }
@@ -366,7 +366,7 @@ class IdentifierCache {
366
366
  identifier = /*#__NOINLINE__*/makeStableRecordIdentifier(keyInfo, 'record', false);
367
367
  }
368
368
  addResourceToCache(this._cache, identifier);
369
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
369
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
370
370
  // eslint-disable-next-line no-console
371
371
  console.groupEnd();
372
372
  }
@@ -408,7 +408,7 @@ class IdentifierCache {
408
408
  identifier = {
409
409
  lid: cacheKey
410
410
  };
411
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
411
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
412
412
  Object.freeze(identifier);
413
413
  }
414
414
  DOCUMENTS.add(identifier);
@@ -454,7 +454,7 @@ class IdentifierCache {
454
454
  }, 'record', true);
455
455
 
456
456
  // populate our unique table
457
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
457
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
458
458
  if (this._cache.resources.has(identifier.lid)) {
459
459
  throw new Error(`The lid generated for the new record is not unique as it matches an existing identifier`);
460
460
  }
@@ -462,7 +462,7 @@ class IdentifierCache {
462
462
 
463
463
  /*#__NOINLINE__*/
464
464
  addResourceToCache(this._cache, identifier);
465
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
465
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
466
466
  // eslint-disable-next-line no-console
467
467
  console.log(`Identifiers: created identifier ${String(identifier)} for newly generated resource`, data);
468
468
  }
@@ -511,7 +511,7 @@ class IdentifierCache {
511
511
  if (hadLid) {
512
512
  data.lid = identifier.lid;
513
513
  }
514
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
514
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
515
515
  // eslint-disable-next-line no-console
516
516
  console.log(`Identifiers: merged identifiers ${generatedIdentifier.lid} and ${existingIdentifier.lid} for resource into ${identifier.lid}`, data);
517
517
  }
@@ -523,12 +523,12 @@ class IdentifierCache {
523
523
 
524
524
  // add to our own secondary lookup table
525
525
  if (id !== newId && newId !== null) {
526
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
526
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
527
527
  // eslint-disable-next-line no-console
528
528
  console.log(`Identifiers: updated id for identifier ${identifier.lid} from '${String(id)}' to '${String(newId)}' for resource`, data);
529
529
  }
530
530
  const typeSet = this._cache.resourcesByType[identifier.type];
531
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
531
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
532
532
  if (!test) {
533
533
  throw new Error(`Expected to find a typeSet for ${identifier.type}`);
534
534
  }
@@ -537,7 +537,7 @@ class IdentifierCache {
537
537
  if (id !== null) {
538
538
  typeSet.id.delete(id);
539
539
  }
540
- } else if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
540
+ } else if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
541
541
  // eslint-disable-next-line no-console
542
542
  console.log(`Identifiers: updated identifier ${identifier.lid} resource`, data);
543
543
  }
@@ -549,7 +549,7 @@ class IdentifierCache {
549
549
  * @private
550
550
  */
551
551
  _mergeRecordIdentifiers(keyInfo, identifier, existingIdentifier, data) {
552
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
552
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
553
553
  if (!test) {
554
554
  throw new Error(`Expected keyInfo to contain an id`);
555
555
  }
@@ -600,7 +600,7 @@ class IdentifierCache {
600
600
  forgetRecordIdentifier(identifierObject) {
601
601
  const identifier = this.getOrCreateRecordIdentifier(identifierObject);
602
602
  const typeSet = this._cache.resourcesByType[identifier.type];
603
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
603
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
604
604
  if (!test) {
605
605
  throw new Error(`Expected to find a typeSet for ${identifier.type}`);
606
606
  }
@@ -617,13 +617,13 @@ class IdentifierCache {
617
617
  });
618
618
  this._cache.polymorphicLidBackMap.delete(identifier.lid);
619
619
  }
620
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
620
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
621
621
  identifier[DEBUG_STALE_CACHE_OWNER] = identifier[CACHE_OWNER];
622
622
  }
623
623
  identifier[CACHE_OWNER] = undefined;
624
624
  IDENTIFIERS.delete(identifier);
625
625
  this._forget(identifier, 'record');
626
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
626
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
627
627
  // eslint-disable-next-line no-console
628
628
  console.log(`Identifiers: released identifier ${identifierObject.lid}`);
629
629
  }
@@ -638,7 +638,7 @@ class IdentifierCache {
638
638
  }
639
639
  function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated) {
640
640
  IDENTIFIERS.add(recordIdentifier);
641
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
641
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
642
642
  // we enforce immutability in dev
643
643
  // but preserve our ability to do controlled updates to the reference
644
644
  let wrapper = {
@@ -700,7 +700,7 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
700
700
  return recordIdentifier;
701
701
  }
702
702
  function performRecordIdentifierUpdate(identifier, keyInfo, data, updateFn) {
703
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
703
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
704
704
  const {
705
705
  id,
706
706
  type
@@ -775,7 +775,7 @@ function detectMerge(cache, keyInfo, identifier, data) {
775
775
  }
776
776
  function getIdentifierFromLid(cache, lid, resource) {
777
777
  const identifier = cache.resources.get(lid);
778
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_IDENTIFIERS)) {
778
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS)) {
779
779
  // eslint-disable-next-line no-console
780
780
  console.log(`Identifiers: cache ${identifier ? 'HIT' : 'MISS'} - Non-Stable ${lid}`, resource);
781
781
  }
@@ -842,6 +842,7 @@ class RecordReference {
842
842
  @return {String} The id of the record.
843
843
  */
844
844
  id() {
845
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
845
846
  this._ref; // consume the tracked prop
846
847
  return this.___identifier.id;
847
848
  }
@@ -955,7 +956,7 @@ class RecordReference {
955
956
  if (id !== null) {
956
957
  return this.store.findRecord(this.type, id);
957
958
  }
958
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
959
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
959
960
  {
960
961
  throw new Error(`Unable to fetch record of type ${this.type} without an id`);
961
962
  }
@@ -982,7 +983,7 @@ class RecordReference {
982
983
  reload: true
983
984
  });
984
985
  }
985
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
986
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
986
987
  {
987
988
  throw new Error(`Unable to fetch record of type ${this.type} without an id`);
988
989
  }
@@ -1038,7 +1039,7 @@ class CacheCapabilitiesManager {
1038
1039
  });
1039
1040
  }
1040
1041
  notifyChange(identifier, namespace, key) {
1041
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1042
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1042
1043
  if (!test) {
1043
1044
  throw new Error(`Expected a stable identifier`);
1044
1045
  }
@@ -1057,7 +1058,7 @@ class CacheCapabilitiesManager {
1057
1058
  return this._store.schema;
1058
1059
  }
1059
1060
  setRecordId(identifier, id) {
1060
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1061
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1061
1062
  if (!test) {
1062
1063
  throw new Error(`Expected a stable identifier`);
1063
1064
  }
@@ -1068,7 +1069,7 @@ class CacheCapabilitiesManager {
1068
1069
  return Boolean(this._store._instanceCache.peek(identifier));
1069
1070
  }
1070
1071
  disconnectRecord(identifier) {
1071
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1072
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1072
1073
  if (!test) {
1073
1074
  throw new Error(`Expected a stable identifier`);
1074
1075
  }
@@ -1077,7 +1078,7 @@ class CacheCapabilitiesManager {
1077
1078
  this._pendingNotifies.delete(identifier);
1078
1079
  }
1079
1080
  }
1080
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
1081
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
1081
1082
  CacheCapabilitiesManager.prototype.getSchemaDefinitionService = function () {
1082
1083
  // FIXME add deprecation for this
1083
1084
  return this._store.schema;
@@ -1091,7 +1092,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
1091
1092
 
1092
1093
  const CacheForIdentifierCache = getOrSetGlobal('CacheForIdentifierCache', new Map());
1093
1094
  function setCacheFor(identifier, cache) {
1094
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1095
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1095
1096
  if (!test) {
1096
1097
  throw new Error(`Illegal set of identifier`);
1097
1098
  }
@@ -1141,7 +1142,7 @@ function peekRecordIdentifier(record) {
1141
1142
  */
1142
1143
 
1143
1144
  function recordIdentifierFor(record) {
1144
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1145
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1145
1146
  if (!test) {
1146
1147
  throw new Error(`${String(record)} is not a record instantiated by @ember-data-mirror/store`);
1147
1148
  }
@@ -1149,7 +1150,7 @@ function recordIdentifierFor(record) {
1149
1150
  return RecordCache.get(record);
1150
1151
  }
1151
1152
  function setRecordIdentifier(record, identifier) {
1152
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1153
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
1153
1154
  if (RecordCache.has(record) && RecordCache.get(record) !== identifier) {
1154
1155
  throw new Error(`${String(record)} was already assigned an identifier`);
1155
1156
  }
@@ -1168,7 +1169,7 @@ function setRecordIdentifier(record, identifier) {
1168
1169
  const StoreMap = getOrSetGlobal('StoreMap', new Map());
1169
1170
  function storeFor(record) {
1170
1171
  const store = StoreMap.get(record);
1171
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1172
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1172
1173
  if (!test) {
1173
1174
  throw new Error(`A record in a disconnected state cannot utilize the store. This typically means the record has been destroyed, most commonly by unloading it.`);
1174
1175
  }
@@ -1210,7 +1211,7 @@ class InstanceCache {
1210
1211
  if ('id' in resourceData) {
1211
1212
  throw new Error(`Failed to update the 'id' for the RecordIdentifier '${identifier.type}:${String(identifier.id)} (${identifier.lid})' to '${String(resourceData.id)}', because that id is already in use by '${matchedIdentifier.type}:${String(matchedIdentifier.id)} (${matchedIdentifier.lid})'`);
1212
1213
  }
1213
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1214
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1214
1215
  {
1215
1216
  throw new Error(`Failed to update the RecordIdentifier '${identifier.type}:${String(identifier.id)} (${identifier.lid})' to merge with the detected duplicate identifier '${matchedIdentifier.type}:${String(matchedIdentifier.id)} (${String(matchedIdentifier.lid)})'`);
1216
1217
  }
@@ -1239,7 +1240,7 @@ class InstanceCache {
1239
1240
  getRecord(identifier, properties) {
1240
1241
  let record = this.__instances.record.get(identifier);
1241
1242
  if (!record) {
1242
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1243
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1243
1244
  if (!test) {
1244
1245
  throw new Error(`Cannot create a new record instance while the store is being destroyed`);
1245
1246
  }
@@ -1251,7 +1252,7 @@ class InstanceCache {
1251
1252
  setCacheFor(record, cache);
1252
1253
  StoreMap.set(record, this.store);
1253
1254
  this.__instances.record.set(identifier, record);
1254
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1255
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1255
1256
  // eslint-disable-next-line no-console
1256
1257
  console.log(`InstanceCache: created Record for ${String(identifier)}`, properties);
1257
1258
  }
@@ -1290,7 +1291,7 @@ class InstanceCache {
1290
1291
  }
1291
1292
  disconnect(identifier) {
1292
1293
  const record = this.__instances.record.get(identifier);
1293
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1294
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1294
1295
  if (!test) {
1295
1296
  throw new Error('Cannot destroy record while it is still materialized');
1296
1297
  }
@@ -1299,25 +1300,25 @@ class InstanceCache {
1299
1300
  this.store.identifierCache.forgetRecordIdentifier(identifier);
1300
1301
  removeRecordDataFor(identifier);
1301
1302
  this.store._requestCache._clearEntries(identifier);
1302
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1303
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1303
1304
  // eslint-disable-next-line no-console
1304
1305
  console.log(`InstanceCache: disconnected ${String(identifier)}`);
1305
1306
  }
1306
1307
  }
1307
1308
  unloadRecord(identifier) {
1308
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1309
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
1309
1310
  const requests = this.store.getRequestStateService().getPendingRequestsForRecord(identifier);
1310
1311
  if (requests.some(req => {
1311
1312
  return req.type === 'mutation';
1312
1313
  })) {
1313
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1314
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1314
1315
  {
1315
1316
  throw new Error(`You can only unload a record which is not inFlight. '${String(identifier)}'`);
1316
1317
  }
1317
1318
  })() : {};
1318
1319
  }
1319
1320
  }
1320
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1321
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1321
1322
  // eslint-disable-next-line no-console
1322
1323
  console.groupCollapsed(`InstanceCache: unloading record for ${String(identifier)}`);
1323
1324
  }
@@ -1332,7 +1333,7 @@ class InstanceCache {
1332
1333
  StoreMap.delete(record);
1333
1334
  RecordCache.delete(record);
1334
1335
  removeRecordDataFor(record);
1335
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1336
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1336
1337
  // eslint-disable-next-line no-console
1337
1338
  console.log(`InstanceCache: destroyed record for ${String(identifier)}`);
1338
1339
  }
@@ -1340,7 +1341,7 @@ class InstanceCache {
1340
1341
  if (cache) {
1341
1342
  cache.unloadRecord(identifier);
1342
1343
  removeRecordDataFor(identifier);
1343
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1344
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1344
1345
  // eslint-disable-next-line no-console
1345
1346
  console.log(`InstanceCache: destroyed cache for ${String(identifier)}`);
1346
1347
  }
@@ -1348,7 +1349,7 @@ class InstanceCache {
1348
1349
  this.disconnect(identifier);
1349
1350
  }
1350
1351
  this.store._requestCache._clearEntries(identifier);
1351
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1352
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1352
1353
  // eslint-disable-next-line no-console
1353
1354
  console.log(`InstanceCache: unloaded RecordData for ${String(identifier)}`);
1354
1355
  // eslint-disable-next-line no-console
@@ -1387,7 +1388,7 @@ class InstanceCache {
1387
1388
  const oldId = identifier.id;
1388
1389
 
1389
1390
  // ID absolutely can't be missing if the oldID is empty (missing Id in response for a new record)
1390
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1391
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1391
1392
  if (!test) {
1392
1393
  throw new Error(`'${type}' was saved to the server, but the response does not have an id and your record does not either.`);
1393
1394
  }
@@ -1395,7 +1396,7 @@ class InstanceCache {
1395
1396
 
1396
1397
  // ID absolutely can't be different than oldID if oldID is not null
1397
1398
  // TODO this assertion and restriction may not strictly be needed in the identifiers world
1398
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1399
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1399
1400
  if (!test) {
1400
1401
  throw new Error(`Cannot update the id for '${type}:${lid}' from '${String(oldId)}' to '${id}'.`);
1401
1402
  }
@@ -1407,7 +1408,7 @@ class InstanceCache {
1407
1408
  warn(`Your ${type} record was saved to the server, but the response does not have an id.`, !(oldId !== null && id === null));
1408
1409
  return;
1409
1410
  }
1410
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_INSTANCE_CACHE)) {
1411
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE)) {
1411
1412
  // eslint-disable-next-line no-console
1412
1413
  console.log(`InstanceCache: updating id to '${id}' for record ${String(identifier)}`);
1413
1414
  }
@@ -1415,7 +1416,7 @@ class InstanceCache {
1415
1416
  type,
1416
1417
  id
1417
1418
  });
1418
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1419
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1419
1420
  if (!test) {
1420
1421
  throw new Error(`'${type}' was saved to the server, but the response returned the new id '${id}', which has already been used with another record.'`);
1421
1422
  }
@@ -1480,7 +1481,7 @@ function preloadData(store, identifier, preload) {
1480
1481
  function preloadRelationship(schema, preloadValue) {
1481
1482
  const relatedType = schema.type;
1482
1483
  if (schema.kind === 'hasMany') {
1483
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1484
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1484
1485
  if (!test) {
1485
1486
  throw new Error('You need to pass in an array to set a hasMany property on a record');
1486
1487
  }
@@ -1489,7 +1490,7 @@ function preloadRelationship(schema, preloadValue) {
1489
1490
  data: preloadValue.map(value => _convertPreloadRelationshipToJSON(value, relatedType))
1490
1491
  };
1491
1492
  }
1492
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1493
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
1493
1494
  if (!test) {
1494
1495
  throw new Error('You should not pass in an array to set a belongsTo property on a record');
1495
1496
  }
@@ -2156,9 +2157,9 @@ class CacheManager {
2156
2157
  /**
2157
2158
  * @module @ember-data-mirror/store
2158
2159
  */
2159
- // eslint-disable-next-line no-restricted-imports
2160
+
2160
2161
  let tokenId = 0;
2161
- const CacheOperations = new Set(['added', 'removed', 'state', 'updated']);
2162
+ const CacheOperations = new Set(['added', 'removed', 'state', 'updated', 'invalidated']);
2162
2163
  function isCacheOperationValue(value) {
2163
2164
  return CacheOperations.has(value);
2164
2165
  }
@@ -2168,7 +2169,7 @@ function runLoopIsFlushing() {
2168
2169
  }
2169
2170
  function _unsubscribe(tokens, token, cache) {
2170
2171
  const identifier = tokens.get(token);
2171
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2172
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS)) {
2172
2173
  if (!identifier) {
2173
2174
  // eslint-disable-next-line no-console
2174
2175
  console.log('Passed unknown unsubscribe token to unsubscribe', identifier);
@@ -2230,7 +2231,7 @@ class NotificationManager {
2230
2231
  */
2231
2232
 
2232
2233
  subscribe(identifier, callback) {
2233
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2234
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2234
2235
  if (!test) {
2235
2236
  throw new Error(`Expected to receive a stable Identifier to subscribe to`);
2236
2237
  }
@@ -2240,7 +2241,7 @@ class NotificationManager {
2240
2241
  map = new Map();
2241
2242
  this._cache.set(identifier, map);
2242
2243
  }
2243
- const unsubToken = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? {
2244
+ const unsubToken = macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? {
2244
2245
  _tokenRef: tokenId++
2245
2246
  } : {};
2246
2247
  map.set(unsubToken, callback);
@@ -2273,19 +2274,19 @@ class NotificationManager {
2273
2274
  */
2274
2275
 
2275
2276
  notify(identifier, value, key) {
2276
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2277
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2277
2278
  if (!test) {
2278
2279
  throw new Error(`Notify does not accept a key argument for the namespace '${value}'. Received key '${key || ''}'.`);
2279
2280
  }
2280
2281
  })(!key || value === 'attributes' || value === 'relationships') : {};
2281
2282
  if (!isStableIdentifier(identifier) && !isDocumentIdentifier(identifier)) {
2282
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2283
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS)) {
2283
2284
  // eslint-disable-next-line no-console
2284
2285
  console.log(`Notifying: Expected to receive a stable Identifier to notify '${value}' '${key || ''}' with, but ${String(identifier)} is not in the cache`, identifier);
2285
2286
  }
2286
2287
  return false;
2287
2288
  }
2288
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2289
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS)) {
2289
2290
  // eslint-disable-next-line no-console
2290
2291
  console.log(`Buffering Notify: ${String(identifier.lid)}\t${value}\t${key || ''}`);
2291
2292
  }
@@ -2318,21 +2319,22 @@ class NotificationManager {
2318
2319
  this._flush();
2319
2320
  }
2320
2321
  _flush() {
2321
- if (this._buffered.size) {
2322
- this._buffered.forEach((states, identifier) => {
2322
+ const buffered = this._buffered;
2323
+ if (buffered.size) {
2324
+ this._buffered = new Map();
2325
+ buffered.forEach((states, identifier) => {
2323
2326
  states.forEach(args => {
2324
2327
  // @ts-expect-error
2325
2328
  this._flushNotification(identifier, args[0], args[1]);
2326
2329
  });
2327
2330
  });
2328
- this._buffered = new Map();
2329
2331
  }
2330
2332
  this._hasFlush = false;
2331
2333
  this._onFlushCB?.();
2332
2334
  this._onFlushCB = undefined;
2333
2335
  }
2334
2336
  _flushNotification(identifier, value, key) {
2335
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
2337
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS)) {
2336
2338
  // eslint-disable-next-line no-console
2337
2339
  console.log(`Notifying: ${String(identifier)}\t${value}\t${key || ''}`);
2338
2340
  }
@@ -2372,71 +2374,6 @@ class NotificationManager {
2372
2374
  */
2373
2375
 
2374
2376
  const NativeProxy = Proxy;
2375
- var __defProp = Object.defineProperty;
2376
- var __export = (target, all) => {
2377
- for (var name in all) __defProp(target, name, {
2378
- get: all[name],
2379
- enumerable: true
2380
- });
2381
- };
2382
-
2383
- // src/runtime.ts
2384
- var runtime_exports = {};
2385
- __export(runtime_exports, {
2386
- c: () => decorateClass,
2387
- f: () => decorateFieldV1,
2388
- g: () => decorateFieldV2,
2389
- i: () => initializeDeferredDecorator,
2390
- m: () => decorateMethodV1,
2391
- n: () => decorateMethodV2,
2392
- p: () => decoratePOJO
2393
- });
2394
- var deferred = /* @__PURE__ */new WeakMap();
2395
- function deferDecorator(proto, prop, desc) {
2396
- let map = deferred.get(proto);
2397
- if (!map) {
2398
- map = /* @__PURE__ */new Map();
2399
- deferred.set(proto, map);
2400
- }
2401
- map.set(prop, desc);
2402
- }
2403
- function findDeferredDecorator(target, prop) {
2404
- let cursor = target.prototype;
2405
- while (cursor) {
2406
- let desc = deferred.get(cursor)?.get(prop);
2407
- if (desc) {
2408
- return desc;
2409
- }
2410
- cursor = cursor.prototype;
2411
- }
2412
- }
2413
- function decorateFieldV1(target, prop, decorators, initializer) {
2414
- return decorateFieldV2(target.prototype, prop, decorators, initializer);
2415
- }
2416
- function decorateFieldV2(prototype, prop, decorators, initializer) {
2417
- let desc = {
2418
- configurable: true,
2419
- enumerable: true,
2420
- writable: true,
2421
- initializer: null
2422
- };
2423
- if (initializer) {
2424
- desc.initializer = initializer;
2425
- }
2426
- for (let decorator of decorators) {
2427
- desc = decorator(prototype, prop, desc) || desc;
2428
- }
2429
- if (desc.initializer === void 0) {
2430
- Object.defineProperty(prototype, prop, desc);
2431
- } else {
2432
- deferDecorator(prototype, prop, desc);
2433
- }
2434
- }
2435
- function decorateMethodV1({
2436
- prototype
2437
- }, prop, decorators) {
2438
- return decorateMethodV2(prototype, prop, decorators);
2439
- }
2440
2377
  function decorateMethodV2(prototype, prop, decorators) {
2441
2378
  const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
2442
2379
  let desc = {
@@ -2451,46 +2388,6 @@ function decorateMethodV2(prototype, prop, decorators) {
2451
2388
  }
2452
2389
  Object.defineProperty(prototype, prop, desc);
2453
2390
  }
2454
- function initializeDeferredDecorator(target, prop) {
2455
- let desc = findDeferredDecorator(target.constructor, prop);
2456
- if (desc) {
2457
- Object.defineProperty(target, prop, {
2458
- enumerable: desc.enumerable,
2459
- configurable: desc.configurable,
2460
- writable: desc.writable,
2461
- value: desc.initializer ? desc.initializer.call(target) : void 0
2462
- });
2463
- }
2464
- }
2465
- function decorateClass(target, decorators) {
2466
- return decorators.reduce((accum, decorator) => decorator(accum) || accum, target);
2467
- }
2468
- function decoratePOJO(pojo, decorated) {
2469
- for (let [type, prop, decorators] of decorated) {
2470
- if (type === "field") {
2471
- decoratePojoField(pojo, prop, decorators);
2472
- } else {
2473
- decorateMethodV2(pojo, prop, decorators);
2474
- }
2475
- }
2476
- return pojo;
2477
- }
2478
- function decoratePojoField(pojo, prop, decorators) {
2479
- let desc = {
2480
- configurable: true,
2481
- enumerable: true,
2482
- writable: true,
2483
- initializer: () => Object.getOwnPropertyDescriptor(pojo, prop)?.value
2484
- };
2485
- for (let decorator of decorators) {
2486
- desc = decorator(pojo, prop, desc) || desc;
2487
- }
2488
- if (desc.initializer) {
2489
- desc.value = desc.initializer.call(pojo);
2490
- delete desc.initializer;
2491
- }
2492
- Object.defineProperty(pojo, prop, desc);
2493
- }
2494
2391
 
2495
2392
  /**
2496
2393
  @module @ember-data-mirror/store
@@ -2527,7 +2424,7 @@ function safeForEach(instance, arr, store, callback, target) {
2527
2424
  }
2528
2425
  // clone to prevent mutation
2529
2426
  arr = arr.slice();
2530
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2427
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2531
2428
  if (!test) {
2532
2429
  throw new Error('`forEach` expects a function as first argument.');
2533
2430
  }
@@ -2681,7 +2578,7 @@ class IdentifierArray {
2681
2578
  // array functions must run through Reflect to work properly
2682
2579
  // binding via other means will not work.
2683
2580
  if (!options.allowMutation) {
2684
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2581
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2685
2582
  if (!test) {
2686
2583
  throw new Error(`Mutating this array of records via ${String(prop)} is not allowed.`);
2687
2584
  }
@@ -2689,7 +2586,7 @@ class IdentifierArray {
2689
2586
  return;
2690
2587
  }
2691
2588
  const args = Array.prototype.slice.call(arguments);
2692
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2589
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2693
2590
  if (!test) {
2694
2591
  throw new Error(`Cannot start a new array transaction while a previous transaction is underway`);
2695
2592
  }
@@ -2735,7 +2632,7 @@ class IdentifierArray {
2735
2632
  } else if (transaction) {
2736
2633
  return Reflect.set(target, prop, value);
2737
2634
  } else {
2738
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2635
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2739
2636
  {
2740
2637
  throw new Error(`unexpected length set`);
2741
2638
  }
@@ -2762,7 +2659,7 @@ class IdentifierArray {
2762
2659
  if (index === null || index > target.length) {
2763
2660
  if (index !== null && transaction) {
2764
2661
  const identifier = recordIdentifierFor(value);
2765
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2662
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2766
2663
  if (!test) {
2767
2664
  throw new Error(`Cannot set index ${index} past the end of the array.`);
2768
2665
  }
@@ -2777,7 +2674,7 @@ class IdentifierArray {
2777
2674
  return false;
2778
2675
  }
2779
2676
  if (!options.allowMutation) {
2780
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2677
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2781
2678
  if (!test) {
2782
2679
  throw new Error(`Mutating ${String(prop)} on this Array is not allowed.`);
2783
2680
  }
@@ -2786,8 +2683,7 @@ class IdentifierArray {
2786
2683
  }
2787
2684
  const original = target[index];
2788
2685
  const newIdentifier = extractIdentifierFromRecord$1(value);
2789
- target[index] = newIdentifier;
2790
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2686
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2791
2687
  if (!test) {
2792
2688
  throw new Error(`Expected a record`);
2793
2689
  }
@@ -2816,7 +2712,7 @@ class IdentifierArray {
2816
2712
  return true;
2817
2713
  },
2818
2714
  deleteProperty(target, prop) {
2819
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2715
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2820
2716
  if (!test) {
2821
2717
  throw new Error(`Deleting keys on managed arrays is disallowed`);
2822
2718
  }
@@ -2872,7 +2768,7 @@ class IdentifierArray {
2872
2768
  is finished.
2873
2769
  */
2874
2770
  _update() {
2875
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2771
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2876
2772
  if (!test) {
2877
2773
  throw new Error(`_update cannot be used with this array`);
2878
2774
  }
@@ -2915,7 +2811,11 @@ const desc = {
2915
2811
  enumerable: true,
2916
2812
  configurable: false,
2917
2813
  get: function () {
2918
- return this;
2814
+ // here to support computed chains
2815
+ // and {{#each}}
2816
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
2817
+ return this;
2818
+ }
2919
2819
  }
2920
2820
  };
2921
2821
  compat(desc);
@@ -2935,12 +2835,12 @@ class Collection extends IdentifierArray {
2935
2835
  } = this;
2936
2836
 
2937
2837
  // TODO save options from initial request?
2938
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2838
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2939
2839
  if (!test) {
2940
2840
  throw new Error(`update cannot be used with this array`);
2941
2841
  }
2942
2842
  })(this.modelName) : {};
2943
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2843
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2944
2844
  if (!test) {
2945
2845
  throw new Error(`update cannot be used with no query`);
2946
2846
  }
@@ -2967,7 +2867,7 @@ Collection.prototype.query = null;
2967
2867
  // Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
2968
2868
 
2969
2869
  function assertRecordPassedToHasMany(record) {
2970
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2870
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2971
2871
  if (!test) {
2972
2872
  throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed $${typeof record}`);
2973
2873
  }
@@ -3342,7 +3242,7 @@ function sync(array, changes, arraySet) {
3342
3242
 
3343
3243
  const Touching = getOrSetGlobal('Touching', Symbol('touching'));
3344
3244
  const RequestPromise = getOrSetGlobal('RequestPromise', Symbol('promise'));
3345
- const EMPTY_ARR = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? Object.freeze([]) : [];
3245
+ const EMPTY_ARR = macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? Object.freeze([]) : [];
3346
3246
  function hasRecordIdentifier(op) {
3347
3247
  return 'recordIdentifier' in op;
3348
3248
  }
@@ -3413,7 +3313,7 @@ class RequestStateService {
3413
3313
  throw error;
3414
3314
  });
3415
3315
  }
3416
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3316
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3417
3317
  {
3418
3318
  throw new Error(`Expected a well formed query`);
3419
3319
  }
@@ -3550,12 +3450,12 @@ function constructResource(type, id, lid) {
3550
3450
  if ('id' in resource) {
3551
3451
  resource.id = coerceId(resource.id);
3552
3452
  }
3553
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3453
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3554
3454
  if (!test) {
3555
3455
  throw new Error('Expected either id or lid to be a valid string');
3556
3456
  }
3557
3457
  })('id' in resource && isNonEmptyString(resource.id) || isNonEmptyString(resource.lid)) : {};
3558
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3458
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3559
3459
  if (!test) {
3560
3460
  throw new Error('if id is present, the type must be a string');
3561
3461
  }
@@ -3571,7 +3471,7 @@ function constructResource(type, id, lid) {
3571
3471
  }
3572
3472
  throw new Error('Expected either id or lid to be a valid string');
3573
3473
  }
3574
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3474
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3575
3475
  if (!test) {
3576
3476
  throw new Error('type must be a string');
3577
3477
  }
@@ -3639,7 +3539,8 @@ const EmptyClass = class {
3639
3539
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
3640
3540
  constructor(args) {}
3641
3541
  };
3642
- const BaseClass = macroCondition(dependencySatisfies('ember-source', '*')) ? macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_STORE_EXTENDS_EMBER_OBJECT) ? importSync('@ember/object') : EmptyClass : EmptyClass;
3542
+ const _BaseClass = macroCondition(dependencySatisfies('ember-source', '*')) ? macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_STORE_EXTENDS_EMBER_OBJECT) ? importSync('@ember/object') : EmptyClass : EmptyClass;
3543
+ const BaseClass = _BaseClass.default ? _BaseClass.default : _BaseClass;
3643
3544
  if (BaseClass !== EmptyClass) {
3644
3545
  deprecate(`The Store class extending from EmberObject is deprecated.
3645
3546
  Please remove usage of EmberObject APIs and mark your class as not requiring it.
@@ -3661,7 +3562,7 @@ const app = new EmberApp(defaults, {
3661
3562
  until: '6.0',
3662
3563
  for: 'ember-data-mirror',
3663
3564
  since: {
3664
- available: '5.4',
3565
+ available: '4.13',
3665
3566
  enabled: '5.4'
3666
3567
  }
3667
3568
  });
@@ -3766,6 +3667,17 @@ class Store extends BaseClass {
3766
3667
 
3767
3668
  // Private
3768
3669
 
3670
+ /**
3671
+ * Async flush buffers notifications until flushed
3672
+ * by finalization of a future configured by store.request
3673
+ *
3674
+ * This is useful for ensuring that notifications are delivered
3675
+ * prior to the promise resolving but without risk of promise
3676
+ * interleaving.
3677
+ *
3678
+ * @internal
3679
+ */
3680
+
3769
3681
  // DEBUG-only properties
3770
3682
 
3771
3683
  get isDestroying() {
@@ -3804,13 +3716,13 @@ class Store extends BaseClass {
3804
3716
  this.isDestroyed = false;
3805
3717
  }
3806
3718
  _run(cb) {
3807
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3719
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3808
3720
  if (!test) {
3809
3721
  throw new Error(`EmberData should never encounter a nested run`);
3810
3722
  }
3811
3723
  })(!this._cbs) : {};
3812
3724
  const _cbs = this._cbs = {};
3813
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3725
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
3814
3726
  try {
3815
3727
  cb();
3816
3728
  if (_cbs.coalesce) {
@@ -3839,6 +3751,16 @@ class Store extends BaseClass {
3839
3751
  this._cbs = null;
3840
3752
  }
3841
3753
  }
3754
+
3755
+ /**
3756
+ * Executes the callback, ensurng that any work that calls
3757
+ * store._schedule is executed after in the right order.
3758
+ *
3759
+ * When queues already exist, scheduled callbacks will
3760
+ * join the existing queue.
3761
+ *
3762
+ * @internal
3763
+ */
3842
3764
  _join(cb) {
3843
3765
  if (this._cbs) {
3844
3766
  cb();
@@ -3847,12 +3769,12 @@ class Store extends BaseClass {
3847
3769
  }
3848
3770
  }
3849
3771
  _schedule(name, cb) {
3850
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3772
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3851
3773
  if (!test) {
3852
3774
  throw new Error(`EmberData expects to schedule only when there is an active run`);
3853
3775
  }
3854
3776
  })(!!this._cbs) : {};
3855
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3777
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3856
3778
  if (!test) {
3857
3779
  throw new Error(`EmberData expects only one flush per queue name, cannot schedule ${name}`);
3858
3780
  }
@@ -3875,7 +3797,7 @@ class Store extends BaseClass {
3875
3797
  return this._requestCache;
3876
3798
  }
3877
3799
  _getAllPending() {
3878
- if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
3800
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
3879
3801
  const all = [];
3880
3802
  const pending = this._requestCache._pending;
3881
3803
  pending.forEach(requests => {
@@ -3953,12 +3875,12 @@ class Store extends BaseClass {
3953
3875
  const identifierCache = this.identifierCache;
3954
3876
  opts.records = requestConfig.records.map(r => identifierCache.getOrCreateRecordIdentifier(r));
3955
3877
  }
3956
- if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
3878
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
3957
3879
  if (this.DISABLE_WAITER) {
3958
3880
  opts.disableTestWaiter = typeof requestConfig.disableTestWaiter === 'boolean' ? requestConfig.disableTestWaiter : true;
3959
3881
  }
3960
3882
  }
3961
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_REQUESTS)) {
3883
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_REQUESTS)) {
3962
3884
  let options;
3963
3885
  try {
3964
3886
  options = JSON.parse(JSON.stringify(requestConfig));
@@ -3971,7 +3893,7 @@ class Store extends BaseClass {
3971
3893
  const request = Object.assign({}, requestConfig, opts);
3972
3894
  const future = this.requestManager.request(request);
3973
3895
  future.onFinalize(() => {
3974
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_REQUESTS)) {
3896
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_REQUESTS)) {
3975
3897
  // eslint-disable-next-line no-console
3976
3898
  console.log(`request: [[FINALIZE]] ${requestConfig.op && !requestConfig.url ? '(LEGACY) ' : ''}${requestConfig.op || '<unknown operation>'} ${requestConfig.url || '<empty url>'} ${requestConfig.method || '<empty method>'}`);
3977
3899
  }
@@ -4036,15 +3958,15 @@ class Store extends BaseClass {
4036
3958
  modelFor(type) {
4037
3959
  // FIXME add deprecation and deprecation stripping
4038
3960
  // FIXME/TODO update RFC to remove this method
4039
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3961
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4040
3962
  assertDestroyedStoreOnly(this, 'modelFor');
4041
3963
  }
4042
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3964
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4043
3965
  if (!test) {
4044
3966
  throw new Error(`You need to pass <type> to the store's modelFor method`);
4045
3967
  }
4046
3968
  })(typeof type === 'string' && type.length) : {};
4047
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3969
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4048
3970
  if (!test) {
4049
3971
  throw new Error(`No model was found for '${type}' and no schema handles the type`);
4050
3972
  }
@@ -4080,15 +4002,15 @@ class Store extends BaseClass {
4080
4002
  */
4081
4003
 
4082
4004
  createRecord(type, inputProperties) {
4083
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4005
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4084
4006
  assertDestroyingStore(this, 'createRecord');
4085
4007
  }
4086
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4008
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4087
4009
  if (!test) {
4088
4010
  throw new Error(`You need to pass a model name to the store's createRecord method`);
4089
4011
  }
4090
4012
  })(type) : {};
4091
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4013
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4092
4014
  if (!test) {
4093
4015
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
4094
4016
  }
@@ -4127,7 +4049,7 @@ class Store extends BaseClass {
4127
4049
  };
4128
4050
  if (resource.id) {
4129
4051
  const identifier = this.identifierCache.peekRecordIdentifier(resource);
4130
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4052
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4131
4053
  if (!test) {
4132
4054
  throw new Error(`The id ${String(properties.id)} has already been used with another '${normalizedModelName}' record.`);
4133
4055
  }
@@ -4156,12 +4078,12 @@ class Store extends BaseClass {
4156
4078
  @param {unknown} record
4157
4079
  */
4158
4080
  deleteRecord(record) {
4159
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4081
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4160
4082
  assertDestroyingStore(this, 'deleteRecord');
4161
4083
  }
4162
4084
  const identifier = peekRecordIdentifier(record);
4163
4085
  const cache = this.cache;
4164
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4086
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4165
4087
  if (!test) {
4166
4088
  throw new Error(`expected the record to be connected to a cache`);
4167
4089
  }
@@ -4188,7 +4110,7 @@ class Store extends BaseClass {
4188
4110
  @param {Model} record
4189
4111
  */
4190
4112
  unloadRecord(record) {
4191
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4113
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4192
4114
  assertDestroyingStore(this, 'unloadRecord');
4193
4115
  }
4194
4116
  const identifier = peekRecordIdentifier(record);
@@ -4402,7 +4324,7 @@ class Store extends BaseClass {
4402
4324
  ```app/routes/post.js
4403
4325
  export default class PostRoute extends Route {
4404
4326
  model(params) {
4405
- return this.store.findRecord('post', params.post_id, { include: 'comments' });
4327
+ return this.store.findRecord('post', params.post_id, { include: ['comments'] });
4406
4328
  }
4407
4329
  }
4408
4330
  ```
@@ -4424,13 +4346,13 @@ class Store extends BaseClass {
4424
4346
  In this case, the post's comments would then be available in your template as
4425
4347
  `model.comments`.
4426
4348
  Multiple relationships can be requested using an `include` parameter consisting of a
4427
- comma-separated list (without white-space) while nested relationships can be specified
4349
+ list of relationship names, while nested relationships can be specified
4428
4350
  using a dot-separated sequence of relationship names. So to request both the post's
4429
4351
  comments and the authors of those comments the request would look like this:
4430
4352
  ```app/routes/post.js
4431
4353
  export default class PostRoute extends Route {
4432
4354
  model(params) {
4433
- return this.store.findRecord('post', params.post_id, { include: 'comments,comments.author' });
4355
+ return this.store.findRecord('post', params.post_id, { include: ['comments','comments.author'] });
4434
4356
  }
4435
4357
  }
4436
4358
  ```
@@ -4476,10 +4398,10 @@ class Store extends BaseClass {
4476
4398
  */
4477
4399
 
4478
4400
  findRecord(resource, id, options) {
4479
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4401
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4480
4402
  assertDestroyingStore(this, 'findRecord');
4481
4403
  }
4482
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4404
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4483
4405
  if (!test) {
4484
4406
  throw new Error(`You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`);
4485
4407
  }
@@ -4487,7 +4409,7 @@ class Store extends BaseClass {
4487
4409
  if (isMaybeIdentifier(resource)) {
4488
4410
  options = id;
4489
4411
  } else {
4490
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4412
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4491
4413
  if (!test) {
4492
4414
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`);
4493
4415
  }
@@ -4555,7 +4477,7 @@ class Store extends BaseClass {
4555
4477
  */
4556
4478
  // TODO @deprecate getReference (and references generally)
4557
4479
  getReference(resource, id) {
4558
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4480
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4559
4481
  assertDestroyingStore(this, 'getReference');
4560
4482
  }
4561
4483
  let resourceIdentifier;
@@ -4566,7 +4488,7 @@ class Store extends BaseClass {
4566
4488
  const normalizedId = ensureStringId(id);
4567
4489
  resourceIdentifier = constructResource(type, normalizedId);
4568
4490
  }
4569
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4491
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4570
4492
  if (!test) {
4571
4493
  throw new Error('getReference expected to receive either a resource identifier or type and id as arguments');
4572
4494
  }
@@ -4618,15 +4540,15 @@ class Store extends BaseClass {
4618
4540
  // this is basically an "are we not empty" query.
4619
4541
  return isLoaded ? this._instanceCache.getRecord(stableIdentifier) : null;
4620
4542
  }
4621
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4543
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4622
4544
  assertDestroyingStore(this, 'peekRecord');
4623
4545
  }
4624
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4546
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4625
4547
  if (!test) {
4626
4548
  throw new Error(`You need to pass a model name to the store's peekRecord method`);
4627
4549
  }
4628
4550
  })(identifier) : {};
4629
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4551
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4630
4552
  if (!test) {
4631
4553
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${String(identifier)}`);
4632
4554
  }
@@ -4681,20 +4603,20 @@ class Store extends BaseClass {
4681
4603
  */
4682
4604
 
4683
4605
  query(type, query, options = {}) {
4684
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4606
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4685
4607
  assertDestroyingStore(this, 'query');
4686
4608
  }
4687
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4609
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4688
4610
  if (!test) {
4689
4611
  throw new Error(`You need to pass a model name to the store's query method`);
4690
4612
  }
4691
4613
  })(type) : {};
4692
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4614
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4693
4615
  if (!test) {
4694
4616
  throw new Error(`You need to pass a query hash to the store's query method`);
4695
4617
  }
4696
4618
  })(query) : {};
4697
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4619
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4698
4620
  if (!test) {
4699
4621
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
4700
4622
  }
@@ -4796,20 +4718,20 @@ class Store extends BaseClass {
4796
4718
  */
4797
4719
 
4798
4720
  queryRecord(type, query, options) {
4799
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4721
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4800
4722
  assertDestroyingStore(this, 'queryRecord');
4801
4723
  }
4802
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4724
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4803
4725
  if (!test) {
4804
4726
  throw new Error(`You need to pass a model name to the store's queryRecord method`);
4805
4727
  }
4806
4728
  })(type) : {};
4807
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4729
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4808
4730
  if (!test) {
4809
4731
  throw new Error(`You need to pass a query hash to the store's queryRecord method`);
4810
4732
  }
4811
4733
  })(query) : {};
4812
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4734
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4813
4735
  if (!test) {
4814
4736
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
4815
4737
  }
@@ -4951,18 +4873,18 @@ class Store extends BaseClass {
4951
4873
  ```app/routes/posts.js
4952
4874
  export default class PostsRoute extends Route {
4953
4875
  model() {
4954
- return this.store.findAll('post', { include: 'comments' });
4876
+ return this.store.findAll('post', { include: ['comments'] });
4955
4877
  }
4956
4878
  }
4957
4879
  ```
4958
4880
  Multiple relationships can be requested using an `include` parameter consisting of a
4959
- comma-separated list (without white-space) while nested relationships can be specified
4881
+ list or relationship names, while nested relationships can be specified
4960
4882
  using a dot-separated sequence of relationship names. So to request both the posts'
4961
4883
  comments and the authors of those comments the request would look like this:
4962
4884
  ```app/routes/posts.js
4963
4885
  export default class PostsRoute extends Route {
4964
4886
  model() {
4965
- return this.store.findAll('post', { include: 'comments,comments.author' });
4887
+ return this.store.findAll('post', { include: ['comments','comments.author'] });
4966
4888
  }
4967
4889
  }
4968
4890
  ```
@@ -4976,15 +4898,15 @@ class Store extends BaseClass {
4976
4898
  */
4977
4899
 
4978
4900
  findAll(type, options = {}) {
4979
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4901
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
4980
4902
  assertDestroyingStore(this, 'findAll');
4981
4903
  }
4982
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4904
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4983
4905
  if (!test) {
4984
4906
  throw new Error(`You need to pass a model name to the store's findAll method`);
4985
4907
  }
4986
4908
  })(type) : {};
4987
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4909
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
4988
4910
  if (!test) {
4989
4911
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
4990
4912
  }
@@ -5024,15 +4946,15 @@ class Store extends BaseClass {
5024
4946
  */
5025
4947
 
5026
4948
  peekAll(type) {
5027
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4949
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5028
4950
  assertDestroyingStore(this, 'peekAll');
5029
4951
  }
5030
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4952
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5031
4953
  if (!test) {
5032
4954
  throw new Error(`You need to pass a model name to the store's peekAll method`);
5033
4955
  }
5034
4956
  })(type) : {};
5035
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4957
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5036
4958
  if (!test) {
5037
4959
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
5038
4960
  }
@@ -5054,10 +4976,10 @@ class Store extends BaseClass {
5054
4976
  */
5055
4977
 
5056
4978
  unloadAll(type) {
5057
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4979
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5058
4980
  assertDestroyedStoreOnly(this, 'unloadAll');
5059
4981
  }
5060
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4982
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5061
4983
  if (!test) {
5062
4984
  throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${String(type)}`);
5063
4985
  }
@@ -5208,7 +5130,7 @@ class Store extends BaseClass {
5208
5130
  */
5209
5131
 
5210
5132
  push(data) {
5211
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5133
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5212
5134
  assertDestroyingStore(this, 'push');
5213
5135
  }
5214
5136
  const pushed = this._push(data, false);
@@ -5230,15 +5152,15 @@ class Store extends BaseClass {
5230
5152
  @return {StableRecordIdentifier|Array<StableRecordIdentifier>|null} identifiers for the primary records that had data loaded
5231
5153
  */
5232
5154
  _push(jsonApiDoc, asyncFlush) {
5233
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5155
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5234
5156
  assertDestroyingStore(this, '_push');
5235
5157
  }
5236
- if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
5158
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.debug.LOG_PAYLOADS)) {
5237
5159
  try {
5238
5160
  const data = JSON.parse(JSON.stringify(jsonApiDoc));
5239
5161
  // eslint-disable-next-line no-console
5240
5162
  console.log('EmberData | Payload - push', data);
5241
- } catch (e) {
5163
+ } catch {
5242
5164
  // eslint-disable-next-line no-console
5243
5165
  console.log('EmberData | Payload - push', jsonApiDoc);
5244
5166
  }
@@ -5268,10 +5190,10 @@ class Store extends BaseClass {
5268
5190
  * @return {Promise<record>}
5269
5191
  */
5270
5192
  saveRecord(record, options = {}) {
5271
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5193
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5272
5194
  assertDestroyingStore(this, 'saveRecord');
5273
5195
  }
5274
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5196
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5275
5197
  if (!test) {
5276
5198
  throw new Error(`Unable to initiate save for a record in a disconnected state`);
5277
5199
  }
@@ -5283,7 +5205,7 @@ class Store extends BaseClass {
5283
5205
  // but just in case we reject here to prevent bad things.
5284
5206
  return Promise.reject(new Error(`Record Is Disconnected`));
5285
5207
  }
5286
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5208
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5287
5209
  if (!test) {
5288
5210
  throw new Error(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`);
5289
5211
  }
@@ -5340,7 +5262,7 @@ class Store extends BaseClass {
5340
5262
  } = this._instanceCache;
5341
5263
  if (!cache) {
5342
5264
  cache = this._instanceCache.cache = this.createCache(this._instanceCache._storeWrapper);
5343
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5265
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5344
5266
  cache = new CacheManager(cache);
5345
5267
  }
5346
5268
  }
@@ -5364,19 +5286,19 @@ class Store extends BaseClass {
5364
5286
  return new this(args);
5365
5287
  }
5366
5288
  }
5367
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
5289
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
5368
5290
  Store.prototype.getSchemaDefinitionService = function () {
5369
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5291
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5370
5292
  if (!test) {
5371
5293
  throw new Error(`You must registerSchemaDefinitionService with the store to use custom model classes`);
5372
5294
  }
5373
5295
  })(this._schema) : {};
5374
5296
  deprecate(`Use \`store.schema\` instead of \`store.getSchemaDefinitionService()\``, false, {
5375
5297
  id: 'ember-data-mirror:schema-service-updates',
5376
- until: '5.0',
5298
+ until: '6.0',
5377
5299
  for: 'ember-data-mirror',
5378
5300
  since: {
5379
- available: '5.4',
5301
+ available: '4.13',
5380
5302
  enabled: '5.4'
5381
5303
  }
5382
5304
  });
@@ -5385,10 +5307,10 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
5385
5307
  Store.prototype.registerSchemaDefinitionService = function (schema) {
5386
5308
  deprecate(`Use \`store.createSchemaService\` instead of \`store.registerSchemaDefinitionService()\``, false, {
5387
5309
  id: 'ember-data-mirror:schema-service-updates',
5388
- until: '5.0',
5310
+ until: '6.0',
5389
5311
  for: 'ember-data-mirror',
5390
5312
  since: {
5391
- available: '5.4',
5313
+ available: '4.13',
5392
5314
  enabled: '5.4'
5393
5315
  }
5394
5316
  });
@@ -5397,10 +5319,10 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
5397
5319
  Store.prototype.registerSchema = function (schema) {
5398
5320
  deprecate(`Use \`store.createSchemaService\` instead of \`store.registerSchema()\``, false, {
5399
5321
  id: 'ember-data-mirror:schema-service-updates',
5400
- until: '5.0',
5322
+ until: '6.0',
5401
5323
  for: 'ember-data-mirror',
5402
5324
  since: {
5403
- available: '5.4',
5325
+ available: '4.13',
5404
5326
  enabled: '5.4'
5405
5327
  }
5406
5328
  });
@@ -5409,10 +5331,10 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
5409
5331
  }
5410
5332
  let assertDestroyingStore;
5411
5333
  let assertDestroyedStoreOnly;
5412
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5334
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5413
5335
  // eslint-disable-next-line @typescript-eslint/no-shadow
5414
5336
  assertDestroyingStore = function assertDestroyingStore(store, method) {
5415
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5337
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5416
5338
  if (!test) {
5417
5339
  throw new Error(`Attempted to call store.${method}(), but the store instance has already been destroyed.`);
5418
5340
  }
@@ -5420,7 +5342,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5420
5342
  };
5421
5343
  // eslint-disable-next-line @typescript-eslint/no-shadow
5422
5344
  assertDestroyedStoreOnly = function assertDestroyedStoreOnly(store, method) {
5423
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5345
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5424
5346
  if (!test) {
5425
5347
  throw new Error(`Attempted to call store.${method}(), but the store instance has already been destroyed.`);
5426
5348
  }
@@ -5434,13 +5356,13 @@ function normalizeProperties(store, identifier, properties) {
5434
5356
  // assert here
5435
5357
  if (properties !== undefined) {
5436
5358
  if ('id' in properties) {
5437
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5359
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5438
5360
  if (!test) {
5439
5361
  throw new Error(`expected id to be a string or null`);
5440
5362
  }
5441
5363
  })(properties.id !== undefined) : {};
5442
5364
  }
5443
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5365
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5444
5366
  if (!test) {
5445
5367
  throw new Error(`You passed '${typeof properties}' as properties for record creation instead of an object.`);
5446
5368
  }
@@ -5460,7 +5382,7 @@ function normalizeProperties(store, identifier, properties) {
5460
5382
  const field = defs.get(prop);
5461
5383
  if (!field) continue;
5462
5384
  if (field.kind === 'hasMany') {
5463
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5385
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
5464
5386
  assertRecordsPassedToHasMany(properties[prop]);
5465
5387
  }
5466
5388
  properties[prop] = extractIdentifiersFromRecords(properties[prop]);
@@ -5473,12 +5395,12 @@ function normalizeProperties(store, identifier, properties) {
5473
5395
  return properties;
5474
5396
  }
5475
5397
  function assertRecordsPassedToHasMany(records) {
5476
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5398
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5477
5399
  if (!test) {
5478
5400
  throw new Error(`You must pass an array of records to set a hasMany relationship`);
5479
5401
  }
5480
5402
  })(Array.isArray(records)) : {};
5481
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5403
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5482
5404
  if (!test) {
5483
5405
  throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed ${records.map(r => `${typeof r}`).join(', ')}`);
5484
5406
  }
@@ -5608,7 +5530,7 @@ class Document {
5608
5530
  * @return Promise<Document>
5609
5531
  */
5610
5532
  fetch(options = {}) {
5611
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5533
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5612
5534
  if (!test) {
5613
5535
  throw new Error(`No self or related link`);
5614
5536
  }
@@ -5709,61 +5631,219 @@ defineSignal(Document.prototype, 'data');
5709
5631
  defineSignal(Document.prototype, 'links');
5710
5632
  defineSignal(Document.prototype, 'errors');
5711
5633
  defineSignal(Document.prototype, 'meta');
5634
+ const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);
5635
+ function calcShouldFetch(store, request, hasCachedValue, identifier) {
5636
+ const {
5637
+ cacheOptions
5638
+ } = request;
5639
+ return request.op && MUTATION_OPS.has(request.op) || cacheOptions?.reload || !hasCachedValue || (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier, store) : false);
5640
+ }
5641
+ function calcShouldBackgroundFetch(store, request, willFetch, identifier) {
5642
+ const {
5643
+ cacheOptions
5644
+ } = request;
5645
+ return cacheOptions?.backgroundReload || (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier, store) : false);
5646
+ }
5647
+ function isMutation(request) {
5648
+ return Boolean(request.op && MUTATION_OPS.has(request.op));
5649
+ }
5650
+ function copyDocumentProperties(target, source) {
5651
+ if ('links' in source) {
5652
+ target.links = source.links;
5653
+ }
5654
+ if ('meta' in source) {
5655
+ target.meta = source.meta;
5656
+ }
5657
+ if ('errors' in source) {
5658
+ target.errors = source.errors;
5659
+ }
5660
+ }
5661
+ function isCacheAffecting(document) {
5662
+ if (!isMutation(document.request)) {
5663
+ return true;
5664
+ }
5665
+ // a mutation combined with a 204 has no cache impact when no known records were involved
5666
+ // a createRecord with a 201 with an empty response and no known records should similarly
5667
+ // have no cache impact
5668
+
5669
+ if (document.request.op === 'createRecord' && document.response?.status === 201) {
5670
+ return document.content ? Object.keys(document.content).length > 0 : false;
5671
+ }
5672
+ return document.response?.status !== 204;
5673
+ }
5674
+ function isAggregateError(error) {
5675
+ return error instanceof AggregateError || error.name === 'AggregateError' && Array.isArray(error.errors);
5676
+ }
5677
+ // TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
5678
+ function cloneError(error) {
5679
+ const isAggregate = isAggregateError(error);
5680
+ const cloned = isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message);
5681
+ cloned.stack = error.stack;
5682
+ cloned.error = error.error;
5683
+
5684
+ // copy over enumerable properties
5685
+ Object.assign(cloned, error);
5686
+ return cloned;
5687
+ }
5688
+ function isErrorDocument(document) {
5689
+ return 'errors' in document;
5690
+ }
5691
+ function getPriority(identifier, deduped, priority) {
5692
+ if (identifier) {
5693
+ const existing = deduped.get(identifier);
5694
+ if (existing) {
5695
+ return existing.priority;
5696
+ }
5697
+ }
5698
+ return priority;
5699
+ }
5712
5700
 
5713
5701
  /**
5714
5702
  * @module @ember-data-mirror/store
5715
5703
  */
5716
5704
 
5717
5705
  /**
5718
- * A service which an application may provide to the store via
5719
- * the store's `lifetimes` property to configure the behavior
5720
- * of the CacheHandler.
5706
+ * A CacheHandler that adds support for using an EmberData Cache with a RequestManager.
5721
5707
  *
5722
- * The default behavior for request lifetimes is to never expire
5723
- * unless manually refreshed via `cacheOptions.reload` or `cacheOptions.backgroundReload`.
5708
+ * This handler will only run when a request has supplied a `store` instance. Requests
5709
+ * issued by the store via `store.request()` will automatically have the `store` instance
5710
+ * attached to the request.
5724
5711
  *
5725
- * Implementing this service allows you to programatically define
5726
- * when a request should be considered expired.
5712
+ * ```ts
5713
+ * requestManager.request({
5714
+ * store: store,
5715
+ * url: '/api/posts',
5716
+ * method: 'GET'
5717
+ * });
5718
+ * ```
5727
5719
  *
5728
- * @class <Interface> CachePolicy
5729
- * @public
5720
+ * When this handler elects to handle a request, it will return the raw `StructuredDocument`
5721
+ * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
5722
+ * return a `Document` instance that will automatically update the UI when the cache is updated
5723
+ * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
5724
+ *
5725
+ * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
5726
+ * means that if desired you can issue requests that utilize the cache without needing to also
5727
+ * utilize Record instances if desired.
5728
+ *
5729
+ * Said differently, you could elect to issue all requests via a RequestManager, without ever using
5730
+ * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
5731
+ * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
5732
+ * approach of EmberData allows for this flexibility.
5733
+ *
5734
+ * ```ts
5735
+ * import { EnableHydration } from '@warp-drive-mirror/core-types/request';
5736
+ *
5737
+ * requestManager.request({
5738
+ * store: store,
5739
+ * url: '/api/posts',
5740
+ * method: 'GET',
5741
+ * [EnableHydration]: true
5742
+ * });
5743
+ *
5744
+ * @typedoc
5730
5745
  */
5731
- const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);
5732
- function isErrorDocument(document) {
5733
- return 'errors' in document;
5734
- }
5746
+ const CacheHandler = {
5747
+ request(context, next) {
5748
+ // if we have no cache or no cache-key skip cache handling
5749
+ if (!context.request.store || context.request.cacheOptions?.[SkipCache]) {
5750
+ return next(context.request);
5751
+ }
5752
+ const {
5753
+ store
5754
+ } = context.request;
5755
+ const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);
5756
+ if (identifier) {
5757
+ context.setIdentifier(identifier);
5758
+ }
5759
+
5760
+ // used to dedupe existing requests that match
5761
+ const DEDUPE = store.requestManager._deduped;
5762
+ const activeRequest = identifier && DEDUPE.get(identifier);
5763
+ const peeked = identifier ? store.cache.peekRequest(identifier) : null;
5764
+
5765
+ // determine if we should skip cache
5766
+ if (calcShouldFetch(store, context.request, !!peeked, identifier)) {
5767
+ if (activeRequest) {
5768
+ activeRequest.priority = {
5769
+ blocking: true
5770
+ };
5771
+ return activeRequest.promise;
5772
+ }
5773
+ let promise = fetchContentAndHydrate(next, context, identifier, {
5774
+ blocking: true
5775
+ });
5776
+ if (identifier) {
5777
+ promise = promise.finally(() => {
5778
+ DEDUPE.delete(identifier);
5779
+ store.notifications.notify(identifier, 'state');
5780
+ });
5781
+ DEDUPE.set(identifier, {
5782
+ priority: {
5783
+ blocking: true
5784
+ },
5785
+ promise
5786
+ });
5787
+ store.notifications.notify(identifier, 'state');
5788
+ }
5789
+ return promise;
5790
+ }
5791
+
5792
+ // if we have not skipped cache, determine if we should update behind the scenes
5793
+ if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {
5794
+ let promise = activeRequest?.promise || fetchContentAndHydrate(next, context, identifier, {
5795
+ blocking: false
5796
+ });
5797
+ if (identifier && !activeRequest) {
5798
+ promise = promise.finally(() => {
5799
+ DEDUPE.delete(identifier);
5800
+ store.notifications.notify(identifier, 'state');
5801
+ });
5802
+ DEDUPE.set(identifier, {
5803
+ priority: {
5804
+ blocking: false
5805
+ },
5806
+ promise
5807
+ });
5808
+ store.notifications.notify(identifier, 'state');
5809
+ }
5810
+ store.requestManager._pending.set(context.id, promise);
5811
+ }
5812
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5813
+ if (!test) {
5814
+ throw new Error(`Expected a peeked request to be present`);
5815
+ }
5816
+ })(peeked) : {};
5817
+ const shouldHydrate = context.request[EnableHydration] || false;
5818
+ context.setResponse(peeked.response);
5819
+ if ('error' in peeked) {
5820
+ const content = shouldHydrate ? maybeUpdateErrorUiObjects(store, {
5821
+ shouldHydrate,
5822
+ identifier
5823
+ }, peeked.content, true) : peeked.content;
5824
+ const newError = cloneError(peeked);
5825
+ newError.content = content;
5826
+ throw newError;
5827
+ }
5828
+ const result = shouldHydrate ? maybeUpdateUiObjects(store, context.request, {
5829
+ shouldHydrate,
5830
+ identifier
5831
+ }, peeked.content, true) : peeked.content;
5832
+ return result;
5833
+ }
5834
+ };
5735
5835
  function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
5736
5836
  const {
5737
5837
  identifier
5738
5838
  } = options;
5739
5839
  if (!document) {
5740
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5840
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5741
5841
  if (!test) {
5742
5842
  throw new Error(`The CacheHandler expected response content but none was found`);
5743
5843
  }
5744
5844
  })(!options.shouldHydrate) : {};
5745
5845
  return document;
5746
5846
  }
5747
- if (isErrorDocument(document)) {
5748
- if (!identifier && !options.shouldHydrate) {
5749
- return document;
5750
- }
5751
- let doc;
5752
- if (identifier) {
5753
- doc = store._documentCache.get(identifier);
5754
- }
5755
- if (!doc) {
5756
- doc = new Document(store, identifier);
5757
- copyDocumentProperties(doc, document);
5758
- if (identifier) {
5759
- store._documentCache.set(identifier, doc);
5760
- }
5761
- } else if (!isFromCache) {
5762
- doc.data = undefined;
5763
- copyDocumentProperties(doc, document);
5764
- }
5765
- return options.shouldHydrate ? doc : document;
5766
- }
5767
5847
  if (Array.isArray(document.data)) {
5768
5848
  const {
5769
5849
  recordArrayManager
@@ -5831,32 +5911,125 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
5831
5911
  return options.shouldHydrate ? doc : document;
5832
5912
  }
5833
5913
  }
5834
- function calcShouldFetch(store, request, hasCachedValue, identifier) {
5914
+ function maybeUpdateErrorUiObjects(store, options, document, isFromCache) {
5835
5915
  const {
5836
- cacheOptions
5837
- } = request;
5838
- return request.op && MUTATION_OPS.has(request.op) || cacheOptions?.reload || !hasCachedValue || (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier, store) : false);
5916
+ identifier
5917
+ } = options;
5918
+
5919
+ // TODO investigate why ResourceErrorDocument is insufficient for expressing all error types
5920
+ if (!isErrorDocument(document) || !identifier && !options.shouldHydrate) {
5921
+ return document;
5922
+ }
5923
+ let doc;
5924
+ if (identifier) {
5925
+ doc = store._documentCache.get(identifier);
5926
+ }
5927
+ if (!doc) {
5928
+ doc = new Document(store, identifier);
5929
+ copyDocumentProperties(doc, document);
5930
+ if (identifier) {
5931
+ store._documentCache.set(identifier, doc);
5932
+ }
5933
+ } else if (!isFromCache) {
5934
+ doc.data = undefined;
5935
+ copyDocumentProperties(doc, document);
5936
+ }
5937
+ return options.shouldHydrate ? doc : document;
5839
5938
  }
5840
- function calcShouldBackgroundFetch(store, request, willFetch, identifier) {
5939
+ function updateCacheForSuccess(store, request, options, document) {
5940
+ let response = null;
5941
+ if (isMutation(request)) {
5942
+ const record = request.data?.record || request.records?.[0];
5943
+ if (record) {
5944
+ response = store.cache.didCommit(record, document);
5945
+
5946
+ // a mutation combined with a 204 has no cache impact when no known records were involved
5947
+ // a createRecord with a 201 with an empty response and no known records should similarly
5948
+ // have no cache impact
5949
+ } else if (isCacheAffecting(document)) {
5950
+ response = store.cache.put(document);
5951
+ }
5952
+ } else {
5953
+ response = store.cache.put(document);
5954
+ }
5955
+ return maybeUpdateUiObjects(store, request, options, response, false);
5956
+ }
5957
+ function handleFetchSuccess(store, context, options, document) {
5841
5958
  const {
5842
- cacheOptions
5843
- } = request;
5844
- return cacheOptions?.backgroundReload || (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier, store) : false);
5959
+ request
5960
+ } = context;
5961
+ store.requestManager._pending.delete(context.id);
5962
+ store._enableAsyncFlush = true;
5963
+ let response;
5964
+ store._join(() => {
5965
+ response = updateCacheForSuccess(store, request, options, document);
5966
+ });
5967
+ store._enableAsyncFlush = null;
5968
+ if (store.lifetimes?.didRequest) {
5969
+ store.lifetimes.didRequest(context.request, document.response, options.identifier, store);
5970
+ }
5971
+ const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);
5972
+ if (finalPriority.blocking) {
5973
+ return response;
5974
+ } else {
5975
+ store.notifications._flush();
5976
+ }
5845
5977
  }
5846
- function isMutation(request) {
5847
- return Boolean(request.op && MUTATION_OPS.has(request.op));
5978
+ function updateCacheForError(store, context, options, error) {
5979
+ let response;
5980
+ if (isMutation(context.request)) {
5981
+ // TODO similar to didCommit we should spec this to be similar to cache.put for handling full response
5982
+ // currently we let the response remain undefiend.
5983
+ const errors = error && error.content && typeof error.content === 'object' && 'errors' in error.content && Array.isArray(error.content.errors) ? error.content.errors : undefined;
5984
+ const record = context.request.data?.record || context.request.records?.[0];
5985
+ store.cache.commitWasRejected(record, errors);
5986
+ } else {
5987
+ response = store.cache.put(error);
5988
+ return maybeUpdateErrorUiObjects(store, options, response, false);
5989
+ }
5848
5990
  }
5849
- function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBackgroundFetch) {
5991
+ function handleFetchError(store, context, options, error) {
5992
+ store.requestManager._pending.delete(context.id);
5993
+ if (context.request.signal?.aborted) {
5994
+ throw error;
5995
+ }
5996
+ store._enableAsyncFlush = true;
5997
+ let response;
5998
+ store._join(() => {
5999
+ response = updateCacheForError(store, context, options, error);
6000
+ });
6001
+ store._enableAsyncFlush = null;
6002
+ if (options.identifier && store.lifetimes?.didRequest) {
6003
+ store.lifetimes.didRequest(context.request, error.response, options.identifier, store);
6004
+ }
6005
+ if (isMutation(context.request)) {
6006
+ throw error;
6007
+ }
6008
+ const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);
6009
+ if (finalPriority.blocking) {
6010
+ const newError = cloneError(error);
6011
+ newError.content = response;
6012
+ throw newError;
6013
+ } else {
6014
+ store.notifications._flush();
6015
+ }
6016
+ }
6017
+ function fetchContentAndHydrate(next, context, identifier, priority) {
5850
6018
  const {
5851
6019
  store
5852
6020
  } = context.request;
5853
6021
  const shouldHydrate = context.request[EnableHydration] || false;
6022
+ const options = {
6023
+ shouldHydrate,
6024
+ identifier,
6025
+ priority
6026
+ };
5854
6027
  let isMut = false;
5855
6028
  if (isMutation(context.request)) {
5856
6029
  isMut = true;
5857
6030
  // TODO should we handle multiple records in request.records by iteratively calling willCommit for each
5858
6031
  const record = context.request.data?.record || context.request.records?.[0];
5859
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
6032
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5860
6033
  if (!test) {
5861
6034
  throw new Error(`Expected to receive a list of records included in the ${context.request.op} request`);
5862
6035
  }
@@ -5869,83 +6042,14 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
5869
6042
  store.lifetimes.willRequest(context.request, identifier, store);
5870
6043
  }
5871
6044
  const promise = next(context.request).then(document => {
5872
- store.requestManager._pending.delete(context.id);
5873
- store._enableAsyncFlush = true;
5874
- let response;
5875
- store._join(() => {
5876
- if (isMutation(context.request)) {
5877
- const record = context.request.data?.record || context.request.records?.[0];
5878
- if (record) {
5879
- response = store.cache.didCommit(record, document);
5880
-
5881
- // a mutation combined with a 204 has no cache impact when no known records were involved
5882
- // a createRecord with a 201 with an empty response and no known records should similarly
5883
- // have no cache impact
5884
- } else if (isCacheAffecting(document)) {
5885
- response = store.cache.put(document);
5886
- }
5887
- } else {
5888
- response = store.cache.put(document);
5889
- }
5890
- response = maybeUpdateUiObjects(store, context.request, {
5891
- shouldHydrate,
5892
- shouldFetch,
5893
- shouldBackgroundFetch,
5894
- identifier
5895
- }, response, false);
5896
- });
5897
- store._enableAsyncFlush = null;
5898
- if (store.lifetimes?.didRequest) {
5899
- store.lifetimes.didRequest(context.request, document.response, identifier, store);
5900
- }
5901
- if (shouldFetch) {
5902
- return response;
5903
- } else if (shouldBackgroundFetch) {
5904
- store.notifications._flush();
5905
- }
6045
+ return handleFetchSuccess(store, context, options, document);
5906
6046
  }, error => {
5907
- store.requestManager._pending.delete(context.id);
5908
- if (context.request.signal?.aborted) {
5909
- throw error;
5910
- }
5911
- store.requestManager._pending.delete(context.id);
5912
- store._enableAsyncFlush = true;
5913
- let response;
5914
- store._join(() => {
5915
- if (isMutation(context.request)) {
5916
- // TODO similar to didCommit we should spec this to be similar to cache.put for handling full response
5917
- // currently we let the response remain undefiend.
5918
- const errors = error && error.content && typeof error.content === 'object' && 'errors' in error.content && Array.isArray(error.content.errors) ? error.content.errors : undefined;
5919
- const record = context.request.data?.record || context.request.records?.[0];
5920
- store.cache.commitWasRejected(record, errors);
5921
- // re-throw the original error to preserve `errors` property.
5922
- throw error;
5923
- } else {
5924
- response = store.cache.put(error);
5925
- response = maybeUpdateUiObjects(store, context.request, {
5926
- shouldHydrate,
5927
- shouldFetch,
5928
- shouldBackgroundFetch,
5929
- identifier
5930
- }, response, false);
5931
- }
5932
- });
5933
- store._enableAsyncFlush = null;
5934
- if (identifier && store.lifetimes?.didRequest) {
5935
- store.lifetimes.didRequest(context.request, error.response, identifier, store);
5936
- }
5937
- if (!shouldBackgroundFetch) {
5938
- const newError = cloneError(error);
5939
- newError.content = response;
5940
- throw newError;
5941
- } else {
5942
- store.notifications._flush();
5943
- }
6047
+ return handleFetchError(store, context, options, error);
5944
6048
  });
5945
6049
  if (!isMut) {
5946
6050
  return promise;
5947
6051
  }
5948
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
6052
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
5949
6053
  if (!test) {
5950
6054
  throw new Error(`Expected a mutation`);
5951
6055
  }
@@ -5962,129 +6066,4 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
5962
6066
  }]
5963
6067
  });
5964
6068
  }
5965
- function isAggregateError(error) {
5966
- return error instanceof AggregateError || error.name === 'AggregateError' && Array.isArray(error.errors);
5967
- }
5968
- // TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
5969
- function cloneError(error) {
5970
- const isAggregate = isAggregateError(error);
5971
- const cloned = isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message);
5972
- cloned.stack = error.stack;
5973
- cloned.error = error.error;
5974
-
5975
- // copy over enumerable properties
5976
- Object.assign(cloned, error);
5977
- return cloned;
5978
- }
5979
-
5980
- /**
5981
- * A CacheHandler that adds support for using an EmberData Cache with a RequestManager.
5982
- *
5983
- * This handler will only run when a request has supplied a `store` instance. Requests
5984
- * issued by the store via `store.request()` will automatically have the `store` instance
5985
- * attached to the request.
5986
- *
5987
- * ```ts
5988
- * requestManager.request({
5989
- * store: store,
5990
- * url: '/api/posts',
5991
- * method: 'GET'
5992
- * });
5993
- * ```
5994
- *
5995
- * When this handler elects to handle a request, it will return the raw `StructuredDocument`
5996
- * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
5997
- * return a `Document` instance that will automatically update the UI when the cache is updated
5998
- * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
5999
- *
6000
- * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
6001
- * means that if desired you can issue requests that utilize the cache without needing to also
6002
- * utilize Record instances if desired.
6003
- *
6004
- * Said differently, you could elect to issue all requests via a RequestManager, without ever using
6005
- * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
6006
- * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
6007
- * approach of EmberData allows for this flexibility.
6008
- *
6009
- * ```ts
6010
- * import { EnableHydration } from '@warp-drive/core-types/request';
6011
- *
6012
- * requestManager.request({
6013
- * store: store,
6014
- * url: '/api/posts',
6015
- * method: 'GET',
6016
- * [EnableHydration]: true
6017
- * });
6018
- *
6019
- * @typedoc
6020
- */
6021
- const CacheHandler = {
6022
- request(context, next) {
6023
- // if we have no cache or no cache-key skip cache handling
6024
- if (!context.request.store || context.request.cacheOptions?.[SkipCache]) {
6025
- return next(context.request);
6026
- }
6027
- const {
6028
- store
6029
- } = context.request;
6030
- const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);
6031
- const peeked = identifier ? store.cache.peekRequest(identifier) : null;
6032
-
6033
- // determine if we should skip cache
6034
- if (calcShouldFetch(store, context.request, !!peeked, identifier)) {
6035
- return fetchContentAndHydrate(next, context, identifier, true, false);
6036
- }
6037
-
6038
- // if we have not skipped cache, determine if we should update behind the scenes
6039
- if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {
6040
- const promise = fetchContentAndHydrate(next, context, identifier, false, true);
6041
- store.requestManager._pending.set(context.id, promise);
6042
- }
6043
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
6044
- if (!test) {
6045
- throw new Error(`Expected a peeked request to be present`);
6046
- }
6047
- })(peeked) : {};
6048
- const shouldHydrate = context.request[EnableHydration] || false;
6049
- context.setResponse(peeked.response);
6050
- if ('error' in peeked) {
6051
- const content = shouldHydrate ? maybeUpdateUiObjects(store, context.request, {
6052
- shouldHydrate,
6053
- identifier
6054
- }, peeked.content, true) : peeked.content;
6055
- const newError = cloneError(peeked);
6056
- newError.content = content;
6057
- throw newError;
6058
- }
6059
- const result = shouldHydrate ? maybeUpdateUiObjects(store, context.request, {
6060
- shouldHydrate,
6061
- identifier
6062
- }, peeked.content, true) : peeked.content;
6063
- return result;
6064
- }
6065
- };
6066
- function copyDocumentProperties(target, source) {
6067
- if ('links' in source) {
6068
- target.links = source.links;
6069
- }
6070
- if ('meta' in source) {
6071
- target.meta = source.meta;
6072
- }
6073
- if ('errors' in source) {
6074
- target.errors = source.errors;
6075
- }
6076
- }
6077
- function isCacheAffecting(document) {
6078
- if (!isMutation(document.request)) {
6079
- return true;
6080
- }
6081
- // a mutation combined with a 204 has no cache impact when no known records were involved
6082
- // a createRecord with a 201 with an empty response and no known records should similarly
6083
- // have no cache impact
6084
-
6085
- if (document.request.op === 'createRecord' && document.response?.status === 201) {
6086
- return document.content ? Object.keys(document.content).length > 0 : false;
6087
- }
6088
- return document.response?.status !== 204;
6089
- }
6090
6069
  export { ARRAY_SIGNAL as A, CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, constructResource as f, coerceId as g, ensureStringId as h, isStableIdentifier as i, Collection as j, SOURCE as k, fastPush as l, removeRecordDataFor as m, notifyArray as n, setRecordIdentifier as o, peekCache as p, StoreMap as q, recordIdentifierFor as r, storeFor as s, setCacheFor as t, normalizeModelName as u };