@ember-data/store 5.4.0-alpha.14 → 5.4.0-alpha.16
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-
|
|
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-aee9dd76";
|
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-
|
|
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-aee9dd76";
|
|
@@ -233,11 +233,12 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
233
233
|
return options.shouldHydrate ? doc : document;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
+
const MUTATION_OPS = new Set(['createRecord', 'updateRecord', 'deleteRecord']);
|
|
236
237
|
function calcShouldFetch(store, request, hasCachedValue, identifier) {
|
|
237
238
|
const {
|
|
238
239
|
cacheOptions
|
|
239
240
|
} = request;
|
|
240
|
-
return cacheOptions?.reload || !hasCachedValue || (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier) : false);
|
|
241
|
+
return request.op && MUTATION_OPS.has(request.op) || cacheOptions?.reload || !hasCachedValue || (store.lifetimes && identifier ? store.lifetimes.isHardExpired(identifier) : false);
|
|
241
242
|
}
|
|
242
243
|
function calcShouldBackgroundFetch(store, request, willFetch, identifier) {
|
|
243
244
|
const {
|
|
@@ -245,17 +246,31 @@ function calcShouldBackgroundFetch(store, request, willFetch, identifier) {
|
|
|
245
246
|
} = request;
|
|
246
247
|
return !willFetch && (cacheOptions?.backgroundReload || (store.lifetimes && identifier ? store.lifetimes.isSoftExpired(identifier) : false));
|
|
247
248
|
}
|
|
249
|
+
function isMutation(request) {
|
|
250
|
+
return Boolean(request.op && MUTATION_OPS.has(request.op));
|
|
251
|
+
}
|
|
248
252
|
function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBackgroundFetch) {
|
|
249
253
|
const {
|
|
250
254
|
store
|
|
251
255
|
} = context.request;
|
|
252
256
|
const shouldHydrate = context.request[Symbol.for('ember-data:enable-hydration')] || false;
|
|
253
|
-
|
|
257
|
+
let isMut = false;
|
|
258
|
+
if (isMutation(context.request)) {
|
|
259
|
+
isMut = true;
|
|
260
|
+
const record = context.request.data?.record;
|
|
261
|
+
assert(`Expected to receive a list of records included in the ${context.request.op} request`, record);
|
|
262
|
+
store.cache.willCommit(record, context);
|
|
263
|
+
}
|
|
264
|
+
const promise = next(context.request).then(document => {
|
|
254
265
|
store.requestManager._pending.delete(context.id);
|
|
255
266
|
store._enableAsyncFlush = true;
|
|
256
267
|
let response;
|
|
257
268
|
store._join(() => {
|
|
258
|
-
|
|
269
|
+
if (isMutation(context.request)) {
|
|
270
|
+
response = store.cache.didCommit(context.request.data.record, document);
|
|
271
|
+
} else {
|
|
272
|
+
response = store.cache.put(document);
|
|
273
|
+
}
|
|
259
274
|
response = maybeUpdateUiObjects(store, context.request, {
|
|
260
275
|
shouldHydrate,
|
|
261
276
|
shouldFetch,
|
|
@@ -278,13 +293,22 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
|
|
|
278
293
|
store._enableAsyncFlush = true;
|
|
279
294
|
let response;
|
|
280
295
|
store._join(() => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
296
|
+
if (isMutation(context.request)) {
|
|
297
|
+
// TODO similar to didCommit we should spec this to be similar to cache.put for handling full response
|
|
298
|
+
// currently we let the response remain undefiend.
|
|
299
|
+
const errors = error && error.content && typeof error.content === 'object' && 'errors' in error.content && Array.isArray(error.content.errors) ? error.content.errors : undefined;
|
|
300
|
+
store.cache.commitWasRejected(context.request.data.record, errors);
|
|
301
|
+
// re-throw the original error to preserve `errors` property.
|
|
302
|
+
throw error;
|
|
303
|
+
} else {
|
|
304
|
+
response = store.cache.put(error);
|
|
305
|
+
response = maybeUpdateUiObjects(store, context.request, {
|
|
306
|
+
shouldHydrate,
|
|
307
|
+
shouldFetch,
|
|
308
|
+
shouldBackgroundFetch,
|
|
309
|
+
identifier
|
|
310
|
+
}, response, false);
|
|
311
|
+
}
|
|
288
312
|
});
|
|
289
313
|
store._enableAsyncFlush = null;
|
|
290
314
|
if (!shouldBackgroundFetch) {
|
|
@@ -295,6 +319,19 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
|
|
|
295
319
|
store.notifications._flush();
|
|
296
320
|
}
|
|
297
321
|
});
|
|
322
|
+
if (!isMut) {
|
|
323
|
+
return promise;
|
|
324
|
+
}
|
|
325
|
+
assert(`Expected a mutation`, isMutation(context.request));
|
|
326
|
+
|
|
327
|
+
// for mutations we need to enqueue the promise with the requestStateService
|
|
328
|
+
return store._requestCache._enqueue(promise, {
|
|
329
|
+
data: [{
|
|
330
|
+
op: 'saveRecord',
|
|
331
|
+
recordIdentifier: context.request.data.record,
|
|
332
|
+
options: undefined
|
|
333
|
+
}]
|
|
334
|
+
});
|
|
298
335
|
}
|
|
299
336
|
function cloneError(error) {
|
|
300
337
|
const cloned = new Error(error.message);
|