@graphql-box/cache-manager 3.2.0 → 3.3.0
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 +42 -46
- package/lib/main/consts/index.js +1 -7
- package/lib/main/consts/index.js.map +1 -1
- package/lib/main/debug/log-cache-entry/index.js +11 -4
- package/lib/main/debug/log-cache-entry/index.js.map +1 -1
- package/lib/main/debug/log-cache-query/index.js +11 -4
- package/lib/main/debug/log-cache-query/index.js.map +1 -1
- package/lib/main/debug/log-partial-compiled/index.js +4 -2
- package/lib/main/debug/log-partial-compiled/index.js.map +1 -1
- package/lib/main/index.js +0 -23
- package/lib/main/index.js.map +1 -1
- package/lib/main/main/index.js +21 -12
- package/lib/main/main/index.js.map +1 -1
- package/lib/module/consts/index.js +0 -3
- package/lib/module/consts/index.js.map +1 -1
- package/lib/module/debug/log-cache-entry/index.js +11 -4
- package/lib/module/debug/log-cache-entry/index.js.map +1 -1
- package/lib/module/debug/log-cache-query/index.js +11 -4
- package/lib/module/debug/log-cache-query/index.js.map +1 -1
- package/lib/module/debug/log-partial-compiled/index.js +3 -1
- package/lib/module/debug/log-partial-compiled/index.js.map +1 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.js +21 -12
- package/lib/module/main/index.js.map +1 -1
- package/lib/types/consts/index.d.ts +0 -3
- package/lib/types/consts/index.d.ts.map +1 -1
- package/lib/types/debug/log-cache-entry/index.d.ts.map +1 -1
- package/lib/types/debug/log-cache-query/index.d.ts.map +1 -1
- package/lib/types/debug/log-partial-compiled/index.d.ts.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/main/index.d.ts +3 -1
- package/lib/types/main/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__snapshots__/index.test.ts.snap +1082 -1082
- package/src/consts/index.ts +0 -4
- package/src/debug/log-cache-entry/index.ts +10 -5
- package/src/debug/log-cache-query/index.ts +10 -5
- package/src/debug/log-partial-compiled/index.ts +3 -3
- package/src/index.ts +0 -1
- package/src/main/index.ts +22 -15
package/src/consts/index.ts
CHANGED
|
@@ -4,7 +4,3 @@ export const NO_CACHE = "noCache";
|
|
|
4
4
|
|
|
5
5
|
export const HEADER_CACHE_CONTROL = "cache-control";
|
|
6
6
|
export const HEADER_NO_CACHE = "no-cache";
|
|
7
|
-
|
|
8
|
-
export const CACHE_ENTRY_ADDED = "cache_entry_added";
|
|
9
|
-
export const CACHE_ENTRY_QUERIED = "cache_entry_queried";
|
|
10
|
-
export const PARTIAL_QUERY_COMPILED = "partial_query_compiled";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { RequestContext } from "@graphql-box/core";
|
|
2
|
-
import { CACHE_ENTRY_ADDED } from "../../consts";
|
|
1
|
+
import { CACHE_ENTRY_ADDED, RequestContext } from "@graphql-box/core";
|
|
3
2
|
|
|
4
3
|
export default function logCacheEntry() {
|
|
5
4
|
return (
|
|
@@ -12,7 +11,9 @@ export default function logCacheEntry() {
|
|
|
12
11
|
|
|
13
12
|
descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {
|
|
14
13
|
return new Promise<void>(async resolve => {
|
|
15
|
-
const { debugManager, ...otherContext } = args[5] as RequestContext
|
|
14
|
+
const { debugManager, requestFieldCacheKey, requestID, ...otherContext } = args[5] as RequestContext & {
|
|
15
|
+
requestFieldCacheKey?: string;
|
|
16
|
+
};
|
|
16
17
|
|
|
17
18
|
if (!debugManager) {
|
|
18
19
|
await method.apply(this, args);
|
|
@@ -26,15 +27,19 @@ export default function logCacheEntry() {
|
|
|
26
27
|
const duration = endTime - startTime;
|
|
27
28
|
resolve();
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
const payload = {
|
|
30
31
|
cachemapOptions: args[3],
|
|
31
32
|
cacheType: args[0],
|
|
32
33
|
context: otherContext,
|
|
33
34
|
hash: args[1],
|
|
34
35
|
options: args[4],
|
|
36
|
+
requestID,
|
|
35
37
|
stats: { duration, endTime, startTime },
|
|
36
38
|
value: args[2],
|
|
37
|
-
|
|
39
|
+
...(requestFieldCacheKey ? { decryptedCacheKey: requestFieldCacheKey } : {}),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
debugManager.emit(CACHE_ENTRY_ADDED, payload);
|
|
38
43
|
});
|
|
39
44
|
};
|
|
40
45
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { RequestContext } from "@graphql-box/core";
|
|
2
|
-
import { CACHE_ENTRY_QUERIED } from "../../consts";
|
|
1
|
+
import { CACHE_ENTRY_QUERIED, RequestContext } from "@graphql-box/core";
|
|
3
2
|
|
|
4
3
|
export default function logCacheQuery() {
|
|
5
4
|
return (
|
|
@@ -13,7 +12,9 @@ export default function logCacheQuery() {
|
|
|
13
12
|
descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {
|
|
14
13
|
try {
|
|
15
14
|
return new Promise(async resolve => {
|
|
16
|
-
const { debugManager, ...otherContext } = args[3] as RequestContext
|
|
15
|
+
const { debugManager, requestFieldCacheKey, requestID, ...otherContext } = args[3] as RequestContext & {
|
|
16
|
+
requestFieldCacheKey?: string;
|
|
17
|
+
};
|
|
17
18
|
|
|
18
19
|
if (!debugManager) {
|
|
19
20
|
resolve(await method.apply(this, args));
|
|
@@ -26,14 +27,18 @@ export default function logCacheQuery() {
|
|
|
26
27
|
const duration = endTime - startTime;
|
|
27
28
|
resolve(result);
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
const payload = {
|
|
30
31
|
cacheType: args[0],
|
|
31
32
|
context: otherContext,
|
|
32
33
|
hash: args[1],
|
|
33
34
|
options: args[2],
|
|
35
|
+
requestID,
|
|
34
36
|
result,
|
|
35
37
|
stats: { duration, endTime, startTime },
|
|
36
|
-
|
|
38
|
+
...(requestFieldCacheKey ? { decryptedCacheKey: requestFieldCacheKey } : {}),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
debugManager.emit(CACHE_ENTRY_QUERIED, payload);
|
|
37
42
|
});
|
|
38
43
|
} catch (error) {
|
|
39
44
|
return Promise.reject(error);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { RequestContext } from "@graphql-box/core";
|
|
2
|
-
import { PARTIAL_QUERY_COMPILED } from "../../consts";
|
|
1
|
+
import { PARTIAL_QUERY_COMPILED, RequestContext } from "@graphql-box/core";
|
|
3
2
|
|
|
4
3
|
export default function logPartialCompiled() {
|
|
5
4
|
return (
|
|
@@ -12,7 +11,7 @@ export default function logPartialCompiled() {
|
|
|
12
11
|
|
|
13
12
|
descriptor.value = async function descriptorValue(...args: any[]): Promise<any> {
|
|
14
13
|
return new Promise<void>(async resolve => {
|
|
15
|
-
const { debugManager, ...otherContext } = args[3] as RequestContext;
|
|
14
|
+
const { debugManager, requestID, ...otherContext } = args[3] as RequestContext;
|
|
16
15
|
|
|
17
16
|
if (!debugManager) {
|
|
18
17
|
await method.apply(this, args);
|
|
@@ -31,6 +30,7 @@ export default function logPartialCompiled() {
|
|
|
31
30
|
hash: args[0],
|
|
32
31
|
options: args[2],
|
|
33
32
|
partialQueryResponse: args[1],
|
|
33
|
+
requestID,
|
|
34
34
|
stats: { duration, endTime, startTime },
|
|
35
35
|
});
|
|
36
36
|
});
|
package/src/index.ts
CHANGED
package/src/main/index.ts
CHANGED
|
@@ -317,7 +317,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
317
317
|
cacheType: CacheTypes,
|
|
318
318
|
hash: string,
|
|
319
319
|
options: RequestOptions,
|
|
320
|
-
context: RequestContext,
|
|
320
|
+
context: RequestContext & { requestFieldCacheKey?: string },
|
|
321
321
|
): Promise<CheckCacheEntryResult | false> {
|
|
322
322
|
return this._checkCacheEntry(cacheType, hash, options, context);
|
|
323
323
|
}
|
|
@@ -376,7 +376,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
376
376
|
context: CacheManagerContext,
|
|
377
377
|
): Promise<void> {
|
|
378
378
|
const keysAndPaths = buildFieldKeysAndPaths(fieldNode, cachedAncestorFieldData, context);
|
|
379
|
-
const { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldPath } = keysAndPaths;
|
|
379
|
+
const { hashedRequestFieldCacheKey, propNameOrIndex, requestFieldCacheKey, requestFieldPath } = keysAndPaths;
|
|
380
380
|
const fieldTypeInfo = context.fieldTypeMap.get(requestFieldPath);
|
|
381
381
|
const { entityData, fragmentKind, fragmentName, requestFieldPathData, typeName } = cachedAncestorFieldData;
|
|
382
382
|
|
|
@@ -390,6 +390,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
390
390
|
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
391
391
|
const { cacheability, entry } = await this._retrieveCachedRequestFieldPathData(
|
|
392
392
|
hashedRequestFieldCacheKey,
|
|
393
|
+
requestFieldCacheKey,
|
|
393
394
|
options,
|
|
394
395
|
context,
|
|
395
396
|
);
|
|
@@ -609,7 +610,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
609
610
|
cacheType: CacheTypes,
|
|
610
611
|
hash: string,
|
|
611
612
|
options: RequestOptions,
|
|
612
|
-
context: CacheManagerContext,
|
|
613
|
+
context: CacheManagerContext & { requestFieldCacheKey?: string },
|
|
613
614
|
): Promise<CheckCacheEntryResult | false> {
|
|
614
615
|
try {
|
|
615
616
|
const cacheability = await this._hasCacheEntry(cacheType, hash);
|
|
@@ -656,7 +657,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
656
657
|
cacheType: CacheTypes,
|
|
657
658
|
hash: string,
|
|
658
659
|
_options: RequestOptions,
|
|
659
|
-
_context: CacheManagerContext,
|
|
660
|
+
_context: CacheManagerContext & { requestFieldCacheKey?: string },
|
|
660
661
|
): Promise<any> {
|
|
661
662
|
try {
|
|
662
663
|
return await this._cache.get(`${cacheType}::${hash}`);
|
|
@@ -797,7 +798,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
797
798
|
|
|
798
799
|
private async _retrieveCachedParentNodeData(
|
|
799
800
|
{ entityData: ancestorEntityData, requestFieldPathData: ancestorRequestFieldPathData }: CachedAncestorFieldData,
|
|
800
|
-
{ hashedRequestFieldCacheKey, propNameOrIndex }: KeysAndPaths,
|
|
801
|
+
{ hashedRequestFieldCacheKey, propNameOrIndex, requestFieldCacheKey }: KeysAndPaths,
|
|
801
802
|
fieldTypeInfo: FieldTypeInfo,
|
|
802
803
|
options: RequestOptions,
|
|
803
804
|
context: CacheManagerContext,
|
|
@@ -809,6 +810,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
809
810
|
if (CacheManager._isNodeRequestFieldPath(fieldTypeInfo)) {
|
|
810
811
|
const { cacheability: entryCacheability, entry } = await this._retrieveCachedRequestFieldPathData(
|
|
811
812
|
hashedRequestFieldCacheKey,
|
|
813
|
+
requestFieldCacheKey,
|
|
812
814
|
options,
|
|
813
815
|
context,
|
|
814
816
|
);
|
|
@@ -856,10 +858,12 @@ export class CacheManager implements CacheManagerDef {
|
|
|
856
858
|
|
|
857
859
|
private async _retrieveCachedRequestFieldPathData(
|
|
858
860
|
hash: string,
|
|
861
|
+
requestFieldCacheKey: string,
|
|
859
862
|
options: RequestOptions,
|
|
860
863
|
context: CacheManagerContext,
|
|
861
864
|
) {
|
|
862
|
-
return (this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, context
|
|
865
|
+
return (this._checkCacheEntry(REQUEST_FIELD_PATHS, hash, options, { ...context, requestFieldCacheKey }) ||
|
|
866
|
+
{}) as Partial<CheckCacheEntryResult>;
|
|
863
867
|
}
|
|
864
868
|
|
|
865
869
|
private async _retrieveCachedResponseData(
|
|
@@ -902,10 +906,10 @@ export class CacheManager implements CacheManagerDef {
|
|
|
902
906
|
context: CacheManagerContext,
|
|
903
907
|
) {
|
|
904
908
|
const responseChunks = this._responseChunksAwaitingCaching.get(
|
|
905
|
-
context.
|
|
909
|
+
context.requestID,
|
|
906
910
|
) as RawResponseDataWithMaybeCacheMetadata[];
|
|
907
911
|
|
|
908
|
-
this._responseChunksAwaitingCaching.delete(context.
|
|
912
|
+
this._responseChunksAwaitingCaching.delete(context.requestID);
|
|
909
913
|
return mergeResponseDataSets([...responseChunks, normalizedResponseData]);
|
|
910
914
|
}
|
|
911
915
|
|
|
@@ -916,7 +920,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
916
920
|
value: any,
|
|
917
921
|
cachemapOptions: CachemapOptions,
|
|
918
922
|
_options: RequestOptions,
|
|
919
|
-
_context: CacheManagerContext,
|
|
923
|
+
_context: CacheManagerContext & { requestFieldCacheKey?: string },
|
|
920
924
|
): Promise<void> {
|
|
921
925
|
try {
|
|
922
926
|
await this._cache.set(`${cacheType}::${hash}`, cloneDeep(value), cachemapOptions);
|
|
@@ -1124,7 +1128,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
1124
1128
|
options: RequestOptions,
|
|
1125
1129
|
context: CacheManagerContext,
|
|
1126
1130
|
): Promise<void> {
|
|
1127
|
-
const { hashedRequestFieldCacheKey, responseDataPath } = keysAndPaths;
|
|
1131
|
+
const { hashedRequestFieldCacheKey, requestFieldCacheKey, responseDataPath } = keysAndPaths;
|
|
1128
1132
|
let fieldData = get(data, responseDataPath);
|
|
1129
1133
|
const isEntity = this._isFieldEntity(fieldData, fieldTypeInfo);
|
|
1130
1134
|
const hasArgsOrDirectives = fieldTypeInfo.hasArguments || fieldTypeInfo.hasDirectives;
|
|
@@ -1134,7 +1138,10 @@ export class CacheManager implements CacheManagerDef {
|
|
|
1134
1138
|
fieldData = filterOutPropsWithArgsOrDirectives(fieldData, field.selectionSet.selections, keysAndPaths, context);
|
|
1135
1139
|
}
|
|
1136
1140
|
|
|
1137
|
-
const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options,
|
|
1141
|
+
const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, {
|
|
1142
|
+
...context,
|
|
1143
|
+
requestFieldCacheKey,
|
|
1144
|
+
});
|
|
1138
1145
|
|
|
1139
1146
|
if (result && isObjectLike(fieldData)) {
|
|
1140
1147
|
fieldData = this._mergeObjects(result.entry, fieldData);
|
|
@@ -1146,7 +1153,7 @@ export class CacheManager implements CacheManagerDef {
|
|
|
1146
1153
|
fieldData,
|
|
1147
1154
|
{ cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
|
|
1148
1155
|
options,
|
|
1149
|
-
context,
|
|
1156
|
+
{ ...context, requestFieldCacheKey },
|
|
1150
1157
|
);
|
|
1151
1158
|
|
|
1152
1159
|
if (hasChildFields(field, { fragmentDefinitions: context.fragmentDefinitions })) {
|
|
@@ -1163,12 +1170,12 @@ export class CacheManager implements CacheManagerDef {
|
|
|
1163
1170
|
normalizedResponseData: RawResponseDataWithMaybeCacheMetadata,
|
|
1164
1171
|
context: CacheManagerContext,
|
|
1165
1172
|
) {
|
|
1166
|
-
const responseChunks = this._responseChunksAwaitingCaching.get(context.
|
|
1173
|
+
const responseChunks = this._responseChunksAwaitingCaching.get(context.requestID);
|
|
1167
1174
|
|
|
1168
1175
|
if (responseChunks) {
|
|
1169
|
-
this._responseChunksAwaitingCaching.set(context.
|
|
1176
|
+
this._responseChunksAwaitingCaching.set(context.requestID, [...responseChunks, normalizedResponseData]);
|
|
1170
1177
|
} else {
|
|
1171
|
-
this._responseChunksAwaitingCaching.set(context.
|
|
1178
|
+
this._responseChunksAwaitingCaching.set(context.requestID, [normalizedResponseData]);
|
|
1172
1179
|
}
|
|
1173
1180
|
}
|
|
1174
1181
|
}
|