@warp-drive/core 5.6.0-alpha.11
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/CHANGELOG.md +1 -0
- package/LICENSE.md +23 -0
- package/README.md +70 -0
- package/addon-main.cjs +5 -0
- package/cjs-dist/addon-shim.cjs +1 -0
- package/cjs-dist/cjs-set-config.cjs +1 -0
- package/declarations/build-config/babel-macros.d.ts +2 -0
- package/declarations/build-config/babel-macros.d.ts.map +1 -0
- package/declarations/build-config/canary-features.d.ts +2 -0
- package/declarations/build-config/canary-features.d.ts.map +1 -0
- package/declarations/build-config/debugging.d.ts +2 -0
- package/declarations/build-config/debugging.d.ts.map +1 -0
- package/declarations/build-config/deprecations.d.ts +2 -0
- package/declarations/build-config/deprecations.d.ts.map +1 -0
- package/declarations/build-config/env.d.ts +2 -0
- package/declarations/build-config/env.d.ts.map +1 -0
- package/declarations/build-config/macros.d.ts +2 -0
- package/declarations/build-config/macros.d.ts.map +1 -0
- package/declarations/build-config.d.ts +2 -0
- package/declarations/build-config.d.ts.map +1 -0
- package/declarations/configure.d.ts +8 -0
- package/declarations/configure.d.ts.map +1 -0
- package/declarations/graph/-private/-diff.d.ts +33 -0
- package/declarations/graph/-private/-diff.d.ts.map +1 -0
- package/declarations/graph/-private/-edge-definition.d.ts +149 -0
- package/declarations/graph/-private/-edge-definition.d.ts.map +1 -0
- package/declarations/graph/-private/-state.d.ts +10 -0
- package/declarations/graph/-private/-state.d.ts.map +1 -0
- package/declarations/graph/-private/-utils.d.ts +26 -0
- package/declarations/graph/-private/-utils.d.ts.map +1 -0
- package/declarations/graph/-private/coerce-id.d.ts +5 -0
- package/declarations/graph/-private/coerce-id.d.ts.map +1 -0
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +7 -0
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
- package/declarations/graph/-private/edges/collection.d.ts +40 -0
- package/declarations/graph/-private/edges/collection.d.ts.map +1 -0
- package/declarations/graph/-private/edges/implicit.d.ts +14 -0
- package/declarations/graph/-private/edges/implicit.d.ts.map +1 -0
- package/declarations/graph/-private/edges/resource.d.ts +25 -0
- package/declarations/graph/-private/edges/resource.d.ts.map +1 -0
- package/declarations/graph/-private/graph.d.ts +55 -0
- package/declarations/graph/-private/graph.d.ts.map +1 -0
- package/declarations/graph/-private/normalize-link.d.ts +3 -0
- package/declarations/graph/-private/normalize-link.d.ts.map +1 -0
- package/declarations/graph/-private/operations/add-to-related-records.d.ts +5 -0
- package/declarations/graph/-private/operations/add-to-related-records.d.ts.map +1 -0
- package/declarations/graph/-private/operations/merge-identifier.d.ts +4 -0
- package/declarations/graph/-private/operations/merge-identifier.d.ts.map +1 -0
- package/declarations/graph/-private/operations/remove-from-related-records.d.ts +5 -0
- package/declarations/graph/-private/operations/remove-from-related-records.d.ts.map +1 -0
- package/declarations/graph/-private/operations/replace-related-record.d.ts +4 -0
- package/declarations/graph/-private/operations/replace-related-record.d.ts.map +1 -0
- package/declarations/graph/-private/operations/replace-related-records.d.ts +8 -0
- package/declarations/graph/-private/operations/replace-related-records.d.ts.map +1 -0
- package/declarations/graph/-private/operations/update-relationship.d.ts +11 -0
- package/declarations/graph/-private/operations/update-relationship.d.ts.map +1 -0
- package/declarations/graph/-private.d.ts +14 -0
- package/declarations/graph/-private.d.ts.map +1 -0
- package/declarations/index.d.ts +15 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/reactive/-private/document.d.ts +147 -0
- package/declarations/reactive/-private/document.d.ts.map +1 -0
- package/declarations/reactive/-private/fields/compute.d.ts +40 -0
- package/declarations/reactive/-private/fields/compute.d.ts.map +1 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +23 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts.map +1 -0
- package/declarations/reactive/-private/fields/managed-object.d.ts +21 -0
- package/declarations/reactive/-private/fields/managed-object.d.ts.map +1 -0
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +20 -0
- package/declarations/reactive/-private/fields/many-array-manager.d.ts.map +1 -0
- package/declarations/reactive/-private/hooks.d.ts +6 -0
- package/declarations/reactive/-private/hooks.d.ts.map +1 -0
- package/declarations/reactive/-private/record.d.ts +61 -0
- package/declarations/reactive/-private/record.d.ts.map +1 -0
- package/declarations/reactive/-private/schema.d.ts +180 -0
- package/declarations/reactive/-private/schema.d.ts.map +1 -0
- package/declarations/reactive/-private/symbols.d.ts +11 -0
- package/declarations/reactive/-private/symbols.d.ts.map +1 -0
- package/declarations/reactive/-private.d.ts +2 -0
- package/declarations/reactive/-private.d.ts.map +1 -0
- package/declarations/reactive.d.ts +5 -0
- package/declarations/reactive.d.ts.map +1 -0
- package/declarations/request/-private/context.d.ts +42 -0
- package/declarations/request/-private/context.d.ts.map +1 -0
- package/declarations/request/-private/debug.d.ts +5 -0
- package/declarations/request/-private/debug.d.ts.map +1 -0
- package/declarations/request/-private/fetch.d.ts +40 -0
- package/declarations/request/-private/fetch.d.ts.map +1 -0
- package/declarations/request/-private/future.d.ts +8 -0
- package/declarations/request/-private/future.d.ts.map +1 -0
- package/declarations/request/-private/manager.d.ts +160 -0
- package/declarations/request/-private/manager.d.ts.map +1 -0
- package/declarations/request/-private/promise-cache.d.ts +20 -0
- package/declarations/request/-private/promise-cache.d.ts.map +1 -0
- package/declarations/request/-private/types.d.ts +236 -0
- package/declarations/request/-private/types.d.ts.map +1 -0
- package/declarations/request/-private/utils.d.ts +16 -0
- package/declarations/request/-private/utils.d.ts.map +1 -0
- package/declarations/request.d.ts +6 -0
- package/declarations/request.d.ts.map +1 -0
- package/declarations/store/-private/cache-handler/handler.d.ts +57 -0
- package/declarations/store/-private/cache-handler/handler.d.ts.map +1 -0
- package/declarations/store/-private/cache-handler/types.d.ts +99 -0
- package/declarations/store/-private/cache-handler/types.d.ts.map +1 -0
- package/declarations/store/-private/cache-handler/utils.d.ts +32 -0
- package/declarations/store/-private/cache-handler/utils.d.ts.map +1 -0
- package/declarations/store/-private/caches/cache-utils.d.ts +9 -0
- package/declarations/store/-private/caches/cache-utils.d.ts.map +1 -0
- package/declarations/store/-private/caches/identifier-cache.d.ts +316 -0
- package/declarations/store/-private/caches/identifier-cache.d.ts.map +1 -0
- package/declarations/store/-private/caches/instance-cache.d.ts +65 -0
- package/declarations/store/-private/caches/instance-cache.d.ts.map +1 -0
- package/declarations/store/-private/caches/resource-utils.d.ts +10 -0
- package/declarations/store/-private/caches/resource-utils.d.ts.map +1 -0
- package/declarations/store/-private/debug/utils.d.ts +7 -0
- package/declarations/store/-private/debug/utils.d.ts.map +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +383 -0
- package/declarations/store/-private/default-cache-policy.d.ts.map +1 -0
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts +164 -0
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts.map +1 -0
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +17 -0
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts.map +1 -0
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +26 -0
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts.map +1 -0
- package/declarations/store/-private/managers/cache-manager.d.ts +428 -0
- package/declarations/store/-private/managers/cache-manager.d.ts.map +1 -0
- package/declarations/store/-private/managers/notification-manager.d.ts +93 -0
- package/declarations/store/-private/managers/notification-manager.d.ts.map +1 -0
- package/declarations/store/-private/managers/record-array-manager.d.ts +98 -0
- package/declarations/store/-private/managers/record-array-manager.d.ts.map +1 -0
- package/declarations/store/-private/network/request-cache.d.ts +104 -0
- package/declarations/store/-private/network/request-cache.d.ts.map +1 -0
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts +255 -0
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts.map +1 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +93 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts.map +1 -0
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +170 -0
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts.map +1 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +30 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts.map +1 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +255 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts.map +1 -0
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +141 -0
- package/declarations/store/-private/record-arrays/identifier-array.d.ts.map +1 -0
- package/declarations/store/-private/record-arrays/many-array.d.ts +199 -0
- package/declarations/store/-private/record-arrays/many-array.d.ts.map +1 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +116 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts.map +1 -0
- package/declarations/store/-private/store-service.d.ts +1597 -0
- package/declarations/store/-private/store-service.d.ts.map +1 -0
- package/declarations/store/-private/store-service.type-test.d.ts +2 -0
- package/declarations/store/-private/store-service.type-test.d.ts.map +1 -0
- package/declarations/store/-private/utils/coerce-id.d.ts +5 -0
- package/declarations/store/-private/utils/coerce-id.d.ts.map +1 -0
- package/declarations/store/-private/utils/construct-resource.d.ts +7 -0
- package/declarations/store/-private/utils/construct-resource.d.ts.map +1 -0
- package/declarations/store/-private/utils/is-non-empty-string.d.ts +2 -0
- package/declarations/store/-private/utils/is-non-empty-string.d.ts.map +1 -0
- package/declarations/store/-private/utils/normalize-model-name.d.ts +2 -0
- package/declarations/store/-private/utils/normalize-model-name.d.ts.map +1 -0
- package/declarations/store/-private/utils/uuid-polyfill.d.ts +2 -0
- package/declarations/store/-private/utils/uuid-polyfill.d.ts.map +1 -0
- package/declarations/store/-private.d.ts +27 -0
- package/declarations/store/-private.d.ts.map +1 -0
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +100 -0
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts.map +1 -0
- package/declarations/store/-types/q/ds-model.d.ts +22 -0
- package/declarations/store/-types/q/ds-model.d.ts.map +1 -0
- package/declarations/store/-types/q/identifier.d.ts +21 -0
- package/declarations/store/-types/q/identifier.d.ts.map +1 -0
- package/declarations/store/-types/q/promise-proxies.d.ts +2 -0
- package/declarations/store/-types/q/promise-proxies.d.ts.map +1 -0
- package/declarations/store/-types/q/record-data-json-api.d.ts +31 -0
- package/declarations/store/-types/q/record-data-json-api.d.ts.map +1 -0
- package/declarations/store/-types/q/record-instance.d.ts +24 -0
- package/declarations/store/-types/q/record-instance.d.ts.map +1 -0
- package/declarations/store/-types/q/schema-service.d.ts +331 -0
- package/declarations/store/-types/q/schema-service.d.ts.map +1 -0
- package/declarations/store/-types/q/store.d.ts +35 -0
- package/declarations/store/-types/q/store.d.ts.map +1 -0
- package/declarations/store.d.ts +2 -0
- package/declarations/store.d.ts.map +1 -0
- package/declarations/types/-private.d.ts +14 -0
- package/declarations/types/-private.d.ts.map +1 -0
- package/declarations/types/cache/aliases.d.ts +2 -0
- package/declarations/types/cache/aliases.d.ts.map +1 -0
- package/declarations/types/cache/change.d.ts +7 -0
- package/declarations/types/cache/change.d.ts.map +1 -0
- package/declarations/types/cache/mutations.d.ts +39 -0
- package/declarations/types/cache/mutations.d.ts.map +1 -0
- package/declarations/types/cache/operations.d.ts +72 -0
- package/declarations/types/cache/operations.d.ts.map +1 -0
- package/declarations/types/cache/relationship.d.ts +14 -0
- package/declarations/types/cache/relationship.d.ts.map +1 -0
- package/declarations/types/cache.d.ts +492 -0
- package/declarations/types/cache.d.ts.map +1 -0
- package/declarations/types/graph.d.ts +48 -0
- package/declarations/types/graph.d.ts.map +1 -0
- package/declarations/types/identifier.d.ts +111 -0
- package/declarations/types/identifier.d.ts.map +1 -0
- package/declarations/types/json/raw.d.ts +7 -0
- package/declarations/types/json/raw.d.ts.map +1 -0
- package/declarations/types/params.d.ts +10 -0
- package/declarations/types/params.d.ts.map +1 -0
- package/declarations/types/record.d.ts +96 -0
- package/declarations/types/record.d.ts.map +1 -0
- package/declarations/types/record.type-test.d.ts +2 -0
- package/declarations/types/record.type-test.d.ts.map +1 -0
- package/declarations/types/request.d.ts +308 -0
- package/declarations/types/request.d.ts.map +1 -0
- package/declarations/types/request.type-test.d.ts +2 -0
- package/declarations/types/request.type-test.d.ts.map +1 -0
- package/declarations/types/runtime.d.ts +15 -0
- package/declarations/types/runtime.d.ts.map +1 -0
- package/declarations/types/schema/concepts.d.ts +17 -0
- package/declarations/types/schema/concepts.d.ts.map +1 -0
- package/declarations/types/schema/fields.d.ts +1674 -0
- package/declarations/types/schema/fields.d.ts.map +1 -0
- package/declarations/types/schema/fields.type-test.d.ts +2 -0
- package/declarations/types/schema/fields.type-test.d.ts.map +1 -0
- package/declarations/types/spec/document.d.ts +31 -0
- package/declarations/types/spec/document.d.ts.map +1 -0
- package/declarations/types/spec/error.d.ts +19 -0
- package/declarations/types/spec/error.d.ts.map +1 -0
- package/declarations/types/spec/json-api-raw.d.ts +142 -0
- package/declarations/types/spec/json-api-raw.d.ts.map +1 -0
- package/declarations/types/symbols.d.ts +79 -0
- package/declarations/types/symbols.d.ts.map +1 -0
- package/declarations/types/utils.d.ts +5 -0
- package/declarations/types/utils.d.ts.map +1 -0
- package/declarations/types.d.ts +12 -0
- package/declarations/types.d.ts.map +1 -0
- package/declarations/utils/string.d.ts +45 -0
- package/declarations/utils/string.d.ts.map +1 -0
- package/dist/build-config/babel-macros.js +1 -0
- package/dist/build-config/babel-macros.js.map +1 -0
- package/dist/build-config/canary-features.js +1 -0
- package/dist/build-config/canary-features.js.map +1 -0
- package/dist/build-config/debugging.js +1 -0
- package/dist/build-config/debugging.js.map +1 -0
- package/dist/build-config/deprecations.js +1 -0
- package/dist/build-config/deprecations.js.map +1 -0
- package/dist/build-config/env.js +1 -0
- package/dist/build-config/env.js.map +1 -0
- package/dist/build-config/macros.js +1 -0
- package/dist/build-config/macros.js.map +1 -0
- package/dist/build-config.js +1 -0
- package/dist/build-config.js.map +1 -0
- package/dist/configure-Bz49BEZQ.js +145 -0
- package/dist/configure-Bz49BEZQ.js.map +1 -0
- package/dist/configure.js +1 -0
- package/dist/configure.js.map +1 -0
- package/dist/context-DE5sFezZ.js +636 -0
- package/dist/context-DE5sFezZ.js.map +1 -0
- package/dist/graph/-private.js +3364 -0
- package/dist/graph/-private.js.map +1 -0
- package/dist/handler-DYUefHNU.js +339 -0
- package/dist/handler-DYUefHNU.js.map +1 -0
- package/dist/index.js +382 -0
- package/dist/index.js.map +1 -0
- package/dist/reactive/-private.js +1 -0
- package/dist/reactive/-private.js.map +1 -0
- package/dist/reactive.js +1802 -0
- package/dist/reactive.js.map +1 -0
- package/dist/request-state-Bv5CY_H0.js +7358 -0
- package/dist/request-state-Bv5CY_H0.js.map +1 -0
- package/dist/request.js +1 -0
- package/dist/request.js.map +1 -0
- package/dist/store/-private.js +3 -0
- package/dist/store/-private.js.map +1 -0
- package/dist/store.js +545 -0
- package/dist/store.js.map +1 -0
- package/dist/symbols-DyqeYQTe.js +44 -0
- package/dist/symbols-DyqeYQTe.js.map +1 -0
- package/dist/types/-private.js +79 -0
- package/dist/types/-private.js.map +1 -0
- package/dist/types/cache/aliases.js +0 -0
- package/dist/types/cache/aliases.js.map +1 -0
- package/dist/types/cache/change.js +0 -0
- package/dist/types/cache/change.js.map +1 -0
- package/dist/types/cache/mutations.js +0 -0
- package/dist/types/cache/mutations.js.map +1 -0
- package/dist/types/cache/operations.js +0 -0
- package/dist/types/cache/operations.js.map +1 -0
- package/dist/types/cache/relationship.js +0 -0
- package/dist/types/cache/relationship.js.map +1 -0
- package/dist/types/cache.js +0 -0
- package/dist/types/cache.js.map +1 -0
- package/dist/types/graph.js +0 -0
- package/dist/types/graph.js.map +1 -0
- package/dist/types/identifier.js +89 -0
- package/dist/types/identifier.js.map +1 -0
- package/dist/types/json/raw.js +0 -0
- package/dist/types/json/raw.js.map +1 -0
- package/dist/types/params.js +0 -0
- package/dist/types/params.js.map +1 -0
- package/dist/types/record.js +64 -0
- package/dist/types/record.js.map +1 -0
- package/dist/types/request.js +33 -0
- package/dist/types/request.js.map +1 -0
- package/dist/types/runtime.js +34 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/schema/concepts.js +0 -0
- package/dist/types/schema/concepts.js.map +1 -0
- package/dist/types/schema/fields.js +470 -0
- package/dist/types/schema/fields.js.map +1 -0
- package/dist/types/schema/fields.type-test.js +0 -0
- package/dist/types/schema/fields.type-test.js.map +1 -0
- package/dist/types/spec/document.js +0 -0
- package/dist/types/spec/document.js.map +1 -0
- package/dist/types/spec/error.js +0 -0
- package/dist/types/spec/error.js.map +1 -0
- package/dist/types/spec/json-api-raw.js +0 -0
- package/dist/types/spec/json-api-raw.js.map +1 -0
- package/dist/types/symbols.js +84 -0
- package/dist/types/symbols.js.map +1 -0
- package/dist/types/utils.js +0 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types.js +0 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/string.js +92 -0
- package/dist/utils/string.js.map +1 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +70 -0
package/dist/request.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./context-DE5sFezZ.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { C as CollectionRecordArray, I as LiveArray, M as MUTATE, R as RecordArrayManager, l as RelatedCollection, d as SOURCE, z as Signals, S as Store, j as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, b as coerceId, c as constructResource, E as consumeInternalSignal, y as defineNonEnumerableSignal, x as defineSignal, e as ensureStringId, w as entangleSignal, f as fastPush, v as gate, F as getOrCreateInternalSignal, q as getPromiseState, t as getRequestState, a as isDocumentIdentifier, i as isStableIdentifier, m as log, o as logGroup, u as memoized, D as notifyInternalSignal, p as peekCache, A as peekInternalSignal, r as recordIdentifierFor, g as removeRecordDataFor, k as setCacheFor, h as setRecordIdentifier, s as storeFor, B as withSignalStore } from "../request-state-Bv5CY_H0.js";
|
|
2
|
+
export { C as CacheHandler } from "../handler-DYUefHNU.js";
|
|
3
|
+
export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo, w as waitFor } from "../configure-Bz49BEZQ.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"-private.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { deprecate } from '@ember/debug';
|
|
2
|
+
import { LRUCache } from "./utils/string.js";
|
|
3
|
+
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
4
|
+
const NUMERIC_KEYS = new Set(['max-age', 's-maxage', 'stale-if-error', 'stale-while-revalidate']);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parses a string Cache-Control header value into an object with the following structure:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* interface CacheControlValue {
|
|
11
|
+
* immutable?: boolean;
|
|
12
|
+
* 'max-age'?: number;
|
|
13
|
+
* 'must-revalidate'?: boolean;
|
|
14
|
+
* 'must-understand'?: boolean;
|
|
15
|
+
* 'no-cache'?: boolean;
|
|
16
|
+
* 'no-store'?: boolean;
|
|
17
|
+
* 'no-transform'?: boolean;
|
|
18
|
+
* 'only-if-cached'?: boolean;
|
|
19
|
+
* private?: boolean;
|
|
20
|
+
* 'proxy-revalidate'?: boolean;
|
|
21
|
+
* public?: boolean;
|
|
22
|
+
* 's-maxage'?: number;
|
|
23
|
+
* 'stale-if-error'?: number;
|
|
24
|
+
* 'stale-while-revalidate'?: number;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @param {String} header
|
|
30
|
+
* @return {CacheControlValue}
|
|
31
|
+
*/
|
|
32
|
+
function parseCacheControl(header) {
|
|
33
|
+
return CACHE_CONTROL_CACHE.get(header);
|
|
34
|
+
}
|
|
35
|
+
const CACHE_CONTROL_CACHE = new LRUCache(header => {
|
|
36
|
+
let key = '';
|
|
37
|
+
let value = '';
|
|
38
|
+
let isParsingKey = true;
|
|
39
|
+
const cacheControlValue = {};
|
|
40
|
+
for (let i = 0; i < header.length; i++) {
|
|
41
|
+
const char = header.charAt(i);
|
|
42
|
+
if (char === ',') {
|
|
43
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
44
|
+
if (!test) {
|
|
45
|
+
throw new Error(`Invalid Cache-Control value, expected a value`);
|
|
46
|
+
}
|
|
47
|
+
})(!isParsingKey || !NUMERIC_KEYS.has(key)) : {};
|
|
48
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
49
|
+
if (!test) {
|
|
50
|
+
throw new Error(`Invalid Cache-Control value, expected a value after "=" but got ","`);
|
|
51
|
+
}
|
|
52
|
+
})(i === 0 || header.charAt(i - 1) !== '=') : {};
|
|
53
|
+
isParsingKey = true;
|
|
54
|
+
// @ts-expect-error TS incorrectly thinks that optional keys must have a type that includes undefined
|
|
55
|
+
cacheControlValue[key] = NUMERIC_KEYS.has(key) ? parseCacheControlValue(value) : true;
|
|
56
|
+
key = '';
|
|
57
|
+
value = '';
|
|
58
|
+
continue;
|
|
59
|
+
} else if (char === '=') {
|
|
60
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
61
|
+
if (!test) {
|
|
62
|
+
throw new Error(`Invalid Cache-Control value, expected a value after "="`);
|
|
63
|
+
}
|
|
64
|
+
})(i + 1 !== header.length) : {};
|
|
65
|
+
isParsingKey = false;
|
|
66
|
+
} else if (char === ' ' || char === `\t` || char === `\n`) {
|
|
67
|
+
continue;
|
|
68
|
+
} else if (isParsingKey) {
|
|
69
|
+
key += char;
|
|
70
|
+
} else {
|
|
71
|
+
value += char;
|
|
72
|
+
}
|
|
73
|
+
if (i === header.length - 1) {
|
|
74
|
+
// @ts-expect-error TS incorrectly thinks that optional keys must have a type that includes undefined
|
|
75
|
+
cacheControlValue[key] = NUMERIC_KEYS.has(key) ? parseCacheControlValue(value) : true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return cacheControlValue;
|
|
79
|
+
}, 200);
|
|
80
|
+
function parseCacheControlValue(stringToParse) {
|
|
81
|
+
const parsedValue = Number.parseInt(stringToParse);
|
|
82
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
83
|
+
if (!test) {
|
|
84
|
+
throw new Error(`Invalid Cache-Control value, expected a number but got - ${stringToParse}`);
|
|
85
|
+
}
|
|
86
|
+
})(!Number.isNaN(parsedValue)) : {};
|
|
87
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
88
|
+
if (!test) {
|
|
89
|
+
throw new Error(`Invalid Cache-Control value, expected a number greater than 0 but got - ${stringToParse}`);
|
|
90
|
+
}
|
|
91
|
+
})(parsedValue >= 0) : {};
|
|
92
|
+
if (Number.isNaN(parsedValue) || parsedValue < 0) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
return parsedValue;
|
|
96
|
+
}
|
|
97
|
+
function isExpired(identifier, request, config) {
|
|
98
|
+
const {
|
|
99
|
+
constraints
|
|
100
|
+
} = config;
|
|
101
|
+
if (constraints?.isExpired) {
|
|
102
|
+
const result = constraints.isExpired(request);
|
|
103
|
+
if (result !== null) {
|
|
104
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
105
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because constraints.isExpired returned ${result}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const {
|
|
114
|
+
headers
|
|
115
|
+
} = request.response;
|
|
116
|
+
if (!headers) {
|
|
117
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
118
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no headers were provided`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// if we have no headers then both the headers based expiration
|
|
125
|
+
// and the time based expiration will be considered expired
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// check for X-WarpDrive-Expires
|
|
130
|
+
const now = Date.now();
|
|
131
|
+
const date = headers.get('Date');
|
|
132
|
+
if (constraints?.headers) {
|
|
133
|
+
if (constraints.headers['X-WarpDrive-Expires']) {
|
|
134
|
+
const xWarpDriveExpires = headers.get('X-WarpDrive-Expires');
|
|
135
|
+
if (xWarpDriveExpires) {
|
|
136
|
+
const expirationTime = new Date(xWarpDriveExpires).getTime();
|
|
137
|
+
const result = now >= expirationTime;
|
|
138
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
139
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
140
|
+
// eslint-disable-next-line no-console
|
|
141
|
+
console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by X-WarpDrive-Expires header is ${result ? 'in the past' : 'in the future'}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// check for Cache-Control
|
|
149
|
+
if (constraints.headers['Cache-Control']) {
|
|
150
|
+
const cacheControl = headers.get('Cache-Control');
|
|
151
|
+
const age = headers.get('Age');
|
|
152
|
+
if (cacheControl && age && date) {
|
|
153
|
+
const cacheControlValue = parseCacheControl(cacheControl);
|
|
154
|
+
|
|
155
|
+
// max-age and s-maxage are stored in
|
|
156
|
+
const maxAge = cacheControlValue['max-age'] || cacheControlValue['s-maxage'];
|
|
157
|
+
if (maxAge) {
|
|
158
|
+
// age is stored in seconds
|
|
159
|
+
const ageValue = parseInt(age, 10);
|
|
160
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
161
|
+
if (!test) {
|
|
162
|
+
throw new Error(`Invalid Cache-Control value, expected a number but got - ${age}`);
|
|
163
|
+
}
|
|
164
|
+
})(!Number.isNaN(ageValue)) : {};
|
|
165
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
166
|
+
if (!test) {
|
|
167
|
+
throw new Error(`Invalid Cache-Control value, expected a number greater than 0 but got - ${age}`);
|
|
168
|
+
}
|
|
169
|
+
})(ageValue >= 0) : {};
|
|
170
|
+
if (!Number.isNaN(ageValue) && ageValue >= 0) {
|
|
171
|
+
const dateValue = new Date(date).getTime();
|
|
172
|
+
const expirationTime = dateValue + (maxAge - ageValue) * 1000;
|
|
173
|
+
const result = now >= expirationTime;
|
|
174
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
175
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
176
|
+
// eslint-disable-next-line no-console
|
|
177
|
+
console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by Cache-Control header is ${result ? 'in the past' : 'in the future'}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// check for Expires
|
|
187
|
+
if (constraints.headers.Expires) {
|
|
188
|
+
const expires = headers.get('Expires');
|
|
189
|
+
if (expires) {
|
|
190
|
+
const expirationTime = new Date(expires).getTime();
|
|
191
|
+
const result = now >= expirationTime;
|
|
192
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
193
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
194
|
+
// eslint-disable-next-line no-console
|
|
195
|
+
console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by Expires header is ${result ? 'in the past' : 'in the future'}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// check for Date
|
|
204
|
+
if (!date) {
|
|
205
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
206
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
207
|
+
// eslint-disable-next-line no-console
|
|
208
|
+
console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no Date header was provided`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
let expirationTime = config.apiCacheHardExpires;
|
|
214
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
215
|
+
if (!config.disableTestOptimization) {
|
|
216
|
+
expirationTime = config.apiCacheSoftExpires;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const time = new Date(date).getTime();
|
|
220
|
+
const deadline = time + expirationTime;
|
|
221
|
+
const result = now >= deadline;
|
|
222
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
223
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
224
|
+
// eslint-disable-next-line no-console
|
|
225
|
+
console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the apiCacheHardExpires time since the response's Date header is ${result ? 'in the past' : 'in the future'}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The configuration options for the {@link DefaultCachePolicy}
|
|
233
|
+
*
|
|
234
|
+
* ```ts
|
|
235
|
+
* import { DefaultCachePolicy } from '@warp-drive/core/store';
|
|
236
|
+
*
|
|
237
|
+
* new DefaultCachePolicy({
|
|
238
|
+
* // ... PolicyConfig Settings ... //
|
|
239
|
+
* });
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* A basic CachePolicy that can be added to the Store service.
|
|
246
|
+
*
|
|
247
|
+
* Determines staleness based on time since the request was last received from the API
|
|
248
|
+
* using the `date` header.
|
|
249
|
+
*
|
|
250
|
+
* Determines expiration based on configured constraints as well as a time based
|
|
251
|
+
* expiration strategy based on the `date` header.
|
|
252
|
+
*
|
|
253
|
+
* In order expiration is determined by:
|
|
254
|
+
*
|
|
255
|
+
* - Is explicitly invalidated
|
|
256
|
+
* - ↳ (if null) isExpired function \<IF Constraint Active>
|
|
257
|
+
* - ↳ (if null) X-WarpDrive-Expires header \<IF Constraint Active>
|
|
258
|
+
* - ↳ (if null) Cache-Control header \<IF Constraint Active>
|
|
259
|
+
* - ↳ (if null) Expires header \<IF Constraint Active>
|
|
260
|
+
* - ↳ (if null) Date header + apiCacheHardExpires \< current time
|
|
261
|
+
*
|
|
262
|
+
* Invalidates any request for which `cacheOptions.types` was provided when a createRecord
|
|
263
|
+
* request for that type is successful.
|
|
264
|
+
*
|
|
265
|
+
* For this to work, the `createRecord` request must include the `cacheOptions.types` array
|
|
266
|
+
* with the types that should be invalidated, or its request should specify the identifiers
|
|
267
|
+
* of the records that are being created via `records`. Providing both is valid.
|
|
268
|
+
*
|
|
269
|
+
* > [!NOTE]
|
|
270
|
+
* > only requests that had specified `cacheOptions.types` and occurred prior to the
|
|
271
|
+
* > createRecord request will be invalidated. This means that a given request should always
|
|
272
|
+
* > specify the types that would invalidate it to opt into this behavior. Abstracting this
|
|
273
|
+
* > behavior via builders is recommended to ensure consistency.
|
|
274
|
+
*
|
|
275
|
+
* This allows the Store's CacheHandler to determine if a request is expired and
|
|
276
|
+
* should be refetched upon next request.
|
|
277
|
+
*
|
|
278
|
+
* The `Fetch` handler provided by `@warp-drive/core` will automatically
|
|
279
|
+
* add the `date` header to responses if it is not present.
|
|
280
|
+
*
|
|
281
|
+
* > [!NOTE]
|
|
282
|
+
* > Date headers do not have millisecond precision, so expiration times should
|
|
283
|
+
* > generally be larger than 1000ms.
|
|
284
|
+
*
|
|
285
|
+
* Usage:
|
|
286
|
+
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* import { Store } from '@warp-drive/core';
|
|
289
|
+
* import { DefaultCachePolicy } from '@warp-drive/core/store';
|
|
290
|
+
*
|
|
291
|
+
* export class AppStore extends Store {
|
|
292
|
+
* lifetimes = new DefaultCachePolicy({
|
|
293
|
+
* apiCacheSoftExpires: 30_000,
|
|
294
|
+
* apiCacheHardExpires: 60_000
|
|
295
|
+
* });
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* In Testing environments, the `apiCacheSoftExpires` will always be `false`
|
|
300
|
+
* and `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.
|
|
301
|
+
*
|
|
302
|
+
* This helps reduce flakiness and produce predictably rendered results in test suites.
|
|
303
|
+
*
|
|
304
|
+
* Requests that specifically set `cacheOptions.backgroundReload = true` will
|
|
305
|
+
* still be background reloaded in tests.
|
|
306
|
+
*
|
|
307
|
+
* This behavior can be opted out of by setting `disableTestOptimization = true`
|
|
308
|
+
* in the policy config.
|
|
309
|
+
*
|
|
310
|
+
* @public
|
|
311
|
+
*/
|
|
312
|
+
class DefaultCachePolicy {
|
|
313
|
+
_getStore(store) {
|
|
314
|
+
let set = this._stores.get(store);
|
|
315
|
+
if (!set) {
|
|
316
|
+
set = {
|
|
317
|
+
invalidated: new Set(),
|
|
318
|
+
types: new Map()
|
|
319
|
+
};
|
|
320
|
+
this._stores.set(store, set);
|
|
321
|
+
}
|
|
322
|
+
return set;
|
|
323
|
+
}
|
|
324
|
+
constructor(config) {
|
|
325
|
+
this._stores = new WeakMap();
|
|
326
|
+
const _config = arguments.length === 1 ? config : arguments[1];
|
|
327
|
+
deprecate(`Passing a Store to the CachePolicy is deprecated, please pass only a config instead.`, arguments.length === 1, {
|
|
328
|
+
id: 'ember-data:request-utils:lifetimes-service-store-arg',
|
|
329
|
+
since: {
|
|
330
|
+
enabled: '5.4',
|
|
331
|
+
available: '4.13'
|
|
332
|
+
},
|
|
333
|
+
for: '@ember-data/request-utils',
|
|
334
|
+
until: '6.0'
|
|
335
|
+
});
|
|
336
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
337
|
+
if (!test) {
|
|
338
|
+
throw new Error(`You must pass a config to the CachePolicy`);
|
|
339
|
+
}
|
|
340
|
+
})(_config) : {};
|
|
341
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
342
|
+
if (!test) {
|
|
343
|
+
throw new Error(`You must pass a apiCacheSoftExpires to the CachePolicy`);
|
|
344
|
+
}
|
|
345
|
+
})(typeof _config.apiCacheSoftExpires === 'number') : {};
|
|
346
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
347
|
+
if (!test) {
|
|
348
|
+
throw new Error(`You must pass a apiCacheHardExpires to the CachePolicy`);
|
|
349
|
+
}
|
|
350
|
+
})(typeof _config.apiCacheHardExpires === 'number') : {};
|
|
351
|
+
this.config = _config;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Invalidate a request by its identifier for a given store instance.
|
|
356
|
+
*
|
|
357
|
+
* While the store argument may seem redundant, the CachePolicy
|
|
358
|
+
* is designed to be shared across multiple stores / forks
|
|
359
|
+
* of the store.
|
|
360
|
+
*
|
|
361
|
+
* ```ts
|
|
362
|
+
* store.lifetimes.invalidateRequest(store, identifier);
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @public
|
|
366
|
+
* @param {StableDocumentIdentifier} identifier
|
|
367
|
+
* @param {Store} store
|
|
368
|
+
*/
|
|
369
|
+
invalidateRequest(identifier, store) {
|
|
370
|
+
this._getStore(store).invalidated.add(identifier);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Invalidate all requests associated to a specific type
|
|
375
|
+
* for a given store instance.
|
|
376
|
+
*
|
|
377
|
+
* While the store argument may seem redundant, the CachePolicy
|
|
378
|
+
* is designed to be shared across multiple stores / forks
|
|
379
|
+
* of the store.
|
|
380
|
+
*
|
|
381
|
+
* This invalidation is done automatically when using this service
|
|
382
|
+
* for both the CacheHandler and the LegacyNetworkHandler.
|
|
383
|
+
*
|
|
384
|
+
* ```ts
|
|
385
|
+
* store.lifetimes.invalidateRequestsForType(store, 'person');
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @public
|
|
389
|
+
* @param {String} type
|
|
390
|
+
* @param {Store} store
|
|
391
|
+
*/
|
|
392
|
+
invalidateRequestsForType(type, store) {
|
|
393
|
+
const storeCache = this._getStore(store);
|
|
394
|
+
const set = storeCache.types.get(type);
|
|
395
|
+
const notifications = store.notifications;
|
|
396
|
+
if (set) {
|
|
397
|
+
// TODO batch notifications
|
|
398
|
+
set.forEach(id => {
|
|
399
|
+
storeCache.invalidated.add(id);
|
|
400
|
+
notifications.notify(id, 'invalidated');
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Invoked when a request has been fulfilled from the configured request handlers.
|
|
407
|
+
* This is invoked by the CacheHandler for both foreground and background requests
|
|
408
|
+
* once the cache has been updated.
|
|
409
|
+
*
|
|
410
|
+
* Note, this is invoked by the CacheHandler regardless of whether
|
|
411
|
+
* the request has a cache-key.
|
|
412
|
+
*
|
|
413
|
+
* This method should not be invoked directly by consumers.
|
|
414
|
+
*
|
|
415
|
+
* @public
|
|
416
|
+
* @param {ImmutableRequestInfo} request
|
|
417
|
+
* @param {ImmutableResponse} response
|
|
418
|
+
* @param {Store} store
|
|
419
|
+
* @param {StableDocumentIdentifier | null} identifier
|
|
420
|
+
* @return {void}
|
|
421
|
+
*/
|
|
422
|
+
didRequest(request, response, identifier, store) {
|
|
423
|
+
// if this is a successful createRecord request, invalidate the cacheKey for the type
|
|
424
|
+
if (request.op === 'createRecord') {
|
|
425
|
+
const statusNumber = response?.status ?? 0;
|
|
426
|
+
if (statusNumber >= 200 && statusNumber < 400) {
|
|
427
|
+
const types = new Set(request.records?.map(r => r.type));
|
|
428
|
+
const additionalTypes = request.cacheOptions?.types;
|
|
429
|
+
additionalTypes?.forEach(type => {
|
|
430
|
+
types.add(type);
|
|
431
|
+
});
|
|
432
|
+
types.forEach(type => {
|
|
433
|
+
this.invalidateRequestsForType(type, store);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// add this document's cacheKey to a map for all associated types
|
|
438
|
+
// it is recommended to only use this for queries
|
|
439
|
+
} else if (identifier && request.cacheOptions?.types?.length) {
|
|
440
|
+
const storeCache = this._getStore(store);
|
|
441
|
+
request.cacheOptions?.types.forEach(type => {
|
|
442
|
+
const set = storeCache.types.get(type);
|
|
443
|
+
if (set) {
|
|
444
|
+
set.add(identifier);
|
|
445
|
+
storeCache.invalidated.delete(identifier);
|
|
446
|
+
} else {
|
|
447
|
+
storeCache.types.set(type, new Set([identifier]));
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Invoked to determine if the request may be fulfilled from cache
|
|
455
|
+
* if possible.
|
|
456
|
+
*
|
|
457
|
+
* Note, this is only invoked by the CacheHandler if the request has
|
|
458
|
+
* a cache-key.
|
|
459
|
+
*
|
|
460
|
+
* If no cache entry is found or the entry is hard expired,
|
|
461
|
+
* the request will be fulfilled from the configured request handlers
|
|
462
|
+
* and the cache will be updated before returning the response.
|
|
463
|
+
*
|
|
464
|
+
* @public
|
|
465
|
+
* @param {StableDocumentIdentifier} identifier
|
|
466
|
+
* @param {Store} store
|
|
467
|
+
* @return {Boolean} true if the request is considered hard expired
|
|
468
|
+
*/
|
|
469
|
+
isHardExpired(identifier, store) {
|
|
470
|
+
// if we are explicitly invalidated, we are hard expired
|
|
471
|
+
const storeCache = this._getStore(store);
|
|
472
|
+
if (storeCache.invalidated.has(identifier)) {
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
const cache = store.cache;
|
|
476
|
+
const cached = cache.peekRequest(identifier);
|
|
477
|
+
if (!cached?.response) {
|
|
478
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
479
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
480
|
+
// eslint-disable-next-line no-console
|
|
481
|
+
console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no cache entry was found`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
return isExpired(identifier, cached, this.config);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Invoked if `isHardExpired` is false to determine if the request
|
|
491
|
+
* should be update behind the scenes if cache data is already available.
|
|
492
|
+
*
|
|
493
|
+
* Note, this is only invoked by the CacheHandler if the request has
|
|
494
|
+
* a cache-key.
|
|
495
|
+
*
|
|
496
|
+
* If true, the request will be fulfilled from cache while a backgrounded
|
|
497
|
+
* request is made to update the cache via the configured request handlers.
|
|
498
|
+
*
|
|
499
|
+
* @public
|
|
500
|
+
* @param {StableDocumentIdentifier} identifier
|
|
501
|
+
* @param {Store} store
|
|
502
|
+
* @return {Boolean} true if the request is considered soft expired
|
|
503
|
+
*/
|
|
504
|
+
isSoftExpired(identifier, store) {
|
|
505
|
+
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
506
|
+
if (!this.config.disableTestOptimization) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const cache = store.cache;
|
|
511
|
+
const cached = cache.peekRequest(identifier);
|
|
512
|
+
if (cached?.response) {
|
|
513
|
+
const date = cached.response.headers.get('date');
|
|
514
|
+
if (!date) {
|
|
515
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
516
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
517
|
+
// eslint-disable-next-line no-console
|
|
518
|
+
console.log(`CachePolicy: ${identifier.lid} is STALE because no date header was found`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return true;
|
|
522
|
+
} else {
|
|
523
|
+
const time = new Date(date).getTime();
|
|
524
|
+
const now = Date.now();
|
|
525
|
+
const deadline = time + this.config.apiCacheSoftExpires;
|
|
526
|
+
const result = now >= deadline;
|
|
527
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
528
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
529
|
+
// eslint-disable-next-line no-console
|
|
530
|
+
console.log(`CachePolicy: ${identifier.lid} is ${result ? 'STALE' : 'NOT stale'}. Expiration time: ${deadline}, now: ${now}`);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return result;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
537
|
+
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
538
|
+
// eslint-disable-next-line no-console
|
|
539
|
+
console.log(`CachePolicy: ${identifier.lid} is STALE because no cache entry was found`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
export { DefaultCachePolicy, parseCacheControl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../src/store/-private/default-cache-policy.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport { LOG_CACHE_POLICY } from '@warp-drive/core/build-config/debugging';\nimport { TESTING } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { StableDocumentIdentifier, StableRecordIdentifier } from '@warp-drive/core/types/identifier';\nimport type { ImmutableRequestInfo, ResponseInfo, StructuredDocument } from '@warp-drive/core/types/request';\nimport type { ResourceDocument } from '@warp-drive/core/types/spec/document';\n\nimport { LRUCache } from '../../utils/string';\n\ntype UnsubscribeToken = object;\ntype CacheOperation = 'added' | 'removed' | 'updated' | 'state';\ntype DocumentCacheOperation = 'invalidated' | 'added' | 'removed' | 'updated' | 'state';\n\nexport interface NotificationCallback {\n (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;\n (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;\n // (identifier: StableRecordIdentifier, notificationType: NotificationType, key?: string): void;\n}\n\ninterface ResourceOperationCallback {\n // resource updates\n (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;\n}\n\ninterface DocumentOperationCallback {\n // document updates\n (identifier: StableDocumentIdentifier, notificationType: DocumentCacheOperation): void;\n}\n\ntype NotificationManager = {\n subscribe(identifier: StableRecordIdentifier, callback: NotificationCallback): UnsubscribeToken;\n subscribe(identifier: 'resource', callback: ResourceOperationCallback): UnsubscribeToken;\n subscribe(identifier: 'document' | StableDocumentIdentifier, callback: DocumentOperationCallback): UnsubscribeToken;\n\n notify(identifier: StableRecordIdentifier, value: 'attributes' | 'relationships', key?: string): boolean;\n notify(identifier: StableRecordIdentifier, value: 'errors' | 'meta' | 'identity' | 'state'): boolean;\n notify(identifier: StableRecordIdentifier, value: CacheOperation): boolean;\n notify(identifier: StableDocumentIdentifier, value: DocumentCacheOperation): boolean;\n};\n\ntype Store = {\n cache: Cache;\n notifications: NotificationManager;\n};\n\nexport interface CacheControlValue {\n immutable?: boolean;\n 'max-age'?: number;\n 'must-revalidate'?: boolean;\n 'must-understand'?: boolean;\n 'no-cache'?: boolean;\n 'no-store'?: boolean;\n 'no-transform'?: boolean;\n 'only-if-cached'?: boolean;\n private?: boolean;\n 'proxy-revalidate'?: boolean;\n public?: boolean;\n 's-maxage'?: number;\n 'stale-if-error'?: number;\n 'stale-while-revalidate'?: number;\n}\n\ntype CacheControlKey = keyof CacheControlValue;\n\nconst NUMERIC_KEYS = new Set(['max-age', 's-maxage', 'stale-if-error', 'stale-while-revalidate']);\n\n/**\n * Parses a string Cache-Control header value into an object with the following structure:\n *\n * ```ts\n * interface CacheControlValue {\n * immutable?: boolean;\n * 'max-age'?: number;\n * 'must-revalidate'?: boolean;\n * 'must-understand'?: boolean;\n * 'no-cache'?: boolean;\n * 'no-store'?: boolean;\n * 'no-transform'?: boolean;\n * 'only-if-cached'?: boolean;\n * private?: boolean;\n * 'proxy-revalidate'?: boolean;\n * public?: boolean;\n * 's-maxage'?: number;\n * 'stale-if-error'?: number;\n * 'stale-while-revalidate'?: number;\n * }\n * ```\n *\n * @public\n * @param {String} header\n * @return {CacheControlValue}\n */\nexport function parseCacheControl(header: string): CacheControlValue {\n return CACHE_CONTROL_CACHE.get(header);\n}\n\nconst CACHE_CONTROL_CACHE = new LRUCache((header: string) => {\n let key: CacheControlKey = '' as CacheControlKey;\n let value = '';\n let isParsingKey = true;\n const cacheControlValue: CacheControlValue = {};\n\n for (let i = 0; i < header.length; i++) {\n const char = header.charAt(i);\n if (char === ',') {\n assert(`Invalid Cache-Control value, expected a value`, !isParsingKey || !NUMERIC_KEYS.has(key));\n assert(\n `Invalid Cache-Control value, expected a value after \"=\" but got \",\"`,\n i === 0 || header.charAt(i - 1) !== '='\n );\n isParsingKey = true;\n // @ts-expect-error TS incorrectly thinks that optional keys must have a type that includes undefined\n cacheControlValue[key] = NUMERIC_KEYS.has(key) ? parseCacheControlValue(value) : true;\n key = '' as CacheControlKey;\n value = '';\n continue;\n } else if (char === '=') {\n assert(`Invalid Cache-Control value, expected a value after \"=\"`, i + 1 !== header.length);\n isParsingKey = false;\n } else if (char === ' ' || char === `\\t` || char === `\\n`) {\n continue;\n } else if (isParsingKey) {\n key += char;\n } else {\n value += char;\n }\n\n if (i === header.length - 1) {\n // @ts-expect-error TS incorrectly thinks that optional keys must have a type that includes undefined\n cacheControlValue[key] = NUMERIC_KEYS.has(key) ? parseCacheControlValue(value) : true;\n }\n }\n\n return cacheControlValue;\n}, 200);\n\nfunction parseCacheControlValue(stringToParse: string): number {\n const parsedValue = Number.parseInt(stringToParse);\n assert(`Invalid Cache-Control value, expected a number but got - ${stringToParse}`, !Number.isNaN(parsedValue));\n assert(`Invalid Cache-Control value, expected a number greater than 0 but got - ${stringToParse}`, parsedValue >= 0);\n if (Number.isNaN(parsedValue) || parsedValue < 0) {\n return 0;\n }\n\n return parsedValue;\n}\n\nfunction isExpired(\n identifier: StableDocumentIdentifier,\n request: StructuredDocument<ResourceDocument>,\n config: PolicyConfig\n): boolean {\n const { constraints } = config;\n\n if (constraints?.isExpired) {\n const result = constraints.isExpired(request);\n if (result !== null) {\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(\n `CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because constraints.isExpired returned ${result}`\n );\n }\n return result;\n }\n }\n\n const { headers } = request.response!;\n\n if (!headers) {\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no headers were provided`);\n }\n\n // if we have no headers then both the headers based expiration\n // and the time based expiration will be considered expired\n return true;\n }\n\n // check for X-WarpDrive-Expires\n const now = Date.now();\n const date = headers.get('Date');\n\n if (constraints?.headers) {\n if (constraints.headers['X-WarpDrive-Expires']) {\n const xWarpDriveExpires = headers.get('X-WarpDrive-Expires');\n if (xWarpDriveExpires) {\n const expirationTime = new Date(xWarpDriveExpires).getTime();\n const result = now >= expirationTime;\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(\n `CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by X-WarpDrive-Expires header is ${result ? 'in the past' : 'in the future'}`\n );\n }\n return result;\n }\n }\n\n // check for Cache-Control\n if (constraints.headers['Cache-Control']) {\n const cacheControl = headers.get('Cache-Control');\n const age = headers.get('Age');\n\n if (cacheControl && age && date) {\n const cacheControlValue = parseCacheControl(cacheControl);\n\n // max-age and s-maxage are stored in\n const maxAge = cacheControlValue['max-age'] || cacheControlValue['s-maxage'];\n\n if (maxAge) {\n // age is stored in seconds\n const ageValue = parseInt(age, 10);\n assert(`Invalid Cache-Control value, expected a number but got - ${age}`, !Number.isNaN(ageValue));\n assert(`Invalid Cache-Control value, expected a number greater than 0 but got - ${age}`, ageValue >= 0);\n\n if (!Number.isNaN(ageValue) && ageValue >= 0) {\n const dateValue = new Date(date).getTime();\n const expirationTime = dateValue + (maxAge - ageValue) * 1000;\n const result = now >= expirationTime;\n\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(\n `CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by Cache-Control header is ${result ? 'in the past' : 'in the future'}`\n );\n }\n\n return result;\n }\n }\n }\n }\n\n // check for Expires\n if (constraints.headers.Expires) {\n const expires = headers.get('Expires');\n if (expires) {\n const expirationTime = new Date(expires).getTime();\n const result = now >= expirationTime;\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(\n `CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by Expires header is ${result ? 'in the past' : 'in the future'}`\n );\n }\n return result;\n }\n }\n }\n\n // check for Date\n if (!date) {\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no Date header was provided`);\n }\n return true;\n }\n\n let expirationTime = config.apiCacheHardExpires;\n if (TESTING) {\n if (!config.disableTestOptimization) {\n expirationTime = config.apiCacheSoftExpires;\n }\n }\n\n const time = new Date(date).getTime();\n const deadline = time + expirationTime;\n const result = now >= deadline;\n\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(\n `CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the apiCacheHardExpires time since the response's Date header is ${result ? 'in the past' : 'in the future'}`\n );\n }\n\n return result;\n}\n\n/**\n * The configuration options for the {@link DefaultCachePolicy}\n *\n * ```ts\n * import { DefaultCachePolicy } from '@warp-drive/core/store';\n *\n * new DefaultCachePolicy({\n * // ... PolicyConfig Settings ... //\n * });\n * ```\n *\n */\nexport type PolicyConfig = {\n /**\n * the number of milliseconds after which a request is considered\n * stale. If a request is issued again after this time, the request\n * will respond from cache immediately while a background request\n * is made to update the cache.\n *\n * This is calculated against the `date` header of the response.\n *\n * If your API does not provide a `date` header, the `Fetch` handler\n * provided by `@warp-drive/core` will automatically add\n * it to responses if it is not present. Responses without a `date`\n * header will be considered stale immediately.\n *\n */\n apiCacheSoftExpires: number;\n /**\n * the number of milliseconds after which a request is considered\n * expired and should be re-fetched. If a request is issued again\n * after this time, the request will disregard the cache and\n * wait for a fresh response from the API.\n *\n * This is calculated against the `date` header of the response.\n *\n * If your API does not provide a `date` header, the `Fetch` handler\n * provided by `@warp-drive/core` will automatically add\n * it to responses if it is not present. Responses without a `date`\n * header will be considered hard expired immediately.\n *\n */\n apiCacheHardExpires: number;\n /**\n * In Testing environments, the `apiCacheSoftExpires` will always be `false`\n * and `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.\n *\n * This helps reduce flakiness and produce predictably rendered results in test suites.\n *\n * Requests that specifically set `cacheOptions.backgroundReload = true` will\n * still be background reloaded in tests.\n *\n * This behavior can be opted out of by setting this value to `true`.\n *\n */\n disableTestOptimization?: boolean;\n\n /**\n * In addition to the simple time-based expiration strategy, CachePolicy\n * supports various common server-supplied expiration strategies via\n * headers, as well as custom expiration strategies via the `isExpired`\n * function.\n *\n * Requests will be validated for expiration against these constraints.\n * If any of these constraints are not met, the request will be considered\n * expired. If all constraints are met, the request will be considered\n * valid and the time based expiration strategy will NOT be used.\n *\n * Meeting a constraint means BOTH that the properties the constraint\n * requires are present AND that the expiration time indicated by those\n * properties has not been exceeded.\n *\n * In other words, if the properties for a constraint are not present,\n * this does not count either as meeting or as not meeting the constraint,\n * the constraint simply does not apply.\n *\n * The `isExpired` function is called with the request and should return\n * `true` if the request is expired, `false` if it is not expired, and\n * `null` if the expiration status is unknown.\n *\n * In order constraints are checked:\n *\n * - isExpired function\n * - ↳ (if null) X-WarpDrive-Expires header\n * - ↳ (if null) Cache-Control header\n * - ↳ (if null) Expires header\n *\n */\n constraints?: {\n /**\n * Headers that should be checked for expiration.\n *\n */\n headers?: {\n /**\n * Whether the `Cache-Control` header should be checked for expiration.\n * If `true`, then the `max-age` and `s-maxage` directives are used alongside\n * the `Age` and `Date` headers to determine if the expiration time has passed.\n *\n * Other directives are ignored.\n *\n * 'Cache-Control' will take precedence over 'Expires' if both are present\n * and both configured to be checked.\n *\n */\n 'Cache-Control'?: boolean;\n\n /**\n * Whether the `Expires` header should be checked for expiration.\n *\n * If `true`, then the `Expires` header is used to caclulate the expiration time\n * and determine if the expiration time has passed.\n *\n * 'Cache-Control' will take precedence over 'Expires' if both are present.\n *\n */\n Expires?: boolean;\n\n /**\n * Whether the `X-WarpDrive-Expires` header should be checked for expiration.\n *\n * If `true`, then the `X-WarpDrive-Expires` header is used to caclulate the expiration time\n * and determine if the expiration time has passed.\n *\n * This header will take precedence over 'Cache-Control' and 'Expires' if all three are present.\n *\n * The header's value should be a [UTC date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString).\n *\n */\n 'X-WarpDrive-Expires'?: boolean;\n };\n\n /**\n * A function that should be called to determine if the request is expired.\n *\n * If present, this function will be called with the request and should return\n * `true` if the request is expired, `false` if it is not expired, and\n * `null` if the expiration status is unknown.\n *\n * If the function does not return `null`,\n *\n */\n isExpired?: (request: StructuredDocument<ResourceDocument>) => boolean | null;\n };\n};\n\n/**\n * A basic CachePolicy that can be added to the Store service.\n *\n * Determines staleness based on time since the request was last received from the API\n * using the `date` header.\n *\n * Determines expiration based on configured constraints as well as a time based\n * expiration strategy based on the `date` header.\n *\n * In order expiration is determined by:\n *\n * - Is explicitly invalidated\n * - ↳ (if null) isExpired function \\<IF Constraint Active>\n * - ↳ (if null) X-WarpDrive-Expires header \\<IF Constraint Active>\n * - ↳ (if null) Cache-Control header \\<IF Constraint Active>\n * - ↳ (if null) Expires header \\<IF Constraint Active>\n * - ↳ (if null) Date header + apiCacheHardExpires \\< current time\n *\n * Invalidates any request for which `cacheOptions.types` was provided when a createRecord\n * request for that type is successful.\n *\n * For this to work, the `createRecord` request must include the `cacheOptions.types` array\n * with the types that should be invalidated, or its request should specify the identifiers\n * of the records that are being created via `records`. Providing both is valid.\n *\n * > [!NOTE]\n * > only requests that had specified `cacheOptions.types` and occurred prior to the\n * > createRecord request will be invalidated. This means that a given request should always\n * > specify the types that would invalidate it to opt into this behavior. Abstracting this\n * > behavior via builders is recommended to ensure consistency.\n *\n * This allows the Store's CacheHandler to determine if a request is expired and\n * should be refetched upon next request.\n *\n * The `Fetch` handler provided by `@warp-drive/core` will automatically\n * add the `date` header to responses if it is not present.\n *\n * > [!NOTE]\n * > Date headers do not have millisecond precision, so expiration times should\n * > generally be larger than 1000ms.\n *\n * Usage:\n *\n * ```ts\n * import { Store } from '@warp-drive/core';\n * import { DefaultCachePolicy } from '@warp-drive/core/store';\n *\n * export class AppStore extends Store {\n * lifetimes = new DefaultCachePolicy({\n * apiCacheSoftExpires: 30_000,\n * apiCacheHardExpires: 60_000\n * });\n * }\n * ```\n *\n * In Testing environments, the `apiCacheSoftExpires` will always be `false`\n * and `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.\n *\n * This helps reduce flakiness and produce predictably rendered results in test suites.\n *\n * Requests that specifically set `cacheOptions.backgroundReload = true` will\n * still be background reloaded in tests.\n *\n * This behavior can be opted out of by setting `disableTestOptimization = true`\n * in the policy config.\n *\n * @public\n */\nexport class DefaultCachePolicy {\n declare config: PolicyConfig;\n declare _stores: WeakMap<\n Store,\n { invalidated: Set<StableDocumentIdentifier>; types: Map<string, Set<StableDocumentIdentifier>> }\n >;\n\n _getStore(store: Store): {\n invalidated: Set<StableDocumentIdentifier>;\n types: Map<string, Set<StableDocumentIdentifier>>;\n } {\n let set = this._stores.get(store);\n if (!set) {\n set = { invalidated: new Set(), types: new Map() };\n this._stores.set(store, set);\n }\n return set;\n }\n\n constructor(config: PolicyConfig) {\n this._stores = new WeakMap();\n\n const _config = arguments.length === 1 ? config : (arguments[1] as unknown as PolicyConfig);\n deprecate(\n `Passing a Store to the CachePolicy is deprecated, please pass only a config instead.`,\n arguments.length === 1,\n {\n id: 'ember-data:request-utils:lifetimes-service-store-arg',\n since: {\n enabled: '5.4',\n available: '4.13',\n },\n for: '@ember-data/request-utils',\n until: '6.0',\n }\n );\n assert(`You must pass a config to the CachePolicy`, _config);\n assert(`You must pass a apiCacheSoftExpires to the CachePolicy`, typeof _config.apiCacheSoftExpires === 'number');\n assert(`You must pass a apiCacheHardExpires to the CachePolicy`, typeof _config.apiCacheHardExpires === 'number');\n this.config = _config;\n }\n\n /**\n * Invalidate a request by its identifier for a given store instance.\n *\n * While the store argument may seem redundant, the CachePolicy\n * is designed to be shared across multiple stores / forks\n * of the store.\n *\n * ```ts\n * store.lifetimes.invalidateRequest(store, identifier);\n * ```\n *\n * @public\n * @param {StableDocumentIdentifier} identifier\n * @param {Store} store\n */\n invalidateRequest(identifier: StableDocumentIdentifier, store: Store): void {\n this._getStore(store).invalidated.add(identifier);\n }\n\n /**\n * Invalidate all requests associated to a specific type\n * for a given store instance.\n *\n * While the store argument may seem redundant, the CachePolicy\n * is designed to be shared across multiple stores / forks\n * of the store.\n *\n * This invalidation is done automatically when using this service\n * for both the CacheHandler and the LegacyNetworkHandler.\n *\n * ```ts\n * store.lifetimes.invalidateRequestsForType(store, 'person');\n * ```\n *\n * @public\n * @param {String} type\n * @param {Store} store\n */\n invalidateRequestsForType(type: string, store: Store): void {\n const storeCache = this._getStore(store);\n const set = storeCache.types.get(type);\n const notifications = store.notifications;\n\n if (set) {\n // TODO batch notifications\n set.forEach((id) => {\n storeCache.invalidated.add(id);\n notifications.notify(id, 'invalidated');\n });\n }\n }\n\n /**\n * Invoked when a request has been fulfilled from the configured request handlers.\n * This is invoked by the CacheHandler for both foreground and background requests\n * once the cache has been updated.\n *\n * Note, this is invoked by the CacheHandler regardless of whether\n * the request has a cache-key.\n *\n * This method should not be invoked directly by consumers.\n *\n * @public\n * @param {ImmutableRequestInfo} request\n * @param {ImmutableResponse} response\n * @param {Store} store\n * @param {StableDocumentIdentifier | null} identifier\n * @return {void}\n */\n didRequest(\n request: ImmutableRequestInfo,\n response: Response | ResponseInfo | null,\n identifier: StableDocumentIdentifier | null,\n store: Store\n ): void {\n // if this is a successful createRecord request, invalidate the cacheKey for the type\n if (request.op === 'createRecord') {\n const statusNumber = response?.status ?? 0;\n if (statusNumber >= 200 && statusNumber < 400) {\n const types = new Set(request.records?.map((r) => r.type));\n const additionalTypes = request.cacheOptions?.types;\n additionalTypes?.forEach((type) => {\n types.add(type);\n });\n\n types.forEach((type) => {\n this.invalidateRequestsForType(type, store);\n });\n }\n\n // add this document's cacheKey to a map for all associated types\n // it is recommended to only use this for queries\n } else if (identifier && request.cacheOptions?.types?.length) {\n const storeCache = this._getStore(store);\n request.cacheOptions?.types.forEach((type) => {\n const set = storeCache.types.get(type);\n if (set) {\n set.add(identifier);\n storeCache.invalidated.delete(identifier);\n } else {\n storeCache.types.set(type, new Set([identifier]));\n }\n });\n }\n }\n\n /**\n * Invoked to determine if the request may be fulfilled from cache\n * if possible.\n *\n * Note, this is only invoked by the CacheHandler if the request has\n * a cache-key.\n *\n * If no cache entry is found or the entry is hard expired,\n * the request will be fulfilled from the configured request handlers\n * and the cache will be updated before returning the response.\n *\n * @public\n * @param {StableDocumentIdentifier} identifier\n * @param {Store} store\n * @return {Boolean} true if the request is considered hard expired\n */\n isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean {\n // if we are explicitly invalidated, we are hard expired\n const storeCache = this._getStore(store);\n if (storeCache.invalidated.has(identifier)) {\n return true;\n }\n const cache = store.cache;\n const cached = cache.peekRequest(identifier);\n\n if (!cached?.response) {\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no cache entry was found`);\n }\n return true;\n }\n\n return isExpired(identifier, cached, this.config);\n }\n\n /**\n * Invoked if `isHardExpired` is false to determine if the request\n * should be update behind the scenes if cache data is already available.\n *\n * Note, this is only invoked by the CacheHandler if the request has\n * a cache-key.\n *\n * If true, the request will be fulfilled from cache while a backgrounded\n * request is made to update the cache via the configured request handlers.\n *\n * @public\n * @param {StableDocumentIdentifier} identifier\n * @param {Store} store\n * @return {Boolean} true if the request is considered soft expired\n */\n isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean {\n if (TESTING) {\n if (!this.config.disableTestOptimization) {\n return false;\n }\n }\n const cache = store.cache;\n const cached = cache.peekRequest(identifier);\n\n if (cached?.response) {\n const date = cached.response.headers.get('date');\n\n if (!date) {\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(`CachePolicy: ${identifier.lid} is STALE because no date header was found`);\n }\n return true;\n } else {\n const time = new Date(date).getTime();\n const now = Date.now();\n const deadline = time + this.config.apiCacheSoftExpires;\n const result = now >= deadline;\n\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(\n `CachePolicy: ${identifier.lid} is ${result ? 'STALE' : 'NOT stale'}. Expiration time: ${deadline}, now: ${now}`\n );\n }\n\n return result;\n }\n }\n\n if (LOG_CACHE_POLICY) {\n // eslint-disable-next-line no-console\n console.log(`CachePolicy: ${identifier.lid} is STALE because no cache entry was found`);\n }\n\n return true;\n }\n}\n"],"names":["NUMERIC_KEYS","Set","parseCacheControl","header","CACHE_CONTROL_CACHE","get","LRUCache","key","value","isParsingKey","cacheControlValue","i","length","char","charAt","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","has","parseCacheControlValue","stringToParse","parsedValue","Number","parseInt","isNaN","isExpired","identifier","request","config","constraints","result","activeLogging","LOG_CACHE_POLICY","debug","globalThis","getWarpDriveRuntimeConfig","console","log","lid","headers","response","now","Date","date","xWarpDriveExpires","expirationTime","getTime","cacheControl","age","maxAge","ageValue","dateValue","Expires","expires","apiCacheHardExpires","TESTING","disableTestOptimization","apiCacheSoftExpires","time","deadline","DefaultCachePolicy","_getStore","store","set","_stores","invalidated","types","Map","constructor","WeakMap","_config","arguments","deprecate","id","since","enabled","available","for","until","invalidateRequest","add","invalidateRequestsForType","type","storeCache","notifications","forEach","notify","didRequest","op","statusNumber","status","records","map","r","additionalTypes","cacheOptions","delete","isHardExpired","cache","cached","peekRequest","isSoftExpired"],"mappings":";;;;AAmEA,MAAMA,YAAY,GAAG,IAAIC,GAAG,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,wBAAwB,CAAC,CAAC;;AAEjG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAACC,MAAc,EAAqB;AACnE,EAAA,OAAOC,mBAAmB,CAACC,GAAG,CAACF,MAAM,CAAC;AACxC;AAEA,MAAMC,mBAAmB,GAAG,IAAIE,QAAQ,CAAEH,MAAc,IAAK;EAC3D,IAAII,GAAoB,GAAG,EAAqB;EAChD,IAAIC,KAAK,GAAG,EAAE;EACd,IAAIC,YAAY,GAAG,IAAI;EACvB,MAAMC,iBAAoC,GAAG,EAAE;AAE/C,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGR,MAAM,CAACS,MAAM,EAAED,CAAC,EAAE,EAAE;AACtC,IAAA,MAAME,IAAI,GAAGV,MAAM,CAACW,MAAM,CAACH,CAAC,CAAC;IAC7B,IAAIE,IAAI,KAAK,GAAG,EAAE;MAChBE,cAAA,CAAAC,eAAA,EAAA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