prismadoc 1.0.32 → 1.0.33
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/dist/entities/dto-generator.js +11 -2
- package/dist/entities/model.js +2 -2
- package/dist/main.js +8 -3
- package/package.json +1 -1
|
@@ -14,9 +14,11 @@ export class DocGenDto {
|
|
|
14
14
|
classValidators = new Set();
|
|
15
15
|
enums = new Set();
|
|
16
16
|
enumImportPath;
|
|
17
|
-
|
|
17
|
+
mainEnumNames;
|
|
18
|
+
constructor(model, enumImportPath, mainEnumNames) {
|
|
18
19
|
this.name = model.name;
|
|
19
20
|
this.enumImportPath = enumImportPath ?? "@prisma/client";
|
|
21
|
+
this.mainEnumNames = mainEnumNames ?? new Set();
|
|
20
22
|
this.classValidators.add("IsString");
|
|
21
23
|
this.classValidators.add("IsNotEmpty");
|
|
22
24
|
for (const field of model.fields) {
|
|
@@ -45,7 +47,14 @@ export class DocGenDto {
|
|
|
45
47
|
.join("\n\n");
|
|
46
48
|
if (this.enums.size > 0) {
|
|
47
49
|
this.classValidators.add("IsEnum");
|
|
48
|
-
|
|
50
|
+
const localEnums = Array.from(this.enums).filter((e) => !this.mainEnumNames.has(e));
|
|
51
|
+
const prismaEnums = Array.from(this.enums).filter((e) => this.mainEnumNames.has(e));
|
|
52
|
+
if (localEnums.length > 0) {
|
|
53
|
+
this.imports.add(`import { ${localEnums.join(", ")} } from '${this.enumImportPath}';`);
|
|
54
|
+
}
|
|
55
|
+
if (prismaEnums.length > 0) {
|
|
56
|
+
this.imports.add(`import { ${prismaEnums.join(", ")} } from '@prisma/client';`);
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
this.imports.add(`import { ${Array.from(this.classValidators)} } from '${config.validatorPath}';`);
|
|
51
60
|
const intersections = this.fields.map((field) => Helper.capitalizeFirstSafe(field.name) + "Dto");
|
package/dist/entities/model.js
CHANGED
|
@@ -10,13 +10,13 @@ export class DocGenModel {
|
|
|
10
10
|
exports;
|
|
11
11
|
file;
|
|
12
12
|
servicePrefix;
|
|
13
|
-
constructor(model, servicePrefix) {
|
|
13
|
+
constructor(model, servicePrefix, mainEnumNames) {
|
|
14
14
|
this.name = model.name;
|
|
15
15
|
this.fields = model.fields;
|
|
16
16
|
this.servicePrefix = servicePrefix;
|
|
17
17
|
const enumImportPath = servicePrefix ? "../enums" : undefined;
|
|
18
18
|
this.response = new DocGenResponse(model);
|
|
19
|
-
this.dto = new DocGenDto(model, enumImportPath);
|
|
19
|
+
this.dto = new DocGenDto(model, enumImportPath, mainEnumNames);
|
|
20
20
|
const kebabName = Helper.toKebab(this.name);
|
|
21
21
|
const fileName = servicePrefix ? `${servicePrefix}.${kebabName}` : kebabName;
|
|
22
22
|
this.exports = [`export * from './types/${fileName}'`];
|
package/dist/main.js
CHANGED
|
@@ -68,10 +68,15 @@ export class DocGen {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
async processExternalSchema(name, prismaSchema, mainPrismaDataModel, mainModelNames, mainEnumNames) {
|
|
71
|
-
// Remove blocos datasource/generator do schema externo
|
|
72
|
-
const
|
|
71
|
+
// Remove blocos datasource/generator e definições duplicadas do schema externo
|
|
72
|
+
const allMainNames = new Set([...mainModelNames, ...mainEnumNames]);
|
|
73
|
+
let cleanedExternal = prismaSchema
|
|
73
74
|
.replaceAll(/datasource\s+\w+\s*\{[^}]*\}/g, "")
|
|
74
75
|
.replaceAll(/generator\s+\w+\s*\{[^}]*\}/g, "");
|
|
76
|
+
// Remove models/enums que já existem no schema principal
|
|
77
|
+
for (const typeName of allMainNames) {
|
|
78
|
+
cleanedExternal = cleanedExternal.replaceAll(new RegExp(`(?:model|enum)\\s+${typeName}\\s*\\{[^}]*\\}`, "g"), "");
|
|
79
|
+
}
|
|
75
80
|
// Combina com o schema principal para que o Prisma resolva todos os tipos
|
|
76
81
|
const combined = mainPrismaDataModel + "\n" + cleanedExternal;
|
|
77
82
|
const { datamodel } = await this.getDMMFSafe(combined);
|
|
@@ -97,7 +102,7 @@ export class DocGen {
|
|
|
97
102
|
enumFile.save();
|
|
98
103
|
}
|
|
99
104
|
for (const model of externalModels) {
|
|
100
|
-
const docModel = new DocGenModel(model, servicePrefix);
|
|
105
|
+
const docModel = new DocGenModel(model, servicePrefix, mainEnumNames);
|
|
101
106
|
serviceIndexExports.push(...docModel.exports);
|
|
102
107
|
docModel.save();
|
|
103
108
|
}
|