@graphql-box/cache-manager 2.3.0 → 2.3.1
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/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/production.analysis.txt +17 -17
- package/lib/main/helpers/normalizeResponseData.js +2 -1
- package/lib/main/helpers/normalizeResponseData.js.map +1 -1
- package/lib/main/main/index.js +42 -31
- package/lib/main/main/index.js.map +1 -1
- package/lib/module/helpers/normalizeResponseData.js +2 -1
- package/lib/module/helpers/normalizeResponseData.js.map +1 -1
- package/lib/module/main/index.js +42 -31
- package/lib/module/main/index.js.map +1 -1
- package/lib/types/helpers/normalizeResponseData.d.ts +1 -0
- package/lib/types/helpers/normalizeResponseData.d.ts.map +1 -1
- package/lib/types/main/index.d.ts +2 -2
- package/lib/types/main/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__snapshots__/index.test.ts.snap +17 -0
- package/src/helpers/normalizeResponseData.ts +1 -0
- package/src/main/index.ts +48 -39
|
@@ -14590,6 +14590,7 @@ Object {
|
|
|
14590
14590
|
},
|
|
14591
14591
|
},
|
|
14592
14592
|
"hasNext": undefined,
|
|
14593
|
+
"path": undefined,
|
|
14593
14594
|
}
|
|
14594
14595
|
`;
|
|
14595
14596
|
|
|
@@ -15918,6 +15919,7 @@ Object {
|
|
|
15918
15919
|
},
|
|
15919
15920
|
},
|
|
15920
15921
|
"hasNext": undefined,
|
|
15922
|
+
"path": undefined,
|
|
15921
15923
|
}
|
|
15922
15924
|
`;
|
|
15923
15925
|
|
|
@@ -17215,6 +17217,7 @@ Object {
|
|
|
17215
17217
|
},
|
|
17216
17218
|
},
|
|
17217
17219
|
"hasNext": undefined,
|
|
17220
|
+
"path": undefined,
|
|
17218
17221
|
}
|
|
17219
17222
|
`;
|
|
17220
17223
|
|
|
@@ -18468,6 +18471,7 @@ Object {
|
|
|
18468
18471
|
},
|
|
18469
18472
|
},
|
|
18470
18473
|
"hasNext": undefined,
|
|
18474
|
+
"path": undefined,
|
|
18471
18475
|
}
|
|
18472
18476
|
`;
|
|
18473
18477
|
|
|
@@ -19690,6 +19694,7 @@ Object {
|
|
|
19690
19694
|
},
|
|
19691
19695
|
},
|
|
19692
19696
|
"hasNext": undefined,
|
|
19697
|
+
"path": undefined,
|
|
19693
19698
|
}
|
|
19694
19699
|
`;
|
|
19695
19700
|
|
|
@@ -19947,6 +19952,7 @@ Object {
|
|
|
19947
19952
|
},
|
|
19948
19953
|
},
|
|
19949
19954
|
"hasNext": undefined,
|
|
19955
|
+
"path": undefined,
|
|
19950
19956
|
}
|
|
19951
19957
|
`;
|
|
19952
19958
|
|
|
@@ -20204,6 +20210,7 @@ Object {
|
|
|
20204
20210
|
},
|
|
20205
20211
|
},
|
|
20206
20212
|
"hasNext": undefined,
|
|
20213
|
+
"path": undefined,
|
|
20207
20214
|
}
|
|
20208
20215
|
`;
|
|
20209
20216
|
|
|
@@ -21271,6 +21278,7 @@ Object {
|
|
|
21271
21278
|
},
|
|
21272
21279
|
},
|
|
21273
21280
|
"hasNext": undefined,
|
|
21281
|
+
"path": undefined,
|
|
21274
21282
|
}
|
|
21275
21283
|
`;
|
|
21276
21284
|
|
|
@@ -22321,6 +22329,7 @@ Object {
|
|
|
22321
22329
|
},
|
|
22322
22330
|
},
|
|
22323
22331
|
"hasNext": undefined,
|
|
22332
|
+
"path": undefined,
|
|
22324
22333
|
}
|
|
22325
22334
|
`;
|
|
22326
22335
|
|
|
@@ -23302,6 +23311,7 @@ Object {
|
|
|
23302
23311
|
},
|
|
23303
23312
|
},
|
|
23304
23313
|
"hasNext": undefined,
|
|
23314
|
+
"path": undefined,
|
|
23305
23315
|
}
|
|
23306
23316
|
`;
|
|
23307
23317
|
|
|
@@ -24266,6 +24276,7 @@ Object {
|
|
|
24266
24276
|
},
|
|
24267
24277
|
},
|
|
24268
24278
|
"hasNext": undefined,
|
|
24279
|
+
"path": undefined,
|
|
24269
24280
|
}
|
|
24270
24281
|
`;
|
|
24271
24282
|
|
|
@@ -24426,6 +24437,7 @@ Object {
|
|
|
24426
24437
|
},
|
|
24427
24438
|
},
|
|
24428
24439
|
"hasNext": undefined,
|
|
24440
|
+
"path": undefined,
|
|
24429
24441
|
}
|
|
24430
24442
|
`;
|
|
24431
24443
|
|
|
@@ -24586,6 +24598,7 @@ Object {
|
|
|
24586
24598
|
},
|
|
24587
24599
|
},
|
|
24588
24600
|
"hasNext": undefined,
|
|
24601
|
+
"path": undefined,
|
|
24589
24602
|
}
|
|
24590
24603
|
`;
|
|
24591
24604
|
|
|
@@ -24915,6 +24928,7 @@ Object {
|
|
|
24915
24928
|
},
|
|
24916
24929
|
},
|
|
24917
24930
|
"hasNext": undefined,
|
|
24931
|
+
"path": undefined,
|
|
24918
24932
|
}
|
|
24919
24933
|
`;
|
|
24920
24934
|
|
|
@@ -25244,6 +25258,7 @@ Object {
|
|
|
25244
25258
|
},
|
|
25245
25259
|
},
|
|
25246
25260
|
"hasNext": undefined,
|
|
25261
|
+
"path": undefined,
|
|
25247
25262
|
}
|
|
25248
25263
|
`;
|
|
25249
25264
|
|
|
@@ -25490,6 +25505,7 @@ Object {
|
|
|
25490
25505
|
},
|
|
25491
25506
|
},
|
|
25492
25507
|
"hasNext": undefined,
|
|
25508
|
+
"path": undefined,
|
|
25493
25509
|
}
|
|
25494
25510
|
`;
|
|
25495
25511
|
|
|
@@ -25736,5 +25752,6 @@ Object {
|
|
|
25736
25752
|
},
|
|
25737
25753
|
},
|
|
25738
25754
|
"hasNext": undefined,
|
|
25755
|
+
"path": undefined,
|
|
25739
25756
|
}
|
|
25740
25757
|
`;
|
package/src/main/index.ts
CHANGED
|
@@ -113,17 +113,6 @@ export class CacheManager implements CacheManagerDef {
|
|
|
113
113
|
return cacheability ? cacheability.printCacheControl() : defaultCacheControl;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
private static _getResponseCacheMetadata(
|
|
117
|
-
cacheMetadata: CacheMetadata,
|
|
118
|
-
partialQueryResponse?: PartialQueryResponse,
|
|
119
|
-
): CacheMetadata {
|
|
120
|
-
if (!partialQueryResponse) {
|
|
121
|
-
return cacheMetadata;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return new Map([...partialQueryResponse.cacheMetadata, ...cacheMetadata]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
116
|
private static _isNodeEntity(fieldTypeInfo?: FieldTypeInfo): boolean {
|
|
128
117
|
if (!fieldTypeInfo) {
|
|
129
118
|
return false;
|
|
@@ -145,6 +134,17 @@ export class CacheManager implements CacheManagerDef {
|
|
|
145
134
|
return !noCache && cacheability.checkTTL();
|
|
146
135
|
}
|
|
147
136
|
|
|
137
|
+
private static _mergeResponseCacheMetadata(
|
|
138
|
+
cacheMetadata: CacheMetadata,
|
|
139
|
+
partialQueryResponse?: PartialQueryResponse,
|
|
140
|
+
): CacheMetadata {
|
|
141
|
+
if (!partialQueryResponse) {
|
|
142
|
+
return cacheMetadata;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return new Map([...partialQueryResponse.cacheMetadata, ...cacheMetadata]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
148
|
private static _setCachedData(
|
|
149
149
|
requestData: PlainObjectMap,
|
|
150
150
|
{ data }: MergedCachedFieldData,
|
|
@@ -330,7 +330,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
330
330
|
|
|
331
331
|
const dataCaching: Promise<void>[] = [];
|
|
332
332
|
|
|
333
|
-
const { cacheMetadata, data, hasNext } = await this._resolveRequest(
|
|
333
|
+
const { cacheMetadata, data, hasNext, path } = await this._resolveRequest(
|
|
334
334
|
updatedRequestData,
|
|
335
335
|
rawResponseData,
|
|
336
336
|
options,
|
|
@@ -340,35 +340,41 @@ export class CacheManager implements CacheManagerDef {
|
|
|
340
340
|
let partialQueryResponse: PartialQueryResponse | undefined;
|
|
341
341
|
|
|
342
342
|
if (cacheManagerContext.queryFiltered) {
|
|
343
|
+
if (!(rawResponseData.hasNext || rawResponseData.path)) {
|
|
344
|
+
dataCaching.push(
|
|
345
|
+
this._setQueryResponseCacheEntry(
|
|
346
|
+
updatedRequestData.hash,
|
|
347
|
+
{ cacheMetadata, data },
|
|
348
|
+
options,
|
|
349
|
+
cacheManagerContext,
|
|
350
|
+
),
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!rawResponseData.path) {
|
|
355
|
+
partialQueryResponse = this._getPartialQueryResponse(requestData.hash);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const responseCacheMetadata = CacheManager._mergeResponseCacheMetadata(cacheMetadata, partialQueryResponse);
|
|
360
|
+
const responseData = this._mergeResponseData(data, partialQueryResponse);
|
|
361
|
+
|
|
362
|
+
if (!(rawResponseData.hasNext || rawResponseData.path)) {
|
|
343
363
|
dataCaching.push(
|
|
344
364
|
this._setQueryResponseCacheEntry(
|
|
345
|
-
|
|
346
|
-
{ cacheMetadata, data },
|
|
365
|
+
requestData.hash,
|
|
366
|
+
{ cacheMetadata: responseCacheMetadata, data: responseData },
|
|
347
367
|
options,
|
|
348
368
|
cacheManagerContext,
|
|
349
369
|
),
|
|
350
370
|
);
|
|
351
|
-
|
|
352
|
-
partialQueryResponse = this._getPartialQueryResponse(requestData.hash);
|
|
353
371
|
}
|
|
354
372
|
|
|
355
|
-
const responseCacheMetadata = CacheManager._getResponseCacheMetadata(cacheMetadata, partialQueryResponse);
|
|
356
|
-
const responseData = this._getResponseData(data, partialQueryResponse);
|
|
357
|
-
|
|
358
|
-
dataCaching.push(
|
|
359
|
-
this._setQueryResponseCacheEntry(
|
|
360
|
-
requestData.hash,
|
|
361
|
-
{ cacheMetadata: responseCacheMetadata, data: responseData },
|
|
362
|
-
options,
|
|
363
|
-
cacheManagerContext,
|
|
364
|
-
),
|
|
365
|
-
);
|
|
366
|
-
|
|
367
373
|
if (options.awaitDataCaching) {
|
|
368
374
|
await Promise.all(dataCaching);
|
|
369
375
|
}
|
|
370
376
|
|
|
371
|
-
return { cacheMetadata: responseCacheMetadata, data: responseData, hasNext };
|
|
377
|
+
return { cacheMetadata: responseCacheMetadata, data: responseData, hasNext, path };
|
|
372
378
|
}
|
|
373
379
|
|
|
374
380
|
public async resolveRequest(
|
|
@@ -616,14 +622,6 @@ export class CacheManager implements CacheManagerDef {
|
|
|
616
622
|
return partialQueryResponse;
|
|
617
623
|
}
|
|
618
624
|
|
|
619
|
-
private _getResponseData(responseData: PlainObjectMap, partialQueryResponse?: PartialQueryResponse): PlainObjectMap {
|
|
620
|
-
if (!partialQueryResponse) {
|
|
621
|
-
return responseData;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return this._mergeObjects(partialQueryResponse.data, responseData);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
625
|
private async _hasCacheEntry(cacheType: CacheTypes, hash: string): Promise<Cacheability | false> {
|
|
628
626
|
try {
|
|
629
627
|
return await this._cache.has(`${cacheType}::${hash}`);
|
|
@@ -654,6 +652,17 @@ export class CacheManager implements CacheManagerDef {
|
|
|
654
652
|
});
|
|
655
653
|
}
|
|
656
654
|
|
|
655
|
+
private _mergeResponseData(
|
|
656
|
+
responseData: PlainObjectMap,
|
|
657
|
+
partialQueryResponse?: PartialQueryResponse,
|
|
658
|
+
): PlainObjectMap {
|
|
659
|
+
if (!partialQueryResponse) {
|
|
660
|
+
return responseData;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
return this._mergeObjects(partialQueryResponse.data, responseData);
|
|
664
|
+
}
|
|
665
|
+
|
|
657
666
|
private async _parseEntityAndRequestFieldPathCacheEntryData(
|
|
658
667
|
field: FieldNode,
|
|
659
668
|
ancestorKeysAndPaths: AncestorKeysAndPaths,
|
|
@@ -717,7 +726,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
717
726
|
const normalizedResponseData = rawResponseData.path ? normalizeResponseData(rawResponseData) : rawResponseData;
|
|
718
727
|
const dataCaching: Promise<void>[] = [];
|
|
719
728
|
const cacheMetadata = this._buildCacheMetadata(requestData, normalizedResponseData, options, context);
|
|
720
|
-
const { data, hasNext } = normalizedResponseData;
|
|
729
|
+
const { data, hasNext, path } = normalizedResponseData;
|
|
721
730
|
|
|
722
731
|
dataCaching.push(
|
|
723
732
|
this._setEntityAndRequestFieldPathCacheEntries(
|
|
@@ -732,7 +741,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
732
741
|
await Promise.all(dataCaching);
|
|
733
742
|
}
|
|
734
743
|
|
|
735
|
-
return { cacheMetadata, data, hasNext };
|
|
744
|
+
return { cacheMetadata, data, hasNext, path };
|
|
736
745
|
}
|
|
737
746
|
|
|
738
747
|
private async _retrieveCachedEntityData(
|