nest-prisma_doc-gen 1.0.3 → 1.0.4
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/config.type.js +16 -0
- package/dist/entities/dto-generator.js +7 -5
- package/dist/entities/entity-generator.js +4 -4
- package/dist/entities/field.js +5 -6
- package/dist/index.js +0 -1
- package/dist/main.js +8 -6
- package/dist/rules.js +1 -1
- package/dist/schemas/config.schema.json +79 -0
- package/dist/static.js +0 -22
- package/dist/testes.js +21 -0
- package/dist/types.js +1 -17
- package/dist/utils/config-loader.js +33 -0
- package/dist/utils/copy-schemas.js +10 -0
- package/dist/utils/loader.js +47 -0
- package/package.json +12 -8
- package/dist/entities/dto-generator.d.ts +0 -13
- package/dist/entities/entity-generator.d.ts +0 -12
- package/dist/entities/enum.d.ts +0 -22
- package/dist/entities/field.d.ts +0 -24
- package/dist/entities/model.d.ts +0 -11
- package/dist/field.type.d.ts +0 -7
- package/dist/file.d.ts +0 -11
- package/dist/helpers/helpers.d.ts +0 -14
- package/dist/helpers/loader.d.ts +0 -4
- package/dist/helpers/loader.js +0 -50
- package/dist/helpers/propeties.static.d.ts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/main.d.ts +0 -13
- package/dist/rules.d.ts +0 -11
- package/dist/static.d.ts +0 -6
- package/dist/types.d.ts +0 -79
- package/src/entities/dto-generator.ts +0 -61
- package/src/entities/entity-generator.ts +0 -55
- package/src/entities/enum.ts +0 -47
- package/src/entities/field.ts +0 -190
- package/src/entities/model.ts +0 -23
- package/src/entities/validator.ts +0 -17
- package/src/field.type.ts +0 -27
- package/src/file.ts +0 -34
- package/src/helpers/helpers.ts +0 -152
- package/src/helpers/loader.ts +0 -60
- package/src/helpers/propeties.static.ts +0 -3
- package/src/index.ts +0 -2
- package/src/main.ts +0 -68
- package/src/rules.ts +0 -31
- package/src/static.ts +0 -28
- package/src/types/global.d.ts +0 -1
- package/src/types.ts +0 -109
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -15
- /package/dist/{helpers → utils}/helpers.js +0 -0
- /package/dist/{helpers → utils}/propeties.static.js +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class ValidatorBuilder {
|
|
2
|
+
decorator;
|
|
3
|
+
fields;
|
|
4
|
+
constructor(decorator, fields) {
|
|
5
|
+
this.decorator = decorator;
|
|
6
|
+
this.fields = fields;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class ApiExampleBuilder {
|
|
10
|
+
fields;
|
|
11
|
+
example;
|
|
12
|
+
constructor(fields, example) {
|
|
13
|
+
this.fields = fields;
|
|
14
|
+
this.example = example;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocGenFile } from "../file.js";
|
|
2
|
-
import { Helper } from "../
|
|
2
|
+
import { Helper } from "../utils/helpers.js";
|
|
3
3
|
import { Static } from "../static.js";
|
|
4
4
|
import { DocGenField } from "./field.js";
|
|
5
5
|
export class DocGenDto {
|
|
@@ -11,11 +11,11 @@ export class DocGenDto {
|
|
|
11
11
|
enums = new Set();
|
|
12
12
|
constructor(model) {
|
|
13
13
|
this.name = model.name;
|
|
14
|
-
model.fields
|
|
14
|
+
for (const field of model.fields) {
|
|
15
15
|
if (field.isUpdatedAt || field.isId || field.name === "createdAt" || field.kind === "object")
|
|
16
|
-
|
|
16
|
+
continue;
|
|
17
17
|
this.fields.push(new DocGenField(field, "dto"));
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
this.file = new DocGenFile({
|
|
20
20
|
dir: "/dto",
|
|
21
21
|
fileName: `${Helper.toKebab(this.name)}.dto.ts`,
|
|
@@ -25,7 +25,9 @@ export class DocGenDto {
|
|
|
25
25
|
build() {
|
|
26
26
|
const sanitizedFields = this.fields
|
|
27
27
|
.map((field) => {
|
|
28
|
-
field.validators
|
|
28
|
+
for (const { name } of field.validators) {
|
|
29
|
+
this.classValidators.add(name);
|
|
30
|
+
}
|
|
29
31
|
if (field.isEntity) {
|
|
30
32
|
this.imports.add(`import { ${field.type} } from '../entities/${Helper.toKebab(field.scalarType)}.entity'`);
|
|
31
33
|
this.imports.add(`import { generateExample } from 'src/utils/functions/reflect'`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocGenFile } from "../file.js";
|
|
2
|
-
import { Helper } from "../
|
|
2
|
+
import { Helper } from "../utils/helpers.js";
|
|
3
3
|
import { Static } from "../static.js";
|
|
4
4
|
import { DocGenField } from "./field.js";
|
|
5
5
|
export class DocGenEntity {
|
|
@@ -10,11 +10,11 @@ export class DocGenEntity {
|
|
|
10
10
|
enums = new Set();
|
|
11
11
|
constructor(model) {
|
|
12
12
|
this.name = model.name;
|
|
13
|
-
model.fields
|
|
13
|
+
for (const field of model.fields) {
|
|
14
14
|
if (field.kind === "object")
|
|
15
|
-
|
|
15
|
+
continue;
|
|
16
16
|
this.fields.push(new DocGenField(field, "entity"));
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
this.file = new DocGenFile({
|
|
19
19
|
dir: "/entity",
|
|
20
20
|
fileName: `${Helper.toKebab(this.name)}.entity.ts`,
|
package/dist/entities/field.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Helper } from "../
|
|
2
|
-
import { config } from "../
|
|
3
|
-
import { Static } from "../static.js";
|
|
1
|
+
import { Helper } from "../utils/helpers.js";
|
|
2
|
+
import { config } from "../utils/loader.js";
|
|
4
3
|
import { Validator } from "./validator.js";
|
|
5
4
|
const helpers = new Helper();
|
|
6
5
|
const rules = config;
|
|
@@ -67,9 +66,9 @@ export class DocGenField {
|
|
|
67
66
|
}
|
|
68
67
|
const findedDecorators = rules.validators.get(this.name);
|
|
69
68
|
if (findedDecorators) {
|
|
70
|
-
|
|
69
|
+
for (const name of findedDecorators) {
|
|
71
70
|
this.processValidator(name);
|
|
72
|
-
}
|
|
71
|
+
}
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
setType() {
|
|
@@ -113,7 +112,7 @@ export class DocGenField {
|
|
|
113
112
|
props.push(`example: ${this.scalarField.type}[0]`);
|
|
114
113
|
}
|
|
115
114
|
else if (this.scalarField.type === "Int") {
|
|
116
|
-
props.push(`example:
|
|
115
|
+
props.push(`example: 777`);
|
|
117
116
|
}
|
|
118
117
|
else if (this.scalarField.type === "String") {
|
|
119
118
|
props.push(`example: 'ordinary string'`);
|
package/dist/index.js
CHANGED
package/dist/main.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from "node:path";
|
|
|
3
3
|
import { DocEnums, DocGenEnum } from "./entities/enum.js";
|
|
4
4
|
import { DocGenModel } from "./entities/model.js";
|
|
5
5
|
import { DocFields } from "./field.type.js";
|
|
6
|
-
import { Helper } from "./
|
|
6
|
+
import { Helper } from "./utils/helpers.js";
|
|
7
7
|
import prismaPkg from "@prisma/internals";
|
|
8
8
|
const { getDMMF } = prismaPkg;
|
|
9
9
|
const ROOT = process.cwd();
|
|
@@ -25,9 +25,11 @@ export class DocGen {
|
|
|
25
25
|
});
|
|
26
26
|
}));
|
|
27
27
|
const fieldSet = new Set();
|
|
28
|
-
datamodel.models
|
|
29
|
-
model.fields
|
|
30
|
-
|
|
28
|
+
for (const model of datamodel.models) {
|
|
29
|
+
for (const field of model.fields) {
|
|
30
|
+
fieldSet.add(`'${field.name}'`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
31
33
|
this.fields = new DocFields(Array.from(fieldSet).toString());
|
|
32
34
|
this.models = datamodel.models.map((model) => {
|
|
33
35
|
return new DocGenModel(model);
|
|
@@ -37,9 +39,9 @@ export class DocGen {
|
|
|
37
39
|
build() {
|
|
38
40
|
this.fields.file.save();
|
|
39
41
|
this.enums.file.save();
|
|
40
|
-
this.models
|
|
42
|
+
for (const model of this.models) {
|
|
41
43
|
model.save();
|
|
42
|
-
}
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
const generator = new DocGen();
|
package/dist/rules.js
CHANGED
|
@@ -13,7 +13,7 @@ export class DocGenRules {
|
|
|
13
13
|
this.examples = new Map(examples.flatMap((builder) => builder.fields.map((field) => [field, builder])));
|
|
14
14
|
this.validators = new Map(uniqueFieldsToValidate.map((field) => [
|
|
15
15
|
field,
|
|
16
|
-
validators.filter((validator) => validator.fields.includes(field)).map((validator) => validator.decorator
|
|
16
|
+
validators.filter((validator) => validator.fields.includes(field)).map((validator) => validator.decorator),
|
|
17
17
|
]));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$ref": "#/definitions/Rules",
|
|
4
|
+
"definitions": {
|
|
5
|
+
"ApiExampleBuilder": {
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"type": "object",
|
|
8
|
+
"description": "Define um exemplo usado para popular campos de DTO durante a geração automática.",
|
|
9
|
+
"properties": {
|
|
10
|
+
"example": {
|
|
11
|
+
"type": ["string", "boolean", "number"],
|
|
12
|
+
"description": "Valor de exemplo a ser usado para os campos especificados."
|
|
13
|
+
},
|
|
14
|
+
"fields": {
|
|
15
|
+
"type": "array",
|
|
16
|
+
"items": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
"description": "Lista de nomes de campos onde o exemplo será aplicado."
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"required": ["fields", "example"]
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
"ValidatorBuilder": {
|
|
26
|
+
"additionalProperties": false,
|
|
27
|
+
"type": "object",
|
|
28
|
+
"description": "Define um validador a ser aplicado a determinados campos.",
|
|
29
|
+
"properties": {
|
|
30
|
+
"decorator": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "Nome do decorator de validação (ex: IsEmail, IsStrongPassword)."
|
|
33
|
+
},
|
|
34
|
+
"fields": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": {
|
|
37
|
+
"type": "string"
|
|
38
|
+
},
|
|
39
|
+
"description": "Campos que recebem este validador."
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"required": ["decorator", "fields"]
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
"Rules": {
|
|
46
|
+
"additionalProperties": false,
|
|
47
|
+
"type": "object",
|
|
48
|
+
"description": "Configuração principal do DocGen.",
|
|
49
|
+
"properties": {
|
|
50
|
+
"$schema": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"description": "Caminho para o schema de validação (usado pelo editor para autocomplete)."
|
|
53
|
+
},
|
|
54
|
+
"ignore": {
|
|
55
|
+
"type": "array",
|
|
56
|
+
"items": {
|
|
57
|
+
"type": "string"
|
|
58
|
+
},
|
|
59
|
+
"description": "Campos a serem ignorados durante a geração automática de DTOs."
|
|
60
|
+
},
|
|
61
|
+
"examples": {
|
|
62
|
+
"type": "array",
|
|
63
|
+
"items": {
|
|
64
|
+
"$ref": "#/definitions/ApiExampleBuilder"
|
|
65
|
+
},
|
|
66
|
+
"description": "Lista de exemplos a serem aplicados a campos específicos."
|
|
67
|
+
},
|
|
68
|
+
"validators": {
|
|
69
|
+
"type": "array",
|
|
70
|
+
"items": {
|
|
71
|
+
"$ref": "#/definitions/ValidatorBuilder"
|
|
72
|
+
},
|
|
73
|
+
"description": "Lista de validadores associados a campos específicos."
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": ["ignore", "examples", "validators"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
package/dist/static.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
1
|
export class Static {
|
|
2
2
|
static AUTO_GENERATED_COMMENT = "// AUTO-GERADO: NÃO EDITAR MANUALMENTE. SUJEITO A PAULADAS!";
|
|
3
|
-
static STATIC_NAMES = [
|
|
4
|
-
"Alessandro",
|
|
5
|
-
"Pablo",
|
|
6
|
-
"Cláudio",
|
|
7
|
-
"Thiago",
|
|
8
|
-
"Guilherme",
|
|
9
|
-
"Dalton",
|
|
10
|
-
"Kaio",
|
|
11
|
-
"Gustavo",
|
|
12
|
-
"Cadu",
|
|
13
|
-
"Neyanne",
|
|
14
|
-
"John",
|
|
15
|
-
"Matheus",
|
|
16
|
-
"Davi",
|
|
17
|
-
];
|
|
18
|
-
static getRandomString(values) {
|
|
19
|
-
const idx = Math.floor(Math.random() * values.length);
|
|
20
|
-
return values[idx];
|
|
21
|
-
}
|
|
22
|
-
static getRandomNumber(min = 0, max = 1000) {
|
|
23
|
-
return Math.floor(Math.random() * (max - min)) + min;
|
|
24
|
-
}
|
|
25
3
|
}
|
package/dist/testes.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// import { Ajv } from "ajv";
|
|
2
|
+
// import schema from "./schemas/config.schema.json" with { type: "json" };
|
|
3
|
+
export {};
|
|
4
|
+
// const ajv = new Ajv();
|
|
5
|
+
// const validate = ajv.compile(schema);
|
|
6
|
+
// const data = {
|
|
7
|
+
// ignore: ["senha", "id"],
|
|
8
|
+
// examples: [
|
|
9
|
+
// { fields: ["name"], example: "João" },
|
|
10
|
+
// { fields: ["idade"], example: 30 },
|
|
11
|
+
// ],
|
|
12
|
+
// validators: [
|
|
13
|
+
// { decorator: "IsString", fields: ["name"] },
|
|
14
|
+
// { decorator: "IsInt", fields: ["idade"] },
|
|
15
|
+
// ],
|
|
16
|
+
// };
|
|
17
|
+
// if (validate(data)) {
|
|
18
|
+
// console.log("✅ JSON válido!");
|
|
19
|
+
// } else {
|
|
20
|
+
// console.error("❌ Erros:", validate.errors);
|
|
21
|
+
// }
|
package/dist/types.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
decorator;
|
|
3
|
-
fields;
|
|
4
|
-
constructor(decorator, fields) {
|
|
5
|
-
this.decorator = decorator;
|
|
6
|
-
this.fields = fields;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class ApiExampleBuilder {
|
|
10
|
-
fields;
|
|
11
|
-
example;
|
|
12
|
-
constructor(fields, example) {
|
|
13
|
-
this.fields = fields;
|
|
14
|
-
this.example = example;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
// field: Field, fieldType: FieldType
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// import * as fs from "node:fs/promises";
|
|
2
|
+
// import * as path from "node:path";
|
|
3
|
+
// import { fileURLToPath } from "node:url";
|
|
4
|
+
// import Ajv from "ajv";
|
|
5
|
+
// import addFormats from "ajv-formats";
|
|
6
|
+
// import { DocGenRules } from "nest-prisma_doc-gen";
|
|
7
|
+
export {};
|
|
8
|
+
// // Caminho absoluto do diretório da lib (onde este arquivo está)
|
|
9
|
+
// const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
// const __dirname = path.dirname(__filename);
|
|
11
|
+
// // Caminho para o schema dentro da lib
|
|
12
|
+
// const SCHEMA_PATH = path.join(__dirname, "../schemas/config.schema.json");
|
|
13
|
+
// // Caminho para o config do projeto (que será validado)
|
|
14
|
+
// const CONFIG_PATH = path.join(process.cwd(), "doc-gen.config.json");
|
|
15
|
+
// async function readJson(filePath: string) {
|
|
16
|
+
// const content = await fs.readFile(filePath, "utf8");
|
|
17
|
+
// return JSON.parse(content);
|
|
18
|
+
// }
|
|
19
|
+
// export async function loadDocGenConfig() {
|
|
20
|
+
// // Lê os dois arquivos
|
|
21
|
+
// const [schema, config] = (await Promise.all([readJson(SCHEMA_PATH), readJson(CONFIG_PATH)])) as [any, DocGenRules];
|
|
22
|
+
// // Configura o validador
|
|
23
|
+
// const ajv = new Ajv.Ajv({ allErrors: true, strict: false });
|
|
24
|
+
// addFormats.default(ajv);
|
|
25
|
+
// const validate = ajv.compile(schema);
|
|
26
|
+
// const valid = validate(config);
|
|
27
|
+
// if (!valid) {
|
|
28
|
+
// const errors = (validate.errors ?? []).map((e) => `${e.instancePath || "(root)"} ${e.message}`).join("\n - ");
|
|
29
|
+
// throw new Error(`❌ Config inválida em ${path.basename(CONFIG_PATH)}:\n - ${errors}`);
|
|
30
|
+
// }
|
|
31
|
+
// console.log("✅ Configuração válida!");
|
|
32
|
+
// return { config, path: CONFIG_PATH };
|
|
33
|
+
// }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
const src = path.join(__dirname, "../schemas/config.schema.json");
|
|
7
|
+
const destDir = path.join(__dirname, "../dist/schemas");
|
|
8
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
9
|
+
fs.copyFileSync(src, path.join(destDir, "config.schema.json"));
|
|
10
|
+
console.log("✅ Copiado config.schema.json para dist/schemas/");
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { DocGenRules } from "../rules.js";
|
|
5
|
+
import Ajv from "ajv";
|
|
6
|
+
import addFormats from "ajv-formats";
|
|
7
|
+
// Caminho absoluto do diretório da lib (onde este arquivo está)
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
// Caminho para o schema dentro da lib
|
|
11
|
+
const SCHEMA_PATH = path.join(__dirname, "../schemas/config.schema.json");
|
|
12
|
+
const CONFIG_PATH = path.join(process.cwd(), "doc-gen.config.json");
|
|
13
|
+
export class DocGenConfig {
|
|
14
|
+
ignore;
|
|
15
|
+
examples;
|
|
16
|
+
validators;
|
|
17
|
+
constructor(configs) {
|
|
18
|
+
const { examples, ignore, validators } = configs;
|
|
19
|
+
this.ignore = ignore;
|
|
20
|
+
this.examples = examples;
|
|
21
|
+
this.validators = validators;
|
|
22
|
+
}
|
|
23
|
+
static async readJson(filePath) {
|
|
24
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
25
|
+
return JSON.parse(content);
|
|
26
|
+
}
|
|
27
|
+
static async load() {
|
|
28
|
+
// Lê os dois arquivos
|
|
29
|
+
const [schema, config] = (await Promise.all([this.readJson(SCHEMA_PATH), this.readJson(CONFIG_PATH)]));
|
|
30
|
+
// Configura o validador
|
|
31
|
+
const ajv = new Ajv.Ajv({ allErrors: true, strict: false });
|
|
32
|
+
addFormats.default(ajv);
|
|
33
|
+
const validate = ajv.compile(schema);
|
|
34
|
+
const valid = validate(config);
|
|
35
|
+
if (!valid) {
|
|
36
|
+
const errors = (validate.errors ?? []).map((e) => `${e.instancePath || "(root)"} ${e.message}`).join("\n - ");
|
|
37
|
+
throw new Error(`❌ Config inválida em ${path.basename(CONFIG_PATH)}:\n - ${errors}`);
|
|
38
|
+
}
|
|
39
|
+
console.log("✅ Configuração válida!");
|
|
40
|
+
return DocGenConfig.newWithConfigs(config);
|
|
41
|
+
}
|
|
42
|
+
/** Cria uma instância a partir de configurações */
|
|
43
|
+
static newWithConfigs(params) {
|
|
44
|
+
return new DocGenConfig(new DocGenRules(params));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export const config = await DocGenConfig.load();
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-prisma_doc-gen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Auto generates ApiProperties from schema.prisma",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"
|
|
9
|
+
"build": "tsc && npm run copy-schemas",
|
|
10
|
+
"copy-schemas": "node scripts/copy-schemas.js"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -28,15 +28,19 @@
|
|
|
28
28
|
"author": "Alessandro Lepore",
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@esbuild/win32-x64": "^0.25.11",
|
|
31
32
|
"@prisma/internals": "^6.17.1",
|
|
32
|
-
"
|
|
33
|
+
"ajv": "^8.17.1",
|
|
34
|
+
"ajv-formats": "^3.0.1",
|
|
33
35
|
"prettier": "^3.6.2",
|
|
34
|
-
"ts-node": "^10.9.2"
|
|
35
|
-
"tsx": "^4.19.1"
|
|
36
|
+
"ts-node": "^10.9.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/node": "^24.7.2",
|
|
39
|
-
"tsx": "^4.20.6",
|
|
40
40
|
"typescript": "^5.6.3"
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"src/schemas/config.schema.json"
|
|
45
|
+
]
|
|
42
46
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DocGenFile } from "../file.js";
|
|
2
|
-
import { Model } from "../types.js";
|
|
3
|
-
import { DocGenField } from "./field.js";
|
|
4
|
-
export declare class DocGenDto {
|
|
5
|
-
name: string;
|
|
6
|
-
file: DocGenFile;
|
|
7
|
-
fields: DocGenField[];
|
|
8
|
-
imports: Set<string>;
|
|
9
|
-
classValidators: Set<string>;
|
|
10
|
-
enums: Set<string>;
|
|
11
|
-
constructor(model: Model);
|
|
12
|
-
build(): string;
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DocGenFile } from "../file.js";
|
|
2
|
-
import { Model } from "../types.js";
|
|
3
|
-
import { DocGenField } from "./field.js";
|
|
4
|
-
export declare class DocGenEntity {
|
|
5
|
-
name: string;
|
|
6
|
-
file: DocGenFile;
|
|
7
|
-
fields: DocGenField[];
|
|
8
|
-
imports: Set<string>;
|
|
9
|
-
enums: Set<string>;
|
|
10
|
-
constructor(model: Model);
|
|
11
|
-
build(): string;
|
|
12
|
-
}
|
package/dist/entities/enum.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DocGenFile } from "../file.js";
|
|
2
|
-
import { DbName } from "../types.js";
|
|
3
|
-
export type EnumValue = {
|
|
4
|
-
name: string;
|
|
5
|
-
dbName: DbName;
|
|
6
|
-
};
|
|
7
|
-
export declare class DocGenEnum {
|
|
8
|
-
name: string;
|
|
9
|
-
values: EnumValue[];
|
|
10
|
-
dbName: DbName;
|
|
11
|
-
constructor(params: {
|
|
12
|
-
name: string;
|
|
13
|
-
values: EnumValue[];
|
|
14
|
-
dbName: DbName;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
export declare class DocEnums {
|
|
18
|
-
enums: DocGenEnum[];
|
|
19
|
-
file: DocGenFile;
|
|
20
|
-
constructor(enums: DocGenEnum[]);
|
|
21
|
-
build(): string;
|
|
22
|
-
}
|
package/dist/entities/field.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { FieldDefault, Scalar, FieldKind, FieldType, Field } from "../types.js";
|
|
2
|
-
export declare class DocGenField {
|
|
3
|
-
name: string;
|
|
4
|
-
isList: boolean;
|
|
5
|
-
default?: FieldDefault | string;
|
|
6
|
-
scalarType: Scalar;
|
|
7
|
-
kind: FieldKind;
|
|
8
|
-
type: string;
|
|
9
|
-
fieldType: FieldType;
|
|
10
|
-
isEnum: boolean;
|
|
11
|
-
isEntity: boolean;
|
|
12
|
-
isUpdatedAt: boolean;
|
|
13
|
-
isRequired: boolean;
|
|
14
|
-
validators: Set<string>;
|
|
15
|
-
readonly scalarField: Field;
|
|
16
|
-
constructor(field: Field, fieldType: FieldType);
|
|
17
|
-
private init;
|
|
18
|
-
private setValidators;
|
|
19
|
-
private setType;
|
|
20
|
-
private buildApiExample;
|
|
21
|
-
private sanitizeValidators;
|
|
22
|
-
private buildInfos;
|
|
23
|
-
build(): string;
|
|
24
|
-
}
|
package/dist/entities/model.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Field, Model } from "../types.js";
|
|
2
|
-
import { DocGenDto } from "./dto-generator.js";
|
|
3
|
-
import { DocGenEntity } from "./entity-generator.js";
|
|
4
|
-
export declare class DocGenModel {
|
|
5
|
-
name: string;
|
|
6
|
-
entitie: DocGenEntity;
|
|
7
|
-
createDtos: DocGenDto;
|
|
8
|
-
fields: Field[];
|
|
9
|
-
constructor(model: Model);
|
|
10
|
-
save(): void;
|
|
11
|
-
}
|
package/dist/field.type.d.ts
DELETED
package/dist/file.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Scalar, Field, DocGenModel } from "../types.js";
|
|
2
|
-
export declare class Helper {
|
|
3
|
-
static prismaScalarToTs(s: Scalar): string;
|
|
4
|
-
static validatorForScalar(s: Scalar): string;
|
|
5
|
-
static swaggerType(field: Field): string | undefined;
|
|
6
|
-
static toKebab(s: string): string;
|
|
7
|
-
importsForModel(model: DocGenModel): {
|
|
8
|
-
enums: boolean;
|
|
9
|
-
hasDate: boolean;
|
|
10
|
-
};
|
|
11
|
-
static readPrismaFolderDatamodel(dir: string): Promise<string>;
|
|
12
|
-
findTypeForField(field: Field): string;
|
|
13
|
-
isDate(field: Field): boolean;
|
|
14
|
-
}
|
package/dist/helpers/loader.d.ts
DELETED
package/dist/helpers/loader.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import "tsx/esm";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
import * as fs from "node:fs";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import { DocGenRules } from "../rules.js";
|
|
6
|
-
export class DocGenConfig {
|
|
7
|
-
ignore;
|
|
8
|
-
examples;
|
|
9
|
-
validators;
|
|
10
|
-
constructor(configs) {
|
|
11
|
-
const { examples, ignore, validators } = configs;
|
|
12
|
-
this.ignore = ignore;
|
|
13
|
-
this.examples = examples;
|
|
14
|
-
this.validators = validators;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Carrega o arquivo doc-gen.config.ts|.js da raiz do projeto.
|
|
18
|
-
*/
|
|
19
|
-
static async load() {
|
|
20
|
-
const ROOT = process.cwd();
|
|
21
|
-
const CONFIG_PATH_TS = path.join(ROOT, "doc-gen.config.mts");
|
|
22
|
-
const CONFIG_PATH_JS = path.join(ROOT, "doc-gen.config.mjs");
|
|
23
|
-
let configFile;
|
|
24
|
-
if (fs.existsSync(CONFIG_PATH_TS))
|
|
25
|
-
configFile = CONFIG_PATH_TS;
|
|
26
|
-
else if (fs.existsSync(CONFIG_PATH_JS))
|
|
27
|
-
configFile = CONFIG_PATH_JS;
|
|
28
|
-
if (!configFile) {
|
|
29
|
-
console.warn("⚠️ Nenhum arquivo doc-gen.config.ts|.js encontrado. Usando configuração vazia.");
|
|
30
|
-
return this.newEmpty();
|
|
31
|
-
}
|
|
32
|
-
await import("tsx/esm");
|
|
33
|
-
const imported = await import(pathToFileURL(configFile).href);
|
|
34
|
-
const rules = imported.rules;
|
|
35
|
-
if (!rules) {
|
|
36
|
-
console.warn("⚠️ O arquivo doc-gen.config.ts|.js não exporta 'rules'.");
|
|
37
|
-
return this.newEmpty();
|
|
38
|
-
}
|
|
39
|
-
return this.newWithConfigs(rules);
|
|
40
|
-
}
|
|
41
|
-
/** Cria uma instância vazia */
|
|
42
|
-
static newEmpty() {
|
|
43
|
-
return new DocGenConfig(new DocGenRules({ ignore: [], examples: [], validators: [] }));
|
|
44
|
-
}
|
|
45
|
-
/** Cria uma instância a partir de configurações */
|
|
46
|
-
static newWithConfigs(params) {
|
|
47
|
-
return new DocGenConfig(new DocGenRules(params));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export const config = await DocGenConfig.load();
|
package/dist/index.d.ts
DELETED
package/dist/main.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { DocEnums } from "./entities/enum.js";
|
|
3
|
-
import { DocGenModel } from "./entities/model.js";
|
|
4
|
-
import { DocFields } from "./field.type.js";
|
|
5
|
-
export declare class DocGen {
|
|
6
|
-
datamodel: string;
|
|
7
|
-
properties: Set<string>;
|
|
8
|
-
enums: DocEnums;
|
|
9
|
-
fields: DocFields;
|
|
10
|
-
models: DocGenModel[];
|
|
11
|
-
init(): Promise<void>;
|
|
12
|
-
build(): void;
|
|
13
|
-
}
|
package/dist/rules.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApiExampleBuilder, ValidatorBuilder } from "./types.js";
|
|
2
|
-
export declare class DocGenRules {
|
|
3
|
-
ignore: string[];
|
|
4
|
-
examples: Map<string, ApiExampleBuilder>;
|
|
5
|
-
validators: Map<string, string[]>;
|
|
6
|
-
constructor(params: {
|
|
7
|
-
ignore: string[];
|
|
8
|
-
examples: ApiExampleBuilder[];
|
|
9
|
-
validators: ValidatorBuilder[];
|
|
10
|
-
});
|
|
11
|
-
}
|