houdini-svelte 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.
@@ -75816,6 +75816,33 @@ var GarbageCollector = class {
75816
75816
  }
75817
75817
  }
75818
75818
  };
75819
+ function evaluateKey(key, variables = null) {
75820
+ let evaluated = "";
75821
+ let varName = "";
75822
+ let inString = false;
75823
+ for (const char of key) {
75824
+ if (varName) {
75825
+ if (varChars.includes(char)) {
75826
+ varName += char;
75827
+ continue;
75828
+ }
75829
+ const value2 = variables?.[varName.slice(1)];
75830
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
75831
+ varName = "";
75832
+ }
75833
+ if (char === "$" && !inString) {
75834
+ varName = "$";
75835
+ continue;
75836
+ }
75837
+ if (char === '"') {
75838
+ inString = !inString;
75839
+ }
75840
+ evaluated += char;
75841
+ }
75842
+ return evaluated;
75843
+ }
75844
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
75845
+ var rootID = "_ROOT_";
75819
75846
  var ListManager = class {
75820
75847
  rootID;
75821
75848
  cache;
@@ -75881,11 +75908,15 @@ var ListManager = class {
75881
75908
  this.listsByField.get(parentID).get(list.key).push(handler);
75882
75909
  }
75883
75910
  removeIDFromAllLists(id2, layer) {
75911
+ let removed = false;
75884
75912
  for (const fieldMap of this.lists.values()) {
75885
75913
  for (const list of fieldMap.values()) {
75886
- list.removeID(id2, void 0, layer);
75914
+ if (list.removeID(id2, void 0, layer)) {
75915
+ removed = true;
75916
+ }
75887
75917
  }
75888
75918
  }
75919
+ return removed;
75889
75920
  }
75890
75921
  deleteField(parentID, field) {
75891
75922
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -76188,7 +76219,13 @@ var ListCollection = class {
76188
76219
  this.lists.forEach((list) => list.addToList(...args));
76189
76220
  }
76190
76221
  removeID(...args) {
76191
- this.lists.forEach((list) => list.removeID(...args));
76222
+ let removed = false;
76223
+ this.lists.forEach((list) => {
76224
+ if (list.removeID(...args)) {
76225
+ removed = true;
76226
+ }
76227
+ });
76228
+ return removed;
76192
76229
  }
76193
76230
  remove(...args) {
76194
76231
  this.lists.forEach((list) => list.remove(...args));
@@ -76303,6 +76340,7 @@ var InMemoryStorage = class {
76303
76340
  }
76304
76341
  registerIDMapping(from, to) {
76305
76342
  this.idMaps[from] = to;
76343
+ this.idMaps[to] = from;
76306
76344
  }
76307
76345
  createLayer(optimistic = false) {
76308
76346
  const layer = new Layer(this.idCount++);
@@ -76313,11 +76351,11 @@ var InMemoryStorage = class {
76313
76351
  insert(id2, field, location, target) {
76314
76352
  return this.topLayer.insert(id2, field, location, target);
76315
76353
  }
76316
- remove(id2, field, target, layerToUser = this.topLayer) {
76317
- return layerToUser.remove(id2, field, target);
76354
+ remove(id2, field, target, layer = this.topLayer) {
76355
+ return layer.remove(id2, field, target);
76318
76356
  }
76319
- delete(id2, layerToUser = this.topLayer) {
76320
- return layerToUser.delete(id2);
76357
+ delete(id2, layer = this.topLayer) {
76358
+ return layer.delete(id2);
76321
76359
  }
76322
76360
  deleteField(id2, field) {
76323
76361
  return this.topLayer.deleteField(id2, field);
@@ -76355,6 +76393,9 @@ var InMemoryStorage = class {
76355
76393
  return;
76356
76394
  }
76357
76395
  operations.remove.add(v);
76396
+ if (this.idMaps[v]) {
76397
+ operations.remove.add(this.idMaps[v]);
76398
+ }
76358
76399
  });
76359
76400
  if (typeof layerValue === "undefined" && defaultValue) {
76360
76401
  const targetLayer = this.topLayer;
@@ -76381,7 +76422,11 @@ var InMemoryStorage = class {
76381
76422
  operations.remove.add(op.id);
76382
76423
  }
76383
76424
  if (isInsertOperation(op)) {
76384
- operations.insert[op.location].unshift(op.id);
76425
+ if (op.location === OperationLocation.end) {
76426
+ operations.insert[op.location].unshift(op.id);
76427
+ } else {
76428
+ operations.insert[op.location].push(op.id);
76429
+ }
76385
76430
  }
76386
76431
  if (isDeleteOperation(op)) {
76387
76432
  return {
@@ -76627,7 +76672,7 @@ var Layer = class {
76627
76672
  }
76628
76673
  for (const [id2, ops] of Object.entries(layer.operations)) {
76629
76674
  const fields = {};
76630
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
76675
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
76631
76676
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
76632
76677
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
76633
76678
  }
@@ -76691,32 +76736,6 @@ var OperationKind = {
76691
76736
  insert: "insert",
76692
76737
  remove: "remove"
76693
76738
  };
76694
- function evaluateKey(key, variables = null) {
76695
- let evaluated = "";
76696
- let varName = "";
76697
- let inString = false;
76698
- for (const char of key) {
76699
- if (varName) {
76700
- if (varChars.includes(char)) {
76701
- varName += char;
76702
- continue;
76703
- }
76704
- const value2 = variables?.[varName.slice(1)];
76705
- evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
76706
- varName = "";
76707
- }
76708
- if (char === "$" && !inString) {
76709
- varName = "$";
76710
- continue;
76711
- }
76712
- if (char === '"') {
76713
- inString = !inString;
76714
- }
76715
- evaluated += char;
76716
- }
76717
- return evaluated;
76718
- }
76719
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
76720
76739
  var InMemorySubscriptions = class {
76721
76740
  cache;
76722
76741
  constructor(cache) {
@@ -76727,6 +76746,9 @@ var InMemorySubscriptions = class {
76727
76746
  activeFields(parent2) {
76728
76747
  return Object.keys(this.subscribers.get(parent2) || {});
76729
76748
  }
76749
+ copySubscribers(from, to) {
76750
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
76751
+ }
76730
76752
  add({
76731
76753
  parent: parent2,
76732
76754
  spec,
@@ -76909,6 +76931,11 @@ var InMemorySubscriptions = class {
76909
76931
  get(id2, field) {
76910
76932
  return this.subscribers.get(id2)?.get(field)?.selections || [];
76911
76933
  }
76934
+ getAll(id2) {
76935
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
76936
+ (fieldSub) => fieldSub.selections
76937
+ );
76938
+ }
76912
76939
  remove(id2, selection, targets, variables, visited = []) {
76913
76940
  visited.push(id2);
76914
76941
  const linkedIDs = [];
@@ -76950,7 +76977,7 @@ var InMemorySubscriptions = class {
76950
76977
  }
76951
76978
  const subscriberField = subscriber.get(fieldName);
76952
76979
  for (const spec of specs) {
76953
- const counts = subscriber.get(fieldName)?.referenceCounts;
76980
+ const counts = subscriberField?.referenceCounts;
76954
76981
  if (!counts?.has(spec.set)) {
76955
76982
  continue;
76956
76983
  }
@@ -76973,24 +77000,23 @@ var InMemorySubscriptions = class {
76973
77000
  this.subscribers.delete(id2);
76974
77001
  }
76975
77002
  }
76976
- removeAllSubscribers(id2, targets, visited = []) {
76977
- visited.push(id2);
76978
- const subscriber = this.subscribers.get(id2);
76979
- for (const [key, val] of subscriber?.entries() ?? []) {
76980
- const subscribers = targets || val.selections.map(([spec]) => spec);
76981
- this.removeSubscribers(id2, key, subscribers);
76982
- const { value: value2, kind } = this.cache._internal_unstable.storage.get(id2, key);
76983
- if (kind === "scalar") {
76984
- continue;
76985
- }
76986
- const nextTargets = Array.isArray(value2) ? flatten(value2) : [value2];
76987
- for (const id22 of nextTargets) {
76988
- if (visited.includes(id22)) {
76989
- continue;
76990
- }
76991
- this.removeAllSubscribers(id22, subscribers, visited);
77003
+ removeAllSubscribers(id2, targets) {
77004
+ if (!targets) {
77005
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
77006
+ (spec) => spec.selections.flatMap((sel) => sel[0])
77007
+ );
77008
+ }
77009
+ for (const target of targets) {
77010
+ for (const subselection of this.findSubSelections(
77011
+ target.parentID || rootID,
77012
+ target.selection,
77013
+ target.variables || {},
77014
+ id2
77015
+ )) {
77016
+ this.remove(id2, subselection, targets, target.variables || {});
76992
77017
  }
76993
77018
  }
77019
+ return;
76994
77020
  }
76995
77021
  get size() {
76996
77022
  let size = 0;
@@ -77001,6 +77027,32 @@ var InMemorySubscriptions = class {
77001
77027
  }
77002
77028
  return size;
77003
77029
  }
77030
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
77031
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
77032
+ let targetSelection = getFieldsForType(selection, __typename, false);
77033
+ for (const fieldSelection of Object.values(targetSelection || {})) {
77034
+ if (!fieldSelection.selection) {
77035
+ continue;
77036
+ }
77037
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
77038
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
77039
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
77040
+ if (links.includes(searchTarget)) {
77041
+ selections.push(fieldSelection.selection);
77042
+ } else {
77043
+ for (const link of links) {
77044
+ this.findSubSelections(
77045
+ link,
77046
+ fieldSelection.selection,
77047
+ variables,
77048
+ searchTarget,
77049
+ selections
77050
+ );
77051
+ }
77052
+ }
77053
+ }
77054
+ return selections;
77055
+ }
77004
77056
  };
77005
77057
  var Cache = class {
77006
77058
  _internal_unstable;
@@ -77076,11 +77128,17 @@ var Cache = class {
77076
77128
  }
77077
77129
  registerKeyMap(source, mapped) {
77078
77130
  this._internal_unstable.storage.registerIDMapping(source, mapped);
77131
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
77079
77132
  }
77080
77133
  delete(id2, layer) {
77081
- this._internal_unstable.subscriptions.removeAllSubscribers(id2);
77082
- this._internal_unstable.lists.removeIDFromAllLists(id2, layer);
77083
- this._internal_unstable.storage.delete(id2, layer);
77134
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
77135
+ Boolean
77136
+ );
77137
+ for (const recordID of recordIDs) {
77138
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
77139
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
77140
+ this._internal_unstable.storage.delete(recordID, layer);
77141
+ }
77084
77142
  }
77085
77143
  setConfig(config2) {
77086
77144
  this._internal_unstable.setConfig(config2);
@@ -77386,6 +77444,9 @@ var CacheInternal = class {
77386
77444
  layer,
77387
77445
  forceNotify
77388
77446
  });
77447
+ let action = () => {
77448
+ layer.writeLink(parent2, key, linkedIDs);
77449
+ };
77389
77450
  if (applyUpdates && updates) {
77390
77451
  if (key === "edges") {
77391
77452
  const newNodeIDs = [];
@@ -77420,8 +77481,26 @@ var CacheInternal = class {
77420
77481
  }
77421
77482
  if (update === "prepend") {
77422
77483
  linkedIDs = newIDs.concat(oldIDs);
77484
+ if (layer?.optimistic) {
77485
+ action = () => {
77486
+ for (const id2 of newIDs) {
77487
+ if (id2) {
77488
+ layer.insert(parent2, key, "start", id2);
77489
+ }
77490
+ }
77491
+ };
77492
+ }
77423
77493
  } else if (update === "append") {
77424
77494
  linkedIDs = oldIDs.concat(newIDs);
77495
+ if (layer?.optimistic) {
77496
+ action = () => {
77497
+ for (const id2 of newIDs) {
77498
+ if (id2) {
77499
+ layer.insert(parent2, key, "end", id2);
77500
+ }
77501
+ }
77502
+ };
77503
+ }
77425
77504
  } else if (update === "replace") {
77426
77505
  linkedIDs = newIDs;
77427
77506
  }
@@ -77440,7 +77519,7 @@ var CacheInternal = class {
77440
77519
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
77441
77520
  }
77442
77521
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
77443
- layer.writeLink(parent2, key, linkedIDs);
77522
+ action();
77444
77523
  }
77445
77524
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
77446
77525
  if (id2 == null) {
@@ -77495,6 +77574,9 @@ var CacheInternal = class {
77495
77574
  if (!targetID) {
77496
77575
  continue;
77497
77576
  }
77577
+ toNotify.push(
77578
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
77579
+ );
77498
77580
  this.cache.delete(targetID, layer);
77499
77581
  }
77500
77582
  }
@@ -77916,7 +77998,6 @@ function variableValue(value2, args) {
77916
77998
  );
77917
77999
  }
77918
78000
  }
77919
- var rootID = "_ROOT_";
77920
78001
  function defaultComponentField({
77921
78002
  cache,
77922
78003
  component,
@@ -132548,6 +132629,33 @@ var GarbageCollector2 = class {
132548
132629
  }
132549
132630
  }
132550
132631
  };
132632
+ function evaluateKey2(key, variables = null) {
132633
+ let evaluated = "";
132634
+ let varName = "";
132635
+ let inString = false;
132636
+ for (const char of key) {
132637
+ if (varName) {
132638
+ if (varChars2.includes(char)) {
132639
+ varName += char;
132640
+ continue;
132641
+ }
132642
+ const value2 = variables?.[varName.slice(1)];
132643
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
132644
+ varName = "";
132645
+ }
132646
+ if (char === "$" && !inString) {
132647
+ varName = "$";
132648
+ continue;
132649
+ }
132650
+ if (char === '"') {
132651
+ inString = !inString;
132652
+ }
132653
+ evaluated += char;
132654
+ }
132655
+ return evaluated;
132656
+ }
132657
+ var varChars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
132658
+ var rootID2 = "_ROOT_";
132551
132659
  var ListManager2 = class {
132552
132660
  rootID;
132553
132661
  cache;
@@ -132613,11 +132721,15 @@ var ListManager2 = class {
132613
132721
  this.listsByField.get(parentID).get(list.key).push(handler);
132614
132722
  }
132615
132723
  removeIDFromAllLists(id2, layer) {
132724
+ let removed = false;
132616
132725
  for (const fieldMap of this.lists.values()) {
132617
132726
  for (const list of fieldMap.values()) {
132618
- list.removeID(id2, void 0, layer);
132727
+ if (list.removeID(id2, void 0, layer)) {
132728
+ removed = true;
132729
+ }
132619
132730
  }
132620
132731
  }
132732
+ return removed;
132621
132733
  }
132622
132734
  deleteField(parentID, field) {
132623
132735
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -132920,7 +133032,13 @@ var ListCollection2 = class {
132920
133032
  this.lists.forEach((list) => list.addToList(...args));
132921
133033
  }
132922
133034
  removeID(...args) {
132923
- this.lists.forEach((list) => list.removeID(...args));
133035
+ let removed = false;
133036
+ this.lists.forEach((list) => {
133037
+ if (list.removeID(...args)) {
133038
+ removed = true;
133039
+ }
133040
+ });
133041
+ return removed;
132924
133042
  }
132925
133043
  remove(...args) {
132926
133044
  this.lists.forEach((list) => list.remove(...args));
@@ -133035,6 +133153,7 @@ var InMemoryStorage2 = class {
133035
133153
  }
133036
133154
  registerIDMapping(from, to) {
133037
133155
  this.idMaps[from] = to;
133156
+ this.idMaps[to] = from;
133038
133157
  }
133039
133158
  createLayer(optimistic = false) {
133040
133159
  const layer = new Layer2(this.idCount++);
@@ -133045,11 +133164,11 @@ var InMemoryStorage2 = class {
133045
133164
  insert(id2, field, location, target) {
133046
133165
  return this.topLayer.insert(id2, field, location, target);
133047
133166
  }
133048
- remove(id2, field, target, layerToUser = this.topLayer) {
133049
- return layerToUser.remove(id2, field, target);
133167
+ remove(id2, field, target, layer = this.topLayer) {
133168
+ return layer.remove(id2, field, target);
133050
133169
  }
133051
- delete(id2, layerToUser = this.topLayer) {
133052
- return layerToUser.delete(id2);
133170
+ delete(id2, layer = this.topLayer) {
133171
+ return layer.delete(id2);
133053
133172
  }
133054
133173
  deleteField(id2, field) {
133055
133174
  return this.topLayer.deleteField(id2, field);
@@ -133087,6 +133206,9 @@ var InMemoryStorage2 = class {
133087
133206
  return;
133088
133207
  }
133089
133208
  operations.remove.add(v);
133209
+ if (this.idMaps[v]) {
133210
+ operations.remove.add(this.idMaps[v]);
133211
+ }
133090
133212
  });
133091
133213
  if (typeof layerValue === "undefined" && defaultValue) {
133092
133214
  const targetLayer = this.topLayer;
@@ -133113,7 +133235,11 @@ var InMemoryStorage2 = class {
133113
133235
  operations.remove.add(op.id);
133114
133236
  }
133115
133237
  if (isInsertOperation2(op)) {
133116
- operations.insert[op.location].unshift(op.id);
133238
+ if (op.location === OperationLocation2.end) {
133239
+ operations.insert[op.location].unshift(op.id);
133240
+ } else {
133241
+ operations.insert[op.location].push(op.id);
133242
+ }
133117
133243
  }
133118
133244
  if (isDeleteOperation2(op)) {
133119
133245
  return {
@@ -133359,7 +133485,7 @@ var Layer2 = class {
133359
133485
  }
133360
133486
  for (const [id2, ops] of Object.entries(layer.operations)) {
133361
133487
  const fields = {};
133362
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
133488
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
133363
133489
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
133364
133490
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
133365
133491
  }
@@ -133423,32 +133549,6 @@ var OperationKind2 = {
133423
133549
  insert: "insert",
133424
133550
  remove: "remove"
133425
133551
  };
133426
- function evaluateKey2(key, variables = null) {
133427
- let evaluated = "";
133428
- let varName = "";
133429
- let inString = false;
133430
- for (const char of key) {
133431
- if (varName) {
133432
- if (varChars2.includes(char)) {
133433
- varName += char;
133434
- continue;
133435
- }
133436
- const value2 = variables?.[varName.slice(1)];
133437
- evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
133438
- varName = "";
133439
- }
133440
- if (char === "$" && !inString) {
133441
- varName = "$";
133442
- continue;
133443
- }
133444
- if (char === '"') {
133445
- inString = !inString;
133446
- }
133447
- evaluated += char;
133448
- }
133449
- return evaluated;
133450
- }
133451
- var varChars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
133452
133552
  var InMemorySubscriptions2 = class {
133453
133553
  cache;
133454
133554
  constructor(cache) {
@@ -133459,6 +133559,9 @@ var InMemorySubscriptions2 = class {
133459
133559
  activeFields(parent2) {
133460
133560
  return Object.keys(this.subscribers.get(parent2) || {});
133461
133561
  }
133562
+ copySubscribers(from, to) {
133563
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
133564
+ }
133462
133565
  add({
133463
133566
  parent: parent2,
133464
133567
  spec,
@@ -133641,6 +133744,11 @@ var InMemorySubscriptions2 = class {
133641
133744
  get(id2, field) {
133642
133745
  return this.subscribers.get(id2)?.get(field)?.selections || [];
133643
133746
  }
133747
+ getAll(id2) {
133748
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
133749
+ (fieldSub) => fieldSub.selections
133750
+ );
133751
+ }
133644
133752
  remove(id2, selection, targets, variables, visited = []) {
133645
133753
  visited.push(id2);
133646
133754
  const linkedIDs = [];
@@ -133682,7 +133790,7 @@ var InMemorySubscriptions2 = class {
133682
133790
  }
133683
133791
  const subscriberField = subscriber.get(fieldName);
133684
133792
  for (const spec of specs) {
133685
- const counts = subscriber.get(fieldName)?.referenceCounts;
133793
+ const counts = subscriberField?.referenceCounts;
133686
133794
  if (!counts?.has(spec.set)) {
133687
133795
  continue;
133688
133796
  }
@@ -133705,24 +133813,23 @@ var InMemorySubscriptions2 = class {
133705
133813
  this.subscribers.delete(id2);
133706
133814
  }
133707
133815
  }
133708
- removeAllSubscribers(id2, targets, visited = []) {
133709
- visited.push(id2);
133710
- const subscriber = this.subscribers.get(id2);
133711
- for (const [key, val] of subscriber?.entries() ?? []) {
133712
- const subscribers = targets || val.selections.map(([spec]) => spec);
133713
- this.removeSubscribers(id2, key, subscribers);
133714
- const { value: value2, kind } = this.cache._internal_unstable.storage.get(id2, key);
133715
- if (kind === "scalar") {
133716
- continue;
133717
- }
133718
- const nextTargets = Array.isArray(value2) ? flatten2(value2) : [value2];
133719
- for (const id22 of nextTargets) {
133720
- if (visited.includes(id22)) {
133721
- continue;
133722
- }
133723
- this.removeAllSubscribers(id22, subscribers, visited);
133816
+ removeAllSubscribers(id2, targets) {
133817
+ if (!targets) {
133818
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
133819
+ (spec) => spec.selections.flatMap((sel) => sel[0])
133820
+ );
133821
+ }
133822
+ for (const target of targets) {
133823
+ for (const subselection of this.findSubSelections(
133824
+ target.parentID || rootID2,
133825
+ target.selection,
133826
+ target.variables || {},
133827
+ id2
133828
+ )) {
133829
+ this.remove(id2, subselection, targets, target.variables || {});
133724
133830
  }
133725
133831
  }
133832
+ return;
133726
133833
  }
133727
133834
  get size() {
133728
133835
  let size = 0;
@@ -133733,6 +133840,32 @@ var InMemorySubscriptions2 = class {
133733
133840
  }
133734
133841
  return size;
133735
133842
  }
133843
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
133844
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
133845
+ let targetSelection = getFieldsForType2(selection, __typename, false);
133846
+ for (const fieldSelection of Object.values(targetSelection || {})) {
133847
+ if (!fieldSelection.selection) {
133848
+ continue;
133849
+ }
133850
+ const key = evaluateKey2(fieldSelection.keyRaw, variables || {});
133851
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
133852
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten2(linkedRecord.value);
133853
+ if (links.includes(searchTarget)) {
133854
+ selections.push(fieldSelection.selection);
133855
+ } else {
133856
+ for (const link of links) {
133857
+ this.findSubSelections(
133858
+ link,
133859
+ fieldSelection.selection,
133860
+ variables,
133861
+ searchTarget,
133862
+ selections
133863
+ );
133864
+ }
133865
+ }
133866
+ }
133867
+ return selections;
133868
+ }
133736
133869
  };
133737
133870
  var Cache2 = class {
133738
133871
  _internal_unstable;
@@ -133808,11 +133941,17 @@ var Cache2 = class {
133808
133941
  }
133809
133942
  registerKeyMap(source, mapped) {
133810
133943
  this._internal_unstable.storage.registerIDMapping(source, mapped);
133944
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
133811
133945
  }
133812
133946
  delete(id2, layer) {
133813
- this._internal_unstable.subscriptions.removeAllSubscribers(id2);
133814
- this._internal_unstable.lists.removeIDFromAllLists(id2, layer);
133815
- this._internal_unstable.storage.delete(id2, layer);
133947
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
133948
+ Boolean
133949
+ );
133950
+ for (const recordID of recordIDs) {
133951
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
133952
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
133953
+ this._internal_unstable.storage.delete(recordID, layer);
133954
+ }
133816
133955
  }
133817
133956
  setConfig(config2) {
133818
133957
  this._internal_unstable.setConfig(config2);
@@ -134118,6 +134257,9 @@ var CacheInternal2 = class {
134118
134257
  layer,
134119
134258
  forceNotify
134120
134259
  });
134260
+ let action = () => {
134261
+ layer.writeLink(parent2, key, linkedIDs);
134262
+ };
134121
134263
  if (applyUpdates && updates) {
134122
134264
  if (key === "edges") {
134123
134265
  const newNodeIDs = [];
@@ -134152,8 +134294,26 @@ var CacheInternal2 = class {
134152
134294
  }
134153
134295
  if (update === "prepend") {
134154
134296
  linkedIDs = newIDs.concat(oldIDs);
134297
+ if (layer?.optimistic) {
134298
+ action = () => {
134299
+ for (const id2 of newIDs) {
134300
+ if (id2) {
134301
+ layer.insert(parent2, key, "start", id2);
134302
+ }
134303
+ }
134304
+ };
134305
+ }
134155
134306
  } else if (update === "append") {
134156
134307
  linkedIDs = oldIDs.concat(newIDs);
134308
+ if (layer?.optimistic) {
134309
+ action = () => {
134310
+ for (const id2 of newIDs) {
134311
+ if (id2) {
134312
+ layer.insert(parent2, key, "end", id2);
134313
+ }
134314
+ }
134315
+ };
134316
+ }
134157
134317
  } else if (update === "replace") {
134158
134318
  linkedIDs = newIDs;
134159
134319
  }
@@ -134172,7 +134332,7 @@ var CacheInternal2 = class {
134172
134332
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
134173
134333
  }
134174
134334
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
134175
- layer.writeLink(parent2, key, linkedIDs);
134335
+ action();
134176
134336
  }
134177
134337
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
134178
134338
  if (id2 == null) {
@@ -134227,6 +134387,9 @@ var CacheInternal2 = class {
134227
134387
  if (!targetID) {
134228
134388
  continue;
134229
134389
  }
134390
+ toNotify.push(
134391
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
134392
+ );
134230
134393
  this.cache.delete(targetID, layer);
134231
134394
  }
134232
134395
  }
@@ -134648,7 +134811,6 @@ function variableValue2(value2, args) {
134648
134811
  );
134649
134812
  }
134650
134813
  }
134651
- var rootID2 = "_ROOT_";
134652
134814
  function defaultComponentField2({
134653
134815
  cache,
134654
134816
  component,
@@ -196900,6 +197062,33 @@ var GarbageCollector3 = class {
196900
197062
  }
196901
197063
  }
196902
197064
  };
197065
+ function evaluateKey3(key, variables = null) {
197066
+ let evaluated = "";
197067
+ let varName = "";
197068
+ let inString = false;
197069
+ for (const char of key) {
197070
+ if (varName) {
197071
+ if (varChars3.includes(char)) {
197072
+ varName += char;
197073
+ continue;
197074
+ }
197075
+ const value2 = variables?.[varName.slice(1)];
197076
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
197077
+ varName = "";
197078
+ }
197079
+ if (char === "$" && !inString) {
197080
+ varName = "$";
197081
+ continue;
197082
+ }
197083
+ if (char === '"') {
197084
+ inString = !inString;
197085
+ }
197086
+ evaluated += char;
197087
+ }
197088
+ return evaluated;
197089
+ }
197090
+ var varChars3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
197091
+ var rootID3 = "_ROOT_";
196903
197092
  var ListManager3 = class {
196904
197093
  rootID;
196905
197094
  cache;
@@ -196965,11 +197154,15 @@ var ListManager3 = class {
196965
197154
  this.listsByField.get(parentID).get(list.key).push(handler);
196966
197155
  }
196967
197156
  removeIDFromAllLists(id2, layer) {
197157
+ let removed = false;
196968
197158
  for (const fieldMap of this.lists.values()) {
196969
197159
  for (const list of fieldMap.values()) {
196970
- list.removeID(id2, void 0, layer);
197160
+ if (list.removeID(id2, void 0, layer)) {
197161
+ removed = true;
197162
+ }
196971
197163
  }
196972
197164
  }
197165
+ return removed;
196973
197166
  }
196974
197167
  deleteField(parentID, field) {
196975
197168
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -197272,7 +197465,13 @@ var ListCollection3 = class {
197272
197465
  this.lists.forEach((list) => list.addToList(...args));
197273
197466
  }
197274
197467
  removeID(...args) {
197275
- this.lists.forEach((list) => list.removeID(...args));
197468
+ let removed = false;
197469
+ this.lists.forEach((list) => {
197470
+ if (list.removeID(...args)) {
197471
+ removed = true;
197472
+ }
197473
+ });
197474
+ return removed;
197276
197475
  }
197277
197476
  remove(...args) {
197278
197477
  this.lists.forEach((list) => list.remove(...args));
@@ -197387,6 +197586,7 @@ var InMemoryStorage3 = class {
197387
197586
  }
197388
197587
  registerIDMapping(from, to) {
197389
197588
  this.idMaps[from] = to;
197589
+ this.idMaps[to] = from;
197390
197590
  }
197391
197591
  createLayer(optimistic = false) {
197392
197592
  const layer = new Layer3(this.idCount++);
@@ -197397,11 +197597,11 @@ var InMemoryStorage3 = class {
197397
197597
  insert(id2, field, location, target) {
197398
197598
  return this.topLayer.insert(id2, field, location, target);
197399
197599
  }
197400
- remove(id2, field, target, layerToUser = this.topLayer) {
197401
- return layerToUser.remove(id2, field, target);
197600
+ remove(id2, field, target, layer = this.topLayer) {
197601
+ return layer.remove(id2, field, target);
197402
197602
  }
197403
- delete(id2, layerToUser = this.topLayer) {
197404
- return layerToUser.delete(id2);
197603
+ delete(id2, layer = this.topLayer) {
197604
+ return layer.delete(id2);
197405
197605
  }
197406
197606
  deleteField(id2, field) {
197407
197607
  return this.topLayer.deleteField(id2, field);
@@ -197439,6 +197639,9 @@ var InMemoryStorage3 = class {
197439
197639
  return;
197440
197640
  }
197441
197641
  operations.remove.add(v);
197642
+ if (this.idMaps[v]) {
197643
+ operations.remove.add(this.idMaps[v]);
197644
+ }
197442
197645
  });
197443
197646
  if (typeof layerValue === "undefined" && defaultValue) {
197444
197647
  const targetLayer = this.topLayer;
@@ -197465,7 +197668,11 @@ var InMemoryStorage3 = class {
197465
197668
  operations.remove.add(op.id);
197466
197669
  }
197467
197670
  if (isInsertOperation3(op)) {
197468
- operations.insert[op.location].unshift(op.id);
197671
+ if (op.location === OperationLocation3.end) {
197672
+ operations.insert[op.location].unshift(op.id);
197673
+ } else {
197674
+ operations.insert[op.location].push(op.id);
197675
+ }
197469
197676
  }
197470
197677
  if (isDeleteOperation3(op)) {
197471
197678
  return {
@@ -197711,7 +197918,7 @@ var Layer3 = class {
197711
197918
  }
197712
197919
  for (const [id2, ops] of Object.entries(layer.operations)) {
197713
197920
  const fields = {};
197714
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
197921
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
197715
197922
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
197716
197923
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
197717
197924
  }
@@ -197775,32 +197982,6 @@ var OperationKind3 = {
197775
197982
  insert: "insert",
197776
197983
  remove: "remove"
197777
197984
  };
197778
- function evaluateKey3(key, variables = null) {
197779
- let evaluated = "";
197780
- let varName = "";
197781
- let inString = false;
197782
- for (const char of key) {
197783
- if (varName) {
197784
- if (varChars3.includes(char)) {
197785
- varName += char;
197786
- continue;
197787
- }
197788
- const value2 = variables?.[varName.slice(1)];
197789
- evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
197790
- varName = "";
197791
- }
197792
- if (char === "$" && !inString) {
197793
- varName = "$";
197794
- continue;
197795
- }
197796
- if (char === '"') {
197797
- inString = !inString;
197798
- }
197799
- evaluated += char;
197800
- }
197801
- return evaluated;
197802
- }
197803
- var varChars3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
197804
197985
  var InMemorySubscriptions3 = class {
197805
197986
  cache;
197806
197987
  constructor(cache) {
@@ -197811,6 +197992,9 @@ var InMemorySubscriptions3 = class {
197811
197992
  activeFields(parent2) {
197812
197993
  return Object.keys(this.subscribers.get(parent2) || {});
197813
197994
  }
197995
+ copySubscribers(from, to) {
197996
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
197997
+ }
197814
197998
  add({
197815
197999
  parent: parent2,
197816
198000
  spec,
@@ -197993,6 +198177,11 @@ var InMemorySubscriptions3 = class {
197993
198177
  get(id2, field) {
197994
198178
  return this.subscribers.get(id2)?.get(field)?.selections || [];
197995
198179
  }
198180
+ getAll(id2) {
198181
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
198182
+ (fieldSub) => fieldSub.selections
198183
+ );
198184
+ }
197996
198185
  remove(id2, selection, targets, variables, visited = []) {
197997
198186
  visited.push(id2);
197998
198187
  const linkedIDs = [];
@@ -198034,7 +198223,7 @@ var InMemorySubscriptions3 = class {
198034
198223
  }
198035
198224
  const subscriberField = subscriber.get(fieldName);
198036
198225
  for (const spec of specs) {
198037
- const counts = subscriber.get(fieldName)?.referenceCounts;
198226
+ const counts = subscriberField?.referenceCounts;
198038
198227
  if (!counts?.has(spec.set)) {
198039
198228
  continue;
198040
198229
  }
@@ -198057,24 +198246,23 @@ var InMemorySubscriptions3 = class {
198057
198246
  this.subscribers.delete(id2);
198058
198247
  }
198059
198248
  }
198060
- removeAllSubscribers(id2, targets, visited = []) {
198061
- visited.push(id2);
198062
- const subscriber = this.subscribers.get(id2);
198063
- for (const [key, val] of subscriber?.entries() ?? []) {
198064
- const subscribers = targets || val.selections.map(([spec]) => spec);
198065
- this.removeSubscribers(id2, key, subscribers);
198066
- const { value: value2, kind } = this.cache._internal_unstable.storage.get(id2, key);
198067
- if (kind === "scalar") {
198068
- continue;
198069
- }
198070
- const nextTargets = Array.isArray(value2) ? flatten3(value2) : [value2];
198071
- for (const id22 of nextTargets) {
198072
- if (visited.includes(id22)) {
198073
- continue;
198074
- }
198075
- this.removeAllSubscribers(id22, subscribers, visited);
198249
+ removeAllSubscribers(id2, targets) {
198250
+ if (!targets) {
198251
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
198252
+ (spec) => spec.selections.flatMap((sel) => sel[0])
198253
+ );
198254
+ }
198255
+ for (const target of targets) {
198256
+ for (const subselection of this.findSubSelections(
198257
+ target.parentID || rootID3,
198258
+ target.selection,
198259
+ target.variables || {},
198260
+ id2
198261
+ )) {
198262
+ this.remove(id2, subselection, targets, target.variables || {});
198076
198263
  }
198077
198264
  }
198265
+ return;
198078
198266
  }
198079
198267
  get size() {
198080
198268
  let size = 0;
@@ -198085,6 +198273,32 @@ var InMemorySubscriptions3 = class {
198085
198273
  }
198086
198274
  return size;
198087
198275
  }
198276
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
198277
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
198278
+ let targetSelection = getFieldsForType3(selection, __typename, false);
198279
+ for (const fieldSelection of Object.values(targetSelection || {})) {
198280
+ if (!fieldSelection.selection) {
198281
+ continue;
198282
+ }
198283
+ const key = evaluateKey3(fieldSelection.keyRaw, variables || {});
198284
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
198285
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten3(linkedRecord.value);
198286
+ if (links.includes(searchTarget)) {
198287
+ selections.push(fieldSelection.selection);
198288
+ } else {
198289
+ for (const link of links) {
198290
+ this.findSubSelections(
198291
+ link,
198292
+ fieldSelection.selection,
198293
+ variables,
198294
+ searchTarget,
198295
+ selections
198296
+ );
198297
+ }
198298
+ }
198299
+ }
198300
+ return selections;
198301
+ }
198088
198302
  };
198089
198303
  var Cache3 = class {
198090
198304
  _internal_unstable;
@@ -198160,11 +198374,17 @@ var Cache3 = class {
198160
198374
  }
198161
198375
  registerKeyMap(source, mapped) {
198162
198376
  this._internal_unstable.storage.registerIDMapping(source, mapped);
198377
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
198163
198378
  }
198164
198379
  delete(id2, layer) {
198165
- this._internal_unstable.subscriptions.removeAllSubscribers(id2);
198166
- this._internal_unstable.lists.removeIDFromAllLists(id2, layer);
198167
- this._internal_unstable.storage.delete(id2, layer);
198380
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
198381
+ Boolean
198382
+ );
198383
+ for (const recordID of recordIDs) {
198384
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
198385
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
198386
+ this._internal_unstable.storage.delete(recordID, layer);
198387
+ }
198168
198388
  }
198169
198389
  setConfig(config2) {
198170
198390
  this._internal_unstable.setConfig(config2);
@@ -198470,6 +198690,9 @@ var CacheInternal3 = class {
198470
198690
  layer,
198471
198691
  forceNotify
198472
198692
  });
198693
+ let action = () => {
198694
+ layer.writeLink(parent2, key, linkedIDs);
198695
+ };
198473
198696
  if (applyUpdates && updates) {
198474
198697
  if (key === "edges") {
198475
198698
  const newNodeIDs = [];
@@ -198504,8 +198727,26 @@ var CacheInternal3 = class {
198504
198727
  }
198505
198728
  if (update === "prepend") {
198506
198729
  linkedIDs = newIDs.concat(oldIDs);
198730
+ if (layer?.optimistic) {
198731
+ action = () => {
198732
+ for (const id2 of newIDs) {
198733
+ if (id2) {
198734
+ layer.insert(parent2, key, "start", id2);
198735
+ }
198736
+ }
198737
+ };
198738
+ }
198507
198739
  } else if (update === "append") {
198508
198740
  linkedIDs = oldIDs.concat(newIDs);
198741
+ if (layer?.optimistic) {
198742
+ action = () => {
198743
+ for (const id2 of newIDs) {
198744
+ if (id2) {
198745
+ layer.insert(parent2, key, "end", id2);
198746
+ }
198747
+ }
198748
+ };
198749
+ }
198509
198750
  } else if (update === "replace") {
198510
198751
  linkedIDs = newIDs;
198511
198752
  }
@@ -198524,7 +198765,7 @@ var CacheInternal3 = class {
198524
198765
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
198525
198766
  }
198526
198767
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
198527
- layer.writeLink(parent2, key, linkedIDs);
198768
+ action();
198528
198769
  }
198529
198770
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
198530
198771
  if (id2 == null) {
@@ -198579,6 +198820,9 @@ var CacheInternal3 = class {
198579
198820
  if (!targetID) {
198580
198821
  continue;
198581
198822
  }
198823
+ toNotify.push(
198824
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
198825
+ );
198582
198826
  this.cache.delete(targetID, layer);
198583
198827
  }
198584
198828
  }
@@ -199000,7 +199244,6 @@ function variableValue3(value2, args) {
199000
199244
  );
199001
199245
  }
199002
199246
  }
199003
- var rootID3 = "_ROOT_";
199004
199247
  function defaultComponentField3({
199005
199248
  cache,
199006
199249
  component,
@@ -262768,6 +263011,33 @@ var GarbageCollector4 = class {
262768
263011
  }
262769
263012
  }
262770
263013
  };
263014
+ function evaluateKey4(key, variables = null) {
263015
+ let evaluated = "";
263016
+ let varName = "";
263017
+ let inString = false;
263018
+ for (const char of key) {
263019
+ if (varName) {
263020
+ if (varChars4.includes(char)) {
263021
+ varName += char;
263022
+ continue;
263023
+ }
263024
+ const value2 = variables?.[varName.slice(1)];
263025
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
263026
+ varName = "";
263027
+ }
263028
+ if (char === "$" && !inString) {
263029
+ varName = "$";
263030
+ continue;
263031
+ }
263032
+ if (char === '"') {
263033
+ inString = !inString;
263034
+ }
263035
+ evaluated += char;
263036
+ }
263037
+ return evaluated;
263038
+ }
263039
+ var varChars4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
263040
+ var rootID4 = "_ROOT_";
262771
263041
  var ListManager4 = class {
262772
263042
  rootID;
262773
263043
  cache;
@@ -262833,11 +263103,15 @@ var ListManager4 = class {
262833
263103
  this.listsByField.get(parentID).get(list.key).push(handler);
262834
263104
  }
262835
263105
  removeIDFromAllLists(id2, layer) {
263106
+ let removed = false;
262836
263107
  for (const fieldMap of this.lists.values()) {
262837
263108
  for (const list of fieldMap.values()) {
262838
- list.removeID(id2, void 0, layer);
263109
+ if (list.removeID(id2, void 0, layer)) {
263110
+ removed = true;
263111
+ }
262839
263112
  }
262840
263113
  }
263114
+ return removed;
262841
263115
  }
262842
263116
  deleteField(parentID, field) {
262843
263117
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -263140,7 +263414,13 @@ var ListCollection4 = class {
263140
263414
  this.lists.forEach((list) => list.addToList(...args));
263141
263415
  }
263142
263416
  removeID(...args) {
263143
- this.lists.forEach((list) => list.removeID(...args));
263417
+ let removed = false;
263418
+ this.lists.forEach((list) => {
263419
+ if (list.removeID(...args)) {
263420
+ removed = true;
263421
+ }
263422
+ });
263423
+ return removed;
263144
263424
  }
263145
263425
  remove(...args) {
263146
263426
  this.lists.forEach((list) => list.remove(...args));
@@ -263255,6 +263535,7 @@ var InMemoryStorage4 = class {
263255
263535
  }
263256
263536
  registerIDMapping(from, to) {
263257
263537
  this.idMaps[from] = to;
263538
+ this.idMaps[to] = from;
263258
263539
  }
263259
263540
  createLayer(optimistic = false) {
263260
263541
  const layer = new Layer4(this.idCount++);
@@ -263265,11 +263546,11 @@ var InMemoryStorage4 = class {
263265
263546
  insert(id2, field, location, target) {
263266
263547
  return this.topLayer.insert(id2, field, location, target);
263267
263548
  }
263268
- remove(id2, field, target, layerToUser = this.topLayer) {
263269
- return layerToUser.remove(id2, field, target);
263549
+ remove(id2, field, target, layer = this.topLayer) {
263550
+ return layer.remove(id2, field, target);
263270
263551
  }
263271
- delete(id2, layerToUser = this.topLayer) {
263272
- return layerToUser.delete(id2);
263552
+ delete(id2, layer = this.topLayer) {
263553
+ return layer.delete(id2);
263273
263554
  }
263274
263555
  deleteField(id2, field) {
263275
263556
  return this.topLayer.deleteField(id2, field);
@@ -263307,6 +263588,9 @@ var InMemoryStorage4 = class {
263307
263588
  return;
263308
263589
  }
263309
263590
  operations.remove.add(v);
263591
+ if (this.idMaps[v]) {
263592
+ operations.remove.add(this.idMaps[v]);
263593
+ }
263310
263594
  });
263311
263595
  if (typeof layerValue === "undefined" && defaultValue) {
263312
263596
  const targetLayer = this.topLayer;
@@ -263333,7 +263617,11 @@ var InMemoryStorage4 = class {
263333
263617
  operations.remove.add(op.id);
263334
263618
  }
263335
263619
  if (isInsertOperation4(op)) {
263336
- operations.insert[op.location].unshift(op.id);
263620
+ if (op.location === OperationLocation4.end) {
263621
+ operations.insert[op.location].unshift(op.id);
263622
+ } else {
263623
+ operations.insert[op.location].push(op.id);
263624
+ }
263337
263625
  }
263338
263626
  if (isDeleteOperation4(op)) {
263339
263627
  return {
@@ -263579,7 +263867,7 @@ var Layer4 = class {
263579
263867
  }
263580
263868
  for (const [id2, ops] of Object.entries(layer.operations)) {
263581
263869
  const fields = {};
263582
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
263870
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
263583
263871
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
263584
263872
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
263585
263873
  }
@@ -263643,32 +263931,6 @@ var OperationKind4 = {
263643
263931
  insert: "insert",
263644
263932
  remove: "remove"
263645
263933
  };
263646
- function evaluateKey4(key, variables = null) {
263647
- let evaluated = "";
263648
- let varName = "";
263649
- let inString = false;
263650
- for (const char of key) {
263651
- if (varName) {
263652
- if (varChars4.includes(char)) {
263653
- varName += char;
263654
- continue;
263655
- }
263656
- const value2 = variables?.[varName.slice(1)];
263657
- evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
263658
- varName = "";
263659
- }
263660
- if (char === "$" && !inString) {
263661
- varName = "$";
263662
- continue;
263663
- }
263664
- if (char === '"') {
263665
- inString = !inString;
263666
- }
263667
- evaluated += char;
263668
- }
263669
- return evaluated;
263670
- }
263671
- var varChars4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
263672
263934
  var InMemorySubscriptions4 = class {
263673
263935
  cache;
263674
263936
  constructor(cache) {
@@ -263679,6 +263941,9 @@ var InMemorySubscriptions4 = class {
263679
263941
  activeFields(parent2) {
263680
263942
  return Object.keys(this.subscribers.get(parent2) || {});
263681
263943
  }
263944
+ copySubscribers(from, to) {
263945
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
263946
+ }
263682
263947
  add({
263683
263948
  parent: parent2,
263684
263949
  spec,
@@ -263861,6 +264126,11 @@ var InMemorySubscriptions4 = class {
263861
264126
  get(id2, field) {
263862
264127
  return this.subscribers.get(id2)?.get(field)?.selections || [];
263863
264128
  }
264129
+ getAll(id2) {
264130
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
264131
+ (fieldSub) => fieldSub.selections
264132
+ );
264133
+ }
263864
264134
  remove(id2, selection, targets, variables, visited = []) {
263865
264135
  visited.push(id2);
263866
264136
  const linkedIDs = [];
@@ -263902,7 +264172,7 @@ var InMemorySubscriptions4 = class {
263902
264172
  }
263903
264173
  const subscriberField = subscriber.get(fieldName);
263904
264174
  for (const spec of specs) {
263905
- const counts = subscriber.get(fieldName)?.referenceCounts;
264175
+ const counts = subscriberField?.referenceCounts;
263906
264176
  if (!counts?.has(spec.set)) {
263907
264177
  continue;
263908
264178
  }
@@ -263925,24 +264195,23 @@ var InMemorySubscriptions4 = class {
263925
264195
  this.subscribers.delete(id2);
263926
264196
  }
263927
264197
  }
263928
- removeAllSubscribers(id2, targets, visited = []) {
263929
- visited.push(id2);
263930
- const subscriber = this.subscribers.get(id2);
263931
- for (const [key, val] of subscriber?.entries() ?? []) {
263932
- const subscribers = targets || val.selections.map(([spec]) => spec);
263933
- this.removeSubscribers(id2, key, subscribers);
263934
- const { value: value2, kind } = this.cache._internal_unstable.storage.get(id2, key);
263935
- if (kind === "scalar") {
263936
- continue;
263937
- }
263938
- const nextTargets = Array.isArray(value2) ? flatten4(value2) : [value2];
263939
- for (const id22 of nextTargets) {
263940
- if (visited.includes(id22)) {
263941
- continue;
263942
- }
263943
- this.removeAllSubscribers(id22, subscribers, visited);
264198
+ removeAllSubscribers(id2, targets) {
264199
+ if (!targets) {
264200
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
264201
+ (spec) => spec.selections.flatMap((sel) => sel[0])
264202
+ );
264203
+ }
264204
+ for (const target of targets) {
264205
+ for (const subselection of this.findSubSelections(
264206
+ target.parentID || rootID4,
264207
+ target.selection,
264208
+ target.variables || {},
264209
+ id2
264210
+ )) {
264211
+ this.remove(id2, subselection, targets, target.variables || {});
263944
264212
  }
263945
264213
  }
264214
+ return;
263946
264215
  }
263947
264216
  get size() {
263948
264217
  let size = 0;
@@ -263953,6 +264222,32 @@ var InMemorySubscriptions4 = class {
263953
264222
  }
263954
264223
  return size;
263955
264224
  }
264225
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
264226
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
264227
+ let targetSelection = getFieldsForType4(selection, __typename, false);
264228
+ for (const fieldSelection of Object.values(targetSelection || {})) {
264229
+ if (!fieldSelection.selection) {
264230
+ continue;
264231
+ }
264232
+ const key = evaluateKey4(fieldSelection.keyRaw, variables || {});
264233
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
264234
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten4(linkedRecord.value);
264235
+ if (links.includes(searchTarget)) {
264236
+ selections.push(fieldSelection.selection);
264237
+ } else {
264238
+ for (const link of links) {
264239
+ this.findSubSelections(
264240
+ link,
264241
+ fieldSelection.selection,
264242
+ variables,
264243
+ searchTarget,
264244
+ selections
264245
+ );
264246
+ }
264247
+ }
264248
+ }
264249
+ return selections;
264250
+ }
263956
264251
  };
263957
264252
  var Cache4 = class {
263958
264253
  _internal_unstable;
@@ -264028,11 +264323,17 @@ var Cache4 = class {
264028
264323
  }
264029
264324
  registerKeyMap(source, mapped) {
264030
264325
  this._internal_unstable.storage.registerIDMapping(source, mapped);
264326
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
264031
264327
  }
264032
264328
  delete(id2, layer) {
264033
- this._internal_unstable.subscriptions.removeAllSubscribers(id2);
264034
- this._internal_unstable.lists.removeIDFromAllLists(id2, layer);
264035
- this._internal_unstable.storage.delete(id2, layer);
264329
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
264330
+ Boolean
264331
+ );
264332
+ for (const recordID of recordIDs) {
264333
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
264334
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
264335
+ this._internal_unstable.storage.delete(recordID, layer);
264336
+ }
264036
264337
  }
264037
264338
  setConfig(config2) {
264038
264339
  this._internal_unstable.setConfig(config2);
@@ -264338,6 +264639,9 @@ var CacheInternal4 = class {
264338
264639
  layer,
264339
264640
  forceNotify
264340
264641
  });
264642
+ let action = () => {
264643
+ layer.writeLink(parent2, key, linkedIDs);
264644
+ };
264341
264645
  if (applyUpdates && updates) {
264342
264646
  if (key === "edges") {
264343
264647
  const newNodeIDs = [];
@@ -264372,8 +264676,26 @@ var CacheInternal4 = class {
264372
264676
  }
264373
264677
  if (update === "prepend") {
264374
264678
  linkedIDs = newIDs.concat(oldIDs);
264679
+ if (layer?.optimistic) {
264680
+ action = () => {
264681
+ for (const id2 of newIDs) {
264682
+ if (id2) {
264683
+ layer.insert(parent2, key, "start", id2);
264684
+ }
264685
+ }
264686
+ };
264687
+ }
264375
264688
  } else if (update === "append") {
264376
264689
  linkedIDs = oldIDs.concat(newIDs);
264690
+ if (layer?.optimistic) {
264691
+ action = () => {
264692
+ for (const id2 of newIDs) {
264693
+ if (id2) {
264694
+ layer.insert(parent2, key, "end", id2);
264695
+ }
264696
+ }
264697
+ };
264698
+ }
264377
264699
  } else if (update === "replace") {
264378
264700
  linkedIDs = newIDs;
264379
264701
  }
@@ -264392,7 +264714,7 @@ var CacheInternal4 = class {
264392
264714
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
264393
264715
  }
264394
264716
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
264395
- layer.writeLink(parent2, key, linkedIDs);
264717
+ action();
264396
264718
  }
264397
264719
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
264398
264720
  if (id2 == null) {
@@ -264447,6 +264769,9 @@ var CacheInternal4 = class {
264447
264769
  if (!targetID) {
264448
264770
  continue;
264449
264771
  }
264772
+ toNotify.push(
264773
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
264774
+ );
264450
264775
  this.cache.delete(targetID, layer);
264451
264776
  }
264452
264777
  }
@@ -264868,7 +265193,6 @@ function variableValue4(value2, args) {
264868
265193
  );
264869
265194
  }
264870
265195
  }
264871
- var rootID4 = "_ROOT_";
264872
265196
  function defaultComponentField4({
264873
265197
  cache,
264874
265198
  component,
@@ -294488,7 +294812,7 @@ async function codegen_default(input) {
294488
294812
  // src/plugin/fsPatch.ts
294489
294813
  var import_node_fs3 = __toESM(require("node:fs"), 1);
294490
294814
  var import_promises5 = __toESM(require("node:fs/promises"), 1);
294491
- var fsPatch_default = (getFramwork) => ({
294815
+ var fsPatch_default = (getFramework) => ({
294492
294816
  async resolveId(filepath, _, { config: config2, isEntry }) {
294493
294817
  if (!isEntry) {
294494
294818
  const match = filepath.match("^((../)+)src/routes");
@@ -294498,7 +294822,7 @@ var fsPatch_default = (getFramwork) => ({
294498
294822
  return;
294499
294823
  }
294500
294824
  filepath = path_exports.posixify(filepath.toString());
294501
- if (is_route_script(getFramwork(), filepath) || is_root_layout(config2, filepath) || is_root_layout_server(config2, filepath)) {
294825
+ if (is_route_script(getFramework(), filepath) || is_root_layout(config2, filepath) || is_root_layout_server(config2, filepath)) {
294502
294826
  return {
294503
294827
  id: resolve_relative(config2, filepath)
294504
294828
  };
@@ -294506,7 +294830,7 @@ var fsPatch_default = (getFramwork) => ({
294506
294830
  },
294507
294831
  load: async (filepath, { config: config2 }) => {
294508
294832
  filepath = path_exports.posixify(filepath.toString());
294509
- if (is_route_script(getFramwork(), filepath) || is_root_layout_server(config2, filepath)) {
294833
+ if (is_route_script(getFramework(), filepath) || is_root_layout_server(config2, filepath)) {
294510
294834
  filepath = resolve_relative(config2, filepath);
294511
294835
  return {
294512
294836
  code: await fs_exports.readFile(filepath) || await fs_exports.readFile(path_exports.join(config2.projectRoot, filepath)) || ""
@@ -294524,34 +294848,40 @@ var _readDirSync = import_node_fs3.default.readdirSync;
294524
294848
  var _statSync = import_node_fs3.default.statSync;
294525
294849
  var _readFileSync = import_node_fs3.default.readFileSync;
294526
294850
  var _unlinkSync = import_node_fs3.default.unlinkSync;
294851
+ function getStringFilepath(fp) {
294852
+ if (fp instanceof URL) {
294853
+ return fp.pathname;
294854
+ }
294855
+ return fp.toString();
294856
+ }
294527
294857
  import_node_fs3.default.readFileSync = function(fp, options) {
294528
- const filepath = fp.toString();
294858
+ const filepath = getStringFilepath(fp);
294529
294859
  if (filepath.endsWith("+page.js") || filepath.endsWith("+layout.js") || filepath.replace(".ts", ".js").endsWith("+layout.server.js")) {
294530
294860
  try {
294531
- return _readFileSync(filepath, options);
294861
+ return _readFileSync(fp, options);
294532
294862
  } catch {
294533
294863
  return typeof options === "string" || options?.encoding ? "" : Buffer.from("");
294534
294864
  }
294535
294865
  }
294536
294866
  if (filepath.endsWith(path_exports.join("src", "routes", "+layout.svelte"))) {
294537
294867
  try {
294538
- return _readFileSync(filepath, options);
294868
+ return _readFileSync(fp, options);
294539
294869
  } catch {
294540
294870
  return typeof options === "string" || options?.encoding ? empty_layout : Buffer.from(empty_layout);
294541
294871
  }
294542
294872
  }
294543
- return _readFileSync(filepath, options);
294873
+ return _readFileSync(fp, options);
294544
294874
  };
294545
294875
  import_node_fs3.default.statSync = function(fp, options) {
294546
- let filepath = fp.toString();
294876
+ let filepath = getStringFilepath(fp);
294547
294877
  if (!filepath.includes("routes") || !path_exports.basename(filepath).startsWith("+")) {
294548
294878
  return _statSync(fp, options);
294549
294879
  }
294550
294880
  try {
294551
- const result = _statSync(filepath, options);
294881
+ const result = _statSync(fp, options);
294552
294882
  return result;
294553
294883
  } catch (error2) {
294554
- filepath = path_exports.posixify(filepath.toString());
294884
+ filepath = path_exports.posixify(filepath);
294555
294885
  const mock5 = virtual_file(path_exports.basename(filepath), { withFileTypes: true });
294556
294886
  if (filepath.endsWith(path_exports.join("routes", "+layout.svelte")) || filepath.endsWith(path_exports.join("routes", "+layout.svelte")) || filepath.endsWith(path_exports.join("routes", "+layout.server.js")) || filepath.endsWith(path_exports.join("routes", "+layout.server.js"))) {
294557
294887
  return mock5;
@@ -294569,10 +294899,11 @@ import_node_fs3.default.unlinkSync = function(filepath) {
294569
294899
  } catch {
294570
294900
  }
294571
294901
  };
294572
- import_node_fs3.default.readdirSync = function(filepath, options) {
294573
- if (!filepath.toString().includes("routes"))
294574
- return _readDirSync(filepath, options);
294575
- const result = _readDirSync(filepath, options);
294902
+ import_node_fs3.default.readdirSync = function(fp, options) {
294903
+ const filepath = getStringFilepath(fp);
294904
+ if (!filepath.includes("routes"))
294905
+ return _readDirSync(fp, options);
294906
+ const result = _readDirSync(fp, options);
294576
294907
  const file_names = result.map((file) => {
294577
294908
  if (file instanceof import_node_fs3.Dirent) {
294578
294909
  return file.name;
@@ -294588,7 +294919,7 @@ import_node_fs3.default.readdirSync = function(filepath, options) {
294588
294919
  if (contains("+page.svelte", "+page.gql") && !contains("+page.js", "+page.ts")) {
294589
294920
  result.push(virtual_file("+page.js", options));
294590
294921
  }
294591
- const posix_filepath = path_exports.posixify(filepath.toString());
294922
+ const posix_filepath = path_exports.posixify(filepath);
294592
294923
  if ((is_root_route(posix_filepath) || contains("+layout.svelte", "+layout.gql")) && !contains("+layout.ts", "+layout.js")) {
294593
294924
  result.push(virtual_file("+layout.js", options));
294594
294925
  }