nitro-graphql 2.0.0-beta.70 → 2.0.0-beta.73

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 (228) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/adapter.d.mts +0 -3
  3. package/dist/cli/adapter.mjs +7 -32
  4. package/dist/cli/commands/build.d.mts +2 -2
  5. package/dist/cli/commands/build.mjs +1 -3
  6. package/dist/cli/commands/dev.d.mts +2 -2
  7. package/dist/cli/commands/dev.mjs +1 -3
  8. package/dist/cli/commands/generate.mjs +10 -10
  9. package/dist/cli/commands/init.mjs +4 -4
  10. package/dist/cli/commands/validate.mjs +1 -3
  11. package/dist/cli/completions.mjs +1 -3
  12. package/dist/cli/config.d.mts +4 -5
  13. package/dist/cli/config.mjs +4 -3
  14. package/dist/cli/index.d.mts +3 -6
  15. package/dist/cli/index.mjs +2 -4
  16. package/dist/cli/server/debug-handler.mjs +2 -5
  17. package/dist/cli/server/dev-server.mjs +1 -3
  18. package/dist/cli/server/graphql-handler.mjs +3 -4
  19. package/dist/cli/server/health-handler.mjs +1 -2
  20. package/dist/cli/server/loader.mjs +1 -3
  21. package/dist/cli/server/sandbox-handler.mjs +1 -3
  22. package/dist/cli/server/watcher.mjs +2 -4
  23. package/dist/cli/server/ws-handler.mjs +1 -3
  24. package/dist/config.mjs +1 -2
  25. package/dist/core/codegen/client.d.mts +4 -27
  26. package/dist/core/codegen/client.mjs +26 -447
  27. package/dist/core/codegen/document-loader.mjs +1 -3
  28. package/dist/core/codegen/file-header.d.mts +7 -0
  29. package/dist/core/codegen/file-header.mjs +12 -0
  30. package/dist/core/codegen/index.d.mts +7 -5
  31. package/dist/core/codegen/index.mjs +7 -6
  32. package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -3
  33. package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +7 -6
  34. package/dist/core/codegen/schema-loader.d.mts +2 -7
  35. package/dist/core/codegen/schema-loader.mjs +66 -73
  36. package/dist/core/codegen/server-type-helpers.d.mts +14 -0
  37. package/dist/core/codegen/server-type-helpers.mjs +76 -0
  38. package/dist/core/codegen/server.d.mts +1 -15
  39. package/dist/core/codegen/server.mjs +15 -107
  40. package/dist/core/codegen/subscription-extractor.d.mts +20 -0
  41. package/dist/core/codegen/subscription-extractor.mjs +30 -0
  42. package/dist/core/codegen/validation.mjs +1 -3
  43. package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
  44. package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
  45. package/dist/core/constants.d.mts +5 -53
  46. package/dist/core/constants.mjs +13 -56
  47. package/dist/core/create-config.d.mts +31 -0
  48. package/dist/core/create-config.mjs +42 -0
  49. package/dist/core/debug/index.d.mts +2 -2
  50. package/dist/core/debug/index.mjs +2 -3
  51. package/dist/core/debug/template.d.mts +1 -5
  52. package/dist/core/debug/template.mjs +5 -4
  53. package/dist/core/extend/index.mjs +1 -2
  54. package/dist/core/extend/loader.d.mts +0 -1
  55. package/dist/core/extend/loader.mjs +60 -92
  56. package/dist/core/index.d.mts +22 -21
  57. package/dist/core/index.mjs +19 -16
  58. package/dist/core/manifest.mjs +4 -4
  59. package/dist/core/pubsub/index.d.mts +2 -109
  60. package/dist/core/pubsub/index.mjs +2 -148
  61. package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
  62. package/dist/core/pubsub/memory-pubsub.mjs +146 -0
  63. package/dist/core/scanning/ast-scanner.mjs +5 -5
  64. package/dist/core/scanning/directives.mjs +3 -5
  65. package/dist/core/scanning/documents.d.mts +4 -3
  66. package/dist/core/scanning/documents.mjs +4 -5
  67. package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
  68. package/dist/core/scanning/{common.mjs → file-scanner.mjs} +3 -13
  69. package/dist/core/scanning/index.d.mts +3 -3
  70. package/dist/core/scanning/index.mjs +3 -4
  71. package/dist/core/scanning/resolvers.mjs +9 -11
  72. package/dist/core/scanning/schemas.d.mts +1 -5
  73. package/dist/core/scanning/schemas.mjs +2 -26
  74. package/dist/core/schema/builder.d.mts +4 -2
  75. package/dist/core/schema/builder.mjs +4 -4
  76. package/dist/core/schema/federation.mjs +1 -3
  77. package/dist/core/schema/index.d.mts +2 -2
  78. package/dist/core/schema/index.mjs +2 -3
  79. package/dist/core/server/apollo.d.mts +20 -0
  80. package/dist/core/server/apollo.mjs +54 -0
  81. package/dist/core/server/index.d.mts +4 -2
  82. package/dist/core/server/index.mjs +3 -3
  83. package/dist/core/server/sandbox.mjs +1 -2
  84. package/dist/core/server/types.d.mts +7 -14
  85. package/dist/core/server/types.mjs +15 -1
  86. package/dist/core/server/yoga.d.mts +1 -7
  87. package/dist/core/server/yoga.mjs +4 -15
  88. package/dist/core/types/adapter.d.mts +3 -40
  89. package/dist/core/types/adapter.mjs +1 -1
  90. package/dist/core/types/codegen.d.mts +22 -45
  91. package/dist/core/types/codegen.mjs +1 -1
  92. package/dist/core/types/config.d.mts +33 -121
  93. package/dist/core/types/config.mjs +1 -1
  94. package/dist/core/types/define.d.mts +8 -5
  95. package/dist/core/types/define.mjs +1 -1
  96. package/dist/core/types/index.d.mts +5 -4
  97. package/dist/core/types/index.mjs +1 -1
  98. package/dist/core/types/scanning.d.mts +4 -1
  99. package/dist/core/types/scanning.mjs +1 -1
  100. package/dist/core/types/standard-schema.d.mts +64 -0
  101. package/dist/core/types/standard-schema.mjs +1 -0
  102. package/dist/core/utils/directive-parser.d.mts +8 -63
  103. package/dist/core/utils/directive-parser.mjs +114 -167
  104. package/dist/core/utils/errors.mjs +1 -3
  105. package/dist/core/utils/file-io.d.mts +1 -5
  106. package/dist/core/utils/file-io.mjs +1 -13
  107. package/dist/core/utils/imports.mjs +3 -4
  108. package/dist/core/utils/index.d.mts +5 -4
  109. package/dist/core/utils/index.mjs +6 -6
  110. package/dist/core/utils/logger.d.mts +1 -10
  111. package/dist/core/utils/logger.mjs +1 -21
  112. package/dist/core/utils/ofetch-templates.mjs +4 -6
  113. package/dist/core/utils/runtime.d.mts +1 -30
  114. package/dist/core/utils/runtime.mjs +2 -46
  115. package/dist/core/utils/string.d.mts +10 -0
  116. package/dist/core/utils/string.mjs +12 -0
  117. package/dist/core/utils/subscribe-templates.mjs +1 -2
  118. package/dist/core/validation/external-services.mjs +3 -3
  119. package/dist/core/validation/index.mjs +1 -2
  120. package/dist/core/watcher/create-watcher.d.mts +103 -0
  121. package/dist/core/watcher/create-watcher.mjs +143 -0
  122. package/dist/core/watcher/index.d.mts +2 -107
  123. package/dist/core/watcher/index.mjs +2 -141
  124. package/dist/define.d.mts +4 -2
  125. package/dist/define.mjs +8 -9
  126. package/dist/index.d.mts +4 -3
  127. package/dist/index.mjs +3 -4
  128. package/dist/nitro/adapter.d.mts +6 -11
  129. package/dist/nitro/adapter.mjs +12 -45
  130. package/dist/nitro/apollo.mjs +1 -3
  131. package/dist/nitro/codegen/client-types.d.mts +12 -0
  132. package/dist/nitro/codegen/client-types.mjs +73 -0
  133. package/dist/nitro/codegen/external-types.d.mts +8 -0
  134. package/dist/nitro/codegen/external-types.mjs +47 -0
  135. package/dist/nitro/codegen/index.d.mts +4 -0
  136. package/dist/nitro/codegen/index.mjs +4 -0
  137. package/dist/nitro/codegen/server-types.d.mts +12 -0
  138. package/dist/nitro/codegen/server-types.mjs +81 -0
  139. package/dist/nitro/defaults.d.mts +28 -0
  140. package/dist/nitro/defaults.mjs +34 -0
  141. package/dist/nitro/index.d.mts +11 -3
  142. package/dist/nitro/index.mjs +4 -6
  143. package/dist/nitro/paths.d.mts +3 -2
  144. package/dist/nitro/paths.mjs +14 -5
  145. package/dist/nitro/rollup.mjs +8 -8
  146. package/dist/nitro/routes/_ws-handler.d.mts +6 -0
  147. package/dist/nitro/routes/_ws-handler.mjs +49 -0
  148. package/dist/nitro/routes/apollo-sandbox-script.d.mts +2 -2
  149. package/dist/nitro/routes/apollo-sandbox-script.mjs +1 -3
  150. package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
  151. package/dist/nitro/routes/apollo-server-ws.mjs +10 -48
  152. package/dist/nitro/routes/apollo-server.d.mts +2 -2
  153. package/dist/nitro/routes/apollo-server.mjs +17 -58
  154. package/dist/nitro/routes/debug.d.mts +2 -2
  155. package/dist/nitro/routes/debug.mjs +4 -7
  156. package/dist/nitro/routes/graphql-yoga-ws.d.mts +3 -3
  157. package/dist/nitro/routes/graphql-yoga-ws.mjs +7 -48
  158. package/dist/nitro/routes/graphql-yoga.d.mts +2 -2
  159. package/dist/nitro/routes/graphql-yoga.mjs +8 -8
  160. package/dist/nitro/routes/health.d.mts +2 -2
  161. package/dist/nitro/routes/health.mjs +23 -27
  162. package/dist/nitro/setup/extend-loader.d.mts +6 -5
  163. package/dist/nitro/setup/extend-loader.mjs +31 -61
  164. package/dist/nitro/setup/file-watcher.mjs +9 -8
  165. package/dist/nitro/setup/logging.d.mts +1 -8
  166. package/dist/nitro/setup/logging.mjs +7 -24
  167. package/dist/nitro/setup/rollup-integration.mjs +36 -4
  168. package/dist/nitro/setup/routes.mjs +1 -3
  169. package/dist/nitro/setup/scanner.d.mts +8 -43
  170. package/dist/nitro/setup/scanner.mjs +56 -60
  171. package/dist/nitro/setup/security.d.mts +10 -0
  172. package/dist/nitro/setup/security.mjs +17 -0
  173. package/dist/nitro/setup/ts-config.mjs +1 -3
  174. package/dist/nitro/setup/type-generation.d.mts +13 -0
  175. package/dist/nitro/setup/type-generation.mjs +16 -0
  176. package/dist/nitro/setup.d.mts +4 -3
  177. package/dist/nitro/setup.mjs +88 -77
  178. package/dist/nitro/state.d.mts +32 -0
  179. package/dist/nitro/state.mjs +58 -0
  180. package/dist/nitro/types/augmentation.d.mts +59 -0
  181. package/dist/nitro/types/augmentation.mjs +1 -0
  182. package/dist/nitro/types/config.d.mts +327 -0
  183. package/dist/nitro/types/config.mjs +1 -0
  184. package/dist/nitro/types/define.d.mts +13 -0
  185. package/dist/nitro/types/define.mjs +1 -0
  186. package/dist/nitro/types/index.d.mts +10 -0
  187. package/dist/nitro/types/index.mjs +1 -0
  188. package/dist/nitro/virtual/debug-info.d.mts +9 -0
  189. package/dist/nitro/virtual/debug-info.mjs +35 -0
  190. package/dist/nitro/virtual/graphql-config.d.mts +9 -0
  191. package/dist/nitro/virtual/graphql-config.mjs +33 -0
  192. package/dist/nitro/virtual/index.d.mts +25 -0
  193. package/dist/nitro/virtual/index.mjs +45 -0
  194. package/dist/nitro/virtual/module-config.d.mts +9 -0
  195. package/dist/nitro/virtual/module-config.mjs +10 -0
  196. package/dist/nitro/virtual/pubsub.d.mts +9 -0
  197. package/dist/nitro/virtual/pubsub.mjs +17 -0
  198. package/dist/nitro/virtual/server-directives.d.mts +9 -0
  199. package/dist/nitro/virtual/server-directives.mjs +12 -0
  200. package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
  201. package/dist/nitro/virtual/server-resolvers.mjs +17 -0
  202. package/dist/nitro/virtual/server-schemas.d.mts +9 -0
  203. package/dist/nitro/virtual/server-schemas.mjs +31 -0
  204. package/dist/nitro/virtual/stubs.d.mts +42 -10
  205. package/dist/nitro/virtual/stubs.mjs +1 -7
  206. package/dist/nitro/virtual/utils.d.mts +15 -0
  207. package/dist/nitro/virtual/utils.mjs +26 -0
  208. package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
  209. package/dist/nitro/virtual/validation-schemas.mjs +33 -0
  210. package/dist/nuxt.mjs +4 -5
  211. package/dist/stubs/index.mjs +1 -1
  212. package/dist/subscribe/index.mjs +3 -4
  213. package/native/index.js +52 -52
  214. package/package.json +41 -41
  215. package/dist/cli/commands/index.d.mts +0 -5
  216. package/dist/cli/commands/index.mjs +0 -6
  217. package/dist/core/codegen/plugin.d.mts +0 -19
  218. package/dist/core/codegen/plugin.mjs +0 -30
  219. package/dist/core/config.d.mts +0 -45
  220. package/dist/core/config.mjs +0 -78
  221. package/dist/nitro/codegen.d.mts +0 -18
  222. package/dist/nitro/codegen.mjs +0 -173
  223. package/dist/nitro/config.d.mts +0 -50
  224. package/dist/nitro/config.mjs +0 -57
  225. package/dist/nitro/types.d.mts +0 -549
  226. package/dist/nitro/types.mjs +0 -1
  227. package/dist/nitro/virtual/generators.d.mts +0 -38
  228. package/dist/nitro/virtual/generators.mjs +0 -192
@@ -1,7 +1,8 @@
1
- import { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.mjs";
1
+ import { DirectiveFileRef, ParsedDirective, generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile } from "./directive-parser.mjs";
2
2
  import { MaskErrorOptions, createDefaultMaskError } from "./errors.mjs";
3
- import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./file-io.mjs";
3
+ import { ensureDir, writeFile, writeFileIfChanged } from "./file-io.mjs";
4
4
  import { getImportId, relativeWithDot } from "./imports.mjs";
5
- import { createLogger, createSilentLogger, defaultLogger } from "./logger.mjs";
5
+ import { createLogger } from "./logger.mjs";
6
6
  import { OfetchTemplateOptions, generateOfetchTemplate } from "./ofetch-templates.mjs";
7
- export { DirectiveFileRef, DirectiveParser, MaskErrorOptions, OfetchTemplateOptions, ParsedDirective, createDefaultMaskError, createLogger, createSilentLogger, defaultLogger, directiveParser, ensureDir, generateDirectiveSchema, generateDirectiveSchemas, generateOfetchTemplate, getImportId, readFileSafe, relativeWithDot, writeFile, writeFileIfChanged };
7
+ import { capitalize } from "./string.mjs";
8
+ export { DirectiveFileRef, MaskErrorOptions, OfetchTemplateOptions, ParsedDirective, capitalize, createDefaultMaskError, createLogger, ensureDir, generateDirectiveSchema, generateDirectiveSchemas, generateOfetchTemplate, getImportId, parseDirectivesFromFile, relativeWithDot, writeFile, writeFileIfChanged };
@@ -1,8 +1,8 @@
1
- import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./file-io.mjs";
2
- import { createLogger, createSilentLogger, defaultLogger } from "./logger.mjs";
3
- import { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.mjs";
4
- import { createDefaultMaskError } from "./errors.mjs";
1
+ import { ensureDir, writeFile, writeFileIfChanged } from "./file-io.mjs";
2
+ import { capitalize } from "./string.mjs";
3
+ import { createLogger } from "./logger.mjs";
5
4
  import { getImportId, relativeWithDot } from "./imports.mjs";
5
+ import { generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile } from "./directive-parser.mjs";
6
+ import { createDefaultMaskError } from "./errors.mjs";
6
7
  import { generateOfetchTemplate } from "./ofetch-templates.mjs";
7
-
8
- export { DirectiveParser, createDefaultMaskError, createLogger, createSilentLogger, defaultLogger, directiveParser, ensureDir, generateDirectiveSchema, generateDirectiveSchemas, generateOfetchTemplate, getImportId, readFileSafe, relativeWithDot, writeFile, writeFileIfChanged };
8
+ export { capitalize, createDefaultMaskError, createLogger, ensureDir, generateDirectiveSchema, generateDirectiveSchemas, generateOfetchTemplate, getImportId, parseDirectivesFromFile, relativeWithDot, writeFile, writeFileIfChanged };
@@ -5,14 +5,5 @@ import { CoreLogger } from "../types/config.mjs";
5
5
  * Create a logger instance with the nitro-graphql tag
6
6
  */
7
7
  declare function createLogger(tag?: string): CoreLogger;
8
- /**
9
- * Default logger instance
10
- */
11
- declare const defaultLogger: CoreLogger;
12
- /**
13
- * Create a silent logger (no output)
14
- * Useful for testing or when logging should be suppressed
15
- */
16
- declare function createSilentLogger(): CoreLogger;
17
8
  //#endregion
18
- export { createLogger, createSilentLogger, defaultLogger };
9
+ export { createLogger };
@@ -1,6 +1,5 @@
1
1
  import { LOG_TAG } from "../constants.mjs";
2
2
  import { consola as consola$1 } from "consola";
3
-
4
3
  //#region src/core/utils/logger.ts
5
4
  /**
6
5
  * Create a logger instance with the nitro-graphql tag
@@ -15,24 +14,5 @@ function createLogger(tag = LOG_TAG) {
15
14
  debug: (message, ...args) => logger.debug(message, ...args)
16
15
  };
17
16
  }
18
- /**
19
- * Default logger instance
20
- */
21
- const defaultLogger = createLogger();
22
- /**
23
- * Create a silent logger (no output)
24
- * Useful for testing or when logging should be suppressed
25
- */
26
- function createSilentLogger() {
27
- const noop = () => {};
28
- return {
29
- info: noop,
30
- warn: noop,
31
- error: noop,
32
- success: noop,
33
- debug: noop
34
- };
35
- }
36
-
37
17
  //#endregion
38
- export { createLogger, createSilentLogger, defaultLogger };
18
+ export { createLogger };
@@ -1,10 +1,9 @@
1
+ import { capitalize } from "./string.mjs";
1
2
  //#region src/core/utils/ofetch-templates.ts
2
3
  /**
3
- * Capitalize first letter of a string
4
+ * Shared ofetch template generation utilities
5
+ * Used by both main client and external service code generation
4
6
  */
5
- function capitalize(str) {
6
- return str.charAt(0).toUpperCase() + str.slice(1);
7
- }
8
7
  /**
9
8
  * Generate ofetch client template content
10
9
  *
@@ -130,6 +129,5 @@ export function create${capitalizedName}GraphQLClient(endpoint: string = '${endp
130
129
 
131
130
  export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedName}GraphQLClient())`;
132
131
  }
133
-
134
132
  //#endregion
135
- export { generateOfetchTemplate };
133
+ export { generateOfetchTemplate };
@@ -1,5 +1,3 @@
1
- import { basename, dirname, join, resolve } from "pathe";
2
-
3
1
  //#region src/core/utils/runtime.d.ts
4
2
  /**
5
3
  * Cross-runtime compatibility layer
@@ -7,34 +5,18 @@ import { basename, dirname, join, resolve } from "pathe";
7
5
  * Provides runtime-agnostic file system and process utilities
8
6
  * that work across Node.js, Bun, and Deno.
9
7
  */
10
- /**
11
- * Read file contents asynchronously
12
- */
13
- declare function readFile(path: string): Promise<string>;
14
8
  /**
15
9
  * Read file contents synchronously
16
10
  */
17
11
  declare function readFileSync_(path: string): string;
18
- /**
19
- * Write file contents asynchronously
20
- */
21
- declare function writeFile(path: string, content: string): Promise<void>;
22
12
  /**
23
13
  * Write file contents synchronously
24
14
  */
25
15
  declare function writeFileSync_(path: string, content: string): void;
26
- /**
27
- * Check if file/directory exists asynchronously
28
- */
29
- declare function exists(path: string): Promise<boolean>;
30
16
  /**
31
17
  * Check if file/directory exists synchronously
32
18
  */
33
19
  declare function existsSync_(path: string): boolean;
34
- /**
35
- * Create directory recursively asynchronously
36
- */
37
- declare function mkdir(path: string): Promise<void>;
38
20
  /**
39
21
  * Create directory recursively synchronously
40
22
  */
@@ -59,16 +41,5 @@ declare function pathToFileURL(path: string): URL;
59
41
  * Works across Node.js, Bun, and Deno
60
42
  */
61
43
  declare function onSignal(signal: 'SIGINT' | 'SIGTERM', handler: () => void): void;
62
- /**
63
- * Read directory contents
64
- */
65
- declare function readdir(path: string): Promise<string[]>;
66
- /**
67
- * Get file/directory stats
68
- */
69
- declare function stat(path: string): Promise<{
70
- isDirectory: () => boolean;
71
- isFile: () => boolean;
72
- }>;
73
44
  //#endregion
74
- export { basename, dirname, exists, existsSync_, exit, getCwd, join, mkdir, mkdirSync_, onSignal, pathToFileURL, readFile, readFileSync_, readdir, resolve, stat, writeFile, writeFileSync_ };
45
+ export { existsSync_, exit, getCwd, mkdirSync_, onSignal, pathToFileURL, readFileSync_, writeFileSync_ };
@@ -1,7 +1,5 @@
1
- import { basename, dirname, join, resolve } from "pathe";
2
- import { existsSync, mkdirSync, promises, readFileSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
2
  import { pathToFileURL as pathToFileURL$1 } from "node:url";
4
-
5
3
  //#region src/core/utils/runtime.ts
6
4
  /**
7
5
  * Cross-runtime compatibility layer
@@ -11,53 +9,24 @@ import { pathToFileURL as pathToFileURL$1 } from "node:url";
11
9
  */
12
10
  const _globalThis = globalThis;
13
11
  /**
14
- * Read file contents asynchronously
15
- */
16
- async function readFile(path) {
17
- return promises.readFile(path, "utf-8");
18
- }
19
- /**
20
12
  * Read file contents synchronously
21
13
  */
22
14
  function readFileSync_(path) {
23
15
  return readFileSync(path, "utf-8");
24
16
  }
25
17
  /**
26
- * Write file contents asynchronously
27
- */
28
- async function writeFile(path, content) {
29
- await promises.writeFile(path, content, "utf-8");
30
- }
31
- /**
32
18
  * Write file contents synchronously
33
19
  */
34
20
  function writeFileSync_(path, content) {
35
21
  writeFileSync(path, content, "utf-8");
36
22
  }
37
23
  /**
38
- * Check if file/directory exists asynchronously
39
- */
40
- async function exists(path) {
41
- try {
42
- await promises.access(path);
43
- return true;
44
- } catch {
45
- return false;
46
- }
47
- }
48
- /**
49
24
  * Check if file/directory exists synchronously
50
25
  */
51
26
  function existsSync_(path) {
52
27
  return existsSync(path);
53
28
  }
54
29
  /**
55
- * Create directory recursively asynchronously
56
- */
57
- async function mkdir(path) {
58
- await promises.mkdir(path, { recursive: true });
59
- }
60
- /**
61
30
  * Create directory recursively synchronously
62
31
  */
63
32
  function mkdirSync_(path) {
@@ -94,18 +63,5 @@ function onSignal(signal, handler) {
94
63
  if (_globalThis.Deno) _globalThis.Deno.addSignalListener(signal, handler);
95
64
  else process.on(signal, handler);
96
65
  }
97
- /**
98
- * Read directory contents
99
- */
100
- async function readdir(path) {
101
- return promises.readdir(path);
102
- }
103
- /**
104
- * Get file/directory stats
105
- */
106
- async function stat(path) {
107
- return promises.stat(path);
108
- }
109
-
110
66
  //#endregion
111
- export { basename, dirname, exists, existsSync_, exit, getCwd, join, mkdir, mkdirSync_, onSignal, pathToFileURL, readFile, readFileSync_, readdir, resolve, stat, writeFile, writeFileSync_ };
67
+ export { existsSync_, exit, getCwd, mkdirSync_, onSignal, pathToFileURL, readFileSync_, writeFileSync_ };
@@ -0,0 +1,10 @@
1
+ //#region src/core/utils/string.d.ts
2
+ /**
3
+ * Shared string utilities
4
+ */
5
+ /**
6
+ * Capitalize the first character of a string (PascalCase first letter)
7
+ */
8
+ declare function capitalize(str: string): string;
9
+ //#endregion
10
+ export { capitalize };
@@ -0,0 +1,12 @@
1
+ //#region src/core/utils/string.ts
2
+ /**
3
+ * Shared string utilities
4
+ */
5
+ /**
6
+ * Capitalize the first character of a string (PascalCase first letter)
7
+ */
8
+ function capitalize(str) {
9
+ return str.charAt(0).toUpperCase() + str.slice(1);
10
+ }
11
+ //#endregion
12
+ export { capitalize };
@@ -54,6 +54,5 @@ const config: SubscriptionClientConfig = {
54
54
  // Export configured client instance
55
55
  export const subscriptionClient = createSubscriptionClient(config)
56
56
  `;
57
-
58
57
  //#endregion
59
- export { subscribeClientTemplate };
58
+ export { subscribeClientTemplate };
@@ -3,6 +3,7 @@
3
3
  * External services validation utilities
4
4
  * Framework-agnostic validation helpers
5
5
  */
6
+ const VALID_IDENTIFIER_RE = /^[a-z]\w*$/i;
6
7
  /**
7
8
  * Validate external GraphQL service configuration
8
9
  */
@@ -24,10 +25,9 @@ function validateExternalServices(services) {
24
25
  } catch {
25
26
  errors.push(`${prefix}.endpoint "${service.endpoint}" must be a valid URL`);
26
27
  }
27
- if ("name" in service && typeof service.name === "string" && !/^[a-z]\w*$/i.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
28
+ if ("name" in service && typeof service.name === "string" && !VALID_IDENTIFIER_RE.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
28
29
  }
29
30
  return errors;
30
31
  }
31
-
32
32
  //#endregion
33
- export { validateExternalServices };
33
+ export { validateExternalServices };
@@ -1,3 +1,2 @@
1
1
  import { validateExternalServices } from "./external-services.mjs";
2
-
3
- export { validateExternalServices };
2
+ export { validateExternalServices };
@@ -0,0 +1,103 @@
1
+ import { FSWatcher } from "chokidar";
2
+
3
+ //#region src/core/watcher/create-watcher.d.ts
4
+ /**
5
+ * Configuration for core watcher
6
+ */
7
+ interface CoreWatcherConfig {
8
+ /** Directories to watch */
9
+ watchDirs: string[];
10
+ /** Server directory path (to classify changes) */
11
+ serverDir: string;
12
+ /** Debounce delay in ms (default: 150) */
13
+ debounceMs?: number;
14
+ /** Persistent watcher (default: true) */
15
+ persistent?: boolean;
16
+ /** Ignore initial scan (default: true) */
17
+ ignoreInitial?: boolean;
18
+ /** Use polling mode (default: false, but auto-enabled in CI/test environments) */
19
+ usePolling?: boolean;
20
+ }
21
+ /**
22
+ * Callbacks for watcher events
23
+ */
24
+ interface CoreWatcherCallbacks {
25
+ /** Called when server files change (schemas, resolvers, directives) */
26
+ onServerChange: () => Promise<void>;
27
+ /** Called when client files change (documents only) */
28
+ onClientChange: () => Promise<void>;
29
+ /** Called when watcher is ready */
30
+ onReady?: () => void;
31
+ /** Called on watcher error */
32
+ onError?: (error: unknown) => void;
33
+ }
34
+ /**
35
+ * File type classification
36
+ */
37
+ type FileType = 'graphql' | 'resolver' | 'directive' | null;
38
+ /**
39
+ * Change type classification
40
+ */
41
+ type ChangeType = 'server' | 'client' | null;
42
+ /**
43
+ * Check if a file is a GraphQL-related file
44
+ */
45
+ declare function getFileType(path: string): FileType;
46
+ /**
47
+ * Check if a file should be watched
48
+ */
49
+ declare function isWatchableFile(path: string): boolean;
50
+ /**
51
+ * Classify a file change as server or client
52
+ */
53
+ declare function classifyChange(path: string, serverDir: string): ChangeType;
54
+ declare function createIgnoredFunction(): (path: string) => boolean;
55
+ /**
56
+ * Check if a path should be skipped (generated files)
57
+ */
58
+ declare function shouldSkipPath(path: string): boolean;
59
+ /**
60
+ * Create a core file watcher
61
+ *
62
+ * This is the shared watcher used by both Nitro and CLI.
63
+ * Framework-specific actions are passed as callbacks.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * // In Nitro
68
+ * const watcher = createCoreWatcher(
69
+ * { watchDirs, serverDir: nitro.graphql.serverDir },
70
+ * {
71
+ * onServerChange: async () => {
72
+ * await performGraphQLScan(nitro, { silent: true, isRescan: true })
73
+ * await generateServerTypes(nitro, { silent: true })
74
+ * await nitro.hooks.callHook('dev:reload')
75
+ * },
76
+ * onClientChange: async () => {
77
+ * await generateClientTypes(nitro, { silent: true })
78
+ * },
79
+ * }
80
+ * )
81
+ *
82
+ * // In CLI
83
+ * const watcher = createCoreWatcher(
84
+ * { watchDirs, serverDir: ctx.config.serverDir },
85
+ * {
86
+ * onServerChange: async () => {
87
+ * await generateAll(ctx, { silent: true })
88
+ * await reloadHandler()
89
+ * },
90
+ * onClientChange: async () => {
91
+ * await generateClient(ctx, { silent: true })
92
+ * },
93
+ * }
94
+ * )
95
+ * ```
96
+ */
97
+ declare function createCoreWatcher(config: CoreWatcherConfig, callbacks: CoreWatcherCallbacks): FSWatcher;
98
+ /**
99
+ * Close a watcher safely
100
+ */
101
+ declare function closeWatcher(watcher: FSWatcher): Promise<void>;
102
+ //#endregion
103
+ export { ChangeType, CoreWatcherCallbacks, CoreWatcherConfig, FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
@@ -0,0 +1,143 @@
1
+ import { DEFAULT_IGNORE_PATTERNS, DIRECTIVE_EXTENSIONS, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../constants.mjs";
2
+ import { watch } from "chokidar";
3
+ import { debounce } from "perfect-debounce";
4
+ //#region src/core/watcher/create-watcher.ts
5
+ const BACKSLASH_RE = /\\/g;
6
+ /**
7
+ * Check if a file is a GraphQL-related file
8
+ */
9
+ function getFileType(path) {
10
+ if (GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext))) return "graphql";
11
+ if (RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext))) return "resolver";
12
+ if (DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext))) return "directive";
13
+ return null;
14
+ }
15
+ /**
16
+ * Check if a file should be watched
17
+ */
18
+ function isWatchableFile(path) {
19
+ return getFileType(path) !== null;
20
+ }
21
+ /**
22
+ * Classify a file change as server or client
23
+ */
24
+ function classifyChange(path, serverDir) {
25
+ const fileType = getFileType(path);
26
+ if (!fileType) return null;
27
+ if (fileType === "resolver" || fileType === "directive") return "server";
28
+ if (fileType === "graphql") {
29
+ const normalizedPath = path.replace(BACKSLASH_RE, "/");
30
+ const normalizedServerDir = serverDir.replace(BACKSLASH_RE, "/");
31
+ if (normalizedPath.includes(normalizedServerDir)) return "server";
32
+ if (normalizedPath.includes("/server/graphql/") || normalizedPath.includes("\\server\\graphql\\")) return "server";
33
+ return "client";
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * Create the ignored function for chokidar
39
+ * Filters out non-GraphQL files and system directories
40
+ */
41
+ const GLOB_STAR_RE = /\*\*/g;
42
+ const SINGLE_STAR_RE = /\*/g;
43
+ function createIgnoredFunction() {
44
+ const ignoredDirs = DEFAULT_IGNORE_PATTERNS.map((p) => p.replace(GLOB_STAR_RE, "").replace(SINGLE_STAR_RE, ""));
45
+ return (path) => {
46
+ if (ignoredDirs.some((dir) => path.includes(dir))) return true;
47
+ if (!(path.split("/").pop() || "").includes(".") || path.endsWith("/")) return false;
48
+ return !isWatchableFile(path);
49
+ };
50
+ }
51
+ /**
52
+ * Check if a path should be skipped (generated files)
53
+ */
54
+ function shouldSkipPath(path) {
55
+ return path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts");
56
+ }
57
+ /**
58
+ * Create a core file watcher
59
+ *
60
+ * This is the shared watcher used by both Nitro and CLI.
61
+ * Framework-specific actions are passed as callbacks.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // In Nitro
66
+ * const watcher = createCoreWatcher(
67
+ * { watchDirs, serverDir: nitro.graphql.serverDir },
68
+ * {
69
+ * onServerChange: async () => {
70
+ * await performGraphQLScan(nitro, { silent: true, isRescan: true })
71
+ * await generateServerTypes(nitro, { silent: true })
72
+ * await nitro.hooks.callHook('dev:reload')
73
+ * },
74
+ * onClientChange: async () => {
75
+ * await generateClientTypes(nitro, { silent: true })
76
+ * },
77
+ * }
78
+ * )
79
+ *
80
+ * // In CLI
81
+ * const watcher = createCoreWatcher(
82
+ * { watchDirs, serverDir: ctx.config.serverDir },
83
+ * {
84
+ * onServerChange: async () => {
85
+ * await generateAll(ctx, { silent: true })
86
+ * await reloadHandler()
87
+ * },
88
+ * onClientChange: async () => {
89
+ * await generateClient(ctx, { silent: true })
90
+ * },
91
+ * }
92
+ * )
93
+ * ```
94
+ */
95
+ function createCoreWatcher(config, callbacks) {
96
+ const { watchDirs, serverDir, debounceMs = 150, persistent = true, ignoreInitial = true, usePolling } = config;
97
+ const shouldUsePolling = usePolling ?? (process.env.CI === "true" || process.env.VITE_TEST === "true");
98
+ const watcher = watch(watchDirs, {
99
+ persistent,
100
+ ignoreInitial,
101
+ ignored: createIgnoredFunction(),
102
+ usePolling: shouldUsePolling,
103
+ interval: shouldUsePolling ? 100 : void 0,
104
+ awaitWriteFinish: shouldUsePolling ? {
105
+ stabilityThreshold: 100,
106
+ pollInterval: 50
107
+ } : false
108
+ });
109
+ const pending = {
110
+ server: false,
111
+ client: false
112
+ };
113
+ async function processChanges() {
114
+ const changes = { ...pending };
115
+ pending.server = pending.client = false;
116
+ try {
117
+ if (changes.server) await callbacks.onServerChange();
118
+ else if (changes.client) await callbacks.onClientChange();
119
+ } catch (error) {
120
+ callbacks.onError?.(error);
121
+ }
122
+ }
123
+ const debouncedProcess = debounce(processChanges, debounceMs);
124
+ watcher.on("all", (_, path) => {
125
+ if (shouldSkipPath(path)) return;
126
+ const changeType = classifyChange(path, serverDir);
127
+ if (!changeType) return;
128
+ if (changeType === "server") pending.server = true;
129
+ else pending.client = true;
130
+ debouncedProcess();
131
+ });
132
+ if (callbacks.onReady) watcher.on("ready", callbacks.onReady);
133
+ if (callbacks.onError) watcher.on("error", callbacks.onError);
134
+ return watcher;
135
+ }
136
+ /**
137
+ * Close a watcher safely
138
+ */
139
+ async function closeWatcher(watcher) {
140
+ await watcher.close();
141
+ }
142
+ //#endregion
143
+ export { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
@@ -1,107 +1,2 @@
1
- import { FSWatcher } from "chokidar";
2
-
3
- //#region src/core/watcher/index.d.ts
4
- /**
5
- * Configuration for core watcher
6
- */
7
- interface CoreWatcherConfig {
8
- /** Directories to watch */
9
- watchDirs: string[];
10
- /** Server directory path (to classify changes) */
11
- serverDir: string;
12
- /** Debounce delay in ms (default: 150) */
13
- debounceMs?: number;
14
- /** Persistent watcher (default: true) */
15
- persistent?: boolean;
16
- /** Ignore initial scan (default: true) */
17
- ignoreInitial?: boolean;
18
- /** Use polling mode (default: false, but auto-enabled in CI/test environments) */
19
- usePolling?: boolean;
20
- }
21
- /**
22
- * Callbacks for watcher events
23
- */
24
- interface CoreWatcherCallbacks {
25
- /** Called when server files change (schemas, resolvers, directives) */
26
- onServerChange: () => Promise<void>;
27
- /** Called when client files change (documents only) */
28
- onClientChange: () => Promise<void>;
29
- /** Called when watcher is ready */
30
- onReady?: () => void;
31
- /** Called on watcher error */
32
- onError?: (error: unknown) => void;
33
- }
34
- /**
35
- * File type classification
36
- */
37
- type FileType = 'graphql' | 'resolver' | 'directive' | null;
38
- /**
39
- * Change type classification
40
- */
41
- type ChangeType = 'server' | 'client' | null;
42
- /**
43
- * Check if a file is a GraphQL-related file
44
- */
45
- declare function getFileType(path: string): FileType;
46
- /**
47
- * Check if a file should be watched
48
- */
49
- declare function isWatchableFile(path: string): boolean;
50
- /**
51
- * Classify a file change as server or client
52
- */
53
- declare function classifyChange(path: string, serverDir: string): ChangeType;
54
- /**
55
- * Create the ignored function for chokidar
56
- * Filters out non-GraphQL files and system directories
57
- */
58
- declare function createIgnoredFunction(): (path: string) => boolean;
59
- /**
60
- * Check if a path should be skipped (generated files)
61
- */
62
- declare function shouldSkipPath(path: string): boolean;
63
- /**
64
- * Create a core file watcher
65
- *
66
- * This is the shared watcher used by both Nitro and CLI.
67
- * Framework-specific actions are passed as callbacks.
68
- *
69
- * @example
70
- * ```typescript
71
- * // In Nitro
72
- * const watcher = createCoreWatcher(
73
- * { watchDirs, serverDir: nitro.graphql.serverDir },
74
- * {
75
- * onServerChange: async () => {
76
- * await performGraphQLScan(nitro, { silent: true, isRescan: true })
77
- * await generateServerTypes(nitro, { silent: true })
78
- * await nitro.hooks.callHook('dev:reload')
79
- * },
80
- * onClientChange: async () => {
81
- * await generateClientTypes(nitro, { silent: true })
82
- * },
83
- * }
84
- * )
85
- *
86
- * // In CLI
87
- * const watcher = createCoreWatcher(
88
- * { watchDirs, serverDir: ctx.config.serverDir },
89
- * {
90
- * onServerChange: async () => {
91
- * await generateAll(ctx, { silent: true })
92
- * await reloadHandler()
93
- * },
94
- * onClientChange: async () => {
95
- * await generateClient(ctx, { silent: true })
96
- * },
97
- * }
98
- * )
99
- * ```
100
- */
101
- declare function createCoreWatcher(config: CoreWatcherConfig, callbacks: CoreWatcherCallbacks): FSWatcher;
102
- /**
103
- * Close a watcher safely
104
- */
105
- declare function closeWatcher(watcher: FSWatcher): Promise<void>;
106
- //#endregion
107
- export { ChangeType, CoreWatcherCallbacks, CoreWatcherConfig, FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
1
+ import { ChangeType, CoreWatcherCallbacks, CoreWatcherConfig, FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath } from "./create-watcher.mjs";
2
+ export { type ChangeType, type CoreWatcherCallbacks, type CoreWatcherConfig, type FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };