hono-takibi 0.16.0 → 0.17.0
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 +1 -1
- package/dist/cli.js +58 -39
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +3 -0
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +2 -1
- package/dist/core/rpc/index.js +23 -11
- package/dist/core/type/index.js +4 -2
- package/dist/{core-BTIn-SV7.js → core-B31BC8gp.js} +2711 -2013
- package/dist/{docs-BUk6OQGb.js → docs-BxfKU8TG.js} +41 -6
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{hooks-BI33t89i.js → hooks-sH69j0o0.js} +44 -25
- package/dist/index-5uq71Dt_.d.ts +860 -0
- package/dist/index-DKui1bHG.d.ts +11 -0
- package/dist/index.d.ts +2 -949
- package/dist/index.js +162 -89
- package/dist/{openapi-BCxQyBJl.js → openapi-CahO4sie.js} +1042 -301
- package/dist/{rpc-UzOYe2mc.js → rpc-BvVFjspk.js} +60 -2
- package/dist/{shared-C6tCzlhg.js → shared-CU8tD0KG.js} +121 -36
- package/dist/{utils-DNYSWwCh.js → utils-BvdDxide.js} +6 -2
- package/dist/vite-plugin/index.js +4 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ npx hono-takibi
|
|
|
48
48
|
- [Configuration](https://hono-takibi.dev/docs/guides/config)
|
|
49
49
|
- [Template](https://hono-takibi.dev/docs/guides/template)
|
|
50
50
|
- [Client](https://hono-takibi.dev/docs/guides/client)
|
|
51
|
-
- [
|
|
51
|
+
- [Mock](https://hono-takibi.dev/docs/guides/mock)
|
|
52
52
|
- [API Docs](https://hono-takibi.dev/docs/guides/api-docs)
|
|
53
53
|
- [Vendor Extensions](https://hono-takibi.dev/docs/guides/vendor)
|
|
54
54
|
- [Vite Plugin](https://hono-takibi.dev/docs/guides/vite-plugin)
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Console, Effect, FileSystem, Option, Ref, Result, Schema, Stream } from "effect";
|
|
5
|
-
import path from "node:path";
|
|
2
|
+
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
3
|
+
import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
|
|
6
4
|
import { Argument, CliError, Command, Flag } from "effect/unstable/cli";
|
|
7
5
|
//#region package.json
|
|
8
|
-
var version = "0.
|
|
6
|
+
var version = "0.17.0";
|
|
9
7
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
8
|
//#endregion
|
|
11
9
|
//#region src/cli/index.ts
|
|
@@ -51,11 +49,11 @@ function runJobs(config) {
|
|
|
51
49
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob }] = yield* Effect.promise(() => Promise.all([
|
|
52
50
|
import("./openapi-DQRxq2_O.js").then((n) => n.t),
|
|
53
51
|
import("./format-CuHABcKC.js").then((n) => n.r),
|
|
54
|
-
import("./shared-
|
|
52
|
+
import("./shared-CU8tD0KG.js").then((n) => n.i)
|
|
55
53
|
]));
|
|
56
54
|
const jobs = makeJob(yield* parseOpenAPI(config.input), config);
|
|
57
55
|
yield* cleanSplitOutputs(jobs.filter((job) => job.split).map((job) => job.output));
|
|
58
|
-
return (yield* Effect.
|
|
56
|
+
return (yield* Effect.forEach(jobs, (job) => job.run(job.output), { concurrency: "unbounded" }).pipe(Effect.provideService(FormatOptions, config.format ?? {}))).filter((message) => message !== "").join("\n");
|
|
59
57
|
});
|
|
60
58
|
}
|
|
61
59
|
function runConfigPass(configPath, reload) {
|
|
@@ -71,48 +69,57 @@ function isSameTarget(left, right) {
|
|
|
71
69
|
return left?.inputDirectory === right?.inputDirectory && left?.outside.join("\n") === right?.outside.join("\n");
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
|
-
*
|
|
72
|
+
* Generates from a config that was read, and answers what to watch for its documents.
|
|
75
73
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* what it answers never reaches a generator.
|
|
80
|
-
*
|
|
81
|
-
* The directory comes from the config alone, so a pass that fails after the config was
|
|
82
|
-
* read — a document that does not parse, say — still names it. Otherwise the very edit
|
|
83
|
-
* that fixes the document would never be seen. The answer is `undefined` only when the
|
|
84
|
-
* config itself could not be read.
|
|
74
|
+
* The directory comes from the config alone, so a pass that fails here — a document
|
|
75
|
+
* that does not parse, say — still names it. Otherwise the very edit that fixes the
|
|
76
|
+
* document would never be seen.
|
|
85
77
|
*
|
|
86
78
|
* The files outside the directory come from the document, and a broken document cannot
|
|
87
79
|
* list them. `previous` is what stands in then: the fix may well belong in one of the
|
|
88
80
|
* files the last readable version pointed at.
|
|
89
81
|
*/
|
|
90
|
-
function
|
|
82
|
+
function reportJobs(config, previous) {
|
|
91
83
|
return Effect.gen(function* () {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
else yield* Console.error(`❌ ${report.failure.message}`);
|
|
100
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-C6tCzlhg.js").then((n) => n.o));
|
|
101
|
-
const inputDirectory = path.dirname(path.resolve(process.cwd(), config.success.input));
|
|
84
|
+
const path = yield* Path.Path;
|
|
85
|
+
yield* runJobs(config).pipe(Effect.matchEffect({
|
|
86
|
+
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
87
|
+
onSuccess: (report) => Console.log(report)
|
|
88
|
+
}));
|
|
89
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-CU8tD0KG.js").then((n) => n.i));
|
|
90
|
+
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
102
91
|
return {
|
|
103
92
|
inputDirectory,
|
|
104
|
-
outside: yield* outsideSources(config.
|
|
93
|
+
outside: yield* outsideSources(config.input).pipe(Effect.orElseSucceed(() => previous?.inputDirectory === inputDirectory ? previous.outside : []))
|
|
105
94
|
};
|
|
106
95
|
});
|
|
107
96
|
}
|
|
108
97
|
/**
|
|
98
|
+
* Runs one pass and answers what to watch for the documents.
|
|
99
|
+
*
|
|
100
|
+
* Two separate things happen to the document here. `runJobs` generates from it, reading
|
|
101
|
+
* it the way every other mode does. `outsideSources` then only asks which files it was
|
|
102
|
+
* read from, so that an edit to any of them brings the session back to this function;
|
|
103
|
+
* what it answers never reaches a generator.
|
|
104
|
+
*
|
|
105
|
+
* The answer is `undefined` only when the config itself could not be read.
|
|
106
|
+
*/
|
|
107
|
+
function reportConfigPass(configPath, reload, previous) {
|
|
108
|
+
return loadConfig(configPath, reload).pipe(Effect.matchEffect({
|
|
109
|
+
onFailure: (error) => Console.error(`❌ ${error.message}`).pipe(Effect.as(void 0)),
|
|
110
|
+
onSuccess: (config) => reportJobs(config, previous)
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
109
114
|
* `directory`, or the closest directory above it that exists.
|
|
110
115
|
*
|
|
111
116
|
* A directory that is not there cannot be watched, but the one it will appear in can.
|
|
112
117
|
*/
|
|
113
118
|
function nearestExisting(directory) {
|
|
114
119
|
return Effect.gen(function* () {
|
|
115
|
-
const
|
|
120
|
+
const fs = yield* FileSystem.FileSystem;
|
|
121
|
+
const path = yield* Path.Path;
|
|
122
|
+
const exists = yield* fs.exists(directory).pipe(Effect.orElseSucceed(() => false));
|
|
116
123
|
const parent = path.dirname(directory);
|
|
117
124
|
return exists || parent === directory ? directory : yield* nearestExisting(parent);
|
|
118
125
|
});
|
|
@@ -138,8 +145,9 @@ function watchPass(configPath, target, watched, nextTarget) {
|
|
|
138
145
|
function outsideEvents(outside) {
|
|
139
146
|
return Effect.gen(function* () {
|
|
140
147
|
const fs = yield* FileSystem.FileSystem;
|
|
148
|
+
const path = yield* Path.Path;
|
|
141
149
|
const directories = [...new Set(outside.map((file) => path.dirname(file)))];
|
|
142
|
-
const present = yield* Effect.
|
|
150
|
+
const present = yield* Effect.forEach(directories, (directory) => fs.exists(directory).pipe(Effect.orElseSucceed(() => false)), { concurrency: "unbounded" });
|
|
143
151
|
return directories.filter((_, index) => present[index]).map((directory) => fs.watch(directory).pipe(Stream.filter((event) => outside.includes(path.join(directory, event.path)))));
|
|
144
152
|
});
|
|
145
153
|
}
|
|
@@ -155,6 +163,7 @@ function outsideEvents(outside) {
|
|
|
155
163
|
function watchRound(configPath, target, watched) {
|
|
156
164
|
return Effect.gen(function* () {
|
|
157
165
|
const fs = yield* FileSystem.FileSystem;
|
|
166
|
+
const path = yield* Path.Path;
|
|
158
167
|
const configFile = path.basename(configPath);
|
|
159
168
|
const nextTarget = yield* Ref.make(target);
|
|
160
169
|
const configEvents = fs.watch(path.dirname(configPath)).pipe(Stream.filter((event) => event.path === configFile));
|
|
@@ -167,12 +176,22 @@ function watchRound(configPath, target, watched) {
|
|
|
167
176
|
return yield* Ref.get(nextTarget);
|
|
168
177
|
});
|
|
169
178
|
}
|
|
170
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Announces what a round watches, runs it, and leaves the next target in `current`.
|
|
181
|
+
*/
|
|
182
|
+
function watchCycle(configPath, current) {
|
|
171
183
|
return Effect.gen(function* () {
|
|
184
|
+
const target = yield* Ref.get(current);
|
|
172
185
|
const watched = target === void 0 ? void 0 : yield* nearestExisting(target.inputDirectory);
|
|
173
186
|
const documents = [target?.inputDirectory, ...target?.outside ?? []].filter((entry) => entry !== void 0).join(", ");
|
|
174
187
|
yield* Console.log(target === void 0 ? `\n👀 Watching ${configPath} — Ctrl-C to stop` : watched === target.inputDirectory ? `\n👀 Watching ${documents} and ${configPath} — Ctrl-C to stop` : `\n👀 Watching ${configPath}, waiting for ${target.inputDirectory} — Ctrl-C to stop`);
|
|
175
|
-
|
|
188
|
+
yield* Ref.set(current, yield* watchRound(configPath, target, watched));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function watchConfig(configPath, target) {
|
|
192
|
+
return Effect.gen(function* () {
|
|
193
|
+
const current = yield* Ref.make(target);
|
|
194
|
+
return yield* Effect.forever(watchCycle(configPath, current));
|
|
176
195
|
});
|
|
177
196
|
}
|
|
178
197
|
function generate(args) {
|
|
@@ -194,18 +213,18 @@ function generate(args) {
|
|
|
194
213
|
})]
|
|
195
214
|
});
|
|
196
215
|
if (input !== void 0 && output !== void 0) {
|
|
197
|
-
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DQRxq2_O.js").then((n) => n.t), import("./core-
|
|
216
|
+
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DQRxq2_O.js").then((n) => n.t), import("./core-B31BC8gp.js").then((n) => n.t)]));
|
|
198
217
|
return yield* Console.log(yield* takibi(yield* parseOpenAPI(input), output));
|
|
199
218
|
}
|
|
200
219
|
const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
|
|
201
220
|
if (args.watch) return yield* watchConfig(resolvedConfig, yield* reportConfigPass(resolvedConfig, false, void 0));
|
|
202
|
-
const first = yield* runConfigPass(resolvedConfig, false).pipe(Effect.
|
|
221
|
+
const first = yield* runConfigPass(resolvedConfig, false).pipe(Effect.catchTag("ConfigError", (error) => Effect.fail(configPath === void 0 && error.notFound === true ? new CliError.ShowHelp({
|
|
203
222
|
commandPath: [COMMAND_NAME],
|
|
204
223
|
errors: [new CliError.UserError({
|
|
205
224
|
cause: error,
|
|
206
225
|
userMessage: error.message
|
|
207
226
|
})]
|
|
208
|
-
}) : error));
|
|
227
|
+
}) : error)));
|
|
209
228
|
yield* Console.log(first.report);
|
|
210
229
|
}).pipe(Effect.mapError((error) => CliError.isCliError(error) ? error : new CliError.UserError({
|
|
211
230
|
cause: error,
|
|
@@ -232,11 +251,11 @@ function makeCli() {
|
|
|
232
251
|
}
|
|
233
252
|
]));
|
|
234
253
|
}
|
|
235
|
-
function honoTakibi(
|
|
236
|
-
return Command.
|
|
254
|
+
function honoTakibi() {
|
|
255
|
+
return Command.run(makeCli(), { version });
|
|
237
256
|
}
|
|
238
257
|
//#endregion
|
|
239
258
|
//#region src/index.ts
|
|
240
|
-
NodeRuntime.runMain(honoTakibi(
|
|
259
|
+
NodeRuntime.runMain(honoTakibi().pipe(Effect.provide(NodeServices.layer)));
|
|
241
260
|
//#endregion
|
|
242
261
|
export {};
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as docs } from "../../docs-
|
|
1
|
+
import { t as docs } from "../../docs-BxfKU8TG.js";
|
|
2
2
|
export { docs };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-tsPqeV6H.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
+
import { t as Grouping } from "../../index-DKui1bHG.js";
|
|
3
4
|
//#region src/core/hooks/index.d.ts
|
|
4
5
|
declare const HOOK_CONFIGS: {
|
|
5
6
|
readonly swr: {
|
|
@@ -163,5 +164,7 @@ declare const HOOK_CONFIGS: {
|
|
|
163
164
|
export type HookLibrary = keyof typeof HOOK_CONFIGS;
|
|
164
165
|
export declare function hooks(openAPI: OpenAPI, output: string, importPath: string, library: HookLibrary, options?: {
|
|
165
166
|
readonly clientName?: string;
|
|
167
|
+
readonly grouping?: Grouping;
|
|
168
|
+
readonly basePath?: string;
|
|
166
169
|
}): import("effect/Effect").Effect<string, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
167
170
|
//#endregion
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as hooks } from "../../hooks-
|
|
1
|
+
import { t as hooks } from "../../hooks-sH69j0o0.js";
|
|
2
2
|
export { hooks };
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-tsPqeV6H.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
+
import { t as Grouping } from "../../index-DKui1bHG.js";
|
|
3
4
|
import { Effect } from "effect";
|
|
4
5
|
//#region src/core/rpc/index.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Generates RPC client wrapper functions from OpenAPI specification.
|
|
7
8
|
*/
|
|
8
|
-
export declare function rpc(openAPI: OpenAPI, output: string, importPath: string, clientName?: string, useParseResponse?: boolean, basePath?: string, docs?: boolean): Effect.Effect<string, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
9
|
+
export declare function rpc(openAPI: OpenAPI, output: string, importPath: string, clientName?: string, useParseResponse?: boolean, basePath?: string, docs?: boolean, grouping?: Grouping): Effect.Effect<string, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
9
10
|
//#endregion
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as GenerateError } from "../../format-CuHABcKC.js";
|
|
2
|
-
import { A as isOperationLike, O as isOpenAPIPaths, R as isRecord, f as methodPath, l as makeInferRequestType } from "../../utils-
|
|
2
|
+
import { A as isOperationLike, O as isOpenAPIPaths, R as isRecord, f as methodPath, l as makeInferRequestType } from "../../utils-BvdDxide.js";
|
|
3
3
|
import { t as emit } from "../../emit-CSV6od97.js";
|
|
4
|
-
import { a as parsePathItem, i as operationHasArgs, r as makeOperationDeps, t as formatPath } from "../../rpc-
|
|
4
|
+
import { a as parsePathItem, i as operationHasArgs, o as groupClientName, r as makeOperationDeps, t as formatPath } from "../../rpc-BvVFjspk.js";
|
|
5
5
|
import { Effect } from "effect";
|
|
6
6
|
import { dirname } from "node:path";
|
|
7
7
|
//#region src/core/rpc/index.ts
|
|
@@ -20,9 +20,14 @@ function makeJsDoc(operation, method, path) {
|
|
|
20
20
|
sections.push([`${method.toUpperCase()} ${path}`]);
|
|
21
21
|
return `/**\n${sections.map((lines) => lines.join("\n")).join("\n\n").split("\n").map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
|
|
22
22
|
}
|
|
23
|
-
function makeOperationCode(path, method, item,
|
|
23
|
+
function makeOperationCode(path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
24
24
|
const operation = item[method];
|
|
25
25
|
if (!isOperationLike(operation)) return null;
|
|
26
|
+
const group = grouping?.(path, operationTags(operation));
|
|
27
|
+
const deps = group === void 0 ? base : {
|
|
28
|
+
...base,
|
|
29
|
+
client: groupClientName(group)
|
|
30
|
+
};
|
|
26
31
|
const funcName = methodPath(method, path);
|
|
27
32
|
const pathResult = formatPath(path, hasBasePath);
|
|
28
33
|
const hasArgs = operationHasArgs(item, operation, deps);
|
|
@@ -32,10 +37,15 @@ function makeOperationCode(path, method, item, deps, useParseResponse, hasBasePa
|
|
|
32
37
|
const call = useParseResponse ? `parseResponse(${clientCall})` : clientCall;
|
|
33
38
|
return {
|
|
34
39
|
code: `${docs ? makeJsDoc(operation, method, path) : ""}export async function ${funcName}(${argSig}){return await ${call}}`,
|
|
35
|
-
hasArgs
|
|
40
|
+
hasArgs,
|
|
41
|
+
client: deps.client
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
|
-
function
|
|
44
|
+
function operationTags(operation) {
|
|
45
|
+
const tags = "tags" in operation ? operation.tags : void 0;
|
|
46
|
+
return Array.isArray(tags) ? tags.filter((tag) => typeof tag === "string") : void 0;
|
|
47
|
+
}
|
|
48
|
+
function makeOperationCodes(paths, deps, useParseResponse, hasBasePath, docs, grouping) {
|
|
39
49
|
return Object.entries(paths).filter((entry) => isRecord(entry[1])).flatMap(([p, rawItem]) => {
|
|
40
50
|
const pathItem = parsePathItem(rawItem);
|
|
41
51
|
return [
|
|
@@ -48,25 +58,27 @@ function makeOperationCodes(paths, deps, useParseResponse, hasBasePath, docs) {
|
|
|
48
58
|
"patch",
|
|
49
59
|
"trace",
|
|
50
60
|
"query"
|
|
51
|
-
].map((method) => makeOperationCode(p, method, pathItem, deps, useParseResponse, hasBasePath, docs)).filter((item) => item !== null);
|
|
61
|
+
].map((method) => makeOperationCode(p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
52
62
|
});
|
|
53
63
|
}
|
|
54
|
-
function makeHeader(importPath, needsInferRequestType,
|
|
55
|
-
return `import type{${needsInferRequestType ? "InferRequestType,ClientRequestOptions" : "ClientRequestOptions"}}from'hono/client'\n${useParseResponse ? `import{parseResponse}from'hono/client'\n` : ""}import{${
|
|
64
|
+
function makeHeader(importPath, needsInferRequestType, clientNames, useParseResponse) {
|
|
65
|
+
return `import type{${needsInferRequestType ? "InferRequestType,ClientRequestOptions" : "ClientRequestOptions"}}from'hono/client'\n${useParseResponse ? `import{parseResponse}from'hono/client'\n` : ""}import{${clientNames.join(",")}}from'${importPath}'\n\n`;
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
68
|
* Generates RPC client wrapper functions from OpenAPI specification.
|
|
59
69
|
*/
|
|
60
|
-
function rpc(openAPI, output, importPath, clientName = "client", useParseResponse, basePath, docs) {
|
|
70
|
+
function rpc(openAPI, output, importPath, clientName = "client", useParseResponse, basePath, docs, grouping) {
|
|
61
71
|
return Effect.gen(function* () {
|
|
62
72
|
const paths = openAPI.paths;
|
|
63
73
|
if (!isOpenAPIPaths(paths)) return yield* new GenerateError({ message: "Invalid OpenAPI paths" });
|
|
64
74
|
const hasBasePath = basePath !== void 0 && basePath !== "/";
|
|
65
75
|
const componentsParameters = openAPI.components?.parameters ?? {};
|
|
66
76
|
const componentsRequestBodies = openAPI.components?.requestBodies ?? {};
|
|
67
|
-
const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), useParseResponse, hasBasePath, docs);
|
|
77
|
+
const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), useParseResponse, hasBasePath, docs, grouping);
|
|
68
78
|
const body = operationCodes.map(({ code }) => code).join("\n\n");
|
|
69
|
-
const
|
|
79
|
+
const needsInferRequestType = operationCodes.some(({ hasArgs }) => hasArgs);
|
|
80
|
+
const clientNames = [...new Set(operationCodes.map(({ client }) => client))];
|
|
81
|
+
const code = `${makeHeader(importPath, needsInferRequestType, clientNames.length > 0 ? clientNames : [clientName], useParseResponse)}${body}${operationCodes.length > 0 ? "\n" : ""}`;
|
|
70
82
|
yield* emit(code, dirname(output), output);
|
|
71
83
|
return `Generated rpc code written to ${output}`;
|
|
72
84
|
});
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as isMediaWithSchema, M as isParameterArray, O as isOpenAPIPaths, T as isHttpMethod, U as isSchemaArray, V as isRequestBody, Y as isStringRef, g as statusCodeToNumber, j as isParameter, k as isOperation, u as makeSafeKey } from "../../utils-
|
|
1
|
+
import { D as isMediaWithSchema, M as isParameterArray, O as isOpenAPIPaths, T as isHttpMethod, U as isSchemaArray, V as isRequestBody, Y as isStringRef, g as statusCodeToNumber, j as isParameter, k as isOperation, u as makeSafeKey } from "../../utils-BvdDxide.js";
|
|
2
2
|
import { t as emit } from "../../emit-CSV6od97.js";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
import path from "node:path";
|
|
@@ -161,9 +161,11 @@ function makeSchemaTypeString(schema, components, visited) {
|
|
|
161
161
|
if (schema.oneOf && schema.oneOf.length > 0) return schema.oneOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
|
|
162
162
|
if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
|
|
163
163
|
if (schema.allOf && schema.allOf.length > 0) return makeAllOfTypeString(schema.allOf, components, visited);
|
|
164
|
-
|
|
164
|
+
const isBigintLiteral = (value) => typeof value === "number" && Number.isInteger(value) && (Array.isArray(schema.type) ? schema.type.includes("integer") : schema.type === "integer") && (schema.format === "int64" || schema.format === "uint64" || schema.format === "bigint");
|
|
165
|
+
if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : isBigintLiteral(v) ? `${v}n` : String(v)).join("|");
|
|
165
166
|
if (schema.const !== void 0) {
|
|
166
167
|
if (typeof schema.const === "string") return `'${schema.const.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
168
|
+
if (isBigintLiteral(schema.const)) return `${schema.const}n`;
|
|
167
169
|
if (typeof schema.const === "number" || typeof schema.const === "boolean") return String(schema.const);
|
|
168
170
|
return JSON.stringify(schema.const);
|
|
169
171
|
}
|