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
@@ -0,0 +1,192 @@
1
+ import { Helper } from "../utils/helpers.js";
2
+ import { config } from "../utils/loader.js";
3
+ import { Validator } from "./validator.js";
4
+ const helpers = new Helper();
5
+ const rules = config;
6
+ export class DocGenField {
7
+ name;
8
+ isArray;
9
+ default;
10
+ scalarType;
11
+ kind;
12
+ type;
13
+ fieldType;
14
+ isEnum = false;
15
+ isResponse = false;
16
+ isUpdatedAt = false;
17
+ isRequired;
18
+ validators = new Set();
19
+ scalarField;
20
+ constructor(field, fieldType) {
21
+ const { name, isList, type, kind, isRequired, isUpdatedAt } = field;
22
+ this.name = name;
23
+ this.isArray = isList;
24
+ this.scalarType = type;
25
+ this.kind = kind;
26
+ this.isRequired = isRequired;
27
+ this.scalarField = field;
28
+ this.isUpdatedAt = isUpdatedAt;
29
+ this.fieldType = fieldType;
30
+ this.setType();
31
+ this.setValidators();
32
+ }
33
+ processValidator(params) {
34
+ const validator = new Validator(params);
35
+ if (this.isArray)
36
+ validator.inside = {
37
+ type: "number",
38
+ content: "{ each: true }",
39
+ };
40
+ this.validators.add(validator);
41
+ }
42
+ setValidators() {
43
+ if (this.scalarType === "String" || this.scalarType === "DateTime" || this.scalarType === "Json") {
44
+ this.processValidator({ name: "IsString" });
45
+ if (this.isRequired) {
46
+ this.processValidator({ name: "IsNotEmpty" });
47
+ }
48
+ }
49
+ else if (this.scalarType === "Boolean") {
50
+ this.processValidator({ name: "IsBoolean" });
51
+ }
52
+ else if (this.scalarType === "Int" ||
53
+ this.scalarType === "BigInt" ||
54
+ this.scalarType === "Float" ||
55
+ this.scalarType === "Decimal") {
56
+ this.processValidator({ name: "IsNumber" });
57
+ }
58
+ if (this.isArray) {
59
+ const validator = new Validator({ name: "IsArray" });
60
+ this.validators.add(validator);
61
+ }
62
+ if (!this.isRequired)
63
+ this.processValidator({ name: "IsOptional" });
64
+ if (this.isEnum) {
65
+ const content = this.isArray ? `${this.type}, { each: true } ` : this.type;
66
+ this.validators.add(new Validator({
67
+ name: "IsEnum",
68
+ inside: {
69
+ content,
70
+ type: "number",
71
+ },
72
+ }));
73
+ }
74
+ const findedDecorators = rules.validators.get(this.name);
75
+ if (findedDecorators) {
76
+ for (const props of findedDecorators) {
77
+ const { decorator, inside } = props;
78
+ this.processValidator({ name: decorator, inside: inside });
79
+ }
80
+ }
81
+ }
82
+ setType() {
83
+ if (this.kind === "enum") {
84
+ this.isEnum = true;
85
+ this.type = this.scalarType;
86
+ }
87
+ else if (this.kind === "object") {
88
+ this.isResponse = true;
89
+ this.type = `${this.scalarType}Res`;
90
+ }
91
+ else if (this.kind === "scalar") {
92
+ this.type = Helper.prismaScalarToTs(this.scalarType);
93
+ }
94
+ }
95
+ getRuledExample(fieldName) {
96
+ const example = rules.examples.get(fieldName)?.example;
97
+ if (!example && example !== 0) {
98
+ return "example: 'aaaa'";
99
+ }
100
+ const isNumber = Number.isInteger(example);
101
+ return isNumber ? `example: ${example}` : `example: '${example}'`;
102
+ }
103
+ buildApiExample() {
104
+ const fieldName = this.scalarField.name;
105
+ const props = [];
106
+ if (this.isResponse) {
107
+ if (this.isArray) {
108
+ props.push(`example: [generateExample(${this.type})]`);
109
+ }
110
+ else {
111
+ props.push(`example: generateExample(${this.type})`);
112
+ }
113
+ }
114
+ else if (rules.examples.get(fieldName)) {
115
+ props.push(this.getRuledExample(fieldName));
116
+ }
117
+ else if (helpers.isDate(this.scalarField)) {
118
+ props.push(`example: '2025-09-03T03:00:00.000Z'`);
119
+ }
120
+ else if (this.scalarField.isId || Helper.splitByUpperCase(this.scalarField.name).includes("Id")) {
121
+ props.push(`example: 'cmfxu4njg000008l52v7t8qze'`);
122
+ }
123
+ else if (this.scalarField.type === "Boolean") {
124
+ props.push(`example: true`);
125
+ }
126
+ else if (this.scalarField.kind === "enum") {
127
+ const example = [`example: Object.values(${this.scalarField.type}) ${this.isArray ? "" : "[0]"}`];
128
+ props.push(example.join());
129
+ }
130
+ else if (this.scalarField.type === "Int") {
131
+ props.push(`example: 777`);
132
+ }
133
+ else if (this.scalarField.type === "String") {
134
+ props.push(`example: 'ordinary string'`);
135
+ }
136
+ if (this.type === "object") {
137
+ props.push(`additionalProperties: true`);
138
+ }
139
+ else {
140
+ props.push(`required: ${this.scalarField.isRequired}`);
141
+ }
142
+ return props;
143
+ }
144
+ sanitizeValidators() {
145
+ const sanitizedValidators = Array.from(this.validators).map((validator) => {
146
+ return validator.build();
147
+ });
148
+ return sanitizedValidators;
149
+ }
150
+ buildInfos() {
151
+ const key = this.isEnum ? "enum" : "type";
152
+ const apiType = () => {
153
+ if (this.type === "Date")
154
+ return `'string'`;
155
+ if (this.isArray && this.isResponse) {
156
+ return `[${this.type}]`;
157
+ }
158
+ else if (this.isEnum) {
159
+ return `${this.type}`;
160
+ }
161
+ else if (this.isResponse) {
162
+ return `() => ${this.type}`;
163
+ }
164
+ return `'${this.type}'`;
165
+ };
166
+ const fieldType = () => {
167
+ if (this.isArray) {
168
+ return `${this.type}[]`;
169
+ }
170
+ else {
171
+ return this.type;
172
+ }
173
+ };
174
+ const optionalFlag = this.isRequired ? "!" : "?";
175
+ const validators = this.sanitizeValidators();
176
+ const apiExample = this.buildApiExample().join(", ");
177
+ return {
178
+ apiProperty: `@ApiProperty({ ${key}: ${apiType()}, ${apiExample}, ${this.isArray ? "isArray: true" : ""} })`,
179
+ validators,
180
+ atributes: `${this.name}${optionalFlag}: ${fieldType()};`,
181
+ };
182
+ }
183
+ build() {
184
+ const { apiProperty, atributes, validators } = this.buildInfos();
185
+ if (this.fieldType === "dto") {
186
+ return [apiProperty, ...validators, atributes].join("\n");
187
+ }
188
+ else {
189
+ return [apiProperty, atributes].join("\n");
190
+ }
191
+ }
192
+ }
@@ -0,0 +1,24 @@
1
+ import { DocGenFile } from "../file.js";
2
+ import { config } from "../utils/loader.js";
3
+ export class DocGenGeneric {
4
+ file;
5
+ constructor() {
6
+ const imports = `
7
+ import { ApiProperty } from '@nestjs/swagger';
8
+ import { IsString, IsNotEmpty } from '${config.validatorPath}';
9
+ `;
10
+ const validatorProps = `
11
+ export class DefaultIdDto {
12
+ @ApiProperty({ type: 'string', example: 'cmfxu4njg000008l52v7t8qze', required: true })
13
+ @IsString()
14
+ @IsNotEmpty()
15
+ id!: string;
16
+ }
17
+ `;
18
+ const fileContent = [imports, validatorProps];
19
+ this.file = new DocGenFile({ fileName: "generic.dto.ts", data: fileContent.join("\n"), dir: "" });
20
+ }
21
+ build() {
22
+ this.file.save();
23
+ }
24
+ }
@@ -0,0 +1,83 @@
1
+ import { DocGenFile } from "../file.js";
2
+ import { Helper } from "../utils/helpers.js";
3
+ import { DocGenDto } from "./dto-generator.js";
4
+ import { DocGenResponse } from "./response-generator.js";
5
+ export class DocGenModel {
6
+ name;
7
+ response;
8
+ dto;
9
+ fields;
10
+ exports;
11
+ file;
12
+ servicePrefix;
13
+ constructor(model, servicePrefix) {
14
+ this.name = model.name;
15
+ this.fields = model.fields;
16
+ this.servicePrefix = servicePrefix;
17
+ const enumImportPath = servicePrefix ? "../enums" : undefined;
18
+ this.response = new DocGenResponse(model);
19
+ this.dto = new DocGenDto(model, enumImportPath);
20
+ const kebabName = Helper.toKebab(this.name);
21
+ const fileName = servicePrefix ? `${servicePrefix}.${kebabName}` : kebabName;
22
+ this.exports = [`export * from './types/${fileName}'`];
23
+ const teste = new Map();
24
+ const bla = [...this.dto.fields, ...this.response.fields];
25
+ bla.forEach((field) => {
26
+ let a = teste.get(field.name);
27
+ if (!a) {
28
+ a = [];
29
+ teste.set(field.name, a);
30
+ }
31
+ a.push(field.fieldType);
32
+ });
33
+ const fdm = `
34
+ export namespace Input {
35
+ ${Array.from(teste)
36
+ .map(([fieldName, fieldTypes]) => {
37
+ const name = Helper.capitalizeFirstSafe(fieldName);
38
+ const types = fieldTypes.map((type) => Helper.capitalizeFirstSafe(type));
39
+ return `
40
+ export namespace ${name} {
41
+ ${types
42
+ .map((type) => {
43
+ return `
44
+ export type ${type} = ${name + type}
45
+ export const ${type} = ${name + type}
46
+ `;
47
+ })
48
+ .join(";")}
49
+ }
50
+ `;
51
+ })
52
+ .join(";")}
53
+ }
54
+ `;
55
+ const intaaa = `
56
+ export namespace ${this.name} {
57
+ export const Dto = ${this.name}Dto;
58
+ export type Dto = ${this.name}Dto;
59
+ export const Res = ${this.name}Res;
60
+ export type Res = ${this.name}Res;
61
+ export const Id = ${this.name}Id;
62
+ export type Id = ${this.name}Id;
63
+ ${fdm}
64
+ }
65
+ `;
66
+ // Build response primeiro para coletar enums, depois mergear no DTO
67
+ const responseResult = this.response.build();
68
+ for (const e of this.response.enums) {
69
+ this.dto.enums.add(e);
70
+ }
71
+ const dtoResult = this.dto.build();
72
+ const data = [dtoResult, responseResult, intaaa].join("");
73
+ const fileDir = servicePrefix ? `/${servicePrefix}/types` : "/types";
74
+ this.file = new DocGenFile({
75
+ dir: fileDir,
76
+ fileName: `${fileName}.ts`,
77
+ data,
78
+ });
79
+ }
80
+ save() {
81
+ this.file.save();
82
+ }
83
+ }
@@ -0,0 +1,30 @@
1
+ import { Helper } from "../utils/helpers.js";
2
+ import { DocGenField } from "./field.js";
3
+ export class DocGenResponse {
4
+ name;
5
+ // file: DocGenFile;
6
+ fields = [];
7
+ enums = new Set();
8
+ constructor(model) {
9
+ this.name = model.name;
10
+ for (const field of model.fields) {
11
+ if (field.kind === "object")
12
+ continue;
13
+ this.fields.push(new DocGenField(field, "res"));
14
+ }
15
+ }
16
+ build() {
17
+ const sanitizedFields = this.fields
18
+ .map((field) => {
19
+ if (field.isEnum) {
20
+ this.enums.add(field.type);
21
+ }
22
+ return `class ${Helper.capitalizeFirstSafe(field.name)}Res {
23
+ ${field.build()}
24
+ }`;
25
+ })
26
+ .join("\n\n");
27
+ const intersections = this.fields.map((field) => Helper.capitalizeFirstSafe(field.name) + "Res");
28
+ return [`${sanitizedFields}`, `class ${this.name}Res extends IntersectionType(${intersections.join(",")}) {}`].join("\n\n");
29
+ }
30
+ }
@@ -0,0 +1,16 @@
1
+ export class Validator {
2
+ name;
3
+ inside;
4
+ constructor(params) {
5
+ const { name, inside } = params;
6
+ this.name = name;
7
+ this.inside = inside;
8
+ }
9
+ build() {
10
+ if (!this.inside) {
11
+ return `@${this.name}()`;
12
+ }
13
+ const value = this.inside.type === "number" ? this.inside.content : `'${this.inside.content}'`;
14
+ return `@${this.name}(${value})`;
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ import { DocGenFile } from "./file.js";
2
+ import { Static } from "./static.js";
3
+ export class DocFields {
4
+ fields;
5
+ file;
6
+ constructor(fields) {
7
+ this.fields = fields;
8
+ this.file = new DocGenFile({
9
+ dir: "/",
10
+ fileName: "fields.ts",
11
+ data: this.build(),
12
+ });
13
+ }
14
+ build() {
15
+ const content = `
16
+ ${Static.AUTO_GENERATED_COMMENT}
17
+ export const FIELD_NAMES = [${this.fields}] as const
18
+ export type FieldName = (typeof FIELD_NAMES)[number];
19
+ `;
20
+ return content;
21
+ }
22
+ }
package/dist/fields.ts ADDED
@@ -0,0 +1,138 @@
1
+ // AUTO-GERADO: NÃO EDITAR MANUALMENTE. SUJEITO A PAULADAS!
2
+ export const FIELD_NAMES = [
3
+ "id",
4
+ "user",
5
+ "country",
6
+ "admin",
7
+ "owner",
8
+ "customer",
9
+ "member",
10
+ "staff",
11
+ "agenda",
12
+ "notifications",
13
+ "twoFactorAuth",
14
+ "kycAttempts",
15
+ "tickets",
16
+ "ticketMessages",
17
+ "avatarId",
18
+ "createdAt",
19
+ "updatedAt",
20
+ "account",
21
+ "status",
22
+ "daysConfig",
23
+ "meetingGuestIn",
24
+ "meetingOwnerIn",
25
+ "accountAgenda",
26
+ "weekDay",
27
+ "timeConfigs",
28
+ "startMin",
29
+ "endMin",
30
+ "weekDayConfigId",
31
+ "weekDayConfig",
32
+ "planId",
33
+ "plan",
34
+ "title",
35
+ "message",
36
+ "read",
37
+ "accountId",
38
+ "readAt",
39
+ "name",
40
+ "posts",
41
+ "content",
42
+ "categoryId",
43
+ "category",
44
+ "coverId",
45
+ "imagesId",
46
+ "publishedAt",
47
+ "phone",
48
+ "nationality",
49
+ "street",
50
+ "number",
51
+ "complement",
52
+ "neighborhood",
53
+ "city",
54
+ "state",
55
+ "zipCode",
56
+ "kycAttemptId",
57
+ "kycAttempt",
58
+ "guests",
59
+ "meetingOwnerAccountAgendaId",
60
+ "meetingOwnerAccountAgenda",
61
+ "startDate",
62
+ "endDate",
63
+ "inviteStatus",
64
+ "agendaId",
65
+ "meetingId",
66
+ "meeting",
67
+ "acceptedAt",
68
+ "roleId",
69
+ "role",
70
+ "email",
71
+ "code",
72
+ "expiresAt",
73
+ "tenant",
74
+ "externalId",
75
+ "enabled",
76
+ "secret",
77
+ "logs",
78
+ "action",
79
+ "success",
80
+ "accountTwoFactorAuthId",
81
+ "accountTwoFactorAuth",
82
+ "privacy",
83
+ "mimeType",
84
+ "key",
85
+ "size",
86
+ "url",
87
+ "isUnique",
88
+ "originalName",
89
+ "referenceCount",
90
+ "fileId",
91
+ "files",
92
+ "active",
93
+ "projectId",
94
+ "privateKey",
95
+ "clientEmail",
96
+ "isEnabled",
97
+ "mandatoryDocuments",
98
+ "expirationInDays",
99
+ "maxAttempts",
100
+ "tenantId",
101
+ "legalName",
102
+ "dateOfBirth",
103
+ "details",
104
+ "documents",
105
+ "rejectionReason",
106
+ "adminComments",
107
+ "submittedAt",
108
+ "approvedAt",
109
+ "rejectedAt",
110
+ "type",
111
+ "description",
112
+ "server",
113
+ "port",
114
+ "password",
115
+ "systemEmail",
116
+ "inactivatedAt",
117
+ "permissions",
118
+ "staffUsers",
119
+ "price",
120
+ "customers",
121
+ "members",
122
+ "users",
123
+ "roles",
124
+ "plans",
125
+ "policies",
126
+ "kycConfig",
127
+ "smtpConfig",
128
+ "ownerId",
129
+ "text",
130
+ "ticketId",
131
+ "senderAccountId",
132
+ "senderAccount",
133
+ "ticket",
134
+ "applicantAccountId",
135
+ "applicantAccount",
136
+ "messages",
137
+ ] as const;
138
+ export type FieldName = (typeof FIELD_NAMES)[number];
package/dist/file.js ADDED
@@ -0,0 +1,27 @@
1
+ import { promises as fs } from "node:fs";
2
+ import * as path from "node:path";
3
+ import * as prettier from "prettier";
4
+ import { config } from "./utils/loader.js";
5
+ const ROOT = process.cwd();
6
+ const OUT_DIR = path.join(ROOT, config.outputPath);
7
+ export class DocGenFile {
8
+ outDir;
9
+ data;
10
+ constructor(params) {
11
+ const { fileName, dir, data, customDir } = params;
12
+ this.outDir = path.join(OUT_DIR, dir, fileName);
13
+ this.data = data;
14
+ if (customDir)
15
+ this.outDir = customDir;
16
+ }
17
+ async save() {
18
+ const dir = path.dirname(this.outDir);
19
+ await fs.mkdir(dir, { recursive: true });
20
+ const prettierConfig = await prettier.resolveConfig(this.outDir);
21
+ const formatted = await prettier.format(this.data, {
22
+ ...prettierConfig,
23
+ filepath: this.outDir,
24
+ });
25
+ await fs.writeFile(this.outDir, formatted, "utf-8");
26
+ }
27
+ }
@@ -0,0 +1,13 @@
1
+ import { ApiProperty } from "@nestjs/swagger";
2
+ import { IsString, IsNotEmpty } from "src/_nest/validators";
3
+
4
+ export class DefaultIdDto {
5
+ @ApiProperty({
6
+ type: "string",
7
+ example: "cmfxu4njg000008l52v7t8qze",
8
+ required: true,
9
+ })
10
+ @IsString()
11
+ @IsNotEmpty()
12
+ id!: string;
13
+ }
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { DocGenRules } from "./rules.js";
package/dist/index.ts ADDED
@@ -0,0 +1,40 @@
1
+ export * from "./types/account";
2
+ export * from "./types/admin";
3
+ export * from "./types/account-agenda";
4
+ export * from "./types/agenda-week-day-config";
5
+ export * from "./types/agenda-day-time-config";
6
+ export * from "./types/customer";
7
+ export * from "./types/notification";
8
+ export * from "./types/knowledge-base-category";
9
+ export * from "./types/knowledge-base-post";
10
+ export * from "./types/kyc-attempt-details";
11
+ export * from "./types/meeting";
12
+ export * from "./types/meeting-guest";
13
+ export * from "./types/member";
14
+ export * from "./types/otp-auth-code";
15
+ export * from "./types/otp-auth-code-request-log";
16
+ export * from "./types/owner";
17
+ export * from "./types/push-notification";
18
+ export * from "./types/email-auth-code";
19
+ export * from "./types/account-two-factor-auth";
20
+ export * from "./types/account-two-factor-auth-log";
21
+ export * from "./types/file";
22
+ export * from "./types/dummy";
23
+ export * from "./types/dummy-many";
24
+ export * from "./types/dummy-unique";
25
+ export * from "./types/firebase-config";
26
+ export * from "./types/kyc-config";
27
+ export * from "./types/kyc-attempt";
28
+ export * from "./types/kyc-document";
29
+ export * from "./types/policy";
30
+ export * from "./types/smtp-config";
31
+ export * from "./types/user";
32
+ export * from "./types/staff-role";
33
+ export * from "./types/staff";
34
+ export * from "./types/tenant-plan";
35
+ export * from "./types/tenant-role";
36
+ export * from "./types/tenant";
37
+ export * from "./types/ticket-message";
38
+ export * from "./types/ticket";
39
+ export { FieldName } from "./fields";
40
+ export * as DG from "../dist/index";