@ember-data/model 5.4.0-alpha.64 → 5.4.0-alpha.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/addon-main.cjs +5 -0
  2. package/blueprints/model/index.js +18 -5
  3. package/blueprints/model-test/index.js +16 -10
  4. package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +4 -5
  5. package/{addon → dist}/-private.js +2 -2
  6. package/{addon/has-many-BuTJfT5a.js → dist/has-many-CR10J-rp.js} +49 -26
  7. package/dist/has-many-CR10J-rp.js.map +1 -0
  8. package/dist/hooks-BNw6VdLr.js +75 -0
  9. package/dist/hooks-BNw6VdLr.js.map +1 -0
  10. package/dist/hooks.js +2 -0
  11. package/{addon → dist}/hooks.js.map +1 -1
  12. package/dist/index.js +4 -0
  13. package/{addon → dist}/index.js.map +1 -1
  14. package/dist/migration-support.js +211 -0
  15. package/dist/migration-support.js.map +1 -0
  16. package/{addon/model-DJ9C4aZ-.js → dist/model-CsbDNxap.js} +821 -250
  17. package/dist/model-CsbDNxap.js.map +1 -0
  18. package/dist/schema-provider-C5vR7TBr.js +256 -0
  19. package/dist/schema-provider-C5vR7TBr.js.map +1 -0
  20. package/package.json +39 -59
  21. package/unstable-preview-types/-private/attr.d.ts.map +1 -1
  22. package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -1
  23. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +2 -2
  24. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -1
  25. package/unstable-preview-types/-private/errors.d.ts +2 -5
  26. package/unstable-preview-types/-private/errors.d.ts.map +1 -1
  27. package/unstable-preview-types/-private/has-many.d.ts.map +1 -1
  28. package/unstable-preview-types/-private/hooks.d.ts.map +1 -1
  29. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +16 -20
  30. package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -1
  31. package/unstable-preview-types/-private/many-array.d.ts +11 -13
  32. package/unstable-preview-types/-private/many-array.d.ts.map +1 -1
  33. package/unstable-preview-types/-private/model-methods.d.ts +6 -5
  34. package/unstable-preview-types/-private/model-methods.d.ts.map +1 -1
  35. package/unstable-preview-types/-private/model.d.ts +38 -35
  36. package/unstable-preview-types/-private/model.d.ts.map +1 -1
  37. package/unstable-preview-types/-private/notify-changes.d.ts +1 -1
  38. package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -1
  39. package/unstable-preview-types/-private/promise-belongs-to.d.ts +1 -2
  40. package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -1
  41. package/unstable-preview-types/-private/promise-many-array.d.ts +4 -4
  42. package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -1
  43. package/unstable-preview-types/-private/record-state.d.ts +3 -4
  44. package/unstable-preview-types/-private/record-state.d.ts.map +1 -1
  45. package/unstable-preview-types/-private/references/belongs-to.d.ts +4 -4
  46. package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -1
  47. package/unstable-preview-types/-private/references/has-many.d.ts +7 -7
  48. package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -1
  49. package/unstable-preview-types/-private/schema-provider.d.ts +46 -15
  50. package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -1
  51. package/unstable-preview-types/-private/type-utils.d.ts +64 -0
  52. package/unstable-preview-types/-private/type-utils.d.ts.map +1 -0
  53. package/unstable-preview-types/-private.d.ts +4 -3
  54. package/unstable-preview-types/-private.d.ts.map +1 -1
  55. package/unstable-preview-types/index.d.ts +20 -20
  56. package/unstable-preview-types/index.d.ts.map +1 -1
  57. package/unstable-preview-types/migration-support.d.ts +45 -6
  58. package/unstable-preview-types/migration-support.d.ts.map +1 -1
  59. package/addon/has-many-BuTJfT5a.js.map +0 -1
  60. package/addon/hooks-BMoEt0SI.js +0 -176
  61. package/addon/hooks-BMoEt0SI.js.map +0 -1
  62. package/addon/hooks.js +0 -1
  63. package/addon/index.js +0 -3
  64. package/addon/migration-support.js +0 -118
  65. package/addon/migration-support.js.map +0 -1
  66. package/addon/model-DJ9C4aZ-.js.map +0 -1
  67. package/addon/util-CSYkrwfb.js +0 -35
  68. package/addon/util-CSYkrwfb.js.map +0 -1
  69. package/addon-main.js +0 -94
  70. package/unstable-preview-types/-private/promise-proxy-base.d.ts +0 -35
  71. /package/{addon → dist}/-private.js.map +0 -0
@@ -1,18 +1,51 @@
1
- import { assert, deprecate } from '@ember/debug';
1
+ import { deprecate } from '@ember/debug';
2
+ import { dasherize } from '@ember/string';
3
+ import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
2
4
  import EmberObject, { computed, get } from '@ember/object';
3
5
  import { recordIdentifierFor as recordIdentifierFor$1, storeFor as storeFor$1 } from '@ember-data/store';
4
- import { RecordArray, MUTATE, SOURCE, recordIdentifierFor, ARRAY_SIGNAL, notifyArray, isStableIdentifier, storeFor, peekCache, fastPush, coerceId } from '@ember-data/store/-private';
6
+ import { LiveArray, MUTATE, SOURCE, recordIdentifierFor, ARRAY_SIGNAL, notifyArray, isStableIdentifier, storeFor, peekCache, fastPush, coerceId } from '@ember-data/store/-private';
5
7
  import { cached, compat } from '@ember-data/tracking';
6
- import { addToTransaction, defineSignal, getSignal, subscribe, peekSignal } from '@ember-data/tracking/-private';
8
+ import { addToTransaction, defineSignal, peekSignal, getSignal, subscribe } from '@ember-data/tracking/-private';
7
9
  import { RecordStore } from '@warp-drive/core-types/symbols';
8
10
  import { A } from '@ember/array';
9
11
  import ArrayProxy from '@ember/array/proxy';
10
12
  import { mapBy, not } from '@ember/object/computed';
11
- import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
12
13
  import { upgradeStore } from '@ember-data/legacy-compat/-private';
14
+ import { getOrSetGlobal } from '@warp-drive/core-types/-private';
13
15
  import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
14
16
  import ObjectProxy from '@ember/object/proxy';
15
17
  import { cacheFor } from '@ember/object/internals';
18
+ function isElementDescriptor(args) {
19
+ const [maybeTarget, maybeKey, maybeDesc] = args;
20
+ return (
21
+ // Ensure we have the right number of args
22
+ args.length === 3 && (
23
+ // Make sure the target is a class or object (prototype)
24
+ typeof maybeTarget === 'function' || typeof maybeTarget === 'object' && maybeTarget !== null) &&
25
+ // Make sure the key is a string
26
+ typeof maybeKey === 'string' && (
27
+ // Make sure the descriptor is the right shape
28
+ typeof maybeDesc === 'object' && maybeDesc !== null && 'enumerable' in maybeDesc && 'configurable' in maybeDesc ||
29
+ // TS compatibility
30
+ maybeDesc === undefined)
31
+ );
32
+ }
33
+ function normalizeModelName(type) {
34
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
35
+ const result = dasherize(type);
36
+ deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
37
+ id: 'ember-data:deprecate-non-strict-types',
38
+ until: '6.0',
39
+ for: 'ember-data',
40
+ since: {
41
+ available: '5.3',
42
+ enabled: '5.3'
43
+ }
44
+ });
45
+ return result;
46
+ }
47
+ return type;
48
+ }
16
49
 
17
50
  /**
18
51
  @module @ember-data/store
@@ -60,7 +93,7 @@ import { cacheFor } from '@ember/object/internals';
60
93
  @class ManyArray
61
94
  @public
62
95
  */
63
- class RelatedCollection extends RecordArray {
96
+ class RelatedCollection extends LiveArray {
64
97
  /**
65
98
  The loading state of this array
66
99
  @property {Boolean} isLoaded
@@ -110,8 +143,6 @@ class RelatedCollection extends RecordArray {
110
143
  @public
111
144
  */
112
145
 
113
- // @ts-expect-error
114
-
115
146
  constructor(options) {
116
147
  super(options);
117
148
  this.isLoaded = options.isLoaded || false;
@@ -143,7 +174,7 @@ class RelatedCollection extends RecordArray {
143
174
  {
144
175
  const newValues = extractIdentifiersFromRecords(args);
145
176
  assertNoDuplicates(this, target, currentState => currentState.push(...newValues), `Cannot push duplicates to a hasMany's state.`);
146
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
177
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
147
178
  // dedupe
148
179
  const seen = new Set(target);
149
180
  const unique = new Set();
@@ -187,7 +218,7 @@ class RelatedCollection extends RecordArray {
187
218
  {
188
219
  const newValues = extractIdentifiersFromRecords(args);
189
220
  assertNoDuplicates(this, target, currentState => currentState.unshift(...newValues), `Cannot unshift duplicates to a hasMany's state.`);
190
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
221
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
191
222
  // dedupe
192
223
  const seen = new Set(target);
193
224
  const unique = new Set();
@@ -244,7 +275,7 @@ class RelatedCollection extends RecordArray {
244
275
  if (start === 0 && deleteCount === this[SOURCE].length) {
245
276
  const newValues = extractIdentifiersFromRecords(adds);
246
277
  assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot replace a hasMany's state with a new state that contains duplicates.`);
247
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
278
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
248
279
  // dedupe
249
280
  const current = new Set(adds);
250
281
  const unique = Array.from(current);
@@ -261,7 +292,7 @@ class RelatedCollection extends RecordArray {
261
292
  }
262
293
  const newValues = extractIdentifiersFromRecords(adds);
263
294
  assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot splice a hasMany's state with a new state that contains duplicates.`);
264
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
295
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
265
296
  // dedupe
266
297
  const currentState = target.slice();
267
298
  currentState.splice(start, deleteCount);
@@ -308,13 +339,16 @@ class RelatedCollection extends RecordArray {
308
339
  return result;
309
340
  }
310
341
  default:
311
- assert(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
342
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
343
+ {
344
+ throw new Error(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
345
+ }
346
+ })() : {};
312
347
  }
313
348
  }
314
349
  notify() {
315
350
  const signal = this[ARRAY_SIGNAL];
316
351
  signal.shouldReset = true;
317
- // @ts-expect-error
318
352
  notifyArray(this);
319
353
  }
320
354
 
@@ -367,7 +401,11 @@ class RelatedCollection extends RecordArray {
367
401
  const {
368
402
  store
369
403
  } = this;
370
- assert(`Expected modelName to be set`, this.modelName);
404
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
405
+ if (!test) {
406
+ throw new Error(`Expected modelName to be set`);
407
+ }
408
+ })(this.modelName) : {};
371
409
  const record = store.createRecord(this.modelName, hash);
372
410
  this.push(record);
373
411
  return record;
@@ -384,14 +422,18 @@ RelatedCollection.prototype._inverseIsAsync = false;
384
422
  RelatedCollection.prototype.key = '';
385
423
  RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
386
424
  function assertRecordPassedToHasMany(record) {
387
- assert(`All elements of a hasMany relationship must be instances of Model, you passed $${typeof record}`, function () {
425
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
426
+ if (!test) {
427
+ throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed $${typeof record}`);
428
+ }
429
+ })(function () {
388
430
  try {
389
431
  recordIdentifierFor(record);
390
432
  return true;
391
433
  } catch {
392
434
  return false;
393
435
  }
394
- }());
436
+ }()) : {};
395
437
  }
396
438
  function extractIdentifiersFromRecords(records) {
397
439
  return records.map(extractIdentifierFromRecord$1);
@@ -405,7 +447,7 @@ function assertNoDuplicates(collection, target, callback, reason) {
405
447
  callback(state);
406
448
  if (state.length !== new Set(state).size) {
407
449
  const duplicates = state.filter((currentValue, currentIndex) => state.indexOf(currentValue) !== currentIndex);
408
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
450
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
409
451
  deprecate(`${reason} This behavior is deprecated. Found duplicates for the following records within the new state provided to \`<${collection.identifier.type}:${collection.identifier.id || collection.identifier.lid}>.${collection.key}\`\n\t- ${Array.from(new Set(duplicates)).map(r => isStableIdentifier(r) ? r.lid : recordIdentifierFor(r).lid).sort((a, b) => a.localeCompare(b)).join('\n\t- ')}`, false, {
410
452
  id: 'ember-data:deprecate-many-array-duplicates',
411
453
  for: 'ember-data',
@@ -464,34 +506,129 @@ function mutate(collection, mutation, _SIGNAL) {
464
506
  collection._manager.mutate(mutation);
465
507
  addToTransaction(_SIGNAL);
466
508
  }
467
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
468
- var desc = {};
469
- Object.keys(descriptor).forEach(function (key) {
470
- desc[key] = descriptor[key];
509
+ const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
510
+ var __defProp = Object.defineProperty;
511
+ var __export = (target, all) => {
512
+ for (var name in all) __defProp(target, name, {
513
+ get: all[name],
514
+ enumerable: true
471
515
  });
472
- desc.enumerable = !!desc.enumerable;
473
- desc.configurable = !!desc.configurable;
474
- if ('value' in desc || desc.initializer) {
475
- desc.writable = true;
476
- }
477
- desc = decorators.slice().reverse().reduce(function (desc, decorator) {
478
- return decorator(target, property, desc) || desc;
479
- }, desc);
480
- if (context && desc.initializer !== void 0) {
481
- desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
482
- desc.initializer = undefined;
516
+ };
517
+
518
+ // src/runtime.ts
519
+ var runtime_exports = {};
520
+ __export(runtime_exports, {
521
+ c: () => decorateClass,
522
+ f: () => decorateFieldV1,
523
+ g: () => decorateFieldV2,
524
+ i: () => initializeDeferredDecorator,
525
+ m: () => decorateMethodV1,
526
+ n: () => decorateMethodV2,
527
+ p: () => decoratePOJO
528
+ });
529
+ var deferred = /* @__PURE__ */new WeakMap();
530
+ function deferDecorator(proto, prop, desc) {
531
+ let map = deferred.get(proto);
532
+ if (!map) {
533
+ map = /* @__PURE__ */new Map();
534
+ deferred.set(proto, map);
535
+ }
536
+ map.set(prop, desc);
537
+ }
538
+ function findDeferredDecorator(target, prop) {
539
+ let cursor = target.prototype;
540
+ while (cursor) {
541
+ let desc = deferred.get(cursor)?.get(prop);
542
+ if (desc) {
543
+ return desc;
544
+ }
545
+ cursor = cursor.prototype;
546
+ }
547
+ }
548
+ function decorateFieldV1(target, prop, decorators, initializer) {
549
+ return decorateFieldV2(target.prototype, prop, decorators, initializer);
550
+ }
551
+ function decorateFieldV2(prototype, prop, decorators, initializer) {
552
+ let desc = {
553
+ configurable: true,
554
+ enumerable: true,
555
+ writable: true,
556
+ initializer: null
557
+ };
558
+ if (initializer) {
559
+ desc.initializer = initializer;
560
+ }
561
+ for (let decorator of decorators) {
562
+ desc = decorator(prototype, prop, desc) || desc;
483
563
  }
484
564
  if (desc.initializer === void 0) {
485
- Object.defineProperty(target, property, desc);
486
- desc = null;
565
+ Object.defineProperty(prototype, prop, desc);
566
+ } else {
567
+ deferDecorator(prototype, prop, desc);
487
568
  }
488
- return desc;
489
569
  }
490
- const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
491
- var _dec$1, _class$6;
570
+ function decorateMethodV1({
571
+ prototype
572
+ }, prop, decorators) {
573
+ return decorateMethodV2(prototype, prop, decorators);
574
+ }
575
+ function decorateMethodV2(prototype, prop, decorators) {
576
+ const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
577
+ let desc = {
578
+ ...origDesc
579
+ };
580
+ for (let decorator of decorators) {
581
+ desc = decorator(prototype, prop, desc) || desc;
582
+ }
583
+ if (desc.initializer !== void 0) {
584
+ desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
585
+ desc.initializer = void 0;
586
+ }
587
+ Object.defineProperty(prototype, prop, desc);
588
+ }
589
+ function initializeDeferredDecorator(target, prop) {
590
+ let desc = findDeferredDecorator(target.constructor, prop);
591
+ if (desc) {
592
+ Object.defineProperty(target, prop, {
593
+ enumerable: desc.enumerable,
594
+ configurable: desc.configurable,
595
+ writable: desc.writable,
596
+ value: desc.initializer ? desc.initializer.call(target) : void 0
597
+ });
598
+ }
599
+ }
600
+ function decorateClass(target, decorators) {
601
+ return decorators.reduce((accum, decorator) => decorator(accum) || accum, target);
602
+ }
603
+ function decoratePOJO(pojo, decorated) {
604
+ for (let [type, prop, decorators] of decorated) {
605
+ if (type === "field") {
606
+ decoratePojoField(pojo, prop, decorators);
607
+ } else {
608
+ decorateMethodV2(pojo, prop, decorators);
609
+ }
610
+ }
611
+ return pojo;
612
+ }
613
+ function decoratePojoField(pojo, prop, decorators) {
614
+ let desc = {
615
+ configurable: true,
616
+ enumerable: true,
617
+ writable: true,
618
+ initializer: () => Object.getOwnPropertyDescriptor(pojo, prop)?.value
619
+ };
620
+ for (let decorator of decorators) {
621
+ desc = decorator(pojo, prop, desc) || desc;
622
+ }
623
+ if (desc.initializer) {
624
+ desc.value = desc.initializer.call(pojo);
625
+ delete desc.initializer;
626
+ }
627
+ Object.defineProperty(pojo, prop, desc);
628
+ }
492
629
  const LegacyPromiseProxy = Symbol.for('LegacyPromiseProxy');
493
630
 
494
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
631
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-extraneous-class
495
632
 
496
633
  const Extended = PromiseObject;
497
634
 
@@ -508,11 +645,7 @@ const Extended = PromiseObject;
508
645
  @extends PromiseObject
509
646
  @private
510
647
  */
511
- let PromiseBelongsTo = (_dec$1 = computed(), (_class$6 = class PromiseBelongsTo extends Extended {
512
- constructor(...args) {
513
- super(...args);
514
- this[LegacyPromiseProxy] = true;
515
- }
648
+ class PromiseBelongsTo extends Extended {
516
649
  get id() {
517
650
  const {
518
651
  key,
@@ -525,15 +658,29 @@ let PromiseBelongsTo = (_dec$1 = computed(), (_class$6 = class PromiseBelongsTo
525
658
  // we don't proxy meta because we would need to proxy it to the relationship state container
526
659
  // however, meta on relationships does not trigger change notifications.
527
660
  // if you need relationship meta, you should do `record.belongsTo(relationshipName).meta()`
661
+ static {
662
+ decorateMethodV2(this.prototype, "id", [cached]);
663
+ }
528
664
  get meta() {
529
665
  // eslint-disable-next-line no-constant-condition
530
666
  {
531
- assert('You attempted to access meta on the promise for the async belongsTo relationship ' + `${this._belongsToState.modelName}:${this._belongsToState.key}'.` + '\nUse `record.belongsTo(relationshipName).meta()` instead.', false);
667
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
668
+ {
669
+ throw new Error('You attempted to access meta on the promise for the async belongsTo relationship ' + `${this._belongsToState.modelName}:${this._belongsToState.key}'.` + '\nUse `record.belongsTo(relationshipName).meta()` instead.');
670
+ }
671
+ })() : {};
532
672
  }
533
673
  return;
534
674
  }
675
+ static {
676
+ decorateMethodV2(this.prototype, "meta", [computed()]);
677
+ }
535
678
  async reload(options) {
536
- assert('You are trying to reload an async belongsTo before it has been created', this.content !== undefined);
679
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
680
+ if (!test) {
681
+ throw new Error('You are trying to reload an async belongsTo before it has been created');
682
+ }
683
+ })(this.content !== undefined) : {};
537
684
  const {
538
685
  key,
539
686
  legacySupport
@@ -541,8 +688,9 @@ let PromiseBelongsTo = (_dec$1 = computed(), (_class$6 = class PromiseBelongsTo
541
688
  await legacySupport.reloadBelongsTo(key, options);
542
689
  return this;
543
690
  }
544
- }, (_applyDecoratedDescriptor(_class$6.prototype, "id", [cached], Object.getOwnPropertyDescriptor(_class$6.prototype, "id"), _class$6.prototype), _applyDecoratedDescriptor(_class$6.prototype, "meta", [_dec$1], Object.getOwnPropertyDescriptor(_class$6.prototype, "meta"), _class$6.prototype)), _class$6));
545
- var _class$5;
691
+ [LegacyPromiseProxy] = true;
692
+ }
693
+
546
694
  /**
547
695
  @module @ember-data/model
548
696
  */
@@ -562,9 +710,8 @@ var _class$5;
562
710
  @class PromiseManyArray
563
711
  @public
564
712
  */
565
- let PromiseManyArray = (_class$5 = class PromiseManyArray {
713
+ class PromiseManyArray {
566
714
  constructor(promise, content) {
567
- this[LegacyPromiseProxy] = true;
568
715
  this._update(promise, content);
569
716
  this.isDestroyed = false;
570
717
  }
@@ -577,7 +724,7 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
577
724
  get length() {
578
725
  // shouldn't be needed, but ends up being needed
579
726
  // for computed chains even in 4.x
580
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
727
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
581
728
  this['[]'];
582
729
  }
583
730
  return this.content ? this.content.length : 0;
@@ -593,6 +740,9 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
593
740
  * @return
594
741
  * @private
595
742
  */
743
+ static {
744
+ decorateMethodV2(this.prototype, "length", [compat]);
745
+ }
596
746
  forEach(cb) {
597
747
  if (this.content && this.length) {
598
748
  this.content.forEach(cb);
@@ -607,7 +757,11 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
607
757
  * @return
608
758
  */
609
759
  reload(options) {
610
- assert('You are trying to reload an async manyArray before it has been created', this.content);
760
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
761
+ if (!test) {
762
+ throw new Error('You are trying to reload an async manyArray before it has been created');
763
+ }
764
+ })(this.content) : {};
611
765
  void this.content.reload(options);
612
766
  return this;
613
767
  }
@@ -702,12 +856,17 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
702
856
  * @property meta
703
857
  * @public
704
858
  */
859
+ static {
860
+ decorateMethodV2(this.prototype, "links", [compat]);
861
+ }
705
862
  get meta() {
706
863
  return this.content ? this.content.meta : undefined;
707
864
  }
708
865
 
709
866
  //---- Our own stuff
710
-
867
+ static {
868
+ decorateMethodV2(this.prototype, "meta", [compat]);
869
+ }
711
870
  _update(promise, content) {
712
871
  if (content !== undefined) {
713
872
  this.content = content;
@@ -720,7 +879,8 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
720
879
  }) {
721
880
  return new this(promise, content);
722
881
  }
723
- }, (_applyDecoratedDescriptor(_class$5.prototype, "length", [compat], Object.getOwnPropertyDescriptor(_class$5.prototype, "length"), _class$5.prototype), _applyDecoratedDescriptor(_class$5.prototype, "links", [compat], Object.getOwnPropertyDescriptor(_class$5.prototype, "links"), _class$5.prototype), _applyDecoratedDescriptor(_class$5.prototype, "meta", [compat], Object.getOwnPropertyDescriptor(_class$5.prototype, "meta"), _class$5.prototype)), _class$5);
882
+ [LegacyPromiseProxy] = true;
883
+ }
724
884
  defineSignal(PromiseManyArray.prototype, 'content', null);
725
885
  defineSignal(PromiseManyArray.prototype, 'isPending', false);
726
886
  defineSignal(PromiseManyArray.prototype, 'isRejected', false);
@@ -731,7 +891,7 @@ defineSignal(PromiseManyArray.prototype, 'isSettled', false);
731
891
  // A(identifierArray) since it is not configurable
732
892
  // which is preferrable to the `meta` override we used
733
893
  // before which required importing all of Ember
734
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
894
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
735
895
  const desc = {
736
896
  enumerable: true,
737
897
  configurable: false,
@@ -781,21 +941,27 @@ function tapPromise(proxy, promise) {
781
941
  `record.relationshipFor(key)`.
782
942
  */
783
943
  let assertPolymorphicType;
784
- if (macroCondition(getOwnConfig().env.DEBUG)) {
944
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
945
+ // eslint-disable-next-line @typescript-eslint/no-shadow
785
946
  assertPolymorphicType = function assertPolymorphicType(parentIdentifier, parentDefinition, addedIdentifier, store) {
786
947
  if (parentDefinition.inverseIsImplicit) {
787
948
  return;
788
949
  }
789
950
  if (parentDefinition.isPolymorphic) {
790
- let meta = store.getSchemaDefinitionService().relationshipsDefinitionFor(addedIdentifier)[parentDefinition.inverseKey];
791
- assert(`The schema for the relationship '${parentDefinition.inverseKey}' on '${addedIdentifier.type}' type does not implement '${parentDefinition.type}' and thus cannot be assigned to the '${parentDefinition.key}' relationship in '${parentIdentifier.type}'. The definition should specify 'as: "${parentDefinition.type}"' in options.`, meta?.options.as === parentDefinition.type);
951
+ const meta = store.schema.fields(addedIdentifier)?.get(parentDefinition.inverseKey);
952
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
953
+ if (!test) {
954
+ throw new Error(`Expected the schema for the field ${parentDefinition.inverseKey} on ${addedIdentifier.type} to be for a legacy relationship`);
955
+ }
956
+ })(!meta || meta.kind === 'belongsTo' || meta.kind === 'hasMany') : {};
957
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
958
+ if (!test) {
959
+ throw new Error(`The schema for the relationship '${parentDefinition.inverseKey}' on '${addedIdentifier.type}' type does not implement '${parentDefinition.type}' and thus cannot be assigned to the '${parentDefinition.key}' relationship in '${parentIdentifier.type}'. The definition should specify 'as: "${parentDefinition.type}"' in options.`);
960
+ }
961
+ })(meta?.options.as === parentDefinition.type) : {};
792
962
  }
793
963
  };
794
964
  }
795
- var _class$4;
796
- /**
797
- @module @ember-data/model
798
- */
799
965
  function isResourceIdentiferWithRelatedLinks$1(value) {
800
966
  return Boolean(value && value.links && value.links.related);
801
967
  }
@@ -827,24 +993,26 @@ function isResourceIdentiferWithRelatedLinks$1(value) {
827
993
  @class HasManyReference
828
994
  @public
829
995
  */
830
- let HasManyReference = (_class$4 = class HasManyReference {
996
+ class HasManyReference {
997
+ /**
998
+ * The field name on the parent record for this has-many relationship.
999
+ *
1000
+ * @property {String} key
1001
+ * @public
1002
+ */
1003
+
1004
+ /**
1005
+ * The type of resource this relationship will contain.
1006
+ *
1007
+ * @property {String} type
1008
+ * @public
1009
+ */
1010
+
1011
+ // unsubscribe tokens given to us by the notification manager
1012
+ ___token;
1013
+ ___identifier;
1014
+ ___relatedTokenMap;
831
1015
  constructor(store, graph, parentIdentifier, hasManyRelationship, key) {
832
- /**
833
- * The field name on the parent record for this has-many relationship.
834
- *
835
- * @property {String} key
836
- * @public
837
- */
838
- /**
839
- * The type of resource this relationship will contain.
840
- *
841
- * @property {String} type
842
- * @public
843
- */
844
- // unsubscribe tokens given to us by the notification manager
845
- this.___token = void 0;
846
- this.___identifier = void 0;
847
- this.___relatedTokenMap = void 0;
848
1016
  this.graph = graph;
849
1017
  this.key = key;
850
1018
  this.hasManyRelationship = hasManyRelationship;
@@ -908,6 +1076,9 @@ let HasManyReference = (_class$4 = class HasManyReference {
908
1076
  map.clear();
909
1077
  return [];
910
1078
  }
1079
+ static {
1080
+ decorateMethodV2(this.prototype, "identifiers", [compat, cached]);
1081
+ }
911
1082
  _resource() {
912
1083
  const cache = this.store.cache;
913
1084
  return cache.getRelationship(this.___identifier, this.key);
@@ -1177,12 +1348,16 @@ let HasManyReference = (_class$4 = class HasManyReference {
1177
1348
  const isResourceData = Array.isArray(dataDoc.data) && dataDoc.data.length > 0 && isMaybeResource(dataDoc.data[0]);
1178
1349
 
1179
1350
  // enforce that one of links, meta or data is present
1180
- assert(`You must provide at least one of 'links', 'meta' or 'data' when calling hasManyReference.push`, 'links' in dataDoc || 'meta' in dataDoc || 'data' in dataDoc);
1351
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
1352
+ if (!test) {
1353
+ throw new Error(`You must provide at least one of 'links', 'meta' or 'data' when calling hasManyReference.push`);
1354
+ }
1355
+ })('links' in dataDoc || 'meta' in dataDoc || 'data' in dataDoc) : {};
1181
1356
  const identifiers = !Array.isArray(dataDoc.data) ? [] : isResourceData ? store._push(dataDoc, true) : dataDoc.data.map(i => store.identifierCache.getOrCreateRecordIdentifier(i));
1182
1357
  const {
1183
1358
  identifier
1184
1359
  } = this.hasManyRelationship;
1185
- if (macroCondition(getOwnConfig().env.DEBUG)) {
1360
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1186
1361
  const relationshipMeta = this.hasManyRelationship.definition;
1187
1362
  identifiers.forEach(added => {
1188
1363
  assertPolymorphicType(identifier, relationshipMeta, added, store);
@@ -1372,13 +1547,12 @@ let HasManyReference = (_class$4 = class HasManyReference {
1372
1547
  const support = LEGACY_SUPPORT.get(this.___identifier);
1373
1548
  return support.reloadHasMany(this.key, options);
1374
1549
  }
1375
- }, _applyDecoratedDescriptor(_class$4.prototype, "identifiers", [cached, compat], Object.getOwnPropertyDescriptor(_class$4.prototype, "identifiers"), _class$4.prototype), _class$4);
1550
+ }
1376
1551
  defineSignal(HasManyReference.prototype, '_ref', 0);
1377
1552
  function isMaybeResource(object) {
1378
1553
  const keys = Object.keys(object).filter(k => k !== 'id' && k !== 'type' && k !== 'lid');
1379
1554
  return keys.length > 0;
1380
1555
  }
1381
- var _class$3;
1382
1556
  function isResourceIdentiferWithRelatedLinks(value) {
1383
1557
  return Boolean(value && value.links && value.links.related);
1384
1558
  }
@@ -1411,7 +1585,7 @@ function isResourceIdentiferWithRelatedLinks(value) {
1411
1585
  @class BelongsToReference
1412
1586
  @public
1413
1587
  */
1414
- let BelongsToReference = (_class$3 = class BelongsToReference {
1588
+ class BelongsToReference {
1415
1589
  /**
1416
1590
  * The field name on the parent record for this has-many relationship.
1417
1591
  *
@@ -1514,6 +1688,9 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1514
1688
  @public
1515
1689
  @return {String} The id of the record in this belongsTo relationship.
1516
1690
  */
1691
+ static {
1692
+ decorateMethodV2(this.prototype, "identifier", [compat, cached]);
1693
+ }
1517
1694
  id() {
1518
1695
  return this.identifier?.id || null;
1519
1696
  }
@@ -1752,7 +1929,7 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1752
1929
  const {
1753
1930
  identifier
1754
1931
  } = this.belongsToRelationship;
1755
- if (macroCondition(getOwnConfig().env.DEBUG)) {
1932
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1756
1933
  if (added) {
1757
1934
  assertPolymorphicType(identifier, this.belongsToRelationship.definition, added, store);
1758
1935
  }
@@ -1933,15 +2110,23 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1933
2110
  const support = LEGACY_SUPPORT.get(this.___identifier);
1934
2111
  return support.reloadBelongsTo(this.key, options).then(() => this.value());
1935
2112
  }
1936
- }, _applyDecoratedDescriptor(_class$3.prototype, "identifier", [cached, compat], Object.getOwnPropertyDescriptor(_class$3.prototype, "identifier"), _class$3.prototype), _class$3);
2113
+ }
1937
2114
  defineSignal(BelongsToReference.prototype, '_ref', 0);
1938
- const LEGACY_SUPPORT = new Map();
2115
+ const LEGACY_SUPPORT = getOrSetGlobal('LEGACY_SUPPORT', new Map());
1939
2116
  function lookupLegacySupport(record) {
1940
2117
  const identifier = recordIdentifierFor(record);
1941
- assert(`Expected a record`, identifier);
2118
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2119
+ if (!test) {
2120
+ throw new Error(`Expected a record`);
2121
+ }
2122
+ })(identifier) : {};
1942
2123
  let support = LEGACY_SUPPORT.get(identifier);
1943
2124
  if (!support) {
1944
- assert(`Memory Leak Detected`, !record.isDestroyed && !record.isDestroying);
2125
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2126
+ if (!test) {
2127
+ throw new Error(`Memory Leak Detected`);
2128
+ }
2129
+ })(!record.isDestroyed && !record.isDestroying) : {};
1945
2130
  support = new LegacySupport(record);
1946
2131
  LEGACY_SUPPORT.set(identifier, support);
1947
2132
  LEGACY_SUPPORT.set(record, support);
@@ -1954,7 +2139,7 @@ class LegacySupport {
1954
2139
  this.store = storeFor(record);
1955
2140
  this.identifier = recordIdentifierFor(record);
1956
2141
  this.cache = peekCache(record);
1957
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2142
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
1958
2143
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
1959
2144
  this.graph = graphFor(this.store);
1960
2145
  }
@@ -1995,7 +2180,11 @@ class LegacySupport {
1995
2180
  return loadingPromise;
1996
2181
  }
1997
2182
  const relationship = this.graph.get(this.identifier, key);
1998
- assert(`Expected ${key} to be a belongs-to relationship`, isBelongsTo(relationship));
2183
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2184
+ if (!test) {
2185
+ throw new Error(`Expected ${key} to be a belongs-to relationship`);
2186
+ }
2187
+ })(isBelongsTo(relationship)) : {};
1999
2188
  const resource = this.cache.getRelationship(this.identifier, key);
2000
2189
  relationship.state.hasFailedLoadAttempt = false;
2001
2190
  relationship.state.shouldForceReload = true;
@@ -2015,10 +2204,18 @@ class LegacySupport {
2015
2204
  } = this;
2016
2205
  const resource = cache.getRelationship(this.identifier, key);
2017
2206
  const relatedIdentifier = resource && resource.data ? resource.data : null;
2018
- assert(`Expected a stable identifier`, !relatedIdentifier || isStableIdentifier(relatedIdentifier));
2207
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2208
+ if (!test) {
2209
+ throw new Error(`Expected a stable identifier`);
2210
+ }
2211
+ })(!relatedIdentifier || isStableIdentifier(relatedIdentifier)) : {};
2019
2212
  const store = this.store;
2020
2213
  const relationship = this.graph.get(this.identifier, key);
2021
- assert(`Expected ${key} to be a belongs-to relationship`, isBelongsTo(relationship));
2214
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2215
+ if (!test) {
2216
+ throw new Error(`Expected ${key} to be a belongs-to relationship`);
2217
+ }
2218
+ })(isBelongsTo(relationship)) : {};
2022
2219
  const isAsync = relationship.definition.isAsync;
2023
2220
  const _belongsToState = {
2024
2221
  key,
@@ -2042,7 +2239,11 @@ class LegacySupport {
2042
2239
  return null;
2043
2240
  } else {
2044
2241
  const toReturn = store._instanceCache.getRecord(relatedIdentifier);
2045
- assert(`You looked up the '${key}' relationship on a '${identifier.type}' with id ${identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`belongsTo(<type>, { async: true, inverse: <inverse> })\`)`, toReturn === null || store._instanceCache.recordIsLoaded(relatedIdentifier, true));
2242
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2243
+ if (!test) {
2244
+ throw new Error(`You looked up the '${key}' relationship on a '${identifier.type}' with id ${identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`belongsTo(<type>, { async: true, inverse: <inverse> })\`)`);
2245
+ }
2246
+ })(toReturn === null || store._instanceCache.recordIsLoaded(relatedIdentifier, true)) : {};
2046
2247
  return toReturn;
2047
2248
  }
2048
2249
  }
@@ -2064,7 +2265,11 @@ class LegacySupport {
2064
2265
  if (jsonApi.data) {
2065
2266
  for (let i = 0; i < jsonApi.data.length; i++) {
2066
2267
  const relatedIdentifier = jsonApi.data[i];
2067
- assert(`Expected a stable identifier`, isStableIdentifier(relatedIdentifier));
2268
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2269
+ if (!test) {
2270
+ throw new Error(`Expected a stable identifier`);
2271
+ }
2272
+ })(isStableIdentifier(relatedIdentifier)) : {};
2068
2273
  if (cache.recordIsLoaded(relatedIdentifier, true)) {
2069
2274
  identifiers.push(relatedIdentifier);
2070
2275
  }
@@ -2073,7 +2278,7 @@ class LegacySupport {
2073
2278
  return [identifiers, jsonApi];
2074
2279
  }
2075
2280
  getManyArray(key, definition) {
2076
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2281
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2077
2282
  let manyArray = this._manyArrayCache[key];
2078
2283
  if (!definition) {
2079
2284
  definition = this.graph.get(this.identifier, key).definition;
@@ -2100,10 +2305,14 @@ class LegacySupport {
2100
2305
  }
2101
2306
  return manyArray;
2102
2307
  }
2103
- assert('hasMany only works with the @ember-data/json-api package');
2308
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2309
+ {
2310
+ throw new Error('hasMany only works with the @ember-data/json-api package');
2311
+ }
2312
+ })() : {};
2104
2313
  }
2105
2314
  fetchAsyncHasMany(key, relationship, manyArray, options) {
2106
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2315
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2107
2316
  let loadingPromise = this._relationshipPromisesCache[key];
2108
2317
  if (loadingPromise) {
2109
2318
  return loadingPromise;
@@ -2118,10 +2327,14 @@ class LegacySupport {
2118
2327
  this._relationshipPromisesCache[key] = loadingPromise;
2119
2328
  return loadingPromise;
2120
2329
  }
2121
- assert('hasMany only works with the @ember-data/json-api package');
2330
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2331
+ {
2332
+ throw new Error('hasMany only works with the @ember-data/json-api package');
2333
+ }
2334
+ })() : {};
2122
2335
  }
2123
2336
  reloadHasMany(key, options) {
2124
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2337
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2125
2338
  const loadingPromise = this._relationshipPromisesCache[key];
2126
2339
  if (loadingPromise) {
2127
2340
  return loadingPromise;
@@ -2142,10 +2355,14 @@ class LegacySupport {
2142
2355
  }
2143
2356
  return promise;
2144
2357
  }
2145
- assert(`hasMany only works with the @ember-data/json-api package`);
2358
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2359
+ {
2360
+ throw new Error(`hasMany only works with the @ember-data/json-api package`);
2361
+ }
2362
+ })() : {};
2146
2363
  }
2147
2364
  getHasMany(key, options) {
2148
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2365
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2149
2366
  const relationship = this.graph.get(this.identifier, key);
2150
2367
  const {
2151
2368
  definition,
@@ -2162,11 +2379,19 @@ class LegacySupport {
2162
2379
  content: manyArray
2163
2380
  });
2164
2381
  } else {
2165
- assert(`You looked up the '${key}' relationship on a '${this.identifier.type}' with id ${this.identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('hasMany(<type>, { async: true, inverse: <inverse> })')`, !anyUnloaded(this.store, relationship));
2382
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2383
+ if (!test) {
2384
+ throw new Error(`You looked up the '${key}' relationship on a '${this.identifier.type}' with id ${this.identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('hasMany(<type>, { async: true, inverse: <inverse> })')`);
2385
+ }
2386
+ })(!anyUnloaded(this.store, relationship)) : {};
2166
2387
  return manyArray;
2167
2388
  }
2168
2389
  }
2169
- assert(`hasMany only works with the @ember-data/json-api package`);
2390
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2391
+ {
2392
+ throw new Error(`hasMany only works with the @ember-data/json-api package`);
2393
+ }
2394
+ })() : {};
2170
2395
  }
2171
2396
  _updatePromiseProxyFor(kind, key, args) {
2172
2397
  let promiseProxy = this._relationshipProxyCache[key];
@@ -2176,7 +2401,11 @@ class LegacySupport {
2176
2401
  content
2177
2402
  } = args;
2178
2403
  if (promiseProxy) {
2179
- assert(`Expected a PromiseManyArray`, '_update' in promiseProxy);
2404
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2405
+ if (!test) {
2406
+ throw new Error(`Expected a PromiseManyArray`);
2407
+ }
2408
+ })('_update' in promiseProxy) : {};
2180
2409
  promiseProxy._update(promise, content);
2181
2410
  } else {
2182
2411
  promiseProxy = this._relationshipProxyCache[key] = new PromiseManyArray(promise, content);
@@ -2188,7 +2417,11 @@ class LegacySupport {
2188
2417
  promise,
2189
2418
  content
2190
2419
  } = args;
2191
- assert(`Expected a PromiseBelongsTo`, '_belongsToState' in promiseProxy);
2420
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2421
+ if (!test) {
2422
+ throw new Error(`Expected a PromiseBelongsTo`);
2423
+ }
2424
+ })('_belongsToState' in promiseProxy) : {};
2192
2425
  if (content !== undefined) {
2193
2426
  promiseProxy.set('content', content);
2194
2427
  }
@@ -2202,22 +2435,30 @@ class LegacySupport {
2202
2435
  referenceFor(kind, name) {
2203
2436
  let reference = this.references[name];
2204
2437
  if (!reference) {
2205
- if (macroCondition(!getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2438
+ if (macroCondition(!dependencySatisfies('@ember-data/graph', '*'))) {
2206
2439
  // TODO @runspired while this feels odd, it is not a regression in capability because we do
2207
2440
  // not today support references pulling from RecordDatas other than our own
2208
2441
  // because of the intimate API access involved. This is something we will need to redesign.
2209
- assert(`snapshot.belongsTo only supported for @ember-data/json-api`);
2442
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2443
+ {
2444
+ throw new Error(`snapshot.belongsTo only supported for @ember-data/json-api`);
2445
+ }
2446
+ })() : {};
2210
2447
  }
2211
2448
  const {
2212
2449
  graph,
2213
2450
  identifier
2214
2451
  } = this;
2215
2452
  const relationship = graph.get(identifier, name);
2216
- if (macroCondition(getOwnConfig().env.DEBUG)) {
2453
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
2217
2454
  if (kind) {
2218
2455
  const modelName = identifier.type;
2219
2456
  const actualRelationshipKind = relationship.definition.kind;
2220
- assert(`You tried to get the '${name}' relationship on a '${modelName}' via record.${kind}('${name}'), but the relationship is of kind '${actualRelationshipKind}'. Use record.${actualRelationshipKind}('${name}') instead.`, actualRelationshipKind === kind);
2457
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2458
+ if (!test) {
2459
+ throw new Error(`You tried to get the '${name}' relationship on a '${modelName}' via record.${kind}('${name}'), but the relationship is of kind '${actualRelationshipKind}'. Use record.${actualRelationshipKind}('${name}') instead.`);
2460
+ }
2461
+ })(actualRelationshipKind === kind) : {};
2221
2462
  }
2222
2463
  }
2223
2464
  const relationshipKind = relationship.definition.kind;
@@ -2231,7 +2472,7 @@ class LegacySupport {
2231
2472
  return reference;
2232
2473
  }
2233
2474
  _findHasManyByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
2234
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2475
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2235
2476
  if (!resource) {
2236
2477
  return;
2237
2478
  }
@@ -2251,12 +2492,17 @@ class LegacySupport {
2251
2492
  const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
2252
2493
  const identifiers = resource.data;
2253
2494
  const shouldFindViaLink = resource.links && resource.links.related && (typeof adapter.findHasMany === 'function' || typeof identifiers === 'undefined') && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
2254
- const relationshipMeta = this.store.getSchemaDefinitionService().relationshipsDefinitionFor({
2495
+ const field = this.store.schema.fields({
2255
2496
  type: definition.inverseType
2256
- })[definition.key];
2497
+ }).get(definition.key);
2498
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2499
+ if (!test) {
2500
+ throw new Error(`Expected a hasMany field definition for ${definition.inverseType}.${definition.key}`);
2501
+ }
2502
+ })(field && field.kind === 'hasMany') : {};
2257
2503
  const request = {
2258
2504
  useLink: shouldFindViaLink,
2259
- field: relationshipMeta,
2505
+ field,
2260
2506
  links: resource.links,
2261
2507
  meta: resource.meta,
2262
2508
  options,
@@ -2265,8 +2511,16 @@ class LegacySupport {
2265
2511
 
2266
2512
  // fetch via link
2267
2513
  if (shouldFindViaLink) {
2268
- assert(`Expected collection to be an array`, !identifiers || Array.isArray(identifiers));
2269
- assert(`Expected stable identifiers`, !identifiers || identifiers.every(isStableIdentifier));
2514
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2515
+ if (!test) {
2516
+ throw new Error(`Expected collection to be an array`);
2517
+ }
2518
+ })(!identifiers || Array.isArray(identifiers)) : {};
2519
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2520
+ if (!test) {
2521
+ throw new Error(`Expected stable identifiers`);
2522
+ }
2523
+ })(!identifiers || identifiers.every(isStableIdentifier)) : {};
2270
2524
  return this.store.request({
2271
2525
  op: 'findHasMany',
2272
2526
  records: identifiers || [],
@@ -2284,8 +2538,16 @@ class LegacySupport {
2284
2538
  }
2285
2539
  const hasData = hasReceivedData && !isEmpty;
2286
2540
  if (attemptLocalCache || hasData || hasLocalPartialData) {
2287
- assert(`Expected collection to be an array`, Array.isArray(identifiers));
2288
- assert(`Expected stable identifiers`, identifiers.every(isStableIdentifier));
2541
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2542
+ if (!test) {
2543
+ throw new Error(`Expected collection to be an array`);
2544
+ }
2545
+ })(Array.isArray(identifiers)) : {};
2546
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2547
+ if (!test) {
2548
+ throw new Error(`Expected stable identifiers`);
2549
+ }
2550
+ })(identifiers.every(isStableIdentifier)) : {};
2289
2551
  options.reload = options.reload || !attemptLocalCache || undefined;
2290
2552
  return this.store.request({
2291
2553
  op: 'findHasMany',
@@ -2301,7 +2563,11 @@ class LegacySupport {
2301
2563
  // TODO if the relationshipIsStale, should we hit the adapter anyway?
2302
2564
  return;
2303
2565
  }
2304
- assert(`hasMany only works with the @ember-data/json-api package`);
2566
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2567
+ {
2568
+ throw new Error(`hasMany only works with the @ember-data/json-api package`);
2569
+ }
2570
+ })() : {};
2305
2571
  }
2306
2572
  _findBelongsToByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
2307
2573
  if (!resource) {
@@ -2316,7 +2582,11 @@ class LegacySupport {
2316
2582
  return this._pending[key];
2317
2583
  }
2318
2584
  const identifier = resource.data ? resource.data : null;
2319
- assert(`Expected a stable identifier`, !identifier || isStableIdentifier(identifier));
2585
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2586
+ if (!test) {
2587
+ throw new Error(`Expected a stable identifier`);
2588
+ }
2589
+ })(!identifier || isStableIdentifier(identifier)) : {};
2320
2590
  const {
2321
2591
  isStale,
2322
2592
  hasDematerializedInverse,
@@ -2326,11 +2596,15 @@ class LegacySupport {
2326
2596
  } = relationship.state;
2327
2597
  const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
2328
2598
  const shouldFindViaLink = resource.links?.related && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
2329
- const relationshipMeta = this.store.getSchemaDefinitionService().relationshipsDefinitionFor(this.identifier)[relationship.definition.key];
2330
- assert(`Attempted to access a belongsTo relationship but no definition exists for it`, relationshipMeta);
2599
+ const field = this.store.schema.fields(this.identifier).get(relationship.definition.key);
2600
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2601
+ if (!test) {
2602
+ throw new Error(`Attempted to access a belongsTo relationship but no definition exists for it`);
2603
+ }
2604
+ })(field && field.kind === 'belongsTo') : {};
2331
2605
  const request = {
2332
2606
  useLink: shouldFindViaLink,
2333
- field: relationshipMeta,
2607
+ field,
2334
2608
  links: resource.links,
2335
2609
  meta: resource.meta,
2336
2610
  options,
@@ -2371,7 +2645,11 @@ class LegacySupport {
2371
2645
 
2372
2646
  // we may need to fetch
2373
2647
  if (identifier) {
2374
- assert(`Cannot fetch belongs-to relationship with no information`, identifier);
2648
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2649
+ if (!test) {
2650
+ throw new Error(`Cannot fetch belongs-to relationship with no information`);
2651
+ }
2652
+ })(identifier) : {};
2375
2653
  options.reload = options.reload || !attemptLocalCache || undefined;
2376
2654
  this._pending[key] = this.store.request({
2377
2655
  op: 'findBelongsTo',
@@ -2459,7 +2737,11 @@ function extractIdentifierFromRecord(record) {
2459
2737
  }
2460
2738
  function anyUnloaded(store, relationship) {
2461
2739
  const graph = store._graph;
2462
- assert(`Expected a Graph instance to be available`, graph);
2740
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2741
+ if (!test) {
2742
+ throw new Error(`Expected a Graph instance to be available`);
2743
+ }
2744
+ })(graph) : {};
2463
2745
  const relationshipData = graph.getData(relationship.identifier, relationship.definition.key);
2464
2746
  const state = relationshipData.data;
2465
2747
  const cache = store._instanceCache;
@@ -2473,7 +2755,11 @@ function areAllInverseRecordsLoaded(store, resource) {
2473
2755
  const instanceCache = store._instanceCache;
2474
2756
  const identifiers = resource.data;
2475
2757
  if (Array.isArray(identifiers)) {
2476
- assert(`Expected stable identifiers`, identifiers.every(isStableIdentifier));
2758
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2759
+ if (!test) {
2760
+ throw new Error(`Expected stable identifiers`);
2761
+ }
2762
+ })(identifiers.every(isStableIdentifier)) : {};
2477
2763
  // treat as collection
2478
2764
  // check for unloaded records
2479
2765
  return identifiers.every(identifier => instanceCache.recordIsLoaded(identifier));
@@ -2481,26 +2767,16 @@ function areAllInverseRecordsLoaded(store, resource) {
2481
2767
 
2482
2768
  // treat as single resource
2483
2769
  if (!identifiers) return true;
2484
- assert(`Expected stable identifiers`, isStableIdentifier(identifiers));
2770
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
2771
+ if (!test) {
2772
+ throw new Error(`Expected stable identifiers`);
2773
+ }
2774
+ })(isStableIdentifier(identifiers)) : {};
2485
2775
  return instanceCache.recordIsLoaded(identifiers);
2486
2776
  }
2487
2777
  function isBelongsTo(relationship) {
2488
2778
  return relationship.definition.kind === 'belongsTo';
2489
2779
  }
2490
- function _initializerDefineProperty(target, property, descriptor, context) {
2491
- if (!descriptor) return;
2492
- Object.defineProperty(target, property, {
2493
- enumerable: descriptor.enumerable,
2494
- configurable: descriptor.configurable,
2495
- writable: descriptor.writable,
2496
- value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
2497
- });
2498
- }
2499
- var _dec, _dec2, _dec3, _dec4, _class$2, _descriptor, _descriptor2;
2500
-
2501
- /**
2502
- @module @ember-data/model
2503
- */
2504
2780
 
2505
2781
  // we force the type here to our own construct because mixin and extend patterns
2506
2782
  // lose generic signatures. We also do this because we need to Omit `clear` from
@@ -2582,40 +2858,7 @@ const ArrayProxyWithCustomOverrides = ArrayProxy;
2582
2858
  @public
2583
2859
  @extends Ember.ArrayProxy
2584
2860
  */
2585
- let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = computed(), _dec4 = not('length'), (_class$2 = class Errors extends ArrayProxyWithCustomOverrides {
2586
- constructor(...args) {
2587
- super(...args);
2588
- /**
2589
- An array containing all of the error messages for this
2590
- record. This is useful for displaying all errors to the user.
2591
- ```handlebars
2592
- {{#each @model.errors.messages as |message|}}
2593
- <div class="error">
2594
- {{message}}
2595
- </div>
2596
- {{/each}}
2597
- ```
2598
- @property messages
2599
- @public
2600
- @type {Array}
2601
- */
2602
- _initializerDefineProperty(this, "messages", _descriptor, this);
2603
- /**
2604
- Total number of errors.
2605
- @property length
2606
- @type {Number}
2607
- @public
2608
- @readOnly
2609
- */
2610
- /**
2611
- `true` if we have no errors.
2612
- @property isEmpty
2613
- @type {Boolean}
2614
- @public
2615
- @readOnly
2616
- */
2617
- _initializerDefineProperty(this, "isEmpty", _descriptor2, this);
2618
- }
2861
+ class Errors extends ArrayProxyWithCustomOverrides {
2619
2862
  /**
2620
2863
  @property errorsByAttributeName
2621
2864
  @type {MapWithDefault}
@@ -2642,6 +2885,9 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2642
2885
  @param {String} attribute
2643
2886
  @return {Array}
2644
2887
  */
2888
+ static {
2889
+ decorateMethodV2(this.prototype, "errorsByAttributeName", [computed()]);
2890
+ }
2645
2891
  errorsFor(attribute) {
2646
2892
  const map = this.errorsByAttributeName;
2647
2893
  let errors = map.get(attribute);
@@ -2657,6 +2903,25 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2657
2903
  get(errors, '[]');
2658
2904
  return errors;
2659
2905
  }
2906
+
2907
+ /**
2908
+ An array containing all of the error messages for this
2909
+ record. This is useful for displaying all errors to the user.
2910
+ ```handlebars
2911
+ {{#each @model.errors.messages as |message|}}
2912
+ <div class="error">
2913
+ {{message}}
2914
+ </div>
2915
+ {{/each}}
2916
+ ```
2917
+ @property messages
2918
+ @public
2919
+ @type {Array}
2920
+ */
2921
+ static {
2922
+ decorateFieldV2(this.prototype, "messages", [mapBy('content', 'message')]);
2923
+ }
2924
+ #messages = (initializeDeferredDecorator(this, "messages"), void 0);
2660
2925
  /**
2661
2926
  @property content
2662
2927
  @type {Array}
@@ -2670,6 +2935,9 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2670
2935
  @method unknownProperty
2671
2936
  @private
2672
2937
  */
2938
+ static {
2939
+ decorateMethodV2(this.prototype, "content", [computed()]);
2940
+ }
2673
2941
  unknownProperty(attribute) {
2674
2942
  const errors = this.errorsFor(attribute);
2675
2943
  if (errors.length === 0) {
@@ -2677,6 +2945,26 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2677
2945
  }
2678
2946
  return errors;
2679
2947
  }
2948
+
2949
+ /**
2950
+ Total number of errors.
2951
+ @property length
2952
+ @type {Number}
2953
+ @public
2954
+ @readOnly
2955
+ */
2956
+
2957
+ /**
2958
+ `true` if we have no errors.
2959
+ @property isEmpty
2960
+ @type {Boolean}
2961
+ @public
2962
+ @readOnly
2963
+ */
2964
+ static {
2965
+ decorateFieldV2(this.prototype, "isEmpty", [not('length')]);
2966
+ }
2967
+ #isEmpty = (initializeDeferredDecorator(this, "isEmpty"), void 0);
2680
2968
  /**
2681
2969
  Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
2682
2970
  the record and transition the record into an `invalid` state.
@@ -2835,9 +3123,7 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2835
3123
  /**
2836
3124
  Checks if there are error messages for the given attribute.
2837
3125
  ```app/controllers/user/edit.js
2838
- import Controller from '@ember/controller';
2839
- import { action } from '@ember/object';
2840
- export default class UserEditController extends Controller {
3126
+ export default class UserEditController extends Controller {
2841
3127
  @action
2842
3128
  save(user) {
2843
3129
  if (user.errors.has('email')) {
@@ -2855,17 +3141,7 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2855
3141
  has(attribute) {
2856
3142
  return this.errorsFor(attribute).length > 0;
2857
3143
  }
2858
- }, (_applyDecoratedDescriptor(_class$2.prototype, "errorsByAttributeName", [_dec], Object.getOwnPropertyDescriptor(_class$2.prototype, "errorsByAttributeName"), _class$2.prototype), _descriptor = _applyDecoratedDescriptor(_class$2.prototype, "messages", [_dec2], {
2859
- configurable: true,
2860
- enumerable: true,
2861
- writable: true,
2862
- initializer: null
2863
- }), _applyDecoratedDescriptor(_class$2.prototype, "content", [_dec3], Object.getOwnPropertyDescriptor(_class$2.prototype, "content"), _class$2.prototype), _descriptor2 = _applyDecoratedDescriptor(_class$2.prototype, "isEmpty", [_dec4], {
2864
- configurable: true,
2865
- enumerable: true,
2866
- writable: true,
2867
- initializer: null
2868
- })), _class$2));
3144
+ }
2869
3145
  function rollbackAttributes() {
2870
3146
  const {
2871
3147
  currentState
@@ -2898,7 +3174,11 @@ function reload(options = {}) {
2898
3174
  options.isReloading = true;
2899
3175
  options.reload = true;
2900
3176
  const identifier = recordIdentifierFor$1(this);
2901
- assert(`You cannot reload a record without an ID`, identifier.id);
3177
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3178
+ if (!test) {
3179
+ throw new Error(`You cannot reload a record without an ID`);
3180
+ }
3181
+ })(identifier.id) : {};
2902
3182
  this.isReloading = true;
2903
3183
  const promise = this[RecordStore].request({
2904
3184
  op: 'findRecord',
@@ -2973,7 +3253,11 @@ function notifyChanges(identifier, value, key, record, store) {
2973
3253
  } else if (value === 'relationships') {
2974
3254
  if (key) {
2975
3255
  const meta = record.constructor.relationshipsByName.get(key);
2976
- assert(`Expected to find a relationship for ${key} on ${identifier.type}`, meta);
3256
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3257
+ if (!test) {
3258
+ throw new Error(`Expected to find a relationship for ${key} on ${identifier.type}`);
3259
+ }
3260
+ })(meta) : {};
2977
3261
  notifyRelationship(identifier, key, record, meta);
2978
3262
  } else {
2979
3263
  record.eachRelationship((name, meta) => {
@@ -3002,8 +3286,16 @@ function notifyRelationship(identifier, key, record, meta) {
3002
3286
  //We need to notifyPropertyChange in the adding case because we need to make sure
3003
3287
  //we fetch the newly added record in case it is unloaded
3004
3288
  //TODO(Igor): Consider whether we could do this only if the record state is unloaded
3005
- assert(`Expected options to exist on relationship meta`, meta.options);
3006
- assert(`Expected async to exist on relationship meta options`, 'async' in meta.options);
3289
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3290
+ if (!test) {
3291
+ throw new Error(`Expected options to exist on relationship meta`);
3292
+ }
3293
+ })(meta.options) : {};
3294
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3295
+ if (!test) {
3296
+ throw new Error(`Expected async to exist on relationship meta options`);
3297
+ }
3298
+ })('async' in meta.options) : {};
3007
3299
  if (meta.options.async) {
3008
3300
  record.notifyPropertyChange(key);
3009
3301
  }
@@ -3017,7 +3309,6 @@ function notifyAttribute(store, identifier, key, record) {
3017
3309
  record.notifyPropertyChange(key);
3018
3310
  }
3019
3311
  }
3020
- var _class$1;
3021
3312
  const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
3022
3313
  const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
3023
3314
  const PRIMARY_ATTRIBUTE_KEY = 'base';
@@ -3102,7 +3393,7 @@ root
3102
3393
 
3103
3394
  @internal
3104
3395
  */
3105
- let RecordState = (_class$1 = class RecordState {
3396
+ class RecordState {
3106
3397
  constructor(record) {
3107
3398
  const store = storeFor$1(record);
3108
3399
  const identity = recordIdentifierFor(record);
@@ -3199,7 +3490,11 @@ let RecordState = (_class$1 = class RecordState {
3199
3490
  notifySignal(this, key);
3200
3491
  }
3201
3492
  updateInvalidErrors(errors) {
3202
- assert(`Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`, typeof this.cache.getErrors === 'function');
3493
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3494
+ if (!test) {
3495
+ throw new Error(`Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`);
3496
+ }
3497
+ })(typeof this.cache.getErrors === 'function') : {};
3203
3498
  const jsonApiErrors = this.cache.getErrors(this.identifier);
3204
3499
  errors.clear();
3205
3500
  for (let i = 0; i < jsonApiErrors.length; i++) {
@@ -3214,7 +3509,11 @@ let RecordState = (_class$1 = class RecordState {
3214
3509
  }
3215
3510
  if (key) {
3216
3511
  const errMsg = error.detail || error.title;
3217
- assert(`Expected field error to have a detail or title to use as the message`, errMsg);
3512
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3513
+ if (!test) {
3514
+ throw new Error(`Expected field error to have a detail or title to use as the message`);
3515
+ }
3516
+ })(errMsg) : {};
3218
3517
  errors.add(key, errMsg);
3219
3518
  }
3220
3519
  }
@@ -3230,16 +3529,26 @@ let RecordState = (_class$1 = class RecordState {
3230
3529
  get isLoading() {
3231
3530
  return !this.isLoaded && this.pendingCount > 0 && this.fulfilledCount === 0;
3232
3531
  }
3532
+ static {
3533
+ decorateMethodV2(this.prototype, "isLoading", [tagged]);
3534
+ }
3233
3535
  get isLoaded() {
3234
3536
  if (this.isNew) {
3235
3537
  return true;
3236
3538
  }
3237
3539
  return this.fulfilledCount > 0 || !this.isEmpty;
3238
3540
  }
3541
+ static {
3542
+ decorateMethodV2(this.prototype, "isLoaded", [tagged]);
3543
+ }
3239
3544
  get isSaved() {
3240
3545
  const rd = this.cache;
3241
3546
  if (this.isDeleted) {
3242
- assert(`Expected Cache to implement isDeletionCommitted()`, typeof rd.isDeletionCommitted === 'function');
3547
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3548
+ if (!test) {
3549
+ throw new Error(`Expected Cache to implement isDeletionCommitted()`);
3550
+ }
3551
+ })(typeof rd.isDeletionCommitted === 'function') : {};
3243
3552
  return rd.isDeletionCommitted(this.identifier);
3244
3553
  }
3245
3554
  if (this.isNew || this.isEmpty || !this.isValid || this.isDirty || this.isLoading) {
@@ -3247,26 +3556,53 @@ let RecordState = (_class$1 = class RecordState {
3247
3556
  }
3248
3557
  return true;
3249
3558
  }
3559
+ static {
3560
+ decorateMethodV2(this.prototype, "isSaved", [tagged]);
3561
+ }
3250
3562
  get isEmpty() {
3251
3563
  const rd = this.cache;
3252
3564
  // TODO this is not actually an RFC'd concept. Determine the
3253
3565
  // correct heuristic to replace this with.
3254
- assert(`Expected Cache to implement isEmpty()`, typeof rd.isEmpty === 'function');
3566
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3567
+ if (!test) {
3568
+ throw new Error(`Expected Cache to implement isEmpty()`);
3569
+ }
3570
+ })(typeof rd.isEmpty === 'function') : {};
3255
3571
  return !this.isNew && rd.isEmpty(this.identifier);
3256
3572
  }
3573
+ static {
3574
+ decorateMethodV2(this.prototype, "isEmpty", [tagged]);
3575
+ }
3257
3576
  get isNew() {
3258
3577
  const rd = this.cache;
3259
- assert(`Expected Cache to implement isNew()`, typeof rd.isNew === 'function');
3578
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3579
+ if (!test) {
3580
+ throw new Error(`Expected Cache to implement isNew()`);
3581
+ }
3582
+ })(typeof rd.isNew === 'function') : {};
3260
3583
  return rd.isNew(this.identifier);
3261
3584
  }
3585
+ static {
3586
+ decorateMethodV2(this.prototype, "isNew", [tagged]);
3587
+ }
3262
3588
  get isDeleted() {
3263
3589
  const rd = this.cache;
3264
- assert(`Expected Cache to implement isDeleted()`, typeof rd.isDeleted === 'function');
3590
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3591
+ if (!test) {
3592
+ throw new Error(`Expected Cache to implement isDeleted()`);
3593
+ }
3594
+ })(typeof rd.isDeleted === 'function') : {};
3265
3595
  return rd.isDeleted(this.identifier);
3266
3596
  }
3597
+ static {
3598
+ decorateMethodV2(this.prototype, "isDeleted", [tagged]);
3599
+ }
3267
3600
  get isValid() {
3268
3601
  return this.record.errors.length === 0;
3269
3602
  }
3603
+ static {
3604
+ decorateMethodV2(this.prototype, "isValid", [tagged]);
3605
+ }
3270
3606
  get isDirty() {
3271
3607
  const rd = this.cache;
3272
3608
  if (this.isEmpty || rd.isDeletionCommitted(this.identifier) || this.isDeleted && this.isNew) {
@@ -3274,6 +3610,9 @@ let RecordState = (_class$1 = class RecordState {
3274
3610
  }
3275
3611
  return this.isDeleted || this.isNew || rd.hasChangedAttrs(this.identifier);
3276
3612
  }
3613
+ static {
3614
+ decorateMethodV2(this.prototype, "isDirty", [tagged]);
3615
+ }
3277
3616
  get isError() {
3278
3617
  const errorReq = this._errorRequests[this._errorRequests.length - 1];
3279
3618
  if (!errorReq) {
@@ -3282,6 +3621,9 @@ let RecordState = (_class$1 = class RecordState {
3282
3621
  return true;
3283
3622
  }
3284
3623
  }
3624
+ static {
3625
+ decorateMethodV2(this.prototype, "isError", [tagged]);
3626
+ }
3285
3627
  get adapterError() {
3286
3628
  const request = this._lastError;
3287
3629
  if (!request) {
@@ -3289,9 +3631,15 @@ let RecordState = (_class$1 = class RecordState {
3289
3631
  }
3290
3632
  return request.state === 'rejected' && request.response.data;
3291
3633
  }
3634
+ static {
3635
+ decorateMethodV2(this.prototype, "adapterError", [tagged]);
3636
+ }
3292
3637
  get isPreloaded() {
3293
3638
  return !this.isEmpty && this.isLoading;
3294
3639
  }
3640
+ static {
3641
+ decorateMethodV2(this.prototype, "isPreloaded", [cached]);
3642
+ }
3295
3643
  get stateName() {
3296
3644
  // we might be empty while loading so check this first
3297
3645
  if (this.isLoading) {
@@ -3336,6 +3684,9 @@ let RecordState = (_class$1 = class RecordState {
3336
3684
  return 'root.loaded.saved';
3337
3685
  }
3338
3686
  }
3687
+ static {
3688
+ decorateMethodV2(this.prototype, "stateName", [cached]);
3689
+ }
3339
3690
  get dirtyType() {
3340
3691
  // we might be empty while loading so check this first
3341
3692
  if (this.isLoading || this.isEmpty) {
@@ -3358,15 +3709,21 @@ let RecordState = (_class$1 = class RecordState {
3358
3709
  return '';
3359
3710
  }
3360
3711
  }
3361
- }, (_applyDecoratedDescriptor(_class$1.prototype, "isLoading", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isLoading"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isLoaded", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isLoaded"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isSaved", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isSaved"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isEmpty", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isEmpty"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isNew", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isNew"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isDeleted", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isDeleted"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isValid", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isValid"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isDirty", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isDirty"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isError", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "isError"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "adapterError", [tagged], Object.getOwnPropertyDescriptor(_class$1.prototype, "adapterError"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "isPreloaded", [cached], Object.getOwnPropertyDescriptor(_class$1.prototype, "isPreloaded"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "stateName", [cached], Object.getOwnPropertyDescriptor(_class$1.prototype, "stateName"), _class$1.prototype), _applyDecoratedDescriptor(_class$1.prototype, "dirtyType", [cached], Object.getOwnPropertyDescriptor(_class$1.prototype, "dirtyType"), _class$1.prototype)), _class$1);
3712
+ static {
3713
+ decorateMethodV2(this.prototype, "dirtyType", [cached]);
3714
+ }
3715
+ }
3362
3716
  defineSignal(RecordState.prototype, 'isSaving', false);
3363
3717
  function notifyErrorsStateChanged(state) {
3364
3718
  state.notify('isValid');
3365
3719
  state.notify('isError');
3366
3720
  state.notify('adapterError');
3367
3721
  }
3368
- var _class, _Model;
3369
- // instantiateRecord as well.
3722
+
3723
+ /**
3724
+ @module @ember-data/model
3725
+ */
3726
+
3370
3727
  /*
3371
3728
  * This decorator allows us to lazily compute
3372
3729
  * an expensive getter on first-access and thereafter
@@ -3413,11 +3770,12 @@ function computeOnce(target, propertyName, desc) {
3413
3770
  @public
3414
3771
  @extends Ember.EmberObject
3415
3772
  */
3416
- let Model = (_class = (_Model = class Model extends EmberObject {
3773
+
3774
+ class Model extends EmberObject {
3417
3775
  // set during create by the store
3418
3776
 
3419
3777
  init(options) {
3420
- if (macroCondition(getOwnConfig().env.DEBUG)) {
3778
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3421
3779
  if (!options?._secretInit && !options?._createProps) {
3422
3780
  throw new Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.');
3423
3781
  }
@@ -3431,7 +3789,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3431
3789
  this[RecordStore] = store;
3432
3790
  const identity = _secretInit.identifier;
3433
3791
  _secretInit.cb(this, _secretInit.cache, identity, _secretInit.store);
3434
- this.___recordState = macroCondition(getOwnConfig().env.DEBUG) ? new RecordState(this) : null;
3792
+ this.___recordState = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? new RecordState(this) : null;
3435
3793
  this.setProperties(createProps);
3436
3794
  const notifications = store.notifications;
3437
3795
  this.___private_notifications = notifications.subscribe(identity, (identifier, type, field) => {
@@ -3439,7 +3797,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3439
3797
  });
3440
3798
  }
3441
3799
 
3442
- // @ts-expect-error destroy should not return a value
3800
+ // @ts-expect-error destroy should not return a value, but ember's types force it to
3443
3801
  destroy() {
3444
3802
  const identifier = recordIdentifierFor$1(this);
3445
3803
  this.___recordState?.destroy();
@@ -3490,6 +3848,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3490
3848
  @type {Boolean}
3491
3849
  @readOnly
3492
3850
  */
3851
+ static {
3852
+ decorateMethodV2(this.prototype, "isEmpty", [compat]);
3853
+ }
3493
3854
  get isLoading() {
3494
3855
  return this.currentState.isLoading;
3495
3856
  }
@@ -3512,6 +3873,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3512
3873
  @type {Boolean}
3513
3874
  @readOnly
3514
3875
  */
3876
+ static {
3877
+ decorateMethodV2(this.prototype, "isLoading", [compat]);
3878
+ }
3515
3879
  get isLoaded() {
3516
3880
  return this.currentState.isLoaded;
3517
3881
  }
@@ -3537,6 +3901,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3537
3901
  @type {Boolean}
3538
3902
  @readOnly
3539
3903
  */
3904
+ static {
3905
+ decorateMethodV2(this.prototype, "isLoaded", [compat]);
3906
+ }
3540
3907
  get hasDirtyAttributes() {
3541
3908
  return this.currentState.isDirty;
3542
3909
  }
@@ -3561,6 +3928,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3561
3928
  @type {Boolean}
3562
3929
  @readOnly
3563
3930
  */
3931
+ static {
3932
+ decorateMethodV2(this.prototype, "hasDirtyAttributes", [compat]);
3933
+ }
3564
3934
  get isSaving() {
3565
3935
  return this.currentState.isSaving;
3566
3936
  }
@@ -3597,6 +3967,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3597
3967
  @type {Boolean}
3598
3968
  @readOnly
3599
3969
  */
3970
+ static {
3971
+ decorateMethodV2(this.prototype, "isSaving", [compat]);
3972
+ }
3600
3973
  get isDeleted() {
3601
3974
  return this.currentState.isDeleted;
3602
3975
  }
@@ -3619,6 +3992,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3619
3992
  @type {Boolean}
3620
3993
  @readOnly
3621
3994
  */
3995
+ static {
3996
+ decorateMethodV2(this.prototype, "isDeleted", [compat]);
3997
+ }
3622
3998
  get isNew() {
3623
3999
  return this.currentState.isNew;
3624
4000
  }
@@ -3632,6 +4008,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3632
4008
  @type {Boolean}
3633
4009
  @readOnly
3634
4010
  */
4011
+ static {
4012
+ decorateMethodV2(this.prototype, "isNew", [compat]);
4013
+ }
3635
4014
  get isValid() {
3636
4015
  return this.currentState.isValid;
3637
4016
  }
@@ -3653,6 +4032,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3653
4032
  @type {String}
3654
4033
  @readOnly
3655
4034
  */
4035
+ static {
4036
+ decorateMethodV2(this.prototype, "isValid", [compat]);
4037
+ }
3656
4038
  get dirtyType() {
3657
4039
  return this.currentState.dirtyType;
3658
4040
  }
@@ -3674,11 +4056,17 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3674
4056
  @type {Boolean}
3675
4057
  @readOnly
3676
4058
  */
4059
+ static {
4060
+ decorateMethodV2(this.prototype, "dirtyType", [compat]);
4061
+ }
3677
4062
  get isError() {
3678
4063
  return this.currentState.isError;
3679
4064
  }
4065
+ static {
4066
+ decorateMethodV2(this.prototype, "isError", [compat]);
4067
+ }
3680
4068
  set isError(v) {
3681
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4069
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3682
4070
  throw new Error(`isError is not directly settable`);
3683
4071
  }
3684
4072
  }
@@ -3718,7 +4106,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3718
4106
  // this guard exists, because some dev-only deprecation code
3719
4107
  // (addListener via validatePropertyInjections) invokes toString before the
3720
4108
  // object is real.
3721
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4109
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3722
4110
  try {
3723
4111
  return recordIdentifierFor$1(this).id;
3724
4112
  } catch {
@@ -3727,11 +4115,18 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3727
4115
  }
3728
4116
  return recordIdentifierFor$1(this).id;
3729
4117
  }
4118
+ static {
4119
+ decorateMethodV2(this.prototype, "id", [tagged]);
4120
+ }
3730
4121
  set id(id) {
3731
4122
  const normalizedId = coerceId(id);
3732
4123
  const identifier = recordIdentifierFor$1(this);
3733
4124
  const didChange = normalizedId !== identifier.id;
3734
- assert(`Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`, !didChange || identifier.id === null);
4125
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4126
+ if (!test) {
4127
+ throw new Error(`Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`);
4128
+ }
4129
+ })(!didChange || identifier.id === null) : {};
3735
4130
  if (normalizedId !== null && didChange) {
3736
4131
  this.store._instanceCache.setRecordId(identifier, normalizedId);
3737
4132
  this.store.notifications.notify(identifier, 'identity');
@@ -3753,13 +4148,16 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3753
4148
  // when using legacy/classic ember classes. Basically: lazy in prod and eager in dev.
3754
4149
  // so we do this to try to steer folks to the nicer "dont user currentState"
3755
4150
  // error.
3756
- if (macroCondition(!getOwnConfig().env.DEBUG)) {
4151
+ if (macroCondition(!getGlobalConfig().WarpDrive.env.DEBUG)) {
3757
4152
  if (!this.___recordState) {
3758
4153
  this.___recordState = new RecordState(this);
3759
4154
  }
3760
4155
  }
3761
4156
  return this.___recordState;
3762
4157
  }
4158
+ static {
4159
+ decorateMethodV2(this.prototype, "currentState", [tagged]);
4160
+ }
3763
4161
  set currentState(_v) {
3764
4162
  throw new Error('cannot set currentState');
3765
4163
  }
@@ -3829,9 +4227,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3829
4227
  @public
3830
4228
  @type {AdapterError}
3831
4229
  */
4230
+ static {
4231
+ decorateMethodV2(this.prototype, "errors", [computeOnce]);
4232
+ }
3832
4233
  get adapterError() {
3833
4234
  return this.currentState.adapterError;
3834
4235
  }
4236
+ static {
4237
+ decorateMethodV2(this.prototype, "adapterError", [compat]);
4238
+ }
3835
4239
  set adapterError(v) {
3836
4240
  throw new Error(`adapterError is not directly settable`);
3837
4241
  }
@@ -3848,7 +4252,6 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3848
4252
  @param {Object} options
3849
4253
  @return {Object} an object whose values are primitive JSON values only
3850
4254
  */
3851
-
3852
4255
  /*
3853
4256
  We hook the default implementation to ensure
3854
4257
  our tagged properties are properly notified
@@ -3857,7 +4260,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3857
4260
  to trigger their flush. We wouldn't need to
3858
4261
  super in 4.0+ where sync observers are removed.
3859
4262
  */
3860
- // @ts-expect-error no return is necessary
4263
+ // @ts-expect-error no return is necessary, but Ember's types are forcing it
3861
4264
  notifyPropertyChange(prop) {
3862
4265
  notifySignal(this, prop);
3863
4266
  super.notifyPropertyChange(prop);
@@ -3986,7 +4389,6 @@ let Model = (_class = (_Model = class Model extends EmberObject {
3986
4389
  @method _createSnapshot
3987
4390
  @private
3988
4391
  */
3989
-
3990
4392
  // TODO @deprecate in favor of a public API or examples of how to test successfully
3991
4393
 
3992
4394
  /**
@@ -4046,7 +4448,11 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4046
4448
  */
4047
4449
 
4048
4450
  attr() {
4049
- assert('The `attr` method is not available on Model, a Snapshot was probably expected. Are you passing a Model instead of a Snapshot to your serializer?', false);
4451
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4452
+ {
4453
+ throw new Error('The `attr` method is not available on Model, a Snapshot was probably expected. Are you passing a Model instead of a Snapshot to your serializer?');
4454
+ }
4455
+ })() : {};
4050
4456
  }
4051
4457
 
4052
4458
  /**
@@ -4179,6 +4585,45 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4179
4585
  eachAttribute(callback, binding) {
4180
4586
  this.constructor.eachAttribute(callback, binding);
4181
4587
  }
4588
+ static isModel = true;
4589
+
4590
+ /**
4591
+ Create should only ever be called by the store. To create an instance of a
4592
+ `Model` in a dirty state use `store.createRecord`.
4593
+ To create instances of `Model` in a clean state, use `store.push`
4594
+ @method create
4595
+ @private
4596
+ @static
4597
+ */
4598
+
4599
+ /**
4600
+ Represents the model's class name as a string. This can be used to look up the model's class name through
4601
+ `Store`'s modelFor method.
4602
+ `modelName` is generated for you by EmberData. It will be a lowercased, dasherized string.
4603
+ For example:
4604
+ ```javascript
4605
+ store.modelFor('post').modelName; // 'post'
4606
+ store.modelFor('blog-post').modelName; // 'blog-post'
4607
+ ```
4608
+ The most common place you'll want to access `modelName` is in your serializer's `payloadKeyFromModelName` method. For example, to change payload
4609
+ keys to underscore (instead of dasherized), you might use the following code:
4610
+ ```javascript
4611
+ import RESTSerializer from '@ember-data/serializer/rest';
4612
+ import { underscore } from '<app-name>/utils/string-utils';
4613
+ export default const PostSerializer = RESTSerializer.extend({
4614
+ payloadKeyFromModelName(modelName) {
4615
+ return underscore(modelName);
4616
+ }
4617
+ });
4618
+ ```
4619
+ @property modelName
4620
+ @public
4621
+ @type String
4622
+ @readonly
4623
+ @static
4624
+ */
4625
+ static modelName = null;
4626
+
4182
4627
  /*
4183
4628
  These class methods below provide relationship
4184
4629
  introspection abilities about relationships.
@@ -4211,12 +4656,20 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4211
4656
  @return {Model} the type of the relationship, or undefined
4212
4657
  */
4213
4658
  static typeForRelationship(name, store) {
4214
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4659
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4660
+ if (!test) {
4661
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4662
+ }
4663
+ })(this.modelName) : {};
4215
4664
  const relationship = this.relationshipsByName.get(name);
4216
4665
  return relationship && store.modelFor(relationship.type);
4217
4666
  }
4218
4667
  static get inverseMap() {
4219
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4668
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4669
+ if (!test) {
4670
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4671
+ }
4672
+ })(this.modelName) : {};
4220
4673
  return Object.create(null);
4221
4674
  }
4222
4675
 
@@ -4246,8 +4699,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4246
4699
  @param {Store} store
4247
4700
  @return {Object} the inverse relationship, or null
4248
4701
  */
4702
+ static {
4703
+ decorateMethodV2(this, "inverseMap", [computeOnce]);
4704
+ }
4249
4705
  static inverseFor(name, store) {
4250
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4706
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4707
+ if (!test) {
4708
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4709
+ }
4710
+ })(this.modelName) : {};
4251
4711
  const inverseMap = this.inverseMap;
4252
4712
  if (inverseMap[name]) {
4253
4713
  return inverseMap[name];
@@ -4260,30 +4720,47 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4260
4720
 
4261
4721
  //Calculate the inverse, ignoring the cache
4262
4722
  static _findInverseFor(name, store) {
4263
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4723
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4724
+ if (!test) {
4725
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4726
+ }
4727
+ })(this.modelName) : {};
4264
4728
  const relationship = this.relationshipsByName.get(name);
4265
- assert(`No relationship named '${name}' on '${this.modelName}' exists.`, relationship);
4729
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4730
+ if (!test) {
4731
+ throw new Error(`No relationship named '${name}' on '${this.modelName}' exists.`);
4732
+ }
4733
+ })(relationship) : {};
4266
4734
  if (!relationship) {
4267
4735
  return null;
4268
4736
  }
4269
4737
  const {
4270
4738
  options
4271
4739
  } = relationship;
4272
- assert(`Expected the relationship ${name} on ${this.modelName} to define an inverse.`, options.inverse === null || typeof options.inverse === 'string' && options.inverse.length > 0);
4740
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4741
+ if (!test) {
4742
+ throw new Error(`Expected the relationship ${name} on ${this.modelName} to define an inverse.`);
4743
+ }
4744
+ })(options.inverse === null || typeof options.inverse === 'string' && options.inverse.length > 0) : {};
4273
4745
  if (options.inverse === null) {
4274
4746
  return null;
4275
4747
  }
4276
- const schemaExists = store.schema.doesTypeExist(relationship.type);
4277
- assert(`No associated schema found for '${relationship.type}' while calculating the inverse of ${name} on ${this.modelName}`, schemaExists);
4748
+ const schemaExists = store.schema.hasResource(relationship);
4749
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4750
+ if (!test) {
4751
+ throw new Error(`No associated schema found for '${relationship.type}' while calculating the inverse of ${name} on ${this.modelName}`);
4752
+ }
4753
+ })(schemaExists) : {};
4278
4754
  if (!schemaExists) {
4279
4755
  return null;
4280
4756
  }
4281
- const inverseSchemas = store.schema.relationshipsDefinitionFor({
4282
- type: relationship.type
4283
- });
4284
- const inverseSchema = inverseSchemas[options.inverse];
4285
- assert(`No inverse relationship found for '${name}' on '${this.modelName}'`, inverseSchema !== undefined);
4286
- return inverseSchema || null;
4757
+ const inverseField = store.schema.fields(relationship).get(options.inverse);
4758
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4759
+ if (!test) {
4760
+ throw new Error(`No inverse relationship found for '${name}' on '${this.modelName}'`);
4761
+ }
4762
+ })(inverseField && (inverseField.kind === 'belongsTo' || inverseField.kind === 'hasMany')) : {};
4763
+ return inverseField || null;
4287
4764
  }
4288
4765
 
4289
4766
  /**
@@ -4321,7 +4798,11 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4321
4798
  */
4322
4799
 
4323
4800
  static get relationships() {
4324
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4801
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4802
+ if (!test) {
4803
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4804
+ }
4805
+ })(this.modelName) : {};
4325
4806
  const map = new Map();
4326
4807
  const relationshipsByName = this.relationshipsByName;
4327
4808
 
@@ -4365,8 +4846,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4365
4846
  @type Object
4366
4847
  @readOnly
4367
4848
  */
4849
+ static {
4850
+ decorateMethodV2(this, "relationships", [computeOnce]);
4851
+ }
4368
4852
  static get relationshipNames() {
4369
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4853
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4854
+ if (!test) {
4855
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4856
+ }
4857
+ })(this.modelName) : {};
4370
4858
  const names = {
4371
4859
  hasMany: [],
4372
4860
  belongsTo: []
@@ -4404,8 +4892,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4404
4892
  @type Array
4405
4893
  @readOnly
4406
4894
  */
4895
+ static {
4896
+ decorateMethodV2(this, "relationshipNames", [computeOnce]);
4897
+ }
4407
4898
  static get relatedTypes() {
4408
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4899
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4900
+ if (!test) {
4901
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4902
+ }
4903
+ })(this.modelName) : {};
4409
4904
  const types = [];
4410
4905
  const rels = this.relationshipsObject;
4411
4906
  const relationships = Object.keys(rels);
@@ -4451,8 +4946,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4451
4946
  @type Map
4452
4947
  @readOnly
4453
4948
  */
4949
+ static {
4950
+ decorateMethodV2(this, "relatedTypes", [computeOnce]);
4951
+ }
4454
4952
  static get relationshipsByName() {
4455
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4953
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4954
+ if (!test) {
4955
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4956
+ }
4957
+ })(this.modelName) : {};
4456
4958
  const map = new Map();
4457
4959
  const rels = this.relationshipsObject;
4458
4960
  const relationships = Object.keys(rels);
@@ -4463,8 +4965,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4463
4965
  }
4464
4966
  return map;
4465
4967
  }
4968
+ static {
4969
+ decorateMethodV2(this, "relationshipsByName", [computeOnce]);
4970
+ }
4466
4971
  static get relationshipsObject() {
4467
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
4972
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4973
+ if (!test) {
4974
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
4975
+ }
4976
+ })(this.modelName) : {};
4468
4977
  const relationships = Object.create(null);
4469
4978
  const modelName = this.modelName;
4470
4979
  this.eachComputedProperty((name, meta) => {
@@ -4474,10 +4983,17 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4474
4983
  // TODO deprecate key being here
4475
4984
  meta.key = name;
4476
4985
  meta.name = name;
4477
- meta.parentModelName = modelName;
4478
4986
  relationships[name] = meta;
4479
- assert(`Expected options in meta`, meta.options && typeof meta.options === 'object');
4480
- assert(`You should not specify both options.as and options.inverse as null on ${modelName}.${meta.name}, as if there is no inverse field there is no abstract type to conform to. You may have intended for this relationship to be polymorphic, or you may have mistakenly set inverse to null.`, !(meta.options.inverse === null && meta.options.as?.length));
4987
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4988
+ if (!test) {
4989
+ throw new Error(`Expected options in meta`);
4990
+ }
4991
+ })(meta.options && typeof meta.options === 'object') : {};
4992
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
4993
+ if (!test) {
4994
+ throw new Error(`You should not specify both options.as and options.inverse as null on ${modelName}.${meta.name}, as if there is no inverse field there is no abstract type to conform to. You may have intended for this relationship to be polymorphic, or you may have mistakenly set inverse to null.`);
4995
+ }
4996
+ })(!(meta.options.inverse === null && meta.options.as?.length)) : {};
4481
4997
  });
4482
4998
  return relationships;
4483
4999
  }
@@ -4514,8 +5030,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4514
5030
  @type Map
4515
5031
  @readOnly
4516
5032
  */
5033
+ static {
5034
+ decorateMethodV2(this, "relationshipsObject", [computeOnce]);
5035
+ }
4517
5036
  static get fields() {
4518
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5037
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5038
+ if (!test) {
5039
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5040
+ }
5041
+ })(this.modelName) : {};
4519
5042
  const map = new Map();
4520
5043
  this.eachComputedProperty((name, meta) => {
4521
5044
  if (isRelationshipSchema(meta)) {
@@ -4537,8 +5060,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4537
5060
  @param {Function} callback the callback to invoke
4538
5061
  @param {any} binding the value to which the callback's `this` should be bound
4539
5062
  */
5063
+ static {
5064
+ decorateMethodV2(this, "fields", [computeOnce]);
5065
+ }
4540
5066
  static eachRelationship(callback, binding) {
4541
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5067
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5068
+ if (!test) {
5069
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5070
+ }
5071
+ })(this.modelName) : {};
4542
5072
  this.relationshipsByName.forEach((relationship, name) => {
4543
5073
  callback.call(binding, name, relationship);
4544
5074
  });
@@ -4556,7 +5086,11 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4556
5086
  @param {any} binding the value to which the callback's `this` should be bound
4557
5087
  */
4558
5088
  static eachRelatedType(callback, binding) {
4559
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5089
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5090
+ if (!test) {
5091
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5092
+ }
5093
+ })(this.modelName) : {};
4560
5094
  const relationshipTypes = this.relatedTypes;
4561
5095
  for (let i = 0; i < relationshipTypes.length; i++) {
4562
5096
  const type = relationshipTypes[i];
@@ -4571,7 +5105,11 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4571
5105
  * @deprecated
4572
5106
  */
4573
5107
  static determineRelationshipType(knownSide, store) {
4574
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5108
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5109
+ if (!test) {
5110
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5111
+ }
5112
+ })(this.modelName) : {};
4575
5113
  const knownKey = knownSide.name;
4576
5114
  const knownKind = knownSide.kind;
4577
5115
  const inverse = this.inverseFor(knownKey, store);
@@ -4621,11 +5159,19 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4621
5159
  @readOnly
4622
5160
  */
4623
5161
  static get attributes() {
4624
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5162
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5163
+ if (!test) {
5164
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5165
+ }
5166
+ })(this.modelName) : {};
4625
5167
  const map = new Map();
4626
5168
  this.eachComputedProperty((name, meta) => {
4627
5169
  if (isAttributeSchema(meta)) {
4628
- assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString(), name !== 'id');
5170
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5171
+ if (!test) {
5172
+ throw new Error("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString());
5173
+ }
5174
+ })(name !== 'id') : {};
4629
5175
 
4630
5176
  // TODO deprecate key being here
4631
5177
  meta.key = name;
@@ -4666,8 +5212,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4666
5212
  @type {Map}
4667
5213
  @readOnly
4668
5214
  */
5215
+ static {
5216
+ decorateMethodV2(this, "attributes", [computeOnce]);
5217
+ }
4669
5218
  static get transformedAttributes() {
4670
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5219
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5220
+ if (!test) {
5221
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5222
+ }
5223
+ })(this.modelName) : {};
4671
5224
  const map = new Map();
4672
5225
  this.eachAttribute((name, meta) => {
4673
5226
  if (meta.type) {
@@ -4711,8 +5264,15 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4711
5264
  @param {Object} [binding] the value to which the callback's `this` should be bound
4712
5265
  @static
4713
5266
  */
5267
+ static {
5268
+ decorateMethodV2(this, "transformedAttributes", [computeOnce]);
5269
+ }
4714
5270
  static eachAttribute(callback, binding) {
4715
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5271
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5272
+ if (!test) {
5273
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5274
+ }
5275
+ })(this.modelName) : {};
4716
5276
  this.attributes.forEach((meta, name) => {
4717
5277
  callback.call(binding, name, meta);
4718
5278
  });
@@ -4754,7 +5314,11 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4754
5314
  @static
4755
5315
  */
4756
5316
  static eachTransformedAttribute(callback, binding) {
4757
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5317
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5318
+ if (!test) {
5319
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5320
+ }
5321
+ })(this.modelName) : {};
4758
5322
  this.transformedAttributes.forEach((type, name) => {
4759
5323
  callback.call(binding, name, type);
4760
5324
  });
@@ -4767,11 +5331,18 @@ let Model = (_class = (_Model = class Model extends EmberObject {
4767
5331
  @static
4768
5332
  */
4769
5333
  static toString() {
4770
- assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
5334
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5335
+ if (!test) {
5336
+ throw new Error(`Accessing schema information on Models without looking up the model via the store is disallowed.`);
5337
+ }
5338
+ })(this.modelName) : {};
4771
5339
  return `model:${this.modelName}`;
4772
5340
  }
4773
- }, _Model.isModel = true, _Model.modelName = null, _Model), (_applyDecoratedDescriptor(_class.prototype, "isEmpty", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isEmpty"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isLoading", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isLoading"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isLoaded", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isLoaded"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "hasDirtyAttributes", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "hasDirtyAttributes"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isSaving", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isSaving"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isDeleted", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isDeleted"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isNew", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isNew"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isValid", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isValid"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "dirtyType", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "dirtyType"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "isError", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "isError"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "id", [tagged], Object.getOwnPropertyDescriptor(_class.prototype, "id"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "currentState", [tagged], Object.getOwnPropertyDescriptor(_class.prototype, "currentState"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "errors", [computeOnce], Object.getOwnPropertyDescriptor(_class.prototype, "errors"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "adapterError", [compat], Object.getOwnPropertyDescriptor(_class.prototype, "adapterError"), _class.prototype), _applyDecoratedDescriptor(_class, "inverseMap", [computeOnce], Object.getOwnPropertyDescriptor(_class, "inverseMap"), _class), _applyDecoratedDescriptor(_class, "relationships", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationships"), _class), _applyDecoratedDescriptor(_class, "relationshipNames", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipNames"), _class), _applyDecoratedDescriptor(_class, "relatedTypes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relatedTypes"), _class), _applyDecoratedDescriptor(_class, "relationshipsByName", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipsByName"), _class), _applyDecoratedDescriptor(_class, "relationshipsObject", [computeOnce], Object.getOwnPropertyDescriptor(_class, "relationshipsObject"), _class), _applyDecoratedDescriptor(_class, "fields", [computeOnce], Object.getOwnPropertyDescriptor(_class, "fields"), _class), _applyDecoratedDescriptor(_class, "attributes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "attributes"), _class), _applyDecoratedDescriptor(_class, "transformedAttributes", [computeOnce], Object.getOwnPropertyDescriptor(_class, "transformedAttributes"), _class)), _class);
5341
+ }
5342
+
5343
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
4774
5344
  Model.prototype.save = save;
5345
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
4775
5346
  Model.prototype.destroyRecord = destroyRecord;
4776
5347
  Model.prototype.unloadRecord = unloadRecord;
4777
5348
  Model.prototype.hasMany = hasMany;
@@ -4788,7 +5359,7 @@ defineSignal(Model.prototype, 'isReloading', false);
4788
5359
  // the values initialized during create to `setUnknownProperty`
4789
5360
  Model.prototype._createProps = null;
4790
5361
  Model.prototype._secretInit = null;
4791
- if (macroCondition(getOwnConfig().env.DEBUG)) {
5362
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4792
5363
  const lookupDescriptor = function lookupDescriptor(obj, keyName) {
4793
5364
  let current = obj;
4794
5365
  do {
@@ -4833,4 +5404,4 @@ function isRelationshipSchema(meta) {
4833
5404
  function isAttributeSchema(meta) {
4834
5405
  return typeof meta === 'object' && meta !== null && 'kind' in meta && meta.kind === 'attribute';
4835
5406
  }
4836
- export { Errors as E, LEGACY_SUPPORT as L, Model as M, PromiseBelongsTo as P, RelatedCollection as R, PromiseManyArray as a, save as b, reload as c, destroyRecord as d, deleteRecord as e, RecordState as f, changedAttributes as g, hasMany as h, belongsTo as i, createSnapshot as j, lookupLegacySupport as l, rollbackAttributes as r, serialize as s, unloadRecord as u };
5407
+ export { Errors as E, LEGACY_SUPPORT as L, Model as M, PromiseBelongsTo as P, RelatedCollection as R, PromiseManyArray as a, save as b, reload as c, destroyRecord as d, deleteRecord as e, RecordState as f, changedAttributes as g, hasMany as h, belongsTo as i, createSnapshot as j, isElementDescriptor as k, lookupLegacySupport as l, normalizeModelName as n, rollbackAttributes as r, serialize as s, unloadRecord as u };