hono-takibi 0.9.99991 → 0.9.99993

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.
@@ -163,7 +163,7 @@ function makeParameterSchema(parameter) {
163
163
  }
164
164
  function makeSchemaTypeString(schema, components, visited) {
165
165
  if (!schema) return "unknown";
166
- if (schema.$ref) return visited.has(schema.$ref) ? "unknown" : makeRefTypeString(schema.$ref, components, new Set([...visited, schema.$ref]));
166
+ if (schema.$ref) return visited.has(schema.$ref) ? "unknown" : makeRefTypeString(schema.$ref, components, /* @__PURE__ */ new Set([...visited, schema.$ref]));
167
167
  if (schema.oneOf && schema.oneOf.length > 0) return schema.oneOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
168
168
  if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
169
169
  if (schema.allOf && schema.allOf.length > 0) return makeAllOfTypeString(schema.allOf, components, visited);
@@ -228,7 +228,7 @@ function makeAllOfTypeString(allOf, components, visited) {
228
228
  }
229
229
  function makePropertyMap(schema, components, visited) {
230
230
  if (schema.$ref && visited.has(schema.$ref)) return /* @__PURE__ */ new Map();
231
- const nextVisited = schema.$ref ? new Set([...visited, schema.$ref]) : visited;
231
+ const nextVisited = schema.$ref ? /* @__PURE__ */ new Set([...visited, schema.$ref]) : visited;
232
232
  const resolved = makeResolvedSchema(schema, components);
233
233
  const fromAllOf = new Map(resolved.allOf && resolved.allOf.length > 0 ? resolved.allOf.flatMap((subSchema) => [...makePropertyMap(subSchema, components, nextVisited).entries()]) : []);
234
234
  if (!resolved.properties) return fromAllOf;
@@ -1,2 +1,2 @@
1
- import { t as zodOpenAPIHono } from "../../../openapi-Lc8kequ9.js";
1
+ import { t as zodOpenAPIHono } from "../../../openapi-8ZYAMj_e.js";
2
2
  export { zodOpenAPIHono };
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-B8mI7vUM.js";
4
+ import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-DC4zuL9A.js";
5
5
  import { existsSync } from "node:fs";
6
6
  import { resolve } from "node:path";
7
7
  //#region src/cli/index.ts
@@ -47,7 +47,7 @@ function makeImports(code, fromFile, components, split = false, honoExtras = [])
47
47
  const grouped = Array.from(code.matchAll(SCAN), (m) => m[1]).filter((name) => Boolean(name) && !defined.has(name)).reduce((acc, name) => {
48
48
  const kind = classifyRef(name);
49
49
  if (!kind) return acc;
50
- return new Map(acc).set(kind, new Set([...acc.get(kind) ?? [], name]));
50
+ return new Map(acc).set(kind, /* @__PURE__ */ new Set([...acc.get(kind) ?? [], name]));
51
51
  }, /* @__PURE__ */ new Map());
52
52
  const needsCreateRoute = code.includes("createRoute(");
53
53
  const needsZ = code.includes("z.");
@@ -358,7 +358,7 @@ function makePathItem(pathItem) {
358
358
  //#endregion
359
359
  //#region src/helper/wrap.ts
360
360
  function wrap(zod, schema, meta, options) {
361
- const unsupportedProps = new Set([
361
+ const unsupportedProps = /* @__PURE__ */ new Set([
362
362
  "$recursiveRef",
363
363
  "$recursiveAnchor",
364
364
  "optional",
@@ -395,7 +395,8 @@ function wrap(zod, schema, meta, options) {
395
395
  if (typeof v === "string") return JSON.stringify(v);
396
396
  return JSON.stringify(v);
397
397
  };
398
- const n = schema.nullable === true || (Array.isArray(schema.type) ? schema.type.includes("null") : schema.type === "null") ? `${zod}.nullable()` : zod;
398
+ const isNullable = schema.nullable === true || (Array.isArray(schema.type) ? schema.type.includes("null") : schema.type === "null");
399
+ const n = isNullable ? `${zod}.nullable()` : zod;
399
400
  const d = schema.default !== void 0 ? `${n}.default(${formatLiteral(schema.default)})` : n;
400
401
  const pf = schema["x-prefault"] !== void 0 ? `${d}.prefault(${formatLiteral(schema["x-prefault"])})` : d;
401
402
  const c = schema["x-catch"] !== void 0 ? `${pf}.catch(${formatLiteral(schema["x-catch"])})` : pf;
@@ -406,7 +407,7 @@ function wrap(zod, schema, meta, options) {
406
407
  const codec = schema["x-codec"];
407
408
  const replaced = preprocess ?? transform ?? pipe ?? codec ?? superRefineChain;
408
409
  const z = schema["x-brand"] ? `${replaced}.brand<"${schema["x-brand"]}">()` : replaced;
409
- const zodExpressedProps = new Set([
410
+ const zodExpressedProps = /* @__PURE__ */ new Set([
410
411
  "type",
411
412
  "format",
412
413
  "default",
@@ -556,9 +557,12 @@ function wrap(zod, schema, meta, options) {
556
557
  return `${JSON.stringify(key)}:${JSON.stringify(value)}`;
557
558
  }).join(",")}}`;
558
559
  };
560
+ const typeList = Array.isArray(schema.type) ? schema.type : schema.type !== void 0 ? [schema.type] : [];
561
+ const fileMetaProps = schema.format === "binary" && typeList.includes("string") && schema.contentEncoding === void 0 && schema.contentMediaType === void 0 && schema.contentSchema === void 0 && schema["x-codec"] === void 0 ? [isNullable ? "type:[\"string\",\"null\"]" : "type:\"string\"", "format:\"binary\""] : [];
559
562
  const result = [
560
563
  meta?.parameters ? `param:${serializeParam(meta.parameters)}` : void 0,
561
564
  ...headerMetaProps,
565
+ ...fileMetaProps,
562
566
  openapiSchemaBody && openapiSchemaBody.length > 0 ? openapiSchemaBody : void 0
563
567
  ].filter((v) => v !== void 0);
564
568
  if (meta?.parameters || meta?.headers) {
@@ -1220,12 +1224,12 @@ const FORMAT_STRING = {
1220
1224
  toUpperCase: "toUpperCase()",
1221
1225
  trim: "trim()"
1222
1226
  };
1223
- const TRANSFORM_FORMATS = new Set([
1227
+ const TRANSFORM_FORMATS = /* @__PURE__ */ new Set([
1224
1228
  "toLowerCase",
1225
1229
  "toUpperCase",
1226
1230
  "trim"
1227
1231
  ]);
1228
- const DATE_FORMATS = new Set(["date", "date-time"]);
1232
+ const DATE_FORMATS = /* @__PURE__ */ new Set(["date", "date-time"]);
1229
1233
  const EMAIL_PATTERN_PRESET = {
1230
1234
  html5: "html5Email",
1231
1235
  rfc5322: "rfc5322Email",
@@ -1670,7 +1674,7 @@ function tarjanConnect(name, deps, var2name, state) {
1670
1674
  const indices = new Map(state.indices).set(name, currentIndex);
1671
1675
  const lowLinks = new Map(state.lowLinks).set(name, currentIndex);
1672
1676
  const stack = [...state.stack, name];
1673
- const onStack = new Set([...state.onStack, name]);
1677
+ const onStack = /* @__PURE__ */ new Set([...state.onStack, name]);
1674
1678
  const initialState = {
1675
1679
  ...state,
1676
1680
  indices,
@@ -1734,7 +1738,7 @@ function analyzeCircularSchemas(schemas, schemaNames, readonly) {
1734
1738
  return [n, extractIdentifiers(code, varNameSet).filter((v) => v !== selfVar)];
1735
1739
  }));
1736
1740
  const cyclicSchemas = findCyclicSchemas(schemaNames, depsMap);
1737
- const extendedCyclicSchemas = new Set([...cyclicSchemas, ...[...cyclicSchemas].flatMap((n) => (depsMap.get(n) ?? []).map((v) => varNameToName.get(v)).filter((x) => x !== void 0))]);
1741
+ const extendedCyclicSchemas = /* @__PURE__ */ new Set([...cyclicSchemas, ...[...cyclicSchemas].flatMap((n) => (depsMap.get(n) ?? []).map((v) => varNameToName.get(v)).filter((x) => x !== void 0))]);
1738
1742
  return {
1739
1743
  zSchemaMap,
1740
1744
  depsMap,
@@ -1801,12 +1805,12 @@ function topoSort(decls) {
1801
1805
  if (!decl) return state;
1802
1806
  const withTemp = {
1803
1807
  ...state,
1804
- temp: new Set([...state.temp, key])
1808
+ temp: /* @__PURE__ */ new Set([...state.temp, key])
1805
1809
  };
1806
1810
  const afterRefs = decl.refs.map((ref) => findByName(ref)).filter((d) => d !== void 0).reduce((s, d) => visit(makeKey(d.kind, d.name), s), withTemp);
1807
1811
  return {
1808
1812
  sorted: [...afterRefs.sorted, decl],
1809
- perm: new Set([...afterRefs.perm, key]),
1813
+ perm: /* @__PURE__ */ new Set([...afterRefs.perm, key]),
1810
1814
  temp: new Set([...afterRefs.temp].filter((t) => t !== key))
1811
1815
  };
1812
1816
  };
@@ -1,7 +1,7 @@
1
1
  import { n as fmt, t as emit } from "./emit-CFR63U4L.js";
2
2
  import { a as writeFile, i as unlink, n as readFile, r as readdir, t as mkdir } from "./fsp-BXry-Hx5.js";
3
3
  import { I as statusCodeToNumber, L as toIdentifierPascalCase, M as methodPath, O as escapeRegexLiteral, P as renderNamedImport, R as uncapitalize, T as ensureSuffix, b as isSecurityScheme, i as isMediaWithSchema, k as makeBarrel, l as isParameter, n as isHttpMethod, p as isRefObject, s as isOperation, t as isContentBody, y as isSecurityArray, z as zodToOpenAPISchema } from "./guard-zvkMUVYD.js";
4
- import { S as makeModuleSpec, _ as makeRef, a as responsesCode, b as makeExportConst, c as headersCode, d as ast, f as zodToOpenAPI, g as makePathItem, h as makeOperationResponses, i as schemasCode, l as makeSplitSchemaFile, m as makeCallbacks, n as routeCode, o as requestBodiesCode, p as makeCallback, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as analyzeCircularSchemas, v as makeRequest, x as makeImports, y as makeConst } from "./openapi-Lc8kequ9.js";
4
+ import { S as makeModuleSpec, _ as makeRef, a as responsesCode, b as makeExportConst, c as headersCode, d as ast, f as zodToOpenAPI, g as makePathItem, h as makeOperationResponses, i as schemasCode, l as makeSplitSchemaFile, m as makeCallbacks, n as routeCode, o as requestBodiesCode, p as makeCallback, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as analyzeCircularSchemas, v as makeRequest, x as makeImports, y as makeConst } from "./openapi-8ZYAMj_e.js";
5
5
  import { t as hooks } from "./hooks-CkiatAe9.js";
6
6
  import { t as docs } from "./docs-380Wcu6a.js";
7
7
  import { rpc } from "./core/rpc/index.js";
@@ -560,6 +560,53 @@ const PROPERTY_NAME_TO_FAKER = {
560
560
  count: "faker.number.int({ min: 0, max: 1000 })",
561
561
  age: "faker.number.int({ min: 1, max: 120 })"
562
562
  };
563
+ const hasNumericConstraint = (schema) => schema.minimum !== void 0 || schema.maximum !== void 0 || schema.exclusiveMinimum !== void 0 || schema.exclusiveMaximum !== void 0 || schema.multipleOf !== void 0;
564
+ function numericRange(schema, integer) {
565
+ const step = integer ? 1 : 0;
566
+ const min = typeof schema.exclusiveMinimum === "number" ? schema.exclusiveMinimum + step : schema.exclusiveMinimum === true && schema.minimum !== void 0 ? schema.minimum + step : schema.minimum;
567
+ const max = typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum - step : schema.exclusiveMaximum === true && schema.maximum !== void 0 ? schema.maximum - step : schema.maximum;
568
+ return {
569
+ ...min !== void 0 ? { min } : {},
570
+ ...max !== void 0 ? { max } : {},
571
+ ...schema.multipleOf !== void 0 ? { multipleOf: schema.multipleOf } : {}
572
+ };
573
+ }
574
+ function numericFaker(schema, range) {
575
+ if (schema.type === "integer" && (schema.format === "int64" || schema.format === "bigint")) return `faker.number.bigInt({ min: ${range.min ?? 0}n, max: ${range.max ?? 9007199254740991}n })`;
576
+ if (schema.type === "integer") {
577
+ const defaultMin = schema.format === "int32" ? -2147483648 : 1;
578
+ const defaultMax = schema.format === "int32" ? 2147483647 : 1e3;
579
+ return `faker.number.int({ ${[
580
+ `min: ${range.min ?? defaultMin}`,
581
+ `max: ${range.max ?? defaultMax}`,
582
+ ...range.multipleOf !== void 0 ? [`multipleOf: ${range.multipleOf}`] : []
583
+ ].join(", ")} })`;
584
+ }
585
+ const defaultMax = schema.format === "double" ? 1e6 : 1e3;
586
+ const fractionDigits = schema.format === "double" ? 4 : 2;
587
+ return `faker.number.float({ ${(range.multipleOf !== void 0 ? [
588
+ `min: ${range.min ?? 1}`,
589
+ `max: ${range.max ?? defaultMax}`,
590
+ `multipleOf: ${range.multipleOf}`
591
+ ] : [
592
+ `min: ${range.min ?? 1}`,
593
+ `max: ${range.max ?? defaultMax}`,
594
+ `fractionDigits: ${fractionDigits}`
595
+ ]).join(", ")} })`;
596
+ }
597
+ function resolveRef(schema, schemas) {
598
+ if (!schema.$ref) return schema;
599
+ const name = schema.$ref.split("/").at(-1);
600
+ return (name ? schemas?.[name] : void 0) ?? schema;
601
+ }
602
+ function isKnownScalar(schema, schemas) {
603
+ const resolved = resolveRef(schema, schemas);
604
+ if (resolved.enum || resolved.const !== void 0) return true;
605
+ if (resolved.properties || resolved.type === "object") return false;
606
+ if (resolved.allOf && resolved.allOf.length > 0) return resolved.allOf.every((s) => isKnownScalar(s, schemas));
607
+ if (resolved.oneOf || resolved.anyOf || resolved.type === "array") return false;
608
+ return typeof resolved.type === "string";
609
+ }
563
610
  function schemaToFaker(schema, propertyName, options = {}) {
564
611
  if (options.useExamples && schema.example !== void 0) return JSON.stringify(schema.example);
565
612
  if (schema.const !== void 0) return `${JSON.stringify(schema.const)} as const`;
@@ -582,12 +629,24 @@ function schemaToFaker(schema, propertyName, options = {}) {
582
629
  if (schema.type === "object" && schema.properties) return `{ ${renderProps(schema.properties, schema.required)} }`;
583
630
  if (schema.type === "object" && !schema.properties && schema.additionalProperties) return "{}";
584
631
  if (schema.allOf && schema.allOf.length > 0) {
585
- const merged = schema.allOf.map((s) => schemaToFaker(s, propertyName, options)).map((m) => `...${m}`).join(", ");
586
- if (schema.properties) return `{ ${merged}, ${renderProps(schema.properties, schema.required)} }`;
632
+ if (!schema.properties && schema.allOf.every((s) => isKnownScalar(s, options.schemas))) {
633
+ const [only] = schema.allOf;
634
+ if (schema.allOf.length === 1 && only) return schemaToFaker(only, propertyName, options);
635
+ return schemaToFaker(schema.allOf.map((s) => resolveRef(s, options.schemas)).reduce((acc, s) => ({
636
+ ...acc,
637
+ ...s
638
+ }), {}), propertyName, options);
639
+ }
640
+ const merged = schema.allOf.filter((s) => !isKnownScalar(s, options.schemas)).map((s) => `...${schemaToFaker(s, propertyName, options)}`).join(", ");
641
+ if (schema.properties) {
642
+ const props = renderProps(schema.properties, schema.required);
643
+ return merged.length > 0 ? `{ ${merged}, ${props} }` : `{ ${props} }`;
644
+ }
587
645
  return `{ ${merged} }`;
588
646
  }
589
647
  const union = schema.oneOf && schema.oneOf.length > 0 ? schema.oneOf : schema.anyOf && schema.anyOf.length > 0 ? schema.anyOf : void 0;
590
648
  if (union) return `faker.helpers.arrayElement([${union.map((s) => schemaToFaker(s, propertyName, options)).join(", ")}])`;
649
+ if ((schema.type === "integer" || schema.type === "number") && hasNumericConstraint(schema)) return numericFaker(schema, numericRange(schema, schema.type === "integer"));
591
650
  if (schema.format && FORMAT_TO_FAKER[schema.format]) return FORMAT_TO_FAKER[schema.format];
592
651
  if (propertyName && PROPERTY_NAME_TO_FAKER[propertyName]) {
593
652
  const hint = PROPERTY_NAME_TO_FAKER[propertyName];
@@ -598,12 +657,7 @@ function schemaToFaker(schema, propertyName, options = {}) {
598
657
  if (schema.pattern) return `faker.helpers.fromRegExp(/${escapeRegexLiteral(schema.pattern)}/)`;
599
658
  return `faker.string.alpha({ length: { min: ${schema.minLength ?? 5}, max: ${schema.maxLength ?? 20} } })`;
600
659
  }
601
- if (schema.type === "integer" || schema.type === "number") {
602
- const min = schema.minimum ?? 1;
603
- const max = schema.maximum ?? 1e3;
604
- if (schema.type === "integer") return `faker.number.int({ min: ${min}, max: ${max} })`;
605
- return `faker.number.float({ min: ${min}, max: ${max}, fractionDigits: 2 })`;
606
- }
660
+ if (schema.type === "integer" || schema.type === "number") return numericFaker(schema, numericRange(schema, schema.type === "integer"));
607
661
  return TYPE_TO_FAKER[schema.type];
608
662
  }
609
663
  return "undefined";
@@ -680,11 +734,37 @@ function detectCircularSchemas$1(schemas) {
680
734
  }
681
735
  return circular;
682
736
  }
737
+ function collectSchemaRefs$1(node, refs) {
738
+ if (Array.isArray(node)) {
739
+ for (const item of node) collectSchemaRefs$1(item, refs);
740
+ return refs;
741
+ }
742
+ if (node !== null && typeof node === "object") for (const [key, value] of Object.entries(node)) if (key === "$ref" && typeof value === "string" && value.includes("/components/schemas/")) {
743
+ const name = value.split("/").at(-1);
744
+ if (name) refs.add(name);
745
+ } else collectSchemaRefs$1(value, refs);
746
+ return refs;
747
+ }
748
+ function schemaClosure(roots, schemas) {
749
+ const used = /* @__PURE__ */ new Set();
750
+ const stack = [...roots];
751
+ while (stack.length > 0) {
752
+ const name = stack.pop();
753
+ if (name === void 0 || used.has(name)) continue;
754
+ used.add(name);
755
+ const schema = schemas[name];
756
+ if (schema) {
757
+ for (const ref of collectSchemaRefs$1(schema, /* @__PURE__ */ new Set())) if (!used.has(ref)) stack.push(ref);
758
+ }
759
+ }
760
+ return used;
761
+ }
683
762
  function makeMockFunction(name, schema, schemas, isCircular) {
684
763
  const mockBody = schemaToFaker(schema, void 0, { schemas });
685
764
  const returnType = isCircular ? ": any" : "";
686
765
  const sanitized = name.replace(/\./g, "");
687
- return `function mock${sanitized}()${returnType}{return ${schema["x-brand"] ? `${mockBody} as z.infer<typeof ${sanitized}Schema>` : mockBody}}`;
766
+ const schemaConst = toIdentifierPascalCase(ensureSuffix(name, "Schema"));
767
+ return `function mock${sanitized}()${returnType}{return ${schema["x-brand"] ? `${mockBody} as z.infer<typeof ${schemaConst}>` : mockBody}}`;
688
768
  }
689
769
  function extractSecurityInfo(opSecurity, globalSecurity, securitySchemes) {
690
770
  return (opSecurity ?? globalSecurity ?? []).flatMap((secDef) => Object.keys(secDef).flatMap((schemeName) => {
@@ -804,7 +884,67 @@ function makeAuthCheck(security, has401) {
804
884
  if (authChecks.length === 0) return "";
805
885
  return `if(!(${authChecks.join(" || ")})){return c.json({ message: 'Unauthorized' }, 401)}`;
806
886
  }
807
- function makeHandlerBody(statusCode, jsonSchema, textSchema, schemas, allRefs) {
887
+ function extractMediaExample(media, components) {
888
+ if (media.example !== void 0) return media.example;
889
+ if (!media.examples) return void 0;
890
+ const first = Object.values(media.examples)[0];
891
+ if (!first) return void 0;
892
+ if ("$ref" in first && typeof first.$ref === "string") {
893
+ const name = first.$ref.split("/").at(-1);
894
+ const resolved = name ? components?.examples?.[name] : void 0;
895
+ return resolved && "value" in resolved ? resolved.value : void 0;
896
+ }
897
+ return "value" in first ? first.value : void 0;
898
+ }
899
+ const PAGE_PARAM_NAMES = [
900
+ "page",
901
+ "pageNumber",
902
+ "page_number"
903
+ ];
904
+ const OFFSET_PARAM_NAMES = ["offset", "skip"];
905
+ const ROWS_PARAM_NAMES = [
906
+ "rows",
907
+ "limit",
908
+ "perPage",
909
+ "per_page",
910
+ "pageSize",
911
+ "page_size",
912
+ "size",
913
+ "take"
914
+ ];
915
+ function detectPagination(operation) {
916
+ if (operation["x-pagination"] !== true) return void 0;
917
+ const queryParams = (operation.parameters ?? []).filter((p) => "in" in p && p.in === "query");
918
+ const rows = queryParams.find((p) => ROWS_PARAM_NAMES.includes(p.name));
919
+ if (!rows) return void 0;
920
+ const pageParam = queryParams.find((p) => PAGE_PARAM_NAMES.includes(p.name));
921
+ const offsetParam = pageParam ? void 0 : queryParams.find((p) => OFFSET_PARAM_NAMES.includes(p.name));
922
+ const cursor = pageParam ?? offsetParam;
923
+ if (!cursor) return void 0;
924
+ const defaultRows = typeof rows.schema?.default === "number" ? rows.schema.default : 20;
925
+ return {
926
+ rowsParam: rows.name,
927
+ cursorParam: cursor.name,
928
+ offsetStyle: offsetParam !== void 0,
929
+ defaultRows
930
+ };
931
+ }
932
+ function makeHandlerBody(args) {
933
+ const { statusCode, jsonSchema, textSchema, schemas, allRefs, exampleValue, exampleCast, pagination } = args;
934
+ if (exampleValue !== void 0) {
935
+ const cast = exampleCast ? ` as z.infer<typeof ${exampleCast}>` : "";
936
+ return `return c.json(${JSON.stringify(exampleValue)}${cast}, ${statusCode})`;
937
+ }
938
+ if (pagination && jsonSchema?.type === "array" && jsonSchema.items) {
939
+ collectRefs(jsonSchema, allRefs);
940
+ const itemFaker = schemaToFaker(Array.isArray(jsonSchema.items) ? jsonSchema.items[0] : jsonSchema.items, void 0, { schemas });
941
+ const startExpr = pagination.offsetStyle ? `const start = query.${pagination.cursorParam} ?? 0` : `const page = query.${pagination.cursorParam} ?? 1\nconst start = (page - 1) * rows`;
942
+ return `const query = c.req.valid('query')
943
+ const rows = query.${pagination.rowsParam} ?? ${pagination.defaultRows}
944
+ ${startExpr}
945
+ const items = Array.from({ length: ${pagination.totalConst} }, () => (${itemFaker}))
946
+ return c.json(items.slice(start, start + rows), ${statusCode})`;
947
+ }
808
948
  if (jsonSchema) {
809
949
  collectRefs(jsonSchema, allRefs);
810
950
  return `return c.json(${schemaToFaker(jsonSchema, void 0, { schemas })}, ${statusCode})`;
@@ -830,7 +970,26 @@ function makeMock(openapi, basePath, options = {}) {
830
970
  const successResponse = success?.response;
831
971
  const jsonMedia = successResponse?.content?.["application/json"];
832
972
  const textMedia = successResponse?.content?.["text/plain"];
833
- const handlerBody = makeHandlerBody(statusCode, jsonMedia && isMediaWithSchema(jsonMedia) ? jsonMedia.schema : void 0, textMedia && isMediaWithSchema(textMedia) ? textMedia.schema : void 0, schemas, allRefs);
973
+ const jsonSchema = jsonMedia && isMediaWithSchema(jsonMedia) ? jsonMedia.schema : void 0;
974
+ const textSchema = textMedia && isMediaWithSchema(textMedia) ? textMedia.schema : void 0;
975
+ const exampleValue = jsonMedia ? extractMediaExample(jsonMedia, openapi.components) : void 0;
976
+ const exampleCast = exampleValue !== void 0 && jsonSchema?.$ref ? toIdentifierPascalCase(ensureSuffix(jsonSchema.$ref.split("/").at(-1) ?? "", "Schema")) : void 0;
977
+ const pag = detectPagination(operation);
978
+ const pagination = pag && exampleValue === void 0 && jsonSchema?.type === "array" && jsonSchema.items ? {
979
+ totalConst: `${routeId}Total`,
980
+ ...pag
981
+ } : void 0;
982
+ const handlerBody = makeHandlerBody({
983
+ statusCode,
984
+ jsonSchema,
985
+ textSchema,
986
+ schemas,
987
+ allRefs,
988
+ exampleValue,
989
+ exampleCast,
990
+ pagination
991
+ });
992
+ const paginationDecl = pagination ? `const ${pagination.totalConst} = faker.number.int({ min: 0, max: ${Math.min(pagination.defaultRows * 3, 3e3)} })` : "";
834
993
  const authCheck = makeAuthCheck(security, operation.responses?.[String(401)] !== void 0);
835
994
  const handler = `const ${routeId}RouteHandler: RouteHandler<typeof ${routeId}Route> = async (${handlerBody.includes("c.") || authCheck !== "" ? "c" : "_c"}) => {${authCheck}${handlerBody}}`;
836
995
  return [{
@@ -840,17 +999,34 @@ function makeMock(openapi, basePath, options = {}) {
840
999
  path: p,
841
1000
  requiresAuth
842
1001
  },
843
- handler
1002
+ handler,
1003
+ paginationDecl
844
1004
  }];
845
1005
  }));
846
1006
  const routeMetas = processed.map(({ entry }) => entry);
847
1007
  const handlers = processed.map(({ handler }) => handler);
1008
+ const paginationDecls = processed.flatMap(({ paginationDecl }) => paginationDecl.length > 0 ? [paginationDecl] : []);
848
1009
  const allDeps = /* @__PURE__ */ new Set();
849
1010
  for (const ref of allRefs) collectAllDependencies(ref, schemas, allDeps);
850
1011
  const sortedRefs = topologicalSort(allDeps, schemas);
851
1012
  const circularSchemas = detectCircularSchemas$1(schemas);
852
1013
  const mockFunctions = sortedRefs.filter((refName) => schemas[refName]).map((refName) => makeMockFunction(refName, schemas[refName], schemas, circularSchemas.has(refName)));
853
- const components = openapi.components ? componentsCode(openapi.components, {
1014
+ const rootRefs = collectSchemaRefs$1(filteredOpenapi.paths, /* @__PURE__ */ new Set());
1015
+ if (openapi.components) {
1016
+ collectSchemaRefs$1(openapi.components.responses, rootRefs);
1017
+ collectSchemaRefs$1(openapi.components.parameters, rootRefs);
1018
+ collectSchemaRefs$1(openapi.components.requestBodies, rootRefs);
1019
+ collectSchemaRefs$1(openapi.components.headers, rootRefs);
1020
+ collectSchemaRefs$1(openapi.components.callbacks, rootRefs);
1021
+ collectSchemaRefs$1(openapi.components.pathItems, rootRefs);
1022
+ collectSchemaRefs$1(openapi.components.links, rootRefs);
1023
+ }
1024
+ const usedSchemaNames = schemaClosure(rootRefs, schemas);
1025
+ const filteredComponents = openapi.components ? {
1026
+ ...openapi.components,
1027
+ schemas: Object.fromEntries(Object.entries(schemas).filter(([name]) => usedSchemaNames.has(name)))
1028
+ } : void 0;
1029
+ const components = filteredComponents ? componentsCode(filteredComponents, {
854
1030
  exportSchemasTypes: false,
855
1031
  exportSchemas: false,
856
1032
  exportParametersTypes: false,
@@ -883,6 +1059,7 @@ export default app`;
883
1059
  components,
884
1060
  routes,
885
1061
  mockFunctions.join("\n\n"),
1062
+ paginationDecls.join("\n"),
886
1063
  handlersJoined,
887
1064
  appCode
888
1065
  ].filter((s) => s.length > 0).join("\n\n");
@@ -1115,7 +1292,7 @@ function extractTestCases(spec) {
1115
1292
  } : void 0;
1116
1293
  const bodyRefs = jsonBodySchema ? collectSchemaRefs(jsonBodySchema, spec.components?.schemas) : [];
1117
1294
  const paramRefs = resolvedParams.flatMap((p) => collectSchemaRefs(p.schema, spec.components?.schemas));
1118
- const usedSchemaRefs = [...new Set([...bodyRefs, ...paramRefs])];
1295
+ const usedSchemaRefs = [.../* @__PURE__ */ new Set([...bodyRefs, ...paramRefs])];
1119
1296
  const responseKeys = Object.keys(operation.responses || {});
1120
1297
  const successStatus = responseKeys.filter((s) => s.startsWith("2")).map((s) => Number.parseInt(s, 10)).toSorted((a, b) => a - b)[0] ?? 200;
1121
1298
  const errorStatuses = responseKeys.filter((s) => (s.startsWith("4") || s.startsWith("5")) && s !== "default").map((s) => Number.parseInt(s, 10)).toSorted((a, b) => a - b);
@@ -1177,7 +1354,7 @@ function topologicalOrder(usedSchemaNames, schemas) {
1177
1354
  if (visited.has(name) || !usedSchemaNames.has(name) || visiting.has(name)) return [];
1178
1355
  const nextVisiting = new Set(visiting).add(name);
1179
1356
  const schema = schemas[name];
1180
- const depOrder = schema ? collectSchemaRefs(schema, schemas, new Set([name])).flatMap((dep) => {
1357
+ const depOrder = schema ? collectSchemaRefs(schema, schemas, /* @__PURE__ */ new Set([name])).flatMap((dep) => {
1181
1358
  const subOrder = visit(dep, visited, nextVisiting);
1182
1359
  for (const n of subOrder) visited.add(n);
1183
1360
  return subOrder;
@@ -1778,7 +1955,7 @@ function extractMockFunctions(file, code) {
1778
1955
  * Returns a map of route identifier (e.g., "GET /users") to block info
1779
1956
  * including text and source positions for removal.
1780
1957
  */
1781
- const DESCRIBE_MODIFIERS = new Set([
1958
+ const DESCRIBE_MODIFIERS = /* @__PURE__ */ new Set([
1782
1959
  "skip",
1783
1960
  "only",
1784
1961
  "skipIf",
@@ -1843,7 +2020,7 @@ function mergeTestFile(existingCode, generatedCode) {
1843
2020
  * `vite-plus/test`) would leave duplicate framework imports.
1844
2021
  */
1845
2022
  function filterTestFrameworkImports(mergedImports, generatedFile) {
1846
- const TEST_FRAMEWORK_MODULES = new Set([
2023
+ const TEST_FRAMEWORK_MODULES = /* @__PURE__ */ new Set([
1847
2024
  "vitest",
1848
2025
  "bun:test",
1849
2026
  "vite-plus/test"
@@ -1966,9 +2143,9 @@ function makeMergedHandlers(handlers) {
1966
2143
  if (existing) handlerMap.set(handler.fileName, {
1967
2144
  ...handler,
1968
2145
  contents: [...existing.contents, ...handler.contents],
1969
- routeNames: Array.from(new Set([...existing.routeNames, ...handler.routeNames])),
2146
+ routeNames: Array.from(/* @__PURE__ */ new Set([...existing.routeNames, ...handler.routeNames])),
1970
2147
  needsFaker: existing.needsFaker || handler.needsFaker,
1971
- usedRefs: new Set([...existing.usedRefs, ...handler.usedRefs])
2148
+ usedRefs: /* @__PURE__ */ new Set([...existing.usedRefs, ...handler.usedRefs])
1972
2149
  });
1973
2150
  else handlerMap.set(handler.fileName, handler);
1974
2151
  }
@@ -1,7 +1,7 @@
1
1
  import { parseConfig } from "../config/index.js";
2
2
  import { r as setFormatOptions } from "../emit-CFR63U4L.js";
3
3
  import { f as isRecord } from "../guard-zvkMUVYD.js";
4
- import { n as parseOpenAPI, t as makeJob } from "../shared-B8mI7vUM.js";
4
+ import { n as parseOpenAPI, t as makeJob } from "../shared-DC4zuL9A.js";
5
5
  import path from "node:path";
6
6
  import fsp from "node:fs/promises";
7
7
  //#region src/vite-plugin/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
- "version": "0.9.99991",
3
+ "version": "0.9.99993",
4
4
  "description": "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi",
5
5
  "keywords": [
6
6
  "hono",
@@ -53,24 +53,21 @@
53
53
  "import": "./dist/core/docs/index.js"
54
54
  }
55
55
  },
56
- "publishConfig": {
57
- "access": "public"
58
- },
59
56
  "dependencies": {
60
57
  "@apidevtools/swagger-parser": "^12.1.0",
61
58
  "@typespec/compiler": "^1.13.0",
62
59
  "@typespec/openapi3": "^1.13.0",
63
- "oxfmt": "^0.54.0",
60
+ "oxfmt": "^0.56.0",
64
61
  "ts-morph": "^28.0.0",
65
62
  "typescript": "^6.0.3",
66
63
  "zod": "^4.4.3"
67
64
  },
68
65
  "devDependencies": {
69
- "@types/node": "^25.9.3",
66
+ "@types/node": "^26.0.1",
70
67
  "@typespec/http": "^1.13.0",
71
68
  "@typespec/rest": "^0.83.0",
72
69
  "@typespec/versioning": "^0.83.0",
73
- "tsdown": "0.22.2"
70
+ "tsdown": "0.22.3"
74
71
  },
75
72
  "scripts": {
76
73
  "build": "tsdown"