hono-takibi 0.4.4 → 0.4.5

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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generate Zod gt validation
3
+ *
4
+ * @param minimum - Minimum value
5
+ * @returns Zod gt validation string
6
+ */
7
+ export declare function generateZodGt(minimum: number): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateZodGt = generateZodGt;
4
+ /**
5
+ * Generate Zod gt validation
6
+ *
7
+ * @param minimum - Minimum value
8
+ * @returns Zod gt validation string
9
+ */
10
+ function generateZodGt(minimum) {
11
+ return `.gt(${minimum})`;
12
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generates a Zod length validation string
3
+ *
4
+ * @param length - The length value to validate against
5
+ * @returns The Zod length validation string
6
+ *
7
+ * @example
8
+ * const lengthValidation = generateZodLength(10)
9
+ * // Returns: 'length(10)'
10
+ */
11
+ export declare function generateZodLength(length: number): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateZodLength = generateZodLength;
4
+ /**
5
+ * Generates a Zod length validation string
6
+ *
7
+ * @param length - The length value to validate against
8
+ * @returns The Zod length validation string
9
+ *
10
+ * @example
11
+ * const lengthValidation = generateZodLength(10)
12
+ * // Returns: 'length(10)'
13
+ */
14
+ function generateZodLength(length) {
15
+ return `.length(${length})`;
16
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generate Zod lt validation
3
+ *
4
+ * @param maximum - Maximum value
5
+ * @returns Zod lt validation string
6
+ */
7
+ export declare function generateZodLt(maximum: number): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateZodLt = generateZodLt;
4
+ /**
5
+ * Generate Zod lt validation
6
+ *
7
+ * @param maximum - Maximum value
8
+ * @returns Zod lt validation string
9
+ */
10
+ function generateZodLt(maximum) {
11
+ return `.lt(${maximum})`;
12
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates a zod nullable validation
3
+ *
4
+ * @returns zod nullable
5
+ */
6
+ export declare function generateZodNullable(): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateZodNullable = generateZodNullable;
4
+ /**
5
+ * Generates a zod nullable validation
6
+ *
7
+ * @returns zod nullable
8
+ */
9
+ function generateZodNullable() {
10
+ return '.nullable()';
11
+ }
@@ -1,5 +1,5 @@
1
1
  import type { DefaultValue, ExampleValue } from '../../types';
2
- type GenerateZodNumberSchemaParams = {
2
+ type GenerateZodNumberParams = {
3
3
  pattern?: string;
4
4
  minLength?: number;
5
5
  maxLength?: number;
@@ -13,11 +13,11 @@ type GenerateZodNumberSchemaParams = {
13
13
  isPath?: boolean;
14
14
  };
15
15
  /**
16
- * Generates a zod schema for a number.
16
+ * Generates zod number
17
17
  *
18
- * @function generateZodNumberSchema
19
- * @param args - The parameters to generate the zod schema.
20
- * @returns A zod schema for a number.
18
+ * @function generateZodNumber
19
+ * @param args - zod number params
20
+ * @returns zod number
21
21
  */
22
- export declare function generateZodNumberSchema(args: GenerateZodNumberSchemaParams): string;
22
+ export declare function generateZodNumber(args: GenerateZodNumberParams): string;
23
23
  export {};
@@ -1,41 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateZodNumberSchema = generateZodNumberSchema;
3
+ exports.generateZodNumber = generateZodNumber;
4
4
  const generate_zod_default_1 = require("./generate-zod-default");
5
+ const generate_zod_gt_1 = require("./generate-zod-gt");
6
+ const generate_zod_lt_1 = require("./generate-zod-lt");
5
7
  const generate_zod_max_1 = require("./generate-zod-max");
6
8
  const generate_zod_min_1 = require("./generate-zod-min");
7
9
  const generate_zod_regex_1 = require("./generate-zod-regex");
8
10
  const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
9
11
  /**
10
- * Generates a zod schema for a number.
12
+ * Generates zod number
11
13
  *
12
- * @function generateZodNumberSchema
13
- * @param args - The parameters to generate the zod schema.
14
- * @returns A zod schema for a number.
14
+ * @function generateZodNumber
15
+ * @param args - zod number params
16
+ * @returns zod number
15
17
  */
16
- function generateZodNumberSchema(args) {
18
+ function generateZodNumber(args) {
17
19
  const validations = ['z.number()'];
18
20
  // pattern
19
- if (args.pattern)
21
+ if (args.pattern) {
20
22
  validations.push((0, generate_zod_regex_1.generateZodRegex)(args.pattern));
23
+ }
21
24
  // minLength
22
- if (args.minLength)
25
+ if (args.minLength) {
23
26
  validations.push((0, generate_zod_min_1.generateZodMin)(args.minLength));
27
+ }
24
28
  // maxLength
25
- if (args.maxLength)
29
+ if (args.maxLength) {
26
30
  validations.push((0, generate_zod_max_1.generateZodMax)(args.maxLength));
31
+ }
27
32
  // minimum
28
- if (args.minimum)
33
+ if (args.minimum) {
29
34
  validations.push((0, generate_zod_min_1.generateZodMin)(args.minimum));
35
+ }
30
36
  // maximum
31
- if (args.maximum)
37
+ if (args.maximum) {
32
38
  validations.push((0, generate_zod_max_1.generateZodMax)(args.maximum));
39
+ }
33
40
  // default
34
- if (args.default)
41
+ if (args.default) {
35
42
  validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
43
+ }
36
44
  // example
37
- if (args.example)
45
+ if (args.example) {
38
46
  validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example, args.paramName, args.isPath));
47
+ }
39
48
  // 0 falsy value
40
49
  // minimum === 0
41
50
  // positive
@@ -53,15 +62,13 @@ function generateZodNumberSchema(args) {
53
62
  // gt
54
63
  if (args.minimum) {
55
64
  if (args.minimum > 0 && args.exclusiveMinimum) {
56
- const res = `.gt(${args.minimum})`;
57
- validations.push(res);
65
+ validations.push((0, generate_zod_gt_1.generateZodGt)(args.minimum));
58
66
  }
59
67
  }
60
68
  // lt
61
69
  if (args.maximum) {
62
70
  if (args.maximum > 0 && args.exclusiveMaximum) {
63
- const res = `.lt(${args.maximum})`;
64
- validations.push(res);
71
+ validations.push((0, generate_zod_lt_1.generateZodLt)(args.maximum));
65
72
  }
66
73
  }
67
74
  return validations.join('');
@@ -1,5 +1,5 @@
1
1
  import type { FormatString, ExampleValue, DefaultValue } from '../../types';
2
- type GenerateZodStringSchemaParams = {
2
+ type GenerateZodStringParams = {
3
3
  pattern?: string;
4
4
  minLength?: number;
5
5
  maxLength?: number;
@@ -11,35 +11,35 @@ type GenerateZodStringSchemaParams = {
11
11
  isPath?: boolean;
12
12
  };
13
13
  /**
14
- * Generates a Zod schema string for string validation
14
+ * Generates zod string schema
15
15
  *
16
- * @function generateZodStringSchema
17
- * @param args - Parameters for string schema generation
18
- * @returns Generated Zod schema string with chained validations
16
+ * @function generateZodString
17
+ * @param args - zod string params
18
+ * @returns zod string
19
19
  *
20
20
  * @example
21
21
  * // Basic string validation
22
- * generateZodStringSchema({})
22
+ * generateZodString({})
23
23
  * // Returns: 'z.string()'
24
24
  *
25
25
  * @example
26
26
  * // With regex pattern
27
- * generateZodStringSchema({ pattern: '^[A-Z]+$' })
27
+ * generateZodString({ pattern: '^[A-Z]+$' })
28
28
  * // Returns: 'z.string().regex(/^[A-Z]+$/)'
29
29
  *
30
30
  * @example
31
31
  * // With length constraints
32
- * generateZodStringSchema({ minLength: 3, maxLength: 10 })
32
+ * generateZodString({ minLength: 3, maxLength: 10 })
33
33
  * // Returns: 'z.string().min(3).max(10)'
34
34
  *
35
35
  * @example
36
36
  * // With format
37
- * generateZodStringSchema({ format: 'email' })
37
+ * generateZodString({ format: 'email' })
38
38
  * // Returns: 'z.string().email()'
39
39
  *
40
40
  * @example
41
41
  * // Combined validations
42
- * generateZodStringSchema({
42
+ * generateZodString({
43
43
  * pattern: '^[a-z]+$',
44
44
  * minLength: 3,
45
45
  * maxLength: 10,
@@ -47,5 +47,5 @@ type GenerateZodStringSchemaParams = {
47
47
  * })
48
48
  * // Returns: 'z.string().regex(/^[a-z]+$/).min(3).max(10).email()'
49
49
  */
50
- export declare function generateZodStringSchema(args: GenerateZodStringSchemaParams): string;
50
+ export declare function generateZodString(args: GenerateZodStringParams): string;
51
51
  export {};
@@ -1,42 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateZodStringSchema = generateZodStringSchema;
3
+ exports.generateZodString = generateZodString;
4
4
  const get_zod_string_format_1 = require("../../core/zod/get-zod-string-format");
5
5
  const generate_zod_default_1 = require("./generate-zod-default");
6
6
  const generate_zod_max_1 = require("./generate-zod-max");
7
7
  const generate_zod_min_1 = require("./generate-zod-min");
8
+ const generate_zod_nullable_1 = require("./generate-zod-nullable");
8
9
  const generate_zod_regex_1 = require("./generate-zod-regex");
9
10
  const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
10
11
  /**
11
- * Generates a Zod schema string for string validation
12
+ * Generates zod string schema
12
13
  *
13
- * @function generateZodStringSchema
14
- * @param args - Parameters for string schema generation
15
- * @returns Generated Zod schema string with chained validations
14
+ * @function generateZodString
15
+ * @param args - zod string params
16
+ * @returns zod string
16
17
  *
17
18
  * @example
18
19
  * // Basic string validation
19
- * generateZodStringSchema({})
20
+ * generateZodString({})
20
21
  * // Returns: 'z.string()'
21
22
  *
22
23
  * @example
23
24
  * // With regex pattern
24
- * generateZodStringSchema({ pattern: '^[A-Z]+$' })
25
+ * generateZodString({ pattern: '^[A-Z]+$' })
25
26
  * // Returns: 'z.string().regex(/^[A-Z]+$/)'
26
27
  *
27
28
  * @example
28
29
  * // With length constraints
29
- * generateZodStringSchema({ minLength: 3, maxLength: 10 })
30
+ * generateZodString({ minLength: 3, maxLength: 10 })
30
31
  * // Returns: 'z.string().min(3).max(10)'
31
32
  *
32
33
  * @example
33
34
  * // With format
34
- * generateZodStringSchema({ format: 'email' })
35
+ * generateZodString({ format: 'email' })
35
36
  * // Returns: 'z.string().email()'
36
37
  *
37
38
  * @example
38
39
  * // Combined validations
39
- * generateZodStringSchema({
40
+ * generateZodString({
40
41
  * pattern: '^[a-z]+$',
41
42
  * minLength: 3,
42
43
  * maxLength: 10,
@@ -44,28 +45,35 @@ const generate_zod_to_openapi_1 = require("./openapi/generate-zod-to-openapi");
44
45
  * })
45
46
  * // Returns: 'z.string().regex(/^[a-z]+$/).min(3).max(10).email()'
46
47
  */
47
- function generateZodStringSchema(args) {
48
+ function generateZodString(args) {
48
49
  const validations = ['z.string()'];
49
50
  // pattern
50
- if (args.pattern)
51
+ if (args.pattern) {
51
52
  validations.push((0, generate_zod_regex_1.generateZodRegex)(args.pattern));
53
+ }
52
54
  // minLength
53
- if (args.minLength)
55
+ if (args.minLength) {
54
56
  validations.push((0, generate_zod_min_1.generateZodMin)(args.minLength));
57
+ }
55
58
  // maxLength
56
- if (args.maxLength)
59
+ if (args.maxLength) {
57
60
  validations.push((0, generate_zod_max_1.generateZodMax)(args.maxLength));
61
+ }
58
62
  // format
59
- if (args.format)
63
+ if (args.format) {
60
64
  validations.push((0, get_zod_string_format_1.getZodFormatString)(args.format));
65
+ }
61
66
  // default
62
- if (args.default)
67
+ if (args.default) {
63
68
  validations.push((0, generate_zod_default_1.generateZodDefault)(args.default));
69
+ }
64
70
  // nullable
65
- if (args.nullable)
66
- validations.push('.nullable()');
71
+ if (args.nullable) {
72
+ validations.push((0, generate_zod_nullable_1.generateZodNullable)());
73
+ }
67
74
  // example
68
- if (args.example)
75
+ if (args.example) {
69
76
  validations.push((0, generate_zod_to_openapi_1.generateZodToOpenAPI)(args.example, args.paramName, args.isPath));
77
+ }
70
78
  return validations.join('');
71
79
  }
@@ -0,0 +1 @@
1
+ export declare function stripMaxIfLtExistHelper(str: string, maximum: number): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripMaxIfLtExistHelper = stripMaxIfLtExistHelper;
4
+ function stripMaxIfLtExistHelper(str, maximum) {
5
+ return str.replace(`.max(${maximum})`, '');
6
+ }
@@ -0,0 +1 @@
1
+ export declare function stripMinIfgTExistHelper(str: string, minimum: number): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripMinIfgTExistHelper = stripMinIfgTExistHelper;
4
+ function stripMinIfgTExistHelper(str, minimum) {
5
+ return str.replace(`.min(${minimum})`, '');
6
+ }
@@ -0,0 +1 @@
1
+ export declare function stripMinMaxExistHelper(str: string, min: number, max: number): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripMinMaxExistHelper = stripMinMaxExistHelper;
4
+ function stripMinMaxExistHelper(str, min, max) {
5
+ return str.replace(`.min(${min})`, '').replace(`.max(${max})`, '');
6
+ }
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateZodSchema = generateZodSchema;
4
4
  const generate_zod_array_1 = require("../generate-zod-array");
5
- const generate_zod_string_schema_1 = require("../generate-zod-string-schema");
5
+ const generate_zod_string_1 = require("../generate-zod-string");
6
6
  const is_format_string_1 = require("../../../core/validator/is-format-string");
7
- const generate_zod_number_schema_1 = require("../generate-zod-number-schema");
7
+ const generate_zod_number_1 = require("../generate-zod-number");
8
8
  const generate_zod_integer_schema_1 = require("../generate-zod-integer-schema");
9
9
  const generate_allof_code_1 = require("../../zod-openapi-hono/openapi/component/allof/generate-allof-code");
10
10
  const generate_anyof_code_1 = require("../../zod-openapi-hono/openapi/component/anyof/generate-anyof-code");
@@ -14,6 +14,10 @@ const generate_zod_object_1 = require("../generate-zod-object");
14
14
  const generate_zod_enum_1 = require("../generate-zod-enum");
15
15
  const generate_zod_max_1 = require("../generate-zod-max");
16
16
  const generate_zod_min_1 = require("../generate-zod-min");
17
+ const strip_min_if_gt_exist_helper_1 = require("../helper/strip-min-if-gt-exist-helper");
18
+ const strip_max_if_lt_exist_helper_1 = require("../helper/strip-max-if-lt-exist-helper");
19
+ const generate_zod_length_1 = require("../generate-zod-length");
20
+ const strip_min_max_exist_helper_1 = require("../helper/strip-min-max-exist-helper");
17
21
  /**
18
22
  * Mapping of OpenAPI/JSON Schema types to Zod schema strings
19
23
  *
@@ -103,7 +107,7 @@ function generateZodSchema(config, schema, paramName, isPath) {
103
107
  }
104
108
  // string
105
109
  if (schema.type === 'string') {
106
- return (0, generate_zod_string_schema_1.generateZodStringSchema)({
110
+ const res = (0, generate_zod_string_1.generateZodString)({
107
111
  pattern: schema.pattern,
108
112
  minLength: schema.minLength,
109
113
  maxLength: schema.maxLength,
@@ -114,10 +118,21 @@ function generateZodSchema(config, schema, paramName, isPath) {
114
118
  paramName,
115
119
  isPath,
116
120
  });
121
+ // length
122
+ if (schema.minLength &&
123
+ schema.maxLength &&
124
+ schema.maxLength &&
125
+ schema.minLength === schema.maxLength &&
126
+ res.includes(`min(${schema.minLength})`) &&
127
+ res.includes(`max(${schema.maxLength})`)) {
128
+ const property = (0, strip_min_max_exist_helper_1.stripMinMaxExistHelper)(res, schema.minLength, schema.maxLength);
129
+ return `${property}${(0, generate_zod_length_1.generateZodLength)(schema.minLength)}`;
130
+ }
131
+ return res;
117
132
  }
118
133
  // number
119
134
  if (schema.type === 'number') {
120
- const res = (0, generate_zod_number_schema_1.generateZodNumberSchema)({
135
+ const res = (0, generate_zod_number_1.generateZodNumber)({
121
136
  pattern: schema.pattern,
122
137
  minLength: schema.minLength,
123
138
  maxLength: schema.maxLength,
@@ -131,12 +146,16 @@ function generateZodSchema(config, schema, paramName, isPath) {
131
146
  exclusiveMaximum: schema.exclusiveMaximum,
132
147
  });
133
148
  // gt
134
- if (res.includes(`min(${schema.minimum})`) && res.includes(`gt(${schema.minimum})`)) {
135
- return res.replace(`.min(${schema.minimum})`, '');
149
+ if (res.includes(`min(${schema.minimum})`) &&
150
+ res.includes(`gt(${schema.minimum})`) &&
151
+ schema.minimum) {
152
+ return (0, strip_min_if_gt_exist_helper_1.stripMinIfgTExistHelper)(res, schema.minimum);
136
153
  }
137
154
  // lt
138
- if (res.includes(`max(${schema.maximum})`) && res.includes(`lt(${schema.maximum})`)) {
139
- return res.replace(`.max(${schema.maximum})`, '');
155
+ if (res.includes(`max(${schema.maximum})`) &&
156
+ res.includes(`lt(${schema.maximum})`) &&
157
+ schema.maximum) {
158
+ return (0, strip_max_if_lt_exist_helper_1.stripMaxIfLtExistHelper)(res, schema.maximum);
140
159
  }
141
160
  return res;
142
161
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
3
  "description": "Hono Takibi is a CLI tool that generates Hono routes from OpenAPI specifications.",
4
- "version": "0.4.4",
4
+ "version": "0.4.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "hono",
@@ -34,6 +34,7 @@
34
34
  }
35
35
  },
36
36
  "scripts": {
37
+ "takibis": "pnpm build && tsx index.ts",
37
38
  "dev": "vite --host",
38
39
  "deps": "rm -rf node_modules && pnpm install",
39
40
  "build": "tsc",
@@ -50,6 +51,7 @@
50
51
  "@hono/zod-openapi": "^0.18.3",
51
52
  "@types/node": "^22.10.2",
52
53
  "@vitest/coverage-v8": "^2.1.8",
54
+ "tsx": "^4.7.1",
53
55
  "typescript": "^5.7.2",
54
56
  "vite": "^6.1.0",
55
57
  "vitest": "^2.1.8"