houdini 1.0.0-next.4 → 1.0.0-next.5

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 (78) hide show
  1. package/build/cmd-cjs/index.js +1217 -1021
  2. package/build/cmd-esm/index.js +1217 -1021
  3. package/build/codegen/generators/artifacts/utils.d.ts +0 -1
  4. package/build/codegen-cjs/index.js +810 -676
  5. package/build/codegen-esm/index.js +810 -676
  6. package/build/lib/config.d.ts +10 -90
  7. package/build/lib/deepMerge.d.ts +1 -0
  8. package/build/lib/graphql.d.ts +5 -2
  9. package/build/lib/index.d.ts +2 -0
  10. package/build/lib/pipeline.d.ts +1 -1
  11. package/build/lib/plugin.d.ts +2 -0
  12. package/build/lib/types.d.ts +250 -2
  13. package/build/lib-cjs/index.js +351 -162
  14. package/build/lib-esm/index.js +349 -162
  15. package/build/runtime/cache/cache.d.ts +20 -3
  16. package/build/runtime/cache/staleManager.d.ts +30 -0
  17. package/build/runtime/cache/subscription.d.ts +2 -1
  18. package/build/runtime/client/plugins/subscription.d.ts +1 -2
  19. package/build/runtime/lib/config.d.ts +4 -0
  20. package/build/runtime/lib/index.d.ts +1 -0
  21. package/build/runtime/lib/key.d.ts +6 -0
  22. package/build/runtime/lib/types.d.ts +2 -2
  23. package/build/runtime/public/cache.d.ts +8 -1
  24. package/build/runtime/public/record.d.ts +11 -1
  25. package/build/runtime/public/tests/test.d.ts +9 -10
  26. package/build/runtime-cjs/cache/cache.d.ts +20 -3
  27. package/build/runtime-cjs/cache/cache.js +65 -6
  28. package/build/runtime-cjs/cache/gc.js +9 -0
  29. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  30. package/build/runtime-cjs/cache/staleManager.js +95 -0
  31. package/build/runtime-cjs/cache/subscription.d.ts +2 -1
  32. package/build/runtime-cjs/cache/subscription.js +6 -3
  33. package/build/runtime-cjs/client/documentStore.js +1 -0
  34. package/build/runtime-cjs/client/plugins/cache.js +5 -3
  35. package/build/runtime-cjs/client/plugins/fetch.js +1 -0
  36. package/build/runtime-cjs/client/plugins/query.js +1 -0
  37. package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -2
  38. package/build/runtime-cjs/client/plugins/subscription.js +2 -0
  39. package/build/runtime-cjs/lib/config.d.ts +4 -0
  40. package/build/runtime-cjs/lib/index.d.ts +1 -0
  41. package/build/runtime-cjs/lib/index.js +1 -0
  42. package/build/runtime-cjs/lib/key.d.ts +6 -0
  43. package/build/runtime-cjs/lib/key.js +41 -0
  44. package/build/runtime-cjs/lib/types.d.ts +2 -2
  45. package/build/runtime-cjs/public/cache.d.ts +8 -1
  46. package/build/runtime-cjs/public/cache.js +3 -0
  47. package/build/runtime-cjs/public/record.d.ts +11 -1
  48. package/build/runtime-cjs/public/record.js +8 -1
  49. package/build/runtime-cjs/public/tests/test.d.ts +9 -10
  50. package/build/runtime-esm/cache/cache.d.ts +20 -3
  51. package/build/runtime-esm/cache/cache.js +66 -7
  52. package/build/runtime-esm/cache/gc.js +9 -0
  53. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  54. package/build/runtime-esm/cache/staleManager.js +71 -0
  55. package/build/runtime-esm/cache/subscription.d.ts +2 -1
  56. package/build/runtime-esm/cache/subscription.js +6 -3
  57. package/build/runtime-esm/client/documentStore.js +1 -0
  58. package/build/runtime-esm/client/plugins/cache.js +5 -3
  59. package/build/runtime-esm/client/plugins/fetch.js +1 -0
  60. package/build/runtime-esm/client/plugins/query.js +1 -0
  61. package/build/runtime-esm/client/plugins/subscription.d.ts +1 -2
  62. package/build/runtime-esm/client/plugins/subscription.js +2 -0
  63. package/build/runtime-esm/lib/config.d.ts +4 -0
  64. package/build/runtime-esm/lib/index.d.ts +1 -0
  65. package/build/runtime-esm/lib/index.js +1 -0
  66. package/build/runtime-esm/lib/key.d.ts +6 -0
  67. package/build/runtime-esm/lib/key.js +17 -0
  68. package/build/runtime-esm/lib/types.d.ts +2 -2
  69. package/build/runtime-esm/public/cache.d.ts +8 -1
  70. package/build/runtime-esm/public/cache.js +3 -0
  71. package/build/runtime-esm/public/record.d.ts +11 -1
  72. package/build/runtime-esm/public/record.js +8 -1
  73. package/build/runtime-esm/public/tests/test.d.ts +9 -10
  74. package/build/test-cjs/index.js +893 -747
  75. package/build/test-esm/index.js +893 -747
  76. package/build/vite-cjs/index.js +1195 -998
  77. package/build/vite-esm/index.js +1195 -998
  78. package/package.json +3 -2
@@ -15480,6 +15480,109 @@ var require_minimatch = __commonJS({
15480
15480
  }
15481
15481
  });
15482
15482
 
15483
+ // ../../node_modules/.pnpm/deepmerge@4.2.2/node_modules/deepmerge/dist/cjs.js
15484
+ var require_cjs = __commonJS({
15485
+ "../../node_modules/.pnpm/deepmerge@4.2.2/node_modules/deepmerge/dist/cjs.js"(exports, module) {
15486
+ "use strict";
15487
+ var isMergeableObject = function isMergeableObject2(value) {
15488
+ return isNonNullObject(value) && !isSpecial(value);
15489
+ };
15490
+ function isNonNullObject(value) {
15491
+ return !!value && typeof value === "object";
15492
+ }
15493
+ function isSpecial(value) {
15494
+ var stringValue = Object.prototype.toString.call(value);
15495
+ return stringValue === "[object RegExp]" || stringValue === "[object Date]" || isReactElement(value);
15496
+ }
15497
+ var canUseSymbol = typeof Symbol === "function" && Symbol.for;
15498
+ var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for("react.element") : 60103;
15499
+ function isReactElement(value) {
15500
+ return value.$$typeof === REACT_ELEMENT_TYPE;
15501
+ }
15502
+ function emptyTarget(val) {
15503
+ return Array.isArray(val) ? [] : {};
15504
+ }
15505
+ function cloneUnlessOtherwiseSpecified(value, options) {
15506
+ return options.clone !== false && options.isMergeableObject(value) ? deepmerge(emptyTarget(value), value, options) : value;
15507
+ }
15508
+ function defaultArrayMerge(target, source, options) {
15509
+ return target.concat(source).map(function(element) {
15510
+ return cloneUnlessOtherwiseSpecified(element, options);
15511
+ });
15512
+ }
15513
+ function getMergeFunction(key, options) {
15514
+ if (!options.customMerge) {
15515
+ return deepmerge;
15516
+ }
15517
+ var customMerge = options.customMerge(key);
15518
+ return typeof customMerge === "function" ? customMerge : deepmerge;
15519
+ }
15520
+ function getEnumerableOwnPropertySymbols(target) {
15521
+ return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function(symbol) {
15522
+ return target.propertyIsEnumerable(symbol);
15523
+ }) : [];
15524
+ }
15525
+ function getKeys(target) {
15526
+ return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
15527
+ }
15528
+ function propertyIsOnObject(object, property) {
15529
+ try {
15530
+ return property in object;
15531
+ } catch (_) {
15532
+ return false;
15533
+ }
15534
+ }
15535
+ function propertyIsUnsafe(target, key) {
15536
+ return propertyIsOnObject(target, key) && !(Object.hasOwnProperty.call(target, key) && Object.propertyIsEnumerable.call(target, key));
15537
+ }
15538
+ function mergeObject(target, source, options) {
15539
+ var destination = {};
15540
+ if (options.isMergeableObject(target)) {
15541
+ getKeys(target).forEach(function(key) {
15542
+ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
15543
+ });
15544
+ }
15545
+ getKeys(source).forEach(function(key) {
15546
+ if (propertyIsUnsafe(target, key)) {
15547
+ return;
15548
+ }
15549
+ if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
15550
+ destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
15551
+ } else {
15552
+ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
15553
+ }
15554
+ });
15555
+ return destination;
15556
+ }
15557
+ function deepmerge(target, source, options) {
15558
+ options = options || {};
15559
+ options.arrayMerge = options.arrayMerge || defaultArrayMerge;
15560
+ options.isMergeableObject = options.isMergeableObject || isMergeableObject;
15561
+ options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
15562
+ var sourceIsArray = Array.isArray(source);
15563
+ var targetIsArray = Array.isArray(target);
15564
+ var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
15565
+ if (!sourceAndTargetTypesMatch) {
15566
+ return cloneUnlessOtherwiseSpecified(source, options);
15567
+ } else if (sourceIsArray) {
15568
+ return options.arrayMerge(target, source, options);
15569
+ } else {
15570
+ return mergeObject(target, source, options);
15571
+ }
15572
+ }
15573
+ deepmerge.all = function deepmergeAll(array, options) {
15574
+ if (!Array.isArray(array)) {
15575
+ throw new Error("first argument should be an array");
15576
+ }
15577
+ return array.reduce(function(prev, next) {
15578
+ return deepmerge(prev, next, options);
15579
+ }, {});
15580
+ };
15581
+ var deepmerge_1 = deepmerge;
15582
+ module.exports = deepmerge_1;
15583
+ }
15584
+ });
15585
+
15483
15586
  // ../../node_modules/.pnpm/universalify@2.0.0/node_modules/universalify/index.js
15484
15587
  var require_universalify = __commonJS({
15485
15588
  "../../node_modules/.pnpm/universalify@2.0.0/node_modules/universalify/index.js"(exports) {
@@ -29197,9 +29300,9 @@ var require_lib3 = __commonJS({
29197
29300
  return true;
29198
29301
  }
29199
29302
  }
29200
- getPluginOption(plugin, name) {
29303
+ getPluginOption(plugin2, name) {
29201
29304
  var _this$plugins$get;
29202
- return (_this$plugins$get = this.plugins.get(plugin)) == null ? void 0 : _this$plugins$get[name];
29305
+ return (_this$plugins$get = this.plugins.get(plugin2)) == null ? void 0 : _this$plugins$get[name];
29203
29306
  }
29204
29307
  };
29205
29308
  function setTrailingComments(node, comments) {
@@ -37603,15 +37706,15 @@ var require_lib3 = __commonJS({
37603
37706
  });
37604
37707
  }
37605
37708
  function getPluginOption(plugins, name, option) {
37606
- const plugin = plugins.find((plugin2) => {
37607
- if (Array.isArray(plugin2)) {
37608
- return plugin2[0] === name;
37709
+ const plugin2 = plugins.find((plugin3) => {
37710
+ if (Array.isArray(plugin3)) {
37711
+ return plugin3[0] === name;
37609
37712
  } else {
37610
- return plugin2 === name;
37713
+ return plugin3 === name;
37611
37714
  }
37612
37715
  });
37613
- if (plugin && Array.isArray(plugin) && plugin.length > 1) {
37614
- return plugin[1][option];
37716
+ if (plugin2 && Array.isArray(plugin2) && plugin2.length > 1) {
37717
+ return plugin2[1][option];
37615
37718
  }
37616
37719
  return null;
37617
37720
  }
@@ -41941,8 +42044,8 @@ var require_lib3 = __commonJS({
41941
42044
  };
41942
42045
  function pluginsMap(plugins) {
41943
42046
  const pluginMap = /* @__PURE__ */ new Map();
41944
- for (const plugin of plugins) {
41945
- const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}];
42047
+ for (const plugin2 of plugins) {
42048
+ const [name, options] = Array.isArray(plugin2) ? plugin2 : [plugin2, {}];
41946
42049
  if (!pluginMap.has(name))
41947
42050
  pluginMap.set(name, options || {});
41948
42051
  }
@@ -42011,8 +42114,8 @@ var require_lib3 = __commonJS({
42011
42114
  let cls = parserClassCache[key];
42012
42115
  if (!cls) {
42013
42116
  cls = Parser;
42014
- for (const plugin of pluginList) {
42015
- cls = mixinPlugins[plugin](cls);
42117
+ for (const plugin2 of pluginList) {
42118
+ cls = mixinPlugins[plugin2](cls);
42016
42119
  }
42017
42120
  parserClassCache[key] = cls;
42018
42121
  }
@@ -44643,12 +44746,12 @@ var require_fork = __commonJS({
44643
44746
  function createFork() {
44644
44747
  var used = [];
44645
44748
  var usedResult = [];
44646
- function use(plugin) {
44647
- var idx = used.indexOf(plugin);
44749
+ function use(plugin2) {
44750
+ var idx = used.indexOf(plugin2);
44648
44751
  if (idx === -1) {
44649
44752
  idx = used.length;
44650
- used.push(plugin);
44651
- usedResult[idx] = plugin(fork);
44753
+ used.push(plugin2);
44754
+ usedResult[idx] = plugin2(fork);
44652
44755
  }
44653
44756
  return usedResult[idx];
44654
44757
  }
@@ -61503,6 +61606,9 @@ var houdini_mode = {
61503
61606
  }
61504
61607
  };
61505
61608
 
61609
+ // src/lib/deepMerge.ts
61610
+ var import_deepmerge = __toESM(require_cjs(), 1);
61611
+
61506
61612
  // src/lib/error.ts
61507
61613
  var HoudiniError = class extends Error {
61508
61614
  filepath = null;
@@ -61522,6 +61628,20 @@ var HoudiniError = class extends Error {
61522
61628
  }
61523
61629
  };
61524
61630
 
61631
+ // src/lib/deepMerge.ts
61632
+ function deepMerge(filepath, ...targets) {
61633
+ try {
61634
+ if (targets.length === 1) {
61635
+ return targets[0];
61636
+ } else if (targets.length === 2) {
61637
+ return (0, import_deepmerge.default)(targets[0], targets[1]);
61638
+ }
61639
+ return deepMerge(filepath, targets[0], deepMerge(filepath, ...targets.slice(1)));
61640
+ } catch (e2) {
61641
+ throw new HoudiniError({ filepath, message: "could not merge: " + targets });
61642
+ }
61643
+ }
61644
+
61525
61645
  // src/lib/fs.ts
61526
61646
  var fs_exports = {};
61527
61647
  __export(fs_exports, {
@@ -63039,6 +63159,31 @@ async function pullSchema(url, schemaPath, headers) {
63039
63159
  return false;
63040
63160
  }
63041
63161
 
63162
+ // src/lib/plugin.ts
63163
+ function plugin(name, hooks) {
63164
+ const data = {
63165
+ name,
63166
+ plugin: hooks,
63167
+ __plugin_init__: true,
63168
+ with(config) {
63169
+ return {
63170
+ ...data,
63171
+ config
63172
+ };
63173
+ }
63174
+ };
63175
+ return data;
63176
+ }
63177
+
63178
+ // src/lib/types.ts
63179
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
63180
+ LogLevel2["Full"] = "full";
63181
+ LogLevel2["Summary"] = "summary";
63182
+ LogLevel2["ShortSummary"] = "short-summary";
63183
+ LogLevel2["Quiet"] = "quiet";
63184
+ return LogLevel2;
63185
+ })(LogLevel || {});
63186
+
63042
63187
  // src/lib/config.ts
63043
63188
  var currentDir = global.__dirname || dirname(fileURLToPath(import.meta.url));
63044
63189
  var Config = class {
@@ -63057,7 +63202,6 @@ var Config = class {
63057
63202
  internalListPosition;
63058
63203
  defaultListTarget = null;
63059
63204
  definitionsFolder;
63060
- newSchema = "";
63061
63205
  newDocuments = "";
63062
63206
  defaultKeys = ["id"];
63063
63207
  typeConfig;
@@ -63111,7 +63255,7 @@ var Config = class {
63111
63255
  Object.values(LogLevel)
63112
63256
  )}`
63113
63257
  );
63114
- logLevel = LogLevel.Summary;
63258
+ logLevel = "summary" /* Summary */;
63115
63259
  }
63116
63260
  this.schemaPath = schemaPath;
63117
63261
  this.filepath = filepath;
@@ -63127,7 +63271,7 @@ var Config = class {
63127
63271
  this.internalListPosition = defaultListPosition === "append" ? "last" : "first";
63128
63272
  this.defaultListTarget = defaultListTarget;
63129
63273
  this.definitionsFolder = definitionsPath;
63130
- this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
63274
+ this.logLevel = (logLevel || "summary" /* Summary */).toLowerCase();
63131
63275
  this.defaultFragmentMasking = defaultFragmentMasking;
63132
63276
  this.routesDir = join2(this.projectRoot, "src", "routes");
63133
63277
  this.schemaPollInterval = watchSchema?.interval ?? 2e3;
@@ -63156,7 +63300,7 @@ var Config = class {
63156
63300
  return Array.isArray(this.configFile.include) ? this.configFile.include : [this.configFile.include];
63157
63301
  }
63158
63302
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
63159
- this.plugins.flatMap((plugin) => plugin.extensions ?? [])
63303
+ this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
63160
63304
  );
63161
63305
  return [`src/**/*{${extensions.join(",")}}`];
63162
63306
  }
@@ -63165,10 +63309,10 @@ var Config = class {
63165
63309
  }
63166
63310
  async getEnv() {
63167
63311
  let env = process.env;
63168
- for (const plugin of this.plugins) {
63169
- if (plugin.env) {
63312
+ for (const plugin2 of this.plugins) {
63313
+ if (plugin2.env) {
63170
63314
  env = {
63171
- ...await plugin.env({ config: this, env })
63315
+ ...await plugin2.env({ config: this, env })
63172
63316
  };
63173
63317
  }
63174
63318
  }
@@ -63218,6 +63362,19 @@ var Config = class {
63218
63362
  )
63219
63363
  ];
63220
63364
  }
63365
+ #newSchemaInstance = null;
63366
+ #schemaString = "";
63367
+ set newSchema(value) {
63368
+ this.#schemaString = value;
63369
+ if (value) {
63370
+ this.#newSchemaInstance = graphql2.buildSchema(value);
63371
+ } else {
63372
+ this.#newSchemaInstance = null;
63373
+ }
63374
+ }
63375
+ get newSchema() {
63376
+ return this.#schemaString;
63377
+ }
63221
63378
  get artifactDirectory() {
63222
63379
  return join2(this.rootDir, this.artifactDirectoryName);
63223
63380
  }
@@ -63254,23 +63411,8 @@ var Config = class {
63254
63411
  get typeRootFile() {
63255
63412
  return "$houdini.d.ts";
63256
63413
  }
63257
- findModule(pkg = "houdini", currentLocation = join2(dirname(this.filepath))) {
63258
- const pathEndingBy = ["node_modules", pkg];
63259
- let locationFound = join2(currentLocation, ...pathEndingBy);
63260
- let previousLocation = "";
63261
- const backFolder = [];
63262
- while (previousLocation !== locationFound && !existsSync(locationFound)) {
63263
- previousLocation = locationFound;
63264
- backFolder.push("../");
63265
- locationFound = join2(currentLocation, ...backFolder, ...pathEndingBy);
63266
- }
63267
- if (previousLocation === locationFound) {
63268
- throw new Error("Could not find any node_modules/houdini folder");
63269
- }
63270
- return locationFound;
63271
- }
63272
63414
  get runtimeSource() {
63273
- const relative2 = houdini_mode.is_testing ? join2(currentDir, "..", "..") : this.findModule();
63415
+ const relative2 = houdini_mode.is_testing ? join2(currentDir, "..", "..") : findModule("houdini", join2(dirname(this.filepath)));
63274
63416
  const which = this.module === "esm" ? "esm" : "cjs";
63275
63417
  return resolve(relative2, "build", `runtime-${which}`);
63276
63418
  }
@@ -63325,16 +63467,27 @@ var Config = class {
63325
63467
  relative(process.cwd(), filepath).replaceAll(sep, "_").replace(".ts", ".js")
63326
63468
  );
63327
63469
  }
63470
+ excludeFile(filepath) {
63471
+ if (this.exclude.length > 0 && this.exclude.some((pattern) => (0, import_minimatch.default)(filepath, pattern))) {
63472
+ return true;
63473
+ }
63474
+ for (const plugin2 of this.plugins) {
63475
+ if (plugin2?.exclude?.({ config: this, filepath })) {
63476
+ return true;
63477
+ }
63478
+ }
63479
+ return false;
63480
+ }
63328
63481
  includeFile(filepath, {
63329
63482
  root = this.projectRoot,
63330
63483
  ignore_plugins = false
63331
63484
  } = {}) {
63332
63485
  let included = false;
63333
- for (const plugin of ignore_plugins ? [] : this.plugins) {
63334
- if (!plugin.include) {
63486
+ for (const plugin2 of ignore_plugins ? [] : this.plugins) {
63487
+ if (!plugin2.include) {
63335
63488
  continue;
63336
63489
  }
63337
- if (plugin.include(this, filepath)) {
63490
+ if (plugin2.include({ config: this, filepath })) {
63338
63491
  included = true;
63339
63492
  break;
63340
63493
  }
@@ -63342,7 +63495,7 @@ var Config = class {
63342
63495
  if (!included && !this.include.some((pattern) => (0, import_minimatch.default)(filepath, join2(root, pattern)))) {
63343
63496
  return false;
63344
63497
  }
63345
- return !this.exclude || this.exclude.length === 0 || !this.exclude.some((pattern) => (0, import_minimatch.default)(filepath, pattern));
63498
+ return !this.excludeFile(filepath);
63346
63499
  }
63347
63500
  pluginRuntimeDirectory(name) {
63348
63501
  return join2(this.pluginDirectory(name), "runtime");
@@ -63458,23 +63611,9 @@ var Config = class {
63458
63611
  isInternalEnum(node) {
63459
63612
  return node.name.value === "CachePolicy";
63460
63613
  }
63461
- isInternalDirective({ name }) {
63462
- return [
63463
- this.listDirective,
63464
- this.listPrependDirective,
63465
- this.listAppendDirective,
63466
- this.listParentDirective,
63467
- this.listAllListsDirective,
63468
- this.whenDirective,
63469
- this.whenNotDirective,
63470
- this.argumentsDirective,
63471
- this.withDirective,
63472
- this.paginateDirective,
63473
- this.cacheDirective,
63474
- this.loadDirective,
63475
- this.maskEnableDirective,
63476
- this.maskDisableDirective
63477
- ].includes(name.value) || this.isDeleteDirective(name.value);
63614
+ isInternalDirective(name) {
63615
+ const internalDirectives = this.#newSchemaInstance?.getDirectives().map((directive) => directive.name) ?? [];
63616
+ return internalDirectives.includes(name) || this.isDeleteDirective(name);
63478
63617
  }
63479
63618
  isListFragment(name) {
63480
63619
  return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
@@ -63532,53 +63671,7 @@ var Config = class {
63532
63671
  }
63533
63672
  };
63534
63673
  var DEFAULT_CONFIG_PATH = join2(process.cwd(), "houdini.config.js");
63535
- async function readConfigFile(configPath = DEFAULT_CONFIG_PATH) {
63536
- let importPath2 = importPath(configPath);
63537
- let imported;
63538
- try {
63539
- imported = await import(importPath2);
63540
- } catch (e2) {
63541
- throw new Error(`Could not load config file at file://${configPath}.
63542
- ${e2.message}`);
63543
- }
63544
- const config = imported.default || imported;
63545
- return config;
63546
- }
63547
63674
  var _config;
63548
- async function loadSchemaFile(schemaPath) {
63549
- if (isAbsolute(schemaPath)) {
63550
- const relPath = relative(process.cwd(), schemaPath);
63551
- const error = new Error(
63552
- `Invalid config value: 'schemaPath' must now be passed as a relative directory. Please change its value to "./${relPath}".`
63553
- );
63554
- error.stack = "";
63555
- throw error;
63556
- }
63557
- if (glob.hasMagic(schemaPath)) {
63558
- const sourceFiles = await glob(schemaPath);
63559
- return mergeSchemas({
63560
- typeDefs: await Promise.all(
63561
- sourceFiles.map(async (filepath) => await readFile(filepath))
63562
- )
63563
- });
63564
- }
63565
- try {
63566
- await stat(schemaPath);
63567
- } catch {
63568
- throw new HoudiniError({
63569
- message: `Schema file does not exist! Create it using houdini pull-schema`
63570
- });
63571
- }
63572
- const contents = await readFile(schemaPath);
63573
- if (schemaPath.endsWith("gql") || schemaPath.endsWith("graphql")) {
63574
- return graphql2.buildSchema(contents);
63575
- }
63576
- const jsonContents = JSON.parse(contents);
63577
- if (jsonContents.data) {
63578
- return graphql2.buildClientSchema(jsonContents.data);
63579
- }
63580
- return graphql2.buildClientSchema(jsonContents);
63581
- }
63582
63675
  var pendingConfigPromise = null;
63583
63676
  async function getConfig({
63584
63677
  configPath = DEFAULT_CONFIG_PATH,
@@ -63599,15 +63692,34 @@ async function getConfig({
63599
63692
  resolve2 = res;
63600
63693
  reject = rej;
63601
63694
  });
63602
- let configFile = {
63603
- ...await readConfigFile(configPath)
63604
- };
63605
- if (!configFile.plugins) {
63606
- throw new HoudiniError({
63607
- message: "Welcome to 0.17.0! Please following the migration guide here: http://www.houdinigraphql.com/guides/release-notes#0170"
63608
- });
63609
- }
63610
63695
  try {
63696
+ let configFile = await readConfigFile(configPath);
63697
+ const pluginsNested = [];
63698
+ for (const [pluginName, plugin_config] of Object.entries(configFile.plugins ?? {})) {
63699
+ let pluginFile = join2(dirname(configPath), pluginName);
63700
+ if (!pluginName.startsWith(".")) {
63701
+ pluginFile = await pluginPath(pluginName, configPath);
63702
+ }
63703
+ const { default: pluginInit } = await import(pathToFileURL(pluginFile).toString());
63704
+ if (!pluginInit.plugin || !pluginInit.name) {
63705
+ throw new HoudiniError({
63706
+ filepath: pluginFile,
63707
+ message: `The default export does not match the expected shape.`,
63708
+ description: "Please make sure that the file exports the default of the plugin function."
63709
+ });
63710
+ }
63711
+ const hooks = await pluginInit.plugin(plugin_config);
63712
+ const hooksList = (Array.isArray(hooks) ? hooks : [hooks]).filter(Boolean).flat();
63713
+ pluginsNested.push(
63714
+ await flattenPluginList(configPath, hooksList, pluginName, pluginFile)
63715
+ );
63716
+ }
63717
+ const plugins = pluginsNested.flat();
63718
+ for (const plugin2 of plugins) {
63719
+ if (plugin2.config) {
63720
+ configFile = deepMerge(configPath, configFile, await plugin2.config(configFile));
63721
+ }
63722
+ }
63611
63723
  _config = new Config({
63612
63724
  ...configFile,
63613
63725
  ...extraConfig,
@@ -63620,7 +63732,7 @@ async function getConfig({
63620
63732
  if (glob.hasMagic(_config.schemaPath)) {
63621
63733
  console.log(
63622
63734
  `\u26A0\uFE0F Your houdini configuration contains an apiUrl and a path pointing to multiple files.
63623
- This will prevent your schema from being pulled.`
63735
+ This will prevent your schema from being pulled.`
63624
63736
  );
63625
63737
  } else if (!await readFile(_config.schemaPath)) {
63626
63738
  console.log("\u231B Pulling schema from api");
@@ -63631,67 +63743,138 @@ This will prevent your schema from being pulled.`
63631
63743
  _config.schema = await loadSchemaFile(_config.schemaPath);
63632
63744
  }
63633
63745
  }
63746
+ _config.plugins = orderedPlugins(plugins);
63747
+ await Promise.all(_config.plugins.map((plugin2) => plugin2.after_load?.({ config: _config })));
63748
+ resolve2(_config);
63749
+ return _config;
63634
63750
  } catch (e2) {
63635
63751
  reject(e2);
63636
63752
  throw e2;
63637
63753
  }
63638
- const plugins = [];
63639
- for (const [pluginName, plugin_config] of Object.entries(_config.configFile.plugins ?? {})) {
63640
- try {
63641
- const pluginDirectory = _config.findModule(pluginName);
63642
- const { default: pluginFactory } = await import(pathToFileURL(pluginDirectory).toString() + "/build/plugin-esm/index.js");
63643
- let include_runtime = false;
63644
- try {
63645
- await stat(join2(pluginDirectory, "build", "runtime-esm"));
63646
- include_runtime = true;
63647
- } catch {
63648
- }
63649
- let version = "";
63650
- try {
63651
- const packageJsonSrc = await readFile(join2(pluginDirectory, "package.json"));
63652
- if (!packageJsonSrc) {
63653
- throw new Error("skip");
63654
- }
63655
- const packageJSON = JSON.parse(packageJsonSrc);
63656
- version = packageJSON.version;
63657
- } catch {
63754
+ }
63755
+ async function flattenPluginList(root, list, name, pluginFile) {
63756
+ const pluginsLeft = [
63757
+ {
63758
+ ...plugin(name, async () => list),
63759
+ local: pluginFile
63760
+ }
63761
+ ];
63762
+ const result = [];
63763
+ while (pluginsLeft.length > 0) {
63764
+ const head = pluginsLeft.shift();
63765
+ if (!head) {
63766
+ break;
63767
+ }
63768
+ const nestedFile = head.local ?? await pluginPath(head.name, root);
63769
+ const nestedPlugin = await head.plugin(head.config ?? {});
63770
+ const nestedPluginValues = Array.isArray(nestedPlugin) ? nestedPlugin : [nestedPlugin];
63771
+ for (const value of nestedPluginValues) {
63772
+ if (!value) {
63773
+ continue;
63658
63774
  }
63659
- if (typeof plugin_config)
63660
- plugins.push({
63661
- ...await pluginFactory(plugin_config),
63662
- name: pluginName,
63663
- include_runtime,
63664
- version,
63665
- directory: pluginDirectory
63775
+ if ("__plugin_init__" in value) {
63776
+ pluginsLeft.push(value);
63777
+ } else {
63778
+ result.push({
63779
+ ...value,
63780
+ name: head.name,
63781
+ filepath: nestedFile
63666
63782
  });
63667
- } catch (e2) {
63668
- throw new Error(
63669
- `Could not find plugin: ${pluginName}. Are you sure its installed? If so, please open a ticket on GitHub.`
63670
- );
63783
+ }
63671
63784
  }
63672
63785
  }
63673
- _config.plugins = orderedPlugins(plugins);
63674
- await Promise.all(_config.plugins.map((plugin) => plugin.after_load?.(_config)));
63675
- resolve2(_config);
63676
- return _config;
63786
+ return result;
63787
+ }
63788
+ async function readConfigFile(configPath = DEFAULT_CONFIG_PATH) {
63789
+ let importPath2 = importPath(configPath);
63790
+ let imported;
63791
+ try {
63792
+ imported = await import(importPath2);
63793
+ } catch (e2) {
63794
+ throw new Error(`Could not load config file at file://${configPath}.
63795
+ ${e2.message}`);
63796
+ }
63797
+ const config = imported.default || imported;
63798
+ return config;
63677
63799
  }
63678
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
63679
- LogLevel2["Full"] = "full";
63680
- LogLevel2["Summary"] = "summary";
63681
- LogLevel2["ShortSummary"] = "short-summary";
63682
- LogLevel2["Quiet"] = "quiet";
63683
- return LogLevel2;
63684
- })(LogLevel || {});
63685
63800
  var orderedPlugins = (plugins) => {
63686
63801
  const ordered = plugins.filter(
63687
- (plugin) => plugin.order === "before" || plugin.order === void 0
63802
+ (plugin2) => plugin2.order === "before" || plugin2.order === void 0
63688
63803
  );
63689
63804
  ordered.push(
63690
- ...plugins.filter((plugin) => plugin.order === "core"),
63691
- ...plugins.filter((plugin) => plugin.order === "after")
63805
+ ...plugins.filter((plugin2) => plugin2.order === "core"),
63806
+ ...plugins.filter((plugin2) => plugin2.order === "after")
63692
63807
  );
63693
63808
  return ordered;
63694
63809
  };
63810
+ async function pluginPath(plugin_name, config_path) {
63811
+ try {
63812
+ const pluginDirectory = findModule(plugin_name, config_path);
63813
+ const packageJsonSrc = await readFile(join2(pluginDirectory, "package.json"));
63814
+ if (!packageJsonSrc) {
63815
+ throw new Error("skip");
63816
+ }
63817
+ const packageJSON = JSON.parse(packageJsonSrc);
63818
+ if (!packageJSON.exports?.["."]?.import) {
63819
+ throw new Error("");
63820
+ }
63821
+ return join2(pluginDirectory, packageJSON.exports["."].import);
63822
+ } catch {
63823
+ const err = new Error(
63824
+ `Could not find plugin: ${plugin_name}. Are you sure its installed? If so, please open a ticket on GitHub.`
63825
+ );
63826
+ throw err;
63827
+ }
63828
+ }
63829
+ function findModule(pkg = "houdini", currentLocation) {
63830
+ const pathEndingBy = ["node_modules", pkg];
63831
+ let locationFound = join2(currentLocation, ...pathEndingBy);
63832
+ let previousLocation = "";
63833
+ const backFolder = [];
63834
+ while (previousLocation !== locationFound && !existsSync(locationFound)) {
63835
+ previousLocation = locationFound;
63836
+ backFolder.push("../");
63837
+ locationFound = join2(currentLocation, ...backFolder, ...pathEndingBy);
63838
+ }
63839
+ if (previousLocation === locationFound) {
63840
+ throw new Error("Could not find any node_modules/houdini folder");
63841
+ }
63842
+ return locationFound;
63843
+ }
63844
+ async function loadSchemaFile(schemaPath) {
63845
+ if (isAbsolute(schemaPath)) {
63846
+ const relPath = relative(process.cwd(), schemaPath);
63847
+ const error = new Error(
63848
+ `Invalid config value: 'schemaPath' must now be passed as a relative directory. Please change its value to "./${relPath}".`
63849
+ );
63850
+ error.stack = "";
63851
+ throw error;
63852
+ }
63853
+ if (glob.hasMagic(schemaPath)) {
63854
+ const sourceFiles = await glob(schemaPath);
63855
+ return mergeSchemas({
63856
+ typeDefs: await Promise.all(
63857
+ sourceFiles.map(async (filepath) => await readFile(filepath))
63858
+ )
63859
+ });
63860
+ }
63861
+ try {
63862
+ await stat(schemaPath);
63863
+ } catch {
63864
+ throw new HoudiniError({
63865
+ message: `Schema file does not exist! Create it using houdini pull-schema`
63866
+ });
63867
+ }
63868
+ const contents = await readFile(schemaPath);
63869
+ if (schemaPath.endsWith("gql") || schemaPath.endsWith("graphql")) {
63870
+ return graphql2.buildSchema(contents);
63871
+ }
63872
+ const jsonContents = JSON.parse(contents);
63873
+ if (jsonContents.data) {
63874
+ return graphql2.buildClientSchema(jsonContents.data);
63875
+ }
63876
+ return graphql2.buildClientSchema(jsonContents);
63877
+ }
63695
63878
 
63696
63879
  // src/lib/graphql.ts
63697
63880
  var graphql3 = __toESM(require_graphql2(), 1);
@@ -63705,8 +63888,10 @@ function getRootType(type) {
63705
63888
  }
63706
63889
  return type;
63707
63890
  }
63708
- function hashDocument(document) {
63709
- const docString = typeof document === "string" ? document : graphql3.print(document);
63891
+ function hashDocument({
63892
+ document
63893
+ }) {
63894
+ const docString = typeof document === "string" ? document : graphql3.print(document.document);
63710
63895
  return crypto.createHash("sha256").update(docString).digest("hex");
63711
63896
  }
63712
63897
  function parentTypeFromAncestors(schema, filepath, ancestors) {
@@ -64135,6 +64320,7 @@ export {
64135
64320
  TypeWrapper,
64136
64321
  cleanupFiles,
64137
64322
  computeID,
64323
+ deepMerge,
64138
64324
  defaultConfigValues,
64139
64325
  definitionFromAncestors,
64140
64326
  ensureArtifactImport,
@@ -64155,6 +64341,7 @@ export {
64155
64341
  parseJS,
64156
64342
  parseJSON,
64157
64343
  path_exports as path,
64344
+ plugin,
64158
64345
  pullSchema,
64159
64346
  readConfigFile,
64160
64347
  runPipeline,