@warp-drive/core 5.6.0-beta.1 → 5.6.0-beta.3
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/graph/-private/-diff.d.ts +7 -20
- package/declarations/graph/-private/-edge-definition.d.ts +3 -12
- package/declarations/graph/-private/-state.d.ts +0 -87
- package/declarations/graph/-private/-utils.d.ts +5 -11
- package/declarations/graph/-private/coerce-id.d.ts +0 -6
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
- package/declarations/graph/-private/edges/collection.d.ts +10 -10
- package/declarations/graph/-private/edges/implicit.d.ts +5 -5
- package/declarations/graph/-private/edges/resource.d.ts +6 -7
- package/declarations/graph/-private/graph.d.ts +17 -51
- package/declarations/graph/-private/normalize-link.d.ts +0 -6
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +73 -0
- package/declarations/reactive/-private/document.d.ts +11 -27
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -11
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -11
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
- package/declarations/reactive/-private/hooks.d.ts +2 -2
- package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
- package/declarations/reactive/-private/record.d.ts +44 -34
- package/declarations/reactive/-private/schema.d.ts +50 -68
- package/declarations/reactive/-private/symbols.d.ts +2 -33
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +3 -5
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +24 -28
- package/declarations/request/-private/types.d.ts +22 -24
- package/declarations/request/-private/utils.d.ts +44 -2
- package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
- package/declarations/store/-private/cache-handler/types.d.ts +10 -10
- package/declarations/store/-private/cache-handler/utils.d.ts +4 -5
- package/declarations/store/-private/caches/instance-cache.d.ts +22 -28
- package/declarations/store/-private/debug/utils.d.ts +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +25 -40
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
- package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
- package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
- package/declarations/store/-private/network/request-cache.d.ts +21 -25
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
- package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
- package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
- package/declarations/store/-private/store-service.d.ts +167 -877
- package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
- package/declarations/store/-private.d.ts +13 -14
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
- package/declarations/store/-types/q/identifier.d.ts +9 -6
- package/declarations/store/-types/q/record-instance.d.ts +0 -1
- package/declarations/store/-types/q/schema-service.d.ts +64 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +223 -0
- package/declarations/store/deprecated/store.d.ts +783 -0
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +0 -11
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -37
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -7
- package/declarations/types/cache.d.ts +51 -127
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +52 -78
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +66 -42
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +391 -14
- package/declarations/types/spec/document.d.ts +6 -10
- package/declarations/types/spec/json-api-raw.d.ts +6 -9
- package/declarations/types.d.ts +1 -1
- package/declarations/utils/string.d.ts +2 -3
- package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
- package/dist/configure.js +1 -1
- package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
- package/dist/graph/-private.js +137 -144
- package/dist/index.js +25 -14
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +337 -1422
- package/dist/{request-state-CjLph1LP.js → request-state-C955e0AL.js} +8352 -5912
- package/dist/request.js +1 -1
- package/dist/store/-private.js +2 -3
- package/dist/store.js +32 -44
- package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
- package/dist/types/-private.js +1 -1
- package/dist/types/identifier.js +19 -45
- package/dist/types/request.js +45 -3
- package/dist/types/schema/fields.js +23 -2
- package/dist/utils/string.js +2 -2
- package/package.json +11 -11
- package/declarations/reactive/-private/fields/compute.d.ts +0 -43
- package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
- package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
- package/declarations/store/-types/q/ds-model.d.ts +0 -21
- package/dist/handler-C2T-IyJK.js +0 -339
|
@@ -3,7 +3,7 @@ import type { Change } from "./cache/change.js";
|
|
|
3
3
|
import type { Mutation } from "./cache/mutations.js";
|
|
4
4
|
import type { Operation } from "./cache/operations.js";
|
|
5
5
|
import type { CollectionRelationship, ResourceRelationship } from "./cache/relationship.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { RequestKey, ResourceKey } from "./identifier.js";
|
|
7
7
|
import type { Value } from "./json/raw.js";
|
|
8
8
|
import type { TypeFromInstanceOrString } from "./record.js";
|
|
9
9
|
import type { RequestContext, StructuredDataDocument, StructuredDocument } from "./request.js";
|
|
@@ -13,20 +13,19 @@ import type { ApiError } from "./spec/error.js";
|
|
|
13
13
|
* A hash of changed attributes with the key being the attribute name and the value being an
|
|
14
14
|
* array of `[oldValue, newValue]`.
|
|
15
15
|
*
|
|
16
|
-
* @internal
|
|
17
16
|
*/
|
|
18
17
|
export type ChangedAttributesHash = Record<string, [Value | undefined, Value]>;
|
|
19
18
|
export type RelationshipDiff = {
|
|
20
19
|
kind: "collection";
|
|
21
|
-
remoteState:
|
|
22
|
-
additions: Set<
|
|
23
|
-
removals: Set<
|
|
24
|
-
localState:
|
|
20
|
+
remoteState: ResourceKey[];
|
|
21
|
+
additions: Set<ResourceKey>;
|
|
22
|
+
removals: Set<ResourceKey>;
|
|
23
|
+
localState: ResourceKey[];
|
|
25
24
|
reordered: boolean;
|
|
26
25
|
} | {
|
|
27
26
|
kind: "resource";
|
|
28
|
-
remoteState:
|
|
29
|
-
localState:
|
|
27
|
+
remoteState: ResourceKey | null;
|
|
28
|
+
localState: ResourceKey | null;
|
|
30
29
|
};
|
|
31
30
|
/**
|
|
32
31
|
* The interface for WarpDrive Caches.
|
|
@@ -34,20 +33,15 @@ export type RelationshipDiff = {
|
|
|
34
33
|
* A Cache handles in-memory storage of Document and Resource
|
|
35
34
|
* data.
|
|
36
35
|
*
|
|
37
|
-
* @class (Interface) Cache
|
|
38
36
|
* @public
|
|
39
37
|
*/
|
|
40
38
|
export interface Cache {
|
|
41
39
|
/**
|
|
42
40
|
* The Cache Version that this implementation implements.
|
|
43
41
|
*
|
|
44
|
-
* @type {'2'}
|
|
45
42
|
* @public
|
|
46
|
-
* @property version
|
|
47
43
|
*/
|
|
48
44
|
version: "2";
|
|
49
|
-
// Cache Management
|
|
50
|
-
// ================
|
|
51
45
|
/**
|
|
52
46
|
* Cache the response to a request
|
|
53
47
|
*
|
|
@@ -65,8 +59,6 @@ export interface Cache {
|
|
|
65
59
|
* a `content` member and therefor must not assume the existence
|
|
66
60
|
* of `request` and `response` on the document.
|
|
67
61
|
*
|
|
68
|
-
* @param {StructuredDocument} doc
|
|
69
|
-
* @return {ResourceDocument}
|
|
70
62
|
* @public
|
|
71
63
|
*/
|
|
72
64
|
put<T>(doc: StructuredDocument<T> | {
|
|
@@ -77,15 +69,12 @@ export interface Cache {
|
|
|
77
69
|
* by merging new information into the existing state.
|
|
78
70
|
*
|
|
79
71
|
* @public
|
|
80
|
-
* @param
|
|
81
|
-
* @return {void}
|
|
72
|
+
* @param op the operation(s) to perform
|
|
82
73
|
*/
|
|
83
74
|
patch(op: Operation | Operation[]): void;
|
|
84
75
|
/**
|
|
85
76
|
* Update the "local" or "current" (unpersisted) state of the Cache
|
|
86
77
|
*
|
|
87
|
-
* @param {Mutation} mutation
|
|
88
|
-
* @return {void}
|
|
89
78
|
* @public
|
|
90
79
|
*/
|
|
91
80
|
mutate(mutation: Mutation): void;
|
|
@@ -117,11 +106,10 @@ export interface Cache {
|
|
|
117
106
|
* notifications for relational data.
|
|
118
107
|
*
|
|
119
108
|
* @public
|
|
120
|
-
* @
|
|
121
|
-
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
109
|
+
* @return the known resource data, if any
|
|
122
110
|
*/
|
|
123
|
-
peek<T = unknown>(
|
|
124
|
-
peek(
|
|
111
|
+
peek<T = unknown>(cacheKey: ResourceKey<TypeFromInstanceOrString<T>>): T | null;
|
|
112
|
+
peek(cacheKey: RequestKey): ResourceDocument | null;
|
|
125
113
|
/**
|
|
126
114
|
* Peek remote resource data from the Cache.
|
|
127
115
|
*
|
|
@@ -152,11 +140,10 @@ export interface Cache {
|
|
|
152
140
|
* notifications for relational data.
|
|
153
141
|
*
|
|
154
142
|
* @public
|
|
155
|
-
* @
|
|
156
|
-
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
143
|
+
* @return the known data, if any
|
|
157
144
|
*/
|
|
158
|
-
peekRemoteState<T = unknown>(
|
|
159
|
-
peekRemoteState(
|
|
145
|
+
peekRemoteState<T = unknown>(cacheKey: ResourceKey<TypeFromInstanceOrString<T>>): T | null;
|
|
146
|
+
peekRemoteState(cacheKey: RequestKey): ResourceDocument | null;
|
|
160
147
|
/**
|
|
161
148
|
* Peek the Cache for the existing request data associated with
|
|
162
149
|
* a cacheable request
|
|
@@ -165,23 +152,16 @@ export interface Cache {
|
|
|
165
152
|
* that it will return the the request, response, and content
|
|
166
153
|
* whereas `peek` will return just the `content`.
|
|
167
154
|
*
|
|
168
|
-
* @param {StableDocumentIdentifier}
|
|
169
|
-
* @return {StructuredDocument<ResourceDocument> | null}
|
|
170
155
|
* @public
|
|
171
156
|
*/
|
|
172
|
-
peekRequest(
|
|
157
|
+
peekRequest(cacheKey: RequestKey): StructuredDocument<ResourceDocument> | null;
|
|
173
158
|
/**
|
|
174
|
-
* Push resource data from a remote source into the cache for this
|
|
159
|
+
* Push resource data from a remote source into the cache for this ResourceKey
|
|
175
160
|
*
|
|
176
161
|
* @public
|
|
177
|
-
* @
|
|
178
|
-
* @param data
|
|
179
|
-
* @param hasRecord
|
|
180
|
-
* @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
|
|
162
|
+
* @return if `hasRecord` is true then calculated key changes should be returned
|
|
181
163
|
*/
|
|
182
|
-
upsert(
|
|
183
|
-
// Cache Forking Support
|
|
184
|
-
// =====================
|
|
164
|
+
upsert(cacheKey: ResourceKey, data: ResourceBlob, hasRecord: boolean): void | string[];
|
|
185
165
|
/**
|
|
186
166
|
* Create a fork of the cache from the current state.
|
|
187
167
|
*
|
|
@@ -190,7 +170,6 @@ export interface Cache {
|
|
|
190
170
|
* utilize this method to fork the cache.
|
|
191
171
|
*
|
|
192
172
|
* @public
|
|
193
|
-
* @return {Promise<Cache>}
|
|
194
173
|
*/
|
|
195
174
|
fork(): Promise<Cache>;
|
|
196
175
|
/**
|
|
@@ -200,9 +179,6 @@ export interface Cache {
|
|
|
200
179
|
* preferring instead to merge at the Store level, which will
|
|
201
180
|
* utilize this method to merge the caches.
|
|
202
181
|
*
|
|
203
|
-
* @param {Cache} cache
|
|
204
|
-
* @public
|
|
205
|
-
* @return {Promise<void>}
|
|
206
182
|
*/
|
|
207
183
|
merge(cache: Cache): Promise<void>;
|
|
208
184
|
/**
|
|
@@ -214,7 +190,7 @@ export interface Cache {
|
|
|
214
190
|
* `Change` entry in the returned array.
|
|
215
191
|
*
|
|
216
192
|
* A `Change` is described by an object containing up to
|
|
217
|
-
* three properties: (1) the `
|
|
193
|
+
* three properties: (1) the `CacheKey` of the entity that
|
|
218
194
|
* changed; (2) the `op` code of that change being one of
|
|
219
195
|
* `upsert` or `remove`, and if the op is `upsert` a `patch`
|
|
220
196
|
* containing the data to merge into the cache for the given
|
|
@@ -229,7 +205,7 @@ export interface Cache {
|
|
|
229
205
|
*
|
|
230
206
|
* ```ts
|
|
231
207
|
* interface Change {
|
|
232
|
-
*
|
|
208
|
+
* key: ResourceKey | RequestKey;
|
|
233
209
|
* op: 'upsert' | 'remove';
|
|
234
210
|
* patch?: unknown;
|
|
235
211
|
* }
|
|
@@ -238,8 +214,6 @@ export interface Cache {
|
|
|
238
214
|
* @public
|
|
239
215
|
*/
|
|
240
216
|
diff(): Promise<Change[]>;
|
|
241
|
-
// SSR Support
|
|
242
|
-
// ===========
|
|
243
217
|
/**
|
|
244
218
|
* Serialize the entire contents of the Cache into a Stream
|
|
245
219
|
* which may be fed back into a new instance of the same Cache
|
|
@@ -261,13 +235,9 @@ export interface Cache {
|
|
|
261
235
|
* behavior supports optimizing pre/fetching of data for route transitions
|
|
262
236
|
* via data-only SSR modes.
|
|
263
237
|
*
|
|
264
|
-
* @param {ReadableStream} stream
|
|
265
|
-
* @return {Promise<void>}
|
|
266
238
|
* @public
|
|
267
239
|
*/
|
|
268
240
|
hydrate(stream: ReadableStream<unknown>): Promise<void>;
|
|
269
|
-
// Resource Support
|
|
270
|
-
// ================
|
|
271
241
|
/**
|
|
272
242
|
* [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
|
|
273
243
|
*
|
|
@@ -275,37 +245,31 @@ export interface Cache {
|
|
|
275
245
|
* process. This return value behavior is deprecated.
|
|
276
246
|
*
|
|
277
247
|
* @public
|
|
278
|
-
* @param identifier
|
|
279
|
-
* @param createArgs
|
|
280
248
|
*/
|
|
281
|
-
clientDidCreate(
|
|
249
|
+
clientDidCreate(cacheKey: ResourceKey, createArgs?: Record<string, unknown>): Record<string, unknown>;
|
|
282
250
|
/**
|
|
283
251
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
284
252
|
* will be part of a save transaction.
|
|
285
253
|
*
|
|
286
254
|
* @public
|
|
287
|
-
* @param identifier
|
|
288
255
|
*/
|
|
289
|
-
willCommit(
|
|
256
|
+
willCommit(cacheKey: ResourceKey, context: RequestContext | null): void;
|
|
290
257
|
/**
|
|
291
258
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
292
259
|
* was successfully updated as part of a save transaction.
|
|
293
260
|
*
|
|
294
261
|
* @public
|
|
295
|
-
* @param
|
|
262
|
+
* @param the primary ResourceKey that was operated on
|
|
296
263
|
* @param data - a document in the cache format containing any updated data
|
|
297
|
-
* @return {SingleResourceDataDocument}
|
|
298
264
|
*/
|
|
299
|
-
didCommit(
|
|
265
|
+
didCommit(cacheKey: ResourceKey, result: StructuredDataDocument<unknown> | null): SingleResourceDataDocument;
|
|
300
266
|
/**
|
|
301
267
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
302
268
|
* was update via a save transaction failed.
|
|
303
269
|
*
|
|
304
270
|
* @public
|
|
305
|
-
* @param identifier
|
|
306
|
-
* @param errors
|
|
307
271
|
*/
|
|
308
|
-
commitWasRejected(
|
|
272
|
+
commitWasRejected(cacheKey: ResourceKey, errors?: ApiError[]): void;
|
|
309
273
|
/**
|
|
310
274
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
311
275
|
* should be cleared.
|
|
@@ -313,40 +277,28 @@ export interface Cache {
|
|
|
313
277
|
* This method is a candidate to become a mutation
|
|
314
278
|
*
|
|
315
279
|
* @public
|
|
316
|
-
* @param identifier
|
|
317
280
|
*/
|
|
318
|
-
unloadRecord(
|
|
319
|
-
// Granular Resource Data APIs
|
|
320
|
-
// ===========================
|
|
281
|
+
unloadRecord(cacheKey: ResourceKey): void;
|
|
321
282
|
/**
|
|
322
283
|
* Retrieve the data for an attribute from the cache
|
|
323
284
|
*
|
|
324
285
|
* @public
|
|
325
|
-
* @param identifier
|
|
326
|
-
* @param field
|
|
327
|
-
* @return {unknown}
|
|
328
286
|
*/
|
|
329
|
-
getAttr(
|
|
287
|
+
getAttr(cacheKey: ResourceKey, field: string | string[]): Value | undefined;
|
|
330
288
|
/**
|
|
331
289
|
* Retrieve remote state without any local changes for a specific attribute
|
|
332
290
|
*
|
|
333
291
|
* @public
|
|
334
|
-
* @param identifier
|
|
335
|
-
* @param field
|
|
336
|
-
* @return {unknown}
|
|
337
292
|
*/
|
|
338
|
-
getRemoteAttr(
|
|
293
|
+
getRemoteAttr(cacheKey: ResourceKey, field: string | string[]): Value | undefined;
|
|
339
294
|
/**
|
|
340
295
|
* Mutate the data for an attribute in the cache
|
|
341
296
|
*
|
|
342
297
|
* This method is a candidate to become a mutation
|
|
343
298
|
*
|
|
344
299
|
* @public
|
|
345
|
-
* @param identifier
|
|
346
|
-
* @param field
|
|
347
|
-
* @param value
|
|
348
300
|
*/
|
|
349
|
-
setAttr(
|
|
301
|
+
setAttr(cacheKey: ResourceKey, field: string | string[], value: Value): void;
|
|
350
302
|
/**
|
|
351
303
|
* Query the cache for the changed attributes of a resource.
|
|
352
304
|
*
|
|
@@ -357,28 +309,23 @@ export interface Cache {
|
|
|
357
309
|
* ```
|
|
358
310
|
*
|
|
359
311
|
* @public
|
|
360
|
-
* @param identifier
|
|
361
|
-
* @return {Record<string, [unknown, unknown]>} `{ <field>: [<old>, <new>] }`
|
|
362
312
|
*/
|
|
363
|
-
changedAttrs(
|
|
313
|
+
changedAttrs(cacheKey: ResourceKey): ChangedAttributesHash;
|
|
364
314
|
/**
|
|
365
315
|
* Query the cache for whether any mutated attributes exist
|
|
366
316
|
*
|
|
367
317
|
* @public
|
|
368
|
-
* @param identifier
|
|
369
|
-
* @return {Boolean}
|
|
370
318
|
*/
|
|
371
|
-
hasChangedAttrs(
|
|
319
|
+
hasChangedAttrs(cacheKey: ResourceKey): boolean;
|
|
372
320
|
/**
|
|
373
321
|
* Tell the cache to discard any uncommitted mutations to attributes
|
|
374
322
|
*
|
|
375
323
|
* This method is a candidate to become a mutation
|
|
376
324
|
*
|
|
377
325
|
* @public
|
|
378
|
-
* @
|
|
379
|
-
* @return {String[]} the names of fields that were restored
|
|
326
|
+
* @return the names of fields that were restored
|
|
380
327
|
*/
|
|
381
|
-
rollbackAttrs(
|
|
328
|
+
rollbackAttrs(cacheKey: ResourceKey): string[];
|
|
382
329
|
/**
|
|
383
330
|
* Query the cache for the changes to relationships of a resource.
|
|
384
331
|
*
|
|
@@ -388,32 +335,28 @@ export interface Cache {
|
|
|
388
335
|
* type RelationshipDiff =
|
|
389
336
|
| {
|
|
390
337
|
kind: 'collection';
|
|
391
|
-
remoteState:
|
|
392
|
-
additions: Set<
|
|
393
|
-
removals: Set<
|
|
394
|
-
localState:
|
|
338
|
+
remoteState: ResourceKey[];
|
|
339
|
+
additions: Set<ResourceKey>;
|
|
340
|
+
removals: Set<ResourceKey>;
|
|
341
|
+
localState: ResourceKey[];
|
|
395
342
|
reordered: boolean;
|
|
396
343
|
}
|
|
397
344
|
| {
|
|
398
345
|
kind: 'resource';
|
|
399
|
-
remoteState:
|
|
400
|
-
localState:
|
|
346
|
+
remoteState: ResourceKey | null;
|
|
347
|
+
localState: ResourceKey | null;
|
|
401
348
|
};
|
|
402
349
|
```
|
|
403
350
|
*
|
|
404
351
|
* @public
|
|
405
|
-
* @param {StableRecordIdentifier} identifier
|
|
406
|
-
* @return {Map<string, RelationshipDiff>}
|
|
407
352
|
*/
|
|
408
|
-
changedRelationships(
|
|
353
|
+
changedRelationships(cacheKey: ResourceKey): Map<string, RelationshipDiff>;
|
|
409
354
|
/**
|
|
410
355
|
* Query the cache for whether any mutated attributes exist
|
|
411
356
|
*
|
|
412
357
|
* @public
|
|
413
|
-
* @param {StableRecordIdentifier} identifier
|
|
414
|
-
* @return {Boolean}
|
|
415
358
|
*/
|
|
416
|
-
hasChangedRelationships(
|
|
359
|
+
hasChangedRelationships(cacheKey: ResourceKey): boolean;
|
|
417
360
|
/**
|
|
418
361
|
* Tell the cache to discard any uncommitted mutations to relationships.
|
|
419
362
|
*
|
|
@@ -422,30 +365,23 @@ export interface Cache {
|
|
|
422
365
|
* This method is a candidate to become a mutation
|
|
423
366
|
*
|
|
424
367
|
* @public
|
|
425
|
-
* @
|
|
426
|
-
* @return {String[]} the names of relationships that were restored
|
|
368
|
+
* @return the names of relationships that were restored
|
|
427
369
|
*/
|
|
428
|
-
rollbackRelationships(
|
|
370
|
+
rollbackRelationships(cacheKey: ResourceKey): string[];
|
|
429
371
|
/**
|
|
430
372
|
* Query the cache for the current state of a relationship property
|
|
431
373
|
*
|
|
432
374
|
* @public
|
|
433
|
-
* @param {StableRecordIdentifier} identifier
|
|
434
|
-
* @param {String} field
|
|
435
375
|
* @return resource relationship object
|
|
436
376
|
*/
|
|
437
|
-
getRelationship(
|
|
377
|
+
getRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
|
|
438
378
|
/**
|
|
439
379
|
* Query the cache for the server state of a relationship property without any local changes
|
|
440
380
|
*
|
|
441
381
|
* @public
|
|
442
|
-
* @param {StableRecordIdentifier} identifier
|
|
443
|
-
* @param {String} field
|
|
444
382
|
* @return resource relationship object
|
|
445
383
|
*/
|
|
446
|
-
getRemoteRelationship(
|
|
447
|
-
// Resource State
|
|
448
|
-
// ===============
|
|
384
|
+
getRemoteRelationship(cacheKey: ResourceKey, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
|
|
449
385
|
/**
|
|
450
386
|
* Update the cache state for the given resource to be marked
|
|
451
387
|
* as locally deleted, or remove such a mark.
|
|
@@ -453,51 +389,39 @@ export interface Cache {
|
|
|
453
389
|
* This method is a candidate to become a mutation
|
|
454
390
|
*
|
|
455
391
|
* @public
|
|
456
|
-
* @param identifier
|
|
457
|
-
* @param {Boolean} isDeleted
|
|
458
392
|
*/
|
|
459
|
-
setIsDeleted(
|
|
393
|
+
setIsDeleted(cacheKey: ResourceKey, isDeleted: boolean): void;
|
|
460
394
|
/**
|
|
461
395
|
* Query the cache for any validation errors applicable to the given resource.
|
|
462
396
|
*
|
|
463
397
|
* @public
|
|
464
|
-
* @param identifier
|
|
465
|
-
* @return {JsonApiError[]}
|
|
466
398
|
*/
|
|
467
|
-
getErrors(
|
|
399
|
+
getErrors(cacheKey: ResourceKey): ApiError[];
|
|
468
400
|
/**
|
|
469
401
|
* Query the cache for whether a given resource has any available data
|
|
470
402
|
*
|
|
471
403
|
* @public
|
|
472
|
-
* @param identifier
|
|
473
|
-
* @return {Boolean}
|
|
474
404
|
*/
|
|
475
|
-
isEmpty(
|
|
405
|
+
isEmpty(cacheKey: ResourceKey): boolean;
|
|
476
406
|
/**
|
|
477
407
|
* Query the cache for whether a given resource was created locally and not
|
|
478
408
|
* yet persisted.
|
|
479
409
|
*
|
|
480
410
|
* @public
|
|
481
|
-
* @param identifier
|
|
482
|
-
* @return {Boolean}
|
|
483
411
|
*/
|
|
484
|
-
isNew(
|
|
412
|
+
isNew(cacheKey: ResourceKey): boolean;
|
|
485
413
|
/**
|
|
486
414
|
* Query the cache for whether a given resource is marked as deleted (but not
|
|
487
415
|
* necessarily persisted yet).
|
|
488
416
|
*
|
|
489
417
|
* @public
|
|
490
|
-
* @param identifier
|
|
491
|
-
* @return {Boolean}
|
|
492
418
|
*/
|
|
493
|
-
isDeleted(
|
|
419
|
+
isDeleted(cacheKey: ResourceKey): boolean;
|
|
494
420
|
/**
|
|
495
421
|
* Query the cache for whether a given resource has been deleted and that deletion
|
|
496
422
|
* has also been persisted.
|
|
497
423
|
*
|
|
498
424
|
* @public
|
|
499
|
-
* @param identifier
|
|
500
|
-
* @return {Boolean}
|
|
501
425
|
*/
|
|
502
|
-
isDeletionCommitted(
|
|
426
|
+
isDeletionCommitted(cacheKey: ResourceKey): boolean;
|
|
503
427
|
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import type { AddToResourceRelationshipMutation as AddResourceMutation, RemoveFromResourceRelationshipMutation as RemoveResourceMutation } from "./cache/mutations.js";
|
|
2
2
|
import type { AddToResourceRelationshipOperation as AddResourceOperation, RemoveFromResourceRelationshipOperation as RemoveResourceOperation, UpdateResourceRelationshipOperation } from "./cache/operations.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ResourceKey } from "./identifier.js";
|
|
4
4
|
import type { CollectionResourceRelationship, SingleResourceRelationship } from "./spec/json-api-raw.js";
|
|
5
5
|
export interface Operation {
|
|
6
6
|
op: string;
|
|
7
7
|
}
|
|
8
8
|
export interface UpdateRelationshipOperation {
|
|
9
9
|
op: "updateRelationship";
|
|
10
|
-
record:
|
|
10
|
+
record: ResourceKey;
|
|
11
11
|
field: string;
|
|
12
12
|
value: SingleResourceRelationship | CollectionResourceRelationship;
|
|
13
13
|
}
|
|
14
14
|
export interface DeleteRecordOperation {
|
|
15
15
|
op: "deleteRecord";
|
|
16
|
-
record:
|
|
16
|
+
record: ResourceKey;
|
|
17
17
|
isNew: boolean;
|
|
18
18
|
}
|
|
19
19
|
export interface UnknownOperation {
|
|
20
20
|
op: "never";
|
|
21
|
-
record:
|
|
21
|
+
record: ResourceKey;
|
|
22
22
|
field: string;
|
|
23
23
|
}
|
|
24
24
|
export interface ReplaceRelatedRecordOperation {
|
|
25
25
|
op: "replaceRelatedRecord";
|
|
26
|
-
record:
|
|
26
|
+
record: ResourceKey;
|
|
27
27
|
field: string;
|
|
28
|
-
value:
|
|
29
|
-
prior?:
|
|
28
|
+
value: ResourceKey | null;
|
|
29
|
+
prior?: ResourceKey;
|
|
30
30
|
index?: number;
|
|
31
31
|
}
|
|
32
32
|
export interface SortRelatedRecords {
|
|
33
33
|
op: "sortRelatedRecords";
|
|
34
|
-
record:
|
|
34
|
+
record: ResourceKey;
|
|
35
35
|
field: string;
|
|
36
|
-
value:
|
|
36
|
+
value: ResourceKey[];
|
|
37
37
|
}
|
|
38
38
|
export interface ReplaceRelatedRecordsOperation {
|
|
39
39
|
op: "replaceRelatedRecords";
|
|
40
|
-
record:
|
|
40
|
+
record: ResourceKey;
|
|
41
41
|
field: string;
|
|
42
|
-
value:
|
|
43
|
-
prior?:
|
|
42
|
+
value: ResourceKey[];
|
|
43
|
+
prior?: ResourceKey[];
|
|
44
44
|
index?: number;
|
|
45
45
|
}
|
|
46
46
|
export type RemoteRelationshipOperation = UpdateResourceRelationshipOperation | UpdateRelationshipOperation | ReplaceRelatedRecordOperation | ReplaceRelatedRecordsOperation | RemoveResourceOperation | AddResourceOperation | DeleteRecordOperation | SortRelatedRecords;
|
|
@@ -1,112 +1,86 @@
|
|
|
1
|
-
// provided for additional debuggability
|
|
2
1
|
export declare const DEBUG_CLIENT_ORIGINATED: unique symbol;
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const DEBUG_KEY_TYPE: unique symbol;
|
|
4
3
|
export declare const DEBUG_STALE_CACHE_OWNER: unique symbol;
|
|
5
|
-
// also present in production
|
|
6
4
|
export declare const CACHE_OWNER: "__$co";
|
|
7
|
-
export type
|
|
8
|
-
export interface Identifier {
|
|
9
|
-
lid: string;
|
|
10
|
-
clientId?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface ExistingRecordIdentifier<T extends string = string> extends Identifier {
|
|
13
|
-
id: string;
|
|
14
|
-
type: T;
|
|
15
|
-
}
|
|
16
|
-
export interface NewRecordIdentifier<T extends string = string> extends Identifier {
|
|
17
|
-
id: string | null;
|
|
18
|
-
type: T;
|
|
19
|
-
}
|
|
20
|
-
export type StableDocumentIdentifier = {
|
|
21
|
-
lid: string;
|
|
22
|
-
};
|
|
23
|
-
export type RequestKey = StableDocumentIdentifier;
|
|
5
|
+
export type CacheKeyType = "record" | "document";
|
|
24
6
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
7
|
+
* A referentially stable object with a unique string (lid) that can be used
|
|
8
|
+
* as a reference to request data in the cache.
|
|
27
9
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* may also indicate that it was generated for a secondary
|
|
31
|
-
* index and the primary `id` index is not yet known.
|
|
10
|
+
* Only requests that are assigned a RequestKey are retrievable/replayable from
|
|
11
|
+
* the cache, though requests without RequestKeys may still update cache state.
|
|
32
12
|
*
|
|
33
|
-
* @
|
|
13
|
+
* @public
|
|
34
14
|
*/
|
|
35
|
-
export
|
|
15
|
+
export interface RequestKey {
|
|
16
|
+
lid: string;
|
|
17
|
+
type: "@document";
|
|
18
|
+
}
|
|
19
|
+
/** @deprecated use {@link RequestKey} */
|
|
20
|
+
export type StableDocumentIdentifier = RequestKey;
|
|
36
21
|
/**
|
|
37
|
-
* Used when an
|
|
38
|
-
*
|
|
39
|
-
* @internal
|
|
22
|
+
* Used when an ResourceKey is known to be the stable version
|
|
40
23
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
interface ResourceKeyBase<T extends string = string> {
|
|
25
|
+
/**
|
|
26
|
+
* A string representing a unique identity.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
lid: string;
|
|
31
|
+
/**
|
|
32
|
+
* the primary `ResourceType` or "model name" this ResourceKey belongs to.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
type: T;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
|
-
* Used when a
|
|
39
|
+
* Used when a ResourceKey was not created locally as part
|
|
46
40
|
* of a call to store.createRecord
|
|
47
41
|
*
|
|
48
|
-
* Distinguishing between this
|
|
49
|
-
*
|
|
42
|
+
* Distinguishing between this ResourceKey and one for a client created
|
|
43
|
+
* resource that was created with an ID is generally speaking not possible
|
|
50
44
|
* at runtime, so anything with an ID typically narrows to this.
|
|
51
|
-
*
|
|
52
|
-
* @internal
|
|
53
45
|
*/
|
|
54
|
-
export interface
|
|
46
|
+
export interface PersistedResourceKey<T extends string = string> extends ResourceKeyBase<T> {
|
|
47
|
+
/**
|
|
48
|
+
* the PrimaryKey for the resource this ResourceKey represents.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
55
52
|
id: string;
|
|
56
|
-
type: T;
|
|
57
|
-
[DEBUG_CLIENT_ORIGINATED]?: boolean;
|
|
58
|
-
[CACHE_OWNER]: number | undefined;
|
|
59
|
-
[DEBUG_STALE_CACHE_OWNER]?: number | undefined;
|
|
60
53
|
}
|
|
54
|
+
/** @deprecated use {@link PersistedResourceKey} */
|
|
55
|
+
export type StableExistingRecordIdentifier<T extends string = string> = PersistedResourceKey<T>;
|
|
61
56
|
/**
|
|
62
|
-
* Used when a
|
|
57
|
+
* Used when a ResourceKey was created locally
|
|
63
58
|
* (by a call to store.createRecord).
|
|
64
59
|
*
|
|
65
|
-
* It is possible in rare circumstances to have a
|
|
60
|
+
* It is possible in rare circumstances to have a ResourceKey
|
|
66
61
|
* that is not for a new record but does not have an ID. This would
|
|
67
62
|
* happen if a user intentionally created one for use with a secondary-index
|
|
68
63
|
* prior to the record having been fully loaded.
|
|
69
|
-
*
|
|
70
|
-
* @internal
|
|
71
64
|
*/
|
|
72
|
-
export interface
|
|
65
|
+
export interface NewResourceKey<T extends string = string> extends ResourceKeyBase<T> {
|
|
66
|
+
/**
|
|
67
|
+
* the PrimaryKey for the resource this ResourceKey represents. `null`
|
|
68
|
+
* if not yet assigned a PrimaryKey value.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
73
72
|
id: string | null;
|
|
74
|
-
type: T;
|
|
75
|
-
[DEBUG_CLIENT_ORIGINATED]?: boolean;
|
|
76
|
-
[CACHE_OWNER]: number | undefined;
|
|
77
|
-
[DEBUG_STALE_CACHE_OWNER]?: number | undefined;
|
|
78
73
|
}
|
|
79
74
|
/**
|
|
80
75
|
* A referentially stable object with a unique string (lid) that can be used
|
|
81
76
|
* as a reference to data in the cache.
|
|
82
77
|
*
|
|
83
|
-
* Every
|
|
78
|
+
* Every resource has a unique ResourceKey, and ResourceKeys may refer
|
|
84
79
|
* to data that has never been loaded (for instance, in an async relationship).
|
|
85
80
|
*
|
|
86
|
-
* @class StableRecordIdentifier
|
|
87
|
-
* @public
|
|
88
|
-
*/
|
|
89
|
-
/**
|
|
90
|
-
* A string representing a unique identity.
|
|
91
|
-
*
|
|
92
|
-
* @property lid
|
|
93
|
-
* @type {String}
|
|
94
|
-
* @public
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* the primary resource `type` or `modelName` this identity belongs to.
|
|
98
|
-
*
|
|
99
|
-
* @property type
|
|
100
|
-
* @type {String}
|
|
101
|
-
* @public
|
|
102
|
-
*/
|
|
103
|
-
/**
|
|
104
|
-
* the primary id for the record this identity belongs to. `null`
|
|
105
|
-
* if not yet assigned an id.
|
|
106
|
-
*
|
|
107
|
-
* @property id
|
|
108
|
-
* @type {String | null}
|
|
109
81
|
* @public
|
|
110
82
|
*/
|
|
111
|
-
export type
|
|
112
|
-
|
|
83
|
+
export type ResourceKey<T extends string = string> = PersistedResourceKey<T> | NewResourceKey<T>;
|
|
84
|
+
/** @deprecated use {@link ResourceKey} */
|
|
85
|
+
export type StableRecordIdentifier<T extends string = string> = ResourceKey<T>;
|
|
86
|
+
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Includes, TypedRecordInstance } from "./record.js";
|
|
2
1
|
export type SerializablePrimitive = string | number | boolean | null;
|
|
3
2
|
export type Serializable = SerializablePrimitive | SerializablePrimitive[];
|
|
4
3
|
export type QueryParamsSerializationOptions = {
|
|
5
4
|
arrayFormat?: "bracket" | "indices" | "repeat" | "comma";
|
|
6
5
|
};
|
|
7
|
-
export type QueryParamsSource
|
|
8
|
-
include?:
|
|
6
|
+
export type QueryParamsSource = ({
|
|
7
|
+
include?: string | string[];
|
|
9
8
|
} & Record<Exclude<string, "include">, Serializable>) | URLSearchParams;
|