@soda-gql/codegen 0.9.0 → 0.10.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/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
- const require_generator = require('./generator-CyT7AfiI.cjs');
1
+ const require_generator = require('./generator-B-ATtEt4.cjs');
2
2
  let node_fs = require("node:fs");
3
3
  let node_path = require("node:path");
4
4
  let neverthrow = require("neverthrow");
5
+ let node_fs_promises = require("node:fs/promises");
5
6
  let esbuild = require("esbuild");
6
7
  let graphql = require("graphql");
7
8
  let node_crypto = require("node:crypto");
@@ -91,9 +92,92 @@ const writeModule = (outPath, contents) => {
91
92
  }
92
93
  };
93
94
 
95
+ //#endregion
96
+ //#region packages/codegen/src/prebuilt-generator.ts
97
+ /**
98
+ * Generate the prebuilt module code.
99
+ *
100
+ * This generates:
101
+ * - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes
102
+ * - prebuilt/types.ts: Placeholder types that builder will populate
103
+ */
104
+ const generatePrebuiltModule = (schemas, options) => {
105
+ const schemaNames = Array.from(schemas.keys());
106
+ const typeImports = [];
107
+ const runtimeImports = [];
108
+ for (const name of schemaNames) {
109
+ typeImports.push(`Schema_${name}`, `FragmentBuilders_${name}`, `Context_${name}`);
110
+ runtimeImports.push(`__schema_${name}`, `__inputTypeMethods_${name}`, `__directiveMethods_${name}`);
111
+ const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
112
+ if (hasAdapter) {
113
+ typeImports.push(`Adapter_${name}`);
114
+ runtimeImports.push(`__adapter_${name}`);
115
+ }
116
+ }
117
+ const gqlEntries = [];
118
+ for (const name of schemaNames) {
119
+ const document = schemas.get(name);
120
+ if (!document) continue;
121
+ const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
122
+ if (hasAdapter) {
123
+ gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}, Adapter_${name}>(__schema_${name}, { adapter: __adapter_${name}, inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
124
+ } else {
125
+ gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}>(__schema_${name}, { inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
126
+ }
127
+ }
128
+ const indexCode = `\
129
+ /**
130
+ * Prebuilt GQL module for bundler-compatible type resolution.
131
+ *
132
+ * This module uses createPrebuiltGqlElementComposer which looks up types
133
+ * from PrebuiltTypes instead of using complex type inference.
134
+ *
135
+ * @module
136
+ * @generated by @soda-gql/codegen
137
+ */
138
+
139
+ import { createPrebuiltGqlElementComposer } from "@soda-gql/core";
140
+ import {
141
+ ${runtimeImports.join(",\n ")},
142
+ type ${typeImports.join(",\n type ")},
143
+ } from "${options.mainModulePath}";
144
+ import type { ${schemaNames.map((name) => `PrebuiltTypes_${name}`).join(", ")} } from "./types";
145
+
146
+ export const gql = {
147
+ ${gqlEntries.join(",\n")}
148
+ };
149
+
150
+ // Re-export types from main module
151
+ export type { ${typeImports.join(", ")} };
152
+ `;
153
+ const typesCode = `\
154
+ /**
155
+ * Prebuilt type registry.
156
+ *
157
+ * This file contains placeholder types that will be populated by the builder
158
+ * when running \`soda-gql build\` command.
159
+ *
160
+ * @module
161
+ * @generated by @soda-gql/codegen
162
+ */
163
+
164
+ import type { EmptyPrebuiltTypeRegistry } from "@soda-gql/core";
165
+
166
+ ${schemaNames.map((name) => `// Placeholder for ${name} schema - populated by builder\nexport type PrebuiltTypes_${name} = EmptyPrebuiltTypeRegistry;`).join("\n\n")}
167
+ `;
168
+ return {
169
+ indexCode,
170
+ typesCode
171
+ };
172
+ };
173
+
94
174
  //#endregion
95
175
  //#region packages/codegen/src/schema.ts
96
- const loadSchema = (schemaPath) => {
176
+ /**
177
+ * Load a single schema file.
178
+ * @internal Use loadSchema for public API.
179
+ */
180
+ const loadSingleSchema = (schemaPath) => {
97
181
  const resolvedPath = (0, node_path.resolve)(schemaPath);
98
182
  if (!(0, node_fs.existsSync)(resolvedPath)) {
99
183
  return (0, neverthrow.err)({
@@ -115,6 +199,22 @@ const loadSchema = (schemaPath) => {
115
199
  });
116
200
  }
117
201
  };
202
+ /**
203
+ * Load and merge multiple schema files into a single DocumentNode.
204
+ * Uses GraphQL's concatAST to combine definitions from all files.
205
+ */
206
+ const loadSchema = (schemaPaths) => {
207
+ const documents = [];
208
+ for (const schemaPath of schemaPaths) {
209
+ const result = loadSingleSchema(schemaPath);
210
+ if (result.isErr()) {
211
+ return (0, neverthrow.err)(result.error);
212
+ }
213
+ documents.push(result.value);
214
+ }
215
+ const merged = (0, graphql.concatAST)(documents);
216
+ return (0, neverthrow.ok)(merged);
217
+ };
118
218
  const hashSchema = (document) => (0, node_crypto.createHash)("sha256").update((0, graphql.print)(document)).digest("hex");
119
219
 
120
220
  //#endregion
@@ -209,10 +309,11 @@ const runCodegen = async (options) => {
209
309
  const { code } = require_generator.generateMultiSchemaModule(schemas, {
210
310
  injection: injectionConfig,
211
311
  defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
212
- inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
312
+ inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,
313
+ exportForPrebuilt: options.prebuilt
213
314
  });
214
315
  for (const [name, document] of schemas.entries()) {
215
- const schemaIndex = (await Promise.resolve().then(() => require("./generator-DUIxav8h.cjs"))).createSchemaIndex(document);
316
+ const schemaIndex = (await Promise.resolve().then(() => require("./generator-HOw0EOk_.cjs"))).createSchemaIndex(document);
216
317
  const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
217
318
  const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
218
319
  const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
@@ -229,6 +330,32 @@ const runCodegen = async (options) => {
229
330
  if (writeResult.isErr()) {
230
331
  return (0, neverthrow.err)(writeResult.error);
231
332
  }
333
+ if (options.prebuilt) {
334
+ const prebuiltDir = (0, node_path.join)((0, node_path.dirname)(outPath), "prebuilt");
335
+ await (0, node_fs_promises.mkdir)(prebuiltDir, { recursive: true });
336
+ const mainModulePath = toImportSpecifier((0, node_path.join)(prebuiltDir, "index.ts"), outPath, importSpecifierOptions);
337
+ const prebuilt = generatePrebuiltModule(schemas, {
338
+ mainModulePath,
339
+ injection: injectionConfig
340
+ });
341
+ const prebuiltIndexPath = (0, node_path.join)(prebuiltDir, "index.ts");
342
+ const prebuiltIndexResult = await writeModule(prebuiltIndexPath, prebuilt.indexCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
343
+ if (prebuiltIndexResult.isErr()) {
344
+ return (0, neverthrow.err)(prebuiltIndexResult.error);
345
+ }
346
+ const prebuiltTypesPath = (0, node_path.join)(prebuiltDir, "types.ts");
347
+ const prebuiltTypesResult = await writeModule(prebuiltTypesPath, prebuilt.typesCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
348
+ if (prebuiltTypesResult.isErr()) {
349
+ return (0, neverthrow.err)(prebuiltTypesResult.error);
350
+ }
351
+ const prebuiltBundleOutcome = await esbuildBundler.bundle({
352
+ sourcePath: prebuiltIndexPath,
353
+ external: ["@soda-gql/core", "@soda-gql/runtime"]
354
+ });
355
+ if (prebuiltBundleOutcome.isErr()) {
356
+ return (0, neverthrow.err)(prebuiltBundleOutcome.error);
357
+ }
358
+ }
232
359
  const bundleOutcome = await esbuildBundler.bundle({
233
360
  sourcePath: outPath,
234
361
  external: ["@soda-gql/core", "@soda-gql/runtime"]
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["esbuildBundler: Bundler","extensionMap: Record<string, string>","withPrefix","currentExt","schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }>","generateMultiSchemaModule","defaultBundler"],"sources":["../src/inject-template.ts","../src/bundler/esbuild.ts","../src/file.ts","../src/schema.ts","../src/runner.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nconst templateContents = `\\\nimport { defineScalar } from \"@soda-gql/core\";\n\nexport const scalar = {\n ...defineScalar<\"ID\", string, string>(\"ID\"),\n ...defineScalar<\"String\", string, string>(\"String\"),\n ...defineScalar<\"Int\", number, number>(\"Int\"),\n ...defineScalar<\"Float\", number, number>(\"Float\"),\n ...defineScalar<\"Boolean\", boolean, boolean>(\"Boolean\"),\n} as const;\n`;\n\nexport const writeInjectTemplate = (outPath: string) => {\n const targetPath = resolve(outPath);\n\n try {\n if (existsSync(targetPath)) {\n return err<void, CodegenError>({\n code: \"INJECT_TEMPLATE_EXISTS\",\n message: `Inject module already exists: ${targetPath}`,\n outPath: targetPath,\n });\n }\n\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, `${templateContents}\\n`);\n return ok<void, CodegenError>(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<void, CodegenError>({\n code: \"INJECT_TEMPLATE_FAILED\",\n message,\n outPath: targetPath,\n });\n }\n};\n\nexport const getInjectTemplate = (): string => `${templateContents}\\n`;\n","import { extname } from \"node:path\";\nimport { build } from \"esbuild\";\nimport { err, ok } from \"neverthrow\";\nimport type { Bundler } from \"./types\";\n\nexport const esbuildBundler: Bundler = {\n name: \"esbuild\",\n bundle: async ({ sourcePath, external }) => {\n try {\n const sourceExt = extname(sourcePath);\n const baseName = sourcePath.slice(0, -sourceExt.length);\n const cjsPath = `${baseName}.cjs`;\n\n await build({\n entryPoints: [sourcePath],\n outfile: cjsPath,\n format: \"cjs\",\n platform: \"node\",\n bundle: true,\n external: [...external],\n sourcemap: false,\n minify: false,\n treeShaking: false,\n });\n\n return ok({ cjsPath });\n } catch (error) {\n return err({\n code: \"EMIT_FAILED\" as const,\n message: `[esbuild] Failed to bundle: ${error instanceof Error ? error.message : String(error)}`,\n outPath: sourcePath,\n });\n }\n },\n};\n","import { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nexport const writeModule = (outPath: string, contents: string) => {\n const targetPath = resolve(outPath);\n\n try {\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, contents);\n return ok<void, CodegenError>(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<void, CodegenError>({\n code: \"EMIT_FAILED\",\n message,\n outPath: targetPath,\n });\n }\n};\n","import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { type DocumentNode, parse, print } from \"graphql\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nexport const loadSchema = (schemaPath: string) => {\n const resolvedPath = resolve(schemaPath);\n\n if (!existsSync(resolvedPath)) {\n return err<DocumentNode, CodegenError>({\n code: \"SCHEMA_NOT_FOUND\",\n message: `Schema file not found at ${resolvedPath}`,\n schemaPath: resolvedPath,\n });\n }\n\n try {\n const schemaSource = readFileSync(resolvedPath, \"utf8\");\n const document = parse(schemaSource);\n return ok<DocumentNode, CodegenError>(document);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<DocumentNode, CodegenError>({\n code: \"SCHEMA_INVALID\",\n message: `SchemaValidationError: ${message}`,\n schemaPath: resolvedPath,\n });\n }\n};\n\nexport const hashSchema = (document: DocumentNode): string => createHash(\"sha256\").update(print(document)).digest(\"hex\");\n","import { existsSync } from \"node:fs\";\nimport { basename, dirname, extname, relative, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\nimport { defaultBundler } from \"./bundler\";\nimport { writeModule } from \"./file\";\nimport { generateMultiSchemaModule } from \"./generator\";\nimport { hashSchema, loadSchema } from \"./schema\";\nimport type { CodegenOptions, CodegenResult, CodegenSuccess } from \"./types\";\n\nconst extensionMap: Record<string, string> = {\n \".ts\": \".js\",\n \".tsx\": \".js\",\n \".mts\": \".mjs\",\n \".cts\": \".cjs\",\n \".js\": \".js\",\n \".mjs\": \".mjs\",\n \".cjs\": \".cjs\",\n};\n\ntype ImportSpecifierOptions = {\n includeExtension?: boolean;\n};\n\nconst toImportSpecifier = (fromPath: string, targetPath: string, options?: ImportSpecifierOptions): string => {\n const fromDir = dirname(fromPath);\n const normalized = relative(fromDir, targetPath).replace(/\\\\/g, \"/\");\n const sourceExt = extname(targetPath);\n\n // When includeExtension is false (default), strip the extension entirely\n if (!options?.includeExtension) {\n if (normalized.length === 0) {\n return `./${basename(targetPath, sourceExt)}`;\n }\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n const currentExt = extname(withPrefix);\n return currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n }\n\n // When includeExtension is true, convert to runtime extension\n const runtimeExt = extensionMap[sourceExt] ?? sourceExt;\n\n if (normalized.length === 0) {\n const base = runtimeExt !== sourceExt ? basename(targetPath, sourceExt) : basename(targetPath);\n return `./${base}${runtimeExt}`;\n }\n\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n if (!runtimeExt) {\n return withPrefix;\n }\n if (withPrefix.endsWith(runtimeExt)) {\n return withPrefix;\n }\n\n const currentExt = extname(withPrefix);\n const withoutExt = currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n return `${withoutExt}${runtimeExt}`;\n};\n\nexport const runCodegen = async (options: CodegenOptions): Promise<CodegenResult> => {\n const outPath = resolve(options.outPath);\n const importSpecifierOptions = { includeExtension: options.importExtension };\n\n // Validate that all schema and inject files exist\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n const scalarPath = resolve(schemaConfig.inject.scalars);\n if (!existsSync(scalarPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Scalar module not found for schema '${schemaName}': ${scalarPath}`,\n injectPath: scalarPath,\n });\n }\n\n if (schemaConfig.inject.adapter) {\n const adapterPath = resolve(schemaConfig.inject.adapter);\n if (!existsSync(adapterPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Adapter module not found for schema '${schemaName}': ${adapterPath}`,\n injectPath: adapterPath,\n });\n }\n }\n }\n\n // Load all schemas\n const schemas = new Map<string, import(\"graphql\").DocumentNode>();\n const schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }> = {};\n\n for (const [name, schemaConfig] of Object.entries(options.schemas)) {\n const result = await loadSchema(schemaConfig.schema).match(\n (doc) => Promise.resolve(ok(doc)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (result.isErr()) {\n return err(result.error);\n }\n\n schemas.set(name, result.value);\n }\n\n // Build injection config for each schema\n const injectionConfig = new Map<\n string,\n {\n scalarImportPath: string;\n adapterImportPath?: string;\n }\n >();\n\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n const injectConfig = schemaConfig.inject;\n\n injectionConfig.set(schemaName, {\n scalarImportPath: toImportSpecifier(outPath, resolve(injectConfig.scalars), importSpecifierOptions),\n ...(injectConfig.adapter\n ? { adapterImportPath: toImportSpecifier(outPath, resolve(injectConfig.adapter), importSpecifierOptions) }\n : {}),\n });\n }\n\n // Build defaultInputDepth and inputDepthOverrides config for each schema\n const defaultInputDepthConfig = new Map<string, number>();\n const inputDepthOverridesConfig = new Map<string, Readonly<Record<string, number>>>();\n\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n if (schemaConfig.defaultInputDepth !== undefined && schemaConfig.defaultInputDepth !== 3) {\n defaultInputDepthConfig.set(schemaName, schemaConfig.defaultInputDepth);\n }\n if (schemaConfig.inputDepthOverrides && Object.keys(schemaConfig.inputDepthOverrides).length > 0) {\n inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);\n }\n }\n\n // Generate multi-schema module\n const { code } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\n defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,\n inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,\n });\n\n // Calculate individual schema stats and hashes\n for (const [name, document] of schemas.entries()) {\n const schemaIndex = (await import(\"./generator\")).createSchemaIndex(document);\n const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const unions = Array.from(schemaIndex.unions.keys()).filter((n) => !n.startsWith(\"__\")).length;\n\n schemaHashes[name] = {\n schemaHash: hashSchema(document),\n objects,\n enums,\n inputs,\n unions,\n };\n }\n\n // Write the module\n const writeResult = await writeModule(outPath, code).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (writeResult.isErr()) {\n return err(writeResult.error);\n }\n\n // Bundle the generated module\n const bundleOutcome = await defaultBundler.bundle({\n sourcePath: outPath,\n external: [\"@soda-gql/core\", \"@soda-gql/runtime\"],\n });\n const bundleResult = bundleOutcome.match(\n (result) => ok(result),\n (error) => err(error),\n );\n\n if (bundleResult.isErr()) {\n return err(bundleResult.error);\n }\n\n return ok({\n schemas: schemaHashes,\n outPath,\n cjsPath: bundleResult.value.cjsPath,\n } satisfies CodegenSuccess);\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,mBAAmB;;;;;;;;;;;AAYzB,MAAa,uBAAuB,YAAoB;CACtD,MAAM,oCAAqB,QAAQ;AAEn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c,MAAM,YAAY,SAAS,KAAK,CAAC,YAC7C,QAAQ,2BAAW,UAAU,CAAC,GACnC,UAAU,QAAQ,4BAAY,MAAM,CAAC,CACvC;AAED,KAAI,YAAY,OAAO,EAAE;AACvB,6BAAW,YAAY,MAAM;;CAI/B,MAAM,gBAAgB,MAAMC,eAAe,OAAO;EAChD,YAAY;EACZ,UAAU,CAAC,kBAAkB,oBAAoB;EAClD,CAAC;CACF,MAAM,eAAe,cAAc,OAChC,8BAAc,OAAO,GACrB,8BAAc,MAAM,CACtB;AAED,KAAI,aAAa,OAAO,EAAE;AACxB,6BAAW,aAAa,MAAM;;AAGhC,2BAAU;EACR,SAAS;EACT;EACA,SAAS,aAAa,MAAM;EAC7B,CAA0B"}
1
+ {"version":3,"file":"index.cjs","names":["esbuildBundler: Bundler","typeImports: string[]","runtimeImports: string[]","gqlEntries: string[]","documents: DocumentNode[]","extensionMap: Record<string, string>","withPrefix","currentExt","schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }>","generateMultiSchemaModule","defaultBundler"],"sources":["../src/inject-template.ts","../src/bundler/esbuild.ts","../src/file.ts","../src/prebuilt-generator.ts","../src/schema.ts","../src/runner.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nconst templateContents = `\\\nimport { defineScalar } from \"@soda-gql/core\";\n\nexport const scalar = {\n ...defineScalar<\"ID\", string, string>(\"ID\"),\n ...defineScalar<\"String\", string, string>(\"String\"),\n ...defineScalar<\"Int\", number, number>(\"Int\"),\n ...defineScalar<\"Float\", number, number>(\"Float\"),\n ...defineScalar<\"Boolean\", boolean, boolean>(\"Boolean\"),\n} as const;\n`;\n\nexport const writeInjectTemplate = (outPath: string) => {\n const targetPath = resolve(outPath);\n\n try {\n if (existsSync(targetPath)) {\n return err<void, CodegenError>({\n code: \"INJECT_TEMPLATE_EXISTS\",\n message: `Inject module already exists: ${targetPath}`,\n outPath: targetPath,\n });\n }\n\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, `${templateContents}\\n`);\n return ok<void, CodegenError>(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<void, CodegenError>({\n code: \"INJECT_TEMPLATE_FAILED\",\n message,\n outPath: targetPath,\n });\n }\n};\n\nexport const getInjectTemplate = (): string => `${templateContents}\\n`;\n","import { extname } from \"node:path\";\nimport { build } from \"esbuild\";\nimport { err, ok } from \"neverthrow\";\nimport type { Bundler } from \"./types\";\n\nexport const esbuildBundler: Bundler = {\n name: \"esbuild\",\n bundle: async ({ sourcePath, external }) => {\n try {\n const sourceExt = extname(sourcePath);\n const baseName = sourcePath.slice(0, -sourceExt.length);\n const cjsPath = `${baseName}.cjs`;\n\n await build({\n entryPoints: [sourcePath],\n outfile: cjsPath,\n format: \"cjs\",\n platform: \"node\",\n bundle: true,\n external: [...external],\n sourcemap: false,\n minify: false,\n treeShaking: false,\n });\n\n return ok({ cjsPath });\n } catch (error) {\n return err({\n code: \"EMIT_FAILED\" as const,\n message: `[esbuild] Failed to bundle: ${error instanceof Error ? error.message : String(error)}`,\n outPath: sourcePath,\n });\n }\n },\n};\n","import { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nexport const writeModule = (outPath: string, contents: string) => {\n const targetPath = resolve(outPath);\n\n try {\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, contents);\n return ok<void, CodegenError>(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<void, CodegenError>({\n code: \"EMIT_FAILED\",\n message,\n outPath: targetPath,\n });\n }\n};\n","/**\n * Prebuilt module generator for bundler-compatible type resolution.\n *\n * Generates a prebuilt version of the gql composer that uses\n * PrebuiltTypes for type lookup instead of complex inference.\n *\n * @module\n */\n\nimport type { DocumentNode } from \"graphql\";\n\ntype PrebuiltGeneratorOptions = {\n /**\n * Relative import path to the main gql module.\n * Example: \"../index\" (from prebuilt/index.ts to index.ts)\n */\n readonly mainModulePath: string;\n /**\n * Per-schema injection config (adapter import paths).\n */\n readonly injection?: Map<\n string,\n {\n readonly adapterImportPath?: string;\n }\n >;\n};\n\ntype PrebuiltGeneratedModule = {\n /** The generated code for prebuilt/index.ts */\n readonly indexCode: string;\n /** The generated code for prebuilt/types.ts (placeholder) */\n readonly typesCode: string;\n};\n\n/**\n * Generate the prebuilt module code.\n *\n * This generates:\n * - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes\n * - prebuilt/types.ts: Placeholder types that builder will populate\n */\nexport const generatePrebuiltModule = (\n schemas: Map<string, DocumentNode>,\n options: PrebuiltGeneratorOptions,\n): PrebuiltGeneratedModule => {\n const schemaNames = Array.from(schemas.keys());\n\n // Generate type imports from main module\n const typeImports: string[] = [];\n // Generate runtime imports from main module (the __ prefixed exports)\n const runtimeImports: string[] = [];\n\n for (const name of schemaNames) {\n // Type imports - include Context type from main module\n typeImports.push(`Schema_${name}`, `FragmentBuilders_${name}`, `Context_${name}`);\n\n // Runtime imports\n runtimeImports.push(`__schema_${name}`, `__inputTypeMethods_${name}`, `__directiveMethods_${name}`);\n\n // Check if adapter is used for this schema\n const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;\n if (hasAdapter) {\n typeImports.push(`Adapter_${name}`);\n runtimeImports.push(`__adapter_${name}`);\n }\n }\n\n // Generate gql entries with createPrebuiltGqlElementComposer\n const gqlEntries: string[] = [];\n\n for (const name of schemaNames) {\n const document = schemas.get(name);\n if (!document) continue;\n\n const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;\n\n // Generate gql entry with PrebuiltGqlElementComposer\n // Context type is now imported from main module\n if (hasAdapter) {\n gqlEntries.push(\n ` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}, Adapter_${name}>(__schema_${name}, { adapter: __adapter_${name}, inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`,\n );\n } else {\n gqlEntries.push(\n ` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}>(__schema_${name}, { inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`,\n );\n }\n }\n\n // Generate the prebuilt/index.ts code\n const indexCode = `\\\n/**\n * Prebuilt GQL module for bundler-compatible type resolution.\n *\n * This module uses createPrebuiltGqlElementComposer which looks up types\n * from PrebuiltTypes instead of using complex type inference.\n *\n * @module\n * @generated by @soda-gql/codegen\n */\n\nimport { createPrebuiltGqlElementComposer } from \"@soda-gql/core\";\nimport {\n ${runtimeImports.join(\",\\n \")},\n type ${typeImports.join(\",\\n type \")},\n} from \"${options.mainModulePath}\";\nimport type { ${schemaNames.map((name) => `PrebuiltTypes_${name}`).join(\", \")} } from \"./types\";\n\nexport const gql = {\n${gqlEntries.join(\",\\n\")}\n};\n\n// Re-export types from main module\nexport type { ${typeImports.join(\", \")} };\n`;\n\n // Generate the prebuilt/types.ts placeholder\n const typesCode = `\\\n/**\n * Prebuilt type registry.\n *\n * This file contains placeholder types that will be populated by the builder\n * when running \\`soda-gql build\\` command.\n *\n * @module\n * @generated by @soda-gql/codegen\n */\n\nimport type { EmptyPrebuiltTypeRegistry } from \"@soda-gql/core\";\n\n${schemaNames.map((name) => `// Placeholder for ${name} schema - populated by builder\\nexport type PrebuiltTypes_${name} = EmptyPrebuiltTypeRegistry;`).join(\"\\n\\n\")}\n`;\n\n return {\n indexCode,\n typesCode,\n };\n};\n","import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { concatAST, type DocumentNode, parse, print } from \"graphql\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\n/**\n * Load a single schema file.\n * @internal Use loadSchema for public API.\n */\nexport const loadSingleSchema = (schemaPath: string) => {\n const resolvedPath = resolve(schemaPath);\n\n if (!existsSync(resolvedPath)) {\n return err<DocumentNode, CodegenError>({\n code: \"SCHEMA_NOT_FOUND\",\n message: `Schema file not found at ${resolvedPath}`,\n schemaPath: resolvedPath,\n });\n }\n\n try {\n const schemaSource = readFileSync(resolvedPath, \"utf8\");\n const document = parse(schemaSource);\n return ok<DocumentNode, CodegenError>(document);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<DocumentNode, CodegenError>({\n code: \"SCHEMA_INVALID\",\n message: `SchemaValidationError: ${message}`,\n schemaPath: resolvedPath,\n });\n }\n};\n\n/**\n * Load and merge multiple schema files into a single DocumentNode.\n * Uses GraphQL's concatAST to combine definitions from all files.\n */\nexport const loadSchema = (schemaPaths: readonly string[]) => {\n const documents: DocumentNode[] = [];\n\n for (const schemaPath of schemaPaths) {\n const result = loadSingleSchema(schemaPath);\n if (result.isErr()) {\n return err<DocumentNode, CodegenError>(result.error);\n }\n documents.push(result.value);\n }\n\n // Merge all documents into one\n const merged = concatAST(documents);\n return ok<DocumentNode, CodegenError>(merged);\n};\n\nexport const hashSchema = (document: DocumentNode): string => createHash(\"sha256\").update(print(document)).digest(\"hex\");\n","import { existsSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { basename, dirname, extname, join, relative, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\nimport { defaultBundler } from \"./bundler\";\nimport { writeModule } from \"./file\";\nimport { generateMultiSchemaModule } from \"./generator\";\nimport { generatePrebuiltModule } from \"./prebuilt-generator\";\nimport { hashSchema, loadSchema } from \"./schema\";\nimport type { CodegenOptions, CodegenResult, CodegenSuccess } from \"./types\";\n\nconst extensionMap: Record<string, string> = {\n \".ts\": \".js\",\n \".tsx\": \".js\",\n \".mts\": \".mjs\",\n \".cts\": \".cjs\",\n \".js\": \".js\",\n \".mjs\": \".mjs\",\n \".cjs\": \".cjs\",\n};\n\ntype ImportSpecifierOptions = {\n includeExtension?: boolean;\n};\n\nconst toImportSpecifier = (fromPath: string, targetPath: string, options?: ImportSpecifierOptions): string => {\n const fromDir = dirname(fromPath);\n const normalized = relative(fromDir, targetPath).replace(/\\\\/g, \"/\");\n const sourceExt = extname(targetPath);\n\n // When includeExtension is false (default), strip the extension entirely\n if (!options?.includeExtension) {\n if (normalized.length === 0) {\n return `./${basename(targetPath, sourceExt)}`;\n }\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n const currentExt = extname(withPrefix);\n return currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n }\n\n // When includeExtension is true, convert to runtime extension\n const runtimeExt = extensionMap[sourceExt] ?? sourceExt;\n\n if (normalized.length === 0) {\n const base = runtimeExt !== sourceExt ? basename(targetPath, sourceExt) : basename(targetPath);\n return `./${base}${runtimeExt}`;\n }\n\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n if (!runtimeExt) {\n return withPrefix;\n }\n if (withPrefix.endsWith(runtimeExt)) {\n return withPrefix;\n }\n\n const currentExt = extname(withPrefix);\n const withoutExt = currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n return `${withoutExt}${runtimeExt}`;\n};\n\nexport const runCodegen = async (options: CodegenOptions): Promise<CodegenResult> => {\n const outPath = resolve(options.outPath);\n const importSpecifierOptions = { includeExtension: options.importExtension };\n\n // Validate that all schema and inject files exist\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n const scalarPath = resolve(schemaConfig.inject.scalars);\n if (!existsSync(scalarPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Scalar module not found for schema '${schemaName}': ${scalarPath}`,\n injectPath: scalarPath,\n });\n }\n\n if (schemaConfig.inject.adapter) {\n const adapterPath = resolve(schemaConfig.inject.adapter);\n if (!existsSync(adapterPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Adapter module not found for schema '${schemaName}': ${adapterPath}`,\n injectPath: adapterPath,\n });\n }\n }\n }\n\n // Load all schemas\n const schemas = new Map<string, import(\"graphql\").DocumentNode>();\n const schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }> = {};\n\n for (const [name, schemaConfig] of Object.entries(options.schemas)) {\n const result = await loadSchema(schemaConfig.schema).match(\n (doc) => Promise.resolve(ok(doc)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (result.isErr()) {\n return err(result.error);\n }\n\n schemas.set(name, result.value);\n }\n\n // Build injection config for each schema\n const injectionConfig = new Map<\n string,\n {\n scalarImportPath: string;\n adapterImportPath?: string;\n }\n >();\n\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n const injectConfig = schemaConfig.inject;\n\n injectionConfig.set(schemaName, {\n scalarImportPath: toImportSpecifier(outPath, resolve(injectConfig.scalars), importSpecifierOptions),\n ...(injectConfig.adapter\n ? { adapterImportPath: toImportSpecifier(outPath, resolve(injectConfig.adapter), importSpecifierOptions) }\n : {}),\n });\n }\n\n // Build defaultInputDepth and inputDepthOverrides config for each schema\n const defaultInputDepthConfig = new Map<string, number>();\n const inputDepthOverridesConfig = new Map<string, Readonly<Record<string, number>>>();\n\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n if (schemaConfig.defaultInputDepth !== undefined && schemaConfig.defaultInputDepth !== 3) {\n defaultInputDepthConfig.set(schemaName, schemaConfig.defaultInputDepth);\n }\n if (schemaConfig.inputDepthOverrides && Object.keys(schemaConfig.inputDepthOverrides).length > 0) {\n inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);\n }\n }\n\n // Generate multi-schema module\n const { code } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\n defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,\n inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,\n exportForPrebuilt: options.prebuilt,\n });\n\n // Calculate individual schema stats and hashes\n for (const [name, document] of schemas.entries()) {\n const schemaIndex = (await import(\"./generator\")).createSchemaIndex(document);\n const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const unions = Array.from(schemaIndex.unions.keys()).filter((n) => !n.startsWith(\"__\")).length;\n\n schemaHashes[name] = {\n schemaHash: hashSchema(document),\n objects,\n enums,\n inputs,\n unions,\n };\n }\n\n // Write the module\n const writeResult = await writeModule(outPath, code).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (writeResult.isErr()) {\n return err(writeResult.error);\n }\n\n // Generate and write prebuilt module if requested\n if (options.prebuilt) {\n const prebuiltDir = join(dirname(outPath), \"prebuilt\");\n await mkdir(prebuiltDir, { recursive: true });\n\n // Calculate relative import path from prebuilt/index.ts to index.ts\n const mainModulePath = toImportSpecifier(join(prebuiltDir, \"index.ts\"), outPath, importSpecifierOptions);\n\n const prebuilt = generatePrebuiltModule(schemas, {\n mainModulePath,\n injection: injectionConfig,\n });\n\n // Write prebuilt/index.ts\n const prebuiltIndexPath = join(prebuiltDir, \"index.ts\");\n const prebuiltIndexResult = await writeModule(prebuiltIndexPath, prebuilt.indexCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (prebuiltIndexResult.isErr()) {\n return err(prebuiltIndexResult.error);\n }\n\n // Write prebuilt/types.ts\n const prebuiltTypesPath = join(prebuiltDir, \"types.ts\");\n const prebuiltTypesResult = await writeModule(prebuiltTypesPath, prebuilt.typesCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (prebuiltTypesResult.isErr()) {\n return err(prebuiltTypesResult.error);\n }\n\n // Bundle prebuilt module\n const prebuiltBundleOutcome = await defaultBundler.bundle({\n sourcePath: prebuiltIndexPath,\n external: [\"@soda-gql/core\", \"@soda-gql/runtime\"],\n });\n\n if (prebuiltBundleOutcome.isErr()) {\n return err(prebuiltBundleOutcome.error);\n }\n }\n\n // Bundle the generated module\n const bundleOutcome = await defaultBundler.bundle({\n sourcePath: outPath,\n external: [\"@soda-gql/core\", \"@soda-gql/runtime\"],\n });\n const bundleResult = bundleOutcome.match(\n (result) => ok(result),\n (error) => err(error),\n );\n\n if (bundleResult.isErr()) {\n return err(bundleResult.error);\n }\n\n return ok({\n schemas: schemaHashes,\n outPath,\n cjsPath: bundleResult.value.cjsPath,\n } satisfies CodegenSuccess);\n};\n"],"mappings":";;;;;;;;;;AAMA,MAAM,mBAAmB;;;;;;;;;;;AAYzB,MAAa,uBAAuB,YAAoB;CACtD,MAAM,oCAAqB,QAAQ;AAEnC,KAAI;AACF,8BAAe,WAAW,EAAE;AAC1B,8BAA+B;IAC7B,MAAM;IACN,SAAS,iCAAiC;IAC1C,SAAS;IACV,CAAC;;AAGJ,gDAAkB,WAAW,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,6BAAc,YAAY,GAAG,iBAAiB,IAAI;AAClD,4BAA8B,UAAU;UACjC,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,6BAA+B;GAC7B,MAAM;GACN;GACA,SAAS;GACV,CAAC;;;AAIN,MAAa,0BAAkC,GAAG,iBAAiB;;;;ACtCnE,MAAaA,iBAA0B;CACrC,MAAM;CACN,QAAQ,OAAO,EAAE,YAAY,eAAe;AAC1C,MAAI;GACF,MAAM,mCAAoB,WAAW;GACrC,MAAM,WAAW,WAAW,MAAM,GAAG,CAAC,UAAU,OAAO;GACvD,MAAM,UAAU,GAAG,SAAS;AAE5B,4BAAY;IACV,aAAa,CAAC,WAAW;IACzB,SAAS;IACT,QAAQ;IACR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B,QAAQ,EAAE,WAAW;AACtD,oCAAY,aAAa,EAAE,WAAW,MAAM,CAAC;EAG7C,MAAM,iBAAiB,sCAAuB,aAAa,WAAW,EAAE,SAAS,uBAAuB;EAExG,MAAM,WAAW,uBAAuB,SAAS;GAC/C;GACA,WAAW;GACZ,CAAC;EAGF,MAAM,wCAAyB,aAAa,WAAW;EACvD,MAAM,sBAAsB,MAAM,YAAY,mBAAmB,SAAS,UAAU,CAAC,YAC7E,QAAQ,2BAAW,UAAU,CAAC,GACnC,UAAU,QAAQ,4BAAY,MAAM,CAAC,CACvC;AAED,MAAI,oBAAoB,OAAO,EAAE;AAC/B,8BAAW,oBAAoB,MAAM;;EAIvC,MAAM,wCAAyB,aAAa,WAAW;EACvD,MAAM,sBAAsB,MAAM,YAAY,mBAAmB,SAAS,UAAU,CAAC,YAC7E,QAAQ,2BAAW,UAAU,CAAC,GACnC,UAAU,QAAQ,4BAAY,MAAM,CAAC,CACvC;AAED,MAAI,oBAAoB,OAAO,EAAE;AAC/B,8BAAW,oBAAoB,MAAM;;EAIvC,MAAM,wBAAwB,MAAMC,eAAe,OAAO;GACxD,YAAY;GACZ,UAAU,CAAC,kBAAkB,oBAAoB;GAClD,CAAC;AAEF,MAAI,sBAAsB,OAAO,EAAE;AACjC,8BAAW,sBAAsB,MAAM;;;CAK3C,MAAM,gBAAgB,MAAMA,eAAe,OAAO;EAChD,YAAY;EACZ,UAAU,CAAC,kBAAkB,oBAAoB;EAClD,CAAC;CACF,MAAM,eAAe,cAAc,OAChC,8BAAc,OAAO,GACrB,8BAAc,MAAM,CACtB;AAED,KAAI,aAAa,OAAO,EAAE;AACxB,6BAAW,aAAa,MAAM;;AAGhC,2BAAU;EACR,SAAS;EACT;EACA,SAAS,aAAa,MAAM;EAC7B,CAA0B"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import * as neverthrow0 from "neverthrow";
1
+ import * as neverthrow3 from "neverthrow";
2
2
  import { Result } from "neverthrow";
3
3
  import { DocumentNode } from "graphql";
4
4
 
@@ -9,7 +9,7 @@ type CodegenInjectConfig = {
9
9
  readonly adapter?: string;
10
10
  };
11
11
  type CodegenSchemaConfig = {
12
- readonly schema: string;
12
+ readonly schema: readonly string[];
13
13
  readonly inject: CodegenInjectConfig;
14
14
  readonly defaultInputDepth?: number;
15
15
  readonly inputDepthOverrides?: Readonly<Record<string, number>>;
@@ -19,6 +19,8 @@ type CodegenOptions = {
19
19
  readonly outPath: string;
20
20
  readonly format: CodegenFormat;
21
21
  readonly importExtension?: boolean;
22
+ /** Generate prebuilt module for bundler-compatible type resolution. */
23
+ readonly prebuilt?: boolean;
22
24
  };
23
25
  type CodegenCliCommand = {
24
26
  readonly kind: "generate";
@@ -70,14 +72,23 @@ type CodegenSuccess = {
70
72
  type CodegenResult = Result<CodegenSuccess, CodegenError>;
71
73
  //#endregion
72
74
  //#region packages/codegen/src/inject-template.d.ts
73
- declare const writeInjectTemplate: (outPath: string) => neverthrow0.Err<void, CodegenError> | neverthrow0.Ok<void, CodegenError>;
75
+ declare const writeInjectTemplate: (outPath: string) => neverthrow3.Err<void, CodegenError> | neverthrow3.Ok<void, CodegenError>;
74
76
  declare const getInjectTemplate: () => string;
75
77
  //#endregion
76
78
  //#region packages/codegen/src/runner.d.ts
77
79
  declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
78
80
  //#endregion
79
81
  //#region packages/codegen/src/schema.d.ts
80
- declare const loadSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
82
+ /**
83
+ * Load a single schema file.
84
+ * @internal Use loadSchema for public API.
85
+ */
86
+ declare const loadSingleSchema: (schemaPath: string) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
87
+ /**
88
+ * Load and merge multiple schema files into a single DocumentNode.
89
+ * Uses GraphQL's concatAST to combine definitions from all files.
90
+ */
91
+ declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
81
92
  declare const hashSchema: (document: DocumentNode) => string;
82
93
  //#endregion
83
94
  export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type CodegenInjectConfig, type CodegenOptions, type CodegenResult, type CodegenSchemaConfig, type CodegenSuccess, hashSchema, loadSchema, runCodegen, writeInjectTemplate };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/inject-template.ts","../src/runner.ts","../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;KAEY,aAAA;KAGA,mBAAA;;;AAHZ,CAAA;AAGY,KAMA,mBAAA,GANmB;EAMnB,SAAA,MAAA,EAAA,MAAmB;EAEZ,SAAA,MAAA,EAAA,mBAAA;EAEuB,SAAA,iBAAA,CAAA,EAAA,MAAA;EAAT,SAAA,mBAAA,CAAA,EAAA,QAAA,CAAS,MAAT,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;CAAQ;AAG7B,KAAA,cAAA,GAAc;EACS,SAAA,OAAA,EAAf,MAAe,CAAA,MAAA,EAAA,mBAAA,CAAA;EAAf,SAAA,OAAA,EAAA,MAAA;EAED,SAAA,MAAA,EAAA,aAAA;EAAa,SAAA,eAAA,CAAA,EAAA,OAAA;AAIhC,CAAA;AAWY,KAXA,iBAAA,GAWY;EAoCZ,SAAA,IAAA,EAAA,UAAc;EAed,SAAA,OAAa,EA3DD,cA2DC;CAAU,GAAA;EAAgB,SAAA,IAAA,EAAA,oBAAA;EAAvB,SAAA,OAAA,EAAA,MAAA;EAAM,SAAA,MAAA,EAtDX,aAsDW;;KAnDtB,YAAA;;EClBC,SAAA,OAAA,EAAA,MAuBZ;EAvBkD,SAAA,UAAA,EAAA,MAAA;CAAA,GAAA;EAAA,SAAA,IAAA,EAAA,gBAAA;EAAA,SAAA,OAAA,EAAA,MAAA;EAAA,SAAA,UAAA,EAAA,MAAA;AAyBnD,CAAA,GAAa;;;;ACg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B,CGOoB,YHPpB,EGOoB,YHPpB,CAAA,GGOoB,WAAA,CAAA,EHPpB,CGOoB,YHPpB,EGOoB,YHPpB,CAAA;AAM/B;;;;AAIyC,cG0B5B,UH1B4B,EAAA,CAAA,WAAA,EAAA,SAAA,MAAA,EAAA,EAAA,GG0BgB,WAAA,CAAA,GH1BhB,CG0BgB,YH1BhB,EG0BgB,YH1BhB,CAAA,GG0BgB,WAAA,CAAA,EH1BhB,CG0BgB,YH1BhB,EG0BgB,YH1BhB,CAAA;AAG7B,cGuCC,UHvCa,EAAA,CAAA,QAAA,EGuCW,YHvCX,EAAA,GAAA,MAAA"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as neverthrow1 from "neverthrow";
1
+ import * as neverthrow0 from "neverthrow";
2
2
  import { Result } from "neverthrow";
3
3
  import { DocumentNode } from "graphql";
4
4
 
@@ -9,7 +9,7 @@ type CodegenInjectConfig = {
9
9
  readonly adapter?: string;
10
10
  };
11
11
  type CodegenSchemaConfig = {
12
- readonly schema: string;
12
+ readonly schema: readonly string[];
13
13
  readonly inject: CodegenInjectConfig;
14
14
  readonly defaultInputDepth?: number;
15
15
  readonly inputDepthOverrides?: Readonly<Record<string, number>>;
@@ -19,6 +19,8 @@ type CodegenOptions = {
19
19
  readonly outPath: string;
20
20
  readonly format: CodegenFormat;
21
21
  readonly importExtension?: boolean;
22
+ /** Generate prebuilt module for bundler-compatible type resolution. */
23
+ readonly prebuilt?: boolean;
22
24
  };
23
25
  type CodegenCliCommand = {
24
26
  readonly kind: "generate";
@@ -70,14 +72,23 @@ type CodegenSuccess = {
70
72
  type CodegenResult = Result<CodegenSuccess, CodegenError>;
71
73
  //#endregion
72
74
  //#region packages/codegen/src/inject-template.d.ts
73
- declare const writeInjectTemplate: (outPath: string) => neverthrow1.Err<void, CodegenError> | neverthrow1.Ok<void, CodegenError>;
75
+ declare const writeInjectTemplate: (outPath: string) => neverthrow0.Err<void, CodegenError> | neverthrow0.Ok<void, CodegenError>;
74
76
  declare const getInjectTemplate: () => string;
75
77
  //#endregion
76
78
  //#region packages/codegen/src/runner.d.ts
77
79
  declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
78
80
  //#endregion
79
81
  //#region packages/codegen/src/schema.d.ts
80
- declare const loadSchema: (schemaPath: string) => neverthrow1.Err<DocumentNode, CodegenError> | neverthrow1.Ok<DocumentNode, CodegenError>;
82
+ /**
83
+ * Load a single schema file.
84
+ * @internal Use loadSchema for public API.
85
+ */
86
+ declare const loadSingleSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
87
+ /**
88
+ * Load and merge multiple schema files into a single DocumentNode.
89
+ * Uses GraphQL's concatAST to combine definitions from all files.
90
+ */
91
+ declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
81
92
  declare const hashSchema: (document: DocumentNode) => string;
82
93
  //#endregion
83
94
  export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type CodegenInjectConfig, type CodegenOptions, type CodegenResult, type CodegenSchemaConfig, type CodegenSuccess, hashSchema, loadSchema, runCodegen, writeInjectTemplate };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/inject-template.ts","../src/runner.ts","../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;KAEY,aAAA;KAGA,mBAAA;;;AAHZ,CAAA;AAGY,KAMA,mBAAA,GANmB;EAMnB,SAAA,MAAA,EAAA,MAAmB;EAEZ,SAAA,MAAA,EAAA,mBAAA;EAEuB,SAAA,iBAAA,CAAA,EAAA,MAAA;EAAT,SAAA,mBAAA,CAAA,EAAA,QAAA,CAAS,MAAT,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;CAAQ;AAG7B,KAAA,cAAA,GAAc;EACS,SAAA,OAAA,EAAf,MAAe,CAAA,MAAA,EAAA,mBAAA,CAAA;E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A6BtC,SAAA,OAcZ,EAAA,MAAA;CAdwD;AAAA,KHiC7C,cAAA,GGjC6C;EAAA,SAAA,OAAA,EHkCrC,MGlCqC,CAAA,MAAA,EAAA;IAAA,SAAA,UAAA,EAAA,MAAA;IAAA,SAAA,OAAA,EAAA,MAAA;IAAA,SAAA,KAAA,EAAA,MAAA;IAAA,SAAA,MAAA,EAAA,MAAA;IAgB5C,SAA2G,MAAA,EAAA,MAAnF;;;;;KHgCzB,aAAA,GAAgB,OAAO,gBAAgB;;;cCvEtC,0CAAsC,WAAA,CAAA,UAAA,gBAAA,WAAA,CAAA,SAAA;cAyBtC;;;cCkBA,sBAA6B,mBAAiB,QAAQ;;;;;;AF3DnE;AAGY,cGOC,gBHPkB,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GGOoB,WAAA,CAAA,GHPpB,CGOoB,YHPpB,EGOoB,YHPpB,CAAA,GGOoB,WAAA,CAAA,EHPpB,CGOoB,YHPpB,EGOoB,YHPpB,CAAA;AAM/B;;;;AAIyC,cG0B5B,UH1B4B,EAAA,CAAA,WAAA,EAAA,SAAA,MAAA,EAAA,EAAA,GG0BgB,WAAA,CAAA,GH1BhB,CG0BgB,YH1BhB,EG0BgB,YH1BhB,CAAA,GG0BgB,WAAA,CAAA,EH1BhB,CG0BgB,YH1BhB,EG0BgB,YH1BhB,CAAA;AAG7B,cGuCC,UHvCa,EAAA,CAAA,QAAA,EGuCW,YHvCX,EAAA,GAAA,MAAA"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
- import { n as generateMultiSchemaModule } from "./generator-CvzOeank.mjs";
1
+ import { n as generateMultiSchemaModule } from "./generator-DnaEVxKH.mjs";
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { basename, dirname, extname, relative, resolve } from "node:path";
3
+ import { basename, dirname, extname, join, relative, resolve } from "node:path";
4
4
  import { err, ok } from "neverthrow";
5
+ import { mkdir } from "node:fs/promises";
5
6
  import { build } from "esbuild";
6
- import { parse, print } from "graphql";
7
+ import { concatAST, parse, print } from "graphql";
7
8
  import { createHash } from "node:crypto";
8
9
 
9
10
  //#region packages/codegen/src/inject-template.ts
@@ -91,9 +92,92 @@ const writeModule = (outPath, contents) => {
91
92
  }
92
93
  };
93
94
 
95
+ //#endregion
96
+ //#region packages/codegen/src/prebuilt-generator.ts
97
+ /**
98
+ * Generate the prebuilt module code.
99
+ *
100
+ * This generates:
101
+ * - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes
102
+ * - prebuilt/types.ts: Placeholder types that builder will populate
103
+ */
104
+ const generatePrebuiltModule = (schemas, options) => {
105
+ const schemaNames = Array.from(schemas.keys());
106
+ const typeImports = [];
107
+ const runtimeImports = [];
108
+ for (const name of schemaNames) {
109
+ typeImports.push(`Schema_${name}`, `FragmentBuilders_${name}`, `Context_${name}`);
110
+ runtimeImports.push(`__schema_${name}`, `__inputTypeMethods_${name}`, `__directiveMethods_${name}`);
111
+ const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
112
+ if (hasAdapter) {
113
+ typeImports.push(`Adapter_${name}`);
114
+ runtimeImports.push(`__adapter_${name}`);
115
+ }
116
+ }
117
+ const gqlEntries = [];
118
+ for (const name of schemaNames) {
119
+ const document = schemas.get(name);
120
+ if (!document) continue;
121
+ const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
122
+ if (hasAdapter) {
123
+ gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}, Adapter_${name}>(__schema_${name}, { adapter: __adapter_${name}, inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
124
+ } else {
125
+ gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}>(__schema_${name}, { inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
126
+ }
127
+ }
128
+ const indexCode = `\
129
+ /**
130
+ * Prebuilt GQL module for bundler-compatible type resolution.
131
+ *
132
+ * This module uses createPrebuiltGqlElementComposer which looks up types
133
+ * from PrebuiltTypes instead of using complex type inference.
134
+ *
135
+ * @module
136
+ * @generated by @soda-gql/codegen
137
+ */
138
+
139
+ import { createPrebuiltGqlElementComposer } from "@soda-gql/core";
140
+ import {
141
+ ${runtimeImports.join(",\n ")},
142
+ type ${typeImports.join(",\n type ")},
143
+ } from "${options.mainModulePath}";
144
+ import type { ${schemaNames.map((name) => `PrebuiltTypes_${name}`).join(", ")} } from "./types";
145
+
146
+ export const gql = {
147
+ ${gqlEntries.join(",\n")}
148
+ };
149
+
150
+ // Re-export types from main module
151
+ export type { ${typeImports.join(", ")} };
152
+ `;
153
+ const typesCode = `\
154
+ /**
155
+ * Prebuilt type registry.
156
+ *
157
+ * This file contains placeholder types that will be populated by the builder
158
+ * when running \`soda-gql build\` command.
159
+ *
160
+ * @module
161
+ * @generated by @soda-gql/codegen
162
+ */
163
+
164
+ import type { EmptyPrebuiltTypeRegistry } from "@soda-gql/core";
165
+
166
+ ${schemaNames.map((name) => `// Placeholder for ${name} schema - populated by builder\nexport type PrebuiltTypes_${name} = EmptyPrebuiltTypeRegistry;`).join("\n\n")}
167
+ `;
168
+ return {
169
+ indexCode,
170
+ typesCode
171
+ };
172
+ };
173
+
94
174
  //#endregion
95
175
  //#region packages/codegen/src/schema.ts
96
- const loadSchema = (schemaPath) => {
176
+ /**
177
+ * Load a single schema file.
178
+ * @internal Use loadSchema for public API.
179
+ */
180
+ const loadSingleSchema = (schemaPath) => {
97
181
  const resolvedPath = resolve(schemaPath);
98
182
  if (!existsSync(resolvedPath)) {
99
183
  return err({
@@ -115,6 +199,22 @@ const loadSchema = (schemaPath) => {
115
199
  });
116
200
  }
117
201
  };
202
+ /**
203
+ * Load and merge multiple schema files into a single DocumentNode.
204
+ * Uses GraphQL's concatAST to combine definitions from all files.
205
+ */
206
+ const loadSchema = (schemaPaths) => {
207
+ const documents = [];
208
+ for (const schemaPath of schemaPaths) {
209
+ const result = loadSingleSchema(schemaPath);
210
+ if (result.isErr()) {
211
+ return err(result.error);
212
+ }
213
+ documents.push(result.value);
214
+ }
215
+ const merged = concatAST(documents);
216
+ return ok(merged);
217
+ };
118
218
  const hashSchema = (document) => createHash("sha256").update(print(document)).digest("hex");
119
219
 
120
220
  //#endregion
@@ -209,10 +309,11 @@ const runCodegen = async (options) => {
209
309
  const { code } = generateMultiSchemaModule(schemas, {
210
310
  injection: injectionConfig,
211
311
  defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
212
- inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
312
+ inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,
313
+ exportForPrebuilt: options.prebuilt
213
314
  });
214
315
  for (const [name, document] of schemas.entries()) {
215
- const schemaIndex = (await import("./generator-DVB6dq7n.mjs")).createSchemaIndex(document);
316
+ const schemaIndex = (await import("./generator-_yjlHz2T.mjs")).createSchemaIndex(document);
216
317
  const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
217
318
  const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
218
319
  const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
@@ -229,6 +330,32 @@ const runCodegen = async (options) => {
229
330
  if (writeResult.isErr()) {
230
331
  return err(writeResult.error);
231
332
  }
333
+ if (options.prebuilt) {
334
+ const prebuiltDir = join(dirname(outPath), "prebuilt");
335
+ await mkdir(prebuiltDir, { recursive: true });
336
+ const mainModulePath = toImportSpecifier(join(prebuiltDir, "index.ts"), outPath, importSpecifierOptions);
337
+ const prebuilt = generatePrebuiltModule(schemas, {
338
+ mainModulePath,
339
+ injection: injectionConfig
340
+ });
341
+ const prebuiltIndexPath = join(prebuiltDir, "index.ts");
342
+ const prebuiltIndexResult = await writeModule(prebuiltIndexPath, prebuilt.indexCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
343
+ if (prebuiltIndexResult.isErr()) {
344
+ return err(prebuiltIndexResult.error);
345
+ }
346
+ const prebuiltTypesPath = join(prebuiltDir, "types.ts");
347
+ const prebuiltTypesResult = await writeModule(prebuiltTypesPath, prebuilt.typesCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
348
+ if (prebuiltTypesResult.isErr()) {
349
+ return err(prebuiltTypesResult.error);
350
+ }
351
+ const prebuiltBundleOutcome = await esbuildBundler.bundle({
352
+ sourcePath: prebuiltIndexPath,
353
+ external: ["@soda-gql/core", "@soda-gql/runtime"]
354
+ });
355
+ if (prebuiltBundleOutcome.isErr()) {
356
+ return err(prebuiltBundleOutcome.error);
357
+ }
358
+ }
232
359
  const bundleOutcome = await esbuildBundler.bundle({
233
360
  sourcePath: outPath,
234
361
  external: ["@soda-gql/core", "@soda-gql/runtime"]