@ember-data/store 5.4.0-alpha.5 → 5.4.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/addon/-private.js CHANGED
@@ -1 +1 @@
1
- export { f as AdapterPopulatedRecordArray, C as CacheHandler, h as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, m as StoreMap, _ as _clearCaches, e as coerceId, j as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, k as removeRecordDataFor, o as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, l as setRecordIdentifier, s as storeFor } from "./store-service-aa7f91c0";
1
+ export { f as AdapterPopulatedRecordArray, C as CacheHandler, h as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, m as StoreMap, _ as _clearCaches, e as coerceId, j as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, k as removeRecordDataFor, o as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, l as setRecordIdentifier, s as storeFor } from "./store-service-fc1e0bd5";
package/addon/index.js CHANGED
@@ -1 +1 @@
1
- export { C as CacheHandler, S as default, r as recordIdentifierFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./store-service-aa7f91c0";
1
+ export { C as CacheHandler, S as default, r as recordIdentifierFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./store-service-fc1e0bd5";
@@ -664,7 +664,7 @@ class IdentifierCache {
664
664
  console.log(`Identifiers: ${lid ? 'no ' : ''}lid ${lid ? lid + ' ' : ''}determined for resource`, resource);
665
665
  }
666
666
  let identifier = /*#__NOINLINE__*/getIdentifierFromLid(this._cache, lid, resource);
667
- if (identifier !== undefined) {
667
+ if (identifier !== null) {
668
668
  if (macroCondition(getOwnConfig().debug.LOG_IDENTIFIERS)) {
669
669
  // eslint-disable-next-line no-console
670
670
  console.groupEnd();
@@ -953,17 +953,22 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
953
953
  },
954
954
  set [DEBUG_STALE_CACHE_OWNER](value) {
955
955
  recordIdentifier[DEBUG_STALE_CACHE_OWNER] = value;
956
- },
957
- // @ts-expect-error debug only
958
- toString() {
956
+ }
957
+ };
958
+ Object.defineProperty(wrapper, 'toString', {
959
+ enumerable: false,
960
+ value: () => {
959
961
  const {
960
962
  type,
961
963
  id,
962
964
  lid
963
965
  } = recordIdentifier;
964
966
  return `${clientOriginated ? '[CLIENT_ORIGINATED] ' : ''}${String(type)}:${String(id)} (${lid})`;
965
- },
966
- toJSON() {
967
+ }
968
+ });
969
+ Object.defineProperty(wrapper, 'toJSON', {
970
+ enumerable: false,
971
+ value: () => {
967
972
  const {
968
973
  type,
969
974
  id,
@@ -975,7 +980,7 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
975
980
  lid
976
981
  };
977
982
  }
978
- };
983
+ });
979
984
  wrapper[DEBUG_CLIENT_ORIGINATED] = clientOriginated;
980
985
  wrapper[DEBUG_IDENTIFIER_BUCKET] = bucket;
981
986
  IDENTIFIERS.add(wrapper);
@@ -1048,7 +1053,7 @@ function detectMerge(cache, keyInfo, identifier, data) {
1048
1053
  // we trigger a merge of the identifiers
1049
1054
  // though probably we should just throw an error here
1050
1055
  if (id !== null && id === newId && newType === type && hasLid(data) && data.lid !== lid) {
1051
- return cache.resources.get(data.lid) || false;
1056
+ return getIdentifierFromLid(cache, data.lid, data) || false;
1052
1057
 
1053
1058
  // If the lids are the same, and ids are the same, but types are different we should trigger a merge of the identifiers
1054
1059
  } else if (id !== null && id === newId && newType && newType !== type && hasLid(data) && data.lid === lid) {
@@ -1065,7 +1070,7 @@ function getIdentifierFromLid(cache, lid, resource) {
1065
1070
  // eslint-disable-next-line no-console
1066
1071
  console.log(`Identifiers: cache ${identifier ? 'HIT' : 'MISS'} - Non-Stable ${lid}`, resource);
1067
1072
  }
1068
- return identifier;
1073
+ return identifier || null;
1069
1074
  }
1070
1075
  function addResourceToCache(cache, identifier) {
1071
1076
  cache.resources.set(identifier.lid, identifier);
@@ -2227,6 +2232,65 @@ class CacheManager {
2227
2232
  // Relationships
2228
2233
  // =============
2229
2234
 
2235
+ /**
2236
+ * Query the cache for the changes to relationships of a resource.
2237
+ *
2238
+ * Returns a map of relationship names to RelationshipDiff objects.
2239
+ *
2240
+ * ```ts
2241
+ * type RelationshipDiff =
2242
+ | {
2243
+ kind: 'collection';
2244
+ remoteState: StableRecordIdentifier[];
2245
+ additions: Set<StableRecordIdentifier>;
2246
+ removals: Set<StableRecordIdentifier>;
2247
+ localState: StableRecordIdentifier[];
2248
+ reordered: boolean;
2249
+ }
2250
+ | {
2251
+ kind: 'resource';
2252
+ remoteState: StableRecordIdentifier | null;
2253
+ localState: StableRecordIdentifier | null;
2254
+ };
2255
+ ```
2256
+ *
2257
+ * @method changedRelationships
2258
+ * @public
2259
+ * @param {StableRecordIdentifier} identifier
2260
+ * @returns {Map<string, RelationshipDiff>}
2261
+ */
2262
+ changedRelationships(identifier) {
2263
+ return _classPrivateFieldBase(this, _cache)[_cache].changedRelationships(identifier);
2264
+ }
2265
+
2266
+ /**
2267
+ * Query the cache for whether any mutated attributes exist
2268
+ *
2269
+ * @method hasChangedRelationships
2270
+ * @public
2271
+ * @param {StableRecordIdentifier} identifier
2272
+ * @returns {boolean}
2273
+ */
2274
+ hasChangedRelationships(identifier) {
2275
+ return _classPrivateFieldBase(this, _cache)[_cache].hasChangedRelationships(identifier);
2276
+ }
2277
+
2278
+ /**
2279
+ * Tell the cache to discard any uncommitted mutations to relationships.
2280
+ *
2281
+ * This will also discard the change on any appropriate inverses.
2282
+ *
2283
+ * This method is a candidate to become a mutation
2284
+ *
2285
+ * @method rollbackRelationships
2286
+ * @public
2287
+ * @param {StableRecordIdentifier} identifier
2288
+ * @returns {string[]} the names of relationships that were restored
2289
+ */
2290
+ rollbackRelationships(identifier) {
2291
+ return _classPrivateFieldBase(this, _cache)[_cache].rollbackRelationships(identifier);
2292
+ }
2293
+
2230
2294
  /**
2231
2295
  * Query the cache for the current state of a relationship property
2232
2296
  *
@@ -4057,7 +4121,7 @@ class Store extends EmberObject {
4057
4121
  // to avoid conflicts.
4058
4122
 
4059
4123
  if (properties.id === null || properties.id === undefined) {
4060
- let adapter = this.adapterFor(modelName);
4124
+ let adapter = this.adapterFor(modelName, true);
4061
4125
  if (adapter && adapter.generateIdForRecord) {
4062
4126
  properties.id = adapter.generateIdForRecord(this, modelName, properties);
4063
4127
  } else {
@@ -5324,7 +5388,8 @@ class Store extends EmberObject {
5324
5388
  @param {String} modelName
5325
5389
  @return Adapter
5326
5390
  */
5327
- adapterFor(modelName) {
5391
+
5392
+ adapterFor(modelName, _allowMissing) {
5328
5393
  if (macroCondition(getOwnConfig().env.DEBUG)) {
5329
5394
  assertDestroyingStore(this, 'adapterFor');
5330
5395
  }
@@ -5354,7 +5419,7 @@ class Store extends EmberObject {
5354
5419
  _adapterCache.application = adapter;
5355
5420
  return adapter;
5356
5421
  }
5357
- assert(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`);
5422
+ assert(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`, _allowMissing);
5358
5423
  }
5359
5424
 
5360
5425
  /**