@soda-gql/codegen 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{generator-DnaEVxKH.mjs → generator-CGLIILli.mjs} +73 -39
- package/dist/generator-CGLIILli.mjs.map +1 -0
- package/dist/{generator-B-ATtEt4.cjs → generator-Ct01cfhS.cjs} +73 -39
- package/dist/generator-Ct01cfhS.cjs.map +1 -0
- package/dist/{generator-HOw0EOk_.cjs → generator-DfFQbVNB.cjs} +1 -1
- package/dist/generator-j4CLEIBx.mjs +3 -0
- package/dist/index.cjs +27 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +27 -113
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/generator-B-ATtEt4.cjs.map +0 -1
- package/dist/generator-DnaEVxKH.mjs.map +0 -1
- package/dist/generator-_yjlHz2T.mjs +0 -3
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
const require_generator = require('./generator-
|
|
1
|
+
const require_generator = require('./generator-Ct01cfhS.cjs');
|
|
2
2
|
let node_fs = require("node:fs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
let neverthrow = require("neverthrow");
|
|
5
|
-
let node_fs_promises = require("node:fs/promises");
|
|
6
5
|
let esbuild = require("esbuild");
|
|
7
6
|
let graphql = require("graphql");
|
|
8
7
|
let node_crypto = require("node:crypto");
|
|
@@ -92,85 +91,6 @@ const writeModule = (outPath, contents) => {
|
|
|
92
91
|
}
|
|
93
92
|
};
|
|
94
93
|
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region packages/codegen/src/prebuilt-generator.ts
|
|
97
|
-
/**
|
|
98
|
-
* Generate the prebuilt module code.
|
|
99
|
-
*
|
|
100
|
-
* This generates:
|
|
101
|
-
* - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes
|
|
102
|
-
* - prebuilt/types.ts: Placeholder types that builder will populate
|
|
103
|
-
*/
|
|
104
|
-
const generatePrebuiltModule = (schemas, options) => {
|
|
105
|
-
const schemaNames = Array.from(schemas.keys());
|
|
106
|
-
const typeImports = [];
|
|
107
|
-
const runtimeImports = [];
|
|
108
|
-
for (const name of schemaNames) {
|
|
109
|
-
typeImports.push(`Schema_${name}`, `FragmentBuilders_${name}`, `Context_${name}`);
|
|
110
|
-
runtimeImports.push(`__schema_${name}`, `__inputTypeMethods_${name}`, `__directiveMethods_${name}`);
|
|
111
|
-
const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
|
|
112
|
-
if (hasAdapter) {
|
|
113
|
-
typeImports.push(`Adapter_${name}`);
|
|
114
|
-
runtimeImports.push(`__adapter_${name}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const gqlEntries = [];
|
|
118
|
-
for (const name of schemaNames) {
|
|
119
|
-
const document = schemas.get(name);
|
|
120
|
-
if (!document) continue;
|
|
121
|
-
const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
|
|
122
|
-
if (hasAdapter) {
|
|
123
|
-
gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}, Adapter_${name}>(__schema_${name}, { adapter: __adapter_${name}, inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
|
|
124
|
-
} else {
|
|
125
|
-
gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}>(__schema_${name}, { inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const indexCode = `\
|
|
129
|
-
/**
|
|
130
|
-
* Prebuilt GQL module for bundler-compatible type resolution.
|
|
131
|
-
*
|
|
132
|
-
* This module uses createPrebuiltGqlElementComposer which looks up types
|
|
133
|
-
* from PrebuiltTypes instead of using complex type inference.
|
|
134
|
-
*
|
|
135
|
-
* @module
|
|
136
|
-
* @generated by @soda-gql/codegen
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
import { createPrebuiltGqlElementComposer } from "@soda-gql/core";
|
|
140
|
-
import {
|
|
141
|
-
${runtimeImports.join(",\n ")},
|
|
142
|
-
type ${typeImports.join(",\n type ")},
|
|
143
|
-
} from "${options.mainModulePath}";
|
|
144
|
-
import type { ${schemaNames.map((name) => `PrebuiltTypes_${name}`).join(", ")} } from "./types";
|
|
145
|
-
|
|
146
|
-
export const gql = {
|
|
147
|
-
${gqlEntries.join(",\n")}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// Re-export types from main module
|
|
151
|
-
export type { ${typeImports.join(", ")} };
|
|
152
|
-
`;
|
|
153
|
-
const typesCode = `\
|
|
154
|
-
/**
|
|
155
|
-
* Prebuilt type registry.
|
|
156
|
-
*
|
|
157
|
-
* This file contains placeholder types that will be populated by the builder
|
|
158
|
-
* when running \`soda-gql build\` command.
|
|
159
|
-
*
|
|
160
|
-
* @module
|
|
161
|
-
* @generated by @soda-gql/codegen
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
import type { EmptyPrebuiltTypeRegistry } from "@soda-gql/core";
|
|
165
|
-
|
|
166
|
-
${schemaNames.map((name) => `// Placeholder for ${name} schema - populated by builder\nexport type PrebuiltTypes_${name} = EmptyPrebuiltTypeRegistry;`).join("\n\n")}
|
|
167
|
-
`;
|
|
168
|
-
return {
|
|
169
|
-
indexCode,
|
|
170
|
-
typesCode
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
|
|
174
94
|
//#endregion
|
|
175
95
|
//#region packages/codegen/src/schema.ts
|
|
176
96
|
/**
|
|
@@ -306,14 +226,20 @@ const runCodegen = async (options) => {
|
|
|
306
226
|
inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);
|
|
307
227
|
}
|
|
308
228
|
}
|
|
309
|
-
const { code } = require_generator.generateMultiSchemaModule(schemas, {
|
|
229
|
+
const { code: internalCode, injectsCode } = require_generator.generateMultiSchemaModule(schemas, {
|
|
310
230
|
injection: injectionConfig,
|
|
311
231
|
defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
|
|
312
|
-
inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
|
|
313
|
-
exportForPrebuilt: options.prebuilt
|
|
232
|
+
inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
|
|
314
233
|
});
|
|
234
|
+
const indexCode = `/**
|
|
235
|
+
* Generated by @soda-gql/codegen
|
|
236
|
+
* @module
|
|
237
|
+
* @generated
|
|
238
|
+
*/
|
|
239
|
+
export * from "./_internal";
|
|
240
|
+
`;
|
|
315
241
|
for (const [name, document] of schemas.entries()) {
|
|
316
|
-
const schemaIndex = (await Promise.resolve().then(() => require("./generator-
|
|
242
|
+
const schemaIndex = (await Promise.resolve().then(() => require("./generator-DfFQbVNB.cjs"))).createSchemaIndex(document);
|
|
317
243
|
const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
|
|
318
244
|
const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
|
|
319
245
|
const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
|
|
@@ -326,36 +252,22 @@ const runCodegen = async (options) => {
|
|
|
326
252
|
unions
|
|
327
253
|
};
|
|
328
254
|
}
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const prebuiltDir = (0, node_path.join)((0, node_path.dirname)(outPath), "prebuilt");
|
|
335
|
-
await (0, node_fs_promises.mkdir)(prebuiltDir, { recursive: true });
|
|
336
|
-
const mainModulePath = toImportSpecifier((0, node_path.join)(prebuiltDir, "index.ts"), outPath, importSpecifierOptions);
|
|
337
|
-
const prebuilt = generatePrebuiltModule(schemas, {
|
|
338
|
-
mainModulePath,
|
|
339
|
-
injection: injectionConfig
|
|
340
|
-
});
|
|
341
|
-
const prebuiltIndexPath = (0, node_path.join)(prebuiltDir, "index.ts");
|
|
342
|
-
const prebuiltIndexResult = await writeModule(prebuiltIndexPath, prebuilt.indexCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
343
|
-
if (prebuiltIndexResult.isErr()) {
|
|
344
|
-
return (0, neverthrow.err)(prebuiltIndexResult.error);
|
|
345
|
-
}
|
|
346
|
-
const prebuiltTypesPath = (0, node_path.join)(prebuiltDir, "types.ts");
|
|
347
|
-
const prebuiltTypesResult = await writeModule(prebuiltTypesPath, prebuilt.typesCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
348
|
-
if (prebuiltTypesResult.isErr()) {
|
|
349
|
-
return (0, neverthrow.err)(prebuiltTypesResult.error);
|
|
350
|
-
}
|
|
351
|
-
const prebuiltBundleOutcome = await esbuildBundler.bundle({
|
|
352
|
-
sourcePath: prebuiltIndexPath,
|
|
353
|
-
external: ["@soda-gql/core", "@soda-gql/runtime"]
|
|
354
|
-
});
|
|
355
|
-
if (prebuiltBundleOutcome.isErr()) {
|
|
356
|
-
return (0, neverthrow.err)(prebuiltBundleOutcome.error);
|
|
255
|
+
const injectsPath = (0, node_path.join)((0, node_path.dirname)(outPath), "_internal-injects.ts");
|
|
256
|
+
if (injectsCode) {
|
|
257
|
+
const injectsWriteResult = await writeModule(injectsPath, injectsCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
258
|
+
if (injectsWriteResult.isErr()) {
|
|
259
|
+
return (0, neverthrow.err)(injectsWriteResult.error);
|
|
357
260
|
}
|
|
358
261
|
}
|
|
262
|
+
const internalPath = (0, node_path.join)((0, node_path.dirname)(outPath), "_internal.ts");
|
|
263
|
+
const internalWriteResult = await writeModule(internalPath, internalCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
264
|
+
if (internalWriteResult.isErr()) {
|
|
265
|
+
return (0, neverthrow.err)(internalWriteResult.error);
|
|
266
|
+
}
|
|
267
|
+
const indexWriteResult = await writeModule(outPath, indexCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
268
|
+
if (indexWriteResult.isErr()) {
|
|
269
|
+
return (0, neverthrow.err)(indexWriteResult.error);
|
|
270
|
+
}
|
|
359
271
|
const bundleOutcome = await esbuildBundler.bundle({
|
|
360
272
|
sourcePath: outPath,
|
|
361
273
|
external: ["@soda-gql/core", "@soda-gql/runtime"]
|
|
@@ -367,6 +279,8 @@ const runCodegen = async (options) => {
|
|
|
367
279
|
return (0, neverthrow.ok)({
|
|
368
280
|
schemas: schemaHashes,
|
|
369
281
|
outPath,
|
|
282
|
+
internalPath,
|
|
283
|
+
injectsPath,
|
|
370
284
|
cjsPath: bundleResult.value.cjsPath
|
|
371
285
|
});
|
|
372
286
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["esbuildBundler: Bundler","typeImports: string[]","runtimeImports: string[]","gqlEntries: string[]","documents: DocumentNode[]","extensionMap: Record<string, string>","withPrefix","currentExt","schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }>","generateMultiSchemaModule","defaultBundler"],"sources":["../src/inject-template.ts","../src/bundler/esbuild.ts","../src/file.ts","../src/prebuilt-generator.ts","../src/schema.ts","../src/runner.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nconst templateContents = `\\\nimport { defineScalar } from \"@soda-gql/core\";\n\nexport const scalar = {\n ...defineScalar<\"ID\", string, string>(\"ID\"),\n ...defineScalar<\"String\", string, string>(\"String\"),\n ...defineScalar<\"Int\", number, number>(\"Int\"),\n ...defineScalar<\"Float\", number, number>(\"Float\"),\n ...defineScalar<\"Boolean\", boolean, boolean>(\"Boolean\"),\n} as const;\n`;\n\nexport const writeInjectTemplate = (outPath: string) => {\n const targetPath = resolve(outPath);\n\n try {\n if (existsSync(targetPath)) {\n return err<void, CodegenError>({\n code: \"INJECT_TEMPLATE_EXISTS\",\n message: `Inject module already exists: ${targetPath}`,\n outPath: targetPath,\n });\n }\n\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, `${templateContents}\\n`);\n return ok<void, CodegenError>(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<void, CodegenError>({\n code: \"INJECT_TEMPLATE_FAILED\",\n message,\n outPath: targetPath,\n });\n }\n};\n\nexport const getInjectTemplate = (): string => `${templateContents}\\n`;\n","import { extname } from \"node:path\";\nimport { build } from \"esbuild\";\nimport { err, ok } from \"neverthrow\";\nimport type { Bundler } from \"./types\";\n\nexport const esbuildBundler: Bundler = {\n name: \"esbuild\",\n bundle: async ({ sourcePath, external }) => {\n try {\n const sourceExt = extname(sourcePath);\n const baseName = sourcePath.slice(0, -sourceExt.length);\n const cjsPath = `${baseName}.cjs`;\n\n await build({\n entryPoints: [sourcePath],\n outfile: cjsPath,\n format: \"cjs\",\n platform: \"node\",\n bundle: true,\n external: [...external],\n sourcemap: false,\n minify: false,\n treeShaking: false,\n });\n\n return ok({ cjsPath });\n } catch (error) {\n return err({\n code: \"EMIT_FAILED\" as const,\n message: `[esbuild] Failed to bundle: ${error instanceof Error ? error.message : String(error)}`,\n outPath: sourcePath,\n });\n }\n },\n};\n","import { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\nexport const writeModule = (outPath: string, contents: string) => {\n const targetPath = resolve(outPath);\n\n try {\n mkdirSync(dirname(targetPath), { recursive: true });\n writeFileSync(targetPath, contents);\n return ok<void, CodegenError>(undefined);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<void, CodegenError>({\n code: \"EMIT_FAILED\",\n message,\n outPath: targetPath,\n });\n }\n};\n","/**\n * Prebuilt module generator for bundler-compatible type resolution.\n *\n * Generates a prebuilt version of the gql composer that uses\n * PrebuiltTypes for type lookup instead of complex inference.\n *\n * @module\n */\n\nimport type { DocumentNode } from \"graphql\";\n\ntype PrebuiltGeneratorOptions = {\n /**\n * Relative import path to the main gql module.\n * Example: \"../index\" (from prebuilt/index.ts to index.ts)\n */\n readonly mainModulePath: string;\n /**\n * Per-schema injection config (adapter import paths).\n */\n readonly injection?: Map<\n string,\n {\n readonly adapterImportPath?: string;\n }\n >;\n};\n\ntype PrebuiltGeneratedModule = {\n /** The generated code for prebuilt/index.ts */\n readonly indexCode: string;\n /** The generated code for prebuilt/types.ts (placeholder) */\n readonly typesCode: string;\n};\n\n/**\n * Generate the prebuilt module code.\n *\n * This generates:\n * - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes\n * - prebuilt/types.ts: Placeholder types that builder will populate\n */\nexport const generatePrebuiltModule = (\n schemas: Map<string, DocumentNode>,\n options: PrebuiltGeneratorOptions,\n): PrebuiltGeneratedModule => {\n const schemaNames = Array.from(schemas.keys());\n\n // Generate type imports from main module\n const typeImports: string[] = [];\n // Generate runtime imports from main module (the __ prefixed exports)\n const runtimeImports: string[] = [];\n\n for (const name of schemaNames) {\n // Type imports - include Context type from main module\n typeImports.push(`Schema_${name}`, `FragmentBuilders_${name}`, `Context_${name}`);\n\n // Runtime imports\n runtimeImports.push(`__schema_${name}`, `__inputTypeMethods_${name}`, `__directiveMethods_${name}`);\n\n // Check if adapter is used for this schema\n const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;\n if (hasAdapter) {\n typeImports.push(`Adapter_${name}`);\n runtimeImports.push(`__adapter_${name}`);\n }\n }\n\n // Generate gql entries with createPrebuiltGqlElementComposer\n const gqlEntries: string[] = [];\n\n for (const name of schemaNames) {\n const document = schemas.get(name);\n if (!document) continue;\n\n const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;\n\n // Generate gql entry with PrebuiltGqlElementComposer\n // Context type is now imported from main module\n if (hasAdapter) {\n gqlEntries.push(\n ` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}, Adapter_${name}>(__schema_${name}, { adapter: __adapter_${name}, inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`,\n );\n } else {\n gqlEntries.push(\n ` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}>(__schema_${name}, { inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`,\n );\n }\n }\n\n // Generate the prebuilt/index.ts code\n const indexCode = `\\\n/**\n * Prebuilt GQL module for bundler-compatible type resolution.\n *\n * This module uses createPrebuiltGqlElementComposer which looks up types\n * from PrebuiltTypes instead of using complex type inference.\n *\n * @module\n * @generated by @soda-gql/codegen\n */\n\nimport { createPrebuiltGqlElementComposer } from \"@soda-gql/core\";\nimport {\n ${runtimeImports.join(\",\\n \")},\n type ${typeImports.join(\",\\n type \")},\n} from \"${options.mainModulePath}\";\nimport type { ${schemaNames.map((name) => `PrebuiltTypes_${name}`).join(\", \")} } from \"./types\";\n\nexport const gql = {\n${gqlEntries.join(\",\\n\")}\n};\n\n// Re-export types from main module\nexport type { ${typeImports.join(\", \")} };\n`;\n\n // Generate the prebuilt/types.ts placeholder\n const typesCode = `\\\n/**\n * Prebuilt type registry.\n *\n * This file contains placeholder types that will be populated by the builder\n * when running \\`soda-gql build\\` command.\n *\n * @module\n * @generated by @soda-gql/codegen\n */\n\nimport type { EmptyPrebuiltTypeRegistry } from \"@soda-gql/core\";\n\n${schemaNames.map((name) => `// Placeholder for ${name} schema - populated by builder\\nexport type PrebuiltTypes_${name} = EmptyPrebuiltTypeRegistry;`).join(\"\\n\\n\")}\n`;\n\n return {\n indexCode,\n typesCode,\n };\n};\n","import { createHash } from \"node:crypto\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { concatAST, type DocumentNode, parse, print } from \"graphql\";\nimport { err, ok } from \"neverthrow\";\n\nimport type { CodegenError } from \"./types\";\n\n/**\n * Load a single schema file.\n * @internal Use loadSchema for public API.\n */\nexport const loadSingleSchema = (schemaPath: string) => {\n const resolvedPath = resolve(schemaPath);\n\n if (!existsSync(resolvedPath)) {\n return err<DocumentNode, CodegenError>({\n code: \"SCHEMA_NOT_FOUND\",\n message: `Schema file not found at ${resolvedPath}`,\n schemaPath: resolvedPath,\n });\n }\n\n try {\n const schemaSource = readFileSync(resolvedPath, \"utf8\");\n const document = parse(schemaSource);\n return ok<DocumentNode, CodegenError>(document);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return err<DocumentNode, CodegenError>({\n code: \"SCHEMA_INVALID\",\n message: `SchemaValidationError: ${message}`,\n schemaPath: resolvedPath,\n });\n }\n};\n\n/**\n * Load and merge multiple schema files into a single DocumentNode.\n * Uses GraphQL's concatAST to combine definitions from all files.\n */\nexport const loadSchema = (schemaPaths: readonly string[]) => {\n const documents: DocumentNode[] = [];\n\n for (const schemaPath of schemaPaths) {\n const result = loadSingleSchema(schemaPath);\n if (result.isErr()) {\n return err<DocumentNode, CodegenError>(result.error);\n }\n documents.push(result.value);\n }\n\n // Merge all documents into one\n const merged = concatAST(documents);\n return ok<DocumentNode, CodegenError>(merged);\n};\n\nexport const hashSchema = (document: DocumentNode): string => createHash(\"sha256\").update(print(document)).digest(\"hex\");\n","import { existsSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { basename, dirname, extname, join, relative, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\nimport { defaultBundler } from \"./bundler\";\nimport { writeModule } from \"./file\";\nimport { generateMultiSchemaModule } from \"./generator\";\nimport { generatePrebuiltModule } from \"./prebuilt-generator\";\nimport { hashSchema, loadSchema } from \"./schema\";\nimport type { CodegenOptions, CodegenResult, CodegenSuccess } from \"./types\";\n\nconst extensionMap: Record<string, string> = {\n \".ts\": \".js\",\n \".tsx\": \".js\",\n \".mts\": \".mjs\",\n \".cts\": \".cjs\",\n \".js\": \".js\",\n \".mjs\": \".mjs\",\n \".cjs\": \".cjs\",\n};\n\ntype ImportSpecifierOptions = {\n includeExtension?: boolean;\n};\n\nconst toImportSpecifier = (fromPath: string, targetPath: string, options?: ImportSpecifierOptions): string => {\n const fromDir = dirname(fromPath);\n const normalized = relative(fromDir, targetPath).replace(/\\\\/g, \"/\");\n const sourceExt = extname(targetPath);\n\n // When includeExtension is false (default), strip the extension entirely\n if (!options?.includeExtension) {\n if (normalized.length === 0) {\n return `./${basename(targetPath, sourceExt)}`;\n }\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n const currentExt = extname(withPrefix);\n return currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n }\n\n // When includeExtension is true, convert to runtime extension\n const runtimeExt = extensionMap[sourceExt] ?? sourceExt;\n\n if (normalized.length === 0) {\n const base = runtimeExt !== sourceExt ? basename(targetPath, sourceExt) : basename(targetPath);\n return `./${base}${runtimeExt}`;\n }\n\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n if (!runtimeExt) {\n return withPrefix;\n }\n if (withPrefix.endsWith(runtimeExt)) {\n return withPrefix;\n }\n\n const currentExt = extname(withPrefix);\n const withoutExt = currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n return `${withoutExt}${runtimeExt}`;\n};\n\nexport const runCodegen = async (options: CodegenOptions): Promise<CodegenResult> => {\n const outPath = resolve(options.outPath);\n const importSpecifierOptions = { includeExtension: options.importExtension };\n\n // Validate that all schema and inject files exist\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n const scalarPath = resolve(schemaConfig.inject.scalars);\n if (!existsSync(scalarPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Scalar module not found for schema '${schemaName}': ${scalarPath}`,\n injectPath: scalarPath,\n });\n }\n\n if (schemaConfig.inject.adapter) {\n const adapterPath = resolve(schemaConfig.inject.adapter);\n if (!existsSync(adapterPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Adapter module not found for schema '${schemaName}': ${adapterPath}`,\n injectPath: adapterPath,\n });\n }\n }\n }\n\n // Load all schemas\n const schemas = new Map<string, import(\"graphql\").DocumentNode>();\n const schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }> = {};\n\n for (const [name, schemaConfig] of Object.entries(options.schemas)) {\n const result = await loadSchema(schemaConfig.schema).match(\n (doc) => Promise.resolve(ok(doc)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (result.isErr()) {\n return err(result.error);\n }\n\n schemas.set(name, result.value);\n }\n\n // Build injection config for each schema\n const injectionConfig = new Map<\n string,\n {\n scalarImportPath: string;\n adapterImportPath?: string;\n }\n >();\n\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n const injectConfig = schemaConfig.inject;\n\n injectionConfig.set(schemaName, {\n scalarImportPath: toImportSpecifier(outPath, resolve(injectConfig.scalars), importSpecifierOptions),\n ...(injectConfig.adapter\n ? { adapterImportPath: toImportSpecifier(outPath, resolve(injectConfig.adapter), importSpecifierOptions) }\n : {}),\n });\n }\n\n // Build defaultInputDepth and inputDepthOverrides config for each schema\n const defaultInputDepthConfig = new Map<string, number>();\n const inputDepthOverridesConfig = new Map<string, Readonly<Record<string, number>>>();\n\n for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {\n if (schemaConfig.defaultInputDepth !== undefined && schemaConfig.defaultInputDepth !== 3) {\n defaultInputDepthConfig.set(schemaName, schemaConfig.defaultInputDepth);\n }\n if (schemaConfig.inputDepthOverrides && Object.keys(schemaConfig.inputDepthOverrides).length > 0) {\n inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);\n }\n }\n\n // Generate multi-schema module\n const { code } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\n defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,\n inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,\n exportForPrebuilt: options.prebuilt,\n });\n\n // Calculate individual schema stats and hashes\n for (const [name, document] of schemas.entries()) {\n const schemaIndex = (await import(\"./generator\")).createSchemaIndex(document);\n const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const unions = Array.from(schemaIndex.unions.keys()).filter((n) => !n.startsWith(\"__\")).length;\n\n schemaHashes[name] = {\n schemaHash: hashSchema(document),\n objects,\n enums,\n inputs,\n unions,\n };\n }\n\n // Write the module\n const writeResult = await writeModule(outPath, code).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (writeResult.isErr()) {\n return err(writeResult.error);\n }\n\n // Generate and write prebuilt module if requested\n if (options.prebuilt) {\n const prebuiltDir = join(dirname(outPath), \"prebuilt\");\n await mkdir(prebuiltDir, { recursive: true });\n\n // Calculate relative import path from prebuilt/index.ts to index.ts\n const mainModulePath = toImportSpecifier(join(prebuiltDir, \"index.ts\"), outPath, importSpecifierOptions);\n\n const prebuilt = generatePrebuiltModule(schemas, {\n mainModulePath,\n injection: injectionConfig,\n });\n\n // Write prebuilt/index.ts\n const prebuiltIndexPath = join(prebuiltDir, \"index.ts\");\n const prebuiltIndexResult = await writeModule(prebuiltIndexPath, prebuilt.indexCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (prebuiltIndexResult.isErr()) {\n return err(prebuiltIndexResult.error);\n }\n\n // Write prebuilt/types.ts\n const prebuiltTypesPath = join(prebuiltDir, \"types.ts\");\n const prebuiltTypesResult = await writeModule(prebuiltTypesPath, prebuilt.typesCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (prebuiltTypesResult.isErr()) {\n return err(prebuiltTypesResult.error);\n }\n\n // Bundle prebuilt module\n const prebuiltBundleOutcome = await defaultBundler.bundle({\n sourcePath: prebuiltIndexPath,\n external: [\"@soda-gql/core\", \"@soda-gql/runtime\"],\n });\n\n if (prebuiltBundleOutcome.isErr()) {\n return err(prebuiltBundleOutcome.error);\n }\n }\n\n // Bundle the generated module\n const bundleOutcome = await defaultBundler.bundle({\n sourcePath: outPath,\n external: [\"@soda-gql/core\", \"@soda-gql/runtime\"],\n });\n const bundleResult = bundleOutcome.match(\n (result) => ok(result),\n (error) => err(error),\n );\n\n if (bundleResult.isErr()) {\n return err(bundleResult.error);\n }\n\n return ok({\n schemas: schemaHashes,\n outPath,\n cjsPath: bundleResult.value.cjsPath,\n } satisfies CodegenSuccess);\n};\n"],"mappings":";;;;;;;;;;AAMA,MAAM,mBAAmB;;;;;;;;;;;AAYzB,MAAa,uBAAuB,YAAoB;CACtD,MAAM,oCAAqB,QAAQ;AAEnC,KAAI;AACF,8BAAe,WAAW,EAAE;AAC1B,8BAA+B;IAC7B,MAAM;IACN,SAAS,iCAAiC;IAC1C,SAAS;IACV,CAAC;;AAGJ,gDAAkB,WAAW,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,6BAAc,YAAY,GAAG,iBAAiB,IAAI;AACl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8BAAW,sBAAsB,MAAM;;;CAK3C,MAAM,gBAAgB,MAAMA,eAAe,OAAO;EAChD,YAAY;EACZ,UAAU,CAAC,kBAAkB,oBAAoB;EAClD,CAAC;CACF,MAAM,eAAe,cAAc,OAChC,8BAAc,OAAO,GACrB,8BAAc,MAAM,CACtB;AAED,KAAI,aAAa,OAAO,EAAE;AACxB,6BAAW,aAAa,MAAM;;AAGhC,2BAAU;EACR,SAAS;EACT;EACA,SAAS,aAAa,MAAM;EAC7B,CAA0B"}
|
|
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, join, 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 (this becomes _internal.ts content)\n const { code: internalCode, injectsCode } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\n defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,\n inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,\n });\n\n // Generate index.ts wrapper (simple re-export from _internal)\n const indexCode = `/**\n * Generated by @soda-gql/codegen\n * @module\n * @generated\n */\nexport * from \"./_internal\";\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 _internal-injects.ts (adapter imports only, referenced by both _internal.ts and prebuilt)\n const injectsPath = join(dirname(outPath), \"_internal-injects.ts\");\n if (injectsCode) {\n const injectsWriteResult = await writeModule(injectsPath, injectsCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (injectsWriteResult.isErr()) {\n return err(injectsWriteResult.error);\n }\n }\n\n // Write _internal.ts (implementation)\n const internalPath = join(dirname(outPath), \"_internal.ts\");\n const internalWriteResult = await writeModule(internalPath, internalCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (internalWriteResult.isErr()) {\n return err(internalWriteResult.error);\n }\n\n // Write index.ts (re-export wrapper)\n const indexWriteResult = await writeModule(outPath, indexCode).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (indexWriteResult.isErr()) {\n return err(indexWriteResult.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 internalPath,\n injectsPath,\n cjsPath: bundleResult.value.cjsPath,\n } satisfies CodegenSuccess);\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,mBAAmB;;;;;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;AACxB,6BAAW,aAAa,MAAM;;AAGhC,2BAAU;EACR,SAAS;EACT;EACA;EACA;EACA,SAAS,aAAa,MAAM;EAC7B,CAA0B"}
|
package/dist/index.d.cts
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
|
|
|
@@ -19,8 +19,6 @@ type CodegenOptions = {
|
|
|
19
19
|
readonly outPath: string;
|
|
20
20
|
readonly format: CodegenFormat;
|
|
21
21
|
readonly importExtension?: boolean;
|
|
22
|
-
/** Generate prebuilt module for bundler-compatible type resolution. */
|
|
23
|
-
readonly prebuilt?: boolean;
|
|
24
22
|
};
|
|
25
23
|
type CodegenCliCommand = {
|
|
26
24
|
readonly kind: "generate";
|
|
@@ -67,12 +65,14 @@ type CodegenSuccess = {
|
|
|
67
65
|
readonly unions: number;
|
|
68
66
|
}>;
|
|
69
67
|
readonly outPath: string;
|
|
68
|
+
readonly internalPath: string;
|
|
69
|
+
readonly injectsPath: string;
|
|
70
70
|
readonly cjsPath: string;
|
|
71
71
|
};
|
|
72
72
|
type CodegenResult = Result<CodegenSuccess, CodegenError>;
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region packages/codegen/src/inject-template.d.ts
|
|
75
|
-
declare const writeInjectTemplate: (outPath: string) =>
|
|
75
|
+
declare const writeInjectTemplate: (outPath: string) => neverthrow0.Err<void, CodegenError> | neverthrow0.Ok<void, CodegenError>;
|
|
76
76
|
declare const getInjectTemplate: () => string;
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region packages/codegen/src/runner.d.ts
|
|
@@ -83,12 +83,12 @@ declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
|
|
|
83
83
|
* Load a single schema file.
|
|
84
84
|
* @internal Use loadSchema for public API.
|
|
85
85
|
*/
|
|
86
|
-
declare const loadSingleSchema: (schemaPath: string) =>
|
|
86
|
+
declare const loadSingleSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
87
87
|
/**
|
|
88
88
|
* Load and merge multiple schema files into a single DocumentNode.
|
|
89
89
|
* Uses GraphQL's concatAST to combine definitions from all files.
|
|
90
90
|
*/
|
|
91
|
-
declare const loadSchema: (schemaPaths: readonly string[]) =>
|
|
91
|
+
declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
92
92
|
declare const hashSchema: (document: DocumentNode) => string;
|
|
93
93
|
//#endregion
|
|
94
94
|
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,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;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","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MAAA;EAAA,SAAA,OAAA,EAAA,MAAA;CAAA;AA6BtC,KH+BD,cAAA,GGjBX;EAdwD,SAAA,OAAA,EHgCrC,MGhCqC,CAAA,MAAA,EAAA;IAAA,SAAA,UAAA,EAAA,MAAA;IAAA,SAAA,OAAA,EAAA,MAAA;IAAA,SAAA,KAAA,EAAA,MAAA;IAAA,SAAA,MAAA,EAAA,MAAA;IAAA,SAAA,MAAA,EAAA,MAAA;EAAA,CAAA,CAAA;EAgB5C,SAAA,OAA2G,EAAA,MAAA;;;;;KHgC5G,aAAA,GAAgB,OAAO,gBAAgB;;;cCvEtC,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.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as neverthrow3 from "neverthrow";
|
|
2
2
|
import { Result } from "neverthrow";
|
|
3
3
|
import { DocumentNode } from "graphql";
|
|
4
4
|
|
|
@@ -19,8 +19,6 @@ type CodegenOptions = {
|
|
|
19
19
|
readonly outPath: string;
|
|
20
20
|
readonly format: CodegenFormat;
|
|
21
21
|
readonly importExtension?: boolean;
|
|
22
|
-
/** Generate prebuilt module for bundler-compatible type resolution. */
|
|
23
|
-
readonly prebuilt?: boolean;
|
|
24
22
|
};
|
|
25
23
|
type CodegenCliCommand = {
|
|
26
24
|
readonly kind: "generate";
|
|
@@ -67,12 +65,14 @@ type CodegenSuccess = {
|
|
|
67
65
|
readonly unions: number;
|
|
68
66
|
}>;
|
|
69
67
|
readonly outPath: string;
|
|
68
|
+
readonly internalPath: string;
|
|
69
|
+
readonly injectsPath: string;
|
|
70
70
|
readonly cjsPath: string;
|
|
71
71
|
};
|
|
72
72
|
type CodegenResult = Result<CodegenSuccess, CodegenError>;
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region packages/codegen/src/inject-template.d.ts
|
|
75
|
-
declare const writeInjectTemplate: (outPath: string) =>
|
|
75
|
+
declare const writeInjectTemplate: (outPath: string) => neverthrow3.Err<void, CodegenError> | neverthrow3.Ok<void, CodegenError>;
|
|
76
76
|
declare const getInjectTemplate: () => string;
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region packages/codegen/src/runner.d.ts
|
|
@@ -83,12 +83,12 @@ declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
|
|
|
83
83
|
* Load a single schema file.
|
|
84
84
|
* @internal Use loadSchema for public API.
|
|
85
85
|
*/
|
|
86
|
-
declare const loadSingleSchema: (schemaPath: string) =>
|
|
86
|
+
declare const loadSingleSchema: (schemaPath: string) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
|
|
87
87
|
/**
|
|
88
88
|
* Load and merge multiple schema files into a single DocumentNode.
|
|
89
89
|
* Uses GraphQL's concatAST to combine definitions from all files.
|
|
90
90
|
*/
|
|
91
|
-
declare const loadSchema: (schemaPaths: readonly string[]) =>
|
|
91
|
+
declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
|
|
92
92
|
declare const hashSchema: (document: DocumentNode) => string;
|
|
93
93
|
//#endregion
|
|
94
94
|
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,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;
|
|
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,MAAA,EAAA,MAAA,CAAA,CAAA;CAAQ;AAG7B,KAAA,cAAA,GAAc;EACS,SAAA,OAAA,E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,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
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { n as generateMultiSchemaModule } from "./generator-
|
|
1
|
+
import { n as generateMultiSchemaModule } from "./generator-CGLIILli.mjs";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { err, ok } from "neverthrow";
|
|
5
|
-
import { mkdir } from "node:fs/promises";
|
|
6
5
|
import { build } from "esbuild";
|
|
7
6
|
import { concatAST, parse, print } from "graphql";
|
|
8
7
|
import { createHash } from "node:crypto";
|
|
@@ -92,85 +91,6 @@ const writeModule = (outPath, contents) => {
|
|
|
92
91
|
}
|
|
93
92
|
};
|
|
94
93
|
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region packages/codegen/src/prebuilt-generator.ts
|
|
97
|
-
/**
|
|
98
|
-
* Generate the prebuilt module code.
|
|
99
|
-
*
|
|
100
|
-
* This generates:
|
|
101
|
-
* - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes
|
|
102
|
-
* - prebuilt/types.ts: Placeholder types that builder will populate
|
|
103
|
-
*/
|
|
104
|
-
const generatePrebuiltModule = (schemas, options) => {
|
|
105
|
-
const schemaNames = Array.from(schemas.keys());
|
|
106
|
-
const typeImports = [];
|
|
107
|
-
const runtimeImports = [];
|
|
108
|
-
for (const name of schemaNames) {
|
|
109
|
-
typeImports.push(`Schema_${name}`, `FragmentBuilders_${name}`, `Context_${name}`);
|
|
110
|
-
runtimeImports.push(`__schema_${name}`, `__inputTypeMethods_${name}`, `__directiveMethods_${name}`);
|
|
111
|
-
const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
|
|
112
|
-
if (hasAdapter) {
|
|
113
|
-
typeImports.push(`Adapter_${name}`);
|
|
114
|
-
runtimeImports.push(`__adapter_${name}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const gqlEntries = [];
|
|
118
|
-
for (const name of schemaNames) {
|
|
119
|
-
const document = schemas.get(name);
|
|
120
|
-
if (!document) continue;
|
|
121
|
-
const hasAdapter = options.injection?.get(name)?.adapterImportPath !== undefined;
|
|
122
|
-
if (hasAdapter) {
|
|
123
|
-
gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}, Adapter_${name}>(__schema_${name}, { adapter: __adapter_${name}, inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
|
|
124
|
-
} else {
|
|
125
|
-
gqlEntries.push(` ${name}: createPrebuiltGqlElementComposer<Schema_${name}, PrebuiltTypes_${name}, FragmentBuilders_${name}, typeof __directiveMethods_${name}, Context_${name}>(__schema_${name}, { inputTypeMethods: __inputTypeMethods_${name}, directiveMethods: __directiveMethods_${name} })`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const indexCode = `\
|
|
129
|
-
/**
|
|
130
|
-
* Prebuilt GQL module for bundler-compatible type resolution.
|
|
131
|
-
*
|
|
132
|
-
* This module uses createPrebuiltGqlElementComposer which looks up types
|
|
133
|
-
* from PrebuiltTypes instead of using complex type inference.
|
|
134
|
-
*
|
|
135
|
-
* @module
|
|
136
|
-
* @generated by @soda-gql/codegen
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
import { createPrebuiltGqlElementComposer } from "@soda-gql/core";
|
|
140
|
-
import {
|
|
141
|
-
${runtimeImports.join(",\n ")},
|
|
142
|
-
type ${typeImports.join(",\n type ")},
|
|
143
|
-
} from "${options.mainModulePath}";
|
|
144
|
-
import type { ${schemaNames.map((name) => `PrebuiltTypes_${name}`).join(", ")} } from "./types";
|
|
145
|
-
|
|
146
|
-
export const gql = {
|
|
147
|
-
${gqlEntries.join(",\n")}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// Re-export types from main module
|
|
151
|
-
export type { ${typeImports.join(", ")} };
|
|
152
|
-
`;
|
|
153
|
-
const typesCode = `\
|
|
154
|
-
/**
|
|
155
|
-
* Prebuilt type registry.
|
|
156
|
-
*
|
|
157
|
-
* This file contains placeholder types that will be populated by the builder
|
|
158
|
-
* when running \`soda-gql build\` command.
|
|
159
|
-
*
|
|
160
|
-
* @module
|
|
161
|
-
* @generated by @soda-gql/codegen
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
import type { EmptyPrebuiltTypeRegistry } from "@soda-gql/core";
|
|
165
|
-
|
|
166
|
-
${schemaNames.map((name) => `// Placeholder for ${name} schema - populated by builder\nexport type PrebuiltTypes_${name} = EmptyPrebuiltTypeRegistry;`).join("\n\n")}
|
|
167
|
-
`;
|
|
168
|
-
return {
|
|
169
|
-
indexCode,
|
|
170
|
-
typesCode
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
|
|
174
94
|
//#endregion
|
|
175
95
|
//#region packages/codegen/src/schema.ts
|
|
176
96
|
/**
|
|
@@ -306,14 +226,20 @@ const runCodegen = async (options) => {
|
|
|
306
226
|
inputDepthOverridesConfig.set(schemaName, schemaConfig.inputDepthOverrides);
|
|
307
227
|
}
|
|
308
228
|
}
|
|
309
|
-
const { code } = generateMultiSchemaModule(schemas, {
|
|
229
|
+
const { code: internalCode, injectsCode } = generateMultiSchemaModule(schemas, {
|
|
310
230
|
injection: injectionConfig,
|
|
311
231
|
defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
|
|
312
|
-
inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
|
|
313
|
-
exportForPrebuilt: options.prebuilt
|
|
232
|
+
inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined
|
|
314
233
|
});
|
|
234
|
+
const indexCode = `/**
|
|
235
|
+
* Generated by @soda-gql/codegen
|
|
236
|
+
* @module
|
|
237
|
+
* @generated
|
|
238
|
+
*/
|
|
239
|
+
export * from "./_internal";
|
|
240
|
+
`;
|
|
315
241
|
for (const [name, document] of schemas.entries()) {
|
|
316
|
-
const schemaIndex = (await import("./generator-
|
|
242
|
+
const schemaIndex = (await import("./generator-j4CLEIBx.mjs")).createSchemaIndex(document);
|
|
317
243
|
const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
|
|
318
244
|
const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
|
|
319
245
|
const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
|
|
@@ -326,36 +252,22 @@ const runCodegen = async (options) => {
|
|
|
326
252
|
unions
|
|
327
253
|
};
|
|
328
254
|
}
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const prebuiltDir = join(dirname(outPath), "prebuilt");
|
|
335
|
-
await mkdir(prebuiltDir, { recursive: true });
|
|
336
|
-
const mainModulePath = toImportSpecifier(join(prebuiltDir, "index.ts"), outPath, importSpecifierOptions);
|
|
337
|
-
const prebuilt = generatePrebuiltModule(schemas, {
|
|
338
|
-
mainModulePath,
|
|
339
|
-
injection: injectionConfig
|
|
340
|
-
});
|
|
341
|
-
const prebuiltIndexPath = join(prebuiltDir, "index.ts");
|
|
342
|
-
const prebuiltIndexResult = await writeModule(prebuiltIndexPath, prebuilt.indexCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
|
|
343
|
-
if (prebuiltIndexResult.isErr()) {
|
|
344
|
-
return err(prebuiltIndexResult.error);
|
|
345
|
-
}
|
|
346
|
-
const prebuiltTypesPath = join(prebuiltDir, "types.ts");
|
|
347
|
-
const prebuiltTypesResult = await writeModule(prebuiltTypesPath, prebuilt.typesCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
|
|
348
|
-
if (prebuiltTypesResult.isErr()) {
|
|
349
|
-
return err(prebuiltTypesResult.error);
|
|
350
|
-
}
|
|
351
|
-
const prebuiltBundleOutcome = await esbuildBundler.bundle({
|
|
352
|
-
sourcePath: prebuiltIndexPath,
|
|
353
|
-
external: ["@soda-gql/core", "@soda-gql/runtime"]
|
|
354
|
-
});
|
|
355
|
-
if (prebuiltBundleOutcome.isErr()) {
|
|
356
|
-
return err(prebuiltBundleOutcome.error);
|
|
255
|
+
const injectsPath = join(dirname(outPath), "_internal-injects.ts");
|
|
256
|
+
if (injectsCode) {
|
|
257
|
+
const injectsWriteResult = await writeModule(injectsPath, injectsCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
|
|
258
|
+
if (injectsWriteResult.isErr()) {
|
|
259
|
+
return err(injectsWriteResult.error);
|
|
357
260
|
}
|
|
358
261
|
}
|
|
262
|
+
const internalPath = join(dirname(outPath), "_internal.ts");
|
|
263
|
+
const internalWriteResult = await writeModule(internalPath, internalCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
|
|
264
|
+
if (internalWriteResult.isErr()) {
|
|
265
|
+
return err(internalWriteResult.error);
|
|
266
|
+
}
|
|
267
|
+
const indexWriteResult = await writeModule(outPath, indexCode).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
|
|
268
|
+
if (indexWriteResult.isErr()) {
|
|
269
|
+
return err(indexWriteResult.error);
|
|
270
|
+
}
|
|
359
271
|
const bundleOutcome = await esbuildBundler.bundle({
|
|
360
272
|
sourcePath: outPath,
|
|
361
273
|
external: ["@soda-gql/core", "@soda-gql/runtime"]
|
|
@@ -367,6 +279,8 @@ const runCodegen = async (options) => {
|
|
|
367
279
|
return ok({
|
|
368
280
|
schemas: schemaHashes,
|
|
369
281
|
outPath,
|
|
282
|
+
internalPath,
|
|
283
|
+
injectsPath,
|
|
370
284
|
cjsPath: bundleResult.value.cjsPath
|
|
371
285
|
});
|
|
372
286
|
};
|