@soda-gql/sdk 0.11.4 → 0.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -2
- package/dist/index.cjs +67 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +59 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +67 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://badge.fury.io/js/@soda-gql%2Fsdk)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
Programmatic API for soda-gql prebuild operations.
|
|
6
|
+
Programmatic API for soda-gql prebuild and codegen operations.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -18,7 +18,8 @@ and build plugins to execute artifact generation without invoking the CLI.
|
|
|
18
18
|
|
|
19
19
|
**Key Features:**
|
|
20
20
|
|
|
21
|
-
- Synchronous and asynchronous build APIs
|
|
21
|
+
- Synchronous and asynchronous build APIs (`prebuild`, `prebuildAsync`)
|
|
22
|
+
- Programmatic code generation from GraphQL schemas (`codegenAsync`)
|
|
22
23
|
- Optional context transformation for modifying composer context
|
|
23
24
|
- Configurable build options (force rebuild, evaluator ID, entrypoints override)
|
|
24
25
|
- Comprehensive error handling with typed Result
|
|
@@ -77,6 +78,29 @@ const result = await prebuildAsync({
|
|
|
77
78
|
});
|
|
78
79
|
```
|
|
79
80
|
|
|
81
|
+
### Code Generation
|
|
82
|
+
|
|
83
|
+
Generate GraphQL runtime modules programmatically:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { codegenAsync } from "@soda-gql/sdk";
|
|
87
|
+
|
|
88
|
+
// Generate from config file
|
|
89
|
+
const result = await codegenAsync({
|
|
90
|
+
configPath: "./soda-gql.config.ts",
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (result.isOk()) {
|
|
94
|
+
console.log("Generated:", result.value.outPath);
|
|
95
|
+
console.log("Schemas:", Object.keys(result.value.schemas));
|
|
96
|
+
} else {
|
|
97
|
+
console.error("Codegen failed:", result.error);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Without explicit config path (will search for config file)
|
|
101
|
+
const autoResult = await codegenAsync();
|
|
102
|
+
```
|
|
103
|
+
|
|
80
104
|
## API Reference
|
|
81
105
|
|
|
82
106
|
### `prebuild(options: PrebuildOptions): Result<PrebuildResult, PrebuildError>`
|
|
@@ -87,6 +111,11 @@ Synchronously builds GraphQL artifacts based on the provided configuration.
|
|
|
87
111
|
|
|
88
112
|
Asynchronously builds GraphQL artifacts. Preferred for build plugins and tools.
|
|
89
113
|
|
|
114
|
+
### `codegenAsync(options?: CodegenSdkOptions): Promise<Result<CodegenSdkResult, CodegenSdkError>>`
|
|
115
|
+
|
|
116
|
+
Generates GraphQL runtime modules from schemas defined in config. Wraps the CLI's `codegen` command
|
|
117
|
+
for programmatic use.
|
|
118
|
+
|
|
90
119
|
### Types
|
|
91
120
|
|
|
92
121
|
#### `PrebuildOptions`
|
|
@@ -119,6 +148,34 @@ type ContextTransformer = (
|
|
|
119
148
|
) => Record<string, unknown>;
|
|
120
149
|
```
|
|
121
150
|
|
|
151
|
+
#### `CodegenSdkOptions`
|
|
152
|
+
|
|
153
|
+
| Property | Type | Required | Description |
|
|
154
|
+
| ------------ | -------- | -------- | --------------------------------------------------- |
|
|
155
|
+
| `configPath` | `string` | No | Path to soda-gql config file (searches if omitted) |
|
|
156
|
+
|
|
157
|
+
#### `CodegenSdkResult`
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
interface CodegenSdkResult {
|
|
161
|
+
schemas: Record<string, {
|
|
162
|
+
schemaHash: string;
|
|
163
|
+
objects: number;
|
|
164
|
+
enums: number;
|
|
165
|
+
inputs: number;
|
|
166
|
+
unions: number;
|
|
167
|
+
}>;
|
|
168
|
+
outPath: string;
|
|
169
|
+
internalPath: string;
|
|
170
|
+
injectsPath: string;
|
|
171
|
+
cjsPath: string;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `CodegenSdkError`
|
|
176
|
+
|
|
177
|
+
Union type: `ConfigError | CodegenError`
|
|
178
|
+
|
|
122
179
|
## Session Lifecycle
|
|
123
180
|
|
|
124
181
|
`prebuild` and `prebuildAsync` internally create a BuilderSession and always call `dispose()` after
|
|
@@ -152,6 +209,7 @@ may result in incorrect context being applied.
|
|
|
152
209
|
## Related Packages
|
|
153
210
|
|
|
154
211
|
- [@soda-gql/builder](../builder) - Core build system
|
|
212
|
+
- [@soda-gql/codegen](../codegen) - Code generation from GraphQL schemas
|
|
155
213
|
- [@soda-gql/config](../config) - Configuration loading
|
|
156
214
|
- [@soda-gql/core](../core) - GraphQL composition primitives
|
|
157
215
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,72 @@
|
|
|
1
|
-
let
|
|
1
|
+
let node_path = require("node:path");
|
|
2
|
+
let __soda_gql_codegen = require("@soda-gql/codegen");
|
|
2
3
|
let __soda_gql_config = require("@soda-gql/config");
|
|
3
|
-
let __soda_gql_core__internal = require("@soda-gql/core/_internal");
|
|
4
4
|
let neverthrow = require("neverthrow");
|
|
5
|
+
let __soda_gql_builder = require("@soda-gql/builder");
|
|
6
|
+
let __soda_gql_core__internal = require("@soda-gql/core/_internal");
|
|
7
|
+
|
|
8
|
+
//#region packages/sdk/src/codegen.ts
|
|
9
|
+
/**
|
|
10
|
+
* Codegen API for programmatic code generation from GraphQL schemas.
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Generate GraphQL runtime module asynchronously from a config file.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This function loads the soda-gql config, validates the schemas configuration,
|
|
18
|
+
* and generates TypeScript/CommonJS modules from GraphQL schemas.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Codegen options including optional config path
|
|
21
|
+
* @returns Promise resolving to Result containing the generation result or an error
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = await codegenAsync({ configPath: './soda-gql.config.ts' });
|
|
26
|
+
* if (result.isOk()) {
|
|
27
|
+
* console.log('Generated:', result.value.outPath);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Without explicit config path (will search for config file)
|
|
34
|
+
* const result = await codegenAsync();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const codegenAsync = async (options = {}) => {
|
|
38
|
+
const { configPath } = options;
|
|
39
|
+
const configResult = (0, __soda_gql_config.loadConfig)(configPath);
|
|
40
|
+
if (configResult.isErr()) {
|
|
41
|
+
return (0, neverthrow.err)(configResult.error);
|
|
42
|
+
}
|
|
43
|
+
const config = configResult.value;
|
|
44
|
+
if (!config.schemas || Object.keys(config.schemas).length === 0) {
|
|
45
|
+
return (0, neverthrow.err)({
|
|
46
|
+
code: "CONFIG_VALIDATION_FAILED",
|
|
47
|
+
message: "schemas configuration is required in soda-gql config"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const outPath = (0, node_path.join)(config.outdir, "index.ts");
|
|
51
|
+
const result = await (0, __soda_gql_codegen.runCodegen)({
|
|
52
|
+
schemas: config.schemas,
|
|
53
|
+
outPath,
|
|
54
|
+
format: "human",
|
|
55
|
+
importExtension: config.styles.importExtension
|
|
56
|
+
});
|
|
57
|
+
if (result.isErr()) {
|
|
58
|
+
return (0, neverthrow.err)(result.error);
|
|
59
|
+
}
|
|
60
|
+
return (0, neverthrow.ok)({
|
|
61
|
+
schemas: result.value.schemas,
|
|
62
|
+
outPath: result.value.outPath,
|
|
63
|
+
internalPath: result.value.internalPath,
|
|
64
|
+
injectsPath: result.value.injectsPath,
|
|
65
|
+
cjsPath: result.value.cjsPath
|
|
66
|
+
});
|
|
67
|
+
};
|
|
5
68
|
|
|
69
|
+
//#endregion
|
|
6
70
|
//#region packages/sdk/src/prebuild.ts
|
|
7
71
|
/**
|
|
8
72
|
* Prebuild API for programmatic artifact generation.
|
|
@@ -108,6 +172,7 @@ const prebuildAsync = async (options) => {
|
|
|
108
172
|
};
|
|
109
173
|
|
|
110
174
|
//#endregion
|
|
175
|
+
exports.codegenAsync = codegenAsync;
|
|
111
176
|
exports.prebuild = prebuild;
|
|
112
177
|
exports.prebuildAsync = prebuildAsync;
|
|
113
178
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/prebuild.ts"],"sourcesContent":["/**\n * Prebuild API for programmatic artifact generation.\n * @module\n */\n\nimport { type BuilderArtifact, type BuilderError, createBuilderSession } from \"@soda-gql/builder\";\nimport { type ConfigError, loadConfig } from \"@soda-gql/config\";\nimport { type ContextTransformer, clearContextTransformer, setContextTransformer } from \"@soda-gql/core/_internal\";\nimport { err, type Result } from \"neverthrow\";\n\nexport type { ContextTransformer };\n\n/**\n * Error type for prebuild operations.\n * Can be either a config loading error or a builder error.\n */\nexport type PrebuildError = ConfigError | BuilderError;\n\n/**\n * Options for prebuild functions.\n */\nexport interface PrebuildOptions {\n /** Path to soda-gql config file */\n configPath: string;\n /** Optional context transformer to modify composer context */\n contextTransformer?: ContextTransformer;\n /** Unique identifier for this evaluator instance (default: \"default\") */\n evaluatorId?: string;\n /** Override entrypoints from config.include */\n entrypointsOverride?: readonly string[] | ReadonlySet<string>;\n /** Force rebuild even if no changes detected */\n force?: boolean;\n}\n\n/**\n * Result of prebuild operations.\n */\nexport interface PrebuildResult {\n artifact: BuilderArtifact;\n}\n\n/**\n * Build artifact synchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = prebuild({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuild = (options: PrebuildOptions): Result<PrebuildResult, PrebuildError> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = session.build({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n\n/**\n * Build artifact asynchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Promise resolving to Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuildAsync = async (options: PrebuildOptions): Promise<Result<PrebuildResult, PrebuildError>> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path (sync - no async version available)\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = await session.buildAsync({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/codegen.ts","../src/prebuild.ts"],"sourcesContent":["/**\n * Codegen API for programmatic code generation from GraphQL schemas.\n * @module\n */\n\nimport { join } from \"node:path\";\nimport type { CodegenError, CodegenSuccess } from \"@soda-gql/codegen\";\nimport { runCodegen } from \"@soda-gql/codegen\";\nimport type { ConfigError } from \"@soda-gql/config\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport { err, ok, type Result } from \"neverthrow\";\n\n/**\n * Error type for codegen operations.\n * Can be either a config loading error or a codegen error.\n */\nexport type CodegenSdkError = ConfigError | CodegenError;\n\n/**\n * Options for codegenAsync function.\n */\nexport interface CodegenSdkOptions {\n /** Path to soda-gql config file (optional, will search if not provided) */\n configPath?: string;\n}\n\n/**\n * Result of codegen operations.\n */\nexport interface CodegenSdkResult {\n /** Generated schema information */\n schemas: CodegenSuccess[\"schemas\"];\n /** Path to generated TypeScript module */\n outPath: string;\n /** Path to internal module */\n internalPath: string;\n /** Path to injects module */\n injectsPath: string;\n /** Path to CommonJS bundle */\n cjsPath: string;\n}\n\n/**\n * Generate GraphQL runtime module asynchronously from a config file.\n *\n * @remarks\n * This function loads the soda-gql config, validates the schemas configuration,\n * and generates TypeScript/CommonJS modules from GraphQL schemas.\n *\n * @param options - Codegen options including optional config path\n * @returns Promise resolving to Result containing the generation result or an error\n *\n * @example\n * ```typescript\n * const result = await codegenAsync({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log('Generated:', result.value.outPath);\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Without explicit config path (will search for config file)\n * const result = await codegenAsync();\n * ```\n */\nexport const codegenAsync = async (options: CodegenSdkOptions = {}): Promise<Result<CodegenSdkResult, CodegenSdkError>> => {\n const { configPath } = options;\n\n // Load config from file path\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n // Validate schemas config exists\n if (!config.schemas || Object.keys(config.schemas).length === 0) {\n return err({\n code: \"CONFIG_VALIDATION_FAILED\",\n message: \"schemas configuration is required in soda-gql config\",\n });\n }\n\n // Derive output path from outdir (already absolute)\n const outPath = join(config.outdir, \"index.ts\");\n\n // Run codegen (config.schemas is already resolved by loadConfig)\n const result = await runCodegen({\n schemas: config.schemas,\n outPath,\n format: \"human\",\n importExtension: config.styles.importExtension,\n });\n\n if (result.isErr()) {\n return err(result.error);\n }\n\n return ok({\n schemas: result.value.schemas,\n outPath: result.value.outPath,\n internalPath: result.value.internalPath,\n injectsPath: result.value.injectsPath,\n cjsPath: result.value.cjsPath,\n });\n};\n","/**\n * Prebuild API for programmatic artifact generation.\n * @module\n */\n\nimport { type BuilderArtifact, type BuilderError, createBuilderSession } from \"@soda-gql/builder\";\nimport { type ConfigError, loadConfig } from \"@soda-gql/config\";\nimport { type ContextTransformer, clearContextTransformer, setContextTransformer } from \"@soda-gql/core/_internal\";\nimport { err, type Result } from \"neverthrow\";\n\nexport type { ContextTransformer };\n\n/**\n * Error type for prebuild operations.\n * Can be either a config loading error or a builder error.\n */\nexport type PrebuildError = ConfigError | BuilderError;\n\n/**\n * Options for prebuild functions.\n */\nexport interface PrebuildOptions {\n /** Path to soda-gql config file */\n configPath: string;\n /** Optional context transformer to modify composer context */\n contextTransformer?: ContextTransformer;\n /** Unique identifier for this evaluator instance (default: \"default\") */\n evaluatorId?: string;\n /** Override entrypoints from config.include */\n entrypointsOverride?: readonly string[] | ReadonlySet<string>;\n /** Force rebuild even if no changes detected */\n force?: boolean;\n}\n\n/**\n * Result of prebuild operations.\n */\nexport interface PrebuildResult {\n artifact: BuilderArtifact;\n}\n\n/**\n * Build artifact synchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = prebuild({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuild = (options: PrebuildOptions): Result<PrebuildResult, PrebuildError> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = session.build({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n\n/**\n * Build artifact asynchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Promise resolving to Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuildAsync = async (options: PrebuildOptions): Promise<Result<PrebuildResult, PrebuildError>> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path (sync - no async version available)\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = await session.buildAsync({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,eAAe,OAAO,UAA6B,EAAE,KAAyD;CACzH,MAAM,EAAE,eAAe;CAGvB,MAAM,iDAA0B,WAAW;AAC3C,KAAI,aAAa,OAAO,EAAE;AACxB,6BAAW,aAAa,MAAM;;CAEhC,MAAM,SAAS,aAAa;AAG5B,KAAI,CAAC,OAAO,WAAW,OAAO,KAAK,OAAO,QAAQ,CAAC,WAAW,GAAG;AAC/D,6BAAW;GACT,MAAM;GACN,SAAS;GACV,CAAC;;CAIJ,MAAM,8BAAe,OAAO,QAAQ,WAAW;CAG/C,MAAM,SAAS,yCAAiB;EAC9B,SAAS,OAAO;EAChB;EACA,QAAQ;EACR,iBAAiB,OAAO,OAAO;EAChC,CAAC;AAEF,KAAI,OAAO,OAAO,EAAE;AAClB,6BAAW,OAAO,MAAM;;AAG1B,2BAAU;EACR,SAAS,OAAO,MAAM;EACtB,SAAS,OAAO,MAAM;EACtB,cAAc,OAAO,MAAM;EAC3B,aAAa,OAAO,MAAM;EAC1B,SAAS,OAAO,MAAM;EACvB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtCJ,MAAa,YAAY,YAAoE;CAC3F,MAAM,EAAE,YAAY,oBAAoB,aAAa,qBAAqB,UAAU;CAGpF,MAAM,iDAA0B,WAAW;AAC3C,KAAI,aAAa,OAAO,EAAE;AACxB,6BAAW,aAAa,MAAM;;CAEhC,MAAM,SAAS,aAAa;CAE5B,MAAM,uDAA+B;EAAE;EAAQ;EAAa;EAAqB,CAAC;AAElF,KAAI;AACF,MAAI,oBAAoB;AACtB,wDAAsB,mBAAmB;;EAE3C,MAAM,SAAS,QAAQ,MAAM,EAAE,OAAO,CAAC;AACvC,SAAO,OAAO,KAAK,cAAc,EAAE,UAAU,EAAE;WACvC;AACR,0DAAyB;AACzB,UAAQ,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BrB,MAAa,gBAAgB,OAAO,YAA6E;CAC/G,MAAM,EAAE,YAAY,oBAAoB,aAAa,qBAAqB,UAAU;CAGpF,MAAM,iDAA0B,WAAW;AAC3C,KAAI,aAAa,OAAO,EAAE;AACxB,6BAAW,aAAa,MAAM;;CAEhC,MAAM,SAAS,aAAa;CAE5B,MAAM,uDAA+B;EAAE;EAAQ;EAAa;EAAqB,CAAC;AAElF,KAAI;AACF,MAAI,oBAAoB;AACtB,wDAAsB,mBAAmB;;EAE3C,MAAM,SAAS,MAAM,QAAQ,WAAW,EAAE,OAAO,CAAC;AAClD,SAAO,OAAO,KAAK,cAAc,EAAE,UAAU,EAAE;WACvC;AACR,0DAAyB;AACzB,UAAQ,SAAS"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CodegenError, CodegenSuccess } from "@soda-gql/codegen";
|
|
2
2
|
import { ConfigError } from "@soda-gql/config";
|
|
3
|
-
import { ContextTransformer } from "@soda-gql/core/_internal";
|
|
4
3
|
import { Result } from "neverthrow";
|
|
4
|
+
import { BuilderArtifact, BuilderError } from "@soda-gql/builder";
|
|
5
|
+
import { ContextTransformer } from "@soda-gql/core/_internal";
|
|
5
6
|
|
|
6
|
-
//#region packages/sdk/src/
|
|
7
|
+
//#region packages/sdk/src/codegen.d.ts
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Error type for codegen operations.
|
|
11
|
+
* Can be either a config loading error or a codegen error.
|
|
12
|
+
*/
|
|
13
|
+
type CodegenSdkError = ConfigError | CodegenError;
|
|
14
|
+
/**
|
|
15
|
+
* Options for codegenAsync function.
|
|
16
|
+
*/
|
|
17
|
+
interface CodegenSdkOptions {
|
|
18
|
+
/** Path to soda-gql config file (optional, will search if not provided) */
|
|
19
|
+
configPath?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of codegen operations.
|
|
23
|
+
*/
|
|
24
|
+
interface CodegenSdkResult {
|
|
25
|
+
/** Generated schema information */
|
|
26
|
+
schemas: CodegenSuccess["schemas"];
|
|
27
|
+
/** Path to generated TypeScript module */
|
|
28
|
+
outPath: string;
|
|
29
|
+
/** Path to internal module */
|
|
30
|
+
internalPath: string;
|
|
31
|
+
/** Path to injects module */
|
|
32
|
+
injectsPath: string;
|
|
33
|
+
/** Path to CommonJS bundle */
|
|
34
|
+
cjsPath: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate GraphQL runtime module asynchronously from a config file.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* This function loads the soda-gql config, validates the schemas configuration,
|
|
41
|
+
* and generates TypeScript/CommonJS modules from GraphQL schemas.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Codegen options including optional config path
|
|
44
|
+
* @returns Promise resolving to Result containing the generation result or an error
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const result = await codegenAsync({ configPath: './soda-gql.config.ts' });
|
|
49
|
+
* if (result.isOk()) {
|
|
50
|
+
* console.log('Generated:', result.value.outPath);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Without explicit config path (will search for config file)
|
|
57
|
+
* const result = await codegenAsync();
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare const codegenAsync: (options?: CodegenSdkOptions) => Promise<Result<CodegenSdkResult, CodegenSdkError>>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region packages/sdk/src/prebuild.d.ts
|
|
8
63
|
/**
|
|
9
64
|
* Error type for prebuild operations.
|
|
10
65
|
* Can be either a config loading error or a builder error.
|
|
@@ -86,5 +141,5 @@ declare const prebuild: (options: PrebuildOptions) => Result<PrebuildResult, Pre
|
|
|
86
141
|
*/
|
|
87
142
|
declare const prebuildAsync: (options: PrebuildOptions) => Promise<Result<PrebuildResult, PrebuildError>>;
|
|
88
143
|
//#endregion
|
|
89
|
-
export { type ContextTransformer, type PrebuildError, type PrebuildOptions, type PrebuildResult, prebuild, prebuildAsync };
|
|
144
|
+
export { type CodegenSdkError, type CodegenSdkOptions, type CodegenSdkResult, type ContextTransformer, type PrebuildError, type PrebuildOptions, type PrebuildResult, codegenAsync, prebuild, prebuildAsync };
|
|
90
145
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/prebuild.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/codegen.ts","../src/prebuild.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAgBA;AAKA;AAQA;AAqCA;AAA4C,KAlDhC,eAAA,GAAkB,WAkDc,GAlDA,YAkDA;;;;AAAyB,UA7CpD,iBAAA,CA6CoD;EAAO;;;;AClD5E;AAKA;AAgBiB,UDRA,gBAAA,CCSL;EA6BC;EAAqB,OAAA,EDpCvB,cCoCuB,CAAA,SAAA,CAAA;EAAyB;EAAgB,OAAA,EAAA,MAAA;EAAvB;EAAM,YAAA,EAAA,MAAA;EAkD7C;EAAgC,WAAA,EAAA,MAAA;EAAiC;EAAgB,OAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;cDnDjF,yBAA+B,sBAAyB,QAAQ,OAAO,kBAAkB;;;AArCtG;AAqCA;;;AAAsG,KClD1F,aAAA,GAAgB,WDkD0E,GClD5D,YDkD4D;;;;UC7CrF,eAAA;;;EALL;EAKK,kBAAe,CAAA,EAIT,kBAAA;EAYN;EA8BJ,WAsBZ,CAAA,EAAA,MAAA;EAtBiC;EAAyB,mBAAA,CAAA,EAAA,SAAA,MAAA,EAAA,GAtCf,WAsCe,CAAA,MAAA,CAAA;EAAgB;EAAvB,KAAA,CAAA,EAAA,OAAA;;AAkDpD;;;AAA8F,UAhF7E,cAAA,CAgF6E;EAAvB,QAAA,EA/E3D,eA+E2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAlD1D,oBAAqB,oBAAkB,OAAO,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkD9D,yBAAgC,oBAAkB,QAAQ,OAAO,gBAAgB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CodegenError, CodegenSuccess } from "@soda-gql/codegen";
|
|
2
2
|
import { ConfigError } from "@soda-gql/config";
|
|
3
|
-
import { ContextTransformer } from "@soda-gql/core/_internal";
|
|
4
3
|
import { Result } from "neverthrow";
|
|
4
|
+
import { BuilderArtifact, BuilderError } from "@soda-gql/builder";
|
|
5
|
+
import { ContextTransformer } from "@soda-gql/core/_internal";
|
|
5
6
|
|
|
6
|
-
//#region packages/sdk/src/
|
|
7
|
+
//#region packages/sdk/src/codegen.d.ts
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Error type for codegen operations.
|
|
11
|
+
* Can be either a config loading error or a codegen error.
|
|
12
|
+
*/
|
|
13
|
+
type CodegenSdkError = ConfigError | CodegenError;
|
|
14
|
+
/**
|
|
15
|
+
* Options for codegenAsync function.
|
|
16
|
+
*/
|
|
17
|
+
interface CodegenSdkOptions {
|
|
18
|
+
/** Path to soda-gql config file (optional, will search if not provided) */
|
|
19
|
+
configPath?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of codegen operations.
|
|
23
|
+
*/
|
|
24
|
+
interface CodegenSdkResult {
|
|
25
|
+
/** Generated schema information */
|
|
26
|
+
schemas: CodegenSuccess["schemas"];
|
|
27
|
+
/** Path to generated TypeScript module */
|
|
28
|
+
outPath: string;
|
|
29
|
+
/** Path to internal module */
|
|
30
|
+
internalPath: string;
|
|
31
|
+
/** Path to injects module */
|
|
32
|
+
injectsPath: string;
|
|
33
|
+
/** Path to CommonJS bundle */
|
|
34
|
+
cjsPath: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate GraphQL runtime module asynchronously from a config file.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* This function loads the soda-gql config, validates the schemas configuration,
|
|
41
|
+
* and generates TypeScript/CommonJS modules from GraphQL schemas.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Codegen options including optional config path
|
|
44
|
+
* @returns Promise resolving to Result containing the generation result or an error
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const result = await codegenAsync({ configPath: './soda-gql.config.ts' });
|
|
49
|
+
* if (result.isOk()) {
|
|
50
|
+
* console.log('Generated:', result.value.outPath);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Without explicit config path (will search for config file)
|
|
57
|
+
* const result = await codegenAsync();
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare const codegenAsync: (options?: CodegenSdkOptions) => Promise<Result<CodegenSdkResult, CodegenSdkError>>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region packages/sdk/src/prebuild.d.ts
|
|
8
63
|
/**
|
|
9
64
|
* Error type for prebuild operations.
|
|
10
65
|
* Can be either a config loading error or a builder error.
|
|
@@ -86,5 +141,5 @@ declare const prebuild: (options: PrebuildOptions) => Result<PrebuildResult, Pre
|
|
|
86
141
|
*/
|
|
87
142
|
declare const prebuildAsync: (options: PrebuildOptions) => Promise<Result<PrebuildResult, PrebuildError>>;
|
|
88
143
|
//#endregion
|
|
89
|
-
export { type ContextTransformer, type PrebuildError, type PrebuildOptions, type PrebuildResult, prebuild, prebuildAsync };
|
|
144
|
+
export { type CodegenSdkError, type CodegenSdkOptions, type CodegenSdkResult, type ContextTransformer, type PrebuildError, type PrebuildOptions, type PrebuildResult, codegenAsync, prebuild, prebuildAsync };
|
|
90
145
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/prebuild.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/codegen.ts","../src/prebuild.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAgBA;AAKA;AAQA;AAqCA;AAA4C,KAlDhC,eAAA,GAAkB,WAkDc,GAlDA,YAkDA;;;;AAAyB,UA7CpD,iBAAA,CA6CoD;EAAO;;;;AClD5E;AAKA;AAgBiB,UDRA,gBAAA,CCSL;EA6BC;EAAqB,OAAA,EDpCvB,cCoCuB,CAAA,SAAA,CAAA;EAAyB;EAAgB,OAAA,EAAA,MAAA;EAAvB;EAAM,YAAA,EAAA,MAAA;EAkD7C;EAAgC,WAAA,EAAA,MAAA;EAAiC;EAAgB,OAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;cDnDjF,yBAA+B,sBAAyB,QAAQ,OAAO,kBAAkB;;;AArCtG;AAqCA;;;AAAsG,KClD1F,aAAA,GAAgB,WDkD0E,GClD5D,YDkD4D;;;;UC7CrF,eAAA;;;EALL;EAKK,kBAAe,CAAA,EAIT,kBAAA;EAYN;EA8BJ,WAsBZ,CAAA,EAAA,MAAA;EAtBiC;EAAyB,mBAAA,CAAA,EAAA,SAAA,MAAA,EAAA,GAtCf,WAsCe,CAAA,MAAA,CAAA;EAAgB;EAAvB,KAAA,CAAA,EAAA,OAAA;;AAkDpD;;;AAA8F,UAhF7E,cAAA,CAgF6E;EAAvB,QAAA,EA/E3D,eA+E2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAlD1D,oBAAqB,oBAAkB,OAAO,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkD9D,yBAAgC,oBAAkB,QAAQ,OAAO,gBAAgB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { runCodegen } from "@soda-gql/codegen";
|
|
2
3
|
import { loadConfig } from "@soda-gql/config";
|
|
4
|
+
import { err, ok } from "neverthrow";
|
|
5
|
+
import { createBuilderSession } from "@soda-gql/builder";
|
|
3
6
|
import { clearContextTransformer, setContextTransformer } from "@soda-gql/core/_internal";
|
|
4
|
-
import { err } from "neverthrow";
|
|
5
7
|
|
|
8
|
+
//#region packages/sdk/src/codegen.ts
|
|
9
|
+
/**
|
|
10
|
+
* Codegen API for programmatic code generation from GraphQL schemas.
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Generate GraphQL runtime module asynchronously from a config file.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This function loads the soda-gql config, validates the schemas configuration,
|
|
18
|
+
* and generates TypeScript/CommonJS modules from GraphQL schemas.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Codegen options including optional config path
|
|
21
|
+
* @returns Promise resolving to Result containing the generation result or an error
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = await codegenAsync({ configPath: './soda-gql.config.ts' });
|
|
26
|
+
* if (result.isOk()) {
|
|
27
|
+
* console.log('Generated:', result.value.outPath);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Without explicit config path (will search for config file)
|
|
34
|
+
* const result = await codegenAsync();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const codegenAsync = async (options = {}) => {
|
|
38
|
+
const { configPath } = options;
|
|
39
|
+
const configResult = loadConfig(configPath);
|
|
40
|
+
if (configResult.isErr()) {
|
|
41
|
+
return err(configResult.error);
|
|
42
|
+
}
|
|
43
|
+
const config = configResult.value;
|
|
44
|
+
if (!config.schemas || Object.keys(config.schemas).length === 0) {
|
|
45
|
+
return err({
|
|
46
|
+
code: "CONFIG_VALIDATION_FAILED",
|
|
47
|
+
message: "schemas configuration is required in soda-gql config"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const outPath = join(config.outdir, "index.ts");
|
|
51
|
+
const result = await runCodegen({
|
|
52
|
+
schemas: config.schemas,
|
|
53
|
+
outPath,
|
|
54
|
+
format: "human",
|
|
55
|
+
importExtension: config.styles.importExtension
|
|
56
|
+
});
|
|
57
|
+
if (result.isErr()) {
|
|
58
|
+
return err(result.error);
|
|
59
|
+
}
|
|
60
|
+
return ok({
|
|
61
|
+
schemas: result.value.schemas,
|
|
62
|
+
outPath: result.value.outPath,
|
|
63
|
+
internalPath: result.value.internalPath,
|
|
64
|
+
injectsPath: result.value.injectsPath,
|
|
65
|
+
cjsPath: result.value.cjsPath
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
6
70
|
//#region packages/sdk/src/prebuild.ts
|
|
7
71
|
/**
|
|
8
72
|
* Prebuild API for programmatic artifact generation.
|
|
@@ -108,5 +172,5 @@ const prebuildAsync = async (options) => {
|
|
|
108
172
|
};
|
|
109
173
|
|
|
110
174
|
//#endregion
|
|
111
|
-
export { prebuild, prebuildAsync };
|
|
175
|
+
export { codegenAsync, prebuild, prebuildAsync };
|
|
112
176
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/prebuild.ts"],"sourcesContent":["/**\n * Prebuild API for programmatic artifact generation.\n * @module\n */\n\nimport { type BuilderArtifact, type BuilderError, createBuilderSession } from \"@soda-gql/builder\";\nimport { type ConfigError, loadConfig } from \"@soda-gql/config\";\nimport { type ContextTransformer, clearContextTransformer, setContextTransformer } from \"@soda-gql/core/_internal\";\nimport { err, type Result } from \"neverthrow\";\n\nexport type { ContextTransformer };\n\n/**\n * Error type for prebuild operations.\n * Can be either a config loading error or a builder error.\n */\nexport type PrebuildError = ConfigError | BuilderError;\n\n/**\n * Options for prebuild functions.\n */\nexport interface PrebuildOptions {\n /** Path to soda-gql config file */\n configPath: string;\n /** Optional context transformer to modify composer context */\n contextTransformer?: ContextTransformer;\n /** Unique identifier for this evaluator instance (default: \"default\") */\n evaluatorId?: string;\n /** Override entrypoints from config.include */\n entrypointsOverride?: readonly string[] | ReadonlySet<string>;\n /** Force rebuild even if no changes detected */\n force?: boolean;\n}\n\n/**\n * Result of prebuild operations.\n */\nexport interface PrebuildResult {\n artifact: BuilderArtifact;\n}\n\n/**\n * Build artifact synchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = prebuild({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuild = (options: PrebuildOptions): Result<PrebuildResult, PrebuildError> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = session.build({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n\n/**\n * Build artifact asynchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Promise resolving to Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuildAsync = async (options: PrebuildOptions): Promise<Result<PrebuildResult, PrebuildError>> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path (sync - no async version available)\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = await session.buildAsync({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/codegen.ts","../src/prebuild.ts"],"sourcesContent":["/**\n * Codegen API for programmatic code generation from GraphQL schemas.\n * @module\n */\n\nimport { join } from \"node:path\";\nimport type { CodegenError, CodegenSuccess } from \"@soda-gql/codegen\";\nimport { runCodegen } from \"@soda-gql/codegen\";\nimport type { ConfigError } from \"@soda-gql/config\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport { err, ok, type Result } from \"neverthrow\";\n\n/**\n * Error type for codegen operations.\n * Can be either a config loading error or a codegen error.\n */\nexport type CodegenSdkError = ConfigError | CodegenError;\n\n/**\n * Options for codegenAsync function.\n */\nexport interface CodegenSdkOptions {\n /** Path to soda-gql config file (optional, will search if not provided) */\n configPath?: string;\n}\n\n/**\n * Result of codegen operations.\n */\nexport interface CodegenSdkResult {\n /** Generated schema information */\n schemas: CodegenSuccess[\"schemas\"];\n /** Path to generated TypeScript module */\n outPath: string;\n /** Path to internal module */\n internalPath: string;\n /** Path to injects module */\n injectsPath: string;\n /** Path to CommonJS bundle */\n cjsPath: string;\n}\n\n/**\n * Generate GraphQL runtime module asynchronously from a config file.\n *\n * @remarks\n * This function loads the soda-gql config, validates the schemas configuration,\n * and generates TypeScript/CommonJS modules from GraphQL schemas.\n *\n * @param options - Codegen options including optional config path\n * @returns Promise resolving to Result containing the generation result or an error\n *\n * @example\n * ```typescript\n * const result = await codegenAsync({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log('Generated:', result.value.outPath);\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Without explicit config path (will search for config file)\n * const result = await codegenAsync();\n * ```\n */\nexport const codegenAsync = async (options: CodegenSdkOptions = {}): Promise<Result<CodegenSdkResult, CodegenSdkError>> => {\n const { configPath } = options;\n\n // Load config from file path\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n // Validate schemas config exists\n if (!config.schemas || Object.keys(config.schemas).length === 0) {\n return err({\n code: \"CONFIG_VALIDATION_FAILED\",\n message: \"schemas configuration is required in soda-gql config\",\n });\n }\n\n // Derive output path from outdir (already absolute)\n const outPath = join(config.outdir, \"index.ts\");\n\n // Run codegen (config.schemas is already resolved by loadConfig)\n const result = await runCodegen({\n schemas: config.schemas,\n outPath,\n format: \"human\",\n importExtension: config.styles.importExtension,\n });\n\n if (result.isErr()) {\n return err(result.error);\n }\n\n return ok({\n schemas: result.value.schemas,\n outPath: result.value.outPath,\n internalPath: result.value.internalPath,\n injectsPath: result.value.injectsPath,\n cjsPath: result.value.cjsPath,\n });\n};\n","/**\n * Prebuild API for programmatic artifact generation.\n * @module\n */\n\nimport { type BuilderArtifact, type BuilderError, createBuilderSession } from \"@soda-gql/builder\";\nimport { type ConfigError, loadConfig } from \"@soda-gql/config\";\nimport { type ContextTransformer, clearContextTransformer, setContextTransformer } from \"@soda-gql/core/_internal\";\nimport { err, type Result } from \"neverthrow\";\n\nexport type { ContextTransformer };\n\n/**\n * Error type for prebuild operations.\n * Can be either a config loading error or a builder error.\n */\nexport type PrebuildError = ConfigError | BuilderError;\n\n/**\n * Options for prebuild functions.\n */\nexport interface PrebuildOptions {\n /** Path to soda-gql config file */\n configPath: string;\n /** Optional context transformer to modify composer context */\n contextTransformer?: ContextTransformer;\n /** Unique identifier for this evaluator instance (default: \"default\") */\n evaluatorId?: string;\n /** Override entrypoints from config.include */\n entrypointsOverride?: readonly string[] | ReadonlySet<string>;\n /** Force rebuild even if no changes detected */\n force?: boolean;\n}\n\n/**\n * Result of prebuild operations.\n */\nexport interface PrebuildResult {\n artifact: BuilderArtifact;\n}\n\n/**\n * Build artifact synchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = prebuild({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuild = (options: PrebuildOptions): Result<PrebuildResult, PrebuildError> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = session.build({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n\n/**\n * Build artifact asynchronously from a config file.\n *\n * @remarks\n * **Concurrent Execution Warning**: This function uses global state for context transformation.\n * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different\n * `contextTransformer` options. Sequential execution is safe.\n *\n * **Session Lifecycle**: This function automatically handles session lifecycle:\n * - Creates a BuilderSession with the resolved config\n * - Calls `session.dispose()` in a finally block to:\n * - Save incremental build cache to disk\n * - Unregister from process exit handler\n * - Clears context transformer state after build\n *\n * @param options - Prebuild options including config path and optional transformer\n * @returns Promise resolving to Result containing the built artifact or an error\n *\n * @example\n * ```typescript\n * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });\n * if (result.isOk()) {\n * console.log(result.value.artifact.elements);\n * }\n * ```\n */\nexport const prebuildAsync = async (options: PrebuildOptions): Promise<Result<PrebuildResult, PrebuildError>> => {\n const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;\n\n // Load config from file path (sync - no async version available)\n const configResult = loadConfig(configPath);\n if (configResult.isErr()) {\n return err(configResult.error);\n }\n const config = configResult.value;\n\n const session = createBuilderSession({ config, evaluatorId, entrypointsOverride });\n\n try {\n if (contextTransformer) {\n setContextTransformer(contextTransformer);\n }\n const result = await session.buildAsync({ force });\n return result.map((artifact) => ({ artifact }));\n } finally {\n clearContextTransformer();\n session.dispose();\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,eAAe,OAAO,UAA6B,EAAE,KAAyD;CACzH,MAAM,EAAE,eAAe;CAGvB,MAAM,eAAe,WAAW,WAAW;AAC3C,KAAI,aAAa,OAAO,EAAE;AACxB,SAAO,IAAI,aAAa,MAAM;;CAEhC,MAAM,SAAS,aAAa;AAG5B,KAAI,CAAC,OAAO,WAAW,OAAO,KAAK,OAAO,QAAQ,CAAC,WAAW,GAAG;AAC/D,SAAO,IAAI;GACT,MAAM;GACN,SAAS;GACV,CAAC;;CAIJ,MAAM,UAAU,KAAK,OAAO,QAAQ,WAAW;CAG/C,MAAM,SAAS,MAAM,WAAW;EAC9B,SAAS,OAAO;EAChB;EACA,QAAQ;EACR,iBAAiB,OAAO,OAAO;EAChC,CAAC;AAEF,KAAI,OAAO,OAAO,EAAE;AAClB,SAAO,IAAI,OAAO,MAAM;;AAG1B,QAAO,GAAG;EACR,SAAS,OAAO,MAAM;EACtB,SAAS,OAAO,MAAM;EACtB,cAAc,OAAO,MAAM;EAC3B,aAAa,OAAO,MAAM;EAC1B,SAAS,OAAO,MAAM;EACvB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtCJ,MAAa,YAAY,YAAoE;CAC3F,MAAM,EAAE,YAAY,oBAAoB,aAAa,qBAAqB,UAAU;CAGpF,MAAM,eAAe,WAAW,WAAW;AAC3C,KAAI,aAAa,OAAO,EAAE;AACxB,SAAO,IAAI,aAAa,MAAM;;CAEhC,MAAM,SAAS,aAAa;CAE5B,MAAM,UAAU,qBAAqB;EAAE;EAAQ;EAAa;EAAqB,CAAC;AAElF,KAAI;AACF,MAAI,oBAAoB;AACtB,yBAAsB,mBAAmB;;EAE3C,MAAM,SAAS,QAAQ,MAAM,EAAE,OAAO,CAAC;AACvC,SAAO,OAAO,KAAK,cAAc,EAAE,UAAU,EAAE;WACvC;AACR,2BAAyB;AACzB,UAAQ,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BrB,MAAa,gBAAgB,OAAO,YAA6E;CAC/G,MAAM,EAAE,YAAY,oBAAoB,aAAa,qBAAqB,UAAU;CAGpF,MAAM,eAAe,WAAW,WAAW;AAC3C,KAAI,aAAa,OAAO,EAAE;AACxB,SAAO,IAAI,aAAa,MAAM;;CAEhC,MAAM,SAAS,aAAa;CAE5B,MAAM,UAAU,qBAAqB;EAAE;EAAQ;EAAa;EAAqB,CAAC;AAElF,KAAI;AACF,MAAI,oBAAoB;AACtB,yBAAsB,mBAAmB;;EAE3C,MAAM,SAAS,MAAM,QAAQ,WAAW,EAAE,OAAO,CAAC;AAClD,SAAO,OAAO,KAAK,cAAc,EAAE,UAAU,EAAE;WACvC;AACR,2BAAyB;AACzB,UAAQ,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/sdk",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"description": "Programmatic SDK for soda-gql CLI features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
"./package.json": "./package.json"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@soda-gql/builder": "0.11.
|
|
51
|
-
"@soda-gql/
|
|
52
|
-
"@soda-gql/
|
|
50
|
+
"@soda-gql/builder": "0.11.5",
|
|
51
|
+
"@soda-gql/codegen": "0.11.5",
|
|
52
|
+
"@soda-gql/config": "0.11.5",
|
|
53
|
+
"@soda-gql/core": "0.11.5",
|
|
53
54
|
"neverthrow": "^8.1.1"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {},
|