hono-takibi 0.25.0 → 0.27.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 +3 -1
- package/dist/cli.js +19 -17
- package/dist/core/docs/index.d.ts +2 -4
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +3 -5
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +4 -6
- package/dist/core/rpc/index.js +9 -10
- package/dist/core/type/index.d.ts +3 -5
- package/dist/core/type/index.js +4 -5
- package/dist/{core-rnNgBu4D.js → core-DWz4JxmP.js} +73 -89
- package/dist/{docs-BApYjFQG.js → docs-CDFG1tXT.js} +20 -16
- package/dist/{emit-uwlZZeRM.js → emit-CqkT9T4Q.js} +3 -4
- package/dist/{file-K6j5IJXi.js → file-Bip_L0oR.js} +1 -2
- package/dist/{format-CuHABcKC.js → format-BF7SbaMP.js} +3 -5
- package/dist/generator/zod-openapi-hono/openapi/index.d.ts +2 -4
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/guard-BH6yBr0M.js +332 -0
- package/dist/{hooks-RrTkHWCS.js → hooks-CKIK30qr.js} +34 -35
- package/dist/{index-j7o04Qt1.d.ts → index-8HyUtaew.d.ts} +2 -4
- package/dist/{index-CtUxilW-.d.ts → index-DqcEtGVl.d.ts} +4 -8
- package/dist/{index-B3ze4n_I.d.ts → index-DvZscmYm.d.ts} +0 -2
- package/dist/{index-D_gf3Xzx.d.ts → index-sZ1C8djg.d.ts} +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/{openapi-CuyeukCF.js → openapi-DqpjdjTv.js} +342 -143
- package/dist/{openapi-t_u-tF52.js → openapi-tYYvoKiU.js} +2 -3
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/{rpc-BOAnGH-n.js → rpc-GDi7a_Ep.js} +3 -6
- package/dist/{shared-Tq3KgO4s.js → shared-Ba1iJE80.js} +25 -10
- package/dist/{utils-v71BPo5C.js → utils-CDLiYepO.js} +103 -249
- package/dist/vite-plugin/index.d.ts +1 -3
- package/dist/vite-plugin/index.js +12 -9
- package/package.json +5 -5
- package/dist/constants-CxrXPVxh.js +0 -82
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ From one document it can generate:
|
|
|
21
21
|
npm install -D hono-takibi
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Pass an OpenAPI (`.yaml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
|
|
24
|
+
Pass an OpenAPI (`.yaml`, `.yml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
npx hono-takibi openapi.yaml -o src/routes.ts
|
|
@@ -38,6 +38,8 @@ export default defineConfig({
|
|
|
38
38
|
})
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
`input` also takes an `http(s)` URL, with or without a file extension: a remote document is read by its content.
|
|
42
|
+
|
|
41
43
|
```bash
|
|
42
44
|
npx hono-takibi
|
|
43
45
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Z as INPUT_EXTENSIONS, m as isInputPath } from "./guard-BH6yBr0M.js";
|
|
3
3
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
4
4
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
5
5
|
import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
|
|
6
6
|
import { Argument, CliError, Command, Flag } from "effect/cli";
|
|
7
|
-
|
|
8
|
-
var version = "0.
|
|
7
|
+
// package.json
|
|
8
|
+
var version = "0.27.0";
|
|
9
9
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
|
-
|
|
11
|
-
//#region src/cli/index.ts
|
|
10
|
+
// src/cli/index.ts
|
|
12
11
|
const COMMAND_NAME = "hono-takibi";
|
|
13
12
|
const DEFAULT_CONFIG_FILE = "hono-takibi.config.ts";
|
|
14
|
-
const DocumentPathSchema = Schema.String.pipe(Schema.refine(
|
|
13
|
+
const DocumentPathSchema = Schema.String.pipe(Schema.refine(isInputPath, { message: "an OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document" })).annotate({
|
|
15
14
|
title: "Input document",
|
|
16
15
|
description: "OpenAPI or TypeSpec document the one-shot mode generates from.",
|
|
17
16
|
examples: [
|
|
@@ -39,12 +38,12 @@ function loadConfig(configPath, reload) {
|
|
|
39
38
|
}
|
|
40
39
|
function runJobs(config) {
|
|
41
40
|
return Effect.gen(function* () {
|
|
42
|
-
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
43
|
-
import("./openapi-
|
|
44
|
-
import("./format-
|
|
45
|
-
import("./shared-
|
|
41
|
+
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
42
|
+
import("./openapi-tYYvoKiU.js").then((n) => n.t),
|
|
43
|
+
import("./format-BF7SbaMP.js").then((n) => n.r),
|
|
44
|
+
import("./shared-Ba1iJE80.js").then((n) => n.o)
|
|
46
45
|
]));
|
|
47
|
-
const openAPI = yield* parseOpenAPI(config.input);
|
|
46
|
+
const openAPI = yield* openAPI3(yield* parseOpenAPI(config.input), config.input);
|
|
48
47
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
49
48
|
yield* cleanSplitOutputs(jobs.filter((job) => job.split).map((job) => job.output));
|
|
50
49
|
return (yield* Effect.forEach(jobs, (job) => job.run(job.output), { concurrency: "unbounded" }).pipe(Effect.provideService(FormatOptions, config.format ?? {}))).filter((message) => message !== "").join("\n");
|
|
@@ -80,7 +79,7 @@ function reportJobs(config, previous) {
|
|
|
80
79
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
81
80
|
onSuccess: (report) => Console.log(report)
|
|
82
81
|
}));
|
|
83
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
82
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-Ba1iJE80.js").then((n) => n.o));
|
|
84
83
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
85
84
|
return {
|
|
86
85
|
inputDirectory,
|
|
@@ -207,8 +206,13 @@ function generate(args) {
|
|
|
207
206
|
})]
|
|
208
207
|
});
|
|
209
208
|
if (input !== void 0 && output !== void 0) {
|
|
210
|
-
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([
|
|
211
|
-
|
|
209
|
+
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
210
|
+
import("./openapi-tYYvoKiU.js").then((n) => n.t),
|
|
211
|
+
import("./core-DWz4JxmP.js").then((n) => n.t),
|
|
212
|
+
import("./shared-Ba1iJE80.js").then((n) => n.o)
|
|
213
|
+
]));
|
|
214
|
+
const document = yield* openAPI3(yield* parseOpenAPI(input), input);
|
|
215
|
+
return yield* Console.log(yield* takibi(document, output));
|
|
212
216
|
}
|
|
213
217
|
const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
|
|
214
218
|
if (args.watch) return yield* watchConfig(resolvedConfig, yield* reportConfigPass(resolvedConfig, false, void 0));
|
|
@@ -248,8 +252,6 @@ function makeCli() {
|
|
|
248
252
|
function honoTakibi() {
|
|
249
253
|
return Command.run(makeCli(), { version });
|
|
250
254
|
}
|
|
251
|
-
|
|
252
|
-
//#region src/index.ts
|
|
255
|
+
// src/index.ts
|
|
253
256
|
NodeRuntime.runMain(honoTakibi().pipe(Effect.provide(NodeServices.layer)));
|
|
254
|
-
//#endregion
|
|
255
257
|
export {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
-
|
|
4
|
-
export declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Effect.Effect<string, import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
5
|
-
//#endregion
|
|
3
|
+
export declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Effect.Effect<string, import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as docs } from "../../docs-
|
|
1
|
+
export { t as docs } from "../../docs-CDFG1tXT.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
-
import { n as GenerateError, t as FormatError } from "../../index-
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
4
|
-
//#region src/core/hooks/index.d.ts
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
|
+
import { n as GenerateError, t as FormatError } from "../../index-sZ1C8djg.js";
|
|
3
|
+
import { t as Grouping } from "../../index-8HyUtaew.js";
|
|
5
4
|
declare const HOOK_CONFIGS: {
|
|
6
5
|
readonly swr: {
|
|
7
6
|
readonly packageName: 'swr';
|
|
@@ -167,5 +166,4 @@ export declare function hooks(openAPI: OpenAPI, output: string, importPath: stri
|
|
|
167
166
|
readonly grouping?: Grouping;
|
|
168
167
|
readonly basePath?: string;
|
|
169
168
|
}): import("effect/Effect").Effect<`Generated ${string} hooks written to ${string}`, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
170
|
-
//#endregion
|
|
171
169
|
export {};
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as hooks } from "../../hooks-
|
|
1
|
+
export { t as hooks } from "../../hooks-CKIK30qr.js";
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
-
import { n as GenerateError, t as FormatError } from "../../index-
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
|
+
import { n as GenerateError, t as FormatError } from "../../index-sZ1C8djg.js";
|
|
3
|
+
import { t as Grouping } from "../../index-8HyUtaew.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
|
-
//#region src/core/rpc/index.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Generates RPC client wrapper functions from OpenAPI specification.
|
|
8
7
|
*/
|
|
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>;
|
|
10
|
-
//#endregion
|
|
8
|
+
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>;
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as GenerateError } from "../../format-
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
5
|
-
import { t as emit } from "../../emit-
|
|
1
|
+
import { O as isRecord, Y as HTTP_METHODS, b as isOperationLike, v as isOpenAPIPaths } from "../../guard-BH6yBr0M.js";
|
|
2
|
+
import { i as GenerateError } from "../../format-BF7SbaMP.js";
|
|
3
|
+
import { _ as routeName, u as makeInferRequestType } from "../../utils-CDLiYepO.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-GDi7a_Ep.js";
|
|
5
|
+
import { t as emit } from "../../emit-CqkT9T4Q.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
|
-
|
|
8
|
+
// src/core/rpc/index.ts
|
|
9
9
|
/**
|
|
10
10
|
* Builds a JSDoc block from operation `summary` / `description` plus the HTTP route line.
|
|
11
11
|
* Returns an empty string when neither summary nor description is present (the route line
|
|
@@ -21,7 +21,7 @@ function makeJsDoc(operation, method, path) {
|
|
|
21
21
|
sections.push([`${method.toUpperCase()} ${path}`]);
|
|
22
22
|
return `/**\n${sections.map((lines) => lines.join("\n")).join("\n\n").split("\n").map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
|
|
23
23
|
}
|
|
24
|
-
function makeOperationCode(path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
24
|
+
function makeOperationCode(paths, path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
25
25
|
const operation = item[method];
|
|
26
26
|
if (!isOperationLike(operation)) return null;
|
|
27
27
|
const group = grouping?.(path, operationTags(operation));
|
|
@@ -29,7 +29,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
29
29
|
...base,
|
|
30
30
|
client: makeGroupClientName(group)
|
|
31
31
|
};
|
|
32
|
-
const funcName =
|
|
32
|
+
const funcName = routeName(method, path, paths);
|
|
33
33
|
const pathResult = formatPath(path, hasBasePath);
|
|
34
34
|
const hasArgs = operationHasArgs(item, operation, deps);
|
|
35
35
|
const inferType = makeInferRequestType(deps.client, pathResult, method);
|
|
@@ -45,7 +45,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
45
45
|
function makeOperationCodes(paths, deps, useParseResponse, hasBasePath, docs, grouping) {
|
|
46
46
|
return Object.entries(paths).filter((entry) => isRecord(entry[1])).flatMap(([p, rawItem]) => {
|
|
47
47
|
const pathItem = parsePathItem(rawItem);
|
|
48
|
-
return HTTP_METHODS.map((method) => makeOperationCode(p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
48
|
+
return HTTP_METHODS.map((method) => makeOperationCode(paths, p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
function makeHeader(importPath, needsInferRequestType, clientNames, useParseResponse) {
|
|
@@ -70,5 +70,4 @@ function rpc(openAPI, output, importPath, clientName = "client", useParseRespons
|
|
|
70
70
|
return `Generated rpc code written to ${output}`;
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
//#endregion
|
|
74
73
|
export { rpc };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
-
import { t as FormatError } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
|
+
import { t as FormatError } from "../../index-sZ1C8djg.js";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
|
-
//#region src/core/type/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Generates TypeScript type declarations from OpenAPI specification.
|
|
7
6
|
*/
|
|
8
|
-
export declare function type(openAPI: OpenAPI, output: `${string}.ts`, readonly?: boolean): Effect.Effect<string, FormatError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
9
|
-
//#endregion
|
|
7
|
+
export declare function type(openAPI: OpenAPI, output: `${string}.ts`, readonly?: boolean): Effect.Effect<string, FormatError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import {
|
|
3
|
-
import { t as emit } from "../../emit-
|
|
1
|
+
import { N as isSchemaArray, S as isParameterArray, d as isHttpMethod, g as isMediaWithSchema, j as isRequestBody, v as isOpenAPIPaths, x as isParameter, y as isOperation, z as isStringRef } from "../../guard-BH6yBr0M.js";
|
|
2
|
+
import { d as makeSafeKey, v as statusCodeToNumber, y as toIdentifierPascalCase } from "../../utils-CDLiYepO.js";
|
|
3
|
+
import { t as emit } from "../../emit-CqkT9T4Q.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
|
|
6
|
+
// src/core/type/index.ts
|
|
7
7
|
/**
|
|
8
8
|
* DeepReadonly utility type that recursively makes all properties readonly.
|
|
9
9
|
*/
|
|
@@ -300,5 +300,4 @@ function makeObjectTypeString(schema, aliases, visited) {
|
|
|
300
300
|
return requiredSet.has(key) ? `${safeKey}:${propType}` : `${safeKey}?:${propType}|undefined`;
|
|
301
301
|
}).join(";")}}`;
|
|
302
302
|
}
|
|
303
|
-
//#endregion
|
|
304
303
|
export { type };
|