@ember-data/model 4.12.0-alpha.6 → 4.12.0-alpha.8

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-d114a056";
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-d114a056";
1
+ import { M as Model } from "./has-many-78309ccf";
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-78309ccf";
3
3
  import { getOwner } from '@ember/application';
4
4
 
5
5
  /*
@@ -1,8 +1,8 @@
1
1
  import { macroCondition, isDevelopingApp, getOwnConfig, importSync, dependencySatisfies } from '@embroider/macros';
2
2
  import { assert, deprecate, warn, inspect } from '@ember/debug';
3
3
  import EmberObject, { computed, get } from '@ember/object';
4
- import { recordIdentifierFor, storeFor } from '@ember-data/store';
5
- import { recordDataFor, RecordArray, MUTATE, SOURCE, recordIdentifierFor as recordIdentifierFor$1, IDENTIFIER_ARRAY_TAG, notifyArray, isStableIdentifier, storeFor as storeFor$1, fastPush, coerceId } from '@ember-data/store/-private';
4
+ import { recordIdentifierFor, storeFor as storeFor$1 } from '@ember-data/store';
5
+ import { peekCache, RecordArray, MUTATE, SOURCE, recordIdentifierFor as recordIdentifierFor$1, IDENTIFIER_ARRAY_TAG, notifyArray, isStableIdentifier, storeFor, fastPush, coerceId } from '@ember-data/store/-private';
6
6
  import { dasherize } from '@ember/string';
7
7
  import ArrayMixin, { A, NativeArray } from '@ember/array';
8
8
  import { singularize } from 'ember-inflector';
@@ -150,7 +150,7 @@ function attr(type, options) {
150
150
  if (this.isDestroyed || this.isDestroying) {
151
151
  return;
152
152
  }
153
- return recordDataFor(this).getAttr(recordIdentifierFor(this), key);
153
+ return peekCache(this).getAttr(recordIdentifierFor(this), key);
154
154
  },
155
155
  set(key, value) {
156
156
  if (macroCondition(isDevelopingApp())) {
@@ -160,10 +160,10 @@ function attr(type, options) {
160
160
  }
161
161
  assert(`Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`, !this.currentState.isDeleted);
162
162
  const identifier = recordIdentifierFor(this);
163
- const recordData = storeFor(this)._instanceCache.getRecordData(identifier);
164
- let currentValue = recordData.getAttr(identifier, key);
163
+ const cache = peekCache(this);
164
+ let currentValue = cache.getAttr(identifier, key);
165
165
  if (currentValue !== value) {
166
- recordData.setAttr(identifier, key, value);
166
+ cache.setAttr(identifier, key, value);
167
167
  if (!this.isValid) {
168
168
  const {
169
169
  errors
@@ -1286,7 +1286,7 @@ class RelatedCollection extends RecordArray {
1286
1286
  RelatedCollection.prototype.isAsync = false;
1287
1287
  RelatedCollection.prototype.isPolymorphic = false;
1288
1288
  RelatedCollection.prototype.identifier = null;
1289
- RelatedCollection.prototype.recordData = null;
1289
+ RelatedCollection.prototype.cache = null;
1290
1290
  RelatedCollection.prototype._inverseIsAsync = false;
1291
1291
  RelatedCollection.prototype.key = '';
1292
1292
  RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
@@ -1967,7 +1967,8 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1967
1967
  }
1968
1968
  _resource() {
1969
1969
  this._ref; // subscribe
1970
- return this.store._instanceCache.getRecordData(this.___identifier).getRelationship(this.___identifier, this.key);
1970
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.store._instanceCache.getResourceCache(this.___identifier) : this.store.cache;
1971
+ return cache.getRelationship(this.___identifier, this.key);
1971
1972
  }
1972
1973
 
1973
1974
  /**
@@ -2332,7 +2333,8 @@ let HasManyReference = (_class$2 = class HasManyReference {
2332
2333
  return [];
2333
2334
  }
2334
2335
  _resource() {
2335
- return this.store._instanceCache.getRecordData(this.___identifier).getRelationship(this.___identifier, this.key);
2336
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.store._instanceCache.getResourceCache(this.___identifier) : this.store.cache;
2337
+ return cache.getRelationship(this.___identifier, this.key);
2336
2338
  }
2337
2339
 
2338
2340
  /**
@@ -2775,9 +2777,9 @@ let HasManyReference = (_class$2 = class HasManyReference {
2775
2777
  class LegacySupport {
2776
2778
  constructor(record) {
2777
2779
  this.record = record;
2778
- this.store = storeFor$1(record);
2780
+ this.store = storeFor(record);
2779
2781
  this.identifier = recordIdentifierFor$1(record);
2780
- this.recordData = this.store._instanceCache.getRecordData(this.identifier);
2782
+ this.cache = peekCache(record);
2781
2783
  this._manyArrayCache = Object.create(null);
2782
2784
  this._relationshipPromisesCache = Object.create(null);
2783
2785
  this._relationshipProxyCache = Object.create(null);
@@ -2801,7 +2803,7 @@ class LegacySupport {
2801
2803
  fastPush(currentState, identifiers);
2802
2804
  }
2803
2805
  updateCache(operation) {
2804
- this.recordData.update(operation);
2806
+ this.cache.update(operation);
2805
2807
  }
2806
2808
  _findBelongsTo(key, resource, relationship, options) {
2807
2809
  // TODO @runspired follow up if parent isNew then we should not be attempting load here
@@ -2816,7 +2818,7 @@ class LegacySupport {
2816
2818
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
2817
2819
  const relationship = graphFor(this.store).get(this.identifier, key);
2818
2820
  assert(`Expected ${key} to be a belongs-to relationship`, isBelongsTo(relationship));
2819
- let resource = this.recordData.getRelationship(this.identifier, key);
2821
+ let resource = this.cache.getRelationship(this.identifier, key);
2820
2822
  relationship.state.hasFailedLoadAttempt = false;
2821
2823
  relationship.state.shouldForceReload = true;
2822
2824
  let promise = this._findBelongsTo(key, resource, relationship, options);
@@ -2830,9 +2832,9 @@ class LegacySupport {
2830
2832
  getBelongsTo(key, options) {
2831
2833
  const {
2832
2834
  identifier,
2833
- recordData
2835
+ cache
2834
2836
  } = this;
2835
- let resource = recordData.getRelationship(this.identifier, key);
2837
+ let resource = cache.getRelationship(this.identifier, key);
2836
2838
  let relatedIdentifier = resource && resource.data ? resource.data : null;
2837
2839
  assert(`Expected a stable identifier`, !relatedIdentifier || isStableIdentifier(relatedIdentifier));
2838
2840
  const store = this.store;
@@ -2868,7 +2870,7 @@ class LegacySupport {
2868
2870
  }
2869
2871
  }
2870
2872
  setDirtyBelongsTo(key, value) {
2871
- return this.recordData.update({
2873
+ return this.cache.update({
2872
2874
  op: 'replaceRelatedRecord',
2873
2875
  record: this.identifier,
2874
2876
  field: key,
@@ -2878,7 +2880,7 @@ class LegacySupport {
2878
2880
  true);
2879
2881
  }
2880
2882
  _getCurrentState(identifier, field) {
2881
- let jsonApi = this.recordData.getRelationship(identifier, field, true);
2883
+ let jsonApi = this.cache.getRelationship(identifier, field, true);
2882
2884
  const cache = this.store._instanceCache;
2883
2885
  let identifiers = [];
2884
2886
  if (jsonApi.data) {
@@ -2905,7 +2907,7 @@ class LegacySupport {
2905
2907
  store: this.store,
2906
2908
  type: definition.type,
2907
2909
  identifier: this.identifier,
2908
- recordData: this.recordData,
2910
+ cache: this.cache,
2909
2911
  identifiers,
2910
2912
  key,
2911
2913
  meta: doc.meta || null,
@@ -2929,7 +2931,7 @@ class LegacySupport {
2929
2931
  if (loadingPromise) {
2930
2932
  return loadingPromise;
2931
2933
  }
2932
- const jsonApi = this.recordData.getRelationship(this.identifier, key);
2934
+ const jsonApi = this.cache.getRelationship(this.identifier, key);
2933
2935
  const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
2934
2936
  if (!promise) {
2935
2937
  manyArray.isLoaded = true;
@@ -3356,7 +3358,8 @@ function notifyRelationship(identifier, key, record, meta) {
3356
3358
  }
3357
3359
  function notifyAttribute(store, identifier, key, record) {
3358
3360
  let currentValue = cacheFor(record, key);
3359
- if (currentValue !== store._instanceCache.getRecordData(identifier).getAttr(identifier, key)) {
3361
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? peekCache(record) : store.cache;
3362
+ if (currentValue !== cache.getAttr(identifier, key)) {
3360
3363
  record.notifyPropertyChange(key);
3361
3364
  }
3362
3365
  }
@@ -3491,11 +3494,11 @@ root
3491
3494
  let RecordState = (_class3 = class RecordState {
3492
3495
  constructor(record) {
3493
3496
  _initializerDefineProperty(this, "isSaving", _descriptor2, this);
3494
- const store = storeFor(record);
3497
+ const store = storeFor$1(record);
3495
3498
  const identity = recordIdentifierFor$1(record);
3496
3499
  this.identifier = identity;
3497
3500
  this.record = record;
3498
- this.cache = store._instanceCache.getRecordData(identity);
3501
+ this.cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? peekCache(record) : store.cache;
3499
3502
  this.pendingCount = 0;
3500
3503
  this.fulfilledCount = 0;
3501
3504
  this.rejectedCount = 0;
@@ -3580,7 +3583,7 @@ let RecordState = (_class3 = class RecordState {
3580
3583
  });
3581
3584
  }
3582
3585
  destroy() {
3583
- storeFor(this.record).notifications.unsubscribe(this.handler);
3586
+ storeFor$1(this.record).notifications.unsubscribe(this.handler);
3584
3587
  }
3585
3588
  notify(key) {
3586
3589
  getTag(this, key).notify();
@@ -3944,7 +3947,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3944
3947
  let store = this.store = _secretInit.store;
3945
3948
  super.init(options);
3946
3949
  let identity = _secretInit.identifier;
3947
- _secretInit.cb(this, _secretInit.recordData, identity, _secretInit.store);
3950
+ _secretInit.cb(this, _secretInit.cache, identity, _secretInit.store);
3948
3951
  this.___recordState = macroCondition(isDevelopingApp()) ? new RecordState(this) : null;
3949
3952
  this.setProperties(createProps);
3950
3953
  let notifications = store.notifications;
@@ -3955,7 +3958,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3955
3958
  destroy() {
3956
3959
  const identifier = recordIdentifierFor(this);
3957
3960
  this.___recordState?.destroy();
3958
- const store = storeFor(this);
3961
+ const store = storeFor$1(this);
3959
3962
  store.notifications.unsubscribe(this.___private_notifications);
3960
3963
  // Legacy behavior is to notify the relationships on destroy
3961
3964
  // such that they "clear". It's uncertain this behavior would
@@ -4346,7 +4349,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4346
4349
  @return {Object} an object whose values are primitive JSON values only
4347
4350
  */
4348
4351
  serialize(options) {
4349
- return storeFor(this)._instanceCache.createSnapshot(recordIdentifierFor(this)).serialize(options);
4352
+ return storeFor$1(this)._instanceCache.createSnapshot(recordIdentifierFor(this)).serialize(options);
4350
4353
  }
4351
4354
 
4352
4355
  /*
@@ -4395,7 +4398,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4395
4398
  deleteRecord() {
4396
4399
  // ensure we've populated currentState prior to deleting a new record
4397
4400
  if (this.currentState) {
4398
- storeFor(this).deleteRecord(this);
4401
+ storeFor$1(this).deleteRecord(this);
4399
4402
  }
4400
4403
  }
4401
4404
 
@@ -4462,7 +4465,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4462
4465
  if (this.currentState.isNew && (this.isDestroyed || this.isDestroying)) {
4463
4466
  return;
4464
4467
  }
4465
- storeFor(this).unloadRecord(this);
4468
+ storeFor$1(this).unloadRecord(this);
4466
4469
  }
4467
4470
 
4468
4471
  /**
@@ -4518,7 +4521,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4518
4521
  and value is an [oldProp, newProp] array.
4519
4522
  */
4520
4523
  changedAttributes() {
4521
- return recordDataFor(this).changedAttrs(recordIdentifierFor(this));
4524
+ return peekCache(this).changedAttrs(recordIdentifierFor(this));
4522
4525
  }
4523
4526
 
4524
4527
  /**
@@ -4543,8 +4546,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4543
4546
  const {
4544
4547
  isNew
4545
4548
  } = currentState;
4546
- storeFor(this)._join(() => {
4547
- recordDataFor(this).rollbackAttrs(recordIdentifierFor(this));
4549
+ storeFor$1(this)._join(() => {
4550
+ peekCache(this).rollbackAttrs(recordIdentifierFor(this));
4548
4551
  this.errors.clear();
4549
4552
  currentState.cleanErrorRequests();
4550
4553
  if (isNew) {
@@ -4559,7 +4562,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4559
4562
  */
4560
4563
  // TODO @deprecate in favor of a public API or examples of how to test successfully
4561
4564
  _createSnapshot() {
4562
- return storeFor(this)._instanceCache.createSnapshot(recordIdentifierFor(this));
4565
+ return storeFor$1(this)._instanceCache.createSnapshot(recordIdentifierFor(this));
4563
4566
  }
4564
4567
 
4565
4568
  /**
@@ -4601,7 +4604,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4601
4604
  if (this.currentState.isNew && this.currentState.isDeleted) {
4602
4605
  promise = resolve(this);
4603
4606
  } else {
4604
- promise = storeFor(this).saveRecord(this, options);
4607
+ promise = storeFor$1(this).saveRecord(this, options);
4605
4608
  }
4606
4609
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SAVE_PROMISE_ACCESS)) {
4607
4610
  return deprecatedPromiseObject(promise);
@@ -4641,7 +4644,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4641
4644
  let identifier = recordIdentifierFor(this);
4642
4645
  assert(`You cannot reload a record without an ID`, identifier.id);
4643
4646
  this.isReloading = true;
4644
- const promise = storeFor(this)._fetchManager.scheduleFetch(identifier, options).then(() => this).finally(() => {
4647
+ const promise = storeFor$1(this)._fetchManager.scheduleFetch(identifier, options).then(() => this).finally(() => {
4645
4648
  this.isReloading = false;
4646
4649
  });
4647
4650
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SAVE_PROMISE_ACCESS)) {
@@ -4809,7 +4812,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4809
4812
  return this.constructor.relationshipsByName.get(name);
4810
4813
  }
4811
4814
  inverseFor(key) {
4812
- return this.constructor.inverseFor(key, storeFor(this));
4815
+ return this.constructor.inverseFor(key, storeFor$1(this));
4813
4816
  }
4814
4817
  eachAttribute(callback, binding) {
4815
4818
  this.constructor.eachAttribute(callback, binding);