@warp-drive/core 5.8.0-alpha.4 → 5.8.0-alpha.5
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 +1 -1
- package/declarations/reactive/-private/schema.d.ts +76 -3
- package/declarations/store/-private/caches/instance-cache.d.ts +2 -3
- package/declarations/store/-private/default-cache-policy.d.ts +76 -59
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/-private/store-service.d.ts +41 -62
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/deprecated/store.d.ts +32 -31
- package/declarations/{store/-types/q → types/schema}/schema-service.d.ts +11 -9
- package/declarations/types.d.ts +1 -1
- package/dist/{request-state-CUuZzgvE.js → index-MiSBsI57.js} +4497 -3402
- package/dist/index.js +4 -381
- package/dist/reactive.js +4 -743
- package/dist/store/-private.js +1 -1
- package/dist/store.js +84 -47
- package/dist/types/-private.js +1 -1
- package/dist/types/schema/schema-service.js +0 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
[](https://api.emberjs.com/ember-data/release)
|
|
20
20
|
[](https://discord.gg/zT3asNS
|
|
21
21
|
)
|
|
22
|
-
[](https://discord.gg/
|
|
22
|
+
[](https://discord.gg/PHBbnWJx5S
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
|
|
@@ -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
|
-
*
|
|
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
|
}
|
|
@@ -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
|
|
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
|
|
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,6 +72,8 @@ 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
78
|
* @param {String} header
|
|
71
79
|
* @return {CacheControlValue}
|
|
@@ -74,16 +82,19 @@ export declare function parseCacheControl(header: string): CacheControlValue;
|
|
|
74
82
|
/**
|
|
75
83
|
* The configuration options for the {@link DefaultCachePolicy}
|
|
76
84
|
*
|
|
77
|
-
* ```ts
|
|
78
|
-
* import {
|
|
85
|
+
* ```ts [app/services/store.ts]
|
|
86
|
+
* import { Store } from '@warp-drive/core';
|
|
87
|
+
* import { DefaultCachePolicy } from '@warp-drive/core/store'; // [!code focus]
|
|
79
88
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
89
|
+
* export default class AppStore extends Store {
|
|
90
|
+
* lifetimes = new DefaultCachePolicy({ // [!code focus:3]
|
|
91
|
+
* // ... PolicyConfig Settings ... //
|
|
92
|
+
* });
|
|
93
|
+
* }
|
|
83
94
|
* ```
|
|
84
95
|
*
|
|
85
96
|
*/
|
|
86
|
-
export
|
|
97
|
+
export interface PolicyConfig {
|
|
87
98
|
/**
|
|
88
99
|
* the number of milliseconds after which a request is considered
|
|
89
100
|
* stale. If a request is issued again after this time, the request
|
|
@@ -211,64 +222,79 @@ export type PolicyConfig = {
|
|
|
211
222
|
*/
|
|
212
223
|
isExpired?: (request: StructuredDocument<ResourceDocument>) => boolean | null;
|
|
213
224
|
};
|
|
214
|
-
}
|
|
225
|
+
}
|
|
215
226
|
/**
|
|
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.
|
|
220
|
-
*
|
|
221
|
-
* Determines expiration based on configured constraints as well as a time based
|
|
222
|
-
* expiration strategy based on the `date` header.
|
|
227
|
+
* A basic {@link CachePolicy} that can be added to the Store service.
|
|
223
228
|
*
|
|
224
|
-
*
|
|
229
|
+
* ```ts [app/services/store.ts]
|
|
230
|
+
* import { Store } from '@warp-drive/core';
|
|
231
|
+
* import { DefaultCachePolicy } from '@warp-drive/core/store'; // [!code focus]
|
|
225
232
|
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
233
|
+
* export default class AppStore extends Store {
|
|
234
|
+
* lifetimes = new DefaultCachePolicy({ // [!code focus:5]
|
|
235
|
+
* apiCacheSoftExpires: 30_000,
|
|
236
|
+
* apiCacheHardExpires: 60_000,
|
|
237
|
+
* // ... Other PolicyConfig Settings ... //
|
|
238
|
+
* });
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
232
241
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
242
|
+
* :::tip 💡 TIP
|
|
243
|
+
* Date headers do not have millisecond precision, so expiration times should
|
|
244
|
+
* generally be larger than 1000ms.
|
|
245
|
+
* :::
|
|
235
246
|
*
|
|
236
|
-
*
|
|
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.
|
|
247
|
+
* See also {@link PolicyConfig} for configuration options.
|
|
239
248
|
*
|
|
240
|
-
*
|
|
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.
|
|
249
|
+
* ### The Mechanics
|
|
245
250
|
*
|
|
246
|
-
* This
|
|
247
|
-
*
|
|
251
|
+
* This policy determines staleness based on various configurable constraints falling back to a simple
|
|
252
|
+
* check of the time elapsed since the request was last received from the API using the `date` header
|
|
253
|
+
* from the last response.
|
|
248
254
|
*
|
|
249
|
-
*
|
|
255
|
+
* :::tip 💡 TIP
|
|
256
|
+
* The {@link Fetch} handler provided by `@warp-drive/core` will automatically
|
|
250
257
|
* add the `date` header to responses if it is not present.
|
|
258
|
+
* :::
|
|
251
259
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* > generally be larger than 1000ms.
|
|
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}
|
|
255
262
|
*
|
|
256
|
-
*
|
|
263
|
+
* In order expiration is determined by:
|
|
257
264
|
*
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
*
|
|
265
|
+
* ```md
|
|
266
|
+
* Is explicitly invalidated by `cacheOptions.reload`
|
|
267
|
+
* ↳ (if falsey) if the request has been explicitly invalidated
|
|
268
|
+
* since the last request (see Automatic Invalidation below)
|
|
269
|
+
* ↳ (if false) (If Active) isExpired function
|
|
270
|
+
* ↳ (if null) (If Active) X-WarpDrive-Expires header
|
|
271
|
+
* ↳ (if null) (If Active) Cache-Control header
|
|
272
|
+
* ↳ (if null) (If Active) Expires header
|
|
273
|
+
* ↳ (if null) Date header + apiCacheHardExpires < current time
|
|
261
274
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* });
|
|
267
|
-
* }
|
|
275
|
+
* -- <if above is false, a background request is issued if> --
|
|
276
|
+
*
|
|
277
|
+
* ↳ is invalidated by `cacheOptions.backgroundReload`
|
|
278
|
+
* ↳ (if falsey) Date header + apiCacheSoftExpires < current time
|
|
268
279
|
* ```
|
|
269
280
|
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
281
|
+
* ### Automatic Invalidation / Entanglement
|
|
282
|
+
*
|
|
283
|
+
* 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
|
+
* when a request with an `OpCode` of `"createRecord"` is successful and also includes
|
|
286
|
+
* a matching type in its own `cacheOptions.types` array.
|
|
287
|
+
|
|
288
|
+
* :::tip 💡 TIP
|
|
289
|
+
* Abstracting this behavior via builders is recommended to ensure consistency.
|
|
290
|
+
* :::
|
|
291
|
+
*
|
|
292
|
+
* ### Testing
|
|
293
|
+
*
|
|
294
|
+
* In Testing environments:
|
|
295
|
+
*
|
|
296
|
+
* - `apiCacheSoftExpires` will always be `false`
|
|
297
|
+
* - `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.
|
|
272
298
|
*
|
|
273
299
|
* This helps reduce flakiness and produce predictably rendered results in test suites.
|
|
274
300
|
*
|
|
@@ -280,16 +306,7 @@ export type PolicyConfig = {
|
|
|
280
306
|
*
|
|
281
307
|
* @public
|
|
282
308
|
*/
|
|
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
|
-
};
|
|
309
|
+
export declare class DefaultCachePolicy implements CachePolicy {
|
|
293
310
|
constructor(config: PolicyConfig);
|
|
294
311
|
/**
|
|
295
312
|
* Invalidate a request by its CacheKey for the given store instance.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { CacheCapabilitiesManager as StoreWrapper } from "../../-types/q/cache-capabilities-manager.js";
|
|
3
|
-
import type { SchemaService } from "
|
|
3
|
+
import type { SchemaService } from "../../../types/schema/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";
|
|
@@ -8,7 +8,7 @@ import type { CollectionResourceDocument, EmptyResourceDocument, JsonApiDocument
|
|
|
8
8
|
import type { Type } from "../../types/symbols.js";
|
|
9
9
|
import type { CacheCapabilitiesManager } from "../-types/q/cache-capabilities-manager.js";
|
|
10
10
|
import type { OpaqueRecordInstance } from "../-types/q/record-instance.js";
|
|
11
|
-
import type { SchemaService } from "
|
|
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";
|
|
@@ -101,7 +101,7 @@ export interface Store {
|
|
|
101
101
|
* For Example, to use the default SchemaService for ReactiveResource
|
|
102
102
|
*
|
|
103
103
|
* ```ts
|
|
104
|
-
* import { SchemaService } from '@warp-drive/
|
|
104
|
+
* import { SchemaService } from '@warp-drive/core/reactive';
|
|
105
105
|
*
|
|
106
106
|
* class extends Store {
|
|
107
107
|
* createSchemaService() {
|
|
@@ -110,10 +110,10 @@ export interface Store {
|
|
|
110
110
|
* }
|
|
111
111
|
* ```
|
|
112
112
|
*
|
|
113
|
-
* Or to use the SchemaService for @
|
|
113
|
+
* Or to use the SchemaService for @warp-drive/legacy/model
|
|
114
114
|
*
|
|
115
115
|
* ```ts
|
|
116
|
-
* import { buildSchema } from '@
|
|
116
|
+
* import { buildSchema } from '@warp-drive/legacy/model';
|
|
117
117
|
*
|
|
118
118
|
* class extends Store {
|
|
119
119
|
* createSchemaService() {
|
|
@@ -125,13 +125,13 @@ export interface Store {
|
|
|
125
125
|
* If you wish to chain services, you must either
|
|
126
126
|
* instantiate each schema source directly or super to retrieve
|
|
127
127
|
* an existing service. For convenience, when migrating from
|
|
128
|
-
* `@
|
|
128
|
+
* `@warp-drive/legacy/model` to {@link ReactiveResource} a
|
|
129
129
|
* SchemaService is provided that handles this transition
|
|
130
130
|
* for you:
|
|
131
131
|
*
|
|
132
132
|
* ```ts
|
|
133
|
-
* import { DelegatingSchemaService } from '@
|
|
134
|
-
* import { SchemaService } from '@warp-drive/
|
|
133
|
+
* import { DelegatingSchemaService } from '@warp-drive/legacy/model/migration-support';
|
|
134
|
+
* import { SchemaService } from '@warp-drive/core/reactive';
|
|
135
135
|
*
|
|
136
136
|
* class extends Store {
|
|
137
137
|
* createSchemaService() {
|
|
@@ -176,7 +176,7 @@ export interface Store {
|
|
|
176
176
|
* For Example:
|
|
177
177
|
*
|
|
178
178
|
* ```ts
|
|
179
|
-
* import Store from '@
|
|
179
|
+
* import { Store } from '@warp-drive/core';
|
|
180
180
|
*
|
|
181
181
|
* class SchemaDelegator {
|
|
182
182
|
* constructor(schema) {
|
|
@@ -210,7 +210,6 @@ export interface Store {
|
|
|
210
210
|
* }
|
|
211
211
|
* ```
|
|
212
212
|
*
|
|
213
|
-
* @param {SchemaService} schema
|
|
214
213
|
* @deprecated
|
|
215
214
|
* @public
|
|
216
215
|
*/
|
|
@@ -230,7 +229,7 @@ export interface Store {
|
|
|
230
229
|
* For Example:
|
|
231
230
|
*
|
|
232
231
|
* ```ts
|
|
233
|
-
* import Store from '@
|
|
232
|
+
* import { Store } from '@warp-drive/core';
|
|
234
233
|
*
|
|
235
234
|
* class SchemaDelegator {
|
|
236
235
|
* constructor(schema) {
|
|
@@ -264,7 +263,6 @@ export interface Store {
|
|
|
264
263
|
* }
|
|
265
264
|
* ```
|
|
266
265
|
*
|
|
267
|
-
* @param {SchemaService} schema
|
|
268
266
|
* @deprecated
|
|
269
267
|
* @public
|
|
270
268
|
*/
|
|
@@ -321,20 +319,18 @@ export declare class Store extends BaseClass {
|
|
|
321
319
|
*/
|
|
322
320
|
readonly cacheKeyManager: CacheKeyManager;
|
|
323
321
|
/**
|
|
324
|
-
* Provides access to the
|
|
322
|
+
* Provides access to the {@link RequestManager} instance associated
|
|
325
323
|
* with this Store instance.
|
|
326
324
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
325
|
+
* See also:
|
|
326
|
+
* - {@link Fetch}
|
|
327
|
+
* - {@link CacheHandlerInterface | CacheHandler (Interface)}
|
|
328
|
+
* - {@link CacheHandler | CacheHandler (Class)}
|
|
331
329
|
*
|
|
332
330
|
* ```ts
|
|
333
|
-
* import
|
|
334
|
-
* import RequestManager from '@ember-data/request';
|
|
335
|
-
* import Fetch from '@ember-data/request/fetch';
|
|
331
|
+
* import { CacheHandler, Fetch, RequestManager, Store } from '@warp-drive/core';
|
|
336
332
|
*
|
|
337
|
-
* class extends Store {
|
|
333
|
+
* class AppStore extends Store {
|
|
338
334
|
* requestManager = new RequestManager()
|
|
339
335
|
* .use([Fetch])
|
|
340
336
|
* .useCache(CacheHandler);
|
|
@@ -350,9 +346,9 @@ export declare class Store extends BaseClass {
|
|
|
350
346
|
*
|
|
351
347
|
* Note, when defined, these methods will only be invoked if a
|
|
352
348
|
* cache key exists for the request, either because the request
|
|
353
|
-
* contains `cacheOptions.key` or because the
|
|
349
|
+
* contains `cacheOptions.key` or because the {@link CacheKeyManager}
|
|
354
350
|
* was able to generate a key for the request using the configured
|
|
355
|
-
*
|
|
351
|
+
* {@link setIdentifierGenerationMethod | generation method}.
|
|
356
352
|
*
|
|
357
353
|
* `isSoftExpired` will only be invoked if `isHardExpired` returns `false`.
|
|
358
354
|
*
|
|
@@ -557,14 +553,10 @@ export declare class Store extends BaseClass {
|
|
|
557
553
|
otherwise it will return `null`. A record is available if it has been fetched earlier, or
|
|
558
554
|
pushed manually into the store.
|
|
559
555
|
|
|
560
|
-
See [findRecord](../methods/findRecord?anchor=findRecord) if you would like to request this record from the backend.
|
|
561
|
-
|
|
562
|
-
_Note: This is a synchronous method and does not return a promise._
|
|
563
|
-
|
|
564
556
|
**Example 1**
|
|
565
557
|
|
|
566
|
-
```
|
|
567
|
-
|
|
558
|
+
```ts
|
|
559
|
+
const post = store.peekRecord('post', '1');
|
|
568
560
|
|
|
569
561
|
post.id; // '1'
|
|
570
562
|
```
|
|
@@ -575,8 +567,8 @@ export declare class Store extends BaseClass {
|
|
|
575
567
|
|
|
576
568
|
**Example 2**
|
|
577
569
|
|
|
578
|
-
```
|
|
579
|
-
|
|
570
|
+
```ts
|
|
571
|
+
const post = store.peekRecord({ type: 'post', id: '1' });
|
|
580
572
|
post.id; // '1'
|
|
581
573
|
```
|
|
582
574
|
|
|
@@ -590,40 +582,34 @@ export declare class Store extends BaseClass {
|
|
|
590
582
|
post.id; // '1'
|
|
591
583
|
```
|
|
592
584
|
|
|
593
|
-
|
|
594
585
|
@since 1.13.0
|
|
595
586
|
@public
|
|
596
|
-
@param
|
|
597
|
-
@param
|
|
598
|
-
@return {Model|null} record
|
|
587
|
+
@param type - either a string representing the modelName or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
|
|
588
|
+
@param id - optional only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved.
|
|
599
589
|
*/
|
|
600
590
|
peekRecord<T>(type: TypeFromInstance<T>, id: string | number): T | null;
|
|
601
591
|
peekRecord(type: string, id: string | number): unknown | null;
|
|
602
592
|
peekRecord<T>(identifier: ResourceIdentifierObject<TypeFromInstance<T>>): T | null;
|
|
603
593
|
peekRecord(identifier: ResourceIdentifierObject): unknown | null;
|
|
604
594
|
/**
|
|
605
|
-
This method returns
|
|
606
|
-
known records for a given type in the store.
|
|
595
|
+
This method returns the {@link LegacyLiveArray} that contains all of the
|
|
596
|
+
known records for a given type in the store. Each ResourceType has only
|
|
597
|
+
one LiveArray instance, so multiple calls to `peekAll` with the same type
|
|
598
|
+
will always return the same instance.
|
|
607
599
|
|
|
608
|
-
Note that because it's
|
|
600
|
+
Note that because it's a LiveArray, the result will contain any
|
|
609
601
|
locally created records of the type, however, it will not make a
|
|
610
|
-
request to the backend to retrieve additional records.
|
|
611
|
-
would like to request all the records from the backend please use
|
|
612
|
-
[store.findAll](../methods/findAll?anchor=findAll).
|
|
613
|
-
|
|
614
|
-
Also note that multiple calls to `peekAll` for a given type will always
|
|
615
|
-
return the same `RecordArray`.
|
|
602
|
+
request to the backend to retrieve additional records.
|
|
616
603
|
|
|
617
604
|
Example
|
|
618
605
|
|
|
619
|
-
```
|
|
620
|
-
|
|
606
|
+
```ts
|
|
607
|
+
const allPosts = store.peekAll('post');
|
|
621
608
|
```
|
|
622
609
|
|
|
623
610
|
@since 1.13.0
|
|
624
611
|
@public
|
|
625
|
-
@param
|
|
626
|
-
@return {RecordArray}
|
|
612
|
+
@param type the name of the resource
|
|
627
613
|
*/
|
|
628
614
|
peekAll<T>(type: TypeFromInstance<T>): LegacyLiveArray<T>;
|
|
629
615
|
peekAll(type: string): LegacyLiveArray;
|
|
@@ -708,7 +694,7 @@ export declare class Store extends BaseClass {
|
|
|
708
694
|
For this model:
|
|
709
695
|
|
|
710
696
|
```js [app/models/person.js]
|
|
711
|
-
import Model, { attr, hasMany } from '@
|
|
697
|
+
import Model, { attr, hasMany } from '@warp-drive/legacy/model';
|
|
712
698
|
|
|
713
699
|
export default class PersonRoute extends Route {
|
|
714
700
|
@attr('string') firstName;
|
|
@@ -775,23 +761,17 @@ export declare class Store extends BaseClass {
|
|
|
775
761
|
}
|
|
776
762
|
```
|
|
777
763
|
|
|
778
|
-
If you're streaming data or implementing
|
|
779
|
-
that you have converted the incoming data into this form.
|
|
780
|
-
store's [normalize](../methods/normalize?anchor=normalize) method is a convenience
|
|
781
|
-
helper for converting a json payload into the form Ember Data
|
|
782
|
-
expects.
|
|
783
|
-
|
|
784
|
-
```js
|
|
785
|
-
store.push(store.normalize('person', data));
|
|
786
|
-
```
|
|
764
|
+
If you're streaming data, or implementing response handling, make sure
|
|
765
|
+
that you have converted the incoming data into this form.
|
|
787
766
|
|
|
788
767
|
This method can be used both to push in brand new
|
|
789
768
|
records, as well as to update existing records.
|
|
790
769
|
|
|
770
|
+
See also {@link Cache.patch}
|
|
771
|
+
|
|
791
772
|
@public
|
|
792
|
-
@param
|
|
793
|
-
@return the record(s) that
|
|
794
|
-
updated.
|
|
773
|
+
@param data
|
|
774
|
+
@return the primary record(s) that created or updated.
|
|
795
775
|
*/
|
|
796
776
|
push(data: EmptyResourceDocument): null;
|
|
797
777
|
push<T>(data: SingleResourceDocument<TypeFromInstance<T>>): T;
|
|
@@ -803,8 +783,7 @@ export declare class Store extends BaseClass {
|
|
|
803
783
|
without creating materialized records.
|
|
804
784
|
|
|
805
785
|
@private
|
|
806
|
-
@
|
|
807
|
-
@return {ResourceKey|Array<ResourceKey>|null} identifiers for the primary records that had data loaded
|
|
786
|
+
@return identifiers for the primary records that had data loaded
|
|
808
787
|
*/
|
|
809
788
|
_push(jsonApiDoc: JsonApiDocument, asyncFlush?: boolean): PersistedResourceKey | PersistedResourceKey[] | null;
|
|
810
789
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { CacheKeyManager } from "../../-private/managers/cache-key-manager.js";
|
|
3
3
|
import type { NotificationType } from "../../-private/managers/notification-manager.js";
|
|
4
|
-
import type { SchemaService } from "
|
|
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
|