@graphql-box/cache-manager 2.4.2 → 3.1.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 +63 -27
- package/lib/main/helpers/isFirstResponseChunk.js +11 -0
- package/lib/main/helpers/isFirstResponseChunk.js.map +1 -0
- package/lib/main/helpers/isLastResponseChunk.js +11 -0
- package/lib/main/helpers/isLastResponseChunk.js.map +1 -0
- package/lib/main/helpers/isNotLastResponseChunk.js +11 -0
- package/lib/main/helpers/isNotLastResponseChunk.js.map +1 -0
- package/lib/main/helpers/isNotResponseChunk.js +11 -0
- package/lib/main/helpers/isNotResponseChunk.js.map +1 -0
- package/lib/main/helpers/mergeResponseDataSets.js +53 -0
- package/lib/main/helpers/mergeResponseDataSets.js.map +1 -0
- package/lib/main/helpers/normalizePatchResponseData.js +10 -5
- package/lib/main/helpers/normalizePatchResponseData.js.map +1 -1
- package/lib/main/main/index.js +145 -121
- package/lib/main/main/index.js.map +1 -1
- package/lib/module/helpers/isFirstResponseChunk.js +2 -0
- package/lib/module/helpers/isFirstResponseChunk.js.map +1 -0
- package/lib/module/helpers/isLastResponseChunk.js +2 -0
- package/lib/module/helpers/isLastResponseChunk.js.map +1 -0
- package/lib/module/helpers/isNotLastResponseChunk.js +2 -0
- package/lib/module/helpers/isNotLastResponseChunk.js.map +1 -0
- package/lib/module/helpers/isNotResponseChunk.js +2 -0
- package/lib/module/helpers/isNotResponseChunk.js.map +1 -0
- package/lib/module/helpers/mergeResponseDataSets.js +41 -0
- package/lib/module/helpers/mergeResponseDataSets.js.map +1 -0
- package/lib/module/helpers/normalizePatchResponseData.js +10 -5
- package/lib/module/helpers/normalizePatchResponseData.js.map +1 -1
- package/lib/module/main/index.js +142 -121
- package/lib/module/main/index.js.map +1 -1
- package/lib/types/defs/index.d.ts +3 -10
- package/lib/types/defs/index.d.ts.map +1 -1
- package/lib/types/helpers/isFirstResponseChunk.d.ts +5 -0
- package/lib/types/helpers/isFirstResponseChunk.d.ts.map +1 -0
- package/lib/types/helpers/isLastResponseChunk.d.ts +5 -0
- package/lib/types/helpers/isLastResponseChunk.d.ts.map +1 -0
- package/lib/types/helpers/isNotLastResponseChunk.d.ts +5 -0
- package/lib/types/helpers/isNotLastResponseChunk.d.ts.map +1 -0
- package/lib/types/helpers/isNotResponseChunk.d.ts +5 -0
- package/lib/types/helpers/isNotResponseChunk.d.ts.map +1 -0
- package/lib/types/helpers/mergeResponseDataSets.d.ts +4 -0
- package/lib/types/helpers/mergeResponseDataSets.d.ts.map +1 -0
- package/lib/types/helpers/normalizePatchResponseData.d.ts +2 -8
- package/lib/types/helpers/normalizePatchResponseData.d.ts.map +1 -1
- package/lib/types/main/index.d.ts +7 -5
- package/lib/types/main/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/__snapshots__/index.test.ts.snap +12481 -11881
- package/src/defs/index.ts +14 -22
- package/src/helpers/isFirstResponseChunk.ts +5 -0
- package/src/helpers/isLastResponseChunk.ts +5 -0
- package/src/helpers/isNotLastResponseChunk.ts +5 -0
- package/src/helpers/isNotResponseChunk.ts +5 -0
- package/src/helpers/mergeResponseDataSets.ts +35 -0
- package/src/helpers/normalizePatchResponseData.ts +8 -1
- package/src/index.test.ts +191 -115
- package/src/main/index.ts +171 -137
package/src/defs/index.ts
CHANGED
|
@@ -47,14 +47,6 @@ export interface ClientOptions {
|
|
|
47
47
|
typeIDKey: string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export interface InitOptions {
|
|
51
|
-
cache: Cachemap;
|
|
52
|
-
cascadeCacheControl?: boolean;
|
|
53
|
-
fallbackOperationCacheability?: string;
|
|
54
|
-
typeCacheDirectives?: PlainObjectStringMap;
|
|
55
|
-
typeIDKey: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
50
|
export interface ConstructorOptions {
|
|
59
51
|
cache: Cachemap;
|
|
60
52
|
cascadeCacheControl?: boolean;
|
|
@@ -189,6 +181,19 @@ export interface CachemapOptions {
|
|
|
189
181
|
export interface CacheManagerDef {
|
|
190
182
|
cache: Cachemap;
|
|
191
183
|
analyzeQuery(requestData: RequestData, options: RequestOptions, context: RequestContext): Promise<AnalyzeQueryResult>;
|
|
184
|
+
cacheQuery(
|
|
185
|
+
requestData: RequestData,
|
|
186
|
+
updatedRequestData: RequestData,
|
|
187
|
+
responseData: RawResponseDataWithMaybeCacheMetadata,
|
|
188
|
+
options: RequestOptions,
|
|
189
|
+
context: RequestContext,
|
|
190
|
+
): Promise<ResponseData>;
|
|
191
|
+
cacheResponse(
|
|
192
|
+
requestData: RequestData,
|
|
193
|
+
responseData: RawResponseDataWithMaybeCacheMetadata,
|
|
194
|
+
options: RequestOptions,
|
|
195
|
+
context: RequestContext,
|
|
196
|
+
): Promise<ResponseData>;
|
|
192
197
|
checkCacheEntry(
|
|
193
198
|
cacheType: CacheTypes,
|
|
194
199
|
hash: string,
|
|
@@ -201,19 +206,6 @@ export interface CacheManagerDef {
|
|
|
201
206
|
context: RequestContext,
|
|
202
207
|
): Promise<ResponseData | false>;
|
|
203
208
|
deletePartialQueryResponse(hash: string): void;
|
|
204
|
-
resolveQuery(
|
|
205
|
-
requestData: RequestData,
|
|
206
|
-
updatedRequestData: RequestData,
|
|
207
|
-
responseData: RawResponseDataWithMaybeCacheMetadata,
|
|
208
|
-
options: RequestOptions,
|
|
209
|
-
context: RequestContext,
|
|
210
|
-
): Promise<ResponseData>;
|
|
211
|
-
resolveRequest(
|
|
212
|
-
requestData: RequestData,
|
|
213
|
-
responseData: RawResponseDataWithMaybeCacheMetadata,
|
|
214
|
-
options: RequestOptions,
|
|
215
|
-
context: RequestContext,
|
|
216
|
-
): Promise<ResponseData>;
|
|
217
209
|
}
|
|
218
210
|
|
|
219
|
-
export type CacheManagerInit = (options: ClientOptions) =>
|
|
211
|
+
export type CacheManagerInit = (options: ClientOptions) => CacheManagerDef;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RawResponseDataWithMaybeCacheMetadata } from "@graphql-box/core";
|
|
2
|
+
import { CacheManagerContext } from "..";
|
|
3
|
+
|
|
4
|
+
export default (rawResponseData: RawResponseDataWithMaybeCacheMetadata, context: CacheManagerContext) =>
|
|
5
|
+
context.hasDeferOrStream && rawResponseData.hasNext && !rawResponseData.paths;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RawResponseDataWithMaybeCacheMetadata } from "@graphql-box/core";
|
|
2
|
+
import { CacheManagerContext } from "..";
|
|
3
|
+
|
|
4
|
+
export default (rawResponseData: RawResponseDataWithMaybeCacheMetadata, context: CacheManagerContext) =>
|
|
5
|
+
context.hasDeferOrStream && !rawResponseData.hasNext && rawResponseData.paths;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RawResponseDataWithMaybeCacheMetadata } from "@graphql-box/core";
|
|
2
|
+
import { CacheManagerContext } from "..";
|
|
3
|
+
|
|
4
|
+
export default (rawResponseData: RawResponseDataWithMaybeCacheMetadata, context: CacheManagerContext) =>
|
|
5
|
+
context.hasDeferOrStream && rawResponseData.hasNext;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RawResponseDataWithMaybeCacheMetadata } from "@graphql-box/core";
|
|
2
|
+
import { CacheManagerContext } from "..";
|
|
3
|
+
|
|
4
|
+
export default (rawResponseData: RawResponseDataWithMaybeCacheMetadata, context: CacheManagerContext) =>
|
|
5
|
+
!context.hasDeferOrStream && !rawResponseData.hasNext && !rawResponseData.paths;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RawResponseDataWithMaybeCacheMetadata } from "@graphql-box/core";
|
|
2
|
+
import { merge } from "lodash";
|
|
3
|
+
|
|
4
|
+
export default (responseDataSets: RawResponseDataWithMaybeCacheMetadata[]) => {
|
|
5
|
+
return responseDataSets.reduce(
|
|
6
|
+
(acc: RawResponseDataWithMaybeCacheMetadata, dataSet, index) => {
|
|
7
|
+
const { _cacheMetadata, data, hasNext, headers, paths } = dataSet;
|
|
8
|
+
|
|
9
|
+
if (_cacheMetadata) {
|
|
10
|
+
acc._cacheMetadata = acc._cacheMetadata ? { ...acc._cacheMetadata, ..._cacheMetadata } : _cacheMetadata;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
acc.data = acc.data ? merge(acc.data, data) : data;
|
|
14
|
+
|
|
15
|
+
if (index === 0) {
|
|
16
|
+
acc.headers = headers;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (index === responseDataSets.length - 1) {
|
|
20
|
+
acc.hasNext = hasNext;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (paths) {
|
|
24
|
+
if (!acc.paths) {
|
|
25
|
+
acc.paths = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
acc.paths.push(paths[0]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return acc;
|
|
32
|
+
},
|
|
33
|
+
{ data: {} },
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { RawResponseDataWithMaybeCacheMetadata } from "@graphql-box/core";
|
|
2
2
|
import { set } from "lodash";
|
|
3
|
+
import { CacheManagerContext } from "..";
|
|
4
|
+
|
|
5
|
+
export default (rawResponseData: RawResponseDataWithMaybeCacheMetadata, context: CacheManagerContext) => {
|
|
6
|
+
if (!context.normalizePatchResponseData) {
|
|
7
|
+
return rawResponseData;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { data, paths, ...rest } = rawResponseData;
|
|
3
11
|
|
|
4
|
-
export default ({ data, paths, ...rest }: RawResponseDataWithMaybeCacheMetadata) => {
|
|
5
12
|
return {
|
|
6
13
|
...rest,
|
|
7
14
|
data: set({}, (paths as string[])[0], data),
|