@ember-data/store 5.4.0-alpha.49 → 5.4.0-alpha.50
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 +1 -1
- package/addon/{cache-handler-B6QvsAXr.js → cache-handler-BGVZPfAA.js} +72 -3
- package/addon/{cache-handler-B6QvsAXr.js.map → cache-handler-BGVZPfAA.js.map} +1 -1
- package/addon/index.js +1 -1
- package/package.json +9 -9
- package/unstable-preview-types/-private/cache-handler.d.ts +41 -0
- package/unstable-preview-types/-private/cache-handler.d.ts.map +1 -1
package/addon/-private.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as ARRAY_SIGNAL, f as AdapterPopulatedRecordArray, C as CacheHandler, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, l as StoreMap, _ as _clearCaches, o as _deprecatingNormalize, e as coerceId, h as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, j as removeRecordDataFor, m as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, k as setRecordIdentifier, s as storeFor } from "./cache-handler-
|
|
1
|
+
export { A as ARRAY_SIGNAL, f as AdapterPopulatedRecordArray, C as CacheHandler, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, g as SOURCE, S as Store, l as StoreMap, _ as _clearCaches, o as _deprecatingNormalize, e as coerceId, h as fastPush, i as isStableIdentifier, n as notifyArray, p as peekCache, r as recordIdentifierFor, j as removeRecordDataFor, m as setCacheFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, k as setRecordIdentifier, s as storeFor } from "./cache-handler-BGVZPfAA";
|
|
@@ -5391,6 +5391,10 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
5391
5391
|
const {
|
|
5392
5392
|
identifier
|
|
5393
5393
|
} = options;
|
|
5394
|
+
if (!document) {
|
|
5395
|
+
assert(`The CacheHandler expected response content but none was found`, !options.shouldHydrate);
|
|
5396
|
+
return document;
|
|
5397
|
+
}
|
|
5394
5398
|
if (isErrorDocument(document)) {
|
|
5395
5399
|
if (!identifier && !options.shouldHydrate) {
|
|
5396
5400
|
return document;
|
|
@@ -5503,8 +5507,10 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
|
|
|
5503
5507
|
isMut = true;
|
|
5504
5508
|
// TODO should we handle multiple records in request.records by iteratively calling willCommit for each
|
|
5505
5509
|
const record = context.request.data?.record || context.request.records?.[0];
|
|
5506
|
-
assert(`Expected to receive a list of records included in the ${context.request.op} request`, record);
|
|
5507
|
-
|
|
5510
|
+
assert(`Expected to receive a list of records included in the ${context.request.op} request`, record || !shouldHydrate);
|
|
5511
|
+
if (record) {
|
|
5512
|
+
store.cache.willCommit(record, context);
|
|
5513
|
+
}
|
|
5508
5514
|
}
|
|
5509
5515
|
if (store.lifetimes?.willRequest) {
|
|
5510
5516
|
store.lifetimes.willRequest(context.request, identifier, store);
|
|
@@ -5516,7 +5522,15 @@ function fetchContentAndHydrate(next, context, identifier, shouldFetch, shouldBa
|
|
|
5516
5522
|
store._join(() => {
|
|
5517
5523
|
if (isMutation(context.request)) {
|
|
5518
5524
|
const record = context.request.data?.record || context.request.records?.[0];
|
|
5519
|
-
|
|
5525
|
+
if (record) {
|
|
5526
|
+
response = store.cache.didCommit(record, document);
|
|
5527
|
+
|
|
5528
|
+
// a mutation combined with a 204 has no cache impact when no known records were involved
|
|
5529
|
+
// a createRecord with a 201 with an empty response and no known records should similarly
|
|
5530
|
+
// have no cache impact
|
|
5531
|
+
} else if (isCacheAffecting(document)) {
|
|
5532
|
+
response = store.cache.put(document);
|
|
5533
|
+
}
|
|
5520
5534
|
} else {
|
|
5521
5535
|
response = store.cache.put(document);
|
|
5522
5536
|
}
|
|
@@ -5597,6 +5611,48 @@ function cloneError(error) {
|
|
|
5597
5611
|
cloned.error = error.error;
|
|
5598
5612
|
return cloned;
|
|
5599
5613
|
}
|
|
5614
|
+
|
|
5615
|
+
/**
|
|
5616
|
+
* A CacheHandler that adds support for using an EmberData Cache with a RequestManager.
|
|
5617
|
+
*
|
|
5618
|
+
* This handler will only run when a request has supplied a `store` instance. Requests
|
|
5619
|
+
* issued by the store via `store.request()` will automatically have the `store` instance
|
|
5620
|
+
* attached to the request.
|
|
5621
|
+
*
|
|
5622
|
+
* ```ts
|
|
5623
|
+
* requestManager.request({
|
|
5624
|
+
* store: store,
|
|
5625
|
+
* url: '/api/posts',
|
|
5626
|
+
* method: 'GET'
|
|
5627
|
+
* });
|
|
5628
|
+
* ```
|
|
5629
|
+
*
|
|
5630
|
+
* When this handler elects to handle a request, it will return the raw `StructuredDocument`
|
|
5631
|
+
* unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
|
|
5632
|
+
* return a `Document` instance that will automatically update the UI when the cache is updated
|
|
5633
|
+
* in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
|
|
5634
|
+
*
|
|
5635
|
+
* When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
|
|
5636
|
+
* means that if desired you can issue requests that utilize the cache without needing to also
|
|
5637
|
+
* utilize Record instances if desired.
|
|
5638
|
+
*
|
|
5639
|
+
* Said differently, you could elect to issue all requests via a RequestManager, without ever using
|
|
5640
|
+
* the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
|
|
5641
|
+
* necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
|
|
5642
|
+
* approach of EmberData allows for this flexibility.
|
|
5643
|
+
*
|
|
5644
|
+
* ```ts
|
|
5645
|
+
* import { EnableHydration } from '@warp-drive/core-types/request';
|
|
5646
|
+
*
|
|
5647
|
+
* requestManager.request({
|
|
5648
|
+
* store: store,
|
|
5649
|
+
* url: '/api/posts',
|
|
5650
|
+
* method: 'GET',
|
|
5651
|
+
* [EnableHydration]: true
|
|
5652
|
+
* });
|
|
5653
|
+
*
|
|
5654
|
+
* @typedoc
|
|
5655
|
+
*/
|
|
5600
5656
|
const CacheHandler = {
|
|
5601
5657
|
request(context, next) {
|
|
5602
5658
|
// if we have no cache or no cache-key skip cache handling
|
|
@@ -5647,4 +5703,17 @@ function copyDocumentProperties(target, source) {
|
|
|
5647
5703
|
target.errors = source.errors;
|
|
5648
5704
|
}
|
|
5649
5705
|
}
|
|
5706
|
+
function isCacheAffecting(document) {
|
|
5707
|
+
if (!isMutation(document.request)) {
|
|
5708
|
+
return true;
|
|
5709
|
+
}
|
|
5710
|
+
// a mutation combined with a 204 has no cache impact when no known records were involved
|
|
5711
|
+
// a createRecord with a 201 with an empty response and no known records should similarly
|
|
5712
|
+
// have no cache impact
|
|
5713
|
+
|
|
5714
|
+
if (document.request.op === 'createRecord' && document.response?.status === 201) {
|
|
5715
|
+
return document.content ? Object.keys(document.content).length > 0 : false;
|
|
5716
|
+
}
|
|
5717
|
+
return document.response?.status !== 204;
|
|
5718
|
+
}
|
|
5650
5719
|
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, coerceId as e, Collection as f, SOURCE as g, fastPush as h, isStableIdentifier as i, removeRecordDataFor as j, setRecordIdentifier as k, StoreMap as l, setCacheFor as m, notifyArray as n, normalizeModelName as o, peekCache as p, recordIdentifierFor as r, storeFor as s };
|