nitro-graphql 2.0.0-beta.72 → 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 (187) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/adapter.d.mts +0 -3
  3. package/dist/cli/adapter.mjs +6 -29
  4. package/dist/cli/commands/generate.mjs +2 -2
  5. package/dist/cli/config.d.mts +4 -5
  6. package/dist/cli/config.mjs +3 -1
  7. package/dist/cli/index.d.mts +3 -6
  8. package/dist/cli/index.mjs +1 -1
  9. package/dist/cli/server/graphql-handler.mjs +2 -1
  10. package/dist/cli/server/watcher.mjs +1 -1
  11. package/dist/core/codegen/client.d.mts +4 -27
  12. package/dist/core/codegen/client.mjs +26 -445
  13. package/dist/core/codegen/file-header.d.mts +7 -0
  14. package/dist/core/codegen/file-header.mjs +12 -0
  15. package/dist/core/codegen/index.d.mts +7 -5
  16. package/dist/core/codegen/index.mjs +7 -5
  17. package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
  18. package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
  19. package/dist/core/codegen/schema-loader.d.mts +2 -7
  20. package/dist/core/codegen/schema-loader.mjs +65 -70
  21. package/dist/core/codegen/server-type-helpers.d.mts +14 -0
  22. package/dist/core/codegen/server-type-helpers.mjs +76 -0
  23. package/dist/core/codegen/server.d.mts +1 -15
  24. package/dist/core/codegen/server.mjs +15 -105
  25. package/dist/core/codegen/subscription-extractor.d.mts +20 -0
  26. package/dist/core/codegen/subscription-extractor.mjs +30 -0
  27. package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
  28. package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
  29. package/dist/core/constants.d.mts +5 -53
  30. package/dist/core/constants.mjs +13 -54
  31. package/dist/core/create-config.d.mts +31 -0
  32. package/dist/core/create-config.mjs +42 -0
  33. package/dist/core/debug/index.d.mts +2 -2
  34. package/dist/core/debug/index.mjs +2 -2
  35. package/dist/core/debug/template.d.mts +1 -5
  36. package/dist/core/debug/template.mjs +1 -1
  37. package/dist/core/extend/loader.d.mts +0 -1
  38. package/dist/core/extend/loader.mjs +59 -89
  39. package/dist/core/index.d.mts +22 -17
  40. package/dist/core/index.mjs +19 -15
  41. package/dist/core/manifest.mjs +3 -1
  42. package/dist/core/pubsub/index.d.mts +2 -109
  43. package/dist/core/pubsub/index.mjs +1 -145
  44. package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
  45. package/dist/core/pubsub/memory-pubsub.mjs +146 -0
  46. package/dist/core/scanning/ast-scanner.mjs +4 -2
  47. package/dist/core/scanning/directives.mjs +2 -3
  48. package/dist/core/scanning/documents.d.mts +4 -3
  49. package/dist/core/scanning/documents.mjs +1 -1
  50. package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
  51. package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
  52. package/dist/core/scanning/index.d.mts +3 -3
  53. package/dist/core/scanning/index.mjs +3 -3
  54. package/dist/core/scanning/resolvers.mjs +8 -9
  55. package/dist/core/scanning/schemas.d.mts +1 -5
  56. package/dist/core/scanning/schemas.mjs +2 -24
  57. package/dist/core/schema/builder.d.mts +4 -2
  58. package/dist/core/schema/builder.mjs +4 -2
  59. package/dist/core/schema/index.d.mts +2 -2
  60. package/dist/core/schema/index.mjs +2 -2
  61. package/dist/core/server/apollo.d.mts +20 -0
  62. package/dist/core/server/apollo.mjs +54 -0
  63. package/dist/core/server/index.d.mts +4 -2
  64. package/dist/core/server/index.mjs +3 -2
  65. package/dist/core/server/types.d.mts +7 -14
  66. package/dist/core/server/types.mjs +15 -1
  67. package/dist/core/server/yoga.d.mts +1 -7
  68. package/dist/core/server/yoga.mjs +4 -13
  69. package/dist/core/types/adapter.d.mts +4 -39
  70. package/dist/core/types/codegen.d.mts +22 -45
  71. package/dist/core/types/config.d.mts +33 -121
  72. package/dist/core/types/define.d.mts +8 -5
  73. package/dist/core/types/index.d.mts +5 -4
  74. package/dist/core/types/scanning.d.mts +4 -1
  75. package/dist/core/types/standard-schema.d.mts +64 -0
  76. package/dist/core/utils/directive-parser.d.mts +8 -63
  77. package/dist/core/utils/directive-parser.mjs +114 -166
  78. package/dist/core/utils/file-io.d.mts +1 -5
  79. package/dist/core/utils/file-io.mjs +1 -11
  80. package/dist/core/utils/index.d.mts +5 -4
  81. package/dist/core/utils/index.mjs +6 -5
  82. package/dist/core/utils/logger.d.mts +1 -10
  83. package/dist/core/utils/logger.mjs +1 -19
  84. package/dist/core/utils/ofetch-templates.mjs +3 -4
  85. package/dist/core/utils/runtime.d.mts +1 -30
  86. package/dist/core/utils/runtime.mjs +2 -44
  87. package/dist/core/utils/string.d.mts +10 -0
  88. package/dist/core/utils/string.mjs +12 -0
  89. package/dist/core/watcher/create-watcher.d.mts +103 -0
  90. package/dist/core/watcher/create-watcher.mjs +143 -0
  91. package/dist/core/watcher/index.d.mts +2 -107
  92. package/dist/core/watcher/index.mjs +1 -139
  93. package/dist/define.d.mts +4 -2
  94. package/dist/define.mjs +7 -6
  95. package/dist/index.d.mts +4 -3
  96. package/dist/index.mjs +1 -1
  97. package/dist/nitro/adapter.d.mts +6 -10
  98. package/dist/nitro/adapter.mjs +12 -42
  99. package/dist/nitro/codegen/client-types.d.mts +12 -0
  100. package/dist/nitro/codegen/client-types.mjs +73 -0
  101. package/dist/nitro/codegen/external-types.d.mts +8 -0
  102. package/dist/nitro/codegen/external-types.mjs +47 -0
  103. package/dist/nitro/codegen/index.d.mts +4 -0
  104. package/dist/nitro/codegen/index.mjs +4 -0
  105. package/dist/nitro/codegen/server-types.d.mts +12 -0
  106. package/dist/nitro/codegen/server-types.mjs +81 -0
  107. package/dist/nitro/defaults.d.mts +28 -0
  108. package/dist/nitro/defaults.mjs +34 -0
  109. package/dist/nitro/index.d.mts +11 -3
  110. package/dist/nitro/index.mjs +1 -1
  111. package/dist/nitro/paths.d.mts +3 -2
  112. package/dist/nitro/paths.mjs +13 -9
  113. package/dist/nitro/rollup.mjs +4 -3
  114. package/dist/nitro/routes/_ws-handler.d.mts +6 -0
  115. package/dist/nitro/routes/_ws-handler.mjs +49 -0
  116. package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
  117. package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
  118. package/dist/nitro/routes/apollo-server.d.mts +1 -1
  119. package/dist/nitro/routes/apollo-server.mjs +16 -55
  120. package/dist/nitro/routes/debug.d.mts +1 -1
  121. package/dist/nitro/routes/debug.mjs +1 -0
  122. package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
  123. package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
  124. package/dist/nitro/routes/graphql-yoga.mjs +7 -5
  125. package/dist/nitro/routes/health.mjs +22 -24
  126. package/dist/nitro/setup/extend-loader.d.mts +6 -5
  127. package/dist/nitro/setup/extend-loader.mjs +30 -58
  128. package/dist/nitro/setup/file-watcher.mjs +6 -4
  129. package/dist/nitro/setup/logging.d.mts +1 -8
  130. package/dist/nitro/setup/logging.mjs +7 -22
  131. package/dist/nitro/setup/rollup-integration.mjs +32 -1
  132. package/dist/nitro/setup/scanner.d.mts +8 -43
  133. package/dist/nitro/setup/scanner.mjs +56 -58
  134. package/dist/nitro/setup/security.d.mts +10 -0
  135. package/dist/nitro/setup/security.mjs +17 -0
  136. package/dist/nitro/setup/type-generation.d.mts +13 -0
  137. package/dist/nitro/setup/type-generation.mjs +16 -0
  138. package/dist/nitro/setup.d.mts +4 -3
  139. package/dist/nitro/setup.mjs +87 -74
  140. package/dist/nitro/state.d.mts +32 -0
  141. package/dist/nitro/state.mjs +58 -0
  142. package/dist/nitro/types/augmentation.d.mts +59 -0
  143. package/dist/nitro/types/augmentation.mjs +1 -0
  144. package/dist/nitro/types/config.d.mts +327 -0
  145. package/dist/nitro/types/config.mjs +1 -0
  146. package/dist/nitro/types/define.d.mts +13 -0
  147. package/dist/nitro/types/define.mjs +1 -0
  148. package/dist/nitro/types/index.d.mts +10 -0
  149. package/dist/nitro/types/index.mjs +1 -0
  150. package/dist/nitro/virtual/debug-info.d.mts +9 -0
  151. package/dist/nitro/virtual/debug-info.mjs +35 -0
  152. package/dist/nitro/virtual/graphql-config.d.mts +9 -0
  153. package/dist/nitro/virtual/graphql-config.mjs +33 -0
  154. package/dist/nitro/virtual/index.d.mts +25 -0
  155. package/dist/nitro/virtual/index.mjs +45 -0
  156. package/dist/nitro/virtual/module-config.d.mts +9 -0
  157. package/dist/nitro/virtual/module-config.mjs +10 -0
  158. package/dist/nitro/virtual/pubsub.d.mts +9 -0
  159. package/dist/nitro/virtual/pubsub.mjs +17 -0
  160. package/dist/nitro/virtual/server-directives.d.mts +9 -0
  161. package/dist/nitro/virtual/server-directives.mjs +12 -0
  162. package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
  163. package/dist/nitro/virtual/server-resolvers.mjs +17 -0
  164. package/dist/nitro/virtual/server-schemas.d.mts +9 -0
  165. package/dist/nitro/virtual/server-schemas.mjs +31 -0
  166. package/dist/nitro/virtual/stubs.d.mts +42 -10
  167. package/dist/nitro/virtual/stubs.mjs +0 -5
  168. package/dist/nitro/virtual/utils.d.mts +15 -0
  169. package/dist/nitro/virtual/utils.mjs +26 -0
  170. package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
  171. package/dist/nitro/virtual/validation-schemas.mjs +33 -0
  172. package/native/index.js +52 -52
  173. package/package.json +15 -15
  174. package/dist/cli/commands/index.d.mts +0 -5
  175. package/dist/cli/commands/index.mjs +0 -5
  176. package/dist/core/codegen/plugin.d.mts +0 -19
  177. package/dist/core/codegen/plugin.mjs +0 -29
  178. package/dist/core/config.d.mts +0 -45
  179. package/dist/core/config.mjs +0 -76
  180. package/dist/nitro/codegen.d.mts +0 -18
  181. package/dist/nitro/codegen.mjs +0 -171
  182. package/dist/nitro/config.d.mts +0 -50
  183. package/dist/nitro/config.mjs +0 -55
  184. package/dist/nitro/types.d.mts +0 -549
  185. package/dist/nitro/virtual/generators.d.mts +0 -38
  186. package/dist/nitro/virtual/generators.mjs +0 -190
  187. /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
@@ -0,0 +1,64 @@
1
+ //#region src/core/types/standard-schema.d.ts
2
+ /**
3
+ * Standard Schema V1 type definition
4
+ * Implements the Standard Schema specification for runtime validation interop
5
+ * @see https://github.com/standard-schema/standard-schema
6
+ */
7
+ /** The Standard Schema interface. */
8
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
9
+ /** The Standard Schema properties. */
10
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
11
+ }
12
+ declare namespace StandardSchemaV1 {
13
+ /** The Standard Schema properties interface. */
14
+ export interface Props<Input = unknown, Output = Input> {
15
+ /** The version number of the standard. */
16
+ readonly version: 1;
17
+ /** The vendor name of the schema library. */
18
+ readonly vendor: string;
19
+ /** Validates unknown input values. */
20
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
21
+ /** Inferred types associated with the schema. */
22
+ readonly types?: Types<Input, Output> | undefined;
23
+ }
24
+ /** The result interface of the validate function. */
25
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
26
+ /** The result interface if validation succeeds. */
27
+ export interface SuccessResult<Output> {
28
+ /** The typed output value. */
29
+ readonly value: Output;
30
+ /** The non-existent issues. */
31
+ readonly issues?: undefined;
32
+ }
33
+ /** The result interface if validation fails. */
34
+ export interface FailureResult {
35
+ /** The issues of failed validation. */
36
+ readonly issues: ReadonlyArray<Issue>;
37
+ }
38
+ /** The issue interface of the failure output. */
39
+ export interface Issue {
40
+ /** The error message of the issue. */
41
+ readonly message: string;
42
+ /** The path of the issue, if any. */
43
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
44
+ }
45
+ /** The path segment interface of the issue. */
46
+ export interface PathSegment {
47
+ /** The key representing a path segment. */
48
+ readonly key: PropertyKey;
49
+ }
50
+ /** The Standard Schema types interface. */
51
+ export interface Types<Input = unknown, Output = Input> {
52
+ /** The input type of the schema. */
53
+ readonly input: Input;
54
+ /** The output type of the schema. */
55
+ readonly output: Output;
56
+ }
57
+ /** Infers the input type of a Standard Schema. */
58
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
59
+ /** Infers the output type of a Standard Schema. */
60
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
61
+ export {};
62
+ }
63
+ //#endregion
64
+ export { StandardSchemaV1 };
@@ -1,80 +1,29 @@
1
1
  //#region src/core/utils/directive-parser.d.ts
2
2
  /**
3
3
  * Directive parser utilities
4
- * AST-based parsing for GraphQL directive definitions
4
+ * AST-based parsing for GraphQL directive definitions using oxc-parser
5
5
  */
6
6
  interface ParsedDirective {
7
7
  name: string;
8
8
  locations: string[];
9
9
  args?: Record<string, {
10
10
  type: string;
11
- defaultValue?: any;
11
+ defaultValue?: string | number | boolean | null;
12
12
  }>;
13
13
  description?: string;
14
14
  isRepeatable?: boolean;
15
15
  }
16
16
  /**
17
- * Clean AST-based directive parser using oxc-parser
17
+ * Parse directives from a TypeScript/JavaScript file
18
18
  */
19
- declare class DirectiveParser {
20
- private oxc;
21
- init(): Promise<void>;
22
- /**
23
- * Parse directives from a TypeScript/JavaScript file
24
- */
25
- parseDirectives(fileContent: string, filePath: string): Promise<ParsedDirective[]>;
26
- /**
27
- * Extract directive definitions from AST
28
- */
29
- private extractDirectiveDefinitions;
30
- /**
31
- * Traverse AST nodes recursively
32
- */
33
- private traverse;
34
- /**
35
- * Check if node is a defineDirective call
36
- */
37
- private isDefineDirectiveCall;
38
- /**
39
- * Extract directive configuration from defineDirective call
40
- */
41
- private extractDirectiveFromCall;
42
- /**
43
- * Extract directive properties from object expression
44
- */
45
- private extractDirectiveFromObject;
46
- /**
47
- * Extract string literal value
48
- */
49
- private extractStringLiteral;
50
- /**
51
- * Extract boolean literal value
52
- */
53
- private extractBooleanLiteral;
54
- /**
55
- * Extract array of strings
56
- */
57
- private extractStringArray;
58
- /**
59
- * Extract arguments object
60
- */
61
- private extractArgsObject;
62
- /**
63
- * Extract argument configuration
64
- */
65
- private extractArgConfig;
66
- /**
67
- * Extract literal value (string, number, boolean)
68
- */
69
- private extractLiteralValue;
70
- }
19
+ declare function parseDirectivesFromFile(fileContent: string, filePath: string): ParsedDirective[];
71
20
  /**
72
21
  * Generate GraphQL directive schema from parsed directive
73
22
  */
74
23
  declare function generateDirectiveSchema(directive: ParsedDirective): string;
75
24
  /**
76
25
  * Directive file reference
77
- * Can be either { fullPath } or { specifier } (for GenImport compatibility)
26
+ * Accepts either { fullPath } or { specifier } form
78
27
  */
79
28
  type DirectiveFileRef = {
80
29
  fullPath: string;
@@ -82,13 +31,9 @@ type DirectiveFileRef = {
82
31
  specifier: string;
83
32
  };
84
33
  /**
85
- * Singleton instance for reuse
86
- */
87
- declare const directiveParser: DirectiveParser;
88
- /**
89
- * Generate GraphQL schema content from an array of parsed directives
90
- * Returns the schema string and optionally writes to buildDir/directives.graphql
34
+ * Generate GraphQL schema content from directive files
35
+ * Parses each file, extracts defineDirective calls, and produces SDL
91
36
  */
92
37
  declare function generateDirectiveSchemas(directives: DirectiveFileRef[], buildDir?: string): Promise<string | null>;
93
38
  //#endregion
94
- export { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
39
+ export { DirectiveFileRef, ParsedDirective, generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile };
@@ -1,170 +1,126 @@
1
+ import { parseSync } from "oxc-parser";
1
2
  //#region src/core/utils/directive-parser.ts
2
3
  /**
3
- * Clean AST-based directive parser using oxc-parser
4
+ * Directive parser utilities
5
+ * AST-based parsing for GraphQL directive definitions using oxc-parser
4
6
  */
5
- var DirectiveParser = class {
6
- oxc;
7
- async init() {
8
- if (!this.oxc) this.oxc = await import("oxc-parser");
9
- }
10
- /**
11
- * Parse directives from a TypeScript/JavaScript file
12
- */
13
- async parseDirectives(fileContent, filePath) {
14
- await this.init();
15
- try {
16
- const result = this.oxc.parseSync(filePath, fileContent, {
17
- lang: filePath.endsWith(".ts") ? "ts" : "js",
18
- sourceType: "module",
19
- astType: "ts"
20
- });
21
- if (result.errors.length > 0) return [];
22
- return this.extractDirectiveDefinitions(result.program);
23
- } catch {
24
- return [];
25
- }
26
- }
27
- /**
28
- * Extract directive definitions from AST
29
- */
30
- extractDirectiveDefinitions(program) {
31
- const directives = [];
32
- this.traverse(program, (node) => {
33
- if (this.isDefineDirectiveCall(node)) {
34
- const directive = this.extractDirectiveFromCall(node);
35
- if (directive) directives.push(directive);
7
+ function extractStringLiteral(node) {
8
+ if (node?.type === "Literal" && typeof node.value === "string") return node.value;
9
+ }
10
+ function extractBooleanLiteral(node) {
11
+ if (node?.type === "Literal" && typeof node.value === "boolean") return node.value;
12
+ }
13
+ function extractLiteralValue(node) {
14
+ if (node?.type === "Literal") return node.value ?? void 0;
15
+ }
16
+ function extractStringArray(node) {
17
+ if (node?.type !== "ArrayExpression") return [];
18
+ return (node.elements || []).filter((el) => el?.type === "Literal" && typeof el.value === "string").map((el) => el.value);
19
+ }
20
+ function extractArgConfig(node) {
21
+ if (node?.type !== "ObjectExpression") return null;
22
+ let type = "String";
23
+ let defaultValue;
24
+ for (const prop of node.properties || []) {
25
+ if (prop.type !== "Property" || prop.key?.type !== "Identifier") continue;
26
+ switch (prop.key.name) {
27
+ case "type": {
28
+ const typeValue = extractStringLiteral(prop.value);
29
+ if (typeValue) type = typeValue;
30
+ break;
36
31
  }
37
- });
38
- return directives;
39
- }
40
- /**
41
- * Traverse AST nodes recursively
42
- */
43
- traverse(node, visitor) {
44
- if (!node || typeof node !== "object") return;
45
- visitor(node);
46
- for (const key in node) {
47
- const child = node[key];
48
- if (Array.isArray(child)) child.forEach((item) => this.traverse(item, visitor));
49
- else if (child && typeof child === "object") this.traverse(child, visitor);
32
+ case "defaultValue":
33
+ defaultValue = extractLiteralValue(prop.value);
34
+ break;
50
35
  }
51
36
  }
52
- /**
53
- * Check if node is a defineDirective call
54
- */
55
- isDefineDirectiveCall(node) {
56
- return node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "defineDirective" && node.arguments?.length > 0;
57
- }
58
- /**
59
- * Extract directive configuration from defineDirective call
60
- */
61
- extractDirectiveFromCall(node) {
62
- const arg = node.arguments[0];
63
- if (arg?.type !== "ObjectExpression") return null;
64
- return this.extractDirectiveFromObject(arg);
37
+ return {
38
+ type,
39
+ ...defaultValue !== void 0 && { defaultValue }
40
+ };
41
+ }
42
+ function extractArgsObject(node) {
43
+ if (node?.type !== "ObjectExpression") return {};
44
+ const args = {};
45
+ for (const prop of node.properties || []) {
46
+ if (prop.type !== "Property" || prop.key?.type !== "Identifier") continue;
47
+ const argConfig = extractArgConfig(prop.value);
48
+ if (argConfig) args[prop.key.name] = argConfig;
65
49
  }
66
- /**
67
- * Extract directive properties from object expression
68
- */
69
- extractDirectiveFromObject(objNode) {
70
- let name = "";
71
- let locations = [];
72
- let args = {};
73
- let description;
74
- let isRepeatable;
75
- for (const prop of objNode.properties || []) {
76
- if (prop.type !== "Property" || prop.key?.type !== "Identifier") continue;
77
- switch (prop.key.name) {
78
- case "name":
79
- name = this.extractStringLiteral(prop.value) || "";
80
- break;
81
- case "locations":
82
- locations = this.extractStringArray(prop.value);
83
- break;
84
- case "args":
85
- args = this.extractArgsObject(prop.value);
86
- break;
87
- case "description":
88
- description = this.extractStringLiteral(prop.value);
89
- break;
90
- case "isRepeatable":
91
- isRepeatable = this.extractBooleanLiteral(prop.value);
92
- break;
93
- }
50
+ return args;
51
+ }
52
+ function extractDirectiveFromObject(objNode) {
53
+ let name = "";
54
+ let locations = [];
55
+ let args = {};
56
+ let description;
57
+ let isRepeatable;
58
+ for (const prop of objNode.properties || []) {
59
+ if (prop.type !== "Property" || prop.key?.type !== "Identifier") continue;
60
+ switch (prop.key.name) {
61
+ case "name":
62
+ name = extractStringLiteral(prop.value) || "";
63
+ break;
64
+ case "locations":
65
+ locations = extractStringArray(prop.value);
66
+ break;
67
+ case "args":
68
+ args = extractArgsObject(prop.value);
69
+ break;
70
+ case "description":
71
+ description = extractStringLiteral(prop.value);
72
+ break;
73
+ case "isRepeatable":
74
+ isRepeatable = extractBooleanLiteral(prop.value);
75
+ break;
94
76
  }
95
- return name && locations.length > 0 ? {
96
- name,
97
- locations,
98
- args,
99
- description,
100
- isRepeatable
101
- } : null;
102
- }
103
- /**
104
- * Extract string literal value
105
- */
106
- extractStringLiteral(node) {
107
- if (node?.type === "Literal" && typeof node.value === "string") return node.value;
108
- }
109
- /**
110
- * Extract boolean literal value
111
- */
112
- extractBooleanLiteral(node) {
113
- if (node?.type === "Literal" && typeof node.value === "boolean") return node.value;
114
- }
115
- /**
116
- * Extract array of strings
117
- */
118
- extractStringArray(node) {
119
- if (node?.type !== "ArrayExpression") return [];
120
- return (node.elements || []).filter((el) => el?.type === "Literal" && typeof el.value === "string").map((el) => el.value);
121
77
  }
122
- /**
123
- * Extract arguments object
124
- */
125
- extractArgsObject(node) {
126
- if (node?.type !== "ObjectExpression") return {};
127
- const args = {};
128
- for (const prop of node.properties || []) {
129
- if (prop.type !== "Property" || prop.key?.type !== "Identifier") continue;
130
- const argName = prop.key.name;
131
- const argConfig = this.extractArgConfig(prop.value);
132
- if (argConfig) args[argName] = argConfig;
133
- }
134
- return args;
78
+ return name && locations.length > 0 ? {
79
+ name,
80
+ locations,
81
+ args,
82
+ description,
83
+ isRepeatable
84
+ } : null;
85
+ }
86
+ function traverse(node, visitor) {
87
+ if (!node || typeof node !== "object") return;
88
+ visitor(node);
89
+ for (const key in node) {
90
+ const child = node[key];
91
+ if (Array.isArray(child)) child.forEach((item) => traverse(item, visitor));
92
+ else if (child && typeof child === "object") traverse(child, visitor);
135
93
  }
136
- /**
137
- * Extract argument configuration
138
- */
139
- extractArgConfig(node) {
140
- if (node?.type !== "ObjectExpression") return null;
141
- let type = "String";
142
- let defaultValue;
143
- for (const prop of node.properties || []) {
144
- if (prop.type !== "Property" || prop.key?.type !== "Identifier") continue;
145
- switch (prop.key.name) {
146
- case "type": {
147
- const typeValue = this.extractStringLiteral(prop.value);
148
- if (typeValue) type = typeValue;
149
- break;
94
+ }
95
+ function isDefineDirectiveCall(node) {
96
+ return node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "defineDirective" && (node.arguments?.length ?? 0) > 0;
97
+ }
98
+ /**
99
+ * Parse directives from a TypeScript/JavaScript file
100
+ */
101
+ function parseDirectivesFromFile(fileContent, filePath) {
102
+ try {
103
+ const result = parseSync(filePath, fileContent, {
104
+ lang: filePath.endsWith(".ts") ? "ts" : "js",
105
+ sourceType: "module",
106
+ astType: "ts"
107
+ });
108
+ if (result.errors.length > 0) return [];
109
+ const directives = [];
110
+ traverse(result.program, (node) => {
111
+ if (isDefineDirectiveCall(node)) {
112
+ const arg = node.arguments[0];
113
+ if (arg?.type === "ObjectExpression") {
114
+ const directive = extractDirectiveFromObject(arg);
115
+ if (directive) directives.push(directive);
150
116
  }
151
- case "defaultValue":
152
- defaultValue = this.extractLiteralValue(prop.value);
153
- break;
154
117
  }
155
- }
156
- return {
157
- type,
158
- ...defaultValue !== void 0 && { defaultValue }
159
- };
160
- }
161
- /**
162
- * Extract literal value (string, number, boolean)
163
- */
164
- extractLiteralValue(node) {
165
- if (node?.type === "Literal") return node.value;
118
+ });
119
+ return directives;
120
+ } catch {
121
+ return [];
166
122
  }
167
- };
123
+ }
168
124
  /**
169
125
  * Generate GraphQL directive schema from parsed directive
170
126
  */
@@ -179,19 +135,12 @@ function generateDirectiveSchema(directive) {
179
135
  const locations = directive.locations.join(" | ");
180
136
  return `directive @${directive.name}${args} on ${locations}`;
181
137
  }
182
- /**
183
- * Get the file path from a directive reference
184
- */
185
138
  function getFilePath(ref) {
186
139
  return "fullPath" in ref ? ref.fullPath : ref.specifier;
187
140
  }
188
141
  /**
189
- * Singleton instance for reuse
190
- */
191
- const directiveParser = new DirectiveParser();
192
- /**
193
- * Generate GraphQL schema content from an array of parsed directives
194
- * Returns the schema string and optionally writes to buildDir/directives.graphql
142
+ * Generate GraphQL schema content from directive files
143
+ * Parses each file, extracts defineDirective calls, and produces SDL
195
144
  */
196
145
  async function generateDirectiveSchemas(directives, buildDir) {
197
146
  if (directives.length === 0) return null;
@@ -200,8 +149,7 @@ async function generateDirectiveSchemas(directives, buildDir) {
200
149
  const allParsedDirectives = [];
201
150
  for (const directive of directives) try {
202
151
  const filePath = getFilePath(directive);
203
- const content = fs.readFileSync(filePath, "utf-8");
204
- const parsed = await directiveParser.parseDirectives(content, filePath);
152
+ const parsed = parseDirectivesFromFile(fs.readFileSync(filePath, "utf-8"), filePath);
205
153
  allParsedDirectives.push(...parsed);
206
154
  } catch {}
207
155
  if (allParsedDirectives.length === 0) return null;
@@ -214,4 +162,4 @@ async function generateDirectiveSchemas(directives, buildDir) {
214
162
  return schemaContent;
215
163
  }
216
164
  //#endregion
217
- export { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
165
+ export { generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile };
@@ -16,9 +16,5 @@ declare function writeFileIfChanged(path: string, content: string): boolean;
16
16
  * Ensure directory exists
17
17
  */
18
18
  declare function ensureDir(path: string): void;
19
- /**
20
- * Read file safely, returns undefined if file doesn't exist
21
- */
22
- declare function readFileSafe(path: string): string | undefined;
23
19
  //#endregion
24
- export { ensureDir, readFileSafe, writeFile, writeFileIfChanged };
20
+ export { ensureDir, writeFile, writeFileIfChanged };
@@ -31,15 +31,5 @@ function writeFileIfChanged(path, content) {
31
31
  function ensureDir(path) {
32
32
  mkdirSync(path, { recursive: true });
33
33
  }
34
- /**
35
- * Read file safely, returns undefined if file doesn't exist
36
- */
37
- function readFileSafe(path) {
38
- try {
39
- return readFileSync(path, "utf-8");
40
- } catch {
41
- return;
42
- }
43
- }
44
34
  //#endregion
45
- export { ensureDir, readFileSafe, writeFile, writeFileIfChanged };
35
+ export { ensureDir, writeFile, writeFileIfChanged };
@@ -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,7 +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
- 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 };
@@ -14,23 +14,5 @@ function createLogger(tag = LOG_TAG) {
14
14
  debug: (message, ...args) => logger.debug(message, ...args)
15
15
  };
16
16
  }
17
- /**
18
- * Default logger instance
19
- */
20
- const defaultLogger = createLogger();
21
- /**
22
- * Create a silent logger (no output)
23
- * Useful for testing or when logging should be suppressed
24
- */
25
- function createSilentLogger() {
26
- const noop = () => {};
27
- return {
28
- info: noop,
29
- warn: noop,
30
- error: noop,
31
- success: noop,
32
- debug: noop
33
- };
34
- }
35
17
  //#endregion
36
- 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
  *
@@ -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_ };