@ember-data/model 4.12.0 → 4.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/addon/-private.js CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Model } from "./has-many-465843f4";
2
- export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, P as PromiseBelongsTo, c as PromiseManyArray, a as attr, b as belongsTo, h as hasMany } from "./has-many-465843f4";
1
+ import { M as Model } from "./has-many-26d79228";
2
+ export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, P as PromiseBelongsTo, c as PromiseManyArray, a as attr, b as belongsTo, h as hasMany } from "./has-many-26d79228";
3
3
  import { getOwner } from '@ember/application';
4
4
 
5
5
  /*
@@ -1383,7 +1383,9 @@ if (macroCondition(getOwnConfig().env.DEBUG)) {
1383
1383
  }
1384
1384
  if (parentDefinition.isPolymorphic) {
1385
1385
  let meta = store.getSchemaDefinitionService().relationshipsDefinitionFor(addedIdentifier)[parentDefinition.inverseKey];
1386
- if (meta?.options?.as) {
1386
+ if (macroCondition(!getOwnConfig().deprecations.DEPRECATE_NON_EXPLICIT_POLYMORPHISM)) {
1387
+ 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);
1388
+ } else if (meta?.options?.as?.length > 0) {
1387
1389
  asserted = true;
1388
1390
  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);
1389
1391
  }
@@ -2435,6 +2437,7 @@ class LegacySupport {
2435
2437
  this._manyArrayCache = Object.create(null);
2436
2438
  this._relationshipPromisesCache = Object.create(null);
2437
2439
  this._relationshipProxyCache = Object.create(null);
2440
+ this._pending = Object.create(null);
2438
2441
  this.references = Object.create(null);
2439
2442
  }
2440
2443
  _syncArray(array) {
@@ -2781,12 +2784,13 @@ class LegacySupport {
2781
2784
  if (!resource) {
2782
2785
  return Promise.resolve(null);
2783
2786
  }
2787
+ const key = relationship.definition.key;
2784
2788
 
2785
2789
  // interleaved promises mean that we MUST cache this here
2786
2790
  // in order to prevent infinite re-render if the request
2787
2791
  // fails.
2788
- if (this._pending) {
2789
- return this._pending;
2792
+ if (this._pending[key]) {
2793
+ return this._pending[key];
2790
2794
  }
2791
2795
  const identifier = resource.data ? resource.data : null;
2792
2796
  assert(`Expected a stable identifier`, !identifier || isStableIdentifier(identifier));
@@ -2820,10 +2824,10 @@ class LegacySupport {
2820
2824
  [Symbol.for('ember-data:skip-cache')]: true
2821
2825
  }
2822
2826
  });
2823
- this._pending = future.then(doc => doc.content).finally(() => {
2824
- this._pending = null;
2827
+ this._pending[key] = future.then(doc => doc.content).finally(() => {
2828
+ this._pending[key] = undefined;
2825
2829
  });
2826
- return this._pending;
2830
+ return this._pending[key];
2827
2831
  }
2828
2832
  const preferLocalCache = hasReceivedData && allInverseRecordsAreLoaded && !isEmpty;
2829
2833
  const hasLocalPartialData = hasDematerializedInverse || isEmpty && resource.data;
@@ -2846,7 +2850,7 @@ class LegacySupport {
2846
2850
  if (identifier) {
2847
2851
  assert(`Cannot fetch belongs-to relationship with no information`, identifier);
2848
2852
  options.reload = options.reload || !attemptLocalCache || undefined;
2849
- this._pending = this.store.request({
2853
+ this._pending[key] = this.store.request({
2850
2854
  op: 'findBelongsTo',
2851
2855
  records: [identifier],
2852
2856
  data: request,
@@ -2854,9 +2858,9 @@ class LegacySupport {
2854
2858
  [Symbol.for('ember-data:skip-cache')]: true
2855
2859
  }
2856
2860
  }).then(doc => doc.content).finally(() => {
2857
- this._pending = null;
2861
+ this._pending[key] = undefined;
2858
2862
  });
2859
- return this._pending;
2863
+ return this._pending[key];
2860
2864
  }
2861
2865
 
2862
2866
  // we were explicitly told we have no data and no links.
@@ -3051,6 +3055,11 @@ function isInvalidError(error) {
3051
3055
  let Tag = (_class$1 = class Tag {
3052
3056
  constructor() {
3053
3057
  _initializerDefineProperty(this, "ref", _descriptor$1, this);
3058
+ if (macroCondition(getOwnConfig().env.DEBUG)) {
3059
+ const [base, prop] = arguments;
3060
+ this._debug_base = base;
3061
+ this._debug_prop = prop;
3062
+ }
3054
3063
  this.rev = 1;
3055
3064
  this.isDirty = true;
3056
3065
  this.value = undefined;
@@ -3083,7 +3092,8 @@ function getTag(record, key) {
3083
3092
  tags = Object.create(null);
3084
3093
  Tags.set(record, tags);
3085
3094
  }
3086
- return tags[key] = tags[key] || new Tag();
3095
+ // @ts-expect-error
3096
+ return tags[key] = tags[key] || (macroCondition(getOwnConfig().env.DEBUG) ? new Tag(record.constructor.modelName, key) : new Tag());
3087
3097
  }
3088
3098
  function peekTag(record, key) {
3089
3099
  let tags = Tags.get(record);
@@ -5015,6 +5025,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
5015
5025
  meta.name = name;
5016
5026
  meta.parentModelName = modelName;
5017
5027
  relationships[name] = macroCondition(getOwnConfig().deprecations.DEPRECATE_RELATIONSHIPS_WITHOUT_INVERSE) ? relationshipFromMeta(meta) : meta;
5028
+ 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));
5018
5029
  }
5019
5030
  });
5020
5031
  return relationships;