@ember-data/store 5.4.0-alpha.94 → 5.4.0-alpha.98
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 +1 -1
- package/dist/{handler-DEXNABd3.js → handler-Dj0xi5y4.js} +68 -13
- package/dist/handler-Dj0xi5y4.js.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +11 -11
- package/unstable-preview-types/-private/cache-handler/handler.d.ts.map +1 -1
- package/unstable-preview-types/-private/cache-handler/types.d.ts +22 -0
- package/unstable-preview-types/-private/cache-handler/types.d.ts.map +1 -1
- package/unstable-preview-types/-private/cache-handler/utils.d.ts +9 -0
- package/unstable-preview-types/-private/cache-handler/utils.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/notification-manager.d.ts +4 -2
- package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +25 -25
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/dist/handler-DEXNABd3.js.map +0 -1
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 "./handler-
|
|
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-Dj0xi5y4.js";
|
|
@@ -2158,7 +2158,7 @@ class CacheManager {
|
|
|
2158
2158
|
*/
|
|
2159
2159
|
// eslint-disable-next-line no-restricted-imports
|
|
2160
2160
|
let tokenId = 0;
|
|
2161
|
-
const CacheOperations = new Set(['added', 'removed', 'state', 'updated']);
|
|
2161
|
+
const CacheOperations = new Set(['added', 'removed', 'state', 'updated', 'invalidated']);
|
|
2162
2162
|
function isCacheOperationValue(value) {
|
|
2163
2163
|
return CacheOperations.has(value);
|
|
2164
2164
|
}
|
|
@@ -2318,14 +2318,15 @@ class NotificationManager {
|
|
|
2318
2318
|
this._flush();
|
|
2319
2319
|
}
|
|
2320
2320
|
_flush() {
|
|
2321
|
-
|
|
2322
|
-
|
|
2321
|
+
const buffered = this._buffered;
|
|
2322
|
+
if (buffered.size) {
|
|
2323
|
+
this._buffered = new Map();
|
|
2324
|
+
buffered.forEach((states, identifier) => {
|
|
2323
2325
|
states.forEach(args => {
|
|
2324
2326
|
// @ts-expect-error
|
|
2325
2327
|
this._flushNotification(identifier, args[0], args[1]);
|
|
2326
2328
|
});
|
|
2327
2329
|
});
|
|
2328
|
-
this._buffered = new Map();
|
|
2329
2330
|
}
|
|
2330
2331
|
this._hasFlush = false;
|
|
2331
2332
|
this._onFlushCB?.();
|
|
@@ -5787,6 +5788,15 @@ function cloneError(error) {
|
|
|
5787
5788
|
function isErrorDocument(document) {
|
|
5788
5789
|
return 'errors' in document;
|
|
5789
5790
|
}
|
|
5791
|
+
function getPriority(identifier, deduped, priority) {
|
|
5792
|
+
if (identifier) {
|
|
5793
|
+
const existing = deduped.get(identifier);
|
|
5794
|
+
if (existing) {
|
|
5795
|
+
return existing.priority;
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
return priority;
|
|
5799
|
+
}
|
|
5790
5800
|
|
|
5791
5801
|
/**
|
|
5792
5802
|
* @module @ember-data/store
|
|
@@ -5843,16 +5853,60 @@ const CacheHandler = {
|
|
|
5843
5853
|
store
|
|
5844
5854
|
} = context.request;
|
|
5845
5855
|
const identifier = store.identifierCache.getOrCreateDocumentIdentifier(context.request);
|
|
5856
|
+
if (identifier) {
|
|
5857
|
+
context.setIdentifier(identifier);
|
|
5858
|
+
}
|
|
5859
|
+
|
|
5860
|
+
// used to dedupe existing requests that match
|
|
5861
|
+
const DEDUPE = store.requestManager._deduped;
|
|
5862
|
+
const activeRequest = identifier && DEDUPE.get(identifier);
|
|
5846
5863
|
const peeked = identifier ? store.cache.peekRequest(identifier) : null;
|
|
5847
5864
|
|
|
5848
5865
|
// determine if we should skip cache
|
|
5849
5866
|
if (calcShouldFetch(store, context.request, !!peeked, identifier)) {
|
|
5850
|
-
|
|
5867
|
+
if (activeRequest) {
|
|
5868
|
+
activeRequest.priority = {
|
|
5869
|
+
blocking: true
|
|
5870
|
+
};
|
|
5871
|
+
return activeRequest.promise;
|
|
5872
|
+
}
|
|
5873
|
+
let promise = fetchContentAndHydrate(next, context, identifier, {
|
|
5874
|
+
blocking: true
|
|
5875
|
+
});
|
|
5876
|
+
if (identifier) {
|
|
5877
|
+
promise = promise.finally(() => {
|
|
5878
|
+
DEDUPE.delete(identifier);
|
|
5879
|
+
store.notifications.notify(identifier, 'state');
|
|
5880
|
+
});
|
|
5881
|
+
DEDUPE.set(identifier, {
|
|
5882
|
+
priority: {
|
|
5883
|
+
blocking: true
|
|
5884
|
+
},
|
|
5885
|
+
promise
|
|
5886
|
+
});
|
|
5887
|
+
store.notifications.notify(identifier, 'state');
|
|
5888
|
+
}
|
|
5889
|
+
return promise;
|
|
5851
5890
|
}
|
|
5852
5891
|
|
|
5853
5892
|
// if we have not skipped cache, determine if we should update behind the scenes
|
|
5854
5893
|
if (calcShouldBackgroundFetch(store, context.request, false, identifier)) {
|
|
5855
|
-
|
|
5894
|
+
let promise = activeRequest?.promise || fetchContentAndHydrate(next, context, identifier, {
|
|
5895
|
+
blocking: false
|
|
5896
|
+
});
|
|
5897
|
+
if (identifier && !activeRequest) {
|
|
5898
|
+
promise = promise.finally(() => {
|
|
5899
|
+
DEDUPE.delete(identifier);
|
|
5900
|
+
store.notifications.notify(identifier, 'state');
|
|
5901
|
+
});
|
|
5902
|
+
DEDUPE.set(identifier, {
|
|
5903
|
+
priority: {
|
|
5904
|
+
blocking: false
|
|
5905
|
+
},
|
|
5906
|
+
promise
|
|
5907
|
+
});
|
|
5908
|
+
store.notifications.notify(identifier, 'state');
|
|
5909
|
+
}
|
|
5856
5910
|
store.requestManager._pending.set(context.id, promise);
|
|
5857
5911
|
}
|
|
5858
5912
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -6014,9 +6068,10 @@ function handleFetchSuccess(store, context, options, document) {
|
|
|
6014
6068
|
if (store.lifetimes?.didRequest) {
|
|
6015
6069
|
store.lifetimes.didRequest(context.request, document.response, options.identifier, store);
|
|
6016
6070
|
}
|
|
6017
|
-
|
|
6071
|
+
const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);
|
|
6072
|
+
if (finalPriority.blocking) {
|
|
6018
6073
|
return response;
|
|
6019
|
-
} else
|
|
6074
|
+
} else {
|
|
6020
6075
|
store.notifications._flush();
|
|
6021
6076
|
}
|
|
6022
6077
|
}
|
|
@@ -6050,7 +6105,8 @@ function handleFetchError(store, context, options, error) {
|
|
|
6050
6105
|
if (isMutation(context.request)) {
|
|
6051
6106
|
throw error;
|
|
6052
6107
|
}
|
|
6053
|
-
|
|
6108
|
+
const finalPriority = getPriority(options.identifier, store.requestManager._deduped, options.priority);
|
|
6109
|
+
if (finalPriority.blocking) {
|
|
6054
6110
|
const newError = cloneError(error);
|
|
6055
6111
|
newError.content = response;
|
|
6056
6112
|
throw newError;
|
|
@@ -6058,16 +6114,15 @@ function handleFetchError(store, context, options, error) {
|
|
|
6058
6114
|
store.notifications._flush();
|
|
6059
6115
|
}
|
|
6060
6116
|
}
|
|
6061
|
-
function fetchContentAndHydrate(next, context, identifier,
|
|
6117
|
+
function fetchContentAndHydrate(next, context, identifier, priority) {
|
|
6062
6118
|
const {
|
|
6063
6119
|
store
|
|
6064
6120
|
} = context.request;
|
|
6065
6121
|
const shouldHydrate = context.request[EnableHydration] || false;
|
|
6066
6122
|
const options = {
|
|
6067
|
-
shouldBackgroundFetch,
|
|
6068
|
-
shouldFetch,
|
|
6069
6123
|
shouldHydrate,
|
|
6070
|
-
identifier
|
|
6124
|
+
identifier,
|
|
6125
|
+
priority
|
|
6071
6126
|
};
|
|
6072
6127
|
let isMut = false;
|
|
6073
6128
|
if (isMutation(context.request)) {
|