@warp-drive/core 5.8.0-alpha.4 → 5.8.0-alpha.6

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 CHANGED
@@ -19,7 +19,7 @@
19
19
  [![Docs](./logos/docs-badge.svg)](https://api.emberjs.com/ember-data/release)
20
20
  [![EmberJS Discord Community Server](https://img.shields.io/badge/EmberJS-grey?logo=discord&logoColor=FFC474)](https://discord.gg/zT3asNS
21
21
  )
22
- [![WarpDrive Discord Server](https://img.shields.io/badge/WarpDrive-grey?logo=discord&logoColor=FFC474)](https://discord.gg/n8BptgFzNt
22
+ [![WarpDrive Discord Server](https://img.shields.io/badge/WarpDrive-grey?logo=discord&logoColor=FFC474)](https://discord.gg/PHBbnWJx5S
23
23
  )
24
24
 
25
25
 
@@ -1 +1,18 @@
1
- export { setConfig } from "@warp-drive/build-config";
1
+ /**
2
+ * This module provides a build-plugin that enables configuration of deprecations,
3
+ * optional features, development/testing support and debug logging.
4
+ *
5
+ * Available settings include:
6
+ *
7
+ * - {@link LOGGING | debugging}
8
+ * - {@link DEPRECATIONS | deprecations}
9
+ * - {@link FEATURES | features}
10
+ * - {@link WarpDriveConfig.polyfillUUID | polyfillUUID}
11
+ * - {@link WarpDriveConfig.includeDataAdapterInProduction | includeDataAdapterInProduction}
12
+ * - {@link WarpDriveConfig.compatWith | compatWith}
13
+ *
14
+ * @module
15
+ */
16
+ import type { WarpDriveConfig } from "@warp-drive/build-config";
17
+ export { setConfig, babelPlugin } from "@warp-drive/build-config";
18
+ export type { WarpDriveConfig };
@@ -2,13 +2,90 @@
2
2
  * @module
3
3
  * @mergeModuleWith <project>
4
4
  */
5
+ import type { CAUTION_MEGA_DANGER_ZONE_Extension } from "./reactive.js";
5
6
  import type { ReactiveDocument } from "./reactive/-private/document.js";
6
- export { Fetch } from "./request/-private/fetch.js";
7
- export { RequestManager } from "./request/-private/manager.js";
8
- export { Store, type StoreRequestContext, CacheHandler, type CachePolicy, type StoreRequestInput, recordIdentifierFor, storeFor } from "./store/-private.js";
7
+ import type { Handler } from "./request.js";
8
+ import { Fetch } from "./request/-private/fetch.js";
9
+ import { RequestManager } from "./request/-private/manager.js";
10
+ import { CacheHandler, type CachePolicy, Store } from "./store/-private.js";
11
+ import type { CacheCapabilitiesManager } from "./types.js";
12
+ import type { Cache } from "./types/cache.js";
13
+ import type { Derivation, HashFn, Transformation } from "./types/schema/concepts.js";
14
+ import type { ObjectSchema, PolarisResourceSchema, Trait } from "./types/schema/fields.js";
15
+ export { Fetch, RequestManager };
16
+ export { Store, CacheHandler, type CachePolicy };
17
+ export { type StoreRequestContext, type StoreRequestInput, recordIdentifierFor, storeFor } from "./store/-private.js";
9
18
  /**
10
19
  * @deprecated use `ReactiveDocument` instead
11
20
  */
12
21
  export type Document<T> = ReactiveDocument<T>;
13
22
  export type { DocumentCacheOperation, CacheOperation, NotificationType } from "./store/-private/managers/notification-manager.js";
14
23
  export { setIdentifierGenerationMethod, setIdentifierUpdateMethod, setIdentifierForgetMethod, setIdentifierResetMethod, setKeyInfoForResource } from "./store/-private/managers/cache-key-manager.js";
24
+ /**
25
+ * Options for setting up a Store instance with `useRecommendedStore`.
26
+ */
27
+ export interface StoreSetupOptions {
28
+ /**
29
+ * The Cache implementation to use
30
+ */
31
+ cache: new (capabilities: CacheCapabilitiesManager) => Cache;
32
+ /**
33
+ * The Cache policy to use.
34
+ *
35
+ * Defaults to {@link DefaultCachePolicy} configured to
36
+ * respect `Expires`, `X-WarpDrive-Expires`, and `Cache-Control` headers
37
+ * with a fallback to 30s soft expiration and 15m hard expiration.
38
+ */
39
+ policy?: CachePolicy;
40
+ /**
41
+ * The request handlers to use. {@link Fetch} will automatically
42
+ * be added to the end of the handler chain and {@link CacheHandler}
43
+ * will automatically be added as the cache handler.
44
+ */
45
+ handlers?: Handler[];
46
+ /**
47
+ * Schemas describing the structure of your resource data.
48
+ *
49
+ * See {@link PolarisResourceSchema,} and {@link ObjectSchema} for more information.
50
+ */
51
+ schemas?: Array<PolarisResourceSchema | ObjectSchema>;
52
+ /**
53
+ * {@link Trait | Traits} to use with {@link PolarisResourceSchema, | Resource Schemas}
54
+ */
55
+ traits?: Trait[];
56
+ /**
57
+ * {@link Derivation | Derivations} to use for derived fields.
58
+ */
59
+ derivations?: Derivation[];
60
+ /**
61
+ * {@link Transformation | Transformations} to use for transforming fields.
62
+ */
63
+ transformations?: Transformation[];
64
+ /**
65
+ * {@link HashFn | Hash Functions} to use for embedded object identity and polymorphic type calculations
66
+ */
67
+ hashFns?: HashFn[];
68
+ /**
69
+ * {@link CAUTION_MEGA_DANGER_ZONE_Extension | Extensions} to use with resources, objects and arrays
70
+ * to provide custom behaviors and capabilities that are not described by Schema.
71
+ *
72
+ * This feature should only be used during a transition period to support migrating towards
73
+ * schemas from existing Model and ModelFragments implementations.
74
+ */
75
+ CAUTION_MEGA_DANGER_ZONE_extensions?: CAUTION_MEGA_DANGER_ZONE_Extension[];
76
+ }
77
+ /**
78
+ * Creates a configured Store class with recommended defaults
79
+ * for schema handling, reactivity, caching, and request management.
80
+ *
81
+ * ```ts
82
+ * import { useRecommendedStore } from '@warp-drive/core';
83
+ * import { JSONAPICache } from '@warp-drive/json-api';
84
+ *
85
+ * export const Store = useRecommendedStore({
86
+ * cache: JSONAPICache,
87
+ * schemas: [],
88
+ * });
89
+ * ```
90
+ */
91
+ export declare function useRecommendedStore(options: StoreSetupOptions, StoreKlass?: typeof Store): typeof Store;
@@ -8,17 +8,22 @@ import type { WithPartial } from "../../types/utils.js";
8
8
  import type { ReactiveResource } from "./record.js";
9
9
  /**
10
10
  * Extensions allow providing non-schema driven behaviors to
11
- * reactive resources and arrays.
11
+ * ReactiveResources, ReactiveArrays, and ReactiveObjects.
12
+ *
13
+ * This should only be used for temporary migration purposes
14
+ * to the new schema system when migrating from either Model
15
+ * or ModelFragments.
12
16
  */
13
17
  export interface CAUTION_MEGA_DANGER_ZONE_Extension {
14
18
  /**
15
19
  * Whether this extension extends the behaviors of objects
16
- * or of arrays.
20
+ * (both ReactiveObjects and ReactiveResources) or of arrays.
17
21
  */
18
22
  kind: "object" | "array";
19
23
  /**
20
24
  * The name of the extension, to be used when specifying
21
- * either `objectExtensions` or `arrayExtensions`
25
+ * either `objectExtensions` or `arrayExtensions` on the
26
+ * field, ResourceSchema or ObjectSchema
22
27
  */
23
28
  name: string;
24
29
  /**
@@ -29,6 +34,74 @@ export interface CAUTION_MEGA_DANGER_ZONE_Extension {
29
34
  *
30
35
  * A constructable such as a Function or Class whose prototype
31
36
  * will be iterated with getOwnPropertyNames.
37
+ *
38
+ * Examples:
39
+ *
40
+ * **An Object with methods**
41
+ *
42
+ * ```ts
43
+ * store.schema.CAUTION_MEGA_DANGER_ZONE_registerExtension({
44
+ * kind: 'object',
45
+ * name: 'do-thing-1',
46
+ * features: {
47
+ * doThingOne(this: { street: string }) {
48
+ * return `do-thing-1:${this.street}`;
49
+ * },
50
+ * doThingTwo(this: { street: string }) {
51
+ * return `do-thing-1:${this.street}`;
52
+ * },
53
+ * },
54
+ * });
55
+ * ```
56
+ *
57
+ * **A class with getters, methods and decorated fields**
58
+ *
59
+ * ```ts
60
+ * class Features {
61
+ * sayHello() {
62
+ * return 'hello!';
63
+ * }
64
+ *
65
+ * @tracked trackedField = 'initial tracked value';
66
+ *
67
+ * get realName() {
68
+ * const self = this as unknown as { name: string };
69
+ * return self.name;
70
+ * }
71
+ * set realName(v: string) {
72
+ * const self = this as unknown as { name: string };
73
+ * self.name = v;
74
+ * }
75
+ *
76
+ * get greeting() {
77
+ * const self = this as unknown as { name: string };
78
+ * return `hello ${self.name}!`;
79
+ * }
80
+ *
81
+ * @computed('name')
82
+ * get salutation() {
83
+ * const self = this as unknown as { name: string };
84
+ * return `salutations ${self.name}!`;
85
+ * }
86
+ *
87
+ * @cached
88
+ * get helloThere() {
89
+ * const self = this as unknown as { name: string };
90
+ * return `Well Hello There ${self.name}!`;
91
+ * }
92
+ * }
93
+ *
94
+ * // non-decorated fields dont appear on class prototypes as they are instance only
95
+ * // @ts-expect-error
96
+ * Features.prototype.untrackedField = 'initial untracked value';
97
+ *
98
+ * store.schema.CAUTION_MEGA_DANGER_ZONE_registerExtension({
99
+ * kind: 'object',
100
+ * name: 'my-ext',
101
+ * features: Features,
102
+ * });
103
+ * ```
104
+ *
32
105
  */
33
106
  features: Record<string | symbol, unknown> | Function;
34
107
  }
@@ -80,7 +153,7 @@ export interface ExtensibleField {
80
153
  * @param schema
81
154
  * @return {PolarisResourceSchema}
82
155
  */
83
- export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">): ResourceSchema;
156
+ export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">): PolarisResourceSchema;
84
157
  interface FromIdentityDerivation {
85
158
  (record: ReactiveResource, options: {
86
159
  key: "lid";
@@ -8,7 +8,7 @@ import type { CacheManager } from "../managers/cache-manager.js";
8
8
  import type { CreateRecordProperties, Store } from "../store-service.js";
9
9
  export declare function peekRecordIdentifier(record: OpaqueRecordInstance): ResourceKey | undefined;
10
10
  /**
11
- Retrieves the unique referentially-stable [RecordIdentifier](/ember-data/release/classes/ResourceKey)
11
+ Retrieves the unique referentially-stable {@link ResourceKey}
12
12
  assigned to the given record instance.
13
13
 
14
14
  ```js
@@ -22,8 +22,7 @@ const { id, type, lid } = identifier;
22
22
  ```
23
23
 
24
24
  @public
25
- @param {Object} record a record instance previously obstained from the store.
26
- @return {ResourceKey}
25
+ @param record a record instance previously obstained from the store.
27
26
  */
28
27
  export declare function recordIdentifierFor<T extends TypedRecordInstance>(record: T): ResourceKey<TypeFromInstance<T>>;
29
28
  export declare function recordIdentifierFor(record: OpaqueRecordInstance): ResourceKey;
@@ -2,6 +2,7 @@ import type { Cache } from "@warp-drive/core/types/cache";
2
2
  import type { RequestKey, ResourceKey } from "@warp-drive/core/types/identifier";
3
3
  import type { ImmutableRequestInfo, ResponseInfo, StructuredDocument } from "@warp-drive/core/types/request";
4
4
  import type { ResourceDocument } from "@warp-drive/core/types/spec/document";
5
+ import type { CachePolicy } from "../-private.js";
5
6
  type UnsubscribeToken = object;
6
7
  type CacheOperation = "added" | "removed" | "updated" | "state";
7
8
  type DocumentCacheOperation = "invalidated" | "added" | "removed" | "updated" | "state";
@@ -28,6 +29,11 @@ type Store = {
28
29
  cache: Cache;
29
30
  notifications: NotificationManager;
30
31
  };
32
+ /**
33
+ * Interface of a parsed Cache-Control header value.
34
+ *
35
+ * - [MDN Cache-Control Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control)
36
+ */
31
37
  export interface CacheControlValue {
32
38
  immutable?: boolean;
33
39
  "max-age"?: number;
@@ -66,24 +72,83 @@ export interface CacheControlValue {
66
72
  * }
67
73
  * ```
68
74
  *
75
+ * See also {@link CacheControlValue} and [Response Directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control#response_directives)
76
+ *
69
77
  * @public
70
- * @param {String} header
71
- * @return {CacheControlValue}
72
78
  */
73
79
  export declare function parseCacheControl(header: string): CacheControlValue;
74
80
  /**
81
+ * The constraint options for {@link PolicyConfig.constraints}
82
+ */
83
+ export interface PolicyConfigConstraints {
84
+ /**
85
+ * Headers that should be checked for expiration.
86
+ *
87
+ */
88
+ headers?: {
89
+ /**
90
+ * Whether the `Cache-Control` header should be checked for expiration.
91
+ * If `true`, then the `max-age` and `s-maxage` directives are used alongside
92
+ * the `Age` and `Date` headers to determine if the expiration time has passed.
93
+ *
94
+ * Other directives are ignored.
95
+ *
96
+ * 'Cache-Control' will take precedence over 'Expires' if both are present
97
+ * and both configured to be checked.
98
+ *
99
+ */
100
+ "Cache-Control"?: boolean;
101
+ /**
102
+ * Whether the `Expires` header should be checked for expiration.
103
+ *
104
+ * If `true`, then the `Expires` header is used to caclulate the expiration time
105
+ * and determine if the expiration time has passed.
106
+ *
107
+ * 'Cache-Control' will take precedence over 'Expires' if both are present.
108
+ *
109
+ */
110
+ Expires?: boolean;
111
+ /**
112
+ * Whether the `X-WarpDrive-Expires` header should be checked for expiration.
113
+ *
114
+ * If `true`, then the `X-WarpDrive-Expires` header is used to caclulate the expiration time
115
+ * and determine if the expiration time has passed.
116
+ *
117
+ * This header will take precedence over 'Cache-Control' and 'Expires' if all three are present.
118
+ *
119
+ * The header's value should be a [UTC date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString).
120
+ *
121
+ */
122
+ "X-WarpDrive-Expires"?: boolean;
123
+ };
124
+ /**
125
+ * A function that should be called to determine if the request is expired.
126
+ *
127
+ * If present, this function will be called with the request and should return
128
+ * `true` if the request is expired, `false` if it is not expired, and
129
+ * `null` if the expiration status is unknown.
130
+ *
131
+ * If the function does not return `null`,
132
+ *
133
+ */
134
+ isExpired?: (request: StructuredDocument<ResourceDocument>) => boolean | null;
135
+ }
136
+ /**
75
137
  * The configuration options for the {@link DefaultCachePolicy}
76
138
  *
77
- * ```ts
78
- * import { DefaultCachePolicy } from '@warp-drive/core/store';
139
+ * ```ts [app/services/store.ts]
140
+ * import { Store } from '@warp-drive/core';
141
+ * import { DefaultCachePolicy } from '@warp-drive/core/store'; // [!code focus]
79
142
  *
80
- * new DefaultCachePolicy({
81
- * // ... PolicyConfig Settings ... //
82
- * });
143
+ * export default class AppStore extends Store {
144
+ * lifetimes = new DefaultCachePolicy({ // [!code focus:3]
145
+ * // ... PolicyConfig Settings ... //
146
+ * });
147
+ * }
83
148
  * ```
84
149
  *
85
150
  */
86
- export type PolicyConfig = {
151
+ export interface PolicyConfig {
87
152
  /**
88
153
  * the number of milliseconds after which a request is considered
89
154
  * stale. If a request is issued again after this time, the request
@@ -92,10 +157,9 @@ export type PolicyConfig = {
92
157
  *
93
158
  * This is calculated against the `date` header of the response.
94
159
  *
95
- * If your API does not provide a `date` header, the `Fetch` handler
96
- * provided by `@warp-drive/core` will automatically add
97
- * it to responses if it is not present. Responses without a `date`
98
- * header will be considered stale immediately.
160
+ * If your API does not provide a `date` header, the {@link Fetch} handler
161
+ * will automatically add it to responses if it is not present. Responses
162
+ * without a `date` header will be considered stale immediately.
99
163
  *
100
164
  */
101
165
  apiCacheSoftExpires: number;
@@ -107,10 +171,9 @@ export type PolicyConfig = {
107
171
  *
108
172
  * This is calculated against the `date` header of the response.
109
173
  *
110
- * If your API does not provide a `date` header, the `Fetch` handler
111
- * provided by `@warp-drive/core` will automatically add
112
- * it to responses if it is not present. Responses without a `date`
113
- * header will be considered hard expired immediately.
174
+ * If your API does not provide a `date` header, the {@link Fetch} handler
175
+ * will automatically add it to responses if it is not present. Responses
176
+ * without a `date` header will be considered hard expired immediately.
114
177
  *
115
178
  */
116
179
  apiCacheHardExpires: number;
@@ -120,8 +183,8 @@ export type PolicyConfig = {
120
183
  *
121
184
  * This helps reduce flakiness and produce predictably rendered results in test suites.
122
185
  *
123
- * Requests that specifically set `cacheOptions.backgroundReload = true` will
124
- * still be background reloaded in tests.
186
+ * Requests that specifically set {@link RequestInfo.cacheOptions.backgroundReload | cacheOptions.backgroundReload }
187
+ * will still be background reloaded in tests.
125
188
  *
126
189
  * This behavior can be opted out of by setting this value to `true`.
127
190
  *
@@ -130,7 +193,7 @@ export type PolicyConfig = {
130
193
  /**
131
194
  * In addition to the simple time-based expiration strategy, CachePolicy
132
195
  * supports various common server-supplied expiration strategies via
133
- * headers, as well as custom expiration strategies via the `isExpired`
196
+ * headers, as well as custom expiration strategies via the {@link PolicyConfigConstraints.isExpired | isExpired}
134
197
  * function.
135
198
  *
136
199
  * Requests will be validated for expiration against these constraints.
@@ -157,118 +220,82 @@ export type PolicyConfig = {
157
220
  * - ↳ (if null) Cache-Control header
158
221
  * - ↳ (if null) Expires header
159
222
  *
223
+ * See {@link PolicyConfigConstraints} for configuration options.
160
224
  */
161
- constraints?: {
162
- /**
163
- * Headers that should be checked for expiration.
164
- *
165
- */
166
- headers?: {
167
- /**
168
- * Whether the `Cache-Control` header should be checked for expiration.
169
- * If `true`, then the `max-age` and `s-maxage` directives are used alongside
170
- * the `Age` and `Date` headers to determine if the expiration time has passed.
171
- *
172
- * Other directives are ignored.
173
- *
174
- * 'Cache-Control' will take precedence over 'Expires' if both are present
175
- * and both configured to be checked.
176
- *
177
- */
178
- "Cache-Control"?: boolean;
179
- /**
180
- * Whether the `Expires` header should be checked for expiration.
181
- *
182
- * If `true`, then the `Expires` header is used to caclulate the expiration time
183
- * and determine if the expiration time has passed.
184
- *
185
- * 'Cache-Control' will take precedence over 'Expires' if both are present.
186
- *
187
- */
188
- Expires?: boolean;
189
- /**
190
- * Whether the `X-WarpDrive-Expires` header should be checked for expiration.
191
- *
192
- * If `true`, then the `X-WarpDrive-Expires` header is used to caclulate the expiration time
193
- * and determine if the expiration time has passed.
194
- *
195
- * This header will take precedence over 'Cache-Control' and 'Expires' if all three are present.
196
- *
197
- * The header's value should be a [UTC date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString).
198
- *
199
- */
200
- "X-WarpDrive-Expires"?: boolean;
201
- };
202
- /**
203
- * A function that should be called to determine if the request is expired.
204
- *
205
- * If present, this function will be called with the request and should return
206
- * `true` if the request is expired, `false` if it is not expired, and
207
- * `null` if the expiration status is unknown.
208
- *
209
- * If the function does not return `null`,
210
- *
211
- */
212
- isExpired?: (request: StructuredDocument<ResourceDocument>) => boolean | null;
213
- };
214
- };
225
+ constraints?: PolicyConfigConstraints;
226
+ }
215
227
  /**
216
- * A basic CachePolicy that can be added to the Store service.
217
- *
218
- * Determines staleness based on time since the request was last received from the API
219
- * using the `date` header.
228
+ * A basic {@link CachePolicy} that can be added to the Store service.
220
229
  *
221
- * Determines expiration based on configured constraints as well as a time based
222
- * expiration strategy based on the `date` header.
223
- *
224
- * In order expiration is determined by:
230
+ * ```ts [app/services/store.ts]
231
+ * import { Store } from '@warp-drive/core';
232
+ * import { DefaultCachePolicy } from '@warp-drive/core/store'; // [!code focus]
225
233
  *
226
- * - Is explicitly invalidated
227
- * - ↳ (if null) isExpired function \<IF Constraint Active>
228
- * - ↳ (if null) X-WarpDrive-Expires header \<IF Constraint Active>
229
- * - ↳ (if null) Cache-Control header \<IF Constraint Active>
230
- * - ↳ (if null) Expires header \<IF Constraint Active>
231
- * - ↳ (if null) Date header + apiCacheHardExpires \< current time
234
+ * export default class AppStore extends Store {
235
+ * lifetimes = new DefaultCachePolicy({ // [!code focus:5]
236
+ * apiCacheSoftExpires: 30_000,
237
+ * apiCacheHardExpires: 60_000,
238
+ * // ... Other PolicyConfig Settings ... //
239
+ * });
240
+ * }
241
+ * ```
232
242
  *
233
- * Invalidates any request for which `cacheOptions.types` was provided when a createRecord
234
- * request for that type is successful.
243
+ * :::tip 💡 TIP
244
+ * Date headers do not have millisecond precision, so expiration times should
245
+ * generally be larger than 1000ms.
246
+ * :::
235
247
  *
236
- * For this to work, the `createRecord` request must include the `cacheOptions.types` array
237
- * with the types that should be invalidated, or its request should specify the ResourceKeys
238
- * of the records that are being created via `records`. Providing both is valid.
248
+ * See also {@link PolicyConfig} for configuration options.
239
249
  *
240
- * > [!NOTE]
241
- * > only requests that had specified `cacheOptions.types` and occurred prior to the
242
- * > createRecord request will be invalidated. This means that a given request should always
243
- * > specify the types that would invalidate it to opt into this behavior. Abstracting this
244
- * > behavior via builders is recommended to ensure consistency.
250
+ * ### The Mechanics
245
251
  *
246
- * This allows the Store's CacheHandler to determine if a request is expired and
247
- * should be refetched upon next request.
252
+ * This policy determines staleness based on various configurable constraints falling back to a simple
253
+ * check of the time elapsed since the request was last received from the API using the `date` header
254
+ * from the last response.
248
255
  *
249
- * The `Fetch` handler provided by `@warp-drive/core` will automatically
256
+ * :::tip 💡 TIP
257
+ * The {@link Fetch} handler provided by `@warp-drive/core` will automatically
250
258
  * add the `date` header to responses if it is not present.
259
+ * :::
251
260
  *
252
- * > [!NOTE]
253
- * > Date headers do not have millisecond precision, so expiration times should
254
- * > generally be larger than 1000ms.
261
+ * - For manual override of reload see {@link CacheOptions.reload | cacheOptions.reload}
262
+ * - For manual override of background reload see {@link CacheOptions.backgroundReload | cacheOptions.backgroundReload}
255
263
  *
256
- * Usage:
264
+ * In order expiration is determined by:
257
265
  *
258
- * ```ts
259
- * import { Store } from '@warp-drive/core';
260
- * import { DefaultCachePolicy } from '@warp-drive/core/store';
266
+ * ```md
267
+ * Is explicitly invalidated by `cacheOptions.reload`
268
+ * (if falsey) if the request has been explicitly invalidated
269
+ * since the last request (see Automatic Invalidation below)
270
+ * ↳ (if false) (If Active) isExpired function
271
+ * ↳ (if null) (If Active) X-WarpDrive-Expires header
272
+ * ↳ (if null) (If Active) Cache-Control header
273
+ * ↳ (if null) (If Active) Expires header
274
+ * ↳ (if null) Date header + apiCacheHardExpires < current time
261
275
  *
262
- * export class AppStore extends Store {
263
- * lifetimes = new DefaultCachePolicy({
264
- * apiCacheSoftExpires: 30_000,
265
- * apiCacheHardExpires: 60_000
266
- * });
267
- * }
276
+ * -- <if above is false, a background request is issued if> --
277
+ *
278
+ * is invalidated by `cacheOptions.backgroundReload`
279
+ * (if falsey) Date header + apiCacheSoftExpires < current time
268
280
  * ```
269
281
  *
270
- * In Testing environments, the `apiCacheSoftExpires` will always be `false`
271
- * and `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.
282
+ * ### Automatic Invalidation / Entanglement
283
+ *
284
+ * It also invalidates any request with an {@link RequestInfo.op | OpCode} of `"query"`
285
+ * for which {@link CacheOptions.types | cacheOptions.types} was provided
286
+ * when a request with an `OpCode` of `"createRecord"` is successful and also includes
287
+ * a matching type in its own `cacheOptions.types` array.
288
+
289
+ * :::tip 💡 TIP
290
+ * Abstracting this behavior via builders is recommended to ensure consistency.
291
+ * :::
292
+ *
293
+ * ### Testing
294
+ *
295
+ * In Testing environments:
296
+ *
297
+ * - `apiCacheSoftExpires` will always be `false`
298
+ * - `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.
272
299
  *
273
300
  * This helps reduce flakiness and produce predictably rendered results in test suites.
274
301
  *
@@ -280,16 +307,7 @@ export type PolicyConfig = {
280
307
  *
281
308
  * @public
282
309
  */
283
- export declare class DefaultCachePolicy {
284
- config: PolicyConfig;
285
- _stores: WeakMap<Store, {
286
- invalidated: Set<RequestKey>;
287
- types: Map<string, Set<RequestKey>>;
288
- }>;
289
- _getStore(store: Store): {
290
- invalidated: Set<RequestKey>;
291
- types: Map<string, Set<RequestKey>>;
292
- };
310
+ export declare class DefaultCachePolicy implements CachePolicy {
293
311
  constructor(config: PolicyConfig);
294
312
  /**
295
313
  * Invalidate a request by its CacheKey for the given store instance.
@@ -314,7 +332,7 @@ export declare class DefaultCachePolicy {
314
332
  * of the store.
315
333
  *
316
334
  * This invalidation is done automatically when using this service
317
- * for both the CacheHandler and the LegacyNetworkHandler.
335
+ * for both the {@link CacheHandler} and the [NetworkHandler](/api/@warp-drive/legacy/compat/variables/LegacyNetworkHandler).
318
336
  *
319
337
  * ```ts
320
338
  * store.lifetimes.invalidateRequestsForType(store, 'person');
@@ -328,7 +346,7 @@ export declare class DefaultCachePolicy {
328
346
  * This is invoked by the CacheHandler for both foreground and background requests
329
347
  * once the cache has been updated.
330
348
  *
331
- * Note, this is invoked by the CacheHandler regardless of whether
349
+ * Note, this is invoked by the {@link CacheHandler} regardless of whether
332
350
  * the request has a cache-key.
333
351
  *
334
352
  * This method should not be invoked directly by consumers.
@@ -340,7 +358,7 @@ export declare class DefaultCachePolicy {
340
358
  * Invoked to determine if the request may be fulfilled from cache
341
359
  * if possible.
342
360
  *
343
- * Note, this is only invoked by the CacheHandler if the request has
361
+ * Note, this is only invoked by the {@link CacheHandler} if the request has
344
362
  * a cache-key.
345
363
  *
346
364
  * If no cache entry is found or the entry is hard expired,
@@ -355,7 +373,7 @@ export declare class DefaultCachePolicy {
355
373
  * Invoked if `isHardExpired` is false to determine if the request
356
374
  * should be update behind the scenes if cache data is already available.
357
375
  *
358
- * Note, this is only invoked by the CacheHandler if the request has
376
+ * Note, this is only invoked by the {@link CacheHandler} if the request has
359
377
  * a cache-key.
360
378
  *
361
379
  * If true, the request will be fulfilled from cache while a backgrounded
@@ -1,6 +1,6 @@
1
1
  import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
2
+ import type { SchemaService } from "../../../types/schema/schema-service.js";
2
3
  import type { CacheCapabilitiesManager as StoreWrapper } from "../../-types/q/cache-capabilities-manager.js";
3
- import type { SchemaService } from "../../-types/q/schema-service.js";
4
4
  import type { PrivateStore, Store } from "../store-service.js";
5
5
  import type { CacheKeyManager } from "./cache-key-manager.js";
6
6
  import type { NotificationType } from "./notification-manager.js";
@@ -256,6 +256,7 @@ export declare function createPromiseState<
256
256
  *
257
257
  * If looking to use in a template, consider also the `<Await />` component.
258
258
  *
259
+ * See also {@link PromiseState}
259
260
  */
260
261
  export declare function getPromiseState<
261
262
  T = unknown,