@soda-gql/codegen 0.9.0 → 0.9.1
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 +21 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +13 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +22 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -93,7 +93,11 @@ const writeModule = (outPath, contents) => {
|
|
|
93
93
|
|
|
94
94
|
//#endregion
|
|
95
95
|
//#region packages/codegen/src/schema.ts
|
|
96
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Load a single schema file.
|
|
98
|
+
* @internal Use loadSchema for public API.
|
|
99
|
+
*/
|
|
100
|
+
const loadSingleSchema = (schemaPath) => {
|
|
97
101
|
const resolvedPath = (0, node_path.resolve)(schemaPath);
|
|
98
102
|
if (!(0, node_fs.existsSync)(resolvedPath)) {
|
|
99
103
|
return (0, neverthrow.err)({
|
|
@@ -115,6 +119,22 @@ const loadSchema = (schemaPath) => {
|
|
|
115
119
|
});
|
|
116
120
|
}
|
|
117
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Load and merge multiple schema files into a single DocumentNode.
|
|
124
|
+
* Uses GraphQL's concatAST to combine definitions from all files.
|
|
125
|
+
*/
|
|
126
|
+
const loadSchema = (schemaPaths) => {
|
|
127
|
+
const documents = [];
|
|
128
|
+
for (const schemaPath of schemaPaths) {
|
|
129
|
+
const result = loadSingleSchema(schemaPath);
|
|
130
|
+
if (result.isErr()) {
|
|
131
|
+
return (0, neverthrow.err)(result.error);
|
|
132
|
+
}
|
|
133
|
+
documents.push(result.value);
|
|
134
|
+
}
|
|
135
|
+
const merged = (0, graphql.concatAST)(documents);
|
|
136
|
+
return (0, neverthrow.ok)(merged);
|
|
137
|
+
};
|
|
118
138
|
const hashSchema = (document) => (0, node_crypto.createHash)("sha256").update((0, graphql.print)(document)).digest("hex");
|
|
119
139
|
|
|
120
140
|
//#endregion
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 } sat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AAQ,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"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["esbuildBundler: Bundler","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/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 { 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 { 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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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.d.cts
CHANGED
|
@@ -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>>;
|
|
@@ -77,7 +77,16 @@ declare const getInjectTemplate: () => string;
|
|
|
77
77
|
declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
|
|
78
78
|
//#endregion
|
|
79
79
|
//#region packages/codegen/src/schema.d.ts
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Load a single schema file.
|
|
82
|
+
* @internal Use loadSchema for public API.
|
|
83
|
+
*/
|
|
84
|
+
declare const loadSingleSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
85
|
+
/**
|
|
86
|
+
* Load and merge multiple schema files into a single DocumentNode.
|
|
87
|
+
* Uses GraphQL's concatAST to combine definitions from all files.
|
|
88
|
+
*/
|
|
89
|
+
declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
81
90
|
declare const hashSchema: (document: DocumentNode) => string;
|
|
82
91
|
//#endregion
|
|
83
92
|
export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type CodegenInjectConfig, type CodegenOptions, type CodegenResult, type CodegenSchemaConfig, type CodegenSuccess, hashSchema, loadSchema, runCodegen, writeInjectTemplate };
|
package/dist/index.d.cts.map
CHANGED
|
@@ -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,
|
|
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,SAAmB,MAAA,EAAA;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;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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
|
|
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>>;
|
|
@@ -70,14 +70,23 @@ type CodegenSuccess = {
|
|
|
70
70
|
type CodegenResult = Result<CodegenSuccess, CodegenError>;
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region packages/codegen/src/inject-template.d.ts
|
|
73
|
-
declare const writeInjectTemplate: (outPath: string) =>
|
|
73
|
+
declare const writeInjectTemplate: (outPath: string) => neverthrow0.Err<void, CodegenError> | neverthrow0.Ok<void, CodegenError>;
|
|
74
74
|
declare const getInjectTemplate: () => string;
|
|
75
75
|
//#endregion
|
|
76
76
|
//#region packages/codegen/src/runner.d.ts
|
|
77
77
|
declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
|
|
78
78
|
//#endregion
|
|
79
79
|
//#region packages/codegen/src/schema.d.ts
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Load a single schema file.
|
|
82
|
+
* @internal Use loadSchema for public API.
|
|
83
|
+
*/
|
|
84
|
+
declare const loadSingleSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
85
|
+
/**
|
|
86
|
+
* Load and merge multiple schema files into a single DocumentNode.
|
|
87
|
+
* Uses GraphQL's concatAST to combine definitions from all files.
|
|
88
|
+
*/
|
|
89
|
+
declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
81
90
|
declare const hashSchema: (document: DocumentNode) => string;
|
|
82
91
|
//#endregion
|
|
83
92
|
export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type CodegenInjectConfig, type CodegenOptions, type CodegenResult, type CodegenSchemaConfig, type CodegenSuccess, hashSchema, loadSchema, runCodegen, writeInjectTemplate };
|
package/dist/index.d.mts.map
CHANGED
|
@@ -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,
|
|
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,SAAmB,MAAA,EAAA;EAEZ,SAAA,MAAA,EAAA,mBAAA;EAEuB,SAAA,iBAAA,CAAA,EAAA,MAAA;EAAT,SAAA,mBAAA,CAAA,EAAA,QAAA,CAAS,MAAT,CAAA,MAA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SAAA,OAA2G,EAAA,MAAA;;;KH8B5G,aAAA,GAAgB,OAAO,gBAAgB;;;cCrEtC,0CAAsC,WAAA,CAAA,UAAA,gBAAA,WAAA,CAAA,SAAA;cAyBtC;;;cCgBA,sBAA6B,mBAAiB,QAAQ;;;;;;AFzDnE;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
|
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
3
3
|
import { basename, dirname, extname, relative, resolve } from "node:path";
|
|
4
4
|
import { err, ok } from "neverthrow";
|
|
5
5
|
import { build } from "esbuild";
|
|
6
|
-
import { parse, print } from "graphql";
|
|
6
|
+
import { concatAST, parse, print } from "graphql";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
|
|
9
9
|
//#region packages/codegen/src/inject-template.ts
|
|
@@ -93,7 +93,11 @@ const writeModule = (outPath, contents) => {
|
|
|
93
93
|
|
|
94
94
|
//#endregion
|
|
95
95
|
//#region packages/codegen/src/schema.ts
|
|
96
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Load a single schema file.
|
|
98
|
+
* @internal Use loadSchema for public API.
|
|
99
|
+
*/
|
|
100
|
+
const loadSingleSchema = (schemaPath) => {
|
|
97
101
|
const resolvedPath = resolve(schemaPath);
|
|
98
102
|
if (!existsSync(resolvedPath)) {
|
|
99
103
|
return err({
|
|
@@ -115,6 +119,22 @@ const loadSchema = (schemaPath) => {
|
|
|
115
119
|
});
|
|
116
120
|
}
|
|
117
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Load and merge multiple schema files into a single DocumentNode.
|
|
124
|
+
* Uses GraphQL's concatAST to combine definitions from all files.
|
|
125
|
+
*/
|
|
126
|
+
const loadSchema = (schemaPaths) => {
|
|
127
|
+
const documents = [];
|
|
128
|
+
for (const schemaPath of schemaPaths) {
|
|
129
|
+
const result = loadSingleSchema(schemaPath);
|
|
130
|
+
if (result.isErr()) {
|
|
131
|
+
return err(result.error);
|
|
132
|
+
}
|
|
133
|
+
documents.push(result.value);
|
|
134
|
+
}
|
|
135
|
+
const merged = concatAST(documents);
|
|
136
|
+
return ok(merged);
|
|
137
|
+
};
|
|
118
138
|
const hashSchema = (document) => createHash("sha256").update(print(document)).digest("hex");
|
|
119
139
|
|
|
120
140
|
//#endregion
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 // 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,MA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AO,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","documents: DocumentNode[]","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 { 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 { 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,U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