@ember-data/model 4.12.0-alpha.7 → 4.12.0-alpha.9

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-2cd7707a";
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-2cd7707a";
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
@@ -1118,7 +1118,7 @@ class RelatedCollection extends RecordArray {
1118
1118
  switch (prop) {
1119
1119
  case 'length 0':
1120
1120
  {
1121
- this._manager.updateCache({
1121
+ this._manager.mutate({
1122
1122
  op: 'replaceRelatedRecords',
1123
1123
  record: this.identifier,
1124
1124
  field: this.key,
@@ -1129,7 +1129,7 @@ class RelatedCollection extends RecordArray {
1129
1129
  case 'replace cell':
1130
1130
  {
1131
1131
  const [index, prior, value] = args;
1132
- this._manager.updateCache({
1132
+ this._manager.mutate({
1133
1133
  op: 'replaceRelatedRecord',
1134
1134
  record: this.identifier,
1135
1135
  field: this.key,
@@ -1140,7 +1140,7 @@ class RelatedCollection extends RecordArray {
1140
1140
  break;
1141
1141
  }
1142
1142
  case 'push':
1143
- this._manager.updateCache({
1143
+ this._manager.mutate({
1144
1144
  op: 'addToRelatedRecords',
1145
1145
  record: this.identifier,
1146
1146
  field: this.key,
@@ -1149,7 +1149,7 @@ class RelatedCollection extends RecordArray {
1149
1149
  break;
1150
1150
  case 'pop':
1151
1151
  if (result) {
1152
- this._manager.updateCache({
1152
+ this._manager.mutate({
1153
1153
  op: 'removeFromRelatedRecords',
1154
1154
  record: this.identifier,
1155
1155
  field: this.key,
@@ -1158,7 +1158,7 @@ class RelatedCollection extends RecordArray {
1158
1158
  }
1159
1159
  break;
1160
1160
  case 'unshift':
1161
- this._manager.updateCache({
1161
+ this._manager.mutate({
1162
1162
  op: 'addToRelatedRecords',
1163
1163
  record: this.identifier,
1164
1164
  field: this.key,
@@ -1168,7 +1168,7 @@ class RelatedCollection extends RecordArray {
1168
1168
  break;
1169
1169
  case 'shift':
1170
1170
  if (result) {
1171
- this._manager.updateCache({
1171
+ this._manager.mutate({
1172
1172
  op: 'removeFromRelatedRecords',
1173
1173
  record: this.identifier,
1174
1174
  field: this.key,
@@ -1178,7 +1178,7 @@ class RelatedCollection extends RecordArray {
1178
1178
  }
1179
1179
  break;
1180
1180
  case 'sort':
1181
- this._manager.updateCache({
1181
+ this._manager.mutate({
1182
1182
  op: 'sortRelatedRecords',
1183
1183
  record: this.identifier,
1184
1184
  field: this.key,
@@ -1190,7 +1190,7 @@ class RelatedCollection extends RecordArray {
1190
1190
  const [start, removeCount, ...adds] = args;
1191
1191
  // detect a full replace
1192
1192
  if (removeCount > 0 && adds.length === this[SOURCE].length) {
1193
- this._manager.updateCache({
1193
+ this._manager.mutate({
1194
1194
  op: 'replaceRelatedRecords',
1195
1195
  record: this.identifier,
1196
1196
  field: this.key,
@@ -1199,7 +1199,7 @@ class RelatedCollection extends RecordArray {
1199
1199
  return;
1200
1200
  }
1201
1201
  if (removeCount > 0) {
1202
- this._manager.updateCache({
1202
+ this._manager.mutate({
1203
1203
  op: 'removeFromRelatedRecords',
1204
1204
  record: this.identifier,
1205
1205
  field: this.key,
@@ -1208,7 +1208,7 @@ class RelatedCollection extends RecordArray {
1208
1208
  });
1209
1209
  }
1210
1210
  if (adds?.length) {
1211
- this._manager.updateCache({
1211
+ this._manager.mutate({
1212
1212
  op: 'addToRelatedRecords',
1213
1213
  record: this.identifier,
1214
1214
  field: this.key,
@@ -1278,6 +1278,7 @@ class RelatedCollection extends RecordArray {
1278
1278
  const {
1279
1279
  store
1280
1280
  } = this;
1281
+ assert(`Expected modelName to be set`, this.modelName);
1281
1282
  const record = store.createRecord(this.modelName, hash);
1282
1283
  this.push(record);
1283
1284
  return record;
@@ -1286,7 +1287,7 @@ class RelatedCollection extends RecordArray {
1286
1287
  RelatedCollection.prototype.isAsync = false;
1287
1288
  RelatedCollection.prototype.isPolymorphic = false;
1288
1289
  RelatedCollection.prototype.identifier = null;
1289
- RelatedCollection.prototype.recordData = null;
1290
+ RelatedCollection.prototype.cache = null;
1290
1291
  RelatedCollection.prototype._inverseIsAsync = false;
1291
1292
  RelatedCollection.prototype.key = '';
1292
1293
  RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
@@ -1967,7 +1968,8 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1967
1968
  }
1968
1969
  _resource() {
1969
1970
  this._ref; // subscribe
1970
- return this.store._instanceCache.getRecordData(this.___identifier).getRelationship(this.___identifier, this.key);
1971
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.store._instanceCache.getResourceCache(this.___identifier) : this.store.cache;
1972
+ return cache.getRelationship(this.___identifier, this.key);
1971
1973
  }
1972
1974
 
1973
1975
  /**
@@ -2332,7 +2334,8 @@ let HasManyReference = (_class$2 = class HasManyReference {
2332
2334
  return [];
2333
2335
  }
2334
2336
  _resource() {
2335
- return this.store._instanceCache.getRecordData(this.___identifier).getRelationship(this.___identifier, this.key);
2337
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.store._instanceCache.getResourceCache(this.___identifier) : this.store.cache;
2338
+ return cache.getRelationship(this.___identifier, this.key);
2336
2339
  }
2337
2340
 
2338
2341
  /**
@@ -2775,9 +2778,9 @@ let HasManyReference = (_class$2 = class HasManyReference {
2775
2778
  class LegacySupport {
2776
2779
  constructor(record) {
2777
2780
  this.record = record;
2778
- this.store = storeFor$1(record);
2781
+ this.store = storeFor(record);
2779
2782
  this.identifier = recordIdentifierFor$1(record);
2780
- this.recordData = this.store._instanceCache.getRecordData(this.identifier);
2783
+ this.cache = peekCache(record);
2781
2784
  this._manyArrayCache = Object.create(null);
2782
2785
  this._relationshipPromisesCache = Object.create(null);
2783
2786
  this._relationshipProxyCache = Object.create(null);
@@ -2800,8 +2803,8 @@ class LegacySupport {
2800
2803
  currentState.length = 0;
2801
2804
  fastPush(currentState, identifiers);
2802
2805
  }
2803
- updateCache(operation) {
2804
- this.recordData.update(operation);
2806
+ mutate(mutation) {
2807
+ this.cache.mutate(mutation);
2805
2808
  }
2806
2809
  _findBelongsTo(key, resource, relationship, options) {
2807
2810
  // TODO @runspired follow up if parent isNew then we should not be attempting load here
@@ -2816,7 +2819,7 @@ class LegacySupport {
2816
2819
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
2817
2820
  const relationship = graphFor(this.store).get(this.identifier, key);
2818
2821
  assert(`Expected ${key} to be a belongs-to relationship`, isBelongsTo(relationship));
2819
- let resource = this.recordData.getRelationship(this.identifier, key);
2822
+ let resource = this.cache.getRelationship(this.identifier, key);
2820
2823
  relationship.state.hasFailedLoadAttempt = false;
2821
2824
  relationship.state.shouldForceReload = true;
2822
2825
  let promise = this._findBelongsTo(key, resource, relationship, options);
@@ -2830,9 +2833,9 @@ class LegacySupport {
2830
2833
  getBelongsTo(key, options) {
2831
2834
  const {
2832
2835
  identifier,
2833
- recordData
2836
+ cache
2834
2837
  } = this;
2835
- let resource = recordData.getRelationship(this.identifier, key);
2838
+ let resource = cache.getRelationship(this.identifier, key);
2836
2839
  let relatedIdentifier = resource && resource.data ? resource.data : null;
2837
2840
  assert(`Expected a stable identifier`, !relatedIdentifier || isStableIdentifier(relatedIdentifier));
2838
2841
  const store = this.store;
@@ -2868,7 +2871,7 @@ class LegacySupport {
2868
2871
  }
2869
2872
  }
2870
2873
  setDirtyBelongsTo(key, value) {
2871
- return this.recordData.update({
2874
+ return this.cache.mutate({
2872
2875
  op: 'replaceRelatedRecord',
2873
2876
  record: this.identifier,
2874
2877
  field: key,
@@ -2878,7 +2881,7 @@ class LegacySupport {
2878
2881
  true);
2879
2882
  }
2880
2883
  _getCurrentState(identifier, field) {
2881
- let jsonApi = this.recordData.getRelationship(identifier, field, true);
2884
+ let jsonApi = this.cache.getRelationship(identifier, field, true);
2882
2885
  const cache = this.store._instanceCache;
2883
2886
  let identifiers = [];
2884
2887
  if (jsonApi.data) {
@@ -2905,7 +2908,7 @@ class LegacySupport {
2905
2908
  store: this.store,
2906
2909
  type: definition.type,
2907
2910
  identifier: this.identifier,
2908
- recordData: this.recordData,
2911
+ cache: this.cache,
2909
2912
  identifiers,
2910
2913
  key,
2911
2914
  meta: doc.meta || null,
@@ -2929,7 +2932,7 @@ class LegacySupport {
2929
2932
  if (loadingPromise) {
2930
2933
  return loadingPromise;
2931
2934
  }
2932
- const jsonApi = this.recordData.getRelationship(this.identifier, key);
2935
+ const jsonApi = this.cache.getRelationship(this.identifier, key);
2933
2936
  const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
2934
2937
  if (!promise) {
2935
2938
  manyArray.isLoaded = true;
@@ -3356,7 +3359,8 @@ function notifyRelationship(identifier, key, record, meta) {
3356
3359
  }
3357
3360
  function notifyAttribute(store, identifier, key, record) {
3358
3361
  let currentValue = cacheFor(record, key);
3359
- if (currentValue !== store._instanceCache.getRecordData(identifier).getAttr(identifier, key)) {
3362
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? peekCache(record) : store.cache;
3363
+ if (currentValue !== cache.getAttr(identifier, key)) {
3360
3364
  record.notifyPropertyChange(key);
3361
3365
  }
3362
3366
  }
@@ -3491,11 +3495,11 @@ root
3491
3495
  let RecordState = (_class3 = class RecordState {
3492
3496
  constructor(record) {
3493
3497
  _initializerDefineProperty(this, "isSaving", _descriptor2, this);
3494
- const store = storeFor(record);
3498
+ const store = storeFor$1(record);
3495
3499
  const identity = recordIdentifierFor$1(record);
3496
3500
  this.identifier = identity;
3497
3501
  this.record = record;
3498
- this.cache = store._instanceCache.getRecordData(identity);
3502
+ this.cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? peekCache(record) : store.cache;
3499
3503
  this.pendingCount = 0;
3500
3504
  this.fulfilledCount = 0;
3501
3505
  this.rejectedCount = 0;
@@ -3580,7 +3584,7 @@ let RecordState = (_class3 = class RecordState {
3580
3584
  });
3581
3585
  }
3582
3586
  destroy() {
3583
- storeFor(this.record).notifications.unsubscribe(this.handler);
3587
+ storeFor$1(this.record).notifications.unsubscribe(this.handler);
3584
3588
  }
3585
3589
  notify(key) {
3586
3590
  getTag(this, key).notify();
@@ -3944,7 +3948,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3944
3948
  let store = this.store = _secretInit.store;
3945
3949
  super.init(options);
3946
3950
  let identity = _secretInit.identifier;
3947
- _secretInit.cb(this, _secretInit.recordData, identity, _secretInit.store);
3951
+ _secretInit.cb(this, _secretInit.cache, identity, _secretInit.store);
3948
3952
  this.___recordState = macroCondition(isDevelopingApp()) ? new RecordState(this) : null;
3949
3953
  this.setProperties(createProps);
3950
3954
  let notifications = store.notifications;
@@ -3955,7 +3959,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3955
3959
  destroy() {
3956
3960
  const identifier = recordIdentifierFor(this);
3957
3961
  this.___recordState?.destroy();
3958
- const store = storeFor(this);
3962
+ const store = storeFor$1(this);
3959
3963
  store.notifications.unsubscribe(this.___private_notifications);
3960
3964
  // Legacy behavior is to notify the relationships on destroy
3961
3965
  // such that they "clear". It's uncertain this behavior would
@@ -4346,7 +4350,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4346
4350
  @return {Object} an object whose values are primitive JSON values only
4347
4351
  */
4348
4352
  serialize(options) {
4349
- return storeFor(this)._instanceCache.createSnapshot(recordIdentifierFor(this)).serialize(options);
4353
+ return storeFor$1(this)._instanceCache.createSnapshot(recordIdentifierFor(this)).serialize(options);
4350
4354
  }
4351
4355
 
4352
4356
  /*
@@ -4395,7 +4399,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4395
4399
  deleteRecord() {
4396
4400
  // ensure we've populated currentState prior to deleting a new record
4397
4401
  if (this.currentState) {
4398
- storeFor(this).deleteRecord(this);
4402
+ storeFor$1(this).deleteRecord(this);
4399
4403
  }
4400
4404
  }
4401
4405
 
@@ -4462,7 +4466,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4462
4466
  if (this.currentState.isNew && (this.isDestroyed || this.isDestroying)) {
4463
4467
  return;
4464
4468
  }
4465
- storeFor(this).unloadRecord(this);
4469
+ storeFor$1(this).unloadRecord(this);
4466
4470
  }
4467
4471
 
4468
4472
  /**
@@ -4518,7 +4522,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4518
4522
  and value is an [oldProp, newProp] array.
4519
4523
  */
4520
4524
  changedAttributes() {
4521
- return recordDataFor(this).changedAttrs(recordIdentifierFor(this));
4525
+ return peekCache(this).changedAttrs(recordIdentifierFor(this));
4522
4526
  }
4523
4527
 
4524
4528
  /**
@@ -4543,8 +4547,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4543
4547
  const {
4544
4548
  isNew
4545
4549
  } = currentState;
4546
- storeFor(this)._join(() => {
4547
- recordDataFor(this).rollbackAttrs(recordIdentifierFor(this));
4550
+ storeFor$1(this)._join(() => {
4551
+ peekCache(this).rollbackAttrs(recordIdentifierFor(this));
4548
4552
  this.errors.clear();
4549
4553
  currentState.cleanErrorRequests();
4550
4554
  if (isNew) {
@@ -4559,7 +4563,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4559
4563
  */
4560
4564
  // TODO @deprecate in favor of a public API or examples of how to test successfully
4561
4565
  _createSnapshot() {
4562
- return storeFor(this)._instanceCache.createSnapshot(recordIdentifierFor(this));
4566
+ return storeFor$1(this)._instanceCache.createSnapshot(recordIdentifierFor(this));
4563
4567
  }
4564
4568
 
4565
4569
  /**
@@ -4601,7 +4605,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4601
4605
  if (this.currentState.isNew && this.currentState.isDeleted) {
4602
4606
  promise = resolve(this);
4603
4607
  } else {
4604
- promise = storeFor(this).saveRecord(this, options);
4608
+ promise = storeFor$1(this).saveRecord(this, options);
4605
4609
  }
4606
4610
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SAVE_PROMISE_ACCESS)) {
4607
4611
  return deprecatedPromiseObject(promise);
@@ -4641,7 +4645,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4641
4645
  let identifier = recordIdentifierFor(this);
4642
4646
  assert(`You cannot reload a record without an ID`, identifier.id);
4643
4647
  this.isReloading = true;
4644
- const promise = storeFor(this)._fetchManager.scheduleFetch(identifier, options).then(() => this).finally(() => {
4648
+ const promise = storeFor$1(this)._fetchManager.scheduleFetch(identifier, options).then(() => this).finally(() => {
4645
4649
  this.isReloading = false;
4646
4650
  });
4647
4651
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SAVE_PROMISE_ACCESS)) {
@@ -4809,7 +4813,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4809
4813
  return this.constructor.relationshipsByName.get(name);
4810
4814
  }
4811
4815
  inverseFor(key) {
4812
- return this.constructor.inverseFor(key, storeFor(this));
4816
+ return this.constructor.inverseFor(key, storeFor$1(this));
4813
4817
  }
4814
4818
  eachAttribute(callback, binding) {
4815
4819
  this.constructor.eachAttribute(callback, binding);