@ember-data/model 5.4.0-beta.3 → 5.4.0-beta.5

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 (92) hide show
  1. package/README.md +19 -0
  2. package/addon-main.cjs +5 -0
  3. package/blueprints/model/index.js +18 -5
  4. package/blueprints/model-test/index.js +16 -10
  5. package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +4 -5
  6. package/{addon → dist}/-private.js +2 -2
  7. package/dist/has-many-78F2FHCC.js +674 -0
  8. package/dist/has-many-78F2FHCC.js.map +1 -0
  9. package/dist/hooks-BgrTI_ff.js +75 -0
  10. package/dist/hooks-BgrTI_ff.js.map +1 -0
  11. package/dist/hooks.js +2 -0
  12. package/{addon → dist}/hooks.js.map +1 -1
  13. package/dist/index.js +4 -0
  14. package/{addon → dist}/index.js.map +1 -1
  15. package/dist/migration-support.js +210 -0
  16. package/dist/migration-support.js.map +1 -0
  17. package/{addon/model-YsOraZ6y.js → dist/model-BFnMMaye.js} +889 -424
  18. package/dist/model-BFnMMaye.js.map +1 -0
  19. package/dist/schema-provider-Cgpcwfn7.js +256 -0
  20. package/dist/schema-provider-Cgpcwfn7.js.map +1 -0
  21. package/ember-data-logo-dark.svg +12 -0
  22. package/ember-data-logo-light.svg +12 -0
  23. package/package.json +48 -75
  24. package/unstable-preview-types/-private/attr.d.ts +174 -0
  25. package/unstable-preview-types/-private/attr.d.ts.map +1 -0
  26. package/unstable-preview-types/-private/attr.type-test.d.ts +4 -0
  27. package/unstable-preview-types/-private/attr.type-test.d.ts.map +1 -0
  28. package/unstable-preview-types/-private/belongs-to.d.ts +180 -0
  29. package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -0
  30. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -0
  31. package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +1 -0
  32. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -0
  33. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  34. package/unstable-preview-types/-private/errors.d.ts +305 -0
  35. package/unstable-preview-types/-private/errors.d.ts.map +1 -0
  36. package/unstable-preview-types/-private/has-many.d.ts +169 -0
  37. package/unstable-preview-types/-private/has-many.d.ts.map +1 -0
  38. package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -0
  39. package/unstable-preview-types/-private/has-many.type-test.d.ts.map +1 -0
  40. package/unstable-preview-types/-private/hooks.d.ts +13 -0
  41. package/unstable-preview-types/-private/hooks.d.ts.map +1 -0
  42. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +60 -0
  43. package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -0
  44. package/unstable-preview-types/-private/many-array.d.ts +196 -0
  45. package/unstable-preview-types/-private/many-array.d.ts.map +1 -0
  46. package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -0
  47. package/unstable-preview-types/-private/model-for-mixin.d.ts.map +1 -0
  48. package/unstable-preview-types/-private/model-methods.d.ts +37 -0
  49. package/unstable-preview-types/-private/model-methods.d.ts.map +1 -0
  50. package/unstable-preview-types/-private/model.d.ts +1306 -0
  51. package/unstable-preview-types/-private/model.d.ts.map +1 -0
  52. package/unstable-preview-types/-private/model.type-test.d.ts +4 -0
  53. package/unstable-preview-types/-private/model.type-test.d.ts.map +1 -0
  54. package/unstable-preview-types/-private/notify-changes.d.ts +8 -0
  55. package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -0
  56. package/unstable-preview-types/-private/promise-belongs-to.d.ts +48 -0
  57. package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -0
  58. package/unstable-preview-types/-private/promise-many-array.d.ts +131 -0
  59. package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -0
  60. package/unstable-preview-types/-private/record-state.d.ts +90 -0
  61. package/unstable-preview-types/-private/record-state.d.ts.map +1 -0
  62. package/unstable-preview-types/-private/references/belongs-to.d.ts +503 -0
  63. package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -0
  64. package/unstable-preview-types/-private/references/has-many.d.ts +515 -0
  65. package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -0
  66. package/unstable-preview-types/-private/schema-provider.d.ts +64 -0
  67. package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -0
  68. package/unstable-preview-types/-private/type-utils.d.ts +64 -0
  69. package/unstable-preview-types/-private/type-utils.d.ts.map +1 -0
  70. package/unstable-preview-types/-private/util.d.ts +11 -0
  71. package/unstable-preview-types/-private/util.d.ts.map +1 -0
  72. package/unstable-preview-types/-private.d.ts +13 -0
  73. package/unstable-preview-types/-private.d.ts.map +1 -0
  74. package/unstable-preview-types/hooks.d.ts +5 -0
  75. package/unstable-preview-types/hooks.d.ts.map +1 -0
  76. package/unstable-preview-types/index.d.ts +76 -0
  77. package/unstable-preview-types/index.d.ts.map +1 -0
  78. package/unstable-preview-types/migration-support.d.ts +56 -0
  79. package/unstable-preview-types/migration-support.d.ts.map +1 -0
  80. package/addon/has-many-PdQBns8a.js +0 -323
  81. package/addon/has-many-PdQBns8a.js.map +0 -1
  82. package/addon/hooks-dXmQbIOF.js +0 -176
  83. package/addon/hooks-dXmQbIOF.js.map +0 -1
  84. package/addon/hooks.js +0 -1
  85. package/addon/index.js +0 -3
  86. package/addon/migration-support.js +0 -118
  87. package/addon/migration-support.js.map +0 -1
  88. package/addon/model-YsOraZ6y.js.map +0 -1
  89. package/addon/util-3DHZJC9h.js +0 -38
  90. package/addon/util-3DHZJC9h.js.map +0 -1
  91. package/addon-main.js +0 -93
  92. /package/{addon → dist}/-private.js.map +0 -0
@@ -1,18 +1,51 @@
1
- import { assert, deprecate, warn } from '@ember/debug';
1
+ import { deprecate } from '@ember/debug';
2
+ import { dasherize } from '@ember-data/request-utils/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,22 +339,25 @@ 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
 
321
355
  /**
322
356
  Reloads all of the records in the manyArray. If the manyArray
323
357
  holds a relationship that was originally fetched using a links url
324
- Ember Data will revisit the original links url to repopulate the
358
+ EmberData will revisit the original links url to repopulate the
325
359
  relationship.
326
- If the manyArray holds the result of a `store.query()` reload will
360
+ If the ManyArray holds the result of a `store.query()` reload will
327
361
  re-run the original query.
328
362
  Example
329
363
  ```javascript
@@ -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,33 +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
+ }
629
+ const LegacyPromiseProxy = Symbol.for('LegacyPromiseProxy');
492
630
 
493
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
631
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-extraneous-class
494
632
 
495
633
  const Extended = PromiseObject;
496
634
 
@@ -507,7 +645,7 @@ const Extended = PromiseObject;
507
645
  @extends PromiseObject
508
646
  @private
509
647
  */
510
- let PromiseBelongsTo = (_dec$1 = computed(), (_class$6 = class PromiseBelongsTo extends Extended {
648
+ class PromiseBelongsTo extends Extended {
511
649
  get id() {
512
650
  const {
513
651
  key,
@@ -520,15 +658,29 @@ let PromiseBelongsTo = (_dec$1 = computed(), (_class$6 = class PromiseBelongsTo
520
658
  // we don't proxy meta because we would need to proxy it to the relationship state container
521
659
  // however, meta on relationships does not trigger change notifications.
522
660
  // if you need relationship meta, you should do `record.belongsTo(relationshipName).meta()`
661
+ static {
662
+ decorateMethodV2(this.prototype, "id", [cached]);
663
+ }
523
664
  get meta() {
524
665
  // eslint-disable-next-line no-constant-condition
525
666
  {
526
- 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
+ })() : {};
527
672
  }
528
673
  return;
529
674
  }
675
+ static {
676
+ decorateMethodV2(this.prototype, "meta", [computed()]);
677
+ }
530
678
  async reload(options) {
531
- 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) : {};
532
684
  const {
533
685
  key,
534
686
  legacySupport
@@ -536,8 +688,9 @@ let PromiseBelongsTo = (_dec$1 = computed(), (_class$6 = class PromiseBelongsTo
536
688
  await legacySupport.reloadBelongsTo(key, options);
537
689
  return this;
538
690
  }
539
- }, (_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));
540
- var _class$5;
691
+ [LegacyPromiseProxy] = true;
692
+ }
693
+
541
694
  /**
542
695
  @module @ember-data/model
543
696
  */
@@ -557,14 +710,12 @@ var _class$5;
557
710
  @class PromiseManyArray
558
711
  @public
559
712
  */
560
- let PromiseManyArray = (_class$5 = class PromiseManyArray {
713
+ class PromiseManyArray {
561
714
  constructor(promise, content) {
562
715
  this._update(promise, content);
563
716
  this.isDestroyed = false;
564
717
  }
565
718
 
566
- //---- Methods/Properties on ArrayProxy that we will keep as our API
567
-
568
719
  /**
569
720
  * Retrieve the length of the content
570
721
  * @property length
@@ -573,7 +724,7 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
573
724
  get length() {
574
725
  // shouldn't be needed, but ends up being needed
575
726
  // for computed chains even in 4.x
576
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
727
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
577
728
  this['[]'];
578
729
  }
579
730
  return this.content ? this.content.length : 0;
@@ -589,6 +740,9 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
589
740
  * @return
590
741
  * @private
591
742
  */
743
+ static {
744
+ decorateMethodV2(this.prototype, "length", [compat]);
745
+ }
592
746
  forEach(cb) {
593
747
  if (this.content && this.length) {
594
748
  this.content.forEach(cb);
@@ -603,7 +757,11 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
603
757
  * @return
604
758
  */
605
759
  reload(options) {
606
- 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) : {};
607
765
  void this.content.reload(options);
608
766
  return this;
609
767
  }
@@ -698,12 +856,17 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
698
856
  * @property meta
699
857
  * @public
700
858
  */
859
+ static {
860
+ decorateMethodV2(this.prototype, "links", [compat]);
861
+ }
701
862
  get meta() {
702
863
  return this.content ? this.content.meta : undefined;
703
864
  }
704
865
 
705
866
  //---- Our own stuff
706
-
867
+ static {
868
+ decorateMethodV2(this.prototype, "meta", [compat]);
869
+ }
707
870
  _update(promise, content) {
708
871
  if (content !== undefined) {
709
872
  this.content = content;
@@ -716,7 +879,8 @@ let PromiseManyArray = (_class$5 = class PromiseManyArray {
716
879
  }) {
717
880
  return new this(promise, content);
718
881
  }
719
- }, (_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
+ }
720
884
  defineSignal(PromiseManyArray.prototype, 'content', null);
721
885
  defineSignal(PromiseManyArray.prototype, 'isPending', false);
722
886
  defineSignal(PromiseManyArray.prototype, 'isRejected', false);
@@ -727,7 +891,7 @@ defineSignal(PromiseManyArray.prototype, 'isSettled', false);
727
891
  // A(identifierArray) since it is not configurable
728
892
  // which is preferrable to the `meta` override we used
729
893
  // before which required importing all of Ember
730
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_COMPUTED_CHAINS)) {
894
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
731
895
  const desc = {
732
896
  enumerable: true,
733
897
  configurable: false,
@@ -777,21 +941,27 @@ function tapPromise(proxy, promise) {
777
941
  `record.relationshipFor(key)`.
778
942
  */
779
943
  let assertPolymorphicType;
780
- if (macroCondition(getOwnConfig().env.DEBUG)) {
944
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
945
+ // eslint-disable-next-line @typescript-eslint/no-shadow
781
946
  assertPolymorphicType = function assertPolymorphicType(parentIdentifier, parentDefinition, addedIdentifier, store) {
782
947
  if (parentDefinition.inverseIsImplicit) {
783
948
  return;
784
949
  }
785
950
  if (parentDefinition.isPolymorphic) {
786
- let meta = store.getSchemaDefinitionService().relationshipsDefinitionFor(addedIdentifier)[parentDefinition.inverseKey];
787
- 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) : {};
788
962
  }
789
963
  };
790
964
  }
791
- var _class$4;
792
- /**
793
- @module @ember-data/model
794
- */
795
965
  function isResourceIdentiferWithRelatedLinks$1(value) {
796
966
  return Boolean(value && value.links && value.links.related);
797
967
  }
@@ -823,24 +993,26 @@ function isResourceIdentiferWithRelatedLinks$1(value) {
823
993
  @class HasManyReference
824
994
  @public
825
995
  */
826
- 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;
827
1015
  constructor(store, graph, parentIdentifier, hasManyRelationship, key) {
828
- /**
829
- * The field name on the parent record for this has-many relationship.
830
- *
831
- * @property {String} key
832
- * @public
833
- */
834
- /**
835
- * The type of resource this relationship will contain.
836
- *
837
- * @property {String} type
838
- * @public
839
- */
840
- // unsubscribe tokens given to us by the notification manager
841
- this.___token = void 0;
842
- this.___identifier = void 0;
843
- this.___relatedTokenMap = void 0;
844
1016
  this.graph = graph;
845
1017
  this.key = key;
846
1018
  this.hasManyRelationship = hasManyRelationship;
@@ -904,6 +1076,9 @@ let HasManyReference = (_class$4 = class HasManyReference {
904
1076
  map.clear();
905
1077
  return [];
906
1078
  }
1079
+ static {
1080
+ decorateMethodV2(this.prototype, "identifiers", [compat, cached]);
1081
+ }
907
1082
  _resource() {
908
1083
  const cache = this.store.cache;
909
1084
  return cache.getRelationship(this.___identifier, this.key);
@@ -1173,12 +1348,16 @@ let HasManyReference = (_class$4 = class HasManyReference {
1173
1348
  const isResourceData = Array.isArray(dataDoc.data) && dataDoc.data.length > 0 && isMaybeResource(dataDoc.data[0]);
1174
1349
 
1175
1350
  // enforce that one of links, meta or data is present
1176
- 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) : {};
1177
1356
  const identifiers = !Array.isArray(dataDoc.data) ? [] : isResourceData ? store._push(dataDoc, true) : dataDoc.data.map(i => store.identifierCache.getOrCreateRecordIdentifier(i));
1178
1357
  const {
1179
1358
  identifier
1180
1359
  } = this.hasManyRelationship;
1181
- if (macroCondition(getOwnConfig().env.DEBUG)) {
1360
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1182
1361
  const relationshipMeta = this.hasManyRelationship.definition;
1183
1362
  identifiers.forEach(added => {
1184
1363
  assertPolymorphicType(identifier, relationshipMeta, added, store);
@@ -1368,13 +1547,12 @@ let HasManyReference = (_class$4 = class HasManyReference {
1368
1547
  const support = LEGACY_SUPPORT.get(this.___identifier);
1369
1548
  return support.reloadHasMany(this.key, options);
1370
1549
  }
1371
- }, _applyDecoratedDescriptor(_class$4.prototype, "identifiers", [cached, compat], Object.getOwnPropertyDescriptor(_class$4.prototype, "identifiers"), _class$4.prototype), _class$4);
1550
+ }
1372
1551
  defineSignal(HasManyReference.prototype, '_ref', 0);
1373
1552
  function isMaybeResource(object) {
1374
1553
  const keys = Object.keys(object).filter(k => k !== 'id' && k !== 'type' && k !== 'lid');
1375
1554
  return keys.length > 0;
1376
1555
  }
1377
- var _class$3;
1378
1556
  function isResourceIdentiferWithRelatedLinks(value) {
1379
1557
  return Boolean(value && value.links && value.links.related);
1380
1558
  }
@@ -1407,7 +1585,7 @@ function isResourceIdentiferWithRelatedLinks(value) {
1407
1585
  @class BelongsToReference
1408
1586
  @public
1409
1587
  */
1410
- let BelongsToReference = (_class$3 = class BelongsToReference {
1588
+ class BelongsToReference {
1411
1589
  /**
1412
1590
  * The field name on the parent record for this has-many relationship.
1413
1591
  *
@@ -1510,6 +1688,9 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1510
1688
  @public
1511
1689
  @return {String} The id of the record in this belongsTo relationship.
1512
1690
  */
1691
+ static {
1692
+ decorateMethodV2(this.prototype, "identifier", [compat, cached]);
1693
+ }
1513
1694
  id() {
1514
1695
  return this.identifier?.id || null;
1515
1696
  }
@@ -1737,7 +1918,7 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1737
1918
  @public
1738
1919
  @param {Object} doc a JSONAPI document object describing the new value of this relationship.
1739
1920
  @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
1740
- @return {Promise<RecordInstance | null | void>}
1921
+ @return {Promise<OpaqueRecordInstance | null | void>}
1741
1922
  */
1742
1923
  async push(doc, skipFetch) {
1743
1924
  const {
@@ -1748,7 +1929,7 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1748
1929
  const {
1749
1930
  identifier
1750
1931
  } = this.belongsToRelationship;
1751
- if (macroCondition(getOwnConfig().env.DEBUG)) {
1932
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
1752
1933
  if (added) {
1753
1934
  assertPolymorphicType(identifier, this.belongsToRelationship.definition, added, store);
1754
1935
  }
@@ -1929,15 +2110,23 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1929
2110
  const support = LEGACY_SUPPORT.get(this.___identifier);
1930
2111
  return support.reloadBelongsTo(this.key, options).then(() => this.value());
1931
2112
  }
1932
- }, _applyDecoratedDescriptor(_class$3.prototype, "identifier", [cached, compat], Object.getOwnPropertyDescriptor(_class$3.prototype, "identifier"), _class$3.prototype), _class$3);
2113
+ }
1933
2114
  defineSignal(BelongsToReference.prototype, '_ref', 0);
1934
- const LEGACY_SUPPORT = new Map();
2115
+ const LEGACY_SUPPORT = getOrSetGlobal('LEGACY_SUPPORT', new Map());
1935
2116
  function lookupLegacySupport(record) {
1936
2117
  const identifier = recordIdentifierFor(record);
1937
- 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) : {};
1938
2123
  let support = LEGACY_SUPPORT.get(identifier);
1939
2124
  if (!support) {
1940
- 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) : {};
1941
2130
  support = new LegacySupport(record);
1942
2131
  LEGACY_SUPPORT.set(identifier, support);
1943
2132
  LEGACY_SUPPORT.set(record, support);
@@ -1950,7 +2139,7 @@ class LegacySupport {
1950
2139
  this.store = storeFor(record);
1951
2140
  this.identifier = recordIdentifierFor(record);
1952
2141
  this.cache = peekCache(record);
1953
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2142
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
1954
2143
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
1955
2144
  this.graph = graphFor(this.store);
1956
2145
  }
@@ -1991,7 +2180,11 @@ class LegacySupport {
1991
2180
  return loadingPromise;
1992
2181
  }
1993
2182
  const relationship = this.graph.get(this.identifier, key);
1994
- 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)) : {};
1995
2188
  const resource = this.cache.getRelationship(this.identifier, key);
1996
2189
  relationship.state.hasFailedLoadAttempt = false;
1997
2190
  relationship.state.shouldForceReload = true;
@@ -2011,10 +2204,18 @@ class LegacySupport {
2011
2204
  } = this;
2012
2205
  const resource = cache.getRelationship(this.identifier, key);
2013
2206
  const relatedIdentifier = resource && resource.data ? resource.data : null;
2014
- 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)) : {};
2015
2212
  const store = this.store;
2016
2213
  const relationship = this.graph.get(this.identifier, key);
2017
- 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)) : {};
2018
2219
  const isAsync = relationship.definition.isAsync;
2019
2220
  const _belongsToState = {
2020
2221
  key,
@@ -2038,7 +2239,11 @@ class LegacySupport {
2038
2239
  return null;
2039
2240
  } else {
2040
2241
  const toReturn = store._instanceCache.getRecord(relatedIdentifier);
2041
- 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)) : {};
2042
2247
  return toReturn;
2043
2248
  }
2044
2249
  }
@@ -2060,7 +2265,11 @@ class LegacySupport {
2060
2265
  if (jsonApi.data) {
2061
2266
  for (let i = 0; i < jsonApi.data.length; i++) {
2062
2267
  const relatedIdentifier = jsonApi.data[i];
2063
- 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)) : {};
2064
2273
  if (cache.recordIsLoaded(relatedIdentifier, true)) {
2065
2274
  identifiers.push(relatedIdentifier);
2066
2275
  }
@@ -2069,7 +2278,7 @@ class LegacySupport {
2069
2278
  return [identifiers, jsonApi];
2070
2279
  }
2071
2280
  getManyArray(key, definition) {
2072
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2281
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2073
2282
  let manyArray = this._manyArrayCache[key];
2074
2283
  if (!definition) {
2075
2284
  definition = this.graph.get(this.identifier, key).definition;
@@ -2096,10 +2305,14 @@ class LegacySupport {
2096
2305
  }
2097
2306
  return manyArray;
2098
2307
  }
2099
- 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
+ })() : {};
2100
2313
  }
2101
2314
  fetchAsyncHasMany(key, relationship, manyArray, options) {
2102
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2315
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2103
2316
  let loadingPromise = this._relationshipPromisesCache[key];
2104
2317
  if (loadingPromise) {
2105
2318
  return loadingPromise;
@@ -2114,10 +2327,14 @@ class LegacySupport {
2114
2327
  this._relationshipPromisesCache[key] = loadingPromise;
2115
2328
  return loadingPromise;
2116
2329
  }
2117
- 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
+ })() : {};
2118
2335
  }
2119
2336
  reloadHasMany(key, options) {
2120
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2337
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2121
2338
  const loadingPromise = this._relationshipPromisesCache[key];
2122
2339
  if (loadingPromise) {
2123
2340
  return loadingPromise;
@@ -2138,10 +2355,14 @@ class LegacySupport {
2138
2355
  }
2139
2356
  return promise;
2140
2357
  }
2141
- 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
+ })() : {};
2142
2363
  }
2143
2364
  getHasMany(key, options) {
2144
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2365
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2145
2366
  const relationship = this.graph.get(this.identifier, key);
2146
2367
  const {
2147
2368
  definition,
@@ -2158,11 +2379,19 @@ class LegacySupport {
2158
2379
  content: manyArray
2159
2380
  });
2160
2381
  } else {
2161
- 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)) : {};
2162
2387
  return manyArray;
2163
2388
  }
2164
2389
  }
2165
- 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
+ })() : {};
2166
2395
  }
2167
2396
  _updatePromiseProxyFor(kind, key, args) {
2168
2397
  let promiseProxy = this._relationshipProxyCache[key];
@@ -2172,7 +2401,11 @@ class LegacySupport {
2172
2401
  content
2173
2402
  } = args;
2174
2403
  if (promiseProxy) {
2175
- 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) : {};
2176
2409
  promiseProxy._update(promise, content);
2177
2410
  } else {
2178
2411
  promiseProxy = this._relationshipProxyCache[key] = new PromiseManyArray(promise, content);
@@ -2184,7 +2417,11 @@ class LegacySupport {
2184
2417
  promise,
2185
2418
  content
2186
2419
  } = args;
2187
- 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) : {};
2188
2425
  if (content !== undefined) {
2189
2426
  promiseProxy.set('content', content);
2190
2427
  }
@@ -2198,22 +2435,30 @@ class LegacySupport {
2198
2435
  referenceFor(kind, name) {
2199
2436
  let reference = this.references[name];
2200
2437
  if (!reference) {
2201
- if (macroCondition(!getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2438
+ if (macroCondition(!dependencySatisfies('@ember-data/graph', '*'))) {
2202
2439
  // TODO @runspired while this feels odd, it is not a regression in capability because we do
2203
2440
  // not today support references pulling from RecordDatas other than our own
2204
2441
  // because of the intimate API access involved. This is something we will need to redesign.
2205
- 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
+ })() : {};
2206
2447
  }
2207
2448
  const {
2208
2449
  graph,
2209
2450
  identifier
2210
2451
  } = this;
2211
2452
  const relationship = graph.get(identifier, name);
2212
- if (macroCondition(getOwnConfig().env.DEBUG)) {
2453
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
2213
2454
  if (kind) {
2214
2455
  const modelName = identifier.type;
2215
2456
  const actualRelationshipKind = relationship.definition.kind;
2216
- 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) : {};
2217
2462
  }
2218
2463
  }
2219
2464
  const relationshipKind = relationship.definition.kind;
@@ -2227,7 +2472,7 @@ class LegacySupport {
2227
2472
  return reference;
2228
2473
  }
2229
2474
  _findHasManyByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
2230
- if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2475
+ if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
2231
2476
  if (!resource) {
2232
2477
  return;
2233
2478
  }
@@ -2236,7 +2481,7 @@ class LegacySupport {
2236
2481
  state
2237
2482
  } = relationship;
2238
2483
  upgradeStore(this.store);
2239
- const adapter = this.store.adapterFor(definition.type);
2484
+ const adapter = this.store.adapterFor?.(definition.type);
2240
2485
  const {
2241
2486
  isStale,
2242
2487
  hasDematerializedInverse,
@@ -2246,13 +2491,18 @@ class LegacySupport {
2246
2491
  } = state;
2247
2492
  const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
2248
2493
  const identifiers = resource.data;
2249
- const shouldFindViaLink = resource.links && resource.links.related && (typeof adapter.findHasMany === 'function' || typeof identifiers === 'undefined') && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
2250
- const relationshipMeta = this.store.getSchemaDefinitionService().relationshipsDefinitionFor({
2494
+ const shouldFindViaLink = resource.links && resource.links.related && (typeof adapter?.findHasMany === 'function' || typeof identifiers === 'undefined') && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
2495
+ const field = this.store.schema.fields({
2251
2496
  type: definition.inverseType
2252
- })[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') : {};
2253
2503
  const request = {
2254
2504
  useLink: shouldFindViaLink,
2255
- field: relationshipMeta,
2505
+ field,
2256
2506
  links: resource.links,
2257
2507
  meta: resource.meta,
2258
2508
  options,
@@ -2261,8 +2511,16 @@ class LegacySupport {
2261
2511
 
2262
2512
  // fetch via link
2263
2513
  if (shouldFindViaLink) {
2264
- assert(`Expected collection to be an array`, !identifiers || Array.isArray(identifiers));
2265
- 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)) : {};
2266
2524
  return this.store.request({
2267
2525
  op: 'findHasMany',
2268
2526
  records: identifiers || [],
@@ -2280,8 +2538,16 @@ class LegacySupport {
2280
2538
  }
2281
2539
  const hasData = hasReceivedData && !isEmpty;
2282
2540
  if (attemptLocalCache || hasData || hasLocalPartialData) {
2283
- assert(`Expected collection to be an array`, Array.isArray(identifiers));
2284
- 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)) : {};
2285
2551
  options.reload = options.reload || !attemptLocalCache || undefined;
2286
2552
  return this.store.request({
2287
2553
  op: 'findHasMany',
@@ -2297,7 +2563,11 @@ class LegacySupport {
2297
2563
  // TODO if the relationshipIsStale, should we hit the adapter anyway?
2298
2564
  return;
2299
2565
  }
2300
- 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
+ })() : {};
2301
2571
  }
2302
2572
  _findBelongsToByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
2303
2573
  if (!resource) {
@@ -2312,7 +2582,11 @@ class LegacySupport {
2312
2582
  return this._pending[key];
2313
2583
  }
2314
2584
  const identifier = resource.data ? resource.data : null;
2315
- 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)) : {};
2316
2590
  const {
2317
2591
  isStale,
2318
2592
  hasDematerializedInverse,
@@ -2322,11 +2596,15 @@ class LegacySupport {
2322
2596
  } = relationship.state;
2323
2597
  const allInverseRecordsAreLoaded = areAllInverseRecordsLoaded(this.store, resource);
2324
2598
  const shouldFindViaLink = resource.links?.related && (shouldForceReload || hasDematerializedInverse || isStale || !allInverseRecordsAreLoaded && !isEmpty);
2325
- const relationshipMeta = this.store.getSchemaDefinitionService().relationshipsDefinitionFor(this.identifier)[relationship.definition.key];
2326
- 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') : {};
2327
2605
  const request = {
2328
2606
  useLink: shouldFindViaLink,
2329
- field: relationshipMeta,
2607
+ field,
2330
2608
  links: resource.links,
2331
2609
  meta: resource.meta,
2332
2610
  options,
@@ -2367,7 +2645,11 @@ class LegacySupport {
2367
2645
 
2368
2646
  // we may need to fetch
2369
2647
  if (identifier) {
2370
- 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) : {};
2371
2653
  options.reload = options.reload || !attemptLocalCache || undefined;
2372
2654
  this._pending[key] = this.store.request({
2373
2655
  op: 'findBelongsTo',
@@ -2455,7 +2737,11 @@ function extractIdentifierFromRecord(record) {
2455
2737
  }
2456
2738
  function anyUnloaded(store, relationship) {
2457
2739
  const graph = store._graph;
2458
- 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) : {};
2459
2745
  const relationshipData = graph.getData(relationship.identifier, relationship.definition.key);
2460
2746
  const state = relationshipData.data;
2461
2747
  const cache = store._instanceCache;
@@ -2469,7 +2755,11 @@ function areAllInverseRecordsLoaded(store, resource) {
2469
2755
  const instanceCache = store._instanceCache;
2470
2756
  const identifiers = resource.data;
2471
2757
  if (Array.isArray(identifiers)) {
2472
- 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)) : {};
2473
2763
  // treat as collection
2474
2764
  // check for unloaded records
2475
2765
  return identifiers.every(identifier => instanceCache.recordIsLoaded(identifier));
@@ -2477,26 +2767,16 @@ function areAllInverseRecordsLoaded(store, resource) {
2477
2767
 
2478
2768
  // treat as single resource
2479
2769
  if (!identifiers) return true;
2480
- 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)) : {};
2481
2775
  return instanceCache.recordIsLoaded(identifiers);
2482
2776
  }
2483
2777
  function isBelongsTo(relationship) {
2484
2778
  return relationship.definition.kind === 'belongsTo';
2485
2779
  }
2486
- function _initializerDefineProperty(target, property, descriptor, context) {
2487
- if (!descriptor) return;
2488
- Object.defineProperty(target, property, {
2489
- enumerable: descriptor.enumerable,
2490
- configurable: descriptor.configurable,
2491
- writable: descriptor.writable,
2492
- value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
2493
- });
2494
- }
2495
- var _dec, _dec2, _dec3, _dec4, _class$2, _descriptor, _descriptor2;
2496
-
2497
- /**
2498
- @module @ember-data/model
2499
- */
2500
2780
 
2501
2781
  // we force the type here to our own construct because mixin and extend patterns
2502
2782
  // lose generic signatures. We also do this because we need to Omit `clear` from
@@ -2578,40 +2858,7 @@ const ArrayProxyWithCustomOverrides = ArrayProxy;
2578
2858
  @public
2579
2859
  @extends Ember.ArrayProxy
2580
2860
  */
2581
- let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = computed(), _dec4 = not('length'), (_class$2 = class Errors extends ArrayProxyWithCustomOverrides {
2582
- constructor(...args) {
2583
- super(...args);
2584
- /**
2585
- An array containing all of the error messages for this
2586
- record. This is useful for displaying all errors to the user.
2587
- ```handlebars
2588
- {{#each @model.errors.messages as |message|}}
2589
- <div class="error">
2590
- {{message}}
2591
- </div>
2592
- {{/each}}
2593
- ```
2594
- @property messages
2595
- @public
2596
- @type {Array}
2597
- */
2598
- _initializerDefineProperty(this, "messages", _descriptor, this);
2599
- /**
2600
- Total number of errors.
2601
- @property length
2602
- @type {Number}
2603
- @public
2604
- @readOnly
2605
- */
2606
- /**
2607
- `true` if we have no errors.
2608
- @property isEmpty
2609
- @type {Boolean}
2610
- @public
2611
- @readOnly
2612
- */
2613
- _initializerDefineProperty(this, "isEmpty", _descriptor2, this);
2614
- }
2861
+ class Errors extends ArrayProxyWithCustomOverrides {
2615
2862
  /**
2616
2863
  @property errorsByAttributeName
2617
2864
  @type {MapWithDefault}
@@ -2638,6 +2885,9 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2638
2885
  @param {String} attribute
2639
2886
  @return {Array}
2640
2887
  */
2888
+ static {
2889
+ decorateMethodV2(this.prototype, "errorsByAttributeName", [computed()]);
2890
+ }
2641
2891
  errorsFor(attribute) {
2642
2892
  const map = this.errorsByAttributeName;
2643
2893
  let errors = map.get(attribute);
@@ -2653,6 +2903,25 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2653
2903
  get(errors, '[]');
2654
2904
  return errors;
2655
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);
2656
2925
  /**
2657
2926
  @property content
2658
2927
  @type {Array}
@@ -2666,6 +2935,9 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2666
2935
  @method unknownProperty
2667
2936
  @private
2668
2937
  */
2938
+ static {
2939
+ decorateMethodV2(this.prototype, "content", [computed()]);
2940
+ }
2669
2941
  unknownProperty(attribute) {
2670
2942
  const errors = this.errorsFor(attribute);
2671
2943
  if (errors.length === 0) {
@@ -2673,6 +2945,26 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2673
2945
  }
2674
2946
  return errors;
2675
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);
2676
2968
  /**
2677
2969
  Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
2678
2970
  the record and transition the record into an `invalid` state.
@@ -2831,9 +3123,7 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2831
3123
  /**
2832
3124
  Checks if there are error messages for the given attribute.
2833
3125
  ```app/controllers/user/edit.js
2834
- import Controller from '@ember/controller';
2835
- import { action } from '@ember/object';
2836
- export default class UserEditController extends Controller {
3126
+ export default class UserEditController extends Controller {
2837
3127
  @action
2838
3128
  save(user) {
2839
3129
  if (user.errors.has('email')) {
@@ -2851,17 +3141,7 @@ let Errors = (_dec = computed(), _dec2 = mapBy('content', 'message'), _dec3 = co
2851
3141
  has(attribute) {
2852
3142
  return this.errorsFor(attribute).length > 0;
2853
3143
  }
2854
- }, (_applyDecoratedDescriptor(_class$2.prototype, "errorsByAttributeName", [_dec], Object.getOwnPropertyDescriptor(_class$2.prototype, "errorsByAttributeName"), _class$2.prototype), _descriptor = _applyDecoratedDescriptor(_class$2.prototype, "messages", [_dec2], {
2855
- configurable: true,
2856
- enumerable: true,
2857
- writable: true,
2858
- initializer: null
2859
- }), _applyDecoratedDescriptor(_class$2.prototype, "content", [_dec3], Object.getOwnPropertyDescriptor(_class$2.prototype, "content"), _class$2.prototype), _descriptor2 = _applyDecoratedDescriptor(_class$2.prototype, "isEmpty", [_dec4], {
2860
- configurable: true,
2861
- enumerable: true,
2862
- writable: true,
2863
- initializer: null
2864
- })), _class$2));
3144
+ }
2865
3145
  function rollbackAttributes() {
2866
3146
  const {
2867
3147
  currentState
@@ -2894,7 +3174,11 @@ function reload(options = {}) {
2894
3174
  options.isReloading = true;
2895
3175
  options.reload = true;
2896
3176
  const identifier = recordIdentifierFor$1(this);
2897
- 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) : {};
2898
3182
  this.isReloading = true;
2899
3183
  const promise = this[RecordStore].request({
2900
3184
  op: 'findRecord',
@@ -2953,6 +3237,8 @@ function createSnapshot() {
2953
3237
  const FetchManager = importSync('@ember-data/legacy-compat/-private').FetchManager;
2954
3238
  store._fetchManager = new FetchManager(store);
2955
3239
  }
3240
+
3241
+ // @ts-expect-error Typescript isn't able to curry narrowed args that are divorced from each other.
2956
3242
  return store._fetchManager.createSnapshot(recordIdentifierFor$1(this));
2957
3243
  }
2958
3244
  function notifyChanges(identifier, value, key, record, store) {
@@ -2967,7 +3253,11 @@ function notifyChanges(identifier, value, key, record, store) {
2967
3253
  } else if (value === 'relationships') {
2968
3254
  if (key) {
2969
3255
  const meta = record.constructor.relationshipsByName.get(key);
2970
- 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) : {};
2971
3261
  notifyRelationship(identifier, key, record, meta);
2972
3262
  } else {
2973
3263
  record.eachRelationship((name, meta) => {
@@ -2996,8 +3286,16 @@ function notifyRelationship(identifier, key, record, meta) {
2996
3286
  //We need to notifyPropertyChange in the adding case because we need to make sure
2997
3287
  //we fetch the newly added record in case it is unloaded
2998
3288
  //TODO(Igor): Consider whether we could do this only if the record state is unloaded
2999
- assert(`Expected options to exist on relationship meta`, meta.options);
3000
- 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) : {};
3001
3299
  if (meta.options.async) {
3002
3300
  record.notifyPropertyChange(key);
3003
3301
  }
@@ -3011,7 +3309,6 @@ function notifyAttribute(store, identifier, key, record) {
3011
3309
  record.notifyPropertyChange(key);
3012
3310
  }
3013
3311
  }
3014
- var _class$1;
3015
3312
  const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
3016
3313
  const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
3017
3314
  const PRIMARY_ATTRIBUTE_KEY = 'base';
@@ -3096,7 +3393,7 @@ root
3096
3393
 
3097
3394
  @internal
3098
3395
  */
3099
- let RecordState = (_class$1 = class RecordState {
3396
+ class RecordState {
3100
3397
  constructor(record) {
3101
3398
  const store = storeFor$1(record);
3102
3399
  const identity = recordIdentifierFor(record);
@@ -3193,7 +3490,11 @@ let RecordState = (_class$1 = class RecordState {
3193
3490
  notifySignal(this, key);
3194
3491
  }
3195
3492
  updateInvalidErrors(errors) {
3196
- 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') : {};
3197
3498
  const jsonApiErrors = this.cache.getErrors(this.identifier);
3198
3499
  errors.clear();
3199
3500
  for (let i = 0; i < jsonApiErrors.length; i++) {
@@ -3208,7 +3509,11 @@ let RecordState = (_class$1 = class RecordState {
3208
3509
  }
3209
3510
  if (key) {
3210
3511
  const errMsg = error.detail || error.title;
3211
- 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) : {};
3212
3517
  errors.add(key, errMsg);
3213
3518
  }
3214
3519
  }
@@ -3224,16 +3529,26 @@ let RecordState = (_class$1 = class RecordState {
3224
3529
  get isLoading() {
3225
3530
  return !this.isLoaded && this.pendingCount > 0 && this.fulfilledCount === 0;
3226
3531
  }
3532
+ static {
3533
+ decorateMethodV2(this.prototype, "isLoading", [tagged]);
3534
+ }
3227
3535
  get isLoaded() {
3228
3536
  if (this.isNew) {
3229
3537
  return true;
3230
3538
  }
3231
3539
  return this.fulfilledCount > 0 || !this.isEmpty;
3232
3540
  }
3541
+ static {
3542
+ decorateMethodV2(this.prototype, "isLoaded", [tagged]);
3543
+ }
3233
3544
  get isSaved() {
3234
3545
  const rd = this.cache;
3235
3546
  if (this.isDeleted) {
3236
- 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') : {};
3237
3552
  return rd.isDeletionCommitted(this.identifier);
3238
3553
  }
3239
3554
  if (this.isNew || this.isEmpty || !this.isValid || this.isDirty || this.isLoading) {
@@ -3241,26 +3556,53 @@ let RecordState = (_class$1 = class RecordState {
3241
3556
  }
3242
3557
  return true;
3243
3558
  }
3559
+ static {
3560
+ decorateMethodV2(this.prototype, "isSaved", [tagged]);
3561
+ }
3244
3562
  get isEmpty() {
3245
3563
  const rd = this.cache;
3246
3564
  // TODO this is not actually an RFC'd concept. Determine the
3247
3565
  // correct heuristic to replace this with.
3248
- 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') : {};
3249
3571
  return !this.isNew && rd.isEmpty(this.identifier);
3250
3572
  }
3573
+ static {
3574
+ decorateMethodV2(this.prototype, "isEmpty", [tagged]);
3575
+ }
3251
3576
  get isNew() {
3252
3577
  const rd = this.cache;
3253
- 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') : {};
3254
3583
  return rd.isNew(this.identifier);
3255
3584
  }
3585
+ static {
3586
+ decorateMethodV2(this.prototype, "isNew", [tagged]);
3587
+ }
3256
3588
  get isDeleted() {
3257
3589
  const rd = this.cache;
3258
- 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') : {};
3259
3595
  return rd.isDeleted(this.identifier);
3260
3596
  }
3597
+ static {
3598
+ decorateMethodV2(this.prototype, "isDeleted", [tagged]);
3599
+ }
3261
3600
  get isValid() {
3262
3601
  return this.record.errors.length === 0;
3263
3602
  }
3603
+ static {
3604
+ decorateMethodV2(this.prototype, "isValid", [tagged]);
3605
+ }
3264
3606
  get isDirty() {
3265
3607
  const rd = this.cache;
3266
3608
  if (this.isEmpty || rd.isDeletionCommitted(this.identifier) || this.isDeleted && this.isNew) {
@@ -3268,6 +3610,9 @@ let RecordState = (_class$1 = class RecordState {
3268
3610
  }
3269
3611
  return this.isDeleted || this.isNew || rd.hasChangedAttrs(this.identifier);
3270
3612
  }
3613
+ static {
3614
+ decorateMethodV2(this.prototype, "isDirty", [tagged]);
3615
+ }
3271
3616
  get isError() {
3272
3617
  const errorReq = this._errorRequests[this._errorRequests.length - 1];
3273
3618
  if (!errorReq) {
@@ -3276,6 +3621,9 @@ let RecordState = (_class$1 = class RecordState {
3276
3621
  return true;
3277
3622
  }
3278
3623
  }
3624
+ static {
3625
+ decorateMethodV2(this.prototype, "isError", [tagged]);
3626
+ }
3279
3627
  get adapterError() {
3280
3628
  const request = this._lastError;
3281
3629
  if (!request) {
@@ -3283,9 +3631,15 @@ let RecordState = (_class$1 = class RecordState {
3283
3631
  }
3284
3632
  return request.state === 'rejected' && request.response.data;
3285
3633
  }
3634
+ static {
3635
+ decorateMethodV2(this.prototype, "adapterError", [tagged]);
3636
+ }
3286
3637
  get isPreloaded() {
3287
3638
  return !this.isEmpty && this.isLoading;
3288
3639
  }
3640
+ static {
3641
+ decorateMethodV2(this.prototype, "isPreloaded", [cached]);
3642
+ }
3289
3643
  get stateName() {
3290
3644
  // we might be empty while loading so check this first
3291
3645
  if (this.isLoading) {
@@ -3330,6 +3684,9 @@ let RecordState = (_class$1 = class RecordState {
3330
3684
  return 'root.loaded.saved';
3331
3685
  }
3332
3686
  }
3687
+ static {
3688
+ decorateMethodV2(this.prototype, "stateName", [cached]);
3689
+ }
3333
3690
  get dirtyType() {
3334
3691
  // we might be empty while loading so check this first
3335
3692
  if (this.isLoading || this.isEmpty) {
@@ -3352,38 +3709,20 @@ let RecordState = (_class$1 = class RecordState {
3352
3709
  return '';
3353
3710
  }
3354
3711
  }
3355
- }, (_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
+ }
3356
3716
  defineSignal(RecordState.prototype, 'isSaving', false);
3357
3717
  function notifyErrorsStateChanged(state) {
3358
3718
  state.notify('isValid');
3359
3719
  state.notify('isError');
3360
3720
  state.notify('adapterError');
3361
3721
  }
3362
- var _class, _class2;
3363
- function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
3364
- const possibleRelationships = relationshipsSoFar || [];
3365
- const relationshipMap = inverseType.relationships;
3366
- if (!relationshipMap) {
3367
- return possibleRelationships;
3368
- }
3369
- const relationshipsForType = relationshipMap.get(type.modelName);
3370
- const relationships = Array.isArray(relationshipsForType) ? relationshipsForType.filter(relationship => {
3371
- const optionsForRelationship = relationship.options;
3372
- if (!optionsForRelationship.inverse && optionsForRelationship.inverse !== null) {
3373
- return true;
3374
- }
3375
- return name === optionsForRelationship.inverse;
3376
- }) : null;
3377
- if (relationships) {
3378
- possibleRelationships.push.apply(possibleRelationships, relationships);
3379
- }
3380
3722
 
3381
- //Recurse to support polymorphism
3382
- if (type.superclass) {
3383
- findPossibleInverses(type.superclass, inverseType, name, possibleRelationships);
3384
- }
3385
- return possibleRelationships;
3386
- }
3723
+ /**
3724
+ @module @ember-data/model
3725
+ */
3387
3726
 
3388
3727
  /*
3389
3728
  * This decorator allows us to lazily compute
@@ -3392,6 +3731,7 @@ function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
3392
3731
  */
3393
3732
  function computeOnce(target, propertyName, desc) {
3394
3733
  const cache = new WeakMap();
3734
+ // eslint-disable-next-line @typescript-eslint/unbound-method
3395
3735
  const getter = desc.get;
3396
3736
  desc.get = function () {
3397
3737
  let meta = cache.get(this);
@@ -3430,14 +3770,13 @@ function computeOnce(target, propertyName, desc) {
3430
3770
  @public
3431
3771
  @extends Ember.EmberObject
3432
3772
  */
3433
- let Model = (_class = (_class2 = class Model extends EmberObject {
3434
- constructor(...args) {
3435
- super(...args);
3436
- this.___private_notifications = void 0;
3437
- }
3438
- init(options = {}) {
3439
- if (macroCondition(getOwnConfig().env.DEBUG)) {
3440
- if (!options._secretInit && !options._createProps) {
3773
+
3774
+ class Model extends EmberObject {
3775
+ // set during create by the store
3776
+
3777
+ init(options) {
3778
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3779
+ if (!options?._secretInit && !options?._createProps) {
3441
3780
  throw new Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.');
3442
3781
  }
3443
3782
  }
@@ -3450,13 +3789,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3450
3789
  this[RecordStore] = store;
3451
3790
  const identity = _secretInit.identifier;
3452
3791
  _secretInit.cb(this, _secretInit.cache, identity, _secretInit.store);
3453
- this.___recordState = macroCondition(getOwnConfig().env.DEBUG) ? new RecordState(this) : null;
3792
+ this.___recordState = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? new RecordState(this) : null;
3454
3793
  this.setProperties(createProps);
3455
3794
  const notifications = store.notifications;
3456
3795
  this.___private_notifications = notifications.subscribe(identity, (identifier, type, field) => {
3457
3796
  notifyChanges(identifier, type, field, this, store);
3458
3797
  });
3459
3798
  }
3799
+
3800
+ // @ts-expect-error destroy should not return a value, but ember's types force it to
3460
3801
  destroy() {
3461
3802
  const identifier = recordIdentifierFor$1(this);
3462
3803
  this.___recordState?.destroy();
@@ -3507,6 +3848,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3507
3848
  @type {Boolean}
3508
3849
  @readOnly
3509
3850
  */
3851
+ static {
3852
+ decorateMethodV2(this.prototype, "isEmpty", [compat]);
3853
+ }
3510
3854
  get isLoading() {
3511
3855
  return this.currentState.isLoading;
3512
3856
  }
@@ -3529,6 +3873,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3529
3873
  @type {Boolean}
3530
3874
  @readOnly
3531
3875
  */
3876
+ static {
3877
+ decorateMethodV2(this.prototype, "isLoading", [compat]);
3878
+ }
3532
3879
  get isLoaded() {
3533
3880
  return this.currentState.isLoaded;
3534
3881
  }
@@ -3554,6 +3901,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3554
3901
  @type {Boolean}
3555
3902
  @readOnly
3556
3903
  */
3904
+ static {
3905
+ decorateMethodV2(this.prototype, "isLoaded", [compat]);
3906
+ }
3557
3907
  get hasDirtyAttributes() {
3558
3908
  return this.currentState.isDirty;
3559
3909
  }
@@ -3578,6 +3928,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3578
3928
  @type {Boolean}
3579
3929
  @readOnly
3580
3930
  */
3931
+ static {
3932
+ decorateMethodV2(this.prototype, "hasDirtyAttributes", [compat]);
3933
+ }
3581
3934
  get isSaving() {
3582
3935
  return this.currentState.isSaving;
3583
3936
  }
@@ -3614,6 +3967,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3614
3967
  @type {Boolean}
3615
3968
  @readOnly
3616
3969
  */
3970
+ static {
3971
+ decorateMethodV2(this.prototype, "isSaving", [compat]);
3972
+ }
3617
3973
  get isDeleted() {
3618
3974
  return this.currentState.isDeleted;
3619
3975
  }
@@ -3636,6 +3992,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3636
3992
  @type {Boolean}
3637
3993
  @readOnly
3638
3994
  */
3995
+ static {
3996
+ decorateMethodV2(this.prototype, "isDeleted", [compat]);
3997
+ }
3639
3998
  get isNew() {
3640
3999
  return this.currentState.isNew;
3641
4000
  }
@@ -3649,6 +4008,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3649
4008
  @type {Boolean}
3650
4009
  @readOnly
3651
4010
  */
4011
+ static {
4012
+ decorateMethodV2(this.prototype, "isNew", [compat]);
4013
+ }
3652
4014
  get isValid() {
3653
4015
  return this.currentState.isValid;
3654
4016
  }
@@ -3670,6 +4032,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3670
4032
  @type {String}
3671
4033
  @readOnly
3672
4034
  */
4035
+ static {
4036
+ decorateMethodV2(this.prototype, "isValid", [compat]);
4037
+ }
3673
4038
  get dirtyType() {
3674
4039
  return this.currentState.dirtyType;
3675
4040
  }
@@ -3691,11 +4056,17 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3691
4056
  @type {Boolean}
3692
4057
  @readOnly
3693
4058
  */
4059
+ static {
4060
+ decorateMethodV2(this.prototype, "dirtyType", [compat]);
4061
+ }
3694
4062
  get isError() {
3695
4063
  return this.currentState.isError;
3696
4064
  }
4065
+ static {
4066
+ decorateMethodV2(this.prototype, "isError", [compat]);
4067
+ }
3697
4068
  set isError(v) {
3698
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4069
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3699
4070
  throw new Error(`isError is not directly settable`);
3700
4071
  }
3701
4072
  }
@@ -3735,20 +4106,27 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3735
4106
  // this guard exists, because some dev-only deprecation code
3736
4107
  // (addListener via validatePropertyInjections) invokes toString before the
3737
4108
  // object is real.
3738
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4109
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
3739
4110
  try {
3740
4111
  return recordIdentifierFor$1(this).id;
3741
4112
  } catch {
3742
- return void 0;
4113
+ return null;
3743
4114
  }
3744
4115
  }
3745
4116
  return recordIdentifierFor$1(this).id;
3746
4117
  }
4118
+ static {
4119
+ decorateMethodV2(this.prototype, "id", [tagged]);
4120
+ }
3747
4121
  set id(id) {
3748
4122
  const normalizedId = coerceId(id);
3749
4123
  const identifier = recordIdentifierFor$1(this);
3750
4124
  const didChange = normalizedId !== identifier.id;
3751
- 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) : {};
3752
4130
  if (normalizedId !== null && didChange) {
3753
4131
  this.store._instanceCache.setRecordId(identifier, normalizedId);
3754
4132
  this.store.notifications.notify(identifier, 'identity');
@@ -3770,13 +4148,16 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3770
4148
  // when using legacy/classic ember classes. Basically: lazy in prod and eager in dev.
3771
4149
  // so we do this to try to steer folks to the nicer "dont user currentState"
3772
4150
  // error.
3773
- if (macroCondition(!getOwnConfig().env.DEBUG)) {
4151
+ if (macroCondition(!getGlobalConfig().WarpDrive.env.DEBUG)) {
3774
4152
  if (!this.___recordState) {
3775
4153
  this.___recordState = new RecordState(this);
3776
4154
  }
3777
4155
  }
3778
4156
  return this.___recordState;
3779
4157
  }
4158
+ static {
4159
+ decorateMethodV2(this.prototype, "currentState", [tagged]);
4160
+ }
3780
4161
  set currentState(_v) {
3781
4162
  throw new Error('cannot set currentState');
3782
4163
  }
@@ -3846,9 +4227,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3846
4227
  @public
3847
4228
  @type {AdapterError}
3848
4229
  */
4230
+ static {
4231
+ decorateMethodV2(this.prototype, "errors", [computeOnce]);
4232
+ }
3849
4233
  get adapterError() {
3850
4234
  return this.currentState.adapterError;
3851
4235
  }
4236
+ static {
4237
+ decorateMethodV2(this.prototype, "adapterError", [compat]);
4238
+ }
3852
4239
  set adapterError(v) {
3853
4240
  throw new Error(`adapterError is not directly settable`);
3854
4241
  }
@@ -3865,7 +4252,6 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3865
4252
  @param {Object} options
3866
4253
  @return {Object} an object whose values are primitive JSON values only
3867
4254
  */
3868
-
3869
4255
  /*
3870
4256
  We hook the default implementation to ensure
3871
4257
  our tagged properties are properly notified
@@ -3874,6 +4260,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3874
4260
  to trigger their flush. We wouldn't need to
3875
4261
  super in 4.0+ where sync observers are removed.
3876
4262
  */
4263
+ // @ts-expect-error no return is necessary, but Ember's types are forcing it
3877
4264
  notifyPropertyChange(prop) {
3878
4265
  notifySignal(this, prop);
3879
4266
  super.notifyPropertyChange(prop);
@@ -4061,7 +4448,11 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4061
4448
  */
4062
4449
 
4063
4450
  attr() {
4064
- 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
+ })() : {};
4065
4456
  }
4066
4457
 
4067
4458
  /**
@@ -4178,7 +4569,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4178
4569
  }
4179
4570
  ```
4180
4571
  @method eachRelationship
4181
- @public
4572
+ @public
4182
4573
  @param {Function} callback the callback to invoke
4183
4574
  @param {any} binding the value to which the callback's `this` should be bound
4184
4575
  */
@@ -4194,6 +4585,45 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4194
4585
  eachAttribute(callback, binding) {
4195
4586
  this.constructor.eachAttribute(callback, binding);
4196
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
+
4197
4627
  /*
4198
4628
  These class methods below provide relationship
4199
4629
  introspection abilities about relationships.
@@ -4226,12 +4656,20 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4226
4656
  @return {Model} the type of the relationship, or undefined
4227
4657
  */
4228
4658
  static typeForRelationship(name, store) {
4229
- 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) : {};
4230
4664
  const relationship = this.relationshipsByName.get(name);
4231
4665
  return relationship && store.modelFor(relationship.type);
4232
4666
  }
4233
4667
  static get inverseMap() {
4234
- 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) : {};
4235
4673
  return Object.create(null);
4236
4674
  }
4237
4675
 
@@ -4251,8 +4689,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4251
4689
  }
4252
4690
  ```
4253
4691
  ``` js
4254
- store.modelFor('post').inverseFor('comments', store) // { type: App.Message, name: 'owner', kind: 'belongsTo' }
4255
- store.modelFor('message').inverseFor('owner', store) // { type: App.Post, name: 'comments', kind: 'hasMany' }
4692
+ store.modelFor('post').inverseFor('comments', store) // { type: 'message', name: 'owner', kind: 'belongsTo' }
4693
+ store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
4256
4694
  ```
4257
4695
  @method inverseFor
4258
4696
  @public
@@ -4261,8 +4699,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4261
4699
  @param {Store} store
4262
4700
  @return {Object} the inverse relationship, or null
4263
4701
  */
4702
+ static {
4703
+ decorateMethodV2(this, "inverseMap", [computeOnce]);
4704
+ }
4264
4705
  static inverseFor(name, store) {
4265
- 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) : {};
4266
4711
  const inverseMap = this.inverseMap;
4267
4712
  if (inverseMap[name]) {
4268
4713
  return inverseMap[name];
@@ -4275,83 +4720,47 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4275
4720
 
4276
4721
  //Calculate the inverse, ignoring the cache
4277
4722
  static _findInverseFor(name, store) {
4278
- 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) : {};
4279
4728
  const relationship = this.relationshipsByName.get(name);
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) : {};
4734
+ if (!relationship) {
4735
+ return null;
4736
+ }
4280
4737
  const {
4281
4738
  options
4282
4739
  } = relationship;
4283
- const isPolymorphic = options.polymorphic;
4284
-
4285
- //If inverse is manually specified to be null, like `comments: hasMany('message', { inverse: null })`
4286
- const isExplicitInverseNull = options.inverse === null;
4287
- const isAbstractType = !isExplicitInverseNull && isPolymorphic && !store.getSchemaDefinitionService().doesTypeExist(relationship.type);
4288
- if (isExplicitInverseNull || isAbstractType) {
4289
- assert(`No schema for the abstract type '${relationship.type}' for the polymorphic relationship '${name}' on '${this.modelName}' was provided by the SchemaDefinitionService.`, !isPolymorphic || isExplicitInverseNull);
4290
- return null;
4291
- }
4292
- let fieldOnInverse, inverseKind, inverseRelationship, inverseOptions;
4293
- const inverseSchema = this.typeForRelationship(name, store);
4294
-
4295
- // if the type does not exist and we are not polymorphic
4296
- //If inverse is specified manually, return the inverse
4297
- if (options.inverse !== undefined) {
4298
- fieldOnInverse = options.inverse;
4299
- inverseRelationship = inverseSchema && inverseSchema.relationshipsByName.get(fieldOnInverse);
4300
- assert(`We found no field named '${fieldOnInverse}' on the schema for '${inverseSchema.modelName}' to be the inverse of the '${name}' relationship on '${this.modelName}'. This is most likely due to a missing field on your model definition.`, inverseRelationship);
4301
-
4302
- // TODO probably just return the whole inverse here
4303
- inverseKind = inverseRelationship.kind;
4304
- inverseOptions = inverseRelationship.options;
4305
- } else {
4306
- //No inverse was specified manually, we need to use a heuristic to guess one
4307
- if (relationship.type === relationship.parentModelName) {
4308
- warn(`Detected a reflexive relationship named '${name}' on the schema for '${relationship.type}' without an inverse option. Look at https://guides.emberjs.com/current/models/relationships/#toc_reflexive-relations for how to explicitly specify inverses.`, false, {
4309
- id: 'ds.model.reflexive-relationship-without-inverse'
4310
- });
4311
- }
4312
- let possibleRelationships = findPossibleInverses(this, inverseSchema, name);
4313
- if (possibleRelationships.length === 0) {
4314
- return null;
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.`);
4315
4743
  }
4316
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4317
- const filteredRelationships = possibleRelationships.filter(possibleRelationship => {
4318
- const optionsForRelationship = possibleRelationship.options;
4319
- return name === optionsForRelationship.inverse;
4320
- });
4321
- assert("You defined the '" + name + "' relationship on " + this + ', but you defined the inverse relationships of type ' + inverseSchema.toString() + ' multiple times. Look at https://guides.emberjs.com/current/models/relationships/#toc_explicit-inverses for how to explicitly specify inverses', filteredRelationships.length < 2);
4322
- }
4323
- const explicitRelationship = possibleRelationships.find(relationship => relationship.options.inverse === name);
4324
- if (explicitRelationship) {
4325
- possibleRelationships = [explicitRelationship];
4326
- }
4327
- assert("You defined the '" + name + "' relationship on " + this + ', but multiple possible inverse relationships of type ' + this + ' were found on ' + inverseSchema + '. Look at https://guides.emberjs.com/current/models/relationships/#toc_explicit-inverses for how to explicitly specify inverses', possibleRelationships.length === 1);
4328
- fieldOnInverse = possibleRelationships[0].name;
4329
- inverseKind = possibleRelationships[0].kind;
4330
- inverseOptions = possibleRelationships[0].options;
4744
+ })(options.inverse === null || typeof options.inverse === 'string' && options.inverse.length > 0) : {};
4745
+ if (options.inverse === null) {
4746
+ return null;
4331
4747
  }
4332
-
4333
- // ensure inverse is properly configured
4334
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4335
- if (isPolymorphic) {
4336
- assert(`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${fieldOnInverse}' on type '${inverseSchema.modelName}' is misconfigured.`, inverseOptions.as);
4337
- assert(`options.as should match the expected type of the polymorphic relationship. Expected field '${fieldOnInverse}' on type '${inverseSchema.modelName}' to specify '${relationship.type}' but found '${inverseOptions.as}'`, !!inverseOptions.as && relationship.type === inverseOptions.as);
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}`);
4338
4752
  }
4753
+ })(schemaExists) : {};
4754
+ if (!schemaExists) {
4755
+ return null;
4339
4756
  }
4340
-
4341
- // ensure we are properly configured
4342
- if (macroCondition(getOwnConfig().env.DEBUG)) {
4343
- if (inverseOptions.polymorphic) {
4344
- assert(`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${name}' on type '${this.modelName}' is misconfigured.`, options.as);
4345
- assert(`options.as should match the expected type of the polymorphic relationship. Expected field '${name}' on type '${this.modelName}' to specify '${inverseRelationship.type}' but found '${options.as}'`, !!options.as && inverseRelationship.type === options.as);
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}'`);
4346
4761
  }
4347
- }
4348
- assert(`The ${inverseSchema.modelName}:${fieldOnInverse} relationship declares 'inverse: null', but it was resolved as the inverse for ${this.modelName}:${name}.`, inverseOptions.inverse !== null);
4349
- return {
4350
- type: inverseSchema,
4351
- name: fieldOnInverse,
4352
- kind: inverseKind,
4353
- options: inverseOptions
4354
- };
4762
+ })(inverseField && (inverseField.kind === 'belongsTo' || inverseField.kind === 'hasMany')) : {};
4763
+ return inverseField || null;
4355
4764
  }
4356
4765
 
4357
4766
  /**
@@ -4389,7 +4798,11 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4389
4798
  */
4390
4799
 
4391
4800
  static get relationships() {
4392
- 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) : {};
4393
4806
  const map = new Map();
4394
4807
  const relationshipsByName = this.relationshipsByName;
4395
4808
 
@@ -4433,14 +4846,21 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4433
4846
  @type Object
4434
4847
  @readOnly
4435
4848
  */
4849
+ static {
4850
+ decorateMethodV2(this, "relationships", [computeOnce]);
4851
+ }
4436
4852
  static get relationshipNames() {
4437
- 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) : {};
4438
4858
  const names = {
4439
4859
  hasMany: [],
4440
4860
  belongsTo: []
4441
4861
  };
4442
4862
  this.eachComputedProperty((name, meta) => {
4443
- if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
4863
+ if (isRelationshipSchema(meta)) {
4444
4864
  names[meta.kind].push(name);
4445
4865
  }
4446
4866
  });
@@ -4472,8 +4892,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4472
4892
  @type Array
4473
4893
  @readOnly
4474
4894
  */
4895
+ static {
4896
+ decorateMethodV2(this, "relationshipNames", [computeOnce]);
4897
+ }
4475
4898
  static get relatedTypes() {
4476
- 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) : {};
4477
4904
  const types = [];
4478
4905
  const rels = this.relationshipsObject;
4479
4906
  const relationships = Object.keys(rels);
@@ -4484,7 +4911,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4484
4911
  const name = relationships[i];
4485
4912
  const meta = rels[name];
4486
4913
  const modelName = meta.type;
4487
- if (types.indexOf(modelName) === -1) {
4914
+ if (!types.includes(modelName)) {
4488
4915
  types.push(modelName);
4489
4916
  }
4490
4917
  }
@@ -4519,8 +4946,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4519
4946
  @type Map
4520
4947
  @readOnly
4521
4948
  */
4949
+ static {
4950
+ decorateMethodV2(this, "relatedTypes", [computeOnce]);
4951
+ }
4522
4952
  static get relationshipsByName() {
4523
- 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) : {};
4524
4958
  const map = new Map();
4525
4959
  const rels = this.relationshipsObject;
4526
4960
  const relationships = Object.keys(rels);
@@ -4531,19 +4965,35 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4531
4965
  }
4532
4966
  return map;
4533
4967
  }
4968
+ static {
4969
+ decorateMethodV2(this, "relationshipsByName", [computeOnce]);
4970
+ }
4534
4971
  static get relationshipsObject() {
4535
- 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) : {};
4536
4977
  const relationships = Object.create(null);
4537
4978
  const modelName = this.modelName;
4538
4979
  this.eachComputedProperty((name, meta) => {
4539
- if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
4540
- // TODO deprecate key being here
4541
- meta.key = name;
4542
- meta.name = name;
4543
- meta.parentModelName = modelName;
4544
- relationships[name] = meta;
4545
- 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 > 0));
4980
+ if (!isRelationshipSchema(meta)) {
4981
+ return;
4546
4982
  }
4983
+ // TODO deprecate key being here
4984
+ meta.key = name;
4985
+ meta.name = name;
4986
+ relationships[name] = meta;
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)) : {};
4547
4997
  });
4548
4998
  return relationships;
4549
4999
  }
@@ -4580,13 +5030,20 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4580
5030
  @type Map
4581
5031
  @readOnly
4582
5032
  */
5033
+ static {
5034
+ decorateMethodV2(this, "relationshipsObject", [computeOnce]);
5035
+ }
4583
5036
  static get fields() {
4584
- 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) : {};
4585
5042
  const map = new Map();
4586
5043
  this.eachComputedProperty((name, meta) => {
4587
- if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
5044
+ if (isRelationshipSchema(meta)) {
4588
5045
  map.set(name, meta.kind);
4589
- } else if (meta.kind === 'attribute') {
5046
+ } else if (isAttributeSchema(meta)) {
4590
5047
  map.set(name, 'attribute');
4591
5048
  }
4592
5049
  });
@@ -4603,8 +5060,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4603
5060
  @param {Function} callback the callback to invoke
4604
5061
  @param {any} binding the value to which the callback's `this` should be bound
4605
5062
  */
5063
+ static {
5064
+ decorateMethodV2(this, "fields", [computeOnce]);
5065
+ }
4606
5066
  static eachRelationship(callback, binding) {
4607
- 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) : {};
4608
5072
  this.relationshipsByName.forEach((relationship, name) => {
4609
5073
  callback.call(binding, name, relationship);
4610
5074
  });
@@ -4622,15 +5086,30 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4622
5086
  @param {any} binding the value to which the callback's `this` should be bound
4623
5087
  */
4624
5088
  static eachRelatedType(callback, binding) {
4625
- 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) : {};
4626
5094
  const relationshipTypes = this.relatedTypes;
4627
5095
  for (let i = 0; i < relationshipTypes.length; i++) {
4628
5096
  const type = relationshipTypes[i];
4629
5097
  callback.call(binding, type);
4630
5098
  }
4631
5099
  }
5100
+
5101
+ /**
5102
+ *
5103
+ * @method determineRelationshipType
5104
+ * @private
5105
+ * @deprecated
5106
+ */
4632
5107
  static determineRelationshipType(knownSide, store) {
4633
- 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) : {};
4634
5113
  const knownKey = knownSide.name;
4635
5114
  const knownKind = knownSide.kind;
4636
5115
  const inverse = this.inverseFor(knownKey, store);
@@ -4680,11 +5159,19 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4680
5159
  @readOnly
4681
5160
  */
4682
5161
  static get attributes() {
4683
- 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) : {};
4684
5167
  const map = new Map();
4685
5168
  this.eachComputedProperty((name, meta) => {
4686
- if (meta.kind === 'attribute') {
4687
- 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');
5169
+ if (isAttributeSchema(meta)) {
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') : {};
4688
5175
 
4689
5176
  // TODO deprecate key being here
4690
5177
  meta.key = name;
@@ -4725,8 +5212,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4725
5212
  @type {Map}
4726
5213
  @readOnly
4727
5214
  */
5215
+ static {
5216
+ decorateMethodV2(this, "attributes", [computeOnce]);
5217
+ }
4728
5218
  static get transformedAttributes() {
4729
- 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) : {};
4730
5224
  const map = new Map();
4731
5225
  this.eachAttribute((name, meta) => {
4732
5226
  if (meta.type) {
@@ -4770,8 +5264,15 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4770
5264
  @param {Object} [binding] the value to which the callback's `this` should be bound
4771
5265
  @static
4772
5266
  */
5267
+ static {
5268
+ decorateMethodV2(this, "transformedAttributes", [computeOnce]);
5269
+ }
4773
5270
  static eachAttribute(callback, binding) {
4774
- 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) : {};
4775
5276
  this.attributes.forEach((meta, name) => {
4776
5277
  callback.call(binding, name, meta);
4777
5278
  });
@@ -4813,7 +5314,11 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4813
5314
  @static
4814
5315
  */
4815
5316
  static eachTransformedAttribute(callback, binding) {
4816
- 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) : {};
4817
5322
  this.transformedAttributes.forEach((type, name) => {
4818
5323
  callback.call(binding, name, type);
4819
5324
  });
@@ -4826,11 +5331,18 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4826
5331
  @static
4827
5332
  */
4828
5333
  static toString() {
4829
- 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) : {};
4830
5339
  return `model:${this.modelName}`;
4831
5340
  }
4832
- }, _class2.isModel = true, _class2.modelName = null, _class2), (_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
4833
5344
  Model.prototype.save = save;
5345
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
4834
5346
  Model.prototype.destroyRecord = destroyRecord;
4835
5347
  Model.prototype.unloadRecord = unloadRecord;
4836
5348
  Model.prototype.hasMany = hasMany;
@@ -4847,64 +5359,7 @@ defineSignal(Model.prototype, 'isReloading', false);
4847
5359
  // the values initialized during create to `setUnknownProperty`
4848
5360
  Model.prototype._createProps = null;
4849
5361
  Model.prototype._secretInit = null;
4850
- if (macroCondition(getOwnConfig().includeDataAdapter)) {
4851
- /**
4852
- Provides info about the model for debugging purposes
4853
- by grouping the properties into more semantic groups.
4854
- Meant to be used by debugging tools such as the Chrome Ember Extension.
4855
- - Groups all attributes in "Attributes" group.
4856
- - Groups all belongsTo relationships in "Belongs To" group.
4857
- - Groups all hasMany relationships in "Has Many" group.
4858
- - Groups all flags in "Flags" group.
4859
- - Flags relationship CPs as expensive properties.
4860
- @method _debugInfo
4861
- @for Model
4862
- @private
4863
- */
4864
- Model.prototype._debugInfo = function () {
4865
- const relationships = {};
4866
- const expensiveProperties = [];
4867
- const identifier = recordIdentifierFor$1(this);
4868
- const schema = this.store.getSchemaDefinitionService();
4869
- const attrDefs = schema.attributesDefinitionFor(identifier);
4870
- const relDefs = schema.relationshipsDefinitionFor(identifier);
4871
- const attributes = Object.keys(attrDefs);
4872
- attributes.unshift('id');
4873
- const groups = [{
4874
- name: 'Attributes',
4875
- properties: attributes,
4876
- expand: true
4877
- }];
4878
- Object.keys(relDefs).forEach(name => {
4879
- const relationship = relDefs[name];
4880
- let properties = relationships[relationship.kind];
4881
- if (properties === undefined) {
4882
- properties = relationships[relationship.kind] = [];
4883
- groups.push({
4884
- name: relationship.kind,
4885
- properties,
4886
- expand: true
4887
- });
4888
- }
4889
- properties.push(name);
4890
- expensiveProperties.push(name);
4891
- });
4892
- groups.push({
4893
- name: 'Flags',
4894
- properties: ['isLoaded', 'hasDirtyAttributes', 'isSaving', 'isDeleted', 'isError', 'isNew', 'isValid']
4895
- });
4896
- return {
4897
- propertyInfo: {
4898
- // include all other mixins / properties (not just the grouped ones)
4899
- includeOtherProperties: true,
4900
- groups: groups,
4901
- // don't pre-calculate unless cached
4902
- expensiveProperties: expensiveProperties
4903
- }
4904
- };
4905
- };
4906
- }
4907
- if (macroCondition(getOwnConfig().env.DEBUG)) {
5362
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
4908
5363
  const lookupDescriptor = function lookupDescriptor(obj, keyName) {
4909
5364
  let current = obj;
4910
5365
  do {
@@ -4916,27 +5371,37 @@ if (macroCondition(getOwnConfig().env.DEBUG)) {
4916
5371
  } while (current !== null);
4917
5372
  return null;
4918
5373
  };
4919
- Model.reopen({
4920
- init() {
4921
- this._super(...arguments);
4922
- const ourDescriptor = lookupDescriptor(Model.prototype, 'currentState');
4923
- const theirDescriptor = lookupDescriptor(this, 'currentState');
4924
- const realState = this.___recordState;
4925
- if (ourDescriptor.get !== theirDescriptor.get || realState !== this.currentState) {
4926
- throw new Error(`'currentState' is a reserved property name on instances of classes extending Model. Please choose a different property name for ${this.constructor.toString()}`);
4927
- }
4928
- const ID_DESCRIPTOR = lookupDescriptor(Model.prototype, 'id');
4929
- const idDesc = lookupDescriptor(this, 'id');
4930
- if (idDesc.get !== ID_DESCRIPTOR.get) {
4931
- 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.constructor.toString()}`);
4932
- }
5374
+
5375
+ // eslint-disable-next-line @typescript-eslint/unbound-method
5376
+ const init = Model.prototype.init;
5377
+ Model.prototype.init = function (createArgs) {
5378
+ init.call(this, createArgs);
5379
+ const ourDescriptor = lookupDescriptor(Model.prototype, 'currentState');
5380
+ const theirDescriptor = lookupDescriptor(this, 'currentState');
5381
+ if (!ourDescriptor || !theirDescriptor) {
5382
+ throw new Error(`Unable to determine if 'currentState' is a reserved property name on instances of classes extending Model. Please ensure that 'currentState' is not defined as a property on ${this.constructor.toString()}`);
5383
+ }
5384
+ const realState = this.___recordState;
5385
+ if (ourDescriptor.get !== theirDescriptor.get || realState !== this.currentState) {
5386
+ throw new Error(`'currentState' is a reserved property name on instances of classes extending Model. Please choose a different property name for ${this.constructor.toString()}`);
5387
+ }
5388
+ const ID_DESCRIPTOR = lookupDescriptor(Model.prototype, 'id');
5389
+ const idDesc = lookupDescriptor(this, 'id');
5390
+ if (!ID_DESCRIPTOR || !idDesc) {
5391
+ throw new Error(`Unable to determine if 'id' is a reserved property name on instances of classes extending Model. Please ensure that 'id' is not defined as a property on ${this.constructor.toString()}`);
5392
+ }
5393
+ if (idDesc.get !== ID_DESCRIPTOR.get) {
5394
+ 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.constructor.toString()}`);
4933
5395
  }
4934
- });
4935
- Model.reopen = function deprecatedReopen() {
4936
- assert(`Model.reopen is deprecated. Use Foo extends Model to extend your class instead.`);
4937
- };
4938
- Model.reopenClass = function deprecatedReopenClass() {
4939
- assert(`Model.reopenClass is deprecated. Use Foo extends Model to add static methods and properties to your class instead.`);
4940
5396
  };
5397
+ delete Model.reopen;
5398
+ delete Model.reopenClass;
5399
+ }
5400
+ function isRelationshipSchema(meta) {
5401
+ const hasKind = typeof meta === 'object' && meta !== null && 'kind' in meta && 'options' in meta;
5402
+ return hasKind && (meta.kind === 'hasMany' || meta.kind === 'belongsTo');
5403
+ }
5404
+ function isAttributeSchema(meta) {
5405
+ return typeof meta === 'object' && meta !== null && 'kind' in meta && meta.kind === 'attribute';
4941
5406
  }
4942
- 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 };