hono-takibi 0.9.99997 → 0.9.99998

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 CHANGED
@@ -135,10 +135,10 @@ export default defineConfig({
135
135
  This generates:
136
136
 
137
137
  - `src/index.ts` - App entry point with route registrations
138
- - `src/handlers/*.ts` - Handler stubs for each resource
138
+ - `src/handlers/*.ts` - Handler stubs, one file per tag (the first `tags` entry of each operation, lower camel case; the first path segment when an operation has no tag)
139
139
  - `src/handlers/*.test.ts` - Test files with `@faker-js/faker` mock data (imports from `vitest`, `vite-plus/test`, or `bun:test`)
140
140
 
141
- Re-running after updating your OpenAPI spec is safe — your hand-written handler logic and test customizations are preserved. Only new routes are added as stubs.
141
+ Re-running after updating your OpenAPI spec is safe — your hand-written handler logic and test customizations are preserved. Only new routes are added as stubs. The generator never deletes a file under `handlers/` and never re-stubs a handler that already exists in that directory: a handler you moved into another file (e.g. split by concern) is regenerated in place, files that hold no `*RouteHandler` export / `.openapi(xxxRoute)` registration / `*Route` export stay untouched, and their `export * from` lines in `handlers/index.ts` are kept. When a route leaves the spec, its handler declaration and route import are removed from whichever file holds them, but the file itself — and anything hand-written in it — remains; delete it by hand once nothing else is in it. Only top-level files in `handlers/` are scanned, not subdirectories.
142
142
 
143
143
  ### Handler Generation Modes
144
144
 
@@ -170,6 +170,8 @@ export const api = app.route('/', healthHandler)
170
170
  export default app
171
171
  ```
172
172
 
173
+ If you split routes into hand-written files in this mode, name each sub-router export `<fileBasename>Handler` (e.g. `export const sharesHandler = ...` in `shares.ts`) — that is the name the generator merges into and the app mounts.
174
+
173
175
  #### `routeHandler: true`
174
176
 
175
177
  Handlers export typed `RouteHandler` functions, and `index.ts` centralizes route registration:
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { readConfig } from "./index.js";
3
- import { r as setFormatOptions } from "./emit-CFR63U4L.js";
4
- import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-66qmwvRi.js";
3
+ import { r as setFormatOptions } from "./emit-rUfH9f6q.js";
4
+ import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-Zyc06ZL_.js";
5
5
  import { existsSync } from "node:fs";
6
6
  import { resolve } from "node:path";
7
7
  //#region src/cli/index.ts
@@ -9,12 +9,16 @@ const HELP_TEXT = `Usage: hono-takibi <input.{yaml,json,tsp}> -o <output.ts>
9
9
 
10
10
  Options:
11
11
  -h, --help display help for command`;
12
+ function isYamlOrJsonOrTsp(i) {
13
+ return i.endsWith(".yaml") || i.endsWith(".json") || i.endsWith(".tsp");
14
+ }
15
+ function isTs(o) {
16
+ return o.endsWith(".ts");
17
+ }
12
18
  function parseCli(args) {
13
19
  const input = args[0];
14
20
  const oIdx = args.indexOf("-o");
15
21
  const output = oIdx !== -1 ? args[oIdx + 1] : void 0;
16
- const isYamlOrJsonOrTsp = (i) => i.endsWith(".yaml") || i.endsWith(".json") || i.endsWith(".tsp");
17
- const isTs = (o) => o.endsWith(".ts");
18
22
  if (!(input && output && isYamlOrJsonOrTsp(input) && isTs(output))) return {
19
23
  ok: false,
20
24
  error: HELP_TEXT
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/docs/index.d.ts
3
3
  declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Promise<{
4
4
  readonly value?: never;
@@ -1,2 +1,2 @@
1
- import { t as docs } from "../../docs-D6-_1ql4.js";
1
+ import { t as docs } from "../../docs-D0ZoEuTk.js";
2
2
  export { docs };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/hooks/index.d.ts
3
3
  declare const HOOK_CONFIGS: {
4
4
  readonly swr: {
@@ -1,2 +1,2 @@
1
- import { t as hooks } from "../../hooks-qJjGH61L.js";
1
+ import { t as hooks } from "../../hooks-BMBBxGkd.js";
2
2
  export { hooks };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/rpc/index.d.ts
3
3
  /**
4
4
  * Generates RPC client wrapper functions from OpenAPI specification.
@@ -1,7 +1,7 @@
1
- import { t as emit } from "../../emit-CFR63U4L.js";
2
- import { N as methodPath, c as isOperationLike, f as isRecord, j as makeInferRequestType, o as isOpenAPIPaths } from "../../guard-C_eRJ0au.js";
3
- import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-BDZmSva1.js";
4
- import path from "node:path";
1
+ import { t as emit } from "../../emit-rUfH9f6q.js";
2
+ import { D as isOpenAPIPaths, L as isRecord, d as methodPath, k as isOperationLike, l as makeInferRequestType } from "../../utils-D1npWaGs.js";
3
+ import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-BefI0iar.js";
4
+ import { dirname, join } from "node:path";
5
5
  //#region src/core/rpc/index.ts
6
6
  /**
7
7
  * Builds a JSDoc block from operation `summary` / `description` plus the HTTP route line.
@@ -16,7 +16,7 @@ function makeJsDoc(operation, method, path) {
16
16
  if (summary) sections.push([summary]);
17
17
  if (description) sections.push(description.split("\n"));
18
18
  sections.push([`${method.toUpperCase()} ${path}`]);
19
- return `/**\n${sections.map((lines, i) => i === 0 ? lines : ["", ...lines]).flat().map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
19
+ return `/**\n${sections.map((lines) => lines.join("\n")).join("\n\n").split("\n").map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
20
20
  }
21
21
  function makeOperationCode(path, method, item, deps, useParseResponse, hasBasePath, docs) {
22
22
  const operation = item[method];
@@ -83,8 +83,8 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
83
83
  const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), useParseResponse, hasBasePath, docs);
84
84
  if (!split) {
85
85
  const body = operationCodes.map(({ code }) => code).join("\n\n");
86
- const code = `${makeHeader(importPath, operationCodes.some(({ hasArgs }) => hasArgs), clientName, useParseResponse)}${body}${operationCodes.length ? "\n" : ""}`;
87
- const emitResult = await emit(code, path.dirname(output), output);
86
+ const code = `${makeHeader(importPath, operationCodes.some(({ hasArgs }) => hasArgs), clientName, useParseResponse)}${body}${operationCodes.length > 0 ? "\n" : ""}`;
87
+ const emitResult = await emit(code, dirname(output), output);
88
88
  if (!emitResult.ok) return {
89
89
  ok: false,
90
90
  error: emitResult.error
@@ -95,12 +95,12 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
95
95
  };
96
96
  }
97
97
  const { outDir, indexPath } = resolveSplitOutDir(output);
98
- const index = `${Array.from(new Set(operationCodes.map(({ funcName }) => `export * from './${funcName}'`))).join("\n")}\n`;
98
+ const index = `${[...new Set(operationCodes.map(({ funcName }) => `export * from './${funcName}'`))].join("\n")}\n`;
99
99
  const e = (await Promise.all([...operationCodes.map(({ funcName, code, hasArgs }) => {
100
100
  const fileSrc = `${makeHeader(importPath, hasArgs, clientName, useParseResponse)}${code}\n`;
101
- const filePath = path.join(outDir, `${funcName}.ts`);
102
- return emit(fileSrc, path.dirname(filePath), filePath);
103
- }), emit(index, path.dirname(indexPath), indexPath)])).find((result) => !result.ok);
101
+ const filePath = join(outDir, `${funcName}.ts`);
102
+ return emit(fileSrc, dirname(filePath), filePath);
103
+ }), emit(index, dirname(indexPath), indexPath)])).find((result) => !result.ok);
104
104
  if (e) return e;
105
105
  return {
106
106
  ok: true,
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/type/index.d.ts
3
3
  /**
4
4
  * Generates TypeScript type declarations from OpenAPI specification.
@@ -1,5 +1,5 @@
1
- import { t as emit } from "../../emit-CFR63U4L.js";
2
- import { L as statusCodeToNumber, M as makeSafeKey, 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-C_eRJ0au.js";
1
+ import { t as emit } from "../../emit-rUfH9f6q.js";
2
+ import { A as isParameter, C as isHttpMethod, D as isOpenAPIPaths, O as isOperation, T as isMediaWithSchema, V as isSchemaArray, h as statusCodeToNumber, j as isParameterArray, q as isStringRef, u as makeSafeKey, z as isRequestBody } from "../../utils-D1npWaGs.js";
3
3
  import path from "node:path";
4
4
  //#region src/core/type/index.ts
5
5
  /**
@@ -28,7 +28,8 @@ async function type(openAPI, output, readonly) {
28
28
  };
29
29
  }
30
30
  function makeHonoSchemaType(openAPI) {
31
- const { paths, components } = openAPI;
31
+ const { components } = openAPI;
32
+ const paths = isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {};
32
33
  const pathEntries = Object.entries(paths).flatMap(([openApiPath, pathItem]) => {
33
34
  const honoPath = makeHonoPath(openApiPath);
34
35
  const pathLevelParams = isParameterArray(pathItem.parameters) ? pathItem.parameters : [];
@@ -47,7 +48,7 @@ function makeHonoSchemaType(openAPI) {
47
48
  return pathEntries.length === 0 ? "{}" : pathEntries.map(({ path: p, methods }) => `{'${p}':{${methods}}}`).join("&");
48
49
  }
49
50
  function makeHonoPath(openApiPath) {
50
- return openApiPath.replace(/\{([^}]+)\}/g, ":$1");
51
+ return openApiPath.replaceAll(/\{([^}]+)\}/g, ":$1");
51
52
  }
52
53
  function makeMethodType(operation, openApiPath, components, pathLevelParams) {
53
54
  const inputType = makeInputType(operation, openApiPath, components, pathLevelParams);
@@ -69,7 +70,7 @@ function makeInputType(operation, openApiPath, components, pathLevelParams) {
69
70
  return parts.length === 0 ? "{}" : parts.join("&");
70
71
  }
71
72
  function makePathParams(openApiPath) {
72
- return Array.from(openApiPath.matchAll(/\{([^}]+)\}/g)).map((m) => m[1]);
73
+ return [...openApiPath.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
73
74
  }
74
75
  function makeParamPart(params, components) {
75
76
  const props = params.map((p) => {
@@ -168,9 +169,9 @@ function makeSchemaTypeString(schema, components, visited) {
168
169
  if (schema.oneOf && schema.oneOf.length > 0) return schema.oneOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
169
170
  if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
170
171
  if (schema.allOf && schema.allOf.length > 0) return makeAllOfTypeString(schema.allOf, components, visited);
171
- if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'` : String(v)).join("|");
172
+ if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : String(v)).join("|");
172
173
  if (schema.const !== void 0) {
173
- if (typeof schema.const === "string") return `'${schema.const.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
174
+ if (typeof schema.const === "string") return `'${schema.const.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
174
175
  if (typeof schema.const === "number" || typeof schema.const === "boolean") return String(schema.const);
175
176
  return JSON.stringify(schema.const);
176
177
  }
@@ -222,7 +223,7 @@ function makeAllOfTypeString(allOf, components, visited) {
222
223
  return result;
223
224
  }, /* @__PURE__ */ new Map());
224
225
  if (mergedProps.size === 0) return "{}";
225
- return `{${Array.from(mergedProps.entries()).map(([key, { type, required }]) => {
226
+ return `{${[...mergedProps.entries()].map(([key, { type, required }]) => {
226
227
  const safeKey = makeSafeKey(key);
227
228
  return required ? `${safeKey}:${type}` : `${safeKey}?:${type}|undefined`;
228
229
  }).join(";")}}`;
@@ -1,5 +1,5 @@
1
- import { a as writeFile, t as mkdir } from "./fsp-BXry-Hx5.js";
2
- import { O as escapeHtml, 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-C_eRJ0au.js";
1
+ import { i as writeFile, t as mkdir } from "./fsp-BxW8iutq.js";
2
+ import { B as isResponses, D as isOpenAPIPaths, E as isOAuthFlowValue, G as isSecurityScheme, H as isSchemaObject, L as isRecord, R as isRefObject, V as isSchemaArray, W as isSecurityArray, o as escapeHtml, w as isMedia, z as isRequestBody } from "./utils-D1npWaGs.js";
3
3
  import path from "node:path";
4
4
  import { STATUS_CODES } from "node:http";
5
5
  //#region src/generator/docs/index.ts
@@ -15,10 +15,10 @@ const HTTP_METHODS = [
15
15
  ];
16
16
  const MAX_SCHEMA_DEPTH = 50;
17
17
  function toSlug(text) {
18
- return (typeof text === "string" ? text : String(text ?? "")).replace(/[A-Z]/g, (c) => c.toLowerCase()).replace(/[^a-z0-9\u3000-\u9fff\uff00-\uffef -]/g, "").replace(/\s+/g, "-");
18
+ return (typeof text === "string" ? text : String(text ?? "")).replaceAll(/[A-Z]/g, (c) => c.toLowerCase()).replaceAll(/[^a-z0-9\u3000-\u9fff\uff00-\uffef -]/g, "").replaceAll(/\s+/g, "-");
19
19
  }
20
20
  function toTitleSlug(title) {
21
- return (typeof title === "string" ? title : String(title ?? "")).toLowerCase().replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, "-");
21
+ return (typeof title === "string" ? title : String(title ?? "")).toLowerCase().replaceAll(/[^a-z0-9 -]/g, "").replaceAll(/\s+/g, "-");
22
22
  }
23
23
  function lookupComponentSection(components, section) {
24
24
  switch (section) {
@@ -65,8 +65,8 @@ function formatSchemaType(schema) {
65
65
  return `[${name}](#schema${name.toLowerCase()})`;
66
66
  }
67
67
  if (schema.type === "array" && schema.items) {
68
- const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
69
- if (itemSchema) return `[${formatSchemaType(itemSchema)}]`;
68
+ const itemSchema = isSchemaArray(schema.items) ? schema.items[0] : schema.items;
69
+ if (isSchemaObject(itemSchema)) return `[${formatSchemaType(itemSchema)}]`;
70
70
  return "array";
71
71
  }
72
72
  const baseType = Array.isArray(schema.type) ? schema.type.join(" | ") : schema.type ?? "object";
@@ -103,7 +103,7 @@ function makeDefaultValue(schema) {
103
103
  switch (schema.type) {
104
104
  case "string": return makeDefaultString(schema.format);
105
105
  case "number":
106
- case "integer": return schema.minimum !== void 0 ? schema.minimum : 0;
106
+ case "integer": return schema.minimum ?? 0;
107
107
  case "boolean": return true;
108
108
  default: return null;
109
109
  }
@@ -126,8 +126,8 @@ function makeExampleFromSchema(schema, components, visited = /* @__PURE__ */ new
126
126
  return result;
127
127
  }
128
128
  if (schema.type === "array" && schema.items) {
129
- const item = Array.isArray(schema.items) ? schema.items[0] : schema.items;
130
- if (item) return [makeExampleFromSchema(item, components, visited, depth + 1)];
129
+ const item = isSchemaArray(schema.items) ? schema.items[0] : schema.items;
130
+ if (isSchemaObject(item)) return [makeExampleFromSchema(item, components, visited, depth + 1)];
131
131
  return [];
132
132
  }
133
133
  if (schema.allOf?.length) {
@@ -326,7 +326,7 @@ function makeCodeSampleCurl(method, pathStr, basePath, operation, securityScheme
326
326
  [
327
327
  `curl ${url} \\`,
328
328
  ...remaining.slice(0, -1).map((r) => `${r} \\`),
329
- remaining[remaining.length - 1]
329
+ remaining.at(-1)
330
330
  ].join("\n"),
331
331
  "```"
332
332
  ];
@@ -346,7 +346,7 @@ function resolveOperationParameters(operation, components) {
346
346
  });
347
347
  }
348
348
  function getPathParameters(openAPI, pathStr) {
349
- const pathItem = openAPI.paths?.[pathStr];
349
+ const pathItem = (isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {})[pathStr];
350
350
  if (!pathItem?.parameters) return [];
351
351
  return pathItem.parameters.flatMap((parameter) => {
352
352
  if ("$ref" in parameter && parameter.$ref) {
@@ -388,12 +388,12 @@ function flattenBodyParams(schema, components, prefix, visited = /* @__PURE__ */
388
388
  required: requiredSet.has(key),
389
389
  description: propSchema.description ?? "none"
390
390
  };
391
- if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenBodyParams(propSchema, components, (prefix ? `${prefix}»` : "»»").replace(/»/g, "» "), visited, depth + 1)];
391
+ if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenBodyParams(propSchema, components, (prefix ? `${prefix}»` : "»»").replaceAll("»", "» "), visited, depth + 1)];
392
392
  if (propSchema.$ref) {
393
393
  if (visited.has(propSchema.$ref)) return [row];
394
394
  visited.add(propSchema.$ref);
395
395
  const innerResolved = resolveRef(propSchema.$ref, components);
396
- if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenBodyParams(innerResolved, components, (prefix ? `${prefix}»` : "»»").replace(/»/g, "» "), visited, depth + 1)];
396
+ if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenBodyParams(innerResolved, components, (prefix ? `${prefix}»` : "»»").replaceAll("»", "» "), visited, depth + 1)];
397
397
  }
398
398
  return [row];
399
399
  });
@@ -495,7 +495,7 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
495
495
  restrictions: "none",
496
496
  description: propSchema.description ?? "none"
497
497
  };
498
- const nestedPrefix = (prefix ? `${prefix}»` : "»").replace(/»/g, "» ").trimEnd();
498
+ const nestedPrefix = (prefix ? `${prefix}»` : "»").replaceAll("»", "» ").trimEnd();
499
499
  if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenResponseSchemaFields(propSchema, components, nestedPrefix, visited, depth + 1)];
500
500
  if (propSchema.$ref) {
501
501
  if (visited.has(propSchema.$ref)) return [row];
@@ -504,8 +504,8 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
504
504
  if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenResponseSchemaFields(innerResolved, components, nestedPrefix, visited, depth + 1)];
505
505
  }
506
506
  if (propSchema.type === "array" && propSchema.items) {
507
- const itemSchema = Array.isArray(propSchema.items) ? propSchema.items[0] : propSchema.items;
508
- if (itemSchema) {
507
+ const itemSchema = isSchemaArray(propSchema.items) ? propSchema.items[0] : propSchema.items;
508
+ if (isSchemaObject(itemSchema)) {
509
509
  const resolvedItem = resolveArrayItem(itemSchema, components, visited);
510
510
  if (resolvedItem.type === "object" && resolvedItem.properties) return [row, ...flattenResponseSchemaFields(resolvedItem, components, nestedPrefix, visited, depth + 1)];
511
511
  }
@@ -514,8 +514,8 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
514
514
  });
515
515
  }
516
516
  if (schema.type === "array" && schema.items) {
517
- const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
518
- if (itemSchema) {
517
+ const itemSchema = isSchemaArray(schema.items) ? schema.items[0] : schema.items;
518
+ if (isSchemaObject(itemSchema)) {
519
519
  const anonRow = {
520
520
  name: "*anonymous*",
521
521
  type: `[${formatSchemaType(itemSchema)}]`,
@@ -652,8 +652,8 @@ function makeSchemasSection(schemas, components) {
652
652
  return lines;
653
653
  }
654
654
  function collectEndpoints(openAPI) {
655
- if (!openAPI.paths) return [];
656
- return Object.entries(openAPI.paths).flatMap(([pathStr, pathItem]) => {
655
+ const paths = isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {};
656
+ return Object.entries(paths).flatMap(([pathStr, pathItem]) => {
657
657
  if (!pathItem) return [];
658
658
  return HTTP_METHODS.flatMap((method) => {
659
659
  const operation = pathItem[method];
@@ -1,4 +1,4 @@
1
- import { a as writeFile, t as mkdir } from "./fsp-BXry-Hx5.js";
1
+ import { i as writeFile, t as mkdir } from "./fsp-BxW8iutq.js";
2
2
  import { format } from "oxfmt";
3
3
  //#region src/format/index.ts
4
4
  const defaultConfig = {
@@ -1,23 +1,5 @@
1
1
  import fsp from "node:fs/promises";
2
2
  //#region src/fsp/index.ts
3
- async function unlink(path) {
4
- try {
5
- await fsp.unlink(path);
6
- return {
7
- ok: true,
8
- value: void 0
9
- };
10
- } catch (e) {
11
- if (e instanceof Error && "code" in e && e.code === "ENOENT") return {
12
- ok: true,
13
- value: void 0
14
- };
15
- return {
16
- ok: false,
17
- error: e instanceof Error ? e.message : String(e)
18
- };
19
- }
20
- }
21
3
  async function mkdir(dir) {
22
4
  try {
23
5
  await fsp.mkdir(dir, { recursive: true });
@@ -86,4 +68,4 @@ async function writeFile(path, data) {
86
68
  }
87
69
  }
88
70
  //#endregion
89
- export { writeFile as a, unlink as i, readFile as n, readdir as r, mkdir as t };
71
+ export { writeFile as i, readFile as n, readdir as r, mkdir as t };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../../index-BDBsbJIq.js";
2
2
  //#region src/generator/zod-openapi-hono/openapi/index.d.ts
3
3
  declare function zodOpenAPIHono(openapi: OpenAPI, options: {
4
4
  readonly readonly?: boolean;
@@ -1,2 +1,2 @@
1
- import { t as zodOpenAPIHono } from "../../../openapi-QvfGV6Gp.js";
1
+ import { t as zodOpenAPIHono } from "../../../openapi-DvDCtFfn.js";
2
2
  export { zodOpenAPIHono };
@@ -1,6 +1,6 @@
1
- import { t as emit } from "./emit-CFR63U4L.js";
2
- import { N as methodPath, R as toIdentifierPascalCase, c as isOperationLike, f as isRecord, o as isOpenAPIPaths, w as capitalize } from "./guard-C_eRJ0au.js";
3
- import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-BDZmSva1.js";
1
+ import { t as emit } from "./emit-rUfH9f6q.js";
2
+ import { D as isOpenAPIPaths, L as isRecord, d as methodPath, g as toIdentifierPascalCase, k as isOperationLike, n as capitalize } from "./utils-D1npWaGs.js";
3
+ import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-BefI0iar.js";
4
4
  import path from "node:path";
5
5
  //#region src/helper/query.ts
6
6
  function makeHookName(method, pathStr, prefix) {
@@ -28,15 +28,6 @@ function makeInfiniteQueryKeyGetterName(method, pathStr, isSWR) {
28
28
  if (isSWR) return `get${capitalize(methodPath(method, pathStr))}InfiniteKey`;
29
29
  return `get${capitalize(methodPath("", pathStr))}InfiniteQueryKey`;
30
30
  }
31
- function makeQueryOptionsGetterName(pathStr) {
32
- return `get${capitalize(methodPath("", pathStr))}QueryOptions`;
33
- }
34
- function makeInfiniteQueryOptionsGetterName(pathStr) {
35
- return `get${capitalize(methodPath("", pathStr))}InfiniteQueryOptions`;
36
- }
37
- function makeMutationOptionsGetterName(method, pathStr) {
38
- return `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
39
- }
40
31
  function makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeader = false) {
41
32
  const prefix = honoPath.replace(/^\//, "").split("/")[0];
42
33
  if (config.isVueQuery) {
@@ -360,7 +351,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
360
351
  const runtimeAccess = makeRuntimeAccess(clientName, method, pathStr);
361
352
  const responseType = makeResponseTypeFromClient(clientName, method, pathStr);
362
353
  const hasNoContent = hasNoContentResponse(op);
363
- const honoPath = pathStr.replace(/\{([^}]+)\}/g, ":$1");
354
+ const honoPath = pathStr.replaceAll(/\{([^}]+)\}/g, ":$1");
364
355
  if (config.isSWR) {
365
356
  if (isQuery) {
366
357
  const keyGetterName = makeQueryKeyGetterName(method, pathStr, true);
@@ -397,12 +388,12 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
397
388
  const queryHookName = makeHookName("", pathStr, config.hookPrefix);
398
389
  const pathFuncName = methodPath("", pathStr);
399
390
  const keyGetterName = makeQueryKeyGetterName(method, pathStr);
400
- const optionsGetterName = makeQueryOptionsGetterName(pathStr);
391
+ const optionsGetterName = `get${capitalize(methodPath("", pathStr))}QueryOptions`;
401
392
  const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeaderArgs);
402
393
  const optionsGetterCode = makeQueryOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, argsType, runtimeAccess, config);
403
394
  const hookCode = makeQueryHookCode(queryHookName, keyGetterName, runtimeAccess, hasArgs, argsType, responseType, config);
404
395
  const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr);
405
- const infiniteOptionsGetterName = makeInfiniteQueryOptionsGetterName(pathStr);
396
+ const infiniteOptionsGetterName = `get${capitalize(methodPath("", pathStr))}InfiniteQueryOptions`;
406
397
  const { infiniteQueryFn, useInfiniteQueryOptionsType } = config;
407
398
  const hasInfinite = !!(infiniteQueryFn && useInfiniteQueryOptionsType) && hasPagination;
408
399
  const infiniteKeyGetterCode = hasInfinite ? makeInfiniteQueryKeyGetterCode(infiniteKeyGetterName, hasArgs, argsType, honoPath, config, hasHeaderArgs) : null;
@@ -452,7 +443,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
452
443
  operationFileName
453
444
  };
454
445
  }
455
- const optionsGetterName = makeMutationOptionsGetterName(method, pathStr);
446
+ const optionsGetterName = `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
456
447
  return {
457
448
  code: `${makeMutationOptionsGetterCode(optionsGetterName, hasArgs, argsType, runtimeAccess, method, honoPath, responseType, hasNoContent, config)}\n\n${makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent)}`,
458
449
  isQuery: false,
@@ -555,7 +546,7 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
555
546
  const prefixBody = prefixKeyCodes.join("\n\n");
556
547
  const hookBody = hookCodes.map(({ code }) => code).join("\n\n");
557
548
  const body = prefixBody + (prefixBody && hookBody ? "\n\n" : "") + hookBody;
558
- const code = `${makeHeader(importPath, clientName, hookCodes.some(({ isQuery }) => isQuery), hookCodes.some(({ isQuery }) => !isQuery), hasAnyArgs, config, hookCodes.some(({ isQuery, hasArgs }) => isQuery && hasArgs), hookCodes.some(({ hasInfinite }) => hasInfinite))}${body}${hookCodes.length ? "\n" : ""}`;
549
+ const code = `${makeHeader(importPath, clientName, hookCodes.some(({ isQuery }) => isQuery), hookCodes.some(({ isQuery }) => !isQuery), hasAnyArgs, config, hookCodes.some(({ isQuery, hasArgs }) => isQuery && hasArgs), hookCodes.some(({ hasInfinite }) => hasInfinite))}${body}${hookCodes.length > 0 ? "\n" : ""}`;
559
550
  const emitResult = await emit(code, path.dirname(output), output);
560
551
  if (!emitResult.ok) return {
561
552
  ok: false,
@@ -563,12 +554,12 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
563
554
  };
564
555
  return {
565
556
  ok: true,
566
- value: `Generated ${config.frameworkName.toLowerCase().replace(/ /g, "-")} hooks written to ${output}`
557
+ value: `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${output}`
567
558
  };
568
559
  }
569
560
  const { outDir, indexPath } = resolveSplitOutDir(output);
570
- const keysCode = prefixKeyCodes.length ? `${prefixKeyCodes.join("\n\n")}\n` : "";
571
- const exportLines = Array.from(new Set(hookCodes.map(({ operationFileName }) => `export * from './${operationFileName}'`)));
561
+ const keysCode = prefixKeyCodes.length > 0 ? `${prefixKeyCodes.join("\n\n")}\n` : "";
562
+ const exportLines = [...new Set(hookCodes.map(({ operationFileName }) => `export * from './${operationFileName}'`))];
572
563
  const index = `${(keysCode ? [`export * from './keys'`, ...exportLines] : exportLines).join("\n")}\n`;
573
564
  const e = (await Promise.all([
574
565
  ...hookCodes.map(({ operationFileName, code, isQuery, hasArgs, hasInfinite }) => {
@@ -582,7 +573,7 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
582
573
  if (e) return e;
583
574
  return {
584
575
  ok: true,
585
- value: `Generated ${config.frameworkName.toLowerCase().replace(/ /g, "-")} hooks written to ${outDir}/*.ts (index.ts included)`
576
+ value: `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${outDir}/*.ts (index.ts included)`
586
577
  };
587
578
  }
588
579
  //#endregion
@@ -1,7 +1,5 @@
1
- import SwaggerParser from "@apidevtools/swagger-parser";
2
1
  //#region src/openapi/index.d.ts
3
- type BaseOpenAPI = Awaited<ReturnType<typeof SwaggerParser.bundle>>;
4
- type OpenAPI = BaseOpenAPI & {
2
+ type OpenAPI = {
5
3
  readonly openapi?: string;
6
4
  readonly $self?: string;
7
5
  readonly info?: {
@@ -40,8 +38,6 @@ type OpenAPI = BaseOpenAPI & {
40
38
  readonly kind?: string;
41
39
  }[];
42
40
  readonly externalDocs?: ExternalDocs;
43
- } & {
44
- paths: OpenAPIPaths;
45
41
  };
46
42
  type Components = {
47
43
  readonly schemas?: {
@@ -100,18 +96,22 @@ type Components = {
100
96
  readonly [k: string]: Media | Reference;
101
97
  };
102
98
  };
103
- type OAuthFlow = {
104
- readonly implicit?: {
105
- readonly authorizationUrl: string;
106
- readonly deviceAuthorizationUrl: string;
107
- readonly tokenUrl: string;
108
- readonly refreshUrl: string;
109
- readonly scopes: {
110
- readonly [k: string]: string;
111
- };
99
+ type OAuthFlowDetail = {
100
+ readonly authorizationUrl?: string;
101
+ readonly deviceAuthorizationUrl?: string;
102
+ readonly tokenUrl?: string;
103
+ readonly refreshUrl?: string;
104
+ readonly scopes: {
105
+ readonly [k: string]: string;
112
106
  };
113
107
  };
114
- type OpenAPIPaths = { readonly [P in keyof NonNullable<BaseOpenAPI['paths']>]: PathItem; };
108
+ type OAuthFlow = {
109
+ readonly implicit?: OAuthFlowDetail;
110
+ readonly password?: OAuthFlowDetail;
111
+ readonly clientCredentials?: OAuthFlowDetail;
112
+ readonly authorizationCode?: OAuthFlowDetail;
113
+ readonly deviceAuthorization?: OAuthFlowDetail;
114
+ };
115
115
  type Type = 'string' | 'number' | 'integer' | 'date' | 'boolean' | 'array' | 'object' | 'null';
116
116
  type Format = FormatString | FormatNumber;
117
117
  type FormatString = 'email' | 'uuid' | 'uuidv4' | 'uuidv6' | 'uuidv7' | 'url' | 'uri' | 'httpUrl' | 'hostname' | 'hex' | 'jwt' | 'emoji' | 'base64' | 'base64url' | 'nanoid' | 'cuid' | 'cuid2' | 'ulid' | 'ipv4' | 'ipv6' | 'cidrv4' | 'cidrv6' | 'date' | 'time' | 'date-time' | 'duration' | 'binary' | 'byte' | 'password' | 'mac' | 'hash' | 'e164' | 'guid' | 'toLowerCase' | 'toUpperCase' | 'trim';
@@ -213,11 +213,7 @@ type Operation = {
213
213
  readonly [k: string]: Responses;
214
214
  };
215
215
  readonly callbacks?: {
216
- readonly [k: string]: {
217
- readonly $ref?: string;
218
- readonly summary?: string;
219
- readonly description?: string;
220
- };
216
+ readonly [k: string]: Callbacks | Reference;
221
217
  };
222
218
  readonly deprecated?: boolean;
223
219
  readonly security?: readonly {
package/dist/index.js CHANGED
@@ -186,11 +186,10 @@ const ConfigSchema = z.object({
186
186
  "mediaTypes"
187
187
  ].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) => {
188
188
  if (v.template?.define !== true || v.components?.output === void 0) return true;
189
- const normalize = (p) => p.replace(/^\.\//, "");
190
- const componentsOutput = normalize(v.components.output);
189
+ const componentsOutput = v.components.output.replace(/^\.\//, "");
191
190
  const container = componentsOutput.endsWith("/index.ts") ? componentsOutput.slice(0, -9) : componentsOutput;
192
191
  const anchor = container.includes("/") ? container.slice(0, container.lastIndexOf("/")) : "";
193
- const appEntry = normalize(v.output ?? (anchor === "" || anchor === "." ? "index.ts" : `${anchor}/index.ts`));
192
+ const appEntry = (v.output ?? (anchor === "" || anchor === "." ? "index.ts" : `${anchor}/index.ts`)).replace(/^\.\//, "");
194
193
  if (!appEntry.endsWith("index.ts")) return true;
195
194
  const baseDir = appEntry === "index.ts" ? "" : appEntry.slice(0, -9);
196
195
  const routesDir = baseDir === "" ? "routes" : `${baseDir}/routes`;