@warp-drive/core 5.8.0-alpha.4 → 5.8.0-alpha.41
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/README.md +22 -38
- package/declarations/build-config.d.ts +18 -1
- package/declarations/configure.d.ts +1 -1
- package/declarations/graph/-private/-edge-definition.d.ts +12 -2
- package/declarations/index.d.ts +90 -8
- package/declarations/reactive/-private/default-mode.d.ts +1 -1
- package/declarations/reactive/-private/document.d.ts +58 -46
- package/declarations/reactive/-private/fields/extension.d.ts +1 -1
- package/declarations/reactive/-private/fields/managed-array.d.ts +2 -2
- package/declarations/reactive/-private/fields/managed-object.d.ts +1 -1
- package/declarations/reactive/-private/record.d.ts +10 -1
- package/declarations/reactive/-private/schema.d.ts +77 -4
- package/declarations/reactive/-private.d.ts +1 -0
- package/declarations/reactive.d.ts +13 -8
- package/declarations/request/-private/types.d.ts +1 -1
- package/declarations/request.d.ts +47 -0
- package/declarations/signals/-leaked.d.ts +2 -0
- package/declarations/signals/-private.d.ts +6 -0
- package/declarations/{store/-private/new-core-tmp → signals}/promise-state.d.ts +2 -1
- package/declarations/{store/-private/new-core-tmp → signals}/request-state.d.ts +6 -6
- package/declarations/{store/-private/new-core-tmp → signals}/request-subscription.d.ts +4 -4
- package/declarations/store/-private/cache-handler/types.d.ts +2 -16
- package/declarations/store/-private/caches/instance-cache.d.ts +5 -6
- package/declarations/store/-private/default-cache-policy.d.ts +147 -129
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/-private/managers/cache-key-manager.d.ts +26 -8
- package/declarations/store/-private/managers/cache-manager.d.ts +7 -18
- package/declarations/store/-private/managers/notification-manager.d.ts +1 -1
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +1 -1
- package/declarations/store/-private/record-arrays/resource-array.d.ts +1 -1
- package/declarations/store/-private/store-service.d.ts +43 -64
- package/declarations/store/-private.d.ts +0 -6
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/deprecated/-private.d.ts +2 -2
- package/declarations/store/deprecated/store.d.ts +33 -32
- package/declarations/store.d.ts +1 -0
- package/declarations/types/cache.d.ts +8 -6
- package/declarations/types/record.d.ts +132 -0
- package/declarations/types/request.d.ts +26 -14
- package/declarations/types/schema/fields.d.ts +37 -13
- package/declarations/{store/-types/q → types/schema}/schema-service.d.ts +15 -13
- package/declarations/types/spec/document.d.ts +34 -0
- package/declarations/types/symbols.d.ts +2 -2
- package/declarations/types.d.ts +1 -1
- package/dist/build-config.js +1 -1
- package/dist/configure-DPUFCemT.js +1940 -0
- package/dist/configure.js +2 -1
- package/dist/default-cache-policy-D7_u4YRH.js +572 -0
- package/dist/{context-C_7OLieY.js → future-BKkJJkj7.js} +174 -174
- package/dist/graph/-private.js +16 -6
- package/dist/{request-state-CUuZzgvE.js → index-CQP2NSqg.js} +8835 -9432
- package/dist/index.js +6 -382
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +4 -903
- package/dist/request.js +49 -1
- package/dist/signals/-leaked.js +1 -0
- package/dist/store/-private.js +1 -2
- package/dist/store.js +1 -533
- package/dist/symbols-3C1OkYtZ.js +39 -0
- package/dist/types/-private.js +1 -1
- package/dist/types/record.js +127 -0
- package/dist/types/request.js +14 -12
- package/dist/types/schema/fields.js +14 -0
- package/dist/types/schema/schema-service.js +0 -0
- package/dist/types/symbols.js +2 -2
- package/dist/unpkg/dev/-leaked-Co0EI6Go.js +1939 -0
- package/dist/unpkg/dev/build-config/babel-macros.js +1 -0
- package/dist/unpkg/dev/build-config/canary-features.js +1 -0
- package/dist/unpkg/dev/build-config/debugging.js +1 -0
- package/dist/unpkg/dev/build-config/deprecations.js +1 -0
- package/dist/unpkg/dev/build-config/env.js +1 -0
- package/dist/unpkg/dev/build-config/macros.js +1 -0
- package/dist/unpkg/dev/build-config.js +1 -0
- package/dist/unpkg/dev/configure.js +1 -0
- package/dist/unpkg/dev/future-DFfOzSoe.js +672 -0
- package/dist/unpkg/dev/graph/-private.js +3132 -0
- package/dist/unpkg/dev/index-CepUPZlc.js +9392 -0
- package/dist/unpkg/dev/index.js +6 -0
- package/dist/unpkg/dev/reactive/-private.js +1 -0
- package/dist/unpkg/dev/reactive.js +3 -0
- package/dist/unpkg/dev/request.js +49 -0
- package/dist/unpkg/dev/runtime-DGG4CvlW.js +135 -0
- package/dist/unpkg/dev/signals/-leaked.js +1 -0
- package/dist/unpkg/dev/store/-private.js +55 -0
- package/dist/unpkg/dev/store.js +558 -0
- package/dist/unpkg/dev/types/-private.js +69 -0
- package/dist/unpkg/dev/types/cache/aliases.js +0 -0
- package/dist/unpkg/dev/types/cache/change.js +0 -0
- package/dist/unpkg/dev/types/cache/mutations.js +0 -0
- package/dist/unpkg/dev/types/cache/operations.js +0 -0
- package/dist/unpkg/dev/types/cache/relationship.js +0 -0
- package/dist/unpkg/dev/types/cache.js +0 -0
- package/dist/unpkg/dev/types/graph.js +0 -0
- package/dist/unpkg/dev/types/identifier.js +61 -0
- package/dist/unpkg/dev/types/json/raw.js +0 -0
- package/dist/unpkg/dev/types/params.js +0 -0
- package/dist/unpkg/dev/types/record.js +191 -0
- package/dist/unpkg/dev/types/request.js +77 -0
- package/dist/unpkg/dev/types/runtime.js +34 -0
- package/dist/unpkg/dev/types/schema/concepts.js +0 -0
- package/dist/unpkg/dev/types/schema/fields.js +505 -0
- package/dist/unpkg/dev/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/dev/types/schema/schema-service.js +0 -0
- package/dist/unpkg/dev/types/spec/document.js +0 -0
- package/dist/unpkg/dev/types/spec/error.js +0 -0
- package/dist/unpkg/dev/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/dev/types/symbols.js +84 -0
- package/dist/unpkg/dev/types/utils.js +0 -0
- package/dist/unpkg/dev/types.js +0 -0
- package/dist/unpkg/dev/utils/string.js +91 -0
- package/dist/unpkg/dev-deprecated/-leaked-DjMeRqdU.js +1939 -0
- package/dist/unpkg/dev-deprecated/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/dev-deprecated/build-config/babel-macros.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/canary-features.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/debugging.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/deprecations.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/env.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/macros.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config.js +1 -0
- package/dist/unpkg/dev-deprecated/configure.js +1 -0
- package/dist/unpkg/dev-deprecated/future-DFfOzSoe.js +672 -0
- package/dist/unpkg/dev-deprecated/graph/-private.js +3327 -0
- package/dist/unpkg/dev-deprecated/index-C_EEmn_3.js +10007 -0
- package/dist/unpkg/dev-deprecated/index.js +5 -0
- package/dist/unpkg/dev-deprecated/reactive/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/reactive.js +3 -0
- package/dist/unpkg/dev-deprecated/request.js +49 -0
- package/dist/unpkg/dev-deprecated/runtime-DfhJzpZH.js +135 -0
- package/dist/unpkg/dev-deprecated/signals/-leaked.js +1 -0
- package/dist/unpkg/dev-deprecated/store/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/store.js +558 -0
- package/dist/unpkg/dev-deprecated/types/-private.js +69 -0
- package/dist/unpkg/dev-deprecated/types/cache/aliases.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/change.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/mutations.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/operations.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/relationship.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache.js +0 -0
- package/dist/unpkg/dev-deprecated/types/graph.js +0 -0
- package/dist/unpkg/dev-deprecated/types/identifier.js +61 -0
- package/dist/unpkg/dev-deprecated/types/json/raw.js +0 -0
- package/dist/unpkg/dev-deprecated/types/params.js +0 -0
- package/dist/unpkg/dev-deprecated/types/record.js +191 -0
- package/dist/unpkg/dev-deprecated/types/request.js +77 -0
- package/dist/unpkg/dev-deprecated/types/runtime.js +34 -0
- package/dist/unpkg/dev-deprecated/types/schema/concepts.js +0 -0
- package/dist/unpkg/dev-deprecated/types/schema/fields.js +505 -0
- package/dist/unpkg/dev-deprecated/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/dev-deprecated/types/schema/schema-service.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/document.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/error.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/dev-deprecated/types/symbols.js +84 -0
- package/dist/unpkg/dev-deprecated/types/utils.js +0 -0
- package/dist/unpkg/dev-deprecated/types.js +0 -0
- package/dist/unpkg/dev-deprecated/utils/string.js +91 -0
- package/dist/unpkg/prod/-leaked-DUONXQDB.js +1676 -0
- package/dist/unpkg/prod/-private-sql1_mdx.js +39 -0
- package/dist/unpkg/prod/build-config/babel-macros.js +1 -0
- package/dist/unpkg/prod/build-config/canary-features.js +1 -0
- package/dist/unpkg/prod/build-config/debugging.js +1 -0
- package/dist/unpkg/prod/build-config/deprecations.js +1 -0
- package/dist/unpkg/prod/build-config/env.js +1 -0
- package/dist/unpkg/prod/build-config/macros.js +1 -0
- package/dist/unpkg/prod/build-config.js +1 -0
- package/dist/unpkg/prod/configure.js +2 -0
- package/dist/unpkg/prod/graph/-private.js +2235 -0
- package/dist/unpkg/prod/handler-EU_8ncB2.js +1619 -0
- package/dist/unpkg/prod/index.js +483 -0
- package/dist/unpkg/prod/promise-cache-DIT8Ypjq.js +19 -0
- package/dist/unpkg/prod/reactive/-private.js +1 -0
- package/dist/unpkg/prod/reactive.js +30 -0
- package/dist/unpkg/prod/request-BrJSCG6r.js +421 -0
- package/dist/unpkg/prod/request.js +2 -0
- package/dist/unpkg/prod/schema-BSkHyoWz.js +5219 -0
- package/dist/unpkg/prod/signals/-leaked.js +1 -0
- package/dist/unpkg/prod/store/-private.js +126 -0
- package/dist/unpkg/prod/store.js +437 -0
- package/dist/unpkg/prod/types/-private.js +49 -0
- package/dist/unpkg/prod/types/cache/aliases.js +0 -0
- package/dist/unpkg/prod/types/cache/change.js +0 -0
- package/dist/unpkg/prod/types/cache/mutations.js +0 -0
- package/dist/unpkg/prod/types/cache/operations.js +0 -0
- package/dist/unpkg/prod/types/cache/relationship.js +0 -0
- package/dist/unpkg/prod/types/cache.js +0 -0
- package/dist/unpkg/prod/types/graph.js +0 -0
- package/dist/unpkg/prod/types/identifier.js +61 -0
- package/dist/unpkg/prod/types/json/raw.js +0 -0
- package/dist/unpkg/prod/types/params.js +0 -0
- package/dist/unpkg/prod/types/record.js +191 -0
- package/dist/unpkg/prod/types/request.js +77 -0
- package/dist/unpkg/prod/types/runtime.js +34 -0
- package/dist/unpkg/prod/types/schema/concepts.js +0 -0
- package/dist/unpkg/prod/types/schema/fields.js +505 -0
- package/dist/unpkg/prod/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/prod/types/schema/schema-service.js +0 -0
- package/dist/unpkg/prod/types/spec/document.js +0 -0
- package/dist/unpkg/prod/types/spec/error.js +0 -0
- package/dist/unpkg/prod/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/prod/types/symbols.js +84 -0
- package/dist/unpkg/prod/types/utils.js +0 -0
- package/dist/unpkg/prod/types.js +0 -0
- package/dist/unpkg/prod/utils/string.js +72 -0
- package/dist/unpkg/prod-deprecated/-leaked-DRNv9VIX.js +1676 -0
- package/dist/unpkg/prod-deprecated/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/prod-deprecated/build-config/babel-macros.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/canary-features.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/debugging.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/deprecations.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/env.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/macros.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config.js +1 -0
- package/dist/unpkg/prod-deprecated/configure.js +2 -0
- package/dist/unpkg/prod-deprecated/graph/-private.js +2408 -0
- package/dist/unpkg/prod-deprecated/handler-CCIu4sQ3.js +334 -0
- package/dist/unpkg/prod-deprecated/hooks-Dv4Np0MY.js +26 -0
- package/dist/unpkg/prod-deprecated/index.js +483 -0
- package/dist/unpkg/prod-deprecated/promise-cache-DIT8Ypjq.js +19 -0
- package/dist/unpkg/prod-deprecated/reactive/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/reactive.js +5 -0
- package/dist/unpkg/prod-deprecated/request-BrJSCG6r.js +421 -0
- package/dist/unpkg/prod-deprecated/request.js +2 -0
- package/dist/unpkg/prod-deprecated/schema-CJcjHv0E.js +6939 -0
- package/dist/unpkg/prod-deprecated/signals/-leaked.js +1 -0
- package/dist/unpkg/prod-deprecated/store/-private.js +88 -0
- package/dist/unpkg/prod-deprecated/store.js +437 -0
- package/dist/unpkg/prod-deprecated/types/-private.js +49 -0
- package/dist/unpkg/prod-deprecated/types/cache/aliases.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/change.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/mutations.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/operations.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/relationship.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache.js +0 -0
- package/dist/unpkg/prod-deprecated/types/graph.js +0 -0
- package/dist/unpkg/prod-deprecated/types/identifier.js +61 -0
- package/dist/unpkg/prod-deprecated/types/json/raw.js +0 -0
- package/dist/unpkg/prod-deprecated/types/params.js +0 -0
- package/dist/unpkg/prod-deprecated/types/record.js +191 -0
- package/dist/unpkg/prod-deprecated/types/request.js +77 -0
- package/dist/unpkg/prod-deprecated/types/runtime.js +34 -0
- package/dist/unpkg/prod-deprecated/types/schema/concepts.js +0 -0
- package/dist/unpkg/prod-deprecated/types/schema/fields.js +505 -0
- package/dist/unpkg/prod-deprecated/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/prod-deprecated/types/schema/schema-service.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/document.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/error.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/prod-deprecated/types/symbols.js +84 -0
- package/dist/unpkg/prod-deprecated/types/utils.js +0 -0
- package/dist/unpkg/prod-deprecated/types.js +0 -0
- package/dist/unpkg/prod-deprecated/utils/string.js +72 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +11 -3
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +0 -24
- package/dist/configure-C3x8YXzL.js +0 -181
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/configure.d.ts +0 -0
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/internal.d.ts +0 -0
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/signal.d.ts +0 -0
- /package/dist/{symbols-sql1_mdx.js → unpkg/dev/-private-sql1_mdx.js} +0 -0
package/dist/request.js
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./
|
|
1
|
+
export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./future-BKkJJkj7.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Brands the supplied object with the supplied response type.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { ReactiveDataDocument } from '@warp-drive/core/reactive';
|
|
8
|
+
* import { withResponseType } from '@warp-drive/core/request';
|
|
9
|
+
* import type { User } from '#/data/user.ts'
|
|
10
|
+
*
|
|
11
|
+
* const result = await store.request(
|
|
12
|
+
* withResponseType<ReactiveDataDocument<User>>({ url: '/users/1' })
|
|
13
|
+
* );
|
|
14
|
+
*
|
|
15
|
+
* result.content.data; // will have type User
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
function withResponseType(obj) {
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Brands the supplied object with the supplied response type
|
|
25
|
+
* wrapped in {@link ReactiveDataDocument}. This is a convenience for
|
|
26
|
+
* the common case of using {@link withResponseType} with `ReactiveDataDocument`.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { withReactiveResponse } from '@warp-drive/core/request';
|
|
30
|
+
* import type { User } from '#/data/user.ts'
|
|
31
|
+
*
|
|
32
|
+
* const result = await store.request(
|
|
33
|
+
* withReactiveResponse<User>({ url: '/users/1' })
|
|
34
|
+
* );
|
|
35
|
+
*
|
|
36
|
+
* result.content.data; // will have type User
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
function withReactiveResponse(obj) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use {@link withResponseType} instead
|
|
47
|
+
*/
|
|
48
|
+
const withBrand = withResponseType;
|
|
49
|
+
export { withBrand, withReactiveResponse, withResponseType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { D as DISPOSE, a as defineGate, d as defineNonEnumerableSignal, b as defineSignal, e as entangleSignal, g as gate, m as memoized, n as notifyInternalSignal, p as peekInternalSignal, s as signal, w as waitFor, c as withSignalStore } from "../configure-DPUFCemT.js";
|
package/dist/store/-private.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { C as CacheHandler,
|
|
2
|
-
export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, w as waitFor } from "../configure-C3x8YXzL.js";
|
|
1
|
+
export { C as CacheHandler, R as RecordArrayManager, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, l as createLegacyManyArray, e as ensureStringId, f as fastPush, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, r as recordIdentifierFor, j as setRecordIdentifier, s as storeFor } from "../index-CQP2NSqg.js";
|
package/dist/store.js
CHANGED
|
@@ -1,533 +1 @@
|
|
|
1
|
-
|
|
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(cacheKey, 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: ${cacheKey.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: ${cacheKey.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: ${cacheKey.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: ${cacheKey.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: ${cacheKey.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: ${cacheKey.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: ${cacheKey.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 ResourceKeys
|
|
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 CacheKey for the 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, cacheKey);
|
|
363
|
-
* ```
|
|
364
|
-
*
|
|
365
|
-
* @public
|
|
366
|
-
*/
|
|
367
|
-
invalidateRequest(cacheKey, store) {
|
|
368
|
-
this._getStore(store).invalidated.add(cacheKey);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Invalidate all requests associated to a specific type
|
|
373
|
-
* for a given store instance.
|
|
374
|
-
*
|
|
375
|
-
* While the store argument may seem redundant, the CachePolicy
|
|
376
|
-
* is designed to be shared across multiple stores / forks
|
|
377
|
-
* of the store.
|
|
378
|
-
*
|
|
379
|
-
* This invalidation is done automatically when using this service
|
|
380
|
-
* for both the CacheHandler and the LegacyNetworkHandler.
|
|
381
|
-
*
|
|
382
|
-
* ```ts
|
|
383
|
-
* store.lifetimes.invalidateRequestsForType(store, 'person');
|
|
384
|
-
* ```
|
|
385
|
-
*
|
|
386
|
-
* @public
|
|
387
|
-
*/
|
|
388
|
-
invalidateRequestsForType(type, store) {
|
|
389
|
-
const storeCache = this._getStore(store);
|
|
390
|
-
const set = storeCache.types.get(type);
|
|
391
|
-
const notifications = store.notifications;
|
|
392
|
-
if (set) {
|
|
393
|
-
// TODO batch notifications
|
|
394
|
-
set.forEach(id => {
|
|
395
|
-
storeCache.invalidated.add(id);
|
|
396
|
-
// @ts-expect-error
|
|
397
|
-
notifications.notify(id, 'invalidated', null);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Invoked when a request has been fulfilled from the configured request handlers.
|
|
404
|
-
* This is invoked by the CacheHandler for both foreground and background requests
|
|
405
|
-
* once the cache has been updated.
|
|
406
|
-
*
|
|
407
|
-
* Note, this is invoked by the CacheHandler regardless of whether
|
|
408
|
-
* the request has a cache-key.
|
|
409
|
-
*
|
|
410
|
-
* This method should not be invoked directly by consumers.
|
|
411
|
-
*
|
|
412
|
-
* @public
|
|
413
|
-
*/
|
|
414
|
-
didRequest(request, response, cacheKey, store) {
|
|
415
|
-
// if this is a successful createRecord request, invalidate the cacheKey for the type
|
|
416
|
-
if (request.op === 'createRecord') {
|
|
417
|
-
const statusNumber = response?.status ?? 0;
|
|
418
|
-
if (statusNumber >= 200 && statusNumber < 400) {
|
|
419
|
-
const types = new Set(request.records?.map(r => r.type));
|
|
420
|
-
const additionalTypes = request.cacheOptions?.types;
|
|
421
|
-
additionalTypes?.forEach(type => {
|
|
422
|
-
types.add(type);
|
|
423
|
-
});
|
|
424
|
-
types.forEach(type => {
|
|
425
|
-
this.invalidateRequestsForType(type, store);
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// add this document's cacheKey to a map for all associated types
|
|
430
|
-
// it is recommended to only use this for queries
|
|
431
|
-
} else if (cacheKey && request.cacheOptions?.types?.length) {
|
|
432
|
-
const storeCache = this._getStore(store);
|
|
433
|
-
request.cacheOptions?.types.forEach(type => {
|
|
434
|
-
const set = storeCache.types.get(type);
|
|
435
|
-
if (set) {
|
|
436
|
-
set.add(cacheKey);
|
|
437
|
-
storeCache.invalidated.delete(cacheKey);
|
|
438
|
-
} else {
|
|
439
|
-
storeCache.types.set(type, new Set([cacheKey]));
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Invoked to determine if the request may be fulfilled from cache
|
|
447
|
-
* if possible.
|
|
448
|
-
*
|
|
449
|
-
* Note, this is only invoked by the CacheHandler if the request has
|
|
450
|
-
* a cache-key.
|
|
451
|
-
*
|
|
452
|
-
* If no cache entry is found or the entry is hard expired,
|
|
453
|
-
* the request will be fulfilled from the configured request handlers
|
|
454
|
-
* and the cache will be updated before returning the response.
|
|
455
|
-
*
|
|
456
|
-
* @public
|
|
457
|
-
* @return true if the request is considered hard expired
|
|
458
|
-
*/
|
|
459
|
-
isHardExpired(cacheKey, store) {
|
|
460
|
-
// if we are explicitly invalidated, we are hard expired
|
|
461
|
-
const storeCache = this._getStore(store);
|
|
462
|
-
if (storeCache.invalidated.has(cacheKey)) {
|
|
463
|
-
return true;
|
|
464
|
-
}
|
|
465
|
-
const cache = store.cache;
|
|
466
|
-
const cached = cache.peekRequest(cacheKey);
|
|
467
|
-
if (!cached?.response) {
|
|
468
|
-
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
469
|
-
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
470
|
-
// eslint-disable-next-line no-console
|
|
471
|
-
console.log(`CachePolicy: ${cacheKey.lid} is EXPIRED because no cache entry was found`);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return true;
|
|
475
|
-
}
|
|
476
|
-
return isExpired(cacheKey, cached, this.config);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Invoked if `isHardExpired` is false to determine if the request
|
|
481
|
-
* should be update behind the scenes if cache data is already available.
|
|
482
|
-
*
|
|
483
|
-
* Note, this is only invoked by the CacheHandler if the request has
|
|
484
|
-
* a cache-key.
|
|
485
|
-
*
|
|
486
|
-
* If true, the request will be fulfilled from cache while a backgrounded
|
|
487
|
-
* request is made to update the cache via the configured request handlers.
|
|
488
|
-
*
|
|
489
|
-
* @public
|
|
490
|
-
* @return true if the request is considered soft expired
|
|
491
|
-
*/
|
|
492
|
-
isSoftExpired(cacheKey, store) {
|
|
493
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
|
|
494
|
-
if (!this.config.disableTestOptimization) {
|
|
495
|
-
return false;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
const cache = store.cache;
|
|
499
|
-
const cached = cache.peekRequest(cacheKey);
|
|
500
|
-
if (cached?.response) {
|
|
501
|
-
const date = cached.response.headers.get('date');
|
|
502
|
-
if (!date) {
|
|
503
|
-
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
504
|
-
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
505
|
-
// eslint-disable-next-line no-console
|
|
506
|
-
console.log(`CachePolicy: ${cacheKey.lid} is STALE because no date header was found`);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
return true;
|
|
510
|
-
} else {
|
|
511
|
-
const time = new Date(date).getTime();
|
|
512
|
-
const now = Date.now();
|
|
513
|
-
const deadline = time + this.config.apiCacheSoftExpires;
|
|
514
|
-
const result = now >= deadline;
|
|
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: ${cacheKey.lid} is ${result ? 'STALE' : 'NOT stale'}. Expiration time: ${deadline}, now: ${now}`);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
return result;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
|
|
525
|
-
if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
|
|
526
|
-
// eslint-disable-next-line no-console
|
|
527
|
-
console.log(`CachePolicy: ${cacheKey.lid} is STALE because no cache entry was found`);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return true;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
export { DefaultCachePolicy, parseCacheControl };
|
|
1
|
+
export { D as DefaultCachePolicy, p as parseCacheControl } from "./default-cache-policy-D7_u4YRH.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getOrSetGlobal } from './types/-private.js';
|
|
2
|
+
|
|
3
|
+
///////////////////
|
|
4
|
+
///// WARNING /////
|
|
5
|
+
///////////////////
|
|
6
|
+
|
|
7
|
+
// Great, got your attention with that warning didn't we?
|
|
8
|
+
// Good. Here's the deal: typescript treats symbols as unique types.
|
|
9
|
+
// If by accident a module creating a symbol is processed more than
|
|
10
|
+
// once, the symbol will be different in each processing. This will
|
|
11
|
+
// cause a type error.
|
|
12
|
+
// It could also cause a runtime error if the symbol is used innapropriately.
|
|
13
|
+
// However, this case is extremely hard to hit and would require other things
|
|
14
|
+
// to go wrong first.
|
|
15
|
+
//
|
|
16
|
+
// So, why do the warning? And why do we lie about the types of the symbols?
|
|
17
|
+
//
|
|
18
|
+
// Because we intentionally create multiple copies of them within the types
|
|
19
|
+
// at build time. This is because we rollup our d.ts files in order to give
|
|
20
|
+
// our consumers a better experience.
|
|
21
|
+
//
|
|
22
|
+
// However, no tool today supports rolling up d.ts files with multiple entry
|
|
23
|
+
// points correctly. The tool we use currently (vite-plugin-dts) uses @microsoft/api-extractor
|
|
24
|
+
// which creates a fully unique stand-alone types file per-entry-point. Thus
|
|
25
|
+
// every entry point that uses one of these symbols somewhere will have accidentally
|
|
26
|
+
// created a new symbol type.
|
|
27
|
+
//
|
|
28
|
+
// This cast allows us to rollup these types using this tool while not encountering
|
|
29
|
+
// the unique symbol type issue.
|
|
30
|
+
//
|
|
31
|
+
// Note that none of these symbols are part of the public API, these are used for
|
|
32
|
+
// debugging DX and as a safe way to provide an intimate contract on public objects.
|
|
33
|
+
|
|
34
|
+
const SOURCE = getOrSetGlobal('SOURCE', Symbol('#source'));
|
|
35
|
+
const Destroy = getOrSetGlobal('Destroy', Symbol.dispose || Symbol.for('Dispose'));
|
|
36
|
+
const Checkout = getOrSetGlobal('Checkout', Symbol('Checkout'));
|
|
37
|
+
const Commit = getOrSetGlobal('Commit', Symbol('Commit'));
|
|
38
|
+
const Context = getOrSetGlobal('Context', Symbol('Context'));
|
|
39
|
+
export { Checkout as C, Destroy as D, SOURCE as S, Context as a, Commit as b };
|
package/dist/types/-private.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
2
2
|
const name = "@warp-drive/core";
|
|
3
|
-
const version = "5.8.0-alpha.
|
|
3
|
+
const version = "5.8.0-alpha.41";
|
|
4
4
|
|
|
5
5
|
// in testing mode, we utilize globals to ensure only one copy exists of
|
|
6
6
|
// these maps, due to bugs in ember-auto-import
|