@openmirai/typeforge 0.1.7
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/README.md +268 -0
- package/assets/typeforge-logo.png +0 -0
- package/dist/adapters/axios/index.d.ts +38 -0
- package/dist/adapters/axios/index.d.ts.map +1 -0
- package/dist/adapters/axios/index.js +43 -0
- package/dist/adapters/axios/index.js.map +1 -0
- package/dist/adapters/fetch/index.d.ts +42 -0
- package/dist/adapters/fetch/index.d.ts.map +1 -0
- package/dist/adapters/fetch/index.js +77 -0
- package/dist/adapters/fetch/index.js.map +1 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +182 -0
- package/dist/cli.js.map +1 -0
- package/dist/http/types.d.ts +32 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +2 -0
- package/dist/http/validate.d.ts +10 -0
- package/dist/http/validate.d.ts.map +1 -0
- package/dist/http/validate.js +21 -0
- package/dist/http/validate.js.map +1 -0
- package/dist/index.d.ts +326 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/init-BBNO0SYd.js +2029 -0
- package/dist/init-BBNO0SYd.js.map +1 -0
- package/dist/routes/index.d.ts +33 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +38 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/validation/zod.d.ts +11 -0
- package/dist/validation/zod.d.ts.map +1 -0
- package/dist/validation/zod.js +8 -0
- package/dist/validation/zod.js.map +1 -0
- package/package.json +107 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { g as loadProjectConfig, h as listSourceKeys, r as generateForSource, t as initProject } from "./init-BBNO0SYd.js";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
function parseArgs(argv) {
|
|
7
|
+
const parsed = { sources: [] };
|
|
8
|
+
const positional = [];
|
|
9
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
10
|
+
const arg = argv[index];
|
|
11
|
+
if (arg === void 0) continue;
|
|
12
|
+
if (arg === "--check") {
|
|
13
|
+
parsed.check = true;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (arg === "--accept-base") {
|
|
17
|
+
parsed.acceptBase = true;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (arg === "--all") {
|
|
21
|
+
parsed.all = true;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (arg.startsWith("--source=")) {
|
|
25
|
+
const value = arg.slice(9);
|
|
26
|
+
parsed.sources.push(value);
|
|
27
|
+
if (parsed.source === void 0) parsed.source = value;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (arg === "--source") {
|
|
31
|
+
const value = argv[index + 1];
|
|
32
|
+
if (value !== void 0) {
|
|
33
|
+
parsed.sources.push(value);
|
|
34
|
+
if (parsed.source === void 0) parsed.source = value;
|
|
35
|
+
index += 1;
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (arg.startsWith("--spec=")) {
|
|
40
|
+
parsed.spec = arg.slice(7);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (arg === "--spec") {
|
|
44
|
+
const value = argv[index + 1];
|
|
45
|
+
if (value !== void 0) {
|
|
46
|
+
parsed.spec = value;
|
|
47
|
+
index += 1;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (arg.startsWith("--client=")) {
|
|
52
|
+
const value = arg.slice(9);
|
|
53
|
+
if (value === "axios" || value === "fetch" || value === "custom") parsed.client = value;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (arg === "--client") {
|
|
57
|
+
const value = argv[index + 1];
|
|
58
|
+
if (value === "axios" || value === "fetch" || value === "custom") {
|
|
59
|
+
parsed.client = value;
|
|
60
|
+
index += 1;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (arg.startsWith("--layout=")) {
|
|
65
|
+
const value = arg.slice(9);
|
|
66
|
+
if (value === "monolith" || value === "packages") parsed.layout = value;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (arg === "--layout") {
|
|
70
|
+
const value = argv[index + 1];
|
|
71
|
+
if (value === "monolith" || value === "packages") {
|
|
72
|
+
parsed.layout = value;
|
|
73
|
+
index += 1;
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (!arg.startsWith("-")) positional.push(arg);
|
|
78
|
+
}
|
|
79
|
+
const command = positional[0];
|
|
80
|
+
if (command !== void 0) parsed.command = command;
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
83
|
+
function printHelp() {
|
|
84
|
+
process.stdout.write(`typeforge — headless OpenAPI TypeScript codegen
|
|
85
|
+
|
|
86
|
+
Usage:
|
|
87
|
+
typeforge init --source <key> --client axios|fetch|custom [--layout monolith|packages]
|
|
88
|
+
typeforge generate --source <key> [--source <key2> ...] [--spec <path>] [--check] [--accept-base]
|
|
89
|
+
typeforge generate --all [--check] [--accept-base]
|
|
90
|
+
typeforge check --source <key> [--spec <path>]
|
|
91
|
+
typeforge accept-base --source <key> [--spec <path>]
|
|
92
|
+
|
|
93
|
+
Multi-source generate:
|
|
94
|
+
Provide multiple --source flags, or use --all to generate every source under apiRoot.
|
|
95
|
+
Configure per-source spec paths in each source.ts:
|
|
96
|
+
import { defineSourceConfig } from "@openmirai/typeforge";
|
|
97
|
+
export default defineSourceConfig({ spec: "./specs/acme.json", ... });
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
async function runGenerate(args) {
|
|
101
|
+
if (args.check === true && args.acceptBase === true) {
|
|
102
|
+
process.stderr.write("typeforge: --accept-base is not allowed with --check\n");
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
const cwd = process.cwd();
|
|
106
|
+
const apiRoot = loadProjectConfig(cwd).apiRoot ?? "src/api";
|
|
107
|
+
let sources;
|
|
108
|
+
if (args.all === true) sources = listSourceKeys(cwd, apiRoot);
|
|
109
|
+
else if (args.sources.length > 0) sources = args.sources;
|
|
110
|
+
else sources = [];
|
|
111
|
+
if (sources.length === 0) {
|
|
112
|
+
process.stderr.write("typeforge: --source <key> or --all is required\n");
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
let exitCode = 0;
|
|
116
|
+
for (const sourceKey of sources) try {
|
|
117
|
+
const generateOptions = { sourceKey };
|
|
118
|
+
if (args.acceptBase === true) generateOptions.acceptBase = true;
|
|
119
|
+
if (args.check === true) generateOptions.check = true;
|
|
120
|
+
if (args.spec !== void 0) generateOptions.specFlag = args.spec;
|
|
121
|
+
const result = await generateForSource(generateOptions);
|
|
122
|
+
if (args.check === true) {
|
|
123
|
+
if (result.changed.length > 0) {
|
|
124
|
+
process.stderr.write(`typeforge: stale generated files for "${sourceKey}":\n`);
|
|
125
|
+
for (const file of result.changed) process.stderr.write(` ${file}\n`);
|
|
126
|
+
exitCode = 1;
|
|
127
|
+
} else process.stdout.write(`typeforge: "${sourceKey}" is up to date\n`);
|
|
128
|
+
} else process.stdout.write(`typeforge: generated ${result.files} files for "${sourceKey}" (${result.changed.length} changed)\n`);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
exitCode = 1;
|
|
131
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
132
|
+
process.stderr.write(`${message}\n`);
|
|
133
|
+
}
|
|
134
|
+
return exitCode;
|
|
135
|
+
}
|
|
136
|
+
async function main() {
|
|
137
|
+
const args = parseArgs(process.argv.slice(2));
|
|
138
|
+
if (args.command === void 0 || args.command === "help" || args.command === "--help" || args.command === "-h") {
|
|
139
|
+
printHelp();
|
|
140
|
+
process.exit(0);
|
|
141
|
+
}
|
|
142
|
+
if (args.command === "init") {
|
|
143
|
+
if (args.source === void 0 || args.client === void 0) {
|
|
144
|
+
process.stderr.write("typeforge: init requires --source and --client\n");
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
const initOptions = {
|
|
148
|
+
client: args.client,
|
|
149
|
+
sourceKey: args.source
|
|
150
|
+
};
|
|
151
|
+
if (args.layout !== void 0) initOptions.layout = args.layout;
|
|
152
|
+
const result = initProject(initOptions);
|
|
153
|
+
for (const file of result.created) process.stdout.write(`created ${file}\n`);
|
|
154
|
+
for (const file of result.skipped) process.stdout.write(`skipped ${file} (already exists)\n`);
|
|
155
|
+
process.exit(0);
|
|
156
|
+
}
|
|
157
|
+
if (args.command === "generate" || args.command === "check" || args.command === "accept-base") {
|
|
158
|
+
if (args.command === "check") args.check = true;
|
|
159
|
+
if (args.command === "accept-base") args.acceptBase = true;
|
|
160
|
+
process.exit(await runGenerate(args));
|
|
161
|
+
}
|
|
162
|
+
process.stderr.write(`typeforge: unknown command "${args.command}"\n`);
|
|
163
|
+
printHelp();
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
if ((() => {
|
|
167
|
+
const entry = process.argv[1];
|
|
168
|
+
if (entry === void 0) return false;
|
|
169
|
+
try {
|
|
170
|
+
return import.meta.url === pathToFileURL(realpathSync(entry)).href;
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
})()) main().catch((error) => {
|
|
175
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
176
|
+
process.stderr.write(`${message}\n`);
|
|
177
|
+
process.exit(1);
|
|
178
|
+
});
|
|
179
|
+
//#endregion
|
|
180
|
+
export { parseArgs };
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { realpathSync } from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport { listSourceKeys, loadProjectConfig } from \"./config/load\";\nimport { generateForSource } from \"./generate/index\";\nimport type { GenerateOptions } from \"./generate/index\";\nimport { initProject } from \"./init/index\";\nimport type { InitOptions } from \"./init/index\";\n\ninterface ParsedArgs {\n command?: string;\n /** Populated by the first --source value; kept for init (single-source) compat. */\n source?: string;\n /** All --source values collected for multi-source generate. */\n sources: Array<string>;\n spec?: string;\n client?: \"axios\" | \"fetch\" | \"custom\";\n layout?: \"monolith\" | \"packages\";\n check?: boolean;\n acceptBase?: boolean;\n all?: boolean;\n}\n\nexport function parseArgs(argv: Array<string>): ParsedArgs {\n const parsed: ParsedArgs = { sources: [] };\n const positional: Array<string> = [];\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n if (arg === undefined) {\n continue;\n }\n\n if (arg === \"--check\") {\n parsed.check = true;\n continue;\n }\n if (arg === \"--accept-base\") {\n parsed.acceptBase = true;\n continue;\n }\n if (arg === \"--all\") {\n parsed.all = true;\n continue;\n }\n if (arg.startsWith(\"--source=\")) {\n const value = arg.slice(\"--source=\".length);\n parsed.sources.push(value);\n if (parsed.source === undefined) {\n parsed.source = value;\n }\n continue;\n }\n if (arg === \"--source\") {\n const value = argv[index + 1];\n if (value !== undefined) {\n parsed.sources.push(value);\n if (parsed.source === undefined) {\n parsed.source = value;\n }\n index += 1;\n }\n continue;\n }\n if (arg.startsWith(\"--spec=\")) {\n parsed.spec = arg.slice(\"--spec=\".length);\n continue;\n }\n if (arg === \"--spec\") {\n const value = argv[index + 1];\n if (value !== undefined) {\n parsed.spec = value;\n index += 1;\n }\n continue;\n }\n if (arg.startsWith(\"--client=\")) {\n const value = arg.slice(\"--client=\".length);\n if (value === \"axios\" || value === \"fetch\" || value === \"custom\") {\n parsed.client = value;\n }\n continue;\n }\n if (arg === \"--client\") {\n const value = argv[index + 1];\n if (value === \"axios\" || value === \"fetch\" || value === \"custom\") {\n parsed.client = value;\n index += 1;\n }\n continue;\n }\n if (arg.startsWith(\"--layout=\")) {\n const value = arg.slice(\"--layout=\".length);\n if (value === \"monolith\" || value === \"packages\") {\n parsed.layout = value;\n }\n continue;\n }\n if (arg === \"--layout\") {\n const value = argv[index + 1];\n if (value === \"monolith\" || value === \"packages\") {\n parsed.layout = value;\n index += 1;\n }\n continue;\n }\n if (!arg.startsWith(\"-\")) {\n positional.push(arg);\n }\n }\n\n const command = positional[0];\n if (command !== undefined) {\n parsed.command = command;\n }\n return parsed;\n}\n\nfunction printHelp(): void {\n process.stdout.write(`typeforge — headless OpenAPI TypeScript codegen\n\nUsage:\n typeforge init --source <key> --client axios|fetch|custom [--layout monolith|packages]\n typeforge generate --source <key> [--source <key2> ...] [--spec <path>] [--check] [--accept-base]\n typeforge generate --all [--check] [--accept-base]\n typeforge check --source <key> [--spec <path>]\n typeforge accept-base --source <key> [--spec <path>]\n\nMulti-source generate:\n Provide multiple --source flags, or use --all to generate every source under apiRoot.\n Configure per-source spec paths in each source.ts:\n import { defineSourceConfig } from \"@openmirai/typeforge\";\n export default defineSourceConfig({ spec: \"./specs/acme.json\", ... });\n`);\n}\n\nasync function runGenerate(args: ParsedArgs): Promise<number> {\n if (args.check === true && args.acceptBase === true) {\n process.stderr.write(\n \"typeforge: --accept-base is not allowed with --check\\n\"\n );\n return 1;\n }\n\n const cwd = process.cwd();\n const projectConfig = loadProjectConfig(cwd);\n const apiRoot = projectConfig.apiRoot ?? \"src/api\";\n let sources: Array<string>;\n if (args.all === true) {\n sources = listSourceKeys(cwd, apiRoot);\n } else if (args.sources.length > 0) {\n sources = args.sources;\n } else {\n sources = [];\n }\n\n if (sources.length === 0) {\n process.stderr.write(\"typeforge: --source <key> or --all is required\\n\");\n return 1;\n }\n\n let exitCode = 0;\n for (const sourceKey of sources) {\n try {\n const generateOptions: GenerateOptions = { sourceKey };\n if (args.acceptBase === true) {\n generateOptions.acceptBase = true;\n }\n if (args.check === true) {\n generateOptions.check = true;\n }\n if (args.spec !== undefined) {\n generateOptions.specFlag = args.spec;\n }\n\n const result = await generateForSource(generateOptions);\n\n if (args.check === true) {\n if (result.changed.length > 0) {\n process.stderr.write(\n `typeforge: stale generated files for \"${sourceKey}\":\\n`\n );\n for (const file of result.changed) {\n process.stderr.write(` ${file}\\n`);\n }\n exitCode = 1;\n } else {\n process.stdout.write(`typeforge: \"${sourceKey}\" is up to date\\n`);\n }\n } else {\n process.stdout.write(\n `typeforge: generated ${result.files} files for \"${sourceKey}\" (${result.changed.length} changed)\\n`\n );\n }\n } catch (error) {\n exitCode = 1;\n const message = error instanceof Error ? error.message : String(error);\n process.stderr.write(`${message}\\n`);\n }\n }\n\n return exitCode;\n}\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n\n if (\n args.command === undefined ||\n args.command === \"help\" ||\n args.command === \"--help\" ||\n args.command === \"-h\"\n ) {\n printHelp();\n process.exit(0);\n }\n\n if (args.command === \"init\") {\n if (args.source === undefined || args.client === undefined) {\n process.stderr.write(\"typeforge: init requires --source and --client\\n\");\n process.exit(1);\n }\n\n const initOptions: InitOptions = {\n client: args.client,\n sourceKey: args.source,\n };\n if (args.layout !== undefined) {\n initOptions.layout = args.layout;\n }\n\n const result = initProject(initOptions);\n\n for (const file of result.created) {\n process.stdout.write(`created ${file}\\n`);\n }\n for (const file of result.skipped) {\n process.stdout.write(`skipped ${file} (already exists)\\n`);\n }\n process.exit(0);\n }\n\n if (\n args.command === \"generate\" ||\n args.command === \"check\" ||\n args.command === \"accept-base\"\n ) {\n if (args.command === \"check\") {\n args.check = true;\n }\n if (args.command === \"accept-base\") {\n args.acceptBase = true;\n }\n process.exit(await runGenerate(args));\n }\n\n process.stderr.write(`typeforge: unknown command \"${args.command}\"\\n`);\n printHelp();\n process.exit(1);\n}\n\n// Only auto-execute when this file is the Node.js entry point.\n// Guarding with import.meta.url allows the module to be safely imported\n// in tests without triggering process.exit.\nconst isEntryPoint = ((): boolean => {\n const entry = process.argv[1];\n if (entry === undefined) {\n return false;\n }\n try {\n return import.meta.url === pathToFileURL(realpathSync(entry)).href;\n } catch {\n return false;\n }\n})();\n\nif (isEntryPoint) {\n main().catch((error: unknown) => {\n const message = error instanceof Error ? error.message : String(error);\n process.stderr.write(`${message}\\n`);\n process.exit(1);\n });\n}\n"],"mappings":";;;;;AAuBA,SAAgB,UAAU,MAAiC;CACzD,MAAM,SAAqB,EAAE,SAAS,CAAC,EAAE;CACzC,MAAM,aAA4B,CAAC;CAEnC,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;EACnD,MAAM,MAAM,KAAK;EACjB,IAAI,QAAQ,KAAA,GACV;EAGF,IAAI,QAAQ,WAAW;GACrB,OAAO,QAAQ;GACf;EACF;EACA,IAAI,QAAQ,iBAAiB;GAC3B,OAAO,aAAa;GACpB;EACF;EACA,IAAI,QAAQ,SAAS;GACnB,OAAO,MAAM;GACb;EACF;EACA,IAAI,IAAI,WAAW,WAAW,GAAG;GAC/B,MAAM,QAAQ,IAAI,MAAM,CAAkB;GAC1C,OAAO,QAAQ,KAAK,KAAK;GACzB,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;GAElB;EACF;EACA,IAAI,QAAQ,YAAY;GACtB,MAAM,QAAQ,KAAK,QAAQ;GAC3B,IAAI,UAAU,KAAA,GAAW;IACvB,OAAO,QAAQ,KAAK,KAAK;IACzB,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;IAElB,SAAS;GACX;GACA;EACF;EACA,IAAI,IAAI,WAAW,SAAS,GAAG;GAC7B,OAAO,OAAO,IAAI,MAAM,CAAgB;GACxC;EACF;EACA,IAAI,QAAQ,UAAU;GACpB,MAAM,QAAQ,KAAK,QAAQ;GAC3B,IAAI,UAAU,KAAA,GAAW;IACvB,OAAO,OAAO;IACd,SAAS;GACX;GACA;EACF;EACA,IAAI,IAAI,WAAW,WAAW,GAAG;GAC/B,MAAM,QAAQ,IAAI,MAAM,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,QAAQ,OAAO,MAAM,WAAW,KAAK,GAAG;EAE1C,KAAK,MAAM,QAAQ,OAAO,SACxB,QAAQ,OAAO,MAAM,WAAW,KAAK,oBAAoB;EAE3D,QAAQ,KAAK,CAAC;CAChB;CAEA,IACE,KAAK,YAAY,cACjB,KAAK,YAAY,WACjB,KAAK,YAAY,eACjB;EACA,IAAI,KAAK,YAAY,SACnB,KAAK,QAAQ;EAEf,IAAI,KAAK,YAAY,eACnB,KAAK,aAAa;EAEpB,QAAQ,KAAK,MAAM,YAAY,IAAI,CAAC;CACtC;CAEA,QAAQ,OAAO,MAAM,+BAA+B,KAAK,QAAQ,IAAI;CACrE,UAAU;CACV,QAAQ,KAAK,CAAC;AAChB;AAiBA,WAZqC;CACnC,MAAM,QAAQ,QAAQ,KAAK;CAC3B,IAAI,UAAU,KAAA,GACZ,OAAO;CAET,IAAI;EACF,OAAO,YAAY,QAAQ,cAAc,aAAa,KAAK,CAAC,CAAC,CAAC;CAChE,QAAQ;EACN,OAAO;CACT;AACF,EAAA,CAEe,GACb,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CACrE,QAAQ,OAAO,MAAM,GAAG,QAAQ,GAAG;CACnC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ResponseValidationError, ResponseValidator, coerceResponseData } from "./validate.js";
|
|
2
|
+
//#region src/json/types.d.ts
|
|
3
|
+
type QueryParamValue = string | number | boolean | null | undefined;
|
|
4
|
+
type QueryParams = Record<string, QueryParamValue>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/http/types.d.ts
|
|
7
|
+
interface HTTPFetchConfig<TParams extends object = QueryParams, TResponse = unknown> {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
params?: TParams;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
validateResponse?: ResponseValidator<TResponse>;
|
|
12
|
+
}
|
|
13
|
+
interface HTTPFetch {
|
|
14
|
+
get<TResponse, TParams extends object = QueryParams>(route: string, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
15
|
+
data: TResponse;
|
|
16
|
+
}>;
|
|
17
|
+
post<TResponse, TBody = unknown, TParams extends object = QueryParams>(route: string, body: TBody, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
18
|
+
data: TResponse;
|
|
19
|
+
}>;
|
|
20
|
+
put<TResponse, TBody = unknown, TParams extends object = QueryParams>(route: string, body: TBody, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
21
|
+
data: TResponse;
|
|
22
|
+
}>;
|
|
23
|
+
patch<TResponse, TBody = unknown, TParams extends object = QueryParams>(route: string, body: TBody, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
24
|
+
data: TResponse;
|
|
25
|
+
}>;
|
|
26
|
+
delete<TResponse, TParams extends object = QueryParams>(route: string, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
27
|
+
data: TResponse;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { HTTPFetch, HTTPFetchConfig, type QueryParamValue, type QueryParams, ResponseValidationError, type ResponseValidator, coerceResponseData };
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/json/types.ts","../../src/http/types.ts"],"mappings":";;KAUY;KAEA,cAAc,eAAe;;;UCLxB,gBACf,yBAAyB,aACzB;EAEA,SAAS;EACT,SAAS;EACT,UAAU;EACV,mBAAmB,kBAAkB;;UAGtB;EACf,IAAI,WAAW,yBAAyB,aACtC,eACA,SAAS,gBAAgB,SAAS,aACjC;IAAU,MAAM;;EACnB,KAAK,WAAW,iBAAiB,yBAAyB,aACxD,eACA,MAAM,OACN,SAAS,gBAAgB,SAAS,aACjC;IAAU,MAAM;;EACnB,IAAI,WAAW,iBAAiB,yBAAyB,aACvD,eACA,MAAM,OACN,SAAS,gBAAgB,SAAS,aACjC;IAAU,MAAM;;EACnB,MAAM,WAAW,iBAAiB,yBAAyB,aACzD,eACA,MAAM,OACN,SAAS,gBAAgB,SAAS,aACjC;IAAU,MAAM;;EACnB,OAAO,WAAW,yBAAyB,aACzC,eACA,SAAS,gBAAgB,SAAS,aACjC;IAAU,MAAM"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/http/validate.d.ts
|
|
2
|
+
type ResponseValidator<T> = (value: unknown) => T;
|
|
3
|
+
declare class ResponseValidationError extends Error {
|
|
4
|
+
readonly cause: unknown;
|
|
5
|
+
constructor(message: string, cause: unknown);
|
|
6
|
+
}
|
|
7
|
+
declare function coerceResponseData<T>(value: unknown, validator?: ResponseValidator<T>): T;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ResponseValidationError, ResponseValidator, coerceResponseData };
|
|
10
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","names":[],"sources":["../../src/http/validate.ts"],"mappings":";KAAY,kBAAkB,MAAM,mBAAmB;cAE1C,gCAAgC;WACzB;EAElB,YAAY,iBAAiB;;iBAOf,mBAAmB,GACjC,gBACA,YAAY,kBAAkB,KAC7B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/http/validate.ts
|
|
2
|
+
var ResponseValidationError = class extends Error {
|
|
3
|
+
cause;
|
|
4
|
+
constructor(message, cause) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "ResponseValidationError";
|
|
7
|
+
this.cause = cause;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function coerceResponseData(value, validator) {
|
|
11
|
+
if (validator === void 0) return value;
|
|
12
|
+
try {
|
|
13
|
+
return validator(value);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw new ResponseValidationError("Response validation failed", error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ResponseValidationError, coerceResponseData };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","names":[],"sources":["../../src/http/validate.ts"],"sourcesContent":["export type ResponseValidator<T> = (value: unknown) => T;\n\nexport class ResponseValidationError extends Error {\n override readonly cause: unknown;\n\n constructor(message: string, cause: unknown) {\n super(message);\n this.name = \"ResponseValidationError\";\n this.cause = cause;\n }\n}\n\nexport function coerceResponseData<T>(\n value: unknown,\n validator?: ResponseValidator<T>\n): T {\n if (validator === undefined) {\n return value as T;\n }\n\n try {\n return validator(value);\n } catch (error) {\n throw new ResponseValidationError(\"Response validation failed\", error);\n }\n}\n"],"mappings":";AAEA,IAAa,0BAAb,cAA6C,MAAM;CACjD;CAEA,YAAY,SAAiB,OAAgB;EAC3C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF;AAEA,SAAgB,mBACd,OACA,WACG;CACH,IAAI,cAAc,KAAA,GAChB,OAAO;CAGT,IAAI;EACF,OAAO,UAAU,KAAK;CACxB,SAAS,OAAO;EACd,MAAM,IAAI,wBAAwB,8BAA8B,KAAK;CACvE;AACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
//#region src/json/types.d.ts
|
|
2
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
3
|
+
interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
type JsonArray = Array<JsonValue>;
|
|
7
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
8
|
+
type QueryParamValue = string | number | boolean | null | undefined;
|
|
9
|
+
type QueryParams = Record<string, QueryParamValue>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/parser/types.d.ts
|
|
12
|
+
interface IR {
|
|
13
|
+
sources: Array<IRSource>;
|
|
14
|
+
}
|
|
15
|
+
interface IRSource {
|
|
16
|
+
key: string;
|
|
17
|
+
paths: Array<IRPath>;
|
|
18
|
+
components: {
|
|
19
|
+
schemas: Record<string, IRSchema>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface IRPath {
|
|
23
|
+
path: string;
|
|
24
|
+
cleanPath: string;
|
|
25
|
+
operations: Array<IROperation>;
|
|
26
|
+
}
|
|
27
|
+
interface IROperation {
|
|
28
|
+
method: HttpMethod;
|
|
29
|
+
operationId?: string;
|
|
30
|
+
pathParams: Array<IRPathParam>;
|
|
31
|
+
queryParams: Array<IRQueryParam>;
|
|
32
|
+
requestBody?: IRRequestBody;
|
|
33
|
+
responses: Array<IRResponse>;
|
|
34
|
+
}
|
|
35
|
+
type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
36
|
+
interface IRPathParam {
|
|
37
|
+
name: string;
|
|
38
|
+
schema: IRSchema;
|
|
39
|
+
}
|
|
40
|
+
interface IRQueryParam {
|
|
41
|
+
name: string;
|
|
42
|
+
required: boolean;
|
|
43
|
+
schema: IRSchema;
|
|
44
|
+
}
|
|
45
|
+
interface IRRequestBody {
|
|
46
|
+
required: boolean;
|
|
47
|
+
schema: IRSchema;
|
|
48
|
+
}
|
|
49
|
+
interface IRResponse {
|
|
50
|
+
statusCode: string;
|
|
51
|
+
schema?: IRSchema;
|
|
52
|
+
}
|
|
53
|
+
interface IRSchema {
|
|
54
|
+
kind: "object" | "array" | "string" | "number" | "boolean" | "null" | "unknown" | "ref" | "oneOf" | "anyOf" | "allOf";
|
|
55
|
+
ref?: string;
|
|
56
|
+
items?: IRSchema;
|
|
57
|
+
properties?: Record<string, IRSchemaProperty>;
|
|
58
|
+
required?: Array<string>;
|
|
59
|
+
enum?: Array<JsonPrimitive>;
|
|
60
|
+
additionalProperties?: IRSchema | boolean;
|
|
61
|
+
oneOf?: Array<IRSchema>;
|
|
62
|
+
anyOf?: Array<IRSchema>;
|
|
63
|
+
allOf?: Array<IRSchema>;
|
|
64
|
+
format?: string;
|
|
65
|
+
nullable?: boolean;
|
|
66
|
+
"x-map-key-ref"?: string;
|
|
67
|
+
}
|
|
68
|
+
interface IRSchemaProperty {
|
|
69
|
+
schema: IRSchema;
|
|
70
|
+
required: boolean;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/parser/index.d.ts
|
|
74
|
+
declare function parseSchema(raw: JsonValue): IRSchema;
|
|
75
|
+
declare function parseSpec(raw: JsonValue, opts: {
|
|
76
|
+
pathPrefix?: string;
|
|
77
|
+
ignorePaths?: Array<string>;
|
|
78
|
+
}): IRSource;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/parser/loader.d.ts
|
|
81
|
+
type SpecSource = {
|
|
82
|
+
kind: "file";
|
|
83
|
+
path: string;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "env";
|
|
86
|
+
varName: string;
|
|
87
|
+
} | {
|
|
88
|
+
kind: "local-override";
|
|
89
|
+
path: string;
|
|
90
|
+
};
|
|
91
|
+
declare function loadSpec(source: SpecSource): Promise<JsonValue>;
|
|
92
|
+
/**
|
|
93
|
+
* Resolution priority:
|
|
94
|
+
* 1. --spec CLI flag
|
|
95
|
+
* 2. OPENAPI_SPEC_<UPPER_KEY> env var
|
|
96
|
+
* 3. source.ts `spec` property (project-relative path from config)
|
|
97
|
+
* 4. typeforge.local.json (gitignored per-machine override)
|
|
98
|
+
* 5. committed snapshot at snapshotPath
|
|
99
|
+
*
|
|
100
|
+
* Throws a human-readable error (no stack trace as first line) when nothing is found.
|
|
101
|
+
*/
|
|
102
|
+
declare function resolveSpecSource(sourceKey: string, opts: {
|
|
103
|
+
specFlag?: string;
|
|
104
|
+
sourceConfigSpec?: string;
|
|
105
|
+
localOverridePath?: string;
|
|
106
|
+
snapshotPath?: string;
|
|
107
|
+
}): SpecSource;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/http/validate.d.ts
|
|
110
|
+
type ResponseValidator<T> = (value: unknown) => T;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/http/types.d.ts
|
|
113
|
+
interface HTTPFetchConfig<TParams extends object = QueryParams, TResponse = unknown> {
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
params?: TParams;
|
|
116
|
+
headers?: Record<string, string>;
|
|
117
|
+
validateResponse?: ResponseValidator<TResponse>;
|
|
118
|
+
}
|
|
119
|
+
interface HTTPFetch {
|
|
120
|
+
get<TResponse, TParams extends object = QueryParams>(route: string, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
121
|
+
data: TResponse;
|
|
122
|
+
}>;
|
|
123
|
+
post<TResponse, TBody = unknown, TParams extends object = QueryParams>(route: string, body: TBody, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
124
|
+
data: TResponse;
|
|
125
|
+
}>;
|
|
126
|
+
put<TResponse, TBody = unknown, TParams extends object = QueryParams>(route: string, body: TBody, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
127
|
+
data: TResponse;
|
|
128
|
+
}>;
|
|
129
|
+
patch<TResponse, TBody = unknown, TParams extends object = QueryParams>(route: string, body: TBody, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
130
|
+
data: TResponse;
|
|
131
|
+
}>;
|
|
132
|
+
delete<TResponse, TParams extends object = QueryParams>(route: string, config?: HTTPFetchConfig<TParams, TResponse>): Promise<{
|
|
133
|
+
data: TResponse;
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/config/types.d.ts
|
|
138
|
+
interface TypeforgeConfig {
|
|
139
|
+
apiRoot?: string;
|
|
140
|
+
}
|
|
141
|
+
/** @deprecated Use `TypeforgeConfig`. */
|
|
142
|
+
type OpenApiCodegenConfig = TypeforgeConfig;
|
|
143
|
+
type GenerationMode = "authoritative" | "merge";
|
|
144
|
+
type NamingStrategy = "path" | "operationId";
|
|
145
|
+
interface QueryExtendsConfig {
|
|
146
|
+
page?: string;
|
|
147
|
+
limit?: string;
|
|
148
|
+
sortBy?: string;
|
|
149
|
+
sortOrder?: string;
|
|
150
|
+
paginationTypeName?: string;
|
|
151
|
+
paginationImportPath?: string;
|
|
152
|
+
sortTypeName?: string;
|
|
153
|
+
sortImportPath?: string;
|
|
154
|
+
}
|
|
155
|
+
interface SourceConfig {
|
|
156
|
+
/**
|
|
157
|
+
* Project-relative directory for generated API function files.
|
|
158
|
+
* Defaults to `<apiRoot>/<source>/generated/functions`.
|
|
159
|
+
*/
|
|
160
|
+
functionsDir?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Project-relative directory for generated API type files.
|
|
163
|
+
* Defaults to `<apiRoot>/<source>/generated/types`.
|
|
164
|
+
*/
|
|
165
|
+
typesDir?: string;
|
|
166
|
+
pathPrefix?: string;
|
|
167
|
+
ignorePaths?: Array<string>;
|
|
168
|
+
stripApiPrefix?: boolean;
|
|
169
|
+
routeEnumName?: string;
|
|
170
|
+
generationMode?: GenerationMode;
|
|
171
|
+
naming?: NamingStrategy;
|
|
172
|
+
maxRenderDepth?: number;
|
|
173
|
+
resolveMapKeyRefs?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Emit an envelope's `data` schema as the operation response type.
|
|
176
|
+
* Enable this only when the project's HTTPFetch implementation already
|
|
177
|
+
* unwraps response envelopes before returning its `{ data }` value.
|
|
178
|
+
*/
|
|
179
|
+
unwrapResponseData?: boolean;
|
|
180
|
+
queryExtends?: QueryExtendsConfig;
|
|
181
|
+
/** When true, emit TanStack Query helpers for GET endpoints (requires query-scope.ts). */
|
|
182
|
+
tanstackQuery?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Explicit import base for generated function files pointing back to the
|
|
185
|
+
* `generated/` directory. When set, overrides both relative paths and
|
|
186
|
+
* tsconfig alias auto-detection.
|
|
187
|
+
*
|
|
188
|
+
* Example: `"@mirai/utils/src/api/v2/generated"` produces imports like
|
|
189
|
+
* `import ... from "@mirai/utils/src/api/v2/generated/runtime"`.
|
|
190
|
+
*/
|
|
191
|
+
importBase?: string;
|
|
192
|
+
/**
|
|
193
|
+
* Path to the OpenAPI spec file, relative to the project root.
|
|
194
|
+
* Used as the default spec source when no --spec flag or env var is provided.
|
|
195
|
+
* Example: "../mirai-core-api/cmd/admin/docs/swagger.json"
|
|
196
|
+
*/
|
|
197
|
+
spec?: string;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/config/define.d.ts
|
|
201
|
+
/**
|
|
202
|
+
* Identity helper for `source.ts`. Use it so the object is checked against
|
|
203
|
+
* `SourceConfig` and editors can autocomplete fields.
|
|
204
|
+
*/
|
|
205
|
+
declare function defineSourceConfig(config: SourceConfig): SourceConfig;
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/generate/index.d.ts
|
|
208
|
+
interface GenerateOptions {
|
|
209
|
+
cwd?: string;
|
|
210
|
+
sourceKey: string;
|
|
211
|
+
specFlag?: string;
|
|
212
|
+
check?: boolean;
|
|
213
|
+
acceptBase?: boolean;
|
|
214
|
+
}
|
|
215
|
+
interface GenerateResult {
|
|
216
|
+
sourceKey: string;
|
|
217
|
+
files: number;
|
|
218
|
+
changed: Array<string>;
|
|
219
|
+
check: boolean;
|
|
220
|
+
}
|
|
221
|
+
interface GenerateContext {
|
|
222
|
+
cwd: string;
|
|
223
|
+
apiRoot: string;
|
|
224
|
+
sourceKey: string;
|
|
225
|
+
sourceConfig: SourceConfig;
|
|
226
|
+
sourceDir: string;
|
|
227
|
+
generatedDir: string;
|
|
228
|
+
typesDir: string;
|
|
229
|
+
functionsDir: string;
|
|
230
|
+
routesFile: string;
|
|
231
|
+
baseFile: string;
|
|
232
|
+
snapshotPath: string;
|
|
233
|
+
httpMode: "singleton" | "injected";
|
|
234
|
+
hasQueryScope: boolean;
|
|
235
|
+
}
|
|
236
|
+
declare function buildGenerateContext(cwd: string, sourceKey: string): GenerateContext;
|
|
237
|
+
declare function generateForSource(options: GenerateOptions): Promise<GenerateResult>;
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/init/index.d.ts
|
|
240
|
+
type HttpClient = "axios" | "fetch" | "custom";
|
|
241
|
+
type ProjectLayout = "monolith" | "packages";
|
|
242
|
+
interface InitOptions {
|
|
243
|
+
cwd?: string;
|
|
244
|
+
sourceKey: string;
|
|
245
|
+
client: HttpClient;
|
|
246
|
+
layout?: ProjectLayout;
|
|
247
|
+
}
|
|
248
|
+
declare function initProject(options: InitOptions): {
|
|
249
|
+
created: Array<string>;
|
|
250
|
+
skipped: Array<string>;
|
|
251
|
+
};
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/envelope-guard/index.d.ts
|
|
254
|
+
type EnvelopeMode = "shared" | "raw" | "mixed";
|
|
255
|
+
interface EnvelopeField {
|
|
256
|
+
name: string;
|
|
257
|
+
required: boolean;
|
|
258
|
+
kind: string;
|
|
259
|
+
}
|
|
260
|
+
interface EnvelopeShape {
|
|
261
|
+
fields: Array<EnvelopeField>;
|
|
262
|
+
schema: IRSchema;
|
|
263
|
+
}
|
|
264
|
+
interface OperationEnvelope {
|
|
265
|
+
method: string;
|
|
266
|
+
path: string;
|
|
267
|
+
shape: EnvelopeShape;
|
|
268
|
+
}
|
|
269
|
+
interface EnvelopeAnalysis {
|
|
270
|
+
mode: EnvelopeMode;
|
|
271
|
+
shared?: EnvelopeShape;
|
|
272
|
+
operations: Array<OperationEnvelope>;
|
|
273
|
+
groups: Map<string, Array<OperationEnvelope>>;
|
|
274
|
+
}
|
|
275
|
+
interface EnvelopeFieldDiff {
|
|
276
|
+
field: string;
|
|
277
|
+
issue: "missing" | "extra" | "type-changed" | "required-changed";
|
|
278
|
+
spec?: EnvelopeField;
|
|
279
|
+
user?: EnvelopeField;
|
|
280
|
+
}
|
|
281
|
+
interface UserBaseResponseShape {
|
|
282
|
+
fields: Array<EnvelopeField>;
|
|
283
|
+
sourcePath: string;
|
|
284
|
+
}
|
|
285
|
+
declare function analyzeEnvelope(source: IRSource): EnvelopeAnalysis;
|
|
286
|
+
declare function parseUserBaseResponse(content: string): UserBaseResponseShape | undefined;
|
|
287
|
+
declare function diffEnvelopeFields(spec: EnvelopeShape, user: UserBaseResponseShape): Array<EnvelopeFieldDiff>;
|
|
288
|
+
declare function buildBaseResponseInterface(shape: EnvelopeShape, genericName?: string): string;
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/emitters/recursive-ref-error.d.ts
|
|
291
|
+
declare class RecursiveRefError extends Error {
|
|
292
|
+
readonly cycle: Array<string>;
|
|
293
|
+
readonly schemaPath: string;
|
|
294
|
+
readonly sourceKey: string;
|
|
295
|
+
constructor(sourceKey: string, cycle: Array<string>, schemaPath: string);
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/plugins/known-types/types.d.ts
|
|
299
|
+
interface KnownTypeRule {
|
|
300
|
+
name: string;
|
|
301
|
+
typeName: string;
|
|
302
|
+
importPath: string | null;
|
|
303
|
+
matcher: (schema: IRSchema, components: Record<string, IRSchema>) => boolean;
|
|
304
|
+
}
|
|
305
|
+
/** Declarative rule loaded from user known-types.ts (no functions). */
|
|
306
|
+
interface DeclarativeKnownTypeRule {
|
|
307
|
+
name: string;
|
|
308
|
+
typeName: string;
|
|
309
|
+
importPath?: string | null;
|
|
310
|
+
exactProperties?: Array<string>;
|
|
311
|
+
requireProperties?: Array<string>;
|
|
312
|
+
excludeProperties?: Array<string>;
|
|
313
|
+
maxPropertyCount?: number;
|
|
314
|
+
}
|
|
315
|
+
interface KnownTypeMatch {
|
|
316
|
+
rule: KnownTypeRule;
|
|
317
|
+
typeName: string;
|
|
318
|
+
importPath: string | null;
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/plugins/known-types/index.d.ts
|
|
322
|
+
declare function loadKnownTypeRules(cwd: string, apiRoot: string): Array<KnownTypeRule>;
|
|
323
|
+
declare function matchKnownType(schema: IRSchema, components: Record<string, IRSchema>, rules: Array<KnownTypeRule>): KnownTypeMatch | undefined;
|
|
324
|
+
//#endregion
|
|
325
|
+
export { type DeclarativeKnownTypeRule, type EnvelopeAnalysis, type EnvelopeMode, type EnvelopeShape, type GenerateOptions, type GenerateResult, type GenerationMode, type HTTPFetch, type HTTPFetchConfig, type HttpClient, type HttpMethod, type IR, type IROperation, type IRPath, type IRPathParam, type IRQueryParam, type IRRequestBody, type IRResponse, type IRSchema, type IRSchemaProperty, type IRSource, type InitOptions, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type KnownTypeRule, type NamingStrategy, type OpenApiCodegenConfig, type ProjectLayout, type QueryExtendsConfig, type QueryParams, RecursiveRefError, type SourceConfig, type SpecSource, type TypeforgeConfig, analyzeEnvelope, buildBaseResponseInterface, buildGenerateContext, defineSourceConfig, diffEnvelopeFields, generateForSource, initProject, loadKnownTypeRules, loadSpec, matchKnownType, parseSchema, parseSpec, parseUserBaseResponse, resolveSpecSource };
|
|
326
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/json/types.ts","../src/parser/types.ts","../src/parser/index.ts","../src/parser/loader.ts","../src/http/validate.ts","../src/http/types.ts","../src/config/types.ts","../src/config/define.ts","../src/generate/index.ts","../src/init/index.ts","../src/envelope-guard/index.ts","../src/emitters/recursive-ref-error.ts","../src/plugins/known-types/types.ts","../src/plugins/known-types/index.ts"],"mappings":";KAAY;UAEK;GACd,cAAc;;KAGL,YAAY,MAAM;KAElB,YAAY,gBAAgB,aAAa;KAEzC;KAEA,cAAc,eAAe;;;UCVxB;EACf,SAAS,MAAM;;UAGA;EACf;EACA,OAAO,MAAM;EACb;IAAc,SAAS,eAAe;;;UAGvB;EACf;EACA;EACA,YAAY,MAAM;;UAGH;EACf,QAAQ;EACR;EACA,YAAY,MAAM;EAClB,aAAa,MAAM;EACnB,cAAc;EACd,WAAW,MAAM;;KAGP;UAEK;EACf;EACA,QAAQ;;UAGO;EACf;EACA;EACA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;EAEf;;;;;;;;;EASA;;;;;;EAMA;;;;;;;;iBC1Dc,mBAAmB,QAAQ,eAAe;;;UC4BzC;EACf;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA,SAAS;EACT;;UAGe;EACf;EACA;EACA;EACA,cAAc;EACd;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGc,qBACd,aACA,oBACC;iBAsGmB,kBACpB,SAAS,kBACR,QAAQ;;;KCrKC;KACA;UAEK;EACf;EACA;EACA,QAAQ;EACR,SAAS;;iBAyIK,YAAY,SAAS;EACnC,SAAS;EACT,SAAS;;;;KCrJC;UAEK;EACf;EACA;EACA;;UAGe;EACf,QAAQ,MAAM;EACd,QAAQ;;UAGO;EACf;EACA;EACA,OAAO;;UAGQ;EACf,MAAM;EACN,SAAS;EACT,YAAY,MAAM;EAClB,QAAQ,YAAY,MAAM;;UAGX;EACf;EACA;EACA,OAAO;EACP,OAAO;;UAGQ;EACf,QAAQ,MAAM;EACd;;iBA2Hc,gBAAgB,QAAQ,WAAW;iBAiFnC,sBACd,kBACC;iBAqCa,mBACd,MAAM,eACN,MAAM,wBACL,MAAM;iBAiEO,2BACd,OAAO,eACP;;;cC9VW,0BAA0B;WAC5B,OAAO;WACP;WACA;EAET,YAAY,mBAAmB,OAAO,eAAe;;;;UCLtC;EACf;EACA;EACA;EACA,UAAU,QAAQ,UAAU,YAAY,eAAe;;;UAIxC;EACf;EACA;EACA;EACA,kBAAkB;EAClB,oBAAoB;EACpB,oBAAoB;EACpB;;UAGe;EACf,MAAM;EACN;EACA;;;;iBCXc,mBACd,aACA,kBACC,MAAM;iBAIO,eACd,QAAQ,UACR,YAAY,eAAe,WAC3B,OAAO,MAAM,iBACZ"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { a as resolveSpecSource, c as RecursiveRefError, d as analyzeEnvelope, f as buildBaseResponseInterface, i as loadSpec, l as parseSchema, m as parseUserBaseResponse, n as buildGenerateContext, o as loadKnownTypeRules, p as diffEnvelopeFields, r as generateForSource, s as matchKnownType, t as initProject, u as parseSpec } from "./init-BBNO0SYd.js";
|
|
2
|
+
//#region src/config/define.ts
|
|
3
|
+
/**
|
|
4
|
+
* Identity helper for `source.ts`. Use it so the object is checked against
|
|
5
|
+
* `SourceConfig` and editors can autocomplete fields.
|
|
6
|
+
*/
|
|
7
|
+
function defineSourceConfig(config) {
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { RecursiveRefError, analyzeEnvelope, buildBaseResponseInterface, buildGenerateContext, defineSourceConfig, diffEnvelopeFields, generateForSource, initProject, loadKnownTypeRules, loadSpec, matchKnownType, parseSchema, parseSpec, parseUserBaseResponse, resolveSpecSource };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/config/define.ts"],"sourcesContent":["import type { SourceConfig } from \"./types\";\n\n/**\n * Identity helper for `source.ts`. Use it so the object is checked against\n * `SourceConfig` and editors can autocomplete fields.\n */\nexport function defineSourceConfig(config: SourceConfig): SourceConfig {\n return config;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,mBAAmB,QAAoC;CACrE,OAAO;AACT"}
|