houdini 1.2.54 → 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
@@ -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
  }
@@ -55394,34 +55441,6 @@ var OperationKind = {
55394
55441
  remove: "remove"
55395
55442
  };
55396
55443
 
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
55444
  // src/runtime/cache/subscription.ts
55426
55445
  var InMemorySubscriptions = class {
55427
55446
  cache;
@@ -55433,6 +55452,9 @@ var InMemorySubscriptions = class {
55433
55452
  activeFields(parent2) {
55434
55453
  return Object.keys(this.subscribers.get(parent2) || {});
55435
55454
  }
55455
+ copySubscribers(from, to) {
55456
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
55457
+ }
55436
55458
  add({
55437
55459
  parent: parent2,
55438
55460
  spec,
@@ -55615,6 +55637,11 @@ var InMemorySubscriptions = class {
55615
55637
  get(id, field) {
55616
55638
  return this.subscribers.get(id)?.get(field)?.selections || [];
55617
55639
  }
55640
+ getAll(id) {
55641
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
55642
+ (fieldSub) => fieldSub.selections
55643
+ );
55644
+ }
55618
55645
  remove(id, selection, targets, variables, visited = []) {
55619
55646
  visited.push(id);
55620
55647
  const linkedIDs = [];
@@ -55656,7 +55683,7 @@ var InMemorySubscriptions = class {
55656
55683
  }
55657
55684
  const subscriberField = subscriber.get(fieldName);
55658
55685
  for (const spec of specs) {
55659
- const counts = subscriber.get(fieldName)?.referenceCounts;
55686
+ const counts = subscriberField?.referenceCounts;
55660
55687
  if (!counts?.has(spec.set)) {
55661
55688
  continue;
55662
55689
  }
@@ -55679,24 +55706,23 @@ var InMemorySubscriptions = class {
55679
55706
  this.subscribers.delete(id);
55680
55707
  }
55681
55708
  }
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);
55709
+ removeAllSubscribers(id, targets) {
55710
+ if (!targets) {
55711
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
55712
+ (spec) => spec.selections.flatMap((sel) => sel[0])
55713
+ );
55714
+ }
55715
+ for (const target of targets) {
55716
+ for (const subselection of this.findSubSelections(
55717
+ target.parentID || rootID,
55718
+ target.selection,
55719
+ target.variables || {},
55720
+ id
55721
+ )) {
55722
+ this.remove(id, subselection, targets, target.variables || {});
55698
55723
  }
55699
55724
  }
55725
+ return;
55700
55726
  }
55701
55727
  get size() {
55702
55728
  let size = 0;
@@ -55707,6 +55733,32 @@ var InMemorySubscriptions = class {
55707
55733
  }
55708
55734
  return size;
55709
55735
  }
55736
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
55737
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
55738
+ let targetSelection = getFieldsForType(selection, __typename, false);
55739
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55740
+ if (!fieldSelection.selection) {
55741
+ continue;
55742
+ }
55743
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
55744
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
55745
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
55746
+ if (links.includes(searchTarget)) {
55747
+ selections.push(fieldSelection.selection);
55748
+ } else {
55749
+ for (const link of links) {
55750
+ this.findSubSelections(
55751
+ link,
55752
+ fieldSelection.selection,
55753
+ variables,
55754
+ searchTarget,
55755
+ selections
55756
+ );
55757
+ }
55758
+ }
55759
+ }
55760
+ return selections;
55761
+ }
55710
55762
  };
55711
55763
 
55712
55764
  // src/runtime/cache/cache.ts
@@ -55784,11 +55836,17 @@ var Cache = class {
55784
55836
  }
55785
55837
  registerKeyMap(source, mapped) {
55786
55838
  this._internal_unstable.storage.registerIDMapping(source, mapped);
55839
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
55787
55840
  }
55788
55841
  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);
55842
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
55843
+ Boolean
55844
+ );
55845
+ for (const recordID of recordIDs) {
55846
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
55847
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
55848
+ this._internal_unstable.storage.delete(recordID, layer);
55849
+ }
55792
55850
  }
55793
55851
  setConfig(config) {
55794
55852
  this._internal_unstable.setConfig(config);
@@ -56094,6 +56152,9 @@ var CacheInternal = class {
56094
56152
  layer,
56095
56153
  forceNotify
56096
56154
  });
56155
+ let action = () => {
56156
+ layer.writeLink(parent2, key, linkedIDs);
56157
+ };
56097
56158
  if (applyUpdates && updates) {
56098
56159
  if (key === "edges") {
56099
56160
  const newNodeIDs = [];
@@ -56128,8 +56189,26 @@ var CacheInternal = class {
56128
56189
  }
56129
56190
  if (update === "prepend") {
56130
56191
  linkedIDs = newIDs.concat(oldIDs);
56192
+ if (layer?.optimistic) {
56193
+ action = () => {
56194
+ for (const id of newIDs) {
56195
+ if (id) {
56196
+ layer.insert(parent2, key, "start", id);
56197
+ }
56198
+ }
56199
+ };
56200
+ }
56131
56201
  } else if (update === "append") {
56132
56202
  linkedIDs = oldIDs.concat(newIDs);
56203
+ if (layer?.optimistic) {
56204
+ action = () => {
56205
+ for (const id of newIDs) {
56206
+ if (id) {
56207
+ layer.insert(parent2, key, "end", id);
56208
+ }
56209
+ }
56210
+ };
56211
+ }
56133
56212
  } else if (update === "replace") {
56134
56213
  linkedIDs = newIDs;
56135
56214
  }
@@ -56148,7 +56227,7 @@ var CacheInternal = class {
56148
56227
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56149
56228
  }
56150
56229
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56151
- layer.writeLink(parent2, key, linkedIDs);
56230
+ action();
56152
56231
  }
56153
56232
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56154
56233
  if (id == null) {
@@ -56203,6 +56282,9 @@ var CacheInternal = class {
56203
56282
  if (!targetID) {
56204
56283
  continue;
56205
56284
  }
56285
+ toNotify.push(
56286
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
56287
+ );
56206
56288
  this.cache.delete(targetID, layer);
56207
56289
  }
56208
56290
  }
@@ -56624,7 +56706,6 @@ function variableValue(value, args) {
56624
56706
  );
56625
56707
  }
56626
56708
  }
56627
- var rootID = "_ROOT_";
56628
56709
  function defaultComponentField({
56629
56710
  cache,
56630
56711
  component,
@@ -63939,6 +63939,35 @@ var GarbageCollector = class {
63939
63939
  }
63940
63940
  };
63941
63941
 
63942
+ // src/runtime/cache/stuff.ts
63943
+ function evaluateKey(key, variables = null) {
63944
+ let evaluated = "";
63945
+ let varName = "";
63946
+ let inString = false;
63947
+ for (const char of key) {
63948
+ if (varName) {
63949
+ if (varChars.includes(char)) {
63950
+ varName += char;
63951
+ continue;
63952
+ }
63953
+ const value = variables?.[varName.slice(1)];
63954
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
63955
+ varName = "";
63956
+ }
63957
+ if (char === "$" && !inString) {
63958
+ varName = "$";
63959
+ continue;
63960
+ }
63961
+ if (char === '"') {
63962
+ inString = !inString;
63963
+ }
63964
+ evaluated += char;
63965
+ }
63966
+ return evaluated;
63967
+ }
63968
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
63969
+ var rootID = "_ROOT_";
63970
+
63942
63971
  // src/runtime/cache/lists.ts
63943
63972
  var ListManager = class {
63944
63973
  rootID;
@@ -64005,11 +64034,15 @@ var ListManager = class {
64005
64034
  this.listsByField.get(parentID).get(list.key).push(handler);
64006
64035
  }
64007
64036
  removeIDFromAllLists(id, layer) {
64037
+ let removed = false;
64008
64038
  for (const fieldMap of this.lists.values()) {
64009
64039
  for (const list of fieldMap.values()) {
64010
- list.removeID(id, void 0, layer);
64040
+ if (list.removeID(id, void 0, layer)) {
64041
+ removed = true;
64042
+ }
64011
64043
  }
64012
64044
  }
64045
+ return removed;
64013
64046
  }
64014
64047
  deleteField(parentID, field) {
64015
64048
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -64312,7 +64345,13 @@ var ListCollection = class {
64312
64345
  this.lists.forEach((list) => list.addToList(...args));
64313
64346
  }
64314
64347
  removeID(...args) {
64315
- this.lists.forEach((list) => list.removeID(...args));
64348
+ let removed = false;
64349
+ this.lists.forEach((list) => {
64350
+ if (list.removeID(...args)) {
64351
+ removed = true;
64352
+ }
64353
+ });
64354
+ return removed;
64316
64355
  }
64317
64356
  remove(...args) {
64318
64357
  this.lists.forEach((list) => list.remove(...args));
@@ -64431,6 +64470,7 @@ var InMemoryStorage = class {
64431
64470
  }
64432
64471
  registerIDMapping(from, to) {
64433
64472
  this.idMaps[from] = to;
64473
+ this.idMaps[to] = from;
64434
64474
  }
64435
64475
  createLayer(optimistic = false) {
64436
64476
  const layer = new Layer(this.idCount++);
@@ -64441,11 +64481,11 @@ var InMemoryStorage = class {
64441
64481
  insert(id, field, location, target) {
64442
64482
  return this.topLayer.insert(id, field, location, target);
64443
64483
  }
64444
- remove(id, field, target, layerToUser = this.topLayer) {
64445
- return layerToUser.remove(id, field, target);
64484
+ remove(id, field, target, layer = this.topLayer) {
64485
+ return layer.remove(id, field, target);
64446
64486
  }
64447
- delete(id, layerToUser = this.topLayer) {
64448
- return layerToUser.delete(id);
64487
+ delete(id, layer = this.topLayer) {
64488
+ return layer.delete(id);
64449
64489
  }
64450
64490
  deleteField(id, field) {
64451
64491
  return this.topLayer.deleteField(id, field);
@@ -64483,6 +64523,9 @@ var InMemoryStorage = class {
64483
64523
  return;
64484
64524
  }
64485
64525
  operations.remove.add(v);
64526
+ if (this.idMaps[v]) {
64527
+ operations.remove.add(this.idMaps[v]);
64528
+ }
64486
64529
  });
64487
64530
  if (typeof layerValue === "undefined" && defaultValue) {
64488
64531
  const targetLayer = this.topLayer;
@@ -64509,7 +64552,11 @@ var InMemoryStorage = class {
64509
64552
  operations.remove.add(op.id);
64510
64553
  }
64511
64554
  if (isInsertOperation(op)) {
64512
- operations.insert[op.location].unshift(op.id);
64555
+ if (op.location === OperationLocation.end) {
64556
+ operations.insert[op.location].unshift(op.id);
64557
+ } else {
64558
+ operations.insert[op.location].push(op.id);
64559
+ }
64513
64560
  }
64514
64561
  if (isDeleteOperation(op)) {
64515
64562
  return {
@@ -64755,7 +64802,7 @@ var Layer = class {
64755
64802
  }
64756
64803
  for (const [id, ops] of Object.entries(layer.operations)) {
64757
64804
  const fields = {};
64758
- for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
64805
+ for (const opMap of [layer.operations[id], this.operations[id]].filter(Boolean)) {
64759
64806
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
64760
64807
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
64761
64808
  }
@@ -64820,34 +64867,6 @@ var OperationKind = {
64820
64867
  remove: "remove"
64821
64868
  };
64822
64869
 
64823
- // src/runtime/cache/stuff.ts
64824
- function evaluateKey(key, variables = null) {
64825
- let evaluated = "";
64826
- let varName = "";
64827
- let inString = false;
64828
- for (const char of key) {
64829
- if (varName) {
64830
- if (varChars.includes(char)) {
64831
- varName += char;
64832
- continue;
64833
- }
64834
- const value = variables?.[varName.slice(1)];
64835
- evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
64836
- varName = "";
64837
- }
64838
- if (char === "$" && !inString) {
64839
- varName = "$";
64840
- continue;
64841
- }
64842
- if (char === '"') {
64843
- inString = !inString;
64844
- }
64845
- evaluated += char;
64846
- }
64847
- return evaluated;
64848
- }
64849
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
64850
-
64851
64870
  // src/runtime/cache/subscription.ts
64852
64871
  var InMemorySubscriptions = class {
64853
64872
  cache;
@@ -64859,6 +64878,9 @@ var InMemorySubscriptions = class {
64859
64878
  activeFields(parent) {
64860
64879
  return Object.keys(this.subscribers.get(parent) || {});
64861
64880
  }
64881
+ copySubscribers(from, to) {
64882
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
64883
+ }
64862
64884
  add({
64863
64885
  parent,
64864
64886
  spec,
@@ -65041,6 +65063,11 @@ var InMemorySubscriptions = class {
65041
65063
  get(id, field) {
65042
65064
  return this.subscribers.get(id)?.get(field)?.selections || [];
65043
65065
  }
65066
+ getAll(id) {
65067
+ return [...this.subscribers.get(id)?.values() || []].flatMap(
65068
+ (fieldSub) => fieldSub.selections
65069
+ );
65070
+ }
65044
65071
  remove(id, selection, targets, variables, visited = []) {
65045
65072
  visited.push(id);
65046
65073
  const linkedIDs = [];
@@ -65082,7 +65109,7 @@ var InMemorySubscriptions = class {
65082
65109
  }
65083
65110
  const subscriberField = subscriber.get(fieldName);
65084
65111
  for (const spec of specs) {
65085
- const counts = subscriber.get(fieldName)?.referenceCounts;
65112
+ const counts = subscriberField?.referenceCounts;
65086
65113
  if (!counts?.has(spec.set)) {
65087
65114
  continue;
65088
65115
  }
@@ -65105,24 +65132,23 @@ var InMemorySubscriptions = class {
65105
65132
  this.subscribers.delete(id);
65106
65133
  }
65107
65134
  }
65108
- removeAllSubscribers(id, targets, visited = []) {
65109
- visited.push(id);
65110
- const subscriber = this.subscribers.get(id);
65111
- for (const [key, val] of subscriber?.entries() ?? []) {
65112
- const subscribers = targets || val.selections.map(([spec]) => spec);
65113
- this.removeSubscribers(id, key, subscribers);
65114
- const { value, kind } = this.cache._internal_unstable.storage.get(id, key);
65115
- if (kind === "scalar") {
65116
- continue;
65117
- }
65118
- const nextTargets = Array.isArray(value) ? flatten(value) : [value];
65119
- for (const id2 of nextTargets) {
65120
- if (visited.includes(id2)) {
65121
- continue;
65122
- }
65123
- this.removeAllSubscribers(id2, subscribers, visited);
65135
+ removeAllSubscribers(id, targets) {
65136
+ if (!targets) {
65137
+ targets = [...this.subscribers.get(id)?.values() || []].flatMap(
65138
+ (spec) => spec.selections.flatMap((sel) => sel[0])
65139
+ );
65140
+ }
65141
+ for (const target of targets) {
65142
+ for (const subselection of this.findSubSelections(
65143
+ target.parentID || rootID,
65144
+ target.selection,
65145
+ target.variables || {},
65146
+ id
65147
+ )) {
65148
+ this.remove(id, subselection, targets, target.variables || {});
65124
65149
  }
65125
65150
  }
65151
+ return;
65126
65152
  }
65127
65153
  get size() {
65128
65154
  let size = 0;
@@ -65133,6 +65159,32 @@ var InMemorySubscriptions = class {
65133
65159
  }
65134
65160
  return size;
65135
65161
  }
65162
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
65163
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
65164
+ let targetSelection = getFieldsForType(selection, __typename, false);
65165
+ for (const fieldSelection of Object.values(targetSelection || {})) {
65166
+ if (!fieldSelection.selection) {
65167
+ continue;
65168
+ }
65169
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
65170
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
65171
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
65172
+ if (links.includes(searchTarget)) {
65173
+ selections.push(fieldSelection.selection);
65174
+ } else {
65175
+ for (const link of links) {
65176
+ this.findSubSelections(
65177
+ link,
65178
+ fieldSelection.selection,
65179
+ variables,
65180
+ searchTarget,
65181
+ selections
65182
+ );
65183
+ }
65184
+ }
65185
+ }
65186
+ return selections;
65187
+ }
65136
65188
  };
65137
65189
 
65138
65190
  // src/runtime/cache/cache.ts
@@ -65210,11 +65262,17 @@ var Cache = class {
65210
65262
  }
65211
65263
  registerKeyMap(source, mapped) {
65212
65264
  this._internal_unstable.storage.registerIDMapping(source, mapped);
65265
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
65213
65266
  }
65214
65267
  delete(id, layer) {
65215
- this._internal_unstable.subscriptions.removeAllSubscribers(id);
65216
- this._internal_unstable.lists.removeIDFromAllLists(id, layer);
65217
- this._internal_unstable.storage.delete(id, layer);
65268
+ const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
65269
+ Boolean
65270
+ );
65271
+ for (const recordID of recordIDs) {
65272
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
65273
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
65274
+ this._internal_unstable.storage.delete(recordID, layer);
65275
+ }
65218
65276
  }
65219
65277
  setConfig(config) {
65220
65278
  this._internal_unstable.setConfig(config);
@@ -65520,6 +65578,9 @@ var CacheInternal = class {
65520
65578
  layer,
65521
65579
  forceNotify
65522
65580
  });
65581
+ let action = () => {
65582
+ layer.writeLink(parent, key, linkedIDs);
65583
+ };
65523
65584
  if (applyUpdates && updates) {
65524
65585
  if (key === "edges") {
65525
65586
  const newNodeIDs = [];
@@ -65554,8 +65615,26 @@ var CacheInternal = class {
65554
65615
  }
65555
65616
  if (update === "prepend") {
65556
65617
  linkedIDs = newIDs.concat(oldIDs);
65618
+ if (layer?.optimistic) {
65619
+ action = () => {
65620
+ for (const id of newIDs) {
65621
+ if (id) {
65622
+ layer.insert(parent, key, "start", id);
65623
+ }
65624
+ }
65625
+ };
65626
+ }
65557
65627
  } else if (update === "append") {
65558
65628
  linkedIDs = oldIDs.concat(newIDs);
65629
+ if (layer?.optimistic) {
65630
+ action = () => {
65631
+ for (const id of newIDs) {
65632
+ if (id) {
65633
+ layer.insert(parent, key, "end", id);
65634
+ }
65635
+ }
65636
+ };
65637
+ }
65559
65638
  } else if (update === "replace") {
65560
65639
  linkedIDs = newIDs;
65561
65640
  }
@@ -65574,7 +65653,7 @@ var CacheInternal = class {
65574
65653
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
65575
65654
  }
65576
65655
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
65577
- layer.writeLink(parent, key, linkedIDs);
65656
+ action();
65578
65657
  }
65579
65658
  for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
65580
65659
  if (id == null) {
@@ -65629,6 +65708,9 @@ var CacheInternal = class {
65629
65708
  if (!targetID) {
65630
65709
  continue;
65631
65710
  }
65711
+ toNotify.push(
65712
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
65713
+ );
65632
65714
  this.cache.delete(targetID, layer);
65633
65715
  }
65634
65716
  }
@@ -66050,7 +66132,6 @@ function variableValue(value, args) {
66050
66132
  );
66051
66133
  }
66052
66134
  }
66053
- var rootID = "_ROOT_";
66054
66135
  function defaultComponentField({
66055
66136
  cache,
66056
66137
  component,
@@ -66731,7 +66812,9 @@ var optimisticKeys = (cache, callbackCache = callbacks, keyCache = keys, objectI
66731
66812
  });
66732
66813
  delete callbackCache[optimisticValue];
66733
66814
  },
66734
- onIDChange: (optimisticValue, realValue) => cache.registerKeyMap(optimisticValue, realValue)
66815
+ onIDChange: (optimisticValue, realValue) => {
66816
+ cache.registerKeyMap(optimisticValue, realValue);
66817
+ }
66735
66818
  }
66736
66819
  );
66737
66820
  }