@warp-drive/core 5.8.0-alpha.5 → 5.8.0-alpha.7
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/declarations/build-config.d.ts +18 -1
- package/declarations/index.d.ts +80 -3
- package/declarations/reactive/-private/document.d.ts +58 -46
- package/declarations/reactive/-private/schema.d.ts +1 -1
- package/declarations/reactive.d.ts +3 -2
- package/declarations/request.d.ts +25 -0
- package/declarations/store/-private/caches/instance-cache.d.ts +1 -1
- package/declarations/store/-private/default-cache-policy.d.ts +74 -73
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/-private/managers/cache-manager.d.ts +6 -4
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts +1 -0
- package/declarations/store/-private/store-service.d.ts +1 -1
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/deprecated/store.d.ts +1 -1
- package/declarations/types/cache.d.ts +6 -4
- package/declarations/types/request.d.ts +4 -6
- package/declarations/types/schema/fields.d.ts +11 -0
- package/declarations/types/symbols.d.ts +2 -2
- package/dist/build-config.js +1 -1
- package/dist/default-cache-policy-D7_u4YRH.js +572 -0
- package/dist/graph/-private.js +1 -1
- package/dist/{index-MiSBsI57.js → index-BMCk_UD5.js} +10453 -10426
- package/dist/index.js +5 -4
- package/dist/reactive.js +7 -42
- package/dist/{context-C_7OLieY.js → request-CN-dNlEY.js} +193 -173
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -1
- package/dist/store.js +1 -570
- package/dist/types/-private.js +1 -1
- package/dist/types/request.js +3 -5
- package/dist/types/schema/fields.js +14 -0
- package/dist/types/symbols.js +2 -2
- package/package.json +3 -3
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
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 };
|
package/declarations/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
@@ -3,25 +3,13 @@ import type { RequestKey } from "../../types/identifier.js";
|
|
|
3
3
|
import type { ImmutableRequestInfo, RequestInfo } from "../../types/request.js";
|
|
4
4
|
import type { ResourceDocument } from "../../types/spec/document.js";
|
|
5
5
|
import type { Meta, PaginationLinks } from "../../types/spec/json-api-raw.js";
|
|
6
|
-
|
|
7
|
-
* A Document is a class that wraps the response content from a request to the API
|
|
8
|
-
* returned by `Cache.put` or `Cache.peek`, converting ResourceKeys into
|
|
9
|
-
* ReactiveResource instances.
|
|
10
|
-
*
|
|
11
|
-
* It is not directly instantiated by the user, and its properties should not
|
|
12
|
-
* be directly modified. Whether individual properties are mutable or not is
|
|
13
|
-
* determined by the record instance itself.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
* @hideconstructor
|
|
17
|
-
*/
|
|
18
|
-
export declare class ReactiveDocument<T> {
|
|
6
|
+
export interface ReactiveDocumentBase<T> {
|
|
19
7
|
/**
|
|
20
8
|
* The links object for this document, if any
|
|
21
9
|
*
|
|
22
10
|
* e.g.
|
|
23
11
|
*
|
|
24
|
-
* ```
|
|
12
|
+
* ```ts
|
|
25
13
|
* {
|
|
26
14
|
* self: '/articles?page[number]=3',
|
|
27
15
|
* }
|
|
@@ -31,24 +19,6 @@ export declare class ReactiveDocument<T> {
|
|
|
31
19
|
*/
|
|
32
20
|
readonly links?: PaginationLinks;
|
|
33
21
|
/**
|
|
34
|
-
* The primary data for this document, if any.
|
|
35
|
-
*
|
|
36
|
-
* If this document has no primary data (e.g. because it is an error document)
|
|
37
|
-
* this property will be `undefined`.
|
|
38
|
-
*
|
|
39
|
-
* For collections this will be an array of record instances,
|
|
40
|
-
* for single resource requests it will be a single record instance or null.
|
|
41
|
-
*
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
readonly data?: T;
|
|
45
|
-
/**
|
|
46
|
-
* The errors returned by the API for this request, if any
|
|
47
|
-
*
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
readonly errors?: object[];
|
|
51
|
-
/**
|
|
52
22
|
* The meta object for this document, if any
|
|
53
23
|
*
|
|
54
24
|
* @public
|
|
@@ -60,18 +30,12 @@ export declare class ReactiveDocument<T> {
|
|
|
60
30
|
* @public
|
|
61
31
|
*/
|
|
62
32
|
readonly identifier: RequestKey | null;
|
|
63
|
-
constructor(store: Store, cacheKey: RequestKey | null, localCache: {
|
|
64
|
-
document: ResourceDocument;
|
|
65
|
-
request: ImmutableRequestInfo;
|
|
66
|
-
} | null);
|
|
67
33
|
/**
|
|
68
34
|
* Fetches the related link for this document, returning a promise that resolves
|
|
69
35
|
* with the document when the request completes. If no related link is present,
|
|
70
36
|
* will fallback to the self link if present
|
|
71
37
|
*
|
|
72
38
|
* @public
|
|
73
|
-
* @param {Object} options
|
|
74
|
-
* @return {Promise<Document>}
|
|
75
39
|
*/
|
|
76
40
|
fetch(options?: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T>>;
|
|
77
41
|
/**
|
|
@@ -80,8 +44,6 @@ export declare class ReactiveDocument<T> {
|
|
|
80
44
|
* next link.
|
|
81
45
|
*
|
|
82
46
|
* @public
|
|
83
|
-
* @param {Object} options
|
|
84
|
-
* @return {Promise<Document | null>}
|
|
85
47
|
*/
|
|
86
48
|
next(options?: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
87
49
|
/**
|
|
@@ -90,8 +52,6 @@ export declare class ReactiveDocument<T> {
|
|
|
90
52
|
* prev link.
|
|
91
53
|
*
|
|
92
54
|
* @public
|
|
93
|
-
* @param {Object} options
|
|
94
|
-
* @return {Promise<Document | null>}
|
|
95
55
|
*/
|
|
96
56
|
prev(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
97
57
|
/**
|
|
@@ -100,8 +60,6 @@ export declare class ReactiveDocument<T> {
|
|
|
100
60
|
* first link.
|
|
101
61
|
*
|
|
102
62
|
* @public
|
|
103
|
-
* @param {Object} options
|
|
104
|
-
* @return {Promise<Document | null>}
|
|
105
63
|
*/
|
|
106
64
|
first(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
107
65
|
/**
|
|
@@ -110,8 +68,6 @@ export declare class ReactiveDocument<T> {
|
|
|
110
68
|
* last link.
|
|
111
69
|
*
|
|
112
70
|
* @public
|
|
113
|
-
* @param {Object} options
|
|
114
|
-
* @return {Promise<Document | null>}
|
|
115
71
|
*/
|
|
116
72
|
last(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
|
|
117
73
|
/**
|
|
@@ -128,3 +84,59 @@ export declare class ReactiveDocument<T> {
|
|
|
128
84
|
*/
|
|
129
85
|
toJSON(): object;
|
|
130
86
|
}
|
|
87
|
+
export interface ReactiveErrorDocument<T> extends ReactiveDocumentBase<T> {
|
|
88
|
+
/**
|
|
89
|
+
* The primary data for this document, if any.
|
|
90
|
+
*
|
|
91
|
+
* If this document has no primary data (e.g. because it is an error document)
|
|
92
|
+
* this property will be `undefined`.
|
|
93
|
+
*
|
|
94
|
+
* For collections this will be an array of record instances,
|
|
95
|
+
* for single resource requests it will be a single record instance or null.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
readonly data?: undefined;
|
|
100
|
+
/**
|
|
101
|
+
* The errors returned by the API for this request, if any
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
readonly errors: object[];
|
|
106
|
+
}
|
|
107
|
+
export interface ReactiveDataDocument<T> extends ReactiveDocumentBase<T> {
|
|
108
|
+
/**
|
|
109
|
+
* The primary data for this document, if any.
|
|
110
|
+
*
|
|
111
|
+
* If this document has no primary data (e.g. because it is an error document)
|
|
112
|
+
* this property will be `undefined`.
|
|
113
|
+
*
|
|
114
|
+
* For collections this will be an array of record instances,
|
|
115
|
+
* for single resource requests it will be a single record instance or null.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
readonly data: T;
|
|
120
|
+
/**
|
|
121
|
+
* The errors returned by the API for this request, if any
|
|
122
|
+
*
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
readonly errors?: undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A Document is a class that wraps the response content from a request to the API
|
|
129
|
+
* returned by `Cache.put` or `Cache.peek`, converting ResourceKeys into
|
|
130
|
+
* ReactiveResource instances.
|
|
131
|
+
*
|
|
132
|
+
* It is not directly instantiated by the user, and its properties should not
|
|
133
|
+
* be directly modified. Whether individual properties are mutable or not is
|
|
134
|
+
* determined by the record instance itself.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export type ReactiveDocument<T> = ReactiveDataDocument<T> | ReactiveErrorDocument<T>;
|
|
139
|
+
export declare function createReactiveDocument<T>(store: Store, cacheKey: RequestKey | null, localCache: {
|
|
140
|
+
document: ResourceDocument;
|
|
141
|
+
request: ImmutableRequestInfo;
|
|
142
|
+
} | null): ReactiveDocument<T>;
|
|
@@ -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">):
|
|
156
|
+
export declare function withDefaults(schema: WithPartial<PolarisResourceSchema, "identity">): PolarisResourceSchema;
|
|
157
157
|
interface FromIdentityDerivation {
|
|
158
158
|
(record: ReactiveResource, options: {
|
|
159
159
|
key: "lid";
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
* The shape of the object and the transformation of raw cache data into its
|
|
56
56
|
* reactive form is controlled by a resource schema.
|
|
57
57
|
*
|
|
58
|
-
* For instance, lets say your API is a [{
|
|
58
|
+
* For instance, lets say your API is a [{json:api}](https://jsonapi.org) and your store is using
|
|
59
59
|
* the Cache provided by [@warp-drive/json-api](/api/@warp-drive/json-api), and a request
|
|
60
60
|
* returns the following raw data:
|
|
61
61
|
*
|
|
@@ -277,5 +277,6 @@ export { type CAUTION_MEGA_DANGER_ZONE_Extension, type ProcessedExtension, type
|
|
|
277
277
|
export { commit, type ReactiveResource } from "./reactive/-private/record.js";
|
|
278
278
|
export { checkout };
|
|
279
279
|
export { Checkout } from "./reactive/-private/symbols.js";
|
|
280
|
-
export { type ReactiveDocument } from "./reactive/-private/document.js";
|
|
280
|
+
export { type ReactiveDocument, type ReactiveDataDocument, type ReactiveErrorDocument } from "./reactive/-private/document.js";
|
|
281
281
|
export { getExpensiveRequestSubscription } from "./store/-private/new-core-tmp/expensive-subscription.js";
|
|
282
|
+
export { createRequestSubscription, getRequestState, getPromiseState, type PromiseState, type RequestState } from "./store/-private.js";
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import type { RequestInfo } from "./types/request.js";
|
|
2
|
+
import type { RequestSignature } from "./types/symbols.js";
|
|
1
3
|
export { createDeferred } from "./request/-private/future.js";
|
|
2
4
|
export type { Future, Handler, CacheHandler, NextFn, Deferred, ManagedRequestPriority } from "./request/-private/types.js";
|
|
3
5
|
export { setPromiseResult, getPromiseResult } from "./request/-private/promise-cache.js";
|
|
4
6
|
export type { Awaitable } from "./request/-private/promise-cache.js";
|
|
5
7
|
export type { Context } from "./request/-private/context.js";
|
|
8
|
+
/**
|
|
9
|
+
* Brands the supplied object with the supplied response type.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { ReactiveDataDocument } from '@warp-drive/core/reactive';
|
|
13
|
+
* import { withResponseType } from '@warp-drive/core/request';
|
|
14
|
+
* import type { User } from '#/data/user.ts'
|
|
15
|
+
*
|
|
16
|
+
* const result = await store.request(
|
|
17
|
+
* withResponseType<ReactiveDataDocument<User>>({ url: '/users/1' })
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* result.content.data; // will have type User
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export declare function withResponseType<T>(obj: RequestInfo): RequestInfo<T> & {
|
|
25
|
+
[RequestSignature]: T;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use {@link withResponseType} instead
|
|
29
|
+
*/
|
|
30
|
+
export { withResponseType as withBrand };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactiveDocument } from "../../../reactive/-private/document.js";
|
|
1
|
+
import { type ReactiveDocument } from "../../../reactive/-private/document.js";
|
|
2
2
|
import type { Cache } from "../../../types/cache.js";
|
|
3
3
|
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
4
4
|
import type { TypedRecordInstance, TypeFromInstance } from "../../../types/record.js";
|
|
@@ -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
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
|
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
|
|
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
|
|
261
|
-
* - For manual override of background reload see {@link
|
|
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
|
|
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";
|
|
@@ -6,7 +6,7 @@ import type { LocalRelationshipOperation } from "../../../types/graph.js";
|
|
|
6
6
|
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
7
7
|
import type { Value } from "../../../types/json/raw.js";
|
|
8
8
|
import type { StructuredDataDocument, StructuredDocument } from "../../../types/request.js";
|
|
9
|
-
import type { ResourceDocument, SingleResourceDataDocument } from "../../../types/spec/document.js";
|
|
9
|
+
import type { CollectionResourceDataDocument, ResourceDocument, SingleResourceDataDocument } from "../../../types/spec/document.js";
|
|
10
10
|
import type { ApiError } from "../../../types/spec/error.js";
|
|
11
11
|
import type { StoreRequestContext } from "../cache-handler/handler.js";
|
|
12
12
|
/**
|
|
@@ -220,21 +220,23 @@ export declare class CacheManager implements Cache {
|
|
|
220
220
|
* @public
|
|
221
221
|
* @param key
|
|
222
222
|
*/
|
|
223
|
-
willCommit(key: ResourceKey, context: StoreRequestContext): void;
|
|
223
|
+
willCommit(key: ResourceKey | ResourceKey[], context: StoreRequestContext): void;
|
|
224
224
|
/**
|
|
225
225
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
226
226
|
* was successfully updated as part of a save transaction.
|
|
227
227
|
*
|
|
228
228
|
* @public
|
|
229
229
|
*/
|
|
230
|
-
didCommit(key: ResourceKey, result: StructuredDataDocument<
|
|
230
|
+
didCommit(key: ResourceKey, result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
231
|
+
didCommit(key: ResourceKey[], result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
232
|
+
didCommit(key: ResourceKey[], result: StructuredDataDocument<CollectionResourceDataDocument> | null): CollectionResourceDataDocument;
|
|
231
233
|
/**
|
|
232
234
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
233
235
|
* was update via a save transaction failed.
|
|
234
236
|
*
|
|
235
237
|
* @public
|
|
236
238
|
*/
|
|
237
|
-
commitWasRejected(key: ResourceKey, errors?: ApiError[]): void;
|
|
239
|
+
commitWasRejected(key: ResourceKey | ResourceKey[], errors?: ApiError[]): void;
|
|
238
240
|
/**
|
|
239
241
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
240
242
|
* should be cleared.
|
|
@@ -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
|
|
@@ -254,7 +254,7 @@ declare module "../-private/store-service" {
|
|
|
254
254
|
|
|
255
255
|
If you use an adapter such as the
|
|
256
256
|
[JSONAPIAdapter](/api/@warp-drive/legacy/adapter/json-api/classes/JSONAPIAdapter)
|
|
257
|
-
which supports the [{
|
|
257
|
+
which supports the [{json:api} specification](http://jsonapi.org/) and if your server
|
|
258
258
|
endpoint supports the use of an
|
|
259
259
|
['include' query parameter](http://jsonapi.org/format/#fetching-includes),
|
|
260
260
|
you can use `findRecord()` or `findAll()` to automatically retrieve additional records related to
|