@warp-drive-mirror/json-api 5.7.0-alpha.2 → 5.7.0-alpha.21
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 +42 -43
- 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;
|
|
@@ -1374,11 +1374,8 @@ class JSONAPICache {
|
|
|
1374
1374
|
}
|
|
1375
1375
|
upgradeCapabilities(this._capabilities);
|
|
1376
1376
|
const store = this._capabilities._store;
|
|
1377
|
-
const attrs = this
|
|
1377
|
+
const attrs = getCacheFields(this, identifier);
|
|
1378
1378
|
attrs.forEach((attr, key) => {
|
|
1379
|
-
if (attr.kind === 'alias') {
|
|
1380
|
-
return;
|
|
1381
|
-
}
|
|
1382
1379
|
if (key in attributes && attributes[key] !== undefined) {
|
|
1383
1380
|
return;
|
|
1384
1381
|
}
|
|
@@ -1410,7 +1407,7 @@ class JSONAPICache {
|
|
|
1410
1407
|
*/
|
|
1411
1408
|
|
|
1412
1409
|
peekRemoteState(identifier) {
|
|
1413
|
-
if (
|
|
1410
|
+
if (isResourceKey(identifier)) {
|
|
1414
1411
|
const peeked = this.__safePeek(identifier, false);
|
|
1415
1412
|
if (!peeked) {
|
|
1416
1413
|
return null;
|
|
@@ -1435,7 +1432,7 @@ class JSONAPICache {
|
|
|
1435
1432
|
}
|
|
1436
1433
|
upgradeCapabilities(this._capabilities);
|
|
1437
1434
|
const store = this._capabilities._store;
|
|
1438
|
-
const attrs = this
|
|
1435
|
+
const attrs = getCacheFields(this, identifier);
|
|
1439
1436
|
attrs.forEach((attr, key) => {
|
|
1440
1437
|
if (key in attributes && attributes[key] !== undefined) {
|
|
1441
1438
|
return;
|
|
@@ -1551,7 +1548,7 @@ class JSONAPICache {
|
|
|
1551
1548
|
*
|
|
1552
1549
|
* ```ts
|
|
1553
1550
|
* interface Change {
|
|
1554
|
-
* identifier:
|
|
1551
|
+
* identifier: ResourceKey | RequestKey;
|
|
1555
1552
|
* op: 'upsert' | 'remove';
|
|
1556
1553
|
* patch?: unknown;
|
|
1557
1554
|
* }
|
|
@@ -1629,8 +1626,7 @@ class JSONAPICache {
|
|
|
1629
1626
|
cached.isNew = true;
|
|
1630
1627
|
const createOptions = {};
|
|
1631
1628
|
if (options !== undefined) {
|
|
1632
|
-
const
|
|
1633
|
-
const fields = storeWrapper.schema.fields(identifier);
|
|
1629
|
+
const fields = getCacheFields(this, identifier);
|
|
1634
1630
|
const graph = this.__graph;
|
|
1635
1631
|
const propertyNames = Object.keys(options);
|
|
1636
1632
|
for (let i = 0; i < propertyNames.length; i++) {
|
|
@@ -1686,7 +1682,7 @@ class JSONAPICache {
|
|
|
1686
1682
|
* @category Resource Lifecycle
|
|
1687
1683
|
* @public
|
|
1688
1684
|
*/
|
|
1689
|
-
willCommit(identifier) {
|
|
1685
|
+
willCommit(identifier, _context) {
|
|
1690
1686
|
const cached = this.__peek(identifier, false);
|
|
1691
1687
|
|
|
1692
1688
|
/*
|
|
@@ -1720,7 +1716,7 @@ class JSONAPICache {
|
|
|
1720
1716
|
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
1721
1717
|
if (macroCondition(!getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE)) {
|
|
1722
1718
|
// save off info about saved relationships
|
|
1723
|
-
const fields = this
|
|
1719
|
+
const fields = getCacheFields(this, identifier);
|
|
1724
1720
|
fields.forEach((schema, name) => {
|
|
1725
1721
|
if (schema.kind === 'belongsTo') {
|
|
1726
1722
|
if (this.__graph._isDirty(identifier, name)) {
|
|
@@ -1742,8 +1738,8 @@ class JSONAPICache {
|
|
|
1742
1738
|
* @public
|
|
1743
1739
|
*/
|
|
1744
1740
|
didCommit(committedIdentifier, result) {
|
|
1745
|
-
const payload = result.content;
|
|
1746
|
-
const operation = result.request.op;
|
|
1741
|
+
const payload = result ? result.content : null;
|
|
1742
|
+
const operation = result ? result.request.op : null;
|
|
1747
1743
|
const data = payload && payload.data;
|
|
1748
1744
|
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_CACHE)) {
|
|
1749
1745
|
if (getGlobalConfig().WarpDriveMirror.debug.LOG_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE) {
|
|
@@ -1765,10 +1761,10 @@ class JSONAPICache {
|
|
|
1765
1761
|
})(committedIdentifier.id) : {};
|
|
1766
1762
|
}
|
|
1767
1763
|
const {
|
|
1768
|
-
|
|
1764
|
+
cacheKeyManager
|
|
1769
1765
|
} = this._capabilities;
|
|
1770
1766
|
const existingId = committedIdentifier.id;
|
|
1771
|
-
const identifier = operation !== 'deleteRecord' && data ?
|
|
1767
|
+
const identifier = operation !== 'deleteRecord' && data ? cacheKeyManager.updateRecordIdentifier(committedIdentifier, data) : committedIdentifier;
|
|
1772
1768
|
const cached = this.__peek(identifier, false);
|
|
1773
1769
|
if (cached.isDeleted) {
|
|
1774
1770
|
this.__graph.push({
|
|
@@ -1790,7 +1786,7 @@ class JSONAPICache {
|
|
|
1790
1786
|
throw error;
|
|
1791
1787
|
}
|
|
1792
1788
|
}
|
|
1793
|
-
const fields = this
|
|
1789
|
+
const fields = getCacheFields(this, identifier);
|
|
1794
1790
|
cached.isNew = false;
|
|
1795
1791
|
let newCanonicalAttributes;
|
|
1796
1792
|
if (data) {
|
|
@@ -1818,7 +1814,7 @@ class JSONAPICache {
|
|
|
1818
1814
|
if (!inFlightData || !('data' in inFlightData)) {
|
|
1819
1815
|
return;
|
|
1820
1816
|
}
|
|
1821
|
-
const actualData = relationshipData ? this._capabilities.
|
|
1817
|
+
const actualData = relationshipData ? this._capabilities.cacheKeyManager.getOrCreateRecordIdentifier(relationshipData) : null;
|
|
1822
1818
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1823
1819
|
if (!test) {
|
|
1824
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>'}`);
|
|
@@ -1847,7 +1843,7 @@ class JSONAPICache {
|
|
|
1847
1843
|
const included = payload && payload.included;
|
|
1848
1844
|
if (included) {
|
|
1849
1845
|
for (let i = 0, length = included.length; i < length; i++) {
|
|
1850
|
-
putOne(this,
|
|
1846
|
+
putOne(this, cacheKeyManager, included[i]);
|
|
1851
1847
|
}
|
|
1852
1848
|
}
|
|
1853
1849
|
return {
|
|
@@ -1997,7 +1993,7 @@ class JSONAPICache {
|
|
|
1997
1993
|
} else if (cached.defaultAttrs && attribute in cached.defaultAttrs) {
|
|
1998
1994
|
return cached.defaultAttrs[attribute];
|
|
1999
1995
|
} else {
|
|
2000
|
-
const attrSchema = this
|
|
1996
|
+
const attrSchema = getCacheFields(this, identifier).get(attribute);
|
|
2001
1997
|
upgradeCapabilities(this._capabilities);
|
|
2002
1998
|
const defaultValue = getDefaultValue(attrSchema, identifier, this._capabilities._store);
|
|
2003
1999
|
if (schemaHasLegacyDefaultValueFn(attrSchema)) {
|
|
@@ -2064,7 +2060,7 @@ class JSONAPICache {
|
|
|
2064
2060
|
} else if (cached.defaultAttrs && attribute in cached.defaultAttrs) {
|
|
2065
2061
|
return cached.defaultAttrs[attribute];
|
|
2066
2062
|
} else {
|
|
2067
|
-
const attrSchema = this
|
|
2063
|
+
const attrSchema = getCacheFields(this, identifier).get(attribute);
|
|
2068
2064
|
upgradeCapabilities(this._capabilities);
|
|
2069
2065
|
const defaultValue = getDefaultValue(attrSchema, identifier, this._capabilities._store);
|
|
2070
2066
|
if (schemaHasLegacyDefaultValueFn(attrSchema)) {
|
|
@@ -2285,16 +2281,16 @@ class JSONAPICache {
|
|
|
2285
2281
|
* type RelationshipDiff =
|
|
2286
2282
|
| {
|
|
2287
2283
|
kind: 'collection';
|
|
2288
|
-
remoteState:
|
|
2289
|
-
additions: Set<
|
|
2290
|
-
removals: Set<
|
|
2291
|
-
localState:
|
|
2284
|
+
remoteState: ResourceKey[];
|
|
2285
|
+
additions: Set<ResourceKey>;
|
|
2286
|
+
removals: Set<ResourceKey>;
|
|
2287
|
+
localState: ResourceKey[];
|
|
2292
2288
|
reordered: boolean;
|
|
2293
2289
|
}
|
|
2294
2290
|
| {
|
|
2295
2291
|
kind: 'resource';
|
|
2296
|
-
remoteState:
|
|
2297
|
-
localState:
|
|
2292
|
+
remoteState: ResourceKey | null;
|
|
2293
|
+
localState: ResourceKey | null;
|
|
2298
2294
|
};
|
|
2299
2295
|
```
|
|
2300
2296
|
*
|
|
@@ -2719,11 +2715,6 @@ function hasLegacyDefaultValueFn(options) {
|
|
|
2719
2715
|
return !!options && typeof options.defaultValue === 'function';
|
|
2720
2716
|
}
|
|
2721
2717
|
function getDefaultValue(schema, identifier, store) {
|
|
2722
|
-
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2723
|
-
if (!test) {
|
|
2724
|
-
throw new Error(`AliasFields should not be directly accessed from the cache`);
|
|
2725
|
-
}
|
|
2726
|
-
})(schema?.kind !== 'alias') : {};
|
|
2727
2718
|
const options = schema?.options;
|
|
2728
2719
|
if (!schema || !options && !schema.type) {
|
|
2729
2720
|
return;
|
|
@@ -3055,7 +3046,7 @@ function cacheUpsert(cache, identifier, data, calculateChanges) {
|
|
|
3055
3046
|
cache._capabilities.notifyChange(identifier, 'identity', null);
|
|
3056
3047
|
cache._capabilities.notifyChange(identifier, 'state', null);
|
|
3057
3048
|
}
|
|
3058
|
-
const fields = cache
|
|
3049
|
+
const fields = getCacheFields(cache, identifier);
|
|
3059
3050
|
|
|
3060
3051
|
// if no cache entry existed, no record exists / property has been accessed
|
|
3061
3052
|
// and thus we do not need to notify changes to any properties.
|
|
@@ -3089,8 +3080,8 @@ function cacheUpsert(cache, identifier, data, calculateChanges) {
|
|
|
3089
3080
|
return changedKeys?.size ? Array.from(changedKeys) : undefined;
|
|
3090
3081
|
}
|
|
3091
3082
|
function patchCache(Cache, op) {
|
|
3092
|
-
const isRecord =
|
|
3093
|
-
const isDocument = !isRecord &&
|
|
3083
|
+
const isRecord = isResourceKey(op.record);
|
|
3084
|
+
const isDocument = !isRecord && isRequestKey(op.record);
|
|
3094
3085
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3095
3086
|
if (!test) {
|
|
3096
3087
|
throw new Error(`Expected Cache.patch op.record to be a record or document identifier`);
|
|
@@ -3124,7 +3115,7 @@ function patchCache(Cache, op) {
|
|
|
3124
3115
|
{
|
|
3125
3116
|
if (isRecord) {
|
|
3126
3117
|
if ('field' in op) {
|
|
3127
|
-
const field = Cache
|
|
3118
|
+
const field = getCacheFields(Cache, op.record).get(op.field);
|
|
3128
3119
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3129
3120
|
if (!test) {
|
|
3130
3121
|
throw new Error(`Expected ${op.field} to be a field on ${op.record.type}`);
|
|
@@ -3227,5 +3218,13 @@ function patchCache(Cache, op) {
|
|
|
3227
3218
|
}
|
|
3228
3219
|
}
|
|
3229
3220
|
}
|
|
3221
|
+
function getCacheFields(cache, identifier) {
|
|
3222
|
+
if (cache._capabilities.schema.cacheFields) {
|
|
3223
|
+
return cache._capabilities.schema.cacheFields(identifier);
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
// the model schema service cannot process fields that are not cache fields
|
|
3227
|
+
return cache._capabilities.schema.fields(identifier);
|
|
3228
|
+
}
|
|
3230
3229
|
|
|
3231
3230
|
export { JSONAPICache };
|
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.21",
|
|
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.21"
|
|
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.21",
|
|
48
|
+
"@warp-drive-mirror/core": "5.7.0-alpha.21",
|
|
49
49
|
"decorator-transforms": "^2.3.0",
|
|
50
50
|
"expect-type": "^1.2.1",
|
|
51
51
|
"typescript": "^5.8.3",
|