prismadoc 1.0.29

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 (63) hide show
  1. package/README.md +425 -0
  2. package/dist/config.type.js +38 -0
  3. package/dist/entities/dto-generator.js +69 -0
  4. package/dist/entities/enum.js +40 -0
  5. package/dist/entities/field.js +192 -0
  6. package/dist/entities/generic.js +24 -0
  7. package/dist/entities/model.js +83 -0
  8. package/dist/entities/response-generator.js +30 -0
  9. package/dist/entities/validator.js +16 -0
  10. package/dist/field.type.js +22 -0
  11. package/dist/fields.ts +138 -0
  12. package/dist/file.js +27 -0
  13. package/dist/generic.dto.ts +13 -0
  14. package/dist/index.js +1 -0
  15. package/dist/index.ts +40 -0
  16. package/dist/main.js +155 -0
  17. package/dist/rules.js +35 -0
  18. package/dist/schemas/config.schema.json +136 -0
  19. package/dist/static.js +3 -0
  20. package/dist/types/account-agenda.ts +68 -0
  21. package/dist/types/account-two-factor-auth-log.ts +127 -0
  22. package/dist/types/account-two-factor-auth.ts +145 -0
  23. package/dist/types/account.ts +126 -0
  24. package/dist/types/admin.ts +68 -0
  25. package/dist/types/agenda-day-time-config.ts +113 -0
  26. package/dist/types/agenda-week-day-config.ts +68 -0
  27. package/dist/types/customer.ts +99 -0
  28. package/dist/types/dummy-many.ts +71 -0
  29. package/dist/types/dummy-unique.ts +68 -0
  30. package/dist/types/dummy.ts +68 -0
  31. package/dist/types/email-auth-code.ts +136 -0
  32. package/dist/types/file.ts +299 -0
  33. package/dist/types/firebase-config.ts +140 -0
  34. package/dist/types/knowledge-base-category.ts +91 -0
  35. package/dist/types/knowledge-base-post.ts +262 -0
  36. package/dist/types/kyc-attempt-details.ts +273 -0
  37. package/dist/types/kyc-attempt.ts +365 -0
  38. package/dist/types/kyc-config.ts +199 -0
  39. package/dist/types/kyc-document.ts +260 -0
  40. package/dist/types/meeting-guest.ts +185 -0
  41. package/dist/types/meeting.ts +205 -0
  42. package/dist/types/member.ts +99 -0
  43. package/dist/types/notification.ts +193 -0
  44. package/dist/types/otp-auth-code-request-log.ts +116 -0
  45. package/dist/types/otp-auth-code.ts +136 -0
  46. package/dist/types/owner.ts +68 -0
  47. package/dist/types/policy.ts +169 -0
  48. package/dist/types/push-notification.ts +77 -0
  49. package/dist/types/smtp-config.ts +188 -0
  50. package/dist/types/staff-role.ts +121 -0
  51. package/dist/types/staff.ts +99 -0
  52. package/dist/types/tenant-plan.ts +177 -0
  53. package/dist/types/tenant-role.ts +152 -0
  54. package/dist/types/tenant.ts +149 -0
  55. package/dist/types/ticket-message.ts +177 -0
  56. package/dist/types/ticket.ts +177 -0
  57. package/dist/types/user.ts +281 -0
  58. package/dist/types.js +1 -0
  59. package/dist/utils/helpers.js +146 -0
  60. package/dist/utils/loader.js +81 -0
  61. package/dist/utils/prisma-utils.js +73 -0
  62. package/dist/utils/propeties.static.js +2 -0
  63. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,425 @@
1
+ # Nest Prisma DocGen
2
+
3
+ [![npm version](https://img.shields.io/npm/v/nest-prisma_doc-gen.svg)](https://www.npmjs.com/package/nest-prisma_doc-gen)
4
+ [![npm downloads](https://img.shields.io/npm/dm/nest-prisma_doc-gen.svg)](https://www.npmjs.com/package/nest-prisma_doc-gen)
5
+ [![npm total downloads](https://img.shields.io/npm/dt/nest-prisma_doc-gen.svg)](https://www.npmjs.com/package/nest-prisma_doc-gen)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.6+-blue.svg)](https://www.typescriptlang.org/)
7
+ [![NestJS](https://img.shields.io/badge/NestJS-9+-red.svg)](https://nestjs.com/)
8
+ [![Prisma](https://img.shields.io/badge/Prisma-7+-2D3748.svg)](https://www.prisma.io/)
9
+
10
+ A TypeScript code generator that automatically creates NestJS Swagger DTOs and Response types from your Prisma schema. Eliminates the boilerplate of writing `@ApiProperty()` decorators by parsing your `schema.prisma` file.
11
+
12
+ ## 🚨 Looking for a Better Name?
13
+
14
+ This package is currently named `nest-prisma_doc-gen`, but we're considering alternatives:
15
+
16
+ | Option | Rationale |
17
+ |--------|-----------|
18
+ | **`prisma-nest-swagger`** | Clear stack order: Prisma → Nest → Swagger |
19
+ | **`prisma-swagger-dto`** | Emphasizes DTO generation for Swagger |
20
+ | **`@pinaculo/prisma-doc`** | Scoped package, cleaner and professional |
21
+ | **`prisma-api-gen`** | Short, generic but descriptive |
22
+ | **`nest-prisma-codegen`** | Emphasizes code generation aspect |
23
+
24
+ **Vote for your favorite by opening an issue!** 🗳️
25
+
26
+ ---
27
+
28
+ ## 🚀 Features
29
+
30
+ - **🔮 Auto-Generated DTOs** - Creates TypeScript DTOs with `@ApiProperty()` decorators from Prisma models
31
+ - **📦 Response Types** - Generates response classes for API documentation
32
+ - **🎯 Type-Safe** - Full TypeScript support with proper type inference
33
+ - **⚡ Intersection Types** - Uses NestJS `IntersectionType` for composing DTOs
34
+ - **🧹 Ignores Boilerplate** - Automatically skips `id`, `createdAt`, `updatedAt` fields
35
+ - **✅ Class Validator Support** - Integrates with `class-validator` decorators
36
+ - **📊 Enum Support** - Handles Prisma enums automatically
37
+ - **🔧 Configurable** - Customizable via `doc-gen.config.json`
38
+
39
+ ## 📦 Installation
40
+
41
+ ```bash
42
+ npm install nest-prisma_doc-gen
43
+ # or
44
+ yarn add nest-prisma_doc-gen
45
+ # or
46
+ pnpm add nest-prisma_doc-gen
47
+ ```
48
+
49
+ ## 🏁 Quick Start
50
+
51
+ ### 1. Create Configuration File
52
+
53
+ Create `doc-gen.config.json` in your project root:
54
+
55
+ ```json
56
+ {
57
+ "prismaPath": "prisma",
58
+ "validatorPath": "src/_nest/validators",
59
+ "ignore": ["createdAt", "updatedAt", "password"],
60
+ "examples": [],
61
+ "validators": []
62
+ }
63
+ ```
64
+
65
+ ### 2. Run the Generator
66
+
67
+ ```bash
68
+ # Using npx
69
+ npx doc-gen
70
+
71
+ # Or add to package.json scripts
72
+ {
73
+ "scripts": {
74
+ "generate:docs": "doc-gen"
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### 3. Use Generated Types
80
+
81
+ The generator creates files in `src/types/docgen/`:
82
+
83
+ ```typescript
84
+ import { User } from "src/types/docgen";
85
+
86
+ // Use the DTO
87
+ @Controller("users")
88
+ export class UserController {
89
+ @Post()
90
+ @ApiBody({ type: User.Dto })
91
+ async create(@Body() dto: User.Dto): Promise<User.Res> {
92
+ // Your implementation
93
+ }
94
+
95
+ @Get(":userId")
96
+ async findOne(@Param() { userId }: User.Id): Promise<User.Res> {
97
+ // Your implementation
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## 📁 Generated Structure
103
+
104
+ ```
105
+ src/types/docgen/
106
+ ├── index.ts # Main exports
107
+ ├── docgen-fields.ts # Field constants
108
+ ├── entities/
109
+ │ └── [model].response.ts # Response types
110
+ └── types/
111
+ └── [model].ts # DTOs and namespaces
112
+ ```
113
+
114
+ ### Example Generated File
115
+
116
+ For a Prisma model like:
117
+
118
+ ```prisma
119
+ model User {
120
+ id String @id @default(cuid())
121
+ email String @unique
122
+ name String
123
+ role Role @default(USER)
124
+ createdAt DateTime @default(now())
125
+ updatedAt DateTime @updatedAt
126
+ }
127
+
128
+ enum Role {
129
+ USER
130
+ ADMIN
131
+ }
132
+ ```
133
+
134
+ The generator produces:
135
+
136
+ ```typescript
137
+ // AUTO GENERADO. QUEM ALTERAR GOSTA DE RAPAZES!
138
+ /* eslint-disable @typescript-eslint/no-namespace */
139
+ import { ApiProperty, IntersectionType } from '@nestjs/swagger';
140
+ import { IsString, IsNotEmpty, IsEnum } from 'src/_nest/validators';
141
+ import { Role } from '@prisma/client';
142
+
143
+ class EmailDto {
144
+ @ApiProperty({ type: 'string', example: 'user@example.com', required: true })
145
+ @IsString()
146
+ @IsNotEmpty()
147
+ email!: string;
148
+ }
149
+
150
+ class NameDto {
151
+ @ApiProperty({ type: 'string', example: 'John Doe', required: true })
152
+ @IsString()
153
+ @IsNotEmpty()
154
+ name!: string;
155
+ }
156
+
157
+ class RoleDto {
158
+ @ApiProperty({ enum: Role, enumName: 'Role', example: Role.USER, required: true })
159
+ @IsEnum(Role)
160
+ role!: Role;
161
+ }
162
+
163
+ class UserDto extends IntersectionType(EmailDto, NameDto, RoleDto) {}
164
+
165
+ class UserId {
166
+ @ApiProperty({ type: 'string', example: 'cmfxu4njg000008l52v7t8qze', required: true })
167
+ @IsString()
168
+ @IsNotEmpty()
169
+ userid!: string;
170
+ }
171
+
172
+ // Response types...
173
+
174
+ export namespace User {
175
+ export const Dto = UserDto;
176
+ export type Dto = UserDto;
177
+ export const Res = UserRes;
178
+ export type Res = UserRes;
179
+ export const Id = UserId;
180
+ export type Id = UserId;
181
+
182
+ export namespace Input {
183
+ export namespace Email {
184
+ export type Dto = EmailDto
185
+ export const Dto = EmailDto
186
+ }
187
+ export namespace Name {
188
+ export type Dto = NameDto
189
+ export const Dto = NameDto
190
+ }
191
+ export namespace Role {
192
+ export type Dto = RoleDto
193
+ export const Dto = RoleDto
194
+ }
195
+ }
196
+ }
197
+ ```
198
+
199
+ ## ⚙️ Configuration
200
+
201
+ ### `doc-gen.config.json`
202
+
203
+ | Property | Type | Default | Description |
204
+ |----------|------|---------|-------------|
205
+ | `prismaPath` | `string` | `"prisma"` | Path to prisma schema folder |
206
+ | `validatorPath` | `string` | `"src/_nest/validators"` | Import path for validators |
207
+ | `ignore` | `string[]` | `[]` | Field names to ignore (e.g., `["password"]`)
208
+ | `examples` | `array` | `[]` | Custom example generators |
209
+ | `validators` | `array` | `[]` | Field-specific validators |
210
+
211
+ ### Advanced Configuration
212
+
213
+ ```json
214
+ {
215
+ "prismaPath": "prisma",
216
+ "validatorPath": "src/common/validators",
217
+ "ignore": ["createdAt", "updatedAt", "deletedAt", "passwordHash"],
218
+ "examples": [
219
+ {
220
+ "field": "email",
221
+ "value": "user@example.com"
222
+ },
223
+ {
224
+ "field": "phone",
225
+ "value": "+1 555-1234"
226
+ }
227
+ ],
228
+ "validators": [
229
+ {
230
+ "fields": ["email"],
231
+ "validator": "IsEmail"
232
+ },
233
+ {
234
+ "fields": ["phone"],
235
+ "validator": "IsPhoneNumber"
236
+ }
237
+ ]
238
+ }
239
+ ```
240
+
241
+ ## 🧩 Generated API
242
+
243
+ Each model generates a namespace with:
244
+
245
+ ### Types/Classes
246
+
247
+ | Export | Type | Description |
248
+ |--------|------|-------------|
249
+ | `User.Dto` | `class` | Input DTO for create/update operations |
250
+ | `User.Res` | `class` | Response type with all fields |
251
+ | `User.Id` | `class` | ID parameter type for routes |
252
+
253
+ ### Input Namespace
254
+
255
+ Access individual field DTOs:
256
+
257
+ ```typescript
258
+ import { User } from "src/types/docgen";
259
+
260
+ // Individual field DTOs
261
+ type EmailDto = User.Input.Email.Dto;
262
+ type NameDto = User.Input.Name.Dto;
263
+
264
+ // Use in custom compositions
265
+ class CustomDto extends IntersectionType(
266
+ User.Input.Email.Dto,
267
+ User.Input.Name.Dto
268
+ ) {}
269
+ ```
270
+
271
+ ## 🔧 TypeScript Configuration
272
+
273
+ Ensure your `tsconfig.json` includes:
274
+
275
+ ```json
276
+ {
277
+ "compilerOptions": {
278
+ "strict": true,
279
+ "esModuleInterop": true,
280
+ "experimentalDecorators": true,
281
+ "emitDecoratorMetadata": true
282
+ }
283
+ }
284
+ ```
285
+
286
+ ## 📚 Usage Examples
287
+
288
+ ### Basic Controller
289
+
290
+ ```typescript
291
+ import { Controller, Get, Post, Body, Param } from "@nestjs/common";
292
+ import { ApiBody, ApiResponse } from "@nestjs/swagger";
293
+ import { User } from "src/types/docgen";
294
+
295
+ @Controller("users")
296
+ export class UserController {
297
+ @Post()
298
+ @ApiBody({ type: User.Dto })
299
+ @ApiResponse({ status: 201, type: User.Res })
300
+ async create(@Body() dto: User.Dto): Promise<User.Res> {
301
+ return this.userService.create(dto);
302
+ }
303
+
304
+ @Get(":userId")
305
+ @ApiResponse({ status: 200, type: User.Res })
306
+ async findOne(@Param() params: User.Id): Promise<User.Res> {
307
+ return this.userService.findOne(params.userid);
308
+ }
309
+
310
+ @Get()
311
+ @ApiResponse({ status: 200, type: [User.Res] })
312
+ async findAll(): Promise<User.Res[]> {
313
+ return this.userService.findAll();
314
+ }
315
+ }
316
+ ```
317
+
318
+ ### Custom Validation
319
+
320
+ ```typescript
321
+ // src/_nest/validators/index.ts
322
+ export { IsString, IsNotEmpty, IsEnum, IsEmail, IsOptional } from "class-validator";
323
+
324
+ // Custom validators
325
+ export function IsPhoneNumber() {
326
+ // Your custom validator
327
+ }
328
+ ```
329
+
330
+ ### Integration with Prisma Client
331
+
332
+ ```typescript
333
+ import { Injectable } from "@nestjs/common";
334
+ import { PrismaService } from "src/prisma/prisma.service";
335
+ import { User } from "src/types/docgen";
336
+
337
+ @Injectable()
338
+ export class UserService {
339
+ constructor(private prisma: PrismaService) {}
340
+
341
+ async create(dto: User.Dto): Promise<User.Res> {
342
+ return this.prisma.user.create({ data: dto });
343
+ }
344
+
345
+ async findOne(id: string): Promise<User.Res> {
346
+ return this.prisma.user.findUnique({ where: { id } });
347
+ }
348
+ }
349
+ ```
350
+
351
+ ## 🔄 Workflow Integration
352
+
353
+ ### Development
354
+
355
+ Add to your development workflow:
356
+
357
+ ```json
358
+ {
359
+ "scripts": {
360
+ "db:generate": "prisma generate && doc-gen",
361
+ "build": "doc-gen && nest build",
362
+ "dev": "doc-gen && nest start --watch"
363
+ }
364
+ }
365
+ ```
366
+
367
+ ### Pre-commit Hook
368
+
369
+ Using Husky:
370
+
371
+ ```bash
372
+ # .husky/pre-commit
373
+ npm run doc-gen
374
+ git add src/types/docgen
375
+ ```
376
+
377
+ ## 🛠️ Troubleshooting
378
+
379
+ ### "Cannot find module" Errors
380
+
381
+ Ensure the generator has run:
382
+
383
+ ```bash
384
+ npx doc-gen
385
+ ```
386
+
387
+ ### Prisma Schema Not Found
388
+
389
+ Check your `doc-gen.config.json`:
390
+
391
+ ```json
392
+ {
393
+ "prismaPath": "prisma" // Adjust if your schema is elsewhere
394
+ }
395
+ ```
396
+
397
+ ### Validators Not Importing
398
+
399
+ Verify the `validatorPath` in config matches your project structure:
400
+
401
+ ```json
402
+ {
403
+ "validatorPath": "src/common/validators" // Adjust as needed
404
+ }
405
+ ```
406
+
407
+ ## 📄 License
408
+
409
+ ISC License - see [LICENSE](LICENSE) for details.
410
+
411
+ ## 🤝 Contributing
412
+
413
+ Contributions are welcome! Please feel free to submit a Pull Request.
414
+
415
+ ## 🔗 Links
416
+
417
+ - [npm](https://www.npmjs.com/package/nest-prisma_doc-gen)
418
+ - [GitHub](https://github.com/aleleppy/nest-prisma-doc-gen)
419
+ - [NestJS](https://nestjs.com/)
420
+ - [Prisma](https://www.prisma.io/)
421
+ - [Swagger/OpenAPI](https://swagger.io/)
422
+
423
+ ---
424
+
425
+ Built with 🦍 by the Pináculo Digital team.
@@ -0,0 +1,38 @@
1
+ export class ValidatorBuilder {
2
+ decorator;
3
+ inside;
4
+ fields;
5
+ constructor(decorator, fields, inside) {
6
+ this.decorator = decorator;
7
+ this.fields = fields;
8
+ this.inside = inside;
9
+ }
10
+ }
11
+ export class ApiExampleBuilder {
12
+ fields;
13
+ example;
14
+ constructor(fields, example) {
15
+ this.fields = fields;
16
+ this.example = example;
17
+ }
18
+ }
19
+ export class ExternalPrismaSchema {
20
+ name;
21
+ url;
22
+ apiKey;
23
+ constructor(name, url, apiKey) {
24
+ this.name = name;
25
+ this.url = url;
26
+ this.apiKey = apiKey;
27
+ }
28
+ /** Resolve apiKey: se começa com '$', busca de process.env; senão, retorna literal */
29
+ resolveApiKey() {
30
+ if (!this.apiKey)
31
+ return undefined;
32
+ if (this.apiKey.startsWith("$")) {
33
+ const envVar = this.apiKey.slice(1);
34
+ return process.env[envVar];
35
+ }
36
+ return this.apiKey;
37
+ }
38
+ }
@@ -0,0 +1,69 @@
1
+ import { Helper } from "../utils/helpers.js";
2
+ import { Static } from "../static.js";
3
+ import { DocGenField } from "./field.js";
4
+ import { config } from "../utils/loader.js";
5
+ export class DocGenDto {
6
+ name;
7
+ // file: DocGenFile;
8
+ fields = [];
9
+ imports = new Set([
10
+ `${Static.AUTO_GENERATED_COMMENT}`,
11
+ "/* eslint-disable @typescript-eslint/no-namespace */",
12
+ `import { ApiProperty, IntersectionType } from '@nestjs/swagger'`,
13
+ ]);
14
+ classValidators = new Set();
15
+ enums = new Set();
16
+ enumImportPath;
17
+ constructor(model, enumImportPath) {
18
+ this.name = model.name;
19
+ this.enumImportPath = enumImportPath ?? "@prisma/client";
20
+ this.classValidators.add("IsString");
21
+ this.classValidators.add("IsNotEmpty");
22
+ for (const field of model.fields) {
23
+ if (field.isUpdatedAt || field.isId || field.name === "createdAt" || field.kind === "object")
24
+ continue;
25
+ this.fields.push(new DocGenField(field, "dto"));
26
+ }
27
+ }
28
+ build() {
29
+ const sanitizedFields = this.fields
30
+ .map((field) => {
31
+ for (const { name } of field.validators) {
32
+ this.classValidators.add(name);
33
+ }
34
+ if (field.isResponse) {
35
+ this.imports.add(`import { ${field.type} } from '../entities/${Helper.toKebab(field.scalarType)}.response'`);
36
+ this.imports.add(`import { generateExample } from 'src/utils/functions/reflect'`);
37
+ }
38
+ else if (field.isEnum) {
39
+ this.enums.add(field.type);
40
+ }
41
+ return `class ${Helper.capitalizeFirstSafe(field.name)}Dto {
42
+ ${field.build()}
43
+ }`;
44
+ })
45
+ .join("\n\n");
46
+ if (this.enums.size > 0) {
47
+ this.classValidators.add("IsEnum");
48
+ this.imports.add(`import { ${Array.from(this.enums)} } from '${this.enumImportPath}';`);
49
+ }
50
+ this.imports.add(`import { ${Array.from(this.classValidators)} } from '${config.validatorPath}';`);
51
+ const intersections = this.fields.map((field) => Helper.capitalizeFirstSafe(field.name) + "Dto");
52
+ const intersectionClassName = `class ${this.name}Dto`;
53
+ const intersectionClass = intersections.length > 0
54
+ ? `${intersectionClassName} extends IntersectionType(${intersections.join(",")}) {}`
55
+ : `${intersectionClassName}{}`;
56
+ return [
57
+ `${Array.from(this.imports).join("\n")}`,
58
+ `${sanitizedFields}`,
59
+ `${intersectionClass}`,
60
+ `class ${this.name}Id {
61
+ @ApiProperty({ type: 'string', example: 'cmfxu4njg000008l52v7t8qze', required: true })
62
+ @IsString()
63
+ @IsNotEmpty()
64
+ ${this.name.toLocaleLowerCase()}Id!: string;
65
+ }
66
+ `,
67
+ ].join("\n\n");
68
+ }
69
+ }
@@ -0,0 +1,40 @@
1
+ // import { DocGenFile } from "../file.js";
2
+ // import { DbName } from "../types.js";
3
+ export {};
4
+ // export type EnumValue = { name: string; dbName: DbName };
5
+ // export class DocGenEnum {
6
+ // name: string;
7
+ // values: EnumValue[];
8
+ // dbName: DbName;
9
+ // constructor(params: { name: string; values: EnumValue[]; dbName: DbName }) {
10
+ // const { dbName, name, values } = params;
11
+ // this.dbName = dbName;
12
+ // this.name = name;
13
+ // this.values = values;
14
+ // }
15
+ // }
16
+ // export class DocEnums {
17
+ // enums: DocGenEnum[];
18
+ // file: DocGenFile;
19
+ // constructor(enums: DocGenEnum[]) {
20
+ // this.enums = enums;
21
+ // this.file = new DocGenFile({
22
+ // dir: "/",
23
+ // fileName: "enums.ts",
24
+ // data: this.build(),
25
+ // });
26
+ // }
27
+ // build() {
28
+ // const enums = this.enums.map((en) => {
29
+ // const enumName = en.name;
30
+ // return `
31
+ // export const ${enumName} = [${en.values.map((n) => `'${n.name}'`)}] as const;
32
+ // export type ${enumName} = typeof ${enumName}[number];
33
+ // `;
34
+ // });
35
+ // return `
36
+ // // AUTO-GERADO: NÃO EDITAR MANUALMENTE. SUJEITO A PAULADAS!
37
+ // ${enums.join("\n")}
38
+ // `;
39
+ // }
40
+ // }