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
@@ -54520,6 +54520,35 @@ var GarbageCollector = class {
54520
54520
  }
54521
54521
  };
54522
54522
 
54523
+ // src/runtime/cache/stuff.ts
54524
+ function evaluateKey(key, variables = null) {
54525
+ let evaluated = "";
54526
+ let varName = "";
54527
+ let inString = false;
54528
+ for (const char of key) {
54529
+ if (varName) {
54530
+ if (varChars.includes(char)) {
54531
+ varName += char;
54532
+ continue;
54533
+ }
54534
+ const value = variables?.[varName.slice(1)];
54535
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
54536
+ varName = "";
54537
+ }
54538
+ if (char === "$" && !inString) {
54539
+ varName = "$";
54540
+ continue;
54541
+ }
54542
+ if (char === '"') {
54543
+ inString = !inString;
54544
+ }
54545
+ evaluated += char;
54546
+ }
54547
+ return evaluated;
54548
+ }
54549
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
54550
+ var rootID = "_ROOT_";
54551
+
54523
54552
  // src/runtime/cache/lists.ts
54524
54553
  var ListManager = class {
54525
54554
  rootID;
@@ -54586,11 +54615,15 @@ var ListManager = class {
54586
54615
  this.listsByField.get(parentID).get(list.key).push(handler);
54587
54616
  }
54588
54617
  removeIDFromAllLists(id, layer) {
54618
+ let removed = false;
54589
54619
  for (const fieldMap of this.lists.values()) {
54590
54620
  for (const list of fieldMap.values()) {
54591
- list.removeID(id, void 0, layer);
54621
+ if (list.removeID(id, void 0, layer)) {
54622
+ removed = true;
54623
+ }
54592
54624
  }
54593
54625
  }
54626
+ return removed;
54594
54627
  }
54595
54628
  deleteField(parentID, field) {
54596
54629
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -54893,7 +54926,13 @@ var ListCollection = class {
54893
54926
  this.lists.forEach((list) => list.addToList(...args));
54894
54927
  }
54895
54928
  removeID(...args) {
54896
- this.lists.forEach((list) => list.removeID(...args));
54929
+ let removed = false;
54930
+ this.lists.forEach((list) => {
54931
+ if (list.removeID(...args)) {
54932
+ removed = true;
54933
+ }
54934
+ });
54935
+ return removed;
54897
54936
  }
54898
54937
  remove(...args) {
54899
54938
  this.lists.forEach((list) => list.remove(...args));
@@ -55012,6 +55051,7 @@ var InMemoryStorage = class {
55012
55051
  }
55013
55052
  registerIDMapping(from, to) {
55014
55053
  this.idMaps[from] = to;
55054
+ this.idMaps[to] = from;
55015
55055
  }
55016
55056
  createLayer(optimistic = false) {
55017
55057
  const layer = new Layer(this.idCount++);
@@ -55022,11 +55062,11 @@ var InMemoryStorage = class {
55022
55062
  insert(id, field, location, target) {
55023
55063
  return this.topLayer.insert(id, field, location, target);
55024
55064
  }
55025
- remove(id, field, target, layerToUser = this.topLayer) {
55026
- return layerToUser.remove(id, field, target);
55065
+ remove(id, field, target, layer = this.topLayer) {
55066
+ return layer.remove(id, field, target);
55027
55067
  }
55028
- delete(id, layerToUser = this.topLayer) {
55029
- return layerToUser.delete(id);
55068
+ delete(id, layer = this.topLayer) {
55069
+ return layer.delete(id);
55030
55070
  }
55031
55071
  deleteField(id, field) {
55032
55072
  return this.topLayer.deleteField(id, field);
@@ -55064,6 +55104,9 @@ var InMemoryStorage = class {
55064
55104
  return;
55065
55105
  }
55066
55106
  operations.remove.add(v);
55107
+ if (this.idMaps[v]) {
55108
+ operations.remove.add(this.idMaps[v]);
55109
+ }
55067
55110
  });
55068
55111
  if (typeof layerValue === "undefined" && defaultValue) {
55069
55112
  const targetLayer = this.topLayer;
@@ -55090,7 +55133,11 @@ var InMemoryStorage = class {
55090
55133
  operations.remove.add(op.id);
55091
55134
  }
55092
55135
  if (isInsertOperation(op)) {
55093
- operations.insert[op.location].unshift(op.id);
55136
+ if (op.location === OperationLocation.end) {
55137
+ operations.insert[op.location].unshift(op.id);
55138
+ } else {
55139
+ operations.insert[op.location].push(op.id);
55140
+ }
55094
55141
  }
55095
55142
  if (isDeleteOperation(op)) {
55096
55143
  return {
@@ -55336,7 +55383,7 @@ var Layer = class {
55336
55383
  }
55337
55384
  for (const [id, ops] of Object.entries(layer.operations)) {
55338
55385
  const fields = {};
55339
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
55386
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
55340
55387
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
55341
55388
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
55342
55389
  }
@@ -55376,6 +55423,7 @@ var Layer = class {
55376
55423
  [id]: {
55377
55424
  ...this.operations[id],
55378
55425
  fields: {
55426
+ ...this.operations[id]?.fields,
55379
55427
  [field]: [...this.operations[id]?.fields[field] || [], operation]
55380
55428
  }
55381
55429
  }
@@ -55401,34 +55449,6 @@ var OperationKind = {
55401
55449
  remove: "remove"
55402
55450
  };
55403
55451
 
55404
- // src/runtime/cache/stuff.ts
55405
- function evaluateKey(key, variables = null) {
55406
- let evaluated = "";
55407
- let varName = "";
55408
- let inString = false;
55409
- for (const char of key) {
55410
- if (varName) {
55411
- if (varChars.includes(char)) {
55412
- varName += char;
55413
- continue;
55414
- }
55415
- const value = variables?.[varName.slice(1)];
55416
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
55417
- varName = "";
55418
- }
55419
- if (char === "$" && !inString) {
55420
- varName = "$";
55421
- continue;
55422
- }
55423
- if (char === '"') {
55424
- inString = !inString;
55425
- }
55426
- evaluated += char;
55427
- }
55428
- return evaluated;
55429
- }
55430
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
55431
-
55432
55452
  // src/runtime/cache/subscription.ts
55433
55453
  var InMemorySubscriptions = class {
55434
55454
  cache;
@@ -55440,6 +55460,9 @@ var InMemorySubscriptions = class {
55440
55460
  activeFields(parent2) {
55441
55461
  return Object.keys(this.subscribers.get(parent2) || {});
55442
55462
  }
55463
+ copySubscribers(from, to) {
55464
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
55465
+ }
55443
55466
  add({
55444
55467
  parent: parent2,
55445
55468
  spec,
@@ -55622,6 +55645,11 @@ var InMemorySubscriptions = class {
55622
55645
  get(id, field) {
55623
55646
  return this.subscribers.get(id)?.get(field)?.selections || [];
55624
55647
  }
55648
+ getAll(id) {
55649
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
55650
+ (fieldSub) => fieldSub.selections
55651
+ );
55652
+ }
55625
55653
  remove(id, selection, targets, variables, visited = []) {
55626
55654
  visited.push(id);
55627
55655
  const linkedIDs = [];
@@ -55663,7 +55691,7 @@ var InMemorySubscriptions = class {
55663
55691
  }
55664
55692
  const subscriberField = subscriber.get(fieldName);
55665
55693
  for (const spec of specs) {
55666
- const counts = subscriber.get(fieldName)?.referenceCounts;
55694
+ const counts = subscriberField?.referenceCounts;
55667
55695
  if (!counts?.has(spec.set)) {
55668
55696
  continue;
55669
55697
  }
@@ -55686,24 +55714,23 @@ var InMemorySubscriptions = class {
55686
55714
  this.subscribers.delete(id);
55687
55715
  }
55688
55716
  }
55689
- removeAllSubscribers(id, targets, visited = []) {
55690
- visited.push(id);
55691
- const subscriber = this.subscribers.get(id);
55692
- for (const [key, val] of subscriber?.entries() ?? []) {
55693
- const subscribers = targets || val.selections.map(([spec]) => spec);
55694
- this.removeSubscribers(id, key, subscribers);
55695
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
55696
- if (kind === "scalar") {
55697
- continue;
55698
- }
55699
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
55700
- for (const id2 of nextTargets) {
55701
- if (visited.includes(id2)) {
55702
- continue;
55703
- }
55704
- this.removeAllSubscribers(id2, subscribers, visited);
55717
+ removeAllSubscribers(id, targets) {
55718
+ if (!targets) {
55719
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
55720
+ (spec) => spec.selections.flatMap((sel) => sel[0])
55721
+ );
55722
+ }
55723
+ for (const target of targets) {
55724
+ for (const subselection of this.findSubSelections(
55725
+ target.parentID || rootID,
55726
+ target.selection,
55727
+ target.variables || {},
55728
+ id
55729
+ )) {
55730
+ this.remove(id, subselection, targets, target.variables || {});
55705
55731
  }
55706
55732
  }
55733
+ return;
55707
55734
  }
55708
55735
  get size() {
55709
55736
  let size = 0;
@@ -55714,6 +55741,32 @@ var InMemorySubscriptions = class {
55714
55741
  }
55715
55742
  return size;
55716
55743
  }
55744
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
55745
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
55746
+ let targetSelection = getFieldsForType(selection, __typename, false);
55747
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55748
+ if (!fieldSelection.selection) {
55749
+ continue;
55750
+ }
55751
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
55752
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
55753
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
55754
+ if (links.includes(searchTarget)) {
55755
+ selections.push(fieldSelection.selection);
55756
+ } else {
55757
+ for (const link of links) {
55758
+ this.findSubSelections(
55759
+ link,
55760
+ fieldSelection.selection,
55761
+ variables,
55762
+ searchTarget,
55763
+ selections
55764
+ );
55765
+ }
55766
+ }
55767
+ }
55768
+ return selections;
55769
+ }
55717
55770
  };
55718
55771
 
55719
55772
  // src/runtime/cache/cache.ts
@@ -55791,11 +55844,17 @@ var Cache = class {
55791
55844
  }
55792
55845
  registerKeyMap(source, mapped) {
55793
55846
  this._internal_unstable.storage.registerIDMapping(source, mapped);
55847
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
55794
55848
  }
55795
55849
  delete(id, layer) {
55796
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
55797
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
55798
- this._internal_unstable.storage.delete(id, layer);
55850
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
55851
+ Boolean
55852
+ );
55853
+ for (const recordID of recordIDs) {
55854
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
55855
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
55856
+ this._internal_unstable.storage.delete(recordID, layer);
55857
+ }
55799
55858
  }
55800
55859
  setConfig(config) {
55801
55860
  this._internal_unstable.setConfig(config);
@@ -56101,6 +56160,9 @@ var CacheInternal = class {
56101
56160
  layer,
56102
56161
  forceNotify
56103
56162
  });
56163
+ let action = () => {
56164
+ layer.writeLink(parent2, key, linkedIDs);
56165
+ };
56104
56166
  if (applyUpdates && updates) {
56105
56167
  if (key === "edges") {
56106
56168
  const newNodeIDs = [];
@@ -56135,8 +56197,26 @@ var CacheInternal = class {
56135
56197
  }
56136
56198
  if (update === "prepend") {
56137
56199
  linkedIDs = newIDs.concat(oldIDs);
56200
+ if (layer?.optimistic) {
56201
+ action = () => {
56202
+ for (const id of newIDs) {
56203
+ if (id) {
56204
+ layer.insert(parent2, key, "start", id);
56205
+ }
56206
+ }
56207
+ };
56208
+ }
56138
56209
  } else if (update === "append") {
56139
56210
  linkedIDs = oldIDs.concat(newIDs);
56211
+ if (layer?.optimistic) {
56212
+ action = () => {
56213
+ for (const id of newIDs) {
56214
+ if (id) {
56215
+ layer.insert(parent2, key, "end", id);
56216
+ }
56217
+ }
56218
+ };
56219
+ }
56140
56220
  } else if (update === "replace") {
56141
56221
  linkedIDs = newIDs;
56142
56222
  }
@@ -56155,7 +56235,7 @@ var CacheInternal = class {
56155
56235
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56156
56236
  }
56157
56237
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56158
- layer.writeLink(parent2, key, linkedIDs);
56238
+ action();
56159
56239
  }
56160
56240
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56161
56241
  if (id == null) {
@@ -56210,6 +56290,9 @@ var CacheInternal = class {
56210
56290
  if (!targetID) {
56211
56291
  continue;
56212
56292
  }
56293
+ toNotify.push(
56294
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
56295
+ );
56213
56296
  this.cache.delete(targetID, layer);
56214
56297
  }
56215
56298
  }
@@ -56631,7 +56714,6 @@ function variableValue(value, args) {
56631
56714
  );
56632
56715
  }
56633
56716
  }
56634
- var rootID = "_ROOT_";
56635
56717
  function defaultComponentField({
56636
56718
  cache,
56637
56719
  component,
@@ -66689,6 +66689,35 @@ var GarbageCollector = class {
66689
66689
  }
66690
66690
  };
66691
66691
 
66692
+ // src/runtime/cache/stuff.ts
66693
+ function evaluateKey(key, variables = null) {
66694
+ let evaluated = "";
66695
+ let varName = "";
66696
+ let inString = false;
66697
+ for (const char of key) {
66698
+ if (varName) {
66699
+ if (varChars.includes(char)) {
66700
+ varName += char;
66701
+ continue;
66702
+ }
66703
+ const value = variables?.[varName.slice(1)];
66704
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
66705
+ varName = "";
66706
+ }
66707
+ if (char === "$" && !inString) {
66708
+ varName = "$";
66709
+ continue;
66710
+ }
66711
+ if (char === '"') {
66712
+ inString = !inString;
66713
+ }
66714
+ evaluated += char;
66715
+ }
66716
+ return evaluated;
66717
+ }
66718
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
66719
+ var rootID = "_ROOT_";
66720
+
66692
66721
  // src/runtime/cache/lists.ts
66693
66722
  var ListManager = class {
66694
66723
  rootID;
@@ -66755,11 +66784,15 @@ var ListManager = class {
66755
66784
  this.listsByField.get(parentID).get(list.key).push(handler);
66756
66785
  }
66757
66786
  removeIDFromAllLists(id, layer) {
66787
+ let removed = false;
66758
66788
  for (const fieldMap of this.lists.values()) {
66759
66789
  for (const list of fieldMap.values()) {
66760
- list.removeID(id, void 0, layer);
66790
+ if (list.removeID(id, void 0, layer)) {
66791
+ removed = true;
66792
+ }
66761
66793
  }
66762
66794
  }
66795
+ return removed;
66763
66796
  }
66764
66797
  deleteField(parentID, field) {
66765
66798
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -67062,7 +67095,13 @@ var ListCollection = class {
67062
67095
  this.lists.forEach((list) => list.addToList(...args));
67063
67096
  }
67064
67097
  removeID(...args) {
67065
- this.lists.forEach((list) => list.removeID(...args));
67098
+ let removed = false;
67099
+ this.lists.forEach((list) => {
67100
+ if (list.removeID(...args)) {
67101
+ removed = true;
67102
+ }
67103
+ });
67104
+ return removed;
67066
67105
  }
67067
67106
  remove(...args) {
67068
67107
  this.lists.forEach((list) => list.remove(...args));
@@ -67181,6 +67220,7 @@ var InMemoryStorage = class {
67181
67220
  }
67182
67221
  registerIDMapping(from, to) {
67183
67222
  this.idMaps[from] = to;
67223
+ this.idMaps[to] = from;
67184
67224
  }
67185
67225
  createLayer(optimistic = false) {
67186
67226
  const layer = new Layer(this.idCount++);
@@ -67191,11 +67231,11 @@ var InMemoryStorage = class {
67191
67231
  insert(id, field, location, target) {
67192
67232
  return this.topLayer.insert(id, field, location, target);
67193
67233
  }
67194
- remove(id, field, target, layerToUser = this.topLayer) {
67195
- return layerToUser.remove(id, field, target);
67234
+ remove(id, field, target, layer = this.topLayer) {
67235
+ return layer.remove(id, field, target);
67196
67236
  }
67197
- delete(id, layerToUser = this.topLayer) {
67198
- return layerToUser.delete(id);
67237
+ delete(id, layer = this.topLayer) {
67238
+ return layer.delete(id);
67199
67239
  }
67200
67240
  deleteField(id, field) {
67201
67241
  return this.topLayer.deleteField(id, field);
@@ -67233,6 +67273,9 @@ var InMemoryStorage = class {
67233
67273
  return;
67234
67274
  }
67235
67275
  operations.remove.add(v);
67276
+ if (this.idMaps[v]) {
67277
+ operations.remove.add(this.idMaps[v]);
67278
+ }
67236
67279
  });
67237
67280
  if (typeof layerValue === "undefined" && defaultValue) {
67238
67281
  const targetLayer = this.topLayer;
@@ -67259,7 +67302,11 @@ var InMemoryStorage = class {
67259
67302
  operations.remove.add(op.id);
67260
67303
  }
67261
67304
  if (isInsertOperation(op)) {
67262
- operations.insert[op.location].unshift(op.id);
67305
+ if (op.location === OperationLocation.end) {
67306
+ operations.insert[op.location].unshift(op.id);
67307
+ } else {
67308
+ operations.insert[op.location].push(op.id);
67309
+ }
67263
67310
  }
67264
67311
  if (isDeleteOperation(op)) {
67265
67312
  return {
@@ -67505,7 +67552,7 @@ var Layer = class {
67505
67552
  }
67506
67553
  for (const [id, ops] of Object.entries(layer.operations)) {
67507
67554
  const fields = {};
67508
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
67555
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
67509
67556
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
67510
67557
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
67511
67558
  }
@@ -67545,6 +67592,7 @@ var Layer = class {
67545
67592
  [id]: {
67546
67593
  ...this.operations[id],
67547
67594
  fields: {
67595
+ ...this.operations[id]?.fields,
67548
67596
  [field]: [...this.operations[id]?.fields[field] || [], operation]
67549
67597
  }
67550
67598
  }
@@ -67570,34 +67618,6 @@ var OperationKind = {
67570
67618
  remove: "remove"
67571
67619
  };
67572
67620
 
67573
- // src/runtime/cache/stuff.ts
67574
- function evaluateKey(key, variables = null) {
67575
- let evaluated = "";
67576
- let varName = "";
67577
- let inString = false;
67578
- for (const char of key) {
67579
- if (varName) {
67580
- if (varChars.includes(char)) {
67581
- varName += char;
67582
- continue;
67583
- }
67584
- const value = variables?.[varName.slice(1)];
67585
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
67586
- varName = "";
67587
- }
67588
- if (char === "$" && !inString) {
67589
- varName = "$";
67590
- continue;
67591
- }
67592
- if (char === '"') {
67593
- inString = !inString;
67594
- }
67595
- evaluated += char;
67596
- }
67597
- return evaluated;
67598
- }
67599
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
67600
-
67601
67621
  // src/runtime/cache/subscription.ts
67602
67622
  var InMemorySubscriptions = class {
67603
67623
  cache;
@@ -67609,6 +67629,9 @@ var InMemorySubscriptions = class {
67609
67629
  activeFields(parent2) {
67610
67630
  return Object.keys(this.subscribers.get(parent2) || {});
67611
67631
  }
67632
+ copySubscribers(from, to) {
67633
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
67634
+ }
67612
67635
  add({
67613
67636
  parent: parent2,
67614
67637
  spec,
@@ -67791,6 +67814,11 @@ var InMemorySubscriptions = class {
67791
67814
  get(id, field) {
67792
67815
  return this.subscribers.get(id)?.get(field)?.selections || [];
67793
67816
  }
67817
+ getAll(id) {
67818
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
67819
+ (fieldSub) => fieldSub.selections
67820
+ );
67821
+ }
67794
67822
  remove(id, selection, targets, variables, visited = []) {
67795
67823
  visited.push(id);
67796
67824
  const linkedIDs = [];
@@ -67832,7 +67860,7 @@ var InMemorySubscriptions = class {
67832
67860
  }
67833
67861
  const subscriberField = subscriber.get(fieldName);
67834
67862
  for (const spec of specs) {
67835
- const counts = subscriber.get(fieldName)?.referenceCounts;
67863
+ const counts = subscriberField?.referenceCounts;
67836
67864
  if (!counts?.has(spec.set)) {
67837
67865
  continue;
67838
67866
  }
@@ -67855,24 +67883,23 @@ var InMemorySubscriptions = class {
67855
67883
  this.subscribers.delete(id);
67856
67884
  }
67857
67885
  }
67858
- removeAllSubscribers(id, targets, visited = []) {
67859
- visited.push(id);
67860
- const subscriber = this.subscribers.get(id);
67861
- for (const [key, val] of subscriber?.entries() ?? []) {
67862
- const subscribers = targets || val.selections.map(([spec]) => spec);
67863
- this.removeSubscribers(id, key, subscribers);
67864
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
67865
- if (kind === "scalar") {
67866
- continue;
67867
- }
67868
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
67869
- for (const id2 of nextTargets) {
67870
- if (visited.includes(id2)) {
67871
- continue;
67872
- }
67873
- this.removeAllSubscribers(id2, subscribers, visited);
67886
+ removeAllSubscribers(id, targets) {
67887
+ if (!targets) {
67888
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
67889
+ (spec) => spec.selections.flatMap((sel) => sel[0])
67890
+ );
67891
+ }
67892
+ for (const target of targets) {
67893
+ for (const subselection of this.findSubSelections(
67894
+ target.parentID || rootID,
67895
+ target.selection,
67896
+ target.variables || {},
67897
+ id
67898
+ )) {
67899
+ this.remove(id, subselection, targets, target.variables || {});
67874
67900
  }
67875
67901
  }
67902
+ return;
67876
67903
  }
67877
67904
  get size() {
67878
67905
  let size = 0;
@@ -67883,6 +67910,32 @@ var InMemorySubscriptions = class {
67883
67910
  }
67884
67911
  return size;
67885
67912
  }
67913
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
67914
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
67915
+ let targetSelection = getFieldsForType(selection, __typename, false);
67916
+ for (const fieldSelection of Object.values(targetSelection || {})) {
67917
+ if (!fieldSelection.selection) {
67918
+ continue;
67919
+ }
67920
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
67921
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
67922
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
67923
+ if (links.includes(searchTarget)) {
67924
+ selections.push(fieldSelection.selection);
67925
+ } else {
67926
+ for (const link of links) {
67927
+ this.findSubSelections(
67928
+ link,
67929
+ fieldSelection.selection,
67930
+ variables,
67931
+ searchTarget,
67932
+ selections
67933
+ );
67934
+ }
67935
+ }
67936
+ }
67937
+ return selections;
67938
+ }
67886
67939
  };
67887
67940
 
67888
67941
  // src/runtime/cache/cache.ts
@@ -67960,11 +68013,17 @@ var Cache = class {
67960
68013
  }
67961
68014
  registerKeyMap(source, mapped) {
67962
68015
  this._internal_unstable.storage.registerIDMapping(source, mapped);
68016
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
67963
68017
  }
67964
68018
  delete(id, layer) {
67965
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
67966
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
67967
- this._internal_unstable.storage.delete(id, layer);
68019
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
68020
+ Boolean
68021
+ );
68022
+ for (const recordID of recordIDs) {
68023
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
68024
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
68025
+ this._internal_unstable.storage.delete(recordID, layer);
68026
+ }
67968
68027
  }
67969
68028
  setConfig(config2) {
67970
68029
  this._internal_unstable.setConfig(config2);
@@ -68270,6 +68329,9 @@ var CacheInternal = class {
68270
68329
  layer,
68271
68330
  forceNotify
68272
68331
  });
68332
+ let action = () => {
68333
+ layer.writeLink(parent2, key, linkedIDs);
68334
+ };
68273
68335
  if (applyUpdates && updates) {
68274
68336
  if (key === "edges") {
68275
68337
  const newNodeIDs = [];
@@ -68304,8 +68366,26 @@ var CacheInternal = class {
68304
68366
  }
68305
68367
  if (update === "prepend") {
68306
68368
  linkedIDs = newIDs.concat(oldIDs);
68369
+ if (layer?.optimistic) {
68370
+ action = () => {
68371
+ for (const id of newIDs) {
68372
+ if (id) {
68373
+ layer.insert(parent2, key, "start", id);
68374
+ }
68375
+ }
68376
+ };
68377
+ }
68307
68378
  } else if (update === "append") {
68308
68379
  linkedIDs = oldIDs.concat(newIDs);
68380
+ if (layer?.optimistic) {
68381
+ action = () => {
68382
+ for (const id of newIDs) {
68383
+ if (id) {
68384
+ layer.insert(parent2, key, "end", id);
68385
+ }
68386
+ }
68387
+ };
68388
+ }
68309
68389
  } else if (update === "replace") {
68310
68390
  linkedIDs = newIDs;
68311
68391
  }
@@ -68324,7 +68404,7 @@ var CacheInternal = class {
68324
68404
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
68325
68405
  }
68326
68406
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
68327
- layer.writeLink(parent2, key, linkedIDs);
68407
+ action();
68328
68408
  }
68329
68409
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
68330
68410
  if (id == null) {
@@ -68379,6 +68459,9 @@ var CacheInternal = class {
68379
68459
  if (!targetID) {
68380
68460
  continue;
68381
68461
  }
68462
+ toNotify.push(
68463
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
68464
+ );
68382
68465
  this.cache.delete(targetID, layer);
68383
68466
  }
68384
68467
  }
@@ -68800,7 +68883,6 @@ function variableValue(value, args) {
68800
68883
  );
68801
68884
  }
68802
68885
  }
68803
- var rootID = "_ROOT_";
68804
68886
  function defaultComponentField({
68805
68887
  cache,
68806
68888
  component,