houdini 1.2.5 → 1.2.6-next.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.
Files changed (47) hide show
  1. package/build/cmd-cjs/index.js +607 -554
  2. package/build/cmd-esm/index.js +607 -554
  3. package/build/codegen/generators/artifacts/selection.d.ts +1 -3
  4. package/build/codegen-cjs/index.js +594 -541
  5. package/build/codegen-esm/index.js +594 -541
  6. package/build/lib-cjs/index.js +35 -2
  7. package/build/lib-esm/index.js +35 -2
  8. package/build/runtime/cache/cache.d.ts +1 -0
  9. package/build/runtime/cache/gc.d.ts +1 -0
  10. package/build/runtime/cache/lists.d.ts +1 -0
  11. package/build/runtime/cache/staleManager.d.ts +1 -0
  12. package/build/runtime/cache/storage.d.ts +1 -0
  13. package/build/runtime/cache/subscription.d.ts +2 -1
  14. package/build/runtime/public/cache.d.ts +4 -0
  15. package/build/runtime-cjs/cache/cache.d.ts +1 -0
  16. package/build/runtime-cjs/cache/cache.js +10 -2
  17. package/build/runtime-cjs/cache/gc.d.ts +1 -0
  18. package/build/runtime-cjs/cache/gc.js +3 -0
  19. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  20. package/build/runtime-cjs/cache/lists.js +4 -0
  21. package/build/runtime-cjs/cache/staleManager.d.ts +1 -0
  22. package/build/runtime-cjs/cache/staleManager.js +3 -0
  23. package/build/runtime-cjs/cache/storage.d.ts +1 -0
  24. package/build/runtime-cjs/cache/storage.js +3 -0
  25. package/build/runtime-cjs/cache/subscription.d.ts +2 -1
  26. package/build/runtime-cjs/cache/subscription.js +13 -0
  27. package/build/runtime-cjs/public/cache.d.ts +4 -0
  28. package/build/runtime-cjs/public/cache.js +3 -0
  29. package/build/runtime-esm/cache/cache.d.ts +1 -0
  30. package/build/runtime-esm/cache/cache.js +10 -2
  31. package/build/runtime-esm/cache/gc.d.ts +1 -0
  32. package/build/runtime-esm/cache/gc.js +3 -0
  33. package/build/runtime-esm/cache/lists.d.ts +1 -0
  34. package/build/runtime-esm/cache/lists.js +4 -0
  35. package/build/runtime-esm/cache/staleManager.d.ts +1 -0
  36. package/build/runtime-esm/cache/staleManager.js +3 -0
  37. package/build/runtime-esm/cache/storage.d.ts +1 -0
  38. package/build/runtime-esm/cache/storage.js +3 -0
  39. package/build/runtime-esm/cache/subscription.d.ts +2 -1
  40. package/build/runtime-esm/cache/subscription.js +13 -0
  41. package/build/runtime-esm/public/cache.d.ts +4 -0
  42. package/build/runtime-esm/public/cache.js +3 -0
  43. package/build/test-cjs/index.js +597 -544
  44. package/build/test-esm/index.js +597 -544
  45. package/build/vite-cjs/index.js +612 -559
  46. package/build/vite-esm/index.js +612 -559
  47. package/package.json +1 -1
@@ -63711,6 +63711,9 @@ var GarbageCollector = class {
63711
63711
  constructor(cache) {
63712
63712
  this.cache = cache;
63713
63713
  }
63714
+ reset() {
63715
+ this.lifetimes.clear();
63716
+ }
63714
63717
  resetLifetime(id, field) {
63715
63718
  if (!this.lifetimes.get(id)) {
63716
63719
  this.lifetimes.set(id, /* @__PURE__ */ new Map());
@@ -63830,6 +63833,10 @@ var ListManager = class {
63830
63833
  }
63831
63834
  this.listsByField.get(parentID).delete(field);
63832
63835
  }
63836
+ reset() {
63837
+ this.lists.clear();
63838
+ this.listsByField.clear();
63839
+ }
63833
63840
  };
63834
63841
  var List = class {
63835
63842
  recordID;
@@ -64212,6 +64219,9 @@ var StaleManager = class {
64212
64219
  }
64213
64220
  }
64214
64221
  }
64222
+ reset() {
64223
+ this.fieldsTime.clear();
64224
+ }
64215
64225
  };
64216
64226
 
64217
64227
  // src/runtime/cache/storage.ts
@@ -64392,6 +64402,9 @@ var InMemoryStorage = class {
64392
64402
  layer.fields = fields;
64393
64403
  layer.links = links;
64394
64404
  }
64405
+ reset() {
64406
+ this.data = [];
64407
+ }
64395
64408
  };
64396
64409
  var Layer = class {
64397
64410
  id;
@@ -64837,6 +64850,18 @@ var InMemorySubscriptions = class {
64837
64850
  this.remove(linkedRecordID, linkFields, targets, visited);
64838
64851
  }
64839
64852
  }
64853
+ reset() {
64854
+ const subscribers = Object.entries(this.subscribers).filter(
64855
+ ([id]) => !id.startsWith(rootID)
64856
+ );
64857
+ for (const [id, _fields] of subscribers) {
64858
+ delete this.subscribers[id];
64859
+ }
64860
+ const subscriptionSpecs = subscribers.flatMap(
64861
+ ([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
64862
+ );
64863
+ return subscriptionSpecs;
64864
+ }
64840
64865
  removeSubscribers(id, fieldName, specs) {
64841
64866
  let targets = [];
64842
64867
  for (const spec of specs) {
@@ -65026,6 +65051,14 @@ var Cache = class {
65026
65051
  }
65027
65052
  this.#notifySubscribers(toNotify);
65028
65053
  }
65054
+ reset() {
65055
+ const subSpecs = this._internal_unstable.subscriptions.reset();
65056
+ this._internal_unstable.staleManager.reset();
65057
+ this._internal_unstable.lifetimes.reset();
65058
+ this._internal_unstable.lists.reset();
65059
+ this._internal_unstable.storage.reset();
65060
+ this.#notifySubscribers(subSpecs);
65061
+ }
65029
65062
  #notifySubscribers(subs) {
65030
65063
  if (subs.length === 0) {
65031
65064
  return;
@@ -65208,7 +65241,7 @@ var CacheInternal = class {
65208
65241
  forceNotify
65209
65242
  });
65210
65243
  }
65211
- } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
65244
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
65212
65245
  let oldIDs = [...previousValue || []];
65213
65246
  const emptyEdges = !updates ? [] : oldIDs.map((id) => {
65214
65247
  if (!id) {
@@ -65281,7 +65314,7 @@ var CacheInternal = class {
65281
65314
  } else {
65282
65315
  linkedIDs = nestedIDs;
65283
65316
  }
65284
- const contentChanged = !deepEquals(linkedIDs, oldIDs);
65317
+ const contentChanged = !deepEquals(linkedIDs, oldIDs) || previousValue === null;
65285
65318
  if (contentChanged || forceNotify) {
65286
65319
  toNotify.push(...currentSubscribers);
65287
65320
  }
@@ -63651,6 +63651,9 @@ var GarbageCollector = class {
63651
63651
  constructor(cache) {
63652
63652
  this.cache = cache;
63653
63653
  }
63654
+ reset() {
63655
+ this.lifetimes.clear();
63656
+ }
63654
63657
  resetLifetime(id, field) {
63655
63658
  if (!this.lifetimes.get(id)) {
63656
63659
  this.lifetimes.set(id, /* @__PURE__ */ new Map());
@@ -63770,6 +63773,10 @@ var ListManager = class {
63770
63773
  }
63771
63774
  this.listsByField.get(parentID).delete(field);
63772
63775
  }
63776
+ reset() {
63777
+ this.lists.clear();
63778
+ this.listsByField.clear();
63779
+ }
63773
63780
  };
63774
63781
  var List = class {
63775
63782
  recordID;
@@ -64152,6 +64159,9 @@ var StaleManager = class {
64152
64159
  }
64153
64160
  }
64154
64161
  }
64162
+ reset() {
64163
+ this.fieldsTime.clear();
64164
+ }
64155
64165
  };
64156
64166
 
64157
64167
  // src/runtime/cache/storage.ts
@@ -64332,6 +64342,9 @@ var InMemoryStorage = class {
64332
64342
  layer.fields = fields;
64333
64343
  layer.links = links;
64334
64344
  }
64345
+ reset() {
64346
+ this.data = [];
64347
+ }
64335
64348
  };
64336
64349
  var Layer = class {
64337
64350
  id;
@@ -64777,6 +64790,18 @@ var InMemorySubscriptions = class {
64777
64790
  this.remove(linkedRecordID, linkFields, targets, visited);
64778
64791
  }
64779
64792
  }
64793
+ reset() {
64794
+ const subscribers = Object.entries(this.subscribers).filter(
64795
+ ([id]) => !id.startsWith(rootID)
64796
+ );
64797
+ for (const [id, _fields] of subscribers) {
64798
+ delete this.subscribers[id];
64799
+ }
64800
+ const subscriptionSpecs = subscribers.flatMap(
64801
+ ([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
64802
+ );
64803
+ return subscriptionSpecs;
64804
+ }
64780
64805
  removeSubscribers(id, fieldName, specs) {
64781
64806
  let targets = [];
64782
64807
  for (const spec of specs) {
@@ -64966,6 +64991,14 @@ var Cache = class {
64966
64991
  }
64967
64992
  this.#notifySubscribers(toNotify);
64968
64993
  }
64994
+ reset() {
64995
+ const subSpecs = this._internal_unstable.subscriptions.reset();
64996
+ this._internal_unstable.staleManager.reset();
64997
+ this._internal_unstable.lifetimes.reset();
64998
+ this._internal_unstable.lists.reset();
64999
+ this._internal_unstable.storage.reset();
65000
+ this.#notifySubscribers(subSpecs);
65001
+ }
64969
65002
  #notifySubscribers(subs) {
64970
65003
  if (subs.length === 0) {
64971
65004
  return;
@@ -65148,7 +65181,7 @@ var CacheInternal = class {
65148
65181
  forceNotify
65149
65182
  });
65150
65183
  }
65151
- } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
65184
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
65152
65185
  let oldIDs = [...previousValue || []];
65153
65186
  const emptyEdges = !updates ? [] : oldIDs.map((id) => {
65154
65187
  if (!id) {
@@ -65221,7 +65254,7 @@ var CacheInternal = class {
65221
65254
  } else {
65222
65255
  linkedIDs = nestedIDs;
65223
65256
  }
65224
- const contentChanged = !deepEquals(linkedIDs, oldIDs);
65257
+ const contentChanged = !deepEquals(linkedIDs, oldIDs) || previousValue === null;
65225
65258
  if (contentChanged || forceNotify) {
65226
65259
  toNotify.push(...currentSubscribers);
65227
65260
  }
@@ -50,6 +50,7 @@ export declare class Cache {
50
50
  serialize(): string;
51
51
  hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
52
52
  clearLayer(layerID: Layer['id']): void;
53
+ reset(): void;
53
54
  }
54
55
  declare class CacheInternal {
55
56
  private _disabled;
@@ -4,6 +4,7 @@ export declare class GarbageCollector {
4
4
  private lifetimes;
5
5
  get cacheBufferSize(): number;
6
6
  constructor(cache: Cache);
7
+ reset(): void;
7
8
  resetLifetime(id: string, field: string): void;
8
9
  tick(): void;
9
10
  }
@@ -23,6 +23,7 @@ export declare class ListManager {
23
23
  }): void;
24
24
  removeIDFromAllLists(id: string, layer?: Layer): void;
25
25
  deleteField(parentID: string, field: string): void;
26
+ reset(): void;
26
27
  }
27
28
  export declare class List {
28
29
  readonly recordID: string;
@@ -27,4 +27,5 @@ export declare class StaleManager {
27
27
  markTypeStale(type: string): void;
28
28
  markTypeFieldStale(type: string, field: string, when?: {}): void;
29
29
  delete(id: string, field: string): void;
30
+ reset(): void;
30
31
  }
@@ -31,6 +31,7 @@ export declare class InMemoryStorage {
31
31
  fields: EntityFieldMap;
32
32
  links: LinkMap;
33
33
  }, layer?: Layer): void;
34
+ reset(): void;
34
35
  }
35
36
  export declare class Layer {
36
37
  readonly id: LayerID;
@@ -1,5 +1,5 @@
1
1
  import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
- import type { Cache } from './cache';
2
+ import { type Cache } from './cache';
3
3
  export type FieldSelection = [
4
4
  SubscriptionSpec,
5
5
  Required<SubscriptionSelection>['fields'] | undefined
@@ -43,6 +43,7 @@ export declare class InMemorySubscriptions {
43
43
  }): void;
44
44
  get(id: string, field: string): FieldSelection[];
45
45
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
46
+ reset(): SubscriptionSpec[];
46
47
  private removeSubscribers;
47
48
  removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
48
49
  }
@@ -36,4 +36,8 @@ export declare class Cache<Def extends CacheTypeDef> {
36
36
  field?: _Field;
37
37
  when?: ArgType<Def, _Type, _Field>;
38
38
  }): void;
39
+ /**
40
+ * Reset the entire cache by clearing all records and lists
41
+ */
42
+ reset(): void;
39
43
  }
@@ -50,6 +50,7 @@ export declare class Cache {
50
50
  serialize(): string;
51
51
  hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
52
52
  clearLayer(layerID: Layer['id']): void;
53
+ reset(): void;
53
54
  }
54
55
  declare class CacheInternal {
55
56
  private _disabled;
@@ -183,6 +183,14 @@ class Cache {
183
183
  }
184
184
  this.#notifySubscribers(toNotify);
185
185
  }
186
+ reset() {
187
+ const subSpecs = this._internal_unstable.subscriptions.reset();
188
+ this._internal_unstable.staleManager.reset();
189
+ this._internal_unstable.lifetimes.reset();
190
+ this._internal_unstable.lists.reset();
191
+ this._internal_unstable.storage.reset();
192
+ this.#notifySubscribers(subSpecs);
193
+ }
186
194
  #notifySubscribers(subs) {
187
195
  if (subs.length === 0) {
188
196
  return;
@@ -365,7 +373,7 @@ class CacheInternal {
365
373
  forceNotify
366
374
  });
367
375
  }
368
- } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
376
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
369
377
  let oldIDs = [...previousValue || []];
370
378
  const emptyEdges = !updates ? [] : oldIDs.map((id) => {
371
379
  if (!id) {
@@ -438,7 +446,7 @@ class CacheInternal {
438
446
  } else {
439
447
  linkedIDs = nestedIDs;
440
448
  }
441
- const contentChanged = !(0, import_deepEquals.deepEquals)(linkedIDs, oldIDs);
449
+ const contentChanged = !(0, import_deepEquals.deepEquals)(linkedIDs, oldIDs) || previousValue === null;
442
450
  if (contentChanged || forceNotify) {
443
451
  toNotify.push(...currentSubscribers);
444
452
  }
@@ -4,6 +4,7 @@ export declare class GarbageCollector {
4
4
  private lifetimes;
5
5
  get cacheBufferSize(): number;
6
6
  constructor(cache: Cache);
7
+ reset(): void;
7
8
  resetLifetime(id: string, field: string): void;
8
9
  tick(): void;
9
10
  }
@@ -30,6 +30,9 @@ class GarbageCollector {
30
30
  constructor(cache) {
31
31
  this.cache = cache;
32
32
  }
33
+ reset() {
34
+ this.lifetimes.clear();
35
+ }
33
36
  resetLifetime(id, field) {
34
37
  if (!this.lifetimes.get(id)) {
35
38
  this.lifetimes.set(id, /* @__PURE__ */ new Map());
@@ -23,6 +23,7 @@ export declare class ListManager {
23
23
  }): void;
24
24
  removeIDFromAllLists(id: string, layer?: Layer): void;
25
25
  deleteField(parentID: string, field: string): void;
26
+ reset(): void;
26
27
  }
27
28
  export declare class List {
28
29
  readonly recordID: string;
@@ -108,6 +108,10 @@ class ListManager {
108
108
  }
109
109
  this.listsByField.get(parentID).delete(field);
110
110
  }
111
+ reset() {
112
+ this.lists.clear();
113
+ this.listsByField.clear();
114
+ }
111
115
  }
112
116
  class List {
113
117
  recordID;
@@ -27,4 +27,5 @@ export declare class StaleManager {
27
27
  markTypeStale(type: string): void;
28
28
  markTypeFieldStale(type: string, field: string, when?: {}): void;
29
29
  delete(id: string, field: string): void;
30
+ reset(): void;
30
31
  }
@@ -88,6 +88,9 @@ class StaleManager {
88
88
  }
89
89
  }
90
90
  }
91
+ reset() {
92
+ this.fieldsTime.clear();
93
+ }
91
94
  }
92
95
  // Annotate the CommonJS export names for ESM import in node:
93
96
  0 && (module.exports = {
@@ -31,6 +31,7 @@ export declare class InMemoryStorage {
31
31
  fields: EntityFieldMap;
32
32
  links: LinkMap;
33
33
  }, layer?: Layer): void;
34
+ reset(): void;
34
35
  }
35
36
  export declare class Layer {
36
37
  readonly id: LayerID;
@@ -202,6 +202,9 @@ class InMemoryStorage {
202
202
  layer.fields = fields;
203
203
  layer.links = links;
204
204
  }
205
+ reset() {
206
+ this.data = [];
207
+ }
205
208
  }
206
209
  class Layer {
207
210
  id;
@@ -1,5 +1,5 @@
1
1
  import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
- import type { Cache } from './cache';
2
+ import { type Cache } from './cache';
3
3
  export type FieldSelection = [
4
4
  SubscriptionSpec,
5
5
  Required<SubscriptionSelection>['fields'] | undefined
@@ -43,6 +43,7 @@ export declare class InMemorySubscriptions {
43
43
  }): void;
44
44
  get(id: string, field: string): FieldSelection[];
45
45
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
46
+ reset(): SubscriptionSpec[];
46
47
  private removeSubscribers;
47
48
  removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
48
49
  }
@@ -23,6 +23,7 @@ __export(subscription_exports, {
23
23
  module.exports = __toCommonJS(subscription_exports);
24
24
  var import_flatten = require("../lib/flatten");
25
25
  var import_selection = require("../lib/selection");
26
+ var import_cache = require("./cache");
26
27
  var import_stuff = require("./stuff");
27
28
  class InMemorySubscriptions {
28
29
  cache;
@@ -239,6 +240,18 @@ class InMemorySubscriptions {
239
240
  this.remove(linkedRecordID, linkFields, targets, visited);
240
241
  }
241
242
  }
243
+ reset() {
244
+ const subscribers = Object.entries(this.subscribers).filter(
245
+ ([id]) => !id.startsWith(import_cache.rootID)
246
+ );
247
+ for (const [id, _fields] of subscribers) {
248
+ delete this.subscribers[id];
249
+ }
250
+ const subscriptionSpecs = subscribers.flatMap(
251
+ ([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
252
+ );
253
+ return subscriptionSpecs;
254
+ }
242
255
  removeSubscribers(id, fieldName, specs) {
243
256
  let targets = [];
244
257
  for (const spec of specs) {
@@ -36,4 +36,8 @@ export declare class Cache<Def extends CacheTypeDef> {
36
36
  field?: _Field;
37
37
  when?: ArgType<Def, _Type, _Field>;
38
38
  }): void;
39
+ /**
40
+ * Reset the entire cache by clearing all records and lists
41
+ */
42
+ reset(): void;
39
43
  }
@@ -90,6 +90,9 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
90
90
  markStale(type, options) {
91
91
  return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
92
92
  }
93
+ reset() {
94
+ return this._internal_unstable.reset();
95
+ }
93
96
  }
94
97
  // Annotate the CommonJS export names for ESM import in node:
95
98
  0 && (module.exports = {
@@ -50,6 +50,7 @@ export declare class Cache {
50
50
  serialize(): string;
51
51
  hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
52
52
  clearLayer(layerID: Layer['id']): void;
53
+ reset(): void;
53
54
  }
54
55
  declare class CacheInternal {
55
56
  private _disabled;
@@ -158,6 +158,14 @@ class Cache {
158
158
  }
159
159
  this.#notifySubscribers(toNotify);
160
160
  }
161
+ reset() {
162
+ const subSpecs = this._internal_unstable.subscriptions.reset();
163
+ this._internal_unstable.staleManager.reset();
164
+ this._internal_unstable.lifetimes.reset();
165
+ this._internal_unstable.lists.reset();
166
+ this._internal_unstable.storage.reset();
167
+ this.#notifySubscribers(subSpecs);
168
+ }
161
169
  #notifySubscribers(subs) {
162
170
  if (subs.length === 0) {
163
171
  return;
@@ -340,7 +348,7 @@ class CacheInternal {
340
348
  forceNotify
341
349
  });
342
350
  }
343
- } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
351
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
344
352
  let oldIDs = [...previousValue || []];
345
353
  const emptyEdges = !updates ? [] : oldIDs.map((id) => {
346
354
  if (!id) {
@@ -413,7 +421,7 @@ class CacheInternal {
413
421
  } else {
414
422
  linkedIDs = nestedIDs;
415
423
  }
416
- const contentChanged = !deepEquals(linkedIDs, oldIDs);
424
+ const contentChanged = !deepEquals(linkedIDs, oldIDs) || previousValue === null;
417
425
  if (contentChanged || forceNotify) {
418
426
  toNotify.push(...currentSubscribers);
419
427
  }
@@ -4,6 +4,7 @@ export declare class GarbageCollector {
4
4
  private lifetimes;
5
5
  get cacheBufferSize(): number;
6
6
  constructor(cache: Cache);
7
+ reset(): void;
7
8
  resetLifetime(id: string, field: string): void;
8
9
  tick(): void;
9
10
  }
@@ -7,6 +7,9 @@ class GarbageCollector {
7
7
  constructor(cache) {
8
8
  this.cache = cache;
9
9
  }
10
+ reset() {
11
+ this.lifetimes.clear();
12
+ }
10
13
  resetLifetime(id, field) {
11
14
  if (!this.lifetimes.get(id)) {
12
15
  this.lifetimes.set(id, /* @__PURE__ */ new Map());
@@ -23,6 +23,7 @@ export declare class ListManager {
23
23
  }): void;
24
24
  removeIDFromAllLists(id: string, layer?: Layer): void;
25
25
  deleteField(parentID: string, field: string): void;
26
+ reset(): void;
26
27
  }
27
28
  export declare class List {
28
29
  readonly recordID: string;
@@ -83,6 +83,10 @@ class ListManager {
83
83
  }
84
84
  this.listsByField.get(parentID).delete(field);
85
85
  }
86
+ reset() {
87
+ this.lists.clear();
88
+ this.listsByField.clear();
89
+ }
86
90
  }
87
91
  class List {
88
92
  recordID;
@@ -27,4 +27,5 @@ export declare class StaleManager {
27
27
  markTypeStale(type: string): void;
28
28
  markTypeFieldStale(type: string, field: string, when?: {}): void;
29
29
  delete(id: string, field: string): void;
30
+ reset(): void;
30
31
  }
@@ -65,6 +65,9 @@ class StaleManager {
65
65
  }
66
66
  }
67
67
  }
68
+ reset() {
69
+ this.fieldsTime.clear();
70
+ }
68
71
  }
69
72
  export {
70
73
  StaleManager
@@ -31,6 +31,7 @@ export declare class InMemoryStorage {
31
31
  fields: EntityFieldMap;
32
32
  links: LinkMap;
33
33
  }, layer?: Layer): void;
34
+ reset(): void;
34
35
  }
35
36
  export declare class Layer {
36
37
  readonly id: LayerID;
@@ -176,6 +176,9 @@ class InMemoryStorage {
176
176
  layer.fields = fields;
177
177
  layer.links = links;
178
178
  }
179
+ reset() {
180
+ this.data = [];
181
+ }
179
182
  }
180
183
  class Layer {
181
184
  id;
@@ -1,5 +1,5 @@
1
1
  import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
- import type { Cache } from './cache';
2
+ import { type Cache } from './cache';
3
3
  export type FieldSelection = [
4
4
  SubscriptionSpec,
5
5
  Required<SubscriptionSelection>['fields'] | undefined
@@ -43,6 +43,7 @@ export declare class InMemorySubscriptions {
43
43
  }): void;
44
44
  get(id: string, field: string): FieldSelection[];
45
45
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
46
+ reset(): SubscriptionSpec[];
46
47
  private removeSubscribers;
47
48
  removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
48
49
  }
@@ -1,5 +1,6 @@
1
1
  import { flatten } from "../lib/flatten";
2
2
  import { getFieldsForType } from "../lib/selection";
3
+ import { rootID } from "./cache";
3
4
  import { evaluateKey } from "./stuff";
4
5
  class InMemorySubscriptions {
5
6
  cache;
@@ -216,6 +217,18 @@ class InMemorySubscriptions {
216
217
  this.remove(linkedRecordID, linkFields, targets, visited);
217
218
  }
218
219
  }
220
+ reset() {
221
+ const subscribers = Object.entries(this.subscribers).filter(
222
+ ([id]) => !id.startsWith(rootID)
223
+ );
224
+ for (const [id, _fields] of subscribers) {
225
+ delete this.subscribers[id];
226
+ }
227
+ const subscriptionSpecs = subscribers.flatMap(
228
+ ([_id, fields]) => Object.values(fields).flatMap((field) => field.map(([spec]) => spec))
229
+ );
230
+ return subscriptionSpecs;
231
+ }
219
232
  removeSubscribers(id, fieldName, specs) {
220
233
  let targets = [];
221
234
  for (const spec of specs) {
@@ -36,4 +36,8 @@ export declare class Cache<Def extends CacheTypeDef> {
36
36
  field?: _Field;
37
37
  when?: ArgType<Def, _Type, _Field>;
38
38
  }): void;
39
+ /**
40
+ * Reset the entire cache by clearing all records and lists
41
+ */
42
+ reset(): void;
39
43
  }
@@ -67,6 +67,9 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
67
67
  markStale(type, options) {
68
68
  return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
69
69
  }
70
+ reset() {
71
+ return this._internal_unstable.reset();
72
+ }
70
73
  }
71
74
  export {
72
75
  Cache