@soda-gql/codegen 0.5.2 → 0.5.3

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
@@ -196,7 +196,21 @@ const runCodegen = async (options) => {
196
196
  ...injectConfig.adapter ? { adapterImportPath: toImportSpecifier(outPath, (0, node_path.resolve)(injectConfig.adapter), importSpecifierOptions) } : {}
197
197
  });
198
198
  }
199
- const { code } = require_generator.generateMultiSchemaModule(schemas, { injection: injectionConfig });
199
+ const defaultInputDepthConfig = new Map();
200
+ const inputDepthOverridesConfig = new Map();
201
+ for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {
202
+ if (schemaConfig.defaultInputDepth !== undefined && schemaConfig.defaultInputDepth !== 3) {
203
+ defaultInputDepthConfig.set(schemaName, schemaConfig.defaultInputDepth);
204
+ }
205
+ if (schemaConfig.inputDepthOverrides && Object.keys(schemaConfig.inputDepthOverrides).length > 0) {
206
+ inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);
207
+ }
208
+ }
209
+ const { code } = require_generator.generateMultiSchemaModule(schemas, {
210
+ injection: injectionConfig,
211
+ defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
212
+ inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
213
+ });
200
214
  for (const [name, document] of schemas.entries()) {
201
215
  const schemaIndex = (await Promise.resolve().then(() => require("./generator-Dr445O16.cjs"))).createSchemaIndex(document);
202
216
  const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
@@ -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 // Generate multi-schema module\n const { code } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\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;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,UAAU;IACV,QAAQ;IACR,UAAU,CAAC,GAAG,SAAS;IACvB,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AK,CAAC,CAAC;AAExF,eAAa,QAAQ;GACnB,YAAY,WAAW,SAAS;GAChC;GACA;GACA;GACA;GACD;;CAIH,MAAM,cAAc,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","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;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,UAAU;IACV,QAAQ;IACR,UAAU,CA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2CAAM,8BAAuB,kBAAkB,SAAS;EAC7E,MAAM,UAAU,MAAM,KAAK,YAAY,QAAQ,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;EAC1F,MAAM,QAAQ,MAAM,KAAK,YAAY,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;EACtF,MAAM,SAAS,MAAM,KAAK,YAAY,OAAO,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;EACxF,MAAM,SAAS,MAAM,KAAK,YAAY,OAAO,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;AAExF,eAAa,QAAQ;GACnB,YAAY,WAAW,SAAS;GAChC;GACA;GACA;GACA;GACD;;CAIH,MAAM,cAAc,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"}
package/dist/index.mjs CHANGED
@@ -196,7 +196,21 @@ const runCodegen = async (options) => {
196
196
  ...injectConfig.adapter ? { adapterImportPath: toImportSpecifier(outPath, resolve(injectConfig.adapter), importSpecifierOptions) } : {}
197
197
  });
198
198
  }
199
- const { code } = generateMultiSchemaModule(schemas, { injection: injectionConfig });
199
+ const defaultInputDepthConfig = new Map();
200
+ const inputDepthOverridesConfig = new Map();
201
+ for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {
202
+ if (schemaConfig.defaultInputDepth !== undefined && schemaConfig.defaultInputDepth !== 3) {
203
+ defaultInputDepthConfig.set(schemaName, schemaConfig.defaultInputDepth);
204
+ }
205
+ if (schemaConfig.inputDepthOverrides && Object.keys(schemaConfig.inputDepthOverrides).length > 0) {
206
+ inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);
207
+ }
208
+ }
209
+ const { code } = generateMultiSchemaModule(schemas, {
210
+ injection: injectionConfig,
211
+ defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
212
+ inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
213
+ });
200
214
  for (const [name, document] of schemas.entries()) {
201
215
  const schemaIndex = (await import("./generator-LDU9eA31.mjs")).createSchemaIndex(document);
202
216
  const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["esbuildBundler: Bundler","extensionMap: Record<string, string>","withPrefix","currentExt","schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }>","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 // Generate multi-schema module\n const { code } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\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 cjsP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C,GACnC,UAAU,QAAQ,QAAQ,IAAI,MAAM,CAAC,CACvC;AAED,KAAI,YAAY,OAAO,EAAE;AACvB,SAAO,IAAI,YAAY,MAAM;;CAI/B,MAAM,gBAAgB,MAAMC,eAAe,OAAO;EAChD,YAAY;EACZ,UAAU,CAAC,kBAAkB,oBAAoB;EAClD,CAAC;CACF,MAAM,eAAe,cAAc,OAChC,WAAW,GAAG,OAAO,GACrB,UAAU,IAAI,MAAM,CACtB;AAED,KAAI,aAAa,OAAO,EAAE;AACxB,SAAO,IAAI,aAAa,MAAM;;AAGhC,QAAO,GAAG;EACR,SAAS;EACT;EACA,SAAS,aAAa,MAAM;EAC7B,CAA0B"}
1
+ {"version":3,"file":"index.mjs","names":["esbuildBundler: Bundler","extensionMap: Record<string, string>","withPrefix","currentExt","schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }>","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,aAAa,QAAQ,QAAQ;AAEnC,KAAI;AACF,MAAI,WAAW,WAAW,EAAE;AAC1B,UAAO,IAAwB;IAC7B,MAAM;IACN,SAAS,iCAAiC;IAC1C,SAAS;IACV,CAAC;;AAGJ,YAAU,QAAQ,WAAW,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,gBAAc,YAAY,GAAG,iBAAiB,IAAI;AAClD,SAAO,GAAuB,UAAU;UACjC,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,SAAO,IAAwB;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,YAAY,QAAQ,WAAW;GACrC,MAAM,WAAW,WAAW,MAAM,GAAG,CAAC,UAAU,OAAO;GACvD,MAAM,UAAU,GAAG,SAAS;AAE5B,SAAM,MAAM;IACV,aAAa,CAAC,WAAW;IACzB,SAAS;IACT,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,UAAU,CAAC,GAAG,SAAS;IACvB,WAAW;IACX,QAAQ;IACR,aAAa;IACd,CAAC;AAEF,UAAO,GAAG,EAAE,SAAS,CAAC;WACf,OAAO;AAC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code generation for soda-gql",
5
5
  "type": "module",
6
6
  "private": false,
@@ -46,8 +46,8 @@
46
46
  "./package.json": "./package.json"
47
47
  },
48
48
  "dependencies": {
49
- "@soda-gql/core": "0.5.2",
50
- "@soda-gql/runtime": "0.5.2",
49
+ "@soda-gql/core": "0.5.3",
50
+ "@soda-gql/runtime": "0.5.3",
51
51
  "esbuild": "^0.24.0",
52
52
  "graphql": "^16.8.1",
53
53
  "neverthrow": "^8.1.1"