houdini 1.0.0-next.9 → 1.0.0

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 (60) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +2281 -105
  3. package/build/cmd-esm/index.js +2281 -105
  4. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  5. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  6. package/build/codegen-cjs/index.js +2876 -674
  7. package/build/codegen-esm/index.js +2876 -674
  8. package/build/lib/config.d.ts +4 -6
  9. package/build/lib/types.d.ts +18 -15
  10. package/build/lib-cjs/index.js +3159 -171
  11. package/build/lib-esm/index.js +3152 -171
  12. package/build/runtime/cache/storage.d.ts +18 -15
  13. package/build/runtime/client/documentStore.d.ts +15 -13
  14. package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
  15. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  16. package/build/runtime/lib/config.d.ts +2 -2
  17. package/build/runtime/lib/scalars.d.ts +1 -1
  18. package/build/runtime/lib/types.d.ts +41 -42
  19. package/build/runtime-cjs/cache/storage.d.ts +18 -15
  20. package/build/runtime-cjs/cache/storage.js +9 -11
  21. package/build/runtime-cjs/client/documentStore.d.ts +15 -13
  22. package/build/runtime-cjs/client/documentStore.js +10 -7
  23. package/build/runtime-cjs/client/index.js +3 -0
  24. package/build/runtime-cjs/client/plugins/cache.js +3 -3
  25. package/build/runtime-cjs/client/plugins/fetch.js +2 -2
  26. package/build/runtime-cjs/client/plugins/query.js +1 -1
  27. package/build/runtime-cjs/client/plugins/subscription.js +2 -2
  28. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
  29. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  30. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  31. package/build/runtime-cjs/lib/config.d.ts +2 -2
  32. package/build/runtime-cjs/lib/config.js +11 -1
  33. package/build/runtime-cjs/lib/scalars.d.ts +1 -1
  34. package/build/runtime-cjs/lib/scalars.js +13 -2
  35. package/build/runtime-cjs/lib/types.d.ts +41 -42
  36. package/build/runtime-cjs/lib/types.js +26 -30
  37. package/build/runtime-esm/cache/storage.d.ts +18 -15
  38. package/build/runtime-esm/cache/storage.js +9 -11
  39. package/build/runtime-esm/client/documentStore.d.ts +15 -13
  40. package/build/runtime-esm/client/documentStore.js +10 -7
  41. package/build/runtime-esm/client/index.js +5 -2
  42. package/build/runtime-esm/client/plugins/cache.js +3 -3
  43. package/build/runtime-esm/client/plugins/fetch.js +2 -2
  44. package/build/runtime-esm/client/plugins/query.js +1 -1
  45. package/build/runtime-esm/client/plugins/subscription.js +2 -2
  46. package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
  47. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  48. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  49. package/build/runtime-esm/lib/config.d.ts +2 -2
  50. package/build/runtime-esm/lib/config.js +11 -1
  51. package/build/runtime-esm/lib/scalars.d.ts +1 -1
  52. package/build/runtime-esm/lib/scalars.js +13 -2
  53. package/build/runtime-esm/lib/types.d.ts +41 -42
  54. package/build/runtime-esm/lib/types.js +26 -30
  55. package/build/test-cjs/index.js +2258 -82
  56. package/build/test-esm/index.js +2258 -82
  57. package/build/vite/houdini.d.ts +2 -0
  58. package/build/vite-cjs/index.js +2284 -106
  59. package/build/vite-esm/index.js +2284 -106
  60. package/package.json +2 -2
@@ -22418,42 +22418,42 @@ var require_node = __commonJS({
22418
22418
  return Link2;
22419
22419
  }(events_1.EventEmitter);
22420
22420
  exports.Link = Link;
22421
- var File3 = function() {
22422
- function File4(link, node, flags, fd) {
22421
+ var File4 = function() {
22422
+ function File5(link, node, flags, fd) {
22423
22423
  this.position = 0;
22424
22424
  this.link = link;
22425
22425
  this.node = node;
22426
22426
  this.flags = flags;
22427
22427
  this.fd = fd;
22428
22428
  }
22429
- File4.prototype.getString = function(encoding) {
22429
+ File5.prototype.getString = function(encoding) {
22430
22430
  if (encoding === void 0) {
22431
22431
  encoding = "utf8";
22432
22432
  }
22433
22433
  return this.node.getString();
22434
22434
  };
22435
- File4.prototype.setString = function(str) {
22435
+ File5.prototype.setString = function(str) {
22436
22436
  this.node.setString(str);
22437
22437
  };
22438
- File4.prototype.getBuffer = function() {
22438
+ File5.prototype.getBuffer = function() {
22439
22439
  return this.node.getBuffer();
22440
22440
  };
22441
- File4.prototype.setBuffer = function(buf) {
22441
+ File5.prototype.setBuffer = function(buf) {
22442
22442
  this.node.setBuffer(buf);
22443
22443
  };
22444
- File4.prototype.getSize = function() {
22444
+ File5.prototype.getSize = function() {
22445
22445
  return this.node.getSize();
22446
22446
  };
22447
- File4.prototype.truncate = function(len) {
22447
+ File5.prototype.truncate = function(len) {
22448
22448
  this.node.truncate(len);
22449
22449
  };
22450
- File4.prototype.seekTo = function(position) {
22450
+ File5.prototype.seekTo = function(position) {
22451
22451
  this.position = position;
22452
22452
  };
22453
- File4.prototype.stats = function() {
22453
+ File5.prototype.stats = function() {
22454
22454
  return Stats_1.default.build(this.node);
22455
22455
  };
22456
- File4.prototype.write = function(buf, offset, length, position) {
22456
+ File5.prototype.write = function(buf, offset, length, position) {
22457
22457
  if (offset === void 0) {
22458
22458
  offset = 0;
22459
22459
  }
@@ -22468,7 +22468,7 @@ var require_node = __commonJS({
22468
22468
  this.position = position + bytes;
22469
22469
  return bytes;
22470
22470
  };
22471
- File4.prototype.read = function(buf, offset, length, position) {
22471
+ File5.prototype.read = function(buf, offset, length, position) {
22472
22472
  if (offset === void 0) {
22473
22473
  offset = 0;
22474
22474
  }
@@ -22481,15 +22481,15 @@ var require_node = __commonJS({
22481
22481
  this.position = position + bytes;
22482
22482
  return bytes;
22483
22483
  };
22484
- File4.prototype.chmod = function(perm) {
22484
+ File5.prototype.chmod = function(perm) {
22485
22485
  this.node.chmod(perm);
22486
22486
  };
22487
- File4.prototype.chown = function(uid, gid) {
22487
+ File5.prototype.chown = function(uid, gid) {
22488
22488
  this.node.chown(uid, gid);
22489
22489
  };
22490
- return File4;
22490
+ return File5;
22491
22491
  }();
22492
- exports.File = File3;
22492
+ exports.File = File4;
22493
22493
  }
22494
22494
  });
22495
22495
 
@@ -23175,20 +23175,20 @@ var require_volume = __commonJS({
23175
23175
  }
23176
23176
  function flattenJSON(nestedJSON) {
23177
23177
  var flatJSON = {};
23178
- function flatten(pathPrefix, node) {
23178
+ function flatten2(pathPrefix, node) {
23179
23179
  for (var path2 in node) {
23180
23180
  var contentOrNode = node[path2];
23181
23181
  var joinedPath = join3(pathPrefix, path2);
23182
23182
  if (typeof contentOrNode === "string") {
23183
23183
  flatJSON[joinedPath] = contentOrNode;
23184
23184
  } else if (typeof contentOrNode === "object" && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
23185
- flatten(joinedPath, contentOrNode);
23185
+ flatten2(joinedPath, contentOrNode);
23186
23186
  } else {
23187
23187
  flatJSON[joinedPath] = null;
23188
23188
  }
23189
23189
  }
23190
23190
  }
23191
- flatten("", nestedJSON);
23191
+ flatten2("", nestedJSON);
23192
23192
  return flatJSON;
23193
23193
  }
23194
23194
  var Volume = function() {
@@ -28598,9 +28598,9 @@ var require_streams = __commonJS({
28598
28598
  }
28599
28599
  }
28600
28600
  try {
28601
- const { Blob: Blob3 } = require("buffer");
28602
- if (Blob3 && !Blob3.prototype.stream) {
28603
- Blob3.prototype.stream = function name(params) {
28601
+ const { Blob: Blob4 } = require("buffer");
28602
+ if (Blob4 && !Blob4.prototype.stream) {
28603
+ Blob4.prototype.stream = function name(params) {
28604
28604
  let position = 0;
28605
28605
  const blob = this;
28606
28606
  return new ReadableStream({
@@ -28651,12 +28651,12 @@ async function* toIterator(parts, clone2 = true) {
28651
28651
  }
28652
28652
  }
28653
28653
  }
28654
- var import_streams, POOL_SIZE, _Blob, Blob2, fetch_blob_default;
28654
+ var import_streams, POOL_SIZE, _Blob, Blob3, fetch_blob_default;
28655
28655
  var init_fetch_blob = __esm({
28656
28656
  "../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/index.js"() {
28657
28657
  import_streams = __toESM(require_streams(), 1);
28658
28658
  POOL_SIZE = 65536;
28659
- _Blob = class Blob {
28659
+ _Blob = class Blob2 {
28660
28660
  #parts = [];
28661
28661
  #type = "";
28662
28662
  #size = 0;
@@ -28680,7 +28680,7 @@ var init_fetch_blob = __esm({
28680
28680
  part = new Uint8Array(element.buffer.slice(element.byteOffset, element.byteOffset + element.byteLength));
28681
28681
  } else if (element instanceof ArrayBuffer) {
28682
28682
  part = new Uint8Array(element.slice(0));
28683
- } else if (element instanceof Blob) {
28683
+ } else if (element instanceof Blob2) {
28684
28684
  part = element;
28685
28685
  } else {
28686
28686
  part = encoder.encode(`${element}`);
@@ -28759,7 +28759,7 @@ var init_fetch_blob = __esm({
28759
28759
  relativeStart = 0;
28760
28760
  }
28761
28761
  }
28762
- const blob = new Blob([], { type: String(type).toLowerCase() });
28762
+ const blob = new Blob2([], { type: String(type).toLowerCase() });
28763
28763
  blob.#size = span;
28764
28764
  blob.#parts = blobParts;
28765
28765
  return blob;
@@ -28776,17 +28776,17 @@ var init_fetch_blob = __esm({
28776
28776
  type: { enumerable: true },
28777
28777
  slice: { enumerable: true }
28778
28778
  });
28779
- Blob2 = _Blob;
28780
- fetch_blob_default = Blob2;
28779
+ Blob3 = _Blob;
28780
+ fetch_blob_default = Blob3;
28781
28781
  }
28782
28782
  });
28783
28783
 
28784
28784
  // ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js
28785
- var _File, File2, file_default;
28785
+ var _File, File3, file_default;
28786
28786
  var init_file = __esm({
28787
28787
  "../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js"() {
28788
28788
  init_fetch_blob();
28789
- _File = class File extends fetch_blob_default {
28789
+ _File = class File2 extends fetch_blob_default {
28790
28790
  #lastModified = 0;
28791
28791
  #name = "";
28792
28792
  constructor(fileBits, fileName, options = {}) {
@@ -28815,8 +28815,8 @@ var init_file = __esm({
28815
28815
  return !!object && object instanceof fetch_blob_default && /^(File)$/.test(object[Symbol.toStringTag]);
28816
28816
  }
28817
28817
  };
28818
- File2 = _File;
28819
- file_default = File2;
28818
+ File3 = _File;
28819
+ file_default = File3;
28820
28820
  }
28821
28821
  });
28822
28822
 
@@ -28834,7 +28834,7 @@ Content-Type: ${v.type || "application/octet-stream"}\r
28834
28834
  c.push(`--${b}--`);
28835
28835
  return new B(c, { type: "multipart/form-data; boundary=" + b });
28836
28836
  }
28837
- var t, i, h, r, m, f, e, x, FormData;
28837
+ var t, i, h, r, m, f, e, x, FormData2;
28838
28838
  var init_esm_min = __esm({
28839
28839
  "../../node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js"() {
28840
28840
  init_fetch_blob();
@@ -28849,7 +28849,7 @@ var init_esm_min = __esm({
28849
28849
  throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e2} arguments required, but only ${a.length} present.`);
28850
28850
  }
28851
28851
  };
28852
- FormData = class FormData2 {
28852
+ FormData2 = class FormData3 {
28853
28853
  #d = [];
28854
28854
  constructor(...a) {
28855
28855
  if (a.length)
@@ -29015,7 +29015,7 @@ async function toFormData(Body2, ct) {
29015
29015
  let contentType;
29016
29016
  let filename;
29017
29017
  const entryChunks = [];
29018
- const formData = new FormData();
29018
+ const formData = new FormData2();
29019
29019
  const onPartData = (ui8a) => {
29020
29020
  entryValue += decoder.decode(ui8a, { stream: true });
29021
29021
  };
@@ -68322,7 +68322,18 @@ var graphql2 = __toESM(require_graphql2(), 1);
68322
68322
  var import_minimatch = __toESM(require_minimatch(), 1);
68323
68323
  var import_node_url2 = require("node:url");
68324
68324
 
68325
+ // src/runtime/imports/config.ts
68326
+ var config_default = {};
68327
+
68328
+ // src/runtime/imports/pluginConfig.ts
68329
+ var configs = [];
68330
+ var pluginConfig_default = configs;
68331
+
68325
68332
  // src/runtime/lib/config.ts
68333
+ var mockConfig = null;
68334
+ function getMockConfig() {
68335
+ return mockConfig;
68336
+ }
68326
68337
  function defaultConfigValues(file) {
68327
68338
  return {
68328
68339
  defaultKeys: ["id"],
@@ -68350,12 +68361,150 @@ function computeID(configFile, type, data) {
68350
68361
  }
68351
68362
  return id.slice(0, -2);
68352
68363
  }
68364
+ var _configFile = null;
68365
+ function getCurrentConfig() {
68366
+ const mockConfig2 = getMockConfig();
68367
+ if (mockConfig2) {
68368
+ return mockConfig2;
68369
+ }
68370
+ if (_configFile) {
68371
+ return _configFile;
68372
+ }
68373
+ let configFile = defaultConfigValues(config_default);
68374
+ for (const pluginConfig of pluginConfig_default) {
68375
+ configFile = pluginConfig(configFile);
68376
+ }
68377
+ _configFile = configFile;
68378
+ return configFile;
68379
+ }
68380
+
68381
+ // src/runtime/lib/deepEquals.ts
68382
+ function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
68383
+ if (Object.is(objA, objB))
68384
+ return true;
68385
+ if (objA instanceof Date && objB instanceof Date) {
68386
+ return objA.getTime() === objB.getTime();
68387
+ }
68388
+ if (objA instanceof RegExp && objB instanceof RegExp) {
68389
+ return objA.toString() === objB.toString();
68390
+ }
68391
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
68392
+ return false;
68393
+ }
68394
+ if (map.get(objA) === objB)
68395
+ return true;
68396
+ map.set(objA, objB);
68397
+ const keysA = Reflect.ownKeys(objA);
68398
+ const keysB = Reflect.ownKeys(objB);
68399
+ if (keysA.length !== keysB.length) {
68400
+ return false;
68401
+ }
68402
+ for (let i2 = 0; i2 < keysA.length; i2++) {
68403
+ if (!Reflect.has(objB, keysA[i2]) || !deepEquals(objA[keysA[i2]], objB[keysA[i2]], map)) {
68404
+ return false;
68405
+ }
68406
+ }
68407
+ return true;
68408
+ }
68409
+
68410
+ // src/runtime/lib/selection.ts
68411
+ function getFieldsForType(selection2, __typename) {
68412
+ let targetSelection = selection2.fields || {};
68413
+ if (selection2.abstractFields && __typename) {
68414
+ const mappedType = selection2.abstractFields.typeMap[__typename];
68415
+ if (mappedType) {
68416
+ targetSelection = selection2.abstractFields.fields[mappedType];
68417
+ } else if (selection2.abstractFields.fields[__typename]) {
68418
+ targetSelection = selection2.abstractFields.fields[__typename];
68419
+ }
68420
+ }
68421
+ return targetSelection;
68422
+ }
68423
+
68424
+ // src/runtime/lib/scalars.ts
68425
+ async function marshalSelection({
68426
+ selection: selection2,
68427
+ data
68428
+ }) {
68429
+ const config2 = getCurrentConfig();
68430
+ if (data === null || typeof data === "undefined") {
68431
+ return data;
68432
+ }
68433
+ if (Array.isArray(data)) {
68434
+ return await Promise.all(data.map((val) => marshalSelection({ selection: selection2, data: val })));
68435
+ }
68436
+ const targetSelection = getFieldsForType(selection2, data["__typename"]);
68437
+ return Object.fromEntries(
68438
+ await Promise.all(
68439
+ Object.entries(data).map(async ([fieldName, value]) => {
68440
+ const { type, selection: selection3 } = targetSelection[fieldName];
68441
+ if (!type) {
68442
+ return [fieldName, value];
68443
+ }
68444
+ if (selection3) {
68445
+ return [fieldName, await marshalSelection({ selection: selection3, data: value })];
68446
+ }
68447
+ if (config2.scalars?.[type]) {
68448
+ const marshalFn = config2.scalars[type].marshal;
68449
+ if (!marshalFn) {
68450
+ throw new Error(
68451
+ `scalar type ${type} is missing a \`marshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
68452
+ );
68453
+ }
68454
+ if (Array.isArray(value)) {
68455
+ return [fieldName, value.map(marshalFn)];
68456
+ }
68457
+ return [fieldName, marshalFn(value)];
68458
+ }
68459
+ return [fieldName, value];
68460
+ })
68461
+ )
68462
+ );
68463
+ }
68353
68464
 
68354
68465
  // src/runtime/lib/types.ts
68355
- var CompiledFragmentKind = "HoudiniFragment" /* Fragment */;
68356
- var CompiledMutationKind = "HoudiniMutation" /* Mutation */;
68357
- var CompiledQueryKind = "HoudiniQuery" /* Query */;
68358
- var CompiledSubscriptionKind = "HoudiniSubscription" /* Subscription */;
68466
+ var CachePolicy = {
68467
+ CacheOrNetwork: "CacheOrNetwork",
68468
+ CacheOnly: "CacheOnly",
68469
+ NetworkOnly: "NetworkOnly",
68470
+ CacheAndNetwork: "CacheAndNetwork"
68471
+ };
68472
+ var ArtifactKind = {
68473
+ Query: "HoudiniQuery",
68474
+ Subscription: "HoudiniSubscription",
68475
+ Mutation: "HoudiniMutation",
68476
+ Fragment: "HoudiniFragment"
68477
+ };
68478
+ var CompiledFragmentKind = ArtifactKind.Fragment;
68479
+ var CompiledMutationKind = ArtifactKind.Mutation;
68480
+ var CompiledQueryKind = ArtifactKind.Query;
68481
+ var CompiledSubscriptionKind = ArtifactKind.Subscription;
68482
+ var RefetchUpdateMode = {
68483
+ append: "append",
68484
+ prepend: "prepend",
68485
+ replace: "replace"
68486
+ };
68487
+ var DataSource = {
68488
+ Cache: "cache",
68489
+ Network: "network",
68490
+ Ssr: "ssr"
68491
+ };
68492
+
68493
+ // src/runtime/lib/key.ts
68494
+ var computeKey = ({ field, args }) => {
68495
+ const keys = Object.keys(args ?? {});
68496
+ keys.sort();
68497
+ return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
68498
+ };
68499
+ var stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
68500
+ if (Array.isArray(obj_from_json)) {
68501
+ return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
68502
+ }
68503
+ if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
68504
+ return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
68505
+ }
68506
+ return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
68507
+ };
68359
68508
 
68360
68509
  // src/lib/constants.ts
68361
68510
  var siteURL = "https://houdinigraphql.com";
@@ -68801,7 +68950,7 @@ var Body = class {
68801
68950
  } else if (ArrayBuffer.isView(body)) {
68802
68951
  body = import_node_buffer.Buffer.from(body.buffer, body.byteOffset, body.byteLength);
68803
68952
  } else if (body instanceof import_node_stream.default) {
68804
- } else if (body instanceof FormData) {
68953
+ } else if (body instanceof FormData2) {
68805
68954
  body = formDataToBlob(body);
68806
68955
  boundary = body.type.split("=")[1];
68807
68956
  } else {
@@ -68841,7 +68990,7 @@ var Body = class {
68841
68990
  async formData() {
68842
68991
  const ct = this.headers.get("content-type");
68843
68992
  if (ct.startsWith("application/x-www-form-urlencoded")) {
68844
- const formData = new FormData();
68993
+ const formData = new FormData2();
68845
68994
  const parameters = new URLSearchParams(await this.text());
68846
68995
  for (const [name, value] of parameters) {
68847
68996
  formData.append(name, value);
@@ -68967,7 +69116,7 @@ var extractContentType = (body, request) => {
68967
69116
  if (import_node_buffer.Buffer.isBuffer(body) || import_node_util2.types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
68968
69117
  return null;
68969
69118
  }
68970
- if (body instanceof FormData) {
69119
+ if (body instanceof FormData2) {
68971
69120
  return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
68972
69121
  }
68973
69122
  if (body && typeof body.getBoundary === "function") {
@@ -69934,14 +70083,2002 @@ function plugin(name, hooks) {
69934
70083
  return data;
69935
70084
  }
69936
70085
 
70086
+ // src/runtime/lib/flatten.ts
70087
+ function flatten(source) {
70088
+ if (!source) {
70089
+ return [];
70090
+ }
70091
+ return source.reduce((acc, element) => {
70092
+ if (!element) {
70093
+ return acc;
70094
+ }
70095
+ if (Array.isArray(element)) {
70096
+ return acc.concat(flatten(element));
70097
+ }
70098
+ return acc.concat(element);
70099
+ }, []);
70100
+ }
70101
+
70102
+ // src/runtime/cache/gc.ts
70103
+ var GarbageCollector = class {
70104
+ cache;
70105
+ lifetimes = /* @__PURE__ */ new Map();
70106
+ get cacheBufferSize() {
70107
+ return this.cache._internal_unstable.config.cacheBufferSize ?? 10;
70108
+ }
70109
+ constructor(cache) {
70110
+ this.cache = cache;
70111
+ }
70112
+ resetLifetime(id, field) {
70113
+ if (!this.lifetimes.get(id)) {
70114
+ this.lifetimes.set(id, /* @__PURE__ */ new Map());
70115
+ }
70116
+ this.lifetimes.get(id).set(field, 0);
70117
+ }
70118
+ tick() {
70119
+ const dt_tick = Date.now().valueOf();
70120
+ const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
70121
+ for (const [id, fieldMap] of this.lifetimes.entries()) {
70122
+ for (const [field, lifetime] of fieldMap.entries()) {
70123
+ if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
70124
+ continue;
70125
+ }
70126
+ fieldMap.set(field, lifetime + 1);
70127
+ if (fieldMap.get(field) > this.cacheBufferSize) {
70128
+ this.cache._internal_unstable.storage.deleteField(id, field);
70129
+ this.cache._internal_unstable.lists.deleteField(id, field);
70130
+ fieldMap.delete(field);
70131
+ if ([...fieldMap.keys()].length === 0) {
70132
+ this.lifetimes.delete(id);
70133
+ }
70134
+ this.cache._internal_unstable.staleManager.delete(id, field);
70135
+ }
70136
+ if (config_max_time && config_max_time > 0) {
70137
+ const dt_valueOf = this.cache.getFieldTime(id, field);
70138
+ if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
70139
+ this.cache._internal_unstable.staleManager.markFieldStale(id, field);
70140
+ }
70141
+ }
70142
+ }
70143
+ }
70144
+ }
70145
+ };
70146
+
70147
+ // src/runtime/cache/lists.ts
70148
+ var ListManager = class {
70149
+ rootID;
70150
+ cache;
70151
+ constructor(cache, rootID2) {
70152
+ this.rootID = rootID2;
70153
+ this.cache = cache;
70154
+ }
70155
+ lists = /* @__PURE__ */ new Map();
70156
+ listsByField = /* @__PURE__ */ new Map();
70157
+ get(listName, id, allLists) {
70158
+ const matches = this.lists.get(listName);
70159
+ if (!matches || matches.size === 0) {
70160
+ return null;
70161
+ }
70162
+ if (allLists) {
70163
+ return new ListCollection(
70164
+ Array.from(matches, ([key, value]) => [...value.lists]).flat()
70165
+ );
70166
+ }
70167
+ const head = [...matches.values()][0];
70168
+ const { recordType } = head.lists[0];
70169
+ const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
70170
+ if (matches?.size === 1) {
70171
+ if (!id) {
70172
+ return head;
70173
+ }
70174
+ return parentID === Array.from(matches.keys())[0] ? head : null;
70175
+ }
70176
+ if (!id) {
70177
+ console.error(
70178
+ `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 `
70179
+ );
70180
+ return null;
70181
+ }
70182
+ return this.lists.get(listName)?.get(parentID);
70183
+ }
70184
+ remove(listName, id) {
70185
+ this.lists.get(listName)?.delete(id || this.rootID);
70186
+ }
70187
+ add(list) {
70188
+ if (!this.lists.has(list.name)) {
70189
+ this.lists.set(list.name, /* @__PURE__ */ new Map());
70190
+ }
70191
+ const name = list.name;
70192
+ const parentID = list.recordID || this.rootID;
70193
+ if (this.lists.get(name)?.get(parentID)?.includes(list.key)) {
70194
+ return;
70195
+ }
70196
+ if (!this.lists.has(name)) {
70197
+ this.lists.set(name, /* @__PURE__ */ new Map());
70198
+ }
70199
+ if (!this.lists.get(name).has(parentID)) {
70200
+ this.lists.get(name).set(parentID, new ListCollection([]));
70201
+ }
70202
+ if (!this.listsByField.has(parentID)) {
70203
+ this.listsByField.set(parentID, /* @__PURE__ */ new Map());
70204
+ }
70205
+ if (!this.listsByField.get(parentID).has(list.key)) {
70206
+ this.listsByField.get(parentID)?.set(list.key, []);
70207
+ }
70208
+ const handler = new List({ ...list, manager: this });
70209
+ this.lists.get(list.name).get(parentID).lists.push(handler);
70210
+ this.listsByField.get(parentID).get(list.key).push(handler);
70211
+ }
70212
+ removeIDFromAllLists(id) {
70213
+ for (const fieldMap of this.lists.values()) {
70214
+ for (const list of fieldMap.values()) {
70215
+ list.removeID(id);
70216
+ }
70217
+ }
70218
+ }
70219
+ deleteField(parentID, field) {
70220
+ if (!this.listsByField.get(parentID)?.has(field)) {
70221
+ return;
70222
+ }
70223
+ for (const list of this.listsByField.get(parentID).get(field)) {
70224
+ this.lists.get(list.name)?.get(list.recordID)?.deleteListWithKey(field);
70225
+ if (this.lists.get(list.name)?.get(list.recordID)?.lists.length === 0) {
70226
+ this.lists.get(list.name)?.delete(list.recordID);
70227
+ }
70228
+ }
70229
+ this.listsByField.get(parentID).delete(field);
70230
+ }
70231
+ };
70232
+ var List = class {
70233
+ recordID;
70234
+ recordType;
70235
+ key;
70236
+ type;
70237
+ cache;
70238
+ selection;
70239
+ _when;
70240
+ filters;
70241
+ name;
70242
+ connection;
70243
+ manager;
70244
+ abstract;
70245
+ constructor({
70246
+ name,
70247
+ recordID,
70248
+ recordType,
70249
+ key,
70250
+ listType,
70251
+ selection: selection2,
70252
+ when,
70253
+ filters,
70254
+ connection,
70255
+ manager,
70256
+ abstract
70257
+ }) {
70258
+ this.recordID = recordID || rootID;
70259
+ this.recordType = recordType;
70260
+ this.key = key;
70261
+ this.type = listType;
70262
+ this.cache = manager.cache;
70263
+ this.selection = selection2;
70264
+ this._when = when;
70265
+ this.filters = filters;
70266
+ this.name = name;
70267
+ this.connection = connection;
70268
+ this.manager = manager;
70269
+ this.abstract = abstract;
70270
+ }
70271
+ when(when) {
70272
+ return this.manager.lists.get(this.name).get(this.recordID).when(when);
70273
+ }
70274
+ append(selection2, data, variables = {}) {
70275
+ return this.addToList(selection2, data, variables, "last");
70276
+ }
70277
+ prepend(selection2, data, variables = {}) {
70278
+ return this.addToList(selection2, data, variables, "first");
70279
+ }
70280
+ addToList(selection2, data, variables = {}, where) {
70281
+ const listType = this.listType(data);
70282
+ const dataID = this.cache._internal_unstable.id(listType, data);
70283
+ if (!this.validateWhen() || !dataID) {
70284
+ return;
70285
+ }
70286
+ let insertSelection = selection2;
70287
+ let insertData = data;
70288
+ if (this.connection) {
70289
+ insertSelection = {
70290
+ fields: {
70291
+ newEntry: {
70292
+ keyRaw: this.key,
70293
+ type: "Connection",
70294
+ selection: {
70295
+ fields: {
70296
+ edges: {
70297
+ keyRaw: "edges",
70298
+ type: "ConnectionEdge",
70299
+ updates: ["append", "prepend"],
70300
+ selection: {
70301
+ fields: {
70302
+ node: {
70303
+ type: listType,
70304
+ keyRaw: "node",
70305
+ selection: {
70306
+ ...selection2,
70307
+ fields: {
70308
+ ...selection2.fields,
70309
+ __typename: {
70310
+ keyRaw: "__typename",
70311
+ type: "String"
70312
+ }
70313
+ }
70314
+ }
70315
+ }
70316
+ }
70317
+ }
70318
+ }
70319
+ }
70320
+ }
70321
+ }
70322
+ }
70323
+ };
70324
+ insertData = {
70325
+ newEntry: {
70326
+ edges: [{ node: { ...data, __typename: listType } }]
70327
+ }
70328
+ };
70329
+ } else {
70330
+ insertSelection = {
70331
+ fields: {
70332
+ newEntries: {
70333
+ keyRaw: this.key,
70334
+ type: listType,
70335
+ updates: ["append", "prepend"],
70336
+ selection: {
70337
+ ...selection2,
70338
+ fields: {
70339
+ ...selection2.fields,
70340
+ __typename: {
70341
+ keyRaw: "__typename",
70342
+ type: "String"
70343
+ }
70344
+ }
70345
+ }
70346
+ }
70347
+ }
70348
+ };
70349
+ insertData = {
70350
+ newEntries: [{ ...data, __typename: listType }]
70351
+ };
70352
+ }
70353
+ this.cache.write({
70354
+ selection: insertSelection,
70355
+ data: insertData,
70356
+ variables,
70357
+ parent: this.recordID,
70358
+ applyUpdates: [where === "first" ? "prepend" : "append"]
70359
+ });
70360
+ }
70361
+ removeID(id, variables = {}) {
70362
+ if (!this.validateWhen()) {
70363
+ return;
70364
+ }
70365
+ let parentID = this.recordID;
70366
+ let targetID = id;
70367
+ let targetKey = this.key;
70368
+ if (this.connection) {
70369
+ const { value: embeddedConnection } = this.cache._internal_unstable.storage.get(
70370
+ this.recordID,
70371
+ this.key
70372
+ );
70373
+ if (!embeddedConnection) {
70374
+ return;
70375
+ }
70376
+ const embeddedConnectionID = embeddedConnection;
70377
+ const { value: edges } = this.cache._internal_unstable.storage.get(
70378
+ embeddedConnectionID,
70379
+ "edges"
70380
+ );
70381
+ for (const edge of flatten(edges) || []) {
70382
+ if (!edge) {
70383
+ continue;
70384
+ }
70385
+ const edgeID = edge;
70386
+ const { value: nodeID } = this.cache._internal_unstable.storage.get(edgeID, "node");
70387
+ if (!nodeID) {
70388
+ continue;
70389
+ }
70390
+ if (nodeID === id) {
70391
+ targetID = edgeID;
70392
+ }
70393
+ }
70394
+ parentID = embeddedConnectionID;
70395
+ targetKey = "edges";
70396
+ }
70397
+ let value = this.cache._internal_unstable.storage.get(parentID, targetKey).value;
70398
+ if (!value || !value.includes(targetID)) {
70399
+ return;
70400
+ }
70401
+ const subscribers = this.cache._internal_unstable.subscriptions.get(this.recordID, this.key);
70402
+ this.cache._internal_unstable.subscriptions.remove(
70403
+ targetID,
70404
+ this.connection ? this.selection.fields.edges.selection : this.selection,
70405
+ subscribers.map((sub) => sub[0]),
70406
+ variables
70407
+ );
70408
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
70409
+ for (const [spec] of subscribers) {
70410
+ spec.set(
70411
+ this.cache._internal_unstable.getSelection({
70412
+ parent: spec.parentID || this.manager.rootID,
70413
+ selection: spec.selection,
70414
+ variables: spec.variables?.() || {}
70415
+ }).data
70416
+ );
70417
+ }
70418
+ return true;
70419
+ }
70420
+ remove(data, variables = {}) {
70421
+ const targetID = this.cache._internal_unstable.id(this.listType(data), data);
70422
+ if (!targetID) {
70423
+ return;
70424
+ }
70425
+ return this.removeID(targetID, variables);
70426
+ }
70427
+ listType(data) {
70428
+ return data.__typename || this.type;
70429
+ }
70430
+ validateWhen(when) {
70431
+ let filters = when || this._when;
70432
+ let ok = true;
70433
+ if (filters) {
70434
+ const targets = this.filters;
70435
+ if (filters.must && targets) {
70436
+ ok = Object.entries(filters.must).reduce(
70437
+ (prev, [key, value]) => Boolean(prev && targets[key] == value),
70438
+ ok
70439
+ );
70440
+ }
70441
+ if (filters.must_not) {
70442
+ ok = !targets || Object.entries(filters.must_not).reduce(
70443
+ (prev, [key, value]) => Boolean(prev && targets[key] != value),
70444
+ ok
70445
+ );
70446
+ }
70447
+ }
70448
+ return ok;
70449
+ }
70450
+ toggleElement(selection2, data, variables = {}, where) {
70451
+ if (!this.remove(data, variables)) {
70452
+ this.addToList(selection2, data, variables, where);
70453
+ }
70454
+ }
70455
+ *[Symbol.iterator]() {
70456
+ let entries = [];
70457
+ let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
70458
+ if (!this.connection) {
70459
+ entries = flatten(value);
70460
+ } else {
70461
+ entries = this.cache._internal_unstable.storage.get(value, "edges").value;
70462
+ }
70463
+ for (let record2 of entries) {
70464
+ yield record2;
70465
+ }
70466
+ }
70467
+ };
70468
+ var ListCollection = class {
70469
+ lists = [];
70470
+ constructor(lists) {
70471
+ this.lists = lists;
70472
+ }
70473
+ get selection() {
70474
+ return this.lists[0].selection;
70475
+ }
70476
+ append(...args) {
70477
+ this.lists.forEach((list) => list.append(...args));
70478
+ }
70479
+ prepend(...args) {
70480
+ this.lists.forEach((list) => list.prepend(...args));
70481
+ }
70482
+ addToList(...args) {
70483
+ this.lists.forEach((list) => list.addToList(...args));
70484
+ }
70485
+ removeID(...args) {
70486
+ this.lists.forEach((list) => list.removeID(...args));
70487
+ }
70488
+ remove(...args) {
70489
+ this.lists.forEach((list) => list.remove(...args));
70490
+ }
70491
+ toggleElement(...args) {
70492
+ this.lists.forEach((list) => list.toggleElement(...args));
70493
+ }
70494
+ when(when) {
70495
+ return new ListCollection(
70496
+ this.lists.filter((list) => {
70497
+ return list.validateWhen(when);
70498
+ })
70499
+ );
70500
+ }
70501
+ includes(key) {
70502
+ return !!this.lists.find((list) => list.key === key);
70503
+ }
70504
+ deleteListWithKey(key) {
70505
+ return this.lists = this.lists.filter((list) => list.key !== key);
70506
+ }
70507
+ *[Symbol.iterator]() {
70508
+ for (let list of this.lists) {
70509
+ for (const entry of list) {
70510
+ yield entry;
70511
+ }
70512
+ }
70513
+ }
70514
+ };
70515
+
70516
+ // src/runtime/cache/schema.ts
70517
+ var SchemaManager = class {
70518
+ cache;
70519
+ fieldTypes = {};
70520
+ constructor(cache) {
70521
+ this.cache = cache;
70522
+ }
70523
+ setFieldType({
70524
+ parent,
70525
+ key,
70526
+ type,
70527
+ nullable = false,
70528
+ link
70529
+ }) {
70530
+ let parensIndex = key.indexOf("(");
70531
+ if (parensIndex !== -1) {
70532
+ key = key.substring(0, parensIndex);
70533
+ }
70534
+ if (parent === rootID) {
70535
+ parent = "Query";
70536
+ } else if (parent.includes(":")) {
70537
+ parent = parent.substring(0, parent.indexOf(":"));
70538
+ }
70539
+ if (!this.fieldTypes[parent]) {
70540
+ this.fieldTypes[parent] = {};
70541
+ }
70542
+ this.fieldTypes[parent][key] = {
70543
+ type,
70544
+ nullable,
70545
+ link: !!link
70546
+ };
70547
+ }
70548
+ fieldType(type, field) {
70549
+ return this.fieldTypes[type]?.[field] || null;
70550
+ }
70551
+ get config() {
70552
+ return this.cache._internal_unstable.config;
70553
+ }
70554
+ };
70555
+
70556
+ // src/runtime/cache/staleManager.ts
70557
+ var StaleManager = class {
70558
+ cache;
70559
+ fieldsTime = /* @__PURE__ */ new Map();
70560
+ constructor(cache) {
70561
+ this.cache = cache;
70562
+ }
70563
+ #initMapId = (id) => {
70564
+ if (!this.fieldsTime.get(id)) {
70565
+ this.fieldsTime.set(id, /* @__PURE__ */ new Map());
70566
+ }
70567
+ };
70568
+ getFieldTime(id, field) {
70569
+ return this.fieldsTime.get(id)?.get(field);
70570
+ }
70571
+ setFieldTimeToNow(id, field) {
70572
+ this.#initMapId(id);
70573
+ this.fieldsTime.get(id)?.set(field, new Date().valueOf());
70574
+ }
70575
+ markFieldStale(id, field) {
70576
+ this.#initMapId(id);
70577
+ this.fieldsTime.get(id)?.set(field, null);
70578
+ }
70579
+ markAllStale() {
70580
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
70581
+ for (const [field] of fieldMap.entries()) {
70582
+ this.markFieldStale(id, field);
70583
+ }
70584
+ }
70585
+ }
70586
+ markRecordStale(id) {
70587
+ const fieldsTimeOfType = this.fieldsTime.get(id);
70588
+ if (fieldsTimeOfType) {
70589
+ for (const [field] of fieldsTimeOfType.entries()) {
70590
+ this.markFieldStale(id, field);
70591
+ }
70592
+ }
70593
+ }
70594
+ markTypeStale(type) {
70595
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
70596
+ if (id.startsWith(`${type}:`)) {
70597
+ for (const [field] of fieldMap.entries()) {
70598
+ this.markFieldStale(id, field);
70599
+ }
70600
+ }
70601
+ }
70602
+ }
70603
+ markTypeFieldStale(type, field, when) {
70604
+ const key = computeKey({ field, args: when });
70605
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
70606
+ if (id.startsWith(`${type}:`)) {
70607
+ for (const local_field of fieldMap.keys()) {
70608
+ if (local_field === key) {
70609
+ this.markFieldStale(id, field);
70610
+ }
70611
+ }
70612
+ }
70613
+ }
70614
+ }
70615
+ delete(id, field) {
70616
+ if (this.fieldsTime.has(id)) {
70617
+ this.fieldsTime.get(id)?.delete(field);
70618
+ if (this.fieldsTime.get(id)?.size === 0) {
70619
+ this.fieldsTime.delete(id);
70620
+ }
70621
+ }
70622
+ }
70623
+ };
70624
+
70625
+ // src/runtime/cache/storage.ts
70626
+ var InMemoryStorage = class {
70627
+ data;
70628
+ idCount = 0;
70629
+ rank = 0;
70630
+ constructor() {
70631
+ this.data = [];
70632
+ }
70633
+ get layerCount() {
70634
+ return this.data.length;
70635
+ }
70636
+ get nextRank() {
70637
+ return this.rank++;
70638
+ }
70639
+ createLayer(optimistic = false) {
70640
+ const layer = new Layer(this.idCount++);
70641
+ layer.optimistic = optimistic;
70642
+ this.data.push(layer);
70643
+ return layer;
70644
+ }
70645
+ insert(id, field, location, target) {
70646
+ return this.topLayer.insert(id, field, location, target);
70647
+ }
70648
+ remove(id, field, target) {
70649
+ return this.topLayer.remove(id, field, target);
70650
+ }
70651
+ delete(id) {
70652
+ return this.topLayer.delete(id);
70653
+ }
70654
+ deleteField(id, field) {
70655
+ return this.topLayer.deleteField(id, field);
70656
+ }
70657
+ getLayer(id) {
70658
+ for (const layer of this.data) {
70659
+ if (layer.id === id) {
70660
+ return layer;
70661
+ }
70662
+ }
70663
+ throw new Error("Could not find layer with id: " + id);
70664
+ }
70665
+ replaceID(replacement) {
70666
+ for (const layer of this.data) {
70667
+ layer.replaceID(replacement);
70668
+ }
70669
+ }
70670
+ get(id, field) {
70671
+ const operations = {
70672
+ [OperationKind.insert]: {
70673
+ [OperationLocation.start]: [],
70674
+ [OperationLocation.end]: []
70675
+ },
70676
+ [OperationKind.remove]: /* @__PURE__ */ new Set()
70677
+ };
70678
+ const layerIDs = [];
70679
+ for (let i2 = this.data.length - 1; i2 >= 0; i2--) {
70680
+ const layer = this.data[i2];
70681
+ const [layerValue, kind] = layer.get(id, field);
70682
+ const layerOperations = layer.getOperations(id, field) || [];
70683
+ layer.deletedIDs.forEach((v) => {
70684
+ if (layer.operations[v]?.undoDeletesInList?.includes(field)) {
70685
+ return;
70686
+ }
70687
+ operations.remove.add(v);
70688
+ });
70689
+ if (typeof layerValue === "undefined" && layerOperations.length === 0) {
70690
+ if (layer.deletedIDs.size > 0) {
70691
+ layerIDs.push(layer.id);
70692
+ }
70693
+ continue;
70694
+ }
70695
+ if (typeof layerValue !== "undefined" && !Array.isArray(layerValue)) {
70696
+ return {
70697
+ value: layerValue,
70698
+ kind,
70699
+ displayLayers: [layer.id]
70700
+ };
70701
+ }
70702
+ layerIDs.push(layer.id);
70703
+ if (layerOperations.length > 0) {
70704
+ for (const op of layerOperations) {
70705
+ if (isRemoveOperation(op)) {
70706
+ operations.remove.add(op.id);
70707
+ }
70708
+ if (isInsertOperation(op)) {
70709
+ operations.insert[op.location].unshift(op.id);
70710
+ }
70711
+ if (isDeleteOperation(op)) {
70712
+ return {
70713
+ value: void 0,
70714
+ kind: "unknown",
70715
+ displayLayers: []
70716
+ };
70717
+ }
70718
+ }
70719
+ }
70720
+ if (typeof layerValue === "undefined") {
70721
+ continue;
70722
+ }
70723
+ if (!operations.remove.size && !operations.insert.start.length && !operations.insert.end.length) {
70724
+ return { value: layerValue, displayLayers: layerIDs, kind: "link" };
70725
+ }
70726
+ return {
70727
+ value: [...operations.insert.start, ...layerValue, ...operations.insert.end].filter(
70728
+ (value) => !operations.remove.has(value)
70729
+ ),
70730
+ displayLayers: layerIDs,
70731
+ kind
70732
+ };
70733
+ }
70734
+ return {
70735
+ value: void 0,
70736
+ kind: "unknown",
70737
+ displayLayers: []
70738
+ };
70739
+ }
70740
+ writeLink(id, field, value) {
70741
+ return this.topLayer.writeLink(id, field, value);
70742
+ }
70743
+ writeField(id, field, value) {
70744
+ return this.topLayer.writeField(id, field, value);
70745
+ }
70746
+ resolveLayer(id) {
70747
+ let startingIndex = null;
70748
+ for (const [index, layer] of this.data.entries()) {
70749
+ if (layer.id !== id) {
70750
+ continue;
70751
+ }
70752
+ startingIndex = index - 1;
70753
+ this.data[index].optimistic = false;
70754
+ break;
70755
+ }
70756
+ if (startingIndex === null) {
70757
+ throw new Error("could not find layer with id: " + id);
70758
+ }
70759
+ if (startingIndex === -1) {
70760
+ startingIndex = 0;
70761
+ }
70762
+ if (this.data[startingIndex].optimistic) {
70763
+ startingIndex++;
70764
+ }
70765
+ const baseLayer = this.data[startingIndex];
70766
+ let layerIndex = startingIndex;
70767
+ while (layerIndex < this.data.length) {
70768
+ const layer = this.data[layerIndex++];
70769
+ if (layer.optimistic) {
70770
+ layerIndex--;
70771
+ break;
70772
+ }
70773
+ baseLayer.writeLayer(layer);
70774
+ }
70775
+ this.data.splice(startingIndex + 1, layerIndex - startingIndex - 1);
70776
+ }
70777
+ get topLayer() {
70778
+ if (this.data.length === 0) {
70779
+ this.createLayer();
70780
+ }
70781
+ if (this.data[this.data.length - 1]?.optimistic) {
70782
+ this.createLayer();
70783
+ }
70784
+ return this.data[this.data.length - 1];
70785
+ }
70786
+ };
70787
+ var Layer = class {
70788
+ id;
70789
+ optimistic = false;
70790
+ fields = {};
70791
+ links = {};
70792
+ operations = {};
70793
+ deletedIDs = /* @__PURE__ */ new Set();
70794
+ constructor(id) {
70795
+ this.id = id;
70796
+ }
70797
+ get(id, field) {
70798
+ if (typeof this.links[id]?.[field] !== "undefined") {
70799
+ return [this.links[id][field], "link"];
70800
+ }
70801
+ return [this.fields[id]?.[field], "scalar"];
70802
+ }
70803
+ getOperations(id, field) {
70804
+ if (this.operations[id]?.deleted) {
70805
+ return [
70806
+ {
70807
+ kind: OperationKind.delete,
70808
+ target: id
70809
+ }
70810
+ ];
70811
+ }
70812
+ if (this.operations[id]?.fields?.[field]) {
70813
+ return this.operations[id].fields[field];
70814
+ }
70815
+ }
70816
+ writeField(id, field, value) {
70817
+ this.fields[id] = {
70818
+ ...this.fields[id],
70819
+ [field]: value
70820
+ };
70821
+ return this.id;
70822
+ }
70823
+ writeLink(id, field, value) {
70824
+ const valueList = Array.isArray(value) ? value : [value];
70825
+ for (const value2 of flatten(valueList)) {
70826
+ if (!value2) {
70827
+ continue;
70828
+ }
70829
+ const fieldOperations = this.operations[id]?.fields[field];
70830
+ if (this.operations[value2]?.deleted || this.deletedIDs.has(value2)) {
70831
+ this.operations[value2] = {
70832
+ ...this.operations[value2],
70833
+ undoDeletesInList: [...this.operations[id]?.undoDeletesInList || [], field]
70834
+ };
70835
+ } else if (value2 && fieldOperations?.length > 0) {
70836
+ this.operations[id].fields[field] = fieldOperations.filter(
70837
+ (op) => op.kind !== "remove" || op.id !== value2
70838
+ );
70839
+ }
70840
+ }
70841
+ this.links[id] = {
70842
+ ...this.links[id],
70843
+ [field]: value
70844
+ };
70845
+ return this.id;
70846
+ }
70847
+ isDisplayLayer(displayLayers) {
70848
+ return displayLayers.length === 0 || displayLayers.includes(this.id) || Math.max(...displayLayers) < this.id;
70849
+ }
70850
+ clear() {
70851
+ this.links = {};
70852
+ this.fields = {};
70853
+ this.operations = {};
70854
+ this.deletedIDs = /* @__PURE__ */ new Set();
70855
+ }
70856
+ replaceID({ from, to }) {
70857
+ this.fields[to] = this.fields[from];
70858
+ this.links[to] = this.links[from];
70859
+ this.operations[to] = this.operations[from] || { fields: {} };
70860
+ if (this.deletedIDs.has(from)) {
70861
+ this.deletedIDs.add(to);
70862
+ }
70863
+ }
70864
+ removeUndefinedFields() {
70865
+ for (const [id, fields] of Object.entries(this.fields)) {
70866
+ for (const [field, value] of Object.entries(fields)) {
70867
+ if (typeof value === "undefined") {
70868
+ try {
70869
+ delete this.fields[id][field];
70870
+ } catch {
70871
+ }
70872
+ try {
70873
+ delete this.links[id][field];
70874
+ } catch {
70875
+ }
70876
+ }
70877
+ }
70878
+ if (Object.keys(fields || {}).length === 0) {
70879
+ delete this.fields[id];
70880
+ }
70881
+ if (Object.keys(this.links[id] || {}).length === 0) {
70882
+ delete this.links[id];
70883
+ }
70884
+ }
70885
+ }
70886
+ delete(id) {
70887
+ this.operations = {
70888
+ ...this.operations,
70889
+ [id]: {
70890
+ ...this.operations[id],
70891
+ deleted: true,
70892
+ undoDeletesInList: []
70893
+ }
70894
+ };
70895
+ this.deletedIDs.add(id);
70896
+ }
70897
+ deleteField(id, field) {
70898
+ this.fields[id] = {
70899
+ ...this.fields[id],
70900
+ [field]: void 0
70901
+ };
70902
+ }
70903
+ insert(id, field, where, target) {
70904
+ this.addFieldOperation(id, field, {
70905
+ kind: OperationKind.insert,
70906
+ id: target,
70907
+ location: where
70908
+ });
70909
+ }
70910
+ remove(id, field, target) {
70911
+ this.addFieldOperation(id, field, {
70912
+ kind: OperationKind.remove,
70913
+ id: target
70914
+ });
70915
+ }
70916
+ writeLayer(layer) {
70917
+ if (layer.id === this.id) {
70918
+ return;
70919
+ }
70920
+ for (const [id, ops] of Object.entries(layer.operations)) {
70921
+ const fields = {};
70922
+ for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
70923
+ for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
70924
+ fields[fieldName] = [...fields[fieldName] || [], ...operations];
70925
+ }
70926
+ }
70927
+ if (Object.keys(fields).length > 0) {
70928
+ this.operations[id] = {
70929
+ ...this.operations[id],
70930
+ fields
70931
+ };
70932
+ }
70933
+ if (ops?.deleted) {
70934
+ delete this.fields[id];
70935
+ delete this.links[id];
70936
+ }
70937
+ }
70938
+ for (const [id, values] of Object.entries(layer.fields)) {
70939
+ if (!values) {
70940
+ continue;
70941
+ }
70942
+ for (const [field, value] of Object.entries(values)) {
70943
+ this.writeField(id, field, value);
70944
+ }
70945
+ }
70946
+ for (const [id, values] of Object.entries(layer.links)) {
70947
+ if (!values) {
70948
+ continue;
70949
+ }
70950
+ for (const [field, value] of Object.entries(values)) {
70951
+ this.writeLink(id, field, value);
70952
+ }
70953
+ }
70954
+ layer.deletedIDs.forEach((v) => this.deletedIDs.add(v));
70955
+ }
70956
+ addFieldOperation(id, field, operation) {
70957
+ this.operations = {
70958
+ ...this.operations,
70959
+ [id]: {
70960
+ ...this.operations[id],
70961
+ fields: {
70962
+ [field]: [...this.operations[id]?.fields[field] || [], operation]
70963
+ }
70964
+ }
70965
+ };
70966
+ }
70967
+ };
70968
+ function isDeleteOperation(value) {
70969
+ return !!value && value.kind === OperationKind.delete;
70970
+ }
70971
+ function isInsertOperation(value) {
70972
+ return !!value && value.kind === OperationKind.insert;
70973
+ }
70974
+ function isRemoveOperation(value) {
70975
+ return !!value && value.kind === OperationKind.remove;
70976
+ }
70977
+ var OperationLocation = {
70978
+ start: "start",
70979
+ end: "end"
70980
+ };
70981
+ var OperationKind = {
70982
+ delete: "delete",
70983
+ insert: "insert",
70984
+ remove: "remove"
70985
+ };
70986
+
70987
+ // src/runtime/cache/stuff.ts
70988
+ function evaluateKey(key, variables = {}) {
70989
+ let evaluated = "";
70990
+ let varName = "";
70991
+ let inString = false;
70992
+ for (const char of key) {
70993
+ if (varName) {
70994
+ if (varChars.includes(char)) {
70995
+ varName += char;
70996
+ continue;
70997
+ }
70998
+ const value = variables[varName.slice(1)];
70999
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
71000
+ varName = "";
71001
+ }
71002
+ if (char === "$" && !inString) {
71003
+ varName = "$";
71004
+ continue;
71005
+ }
71006
+ if (char === '"') {
71007
+ inString = !inString;
71008
+ }
71009
+ evaluated += char;
71010
+ }
71011
+ return evaluated;
71012
+ }
71013
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
71014
+
71015
+ // src/runtime/cache/subscription.ts
71016
+ var InMemorySubscriptions = class {
71017
+ cache;
71018
+ constructor(cache) {
71019
+ this.cache = cache;
71020
+ }
71021
+ subscribers = {};
71022
+ referenceCounts = {};
71023
+ keyVersions = {};
71024
+ add({
71025
+ parent,
71026
+ spec,
71027
+ selection: selection2,
71028
+ variables,
71029
+ parentType
71030
+ }) {
71031
+ const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
71032
+ let targetSelection = getFieldsForType(selection2, __typename);
71033
+ for (const fieldSelection of Object.values(targetSelection || {})) {
71034
+ const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
71035
+ const key = evaluateKey(keyRaw, variables);
71036
+ let targetSelection2;
71037
+ if (innerSelection) {
71038
+ const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
71039
+ targetSelection2 = getFieldsForType(innerSelection, __typename2);
71040
+ }
71041
+ this.addFieldSubscription({
71042
+ id: parent,
71043
+ key,
71044
+ selection: [spec, targetSelection2],
71045
+ type
71046
+ });
71047
+ if (list) {
71048
+ this.registerList({
71049
+ list,
71050
+ filters,
71051
+ id: parent,
71052
+ key,
71053
+ variables,
71054
+ selection: innerSelection,
71055
+ parentType: parentType || spec.rootType
71056
+ });
71057
+ }
71058
+ if (innerSelection) {
71059
+ const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
71060
+ parent,
71061
+ key
71062
+ );
71063
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
71064
+ for (const child of children) {
71065
+ if (!child) {
71066
+ continue;
71067
+ }
71068
+ this.add({
71069
+ parent: child,
71070
+ spec,
71071
+ selection: innerSelection,
71072
+ variables,
71073
+ parentType: type
71074
+ });
71075
+ }
71076
+ }
71077
+ }
71078
+ }
71079
+ addFieldSubscription({
71080
+ id,
71081
+ key,
71082
+ selection: selection2,
71083
+ type
71084
+ }) {
71085
+ const spec = selection2[0];
71086
+ if (!this.subscribers[id]) {
71087
+ this.subscribers[id] = {};
71088
+ }
71089
+ if (!this.subscribers[id][key]) {
71090
+ this.subscribers[id][key] = [];
71091
+ }
71092
+ if (!this.keyVersions[key]) {
71093
+ this.keyVersions[key] = /* @__PURE__ */ new Set();
71094
+ }
71095
+ this.keyVersions[key].add(key);
71096
+ if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
71097
+ this.subscribers[id][key].push([spec, selection2[1]]);
71098
+ }
71099
+ if (!this.referenceCounts[id]) {
71100
+ this.referenceCounts[id] = {};
71101
+ }
71102
+ if (!this.referenceCounts[id][key]) {
71103
+ this.referenceCounts[id][key] = /* @__PURE__ */ new Map();
71104
+ }
71105
+ const counts = this.referenceCounts[id][key];
71106
+ counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
71107
+ this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
71108
+ const { selection: innerSelection } = selection2[1]?.[key] ?? {};
71109
+ }
71110
+ registerList({
71111
+ list,
71112
+ id,
71113
+ key,
71114
+ parentType,
71115
+ selection: selection2,
71116
+ filters,
71117
+ variables
71118
+ }) {
71119
+ this.cache._internal_unstable.lists.add({
71120
+ name: list.name,
71121
+ connection: list.connection,
71122
+ recordID: id,
71123
+ recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
71124
+ listType: list.type,
71125
+ key,
71126
+ selection: selection2,
71127
+ filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
71128
+ return {
71129
+ ...acc,
71130
+ [key2]: kind !== "Variable" ? value : variables[value]
71131
+ };
71132
+ }, {})
71133
+ });
71134
+ }
71135
+ addMany({
71136
+ parent,
71137
+ variables,
71138
+ subscribers,
71139
+ parentType
71140
+ }) {
71141
+ for (const [spec, targetSelection] of subscribers) {
71142
+ for (const selection2 of Object.values(targetSelection ?? {})) {
71143
+ const {
71144
+ type: linkedType,
71145
+ keyRaw,
71146
+ selection: innerSelection,
71147
+ list,
71148
+ filters
71149
+ } = selection2;
71150
+ const key = evaluateKey(keyRaw, variables);
71151
+ const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
71152
+ this.addFieldSubscription({
71153
+ id: parent,
71154
+ key,
71155
+ selection: [spec, fieldSelection],
71156
+ type: linkedType
71157
+ });
71158
+ if (list) {
71159
+ this.registerList({
71160
+ list,
71161
+ filters,
71162
+ id: parent,
71163
+ key,
71164
+ variables,
71165
+ selection: innerSelection,
71166
+ parentType: parentType || spec.rootType
71167
+ });
71168
+ }
71169
+ const childSelection = selection2.selection;
71170
+ if (childSelection) {
71171
+ const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
71172
+ const children = !Array.isArray(link) ? [link] : flatten(link);
71173
+ for (const linkedRecord of children) {
71174
+ if (!linkedRecord) {
71175
+ continue;
71176
+ }
71177
+ const __typename = this.cache._internal_unstable.storage.get(
71178
+ linkedRecord,
71179
+ "__typename"
71180
+ ).value;
71181
+ let targetSelection2 = getFieldsForType(childSelection, __typename);
71182
+ this.addMany({
71183
+ parent: linkedRecord,
71184
+ variables,
71185
+ subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
71186
+ parentType: linkedType
71187
+ });
71188
+ }
71189
+ }
71190
+ }
71191
+ }
71192
+ }
71193
+ get(id, field) {
71194
+ return this.subscribers[id]?.[field] || [];
71195
+ }
71196
+ remove(id, selection2, targets, variables, visited = []) {
71197
+ visited.push(id);
71198
+ const linkedIDs = [];
71199
+ const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
71200
+ let targetSelection = getFieldsForType(selection2, __typename);
71201
+ for (const fieldSelection of Object.values(targetSelection || {})) {
71202
+ const key = evaluateKey(fieldSelection.keyRaw, variables);
71203
+ this.removeSubscribers(id, key, targets);
71204
+ if (!fieldSelection.selection) {
71205
+ continue;
71206
+ }
71207
+ const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
71208
+ const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
71209
+ for (const link of links) {
71210
+ if (link !== null) {
71211
+ linkedIDs.push([link, fieldSelection.selection || {}]);
71212
+ }
71213
+ }
71214
+ }
71215
+ for (const [linkedRecordID, linkFields] of linkedIDs) {
71216
+ this.remove(linkedRecordID, linkFields, targets, visited);
71217
+ }
71218
+ }
71219
+ removeSubscribers(id, fieldName, specs) {
71220
+ let targets = [];
71221
+ for (const spec of specs) {
71222
+ if (!this.referenceCounts[id]?.[fieldName]?.has(spec.set)) {
71223
+ continue;
71224
+ }
71225
+ const counts = this.referenceCounts[id][fieldName];
71226
+ const newVal = (counts.get(spec.set) || 0) - 1;
71227
+ counts.set(spec.set, newVal);
71228
+ if (newVal <= 0) {
71229
+ targets.push(spec.set);
71230
+ counts.delete(spec.set);
71231
+ }
71232
+ }
71233
+ if (this.subscribers[id]) {
71234
+ this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
71235
+ ([{ set }]) => !targets.includes(set)
71236
+ );
71237
+ }
71238
+ }
71239
+ removeAllSubscribers(id, targets, visited = []) {
71240
+ visited.push(id);
71241
+ for (const field of Object.keys(this.subscribers[id] || [])) {
71242
+ const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
71243
+ this.removeSubscribers(id, field, subscribers);
71244
+ const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
71245
+ if (kind === "scalar") {
71246
+ continue;
71247
+ }
71248
+ const nextTargets = Array.isArray(value) ? flatten(value) : [value];
71249
+ for (const id2 of nextTargets) {
71250
+ if (visited.includes(id2)) {
71251
+ continue;
71252
+ }
71253
+ this.removeAllSubscribers(id2, subscribers, visited);
71254
+ }
71255
+ }
71256
+ }
71257
+ };
71258
+
71259
+ // src/runtime/cache/cache.ts
71260
+ var Cache = class {
71261
+ _internal_unstable;
71262
+ constructor(config2) {
71263
+ this._internal_unstable = new CacheInternal({
71264
+ cache: this,
71265
+ storage: new InMemoryStorage(),
71266
+ subscriptions: new InMemorySubscriptions(this),
71267
+ lists: new ListManager(this, rootID),
71268
+ lifetimes: new GarbageCollector(this),
71269
+ staleManager: new StaleManager(this),
71270
+ schema: new SchemaManager(this)
71271
+ });
71272
+ if (config2) {
71273
+ this.setConfig(defaultConfigValues(config2));
71274
+ }
71275
+ }
71276
+ write({
71277
+ layer: layerID,
71278
+ notifySubscribers = [],
71279
+ ...args
71280
+ }) {
71281
+ const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
71282
+ const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
71283
+ const notified = [];
71284
+ for (const spec of subscribers.concat(notifySubscribers)) {
71285
+ if (!notified.includes(spec.set)) {
71286
+ notified.push(spec.set);
71287
+ spec.set(
71288
+ this._internal_unstable.getSelection({
71289
+ parent: spec.parentID || rootID,
71290
+ selection: spec.selection,
71291
+ variables: spec.variables?.() || {}
71292
+ }).data
71293
+ );
71294
+ }
71295
+ }
71296
+ return subscribers;
71297
+ }
71298
+ read(...args) {
71299
+ const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
71300
+ if (!hasData) {
71301
+ return { data: null, partial: false, stale: false };
71302
+ }
71303
+ return {
71304
+ data,
71305
+ partial,
71306
+ stale
71307
+ };
71308
+ }
71309
+ subscribe(spec, variables = {}) {
71310
+ return this._internal_unstable.subscriptions.add({
71311
+ parent: spec.parentID || rootID,
71312
+ spec,
71313
+ selection: spec.selection,
71314
+ variables
71315
+ });
71316
+ }
71317
+ unsubscribe(spec, variables = {}) {
71318
+ return this._internal_unstable.subscriptions.remove(
71319
+ spec.parentID || rootID,
71320
+ spec.selection,
71321
+ [spec],
71322
+ variables
71323
+ );
71324
+ }
71325
+ list(name, parentID, allLists) {
71326
+ const handler = this._internal_unstable.lists.get(name, parentID, allLists);
71327
+ if (!handler) {
71328
+ throw new Error(
71329
+ `Cannot find list with name: ${name}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
71330
+ );
71331
+ }
71332
+ return handler;
71333
+ }
71334
+ delete(id) {
71335
+ this._internal_unstable.subscriptions.removeAllSubscribers(id);
71336
+ this._internal_unstable.lists.removeIDFromAllLists(id);
71337
+ this._internal_unstable.storage.delete(id);
71338
+ }
71339
+ setConfig(config2) {
71340
+ this._internal_unstable.setConfig(config2);
71341
+ }
71342
+ markTypeStale(options) {
71343
+ if (!options) {
71344
+ this._internal_unstable.staleManager.markAllStale();
71345
+ } else if (!options.field) {
71346
+ this._internal_unstable.staleManager.markTypeStale(options.type);
71347
+ } else {
71348
+ this._internal_unstable.staleManager.markTypeFieldStale(
71349
+ options.type,
71350
+ options.field,
71351
+ options.when
71352
+ );
71353
+ }
71354
+ }
71355
+ markRecordStale(id, options) {
71356
+ if (options.field) {
71357
+ const key = computeKey({ field: options.field, args: options.when ?? {} });
71358
+ this._internal_unstable.staleManager.markFieldStale(id, key);
71359
+ } else {
71360
+ this._internal_unstable.staleManager.markRecordStale(id);
71361
+ }
71362
+ }
71363
+ getFieldTime(id, field) {
71364
+ return this._internal_unstable.staleManager.getFieldTime(id, field);
71365
+ }
71366
+ };
71367
+ var CacheInternal = class {
71368
+ _disabled = false;
71369
+ config = defaultConfigValues({
71370
+ plugins: {
71371
+ "houdini-svelte": {
71372
+ client: ""
71373
+ }
71374
+ }
71375
+ });
71376
+ storage;
71377
+ subscriptions;
71378
+ lists;
71379
+ cache;
71380
+ lifetimes;
71381
+ staleManager;
71382
+ schema;
71383
+ constructor({
71384
+ storage,
71385
+ subscriptions,
71386
+ lists,
71387
+ cache,
71388
+ lifetimes,
71389
+ staleManager,
71390
+ schema
71391
+ }) {
71392
+ this.storage = storage;
71393
+ this.subscriptions = subscriptions;
71394
+ this.lists = lists;
71395
+ this.cache = cache;
71396
+ this.lifetimes = lifetimes;
71397
+ this.staleManager = staleManager;
71398
+ this.schema = schema;
71399
+ this._disabled = typeof globalThis.window === "undefined";
71400
+ try {
71401
+ if (process.env.HOUDINI_TEST === "true") {
71402
+ this._disabled = false;
71403
+ }
71404
+ } catch {
71405
+ }
71406
+ }
71407
+ setConfig(config2) {
71408
+ this.config = config2;
71409
+ }
71410
+ writeSelection({
71411
+ data,
71412
+ selection: selection2,
71413
+ variables = {},
71414
+ parent = rootID,
71415
+ applyUpdates,
71416
+ layer,
71417
+ toNotify = [],
71418
+ forceNotify,
71419
+ forceStale
71420
+ }) {
71421
+ if (this._disabled) {
71422
+ return [];
71423
+ }
71424
+ let targetSelection = getFieldsForType(selection2, data["__typename"]);
71425
+ for (const [field, value] of Object.entries(data)) {
71426
+ if (!selection2 || !targetSelection[field]) {
71427
+ throw new Error(
71428
+ "Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection2)
71429
+ );
71430
+ }
71431
+ let {
71432
+ type: linkedType,
71433
+ keyRaw,
71434
+ selection: fieldSelection,
71435
+ operations,
71436
+ abstract: isAbstract,
71437
+ updates,
71438
+ nullable
71439
+ } = targetSelection[field];
71440
+ const key = evaluateKey(keyRaw, variables);
71441
+ this.schema.setFieldType({
71442
+ parent,
71443
+ key: keyRaw,
71444
+ type: linkedType,
71445
+ nullable,
71446
+ link: !!fieldSelection
71447
+ });
71448
+ const currentSubscribers = this.subscriptions.get(parent, key);
71449
+ const specs = currentSubscribers.map((sub) => sub[0]);
71450
+ const { value: previousValue, displayLayers } = this.storage.get(parent, key);
71451
+ const displayLayer = layer.isDisplayLayer(displayLayers);
71452
+ if (displayLayer) {
71453
+ this.lifetimes.resetLifetime(parent, key);
71454
+ if (forceStale) {
71455
+ this.staleManager.markFieldStale(parent, key);
71456
+ } else {
71457
+ this.staleManager.setFieldTimeToNow(parent, key);
71458
+ }
71459
+ }
71460
+ if (!fieldSelection) {
71461
+ let newValue = value;
71462
+ if (updates && applyUpdates && Array.isArray(value)) {
71463
+ for (const update of applyUpdates) {
71464
+ if (!updates.includes(update)) {
71465
+ continue;
71466
+ }
71467
+ if (update === "append") {
71468
+ newValue = (previousValue || []).concat(value);
71469
+ } else if (update === "prepend") {
71470
+ newValue = value.concat(previousValue || []);
71471
+ }
71472
+ }
71473
+ }
71474
+ if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
71475
+ newValue = previousValue;
71476
+ } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
71477
+ newValue = previousValue;
71478
+ }
71479
+ const valueChanged = !deepEquals(newValue, previousValue);
71480
+ if (displayLayer && (valueChanged || forceNotify)) {
71481
+ toNotify.push(...currentSubscribers);
71482
+ }
71483
+ layer.writeField(parent, key, newValue);
71484
+ } else if (value === null) {
71485
+ if (previousValue === null) {
71486
+ continue;
71487
+ }
71488
+ const previousLinks = flatten([previousValue]);
71489
+ for (const link of previousLinks) {
71490
+ this.subscriptions.remove(link, fieldSelection, specs, variables);
71491
+ }
71492
+ layer.writeLink(parent, key, null);
71493
+ toNotify.push(...currentSubscribers);
71494
+ } else if (value instanceof Object && !Array.isArray(value)) {
71495
+ if (isAbstract) {
71496
+ if (!value.__typename) {
71497
+ throw new Error(
71498
+ "Encountered interface type without __typename in the payload"
71499
+ );
71500
+ }
71501
+ linkedType = value.__typename;
71502
+ }
71503
+ const embedded = this.idFields(linkedType)?.filter(
71504
+ (field2) => typeof value[field2] === "undefined"
71505
+ ).length > 0;
71506
+ let linkedID = null;
71507
+ if (value !== null) {
71508
+ linkedID = !embedded ? this.id(linkedType, value) : `${parent}.${key}`;
71509
+ }
71510
+ let linkChange = linkedID !== previousValue;
71511
+ layer.writeLink(parent, key, linkedID);
71512
+ if (linkedID && displayLayer && (linkChange || forceNotify)) {
71513
+ if (previousValue && typeof previousValue === "string") {
71514
+ this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
71515
+ }
71516
+ this.subscriptions.addMany({
71517
+ parent: linkedID,
71518
+ subscribers: currentSubscribers,
71519
+ variables,
71520
+ parentType: linkedType
71521
+ });
71522
+ toNotify.push(...currentSubscribers);
71523
+ }
71524
+ if (linkedID) {
71525
+ this.writeSelection({
71526
+ selection: fieldSelection,
71527
+ parent: linkedID,
71528
+ data: value,
71529
+ variables,
71530
+ toNotify,
71531
+ applyUpdates,
71532
+ layer,
71533
+ forceNotify
71534
+ });
71535
+ }
71536
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
71537
+ let oldIDs = [...previousValue || []];
71538
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
71539
+ if (!id) {
71540
+ return "";
71541
+ }
71542
+ const { value: cursorField } = this.storage.get(id, "cursor");
71543
+ if (cursorField) {
71544
+ return "";
71545
+ }
71546
+ const { value: node } = this.storage.get(id, "node");
71547
+ if (!node) {
71548
+ return "";
71549
+ }
71550
+ return node;
71551
+ });
71552
+ let linkedIDs = [];
71553
+ const { newIDs, nestedIDs } = this.extractNestedListIDs({
71554
+ value,
71555
+ abstract: Boolean(isAbstract),
71556
+ specs: toNotify,
71557
+ applyUpdates,
71558
+ recordID: parent,
71559
+ key,
71560
+ linkedType,
71561
+ variables,
71562
+ fields: fieldSelection,
71563
+ layer,
71564
+ forceNotify
71565
+ });
71566
+ if (applyUpdates && updates) {
71567
+ if (key === "edges") {
71568
+ const newNodeIDs = [];
71569
+ for (const id of newIDs) {
71570
+ if (!id) {
71571
+ continue;
71572
+ }
71573
+ const { value: node } = this.storage.get(id, "node");
71574
+ if (typeof node !== "string") {
71575
+ continue;
71576
+ }
71577
+ if (!node || !this.storage.get(node, "__typename")) {
71578
+ continue;
71579
+ }
71580
+ newNodeIDs.push(node);
71581
+ }
71582
+ oldIDs = oldIDs.filter((id) => {
71583
+ if (!id) {
71584
+ return true;
71585
+ }
71586
+ const { value: value2 } = this.storage.get(id, "node");
71587
+ const node = value2;
71588
+ if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
71589
+ return false;
71590
+ }
71591
+ return true;
71592
+ });
71593
+ }
71594
+ for (const update of applyUpdates) {
71595
+ if (update !== "replace" && !updates.includes(update)) {
71596
+ continue;
71597
+ }
71598
+ if (update === "prepend") {
71599
+ linkedIDs = newIDs.concat(oldIDs);
71600
+ } else if (update === "append") {
71601
+ linkedIDs = oldIDs.concat(newIDs);
71602
+ } else if (update === "replace") {
71603
+ linkedIDs = newIDs;
71604
+ }
71605
+ }
71606
+ } else {
71607
+ linkedIDs = nestedIDs;
71608
+ }
71609
+ const contentChanged = !deepEquals(linkedIDs, oldIDs);
71610
+ if (contentChanged || forceNotify) {
71611
+ toNotify.push(...currentSubscribers);
71612
+ }
71613
+ for (const lostID of oldIDs) {
71614
+ if (linkedIDs.includes(lostID) || !lostID) {
71615
+ continue;
71616
+ }
71617
+ this.subscriptions.remove(lostID, fieldSelection, specs, variables);
71618
+ }
71619
+ if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
71620
+ layer.writeLink(parent, key, linkedIDs);
71621
+ }
71622
+ for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
71623
+ if (id == null) {
71624
+ continue;
71625
+ }
71626
+ this.subscriptions.addMany({
71627
+ parent: id,
71628
+ subscribers: currentSubscribers,
71629
+ variables,
71630
+ parentType: linkedType
71631
+ });
71632
+ }
71633
+ }
71634
+ for (const operation of operations || []) {
71635
+ let parentID;
71636
+ if (operation.parentID) {
71637
+ if (operation.parentID.kind !== "Variable") {
71638
+ parentID = operation.parentID.value;
71639
+ } else {
71640
+ const id = variables[operation.parentID.value];
71641
+ if (typeof id !== "string") {
71642
+ throw new Error("parentID value must be a string");
71643
+ }
71644
+ parentID = id;
71645
+ }
71646
+ }
71647
+ if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
71648
+ continue;
71649
+ }
71650
+ const targets = Array.isArray(value) ? value : [value];
71651
+ for (const target of targets) {
71652
+ if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
71653
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
71654
+ fieldSelection,
71655
+ target,
71656
+ variables,
71657
+ operation.position || "last"
71658
+ );
71659
+ } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
71660
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
71661
+ } else if (operation.action === "delete" && operation.type) {
71662
+ if (typeof target !== "string") {
71663
+ throw new Error("Cannot delete a record with a non-string ID");
71664
+ }
71665
+ const targetID = this.id(operation.type, target);
71666
+ if (!targetID) {
71667
+ continue;
71668
+ }
71669
+ this.cache.delete(targetID);
71670
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
71671
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
71672
+ fieldSelection,
71673
+ target,
71674
+ variables,
71675
+ operation.position || "last"
71676
+ );
71677
+ }
71678
+ }
71679
+ }
71680
+ }
71681
+ return toNotify;
71682
+ }
71683
+ getSelection({
71684
+ selection: selection2,
71685
+ parent = rootID,
71686
+ variables,
71687
+ stepsFromConnection = null
71688
+ }) {
71689
+ if (parent === null) {
71690
+ return { data: null, partial: false, stale: false, hasData: true };
71691
+ }
71692
+ const target = {};
71693
+ let hasData = false;
71694
+ let partial = false;
71695
+ let cascadeNull = false;
71696
+ let stale = false;
71697
+ const typename = this.storage.get(parent, "__typename").value;
71698
+ let targetSelection = getFieldsForType(selection2, typename);
71699
+ for (const [
71700
+ attributeName,
71701
+ { type, keyRaw, selection: fieldSelection, nullable, list }
71702
+ ] of Object.entries(targetSelection)) {
71703
+ const key = evaluateKey(keyRaw, variables);
71704
+ const { value } = this.storage.get(parent, key);
71705
+ const dt_field = this.staleManager.getFieldTime(parent, key);
71706
+ if (dt_field === null) {
71707
+ stale = true;
71708
+ }
71709
+ let nextStep = stepsFromConnection;
71710
+ if (nextStep !== null) {
71711
+ if (nextStep >= 2) {
71712
+ nextStep = null;
71713
+ } else {
71714
+ nextStep += 1;
71715
+ }
71716
+ }
71717
+ if (list?.connection) {
71718
+ nextStep = 0;
71719
+ }
71720
+ const embeddedCursor = key === "cursor" && stepsFromConnection === 1;
71721
+ if (typeof value === "undefined" && !embeddedCursor) {
71722
+ partial = true;
71723
+ }
71724
+ if (typeof value === "undefined" || value === null) {
71725
+ target[attributeName] = null;
71726
+ if (typeof value !== "undefined") {
71727
+ hasData = true;
71728
+ }
71729
+ } else if (!fieldSelection) {
71730
+ const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
71731
+ if (fnUnmarshal) {
71732
+ target[attributeName] = fnUnmarshal(value);
71733
+ } else {
71734
+ target[attributeName] = value;
71735
+ }
71736
+ hasData = true;
71737
+ } else if (Array.isArray(value)) {
71738
+ const listValue = this.hydrateNestedList({
71739
+ fields: fieldSelection,
71740
+ variables,
71741
+ linkedList: value,
71742
+ stepsFromConnection: nextStep
71743
+ });
71744
+ target[attributeName] = listValue.data;
71745
+ if (listValue.partial) {
71746
+ partial = true;
71747
+ }
71748
+ if (listValue.stale) {
71749
+ stale = true;
71750
+ }
71751
+ if (listValue.hasData || value.length === 0) {
71752
+ hasData = true;
71753
+ }
71754
+ } else {
71755
+ const objectFields = this.getSelection({
71756
+ parent: value,
71757
+ selection: fieldSelection,
71758
+ variables,
71759
+ stepsFromConnection: nextStep
71760
+ });
71761
+ target[attributeName] = objectFields.data;
71762
+ if (objectFields.partial) {
71763
+ partial = true;
71764
+ }
71765
+ if (objectFields.stale) {
71766
+ stale = true;
71767
+ }
71768
+ if (objectFields.hasData) {
71769
+ hasData = true;
71770
+ }
71771
+ }
71772
+ if (target[attributeName] === null && !nullable && !embeddedCursor) {
71773
+ cascadeNull = true;
71774
+ }
71775
+ }
71776
+ return {
71777
+ data: cascadeNull ? null : target,
71778
+ partial: hasData && partial,
71779
+ stale: hasData && stale,
71780
+ hasData
71781
+ };
71782
+ }
71783
+ id(type, data) {
71784
+ const id = typeof data === "string" ? data : this.computeID(type, data);
71785
+ if (!id) {
71786
+ return null;
71787
+ }
71788
+ if (!type) {
71789
+ return id;
71790
+ }
71791
+ return type + ":" + id;
71792
+ }
71793
+ idFields(type) {
71794
+ return keyFieldsForType(this.config, type);
71795
+ }
71796
+ computeID(type, data) {
71797
+ return computeID(this.config, type, data);
71798
+ }
71799
+ hydrateNestedList({
71800
+ fields,
71801
+ variables,
71802
+ linkedList,
71803
+ stepsFromConnection
71804
+ }) {
71805
+ const result = [];
71806
+ let partialData = false;
71807
+ let stale = false;
71808
+ let hasValues = false;
71809
+ for (const entry of linkedList) {
71810
+ if (Array.isArray(entry)) {
71811
+ const nestedValue = this.hydrateNestedList({
71812
+ fields,
71813
+ variables,
71814
+ linkedList: entry,
71815
+ stepsFromConnection
71816
+ });
71817
+ result.push(nestedValue.data);
71818
+ if (nestedValue.partial) {
71819
+ partialData = true;
71820
+ }
71821
+ continue;
71822
+ }
71823
+ if (entry === null) {
71824
+ result.push(entry);
71825
+ continue;
71826
+ }
71827
+ const {
71828
+ data,
71829
+ partial,
71830
+ stale: local_stale,
71831
+ hasData
71832
+ } = this.getSelection({
71833
+ parent: entry,
71834
+ selection: fields,
71835
+ variables,
71836
+ stepsFromConnection
71837
+ });
71838
+ result.push(data);
71839
+ if (partial) {
71840
+ partialData = true;
71841
+ }
71842
+ if (local_stale) {
71843
+ stale = true;
71844
+ }
71845
+ if (hasData) {
71846
+ hasValues = true;
71847
+ }
71848
+ }
71849
+ return {
71850
+ data: result,
71851
+ partial: partialData,
71852
+ stale,
71853
+ hasData: hasValues
71854
+ };
71855
+ }
71856
+ extractNestedListIDs({
71857
+ value,
71858
+ abstract,
71859
+ recordID,
71860
+ key,
71861
+ linkedType,
71862
+ fields,
71863
+ variables,
71864
+ applyUpdates,
71865
+ specs,
71866
+ layer,
71867
+ forceNotify
71868
+ }) {
71869
+ const nestedIDs = [];
71870
+ const newIDs = [];
71871
+ for (const [i2, entry] of value.entries()) {
71872
+ if (Array.isArray(entry)) {
71873
+ const inner = this.extractNestedListIDs({
71874
+ value: entry,
71875
+ abstract,
71876
+ recordID,
71877
+ key,
71878
+ linkedType,
71879
+ fields,
71880
+ variables,
71881
+ applyUpdates,
71882
+ specs,
71883
+ layer,
71884
+ forceNotify
71885
+ });
71886
+ newIDs.push(...inner.newIDs);
71887
+ nestedIDs[i2] = inner.nestedIDs;
71888
+ continue;
71889
+ }
71890
+ if (entry === null || typeof entry === "undefined") {
71891
+ newIDs.push(null);
71892
+ nestedIDs[i2] = null;
71893
+ continue;
71894
+ }
71895
+ const entryObj = entry;
71896
+ let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
71897
+ const embedded = this.idFields(linkedType)?.filter(
71898
+ (field) => typeof entry[field] === "undefined"
71899
+ ).length > 0;
71900
+ const typename = entryObj.__typename;
71901
+ let innerType = linkedType;
71902
+ if (abstract) {
71903
+ if (!typename) {
71904
+ throw new Error("Encountered interface type without __typename in the payload");
71905
+ }
71906
+ innerType = typename;
71907
+ }
71908
+ if (!embedded) {
71909
+ const id = this.id(innerType, entry);
71910
+ if (id) {
71911
+ linkedID = id;
71912
+ } else {
71913
+ continue;
71914
+ }
71915
+ }
71916
+ this.writeSelection({
71917
+ root: rootID,
71918
+ selection: fields,
71919
+ parent: linkedID,
71920
+ data: entryObj,
71921
+ variables,
71922
+ toNotify: specs,
71923
+ applyUpdates,
71924
+ layer,
71925
+ forceNotify
71926
+ });
71927
+ newIDs.push(linkedID);
71928
+ nestedIDs[i2] = linkedID;
71929
+ }
71930
+ return { newIDs, nestedIDs };
71931
+ }
71932
+ collectGarbage() {
71933
+ this.lifetimes.tick();
71934
+ if (this.storage.layerCount === 1) {
71935
+ this.storage.topLayer.removeUndefinedFields();
71936
+ }
71937
+ }
71938
+ };
71939
+ var rootID = "_ROOT_";
71940
+
71941
+ // src/runtime/cache/index.ts
71942
+ var cache_default = new Cache();
71943
+
71944
+ // src/runtime/client/utils/documentPlugins.ts
71945
+ var documentPlugin = (kind, source) => {
71946
+ return () => {
71947
+ const sourceHandlers = source();
71948
+ const enterWrapper = (handler) => {
71949
+ return !handler ? void 0 : (ctx, handlers) => {
71950
+ if (ctx.artifact.kind !== kind) {
71951
+ return handlers.next(ctx);
71952
+ }
71953
+ return handler(ctx, handlers);
71954
+ };
71955
+ };
71956
+ const exitWrapper = (handler) => {
71957
+ return !handler ? void 0 : (ctx, handlers) => {
71958
+ if (ctx.artifact.kind !== kind) {
71959
+ return handlers.resolve(ctx);
71960
+ }
71961
+ return handler(ctx, handlers);
71962
+ };
71963
+ };
71964
+ return {
71965
+ start: enterWrapper(sourceHandlers.start),
71966
+ network: enterWrapper(sourceHandlers.network),
71967
+ afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
71968
+ end: exitWrapper(sourceHandlers.end),
71969
+ catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
71970
+ cleanup: (...args) => sourceHandlers.cleanup?.(...args)
71971
+ };
71972
+ };
71973
+ };
71974
+
71975
+ // src/runtime/client/plugins/query.ts
71976
+ var query = documentPlugin(ArtifactKind.Query, function() {
71977
+ let subscriptionSpec = null;
71978
+ let lastVariables = null;
71979
+ let artifactName = "";
71980
+ return {
71981
+ start(ctx, { next }) {
71982
+ ctx.variables = {
71983
+ ...lastVariables,
71984
+ ...ctx.variables
71985
+ };
71986
+ next(ctx);
71987
+ },
71988
+ end(ctx, { resolve: resolve2, marshalVariables, variablesChanged }) {
71989
+ if (variablesChanged(ctx)) {
71990
+ artifactName = ctx.artifact.name;
71991
+ if (subscriptionSpec) {
71992
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
71993
+ }
71994
+ lastVariables = { ...marshalVariables(ctx) };
71995
+ subscriptionSpec = {
71996
+ rootType: ctx.artifact.rootType,
71997
+ selection: ctx.artifact.selection,
71998
+ variables: () => lastVariables,
71999
+ set: (newValue) => {
72000
+ resolve2(ctx, {
72001
+ data: newValue,
72002
+ errors: null,
72003
+ fetching: false,
72004
+ partial: false,
72005
+ stale: false,
72006
+ source: DataSource.Cache,
72007
+ variables: ctx.variables ?? {}
72008
+ });
72009
+ }
72010
+ };
72011
+ cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
72012
+ }
72013
+ resolve2(ctx);
72014
+ },
72015
+ cleanup() {
72016
+ if (subscriptionSpec) {
72017
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
72018
+ lastVariables = null;
72019
+ }
72020
+ }
72021
+ };
72022
+ });
72023
+
72024
+ // src/runtime/client/plugins/mutation.ts
72025
+ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
72026
+ return {
72027
+ async start(ctx, { next, marshalVariables }) {
72028
+ const layer = cache_default._internal_unstable.storage.createLayer(true);
72029
+ const optimisticResponse = ctx.stuff.optimisticResponse;
72030
+ let toNotify = [];
72031
+ if (optimisticResponse) {
72032
+ toNotify = cache_default.write({
72033
+ selection: ctx.artifact.selection,
72034
+ data: await marshalSelection({
72035
+ selection: ctx.artifact.selection,
72036
+ data: optimisticResponse
72037
+ }),
72038
+ variables: marshalVariables(ctx),
72039
+ layer: layer.id
72040
+ });
72041
+ }
72042
+ ctx.cacheParams = {
72043
+ ...ctx.cacheParams,
72044
+ layer,
72045
+ notifySubscribers: toNotify,
72046
+ forceNotify: true
72047
+ };
72048
+ next(ctx);
72049
+ },
72050
+ afterNetwork(ctx, { resolve: resolve2 }) {
72051
+ ctx.cacheParams?.layer?.clear();
72052
+ resolve2(ctx);
72053
+ },
72054
+ end(ctx, { resolve: resolve2, value }) {
72055
+ const hasErrors = value.errors && value.errors.length > 0;
72056
+ if (hasErrors) {
72057
+ ctx.cacheParams?.layer?.clear();
72058
+ }
72059
+ if (ctx.cacheParams?.layer) {
72060
+ cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
72061
+ }
72062
+ resolve2(ctx);
72063
+ },
72064
+ catch(ctx, { error }) {
72065
+ if (ctx.cacheParams?.layer) {
72066
+ const { layer } = ctx.cacheParams;
72067
+ layer.clear();
72068
+ cache_default._internal_unstable.storage.resolveLayer(layer.id);
72069
+ }
72070
+ throw error;
72071
+ }
72072
+ };
72073
+ });
72074
+
69937
72075
  // src/lib/types.ts
69938
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
69939
- LogLevel2["Full"] = "full";
69940
- LogLevel2["Summary"] = "summary";
69941
- LogLevel2["ShortSummary"] = "short-summary";
69942
- LogLevel2["Quiet"] = "quiet";
69943
- return LogLevel2;
69944
- })(LogLevel || {});
72076
+ var LogLevel = {
72077
+ Full: "full",
72078
+ Summary: "summary",
72079
+ ShortSummary: "short-summary",
72080
+ Quiet: "quiet"
72081
+ };
69945
72082
 
69946
72083
  // src/lib/config.ts
69947
72084
  var import_meta = {};
@@ -69993,7 +72130,7 @@ var Config = class {
69993
72130
  scalars,
69994
72131
  cacheBufferSize,
69995
72132
  definitionsPath,
69996
- defaultCachePolicy = "CacheOrNetwork" /* CacheOrNetwork */,
72133
+ defaultCachePolicy = CachePolicy.CacheOrNetwork,
69997
72134
  defaultPartial = false,
69998
72135
  defaultListPosition = "append",
69999
72136
  defaultListTarget = null,
@@ -70015,7 +72152,7 @@ var Config = class {
70015
72152
  Object.values(LogLevel)
70016
72153
  )}`
70017
72154
  );
70018
- logLevel = "summary" /* Summary */;
72155
+ logLevel = LogLevel.Summary;
70019
72156
  }
70020
72157
  this.schemaPath = schemaPath;
70021
72158
  this.filepath = filepath;
@@ -70031,7 +72168,7 @@ var Config = class {
70031
72168
  this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
70032
72169
  this.defaultListTarget = defaultListTarget;
70033
72170
  this.definitionsFolder = definitionsPath;
70034
- this.logLevel = (logLevel || "summary" /* Summary */).toLowerCase();
72171
+ this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
70035
72172
  this.defaultFragmentMasking = defaultFragmentMasking;
70036
72173
  this.routesDir = join2(this.projectRoot, "src", "routes");
70037
72174
  this.schemaPollInterval = watchSchema?.interval ?? 2e3;
@@ -70372,8 +72509,10 @@ var Config = class {
70372
72509
  return node.name.value === "CachePolicy";
70373
72510
  }
70374
72511
  isInternalDirective(name) {
70375
- const internalDirectives = this.#newSchemaInstance?.getDirectives().map((directive) => directive.name) ?? [];
70376
- return internalDirectives.includes(name) || this.isDeleteDirective(name);
72512
+ const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
72513
+ return list.concat(directive.name);
72514
+ }, []) ?? [];
72515
+ return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
70377
72516
  }
70378
72517
  isListFragment(name) {
70379
72518
  return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
@@ -70480,7 +72619,13 @@ async function getConfig({
70480
72619
  const plugins = pluginsNested.flat();
70481
72620
  for (const plugin2 of plugins) {
70482
72621
  if (plugin2.config) {
70483
- configFile = deepMerge(configPath, configFile, await plugin2.config(configFile));
72622
+ try {
72623
+ const configFactory = await import(plugin2.config);
72624
+ const newValue = typeof configFactory === "function" ? configFactory(configFile) : configFactory;
72625
+ configFile = deepMerge(configPath, configFile, newValue);
72626
+ } catch {
72627
+ console.log("could not load config file" + plugin2.config);
72628
+ }
70484
72629
  }
70485
72630
  }
70486
72631
  _config = new Config({
@@ -70638,6 +72783,8 @@ async function loadSchemaFile(schemaPath) {
70638
72783
  }
70639
72784
  return graphql2.buildClientSchema(jsonContents);
70640
72785
  }
72786
+ var emptySchema = graphql2.buildSchema("type Query { hello: String }");
72787
+ var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
70641
72788
 
70642
72789
  // src/lib/graphql.ts
70643
72790
  var graphql3 = __toESM(require_graphql2(), 1);
@@ -70654,7 +72801,7 @@ function getRootType(type) {
70654
72801
  function hashDocument({
70655
72802
  document
70656
72803
  }) {
70657
- const docString = typeof document === "string" ? document : document.artifact?.raw;
72804
+ const docString = typeof document === "string" ? document : document.originalString;
70658
72805
  return import_node_crypto.default.createHash("sha256").update(docString ?? "").digest("hex");
70659
72806
  }
70660
72807
  function parentTypeFromAncestors(schema, filepath, ancestors) {
@@ -71201,7 +73348,13 @@ var FieldCollection = class {
71201
73348
  if (fragment.selection.size === 0) {
71202
73349
  return [];
71203
73350
  }
71204
- fragment.astNode.selectionSet.selections = fragment.selection.toSelectionSet();
73351
+ fragment.astNode = {
73352
+ ...fragment.astNode,
73353
+ selectionSet: {
73354
+ ...fragment.astNode.selectionSet,
73355
+ selections: fragment.selection.toSelectionSet()
73356
+ }
73357
+ };
71205
73358
  return [fragment.astNode];
71206
73359
  }).concat(
71207
73360
  Object.values(this.fields).map((field) => {
@@ -71425,7 +73578,7 @@ async function fragmentVariables(config2, documents) {
71425
73578
  };
71426
73579
  documents.push({
71427
73580
  name: "generated::fragmentVariables",
71428
- kind: "HoudiniFragment" /* Fragment */,
73581
+ kind: ArtifactKind.Fragment,
71429
73582
  document: doc,
71430
73583
  originalParsed: doc,
71431
73584
  generateStore: false,
@@ -72346,7 +74499,7 @@ async function paginate(config2, documents) {
72346
74499
  ]
72347
74500
  };
72348
74501
  newDocs.push({
72349
- kind: "HoudiniQuery" /* Query */,
74502
+ kind: ArtifactKind.Query,
72350
74503
  filename: doc.filename,
72351
74504
  name: refetchQueryName,
72352
74505
  document: queryDoc,
@@ -72766,7 +74919,7 @@ async function addListFragments(config2, documents) {
72766
74919
  config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql11.print).join("\n\n");
72767
74920
  documents.push({
72768
74921
  name: "generated::lists",
72769
- kind: "HoudiniFragment" /* Fragment */,
74922
+ kind: ArtifactKind.Fragment,
72770
74923
  generateArtifact: false,
72771
74924
  generateStore: false,
72772
74925
  document: generatedDoc,
@@ -73033,7 +75186,7 @@ function selection({
73033
75186
  (directive) => directive.name.value === config2.paginateDirective
73034
75187
  );
73035
75188
  if (paginated && document.refetch && document.refetch.method === "offset") {
73036
- fieldObj.updates = ["append" /* append */];
75189
+ fieldObj.updates = [RefetchUpdateMode.append];
73037
75190
  }
73038
75191
  let continueConnection = inConnection;
73039
75192
  if ([
@@ -73043,7 +75196,7 @@ function selection({
73043
75196
  "hasNextPage",
73044
75197
  "hasPreviousPage"
73045
75198
  ].includes(attributeName) && inConnection && document.refetch) {
73046
- fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
75199
+ fieldObj.updates = [RefetchUpdateMode.append, RefetchUpdateMode.prepend];
73047
75200
  }
73048
75201
  if (attributeName === "node" && inConnection) {
73049
75202
  continueConnection = false;
@@ -73222,7 +75375,7 @@ function artifactGenerator(stats) {
73222
75375
  );
73223
75376
  let rootType = "";
73224
75377
  let selectionSet;
73225
- if (docKind !== "HoudiniFragment" /* Fragment */) {
75378
+ if (docKind !== ArtifactKind.Fragment) {
73226
75379
  const operation = operations[0];
73227
75380
  if (operation.operation === "query") {
73228
75381
  rootType = config2.schema.getQueryType()?.name;
@@ -73255,7 +75408,7 @@ function artifactGenerator(stats) {
73255
75408
  let directive = fragments[0]?.directives?.find(
73256
75409
  (directive2) => directive2.name.value === config2.argumentsDirective
73257
75410
  );
73258
- if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
75411
+ if (docKind === ArtifactKind.Fragment && directive) {
73259
75412
  inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
73260
75413
  }
73261
75414
  const mergedSelection = flattenSelections({
@@ -73296,22 +75449,12 @@ function artifactGenerator(stats) {
73296
75449
  document: doc
73297
75450
  })
73298
75451
  };
73299
- const plugin_data = config2.plugins.reduce(
73300
- (prev, plugin2) => {
73301
- if (!plugin2.artifactData) {
73302
- return prev;
73303
- }
73304
- const result = { ...prev };
73305
- const dataToAdd = plugin2.artifactData({ config: config2, document: doc }) ?? {};
73306
- if (Object.keys(dataToAdd).length > 0) {
73307
- result[plugin2.name] = dataToAdd;
73308
- }
73309
- return result;
73310
- },
73311
- {}
73312
- );
73313
- if (Object.keys(plugin_data).length > 0) {
73314
- artifact.plugin_data = plugin_data;
75452
+ artifact.pluginData = {};
75453
+ for (const plugin2 of config2.plugins) {
75454
+ if (!plugin2.artifactData) {
75455
+ continue;
75456
+ }
75457
+ artifact.pluginData[plugin2.name] = plugin2.artifactData({ config: config2, document: doc }) ?? {};
73315
75458
  }
73316
75459
  if (inputs && inputs.length > 0) {
73317
75460
  artifact.input = inputObject(config2, inputs);
@@ -73372,7 +75515,7 @@ function artifactGenerator(stats) {
73372
75515
  return;
73373
75516
  }
73374
75517
  const match = existingArtifact && existingArtifact.match(/"HoudiniHash=(\w+)"/);
73375
- if (match && match[1] !== hash({ config: config2, document: doc })) {
75518
+ if (match && match[1] !== artifact.hash) {
73376
75519
  stats.changed.push(artifact.name);
73377
75520
  }
73378
75521
  stats.total.push(artifact.name);
@@ -73485,6 +75628,30 @@ async function generatePluginIndex({
73485
75628
  ]);
73486
75629
  }
73487
75630
 
75631
+ // src/codegen/generators/runtime/runtimeConfig.ts
75632
+ async function injectConfig({
75633
+ config: config2,
75634
+ content,
75635
+ importStatement,
75636
+ exportStatement
75637
+ }) {
75638
+ const extraConfigs = config2.plugins.reduce((acc, plugin2) => {
75639
+ if (!plugin2.config) {
75640
+ return acc;
75641
+ }
75642
+ return [...acc, plugin2.config];
75643
+ }, []);
75644
+ return extraConfigs.length > 0 ? `
75645
+ ${extraConfigs.map((plugin2, i2) => importStatement(plugin2, `plugin${i2}`))}
75646
+
75647
+ const plugins = [
75648
+ ${extraConfigs.map((_, i2) => `plugin${i2}`).join(",\n")}
75649
+ ]
75650
+
75651
+ ${exportStatement("plugins")}
75652
+ ` : content;
75653
+ }
75654
+
73488
75655
  // src/codegen/generators/runtime/index.ts
73489
75656
  async function runtimeGenerator(config2, docs) {
73490
75657
  const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
@@ -73495,6 +75662,9 @@ async function runtimeGenerator(config2, docs) {
73495
75662
  [path_exports.join(config2.runtimeSource, "lib", "constants.js")]: (content) => {
73496
75663
  return content.replace("SITE_URL", siteURL);
73497
75664
  },
75665
+ [path_exports.join(config2.runtimeSource, "imports", "pluginConfig.js")]: (content) => {
75666
+ return injectConfig({ config: config2, importStatement, exportStatement, content });
75667
+ },
73498
75668
  [path_exports.join(config2.runtimeSource, "imports", "config.js")]: (content) => {
73499
75669
  const configFilePath = path_exports.join(config2.runtimeDirectory, "imports", "config.js");
73500
75670
  const relativePath = path_exports.relative(path_exports.dirname(configFilePath), config2.filepath);
@@ -74552,7 +76722,7 @@ function listDefinitions(config2, body, docs) {
74552
76722
  function queryDefinitions(config2, body, docs, returnType) {
74553
76723
  return AST12.tsTupleType(
74554
76724
  docs.reduce((prev, doc) => {
74555
- if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
76725
+ if (doc.kind !== ArtifactKind.Query || !doc.generateStore) {
74556
76726
  return prev;
74557
76727
  }
74558
76728
  const definition = doc.document.definitions.find(
@@ -74583,7 +76753,7 @@ function queryDefinitions(config2, body, docs, returnType) {
74583
76753
  }
74584
76754
  function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
74585
76755
  return docs.reduce((prev, doc) => {
74586
- if (doc.kind !== "HoudiniFragment" /* Fragment */) {
76756
+ if (doc.kind !== ArtifactKind.Fragment) {
74587
76757
  return prev;
74588
76758
  }
74589
76759
  const definition = doc.document.definitions.find(
@@ -74722,13 +76892,19 @@ async function definitionsGenerator(config2) {
74722
76892
  })
74723
76893
  )
74724
76894
  ).code;
74725
- const typeDefinitions2 = enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map(
74726
- (definition) => `
74727
- export const ${definition.name.value} = {
74728
- ${definition.values?.map((value) => ` ${value.name.value}: "${value.name.value}"`).join(",\n")}
74729
- } as const
74730
- `
74731
- ).join("");
76895
+ const typeDefinitions2 = `
76896
+ type ValuesOf<T> = T[keyof T]
76897
+ ` + enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map((definition) => {
76898
+ const name = definition.name.value;
76899
+ const values = definition.values;
76900
+ return `
76901
+ export declare const ${name}: {
76902
+ ${values?.map((value) => ` readonly ${value.name.value}: "${value.name.value}";`).join("\n")}
76903
+ }
76904
+
76905
+ export type ${name}$options = ValuesOf<typeof ${name}>
76906
+ `;
76907
+ }).join("");
74732
76908
  const definitionsIndex = `
74733
76909
  export * from './enums.js'
74734
76910
  `;
@@ -74794,10 +76970,10 @@ var graphql22 = __toESM(require_graphql2(), 1);
74794
76970
  async function graphqlExtensions(config2, documents) {
74795
76971
  let internalSchema = `
74796
76972
  enum CachePolicy {
74797
- ${"CacheAndNetwork" /* CacheAndNetwork */}
74798
- ${"CacheOnly" /* CacheOnly */}
74799
- ${"CacheOrNetwork" /* CacheOrNetwork */}
74800
- ${"NetworkOnly" /* NetworkOnly */}
76973
+ ${CachePolicy.CacheAndNetwork}
76974
+ ${CachePolicy.CacheOnly}
76975
+ ${CachePolicy.CacheOrNetwork}
76976
+ ${CachePolicy.NetworkOnly}
74801
76977
  }
74802
76978
 
74803
76979
  """
@@ -75713,7 +77889,7 @@ function getAndVerifyNodeInterface(config2) {
75713
77889
  var nbInvalidNodeFieldMessageDisplayed = 0;
75714
77890
  function displayInvalidNodeFieldMessage(logLevel) {
75715
77891
  if (nbInvalidNodeFieldMessageDisplayed === 0) {
75716
- if (logLevel === "full" /* Full */) {
77892
+ if (logLevel === LogLevel.Full) {
75717
77893
  console.warn(invalidNodeFieldMessage);
75718
77894
  } else {
75719
77895
  console.warn(invalidNodeFieldMessageLight);
@@ -75881,7 +78057,7 @@ async function runPipeline2(config2, docs) {
75881
78057
  }
75882
78058
  const unchanged = artifactStats.total.length - artifactStats.changed.length - artifactStats.new.length - artifactStats.deleted.length;
75883
78059
  const printMessage = !config2.pluginMode || unchanged !== artifactStats.total.length;
75884
- if (!printMessage || config2.logLevel === "quiet" /* Quiet */) {
78060
+ if (!printMessage || config2.logLevel === LogLevel.Quiet) {
75885
78061
  if (error) {
75886
78062
  throw error;
75887
78063
  }
@@ -75895,14 +78071,14 @@ async function runPipeline2(config2, docs) {
75895
78071
  }
75896
78072
  if (artifactStats.total.length === 0) {
75897
78073
  console.log(`\u{1F4A1} No operation found. If that's unexpected, please check your config.`);
75898
- } else if (["summary" /* Summary */, "short-summary" /* ShortSummary */].includes(config2.logLevel)) {
78074
+ } else if (config2.logLevel == LogLevel.Summary || config2.logLevel == LogLevel.ShortSummary) {
75899
78075
  if (unchanged > 0 && printMessage && !config2.pluginMode) {
75900
78076
  console.log(`\u{1F4C3} Unchanged: ${unchanged}`);
75901
78077
  }
75902
78078
  logStyled("CREATED", artifactStats.new, config2.logLevel, config2.pluginMode);
75903
78079
  logStyled("UPDATED", artifactStats.changed, config2.logLevel, config2.pluginMode);
75904
78080
  logStyled("DELETED", artifactStats.deleted, config2.logLevel, config2.pluginMode);
75905
- } else if (config2.logLevel === "full" /* Full */) {
78081
+ } else if (config2.logLevel === LogLevel.Full) {
75906
78082
  for (const artifact of artifactStats.total) {
75907
78083
  let emoji = "\u{1F4C3}";
75908
78084
  if (artifactStats.changed.includes(artifact)) {
@@ -76012,14 +78188,14 @@ async function processGraphQLDocument(config2, filepath, document) {
76012
78188
  });
76013
78189
  }
76014
78190
  }
76015
- let kind = "HoudiniFragment" /* Fragment */;
78191
+ let kind = ArtifactKind.Fragment;
76016
78192
  if (operations.length === 1) {
76017
78193
  if (operations[0].kind === "OperationDefinition" && operations[0].operation === "query") {
76018
- kind = "HoudiniQuery" /* Query */;
78194
+ kind = ArtifactKind.Query;
76019
78195
  } else if (operations[0].kind === "OperationDefinition" && operations[0].operation === "mutation") {
76020
- kind = "HoudiniMutation" /* Mutation */;
78196
+ kind = ArtifactKind.Mutation;
76021
78197
  } else if (operations[0].kind === "OperationDefinition" && operations[0].operation === "subscription") {
76022
- kind = "HoudiniSubscription" /* Subscription */;
78198
+ kind = ArtifactKind.Subscription;
76023
78199
  }
76024
78200
  }
76025
78201
  return {
@@ -76064,7 +78240,7 @@ function logStyled(kind, stat3, logLevel, plugin2) {
76064
78240
  }
76065
78241
  }
76066
78242
  console.log(msg.join(""));
76067
- if (!plugin2 && logLevel === "summary" /* Summary */) {
78243
+ if (!plugin2 && logLevel === LogLevel.Summary) {
76068
78244
  for (const artifact of stat3.slice(0, nbToDisplay)) {
76069
78245
  console.log(` ${artifact}`);
76070
78246
  }
@@ -76507,8 +78683,8 @@ async function updatePackageJSON(targetPath) {
76507
78683
  }
76508
78684
  packageJSON.devDependencies = {
76509
78685
  ...packageJSON.devDependencies,
76510
- houdini: "^1.0.0-next.9",
76511
- "houdini-svelte": "^1.0.0-next.9"
78686
+ houdini: "^1.0.0",
78687
+ "houdini-svelte": "^1.0.0"
76512
78688
  };
76513
78689
  await fs_exports.writeFile(packagePath, JSON.stringify(packageJSON, null, 4));
76514
78690
  }