hekireki 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.
Files changed (78) hide show
  1. package/README.md +361 -0
  2. package/dist/common/format/index.d.ts +1 -0
  3. package/dist/common/format/index.js +12 -0
  4. package/dist/common/helper/get-camel-case-schema-name-helper.d.ts +7 -0
  5. package/dist/common/helper/get-camel-case-schema-name-helper.js +14 -0
  6. package/dist/common/helper/get-pascal-case-schema-name-helper.d.ts +8 -0
  7. package/dist/common/helper/get-pascal-case-schema-name-helper.js +15 -0
  8. package/dist/common/helper/get-variable-name-helper.d.ts +9 -0
  9. package/dist/common/helper/get-variable-name-helper.js +17 -0
  10. package/dist/common/helper/get-variable-schema-name-helper.d.ts +9 -0
  11. package/dist/common/helper/get-variable-schema-name-helper.js +17 -0
  12. package/dist/common/helper/group-by-model-helper.d.ts +8 -0
  13. package/dist/common/helper/group-by-model-helper.js +18 -0
  14. package/dist/common/text/capitalize.d.ts +18 -0
  15. package/dist/common/text/capitalize.js +23 -0
  16. package/dist/common/text/decapitalize.d.ts +17 -0
  17. package/dist/common/text/decapitalize.js +22 -0
  18. package/dist/common/type/index.d.ts +16 -0
  19. package/dist/common/type/index.js +2 -0
  20. package/dist/common/validator/is-fields-validation.d.ts +13 -0
  21. package/dist/common/validator/is-fields-validation.js +13 -0
  22. package/dist/generator/mermaid/generator/generate-er-content.d.ts +8 -0
  23. package/dist/generator/mermaid/generator/generate-er-content.js +23 -0
  24. package/dist/generator/mermaid/generator/generate-model-fields.d.ts +8 -0
  25. package/dist/generator/mermaid/generator/generate-model-fields.js +29 -0
  26. package/dist/generator/mermaid/generator/generate-model-info.d.ts +8 -0
  27. package/dist/generator/mermaid/generator/generate-model-info.js +17 -0
  28. package/dist/generator/mermaid/generator/generate-relation-line.d.ts +8 -0
  29. package/dist/generator/mermaid/generator/generate-relation-line.js +17 -0
  30. package/dist/generator/mermaid/index.d.ts +10 -0
  31. package/dist/generator/mermaid/index.js +73 -0
  32. package/dist/generator/mermaid/output/index.d.ts +8 -0
  33. package/dist/generator/mermaid/output/index.js +24 -0
  34. package/dist/generator/mermaid/type/index.d.ts +11 -0
  35. package/dist/generator/mermaid/type/index.js +2 -0
  36. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.d.ts +7 -0
  37. package/dist/generator/mermaid/validator/exclude-many-to-one-relations.js +12 -0
  38. package/dist/generator/mermaid/validator/extract-relations.d.ts +8 -0
  39. package/dist/generator/mermaid/validator/extract-relations.js +26 -0
  40. package/dist/generator/mermaid/validator/is-relation.d.ts +2 -0
  41. package/dist/generator/mermaid/validator/is-relation.js +32 -0
  42. package/dist/generator/mermaid/validator/parse-relation.d.ts +8 -0
  43. package/dist/generator/mermaid/validator/parse-relation.js +28 -0
  44. package/dist/generator/mermaid/validator/remove-duplicate-relations.d.ts +7 -0
  45. package/dist/generator/mermaid/validator/remove-duplicate-relations.js +12 -0
  46. package/dist/generator/valibot/generator/generate-valibot-infer-input.d.ts +8 -0
  47. package/dist/generator/valibot/generator/generate-valibot-infer-input.js +16 -0
  48. package/dist/generator/valibot/generator/generate-valibot-properties.d.ts +8 -0
  49. package/dist/generator/valibot/generator/generate-valibot-properties.js +20 -0
  50. package/dist/generator/valibot/generator/generate-valibot-schema.d.ts +9 -0
  51. package/dist/generator/valibot/generator/generate-valibot-schema.js +15 -0
  52. package/dist/generator/valibot/generator/generate-valibot-schemas.d.ts +15 -0
  53. package/dist/generator/valibot/generator/generate-valibot-schemas.js +21 -0
  54. package/dist/generator/valibot/generator/generate-valibot.d.ts +9 -0
  55. package/dist/generator/valibot/generator/generate-valibot.js +54 -0
  56. package/dist/generator/valibot/index.d.ts +10 -0
  57. package/dist/generator/valibot/index.js +53 -0
  58. package/dist/generator/valibot/validator/is-valibot-documentation.d.ts +1 -0
  59. package/dist/generator/valibot/validator/is-valibot-documentation.js +13 -0
  60. package/dist/generator/valibot/validator/is-valibot-validation.d.ts +7 -0
  61. package/dist/generator/valibot/validator/is-valibot-validation.js +15 -0
  62. package/dist/generator/zod/generator/generate-zod-infer.d.ts +8 -0
  63. package/dist/generator/zod/generator/generate-zod-infer.js +16 -0
  64. package/dist/generator/zod/generator/generate-zod-properties.d.ts +14 -0
  65. package/dist/generator/zod/generator/generate-zod-properties.js +26 -0
  66. package/dist/generator/zod/generator/generate-zod-schema.d.ts +9 -0
  67. package/dist/generator/zod/generator/generate-zod-schema.js +15 -0
  68. package/dist/generator/zod/generator/generate-zod-schemas.d.ts +14 -0
  69. package/dist/generator/zod/generator/generate-zod-schemas.js +20 -0
  70. package/dist/generator/zod/generator/generate-zod.d.ts +9 -0
  71. package/dist/generator/zod/generator/generate-zod.js +54 -0
  72. package/dist/generator/zod/index.d.ts +10 -0
  73. package/dist/generator/zod/index.js +53 -0
  74. package/dist/generator/zod/validator/is-zod-documentation.d.ts +6 -0
  75. package/dist/generator/zod/validator/is-zod-documentation.js +18 -0
  76. package/dist/generator/zod/validator/is-zod-validation.d.ts +6 -0
  77. package/dist/generator/zod/validator/is-zod-validation.js +14 -0
  78. package/package.json +56 -0
package/README.md ADDED
@@ -0,0 +1,361 @@
1
+ # Hekireki
2
+
3
+ [Hekireki](https://www.npmjs.com/package/hekireki) is a tool that generates validation schemas for Zod and Valibot, as well as ER diagrams, from [Prisma](https://www.prisma.io/) schemas annotated with comments.
4
+
5
+ ## Features
6
+
7
+ - 💎 Automatically generates [Zod](https://zod.dev/) schemas from your Prisma schema
8
+ - 🤖 Automatically generates [Valibot](https://valibot.dev/) schemas from your Prisma schema
9
+ - 📊 Creates [Mermaid](https://mermaid.js.org/) ER diagrams
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install -D hekireki
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Prepare `schema.prisma`:
20
+
21
+ ```prisma
22
+ generator client {
23
+ provider = "prisma-client-js"
24
+ }
25
+
26
+ datasource db {
27
+ provider = "sqlite"
28
+ url = env("DATABASE_URL")
29
+ }
30
+
31
+ generator Hekireki-ER {
32
+ provider = "hekireki-mermaid-er"
33
+ }
34
+
35
+ generator Hekireki-Zod {
36
+ provider = "hekireki-zod"
37
+ type = true
38
+ comment = true
39
+ }
40
+
41
+ generator Hekireki-Valibot {
42
+ provider = "hekireki-valibot"
43
+ type = true
44
+ comment = true
45
+ }
46
+
47
+ model User {
48
+ /// Unique identifier for the user.
49
+ /// @z.string().uuid()
50
+ /// @v.pipe(v.string(), v.uuid())
51
+ id String @id @default(uuid())
52
+ /// Username of the user.
53
+ /// @z.string().min(3)
54
+ /// @v.pipe(v.string(), v.minLength(3))
55
+ username String
56
+ /// Email address of the user.
57
+ /// @z.string().email()
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[]
74
+ }
75
+
76
+ /// @relation User.id Post.userId one-to-many
77
+ model Post {
78
+ /// Unique identifier for the post.
79
+ /// @z.string().uuid()
80
+ /// @v.pipe(v.string(), v.uuid())
81
+ id String @id @default(uuid())
82
+ /// ID of the user who created the post.
83
+ /// @z.string().uuid()
84
+ /// @v.pipe(v.string(), v.uuid())
85
+ userId String
86
+ /// Content of the post.
87
+ /// @z.string().max(500)
88
+ /// @v.pipe(v.string(), v.maxLength(500))
89
+ content String
90
+ /// Timestamp when the post was created.
91
+ /// @z.date()
92
+ /// @v.date()
93
+ createdAt DateTime @default(now())
94
+ /// Timestamp when the post was last updated.
95
+ /// @z.date()
96
+ /// @v.date()
97
+ updatedAt DateTime @default(now()) @updatedAt
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])
127
+ }
128
+ ```
129
+
130
+ ## Generate
131
+
132
+ ### Zod
133
+
134
+ ```ts
135
+ import { z } from 'zod'
136
+
137
+ export const UserSchema = z.object({
138
+ /**
139
+ * Unique identifier for the user.
140
+ */
141
+ id: z.string().uuid(),
142
+ /**
143
+ * Username of the user.
144
+ */
145
+ username: z.string().min(3),
146
+ /**
147
+ * Email address of the user.
148
+ */
149
+ email: z.string().email(),
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(),
162
+ })
163
+
164
+ export type User = z.infer<typeof UserSchema>
165
+
166
+ export const PostSchema = z.object({
167
+ /**
168
+ * Unique identifier for the post.
169
+ */
170
+ id: z.string().uuid(),
171
+ /**
172
+ * ID of the user who created the post.
173
+ */
174
+ userId: z.string().uuid(),
175
+ /**
176
+ * Content of the post.
177
+ */
178
+ content: z.string().max(500),
179
+ /**
180
+ * Timestamp when the post was created.
181
+ */
182
+ createdAt: z.date(),
183
+ /**
184
+ * Timestamp when the post was last updated.
185
+ */
186
+ updatedAt: z.date(),
187
+ })
188
+
189
+ 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
+ ```
212
+
213
+ ## Valibot
214
+ ```ts
215
+ import * as v from 'valibot'
216
+
217
+ export const UserSchema = v.object({
218
+ /**
219
+ * Unique identifier for the user.
220
+ */
221
+ id: v.pipe(v.string(), v.uuid()),
222
+ /**
223
+ * Username of the user.
224
+ */
225
+ username: v.pipe(v.string(), v.minLength(3)),
226
+ /**
227
+ * Email address of the user.
228
+ */
229
+ email: v.pipe(v.string(), v.email()),
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(),
242
+ })
243
+
244
+ export type User = v.InferInput<typeof UserSchema>
245
+
246
+ export const PostSchema = v.object({
247
+ /**
248
+ * Unique identifier for the post.
249
+ */
250
+ id: v.pipe(v.string(), v.uuid()),
251
+ /**
252
+ * ID of the user who created the post.
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.
274
+ */
275
+ id: v.pipe(v.string(), v.uuid()),
276
+ /**
277
+ * ID of the post that is liked.
278
+ */
279
+ postId: v.pipe(v.string(), v.uuid()),
280
+ /**
281
+ * ID of the user who liked the post.
282
+ */
283
+ userId: v.pipe(v.string(), v.uuid()),
284
+ /**
285
+ * Timestamp when the like was created.
286
+ */
287
+ createdAt: v.date(),
288
+ })
289
+
290
+ export type Like = v.InferInput<typeof LikeSchema>
291
+ ```
292
+
293
+ ## Mermaid
294
+
295
+ ```mermaid
296
+ erDiagram
297
+ User ||--o{ Post : "(id) - (userId)"
298
+ Post ||--o{ Like : "(id) - (postId)"
299
+ User ||--o{ Like : "(id) - (userId)"
300
+ User {
301
+ String id "Unique identifier for the user."
302
+ String username "Username of the user."
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."
307
+ }
308
+ Post {
309
+ String id "Unique identifier for the post."
310
+ String userId "ID of the user who created the post."
311
+ String content "Content of the post."
312
+ DateTime createdAt "Timestamp when the post was created."
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."
320
+ }
321
+ ```
322
+
323
+ ## Configuration
324
+
325
+ ### Zod Generator Options
326
+
327
+ | Option | Type | Default | Description |
328
+ |--------------|-----------|-------------------------------------|--------------------------------------------------|
329
+ | `output` | `string` | `./zod` | Output directory |
330
+ | `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
+ | `type` | `boolean` | `false` | Generate TypeScript types |
334
+ | `comment` | `boolean` | `false` | Include schema documentation |
335
+
336
+ ### Valibot Generator Options
337
+
338
+ | Option | Type | Default | Description |
339
+ |--------------|-----------|-------------------------------------|--------------------------------------------------|
340
+ | `output` | `string` | `./valibot` | Output directory |
341
+ | `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
+ | `type` | `boolean` | `false` | Generate TypeScript types |
345
+ | `comment` | `boolean` | `false` | Include schema documentation |
346
+
347
+ ### Mermaid ER Generator Options
348
+
349
+ | Option | Type | Default | Description |
350
+ |--------------|-----------|-------------------------------------|--------------------------------------------------|
351
+ | `output` | `string` | `./mermaid-er` | Output directory |
352
+ | `file` | `string` | `ER.md` | File Name |
353
+
354
+ ⚠️ WARNING: Potential Breaking Changes Without Notice
355
+
356
+ 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:
357
+
358
+
359
+ ## License
360
+
361
+ Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/hekireki?tab=MIT-1-ov-file) for more information.
@@ -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,7 @@
1
+ /**
2
+ * Generates a camelCase schema name from a given schema name.
3
+ *
4
+ * @param schemaName - The original schema name.
5
+ * @returns The camelCase schema name.
6
+ */
7
+ export declare function getCamelCaseSchemaNameHelper(schemaName: string): string;
@@ -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 "../../generator/zod";
2
+ /**
3
+ * Generates a variable name based on the given name and configuration.
4
+ *
5
+ * @param name - The original name.
6
+ * @param config - The configuration.
7
+ * @returns The variable name.
8
+ */
9
+ export declare function getVariableNameHelper(name: string, config: Config): string;
@@ -0,0 +1,17 @@
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
+ * Generates a variable name based on the given name and configuration.
8
+ *
9
+ * @param name - The original name.
10
+ * @param config - The configuration.
11
+ * @returns The variable name.
12
+ */
13
+ function getVariableNameHelper(name, config) {
14
+ return config.typeName === "camelCase"
15
+ ? (0, decapitalize_1.decapitalize)(name)
16
+ : (0, capitalize_1.capitalize)(name);
17
+ }
@@ -0,0 +1,9 @@
1
+ import type { Config } from "../../generator/zod";
2
+ /**
3
+ * Generates a variable schema name based on the given name and configuration.
4
+ *
5
+ * @param name - The original name.
6
+ * @param config - The configuration.
7
+ * @returns The variable schema name.
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
+ * Generates a variable schema name based on the given name and configuration.
8
+ *
9
+ * @param name - The original name.
10
+ * @param config - The configuration.
11
+ * @returns The variable schema name.
12
+ */
13
+ function getVariableSchemaNameHelper(name, config) {
14
+ return config.schemaName === "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,8 @@
1
+ import type { GroupedFields, ValidField } from "../type";
2
+ /**
3
+ * Groups valid fields by model name.
4
+ *
5
+ * @param validFields - The array of valid fields.
6
+ * @returns The grouped fields.
7
+ */
8
+ export declare function groupByModelHelper(validFields: ValidField[]): GroupedFields;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupByModelHelper = groupByModelHelper;
4
+ /**
5
+ * Groups valid fields by model name.
6
+ *
7
+ * @param validFields - The array of valid fields.
8
+ * @returns The grouped fields.
9
+ */
10
+ function groupByModelHelper(validFields) {
11
+ return validFields.reduce((acc, field) => {
12
+ if (!acc[field.modelName]) {
13
+ acc[field.modelName] = [];
14
+ }
15
+ acc[field.modelName].push(field);
16
+ return acc;
17
+ }, {});
18
+ }
@@ -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
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Decapitalizes the first letter of a string
3
+ *
4
+ * @function decapitalize
5
+ * @param str - String to decapitalize
6
+ * @returns String with the first letter in lowercase
7
+ *
8
+ * @example
9
+ * decapitalize('Posts') // Returns: 'posts'
10
+ * decapitalize('User') // Returns: 'user'
11
+ * decapitalize('Api') // Returns: 'api'
12
+ *
13
+ * @remarks
14
+ * - Leaves the rest of the string unchanged
15
+ * - Returns an empty string if the input is empty
16
+ */
17
+ export declare function decapitalize(str: string): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decapitalize = decapitalize;
4
+ /**
5
+ * Decapitalizes the first letter of a string
6
+ *
7
+ * @function decapitalize
8
+ * @param str - String to decapitalize
9
+ * @returns String with the first letter in lowercase
10
+ *
11
+ * @example
12
+ * decapitalize('Posts') // Returns: 'posts'
13
+ * decapitalize('User') // Returns: 'user'
14
+ * decapitalize('Api') // Returns: 'api'
15
+ *
16
+ * @remarks
17
+ * - Leaves the rest of the string unchanged
18
+ * - Returns an empty string if the input is empty
19
+ */
20
+ function decapitalize(str) {
21
+ return `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
22
+ }
@@ -0,0 +1,16 @@
1
+ import type { DMMF } from "@prisma/generator-helper";
2
+ export type Field = {
3
+ documentation: string;
4
+ modelName: string;
5
+ fieldName: string;
6
+ comment: string[];
7
+ validation: string | null;
8
+ };
9
+ export type ValidField = Required<Field>;
10
+ export type GroupedFields = Record<string, Field[]>;
11
+ export type Model = Readonly<DMMF.Model>;
12
+ export type ModelInfo = {
13
+ documentation: string;
14
+ name: string;
15
+ fields: Model["fields"];
16
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import type { ReadonlyDeep } from "@prisma/generator-helper";
2
+ /**
3
+ * Is fields validation
4
+ * @param modelFields - The model fields
5
+ * @returns The fields validation
6
+ */
7
+ export declare function isFieldsValidation(modelFields: {
8
+ documentation: ReadonlyDeep<string | undefined>;
9
+ modelName: string;
10
+ fieldName: string;
11
+ comment: string[];
12
+ validation: string | null;
13
+ }[][]): Required<import("../type").Field>[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFieldsValidation = isFieldsValidation;
4
+ /**
5
+ * Is fields validation
6
+ * @param modelFields - The model fields
7
+ * @returns The fields validation
8
+ */
9
+ function isFieldsValidation(modelFields) {
10
+ return modelFields
11
+ .flat()
12
+ .filter((field) => field.validation !== null);
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { ERContent, Model } from "../type";
2
+ /**
3
+ * generate ER content
4
+ * @function generateERContent
5
+ * @param models
6
+ * @returns ER content
7
+ */
8
+ export declare function generateERContent(models: readonly Model[]): ERContent;