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.
Files changed (102) hide show
  1. package/README.md +87 -341
  2. package/dist/config/index.d.ts +18 -0
  3. package/dist/config/index.js +13 -0
  4. package/dist/generator/mermaid-er/config/index.d.ts +4 -4
  5. package/dist/generator/mermaid-er/config/index.js +4 -10
  6. package/dist/generator/mermaid-er/core/extract-relations.d.ts +1 -1
  7. package/dist/generator/mermaid-er/core/extract-relations.js +3 -6
  8. package/dist/generator/mermaid-er/generator/{generate-er-content.d.ts → er-content.d.ts} +2 -3
  9. package/dist/generator/mermaid-er/generator/{generate-er-content.js → er-content.js} +3 -7
  10. package/dist/generator/mermaid-er/generator/index.d.ts +2 -0
  11. package/dist/generator/mermaid-er/generator/index.js +2 -0
  12. package/dist/generator/mermaid-er/generator/{generate-relation-line.d.ts → relation-line.d.ts} +2 -2
  13. package/dist/generator/mermaid-er/generator/{generate-relation-line.js → relation-line.js} +3 -6
  14. package/dist/generator/mermaid-er/index.d.ts +6 -5
  15. package/dist/generator/mermaid-er/index.js +15 -76
  16. package/dist/generator/mermaid-er/relationship/build-relation-line.js +3 -6
  17. package/dist/generator/mermaid-er/types.js +1 -0
  18. package/dist/generator/mermaid-er/validator/index.d.ts +4 -0
  19. package/dist/generator/mermaid-er/validator/index.js +4 -0
  20. package/dist/generator/mermaid-er/validator/is-relationship.d.ts +1 -1
  21. package/dist/generator/mermaid-er/validator/is-relationship.js +1 -4
  22. package/dist/generator/mermaid-er/validator/parse-relation-line.js +1 -4
  23. package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +1 -7
  24. package/dist/generator/mermaid-er/validator/parse-table-info.js +69 -89
  25. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +1 -4
  26. package/dist/generator/valibot/config/index.d.ts +2 -2
  27. package/dist/generator/valibot/config/index.js +6 -12
  28. package/dist/generator/valibot/core/extract-schema.d.ts +2 -5
  29. package/dist/generator/valibot/core/extract-schema.js +162 -81
  30. package/dist/generator/valibot/generator/infer-input.d.ts +5 -0
  31. package/dist/generator/valibot/generator/infer-input.js +8 -0
  32. package/dist/generator/valibot/generator/valibot-code.d.ts +8 -0
  33. package/dist/generator/valibot/generator/valibot-code.js +16 -0
  34. package/dist/generator/valibot/generator/valibot.d.ts +7 -0
  35. package/dist/generator/valibot/generator/valibot.js +11 -0
  36. package/dist/generator/valibot/index.d.ts +9 -3
  37. package/dist/generator/valibot/index.js +21 -76
  38. package/dist/generator/zod/config/index.d.ts +2 -2
  39. package/dist/generator/zod/config/index.js +6 -12
  40. package/dist/generator/zod/core/extract-schema.d.ts +1 -2
  41. package/dist/generator/zod/core/extract-schema.js +228 -81
  42. package/dist/generator/zod/generator/infer.d.ts +5 -0
  43. package/dist/generator/zod/generator/infer.js +8 -0
  44. package/dist/generator/zod/generator/{generate-zod-code.d.ts → zod-code.d.ts} +2 -3
  45. package/dist/generator/zod/generator/zod-code.js +18 -0
  46. package/dist/generator/zod/generator/{generate-zod-schema.d.ts → zod.d.ts} +2 -4
  47. package/dist/generator/zod/generator/zod.js +12 -0
  48. package/dist/generator/zod/index.d.ts +10 -3
  49. package/dist/generator/zod/index.js +29 -76
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.js +54 -0
  52. package/dist/shared/config/index.d.ts +13 -0
  53. package/dist/{common → shared}/config/index.js +1 -4
  54. package/dist/shared/format/index.d.ts +2 -0
  55. package/dist/shared/format/index.js +10 -0
  56. package/dist/shared/fs/index.d.ts +2 -0
  57. package/dist/shared/fs/index.js +10 -0
  58. package/dist/shared/fsp/index.d.ts +3 -0
  59. package/dist/shared/fsp/index.js +8 -0
  60. package/dist/shared/generator/field-definitions.d.ts +6 -0
  61. package/dist/shared/generator/field-definitions.js +12 -0
  62. package/dist/shared/types.js +1 -0
  63. package/dist/{common/text → shared/utils}/capitalize.js +1 -4
  64. package/dist/shared/utils/compose.d.ts +101 -0
  65. package/dist/shared/utils/compose.js +124 -0
  66. package/dist/shared/utils/file.d.ts +92 -0
  67. package/dist/shared/utils/file.js +177 -0
  68. package/dist/shared/utils/functional.d.ts +118 -0
  69. package/dist/shared/utils/functional.js +96 -0
  70. package/package.json +11 -10
  71. package/dist/common/config/index.d.ts +0 -13
  72. package/dist/common/format/index.d.ts +0 -1
  73. package/dist/common/format/index.js +0 -12
  74. package/dist/common/generator/generate-field-definitions.d.ts +0 -8
  75. package/dist/common/generator/generate-field-definitions.js +0 -16
  76. package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +0 -7
  77. package/dist/common/helper/get-camel-case-schema-name-helper.js +0 -14
  78. package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +0 -8
  79. package/dist/common/helper/get-pascal-case-schema-name-helper.js +0 -15
  80. package/dist/common/helper/get-variable-name-helper.d.ts +0 -9
  81. package/dist/common/helper/get-variable-name-helper.js +0 -15
  82. package/dist/common/helper/get-variable-schema-name-helper.d.ts +0 -9
  83. package/dist/common/helper/get-variable-schema-name-helper.js +0 -17
  84. package/dist/common/text/decapitalize.d.ts +0 -17
  85. package/dist/common/text/decapitalize.js +0 -22
  86. package/dist/common/type/index.js +0 -2
  87. package/dist/generator/mermaid-er/type/index.js +0 -2
  88. package/dist/generator/mermaid-er/validator/is-relation.d.ts +0 -7
  89. package/dist/generator/mermaid-er/validator/is-relation.js +0 -40
  90. package/dist/generator/valibot/generator/generate-valibot-code.d.ts +0 -11
  91. package/dist/generator/valibot/generator/generate-valibot-code.js +0 -21
  92. package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +0 -9
  93. package/dist/generator/valibot/generator/generate-valibot-infer-input.js +0 -16
  94. package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +0 -9
  95. package/dist/generator/valibot/generator/generate-valibot-schema.js +0 -16
  96. package/dist/generator/zod/generator/generate-z-infer.d.ts +0 -11
  97. package/dist/generator/zod/generator/generate-z-infer.js +0 -18
  98. package/dist/generator/zod/generator/generate-zod-code.js +0 -21
  99. package/dist/generator/zod/generator/generate-zod-schema.js +0 -17
  100. /package/dist/generator/mermaid-er/{type/index.d.ts → types.d.ts} +0 -0
  101. /package/dist/{common/type/index.d.ts → shared/types.d.ts} +0 -0
  102. /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
- input:
24
+ Prepare schema.ts:
25
25
 
26
26
  ```ts
27
- import { sql } from 'drizzle-orm'
28
- import { mysqlTable, varchar, timestamp, unique } from 'drizzle-orm/mysql-core'
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
- /// Unique identifier for the user.
32
- /// @z.string().uuid()
31
+ /// Primary key
32
+ /// @z.uuid()
33
33
  /// @v.pipe(v.string(), v.uuid())
34
34
  id: varchar('id', { length: 36 }).primaryKey(),
35
- /// Username of the user.
36
- /// @z.string()
37
- /// @v.string()
38
- username: varchar('username', { length: 255 }).notNull(),
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
- /// Unique identifier for the post.
63
- /// @z.string().uuid()
43
+ /// Primary key
44
+ /// @z.uuid()
64
45
  /// @v.pipe(v.string(), v.uuid())
65
46
  id: varchar('id', { length: 36 }).primaryKey(),
66
- /// ID of the user who created the post.
67
- /// @z.string().uuid()
68
- /// @v.pipe(v.string(), v.uuid())
69
- userId: varchar('user_id', { length: 36 })
70
- .notNull()
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: 500 }).notNull(),
76
- /// Timestamp when the post was created.
77
- /// @z.date()
78
- /// @v.date()
79
- createdAt: timestamp('created_at', { mode: 'string' }).notNull().default(sql`CURRENT_TIMESTAMP`),
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
- /// @relation post.id likes.postId one-to-many
90
- /// @relation user.id likes.userId one-to-many
91
- export const likes = mysqlTable(
92
- 'likes',
93
- {
94
- /// Unique identifier for the like.
95
- /// @z.string().uuid()
96
- /// @v.pipe(v.string(), v.uuid())
97
- id: varchar('id', { length: 36 }).primaryKey(),
98
- /// ID of the post that is liked.
99
- /// @z.string().uuid()
100
- /// @v.pipe(v.string(), v.uuid())
101
- postId: varchar('post_id', { length: 36 })
102
- .notNull()
103
- .references(() => post.id, { onDelete: 'cascade' }),
104
- /// ID of the user who liked the post.
105
- /// @z.string().uuid()
106
- /// @v.pipe(v.string(), v.uuid())
107
- userId: varchar('user_id', { length: 36 })
108
- .notNull()
109
- .references(() => user.id, { onDelete: 'cascade' }),
110
- /// Timestamp when the like was created.
111
- /// @z.date()
112
- /// @v.date()
113
- createdAt: timestamp('created_at', { mode: 'string' })
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
- (t) => [unique().on(t.userId, t.postId)],
118
- )
87
+ "mermaid": {
88
+ "output": "mermaid-er/ER.md"
89
+ }
90
+ }
119
91
  ```
120
92
 
121
- ### Zod
93
+ Run Sizuku:
122
94
 
123
- ```bash
124
- npx sizuku-zod path/to/db/schema.ts -o path/to/output.ts
95
+ ```sh
96
+ npx sizuku
125
97
  ```
126
98
 
127
- output:
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
- * Unique identifier for the user.
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
- password: z.string().min(8).max(100),
108
+ id: z.uuid(),
149
109
  /**
150
- * Timestamp when the user was created.
110
+ * Display name
151
111
  */
152
- createdAt: z.date(),
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
- * Unique identifier for the post.
119
+ * Primary key
162
120
  */
163
- id: z.string().uuid(),
121
+ id: z.uuid(),
164
122
  /**
165
- * ID of the user who created the post.
123
+ * Article title
166
124
  */
167
- userId: z.string().uuid(),
125
+ title: z.string().min(1).max(100),
168
126
  /**
169
- * Content of the post.
127
+ * Body content (no length limit)
170
128
  */
171
129
  content: z.string(),
172
130
  /**
173
- * Timestamp when the post was created.
174
- */
175
- createdAt: z.date(),
176
- /**
177
- * Timestamp when the post was last updated.
131
+ * Foreign key referencing User.id
178
132
  */
179
- updatedAt: z.date(),
133
+ userId: z.uuid(),
180
134
  })
181
135
 
182
- export const LikesSchema = z.object({
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
- * Unique identifier for the user.
146
+ * Primary key
216
147
  */
217
148
  id: v.pipe(v.string(), v.uuid()),
218
149
  /**
219
- * Username of the user.
220
- */
221
- username: v.string(),
222
- /**
223
- * Email address of the user.
150
+ * Display name
224
151
  */
225
- email: v.pipe(v.string(), v.email()),
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
- * Unique identifier for the post.
159
+ * Primary key
243
160
  */
244
161
  id: v.pipe(v.string(), v.uuid()),
245
162
  /**
246
- * ID of the user who created the post.
163
+ * Article title
247
164
  */
248
- userId: v.pipe(v.string(), v.uuid()),
165
+ title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
249
166
  /**
250
- * Content of the post.
167
+ * Body content (no length limit)
251
168
  */
252
169
  content: v.string(),
253
170
  /**
254
- * Timestamp when the post was created.
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
- ```bash
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
- output:
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) Unique identifier for the user."
298
- varchar username "Username of the user."
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) Unique identifier for the post."
306
- varchar userId "(FK) ID of the user who created the post."
307
- varchar content "Content of the post."
308
- timestamp createdAt "Timestamp when the post was created."
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
- input?: string;
3
- output?: string;
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
- "use strict";
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 = node_fs_1.default.existsSync('sizuku-mermaid-er.json')
15
- ? { ...JSON.parse(node_fs_1.default.readFileSync('sizuku-mermaid-er.json', 'utf-8')) }
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,4 +1,4 @@
1
- import type { Relation } from '../type';
1
+ import type { Relation } from '../types.js';
2
2
  /**
3
3
  * Extracts relations from the given code.
4
4
  *
@@ -1,17 +1,14 @@
1
- "use strict";
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 = (0, parse_relation_line_1.parseRelationLine)(line);
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 '../type';
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 generateERContent(relations: Relation[], tables: TableInfo[]): string;
8
+ export declare function erContent(relations: Relation[], tables: TableInfo[]): string;
@@ -1,20 +1,16 @@
1
- "use strict";
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 generateERContent(relations, tables) {
10
+ export function erContent(relations, tables) {
15
11
  const erContent = [
16
12
  ...ER_HEADER,
17
- ...relations.map(generate_relation_line_1.generateRelationLine),
13
+ ...relations.map(relationLine),
18
14
  // Generate per-table definitions
19
15
  ...tables.flatMap((table) => [
20
16
  ` ${table.name} {`,
@@ -0,0 +1,2 @@
1
+ export { relationLine } from './relation-line.js';
2
+ export { erContent } from './er-content.js';
@@ -0,0 +1,2 @@
1
+ export { relationLine } from './relation-line.js';
2
+ export { erContent } from './er-content.js';
@@ -1,7 +1,7 @@
1
- import type { Relation } from '../type';
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 generateRelationLine(relation: Relation): string;
7
+ export declare function relationLine(relation: Relation): string;