@graphql-box/cache-manager 2.5.0 → 3.0.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/src/index.test.ts CHANGED
@@ -40,7 +40,7 @@ describe("@graphql-box/cache-manager >>", () => {
40
40
  beforeAll(async () => {
41
41
  responseData = undefined;
42
42
 
43
- cacheManager = await CacheManager.init({
43
+ cacheManager = new CacheManager({
44
44
  cache: new Cachemap({
45
45
  name: "cachemap",
46
46
  store: map(),
@@ -73,7 +73,7 @@ describe("@graphql-box/cache-manager >>", () => {
73
73
  beforeAll(async () => {
74
74
  responseData = undefined;
75
75
 
76
- cacheManager = await CacheManager.init({
76
+ cacheManager = new CacheManager({
77
77
  cache: new Cachemap({
78
78
  name: "cachemap",
79
79
  store: map(),
@@ -114,7 +114,7 @@ describe("@graphql-box/cache-manager >>", () => {
114
114
  beforeAll(async () => {
115
115
  responseData = undefined;
116
116
 
117
- cacheManager = await CacheManager.init({
117
+ cacheManager = new CacheManager({
118
118
  cache: new Cachemap({
119
119
  name: "cachemap",
120
120
  store: map(),
@@ -147,7 +147,7 @@ describe("@graphql-box/cache-manager >>", () => {
147
147
  beforeAll(async () => {
148
148
  responseData = undefined;
149
149
 
150
- cacheManager = await CacheManager.init({
150
+ cacheManager = new CacheManager({
151
151
  cache: new Cachemap({
152
152
  name: "cachemap",
153
153
  store: map(),
@@ -191,7 +191,7 @@ describe("@graphql-box/cache-manager >>", () => {
191
191
  beforeAll(async () => {
192
192
  responseData = undefined;
193
193
 
194
- cacheManager = await CacheManager.init({
194
+ cacheManager = new CacheManager({
195
195
  cache: new Cachemap({
196
196
  name: "cachemap",
197
197
  store: map(),
@@ -225,7 +225,7 @@ describe("@graphql-box/cache-manager >>", () => {
225
225
  beforeAll(async () => {
226
226
  responseData = undefined;
227
227
 
228
- cacheManager = await CacheManager.init({
228
+ cacheManager = new CacheManager({
229
229
  cache: new Cachemap({
230
230
  name: "cachemap",
231
231
  store: map(),
@@ -263,7 +263,7 @@ describe("@graphql-box/cache-manager >>", () => {
263
263
  beforeAll(async () => {
264
264
  responseData = undefined;
265
265
 
266
- cacheManager = await CacheManager.init({
266
+ cacheManager = new CacheManager({
267
267
  cache: new Cachemap({
268
268
  name: "cachemap",
269
269
  store: map(),
@@ -297,7 +297,7 @@ describe("@graphql-box/cache-manager >>", () => {
297
297
  beforeAll(async () => {
298
298
  responseData = undefined;
299
299
 
300
- cacheManager = await CacheManager.init({
300
+ cacheManager = new CacheManager({
301
301
  cache: new Cachemap({
302
302
  name: "cachemap",
303
303
  store: map(),
@@ -338,7 +338,7 @@ describe("@graphql-box/cache-manager >>", () => {
338
338
  beforeAll(async () => {
339
339
  responseData = undefined;
340
340
 
341
- cacheManager = await CacheManager.init({
341
+ cacheManager = new CacheManager({
342
342
  cache: new Cachemap({
343
343
  name: "cachemap",
344
344
  store: map(),
@@ -372,7 +372,7 @@ describe("@graphql-box/cache-manager >>", () => {
372
372
  beforeAll(async () => {
373
373
  responseData = undefined;
374
374
 
375
- cacheManager = await CacheManager.init({
375
+ cacheManager = new CacheManager({
376
376
  cache: new Cachemap({
377
377
  name: "cachemap",
378
378
  store: map(),
@@ -415,7 +415,7 @@ describe("@graphql-box/cache-manager >>", () => {
415
415
  // @ts-ignore
416
416
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
417
417
 
418
- cacheManager = await CacheManager.init({
418
+ cacheManager = new CacheManager({
419
419
  cache: new Cachemap({
420
420
  name: "cachemap",
421
421
  store: map(),
@@ -467,7 +467,7 @@ describe("@graphql-box/cache-manager >>", () => {
467
467
  // @ts-ignore
468
468
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
469
469
 
470
- cacheManager = await CacheManager.init({
470
+ cacheManager = new CacheManager({
471
471
  cache: new Cachemap({
472
472
  name: "cachemap",
473
473
  store: map(),
@@ -523,7 +523,7 @@ describe("@graphql-box/cache-manager >>", () => {
523
523
  // @ts-ignore
524
524
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
525
525
 
526
- cacheManager = await CacheManager.init({
526
+ cacheManager = new CacheManager({
527
527
  cache: new Cachemap({
528
528
  name: "cachemap",
529
529
  store: map(),
@@ -575,7 +575,7 @@ describe("@graphql-box/cache-manager >>", () => {
575
575
  // @ts-ignore
576
576
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
577
577
 
578
- cacheManager = await CacheManager.init({
578
+ cacheManager = new CacheManager({
579
579
  cache: new Cachemap({
580
580
  name: "cachemap",
581
581
  store: map(),
@@ -634,7 +634,7 @@ describe("@graphql-box/cache-manager >>", () => {
634
634
  // @ts-ignore
635
635
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
636
636
 
637
- cacheManager = await CacheManager.init({
637
+ cacheManager = new CacheManager({
638
638
  cache: new Cachemap({
639
639
  name: "cachemap",
640
640
  store: map(),
@@ -686,7 +686,7 @@ describe("@graphql-box/cache-manager >>", () => {
686
686
  // @ts-ignore
687
687
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
688
688
 
689
- cacheManager = await CacheManager.init({
689
+ cacheManager = new CacheManager({
690
690
  cache: new Cachemap({
691
691
  name: "cachemap",
692
692
  store: map(),
@@ -744,7 +744,7 @@ describe("@graphql-box/cache-manager >>", () => {
744
744
  // @ts-ignore
745
745
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
746
746
 
747
- cacheManager = await CacheManager.init({
747
+ cacheManager = new CacheManager({
748
748
  cache: new Cachemap({
749
749
  name: "cachemap",
750
750
  store: map(),
@@ -818,7 +818,7 @@ describe("@graphql-box/cache-manager >>", () => {
818
818
  beforeAll(async () => {
819
819
  analyzeQueryResult = undefined;
820
820
 
821
- cacheManager = await CacheManager.init({
821
+ cacheManager = new CacheManager({
822
822
  cache: new Cachemap({
823
823
  name: "cachemap",
824
824
  store: map(),
@@ -848,7 +848,7 @@ describe("@graphql-box/cache-manager >>", () => {
848
848
  beforeAll(async () => {
849
849
  analyzeQueryResult = undefined;
850
850
 
851
- cacheManager = await CacheManager.init({
851
+ cacheManager = new CacheManager({
852
852
  cache: new Cachemap({
853
853
  name: "cachemap",
854
854
  store: map(),
@@ -878,7 +878,7 @@ describe("@graphql-box/cache-manager >>", () => {
878
878
  beforeAll(async () => {
879
879
  analyzeQueryResult = undefined;
880
880
 
881
- cacheManager = await CacheManager.init({
881
+ cacheManager = new CacheManager({
882
882
  cache: new Cachemap({
883
883
  name: "cachemap",
884
884
  store: map(),
@@ -908,7 +908,7 @@ describe("@graphql-box/cache-manager >>", () => {
908
908
  beforeAll(async () => {
909
909
  analyzeQueryResult = undefined;
910
910
 
911
- cacheManager = await CacheManager.init({
911
+ cacheManager = new CacheManager({
912
912
  cache: new Cachemap({
913
913
  name: "cachemap",
914
914
  store: map(),
@@ -942,7 +942,7 @@ describe("@graphql-box/cache-manager >>", () => {
942
942
  // @ts-ignore
943
943
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
944
944
 
945
- cacheManager = await CacheManager.init({
945
+ cacheManager = new CacheManager({
946
946
  cache: new Cachemap({
947
947
  name: "cachemap",
948
948
  store: map(),
@@ -990,7 +990,7 @@ describe("@graphql-box/cache-manager >>", () => {
990
990
  // @ts-ignore
991
991
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
992
992
 
993
- cacheManager = await CacheManager.init({
993
+ cacheManager = new CacheManager({
994
994
  cache: new Cachemap({
995
995
  name: "cachemap",
996
996
  store: map(),
@@ -1041,7 +1041,7 @@ describe("@graphql-box/cache-manager >>", () => {
1041
1041
  // @ts-ignore
1042
1042
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1043
1043
 
1044
- cacheManager = await CacheManager.init({
1044
+ cacheManager = new CacheManager({
1045
1045
  cache: new Cachemap({
1046
1046
  name: "cachemap",
1047
1047
  store: map(),
@@ -1090,7 +1090,7 @@ describe("@graphql-box/cache-manager >>", () => {
1090
1090
  // @ts-ignore
1091
1091
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1092
1092
 
1093
- cacheManager = await CacheManager.init({
1093
+ cacheManager = new CacheManager({
1094
1094
  cache: new Cachemap({
1095
1095
  name: "cachemap",
1096
1096
  store: map(),
@@ -1152,7 +1152,7 @@ describe("@graphql-box/cache-manager >>", () => {
1152
1152
  // @ts-ignore
1153
1153
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1154
1154
 
1155
- cacheManager = await CacheManager.init({
1155
+ cacheManager = new CacheManager({
1156
1156
  cache: new Cachemap({
1157
1157
  name: "cachemap",
1158
1158
  store: map(),
@@ -1206,7 +1206,7 @@ describe("@graphql-box/cache-manager >>", () => {
1206
1206
  // @ts-ignore
1207
1207
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1208
1208
 
1209
- cacheManager = await CacheManager.init({
1209
+ cacheManager = new CacheManager({
1210
1210
  cache: new Cachemap({
1211
1211
  name: "cachemap",
1212
1212
  store: map(),
@@ -1263,7 +1263,7 @@ describe("@graphql-box/cache-manager >>", () => {
1263
1263
  // @ts-ignore
1264
1264
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1265
1265
 
1266
- cacheManager = await CacheManager.init({
1266
+ cacheManager = new CacheManager({
1267
1267
  cache: new Cachemap({
1268
1268
  name: "cachemap",
1269
1269
  store: map(),
@@ -1318,7 +1318,7 @@ describe("@graphql-box/cache-manager >>", () => {
1318
1318
  // @ts-ignore
1319
1319
  jest.spyOn(CacheManager, "_isValid").mockReturnValue(true);
1320
1320
 
1321
- cacheManager = await CacheManager.init({
1321
+ cacheManager = new CacheManager({
1322
1322
  cache: new Cachemap({
1323
1323
  name: "cachemap",
1324
1324
  store: map(),
package/src/main/index.ts CHANGED
@@ -49,7 +49,6 @@ import {
49
49
  FieldCount,
50
50
  FieldPathChecklist,
51
51
  FieldPathChecklistValue,
52
- InitOptions,
53
52
  KeysAndPaths,
54
53
  MergedCachedFieldData,
55
54
  PartialQueryResponse,
@@ -71,25 +70,6 @@ import normalizePatchResponseData from "../helpers/normalizePatchResponseData";
71
70
  import { getValidTypeIDValue } from "../helpers/validTypeIDValue";
72
71
 
73
72
  export class CacheManager implements CacheManagerDef {
74
- public static async init(options: InitOptions): Promise<CacheManager> {
75
- const errors: TypeError[] = [];
76
-
77
- if (!options.cache) {
78
- errors.push(new TypeError("@graphql-box/cache-manager expected options.cache."));
79
- }
80
-
81
- if (!!options.typeCacheDirectives && !isPlainObject(options.typeCacheDirectives)) {
82
- const message = "@graphql-box/cache-manager expected options.typeCacheDirectives to be a plain object.";
83
- errors.push(new TypeError(message));
84
- }
85
-
86
- if (errors.length) {
87
- return Promise.reject(errors);
88
- }
89
-
90
- return new CacheManager(options);
91
- }
92
-
93
73
  private static _countFieldPathChecklist(fieldPathChecklist: FieldPathChecklist): FieldCount {
94
74
  const fieldCount: FieldCount = { missing: 0, total: 0 };
95
75
 
@@ -234,12 +214,26 @@ export class CacheManager implements CacheManagerDef {
234
214
  private _typeIDKey: string;
235
215
 
236
216
  constructor(options: ConstructorOptions) {
237
- const { cache, cascadeCacheControl, fallbackOperationCacheability, typeCacheDirectives, typeIDKey } = options;
238
- this._cache = cache;
239
- this._cascadeCacheControl = cascadeCacheControl || false;
240
- this._fallbackOperationCacheability = fallbackOperationCacheability || NO_CACHE;
241
- this._typeCacheDirectives = typeCacheDirectives || {};
242
- this._typeIDKey = typeIDKey;
217
+ const errors: TypeError[] = [];
218
+
219
+ if (!options.cache) {
220
+ errors.push(new TypeError("@graphql-box/cache-manager expected options.cache."));
221
+ }
222
+
223
+ if (!!options.typeCacheDirectives && !isPlainObject(options.typeCacheDirectives)) {
224
+ const message = "@graphql-box/cache-manager expected options.typeCacheDirectives to be a plain object.";
225
+ errors.push(new TypeError(message));
226
+ }
227
+
228
+ if (errors.length) {
229
+ throw errors;
230
+ }
231
+
232
+ this._cache = options.cache;
233
+ this._cascadeCacheControl = options.cascadeCacheControl || false;
234
+ this._fallbackOperationCacheability = options.fallbackOperationCacheability || NO_CACHE;
235
+ this._typeCacheDirectives = options.typeCacheDirectives || {};
236
+ this._typeIDKey = options.typeIDKey;
243
237
  }
244
238
 
245
239
  get cache(): Cachemap {
@@ -1175,5 +1169,5 @@ export default function init(userOptions: UserOptions): CacheManagerInit {
1175
1169
  throw new TypeError("@graphql-box/cache-manager expected userOptions to be a plain object.");
1176
1170
  }
1177
1171
 
1178
- return (clientOptions: ClientOptions) => CacheManager.init({ ...clientOptions, ...userOptions });
1172
+ return (clientOptions: ClientOptions) => new CacheManager({ ...clientOptions, ...userOptions });
1179
1173
  }