sizuku 0.0.7 → 0.1.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 +87 -341
- package/dist/config/index.d.ts +18 -0
- package/dist/config/index.js +13 -0
- package/dist/generator/mermaid-er/config/index.d.ts +4 -4
- package/dist/generator/mermaid-er/config/index.js +4 -10
- package/dist/generator/mermaid-er/core/extract-relations.d.ts +1 -1
- package/dist/generator/mermaid-er/core/extract-relations.js +3 -6
- package/dist/generator/mermaid-er/generator/{generate-er-content.d.ts → er-content.d.ts} +2 -3
- package/dist/generator/mermaid-er/generator/{generate-er-content.js → er-content.js} +3 -7
- package/dist/generator/mermaid-er/generator/index.d.ts +2 -0
- package/dist/generator/mermaid-er/generator/index.js +2 -0
- package/dist/generator/mermaid-er/generator/{generate-relation-line.d.ts → relation-line.d.ts} +2 -2
- package/dist/generator/mermaid-er/generator/{generate-relation-line.js → relation-line.js} +3 -6
- package/dist/generator/mermaid-er/index.d.ts +6 -5
- package/dist/generator/mermaid-er/index.js +15 -76
- package/dist/generator/mermaid-er/relationship/build-relation-line.js +3 -6
- package/dist/generator/mermaid-er/types.js +1 -0
- package/dist/generator/mermaid-er/validator/index.d.ts +4 -0
- package/dist/generator/mermaid-er/validator/index.js +4 -0
- package/dist/generator/mermaid-er/validator/is-relationship.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/is-relationship.js +1 -4
- package/dist/generator/mermaid-er/validator/parse-relation-line.js +1 -4
- package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +1 -7
- package/dist/generator/mermaid-er/validator/parse-table-info.js +69 -89
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +1 -4
- package/dist/generator/valibot/config/index.d.ts +2 -2
- package/dist/generator/valibot/config/index.js +6 -12
- package/dist/generator/valibot/core/extract-schema.d.ts +2 -5
- package/dist/generator/valibot/core/extract-schema.js +162 -81
- package/dist/generator/valibot/generator/infer-input.d.ts +5 -0
- package/dist/generator/valibot/generator/infer-input.js +8 -0
- package/dist/generator/valibot/generator/valibot-code.d.ts +8 -0
- package/dist/generator/valibot/generator/valibot-code.js +16 -0
- package/dist/generator/valibot/generator/valibot.d.ts +7 -0
- package/dist/generator/valibot/generator/valibot.js +11 -0
- package/dist/generator/valibot/index.d.ts +9 -3
- package/dist/generator/valibot/index.js +21 -76
- package/dist/generator/zod/config/index.d.ts +2 -2
- package/dist/generator/zod/config/index.js +6 -12
- package/dist/generator/zod/core/extract-schema.d.ts +1 -2
- package/dist/generator/zod/core/extract-schema.js +228 -81
- package/dist/generator/zod/generator/infer.d.ts +5 -0
- package/dist/generator/zod/generator/infer.js +8 -0
- package/dist/generator/zod/generator/{generate-zod-code.d.ts → zod-code.d.ts} +2 -3
- package/dist/generator/zod/generator/zod-code.js +18 -0
- package/dist/generator/zod/generator/{generate-zod-schema.d.ts → zod.d.ts} +2 -4
- package/dist/generator/zod/generator/zod.js +12 -0
- package/dist/generator/zod/index.d.ts +10 -3
- package/dist/generator/zod/index.js +29 -76
- package/dist/index.d.ts +3 -0
- package/dist/index.js +54 -0
- package/dist/shared/config/index.d.ts +13 -0
- package/dist/{common → shared}/config/index.js +1 -4
- package/dist/shared/format/index.d.ts +2 -0
- package/dist/shared/format/index.js +10 -0
- package/dist/shared/fs/index.d.ts +2 -0
- package/dist/shared/fs/index.js +10 -0
- package/dist/shared/fsp/index.d.ts +3 -0
- package/dist/shared/fsp/index.js +8 -0
- package/dist/shared/generator/field-definitions.d.ts +6 -0
- package/dist/shared/generator/field-definitions.js +12 -0
- package/dist/shared/types.js +1 -0
- package/dist/{common/text → shared/utils}/capitalize.js +1 -4
- package/dist/shared/utils/compose.d.ts +101 -0
- package/dist/shared/utils/compose.js +124 -0
- package/dist/shared/utils/file.d.ts +92 -0
- package/dist/shared/utils/file.js +177 -0
- package/dist/shared/utils/functional.d.ts +118 -0
- package/dist/shared/utils/functional.js +96 -0
- package/package.json +11 -10
- package/dist/common/config/index.d.ts +0 -13
- package/dist/common/format/index.d.ts +0 -1
- package/dist/common/format/index.js +0 -12
- package/dist/common/generator/generate-field-definitions.d.ts +0 -8
- package/dist/common/generator/generate-field-definitions.js +0 -16
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +0 -7
- package/dist/common/helper/get-camel-case-schema-name-helper.js +0 -14
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +0 -8
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +0 -15
- package/dist/common/helper/get-variable-name-helper.d.ts +0 -9
- package/dist/common/helper/get-variable-name-helper.js +0 -15
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +0 -9
- package/dist/common/helper/get-variable-schema-name-helper.js +0 -17
- package/dist/common/text/decapitalize.d.ts +0 -17
- package/dist/common/text/decapitalize.js +0 -22
- package/dist/common/type/index.js +0 -2
- package/dist/generator/mermaid-er/type/index.js +0 -2
- package/dist/generator/mermaid-er/validator/is-relation.d.ts +0 -7
- package/dist/generator/mermaid-er/validator/is-relation.js +0 -40
- package/dist/generator/valibot/generator/generate-valibot-code.d.ts +0 -11
- package/dist/generator/valibot/generator/generate-valibot-code.js +0 -21
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +0 -16
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot-schema.js +0 -16
- package/dist/generator/zod/generator/generate-z-infer.d.ts +0 -11
- package/dist/generator/zod/generator/generate-z-infer.js +0 -18
- package/dist/generator/zod/generator/generate-zod-code.js +0 -21
- package/dist/generator/zod/generator/generate-zod-schema.js +0 -17
- /package/dist/generator/mermaid-er/{type/index.d.ts → types.d.ts} +0 -0
- /package/dist/{common/type/index.d.ts → shared/types.d.ts} +0 -0
- /package/dist/{common/text → shared/utils}/capitalize.d.ts +0 -0
package/README.md
CHANGED
|
@@ -21,432 +21,178 @@ npm install -D sizuku
|
|
|
21
21
|
|
|
22
22
|
### Example
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Prepare schema.ts:
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
27
|
+
import { mysqlTable, varchar } from 'drizzle-orm/mysql-core'
|
|
28
|
+
import { relations } from 'drizzle-orm'
|
|
29
29
|
|
|
30
30
|
export const user = mysqlTable('user', {
|
|
31
|
-
///
|
|
32
|
-
/// @z.
|
|
31
|
+
/// Primary key
|
|
32
|
+
/// @z.uuid()
|
|
33
33
|
/// @v.pipe(v.string(), v.uuid())
|
|
34
34
|
id: varchar('id', { length: 36 }).primaryKey(),
|
|
35
|
-
///
|
|
36
|
-
/// @z.string()
|
|
37
|
-
/// @v.string()
|
|
38
|
-
|
|
39
|
-
/// Email address of the user.
|
|
40
|
-
/// @z.string().email()
|
|
41
|
-
/// @v.pipe(v.string(), v.email())
|
|
42
|
-
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
43
|
-
/// Password for the user.
|
|
44
|
-
/// @z.string().min(8).max(100)
|
|
45
|
-
/// @v.pipe(v.string(), v.minLength(8), v.maxLength(100))
|
|
46
|
-
password: varchar('password', { length: 100 }).notNull(),
|
|
47
|
-
/// Timestamp when the user was created.
|
|
48
|
-
/// @z.date()
|
|
49
|
-
/// @v.date()
|
|
50
|
-
createdAt: timestamp('created_at', { mode: 'string' }).notNull().default(sql`CURRENT_TIMESTAMP`),
|
|
51
|
-
/// Timestamp when the user was last updated.
|
|
52
|
-
/// @z.date()
|
|
53
|
-
/// @v.date()
|
|
54
|
-
updatedAt: timestamp('updated_at', { mode: 'string' })
|
|
55
|
-
.notNull()
|
|
56
|
-
.default(sql`CURRENT_TIMESTAMP`)
|
|
57
|
-
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
|
35
|
+
/// Display name
|
|
36
|
+
/// @z.string().min(1).max(50)
|
|
37
|
+
/// @v.pipe(v.string(), v.minLength(1), v.maxLength(50))
|
|
38
|
+
name: varchar('name', { length: 50 }).notNull(),
|
|
58
39
|
})
|
|
59
40
|
|
|
60
41
|
/// @relation user.id post.userId one-to-many
|
|
61
42
|
export const post = mysqlTable('post', {
|
|
62
|
-
///
|
|
63
|
-
/// @z.
|
|
43
|
+
/// Primary key
|
|
44
|
+
/// @z.uuid()
|
|
64
45
|
/// @v.pipe(v.string(), v.uuid())
|
|
65
46
|
id: varchar('id', { length: 36 }).primaryKey(),
|
|
66
|
-
///
|
|
67
|
-
/// @z.string().
|
|
68
|
-
/// @v.pipe(v.string(), v.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.references(() => user.id, { onDelete: 'cascade' }),
|
|
72
|
-
/// Content of the post.
|
|
47
|
+
/// Article title
|
|
48
|
+
/// @z.string().min(1).max(100)
|
|
49
|
+
/// @v.pipe(v.string(), v.minLength(1), v.maxLength(100))
|
|
50
|
+
title: varchar('title', { length: 100 }).notNull(),
|
|
51
|
+
/// Body content (no length limit)
|
|
73
52
|
/// @z.string()
|
|
74
53
|
/// @v.string()
|
|
75
|
-
content: varchar('content', { length:
|
|
76
|
-
///
|
|
77
|
-
/// @z.
|
|
78
|
-
/// @v.
|
|
79
|
-
|
|
80
|
-
/// Timestamp when the post was last updated.
|
|
81
|
-
/// @z.date()
|
|
82
|
-
/// @v.date()
|
|
83
|
-
updatedAt: timestamp('updated_at', { mode: 'string' })
|
|
84
|
-
.notNull()
|
|
85
|
-
.default(sql`CURRENT_TIMESTAMP`)
|
|
86
|
-
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
|
54
|
+
content: varchar('content', { length: 65535 }).notNull(),
|
|
55
|
+
/// Foreign key referencing User.id
|
|
56
|
+
/// @z.uuid()
|
|
57
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
58
|
+
userId: varchar('user_id', { length: 36 }).notNull(),
|
|
87
59
|
})
|
|
88
60
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.notNull()
|
|
115
|
-
.default(sql`CURRENT_TIMESTAMP`),
|
|
61
|
+
export const userRelations = relations(user, ({ many }) => ({
|
|
62
|
+
posts: many(post),
|
|
63
|
+
}))
|
|
64
|
+
|
|
65
|
+
export const postRelations = relations(post, ({ one }) => ({
|
|
66
|
+
user: one(user, {
|
|
67
|
+
fields: [post.userId],
|
|
68
|
+
references: [user.id],
|
|
69
|
+
}),
|
|
70
|
+
}))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Prepare sizuku.json:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"input": "db/schema.ts",
|
|
78
|
+
"zod": {
|
|
79
|
+
"output": "zod/index.ts",
|
|
80
|
+
"comment": true,
|
|
81
|
+
"type": true
|
|
82
|
+
},
|
|
83
|
+
"valibot": {
|
|
84
|
+
"output": "valibot/index.ts",
|
|
85
|
+
"comment": true
|
|
116
86
|
},
|
|
117
|
-
|
|
118
|
-
|
|
87
|
+
"mermaid": {
|
|
88
|
+
"output": "mermaid-er/ER.md"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
119
91
|
```
|
|
120
92
|
|
|
121
|
-
|
|
93
|
+
Run Sizuku:
|
|
122
94
|
|
|
123
|
-
```
|
|
124
|
-
npx sizuku
|
|
95
|
+
```sh
|
|
96
|
+
npx sizuku
|
|
125
97
|
```
|
|
126
98
|
|
|
127
|
-
|
|
99
|
+
### Zod
|
|
128
100
|
|
|
129
101
|
```ts
|
|
130
|
-
import { z } from 'zod'
|
|
102
|
+
import { z } from 'zod/v4'
|
|
131
103
|
|
|
132
104
|
export const UserSchema = z.object({
|
|
133
105
|
/**
|
|
134
|
-
*
|
|
135
|
-
*/
|
|
136
|
-
id: z.string().uuid(),
|
|
137
|
-
/**
|
|
138
|
-
* Username of the user.
|
|
139
|
-
*/
|
|
140
|
-
username: z.string(),
|
|
141
|
-
/**
|
|
142
|
-
* Email address of the user.
|
|
143
|
-
*/
|
|
144
|
-
email: z.string().email(),
|
|
145
|
-
/**
|
|
146
|
-
* Password for the user.
|
|
106
|
+
* Primary key
|
|
147
107
|
*/
|
|
148
|
-
|
|
108
|
+
id: z.uuid(),
|
|
149
109
|
/**
|
|
150
|
-
*
|
|
110
|
+
* Display name
|
|
151
111
|
*/
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Timestamp when the user was last updated.
|
|
155
|
-
*/
|
|
156
|
-
updatedAt: z.date(),
|
|
112
|
+
name: z.string().min(1).max(50),
|
|
157
113
|
})
|
|
158
114
|
|
|
115
|
+
export type User = z.infer<typeof UserSchema>
|
|
116
|
+
|
|
159
117
|
export const PostSchema = z.object({
|
|
160
118
|
/**
|
|
161
|
-
*
|
|
119
|
+
* Primary key
|
|
162
120
|
*/
|
|
163
|
-
id: z.
|
|
121
|
+
id: z.uuid(),
|
|
164
122
|
/**
|
|
165
|
-
*
|
|
123
|
+
* Article title
|
|
166
124
|
*/
|
|
167
|
-
|
|
125
|
+
title: z.string().min(1).max(100),
|
|
168
126
|
/**
|
|
169
|
-
*
|
|
127
|
+
* Body content (no length limit)
|
|
170
128
|
*/
|
|
171
129
|
content: z.string(),
|
|
172
130
|
/**
|
|
173
|
-
*
|
|
174
|
-
*/
|
|
175
|
-
createdAt: z.date(),
|
|
176
|
-
/**
|
|
177
|
-
* Timestamp when the post was last updated.
|
|
131
|
+
* Foreign key referencing User.id
|
|
178
132
|
*/
|
|
179
|
-
|
|
133
|
+
userId: z.uuid(),
|
|
180
134
|
})
|
|
181
135
|
|
|
182
|
-
export
|
|
183
|
-
/**
|
|
184
|
-
* Unique identifier for the like.
|
|
185
|
-
*/
|
|
186
|
-
id: z.string().uuid(),
|
|
187
|
-
/**
|
|
188
|
-
* ID of the post that is liked.
|
|
189
|
-
*/
|
|
190
|
-
postId: z.string().uuid(),
|
|
191
|
-
/**
|
|
192
|
-
* ID of the user who liked the post.
|
|
193
|
-
*/
|
|
194
|
-
userId: z.string().uuid(),
|
|
195
|
-
/**
|
|
196
|
-
* Timestamp when the like was created.
|
|
197
|
-
*/
|
|
198
|
-
createdAt: z.date(),
|
|
199
|
-
})
|
|
136
|
+
export type Post = z.infer<typeof PostSchema>
|
|
200
137
|
```
|
|
201
138
|
|
|
202
139
|
### Valibot
|
|
203
140
|
|
|
204
|
-
```bash
|
|
205
|
-
npx sizuku-valibot path/to/db/schema.ts -o path/to/output.ts
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
output:
|
|
209
|
-
|
|
210
141
|
```ts
|
|
211
142
|
import * as v from 'valibot'
|
|
212
143
|
|
|
213
144
|
export const UserSchema = v.object({
|
|
214
145
|
/**
|
|
215
|
-
*
|
|
146
|
+
* Primary key
|
|
216
147
|
*/
|
|
217
148
|
id: v.pipe(v.string(), v.uuid()),
|
|
218
149
|
/**
|
|
219
|
-
*
|
|
220
|
-
*/
|
|
221
|
-
username: v.string(),
|
|
222
|
-
/**
|
|
223
|
-
* Email address of the user.
|
|
150
|
+
* Display name
|
|
224
151
|
*/
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Password for the user.
|
|
228
|
-
*/
|
|
229
|
-
password: v.pipe(v.string(), v.minLength(8), v.maxLength(100)),
|
|
230
|
-
/**
|
|
231
|
-
* Timestamp when the user was created.
|
|
232
|
-
*/
|
|
233
|
-
createdAt: v.date(),
|
|
234
|
-
/**
|
|
235
|
-
* Timestamp when the user was last updated.
|
|
236
|
-
*/
|
|
237
|
-
updatedAt: v.date(),
|
|
152
|
+
name: v.pipe(v.string(), v.minLength(1), v.maxLength(50)),
|
|
238
153
|
})
|
|
239
154
|
|
|
155
|
+
export type User = v.InferInput<typeof UserSchema>
|
|
156
|
+
|
|
240
157
|
export const PostSchema = v.object({
|
|
241
158
|
/**
|
|
242
|
-
*
|
|
159
|
+
* Primary key
|
|
243
160
|
*/
|
|
244
161
|
id: v.pipe(v.string(), v.uuid()),
|
|
245
162
|
/**
|
|
246
|
-
*
|
|
163
|
+
* Article title
|
|
247
164
|
*/
|
|
248
|
-
|
|
165
|
+
title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
|
|
249
166
|
/**
|
|
250
|
-
*
|
|
167
|
+
* Body content (no length limit)
|
|
251
168
|
*/
|
|
252
169
|
content: v.string(),
|
|
253
170
|
/**
|
|
254
|
-
*
|
|
255
|
-
*/
|
|
256
|
-
createdAt: v.date(),
|
|
257
|
-
/**
|
|
258
|
-
* Timestamp when the post was last updated.
|
|
259
|
-
*/
|
|
260
|
-
updatedAt: v.date(),
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
export const LikesSchema = v.object({
|
|
264
|
-
/**
|
|
265
|
-
* Unique identifier for the like.
|
|
266
|
-
*/
|
|
267
|
-
id: v.pipe(v.string(), v.uuid()),
|
|
268
|
-
/**
|
|
269
|
-
* ID of the post that is liked.
|
|
270
|
-
*/
|
|
271
|
-
postId: v.pipe(v.string(), v.uuid()),
|
|
272
|
-
/**
|
|
273
|
-
* ID of the user who liked the post.
|
|
171
|
+
* Foreign key referencing User.id
|
|
274
172
|
*/
|
|
275
173
|
userId: v.pipe(v.string(), v.uuid()),
|
|
276
|
-
/**
|
|
277
|
-
* Timestamp when the like was created.
|
|
278
|
-
*/
|
|
279
|
-
createdAt: v.date(),
|
|
280
174
|
})
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
### Mermaid ER
|
|
284
175
|
|
|
285
|
-
|
|
286
|
-
npx sizuku-mermaid-er path/to/db/schema.ts -o path/to/output.md
|
|
176
|
+
export type Post = v.InferInput<typeof PostSchema>
|
|
287
177
|
```
|
|
288
178
|
|
|
289
|
-
|
|
179
|
+
### Mermaid ER
|
|
290
180
|
|
|
291
181
|
```mermaid
|
|
292
182
|
erDiagram
|
|
293
183
|
user ||--}| post : "(id) - (userId)"
|
|
294
|
-
post ||--}| likes : "(id) - (postId)"
|
|
295
|
-
user ||--}| likes : "(id) - (userId)"
|
|
296
184
|
user {
|
|
297
|
-
varchar id "(PK)
|
|
298
|
-
varchar
|
|
299
|
-
varchar email "Email address of the user."
|
|
300
|
-
varchar password "Password for the user."
|
|
301
|
-
timestamp createdAt "Timestamp when the user was created."
|
|
302
|
-
timestamp updatedAt "Timestamp when the user was last updated."
|
|
185
|
+
varchar id "(PK) Primary key"
|
|
186
|
+
varchar name "Display name"
|
|
303
187
|
}
|
|
304
188
|
post {
|
|
305
|
-
varchar id "(PK)
|
|
306
|
-
varchar
|
|
307
|
-
varchar content "
|
|
308
|
-
|
|
309
|
-
timestamp updatedAt "Timestamp when the post was last updated."
|
|
310
|
-
}
|
|
311
|
-
likes {
|
|
312
|
-
varchar id "(PK) Unique identifier for the like."
|
|
313
|
-
varchar postId "(FK) ID of the post that is liked."
|
|
314
|
-
varchar userId "(FK) ID of the user who liked the post."
|
|
315
|
-
timestamp createdAt "Timestamp when the like was created."
|
|
189
|
+
varchar id "(PK) Primary key"
|
|
190
|
+
varchar title "Article title"
|
|
191
|
+
varchar content "Body content (no length limit)"
|
|
192
|
+
varchar userId "Foreign key referencing User.id"
|
|
316
193
|
}
|
|
317
194
|
```
|
|
318
195
|
|
|
319
|
-
## Configuration
|
|
320
|
-
|
|
321
|
-
### sizuku-zod.json
|
|
322
|
-
|
|
323
|
-
#### Schema Options
|
|
324
|
-
|
|
325
|
-
| Option | Type | Default | Description |
|
|
326
|
-
|--------|------|---------|-------------|
|
|
327
|
-
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated schema variables |
|
|
328
|
-
| `export` | `boolean` | `false` | When true, exports all schema definitions |
|
|
329
|
-
|
|
330
|
-
#### Type Options
|
|
331
|
-
|
|
332
|
-
| Option | Type | Default | Description |
|
|
333
|
-
|--------|------|---------|-------------|
|
|
334
|
-
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated type definitions |
|
|
335
|
-
| `export` | `boolean` | `false` | When true, exports all type definitions |
|
|
336
|
-
|
|
337
|
-
#### Comment Options
|
|
338
|
-
|
|
339
|
-
| Option | Type | Default | Description |
|
|
340
|
-
|--------|------|---------|-------------|
|
|
341
|
-
| `name` | `boolean` | `false` | If enabled, includes the element's original name in TSDoc comments. |
|
|
342
|
-
|
|
343
|
-
#### Input and Output
|
|
344
|
-
|
|
345
|
-
| Option | Type | Default | Description |
|
|
346
|
-
|--------|------|---------|-------------|
|
|
347
|
-
| `input` | `string` | `""` | Input file path |
|
|
348
|
-
| `output` | `string` | `""` | Output file path |
|
|
349
|
-
|
|
350
|
-
#### Example
|
|
351
|
-
|
|
352
|
-
```json
|
|
353
|
-
{
|
|
354
|
-
"schema": {
|
|
355
|
-
"name": "PascalCase"
|
|
356
|
-
},
|
|
357
|
-
"type": {
|
|
358
|
-
"name": "PascalCase",
|
|
359
|
-
"export": false
|
|
360
|
-
},
|
|
361
|
-
"comment": true,
|
|
362
|
-
"input": "db/schema.ts",
|
|
363
|
-
"output": "zod/index.ts"
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
> **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
|
|
368
|
-
>
|
|
369
|
-
> When you have configured `sizuku-zod.json`, you can simply run:
|
|
370
|
-
> ```bash
|
|
371
|
-
> npx sizuku-zod
|
|
372
|
-
> ```
|
|
373
|
-
|
|
374
|
-
### sizuku-valibot.json
|
|
375
|
-
|
|
376
|
-
#### Schema Options
|
|
377
|
-
|
|
378
|
-
| Option | Type | Default | Description |
|
|
379
|
-
|----------|---------------------------------|----------------|--------------------------------------------|
|
|
380
|
-
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated schema variables |
|
|
381
|
-
| `export` | `boolean` | `false` | When true, exports all schema definitions |
|
|
382
|
-
|
|
383
|
-
#### Type Options
|
|
384
|
-
|
|
385
|
-
| Option | Type | Default | Description |
|
|
386
|
-
|----------|---------------------------------|----------------|-----------------------------------------|
|
|
387
|
-
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated type definitions |
|
|
388
|
-
| `export` | `boolean` | `false` | When true, exports all type definitions |
|
|
389
|
-
|
|
390
|
-
#### Comment Options
|
|
391
|
-
|
|
392
|
-
| Option | Type | Default | Description |
|
|
393
|
-
|--------|----------------|---------|---------------------------------------------------------------------|
|
|
394
|
-
| `name` | `boolean` | `false` | If enabled, includes the element's original name in TSDoc comments. |
|
|
395
|
-
|
|
396
|
-
#### Input and Output
|
|
397
|
-
|
|
398
|
-
| Option | Type | Default | Description |
|
|
399
|
-
|--------|------|-------------|-------------|
|
|
400
|
-
| `input` | `string` | `""` | Input file path |
|
|
401
|
-
| `output` | `string` | `""` | Output file path |
|
|
402
|
-
|
|
403
|
-
#### Examples
|
|
404
|
-
|
|
405
|
-
```json
|
|
406
|
-
{
|
|
407
|
-
"schema": {
|
|
408
|
-
"name": "PascalCase"
|
|
409
|
-
},
|
|
410
|
-
"type": {
|
|
411
|
-
"name": "PascalCase",
|
|
412
|
-
"export": false
|
|
413
|
-
},
|
|
414
|
-
"comment": true,
|
|
415
|
-
"input": "db/schema.ts",
|
|
416
|
-
"output": "valibot/index.ts"
|
|
417
|
-
}
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
> **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
|
|
421
|
-
>
|
|
422
|
-
> When you have configured `sizuku-valibot.json`, you can simply run:
|
|
423
|
-
> ```bash
|
|
424
|
-
> npx sizuku-valibot
|
|
425
|
-
> ```
|
|
426
|
-
|
|
427
|
-
### sizuku-mermaid-er.json
|
|
428
|
-
|
|
429
|
-
| Option | Type | Default | Description |
|
|
430
|
-
|----------|----------|------------|------------------|
|
|
431
|
-
| `input` | `string` | `""` | Input file path |
|
|
432
|
-
| `output` | `string` | `""` | Output file path |
|
|
433
|
-
|
|
434
|
-
#### Example
|
|
435
|
-
|
|
436
|
-
```json
|
|
437
|
-
{
|
|
438
|
-
"input": "db/schema.ts",
|
|
439
|
-
"output": "mermaid-er/ER.md"
|
|
440
|
-
}
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
> **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
|
|
444
|
-
>
|
|
445
|
-
> When you have configured `sizuku-mermaid-er.json`, you can simply run:
|
|
446
|
-
> ```bash
|
|
447
|
-
> npx sizuku-mermaid-er
|
|
448
|
-
> ```
|
|
449
|
-
|
|
450
196
|
This project is in **early development** and being maintained by a developer with about 2 years of experience. While I'm doing my best to create a useful tool:
|
|
451
197
|
|
|
452
198
|
### ⚠️ WARNING: Potential Breaking Changes Without Notice
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Config = {
|
|
2
|
+
input?: `${string}.ts`;
|
|
3
|
+
zod?: {
|
|
4
|
+
output?: `${string}.ts`;
|
|
5
|
+
comment?: boolean;
|
|
6
|
+
type?: boolean;
|
|
7
|
+
zod?: 'v4' | 'v4-mini' | '@hono/zod-openapi';
|
|
8
|
+
};
|
|
9
|
+
valibot?: {
|
|
10
|
+
output?: `${string}.ts`;
|
|
11
|
+
comment?: boolean;
|
|
12
|
+
type?: boolean;
|
|
13
|
+
};
|
|
14
|
+
mermaid?: {
|
|
15
|
+
output?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function getConfig(): Config;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
export function getConfig() {
|
|
3
|
+
if (!fs.existsSync('sizuku.json')) {
|
|
4
|
+
throw new Error('sizuku.json not found');
|
|
5
|
+
}
|
|
6
|
+
const parsed = JSON.parse(fs.readFileSync('sizuku.json', 'utf-8'));
|
|
7
|
+
return {
|
|
8
|
+
input: parsed.input,
|
|
9
|
+
zod: parsed.zod,
|
|
10
|
+
valibot: parsed.valibot,
|
|
11
|
+
mermaid: parsed.mermaid,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type Config = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
input?: string
|
|
3
|
+
output?: string
|
|
4
|
+
}
|
|
5
5
|
/**
|
|
6
6
|
* Loads the configuration from the `sizuku.json` file or returns the default configuration.
|
|
7
7
|
*
|
|
8
8
|
* @returns The configuration object.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getConfig(): Config
|
|
10
|
+
export declare function getConfig(): Config
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getConfig = getConfig;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
1
|
+
import fs from 'node:fs';
|
|
8
2
|
/**
|
|
9
3
|
* Loads the configuration from the `sizuku.json` file or returns the default configuration.
|
|
10
4
|
*
|
|
11
5
|
* @returns The configuration object.
|
|
12
6
|
*/
|
|
13
|
-
function getConfig() {
|
|
14
|
-
const config =
|
|
15
|
-
? { ...JSON.parse(
|
|
7
|
+
export function getConfig() {
|
|
8
|
+
const config = fs.existsSync('sizuku-mermaid-er.json')
|
|
9
|
+
? { ...JSON.parse(fs.readFileSync('sizuku-mermaid-er.json', 'utf-8')) }
|
|
16
10
|
: {};
|
|
17
11
|
return config;
|
|
18
12
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractRelations = extractRelations;
|
|
4
|
-
const parse_relation_line_1 = require("../validator/parse-relation-line");
|
|
1
|
+
import { parseRelationLine } from '../validator/parse-relation-line.js';
|
|
5
2
|
/**
|
|
6
3
|
* Extracts relations from the given code.
|
|
7
4
|
*
|
|
8
5
|
* @param code - The code to extract relations from.
|
|
9
6
|
* @returns The extracted relations.
|
|
10
7
|
*/
|
|
11
|
-
function extractRelations(code) {
|
|
8
|
+
export function extractRelations(code) {
|
|
12
9
|
const relations = [];
|
|
13
10
|
for (const line of code) {
|
|
14
|
-
const relation =
|
|
11
|
+
const relation = parseRelationLine(line);
|
|
15
12
|
if (relation) {
|
|
16
13
|
relations.push(relation);
|
|
17
14
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Relation, TableInfo } from '../
|
|
1
|
+
import type { Relation, TableInfo } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Generate ER content
|
|
4
|
-
* @function generateERContent
|
|
5
4
|
* @param relations - The relations to generate the ER content from
|
|
6
5
|
* @param tables - The tables to generate the ER content from
|
|
7
6
|
* @returns The generated ER content
|
|
8
7
|
*/
|
|
9
|
-
export declare function
|
|
8
|
+
export declare function erContent(relations: Relation[], tables: TableInfo[]): string;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateERContent = generateERContent;
|
|
4
|
-
const generate_relation_line_1 = require("./generate-relation-line");
|
|
1
|
+
import { relationLine } from './index.js';
|
|
5
2
|
const ER_HEADER = ['```mermaid', 'erDiagram'];
|
|
6
3
|
const ER_FOOTER = ['```'];
|
|
7
4
|
/**
|
|
8
5
|
* Generate ER content
|
|
9
|
-
* @function generateERContent
|
|
10
6
|
* @param relations - The relations to generate the ER content from
|
|
11
7
|
* @param tables - The tables to generate the ER content from
|
|
12
8
|
* @returns The generated ER content
|
|
13
9
|
*/
|
|
14
|
-
function
|
|
10
|
+
export function erContent(relations, tables) {
|
|
15
11
|
const erContent = [
|
|
16
12
|
...ER_HEADER,
|
|
17
|
-
...relations.map(
|
|
13
|
+
...relations.map(relationLine),
|
|
18
14
|
// Generate per-table definitions
|
|
19
15
|
...tables.flatMap((table) => [
|
|
20
16
|
` ${table.name} {`,
|
package/dist/generator/mermaid-er/generator/{generate-relation-line.d.ts → relation-line.d.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Relation } from '../
|
|
1
|
+
import type { Relation } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Generate a relation line for a relation
|
|
4
4
|
* @param relation - The relation to generate a line for
|
|
5
5
|
* @returns The generated relation line
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function relationLine(relation: Relation): string;
|