@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.cjs
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
const require_generator = require('./generator-t_NByvnv.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
node_fs = require_generator.__toESM(node_fs);
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_generator.__toESM(node_path);
|
|
6
|
+
let neverthrow = require("neverthrow");
|
|
7
|
+
neverthrow = require_generator.__toESM(neverthrow);
|
|
8
|
+
let graphql = require("graphql");
|
|
9
|
+
graphql = require_generator.__toESM(graphql);
|
|
10
|
+
let node_crypto = require("node:crypto");
|
|
11
|
+
node_crypto = require_generator.__toESM(node_crypto);
|
|
12
|
+
let tsdown = require("tsdown");
|
|
13
|
+
tsdown = require_generator.__toESM(tsdown);
|
|
14
|
+
|
|
15
|
+
//#region packages/codegen/src/inject-template.ts
|
|
16
|
+
const templateContents = `\
|
|
17
|
+
import { defineScalar } from "@soda-gql/core";
|
|
18
|
+
import { createRuntimeAdapter } from "@soda-gql/runtime";
|
|
19
|
+
|
|
20
|
+
export const scalar = {
|
|
21
|
+
...defineScalar("ID", ({ type }) => ({
|
|
22
|
+
input: type<string>(),
|
|
23
|
+
output: type<string>(),
|
|
24
|
+
directives: {},
|
|
25
|
+
})),
|
|
26
|
+
...defineScalar("String", ({ type }) => ({
|
|
27
|
+
input: type<string>(),
|
|
28
|
+
output: type<string>(),
|
|
29
|
+
directives: {},
|
|
30
|
+
})),
|
|
31
|
+
...defineScalar("Int", ({ type }) => ({
|
|
32
|
+
input: type<number>(),
|
|
33
|
+
output: type<number>(),
|
|
34
|
+
directives: {},
|
|
35
|
+
})),
|
|
36
|
+
...defineScalar("Float", ({ type }) => ({
|
|
37
|
+
input: type<number>(),
|
|
38
|
+
output: type<number>(),
|
|
39
|
+
directives: {},
|
|
40
|
+
})),
|
|
41
|
+
...defineScalar("Boolean", ({ type }) => ({
|
|
42
|
+
input: type<boolean>(),
|
|
43
|
+
output: type<boolean>(),
|
|
44
|
+
directives: {},
|
|
45
|
+
})),
|
|
46
|
+
} as const;
|
|
47
|
+
|
|
48
|
+
export const adapter = createRuntimeAdapter(({ type }) => ({
|
|
49
|
+
nonGraphqlErrorType: type<{ type: "non-graphql-error"; cause: unknown }>(),
|
|
50
|
+
}));
|
|
51
|
+
`;
|
|
52
|
+
const writeInjectTemplate = (outPath) => {
|
|
53
|
+
const targetPath = (0, node_path.resolve)(outPath);
|
|
54
|
+
try {
|
|
55
|
+
if ((0, node_fs.existsSync)(targetPath)) {
|
|
56
|
+
return (0, neverthrow.err)({
|
|
57
|
+
code: "INJECT_TEMPLATE_EXISTS",
|
|
58
|
+
message: `Inject module already exists: ${targetPath}`,
|
|
59
|
+
outPath: targetPath
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(targetPath), { recursive: true });
|
|
63
|
+
(0, node_fs.writeFileSync)(targetPath, `${templateContents}\n`);
|
|
64
|
+
return (0, neverthrow.ok)(undefined);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
return (0, neverthrow.err)({
|
|
68
|
+
code: "INJECT_TEMPLATE_FAILED",
|
|
69
|
+
message,
|
|
70
|
+
outPath: targetPath
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const getInjectTemplate = () => `${templateContents}\n`;
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region packages/codegen/src/file.ts
|
|
78
|
+
const writeModule = (outPath, contents) => {
|
|
79
|
+
const targetPath = (0, node_path.resolve)(outPath);
|
|
80
|
+
try {
|
|
81
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(targetPath), { recursive: true });
|
|
82
|
+
(0, node_fs.writeFileSync)(targetPath, contents);
|
|
83
|
+
return (0, neverthrow.ok)(undefined);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
86
|
+
return (0, neverthrow.err)({
|
|
87
|
+
code: "EMIT_FAILED",
|
|
88
|
+
message,
|
|
89
|
+
outPath: targetPath
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region packages/codegen/src/schema.ts
|
|
96
|
+
const loadSchema = (schemaPath) => {
|
|
97
|
+
const resolvedPath = (0, node_path.resolve)(schemaPath);
|
|
98
|
+
if (!(0, node_fs.existsSync)(resolvedPath)) {
|
|
99
|
+
return (0, neverthrow.err)({
|
|
100
|
+
code: "SCHEMA_NOT_FOUND",
|
|
101
|
+
message: `Schema file not found at ${resolvedPath}`,
|
|
102
|
+
schemaPath: resolvedPath
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const schemaSource = (0, node_fs.readFileSync)(resolvedPath, "utf8");
|
|
107
|
+
const document = (0, graphql.parse)(schemaSource);
|
|
108
|
+
return (0, neverthrow.ok)(document);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
111
|
+
return (0, neverthrow.err)({
|
|
112
|
+
code: "SCHEMA_INVALID",
|
|
113
|
+
message: `SchemaValidationError: ${message}`,
|
|
114
|
+
schemaPath: resolvedPath
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const hashSchema = (document) => (0, node_crypto.createHash)("sha256").update((0, graphql.print)(document)).digest("hex");
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region packages/codegen/src/tsdown-bundle.ts
|
|
122
|
+
const bundleGraphqlSystem = async (sourcePath) => {
|
|
123
|
+
try {
|
|
124
|
+
const sourceDir = (0, node_path.dirname)(sourcePath);
|
|
125
|
+
const sourceExt = (0, node_path.extname)(sourcePath);
|
|
126
|
+
const baseName = sourcePath.slice(0, -sourceExt.length);
|
|
127
|
+
await (0, tsdown.build)({
|
|
128
|
+
config: false,
|
|
129
|
+
entry: sourcePath,
|
|
130
|
+
format: ["cjs"],
|
|
131
|
+
platform: "node",
|
|
132
|
+
external: ["@soda-gql/core", "@soda-gql/runtime"],
|
|
133
|
+
dts: false,
|
|
134
|
+
outDir: sourceDir,
|
|
135
|
+
fixedExtension: true,
|
|
136
|
+
clean: false,
|
|
137
|
+
minify: false,
|
|
138
|
+
sourcemap: false,
|
|
139
|
+
treeshake: false
|
|
140
|
+
});
|
|
141
|
+
const cjsPath = `${baseName}.cjs`;
|
|
142
|
+
return (0, neverthrow.ok)({ cjsPath });
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return (0, neverthrow.err)({
|
|
145
|
+
code: "EMIT_FAILED",
|
|
146
|
+
message: `Failed to bundle graphql-system: ${error instanceof Error ? error.message : String(error)}`,
|
|
147
|
+
outPath: sourcePath
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region packages/codegen/src/runner.ts
|
|
154
|
+
const extensionMap = {
|
|
155
|
+
".ts": ".js",
|
|
156
|
+
".tsx": ".js",
|
|
157
|
+
".mts": ".mjs",
|
|
158
|
+
".cts": ".cjs",
|
|
159
|
+
".js": ".js",
|
|
160
|
+
".mjs": ".mjs",
|
|
161
|
+
".cjs": ".cjs"
|
|
162
|
+
};
|
|
163
|
+
const toImportSpecifier = (fromPath, targetPath) => {
|
|
164
|
+
const fromDir = (0, node_path.dirname)(fromPath);
|
|
165
|
+
const normalized = (0, node_path.relative)(fromDir, targetPath).replace(/\\/g, "/");
|
|
166
|
+
const sourceExt = (0, node_path.extname)(targetPath);
|
|
167
|
+
const runtimeExt = extensionMap[sourceExt] ?? sourceExt;
|
|
168
|
+
if (normalized.length === 0) {
|
|
169
|
+
const base = runtimeExt !== sourceExt ? (0, node_path.basename)(targetPath, sourceExt) : (0, node_path.basename)(targetPath);
|
|
170
|
+
return `./${base}${runtimeExt}`;
|
|
171
|
+
}
|
|
172
|
+
const withPrefix = normalized.startsWith(".") ? normalized : `./${normalized}`;
|
|
173
|
+
if (!runtimeExt) {
|
|
174
|
+
return withPrefix;
|
|
175
|
+
}
|
|
176
|
+
if (withPrefix.endsWith(runtimeExt)) {
|
|
177
|
+
return withPrefix;
|
|
178
|
+
}
|
|
179
|
+
const currentExt = (0, node_path.extname)(withPrefix);
|
|
180
|
+
const withoutExt = currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;
|
|
181
|
+
return `${withoutExt}${runtimeExt}`;
|
|
182
|
+
};
|
|
183
|
+
const runMultiSchemaCodegen = async (options) => {
|
|
184
|
+
const outPath = (0, node_path.resolve)(options.outPath);
|
|
185
|
+
const runtimeAdapters = options.runtimeAdapters ?? (options.injectFromPath ? { default: options.injectFromPath } : {});
|
|
186
|
+
const scalars = options.scalars ?? (options.injectFromPath ? { default: options.injectFromPath } : {});
|
|
187
|
+
const adapterPaths = new Map();
|
|
188
|
+
const scalarPaths = new Map();
|
|
189
|
+
for (const [schemaName, adapterPath] of Object.entries(runtimeAdapters)) {
|
|
190
|
+
const resolvedPath = (0, node_path.resolve)(adapterPath);
|
|
191
|
+
if (!(0, node_fs.existsSync)(resolvedPath)) {
|
|
192
|
+
return (0, neverthrow.err)({
|
|
193
|
+
code: "INJECT_MODULE_NOT_FOUND",
|
|
194
|
+
message: `Runtime adapter module not found for schema '${schemaName}': ${resolvedPath}`,
|
|
195
|
+
injectPath: resolvedPath
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
adapterPaths.set(schemaName, resolvedPath);
|
|
199
|
+
}
|
|
200
|
+
for (const [schemaName, scalarPath] of Object.entries(scalars)) {
|
|
201
|
+
const resolvedPath = (0, node_path.resolve)(scalarPath);
|
|
202
|
+
if (!(0, node_fs.existsSync)(resolvedPath)) {
|
|
203
|
+
return (0, neverthrow.err)({
|
|
204
|
+
code: "INJECT_MODULE_NOT_FOUND",
|
|
205
|
+
message: `Scalar module not found for schema '${schemaName}': ${resolvedPath}`,
|
|
206
|
+
injectPath: resolvedPath
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
scalarPaths.set(schemaName, resolvedPath);
|
|
210
|
+
}
|
|
211
|
+
const schemas = new Map();
|
|
212
|
+
const schemaHashes = {};
|
|
213
|
+
for (const [name, schemaPath] of Object.entries(options.schemas)) {
|
|
214
|
+
const result = await loadSchema(schemaPath).match((doc) => Promise.resolve((0, neverthrow.ok)(doc)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
215
|
+
if (result.isErr()) {
|
|
216
|
+
return (0, neverthrow.err)(result.error);
|
|
217
|
+
}
|
|
218
|
+
schemas.set(name, result.value);
|
|
219
|
+
}
|
|
220
|
+
const injectionConfig = new Map();
|
|
221
|
+
for (const schemaName of schemas.keys()) {
|
|
222
|
+
const adapterPath = adapterPaths.get(schemaName);
|
|
223
|
+
const scalarPath = scalarPaths.get(schemaName);
|
|
224
|
+
if (!adapterPath || !scalarPath) {
|
|
225
|
+
return (0, neverthrow.err)({
|
|
226
|
+
code: "INJECT_MODULE_REQUIRED",
|
|
227
|
+
message: `Missing adapter or scalar configuration for schema '${schemaName}'`
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
injectionConfig.set(schemaName, {
|
|
231
|
+
adapterImportPath: toImportSpecifier(outPath, adapterPath),
|
|
232
|
+
scalarImportPath: toImportSpecifier(outPath, scalarPath)
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const { code } = require_generator.generateMultiSchemaModule(schemas, { injection: injectionConfig });
|
|
236
|
+
for (const [name, document] of schemas.entries()) {
|
|
237
|
+
const schemaIndex = (await Promise.resolve().then(() => require("./generator-DudCa3Gz.cjs"))).createSchemaIndex(document);
|
|
238
|
+
const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
|
|
239
|
+
const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
|
|
240
|
+
const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
|
|
241
|
+
const unions = Array.from(schemaIndex.unions.keys()).filter((n) => !n.startsWith("__")).length;
|
|
242
|
+
schemaHashes[name] = {
|
|
243
|
+
schemaHash: hashSchema(document),
|
|
244
|
+
objects,
|
|
245
|
+
enums,
|
|
246
|
+
inputs,
|
|
247
|
+
unions
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const writeResult = await writeModule(outPath, code).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
251
|
+
if (writeResult.isErr()) {
|
|
252
|
+
return (0, neverthrow.err)(writeResult.error);
|
|
253
|
+
}
|
|
254
|
+
const bundleOutcome = await bundleGraphqlSystem(outPath);
|
|
255
|
+
const bundleResult = bundleOutcome.match((result) => (0, neverthrow.ok)(result), (error) => (0, neverthrow.err)(error));
|
|
256
|
+
if (bundleResult.isErr()) {
|
|
257
|
+
return (0, neverthrow.err)(bundleResult.error);
|
|
258
|
+
}
|
|
259
|
+
return (0, neverthrow.ok)({
|
|
260
|
+
schemas: schemaHashes,
|
|
261
|
+
outPath,
|
|
262
|
+
cjsPath: bundleResult.value.cjsPath
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
exports.hashSchema = hashSchema;
|
|
268
|
+
exports.loadSchema = loadSchema;
|
|
269
|
+
exports.runMultiSchemaCodegen = runMultiSchemaCodegen;
|
|
270
|
+
exports.writeInjectTemplate = writeInjectTemplate;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as neverthrow0 from "neverthrow";
|
|
2
|
+
import { Result } from "neverthrow";
|
|
3
|
+
import { DocumentNode } from "graphql";
|
|
4
|
+
|
|
5
|
+
//#region packages/codegen/src/types.d.ts
|
|
6
|
+
type CodegenFormat = "json" | "human";
|
|
7
|
+
type CodegenOptions = {
|
|
8
|
+
readonly schemaPath: string;
|
|
9
|
+
readonly outPath: string;
|
|
10
|
+
readonly format: CodegenFormat;
|
|
11
|
+
readonly injectFromPath: string;
|
|
12
|
+
};
|
|
13
|
+
type MultiSchemaCodegenOptions = {
|
|
14
|
+
readonly schemas: Record<string, string>;
|
|
15
|
+
readonly outPath: string;
|
|
16
|
+
readonly format: CodegenFormat;
|
|
17
|
+
readonly runtimeAdapters?: Record<string, string>;
|
|
18
|
+
readonly scalars?: Record<string, string>;
|
|
19
|
+
readonly injectFromPath?: string;
|
|
20
|
+
};
|
|
21
|
+
type CodegenCliCommand = {
|
|
22
|
+
readonly kind: "generate";
|
|
23
|
+
readonly options: CodegenOptions;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "emitInjectTemplate";
|
|
26
|
+
readonly outPath: string;
|
|
27
|
+
readonly format: CodegenFormat;
|
|
28
|
+
};
|
|
29
|
+
type CodegenError = {
|
|
30
|
+
readonly code: "SCHEMA_NOT_FOUND";
|
|
31
|
+
readonly message: string;
|
|
32
|
+
readonly schemaPath: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly code: "SCHEMA_INVALID";
|
|
35
|
+
readonly message: string;
|
|
36
|
+
readonly schemaPath: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly code: "EMIT_FAILED";
|
|
39
|
+
readonly message: string;
|
|
40
|
+
readonly outPath: string;
|
|
41
|
+
} | {
|
|
42
|
+
readonly code: "INJECT_MODULE_REQUIRED";
|
|
43
|
+
readonly message: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly code: "INJECT_MODULE_NOT_FOUND";
|
|
46
|
+
readonly message: string;
|
|
47
|
+
readonly injectPath: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly code: "INJECT_TEMPLATE_EXISTS";
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly outPath: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly code: "INJECT_TEMPLATE_FAILED";
|
|
54
|
+
readonly message: string;
|
|
55
|
+
readonly outPath: string;
|
|
56
|
+
};
|
|
57
|
+
type CodegenSuccess = {
|
|
58
|
+
readonly schemaHash: string;
|
|
59
|
+
readonly outPath: string;
|
|
60
|
+
readonly objects: number;
|
|
61
|
+
readonly enums: number;
|
|
62
|
+
readonly inputs: number;
|
|
63
|
+
readonly unions: number;
|
|
64
|
+
};
|
|
65
|
+
type MultiSchemaCodegenSuccess = {
|
|
66
|
+
readonly schemas: Record<string, {
|
|
67
|
+
readonly schemaHash: string;
|
|
68
|
+
readonly objects: number;
|
|
69
|
+
readonly enums: number;
|
|
70
|
+
readonly inputs: number;
|
|
71
|
+
readonly unions: number;
|
|
72
|
+
}>;
|
|
73
|
+
readonly outPath: string;
|
|
74
|
+
readonly cjsPath: string;
|
|
75
|
+
};
|
|
76
|
+
type CodegenResult = Result<CodegenSuccess, CodegenError>;
|
|
77
|
+
type MultiSchemaCodegenResult = Result<MultiSchemaCodegenSuccess, CodegenError>;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region packages/codegen/src/inject-template.d.ts
|
|
80
|
+
declare const writeInjectTemplate: (outPath: string) => neverthrow0.Err<void, CodegenError> | neverthrow0.Ok<void, CodegenError>;
|
|
81
|
+
declare const getInjectTemplate: () => string;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region packages/codegen/src/runner.d.ts
|
|
84
|
+
declare const runMultiSchemaCodegen: (options: MultiSchemaCodegenOptions) => Promise<MultiSchemaCodegenResult>;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region packages/codegen/src/schema.d.ts
|
|
87
|
+
declare const loadSchema: (schemaPath: string) => neverthrow0.Err<DocumentNode, CodegenError> | neverthrow0.Ok<DocumentNode, CodegenError>;
|
|
88
|
+
declare const hashSchema: (document: DocumentNode) => string;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type MultiSchemaCodegenOptions, type MultiSchemaCodegenResult, type MultiSchemaCodegenSuccess, hashSchema, loadSchema, runMultiSchemaCodegen, writeInjectTemplate };
|
|
91
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +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;KAEA,cAAA;;;EAFA,SAAA,MAAA,EAKO,aALM;EAEb,SAAA,cAAc,EAAA,MAGP;AAInB,CAAA;AAAqC,KAAzB,yBAAA,GAAyB;WACjB,OAAA,EAAA,MAAA,CAAA,MAAA,EAAA,MAAA,CAAA;WAED,OAAA,EAAA,MAAA;WACU,MAAA,EADV,aACU;WACR,eAAA,CAAA,EADQ,MACR,CAAA,MAAA,EAAA,MAAA,CAAA;EAAM,SAAA,OAAA,CAAA,EAAN,MAAM,CAAA,MAAA,EAAA,MAAA,CAAA;EAIf,SAAA,cAAiB,CAAA,EAAA,MAAA;CAAA;AAGL,KAHZ,iBAAA,GAGY;WAKD,IAAA,EAAA,UAAA;EAAa,SAAA,OAAA,EALZ,cAKY;AAGpC,CAAA,GAAY;EAoCA,SAAA,IAAA,EAAA,oBAAc;EASd,SAAA,OAAA,EAAA,MAAA;EAeA,SAAA,MAAA,EA/DW,aA+DE;CAAA;AAAU,KA5DvB,YAAA,GA4DuB;WAAgB,IAAA,EAAA,kBAAA;WAAvB,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import { DocumentNode } from "graphql";
|
|
4
|
+
|
|
5
|
+
//#region packages/codegen/src/types.d.ts
|
|
6
|
+
type CodegenFormat = "json" | "human";
|
|
7
|
+
type CodegenOptions = {
|
|
8
|
+
readonly schemaPath: string;
|
|
9
|
+
readonly outPath: string;
|
|
10
|
+
readonly format: CodegenFormat;
|
|
11
|
+
readonly injectFromPath: string;
|
|
12
|
+
};
|
|
13
|
+
type MultiSchemaCodegenOptions = {
|
|
14
|
+
readonly schemas: Record<string, string>;
|
|
15
|
+
readonly outPath: string;
|
|
16
|
+
readonly format: CodegenFormat;
|
|
17
|
+
readonly runtimeAdapters?: Record<string, string>;
|
|
18
|
+
readonly scalars?: Record<string, string>;
|
|
19
|
+
readonly injectFromPath?: string;
|
|
20
|
+
};
|
|
21
|
+
type CodegenCliCommand = {
|
|
22
|
+
readonly kind: "generate";
|
|
23
|
+
readonly options: CodegenOptions;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "emitInjectTemplate";
|
|
26
|
+
readonly outPath: string;
|
|
27
|
+
readonly format: CodegenFormat;
|
|
28
|
+
};
|
|
29
|
+
type CodegenError = {
|
|
30
|
+
readonly code: "SCHEMA_NOT_FOUND";
|
|
31
|
+
readonly message: string;
|
|
32
|
+
readonly schemaPath: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly code: "SCHEMA_INVALID";
|
|
35
|
+
readonly message: string;
|
|
36
|
+
readonly schemaPath: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly code: "EMIT_FAILED";
|
|
39
|
+
readonly message: string;
|
|
40
|
+
readonly outPath: string;
|
|
41
|
+
} | {
|
|
42
|
+
readonly code: "INJECT_MODULE_REQUIRED";
|
|
43
|
+
readonly message: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly code: "INJECT_MODULE_NOT_FOUND";
|
|
46
|
+
readonly message: string;
|
|
47
|
+
readonly injectPath: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly code: "INJECT_TEMPLATE_EXISTS";
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly outPath: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly code: "INJECT_TEMPLATE_FAILED";
|
|
54
|
+
readonly message: string;
|
|
55
|
+
readonly outPath: string;
|
|
56
|
+
};
|
|
57
|
+
type CodegenSuccess = {
|
|
58
|
+
readonly schemaHash: string;
|
|
59
|
+
readonly outPath: string;
|
|
60
|
+
readonly objects: number;
|
|
61
|
+
readonly enums: number;
|
|
62
|
+
readonly inputs: number;
|
|
63
|
+
readonly unions: number;
|
|
64
|
+
};
|
|
65
|
+
type MultiSchemaCodegenSuccess = {
|
|
66
|
+
readonly schemas: Record<string, {
|
|
67
|
+
readonly schemaHash: string;
|
|
68
|
+
readonly objects: number;
|
|
69
|
+
readonly enums: number;
|
|
70
|
+
readonly inputs: number;
|
|
71
|
+
readonly unions: number;
|
|
72
|
+
}>;
|
|
73
|
+
readonly outPath: string;
|
|
74
|
+
readonly cjsPath: string;
|
|
75
|
+
};
|
|
76
|
+
type CodegenResult = Result<CodegenSuccess, CodegenError>;
|
|
77
|
+
type MultiSchemaCodegenResult = Result<MultiSchemaCodegenSuccess, CodegenError>;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region packages/codegen/src/inject-template.d.ts
|
|
80
|
+
declare const writeInjectTemplate: (outPath: string) => neverthrow1.Err<void, CodegenError> | neverthrow1.Ok<void, CodegenError>;
|
|
81
|
+
declare const getInjectTemplate: () => string;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region packages/codegen/src/runner.d.ts
|
|
84
|
+
declare const runMultiSchemaCodegen: (options: MultiSchemaCodegenOptions) => Promise<MultiSchemaCodegenResult>;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region packages/codegen/src/schema.d.ts
|
|
87
|
+
declare const loadSchema: (schemaPath: string) => neverthrow1.Err<DocumentNode, CodegenError> | neverthrow1.Ok<DocumentNode, CodegenError>;
|
|
88
|
+
declare const hashSchema: (document: DocumentNode) => string;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { type CodegenCliCommand, type CodegenError, type CodegenFormat, type MultiSchemaCodegenOptions, type MultiSchemaCodegenResult, type MultiSchemaCodegenSuccess, hashSchema, loadSchema, runMultiSchemaCodegen, writeInjectTemplate };
|
|
91
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/inject-template.ts","../src/runner.ts","../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;KAEY,aAAA;KAEA,cAAA;;;EAFA,SAAA,MAAA,EAKO,aALM;EAEb,SAAA,cAAc,EAAA,MAGP;AAInB,CAAA;AAAqC,KAAzB,yBAAA,GAAyB;WACjB,OAAA,EAAA,MAAA,CAAA,MAAA,EAAA,MAAA,CAAA;WAED,OAAA,EAAA,MAAA;WACU,MAAA,EADV,aACU;WACR,eAAA,CAAA,EADQ,MACR,CAAA,MAAA,EAAA,MAAA,CAAA;EAAM,SAAA,OAAA,CAAA,EAAN,MAAM,CAAA,MAAA,EAAA,MAAA,CAAA;EAIf,SAAA,cAAiB,CAAA,EAAA,MAAA;CAAA;AAGL,KAHZ,iBAAA,GAGY;WAKD,IAAA,EAAA,UAAA;EAAa,SAAA,OAAA,EALZ,cAKY;AAGpC,CAAA,GAAY;EAoCA,SAAA,IAAA,EAAA,oBAAc;EASd,SAAA,OAAA,EAAA,MAAA;EAeA,SAAA,MAAA,EA/DW,aA+DE;CAAA;AAAU,KA5DvB,YAAA,GA4DuB;WAAgB,IAAA,EAAA,kBAAA;WAAvB,OAAA,EAAA,MAAA;EAAM,SAAA,UAAA,EAAA,MAAA;AAClC,CAAA,GAAY;EAAwB,SAAA,IAAA,EAAA,gBAAA;WAAU,OAAA,EAAA,MAAA;WAA2B,UAAA,EAAA,MAAA;;EAA5B,SAAA,IAAA,EAAA,aAAA;;;;ECjDhC,SAAA,IAAA,EAAA,wBAuBZ;EAAA,SAAA,OAAA,EAAA,MAAA;;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