@warp-drive-mirror/json-api 5.7.0-alpha.14 → 5.7.0-alpha.15
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 +44 -44
- package/dist/index.js +25 -25
- package/package.json +4 -4
|
@@ -5,9 +5,9 @@ import type { Change } from "@warp-drive-mirror/core/types/cache/change";
|
|
|
5
5
|
import type { Operation } from "@warp-drive-mirror/core/types/cache/operations";
|
|
6
6
|
import type { CollectionRelationship, ResourceRelationship } from "@warp-drive-mirror/core/types/cache/relationship";
|
|
7
7
|
import type { LocalRelationshipOperation } from "@warp-drive-mirror/core/types/graph";
|
|
8
|
-
import type {
|
|
8
|
+
import type { PersistedResourceKey, RequestKey, ResourceKey } from "@warp-drive-mirror/core/types/identifier";
|
|
9
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";
|
|
10
|
+
import type { RequestContext, StructuredDataDocument, StructuredDocument, StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
|
|
11
11
|
import type { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDocument, ResourceMetaDocument, SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
12
12
|
import type { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
13
13
|
import type { CollectionResourceDocument, ExistingResourceObject, ResourceObject, SingleResourceDocument } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
@@ -131,9 +131,9 @@ export declare class JSONAPICache implements Cache {
|
|
|
131
131
|
/** @internal */
|
|
132
132
|
_capabilities: CacheCapabilitiesManager;
|
|
133
133
|
/** @internal */
|
|
134
|
-
__cache: Map<
|
|
134
|
+
__cache: Map<ResourceKey, CachedResource>;
|
|
135
135
|
/** @internal */
|
|
136
|
-
__destroyedCache: Map<
|
|
136
|
+
__destroyedCache: Map<ResourceKey, CachedResource>;
|
|
137
137
|
/** @internal */
|
|
138
138
|
__documents: Map<string, StructuredDocument<ResourceDocument>>;
|
|
139
139
|
/** @internal */
|
|
@@ -186,8 +186,8 @@ export declare class JSONAPICache implements Cache {
|
|
|
186
186
|
/** @internal */
|
|
187
187
|
_putDocument<T extends ResourceErrorDocument>(doc: StructuredErrorDocument<T>, data: undefined, included: undefined): ResourceErrorDocument;
|
|
188
188
|
_putDocument<T extends ResourceMetaDocument>(doc: StructuredDataDocument<T>, data: undefined, included: undefined): ResourceMetaDocument;
|
|
189
|
-
_putDocument<T extends SingleResourceDocument>(doc: StructuredDataDocument<T>, data:
|
|
190
|
-
_putDocument<T extends CollectionResourceDocument>(doc: StructuredDataDocument<T>, data:
|
|
189
|
+
_putDocument<T extends SingleResourceDocument>(doc: StructuredDataDocument<T>, data: PersistedResourceKey | null, included: PersistedResourceKey[] | undefined): SingleResourceDataDocument;
|
|
190
|
+
_putDocument<T extends CollectionResourceDocument>(doc: StructuredDataDocument<T>, data: PersistedResourceKey[], included: PersistedResourceKey[] | undefined): CollectionResourceDataDocument;
|
|
191
191
|
/**
|
|
192
192
|
* Update the "remote" or "canonical" (persisted) state of the Cache
|
|
193
193
|
* by merging new information into the existing state.
|
|
@@ -234,16 +234,16 @@ export declare class JSONAPICache implements Cache {
|
|
|
234
234
|
* @category Cache Management
|
|
235
235
|
* @public
|
|
236
236
|
*/
|
|
237
|
-
peek(identifier:
|
|
238
|
-
peek(identifier:
|
|
237
|
+
peek(identifier: ResourceKey): ResourceObject | null;
|
|
238
|
+
peek(identifier: RequestKey): ResourceDocument | null;
|
|
239
239
|
/**
|
|
240
240
|
* Peek the remote resource data from the Cache.
|
|
241
241
|
*
|
|
242
242
|
* @category Cache Management
|
|
243
243
|
* @public
|
|
244
244
|
*/
|
|
245
|
-
peekRemoteState(identifier:
|
|
246
|
-
peekRemoteState(identifier:
|
|
245
|
+
peekRemoteState(identifier: ResourceKey): ResourceObject | null;
|
|
246
|
+
peekRemoteState(identifier: RequestKey): ResourceDocument | null;
|
|
247
247
|
/**
|
|
248
248
|
* Peek the Cache for the existing request data associated with
|
|
249
249
|
* a cacheable request.
|
|
@@ -255,7 +255,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
255
255
|
* @category Cache Management
|
|
256
256
|
* @public
|
|
257
257
|
*/
|
|
258
|
-
peekRequest(identifier:
|
|
258
|
+
peekRequest(identifier: RequestKey): StructuredDocument<ResourceDocument> | null;
|
|
259
259
|
/**
|
|
260
260
|
* Push resource data from a remote source into the cache for this identifier
|
|
261
261
|
*
|
|
@@ -263,7 +263,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
263
263
|
* @public
|
|
264
264
|
* @return if `calculateChanges` is true then calculated key changes should be returned
|
|
265
265
|
*/
|
|
266
|
-
upsert(identifier:
|
|
266
|
+
upsert(identifier: ResourceKey, data: ExistingResourceObject, calculateChanges?: boolean): void | string[];
|
|
267
267
|
////////// ============= //////////
|
|
268
268
|
////////// Cache Forking //////////
|
|
269
269
|
////////// ============= //////////
|
|
@@ -313,7 +313,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
313
313
|
*
|
|
314
314
|
* ```ts
|
|
315
315
|
* interface Change {
|
|
316
|
-
* identifier:
|
|
316
|
+
* identifier: ResourceKey | RequestKey;
|
|
317
317
|
* op: 'upsert' | 'remove';
|
|
318
318
|
* patch?: unknown;
|
|
319
319
|
* }
|
|
@@ -363,7 +363,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
363
363
|
* @category Resource Lifecycle
|
|
364
364
|
* @public
|
|
365
365
|
*/
|
|
366
|
-
clientDidCreate(identifier:
|
|
366
|
+
clientDidCreate(identifier: ResourceKey, options?: Record<string, Value>): Record<string, unknown>;
|
|
367
367
|
/**
|
|
368
368
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
369
369
|
* will be part of a save transaction.
|
|
@@ -371,7 +371,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
371
371
|
* @category Resource Lifecycle
|
|
372
372
|
* @public
|
|
373
373
|
*/
|
|
374
|
-
willCommit(identifier:
|
|
374
|
+
willCommit(identifier: ResourceKey, _context: RequestContext | null): void;
|
|
375
375
|
/**
|
|
376
376
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
377
377
|
* was successfully updated as part of a save transaction.
|
|
@@ -379,7 +379,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
379
379
|
* @category Resource Lifecycle
|
|
380
380
|
* @public
|
|
381
381
|
*/
|
|
382
|
-
didCommit(committedIdentifier:
|
|
382
|
+
didCommit(committedIdentifier: ResourceKey, result: StructuredDataDocument<SingleResourceDocument> | null): SingleResourceDataDocument;
|
|
383
383
|
/**
|
|
384
384
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
385
385
|
* was update via a save transaction failed.
|
|
@@ -387,7 +387,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
387
387
|
* @category Resource Lifecycle
|
|
388
388
|
* @public
|
|
389
389
|
*/
|
|
390
|
-
commitWasRejected(identifier:
|
|
390
|
+
commitWasRejected(identifier: ResourceKey, errors?: ApiError[]): void;
|
|
391
391
|
/**
|
|
392
392
|
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
393
393
|
* should be cleared.
|
|
@@ -397,7 +397,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
397
397
|
* @category Resource Lifecycle
|
|
398
398
|
* @public
|
|
399
399
|
*/
|
|
400
|
-
unloadRecord(identifier:
|
|
400
|
+
unloadRecord(identifier: ResourceKey): void;
|
|
401
401
|
////////// ============= //////////
|
|
402
402
|
////////// Resource Data //////////
|
|
403
403
|
////////// ============= //////////
|
|
@@ -408,14 +408,14 @@ export declare class JSONAPICache implements Cache {
|
|
|
408
408
|
* @category Resource Data
|
|
409
409
|
* @public
|
|
410
410
|
*/
|
|
411
|
-
getAttr(identifier:
|
|
411
|
+
getAttr(identifier: ResourceKey, attr: string | string[]): Value | undefined;
|
|
412
412
|
/**
|
|
413
413
|
* Retrieve the remote data for an attribute from the cache
|
|
414
414
|
*
|
|
415
415
|
* @category Resource Data
|
|
416
416
|
* @public
|
|
417
417
|
*/
|
|
418
|
-
getRemoteAttr(identifier:
|
|
418
|
+
getRemoteAttr(identifier: ResourceKey, attr: string | string[]): Value | undefined;
|
|
419
419
|
/**
|
|
420
420
|
* Mutate the data for an attribute in the cache
|
|
421
421
|
*
|
|
@@ -424,7 +424,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
424
424
|
* @category Resource Data
|
|
425
425
|
* @public
|
|
426
426
|
*/
|
|
427
|
-
setAttr(identifier:
|
|
427
|
+
setAttr(identifier: ResourceKey, attr: string | string[], value: Value): void;
|
|
428
428
|
/**
|
|
429
429
|
* Query the cache for the changed attributes of a resource.
|
|
430
430
|
*
|
|
@@ -432,14 +432,14 @@ export declare class JSONAPICache implements Cache {
|
|
|
432
432
|
* @public
|
|
433
433
|
* @return `{ '<field>': ['<old>', '<new>'] }`
|
|
434
434
|
*/
|
|
435
|
-
changedAttrs(identifier:
|
|
435
|
+
changedAttrs(identifier: ResourceKey): ChangedAttributesHash;
|
|
436
436
|
/**
|
|
437
437
|
* Query the cache for whether any mutated attributes exist
|
|
438
438
|
*
|
|
439
439
|
* @category Resource Data
|
|
440
440
|
* @public
|
|
441
441
|
*/
|
|
442
|
-
hasChangedAttrs(identifier:
|
|
442
|
+
hasChangedAttrs(identifier: ResourceKey): boolean;
|
|
443
443
|
/**
|
|
444
444
|
* Tell the cache to discard any uncommitted mutations to attributes
|
|
445
445
|
*
|
|
@@ -449,7 +449,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
449
449
|
* @public
|
|
450
450
|
* @return the names of fields that were restored
|
|
451
451
|
*/
|
|
452
|
-
rollbackAttrs(identifier:
|
|
452
|
+
rollbackAttrs(identifier: ResourceKey): string[];
|
|
453
453
|
/**
|
|
454
454
|
* Query the cache for the changes to relationships of a resource.
|
|
455
455
|
*
|
|
@@ -459,30 +459,30 @@ export declare class JSONAPICache implements Cache {
|
|
|
459
459
|
* type RelationshipDiff =
|
|
460
460
|
| {
|
|
461
461
|
kind: 'collection';
|
|
462
|
-
remoteState:
|
|
463
|
-
additions: Set<
|
|
464
|
-
removals: Set<
|
|
465
|
-
localState:
|
|
462
|
+
remoteState: ResourceKey[];
|
|
463
|
+
additions: Set<ResourceKey>;
|
|
464
|
+
removals: Set<ResourceKey>;
|
|
465
|
+
localState: ResourceKey[];
|
|
466
466
|
reordered: boolean;
|
|
467
467
|
}
|
|
468
468
|
| {
|
|
469
469
|
kind: 'resource';
|
|
470
|
-
remoteState:
|
|
471
|
-
localState:
|
|
470
|
+
remoteState: ResourceKey | null;
|
|
471
|
+
localState: ResourceKey | null;
|
|
472
472
|
};
|
|
473
473
|
```
|
|
474
474
|
*
|
|
475
475
|
* @category Resource Data
|
|
476
476
|
* @public
|
|
477
477
|
*/
|
|
478
|
-
changedRelationships(identifier:
|
|
478
|
+
changedRelationships(identifier: ResourceKey): Map<string, RelationshipDiff>;
|
|
479
479
|
/**
|
|
480
480
|
* Query the cache for whether any mutated relationships exist
|
|
481
481
|
*
|
|
482
482
|
* @category Resource Data
|
|
483
483
|
* @public
|
|
484
484
|
*/
|
|
485
|
-
hasChangedRelationships(identifier:
|
|
485
|
+
hasChangedRelationships(identifier: ResourceKey): boolean;
|
|
486
486
|
/**
|
|
487
487
|
* Tell the cache to discard any uncommitted mutations to relationships.
|
|
488
488
|
*
|
|
@@ -494,7 +494,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
494
494
|
* @public
|
|
495
495
|
* @return the names of relationships that were restored
|
|
496
496
|
*/
|
|
497
|
-
rollbackRelationships(identifier:
|
|
497
|
+
rollbackRelationships(identifier: ResourceKey): string[];
|
|
498
498
|
/**
|
|
499
499
|
* Query the cache for the current state of a relationship property
|
|
500
500
|
*
|
|
@@ -502,7 +502,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
502
502
|
* @public
|
|
503
503
|
* @return resource relationship object
|
|
504
504
|
*/
|
|
505
|
-
getRelationship(identifier:
|
|
505
|
+
getRelationship(identifier: ResourceKey, field: string): ResourceRelationship | CollectionRelationship;
|
|
506
506
|
/**
|
|
507
507
|
* Query the cache for the remote state of a relationship property
|
|
508
508
|
*
|
|
@@ -510,7 +510,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
510
510
|
* @public
|
|
511
511
|
* @return resource relationship object
|
|
512
512
|
*/
|
|
513
|
-
getRemoteRelationship(identifier:
|
|
513
|
+
getRemoteRelationship(identifier: ResourceKey, field: string): ResourceRelationship | CollectionRelationship;
|
|
514
514
|
////////// ============== //////////
|
|
515
515
|
////////// Resource State //////////
|
|
516
516
|
////////// ============== //////////
|
|
@@ -523,21 +523,21 @@ export declare class JSONAPICache implements Cache {
|
|
|
523
523
|
* @category Resource State
|
|
524
524
|
* @public
|
|
525
525
|
*/
|
|
526
|
-
setIsDeleted(identifier:
|
|
526
|
+
setIsDeleted(identifier: ResourceKey, isDeleted: boolean): void;
|
|
527
527
|
/**
|
|
528
528
|
* Query the cache for any validation errors applicable to the given resource.
|
|
529
529
|
*
|
|
530
530
|
* @category Resource State
|
|
531
531
|
* @public
|
|
532
532
|
*/
|
|
533
|
-
getErrors(identifier:
|
|
533
|
+
getErrors(identifier: ResourceKey): ApiError[];
|
|
534
534
|
/**
|
|
535
535
|
* Query the cache for whether a given resource has any available data
|
|
536
536
|
*
|
|
537
537
|
* @category Resource State
|
|
538
538
|
* @public
|
|
539
539
|
*/
|
|
540
|
-
isEmpty(identifier:
|
|
540
|
+
isEmpty(identifier: ResourceKey): boolean;
|
|
541
541
|
/**
|
|
542
542
|
* Query the cache for whether a given resource was created locally and not
|
|
543
543
|
* yet persisted.
|
|
@@ -545,7 +545,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
545
545
|
* @category Resource State
|
|
546
546
|
* @public
|
|
547
547
|
*/
|
|
548
|
-
isNew(identifier:
|
|
548
|
+
isNew(identifier: ResourceKey): boolean;
|
|
549
549
|
/**
|
|
550
550
|
* Query the cache for whether a given resource is marked as deleted (but not
|
|
551
551
|
* necessarily persisted yet).
|
|
@@ -553,7 +553,7 @@ export declare class JSONAPICache implements Cache {
|
|
|
553
553
|
* @category Resource State
|
|
554
554
|
* @public
|
|
555
555
|
*/
|
|
556
|
-
isDeleted(identifier:
|
|
556
|
+
isDeleted(identifier: ResourceKey): boolean;
|
|
557
557
|
/**
|
|
558
558
|
* Query the cache for whether a given resource has been deleted and that deletion
|
|
559
559
|
* has also been persisted.
|
|
@@ -561,26 +561,26 @@ export declare class JSONAPICache implements Cache {
|
|
|
561
561
|
* @category Resource State
|
|
562
562
|
* @public
|
|
563
563
|
*/
|
|
564
|
-
isDeletionCommitted(identifier:
|
|
564
|
+
isDeletionCommitted(identifier: ResourceKey): boolean;
|
|
565
565
|
/**
|
|
566
566
|
* Private method used to populate an entry for the identifier
|
|
567
567
|
*
|
|
568
568
|
* @internal
|
|
569
569
|
*/
|
|
570
|
-
_createCache(identifier:
|
|
570
|
+
_createCache(identifier: ResourceKey): CachedResource;
|
|
571
571
|
/**
|
|
572
572
|
* Peek whether we have cached resource data matching the identifier
|
|
573
573
|
* without asserting if the resource data is missing.
|
|
574
574
|
*
|
|
575
575
|
* @internal
|
|
576
576
|
*/
|
|
577
|
-
__safePeek(identifier:
|
|
577
|
+
__safePeek(identifier: ResourceKey, allowDestroyed: boolean): CachedResource | undefined;
|
|
578
578
|
/**
|
|
579
579
|
* Peek whether we have cached resource data matching the identifier
|
|
580
580
|
* Asserts if the resource data is missing.
|
|
581
581
|
*
|
|
582
582
|
* @internal
|
|
583
583
|
*/
|
|
584
|
-
__peek(identifier:
|
|
584
|
+
__peek(identifier: ResourceKey, allowDestroyed: boolean): CachedResource;
|
|
585
585
|
}
|
|
586
586
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { graphFor, peekGraph, isBelongsTo } from '@warp-drive-mirror/core/graph/-private';
|
|
2
|
-
import { logGroup,
|
|
2
|
+
import { logGroup, isResourceKey, isRequestKey } from '@warp-drive-mirror/core/store/-private';
|
|
3
3
|
import Fuse from 'fuse.js';
|
|
4
4
|
import jsonToAst from 'json-to-ast';
|
|
5
5
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
@@ -1129,7 +1129,7 @@ class JSONAPICache {
|
|
|
1129
1129
|
const included = jsonApiDoc.included;
|
|
1130
1130
|
let i, length;
|
|
1131
1131
|
const {
|
|
1132
|
-
|
|
1132
|
+
cacheKeyManager
|
|
1133
1133
|
} = this._capabilities;
|
|
1134
1134
|
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
1135
1135
|
validateDocumentFields(this._capabilities.schema, jsonApiDoc);
|
|
@@ -1181,21 +1181,21 @@ class JSONAPICache {
|
|
|
1181
1181
|
}
|
|
1182
1182
|
if (included) {
|
|
1183
1183
|
for (i = 0, length = included.length; i < length; i++) {
|
|
1184
|
-
included[i] = putOne(this,
|
|
1184
|
+
included[i] = putOne(this, cacheKeyManager, included[i]);
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
1187
1187
|
if (Array.isArray(jsonApiDoc.data)) {
|
|
1188
1188
|
length = jsonApiDoc.data.length;
|
|
1189
1189
|
const identifiers = [];
|
|
1190
1190
|
for (i = 0; i < length; i++) {
|
|
1191
|
-
identifiers.push(putOne(this,
|
|
1191
|
+
identifiers.push(putOne(this, cacheKeyManager, jsonApiDoc.data[i]));
|
|
1192
1192
|
}
|
|
1193
1193
|
return this._putDocument(doc, identifiers, included);
|
|
1194
1194
|
}
|
|
1195
1195
|
if (jsonApiDoc.data === null) {
|
|
1196
1196
|
return this._putDocument(doc, null, included);
|
|
1197
1197
|
}
|
|
1198
|
-
const identifier = putOne(this,
|
|
1198
|
+
const identifier = putOne(this, cacheKeyManager, jsonApiDoc.data);
|
|
1199
1199
|
return this._putDocument(doc, identifier, included);
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
@@ -1221,7 +1221,7 @@ class JSONAPICache {
|
|
|
1221
1221
|
resourceDocument.included = included;
|
|
1222
1222
|
}
|
|
1223
1223
|
const request = doc.request;
|
|
1224
|
-
const identifier = request ? this._capabilities.
|
|
1224
|
+
const identifier = request ? this._capabilities.cacheKeyManager.getOrCreateDocumentIdentifier(request) : null;
|
|
1225
1225
|
if (identifier) {
|
|
1226
1226
|
resourceDocument.lid = identifier.lid;
|
|
1227
1227
|
|
|
@@ -1243,7 +1243,7 @@ class JSONAPICache {
|
|
|
1243
1243
|
if (!test) {
|
|
1244
1244
|
throw new Error(`Expected a parent identifier for a findHasMany request`);
|
|
1245
1245
|
}
|
|
1246
|
-
})(parentIdentifier &&
|
|
1246
|
+
})(parentIdentifier && isResourceKey(parentIdentifier)) : {};
|
|
1247
1247
|
if (parentField && parentIdentifier) {
|
|
1248
1248
|
this.__graph.push({
|
|
1249
1249
|
op: 'updateRelationship',
|
|
@@ -1349,7 +1349,7 @@ class JSONAPICache {
|
|
|
1349
1349
|
*/
|
|
1350
1350
|
|
|
1351
1351
|
peek(identifier) {
|
|
1352
|
-
if (
|
|
1352
|
+
if (isResourceKey(identifier)) {
|
|
1353
1353
|
const peeked = this.__safePeek(identifier, false);
|
|
1354
1354
|
if (!peeked) {
|
|
1355
1355
|
return null;
|
|
@@ -1407,7 +1407,7 @@ class JSONAPICache {
|
|
|
1407
1407
|
*/
|
|
1408
1408
|
|
|
1409
1409
|
peekRemoteState(identifier) {
|
|
1410
|
-
if (
|
|
1410
|
+
if (isResourceKey(identifier)) {
|
|
1411
1411
|
const peeked = this.__safePeek(identifier, false);
|
|
1412
1412
|
if (!peeked) {
|
|
1413
1413
|
return null;
|
|
@@ -1548,7 +1548,7 @@ class JSONAPICache {
|
|
|
1548
1548
|
*
|
|
1549
1549
|
* ```ts
|
|
1550
1550
|
* interface Change {
|
|
1551
|
-
* identifier:
|
|
1551
|
+
* identifier: ResourceKey | RequestKey;
|
|
1552
1552
|
* op: 'upsert' | 'remove';
|
|
1553
1553
|
* patch?: unknown;
|
|
1554
1554
|
* }
|
|
@@ -1682,7 +1682,7 @@ class JSONAPICache {
|
|
|
1682
1682
|
* @category Resource Lifecycle
|
|
1683
1683
|
* @public
|
|
1684
1684
|
*/
|
|
1685
|
-
willCommit(identifier) {
|
|
1685
|
+
willCommit(identifier, _context) {
|
|
1686
1686
|
const cached = this.__peek(identifier, false);
|
|
1687
1687
|
|
|
1688
1688
|
/*
|
|
@@ -1738,8 +1738,8 @@ class JSONAPICache {
|
|
|
1738
1738
|
* @public
|
|
1739
1739
|
*/
|
|
1740
1740
|
didCommit(committedIdentifier, result) {
|
|
1741
|
-
const payload = result.content;
|
|
1742
|
-
const operation = result.request.op;
|
|
1741
|
+
const payload = result ? result.content : null;
|
|
1742
|
+
const operation = result ? result.request.op : null;
|
|
1743
1743
|
const data = payload && payload.data;
|
|
1744
1744
|
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_CACHE)) {
|
|
1745
1745
|
if (getGlobalConfig().WarpDriveMirror.debug.LOG_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE) {
|
|
@@ -1761,10 +1761,10 @@ class JSONAPICache {
|
|
|
1761
1761
|
})(committedIdentifier.id) : {};
|
|
1762
1762
|
}
|
|
1763
1763
|
const {
|
|
1764
|
-
|
|
1764
|
+
cacheKeyManager
|
|
1765
1765
|
} = this._capabilities;
|
|
1766
1766
|
const existingId = committedIdentifier.id;
|
|
1767
|
-
const identifier = operation !== 'deleteRecord' && data ?
|
|
1767
|
+
const identifier = operation !== 'deleteRecord' && data ? cacheKeyManager.updateRecordIdentifier(committedIdentifier, data) : committedIdentifier;
|
|
1768
1768
|
const cached = this.__peek(identifier, false);
|
|
1769
1769
|
if (cached.isDeleted) {
|
|
1770
1770
|
this.__graph.push({
|
|
@@ -1814,7 +1814,7 @@ class JSONAPICache {
|
|
|
1814
1814
|
if (!inFlightData || !('data' in inFlightData)) {
|
|
1815
1815
|
return;
|
|
1816
1816
|
}
|
|
1817
|
-
const actualData = relationshipData ? this._capabilities.
|
|
1817
|
+
const actualData = relationshipData ? this._capabilities.cacheKeyManager.getOrCreateRecordIdentifier(relationshipData) : null;
|
|
1818
1818
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1819
1819
|
if (!test) {
|
|
1820
1820
|
throw new Error(`Expected the resource relationship '<${identifier.type}>.${name}' on ${identifier.lid} to be saved as ${inFlightData.data ? inFlightData.data.lid : '<null>'} but it was saved as ${actualData ? actualData.lid : '<null>'}`);
|
|
@@ -1843,7 +1843,7 @@ class JSONAPICache {
|
|
|
1843
1843
|
const included = payload && payload.included;
|
|
1844
1844
|
if (included) {
|
|
1845
1845
|
for (let i = 0, length = included.length; i < length; i++) {
|
|
1846
|
-
putOne(this,
|
|
1846
|
+
putOne(this, cacheKeyManager, included[i]);
|
|
1847
1847
|
}
|
|
1848
1848
|
}
|
|
1849
1849
|
return {
|
|
@@ -2281,16 +2281,16 @@ class JSONAPICache {
|
|
|
2281
2281
|
* type RelationshipDiff =
|
|
2282
2282
|
| {
|
|
2283
2283
|
kind: 'collection';
|
|
2284
|
-
remoteState:
|
|
2285
|
-
additions: Set<
|
|
2286
|
-
removals: Set<
|
|
2287
|
-
localState:
|
|
2284
|
+
remoteState: ResourceKey[];
|
|
2285
|
+
additions: Set<ResourceKey>;
|
|
2286
|
+
removals: Set<ResourceKey>;
|
|
2287
|
+
localState: ResourceKey[];
|
|
2288
2288
|
reordered: boolean;
|
|
2289
2289
|
}
|
|
2290
2290
|
| {
|
|
2291
2291
|
kind: 'resource';
|
|
2292
|
-
remoteState:
|
|
2293
|
-
localState:
|
|
2292
|
+
remoteState: ResourceKey | null;
|
|
2293
|
+
localState: ResourceKey | null;
|
|
2294
2294
|
};
|
|
2295
2295
|
```
|
|
2296
2296
|
*
|
|
@@ -3080,8 +3080,8 @@ function cacheUpsert(cache, identifier, data, calculateChanges) {
|
|
|
3080
3080
|
return changedKeys?.size ? Array.from(changedKeys) : undefined;
|
|
3081
3081
|
}
|
|
3082
3082
|
function patchCache(Cache, op) {
|
|
3083
|
-
const isRecord =
|
|
3084
|
-
const isDocument = !isRecord &&
|
|
3083
|
+
const isRecord = isResourceKey(op.record);
|
|
3084
|
+
const isDocument = !isRecord && isRequestKey(op.record);
|
|
3085
3085
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3086
3086
|
if (!test) {
|
|
3087
3087
|
throw new Error(`Expected Cache.patch op.record to be a record or document identifier`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive-mirror/json-api",
|
|
3
|
-
"version": "5.7.0-alpha.
|
|
3
|
+
"version": "5.7.0-alpha.15",
|
|
4
4
|
"description": "A {JSON:API} Cache Implementation for WarpDrive",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@warp-drive-mirror/core": "5.7.0-alpha.
|
|
35
|
+
"@warp-drive-mirror/core": "5.7.0-alpha.15"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@embroider/macros": "^1.16.12",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
45
45
|
"@babel/preset-typescript": "^7.27.0",
|
|
46
46
|
"@types/json-to-ast": "^2.1.4",
|
|
47
|
-
"@warp-drive/internal-config": "5.7.0-alpha.
|
|
48
|
-
"@warp-drive-mirror/core": "5.7.0-alpha.
|
|
47
|
+
"@warp-drive/internal-config": "5.7.0-alpha.15",
|
|
48
|
+
"@warp-drive-mirror/core": "5.7.0-alpha.15",
|
|
49
49
|
"decorator-transforms": "^2.3.0",
|
|
50
50
|
"expect-type": "^1.2.1",
|
|
51
51
|
"typescript": "^5.8.3",
|