@soda-gql/codegen 0.0.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/LICENSE +21 -0
- package/dist/generator-BgvqYNQA.js +511 -0
- package/dist/generator-BgvqYNQA.js.map +1 -0
- package/dist/generator-DLeYPsgP.js +3 -0
- package/dist/generator-DudCa3Gz.cjs +4 -0
- package/dist/generator-t_NByvnv.cjs +551 -0
- package/dist/index.cjs +270 -0
- package/dist/index.d.cts +91 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +262 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { generateMultiSchemaModule } from "./generator-BgvqYNQA.js";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, extname, relative, resolve } from "node:path";
|
|
4
|
+
import { err, ok } from "neverthrow";
|
|
5
|
+
import { parse, print } from "graphql";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { build } from "tsdown";
|
|
8
|
+
|
|
9
|
+
//#region packages/codegen/src/inject-template.ts
|
|
10
|
+
const templateContents = `\
|
|
11
|
+
import { defineScalar } from "@soda-gql/core";
|
|
12
|
+
import { createRuntimeAdapter } from "@soda-gql/runtime";
|
|
13
|
+
|
|
14
|
+
export const scalar = {
|
|
15
|
+
...defineScalar("ID", ({ type }) => ({
|
|
16
|
+
input: type<string>(),
|
|
17
|
+
output: type<string>(),
|
|
18
|
+
directives: {},
|
|
19
|
+
})),
|
|
20
|
+
...defineScalar("String", ({ type }) => ({
|
|
21
|
+
input: type<string>(),
|
|
22
|
+
output: type<string>(),
|
|
23
|
+
directives: {},
|
|
24
|
+
})),
|
|
25
|
+
...defineScalar("Int", ({ type }) => ({
|
|
26
|
+
input: type<number>(),
|
|
27
|
+
output: type<number>(),
|
|
28
|
+
directives: {},
|
|
29
|
+
})),
|
|
30
|
+
...defineScalar("Float", ({ type }) => ({
|
|
31
|
+
input: type<number>(),
|
|
32
|
+
output: type<number>(),
|
|
33
|
+
directives: {},
|
|
34
|
+
})),
|
|
35
|
+
...defineScalar("Boolean", ({ type }) => ({
|
|
36
|
+
input: type<boolean>(),
|
|
37
|
+
output: type<boolean>(),
|
|
38
|
+
directives: {},
|
|
39
|
+
})),
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
export const adapter = createRuntimeAdapter(({ type }) => ({
|
|
43
|
+
nonGraphqlErrorType: type<{ type: "non-graphql-error"; cause: unknown }>(),
|
|
44
|
+
}));
|
|
45
|
+
`;
|
|
46
|
+
const writeInjectTemplate = (outPath) => {
|
|
47
|
+
const targetPath = resolve(outPath);
|
|
48
|
+
try {
|
|
49
|
+
if (existsSync(targetPath)) {
|
|
50
|
+
return err({
|
|
51
|
+
code: "INJECT_TEMPLATE_EXISTS",
|
|
52
|
+
message: `Inject module already exists: ${targetPath}`,
|
|
53
|
+
outPath: targetPath
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
mkdirSync(dirname(targetPath), { recursive: true });
|
|
57
|
+
writeFileSync(targetPath, `${templateContents}\n`);
|
|
58
|
+
return ok(undefined);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
return err({
|
|
62
|
+
code: "INJECT_TEMPLATE_FAILED",
|
|
63
|
+
message,
|
|
64
|
+
outPath: targetPath
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const getInjectTemplate = () => `${templateContents}\n`;
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region packages/codegen/src/file.ts
|
|
72
|
+
const writeModule = (outPath, contents) => {
|
|
73
|
+
const targetPath = resolve(outPath);
|
|
74
|
+
try {
|
|
75
|
+
mkdirSync(dirname(targetPath), { recursive: true });
|
|
76
|
+
writeFileSync(targetPath, contents);
|
|
77
|
+
return ok(undefined);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
80
|
+
return err({
|
|
81
|
+
code: "EMIT_FAILED",
|
|
82
|
+
message,
|
|
83
|
+
outPath: targetPath
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region packages/codegen/src/schema.ts
|
|
90
|
+
const loadSchema = (schemaPath) => {
|
|
91
|
+
const resolvedPath = resolve(schemaPath);
|
|
92
|
+
if (!existsSync(resolvedPath)) {
|
|
93
|
+
return err({
|
|
94
|
+
code: "SCHEMA_NOT_FOUND",
|
|
95
|
+
message: `Schema file not found at ${resolvedPath}`,
|
|
96
|
+
schemaPath: resolvedPath
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const schemaSource = readFileSync(resolvedPath, "utf8");
|
|
101
|
+
const document = parse(schemaSource);
|
|
102
|
+
return ok(document);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
105
|
+
return err({
|
|
106
|
+
code: "SCHEMA_INVALID",
|
|
107
|
+
message: `SchemaValidationError: ${message}`,
|
|
108
|
+
schemaPath: resolvedPath
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const hashSchema = (document) => createHash("sha256").update(print(document)).digest("hex");
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region packages/codegen/src/tsdown-bundle.ts
|
|
116
|
+
const bundleGraphqlSystem = async (sourcePath) => {
|
|
117
|
+
try {
|
|
118
|
+
const sourceDir = dirname(sourcePath);
|
|
119
|
+
const sourceExt = extname(sourcePath);
|
|
120
|
+
const baseName = sourcePath.slice(0, -sourceExt.length);
|
|
121
|
+
await build({
|
|
122
|
+
config: false,
|
|
123
|
+
entry: sourcePath,
|
|
124
|
+
format: ["cjs"],
|
|
125
|
+
platform: "node",
|
|
126
|
+
external: ["@soda-gql/core", "@soda-gql/runtime"],
|
|
127
|
+
dts: false,
|
|
128
|
+
outDir: sourceDir,
|
|
129
|
+
fixedExtension: true,
|
|
130
|
+
clean: false,
|
|
131
|
+
minify: false,
|
|
132
|
+
sourcemap: false,
|
|
133
|
+
treeshake: false
|
|
134
|
+
});
|
|
135
|
+
const cjsPath = `${baseName}.cjs`;
|
|
136
|
+
return ok({ cjsPath });
|
|
137
|
+
} catch (error) {
|
|
138
|
+
return err({
|
|
139
|
+
code: "EMIT_FAILED",
|
|
140
|
+
message: `Failed to bundle graphql-system: ${error instanceof Error ? error.message : String(error)}`,
|
|
141
|
+
outPath: sourcePath
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region packages/codegen/src/runner.ts
|
|
148
|
+
const extensionMap = {
|
|
149
|
+
".ts": ".js",
|
|
150
|
+
".tsx": ".js",
|
|
151
|
+
".mts": ".mjs",
|
|
152
|
+
".cts": ".cjs",
|
|
153
|
+
".js": ".js",
|
|
154
|
+
".mjs": ".mjs",
|
|
155
|
+
".cjs": ".cjs"
|
|
156
|
+
};
|
|
157
|
+
const toImportSpecifier = (fromPath, targetPath) => {
|
|
158
|
+
const fromDir = dirname(fromPath);
|
|
159
|
+
const normalized = relative(fromDir, targetPath).replace(/\\/g, "/");
|
|
160
|
+
const sourceExt = extname(targetPath);
|
|
161
|
+
const runtimeExt = extensionMap[sourceExt] ?? sourceExt;
|
|
162
|
+
if (normalized.length === 0) {
|
|
163
|
+
const base = runtimeExt !== sourceExt ? basename(targetPath, sourceExt) : basename(targetPath);
|
|
164
|
+
return `./${base}${runtimeExt}`;
|
|
165
|
+
}
|
|
166
|
+
const withPrefix = normalized.startsWith(".") ? normalized : `./${normalized}`;
|
|
167
|
+
if (!runtimeExt) {
|
|
168
|
+
return withPrefix;
|
|
169
|
+
}
|
|
170
|
+
if (withPrefix.endsWith(runtimeExt)) {
|
|
171
|
+
return withPrefix;
|
|
172
|
+
}
|
|
173
|
+
const currentExt = extname(withPrefix);
|
|
174
|
+
const withoutExt = currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;
|
|
175
|
+
return `${withoutExt}${runtimeExt}`;
|
|
176
|
+
};
|
|
177
|
+
const runMultiSchemaCodegen = async (options) => {
|
|
178
|
+
const outPath = resolve(options.outPath);
|
|
179
|
+
const runtimeAdapters = options.runtimeAdapters ?? (options.injectFromPath ? { default: options.injectFromPath } : {});
|
|
180
|
+
const scalars = options.scalars ?? (options.injectFromPath ? { default: options.injectFromPath } : {});
|
|
181
|
+
const adapterPaths = new Map();
|
|
182
|
+
const scalarPaths = new Map();
|
|
183
|
+
for (const [schemaName, adapterPath] of Object.entries(runtimeAdapters)) {
|
|
184
|
+
const resolvedPath = resolve(adapterPath);
|
|
185
|
+
if (!existsSync(resolvedPath)) {
|
|
186
|
+
return err({
|
|
187
|
+
code: "INJECT_MODULE_NOT_FOUND",
|
|
188
|
+
message: `Runtime adapter module not found for schema '${schemaName}': ${resolvedPath}`,
|
|
189
|
+
injectPath: resolvedPath
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
adapterPaths.set(schemaName, resolvedPath);
|
|
193
|
+
}
|
|
194
|
+
for (const [schemaName, scalarPath] of Object.entries(scalars)) {
|
|
195
|
+
const resolvedPath = resolve(scalarPath);
|
|
196
|
+
if (!existsSync(resolvedPath)) {
|
|
197
|
+
return err({
|
|
198
|
+
code: "INJECT_MODULE_NOT_FOUND",
|
|
199
|
+
message: `Scalar module not found for schema '${schemaName}': ${resolvedPath}`,
|
|
200
|
+
injectPath: resolvedPath
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
scalarPaths.set(schemaName, resolvedPath);
|
|
204
|
+
}
|
|
205
|
+
const schemas = new Map();
|
|
206
|
+
const schemaHashes = {};
|
|
207
|
+
for (const [name, schemaPath] of Object.entries(options.schemas)) {
|
|
208
|
+
const result = await loadSchema(schemaPath).match((doc) => Promise.resolve(ok(doc)), (error) => Promise.resolve(err(error)));
|
|
209
|
+
if (result.isErr()) {
|
|
210
|
+
return err(result.error);
|
|
211
|
+
}
|
|
212
|
+
schemas.set(name, result.value);
|
|
213
|
+
}
|
|
214
|
+
const injectionConfig = new Map();
|
|
215
|
+
for (const schemaName of schemas.keys()) {
|
|
216
|
+
const adapterPath = adapterPaths.get(schemaName);
|
|
217
|
+
const scalarPath = scalarPaths.get(schemaName);
|
|
218
|
+
if (!adapterPath || !scalarPath) {
|
|
219
|
+
return err({
|
|
220
|
+
code: "INJECT_MODULE_REQUIRED",
|
|
221
|
+
message: `Missing adapter or scalar configuration for schema '${schemaName}'`
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
injectionConfig.set(schemaName, {
|
|
225
|
+
adapterImportPath: toImportSpecifier(outPath, adapterPath),
|
|
226
|
+
scalarImportPath: toImportSpecifier(outPath, scalarPath)
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const { code } = generateMultiSchemaModule(schemas, { injection: injectionConfig });
|
|
230
|
+
for (const [name, document] of schemas.entries()) {
|
|
231
|
+
const schemaIndex = (await import("./generator-DLeYPsgP.js")).createSchemaIndex(document);
|
|
232
|
+
const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
|
|
233
|
+
const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
|
|
234
|
+
const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
|
|
235
|
+
const unions = Array.from(schemaIndex.unions.keys()).filter((n) => !n.startsWith("__")).length;
|
|
236
|
+
schemaHashes[name] = {
|
|
237
|
+
schemaHash: hashSchema(document),
|
|
238
|
+
objects,
|
|
239
|
+
enums,
|
|
240
|
+
inputs,
|
|
241
|
+
unions
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const writeResult = await writeModule(outPath, code).match(() => Promise.resolve(ok(undefined)), (error) => Promise.resolve(err(error)));
|
|
245
|
+
if (writeResult.isErr()) {
|
|
246
|
+
return err(writeResult.error);
|
|
247
|
+
}
|
|
248
|
+
const bundleOutcome = await bundleGraphqlSystem(outPath);
|
|
249
|
+
const bundleResult = bundleOutcome.match((result) => ok(result), (error) => err(error));
|
|
250
|
+
if (bundleResult.isErr()) {
|
|
251
|
+
return err(bundleResult.error);
|
|
252
|
+
}
|
|
253
|
+
return ok({
|
|
254
|
+
schemas: schemaHashes,
|
|
255
|
+
outPath,
|
|
256
|
+
cjsPath: bundleResult.value.cjsPath
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
export { hashSchema, loadSchema, runMultiSchemaCodegen, writeInjectTemplate };
|
|
262
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["extensionMap: Record<string, string>","schemaHashes: Record<string, { schemaHash: string; objects: number; enums: number; inputs: number; unions: number }>"],"sources":["../src/inject-template.ts","../src/file.ts","../src/schema.ts","../src/tsdown-bundle.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\";\nimport { createRuntimeAdapter } from \"@soda-gql/runtime\";\n\nexport const scalar = {\n ...defineScalar(\"ID\", ({ type }) => ({\n input: type<string>(),\n output: type<string>(),\n directives: {},\n })),\n ...defineScalar(\"String\", ({ type }) => ({\n input: type<string>(),\n output: type<string>(),\n directives: {},\n })),\n ...defineScalar(\"Int\", ({ type }) => ({\n input: type<number>(),\n output: type<number>(),\n directives: {},\n })),\n ...defineScalar(\"Float\", ({ type }) => ({\n input: type<number>(),\n output: type<number>(),\n directives: {},\n })),\n ...defineScalar(\"Boolean\", ({ type }) => ({\n input: type<boolean>(),\n output: type<boolean>(),\n directives: {},\n })),\n} as const;\n\nexport const adapter = createRuntimeAdapter(({ type }) => ({\n nonGraphqlErrorType: type<{ type: \"non-graphql-error\"; cause: unknown }>(),\n}));\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 { 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 { dirname, extname } from \"node:path\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport { build, type Options } from \"tsdown\";\nimport type { CodegenError } from \"./types\";\n\nexport type BundleResult = {\n readonly cjsPath: string;\n};\n\nexport const bundleGraphqlSystem = async (sourcePath: string): Promise<Result<BundleResult, CodegenError>> => {\n try {\n const sourceDir = dirname(sourcePath);\n const sourceExt = extname(sourcePath);\n const baseName = sourcePath.slice(0, -sourceExt.length);\n\n await build({\n config: false,\n entry: sourcePath,\n format: [\"cjs\"],\n platform: \"node\",\n external: [\"@soda-gql/core\", \"@soda-gql/runtime\"],\n dts: false,\n outDir: sourceDir,\n fixedExtension: true,\n clean: false,\n minify: false,\n sourcemap: false,\n treeshake: false,\n } satisfies Options);\n\n const cjsPath = `${baseName}.cjs`;\n\n return ok({ cjsPath });\n } catch (error) {\n return err({\n code: \"EMIT_FAILED\",\n message: `Failed to bundle graphql-system: ${error instanceof Error ? error.message : String(error)}`,\n outPath: sourcePath,\n });\n }\n};\n","import { existsSync } from \"node:fs\";\nimport { basename, dirname, extname, relative, resolve } from \"node:path\";\nimport { err, ok } from \"neverthrow\";\nimport { writeModule } from \"./file\";\nimport { generateMultiSchemaModule } from \"./generator\";\nimport { hashSchema, loadSchema } from \"./schema\";\nimport { bundleGraphqlSystem } from \"./tsdown-bundle\";\nimport type { MultiSchemaCodegenOptions, MultiSchemaCodegenResult, MultiSchemaCodegenSuccess } 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\nconst toImportSpecifier = (fromPath: string, targetPath: string): string => {\n const fromDir = dirname(fromPath);\n const normalized = relative(fromDir, targetPath).replace(/\\\\/g, \"/\");\n const sourceExt = extname(targetPath);\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 runMultiSchemaCodegen = async (options: MultiSchemaCodegenOptions): Promise<MultiSchemaCodegenResult> => {\n const outPath = resolve(options.outPath);\n\n // Handle legacy injectFromPath for backward compatibility\n const runtimeAdapters = options.runtimeAdapters ?? (options.injectFromPath ? { default: options.injectFromPath } : {});\n const scalars = options.scalars ?? (options.injectFromPath ? { default: options.injectFromPath } : {});\n\n // Validate that all adapter and scalar files exist\n const adapterPaths = new Map<string, string>();\n const scalarPaths = new Map<string, string>();\n\n for (const [schemaName, adapterPath] of Object.entries(runtimeAdapters)) {\n const resolvedPath = resolve(adapterPath);\n if (!existsSync(resolvedPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Runtime adapter module not found for schema '${schemaName}': ${resolvedPath}`,\n injectPath: resolvedPath,\n });\n }\n adapterPaths.set(schemaName, resolvedPath);\n }\n\n for (const [schemaName, scalarPath] of Object.entries(scalars)) {\n const resolvedPath = resolve(scalarPath);\n if (!existsSync(resolvedPath)) {\n return err({\n code: \"INJECT_MODULE_NOT_FOUND\",\n message: `Scalar module not found for schema '${schemaName}': ${resolvedPath}`,\n injectPath: resolvedPath,\n });\n }\n scalarPaths.set(schemaName, resolvedPath);\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, schemaPath] of Object.entries(options.schemas)) {\n const result = await loadSchema(schemaPath).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<string, { adapterImportPath: string; scalarImportPath: string }>();\n\n for (const schemaName of schemas.keys()) {\n const adapterPath = adapterPaths.get(schemaName);\n const scalarPath = scalarPaths.get(schemaName);\n\n if (!adapterPath || !scalarPath) {\n return err({\n code: \"INJECT_MODULE_REQUIRED\",\n message: `Missing adapter or scalar configuration for schema '${schemaName}'`,\n });\n }\n\n injectionConfig.set(schemaName, {\n adapterImportPath: toImportSpecifier(outPath, adapterPath),\n scalarImportPath: toImportSpecifier(outPath, scalarPath),\n });\n }\n\n // Generate multi-schema module\n const { code } = generateMultiSchemaModule(schemas, {\n injection: injectionConfig,\n });\n\n // Calculate individual schema stats and hashes\n for (const [name, document] of schemas.entries()) {\n const schemaIndex = (await import(\"./generator\")).createSchemaIndex(document);\n const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith(\"__\")).length;\n const unions = Array.from(schemaIndex.unions.keys()).filter((n) => !n.startsWith(\"__\")).length;\n\n schemaHashes[name] = {\n schemaHash: hashSchema(document),\n objects,\n enums,\n inputs,\n unions,\n };\n }\n\n // Write the module\n const writeResult = await writeModule(outPath, code).match(\n () => Promise.resolve(ok(undefined)),\n (error) => Promise.resolve(err(error)),\n );\n\n if (writeResult.isErr()) {\n return err(writeResult.error);\n }\n\n // Bundle the generated module with tsdown\n const bundleOutcome = await bundleGraphqlSystem(outPath);\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 MultiSchemaCodegenSuccess);\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCzB,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;;;;AC9DnE,MAAa,eAAe,SAAiB,aAAqB;CAChE,MAAM,aAAa,QAAQ,QAAQ;AAEnC,KAAI;AACF,YAAU,QAAQ,WAAW,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,gBAAc,YAAY,SAAS;AACnC,SAAO,GAAuB,UAAU;UACjC,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,SAAO,IAAwB;GAC7B,MAAM;GACN;GACA,SAAS;GACV,CAAC;;;;;;ACXN,MAAa,cAAc,eAAuB;CAChD,MAAM,e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,MAAM,KAAK,YAAY,OAAO,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;EACxF,MAAM,SAAS,MAAM,KAAK,YAAY,OAAO,MAAM,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;AAExF,eAAa,QAAQ;GACnB,YAAY,WAAW,SAAS;GAChC;GACA;GACA;GACA;GACD;;CAIH,MAAM,cAAc,MAAM,YAAY,SAAS,KAAK,CAAC,YAC7C,QAAQ,QAAQ,GAAG,UAAU,CAAC,GACnC,UAAU,QAAQ,QAAQ,IAAI,MAAM,CAAC,CACvC;AAED,KAAI,YAAY,OAAO,EAAE;AACvB,SAAO,IAAI,YAAY,MAAM;;CAI/B,MAAM,gBAAgB,MAAM,oBAAoB,QAAQ;CACxD,MAAM,eAAe,cAAc,OAChC,WAAW,GAAG,OAAO,GACrB,UAAU,IAAI,MAAM,CACtB;AAED,KAAI,aAAa,OAAO,EAAE;AACxB,SAAO,IAAI,aAAa,MAAM;;AAGhC,QAAO,GAAG;EACR,SAAS;EACT;EACA,SAAS,aAAa,MAAM;EAC7B,CAAqC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soda-gql/codegen",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Shota Hatada",
|
|
12
|
+
"email": "shota.hatada@whatasoda.me",
|
|
13
|
+
"url": "https://github.com/whatasoda"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"development": "./src/index.ts",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@soda-gql/core": "0.0.1",
|
|
30
|
+
"@soda-gql/runtime": "0.0.1",
|
|
31
|
+
"graphql": "^16.8.1",
|
|
32
|
+
"neverthrow": "^8.1.1",
|
|
33
|
+
"tsdown": "^0.15.7"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"peerDependencies": {}
|
|
37
|
+
}
|