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.
- package/README.md +1 -1
- package/dist/cli/adapter.d.mts +0 -3
- package/dist/cli/adapter.mjs +6 -29
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +3 -1
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/server/graphql-handler.mjs +2 -1
- package/dist/cli/server/watcher.mjs +1 -1
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -445
- package/dist/core/codegen/file-header.d.mts +7 -0
- package/dist/core/codegen/file-header.mjs +12 -0
- package/dist/core/codegen/index.d.mts +7 -5
- package/dist/core/codegen/index.mjs +7 -5
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +65 -70
- package/dist/core/codegen/server-type-helpers.d.mts +14 -0
- package/dist/core/codegen/server-type-helpers.mjs +76 -0
- package/dist/core/codegen/server.d.mts +1 -15
- package/dist/core/codegen/server.mjs +15 -105
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
- package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
- package/dist/core/constants.d.mts +5 -53
- package/dist/core/constants.mjs +13 -54
- package/dist/core/create-config.d.mts +31 -0
- package/dist/core/create-config.mjs +42 -0
- package/dist/core/debug/index.d.mts +2 -2
- package/dist/core/debug/index.mjs +2 -2
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +1 -1
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +59 -89
- package/dist/core/index.d.mts +22 -17
- package/dist/core/index.mjs +19 -15
- package/dist/core/manifest.mjs +3 -1
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +1 -145
- package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
- package/dist/core/pubsub/memory-pubsub.mjs +146 -0
- package/dist/core/scanning/ast-scanner.mjs +4 -2
- package/dist/core/scanning/directives.mjs +2 -3
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +1 -1
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -3
- package/dist/core/scanning/resolvers.mjs +8 -9
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -24
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -2
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -2
- package/dist/core/server/apollo.d.mts +20 -0
- package/dist/core/server/apollo.mjs +54 -0
- package/dist/core/server/index.d.mts +4 -2
- package/dist/core/server/index.mjs +3 -2
- package/dist/core/server/types.d.mts +7 -14
- package/dist/core/server/types.mjs +15 -1
- package/dist/core/server/yoga.d.mts +1 -7
- package/dist/core/server/yoga.mjs +4 -13
- package/dist/core/types/adapter.d.mts +4 -39
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -166
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -11
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -5
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -19
- package/dist/core/utils/ofetch-templates.mjs +3 -4
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -44
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- package/dist/core/watcher/create-watcher.d.mts +103 -0
- package/dist/core/watcher/create-watcher.mjs +143 -0
- package/dist/core/watcher/index.d.mts +2 -107
- package/dist/core/watcher/index.mjs +1 -139
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +7 -6
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/nitro/adapter.d.mts +6 -10
- package/dist/nitro/adapter.mjs +12 -42
- package/dist/nitro/codegen/client-types.d.mts +12 -0
- package/dist/nitro/codegen/client-types.mjs +73 -0
- package/dist/nitro/codegen/external-types.d.mts +8 -0
- package/dist/nitro/codegen/external-types.mjs +47 -0
- package/dist/nitro/codegen/index.d.mts +4 -0
- package/dist/nitro/codegen/index.mjs +4 -0
- package/dist/nitro/codegen/server-types.d.mts +12 -0
- package/dist/nitro/codegen/server-types.mjs +81 -0
- package/dist/nitro/defaults.d.mts +28 -0
- package/dist/nitro/defaults.mjs +34 -0
- package/dist/nitro/index.d.mts +11 -3
- package/dist/nitro/index.mjs +1 -1
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +13 -9
- package/dist/nitro/rollup.mjs +4 -3
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
- package/dist/nitro/routes/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +16 -55
- package/dist/nitro/routes/debug.d.mts +1 -1
- package/dist/nitro/routes/debug.mjs +1 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
- package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
- package/dist/nitro/routes/graphql-yoga.mjs +7 -5
- package/dist/nitro/routes/health.mjs +22 -24
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +30 -58
- package/dist/nitro/setup/file-watcher.mjs +6 -4
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -22
- package/dist/nitro/setup/rollup-integration.mjs +32 -1
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -58
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- package/dist/nitro/setup/type-generation.d.mts +13 -0
- package/dist/nitro/setup/type-generation.mjs +16 -0
- package/dist/nitro/setup.d.mts +4 -3
- package/dist/nitro/setup.mjs +87 -74
- package/dist/nitro/state.d.mts +32 -0
- package/dist/nitro/state.mjs +58 -0
- package/dist/nitro/types/augmentation.d.mts +59 -0
- package/dist/nitro/types/augmentation.mjs +1 -0
- package/dist/nitro/types/config.d.mts +327 -0
- package/dist/nitro/types/config.mjs +1 -0
- package/dist/nitro/types/define.d.mts +13 -0
- package/dist/nitro/types/define.mjs +1 -0
- package/dist/nitro/types/index.d.mts +10 -0
- package/dist/nitro/types/index.mjs +1 -0
- package/dist/nitro/virtual/debug-info.d.mts +9 -0
- package/dist/nitro/virtual/debug-info.mjs +35 -0
- package/dist/nitro/virtual/graphql-config.d.mts +9 -0
- package/dist/nitro/virtual/graphql-config.mjs +33 -0
- package/dist/nitro/virtual/index.d.mts +25 -0
- package/dist/nitro/virtual/index.mjs +45 -0
- package/dist/nitro/virtual/module-config.d.mts +9 -0
- package/dist/nitro/virtual/module-config.mjs +10 -0
- package/dist/nitro/virtual/pubsub.d.mts +9 -0
- package/dist/nitro/virtual/pubsub.mjs +17 -0
- package/dist/nitro/virtual/server-directives.d.mts +9 -0
- package/dist/nitro/virtual/server-directives.mjs +12 -0
- package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
- package/dist/nitro/virtual/server-resolvers.mjs +17 -0
- package/dist/nitro/virtual/server-schemas.d.mts +9 -0
- package/dist/nitro/virtual/server-schemas.mjs +31 -0
- package/dist/nitro/virtual/stubs.d.mts +42 -10
- package/dist/nitro/virtual/stubs.mjs +0 -5
- package/dist/nitro/virtual/utils.d.mts +15 -0
- package/dist/nitro/virtual/utils.mjs +26 -0
- package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
- package/dist/nitro/virtual/validation-schemas.mjs +33 -0
- package/native/index.js +52 -52
- package/package.json +15 -15
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -5
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -29
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -76
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -171
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -55
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -190
- /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?:
|
|
11
|
+
defaultValue?: string | number | boolean | null;
|
|
12
12
|
}>;
|
|
13
13
|
description?: string;
|
|
14
14
|
isRepeatable?: boolean;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Parse directives from a TypeScript/JavaScript file
|
|
18
18
|
*/
|
|
19
|
-
declare
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
4
|
+
* Directive parser utilities
|
|
5
|
+
* AST-based parsing for GraphQL directive definitions using oxc-parser
|
|
4
6
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
158
|
-
|
|
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
|
-
*
|
|
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
|
|
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 {
|
|
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,
|
|
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,
|
|
35
|
+
export { ensureDir, writeFile, writeFileIfChanged };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { DirectiveFileRef,
|
|
1
|
+
import { DirectiveFileRef, ParsedDirective, generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile } from "./directive-parser.mjs";
|
|
2
2
|
import { MaskErrorOptions, createDefaultMaskError } from "./errors.mjs";
|
|
3
|
-
import { ensureDir,
|
|
3
|
+
import { ensureDir, writeFile, writeFileIfChanged } from "./file-io.mjs";
|
|
4
4
|
import { getImportId, relativeWithDot } from "./imports.mjs";
|
|
5
|
-
import { createLogger
|
|
5
|
+
import { createLogger } from "./logger.mjs";
|
|
6
6
|
import { OfetchTemplateOptions, generateOfetchTemplate } from "./ofetch-templates.mjs";
|
|
7
|
-
|
|
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,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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 {
|
|
45
|
+
export { existsSync_, exit, getCwd, mkdirSync_, onSignal, pathToFileURL, readFileSync_, writeFileSync_ };
|