sizuku 0.3.2 → 0.4.0
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 +103 -0
- package/dist/config/index.d.mts +58 -0
- package/dist/config/index.mjs +95 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +1615 -0
- package/package.json +31 -17
- package/dist/cli/main.d.ts +0 -10
- package/dist/cli/main.js +0 -61
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -51
- package/dist/config/index.d.ts +0 -27
- package/dist/config/index.js +0 -85
- package/dist/config/loader.d.ts +0 -19
- package/dist/config/loader.js +0 -30
- package/dist/generator/engine.d.ts +0 -3
- package/dist/generator/engine.js +0 -63
- package/dist/generator/mermaid-er/config/index.d.ts +0 -10
- package/dist/generator/mermaid-er/config/index.js +0 -12
- package/dist/generator/mermaid-er/core/extract-relations.d.ts +0 -8
- package/dist/generator/mermaid-er/core/extract-relations.js +0 -17
- package/dist/generator/mermaid-er/core.d.ts +0 -6
- package/dist/generator/mermaid-er/core.js +0 -54
- package/dist/generator/mermaid-er/generator/er-content.d.ts +0 -20
- package/dist/generator/mermaid-er/generator/er-content.js +0 -23
- package/dist/generator/mermaid-er/generator/index.d.ts +0 -2
- package/dist/generator/mermaid-er/generator/index.js +0 -2
- package/dist/generator/mermaid-er/generator/relation-line.d.ts +0 -12
- package/dist/generator/mermaid-er/generator/relation-line.js +0 -13
- package/dist/generator/mermaid-er/generator.d.ts +0 -3
- package/dist/generator/mermaid-er/generator.js +0 -14
- package/dist/generator/mermaid-er/index.d.ts +0 -12
- package/dist/generator/mermaid-er/index.js +0 -33
- package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -14
- package/dist/generator/mermaid-er/relationship/build-relation-line.js +0 -34
- package/dist/generator/mermaid-er/types.d.ts +0 -21
- package/dist/generator/mermaid-er/types.js +0 -1
- package/dist/generator/mermaid-er/validator/index.d.ts +0 -8
- package/dist/generator/mermaid-er/validator/index.js +0 -74
- package/dist/generator/mermaid-er/validator/is-relationship.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/is-relationship.js +0 -8
- package/dist/generator/mermaid-er/validator/parse-relation-line.d.ts +0 -12
- package/dist/generator/mermaid-er/validator/parse-relation-line.js +0 -20
- package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +0 -2
- package/dist/generator/mermaid-er/validator/parse-table-info.js +0 -71
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -9
- package/dist/generator/valibot/config/index.d.ts +0 -7
- package/dist/generator/valibot/config/index.js +0 -13
- package/dist/generator/valibot/core/extract-schema.d.ts +0 -5
- package/dist/generator/valibot/core/extract-schema.js +0 -173
- package/dist/generator/valibot/core.d.ts +0 -5
- package/dist/generator/valibot/core.js +0 -39
- package/dist/generator/valibot/generator/infer-input.d.ts +0 -5
- package/dist/generator/valibot/generator/infer-input.js +0 -8
- package/dist/generator/valibot/generator/relation-valibot-code.d.ts +0 -13
- package/dist/generator/valibot/generator/relation-valibot-code.js +0 -19
- package/dist/generator/valibot/generator/valibot-code.d.ts +0 -15
- package/dist/generator/valibot/generator/valibot-code.js +0 -16
- package/dist/generator/valibot/generator/valibot.d.ts +0 -14
- package/dist/generator/valibot/generator/valibot.js +0 -15
- package/dist/generator/valibot/generator.d.ts +0 -3
- package/dist/generator/valibot/generator.js +0 -14
- package/dist/generator/valibot/index.d.ts +0 -14
- package/dist/generator/valibot/index.js +0 -50
- package/dist/generator/zod/config/index.d.ts +0 -8
- package/dist/generator/zod/config/index.js +0 -14
- package/dist/generator/zod/core/extract-schema.d.ts +0 -7
- package/dist/generator/zod/core/extract-schema.js +0 -243
- package/dist/generator/zod/core.d.ts +0 -5
- package/dist/generator/zod/core.js +0 -39
- package/dist/generator/zod/generator/infer.d.ts +0 -5
- package/dist/generator/zod/generator/infer.js +0 -8
- package/dist/generator/zod/generator/relation-zod-code.d.ts +0 -13
- package/dist/generator/zod/generator/relation-zod-code.js +0 -19
- package/dist/generator/zod/generator/zod-code.d.ts +0 -17
- package/dist/generator/zod/generator/zod-code.js +0 -18
- package/dist/generator/zod/generator/zod.d.ts +0 -16
- package/dist/generator/zod/generator/zod.js +0 -16
- package/dist/generator/zod/generator.d.ts +0 -3
- package/dist/generator/zod/generator.js +0 -14
- package/dist/generator/zod/index.d.ts +0 -15
- package/dist/generator/zod/index.js +0 -54
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -73
- package/dist/shared/config/index.d.ts +0 -13
- package/dist/shared/config/index.js +0 -10
- package/dist/shared/format/index.d.ts +0 -13
- package/dist/shared/format/index.js +0 -24
- package/dist/shared/fs/index.d.ts +0 -7
- package/dist/shared/fs/index.js +0 -16
- package/dist/shared/fsp/index.d.ts +0 -27
- package/dist/shared/fsp/index.js +0 -38
- package/dist/shared/generator/field-definitions.d.ts +0 -12
- package/dist/shared/generator/field-definitions.js +0 -12
- package/dist/shared/helper/ast-parser.d.ts +0 -3
- package/dist/shared/helper/ast-parser.js +0 -202
- package/dist/shared/helper/build-schema-extractor.d.ts +0 -25
- package/dist/shared/helper/build-schema-extractor.js +0 -33
- package/dist/shared/helper/create-extract-field-from-property.d.ts +0 -15
- package/dist/shared/helper/create-extract-field-from-property.js +0 -20
- package/dist/shared/helper/create-extract-fields-from-call-expression.d.ts +0 -14
- package/dist/shared/helper/create-extract-fields-from-call-expression.js +0 -14
- package/dist/shared/helper/create-extract-relation-field-from-property.d.ts +0 -12
- package/dist/shared/helper/create-extract-relation-field-from-property.js +0 -27
- package/dist/shared/helper/extract-schemas.d.ts +0 -133
- package/dist/shared/helper/extract-schemas.js +0 -445
- package/dist/shared/helper/file-writer.d.ts +0 -3
- package/dist/shared/helper/file-writer.js +0 -25
- package/dist/shared/helper/find-object-literal-expression.d.ts +0 -12
- package/dist/shared/helper/find-object-literal-expression.js +0 -31
- package/dist/shared/helper/find-object-literalIn-args.d.ts +0 -2
- package/dist/shared/helper/find-object-literalIn-args.js +0 -8
- package/dist/shared/helper/is-relation-function.d.ts +0 -10
- package/dist/shared/helper/is-relation-function.js +0 -16
- package/dist/shared/types.d.ts +0 -9
- package/dist/shared/types.js +0 -1
- package/dist/shared/utils/capitalize.d.ts +0 -18
- package/dist/shared/utils/capitalize.js +0 -20
- package/dist/shared/utils/compose.d.ts +0 -101
- package/dist/shared/utils/compose.js +0 -124
- package/dist/shared/utils/file.d.ts +0 -92
- package/dist/shared/utils/file.js +0 -177
- package/dist/shared/utils/functional.d.ts +0 -118
- package/dist/shared/utils/functional.js +0 -96
- package/dist/shared/utils/index.d.ts +0 -20
- package/dist/shared/utils/index.js +0 -48
- package/dist/shared/utils/string-utils.d.ts +0 -8
- package/dist/shared/utils/string-utils.js +0 -28
- package/dist/shared/utils/types.d.ts +0 -32
- package/dist/shared/utils/types.js +0 -2
- package/dist/shared/utils/validation-utils.d.ts +0 -8
- package/dist/shared/utils/validation-utils.js +0 -25
- package/dist/src/config/index.d.ts +0 -18
- package/dist/src/config/index.js +0 -13
- package/dist/src/generator/mermaid-er/core/extract-relations.d.ts +0 -8
- package/dist/src/generator/mermaid-er/core/extract-relations.js +0 -12
- package/dist/src/generator/mermaid-er/generator/er-content.d.ts +0 -9
- package/dist/src/generator/mermaid-er/generator/er-content.js +0 -25
- package/dist/src/generator/mermaid-er/generator/index.d.ts +0 -2
- package/dist/src/generator/mermaid-er/generator/index.js +0 -2
- package/dist/src/generator/mermaid-er/generator/relation-line.d.ts +0 -8
- package/dist/src/generator/mermaid-er/generator/relation-line.js +0 -14
- package/dist/src/generator/mermaid-er/index.d.ts +0 -6
- package/dist/src/generator/mermaid-er/index.js +0 -16
- package/dist/src/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -15
- package/dist/src/generator/mermaid-er/relationship/build-relation-line.js +0 -35
- package/dist/src/generator/mermaid-er/types.d.ts +0 -21
- package/dist/src/generator/mermaid-er/types.js +0 -1
- package/dist/src/generator/mermaid-er/validator/index.d.ts +0 -4
- package/dist/src/generator/mermaid-er/validator/index.js +0 -4
- package/dist/src/generator/mermaid-er/validator/is-relationship.d.ts +0 -8
- package/dist/src/generator/mermaid-er/validator/is-relationship.js +0 -9
- package/dist/src/generator/mermaid-er/validator/parse-relation-line.d.ts +0 -13
- package/dist/src/generator/mermaid-er/validator/parse-relation-line.js +0 -21
- package/dist/src/generator/mermaid-er/validator/parse-table-info.d.ts +0 -8
- package/dist/src/generator/mermaid-er/validator/parse-table-info.js +0 -91
- package/dist/src/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -7
- package/dist/src/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -9
- package/dist/src/generator/valibot/generator/infer-input.d.ts +0 -5
- package/dist/src/generator/valibot/generator/infer-input.js +0 -8
- package/dist/src/generator/valibot/generator/valibot-code.d.ts +0 -14
- package/dist/src/generator/valibot/generator/valibot-code.js +0 -16
- package/dist/src/generator/valibot/generator/valibot.d.ts +0 -13
- package/dist/src/generator/valibot/generator/valibot.js +0 -11
- package/dist/src/generator/valibot/index.d.ts +0 -9
- package/dist/src/generator/valibot/index.js +0 -34
- package/dist/src/generator/zod/generator/infer.d.ts +0 -5
- package/dist/src/generator/zod/generator/infer.js +0 -8
- package/dist/src/generator/zod/generator/zod-code.d.ts +0 -16
- package/dist/src/generator/zod/generator/zod-code.js +0 -18
- package/dist/src/generator/zod/generator/zod.d.ts +0 -15
- package/dist/src/generator/zod/generator/zod.js +0 -12
- package/dist/src/generator/zod/index.d.ts +0 -10
- package/dist/src/generator/zod/index.js +0 -40
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.js +0 -35
- package/dist/src/shared/format/index.d.ts +0 -2
- package/dist/src/shared/format/index.js +0 -10
- package/dist/src/shared/fs/index.d.ts +0 -2
- package/dist/src/shared/fs/index.js +0 -10
- package/dist/src/shared/fsp/index.d.ts +0 -3
- package/dist/src/shared/fsp/index.js +0 -8
- package/dist/src/shared/generator/field-definitions.d.ts +0 -12
- package/dist/src/shared/generator/field-definitions.js +0 -12
- package/dist/src/shared/helper/build-schema-extractor.d.ts +0 -25
- package/dist/src/shared/helper/build-schema-extractor.js +0 -33
- package/dist/src/shared/helper/create-extract-field-from-property.d.ts +0 -15
- package/dist/src/shared/helper/create-extract-field-from-property.js +0 -20
- package/dist/src/shared/helper/create-extract-fields-from-call-expression.d.ts +0 -14
- package/dist/src/shared/helper/create-extract-fields-from-call-expression.js +0 -14
- package/dist/src/shared/helper/create-extract-relation-field-from-property.d.ts +0 -12
- package/dist/src/shared/helper/create-extract-relation-field-from-property.js +0 -27
- package/dist/src/shared/helper/extract-schemas.d.ts +0 -16
- package/dist/src/shared/helper/extract-schemas.js +0 -19
- package/dist/src/shared/helper/find-object-literal-expression.d.ts +0 -12
- package/dist/src/shared/helper/find-object-literal-expression.js +0 -31
- package/dist/src/shared/helper/find-object-literalIn-args.d.ts +0 -2
- package/dist/src/shared/helper/find-object-literalIn-args.js +0 -8
- package/dist/src/shared/helper/is-relation-function.d.ts +0 -10
- package/dist/src/shared/helper/is-relation-function.js +0 -16
- package/dist/src/shared/utils/index.d.ts +0 -33
- package/dist/src/shared/utils/index.js +0 -61
- package/dist/utils/index.d.ts +0 -144
- package/dist/utils/index.js +0 -250
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sizuku",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Sizuku is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from Drizzle schemas annotated with comments.",
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"description": "Sizuku is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams and DBML, from Drizzle schemas annotated with comments.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"drizzle",
|
|
9
9
|
"zod",
|
|
10
10
|
"valibot",
|
|
11
|
-
"mermaid"
|
|
11
|
+
"mermaid",
|
|
12
|
+
"dbml"
|
|
12
13
|
],
|
|
13
14
|
"homepage": "https://github.com/nakita628/sizuku",
|
|
14
15
|
"publishConfig": {
|
|
@@ -21,23 +22,23 @@
|
|
|
21
22
|
"bugs": {
|
|
22
23
|
"url": "https://github.com/nakita628/sizuku/issues"
|
|
23
24
|
},
|
|
24
|
-
"main": "dist/index.
|
|
25
|
-
"types": "dist/index.d.
|
|
25
|
+
"main": "dist/index.mjs",
|
|
26
|
+
"types": "dist/index.d.mts",
|
|
26
27
|
"files": [
|
|
27
28
|
"dist"
|
|
28
29
|
],
|
|
29
30
|
"bin": {
|
|
30
|
-
"sizuku": "dist/index.
|
|
31
|
+
"sizuku": "dist/index.mjs"
|
|
31
32
|
},
|
|
32
33
|
"exports": {
|
|
33
34
|
"./config": {
|
|
34
|
-
"types": "./dist/config/index.d.
|
|
35
|
-
"import": "./dist/config/index.
|
|
35
|
+
"types": "./dist/config/index.d.mts",
|
|
36
|
+
"import": "./dist/config/index.mjs"
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"deps": "rm -rf node_modules && pnpm install",
|
|
40
|
-
"build": "
|
|
41
|
+
"build": "tsdown",
|
|
41
42
|
"typecheck": "tsc --noEmit",
|
|
42
43
|
"dev": "pnpm --filter sizuku-test dev",
|
|
43
44
|
"test": "vitest run",
|
|
@@ -45,16 +46,29 @@
|
|
|
45
46
|
"release": "npm pkg fix && pnpm build && npm publish"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^
|
|
49
|
-
"@vitest/coverage-v8": "^
|
|
50
|
-
"drizzle-orm": "^0.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
49
|
+
"@types/node": "^24.10.1",
|
|
50
|
+
"@vitest/coverage-v8": "^4.0.14",
|
|
51
|
+
"drizzle-orm": "^0.44.7",
|
|
52
|
+
"tsdown": "^0.20.1",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"valibot": "1.2.0",
|
|
55
|
+
"vitest": "^4.0.14"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"drizzle-orm": ">=0.36.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"drizzle-orm": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
54
64
|
},
|
|
55
65
|
"dependencies": {
|
|
66
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
67
|
+
"@softwaretechnik/dbml-renderer": "^1.0.31",
|
|
56
68
|
"prettier": "^3.6.2",
|
|
57
|
-
"ts-morph": "^
|
|
58
|
-
"tsx": "^4.20.
|
|
69
|
+
"ts-morph": "^27.0.2",
|
|
70
|
+
"tsx": "^4.20.6",
|
|
71
|
+
"utils-lab": "^0.0.2",
|
|
72
|
+
"zod": "^4.1.13"
|
|
59
73
|
}
|
|
60
74
|
}
|
package/dist/cli/main.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import type { Result } from 'neverthrow';
|
|
3
|
-
import type { Config } from '../src/config/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Main CLI function that orchestrates the schema generation process.
|
|
6
|
-
*
|
|
7
|
-
* @param config - The configuration object.
|
|
8
|
-
* @returns A Result indicating success or failure.
|
|
9
|
-
*/
|
|
10
|
-
export declare function main(config?: Config): Promise<Result<void, Error>>;
|
package/dist/cli/main.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { err, ok, ResultAsync } from 'neverthrow';
|
|
3
|
-
import { getConfig } from '../src/config/index.js';
|
|
4
|
-
import { sizukuMermaidER } from '../src/generator/mermaid-er/index.js';
|
|
5
|
-
import { sizukuValibot } from '../src/generator/valibot/index.js';
|
|
6
|
-
import { sizukuZod } from '../src/generator/zod/index.js';
|
|
7
|
-
import { readFileSync } from '../src/shared/fs/index.js';
|
|
8
|
-
/**
|
|
9
|
-
* Main CLI function that orchestrates the schema generation process.
|
|
10
|
-
*
|
|
11
|
-
* @param config - The configuration object.
|
|
12
|
-
* @returns A Result indicating success or failure.
|
|
13
|
-
*/
|
|
14
|
-
export async function main(config = getConfig()) {
|
|
15
|
-
return ResultAsync.fromPromise(Promise.resolve(), () => new Error('init'))
|
|
16
|
-
.andThen(() => {
|
|
17
|
-
if (!config.input) {
|
|
18
|
-
return err(new Error('input is not found'));
|
|
19
|
-
}
|
|
20
|
-
const contentResult = readFileSync(config.input);
|
|
21
|
-
if (contentResult.isErr()) {
|
|
22
|
-
return err(contentResult.error);
|
|
23
|
-
}
|
|
24
|
-
const content = contentResult.value;
|
|
25
|
-
const lines = content.split('\n');
|
|
26
|
-
const codeStart = lines.findIndex((line) => !line.trim().startsWith('import') && line.trim() !== '');
|
|
27
|
-
return ok(lines.slice(codeStart));
|
|
28
|
-
})
|
|
29
|
-
.andThen((code) => {
|
|
30
|
-
if (config.zod?.output) {
|
|
31
|
-
return ResultAsync.fromPromise(sizukuZod(code, config.zod.output, config.zod.comment, config.zod.type, config.zod.zod), (e) => (e instanceof Error ? e : new Error(String(e)))).map(() => {
|
|
32
|
-
console.log(`Generated Zod schema at: ${config.zod?.output}`);
|
|
33
|
-
return code;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return ok(code);
|
|
37
|
-
})
|
|
38
|
-
.andThen((code) => {
|
|
39
|
-
if (config.valibot?.output) {
|
|
40
|
-
return ResultAsync.fromPromise(sizukuValibot(code, config.valibot.output, config.valibot.comment, config.valibot.type), (e) => (e instanceof Error ? e : new Error(String(e)))).map(() => {
|
|
41
|
-
console.log(`Generated Valibot schema at: ${config.valibot?.output}`);
|
|
42
|
-
return code;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return ok(code);
|
|
46
|
-
})
|
|
47
|
-
.andThen((code) => {
|
|
48
|
-
if (config.mermaid?.output) {
|
|
49
|
-
return ResultAsync.fromPromise(sizukuMermaidER(code, config.mermaid.output), (e) => e instanceof Error ? e : new Error(String(e))).map(() => {
|
|
50
|
-
console.log(`Generated Mermaid ER at: ${config.mermaid?.output}`);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return ok(undefined);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
main().then((result) => {
|
|
57
|
-
if (!result.isOk()) {
|
|
58
|
-
console.error(result.error);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
});
|
package/dist/cli.d.ts
DELETED
package/dist/cli.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import { Result, err, ok } from 'neverthrow';
|
|
4
|
-
import { loadConfig, validateConfig } from './config/loader.js';
|
|
5
|
-
import { generateSchemas } from './generator/engine.js';
|
|
6
|
-
const main = async () => {
|
|
7
|
-
try {
|
|
8
|
-
// コマンドライン引数を解析
|
|
9
|
-
const args = process.argv.slice(2);
|
|
10
|
-
if (args.length === 0) {
|
|
11
|
-
return err(new Error('Usage: sizuku <config-file>'));
|
|
12
|
-
}
|
|
13
|
-
const configPath = resolve(args[0]);
|
|
14
|
-
// 設定ファイルを読み込み
|
|
15
|
-
const configResult = await loadConfig(configPath);
|
|
16
|
-
if (configResult.isErr()) {
|
|
17
|
-
return err(configResult.error);
|
|
18
|
-
}
|
|
19
|
-
// 設定をバリデーション
|
|
20
|
-
const validationResult = validateConfig(configResult.value);
|
|
21
|
-
if (validationResult.isErr()) {
|
|
22
|
-
return err(validationResult.error);
|
|
23
|
-
}
|
|
24
|
-
const config = validationResult.value;
|
|
25
|
-
// スキーマ生成を実行
|
|
26
|
-
const generationResult = await generateSchemas(config);
|
|
27
|
-
if (generationResult.isErr()) {
|
|
28
|
-
return err(generationResult.error);
|
|
29
|
-
}
|
|
30
|
-
console.log('✅ Schema generation completed successfully!');
|
|
31
|
-
return ok(undefined);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
return err(new Error(`CLI execution failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
// CLI実行
|
|
38
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
39
|
-
main()
|
|
40
|
-
.then(result => {
|
|
41
|
-
if (result.isErr()) {
|
|
42
|
-
console.error('❌ Error:', result.error.message);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
process.exit(0);
|
|
46
|
-
})
|
|
47
|
-
.catch(error => {
|
|
48
|
-
console.error('❌ Unexpected error:', error instanceof Error ? error.message : String(error));
|
|
49
|
-
process.exit(1);
|
|
50
|
-
});
|
|
51
|
-
}
|
package/dist/config/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type Config = {
|
|
2
|
-
readonly input: `${string}.ts`;
|
|
3
|
-
readonly zod?: {
|
|
4
|
-
readonly output: `${string}.ts`;
|
|
5
|
-
readonly comment?: boolean;
|
|
6
|
-
readonly type?: boolean;
|
|
7
|
-
readonly zod?: 'v4' | 'mini' | '@hono/zod-openapi';
|
|
8
|
-
readonly relation?: boolean;
|
|
9
|
-
};
|
|
10
|
-
readonly valibot?: {
|
|
11
|
-
readonly output: `${string}.ts`;
|
|
12
|
-
readonly comment?: boolean;
|
|
13
|
-
readonly type?: boolean;
|
|
14
|
-
readonly relation?: boolean;
|
|
15
|
-
};
|
|
16
|
-
readonly mermaid?: {
|
|
17
|
-
readonly output: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export declare function config(): Promise<{
|
|
21
|
-
readonly ok: true;
|
|
22
|
-
readonly value: Config;
|
|
23
|
-
} | {
|
|
24
|
-
readonly ok: false;
|
|
25
|
-
readonly error: string;
|
|
26
|
-
}>;
|
|
27
|
-
export declare function defineConfig(config: Config): Config;
|
package/dist/config/index.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { register } from 'tsx/esm/api';
|
|
5
|
-
export async function config() {
|
|
6
|
-
const isTs = (o) => o.endsWith('.ts');
|
|
7
|
-
const abs = resolve(process.cwd(), 'sizuku.config.ts');
|
|
8
|
-
if (!existsSync(abs)) {
|
|
9
|
-
return { ok: false, error: `Config not found: ${abs}` };
|
|
10
|
-
}
|
|
11
|
-
try {
|
|
12
|
-
register();
|
|
13
|
-
const mod = await import(pathToFileURL(abs).href);
|
|
14
|
-
if (!('default' in mod)) {
|
|
15
|
-
return { ok: false, error: 'Config must export default object' };
|
|
16
|
-
}
|
|
17
|
-
if (mod.default !== undefined) {
|
|
18
|
-
if (!isTs(mod.default.input)) {
|
|
19
|
-
return { ok: false, error: 'Input must be a .ts file' };
|
|
20
|
-
}
|
|
21
|
-
// zod
|
|
22
|
-
if (mod.default.zod !== undefined) {
|
|
23
|
-
if (!isTs(mod.default.zod.output)) {
|
|
24
|
-
return { ok: false, error: 'Zod output must be a .ts file' };
|
|
25
|
-
}
|
|
26
|
-
if (mod.default.zod.comment !== undefined) {
|
|
27
|
-
if (typeof mod.default.zod.comment !== 'boolean') {
|
|
28
|
-
return { ok: false, error: 'Zod comment must be a boolean' };
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (mod.default.zod.type !== undefined) {
|
|
32
|
-
if (typeof mod.default.zod.type !== 'boolean') {
|
|
33
|
-
return { ok: false, error: 'Zod type must be a boolean' };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (mod.default.zod.zod !== undefined) {
|
|
37
|
-
if (mod.default.zod.zod !== 'v4' &&
|
|
38
|
-
mod.default.zod.zod !== 'mini' &&
|
|
39
|
-
mod.default.zod.zod !== '@hono/zod-openapi') {
|
|
40
|
-
return { ok: false, error: 'zod must be v4, mini, or @hono/zod-openapi' };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (mod.default.zod.relation !== undefined) {
|
|
44
|
-
if (typeof mod.default.zod.relation !== 'boolean') {
|
|
45
|
-
return { ok: false, error: 'Zod relation must be a boolean' };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// valibot
|
|
51
|
-
if (mod.default.valibot !== undefined) {
|
|
52
|
-
if (!isTs(mod.default.valibot.output)) {
|
|
53
|
-
return { ok: false, error: 'Valibot output must be a .ts file' };
|
|
54
|
-
}
|
|
55
|
-
if (mod.default.valibot.comment !== undefined) {
|
|
56
|
-
if (typeof mod.default.valibot.comment !== 'boolean') {
|
|
57
|
-
return { ok: false, error: 'Valibot comment must be a boolean' };
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (mod.default.valibot.type !== undefined) {
|
|
61
|
-
if (typeof mod.default.valibot.type !== 'boolean') {
|
|
62
|
-
return { ok: false, error: 'Valibot type must be a boolean' };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (mod.default.valibot.relation !== undefined) {
|
|
66
|
-
if (typeof mod.default.valibot.relation !== 'boolean') {
|
|
67
|
-
return { ok: false, error: 'Valibot relation must be a boolean' };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// mermaid
|
|
72
|
-
if (mod.default.mermaid !== undefined) {
|
|
73
|
-
if (typeof mod.default.mermaid.output !== 'string') {
|
|
74
|
-
return { ok: false, error: 'Mermaid output must be a string' };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return { ok: true, value: mod.default };
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
return { ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export function defineConfig(config) {
|
|
84
|
-
return config;
|
|
85
|
-
}
|
package/dist/config/loader.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Result } from 'neverthrow';
|
|
2
|
-
export type SizukuConfig = {
|
|
3
|
-
input: string;
|
|
4
|
-
zod?: {
|
|
5
|
-
output: string;
|
|
6
|
-
comment?: boolean;
|
|
7
|
-
type?: boolean;
|
|
8
|
-
};
|
|
9
|
-
valibot?: {
|
|
10
|
-
output: string;
|
|
11
|
-
comment?: boolean;
|
|
12
|
-
type?: boolean;
|
|
13
|
-
};
|
|
14
|
-
mermaid?: {
|
|
15
|
-
output: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export declare const loadConfig: (configPath: string) => Promise<Result<SizukuConfig, Error>>;
|
|
19
|
-
export declare const validateConfig: (config: SizukuConfig) => Result<SizukuConfig, Error>;
|
package/dist/config/loader.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import { Result, err, ok } from 'neverthrow';
|
|
3
|
-
export const loadConfig = async (configPath) => {
|
|
4
|
-
try {
|
|
5
|
-
const configContent = await readFile(configPath, 'utf-8');
|
|
6
|
-
const config = JSON.parse(configContent);
|
|
7
|
-
// 基本的なバリデーション
|
|
8
|
-
if (!config.input) {
|
|
9
|
-
return err(new Error('Config must specify input file path'));
|
|
10
|
-
}
|
|
11
|
-
return ok(config);
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
return err(new Error(`Failed to load config from ${configPath}: ${error instanceof Error ? error.message : String(error)}`));
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export const validateConfig = (config) => {
|
|
18
|
-
try {
|
|
19
|
-
if (!config.input) {
|
|
20
|
-
return err(new Error('Input file path is required'));
|
|
21
|
-
}
|
|
22
|
-
if (!config.zod && !config.valibot && !config.mermaid) {
|
|
23
|
-
return err(new Error('At least one output format must be specified (zod, valibot, or mermaid)'));
|
|
24
|
-
}
|
|
25
|
-
return ok(config);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
return err(new Error(`Config validation failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
29
|
-
}
|
|
30
|
-
};
|
package/dist/generator/engine.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Result, err, ok } from 'neverthrow';
|
|
2
|
-
import { parseSchemaFile } from '../shared/helper/ast-parser.js';
|
|
3
|
-
import { generateZodSchemas } from './zod/generator.js';
|
|
4
|
-
import { generateValibotSchemas } from './valibot/generator.js';
|
|
5
|
-
import { generateMermaidERDiagram } from './mermaid-er/generator.js';
|
|
6
|
-
import { writeFileSafely } from '../shared/helper/file-writer.js';
|
|
7
|
-
export const generateSchemas = async (config) => {
|
|
8
|
-
try {
|
|
9
|
-
// スキーマファイルを解析
|
|
10
|
-
const parseResult = await parseSchemaFile(config.input);
|
|
11
|
-
if (parseResult.isErr()) {
|
|
12
|
-
return err(parseResult.error);
|
|
13
|
-
}
|
|
14
|
-
const schema = parseResult.value;
|
|
15
|
-
// 各フォーマットを生成
|
|
16
|
-
const results = [];
|
|
17
|
-
if (config.zod) {
|
|
18
|
-
results.push(generateZodOutput(schema, config.zod.output));
|
|
19
|
-
}
|
|
20
|
-
if (config.valibot) {
|
|
21
|
-
results.push(generateValibotOutput(schema, config.valibot.output));
|
|
22
|
-
}
|
|
23
|
-
if (config.mermaid) {
|
|
24
|
-
results.push(generateMermaidOutput(schema, config.mermaid.output));
|
|
25
|
-
}
|
|
26
|
-
// すべての生成を待機
|
|
27
|
-
const generationResults = await Promise.all(results);
|
|
28
|
-
// エラーがあれば最初のエラーを返す
|
|
29
|
-
for (const result of generationResults) {
|
|
30
|
-
if (result.isErr()) {
|
|
31
|
-
return err(result.error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return ok(undefined);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
return err(new Error(`Schema generation failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const generateZodOutput = async (schema, outputPath) => {
|
|
41
|
-
const zodResult = generateZodSchemas(schema);
|
|
42
|
-
if (zodResult.isErr()) {
|
|
43
|
-
return err(zodResult.error);
|
|
44
|
-
}
|
|
45
|
-
const writeResult = await writeFileSafely(outputPath, zodResult.value);
|
|
46
|
-
return writeResult;
|
|
47
|
-
};
|
|
48
|
-
const generateValibotOutput = async (schema, outputPath) => {
|
|
49
|
-
const valibotResult = generateValibotSchemas(schema);
|
|
50
|
-
if (valibotResult.isErr()) {
|
|
51
|
-
return err(valibotResult.error);
|
|
52
|
-
}
|
|
53
|
-
const writeResult = await writeFileSafely(outputPath, valibotResult.value);
|
|
54
|
-
return writeResult;
|
|
55
|
-
};
|
|
56
|
-
const generateMermaidOutput = async (schema, outputPath) => {
|
|
57
|
-
const mermaidResult = generateMermaidERDiagram(schema);
|
|
58
|
-
if (mermaidResult.isErr()) {
|
|
59
|
-
return err(mermaidResult.error);
|
|
60
|
-
}
|
|
61
|
-
const writeResult = await writeFileSafely(outputPath, mermaidResult.value);
|
|
62
|
-
return writeResult;
|
|
63
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
/**
|
|
3
|
-
* Loads the configuration from the `sizuku.json` file or returns the default configuration.
|
|
4
|
-
*
|
|
5
|
-
* @returns The configuration object.
|
|
6
|
-
*/
|
|
7
|
-
export function getConfig() {
|
|
8
|
-
const config = fs.existsSync('sizuku-mermaid-er.json')
|
|
9
|
-
? { ...JSON.parse(fs.readFileSync('sizuku-mermaid-er.json', 'utf-8')) }
|
|
10
|
-
: {};
|
|
11
|
-
return config;
|
|
12
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Relation } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Extracts relations from the given code.
|
|
4
|
-
*
|
|
5
|
-
* @param code - The code to extract relations from.
|
|
6
|
-
* @returns The extracted relations.
|
|
7
|
-
*/
|
|
8
|
-
export declare function extractRelations(code: string[]): Relation[];
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { parseRelationLine } from '../validator/parse-relation-line.js';
|
|
2
|
-
/**
|
|
3
|
-
* Extracts relations from the given code.
|
|
4
|
-
*
|
|
5
|
-
* @param code - The code to extract relations from.
|
|
6
|
-
* @returns The extracted relations.
|
|
7
|
-
*/
|
|
8
|
-
export function extractRelations(code) {
|
|
9
|
-
const relations = [];
|
|
10
|
-
for (const line of code) {
|
|
11
|
-
const relation = parseRelationLine(line);
|
|
12
|
-
if (relation) {
|
|
13
|
-
relations.push(relation);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return relations;
|
|
17
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { TableInfo, ColumnInfo, RelationInfo } from '../../shared/utils/types.js';
|
|
2
|
-
export declare const generateMermaidER: (tables: TableInfo[]) => string;
|
|
3
|
-
export declare const generateRelations: (tables: TableInfo[]) => string;
|
|
4
|
-
export declare const generateRelationLine: (relation: RelationInfo) => string;
|
|
5
|
-
export declare const generateEntity: (table: TableInfo) => string;
|
|
6
|
-
export declare const generateColumnDefinition: (column: ColumnInfo) => string;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// 完全純粋なMermaid ER図生成ユーティリティ - 外部import禁止
|
|
2
|
-
export const generateMermaidER = (tables) => {
|
|
3
|
-
const header = 'erDiagram';
|
|
4
|
-
const relations = generateRelations(tables);
|
|
5
|
-
const entities = tables.map(table => generateEntity(table)).join('\n ');
|
|
6
|
-
return `${header}
|
|
7
|
-
${relations}
|
|
8
|
-
${entities}`;
|
|
9
|
-
};
|
|
10
|
-
export const generateRelations = (tables) => {
|
|
11
|
-
const relations = [];
|
|
12
|
-
for (const table of tables) {
|
|
13
|
-
for (const relation of table.relations) {
|
|
14
|
-
const relationLine = generateRelationLine(relation);
|
|
15
|
-
if (relationLine) {
|
|
16
|
-
relations.push(relationLine);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return relations.join('\n ');
|
|
21
|
-
};
|
|
22
|
-
export const generateRelationLine = (relation) => {
|
|
23
|
-
const sourceTable = relation.sourceTable;
|
|
24
|
-
const targetTable = relation.targetTable;
|
|
25
|
-
const sourceColumn = relation.sourceColumn;
|
|
26
|
-
const targetColumn = relation.targetColumn;
|
|
27
|
-
if (relation.type === 'one-to-many') {
|
|
28
|
-
return `${sourceTable} ||--}| ${targetTable} : "(${sourceColumn}) - (${targetColumn})"`;
|
|
29
|
-
}
|
|
30
|
-
else if (relation.type === 'many-to-one') {
|
|
31
|
-
return `${targetTable} ||--}| ${sourceTable} : "(${targetColumn}) - (${sourceColumn})"`;
|
|
32
|
-
}
|
|
33
|
-
else if (relation.type === 'one-to-one') {
|
|
34
|
-
return `${sourceTable} ||--|| ${targetTable} : "(${sourceColumn}) - (${targetColumn})"`;
|
|
35
|
-
}
|
|
36
|
-
else if (relation.type === 'many-to-many') {
|
|
37
|
-
return `${sourceTable} }|--|{ ${targetTable} : "(${sourceColumn}) - (${targetColumn})"`;
|
|
38
|
-
}
|
|
39
|
-
return '';
|
|
40
|
-
};
|
|
41
|
-
export const generateEntity = (table) => {
|
|
42
|
-
const columns = table.columns.map(column => generateColumnDefinition(column)).join('\n ');
|
|
43
|
-
return `${table.name} {
|
|
44
|
-
${columns}
|
|
45
|
-
}`;
|
|
46
|
-
};
|
|
47
|
-
export const generateColumnDefinition = (column) => {
|
|
48
|
-
const type = column.type;
|
|
49
|
-
const name = column.name;
|
|
50
|
-
const comment = column.comment || '';
|
|
51
|
-
const primaryKey = column.isPrimary ? ' (PK)' : '';
|
|
52
|
-
const nullable = column.isNullable ? '' : ' NOT NULL';
|
|
53
|
-
return `${type} ${name}${primaryKey}${nullable} "${comment}"`;
|
|
54
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate ER content
|
|
3
|
-
* @param relations - The relations to generate the ER content from
|
|
4
|
-
* @param tables - The tables to generate the ER content from
|
|
5
|
-
* @returns The generated ER content
|
|
6
|
-
*/
|
|
7
|
-
export declare function erContent(relations: {
|
|
8
|
-
fromModel: string;
|
|
9
|
-
toModel: string;
|
|
10
|
-
fromField: string;
|
|
11
|
-
toField: string;
|
|
12
|
-
type: string;
|
|
13
|
-
}[], tables: {
|
|
14
|
-
name: string;
|
|
15
|
-
fields: {
|
|
16
|
-
type: string;
|
|
17
|
-
name: string;
|
|
18
|
-
description: string | null;
|
|
19
|
-
}[];
|
|
20
|
-
}[]): string;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { relationLine } from './index.js';
|
|
2
|
-
const ER_HEADER = ['```mermaid', 'erDiagram'];
|
|
3
|
-
const ER_FOOTER = ['```'];
|
|
4
|
-
/**
|
|
5
|
-
* Generate ER content
|
|
6
|
-
* @param relations - The relations to generate the ER content from
|
|
7
|
-
* @param tables - The tables to generate the ER content from
|
|
8
|
-
* @returns The generated ER content
|
|
9
|
-
*/
|
|
10
|
-
export function erContent(relations, tables) {
|
|
11
|
-
const erContent = [
|
|
12
|
-
...ER_HEADER,
|
|
13
|
-
...relations.map(relationLine),
|
|
14
|
-
// Generate per-table definitions
|
|
15
|
-
...tables.flatMap((table) => [
|
|
16
|
-
` ${table.name} {`,
|
|
17
|
-
...table.fields.map((field) => ` ${field.type} ${field.name}${field.description ? ` "${field.description}"` : ''}`),
|
|
18
|
-
' }',
|
|
19
|
-
]),
|
|
20
|
-
...ER_FOOTER,
|
|
21
|
-
];
|
|
22
|
-
return erContent.join('\n');
|
|
23
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate a relation line for a relation
|
|
3
|
-
* @param relation - The relation to generate a line for
|
|
4
|
-
* @returns The generated relation line
|
|
5
|
-
*/
|
|
6
|
-
export declare function relationLine(relation: {
|
|
7
|
-
fromModel: string;
|
|
8
|
-
toModel: string;
|
|
9
|
-
fromField: string;
|
|
10
|
-
toField: string;
|
|
11
|
-
type: string;
|
|
12
|
-
}): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { buildRelationLine } from '../../../shared/helper/extract-schemas.js';
|
|
2
|
-
/**
|
|
3
|
-
* Generate a relation line for a relation
|
|
4
|
-
* @param relation - The relation to generate a line for
|
|
5
|
-
* @returns The generated relation line
|
|
6
|
-
*/
|
|
7
|
-
export function relationLine(relation) {
|
|
8
|
-
const cardinality = buildRelationLine(relation.type);
|
|
9
|
-
if (!cardinality) {
|
|
10
|
-
throw new Error(`Unknown relation type: ${relation.type}`);
|
|
11
|
-
}
|
|
12
|
-
return ` ${relation.fromModel} ${cardinality} ${relation.toModel} : "(${relation.fromField}) - (${relation.toField})"`;
|
|
13
|
-
}
|