@soda-gql/sdk 0.10.2

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 ADDED
@@ -0,0 +1,160 @@
1
+ # @soda-gql/sdk
2
+
3
+ [![npm version](https://badge.fury.io/js/@soda-gql%2Fsdk.svg)](https://badge.fury.io/js/@soda-gql%2Fsdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Programmatic API for soda-gql prebuild operations.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ bun add @soda-gql/sdk
12
+ ```
13
+
14
+ ## Overview
15
+
16
+ This package provides a programmatic interface to soda-gql's build system, allowing external tools
17
+ and build plugins to execute artifact generation without invoking the CLI.
18
+
19
+ **Key Features:**
20
+
21
+ - Synchronous and asynchronous build APIs
22
+ - Optional context transformation for modifying composer context
23
+ - Configurable build options (force rebuild, evaluator ID, entrypoints override)
24
+ - Comprehensive error handling with typed Result
25
+
26
+ ## Usage
27
+
28
+ ### Basic Usage
29
+
30
+ ```typescript
31
+ import { prebuild, prebuildAsync } from "@soda-gql/sdk";
32
+
33
+ // Synchronous build
34
+ const result = prebuild({
35
+ configPath: "./soda-gql.config.ts",
36
+ });
37
+
38
+ if (result.isOk()) {
39
+ const { artifact } = result.value;
40
+ console.log(`Built ${Object.keys(artifact.elements).length} elements`);
41
+ } else {
42
+ console.error("Build failed:", result.error);
43
+ }
44
+
45
+ // Asynchronous build
46
+ const asyncResult = await prebuildAsync({
47
+ configPath: "./soda-gql.config.ts",
48
+ });
49
+ ```
50
+
51
+ ### With Context Transformer
52
+
53
+ ```typescript
54
+ import { prebuildAsync } from "@soda-gql/sdk";
55
+
56
+ const result = await prebuildAsync({
57
+ configPath: "./soda-gql.config.ts",
58
+ contextTransformer: (context) => ({
59
+ ...context,
60
+ // Add custom context properties
61
+ buildId: process.env.BUILD_ID,
62
+ environment: "production",
63
+ }),
64
+ });
65
+ ```
66
+
67
+ ### With Build Options
68
+
69
+ ```typescript
70
+ import { prebuildAsync } from "@soda-gql/sdk";
71
+
72
+ const result = await prebuildAsync({
73
+ configPath: "./soda-gql.config.ts",
74
+ force: true, // Force rebuild, ignore cache
75
+ evaluatorId: "my-build", // Custom evaluator ID for cache isolation
76
+ entrypointsOverride: ["./src/graphql/**/*.ts"], // Override config.include
77
+ });
78
+ ```
79
+
80
+ ## API Reference
81
+
82
+ ### `prebuild(options: PrebuildOptions): Result<PrebuildResult, PrebuildError>`
83
+
84
+ Synchronously builds GraphQL artifacts based on the provided configuration.
85
+
86
+ ### `prebuildAsync(options: PrebuildOptions): Promise<Result<PrebuildResult, PrebuildError>>`
87
+
88
+ Asynchronously builds GraphQL artifacts. Preferred for build plugins and tools.
89
+
90
+ ### Types
91
+
92
+ #### `PrebuildOptions`
93
+
94
+ | Property | Type | Required | Description |
95
+ | -------------------- | ------------------------- | -------- | ---------------------------------------------- |
96
+ | `configPath` | `string` | Yes | Path to soda-gql config file |
97
+ | `contextTransformer` | `ContextTransformer` | No | Function to modify composer context |
98
+ | `force` | `boolean` | No | Force rebuild, ignore cache (default: false) |
99
+ | `evaluatorId` | `string` | No | Unique evaluator ID (default: "default") |
100
+ | `entrypointsOverride`| `string[] \| Set<string>` | No | Override config.include patterns |
101
+
102
+ #### `PrebuildResult`
103
+
104
+ ```typescript
105
+ interface PrebuildResult {
106
+ artifact: BuilderArtifact;
107
+ }
108
+ ```
109
+
110
+ #### `PrebuildError`
111
+
112
+ Union type: `ConfigError | BuilderError`
113
+
114
+ #### `ContextTransformer`
115
+
116
+ ```typescript
117
+ type ContextTransformer = (
118
+ context: Record<string, unknown>
119
+ ) => Record<string, unknown>;
120
+ ```
121
+
122
+ ## Session Lifecycle
123
+
124
+ `prebuild` and `prebuildAsync` internally create a BuilderSession and always call `dispose()` after
125
+ build completion (in a finally block).
126
+
127
+ ### What `dispose()` does:
128
+
129
+ 1. **Cache Persistence**: Saves incremental build cache to `node_modules/.cache/soda-gql/builder/cache.json`
130
+ 2. **Exit Handler Cleanup**: Unregisters from process exit handler to prevent duplicate saves
131
+
132
+ ### Notes:
133
+
134
+ - When using SDK, `dispose()` is called automatically - no manual cleanup needed
135
+ - Even if build fails, dispose is guaranteed to run via finally block
136
+ - Cache is shared across builds with the same `evaluatorId`
137
+
138
+ ## Limitations
139
+
140
+ ### Concurrent Execution
141
+
142
+ Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
143
+ `contextTransformer` options. The context transformer uses global state and concurrent calls
144
+ may result in incorrect context being applied.
145
+
146
+ **Safe patterns:**
147
+
148
+ - Sequential builds with different transformers
149
+ - Concurrent builds without transformers
150
+ - Concurrent builds with the same transformer
151
+
152
+ ## Related Packages
153
+
154
+ - [@soda-gql/builder](../builder) - Core build system
155
+ - [@soda-gql/config](../config) - Configuration loading
156
+ - [@soda-gql/core](../core) - GraphQL composition primitives
157
+
158
+ ## License
159
+
160
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,113 @@
1
+ let __soda_gql_builder = require("@soda-gql/builder");
2
+ let __soda_gql_config = require("@soda-gql/config");
3
+ let __soda_gql_core__internal = require("@soda-gql/core/_internal");
4
+ let neverthrow = require("neverthrow");
5
+
6
+ //#region packages/sdk/src/prebuild.ts
7
+ /**
8
+ * Prebuild API for programmatic artifact generation.
9
+ * @module
10
+ */
11
+ /**
12
+ * Build artifact synchronously from a config file.
13
+ *
14
+ * @remarks
15
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
16
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
17
+ * `contextTransformer` options. Sequential execution is safe.
18
+ *
19
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
20
+ * - Creates a BuilderSession with the resolved config
21
+ * - Calls `session.dispose()` in a finally block to:
22
+ * - Save incremental build cache to disk
23
+ * - Unregister from process exit handler
24
+ * - Clears context transformer state after build
25
+ *
26
+ * @param options - Prebuild options including config path and optional transformer
27
+ * @returns Result containing the built artifact or an error
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const result = prebuild({ configPath: './soda-gql.config.ts' });
32
+ * if (result.isOk()) {
33
+ * console.log(result.value.artifact.elements);
34
+ * }
35
+ * ```
36
+ */
37
+ const prebuild = (options) => {
38
+ const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = 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
+ const session = (0, __soda_gql_builder.createBuilderSession)({
45
+ config,
46
+ evaluatorId,
47
+ entrypointsOverride
48
+ });
49
+ try {
50
+ if (contextTransformer) {
51
+ (0, __soda_gql_core__internal.setContextTransformer)(contextTransformer);
52
+ }
53
+ const result = session.build({ force });
54
+ return result.map((artifact) => ({ artifact }));
55
+ } finally {
56
+ (0, __soda_gql_core__internal.clearContextTransformer)();
57
+ session.dispose();
58
+ }
59
+ };
60
+ /**
61
+ * Build artifact asynchronously from a config file.
62
+ *
63
+ * @remarks
64
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
65
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
66
+ * `contextTransformer` options. Sequential execution is safe.
67
+ *
68
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
69
+ * - Creates a BuilderSession with the resolved config
70
+ * - Calls `session.dispose()` in a finally block to:
71
+ * - Save incremental build cache to disk
72
+ * - Unregister from process exit handler
73
+ * - Clears context transformer state after build
74
+ *
75
+ * @param options - Prebuild options including config path and optional transformer
76
+ * @returns Promise resolving to Result containing the built artifact or an error
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });
81
+ * if (result.isOk()) {
82
+ * console.log(result.value.artifact.elements);
83
+ * }
84
+ * ```
85
+ */
86
+ const prebuildAsync = async (options) => {
87
+ const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;
88
+ const configResult = (0, __soda_gql_config.loadConfig)(configPath);
89
+ if (configResult.isErr()) {
90
+ return (0, neverthrow.err)(configResult.error);
91
+ }
92
+ const config = configResult.value;
93
+ const session = (0, __soda_gql_builder.createBuilderSession)({
94
+ config,
95
+ evaluatorId,
96
+ entrypointsOverride
97
+ });
98
+ try {
99
+ if (contextTransformer) {
100
+ (0, __soda_gql_core__internal.setContextTransformer)(contextTransformer);
101
+ }
102
+ const result = await session.buildAsync({ force });
103
+ return result.map((artifact) => ({ artifact }));
104
+ } finally {
105
+ (0, __soda_gql_core__internal.clearContextTransformer)();
106
+ session.dispose();
107
+ }
108
+ };
109
+
110
+ //#endregion
111
+ exports.prebuild = prebuild;
112
+ exports.prebuildAsync = prebuildAsync;
113
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,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"}
@@ -0,0 +1,90 @@
1
+ import { BuilderArtifact, BuilderError } from "@soda-gql/builder";
2
+ import { ConfigError } from "@soda-gql/config";
3
+ import { ContextTransformer } from "@soda-gql/core/_internal";
4
+ import { Result } from "neverthrow";
5
+
6
+ //#region packages/sdk/src/prebuild.d.ts
7
+
8
+ /**
9
+ * Error type for prebuild operations.
10
+ * Can be either a config loading error or a builder error.
11
+ */
12
+ type PrebuildError = ConfigError | BuilderError;
13
+ /**
14
+ * Options for prebuild functions.
15
+ */
16
+ interface PrebuildOptions {
17
+ /** Path to soda-gql config file */
18
+ configPath: string;
19
+ /** Optional context transformer to modify composer context */
20
+ contextTransformer?: ContextTransformer;
21
+ /** Unique identifier for this evaluator instance (default: "default") */
22
+ evaluatorId?: string;
23
+ /** Override entrypoints from config.include */
24
+ entrypointsOverride?: readonly string[] | ReadonlySet<string>;
25
+ /** Force rebuild even if no changes detected */
26
+ force?: boolean;
27
+ }
28
+ /**
29
+ * Result of prebuild operations.
30
+ */
31
+ interface PrebuildResult {
32
+ artifact: BuilderArtifact;
33
+ }
34
+ /**
35
+ * Build artifact synchronously from a config file.
36
+ *
37
+ * @remarks
38
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
39
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
40
+ * `contextTransformer` options. Sequential execution is safe.
41
+ *
42
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
43
+ * - Creates a BuilderSession with the resolved config
44
+ * - Calls `session.dispose()` in a finally block to:
45
+ * - Save incremental build cache to disk
46
+ * - Unregister from process exit handler
47
+ * - Clears context transformer state after build
48
+ *
49
+ * @param options - Prebuild options including config path and optional transformer
50
+ * @returns Result containing the built artifact or an error
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const result = prebuild({ configPath: './soda-gql.config.ts' });
55
+ * if (result.isOk()) {
56
+ * console.log(result.value.artifact.elements);
57
+ * }
58
+ * ```
59
+ */
60
+ declare const prebuild: (options: PrebuildOptions) => Result<PrebuildResult, PrebuildError>;
61
+ /**
62
+ * Build artifact asynchronously from a config file.
63
+ *
64
+ * @remarks
65
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
66
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
67
+ * `contextTransformer` options. Sequential execution is safe.
68
+ *
69
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
70
+ * - Creates a BuilderSession with the resolved config
71
+ * - Calls `session.dispose()` in a finally block to:
72
+ * - Save incremental build cache to disk
73
+ * - Unregister from process exit handler
74
+ * - Clears context transformer state after build
75
+ *
76
+ * @param options - Prebuild options including config path and optional transformer
77
+ * @returns Promise resolving to Result containing the built artifact or an error
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });
82
+ * if (result.isOk()) {
83
+ * console.log(result.value.artifact.elements);
84
+ * }
85
+ * ```
86
+ */
87
+ declare const prebuildAsync: (options: PrebuildOptions) => Promise<Result<PrebuildResult, PrebuildError>>;
88
+ //#endregion
89
+ export { type ContextTransformer, type PrebuildError, type PrebuildOptions, type PrebuildResult, prebuild, prebuildAsync };
90
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/prebuild.ts"],"sourcesContent":[],"mappings":";;;;;;;AAmEA;;;;AAAoD,KAnDxC,aAAA,GAAgB,WAmDwB,GAnDV,YAmDU;;AAkDpD;;AAA8E,UAhG7D,eAAA,CAgG6D;EAAgB;EAAvB,UAAA,EAAA,MAAA;EAAR;EAAO,kBAAA,CAAA,EA5F/C,kBA4F+C;;;;4CAxF1B;;;;;;;UAQ3B,cAAA;YACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BC,oBAAqB,oBAAkB,OAAO,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkD9D,yBAAgC,oBAAkB,QAAQ,OAAO,gBAAgB"}
@@ -0,0 +1,90 @@
1
+ import { BuilderArtifact, BuilderError } from "@soda-gql/builder";
2
+ import { ConfigError } from "@soda-gql/config";
3
+ import { ContextTransformer } from "@soda-gql/core/_internal";
4
+ import { Result } from "neverthrow";
5
+
6
+ //#region packages/sdk/src/prebuild.d.ts
7
+
8
+ /**
9
+ * Error type for prebuild operations.
10
+ * Can be either a config loading error or a builder error.
11
+ */
12
+ type PrebuildError = ConfigError | BuilderError;
13
+ /**
14
+ * Options for prebuild functions.
15
+ */
16
+ interface PrebuildOptions {
17
+ /** Path to soda-gql config file */
18
+ configPath: string;
19
+ /** Optional context transformer to modify composer context */
20
+ contextTransformer?: ContextTransformer;
21
+ /** Unique identifier for this evaluator instance (default: "default") */
22
+ evaluatorId?: string;
23
+ /** Override entrypoints from config.include */
24
+ entrypointsOverride?: readonly string[] | ReadonlySet<string>;
25
+ /** Force rebuild even if no changes detected */
26
+ force?: boolean;
27
+ }
28
+ /**
29
+ * Result of prebuild operations.
30
+ */
31
+ interface PrebuildResult {
32
+ artifact: BuilderArtifact;
33
+ }
34
+ /**
35
+ * Build artifact synchronously from a config file.
36
+ *
37
+ * @remarks
38
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
39
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
40
+ * `contextTransformer` options. Sequential execution is safe.
41
+ *
42
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
43
+ * - Creates a BuilderSession with the resolved config
44
+ * - Calls `session.dispose()` in a finally block to:
45
+ * - Save incremental build cache to disk
46
+ * - Unregister from process exit handler
47
+ * - Clears context transformer state after build
48
+ *
49
+ * @param options - Prebuild options including config path and optional transformer
50
+ * @returns Result containing the built artifact or an error
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const result = prebuild({ configPath: './soda-gql.config.ts' });
55
+ * if (result.isOk()) {
56
+ * console.log(result.value.artifact.elements);
57
+ * }
58
+ * ```
59
+ */
60
+ declare const prebuild: (options: PrebuildOptions) => Result<PrebuildResult, PrebuildError>;
61
+ /**
62
+ * Build artifact asynchronously from a config file.
63
+ *
64
+ * @remarks
65
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
66
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
67
+ * `contextTransformer` options. Sequential execution is safe.
68
+ *
69
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
70
+ * - Creates a BuilderSession with the resolved config
71
+ * - Calls `session.dispose()` in a finally block to:
72
+ * - Save incremental build cache to disk
73
+ * - Unregister from process exit handler
74
+ * - Clears context transformer state after build
75
+ *
76
+ * @param options - Prebuild options including config path and optional transformer
77
+ * @returns Promise resolving to Result containing the built artifact or an error
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });
82
+ * if (result.isOk()) {
83
+ * console.log(result.value.artifact.elements);
84
+ * }
85
+ * ```
86
+ */
87
+ declare const prebuildAsync: (options: PrebuildOptions) => Promise<Result<PrebuildResult, PrebuildError>>;
88
+ //#endregion
89
+ export { type ContextTransformer, type PrebuildError, type PrebuildOptions, type PrebuildResult, prebuild, prebuildAsync };
90
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/prebuild.ts"],"sourcesContent":[],"mappings":";;;;;;;AAmEA;;;;AAAoD,KAnDxC,aAAA,GAAgB,WAmDwB,GAnDV,YAmDU;;AAkDpD;;AAA8E,UAhG7D,eAAA,CAgG6D;EAAgB;EAAvB,UAAA,EAAA,MAAA;EAAR;EAAO,kBAAA,CAAA,EA5F/C,kBA4F+C;;;;4CAxF1B;;;;;;;UAQ3B,cAAA;YACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BC,oBAAqB,oBAAkB,OAAO,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkD9D,yBAAgC,oBAAkB,QAAQ,OAAO,gBAAgB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,112 @@
1
+ import { createBuilderSession } from "@soda-gql/builder";
2
+ import { loadConfig } from "@soda-gql/config";
3
+ import { clearContextTransformer, setContextTransformer } from "@soda-gql/core/_internal";
4
+ import { err } from "neverthrow";
5
+
6
+ //#region packages/sdk/src/prebuild.ts
7
+ /**
8
+ * Prebuild API for programmatic artifact generation.
9
+ * @module
10
+ */
11
+ /**
12
+ * Build artifact synchronously from a config file.
13
+ *
14
+ * @remarks
15
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
16
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
17
+ * `contextTransformer` options. Sequential execution is safe.
18
+ *
19
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
20
+ * - Creates a BuilderSession with the resolved config
21
+ * - Calls `session.dispose()` in a finally block to:
22
+ * - Save incremental build cache to disk
23
+ * - Unregister from process exit handler
24
+ * - Clears context transformer state after build
25
+ *
26
+ * @param options - Prebuild options including config path and optional transformer
27
+ * @returns Result containing the built artifact or an error
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const result = prebuild({ configPath: './soda-gql.config.ts' });
32
+ * if (result.isOk()) {
33
+ * console.log(result.value.artifact.elements);
34
+ * }
35
+ * ```
36
+ */
37
+ const prebuild = (options) => {
38
+ const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;
39
+ const configResult = loadConfig(configPath);
40
+ if (configResult.isErr()) {
41
+ return err(configResult.error);
42
+ }
43
+ const config = configResult.value;
44
+ const session = createBuilderSession({
45
+ config,
46
+ evaluatorId,
47
+ entrypointsOverride
48
+ });
49
+ try {
50
+ if (contextTransformer) {
51
+ setContextTransformer(contextTransformer);
52
+ }
53
+ const result = session.build({ force });
54
+ return result.map((artifact) => ({ artifact }));
55
+ } finally {
56
+ clearContextTransformer();
57
+ session.dispose();
58
+ }
59
+ };
60
+ /**
61
+ * Build artifact asynchronously from a config file.
62
+ *
63
+ * @remarks
64
+ * **Concurrent Execution Warning**: This function uses global state for context transformation.
65
+ * Do not run multiple `prebuild` or `prebuildAsync` calls concurrently with different
66
+ * `contextTransformer` options. Sequential execution is safe.
67
+ *
68
+ * **Session Lifecycle**: This function automatically handles session lifecycle:
69
+ * - Creates a BuilderSession with the resolved config
70
+ * - Calls `session.dispose()` in a finally block to:
71
+ * - Save incremental build cache to disk
72
+ * - Unregister from process exit handler
73
+ * - Clears context transformer state after build
74
+ *
75
+ * @param options - Prebuild options including config path and optional transformer
76
+ * @returns Promise resolving to Result containing the built artifact or an error
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const result = await prebuildAsync({ configPath: './soda-gql.config.ts' });
81
+ * if (result.isOk()) {
82
+ * console.log(result.value.artifact.elements);
83
+ * }
84
+ * ```
85
+ */
86
+ const prebuildAsync = async (options) => {
87
+ const { configPath, contextTransformer, evaluatorId, entrypointsOverride, force } = options;
88
+ const configResult = loadConfig(configPath);
89
+ if (configResult.isErr()) {
90
+ return err(configResult.error);
91
+ }
92
+ const config = configResult.value;
93
+ const session = createBuilderSession({
94
+ config,
95
+ evaluatorId,
96
+ entrypointsOverride
97
+ });
98
+ try {
99
+ if (contextTransformer) {
100
+ setContextTransformer(contextTransformer);
101
+ }
102
+ const result = await session.buildAsync({ force });
103
+ return result.map((artifact) => ({ artifact }));
104
+ } finally {
105
+ clearContextTransformer();
106
+ session.dispose();
107
+ }
108
+ };
109
+
110
+ //#endregion
111
+ export { prebuild, prebuildAsync };
112
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,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 ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@soda-gql/sdk",
3
+ "version": "0.10.2",
4
+ "description": "Programmatic SDK for soda-gql CLI features",
5
+ "type": "module",
6
+ "private": false,
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "author": {
12
+ "name": "Shota Hatada",
13
+ "email": "shota.hatada@whatasoda.me",
14
+ "url": "https://github.com/whatasoda"
15
+ },
16
+ "keywords": [
17
+ "graphql",
18
+ "codegen",
19
+ "zero-runtime",
20
+ "typescript",
21
+ "sdk",
22
+ "programmatic"
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/whatasoda/soda-gql.git",
27
+ "directory": "packages/sdk"
28
+ },
29
+ "homepage": "https://github.com/whatasoda/soda-gql#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/whatasoda/soda-gql/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "main": "./dist/index.mjs",
37
+ "module": "./dist/index.mjs",
38
+ "types": "./dist/index.d.mts",
39
+ "exports": {
40
+ ".": {
41
+ "@soda-gql": "./@x-index.ts",
42
+ "types": "./dist/index.d.mts",
43
+ "import": "./dist/index.mjs",
44
+ "require": "./dist/index.cjs",
45
+ "default": "./dist/index.mjs"
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "dependencies": {
50
+ "@soda-gql/builder": "0.10.2",
51
+ "@soda-gql/config": "0.10.2",
52
+ "@soda-gql/core": "0.10.2",
53
+ "neverthrow": "^8.1.1"
54
+ },
55
+ "devDependencies": {},
56
+ "peerDependencies": {},
57
+ "optionalDependencies": {}
58
+ }