houdini 1.2.53 → 1.2.55

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 (50) hide show
  1. package/build/cmd-cjs/index.js +141 -60
  2. package/build/cmd-esm/index.js +141 -60
  3. package/build/codegen-cjs/index.js +139 -58
  4. package/build/codegen-esm/index.js +139 -58
  5. package/build/lib-cjs/index.js +142 -59
  6. package/build/lib-esm/index.js +142 -59
  7. package/build/runtime/cache/cache.d.ts +1 -2
  8. package/build/runtime/cache/constants.d.ts +1 -0
  9. package/build/runtime/cache/lists.d.ts +2 -2
  10. package/build/runtime/cache/storage.d.ts +4 -4
  11. package/build/runtime/cache/stuff.d.ts +1 -0
  12. package/build/runtime/cache/subscription.d.ts +4 -1
  13. package/build/runtime-cjs/cache/cache.d.ts +1 -2
  14. package/build/runtime-cjs/cache/cache.js +41 -14
  15. package/build/runtime-cjs/cache/constants.d.ts +1 -0
  16. package/build/runtime-cjs/cache/constants.js +28 -0
  17. package/build/runtime-cjs/cache/lists.d.ts +2 -2
  18. package/build/runtime-cjs/cache/lists.js +14 -4
  19. package/build/runtime-cjs/cache/storage.d.ts +4 -4
  20. package/build/runtime-cjs/cache/storage.js +14 -6
  21. package/build/runtime-cjs/cache/stuff.d.ts +1 -0
  22. package/build/runtime-cjs/cache/stuff.js +5 -2
  23. package/build/runtime-cjs/cache/subscription.d.ts +4 -1
  24. package/build/runtime-cjs/cache/subscription.js +51 -19
  25. package/build/runtime-cjs/client/plugins/optimisticKeys.js +3 -1
  26. package/build/runtime-cjs/public/record.js +2 -2
  27. package/build/runtime-esm/cache/cache.d.ts +1 -2
  28. package/build/runtime-esm/cache/cache.js +35 -7
  29. package/build/runtime-esm/cache/constants.d.ts +1 -0
  30. package/build/runtime-esm/cache/constants.js +4 -0
  31. package/build/runtime-esm/cache/lists.d.ts +2 -2
  32. package/build/runtime-esm/cache/lists.js +13 -3
  33. package/build/runtime-esm/cache/storage.d.ts +4 -4
  34. package/build/runtime-esm/cache/storage.js +14 -6
  35. package/build/runtime-esm/cache/stuff.d.ts +1 -0
  36. package/build/runtime-esm/cache/stuff.js +3 -1
  37. package/build/runtime-esm/cache/subscription.d.ts +4 -1
  38. package/build/runtime-esm/cache/subscription.js +51 -19
  39. package/build/runtime-esm/client/plugins/optimisticKeys.js +3 -1
  40. package/build/runtime-esm/public/record.js +1 -1
  41. package/build/test-cjs/index.js +139 -58
  42. package/build/test-esm/index.js +139 -58
  43. package/build/vite-cjs/index.js +139 -58
  44. package/build/vite-esm/index.js +139 -58
  45. package/package.json +1 -1
  46. package/build/runtime/cache/schema.d.ts +0 -21
  47. package/build/runtime-cjs/cache/schema.d.ts +0 -21
  48. package/build/runtime-cjs/cache/schema.js +0 -66
  49. package/build/runtime-esm/cache/schema.d.ts +0 -21
  50. package/build/runtime-esm/cache/schema.js +0 -42
@@ -63855,6 +63855,35 @@ var GarbageCollector = class {
63855
63855
  }
63856
63856
  };
63857
63857
 
63858
+ // src/runtime/cache/stuff.ts
63859
+ function evaluateKey(key, variables = null) {
63860
+ let evaluated = "";
63861
+ let varName = "";
63862
+ let inString = false;
63863
+ for (const char of key) {
63864
+ if (varName) {
63865
+ if (varChars.includes(char)) {
63866
+ varName += char;
63867
+ continue;
63868
+ }
63869
+ const value = variables?.[varName.slice(1)];
63870
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
63871
+ varName = "";
63872
+ }
63873
+ if (char === "$" && !inString) {
63874
+ varName = "$";
63875
+ continue;
63876
+ }
63877
+ if (char === '"') {
63878
+ inString = !inString;
63879
+ }
63880
+ evaluated += char;
63881
+ }
63882
+ return evaluated;
63883
+ }
63884
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
63885
+ var rootID = "_ROOT_";
63886
+
63858
63887
  // src/runtime/cache/lists.ts
63859
63888
  var ListManager = class {
63860
63889
  rootID;
@@ -63921,11 +63950,15 @@ var ListManager = class {
63921
63950
  this.listsByField.get(parentID).get(list.key).push(handler);
63922
63951
  }
63923
63952
  removeIDFromAllLists(id, layer) {
63953
+ let removed = false;
63924
63954
  for (const fieldMap of this.lists.values()) {
63925
63955
  for (const list of fieldMap.values()) {
63926
- list.removeID(id, void 0, layer);
63956
+ if (list.removeID(id, void 0, layer)) {
63957
+ removed = true;
63958
+ }
63927
63959
  }
63928
63960
  }
63961
+ return removed;
63929
63962
  }
63930
63963
  deleteField(parentID, field) {
63931
63964
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -64228,7 +64261,13 @@ var ListCollection = class {
64228
64261
  this.lists.forEach((list) => list.addToList(...args));
64229
64262
  }
64230
64263
  removeID(...args) {
64231
- this.lists.forEach((list) => list.removeID(...args));
64264
+ let removed = false;
64265
+ this.lists.forEach((list) => {
64266
+ if (list.removeID(...args)) {
64267
+ removed = true;
64268
+ }
64269
+ });
64270
+ return removed;
64232
64271
  }
64233
64272
  remove(...args) {
64234
64273
  this.lists.forEach((list) => list.remove(...args));
@@ -64347,6 +64386,7 @@ var InMemoryStorage = class {
64347
64386
  }
64348
64387
  registerIDMapping(from, to) {
64349
64388
  this.idMaps[from] = to;
64389
+ this.idMaps[to] = from;
64350
64390
  }
64351
64391
  createLayer(optimistic = false) {
64352
64392
  const layer = new Layer(this.idCount++);
@@ -64357,11 +64397,11 @@ var InMemoryStorage = class {
64357
64397
  insert(id, field, location, target) {
64358
64398
  return this.topLayer.insert(id, field, location, target);
64359
64399
  }
64360
- remove(id, field, target, layerToUser = this.topLayer) {
64361
- return layerToUser.remove(id, field, target);
64400
+ remove(id, field, target, layer = this.topLayer) {
64401
+ return layer.remove(id, field, target);
64362
64402
  }
64363
- delete(id, layerToUser = this.topLayer) {
64364
- return layerToUser.delete(id);
64403
+ delete(id, layer = this.topLayer) {
64404
+ return layer.delete(id);
64365
64405
  }
64366
64406
  deleteField(id, field) {
64367
64407
  return this.topLayer.deleteField(id, field);
@@ -64399,6 +64439,9 @@ var InMemoryStorage = class {
64399
64439
  return;
64400
64440
  }
64401
64441
  operations.remove.add(v);
64442
+ if (this.idMaps[v]) {
64443
+ operations.remove.add(this.idMaps[v]);
64444
+ }
64402
64445
  });
64403
64446
  if (typeof layerValue === "undefined" && defaultValue) {
64404
64447
  const targetLayer = this.topLayer;
@@ -64425,7 +64468,11 @@ var InMemoryStorage = class {
64425
64468
  operations.remove.add(op.id);
64426
64469
  }
64427
64470
  if (isInsertOperation(op)) {
64428
- operations.insert[op.location].unshift(op.id);
64471
+ if (op.location === OperationLocation.end) {
64472
+ operations.insert[op.location].unshift(op.id);
64473
+ } else {
64474
+ operations.insert[op.location].push(op.id);
64475
+ }
64429
64476
  }
64430
64477
  if (isDeleteOperation(op)) {
64431
64478
  return {
@@ -64671,7 +64718,7 @@ var Layer = class {
64671
64718
  }
64672
64719
  for (const [id, ops] of Object.entries(layer.operations)) {
64673
64720
  const fields = {};
64674
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
64721
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
64675
64722
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
64676
64723
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
64677
64724
  }
@@ -64736,34 +64783,6 @@ var OperationKind = {
64736
64783
  remove: "remove"
64737
64784
  };
64738
64785
 
64739
- // src/runtime/cache/stuff.ts
64740
- function evaluateKey(key, variables = null) {
64741
- let evaluated = "";
64742
- let varName = "";
64743
- let inString = false;
64744
- for (const char of key) {
64745
- if (varName) {
64746
- if (varChars.includes(char)) {
64747
- varName += char;
64748
- continue;
64749
- }
64750
- const value = variables?.[varName.slice(1)];
64751
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
64752
- varName = "";
64753
- }
64754
- if (char === "$" && !inString) {
64755
- varName = "$";
64756
- continue;
64757
- }
64758
- if (char === '"') {
64759
- inString = !inString;
64760
- }
64761
- evaluated += char;
64762
- }
64763
- return evaluated;
64764
- }
64765
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
64766
-
64767
64786
  // src/runtime/cache/subscription.ts
64768
64787
  var InMemorySubscriptions = class {
64769
64788
  cache;
@@ -64775,6 +64794,9 @@ var InMemorySubscriptions = class {
64775
64794
  activeFields(parent) {
64776
64795
  return Object.keys(this.subscribers.get(parent) || {});
64777
64796
  }
64797
+ copySubscribers(from, to) {
64798
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
64799
+ }
64778
64800
  add({
64779
64801
  parent,
64780
64802
  spec,
@@ -64957,6 +64979,11 @@ var InMemorySubscriptions = class {
64957
64979
  get(id, field) {
64958
64980
  return this.subscribers.get(id)?.get(field)?.selections || [];
64959
64981
  }
64982
+ getAll(id) {
64983
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
64984
+ (fieldSub) => fieldSub.selections
64985
+ );
64986
+ }
64960
64987
  remove(id, selection, targets, variables, visited = []) {
64961
64988
  visited.push(id);
64962
64989
  const linkedIDs = [];
@@ -64998,7 +65025,7 @@ var InMemorySubscriptions = class {
64998
65025
  }
64999
65026
  const subscriberField = subscriber.get(fieldName);
65000
65027
  for (const spec of specs) {
65001
- const counts = subscriber.get(fieldName)?.referenceCounts;
65028
+ const counts = subscriberField?.referenceCounts;
65002
65029
  if (!counts?.has(spec.set)) {
65003
65030
  continue;
65004
65031
  }
@@ -65021,24 +65048,23 @@ var InMemorySubscriptions = class {
65021
65048
  this.subscribers.delete(id);
65022
65049
  }
65023
65050
  }
65024
- removeAllSubscribers(id, targets, visited = []) {
65025
- visited.push(id);
65026
- const subscriber = this.subscribers.get(id);
65027
- for (const [key, val] of subscriber?.entries() ?? []) {
65028
- const subscribers = targets || val.selections.map(([spec]) => spec);
65029
- this.removeSubscribers(id, key, subscribers);
65030
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
65031
- if (kind === "scalar") {
65032
- continue;
65033
- }
65034
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
65035
- for (const id2 of nextTargets) {
65036
- if (visited.includes(id2)) {
65037
- continue;
65038
- }
65039
- this.removeAllSubscribers(id2, subscribers, visited);
65051
+ removeAllSubscribers(id, targets) {
65052
+ if (!targets) {
65053
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
65054
+ (spec) => spec.selections.flatMap((sel) => sel[0])
65055
+ );
65056
+ }
65057
+ for (const target of targets) {
65058
+ for (const subselection of this.findSubSelections(
65059
+ target.parentID || rootID,
65060
+ target.selection,
65061
+ target.variables || {},
65062
+ id
65063
+ )) {
65064
+ this.remove(id, subselection, targets, target.variables || {});
65040
65065
  }
65041
65066
  }
65067
+ return;
65042
65068
  }
65043
65069
  get size() {
65044
65070
  let size = 0;
@@ -65049,6 +65075,32 @@ var InMemorySubscriptions = class {
65049
65075
  }
65050
65076
  return size;
65051
65077
  }
65078
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
65079
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
65080
+ let targetSelection = getFieldsForType(selection, __typename, false);
65081
+ for (const fieldSelection of Object.values(targetSelection || {})) {
65082
+ if (!fieldSelection.selection) {
65083
+ continue;
65084
+ }
65085
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
65086
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
65087
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
65088
+ if (links.includes(searchTarget)) {
65089
+ selections.push(fieldSelection.selection);
65090
+ } else {
65091
+ for (const link of links) {
65092
+ this.findSubSelections(
65093
+ link,
65094
+ fieldSelection.selection,
65095
+ variables,
65096
+ searchTarget,
65097
+ selections
65098
+ );
65099
+ }
65100
+ }
65101
+ }
65102
+ return selections;
65103
+ }
65052
65104
  };
65053
65105
 
65054
65106
  // src/runtime/cache/cache.ts
@@ -65126,11 +65178,17 @@ var Cache = class {
65126
65178
  }
65127
65179
  registerKeyMap(source, mapped) {
65128
65180
  this._internal_unstable.storage.registerIDMapping(source, mapped);
65181
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
65129
65182
  }
65130
65183
  delete(id, layer) {
65131
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
65132
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
65133
- this._internal_unstable.storage.delete(id, layer);
65184
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
65185
+ Boolean
65186
+ );
65187
+ for (const recordID of recordIDs) {
65188
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
65189
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
65190
+ this._internal_unstable.storage.delete(recordID, layer);
65191
+ }
65134
65192
  }
65135
65193
  setConfig(config) {
65136
65194
  this._internal_unstable.setConfig(config);
@@ -65436,6 +65494,9 @@ var CacheInternal = class {
65436
65494
  layer,
65437
65495
  forceNotify
65438
65496
  });
65497
+ let action = () => {
65498
+ layer.writeLink(parent, key, linkedIDs);
65499
+ };
65439
65500
  if (applyUpdates && updates) {
65440
65501
  if (key === "edges") {
65441
65502
  const newNodeIDs = [];
@@ -65470,8 +65531,26 @@ var CacheInternal = class {
65470
65531
  }
65471
65532
  if (update === "prepend") {
65472
65533
  linkedIDs = newIDs.concat(oldIDs);
65534
+ if (layer?.optimistic) {
65535
+ action = () => {
65536
+ for (const id of newIDs) {
65537
+ if (id) {
65538
+ layer.insert(parent, key, "start", id);
65539
+ }
65540
+ }
65541
+ };
65542
+ }
65473
65543
  } else if (update === "append") {
65474
65544
  linkedIDs = oldIDs.concat(newIDs);
65545
+ if (layer?.optimistic) {
65546
+ action = () => {
65547
+ for (const id of newIDs) {
65548
+ if (id) {
65549
+ layer.insert(parent, key, "end", id);
65550
+ }
65551
+ }
65552
+ };
65553
+ }
65475
65554
  } else if (update === "replace") {
65476
65555
  linkedIDs = newIDs;
65477
65556
  }
@@ -65490,7 +65569,7 @@ var CacheInternal = class {
65490
65569
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
65491
65570
  }
65492
65571
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
65493
- layer.writeLink(parent, key, linkedIDs);
65572
+ action();
65494
65573
  }
65495
65574
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
65496
65575
  if (id == null) {
@@ -65545,6 +65624,9 @@ var CacheInternal = class {
65545
65624
  if (!targetID) {
65546
65625
  continue;
65547
65626
  }
65627
+ toNotify.push(
65628
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
65629
+ );
65548
65630
  this.cache.delete(targetID, layer);
65549
65631
  }
65550
65632
  }
@@ -65966,7 +66048,6 @@ function variableValue(value, args) {
65966
66048
  );
65967
66049
  }
65968
66050
  }
65969
- var rootID = "_ROOT_";
65970
66051
  function defaultComponentField({
65971
66052
  cache,
65972
66053
  component,
@@ -66647,7 +66728,9 @@ var optimisticKeys = (cache, callbackCache = callbacks, keyCache = keys, objectI
66647
66728
  });
66648
66729
  delete callbackCache[optimisticValue];
66649
66730
  },
66650
- onIDChange: (optimisticValue, realValue) => cache.registerKeyMap(optimisticValue, realValue)
66731
+ onIDChange: (optimisticValue, realValue) => {
66732
+ cache.registerKeyMap(optimisticValue, realValue);
66733
+ }
66651
66734
  }
66652
66735
  );
66653
66736
  }
@@ -36,7 +36,7 @@ export declare class Cache {
36
36
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
37
37
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
38
38
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
39
- registerKeyMap(source: string | number, mapped: string | number): void;
39
+ registerKeyMap(source: string, mapped: string): void;
40
40
  delete(id: string, layer?: Layer): void;
41
41
  setConfig(config: ConfigFile): void;
42
42
  markTypeStale(options?: {
@@ -153,7 +153,6 @@ export declare function evaluateVariables(variables: ValueMap, args: GraphQLObje
153
153
  [k: string]: GraphQLValue;
154
154
  };
155
155
  export declare function variableValue(value: ValueNode, args: GraphQLObject): GraphQLValue;
156
- export declare const rootID = "_ROOT_";
157
156
  export declare function fragmentReference({ component, prop, }: {
158
157
  component: {
159
158
  name: string;
@@ -0,0 +1 @@
1
+ export declare const rootID = "_ROOT_";
@@ -21,7 +21,7 @@ export declare class ListManager {
21
21
  filters?: List['filters'];
22
22
  abstract?: boolean;
23
23
  }): void;
24
- removeIDFromAllLists(id: string, layer?: Layer): void;
24
+ removeIDFromAllLists(id: string, layer?: Layer): boolean;
25
25
  deleteField(parentID: string, field: string): void;
26
26
  reset(): void;
27
27
  }
@@ -77,7 +77,7 @@ export declare class ListCollection {
77
77
  append(...args: Parameters<List['append']>): void;
78
78
  prepend(...args: Parameters<List['prepend']>): void;
79
79
  addToList(...args: Parameters<List['addToList']>): void;
80
- removeID(...args: Parameters<List['removeID']>): void;
80
+ removeID(...args: Parameters<List['removeID']>): boolean;
81
81
  remove(...args: Parameters<List['remove']>): void;
82
82
  toggleElement(...args: Parameters<List['toggleElement']>): void;
83
83
  when(when?: ListWhen): ListCollection;
@@ -3,15 +3,15 @@ export declare class InMemoryStorage {
3
3
  data: Layer[];
4
4
  private idCount;
5
5
  private rank;
6
- private idMaps;
6
+ idMaps: Record<string, string>;
7
7
  constructor();
8
8
  get layerCount(): number;
9
9
  get nextRank(): number;
10
- registerIDMapping(from: string | number, to: string | number): void;
10
+ registerIDMapping(from: string, to: string): void;
11
11
  createLayer(optimistic?: boolean): Layer;
12
12
  insert(id: string, field: string, location: OperationLocations, target: string): void;
13
- remove(id: string, field: string, target: string, layerToUser?: Layer): void;
14
- delete(id: string, layerToUser?: Layer): void;
13
+ remove(id: string, field: string, target: string, layer?: Layer): void;
14
+ delete(id: string, layer?: Layer): void;
15
15
  deleteField(id: string, field: string): void;
16
16
  getLayer(id: number): Layer;
17
17
  replaceID(replacement: {
@@ -1 +1,2 @@
1
1
  export declare function evaluateKey(key: string, variables?: Record<string, any> | null): string;
2
+ export declare const rootID = "_ROOT_";
@@ -10,6 +10,7 @@ export declare class InMemorySubscriptions {
10
10
  private subscribers;
11
11
  private keyVersions;
12
12
  activeFields(parent: string): string[];
13
+ copySubscribers(from: string, to: string): void;
13
14
  add({ parent, spec, selection, variables, parentType, }: {
14
15
  parent: string;
15
16
  parentType?: string;
@@ -41,9 +42,11 @@ export declare class InMemorySubscriptions {
41
42
  parentType: string;
42
43
  }): void;
43
44
  get(id: string, field: string): FieldSelection[];
45
+ getAll(id: string): FieldSelection[];
44
46
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
45
47
  reset(): SubscriptionSpec[];
46
48
  private removeSubscribers;
47
- removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
49
+ removeAllSubscribers(id: string, targets?: SubscriptionSpec[]): void;
48
50
  get size(): number;
51
+ findSubSelections(parentID: string, selection: SubscriptionSelection, variables: {}, searchTarget: string, selections?: SubscriptionSelection[]): Array<SubscriptionSelection>;
49
52
  }
@@ -36,7 +36,7 @@ export declare class Cache {
36
36
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
37
37
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
38
38
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
39
- registerKeyMap(source: string | number, mapped: string | number): void;
39
+ registerKeyMap(source: string, mapped: string): void;
40
40
  delete(id: string, layer?: Layer): void;
41
41
  setConfig(config: ConfigFile): void;
42
42
  markTypeStale(options?: {
@@ -153,7 +153,6 @@ export declare function evaluateVariables(variables: ValueMap, args: GraphQLObje
153
153
  [k: string]: GraphQLValue;
154
154
  };
155
155
  export declare function variableValue(value: ValueNode, args: GraphQLObject): GraphQLValue;
156
- export declare const rootID = "_ROOT_";
157
156
  export declare function fragmentReference({ component, prop, }: {
158
157
  component: {
159
158
  name: string;
@@ -22,7 +22,6 @@ __export(cache_exports, {
22
22
  defaultComponentField: () => defaultComponentField,
23
23
  evaluateVariables: () => evaluateVariables,
24
24
  fragmentReference: () => fragmentReference,
25
- rootID: () => rootID,
26
25
  variableValue: () => variableValue
27
26
  });
28
27
  module.exports = __toCommonJS(cache_exports);
@@ -50,7 +49,7 @@ class Cache {
50
49
  cache: this,
51
50
  storage: new import_storage.InMemoryStorage(),
52
51
  subscriptions: new import_subscription.InMemorySubscriptions(this),
53
- lists: new import_lists.ListManager(this, rootID),
52
+ lists: new import_lists.ListManager(this, import_stuff.rootID),
54
53
  lifetimes: new import_gc.GarbageCollector(this),
55
54
  staleManager: new import_staleManager.StaleManager(this),
56
55
  disabled: disabled ?? typeof globalThis.window === "undefined",
@@ -87,7 +86,7 @@ class Cache {
87
86
  return;
88
87
  }
89
88
  return this._internal_unstable.subscriptions.add({
90
- parent: spec.parentID || rootID,
89
+ parent: spec.parentID || import_stuff.rootID,
91
90
  spec,
92
91
  selection: spec.selection,
93
92
  variables
@@ -95,7 +94,7 @@ class Cache {
95
94
  }
96
95
  unsubscribe(spec, variables = {}) {
97
96
  return this._internal_unstable.subscriptions.remove(
98
- spec.parentID || rootID,
97
+ spec.parentID || import_stuff.rootID,
99
98
  spec.selection,
100
99
  [spec],
101
100
  variables
@@ -112,11 +111,17 @@ class Cache {
112
111
  }
113
112
  registerKeyMap(source, mapped) {
114
113
  this._internal_unstable.storage.registerIDMapping(source, mapped);
114
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
115
115
  }
116
116
  delete(id, layer) {
117
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
118
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
119
- this._internal_unstable.storage.delete(id, layer);
117
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
118
+ Boolean
119
+ );
120
+ for (const recordID of recordIDs) {
121
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
122
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
123
+ this._internal_unstable.storage.delete(recordID, layer);
124
+ }
120
125
  }
121
126
  setConfig(config) {
122
127
  this._internal_unstable.setConfig(config);
@@ -217,7 +222,7 @@ class Cache {
217
222
  notified.push(spec.set);
218
223
  spec.set(
219
224
  this._internal_unstable.getSelection({
220
- parent: spec.parentID || rootID,
225
+ parent: spec.parentID || import_stuff.rootID,
221
226
  selection: spec.selection,
222
227
  variables: spec.variables?.() || {},
223
228
  ignoreMasking: false
@@ -277,7 +282,7 @@ class CacheInternal {
277
282
  data,
278
283
  selection,
279
284
  variables = {},
280
- parent = rootID,
285
+ parent = import_stuff.rootID,
281
286
  applyUpdates,
282
287
  layer,
283
288
  toNotify = [],
@@ -422,6 +427,9 @@ class CacheInternal {
422
427
  layer,
423
428
  forceNotify
424
429
  });
430
+ let action = () => {
431
+ layer.writeLink(parent, key, linkedIDs);
432
+ };
425
433
  if (applyUpdates && updates) {
426
434
  if (key === "edges") {
427
435
  const newNodeIDs = [];
@@ -456,8 +464,26 @@ class CacheInternal {
456
464
  }
457
465
  if (update === "prepend") {
458
466
  linkedIDs = newIDs.concat(oldIDs);
467
+ if (layer?.optimistic) {
468
+ action = () => {
469
+ for (const id of newIDs) {
470
+ if (id) {
471
+ layer.insert(parent, key, "start", id);
472
+ }
473
+ }
474
+ };
475
+ }
459
476
  } else if (update === "append") {
460
477
  linkedIDs = oldIDs.concat(newIDs);
478
+ if (layer?.optimistic) {
479
+ action = () => {
480
+ for (const id of newIDs) {
481
+ if (id) {
482
+ layer.insert(parent, key, "end", id);
483
+ }
484
+ }
485
+ };
486
+ }
461
487
  } else if (update === "replace") {
462
488
  linkedIDs = newIDs;
463
489
  }
@@ -476,7 +502,7 @@ class CacheInternal {
476
502
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
477
503
  }
478
504
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
479
- layer.writeLink(parent, key, linkedIDs);
505
+ action();
480
506
  }
481
507
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
482
508
  if (id == null) {
@@ -531,6 +557,9 @@ class CacheInternal {
531
557
  if (!targetID) {
532
558
  continue;
533
559
  }
560
+ toNotify.push(
561
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
562
+ );
534
563
  this.cache.delete(targetID, layer);
535
564
  }
536
565
  }
@@ -540,7 +569,7 @@ class CacheInternal {
540
569
  }
541
570
  getSelection({
542
571
  selection,
543
- parent = rootID,
572
+ parent = import_stuff.rootID,
544
573
  variables,
545
574
  stepsFromConnection = null,
546
575
  ignoreMasking,
@@ -884,7 +913,7 @@ class CacheInternal {
884
913
  }
885
914
  }
886
915
  this.writeSelection({
887
- root: rootID,
916
+ root: import_stuff.rootID,
888
917
  selection: fields,
889
918
  parent: linkedID,
890
919
  data: entryObj,
@@ -952,7 +981,6 @@ function variableValue(value, args) {
952
981
  );
953
982
  }
954
983
  }
955
- const rootID = "_ROOT_";
956
984
  function fragmentReference({
957
985
  component,
958
986
  prop
@@ -991,6 +1019,5 @@ function defaultComponentField({
991
1019
  defaultComponentField,
992
1020
  evaluateVariables,
993
1021
  fragmentReference,
994
- rootID,
995
1022
  variableValue
996
1023
  });
@@ -0,0 +1 @@
1
+ export declare const rootID = "_ROOT_";
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ rootID: () => rootID
22
+ });
23
+ module.exports = __toCommonJS(constants_exports);
24
+ const rootID = "_ROOT_";
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ rootID
28
+ });
@@ -21,7 +21,7 @@ export declare class ListManager {
21
21
  filters?: List['filters'];
22
22
  abstract?: boolean;
23
23
  }): void;
24
- removeIDFromAllLists(id: string, layer?: Layer): void;
24
+ removeIDFromAllLists(id: string, layer?: Layer): boolean;
25
25
  deleteField(parentID: string, field: string): void;
26
26
  reset(): void;
27
27
  }
@@ -77,7 +77,7 @@ export declare class ListCollection {
77
77
  append(...args: Parameters<List['append']>): void;
78
78
  prepend(...args: Parameters<List['prepend']>): void;
79
79
  addToList(...args: Parameters<List['addToList']>): void;
80
- removeID(...args: Parameters<List['removeID']>): void;
80
+ removeID(...args: Parameters<List['removeID']>): boolean;
81
81
  remove(...args: Parameters<List['remove']>): void;
82
82
  toggleElement(...args: Parameters<List['toggleElement']>): void;
83
83
  when(when?: ListWhen): ListCollection;