@ember-data/store 5.4.0-alpha.91 → 5.4.0-alpha.94

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/dist/-private.js CHANGED
@@ -1 +1 @@
1
- export { A as ARRAY_SIGNAL, C as CacheHandler, j as CollectionRecordArray, I as LiveArray, M as MUTATE, R as RecordArrayManager, k as SOURCE, S as Store, q as StoreMap, _ as _clearCaches, u as _deprecatingNormalize, g as coerceId, f as constructResource, h as ensureStringId, l as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, m as removeRecordDataFor, t as setCacheFor, o as setRecordIdentifier, s as storeFor } from "./cache-handler-C5ilAUZ5.js";
1
+ export { A as ARRAY_SIGNAL, C as CacheHandler, j as CollectionRecordArray, I as LiveArray, M as MUTATE, R as RecordArrayManager, k as SOURCE, S as Store, q as StoreMap, _ as _clearCaches, u as _deprecatingNormalize, g as coerceId, f as constructResource, h as ensureStringId, l as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, m as removeRecordDataFor, t as setCacheFor, o as setRecordIdentifier, s as storeFor } from "./handler-DEXNABd3.js";
@@ -75,7 +75,7 @@ function normalizeModelName(type) {
75
75
 
76
76
  function installPolyfill() {
77
77
  const isFastBoot = typeof FastBoot !== 'undefined';
78
- const CRYPTO = isFastBoot ? FastBoot.require('crypto') : window.crypto;
78
+ const CRYPTO = isFastBoot ? FastBoot.require('crypto') : globalThis.crypto;
79
79
  if (!CRYPTO.randomUUID) {
80
80
  // we might be able to optimize this by requesting more bytes than we need at a time
81
81
  const rng = function () {
@@ -138,7 +138,7 @@ function isDocumentIdentifier(identifier) {
138
138
  return DOCUMENTS.has(identifier);
139
139
  }
140
140
  const isFastBoot = typeof FastBoot !== 'undefined';
141
- const _crypto = isFastBoot ? FastBoot.require('crypto') : window.crypto;
141
+ const _crypto = isFastBoot ? FastBoot.require('crypto') : globalThis.crypto;
142
142
  if (macroCondition(getGlobalConfig().WarpDrive.polyfillUUID)) {
143
143
  installPolyfill();
144
144
  }
@@ -3766,6 +3766,17 @@ class Store extends BaseClass {
3766
3766
 
3767
3767
  // Private
3768
3768
 
3769
+ /**
3770
+ * Async flush buffers notifications until flushed
3771
+ * by finalization of a future configured by store.request
3772
+ *
3773
+ * This is useful for ensuring that notifications are delivered
3774
+ * prior to the promise resolving but without risk of promise
3775
+ * interleaving.
3776
+ *
3777
+ * @internal
3778
+ */
3779
+
3769
3780
  // DEBUG-only properties
3770
3781
 
3771
3782
  get isDestroying() {
@@ -3839,6 +3850,16 @@ class Store extends BaseClass {
3839
3850
  this._cbs = null;
3840
3851
  }
3841
3852
  }
3853
+
3854
+ /**
3855
+ * Executes the callback, ensurng that any work that calls
3856
+ * store._schedule is executed after in the right order.
3857
+ *
3858
+ * When queues already exist, scheduled callbacks will
3859
+ * join the existing queue.
3860
+ *
3861
+ * @internal
3862
+ */
3842
3863
  _join(cb) {
3843
3864
  if (this._cbs) {
3844
3865
  cb();
@@ -5709,29 +5730,154 @@ defineSignal(Document.prototype, 'data');
5709
5730
  defineSignal(Document.prototype, 'links');
5710
5731
  defineSignal(Document.prototype, 'errors');
5711
5732
  defineSignal(Document.prototype, 'meta');
5733
+ const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);
5734
+ function calcShouldFetch(store, request, hasCachedValue, identifier) {
5735
+ const {
5736
+ cacheOptions
5737
+ } = request;
5738
+ return request.op && MUTATION_OPS.has(request.op) || cacheOptions?.reload || !hasCachedValue || (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier, store) : false);
5739
+ }
5740
+ function calcShouldBackgroundFetch(store, request, willFetch, identifier) {
5741
+ const {
5742
+ cacheOptions
5743
+ } = request;
5744
+ return cacheOptions?.backgroundReload || (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier, store) : false);
5745
+ }
5746
+ function isMutation(request) {
5747
+ return Boolean(request.op && MUTATION_OPS.has(request.op));
5748
+ }
5749
+ function copyDocumentProperties(target, source) {
5750
+ if ('links' in source) {
5751
+ target.links = source.links;
5752
+ }
5753
+ if ('meta' in source) {
5754
+ target.meta = source.meta;
5755
+ }
5756
+ if ('errors' in source) {
5757
+ target.errors = source.errors;
5758
+ }
5759
+ }
5760
+ function isCacheAffecting(document) {
5761
+ if (!isMutation(document.request)) {
5762
+ return true;
5763
+ }
5764
+ // a mutation combined with a 204 has no cache impact when no known records were involved
5765
+ // a createRecord with a 201 with an empty response and no known records should similarly
5766
+ // have no cache impact
5767
+
5768
+ if (document.request.op === 'createRecord' && document.response?.status === 201) {
5769
+ return document.content ? Object.keys(document.content).length > 0 : false;
5770
+ }
5771
+ return document.response?.status !== 204;
5772
+ }
5773
+ function isAggregateError(error) {
5774
+ return error instanceof AggregateError || error.name === 'AggregateError' && Array.isArray(error.errors);
5775
+ }
5776
+ // TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
5777
+ function cloneError(error) {
5778
+ const isAggregate = isAggregateError(error);
5779
+ const cloned = isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message);
5780
+ cloned.stack = error.stack;
5781
+ cloned.error = error.error;
5782
+
5783
+ // copy over enumerable properties
5784
+ Object.assign(cloned, error);
5785
+ return cloned;
5786
+ }
5787
+ function isErrorDocument(document) {
5788
+ return 'errors' in document;
5789
+ }
5712
5790
 
5713
5791
  /**
5714
5792
  * @module @ember-data/store
5715
5793
  */
5716
5794
 
5717
5795
  /**
5718
- * A service which an application may provide to the store via
5719
- * the store's `lifetimes` property to configure the behavior
5720
- * of the CacheHandler.
5796
+ * A CacheHandler that adds support for using an EmberData Cache with a RequestManager.
5797
+ *
5798
+ * This handler will only run when a request has supplied a `store` instance. Requests
5799
+ * issued by the store via `store.request()` will automatically have the `store` instance
5800
+ * attached to the request.
5801
+ *
5802
+ * ```ts
5803
+ * requestManager.request({
5804
+ * store: store,
5805
+ * url: '/api/posts',
5806
+ * method: 'GET'
5807
+ * });
5808
+ * ```
5721
5809
  *
5722
- * The default behavior for request lifetimes is to never expire
5723
- * unless manually refreshed via `cacheOptions.reload` or `cacheOptions.backgroundReload`.
5810
+ * When this handler elects to handle a request, it will return the raw `StructuredDocument`
5811
+ * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
5812
+ * return a `Document` instance that will automatically update the UI when the cache is updated
5813
+ * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
5724
5814
  *
5725
- * Implementing this service allows you to programatically define
5726
- * when a request should be considered expired.
5815
+ * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
5816
+ * means that if desired you can issue requests that utilize the cache without needing to also
5817
+ * utilize Record instances if desired.
5727
5818
  *
5728
- * @class <Interface> CachePolicy
5729
- * @public
5819
+ * Said differently, you could elect to issue all requests via a RequestManager, without ever using
5820
+ * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
5821
+ * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
5822
+ * approach of EmberData allows for this flexibility.
5823
+ *
5824
+ * ```ts
5825
+ * import { EnableHydration } from '@warp-drive/core-types/request';
5826
+ *
5827
+ * requestManager.request({
5828
+ * store: store,
5829
+ * url: '/api/posts',
5830
+ * method: 'GET',
5831
+ * [EnableHydration]: true
5832
+ * });
5833
+ *
5834
+ * @typedoc
5730
5835
  */
5731
- const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);
5732
- function isErrorDocument(document) {
5733
- return 'errors' in document;
5734
- }
5836
+ const CacheHandler = {
5837
+ request(context, next) {
5838
+ // if we have no cache or no cache-key skip cache handling
5839
+ if (!context.request.store || context.request.cacheOptions?.[SkipCache]) {
5840
+ return next(context.request);
5841
+ }
5842
+ const {
5843
+ store
5844
+ } = context.request;
5845
+ const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);
5846
+ const peeked = identifier ? store.cache.peekRequest(identifier) : null;
5847
+
5848
+ // determine if we should skip cache
5849
+ if (calcShouldFetch(store, context.request, !!peeked, identifier)) {
5850
+ return fetchContentAndHydrate(next, context, identifier, true, false);
5851
+ }
5852
+
5853
+ // if we have not skipped cache, determine if we should update behind the scenes
5854
+ if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {
5855
+ const promise = fetchContentAndHydrate(next, context, identifier, false, true);
5856
+ store.requestManager._pending.set(context.id, promise);
5857
+ }
5858
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5859
+ if (!test) {
5860
+ throw new Error(`Expected a peeked request to be present`);
5861
+ }
5862
+ })(peeked) : {};
5863
+ const shouldHydrate = context.request[EnableHydration] || false;
5864
+ context.setResponse(peeked.response);
5865
+ if ('error' in peeked) {
5866
+ const content = shouldHydrate ? maybeUpdateErrorUiObjects(store, {
5867
+ shouldHydrate,
5868
+ identifier
5869
+ }, peeked.content, true) : peeked.content;
5870
+ const newError = cloneError(peeked);
5871
+ newError.content = content;
5872
+ throw newError;
5873
+ }
5874
+ const result = shouldHydrate ? maybeUpdateUiObjects(store, context.request, {
5875
+ shouldHydrate,
5876
+ identifier
5877
+ }, peeked.content, true) : peeked.content;
5878
+ return result;
5879
+ }
5880
+ };
5735
5881
  function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
5736
5882
  const {
5737
5883
  identifier
@@ -5744,26 +5890,6 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
5744
5890
  })(!options.shouldHydrate) : {};
5745
5891
  return document;
5746
5892
  }
5747
- if (isErrorDocument(document)) {
5748
- if (!identifier && !options.shouldHydrate) {
5749
- return document;
5750
- }
5751
- let doc;
5752
- if (identifier) {
5753
- doc = store._documentCache.get(identifier);
5754
- }
5755
- if (!doc) {
5756
- doc = new Document(store, identifier);
5757
- copyDocumentProperties(doc, document);
5758
- if (identifier) {
5759
- store._documentCache.set(identifier, doc);
5760
- }
5761
- } else if (!isFromCache) {
5762
- doc.data = undefined;
5763
- copyDocumentProperties(doc, document);
5764
- }
5765
- return options.shouldHydrate ? doc : document;
5766
- }
5767
5893
  if (Array.isArray(document.data)) {
5768
5894
  const {
5769
5895
  recordArrayManager
@@ -5831,26 +5957,118 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
5831
5957
  return options.shouldHydrate ? doc : document;
5832
5958
  }
5833
5959
  }
5834
- function calcShouldFetch(store, request, hasCachedValue, identifier) {
5960
+ function maybeUpdateErrorUiObjects(store, options, document, isFromCache) {
5835
5961
  const {
5836
- cacheOptions
5837
- } = request;
5838
- return request.op && MUTATION_OPS.has(request.op) || cacheOptions?.reload || !hasCachedValue || (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier, store) : false);
5962
+ identifier
5963
+ } = options;
5964
+
5965
+ // TODO investigate why ResourceErrorDocument is insufficient for expressing all error types
5966
+ if (!isErrorDocument(document) || !identifier && !options.shouldHydrate) {
5967
+ return document;
5968
+ }
5969
+ let doc;
5970
+ if (identifier) {
5971
+ doc = store._documentCache.get(identifier);
5972
+ }
5973
+ if (!doc) {
5974
+ doc = new Document(store, identifier);
5975
+ copyDocumentProperties(doc, document);
5976
+ if (identifier) {
5977
+ store._documentCache.set(identifier, doc);
5978
+ }
5979
+ } else if (!isFromCache) {
5980
+ doc.data = undefined;
5981
+ copyDocumentProperties(doc, document);
5982
+ }
5983
+ return options.shouldHydrate ? doc : document;
5839
5984
  }
5840
- function calcShouldBackgroundFetch(store, request, willFetch, identifier) {
5985
+ function updateCacheForSuccess(store, request, options, document) {
5986
+ let response = null;
5987
+ if (isMutation(request)) {
5988
+ const record = request.data?.record || request.records?.[0];
5989
+ if (record) {
5990
+ response = store.cache.didCommit(record, document);
5991
+
5992
+ // a mutation combined with a 204 has no cache impact when no known records were involved
5993
+ // a createRecord with a 201 with an empty response and no known records should similarly
5994
+ // have no cache impact
5995
+ } else if (isCacheAffecting(document)) {
5996
+ response = store.cache.put(document);
5997
+ }
5998
+ } else {
5999
+ response = store.cache.put(document);
6000
+ }
6001
+ return maybeUpdateUiObjects(store, request, options, response, false);
6002
+ }
6003
+ function handleFetchSuccess(store, context, options, document) {
5841
6004
  const {
5842
- cacheOptions
5843
- } = request;
5844
- return cacheOptions?.backgroundReload || (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier, store) : false);
6005
+ request
6006
+ } = context;
6007
+ store.requestManager._pending.delete(context.id);
6008
+ store._enableAsyncFlush = true;
6009
+ let response;
6010
+ store._join(() => {
6011
+ response = updateCacheForSuccess(store, request, options, document);
6012
+ });
6013
+ store._enableAsyncFlush = null;
6014
+ if (store.lifetimes?.didRequest) {
6015
+ store.lifetimes.didRequest(context.request, document.response, options.identifier, store);
6016
+ }
6017
+ if (options.shouldFetch) {
6018
+ return response;
6019
+ } else if (options.shouldBackgroundFetch) {
6020
+ store.notifications._flush();
6021
+ }
5845
6022
  }
5846
- function isMutation(request) {
5847
- return Boolean(request.op && MUTATION_OPS.has(request.op));
6023
+ function updateCacheForError(store, context, options, error) {
6024
+ let response;
6025
+ if (isMutation(context.request)) {
6026
+ // TODO similar to didCommit we should spec this to be similar to cache.put for handling full response
6027
+ // currently we let the response remain undefiend.
6028
+ const errors = error && error.content && typeof error.content === 'object' && 'errors' in error.content && Array.isArray(error.content.errors) ? error.content.errors : undefined;
6029
+ const record = context.request.data?.record || context.request.records?.[0];
6030
+ store.cache.commitWasRejected(record, errors);
6031
+ } else {
6032
+ response = store.cache.put(error);
6033
+ return maybeUpdateErrorUiObjects(store, options, response, false);
6034
+ }
6035
+ }
6036
+ function handleFetchError(store, context, options, error) {
6037
+ store.requestManager._pending.delete(context.id);
6038
+ if (context.request.signal?.aborted) {
6039
+ throw error;
6040
+ }
6041
+ store._enableAsyncFlush = true;
6042
+ let response;
6043
+ store._join(() => {
6044
+ response = updateCacheForError(store, context, options, error);
6045
+ });
6046
+ store._enableAsyncFlush = null;
6047
+ if (options.identifier && store.lifetimes?.didRequest) {
6048
+ store.lifetimes.didRequest(context.request, error.response, options.identifier, store);
6049
+ }
6050
+ if (isMutation(context.request)) {
6051
+ throw error;
6052
+ }
6053
+ if (!options.shouldBackgroundFetch) {
6054
+ const newError = cloneError(error);
6055
+ newError.content = response;
6056
+ throw newError;
6057
+ } else {
6058
+ store.notifications._flush();
6059
+ }
5848
6060
  }
5849
6061
  function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBackgroundFetch) {
5850
6062
  const {
5851
6063
  store
5852
6064
  } = context.request;
5853
6065
  const shouldHydrate = context.request[EnableHydration] || false;
6066
+ const options = {
6067
+ shouldBackgroundFetch,
6068
+ shouldFetch,
6069
+ shouldHydrate,
6070
+ identifier
6071
+ };
5854
6072
  let isMut = false;
5855
6073
  if (isMutation(context.request)) {
5856
6074
  isMut = true;
@@ -5869,78 +6087,9 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
5869
6087
  store.lifetimes.willRequest(context.request, identifier, store);
5870
6088
  }
5871
6089
  const promise = next(context.request).then(document => {
5872
- store.requestManager._pending.delete(context.id);
5873
- store._enableAsyncFlush = true;
5874
- let response;
5875
- store._join(() => {
5876
- if (isMutation(context.request)) {
5877
- const record = context.request.data?.record || context.request.records?.[0];
5878
- if (record) {
5879
- response = store.cache.didCommit(record, document);
5880
-
5881
- // a mutation combined with a 204 has no cache impact when no known records were involved
5882
- // a createRecord with a 201 with an empty response and no known records should similarly
5883
- // have no cache impact
5884
- } else if (isCacheAffecting(document)) {
5885
- response = store.cache.put(document);
5886
- }
5887
- } else {
5888
- response = store.cache.put(document);
5889
- }
5890
- response = maybeUpdateUiObjects(store, context.request, {
5891
- shouldHydrate,
5892
- shouldFetch,
5893
- shouldBackgroundFetch,
5894
- identifier
5895
- }, response, false);
5896
- });
5897
- store._enableAsyncFlush = null;
5898
- if (store.lifetimes?.didRequest) {
5899
- store.lifetimes.didRequest(context.request, document.response, identifier, store);
5900
- }
5901
- if (shouldFetch) {
5902
- return response;
5903
- } else if (shouldBackgroundFetch) {
5904
- store.notifications._flush();
5905
- }
6090
+ return handleFetchSuccess(store, context, options, document);
5906
6091
  }, error => {
5907
- store.requestManager._pending.delete(context.id);
5908
- if (context.request.signal?.aborted) {
5909
- throw error;
5910
- }
5911
- store.requestManager._pending.delete(context.id);
5912
- store._enableAsyncFlush = true;
5913
- let response;
5914
- store._join(() => {
5915
- if (isMutation(context.request)) {
5916
- // TODO similar to didCommit we should spec this to be similar to cache.put for handling full response
5917
- // currently we let the response remain undefiend.
5918
- const errors = error && error.content && typeof error.content === 'object' && 'errors' in error.content && Array.isArray(error.content.errors) ? error.content.errors : undefined;
5919
- const record = context.request.data?.record || context.request.records?.[0];
5920
- store.cache.commitWasRejected(record, errors);
5921
- // re-throw the original error to preserve `errors` property.
5922
- throw error;
5923
- } else {
5924
- response = store.cache.put(error);
5925
- response = maybeUpdateUiObjects(store, context.request, {
5926
- shouldHydrate,
5927
- shouldFetch,
5928
- shouldBackgroundFetch,
5929
- identifier
5930
- }, response, false);
5931
- }
5932
- });
5933
- store._enableAsyncFlush = null;
5934
- if (identifier && store.lifetimes?.didRequest) {
5935
- store.lifetimes.didRequest(context.request, error.response, identifier, store);
5936
- }
5937
- if (!shouldBackgroundFetch) {
5938
- const newError = cloneError(error);
5939
- newError.content = response;
5940
- throw newError;
5941
- } else {
5942
- store.notifications._flush();
5943
- }
6092
+ return handleFetchError(store, context, options, error);
5944
6093
  });
5945
6094
  if (!isMut) {
5946
6095
  return promise;
@@ -5962,129 +6111,4 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
5962
6111
  }]
5963
6112
  });
5964
6113
  }
5965
- function isAggregateError(error) {
5966
- return error instanceof AggregateError || error.name === 'AggregateError' && Array.isArray(error.errors);
5967
- }
5968
- // TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
5969
- function cloneError(error) {
5970
- const isAggregate = isAggregateError(error);
5971
- const cloned = isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message);
5972
- cloned.stack = error.stack;
5973
- cloned.error = error.error;
5974
-
5975
- // copy over enumerable properties
5976
- Object.assign(cloned, error);
5977
- return cloned;
5978
- }
5979
-
5980
- /**
5981
- * A CacheHandler that adds support for using an EmberData Cache with a RequestManager.
5982
- *
5983
- * This handler will only run when a request has supplied a `store` instance. Requests
5984
- * issued by the store via `store.request()` will automatically have the `store` instance
5985
- * attached to the request.
5986
- *
5987
- * ```ts
5988
- * requestManager.request({
5989
- * store: store,
5990
- * url: '/api/posts',
5991
- * method: 'GET'
5992
- * });
5993
- * ```
5994
- *
5995
- * When this handler elects to handle a request, it will return the raw `StructuredDocument`
5996
- * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
5997
- * return a `Document` instance that will automatically update the UI when the cache is updated
5998
- * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
5999
- *
6000
- * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
6001
- * means that if desired you can issue requests that utilize the cache without needing to also
6002
- * utilize Record instances if desired.
6003
- *
6004
- * Said differently, you could elect to issue all requests via a RequestManager, without ever using
6005
- * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
6006
- * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
6007
- * approach of EmberData allows for this flexibility.
6008
- *
6009
- * ```ts
6010
- * import { EnableHydration } from '@warp-drive/core-types/request';
6011
- *
6012
- * requestManager.request({
6013
- * store: store,
6014
- * url: '/api/posts',
6015
- * method: 'GET',
6016
- * [EnableHydration]: true
6017
- * });
6018
- *
6019
- * @typedoc
6020
- */
6021
- const CacheHandler = {
6022
- request(context, next) {
6023
- // if we have no cache or no cache-key skip cache handling
6024
- if (!context.request.store || context.request.cacheOptions?.[SkipCache]) {
6025
- return next(context.request);
6026
- }
6027
- const {
6028
- store
6029
- } = context.request;
6030
- const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);
6031
- const peeked = identifier ? store.cache.peekRequest(identifier) : null;
6032
-
6033
- // determine if we should skip cache
6034
- if (calcShouldFetch(store, context.request, !!peeked, identifier)) {
6035
- return fetchContentAndHydrate(next, context, identifier, true, false);
6036
- }
6037
-
6038
- // if we have not skipped cache, determine if we should update behind the scenes
6039
- if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {
6040
- const promise = fetchContentAndHydrate(next, context, identifier, false, true);
6041
- store.requestManager._pending.set(context.id, promise);
6042
- }
6043
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
6044
- if (!test) {
6045
- throw new Error(`Expected a peeked request to be present`);
6046
- }
6047
- })(peeked) : {};
6048
- const shouldHydrate = context.request[EnableHydration] || false;
6049
- context.setResponse(peeked.response);
6050
- if ('error' in peeked) {
6051
- const content = shouldHydrate ? maybeUpdateUiObjects(store, context.request, {
6052
- shouldHydrate,
6053
- identifier
6054
- }, peeked.content, true) : peeked.content;
6055
- const newError = cloneError(peeked);
6056
- newError.content = content;
6057
- throw newError;
6058
- }
6059
- const result = shouldHydrate ? maybeUpdateUiObjects(store, context.request, {
6060
- shouldHydrate,
6061
- identifier
6062
- }, peeked.content, true) : peeked.content;
6063
- return result;
6064
- }
6065
- };
6066
- function copyDocumentProperties(target, source) {
6067
- if ('links' in source) {
6068
- target.links = source.links;
6069
- }
6070
- if ('meta' in source) {
6071
- target.meta = source.meta;
6072
- }
6073
- if ('errors' in source) {
6074
- target.errors = source.errors;
6075
- }
6076
- }
6077
- function isCacheAffecting(document) {
6078
- if (!isMutation(document.request)) {
6079
- return true;
6080
- }
6081
- // a mutation combined with a 204 has no cache impact when no known records were involved
6082
- // a createRecord with a 201 with an empty response and no known records should similarly
6083
- // have no cache impact
6084
-
6085
- if (document.request.op === 'createRecord' && document.response?.status === 201) {
6086
- return document.content ? Object.keys(document.content).length > 0 : false;
6087
- }
6088
- return document.response?.status !== 204;
6089
- }
6090
6114
  export { ARRAY_SIGNAL as A, CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, constructResource as f, coerceId as g, ensureStringId as h, isStableIdentifier as i, Collection as j, SOURCE as k, fastPush as l, removeRecordDataFor as m, notifyArray as n, setRecordIdentifier as o, peekCache as p, StoreMap as q, recordIdentifierFor as r, storeFor as s, setCacheFor as t, normalizeModelName as u };