hono-takibi 0.9.99993 → 0.9.99995
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 +8 -5
- package/dist/config/index.d.ts +32 -8
- package/dist/config/index.js +38 -4
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.js +3 -2
- package/dist/core/type/index.js +2 -1
- package/dist/{docs-380Wcu6a.js → docs-DbknIWmx.js} +2 -1
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/guard-BSZ8ezEv.js +83 -0
- package/dist/{hooks-CkiatAe9.js → hooks-CCw7jm8g.js} +5 -4
- package/dist/index.js +1 -1
- package/dist/{openapi-8ZYAMj_e.js → openapi-BlTDQFFF.js} +35 -111
- package/dist/{rpc-CepeggWU.js → rpc-BzPo2tZf.js} +1 -1
- package/dist/{shared-DC4zuL9A.js → shared-B-TUm7Fa.js} +96 -153
- package/dist/{guard-zvkMUVYD.js → utils-B5PbMfWs.js} +72 -82
- package/dist/vite-plugin/index.js +117 -22
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -200,7 +200,6 @@ export default app
|
|
|
200
200
|
```ts
|
|
201
201
|
export default defineConfig({
|
|
202
202
|
input: 'openapi.yaml',
|
|
203
|
-
output: './src/index.ts',
|
|
204
203
|
template: { define: true },
|
|
205
204
|
})
|
|
206
205
|
```
|
|
@@ -221,7 +220,7 @@ export const getUsersIdRoute = defineOpenAPIRoute({
|
|
|
221
220
|
})
|
|
222
221
|
```
|
|
223
222
|
|
|
224
|
-
|
|
223
|
+
The app entry defaults to `src/index.ts` (override with `output`, which must be an `index.ts` path such as `./server/index.ts`). Route files always go to `routes/` next to the app entry, and component schemas to `components/index.ts` (override with `components.output`). When `output` is omitted, `components.output` also anchors the layout: `components: { output: './server/components/index.ts' }` puts the app entry at `server/index.ts` and routes at `server/routes/`.
|
|
225
224
|
|
|
226
225
|
## Client Library Integrations
|
|
227
226
|
|
|
@@ -305,7 +304,7 @@ export default defineConfig({
|
|
|
305
304
|
|
|
306
305
|
## Full Config Reference
|
|
307
306
|
|
|
308
|
-
Some options are mutually exclusive: `output` ↔ `routes`, `components.output` ↔ per-type components, `template.define` ↔ `routeHandler`.
|
|
307
|
+
Some options are mutually exclusive: `output` ↔ `routes`, `template.define` ↔ `routes`, `components.output` ↔ per-type components, `template.define` ↔ `routeHandler`.
|
|
309
308
|
|
|
310
309
|
```ts
|
|
311
310
|
import { defineConfig } from 'hono-takibi/config'
|
|
@@ -313,7 +312,7 @@ import { defineConfig } from 'hono-takibi/config'
|
|
|
313
312
|
export default defineConfig({
|
|
314
313
|
input: 'openapi.yaml',
|
|
315
314
|
|
|
316
|
-
output: './src/routes.ts', // single-file mode; with template.define, the app entry (
|
|
315
|
+
output: './src/routes.ts', // single-file mode; with template.define, the app entry (an index.ts path, default ./src/index.ts)
|
|
317
316
|
basePath: '/api',
|
|
318
317
|
readonly: true,
|
|
319
318
|
// format: {}, // oxfmt FormatConfig
|
|
@@ -322,7 +321,6 @@ export default defineConfig({
|
|
|
322
321
|
test: true,
|
|
323
322
|
routeHandler: false, // true: RouteHandler exports
|
|
324
323
|
define: false, // true: defineOpenAPIRoute output
|
|
325
|
-
// output: './src/routes', // define mode dir (default ./src/routes)
|
|
326
324
|
pathAlias: '@/',
|
|
327
325
|
testFramework: 'vitest', // "vitest" | "vite-plus" | "bun"
|
|
328
326
|
},
|
|
@@ -486,6 +484,11 @@ export default defineConfig({
|
|
|
486
484
|
|
|
487
485
|
mock: {
|
|
488
486
|
output: './src/mock.ts',
|
|
487
|
+
useExamples: true,
|
|
488
|
+
locale: 'en',
|
|
489
|
+
delay: false,
|
|
490
|
+
arrayMin: 1,
|
|
491
|
+
arrayMax: 10,
|
|
489
492
|
},
|
|
490
493
|
|
|
491
494
|
docs: {
|
package/dist/config/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
10
10
|
format: z.ZodExactOptional<z.ZodCustom<FormatConfig, FormatConfig>>;
|
|
11
11
|
template: z.ZodExactOptional<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
12
12
|
define: z.ZodLiteral<true>;
|
|
13
|
-
output: z.ZodDefault<z.ZodString>;
|
|
14
13
|
test: z.ZodDefault<z.ZodBoolean>;
|
|
15
14
|
pathAlias: z.ZodExactOptional<z.ZodString>;
|
|
16
15
|
testFramework: z.ZodExactOptional<z.ZodDefault<z.ZodEnum<{
|
|
@@ -21,7 +20,6 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
21
20
|
}, z.core.$strip>>, z.ZodReadonly<z.ZodObject<{
|
|
22
21
|
define: z.ZodDefault<z.ZodOptional<z.ZodLiteral<false>>>;
|
|
23
22
|
routeHandler: z.ZodDefault<z.ZodBoolean>;
|
|
24
|
-
output: z.ZodExactOptional<z.ZodString>;
|
|
25
23
|
test: z.ZodDefault<z.ZodBoolean>;
|
|
26
24
|
pathAlias: z.ZodExactOptional<z.ZodString>;
|
|
27
25
|
testFramework: z.ZodExactOptional<z.ZodDefault<z.ZodEnum<{
|
|
@@ -280,6 +278,14 @@ declare const ConfigSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
280
278
|
}, z.core.$strip>>>;
|
|
281
279
|
mock: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
|
|
282
280
|
output: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
281
|
+
useExamples: z.ZodExactOptional<z.ZodBoolean>;
|
|
282
|
+
locale: z.ZodExactOptional<z.ZodString>;
|
|
283
|
+
delay: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<false>, z.ZodReadonly<z.ZodObject<{
|
|
284
|
+
min: z.ZodNumber;
|
|
285
|
+
max: z.ZodNumber;
|
|
286
|
+
}, z.core.$strip>>]>>;
|
|
287
|
+
arrayMin: z.ZodExactOptional<z.ZodNumber>;
|
|
288
|
+
arrayMax: z.ZodExactOptional<z.ZodNumber>;
|
|
283
289
|
}, z.core.$strip>>>;
|
|
284
290
|
docs: z.ZodExactOptional<z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
285
291
|
output: z.ZodTemplateLiteral<`${string}.md`>;
|
|
@@ -322,7 +328,6 @@ declare function parseConfig(config: unknown): {
|
|
|
322
328
|
format?: FormatConfig;
|
|
323
329
|
template?: Readonly<{
|
|
324
330
|
define: true;
|
|
325
|
-
output: string;
|
|
326
331
|
test: boolean;
|
|
327
332
|
pathAlias?: string;
|
|
328
333
|
testFramework?: "vitest" | "vite-plus" | "bun";
|
|
@@ -330,7 +335,6 @@ declare function parseConfig(config: unknown): {
|
|
|
330
335
|
define: false;
|
|
331
336
|
routeHandler: boolean;
|
|
332
337
|
test: boolean;
|
|
333
|
-
output?: string;
|
|
334
338
|
pathAlias?: string;
|
|
335
339
|
testFramework?: "vitest" | "vite-plus" | "bun";
|
|
336
340
|
}>;
|
|
@@ -565,6 +569,14 @@ declare function parseConfig(config: unknown): {
|
|
|
565
569
|
}>;
|
|
566
570
|
mock?: Readonly<{
|
|
567
571
|
output: string;
|
|
572
|
+
useExamples?: boolean;
|
|
573
|
+
locale?: string;
|
|
574
|
+
delay?: number | false | Readonly<{
|
|
575
|
+
min: number;
|
|
576
|
+
max: number;
|
|
577
|
+
}>;
|
|
578
|
+
arrayMin?: number;
|
|
579
|
+
arrayMax?: number;
|
|
568
580
|
}>;
|
|
569
581
|
docs?: Readonly<{
|
|
570
582
|
output: `${string}.md`;
|
|
@@ -609,7 +621,6 @@ declare function readConfig(): Promise<{
|
|
|
609
621
|
format?: FormatConfig;
|
|
610
622
|
template?: Readonly<{
|
|
611
623
|
define: true;
|
|
612
|
-
output: string;
|
|
613
624
|
test: boolean;
|
|
614
625
|
pathAlias?: string;
|
|
615
626
|
testFramework?: "vitest" | "vite-plus" | "bun";
|
|
@@ -617,7 +628,6 @@ declare function readConfig(): Promise<{
|
|
|
617
628
|
define: false;
|
|
618
629
|
routeHandler: boolean;
|
|
619
630
|
test: boolean;
|
|
620
|
-
output?: string;
|
|
621
631
|
pathAlias?: string;
|
|
622
632
|
testFramework?: "vitest" | "vite-plus" | "bun";
|
|
623
633
|
}>;
|
|
@@ -852,6 +862,14 @@ declare function readConfig(): Promise<{
|
|
|
852
862
|
}>;
|
|
853
863
|
mock?: Readonly<{
|
|
854
864
|
output: string;
|
|
865
|
+
useExamples?: boolean;
|
|
866
|
+
locale?: string;
|
|
867
|
+
delay?: number | false | Readonly<{
|
|
868
|
+
min: number;
|
|
869
|
+
max: number;
|
|
870
|
+
}>;
|
|
871
|
+
arrayMin?: number;
|
|
872
|
+
arrayMax?: number;
|
|
855
873
|
}>;
|
|
856
874
|
docs?: Readonly<{
|
|
857
875
|
output: `${string}.md`;
|
|
@@ -878,14 +896,12 @@ declare function defineConfig(config: z.input<typeof ConfigSchema>): Readonly<{
|
|
|
878
896
|
format?: FormatConfig;
|
|
879
897
|
template?: Readonly<{
|
|
880
898
|
define: true;
|
|
881
|
-
output?: string | undefined;
|
|
882
899
|
test?: boolean | undefined;
|
|
883
900
|
pathAlias?: string;
|
|
884
901
|
testFramework?: "vitest" | "vite-plus" | "bun" | undefined;
|
|
885
902
|
}> | Readonly<{
|
|
886
903
|
define?: false | undefined;
|
|
887
904
|
routeHandler?: boolean | undefined;
|
|
888
|
-
output?: string;
|
|
889
905
|
test?: boolean | undefined;
|
|
890
906
|
pathAlias?: string;
|
|
891
907
|
testFramework?: "vitest" | "vite-plus" | "bun" | undefined;
|
|
@@ -1136,6 +1152,14 @@ declare function defineConfig(config: z.input<typeof ConfigSchema>): Readonly<{
|
|
|
1136
1152
|
}>;
|
|
1137
1153
|
mock?: Readonly<{
|
|
1138
1154
|
output: string;
|
|
1155
|
+
useExamples?: boolean;
|
|
1156
|
+
locale?: string;
|
|
1157
|
+
delay?: number | false | Readonly<{
|
|
1158
|
+
min: number;
|
|
1159
|
+
max: number;
|
|
1160
|
+
}>;
|
|
1161
|
+
arrayMin?: number;
|
|
1162
|
+
arrayMax?: number;
|
|
1139
1163
|
}>;
|
|
1140
1164
|
docs?: Readonly<{
|
|
1141
1165
|
output: `${string}.md`;
|
package/dist/config/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { i as deriveAppEntry } from "../utils-B5PbMfWs.js";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import { resolve } from "node:path";
|
|
3
4
|
import { pathToFileURL } from "node:url";
|
|
@@ -64,7 +65,6 @@ const ConfigSchema = z.object({
|
|
|
64
65
|
format: z.custom(() => true).exactOptional(),
|
|
65
66
|
template: z.discriminatedUnion("define", [z.object({
|
|
66
67
|
define: z.literal(true),
|
|
67
|
-
output: z.string().regex(/^(?!.*\.ts$).+/, { error: "template.output must be a directory, not a .ts file" }).default("src/routes"),
|
|
68
68
|
test: z.boolean().default(false),
|
|
69
69
|
pathAlias: z.string().exactOptional(),
|
|
70
70
|
testFramework: z.enum([
|
|
@@ -75,7 +75,6 @@ const ConfigSchema = z.object({
|
|
|
75
75
|
}).readonly(), z.object({
|
|
76
76
|
define: z.literal(false).optional().default(false),
|
|
77
77
|
routeHandler: z.boolean().default(false),
|
|
78
|
-
output: z.string().regex(/^(?!.*\.ts$).+/, { error: "template.output must be a directory, not a .ts file" }).exactOptional(),
|
|
79
78
|
test: z.boolean().default(false),
|
|
80
79
|
pathAlias: z.string().exactOptional(),
|
|
81
80
|
testFramework: z.enum([
|
|
@@ -148,7 +147,21 @@ const ConfigSchema = z.object({
|
|
|
148
147
|
"bun"
|
|
149
148
|
]).default("vitest").exactOptional()
|
|
150
149
|
}).readonly().exactOptional(),
|
|
151
|
-
mock: z.object({
|
|
150
|
+
mock: z.object({
|
|
151
|
+
output: FileOutputSchema,
|
|
152
|
+
useExamples: z.boolean().exactOptional(),
|
|
153
|
+
locale: z.string().regex(/^[A-Za-z_]{1,40}$/, { error: "Invalid faker locale. Use a code like 'ja', 'en', or 'zh_CN'." }).exactOptional(),
|
|
154
|
+
delay: z.union([
|
|
155
|
+
z.number().int().nonnegative().max(6e4),
|
|
156
|
+
z.literal(false),
|
|
157
|
+
z.object({
|
|
158
|
+
min: z.number().int().nonnegative().max(6e4),
|
|
159
|
+
max: z.number().int().nonnegative().max(6e4)
|
|
160
|
+
}).readonly().refine((v) => v.min <= v.max, { message: "delay.min must be <= delay.max. Swap the values or remove one." })
|
|
161
|
+
]).exactOptional(),
|
|
162
|
+
arrayMin: z.number().int().nonnegative().max(1e3).exactOptional(),
|
|
163
|
+
arrayMax: z.number().int().nonnegative().max(1e3).exactOptional()
|
|
164
|
+
}).readonly().refine((v) => v.arrayMin === void 0 || v.arrayMax === void 0 || v.arrayMin <= v.arrayMax, { message: "arrayMin must be <= arrayMax. Swap the values or remove one." }).exactOptional(),
|
|
152
165
|
docs: z.discriminatedUnion("curl", [z.object({
|
|
153
166
|
output: z.templateLiteral([z.string().min(1), z.enum([".md"])], { error: "must be .md file" }),
|
|
154
167
|
curl: z.literal(true),
|
|
@@ -160,7 +173,28 @@ const ConfigSchema = z.object({
|
|
|
160
173
|
entry: z.string().exactOptional(),
|
|
161
174
|
baseUrl: z.string().exactOptional()
|
|
162
175
|
}).readonly()]).exactOptional()
|
|
163
|
-
}).readonly().refine((v) => !(v.output && v.routes), { message: "output and routes are mutually exclusive. Use output for single-file mode, or routes for separate route output." }).refine((v) => !(v.template?.define && !v.output), { message: "template.define
|
|
176
|
+
}).readonly().refine((v) => !(v.output && v.routes), { message: "output and routes are mutually exclusive. Use output for single-file mode, or routes for separate route output." }).refine((v) => !(v.template?.define === true && v.routes), { message: "template.define and routes are mutually exclusive. define derives routes/ next to the app entry (output, default src/index.ts)." }).refine((v) => !(v.template?.define === true && v.output !== void 0 && !(v.output === "index.ts" || v.output.endsWith("/index.ts"))), { message: "with template.define, output is the app entry and must be an index.ts file (e.g. ./src/index.ts), or omitted to default to src/index.ts. Other names collide with the derived routes/ directory." }).refine((v) => !(v.template?.define === true && v.components !== void 0 && [
|
|
177
|
+
"schemas",
|
|
178
|
+
"responses",
|
|
179
|
+
"parameters",
|
|
180
|
+
"examples",
|
|
181
|
+
"requestBodies",
|
|
182
|
+
"headers",
|
|
183
|
+
"securitySchemes",
|
|
184
|
+
"links",
|
|
185
|
+
"callbacks",
|
|
186
|
+
"pathItems",
|
|
187
|
+
"mediaTypes"
|
|
188
|
+
].some((k) => v.components?.[k] !== void 0)), { message: "with template.define, per-type component outputs (components.schemas, components.responses, ...) are not supported. Use components.output for a single components file." }).refine((v) => {
|
|
189
|
+
if (v.template?.define !== true || v.components?.output === void 0) return true;
|
|
190
|
+
const normalize = (p) => p.replace(/^\.\//, "");
|
|
191
|
+
const componentsOutput = normalize(v.components.output);
|
|
192
|
+
const appEntry = normalize(v.output ?? deriveAppEntry(componentsOutput));
|
|
193
|
+
if (!appEntry.endsWith("index.ts")) return true;
|
|
194
|
+
const baseDir = appEntry === "index.ts" ? "" : appEntry.slice(0, -9);
|
|
195
|
+
const routesDir = baseDir === "" ? "routes" : `${baseDir}/routes`;
|
|
196
|
+
return componentsOutput !== appEntry && !componentsOutput.startsWith(`${routesDir}/`);
|
|
197
|
+
}, { message: "with template.define, components.output must not point at the app entry or inside the derived routes/ directory (it would be overwritten). Choose another path, e.g. src/components/index.ts." });
|
|
164
198
|
function parseConfig(config) {
|
|
165
199
|
const result = ConfigSchema.safeParse(config);
|
|
166
200
|
if (!result.success) {
|
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-DbknIWmx.js";
|
|
2
2
|
export { docs };
|
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-CCw7jm8g.js";
|
|
2
2
|
export { hooks };
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { f as methodPath, u as makeInferRequestType } from "../../utils-B5PbMfWs.js";
|
|
1
2
|
import { t as emit } from "../../emit-CFR63U4L.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-
|
|
3
|
+
import { c as isOperationLike, f as isRecord, o as isOpenAPIPaths } from "../../guard-BSZ8ezEv.js";
|
|
4
|
+
import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-BzPo2tZf.js";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
//#region src/core/rpc/index.ts
|
|
6
7
|
/**
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { d as makeSafeKey, g as statusCodeToNumber } from "../../utils-B5PbMfWs.js";
|
|
1
2
|
import { t as emit } from "../../emit-CFR63U4L.js";
|
|
2
|
-
import {
|
|
3
|
+
import { g as isSchemaArray, i as isMediaWithSchema, l as isParameter, m as isRequestBody, n as isHttpMethod, s as isOperation, u as isParameterArray, x as isStringRef } from "../../guard-BSZ8ezEv.js";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
//#region src/core/type/index.ts
|
|
5
6
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { s as escapeHtml } from "./utils-B5PbMfWs.js";
|
|
1
2
|
import { a as writeFile, t as mkdir } from "./fsp-BXry-Hx5.js";
|
|
2
|
-
import {
|
|
3
|
+
import { a as isOAuthFlowValue, b as isSecurityScheme, f as isRecord, h as isResponses, m as isRequestBody, p as isRefObject, r as isMedia, y as isSecurityArray } from "./guard-BSZ8ezEv.js";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { STATUS_CODES } from "node:http";
|
|
5
6
|
//#region src/generator/docs/index.ts
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
import { t as zodOpenAPIHono } from "../../../openapi-BlTDQFFF.js";
|
|
2
2
|
export { zodOpenAPIHono };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region src/guard/index.ts
|
|
2
|
+
function isRecord(v) {
|
|
3
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4
|
+
}
|
|
5
|
+
function isHttpMethod(method) {
|
|
6
|
+
return method === "get" || method === "put" || method === "post" || method === "delete" || method === "patch" || method === "options" || method === "head" || method === "trace";
|
|
7
|
+
}
|
|
8
|
+
function isValidIdent(str) {
|
|
9
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str);
|
|
10
|
+
}
|
|
11
|
+
function isOpenAPIPaths(v) {
|
|
12
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
13
|
+
return Object.values(v).every((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry));
|
|
14
|
+
}
|
|
15
|
+
function isRefObject(v) {
|
|
16
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "$ref" in v && typeof v.$ref === "string";
|
|
17
|
+
}
|
|
18
|
+
function isStringRef(v) {
|
|
19
|
+
return "$ref" in v && typeof v.$ref === "string";
|
|
20
|
+
}
|
|
21
|
+
function isParameterObject(v) {
|
|
22
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
23
|
+
if (!("name" in v) || typeof v.name !== "string") return false;
|
|
24
|
+
if (!("in" in v)) return false;
|
|
25
|
+
const pos = v.in;
|
|
26
|
+
return pos === "path" || pos === "query" || pos === "header" || pos === "cookie";
|
|
27
|
+
}
|
|
28
|
+
function isParameter(v) {
|
|
29
|
+
return typeof v === "object" && v !== null && "name" in v && "in" in v && ("schema" in v || "content" in v);
|
|
30
|
+
}
|
|
31
|
+
function isParameterArray(v) {
|
|
32
|
+
return Array.isArray(v);
|
|
33
|
+
}
|
|
34
|
+
function isOperationLike(v) {
|
|
35
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "responses" in v;
|
|
36
|
+
}
|
|
37
|
+
function isOperation(v) {
|
|
38
|
+
return typeof v === "object" && v !== null && "responses" in v;
|
|
39
|
+
}
|
|
40
|
+
function isSchemaProperty(v) {
|
|
41
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "schema" in v;
|
|
42
|
+
}
|
|
43
|
+
function isSchemaArray(v) {
|
|
44
|
+
return Array.isArray(v);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* JSON Schema 2020-12 §4.3.2 / §10.3.1.2 type guard for schema-vs-boolean
|
|
48
|
+
* discrimination. `items`, `additionalProperties`, `unevaluatedItems`, and
|
|
49
|
+
* `unevaluatedProperties` may be either an object schema or a boolean schema
|
|
50
|
+
* (`true` = pass-through, `false` = reject). This narrows the union to the
|
|
51
|
+
* object form so callers can recurse without `as` casts.
|
|
52
|
+
*/
|
|
53
|
+
function isSchemaObject(v) {
|
|
54
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
55
|
+
}
|
|
56
|
+
function isMediaWithSchema(v) {
|
|
57
|
+
return typeof v === "object" && v !== null && "schema" in v;
|
|
58
|
+
}
|
|
59
|
+
function isMedia(v) {
|
|
60
|
+
return typeof v === "object" && v !== null && "schema" in v;
|
|
61
|
+
}
|
|
62
|
+
function isRequestBody(v) {
|
|
63
|
+
return typeof v === "object" && v !== null && ("content" in v || "required" in v || "description" in v);
|
|
64
|
+
}
|
|
65
|
+
function isContentBody(v) {
|
|
66
|
+
return typeof v === "object" && v !== null && !("$ref" in v);
|
|
67
|
+
}
|
|
68
|
+
function isSecurityScheme(v) {
|
|
69
|
+
return typeof v === "object" && v !== null && !("$ref" in v);
|
|
70
|
+
}
|
|
71
|
+
function isSecurityArray(v) {
|
|
72
|
+
return Array.isArray(v);
|
|
73
|
+
}
|
|
74
|
+
function isResponses(v) {
|
|
75
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
76
|
+
return "$ref" in v || "description" in v || "content" in v || "headers" in v || "links" in v;
|
|
77
|
+
}
|
|
78
|
+
function isOAuthFlowValue(v) {
|
|
79
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
80
|
+
return "authorizationUrl" in v || "tokenUrl" in v || "scopes" in v;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { isValidIdent as S, isSchemaObject as _, isOAuthFlowValue as a, isSecurityScheme as b, isOperationLike as c, isParameterObject as d, isRecord as f, isSchemaArray as g, isResponses as h, isMediaWithSchema as i, isParameter as l, isRequestBody as m, isHttpMethod as n, isOpenAPIPaths as o, isRefObject as p, isMedia as r, isOperation as s, isContentBody as t, isParameterArray as u, isSchemaProperty as v, isStringRef as x, isSecurityArray as y };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { _ as toIdentifierPascalCase, f as methodPath, n as capitalize } from "./utils-B5PbMfWs.js";
|
|
1
2
|
import { t as emit } from "./emit-CFR63U4L.js";
|
|
2
|
-
import {
|
|
3
|
-
import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-
|
|
3
|
+
import { c as isOperationLike, f as isRecord, o as isOpenAPIPaths } from "./guard-BSZ8ezEv.js";
|
|
4
|
+
import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-BzPo2tZf.js";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
//#region src/helper/query.ts
|
|
6
7
|
function makeHookName(method, pathStr, prefix) {
|
|
@@ -313,7 +314,7 @@ function makeSWRHeader(importPath, clientName, hasQuery, hasMutation, hasAnyArgs
|
|
|
313
314
|
lines.push("import useSWRMutation from'swr/mutation'");
|
|
314
315
|
lines.push("import type{SWRMutationConfiguration}from'swr/mutation'");
|
|
315
316
|
}
|
|
316
|
-
const honoTypeImports = ["ClientRequestOptions", ...hasAnyArgs ? ["InferRequestType"] : []];
|
|
317
|
+
const honoTypeImports = ["ClientRequestOptions", ...hasAnyArgs || hasInfiniteQuery ? ["InferRequestType"] : []];
|
|
317
318
|
lines.push(`import type{${honoTypeImports.join(",")}}from'hono/client'`);
|
|
318
319
|
lines.push("import{parseResponse}from'hono/client'");
|
|
319
320
|
lines.push(`import{${clientName}}from'${importPath}'`);
|
|
@@ -515,7 +516,7 @@ function makeHeader(importPath, clientName, hasQuery, hasMutation, hasAnyArgs, c
|
|
|
515
516
|
...hasMutation ? [config.useMutationOptionsType] : []
|
|
516
517
|
];
|
|
517
518
|
const needsVueImports = config.isVueQuery && hasQueryWithArgs;
|
|
518
|
-
const honoTypeImports = ["ClientRequestOptions", ...hasAnyArgs ? ["InferRequestType"] : []];
|
|
519
|
+
const honoTypeImports = ["ClientRequestOptions", ...hasAnyArgs || hasInfiniteQuery ? ["InferRequestType"] : []];
|
|
519
520
|
return `${[
|
|
520
521
|
...queryImports.length > 0 ? [`import{${queryImports.join(",")}}from'${config.packageName}'`] : [],
|
|
521
522
|
...typeImports.length > 0 ? [`import type{${typeImports.join(",")}}from'${config.packageName}'`] : [],
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readConfig } from "./config/index.js";
|
|
3
3
|
import { r as setFormatOptions } from "./emit-CFR63U4L.js";
|
|
4
|
-
import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-
|
|
4
|
+
import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-B-TUm7Fa.js";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
7
|
//#region src/cli/index.ts
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as toIdentifierPascalCase, a as ensureSuffix, c as escapeRegexLiteral, d as makeSafeKey, f as methodPath, h as requestParamsArray, m as renderNamedImport, o as error, p as normalizeTypes, r as cyclicNodes, t as baseError, v as uncapitalize, y as zodToOpenAPISchema } from "./utils-B5PbMfWs.js";
|
|
2
|
+
import { _ as isSchemaObject, f as isRecord, g as isSchemaArray, l as isParameter, p as isRefObject, r as isMedia, s as isOperation } from "./guard-BSZ8ezEv.js";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import ts from "typescript";
|
|
4
5
|
//#region src/helper/code.ts
|
|
@@ -1634,108 +1635,33 @@ function getChildren(node) {
|
|
|
1634
1635
|
return semanticChildren;
|
|
1635
1636
|
}
|
|
1636
1637
|
function collectIdentifiers(node) {
|
|
1638
|
+
const identifiers = [];
|
|
1637
1639
|
const visit = (n) => {
|
|
1638
|
-
|
|
1639
|
-
const
|
|
1640
|
-
return [...current, ...children];
|
|
1640
|
+
if (ts.isIdentifier(n)) identifiers.push(n.text);
|
|
1641
|
+
for (const child of getChildren(n)) visit(child);
|
|
1641
1642
|
};
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
function extractIdentifiers(code, varNames) {
|
|
1645
|
-
const allIdentifiers = collectIdentifiers(makeSourceFile(code));
|
|
1646
|
-
return [...new Set(allIdentifiers.filter((id) => varNames.has(id)))];
|
|
1647
|
-
}
|
|
1648
|
-
function createInitialState() {
|
|
1649
|
-
return {
|
|
1650
|
-
indices: /* @__PURE__ */ new Map(),
|
|
1651
|
-
lowLinks: /* @__PURE__ */ new Map(),
|
|
1652
|
-
onStack: /* @__PURE__ */ new Set(),
|
|
1653
|
-
stack: [],
|
|
1654
|
-
sccs: [],
|
|
1655
|
-
index: 0
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
function popStackUntil(stack, onStack, name) {
|
|
1659
|
-
const idx = stack.lastIndexOf(name);
|
|
1660
|
-
if (idx === -1) return {
|
|
1661
|
-
scc: [],
|
|
1662
|
-
newStack: stack,
|
|
1663
|
-
newOnStack: onStack
|
|
1664
|
-
};
|
|
1665
|
-
const scc = stack.slice(idx);
|
|
1666
|
-
return {
|
|
1667
|
-
scc,
|
|
1668
|
-
newStack: stack.slice(0, idx),
|
|
1669
|
-
newOnStack: new Set([...onStack].filter((n) => !scc.includes(n)))
|
|
1670
|
-
};
|
|
1671
|
-
}
|
|
1672
|
-
function tarjanConnect(name, deps, var2name, state) {
|
|
1673
|
-
const currentIndex = state.index;
|
|
1674
|
-
const indices = new Map(state.indices).set(name, currentIndex);
|
|
1675
|
-
const lowLinks = new Map(state.lowLinks).set(name, currentIndex);
|
|
1676
|
-
const stack = [...state.stack, name];
|
|
1677
|
-
const onStack = /* @__PURE__ */ new Set([...state.onStack, name]);
|
|
1678
|
-
const initialState = {
|
|
1679
|
-
...state,
|
|
1680
|
-
indices,
|
|
1681
|
-
lowLinks,
|
|
1682
|
-
stack,
|
|
1683
|
-
onStack,
|
|
1684
|
-
index: currentIndex + 1
|
|
1685
|
-
};
|
|
1686
|
-
const afterDeps = (deps.get(name) ?? []).reduce((s, depVar) => {
|
|
1687
|
-
const depName = var2name.get(depVar);
|
|
1688
|
-
if (depName === void 0) return s;
|
|
1689
|
-
if (!s.indices.has(depName)) {
|
|
1690
|
-
const afterConnect = tarjanConnect(depName, deps, var2name, s);
|
|
1691
|
-
const newLowLink = Math.min(afterConnect.lowLinks.get(name) ?? 0, afterConnect.lowLinks.get(depName) ?? 0);
|
|
1692
|
-
const updatedLowLinks = new Map(afterConnect.lowLinks).set(name, newLowLink);
|
|
1693
|
-
return {
|
|
1694
|
-
...afterConnect,
|
|
1695
|
-
lowLinks: updatedLowLinks
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
if (s.onStack.has(depName)) {
|
|
1699
|
-
const newLowLink = Math.min(s.lowLinks.get(name) ?? 0, s.indices.get(depName) ?? 0);
|
|
1700
|
-
const updatedLowLinks = new Map(s.lowLinks).set(name, newLowLink);
|
|
1701
|
-
return {
|
|
1702
|
-
...s,
|
|
1703
|
-
lowLinks: updatedLowLinks
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
return s;
|
|
1707
|
-
}, initialState);
|
|
1708
|
-
if (afterDeps.lowLinks.get(name) === afterDeps.indices.get(name)) {
|
|
1709
|
-
const { scc, newStack, newOnStack } = popStackUntil(afterDeps.stack, afterDeps.onStack, name);
|
|
1710
|
-
return {
|
|
1711
|
-
...afterDeps,
|
|
1712
|
-
stack: newStack,
|
|
1713
|
-
onStack: newOnStack,
|
|
1714
|
-
sccs: [...afterDeps.sccs, scc]
|
|
1715
|
-
};
|
|
1716
|
-
}
|
|
1717
|
-
return afterDeps;
|
|
1643
|
+
visit(node);
|
|
1644
|
+
return identifiers;
|
|
1718
1645
|
}
|
|
1719
1646
|
function findCyclicSchemas(names, deps) {
|
|
1720
|
-
const name2var = new Map(names.map((n) => [n, toIdentifierPascalCase(ensureSuffix(n, "Schema"))]));
|
|
1721
1647
|
const var2name = new Map(names.map((n) => [toIdentifierPascalCase(ensureSuffix(n, "Schema")), n]));
|
|
1722
|
-
|
|
1723
|
-
return new Set(finalState.sccs.flatMap((scc) => {
|
|
1724
|
-
if (scc.length > 1) return [...scc];
|
|
1725
|
-
const single = scc[0];
|
|
1726
|
-
if (!single) return [];
|
|
1727
|
-
const selfVar = name2var.get(single);
|
|
1728
|
-
return selfVar && (deps.get(single) ?? []).includes(selfVar) ? [single] : [];
|
|
1729
|
-
}));
|
|
1648
|
+
return cyclicNodes(new Map(names.map((n) => [n, (deps.get(n) ?? []).map((v) => var2name.get(v)).filter((x) => x !== void 0)])));
|
|
1730
1649
|
}
|
|
1731
1650
|
function analyzeCircularSchemas(schemas, schemaNames, readonly) {
|
|
1732
1651
|
const varNameSet = new Set(schemaNames.map((n) => toIdentifierPascalCase(ensureSuffix(n, "Schema"))));
|
|
1733
1652
|
const varNameToName = new Map(schemaNames.map((n) => [toIdentifierPascalCase(ensureSuffix(n, "Schema")), n]));
|
|
1734
1653
|
const zSchemaMap = new Map(schemaNames.map((n) => [n, zodToOpenAPI(schemas[n], void 0, readonly === true ? { readonly: true } : void 0)]));
|
|
1654
|
+
const batchedSource = makeSourceFile(schemaNames.map((n) => `const ${toIdentifierPascalCase(ensureSuffix(n, "Schema"))} = ${zSchemaMap.get(n)}`).join("\n"));
|
|
1655
|
+
const initializerIdentifiers = new Map(batchedSource.statements.flatMap((statement) => {
|
|
1656
|
+
if (!ts.isVariableStatement(statement)) return [];
|
|
1657
|
+
const declaration = statement.declarationList.declarations[0];
|
|
1658
|
+
if (!(declaration && ts.isIdentifier(declaration.name) && declaration.initializer)) return [];
|
|
1659
|
+
return [[declaration.name.text, collectIdentifiers(declaration.initializer)]];
|
|
1660
|
+
}));
|
|
1735
1661
|
const depsMap = new Map(schemaNames.map((n) => {
|
|
1736
|
-
const code = zSchemaMap.get(n) ?? "";
|
|
1737
1662
|
const selfVar = toIdentifierPascalCase(ensureSuffix(n, "Schema"));
|
|
1738
|
-
|
|
1663
|
+
const identifiers = initializerIdentifiers.get(selfVar) ?? [];
|
|
1664
|
+
return [n, [...new Set(identifiers.filter((id) => varNameSet.has(id)))].filter((v) => v !== selfVar)];
|
|
1739
1665
|
}));
|
|
1740
1666
|
const cyclicSchemas = findCyclicSchemas(schemaNames, depsMap);
|
|
1741
1667
|
const extendedCyclicSchemas = /* @__PURE__ */ new Set([...cyclicSchemas, ...[...cyclicSchemas].flatMap((n) => (depsMap.get(n) ?? []).map((v) => varNameToName.get(v)).filter((x) => x !== void 0))]);
|
|
@@ -1799,27 +1725,24 @@ function topoSort(decls) {
|
|
|
1799
1725
|
const makeKey = (kind, name) => `${kind}:${name}`;
|
|
1800
1726
|
const map = new Map(decls.map((d) => [makeKey(d.kind, d.name), d]));
|
|
1801
1727
|
const findByName = (name) => map.get(makeKey("variable", name)) ?? map.get(makeKey("type", name)) ?? map.get(makeKey("interface", name));
|
|
1802
|
-
const
|
|
1803
|
-
|
|
1728
|
+
const sorted = [];
|
|
1729
|
+
const perm = /* @__PURE__ */ new Set();
|
|
1730
|
+
const temp = /* @__PURE__ */ new Set();
|
|
1731
|
+
const visit = (key) => {
|
|
1732
|
+
if (perm.has(key) || temp.has(key)) return;
|
|
1804
1733
|
const decl = map.get(key);
|
|
1805
|
-
if (!decl) return
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
temp: new Set([...afterRefs.temp].filter((t) => t !== key))
|
|
1815
|
-
};
|
|
1816
|
-
};
|
|
1817
|
-
const initial = {
|
|
1818
|
-
sorted: [],
|
|
1819
|
-
perm: /* @__PURE__ */ new Set(),
|
|
1820
|
-
temp: /* @__PURE__ */ new Set()
|
|
1734
|
+
if (!decl) return;
|
|
1735
|
+
temp.add(key);
|
|
1736
|
+
for (const ref of decl.refs) {
|
|
1737
|
+
const found = findByName(ref);
|
|
1738
|
+
if (found) visit(makeKey(found.kind, found.name));
|
|
1739
|
+
}
|
|
1740
|
+
temp.delete(key);
|
|
1741
|
+
perm.add(key);
|
|
1742
|
+
sorted.push(decl);
|
|
1821
1743
|
};
|
|
1822
|
-
|
|
1744
|
+
for (const decl of decls) visit(makeKey(decl.kind, decl.name));
|
|
1745
|
+
return sorted;
|
|
1823
1746
|
}
|
|
1824
1747
|
function ast(code) {
|
|
1825
1748
|
const decls = parseStatements(makeSourceFile(code));
|
|
@@ -2365,6 +2288,7 @@ function componentsCode(components, options) {
|
|
|
2365
2288
|
function routeCode(openapi, readonly) {
|
|
2366
2289
|
const routeEntries = (openapi, readonly) => {
|
|
2367
2290
|
const makeEntry = (path, method, operation, readonly) => {
|
|
2291
|
+
const request = makeRequest(operation.parameters, operation.requestBody, readonly);
|
|
2368
2292
|
const properties = [
|
|
2369
2293
|
`method:${JSON.stringify(method)}`,
|
|
2370
2294
|
`path:${JSON.stringify(path)}`,
|
|
@@ -2373,7 +2297,7 @@ function routeCode(openapi, readonly) {
|
|
|
2373
2297
|
operation.description ? `description:${JSON.stringify(operation.description)}` : void 0,
|
|
2374
2298
|
operation.externalDocs ? `externalDocs:${JSON.stringify(operation.externalDocs)}` : void 0,
|
|
2375
2299
|
operation.operationId ? `operationId:${JSON.stringify(operation.operationId)}` : void 0,
|
|
2376
|
-
|
|
2300
|
+
request ? `request:${request}` : void 0,
|
|
2377
2301
|
operation.responses ? `responses:${makeOperationResponses(operation.responses, readonly)}` : void 0,
|
|
2378
2302
|
operation.callbacks ? `callbacks:{${makeCallbacks(operation.callbacks, readonly)}}` : void 0,
|
|
2379
2303
|
operation.deprecated ? `deprecated:${JSON.stringify(operation.deprecated)}` : void 0,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as isValidIdent, c as isOperationLike, d as isParameterObject, f as isRecord, p as isRefObject, v as isSchemaProperty } from "./guard-
|
|
1
|
+
import { S as isValidIdent, c as isOperationLike, d as isParameterObject, f as isRecord, p as isRefObject, v as isSchemaProperty } from "./guard-BSZ8ezEv.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
//#region src/helper/rpc.ts
|
|
4
4
|
function makeEscaped(s) {
|