houdini 1.0.0-next.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +2368 -151
  3. package/build/cmd-esm/index.js +2368 -151
  4. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  5. package/build/codegen/transforms/fragmentVariables.d.ts +2 -1
  6. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  7. package/build/codegen/validators/typeCheck.d.ts +1 -0
  8. package/build/codegen-cjs/index.js +2962 -719
  9. package/build/codegen-esm/index.js +2962 -719
  10. package/build/lib/config.d.ts +4 -6
  11. package/build/lib/types.d.ts +18 -15
  12. package/build/lib-cjs/index.js +3159 -171
  13. package/build/lib-esm/index.js +3152 -171
  14. package/build/runtime/cache/storage.d.ts +18 -15
  15. package/build/runtime/client/documentStore.d.ts +15 -13
  16. package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
  17. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  18. package/build/runtime/lib/config.d.ts +2 -2
  19. package/build/runtime/lib/scalars.d.ts +1 -1
  20. package/build/runtime/lib/types.d.ts +41 -42
  21. package/build/runtime-cjs/cache/storage.d.ts +18 -15
  22. package/build/runtime-cjs/cache/storage.js +9 -11
  23. package/build/runtime-cjs/client/documentStore.d.ts +15 -13
  24. package/build/runtime-cjs/client/documentStore.js +10 -7
  25. package/build/runtime-cjs/client/index.js +3 -0
  26. package/build/runtime-cjs/client/plugins/cache.js +3 -3
  27. package/build/runtime-cjs/client/plugins/fetch.js +2 -2
  28. package/build/runtime-cjs/client/plugins/query.js +1 -1
  29. package/build/runtime-cjs/client/plugins/subscription.js +2 -2
  30. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
  31. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  32. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  33. package/build/runtime-cjs/lib/config.d.ts +2 -2
  34. package/build/runtime-cjs/lib/config.js +11 -1
  35. package/build/runtime-cjs/lib/scalars.d.ts +1 -1
  36. package/build/runtime-cjs/lib/scalars.js +13 -2
  37. package/build/runtime-cjs/lib/types.d.ts +41 -42
  38. package/build/runtime-cjs/lib/types.js +26 -30
  39. package/build/runtime-esm/cache/storage.d.ts +18 -15
  40. package/build/runtime-esm/cache/storage.js +9 -11
  41. package/build/runtime-esm/client/documentStore.d.ts +15 -13
  42. package/build/runtime-esm/client/documentStore.js +10 -7
  43. package/build/runtime-esm/client/index.js +5 -2
  44. package/build/runtime-esm/client/plugins/cache.js +3 -3
  45. package/build/runtime-esm/client/plugins/fetch.js +2 -2
  46. package/build/runtime-esm/client/plugins/query.js +1 -1
  47. package/build/runtime-esm/client/plugins/subscription.js +2 -2
  48. package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
  49. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  50. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  51. package/build/runtime-esm/lib/config.d.ts +2 -2
  52. package/build/runtime-esm/lib/config.js +11 -1
  53. package/build/runtime-esm/lib/scalars.d.ts +1 -1
  54. package/build/runtime-esm/lib/scalars.js +13 -2
  55. package/build/runtime-esm/lib/types.d.ts +41 -42
  56. package/build/runtime-esm/lib/types.js +26 -30
  57. package/build/test-cjs/index.js +2346 -128
  58. package/build/test-esm/index.js +2346 -128
  59. package/build/vite/houdini.d.ts +2 -0
  60. package/build/vite-cjs/index.js +2371 -152
  61. package/build/vite-esm/index.js +2371 -152
  62. package/package.json +2 -2
@@ -16069,7 +16069,7 @@ var require_graceful_fs = __commonJS({
16069
16069
  gracefulQueue = "___graceful-fs.queue";
16070
16070
  previousSymbol = "___graceful-fs.previous";
16071
16071
  }
16072
- function noop2() {
16072
+ function noop3() {
16073
16073
  }
16074
16074
  function publishQueue(context, queue2) {
16075
16075
  Object.defineProperty(context, gracefulQueue, {
@@ -16078,7 +16078,7 @@ var require_graceful_fs = __commonJS({
16078
16078
  }
16079
16079
  });
16080
16080
  }
16081
- var debug = noop2;
16081
+ var debug = noop3;
16082
16082
  if (util.debuglog)
16083
16083
  debug = util.debuglog("gfs4");
16084
16084
  else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
@@ -20425,8 +20425,8 @@ var require_node = __commonJS({
20425
20425
  Node2.prototype.isSymlink = function() {
20426
20426
  return (this.mode & S_IFMT) === S_IFLNK;
20427
20427
  };
20428
- Node2.prototype.makeSymlink = function(steps) {
20429
- this.symlink = steps;
20428
+ Node2.prototype.makeSymlink = function(steps2) {
20429
+ this.symlink = steps2;
20430
20430
  this.setIsSymlink();
20431
20431
  };
20432
20432
  Node2.prototype.write = function(buf, off, len, pos) {
@@ -20643,22 +20643,22 @@ var require_node = __commonJS({
20643
20643
  Link2.prototype.getName = function() {
20644
20644
  return this.steps[this.steps.length - 1];
20645
20645
  };
20646
- Link2.prototype.walk = function(steps, stop, i2) {
20646
+ Link2.prototype.walk = function(steps2, stop, i2) {
20647
20647
  if (stop === void 0) {
20648
- stop = steps.length;
20648
+ stop = steps2.length;
20649
20649
  }
20650
20650
  if (i2 === void 0) {
20651
20651
  i2 = 0;
20652
20652
  }
20653
- if (i2 >= steps.length)
20653
+ if (i2 >= steps2.length)
20654
20654
  return this;
20655
20655
  if (i2 >= stop)
20656
20656
  return this;
20657
- var step = steps[i2];
20657
+ var step = steps2[i2];
20658
20658
  var link = this.getChild(step);
20659
20659
  if (!link)
20660
20660
  return null;
20661
- return link.walk(steps, stop, i2 + 1);
20661
+ return link.walk(steps2, stop, i2 + 1);
20662
20662
  };
20663
20663
  Link2.prototype.toJSON = function() {
20664
20664
  return {
@@ -20673,42 +20673,42 @@ var require_node = __commonJS({
20673
20673
  return Link2;
20674
20674
  }(events_1.EventEmitter);
20675
20675
  exports.Link = Link;
20676
- var File3 = function() {
20677
- function File4(link, node, flags, fd) {
20676
+ var File4 = function() {
20677
+ function File5(link, node, flags, fd) {
20678
20678
  this.position = 0;
20679
20679
  this.link = link;
20680
20680
  this.node = node;
20681
20681
  this.flags = flags;
20682
20682
  this.fd = fd;
20683
20683
  }
20684
- File4.prototype.getString = function(encoding) {
20684
+ File5.prototype.getString = function(encoding) {
20685
20685
  if (encoding === void 0) {
20686
20686
  encoding = "utf8";
20687
20687
  }
20688
20688
  return this.node.getString();
20689
20689
  };
20690
- File4.prototype.setString = function(str) {
20690
+ File5.prototype.setString = function(str) {
20691
20691
  this.node.setString(str);
20692
20692
  };
20693
- File4.prototype.getBuffer = function() {
20693
+ File5.prototype.getBuffer = function() {
20694
20694
  return this.node.getBuffer();
20695
20695
  };
20696
- File4.prototype.setBuffer = function(buf) {
20696
+ File5.prototype.setBuffer = function(buf) {
20697
20697
  this.node.setBuffer(buf);
20698
20698
  };
20699
- File4.prototype.getSize = function() {
20699
+ File5.prototype.getSize = function() {
20700
20700
  return this.node.getSize();
20701
20701
  };
20702
- File4.prototype.truncate = function(len) {
20702
+ File5.prototype.truncate = function(len) {
20703
20703
  this.node.truncate(len);
20704
20704
  };
20705
- File4.prototype.seekTo = function(position) {
20705
+ File5.prototype.seekTo = function(position) {
20706
20706
  this.position = position;
20707
20707
  };
20708
- File4.prototype.stats = function() {
20708
+ File5.prototype.stats = function() {
20709
20709
  return Stats_1.default.build(this.node);
20710
20710
  };
20711
- File4.prototype.write = function(buf, offset, length, position) {
20711
+ File5.prototype.write = function(buf, offset, length, position) {
20712
20712
  if (offset === void 0) {
20713
20713
  offset = 0;
20714
20714
  }
@@ -20723,7 +20723,7 @@ var require_node = __commonJS({
20723
20723
  this.position = position + bytes;
20724
20724
  return bytes;
20725
20725
  };
20726
- File4.prototype.read = function(buf, offset, length, position) {
20726
+ File5.prototype.read = function(buf, offset, length, position) {
20727
20727
  if (offset === void 0) {
20728
20728
  offset = 0;
20729
20729
  }
@@ -20736,15 +20736,15 @@ var require_node = __commonJS({
20736
20736
  this.position = position + bytes;
20737
20737
  return bytes;
20738
20738
  };
20739
- File4.prototype.chmod = function(perm) {
20739
+ File5.prototype.chmod = function(perm) {
20740
20740
  this.node.chmod(perm);
20741
20741
  };
20742
- File4.prototype.chown = function(uid, gid) {
20742
+ File5.prototype.chown = function(uid, gid) {
20743
20743
  this.node.chown(uid, gid);
20744
20744
  };
20745
- return File4;
20745
+ return File5;
20746
20746
  }();
20747
- exports.File = File3;
20747
+ exports.File = File4;
20748
20748
  }
20749
20749
  });
20750
20750
 
@@ -21430,20 +21430,20 @@ var require_volume = __commonJS({
21430
21430
  }
21431
21431
  function flattenJSON(nestedJSON) {
21432
21432
  var flatJSON = {};
21433
- function flatten(pathPrefix, node) {
21433
+ function flatten2(pathPrefix, node) {
21434
21434
  for (var path2 in node) {
21435
21435
  var contentOrNode = node[path2];
21436
21436
  var joinedPath = join3(pathPrefix, path2);
21437
21437
  if (typeof contentOrNode === "string") {
21438
21438
  flatJSON[joinedPath] = contentOrNode;
21439
21439
  } else if (typeof contentOrNode === "object" && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
21440
- flatten(joinedPath, contentOrNode);
21440
+ flatten2(joinedPath, contentOrNode);
21441
21441
  } else {
21442
21442
  flatJSON[joinedPath] = null;
21443
21443
  }
21444
21444
  }
21445
21445
  }
21446
- flatten("", nestedJSON);
21446
+ flatten2("", nestedJSON);
21447
21447
  return flatJSON;
21448
21448
  }
21449
21449
  var Volume = function() {
@@ -21581,28 +21581,28 @@ var require_volume = __commonJS({
21581
21581
  else
21582
21582
  return this.genRndStr();
21583
21583
  };
21584
- Volume2.prototype.getLink = function(steps) {
21585
- return this.root.walk(steps);
21584
+ Volume2.prototype.getLink = function(steps2) {
21585
+ return this.root.walk(steps2);
21586
21586
  };
21587
21587
  Volume2.prototype.getLinkOrThrow = function(filename, funcName) {
21588
- var steps = filenameToSteps(filename);
21589
- var link = this.getLink(steps);
21588
+ var steps2 = filenameToSteps(filename);
21589
+ var link = this.getLink(steps2);
21590
21590
  if (!link)
21591
21591
  throw createError(ENOENT, funcName, filename);
21592
21592
  return link;
21593
21593
  };
21594
21594
  Volume2.prototype.getResolvedLink = function(filenameOrSteps) {
21595
- var steps = typeof filenameOrSteps === "string" ? filenameToSteps(filenameOrSteps) : filenameOrSteps;
21595
+ var steps2 = typeof filenameOrSteps === "string" ? filenameToSteps(filenameOrSteps) : filenameOrSteps;
21596
21596
  var link = this.root;
21597
21597
  var i2 = 0;
21598
- while (i2 < steps.length) {
21599
- var step = steps[i2];
21598
+ while (i2 < steps2.length) {
21599
+ var step = steps2[i2];
21600
21600
  link = link.getChild(step);
21601
21601
  if (!link)
21602
21602
  return null;
21603
21603
  var node = link.getNode();
21604
21604
  if (node.isSymlink()) {
21605
- steps = node.symlink.concat(steps.slice(i2 + 1));
21605
+ steps2 = node.symlink.concat(steps2.slice(i2 + 1));
21606
21606
  link = this.root;
21607
21607
  i2 = 0;
21608
21608
  continue;
@@ -21626,16 +21626,16 @@ var require_volume = __commonJS({
21626
21626
  throw createError(ENOTDIR, funcName, filename);
21627
21627
  return link;
21628
21628
  };
21629
- Volume2.prototype.getLinkParent = function(steps) {
21630
- return this.root.walk(steps, steps.length - 1);
21629
+ Volume2.prototype.getLinkParent = function(steps2) {
21630
+ return this.root.walk(steps2, steps2.length - 1);
21631
21631
  };
21632
21632
  Volume2.prototype.getLinkParentAsDirOrThrow = function(filenameOrSteps, funcName) {
21633
- var steps = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps);
21634
- var link = this.getLinkParent(steps);
21633
+ var steps2 = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps);
21634
+ var link = this.getLinkParent(steps2);
21635
21635
  if (!link)
21636
- throw createError(ENOENT, funcName, sep2 + steps.join(sep2));
21636
+ throw createError(ENOENT, funcName, sep2 + steps2.join(sep2));
21637
21637
  if (!link.getNode().isDirectory())
21638
- throw createError(ENOTDIR, funcName, sep2 + steps.join(sep2));
21638
+ throw createError(ENOTDIR, funcName, sep2 + steps2.join(sep2));
21639
21639
  return link;
21640
21640
  };
21641
21641
  Volume2.prototype.getFileByFd = function(fd) {
@@ -21801,16 +21801,16 @@ var require_volume = __commonJS({
21801
21801
  if (resolveSymlinks === void 0) {
21802
21802
  resolveSymlinks = true;
21803
21803
  }
21804
- var steps = filenameToSteps(filename);
21805
- var link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps);
21804
+ var steps2 = filenameToSteps(filename);
21805
+ var link = resolveSymlinks ? this.getResolvedLink(steps2) : this.getLink(steps2);
21806
21806
  if (link && flagsNum & O_EXCL)
21807
21807
  throw createError(EEXIST, "open", filename);
21808
21808
  if (!link && flagsNum & O_CREAT) {
21809
- var dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1));
21809
+ var dirLink = this.getResolvedLink(steps2.slice(0, steps2.length - 1));
21810
21810
  if (!dirLink)
21811
- throw createError(ENOENT, "open", sep2 + steps.join(sep2));
21811
+ throw createError(ENOENT, "open", sep2 + steps2.join(sep2));
21812
21812
  if (flagsNum & O_CREAT && typeof modeNum === "number") {
21813
- link = this.createLink(dirLink, steps[steps.length - 1], false, modeNum);
21813
+ link = this.createLink(dirLink, steps2[steps2.length - 1], false, modeNum);
21814
21814
  }
21815
21815
  }
21816
21816
  if (link)
@@ -21909,8 +21909,8 @@ var require_volume = __commonJS({
21909
21909
  fd = id;
21910
21910
  else {
21911
21911
  var filename = pathToFilename(id);
21912
- var steps = filenameToSteps(filename);
21913
- var link = this.getResolvedLink(steps);
21912
+ var steps2 = filenameToSteps(filename);
21913
+ var link = this.getResolvedLink(steps2);
21914
21914
  if (link) {
21915
21915
  var node = link.getNode();
21916
21916
  if (node.isDirectory())
@@ -22133,8 +22133,8 @@ var require_volume = __commonJS({
22133
22133
  this.wrapAsync(this.linkBase, [existingPathFilename, newPathFilename], callback);
22134
22134
  };
22135
22135
  Volume2.prototype.unlinkBase = function(filename) {
22136
- var steps = filenameToSteps(filename);
22137
- var link = this.getLink(steps);
22136
+ var steps2 = filenameToSteps(filename);
22137
+ var link = this.getLink(steps2);
22138
22138
  if (!link)
22139
22139
  throw createError(ENOENT, "unlink", filename);
22140
22140
  if (link.length)
@@ -22178,8 +22178,8 @@ var require_volume = __commonJS({
22178
22178
  this.wrapAsync(this.symlinkBase, [targetFilename, pathFilename], callback);
22179
22179
  };
22180
22180
  Volume2.prototype.realpathBase = function(filename, encoding) {
22181
- var steps = filenameToSteps(filename);
22182
- var realLink = this.getResolvedLink(steps);
22181
+ var steps2 = filenameToSteps(filename);
22182
+ var realLink = this.getResolvedLink(steps2);
22183
22183
  if (!realLink)
22184
22184
  throw createError(ENOENT, "realpath", filename);
22185
22185
  return (0, encoding_1.strToEncoding)(realLink.getPath() || "/", encoding);
@@ -22345,8 +22345,8 @@ var require_volume = __commonJS({
22345
22345
  this.writeFile(id, data, opts, callback);
22346
22346
  };
22347
22347
  Volume2.prototype.readdirBase = function(filename, options) {
22348
- var steps = filenameToSteps(filename);
22349
- var link = this.getResolvedLink(steps);
22348
+ var steps2 = filenameToSteps(filename);
22349
+ var link = this.getResolvedLink(steps2);
22350
22350
  if (!link)
22351
22351
  throw createError(ENOENT, "readdir", filename);
22352
22352
  var node = link.getNode();
@@ -22484,12 +22484,12 @@ var require_volume = __commonJS({
22484
22484
  this.wrapAsync(this.utimesBase, [pathToFilename(path2), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback);
22485
22485
  };
22486
22486
  Volume2.prototype.mkdirBase = function(filename, modeNum) {
22487
- var steps = filenameToSteps(filename);
22488
- if (!steps.length) {
22487
+ var steps2 = filenameToSteps(filename);
22488
+ if (!steps2.length) {
22489
22489
  throw createError(EEXIST, "mkdir", filename);
22490
22490
  }
22491
22491
  var dir = this.getLinkParentAsDirOrThrow(filename, "mkdir");
22492
- var name = steps[steps.length - 1];
22492
+ var name = steps2[steps2.length - 1];
22493
22493
  if (dir.getChild(name))
22494
22494
  throw createError(EEXIST, "mkdir", filename);
22495
22495
  dir.createChild(name, this.createNode(true, modeNum));
@@ -22497,11 +22497,11 @@ var require_volume = __commonJS({
22497
22497
  Volume2.prototype.mkdirpBase = function(filename, modeNum) {
22498
22498
  var fullPath = resolve2(filename);
22499
22499
  var fullPathSansSlash = fullPath.substring(1);
22500
- var steps = !fullPathSansSlash ? [] : fullPathSansSlash.split(sep2);
22500
+ var steps2 = !fullPathSansSlash ? [] : fullPathSansSlash.split(sep2);
22501
22501
  var link = this.root;
22502
22502
  var created = false;
22503
- for (var i2 = 0; i2 < steps.length; i2++) {
22504
- var step = steps[i2];
22503
+ for (var i2 = 0; i2 < steps2.length; i2++) {
22504
+ var step = steps2[i2];
22505
22505
  if (!link.getNode().isDirectory())
22506
22506
  throw createError(ENOTDIR, "mkdir", link.getPath());
22507
22507
  var child = link.getChild(step);
@@ -23248,7 +23248,7 @@ var require_ponyfill_es2018 = __commonJS({
23248
23248
  })(exports, function(exports2) {
23249
23249
  "use strict";
23250
23250
  const SymbolPolyfill = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? Symbol : (description) => `Symbol(${description})`;
23251
- function noop2() {
23251
+ function noop3() {
23252
23252
  return void 0;
23253
23253
  }
23254
23254
  function getGlobals() {
@@ -23265,7 +23265,7 @@ var require_ponyfill_es2018 = __commonJS({
23265
23265
  function typeIsObject(x2) {
23266
23266
  return typeof x2 === "object" && x2 !== null || typeof x2 === "function";
23267
23267
  }
23268
- const rethrowAssertionErrorRejection = noop2;
23268
+ const rethrowAssertionErrorRejection = noop3;
23269
23269
  const originalPromise = Promise;
23270
23270
  const originalPromiseThen = Promise.prototype.then;
23271
23271
  const originalPromiseResolve = Promise.resolve.bind(originalPromise);
@@ -25474,7 +25474,7 @@ var require_ponyfill_es2018 = __commonJS({
25474
25474
  return newPromise((resolveRead, rejectRead) => {
25475
25475
  ReadableStreamDefaultReaderRead(reader, {
25476
25476
  _chunkSteps: (chunk) => {
25477
- currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop2);
25477
+ currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop3);
25478
25478
  resolveRead(false);
25479
25479
  },
25480
25480
  _closeSteps: () => resolveRead(true),
@@ -26369,7 +26369,7 @@ var require_ponyfill_es2018 = __commonJS({
26369
26369
  reader._readIntoRequests = new SimpleQueue();
26370
26370
  }
26371
26371
  const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
26372
- return transformPromiseWith(sourceCancelPromise, noop2);
26372
+ return transformPromiseWith(sourceCancelPromise, noop3);
26373
26373
  }
26374
26374
  function ReadableStreamClose(stream) {
26375
26375
  stream._state = "closed";
@@ -26853,9 +26853,9 @@ var require_streams = __commonJS({
26853
26853
  }
26854
26854
  }
26855
26855
  try {
26856
- const { Blob: Blob3 } = __require("buffer");
26857
- if (Blob3 && !Blob3.prototype.stream) {
26858
- Blob3.prototype.stream = function name(params) {
26856
+ const { Blob: Blob4 } = __require("buffer");
26857
+ if (Blob4 && !Blob4.prototype.stream) {
26858
+ Blob4.prototype.stream = function name(params) {
26859
26859
  let position = 0;
26860
26860
  const blob = this;
26861
26861
  return new ReadableStream({
@@ -26906,12 +26906,12 @@ async function* toIterator(parts, clone2 = true) {
26906
26906
  }
26907
26907
  }
26908
26908
  }
26909
- var import_streams, POOL_SIZE, _Blob, Blob2, fetch_blob_default;
26909
+ var import_streams, POOL_SIZE, _Blob, Blob3, fetch_blob_default;
26910
26910
  var init_fetch_blob = __esm({
26911
26911
  "../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/index.js"() {
26912
26912
  import_streams = __toESM(require_streams(), 1);
26913
26913
  POOL_SIZE = 65536;
26914
- _Blob = class Blob {
26914
+ _Blob = class Blob2 {
26915
26915
  #parts = [];
26916
26916
  #type = "";
26917
26917
  #size = 0;
@@ -26935,7 +26935,7 @@ var init_fetch_blob = __esm({
26935
26935
  part = new Uint8Array(element.buffer.slice(element.byteOffset, element.byteOffset + element.byteLength));
26936
26936
  } else if (element instanceof ArrayBuffer) {
26937
26937
  part = new Uint8Array(element.slice(0));
26938
- } else if (element instanceof Blob) {
26938
+ } else if (element instanceof Blob2) {
26939
26939
  part = element;
26940
26940
  } else {
26941
26941
  part = encoder.encode(`${element}`);
@@ -27014,7 +27014,7 @@ var init_fetch_blob = __esm({
27014
27014
  relativeStart = 0;
27015
27015
  }
27016
27016
  }
27017
- const blob = new Blob([], { type: String(type).toLowerCase() });
27017
+ const blob = new Blob2([], { type: String(type).toLowerCase() });
27018
27018
  blob.#size = span;
27019
27019
  blob.#parts = blobParts;
27020
27020
  return blob;
@@ -27031,17 +27031,17 @@ var init_fetch_blob = __esm({
27031
27031
  type: { enumerable: true },
27032
27032
  slice: { enumerable: true }
27033
27033
  });
27034
- Blob2 = _Blob;
27035
- fetch_blob_default = Blob2;
27034
+ Blob3 = _Blob;
27035
+ fetch_blob_default = Blob3;
27036
27036
  }
27037
27037
  });
27038
27038
 
27039
27039
  // ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js
27040
- var _File, File2, file_default;
27040
+ var _File, File3, file_default;
27041
27041
  var init_file = __esm({
27042
27042
  "../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js"() {
27043
27043
  init_fetch_blob();
27044
- _File = class File extends fetch_blob_default {
27044
+ _File = class File2 extends fetch_blob_default {
27045
27045
  #lastModified = 0;
27046
27046
  #name = "";
27047
27047
  constructor(fileBits, fileName, options = {}) {
@@ -27070,8 +27070,8 @@ var init_file = __esm({
27070
27070
  return !!object && object instanceof fetch_blob_default && /^(File)$/.test(object[Symbol.toStringTag]);
27071
27071
  }
27072
27072
  };
27073
- File2 = _File;
27074
- file_default = File2;
27073
+ File3 = _File;
27074
+ file_default = File3;
27075
27075
  }
27076
27076
  });
27077
27077
 
@@ -27089,7 +27089,7 @@ Content-Type: ${v.type || "application/octet-stream"}\r
27089
27089
  c.push(`--${b}--`);
27090
27090
  return new B(c, { type: "multipart/form-data; boundary=" + b });
27091
27091
  }
27092
- var t, i, h, r, m, f, e, x, FormData;
27092
+ var t, i, h, r, m, f, e, x, FormData2;
27093
27093
  var init_esm_min = __esm({
27094
27094
  "../../node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js"() {
27095
27095
  init_fetch_blob();
@@ -27104,7 +27104,7 @@ var init_esm_min = __esm({
27104
27104
  throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e2} arguments required, but only ${a.length} present.`);
27105
27105
  }
27106
27106
  };
27107
- FormData = class FormData2 {
27107
+ FormData2 = class FormData3 {
27108
27108
  #d = [];
27109
27109
  constructor(...a) {
27110
27110
  if (a.length)
@@ -27270,7 +27270,7 @@ async function toFormData(Body2, ct) {
27270
27270
  let contentType;
27271
27271
  let filename;
27272
27272
  const entryChunks = [];
27273
- const formData = new FormData();
27273
+ const formData = new FormData2();
27274
27274
  const onPartData = (ui8a) => {
27275
27275
  entryValue += decoder.decode(ui8a, { stream: true });
27276
27276
  };
@@ -27328,7 +27328,7 @@ async function toFormData(Body2, ct) {
27328
27328
  parser.end();
27329
27329
  return formData;
27330
27330
  }
27331
- var s, S, f2, F, LF, CR, SPACE, HYPHEN, COLON, A, Z, lower, noop, MultipartParser;
27331
+ var s, S, f2, F, LF, CR, SPACE, HYPHEN, COLON, A, Z, lower, noop2, MultipartParser;
27332
27332
  var init_multipart_parser = __esm({
27333
27333
  "../../node_modules/.pnpm/node-fetch@3.3.0/node_modules/node-fetch/src/utils/multipart-parser.js"() {
27334
27334
  init_from();
@@ -27359,19 +27359,19 @@ var init_multipart_parser = __esm({
27359
27359
  A = 97;
27360
27360
  Z = 122;
27361
27361
  lower = (c) => c | 32;
27362
- noop = () => {
27362
+ noop2 = () => {
27363
27363
  };
27364
27364
  MultipartParser = class {
27365
27365
  constructor(boundary) {
27366
27366
  this.index = 0;
27367
27367
  this.flags = 0;
27368
- this.onHeaderEnd = noop;
27369
- this.onHeaderField = noop;
27370
- this.onHeadersEnd = noop;
27371
- this.onHeaderValue = noop;
27372
- this.onPartBegin = noop;
27373
- this.onPartData = noop;
27374
- this.onPartEnd = noop;
27368
+ this.onHeaderEnd = noop2;
27369
+ this.onHeaderField = noop2;
27370
+ this.onHeadersEnd = noop2;
27371
+ this.onHeaderValue = noop2;
27372
+ this.onPartBegin = noop2;
27373
+ this.onPartData = noop2;
27374
+ this.onPartEnd = noop2;
27375
27375
  this.boundaryChars = {};
27376
27376
  boundary = "\r\n--" + boundary;
27377
27377
  const ui8a = new Uint8Array(boundary.length);
@@ -37684,11 +37684,11 @@ var require_lib3 = __commonJS({
37684
37684
  return this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors);
37685
37685
  }
37686
37686
  };
37687
- function hasPlugin(plugins, expectedConfig) {
37687
+ function hasPlugin(plugins2, expectedConfig) {
37688
37688
  const [expectedName, expectedOptions] = typeof expectedConfig === "string" ? [expectedConfig, {}] : expectedConfig;
37689
37689
  const expectedKeys = Object.keys(expectedOptions);
37690
37690
  const expectedOptionsIsEmpty = expectedKeys.length === 0;
37691
- return plugins.some((p) => {
37691
+ return plugins2.some((p) => {
37692
37692
  if (typeof p === "string") {
37693
37693
  return expectedOptionsIsEmpty && p === expectedName;
37694
37694
  } else {
@@ -37705,8 +37705,8 @@ var require_lib3 = __commonJS({
37705
37705
  }
37706
37706
  });
37707
37707
  }
37708
- function getPluginOption(plugins, name, option) {
37709
- const plugin2 = plugins.find((plugin3) => {
37708
+ function getPluginOption(plugins2, name, option) {
37709
+ const plugin2 = plugins2.find((plugin3) => {
37710
37710
  if (Array.isArray(plugin3)) {
37711
37711
  return plugin3[0] === name;
37712
37712
  } else {
@@ -37721,43 +37721,43 @@ var require_lib3 = __commonJS({
37721
37721
  var PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack", "smart"];
37722
37722
  var TOPIC_TOKENS = ["^^", "@@", "^", "%", "#"];
37723
37723
  var RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];
37724
- function validatePlugins(plugins) {
37725
- if (hasPlugin(plugins, "decorators")) {
37726
- if (hasPlugin(plugins, "decorators-legacy")) {
37724
+ function validatePlugins(plugins2) {
37725
+ if (hasPlugin(plugins2, "decorators")) {
37726
+ if (hasPlugin(plugins2, "decorators-legacy")) {
37727
37727
  throw new Error("Cannot use the decorators and decorators-legacy plugin together");
37728
37728
  }
37729
- const decoratorsBeforeExport = getPluginOption(plugins, "decorators", "decoratorsBeforeExport");
37729
+ const decoratorsBeforeExport = getPluginOption(plugins2, "decorators", "decoratorsBeforeExport");
37730
37730
  if (decoratorsBeforeExport != null && typeof decoratorsBeforeExport !== "boolean") {
37731
37731
  throw new Error("'decoratorsBeforeExport' must be a boolean.");
37732
37732
  }
37733
- const allowCallParenthesized = getPluginOption(plugins, "decorators", "allowCallParenthesized");
37733
+ const allowCallParenthesized = getPluginOption(plugins2, "decorators", "allowCallParenthesized");
37734
37734
  if (allowCallParenthesized != null && typeof allowCallParenthesized !== "boolean") {
37735
37735
  throw new Error("'allowCallParenthesized' must be a boolean.");
37736
37736
  }
37737
37737
  }
37738
- if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
37738
+ if (hasPlugin(plugins2, "flow") && hasPlugin(plugins2, "typescript")) {
37739
37739
  throw new Error("Cannot combine flow and typescript plugins.");
37740
37740
  }
37741
- if (hasPlugin(plugins, "placeholders") && hasPlugin(plugins, "v8intrinsic")) {
37741
+ if (hasPlugin(plugins2, "placeholders") && hasPlugin(plugins2, "v8intrinsic")) {
37742
37742
  throw new Error("Cannot combine placeholders and v8intrinsic plugins.");
37743
37743
  }
37744
- if (hasPlugin(plugins, "pipelineOperator")) {
37745
- const proposal = getPluginOption(plugins, "pipelineOperator", "proposal");
37744
+ if (hasPlugin(plugins2, "pipelineOperator")) {
37745
+ const proposal = getPluginOption(plugins2, "pipelineOperator", "proposal");
37746
37746
  if (!PIPELINE_PROPOSALS.includes(proposal)) {
37747
37747
  const proposalList = PIPELINE_PROPOSALS.map((p) => `"${p}"`).join(", ");
37748
37748
  throw new Error(`"pipelineOperator" requires "proposal" option whose value must be one of: ${proposalList}.`);
37749
37749
  }
37750
- const tupleSyntaxIsHash = hasPlugin(plugins, ["recordAndTuple", {
37750
+ const tupleSyntaxIsHash = hasPlugin(plugins2, ["recordAndTuple", {
37751
37751
  syntaxType: "hash"
37752
37752
  }]);
37753
37753
  if (proposal === "hack") {
37754
- if (hasPlugin(plugins, "placeholders")) {
37754
+ if (hasPlugin(plugins2, "placeholders")) {
37755
37755
  throw new Error("Cannot combine placeholders plugin and Hack-style pipes.");
37756
37756
  }
37757
- if (hasPlugin(plugins, "v8intrinsic")) {
37757
+ if (hasPlugin(plugins2, "v8intrinsic")) {
37758
37758
  throw new Error("Cannot combine v8intrinsic plugin and Hack-style pipes.");
37759
37759
  }
37760
- const topicToken = getPluginOption(plugins, "pipelineOperator", "topicToken");
37760
+ const topicToken = getPluginOption(plugins2, "pipelineOperator", "topicToken");
37761
37761
  if (!TOPIC_TOKENS.includes(topicToken)) {
37762
37762
  const tokenList = TOPIC_TOKENS.map((t2) => `"${t2}"`).join(", ");
37763
37763
  throw new Error(`"pipelineOperator" in "proposal": "hack" mode also requires a "topicToken" option whose value must be one of: ${tokenList}.`);
@@ -37769,21 +37769,21 @@ var require_lib3 = __commonJS({
37769
37769
  throw new Error('Plugin conflict between `["pipelineOperator", { proposal: "smart" }]` and `["recordAndtuple", { syntaxType: "hash"}]`.');
37770
37770
  }
37771
37771
  }
37772
- if (hasPlugin(plugins, "moduleAttributes")) {
37772
+ if (hasPlugin(plugins2, "moduleAttributes")) {
37773
37773
  {
37774
- if (hasPlugin(plugins, "importAssertions")) {
37774
+ if (hasPlugin(plugins2, "importAssertions")) {
37775
37775
  throw new Error("Cannot combine importAssertions and moduleAttributes plugins.");
37776
37776
  }
37777
- const moduleAttributesVersionPluginOption = getPluginOption(plugins, "moduleAttributes", "version");
37777
+ const moduleAttributesVersionPluginOption = getPluginOption(plugins2, "moduleAttributes", "version");
37778
37778
  if (moduleAttributesVersionPluginOption !== "may-2020") {
37779
37779
  throw new Error("The 'moduleAttributes' plugin requires a 'version' option, representing the last proposal update. Currently, the only supported value is 'may-2020'.");
37780
37780
  }
37781
37781
  }
37782
37782
  }
37783
- if (hasPlugin(plugins, "recordAndTuple") && getPluginOption(plugins, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins, "recordAndTuple", "syntaxType"))) {
37783
+ if (hasPlugin(plugins2, "recordAndTuple") && getPluginOption(plugins2, "recordAndTuple", "syntaxType") != null && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes(getPluginOption(plugins2, "recordAndTuple", "syntaxType"))) {
37784
37784
  throw new Error("The 'syntaxType' option of the 'recordAndTuple' plugin must be one of: " + RECORD_AND_TUPLE_SYNTAX_TYPES.map((p) => `'${p}'`).join(", "));
37785
37785
  }
37786
- if (hasPlugin(plugins, "asyncDoExpressions") && !hasPlugin(plugins, "doExpressions")) {
37786
+ if (hasPlugin(plugins2, "asyncDoExpressions") && !hasPlugin(plugins2, "doExpressions")) {
37787
37787
  const error = new Error("'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.");
37788
37788
  error.missingPlugins = "doExpressions";
37789
37789
  throw error;
@@ -42042,9 +42042,9 @@ var require_lib3 = __commonJS({
42042
42042
  return file;
42043
42043
  }
42044
42044
  };
42045
- function pluginsMap(plugins) {
42045
+ function pluginsMap(plugins2) {
42046
42046
  const pluginMap = /* @__PURE__ */ new Map();
42047
- for (const plugin2 of plugins) {
42047
+ for (const plugin2 of plugins2) {
42048
42048
  const [name, options] = Array.isArray(plugin2) ? plugin2 : [plugin2, {}];
42049
42049
  if (!pluginMap.has(name))
42050
42050
  pluginMap.set(name, options || {});
@@ -44715,10 +44715,10 @@ var require_fork = __commonJS({
44715
44715
  var path_1 = tslib_1.__importDefault(require_path2());
44716
44716
  var node_path_1 = tslib_1.__importDefault(require_node_path());
44717
44717
  var shared_1 = require_shared();
44718
- function default_1(plugins) {
44718
+ function default_1(plugins2) {
44719
44719
  var fork = createFork();
44720
44720
  var types4 = fork.use(types_1.default);
44721
- plugins.forEach(fork.use);
44721
+ plugins2.forEach(fork.use);
44722
44722
  types4.finalize();
44723
44723
  var PathVisitor = fork.use(path_visitor_1.default);
44724
44724
  return {
@@ -61523,6 +61523,10 @@ import { fileURLToPath, pathToFileURL } from "node:url";
61523
61523
  // src/runtime/imports/config.ts
61524
61524
  var config_default = {};
61525
61525
 
61526
+ // src/runtime/imports/pluginConfig.ts
61527
+ var configs = [];
61528
+ var pluginConfig_default = configs;
61529
+
61526
61530
  // src/runtime/lib/config.ts
61527
61531
  var mockConfig = null;
61528
61532
  function getMockConfig() {
@@ -61558,45 +61562,284 @@ function computeID(configFile, type, data) {
61558
61562
  }
61559
61563
  return id.slice(0, -2);
61560
61564
  }
61565
+ var _configFile = null;
61561
61566
  function getCurrentConfig() {
61562
61567
  const mockConfig2 = getMockConfig();
61563
61568
  if (mockConfig2) {
61564
61569
  return mockConfig2;
61565
61570
  }
61566
- return defaultConfigValues(config_default);
61571
+ if (_configFile) {
61572
+ return _configFile;
61573
+ }
61574
+ let configFile = defaultConfigValues(config_default);
61575
+ for (const pluginConfig of pluginConfig_default) {
61576
+ configFile = pluginConfig(configFile);
61577
+ }
61578
+ _configFile = configFile;
61579
+ return configFile;
61580
+ }
61581
+
61582
+ // src/runtime/lib/deepEquals.ts
61583
+ function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
61584
+ if (Object.is(objA, objB))
61585
+ return true;
61586
+ if (objA instanceof Date && objB instanceof Date) {
61587
+ return objA.getTime() === objB.getTime();
61588
+ }
61589
+ if (objA instanceof RegExp && objB instanceof RegExp) {
61590
+ return objA.toString() === objB.toString();
61591
+ }
61592
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
61593
+ return false;
61594
+ }
61595
+ if (map.get(objA) === objB)
61596
+ return true;
61597
+ map.set(objA, objB);
61598
+ const keysA = Reflect.ownKeys(objA);
61599
+ const keysB = Reflect.ownKeys(objB);
61600
+ if (keysA.length !== keysB.length) {
61601
+ return false;
61602
+ }
61603
+ for (let i2 = 0; i2 < keysA.length; i2++) {
61604
+ if (!Reflect.has(objB, keysA[i2]) || !deepEquals(objA[keysA[i2]], objB[keysA[i2]], map)) {
61605
+ return false;
61606
+ }
61607
+ }
61608
+ return true;
61609
+ }
61610
+
61611
+ // src/runtime/lib/selection.ts
61612
+ function getFieldsForType(selection, __typename) {
61613
+ let targetSelection = selection.fields || {};
61614
+ if (selection.abstractFields && __typename) {
61615
+ const mappedType = selection.abstractFields.typeMap[__typename];
61616
+ if (mappedType) {
61617
+ targetSelection = selection.abstractFields.fields[mappedType];
61618
+ } else if (selection.abstractFields.fields[__typename]) {
61619
+ targetSelection = selection.abstractFields.fields[__typename];
61620
+ }
61621
+ }
61622
+ return targetSelection;
61623
+ }
61624
+
61625
+ // src/runtime/lib/scalars.ts
61626
+ async function marshalSelection({
61627
+ selection,
61628
+ data
61629
+ }) {
61630
+ const config = getCurrentConfig();
61631
+ if (data === null || typeof data === "undefined") {
61632
+ return data;
61633
+ }
61634
+ if (Array.isArray(data)) {
61635
+ return await Promise.all(data.map((val) => marshalSelection({ selection, data: val })));
61636
+ }
61637
+ const targetSelection = getFieldsForType(selection, data["__typename"]);
61638
+ return Object.fromEntries(
61639
+ await Promise.all(
61640
+ Object.entries(data).map(async ([fieldName, value]) => {
61641
+ const { type, selection: selection2 } = targetSelection[fieldName];
61642
+ if (!type) {
61643
+ return [fieldName, value];
61644
+ }
61645
+ if (selection2) {
61646
+ return [fieldName, await marshalSelection({ selection: selection2, data: value })];
61647
+ }
61648
+ if (config.scalars?.[type]) {
61649
+ const marshalFn = config.scalars[type].marshal;
61650
+ if (!marshalFn) {
61651
+ throw new Error(
61652
+ `scalar type ${type} is missing a \`marshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
61653
+ );
61654
+ }
61655
+ if (Array.isArray(value)) {
61656
+ return [fieldName, value.map(marshalFn)];
61657
+ }
61658
+ return [fieldName, marshalFn(value)];
61659
+ }
61660
+ return [fieldName, value];
61661
+ })
61662
+ )
61663
+ );
61664
+ }
61665
+ function marshalInputs({
61666
+ artifact,
61667
+ input,
61668
+ config,
61669
+ rootType = "@root"
61670
+ }) {
61671
+ if (input === null || typeof input === "undefined") {
61672
+ return input;
61673
+ }
61674
+ if (!artifact.input) {
61675
+ return input;
61676
+ }
61677
+ const fields = rootType === "@root" ? artifact.input.fields : artifact.input.types[rootType];
61678
+ if (Array.isArray(input)) {
61679
+ return input.map((val) => marshalInputs({ artifact, input: val, rootType, config }));
61680
+ }
61681
+ return Object.fromEntries(
61682
+ Object.entries(input).map(([fieldName, value]) => {
61683
+ const type = fields?.[fieldName];
61684
+ if (!type) {
61685
+ return [fieldName, value];
61686
+ }
61687
+ const marshalFn = config.scalars?.[type]?.marshal;
61688
+ if (marshalFn) {
61689
+ if (Array.isArray(value)) {
61690
+ return [fieldName, value.map(marshalFn)];
61691
+ }
61692
+ return [fieldName, marshalFn(value)];
61693
+ }
61694
+ if (isScalar(config, type) || !artifact.input.types[type]) {
61695
+ return [fieldName, value];
61696
+ }
61697
+ return [fieldName, marshalInputs({ artifact, input: value, rootType: type, config })];
61698
+ })
61699
+ );
61700
+ }
61701
+ function unmarshalSelection(config, selection, data) {
61702
+ if (data === null || typeof data === "undefined") {
61703
+ return data;
61704
+ }
61705
+ if (Array.isArray(data)) {
61706
+ return data.map((val) => unmarshalSelection(config, selection, val));
61707
+ }
61708
+ const targetSelection = getFieldsForType(selection, data["__typename"]);
61709
+ return Object.fromEntries(
61710
+ Object.entries(data).map(([fieldName, value]) => {
61711
+ const { type, selection: selection2 } = targetSelection[fieldName];
61712
+ if (!type) {
61713
+ return [fieldName, value];
61714
+ }
61715
+ if (selection2) {
61716
+ return [
61717
+ fieldName,
61718
+ unmarshalSelection(config, selection2, value)
61719
+ ];
61720
+ }
61721
+ if (value === null) {
61722
+ return [fieldName, value];
61723
+ }
61724
+ if (config.scalars?.[type]?.marshal) {
61725
+ const unmarshalFn = config.scalars[type]?.unmarshal;
61726
+ if (!unmarshalFn) {
61727
+ throw new Error(
61728
+ `scalar type ${type} is missing an \`unmarshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
61729
+ );
61730
+ }
61731
+ if (Array.isArray(value)) {
61732
+ return [fieldName, value.map(unmarshalFn)];
61733
+ }
61734
+ return [fieldName, unmarshalFn(value)];
61735
+ }
61736
+ return [fieldName, value];
61737
+ })
61738
+ );
61739
+ }
61740
+ function isScalar(config, type) {
61741
+ return ["String", "Boolean", "Float", "ID", "Int"].concat(Object.keys(config.scalars || {})).includes(type);
61567
61742
  }
61568
61743
 
61569
61744
  // src/runtime/lib/types.ts
61570
- var CachePolicy = /* @__PURE__ */ ((CachePolicy2) => {
61571
- CachePolicy2["CacheOrNetwork"] = "CacheOrNetwork";
61572
- CachePolicy2["CacheOnly"] = "CacheOnly";
61573
- CachePolicy2["NetworkOnly"] = "NetworkOnly";
61574
- CachePolicy2["CacheAndNetwork"] = "CacheAndNetwork";
61575
- return CachePolicy2;
61576
- })(CachePolicy || {});
61577
- var ArtifactKind = /* @__PURE__ */ ((ArtifactKind2) => {
61578
- ArtifactKind2["Query"] = "HoudiniQuery";
61579
- ArtifactKind2["Subscription"] = "HoudiniSubscription";
61580
- ArtifactKind2["Mutation"] = "HoudiniMutation";
61581
- ArtifactKind2["Fragment"] = "HoudiniFragment";
61582
- return ArtifactKind2;
61583
- })(ArtifactKind || {});
61584
- var CompiledFragmentKind = "HoudiniFragment" /* Fragment */;
61585
- var CompiledMutationKind = "HoudiniMutation" /* Mutation */;
61586
- var CompiledQueryKind = "HoudiniQuery" /* Query */;
61587
- var CompiledSubscriptionKind = "HoudiniSubscription" /* Subscription */;
61588
- var RefetchUpdateMode = /* @__PURE__ */ ((RefetchUpdateMode2) => {
61589
- RefetchUpdateMode2["append"] = "append";
61590
- RefetchUpdateMode2["prepend"] = "prepend";
61591
- RefetchUpdateMode2["replace"] = "replace";
61592
- return RefetchUpdateMode2;
61593
- })(RefetchUpdateMode || {});
61594
- var DataSource = /* @__PURE__ */ ((DataSource2) => {
61595
- DataSource2["Cache"] = "cache";
61596
- DataSource2["Network"] = "network";
61597
- DataSource2["Ssr"] = "ssr";
61598
- return DataSource2;
61599
- })(DataSource || {});
61745
+ var CachePolicy = {
61746
+ CacheOrNetwork: "CacheOrNetwork",
61747
+ CacheOnly: "CacheOnly",
61748
+ NetworkOnly: "NetworkOnly",
61749
+ CacheAndNetwork: "CacheAndNetwork"
61750
+ };
61751
+ var ArtifactKind = {
61752
+ Query: "HoudiniQuery",
61753
+ Subscription: "HoudiniSubscription",
61754
+ Mutation: "HoudiniMutation",
61755
+ Fragment: "HoudiniFragment"
61756
+ };
61757
+ var CompiledFragmentKind = ArtifactKind.Fragment;
61758
+ var CompiledMutationKind = ArtifactKind.Mutation;
61759
+ var CompiledQueryKind = ArtifactKind.Query;
61760
+ var CompiledSubscriptionKind = ArtifactKind.Subscription;
61761
+ var RefetchUpdateMode = {
61762
+ append: "append",
61763
+ prepend: "prepend",
61764
+ replace: "replace"
61765
+ };
61766
+ var DataSource = {
61767
+ Cache: "cache",
61768
+ Network: "network",
61769
+ Ssr: "ssr"
61770
+ };
61771
+
61772
+ // src/runtime/lib/store.ts
61773
+ var subscriber_queue = [];
61774
+ var noop = () => {
61775
+ };
61776
+ var Writable = class {
61777
+ state;
61778
+ #subscribers;
61779
+ #stop;
61780
+ #start;
61781
+ constructor(value, start = noop) {
61782
+ this.state = value;
61783
+ this.#subscribers = /* @__PURE__ */ new Set();
61784
+ this.#stop = null;
61785
+ this.#start = start;
61786
+ }
61787
+ set(new_value) {
61788
+ if (safe_not_equal(this.state, new_value)) {
61789
+ this.state = new_value;
61790
+ if (this.#stop) {
61791
+ const run_queue = !subscriber_queue.length;
61792
+ for (const subscriber of this.#subscribers) {
61793
+ subscriber[1]();
61794
+ subscriber_queue.push(subscriber, this.state);
61795
+ }
61796
+ if (run_queue) {
61797
+ for (let i2 = 0; i2 < subscriber_queue.length; i2 += 2) {
61798
+ subscriber_queue[i2][0](subscriber_queue[i2 + 1]);
61799
+ }
61800
+ subscriber_queue.length = 0;
61801
+ }
61802
+ }
61803
+ }
61804
+ }
61805
+ update(fn) {
61806
+ this.set(fn(this.state));
61807
+ }
61808
+ subscribe(run, invalidate = noop) {
61809
+ const subscriber = [run, invalidate];
61810
+ this.#subscribers.add(subscriber);
61811
+ if (this.#subscribers.size === 1) {
61812
+ this.#stop = this.#start(this.set) || noop;
61813
+ }
61814
+ run(this.state);
61815
+ return () => {
61816
+ this.#subscribers.delete(subscriber);
61817
+ if (this.#subscribers.size === 0) {
61818
+ this.#stop?.();
61819
+ this.#stop = null;
61820
+ }
61821
+ };
61822
+ }
61823
+ };
61824
+ function safe_not_equal(a, b) {
61825
+ return a != a ? b == b : a !== b || a && typeof a === "object" || typeof a === "function";
61826
+ }
61827
+
61828
+ // src/runtime/lib/key.ts
61829
+ var computeKey = ({ field, args }) => {
61830
+ const keys = Object.keys(args ?? {});
61831
+ keys.sort();
61832
+ return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
61833
+ };
61834
+ var stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
61835
+ if (Array.isArray(obj_from_json)) {
61836
+ return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
61837
+ }
61838
+ if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
61839
+ return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
61840
+ }
61841
+ return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
61842
+ };
61600
61843
 
61601
61844
  // src/lib/constants.ts
61602
61845
  var siteURL = "https://houdinigraphql.com";
@@ -62042,7 +62285,7 @@ var Body = class {
62042
62285
  } else if (ArrayBuffer.isView(body)) {
62043
62286
  body = Buffer2.from(body.buffer, body.byteOffset, body.byteLength);
62044
62287
  } else if (body instanceof Stream) {
62045
- } else if (body instanceof FormData) {
62288
+ } else if (body instanceof FormData2) {
62046
62289
  body = formDataToBlob(body);
62047
62290
  boundary = body.type.split("=")[1];
62048
62291
  } else {
@@ -62082,7 +62325,7 @@ var Body = class {
62082
62325
  async formData() {
62083
62326
  const ct = this.headers.get("content-type");
62084
62327
  if (ct.startsWith("application/x-www-form-urlencoded")) {
62085
- const formData = new FormData();
62328
+ const formData = new FormData2();
62086
62329
  const parameters = new URLSearchParams(await this.text());
62087
62330
  for (const [name, value] of parameters) {
62088
62331
  formData.append(name, value);
@@ -62208,7 +62451,7 @@ var extractContentType = (body, request) => {
62208
62451
  if (Buffer2.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
62209
62452
  return null;
62210
62453
  }
62211
- if (body instanceof FormData) {
62454
+ if (body instanceof FormData2) {
62212
62455
  return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
62213
62456
  }
62214
62457
  if (body && typeof body.getBoundary === "function") {
@@ -63175,14 +63418,2735 @@ function plugin(name, hooks) {
63175
63418
  return data;
63176
63419
  }
63177
63420
 
63421
+ // src/runtime/lib/flatten.ts
63422
+ function flatten(source) {
63423
+ if (!source) {
63424
+ return [];
63425
+ }
63426
+ return source.reduce((acc, element) => {
63427
+ if (!element) {
63428
+ return acc;
63429
+ }
63430
+ if (Array.isArray(element)) {
63431
+ return acc.concat(flatten(element));
63432
+ }
63433
+ return acc.concat(element);
63434
+ }, []);
63435
+ }
63436
+
63437
+ // src/runtime/client/plugins/fetch.ts
63438
+ var fetch2 = (target) => {
63439
+ return () => {
63440
+ return {
63441
+ async network(ctx, { client, resolve: resolve2, marshalVariables: marshalVariables2 }) {
63442
+ const fetch3 = ctx.fetch ?? globalThis.fetch;
63443
+ const fetchParams2 = {
63444
+ text: ctx.text,
63445
+ hash: ctx.hash,
63446
+ variables: marshalVariables2(ctx)
63447
+ };
63448
+ let fetchFn = defaultFetch(client.url, ctx.fetchParams);
63449
+ if (target) {
63450
+ if (typeof target === "string") {
63451
+ fetchFn = defaultFetch(target, ctx.fetchParams);
63452
+ } else {
63453
+ fetchFn = target;
63454
+ }
63455
+ }
63456
+ const result = await fetchFn({
63457
+ fetch: (url, args) => {
63458
+ const newArgs = handleMultipart(fetchParams2, args) ?? args;
63459
+ return fetch3(url, newArgs);
63460
+ },
63461
+ metadata: ctx.metadata,
63462
+ session: ctx.session || {},
63463
+ ...fetchParams2
63464
+ });
63465
+ resolve2(ctx, {
63466
+ fetching: false,
63467
+ variables: ctx.variables ?? {},
63468
+ data: result.data,
63469
+ errors: !result.errors || result.errors.length === 0 ? null : result.errors,
63470
+ partial: false,
63471
+ stale: false,
63472
+ source: DataSource.Network
63473
+ });
63474
+ }
63475
+ };
63476
+ };
63477
+ };
63478
+ var defaultFetch = (url, params) => {
63479
+ if (!url) {
63480
+ throw new Error(
63481
+ "Could not find configured client url. Please specify one in your HoudiniClient constructor."
63482
+ );
63483
+ }
63484
+ return async ({ fetch: fetch3, text, variables }) => {
63485
+ const result = await fetch3(url, {
63486
+ method: "POST",
63487
+ body: JSON.stringify({ query: text, variables }),
63488
+ ...params,
63489
+ headers: {
63490
+ Accept: "application/graphql+json, application/json",
63491
+ "Content-Type": "application/json",
63492
+ ...params?.headers
63493
+ }
63494
+ });
63495
+ return await result.json();
63496
+ };
63497
+ };
63498
+ function handleMultipart(params, args) {
63499
+ const { clone: clone2, files } = extractFiles({
63500
+ query: params.text,
63501
+ variables: params.variables
63502
+ });
63503
+ if (files.size) {
63504
+ const req = args;
63505
+ let headers = {};
63506
+ if (req?.headers) {
63507
+ const filtered = Object.entries(req?.headers).filter(([key, value]) => {
63508
+ return !(key.toLowerCase() == "content-type" && value.toLowerCase() == "application/json");
63509
+ });
63510
+ headers = Object.fromEntries(filtered);
63511
+ }
63512
+ const form = new FormData();
63513
+ const operationJSON = JSON.stringify(clone2);
63514
+ form.set("operations", operationJSON);
63515
+ const map = {};
63516
+ let i2 = 0;
63517
+ files.forEach((paths) => {
63518
+ map[++i2] = paths;
63519
+ });
63520
+ form.set("map", JSON.stringify(map));
63521
+ i2 = 0;
63522
+ files.forEach((paths, file) => {
63523
+ form.set(`${++i2}`, file, file.name);
63524
+ });
63525
+ return { ...req, headers, body: form };
63526
+ }
63527
+ }
63528
+ function isExtractableFile(value) {
63529
+ return typeof File !== "undefined" && value instanceof File || typeof Blob !== "undefined" && value instanceof Blob;
63530
+ }
63531
+ function extractFiles(value) {
63532
+ if (!arguments.length)
63533
+ throw new TypeError("Argument 1 `value` is required.");
63534
+ const clones = /* @__PURE__ */ new Map();
63535
+ const files = /* @__PURE__ */ new Map();
63536
+ function recurse(value2, path2, recursed) {
63537
+ if (isExtractableFile(value2)) {
63538
+ const filePaths = files.get(value2);
63539
+ filePaths ? filePaths.push(path2) : files.set(value2, [path2]);
63540
+ return null;
63541
+ }
63542
+ const valueIsList = Array.isArray(value2) || typeof FileList !== "undefined" && value2 instanceof FileList;
63543
+ const valueIsPlainObject = isPlainObject(value2);
63544
+ if (valueIsList || valueIsPlainObject) {
63545
+ let clone2 = clones.get(value2);
63546
+ const uncloned = !clone2;
63547
+ if (uncloned) {
63548
+ clone2 = valueIsList ? [] : value2 instanceof Object ? {} : /* @__PURE__ */ Object.create(null);
63549
+ clones.set(value2, clone2);
63550
+ }
63551
+ if (!recursed.has(value2)) {
63552
+ const pathPrefix = path2 ? `${path2}.` : "";
63553
+ const recursedDeeper = new Set(recursed).add(value2);
63554
+ if (valueIsList) {
63555
+ let index = 0;
63556
+ for (const item of value2) {
63557
+ const itemClone = recurse(item, pathPrefix + index++, recursedDeeper);
63558
+ if (uncloned)
63559
+ clone2.push(itemClone);
63560
+ }
63561
+ } else
63562
+ for (const key in value2) {
63563
+ const propertyClone = recurse(value2[key], pathPrefix + key, recursedDeeper);
63564
+ if (uncloned)
63565
+ clone2[key] = propertyClone;
63566
+ }
63567
+ }
63568
+ return clone2;
63569
+ }
63570
+ return value2;
63571
+ }
63572
+ return {
63573
+ clone: recurse(value, "", /* @__PURE__ */ new Set()),
63574
+ files
63575
+ };
63576
+ }
63577
+ function isPlainObject(value) {
63578
+ if (typeof value !== "object" || value === null) {
63579
+ return false;
63580
+ }
63581
+ const prototype = Object.getPrototypeOf(value);
63582
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
63583
+ }
63584
+
63585
+ // src/runtime/cache/gc.ts
63586
+ var GarbageCollector = class {
63587
+ cache;
63588
+ lifetimes = /* @__PURE__ */ new Map();
63589
+ get cacheBufferSize() {
63590
+ return this.cache._internal_unstable.config.cacheBufferSize ?? 10;
63591
+ }
63592
+ constructor(cache) {
63593
+ this.cache = cache;
63594
+ }
63595
+ resetLifetime(id, field) {
63596
+ if (!this.lifetimes.get(id)) {
63597
+ this.lifetimes.set(id, /* @__PURE__ */ new Map());
63598
+ }
63599
+ this.lifetimes.get(id).set(field, 0);
63600
+ }
63601
+ tick() {
63602
+ const dt_tick = Date.now().valueOf();
63603
+ const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
63604
+ for (const [id, fieldMap] of this.lifetimes.entries()) {
63605
+ for (const [field, lifetime] of fieldMap.entries()) {
63606
+ if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
63607
+ continue;
63608
+ }
63609
+ fieldMap.set(field, lifetime + 1);
63610
+ if (fieldMap.get(field) > this.cacheBufferSize) {
63611
+ this.cache._internal_unstable.storage.deleteField(id, field);
63612
+ this.cache._internal_unstable.lists.deleteField(id, field);
63613
+ fieldMap.delete(field);
63614
+ if ([...fieldMap.keys()].length === 0) {
63615
+ this.lifetimes.delete(id);
63616
+ }
63617
+ this.cache._internal_unstable.staleManager.delete(id, field);
63618
+ }
63619
+ if (config_max_time && config_max_time > 0) {
63620
+ const dt_valueOf = this.cache.getFieldTime(id, field);
63621
+ if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
63622
+ this.cache._internal_unstable.staleManager.markFieldStale(id, field);
63623
+ }
63624
+ }
63625
+ }
63626
+ }
63627
+ }
63628
+ };
63629
+
63630
+ // src/runtime/cache/lists.ts
63631
+ var ListManager = class {
63632
+ rootID;
63633
+ cache;
63634
+ constructor(cache, rootID2) {
63635
+ this.rootID = rootID2;
63636
+ this.cache = cache;
63637
+ }
63638
+ lists = /* @__PURE__ */ new Map();
63639
+ listsByField = /* @__PURE__ */ new Map();
63640
+ get(listName, id, allLists) {
63641
+ const matches = this.lists.get(listName);
63642
+ if (!matches || matches.size === 0) {
63643
+ return null;
63644
+ }
63645
+ if (allLists) {
63646
+ return new ListCollection(
63647
+ Array.from(matches, ([key, value]) => [...value.lists]).flat()
63648
+ );
63649
+ }
63650
+ const head = [...matches.values()][0];
63651
+ const { recordType } = head.lists[0];
63652
+ const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
63653
+ if (matches?.size === 1) {
63654
+ if (!id) {
63655
+ return head;
63656
+ }
63657
+ return parentID === Array.from(matches.keys())[0] ? head : null;
63658
+ }
63659
+ if (!id) {
63660
+ console.error(
63661
+ `Found multiple instances of "${listName}". Please provide one of @parentID or @allLists directives to help identify which list you want modify. For more information, visit this guide: https://www.houdinigraphql.com/api/graphql#parentidvalue-string `
63662
+ );
63663
+ return null;
63664
+ }
63665
+ return this.lists.get(listName)?.get(parentID);
63666
+ }
63667
+ remove(listName, id) {
63668
+ this.lists.get(listName)?.delete(id || this.rootID);
63669
+ }
63670
+ add(list) {
63671
+ if (!this.lists.has(list.name)) {
63672
+ this.lists.set(list.name, /* @__PURE__ */ new Map());
63673
+ }
63674
+ const name = list.name;
63675
+ const parentID = list.recordID || this.rootID;
63676
+ if (this.lists.get(name)?.get(parentID)?.includes(list.key)) {
63677
+ return;
63678
+ }
63679
+ if (!this.lists.has(name)) {
63680
+ this.lists.set(name, /* @__PURE__ */ new Map());
63681
+ }
63682
+ if (!this.lists.get(name).has(parentID)) {
63683
+ this.lists.get(name).set(parentID, new ListCollection([]));
63684
+ }
63685
+ if (!this.listsByField.has(parentID)) {
63686
+ this.listsByField.set(parentID, /* @__PURE__ */ new Map());
63687
+ }
63688
+ if (!this.listsByField.get(parentID).has(list.key)) {
63689
+ this.listsByField.get(parentID)?.set(list.key, []);
63690
+ }
63691
+ const handler = new List({ ...list, manager: this });
63692
+ this.lists.get(list.name).get(parentID).lists.push(handler);
63693
+ this.listsByField.get(parentID).get(list.key).push(handler);
63694
+ }
63695
+ removeIDFromAllLists(id) {
63696
+ for (const fieldMap of this.lists.values()) {
63697
+ for (const list of fieldMap.values()) {
63698
+ list.removeID(id);
63699
+ }
63700
+ }
63701
+ }
63702
+ deleteField(parentID, field) {
63703
+ if (!this.listsByField.get(parentID)?.has(field)) {
63704
+ return;
63705
+ }
63706
+ for (const list of this.listsByField.get(parentID).get(field)) {
63707
+ this.lists.get(list.name)?.get(list.recordID)?.deleteListWithKey(field);
63708
+ if (this.lists.get(list.name)?.get(list.recordID)?.lists.length === 0) {
63709
+ this.lists.get(list.name)?.delete(list.recordID);
63710
+ }
63711
+ }
63712
+ this.listsByField.get(parentID).delete(field);
63713
+ }
63714
+ };
63715
+ var List = class {
63716
+ recordID;
63717
+ recordType;
63718
+ key;
63719
+ type;
63720
+ cache;
63721
+ selection;
63722
+ _when;
63723
+ filters;
63724
+ name;
63725
+ connection;
63726
+ manager;
63727
+ abstract;
63728
+ constructor({
63729
+ name,
63730
+ recordID,
63731
+ recordType,
63732
+ key,
63733
+ listType,
63734
+ selection,
63735
+ when,
63736
+ filters,
63737
+ connection,
63738
+ manager,
63739
+ abstract
63740
+ }) {
63741
+ this.recordID = recordID || rootID;
63742
+ this.recordType = recordType;
63743
+ this.key = key;
63744
+ this.type = listType;
63745
+ this.cache = manager.cache;
63746
+ this.selection = selection;
63747
+ this._when = when;
63748
+ this.filters = filters;
63749
+ this.name = name;
63750
+ this.connection = connection;
63751
+ this.manager = manager;
63752
+ this.abstract = abstract;
63753
+ }
63754
+ when(when) {
63755
+ return this.manager.lists.get(this.name).get(this.recordID).when(when);
63756
+ }
63757
+ append(selection, data, variables = {}) {
63758
+ return this.addToList(selection, data, variables, "last");
63759
+ }
63760
+ prepend(selection, data, variables = {}) {
63761
+ return this.addToList(selection, data, variables, "first");
63762
+ }
63763
+ addToList(selection, data, variables = {}, where) {
63764
+ const listType = this.listType(data);
63765
+ const dataID = this.cache._internal_unstable.id(listType, data);
63766
+ if (!this.validateWhen() || !dataID) {
63767
+ return;
63768
+ }
63769
+ let insertSelection = selection;
63770
+ let insertData = data;
63771
+ if (this.connection) {
63772
+ insertSelection = {
63773
+ fields: {
63774
+ newEntry: {
63775
+ keyRaw: this.key,
63776
+ type: "Connection",
63777
+ selection: {
63778
+ fields: {
63779
+ edges: {
63780
+ keyRaw: "edges",
63781
+ type: "ConnectionEdge",
63782
+ updates: ["append", "prepend"],
63783
+ selection: {
63784
+ fields: {
63785
+ node: {
63786
+ type: listType,
63787
+ keyRaw: "node",
63788
+ selection: {
63789
+ ...selection,
63790
+ fields: {
63791
+ ...selection.fields,
63792
+ __typename: {
63793
+ keyRaw: "__typename",
63794
+ type: "String"
63795
+ }
63796
+ }
63797
+ }
63798
+ }
63799
+ }
63800
+ }
63801
+ }
63802
+ }
63803
+ }
63804
+ }
63805
+ }
63806
+ };
63807
+ insertData = {
63808
+ newEntry: {
63809
+ edges: [{ node: { ...data, __typename: listType } }]
63810
+ }
63811
+ };
63812
+ } else {
63813
+ insertSelection = {
63814
+ fields: {
63815
+ newEntries: {
63816
+ keyRaw: this.key,
63817
+ type: listType,
63818
+ updates: ["append", "prepend"],
63819
+ selection: {
63820
+ ...selection,
63821
+ fields: {
63822
+ ...selection.fields,
63823
+ __typename: {
63824
+ keyRaw: "__typename",
63825
+ type: "String"
63826
+ }
63827
+ }
63828
+ }
63829
+ }
63830
+ }
63831
+ };
63832
+ insertData = {
63833
+ newEntries: [{ ...data, __typename: listType }]
63834
+ };
63835
+ }
63836
+ this.cache.write({
63837
+ selection: insertSelection,
63838
+ data: insertData,
63839
+ variables,
63840
+ parent: this.recordID,
63841
+ applyUpdates: [where === "first" ? "prepend" : "append"]
63842
+ });
63843
+ }
63844
+ removeID(id, variables = {}) {
63845
+ if (!this.validateWhen()) {
63846
+ return;
63847
+ }
63848
+ let parentID = this.recordID;
63849
+ let targetID = id;
63850
+ let targetKey = this.key;
63851
+ if (this.connection) {
63852
+ const { value: embeddedConnection } = this.cache._internal_unstable.storage.get(
63853
+ this.recordID,
63854
+ this.key
63855
+ );
63856
+ if (!embeddedConnection) {
63857
+ return;
63858
+ }
63859
+ const embeddedConnectionID = embeddedConnection;
63860
+ const { value: edges } = this.cache._internal_unstable.storage.get(
63861
+ embeddedConnectionID,
63862
+ "edges"
63863
+ );
63864
+ for (const edge of flatten(edges) || []) {
63865
+ if (!edge) {
63866
+ continue;
63867
+ }
63868
+ const edgeID = edge;
63869
+ const { value: nodeID } = this.cache._internal_unstable.storage.get(edgeID, "node");
63870
+ if (!nodeID) {
63871
+ continue;
63872
+ }
63873
+ if (nodeID === id) {
63874
+ targetID = edgeID;
63875
+ }
63876
+ }
63877
+ parentID = embeddedConnectionID;
63878
+ targetKey = "edges";
63879
+ }
63880
+ let value = this.cache._internal_unstable.storage.get(parentID, targetKey).value;
63881
+ if (!value || !value.includes(targetID)) {
63882
+ return;
63883
+ }
63884
+ const subscribers = this.cache._internal_unstable.subscriptions.get(this.recordID, this.key);
63885
+ this.cache._internal_unstable.subscriptions.remove(
63886
+ targetID,
63887
+ this.connection ? this.selection.fields.edges.selection : this.selection,
63888
+ subscribers.map((sub) => sub[0]),
63889
+ variables
63890
+ );
63891
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
63892
+ for (const [spec] of subscribers) {
63893
+ spec.set(
63894
+ this.cache._internal_unstable.getSelection({
63895
+ parent: spec.parentID || this.manager.rootID,
63896
+ selection: spec.selection,
63897
+ variables: spec.variables?.() || {}
63898
+ }).data
63899
+ );
63900
+ }
63901
+ return true;
63902
+ }
63903
+ remove(data, variables = {}) {
63904
+ const targetID = this.cache._internal_unstable.id(this.listType(data), data);
63905
+ if (!targetID) {
63906
+ return;
63907
+ }
63908
+ return this.removeID(targetID, variables);
63909
+ }
63910
+ listType(data) {
63911
+ return data.__typename || this.type;
63912
+ }
63913
+ validateWhen(when) {
63914
+ let filters = when || this._when;
63915
+ let ok = true;
63916
+ if (filters) {
63917
+ const targets = this.filters;
63918
+ if (filters.must && targets) {
63919
+ ok = Object.entries(filters.must).reduce(
63920
+ (prev, [key, value]) => Boolean(prev && targets[key] == value),
63921
+ ok
63922
+ );
63923
+ }
63924
+ if (filters.must_not) {
63925
+ ok = !targets || Object.entries(filters.must_not).reduce(
63926
+ (prev, [key, value]) => Boolean(prev && targets[key] != value),
63927
+ ok
63928
+ );
63929
+ }
63930
+ }
63931
+ return ok;
63932
+ }
63933
+ toggleElement(selection, data, variables = {}, where) {
63934
+ if (!this.remove(data, variables)) {
63935
+ this.addToList(selection, data, variables, where);
63936
+ }
63937
+ }
63938
+ *[Symbol.iterator]() {
63939
+ let entries = [];
63940
+ let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
63941
+ if (!this.connection) {
63942
+ entries = flatten(value);
63943
+ } else {
63944
+ entries = this.cache._internal_unstable.storage.get(value, "edges").value;
63945
+ }
63946
+ for (let record of entries) {
63947
+ yield record;
63948
+ }
63949
+ }
63950
+ };
63951
+ var ListCollection = class {
63952
+ lists = [];
63953
+ constructor(lists) {
63954
+ this.lists = lists;
63955
+ }
63956
+ get selection() {
63957
+ return this.lists[0].selection;
63958
+ }
63959
+ append(...args) {
63960
+ this.lists.forEach((list) => list.append(...args));
63961
+ }
63962
+ prepend(...args) {
63963
+ this.lists.forEach((list) => list.prepend(...args));
63964
+ }
63965
+ addToList(...args) {
63966
+ this.lists.forEach((list) => list.addToList(...args));
63967
+ }
63968
+ removeID(...args) {
63969
+ this.lists.forEach((list) => list.removeID(...args));
63970
+ }
63971
+ remove(...args) {
63972
+ this.lists.forEach((list) => list.remove(...args));
63973
+ }
63974
+ toggleElement(...args) {
63975
+ this.lists.forEach((list) => list.toggleElement(...args));
63976
+ }
63977
+ when(when) {
63978
+ return new ListCollection(
63979
+ this.lists.filter((list) => {
63980
+ return list.validateWhen(when);
63981
+ })
63982
+ );
63983
+ }
63984
+ includes(key) {
63985
+ return !!this.lists.find((list) => list.key === key);
63986
+ }
63987
+ deleteListWithKey(key) {
63988
+ return this.lists = this.lists.filter((list) => list.key !== key);
63989
+ }
63990
+ *[Symbol.iterator]() {
63991
+ for (let list of this.lists) {
63992
+ for (const entry of list) {
63993
+ yield entry;
63994
+ }
63995
+ }
63996
+ }
63997
+ };
63998
+
63999
+ // src/runtime/cache/schema.ts
64000
+ var SchemaManager = class {
64001
+ cache;
64002
+ fieldTypes = {};
64003
+ constructor(cache) {
64004
+ this.cache = cache;
64005
+ }
64006
+ setFieldType({
64007
+ parent,
64008
+ key,
64009
+ type,
64010
+ nullable = false,
64011
+ link
64012
+ }) {
64013
+ let parensIndex = key.indexOf("(");
64014
+ if (parensIndex !== -1) {
64015
+ key = key.substring(0, parensIndex);
64016
+ }
64017
+ if (parent === rootID) {
64018
+ parent = "Query";
64019
+ } else if (parent.includes(":")) {
64020
+ parent = parent.substring(0, parent.indexOf(":"));
64021
+ }
64022
+ if (!this.fieldTypes[parent]) {
64023
+ this.fieldTypes[parent] = {};
64024
+ }
64025
+ this.fieldTypes[parent][key] = {
64026
+ type,
64027
+ nullable,
64028
+ link: !!link
64029
+ };
64030
+ }
64031
+ fieldType(type, field) {
64032
+ return this.fieldTypes[type]?.[field] || null;
64033
+ }
64034
+ get config() {
64035
+ return this.cache._internal_unstable.config;
64036
+ }
64037
+ };
64038
+
64039
+ // src/runtime/cache/staleManager.ts
64040
+ var StaleManager = class {
64041
+ cache;
64042
+ fieldsTime = /* @__PURE__ */ new Map();
64043
+ constructor(cache) {
64044
+ this.cache = cache;
64045
+ }
64046
+ #initMapId = (id) => {
64047
+ if (!this.fieldsTime.get(id)) {
64048
+ this.fieldsTime.set(id, /* @__PURE__ */ new Map());
64049
+ }
64050
+ };
64051
+ getFieldTime(id, field) {
64052
+ return this.fieldsTime.get(id)?.get(field);
64053
+ }
64054
+ setFieldTimeToNow(id, field) {
64055
+ this.#initMapId(id);
64056
+ this.fieldsTime.get(id)?.set(field, new Date().valueOf());
64057
+ }
64058
+ markFieldStale(id, field) {
64059
+ this.#initMapId(id);
64060
+ this.fieldsTime.get(id)?.set(field, null);
64061
+ }
64062
+ markAllStale() {
64063
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
64064
+ for (const [field] of fieldMap.entries()) {
64065
+ this.markFieldStale(id, field);
64066
+ }
64067
+ }
64068
+ }
64069
+ markRecordStale(id) {
64070
+ const fieldsTimeOfType = this.fieldsTime.get(id);
64071
+ if (fieldsTimeOfType) {
64072
+ for (const [field] of fieldsTimeOfType.entries()) {
64073
+ this.markFieldStale(id, field);
64074
+ }
64075
+ }
64076
+ }
64077
+ markTypeStale(type) {
64078
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
64079
+ if (id.startsWith(`${type}:`)) {
64080
+ for (const [field] of fieldMap.entries()) {
64081
+ this.markFieldStale(id, field);
64082
+ }
64083
+ }
64084
+ }
64085
+ }
64086
+ markTypeFieldStale(type, field, when) {
64087
+ const key = computeKey({ field, args: when });
64088
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
64089
+ if (id.startsWith(`${type}:`)) {
64090
+ for (const local_field of fieldMap.keys()) {
64091
+ if (local_field === key) {
64092
+ this.markFieldStale(id, field);
64093
+ }
64094
+ }
64095
+ }
64096
+ }
64097
+ }
64098
+ delete(id, field) {
64099
+ if (this.fieldsTime.has(id)) {
64100
+ this.fieldsTime.get(id)?.delete(field);
64101
+ if (this.fieldsTime.get(id)?.size === 0) {
64102
+ this.fieldsTime.delete(id);
64103
+ }
64104
+ }
64105
+ }
64106
+ };
64107
+
64108
+ // src/runtime/cache/storage.ts
64109
+ var InMemoryStorage = class {
64110
+ data;
64111
+ idCount = 0;
64112
+ rank = 0;
64113
+ constructor() {
64114
+ this.data = [];
64115
+ }
64116
+ get layerCount() {
64117
+ return this.data.length;
64118
+ }
64119
+ get nextRank() {
64120
+ return this.rank++;
64121
+ }
64122
+ createLayer(optimistic = false) {
64123
+ const layer = new Layer(this.idCount++);
64124
+ layer.optimistic = optimistic;
64125
+ this.data.push(layer);
64126
+ return layer;
64127
+ }
64128
+ insert(id, field, location, target) {
64129
+ return this.topLayer.insert(id, field, location, target);
64130
+ }
64131
+ remove(id, field, target) {
64132
+ return this.topLayer.remove(id, field, target);
64133
+ }
64134
+ delete(id) {
64135
+ return this.topLayer.delete(id);
64136
+ }
64137
+ deleteField(id, field) {
64138
+ return this.topLayer.deleteField(id, field);
64139
+ }
64140
+ getLayer(id) {
64141
+ for (const layer of this.data) {
64142
+ if (layer.id === id) {
64143
+ return layer;
64144
+ }
64145
+ }
64146
+ throw new Error("Could not find layer with id: " + id);
64147
+ }
64148
+ replaceID(replacement) {
64149
+ for (const layer of this.data) {
64150
+ layer.replaceID(replacement);
64151
+ }
64152
+ }
64153
+ get(id, field) {
64154
+ const operations = {
64155
+ [OperationKind.insert]: {
64156
+ [OperationLocation.start]: [],
64157
+ [OperationLocation.end]: []
64158
+ },
64159
+ [OperationKind.remove]: /* @__PURE__ */ new Set()
64160
+ };
64161
+ const layerIDs = [];
64162
+ for (let i2 = this.data.length - 1; i2 >= 0; i2--) {
64163
+ const layer = this.data[i2];
64164
+ const [layerValue, kind] = layer.get(id, field);
64165
+ const layerOperations = layer.getOperations(id, field) || [];
64166
+ layer.deletedIDs.forEach((v) => {
64167
+ if (layer.operations[v]?.undoDeletesInList?.includes(field)) {
64168
+ return;
64169
+ }
64170
+ operations.remove.add(v);
64171
+ });
64172
+ if (typeof layerValue === "undefined" && layerOperations.length === 0) {
64173
+ if (layer.deletedIDs.size > 0) {
64174
+ layerIDs.push(layer.id);
64175
+ }
64176
+ continue;
64177
+ }
64178
+ if (typeof layerValue !== "undefined" && !Array.isArray(layerValue)) {
64179
+ return {
64180
+ value: layerValue,
64181
+ kind,
64182
+ displayLayers: [layer.id]
64183
+ };
64184
+ }
64185
+ layerIDs.push(layer.id);
64186
+ if (layerOperations.length > 0) {
64187
+ for (const op of layerOperations) {
64188
+ if (isRemoveOperation(op)) {
64189
+ operations.remove.add(op.id);
64190
+ }
64191
+ if (isInsertOperation(op)) {
64192
+ operations.insert[op.location].unshift(op.id);
64193
+ }
64194
+ if (isDeleteOperation(op)) {
64195
+ return {
64196
+ value: void 0,
64197
+ kind: "unknown",
64198
+ displayLayers: []
64199
+ };
64200
+ }
64201
+ }
64202
+ }
64203
+ if (typeof layerValue === "undefined") {
64204
+ continue;
64205
+ }
64206
+ if (!operations.remove.size && !operations.insert.start.length && !operations.insert.end.length) {
64207
+ return { value: layerValue, displayLayers: layerIDs, kind: "link" };
64208
+ }
64209
+ return {
64210
+ value: [...operations.insert.start, ...layerValue, ...operations.insert.end].filter(
64211
+ (value) => !operations.remove.has(value)
64212
+ ),
64213
+ displayLayers: layerIDs,
64214
+ kind
64215
+ };
64216
+ }
64217
+ return {
64218
+ value: void 0,
64219
+ kind: "unknown",
64220
+ displayLayers: []
64221
+ };
64222
+ }
64223
+ writeLink(id, field, value) {
64224
+ return this.topLayer.writeLink(id, field, value);
64225
+ }
64226
+ writeField(id, field, value) {
64227
+ return this.topLayer.writeField(id, field, value);
64228
+ }
64229
+ resolveLayer(id) {
64230
+ let startingIndex = null;
64231
+ for (const [index, layer] of this.data.entries()) {
64232
+ if (layer.id !== id) {
64233
+ continue;
64234
+ }
64235
+ startingIndex = index - 1;
64236
+ this.data[index].optimistic = false;
64237
+ break;
64238
+ }
64239
+ if (startingIndex === null) {
64240
+ throw new Error("could not find layer with id: " + id);
64241
+ }
64242
+ if (startingIndex === -1) {
64243
+ startingIndex = 0;
64244
+ }
64245
+ if (this.data[startingIndex].optimistic) {
64246
+ startingIndex++;
64247
+ }
64248
+ const baseLayer = this.data[startingIndex];
64249
+ let layerIndex = startingIndex;
64250
+ while (layerIndex < this.data.length) {
64251
+ const layer = this.data[layerIndex++];
64252
+ if (layer.optimistic) {
64253
+ layerIndex--;
64254
+ break;
64255
+ }
64256
+ baseLayer.writeLayer(layer);
64257
+ }
64258
+ this.data.splice(startingIndex + 1, layerIndex - startingIndex - 1);
64259
+ }
64260
+ get topLayer() {
64261
+ if (this.data.length === 0) {
64262
+ this.createLayer();
64263
+ }
64264
+ if (this.data[this.data.length - 1]?.optimistic) {
64265
+ this.createLayer();
64266
+ }
64267
+ return this.data[this.data.length - 1];
64268
+ }
64269
+ };
64270
+ var Layer = class {
64271
+ id;
64272
+ optimistic = false;
64273
+ fields = {};
64274
+ links = {};
64275
+ operations = {};
64276
+ deletedIDs = /* @__PURE__ */ new Set();
64277
+ constructor(id) {
64278
+ this.id = id;
64279
+ }
64280
+ get(id, field) {
64281
+ if (typeof this.links[id]?.[field] !== "undefined") {
64282
+ return [this.links[id][field], "link"];
64283
+ }
64284
+ return [this.fields[id]?.[field], "scalar"];
64285
+ }
64286
+ getOperations(id, field) {
64287
+ if (this.operations[id]?.deleted) {
64288
+ return [
64289
+ {
64290
+ kind: OperationKind.delete,
64291
+ target: id
64292
+ }
64293
+ ];
64294
+ }
64295
+ if (this.operations[id]?.fields?.[field]) {
64296
+ return this.operations[id].fields[field];
64297
+ }
64298
+ }
64299
+ writeField(id, field, value) {
64300
+ this.fields[id] = {
64301
+ ...this.fields[id],
64302
+ [field]: value
64303
+ };
64304
+ return this.id;
64305
+ }
64306
+ writeLink(id, field, value) {
64307
+ const valueList = Array.isArray(value) ? value : [value];
64308
+ for (const value2 of flatten(valueList)) {
64309
+ if (!value2) {
64310
+ continue;
64311
+ }
64312
+ const fieldOperations = this.operations[id]?.fields[field];
64313
+ if (this.operations[value2]?.deleted || this.deletedIDs.has(value2)) {
64314
+ this.operations[value2] = {
64315
+ ...this.operations[value2],
64316
+ undoDeletesInList: [...this.operations[id]?.undoDeletesInList || [], field]
64317
+ };
64318
+ } else if (value2 && fieldOperations?.length > 0) {
64319
+ this.operations[id].fields[field] = fieldOperations.filter(
64320
+ (op) => op.kind !== "remove" || op.id !== value2
64321
+ );
64322
+ }
64323
+ }
64324
+ this.links[id] = {
64325
+ ...this.links[id],
64326
+ [field]: value
64327
+ };
64328
+ return this.id;
64329
+ }
64330
+ isDisplayLayer(displayLayers) {
64331
+ return displayLayers.length === 0 || displayLayers.includes(this.id) || Math.max(...displayLayers) < this.id;
64332
+ }
64333
+ clear() {
64334
+ this.links = {};
64335
+ this.fields = {};
64336
+ this.operations = {};
64337
+ this.deletedIDs = /* @__PURE__ */ new Set();
64338
+ }
64339
+ replaceID({ from, to }) {
64340
+ this.fields[to] = this.fields[from];
64341
+ this.links[to] = this.links[from];
64342
+ this.operations[to] = this.operations[from] || { fields: {} };
64343
+ if (this.deletedIDs.has(from)) {
64344
+ this.deletedIDs.add(to);
64345
+ }
64346
+ }
64347
+ removeUndefinedFields() {
64348
+ for (const [id, fields] of Object.entries(this.fields)) {
64349
+ for (const [field, value] of Object.entries(fields)) {
64350
+ if (typeof value === "undefined") {
64351
+ try {
64352
+ delete this.fields[id][field];
64353
+ } catch {
64354
+ }
64355
+ try {
64356
+ delete this.links[id][field];
64357
+ } catch {
64358
+ }
64359
+ }
64360
+ }
64361
+ if (Object.keys(fields || {}).length === 0) {
64362
+ delete this.fields[id];
64363
+ }
64364
+ if (Object.keys(this.links[id] || {}).length === 0) {
64365
+ delete this.links[id];
64366
+ }
64367
+ }
64368
+ }
64369
+ delete(id) {
64370
+ this.operations = {
64371
+ ...this.operations,
64372
+ [id]: {
64373
+ ...this.operations[id],
64374
+ deleted: true,
64375
+ undoDeletesInList: []
64376
+ }
64377
+ };
64378
+ this.deletedIDs.add(id);
64379
+ }
64380
+ deleteField(id, field) {
64381
+ this.fields[id] = {
64382
+ ...this.fields[id],
64383
+ [field]: void 0
64384
+ };
64385
+ }
64386
+ insert(id, field, where, target) {
64387
+ this.addFieldOperation(id, field, {
64388
+ kind: OperationKind.insert,
64389
+ id: target,
64390
+ location: where
64391
+ });
64392
+ }
64393
+ remove(id, field, target) {
64394
+ this.addFieldOperation(id, field, {
64395
+ kind: OperationKind.remove,
64396
+ id: target
64397
+ });
64398
+ }
64399
+ writeLayer(layer) {
64400
+ if (layer.id === this.id) {
64401
+ return;
64402
+ }
64403
+ for (const [id, ops] of Object.entries(layer.operations)) {
64404
+ const fields = {};
64405
+ for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
64406
+ for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
64407
+ fields[fieldName] = [...fields[fieldName] || [], ...operations];
64408
+ }
64409
+ }
64410
+ if (Object.keys(fields).length > 0) {
64411
+ this.operations[id] = {
64412
+ ...this.operations[id],
64413
+ fields
64414
+ };
64415
+ }
64416
+ if (ops?.deleted) {
64417
+ delete this.fields[id];
64418
+ delete this.links[id];
64419
+ }
64420
+ }
64421
+ for (const [id, values] of Object.entries(layer.fields)) {
64422
+ if (!values) {
64423
+ continue;
64424
+ }
64425
+ for (const [field, value] of Object.entries(values)) {
64426
+ this.writeField(id, field, value);
64427
+ }
64428
+ }
64429
+ for (const [id, values] of Object.entries(layer.links)) {
64430
+ if (!values) {
64431
+ continue;
64432
+ }
64433
+ for (const [field, value] of Object.entries(values)) {
64434
+ this.writeLink(id, field, value);
64435
+ }
64436
+ }
64437
+ layer.deletedIDs.forEach((v) => this.deletedIDs.add(v));
64438
+ }
64439
+ addFieldOperation(id, field, operation) {
64440
+ this.operations = {
64441
+ ...this.operations,
64442
+ [id]: {
64443
+ ...this.operations[id],
64444
+ fields: {
64445
+ [field]: [...this.operations[id]?.fields[field] || [], operation]
64446
+ }
64447
+ }
64448
+ };
64449
+ }
64450
+ };
64451
+ function isDeleteOperation(value) {
64452
+ return !!value && value.kind === OperationKind.delete;
64453
+ }
64454
+ function isInsertOperation(value) {
64455
+ return !!value && value.kind === OperationKind.insert;
64456
+ }
64457
+ function isRemoveOperation(value) {
64458
+ return !!value && value.kind === OperationKind.remove;
64459
+ }
64460
+ var OperationLocation = {
64461
+ start: "start",
64462
+ end: "end"
64463
+ };
64464
+ var OperationKind = {
64465
+ delete: "delete",
64466
+ insert: "insert",
64467
+ remove: "remove"
64468
+ };
64469
+
64470
+ // src/runtime/cache/stuff.ts
64471
+ function evaluateKey(key, variables = {}) {
64472
+ let evaluated = "";
64473
+ let varName = "";
64474
+ let inString = false;
64475
+ for (const char of key) {
64476
+ if (varName) {
64477
+ if (varChars.includes(char)) {
64478
+ varName += char;
64479
+ continue;
64480
+ }
64481
+ const value = variables[varName.slice(1)];
64482
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
64483
+ varName = "";
64484
+ }
64485
+ if (char === "$" && !inString) {
64486
+ varName = "$";
64487
+ continue;
64488
+ }
64489
+ if (char === '"') {
64490
+ inString = !inString;
64491
+ }
64492
+ evaluated += char;
64493
+ }
64494
+ return evaluated;
64495
+ }
64496
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
64497
+
64498
+ // src/runtime/cache/subscription.ts
64499
+ var InMemorySubscriptions = class {
64500
+ cache;
64501
+ constructor(cache) {
64502
+ this.cache = cache;
64503
+ }
64504
+ subscribers = {};
64505
+ referenceCounts = {};
64506
+ keyVersions = {};
64507
+ add({
64508
+ parent,
64509
+ spec,
64510
+ selection,
64511
+ variables,
64512
+ parentType
64513
+ }) {
64514
+ const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
64515
+ let targetSelection = getFieldsForType(selection, __typename);
64516
+ for (const fieldSelection of Object.values(targetSelection || {})) {
64517
+ const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
64518
+ const key = evaluateKey(keyRaw, variables);
64519
+ let targetSelection2;
64520
+ if (innerSelection) {
64521
+ const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
64522
+ targetSelection2 = getFieldsForType(innerSelection, __typename2);
64523
+ }
64524
+ this.addFieldSubscription({
64525
+ id: parent,
64526
+ key,
64527
+ selection: [spec, targetSelection2],
64528
+ type
64529
+ });
64530
+ if (list) {
64531
+ this.registerList({
64532
+ list,
64533
+ filters,
64534
+ id: parent,
64535
+ key,
64536
+ variables,
64537
+ selection: innerSelection,
64538
+ parentType: parentType || spec.rootType
64539
+ });
64540
+ }
64541
+ if (innerSelection) {
64542
+ const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
64543
+ parent,
64544
+ key
64545
+ );
64546
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
64547
+ for (const child of children) {
64548
+ if (!child) {
64549
+ continue;
64550
+ }
64551
+ this.add({
64552
+ parent: child,
64553
+ spec,
64554
+ selection: innerSelection,
64555
+ variables,
64556
+ parentType: type
64557
+ });
64558
+ }
64559
+ }
64560
+ }
64561
+ }
64562
+ addFieldSubscription({
64563
+ id,
64564
+ key,
64565
+ selection,
64566
+ type
64567
+ }) {
64568
+ const spec = selection[0];
64569
+ if (!this.subscribers[id]) {
64570
+ this.subscribers[id] = {};
64571
+ }
64572
+ if (!this.subscribers[id][key]) {
64573
+ this.subscribers[id][key] = [];
64574
+ }
64575
+ if (!this.keyVersions[key]) {
64576
+ this.keyVersions[key] = /* @__PURE__ */ new Set();
64577
+ }
64578
+ this.keyVersions[key].add(key);
64579
+ if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
64580
+ this.subscribers[id][key].push([spec, selection[1]]);
64581
+ }
64582
+ if (!this.referenceCounts[id]) {
64583
+ this.referenceCounts[id] = {};
64584
+ }
64585
+ if (!this.referenceCounts[id][key]) {
64586
+ this.referenceCounts[id][key] = /* @__PURE__ */ new Map();
64587
+ }
64588
+ const counts = this.referenceCounts[id][key];
64589
+ counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
64590
+ this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
64591
+ const { selection: innerSelection } = selection[1]?.[key] ?? {};
64592
+ }
64593
+ registerList({
64594
+ list,
64595
+ id,
64596
+ key,
64597
+ parentType,
64598
+ selection,
64599
+ filters,
64600
+ variables
64601
+ }) {
64602
+ this.cache._internal_unstable.lists.add({
64603
+ name: list.name,
64604
+ connection: list.connection,
64605
+ recordID: id,
64606
+ recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
64607
+ listType: list.type,
64608
+ key,
64609
+ selection,
64610
+ filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
64611
+ return {
64612
+ ...acc,
64613
+ [key2]: kind !== "Variable" ? value : variables[value]
64614
+ };
64615
+ }, {})
64616
+ });
64617
+ }
64618
+ addMany({
64619
+ parent,
64620
+ variables,
64621
+ subscribers,
64622
+ parentType
64623
+ }) {
64624
+ for (const [spec, targetSelection] of subscribers) {
64625
+ for (const selection of Object.values(targetSelection ?? {})) {
64626
+ const {
64627
+ type: linkedType,
64628
+ keyRaw,
64629
+ selection: innerSelection,
64630
+ list,
64631
+ filters
64632
+ } = selection;
64633
+ const key = evaluateKey(keyRaw, variables);
64634
+ const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
64635
+ this.addFieldSubscription({
64636
+ id: parent,
64637
+ key,
64638
+ selection: [spec, fieldSelection],
64639
+ type: linkedType
64640
+ });
64641
+ if (list) {
64642
+ this.registerList({
64643
+ list,
64644
+ filters,
64645
+ id: parent,
64646
+ key,
64647
+ variables,
64648
+ selection: innerSelection,
64649
+ parentType: parentType || spec.rootType
64650
+ });
64651
+ }
64652
+ const childSelection = selection.selection;
64653
+ if (childSelection) {
64654
+ const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
64655
+ const children = !Array.isArray(link) ? [link] : flatten(link);
64656
+ for (const linkedRecord of children) {
64657
+ if (!linkedRecord) {
64658
+ continue;
64659
+ }
64660
+ const __typename = this.cache._internal_unstable.storage.get(
64661
+ linkedRecord,
64662
+ "__typename"
64663
+ ).value;
64664
+ let targetSelection2 = getFieldsForType(childSelection, __typename);
64665
+ this.addMany({
64666
+ parent: linkedRecord,
64667
+ variables,
64668
+ subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
64669
+ parentType: linkedType
64670
+ });
64671
+ }
64672
+ }
64673
+ }
64674
+ }
64675
+ }
64676
+ get(id, field) {
64677
+ return this.subscribers[id]?.[field] || [];
64678
+ }
64679
+ remove(id, selection, targets, variables, visited = []) {
64680
+ visited.push(id);
64681
+ const linkedIDs = [];
64682
+ const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
64683
+ let targetSelection = getFieldsForType(selection, __typename);
64684
+ for (const fieldSelection of Object.values(targetSelection || {})) {
64685
+ const key = evaluateKey(fieldSelection.keyRaw, variables);
64686
+ this.removeSubscribers(id, key, targets);
64687
+ if (!fieldSelection.selection) {
64688
+ continue;
64689
+ }
64690
+ const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
64691
+ const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
64692
+ for (const link of links) {
64693
+ if (link !== null) {
64694
+ linkedIDs.push([link, fieldSelection.selection || {}]);
64695
+ }
64696
+ }
64697
+ }
64698
+ for (const [linkedRecordID, linkFields] of linkedIDs) {
64699
+ this.remove(linkedRecordID, linkFields, targets, visited);
64700
+ }
64701
+ }
64702
+ removeSubscribers(id, fieldName, specs) {
64703
+ let targets = [];
64704
+ for (const spec of specs) {
64705
+ if (!this.referenceCounts[id]?.[fieldName]?.has(spec.set)) {
64706
+ continue;
64707
+ }
64708
+ const counts = this.referenceCounts[id][fieldName];
64709
+ const newVal = (counts.get(spec.set) || 0) - 1;
64710
+ counts.set(spec.set, newVal);
64711
+ if (newVal <= 0) {
64712
+ targets.push(spec.set);
64713
+ counts.delete(spec.set);
64714
+ }
64715
+ }
64716
+ if (this.subscribers[id]) {
64717
+ this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
64718
+ ([{ set }]) => !targets.includes(set)
64719
+ );
64720
+ }
64721
+ }
64722
+ removeAllSubscribers(id, targets, visited = []) {
64723
+ visited.push(id);
64724
+ for (const field of Object.keys(this.subscribers[id] || [])) {
64725
+ const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
64726
+ this.removeSubscribers(id, field, subscribers);
64727
+ const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
64728
+ if (kind === "scalar") {
64729
+ continue;
64730
+ }
64731
+ const nextTargets = Array.isArray(value) ? flatten(value) : [value];
64732
+ for (const id2 of nextTargets) {
64733
+ if (visited.includes(id2)) {
64734
+ continue;
64735
+ }
64736
+ this.removeAllSubscribers(id2, subscribers, visited);
64737
+ }
64738
+ }
64739
+ }
64740
+ };
64741
+
64742
+ // src/runtime/cache/cache.ts
64743
+ var Cache = class {
64744
+ _internal_unstable;
64745
+ constructor(config) {
64746
+ this._internal_unstable = new CacheInternal({
64747
+ cache: this,
64748
+ storage: new InMemoryStorage(),
64749
+ subscriptions: new InMemorySubscriptions(this),
64750
+ lists: new ListManager(this, rootID),
64751
+ lifetimes: new GarbageCollector(this),
64752
+ staleManager: new StaleManager(this),
64753
+ schema: new SchemaManager(this)
64754
+ });
64755
+ if (config) {
64756
+ this.setConfig(defaultConfigValues(config));
64757
+ }
64758
+ }
64759
+ write({
64760
+ layer: layerID,
64761
+ notifySubscribers = [],
64762
+ ...args
64763
+ }) {
64764
+ const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
64765
+ const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
64766
+ const notified = [];
64767
+ for (const spec of subscribers.concat(notifySubscribers)) {
64768
+ if (!notified.includes(spec.set)) {
64769
+ notified.push(spec.set);
64770
+ spec.set(
64771
+ this._internal_unstable.getSelection({
64772
+ parent: spec.parentID || rootID,
64773
+ selection: spec.selection,
64774
+ variables: spec.variables?.() || {}
64775
+ }).data
64776
+ );
64777
+ }
64778
+ }
64779
+ return subscribers;
64780
+ }
64781
+ read(...args) {
64782
+ const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
64783
+ if (!hasData) {
64784
+ return { data: null, partial: false, stale: false };
64785
+ }
64786
+ return {
64787
+ data,
64788
+ partial,
64789
+ stale
64790
+ };
64791
+ }
64792
+ subscribe(spec, variables = {}) {
64793
+ return this._internal_unstable.subscriptions.add({
64794
+ parent: spec.parentID || rootID,
64795
+ spec,
64796
+ selection: spec.selection,
64797
+ variables
64798
+ });
64799
+ }
64800
+ unsubscribe(spec, variables = {}) {
64801
+ return this._internal_unstable.subscriptions.remove(
64802
+ spec.parentID || rootID,
64803
+ spec.selection,
64804
+ [spec],
64805
+ variables
64806
+ );
64807
+ }
64808
+ list(name, parentID, allLists) {
64809
+ const handler = this._internal_unstable.lists.get(name, parentID, allLists);
64810
+ if (!handler) {
64811
+ throw new Error(
64812
+ `Cannot find list with name: ${name}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
64813
+ );
64814
+ }
64815
+ return handler;
64816
+ }
64817
+ delete(id) {
64818
+ this._internal_unstable.subscriptions.removeAllSubscribers(id);
64819
+ this._internal_unstable.lists.removeIDFromAllLists(id);
64820
+ this._internal_unstable.storage.delete(id);
64821
+ }
64822
+ setConfig(config) {
64823
+ this._internal_unstable.setConfig(config);
64824
+ }
64825
+ markTypeStale(options) {
64826
+ if (!options) {
64827
+ this._internal_unstable.staleManager.markAllStale();
64828
+ } else if (!options.field) {
64829
+ this._internal_unstable.staleManager.markTypeStale(options.type);
64830
+ } else {
64831
+ this._internal_unstable.staleManager.markTypeFieldStale(
64832
+ options.type,
64833
+ options.field,
64834
+ options.when
64835
+ );
64836
+ }
64837
+ }
64838
+ markRecordStale(id, options) {
64839
+ if (options.field) {
64840
+ const key = computeKey({ field: options.field, args: options.when ?? {} });
64841
+ this._internal_unstable.staleManager.markFieldStale(id, key);
64842
+ } else {
64843
+ this._internal_unstable.staleManager.markRecordStale(id);
64844
+ }
64845
+ }
64846
+ getFieldTime(id, field) {
64847
+ return this._internal_unstable.staleManager.getFieldTime(id, field);
64848
+ }
64849
+ };
64850
+ var CacheInternal = class {
64851
+ _disabled = false;
64852
+ config = defaultConfigValues({
64853
+ plugins: {
64854
+ "houdini-svelte": {
64855
+ client: ""
64856
+ }
64857
+ }
64858
+ });
64859
+ storage;
64860
+ subscriptions;
64861
+ lists;
64862
+ cache;
64863
+ lifetimes;
64864
+ staleManager;
64865
+ schema;
64866
+ constructor({
64867
+ storage,
64868
+ subscriptions,
64869
+ lists,
64870
+ cache,
64871
+ lifetimes,
64872
+ staleManager,
64873
+ schema
64874
+ }) {
64875
+ this.storage = storage;
64876
+ this.subscriptions = subscriptions;
64877
+ this.lists = lists;
64878
+ this.cache = cache;
64879
+ this.lifetimes = lifetimes;
64880
+ this.staleManager = staleManager;
64881
+ this.schema = schema;
64882
+ this._disabled = typeof globalThis.window === "undefined";
64883
+ try {
64884
+ if (process.env.HOUDINI_TEST === "true") {
64885
+ this._disabled = false;
64886
+ }
64887
+ } catch {
64888
+ }
64889
+ }
64890
+ setConfig(config) {
64891
+ this.config = config;
64892
+ }
64893
+ writeSelection({
64894
+ data,
64895
+ selection,
64896
+ variables = {},
64897
+ parent = rootID,
64898
+ applyUpdates,
64899
+ layer,
64900
+ toNotify = [],
64901
+ forceNotify,
64902
+ forceStale
64903
+ }) {
64904
+ if (this._disabled) {
64905
+ return [];
64906
+ }
64907
+ let targetSelection = getFieldsForType(selection, data["__typename"]);
64908
+ for (const [field, value] of Object.entries(data)) {
64909
+ if (!selection || !targetSelection[field]) {
64910
+ throw new Error(
64911
+ "Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection)
64912
+ );
64913
+ }
64914
+ let {
64915
+ type: linkedType,
64916
+ keyRaw,
64917
+ selection: fieldSelection,
64918
+ operations,
64919
+ abstract: isAbstract,
64920
+ updates,
64921
+ nullable
64922
+ } = targetSelection[field];
64923
+ const key = evaluateKey(keyRaw, variables);
64924
+ this.schema.setFieldType({
64925
+ parent,
64926
+ key: keyRaw,
64927
+ type: linkedType,
64928
+ nullable,
64929
+ link: !!fieldSelection
64930
+ });
64931
+ const currentSubscribers = this.subscriptions.get(parent, key);
64932
+ const specs = currentSubscribers.map((sub) => sub[0]);
64933
+ const { value: previousValue, displayLayers } = this.storage.get(parent, key);
64934
+ const displayLayer = layer.isDisplayLayer(displayLayers);
64935
+ if (displayLayer) {
64936
+ this.lifetimes.resetLifetime(parent, key);
64937
+ if (forceStale) {
64938
+ this.staleManager.markFieldStale(parent, key);
64939
+ } else {
64940
+ this.staleManager.setFieldTimeToNow(parent, key);
64941
+ }
64942
+ }
64943
+ if (!fieldSelection) {
64944
+ let newValue = value;
64945
+ if (updates && applyUpdates && Array.isArray(value)) {
64946
+ for (const update of applyUpdates) {
64947
+ if (!updates.includes(update)) {
64948
+ continue;
64949
+ }
64950
+ if (update === "append") {
64951
+ newValue = (previousValue || []).concat(value);
64952
+ } else if (update === "prepend") {
64953
+ newValue = value.concat(previousValue || []);
64954
+ }
64955
+ }
64956
+ }
64957
+ if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
64958
+ newValue = previousValue;
64959
+ } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
64960
+ newValue = previousValue;
64961
+ }
64962
+ const valueChanged = !deepEquals(newValue, previousValue);
64963
+ if (displayLayer && (valueChanged || forceNotify)) {
64964
+ toNotify.push(...currentSubscribers);
64965
+ }
64966
+ layer.writeField(parent, key, newValue);
64967
+ } else if (value === null) {
64968
+ if (previousValue === null) {
64969
+ continue;
64970
+ }
64971
+ const previousLinks = flatten([previousValue]);
64972
+ for (const link of previousLinks) {
64973
+ this.subscriptions.remove(link, fieldSelection, specs, variables);
64974
+ }
64975
+ layer.writeLink(parent, key, null);
64976
+ toNotify.push(...currentSubscribers);
64977
+ } else if (value instanceof Object && !Array.isArray(value)) {
64978
+ if (isAbstract) {
64979
+ if (!value.__typename) {
64980
+ throw new Error(
64981
+ "Encountered interface type without __typename in the payload"
64982
+ );
64983
+ }
64984
+ linkedType = value.__typename;
64985
+ }
64986
+ const embedded = this.idFields(linkedType)?.filter(
64987
+ (field2) => typeof value[field2] === "undefined"
64988
+ ).length > 0;
64989
+ let linkedID = null;
64990
+ if (value !== null) {
64991
+ linkedID = !embedded ? this.id(linkedType, value) : `${parent}.${key}`;
64992
+ }
64993
+ let linkChange = linkedID !== previousValue;
64994
+ layer.writeLink(parent, key, linkedID);
64995
+ if (linkedID && displayLayer && (linkChange || forceNotify)) {
64996
+ if (previousValue && typeof previousValue === "string") {
64997
+ this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
64998
+ }
64999
+ this.subscriptions.addMany({
65000
+ parent: linkedID,
65001
+ subscribers: currentSubscribers,
65002
+ variables,
65003
+ parentType: linkedType
65004
+ });
65005
+ toNotify.push(...currentSubscribers);
65006
+ }
65007
+ if (linkedID) {
65008
+ this.writeSelection({
65009
+ selection: fieldSelection,
65010
+ parent: linkedID,
65011
+ data: value,
65012
+ variables,
65013
+ toNotify,
65014
+ applyUpdates,
65015
+ layer,
65016
+ forceNotify
65017
+ });
65018
+ }
65019
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
65020
+ let oldIDs = [...previousValue || []];
65021
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
65022
+ if (!id) {
65023
+ return "";
65024
+ }
65025
+ const { value: cursorField } = this.storage.get(id, "cursor");
65026
+ if (cursorField) {
65027
+ return "";
65028
+ }
65029
+ const { value: node } = this.storage.get(id, "node");
65030
+ if (!node) {
65031
+ return "";
65032
+ }
65033
+ return node;
65034
+ });
65035
+ let linkedIDs = [];
65036
+ const { newIDs, nestedIDs } = this.extractNestedListIDs({
65037
+ value,
65038
+ abstract: Boolean(isAbstract),
65039
+ specs: toNotify,
65040
+ applyUpdates,
65041
+ recordID: parent,
65042
+ key,
65043
+ linkedType,
65044
+ variables,
65045
+ fields: fieldSelection,
65046
+ layer,
65047
+ forceNotify
65048
+ });
65049
+ if (applyUpdates && updates) {
65050
+ if (key === "edges") {
65051
+ const newNodeIDs = [];
65052
+ for (const id of newIDs) {
65053
+ if (!id) {
65054
+ continue;
65055
+ }
65056
+ const { value: node } = this.storage.get(id, "node");
65057
+ if (typeof node !== "string") {
65058
+ continue;
65059
+ }
65060
+ if (!node || !this.storage.get(node, "__typename")) {
65061
+ continue;
65062
+ }
65063
+ newNodeIDs.push(node);
65064
+ }
65065
+ oldIDs = oldIDs.filter((id) => {
65066
+ if (!id) {
65067
+ return true;
65068
+ }
65069
+ const { value: value2 } = this.storage.get(id, "node");
65070
+ const node = value2;
65071
+ if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
65072
+ return false;
65073
+ }
65074
+ return true;
65075
+ });
65076
+ }
65077
+ for (const update of applyUpdates) {
65078
+ if (update !== "replace" && !updates.includes(update)) {
65079
+ continue;
65080
+ }
65081
+ if (update === "prepend") {
65082
+ linkedIDs = newIDs.concat(oldIDs);
65083
+ } else if (update === "append") {
65084
+ linkedIDs = oldIDs.concat(newIDs);
65085
+ } else if (update === "replace") {
65086
+ linkedIDs = newIDs;
65087
+ }
65088
+ }
65089
+ } else {
65090
+ linkedIDs = nestedIDs;
65091
+ }
65092
+ const contentChanged = !deepEquals(linkedIDs, oldIDs);
65093
+ if (contentChanged || forceNotify) {
65094
+ toNotify.push(...currentSubscribers);
65095
+ }
65096
+ for (const lostID of oldIDs) {
65097
+ if (linkedIDs.includes(lostID) || !lostID) {
65098
+ continue;
65099
+ }
65100
+ this.subscriptions.remove(lostID, fieldSelection, specs, variables);
65101
+ }
65102
+ if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
65103
+ layer.writeLink(parent, key, linkedIDs);
65104
+ }
65105
+ for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
65106
+ if (id == null) {
65107
+ continue;
65108
+ }
65109
+ this.subscriptions.addMany({
65110
+ parent: id,
65111
+ subscribers: currentSubscribers,
65112
+ variables,
65113
+ parentType: linkedType
65114
+ });
65115
+ }
65116
+ }
65117
+ for (const operation of operations || []) {
65118
+ let parentID;
65119
+ if (operation.parentID) {
65120
+ if (operation.parentID.kind !== "Variable") {
65121
+ parentID = operation.parentID.value;
65122
+ } else {
65123
+ const id = variables[operation.parentID.value];
65124
+ if (typeof id !== "string") {
65125
+ throw new Error("parentID value must be a string");
65126
+ }
65127
+ parentID = id;
65128
+ }
65129
+ }
65130
+ if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
65131
+ continue;
65132
+ }
65133
+ const targets = Array.isArray(value) ? value : [value];
65134
+ for (const target of targets) {
65135
+ if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
65136
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
65137
+ fieldSelection,
65138
+ target,
65139
+ variables,
65140
+ operation.position || "last"
65141
+ );
65142
+ } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
65143
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
65144
+ } else if (operation.action === "delete" && operation.type) {
65145
+ if (typeof target !== "string") {
65146
+ throw new Error("Cannot delete a record with a non-string ID");
65147
+ }
65148
+ const targetID = this.id(operation.type, target);
65149
+ if (!targetID) {
65150
+ continue;
65151
+ }
65152
+ this.cache.delete(targetID);
65153
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
65154
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
65155
+ fieldSelection,
65156
+ target,
65157
+ variables,
65158
+ operation.position || "last"
65159
+ );
65160
+ }
65161
+ }
65162
+ }
65163
+ }
65164
+ return toNotify;
65165
+ }
65166
+ getSelection({
65167
+ selection,
65168
+ parent = rootID,
65169
+ variables,
65170
+ stepsFromConnection = null
65171
+ }) {
65172
+ if (parent === null) {
65173
+ return { data: null, partial: false, stale: false, hasData: true };
65174
+ }
65175
+ const target = {};
65176
+ let hasData = false;
65177
+ let partial = false;
65178
+ let cascadeNull = false;
65179
+ let stale = false;
65180
+ const typename = this.storage.get(parent, "__typename").value;
65181
+ let targetSelection = getFieldsForType(selection, typename);
65182
+ for (const [
65183
+ attributeName,
65184
+ { type, keyRaw, selection: fieldSelection, nullable, list }
65185
+ ] of Object.entries(targetSelection)) {
65186
+ const key = evaluateKey(keyRaw, variables);
65187
+ const { value } = this.storage.get(parent, key);
65188
+ const dt_field = this.staleManager.getFieldTime(parent, key);
65189
+ if (dt_field === null) {
65190
+ stale = true;
65191
+ }
65192
+ let nextStep = stepsFromConnection;
65193
+ if (nextStep !== null) {
65194
+ if (nextStep >= 2) {
65195
+ nextStep = null;
65196
+ } else {
65197
+ nextStep += 1;
65198
+ }
65199
+ }
65200
+ if (list?.connection) {
65201
+ nextStep = 0;
65202
+ }
65203
+ const embeddedCursor = key === "cursor" && stepsFromConnection === 1;
65204
+ if (typeof value === "undefined" && !embeddedCursor) {
65205
+ partial = true;
65206
+ }
65207
+ if (typeof value === "undefined" || value === null) {
65208
+ target[attributeName] = null;
65209
+ if (typeof value !== "undefined") {
65210
+ hasData = true;
65211
+ }
65212
+ } else if (!fieldSelection) {
65213
+ const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
65214
+ if (fnUnmarshal) {
65215
+ target[attributeName] = fnUnmarshal(value);
65216
+ } else {
65217
+ target[attributeName] = value;
65218
+ }
65219
+ hasData = true;
65220
+ } else if (Array.isArray(value)) {
65221
+ const listValue = this.hydrateNestedList({
65222
+ fields: fieldSelection,
65223
+ variables,
65224
+ linkedList: value,
65225
+ stepsFromConnection: nextStep
65226
+ });
65227
+ target[attributeName] = listValue.data;
65228
+ if (listValue.partial) {
65229
+ partial = true;
65230
+ }
65231
+ if (listValue.stale) {
65232
+ stale = true;
65233
+ }
65234
+ if (listValue.hasData || value.length === 0) {
65235
+ hasData = true;
65236
+ }
65237
+ } else {
65238
+ const objectFields = this.getSelection({
65239
+ parent: value,
65240
+ selection: fieldSelection,
65241
+ variables,
65242
+ stepsFromConnection: nextStep
65243
+ });
65244
+ target[attributeName] = objectFields.data;
65245
+ if (objectFields.partial) {
65246
+ partial = true;
65247
+ }
65248
+ if (objectFields.stale) {
65249
+ stale = true;
65250
+ }
65251
+ if (objectFields.hasData) {
65252
+ hasData = true;
65253
+ }
65254
+ }
65255
+ if (target[attributeName] === null && !nullable && !embeddedCursor) {
65256
+ cascadeNull = true;
65257
+ }
65258
+ }
65259
+ return {
65260
+ data: cascadeNull ? null : target,
65261
+ partial: hasData && partial,
65262
+ stale: hasData && stale,
65263
+ hasData
65264
+ };
65265
+ }
65266
+ id(type, data) {
65267
+ const id = typeof data === "string" ? data : this.computeID(type, data);
65268
+ if (!id) {
65269
+ return null;
65270
+ }
65271
+ if (!type) {
65272
+ return id;
65273
+ }
65274
+ return type + ":" + id;
65275
+ }
65276
+ idFields(type) {
65277
+ return keyFieldsForType(this.config, type);
65278
+ }
65279
+ computeID(type, data) {
65280
+ return computeID(this.config, type, data);
65281
+ }
65282
+ hydrateNestedList({
65283
+ fields,
65284
+ variables,
65285
+ linkedList,
65286
+ stepsFromConnection
65287
+ }) {
65288
+ const result = [];
65289
+ let partialData = false;
65290
+ let stale = false;
65291
+ let hasValues = false;
65292
+ for (const entry of linkedList) {
65293
+ if (Array.isArray(entry)) {
65294
+ const nestedValue = this.hydrateNestedList({
65295
+ fields,
65296
+ variables,
65297
+ linkedList: entry,
65298
+ stepsFromConnection
65299
+ });
65300
+ result.push(nestedValue.data);
65301
+ if (nestedValue.partial) {
65302
+ partialData = true;
65303
+ }
65304
+ continue;
65305
+ }
65306
+ if (entry === null) {
65307
+ result.push(entry);
65308
+ continue;
65309
+ }
65310
+ const {
65311
+ data,
65312
+ partial,
65313
+ stale: local_stale,
65314
+ hasData
65315
+ } = this.getSelection({
65316
+ parent: entry,
65317
+ selection: fields,
65318
+ variables,
65319
+ stepsFromConnection
65320
+ });
65321
+ result.push(data);
65322
+ if (partial) {
65323
+ partialData = true;
65324
+ }
65325
+ if (local_stale) {
65326
+ stale = true;
65327
+ }
65328
+ if (hasData) {
65329
+ hasValues = true;
65330
+ }
65331
+ }
65332
+ return {
65333
+ data: result,
65334
+ partial: partialData,
65335
+ stale,
65336
+ hasData: hasValues
65337
+ };
65338
+ }
65339
+ extractNestedListIDs({
65340
+ value,
65341
+ abstract,
65342
+ recordID,
65343
+ key,
65344
+ linkedType,
65345
+ fields,
65346
+ variables,
65347
+ applyUpdates,
65348
+ specs,
65349
+ layer,
65350
+ forceNotify
65351
+ }) {
65352
+ const nestedIDs = [];
65353
+ const newIDs = [];
65354
+ for (const [i2, entry] of value.entries()) {
65355
+ if (Array.isArray(entry)) {
65356
+ const inner = this.extractNestedListIDs({
65357
+ value: entry,
65358
+ abstract,
65359
+ recordID,
65360
+ key,
65361
+ linkedType,
65362
+ fields,
65363
+ variables,
65364
+ applyUpdates,
65365
+ specs,
65366
+ layer,
65367
+ forceNotify
65368
+ });
65369
+ newIDs.push(...inner.newIDs);
65370
+ nestedIDs[i2] = inner.nestedIDs;
65371
+ continue;
65372
+ }
65373
+ if (entry === null || typeof entry === "undefined") {
65374
+ newIDs.push(null);
65375
+ nestedIDs[i2] = null;
65376
+ continue;
65377
+ }
65378
+ const entryObj = entry;
65379
+ let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
65380
+ const embedded = this.idFields(linkedType)?.filter(
65381
+ (field) => typeof entry[field] === "undefined"
65382
+ ).length > 0;
65383
+ const typename = entryObj.__typename;
65384
+ let innerType = linkedType;
65385
+ if (abstract) {
65386
+ if (!typename) {
65387
+ throw new Error("Encountered interface type without __typename in the payload");
65388
+ }
65389
+ innerType = typename;
65390
+ }
65391
+ if (!embedded) {
65392
+ const id = this.id(innerType, entry);
65393
+ if (id) {
65394
+ linkedID = id;
65395
+ } else {
65396
+ continue;
65397
+ }
65398
+ }
65399
+ this.writeSelection({
65400
+ root: rootID,
65401
+ selection: fields,
65402
+ parent: linkedID,
65403
+ data: entryObj,
65404
+ variables,
65405
+ toNotify: specs,
65406
+ applyUpdates,
65407
+ layer,
65408
+ forceNotify
65409
+ });
65410
+ newIDs.push(linkedID);
65411
+ nestedIDs[i2] = linkedID;
65412
+ }
65413
+ return { newIDs, nestedIDs };
65414
+ }
65415
+ collectGarbage() {
65416
+ this.lifetimes.tick();
65417
+ if (this.storage.layerCount === 1) {
65418
+ this.storage.topLayer.removeUndefinedFields();
65419
+ }
65420
+ }
65421
+ };
65422
+ var rootID = "_ROOT_";
65423
+
65424
+ // src/runtime/cache/index.ts
65425
+ var cache_default = new Cache();
65426
+
65427
+ // src/runtime/client/plugins/cache.ts
65428
+ var cachePolicy = ({
65429
+ enabled,
65430
+ setFetching,
65431
+ cache: localCache = cache_default
65432
+ }) => () => {
65433
+ return {
65434
+ network(ctx, { initialValue, next, resolve: resolve2, marshalVariables: marshalVariables2 }) {
65435
+ const { policy, artifact } = ctx;
65436
+ let useCache = false;
65437
+ if (enabled && artifact.kind === ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
65438
+ if (policy !== CachePolicy.NetworkOnly) {
65439
+ const value = localCache.read({
65440
+ selection: artifact.selection,
65441
+ variables: marshalVariables2(ctx)
65442
+ });
65443
+ const allowed = !value.partial || artifact.kind === ArtifactKind.Query && artifact.partial;
65444
+ if (policy === CachePolicy.CacheOnly) {
65445
+ return resolve2(ctx, {
65446
+ fetching: false,
65447
+ variables: ctx.variables ?? null,
65448
+ data: allowed ? value.data : initialValue.data,
65449
+ errors: null,
65450
+ source: DataSource.Cache,
65451
+ partial: allowed ? value.partial : false,
65452
+ stale: value.stale
65453
+ });
65454
+ }
65455
+ useCache = !!(value.data !== null && allowed);
65456
+ if (useCache) {
65457
+ resolve2(ctx, {
65458
+ fetching: false,
65459
+ variables: ctx.variables ?? null,
65460
+ data: value.data,
65461
+ errors: null,
65462
+ source: DataSource.Cache,
65463
+ partial: value.partial,
65464
+ stale: value.stale
65465
+ });
65466
+ }
65467
+ if (useCache && !value.partial && !value.stale) {
65468
+ return;
65469
+ }
65470
+ }
65471
+ }
65472
+ if (enabled) {
65473
+ setTimeout(() => {
65474
+ localCache._internal_unstable.collectGarbage();
65475
+ }, 0);
65476
+ }
65477
+ setFetching(!useCache);
65478
+ return next(ctx);
65479
+ },
65480
+ afterNetwork(ctx, { resolve: resolve2, value, marshalVariables: marshalVariables2 }) {
65481
+ if (value.source !== DataSource.Cache && enabled && value.data && !ctx.cacheParams?.disableWrite) {
65482
+ localCache.write({
65483
+ ...ctx.cacheParams,
65484
+ layer: ctx.cacheParams?.layer?.id,
65485
+ selection: ctx.artifact.selection,
65486
+ data: value.data,
65487
+ variables: marshalVariables2(ctx)
65488
+ });
65489
+ }
65490
+ resolve2(ctx, value);
65491
+ }
65492
+ };
65493
+ };
65494
+
65495
+ // src/runtime/client/utils/documentPlugins.ts
65496
+ var documentPlugin = (kind, source) => {
65497
+ return () => {
65498
+ const sourceHandlers = source();
65499
+ const enterWrapper = (handler) => {
65500
+ return !handler ? void 0 : (ctx, handlers) => {
65501
+ if (ctx.artifact.kind !== kind) {
65502
+ return handlers.next(ctx);
65503
+ }
65504
+ return handler(ctx, handlers);
65505
+ };
65506
+ };
65507
+ const exitWrapper = (handler) => {
65508
+ return !handler ? void 0 : (ctx, handlers) => {
65509
+ if (ctx.artifact.kind !== kind) {
65510
+ return handlers.resolve(ctx);
65511
+ }
65512
+ return handler(ctx, handlers);
65513
+ };
65514
+ };
65515
+ return {
65516
+ start: enterWrapper(sourceHandlers.start),
65517
+ network: enterWrapper(sourceHandlers.network),
65518
+ afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
65519
+ end: exitWrapper(sourceHandlers.end),
65520
+ catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
65521
+ cleanup: (...args) => sourceHandlers.cleanup?.(...args)
65522
+ };
65523
+ };
65524
+ };
65525
+
65526
+ // src/runtime/client/plugins/query.ts
65527
+ var query = documentPlugin(ArtifactKind.Query, function() {
65528
+ let subscriptionSpec = null;
65529
+ let lastVariables = null;
65530
+ let artifactName = "";
65531
+ return {
65532
+ start(ctx, { next }) {
65533
+ ctx.variables = {
65534
+ ...lastVariables,
65535
+ ...ctx.variables
65536
+ };
65537
+ next(ctx);
65538
+ },
65539
+ end(ctx, { resolve: resolve2, marshalVariables: marshalVariables2, variablesChanged: variablesChanged2 }) {
65540
+ if (variablesChanged2(ctx)) {
65541
+ artifactName = ctx.artifact.name;
65542
+ if (subscriptionSpec) {
65543
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
65544
+ }
65545
+ lastVariables = { ...marshalVariables2(ctx) };
65546
+ subscriptionSpec = {
65547
+ rootType: ctx.artifact.rootType,
65548
+ selection: ctx.artifact.selection,
65549
+ variables: () => lastVariables,
65550
+ set: (newValue) => {
65551
+ resolve2(ctx, {
65552
+ data: newValue,
65553
+ errors: null,
65554
+ fetching: false,
65555
+ partial: false,
65556
+ stale: false,
65557
+ source: DataSource.Cache,
65558
+ variables: ctx.variables ?? {}
65559
+ });
65560
+ }
65561
+ };
65562
+ cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
65563
+ }
65564
+ resolve2(ctx);
65565
+ },
65566
+ cleanup() {
65567
+ if (subscriptionSpec) {
65568
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
65569
+ lastVariables = null;
65570
+ }
65571
+ }
65572
+ };
65573
+ });
65574
+
65575
+ // src/runtime/client/plugins/mutation.ts
65576
+ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
65577
+ return {
65578
+ async start(ctx, { next, marshalVariables: marshalVariables2 }) {
65579
+ const layer = cache_default._internal_unstable.storage.createLayer(true);
65580
+ const optimisticResponse = ctx.stuff.optimisticResponse;
65581
+ let toNotify = [];
65582
+ if (optimisticResponse) {
65583
+ toNotify = cache_default.write({
65584
+ selection: ctx.artifact.selection,
65585
+ data: await marshalSelection({
65586
+ selection: ctx.artifact.selection,
65587
+ data: optimisticResponse
65588
+ }),
65589
+ variables: marshalVariables2(ctx),
65590
+ layer: layer.id
65591
+ });
65592
+ }
65593
+ ctx.cacheParams = {
65594
+ ...ctx.cacheParams,
65595
+ layer,
65596
+ notifySubscribers: toNotify,
65597
+ forceNotify: true
65598
+ };
65599
+ next(ctx);
65600
+ },
65601
+ afterNetwork(ctx, { resolve: resolve2 }) {
65602
+ ctx.cacheParams?.layer?.clear();
65603
+ resolve2(ctx);
65604
+ },
65605
+ end(ctx, { resolve: resolve2, value }) {
65606
+ const hasErrors = value.errors && value.errors.length > 0;
65607
+ if (hasErrors) {
65608
+ ctx.cacheParams?.layer?.clear();
65609
+ }
65610
+ if (ctx.cacheParams?.layer) {
65611
+ cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
65612
+ }
65613
+ resolve2(ctx);
65614
+ },
65615
+ catch(ctx, { error }) {
65616
+ if (ctx.cacheParams?.layer) {
65617
+ const { layer } = ctx.cacheParams;
65618
+ layer.clear();
65619
+ cache_default._internal_unstable.storage.resolveLayer(layer.id);
65620
+ }
65621
+ throw error;
65622
+ }
65623
+ };
65624
+ });
65625
+
65626
+ // src/runtime/client/plugins/subscription.ts
65627
+ function subscription(factory) {
65628
+ return documentPlugin(ArtifactKind.Subscription, () => {
65629
+ let clearSubscription = null;
65630
+ let socketClient = null;
65631
+ let check = null;
65632
+ return {
65633
+ start(ctx, { resolve: resolve2, next, initialValue }) {
65634
+ if (typeof globalThis.window === "undefined") {
65635
+ resolve2(ctx, initialValue);
65636
+ return;
65637
+ }
65638
+ next(ctx);
65639
+ },
65640
+ network(ctx, { resolve: resolve2, initialValue, variablesChanged: variablesChanged2, marshalVariables: marshalVariables2 }) {
65641
+ const checkValue = {
65642
+ fetchParams: ctx.fetchParams ?? {},
65643
+ session: ctx.session ?? {},
65644
+ metadata: ctx.metadata ?? {}
65645
+ };
65646
+ const changed = variablesChanged2(ctx);
65647
+ const sessionChange = !deepEquals(check, checkValue);
65648
+ if (!changed && !sessionChange) {
65649
+ resolve2(ctx, initialValue);
65650
+ return;
65651
+ }
65652
+ check = checkValue;
65653
+ clearSubscription?.();
65654
+ if (!socketClient || sessionChange) {
65655
+ socketClient = factory(ctx);
65656
+ }
65657
+ clearSubscription = socketClient.subscribe(
65658
+ {
65659
+ query: ctx.artifact.raw,
65660
+ variables: marshalVariables2(ctx)
65661
+ },
65662
+ {
65663
+ next: ({ data, errors }) => {
65664
+ resolve2(ctx, {
65665
+ data: data ?? null,
65666
+ errors: [...errors ?? []],
65667
+ fetching: false,
65668
+ partial: true,
65669
+ stale: false,
65670
+ source: DataSource.Network,
65671
+ variables: ctx.variables ?? {}
65672
+ });
65673
+ },
65674
+ error(data) {
65675
+ clearSubscription?.();
65676
+ resolve2(ctx, {
65677
+ partial: true,
65678
+ stale: false,
65679
+ source: DataSource.Network,
65680
+ data: null,
65681
+ errors: [data],
65682
+ fetching: false,
65683
+ variables: ctx.variables ?? {}
65684
+ });
65685
+ },
65686
+ complete() {
65687
+ }
65688
+ }
65689
+ );
65690
+ },
65691
+ cleanup() {
65692
+ clearSubscription?.();
65693
+ }
65694
+ };
65695
+ });
65696
+ }
65697
+
65698
+ // src/runtime/client/plugins/throwOnError.ts
65699
+ var throwOnError = ({ operations, error }) => () => {
65700
+ const all = operations.includes("all");
65701
+ const throwOnKind = (kind) => all || {
65702
+ [ArtifactKind.Query]: operations.includes("query"),
65703
+ [ArtifactKind.Mutation]: operations.includes("mutation"),
65704
+ [ArtifactKind.Fragment]: false,
65705
+ [ArtifactKind.Subscription]: operations.includes("subscription")
65706
+ }[kind];
65707
+ return {
65708
+ async end(ctx, { value, resolve: resolve2 }) {
65709
+ if (value.errors && value.errors.length > 0 && throwOnKind(ctx.artifact.kind)) {
65710
+ const result = await (error ?? defaultErrorFn)(value.errors);
65711
+ throw result;
65712
+ }
65713
+ resolve2(ctx);
65714
+ }
65715
+ };
65716
+ };
65717
+ var defaultErrorFn = async (errors) => new Error(errors.map((error) => error.message).join(". ") + ".");
65718
+
65719
+ // src/runtime/client/plugins/fetchParams.ts
65720
+ var fetchParams = (fn = () => ({})) => () => ({
65721
+ beforeNetwork(ctx, { next, marshalVariables: marshalVariables2 }) {
65722
+ next({
65723
+ ...ctx,
65724
+ fetchParams: fn({
65725
+ config: ctx.config,
65726
+ policy: ctx.policy,
65727
+ metadata: ctx.metadata,
65728
+ session: ctx.session,
65729
+ stuff: ctx.stuff,
65730
+ document: ctx.artifact,
65731
+ variables: marshalVariables2(ctx),
65732
+ text: ctx.artifact.raw,
65733
+ hash: ctx.artifact.hash
65734
+ })
65735
+ });
65736
+ }
65737
+ });
65738
+
65739
+ // src/runtime/client/documentStore.ts
65740
+ var steps = {
65741
+ forward: ["start", "beforeNetwork", "network"],
65742
+ backwards: ["end", "afterNetwork"]
65743
+ };
65744
+ var DocumentStore = class extends Writable {
65745
+ #artifact;
65746
+ #client;
65747
+ #configFile;
65748
+ #plugins;
65749
+ #lastVariables;
65750
+ #lastContext = null;
65751
+ constructor({
65752
+ artifact,
65753
+ plugins: plugins2,
65754
+ pipeline: pipeline2,
65755
+ client,
65756
+ cache = true,
65757
+ initialValue,
65758
+ fetching
65759
+ }) {
65760
+ fetching ??= artifact.kind === ArtifactKind.Query;
65761
+ const initialState = {
65762
+ data: initialValue ?? null,
65763
+ errors: null,
65764
+ partial: false,
65765
+ stale: false,
65766
+ source: null,
65767
+ fetching,
65768
+ variables: null
65769
+ };
65770
+ super(initialState, () => {
65771
+ return () => {
65772
+ this.#lastVariables = null;
65773
+ for (const plugin2 of this.#plugins) {
65774
+ plugin2.cleanup?.(this.#lastContext);
65775
+ }
65776
+ };
65777
+ });
65778
+ this.#artifact = artifact;
65779
+ this.#client = client;
65780
+ this.#lastVariables = null;
65781
+ this.#configFile = getCurrentConfig();
65782
+ this.#plugins = pipeline2 ?? [
65783
+ cachePolicy({
65784
+ enabled: cache,
65785
+ setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
65786
+ })(),
65787
+ ...plugins2 ?? []
65788
+ ];
65789
+ }
65790
+ async send({
65791
+ metadata,
65792
+ session,
65793
+ fetch: fetch3 = globalThis.fetch,
65794
+ variables,
65795
+ policy,
65796
+ stuff,
65797
+ cacheParams,
65798
+ setup = false,
65799
+ silenceEcho = false
65800
+ } = {}) {
65801
+ let context = new ClientPluginContextWrapper({
65802
+ config: this.#configFile,
65803
+ text: this.#artifact.raw,
65804
+ hash: this.#artifact.hash,
65805
+ policy: policy ?? this.#artifact.policy,
65806
+ variables: null,
65807
+ metadata,
65808
+ session,
65809
+ fetch: fetch3,
65810
+ stuff: {
65811
+ inputs: {
65812
+ changed: false,
65813
+ init: false,
65814
+ marshaled: {}
65815
+ },
65816
+ ...stuff
65817
+ },
65818
+ artifact: this.#artifact,
65819
+ lastVariables: this.#lastVariables,
65820
+ cacheParams
65821
+ });
65822
+ const draft = context.draft();
65823
+ draft.variables = variables ?? null;
65824
+ context = context.apply(draft, false);
65825
+ return await new Promise((resolve2, reject) => {
65826
+ const state = {
65827
+ setup,
65828
+ currentStep: 0,
65829
+ index: 0,
65830
+ silenceEcho,
65831
+ promise: {
65832
+ resolved: false,
65833
+ resolve: resolve2,
65834
+ reject
65835
+ },
65836
+ context
65837
+ };
65838
+ this.#step("forward", state);
65839
+ });
65840
+ }
65841
+ #step(direction, ctx, value) {
65842
+ const hook = direction === "error" ? "catch" : steps[direction][ctx.currentStep];
65843
+ let valid = (i2) => i2 <= this.#plugins.length;
65844
+ let step = (i2) => i2 + 1;
65845
+ if (["backwards", "error"].includes(direction)) {
65846
+ valid = (i2) => i2 >= 0;
65847
+ step = (i2) => i2 - 1;
65848
+ }
65849
+ for (let index = ctx.index; valid(index); index = step(index)) {
65850
+ let target = this.#plugins[index]?.[hook];
65851
+ if (!target) {
65852
+ continue;
65853
+ }
65854
+ const draft = ctx.context.draft();
65855
+ let variablesRefChanged = (newContext) => newContext.variables !== draft.variables;
65856
+ const common = {
65857
+ initialValue: this.state,
65858
+ client: this.#client,
65859
+ variablesChanged,
65860
+ marshalVariables,
65861
+ updateState: this.update.bind(this),
65862
+ next: (newContext) => {
65863
+ const nextIndex = ["forward", "error"].includes(direction) ? index + 1 : index;
65864
+ const nextStep = ["backwards", "error"].includes(direction) ? 0 : ctx.currentStep;
65865
+ this.#step("forward", {
65866
+ ...ctx,
65867
+ index: nextIndex,
65868
+ currentStep: nextStep,
65869
+ context: ctx.context.apply(newContext, variablesRefChanged(newContext))
65870
+ });
65871
+ },
65872
+ resolve: (newContext, value2) => {
65873
+ const nextIndex = direction === "backwards" ? index - 1 : index;
65874
+ this.#step(
65875
+ "backwards",
65876
+ {
65877
+ ...ctx,
65878
+ index: nextIndex,
65879
+ context: ctx.context.apply(newContext, variablesRefChanged(newContext))
65880
+ },
65881
+ value2
65882
+ );
65883
+ }
65884
+ };
65885
+ let handlers;
65886
+ if (direction === "forward") {
65887
+ handlers = common;
65888
+ } else if (direction === "backwards") {
65889
+ handlers = {
65890
+ ...common,
65891
+ value,
65892
+ resolve: (ctx2, data2) => {
65893
+ return common.resolve(ctx2, data2 ?? value);
65894
+ }
65895
+ };
65896
+ } else if (direction === "error") {
65897
+ handlers = {
65898
+ ...common,
65899
+ error: value
65900
+ };
65901
+ }
65902
+ try {
65903
+ const result = target(draft, handlers);
65904
+ result?.catch((err) => {
65905
+ this.#step("error", { ...ctx, index: index - 1 }, err);
65906
+ });
65907
+ } catch (err) {
65908
+ this.#step("error", { ...ctx, index: index - 1 }, err);
65909
+ }
65910
+ return;
65911
+ }
65912
+ if (direction === "forward") {
65913
+ if (ctx.setup) {
65914
+ return this.#step(
65915
+ "backwards",
65916
+ {
65917
+ ...ctx,
65918
+ currentStep: 0,
65919
+ index: this.#plugins.length
65920
+ },
65921
+ this.state
65922
+ );
65923
+ }
65924
+ if (ctx.currentStep <= steps.forward.length - 2) {
65925
+ return this.#step("forward", {
65926
+ ...ctx,
65927
+ currentStep: ctx.currentStep + 1,
65928
+ index: 0
65929
+ });
65930
+ }
65931
+ throw new Error(
65932
+ "Called next() on last possible plugin. Your chain is missing a plugin that calls resolve()."
65933
+ );
65934
+ }
65935
+ if (direction === "error") {
65936
+ if (!ctx.promise.resolved) {
65937
+ ctx.promise.reject(value);
65938
+ ctx.promise.resolved = true;
65939
+ }
65940
+ return;
65941
+ }
65942
+ if (ctx.currentStep > 0) {
65943
+ return this.#step(
65944
+ "backwards",
65945
+ {
65946
+ ...ctx,
65947
+ currentStep: ctx.currentStep - 1,
65948
+ index: this.#plugins.length - 1
65949
+ },
65950
+ value
65951
+ );
65952
+ }
65953
+ let data = value.data;
65954
+ try {
65955
+ data = unmarshalSelection(this.#configFile, this.#artifact.selection, data) ?? null;
65956
+ } catch {
65957
+ }
65958
+ const finalValue = {
65959
+ ...value,
65960
+ data
65961
+ };
65962
+ if (!ctx.promise.resolved) {
65963
+ ctx.promise.resolve(finalValue);
65964
+ ctx.promise.resolved = true;
65965
+ }
65966
+ this.#lastContext = ctx.context.draft();
65967
+ this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
65968
+ if (ctx.silenceEcho && finalValue.data === this.state.data) {
65969
+ return;
65970
+ }
65971
+ this.set(finalValue);
65972
+ }
65973
+ };
65974
+ var ClientPluginContextWrapper = class {
65975
+ #context;
65976
+ #lastVariables;
65977
+ constructor({
65978
+ lastVariables,
65979
+ ...values
65980
+ }) {
65981
+ this.#context = values;
65982
+ this.#lastVariables = lastVariables;
65983
+ }
65984
+ get variables() {
65985
+ return this.#context.variables;
65986
+ }
65987
+ draft() {
65988
+ const ctx = {
65989
+ ...this.#context
65990
+ };
65991
+ const applyVariables = this.applyVariables.bind(this);
65992
+ return {
65993
+ ...ctx,
65994
+ get stuff() {
65995
+ return ctx.stuff;
65996
+ },
65997
+ set stuff(val) {
65998
+ ctx.stuff = val;
65999
+ },
66000
+ get variables() {
66001
+ return ctx.variables ?? null;
66002
+ },
66003
+ set variables(val) {
66004
+ Object.assign(ctx, applyVariables(ctx, { variables: val }));
66005
+ }
66006
+ };
66007
+ }
66008
+ applyVariables(source, values) {
66009
+ const artifact = source.artifact;
66010
+ const ctx = {
66011
+ ...source,
66012
+ ...values
66013
+ };
66014
+ const val = values.variables;
66015
+ let changed = {};
66016
+ for (const [name, value] of Object.entries(val ?? {})) {
66017
+ if (value !== source.variables?.[name]) {
66018
+ changed[name] = value;
66019
+ }
66020
+ }
66021
+ ctx.stuff = {
66022
+ ...ctx.stuff,
66023
+ inputs: {
66024
+ ...ctx.stuff.inputs
66025
+ }
66026
+ };
66027
+ const firstInit = !ctx.stuff.inputs || !ctx.stuff.inputs.init;
66028
+ const hasChanged = Object.keys(changed).length > 0 || firstInit;
66029
+ if (artifact.kind !== ArtifactKind.Fragment && hasChanged) {
66030
+ const newVariables = {
66031
+ ...ctx.stuff.inputs?.marshaled,
66032
+ ...marshalInputs({
66033
+ artifact,
66034
+ input: changed,
66035
+ config: source.config
66036
+ })
66037
+ };
66038
+ ctx.stuff.inputs = {
66039
+ init: true,
66040
+ marshaled: newVariables,
66041
+ changed: true
66042
+ };
66043
+ ctx.variables = val;
66044
+ }
66045
+ ctx.stuff = {
66046
+ ...ctx.stuff,
66047
+ inputs: {
66048
+ ...ctx.stuff.inputs,
66049
+ changed: !deepEquals(ctx.stuff.inputs.marshaled, this.#lastVariables)
66050
+ }
66051
+ };
66052
+ return ctx;
66053
+ }
66054
+ apply(values, newVariables) {
66055
+ if (newVariables) {
66056
+ values = this.applyVariables(this.#context, values);
66057
+ }
66058
+ const wrapper = new ClientPluginContextWrapper({
66059
+ ...values,
66060
+ lastVariables: this.#lastVariables
66061
+ });
66062
+ return wrapper;
66063
+ }
66064
+ };
66065
+ function marshalVariables(ctx) {
66066
+ return ctx.stuff.inputs?.marshaled ?? {};
66067
+ }
66068
+ function variablesChanged(ctx) {
66069
+ return ctx.stuff.inputs?.changed;
66070
+ }
66071
+
66072
+ // src/runtime/client/plugins/injectedPlugins.ts
66073
+ var plugins = [];
66074
+ var injectedPlugins_default = plugins;
66075
+
66076
+ // src/runtime/client/index.ts
66077
+ var HoudiniClient = class {
66078
+ url;
66079
+ #plugins;
66080
+ constructor({ url, fetchParams: fetchParams2, plugins: plugins2, pipeline: pipeline2, throwOnError: throwOnError2 }) {
66081
+ if (plugins2 && pipeline2) {
66082
+ throw new Error(
66083
+ "A client cannot be given a pipeline and a list of plugins at the same time."
66084
+ );
66085
+ }
66086
+ this.#plugins = flatten(
66087
+ [].concat(
66088
+ throwOnError2 ? [throwOnError(throwOnError2)] : [],
66089
+ fetchParams(fetchParams2),
66090
+ pipeline2 ?? [
66091
+ query,
66092
+ mutation
66093
+ ].concat(
66094
+ plugins2 ?? [],
66095
+ injectedPlugins_default,
66096
+ fetch2()
66097
+ )
66098
+ )
66099
+ );
66100
+ this.url = url;
66101
+ }
66102
+ observe({
66103
+ artifact,
66104
+ cache = true,
66105
+ initialValue,
66106
+ fetching = false
66107
+ }) {
66108
+ return new DocumentStore({
66109
+ client: this,
66110
+ artifact,
66111
+ plugins: createPluginHooks(this.#plugins),
66112
+ cache,
66113
+ initialValue,
66114
+ fetching
66115
+ });
66116
+ }
66117
+ };
66118
+ function createPluginHooks(plugins2) {
66119
+ return plugins2.reduce((hooks, plugin2) => {
66120
+ if (typeof plugin2 !== "function") {
66121
+ throw new Error("Encountered client plugin that's not a function");
66122
+ }
66123
+ const result = plugin2();
66124
+ if (!result) {
66125
+ return hooks;
66126
+ }
66127
+ if (!Array.isArray(result)) {
66128
+ return hooks.concat(result);
66129
+ }
66130
+ for (const value of result) {
66131
+ if (!value) {
66132
+ continue;
66133
+ }
66134
+ if (typeof value === "function") {
66135
+ return hooks.concat(createPluginHooks([value]));
66136
+ }
66137
+ hooks.push(value);
66138
+ }
66139
+ return hooks;
66140
+ }, []);
66141
+ }
66142
+
63178
66143
  // src/lib/types.ts
63179
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
63180
- LogLevel2["Full"] = "full";
63181
- LogLevel2["Summary"] = "summary";
63182
- LogLevel2["ShortSummary"] = "short-summary";
63183
- LogLevel2["Quiet"] = "quiet";
63184
- return LogLevel2;
63185
- })(LogLevel || {});
66144
+ var LogLevel = {
66145
+ Full: "full",
66146
+ Summary: "summary",
66147
+ ShortSummary: "short-summary",
66148
+ Quiet: "quiet"
66149
+ };
63186
66150
 
63187
66151
  // src/lib/config.ts
63188
66152
  var currentDir = global.__dirname || dirname(fileURLToPath(import.meta.url));
@@ -63233,7 +66197,7 @@ var Config = class {
63233
66197
  scalars,
63234
66198
  cacheBufferSize,
63235
66199
  definitionsPath,
63236
- defaultCachePolicy = "CacheOrNetwork" /* CacheOrNetwork */,
66200
+ defaultCachePolicy = CachePolicy.CacheOrNetwork,
63237
66201
  defaultPartial = false,
63238
66202
  defaultListPosition = "append",
63239
66203
  defaultListTarget = null,
@@ -63255,7 +66219,7 @@ var Config = class {
63255
66219
  Object.values(LogLevel)
63256
66220
  )}`
63257
66221
  );
63258
- logLevel = "summary" /* Summary */;
66222
+ logLevel = LogLevel.Summary;
63259
66223
  }
63260
66224
  this.schemaPath = schemaPath;
63261
66225
  this.filepath = filepath;
@@ -63271,7 +66235,7 @@ var Config = class {
63271
66235
  this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
63272
66236
  this.defaultListTarget = defaultListTarget;
63273
66237
  this.definitionsFolder = definitionsPath;
63274
- this.logLevel = (logLevel || "summary" /* Summary */).toLowerCase();
66238
+ this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
63275
66239
  this.defaultFragmentMasking = defaultFragmentMasking;
63276
66240
  this.routesDir = join2(this.projectRoot, "src", "routes");
63277
66241
  this.schemaPollInterval = watchSchema?.interval ?? 2e3;
@@ -63612,8 +66576,10 @@ var Config = class {
63612
66576
  return node.name.value === "CachePolicy";
63613
66577
  }
63614
66578
  isInternalDirective(name) {
63615
- const internalDirectives = this.#newSchemaInstance?.getDirectives().map((directive) => directive.name) ?? [];
63616
- return internalDirectives.includes(name) || this.isDeleteDirective(name);
66579
+ const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
66580
+ return list.concat(directive.name);
66581
+ }, []) ?? [];
66582
+ return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
63617
66583
  }
63618
66584
  isListFragment(name) {
63619
66585
  return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
@@ -63717,10 +66683,16 @@ async function getConfig({
63717
66683
  await flattenPluginList(configPath, hooksList, pluginName, pluginFile)
63718
66684
  );
63719
66685
  }
63720
- const plugins = pluginsNested.flat();
63721
- for (const plugin2 of plugins) {
66686
+ const plugins2 = pluginsNested.flat();
66687
+ for (const plugin2 of plugins2) {
63722
66688
  if (plugin2.config) {
63723
- configFile = deepMerge(configPath, configFile, await plugin2.config(configFile));
66689
+ try {
66690
+ const configFactory = await import(plugin2.config);
66691
+ const newValue = typeof configFactory === "function" ? configFactory(configFile) : configFactory;
66692
+ configFile = deepMerge(configPath, configFile, newValue);
66693
+ } catch {
66694
+ console.log("could not load config file" + plugin2.config);
66695
+ }
63724
66696
  }
63725
66697
  }
63726
66698
  _config = new Config({
@@ -63746,7 +66718,7 @@ async function getConfig({
63746
66718
  _config.schema = await loadSchemaFile(_config.schemaPath);
63747
66719
  }
63748
66720
  }
63749
- _config.plugins = orderedPlugins(plugins);
66721
+ _config.plugins = orderedPlugins(plugins2);
63750
66722
  await Promise.all(_config.plugins.map((plugin2) => plugin2.afterLoad?.({ config: _config })));
63751
66723
  resolve2(_config);
63752
66724
  return _config;
@@ -63800,13 +66772,13 @@ ${e2.message}`);
63800
66772
  const config = imported.default || imported;
63801
66773
  return config;
63802
66774
  }
63803
- var orderedPlugins = (plugins) => {
63804
- const ordered = plugins.filter(
66775
+ var orderedPlugins = (plugins2) => {
66776
+ const ordered = plugins2.filter(
63805
66777
  (plugin2) => plugin2.order === "before" || plugin2.order === void 0
63806
66778
  );
63807
66779
  ordered.push(
63808
- ...plugins.filter((plugin2) => plugin2.order === "core"),
63809
- ...plugins.filter((plugin2) => plugin2.order === "after")
66780
+ ...plugins2.filter((plugin2) => plugin2.order === "core"),
66781
+ ...plugins2.filter((plugin2) => plugin2.order === "after")
63810
66782
  );
63811
66783
  return ordered;
63812
66784
  };
@@ -63878,6 +66850,8 @@ async function loadSchemaFile(schemaPath) {
63878
66850
  }
63879
66851
  return graphql2.buildClientSchema(jsonContents);
63880
66852
  }
66853
+ var emptySchema = graphql2.buildSchema("type Query { hello: String }");
66854
+ var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
63881
66855
 
63882
66856
  // src/lib/graphql.ts
63883
66857
  var graphql3 = __toESM(require_graphql2(), 1);
@@ -63894,7 +66868,7 @@ function getRootType(type) {
63894
66868
  function hashDocument({
63895
66869
  document
63896
66870
  }) {
63897
- const docString = typeof document === "string" ? document : document.artifact?.raw;
66871
+ const docString = typeof document === "string" ? document : document.originalString;
63898
66872
  return crypto.createHash("sha256").update(docString ?? "").digest("hex");
63899
66873
  }
63900
66874
  function parentTypeFromAncestors(schema, filepath, ancestors) {
@@ -64317,17 +67291,21 @@ export {
64317
67291
  CompiledSubscriptionKind,
64318
67292
  Config,
64319
67293
  DataSource,
67294
+ DocumentStore,
67295
+ HoudiniClient,
64320
67296
  HoudiniError,
64321
67297
  LogLevel,
64322
67298
  RefetchUpdateMode,
64323
67299
  TypeWrapper,
64324
67300
  cleanupFiles,
64325
67301
  computeID,
67302
+ createPluginHooks,
64326
67303
  deepMerge,
64327
67304
  defaultConfigValues,
64328
67305
  definitionFromAncestors,
64329
67306
  ensureArtifactImport,
64330
67307
  ensureImports,
67308
+ fetch2 as fetch,
64331
67309
  find_graphql,
64332
67310
  formatErrors,
64333
67311
  fs_exports as fs,
@@ -64338,6 +67316,7 @@ export {
64338
67316
  hashDocument,
64339
67317
  houdini_mode,
64340
67318
  keyFieldsForType,
67319
+ mutation,
64341
67320
  operation_requires_variables,
64342
67321
  orderedPlugins,
64343
67322
  parentTypeFromAncestors,
@@ -64346,10 +67325,12 @@ export {
64346
67325
  path_exports as path,
64347
67326
  plugin,
64348
67327
  pullSchema,
67328
+ query,
64349
67329
  readConfigFile,
64350
67330
  runPipeline,
64351
67331
  setMockConfig,
64352
67332
  siteURL,
67333
+ subscription,
64353
67334
  unwrapType,
64354
67335
  wrapType
64355
67336
  };