houdini 1.2.54 → 1.2.56

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 +142 -60
  2. package/build/cmd-esm/index.js +142 -60
  3. package/build/codegen-cjs/index.js +140 -58
  4. package/build/codegen-esm/index.js +140 -58
  5. package/build/lib-cjs/index.js +143 -59
  6. package/build/lib-esm/index.js +143 -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 +15 -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 +15 -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 +140 -58
  42. package/build/test-esm/index.js +140 -58
  43. package/build/vite-cjs/index.js +140 -58
  44. package/build/vite-esm/index.js +140 -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
@@ -54513,6 +54513,35 @@ var GarbageCollector = class {
54513
54513
  }
54514
54514
  };
54515
54515
 
54516
+ // src/runtime/cache/stuff.ts
54517
+ function evaluateKey(key, variables = null) {
54518
+ let evaluated = "";
54519
+ let varName = "";
54520
+ let inString = false;
54521
+ for (const char of key) {
54522
+ if (varName) {
54523
+ if (varChars.includes(char)) {
54524
+ varName += char;
54525
+ continue;
54526
+ }
54527
+ const value = variables?.[varName.slice(1)];
54528
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
54529
+ varName = "";
54530
+ }
54531
+ if (char === "$" && !inString) {
54532
+ varName = "$";
54533
+ continue;
54534
+ }
54535
+ if (char === '"') {
54536
+ inString = !inString;
54537
+ }
54538
+ evaluated += char;
54539
+ }
54540
+ return evaluated;
54541
+ }
54542
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
54543
+ var rootID = "_ROOT_";
54544
+
54516
54545
  // src/runtime/cache/lists.ts
54517
54546
  var ListManager = class {
54518
54547
  rootID;
@@ -54579,11 +54608,15 @@ var ListManager = class {
54579
54608
  this.listsByField.get(parentID).get(list.key).push(handler);
54580
54609
  }
54581
54610
  removeIDFromAllLists(id, layer) {
54611
+ let removed = false;
54582
54612
  for (const fieldMap of this.lists.values()) {
54583
54613
  for (const list of fieldMap.values()) {
54584
- list.removeID(id, void 0, layer);
54614
+ if (list.removeID(id, void 0, layer)) {
54615
+ removed = true;
54616
+ }
54585
54617
  }
54586
54618
  }
54619
+ return removed;
54587
54620
  }
54588
54621
  deleteField(parentID, field) {
54589
54622
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -54886,7 +54919,13 @@ var ListCollection = class {
54886
54919
  this.lists.forEach((list) => list.addToList(...args));
54887
54920
  }
54888
54921
  removeID(...args) {
54889
- this.lists.forEach((list) => list.removeID(...args));
54922
+ let removed = false;
54923
+ this.lists.forEach((list) => {
54924
+ if (list.removeID(...args)) {
54925
+ removed = true;
54926
+ }
54927
+ });
54928
+ return removed;
54890
54929
  }
54891
54930
  remove(...args) {
54892
54931
  this.lists.forEach((list) => list.remove(...args));
@@ -55005,6 +55044,7 @@ var InMemoryStorage = class {
55005
55044
  }
55006
55045
  registerIDMapping(from, to) {
55007
55046
  this.idMaps[from] = to;
55047
+ this.idMaps[to] = from;
55008
55048
  }
55009
55049
  createLayer(optimistic = false) {
55010
55050
  const layer = new Layer(this.idCount++);
@@ -55015,11 +55055,11 @@ var InMemoryStorage = class {
55015
55055
  insert(id, field, location, target) {
55016
55056
  return this.topLayer.insert(id, field, location, target);
55017
55057
  }
55018
- remove(id, field, target, layerToUser = this.topLayer) {
55019
- return layerToUser.remove(id, field, target);
55058
+ remove(id, field, target, layer = this.topLayer) {
55059
+ return layer.remove(id, field, target);
55020
55060
  }
55021
- delete(id, layerToUser = this.topLayer) {
55022
- return layerToUser.delete(id);
55061
+ delete(id, layer = this.topLayer) {
55062
+ return layer.delete(id);
55023
55063
  }
55024
55064
  deleteField(id, field) {
55025
55065
  return this.topLayer.deleteField(id, field);
@@ -55057,6 +55097,9 @@ var InMemoryStorage = class {
55057
55097
  return;
55058
55098
  }
55059
55099
  operations.remove.add(v);
55100
+ if (this.idMaps[v]) {
55101
+ operations.remove.add(this.idMaps[v]);
55102
+ }
55060
55103
  });
55061
55104
  if (typeof layerValue === "undefined" && defaultValue) {
55062
55105
  const targetLayer = this.topLayer;
@@ -55083,7 +55126,11 @@ var InMemoryStorage = class {
55083
55126
  operations.remove.add(op.id);
55084
55127
  }
55085
55128
  if (isInsertOperation(op)) {
55086
- operations.insert[op.location].unshift(op.id);
55129
+ if (op.location === OperationLocation.end) {
55130
+ operations.insert[op.location].unshift(op.id);
55131
+ } else {
55132
+ operations.insert[op.location].push(op.id);
55133
+ }
55087
55134
  }
55088
55135
  if (isDeleteOperation(op)) {
55089
55136
  return {
@@ -55329,7 +55376,7 @@ var Layer = class {
55329
55376
  }
55330
55377
  for (const [id, ops] of Object.entries(layer.operations)) {
55331
55378
  const fields = {};
55332
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
55379
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
55333
55380
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
55334
55381
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
55335
55382
  }
@@ -55369,6 +55416,7 @@ var Layer = class {
55369
55416
  [id]: {
55370
55417
  ...this.operations[id],
55371
55418
  fields: {
55419
+ ...this.operations[id]?.fields,
55372
55420
  [field]: [...this.operations[id]?.fields[field] || [], operation]
55373
55421
  }
55374
55422
  }
@@ -55394,34 +55442,6 @@ var OperationKind = {
55394
55442
  remove: "remove"
55395
55443
  };
55396
55444
 
55397
- // src/runtime/cache/stuff.ts
55398
- function evaluateKey(key, variables = null) {
55399
- let evaluated = "";
55400
- let varName = "";
55401
- let inString = false;
55402
- for (const char of key) {
55403
- if (varName) {
55404
- if (varChars.includes(char)) {
55405
- varName += char;
55406
- continue;
55407
- }
55408
- const value = variables?.[varName.slice(1)];
55409
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
55410
- varName = "";
55411
- }
55412
- if (char === "$" && !inString) {
55413
- varName = "$";
55414
- continue;
55415
- }
55416
- if (char === '"') {
55417
- inString = !inString;
55418
- }
55419
- evaluated += char;
55420
- }
55421
- return evaluated;
55422
- }
55423
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
55424
-
55425
55445
  // src/runtime/cache/subscription.ts
55426
55446
  var InMemorySubscriptions = class {
55427
55447
  cache;
@@ -55433,6 +55453,9 @@ var InMemorySubscriptions = class {
55433
55453
  activeFields(parent2) {
55434
55454
  return Object.keys(this.subscribers.get(parent2) || {});
55435
55455
  }
55456
+ copySubscribers(from, to) {
55457
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
55458
+ }
55436
55459
  add({
55437
55460
  parent: parent2,
55438
55461
  spec,
@@ -55615,6 +55638,11 @@ var InMemorySubscriptions = class {
55615
55638
  get(id, field) {
55616
55639
  return this.subscribers.get(id)?.get(field)?.selections || [];
55617
55640
  }
55641
+ getAll(id) {
55642
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
55643
+ (fieldSub) => fieldSub.selections
55644
+ );
55645
+ }
55618
55646
  remove(id, selection, targets, variables, visited = []) {
55619
55647
  visited.push(id);
55620
55648
  const linkedIDs = [];
@@ -55656,7 +55684,7 @@ var InMemorySubscriptions = class {
55656
55684
  }
55657
55685
  const subscriberField = subscriber.get(fieldName);
55658
55686
  for (const spec of specs) {
55659
- const counts = subscriber.get(fieldName)?.referenceCounts;
55687
+ const counts = subscriberField?.referenceCounts;
55660
55688
  if (!counts?.has(spec.set)) {
55661
55689
  continue;
55662
55690
  }
@@ -55679,24 +55707,23 @@ var InMemorySubscriptions = class {
55679
55707
  this.subscribers.delete(id);
55680
55708
  }
55681
55709
  }
55682
- removeAllSubscribers(id, targets, visited = []) {
55683
- visited.push(id);
55684
- const subscriber = this.subscribers.get(id);
55685
- for (const [key, val] of subscriber?.entries() ?? []) {
55686
- const subscribers = targets || val.selections.map(([spec]) => spec);
55687
- this.removeSubscribers(id, key, subscribers);
55688
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
55689
- if (kind === "scalar") {
55690
- continue;
55691
- }
55692
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
55693
- for (const id2 of nextTargets) {
55694
- if (visited.includes(id2)) {
55695
- continue;
55696
- }
55697
- this.removeAllSubscribers(id2, subscribers, visited);
55710
+ removeAllSubscribers(id, targets) {
55711
+ if (!targets) {
55712
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
55713
+ (spec) => spec.selections.flatMap((sel) => sel[0])
55714
+ );
55715
+ }
55716
+ for (const target of targets) {
55717
+ for (const subselection of this.findSubSelections(
55718
+ target.parentID || rootID,
55719
+ target.selection,
55720
+ target.variables || {},
55721
+ id
55722
+ )) {
55723
+ this.remove(id, subselection, targets, target.variables || {});
55698
55724
  }
55699
55725
  }
55726
+ return;
55700
55727
  }
55701
55728
  get size() {
55702
55729
  let size = 0;
@@ -55707,6 +55734,32 @@ var InMemorySubscriptions = class {
55707
55734
  }
55708
55735
  return size;
55709
55736
  }
55737
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
55738
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
55739
+ let targetSelection = getFieldsForType(selection, __typename, false);
55740
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55741
+ if (!fieldSelection.selection) {
55742
+ continue;
55743
+ }
55744
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
55745
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
55746
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
55747
+ if (links.includes(searchTarget)) {
55748
+ selections.push(fieldSelection.selection);
55749
+ } else {
55750
+ for (const link of links) {
55751
+ this.findSubSelections(
55752
+ link,
55753
+ fieldSelection.selection,
55754
+ variables,
55755
+ searchTarget,
55756
+ selections
55757
+ );
55758
+ }
55759
+ }
55760
+ }
55761
+ return selections;
55762
+ }
55710
55763
  };
55711
55764
 
55712
55765
  // src/runtime/cache/cache.ts
@@ -55784,11 +55837,17 @@ var Cache = class {
55784
55837
  }
55785
55838
  registerKeyMap(source, mapped) {
55786
55839
  this._internal_unstable.storage.registerIDMapping(source, mapped);
55840
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
55787
55841
  }
55788
55842
  delete(id, layer) {
55789
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
55790
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
55791
- this._internal_unstable.storage.delete(id, layer);
55843
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
55844
+ Boolean
55845
+ );
55846
+ for (const recordID of recordIDs) {
55847
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
55848
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
55849
+ this._internal_unstable.storage.delete(recordID, layer);
55850
+ }
55792
55851
  }
55793
55852
  setConfig(config) {
55794
55853
  this._internal_unstable.setConfig(config);
@@ -56094,6 +56153,9 @@ var CacheInternal = class {
56094
56153
  layer,
56095
56154
  forceNotify
56096
56155
  });
56156
+ let action = () => {
56157
+ layer.writeLink(parent2, key, linkedIDs);
56158
+ };
56097
56159
  if (applyUpdates && updates) {
56098
56160
  if (key === "edges") {
56099
56161
  const newNodeIDs = [];
@@ -56128,8 +56190,26 @@ var CacheInternal = class {
56128
56190
  }
56129
56191
  if (update === "prepend") {
56130
56192
  linkedIDs = newIDs.concat(oldIDs);
56193
+ if (layer?.optimistic) {
56194
+ action = () => {
56195
+ for (const id of newIDs) {
56196
+ if (id) {
56197
+ layer.insert(parent2, key, "start", id);
56198
+ }
56199
+ }
56200
+ };
56201
+ }
56131
56202
  } else if (update === "append") {
56132
56203
  linkedIDs = oldIDs.concat(newIDs);
56204
+ if (layer?.optimistic) {
56205
+ action = () => {
56206
+ for (const id of newIDs) {
56207
+ if (id) {
56208
+ layer.insert(parent2, key, "end", id);
56209
+ }
56210
+ }
56211
+ };
56212
+ }
56133
56213
  } else if (update === "replace") {
56134
56214
  linkedIDs = newIDs;
56135
56215
  }
@@ -56148,7 +56228,7 @@ var CacheInternal = class {
56148
56228
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56149
56229
  }
56150
56230
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56151
- layer.writeLink(parent2, key, linkedIDs);
56231
+ action();
56152
56232
  }
56153
56233
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56154
56234
  if (id == null) {
@@ -56203,6 +56283,9 @@ var CacheInternal = class {
56203
56283
  if (!targetID) {
56204
56284
  continue;
56205
56285
  }
56286
+ toNotify.push(
56287
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
56288
+ );
56206
56289
  this.cache.delete(targetID, layer);
56207
56290
  }
56208
56291
  }
@@ -56624,7 +56707,6 @@ function variableValue(value, args) {
56624
56707
  );
56625
56708
  }
56626
56709
  }
56627
- var rootID = "_ROOT_";
56628
56710
  function defaultComponentField({
56629
56711
  cache,
56630
56712
  component,
@@ -54513,6 +54513,35 @@ var GarbageCollector = class {
54513
54513
  }
54514
54514
  };
54515
54515
 
54516
+ // src/runtime/cache/stuff.ts
54517
+ function evaluateKey(key, variables = null) {
54518
+ let evaluated = "";
54519
+ let varName = "";
54520
+ let inString = false;
54521
+ for (const char of key) {
54522
+ if (varName) {
54523
+ if (varChars.includes(char)) {
54524
+ varName += char;
54525
+ continue;
54526
+ }
54527
+ const value = variables?.[varName.slice(1)];
54528
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
54529
+ varName = "";
54530
+ }
54531
+ if (char === "$" && !inString) {
54532
+ varName = "$";
54533
+ continue;
54534
+ }
54535
+ if (char === '"') {
54536
+ inString = !inString;
54537
+ }
54538
+ evaluated += char;
54539
+ }
54540
+ return evaluated;
54541
+ }
54542
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
54543
+ var rootID = "_ROOT_";
54544
+
54516
54545
  // src/runtime/cache/lists.ts
54517
54546
  var ListManager = class {
54518
54547
  rootID;
@@ -54579,11 +54608,15 @@ var ListManager = class {
54579
54608
  this.listsByField.get(parentID).get(list.key).push(handler);
54580
54609
  }
54581
54610
  removeIDFromAllLists(id, layer) {
54611
+ let removed = false;
54582
54612
  for (const fieldMap of this.lists.values()) {
54583
54613
  for (const list of fieldMap.values()) {
54584
- list.removeID(id, void 0, layer);
54614
+ if (list.removeID(id, void 0, layer)) {
54615
+ removed = true;
54616
+ }
54585
54617
  }
54586
54618
  }
54619
+ return removed;
54587
54620
  }
54588
54621
  deleteField(parentID, field) {
54589
54622
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -54886,7 +54919,13 @@ var ListCollection = class {
54886
54919
  this.lists.forEach((list) => list.addToList(...args));
54887
54920
  }
54888
54921
  removeID(...args) {
54889
- this.lists.forEach((list) => list.removeID(...args));
54922
+ let removed = false;
54923
+ this.lists.forEach((list) => {
54924
+ if (list.removeID(...args)) {
54925
+ removed = true;
54926
+ }
54927
+ });
54928
+ return removed;
54890
54929
  }
54891
54930
  remove(...args) {
54892
54931
  this.lists.forEach((list) => list.remove(...args));
@@ -55005,6 +55044,7 @@ var InMemoryStorage = class {
55005
55044
  }
55006
55045
  registerIDMapping(from, to) {
55007
55046
  this.idMaps[from] = to;
55047
+ this.idMaps[to] = from;
55008
55048
  }
55009
55049
  createLayer(optimistic = false) {
55010
55050
  const layer = new Layer(this.idCount++);
@@ -55015,11 +55055,11 @@ var InMemoryStorage = class {
55015
55055
  insert(id, field, location, target) {
55016
55056
  return this.topLayer.insert(id, field, location, target);
55017
55057
  }
55018
- remove(id, field, target, layerToUser = this.topLayer) {
55019
- return layerToUser.remove(id, field, target);
55058
+ remove(id, field, target, layer = this.topLayer) {
55059
+ return layer.remove(id, field, target);
55020
55060
  }
55021
- delete(id, layerToUser = this.topLayer) {
55022
- return layerToUser.delete(id);
55061
+ delete(id, layer = this.topLayer) {
55062
+ return layer.delete(id);
55023
55063
  }
55024
55064
  deleteField(id, field) {
55025
55065
  return this.topLayer.deleteField(id, field);
@@ -55057,6 +55097,9 @@ var InMemoryStorage = class {
55057
55097
  return;
55058
55098
  }
55059
55099
  operations.remove.add(v);
55100
+ if (this.idMaps[v]) {
55101
+ operations.remove.add(this.idMaps[v]);
55102
+ }
55060
55103
  });
55061
55104
  if (typeof layerValue === "undefined" && defaultValue) {
55062
55105
  const targetLayer = this.topLayer;
@@ -55083,7 +55126,11 @@ var InMemoryStorage = class {
55083
55126
  operations.remove.add(op.id);
55084
55127
  }
55085
55128
  if (isInsertOperation(op)) {
55086
- operations.insert[op.location].unshift(op.id);
55129
+ if (op.location === OperationLocation.end) {
55130
+ operations.insert[op.location].unshift(op.id);
55131
+ } else {
55132
+ operations.insert[op.location].push(op.id);
55133
+ }
55087
55134
  }
55088
55135
  if (isDeleteOperation(op)) {
55089
55136
  return {
@@ -55329,7 +55376,7 @@ var Layer = class {
55329
55376
  }
55330
55377
  for (const [id, ops] of Object.entries(layer.operations)) {
55331
55378
  const fields = {};
55332
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
55379
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
55333
55380
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
55334
55381
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
55335
55382
  }
@@ -55369,6 +55416,7 @@ var Layer = class {
55369
55416
  [id]: {
55370
55417
  ...this.operations[id],
55371
55418
  fields: {
55419
+ ...this.operations[id]?.fields,
55372
55420
  [field]: [...this.operations[id]?.fields[field] || [], operation]
55373
55421
  }
55374
55422
  }
@@ -55394,34 +55442,6 @@ var OperationKind = {
55394
55442
  remove: "remove"
55395
55443
  };
55396
55444
 
55397
- // src/runtime/cache/stuff.ts
55398
- function evaluateKey(key, variables = null) {
55399
- let evaluated = "";
55400
- let varName = "";
55401
- let inString = false;
55402
- for (const char of key) {
55403
- if (varName) {
55404
- if (varChars.includes(char)) {
55405
- varName += char;
55406
- continue;
55407
- }
55408
- const value = variables?.[varName.slice(1)];
55409
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
55410
- varName = "";
55411
- }
55412
- if (char === "$" && !inString) {
55413
- varName = "$";
55414
- continue;
55415
- }
55416
- if (char === '"') {
55417
- inString = !inString;
55418
- }
55419
- evaluated += char;
55420
- }
55421
- return evaluated;
55422
- }
55423
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
55424
-
55425
55445
  // src/runtime/cache/subscription.ts
55426
55446
  var InMemorySubscriptions = class {
55427
55447
  cache;
@@ -55433,6 +55453,9 @@ var InMemorySubscriptions = class {
55433
55453
  activeFields(parent2) {
55434
55454
  return Object.keys(this.subscribers.get(parent2) || {});
55435
55455
  }
55456
+ copySubscribers(from, to) {
55457
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
55458
+ }
55436
55459
  add({
55437
55460
  parent: parent2,
55438
55461
  spec,
@@ -55615,6 +55638,11 @@ var InMemorySubscriptions = class {
55615
55638
  get(id, field) {
55616
55639
  return this.subscribers.get(id)?.get(field)?.selections || [];
55617
55640
  }
55641
+ getAll(id) {
55642
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
55643
+ (fieldSub) => fieldSub.selections
55644
+ );
55645
+ }
55618
55646
  remove(id, selection, targets, variables, visited = []) {
55619
55647
  visited.push(id);
55620
55648
  const linkedIDs = [];
@@ -55656,7 +55684,7 @@ var InMemorySubscriptions = class {
55656
55684
  }
55657
55685
  const subscriberField = subscriber.get(fieldName);
55658
55686
  for (const spec of specs) {
55659
- const counts = subscriber.get(fieldName)?.referenceCounts;
55687
+ const counts = subscriberField?.referenceCounts;
55660
55688
  if (!counts?.has(spec.set)) {
55661
55689
  continue;
55662
55690
  }
@@ -55679,24 +55707,23 @@ var InMemorySubscriptions = class {
55679
55707
  this.subscribers.delete(id);
55680
55708
  }
55681
55709
  }
55682
- removeAllSubscribers(id, targets, visited = []) {
55683
- visited.push(id);
55684
- const subscriber = this.subscribers.get(id);
55685
- for (const [key, val] of subscriber?.entries() ?? []) {
55686
- const subscribers = targets || val.selections.map(([spec]) => spec);
55687
- this.removeSubscribers(id, key, subscribers);
55688
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
55689
- if (kind === "scalar") {
55690
- continue;
55691
- }
55692
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
55693
- for (const id2 of nextTargets) {
55694
- if (visited.includes(id2)) {
55695
- continue;
55696
- }
55697
- this.removeAllSubscribers(id2, subscribers, visited);
55710
+ removeAllSubscribers(id, targets) {
55711
+ if (!targets) {
55712
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
55713
+ (spec) => spec.selections.flatMap((sel) => sel[0])
55714
+ );
55715
+ }
55716
+ for (const target of targets) {
55717
+ for (const subselection of this.findSubSelections(
55718
+ target.parentID || rootID,
55719
+ target.selection,
55720
+ target.variables || {},
55721
+ id
55722
+ )) {
55723
+ this.remove(id, subselection, targets, target.variables || {});
55698
55724
  }
55699
55725
  }
55726
+ return;
55700
55727
  }
55701
55728
  get size() {
55702
55729
  let size = 0;
@@ -55707,6 +55734,32 @@ var InMemorySubscriptions = class {
55707
55734
  }
55708
55735
  return size;
55709
55736
  }
55737
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
55738
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
55739
+ let targetSelection = getFieldsForType(selection, __typename, false);
55740
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55741
+ if (!fieldSelection.selection) {
55742
+ continue;
55743
+ }
55744
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
55745
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
55746
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
55747
+ if (links.includes(searchTarget)) {
55748
+ selections.push(fieldSelection.selection);
55749
+ } else {
55750
+ for (const link of links) {
55751
+ this.findSubSelections(
55752
+ link,
55753
+ fieldSelection.selection,
55754
+ variables,
55755
+ searchTarget,
55756
+ selections
55757
+ );
55758
+ }
55759
+ }
55760
+ }
55761
+ return selections;
55762
+ }
55710
55763
  };
55711
55764
 
55712
55765
  // src/runtime/cache/cache.ts
@@ -55784,11 +55837,17 @@ var Cache = class {
55784
55837
  }
55785
55838
  registerKeyMap(source, mapped) {
55786
55839
  this._internal_unstable.storage.registerIDMapping(source, mapped);
55840
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
55787
55841
  }
55788
55842
  delete(id, layer) {
55789
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
55790
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
55791
- this._internal_unstable.storage.delete(id, layer);
55843
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
55844
+ Boolean
55845
+ );
55846
+ for (const recordID of recordIDs) {
55847
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
55848
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
55849
+ this._internal_unstable.storage.delete(recordID, layer);
55850
+ }
55792
55851
  }
55793
55852
  setConfig(config) {
55794
55853
  this._internal_unstable.setConfig(config);
@@ -56094,6 +56153,9 @@ var CacheInternal = class {
56094
56153
  layer,
56095
56154
  forceNotify
56096
56155
  });
56156
+ let action = () => {
56157
+ layer.writeLink(parent2, key, linkedIDs);
56158
+ };
56097
56159
  if (applyUpdates && updates) {
56098
56160
  if (key === "edges") {
56099
56161
  const newNodeIDs = [];
@@ -56128,8 +56190,26 @@ var CacheInternal = class {
56128
56190
  }
56129
56191
  if (update === "prepend") {
56130
56192
  linkedIDs = newIDs.concat(oldIDs);
56193
+ if (layer?.optimistic) {
56194
+ action = () => {
56195
+ for (const id of newIDs) {
56196
+ if (id) {
56197
+ layer.insert(parent2, key, "start", id);
56198
+ }
56199
+ }
56200
+ };
56201
+ }
56131
56202
  } else if (update === "append") {
56132
56203
  linkedIDs = oldIDs.concat(newIDs);
56204
+ if (layer?.optimistic) {
56205
+ action = () => {
56206
+ for (const id of newIDs) {
56207
+ if (id) {
56208
+ layer.insert(parent2, key, "end", id);
56209
+ }
56210
+ }
56211
+ };
56212
+ }
56133
56213
  } else if (update === "replace") {
56134
56214
  linkedIDs = newIDs;
56135
56215
  }
@@ -56148,7 +56228,7 @@ var CacheInternal = class {
56148
56228
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56149
56229
  }
56150
56230
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56151
- layer.writeLink(parent2, key, linkedIDs);
56231
+ action();
56152
56232
  }
56153
56233
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56154
56234
  if (id == null) {
@@ -56203,6 +56283,9 @@ var CacheInternal = class {
56203
56283
  if (!targetID) {
56204
56284
  continue;
56205
56285
  }
56286
+ toNotify.push(
56287
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
56288
+ );
56206
56289
  this.cache.delete(targetID, layer);
56207
56290
  }
56208
56291
  }
@@ -56624,7 +56707,6 @@ function variableValue(value, args) {
56624
56707
  );
56625
56708
  }
56626
56709
  }
56627
- var rootID = "_ROOT_";
56628
56710
  function defaultComponentField({
56629
56711
  cache,
56630
56712
  component,