@warp-drive-mirror/json-api 5.6.0-alpha.14 → 5.6.0-alpha.17
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/-private/cache.d.ts +561 -544
- package/declarations/-private/validate-document-fields.d.ts +2 -3
- package/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts +10 -11
- package/declarations/-private/validator/1.1/7.2_resource-objects.d.ts +11 -12
- package/declarations/-private/validator/1.1/links.d.ts +22 -23
- package/declarations/-private/validator/index.d.ts +3 -4
- package/declarations/-private/validator/utils.d.ts +61 -60
- package/declarations/index.d.ts +1 -85
- package/dist/index.js +0 -1
- package/package.json +5 -5
- package/declarations/-private/cache.d.ts.map +0 -1
- package/declarations/-private/validate-document-fields.d.ts.map +0 -1
- package/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts.map +0 -1
- package/declarations/-private/validator/1.1/7.2_resource-objects.d.ts.map +0 -1
- package/declarations/-private/validator/1.1/links.d.ts.map +0 -1
- package/declarations/-private/validator/index.d.ts.map +0 -1
- package/declarations/-private/validator/utils.d.ts.map +0 -1
- package/declarations/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,569 +1,586 @@
|
|
|
1
|
-
import type { Graph } from
|
|
2
|
-
import type { CacheCapabilitiesManager } from
|
|
3
|
-
import type { Cache, ChangedAttributesHash, RelationshipDiff } from
|
|
4
|
-
import type { Change } from
|
|
5
|
-
import type { Operation } from
|
|
6
|
-
import type { CollectionRelationship, ResourceRelationship } from
|
|
7
|
-
import type { LocalRelationshipOperation } from
|
|
8
|
-
import type { StableDocumentIdentifier, StableExistingRecordIdentifier, StableRecordIdentifier } from
|
|
9
|
-
import type { Value } from
|
|
10
|
-
import type { StructuredDataDocument, StructuredDocument, StructuredErrorDocument } from
|
|
11
|
-
import type { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDocument, ResourceMetaDocument, SingleResourceDataDocument } from
|
|
12
|
-
import type { ApiError } from
|
|
13
|
-
import type { CollectionResourceDocument, ExistingResourceObject, ResourceObject, SingleResourceDocument } from
|
|
1
|
+
import type { Graph } from "@warp-drive-mirror/core/graph/-private";
|
|
2
|
+
import type { CacheCapabilitiesManager } from "@warp-drive-mirror/core/types";
|
|
3
|
+
import type { Cache, ChangedAttributesHash, RelationshipDiff } from "@warp-drive-mirror/core/types/cache";
|
|
4
|
+
import type { Change } from "@warp-drive-mirror/core/types/cache/change";
|
|
5
|
+
import type { Operation } from "@warp-drive-mirror/core/types/cache/operations";
|
|
6
|
+
import type { CollectionRelationship, ResourceRelationship } from "@warp-drive-mirror/core/types/cache/relationship";
|
|
7
|
+
import type { LocalRelationshipOperation } from "@warp-drive-mirror/core/types/graph";
|
|
8
|
+
import type { StableDocumentIdentifier, StableExistingRecordIdentifier, StableRecordIdentifier } from "@warp-drive-mirror/core/types/identifier";
|
|
9
|
+
import type { Value } from "@warp-drive-mirror/core/types/json/raw";
|
|
10
|
+
import type { StructuredDataDocument, StructuredDocument, StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
|
|
11
|
+
import type { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDocument, ResourceMetaDocument, SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
12
|
+
import type { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
13
|
+
import type { CollectionResourceDocument, ExistingResourceObject, ResourceObject, SingleResourceDocument } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
14
14
|
interface CachedResource {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
id: string | null;
|
|
16
|
+
remoteAttrs: Record<string, Value | undefined> | null;
|
|
17
|
+
localAttrs: Record<string, Value | undefined> | null;
|
|
18
|
+
defaultAttrs: Record<string, Value | undefined> | null;
|
|
19
|
+
inflightAttrs: Record<string, Value | undefined> | null;
|
|
20
|
+
changes: Record<string, [Value | undefined, Value]> | null;
|
|
21
|
+
errors: ApiError[] | null;
|
|
22
|
+
isNew: boolean;
|
|
23
|
+
isDeleted: boolean;
|
|
24
|
+
isDeletionCommitted: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* debugging only
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
inflightRelationships?: Record<string, unknown> | null;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
* ### JSONAPICache
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
A {@link Cache} implementation tuned for [{json:api}](https://jsonapi.org/)
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
This format excels at simiplifying common complex problems around cache
|
|
42
|
+
consistency and information density. Because most API responses can be quickly
|
|
43
|
+
transformed into {json:api} format without losing any information, WarpDrive
|
|
44
|
+
recommends that most apps use this Cache implementation.
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
If a cache built to understand another format would do better for your app then
|
|
47
|
+
it just needs to follow the same interface.
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
Do you really need a cache? Are sunsets beautiful? Caching is what powers features like
|
|
50
|
+
immutability, mutation management, and allows ***Warp*Drive** to understand your relational
|
|
51
|
+
data.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
Some caches are simple request/response maps. ***Warp*Drive**'s is not. The Cache deeply
|
|
54
|
+
understands the structure of your data, ensuring your data remains consistent both within
|
|
55
|
+
and across requests.
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
### Installation
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
::: code-group
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
```sh [pnpm]
|
|
62
|
+
pnpm add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
63
|
+
```
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
```sh [npm]
|
|
66
|
+
npm add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
67
|
+
```
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
```sh [yarn]
|
|
70
|
+
yarn add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
71
|
+
```
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
```sh [bun]
|
|
74
|
+
bun add --exact @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
75
|
+
```
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
:::
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
### Setup
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
```ts [services/store.ts]
|
|
82
|
+
import { Fetch, RequestManager, Store } from '@warp-drive-mirror/core';
|
|
83
|
+
import {
|
|
84
|
+
registerDerivations,
|
|
85
|
+
SchemaService,
|
|
86
|
+
} from '@warp-drive-mirror/core/reactive';
|
|
87
|
+
import { CacheHandler } from '@warp-drive-mirror/core/store';
|
|
88
|
+
import type { CacheCapabilitiesManager } from '@warp-drive-mirror/core/types'; // [!code focus:2]
|
|
89
|
+
import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
export default class AppStore extends Store {
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
requestManager = new RequestManager()
|
|
94
|
+
.use([Fetch])
|
|
95
|
+
.useCache(CacheHandler);
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
createSchemaService() {
|
|
98
|
+
const schema = new SchemaService();
|
|
99
|
+
registerDerivations(schema);
|
|
100
|
+
return schema;
|
|
101
|
+
}
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
createCache(capabilities: CacheCapabilitiesManager) { // [!code focus:3]
|
|
104
|
+
return new JSONAPICache(capabilities);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
* @categoryDescription Cache Management
|
|
110
|
+
* APIs for primary cache management functionality
|
|
111
|
+
* @categoryDescription Cache Forking
|
|
112
|
+
* APIs that support Cache Forking
|
|
113
|
+
* @categoryDescription SSR Support
|
|
114
|
+
* APIs that support SSR functionality
|
|
115
|
+
* @categoryDescription Resource Lifecycle
|
|
116
|
+
* APIs that support management of resource data
|
|
117
|
+
* @categoryDescription Resource Data
|
|
118
|
+
* APIs that support granular field level management of resource data
|
|
119
|
+
* @categoryDescription Resource State
|
|
120
|
+
* APIs that support managing Resource states
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
@public
|
|
123
|
+
*/
|
|
124
124
|
export declare class JSONAPICache implements Cache {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The Cache Version that this implementation implements.
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
version: "2";
|
|
131
|
+
/** @internal */
|
|
132
|
+
_capabilities: CacheCapabilitiesManager;
|
|
133
|
+
/** @internal */
|
|
134
|
+
__cache: Map<StableRecordIdentifier, CachedResource>;
|
|
135
|
+
/** @internal */
|
|
136
|
+
__destroyedCache: Map<StableRecordIdentifier, CachedResource>;
|
|
137
|
+
/** @internal */
|
|
138
|
+
__documents: Map<string, StructuredDocument<ResourceDocument>>;
|
|
139
|
+
/** @internal */
|
|
140
|
+
__graph: Graph;
|
|
141
|
+
constructor(capabilities: CacheCapabilitiesManager);
|
|
142
|
+
////////// ================ //////////
|
|
143
|
+
////////// Cache Management //////////
|
|
144
|
+
////////// ================ //////////
|
|
145
|
+
/**
|
|
146
|
+
* Cache the response to a request
|
|
147
|
+
*
|
|
148
|
+
* Implements `Cache.put`.
|
|
149
|
+
*
|
|
150
|
+
* Expects a StructuredDocument whose `content` member is a JsonApiDocument.
|
|
151
|
+
*
|
|
152
|
+
* ```js
|
|
153
|
+
* cache.put({
|
|
154
|
+
* request: { url: 'https://api.example.com/v1/user/1' },
|
|
155
|
+
* content: {
|
|
156
|
+
* data: {
|
|
157
|
+
* type: 'user',
|
|
158
|
+
* id: '1',
|
|
159
|
+
* attributes: {
|
|
160
|
+
* name: 'Chris'
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* }
|
|
164
|
+
* })
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* > **Note**
|
|
168
|
+
* > The nested `content` and `data` members are not a mistake. This is because
|
|
169
|
+
* > there are two separate concepts involved here, the `StructuredDocument` which contains
|
|
170
|
+
* > the context of a given Request that has been issued with the returned contents as its
|
|
171
|
+
* > `content` property, and a `JSON:API Document` which is the json contents returned by
|
|
172
|
+
* > this endpoint and which uses its `data` property to signify which resources are the
|
|
173
|
+
* > primary resources associated with the request.
|
|
174
|
+
*
|
|
175
|
+
* StructuredDocument's with urls will be cached as full documents with
|
|
176
|
+
* associated resource membership order and contents preserved but linked
|
|
177
|
+
* into the cache.
|
|
178
|
+
*
|
|
179
|
+
* @category Cache Management
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
put<T extends SingleResourceDocument>(doc: StructuredDataDocument<T>): SingleResourceDataDocument;
|
|
183
|
+
put<T extends CollectionResourceDocument>(doc: StructuredDataDocument<T>): CollectionResourceDataDocument;
|
|
184
|
+
put<T extends ResourceErrorDocument>(doc: StructuredErrorDocument<T>): ResourceErrorDocument;
|
|
185
|
+
put<T extends ResourceMetaDocument>(doc: StructuredDataDocument<T>): ResourceMetaDocument;
|
|
186
|
+
/** @internal */
|
|
187
|
+
_putDocument<T extends ResourceErrorDocument>(doc: StructuredErrorDocument<T>, data: undefined, included: undefined): ResourceErrorDocument;
|
|
188
|
+
_putDocument<T extends ResourceMetaDocument>(doc: StructuredDataDocument<T>, data: undefined, included: undefined): ResourceMetaDocument;
|
|
189
|
+
_putDocument<T extends SingleResourceDocument>(doc: StructuredDataDocument<T>, data: StableExistingRecordIdentifier | null, included: StableExistingRecordIdentifier[] | undefined): SingleResourceDataDocument;
|
|
190
|
+
_putDocument<T extends CollectionResourceDocument>(doc: StructuredDataDocument<T>, data: StableExistingRecordIdentifier[], included: StableExistingRecordIdentifier[] | undefined): CollectionResourceDataDocument;
|
|
191
|
+
/**
|
|
192
|
+
* Update the "remote" or "canonical" (persisted) state of the Cache
|
|
193
|
+
* by merging new information into the existing state.
|
|
194
|
+
*
|
|
195
|
+
* @category Cache Management
|
|
196
|
+
* @public
|
|
197
|
+
* @param op the operation or list of operations to perform
|
|
198
|
+
*/
|
|
199
|
+
patch(op: Operation | Operation[]): void;
|
|
200
|
+
/**
|
|
201
|
+
* Update the "local" or "current" (unpersisted) state of the Cache
|
|
202
|
+
*
|
|
203
|
+
* @category Cache Management
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
mutate(mutation: LocalRelationshipOperation): void;
|
|
207
|
+
/**
|
|
208
|
+
* Peek resource data from the Cache.
|
|
209
|
+
*
|
|
210
|
+
* In development, if the return value
|
|
211
|
+
* is JSON the return value
|
|
212
|
+
* will be deep-cloned and deep-frozen
|
|
213
|
+
* to prevent mutation thereby enforcing cache
|
|
214
|
+
* Immutability.
|
|
215
|
+
*
|
|
216
|
+
* This form of peek is useful for implementations
|
|
217
|
+
* that want to feed raw-data from cache to the UI
|
|
218
|
+
* or which want to interact with a blob of data
|
|
219
|
+
* directly from the presentation cache.
|
|
220
|
+
*
|
|
221
|
+
* An implementation might want to do this because
|
|
222
|
+
* de-referencing records which read from their own
|
|
223
|
+
* blob is generally safer because the record does
|
|
224
|
+
* not require retainining connections to the Store
|
|
225
|
+
* and Cache to present data on a per-field basis.
|
|
226
|
+
*
|
|
227
|
+
* This generally takes the place of `getAttr` as
|
|
228
|
+
* an API and may even take the place of `getRelationship`
|
|
229
|
+
* depending on implementation specifics, though this
|
|
230
|
+
* latter usage is less recommended due to the advantages
|
|
231
|
+
* of the Graph handling necessary entanglements and
|
|
232
|
+
* notifications for relational data.
|
|
233
|
+
*
|
|
234
|
+
* @category Cache Management
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
peek(identifier: StableRecordIdentifier): ResourceObject | null;
|
|
238
|
+
peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
|
|
239
|
+
/**
|
|
240
|
+
* Peek the remote resource data from the Cache.
|
|
241
|
+
*
|
|
242
|
+
* @category Cache Management
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
peekRemoteState(identifier: StableRecordIdentifier): ResourceObject | null;
|
|
246
|
+
peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;
|
|
247
|
+
/**
|
|
248
|
+
* Peek the Cache for the existing request data associated with
|
|
249
|
+
* a cacheable request.
|
|
250
|
+
*
|
|
251
|
+
* This is effectively the reverse of `put` for a request in
|
|
252
|
+
* that it will return the the request, response, and content
|
|
253
|
+
* whereas `peek` will return just the `content`.
|
|
254
|
+
*
|
|
255
|
+
* @category Cache Management
|
|
256
|
+
* @public
|
|
257
|
+
*/
|
|
258
|
+
peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
|
|
259
|
+
/**
|
|
260
|
+
* Push resource data from a remote source into the cache for this identifier
|
|
261
|
+
*
|
|
262
|
+
* @category Cache Management
|
|
263
|
+
* @public
|
|
264
|
+
* @return if `calculateChanges` is true then calculated key changes should be returned
|
|
265
|
+
*/
|
|
266
|
+
upsert(identifier: StableRecordIdentifier, data: ExistingResourceObject, calculateChanges?: boolean): void | string[];
|
|
267
|
+
////////// ============= //////////
|
|
268
|
+
////////// Cache Forking //////////
|
|
269
|
+
////////// ============= //////////
|
|
270
|
+
/**
|
|
271
|
+
* Create a fork of the cache from the current state.
|
|
272
|
+
*
|
|
273
|
+
* Applications should typically not call this method themselves,
|
|
274
|
+
* preferring instead to fork at the Store level, which will
|
|
275
|
+
* utilize this method to fork the cache.
|
|
276
|
+
*
|
|
277
|
+
* @category Cache Forking
|
|
278
|
+
* @internal
|
|
279
|
+
*/
|
|
280
|
+
fork(): Promise<Cache>;
|
|
281
|
+
/**
|
|
282
|
+
* Merge a fork back into a parent Cache.
|
|
283
|
+
*
|
|
284
|
+
* Applications should typically not call this method themselves,
|
|
285
|
+
* preferring instead to merge at the Store level, which will
|
|
286
|
+
* utilize this method to merge the caches.
|
|
287
|
+
*
|
|
288
|
+
* @category Cache Forking
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
merge(_cache: Cache): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Generate the list of changes applied to all
|
|
294
|
+
* record in the store.
|
|
295
|
+
*
|
|
296
|
+
* Each individual resource or document that has
|
|
297
|
+
* been mutated should be described as an individual
|
|
298
|
+
* `Change` entry in the returned array.
|
|
299
|
+
*
|
|
300
|
+
* A `Change` is described by an object containing up to
|
|
301
|
+
* three properties: (1) the `identifier` of the entity that
|
|
302
|
+
* changed; (2) the `op` code of that change being one of
|
|
303
|
+
* `upsert` or `remove`, and if the op is `upsert` a `patch`
|
|
304
|
+
* containing the data to merge into the cache for the given
|
|
305
|
+
* entity.
|
|
306
|
+
*
|
|
307
|
+
* This `patch` is opaque to the Store but should be understood
|
|
308
|
+
* by the Cache and may expect to be utilized by an Adapter
|
|
309
|
+
* when generating data during a `save` operation.
|
|
310
|
+
*
|
|
311
|
+
* It is generally recommended that the `patch` contain only
|
|
312
|
+
* the updated state, ignoring fields that are unchanged
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* interface Change {
|
|
316
|
+
* identifier: StableRecordIdentifier | StableDocumentIdentifier;
|
|
317
|
+
* op: 'upsert' | 'remove';
|
|
318
|
+
* patch?: unknown;
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
*
|
|
322
|
+
* @category Cache Forking
|
|
323
|
+
* @internal
|
|
324
|
+
*/
|
|
325
|
+
diff(): Promise<Change[]>;
|
|
326
|
+
////////// =========== //////////
|
|
327
|
+
////////// SSR Support //////////
|
|
328
|
+
////////// =========== //////////
|
|
329
|
+
/**
|
|
330
|
+
* Serialize the entire contents of the Cache into a Stream
|
|
331
|
+
* which may be fed back into a new instance of the same Cache
|
|
332
|
+
* via `cache.hydrate`.
|
|
333
|
+
*
|
|
334
|
+
* @category SSR Support
|
|
335
|
+
* @internal
|
|
336
|
+
*/
|
|
337
|
+
dump(): Promise<ReadableStream<unknown>>;
|
|
338
|
+
/**
|
|
339
|
+
* hydrate a Cache from a Stream with content previously serialized
|
|
340
|
+
* from another instance of the same Cache, resolving when hydration
|
|
341
|
+
* is complete.
|
|
342
|
+
*
|
|
343
|
+
* This method should expect to be called both in the context of restoring
|
|
344
|
+
* the Cache during application rehydration after SSR **AND** at unknown
|
|
345
|
+
* times during the lifetime of an already booted application when it is
|
|
346
|
+
* desired to bulk-load additional information into the cache. This latter
|
|
347
|
+
* behavior supports optimizing pre/fetching of data for route transitions
|
|
348
|
+
* via data-only SSR modes.
|
|
349
|
+
*
|
|
350
|
+
* @category SSR Support
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
hydrate(stream: ReadableStream<unknown>): Promise<void>;
|
|
354
|
+
////////// ================== //////////
|
|
355
|
+
////////// Resource Lifecycle //////////
|
|
356
|
+
////////// ================== //////////
|
|
357
|
+
/**
|
|
358
|
+
* [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
|
|
359
|
+
*
|
|
360
|
+
* It returns properties from options that should be set on the record during the create
|
|
361
|
+
* process. This return value behavior is deprecated.
|
|
362
|
+
*
|
|
363
|
+
* @category Resource Lifecycle
|
|
364
|
+
* @public
|
|
365
|
+
*/
|
|
366
|
+
clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, Value>): Record<string, unknown>;
|
|
367
|
+
/**
|
|
368
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
369
|
+
* will be part of a save transaction.
|
|
370
|
+
*
|
|
371
|
+
* @category Resource Lifecycle
|
|
372
|
+
* @public
|
|
373
|
+
*/
|
|
374
|
+
willCommit(identifier: StableRecordIdentifier): void;
|
|
375
|
+
/**
|
|
376
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
377
|
+
* was successfully updated as part of a save transaction.
|
|
378
|
+
*
|
|
379
|
+
* @category Resource Lifecycle
|
|
380
|
+
* @public
|
|
381
|
+
*/
|
|
382
|
+
didCommit(committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument<SingleResourceDocument>): SingleResourceDataDocument;
|
|
383
|
+
/**
|
|
384
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
385
|
+
* was update via a save transaction failed.
|
|
386
|
+
*
|
|
387
|
+
* @category Resource Lifecycle
|
|
388
|
+
* @public
|
|
389
|
+
*/
|
|
390
|
+
commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
|
|
391
|
+
/**
|
|
392
|
+
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
393
|
+
* should be cleared.
|
|
394
|
+
*
|
|
395
|
+
* This method is a candidate to become a mutation
|
|
396
|
+
*
|
|
397
|
+
* @category Resource Lifecycle
|
|
398
|
+
* @public
|
|
399
|
+
*/
|
|
400
|
+
unloadRecord(identifier: StableRecordIdentifier): void;
|
|
401
|
+
////////// ============= //////////
|
|
402
|
+
////////// Resource Data //////////
|
|
403
|
+
////////// ============= //////////
|
|
404
|
+
/**
|
|
405
|
+
* Retrieve the data for an attribute from the cache
|
|
406
|
+
* with local mutations applied.
|
|
407
|
+
*
|
|
408
|
+
* @category Resource Data
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
411
|
+
getAttr(identifier: StableRecordIdentifier, attr: string | string[]): Value | undefined;
|
|
412
|
+
/**
|
|
413
|
+
* Retrieve the remote data for an attribute from the cache
|
|
414
|
+
*
|
|
415
|
+
* @category Resource Data
|
|
416
|
+
* @public
|
|
417
|
+
*/
|
|
418
|
+
getRemoteAttr(identifier: StableRecordIdentifier, attr: string | string[]): Value | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Mutate the data for an attribute in the cache
|
|
421
|
+
*
|
|
422
|
+
* This method is a candidate to become a mutation
|
|
423
|
+
*
|
|
424
|
+
* @category Resource Data
|
|
425
|
+
* @public
|
|
426
|
+
*/
|
|
427
|
+
setAttr(identifier: StableRecordIdentifier, attr: string | string[], value: Value): void;
|
|
428
|
+
/**
|
|
429
|
+
* Query the cache for the changed attributes of a resource.
|
|
430
|
+
*
|
|
431
|
+
* @category Resource Data
|
|
432
|
+
* @public
|
|
433
|
+
* @return `{ '<field>': ['<old>', '<new>'] }`
|
|
434
|
+
*/
|
|
435
|
+
changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
|
|
436
|
+
/**
|
|
437
|
+
* Query the cache for whether any mutated attributes exist
|
|
438
|
+
*
|
|
439
|
+
* @category Resource Data
|
|
440
|
+
* @public
|
|
441
|
+
*/
|
|
442
|
+
hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
|
|
443
|
+
/**
|
|
444
|
+
* Tell the cache to discard any uncommitted mutations to attributes
|
|
445
|
+
*
|
|
446
|
+
* This method is a candidate to become a mutation
|
|
447
|
+
*
|
|
448
|
+
* @category Resource Data
|
|
449
|
+
* @public
|
|
450
|
+
* @return the names of fields that were restored
|
|
451
|
+
*/
|
|
452
|
+
rollbackAttrs(identifier: StableRecordIdentifier): string[];
|
|
453
|
+
/**
|
|
454
|
+
* Query the cache for the changes to relationships of a resource.
|
|
455
|
+
*
|
|
456
|
+
* Returns a map of relationship names to RelationshipDiff objects.
|
|
457
|
+
*
|
|
458
|
+
* ```ts
|
|
459
|
+
* type RelationshipDiff =
|
|
460
|
+
| {
|
|
461
|
+
kind: 'collection';
|
|
462
|
+
remoteState: StableRecordIdentifier[];
|
|
463
|
+
additions: Set<StableRecordIdentifier>;
|
|
464
|
+
removals: Set<StableRecordIdentifier>;
|
|
465
|
+
localState: StableRecordIdentifier[];
|
|
466
|
+
reordered: boolean;
|
|
467
|
+
}
|
|
468
|
+
| {
|
|
469
|
+
kind: 'resource';
|
|
470
|
+
remoteState: StableRecordIdentifier | null;
|
|
471
|
+
localState: StableRecordIdentifier | null;
|
|
472
|
+
};
|
|
473
|
+
```
|
|
474
|
+
*
|
|
475
|
+
* @category Resource Data
|
|
476
|
+
* @public
|
|
477
|
+
*/
|
|
478
|
+
changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
|
|
479
|
+
/**
|
|
480
|
+
* Query the cache for whether any mutated relationships exist
|
|
481
|
+
*
|
|
482
|
+
* @category Resource Data
|
|
483
|
+
* @public
|
|
484
|
+
*/
|
|
485
|
+
hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Tell the cache to discard any uncommitted mutations to relationships.
|
|
488
|
+
*
|
|
489
|
+
* This will also discard the change on any appropriate inverses.
|
|
490
|
+
*
|
|
491
|
+
* This method is a candidate to become a mutation
|
|
492
|
+
*
|
|
493
|
+
* @category Resource Data
|
|
494
|
+
* @public
|
|
495
|
+
* @return the names of relationships that were restored
|
|
496
|
+
*/
|
|
497
|
+
rollbackRelationships(identifier: StableRecordIdentifier): string[];
|
|
498
|
+
/**
|
|
499
|
+
* Query the cache for the current state of a relationship property
|
|
500
|
+
*
|
|
501
|
+
* @category Resource Data
|
|
502
|
+
* @public
|
|
503
|
+
* @return resource relationship object
|
|
504
|
+
*/
|
|
505
|
+
getRelationship(identifier: StableRecordIdentifier, field: string): ResourceRelationship | CollectionRelationship;
|
|
506
|
+
/**
|
|
507
|
+
* Query the cache for the remote state of a relationship property
|
|
508
|
+
*
|
|
509
|
+
* @category Resource Data
|
|
510
|
+
* @public
|
|
511
|
+
* @return resource relationship object
|
|
512
|
+
*/
|
|
513
|
+
getRemoteRelationship(identifier: StableRecordIdentifier, field: string): ResourceRelationship | CollectionRelationship;
|
|
514
|
+
////////// ============== //////////
|
|
515
|
+
////////// Resource State //////////
|
|
516
|
+
////////// ============== //////////
|
|
517
|
+
/**
|
|
518
|
+
* Update the cache state for the given resource to be marked
|
|
519
|
+
* as locally deleted, or remove such a mark.
|
|
520
|
+
*
|
|
521
|
+
* This method is a candidate to become a mutation
|
|
522
|
+
*
|
|
523
|
+
* @category Resource State
|
|
524
|
+
* @public
|
|
525
|
+
*/
|
|
526
|
+
setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
|
|
527
|
+
/**
|
|
528
|
+
* Query the cache for any validation errors applicable to the given resource.
|
|
529
|
+
*
|
|
530
|
+
* @category Resource State
|
|
531
|
+
* @public
|
|
532
|
+
*/
|
|
533
|
+
getErrors(identifier: StableRecordIdentifier): ApiError[];
|
|
534
|
+
/**
|
|
535
|
+
* Query the cache for whether a given resource has any available data
|
|
536
|
+
*
|
|
537
|
+
* @category Resource State
|
|
538
|
+
* @public
|
|
539
|
+
*/
|
|
540
|
+
isEmpty(identifier: StableRecordIdentifier): boolean;
|
|
541
|
+
/**
|
|
542
|
+
* Query the cache for whether a given resource was created locally and not
|
|
543
|
+
* yet persisted.
|
|
544
|
+
*
|
|
545
|
+
* @category Resource State
|
|
546
|
+
* @public
|
|
547
|
+
*/
|
|
548
|
+
isNew(identifier: StableRecordIdentifier): boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Query the cache for whether a given resource is marked as deleted (but not
|
|
551
|
+
* necessarily persisted yet).
|
|
552
|
+
*
|
|
553
|
+
* @category Resource State
|
|
554
|
+
* @public
|
|
555
|
+
*/
|
|
556
|
+
isDeleted(identifier: StableRecordIdentifier): boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Query the cache for whether a given resource has been deleted and that deletion
|
|
559
|
+
* has also been persisted.
|
|
560
|
+
*
|
|
561
|
+
* @category Resource State
|
|
562
|
+
* @public
|
|
563
|
+
*/
|
|
564
|
+
isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Private method used to populate an entry for the identifier
|
|
567
|
+
*
|
|
568
|
+
* @internal
|
|
569
|
+
*/
|
|
570
|
+
_createCache(identifier: StableRecordIdentifier): CachedResource;
|
|
571
|
+
/**
|
|
572
|
+
* Peek whether we have cached resource data matching the identifier
|
|
573
|
+
* without asserting if the resource data is missing.
|
|
574
|
+
*
|
|
575
|
+
* @internal
|
|
576
|
+
*/
|
|
577
|
+
__safePeek(identifier: StableRecordIdentifier, allowDestroyed: boolean): CachedResource | undefined;
|
|
578
|
+
/**
|
|
579
|
+
* Peek whether we have cached resource data matching the identifier
|
|
580
|
+
* Asserts if the resource data is missing.
|
|
581
|
+
*
|
|
582
|
+
* @internal
|
|
583
|
+
*/
|
|
584
|
+
__peek(identifier: StableRecordIdentifier, allowDestroyed: boolean): CachedResource;
|
|
567
585
|
}
|
|
568
586
|
export {};
|
|
569
|
-
//# sourceMappingURL=cache.d.ts.map
|