@ember-data/model 4.12.0-alpha.0 → 4.12.0-alpha.10

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.
@@ -1,8 +1,8 @@
1
- import { macroCondition, isDevelopingApp, getOwnConfig, importSync, moduleExists } from '@embroider/macros';
1
+ import { isDevelopingApp, macroCondition, getOwnConfig, importSync } 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, 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';
@@ -103,9 +103,7 @@ function computedMacroWithOptionalParams(fn) {
103
103
  ```
104
104
 
105
105
  ```app/transforms/text.js
106
- import Transform from '@ember-data/serializer/transform';
107
-
108
- export default class TextTransform extends Transform {
106
+ export default class TextTransform {
109
107
  serialize(value, options) {
110
108
  if (options.uppercase) {
111
109
  return value.toUpperCase();
@@ -117,6 +115,10 @@ function computedMacroWithOptionalParams(fn) {
117
115
  deserialize(value) {
118
116
  return value;
119
117
  }
118
+
119
+ static create() {
120
+ return new this();
121
+ }
120
122
  }
121
123
  ```
122
124
 
@@ -142,7 +144,7 @@ function attr(type, options) {
142
144
  };
143
145
  return computed({
144
146
  get(key) {
145
- if (macroCondition(isDevelopingApp())) {
147
+ if (isDevelopingApp()) {
146
148
  if (['currentState'].indexOf(key) !== -1) {
147
149
  throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`);
148
150
  }
@@ -150,20 +152,20 @@ function attr(type, options) {
150
152
  if (this.isDestroyed || this.isDestroying) {
151
153
  return;
152
154
  }
153
- return recordDataFor(this).getAttr(recordIdentifierFor(this), key);
155
+ return peekCache(this).getAttr(recordIdentifierFor(this), key);
154
156
  },
155
157
  set(key, value) {
156
- if (macroCondition(isDevelopingApp())) {
158
+ if (isDevelopingApp()) {
157
159
  if (['currentState'].indexOf(key) !== -1) {
158
160
  throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`);
159
161
  }
160
162
  }
161
163
  assert(`Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`, !this.currentState.isDeleted);
162
164
  const identifier = recordIdentifierFor(this);
163
- const recordData = storeFor(this)._instanceCache.getRecordData(identifier);
164
- let currentValue = recordData.getAttr(identifier, key);
165
+ const cache = peekCache(this);
166
+ let currentValue = cache.getAttr(identifier, key);
165
167
  if (currentValue !== value) {
166
- recordData.setAttr(identifier, key, value);
168
+ cache.setAttr(identifier, key, value);
167
169
  if (!this.isValid) {
168
170
  const {
169
171
  errors
@@ -225,7 +227,7 @@ const PROXIED_OBJECT_PROPS = ['content', 'isPending', 'isSettled', 'isRejected',
225
227
  const ProxySymbolString = String(Symbol.for('PROXY_CONTENT'));
226
228
  function deprecatedPromiseObject(promise) {
227
229
  const promiseObjectProxy = promiseObject(promise);
228
- if (macroCondition(!isDevelopingApp())) {
230
+ if (!isDevelopingApp()) {
229
231
  return promiseObjectProxy;
230
232
  }
231
233
  const handler = {
@@ -648,7 +650,7 @@ function normalizeResponseHelper(serializer, store, modelClass, payload, id, req
648
650
  return normalizedResponse;
649
651
  }
650
652
  function validateDocumentStructure(doc) {
651
- if (macroCondition(isDevelopingApp())) {
653
+ if (isDevelopingApp()) {
652
654
  let errors = [];
653
655
  if (!doc || typeof doc !== 'object') {
654
656
  errors.push('Top level of a JSON API document must be an object');
@@ -835,7 +837,7 @@ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, paren
835
837
  kind
836
838
  } = inverse;
837
839
  let relationshipData = relationships[inverseKey] && relationships[inverseKey].data;
838
- if (macroCondition(isDevelopingApp())) {
840
+ if (isDevelopingApp()) {
839
841
  if (typeof relationshipData !== 'undefined' && !relationshipDataPointsToParent(relationshipData, parentIdentifier)) {
840
842
  let inspect = function inspect(thing) {
841
843
  return `'${JSON.stringify(thing)}'`;
@@ -984,7 +986,7 @@ function payloadIsNotBlank(adapterPayload) {
984
986
  }
985
987
  function guardDestroyedStore(promise, store, label) {
986
988
  let token;
987
- if (macroCondition(isDevelopingApp())) {
989
+ if (isDevelopingApp()) {
988
990
  token = store._trackAsyncRequestStart(label);
989
991
  }
990
992
  let wrapperPromise = resolve(promise, label).then(_v => {
@@ -1004,7 +1006,7 @@ function guardDestroyedStore(promise, store, label) {
1004
1006
  return promise;
1005
1007
  });
1006
1008
  return _guard(wrapperPromise, () => {
1007
- if (macroCondition(isDevelopingApp())) {
1009
+ if (isDevelopingApp()) {
1008
1010
  store._trackAsyncRequestEnd(token);
1009
1011
  }
1010
1012
  return _objectIsAlive(store);
@@ -1118,7 +1120,7 @@ class RelatedCollection extends RecordArray {
1118
1120
  switch (prop) {
1119
1121
  case 'length 0':
1120
1122
  {
1121
- this._manager.updateCache({
1123
+ this._manager.mutate({
1122
1124
  op: 'replaceRelatedRecords',
1123
1125
  record: this.identifier,
1124
1126
  field: this.key,
@@ -1129,7 +1131,7 @@ class RelatedCollection extends RecordArray {
1129
1131
  case 'replace cell':
1130
1132
  {
1131
1133
  const [index, prior, value] = args;
1132
- this._manager.updateCache({
1134
+ this._manager.mutate({
1133
1135
  op: 'replaceRelatedRecord',
1134
1136
  record: this.identifier,
1135
1137
  field: this.key,
@@ -1140,7 +1142,7 @@ class RelatedCollection extends RecordArray {
1140
1142
  break;
1141
1143
  }
1142
1144
  case 'push':
1143
- this._manager.updateCache({
1145
+ this._manager.mutate({
1144
1146
  op: 'addToRelatedRecords',
1145
1147
  record: this.identifier,
1146
1148
  field: this.key,
@@ -1149,7 +1151,7 @@ class RelatedCollection extends RecordArray {
1149
1151
  break;
1150
1152
  case 'pop':
1151
1153
  if (result) {
1152
- this._manager.updateCache({
1154
+ this._manager.mutate({
1153
1155
  op: 'removeFromRelatedRecords',
1154
1156
  record: this.identifier,
1155
1157
  field: this.key,
@@ -1158,7 +1160,7 @@ class RelatedCollection extends RecordArray {
1158
1160
  }
1159
1161
  break;
1160
1162
  case 'unshift':
1161
- this._manager.updateCache({
1163
+ this._manager.mutate({
1162
1164
  op: 'addToRelatedRecords',
1163
1165
  record: this.identifier,
1164
1166
  field: this.key,
@@ -1168,7 +1170,7 @@ class RelatedCollection extends RecordArray {
1168
1170
  break;
1169
1171
  case 'shift':
1170
1172
  if (result) {
1171
- this._manager.updateCache({
1173
+ this._manager.mutate({
1172
1174
  op: 'removeFromRelatedRecords',
1173
1175
  record: this.identifier,
1174
1176
  field: this.key,
@@ -1178,7 +1180,7 @@ class RelatedCollection extends RecordArray {
1178
1180
  }
1179
1181
  break;
1180
1182
  case 'sort':
1181
- this._manager.updateCache({
1183
+ this._manager.mutate({
1182
1184
  op: 'sortRelatedRecords',
1183
1185
  record: this.identifier,
1184
1186
  field: this.key,
@@ -1190,7 +1192,7 @@ class RelatedCollection extends RecordArray {
1190
1192
  const [start, removeCount, ...adds] = args;
1191
1193
  // detect a full replace
1192
1194
  if (removeCount > 0 && adds.length === this[SOURCE].length) {
1193
- this._manager.updateCache({
1195
+ this._manager.mutate({
1194
1196
  op: 'replaceRelatedRecords',
1195
1197
  record: this.identifier,
1196
1198
  field: this.key,
@@ -1199,7 +1201,7 @@ class RelatedCollection extends RecordArray {
1199
1201
  return;
1200
1202
  }
1201
1203
  if (removeCount > 0) {
1202
- this._manager.updateCache({
1204
+ this._manager.mutate({
1203
1205
  op: 'removeFromRelatedRecords',
1204
1206
  record: this.identifier,
1205
1207
  field: this.key,
@@ -1208,7 +1210,7 @@ class RelatedCollection extends RecordArray {
1208
1210
  });
1209
1211
  }
1210
1212
  if (adds?.length) {
1211
- this._manager.updateCache({
1213
+ this._manager.mutate({
1212
1214
  op: 'addToRelatedRecords',
1213
1215
  record: this.identifier,
1214
1216
  field: this.key,
@@ -1224,8 +1226,9 @@ class RelatedCollection extends RecordArray {
1224
1226
  }
1225
1227
  notify() {
1226
1228
  const tag = this[IDENTIFIER_ARRAY_TAG];
1227
- tag.ref = null;
1228
1229
  tag.shouldReset = true;
1230
+ // @ts-expect-error
1231
+ notifyArray(this);
1229
1232
  }
1230
1233
 
1231
1234
  /**
@@ -1277,6 +1280,7 @@ class RelatedCollection extends RecordArray {
1277
1280
  const {
1278
1281
  store
1279
1282
  } = this;
1283
+ assert(`Expected modelName to be set`, this.modelName);
1280
1284
  const record = store.createRecord(this.modelName, hash);
1281
1285
  this.push(record);
1282
1286
  return record;
@@ -1285,7 +1289,7 @@ class RelatedCollection extends RecordArray {
1285
1289
  RelatedCollection.prototype.isAsync = false;
1286
1290
  RelatedCollection.prototype.isPolymorphic = false;
1287
1291
  RelatedCollection.prototype.identifier = null;
1288
- RelatedCollection.prototype.recordData = null;
1292
+ RelatedCollection.prototype.cache = null;
1289
1293
  RelatedCollection.prototype._inverseIsAsync = false;
1290
1294
  RelatedCollection.prototype.key = '';
1291
1295
  RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
@@ -1429,7 +1433,7 @@ let PromiseManyArray = (_class$4 = class PromiseManyArray {
1429
1433
  }
1430
1434
  return false;
1431
1435
  };
1432
- } else if (macroCondition(isDevelopingApp())) {
1436
+ } else if (isDevelopingApp()) {
1433
1437
  const meta = Ember.meta(this);
1434
1438
  meta.hasMixin = mixin => {
1435
1439
  assert(`Do not use A() on an EmberData PromiseManyArray`);
@@ -1714,7 +1718,7 @@ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_PROMISE_MANY_ARRAY_BEHA
1714
1718
  `record.relationshipFor(key)`.
1715
1719
  */
1716
1720
  let assertPolymorphicType;
1717
- if (macroCondition(isDevelopingApp())) {
1721
+ if (isDevelopingApp()) {
1718
1722
  let checkPolymorphic = function checkPolymorphic(modelClass, addedModelClass) {
1719
1723
  if (modelClass.__isMixin) {
1720
1724
  return modelClass.__mixin.detect(addedModelClass.PrototypeMixin) ||
@@ -1966,7 +1970,8 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
1966
1970
  }
1967
1971
  _resource() {
1968
1972
  this._ref; // subscribe
1969
- return this.store._instanceCache.getRecordData(this.___identifier).getRelationship(this.___identifier, this.key);
1973
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.store._instanceCache.getResourceCache(this.___identifier) : this.store.cache;
1974
+ return cache.getRelationship(this.___identifier, this.key);
1970
1975
  }
1971
1976
 
1972
1977
  /**
@@ -2071,7 +2076,7 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
2071
2076
  }
2072
2077
  }
2073
2078
  let record = this.store.push(jsonApiDoc);
2074
- if (macroCondition(isDevelopingApp())) {
2079
+ if (isDevelopingApp()) {
2075
2080
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
2076
2081
  assertPolymorphicType(this.belongsToRelationship.identifier, this.belongsToRelationship.definition, recordIdentifierFor$1(record), this.store);
2077
2082
  }
@@ -2331,7 +2336,8 @@ let HasManyReference = (_class$2 = class HasManyReference {
2331
2336
  return [];
2332
2337
  }
2333
2338
  _resource() {
2334
- return this.store._instanceCache.getRecordData(this.___identifier).getRelationship(this.___identifier, this.key);
2339
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.store._instanceCache.getResourceCache(this.___identifier) : this.store.cache;
2340
+ return cache.getRelationship(this.___identifier, this.key);
2335
2341
  }
2336
2342
 
2337
2343
  /**
@@ -2581,7 +2587,7 @@ let HasManyReference = (_class$2 = class HasManyReference {
2581
2587
  data: obj
2582
2588
  });
2583
2589
  }
2584
- if (macroCondition(isDevelopingApp())) {
2590
+ if (isDevelopingApp()) {
2585
2591
  let relationshipMeta = this.hasManyRelationship.definition;
2586
2592
  let identifier = this.hasManyRelationship.identifier;
2587
2593
 
@@ -2774,9 +2780,9 @@ let HasManyReference = (_class$2 = class HasManyReference {
2774
2780
  class LegacySupport {
2775
2781
  constructor(record) {
2776
2782
  this.record = record;
2777
- this.store = storeFor$1(record);
2783
+ this.store = storeFor(record);
2778
2784
  this.identifier = recordIdentifierFor$1(record);
2779
- this.recordData = this.store._instanceCache.getRecordData(this.identifier);
2785
+ this.cache = peekCache(record);
2780
2786
  this._manyArrayCache = Object.create(null);
2781
2787
  this._relationshipPromisesCache = Object.create(null);
2782
2788
  this._relationshipProxyCache = Object.create(null);
@@ -2799,8 +2805,8 @@ class LegacySupport {
2799
2805
  currentState.length = 0;
2800
2806
  fastPush(currentState, identifiers);
2801
2807
  }
2802
- updateCache(operation) {
2803
- this.recordData.update(operation);
2808
+ mutate(mutation) {
2809
+ this.cache.mutate(mutation);
2804
2810
  }
2805
2811
  _findBelongsTo(key, resource, relationship, options) {
2806
2812
  // TODO @runspired follow up if parent isNew then we should not be attempting load here
@@ -2815,7 +2821,7 @@ class LegacySupport {
2815
2821
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
2816
2822
  const relationship = graphFor(this.store).get(this.identifier, key);
2817
2823
  assert(`Expected ${key} to be a belongs-to relationship`, isBelongsTo(relationship));
2818
- let resource = this.recordData.getRelationship(this.identifier, key);
2824
+ let resource = this.cache.getRelationship(this.identifier, key);
2819
2825
  relationship.state.hasFailedLoadAttempt = false;
2820
2826
  relationship.state.shouldForceReload = true;
2821
2827
  let promise = this._findBelongsTo(key, resource, relationship, options);
@@ -2829,9 +2835,9 @@ class LegacySupport {
2829
2835
  getBelongsTo(key, options) {
2830
2836
  const {
2831
2837
  identifier,
2832
- recordData
2838
+ cache
2833
2839
  } = this;
2834
- let resource = recordData.getRelationship(this.identifier, key);
2840
+ let resource = cache.getRelationship(this.identifier, key);
2835
2841
  let relatedIdentifier = resource && resource.data ? resource.data : null;
2836
2842
  assert(`Expected a stable identifier`, !relatedIdentifier || isStableIdentifier(relatedIdentifier));
2837
2843
  const store = this.store;
@@ -2867,7 +2873,7 @@ class LegacySupport {
2867
2873
  }
2868
2874
  }
2869
2875
  setDirtyBelongsTo(key, value) {
2870
- return this.recordData.update({
2876
+ return this.cache.mutate({
2871
2877
  op: 'replaceRelatedRecord',
2872
2878
  record: this.identifier,
2873
2879
  field: key,
@@ -2877,7 +2883,7 @@ class LegacySupport {
2877
2883
  true);
2878
2884
  }
2879
2885
  _getCurrentState(identifier, field) {
2880
- let jsonApi = this.recordData.getRelationship(identifier, field, true);
2886
+ let jsonApi = this.cache.getRelationship(identifier, field, true);
2881
2887
  const cache = this.store._instanceCache;
2882
2888
  let identifiers = [];
2883
2889
  if (jsonApi.data) {
@@ -2892,7 +2898,7 @@ class LegacySupport {
2892
2898
  return [identifiers, jsonApi];
2893
2899
  }
2894
2900
  getManyArray(key, definition) {
2895
- if (moduleExists("@ember-data/json-api")) {
2901
+ if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2896
2902
  let manyArray = this._manyArrayCache[key];
2897
2903
  if (!definition) {
2898
2904
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
@@ -2904,7 +2910,7 @@ class LegacySupport {
2904
2910
  store: this.store,
2905
2911
  type: definition.type,
2906
2912
  identifier: this.identifier,
2907
- recordData: this.recordData,
2913
+ cache: this.cache,
2908
2914
  identifiers,
2909
2915
  key,
2910
2916
  meta: doc.meta || null,
@@ -2923,12 +2929,12 @@ class LegacySupport {
2923
2929
  assert('hasMany only works with the @ember-data/json-api package');
2924
2930
  }
2925
2931
  fetchAsyncHasMany(key, relationship, manyArray, options) {
2926
- if (moduleExists("@ember-data/json-api")) {
2932
+ if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2927
2933
  let loadingPromise = this._relationshipPromisesCache[key];
2928
2934
  if (loadingPromise) {
2929
2935
  return loadingPromise;
2930
2936
  }
2931
- const jsonApi = this.recordData.getRelationship(this.identifier, key);
2937
+ const jsonApi = this.cache.getRelationship(this.identifier, key);
2932
2938
  const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
2933
2939
  if (!promise) {
2934
2940
  manyArray.isLoaded = true;
@@ -2941,7 +2947,7 @@ class LegacySupport {
2941
2947
  assert('hasMany only works with the @ember-data/json-api package');
2942
2948
  }
2943
2949
  reloadHasMany(key, options) {
2944
- if (moduleExists("@ember-data/json-api")) {
2950
+ if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2945
2951
  let loadingPromise = this._relationshipPromisesCache[key];
2946
2952
  if (loadingPromise) {
2947
2953
  return loadingPromise;
@@ -2966,7 +2972,7 @@ class LegacySupport {
2966
2972
  assert(`hasMany only works with the @ember-data/json-api package`);
2967
2973
  }
2968
2974
  getHasMany(key, options) {
2969
- if (moduleExists("@ember-data/json-api")) {
2975
+ if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
2970
2976
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
2971
2977
  const relationship = graphFor(this.store).get(this.identifier, key);
2972
2978
  const {
@@ -3024,7 +3030,7 @@ class LegacySupport {
3024
3030
  referenceFor(kind, name) {
3025
3031
  let reference = this.references[name];
3026
3032
  if (!reference) {
3027
- if (!moduleExists("@ember-data/json-api")) {
3033
+ if (macroCondition(!getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
3028
3034
  // TODO @runspired while this feels odd, it is not a regression in capability because we do
3029
3035
  // not today support references pulling from RecordDatas other than our own
3030
3036
  // because of the intimate API access involved. This is something we will need to redesign.
@@ -3033,7 +3039,7 @@ class LegacySupport {
3033
3039
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
3034
3040
  const graph = graphFor(this.store);
3035
3041
  const relationship = graph.get(this.identifier, name);
3036
- if (macroCondition(isDevelopingApp())) {
3042
+ if (isDevelopingApp()) {
3037
3043
  if (kind) {
3038
3044
  let modelName = this.identifier.type;
3039
3045
  let actualRelationshipKind = relationship.definition.kind;
@@ -3051,7 +3057,7 @@ class LegacySupport {
3051
3057
  return reference;
3052
3058
  }
3053
3059
  _findHasManyByJsonApiResource(resource, parentIdentifier, relationship, options = {}) {
3054
- if (moduleExists("@ember-data/json-api")) {
3060
+ if (macroCondition(getOwnConfig().packages.HAS_JSON_API_PACKAGE)) {
3055
3061
  if (!resource) {
3056
3062
  return;
3057
3063
  }
@@ -3105,11 +3111,11 @@ class LegacySupport {
3105
3111
  return;
3106
3112
  }
3107
3113
  let finds = new Array(resource.data.length);
3108
- let cache = this.store._instanceCache;
3114
+ let cache = this.store._fetchManager;
3109
3115
  for (let i = 0; i < resource.data.length; i++) {
3110
3116
  const identifier = resource.data[i];
3111
3117
  assert(`expected a stable identifier`, isStableIdentifier(identifier));
3112
- finds[i] = cache._fetchDataIfNeededForIdentifier(identifier, options);
3118
+ finds[i] = cache.fetchDataIfNeededForIdentifier(identifier, options);
3113
3119
  }
3114
3120
  return all(finds);
3115
3121
  }
@@ -3180,7 +3186,7 @@ class LegacySupport {
3180
3186
  if (!identifier) {
3181
3187
  assert(`No Information found for ${resource.data.lid}`, identifier);
3182
3188
  }
3183
- return this.store._instanceCache._fetchDataIfNeededForIdentifier(identifier, options);
3189
+ return this.store._fetchManager.fetchDataIfNeededForIdentifier(identifier, options);
3184
3190
  }
3185
3191
  let resourceIsLocal = !localDataIsEmpty && resource.data.id === null;
3186
3192
  if (identifier && resourceIsLocal) {
@@ -3355,7 +3361,8 @@ function notifyRelationship(identifier, key, record, meta) {
3355
3361
  }
3356
3362
  function notifyAttribute(store, identifier, key, record) {
3357
3363
  let currentValue = cacheFor(record, key);
3358
- if (currentValue !== store._instanceCache.getRecordData(identifier).getAttr(identifier, key)) {
3364
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? peekCache(record) : store.cache;
3365
+ if (currentValue !== cache.getAttr(identifier, key)) {
3359
3366
  record.notifyPropertyChange(key);
3360
3367
  }
3361
3368
  }
@@ -3384,6 +3391,9 @@ let Tag = (_class$1 = class Tag {
3384
3391
  this.rev = 1;
3385
3392
  this.isDirty = true;
3386
3393
  this.value = undefined;
3394
+ /*
3395
+ * whether this was part of a transaction when mutated
3396
+ */
3387
3397
  this.t = false;
3388
3398
  }
3389
3399
  notify() {
@@ -3487,11 +3497,11 @@ root
3487
3497
  let RecordState = (_class3 = class RecordState {
3488
3498
  constructor(record) {
3489
3499
  _initializerDefineProperty(this, "isSaving", _descriptor2, this);
3490
- const store = storeFor(record);
3500
+ const store = storeFor$1(record);
3491
3501
  const identity = recordIdentifierFor$1(record);
3492
3502
  this.identifier = identity;
3493
3503
  this.record = record;
3494
- this.cache = store._instanceCache.getRecordData(identity);
3504
+ this.cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? peekCache(record) : store.cache;
3495
3505
  this.pendingCount = 0;
3496
3506
  this.fulfilledCount = 0;
3497
3507
  this.rejectedCount = 0;
@@ -3551,7 +3561,7 @@ let RecordState = (_class3 = class RecordState {
3551
3561
 
3552
3562
  // we instantiate lazily
3553
3563
  // so we grab anything we don't have yet
3554
- if (macroCondition(!isDevelopingApp())) {
3564
+ if (!isDevelopingApp()) {
3555
3565
  const lastRequest = requests.getLastRequestForRecord(identity);
3556
3566
  if (lastRequest) {
3557
3567
  handleRequest(lastRequest);
@@ -3576,7 +3586,7 @@ let RecordState = (_class3 = class RecordState {
3576
3586
  });
3577
3587
  }
3578
3588
  destroy() {
3579
- storeFor(this.record).notifications.unsubscribe(this.handler);
3589
+ storeFor$1(this.record).notifications.unsubscribe(this.handler);
3580
3590
  }
3581
3591
  notify(key) {
3582
3592
  getTag(this, key).notify();
@@ -3810,7 +3820,7 @@ class RelationshipDefinition {
3810
3820
  inverse = modelClass.inverseFor(this.key, store);
3811
3821
  }
3812
3822
  // TODO make this error again for the non-polymorphic case
3813
- if (macroCondition(isDevelopingApp())) {
3823
+ if (isDevelopingApp()) {
3814
3824
  if (!this.options.polymorphic) {
3815
3825
  modelClass.typeForRelationship(this.key, store);
3816
3826
  }
@@ -3835,6 +3845,7 @@ function lookupLegacySupport(record) {
3835
3845
  const identifier = recordIdentifierFor(record);
3836
3846
  let support = LEGACY_SUPPORT.get(identifier);
3837
3847
  if (!support) {
3848
+ assert(`Memory Leak Detected`, !record.isDestroyed && !record.isDestroying);
3838
3849
  support = new LegacySupport(record);
3839
3850
  LEGACY_SUPPORT.set(identifier, support);
3840
3851
  LEGACY_SUPPORT.set(record, support);
@@ -3927,7 +3938,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3927
3938
  _initializerDefineProperty(this, "isReloading", _descriptor, this);
3928
3939
  }
3929
3940
  init(options = {}) {
3930
- if (macroCondition(isDevelopingApp())) {
3941
+ if (isDevelopingApp()) {
3931
3942
  if (!options._secretInit && !options._createProps) {
3932
3943
  throw new Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.');
3933
3944
  }
@@ -3939,8 +3950,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3939
3950
  let store = this.store = _secretInit.store;
3940
3951
  super.init(options);
3941
3952
  let identity = _secretInit.identifier;
3942
- _secretInit.cb(this, _secretInit.recordData, identity, _secretInit.store);
3943
- this.___recordState = macroCondition(isDevelopingApp()) ? new RecordState(this) : null;
3953
+ _secretInit.cb(this, _secretInit.cache, identity, _secretInit.store);
3954
+ this.___recordState = isDevelopingApp() ? new RecordState(this) : null;
3944
3955
  this.setProperties(createProps);
3945
3956
  let notifications = store.notifications;
3946
3957
  this.___private_notifications = notifications.subscribe(identity, (identifier, type, key) => {
@@ -3950,7 +3961,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
3950
3961
  destroy() {
3951
3962
  const identifier = recordIdentifierFor(this);
3952
3963
  this.___recordState?.destroy();
3953
- const store = storeFor(this);
3964
+ const store = storeFor$1(this);
3954
3965
  store.notifications.unsubscribe(this.___private_notifications);
3955
3966
  // Legacy behavior is to notify the relationships on destroy
3956
3967
  // such that they "clear". It's uncertain this behavior would
@@ -4185,7 +4196,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4185
4196
  return this.currentState.isError;
4186
4197
  }
4187
4198
  set isError(v) {
4188
- if (macroCondition(isDevelopingApp())) {
4199
+ if (isDevelopingApp()) {
4189
4200
  throw new Error(`isError is not directly settable`);
4190
4201
  }
4191
4202
  }
@@ -4210,7 +4221,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4210
4221
  // this guard exists, because some dev-only deprecation code
4211
4222
  // (addListener via validatePropertyInjections) invokes toString before the
4212
4223
  // object is real.
4213
- if (macroCondition(isDevelopingApp())) {
4224
+ if (isDevelopingApp()) {
4214
4225
  try {
4215
4226
  return recordIdentifierFor(this).id;
4216
4227
  } catch {
@@ -4245,7 +4256,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4245
4256
  // when using legacy/classic ember classes. Basically: lazy in prod and eager in dev.
4246
4257
  // so we do this to try to steer folks to the nicer "dont user currentState"
4247
4258
  // error.
4248
- if (macroCondition(!isDevelopingApp())) {
4259
+ if (!isDevelopingApp()) {
4249
4260
  if (!this.___recordState) {
4250
4261
  this.___recordState = new RecordState(this);
4251
4262
  }
@@ -4341,7 +4352,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4341
4352
  @return {Object} an object whose values are primitive JSON values only
4342
4353
  */
4343
4354
  serialize(options) {
4344
- return storeFor(this)._instanceCache.createSnapshot(recordIdentifierFor(this)).serialize(options);
4355
+ return storeFor$1(this)._instanceCache.createSnapshot(recordIdentifierFor(this)).serialize(options);
4345
4356
  }
4346
4357
 
4347
4358
  /*
@@ -4390,7 +4401,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4390
4401
  deleteRecord() {
4391
4402
  // ensure we've populated currentState prior to deleting a new record
4392
4403
  if (this.currentState) {
4393
- storeFor(this).deleteRecord(this);
4404
+ storeFor$1(this).deleteRecord(this);
4394
4405
  }
4395
4406
  }
4396
4407
 
@@ -4457,7 +4468,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4457
4468
  if (this.currentState.isNew && (this.isDestroyed || this.isDestroying)) {
4458
4469
  return;
4459
4470
  }
4460
- storeFor(this).unloadRecord(this);
4471
+ storeFor$1(this).unloadRecord(this);
4461
4472
  }
4462
4473
 
4463
4474
  /**
@@ -4513,7 +4524,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4513
4524
  and value is an [oldProp, newProp] array.
4514
4525
  */
4515
4526
  changedAttributes() {
4516
- return recordDataFor(this).changedAttrs(recordIdentifierFor(this));
4527
+ return peekCache(this).changedAttrs(recordIdentifierFor(this));
4517
4528
  }
4518
4529
 
4519
4530
  /**
@@ -4538,8 +4549,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4538
4549
  const {
4539
4550
  isNew
4540
4551
  } = currentState;
4541
- storeFor(this)._join(() => {
4542
- recordDataFor(this).rollbackAttrs(recordIdentifierFor(this));
4552
+ storeFor$1(this)._join(() => {
4553
+ peekCache(this).rollbackAttrs(recordIdentifierFor(this));
4543
4554
  this.errors.clear();
4544
4555
  currentState.cleanErrorRequests();
4545
4556
  if (isNew) {
@@ -4554,7 +4565,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4554
4565
  */
4555
4566
  // TODO @deprecate in favor of a public API or examples of how to test successfully
4556
4567
  _createSnapshot() {
4557
- return storeFor(this)._instanceCache.createSnapshot(recordIdentifierFor(this));
4568
+ return storeFor$1(this)._instanceCache.createSnapshot(recordIdentifierFor(this));
4558
4569
  }
4559
4570
 
4560
4571
  /**
@@ -4596,7 +4607,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4596
4607
  if (this.currentState.isNew && this.currentState.isDeleted) {
4597
4608
  promise = resolve(this);
4598
4609
  } else {
4599
- promise = storeFor(this).saveRecord(this, options);
4610
+ promise = storeFor$1(this).saveRecord(this, options);
4600
4611
  }
4601
4612
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SAVE_PROMISE_ACCESS)) {
4602
4613
  return deprecatedPromiseObject(promise);
@@ -4636,7 +4647,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4636
4647
  let identifier = recordIdentifierFor(this);
4637
4648
  assert(`You cannot reload a record without an ID`, identifier.id);
4638
4649
  this.isReloading = true;
4639
- const promise = storeFor(this)._fetchManager.scheduleFetch(identifier, options).then(() => this).finally(() => {
4650
+ const promise = storeFor$1(this)._fetchManager.scheduleFetch(identifier, options).then(() => this).finally(() => {
4640
4651
  this.isReloading = false;
4641
4652
  });
4642
4653
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SAVE_PROMISE_ACCESS)) {
@@ -4804,7 +4815,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4804
4815
  return this.constructor.relationshipsByName.get(name);
4805
4816
  }
4806
4817
  inverseFor(key) {
4807
- return this.constructor.inverseFor(key, storeFor(this));
4818
+ return this.constructor.inverseFor(key, storeFor$1(this));
4808
4819
  }
4809
4820
  eachAttribute(callback, binding) {
4810
4821
  this.constructor.eachAttribute(callback, binding);
@@ -4976,7 +4987,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4976
4987
  if (possibleRelationships.length === 0) {
4977
4988
  return null;
4978
4989
  }
4979
- if (macroCondition(isDevelopingApp())) {
4990
+ if (isDevelopingApp()) {
4980
4991
  let filteredRelationships = possibleRelationships.filter(possibleRelationship => {
4981
4992
  let optionsForRelationship = possibleRelationship.options;
4982
4993
  return name === optionsForRelationship.inverse;
@@ -4994,7 +5005,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
4994
5005
  }
4995
5006
 
4996
5007
  // ensure inverse is properly configured
4997
- if (macroCondition(isDevelopingApp())) {
5008
+ if (isDevelopingApp()) {
4998
5009
  if (isPolymorphic) {
4999
5010
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_NON_EXPLICIT_POLYMORPHISM)) {
5000
5011
  if (!inverseOptions.as) {
@@ -5016,7 +5027,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
5016
5027
  }
5017
5028
 
5018
5029
  // ensure we are properly configured
5019
- if (macroCondition(isDevelopingApp())) {
5030
+ if (isDevelopingApp()) {
5020
5031
  if (inverseOptions.polymorphic) {
5021
5032
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_NON_EXPLICIT_POLYMORPHISM)) {
5022
5033
  if (!options.as) {
@@ -5182,7 +5193,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
5182
5193
  import { get } from '@ember/object';
5183
5194
  import Blog from 'app/models/blog';
5184
5195
  let relatedTypes = Blog.relatedTypes');
5185
- //=> [ User, Post ]
5196
+ //=> ['user', 'post']
5186
5197
  ```
5187
5198
  @property relatedTypes
5188
5199
  @public
@@ -5702,7 +5713,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
5702
5713
  // the values initialized during create to `setUnknownProperty`
5703
5714
  Model.prototype._createProps = null;
5704
5715
  Model.prototype._secretInit = null;
5705
- if (getOwnConfig().includeDataAdapter) {
5716
+ if (macroCondition(getOwnConfig().includeDataAdapter)) {
5706
5717
  /**
5707
5718
  Provides info about the model for debugging purposes
5708
5719
  by grouping the properties into more semantic groups.
@@ -5754,7 +5765,7 @@ if (getOwnConfig().includeDataAdapter) {
5754
5765
  };
5755
5766
  };
5756
5767
  }
5757
- if (macroCondition(isDevelopingApp())) {
5768
+ if (isDevelopingApp()) {
5758
5769
  let lookupDescriptor = function lookupDescriptor(obj, keyName) {
5759
5770
  let current = obj;
5760
5771
  do {
@@ -6003,7 +6014,7 @@ function belongsTo(modelName, options) {
6003
6014
  return null;
6004
6015
  }
6005
6016
  const support = lookupLegacySupport(this);
6006
- if (macroCondition(isDevelopingApp())) {
6017
+ if (isDevelopingApp()) {
6007
6018
  if (['currentState'].indexOf(key) !== -1) {
6008
6019
  throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`);
6009
6020
  }
@@ -6022,7 +6033,7 @@ function belongsTo(modelName, options) {
6022
6033
  },
6023
6034
  set(key, value) {
6024
6035
  const support = lookupLegacySupport(this);
6025
- if (macroCondition(isDevelopingApp())) {
6036
+ if (isDevelopingApp()) {
6026
6037
  if (['currentState'].indexOf(key) !== -1) {
6027
6038
  throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`);
6028
6039
  }
@@ -6253,7 +6264,7 @@ function hasMany(type, options) {
6253
6264
  };
6254
6265
  return computed({
6255
6266
  get(key) {
6256
- if (macroCondition(isDevelopingApp())) {
6267
+ if (isDevelopingApp()) {
6257
6268
  if (['currentState'].indexOf(key) !== -1) {
6258
6269
  throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`);
6259
6270
  }
@@ -6264,7 +6275,7 @@ function hasMany(type, options) {
6264
6275
  return lookupLegacySupport(this).getHasMany(key);
6265
6276
  },
6266
6277
  set(key, records) {
6267
- if (macroCondition(isDevelopingApp())) {
6278
+ if (isDevelopingApp()) {
6268
6279
  if (['currentState'].indexOf(key) !== -1) {
6269
6280
  throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`);
6270
6281
  }