@ember-data/store 4.12.0-alpha.7 → 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.
@@ -38,6 +38,26 @@ function normalizeModelName$1(modelName) {
38
38
  return dasherize(modelName);
39
39
  }
40
40
 
41
+ /*
42
+ * Returns the Cache instance associated with a given
43
+ * Model or Identifier
44
+ */
45
+
46
+ const CacheForIdentifierCache = new Map();
47
+ function setCacheFor(identifier, cache) {
48
+ assert(`Illegal set of identifier`, !CacheForIdentifierCache.has(identifier) || CacheForIdentifierCache.get(identifier) === cache);
49
+ CacheForIdentifierCache.set(identifier, cache);
50
+ }
51
+ function removeRecordDataFor(identifier) {
52
+ CacheForIdentifierCache.delete(identifier);
53
+ }
54
+ function peekCache(instance) {
55
+ if (CacheForIdentifierCache.has(instance)) {
56
+ return CacheForIdentifierCache.get(instance);
57
+ }
58
+ return null;
59
+ }
60
+
41
61
  /**
42
62
  @module @ember-data/store
43
63
  */
@@ -386,6 +406,7 @@ class IdentifierCache {
386
406
  @returns {StableRecordIdentifier}
387
407
  @public
388
408
  */
409
+
389
410
  getOrCreateRecordIdentifier(resource) {
390
411
  return this._getRecordIdentifier(resource, true);
391
412
  }
@@ -421,7 +442,7 @@ class IdentifierCache {
421
442
  }
422
443
  if (macroCondition(getOwnConfig().debug.LOG_IDENTIFIERS)) {
423
444
  // eslint-disable-next-line no-console
424
- console.log(`Identifiers: createded identifier ${String(identifier)} for newly generated resource`, data);
445
+ console.log(`Identifiers: created identifier ${String(identifier)} for newly generated resource`, data);
425
446
  }
426
447
  return identifier;
427
448
  }
@@ -708,6 +729,10 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con
708
729
  return desc;
709
730
  }
710
731
  let tokenId = 0;
732
+ const CacheOperations = new Set(['added', 'removed', 'state', 'updated']);
733
+ function isCacheOperationValue(value) {
734
+ return CacheOperations.has(value);
735
+ }
711
736
  const Cache = new Map();
712
737
  const Tokens = new Map();
713
738
  // TODO this isn't importable anyway, remove and use a map on the manager?
@@ -763,7 +788,7 @@ class NotificationManager {
763
788
  * @returns {UnsubscribeToken} an opaque token to be used with unsubscribe
764
789
  */
765
790
  subscribe(identifier, callback) {
766
- assert(`Expected to receive a stable Identifier to subscribe to`, isStableIdentifier(identifier));
791
+ assert(`Expected to receive a stable Identifier to subscribe to`, identifier === 'resource' || identifier === 'document' || isStableIdentifier(identifier));
767
792
  let map = Cache.get(identifier);
768
793
  if (!map) {
769
794
  map = new Map();
@@ -790,27 +815,46 @@ class NotificationManager {
790
815
  }
791
816
  }
792
817
 
793
- // deactivated type signature overloads because pass-through was failing to match any. Bring back if possible.
794
- // notify(identifier: StableRecordIdentifier, value: 'attributes' | 'relationships', key?: string): boolean;
795
- // notify(identifier: StableRecordIdentifier, value: 'errors' | 'meta' | 'identity' | 'state'): boolean;
818
+ /**
819
+ * Custom Caches and Application Code should not call this method directly.
820
+ *
821
+ * @method notify
822
+ * @param identifier
823
+ * @param value
824
+ * @param key
825
+ * @return {Boolean} whether a notification was delivered to any subscribers
826
+ * @private
827
+ */
828
+
796
829
  notify(identifier, value, key) {
797
- assert(`Notify does not accept a key argument for the namespace '${value}'. Received key '${key}'.`, !key || value === 'attributes' || value === 'relationships');
830
+ assert(`Notify does not accept a key argument for the namespace '${value}'. Received key '${key || ''}'.`, !key || value === 'attributes' || value === 'relationships');
798
831
  if (!isStableIdentifier(identifier)) {
799
832
  if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
800
833
  // eslint-disable-next-line no-console
801
- console.log(`Notifying: Expected to receive a stable Identifier to notify '${value}' '${key}' with, but ${String(identifier)} is not in the cache`, identifier);
834
+ console.log(`Notifying: Expected to receive a stable Identifier to notify '${value}' '${key || ''}' with, but ${String(identifier)} is not in the cache`, identifier);
802
835
  }
803
836
  return false;
804
837
  }
805
838
  if (macroCondition(getOwnConfig().debug.LOG_NOTIFICATIONS)) {
806
839
  // eslint-disable-next-line no-console
807
- console.log(`Notifying: ${String(identifier)}\t${value}\t${key}`);
840
+ console.log(`Notifying: ${String(identifier)}\t${value}\t${key || ''}`);
841
+ }
842
+
843
+ // TODO for documents this will need to switch based on Identifier kind
844
+ if (isCacheOperationValue(value)) {
845
+ let callbackMap = Cache.get('resource');
846
+ if (callbackMap) {
847
+ callbackMap.forEach(cb => {
848
+ cb(identifier, value);
849
+ });
850
+ }
808
851
  }
809
852
  let callbackMap = Cache.get(identifier);
810
853
  if (!callbackMap || !callbackMap.size) {
811
854
  return false;
812
855
  }
813
856
  callbackMap.forEach(cb => {
857
+ // @ts-expect-error overload doesn't narrow within body
814
858
  cb(identifier, value, key);
815
859
  });
816
860
  return true;
@@ -1025,14 +1069,49 @@ var id = 0;
1025
1069
  function _classPrivateFieldKey(name) {
1026
1070
  return "__private_" + id++ + "_" + name;
1027
1071
  }
1028
- var _store = /*#__PURE__*/_classPrivateFieldKey("store");
1029
- var _recordData = /*#__PURE__*/_classPrivateFieldKey("recordData");
1030
- var _identifier = /*#__PURE__*/_classPrivateFieldKey("identifier");
1031
- var _isDeprecated = /*#__PURE__*/_classPrivateFieldKey("isDeprecated");
1072
+ function legacyCachePut(store, doc) {
1073
+ const jsonApiDoc = doc.data;
1074
+ let ret;
1075
+ store._join(() => {
1076
+ let included = jsonApiDoc.included;
1077
+ let i, length;
1078
+ if (included) {
1079
+ for (i = 0, length = included.length; i < length; i++) {
1080
+ store._instanceCache.loadData(included[i]);
1081
+ }
1082
+ }
1083
+ if (Array.isArray(jsonApiDoc.data)) {
1084
+ length = jsonApiDoc.data.length;
1085
+ let identifiers = [];
1086
+ for (i = 0; i < length; i++) {
1087
+ identifiers.push(store._instanceCache.loadData(jsonApiDoc.data[i]));
1088
+ }
1089
+ ret = {
1090
+ data: identifiers
1091
+ };
1092
+ return;
1093
+ }
1094
+ if (jsonApiDoc.data === null) {
1095
+ ret = {
1096
+ data: null
1097
+ };
1098
+ return;
1099
+ }
1100
+ assert(`Expected an object in the 'data' property in a call to 'push', but was ${typeof jsonApiDoc.data}`, typeof jsonApiDoc.data === 'object');
1101
+ ret = {
1102
+ data: store._instanceCache.loadData(jsonApiDoc.data)
1103
+ };
1104
+ return;
1105
+ });
1106
+ return ret;
1107
+ }
1108
+
1032
1109
  /**
1033
- * The CacheManager wraps a Cache
1034
- * enforcing that only the public API surface area
1035
- * is exposed.
1110
+ * The CacheManager wraps a Cache enforcing that only
1111
+ * the public API surface area is exposed.
1112
+ *
1113
+ * Hence, it is the value of `Store.cache`, wrapping
1114
+ * the cache instance returned by `Store.createCache`.
1036
1115
  *
1037
1116
  * This class is the the return value of both the
1038
1117
  * `recordDataFor` function supplied to the store
@@ -1069,11 +1148,15 @@ var _isDeprecated = /*#__PURE__*/_classPrivateFieldKey("isDeprecated");
1069
1148
  * @class CacheManager
1070
1149
  * @public
1071
1150
  */
1151
+ var _store = /*#__PURE__*/_classPrivateFieldKey("store");
1152
+ var _cache = /*#__PURE__*/_classPrivateFieldKey("cache");
1153
+ var _identifier = /*#__PURE__*/_classPrivateFieldKey("identifier");
1154
+ var _isDeprecated = /*#__PURE__*/_classPrivateFieldKey("isDeprecated");
1072
1155
  class NonSingletonCacheManager {
1073
1156
  get managedVersion() {
1074
- return _classPrivateFieldBase(this, _recordData)[_recordData].version || '1';
1157
+ return _classPrivateFieldBase(this, _cache)[_cache].version || '1';
1075
1158
  }
1076
- constructor(store, _recordData2, identifier) {
1159
+ constructor(store, _cache2, identifier) {
1077
1160
  Object.defineProperty(this, _isDeprecated, {
1078
1161
  value: _isDeprecated2
1079
1162
  });
@@ -1082,7 +1165,7 @@ class NonSingletonCacheManager {
1082
1165
  writable: true,
1083
1166
  value: void 0
1084
1167
  });
1085
- Object.defineProperty(this, _recordData, {
1168
+ Object.defineProperty(this, _cache, {
1086
1169
  writable: true,
1087
1170
  value: void 0
1088
1171
  });
@@ -1091,9 +1174,9 @@ class NonSingletonCacheManager {
1091
1174
  value: void 0
1092
1175
  });
1093
1176
  _classPrivateFieldBase(this, _store)[_store] = store;
1094
- _classPrivateFieldBase(this, _recordData)[_recordData] = _recordData2;
1177
+ _classPrivateFieldBase(this, _cache)[_cache] = _cache2;
1095
1178
  _classPrivateFieldBase(this, _identifier)[_identifier] = identifier;
1096
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](_recordData2)) {
1179
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](_cache2)) {
1097
1180
  deprecate(`This RecordData uses the deprecated V1 RecordData Spec. Upgrade to V2 to maintain compatibility.`, false, {
1098
1181
  id: 'ember-data:deprecate-v1-cache',
1099
1182
  until: '5.0',
@@ -1105,11 +1188,46 @@ class NonSingletonCacheManager {
1105
1188
  });
1106
1189
  }
1107
1190
  }
1191
+
1192
+ /**
1193
+ * Cache the response to a request
1194
+ *
1195
+ * Unlike `store.push` which has UPSERT
1196
+ * semantics, `put` has `replace` semantics similar to
1197
+ * the `http` method `PUT`
1198
+ *
1199
+ * the individually cacheabl
1200
+ * e resource data it may contain
1201
+ * should upsert, but the document data surrounding it should
1202
+ * fully replace any existing information
1203
+ *
1204
+ * Note that in order to support inserting arbitrary data
1205
+ * to the cache that did not originate from a request `put`
1206
+ * should expect to sometimes encounter a document with only
1207
+ * a `data` member and therefor must not assume the existence
1208
+ * of `request` and `response` on the document.
1209
+ *
1210
+ * @method put
1211
+ * @param {StructuredDocument} doc
1212
+ * @returns {ResourceDocument}
1213
+ * @public
1214
+ */
1215
+ put(doc) {
1216
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1217
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1218
+ if (doc instanceof Error) {
1219
+ // in legacy we don't know how to handle this
1220
+ throw doc;
1221
+ }
1222
+ return legacyCachePut(_classPrivateFieldBase(this, _store)[_store], doc);
1223
+ }
1224
+ return cache.put(doc);
1225
+ }
1108
1226
  // Cache
1109
1227
  // =====
1110
1228
 
1111
1229
  /**
1112
- * Retrieve the identifier for this v1 recordData
1230
+ * Retrieve the identifier for this v1 cache
1113
1231
  *
1114
1232
  * DEPRECATED Caches should not be assumed to be 1:1 with resources
1115
1233
  *
@@ -1124,25 +1242,41 @@ class NonSingletonCacheManager {
1124
1242
  /**
1125
1243
  * Push resource data from a remote source into the cache for this identifier
1126
1244
  *
1245
+ * DEPRECATED Use upsert. Caches should not be assumed to be 1:1 with resources
1246
+ *
1127
1247
  * @method pushData
1248
+ * @param data
1249
+ * @param hasRecord
1250
+ * @returns {void | string[]} if `hasRecord` is true then calculated key changes should be returned
1251
+ * @public
1252
+ * @deprecated
1253
+ */
1254
+ pushData(data, hasRecord) {
1255
+ return this.upsert(_classPrivateFieldBase(this, _identifier)[_identifier], data, hasRecord);
1256
+ }
1257
+
1258
+ /**
1259
+ * Push resource data from a remote source into the cache for this identifier
1260
+ *
1261
+ * @method upsert
1128
1262
  * @public
1129
1263
  * @param identifier
1130
1264
  * @param data
1131
1265
  * @param hasRecord
1132
1266
  * @returns {void | string[]} if `hasRecord` is true then calculated key changes should be returned
1133
1267
  */
1134
- pushData(identifier, data, hasRecord) {
1135
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1268
+ upsert(identifier, data, hasRecord) {
1269
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1136
1270
  // called by something V1
1137
1271
  if (!isStableIdentifier(identifier)) {
1138
1272
  data = identifier;
1139
1273
  hasRecord = data;
1140
1274
  identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1141
1275
  }
1142
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1143
- return recordData.pushData(data, hasRecord);
1276
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1277
+ return cache.pushData(data, hasRecord);
1144
1278
  }
1145
- return recordData.pushData(identifier, data, hasRecord);
1279
+ return cache.upsert(identifier, data, hasRecord);
1146
1280
  }
1147
1281
 
1148
1282
  /**
@@ -1151,17 +1285,17 @@ class NonSingletonCacheManager {
1151
1285
  * Note: currently the only valid operation is a MergeOperation
1152
1286
  * which occurs when a collision of identifiers is detected.
1153
1287
  *
1154
- * @method sync
1288
+ * @method patch
1155
1289
  * @public
1156
1290
  * @param op the operation to perform
1157
1291
  * @returns {void}
1158
1292
  */
1159
- sync(op) {
1160
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1161
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1293
+ patch(op) {
1294
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1295
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1162
1296
  return;
1163
1297
  }
1164
- recordData.sync(op);
1298
+ cache.patch(op);
1165
1299
  }
1166
1300
 
1167
1301
  /**
@@ -1174,25 +1308,25 @@ class NonSingletonCacheManager {
1174
1308
  */
1175
1309
  // isCollection is only needed for interop with v1 cache
1176
1310
  update(operation, isResource) {
1177
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](_classPrivateFieldBase(this, _recordData)[_recordData])) {
1311
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](_classPrivateFieldBase(this, _cache)[_cache])) {
1178
1312
  const cache = _classPrivateFieldBase(this, _store)[_store]._instanceCache;
1179
1313
  switch (operation.op) {
1180
1314
  case 'addToRelatedRecords':
1181
- _classPrivateFieldBase(this, _recordData)[_recordData].addToHasMany(operation.field, operation.value.map(i => cache.getRecordData(i)), operation.index);
1315
+ _classPrivateFieldBase(this, _cache)[_cache].addToHasMany(operation.field, operation.value.map(i => cache.getResourceCache(i)), operation.index);
1182
1316
  return;
1183
1317
  case 'removeFromRelatedRecords':
1184
- _classPrivateFieldBase(this, _recordData)[_recordData].removeFromHasMany(operation.field, operation.value.map(i => cache.getRecordData(i)));
1318
+ _classPrivateFieldBase(this, _cache)[_cache].removeFromHasMany(operation.field, operation.value.map(i => cache.getResourceCache(i)));
1185
1319
  return;
1186
1320
  case 'replaceRelatedRecords':
1187
- _classPrivateFieldBase(this, _recordData)[_recordData].setDirtyHasMany(operation.field, operation.value.map(i => cache.getRecordData(i)));
1321
+ _classPrivateFieldBase(this, _cache)[_cache].setDirtyHasMany(operation.field, operation.value.map(i => cache.getResourceCache(i)));
1188
1322
  return;
1189
1323
  case 'replaceRelatedRecord':
1190
1324
  if (isResource) {
1191
- _classPrivateFieldBase(this, _recordData)[_recordData].setDirtyBelongsTo(operation.field, operation.value ? cache.getRecordData(operation.value) : null);
1325
+ _classPrivateFieldBase(this, _cache)[_cache].setDirtyBelongsTo(operation.field, operation.value ? cache.getResourceCache(operation.value) : null);
1192
1326
  return;
1193
1327
  }
1194
- _classPrivateFieldBase(this, _recordData)[_recordData].removeFromHasMany(operation.field, [cache.getRecordData(operation.prior)]);
1195
- _classPrivateFieldBase(this, _recordData)[_recordData].addToHasMany(operation.field, [cache.getRecordData(operation.value)], operation.index);
1328
+ _classPrivateFieldBase(this, _cache)[_cache].removeFromHasMany(operation.field, [cache.getResourceCache(operation.prior)]);
1329
+ _classPrivateFieldBase(this, _cache)[_cache].addToHasMany(operation.field, [cache.getResourceCache(operation.value)], operation.index);
1196
1330
  return;
1197
1331
  case 'sortRelatedRecords':
1198
1332
  return;
@@ -1200,7 +1334,7 @@ class NonSingletonCacheManager {
1200
1334
  return;
1201
1335
  }
1202
1336
  } else {
1203
- _classPrivateFieldBase(this, _recordData)[_recordData].update(operation);
1337
+ _classPrivateFieldBase(this, _cache)[_cache].update(operation);
1204
1338
  }
1205
1339
  }
1206
1340
 
@@ -1221,15 +1355,15 @@ class NonSingletonCacheManager {
1221
1355
  options = identifier;
1222
1356
  identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1223
1357
  }
1224
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1358
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1225
1359
 
1226
1360
  // TODO deprecate return value
1227
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1228
- recordData.clientDidCreate();
1361
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1362
+ cache.clientDidCreate();
1229
1363
  // if a V2 is calling a V1 we need to call both methods
1230
- return recordData._initRecordCreateOptions(options);
1364
+ return cache._initRecordCreateOptions(options);
1231
1365
  } else {
1232
- return recordData.clientDidCreate(identifier, options);
1366
+ return cache.clientDidCreate(identifier, options);
1233
1367
  }
1234
1368
  }
1235
1369
 
@@ -1245,9 +1379,9 @@ class NonSingletonCacheManager {
1245
1379
  * @param options
1246
1380
  */
1247
1381
  _initRecordCreateOptions(options) {
1248
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1249
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1250
- return recordData._initRecordCreateOptions(options);
1382
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1383
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1384
+ return cache._initRecordCreateOptions(options);
1251
1385
  }
1252
1386
  }
1253
1387
 
@@ -1260,7 +1394,7 @@ class NonSingletonCacheManager {
1260
1394
  * @param identifier
1261
1395
  */
1262
1396
  willCommit(identifier) {
1263
- _classPrivateFieldBase(this, _recordData)[_recordData].willCommit(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1397
+ _classPrivateFieldBase(this, _cache)[_cache].willCommit(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1264
1398
  }
1265
1399
 
1266
1400
  /**
@@ -1278,8 +1412,8 @@ class NonSingletonCacheManager {
1278
1412
  data = identifier;
1279
1413
  identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1280
1414
  }
1281
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1282
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.didCommit(data) : recordData.didCommit(identifier, data);
1415
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1416
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.didCommit(data) : cache.didCommit(identifier, data);
1283
1417
  }
1284
1418
 
1285
1419
  /**
@@ -1292,7 +1426,7 @@ class NonSingletonCacheManager {
1292
1426
  * @param errors
1293
1427
  */
1294
1428
  commitWasRejected(identifier, errors) {
1295
- _classPrivateFieldBase(this, _recordData)[_recordData].commitWasRejected(identifier || _classPrivateFieldBase(this, _identifier)[_identifier], errors);
1429
+ _classPrivateFieldBase(this, _cache)[_cache].commitWasRejected(identifier || _classPrivateFieldBase(this, _identifier)[_identifier], errors);
1296
1430
  }
1297
1431
 
1298
1432
  /**
@@ -1304,11 +1438,11 @@ class NonSingletonCacheManager {
1304
1438
  * @param identifier
1305
1439
  */
1306
1440
  unloadRecord(identifier) {
1307
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1308
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1309
- recordData.unloadRecord();
1441
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1442
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1443
+ cache.unloadRecord();
1310
1444
  } else {
1311
- recordData.unloadRecord(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1445
+ cache.unloadRecord(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1312
1446
  }
1313
1447
  }
1314
1448
 
@@ -1330,8 +1464,8 @@ class NonSingletonCacheManager {
1330
1464
  propertyName = identifier;
1331
1465
  identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1332
1466
  }
1333
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1334
- return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.getAttr(propertyName) : recordData.getAttr(identifier, propertyName);
1467
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1468
+ return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.getAttr(propertyName) : cache.getAttr(identifier, propertyName);
1335
1469
  }
1336
1470
 
1337
1471
  /**
@@ -1344,8 +1478,8 @@ class NonSingletonCacheManager {
1344
1478
  * @param value
1345
1479
  */
1346
1480
  setAttr(identifier, propertyName, value) {
1347
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1348
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.setDirtyAttribute(propertyName, value) : recordData.setAttr(identifier, propertyName, value);
1481
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1482
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.setDirtyAttribute(propertyName, value) : cache.setAttr(identifier, propertyName, value);
1349
1483
  }
1350
1484
 
1351
1485
  /**
@@ -1361,8 +1495,8 @@ class NonSingletonCacheManager {
1361
1495
  * @param value
1362
1496
  */
1363
1497
  setDirtyAttribute(propertyName, value) {
1364
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1365
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.setDirtyAttribute(propertyName, value) : recordData.setAttr(_classPrivateFieldBase(this, _identifier)[_identifier], propertyName, value);
1498
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1499
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.setDirtyAttribute(propertyName, value) : cache.setAttr(_classPrivateFieldBase(this, _identifier)[_identifier], propertyName, value);
1366
1500
  }
1367
1501
 
1368
1502
  /**
@@ -1377,11 +1511,11 @@ class NonSingletonCacheManager {
1377
1511
  * @returns
1378
1512
  */
1379
1513
  changedAttributes() {
1380
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1381
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1382
- return recordData.changedAttributes();
1514
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1515
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1516
+ return cache.changedAttributes();
1383
1517
  }
1384
- return recordData.changedAttrs(_classPrivateFieldBase(this, _identifier)[_identifier]);
1518
+ return cache.changedAttrs(_classPrivateFieldBase(this, _identifier)[_identifier]);
1385
1519
  }
1386
1520
 
1387
1521
  /**
@@ -1394,11 +1528,11 @@ class NonSingletonCacheManager {
1394
1528
  * @returns
1395
1529
  */
1396
1530
  changedAttrs(identifier) {
1397
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1398
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1399
- return recordData.changedAttributes();
1531
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1532
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1533
+ return cache.changedAttributes();
1400
1534
  }
1401
- return recordData.changedAttrs(identifier);
1535
+ return cache.changedAttrs(identifier);
1402
1536
  }
1403
1537
 
1404
1538
  /**
@@ -1412,8 +1546,8 @@ class NonSingletonCacheManager {
1412
1546
  * @returns {boolean}
1413
1547
  */
1414
1548
  hasChangedAttributes() {
1415
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1416
- return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.hasChangedAttributes() : recordData.hasChangedAttrs(_classPrivateFieldBase(this, _identifier)[_identifier]);
1549
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1550
+ return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.hasChangedAttributes() : cache.hasChangedAttrs(_classPrivateFieldBase(this, _identifier)[_identifier]);
1417
1551
  }
1418
1552
 
1419
1553
  /**
@@ -1425,8 +1559,8 @@ class NonSingletonCacheManager {
1425
1559
  * @returns {boolean}
1426
1560
  */
1427
1561
  hasChangedAttrs(identifier) {
1428
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1429
- return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.hasChangedAttributes() : recordData.hasChangedAttrs(identifier);
1562
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1563
+ return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.hasChangedAttributes() : cache.hasChangedAttrs(identifier);
1430
1564
  }
1431
1565
 
1432
1566
  /**
@@ -1440,8 +1574,8 @@ class NonSingletonCacheManager {
1440
1574
  * @returns
1441
1575
  */
1442
1576
  rollbackAttributes() {
1443
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1444
- return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.rollbackAttributes() : recordData.rollbackAttrs(_classPrivateFieldBase(this, _identifier)[_identifier]);
1577
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1578
+ return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.rollbackAttributes() : cache.rollbackAttrs(_classPrivateFieldBase(this, _identifier)[_identifier]);
1445
1579
  }
1446
1580
 
1447
1581
  /**
@@ -1453,8 +1587,8 @@ class NonSingletonCacheManager {
1453
1587
  * @returns the names of attributes that were restored
1454
1588
  */
1455
1589
  rollbackAttrs(identifier) {
1456
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1457
- return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.rollbackAttributes() : recordData.rollbackAttrs(identifier);
1590
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1591
+ return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.rollbackAttributes() : cache.rollbackAttrs(identifier);
1458
1592
  }
1459
1593
 
1460
1594
  // Relationships
@@ -1476,12 +1610,12 @@ class NonSingletonCacheManager {
1476
1610
  * @returns resource relationship object
1477
1611
  */
1478
1612
  getRelationship(identifier, propertyName, isCollection = false) {
1479
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1480
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1613
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1614
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1481
1615
  let isBelongsTo = !isCollection;
1482
- return isBelongsTo ? recordData.getBelongsTo(propertyName) : recordData.getHasMany(propertyName);
1616
+ return isBelongsTo ? cache.getBelongsTo(propertyName) : cache.getHasMany(propertyName);
1483
1617
  }
1484
- return recordData.getRelationship(identifier, propertyName);
1618
+ return cache.getRelationship(identifier, propertyName);
1485
1619
  }
1486
1620
 
1487
1621
  /**
@@ -1496,12 +1630,12 @@ class NonSingletonCacheManager {
1496
1630
  * @returns single resource relationship object
1497
1631
  */
1498
1632
  getBelongsTo(propertyName) {
1499
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1500
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1501
- return recordData.getBelongsTo(propertyName);
1633
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1634
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1635
+ return cache.getBelongsTo(propertyName);
1502
1636
  } else {
1503
1637
  let identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1504
- return recordData.getRelationship(identifier, propertyName);
1638
+ return cache.getRelationship(identifier, propertyName);
1505
1639
  }
1506
1640
  }
1507
1641
 
@@ -1517,12 +1651,12 @@ class NonSingletonCacheManager {
1517
1651
  * @returns single resource relationship object
1518
1652
  */
1519
1653
  getHasMany(propertyName) {
1520
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1521
- if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData)) {
1522
- return recordData.getHasMany(propertyName);
1654
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1655
+ if (_classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache)) {
1656
+ return cache.getHasMany(propertyName);
1523
1657
  } else {
1524
1658
  let identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1525
- return recordData.getRelationship(identifier, propertyName);
1659
+ return cache.getRelationship(identifier, propertyName);
1526
1660
  }
1527
1661
  }
1528
1662
 
@@ -1538,8 +1672,8 @@ class NonSingletonCacheManager {
1538
1672
  * @param value
1539
1673
  */
1540
1674
  setDirtyBelongsTo(propertyName, value) {
1541
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1542
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.setDirtyBelongsTo(propertyName, value) : recordData.update({
1675
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1676
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.setDirtyBelongsTo(propertyName, value) : cache.update({
1543
1677
  op: 'replaceRelatedRecord',
1544
1678
  record: _classPrivateFieldBase(this, _identifier)[_identifier],
1545
1679
  field: propertyName,
@@ -1563,8 +1697,8 @@ class NonSingletonCacheManager {
1563
1697
  */
1564
1698
  addToHasMany(propertyName, value, idx) {
1565
1699
  const identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1566
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1567
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.addToHasMany(propertyName, value, idx) : recordData.update({
1700
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1701
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.addToHasMany(propertyName, value, idx) : cache.update({
1568
1702
  op: 'addToRelatedRecords',
1569
1703
  field: propertyName,
1570
1704
  record: identifier,
@@ -1585,8 +1719,8 @@ class NonSingletonCacheManager {
1585
1719
  */
1586
1720
  removeFromHasMany(propertyName, value) {
1587
1721
  const identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1588
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1589
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.removeFromHasMany(propertyName, value) : recordData.update({
1722
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1723
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.removeFromHasMany(propertyName, value) : cache.update({
1590
1724
  op: 'removeFromRelatedRecords',
1591
1725
  record: identifier,
1592
1726
  field: propertyName,
@@ -1606,8 +1740,8 @@ class NonSingletonCacheManager {
1606
1740
  * @param value
1607
1741
  */
1608
1742
  setDirtyHasMany(propertyName, value) {
1609
- let recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1610
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.setDirtyHasMany(propertyName, value) : recordData.update({
1743
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1744
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.setDirtyHasMany(propertyName, value) : cache.update({
1611
1745
  op: 'replaceRelatedRecords',
1612
1746
  record: _classPrivateFieldBase(this, _identifier)[_identifier],
1613
1747
  field: propertyName,
@@ -1632,8 +1766,8 @@ class NonSingletonCacheManager {
1632
1766
  isDeleted = identifier;
1633
1767
  identifier = _classPrivateFieldBase(this, _identifier)[_identifier];
1634
1768
  }
1635
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1636
- _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.setIsDeleted(isDeleted) : recordData.setIsDeleted(identifier, isDeleted);
1769
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1770
+ _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.setIsDeleted(isDeleted) : cache.setIsDeleted(identifier, isDeleted);
1637
1771
  }
1638
1772
 
1639
1773
  /**
@@ -1645,7 +1779,7 @@ class NonSingletonCacheManager {
1645
1779
  * @returns
1646
1780
  */
1647
1781
  getErrors(identifier) {
1648
- return _classPrivateFieldBase(this, _recordData)[_recordData].getErrors(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1782
+ return _classPrivateFieldBase(this, _cache)[_cache].getErrors(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1649
1783
  }
1650
1784
 
1651
1785
  /**
@@ -1657,8 +1791,8 @@ class NonSingletonCacheManager {
1657
1791
  * @returns {boolean}
1658
1792
  */
1659
1793
  isEmpty(identifier) {
1660
- const recordData = _classPrivateFieldBase(this, _recordData)[_recordData];
1661
- return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](recordData) ? recordData.isEmpty?.(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]) || false : recordData.isEmpty(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1794
+ const cache = _classPrivateFieldBase(this, _cache)[_cache];
1795
+ return _classPrivateFieldBase(this, _isDeprecated)[_isDeprecated](cache) ? cache.isEmpty?.(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]) || false : cache.isEmpty(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1662
1796
  }
1663
1797
 
1664
1798
  /**
@@ -1671,7 +1805,7 @@ class NonSingletonCacheManager {
1671
1805
  * @returns {boolean}
1672
1806
  */
1673
1807
  isNew(identifier) {
1674
- return _classPrivateFieldBase(this, _recordData)[_recordData].isNew(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1808
+ return _classPrivateFieldBase(this, _cache)[_cache].isNew(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1675
1809
  }
1676
1810
 
1677
1811
  /**
@@ -1684,7 +1818,7 @@ class NonSingletonCacheManager {
1684
1818
  * @returns {boolean}
1685
1819
  */
1686
1820
  isDeleted(identifier) {
1687
- return _classPrivateFieldBase(this, _recordData)[_recordData].isDeleted(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1821
+ return _classPrivateFieldBase(this, _cache)[_cache].isDeleted(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1688
1822
  }
1689
1823
 
1690
1824
  /**
@@ -1697,106 +1831,99 @@ class NonSingletonCacheManager {
1697
1831
  * @returns {boolean}
1698
1832
  */
1699
1833
  isDeletionCommitted(identifier) {
1700
- return _classPrivateFieldBase(this, _recordData)[_recordData].isDeletionCommitted(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1834
+ return _classPrivateFieldBase(this, _cache)[_cache].isDeletionCommitted(identifier || _classPrivateFieldBase(this, _identifier)[_identifier]);
1701
1835
  }
1702
1836
  }
1703
- function _isDeprecated2(recordData) {
1704
- let version = recordData.version || '1';
1837
+ function _isDeprecated2(cache) {
1838
+ let version = cache.version || '1';
1705
1839
  return version !== this.version;
1706
1840
  }
1707
- var _recordDatas = /*#__PURE__*/_classPrivateFieldKey("recordDatas");
1708
- var _recordData3 = /*#__PURE__*/_classPrivateFieldKey("recordData");
1841
+ var _cache3 = /*#__PURE__*/_classPrivateFieldKey("cache");
1709
1842
  class SingletonCacheManager {
1710
- constructor() {
1711
- Object.defineProperty(this, _recordData3, {
1712
- value: _recordData4
1713
- });
1843
+ constructor(cache) {
1714
1844
  this.version = '2';
1715
- Object.defineProperty(this, _recordDatas, {
1845
+ Object.defineProperty(this, _cache3, {
1716
1846
  writable: true,
1717
1847
  value: void 0
1718
1848
  });
1719
- _classPrivateFieldBase(this, _recordDatas)[_recordDatas] = new Map();
1849
+ _classPrivateFieldBase(this, _cache3)[_cache3] = cache;
1720
1850
  }
1721
- _addRecordData(identifier, recordData) {
1722
- _classPrivateFieldBase(this, _recordDatas)[_recordDatas].set(identifier, recordData);
1851
+ put(doc) {
1852
+ return _classPrivateFieldBase(this, _cache3)[_cache3].put(doc);
1723
1853
  }
1854
+
1724
1855
  // Cache
1725
1856
  // =====
1726
1857
 
1727
- pushData(identifier, data, hasRecord) {
1728
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).pushData(identifier, data, hasRecord);
1858
+ upsert(identifier, data, hasRecord) {
1859
+ return _classPrivateFieldBase(this, _cache3)[_cache3].upsert(identifier, data, hasRecord);
1729
1860
  }
1730
- sync(op) {
1731
- _classPrivateFieldBase(this, _recordData3)[_recordData3](op.record).sync(op);
1861
+ patch(op) {
1862
+ _classPrivateFieldBase(this, _cache3)[_cache3].patch(op);
1732
1863
  }
1733
1864
  clientDidCreate(identifier, options) {
1734
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).clientDidCreate(identifier, options);
1865
+ return _classPrivateFieldBase(this, _cache3)[_cache3].clientDidCreate(identifier, options);
1735
1866
  }
1736
1867
  willCommit(identifier) {
1737
- _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).willCommit(identifier);
1868
+ _classPrivateFieldBase(this, _cache3)[_cache3].willCommit(identifier);
1738
1869
  }
1739
1870
  didCommit(identifier, data) {
1740
- _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).didCommit(identifier, data);
1871
+ _classPrivateFieldBase(this, _cache3)[_cache3].didCommit(identifier, data);
1741
1872
  }
1742
1873
  commitWasRejected(identifier, errors) {
1743
- _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).commitWasRejected(identifier, errors);
1874
+ _classPrivateFieldBase(this, _cache3)[_cache3].commitWasRejected(identifier, errors);
1744
1875
  }
1745
1876
  unloadRecord(identifier) {
1746
- _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).unloadRecord(identifier);
1877
+ _classPrivateFieldBase(this, _cache3)[_cache3].unloadRecord(identifier);
1747
1878
  }
1748
1879
 
1749
1880
  // Attrs
1750
1881
  // =====
1751
1882
 
1752
1883
  getAttr(identifier, propertyName) {
1753
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).getAttr(identifier, propertyName);
1884
+ return _classPrivateFieldBase(this, _cache3)[_cache3].getAttr(identifier, propertyName);
1754
1885
  }
1755
1886
  setAttr(identifier, propertyName, value) {
1756
- _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).setAttr(identifier, propertyName, value);
1887
+ _classPrivateFieldBase(this, _cache3)[_cache3].setAttr(identifier, propertyName, value);
1757
1888
  }
1758
1889
  changedAttrs(identifier) {
1759
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).changedAttrs(identifier);
1890
+ return _classPrivateFieldBase(this, _cache3)[_cache3].changedAttrs(identifier);
1760
1891
  }
1761
1892
  hasChangedAttrs(identifier) {
1762
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).hasChangedAttrs(identifier);
1893
+ return _classPrivateFieldBase(this, _cache3)[_cache3].hasChangedAttrs(identifier);
1763
1894
  }
1764
1895
  rollbackAttrs(identifier) {
1765
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).rollbackAttrs(identifier);
1896
+ return _classPrivateFieldBase(this, _cache3)[_cache3].rollbackAttrs(identifier);
1766
1897
  }
1767
1898
  getRelationship(identifier, propertyName) {
1768
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).getRelationship(identifier, propertyName);
1899
+ return _classPrivateFieldBase(this, _cache3)[_cache3].getRelationship(identifier, propertyName);
1769
1900
  }
1770
1901
  update(operation) {
1771
- _classPrivateFieldBase(this, _recordData3)[_recordData3](operation.record).update(operation);
1902
+ _classPrivateFieldBase(this, _cache3)[_cache3].update(operation);
1772
1903
  }
1773
1904
 
1774
1905
  // State
1775
1906
  // =============
1776
1907
 
1777
1908
  setIsDeleted(identifier, isDeleted) {
1778
- _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).setIsDeleted(identifier, isDeleted);
1909
+ _classPrivateFieldBase(this, _cache3)[_cache3].setIsDeleted(identifier, isDeleted);
1779
1910
  }
1780
1911
  getErrors(identifier) {
1781
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).getErrors(identifier);
1912
+ return _classPrivateFieldBase(this, _cache3)[_cache3].getErrors(identifier);
1782
1913
  }
1783
1914
  isEmpty(identifier) {
1784
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).isEmpty(identifier);
1915
+ return _classPrivateFieldBase(this, _cache3)[_cache3].isEmpty(identifier);
1785
1916
  }
1786
1917
  isNew(identifier) {
1787
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).isNew(identifier);
1918
+ return _classPrivateFieldBase(this, _cache3)[_cache3].isNew(identifier);
1788
1919
  }
1789
1920
  isDeleted(identifier) {
1790
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).isDeleted(identifier);
1921
+ return _classPrivateFieldBase(this, _cache3)[_cache3].isDeleted(identifier);
1791
1922
  }
1792
1923
  isDeletionCommitted(identifier) {
1793
- return _classPrivateFieldBase(this, _recordData3)[_recordData3](identifier).isDeletionCommitted(identifier);
1924
+ return _classPrivateFieldBase(this, _cache3)[_cache3].isDeletionCommitted(identifier);
1794
1925
  }
1795
1926
  }
1796
- function _recordData4(identifier) {
1797
- assert(`No RecordData Yet Exists!`, _classPrivateFieldBase(this, _recordDatas)[_recordDatas].has(identifier));
1798
- return _classPrivateFieldBase(this, _recordDatas)[_recordDatas].get(identifier);
1799
- }
1800
1927
  function constructResource(type, id, lid) {
1801
1928
  if (typeof type === 'object' && type !== null) {
1802
1929
  let resource = type;
@@ -1887,10 +2014,9 @@ class LegacyWrapper {
1887
2014
  this._scheduleNotification(identifier, key);
1888
2015
  return;
1889
2016
  }
2017
+
2018
+ // @ts-expect-error
1890
2019
  this._store.notifications.notify(identifier, namespace, key);
1891
- if (namespace === 'state') {
1892
- this._store.recordArrayManager.identifierChanged(identifier);
1893
- }
1894
2020
  }
1895
2021
  notifyErrorsChange(type, id, lid) {
1896
2022
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1CACHE_STORE_APIS)) {
@@ -2006,7 +2132,6 @@ class LegacyWrapper {
2006
2132
  const resource = constructResource(type, id, lid);
2007
2133
  const identifier = this.identifierCache.getOrCreateRecordIdentifier(resource);
2008
2134
  this._store.notifications.notify(identifier, 'state');
2009
- this._store.recordArrayManager.identifierChanged(identifier);
2010
2135
  }
2011
2136
  recordDataFor(type, id, lid) {
2012
2137
  let identifier;
@@ -2029,12 +2154,14 @@ class LegacyWrapper {
2029
2154
  assert(`Expected a stable identifier`, isStableIdentifier(type));
2030
2155
  identifier = type;
2031
2156
  }
2032
- const recordData = this._store._instanceCache.getRecordData(identifier);
2033
- if (!id && !lid) {
2034
- recordData.clientDidCreate(identifier);
2035
- this._store.recordArrayManager.identifierAdded(identifier);
2157
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_CREATE_RECORD_DATA_FOR_HOOK) ? this._store._instanceCache.getResourceCache(identifier) : this._store.cache;
2158
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1CACHE_STORE_APIS)) {
2159
+ if (!id && !lid && typeof type === 'string') {
2160
+ cache.clientDidCreate(identifier);
2161
+ this._store.recordArrayManager.identifierAdded(identifier);
2162
+ }
2036
2163
  }
2037
- return recordData;
2164
+ return cache;
2038
2165
  }
2039
2166
  setRecordId(type, id, lid) {
2040
2167
  let identifier;
@@ -2154,17 +2281,27 @@ class V2CacheStoreWrapper {
2154
2281
  this._scheduleNotification(identifier, key);
2155
2282
  return;
2156
2283
  }
2284
+
2285
+ // @ts-expect-error
2157
2286
  this._store.notifications.notify(identifier, namespace, key);
2158
- if (namespace === 'state') {
2159
- this._store.recordArrayManager.identifierChanged(identifier);
2160
- }
2161
2287
  }
2162
2288
  getSchemaDefinitionService() {
2163
2289
  return this._store.getSchemaDefinitionService();
2164
2290
  }
2165
2291
  recordDataFor(identifier) {
2292
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_CREATE_RECORD_DATA_FOR_HOOK)) {
2293
+ deprecate(`StoreWrapper.recordDataFor is deprecated. With Singleton Cache, this method is no longer needed as the caller is its own cache reference.`, false, {
2294
+ for: '@ember-data/store',
2295
+ id: 'ember-data:deprecate-record-data-for',
2296
+ since: {
2297
+ available: '4.10',
2298
+ enabled: '4.10'
2299
+ },
2300
+ until: '5.0'
2301
+ });
2302
+ }
2166
2303
  assert(`Expected a stable identifier`, isStableIdentifier(identifier));
2167
- return this._store._instanceCache.getRecordData(identifier);
2304
+ return macroCondition(getOwnConfig().deprecations.DEPRECATE_CREATE_RECORD_DATA_FOR_HOOK) ? this._store._instanceCache.getResourceCache(identifier) : void 0;
2168
2305
  }
2169
2306
  setRecordId(identifier, id) {
2170
2307
  assert(`Expected a stable identifier`, isStableIdentifier(identifier));
@@ -2274,7 +2411,8 @@ class Snapshot {
2274
2411
  */
2275
2412
  this.modelName = identifier.type;
2276
2413
  if (hasRecord) {
2277
- this._changedAttributes = this._store._instanceCache.getRecordData(identifier).changedAttrs(identifier);
2414
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._store._instanceCache.getResourceCache(identifier) : this._store.cache;
2415
+ this._changedAttributes = cache.changedAttrs(identifier);
2278
2416
  }
2279
2417
  }
2280
2418
 
@@ -2296,14 +2434,14 @@ class Snapshot {
2296
2434
  if (this.__attributes !== null) {
2297
2435
  return this.__attributes;
2298
2436
  }
2299
- let attributes = this.__attributes = Object.create(null);
2437
+ const attributes = this.__attributes = Object.create(null);
2300
2438
  const {
2301
2439
  identifier
2302
2440
  } = this;
2303
- let attrs = Object.keys(this._store.getSchemaDefinitionService().attributesDefinitionFor(identifier));
2304
- let recordData = this._store._instanceCache.getRecordData(identifier);
2441
+ const attrs = Object.keys(this._store.getSchemaDefinitionService().attributesDefinitionFor(identifier));
2442
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._store._instanceCache.getResourceCache(identifier) : this._store.cache;
2305
2443
  attrs.forEach(keyName => {
2306
- attributes[keyName] = recordData.getAttr(identifier, keyName);
2444
+ attributes[keyName] = cache.getAttr(identifier, keyName);
2307
2445
  });
2308
2446
  return attributes;
2309
2447
  }
@@ -2317,11 +2455,11 @@ class Snapshot {
2317
2455
  */
2318
2456
 
2319
2457
  get isNew() {
2320
- const recordData = this._store._instanceCache.peek({
2458
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._store._instanceCache.peek({
2321
2459
  identifier: this.identifier,
2322
- bucket: 'recordData'
2323
- });
2324
- return recordData?.isNew(this.identifier) || false;
2460
+ bucket: 'resourceCache'
2461
+ }) : this._store.cache;
2462
+ return cache?.isNew(this.identifier) || false;
2325
2463
  }
2326
2464
 
2327
2465
  /**
@@ -2449,7 +2587,8 @@ class Snapshot {
2449
2587
  let data = value && value.data;
2450
2588
  let inverseIdentifier = data ? store.identifierCache.getOrCreateRecordIdentifier(data) : null;
2451
2589
  if (value && value.data !== undefined) {
2452
- if (inverseIdentifier && !store._instanceCache.getRecordData(inverseIdentifier).isDeleted(inverseIdentifier)) {
2590
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? inverseIdentifier && store._instanceCache.getResourceCache(inverseIdentifier) : store.cache;
2591
+ if (inverseIdentifier && !cache.isDeleted(inverseIdentifier)) {
2453
2592
  if (returnModeIsId) {
2454
2593
  result = inverseIdentifier.id;
2455
2594
  } else {
@@ -2527,7 +2666,8 @@ class Snapshot {
2527
2666
  results = [];
2528
2667
  value.data.forEach(member => {
2529
2668
  let inverseIdentifier = store.identifierCache.getOrCreateRecordIdentifier(member);
2530
- if (!store._instanceCache.getRecordData(inverseIdentifier).isDeleted(inverseIdentifier)) {
2669
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? store._instanceCache.getResourceCache(inverseIdentifier) : store.cache;
2670
+ if (!cache.isDeleted(inverseIdentifier)) {
2531
2671
  if (returnModeIsIds) {
2532
2672
  results.push(inverseIdentifier.id);
2533
2673
  } else {
@@ -2635,26 +2775,6 @@ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SNAPSHOT_MODEL_CLASS_AC
2635
2775
  function assertIdentifierHasId(identifier) {
2636
2776
  assert(`Attempted to schedule a fetch for a record without an id.`, identifier.id !== null);
2637
2777
  }
2638
-
2639
- /*
2640
- * Returns the RecordData instance associated with a given
2641
- * Model or Identifier
2642
- */
2643
-
2644
- const RecordDataForIdentifierCache = new Map();
2645
- function setRecordDataFor(identifier, recordData) {
2646
- assert(`Illegal set of identifier`, !RecordDataForIdentifierCache.has(identifier) || RecordDataForIdentifierCache.get(identifier) === recordData);
2647
- RecordDataForIdentifierCache.set(identifier, recordData);
2648
- }
2649
- function removeRecordDataFor(identifier) {
2650
- RecordDataForIdentifierCache.delete(identifier);
2651
- }
2652
- function recordDataFor(instance) {
2653
- if (RecordDataForIdentifierCache.has(instance)) {
2654
- return RecordDataForIdentifierCache.get(instance);
2655
- }
2656
- return null;
2657
- }
2658
2778
  let _peekGraph;
2659
2779
  if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
2660
2780
  let __peekGraph;
@@ -2724,16 +2844,18 @@ class InstanceCache {
2724
2844
  constructor(store) {
2725
2845
  this.__instances = {
2726
2846
  record: new Map(),
2727
- recordData: new Map(),
2847
+ resourceCache: new Map(),
2728
2848
  reference: new WeakMap()
2729
2849
  };
2730
2850
  this.store = store;
2731
2851
  this._storeWrapper = new CacheStoreWrapper(this.store);
2732
- this.__recordDataFor = resource => {
2733
- // TODO enforce strict
2734
- const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resource);
2735
- return this.getRecordData(identifier);
2736
- };
2852
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_CREATE_RECORD_DATA_FOR_HOOK)) {
2853
+ this.__cacheFor = resource => {
2854
+ // TODO enforce strict
2855
+ const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resource);
2856
+ return this.getResourceCache(identifier);
2857
+ };
2858
+ }
2737
2859
  store.identifierCache.__configureMerge((identifier, matchedIdentifier, resourceData) => {
2738
2860
  let keptIdentifier = identifier;
2739
2861
  if (identifier.id !== matchedIdentifier.id) {
@@ -2746,11 +2868,11 @@ class InstanceCache {
2746
2868
  // check for duplicate entities
2747
2869
  let keptHasRecord = this.__instances.record.has(keptIdentifier);
2748
2870
  let staleHasRecord = this.__instances.record.has(staleIdentifier);
2749
- let keptRecordData = this.__instances.recordData.get(keptIdentifier) || null;
2750
- let staleRecordData = this.__instances.recordData.get(staleIdentifier) || null;
2871
+ let keptResourceCache = this.__instances.resourceCache.get(keptIdentifier) || null;
2872
+ let staleResourceCache = this.__instances.resourceCache.get(staleIdentifier) || null;
2751
2873
 
2752
2874
  // we cannot merge entities when both have records
2753
- // (this may not be strictly true, we could probably swap the recordData the record points at)
2875
+ // (this may not be strictly true, we could probably swap the cache data the record points at)
2754
2876
  if (keptHasRecord && staleHasRecord) {
2755
2877
  // TODO we probably don't need to throw these errors anymore
2756
2878
  // we can probably just "swap" what data source the abandoned
@@ -2761,23 +2883,27 @@ class InstanceCache {
2761
2883
  }
2762
2884
  assert(`Failed to update the RecordIdentifier '${identifier.type}:${String(identifier.id)} (${identifier.lid})' to merge with the detected duplicate identifier '${matchedIdentifier.type}:${String(matchedIdentifier.id)} (${String(matchedIdentifier.lid)})'`);
2763
2885
  }
2764
- let recordData = keptRecordData || staleRecordData;
2765
- if (recordData) {
2766
- recordData.sync({
2886
+ let resourceCache = keptResourceCache || staleResourceCache;
2887
+ if (resourceCache) {
2888
+ resourceCache.patch({
2889
+ op: 'mergeIdentifiers',
2890
+ record: staleIdentifier,
2891
+ value: keptIdentifier
2892
+ });
2893
+ } else if (macroCondition(!getOwnConfig().deprecations.DEPRECATE_CREATE_RECORD_DATA_FOR_HOOK)) {
2894
+ this.store.cache.patch({
2767
2895
  op: 'mergeIdentifiers',
2768
2896
  record: staleIdentifier,
2769
2897
  value: keptIdentifier
2770
2898
  });
2771
2899
  } else if (macroCondition(dependencySatisfies("@ember-data/json-api", "*"))) {
2772
- // TODO notify cache always, this requires it always being a singleton
2773
- // and not ever specific to one record-data
2774
- this.store.__private_singleton_recordData?.sync({
2900
+ this.store.cache.patch({
2775
2901
  op: 'mergeIdentifiers',
2776
2902
  record: staleIdentifier,
2777
2903
  value: keptIdentifier
2778
2904
  });
2779
2905
  }
2780
- if (staleRecordData === null) {
2906
+ if (staleResourceCache === null) {
2781
2907
  return keptIdentifier;
2782
2908
  }
2783
2909
 
@@ -2805,10 +2931,27 @@ class InstanceCache {
2805
2931
  let record = this.__instances.record.get(identifier);
2806
2932
  if (!record) {
2807
2933
  assert(`Cannot create a new record instance while the store is being destroyed`, !this.store.isDestroying && !this.store.isDestroyed);
2808
- const recordData = this.getRecordData(identifier);
2809
- record = this.store.instantiateRecord(identifier, properties || {}, this.__recordDataFor, this.store.notifications);
2934
+ const cache = this.getResourceCache(identifier);
2935
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_INSTANTIATE_RECORD_ARGS)) {
2936
+ if (this.store.instantiateRecord.length > 2) {
2937
+ deprecate(`Expected store.instantiateRecord to have an arity of 2. recordDataFor and notificationManager args have been deprecated.`, false, {
2938
+ for: '@ember-data/store',
2939
+ id: 'ember-data:deprecate-instantiate-record-args',
2940
+ since: {
2941
+ available: '4.12',
2942
+ enabled: '4.12'
2943
+ },
2944
+ until: '5.0'
2945
+ });
2946
+ }
2947
+ record = this.store.instantiateRecord(identifier, properties || {},
2948
+ // @ts-expect-error
2949
+ this.__cacheFor, this.store.notifications);
2950
+ } else {
2951
+ record = this.store.instantiateRecord(identifier, properties || {});
2952
+ }
2810
2953
  setRecordIdentifier(record, identifier);
2811
- setRecordDataFor(record, recordData);
2954
+ setCacheFor(record, cache);
2812
2955
  StoreMap.set(record, this.store);
2813
2956
  this.__instances.record.set(identifier, record);
2814
2957
  if (macroCondition(getOwnConfig().debug.LOG_INSTANCE_CACHE)) {
@@ -2818,49 +2961,49 @@ class InstanceCache {
2818
2961
  }
2819
2962
  return record;
2820
2963
  }
2821
- getRecordData(identifier) {
2822
- let recordData = this.__instances.recordData.get(identifier);
2823
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1CACHE_STORE_APIS)) {
2824
- if (!recordData && this.store.createRecordDataFor.length > 2) {
2825
- deprecate(`Store.createRecordDataFor(<type>, <id>, <lid>, <storeWrapper>) has been deprecated in favor of Store.createRecordDataFor(<identifier>, <storeWrapper>)`, false, {
2826
- id: 'ember-data:deprecate-v1cache-store-apis',
2827
- for: 'ember-data',
2828
- until: '5.0',
2829
- since: {
2830
- enabled: '4.7',
2831
- available: '4.7'
2832
- }
2833
- });
2834
- let recordDataInstance = this.store.createRecordDataFor(identifier.type, identifier.id,
2835
- // @ts-expect-error
2836
- identifier.lid, this._storeWrapper);
2837
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA)) {
2838
- recordData = new NonSingletonCacheManager(this.store, recordDataInstance, identifier);
2839
- } else {
2840
- recordData = this.__cacheManager = this.__cacheManager || new NonSingletonCacheManager(this.store, recordDataInstance, identifier);
2841
- }
2842
- }
2964
+ getResourceCache(identifier) {
2965
+ if (macroCondition(!getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA)) {
2966
+ const cache = this.store.cache;
2967
+ setCacheFor(identifier, cache);
2968
+ this.__instances.resourceCache.set(identifier, cache);
2969
+ return cache;
2843
2970
  }
2844
- if (!recordData) {
2845
- let recordDataInstance = this.store.createRecordDataFor(identifier, this._storeWrapper);
2846
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA)) {
2847
- recordData = new NonSingletonCacheManager(this.store, recordDataInstance, identifier);
2848
- } else {
2849
- if (macroCondition(isDevelopingApp())) {
2850
- recordData = this.__cacheManager = this.__cacheManager || new SingletonCacheManager();
2851
- recordData._addRecordData(identifier, recordDataInstance);
2852
- } else {
2853
- recordData = recordDataInstance;
2971
+ let cache = this.__instances.resourceCache.get(identifier);
2972
+ if (cache) {
2973
+ return cache;
2974
+ }
2975
+ if (this.store.createRecordDataFor) {
2976
+ deprecate(`Store.createRecordDataFor(<type>, <id>, <lid>, <storeWrapper>) has been deprecated in favor of Store.createCache(<storeWrapper>)`, false, {
2977
+ id: 'ember-data:deprecate-v1-cache',
2978
+ for: 'ember-data',
2979
+ until: '5.0',
2980
+ since: {
2981
+ enabled: '4.12',
2982
+ available: '4.12'
2983
+ }
2984
+ });
2985
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1CACHE_STORE_APIS)) {
2986
+ if (this.store.createRecordDataFor.length > 2) {
2987
+ let cacheInstance = this.store.createRecordDataFor(identifier.type, identifier.id,
2988
+ // @ts-expect-error
2989
+ identifier.lid, this._storeWrapper);
2990
+ cache = new NonSingletonCacheManager(this.store, cacheInstance, identifier);
2854
2991
  }
2855
2992
  }
2856
- setRecordDataFor(identifier, recordData);
2857
- this.__instances.recordData.set(identifier, recordData);
2858
- if (macroCondition(getOwnConfig().debug.LOG_INSTANCE_CACHE)) {
2859
- // eslint-disable-next-line no-console
2860
- console.log(`InstanceCache: created RecordData for ${String(identifier)}`);
2993
+ if (!cache) {
2994
+ let cacheInstance = this.store.createRecordDataFor(identifier, this._storeWrapper);
2995
+ cache = cacheInstance.version === '2' ? cacheInstance : new NonSingletonCacheManager(this.store, cacheInstance, identifier);
2861
2996
  }
2997
+ } else {
2998
+ cache = this.store.cache;
2862
2999
  }
2863
- return recordData;
3000
+ setCacheFor(identifier, cache);
3001
+ this.__instances.resourceCache.set(identifier, cache);
3002
+ if (macroCondition(getOwnConfig().debug.LOG_INSTANCE_CACHE)) {
3003
+ // eslint-disable-next-line no-console
3004
+ console.log(`InstanceCache: created Cache for ${String(identifier)}`);
3005
+ }
3006
+ return cache;
2864
3007
  }
2865
3008
  getReference(identifier) {
2866
3009
  let cache = this.__instances.reference;
@@ -2872,16 +3015,16 @@ class InstanceCache {
2872
3015
  return reference;
2873
3016
  }
2874
3017
  recordIsLoaded(identifier, filterDeleted = false) {
2875
- const recordData = this.__instances.recordData.get(identifier);
2876
- if (!recordData) {
3018
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.__instances.resourceCache.get(identifier) : this.cache;
3019
+ if (!cache) {
2877
3020
  return false;
2878
3021
  }
2879
- const isNew = recordData.isNew(identifier);
2880
- const isEmpty = recordData.isEmpty(identifier);
3022
+ const isNew = cache.isNew(identifier);
3023
+ const isEmpty = cache.isEmpty(identifier);
2881
3024
 
2882
3025
  // if we are new we must consider ourselves loaded
2883
3026
  if (isNew) {
2884
- return !recordData.isDeleted(identifier);
3027
+ return !cache.isDeleted(identifier);
2885
3028
  }
2886
3029
  // even if we have a past request, if we are now empty we are not loaded
2887
3030
  // typically this is true after an unloadRecord call
@@ -2890,23 +3033,8 @@ class InstanceCache {
2890
3033
  // we should consider allowing for something to be loaded that is simply "not empty".
2891
3034
  // which is how RecordState currently handles this case; however, RecordState is buggy
2892
3035
  // in that it does not account for unloading.
2893
- return filterDeleted && recordData.isDeletionCommitted(identifier) ? false : !isEmpty;
2894
-
2895
- /*
2896
- const req = this.store.getRequestStateService();
2897
- const fulfilled = req.getLastRequestForRecord(identifier);
2898
- const isLocallyLoaded = !isEmpty;
2899
- const isLoading =
2900
- !isLocallyLoaded &&
2901
- fulfilled === null &&
2902
- req.getPendingRequestsForRecord(identifier).some((req) => req.type === 'query');
2903
- if (isEmpty || (filterDeleted && recordData.isDeletionCommitted(identifier)) || isLoading) {
2904
- return false;
2905
- }
2906
- return true;
2907
- */
3036
+ return filterDeleted && cache.isDeletionCommitted(identifier) ? false : !isEmpty;
2908
3037
  }
2909
-
2910
3038
  createSnapshot(identifier, options = {}) {
2911
3039
  return new Snapshot(options, identifier, this.store);
2912
3040
  }
@@ -2920,6 +3048,9 @@ class InstanceCache {
2920
3048
  }
2921
3049
  }
2922
3050
  this.store.identifierCache.forgetRecordIdentifier(identifier);
3051
+ this.__instances.resourceCache.delete(identifier);
3052
+ removeRecordDataFor(identifier);
3053
+ this.store._fetchManager.clearEntries(identifier);
2923
3054
  if (macroCondition(getOwnConfig().debug.LOG_INSTANCE_CACHE)) {
2924
3055
  // eslint-disable-next-line no-console
2925
3056
  console.log(`InstanceCache: disconnected ${String(identifier)}`);
@@ -2942,7 +3073,7 @@ class InstanceCache {
2942
3073
  // TODO is this join still necessary?
2943
3074
  this.store._join(() => {
2944
3075
  const record = this.__instances.record.get(identifier);
2945
- const recordData = this.__instances.recordData.get(identifier);
3076
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.__instances.resourceCache.get(identifier) : this.cache;
2946
3077
  if (record) {
2947
3078
  this.store.teardownRecord(record);
2948
3079
  this.__instances.record.delete(identifier);
@@ -2954,20 +3085,18 @@ class InstanceCache {
2954
3085
  console.log(`InstanceCache: destroyed record for ${String(identifier)}`);
2955
3086
  }
2956
3087
  }
2957
- let removeFromRecordArray = true;
2958
- if (recordData) {
2959
- removeFromRecordArray = !recordData.isDeletionCommitted(identifier);
2960
- recordData.unloadRecord(identifier);
2961
- this.__instances.recordData.delete(identifier);
3088
+ if (cache) {
3089
+ cache.unloadRecord(identifier);
3090
+ this.__instances.resourceCache.delete(identifier);
2962
3091
  removeRecordDataFor(identifier);
3092
+ if (macroCondition(getOwnConfig().debug.LOG_INSTANCE_CACHE)) {
3093
+ // eslint-disable-next-line no-console
3094
+ console.log(`InstanceCache: destroyed cache for ${String(identifier)}`);
3095
+ }
2963
3096
  } else {
2964
- removeFromRecordArray = false;
2965
3097
  this.disconnect(identifier);
2966
3098
  }
2967
3099
  this.store._fetchManager.clearEntries(identifier);
2968
- if (removeFromRecordArray) {
2969
- this.store.recordArrayManager.identifierRemoved(identifier);
2970
- }
2971
3100
  if (macroCondition(getOwnConfig().debug.LOG_INSTANCE_CACHE)) {
2972
3101
  // eslint-disable-next-line no-console
2973
3102
  console.log(`InstanceCache: unloaded RecordData for ${String(identifier)}`);
@@ -2977,19 +3106,22 @@ class InstanceCache {
2977
3106
  });
2978
3107
  }
2979
3108
  clear(type) {
2980
- const typeCache = this.store.identifierCache._cache.types;
3109
+ const cache = this.store.identifierCache._cache;
2981
3110
  if (type === undefined) {
2982
- this.__instances.recordData.forEach((value, identifier) => {
3111
+ // it would be cool if we could just de-ref cache here
3112
+ // but probably would require WeakRef models to do so.
3113
+ cache.lids.forEach(identifier => {
2983
3114
  this.unloadRecord(identifier);
2984
3115
  });
2985
3116
  } else {
3117
+ const typeCache = cache.types;
2986
3118
  let identifiers = typeCache[type]?.lid;
2987
- const rds = this.__instances.recordData;
3119
+ // const rds = this.__instances.resourceCache;
2988
3120
  if (identifiers) {
2989
3121
  identifiers.forEach(identifier => {
2990
- if (rds.has(identifier)) {
2991
- this.unloadRecord(identifier);
2992
- }
3122
+ // if (rds.has(identifier)) {
3123
+ this.unloadRecord(identifier);
3124
+ // }
2993
3125
  // TODO we don't remove the identifier, should we?
2994
3126
  });
2995
3127
  }
@@ -3052,7 +3184,7 @@ class InstanceCache {
3052
3184
  });
3053
3185
  }
3054
3186
 
3055
- // TODO update recordData if needed ?
3187
+ // TODO update resource cache if needed ?
3056
3188
  // TODO handle consequences of identifier merge for notifications
3057
3189
  this.store.notifications.notify(identifier, 'identity');
3058
3190
  }
@@ -3081,24 +3213,18 @@ class InstanceCache {
3081
3213
  } else {
3082
3214
  identifier = this.store.identifierCache.getOrCreateRecordIdentifier(data);
3083
3215
  }
3084
- const recordData = this.getRecordData(identifier);
3085
- if (recordData.isNew(identifier)) {
3086
- this.store.notifications.notify(identifier, 'identity');
3087
- }
3216
+ const cache = this.getResourceCache(identifier);
3088
3217
  const hasRecord = this.__instances.record.has(identifier);
3089
- recordData.pushData(identifier, data, hasRecord);
3090
- if (!isUpdate) {
3091
- this.store.recordArrayManager.identifierAdded(identifier);
3092
- }
3218
+ cache.upsert(identifier, data, hasRecord);
3093
3219
  return identifier;
3094
3220
  }
3095
3221
  }
3096
- function _recordDataIsFullDeleted(identifier, recordData) {
3097
- return recordData.isDeletionCommitted(identifier) || recordData.isNew(identifier) && recordData.isDeleted(identifier);
3222
+ function _resourceIsFullDeleted(identifier, cache) {
3223
+ return cache.isDeletionCommitted(identifier) || cache.isNew(identifier) && cache.isDeleted(identifier);
3098
3224
  }
3099
- function recordDataIsFullyDeleted(cache, identifier) {
3100
- let recordData = cache.__instances.recordData.get(identifier);
3101
- return !recordData || _recordDataIsFullDeleted(identifier, recordData);
3225
+ function resourceIsFullyDeleted(instanceCache, identifier) {
3226
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? instanceCache.__instances.resourceCache.get(identifier) : instanceCache.cache;
3227
+ return !cache || _resourceIsFullDeleted(identifier, cache);
3102
3228
  }
3103
3229
 
3104
3230
  /*
@@ -3133,7 +3259,8 @@ function preloadData(store, identifier, preload) {
3133
3259
  jsonPayload.attributes[key] = preloadValue;
3134
3260
  }
3135
3261
  });
3136
- store._instanceCache.getRecordData(identifier).pushData(identifier, jsonPayload);
3262
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? store._instanceCache.getResourceCache(identifier) : store.cache;
3263
+ cache.upsert(identifier, jsonPayload);
3137
3264
  }
3138
3265
  function preloadRelationship(schema, preloadValue) {
3139
3266
  const relatedType = schema.type;
@@ -3164,14 +3291,14 @@ function _convertPreloadRelationshipToJSON(value, type) {
3164
3291
  // and allow identifiers to be used
3165
3292
  return recordIdentifierFor(value);
3166
3293
  }
3167
- function _isEmpty(cache, identifier) {
3168
- const recordData = cache.__instances.recordData.get(identifier);
3169
- if (!recordData) {
3294
+ function _isEmpty(instanceCache, identifier) {
3295
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? instanceCache.__instances.resourceCache.get(identifier) : instanceCache.cache;
3296
+ if (!cache) {
3170
3297
  return true;
3171
3298
  }
3172
- const isNew = recordData.isNew(identifier);
3173
- const isDeleted = recordData.isDeleted(identifier);
3174
- const isEmpty = recordData.isEmpty(identifier);
3299
+ const isNew = cache.isNew(identifier);
3300
+ const isDeleted = cache.isDeleted(identifier);
3301
+ const isEmpty = cache.isEmpty(identifier);
3175
3302
  return (!isNew || isDeleted) && isEmpty;
3176
3303
  }
3177
3304
  function _isLoading(cache, identifier) {
@@ -3185,7 +3312,7 @@ function _isLoading(cache, identifier) {
3185
3312
  function _clearCaches() {
3186
3313
  RecordCache.clear();
3187
3314
  StoreMap.clear();
3188
- RecordDataForIdentifierCache.clear();
3315
+ CacheForIdentifierCache.clear();
3189
3316
  }
3190
3317
  let _modelForMixin;
3191
3318
  if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
@@ -4113,7 +4240,7 @@ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_ARRAY_LIKE)) {
4113
4240
  return this;
4114
4241
  };
4115
4242
  IdentifierArray.prototype.setObjects = function (objects) {
4116
- deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'clear', 'length = 0');
4243
+ deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'setObjects', '`arr.length = 0; arr.push(objects);`');
4117
4244
  assert(`${this.DEPRECATED_CLASS_NAME}.setObjects expects to receive an array as its argument`, Array.isArray(objects));
4118
4245
  this.splice(0, this.length);
4119
4246
  this.push(...objects);
@@ -4368,6 +4495,15 @@ class RecordArrayManager {
4368
4495
  this._pending = new Map();
4369
4496
  this._staged = new Map();
4370
4497
  this._identifiers = RecordArraysCache;
4498
+ this._subscription = this.store.notifications.subscribe('resource', (identifier, type) => {
4499
+ if (type === 'added') {
4500
+ this.identifierAdded(identifier);
4501
+ } else if (type === 'removed') {
4502
+ this.identifierRemoved(identifier);
4503
+ } else if (type === 'state') {
4504
+ this.identifierChanged(identifier);
4505
+ }
4506
+ });
4371
4507
  }
4372
4508
  _syncArray(array) {
4373
4509
  const pending = this._pending.get(array);
@@ -4549,6 +4685,8 @@ class RecordArrayManager {
4549
4685
  this.clear();
4550
4686
  this._live.clear();
4551
4687
  this.isDestroyed = true;
4688
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
4689
+ this.store.notifications.unsubscribe(this._subscription);
4552
4690
  }
4553
4691
  }
4554
4692
  function associate(array, identifiers) {
@@ -4973,14 +5111,14 @@ class FetchManager {
4973
5111
  }
4974
5112
  return identifier;
4975
5113
  }, error => {
4976
- const recordData = store._instanceCache.peek({
5114
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? store._instanceCache.peek({
4977
5115
  identifier,
4978
- bucket: 'recordData'
4979
- });
4980
- if (!recordData || recordData.isEmpty(identifier) || isLoading) {
5116
+ bucket: 'resourceCache'
5117
+ }) : store.cache;
5118
+ if (!cache || cache.isEmpty(identifier) || isLoading) {
4981
5119
  let isReleasable = true;
4982
5120
  if (macroCondition(dependencySatisfies("@ember-data/graph", "*"))) {
4983
- if (!recordData) {
5121
+ if (!cache) {
4984
5122
  const graphFor = importSync('@ember-data/graph/-private').graphFor;
4985
5123
  const graph = graphFor(store);
4986
5124
  isReleasable = graph.isReleasable(identifier);
@@ -4989,7 +5127,7 @@ class FetchManager {
4989
5127
  }
4990
5128
  }
4991
5129
  }
4992
- if (recordData || isReleasable) {
5130
+ if (cache || isReleasable) {
4993
5131
  store._instanceCache.unloadRecord(identifier);
4994
5132
  }
4995
5133
  }
@@ -5468,87 +5606,25 @@ function freeze(obj) {
5468
5606
  }
5469
5607
  return obj;
5470
5608
  }
5471
- /**
5472
- The store contains all of the data for records loaded from the server.
5473
- It is also responsible for creating instances of `Model` that wrap
5474
- the individual data for a record, so that they can be bound to in your
5475
- Handlebars templates.
5476
-
5477
- Define your application's store like this:
5478
-
5479
- ```app/services/store.js
5480
- import Store from '@ember-data/store';
5481
-
5482
- export default class MyStore extends Store {}
5483
- ```
5484
-
5485
- Most Ember.js applications will only have a single `Store` that is
5486
- automatically created by their `Ember.Application`.
5487
-
5488
- You can retrieve models from the store in several ways. To retrieve a record
5489
- for a specific id, use `Store`'s `findRecord()` method:
5490
-
5491
- ```javascript
5492
- store.findRecord('person', 123).then(function (person) {
5493
- });
5494
- ```
5495
-
5496
- By default, the store will talk to your backend using a standard
5497
- REST mechanism. You can customize how the store talks to your
5498
- backend by specifying a custom adapter:
5499
-
5500
- ```app/adapters/application.js
5501
- import Adapter from '@ember-data/adapter';
5502
-
5503
- export default class ApplicationAdapter extends Adapter {
5504
- }
5505
- ```
5506
-
5507
- You can learn more about writing a custom adapter by reading the `Adapter`
5508
- documentation.
5509
-
5510
- ### Store createRecord() vs. push() vs. pushPayload()
5511
-
5512
- The store provides multiple ways to create new record objects. They have
5513
- some subtle differences in their use which are detailed below:
5514
-
5515
- [createRecord](../methods/createRecord?anchor=createRecord) is used for creating new
5516
- records on the client side. This will return a new record in the
5517
- `created.uncommitted` state. In order to persist this record to the
5518
- backend, you will need to call `record.save()`.
5519
-
5520
- [push](../methods/push?anchor=push) is used to notify Ember Data's store of new or
5521
- updated records that exist in the backend. This will return a record
5522
- in the `loaded.saved` state. The primary use-case for `store#push` is
5523
- to notify Ember Data about record updates (full or partial) that happen
5524
- outside of the normal adapter methods (for example
5525
- [SSE](http://dev.w3.org/html5/eventsource/) or [Web
5526
- Sockets](http://www.w3.org/TR/2009/WD-websockets-20091222/)).
5527
-
5528
- [pushPayload](../methods/pushPayload?anchor=pushPayload) is a convenience wrapper for
5529
- `store#push` that will deserialize payloads if the
5530
- Serializer implements a `pushPayload` method.
5531
-
5532
- Note: When creating a new record using any of the above methods
5533
- Ember Data will update `RecordArray`s such as those returned by
5534
- `store#peekAll()` or `store#findAll()`. This means any
5535
- data bindings or computed properties that depend on the RecordArray
5536
- will automatically be synced to include the new or updated record
5537
- values.
5609
+ class Store {
5610
+ /**
5611
+ * Provides access to the NotificationManager associated
5612
+ * with this Store instance.
5613
+ *
5614
+ * The NotificationManager can be used to subscribe to
5615
+ * changes to the cache.
5616
+ *
5617
+ * @property {NotificationManager} notifications
5618
+ * @public
5619
+ */
5538
5620
 
5539
- @main @ember-data/store
5540
- @class Store
5541
- @public
5542
- @extends Ember.Service
5543
- */
5621
+ // DEBUG-only properties
5544
5622
 
5545
- class Store {
5546
5623
  /**
5547
5624
  @method init
5548
5625
  @private
5549
5626
  */
5550
5627
  constructor(createArgs) {
5551
- this.__private_singleton_recordData = void 0;
5552
5628
  this.isDestroying = false;
5553
5629
  this.isDestroyed = false;
5554
5630
  Object.assign(this, createArgs);
@@ -5564,12 +5640,12 @@ class Store {
5564
5640
  * @public
5565
5641
  */
5566
5642
  this.identifierCache = new IdentifierCache();
5643
+ this.notifications = new NotificationManager(this);
5567
5644
 
5568
5645
  // private but maybe useful to be here, somewhat intimate
5569
5646
  this.recordArrayManager = new RecordArrayManager({
5570
5647
  store: this
5571
5648
  });
5572
- this.notifications = new NotificationManager(this);
5573
5649
 
5574
5650
  // private
5575
5651
  this._fetchManager = new FetchManager(this);
@@ -5667,22 +5743,22 @@ class Store {
5667
5743
  * @method instantiateRecord (hook)
5668
5744
  * @param identifier
5669
5745
  * @param createRecordArgs
5670
- * @param recordDataFor
5671
- * @param notificationManager
5746
+ * @param recordDataFor deprecated use this.cache
5747
+ * @param notificationManager deprecated use this.notifications
5672
5748
  * @returns A record instance
5673
5749
  * @public
5674
5750
  */
5675
- instantiateRecord(identifier, createRecordArgs, recordDataFor, notificationManager) {
5751
+ instantiateRecord(identifier, createRecordArgs) {
5676
5752
  if (macroCondition(dependencySatisfies("@ember-data/model", "*"))) {
5677
5753
  let modelName = identifier.type;
5678
- let recordData = this._instanceCache.getRecordData(identifier);
5754
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._instanceCache.getResourceCache(identifier) : this.cache;
5679
5755
  // TODO deprecate allowing unknown args setting
5680
5756
  let createOptions = {
5681
5757
  _createProps: createRecordArgs,
5682
5758
  // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
5683
5759
  _secretInit: {
5684
5760
  identifier,
5685
- recordData,
5761
+ cache,
5686
5762
  store: this,
5687
5763
  cb: secretInit
5688
5764
  }
@@ -5904,10 +5980,9 @@ class Store {
5904
5980
  assert(`The id ${properties.id} has already been used with another '${normalizedModelName}' record.`, !identifier);
5905
5981
  }
5906
5982
  const identifier = this.identifierCache.createIdentifierForNewRecord(resource);
5907
- const recordData = this._instanceCache.getRecordData(identifier);
5908
- const createOptions = normalizeProperties(this, identifier, properties, recordData.managedVersion === '1');
5909
- const resultProps = recordData.clientDidCreate(identifier, createOptions);
5910
- this.recordArrayManager.identifierAdded(identifier);
5983
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._instanceCache.getResourceCache(identifier) : this.cache;
5984
+ const createOptions = normalizeProperties(this, identifier, properties, cache.managedVersion === '1');
5985
+ const resultProps = cache.clientDidCreate(identifier, createOptions);
5911
5986
  record = this._instanceCache.getRecord(identifier, resultProps);
5912
5987
  });
5913
5988
  });
@@ -5932,14 +6007,14 @@ class Store {
5932
6007
  assertDestroyingStore(this, 'deleteRecord');
5933
6008
  }
5934
6009
  const identifier = peekRecordIdentifier(record);
5935
- const recordData = identifier && this._instanceCache.peek({
6010
+ const cache = identifier && (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._instanceCache.peek({
5936
6011
  identifier,
5937
- bucket: 'recordData'
5938
- });
5939
- assert(`expected a recordData instance to exist for the record`, recordData);
6012
+ bucket: 'resourceCache'
6013
+ }) : this.cache);
6014
+ assert(`expected a cache instance to exist for the record`, cache);
5940
6015
  this._join(() => {
5941
- recordData.setIsDeleted(identifier, true);
5942
- if (recordData.isNew(identifier)) {
6016
+ cache.setIsDeleted(identifier, true);
6017
+ if (cache.isNew(identifier)) {
5943
6018
  _backburner.join(() => {
5944
6019
  this._instanceCache.unloadRecord(identifier);
5945
6020
  });
@@ -7088,31 +7163,17 @@ class Store {
7088
7163
  }
7089
7164
  let ret;
7090
7165
  this._join(() => {
7091
- let included = jsonApiDoc.included;
7092
- let i, length;
7093
- if (included) {
7094
- for (i = 0, length = included.length; i < length; i++) {
7095
- this._instanceCache.loadData(included[i]);
7096
- }
7097
- }
7098
- if (Array.isArray(jsonApiDoc.data)) {
7099
- length = jsonApiDoc.data.length;
7100
- let identifiers = new Array(length);
7101
- for (i = 0; i < length; i++) {
7102
- identifiers[i] = this._instanceCache.loadData(jsonApiDoc.data[i]);
7103
- }
7104
- ret = identifiers;
7105
- return;
7106
- }
7107
- if (jsonApiDoc.data === null) {
7108
- ret = null;
7109
- return;
7166
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA)) {
7167
+ ret = legacyCachePut(this, {
7168
+ data: jsonApiDoc
7169
+ });
7170
+ } else {
7171
+ ret = this.cache.put({
7172
+ data: jsonApiDoc
7173
+ });
7110
7174
  }
7111
- assert(`Expected an object in the 'data' property in a call to 'push' for ${jsonApiDoc.type}, but was ${typeof jsonApiDoc.data}`, typeof jsonApiDoc.data === 'object');
7112
- ret = this._instanceCache.loadData(jsonApiDoc.data);
7113
- return;
7114
7175
  });
7115
- return ret;
7176
+ return ret.data;
7116
7177
  }
7117
7178
 
7118
7179
  /**
@@ -7197,21 +7258,21 @@ class Store {
7197
7258
  saveRecord(record, options = {}) {
7198
7259
  assert(`Unable to initate save for a record in a disconnected state`, storeFor(record));
7199
7260
  let identifier = recordIdentifierFor(record);
7200
- let recordData = identifier && this._instanceCache.peek({
7261
+ const cache = identifier && (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._instanceCache.peek({
7201
7262
  identifier,
7202
- bucket: 'recordData'
7203
- });
7204
- if (!recordData) {
7263
+ bucket: 'resourceCache'
7264
+ }) : this.cache);
7265
+ if (!cache) {
7205
7266
  // this commonly means we're disconnected
7206
7267
  // but just in case we reject here to prevent bad things.
7207
7268
  return reject(`Record Is Disconnected`);
7208
7269
  }
7209
7270
  // TODO we used to check if the record was destroyed here
7210
- assert(`Cannot initiate a save request for an unloaded record: ${identifier}`, recordData && this._instanceCache.recordIsLoaded(identifier));
7211
- if (recordDataIsFullyDeleted(this._instanceCache, identifier)) {
7271
+ assert(`Cannot initiate a save request for an unloaded record: ${identifier}`, cache && this._instanceCache.recordIsLoaded(identifier));
7272
+ if (resourceIsFullyDeleted(this._instanceCache, identifier)) {
7212
7273
  return resolve(record);
7213
7274
  }
7214
- recordData.willCommit(identifier);
7275
+ cache.willCommit(identifier);
7215
7276
  if (isDSModel(record)) {
7216
7277
  record.errors.clear();
7217
7278
  }
@@ -7219,9 +7280,9 @@ class Store {
7219
7280
  options = {};
7220
7281
  }
7221
7282
  let operation = 'updateRecord';
7222
- if (recordData.isNew(identifier)) {
7283
+ if (cache.isNew(identifier)) {
7223
7284
  operation = 'createRecord';
7224
- } else if (recordData.isDeleted(identifier)) {
7285
+ } else if (cache.isDeleted(identifier)) {
7225
7286
  operation = 'deleteRecord';
7226
7287
  }
7227
7288
  const saveOptions = Object.assign({
@@ -7257,18 +7318,15 @@ class Store {
7257
7318
  if (!data) {
7258
7319
  assert(`Your ${identifier.type} record was saved to the server, but the response does not have an id and no id has been set client side. Records must have ids. Please update the server response to provide an id in the response or generate the id on the client side either before saving the record or while normalizing the response.`, identifier.id);
7259
7320
  }
7260
- const cache = this.identifierCache;
7321
+ const identifierCache = this.identifierCache;
7261
7322
  let actualIdentifier = identifier;
7262
7323
  if (operation !== 'deleteRecord' && data) {
7263
- actualIdentifier = cache.updateRecordIdentifier(identifier, data);
7324
+ actualIdentifier = identifierCache.updateRecordIdentifier(identifier, data);
7264
7325
  }
7265
7326
 
7266
7327
  //We first make sure the primary data has been updated
7267
- const recordData = this._instanceCache.getRecordData(actualIdentifier);
7268
- recordData.didCommit(identifier, data);
7269
- if (operation === 'deleteRecord') {
7270
- this.recordArrayManager.identifierRemoved(actualIdentifier);
7271
- }
7328
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this._instanceCache.getResourceCache(actualIdentifier) : this.cache;
7329
+ cache.didCommit(identifier, data);
7272
7330
  if (payload && payload.included) {
7273
7331
  this._push({
7274
7332
  data: null,
@@ -7291,49 +7349,60 @@ class Store {
7291
7349
 
7292
7350
  /**
7293
7351
  * Instantiation hook allowing applications or addons to configure the store
7294
- * to utilize a custom RecordData implementation.
7352
+ * to utilize a custom Cache implementation.
7295
7353
  *
7296
- * @method createRecordDataFor (hook)
7354
+ * This hook should not be called directly by consuming applications or libraries.
7355
+ * Use `Store.cache` to access the Cache instance.
7356
+ *
7357
+ * @method createCache (hook)
7297
7358
  * @public
7298
- * @param identifier
7299
7359
  * @param storeWrapper
7360
+ * @returns {Cache}
7300
7361
  */
7301
- createRecordDataFor(identifier, storeWrapper) {
7362
+ createCache(storeWrapper) {
7302
7363
  if (macroCondition(dependencySatisfies("@ember-data/json-api", "*"))) {
7303
- // we can't greedily use require as this causes
7304
- // a cycle we can't easily fix (or clearly pin point) at present.
7305
- //
7306
- // it can be reproduced in partner tests by running
7307
- // node ./scripts/packages-for-commit.js && pnpm test-external:ember-observer
7308
7364
  if (_Cache === undefined) {
7309
- _Cache = importSync('@ember-data/json-api/-private').Cache;
7365
+ _Cache = importSync('@ember-data/json-api').Cache;
7310
7366
  }
7311
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_V1CACHE_STORE_APIS)) {
7312
- if (arguments.length === 4) {
7313
- deprecate(`Store.createRecordDataFor(<type>, <id>, <lid>, <storeWrapper>) has been deprecated in favor of Store.createRecordDataFor(<identifier>, <storeWrapper>)`, false, {
7314
- id: 'ember-data:deprecate-v1cache-store-apis',
7315
- for: 'ember-data',
7316
- until: '5.0',
7317
- since: {
7318
- enabled: '4.7',
7319
- available: '4.7'
7320
- }
7321
- });
7322
- identifier = this.identifierCache.getOrCreateRecordIdentifier({
7323
- type: arguments[0],
7324
- id: arguments[1],
7325
- lid: arguments[2]
7326
- });
7327
- storeWrapper = arguments[3];
7328
- }
7367
+ return new _Cache(storeWrapper);
7368
+ }
7369
+ assert(`Expected store.createCache to be implemented but it wasn't`);
7370
+ }
7371
+
7372
+ /**
7373
+ * Returns the cache instance associated to this Store, instantiates the Cache
7374
+ * if necessary via `Store.createCache`
7375
+ *
7376
+ * @property {Cache} cache
7377
+ * @public
7378
+ */
7379
+ get cache() {
7380
+ let {
7381
+ cache
7382
+ } = this._instanceCache;
7383
+ if (!cache) {
7384
+ cache = this._instanceCache.cache = this.createCache(this._instanceCache._storeWrapper);
7385
+ if (macroCondition(isDevelopingApp())) {
7386
+ cache = new SingletonCacheManager(cache);
7329
7387
  }
7330
- this.__private_singleton_recordData = this.__private_singleton_recordData || new _Cache(storeWrapper);
7331
- this.__private_singleton_recordData.createCache(identifier);
7332
- return this.__private_singleton_recordData;
7333
7388
  }
7334
- assert(`Expected store.createRecordDataFor to be implemented but it wasn't`);
7389
+ return cache;
7335
7390
  }
7336
7391
 
7392
+ /**
7393
+ * [DEPRECATED] use Store.createCache
7394
+ *
7395
+ * Instantiation hook allowing applications or addons to configure the store
7396
+ * to utilize a custom RecordData implementation.
7397
+ *
7398
+ * @method createRecordDataFor (hook)
7399
+ * @deprecated
7400
+ * @public
7401
+ * @param identifier
7402
+ * @param storeWrapper
7403
+ * @returns {Cache}
7404
+ */
7405
+
7337
7406
  /**
7338
7407
  `normalize` converts a json payload into the normalized form that
7339
7408
  [push](../methods/push?anchor=push) expects.
@@ -7548,9 +7617,9 @@ function adapterDidInvalidate(store, identifier, error) {
7548
7617
  error.errors = errorsHashToArray(errorsHash);
7549
7618
  }
7550
7619
  }
7551
- const recordData = store._instanceCache.getRecordData(identifier);
7620
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? store._instanceCache.getResourceCache(identifier) : store.cache;
7552
7621
  if (error.errors) {
7553
- assert(`Expected the RecordData implementation for ${identifier} to have a getErrors(identifier) method for retreiving errors.`, typeof recordData.getErrors === 'function');
7622
+ assert(`Expected the RecordData implementation for ${identifier} to have a getErrors(identifier) method for retreiving errors.`, typeof cache.getErrors === 'function');
7554
7623
  let jsonApiErrors = error.errors;
7555
7624
  if (jsonApiErrors.length === 0) {
7556
7625
  jsonApiErrors = [{
@@ -7561,9 +7630,9 @@ function adapterDidInvalidate(store, identifier, error) {
7561
7630
  }
7562
7631
  }];
7563
7632
  }
7564
- recordData.commitWasRejected(identifier, jsonApiErrors);
7633
+ cache.commitWasRejected(identifier, jsonApiErrors);
7565
7634
  } else {
7566
- recordData.commitWasRejected(identifier);
7635
+ cache.commitWasRejected(identifier);
7567
7636
  }
7568
7637
  }
7569
7638
  function makeArray(value) {
@@ -7651,7 +7720,7 @@ function extractIdentifierFromRecord(recordOrPromiseRecord, isForV1 = false) {
7651
7720
  if (!recordOrPromiseRecord) {
7652
7721
  return null;
7653
7722
  }
7654
- const extract = isForV1 ? recordDataFor : recordIdentifierFor;
7723
+ const extract = isForV1 ? peekCache : recordIdentifierFor;
7655
7724
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_PROMISE_PROXIES)) {
7656
7725
  if (isPromiseRecord(recordOrPromiseRecord)) {
7657
7726
  let content = recordOrPromiseRecord.content;
@@ -7673,10 +7742,10 @@ function extractIdentifierFromRecord(recordOrPromiseRecord, isForV1 = false) {
7673
7742
  function isPromiseRecord(record) {
7674
7743
  return !!record.then;
7675
7744
  }
7676
- function secretInit(record, recordData, identifier, store) {
7745
+ function secretInit(record, cache, identifier, store) {
7677
7746
  setRecordIdentifier(record, identifier);
7678
7747
  StoreMap.set(record, store);
7679
- setRecordDataFor(record, recordData);
7748
+ setCacheFor(record, cache);
7680
7749
  }
7681
7750
  function normalizeModelName(modelName) {
7682
7751
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_HELPERS)) {
@@ -7693,4 +7762,4 @@ function normalizeModelName(modelName) {
7693
7762
  }
7694
7763
  assert(`normalizeModelName support has been removed`);
7695
7764
  }
7696
- export { Collection as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, Snapshot as a, setIdentifierGenerationMethod as b, setIdentifierUpdateMethod as c, setIdentifierForgetMethod as d, setIdentifierResetMethod as e, coerceId as f, notifyArray as g, SOURCE as h, isStableIdentifier as i, IDENTIFIER_ARRAY_TAG as j, fastPush as k, SnapshotRecordArray as l, recordDataFor as m, normalizeModelName as n, removeRecordDataFor as o, recordIdentifierFor as r, storeFor as s };
7765
+ export { Collection as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, Snapshot as a, setIdentifierGenerationMethod as b, setIdentifierUpdateMethod as c, setIdentifierForgetMethod as d, setIdentifierResetMethod as e, coerceId as f, notifyArray as g, SOURCE as h, isStableIdentifier as i, IDENTIFIER_ARRAY_TAG as j, fastPush as k, SnapshotRecordArray as l, removeRecordDataFor as m, normalizeModelName as n, peekCache as p, recordIdentifierFor as r, storeFor as s };