prismadoc 1.0.35 → 1.0.37
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 +1 -1
- package/dist/entities/field.js +5 -2
- package/dist/main.js +0 -42
- package/dist/rules.js +0 -2
- package/package.json +1 -1
|
@@ -4,12 +4,12 @@ import { DocGenField } from "./field.js";
|
|
|
4
4
|
import { config } from "../utils/loader.js";
|
|
5
5
|
export class DocGenDto {
|
|
6
6
|
name;
|
|
7
|
-
// file: DocGenFile;
|
|
8
7
|
fields = [];
|
|
9
8
|
imports = new Set([
|
|
10
9
|
`${Static.AUTO_GENERATED_COMMENT}`,
|
|
11
10
|
"/* eslint-disable @typescript-eslint/no-namespace */",
|
|
12
11
|
`import { ApiProperty, IntersectionType } from '@nestjs/swagger'`,
|
|
12
|
+
`import { Expose } from 'class-transformer'`,
|
|
13
13
|
]);
|
|
14
14
|
classValidators = new Set();
|
|
15
15
|
enums = new Set();
|
package/dist/entities/field.js
CHANGED
|
@@ -40,7 +40,10 @@ export class DocGenField {
|
|
|
40
40
|
this.validators.add(validator);
|
|
41
41
|
}
|
|
42
42
|
setValidators() {
|
|
43
|
-
if (this.scalarType === "
|
|
43
|
+
if (this.scalarType === "DateTime") {
|
|
44
|
+
this.processValidator({ name: "IsDateString" });
|
|
45
|
+
}
|
|
46
|
+
else if (this.scalarType === "String" || this.scalarType === "Json") {
|
|
44
47
|
this.processValidator({ name: "IsString" });
|
|
45
48
|
if (this.isRequired) {
|
|
46
49
|
this.processValidator({ name: "IsNotEmpty" });
|
|
@@ -186,7 +189,7 @@ export class DocGenField {
|
|
|
186
189
|
return [apiProperty, ...validators, atributes].join("\n");
|
|
187
190
|
}
|
|
188
191
|
else {
|
|
189
|
-
return [apiProperty, atributes].join("\n");
|
|
192
|
+
return [apiProperty, "@Expose()", atributes].join("\n");
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
195
|
}
|
package/dist/main.js
CHANGED
|
@@ -15,17 +15,14 @@ const PRISMA_DIR = path.join(ROOT, config.prismaPath);
|
|
|
15
15
|
export class DocGen {
|
|
16
16
|
datamodel;
|
|
17
17
|
properties;
|
|
18
|
-
// enums!: DocEnums;
|
|
19
18
|
fields;
|
|
20
19
|
models;
|
|
21
20
|
generic = new DocGenGeneric();
|
|
22
21
|
indexFile;
|
|
23
|
-
// fieldFile!: DocGenFile;
|
|
24
22
|
externalIndexExports = [];
|
|
25
23
|
async init() {
|
|
26
24
|
const prismaDataModel = await PrismaUtils.readPrismaFolderDatamodel(PRISMA_DIR);
|
|
27
25
|
const { datamodel } = await getDMMF({ datamodel: prismaDataModel });
|
|
28
|
-
console.log("starting2");
|
|
29
26
|
// Busca e processa schemas externos (precisa do schema principal para resolver tipos)
|
|
30
27
|
const externalSchemas = await PrismaUtils.fetchExternalSchemas(config.externalPrismaSchemas);
|
|
31
28
|
const mainModelNames = new Set(datamodel.models.map((m) => m.name));
|
|
@@ -123,17 +120,9 @@ export class DocGen {
|
|
|
123
120
|
this.fields.file.save();
|
|
124
121
|
const indexFileData = [];
|
|
125
122
|
const fields = [];
|
|
126
|
-
// const enumsSet = new Set<string>();
|
|
127
|
-
// const classValidatorsSet = new Set<string>();
|
|
128
123
|
for (const model of this.models) {
|
|
129
124
|
indexFileData.push(...model.exports);
|
|
130
125
|
fields.push(...model.dto.fields);
|
|
131
|
-
// for (const e of model.dto.enums) {
|
|
132
|
-
// enumsSet.add(e);
|
|
133
|
-
// }
|
|
134
|
-
// for (const classValidator of model.dto.classValidators) {
|
|
135
|
-
// classValidatorsSet.add(classValidator);
|
|
136
|
-
// }
|
|
137
126
|
model.save();
|
|
138
127
|
}
|
|
139
128
|
indexFileData.push(...this.externalIndexExports);
|
|
@@ -144,43 +133,12 @@ export class DocGen {
|
|
|
144
133
|
continue;
|
|
145
134
|
fieldMap.set(field.name, field);
|
|
146
135
|
}
|
|
147
|
-
// const imports = new Set([`import { ApiProperty } from '@nestjs/swagger'`]);
|
|
148
|
-
// const validators = `import { ${Array.from(classValidatorsSet)} } from 'src/_nest/validators';`;
|
|
149
|
-
// const exportTypes: string[] = [];
|
|
150
|
-
// const fieldClasses = Array.from(fieldMap)
|
|
151
|
-
// .map(([_, field]) => {
|
|
152
|
-
// field.isRequired = true;
|
|
153
|
-
// const name = Helper.capitalizeFirstSafe(field.name);
|
|
154
|
-
// exportTypes.push(`
|
|
155
|
-
// export const ${name} = ${name}Dto
|
|
156
|
-
// `);
|
|
157
|
-
// return `
|
|
158
|
-
// class ${name}Dto {
|
|
159
|
-
// ${field.build()}
|
|
160
|
-
// }
|
|
161
|
-
// `;
|
|
162
|
-
// })
|
|
163
|
-
// .join("\n");
|
|
164
|
-
// imports.add(`import { ${Array.from(enumsSet)} } from '@prisma/client';`);
|
|
165
|
-
// imports.add(validators);
|
|
166
|
-
// const teste = `
|
|
167
|
-
// export namespace Input {
|
|
168
|
-
// ${exportTypes.join(";")}
|
|
169
|
-
// }
|
|
170
|
-
// `;
|
|
171
|
-
// const fieldFileContent = [Array.from(imports).join("\n"), fieldClasses, teste];
|
|
172
|
-
// this.fieldFile = new DocGenFile({
|
|
173
|
-
// fileName: "fields.types.ts",
|
|
174
|
-
// dir: "",
|
|
175
|
-
// data: fieldFileContent.join("\n"),
|
|
176
|
-
// });
|
|
177
136
|
this.indexFile = new DocGenFile({
|
|
178
137
|
fileName: "index.ts",
|
|
179
138
|
dir: "",
|
|
180
139
|
data: indexFileData.join("\n"),
|
|
181
140
|
});
|
|
182
141
|
this.indexFile.save();
|
|
183
|
-
// this.fieldFile.save();
|
|
184
142
|
}
|
|
185
143
|
}
|
|
186
144
|
const generator = new DocGen();
|
package/dist/rules.js
CHANGED