houdini 1.0.0-next.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +2368 -151
  3. package/build/cmd-esm/index.js +2368 -151
  4. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  5. package/build/codegen/transforms/fragmentVariables.d.ts +2 -1
  6. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  7. package/build/codegen/validators/typeCheck.d.ts +1 -0
  8. package/build/codegen-cjs/index.js +2962 -719
  9. package/build/codegen-esm/index.js +2962 -719
  10. package/build/lib/config.d.ts +4 -6
  11. package/build/lib/types.d.ts +18 -15
  12. package/build/lib-cjs/index.js +3159 -171
  13. package/build/lib-esm/index.js +3152 -171
  14. package/build/runtime/cache/storage.d.ts +18 -15
  15. package/build/runtime/client/documentStore.d.ts +15 -13
  16. package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
  17. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  18. package/build/runtime/lib/config.d.ts +2 -2
  19. package/build/runtime/lib/scalars.d.ts +1 -1
  20. package/build/runtime/lib/types.d.ts +41 -42
  21. package/build/runtime-cjs/cache/storage.d.ts +18 -15
  22. package/build/runtime-cjs/cache/storage.js +9 -11
  23. package/build/runtime-cjs/client/documentStore.d.ts +15 -13
  24. package/build/runtime-cjs/client/documentStore.js +10 -7
  25. package/build/runtime-cjs/client/index.js +3 -0
  26. package/build/runtime-cjs/client/plugins/cache.js +3 -3
  27. package/build/runtime-cjs/client/plugins/fetch.js +2 -2
  28. package/build/runtime-cjs/client/plugins/query.js +1 -1
  29. package/build/runtime-cjs/client/plugins/subscription.js +2 -2
  30. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
  31. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  32. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  33. package/build/runtime-cjs/lib/config.d.ts +2 -2
  34. package/build/runtime-cjs/lib/config.js +11 -1
  35. package/build/runtime-cjs/lib/scalars.d.ts +1 -1
  36. package/build/runtime-cjs/lib/scalars.js +13 -2
  37. package/build/runtime-cjs/lib/types.d.ts +41 -42
  38. package/build/runtime-cjs/lib/types.js +26 -30
  39. package/build/runtime-esm/cache/storage.d.ts +18 -15
  40. package/build/runtime-esm/cache/storage.js +9 -11
  41. package/build/runtime-esm/client/documentStore.d.ts +15 -13
  42. package/build/runtime-esm/client/documentStore.js +10 -7
  43. package/build/runtime-esm/client/index.js +5 -2
  44. package/build/runtime-esm/client/plugins/cache.js +3 -3
  45. package/build/runtime-esm/client/plugins/fetch.js +2 -2
  46. package/build/runtime-esm/client/plugins/query.js +1 -1
  47. package/build/runtime-esm/client/plugins/subscription.js +2 -2
  48. package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
  49. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  50. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  51. package/build/runtime-esm/lib/config.d.ts +2 -2
  52. package/build/runtime-esm/lib/config.js +11 -1
  53. package/build/runtime-esm/lib/scalars.d.ts +1 -1
  54. package/build/runtime-esm/lib/scalars.js +13 -2
  55. package/build/runtime-esm/lib/types.d.ts +41 -42
  56. package/build/runtime-esm/lib/types.js +26 -30
  57. package/build/test-cjs/index.js +2346 -128
  58. package/build/test-esm/index.js +2346 -128
  59. package/build/vite/houdini.d.ts +2 -0
  60. package/build/vite-cjs/index.js +2371 -152
  61. package/build/vite-esm/index.js +2371 -152
  62. package/package.json +2 -2
@@ -3347,7 +3347,7 @@ var require_definition = __commonJS({
3347
3347
  exports.assertInterfaceType = assertInterfaceType;
3348
3348
  exports.isUnionType = isUnionType7;
3349
3349
  exports.assertUnionType = assertUnionType;
3350
- exports.isEnumType = isEnumType6;
3350
+ exports.isEnumType = isEnumType7;
3351
3351
  exports.assertEnumType = assertEnumType;
3352
3352
  exports.isInputObjectType = isInputObjectType2;
3353
3353
  exports.assertInputObjectType = assertInputObjectType;
@@ -3418,7 +3418,7 @@ var require_definition = __commonJS({
3418
3418
  return Constructor;
3419
3419
  }
3420
3420
  function isType(type) {
3421
- return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType6(type) || isInputObjectType2(type) || isListType3(type) || isNonNullType6(type);
3421
+ return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType7(type) || isInputObjectType2(type) || isListType3(type) || isNonNullType6(type);
3422
3422
  }
3423
3423
  function assertType(type) {
3424
3424
  if (!isType(type)) {
@@ -3462,11 +3462,11 @@ var require_definition = __commonJS({
3462
3462
  }
3463
3463
  return type;
3464
3464
  }
3465
- function isEnumType6(type) {
3465
+ function isEnumType7(type) {
3466
3466
  return (0, _instanceOf.default)(type, GraphQLEnumType);
3467
3467
  }
3468
3468
  function assertEnumType(type) {
3469
- if (!isEnumType6(type)) {
3469
+ if (!isEnumType7(type)) {
3470
3470
  throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Enum type."));
3471
3471
  }
3472
3472
  return type;
@@ -3499,7 +3499,7 @@ var require_definition = __commonJS({
3499
3499
  return type;
3500
3500
  }
3501
3501
  function isInputType(type) {
3502
- return isScalarType7(type) || isEnumType6(type) || isInputObjectType2(type) || isWrappingType(type) && isInputType(type.ofType);
3502
+ return isScalarType7(type) || isEnumType7(type) || isInputObjectType2(type) || isWrappingType(type) && isInputType(type.ofType);
3503
3503
  }
3504
3504
  function assertInputType(type) {
3505
3505
  if (!isInputType(type)) {
@@ -3508,7 +3508,7 @@ var require_definition = __commonJS({
3508
3508
  return type;
3509
3509
  }
3510
3510
  function isOutputType(type) {
3511
- return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType6(type) || isWrappingType(type) && isOutputType(type.ofType);
3511
+ return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType7(type) || isWrappingType(type) && isOutputType(type.ofType);
3512
3512
  }
3513
3513
  function assertOutputType(type) {
3514
3514
  if (!isOutputType(type)) {
@@ -3517,7 +3517,7 @@ var require_definition = __commonJS({
3517
3517
  return type;
3518
3518
  }
3519
3519
  function isLeafType(type) {
3520
- return isScalarType7(type) || isEnumType6(type);
3520
+ return isScalarType7(type) || isEnumType7(type);
3521
3521
  }
3522
3522
  function assertLeafType(type) {
3523
3523
  if (!isLeafType(type)) {
@@ -3605,7 +3605,7 @@ var require_definition = __commonJS({
3605
3605
  }
3606
3606
  }
3607
3607
  function isNamedType(type) {
3608
- return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType6(type) || isInputObjectType2(type);
3608
+ return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType7(type) || isInputObjectType2(type);
3609
3609
  }
3610
3610
  function assertNamedType(type) {
3611
3611
  if (!isNamedType(type)) {
@@ -15645,42 +15645,42 @@ var require_node = __commonJS({
15645
15645
  return Link2;
15646
15646
  }(events_1.EventEmitter);
15647
15647
  exports.Link = Link;
15648
- var File = function() {
15649
- function File2(link, node, flags, fd) {
15648
+ var File2 = function() {
15649
+ function File3(link, node, flags, fd) {
15650
15650
  this.position = 0;
15651
15651
  this.link = link;
15652
15652
  this.node = node;
15653
15653
  this.flags = flags;
15654
15654
  this.fd = fd;
15655
15655
  }
15656
- File2.prototype.getString = function(encoding) {
15656
+ File3.prototype.getString = function(encoding) {
15657
15657
  if (encoding === void 0) {
15658
15658
  encoding = "utf8";
15659
15659
  }
15660
15660
  return this.node.getString();
15661
15661
  };
15662
- File2.prototype.setString = function(str) {
15662
+ File3.prototype.setString = function(str) {
15663
15663
  this.node.setString(str);
15664
15664
  };
15665
- File2.prototype.getBuffer = function() {
15665
+ File3.prototype.getBuffer = function() {
15666
15666
  return this.node.getBuffer();
15667
15667
  };
15668
- File2.prototype.setBuffer = function(buf) {
15668
+ File3.prototype.setBuffer = function(buf) {
15669
15669
  this.node.setBuffer(buf);
15670
15670
  };
15671
- File2.prototype.getSize = function() {
15671
+ File3.prototype.getSize = function() {
15672
15672
  return this.node.getSize();
15673
15673
  };
15674
- File2.prototype.truncate = function(len) {
15674
+ File3.prototype.truncate = function(len) {
15675
15675
  this.node.truncate(len);
15676
15676
  };
15677
- File2.prototype.seekTo = function(position) {
15677
+ File3.prototype.seekTo = function(position) {
15678
15678
  this.position = position;
15679
15679
  };
15680
- File2.prototype.stats = function() {
15680
+ File3.prototype.stats = function() {
15681
15681
  return Stats_1.default.build(this.node);
15682
15682
  };
15683
- File2.prototype.write = function(buf, offset, length, position) {
15683
+ File3.prototype.write = function(buf, offset, length, position) {
15684
15684
  if (offset === void 0) {
15685
15685
  offset = 0;
15686
15686
  }
@@ -15695,7 +15695,7 @@ var require_node = __commonJS({
15695
15695
  this.position = position + bytes;
15696
15696
  return bytes;
15697
15697
  };
15698
- File2.prototype.read = function(buf, offset, length, position) {
15698
+ File3.prototype.read = function(buf, offset, length, position) {
15699
15699
  if (offset === void 0) {
15700
15700
  offset = 0;
15701
15701
  }
@@ -15708,15 +15708,15 @@ var require_node = __commonJS({
15708
15708
  this.position = position + bytes;
15709
15709
  return bytes;
15710
15710
  };
15711
- File2.prototype.chmod = function(perm) {
15711
+ File3.prototype.chmod = function(perm) {
15712
15712
  this.node.chmod(perm);
15713
15713
  };
15714
- File2.prototype.chown = function(uid, gid) {
15714
+ File3.prototype.chown = function(uid, gid) {
15715
15715
  this.node.chown(uid, gid);
15716
15716
  };
15717
- return File2;
15717
+ return File3;
15718
15718
  }();
15719
- exports.File = File;
15719
+ exports.File = File2;
15720
15720
  }
15721
15721
  });
15722
15722
 
@@ -16402,20 +16402,20 @@ var require_volume = __commonJS({
16402
16402
  }
16403
16403
  function flattenJSON(nestedJSON) {
16404
16404
  var flatJSON = {};
16405
- function flatten(pathPrefix, node) {
16405
+ function flatten2(pathPrefix, node) {
16406
16406
  for (var path2 in node) {
16407
16407
  var contentOrNode = node[path2];
16408
16408
  var joinedPath = join2(pathPrefix, path2);
16409
16409
  if (typeof contentOrNode === "string") {
16410
16410
  flatJSON[joinedPath] = contentOrNode;
16411
16411
  } else if (typeof contentOrNode === "object" && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
16412
- flatten(joinedPath, contentOrNode);
16412
+ flatten2(joinedPath, contentOrNode);
16413
16413
  } else {
16414
16414
  flatJSON[joinedPath] = null;
16415
16415
  }
16416
16416
  }
16417
16417
  }
16418
- flatten("", nestedJSON);
16418
+ flatten2("", nestedJSON);
16419
16419
  return flatJSON;
16420
16420
  }
16421
16421
  var Volume = function() {
@@ -54060,7 +54060,18 @@ var graphql = __toESM(require_graphql2(), 1);
54060
54060
  var import_minimatch = __toESM(require_minimatch(), 1);
54061
54061
  var import_node_url = require("node:url");
54062
54062
 
54063
+ // src/runtime/imports/config.ts
54064
+ var config_default = {};
54065
+
54066
+ // src/runtime/imports/pluginConfig.ts
54067
+ var configs = [];
54068
+ var pluginConfig_default = configs;
54069
+
54063
54070
  // src/runtime/lib/config.ts
54071
+ var mockConfig = null;
54072
+ function getMockConfig() {
54073
+ return mockConfig;
54074
+ }
54064
54075
  function defaultConfigValues(file) {
54065
54076
  return {
54066
54077
  defaultKeys: ["id"],
@@ -54088,6 +54099,150 @@ function computeID(configFile, type, data) {
54088
54099
  }
54089
54100
  return id.slice(0, -2);
54090
54101
  }
54102
+ var _configFile = null;
54103
+ function getCurrentConfig() {
54104
+ const mockConfig2 = getMockConfig();
54105
+ if (mockConfig2) {
54106
+ return mockConfig2;
54107
+ }
54108
+ if (_configFile) {
54109
+ return _configFile;
54110
+ }
54111
+ let configFile = defaultConfigValues(config_default);
54112
+ for (const pluginConfig of pluginConfig_default) {
54113
+ configFile = pluginConfig(configFile);
54114
+ }
54115
+ _configFile = configFile;
54116
+ return configFile;
54117
+ }
54118
+
54119
+ // src/runtime/lib/deepEquals.ts
54120
+ function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
54121
+ if (Object.is(objA, objB))
54122
+ return true;
54123
+ if (objA instanceof Date && objB instanceof Date) {
54124
+ return objA.getTime() === objB.getTime();
54125
+ }
54126
+ if (objA instanceof RegExp && objB instanceof RegExp) {
54127
+ return objA.toString() === objB.toString();
54128
+ }
54129
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
54130
+ return false;
54131
+ }
54132
+ if (map.get(objA) === objB)
54133
+ return true;
54134
+ map.set(objA, objB);
54135
+ const keysA = Reflect.ownKeys(objA);
54136
+ const keysB = Reflect.ownKeys(objB);
54137
+ if (keysA.length !== keysB.length) {
54138
+ return false;
54139
+ }
54140
+ for (let i = 0; i < keysA.length; i++) {
54141
+ if (!Reflect.has(objB, keysA[i]) || !deepEquals(objA[keysA[i]], objB[keysA[i]], map)) {
54142
+ return false;
54143
+ }
54144
+ }
54145
+ return true;
54146
+ }
54147
+
54148
+ // src/runtime/lib/selection.ts
54149
+ function getFieldsForType(selection2, __typename) {
54150
+ let targetSelection = selection2.fields || {};
54151
+ if (selection2.abstractFields && __typename) {
54152
+ const mappedType = selection2.abstractFields.typeMap[__typename];
54153
+ if (mappedType) {
54154
+ targetSelection = selection2.abstractFields.fields[mappedType];
54155
+ } else if (selection2.abstractFields.fields[__typename]) {
54156
+ targetSelection = selection2.abstractFields.fields[__typename];
54157
+ }
54158
+ }
54159
+ return targetSelection;
54160
+ }
54161
+
54162
+ // src/runtime/lib/scalars.ts
54163
+ async function marshalSelection({
54164
+ selection: selection2,
54165
+ data
54166
+ }) {
54167
+ const config2 = getCurrentConfig();
54168
+ if (data === null || typeof data === "undefined") {
54169
+ return data;
54170
+ }
54171
+ if (Array.isArray(data)) {
54172
+ return await Promise.all(data.map((val) => marshalSelection({ selection: selection2, data: val })));
54173
+ }
54174
+ const targetSelection = getFieldsForType(selection2, data["__typename"]);
54175
+ return Object.fromEntries(
54176
+ await Promise.all(
54177
+ Object.entries(data).map(async ([fieldName, value]) => {
54178
+ const { type, selection: selection3 } = targetSelection[fieldName];
54179
+ if (!type) {
54180
+ return [fieldName, value];
54181
+ }
54182
+ if (selection3) {
54183
+ return [fieldName, await marshalSelection({ selection: selection3, data: value })];
54184
+ }
54185
+ if (config2.scalars?.[type]) {
54186
+ const marshalFn = config2.scalars[type].marshal;
54187
+ if (!marshalFn) {
54188
+ throw new Error(
54189
+ `scalar type ${type} is missing a \`marshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
54190
+ );
54191
+ }
54192
+ if (Array.isArray(value)) {
54193
+ return [fieldName, value.map(marshalFn)];
54194
+ }
54195
+ return [fieldName, marshalFn(value)];
54196
+ }
54197
+ return [fieldName, value];
54198
+ })
54199
+ )
54200
+ );
54201
+ }
54202
+
54203
+ // src/runtime/lib/types.ts
54204
+ var CachePolicy = {
54205
+ CacheOrNetwork: "CacheOrNetwork",
54206
+ CacheOnly: "CacheOnly",
54207
+ NetworkOnly: "NetworkOnly",
54208
+ CacheAndNetwork: "CacheAndNetwork"
54209
+ };
54210
+ var ArtifactKind = {
54211
+ Query: "HoudiniQuery",
54212
+ Subscription: "HoudiniSubscription",
54213
+ Mutation: "HoudiniMutation",
54214
+ Fragment: "HoudiniFragment"
54215
+ };
54216
+ var CompiledFragmentKind = ArtifactKind.Fragment;
54217
+ var CompiledMutationKind = ArtifactKind.Mutation;
54218
+ var CompiledQueryKind = ArtifactKind.Query;
54219
+ var CompiledSubscriptionKind = ArtifactKind.Subscription;
54220
+ var RefetchUpdateMode = {
54221
+ append: "append",
54222
+ prepend: "prepend",
54223
+ replace: "replace"
54224
+ };
54225
+ var DataSource = {
54226
+ Cache: "cache",
54227
+ Network: "network",
54228
+ Ssr: "ssr"
54229
+ };
54230
+
54231
+ // src/runtime/lib/key.ts
54232
+ var computeKey = ({ field, args }) => {
54233
+ const keys = Object.keys(args ?? {});
54234
+ keys.sort();
54235
+ return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
54236
+ };
54237
+ var stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
54238
+ if (Array.isArray(obj_from_json)) {
54239
+ return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
54240
+ }
54241
+ if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
54242
+ return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
54243
+ }
54244
+ return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
54245
+ };
54091
54246
 
54092
54247
  // src/lib/constants.ts
54093
54248
  var siteURL = "https://houdinigraphql.com";
@@ -54410,14 +54565,2002 @@ async function glob(pattern) {
54410
54565
  }
54411
54566
  glob.hasMagic = import_glob.glob.hasMagic;
54412
54567
 
54568
+ // src/runtime/lib/flatten.ts
54569
+ function flatten(source) {
54570
+ if (!source) {
54571
+ return [];
54572
+ }
54573
+ return source.reduce((acc, element) => {
54574
+ if (!element) {
54575
+ return acc;
54576
+ }
54577
+ if (Array.isArray(element)) {
54578
+ return acc.concat(flatten(element));
54579
+ }
54580
+ return acc.concat(element);
54581
+ }, []);
54582
+ }
54583
+
54584
+ // src/runtime/cache/gc.ts
54585
+ var GarbageCollector = class {
54586
+ cache;
54587
+ lifetimes = /* @__PURE__ */ new Map();
54588
+ get cacheBufferSize() {
54589
+ return this.cache._internal_unstable.config.cacheBufferSize ?? 10;
54590
+ }
54591
+ constructor(cache) {
54592
+ this.cache = cache;
54593
+ }
54594
+ resetLifetime(id, field) {
54595
+ if (!this.lifetimes.get(id)) {
54596
+ this.lifetimes.set(id, /* @__PURE__ */ new Map());
54597
+ }
54598
+ this.lifetimes.get(id).set(field, 0);
54599
+ }
54600
+ tick() {
54601
+ const dt_tick = Date.now().valueOf();
54602
+ const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
54603
+ for (const [id, fieldMap] of this.lifetimes.entries()) {
54604
+ for (const [field, lifetime] of fieldMap.entries()) {
54605
+ if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
54606
+ continue;
54607
+ }
54608
+ fieldMap.set(field, lifetime + 1);
54609
+ if (fieldMap.get(field) > this.cacheBufferSize) {
54610
+ this.cache._internal_unstable.storage.deleteField(id, field);
54611
+ this.cache._internal_unstable.lists.deleteField(id, field);
54612
+ fieldMap.delete(field);
54613
+ if ([...fieldMap.keys()].length === 0) {
54614
+ this.lifetimes.delete(id);
54615
+ }
54616
+ this.cache._internal_unstable.staleManager.delete(id, field);
54617
+ }
54618
+ if (config_max_time && config_max_time > 0) {
54619
+ const dt_valueOf = this.cache.getFieldTime(id, field);
54620
+ if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
54621
+ this.cache._internal_unstable.staleManager.markFieldStale(id, field);
54622
+ }
54623
+ }
54624
+ }
54625
+ }
54626
+ }
54627
+ };
54628
+
54629
+ // src/runtime/cache/lists.ts
54630
+ var ListManager = class {
54631
+ rootID;
54632
+ cache;
54633
+ constructor(cache, rootID2) {
54634
+ this.rootID = rootID2;
54635
+ this.cache = cache;
54636
+ }
54637
+ lists = /* @__PURE__ */ new Map();
54638
+ listsByField = /* @__PURE__ */ new Map();
54639
+ get(listName, id, allLists) {
54640
+ const matches = this.lists.get(listName);
54641
+ if (!matches || matches.size === 0) {
54642
+ return null;
54643
+ }
54644
+ if (allLists) {
54645
+ return new ListCollection(
54646
+ Array.from(matches, ([key, value]) => [...value.lists]).flat()
54647
+ );
54648
+ }
54649
+ const head = [...matches.values()][0];
54650
+ const { recordType } = head.lists[0];
54651
+ const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
54652
+ if (matches?.size === 1) {
54653
+ if (!id) {
54654
+ return head;
54655
+ }
54656
+ return parentID === Array.from(matches.keys())[0] ? head : null;
54657
+ }
54658
+ if (!id) {
54659
+ console.error(
54660
+ `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 `
54661
+ );
54662
+ return null;
54663
+ }
54664
+ return this.lists.get(listName)?.get(parentID);
54665
+ }
54666
+ remove(listName, id) {
54667
+ this.lists.get(listName)?.delete(id || this.rootID);
54668
+ }
54669
+ add(list) {
54670
+ if (!this.lists.has(list.name)) {
54671
+ this.lists.set(list.name, /* @__PURE__ */ new Map());
54672
+ }
54673
+ const name = list.name;
54674
+ const parentID = list.recordID || this.rootID;
54675
+ if (this.lists.get(name)?.get(parentID)?.includes(list.key)) {
54676
+ return;
54677
+ }
54678
+ if (!this.lists.has(name)) {
54679
+ this.lists.set(name, /* @__PURE__ */ new Map());
54680
+ }
54681
+ if (!this.lists.get(name).has(parentID)) {
54682
+ this.lists.get(name).set(parentID, new ListCollection([]));
54683
+ }
54684
+ if (!this.listsByField.has(parentID)) {
54685
+ this.listsByField.set(parentID, /* @__PURE__ */ new Map());
54686
+ }
54687
+ if (!this.listsByField.get(parentID).has(list.key)) {
54688
+ this.listsByField.get(parentID)?.set(list.key, []);
54689
+ }
54690
+ const handler = new List({ ...list, manager: this });
54691
+ this.lists.get(list.name).get(parentID).lists.push(handler);
54692
+ this.listsByField.get(parentID).get(list.key).push(handler);
54693
+ }
54694
+ removeIDFromAllLists(id) {
54695
+ for (const fieldMap of this.lists.values()) {
54696
+ for (const list of fieldMap.values()) {
54697
+ list.removeID(id);
54698
+ }
54699
+ }
54700
+ }
54701
+ deleteField(parentID, field) {
54702
+ if (!this.listsByField.get(parentID)?.has(field)) {
54703
+ return;
54704
+ }
54705
+ for (const list of this.listsByField.get(parentID).get(field)) {
54706
+ this.lists.get(list.name)?.get(list.recordID)?.deleteListWithKey(field);
54707
+ if (this.lists.get(list.name)?.get(list.recordID)?.lists.length === 0) {
54708
+ this.lists.get(list.name)?.delete(list.recordID);
54709
+ }
54710
+ }
54711
+ this.listsByField.get(parentID).delete(field);
54712
+ }
54713
+ };
54714
+ var List = class {
54715
+ recordID;
54716
+ recordType;
54717
+ key;
54718
+ type;
54719
+ cache;
54720
+ selection;
54721
+ _when;
54722
+ filters;
54723
+ name;
54724
+ connection;
54725
+ manager;
54726
+ abstract;
54727
+ constructor({
54728
+ name,
54729
+ recordID,
54730
+ recordType,
54731
+ key,
54732
+ listType,
54733
+ selection: selection2,
54734
+ when,
54735
+ filters,
54736
+ connection,
54737
+ manager,
54738
+ abstract
54739
+ }) {
54740
+ this.recordID = recordID || rootID;
54741
+ this.recordType = recordType;
54742
+ this.key = key;
54743
+ this.type = listType;
54744
+ this.cache = manager.cache;
54745
+ this.selection = selection2;
54746
+ this._when = when;
54747
+ this.filters = filters;
54748
+ this.name = name;
54749
+ this.connection = connection;
54750
+ this.manager = manager;
54751
+ this.abstract = abstract;
54752
+ }
54753
+ when(when) {
54754
+ return this.manager.lists.get(this.name).get(this.recordID).when(when);
54755
+ }
54756
+ append(selection2, data, variables = {}) {
54757
+ return this.addToList(selection2, data, variables, "last");
54758
+ }
54759
+ prepend(selection2, data, variables = {}) {
54760
+ return this.addToList(selection2, data, variables, "first");
54761
+ }
54762
+ addToList(selection2, data, variables = {}, where) {
54763
+ const listType = this.listType(data);
54764
+ const dataID = this.cache._internal_unstable.id(listType, data);
54765
+ if (!this.validateWhen() || !dataID) {
54766
+ return;
54767
+ }
54768
+ let insertSelection = selection2;
54769
+ let insertData = data;
54770
+ if (this.connection) {
54771
+ insertSelection = {
54772
+ fields: {
54773
+ newEntry: {
54774
+ keyRaw: this.key,
54775
+ type: "Connection",
54776
+ selection: {
54777
+ fields: {
54778
+ edges: {
54779
+ keyRaw: "edges",
54780
+ type: "ConnectionEdge",
54781
+ updates: ["append", "prepend"],
54782
+ selection: {
54783
+ fields: {
54784
+ node: {
54785
+ type: listType,
54786
+ keyRaw: "node",
54787
+ selection: {
54788
+ ...selection2,
54789
+ fields: {
54790
+ ...selection2.fields,
54791
+ __typename: {
54792
+ keyRaw: "__typename",
54793
+ type: "String"
54794
+ }
54795
+ }
54796
+ }
54797
+ }
54798
+ }
54799
+ }
54800
+ }
54801
+ }
54802
+ }
54803
+ }
54804
+ }
54805
+ };
54806
+ insertData = {
54807
+ newEntry: {
54808
+ edges: [{ node: { ...data, __typename: listType } }]
54809
+ }
54810
+ };
54811
+ } else {
54812
+ insertSelection = {
54813
+ fields: {
54814
+ newEntries: {
54815
+ keyRaw: this.key,
54816
+ type: listType,
54817
+ updates: ["append", "prepend"],
54818
+ selection: {
54819
+ ...selection2,
54820
+ fields: {
54821
+ ...selection2.fields,
54822
+ __typename: {
54823
+ keyRaw: "__typename",
54824
+ type: "String"
54825
+ }
54826
+ }
54827
+ }
54828
+ }
54829
+ }
54830
+ };
54831
+ insertData = {
54832
+ newEntries: [{ ...data, __typename: listType }]
54833
+ };
54834
+ }
54835
+ this.cache.write({
54836
+ selection: insertSelection,
54837
+ data: insertData,
54838
+ variables,
54839
+ parent: this.recordID,
54840
+ applyUpdates: [where === "first" ? "prepend" : "append"]
54841
+ });
54842
+ }
54843
+ removeID(id, variables = {}) {
54844
+ if (!this.validateWhen()) {
54845
+ return;
54846
+ }
54847
+ let parentID = this.recordID;
54848
+ let targetID = id;
54849
+ let targetKey = this.key;
54850
+ if (this.connection) {
54851
+ const { value: embeddedConnection } = this.cache._internal_unstable.storage.get(
54852
+ this.recordID,
54853
+ this.key
54854
+ );
54855
+ if (!embeddedConnection) {
54856
+ return;
54857
+ }
54858
+ const embeddedConnectionID = embeddedConnection;
54859
+ const { value: edges } = this.cache._internal_unstable.storage.get(
54860
+ embeddedConnectionID,
54861
+ "edges"
54862
+ );
54863
+ for (const edge of flatten(edges) || []) {
54864
+ if (!edge) {
54865
+ continue;
54866
+ }
54867
+ const edgeID = edge;
54868
+ const { value: nodeID } = this.cache._internal_unstable.storage.get(edgeID, "node");
54869
+ if (!nodeID) {
54870
+ continue;
54871
+ }
54872
+ if (nodeID === id) {
54873
+ targetID = edgeID;
54874
+ }
54875
+ }
54876
+ parentID = embeddedConnectionID;
54877
+ targetKey = "edges";
54878
+ }
54879
+ let value = this.cache._internal_unstable.storage.get(parentID, targetKey).value;
54880
+ if (!value || !value.includes(targetID)) {
54881
+ return;
54882
+ }
54883
+ const subscribers = this.cache._internal_unstable.subscriptions.get(this.recordID, this.key);
54884
+ this.cache._internal_unstable.subscriptions.remove(
54885
+ targetID,
54886
+ this.connection ? this.selection.fields.edges.selection : this.selection,
54887
+ subscribers.map((sub) => sub[0]),
54888
+ variables
54889
+ );
54890
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
54891
+ for (const [spec] of subscribers) {
54892
+ spec.set(
54893
+ this.cache._internal_unstable.getSelection({
54894
+ parent: spec.parentID || this.manager.rootID,
54895
+ selection: spec.selection,
54896
+ variables: spec.variables?.() || {}
54897
+ }).data
54898
+ );
54899
+ }
54900
+ return true;
54901
+ }
54902
+ remove(data, variables = {}) {
54903
+ const targetID = this.cache._internal_unstable.id(this.listType(data), data);
54904
+ if (!targetID) {
54905
+ return;
54906
+ }
54907
+ return this.removeID(targetID, variables);
54908
+ }
54909
+ listType(data) {
54910
+ return data.__typename || this.type;
54911
+ }
54912
+ validateWhen(when) {
54913
+ let filters = when || this._when;
54914
+ let ok = true;
54915
+ if (filters) {
54916
+ const targets = this.filters;
54917
+ if (filters.must && targets) {
54918
+ ok = Object.entries(filters.must).reduce(
54919
+ (prev, [key, value]) => Boolean(prev && targets[key] == value),
54920
+ ok
54921
+ );
54922
+ }
54923
+ if (filters.must_not) {
54924
+ ok = !targets || Object.entries(filters.must_not).reduce(
54925
+ (prev, [key, value]) => Boolean(prev && targets[key] != value),
54926
+ ok
54927
+ );
54928
+ }
54929
+ }
54930
+ return ok;
54931
+ }
54932
+ toggleElement(selection2, data, variables = {}, where) {
54933
+ if (!this.remove(data, variables)) {
54934
+ this.addToList(selection2, data, variables, where);
54935
+ }
54936
+ }
54937
+ *[Symbol.iterator]() {
54938
+ let entries = [];
54939
+ let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
54940
+ if (!this.connection) {
54941
+ entries = flatten(value);
54942
+ } else {
54943
+ entries = this.cache._internal_unstable.storage.get(value, "edges").value;
54944
+ }
54945
+ for (let record2 of entries) {
54946
+ yield record2;
54947
+ }
54948
+ }
54949
+ };
54950
+ var ListCollection = class {
54951
+ lists = [];
54952
+ constructor(lists) {
54953
+ this.lists = lists;
54954
+ }
54955
+ get selection() {
54956
+ return this.lists[0].selection;
54957
+ }
54958
+ append(...args) {
54959
+ this.lists.forEach((list) => list.append(...args));
54960
+ }
54961
+ prepend(...args) {
54962
+ this.lists.forEach((list) => list.prepend(...args));
54963
+ }
54964
+ addToList(...args) {
54965
+ this.lists.forEach((list) => list.addToList(...args));
54966
+ }
54967
+ removeID(...args) {
54968
+ this.lists.forEach((list) => list.removeID(...args));
54969
+ }
54970
+ remove(...args) {
54971
+ this.lists.forEach((list) => list.remove(...args));
54972
+ }
54973
+ toggleElement(...args) {
54974
+ this.lists.forEach((list) => list.toggleElement(...args));
54975
+ }
54976
+ when(when) {
54977
+ return new ListCollection(
54978
+ this.lists.filter((list) => {
54979
+ return list.validateWhen(when);
54980
+ })
54981
+ );
54982
+ }
54983
+ includes(key) {
54984
+ return !!this.lists.find((list) => list.key === key);
54985
+ }
54986
+ deleteListWithKey(key) {
54987
+ return this.lists = this.lists.filter((list) => list.key !== key);
54988
+ }
54989
+ *[Symbol.iterator]() {
54990
+ for (let list of this.lists) {
54991
+ for (const entry of list) {
54992
+ yield entry;
54993
+ }
54994
+ }
54995
+ }
54996
+ };
54997
+
54998
+ // src/runtime/cache/schema.ts
54999
+ var SchemaManager = class {
55000
+ cache;
55001
+ fieldTypes = {};
55002
+ constructor(cache) {
55003
+ this.cache = cache;
55004
+ }
55005
+ setFieldType({
55006
+ parent,
55007
+ key,
55008
+ type,
55009
+ nullable = false,
55010
+ link
55011
+ }) {
55012
+ let parensIndex = key.indexOf("(");
55013
+ if (parensIndex !== -1) {
55014
+ key = key.substring(0, parensIndex);
55015
+ }
55016
+ if (parent === rootID) {
55017
+ parent = "Query";
55018
+ } else if (parent.includes(":")) {
55019
+ parent = parent.substring(0, parent.indexOf(":"));
55020
+ }
55021
+ if (!this.fieldTypes[parent]) {
55022
+ this.fieldTypes[parent] = {};
55023
+ }
55024
+ this.fieldTypes[parent][key] = {
55025
+ type,
55026
+ nullable,
55027
+ link: !!link
55028
+ };
55029
+ }
55030
+ fieldType(type, field) {
55031
+ return this.fieldTypes[type]?.[field] || null;
55032
+ }
55033
+ get config() {
55034
+ return this.cache._internal_unstable.config;
55035
+ }
55036
+ };
55037
+
55038
+ // src/runtime/cache/staleManager.ts
55039
+ var StaleManager = class {
55040
+ cache;
55041
+ fieldsTime = /* @__PURE__ */ new Map();
55042
+ constructor(cache) {
55043
+ this.cache = cache;
55044
+ }
55045
+ #initMapId = (id) => {
55046
+ if (!this.fieldsTime.get(id)) {
55047
+ this.fieldsTime.set(id, /* @__PURE__ */ new Map());
55048
+ }
55049
+ };
55050
+ getFieldTime(id, field) {
55051
+ return this.fieldsTime.get(id)?.get(field);
55052
+ }
55053
+ setFieldTimeToNow(id, field) {
55054
+ this.#initMapId(id);
55055
+ this.fieldsTime.get(id)?.set(field, new Date().valueOf());
55056
+ }
55057
+ markFieldStale(id, field) {
55058
+ this.#initMapId(id);
55059
+ this.fieldsTime.get(id)?.set(field, null);
55060
+ }
55061
+ markAllStale() {
55062
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
55063
+ for (const [field] of fieldMap.entries()) {
55064
+ this.markFieldStale(id, field);
55065
+ }
55066
+ }
55067
+ }
55068
+ markRecordStale(id) {
55069
+ const fieldsTimeOfType = this.fieldsTime.get(id);
55070
+ if (fieldsTimeOfType) {
55071
+ for (const [field] of fieldsTimeOfType.entries()) {
55072
+ this.markFieldStale(id, field);
55073
+ }
55074
+ }
55075
+ }
55076
+ markTypeStale(type) {
55077
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
55078
+ if (id.startsWith(`${type}:`)) {
55079
+ for (const [field] of fieldMap.entries()) {
55080
+ this.markFieldStale(id, field);
55081
+ }
55082
+ }
55083
+ }
55084
+ }
55085
+ markTypeFieldStale(type, field, when) {
55086
+ const key = computeKey({ field, args: when });
55087
+ for (const [id, fieldMap] of this.fieldsTime.entries()) {
55088
+ if (id.startsWith(`${type}:`)) {
55089
+ for (const local_field of fieldMap.keys()) {
55090
+ if (local_field === key) {
55091
+ this.markFieldStale(id, field);
55092
+ }
55093
+ }
55094
+ }
55095
+ }
55096
+ }
55097
+ delete(id, field) {
55098
+ if (this.fieldsTime.has(id)) {
55099
+ this.fieldsTime.get(id)?.delete(field);
55100
+ if (this.fieldsTime.get(id)?.size === 0) {
55101
+ this.fieldsTime.delete(id);
55102
+ }
55103
+ }
55104
+ }
55105
+ };
55106
+
55107
+ // src/runtime/cache/storage.ts
55108
+ var InMemoryStorage = class {
55109
+ data;
55110
+ idCount = 0;
55111
+ rank = 0;
55112
+ constructor() {
55113
+ this.data = [];
55114
+ }
55115
+ get layerCount() {
55116
+ return this.data.length;
55117
+ }
55118
+ get nextRank() {
55119
+ return this.rank++;
55120
+ }
55121
+ createLayer(optimistic = false) {
55122
+ const layer = new Layer(this.idCount++);
55123
+ layer.optimistic = optimistic;
55124
+ this.data.push(layer);
55125
+ return layer;
55126
+ }
55127
+ insert(id, field, location, target) {
55128
+ return this.topLayer.insert(id, field, location, target);
55129
+ }
55130
+ remove(id, field, target) {
55131
+ return this.topLayer.remove(id, field, target);
55132
+ }
55133
+ delete(id) {
55134
+ return this.topLayer.delete(id);
55135
+ }
55136
+ deleteField(id, field) {
55137
+ return this.topLayer.deleteField(id, field);
55138
+ }
55139
+ getLayer(id) {
55140
+ for (const layer of this.data) {
55141
+ if (layer.id === id) {
55142
+ return layer;
55143
+ }
55144
+ }
55145
+ throw new Error("Could not find layer with id: " + id);
55146
+ }
55147
+ replaceID(replacement) {
55148
+ for (const layer of this.data) {
55149
+ layer.replaceID(replacement);
55150
+ }
55151
+ }
55152
+ get(id, field) {
55153
+ const operations = {
55154
+ [OperationKind.insert]: {
55155
+ [OperationLocation.start]: [],
55156
+ [OperationLocation.end]: []
55157
+ },
55158
+ [OperationKind.remove]: /* @__PURE__ */ new Set()
55159
+ };
55160
+ const layerIDs = [];
55161
+ for (let i = this.data.length - 1; i >= 0; i--) {
55162
+ const layer = this.data[i];
55163
+ const [layerValue, kind] = layer.get(id, field);
55164
+ const layerOperations = layer.getOperations(id, field) || [];
55165
+ layer.deletedIDs.forEach((v) => {
55166
+ if (layer.operations[v]?.undoDeletesInList?.includes(field)) {
55167
+ return;
55168
+ }
55169
+ operations.remove.add(v);
55170
+ });
55171
+ if (typeof layerValue === "undefined" && layerOperations.length === 0) {
55172
+ if (layer.deletedIDs.size > 0) {
55173
+ layerIDs.push(layer.id);
55174
+ }
55175
+ continue;
55176
+ }
55177
+ if (typeof layerValue !== "undefined" && !Array.isArray(layerValue)) {
55178
+ return {
55179
+ value: layerValue,
55180
+ kind,
55181
+ displayLayers: [layer.id]
55182
+ };
55183
+ }
55184
+ layerIDs.push(layer.id);
55185
+ if (layerOperations.length > 0) {
55186
+ for (const op of layerOperations) {
55187
+ if (isRemoveOperation(op)) {
55188
+ operations.remove.add(op.id);
55189
+ }
55190
+ if (isInsertOperation(op)) {
55191
+ operations.insert[op.location].unshift(op.id);
55192
+ }
55193
+ if (isDeleteOperation(op)) {
55194
+ return {
55195
+ value: void 0,
55196
+ kind: "unknown",
55197
+ displayLayers: []
55198
+ };
55199
+ }
55200
+ }
55201
+ }
55202
+ if (typeof layerValue === "undefined") {
55203
+ continue;
55204
+ }
55205
+ if (!operations.remove.size && !operations.insert.start.length && !operations.insert.end.length) {
55206
+ return { value: layerValue, displayLayers: layerIDs, kind: "link" };
55207
+ }
55208
+ return {
55209
+ value: [...operations.insert.start, ...layerValue, ...operations.insert.end].filter(
55210
+ (value) => !operations.remove.has(value)
55211
+ ),
55212
+ displayLayers: layerIDs,
55213
+ kind
55214
+ };
55215
+ }
55216
+ return {
55217
+ value: void 0,
55218
+ kind: "unknown",
55219
+ displayLayers: []
55220
+ };
55221
+ }
55222
+ writeLink(id, field, value) {
55223
+ return this.topLayer.writeLink(id, field, value);
55224
+ }
55225
+ writeField(id, field, value) {
55226
+ return this.topLayer.writeField(id, field, value);
55227
+ }
55228
+ resolveLayer(id) {
55229
+ let startingIndex = null;
55230
+ for (const [index, layer] of this.data.entries()) {
55231
+ if (layer.id !== id) {
55232
+ continue;
55233
+ }
55234
+ startingIndex = index - 1;
55235
+ this.data[index].optimistic = false;
55236
+ break;
55237
+ }
55238
+ if (startingIndex === null) {
55239
+ throw new Error("could not find layer with id: " + id);
55240
+ }
55241
+ if (startingIndex === -1) {
55242
+ startingIndex = 0;
55243
+ }
55244
+ if (this.data[startingIndex].optimistic) {
55245
+ startingIndex++;
55246
+ }
55247
+ const baseLayer = this.data[startingIndex];
55248
+ let layerIndex = startingIndex;
55249
+ while (layerIndex < this.data.length) {
55250
+ const layer = this.data[layerIndex++];
55251
+ if (layer.optimistic) {
55252
+ layerIndex--;
55253
+ break;
55254
+ }
55255
+ baseLayer.writeLayer(layer);
55256
+ }
55257
+ this.data.splice(startingIndex + 1, layerIndex - startingIndex - 1);
55258
+ }
55259
+ get topLayer() {
55260
+ if (this.data.length === 0) {
55261
+ this.createLayer();
55262
+ }
55263
+ if (this.data[this.data.length - 1]?.optimistic) {
55264
+ this.createLayer();
55265
+ }
55266
+ return this.data[this.data.length - 1];
55267
+ }
55268
+ };
55269
+ var Layer = class {
55270
+ id;
55271
+ optimistic = false;
55272
+ fields = {};
55273
+ links = {};
55274
+ operations = {};
55275
+ deletedIDs = /* @__PURE__ */ new Set();
55276
+ constructor(id) {
55277
+ this.id = id;
55278
+ }
55279
+ get(id, field) {
55280
+ if (typeof this.links[id]?.[field] !== "undefined") {
55281
+ return [this.links[id][field], "link"];
55282
+ }
55283
+ return [this.fields[id]?.[field], "scalar"];
55284
+ }
55285
+ getOperations(id, field) {
55286
+ if (this.operations[id]?.deleted) {
55287
+ return [
55288
+ {
55289
+ kind: OperationKind.delete,
55290
+ target: id
55291
+ }
55292
+ ];
55293
+ }
55294
+ if (this.operations[id]?.fields?.[field]) {
55295
+ return this.operations[id].fields[field];
55296
+ }
55297
+ }
55298
+ writeField(id, field, value) {
55299
+ this.fields[id] = {
55300
+ ...this.fields[id],
55301
+ [field]: value
55302
+ };
55303
+ return this.id;
55304
+ }
55305
+ writeLink(id, field, value) {
55306
+ const valueList = Array.isArray(value) ? value : [value];
55307
+ for (const value2 of flatten(valueList)) {
55308
+ if (!value2) {
55309
+ continue;
55310
+ }
55311
+ const fieldOperations = this.operations[id]?.fields[field];
55312
+ if (this.operations[value2]?.deleted || this.deletedIDs.has(value2)) {
55313
+ this.operations[value2] = {
55314
+ ...this.operations[value2],
55315
+ undoDeletesInList: [...this.operations[id]?.undoDeletesInList || [], field]
55316
+ };
55317
+ } else if (value2 && fieldOperations?.length > 0) {
55318
+ this.operations[id].fields[field] = fieldOperations.filter(
55319
+ (op) => op.kind !== "remove" || op.id !== value2
55320
+ );
55321
+ }
55322
+ }
55323
+ this.links[id] = {
55324
+ ...this.links[id],
55325
+ [field]: value
55326
+ };
55327
+ return this.id;
55328
+ }
55329
+ isDisplayLayer(displayLayers) {
55330
+ return displayLayers.length === 0 || displayLayers.includes(this.id) || Math.max(...displayLayers) < this.id;
55331
+ }
55332
+ clear() {
55333
+ this.links = {};
55334
+ this.fields = {};
55335
+ this.operations = {};
55336
+ this.deletedIDs = /* @__PURE__ */ new Set();
55337
+ }
55338
+ replaceID({ from, to }) {
55339
+ this.fields[to] = this.fields[from];
55340
+ this.links[to] = this.links[from];
55341
+ this.operations[to] = this.operations[from] || { fields: {} };
55342
+ if (this.deletedIDs.has(from)) {
55343
+ this.deletedIDs.add(to);
55344
+ }
55345
+ }
55346
+ removeUndefinedFields() {
55347
+ for (const [id, fields] of Object.entries(this.fields)) {
55348
+ for (const [field, value] of Object.entries(fields)) {
55349
+ if (typeof value === "undefined") {
55350
+ try {
55351
+ delete this.fields[id][field];
55352
+ } catch {
55353
+ }
55354
+ try {
55355
+ delete this.links[id][field];
55356
+ } catch {
55357
+ }
55358
+ }
55359
+ }
55360
+ if (Object.keys(fields || {}).length === 0) {
55361
+ delete this.fields[id];
55362
+ }
55363
+ if (Object.keys(this.links[id] || {}).length === 0) {
55364
+ delete this.links[id];
55365
+ }
55366
+ }
55367
+ }
55368
+ delete(id) {
55369
+ this.operations = {
55370
+ ...this.operations,
55371
+ [id]: {
55372
+ ...this.operations[id],
55373
+ deleted: true,
55374
+ undoDeletesInList: []
55375
+ }
55376
+ };
55377
+ this.deletedIDs.add(id);
55378
+ }
55379
+ deleteField(id, field) {
55380
+ this.fields[id] = {
55381
+ ...this.fields[id],
55382
+ [field]: void 0
55383
+ };
55384
+ }
55385
+ insert(id, field, where, target) {
55386
+ this.addFieldOperation(id, field, {
55387
+ kind: OperationKind.insert,
55388
+ id: target,
55389
+ location: where
55390
+ });
55391
+ }
55392
+ remove(id, field, target) {
55393
+ this.addFieldOperation(id, field, {
55394
+ kind: OperationKind.remove,
55395
+ id: target
55396
+ });
55397
+ }
55398
+ writeLayer(layer) {
55399
+ if (layer.id === this.id) {
55400
+ return;
55401
+ }
55402
+ for (const [id, ops] of Object.entries(layer.operations)) {
55403
+ const fields = {};
55404
+ for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
55405
+ for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
55406
+ fields[fieldName] = [...fields[fieldName] || [], ...operations];
55407
+ }
55408
+ }
55409
+ if (Object.keys(fields).length > 0) {
55410
+ this.operations[id] = {
55411
+ ...this.operations[id],
55412
+ fields
55413
+ };
55414
+ }
55415
+ if (ops?.deleted) {
55416
+ delete this.fields[id];
55417
+ delete this.links[id];
55418
+ }
55419
+ }
55420
+ for (const [id, values] of Object.entries(layer.fields)) {
55421
+ if (!values) {
55422
+ continue;
55423
+ }
55424
+ for (const [field, value] of Object.entries(values)) {
55425
+ this.writeField(id, field, value);
55426
+ }
55427
+ }
55428
+ for (const [id, values] of Object.entries(layer.links)) {
55429
+ if (!values) {
55430
+ continue;
55431
+ }
55432
+ for (const [field, value] of Object.entries(values)) {
55433
+ this.writeLink(id, field, value);
55434
+ }
55435
+ }
55436
+ layer.deletedIDs.forEach((v) => this.deletedIDs.add(v));
55437
+ }
55438
+ addFieldOperation(id, field, operation) {
55439
+ this.operations = {
55440
+ ...this.operations,
55441
+ [id]: {
55442
+ ...this.operations[id],
55443
+ fields: {
55444
+ [field]: [...this.operations[id]?.fields[field] || [], operation]
55445
+ }
55446
+ }
55447
+ };
55448
+ }
55449
+ };
55450
+ function isDeleteOperation(value) {
55451
+ return !!value && value.kind === OperationKind.delete;
55452
+ }
55453
+ function isInsertOperation(value) {
55454
+ return !!value && value.kind === OperationKind.insert;
55455
+ }
55456
+ function isRemoveOperation(value) {
55457
+ return !!value && value.kind === OperationKind.remove;
55458
+ }
55459
+ var OperationLocation = {
55460
+ start: "start",
55461
+ end: "end"
55462
+ };
55463
+ var OperationKind = {
55464
+ delete: "delete",
55465
+ insert: "insert",
55466
+ remove: "remove"
55467
+ };
55468
+
55469
+ // src/runtime/cache/stuff.ts
55470
+ function evaluateKey(key, variables = {}) {
55471
+ let evaluated = "";
55472
+ let varName = "";
55473
+ let inString = false;
55474
+ for (const char of key) {
55475
+ if (varName) {
55476
+ if (varChars.includes(char)) {
55477
+ varName += char;
55478
+ continue;
55479
+ }
55480
+ const value = variables[varName.slice(1)];
55481
+ evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
55482
+ varName = "";
55483
+ }
55484
+ if (char === "$" && !inString) {
55485
+ varName = "$";
55486
+ continue;
55487
+ }
55488
+ if (char === '"') {
55489
+ inString = !inString;
55490
+ }
55491
+ evaluated += char;
55492
+ }
55493
+ return evaluated;
55494
+ }
55495
+ var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
55496
+
55497
+ // src/runtime/cache/subscription.ts
55498
+ var InMemorySubscriptions = class {
55499
+ cache;
55500
+ constructor(cache) {
55501
+ this.cache = cache;
55502
+ }
55503
+ subscribers = {};
55504
+ referenceCounts = {};
55505
+ keyVersions = {};
55506
+ add({
55507
+ parent,
55508
+ spec,
55509
+ selection: selection2,
55510
+ variables,
55511
+ parentType
55512
+ }) {
55513
+ const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
55514
+ let targetSelection = getFieldsForType(selection2, __typename);
55515
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55516
+ const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
55517
+ const key = evaluateKey(keyRaw, variables);
55518
+ let targetSelection2;
55519
+ if (innerSelection) {
55520
+ const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
55521
+ targetSelection2 = getFieldsForType(innerSelection, __typename2);
55522
+ }
55523
+ this.addFieldSubscription({
55524
+ id: parent,
55525
+ key,
55526
+ selection: [spec, targetSelection2],
55527
+ type
55528
+ });
55529
+ if (list) {
55530
+ this.registerList({
55531
+ list,
55532
+ filters,
55533
+ id: parent,
55534
+ key,
55535
+ variables,
55536
+ selection: innerSelection,
55537
+ parentType: parentType || spec.rootType
55538
+ });
55539
+ }
55540
+ if (innerSelection) {
55541
+ const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
55542
+ parent,
55543
+ key
55544
+ );
55545
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
55546
+ for (const child of children) {
55547
+ if (!child) {
55548
+ continue;
55549
+ }
55550
+ this.add({
55551
+ parent: child,
55552
+ spec,
55553
+ selection: innerSelection,
55554
+ variables,
55555
+ parentType: type
55556
+ });
55557
+ }
55558
+ }
55559
+ }
55560
+ }
55561
+ addFieldSubscription({
55562
+ id,
55563
+ key,
55564
+ selection: selection2,
55565
+ type
55566
+ }) {
55567
+ const spec = selection2[0];
55568
+ if (!this.subscribers[id]) {
55569
+ this.subscribers[id] = {};
55570
+ }
55571
+ if (!this.subscribers[id][key]) {
55572
+ this.subscribers[id][key] = [];
55573
+ }
55574
+ if (!this.keyVersions[key]) {
55575
+ this.keyVersions[key] = /* @__PURE__ */ new Set();
55576
+ }
55577
+ this.keyVersions[key].add(key);
55578
+ if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
55579
+ this.subscribers[id][key].push([spec, selection2[1]]);
55580
+ }
55581
+ if (!this.referenceCounts[id]) {
55582
+ this.referenceCounts[id] = {};
55583
+ }
55584
+ if (!this.referenceCounts[id][key]) {
55585
+ this.referenceCounts[id][key] = /* @__PURE__ */ new Map();
55586
+ }
55587
+ const counts = this.referenceCounts[id][key];
55588
+ counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
55589
+ this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
55590
+ const { selection: innerSelection } = selection2[1]?.[key] ?? {};
55591
+ }
55592
+ registerList({
55593
+ list,
55594
+ id,
55595
+ key,
55596
+ parentType,
55597
+ selection: selection2,
55598
+ filters,
55599
+ variables
55600
+ }) {
55601
+ this.cache._internal_unstable.lists.add({
55602
+ name: list.name,
55603
+ connection: list.connection,
55604
+ recordID: id,
55605
+ recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
55606
+ listType: list.type,
55607
+ key,
55608
+ selection: selection2,
55609
+ filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
55610
+ return {
55611
+ ...acc,
55612
+ [key2]: kind !== "Variable" ? value : variables[value]
55613
+ };
55614
+ }, {})
55615
+ });
55616
+ }
55617
+ addMany({
55618
+ parent,
55619
+ variables,
55620
+ subscribers,
55621
+ parentType
55622
+ }) {
55623
+ for (const [spec, targetSelection] of subscribers) {
55624
+ for (const selection2 of Object.values(targetSelection ?? {})) {
55625
+ const {
55626
+ type: linkedType,
55627
+ keyRaw,
55628
+ selection: innerSelection,
55629
+ list,
55630
+ filters
55631
+ } = selection2;
55632
+ const key = evaluateKey(keyRaw, variables);
55633
+ const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
55634
+ this.addFieldSubscription({
55635
+ id: parent,
55636
+ key,
55637
+ selection: [spec, fieldSelection],
55638
+ type: linkedType
55639
+ });
55640
+ if (list) {
55641
+ this.registerList({
55642
+ list,
55643
+ filters,
55644
+ id: parent,
55645
+ key,
55646
+ variables,
55647
+ selection: innerSelection,
55648
+ parentType: parentType || spec.rootType
55649
+ });
55650
+ }
55651
+ const childSelection = selection2.selection;
55652
+ if (childSelection) {
55653
+ const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
55654
+ const children = !Array.isArray(link) ? [link] : flatten(link);
55655
+ for (const linkedRecord of children) {
55656
+ if (!linkedRecord) {
55657
+ continue;
55658
+ }
55659
+ const __typename = this.cache._internal_unstable.storage.get(
55660
+ linkedRecord,
55661
+ "__typename"
55662
+ ).value;
55663
+ let targetSelection2 = getFieldsForType(childSelection, __typename);
55664
+ this.addMany({
55665
+ parent: linkedRecord,
55666
+ variables,
55667
+ subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
55668
+ parentType: linkedType
55669
+ });
55670
+ }
55671
+ }
55672
+ }
55673
+ }
55674
+ }
55675
+ get(id, field) {
55676
+ return this.subscribers[id]?.[field] || [];
55677
+ }
55678
+ remove(id, selection2, targets, variables, visited = []) {
55679
+ visited.push(id);
55680
+ const linkedIDs = [];
55681
+ const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
55682
+ let targetSelection = getFieldsForType(selection2, __typename);
55683
+ for (const fieldSelection of Object.values(targetSelection || {})) {
55684
+ const key = evaluateKey(fieldSelection.keyRaw, variables);
55685
+ this.removeSubscribers(id, key, targets);
55686
+ if (!fieldSelection.selection) {
55687
+ continue;
55688
+ }
55689
+ const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
55690
+ const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
55691
+ for (const link of links) {
55692
+ if (link !== null) {
55693
+ linkedIDs.push([link, fieldSelection.selection || {}]);
55694
+ }
55695
+ }
55696
+ }
55697
+ for (const [linkedRecordID, linkFields] of linkedIDs) {
55698
+ this.remove(linkedRecordID, linkFields, targets, visited);
55699
+ }
55700
+ }
55701
+ removeSubscribers(id, fieldName, specs) {
55702
+ let targets = [];
55703
+ for (const spec of specs) {
55704
+ if (!this.referenceCounts[id]?.[fieldName]?.has(spec.set)) {
55705
+ continue;
55706
+ }
55707
+ const counts = this.referenceCounts[id][fieldName];
55708
+ const newVal = (counts.get(spec.set) || 0) - 1;
55709
+ counts.set(spec.set, newVal);
55710
+ if (newVal <= 0) {
55711
+ targets.push(spec.set);
55712
+ counts.delete(spec.set);
55713
+ }
55714
+ }
55715
+ if (this.subscribers[id]) {
55716
+ this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
55717
+ ([{ set }]) => !targets.includes(set)
55718
+ );
55719
+ }
55720
+ }
55721
+ removeAllSubscribers(id, targets, visited = []) {
55722
+ visited.push(id);
55723
+ for (const field of Object.keys(this.subscribers[id] || [])) {
55724
+ const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
55725
+ this.removeSubscribers(id, field, subscribers);
55726
+ const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
55727
+ if (kind === "scalar") {
55728
+ continue;
55729
+ }
55730
+ const nextTargets = Array.isArray(value) ? flatten(value) : [value];
55731
+ for (const id2 of nextTargets) {
55732
+ if (visited.includes(id2)) {
55733
+ continue;
55734
+ }
55735
+ this.removeAllSubscribers(id2, subscribers, visited);
55736
+ }
55737
+ }
55738
+ }
55739
+ };
55740
+
55741
+ // src/runtime/cache/cache.ts
55742
+ var Cache = class {
55743
+ _internal_unstable;
55744
+ constructor(config2) {
55745
+ this._internal_unstable = new CacheInternal({
55746
+ cache: this,
55747
+ storage: new InMemoryStorage(),
55748
+ subscriptions: new InMemorySubscriptions(this),
55749
+ lists: new ListManager(this, rootID),
55750
+ lifetimes: new GarbageCollector(this),
55751
+ staleManager: new StaleManager(this),
55752
+ schema: new SchemaManager(this)
55753
+ });
55754
+ if (config2) {
55755
+ this.setConfig(defaultConfigValues(config2));
55756
+ }
55757
+ }
55758
+ write({
55759
+ layer: layerID,
55760
+ notifySubscribers = [],
55761
+ ...args
55762
+ }) {
55763
+ const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
55764
+ const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
55765
+ const notified = [];
55766
+ for (const spec of subscribers.concat(notifySubscribers)) {
55767
+ if (!notified.includes(spec.set)) {
55768
+ notified.push(spec.set);
55769
+ spec.set(
55770
+ this._internal_unstable.getSelection({
55771
+ parent: spec.parentID || rootID,
55772
+ selection: spec.selection,
55773
+ variables: spec.variables?.() || {}
55774
+ }).data
55775
+ );
55776
+ }
55777
+ }
55778
+ return subscribers;
55779
+ }
55780
+ read(...args) {
55781
+ const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
55782
+ if (!hasData) {
55783
+ return { data: null, partial: false, stale: false };
55784
+ }
55785
+ return {
55786
+ data,
55787
+ partial,
55788
+ stale
55789
+ };
55790
+ }
55791
+ subscribe(spec, variables = {}) {
55792
+ return this._internal_unstable.subscriptions.add({
55793
+ parent: spec.parentID || rootID,
55794
+ spec,
55795
+ selection: spec.selection,
55796
+ variables
55797
+ });
55798
+ }
55799
+ unsubscribe(spec, variables = {}) {
55800
+ return this._internal_unstable.subscriptions.remove(
55801
+ spec.parentID || rootID,
55802
+ spec.selection,
55803
+ [spec],
55804
+ variables
55805
+ );
55806
+ }
55807
+ list(name, parentID, allLists) {
55808
+ const handler = this._internal_unstable.lists.get(name, parentID, allLists);
55809
+ if (!handler) {
55810
+ throw new Error(
55811
+ `Cannot find list with name: ${name}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
55812
+ );
55813
+ }
55814
+ return handler;
55815
+ }
55816
+ delete(id) {
55817
+ this._internal_unstable.subscriptions.removeAllSubscribers(id);
55818
+ this._internal_unstable.lists.removeIDFromAllLists(id);
55819
+ this._internal_unstable.storage.delete(id);
55820
+ }
55821
+ setConfig(config2) {
55822
+ this._internal_unstable.setConfig(config2);
55823
+ }
55824
+ markTypeStale(options) {
55825
+ if (!options) {
55826
+ this._internal_unstable.staleManager.markAllStale();
55827
+ } else if (!options.field) {
55828
+ this._internal_unstable.staleManager.markTypeStale(options.type);
55829
+ } else {
55830
+ this._internal_unstable.staleManager.markTypeFieldStale(
55831
+ options.type,
55832
+ options.field,
55833
+ options.when
55834
+ );
55835
+ }
55836
+ }
55837
+ markRecordStale(id, options) {
55838
+ if (options.field) {
55839
+ const key = computeKey({ field: options.field, args: options.when ?? {} });
55840
+ this._internal_unstable.staleManager.markFieldStale(id, key);
55841
+ } else {
55842
+ this._internal_unstable.staleManager.markRecordStale(id);
55843
+ }
55844
+ }
55845
+ getFieldTime(id, field) {
55846
+ return this._internal_unstable.staleManager.getFieldTime(id, field);
55847
+ }
55848
+ };
55849
+ var CacheInternal = class {
55850
+ _disabled = false;
55851
+ config = defaultConfigValues({
55852
+ plugins: {
55853
+ "houdini-svelte": {
55854
+ client: ""
55855
+ }
55856
+ }
55857
+ });
55858
+ storage;
55859
+ subscriptions;
55860
+ lists;
55861
+ cache;
55862
+ lifetimes;
55863
+ staleManager;
55864
+ schema;
55865
+ constructor({
55866
+ storage,
55867
+ subscriptions,
55868
+ lists,
55869
+ cache,
55870
+ lifetimes,
55871
+ staleManager,
55872
+ schema
55873
+ }) {
55874
+ this.storage = storage;
55875
+ this.subscriptions = subscriptions;
55876
+ this.lists = lists;
55877
+ this.cache = cache;
55878
+ this.lifetimes = lifetimes;
55879
+ this.staleManager = staleManager;
55880
+ this.schema = schema;
55881
+ this._disabled = typeof globalThis.window === "undefined";
55882
+ try {
55883
+ if (process.env.HOUDINI_TEST === "true") {
55884
+ this._disabled = false;
55885
+ }
55886
+ } catch {
55887
+ }
55888
+ }
55889
+ setConfig(config2) {
55890
+ this.config = config2;
55891
+ }
55892
+ writeSelection({
55893
+ data,
55894
+ selection: selection2,
55895
+ variables = {},
55896
+ parent = rootID,
55897
+ applyUpdates,
55898
+ layer,
55899
+ toNotify = [],
55900
+ forceNotify,
55901
+ forceStale
55902
+ }) {
55903
+ if (this._disabled) {
55904
+ return [];
55905
+ }
55906
+ let targetSelection = getFieldsForType(selection2, data["__typename"]);
55907
+ for (const [field, value] of Object.entries(data)) {
55908
+ if (!selection2 || !targetSelection[field]) {
55909
+ throw new Error(
55910
+ "Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection2)
55911
+ );
55912
+ }
55913
+ let {
55914
+ type: linkedType,
55915
+ keyRaw,
55916
+ selection: fieldSelection,
55917
+ operations,
55918
+ abstract: isAbstract,
55919
+ updates,
55920
+ nullable
55921
+ } = targetSelection[field];
55922
+ const key = evaluateKey(keyRaw, variables);
55923
+ this.schema.setFieldType({
55924
+ parent,
55925
+ key: keyRaw,
55926
+ type: linkedType,
55927
+ nullable,
55928
+ link: !!fieldSelection
55929
+ });
55930
+ const currentSubscribers = this.subscriptions.get(parent, key);
55931
+ const specs = currentSubscribers.map((sub) => sub[0]);
55932
+ const { value: previousValue, displayLayers } = this.storage.get(parent, key);
55933
+ const displayLayer = layer.isDisplayLayer(displayLayers);
55934
+ if (displayLayer) {
55935
+ this.lifetimes.resetLifetime(parent, key);
55936
+ if (forceStale) {
55937
+ this.staleManager.markFieldStale(parent, key);
55938
+ } else {
55939
+ this.staleManager.setFieldTimeToNow(parent, key);
55940
+ }
55941
+ }
55942
+ if (!fieldSelection) {
55943
+ let newValue = value;
55944
+ if (updates && applyUpdates && Array.isArray(value)) {
55945
+ for (const update of applyUpdates) {
55946
+ if (!updates.includes(update)) {
55947
+ continue;
55948
+ }
55949
+ if (update === "append") {
55950
+ newValue = (previousValue || []).concat(value);
55951
+ } else if (update === "prepend") {
55952
+ newValue = value.concat(previousValue || []);
55953
+ }
55954
+ }
55955
+ }
55956
+ if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
55957
+ newValue = previousValue;
55958
+ } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
55959
+ newValue = previousValue;
55960
+ }
55961
+ const valueChanged = !deepEquals(newValue, previousValue);
55962
+ if (displayLayer && (valueChanged || forceNotify)) {
55963
+ toNotify.push(...currentSubscribers);
55964
+ }
55965
+ layer.writeField(parent, key, newValue);
55966
+ } else if (value === null) {
55967
+ if (previousValue === null) {
55968
+ continue;
55969
+ }
55970
+ const previousLinks = flatten([previousValue]);
55971
+ for (const link of previousLinks) {
55972
+ this.subscriptions.remove(link, fieldSelection, specs, variables);
55973
+ }
55974
+ layer.writeLink(parent, key, null);
55975
+ toNotify.push(...currentSubscribers);
55976
+ } else if (value instanceof Object && !Array.isArray(value)) {
55977
+ if (isAbstract) {
55978
+ if (!value.__typename) {
55979
+ throw new Error(
55980
+ "Encountered interface type without __typename in the payload"
55981
+ );
55982
+ }
55983
+ linkedType = value.__typename;
55984
+ }
55985
+ const embedded = this.idFields(linkedType)?.filter(
55986
+ (field2) => typeof value[field2] === "undefined"
55987
+ ).length > 0;
55988
+ let linkedID = null;
55989
+ if (value !== null) {
55990
+ linkedID = !embedded ? this.id(linkedType, value) : `${parent}.${key}`;
55991
+ }
55992
+ let linkChange = linkedID !== previousValue;
55993
+ layer.writeLink(parent, key, linkedID);
55994
+ if (linkedID && displayLayer && (linkChange || forceNotify)) {
55995
+ if (previousValue && typeof previousValue === "string") {
55996
+ this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
55997
+ }
55998
+ this.subscriptions.addMany({
55999
+ parent: linkedID,
56000
+ subscribers: currentSubscribers,
56001
+ variables,
56002
+ parentType: linkedType
56003
+ });
56004
+ toNotify.push(...currentSubscribers);
56005
+ }
56006
+ if (linkedID) {
56007
+ this.writeSelection({
56008
+ selection: fieldSelection,
56009
+ parent: linkedID,
56010
+ data: value,
56011
+ variables,
56012
+ toNotify,
56013
+ applyUpdates,
56014
+ layer,
56015
+ forceNotify
56016
+ });
56017
+ }
56018
+ } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
56019
+ let oldIDs = [...previousValue || []];
56020
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
56021
+ if (!id) {
56022
+ return "";
56023
+ }
56024
+ const { value: cursorField } = this.storage.get(id, "cursor");
56025
+ if (cursorField) {
56026
+ return "";
56027
+ }
56028
+ const { value: node } = this.storage.get(id, "node");
56029
+ if (!node) {
56030
+ return "";
56031
+ }
56032
+ return node;
56033
+ });
56034
+ let linkedIDs = [];
56035
+ const { newIDs, nestedIDs } = this.extractNestedListIDs({
56036
+ value,
56037
+ abstract: Boolean(isAbstract),
56038
+ specs: toNotify,
56039
+ applyUpdates,
56040
+ recordID: parent,
56041
+ key,
56042
+ linkedType,
56043
+ variables,
56044
+ fields: fieldSelection,
56045
+ layer,
56046
+ forceNotify
56047
+ });
56048
+ if (applyUpdates && updates) {
56049
+ if (key === "edges") {
56050
+ const newNodeIDs = [];
56051
+ for (const id of newIDs) {
56052
+ if (!id) {
56053
+ continue;
56054
+ }
56055
+ const { value: node } = this.storage.get(id, "node");
56056
+ if (typeof node !== "string") {
56057
+ continue;
56058
+ }
56059
+ if (!node || !this.storage.get(node, "__typename")) {
56060
+ continue;
56061
+ }
56062
+ newNodeIDs.push(node);
56063
+ }
56064
+ oldIDs = oldIDs.filter((id) => {
56065
+ if (!id) {
56066
+ return true;
56067
+ }
56068
+ const { value: value2 } = this.storage.get(id, "node");
56069
+ const node = value2;
56070
+ if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
56071
+ return false;
56072
+ }
56073
+ return true;
56074
+ });
56075
+ }
56076
+ for (const update of applyUpdates) {
56077
+ if (update !== "replace" && !updates.includes(update)) {
56078
+ continue;
56079
+ }
56080
+ if (update === "prepend") {
56081
+ linkedIDs = newIDs.concat(oldIDs);
56082
+ } else if (update === "append") {
56083
+ linkedIDs = oldIDs.concat(newIDs);
56084
+ } else if (update === "replace") {
56085
+ linkedIDs = newIDs;
56086
+ }
56087
+ }
56088
+ } else {
56089
+ linkedIDs = nestedIDs;
56090
+ }
56091
+ const contentChanged = !deepEquals(linkedIDs, oldIDs);
56092
+ if (contentChanged || forceNotify) {
56093
+ toNotify.push(...currentSubscribers);
56094
+ }
56095
+ for (const lostID of oldIDs) {
56096
+ if (linkedIDs.includes(lostID) || !lostID) {
56097
+ continue;
56098
+ }
56099
+ this.subscriptions.remove(lostID, fieldSelection, specs, variables);
56100
+ }
56101
+ if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
56102
+ layer.writeLink(parent, key, linkedIDs);
56103
+ }
56104
+ for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
56105
+ if (id == null) {
56106
+ continue;
56107
+ }
56108
+ this.subscriptions.addMany({
56109
+ parent: id,
56110
+ subscribers: currentSubscribers,
56111
+ variables,
56112
+ parentType: linkedType
56113
+ });
56114
+ }
56115
+ }
56116
+ for (const operation of operations || []) {
56117
+ let parentID;
56118
+ if (operation.parentID) {
56119
+ if (operation.parentID.kind !== "Variable") {
56120
+ parentID = operation.parentID.value;
56121
+ } else {
56122
+ const id = variables[operation.parentID.value];
56123
+ if (typeof id !== "string") {
56124
+ throw new Error("parentID value must be a string");
56125
+ }
56126
+ parentID = id;
56127
+ }
56128
+ }
56129
+ if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
56130
+ continue;
56131
+ }
56132
+ const targets = Array.isArray(value) ? value : [value];
56133
+ for (const target of targets) {
56134
+ if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
56135
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
56136
+ fieldSelection,
56137
+ target,
56138
+ variables,
56139
+ operation.position || "last"
56140
+ );
56141
+ } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
56142
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
56143
+ } else if (operation.action === "delete" && operation.type) {
56144
+ if (typeof target !== "string") {
56145
+ throw new Error("Cannot delete a record with a non-string ID");
56146
+ }
56147
+ const targetID = this.id(operation.type, target);
56148
+ if (!targetID) {
56149
+ continue;
56150
+ }
56151
+ this.cache.delete(targetID);
56152
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
56153
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
56154
+ fieldSelection,
56155
+ target,
56156
+ variables,
56157
+ operation.position || "last"
56158
+ );
56159
+ }
56160
+ }
56161
+ }
56162
+ }
56163
+ return toNotify;
56164
+ }
56165
+ getSelection({
56166
+ selection: selection2,
56167
+ parent = rootID,
56168
+ variables,
56169
+ stepsFromConnection = null
56170
+ }) {
56171
+ if (parent === null) {
56172
+ return { data: null, partial: false, stale: false, hasData: true };
56173
+ }
56174
+ const target = {};
56175
+ let hasData = false;
56176
+ let partial = false;
56177
+ let cascadeNull = false;
56178
+ let stale = false;
56179
+ const typename = this.storage.get(parent, "__typename").value;
56180
+ let targetSelection = getFieldsForType(selection2, typename);
56181
+ for (const [
56182
+ attributeName,
56183
+ { type, keyRaw, selection: fieldSelection, nullable, list }
56184
+ ] of Object.entries(targetSelection)) {
56185
+ const key = evaluateKey(keyRaw, variables);
56186
+ const { value } = this.storage.get(parent, key);
56187
+ const dt_field = this.staleManager.getFieldTime(parent, key);
56188
+ if (dt_field === null) {
56189
+ stale = true;
56190
+ }
56191
+ let nextStep = stepsFromConnection;
56192
+ if (nextStep !== null) {
56193
+ if (nextStep >= 2) {
56194
+ nextStep = null;
56195
+ } else {
56196
+ nextStep += 1;
56197
+ }
56198
+ }
56199
+ if (list?.connection) {
56200
+ nextStep = 0;
56201
+ }
56202
+ const embeddedCursor = key === "cursor" && stepsFromConnection === 1;
56203
+ if (typeof value === "undefined" && !embeddedCursor) {
56204
+ partial = true;
56205
+ }
56206
+ if (typeof value === "undefined" || value === null) {
56207
+ target[attributeName] = null;
56208
+ if (typeof value !== "undefined") {
56209
+ hasData = true;
56210
+ }
56211
+ } else if (!fieldSelection) {
56212
+ const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
56213
+ if (fnUnmarshal) {
56214
+ target[attributeName] = fnUnmarshal(value);
56215
+ } else {
56216
+ target[attributeName] = value;
56217
+ }
56218
+ hasData = true;
56219
+ } else if (Array.isArray(value)) {
56220
+ const listValue = this.hydrateNestedList({
56221
+ fields: fieldSelection,
56222
+ variables,
56223
+ linkedList: value,
56224
+ stepsFromConnection: nextStep
56225
+ });
56226
+ target[attributeName] = listValue.data;
56227
+ if (listValue.partial) {
56228
+ partial = true;
56229
+ }
56230
+ if (listValue.stale) {
56231
+ stale = true;
56232
+ }
56233
+ if (listValue.hasData || value.length === 0) {
56234
+ hasData = true;
56235
+ }
56236
+ } else {
56237
+ const objectFields = this.getSelection({
56238
+ parent: value,
56239
+ selection: fieldSelection,
56240
+ variables,
56241
+ stepsFromConnection: nextStep
56242
+ });
56243
+ target[attributeName] = objectFields.data;
56244
+ if (objectFields.partial) {
56245
+ partial = true;
56246
+ }
56247
+ if (objectFields.stale) {
56248
+ stale = true;
56249
+ }
56250
+ if (objectFields.hasData) {
56251
+ hasData = true;
56252
+ }
56253
+ }
56254
+ if (target[attributeName] === null && !nullable && !embeddedCursor) {
56255
+ cascadeNull = true;
56256
+ }
56257
+ }
56258
+ return {
56259
+ data: cascadeNull ? null : target,
56260
+ partial: hasData && partial,
56261
+ stale: hasData && stale,
56262
+ hasData
56263
+ };
56264
+ }
56265
+ id(type, data) {
56266
+ const id = typeof data === "string" ? data : this.computeID(type, data);
56267
+ if (!id) {
56268
+ return null;
56269
+ }
56270
+ if (!type) {
56271
+ return id;
56272
+ }
56273
+ return type + ":" + id;
56274
+ }
56275
+ idFields(type) {
56276
+ return keyFieldsForType(this.config, type);
56277
+ }
56278
+ computeID(type, data) {
56279
+ return computeID(this.config, type, data);
56280
+ }
56281
+ hydrateNestedList({
56282
+ fields,
56283
+ variables,
56284
+ linkedList,
56285
+ stepsFromConnection
56286
+ }) {
56287
+ const result = [];
56288
+ let partialData = false;
56289
+ let stale = false;
56290
+ let hasValues = false;
56291
+ for (const entry of linkedList) {
56292
+ if (Array.isArray(entry)) {
56293
+ const nestedValue = this.hydrateNestedList({
56294
+ fields,
56295
+ variables,
56296
+ linkedList: entry,
56297
+ stepsFromConnection
56298
+ });
56299
+ result.push(nestedValue.data);
56300
+ if (nestedValue.partial) {
56301
+ partialData = true;
56302
+ }
56303
+ continue;
56304
+ }
56305
+ if (entry === null) {
56306
+ result.push(entry);
56307
+ continue;
56308
+ }
56309
+ const {
56310
+ data,
56311
+ partial,
56312
+ stale: local_stale,
56313
+ hasData
56314
+ } = this.getSelection({
56315
+ parent: entry,
56316
+ selection: fields,
56317
+ variables,
56318
+ stepsFromConnection
56319
+ });
56320
+ result.push(data);
56321
+ if (partial) {
56322
+ partialData = true;
56323
+ }
56324
+ if (local_stale) {
56325
+ stale = true;
56326
+ }
56327
+ if (hasData) {
56328
+ hasValues = true;
56329
+ }
56330
+ }
56331
+ return {
56332
+ data: result,
56333
+ partial: partialData,
56334
+ stale,
56335
+ hasData: hasValues
56336
+ };
56337
+ }
56338
+ extractNestedListIDs({
56339
+ value,
56340
+ abstract,
56341
+ recordID,
56342
+ key,
56343
+ linkedType,
56344
+ fields,
56345
+ variables,
56346
+ applyUpdates,
56347
+ specs,
56348
+ layer,
56349
+ forceNotify
56350
+ }) {
56351
+ const nestedIDs = [];
56352
+ const newIDs = [];
56353
+ for (const [i, entry] of value.entries()) {
56354
+ if (Array.isArray(entry)) {
56355
+ const inner = this.extractNestedListIDs({
56356
+ value: entry,
56357
+ abstract,
56358
+ recordID,
56359
+ key,
56360
+ linkedType,
56361
+ fields,
56362
+ variables,
56363
+ applyUpdates,
56364
+ specs,
56365
+ layer,
56366
+ forceNotify
56367
+ });
56368
+ newIDs.push(...inner.newIDs);
56369
+ nestedIDs[i] = inner.nestedIDs;
56370
+ continue;
56371
+ }
56372
+ if (entry === null || typeof entry === "undefined") {
56373
+ newIDs.push(null);
56374
+ nestedIDs[i] = null;
56375
+ continue;
56376
+ }
56377
+ const entryObj = entry;
56378
+ let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
56379
+ const embedded = this.idFields(linkedType)?.filter(
56380
+ (field) => typeof entry[field] === "undefined"
56381
+ ).length > 0;
56382
+ const typename = entryObj.__typename;
56383
+ let innerType = linkedType;
56384
+ if (abstract) {
56385
+ if (!typename) {
56386
+ throw new Error("Encountered interface type without __typename in the payload");
56387
+ }
56388
+ innerType = typename;
56389
+ }
56390
+ if (!embedded) {
56391
+ const id = this.id(innerType, entry);
56392
+ if (id) {
56393
+ linkedID = id;
56394
+ } else {
56395
+ continue;
56396
+ }
56397
+ }
56398
+ this.writeSelection({
56399
+ root: rootID,
56400
+ selection: fields,
56401
+ parent: linkedID,
56402
+ data: entryObj,
56403
+ variables,
56404
+ toNotify: specs,
56405
+ applyUpdates,
56406
+ layer,
56407
+ forceNotify
56408
+ });
56409
+ newIDs.push(linkedID);
56410
+ nestedIDs[i] = linkedID;
56411
+ }
56412
+ return { newIDs, nestedIDs };
56413
+ }
56414
+ collectGarbage() {
56415
+ this.lifetimes.tick();
56416
+ if (this.storage.layerCount === 1) {
56417
+ this.storage.topLayer.removeUndefinedFields();
56418
+ }
56419
+ }
56420
+ };
56421
+ var rootID = "_ROOT_";
56422
+
56423
+ // src/runtime/cache/index.ts
56424
+ var cache_default = new Cache();
56425
+
56426
+ // src/runtime/client/utils/documentPlugins.ts
56427
+ var documentPlugin = (kind, source) => {
56428
+ return () => {
56429
+ const sourceHandlers = source();
56430
+ const enterWrapper = (handler) => {
56431
+ return !handler ? void 0 : (ctx, handlers) => {
56432
+ if (ctx.artifact.kind !== kind) {
56433
+ return handlers.next(ctx);
56434
+ }
56435
+ return handler(ctx, handlers);
56436
+ };
56437
+ };
56438
+ const exitWrapper = (handler) => {
56439
+ return !handler ? void 0 : (ctx, handlers) => {
56440
+ if (ctx.artifact.kind !== kind) {
56441
+ return handlers.resolve(ctx);
56442
+ }
56443
+ return handler(ctx, handlers);
56444
+ };
56445
+ };
56446
+ return {
56447
+ start: enterWrapper(sourceHandlers.start),
56448
+ network: enterWrapper(sourceHandlers.network),
56449
+ afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
56450
+ end: exitWrapper(sourceHandlers.end),
56451
+ catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
56452
+ cleanup: (...args) => sourceHandlers.cleanup?.(...args)
56453
+ };
56454
+ };
56455
+ };
56456
+
56457
+ // src/runtime/client/plugins/query.ts
56458
+ var query = documentPlugin(ArtifactKind.Query, function() {
56459
+ let subscriptionSpec = null;
56460
+ let lastVariables = null;
56461
+ let artifactName = "";
56462
+ return {
56463
+ start(ctx, { next }) {
56464
+ ctx.variables = {
56465
+ ...lastVariables,
56466
+ ...ctx.variables
56467
+ };
56468
+ next(ctx);
56469
+ },
56470
+ end(ctx, { resolve: resolve2, marshalVariables, variablesChanged }) {
56471
+ if (variablesChanged(ctx)) {
56472
+ artifactName = ctx.artifact.name;
56473
+ if (subscriptionSpec) {
56474
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
56475
+ }
56476
+ lastVariables = { ...marshalVariables(ctx) };
56477
+ subscriptionSpec = {
56478
+ rootType: ctx.artifact.rootType,
56479
+ selection: ctx.artifact.selection,
56480
+ variables: () => lastVariables,
56481
+ set: (newValue) => {
56482
+ resolve2(ctx, {
56483
+ data: newValue,
56484
+ errors: null,
56485
+ fetching: false,
56486
+ partial: false,
56487
+ stale: false,
56488
+ source: DataSource.Cache,
56489
+ variables: ctx.variables ?? {}
56490
+ });
56491
+ }
56492
+ };
56493
+ cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
56494
+ }
56495
+ resolve2(ctx);
56496
+ },
56497
+ cleanup() {
56498
+ if (subscriptionSpec) {
56499
+ cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
56500
+ lastVariables = null;
56501
+ }
56502
+ }
56503
+ };
56504
+ });
56505
+
56506
+ // src/runtime/client/plugins/mutation.ts
56507
+ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
56508
+ return {
56509
+ async start(ctx, { next, marshalVariables }) {
56510
+ const layer = cache_default._internal_unstable.storage.createLayer(true);
56511
+ const optimisticResponse = ctx.stuff.optimisticResponse;
56512
+ let toNotify = [];
56513
+ if (optimisticResponse) {
56514
+ toNotify = cache_default.write({
56515
+ selection: ctx.artifact.selection,
56516
+ data: await marshalSelection({
56517
+ selection: ctx.artifact.selection,
56518
+ data: optimisticResponse
56519
+ }),
56520
+ variables: marshalVariables(ctx),
56521
+ layer: layer.id
56522
+ });
56523
+ }
56524
+ ctx.cacheParams = {
56525
+ ...ctx.cacheParams,
56526
+ layer,
56527
+ notifySubscribers: toNotify,
56528
+ forceNotify: true
56529
+ };
56530
+ next(ctx);
56531
+ },
56532
+ afterNetwork(ctx, { resolve: resolve2 }) {
56533
+ ctx.cacheParams?.layer?.clear();
56534
+ resolve2(ctx);
56535
+ },
56536
+ end(ctx, { resolve: resolve2, value }) {
56537
+ const hasErrors = value.errors && value.errors.length > 0;
56538
+ if (hasErrors) {
56539
+ ctx.cacheParams?.layer?.clear();
56540
+ }
56541
+ if (ctx.cacheParams?.layer) {
56542
+ cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
56543
+ }
56544
+ resolve2(ctx);
56545
+ },
56546
+ catch(ctx, { error }) {
56547
+ if (ctx.cacheParams?.layer) {
56548
+ const { layer } = ctx.cacheParams;
56549
+ layer.clear();
56550
+ cache_default._internal_unstable.storage.resolveLayer(layer.id);
56551
+ }
56552
+ throw error;
56553
+ }
56554
+ };
56555
+ });
56556
+
54413
56557
  // src/lib/types.ts
54414
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
54415
- LogLevel2["Full"] = "full";
54416
- LogLevel2["Summary"] = "summary";
54417
- LogLevel2["ShortSummary"] = "short-summary";
54418
- LogLevel2["Quiet"] = "quiet";
54419
- return LogLevel2;
54420
- })(LogLevel || {});
56558
+ var LogLevel = {
56559
+ Full: "full",
56560
+ Summary: "summary",
56561
+ ShortSummary: "short-summary",
56562
+ Quiet: "quiet"
56563
+ };
54421
56564
 
54422
56565
  // src/lib/config.ts
54423
56566
  var import_meta = {};
@@ -54469,7 +56612,7 @@ var Config = class {
54469
56612
  scalars,
54470
56613
  cacheBufferSize,
54471
56614
  definitionsPath,
54472
- defaultCachePolicy = "CacheOrNetwork" /* CacheOrNetwork */,
56615
+ defaultCachePolicy = CachePolicy.CacheOrNetwork,
54473
56616
  defaultPartial = false,
54474
56617
  defaultListPosition = "append",
54475
56618
  defaultListTarget = null,
@@ -54491,7 +56634,7 @@ var Config = class {
54491
56634
  Object.values(LogLevel)
54492
56635
  )}`
54493
56636
  );
54494
- logLevel = "summary" /* Summary */;
56637
+ logLevel = LogLevel.Summary;
54495
56638
  }
54496
56639
  this.schemaPath = schemaPath;
54497
56640
  this.filepath = filepath;
@@ -54507,7 +56650,7 @@ var Config = class {
54507
56650
  this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
54508
56651
  this.defaultListTarget = defaultListTarget;
54509
56652
  this.definitionsFolder = definitionsPath;
54510
- this.logLevel = (logLevel || "summary" /* Summary */).toLowerCase();
56653
+ this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
54511
56654
  this.defaultFragmentMasking = defaultFragmentMasking;
54512
56655
  this.routesDir = join(this.projectRoot, "src", "routes");
54513
56656
  this.schemaPollInterval = watchSchema?.interval ?? 2e3;
@@ -54848,8 +56991,10 @@ var Config = class {
54848
56991
  return node.name.value === "CachePolicy";
54849
56992
  }
54850
56993
  isInternalDirective(name) {
54851
- const internalDirectives = this.#newSchemaInstance?.getDirectives().map((directive) => directive.name) ?? [];
54852
- return internalDirectives.includes(name) || this.isDeleteDirective(name);
56994
+ const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
56995
+ return list.concat(directive.name);
56996
+ }, []) ?? [];
56997
+ return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
54853
56998
  }
54854
56999
  isListFragment(name) {
54855
57000
  return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
@@ -54922,6 +57067,8 @@ function findModule(pkg = "houdini", currentLocation) {
54922
57067
  }
54923
57068
  return locationFound;
54924
57069
  }
57070
+ var emptySchema = graphql.buildSchema("type Query { hello: String }");
57071
+ var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
54925
57072
 
54926
57073
  // src/lib/graphql.ts
54927
57074
  var graphql2 = __toESM(require_graphql2(), 1);
@@ -54938,7 +57085,7 @@ function getRootType(type) {
54938
57085
  function hashDocument({
54939
57086
  document
54940
57087
  }) {
54941
- const docString = typeof document === "string" ? document : document.artifact?.raw;
57088
+ const docString = typeof document === "string" ? document : document.originalString;
54942
57089
  return import_node_crypto.default.createHash("sha256").update(docString ?? "").digest("hex");
54943
57090
  }
54944
57091
  function parentTypeFromAncestors(schema, filepath, ancestors) {
@@ -55276,7 +57423,13 @@ var FieldCollection = class {
55276
57423
  if (fragment.selection.size === 0) {
55277
57424
  return [];
55278
57425
  }
55279
- fragment.astNode.selectionSet.selections = fragment.selection.toSelectionSet();
57426
+ fragment.astNode = {
57427
+ ...fragment.astNode,
57428
+ selectionSet: {
57429
+ ...fragment.astNode.selectionSet,
57430
+ selections: fragment.selection.toSelectionSet()
57431
+ }
57432
+ };
55280
57433
  return [fragment.astNode];
55281
57434
  }).concat(
55282
57435
  Object.values(this.fields).map((field) => {
@@ -55500,7 +57653,7 @@ async function fragmentVariables(config2, documents) {
55500
57653
  };
55501
57654
  documents.push({
55502
57655
  name: "generated::fragmentVariables",
55503
- kind: "HoudiniFragment" /* Fragment */,
57656
+ kind: ArtifactKind.Fragment,
55504
57657
  document: doc,
55505
57658
  originalParsed: doc,
55506
57659
  generateStore: false,
@@ -55654,26 +57807,45 @@ function fragmentArguments(config2, filepath, definition) {
55654
57807
  if (!typeArg || typeArg.kind !== "StringValue") {
55655
57808
  return [];
55656
57809
  }
55657
- let type = typeArg.value;
55658
- let name = arg.name.value;
55659
- let required = false;
57810
+ let type = parseArgumentTypeString(typeArg.value);
55660
57811
  let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
55661
- if (type[type.length - 1] === "!") {
55662
- type = type.slice(0, -1);
55663
- required = true;
55664
- defaultValue = null;
55665
- }
55666
57812
  return [
55667
57813
  {
55668
- name,
57814
+ name: arg.name.value,
55669
57815
  type,
55670
- required,
57816
+ required: type.kind === "NonNullType",
55671
57817
  defaultValue
55672
57818
  }
55673
57819
  ];
55674
57820
  }) || []
55675
57821
  );
55676
57822
  }
57823
+ function parseArgumentTypeString(input) {
57824
+ if (input[input.length - 1] === "!") {
57825
+ const inner = parseArgumentTypeString(input.substring(0, input.length - 1));
57826
+ if (inner.kind === "NonNullType") {
57827
+ throw new Error("invalid type" + input);
57828
+ }
57829
+ return {
57830
+ kind: "NonNullType",
57831
+ type: inner
57832
+ };
57833
+ }
57834
+ if (input[input.length - 1] === "]") {
57835
+ const inner = parseArgumentTypeString(input.substring(1, input.length - 1));
57836
+ return {
57837
+ kind: "ListType",
57838
+ type: inner
57839
+ };
57840
+ }
57841
+ return {
57842
+ kind: "NamedType",
57843
+ name: {
57844
+ kind: "Name",
57845
+ value: input
57846
+ }
57847
+ };
57848
+ }
55677
57849
  function collectDefaultArgumentValues(config2, filepath, definition) {
55678
57850
  let result = {};
55679
57851
  for (const { name, required, defaultValue } of fragmentArguments(
@@ -55736,19 +57908,9 @@ function fragmentArgumentsDefinitions(config2, filepath, definition) {
55736
57908
  return [];
55737
57909
  }
55738
57910
  return args.map((arg) => {
55739
- const innerType = {
55740
- kind: "NamedType",
55741
- name: {
55742
- kind: "Name",
55743
- value: arg.type
55744
- }
55745
- };
55746
57911
  return {
55747
57912
  kind: "VariableDefinition",
55748
- type: arg.required ? innerType : {
55749
- kind: "NonNullType",
55750
- type: innerType
55751
- },
57913
+ type: arg.type,
55752
57914
  variable: {
55753
57915
  kind: "Variable",
55754
57916
  name: {
@@ -56421,7 +58583,7 @@ async function paginate(config2, documents) {
56421
58583
  ]
56422
58584
  };
56423
58585
  newDocs.push({
56424
- kind: "HoudiniQuery" /* Query */,
58586
+ kind: ArtifactKind.Query,
56425
58587
  filename: doc.filename,
56426
58588
  name: refetchQueryName,
56427
58589
  document: queryDoc,
@@ -56841,7 +59003,7 @@ async function addListFragments(config2, documents) {
56841
59003
  config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql9.print).join("\n\n");
56842
59004
  documents.push({
56843
59005
  name: "generated::lists",
56844
- kind: "HoudiniFragment" /* Fragment */,
59006
+ kind: ArtifactKind.Fragment,
56845
59007
  generateArtifact: false,
56846
59008
  generateStore: false,
56847
59009
  document: generatedDoc,
@@ -57108,7 +59270,7 @@ function selection({
57108
59270
  (directive) => directive.name.value === config2.paginateDirective
57109
59271
  );
57110
59272
  if (paginated && document.refetch && document.refetch.method === "offset") {
57111
- fieldObj.updates = ["append" /* append */];
59273
+ fieldObj.updates = [RefetchUpdateMode.append];
57112
59274
  }
57113
59275
  let continueConnection = inConnection;
57114
59276
  if ([
@@ -57118,7 +59280,7 @@ function selection({
57118
59280
  "hasNextPage",
57119
59281
  "hasPreviousPage"
57120
59282
  ].includes(attributeName) && inConnection && document.refetch) {
57121
- fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
59283
+ fieldObj.updates = [RefetchUpdateMode.append, RefetchUpdateMode.prepend];
57122
59284
  }
57123
59285
  if (attributeName === "node" && inConnection) {
57124
59286
  continueConnection = false;
@@ -57297,7 +59459,7 @@ function artifactGenerator(stats) {
57297
59459
  );
57298
59460
  let rootType = "";
57299
59461
  let selectionSet;
57300
- if (docKind !== "HoudiniFragment" /* Fragment */) {
59462
+ if (docKind !== ArtifactKind.Fragment) {
57301
59463
  const operation = operations[0];
57302
59464
  if (operation.operation === "query") {
57303
59465
  rootType = config2.schema.getQueryType()?.name;
@@ -57330,7 +59492,7 @@ function artifactGenerator(stats) {
57330
59492
  let directive = fragments[0]?.directives?.find(
57331
59493
  (directive2) => directive2.name.value === config2.argumentsDirective
57332
59494
  );
57333
- if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
59495
+ if (docKind === ArtifactKind.Fragment && directive) {
57334
59496
  inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
57335
59497
  }
57336
59498
  const mergedSelection = flattenSelections({
@@ -57371,22 +59533,12 @@ function artifactGenerator(stats) {
57371
59533
  document: doc
57372
59534
  })
57373
59535
  };
57374
- const plugin_data = config2.plugins.reduce(
57375
- (prev, plugin2) => {
57376
- if (!plugin2.artifactData) {
57377
- return prev;
57378
- }
57379
- const result = { ...prev };
57380
- const dataToAdd = plugin2.artifactData({ config: config2, document: doc }) ?? {};
57381
- if (Object.keys(dataToAdd).length > 0) {
57382
- result[plugin2.name] = dataToAdd;
57383
- }
57384
- return result;
57385
- },
57386
- {}
57387
- );
57388
- if (Object.keys(plugin_data).length > 0) {
57389
- artifact.plugin_data = plugin_data;
59536
+ artifact.pluginData = {};
59537
+ for (const plugin2 of config2.plugins) {
59538
+ if (!plugin2.artifactData) {
59539
+ continue;
59540
+ }
59541
+ artifact.pluginData[plugin2.name] = plugin2.artifactData({ config: config2, document: doc }) ?? {};
57390
59542
  }
57391
59543
  if (inputs && inputs.length > 0) {
57392
59544
  artifact.input = inputObject(config2, inputs);
@@ -57447,7 +59599,7 @@ function artifactGenerator(stats) {
57447
59599
  return;
57448
59600
  }
57449
59601
  const match = existingArtifact && existingArtifact.match(/"HoudiniHash=(\w+)"/);
57450
- if (match && match[1] !== hash({ config: config2, document: doc })) {
59602
+ if (match && match[1] !== artifact.hash) {
57451
59603
  stats.changed.push(artifact.name);
57452
59604
  }
57453
59605
  stats.total.push(artifact.name);
@@ -57560,6 +59712,30 @@ async function generatePluginIndex({
57560
59712
  ]);
57561
59713
  }
57562
59714
 
59715
+ // src/codegen/generators/runtime/runtimeConfig.ts
59716
+ async function injectConfig({
59717
+ config: config2,
59718
+ content,
59719
+ importStatement,
59720
+ exportStatement
59721
+ }) {
59722
+ const extraConfigs = config2.plugins.reduce((acc, plugin2) => {
59723
+ if (!plugin2.config) {
59724
+ return acc;
59725
+ }
59726
+ return [...acc, plugin2.config];
59727
+ }, []);
59728
+ return extraConfigs.length > 0 ? `
59729
+ ${extraConfigs.map((plugin2, i) => importStatement(plugin2, `plugin${i}`))}
59730
+
59731
+ const plugins = [
59732
+ ${extraConfigs.map((_, i) => `plugin${i}`).join(",\n")}
59733
+ ]
59734
+
59735
+ ${exportStatement("plugins")}
59736
+ ` : content;
59737
+ }
59738
+
57563
59739
  // src/codegen/generators/runtime/index.ts
57564
59740
  async function runtimeGenerator(config2, docs) {
57565
59741
  const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
@@ -57570,6 +59746,9 @@ async function runtimeGenerator(config2, docs) {
57570
59746
  [path_exports.join(config2.runtimeSource, "lib", "constants.js")]: (content) => {
57571
59747
  return content.replace("SITE_URL", siteURL);
57572
59748
  },
59749
+ [path_exports.join(config2.runtimeSource, "imports", "pluginConfig.js")]: (content) => {
59750
+ return injectConfig({ config: config2, importStatement, exportStatement, content });
59751
+ },
57573
59752
  [path_exports.join(config2.runtimeSource, "imports", "config.js")]: (content) => {
57574
59753
  const configFilePath = path_exports.join(config2.runtimeDirectory, "imports", "config.js");
57575
59754
  const relativePath = path_exports.relative(path_exports.dirname(configFilePath), config2.filepath);
@@ -58627,7 +60806,7 @@ function listDefinitions(config2, body, docs) {
58627
60806
  function queryDefinitions(config2, body, docs, returnType) {
58628
60807
  return AST12.tsTupleType(
58629
60808
  docs.reduce((prev, doc) => {
58630
- if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
60809
+ if (doc.kind !== ArtifactKind.Query || !doc.generateStore) {
58631
60810
  return prev;
58632
60811
  }
58633
60812
  const definition = doc.document.definitions.find(
@@ -58658,7 +60837,7 @@ function queryDefinitions(config2, body, docs, returnType) {
58658
60837
  }
58659
60838
  function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
58660
60839
  return docs.reduce((prev, doc) => {
58661
- if (doc.kind !== "HoudiniFragment" /* Fragment */) {
60840
+ if (doc.kind !== ArtifactKind.Fragment) {
58662
60841
  return prev;
58663
60842
  }
58664
60843
  const definition = doc.document.definitions.find(
@@ -58797,13 +60976,19 @@ async function definitionsGenerator(config2) {
58797
60976
  })
58798
60977
  )
58799
60978
  ).code;
58800
- const typeDefinitions2 = enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map(
58801
- (definition) => `
58802
- export const ${definition.name.value} = {
58803
- ${definition.values?.map((value) => ` ${value.name.value}: "${value.name.value}"`).join(",\n")}
58804
- } as const
58805
- `
58806
- ).join("");
60979
+ const typeDefinitions2 = `
60980
+ type ValuesOf<T> = T[keyof T]
60981
+ ` + enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map((definition) => {
60982
+ const name = definition.name.value;
60983
+ const values = definition.values;
60984
+ return `
60985
+ export declare const ${name}: {
60986
+ ${values?.map((value) => ` readonly ${value.name.value}: "${value.name.value}";`).join("\n")}
60987
+ }
60988
+
60989
+ export type ${name}$options = ValuesOf<typeof ${name}>
60990
+ `;
60991
+ }).join("");
58807
60992
  const definitionsIndex = `
58808
60993
  export * from './enums.js'
58809
60994
  `;
@@ -58869,10 +61054,10 @@ var graphql20 = __toESM(require_graphql2(), 1);
58869
61054
  async function graphqlExtensions(config2, documents) {
58870
61055
  let internalSchema = `
58871
61056
  enum CachePolicy {
58872
- ${"CacheAndNetwork" /* CacheAndNetwork */}
58873
- ${"CacheOnly" /* CacheOnly */}
58874
- ${"CacheOrNetwork" /* CacheOrNetwork */}
58875
- ${"NetworkOnly" /* NetworkOnly */}
61057
+ ${CachePolicy.CacheAndNetwork}
61058
+ ${CachePolicy.CacheOnly}
61059
+ ${CachePolicy.CacheOrNetwork}
61060
+ ${CachePolicy.NetworkOnly}
58876
61061
  }
58877
61062
 
58878
61063
  """
@@ -59062,7 +61247,7 @@ async function typeCheck(config2, docs) {
59062
61247
  const lists = [];
59063
61248
  const listTypes = [];
59064
61249
  const fragments = {};
59065
- for (const { document: parsed, filename } of docs) {
61250
+ for (const { document: parsed, originalString, filename } of docs) {
59066
61251
  graphql23.visit(parsed, {
59067
61252
  [graphql23.Kind.FRAGMENT_DEFINITION](definition) {
59068
61253
  fragments[definition.name.value] = definition;
@@ -59260,7 +61445,7 @@ async function typeCheck(config2, docs) {
59260
61445
  paginateArgs(config2, filepath),
59261
61446
  noUnusedFragmentArguments(config2)
59262
61447
  );
59263
- for (const { filename, document: parsed } of docs) {
61448
+ for (const { filename, document: parsed, originalString } of docs) {
59264
61449
  for (const error of graphql23.validate(config2.schema, parsed, rules(filename))) {
59265
61450
  errors.push(
59266
61451
  new HoudiniError({
@@ -59496,24 +61681,15 @@ function validateFragmentArguments(config2, filepath, fragments) {
59496
61681
  )
59497
61682
  );
59498
61683
  } else {
59499
- const zipped = appliedArgumentNames.map(
59500
- (name) => [
59501
- appliedArguments[name],
59502
- fragmentArguments2[fragmentName].find((arg) => arg.name === name).type
59503
- ]
59504
- );
61684
+ const zipped = appliedArgumentNames.map((name) => [
61685
+ appliedArguments[name],
61686
+ fragmentArguments2[fragmentName].find((arg) => arg.name === name).type
61687
+ ]);
59505
61688
  for (const [applied, target] of zipped) {
59506
- if (applied.value.kind === graphql23.Kind.VARIABLE || applied.value.kind === graphql23.Kind.LIST || applied.value.kind === graphql23.Kind.OBJECT) {
59507
- continue;
59508
- }
59509
- const appliedType = applied.value.kind.substring(
59510
- 0,
59511
- applied.value.kind.length - "Value".length
59512
- );
59513
- if (appliedType !== target) {
61689
+ if (!valueIsType(config2, applied.value, target)) {
59514
61690
  ctx.reportError(
59515
61691
  new graphql23.GraphQLError(
59516
- `Invalid argument type. Expected ${target}, found ${appliedType}`
61692
+ `Invalid argument type. Expected ${target}, found ${applied.value.kind}`
59517
61693
  )
59518
61694
  );
59519
61695
  }
@@ -59523,6 +61699,47 @@ function validateFragmentArguments(config2, filepath, fragments) {
59523
61699
  };
59524
61700
  };
59525
61701
  }
61702
+ function valueIsType(config2, value, targetType) {
61703
+ if (value.kind === "NullValue") {
61704
+ return targetType.kind !== "NonNullType";
61705
+ }
61706
+ if (targetType.kind === "NonNullType") {
61707
+ targetType = targetType.type;
61708
+ }
61709
+ if (value.kind === "ListValue") {
61710
+ if (targetType.kind !== "ListType") {
61711
+ return false;
61712
+ }
61713
+ const listType = targetType.type;
61714
+ return value.values.every((value2) => valueIsType(config2, value2, listType));
61715
+ }
61716
+ if (value.kind === "BooleanValue") {
61717
+ return targetType.kind === "NamedType" && targetType.name.value === "Boolean";
61718
+ }
61719
+ if (value.kind === "StringValue") {
61720
+ return targetType.kind === "NamedType" && targetType.name.value === "String";
61721
+ }
61722
+ if (value.kind === "IntValue") {
61723
+ return targetType.kind === "NamedType" && targetType.name.value === "Int";
61724
+ }
61725
+ if (value.kind === "FloatValue") {
61726
+ return targetType.kind === "NamedType" && targetType.name.value === "Float";
61727
+ }
61728
+ if (value.kind === "ObjectValue" && targetType.kind === "NamedType") {
61729
+ return true;
61730
+ }
61731
+ if (value.kind === "EnumValue" && targetType.kind === "NamedType") {
61732
+ const enumType = config2.schema.getType(targetType.name.value);
61733
+ if (!graphql23.isEnumType(enumType)) {
61734
+ return false;
61735
+ }
61736
+ return enumType.getValues().some((enumValue) => enumValue.value === value.value);
61737
+ }
61738
+ if (value.kind === "Variable") {
61739
+ return true;
61740
+ }
61741
+ return false;
61742
+ }
59526
61743
  function paginateArgs(config2, filepath) {
59527
61744
  return function(ctx) {
59528
61745
  let alreadyPaginated = false;
@@ -59788,7 +62005,7 @@ function getAndVerifyNodeInterface(config2) {
59788
62005
  var nbInvalidNodeFieldMessageDisplayed = 0;
59789
62006
  function displayInvalidNodeFieldMessage(logLevel) {
59790
62007
  if (nbInvalidNodeFieldMessageDisplayed === 0) {
59791
- if (logLevel === "full" /* Full */) {
62008
+ if (logLevel === LogLevel.Full) {
59792
62009
  console.warn(invalidNodeFieldMessage);
59793
62010
  } else {
59794
62011
  console.warn(invalidNodeFieldMessageLight);
@@ -59952,7 +62169,7 @@ async function runPipeline2(config2, docs) {
59952
62169
  }
59953
62170
  const unchanged = artifactStats.total.length - artifactStats.changed.length - artifactStats.new.length - artifactStats.deleted.length;
59954
62171
  const printMessage = !config2.pluginMode || unchanged !== artifactStats.total.length;
59955
- if (!printMessage || config2.logLevel === "quiet" /* Quiet */) {
62172
+ if (!printMessage || config2.logLevel === LogLevel.Quiet) {
59956
62173
  if (error) {
59957
62174
  throw error;
59958
62175
  }
@@ -59966,14 +62183,14 @@ async function runPipeline2(config2, docs) {
59966
62183
  }
59967
62184
  if (artifactStats.total.length === 0) {
59968
62185
  console.log(`\u{1F4A1} No operation found. If that's unexpected, please check your config.`);
59969
- } else if (["summary" /* Summary */, "short-summary" /* ShortSummary */].includes(config2.logLevel)) {
62186
+ } else if (config2.logLevel == LogLevel.Summary || config2.logLevel == LogLevel.ShortSummary) {
59970
62187
  if (unchanged > 0 && printMessage && !config2.pluginMode) {
59971
62188
  console.log(`\u{1F4C3} Unchanged: ${unchanged}`);
59972
62189
  }
59973
62190
  logStyled("CREATED", artifactStats.new, config2.logLevel, config2.pluginMode);
59974
62191
  logStyled("UPDATED", artifactStats.changed, config2.logLevel, config2.pluginMode);
59975
62192
  logStyled("DELETED", artifactStats.deleted, config2.logLevel, config2.pluginMode);
59976
- } else if (config2.logLevel === "full" /* Full */) {
62193
+ } else if (config2.logLevel === LogLevel.Full) {
59977
62194
  for (const artifact of artifactStats.total) {
59978
62195
  let emoji = "\u{1F4C3}";
59979
62196
  if (artifactStats.changed.includes(artifact)) {
@@ -60017,7 +62234,7 @@ function logStyled(kind, stat2, logLevel, plugin2) {
60017
62234
  }
60018
62235
  }
60019
62236
  console.log(msg.join(""));
60020
- if (!plugin2 && logLevel === "summary" /* Summary */) {
62237
+ if (!plugin2 && logLevel === LogLevel.Summary) {
60021
62238
  for (const artifact of stat2.slice(0, nbToDisplay)) {
60022
62239
  console.log(` ${artifact}`);
60023
62240
  }
@@ -60093,6 +62310,7 @@ function testConfigFile({ plugins, ...config2 } = {}) {
60093
62310
  entitiesByCursor(first: Int, after: String, last: Int, before: String): EntityConnection!
60094
62311
  node(id: ID!): Node
60095
62312
  customIdList: [CustomIdType]!
62313
+ nodes(ids: [ID!]!): [Node!]!
60096
62314
  }
60097
62315
 
60098
62316
  type PageInfo {
@@ -60296,18 +62514,18 @@ function pipelineTest(config2, documents, shouldPass, testBody) {
60296
62514
  }
60297
62515
  };
60298
62516
  }
60299
- function mockCollectedDoc(query) {
60300
- const parsed = graphql25.parse(query);
62517
+ function mockCollectedDoc(query2) {
62518
+ const parsed = graphql25.parse(query2);
60301
62519
  const name = parsed.definitions[0].name.value;
60302
62520
  const operations = parsed.definitions;
60303
- let kind = "HoudiniFragment" /* Fragment */;
62521
+ let kind = ArtifactKind.Fragment;
60304
62522
  if (operations.length === 1) {
60305
62523
  if (operations[0].kind === "OperationDefinition" && operations[0].operation === "query") {
60306
- kind = "HoudiniQuery" /* Query */;
62524
+ kind = ArtifactKind.Query;
60307
62525
  } else if (operations[0].kind === "OperationDefinition" && operations[0].operation === "mutation") {
60308
- kind = "HoudiniMutation" /* Mutation */;
62526
+ kind = ArtifactKind.Mutation;
60309
62527
  } else if (operations[0].kind === "OperationDefinition" && operations[0].operation === "subscription") {
60310
- kind = "HoudiniSubscription" /* Subscription */;
62528
+ kind = ArtifactKind.Subscription;
60311
62529
  }
60312
62530
  }
60313
62531
  return {
@@ -60318,7 +62536,7 @@ function mockCollectedDoc(query) {
60318
62536
  filename: `${name}.ts`,
60319
62537
  generateArtifact: true,
60320
62538
  generateStore: true,
60321
- originalString: query,
62539
+ originalString: query2,
60322
62540
  artifact: null
60323
62541
  };
60324
62542
  }