@soda-gql/sdk 0.12.6 → 0.13.0

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 CHANGED
@@ -209,7 +209,7 @@ may result in incorrect context being applied.
209
209
  ## Related Packages
210
210
 
211
211
  - [@soda-gql/builder](../builder) - Core build system
212
- - [@soda-gql/codegen](../codegen) - Code generation from GraphQL schemas
212
+ - [@soda-gql/tools](../tools) - CLI, codegen (`@soda-gql/tools/codegen`), typegen, and formatter
213
213
  - [@soda-gql/config](../config) - Configuration loading
214
214
  - [@soda-gql/core](../core) - GraphQL composition primitives
215
215
 
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  let node_path = require("node:path");
2
- let __soda_gql_codegen = require("@soda-gql/codegen");
3
2
  let __soda_gql_config = require("@soda-gql/config");
3
+ let __soda_gql_tools_codegen = require("@soda-gql/tools/codegen");
4
4
  let neverthrow = require("neverthrow");
5
5
  let __soda_gql_builder = require("@soda-gql/builder");
6
6
  let __soda_gql_core__internal = require("@soda-gql/core/_internal");
@@ -48,7 +48,7 @@ const codegenAsync = async (options = {}) => {
48
48
  });
49
49
  }
50
50
  const outPath = (0, node_path.join)(config.outdir, "index.ts");
51
- const result = await (0, __soda_gql_codegen.runCodegen)({
51
+ const result = await (0, __soda_gql_tools_codegen.runCodegen)({
52
52
  schemas: config.schemas,
53
53
  outPath,
54
54
  format: "human",
@@ -1 +1 @@
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 chunkSize: config.codegen.chunkSize,\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,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AAW,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"}
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 { ConfigError } from \"@soda-gql/config\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport type { CodegenError, CodegenSuccess } from \"@soda-gql/tools/codegen\";\nimport { runCodegen } from \"@soda-gql/tools/codegen\";\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 chunkSize: config.codegen.chunkSize,\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,+CAAiB;EAC9B,SAAS,OAAO;EAChB;EACA,QAAQ;EACR,iBAAiB,OAAO,OAAO;EAC/B,WAAW,OAAO,QAAQ;EAC3B,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvCJ,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,5 +1,5 @@
1
- import { CodegenError, CodegenSuccess } from "@soda-gql/codegen";
2
1
  import { ConfigError } from "@soda-gql/config";
2
+ import { CodegenError, CodegenSuccess } from "@soda-gql/tools/codegen";
3
3
  import { Result } from "neverthrow";
4
4
  import { BuilderArtifact, BuilderError } from "@soda-gql/builder";
5
5
  import { ContextTransformer } from "@soda-gql/core/_internal";
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { CodegenError, CodegenSuccess } from "@soda-gql/codegen";
2
1
  import { ConfigError } from "@soda-gql/config";
2
+ import { CodegenError, CodegenSuccess } from "@soda-gql/tools/codegen";
3
3
  import { Result } from "neverthrow";
4
4
  import { BuilderArtifact, BuilderError } from "@soda-gql/builder";
5
5
  import { ContextTransformer } from "@soda-gql/core/_internal";
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
- import { runCodegen } from "@soda-gql/codegen";
3
2
  import { loadConfig } from "@soda-gql/config";
3
+ import { runCodegen } from "@soda-gql/tools/codegen";
4
4
  import { err, ok } from "neverthrow";
5
5
  import { createBuilderSession } from "@soda-gql/builder";
6
6
  import { clearContextTransformer, setContextTransformer } from "@soda-gql/core/_internal";
@@ -1 +1 @@
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 chunkSize: config.codegen.chunkSize,\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;EAC/B,WAAW,OAAO,QAAQ;EAC3B,CAAC;AAEF,KAAI,OAAO,OAAO,EAAE;AA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ebuild.ts"],"sourcesContent":["/**\n * Codegen API for programmatic code generation from GraphQL schemas.\n * @module\n */\n\nimport { join } from \"node:path\";\nimport type { ConfigError } from \"@soda-gql/config\";\nimport { loadConfig } from \"@soda-gql/config\";\nimport type { CodegenError, CodegenSuccess } from \"@soda-gql/tools/codegen\";\nimport { runCodegen } from \"@soda-gql/tools/codegen\";\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 chunkSize: config.codegen.chunkSize,\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;EAC/B,WAAW,OAAO,QAAQ;EAC3B,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvCJ,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.12.6",
3
+ "version": "0.13.0",
4
4
  "description": "Programmatic SDK for soda-gql CLI features",
5
5
  "type": "module",
6
6
  "private": false,
@@ -49,10 +49,10 @@
49
49
  "./package.json": "./package.json"
50
50
  },
51
51
  "dependencies": {
52
- "@soda-gql/builder": "0.12.6",
53
- "@soda-gql/codegen": "0.12.6",
54
- "@soda-gql/config": "0.12.6",
55
- "@soda-gql/core": "0.12.6",
52
+ "@soda-gql/builder": "0.13.0",
53
+ "@soda-gql/tools": "0.13.0",
54
+ "@soda-gql/config": "0.13.0",
55
+ "@soda-gql/core": "0.13.0",
56
56
  "neverthrow": "^8.1.1"
57
57
  },
58
58
  "devDependencies": {},