hekireki 0.0.9 → 0.2.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 +71 -214
- package/dist/generator/mermaid-er/generator/er-content.d.ts +2 -0
- package/dist/generator/mermaid-er/generator/er-content.js +21 -0
- package/dist/generator/mermaid-er/generator/index.d.ts +4 -0
- package/dist/generator/mermaid-er/generator/index.js +4 -0
- package/dist/generator/mermaid-er/generator/{generate-model-fields.d.ts → model-fields.d.ts} +1 -1
- package/dist/generator/mermaid-er/generator/{generate-model-fields.js → model-fields.js} +1 -4
- package/dist/generator/mermaid-er/generator/model-info.d.ts +7 -0
- package/dist/generator/mermaid-er/generator/model-info.js +9 -0
- package/dist/generator/mermaid-er/generator/relation-line.d.ts +7 -0
- package/dist/generator/mermaid-er/generator/relation-line.js +13 -0
- package/dist/generator/mermaid-er/index.d.ts +0 -6
- package/dist/generator/mermaid-er/index.js +11 -28
- package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -5
- package/dist/generator/mermaid-er/relationship/build-relation-line.js +7 -15
- package/dist/generator/mermaid-er/types.js +1 -0
- package/dist/generator/mermaid-er/validator/exclude-many-to-one-relations.js +1 -4
- package/dist/generator/mermaid-er/validator/extract-relations.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/extract-relations.js +5 -8
- package/dist/generator/mermaid-er/validator/index.d.ts +5 -0
- package/dist/generator/mermaid-er/validator/index.js +5 -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.d.ts +1 -1
- package/dist/generator/mermaid-er/validator/parse-relation.js +1 -4
- package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +1 -4
- package/dist/generator/valibot/generator/index.d.ts +5 -0
- package/dist/generator/valibot/generator/index.js +5 -0
- package/dist/generator/valibot/generator/{generate-valibot-infer-input.d.ts → infer-input.d.ts} +1 -2
- package/dist/generator/valibot/generator/infer-input.js +9 -0
- package/dist/generator/valibot/generator/properties.d.ts +7 -0
- package/dist/generator/valibot/generator/{generate-valibot-properties.js → properties.js} +2 -5
- package/dist/generator/valibot/generator/schema.d.ts +7 -0
- package/dist/generator/valibot/generator/schema.js +9 -0
- package/dist/generator/valibot/generator/{generate-valibot-schemas.d.ts → schemas.d.ts} +2 -4
- package/dist/generator/valibot/generator/schemas.js +17 -0
- package/dist/generator/valibot/generator/valibot.d.ts +9 -0
- package/dist/generator/valibot/generator/valibot.js +50 -0
- package/dist/generator/valibot/index.d.ts +0 -8
- package/dist/generator/valibot/index.js +13 -44
- package/dist/generator/valibot/validator/index.d.ts +2 -0
- package/dist/generator/valibot/validator/index.js +2 -0
- package/dist/generator/valibot/validator/is-valibot-document.d.ts +1 -0
- package/dist/generator/valibot/validator/{is-valibot-documentation.js → is-valibot-document.js} +1 -4
- package/dist/generator/valibot/validator/is-valibot.d.ts +6 -0
- package/dist/generator/valibot/validator/{is-valibot-validation.js → is-valibot.js} +1 -5
- package/dist/generator/zod/generator/index.d.ts +5 -0
- package/dist/generator/zod/generator/index.js +5 -0
- package/dist/generator/zod/generator/{generate-zod-infer.d.ts → infer.d.ts} +1 -2
- package/dist/generator/zod/generator/infer.js +9 -0
- package/dist/generator/zod/generator/{generate-zod-properties.d.ts → properties.d.ts} +2 -3
- package/dist/generator/zod/generator/{generate-zod-properties.js → properties.js} +2 -5
- package/dist/generator/zod/generator/{generate-zod-schema.d.ts → schema.d.ts} +1 -2
- package/dist/generator/zod/generator/schema.js +10 -0
- package/dist/generator/zod/generator/{generate-zod-schemas.d.ts → schemas.d.ts} +2 -3
- package/dist/generator/zod/generator/schemas.js +16 -0
- package/dist/generator/zod/generator/zod.d.ts +9 -0
- package/dist/generator/zod/generator/zod.js +55 -0
- package/dist/generator/zod/index.d.ts +0 -8
- package/dist/generator/zod/index.js +14 -44
- package/dist/generator/zod/validator/index.d.ts +2 -0
- package/dist/generator/zod/validator/index.js +2 -0
- package/dist/generator/zod/validator/{is-zod-documentation.d.ts → is-zod-document.d.ts} +1 -1
- package/dist/generator/zod/validator/{is-zod-documentation.js → is-zod-document.js} +1 -4
- package/dist/generator/zod/validator/{is-zod-validation.d.ts → is-zod.d.ts} +1 -1
- package/dist/generator/zod/validator/{is-zod-validation.js → is-zod.js} +1 -4
- package/dist/shared/format/index.d.ts +1 -0
- package/dist/shared/format/index.js +9 -0
- package/dist/shared/helper/group-by-model.d.ts +8 -0
- package/dist/{common/helper/group-by-model-helper.js → shared/helper/group-by-model.js} +1 -4
- package/dist/shared/types.js +1 -0
- package/dist/{common/text → shared/utils}/capitalize.d.ts +3 -5
- package/dist/{common/text → shared/utils}/capitalize.js +4 -9
- package/dist/shared/utils/index.d.ts +1 -0
- package/dist/shared/utils/index.js +1 -0
- package/dist/shared/validator/is-fields.d.ts +12 -0
- package/dist/{common/validator/is-fields-validation.js → shared/validator/is-fields.js} +1 -4
- package/package.json +13 -12
- package/dist/common/format/index.d.ts +0 -1
- package/dist/common/format/index.js +0 -12
- 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/helper/group-by-model-helper.d.ts +0 -8
- 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/common/validator/is-fields-validation.d.ts +0 -13
- package/dist/generator/mermaid/generator/generate-er-content.d.ts +0 -7
- package/dist/generator/mermaid/generator/generate-er-content.js +0 -22
- package/dist/generator/mermaid/generator/generate-model-fields.d.ts +0 -7
- package/dist/generator/mermaid/generator/generate-model-fields.js +0 -27
- package/dist/generator/mermaid/generator/generate-model-info.d.ts +0 -8
- package/dist/generator/mermaid/generator/generate-model-info.js +0 -13
- package/dist/generator/mermaid/generator/generate-relation-line.d.ts +0 -7
- package/dist/generator/mermaid/generator/generate-relation-line.js +0 -16
- package/dist/generator/mermaid/index.d.ts +0 -9
- package/dist/generator/mermaid/index.js +0 -39
- package/dist/generator/mermaid/output/index.d.ts +0 -8
- package/dist/generator/mermaid/output/index.js +0 -24
- package/dist/generator/mermaid/relationship/build-relation-line.d.ts +0 -14
- package/dist/generator/mermaid/relationship/build-relation-line.js +0 -37
- package/dist/generator/mermaid/relationship/index.d.ts +0 -12
- package/dist/generator/mermaid/relationship/index.js +0 -30
- package/dist/generator/mermaid/type/index.d.ts +0 -10
- package/dist/generator/mermaid/type/index.js +0 -2
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +0 -7
- package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +0 -12
- package/dist/generator/mermaid/validator/extract-relations.d.ts +0 -7
- package/dist/generator/mermaid/validator/extract-relations.js +0 -25
- package/dist/generator/mermaid/validator/is-relation.d.ts +0 -7
- package/dist/generator/mermaid/validator/is-relation.js +0 -37
- package/dist/generator/mermaid/validator/is-relationship.d.ts +0 -7
- package/dist/generator/mermaid/validator/is-relationship.js +0 -11
- package/dist/generator/mermaid/validator/parse-relation.d.ts +0 -8
- package/dist/generator/mermaid/validator/parse-relation.js +0 -24
- package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +0 -6
- package/dist/generator/mermaid/validator/remove-duplicate-relations.js +0 -11
- package/dist/generator/mermaid-er/generator/generate-er-content.d.ts +0 -7
- package/dist/generator/mermaid-er/generator/generate-er-content.js +0 -22
- package/dist/generator/mermaid-er/generator/generate-model-info.d.ts +0 -8
- package/dist/generator/mermaid-er/generator/generate-model-info.js +0 -13
- package/dist/generator/mermaid-er/generator/generate-relation-line.d.ts +0 -7
- package/dist/generator/mermaid-er/generator/generate-relation-line.js +0 -16
- package/dist/generator/mermaid-er/output/index.d.ts +0 -8
- package/dist/generator/mermaid-er/output/index.js +0 -24
- package/dist/generator/mermaid-er/type/index.js +0 -2
- package/dist/generator/valibot/generator/generate-valibot-infer-input.js +0 -16
- package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +0 -8
- package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot-schema.js +0 -15
- package/dist/generator/valibot/generator/generate-valibot-schemas.js +0 -21
- package/dist/generator/valibot/generator/generate-valibot.d.ts +0 -9
- package/dist/generator/valibot/generator/generate-valibot.js +0 -52
- package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +0 -1
- package/dist/generator/valibot/validator/is-valibot-validation.d.ts +0 -7
- package/dist/generator/zod/generator/generate-zod-infer.js +0 -16
- package/dist/generator/zod/generator/generate-zod-schema.js +0 -15
- package/dist/generator/zod/generator/generate-zod-schemas.js +0 -20
- package/dist/generator/zod/generator/generate-zod.d.ts +0 -9
- package/dist/generator/zod/generator/generate-zod.js +0 -52
- /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/README.md
CHANGED
|
@@ -20,110 +20,65 @@ Prepare `schema.prisma`:
|
|
|
20
20
|
|
|
21
21
|
```prisma
|
|
22
22
|
generator client {
|
|
23
|
-
|
|
23
|
+
provider = "prisma-client-js"
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
datasource db {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
provider = "sqlite"
|
|
28
|
+
url = env("DATABASE_URL")
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
generator Hekireki-ER {
|
|
32
|
-
|
|
32
|
+
provider = "hekireki-mermaid-er"
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
generator Hekireki-Zod {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
provider = "hekireki-zod"
|
|
37
|
+
type = true
|
|
38
|
+
comment = false
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
generator Hekireki-Valibot {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
provider = "hekireki-valibot"
|
|
43
|
+
type = true
|
|
44
|
+
comment = false
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
model User {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/// @v.pipe(v.string(), v.email())
|
|
59
|
-
email String
|
|
60
|
-
/// Password for the user.
|
|
61
|
-
/// @z.string().min(8).max(100)
|
|
62
|
-
/// @v.pipe(v.string(), v.minLength(8), v.maxLength(100))
|
|
63
|
-
password String
|
|
64
|
-
/// Timestamp when the user was created.
|
|
65
|
-
/// @z.date()
|
|
66
|
-
/// @v.date()
|
|
67
|
-
createdAt DateTime
|
|
68
|
-
/// Timestamp when the user was last updated.
|
|
69
|
-
/// @z.date()
|
|
70
|
-
/// @v.date()
|
|
71
|
-
updatedAt DateTime
|
|
72
|
-
posts Post[]
|
|
73
|
-
likes Like[]
|
|
48
|
+
/// Primary key
|
|
49
|
+
/// @z.uuid()
|
|
50
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
51
|
+
id String @id @default(uuid())
|
|
52
|
+
/// Display name
|
|
53
|
+
/// @z.string().min(1).max(50)
|
|
54
|
+
/// @v.pipe(v.string(), v.minLength(1), v.maxLength(50))
|
|
55
|
+
name String
|
|
56
|
+
/// One-to-many relation to Post
|
|
57
|
+
posts Post[]
|
|
74
58
|
}
|
|
75
59
|
|
|
76
60
|
/// @relation User.id Post.userId one-to-many
|
|
77
61
|
model Post {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
/// Relation with the User model.
|
|
99
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
100
|
-
likes Like[]
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/// @relation Post.id Like.postId one-to-many
|
|
104
|
-
/// @relation User.id Like.userId one-to-many
|
|
105
|
-
model Like {
|
|
106
|
-
/// Unique identifier for the like.
|
|
107
|
-
/// @z.string().uuid()
|
|
108
|
-
/// @v.pipe(v.string(), v.uuid())
|
|
109
|
-
id String
|
|
110
|
-
/// ID of the post that is liked.
|
|
111
|
-
/// @z.string().uuid()
|
|
112
|
-
/// @v.pipe(v.string(), v.uuid())
|
|
113
|
-
postId String
|
|
114
|
-
/// ID of the user who liked the post.
|
|
115
|
-
/// @z.string().uuid()
|
|
116
|
-
/// @v.pipe(v.string(), v.uuid())
|
|
117
|
-
userId String
|
|
118
|
-
/// Timestamp when the like was created.
|
|
119
|
-
/// @z.date()
|
|
120
|
-
/// @v.date()
|
|
121
|
-
createdAt DateTime @default(now())
|
|
122
|
-
/// Relation with the Post model.
|
|
123
|
-
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
|
|
124
|
-
/// Relation with the User model.
|
|
125
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
126
|
-
@@unique([userId, postId])
|
|
62
|
+
/// Primary key
|
|
63
|
+
/// @z.uuid()
|
|
64
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
65
|
+
id String @id @default(uuid())
|
|
66
|
+
|
|
67
|
+
/// Article title
|
|
68
|
+
/// @z.string().min(1).max(100)
|
|
69
|
+
/// @v.pipe(v.string(), v.minLength(1), v.maxLength(100))
|
|
70
|
+
title String
|
|
71
|
+
|
|
72
|
+
/// Body content (no length limit)
|
|
73
|
+
/// @z.string()
|
|
74
|
+
/// @v.string()
|
|
75
|
+
content String
|
|
76
|
+
/// Foreign key referencing User.id
|
|
77
|
+
/// @z.uuid()
|
|
78
|
+
/// @v.pipe(v.string(), v.uuid())
|
|
79
|
+
userId String
|
|
80
|
+
/// Prisma relation definition
|
|
81
|
+
user User @relation(fields: [userId], references: [id])
|
|
127
82
|
}
|
|
128
83
|
```
|
|
129
84
|
|
|
@@ -132,82 +87,41 @@ model Like {
|
|
|
132
87
|
## Zod
|
|
133
88
|
|
|
134
89
|
```ts
|
|
135
|
-
import { z } from 'zod'
|
|
90
|
+
import { z } from 'zod/v4'
|
|
136
91
|
|
|
137
92
|
export const UserSchema = z.object({
|
|
138
93
|
/**
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
id: z.string().uuid(),
|
|
142
|
-
/**
|
|
143
|
-
* Username of the user.
|
|
94
|
+
* Primary key
|
|
144
95
|
*/
|
|
145
|
-
|
|
96
|
+
id: z.uuid(),
|
|
146
97
|
/**
|
|
147
|
-
*
|
|
98
|
+
* Display name
|
|
148
99
|
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Password for the user.
|
|
152
|
-
*/
|
|
153
|
-
password: z.string().min(8).max(100),
|
|
154
|
-
/**
|
|
155
|
-
* Timestamp when the user was created.
|
|
156
|
-
*/
|
|
157
|
-
createdAt: z.date(),
|
|
158
|
-
/**
|
|
159
|
-
* Timestamp when the user was last updated.
|
|
160
|
-
*/
|
|
161
|
-
updatedAt: z.date(),
|
|
100
|
+
name: z.string().min(1).max(50),
|
|
162
101
|
})
|
|
163
102
|
|
|
164
103
|
export type User = z.infer<typeof UserSchema>
|
|
165
104
|
|
|
166
105
|
export const PostSchema = z.object({
|
|
167
106
|
/**
|
|
168
|
-
*
|
|
107
|
+
* Primary key
|
|
169
108
|
*/
|
|
170
|
-
id: z.
|
|
109
|
+
id: z.uuid(),
|
|
171
110
|
/**
|
|
172
|
-
*
|
|
111
|
+
* Article title
|
|
173
112
|
*/
|
|
174
|
-
|
|
113
|
+
title: z.string().min(1).max(100),
|
|
175
114
|
/**
|
|
176
|
-
*
|
|
115
|
+
* Body content (no length limit)
|
|
177
116
|
*/
|
|
178
|
-
content: z.string()
|
|
117
|
+
content: z.string(),
|
|
179
118
|
/**
|
|
180
|
-
*
|
|
119
|
+
* Foreign key referencing User.id
|
|
181
120
|
*/
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Timestamp when the post was last updated.
|
|
185
|
-
*/
|
|
186
|
-
updatedAt: z.date(),
|
|
121
|
+
userId: z.uuid(),
|
|
187
122
|
})
|
|
188
123
|
|
|
189
124
|
export type Post = z.infer<typeof PostSchema>
|
|
190
|
-
|
|
191
|
-
export const LikeSchema = z.object({
|
|
192
|
-
/**
|
|
193
|
-
* Unique identifier for the like.
|
|
194
|
-
*/
|
|
195
|
-
id: z.string().uuid(),
|
|
196
|
-
/**
|
|
197
|
-
* ID of the post that is liked.
|
|
198
|
-
*/
|
|
199
|
-
postId: z.string().uuid(),
|
|
200
|
-
/**
|
|
201
|
-
* ID of the user who liked the post.
|
|
202
|
-
*/
|
|
203
|
-
userId: z.string().uuid(),
|
|
204
|
-
/**
|
|
205
|
-
* Timestamp when the like was created.
|
|
206
|
-
*/
|
|
207
|
-
createdAt: z.date(),
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
export type Like = z.infer<typeof LikeSchema>
|
|
211
125
|
```
|
|
212
126
|
|
|
213
127
|
## Valibot
|
|
@@ -216,78 +130,37 @@ import * as v from 'valibot'
|
|
|
216
130
|
|
|
217
131
|
export const UserSchema = v.object({
|
|
218
132
|
/**
|
|
219
|
-
*
|
|
133
|
+
* Primary key
|
|
220
134
|
*/
|
|
221
135
|
id: v.pipe(v.string(), v.uuid()),
|
|
222
136
|
/**
|
|
223
|
-
*
|
|
224
|
-
*/
|
|
225
|
-
username: v.pipe(v.string(), v.minLength(3)),
|
|
226
|
-
/**
|
|
227
|
-
* Email address of the user.
|
|
137
|
+
* Display name
|
|
228
138
|
*/
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Password for the user.
|
|
232
|
-
*/
|
|
233
|
-
password: v.pipe(v.string(), v.minLength(8), v.maxLength(100)),
|
|
234
|
-
/**
|
|
235
|
-
* Timestamp when the user was created.
|
|
236
|
-
*/
|
|
237
|
-
createdAt: v.date(),
|
|
238
|
-
/**
|
|
239
|
-
* Timestamp when the user was last updated.
|
|
240
|
-
*/
|
|
241
|
-
updatedAt: v.date(),
|
|
139
|
+
name: v.pipe(v.string(), v.minLength(1), v.maxLength(50)),
|
|
242
140
|
})
|
|
243
141
|
|
|
244
142
|
export type User = v.InferInput<typeof UserSchema>
|
|
245
143
|
|
|
246
144
|
export const PostSchema = v.object({
|
|
247
145
|
/**
|
|
248
|
-
*
|
|
146
|
+
* Primary key
|
|
249
147
|
*/
|
|
250
148
|
id: v.pipe(v.string(), v.uuid()),
|
|
251
149
|
/**
|
|
252
|
-
*
|
|
253
|
-
*/
|
|
254
|
-
userId: v.pipe(v.string(), v.uuid()),
|
|
255
|
-
/**
|
|
256
|
-
* Content of the post.
|
|
257
|
-
*/
|
|
258
|
-
content: v.pipe(v.string(), v.maxLength(500)),
|
|
259
|
-
/**
|
|
260
|
-
* Timestamp when the post was created.
|
|
261
|
-
*/
|
|
262
|
-
createdAt: v.date(),
|
|
263
|
-
/**
|
|
264
|
-
* Timestamp when the post was last updated.
|
|
265
|
-
*/
|
|
266
|
-
updatedAt: v.date(),
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
export type Post = v.InferInput<typeof PostSchema>
|
|
270
|
-
|
|
271
|
-
export const LikeSchema = v.object({
|
|
272
|
-
/**
|
|
273
|
-
* Unique identifier for the like.
|
|
150
|
+
* Article title
|
|
274
151
|
*/
|
|
275
|
-
|
|
152
|
+
title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
|
|
276
153
|
/**
|
|
277
|
-
*
|
|
154
|
+
* Body content (no length limit)
|
|
278
155
|
*/
|
|
279
|
-
|
|
156
|
+
content: v.string(),
|
|
280
157
|
/**
|
|
281
|
-
*
|
|
158
|
+
* Foreign key referencing User.id
|
|
282
159
|
*/
|
|
283
160
|
userId: v.pipe(v.string(), v.uuid()),
|
|
284
|
-
/**
|
|
285
|
-
* Timestamp when the like was created.
|
|
286
|
-
*/
|
|
287
|
-
createdAt: v.date(),
|
|
288
161
|
})
|
|
289
162
|
|
|
290
|
-
export type
|
|
163
|
+
export type Post = v.InferInput<typeof PostSchema>
|
|
291
164
|
```
|
|
292
165
|
|
|
293
166
|
## Mermaid
|
|
@@ -295,28 +168,15 @@ export type Like = v.InferInput<typeof LikeSchema>
|
|
|
295
168
|
```mermaid
|
|
296
169
|
erDiagram
|
|
297
170
|
User ||--}| Post : "(id) - (userId)"
|
|
298
|
-
Post ||--}| Like : "(id) - (postId)"
|
|
299
|
-
User ||--}| Like : "(id) - (userId)"
|
|
300
171
|
User {
|
|
301
|
-
String id "
|
|
302
|
-
String
|
|
303
|
-
String email "Email address of the user."
|
|
304
|
-
String password "Password for the user."
|
|
305
|
-
DateTime createdAt "Timestamp when the user was created."
|
|
306
|
-
DateTime updatedAt "Timestamp when the user was last updated."
|
|
172
|
+
String id "Primary key"
|
|
173
|
+
String name "Display name"
|
|
307
174
|
}
|
|
308
175
|
Post {
|
|
309
|
-
String id "
|
|
310
|
-
String
|
|
311
|
-
String content "
|
|
312
|
-
|
|
313
|
-
DateTime updatedAt "Timestamp when the post was last updated."
|
|
314
|
-
}
|
|
315
|
-
Like {
|
|
316
|
-
String id "Unique identifier for the like."
|
|
317
|
-
String postId "ID of the post that is liked."
|
|
318
|
-
String userId "ID of the user who liked the post."
|
|
319
|
-
DateTime createdAt "Timestamp when the like was created."
|
|
176
|
+
String id "Primary key"
|
|
177
|
+
String title "Article title"
|
|
178
|
+
String content "Body content (no length limit)"
|
|
179
|
+
String userId "Foreign key referencing User.id"
|
|
320
180
|
}
|
|
321
181
|
```
|
|
322
182
|
|
|
@@ -328,19 +188,16 @@ erDiagram
|
|
|
328
188
|
|--------------|-----------|-------------------------------------|--------------------------------------------------|
|
|
329
189
|
| `output` | `string` | `./zod` | Output directory |
|
|
330
190
|
| `file` | `string` | `index.ts` | File Name |
|
|
331
|
-
| `schemaName` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"`| Naming convention for generated schema variables |
|
|
332
|
-
| `typeName` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"`| Naming convention for generated type definitions |
|
|
333
191
|
| `type` | `boolean` | `false` | Generate TypeScript types |
|
|
334
192
|
| `comment` | `boolean` | `false` | Include schema documentation |
|
|
193
|
+
| `zodVersion` | `string` | `'v4'` | Zod import version (`'v4-mini'`, `'@hono/zod-openapi'`, or default `'v4'`) |
|
|
335
194
|
|
|
336
195
|
### Valibot Generator Options
|
|
337
196
|
|
|
338
197
|
| Option | Type | Default | Description |
|
|
339
198
|
|--------------|-----------|-------------------------------------|--------------------------------------------------|
|
|
340
|
-
| `output` | `string` | `./valibot`
|
|
199
|
+
| `output` | `string` | `./valibot` | Output directory |
|
|
341
200
|
| `file` | `string` | `index.ts` | File Name |
|
|
342
|
-
| `schemaName` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"`| Naming convention for generated schema variables |
|
|
343
|
-
| `typeName` | `"PascalCase"` \| `"camelCase"` | `"PascalCase"`| Naming convention for generated type definitions |
|
|
344
201
|
| `type` | `boolean` | `false` | Generate TypeScript types |
|
|
345
202
|
| `comment` | `boolean` | `false` | Include schema documentation |
|
|
346
203
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { modelInfo } from '../generator/index.js';
|
|
2
|
+
import { extractRelations, removeDuplicateRelations } from '../validator/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* generate ER content
|
|
5
|
+
* @param { readonly Model[] } models - models
|
|
6
|
+
* @returns { ERContent } - ER content
|
|
7
|
+
*/
|
|
8
|
+
// ER diagram header
|
|
9
|
+
const ER_HEADER = ['```mermaid', 'erDiagram'];
|
|
10
|
+
// ER diagram footer
|
|
11
|
+
const ER_FOOTER = ['```'];
|
|
12
|
+
export function erContent(models) {
|
|
13
|
+
// extract all relations
|
|
14
|
+
const allRelations = models.flatMap(extractRelations);
|
|
15
|
+
// remove duplicate relations
|
|
16
|
+
const uniqueRelations = removeDuplicateRelations(allRelations);
|
|
17
|
+
// collect all model info
|
|
18
|
+
const modelInfos = models.flatMap(modelInfo);
|
|
19
|
+
// build ER diagram
|
|
20
|
+
return [...ER_HEADER, ...uniqueRelations, ...modelInfos, ...ER_FOOTER];
|
|
21
|
+
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateModelFields = generateModelFields;
|
|
4
1
|
const ZOD_ANNOTATION = '@z.';
|
|
5
2
|
const VALIBOT_ANNOTATION = '@v.';
|
|
6
3
|
/**
|
|
@@ -8,7 +5,7 @@ const VALIBOT_ANNOTATION = '@v.';
|
|
|
8
5
|
* @param { DMMF.Model } model
|
|
9
6
|
* @returns { string[] }
|
|
10
7
|
*/
|
|
11
|
-
function
|
|
8
|
+
export function modelFields(model) {
|
|
12
9
|
return model.fields
|
|
13
10
|
.map((field) => {
|
|
14
11
|
if (field.relationName) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { buildRelationLine } from '../relationship/build-relation-line.js';
|
|
2
|
+
/**
|
|
3
|
+
* generate relation line
|
|
4
|
+
* @param { Relation } relation
|
|
5
|
+
* @returns { string } 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
|
+
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { GeneratorOptions } from '@prisma/generator-helper';
|
|
3
|
-
export type Config = {
|
|
4
|
-
output?: string;
|
|
5
|
-
file?: string | string[];
|
|
6
|
-
};
|
|
7
|
-
export declare const ER_HEADER: readonly ["```mermaid", "erDiagram"];
|
|
8
|
-
export declare const ER_FOOTER: readonly ["```"];
|
|
9
3
|
export declare function main(options: GeneratorOptions): Promise<void>;
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
output:
|
|
11
|
-
file: '
|
|
12
|
-
};
|
|
13
|
-
// ER diagram header
|
|
14
|
-
exports.ER_HEADER = ['```mermaid', 'erDiagram'];
|
|
15
|
-
// ER diagram footer
|
|
16
|
-
exports.ER_FOOTER = ['```'];
|
|
17
|
-
// main function
|
|
18
|
-
async function main(options) {
|
|
19
|
-
const config = {
|
|
20
|
-
output: options.generator.output?.value ?? DEFAULT_CONFIG.output,
|
|
21
|
-
file: options.generator.config?.file ?? DEFAULT_CONFIG.file,
|
|
22
|
-
};
|
|
23
|
-
const models = options.dmmf.datamodel.models;
|
|
24
|
-
const content = (0, generate_er_content_1.generateERContent)(models);
|
|
25
|
-
if (!config.output) {
|
|
26
|
-
throw new Error('output is required');
|
|
27
|
-
}
|
|
28
|
-
(0, output_1.OutputFile)(content, config);
|
|
2
|
+
import { erContent } from './generator/er-content.js';
|
|
3
|
+
import fsp from 'node:fs/promises';
|
|
4
|
+
import pkg from '@prisma/generator-helper';
|
|
5
|
+
const { generatorHandler } = pkg;
|
|
6
|
+
export async function main(options) {
|
|
7
|
+
const content = erContent(options.dmmf.datamodel.models);
|
|
8
|
+
const output = options.generator.output?.value ?? './mermaid-er';
|
|
9
|
+
const file = options.generator.config?.file ?? 'ER.md';
|
|
10
|
+
await fsp.mkdir(output, { recursive: true });
|
|
11
|
+
await fsp.writeFile(`${output}/${file}`, content.join('\n'), { encoding: 'utf-8' });
|
|
29
12
|
}
|
|
30
13
|
// prisma generator handler
|
|
31
|
-
|
|
14
|
+
generatorHandler({
|
|
32
15
|
onManifest() {
|
|
33
16
|
return {
|
|
34
17
|
defaultOutput: './mermaid-er',
|
|
@@ -5,10 +5,5 @@ declare const RELATIONSHIPS: {
|
|
|
5
5
|
readonly many: "}|";
|
|
6
6
|
};
|
|
7
7
|
export type Relationship = keyof typeof RELATIONSHIPS;
|
|
8
|
-
/**
|
|
9
|
-
* Builds a relationship line for mermaid from a string.
|
|
10
|
-
* @param { string } input
|
|
11
|
-
* @returns { string }
|
|
12
|
-
*/
|
|
13
8
|
export declare function buildRelationLine(input: string): string;
|
|
14
9
|
export {};
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildRelationLine = buildRelationLine;
|
|
4
|
-
const is_relationship_1 = require("../validator/is-relationship");
|
|
1
|
+
import { isRelationship } from '../validator/is-relationship.js';
|
|
5
2
|
const RELATIONSHIPS = {
|
|
6
3
|
'zero-one': '|o',
|
|
7
4
|
one: '||',
|
|
8
5
|
'zero-many': '}o',
|
|
9
6
|
many: '}|',
|
|
10
7
|
};
|
|
11
|
-
|
|
12
|
-
* Builds a relationship line for mermaid from a string.
|
|
13
|
-
* @param { string } input
|
|
14
|
-
* @returns { string }
|
|
15
|
-
*/
|
|
16
|
-
function buildRelationLine(input) {
|
|
8
|
+
export function buildRelationLine(input) {
|
|
17
9
|
const parts = input.split('-to-');
|
|
18
10
|
if (parts.length !== 2) {
|
|
19
11
|
throw new Error(`Invalid input format: ${input}`);
|
|
@@ -24,14 +16,14 @@ function buildRelationLine(input) {
|
|
|
24
16
|
const from = parts[0];
|
|
25
17
|
const to = toRaw;
|
|
26
18
|
const isOptional = optionalFlag === 'optional';
|
|
27
|
-
if (!
|
|
28
|
-
throw new Error(`Invalid relationship
|
|
19
|
+
if (!isRelationship(from)) {
|
|
20
|
+
throw new Error(`Invalid relationship: ${from}`);
|
|
21
|
+
}
|
|
22
|
+
if (!isRelationship(to)) {
|
|
23
|
+
throw new Error(`Invalid relationship: ${to}`);
|
|
29
24
|
}
|
|
30
25
|
const fromSymbol = RELATIONSHIPS[from];
|
|
31
26
|
const toSymbol = RELATIONSHIPS[to];
|
|
32
|
-
if (!(fromSymbol && toSymbol)) {
|
|
33
|
-
throw new Error(`Invalid relationship string: ${input}`);
|
|
34
|
-
}
|
|
35
27
|
const connector = isOptional ? '..' : '--';
|
|
36
28
|
return `${fromSymbol}${connector}${toSymbol}`;
|
|
37
29
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.excludeManyToOneRelations = excludeManyToOneRelations;
|
|
4
1
|
/**
|
|
5
2
|
* exclude many-to-one relations
|
|
6
3
|
* @function excludeManyToOneRelations
|
|
7
4
|
* @param relations
|
|
8
5
|
* @returns
|
|
9
6
|
*/
|
|
10
|
-
function excludeManyToOneRelations(relations) {
|
|
7
|
+
export function excludeManyToOneRelations(relations) {
|
|
11
8
|
return [...new Set(relations)].filter((r) => !r.includes('many-to-one'));
|
|
12
9
|
}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.extractRelations = extractRelations;
|
|
4
|
-
const generate_relation_line_1 = require("../generator/generate-relation-line");
|
|
5
|
-
const parse_relation_1 = require("./parse-relation");
|
|
1
|
+
import { relationLine } from '../generator/relation-line.js';
|
|
2
|
+
import { parseRelation } from './index.js';
|
|
6
3
|
/**
|
|
7
4
|
* extract relations from model
|
|
8
5
|
* @param { Model } model
|
|
9
6
|
* @returns { readonly string[] }
|
|
10
7
|
*/
|
|
11
|
-
function extractRelations(model) {
|
|
8
|
+
export function extractRelations(model) {
|
|
12
9
|
const relations = [];
|
|
13
10
|
// @relation annotation
|
|
14
11
|
if (model.documentation) {
|
|
15
12
|
const annotationRelations = model.documentation
|
|
16
13
|
.split('\n')
|
|
17
14
|
.map((line) => {
|
|
18
|
-
const relation =
|
|
19
|
-
return relation ? (
|
|
15
|
+
const relation = parseRelation(line);
|
|
16
|
+
return relation ? relationLine(relation) : null;
|
|
20
17
|
})
|
|
21
18
|
.filter((line) => line !== null);
|
|
22
19
|
relations.push(...annotationRelations);
|