@warp-drive-mirror/json-api 5.10.0-alpha.1 → 5.10.0-alpha.10
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/dist/index.d.ts +295 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +569 -134
- package/dist/index.js.map +1 -1
- package/dist/unpkg/dev/index.js +570 -135
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/dev-deprecated/index.js +570 -135
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod/index.js +559 -133
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/index.js +559 -133
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -12,19 +12,109 @@ import { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDocument
|
|
|
12
12
|
import { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
13
13
|
import { CollectionResourceDocument, ExistingResourceObject, ResourceObject, SingleResourceDocument } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
14
14
|
//#region src/-private/cache.d.ts
|
|
15
|
+
/** One attributes hash on a {@link CachedResource}: a **layer** a projection is read through. */
|
|
16
|
+
type AttrHash = Record<string, Value | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* The cache's entry for a single resource: its id, its attribute values split
|
|
19
|
+
* across four **layers**, and the flags tracking where it sits in the
|
|
20
|
+
* create/update/delete lifecycle.
|
|
21
|
+
*
|
|
22
|
+
* A **projection** answers "what is this field's value" by reading a stack of
|
|
23
|
+
* layers top-down; the first layer holding the field wins. The two projections,
|
|
24
|
+
* with their resolution orders:
|
|
25
|
+
*
|
|
26
|
+
* - **remote state**, what the _immutable_ record reads:
|
|
27
|
+
* {@link RESOLUTION_ORDER_REMOTE_STATE}
|
|
28
|
+
* - **local state**, what an _editable_ copy reads:
|
|
29
|
+
* {@link RESOLUTION_ORDER_LOCAL_STATE}
|
|
30
|
+
*
|
|
31
|
+
* Local state is remote state with the uncommitted mutations laid over it. The
|
|
32
|
+
* guides call those mutations "the diff"; here they are simply the top layers of
|
|
33
|
+
* local state, {@link CachedResource.localAttrs | localAttrs} and
|
|
34
|
+
* {@link CachedResource.inflightAttrs | inflightAttrs}.
|
|
35
|
+
*
|
|
36
|
+
* A field is **dirty** while `localAttrs` or `inflightAttrs` holds it. A save
|
|
37
|
+
* **commits** the mutation: `didCommit` merges the in-flight values into
|
|
38
|
+
* `remoteAttrs` and removes them from `inflightAttrs`. A push carrying the same
|
|
39
|
+
* value as a pending edit in `localAttrs` has the same effect on that edit: the
|
|
40
|
+
* server already holds it, so it is removed from `localAttrs`. "Same value" is
|
|
41
|
+
* decided by the field's schema: a schema-object with an identity hash compares
|
|
42
|
+
* by that hash, everything else by reference.
|
|
43
|
+
*
|
|
44
|
+
* Thus, a dirty field reads as mutated for local readers only, and goes on doing
|
|
45
|
+
* so while its save is in flight.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
15
49
|
interface CachedResource {
|
|
50
|
+
/** The resource's id, once one is known. */
|
|
16
51
|
id: string | null;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The top layer of local state: uncommitted mutations, held apart from remote
|
|
54
|
+
* state. Any field with an entry here is dirty. Along with `inflightAttrs`,
|
|
55
|
+
* this is what the guides call "the diff".
|
|
56
|
+
*
|
|
57
|
+
* Starting a save moves these into `inflightAttrs`, so any further
|
|
58
|
+
* mutation accumulates here afresh without disturbing the request already
|
|
59
|
+
* in flight.
|
|
60
|
+
*/
|
|
61
|
+
localAttrs: AttrHash | null;
|
|
62
|
+
/**
|
|
63
|
+
* The middle layer of local state: the mutations an in-progress save is
|
|
64
|
+
* carrying.
|
|
65
|
+
*
|
|
66
|
+
* Completing a save merges these into
|
|
67
|
+
* {@link CachedResource.remoteAttrs | remoteAttrs} and clears this —
|
|
68
|
+
* committing them. A rejected save moves them back into `localAttrs`
|
|
69
|
+
* instead, without overwriting any newer edit made while it was in flight.
|
|
70
|
+
*/
|
|
71
|
+
inflightAttrs: AttrHash | null;
|
|
72
|
+
/** The top layer of remote state and the data layer beneath local state: the last known persisted values. */
|
|
73
|
+
remoteAttrs: AttrHash | null;
|
|
74
|
+
/**
|
|
75
|
+
* The bottom layer of both projections, consulted for fields no other layer
|
|
76
|
+
* holds. Only one kind of schema default is stored here: the result of a
|
|
77
|
+
* legacy `defaultValue()` *function*, memoized because the function returns a
|
|
78
|
+
* fresh value per call and the record must keep reading the same one. A
|
|
79
|
+
* primitive `options.defaultValue` or a transformation's `defaultValue()` is
|
|
80
|
+
* recomputed on every read instead. Never committed; an entry is dropped once
|
|
81
|
+
* the field gets a real value, whether from a local edit or from a merge into
|
|
82
|
+
* `remoteAttrs`.
|
|
83
|
+
*/
|
|
84
|
+
defaultAttrs: AttrHash | null;
|
|
85
|
+
/**
|
|
86
|
+
* Errors from the most recent rejected save. A successful commit clears
|
|
87
|
+
* them.
|
|
88
|
+
*/
|
|
22
89
|
errors: ApiError[] | null;
|
|
90
|
+
/**
|
|
91
|
+
* Whether this record was created locally and has never been persisted.
|
|
92
|
+
*
|
|
93
|
+
* A payload arriving for it (or a successful commit) clears the flag.
|
|
94
|
+
*/
|
|
23
95
|
isNew: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether this record is marked for deletion. Records the intent only;
|
|
98
|
+
* see {@link CachedResource.isDeletionCommitted | isDeletionCommitted} for
|
|
99
|
+
* whether the server has acted on it.
|
|
100
|
+
*/
|
|
24
101
|
isDeleted: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Whether the deletion is final: the server acknowledged it, or the record
|
|
104
|
+
* was never persisted and has been rolled back.
|
|
105
|
+
*
|
|
106
|
+
* Tracked separately from {@link CachedResource.isDeleted | isDeleted}
|
|
107
|
+
* because the two imply different cleanup: a *committed* deletion has already
|
|
108
|
+
* been announced as removed, so unloading the record must not announce it a
|
|
109
|
+
* second time.
|
|
110
|
+
*/
|
|
25
111
|
isDeletionCommitted: boolean;
|
|
26
112
|
/**
|
|
27
|
-
*
|
|
113
|
+
* The relationship state a save is carrying, retained so `DEBUG` builds can
|
|
114
|
+
* assert the response agrees with what was sent. Only populated in `DEBUG`
|
|
115
|
+
* builds, and only while the
|
|
116
|
+
* `DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE` deprecation is
|
|
117
|
+
* resolved.
|
|
28
118
|
*
|
|
29
119
|
* @internal
|
|
30
120
|
*/
|
|
@@ -52,7 +142,7 @@ interface CachedResource {
|
|
|
52
142
|
*
|
|
53
143
|
* @public
|
|
54
144
|
*/
|
|
55
|
-
declare class JSONAPICache implements Cache {
|
|
145
|
+
export declare class JSONAPICache implements Cache {
|
|
56
146
|
/**
|
|
57
147
|
* The Cache Version that this implementation implements.
|
|
58
148
|
*
|
|
@@ -73,9 +163,9 @@ declare class JSONAPICache implements Cache {
|
|
|
73
163
|
/**
|
|
74
164
|
* Cache the response to a request
|
|
75
165
|
*
|
|
76
|
-
* Implements
|
|
166
|
+
* Implements {@link Cache.put | Cache.put}.
|
|
77
167
|
*
|
|
78
|
-
* Expects a StructuredDocument whose `content` member is a JsonApiDocument.
|
|
168
|
+
* Expects a {@link StructuredDocument} whose `content` member is a JsonApiDocument.
|
|
79
169
|
*
|
|
80
170
|
* ```js
|
|
81
171
|
* cache.put({
|
|
@@ -123,6 +213,16 @@ declare class JSONAPICache implements Cache {
|
|
|
123
213
|
* Update the "remote" or "canonical" (persisted) state of the Cache
|
|
124
214
|
* by merging new information into the existing state.
|
|
125
215
|
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* cache.patch({
|
|
219
|
+
* op: 'update',
|
|
220
|
+
* record: identifier,
|
|
221
|
+
* field: 'name',
|
|
222
|
+
* value: 'Chris',
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
126
226
|
* @category Cache Management
|
|
127
227
|
* @public
|
|
128
228
|
* @param op the operation or list of operations to perform
|
|
@@ -131,6 +231,16 @@ declare class JSONAPICache implements Cache {
|
|
|
131
231
|
/**
|
|
132
232
|
* Update the "local" or "current" (unpersisted) state of the Cache
|
|
133
233
|
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* cache.mutate({
|
|
237
|
+
* op: 'replaceRelatedRecord',
|
|
238
|
+
* record: identifier,
|
|
239
|
+
* field: 'author',
|
|
240
|
+
* value: authorIdentifier,
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
134
244
|
* @category Cache Management
|
|
135
245
|
* @public
|
|
136
246
|
*/
|
|
@@ -155,8 +265,8 @@ declare class JSONAPICache implements Cache {
|
|
|
155
265
|
* not require retainining connections to the Store
|
|
156
266
|
* and Cache to present data on a per-field basis.
|
|
157
267
|
*
|
|
158
|
-
* This generally takes the place of
|
|
159
|
-
* an API and may even take the place of
|
|
268
|
+
* This generally takes the place of {@link JSONAPICache.getAttr | getAttr} as
|
|
269
|
+
* an API and may even take the place of {@link JSONAPICache.getRelationship | getRelationship}
|
|
160
270
|
* depending on implementation specifics, though this
|
|
161
271
|
* latter usage is less recommended due to the advantages
|
|
162
272
|
* of the Graph handling necessary entanglements and
|
|
@@ -171,6 +281,12 @@ declare class JSONAPICache implements Cache {
|
|
|
171
281
|
* the various internal WarpDrive bookkeeping fields.
|
|
172
282
|
* :::
|
|
173
283
|
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* const resource = cache.peek(identifier);
|
|
287
|
+
* const document = cache.peek(requestKey);
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
174
290
|
* @category Cache Management
|
|
175
291
|
* @public
|
|
176
292
|
*/
|
|
@@ -179,6 +295,12 @@ declare class JSONAPICache implements Cache {
|
|
|
179
295
|
/**
|
|
180
296
|
* Peek the remote resource data from the Cache.
|
|
181
297
|
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* const resource = cache.peekRemoteState(identifier);
|
|
301
|
+
* const document = cache.peekRemoteState(requestKey);
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
182
304
|
* @category Cache Management
|
|
183
305
|
* @public
|
|
184
306
|
*/
|
|
@@ -188,9 +310,14 @@ declare class JSONAPICache implements Cache {
|
|
|
188
310
|
* Peek the Cache for the existing request data associated with
|
|
189
311
|
* a cacheable request.
|
|
190
312
|
*
|
|
191
|
-
* This is effectively the reverse of
|
|
313
|
+
* This is effectively the reverse of {@link JSONAPICache.put | put} for a request in
|
|
192
314
|
* that it will return the the request, response, and content
|
|
193
|
-
* whereas
|
|
315
|
+
* whereas {@link JSONAPICache.peek | peek} will return just the `content`.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* const doc = cache.peekRequest(requestKey);
|
|
320
|
+
* ```
|
|
194
321
|
*
|
|
195
322
|
* @category Cache Management
|
|
196
323
|
* @public
|
|
@@ -199,9 +326,20 @@ declare class JSONAPICache implements Cache {
|
|
|
199
326
|
/**
|
|
200
327
|
* Push resource data from a remote source into the cache for this identifier
|
|
201
328
|
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* cache.upsert(identifier, {
|
|
332
|
+
* type: 'user',
|
|
333
|
+
* id: '1',
|
|
334
|
+
* attributes: { name: 'Chris' },
|
|
335
|
+
* });
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
202
338
|
* @category Cache Management
|
|
203
339
|
* @public
|
|
204
|
-
* @return
|
|
340
|
+
* @return when `calculateChanges` is true, the names of the attributes whose persisted value
|
|
341
|
+
* this push changed (the same keys the `'remote'` channel is notified with), or `undefined`
|
|
342
|
+
* when none did. Otherwise `void`.
|
|
205
343
|
*/
|
|
206
344
|
upsert(identifier: ResourceKey, data: ExistingResourceObject, calculateChanges?: boolean): void | string[];
|
|
207
345
|
/**
|
|
@@ -232,7 +370,7 @@ declare class JSONAPICache implements Cache {
|
|
|
232
370
|
*
|
|
233
371
|
* Each individual resource or document that has
|
|
234
372
|
* been mutated should be described as an individual
|
|
235
|
-
*
|
|
373
|
+
* {@link Change} entry in the returned array.
|
|
236
374
|
*
|
|
237
375
|
* A `Change` is described by an object containing up to
|
|
238
376
|
* three properties: (1) the `identifier` of the entity that
|
|
@@ -291,6 +429,11 @@ declare class JSONAPICache implements Cache {
|
|
|
291
429
|
* It returns properties from options that should be set on the record during the create
|
|
292
430
|
* process. This return value behavior is deprecated.
|
|
293
431
|
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```ts
|
|
434
|
+
* cache.clientDidCreate(identifier, { name: 'Chris' });
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
294
437
|
* @category Resource Lifecycle
|
|
295
438
|
* @public
|
|
296
439
|
*/
|
|
@@ -299,6 +442,11 @@ declare class JSONAPICache implements Cache {
|
|
|
299
442
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
300
443
|
* will be part of a save transaction.
|
|
301
444
|
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
* cache.willCommit(identifier, context);
|
|
448
|
+
* ```
|
|
449
|
+
*
|
|
302
450
|
* @category Resource Lifecycle
|
|
303
451
|
* @public
|
|
304
452
|
*/
|
|
@@ -307,16 +455,26 @@ declare class JSONAPICache implements Cache {
|
|
|
307
455
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
308
456
|
* was successfully updated as part of a save transaction.
|
|
309
457
|
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* cache.didCommit(identifier, result);
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
310
463
|
* @category Resource Lifecycle
|
|
311
464
|
* @public
|
|
312
465
|
*/
|
|
313
|
-
didCommit(committedIdentifier: ResourceKey, result: StructuredDataDocument<SingleResourceDataDocument
|
|
314
|
-
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<SingleResourceDataDocument
|
|
315
|
-
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<CollectionResourceDataDocument
|
|
466
|
+
didCommit(committedIdentifier: ResourceKey, result: StructuredDataDocument<SingleResourceDataDocument<ExistingResourceObject, ExistingResourceObject>> | null): SingleResourceDataDocument;
|
|
467
|
+
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<SingleResourceDataDocument<ExistingResourceObject, ExistingResourceObject>> | null): SingleResourceDataDocument;
|
|
468
|
+
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<CollectionResourceDataDocument<ExistingResourceObject>> | null): CollectionResourceDataDocument;
|
|
316
469
|
/**
|
|
317
470
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
318
471
|
* was update via a save transaction failed.
|
|
319
472
|
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* cache.commitWasRejected(identifier, errors);
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
320
478
|
* @category Resource Lifecycle
|
|
321
479
|
* @public
|
|
322
480
|
*/
|
|
@@ -327,6 +485,11 @@ declare class JSONAPICache implements Cache {
|
|
|
327
485
|
*
|
|
328
486
|
* This method is a candidate to become a mutation
|
|
329
487
|
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```ts
|
|
490
|
+
* cache.unloadRecord(identifier);
|
|
491
|
+
* ```
|
|
492
|
+
*
|
|
330
493
|
* @category Resource Lifecycle
|
|
331
494
|
* @public
|
|
332
495
|
*/
|
|
@@ -335,6 +498,12 @@ declare class JSONAPICache implements Cache {
|
|
|
335
498
|
* Retrieve the data for an attribute from the cache
|
|
336
499
|
* with local mutations applied.
|
|
337
500
|
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```ts
|
|
503
|
+
* const name = cache.getAttr(identifier, 'name');
|
|
504
|
+
* const zip = cache.getAttr(identifier, ['address', 'zip']);
|
|
505
|
+
* ```
|
|
506
|
+
*
|
|
338
507
|
* @category Resource Data
|
|
339
508
|
* @public
|
|
340
509
|
*/
|
|
@@ -342,6 +511,11 @@ declare class JSONAPICache implements Cache {
|
|
|
342
511
|
/**
|
|
343
512
|
* Retrieve the remote data for an attribute from the cache
|
|
344
513
|
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* const name = cache.getRemoteAttr(identifier, 'name');
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
345
519
|
* @category Resource Data
|
|
346
520
|
* @public
|
|
347
521
|
*/
|
|
@@ -351,12 +525,35 @@ declare class JSONAPICache implements Cache {
|
|
|
351
525
|
*
|
|
352
526
|
* This method is a candidate to become a mutation
|
|
353
527
|
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```ts
|
|
530
|
+
* cache.setAttr(identifier, 'name', 'Chris');
|
|
531
|
+
* ```
|
|
532
|
+
*
|
|
354
533
|
* @category Resource Data
|
|
355
534
|
* @public
|
|
356
535
|
*/
|
|
357
536
|
setAttr(identifier: ResourceKey, attr: string | string[], value: Value): void;
|
|
358
537
|
/**
|
|
359
|
-
* Query the cache for the changed attributes of a resource
|
|
538
|
+
* Query the cache for the changed attributes of a resource: every unsaved
|
|
539
|
+
* mutation, as a `[before, after]` pair per field.
|
|
540
|
+
*
|
|
541
|
+
* `before` is the value the mutation replaces, which is not always the
|
|
542
|
+
* persisted one. A mutation a save is carrying replaces remote state; an edit
|
|
543
|
+
* made while that save is in flight replaces the in-flight value. So this is
|
|
544
|
+
* what saving from here would change, which is what `serializePatch` and the
|
|
545
|
+
* legacy `Snapshot` consume, rather than a diff against persisted state.
|
|
546
|
+
*
|
|
547
|
+
* Derived from the layers on each call, so it is always consistent with
|
|
548
|
+
* {@link JSONAPICache.getAttr | getAttr} and
|
|
549
|
+
* {@link JSONAPICache.rollbackAttrs | rollbackAttrs}. Dirtiness does not go
|
|
550
|
+
* through here; see {@link JSONAPICache.hasChangedAttrs | hasChangedAttrs}.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* const changes = cache.changedAttrs(identifier);
|
|
555
|
+
* // { name: ['Igor', 'Chris'] }
|
|
556
|
+
* ```
|
|
360
557
|
*
|
|
361
558
|
* @category Resource Data
|
|
362
559
|
* @public
|
|
@@ -366,6 +563,13 @@ declare class JSONAPICache implements Cache {
|
|
|
366
563
|
/**
|
|
367
564
|
* Query the cache for whether any mutated attributes exist
|
|
368
565
|
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```ts
|
|
568
|
+
* if (cache.hasChangedAttrs(identifier)) {
|
|
569
|
+
* // ...
|
|
570
|
+
* }
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
369
573
|
* @category Resource Data
|
|
370
574
|
* @public
|
|
371
575
|
*/
|
|
@@ -375,6 +579,11 @@ declare class JSONAPICache implements Cache {
|
|
|
375
579
|
*
|
|
376
580
|
* This method is a candidate to become a mutation
|
|
377
581
|
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* const restoredKeys = cache.rollbackAttrs(identifier);
|
|
585
|
+
* ```
|
|
586
|
+
*
|
|
378
587
|
* @category Resource Data
|
|
379
588
|
* @public
|
|
380
589
|
* @return the names of fields that were restored
|
|
@@ -383,7 +592,7 @@ declare class JSONAPICache implements Cache {
|
|
|
383
592
|
/**
|
|
384
593
|
* Query the cache for the changes to relationships of a resource.
|
|
385
594
|
*
|
|
386
|
-
* Returns a map of relationship names to RelationshipDiff objects.
|
|
595
|
+
* Returns a map of relationship names to {@link RelationshipDiff} objects.
|
|
387
596
|
*
|
|
388
597
|
* ```ts
|
|
389
598
|
* type RelationshipDiff =
|
|
@@ -402,6 +611,12 @@ declare class JSONAPICache implements Cache {
|
|
|
402
611
|
};
|
|
403
612
|
```
|
|
404
613
|
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* const diffs = cache.changedRelationships(identifier);
|
|
617
|
+
* const comments = diffs.get('comments');
|
|
618
|
+
* ```
|
|
619
|
+
*
|
|
405
620
|
* @category Resource Data
|
|
406
621
|
* @public
|
|
407
622
|
*/
|
|
@@ -409,6 +624,13 @@ declare class JSONAPICache implements Cache {
|
|
|
409
624
|
/**
|
|
410
625
|
* Query the cache for whether any mutated relationships exist
|
|
411
626
|
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* if (cache.hasChangedRelationships(identifier)) {
|
|
630
|
+
* // ...
|
|
631
|
+
* }
|
|
632
|
+
* ```
|
|
633
|
+
*
|
|
412
634
|
* @category Resource Data
|
|
413
635
|
* @public
|
|
414
636
|
*/
|
|
@@ -420,6 +642,11 @@ declare class JSONAPICache implements Cache {
|
|
|
420
642
|
*
|
|
421
643
|
* This method is a candidate to become a mutation
|
|
422
644
|
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```ts
|
|
647
|
+
* const restoredFields = cache.rollbackRelationships(identifier);
|
|
648
|
+
* ```
|
|
649
|
+
*
|
|
423
650
|
* @category Resource Data
|
|
424
651
|
* @public
|
|
425
652
|
* @return the names of relationships that were restored
|
|
@@ -428,6 +655,11 @@ declare class JSONAPICache implements Cache {
|
|
|
428
655
|
/**
|
|
429
656
|
* Query the cache for the current state of a relationship property
|
|
430
657
|
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```ts
|
|
660
|
+
* const relationship = cache.getRelationship(identifier, 'comments');
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
431
663
|
* @category Resource Data
|
|
432
664
|
* @public
|
|
433
665
|
* @return resource relationship object
|
|
@@ -436,6 +668,11 @@ declare class JSONAPICache implements Cache {
|
|
|
436
668
|
/**
|
|
437
669
|
* Query the cache for the remote state of a relationship property
|
|
438
670
|
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* const relationship = cache.getRemoteRelationship(identifier, 'comments');
|
|
674
|
+
* ```
|
|
675
|
+
*
|
|
439
676
|
* @category Resource Data
|
|
440
677
|
* @public
|
|
441
678
|
* @return resource relationship object
|
|
@@ -447,6 +684,11 @@ declare class JSONAPICache implements Cache {
|
|
|
447
684
|
*
|
|
448
685
|
* This method is a candidate to become a mutation
|
|
449
686
|
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```ts
|
|
689
|
+
* cache.setIsDeleted(identifier, true);
|
|
690
|
+
* ```
|
|
691
|
+
*
|
|
450
692
|
* @category Resource State
|
|
451
693
|
* @public
|
|
452
694
|
*/
|
|
@@ -454,6 +696,11 @@ declare class JSONAPICache implements Cache {
|
|
|
454
696
|
/**
|
|
455
697
|
* Query the cache for any validation errors applicable to the given resource.
|
|
456
698
|
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* const errors = cache.getErrors(identifier);
|
|
702
|
+
* ```
|
|
703
|
+
*
|
|
457
704
|
* @category Resource State
|
|
458
705
|
* @public
|
|
459
706
|
*/
|
|
@@ -461,6 +708,13 @@ declare class JSONAPICache implements Cache {
|
|
|
461
708
|
/**
|
|
462
709
|
* Query the cache for whether a given resource has any available data
|
|
463
710
|
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```ts
|
|
713
|
+
* if (cache.isEmpty(identifier)) {
|
|
714
|
+
* // ...
|
|
715
|
+
* }
|
|
716
|
+
* ```
|
|
717
|
+
*
|
|
464
718
|
* @category Resource State
|
|
465
719
|
* @public
|
|
466
720
|
*/
|
|
@@ -469,6 +723,13 @@ declare class JSONAPICache implements Cache {
|
|
|
469
723
|
* Query the cache for whether a given resource was created locally and not
|
|
470
724
|
* yet persisted.
|
|
471
725
|
*
|
|
726
|
+
* @example
|
|
727
|
+
* ```ts
|
|
728
|
+
* if (cache.isNew(identifier)) {
|
|
729
|
+
* // ...
|
|
730
|
+
* }
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
472
733
|
* @category Resource State
|
|
473
734
|
* @public
|
|
474
735
|
*/
|
|
@@ -477,6 +738,13 @@ declare class JSONAPICache implements Cache {
|
|
|
477
738
|
* Query the cache for whether a given resource is marked as deleted (but not
|
|
478
739
|
* necessarily persisted yet).
|
|
479
740
|
*
|
|
741
|
+
* @example
|
|
742
|
+
* ```ts
|
|
743
|
+
* if (cache.isDeleted(identifier)) {
|
|
744
|
+
* // ...
|
|
745
|
+
* }
|
|
746
|
+
* ```
|
|
747
|
+
*
|
|
480
748
|
* @category Resource State
|
|
481
749
|
* @public
|
|
482
750
|
*/
|
|
@@ -485,6 +753,13 @@ declare class JSONAPICache implements Cache {
|
|
|
485
753
|
* Query the cache for whether a given resource has been deleted and that deletion
|
|
486
754
|
* has also been persisted.
|
|
487
755
|
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```ts
|
|
758
|
+
* if (cache.isDeletionCommitted(identifier)) {
|
|
759
|
+
* // ...
|
|
760
|
+
* }
|
|
761
|
+
* ```
|
|
762
|
+
*
|
|
488
763
|
* @category Resource State
|
|
489
764
|
* @public
|
|
490
765
|
*/
|
|
@@ -511,5 +786,4 @@ declare class JSONAPICache implements Cache {
|
|
|
511
786
|
__peek(identifier: ResourceKey, allowDestroyed: boolean): CachedResource;
|
|
512
787
|
}
|
|
513
788
|
//#endregion
|
|
514
|
-
export { JSONAPICache };
|
|
515
789
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/-private/cache.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/-private/cache.ts"],"mappings":";;;;;;;;;;;;;;;KA4FK,WAAW,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAkCrB;;EAER;;;;;;;;;;EAWA,YAAY;;;;;;;;;;EAWZ,eAAe;;EAGf,aAAa;;;;;;;;;;;EAYb,cAAc;;;;;EAMd,QAAQ;;;;;;EAOR;;;;;;EAOA;;;;;;;;;;EAWA;;;;;;;;;;EAWA,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;qBA6Gb,wBAAwB;;;;;;EAMnC;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