houdini 1.0.0-next.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +2325 -121
  3. package/build/cmd-esm/index.js +2325 -121
  4. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  5. package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
  6. package/build/codegen/generators/typescript/types.d.ts +0 -1
  7. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  8. package/build/codegen-cjs/index.js +2919 -689
  9. package/build/codegen-esm/index.js +2919 -689
  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/index.d.ts +1 -1
  17. package/build/runtime/client/plugins/cache.d.ts +1 -1
  18. package/build/runtime/client/plugins/fetch.d.ts +1 -1
  19. package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
  20. package/build/runtime/client/plugins/mutation.d.ts +1 -1
  21. package/build/runtime/client/plugins/query.d.ts +1 -1
  22. package/build/runtime/client/plugins/subscription.d.ts +1 -1
  23. package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
  24. package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
  25. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  26. package/build/runtime/lib/config.d.ts +2 -2
  27. package/build/runtime/lib/scalars.d.ts +1 -1
  28. package/build/runtime/lib/types.d.ts +42 -42
  29. package/build/runtime-cjs/cache/storage.d.ts +18 -15
  30. package/build/runtime-cjs/cache/storage.js +9 -11
  31. package/build/runtime-cjs/client/documentStore.d.ts +15 -13
  32. package/build/runtime-cjs/client/documentStore.js +11 -8
  33. package/build/runtime-cjs/client/index.d.ts +1 -1
  34. package/build/runtime-cjs/client/index.js +16 -13
  35. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  36. package/build/runtime-cjs/client/plugins/cache.js +6 -6
  37. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  38. package/build/runtime-cjs/client/plugins/fetch.js +9 -9
  39. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
  40. package/build/runtime-cjs/client/plugins/fetchParams.js +3 -3
  41. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
  42. package/build/runtime-cjs/client/plugins/mutation.js +3 -3
  43. package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
  44. package/build/runtime-cjs/client/plugins/query.js +4 -4
  45. package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -1
  46. package/build/runtime-cjs/client/plugins/subscription.js +5 -5
  47. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
  48. package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
  49. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
  50. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  51. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  52. package/build/runtime-cjs/lib/config.d.ts +2 -2
  53. package/build/runtime-cjs/lib/config.js +11 -1
  54. package/build/runtime-cjs/lib/scalars.d.ts +1 -1
  55. package/build/runtime-cjs/lib/scalars.js +13 -2
  56. package/build/runtime-cjs/lib/types.d.ts +42 -42
  57. package/build/runtime-cjs/lib/types.js +26 -30
  58. package/build/runtime-esm/cache/storage.d.ts +18 -15
  59. package/build/runtime-esm/cache/storage.js +9 -11
  60. package/build/runtime-esm/client/documentStore.d.ts +15 -13
  61. package/build/runtime-esm/client/documentStore.js +12 -9
  62. package/build/runtime-esm/client/index.d.ts +1 -1
  63. package/build/runtime-esm/client/index.js +13 -10
  64. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  65. package/build/runtime-esm/client/plugins/cache.js +5 -5
  66. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  67. package/build/runtime-esm/client/plugins/fetch.js +8 -8
  68. package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
  69. package/build/runtime-esm/client/plugins/fetchParams.js +2 -2
  70. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
  71. package/build/runtime-esm/client/plugins/mutation.js +2 -2
  72. package/build/runtime-esm/client/plugins/query.d.ts +1 -1
  73. package/build/runtime-esm/client/plugins/query.js +3 -3
  74. package/build/runtime-esm/client/plugins/subscription.d.ts +1 -1
  75. package/build/runtime-esm/client/plugins/subscription.js +4 -4
  76. package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
  77. package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
  78. package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
  79. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  80. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  81. package/build/runtime-esm/lib/config.d.ts +2 -2
  82. package/build/runtime-esm/lib/config.js +11 -1
  83. package/build/runtime-esm/lib/scalars.d.ts +1 -1
  84. package/build/runtime-esm/lib/scalars.js +13 -2
  85. package/build/runtime-esm/lib/types.d.ts +42 -42
  86. package/build/runtime-esm/lib/types.js +26 -30
  87. package/build/test-cjs/index.js +2302 -98
  88. package/build/test-esm/index.js +2302 -98
  89. package/build/vite/houdini.d.ts +2 -0
  90. package/build/vite-cjs/index.js +2328 -122
  91. package/build/vite-esm/index.js +2328 -122
  92. 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 = isEnumType5;
3350
+ exports.isEnumType = isEnumType6;
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) || isEnumType5(type) || isInputObjectType2(type) || isListType3(type) || isNonNullType6(type);
3421
+ return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType6(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 isEnumType5(type) {
3465
+ function isEnumType6(type) {
3466
3466
  return (0, _instanceOf.default)(type, GraphQLEnumType);
3467
3467
  }
3468
3468
  function assertEnumType(type) {
3469
- if (!isEnumType5(type)) {
3469
+ if (!isEnumType6(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) || isEnumType5(type) || isInputObjectType2(type) || isWrappingType(type) && isInputType(type.ofType);
3502
+ return isScalarType7(type) || isEnumType6(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) || isEnumType5(type) || isWrappingType(type) && isOutputType(type.ofType);
3511
+ return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType6(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) || isEnumType5(type);
3520
+ return isScalarType7(type) || isEnumType6(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) || isEnumType5(type) || isInputObjectType2(type);
3608
+ return isScalarType7(type) || isObjectType3(type) || isInterfaceType6(type) || isUnionType7(type) || isEnumType6(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,
@@ -56421,7 +58574,7 @@ async function paginate(config2, documents) {
56421
58574
  ]
56422
58575
  };
56423
58576
  newDocs.push({
56424
- kind: "HoudiniQuery" /* Query */,
58577
+ kind: ArtifactKind.Query,
56425
58578
  filename: doc.filename,
56426
58579
  name: refetchQueryName,
56427
58580
  document: queryDoc,
@@ -56841,7 +58994,7 @@ async function addListFragments(config2, documents) {
56841
58994
  config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql9.print).join("\n\n");
56842
58995
  documents.push({
56843
58996
  name: "generated::lists",
56844
- kind: "HoudiniFragment" /* Fragment */,
58997
+ kind: ArtifactKind.Fragment,
56845
58998
  generateArtifact: false,
56846
58999
  generateStore: false,
56847
59000
  document: generatedDoc,
@@ -57108,7 +59261,7 @@ function selection({
57108
59261
  (directive) => directive.name.value === config2.paginateDirective
57109
59262
  );
57110
59263
  if (paginated && document.refetch && document.refetch.method === "offset") {
57111
- fieldObj.updates = ["append" /* append */];
59264
+ fieldObj.updates = [RefetchUpdateMode.append];
57112
59265
  }
57113
59266
  let continueConnection = inConnection;
57114
59267
  if ([
@@ -57118,7 +59271,7 @@ function selection({
57118
59271
  "hasNextPage",
57119
59272
  "hasPreviousPage"
57120
59273
  ].includes(attributeName) && inConnection && document.refetch) {
57121
- fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
59274
+ fieldObj.updates = [RefetchUpdateMode.append, RefetchUpdateMode.prepend];
57122
59275
  }
57123
59276
  if (attributeName === "node" && inConnection) {
57124
59277
  continueConnection = false;
@@ -57297,7 +59450,7 @@ function artifactGenerator(stats) {
57297
59450
  );
57298
59451
  let rootType = "";
57299
59452
  let selectionSet;
57300
- if (docKind !== "HoudiniFragment" /* Fragment */) {
59453
+ if (docKind !== ArtifactKind.Fragment) {
57301
59454
  const operation = operations[0];
57302
59455
  if (operation.operation === "query") {
57303
59456
  rootType = config2.schema.getQueryType()?.name;
@@ -57330,7 +59483,7 @@ function artifactGenerator(stats) {
57330
59483
  let directive = fragments[0]?.directives?.find(
57331
59484
  (directive2) => directive2.name.value === config2.argumentsDirective
57332
59485
  );
57333
- if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
59486
+ if (docKind === ArtifactKind.Fragment && directive) {
57334
59487
  inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
57335
59488
  }
57336
59489
  const mergedSelection = flattenSelections({
@@ -57371,22 +59524,12 @@ function artifactGenerator(stats) {
57371
59524
  document: doc
57372
59525
  })
57373
59526
  };
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;
59527
+ artifact.pluginData = {};
59528
+ for (const plugin2 of config2.plugins) {
59529
+ if (!plugin2.artifactData) {
59530
+ continue;
59531
+ }
59532
+ artifact.pluginData[plugin2.name] = plugin2.artifactData({ config: config2, document: doc }) ?? {};
57390
59533
  }
57391
59534
  if (inputs && inputs.length > 0) {
57392
59535
  artifact.input = inputObject(config2, inputs);
@@ -57447,7 +59590,7 @@ function artifactGenerator(stats) {
57447
59590
  return;
57448
59591
  }
57449
59592
  const match = existingArtifact && existingArtifact.match(/"HoudiniHash=(\w+)"/);
57450
- if (match && match[1] !== hash({ config: config2, document: doc })) {
59593
+ if (match && match[1] !== artifact.hash) {
57451
59594
  stats.changed.push(artifact.name);
57452
59595
  }
57453
59596
  stats.total.push(artifact.name);
@@ -57560,6 +59703,30 @@ async function generatePluginIndex({
57560
59703
  ]);
57561
59704
  }
57562
59705
 
59706
+ // src/codegen/generators/runtime/runtimeConfig.ts
59707
+ async function injectConfig({
59708
+ config: config2,
59709
+ content,
59710
+ importStatement,
59711
+ exportStatement
59712
+ }) {
59713
+ const extraConfigs = config2.plugins.reduce((acc, plugin2) => {
59714
+ if (!plugin2.config) {
59715
+ return acc;
59716
+ }
59717
+ return [...acc, plugin2.config];
59718
+ }, []);
59719
+ return extraConfigs.length > 0 ? `
59720
+ ${extraConfigs.map((plugin2, i) => importStatement(plugin2, `plugin${i}`))}
59721
+
59722
+ const plugins = [
59723
+ ${extraConfigs.map((_, i) => `plugin${i}`).join(",\n")}
59724
+ ]
59725
+
59726
+ ${exportStatement("plugins")}
59727
+ ` : content;
59728
+ }
59729
+
57563
59730
  // src/codegen/generators/runtime/index.ts
57564
59731
  async function runtimeGenerator(config2, docs) {
57565
59732
  const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
@@ -57570,6 +59737,9 @@ async function runtimeGenerator(config2, docs) {
57570
59737
  [path_exports.join(config2.runtimeSource, "lib", "constants.js")]: (content) => {
57571
59738
  return content.replace("SITE_URL", siteURL);
57572
59739
  },
59740
+ [path_exports.join(config2.runtimeSource, "imports", "pluginConfig.js")]: (content) => {
59741
+ return injectConfig({ config: config2, importStatement, exportStatement, content });
59742
+ },
57573
59743
  [path_exports.join(config2.runtimeSource, "imports", "config.js")]: (content) => {
57574
59744
  const configFilePath = path_exports.join(config2.runtimeDirectory, "imports", "config.js");
57575
59745
  const relativePath = path_exports.relative(path_exports.dirname(configFilePath), config2.filepath);
@@ -57678,11 +59848,13 @@ function scalarPropertyValue(config2, missingScalars, target) {
57678
59848
 
57679
59849
  // src/codegen/generators/typescript/typeReference.ts
57680
59850
  var AST8 = recast8.types.builders;
57681
- function tsTypeReference(config2, missingScalars, definition) {
59851
+ function tsTypeReference(config2, missingScalars, definition, body) {
57682
59852
  const { type, wrappers } = unwrapType(config2, definition.type);
57683
59853
  let result;
57684
59854
  if (graphql14.isScalarType(type)) {
57685
59855
  result = scalarPropertyValue(config2, missingScalars, type);
59856
+ } else if (graphql14.isEnumType(type)) {
59857
+ result = enumReference(config2, body, type.name);
57686
59858
  } else {
57687
59859
  result = AST8.tsTypeReference(AST8.identifier(type.name));
57688
59860
  }
@@ -57697,6 +59869,19 @@ function tsTypeReference(config2, missingScalars, definition) {
57697
59869
  }
57698
59870
  return result;
57699
59871
  }
59872
+ function enumReference(config2, body, name) {
59873
+ ensureImports({
59874
+ config: config2,
59875
+ body,
59876
+ import: ["ValueOf"],
59877
+ importKind: "type",
59878
+ sourceModule: "$houdini/runtime/lib/types"
59879
+ });
59880
+ return AST8.tsTypeReference(
59881
+ AST8.identifier("ValueOf"),
59882
+ AST8.tsTypeParameterInstantiation([AST8.tsTypeQuery(AST8.identifier(name))])
59883
+ );
59884
+ }
57700
59885
 
57701
59886
  // src/codegen/generators/typescript/addReferencedInputTypes.ts
57702
59887
  var AST9 = recast9.types.builders;
@@ -57728,7 +59913,7 @@ function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingS
57728
59913
  members.push(
57729
59914
  AST9.tsPropertySignature(
57730
59915
  AST9.identifier(field.name),
57731
- AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
59916
+ AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field, body)),
57732
59917
  graphql15.isNullableType(field.type)
57733
59918
  )
57734
59919
  );
@@ -57759,6 +59944,13 @@ function inlineType({
57759
59944
  if (graphql16.isScalarType(type)) {
57760
59945
  result = scalarPropertyValue(config2, missingScalars, type);
57761
59946
  } else if (graphql16.isEnumType(type)) {
59947
+ ensureImports({
59948
+ config: config2,
59949
+ body,
59950
+ importKind: "type",
59951
+ import: ["ValueOf"],
59952
+ sourceModule: "$houdini/runtime/lib/types"
59953
+ });
57762
59954
  if (!visitedTypes.has(type.name)) {
57763
59955
  ensureImports({
57764
59956
  config: config2,
@@ -57768,7 +59960,7 @@ function inlineType({
57768
59960
  });
57769
59961
  visitedTypes.add(type.name);
57770
59962
  }
57771
- result = AST10.tsTypeReference(AST10.identifier(type.name));
59963
+ result = enumReference(config2, body, type.name);
57772
59964
  } else if (selections) {
57773
59965
  const rootObj = type;
57774
59966
  const inlineFragments = {};
@@ -58201,7 +60393,7 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
58201
60393
  return AST11.tsPropertySignature(
58202
60394
  AST11.identifier(definition2.variable.name.value),
58203
60395
  AST11.tsTypeAnnotation(
58204
- tsTypeReference(config2, missingScalars, definition2)
60396
+ tsTypeReference(config2, missingScalars, definition2, body)
58205
60397
  ),
58206
60398
  definition2.type.kind !== "NonNullType"
58207
60399
  );
@@ -58268,7 +60460,12 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
58268
60460
  return AST11.tsPropertySignature(
58269
60461
  AST11.identifier(definition2.variable.name.value),
58270
60462
  AST11.tsTypeAnnotation(
58271
- tsTypeReference(config2, missingScalars, definition2)
60463
+ tsTypeReference(
60464
+ config2,
60465
+ missingScalars,
60466
+ definition2,
60467
+ body
60468
+ )
58272
60469
  ),
58273
60470
  definition2.type.kind !== "NonNullType"
58274
60471
  );
@@ -58361,7 +60558,7 @@ async function imperativeCacheTypef(config2, docs) {
58361
60558
  ),
58362
60559
  AST12.tsPropertySignature(
58363
60560
  AST12.identifier("lists"),
58364
- AST12.tsTypeAnnotation(listDefinitions(config2, docs))
60561
+ AST12.tsTypeAnnotation(listDefinitions(config2, body, docs))
58365
60562
  ),
58366
60563
  AST12.tsPropertySignature(
58367
60564
  AST12.identifier("queries"),
@@ -58470,7 +60667,7 @@ function typeDefinitions(config2, body, docs, returnType) {
58470
60667
  const prop = AST12.tsPropertySignature(
58471
60668
  AST12.identifier(arg.name),
58472
60669
  AST12.tsTypeAnnotation(
58473
- tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
60670
+ tsTypeReference(config2, /* @__PURE__ */ new Set(), arg, body)
58474
60671
  )
58475
60672
  );
58476
60673
  const unwrapped2 = unwrapType(config2, arg.type);
@@ -58520,7 +60717,7 @@ function typeDefinitions(config2, body, docs, returnType) {
58520
60717
  })
58521
60718
  );
58522
60719
  }
58523
- function listDefinitions(config2, docs) {
60720
+ function listDefinitions(config2, body, docs) {
58524
60721
  const lists = [];
58525
60722
  const visitedLists = /* @__PURE__ */ new Set();
58526
60723
  for (const doc of docs) {
@@ -58577,7 +60774,8 @@ function listDefinitions(config2, docs) {
58577
60774
  tsTypeReference(
58578
60775
  config2,
58579
60776
  /* @__PURE__ */ new Set(),
58580
- arg
60777
+ arg,
60778
+ body
58581
60779
  )
58582
60780
  )
58583
60781
  );
@@ -58599,7 +60797,7 @@ function listDefinitions(config2, docs) {
58599
60797
  function queryDefinitions(config2, body, docs, returnType) {
58600
60798
  return AST12.tsTupleType(
58601
60799
  docs.reduce((prev, doc) => {
58602
- if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
60800
+ if (doc.kind !== ArtifactKind.Query || !doc.generateStore) {
58603
60801
  return prev;
58604
60802
  }
58605
60803
  const definition = doc.document.definitions.find(
@@ -58630,7 +60828,7 @@ function queryDefinitions(config2, body, docs, returnType) {
58630
60828
  }
58631
60829
  function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
58632
60830
  return docs.reduce((prev, doc) => {
58633
- if (doc.kind !== "HoudiniFragment" /* Fragment */) {
60831
+ if (doc.kind !== ArtifactKind.Fragment) {
58634
60832
  return prev;
58635
60833
  }
58636
60834
  const definition = doc.document.definitions.find(
@@ -58769,13 +60967,19 @@ async function definitionsGenerator(config2) {
58769
60967
  })
58770
60968
  )
58771
60969
  ).code;
58772
- const typeDefinitions2 = enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map(
58773
- (definition) => `
58774
- export declare enum ${definition.name.value} {
58775
- ${definition.values?.map((value) => ` ${value.name.value} = "${value.name.value}"`).join(",\n")}
60970
+ const typeDefinitions2 = `
60971
+ type ValuesOf<T> = T[keyof T]
60972
+ ` + enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map((definition) => {
60973
+ const name = definition.name.value;
60974
+ const values = definition.values;
60975
+ return `
60976
+ export declare const ${name}: {
60977
+ ${values?.map((value) => ` readonly ${value.name.value}: "${value.name.value}";`).join("\n")}
58776
60978
  }
58777
- `
58778
- ).join("");
60979
+
60980
+ export type ${name}$options = ValuesOf<typeof ${name}>
60981
+ `;
60982
+ }).join("");
58779
60983
  const definitionsIndex = `
58780
60984
  export * from './enums.js'
58781
60985
  `;
@@ -58841,10 +61045,10 @@ var graphql20 = __toESM(require_graphql2(), 1);
58841
61045
  async function graphqlExtensions(config2, documents) {
58842
61046
  let internalSchema = `
58843
61047
  enum CachePolicy {
58844
- ${"CacheAndNetwork" /* CacheAndNetwork */}
58845
- ${"CacheOnly" /* CacheOnly */}
58846
- ${"CacheOrNetwork" /* CacheOrNetwork */}
58847
- ${"NetworkOnly" /* NetworkOnly */}
61048
+ ${CachePolicy.CacheAndNetwork}
61049
+ ${CachePolicy.CacheOnly}
61050
+ ${CachePolicy.CacheOrNetwork}
61051
+ ${CachePolicy.NetworkOnly}
58848
61052
  }
58849
61053
 
58850
61054
  """
@@ -59760,7 +61964,7 @@ function getAndVerifyNodeInterface(config2) {
59760
61964
  var nbInvalidNodeFieldMessageDisplayed = 0;
59761
61965
  function displayInvalidNodeFieldMessage(logLevel) {
59762
61966
  if (nbInvalidNodeFieldMessageDisplayed === 0) {
59763
- if (logLevel === "full" /* Full */) {
61967
+ if (logLevel === LogLevel.Full) {
59764
61968
  console.warn(invalidNodeFieldMessage);
59765
61969
  } else {
59766
61970
  console.warn(invalidNodeFieldMessageLight);
@@ -59924,7 +62128,7 @@ async function runPipeline2(config2, docs) {
59924
62128
  }
59925
62129
  const unchanged = artifactStats.total.length - artifactStats.changed.length - artifactStats.new.length - artifactStats.deleted.length;
59926
62130
  const printMessage = !config2.pluginMode || unchanged !== artifactStats.total.length;
59927
- if (!printMessage || config2.logLevel === "quiet" /* Quiet */) {
62131
+ if (!printMessage || config2.logLevel === LogLevel.Quiet) {
59928
62132
  if (error) {
59929
62133
  throw error;
59930
62134
  }
@@ -59938,14 +62142,14 @@ async function runPipeline2(config2, docs) {
59938
62142
  }
59939
62143
  if (artifactStats.total.length === 0) {
59940
62144
  console.log(`\u{1F4A1} No operation found. If that's unexpected, please check your config.`);
59941
- } else if (["summary" /* Summary */, "short-summary" /* ShortSummary */].includes(config2.logLevel)) {
62145
+ } else if (config2.logLevel == LogLevel.Summary || config2.logLevel == LogLevel.ShortSummary) {
59942
62146
  if (unchanged > 0 && printMessage && !config2.pluginMode) {
59943
62147
  console.log(`\u{1F4C3} Unchanged: ${unchanged}`);
59944
62148
  }
59945
62149
  logStyled("CREATED", artifactStats.new, config2.logLevel, config2.pluginMode);
59946
62150
  logStyled("UPDATED", artifactStats.changed, config2.logLevel, config2.pluginMode);
59947
62151
  logStyled("DELETED", artifactStats.deleted, config2.logLevel, config2.pluginMode);
59948
- } else if (config2.logLevel === "full" /* Full */) {
62152
+ } else if (config2.logLevel === LogLevel.Full) {
59949
62153
  for (const artifact of artifactStats.total) {
59950
62154
  let emoji = "\u{1F4C3}";
59951
62155
  if (artifactStats.changed.includes(artifact)) {
@@ -59989,7 +62193,7 @@ function logStyled(kind, stat2, logLevel, plugin2) {
59989
62193
  }
59990
62194
  }
59991
62195
  console.log(msg.join(""));
59992
- if (!plugin2 && logLevel === "summary" /* Summary */) {
62196
+ if (!plugin2 && logLevel === LogLevel.Summary) {
59993
62197
  for (const artifact of stat2.slice(0, nbToDisplay)) {
59994
62198
  console.log(` ${artifact}`);
59995
62199
  }
@@ -60268,18 +62472,18 @@ function pipelineTest(config2, documents, shouldPass, testBody) {
60268
62472
  }
60269
62473
  };
60270
62474
  }
60271
- function mockCollectedDoc(query) {
60272
- const parsed = graphql25.parse(query);
62475
+ function mockCollectedDoc(query2) {
62476
+ const parsed = graphql25.parse(query2);
60273
62477
  const name = parsed.definitions[0].name.value;
60274
62478
  const operations = parsed.definitions;
60275
- let kind = "HoudiniFragment" /* Fragment */;
62479
+ let kind = ArtifactKind.Fragment;
60276
62480
  if (operations.length === 1) {
60277
62481
  if (operations[0].kind === "OperationDefinition" && operations[0].operation === "query") {
60278
- kind = "HoudiniQuery" /* Query */;
62482
+ kind = ArtifactKind.Query;
60279
62483
  } else if (operations[0].kind === "OperationDefinition" && operations[0].operation === "mutation") {
60280
- kind = "HoudiniMutation" /* Mutation */;
62484
+ kind = ArtifactKind.Mutation;
60281
62485
  } else if (operations[0].kind === "OperationDefinition" && operations[0].operation === "subscription") {
60282
- kind = "HoudiniSubscription" /* Subscription */;
62486
+ kind = ArtifactKind.Subscription;
60283
62487
  }
60284
62488
  }
60285
62489
  return {
@@ -60290,7 +62494,7 @@ function mockCollectedDoc(query) {
60290
62494
  filename: `${name}.ts`,
60291
62495
  generateArtifact: true,
60292
62496
  generateStore: true,
60293
- originalString: query,
62497
+ originalString: query2,
60294
62498
  artifact: null
60295
62499
  };
60296
62500
  }