@warp-drive/core 5.8.0-alpha.5 → 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.
@@ -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;
@@ -153,7 +153,7 @@ export interface ExtensibleField {
153
153
  * @param schema
154
154
  * @return {PolarisResourceSchema}
155
155
  */
156
- export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">): ResourceSchema;
156
+ export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">): PolarisResourceSchema;
157
157
  interface FromIdentityDerivation {
158
158
  (record: ReactiveResource, options: {
159
159
  key: "lid";
@@ -75,11 +75,65 @@ export interface CacheControlValue {
75
75
  * See also {@link CacheControlValue} and [Response Directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control#response_directives)
76
76
  *
77
77
  * @public
78
- * @param {String} header
79
- * @return {CacheControlValue}
80
78
  */
81
79
  export declare function parseCacheControl(header: string): CacheControlValue;
82
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
+ /**
83
137
  * The configuration options for the {@link DefaultCachePolicy}
84
138
  *
85
139
  * ```ts [app/services/store.ts]
@@ -103,10 +157,9 @@ export interface PolicyConfig {
103
157
  *
104
158
  * This is calculated against the `date` header of the response.
105
159
  *
106
- * If your API does not provide a `date` header, the `Fetch` handler
107
- * provided by `@warp-drive/core` will automatically add
108
- * it to responses if it is not present. Responses without a `date`
109
- * 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.
110
163
  *
111
164
  */
112
165
  apiCacheSoftExpires: number;
@@ -118,10 +171,9 @@ export interface PolicyConfig {
118
171
  *
119
172
  * This is calculated against the `date` header of the response.
120
173
  *
121
- * If your API does not provide a `date` header, the `Fetch` handler
122
- * provided by `@warp-drive/core` will automatically add
123
- * it to responses if it is not present. Responses without a `date`
124
- * 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.
125
177
  *
126
178
  */
127
179
  apiCacheHardExpires: number;
@@ -131,8 +183,8 @@ export interface PolicyConfig {
131
183
  *
132
184
  * This helps reduce flakiness and produce predictably rendered results in test suites.
133
185
  *
134
- * Requests that specifically set `cacheOptions.backgroundReload = true` will
135
- * 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.
136
188
  *
137
189
  * This behavior can be opted out of by setting this value to `true`.
138
190
  *
@@ -141,7 +193,7 @@ export interface PolicyConfig {
141
193
  /**
142
194
  * In addition to the simple time-based expiration strategy, CachePolicy
143
195
  * supports various common server-supplied expiration strategies via
144
- * headers, as well as custom expiration strategies via the `isExpired`
196
+ * headers, as well as custom expiration strategies via the {@link PolicyConfigConstraints.isExpired | isExpired}
145
197
  * function.
146
198
  *
147
199
  * Requests will be validated for expiration against these constraints.
@@ -168,60 +220,9 @@ export interface PolicyConfig {
168
220
  * - ↳ (if null) Cache-Control header
169
221
  * - ↳ (if null) Expires header
170
222
  *
223
+ * See {@link PolicyConfigConstraints} for configuration options.
171
224
  */
172
- constraints?: {
173
- /**
174
- * Headers that should be checked for expiration.
175
- *
176
- */
177
- headers?: {
178
- /**
179
- * Whether the `Cache-Control` header should be checked for expiration.
180
- * If `true`, then the `max-age` and `s-maxage` directives are used alongside
181
- * the `Age` and `Date` headers to determine if the expiration time has passed.
182
- *
183
- * Other directives are ignored.
184
- *
185
- * 'Cache-Control' will take precedence over 'Expires' if both are present
186
- * and both configured to be checked.
187
- *
188
- */
189
- "Cache-Control"?: boolean;
190
- /**
191
- * Whether the `Expires` header should be checked for expiration.
192
- *
193
- * If `true`, then the `Expires` header is used to caclulate the expiration time
194
- * and determine if the expiration time has passed.
195
- *
196
- * 'Cache-Control' will take precedence over 'Expires' if both are present.
197
- *
198
- */
199
- Expires?: boolean;
200
- /**
201
- * Whether the `X-WarpDrive-Expires` header should be checked for expiration.
202
- *
203
- * If `true`, then the `X-WarpDrive-Expires` header is used to caclulate the expiration time
204
- * and determine if the expiration time has passed.
205
- *
206
- * This header will take precedence over 'Cache-Control' and 'Expires' if all three are present.
207
- *
208
- * The header's value should be a [UTC date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString).
209
- *
210
- */
211
- "X-WarpDrive-Expires"?: boolean;
212
- };
213
- /**
214
- * A function that should be called to determine if the request is expired.
215
- *
216
- * If present, this function will be called with the request and should return
217
- * `true` if the request is expired, `false` if it is not expired, and
218
- * `null` if the expiration status is unknown.
219
- *
220
- * If the function does not return `null`,
221
- *
222
- */
223
- isExpired?: (request: StructuredDocument<ResourceDocument>) => boolean | null;
224
- };
225
+ constraints?: PolicyConfigConstraints;
225
226
  }
226
227
  /**
227
228
  * A basic {@link CachePolicy} that can be added to the Store service.
@@ -257,8 +258,8 @@ export interface PolicyConfig {
257
258
  * add the `date` header to responses if it is not present.
258
259
  * :::
259
260
  *
260
- * - For manual override of reload see {@link RequestInfo.cacheOptions.reload | cacheOptions.reload}
261
- * - For manual override of background reload see {@link RequestInfo.cacheOptions.backgroundReload | cacheOptions.backgroundReload}
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}
262
263
  *
263
264
  * In order expiration is determined by:
264
265
  *
@@ -281,7 +282,7 @@ export interface PolicyConfig {
281
282
  * ### Automatic Invalidation / Entanglement
282
283
  *
283
284
  * It also invalidates any request with an {@link RequestInfo.op | OpCode} of `"query"`
284
- * for which {@link RequestInfo.cacheOptions.types | cacheOptions.types} was provided
285
+ * for which {@link CacheOptions.types | cacheOptions.types} was provided
285
286
  * when a request with an `OpCode` of `"createRecord"` is successful and also includes
286
287
  * a matching type in its own `cacheOptions.types` array.
287
288
 
@@ -331,7 +332,7 @@ export declare class DefaultCachePolicy implements CachePolicy {
331
332
  * of the store.
332
333
  *
333
334
  * This invalidation is done automatically when using this service
334
- * for both the CacheHandler and the LegacyNetworkHandler.
335
+ * for both the {@link CacheHandler} and the [NetworkHandler](/api/@warp-drive/legacy/compat/variables/LegacyNetworkHandler).
335
336
  *
336
337
  * ```ts
337
338
  * store.lifetimes.invalidateRequestsForType(store, 'person');
@@ -345,7 +346,7 @@ export declare class DefaultCachePolicy implements CachePolicy {
345
346
  * This is invoked by the CacheHandler for both foreground and background requests
346
347
  * once the cache has been updated.
347
348
  *
348
- * Note, this is invoked by the CacheHandler regardless of whether
349
+ * Note, this is invoked by the {@link CacheHandler} regardless of whether
349
350
  * the request has a cache-key.
350
351
  *
351
352
  * This method should not be invoked directly by consumers.
@@ -357,7 +358,7 @@ export declare class DefaultCachePolicy implements CachePolicy {
357
358
  * Invoked to determine if the request may be fulfilled from cache
358
359
  * if possible.
359
360
  *
360
- * 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
361
362
  * a cache-key.
362
363
  *
363
364
  * If no cache entry is found or the entry is hard expired,
@@ -372,7 +373,7 @@ export declare class DefaultCachePolicy implements CachePolicy {
372
373
  * Invoked if `isHardExpired` is false to determine if the request
373
374
  * should be update behind the scenes if cache data is already available.
374
375
  *
375
- * 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
376
377
  * a cache-key.
377
378
  *
378
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 { CacheCapabilitiesManager as StoreWrapper } from "../../-types/q/cache-capabilities-manager.js";
3
2
  import type { SchemaService } from "../../../types/schema/schema-service.js";
3
+ import type { CacheCapabilitiesManager as StoreWrapper } from "../../-types/q/cache-capabilities-manager.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,
@@ -4,11 +4,11 @@ import type { PrivateRequestManager, RequestManager } from "../../request/-priva
4
4
  import type { Cache } from "../../types/cache.js";
5
5
  import type { PersistedResourceKey, ResourceKey } from "../../types/identifier.js";
6
6
  import type { TypedRecordInstance, TypeFromInstance } from "../../types/record.js";
7
+ import type { SchemaService } from "../../types/schema/schema-service.js";
7
8
  import type { CollectionResourceDocument, EmptyResourceDocument, JsonApiDocument, ResourceIdentifierObject, SingleResourceDocument } from "../../types/spec/json-api-raw.js";
8
9
  import type { Type } from "../../types/symbols.js";
9
10
  import type { CacheCapabilitiesManager } from "../-types/q/cache-capabilities-manager.js";
10
11
  import type { OpaqueRecordInstance } from "../-types/q/record-instance.js";
11
- import type { SchemaService } from "../../types/schema/schema-service.js";
12
12
  import type { StoreRequestInput } from "./cache-handler/handler.js";
13
13
  import type { CachePolicy } from "./cache-handler/types.js";
14
14
  import { InstanceCache, storeFor } from "./caches/instance-cache.js";
@@ -1,7 +1,7 @@
1
1
  import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
2
+ import type { SchemaService } from "../../../types/schema/schema-service.js";
2
3
  import type { CacheKeyManager } from "../../-private/managers/cache-key-manager.js";
3
4
  import type { NotificationType } from "../../-private/managers/notification-manager.js";
4
- import type { SchemaService } from "../../../types/schema/schema-service.js";
5
5
  /**
6
6
  * CacheCapabilitiesManager provides encapsulated API access to the minimal
7
7
  * subset of the Store's functionality that Cache implementations
@@ -10,10 +10,11 @@ export declare const IS_FUTURE: "___(unique) Symbol(IS_FUTURE)";
10
10
  export declare const STRUCTURED: "___(unique) Symbol(DOC)";
11
11
  export type HTTPMethod = "QUERY" | "GET" | "OPTIONS" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "CONNECT" | "TRACE";
12
12
  /**
13
- * Use these options to adjust CacheHandler behavior for a request.
13
+ * Use these options to adjust {@link CacheHandler} behavior for a request
14
+ * via {@link RequestInfo.cacheOptions}.
14
15
  *
15
16
  */
16
- export type CacheOptions = {
17
+ export interface CacheOptions {
17
18
  /**
18
19
  * A key that uniquely identifies this request. If not present, the url wil be used
19
20
  * as the key for any GET request, while all other requests will not be cached.
@@ -57,7 +58,7 @@ export type CacheOptions = {
57
58
  *
58
59
  */
59
60
  [SkipCache]?: boolean;
60
- };
61
+ }
61
62
  export type FindRecordRequestOptions<
62
63
  RT = unknown,
63
64
  T = unknown
@@ -2125,18 +2125,29 @@ export interface ObjectSchema {
2125
2125
  objectExtensions?: string[];
2126
2126
  }
2127
2127
  export type Schema = ResourceSchema | ObjectSchema;
2128
+ /**
2129
+ * A trait for use on a PolarisMode record
2130
+ */
2128
2131
  export interface PolarisTrait {
2129
2132
  name: string;
2130
2133
  mode: "polaris";
2131
2134
  fields: PolarisModeFieldSchema[];
2132
2135
  traits?: string[];
2133
2136
  }
2137
+ /**
2138
+ * A trait for use on a LegacyMode record
2139
+ */
2134
2140
  export interface LegacyTrait {
2135
2141
  name: string;
2136
2142
  mode: "legacy";
2137
2143
  fields: LegacyModeFieldSchema[];
2138
2144
  traits?: string[];
2139
2145
  }
2146
+ /**
2147
+ * A union of
2148
+ * - {@link LegacyTrait}
2149
+ * - {@link PolarisTrait}
2150
+ */
2140
2151
  export type Trait = LegacyTrait | PolarisTrait;
2141
2152
  /**
2142
2153
  * A no-op type utility that enables type-checking resource schema
@@ -1 +1 @@
1
- export { setConfig } from '@warp-drive/build-config';
1
+ export { babelPlugin, setConfig } from '@warp-drive/build-config';