houdini-svelte 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.
@@ -75813,6 +75813,33 @@ var GarbageCollector = class {
75813
75813
  }
75814
75814
  }
75815
75815
  };
75816
+ function evaluateKey(key, variables = null) {
75817
+ let evaluated = "";
75818
+ let varName = "";
75819
+ let inString = false;
75820
+ for (const char of key) {
75821
+ if (varName) {
75822
+ if (varChars.includes(char)) {
75823
+ varName += char;
75824
+ continue;
75825
+ }
75826
+ const value2 = variables?.[varName.slice(1)];
75827
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
75828
+ varName = "";
75829
+ }
75830
+ if (char === "$" && !inString) {
75831
+ varName = "$";
75832
+ continue;
75833
+ }
75834
+ if (char === '"') {
75835
+ inString = !inString;
75836
+ }
75837
+ evaluated += char;
75838
+ }
75839
+ return evaluated;
75840
+ }
75841
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
75842
+ var rootID = "_ROOT_";
75816
75843
  var ListManager = class {
75817
75844
  rootID;
75818
75845
  cache;
@@ -75878,11 +75905,15 @@ var ListManager = class {
75878
75905
  this.listsByField.get(parentID).get(list.key).push(handler);
75879
75906
  }
75880
75907
  removeIDFromAllLists(id2, layer) {
75908
+ let removed = false;
75881
75909
  for (const fieldMap of this.lists.values()) {
75882
75910
  for (const list of fieldMap.values()) {
75883
- list.removeID(id2, void 0, layer);
75911
+ if (list.removeID(id2, void 0, layer)) {
75912
+ removed = true;
75913
+ }
75884
75914
  }
75885
75915
  }
75916
+ return removed;
75886
75917
  }
75887
75918
  deleteField(parentID, field) {
75888
75919
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -76185,7 +76216,13 @@ var ListCollection = class {
76185
76216
  this.lists.forEach((list) => list.addToList(...args));
76186
76217
  }
76187
76218
  removeID(...args) {
76188
- this.lists.forEach((list) => list.removeID(...args));
76219
+ let removed = false;
76220
+ this.lists.forEach((list) => {
76221
+ if (list.removeID(...args)) {
76222
+ removed = true;
76223
+ }
76224
+ });
76225
+ return removed;
76189
76226
  }
76190
76227
  remove(...args) {
76191
76228
  this.lists.forEach((list) => list.remove(...args));
@@ -76300,6 +76337,7 @@ var InMemoryStorage = class {
76300
76337
  }
76301
76338
  registerIDMapping(from, to) {
76302
76339
  this.idMaps[from] = to;
76340
+ this.idMaps[to] = from;
76303
76341
  }
76304
76342
  createLayer(optimistic = false) {
76305
76343
  const layer = new Layer(this.idCount++);
@@ -76310,11 +76348,11 @@ var InMemoryStorage = class {
76310
76348
  insert(id2, field, location, target) {
76311
76349
  return this.topLayer.insert(id2, field, location, target);
76312
76350
  }
76313
- remove(id2, field, target, layerToUser = this.topLayer) {
76314
- return layerToUser.remove(id2, field, target);
76351
+ remove(id2, field, target, layer = this.topLayer) {
76352
+ return layer.remove(id2, field, target);
76315
76353
  }
76316
- delete(id2, layerToUser = this.topLayer) {
76317
- return layerToUser.delete(id2);
76354
+ delete(id2, layer = this.topLayer) {
76355
+ return layer.delete(id2);
76318
76356
  }
76319
76357
  deleteField(id2, field) {
76320
76358
  return this.topLayer.deleteField(id2, field);
@@ -76352,6 +76390,9 @@ var InMemoryStorage = class {
76352
76390
  return;
76353
76391
  }
76354
76392
  operations.remove.add(v);
76393
+ if (this.idMaps[v]) {
76394
+ operations.remove.add(this.idMaps[v]);
76395
+ }
76355
76396
  });
76356
76397
  if (typeof layerValue === "undefined" && defaultValue) {
76357
76398
  const targetLayer = this.topLayer;
@@ -76378,7 +76419,11 @@ var InMemoryStorage = class {
76378
76419
  operations.remove.add(op.id);
76379
76420
  }
76380
76421
  if (isInsertOperation(op)) {
76381
- operations.insert[op.location].unshift(op.id);
76422
+ if (op.location === OperationLocation.end) {
76423
+ operations.insert[op.location].unshift(op.id);
76424
+ } else {
76425
+ operations.insert[op.location].push(op.id);
76426
+ }
76382
76427
  }
76383
76428
  if (isDeleteOperation(op)) {
76384
76429
  return {
@@ -76624,7 +76669,7 @@ var Layer = class {
76624
76669
  }
76625
76670
  for (const [id2, ops] of Object.entries(layer.operations)) {
76626
76671
  const fields = {};
76627
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
76672
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
76628
76673
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
76629
76674
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
76630
76675
  }
@@ -76688,32 +76733,6 @@ var OperationKind = {
76688
76733
  insert: "insert",
76689
76734
  remove: "remove"
76690
76735
  };
76691
- function evaluateKey(key, variables = null) {
76692
- let evaluated = "";
76693
- let varName = "";
76694
- let inString = false;
76695
- for (const char of key) {
76696
- if (varName) {
76697
- if (varChars.includes(char)) {
76698
- varName += char;
76699
- continue;
76700
- }
76701
- const value2 = variables?.[varName.slice(1)];
76702
- evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
76703
- varName = "";
76704
- }
76705
- if (char === "$" && !inString) {
76706
- varName = "$";
76707
- continue;
76708
- }
76709
- if (char === '"') {
76710
- inString = !inString;
76711
- }
76712
- evaluated += char;
76713
- }
76714
- return evaluated;
76715
- }
76716
- var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
76717
76736
  var InMemorySubscriptions = class {
76718
76737
  cache;
76719
76738
  constructor(cache) {
@@ -76724,6 +76743,9 @@ var InMemorySubscriptions = class {
76724
76743
  activeFields(parent2) {
76725
76744
  return Object.keys(this.subscribers.get(parent2) || {});
76726
76745
  }
76746
+ copySubscribers(from, to) {
76747
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
76748
+ }
76727
76749
  add({
76728
76750
  parent: parent2,
76729
76751
  spec,
@@ -76906,6 +76928,11 @@ var InMemorySubscriptions = class {
76906
76928
  get(id2, field) {
76907
76929
  return this.subscribers.get(id2)?.get(field)?.selections || [];
76908
76930
  }
76931
+ getAll(id2) {
76932
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
76933
+ (fieldSub) => fieldSub.selections
76934
+ );
76935
+ }
76909
76936
  remove(id2, selection, targets, variables, visited = []) {
76910
76937
  visited.push(id2);
76911
76938
  const linkedIDs = [];
@@ -76947,7 +76974,7 @@ var InMemorySubscriptions = class {
76947
76974
  }
76948
76975
  const subscriberField = subscriber.get(fieldName);
76949
76976
  for (const spec of specs) {
76950
- const counts = subscriber.get(fieldName)?.referenceCounts;
76977
+ const counts = subscriberField?.referenceCounts;
76951
76978
  if (!counts?.has(spec.set)) {
76952
76979
  continue;
76953
76980
  }
@@ -76970,24 +76997,23 @@ var InMemorySubscriptions = class {
76970
76997
  this.subscribers.delete(id2);
76971
76998
  }
76972
76999
  }
76973
- removeAllSubscribers(id2, targets, visited = []) {
76974
- visited.push(id2);
76975
- const subscriber = this.subscribers.get(id2);
76976
- for (const [key, val] of subscriber?.entries() ?? []) {
76977
- const subscribers = targets || val.selections.map(([spec]) => spec);
76978
- this.removeSubscribers(id2, key, subscribers);
76979
- const { value: value2, kind } = this.cache._internal_unstable.storage.get(id2, key);
76980
- if (kind === "scalar") {
76981
- continue;
76982
- }
76983
- const nextTargets = Array.isArray(value2) ? flatten(value2) : [value2];
76984
- for (const id22 of nextTargets) {
76985
- if (visited.includes(id22)) {
76986
- continue;
76987
- }
76988
- this.removeAllSubscribers(id22, subscribers, visited);
77000
+ removeAllSubscribers(id2, targets) {
77001
+ if (!targets) {
77002
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
77003
+ (spec) => spec.selections.flatMap((sel) => sel[0])
77004
+ );
77005
+ }
77006
+ for (const target of targets) {
77007
+ for (const subselection of this.findSubSelections(
77008
+ target.parentID || rootID,
77009
+ target.selection,
77010
+ target.variables || {},
77011
+ id2
77012
+ )) {
77013
+ this.remove(id2, subselection, targets, target.variables || {});
76989
77014
  }
76990
77015
  }
77016
+ return;
76991
77017
  }
76992
77018
  get size() {
76993
77019
  let size = 0;
@@ -76998,6 +77024,32 @@ var InMemorySubscriptions = class {
76998
77024
  }
76999
77025
  return size;
77000
77026
  }
77027
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
77028
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
77029
+ let targetSelection = getFieldsForType(selection, __typename, false);
77030
+ for (const fieldSelection of Object.values(targetSelection || {})) {
77031
+ if (!fieldSelection.selection) {
77032
+ continue;
77033
+ }
77034
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
77035
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
77036
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
77037
+ if (links.includes(searchTarget)) {
77038
+ selections.push(fieldSelection.selection);
77039
+ } else {
77040
+ for (const link of links) {
77041
+ this.findSubSelections(
77042
+ link,
77043
+ fieldSelection.selection,
77044
+ variables,
77045
+ searchTarget,
77046
+ selections
77047
+ );
77048
+ }
77049
+ }
77050
+ }
77051
+ return selections;
77052
+ }
77001
77053
  };
77002
77054
  var Cache = class {
77003
77055
  _internal_unstable;
@@ -77073,11 +77125,17 @@ var Cache = class {
77073
77125
  }
77074
77126
  registerKeyMap(source, mapped) {
77075
77127
  this._internal_unstable.storage.registerIDMapping(source, mapped);
77128
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
77076
77129
  }
77077
77130
  delete(id2, layer) {
77078
- this._internal_unstable.subscriptions.removeAllSubscribers(id2);
77079
- this._internal_unstable.lists.removeIDFromAllLists(id2, layer);
77080
- this._internal_unstable.storage.delete(id2, layer);
77131
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
77132
+ Boolean
77133
+ );
77134
+ for (const recordID of recordIDs) {
77135
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
77136
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
77137
+ this._internal_unstable.storage.delete(recordID, layer);
77138
+ }
77081
77139
  }
77082
77140
  setConfig(config2) {
77083
77141
  this._internal_unstable.setConfig(config2);
@@ -77383,6 +77441,9 @@ var CacheInternal = class {
77383
77441
  layer,
77384
77442
  forceNotify
77385
77443
  });
77444
+ let action = () => {
77445
+ layer.writeLink(parent2, key, linkedIDs);
77446
+ };
77386
77447
  if (applyUpdates && updates) {
77387
77448
  if (key === "edges") {
77388
77449
  const newNodeIDs = [];
@@ -77417,8 +77478,26 @@ var CacheInternal = class {
77417
77478
  }
77418
77479
  if (update === "prepend") {
77419
77480
  linkedIDs = newIDs.concat(oldIDs);
77481
+ if (layer?.optimistic) {
77482
+ action = () => {
77483
+ for (const id2 of newIDs) {
77484
+ if (id2) {
77485
+ layer.insert(parent2, key, "start", id2);
77486
+ }
77487
+ }
77488
+ };
77489
+ }
77420
77490
  } else if (update === "append") {
77421
77491
  linkedIDs = oldIDs.concat(newIDs);
77492
+ if (layer?.optimistic) {
77493
+ action = () => {
77494
+ for (const id2 of newIDs) {
77495
+ if (id2) {
77496
+ layer.insert(parent2, key, "end", id2);
77497
+ }
77498
+ }
77499
+ };
77500
+ }
77422
77501
  } else if (update === "replace") {
77423
77502
  linkedIDs = newIDs;
77424
77503
  }
@@ -77437,7 +77516,7 @@ var CacheInternal = class {
77437
77516
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
77438
77517
  }
77439
77518
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
77440
- layer.writeLink(parent2, key, linkedIDs);
77519
+ action();
77441
77520
  }
77442
77521
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
77443
77522
  if (id2 == null) {
@@ -77492,6 +77571,9 @@ var CacheInternal = class {
77492
77571
  if (!targetID) {
77493
77572
  continue;
77494
77573
  }
77574
+ toNotify.push(
77575
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
77576
+ );
77495
77577
  this.cache.delete(targetID, layer);
77496
77578
  }
77497
77579
  }
@@ -77913,7 +77995,6 @@ function variableValue(value2, args) {
77913
77995
  );
77914
77996
  }
77915
77997
  }
77916
- var rootID = "_ROOT_";
77917
77998
  function defaultComponentField({
77918
77999
  cache,
77919
78000
  component,
@@ -140793,6 +140874,33 @@ var GarbageCollector2 = class {
140793
140874
  }
140794
140875
  }
140795
140876
  };
140877
+ function evaluateKey2(key, variables = null) {
140878
+ let evaluated = "";
140879
+ let varName = "";
140880
+ let inString = false;
140881
+ for (const char of key) {
140882
+ if (varName) {
140883
+ if (varChars2.includes(char)) {
140884
+ varName += char;
140885
+ continue;
140886
+ }
140887
+ const value2 = variables?.[varName.slice(1)];
140888
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
140889
+ varName = "";
140890
+ }
140891
+ if (char === "$" && !inString) {
140892
+ varName = "$";
140893
+ continue;
140894
+ }
140895
+ if (char === '"') {
140896
+ inString = !inString;
140897
+ }
140898
+ evaluated += char;
140899
+ }
140900
+ return evaluated;
140901
+ }
140902
+ var varChars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
140903
+ var rootID2 = "_ROOT_";
140796
140904
  var ListManager2 = class {
140797
140905
  rootID;
140798
140906
  cache;
@@ -140858,11 +140966,15 @@ var ListManager2 = class {
140858
140966
  this.listsByField.get(parentID).get(list.key).push(handler);
140859
140967
  }
140860
140968
  removeIDFromAllLists(id2, layer) {
140969
+ let removed = false;
140861
140970
  for (const fieldMap of this.lists.values()) {
140862
140971
  for (const list of fieldMap.values()) {
140863
- list.removeID(id2, void 0, layer);
140972
+ if (list.removeID(id2, void 0, layer)) {
140973
+ removed = true;
140974
+ }
140864
140975
  }
140865
140976
  }
140977
+ return removed;
140866
140978
  }
140867
140979
  deleteField(parentID, field) {
140868
140980
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -141165,7 +141277,13 @@ var ListCollection2 = class {
141165
141277
  this.lists.forEach((list) => list.addToList(...args));
141166
141278
  }
141167
141279
  removeID(...args) {
141168
- this.lists.forEach((list) => list.removeID(...args));
141280
+ let removed = false;
141281
+ this.lists.forEach((list) => {
141282
+ if (list.removeID(...args)) {
141283
+ removed = true;
141284
+ }
141285
+ });
141286
+ return removed;
141169
141287
  }
141170
141288
  remove(...args) {
141171
141289
  this.lists.forEach((list) => list.remove(...args));
@@ -141280,6 +141398,7 @@ var InMemoryStorage2 = class {
141280
141398
  }
141281
141399
  registerIDMapping(from, to) {
141282
141400
  this.idMaps[from] = to;
141401
+ this.idMaps[to] = from;
141283
141402
  }
141284
141403
  createLayer(optimistic = false) {
141285
141404
  const layer = new Layer2(this.idCount++);
@@ -141290,11 +141409,11 @@ var InMemoryStorage2 = class {
141290
141409
  insert(id2, field, location, target) {
141291
141410
  return this.topLayer.insert(id2, field, location, target);
141292
141411
  }
141293
- remove(id2, field, target, layerToUser = this.topLayer) {
141294
- return layerToUser.remove(id2, field, target);
141412
+ remove(id2, field, target, layer = this.topLayer) {
141413
+ return layer.remove(id2, field, target);
141295
141414
  }
141296
- delete(id2, layerToUser = this.topLayer) {
141297
- return layerToUser.delete(id2);
141415
+ delete(id2, layer = this.topLayer) {
141416
+ return layer.delete(id2);
141298
141417
  }
141299
141418
  deleteField(id2, field) {
141300
141419
  return this.topLayer.deleteField(id2, field);
@@ -141332,6 +141451,9 @@ var InMemoryStorage2 = class {
141332
141451
  return;
141333
141452
  }
141334
141453
  operations.remove.add(v);
141454
+ if (this.idMaps[v]) {
141455
+ operations.remove.add(this.idMaps[v]);
141456
+ }
141335
141457
  });
141336
141458
  if (typeof layerValue === "undefined" && defaultValue) {
141337
141459
  const targetLayer = this.topLayer;
@@ -141358,7 +141480,11 @@ var InMemoryStorage2 = class {
141358
141480
  operations.remove.add(op.id);
141359
141481
  }
141360
141482
  if (isInsertOperation2(op)) {
141361
- operations.insert[op.location].unshift(op.id);
141483
+ if (op.location === OperationLocation2.end) {
141484
+ operations.insert[op.location].unshift(op.id);
141485
+ } else {
141486
+ operations.insert[op.location].push(op.id);
141487
+ }
141362
141488
  }
141363
141489
  if (isDeleteOperation2(op)) {
141364
141490
  return {
@@ -141604,7 +141730,7 @@ var Layer2 = class {
141604
141730
  }
141605
141731
  for (const [id2, ops] of Object.entries(layer.operations)) {
141606
141732
  const fields = {};
141607
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
141733
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
141608
141734
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
141609
141735
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
141610
141736
  }
@@ -141668,32 +141794,6 @@ var OperationKind2 = {
141668
141794
  insert: "insert",
141669
141795
  remove: "remove"
141670
141796
  };
141671
- function evaluateKey2(key, variables = null) {
141672
- let evaluated = "";
141673
- let varName = "";
141674
- let inString = false;
141675
- for (const char of key) {
141676
- if (varName) {
141677
- if (varChars2.includes(char)) {
141678
- varName += char;
141679
- continue;
141680
- }
141681
- const value2 = variables?.[varName.slice(1)];
141682
- evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
141683
- varName = "";
141684
- }
141685
- if (char === "$" && !inString) {
141686
- varName = "$";
141687
- continue;
141688
- }
141689
- if (char === '"') {
141690
- inString = !inString;
141691
- }
141692
- evaluated += char;
141693
- }
141694
- return evaluated;
141695
- }
141696
- var varChars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
141697
141797
  var InMemorySubscriptions2 = class {
141698
141798
  cache;
141699
141799
  constructor(cache) {
@@ -141704,6 +141804,9 @@ var InMemorySubscriptions2 = class {
141704
141804
  activeFields(parent2) {
141705
141805
  return Object.keys(this.subscribers.get(parent2) || {});
141706
141806
  }
141807
+ copySubscribers(from, to) {
141808
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
141809
+ }
141707
141810
  add({
141708
141811
  parent: parent2,
141709
141812
  spec,
@@ -141886,6 +141989,11 @@ var InMemorySubscriptions2 = class {
141886
141989
  get(id2, field) {
141887
141990
  return this.subscribers.get(id2)?.get(field)?.selections || [];
141888
141991
  }
141992
+ getAll(id2) {
141993
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
141994
+ (fieldSub) => fieldSub.selections
141995
+ );
141996
+ }
141889
141997
  remove(id2, selection, targets, variables, visited = []) {
141890
141998
  visited.push(id2);
141891
141999
  const linkedIDs = [];
@@ -141927,7 +142035,7 @@ var InMemorySubscriptions2 = class {
141927
142035
  }
141928
142036
  const subscriberField = subscriber.get(fieldName);
141929
142037
  for (const spec of specs) {
141930
- const counts = subscriber.get(fieldName)?.referenceCounts;
142038
+ const counts = subscriberField?.referenceCounts;
141931
142039
  if (!counts?.has(spec.set)) {
141932
142040
  continue;
141933
142041
  }
@@ -141950,24 +142058,23 @@ var InMemorySubscriptions2 = class {
141950
142058
  this.subscribers.delete(id2);
141951
142059
  }
141952
142060
  }
141953
- removeAllSubscribers(id2, targets, visited = []) {
141954
- visited.push(id2);
141955
- const subscriber = this.subscribers.get(id2);
141956
- for (const [key, val] of subscriber?.entries() ?? []) {
141957
- const subscribers = targets || val.selections.map(([spec]) => spec);
141958
- this.removeSubscribers(id2, key, subscribers);
141959
- const { value: value2, kind } = this.cache._internal_unstable.storage.get(id2, key);
141960
- if (kind === "scalar") {
141961
- continue;
141962
- }
141963
- const nextTargets = Array.isArray(value2) ? flatten2(value2) : [value2];
141964
- for (const id22 of nextTargets) {
141965
- if (visited.includes(id22)) {
141966
- continue;
141967
- }
141968
- this.removeAllSubscribers(id22, subscribers, visited);
142061
+ removeAllSubscribers(id2, targets) {
142062
+ if (!targets) {
142063
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
142064
+ (spec) => spec.selections.flatMap((sel) => sel[0])
142065
+ );
142066
+ }
142067
+ for (const target of targets) {
142068
+ for (const subselection of this.findSubSelections(
142069
+ target.parentID || rootID2,
142070
+ target.selection,
142071
+ target.variables || {},
142072
+ id2
142073
+ )) {
142074
+ this.remove(id2, subselection, targets, target.variables || {});
141969
142075
  }
141970
142076
  }
142077
+ return;
141971
142078
  }
141972
142079
  get size() {
141973
142080
  let size = 0;
@@ -141978,6 +142085,32 @@ var InMemorySubscriptions2 = class {
141978
142085
  }
141979
142086
  return size;
141980
142087
  }
142088
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
142089
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
142090
+ let targetSelection = getFieldsForType2(selection, __typename, false);
142091
+ for (const fieldSelection of Object.values(targetSelection || {})) {
142092
+ if (!fieldSelection.selection) {
142093
+ continue;
142094
+ }
142095
+ const key = evaluateKey2(fieldSelection.keyRaw, variables || {});
142096
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
142097
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten2(linkedRecord.value);
142098
+ if (links.includes(searchTarget)) {
142099
+ selections.push(fieldSelection.selection);
142100
+ } else {
142101
+ for (const link of links) {
142102
+ this.findSubSelections(
142103
+ link,
142104
+ fieldSelection.selection,
142105
+ variables,
142106
+ searchTarget,
142107
+ selections
142108
+ );
142109
+ }
142110
+ }
142111
+ }
142112
+ return selections;
142113
+ }
141981
142114
  };
141982
142115
  var Cache2 = class {
141983
142116
  _internal_unstable;
@@ -142053,11 +142186,17 @@ var Cache2 = class {
142053
142186
  }
142054
142187
  registerKeyMap(source, mapped) {
142055
142188
  this._internal_unstable.storage.registerIDMapping(source, mapped);
142189
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
142056
142190
  }
142057
142191
  delete(id2, layer) {
142058
- this._internal_unstable.subscriptions.removeAllSubscribers(id2);
142059
- this._internal_unstable.lists.removeIDFromAllLists(id2, layer);
142060
- this._internal_unstable.storage.delete(id2, layer);
142192
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
142193
+ Boolean
142194
+ );
142195
+ for (const recordID of recordIDs) {
142196
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
142197
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
142198
+ this._internal_unstable.storage.delete(recordID, layer);
142199
+ }
142061
142200
  }
142062
142201
  setConfig(config2) {
142063
142202
  this._internal_unstable.setConfig(config2);
@@ -142363,6 +142502,9 @@ var CacheInternal2 = class {
142363
142502
  layer,
142364
142503
  forceNotify
142365
142504
  });
142505
+ let action = () => {
142506
+ layer.writeLink(parent2, key, linkedIDs);
142507
+ };
142366
142508
  if (applyUpdates && updates) {
142367
142509
  if (key === "edges") {
142368
142510
  const newNodeIDs = [];
@@ -142397,8 +142539,26 @@ var CacheInternal2 = class {
142397
142539
  }
142398
142540
  if (update === "prepend") {
142399
142541
  linkedIDs = newIDs.concat(oldIDs);
142542
+ if (layer?.optimistic) {
142543
+ action = () => {
142544
+ for (const id2 of newIDs) {
142545
+ if (id2) {
142546
+ layer.insert(parent2, key, "start", id2);
142547
+ }
142548
+ }
142549
+ };
142550
+ }
142400
142551
  } else if (update === "append") {
142401
142552
  linkedIDs = oldIDs.concat(newIDs);
142553
+ if (layer?.optimistic) {
142554
+ action = () => {
142555
+ for (const id2 of newIDs) {
142556
+ if (id2) {
142557
+ layer.insert(parent2, key, "end", id2);
142558
+ }
142559
+ }
142560
+ };
142561
+ }
142402
142562
  } else if (update === "replace") {
142403
142563
  linkedIDs = newIDs;
142404
142564
  }
@@ -142417,7 +142577,7 @@ var CacheInternal2 = class {
142417
142577
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
142418
142578
  }
142419
142579
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
142420
- layer.writeLink(parent2, key, linkedIDs);
142580
+ action();
142421
142581
  }
142422
142582
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
142423
142583
  if (id2 == null) {
@@ -142472,6 +142632,9 @@ var CacheInternal2 = class {
142472
142632
  if (!targetID) {
142473
142633
  continue;
142474
142634
  }
142635
+ toNotify.push(
142636
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
142637
+ );
142475
142638
  this.cache.delete(targetID, layer);
142476
142639
  }
142477
142640
  }
@@ -142893,7 +143056,6 @@ function variableValue2(value2, args) {
142893
143056
  );
142894
143057
  }
142895
143058
  }
142896
- var rootID2 = "_ROOT_";
142897
143059
  function defaultComponentField2({
142898
143060
  cache,
142899
143061
  component,