houdini-svelte 1.2.54 → 1.2.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  }
@@ -76664,6 +76709,7 @@ var Layer = class {
76664
76709
  [id2]: {
76665
76710
  ...this.operations[id2],
76666
76711
  fields: {
76712
+ ...this.operations[id2]?.fields,
76667
76713
  [field]: [...this.operations[id2]?.fields[field] || [], operation]
76668
76714
  }
76669
76715
  }
@@ -76688,32 +76734,6 @@ var OperationKind = {
76688
76734
  insert: "insert",
76689
76735
  remove: "remove"
76690
76736
  };
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
76737
  var InMemorySubscriptions = class {
76718
76738
  cache;
76719
76739
  constructor(cache) {
@@ -76724,6 +76744,9 @@ var InMemorySubscriptions = class {
76724
76744
  activeFields(parent2) {
76725
76745
  return Object.keys(this.subscribers.get(parent2) || {});
76726
76746
  }
76747
+ copySubscribers(from, to) {
76748
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
76749
+ }
76727
76750
  add({
76728
76751
  parent: parent2,
76729
76752
  spec,
@@ -76906,6 +76929,11 @@ var InMemorySubscriptions = class {
76906
76929
  get(id2, field) {
76907
76930
  return this.subscribers.get(id2)?.get(field)?.selections || [];
76908
76931
  }
76932
+ getAll(id2) {
76933
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
76934
+ (fieldSub) => fieldSub.selections
76935
+ );
76936
+ }
76909
76937
  remove(id2, selection, targets, variables, visited = []) {
76910
76938
  visited.push(id2);
76911
76939
  const linkedIDs = [];
@@ -76947,7 +76975,7 @@ var InMemorySubscriptions = class {
76947
76975
  }
76948
76976
  const subscriberField = subscriber.get(fieldName);
76949
76977
  for (const spec of specs) {
76950
- const counts = subscriber.get(fieldName)?.referenceCounts;
76978
+ const counts = subscriberField?.referenceCounts;
76951
76979
  if (!counts?.has(spec.set)) {
76952
76980
  continue;
76953
76981
  }
@@ -76970,24 +76998,23 @@ var InMemorySubscriptions = class {
76970
76998
  this.subscribers.delete(id2);
76971
76999
  }
76972
77000
  }
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);
77001
+ removeAllSubscribers(id2, targets) {
77002
+ if (!targets) {
77003
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
77004
+ (spec) => spec.selections.flatMap((sel) => sel[0])
77005
+ );
77006
+ }
77007
+ for (const target of targets) {
77008
+ for (const subselection of this.findSubSelections(
77009
+ target.parentID || rootID,
77010
+ target.selection,
77011
+ target.variables || {},
77012
+ id2
77013
+ )) {
77014
+ this.remove(id2, subselection, targets, target.variables || {});
76989
77015
  }
76990
77016
  }
77017
+ return;
76991
77018
  }
76992
77019
  get size() {
76993
77020
  let size = 0;
@@ -76998,6 +77025,32 @@ var InMemorySubscriptions = class {
76998
77025
  }
76999
77026
  return size;
77000
77027
  }
77028
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
77029
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
77030
+ let targetSelection = getFieldsForType(selection, __typename, false);
77031
+ for (const fieldSelection of Object.values(targetSelection || {})) {
77032
+ if (!fieldSelection.selection) {
77033
+ continue;
77034
+ }
77035
+ const key = evaluateKey(fieldSelection.keyRaw, variables || {});
77036
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
77037
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten(linkedRecord.value);
77038
+ if (links.includes(searchTarget)) {
77039
+ selections.push(fieldSelection.selection);
77040
+ } else {
77041
+ for (const link of links) {
77042
+ this.findSubSelections(
77043
+ link,
77044
+ fieldSelection.selection,
77045
+ variables,
77046
+ searchTarget,
77047
+ selections
77048
+ );
77049
+ }
77050
+ }
77051
+ }
77052
+ return selections;
77053
+ }
77001
77054
  };
77002
77055
  var Cache = class {
77003
77056
  _internal_unstable;
@@ -77073,11 +77126,17 @@ var Cache = class {
77073
77126
  }
77074
77127
  registerKeyMap(source, mapped) {
77075
77128
  this._internal_unstable.storage.registerIDMapping(source, mapped);
77129
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
77076
77130
  }
77077
77131
  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);
77132
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
77133
+ Boolean
77134
+ );
77135
+ for (const recordID of recordIDs) {
77136
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
77137
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
77138
+ this._internal_unstable.storage.delete(recordID, layer);
77139
+ }
77081
77140
  }
77082
77141
  setConfig(config2) {
77083
77142
  this._internal_unstable.setConfig(config2);
@@ -77383,6 +77442,9 @@ var CacheInternal = class {
77383
77442
  layer,
77384
77443
  forceNotify
77385
77444
  });
77445
+ let action = () => {
77446
+ layer.writeLink(parent2, key, linkedIDs);
77447
+ };
77386
77448
  if (applyUpdates && updates) {
77387
77449
  if (key === "edges") {
77388
77450
  const newNodeIDs = [];
@@ -77417,8 +77479,26 @@ var CacheInternal = class {
77417
77479
  }
77418
77480
  if (update === "prepend") {
77419
77481
  linkedIDs = newIDs.concat(oldIDs);
77482
+ if (layer?.optimistic) {
77483
+ action = () => {
77484
+ for (const id2 of newIDs) {
77485
+ if (id2) {
77486
+ layer.insert(parent2, key, "start", id2);
77487
+ }
77488
+ }
77489
+ };
77490
+ }
77420
77491
  } else if (update === "append") {
77421
77492
  linkedIDs = oldIDs.concat(newIDs);
77493
+ if (layer?.optimistic) {
77494
+ action = () => {
77495
+ for (const id2 of newIDs) {
77496
+ if (id2) {
77497
+ layer.insert(parent2, key, "end", id2);
77498
+ }
77499
+ }
77500
+ };
77501
+ }
77422
77502
  } else if (update === "replace") {
77423
77503
  linkedIDs = newIDs;
77424
77504
  }
@@ -77437,7 +77517,7 @@ var CacheInternal = class {
77437
77517
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
77438
77518
  }
77439
77519
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
77440
- layer.writeLink(parent2, key, linkedIDs);
77520
+ action();
77441
77521
  }
77442
77522
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
77443
77523
  if (id2 == null) {
@@ -77492,6 +77572,9 @@ var CacheInternal = class {
77492
77572
  if (!targetID) {
77493
77573
  continue;
77494
77574
  }
77575
+ toNotify.push(
77576
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
77577
+ );
77495
77578
  this.cache.delete(targetID, layer);
77496
77579
  }
77497
77580
  }
@@ -77913,7 +77996,6 @@ function variableValue(value2, args) {
77913
77996
  );
77914
77997
  }
77915
77998
  }
77916
- var rootID = "_ROOT_";
77917
77999
  function defaultComponentField({
77918
78000
  cache,
77919
78001
  component,
@@ -140793,6 +140875,33 @@ var GarbageCollector2 = class {
140793
140875
  }
140794
140876
  }
140795
140877
  };
140878
+ function evaluateKey2(key, variables = null) {
140879
+ let evaluated = "";
140880
+ let varName = "";
140881
+ let inString = false;
140882
+ for (const char of key) {
140883
+ if (varName) {
140884
+ if (varChars2.includes(char)) {
140885
+ varName += char;
140886
+ continue;
140887
+ }
140888
+ const value2 = variables?.[varName.slice(1)];
140889
+ evaluated += typeof value2 !== "undefined" ? JSON.stringify(value2) : "undefined";
140890
+ varName = "";
140891
+ }
140892
+ if (char === "$" && !inString) {
140893
+ varName = "$";
140894
+ continue;
140895
+ }
140896
+ if (char === '"') {
140897
+ inString = !inString;
140898
+ }
140899
+ evaluated += char;
140900
+ }
140901
+ return evaluated;
140902
+ }
140903
+ var varChars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
140904
+ var rootID2 = "_ROOT_";
140796
140905
  var ListManager2 = class {
140797
140906
  rootID;
140798
140907
  cache;
@@ -140858,11 +140967,15 @@ var ListManager2 = class {
140858
140967
  this.listsByField.get(parentID).get(list.key).push(handler);
140859
140968
  }
140860
140969
  removeIDFromAllLists(id2, layer) {
140970
+ let removed = false;
140861
140971
  for (const fieldMap of this.lists.values()) {
140862
140972
  for (const list of fieldMap.values()) {
140863
- list.removeID(id2, void 0, layer);
140973
+ if (list.removeID(id2, void 0, layer)) {
140974
+ removed = true;
140975
+ }
140864
140976
  }
140865
140977
  }
140978
+ return removed;
140866
140979
  }
140867
140980
  deleteField(parentID, field) {
140868
140981
  if (!this.listsByField.get(parentID)?.has(field)) {
@@ -141165,7 +141278,13 @@ var ListCollection2 = class {
141165
141278
  this.lists.forEach((list) => list.addToList(...args));
141166
141279
  }
141167
141280
  removeID(...args) {
141168
- this.lists.forEach((list) => list.removeID(...args));
141281
+ let removed = false;
141282
+ this.lists.forEach((list) => {
141283
+ if (list.removeID(...args)) {
141284
+ removed = true;
141285
+ }
141286
+ });
141287
+ return removed;
141169
141288
  }
141170
141289
  remove(...args) {
141171
141290
  this.lists.forEach((list) => list.remove(...args));
@@ -141280,6 +141399,7 @@ var InMemoryStorage2 = class {
141280
141399
  }
141281
141400
  registerIDMapping(from, to) {
141282
141401
  this.idMaps[from] = to;
141402
+ this.idMaps[to] = from;
141283
141403
  }
141284
141404
  createLayer(optimistic = false) {
141285
141405
  const layer = new Layer2(this.idCount++);
@@ -141290,11 +141410,11 @@ var InMemoryStorage2 = class {
141290
141410
  insert(id2, field, location, target) {
141291
141411
  return this.topLayer.insert(id2, field, location, target);
141292
141412
  }
141293
- remove(id2, field, target, layerToUser = this.topLayer) {
141294
- return layerToUser.remove(id2, field, target);
141413
+ remove(id2, field, target, layer = this.topLayer) {
141414
+ return layer.remove(id2, field, target);
141295
141415
  }
141296
- delete(id2, layerToUser = this.topLayer) {
141297
- return layerToUser.delete(id2);
141416
+ delete(id2, layer = this.topLayer) {
141417
+ return layer.delete(id2);
141298
141418
  }
141299
141419
  deleteField(id2, field) {
141300
141420
  return this.topLayer.deleteField(id2, field);
@@ -141332,6 +141452,9 @@ var InMemoryStorage2 = class {
141332
141452
  return;
141333
141453
  }
141334
141454
  operations.remove.add(v);
141455
+ if (this.idMaps[v]) {
141456
+ operations.remove.add(this.idMaps[v]);
141457
+ }
141335
141458
  });
141336
141459
  if (typeof layerValue === "undefined" && defaultValue) {
141337
141460
  const targetLayer = this.topLayer;
@@ -141358,7 +141481,11 @@ var InMemoryStorage2 = class {
141358
141481
  operations.remove.add(op.id);
141359
141482
  }
141360
141483
  if (isInsertOperation2(op)) {
141361
- operations.insert[op.location].unshift(op.id);
141484
+ if (op.location === OperationLocation2.end) {
141485
+ operations.insert[op.location].unshift(op.id);
141486
+ } else {
141487
+ operations.insert[op.location].push(op.id);
141488
+ }
141362
141489
  }
141363
141490
  if (isDeleteOperation2(op)) {
141364
141491
  return {
@@ -141604,7 +141731,7 @@ var Layer2 = class {
141604
141731
  }
141605
141732
  for (const [id2, ops] of Object.entries(layer.operations)) {
141606
141733
  const fields = {};
141607
- for (const opMap of [this.operations[id2], layer.operations[id2]].filter(Boolean)) {
141734
+ for (const opMap of [layer.operations[id2], this.operations[id2]].filter(Boolean)) {
141608
141735
  for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
141609
141736
  fields[fieldName] = [...fields[fieldName] || [], ...operations];
141610
141737
  }
@@ -141644,6 +141771,7 @@ var Layer2 = class {
141644
141771
  [id2]: {
141645
141772
  ...this.operations[id2],
141646
141773
  fields: {
141774
+ ...this.operations[id2]?.fields,
141647
141775
  [field]: [...this.operations[id2]?.fields[field] || [], operation]
141648
141776
  }
141649
141777
  }
@@ -141668,32 +141796,6 @@ var OperationKind2 = {
141668
141796
  insert: "insert",
141669
141797
  remove: "remove"
141670
141798
  };
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
141799
  var InMemorySubscriptions2 = class {
141698
141800
  cache;
141699
141801
  constructor(cache) {
@@ -141704,6 +141806,9 @@ var InMemorySubscriptions2 = class {
141704
141806
  activeFields(parent2) {
141705
141807
  return Object.keys(this.subscribers.get(parent2) || {});
141706
141808
  }
141809
+ copySubscribers(from, to) {
141810
+ this.subscribers.set(to, this.subscribers.get(from) || /* @__PURE__ */ new Map());
141811
+ }
141707
141812
  add({
141708
141813
  parent: parent2,
141709
141814
  spec,
@@ -141886,6 +141991,11 @@ var InMemorySubscriptions2 = class {
141886
141991
  get(id2, field) {
141887
141992
  return this.subscribers.get(id2)?.get(field)?.selections || [];
141888
141993
  }
141994
+ getAll(id2) {
141995
+ return [...this.subscribers.get(id2)?.values() || []].flatMap(
141996
+ (fieldSub) => fieldSub.selections
141997
+ );
141998
+ }
141889
141999
  remove(id2, selection, targets, variables, visited = []) {
141890
142000
  visited.push(id2);
141891
142001
  const linkedIDs = [];
@@ -141927,7 +142037,7 @@ var InMemorySubscriptions2 = class {
141927
142037
  }
141928
142038
  const subscriberField = subscriber.get(fieldName);
141929
142039
  for (const spec of specs) {
141930
- const counts = subscriber.get(fieldName)?.referenceCounts;
142040
+ const counts = subscriberField?.referenceCounts;
141931
142041
  if (!counts?.has(spec.set)) {
141932
142042
  continue;
141933
142043
  }
@@ -141950,24 +142060,23 @@ var InMemorySubscriptions2 = class {
141950
142060
  this.subscribers.delete(id2);
141951
142061
  }
141952
142062
  }
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);
142063
+ removeAllSubscribers(id2, targets) {
142064
+ if (!targets) {
142065
+ targets = [...this.subscribers.get(id2)?.values() || []].flatMap(
142066
+ (spec) => spec.selections.flatMap((sel) => sel[0])
142067
+ );
142068
+ }
142069
+ for (const target of targets) {
142070
+ for (const subselection of this.findSubSelections(
142071
+ target.parentID || rootID2,
142072
+ target.selection,
142073
+ target.variables || {},
142074
+ id2
142075
+ )) {
142076
+ this.remove(id2, subselection, targets, target.variables || {});
141969
142077
  }
141970
142078
  }
142079
+ return;
141971
142080
  }
141972
142081
  get size() {
141973
142082
  let size = 0;
@@ -141978,6 +142087,32 @@ var InMemorySubscriptions2 = class {
141978
142087
  }
141979
142088
  return size;
141980
142089
  }
142090
+ findSubSelections(parentID, selection, variables, searchTarget, selections = []) {
142091
+ const __typename = this.cache._internal_unstable.storage.get(parentID, "__typename").value;
142092
+ let targetSelection = getFieldsForType2(selection, __typename, false);
142093
+ for (const fieldSelection of Object.values(targetSelection || {})) {
142094
+ if (!fieldSelection.selection) {
142095
+ continue;
142096
+ }
142097
+ const key = evaluateKey2(fieldSelection.keyRaw, variables || {});
142098
+ const linkedRecord = this.cache._internal_unstable.storage.get(parentID, key);
142099
+ const links = !Array.isArray(linkedRecord.value) ? [linkedRecord.value] : flatten2(linkedRecord.value);
142100
+ if (links.includes(searchTarget)) {
142101
+ selections.push(fieldSelection.selection);
142102
+ } else {
142103
+ for (const link of links) {
142104
+ this.findSubSelections(
142105
+ link,
142106
+ fieldSelection.selection,
142107
+ variables,
142108
+ searchTarget,
142109
+ selections
142110
+ );
142111
+ }
142112
+ }
142113
+ }
142114
+ return selections;
142115
+ }
141981
142116
  };
141982
142117
  var Cache2 = class {
141983
142118
  _internal_unstable;
@@ -142053,11 +142188,17 @@ var Cache2 = class {
142053
142188
  }
142054
142189
  registerKeyMap(source, mapped) {
142055
142190
  this._internal_unstable.storage.registerIDMapping(source, mapped);
142191
+ this._internal_unstable.subscriptions.copySubscribers(source, mapped);
142056
142192
  }
142057
142193
  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);
142194
+ const recordIDs = [this._internal_unstable.storage.idMaps[id2], id2].filter(
142195
+ Boolean
142196
+ );
142197
+ for (const recordID of recordIDs) {
142198
+ this._internal_unstable.subscriptions.removeAllSubscribers(recordID);
142199
+ this._internal_unstable.lists.removeIDFromAllLists(recordID, layer);
142200
+ this._internal_unstable.storage.delete(recordID, layer);
142201
+ }
142061
142202
  }
142062
142203
  setConfig(config2) {
142063
142204
  this._internal_unstable.setConfig(config2);
@@ -142363,6 +142504,9 @@ var CacheInternal2 = class {
142363
142504
  layer,
142364
142505
  forceNotify
142365
142506
  });
142507
+ let action = () => {
142508
+ layer.writeLink(parent2, key, linkedIDs);
142509
+ };
142366
142510
  if (applyUpdates && updates) {
142367
142511
  if (key === "edges") {
142368
142512
  const newNodeIDs = [];
@@ -142397,8 +142541,26 @@ var CacheInternal2 = class {
142397
142541
  }
142398
142542
  if (update === "prepend") {
142399
142543
  linkedIDs = newIDs.concat(oldIDs);
142544
+ if (layer?.optimistic) {
142545
+ action = () => {
142546
+ for (const id2 of newIDs) {
142547
+ if (id2) {
142548
+ layer.insert(parent2, key, "start", id2);
142549
+ }
142550
+ }
142551
+ };
142552
+ }
142400
142553
  } else if (update === "append") {
142401
142554
  linkedIDs = oldIDs.concat(newIDs);
142555
+ if (layer?.optimistic) {
142556
+ action = () => {
142557
+ for (const id2 of newIDs) {
142558
+ if (id2) {
142559
+ layer.insert(parent2, key, "end", id2);
142560
+ }
142561
+ }
142562
+ };
142563
+ }
142402
142564
  } else if (update === "replace") {
142403
142565
  linkedIDs = newIDs;
142404
142566
  }
@@ -142417,7 +142579,7 @@ var CacheInternal2 = class {
142417
142579
  this.subscriptions.remove(lostID, fieldSelection, specs, variables);
142418
142580
  }
142419
142581
  if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
142420
- layer.writeLink(parent2, key, linkedIDs);
142582
+ action();
142421
142583
  }
142422
142584
  for (const id2 of newIDs.filter((id22) => !oldIDs.includes(id22))) {
142423
142585
  if (id2 == null) {
@@ -142472,6 +142634,9 @@ var CacheInternal2 = class {
142472
142634
  if (!targetID) {
142473
142635
  continue;
142474
142636
  }
142637
+ toNotify.push(
142638
+ ...this.subscriptions.getAll(targetID).filter((sub) => sub[0].parentID !== targetID)
142639
+ );
142475
142640
  this.cache.delete(targetID, layer);
142476
142641
  }
142477
142642
  }
@@ -142893,7 +143058,6 @@ function variableValue2(value2, args) {
142893
143058
  );
142894
143059
  }
142895
143060
  }
142896
- var rootID2 = "_ROOT_";
142897
143061
  function defaultComponentField2({
142898
143062
  cache,
142899
143063
  component,