@ember-data/store 4.12.0-beta.5 → 4.12.0-beta.6

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, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, S as Store, _ as _clearCaches, e as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, p as peekCache, r as recordIdentifierFor, l as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./index-123f3e7e";
1
+ export { f as AdapterPopulatedRecordArray, C as CacheHandler, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, S as Store, _ as _clearCaches, e as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, p as peekCache, r as recordIdentifierFor, l as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./index-35424a6b";
@@ -727,9 +727,9 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con
727
727
  return desc;
728
728
  }
729
729
  let tokenId = 0;
730
- const CacheOperations = new Set(['added', 'removed', 'state', 'updated']);
730
+ const CacheOperations$1 = new Set(['added', 'removed', 'state', 'updated']);
731
731
  function isCacheOperationValue(value) {
732
- return CacheOperations.has(value);
732
+ return CacheOperations$1.has(value);
733
733
  }
734
734
  function runLoopIsFlushing() {
735
735
  //@ts-expect-error
@@ -2826,7 +2826,7 @@ class InstanceCache {
2826
2826
  return reference;
2827
2827
  }
2828
2828
  recordIsLoaded(identifier, filterDeleted = false) {
2829
- const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.__instances.resourceCache.get(identifier) : this.cache;
2829
+ const cache = macroCondition(getOwnConfig().deprecations.DEPRECATE_V1_RECORD_DATA) ? this.__instances.resourceCache.get(identifier) || this.cache : this.cache;
2830
2830
  if (!cache) {
2831
2831
  return false;
2832
2832
  }
@@ -4294,6 +4294,7 @@ class RecordArrayManager {
4294
4294
  this._managed = new Set();
4295
4295
  this._pending = new Map();
4296
4296
  this._staged = new Map();
4297
+ this._keyedArrays = new Map();
4297
4298
  this._identifiers = RecordArraysCache;
4298
4299
  this._subscription = this.store.notifications.subscribe('resource', (identifier, type) => {
4299
4300
  if (type === 'added') {
@@ -6797,7 +6798,11 @@ function secretInit(record, cache, identifier, store) {
6797
6798
  StoreMap.set(record, store);
6798
6799
  setCacheFor(record, cache);
6799
6800
  }
6801
+ const CacheOperations = new Set(['findRecord', 'findAll', 'query', 'queryRecord', 'findBelongsTo', 'findHasMany', 'updateRecord', 'createRecord', 'deleteRecord']);
6800
6802
  function getHydratedContent(store, request, document) {
6803
+ if (!request.op || !CacheOperations.has(request.op)) {
6804
+ return document;
6805
+ }
6801
6806
  if (Array.isArray(document.data)) {
6802
6807
  const {
6803
6808
  lid
@@ -6824,7 +6829,14 @@ function getHydratedContent(store, request, document) {
6824
6829
  }
6825
6830
  return managed;
6826
6831
  } else {
6827
- return document.data ? store.peekRecord(document.data) : null;
6832
+ switch (request.op) {
6833
+ case 'findBelongsTo':
6834
+ case 'queryRecord':
6835
+ case 'findRecord':
6836
+ return document.data ? store.peekRecord(document.data) : null;
6837
+ default:
6838
+ return document.data;
6839
+ }
6828
6840
  }
6829
6841
  }
6830
6842
  function calcShouldFetch(store, request, hasCachedValue, lid) {
@@ -6833,7 +6845,7 @@ function calcShouldFetch(store, request, hasCachedValue, lid) {
6833
6845
  url,
6834
6846
  method
6835
6847
  } = request;
6836
- return cacheOptions?.reload || !hasCachedValue || store.lifetimes && lid && url && method ? store.lifetimes.isHardExpired(lid, url, method) : false;
6848
+ return cacheOptions?.reload || !hasCachedValue || (store.lifetimes && lid && url && method ? store.lifetimes.isHardExpired(lid, url, method) : false);
6837
6849
  }
6838
6850
  function calcShouldBackgroundFetch(store, request, willFetch, lid) {
6839
6851
  const {
@@ -6841,19 +6853,32 @@ function calcShouldBackgroundFetch(store, request, willFetch, lid) {
6841
6853
  url,
6842
6854
  method
6843
6855
  } = request;
6844
- return !willFetch && (cacheOptions?.backgroundReload || store.lifetimes && lid && url && method ? store.lifetimes.isSoftExpired(lid, url, method) : false);
6856
+ return !willFetch && (cacheOptions?.backgroundReload || (store.lifetimes && lid && url && method ? store.lifetimes.isSoftExpired(lid, url, method) : false));
6845
6857
  }
6846
6858
  function fetchContentAndHydrate(next, context, shouldFetch, shouldBackgroundFetch) {
6847
6859
  const {
6848
6860
  store
6849
6861
  } = context.request;
6850
6862
  return next(context.request).then(document => {
6851
- const response = store.cache.put(document);
6863
+ store._enableAsyncFlush = true;
6864
+ let response;
6865
+ store._join(() => {
6866
+ response = store.cache.put(document);
6867
+ if (shouldFetch) {
6868
+ response = getHydratedContent(store, context.request, response);
6869
+ }
6870
+ });
6871
+ store._enableAsyncFlush = null;
6852
6872
  if (shouldFetch) {
6853
- return getHydratedContent(store, context.request, response);
6873
+ return response;
6854
6874
  }
6855
6875
  }, error => {
6856
- store.cache.put(error);
6876
+ store._enableAsyncFlush = true;
6877
+ store._join(() => {
6878
+ store.cache.put(error);
6879
+ });
6880
+ store._enableAsyncFlush = null;
6881
+
6857
6882
  // TODO @runspired this is probably not the right thing to throw so make sure we add a test
6858
6883
  if (!shouldBackgroundFetch) {
6859
6884
  throw error;
@@ -6863,7 +6888,7 @@ function fetchContentAndHydrate(next, context, shouldFetch, shouldBackgroundFetc
6863
6888
  const CacheHandler = {
6864
6889
  request(context, next) {
6865
6890
  // if we are a legacy request or did not originate from the store, skip cache handling
6866
- if (!context.request.store || context.request.op && !context.request.url) {
6891
+ if (!context.request.store || context.request.op && CacheOperations.has(context.request.op) && !context.request.url) {
6867
6892
  return next(context.request);
6868
6893
  }
6869
6894
  const {