sizuku 0.0.1
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 +471 -0
- package/dist/common/config/index.d.ts +13 -0
- package/dist/common/config/index.js +13 -0
- package/dist/common/format/index.d.ts +1 -0
- package/dist/common/format/index.js +12 -0
- package/dist/common/generator/generate-field-definitions.d.ts +8 -0
- package/dist/common/generator/generate-field-definitions.js +16 -0
- package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +7 -0
- package/dist/common/helper/get-camel-case-schema-name-helper.js +14 -0
- package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +8 -0
- package/dist/common/helper/get-pascal-case-schema-name-helper.js +15 -0
- package/dist/common/helper/get-variable-name-helper.d.ts +9 -0
- package/dist/common/helper/get-variable-name-helper.js +15 -0
- package/dist/common/helper/get-variable-schema-name-helper.d.ts +9 -0
- package/dist/common/helper/get-variable-schema-name-helper.js +17 -0
- package/dist/common/text/capitalize.d.ts +18 -0
- package/dist/common/text/capitalize.js +23 -0
- package/dist/common/text/decapitalize.d.ts +17 -0
- package/dist/common/text/decapitalize.js +22 -0
- package/dist/common/type/index.d.ts +9 -0
- package/dist/common/type/index.js +2 -0
- package/dist/generator/mermaid-er/config/index.d.ts +10 -0
- package/dist/generator/mermaid-er/config/index.js +18 -0
- package/dist/generator/mermaid-er/core/extract-relations.d.ts +8 -0
- package/dist/generator/mermaid-er/core/extract-relations.js +20 -0
- package/dist/generator/mermaid-er/generator/generate-er-content.d.ts +9 -0
- package/dist/generator/mermaid-er/generator/generate-er-content.js +27 -0
- package/dist/generator/mermaid-er/generator/generate-relation-line.d.ts +7 -0
- package/dist/generator/mermaid-er/generator/generate-relation-line.js +16 -0
- package/dist/generator/mermaid-er/index.d.ts +7 -0
- package/dist/generator/mermaid-er/index.js +102 -0
- package/dist/generator/mermaid-er/type/index.d.ts +40 -0
- package/dist/generator/mermaid-er/type/index.js +2 -0
- package/dist/generator/mermaid-er/validator/is-relation.d.ts +7 -0
- package/dist/generator/mermaid-er/validator/is-relation.js +40 -0
- package/dist/generator/mermaid-er/validator/parse-relation-line.d.ts +12 -0
- package/dist/generator/mermaid-er/validator/parse-relation-line.js +28 -0
- package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +8 -0
- package/dist/generator/mermaid-er/validator/parse-table-info.js +91 -0
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +7 -0
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +12 -0
- package/dist/generator/valibot/config/index.d.ts +7 -0
- package/dist/generator/valibot/config/index.js +19 -0
- package/dist/generator/valibot/core/extract-schema.d.ts +8 -0
- package/dist/generator/valibot/core/extract-schema.js +92 -0
- package/dist/generator/valibot/generator/generate-valibot-code.d.ts +11 -0
- package/dist/generator/valibot/generator/generate-valibot-code.js +21 -0
- package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +9 -0
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +16 -0
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +9 -0
- package/dist/generator/valibot/generator/generate-valibot-schema.js +16 -0
- package/dist/generator/valibot/index.d.ts +3 -0
- package/dist/generator/valibot/index.js +77 -0
- package/dist/generator/zod/config/index.d.ts +8 -0
- package/dist/generator/zod/config/index.js +20 -0
- package/dist/generator/zod/core/extract-schema.d.ts +8 -0
- package/dist/generator/zod/core/extract-schema.js +96 -0
- package/dist/generator/zod/generator/generate-z-infer.d.ts +11 -0
- package/dist/generator/zod/generator/generate-z-infer.js +18 -0
- package/dist/generator/zod/generator/generate-zod-code.d.ts +11 -0
- package/dist/generator/zod/generator/generate-zod-code.js +21 -0
- package/dist/generator/zod/generator/generate-zod-schema.d.ts +11 -0
- package/dist/generator/zod/generator/generate-zod-schema.js +17 -0
- package/dist/generator/zod/index.d.ts +3 -0
- package/dist/generator/zod/index.js +77 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
# Sizuku
|
|
2
|
+
|
|
3
|
+
Welcome to **Sizuku**! This tool takes annotations in your code comments and turns them into useful documentation and validation artifacts automatically. Whether you’re looking to visualize your database schema, generate detailed ER documentation, or create type-safe validation schemas, Sizuku has got you covered.
|
|
4
|
+
|
|
5
|
+
## What Can Sizuku Do for You?
|
|
6
|
+
|
|
7
|
+
- **Mermaid ER Diagrams:** Easily see your database tables and how they relate to one another with a clear, visual diagram generated in Mermaid syntax.
|
|
8
|
+
- **ER Definitions:** Automatically create comprehensive documentation of your database schema, including detailed column definitions, relationships, and more.
|
|
9
|
+
- **Validation Schemas:** Generate type-safe validation schemas using either [Zod](https://zod.dev/) or [Valibot](https://valibot.dev/) based on your code annotations (`@z` for Zod, `@v` for Valibot).
|
|
10
|
+
- **Clear Relationship Definitions:** Use the `@relation` annotation in your code to explicitly define how tables are linked (e.g., one-to-many, many-to-many). This ensures that both your ER diagrams and documentation accurately reflect your database relationships.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
### Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -D sizuku
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Example
|
|
24
|
+
|
|
25
|
+
input:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { sql } from 'drizzle-orm'
|
|
29
|
+
import { mysqlTable, varchar, timestamp, unique } from 'drizzle-orm/mysql-core'
|
|
30
|
+
|
|
31
|
+
export const user = mysqlTable('user', {
|
|
32
|
+
/// Unique identifier for the user.
|
|
33
|
+
/// @z.string().uuid()
|
|
34
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
35
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
36
|
+
/// Username of the user.
|
|
37
|
+
/// @z.string()
|
|
38
|
+
/// @v.string()
|
|
39
|
+
username: varchar('username', { length: 255 }).notNull(),
|
|
40
|
+
/// Email address of the user.
|
|
41
|
+
/// @z.string().email()
|
|
42
|
+
/// @v.pipe(v.string(), v.email())
|
|
43
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
44
|
+
/// Password for the user.
|
|
45
|
+
/// @z.string().min(8).max(100)
|
|
46
|
+
/// @v.pipe(v.string(), v.minLength(8), v.maxLength(100))
|
|
47
|
+
password: varchar('password', { length: 100 }).notNull(),
|
|
48
|
+
/// Timestamp when the user was created.
|
|
49
|
+
/// @z.date()
|
|
50
|
+
/// @v.date()
|
|
51
|
+
createdAt: timestamp('created_at', { mode: 'string' }).notNull().default(sql`CURRENT_TIMESTAMP`),
|
|
52
|
+
/// Timestamp when the user was last updated.
|
|
53
|
+
/// @z.date()
|
|
54
|
+
/// @v.date()
|
|
55
|
+
updatedAt: timestamp('updated_at', { mode: 'string' })
|
|
56
|
+
.notNull()
|
|
57
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
58
|
+
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
/// @relation user.id post.userId one-to-many
|
|
62
|
+
export const post = mysqlTable('post', {
|
|
63
|
+
/// Unique identifier for the post.
|
|
64
|
+
/// @z.string().uuid()
|
|
65
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
66
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
67
|
+
/// ID of the user who created the post.
|
|
68
|
+
/// @z.string().uuid()
|
|
69
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
70
|
+
userId: varchar('user_id', { length: 36 })
|
|
71
|
+
.notNull()
|
|
72
|
+
.references(() => user.id, { onDelete: 'cascade' }),
|
|
73
|
+
/// Content of the post.
|
|
74
|
+
/// @z.string()
|
|
75
|
+
/// @v.string()
|
|
76
|
+
content: varchar('content', { length: 500 }).notNull(),
|
|
77
|
+
/// Timestamp when the post was created.
|
|
78
|
+
/// @z.date()
|
|
79
|
+
/// @v.date()
|
|
80
|
+
createdAt: timestamp('created_at', { mode: 'string' }).notNull().default(sql`CURRENT_TIMESTAMP`),
|
|
81
|
+
/// Timestamp when the post was last updated.
|
|
82
|
+
/// @z.date()
|
|
83
|
+
/// @v.date()
|
|
84
|
+
updatedAt: timestamp('updated_at', { mode: 'string' })
|
|
85
|
+
.notNull()
|
|
86
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
87
|
+
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
/// @relation post.id likes.postId one-to-many
|
|
91
|
+
/// @relation user.id likes.userId one-to-many
|
|
92
|
+
export const likes = mysqlTable(
|
|
93
|
+
'likes',
|
|
94
|
+
{
|
|
95
|
+
/// Unique identifier for the like.
|
|
96
|
+
/// @z.string().uuid()
|
|
97
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
98
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
99
|
+
/// ID of the post that is liked.
|
|
100
|
+
/// @z.string().uuid()
|
|
101
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
102
|
+
postId: varchar('post_id', { length: 36 })
|
|
103
|
+
.notNull()
|
|
104
|
+
.references(() => post.id, { onDelete: 'cascade' }),
|
|
105
|
+
/// ID of the user who liked the post.
|
|
106
|
+
/// @z.string().uuid()
|
|
107
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
108
|
+
userId: varchar('user_id', { length: 36 })
|
|
109
|
+
.notNull()
|
|
110
|
+
.references(() => user.id, { onDelete: 'cascade' }),
|
|
111
|
+
/// Timestamp when the like was created.
|
|
112
|
+
/// @z.date()
|
|
113
|
+
/// @v.date()
|
|
114
|
+
createdAt: timestamp('created_at', { mode: 'string' })
|
|
115
|
+
.notNull()
|
|
116
|
+
.default(sql`CURRENT_TIMESTAMP`),
|
|
117
|
+
},
|
|
118
|
+
(t) => [unique().on(t.userId, t.postId)],
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Mermaid ER
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npx sizuku-mermaid-er path/to/db/schema.ts -o path/to/output.md
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
output:
|
|
129
|
+
|
|
130
|
+
```mermaid
|
|
131
|
+
erDiagram
|
|
132
|
+
user ||--o{ post : "(id) - (userId)"
|
|
133
|
+
post ||--o{ likes : "(id) - (postId)"
|
|
134
|
+
user ||--o{ likes : "(id) - (userId)"
|
|
135
|
+
user {
|
|
136
|
+
varchar id "(PK) Unique identifier for the user."
|
|
137
|
+
varchar username "Username of the user."
|
|
138
|
+
varchar email "Email address of the user."
|
|
139
|
+
varchar password "Password for the user."
|
|
140
|
+
timestamp createdAt "Timestamp when the user was created."
|
|
141
|
+
timestamp updatedAt "Timestamp when the user was last updated."
|
|
142
|
+
}
|
|
143
|
+
post {
|
|
144
|
+
varchar id "(PK) Unique identifier for the post."
|
|
145
|
+
varchar userId "(FK) ID of the user who created the post."
|
|
146
|
+
varchar content "Content of the post."
|
|
147
|
+
timestamp createdAt "Timestamp when the post was created."
|
|
148
|
+
timestamp updatedAt "Timestamp when the post was last updated."
|
|
149
|
+
}
|
|
150
|
+
likes {
|
|
151
|
+
varchar id "(PK) Unique identifier for the like."
|
|
152
|
+
varchar postId "(FK) ID of the post that is liked."
|
|
153
|
+
varchar userId "(FK) ID of the user who liked the post."
|
|
154
|
+
timestamp createdAt "Timestamp when the like was created."
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Zod
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npx sizuku-zod path/to/db/schema.ts -o path/to/output.ts
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
output:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { z } from 'zod'
|
|
168
|
+
|
|
169
|
+
export const UserSchema = z.object({
|
|
170
|
+
/**
|
|
171
|
+
* Unique identifier for the user.
|
|
172
|
+
*/
|
|
173
|
+
id: z.string().uuid(),
|
|
174
|
+
/**
|
|
175
|
+
* Username of the user.
|
|
176
|
+
*/
|
|
177
|
+
username: z.string(),
|
|
178
|
+
/**
|
|
179
|
+
* Email address of the user.
|
|
180
|
+
*/
|
|
181
|
+
email: z.string().email(),
|
|
182
|
+
/**
|
|
183
|
+
* Password for the user.
|
|
184
|
+
*/
|
|
185
|
+
password: z.string().min(8).max(100),
|
|
186
|
+
/**
|
|
187
|
+
* Timestamp when the user was created.
|
|
188
|
+
*/
|
|
189
|
+
createdAt: z.date(),
|
|
190
|
+
/**
|
|
191
|
+
* Timestamp when the user was last updated.
|
|
192
|
+
*/
|
|
193
|
+
updatedAt: z.date(),
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
export const PostSchema = z.object({
|
|
197
|
+
/**
|
|
198
|
+
* Unique identifier for the post.
|
|
199
|
+
*/
|
|
200
|
+
id: z.string().uuid(),
|
|
201
|
+
/**
|
|
202
|
+
* ID of the user who created the post.
|
|
203
|
+
*/
|
|
204
|
+
userId: z.string().uuid(),
|
|
205
|
+
/**
|
|
206
|
+
* Content of the post.
|
|
207
|
+
*/
|
|
208
|
+
content: z.string(),
|
|
209
|
+
/**
|
|
210
|
+
* Timestamp when the post was created.
|
|
211
|
+
*/
|
|
212
|
+
createdAt: z.date(),
|
|
213
|
+
/**
|
|
214
|
+
* Timestamp when the post was last updated.
|
|
215
|
+
*/
|
|
216
|
+
updatedAt: z.date(),
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
export const LikesSchema = z.object({
|
|
220
|
+
/**
|
|
221
|
+
* Unique identifier for the like.
|
|
222
|
+
*/
|
|
223
|
+
id: z.string().uuid(),
|
|
224
|
+
/**
|
|
225
|
+
* ID of the post that is liked.
|
|
226
|
+
*/
|
|
227
|
+
postId: z.string().uuid(),
|
|
228
|
+
/**
|
|
229
|
+
* ID of the user who liked the post.
|
|
230
|
+
*/
|
|
231
|
+
userId: z.string().uuid(),
|
|
232
|
+
/**
|
|
233
|
+
* Timestamp when the like was created.
|
|
234
|
+
*/
|
|
235
|
+
createdAt: z.date(),
|
|
236
|
+
})
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Valibot
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
npx sizuku-valibot path/to/db/schema.ts -o path/to/output.ts
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
output:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import * as v from 'valibot'
|
|
249
|
+
|
|
250
|
+
export const UserSchema = v.object({
|
|
251
|
+
/**
|
|
252
|
+
* Unique identifier for the user.
|
|
253
|
+
*/
|
|
254
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
255
|
+
/**
|
|
256
|
+
* Username of the user.
|
|
257
|
+
*/
|
|
258
|
+
username: v.string(),
|
|
259
|
+
/**
|
|
260
|
+
* Email address of the user.
|
|
261
|
+
*/
|
|
262
|
+
email: v.pipe(v.string(), v.email()),
|
|
263
|
+
/**
|
|
264
|
+
* Password for the user.
|
|
265
|
+
*/
|
|
266
|
+
password: v.pipe(v.string(), v.minLength(8), v.maxLength(100)),
|
|
267
|
+
/**
|
|
268
|
+
* Timestamp when the user was created.
|
|
269
|
+
*/
|
|
270
|
+
createdAt: v.date(),
|
|
271
|
+
/**
|
|
272
|
+
* Timestamp when the user was last updated.
|
|
273
|
+
*/
|
|
274
|
+
updatedAt: v.date(),
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
export const PostSchema = v.object({
|
|
278
|
+
/**
|
|
279
|
+
* Unique identifier for the post.
|
|
280
|
+
*/
|
|
281
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
282
|
+
/**
|
|
283
|
+
* ID of the user who created the post.
|
|
284
|
+
*/
|
|
285
|
+
userId: v.pipe(v.string(), v.uuid()),
|
|
286
|
+
/**
|
|
287
|
+
* Content of the post.
|
|
288
|
+
*/
|
|
289
|
+
content: v.string(),
|
|
290
|
+
/**
|
|
291
|
+
* Timestamp when the post was created.
|
|
292
|
+
*/
|
|
293
|
+
createdAt: v.date(),
|
|
294
|
+
/**
|
|
295
|
+
* Timestamp when the post was last updated.
|
|
296
|
+
*/
|
|
297
|
+
updatedAt: v.date(),
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
export const LikesSchema = v.object({
|
|
301
|
+
/**
|
|
302
|
+
* Unique identifier for the like.
|
|
303
|
+
*/
|
|
304
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
305
|
+
/**
|
|
306
|
+
* ID of the post that is liked.
|
|
307
|
+
*/
|
|
308
|
+
postId: v.pipe(v.string(), v.uuid()),
|
|
309
|
+
/**
|
|
310
|
+
* ID of the user who liked the post.
|
|
311
|
+
*/
|
|
312
|
+
userId: v.pipe(v.string(), v.uuid()),
|
|
313
|
+
/**
|
|
314
|
+
* Timestamp when the like was created.
|
|
315
|
+
*/
|
|
316
|
+
createdAt: v.date(),
|
|
317
|
+
})
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Configuration
|
|
321
|
+
|
|
322
|
+
### sizuku-mermaid-er.json
|
|
323
|
+
|
|
324
|
+
| Option | Type | Default | Description |
|
|
325
|
+
|--------|------|---------|-------------|
|
|
326
|
+
| `input` | `string` | `""` | Input file path |
|
|
327
|
+
| `output` | `string` | `""` | Output file path |
|
|
328
|
+
|
|
329
|
+
> **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
|
|
330
|
+
>
|
|
331
|
+
> When you have configured `sizuku-mermaid-er.json`, you can simply run:
|
|
332
|
+
> ```bash
|
|
333
|
+
> npx sizuku-mermaid-er
|
|
334
|
+
> ```
|
|
335
|
+
|
|
336
|
+
#### Example
|
|
337
|
+
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"input": "db/schema.ts",
|
|
341
|
+
"output": "mermaid-er/ER.md"
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### sizuku-zod.json
|
|
346
|
+
|
|
347
|
+
#### Schema Options
|
|
348
|
+
|
|
349
|
+
| Option | Type | Default | Description |
|
|
350
|
+
|--------|------|---------|-------------|
|
|
351
|
+
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated schema variables |
|
|
352
|
+
| `export` | `boolean` | `false` | When true, exports all schema definitions |
|
|
353
|
+
|
|
354
|
+
#### Type Options
|
|
355
|
+
|
|
356
|
+
| Option | Type | Default | Description |
|
|
357
|
+
|--------|------|---------|-------------|
|
|
358
|
+
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated type definitions |
|
|
359
|
+
| `export` | `boolean` | `false` | When true, exports all type definitions |
|
|
360
|
+
|
|
361
|
+
#### Comment Options
|
|
362
|
+
|
|
363
|
+
| Option | Type | Default | Description |
|
|
364
|
+
|--------|------|---------|-------------|
|
|
365
|
+
| `name` | `boolean` | `false` | If enabled, includes the element's original name in TSDoc comments. |
|
|
366
|
+
|
|
367
|
+
#### Input and Output
|
|
368
|
+
|
|
369
|
+
| Option | Type | Default | Description |
|
|
370
|
+
|--------|------|---------|-------------|
|
|
371
|
+
| `input` | `string` | `""` | Input file path |
|
|
372
|
+
| `output` | `string` | `""` | Output file path |
|
|
373
|
+
|
|
374
|
+
#### Example
|
|
375
|
+
|
|
376
|
+
```json
|
|
377
|
+
{
|
|
378
|
+
"schema": {
|
|
379
|
+
"name": "PascalCase"
|
|
380
|
+
},
|
|
381
|
+
"type": {
|
|
382
|
+
"name": "PascalCase",
|
|
383
|
+
"export": false
|
|
384
|
+
},
|
|
385
|
+
"comment": true,
|
|
386
|
+
"input": "db/schema.ts",
|
|
387
|
+
"output": "zod/index.ts"
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
> **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
|
|
392
|
+
>
|
|
393
|
+
> When you have configured `sizuku-zod.json`, you can simply run:
|
|
394
|
+
> ```bash
|
|
395
|
+
> npx sizuku-zod
|
|
396
|
+
> ```
|
|
397
|
+
|
|
398
|
+
### sizuku-valibot.json
|
|
399
|
+
|
|
400
|
+
#### Schema Options
|
|
401
|
+
|
|
402
|
+
| Option | Type | Default | Description |
|
|
403
|
+
|--------|------|---------|-------------|
|
|
404
|
+
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated schema variables |
|
|
405
|
+
| `export` | `boolean` | `false` | When true, exports all schema definitions |
|
|
406
|
+
|
|
407
|
+
#### Type Options
|
|
408
|
+
|
|
409
|
+
| Option | Type | Default | Description |
|
|
410
|
+
|--------|------|---------|-------------|
|
|
411
|
+
| `name` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"` | Naming convention for generated type definitions |
|
|
412
|
+
| `export` | `boolean` | `false` | When true, exports all type definitions |
|
|
413
|
+
|
|
414
|
+
#### Comment Options
|
|
415
|
+
|
|
416
|
+
| Option | Type | Default | Description |
|
|
417
|
+
|--------|------|---------|-------------|
|
|
418
|
+
| `name` | `boolean` | `false` | If enabled, includes the element's original name in TSDoc comments. |
|
|
419
|
+
|
|
420
|
+
#### Input and Output
|
|
421
|
+
|
|
422
|
+
| Option | Type | Default | Description |
|
|
423
|
+
|--------|------|---------|-------------|
|
|
424
|
+
| `input` | `string` | `""` | Input file path |
|
|
425
|
+
| `output` | `string` | `""` | Output file path |
|
|
426
|
+
|
|
427
|
+
#### Examples
|
|
428
|
+
|
|
429
|
+
```json
|
|
430
|
+
{
|
|
431
|
+
"schema": {
|
|
432
|
+
"name": "PascalCase"
|
|
433
|
+
},
|
|
434
|
+
"type": {
|
|
435
|
+
"name": "PascalCase",
|
|
436
|
+
"export": false
|
|
437
|
+
},
|
|
438
|
+
"comment": true,
|
|
439
|
+
"input": "db/schema.ts",
|
|
440
|
+
"output": "valibot/index.ts"
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
> **⚠️** When using a configuration file, command line arguments are not required. The configuration file settings take precedence over command line arguments.
|
|
445
|
+
>
|
|
446
|
+
> When you have configured `sizuku-zod.json`, you can simply run:
|
|
447
|
+
> ```bash
|
|
448
|
+
> npx sizuku-valibot
|
|
449
|
+
> ```
|
|
450
|
+
|
|
451
|
+
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:
|
|
452
|
+
|
|
453
|
+
### ⚠️ WARNING: Potential Breaking Changes Without Notice
|
|
454
|
+
|
|
455
|
+
**This package is in active development and may introduce breaking changes without prior notice.**
|
|
456
|
+
Specifically:
|
|
457
|
+
- Query parameter coercion behavior may change
|
|
458
|
+
- Schema generation logic might be updated
|
|
459
|
+
- Output code structure could be modified
|
|
460
|
+
- Example value handling might be altered
|
|
461
|
+
|
|
462
|
+
We strongly recommend:
|
|
463
|
+
- Pinning to exact versions in production
|
|
464
|
+
- Testing thoroughly when updating versions
|
|
465
|
+
- Reviewing generated code after updates
|
|
466
|
+
|
|
467
|
+
We welcome feedback and contributions to improve the tool!
|
|
468
|
+
|
|
469
|
+
## License
|
|
470
|
+
|
|
471
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/hono-takibi?tab=MIT-1-ov-file) for more information.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
4
|
+
exports.DEFAULT_CONFIG = {
|
|
5
|
+
schema: {
|
|
6
|
+
name: 'PascalCase',
|
|
7
|
+
},
|
|
8
|
+
type: {
|
|
9
|
+
name: 'PascalCase',
|
|
10
|
+
export: false,
|
|
11
|
+
},
|
|
12
|
+
comment: false,
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatCode(code: string): Promise<string>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatCode = formatCode;
|
|
4
|
+
const prettier_1 = require("prettier");
|
|
5
|
+
async function formatCode(code) {
|
|
6
|
+
return await (0, prettier_1.format)(code, {
|
|
7
|
+
parser: 'typescript',
|
|
8
|
+
printWidth: 100,
|
|
9
|
+
singleQuote: true,
|
|
10
|
+
semi: false,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateFieldDefinitions = generateFieldDefinitions;
|
|
4
|
+
/**
|
|
5
|
+
* @function generateFieldDefinitions
|
|
6
|
+
* @param schema
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
function generateFieldDefinitions(schema, config) {
|
|
10
|
+
return schema.fields
|
|
11
|
+
.map(({ name, definition, description }) => {
|
|
12
|
+
const comment = description && config.comment ? `/**\n* ${description}\n*/\n` : '';
|
|
13
|
+
return `${comment}${name}:${definition}`;
|
|
14
|
+
})
|
|
15
|
+
.join(',\n');
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCamelCaseSchemaNameHelper = getCamelCaseSchemaNameHelper;
|
|
4
|
+
const decapitalize_1 = require("../text/decapitalize");
|
|
5
|
+
/**
|
|
6
|
+
* Generates a camelCase schema name from a given schema name.
|
|
7
|
+
*
|
|
8
|
+
* @param schemaName - The original schema name.
|
|
9
|
+
* @returns The camelCase schema name.
|
|
10
|
+
*/
|
|
11
|
+
function getCamelCaseSchemaNameHelper(schemaName) {
|
|
12
|
+
const decapitalizedSchemaName = (0, decapitalize_1.decapitalize)(schemaName);
|
|
13
|
+
return `${decapitalizedSchemaName}Schema`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a PascalCase schema name from a given schema name.
|
|
3
|
+
*
|
|
4
|
+
* @function getPascalCaseSchemaName
|
|
5
|
+
* @param schemaName - The original schema name.
|
|
6
|
+
* @returns The PascalCase schema name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPascalCaseSchemaNameHelper(schemaName: string): string
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPascalCaseSchemaNameHelper = getPascalCaseSchemaNameHelper;
|
|
4
|
+
const capitalize_1 = require("../text/capitalize");
|
|
5
|
+
/**
|
|
6
|
+
* Generates a PascalCase schema name from a given schema name.
|
|
7
|
+
*
|
|
8
|
+
* @function getPascalCaseSchemaName
|
|
9
|
+
* @param schemaName - The original schema name.
|
|
10
|
+
* @returns The PascalCase schema name.
|
|
11
|
+
*/
|
|
12
|
+
function getPascalCaseSchemaNameHelper(schemaName) {
|
|
13
|
+
const capitalizedSchemaName = (0, capitalize_1.capitalize)(schemaName);
|
|
14
|
+
return `${capitalizedSchemaName}Schema`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from '../config'
|
|
2
|
+
/**
|
|
3
|
+
* Get the variable name helper
|
|
4
|
+
*
|
|
5
|
+
* @param name - The name of the schema
|
|
6
|
+
* @param config - The config
|
|
7
|
+
* @returns The variable name helper
|
|
8
|
+
*/
|
|
9
|
+
export declare function getVariableNameHelper(name: string, config: Config): string
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVariableNameHelper = getVariableNameHelper;
|
|
4
|
+
const capitalize_1 = require("../text/capitalize");
|
|
5
|
+
const decapitalize_1 = require("../text/decapitalize");
|
|
6
|
+
/**
|
|
7
|
+
* Get the variable name helper
|
|
8
|
+
*
|
|
9
|
+
* @param name - The name of the schema
|
|
10
|
+
* @param config - The config
|
|
11
|
+
* @returns The variable name helper
|
|
12
|
+
*/
|
|
13
|
+
function getVariableNameHelper(name, config) {
|
|
14
|
+
return config.type.name === 'camelCase' ? (0, decapitalize_1.decapitalize)(name) : (0, capitalize_1.capitalize)(name);
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from '../config'
|
|
2
|
+
/**
|
|
3
|
+
* Get the variable schema name helper
|
|
4
|
+
*
|
|
5
|
+
* @param name - The name of the schema
|
|
6
|
+
* @param config - The config
|
|
7
|
+
* @returns The variable schema name helper
|
|
8
|
+
*/
|
|
9
|
+
export declare function getVariableSchemaNameHelper(name: string, config: Config): string
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVariableSchemaNameHelper = getVariableSchemaNameHelper;
|
|
4
|
+
const get_camel_case_schema_name_helper_1 = require("./get-camel-case-schema-name-helper");
|
|
5
|
+
const get_pascal_case_schema_name_helper_1 = require("./get-pascal-case-schema-name-helper");
|
|
6
|
+
/**
|
|
7
|
+
* Get the variable schema name helper
|
|
8
|
+
*
|
|
9
|
+
* @param name - The name of the schema
|
|
10
|
+
* @param config - The config
|
|
11
|
+
* @returns The variable schema name helper
|
|
12
|
+
*/
|
|
13
|
+
function getVariableSchemaNameHelper(name, config) {
|
|
14
|
+
return config.schema.name === 'camelCase'
|
|
15
|
+
? (0, get_camel_case_schema_name_helper_1.getCamelCaseSchemaNameHelper)(name)
|
|
16
|
+
: (0, get_pascal_case_schema_name_helper_1.getPascalCaseSchemaNameHelper)(name);
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of a string
|
|
3
|
+
*
|
|
4
|
+
* @function capitalize
|
|
5
|
+
* @param str - String to capitalize
|
|
6
|
+
* @returns String with first letter capitalized
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* capitalize('posts') // Returns: 'Posts'
|
|
10
|
+
* capitalize('user') // Returns: 'User'
|
|
11
|
+
* capitalize('api') // Returns: 'Api'
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* - Leaves rest of the string unchanged
|
|
15
|
+
* - Returns empty string if input is empty
|
|
16
|
+
* - Commonly used for generating type names and class names
|
|
17
|
+
*/
|
|
18
|
+
export declare function capitalize(str: string): string
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalize = capitalize;
|
|
4
|
+
/**
|
|
5
|
+
* Capitalizes the first letter of a string
|
|
6
|
+
*
|
|
7
|
+
* @function capitalize
|
|
8
|
+
* @param str - String to capitalize
|
|
9
|
+
* @returns String with first letter capitalized
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* capitalize('posts') // Returns: 'Posts'
|
|
13
|
+
* capitalize('user') // Returns: 'User'
|
|
14
|
+
* capitalize('api') // Returns: 'Api'
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* - Leaves rest of the string unchanged
|
|
18
|
+
* - Returns empty string if input is empty
|
|
19
|
+
* - Commonly used for generating type names and class names
|
|
20
|
+
*/
|
|
21
|
+
function capitalize(str) {
|
|
22
|
+
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
|
|
23
|
+
}
|