hono-takibi 0.7.1 → 0.7.3
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/dist/cli/app.d.ts +3 -0
- package/dist/cli/app.js +15 -0
- package/dist/cli/{helpers/flag-val-helper.d.ts → helper/flag-val.d.ts} +1 -1
- package/dist/cli/helper/flag-val.js +10 -0
- package/dist/cli/helper/has-flag.d.ts +5 -0
- package/dist/cli/helper/has-flag.js +7 -0
- package/dist/cli/helper/index.d.ts +4 -0
- package/dist/cli/helper/index.js +4 -0
- package/dist/cli/helper/set-config.d.ts +21 -0
- package/dist/cli/helper/set-config.js +32 -0
- package/dist/cli/helper/slice-args.d.ts +4 -0
- package/dist/cli/{helpers/slice-args-helper.js → helper/slice-args.js} +1 -1
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.js +38 -0
- package/dist/cli/takibi.d.ts +15 -0
- package/dist/cli/takibi.js +14 -0
- package/dist/cli/types/index.d.ts +4 -16
- package/dist/cli/types/index.js +1 -2
- package/dist/cli/validator/index.d.ts +6 -3
- package/dist/cli/validator/index.js +6 -3
- package/dist/cli/validator/is-ts.d.ts +1 -0
- package/dist/cli/validator/is-ts.js +3 -0
- package/dist/cli/validator/is-yaml-or-json.d.ts +1 -0
- package/dist/cli/validator/is-yaml-or-json.js +3 -0
- package/dist/cli/validator/parse-cli-args.d.ts +7 -6
- package/dist/cli/validator/parse-cli-args.js +16 -57
- package/dist/cli/validator/parse-help.d.ts +6 -0
- package/dist/cli/validator/parse-help.js +8 -0
- package/dist/cli/validator/parse-io.d.ts +13 -0
- package/dist/cli/validator/parse-io.js +20 -0
- package/dist/cli/validator/parse-naming.d.ts +3 -4
- package/dist/cli/validator/parse-naming.js +7 -7
- package/dist/config/index.d.ts +15 -5
- package/dist/config/index.js +12 -5
- package/dist/core/helper/{get-camel-case-schema-name-helper.d.ts → get-camel-case-schema-name.d.ts} +1 -1
- package/dist/core/helper/{get-camel-case-schema-name-helper.js → get-camel-case-schema-name.js} +1 -1
- package/dist/core/helper/{get-pascal-case-schema-name-helper.d.ts → get-pascal-case-schema-name.d.ts} +1 -1
- package/dist/core/helper/{get-pascal-case-schema-name-helper.js → get-pascal-case-schema-name.js} +1 -1
- package/dist/core/helper/get-to-safe-identifier.d.ts +6 -0
- package/dist/core/helper/get-to-safe-identifier.js +8 -0
- package/dist/core/helper/{get-variable-name-helper.d.ts → get-variable-name.d.ts} +1 -1
- package/dist/core/helper/{get-variable-name-helper.js → get-variable-name.js} +1 -1
- package/dist/core/helper/{get-variable-schema-name-helper.d.ts → get-variable-schema-name.d.ts} +1 -1
- package/dist/core/helper/{get-variable-schema-name-helper.js → get-variable-schema-name.js} +4 -4
- package/dist/core/helper/index.d.ts +5 -5
- package/dist/core/helper/index.js +5 -5
- package/dist/core/schema/references/extract-refs.d.ts +1 -1
- package/dist/core/schema/references/find-references.d.ts +1 -1
- package/dist/core/schema/references/get-ref-schema-name.d.ts +1 -1
- package/dist/core/schema/references/get-ref-schema-name.js +2 -2
- package/dist/core/schema/references/resolve-schemas-dependencies.d.ts +1 -1
- package/dist/core/schema/references/traverse-schema-dependencies.d.ts +1 -1
- package/dist/core/schema/references/traverse-schema.d.ts +1 -1
- package/dist/core/validator/is-array-with-schema-reference.d.ts +1 -1
- package/dist/core/validator/is-http-method.d.ts +1 -1
- package/dist/core/validator/is-nullable-schema.d.ts +1 -1
- package/dist/core/validator/is-operation.d.ts +1 -1
- package/dist/core/validator/is-unique-content-schema.d.ts +1 -1
- package/dist/format/index.d.ts +3 -2
- package/dist/format/index.js +17 -8
- package/dist/fsp/index.d.ts +3 -0
- package/dist/fsp/index.js +3 -0
- package/dist/fsp/mkdir.d.ts +2 -0
- package/dist/fsp/mkdir.js +11 -0
- package/dist/fsp/readdir.d.ts +6 -0
- package/dist/fsp/readdir.js +15 -0
- package/dist/fsp/write-file.d.ts +7 -0
- package/dist/fsp/write-file.js +16 -0
- package/dist/generator/zod/{generate-zod-array.d.ts → array.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-array.js → array.js} +1 -1
- package/dist/generator/zod/{generate-zod-coerce.d.ts → coerce.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-coerce.js → coerce.js} +1 -1
- package/dist/generator/zod/{generate-zod-default.d.ts → default.d.ts} +2 -2
- package/dist/generator/zod/{generate-zod-default.js → default.js} +1 -1
- package/dist/generator/zod/enum.d.ts +6 -0
- package/dist/generator/zod/{generate-zod-enum.js → enum.js} +1 -1
- package/dist/generator/zod/{generate-zod-gt.d.ts → gt.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-gt.js → gt.js} +1 -1
- package/dist/generator/zod/index.d.ts +23 -0
- package/dist/generator/zod/index.js +23 -0
- package/dist/generator/zod/{generate-zod-infer.d.ts → infer.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-infer.js → infer.js} +1 -1
- package/dist/generator/zod/{generate-zod-integer-schema.d.ts → integer.d.ts} +2 -2
- package/dist/generator/zod/integer.js +29 -0
- package/dist/generator/zod/{generate-zod-intersection.d.ts → intersection.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-intersection.js → intersection.js} +1 -1
- package/dist/generator/zod/{generate-zod-length.d.ts → length.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-length.js → length.js} +1 -1
- package/dist/generator/zod/{generate-zod-lt.d.ts → lt.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-lt.js → lt.js} +1 -1
- package/dist/generator/zod/{generate-zod-max.d.ts → max.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-max.js → max.js} +1 -1
- package/dist/generator/zod/{generate-zod-min.d.ts → min.d.ts} +3 -3
- package/dist/generator/zod/{generate-zod-min.js → min.js} +3 -3
- package/dist/generator/zod/{generate-zod-nullable.d.ts → nullable.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-nullable.js → nullable.js} +1 -1
- package/dist/generator/zod/{generate-zod-number.d.ts → number.d.ts} +2 -2
- package/dist/generator/zod/{generate-zod-number.js → number.js} +10 -15
- package/dist/generator/zod/{generate-zod-object.d.ts → object.d.ts} +2 -2
- package/dist/generator/zod/{generate-zod-object.js → object.js} +6 -7
- package/dist/generator/zod/{generate-zod-partial-schema.d.ts → partial.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-partial-schema.js → partial.js} +1 -1
- package/dist/generator/zod/{generate-zod-passthrough.d.ts → passthrough.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-passthrough.js → passthrough.js} +1 -1
- package/dist/generator/zod/property/generate-zod-properties-schema.d.ts +1 -1
- package/dist/generator/zod/property/generate-zod-properties-schema.js +4 -4
- package/dist/generator/zod/property/generate-zod-property-schema.d.ts +1 -21
- package/dist/generator/zod/property/generate-zod-property-schema.js +3 -24
- package/dist/generator/zod/{generate-zod-record.d.ts → record.d.ts} +2 -2
- package/dist/generator/zod/{generate-zod-record.js → record.js} +3 -3
- package/dist/generator/zod/reference/generate-array-reference-schema.d.ts +1 -1
- package/dist/generator/zod/reference/generate-array-reference-schema.js +4 -4
- package/dist/generator/zod/reference/generate-reference-schema.d.ts +1 -1
- package/dist/generator/zod/reference/generate-reference-schema.js +2 -2
- package/dist/generator/zod/{generate-zod-regex.d.ts → regex.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-regex.js → regex.js} +1 -1
- package/dist/generator/zod/{generate-zod-object-schema.d.ts → schema.d.ts} +4 -4
- package/dist/generator/zod/{generate-zod-object-schema.js → schema.js} +4 -4
- package/dist/generator/zod/{generate-zod-string.d.ts → string.d.ts} +2 -2
- package/dist/generator/zod/string.js +83 -0
- package/dist/generator/zod/sub/generate-zod-schema-from-sub-schema.d.ts +1 -1
- package/dist/generator/zod/sub/generate-zod-schema-from-sub-schema.js +2 -2
- package/dist/generator/zod/{generate-zod-union.d.ts → union.d.ts} +1 -1
- package/dist/generator/zod/{generate-zod-union.js → union.js} +1 -1
- package/dist/generator/zod/{generate-zod.d.ts → zod.d.ts} +2 -4
- package/dist/generator/zod/{generate-zod.js → zod.js} +21 -32
- package/dist/generator/zod-openapi-hono/app/docs/generate-docs.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/app/helper/get-route-maps.js +6 -4
- package/dist/generator/zod-openapi-hono/app/helper/process-import-map.d.ts +1 -2
- package/dist/generator/zod-openapi-hono/app/helper/process-import-map.js +2 -2
- package/dist/generator/zod-openapi-hono/app/index.d.ts +3 -4
- package/dist/generator/zod-openapi-hono/app/index.js +5 -6
- package/dist/generator/zod-openapi-hono/app/register-component/generate-register-component.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/handler/{generators/generate-handler-name.d.ts → generator/handler-name.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/handler/{generators/generate-handler-name.js → generator/handler-name.js} +1 -1
- package/dist/generator/zod-openapi-hono/handler/{generators/generate-handler.d.ts → generator/handler.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/handler/{generators/generate-handler.js → generator/handler.js} +1 -1
- package/dist/generator/zod-openapi-hono/handler/{generators/generate-import-handlers.d.ts → generator/import-handlers.d.ts} +3 -4
- package/dist/generator/zod-openapi-hono/handler/{generators/generate-import-handlers.js → generator/import-handlers.js} +3 -3
- package/dist/generator/zod-openapi-hono/handler/generator/index.d.ts +3 -0
- package/dist/generator/zod-openapi-hono/handler/generator/index.js +3 -0
- package/dist/generator/zod-openapi-hono/handler/helper/group-handlers-by-file-name-helper.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/handler/zod-openapi-hono-handler.d.ts +16 -0
- package/dist/generator/zod-openapi-hono/handler/{generate-zod-openapi-hono-handler.js → zod-openapi-hono-handler.js} +28 -21
- package/dist/generator/zod-openapi-hono/openapi/component/allof/generate-allof-code.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/allof/generate-allof-code.js +2 -4
- package/dist/generator/zod-openapi-hono/openapi/component/allof/process/process-alllof.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/generate-anyof-code.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/anyof/generate-anyof-code.js +5 -6
- package/dist/generator/zod-openapi-hono/openapi/component/generate-components-code.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/generate-components-code.js +3 -4
- package/dist/generator/zod-openapi-hono/openapi/component/not/generate-not-code.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/generate-oneof-code.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/component/oneof/generate-oneof-code.js +5 -5
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route-code.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/route/generate-route.js +2 -2
- package/dist/generator/zod-openapi-hono/openapi/route/params/index.d.ts +4 -0
- package/dist/generator/zod-openapi-hono/openapi/route/params/index.js +4 -0
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-params-object.d.ts → params-object.d.ts} +2 -2
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-params-object.js → params-object.js} +9 -8
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-request-parameter.d.ts → request-parameter.d.ts} +2 -2
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-request-parameter.js → request-parameter.js} +5 -7
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-request-params-array.d.ts → request-params-array.d.ts} +2 -2
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-request-params-array.js → request-params-array.js} +5 -5
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-request-params.d.ts → request-params.d.ts} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/route/params/{generate-request-params.js → request-params.js} +1 -1
- package/dist/generator/zod-openapi-hono/openapi/route/request/body/generate-request-body.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/route/response/generate-response-schema.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/{generate-zod-openapi-hono.d.ts → zod-openapi-hono.d.ts} +2 -2
- package/dist/generator/zod-openapi-hono/openapi/{generate-zod-openapi-hono.js → zod-openapi-hono.js} +1 -1
- package/dist/generator/{zod/openapi → zod-to-openapi/defining}/generate-zod-to-openapi-schema-definition.js +9 -11
- package/dist/generator/zod-to-openapi/index.d.ts +1 -10
- package/dist/generator/zod-to-openapi/index.js +1 -17
- package/dist/generator/zod-to-openapi/zod-to-openapi.d.ts +13 -0
- package/dist/generator/zod-to-openapi/zod-to-openapi.js +27 -0
- package/dist/index.d.ts +1 -17
- package/dist/index.js +7 -51
- package/dist/openapi/index.d.ts +15 -0
- package/dist/openapi/index.js +1 -0
- package/dist/openapi/parse-openapi.d.ts +8 -0
- package/dist/openapi/parse-openapi.js +16 -0
- package/dist/{types/index.d.ts → openapi/types.d.ts} +2 -2
- package/dist/result/and-then.d.ts +2 -0
- package/dist/result/and-then.js +3 -0
- package/dist/result/async-and-then.d.ts +2 -0
- package/dist/result/async-and-then.js +6 -0
- package/dist/result/err.d.ts +7 -0
- package/dist/result/err.js +8 -0
- package/dist/result/index.d.ts +5 -0
- package/dist/result/index.js +4 -0
- package/dist/result/ok.d.ts +7 -0
- package/dist/result/ok.js +8 -0
- package/dist/result/types.d.ts +9 -0
- package/dist/result/types.js +1 -0
- package/dist/vite-plugin/index.d.ts +1 -1
- package/dist/vite-plugin/index.js +7 -3
- package/dist/vite-plugin/{vite-mode.d.ts → vite.d.ts} +1 -1
- package/dist/vite-plugin/{vite-mode.js → vite.js} +11 -8
- package/package.json +1 -1
- package/dist/cli/helpers/flag-val-helper.js +0 -15
- package/dist/cli/helpers/has-flag-helper.d.ts +0 -5
- package/dist/cli/helpers/has-flag-helper.js +0 -7
- package/dist/cli/helpers/index.d.ts +0 -4
- package/dist/cli/helpers/index.js +0 -4
- package/dist/cli/helpers/merge-config-helper.d.ts +0 -20
- package/dist/cli/helpers/merge-config-helper.js +0 -23
- package/dist/cli/helpers/slice-args-helper.d.ts +0 -4
- package/dist/cli/validator/ensure-io.d.ts +0 -11
- package/dist/cli/validator/ensure-io.js +0 -14
- package/dist/core/helper/get-to-safe-identifier-helper.d.ts +0 -6
- package/dist/core/helper/get-to-safe-identifier-helper.js +0 -12
- package/dist/core/validator/is-format-number.d.ts +0 -7
- package/dist/core/validator/is-format-number.js +0 -8
- package/dist/core/validator/is-format-string.d.ts +0 -7
- package/dist/core/validator/is-format-string.js +0 -26
- package/dist/core/validator/is-schema-reference.d.ts +0 -7
- package/dist/core/validator/is-schema-reference.js +0 -8
- package/dist/generator/zod/generate-zod-enum.d.ts +0 -6
- package/dist/generator/zod/generate-zod-integer-schema.js +0 -32
- package/dist/generator/zod/generate-zod-string.js +0 -121
- package/dist/generator/zod-openapi-hono/handler/generate-zod-openapi-hono-handler.d.ts +0 -16
- package/dist/generator/zod-to-openapi/example/generate-zod-to-openapi-example.d.ts +0 -9
- package/dist/generator/zod-to-openapi/example/generate-zod-to-openapi-example.js +0 -13
- /package/dist/generator/{zod/openapi → zod-to-openapi/defining}/generate-zod-to-openapi-schema-definition.d.ts +0 -0
- /package/dist/{types/index.js → openapi/types.js} +0 -0
package/dist/cli/app.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ok, asyncAndThen } from '../result/index.js';
|
|
3
|
+
import { readdir, writeFile } from '../fsp/index.js';
|
|
4
|
+
import { fmt } from '../format/index.js';
|
|
5
|
+
import { generateApp } from '../generator/zod-openapi-hono/app/index.js';
|
|
6
|
+
import { zodOpenapiHonoHandler } from '../generator/zod-openapi-hono/handler/zod-openapi-hono-handler.js';
|
|
7
|
+
export async function app(openAPI, output, test, template, basePath) {
|
|
8
|
+
if (!(template || !output.includes('/')))
|
|
9
|
+
return ok(undefined);
|
|
10
|
+
const dir = path.dirname(output);
|
|
11
|
+
return await asyncAndThen(await fmt(generateApp(openAPI, output, basePath)), async (appCode) => asyncAndThen(await readdir(dir), async (files) => {
|
|
12
|
+
const target = path.join(dir, files.includes('index.ts') ? 'main.ts' : 'index.ts');
|
|
13
|
+
return await asyncAndThen(await writeFile(target, appCode), async () => asyncAndThen(await zodOpenapiHonoHandler(openAPI, output, test), async () => ok(undefined)));
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* @param as - The array of strings to check for the flag
|
|
3
3
|
* @param f - The flag to look for
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function flagVal(args: readonly string[], flag: string): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param as - The array of strings to check for the flag
|
|
3
|
+
* @param f - The flag to look for
|
|
4
|
+
*/
|
|
5
|
+
export function flagVal(args, flag) {
|
|
6
|
+
const idx = args.indexOf(flag);
|
|
7
|
+
if (idx !== -1 && args[idx + 1] && !args[idx + 1].startsWith('-'))
|
|
8
|
+
return args[idx + 1];
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config } from '../../config/index.js';
|
|
2
|
+
import type { Result } from '../../result/types.js';
|
|
3
|
+
import type { CliFlags } from '../types/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Merge the base configuration with the CLI flags, returning a Result.
|
|
6
|
+
* @param base
|
|
7
|
+
* @param cli
|
|
8
|
+
* @returns Result<Config, string>
|
|
9
|
+
*/
|
|
10
|
+
export declare function setConfig(base: Config, cli: CliFlags): Result<{
|
|
11
|
+
schema: {
|
|
12
|
+
name: 'PascalCase' | 'camelCase';
|
|
13
|
+
export: boolean;
|
|
14
|
+
};
|
|
15
|
+
type: {
|
|
16
|
+
name: 'PascalCase' | 'camelCase';
|
|
17
|
+
export: boolean;
|
|
18
|
+
};
|
|
19
|
+
input: `${string}.yaml` | `${string}.json`;
|
|
20
|
+
output: `${string}.ts`;
|
|
21
|
+
}, string>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { err } from '../../result/err.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merge the base configuration with the CLI flags, returning a Result.
|
|
4
|
+
* @param base
|
|
5
|
+
* @param cli
|
|
6
|
+
* @returns Result<Config, string>
|
|
7
|
+
*/
|
|
8
|
+
export function setConfig(base, cli) {
|
|
9
|
+
const input = cli.input ?? base.input;
|
|
10
|
+
const output = cli.output ?? base.output;
|
|
11
|
+
if (!(input || output)) {
|
|
12
|
+
return err('Usage: hono-takibi <input-file> -o <output-file>');
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
ok: true,
|
|
16
|
+
value: {
|
|
17
|
+
...base,
|
|
18
|
+
input,
|
|
19
|
+
output,
|
|
20
|
+
type: {
|
|
21
|
+
...base.type,
|
|
22
|
+
export: cli.exportType ?? base.type.export ?? false,
|
|
23
|
+
name: cli.typeCase ?? base.type.name ?? 'PascalCase',
|
|
24
|
+
},
|
|
25
|
+
schema: {
|
|
26
|
+
...base.schema,
|
|
27
|
+
export: cli.exportSchema ?? base.schema.export ?? false,
|
|
28
|
+
name: cli.schemaCase ?? base.schema.name ?? 'PascalCase',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ok, asyncAndThen } from '../result/index.js';
|
|
2
|
+
import { sliceArgs } from './helper/slice-args.js';
|
|
3
|
+
import { parseHelp } from './validator/parse-help.js';
|
|
4
|
+
import { parseCliArgs } from './validator/parse-cli-args.js';
|
|
5
|
+
import { getConfig } from '../config/index.js';
|
|
6
|
+
import { setConfig } from './helper/set-config.js';
|
|
7
|
+
import { takibi } from './takibi.js';
|
|
8
|
+
const HELP_TEXT = `
|
|
9
|
+
Usage:
|
|
10
|
+
hono-takibi <input.yaml|json> -o <routes.ts> [options]
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--export-type Export generated type aliases
|
|
14
|
+
|
|
15
|
+
--export-schema Export generated schema objects
|
|
16
|
+
|
|
17
|
+
--naming-case-type <PascalCase|camelCase>
|
|
18
|
+
Casing for generated *type aliases*
|
|
19
|
+
(default: PascalCase)
|
|
20
|
+
|
|
21
|
+
--naming-case-schema <PascalCase|camelCase>
|
|
22
|
+
Casing for generated *schema objects*
|
|
23
|
+
(default: PascalCase)
|
|
24
|
+
|
|
25
|
+
--template Generate an app file and handler stubs
|
|
26
|
+
|
|
27
|
+
--test Generate empty *.test.ts files for handlers
|
|
28
|
+
|
|
29
|
+
--base-path <path> API prefix (e.g. /api)
|
|
30
|
+
|
|
31
|
+
--help Show this help and exit
|
|
32
|
+
`.trimStart();
|
|
33
|
+
export async function honoTakibi() {
|
|
34
|
+
const args = sliceArgs(process.argv);
|
|
35
|
+
return parseHelp(args)
|
|
36
|
+
? ok({ message: HELP_TEXT })
|
|
37
|
+
: await asyncAndThen(getConfig(), async (config) => asyncAndThen(parseCliArgs(args, config), async (cli) => asyncAndThen(setConfig(config, cli), async (finalConfig) => takibi(finalConfig, cli.template, cli.test, cli.basePath))));
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Result } from '../result/types.js';
|
|
2
|
+
export declare function takibi(config: {
|
|
3
|
+
schema: {
|
|
4
|
+
name: 'PascalCase' | 'camelCase';
|
|
5
|
+
export: boolean;
|
|
6
|
+
};
|
|
7
|
+
type: {
|
|
8
|
+
name: 'PascalCase' | 'camelCase';
|
|
9
|
+
export: boolean;
|
|
10
|
+
};
|
|
11
|
+
input: `${string}.yaml` | `${string}.json`;
|
|
12
|
+
output: `${string}.ts`;
|
|
13
|
+
}, template: boolean, test: boolean, basePath?: string): Promise<Result<{
|
|
14
|
+
message: string;
|
|
15
|
+
}, string>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ok, asyncAndThen } from '../result/index.js';
|
|
3
|
+
import { fmt } from '../format/index.js';
|
|
4
|
+
import { parseOpenAPI } from '../openapi/parse-openapi.js';
|
|
5
|
+
import { zodOpenAPIHono } from '../generator/zod-openapi-hono/openapi/zod-openapi-hono.js';
|
|
6
|
+
import { app } from './app.js';
|
|
7
|
+
import { mkdir, writeFile } from '../fsp/index.js';
|
|
8
|
+
export async function takibi(config, template, test, basePath) {
|
|
9
|
+
return await asyncAndThen(await parseOpenAPI(config.input), async (openAPI) => asyncAndThen(await fmt(zodOpenAPIHono(openAPI, config)), async (code) => asyncAndThen(await mkdir(path.dirname(config.output)), async () => asyncAndThen(await writeFile(config.output, code), async () => asyncAndThen(await app(openAPI, config.output, template, test, basePath), async () => ok({
|
|
10
|
+
message: template
|
|
11
|
+
? 'Generated code and template files written'
|
|
12
|
+
: `Generated code written to ${config.output}`,
|
|
13
|
+
}))))));
|
|
14
|
+
}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
export type Naming = 'PascalCase' | 'camelCase';
|
|
2
|
-
export type Ok<T> = {
|
|
3
|
-
ok: true;
|
|
4
|
-
value: T;
|
|
5
|
-
};
|
|
6
|
-
export type Err<E> = {
|
|
7
|
-
ok: false;
|
|
8
|
-
error: E;
|
|
9
|
-
};
|
|
10
|
-
export type Result<T, E = string> = Ok<T> | Err<E>;
|
|
11
|
-
export declare const ok: <T>(v: T) => Ok<T>;
|
|
12
|
-
export declare const err: <E>(e: E) => Err<E>;
|
|
13
1
|
export type CliFlags = {
|
|
14
|
-
input: string
|
|
15
|
-
output: string
|
|
2
|
+
input: `${string}.yaml` | `${string}.json`;
|
|
3
|
+
output: `${string}.ts`;
|
|
16
4
|
exportType?: boolean;
|
|
17
5
|
exportSchema?: boolean;
|
|
18
|
-
typeCase?:
|
|
19
|
-
schemaCase?:
|
|
6
|
+
typeCase?: 'PascalCase' | 'camelCase';
|
|
7
|
+
schemaCase?: 'PascalCase' | 'camelCase';
|
|
20
8
|
template: boolean;
|
|
21
9
|
test: boolean;
|
|
22
10
|
basePath?: string;
|
package/dist/cli/types/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export const err = (e) => ({ ok: false, error: e });
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { parseCliArgs } from './parse-cli-args.js';
|
|
2
|
+
export { parseHelp } from './parse-help.js';
|
|
3
|
+
export { parseIO } from './parse-io.js';
|
|
4
|
+
export { parseNaming } from './parse-naming.js';
|
|
5
|
+
export { isYamlOrJson } from './is-yaml-or-json.js';
|
|
6
|
+
export { isTs } from './is-ts.js';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { parseCliArgs } from './parse-cli-args.js';
|
|
2
|
+
export { parseHelp } from './parse-help.js';
|
|
3
|
+
export { parseIO } from './parse-io.js';
|
|
4
|
+
export { parseNaming } from './parse-naming.js';
|
|
5
|
+
export { isYamlOrJson } from './is-yaml-or-json.js';
|
|
6
|
+
export { isTs } from './is-ts.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isTs(o: string): o is `${string}.ts`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isYamlOrJson(i: string): i is `${string}.yaml` | `${string}.json`;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Result } from '../../result/index.js';
|
|
2
|
+
import type { CliFlags } from '../types/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Parses command line arguments into a structured format.
|
|
4
|
-
* @param
|
|
5
|
+
* @param args - The command line arguments.
|
|
5
6
|
* @returns A Result containing the parsed flags or an error message.
|
|
6
7
|
*/
|
|
7
|
-
export declare function parseCliArgs(
|
|
8
|
-
input?: string
|
|
9
|
-
output?: string
|
|
10
|
-
}): Result<CliFlags>;
|
|
8
|
+
export declare function parseCliArgs(args: readonly string[], config: {
|
|
9
|
+
input?: `${string}.yaml` | `${string}.json`;
|
|
10
|
+
output?: `${string}.ts`;
|
|
11
|
+
}): Result<CliFlags, string>;
|
|
@@ -1,62 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ensureIO } from './ensure-io.js';
|
|
5
|
-
import { parseNaming } from './parse-naming.js';
|
|
6
|
-
import { ok, err } from '../types/index.js';
|
|
7
|
-
const HELP_TEXT = `
|
|
8
|
-
Usage:
|
|
9
|
-
hono-takibi <input.yaml|json> -o <routes.ts> [options]
|
|
10
|
-
|
|
11
|
-
Options:
|
|
12
|
-
--export-type Export generated type aliases
|
|
13
|
-
|
|
14
|
-
--export-schema Export generated schema objects
|
|
15
|
-
|
|
16
|
-
--naming-case-type <PascalCase|camelCase>
|
|
17
|
-
Casing for generated *type aliases*
|
|
18
|
-
(default: PascalCase)
|
|
19
|
-
|
|
20
|
-
--naming-case-schema <PascalCase|camelCase>
|
|
21
|
-
Casing for generated *schema objects*
|
|
22
|
-
(default: PascalCase)
|
|
23
|
-
|
|
24
|
-
--template Generate an app file and handler stubs
|
|
25
|
-
|
|
26
|
-
--test Generate empty *.test.ts files for handlers
|
|
27
|
-
|
|
28
|
-
--base-path <path> API prefix (e.g. /api)
|
|
29
|
-
|
|
30
|
-
--help Show this help and exit
|
|
31
|
-
`.trimStart();
|
|
1
|
+
import { flagVal, hasFlag } from '../helper/index.js';
|
|
2
|
+
import { parseIO, parseNaming } from './index.js';
|
|
3
|
+
import { ok, andThen } from '../../result/index.js';
|
|
32
4
|
/**
|
|
33
5
|
* Parses command line arguments into a structured format.
|
|
34
|
-
* @param
|
|
6
|
+
* @param args - The command line arguments.
|
|
35
7
|
* @returns A Result containing the parsed flags or an error message.
|
|
36
8
|
*/
|
|
37
|
-
export function parseCliArgs(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!sRes.ok)
|
|
50
|
-
return err(sRes.error);
|
|
51
|
-
return ok({
|
|
52
|
-
input: io.value.input,
|
|
53
|
-
output: io.value.output,
|
|
54
|
-
exportType: hasFlagHelper(args, '--export-type') ? true : undefined,
|
|
55
|
-
exportSchema: hasFlagHelper(args, '--export-schema') ? true : undefined,
|
|
56
|
-
typeCase: tRes.value,
|
|
57
|
-
schemaCase: sRes.value,
|
|
58
|
-
template: hasFlagHelper(args, '--template'),
|
|
59
|
-
test: hasFlagHelper(args, '--test'),
|
|
60
|
-
basePath: flagValHelper(args, '--base-path'),
|
|
61
|
-
});
|
|
9
|
+
export function parseCliArgs(args, config) {
|
|
10
|
+
return andThen(parseIO(args, config), (io) => andThen(parseNaming(flagVal(args, '--naming-case-type')), (typeCase) => andThen(parseNaming(flagVal(args, '--naming-case-schema')), (schemaCase) => ok({
|
|
11
|
+
input: io.input,
|
|
12
|
+
output: io.output,
|
|
13
|
+
exportType: hasFlag(args, '--export-type') ? true : undefined,
|
|
14
|
+
exportSchema: hasFlag(args, '--export-schema') ? true : undefined,
|
|
15
|
+
typeCase,
|
|
16
|
+
schemaCase,
|
|
17
|
+
template: hasFlag(args, '--template'),
|
|
18
|
+
test: hasFlag(args, '--test'),
|
|
19
|
+
basePath: flagVal(args, '--base-path'),
|
|
20
|
+
}))));
|
|
62
21
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Result } from '../../result/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @param args - The CLI arguments
|
|
4
|
+
* @param config - The configuration object containing input and output file paths
|
|
5
|
+
* @returns A Result containing the input and output file paths or an error message
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseIO(args: readonly string[], config: {
|
|
8
|
+
input?: `${string}.yaml` | `${string}.json`;
|
|
9
|
+
output?: `${string}.ts`;
|
|
10
|
+
}): Result<{
|
|
11
|
+
input: `${string}.yaml` | `${string}.json`;
|
|
12
|
+
output: `${string}.ts`;
|
|
13
|
+
}, string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ok, err } from '../../result/index.js';
|
|
2
|
+
import { isTs, isYamlOrJson } from './index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @param args - The CLI arguments
|
|
5
|
+
* @param config - The configuration object containing input and output file paths
|
|
6
|
+
* @returns A Result containing the input and output file paths or an error message
|
|
7
|
+
*/
|
|
8
|
+
export function parseIO(args, config) {
|
|
9
|
+
const cliInput = args[0];
|
|
10
|
+
const oIdx = args.indexOf('-o');
|
|
11
|
+
const cliOutput = oIdx !== -1 ? args[oIdx + 1] : undefined;
|
|
12
|
+
const input = cliInput ?? config.input;
|
|
13
|
+
const output = cliOutput ?? config.output;
|
|
14
|
+
if (output) {
|
|
15
|
+
if (isYamlOrJson(input) && isTs(output)) {
|
|
16
|
+
return ok({ input, output });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return err('Usage: hono-takibi <input.yaml|.json> -o <output.ts>');
|
|
20
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { Result } from '
|
|
2
|
-
import type { Naming } from '../types/index.js';
|
|
1
|
+
import type { Result } from '../../result/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Parses the naming case from a raw string.
|
|
5
|
-
* @param
|
|
4
|
+
* @param str - The raw naming case string.
|
|
6
5
|
* @returns A Result containing the parsed Naming or an error message.
|
|
7
6
|
*/
|
|
8
|
-
export declare function parseNaming(
|
|
7
|
+
export declare function parseNaming(str: string | undefined): Result<'PascalCase' | 'camelCase' | undefined, string>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ok, err } from '
|
|
1
|
+
import { ok, err } from '../../result/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Parses the naming case from a raw string.
|
|
4
|
-
* @param
|
|
4
|
+
* @param str - The raw naming case string.
|
|
5
5
|
* @returns A Result containing the parsed Naming or an error message.
|
|
6
6
|
*/
|
|
7
|
-
export function parseNaming(
|
|
8
|
-
if (
|
|
9
|
-
return ok(
|
|
10
|
-
if (
|
|
7
|
+
export function parseNaming(str) {
|
|
8
|
+
if (str === 'PascalCase' || str === 'camelCase')
|
|
9
|
+
return ok(str);
|
|
10
|
+
if (str === undefined)
|
|
11
11
|
return ok(undefined);
|
|
12
|
-
return err(`--naming-case must be PascalCase or camelCase (got ${
|
|
12
|
+
return err(`--naming-case must be PascalCase or camelCase (got ${str})`);
|
|
13
13
|
}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Result } from '../result/types.js';
|
|
1
2
|
export type Config = {
|
|
2
3
|
schema: {
|
|
3
4
|
name: 'PascalCase' | 'camelCase';
|
|
@@ -7,12 +8,21 @@ export type Config = {
|
|
|
7
8
|
name: 'PascalCase' | 'camelCase';
|
|
8
9
|
export: boolean;
|
|
9
10
|
};
|
|
10
|
-
input?: string
|
|
11
|
-
output?: string
|
|
11
|
+
input?: `${string}.yaml` | `${string}.json`;
|
|
12
|
+
output?: `${string}.ts`;
|
|
13
|
+
};
|
|
14
|
+
export declare const DEFAULT_CONFIG: {
|
|
15
|
+
readonly schema: {
|
|
16
|
+
readonly name: "PascalCase";
|
|
17
|
+
readonly export: false;
|
|
18
|
+
};
|
|
19
|
+
readonly type: {
|
|
20
|
+
readonly name: "PascalCase";
|
|
21
|
+
readonly export: false;
|
|
22
|
+
};
|
|
12
23
|
};
|
|
13
|
-
export declare const DEFAULT_CONFIG: Config;
|
|
14
24
|
/**
|
|
15
25
|
* Loads the configuration from the `hono-takibi.json` file or returns the default configuration.
|
|
16
|
-
* @returns { Config }
|
|
26
|
+
* @returns { Result<Config, string> } - A Result containing the configuration or an error message.
|
|
17
27
|
*/
|
|
18
|
-
export declare function getConfig(): Config
|
|
28
|
+
export declare function getConfig(): Result<Config, string>;
|
package/dist/config/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { ok } from '../result/ok.js';
|
|
3
|
+
import { err } from '../result/err.js';
|
|
2
4
|
export const DEFAULT_CONFIG = {
|
|
3
5
|
schema: {
|
|
4
6
|
name: 'PascalCase',
|
|
@@ -11,11 +13,16 @@ export const DEFAULT_CONFIG = {
|
|
|
11
13
|
};
|
|
12
14
|
/**
|
|
13
15
|
* Loads the configuration from the `hono-takibi.json` file or returns the default configuration.
|
|
14
|
-
* @returns { Config }
|
|
16
|
+
* @returns { Result<Config, string> } - A Result containing the configuration or an error message.
|
|
15
17
|
*/
|
|
16
18
|
export function getConfig() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
const config = fs.existsSync('hono-takibi.json')
|
|
21
|
+
? { ...DEFAULT_CONFIG, ...JSON.parse(fs.readFileSync('hono-takibi.json', 'utf-8')) }
|
|
22
|
+
: DEFAULT_CONFIG;
|
|
23
|
+
return ok(config);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
27
|
+
}
|
|
21
28
|
}
|
package/dist/core/helper/{get-camel-case-schema-name-helper.d.ts → get-camel-case-schema-name.d.ts}
RENAMED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param { string } schemaName - The original schema name.
|
|
4
4
|
* @returns { string } The camelCase schema name.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function getCamelCaseSchemaName(schemaName: string): string;
|
package/dist/core/helper/{get-camel-case-schema-name-helper.js → get-camel-case-schema-name.js}
RENAMED
|
@@ -4,7 +4,7 @@ import { decapitalize } from '../text/index.js';
|
|
|
4
4
|
* @param { string } schemaName - The original schema name.
|
|
5
5
|
* @returns { string } The camelCase schema name.
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function getCamelCaseSchemaName(schemaName) {
|
|
8
8
|
const decapitalizedSchemaName = decapitalize(schemaName);
|
|
9
9
|
return `${decapitalizedSchemaName}Schema`;
|
|
10
10
|
}
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param { string } schemaName - The original schema name.
|
|
4
4
|
* @returns { string } The PascalCase schema name.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function getPascalCaseSchemaName(schemaName: string): string;
|
package/dist/core/helper/{get-pascal-case-schema-name-helper.js → get-pascal-case-schema-name.js}
RENAMED
|
@@ -4,7 +4,7 @@ import { capitalize } from '../text/index.js';
|
|
|
4
4
|
* @param { string } schemaName - The original schema name.
|
|
5
5
|
* @returns { string } The PascalCase schema name.
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function getPascalCaseSchemaName(schemaName) {
|
|
8
8
|
const capitalizedSchemaName = capitalize(schemaName);
|
|
9
9
|
return `${capitalizedSchemaName}Schema`;
|
|
10
10
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to a safe TypeScript object key.
|
|
3
|
+
* - Returns as-is if it's a valid identifier
|
|
4
|
+
* - Otherwise wraps it in double quotes (via JSON.stringify)
|
|
5
|
+
*/
|
|
6
|
+
export function getToSafeIdentifier(str) {
|
|
7
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(str) ? str : JSON.stringify(str);
|
|
8
|
+
}
|
|
@@ -5,4 +5,4 @@ import type { Config } from '../../config/index.js';
|
|
|
5
5
|
* @param { Config } config - The config of the schema.
|
|
6
6
|
* @returns { string } The variable name.
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function getVariableName(name: string, config: Config): string;
|
|
@@ -5,6 +5,6 @@ import { capitalize, decapitalize } from '../text/index.js';
|
|
|
5
5
|
* @param { Config } config - The config of the schema.
|
|
6
6
|
* @returns { string } The variable name.
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function getVariableName(name, config) {
|
|
9
9
|
return config.type.name === 'camelCase' ? decapitalize(name) : capitalize(name);
|
|
10
10
|
}
|
package/dist/core/helper/{get-variable-schema-name-helper.d.ts → get-variable-schema-name.d.ts}
RENAMED
|
@@ -5,4 +5,4 @@ import type { Config } from '../../config/index.js';
|
|
|
5
5
|
* @param { Config } config - The config of the schema.
|
|
6
6
|
* @returns { string } The variable schema name.
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function getVariableSchemaName(name: string, config: Config): string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCamelCaseSchemaName, getPascalCaseSchemaName } from './index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Generates a variable schema name from a given name and config.
|
|
4
4
|
* @param { string } name - The name of the schema.
|
|
5
5
|
* @param { Config } config - The config of the schema.
|
|
6
6
|
* @returns { string } The variable schema name.
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function getVariableSchemaName(name, config) {
|
|
9
9
|
return config.schema.name === 'camelCase'
|
|
10
|
-
?
|
|
11
|
-
:
|
|
10
|
+
? getCamelCaseSchemaName(name)
|
|
11
|
+
: getPascalCaseSchemaName(name);
|
|
12
12
|
}
|