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
package/src/helpers/loader.ts
DELETED
|
@@ -1,60 +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
|
-
import { ApiExampleBuilder, DocGenParams } from "../types.js";
|
|
7
|
-
|
|
8
|
-
export class DocGenConfig {
|
|
9
|
-
public readonly ignore: string[];
|
|
10
|
-
public readonly examples: Map<string, ApiExampleBuilder>;
|
|
11
|
-
public readonly validators: Map<string, string[]>;
|
|
12
|
-
|
|
13
|
-
constructor(configs: DocGenRules) {
|
|
14
|
-
const { examples, ignore, validators } = configs;
|
|
15
|
-
this.ignore = ignore;
|
|
16
|
-
this.examples = examples;
|
|
17
|
-
this.validators = validators;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Carrega o arquivo doc-gen.config.ts|.js da raiz do projeto.
|
|
22
|
-
*/
|
|
23
|
-
static async load(): Promise<DocGenConfig> {
|
|
24
|
-
const ROOT = process.cwd();
|
|
25
|
-
const CONFIG_PATH_TS = path.join(ROOT, "doc-gen.config.mts");
|
|
26
|
-
const CONFIG_PATH_JS = path.join(ROOT, "doc-gen.config.mjs");
|
|
27
|
-
|
|
28
|
-
let configFile: string | undefined;
|
|
29
|
-
if (fs.existsSync(CONFIG_PATH_TS)) configFile = CONFIG_PATH_TS;
|
|
30
|
-
else if (fs.existsSync(CONFIG_PATH_JS)) configFile = CONFIG_PATH_JS;
|
|
31
|
-
|
|
32
|
-
if (!configFile) {
|
|
33
|
-
console.warn("⚠️ Nenhum arquivo doc-gen.config.ts|.js encontrado. Usando configuração vazia.");
|
|
34
|
-
return this.newEmpty();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
await import("tsx/esm");
|
|
38
|
-
const imported = await import(pathToFileURL(configFile).href);
|
|
39
|
-
|
|
40
|
-
const rules = imported.rules as DocGenParams | undefined;
|
|
41
|
-
if (!rules) {
|
|
42
|
-
console.warn("⚠️ O arquivo doc-gen.config.ts|.js não exporta 'rules'.");
|
|
43
|
-
return this.newEmpty();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return this.newWithConfigs(rules);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Cria uma instância vazia */
|
|
50
|
-
private static newEmpty() {
|
|
51
|
-
return new DocGenConfig(new DocGenRules({ ignore: [], examples: [], validators: [] }));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Cria uma instância a partir de configurações */
|
|
55
|
-
private static newWithConfigs(params: DocGenParams) {
|
|
56
|
-
return new DocGenConfig(new DocGenRules(params));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const config = await DocGenConfig.load();
|
package/src/index.ts
DELETED
package/src/main.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { DocEnums, DocGenEnum, EnumValue } from "./entities/enum.js";
|
|
4
|
-
import { DocGenModel } from "./entities/model.js";
|
|
5
|
-
import { DocFields } from "./field.type.js";
|
|
6
|
-
import { Helper } from "./helpers/helpers.js";
|
|
7
|
-
import { Model } from "./types.js";
|
|
8
|
-
|
|
9
|
-
import prismaPkg from "@prisma/internals";
|
|
10
|
-
const { getDMMF } = prismaPkg;
|
|
11
|
-
|
|
12
|
-
const ROOT = process.cwd();
|
|
13
|
-
const PRISMA_DIR = path.join(ROOT, "prisma");
|
|
14
|
-
|
|
15
|
-
export class DocGen {
|
|
16
|
-
datamodel!: string;
|
|
17
|
-
properties!: Set<string>;
|
|
18
|
-
enums!: DocEnums;
|
|
19
|
-
fields!: DocFields;
|
|
20
|
-
models!: DocGenModel[];
|
|
21
|
-
|
|
22
|
-
async init() {
|
|
23
|
-
const prismaDataModel = await Helper.readPrismaFolderDatamodel(PRISMA_DIR);
|
|
24
|
-
const { datamodel } = await getDMMF({ datamodel: prismaDataModel });
|
|
25
|
-
|
|
26
|
-
this.enums = new DocEnums(
|
|
27
|
-
datamodel.enums.map(({ dbName, name, values }) => {
|
|
28
|
-
return new DocGenEnum({
|
|
29
|
-
dbName: dbName ?? "",
|
|
30
|
-
name,
|
|
31
|
-
values: values as EnumValue[],
|
|
32
|
-
});
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const fieldSet = new Set<string>();
|
|
37
|
-
|
|
38
|
-
datamodel.models.forEach((model) => {
|
|
39
|
-
model.fields.forEach((field) => fieldSet.add(`'${field.name}'`));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
this.fields = new DocFields(Array.from(fieldSet).toString());
|
|
43
|
-
|
|
44
|
-
this.models = datamodel.models.map((model) => {
|
|
45
|
-
return new DocGenModel(model as Model);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
this.build();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
build() {
|
|
52
|
-
this.fields.file.save();
|
|
53
|
-
this.enums.file.save();
|
|
54
|
-
this.models.forEach((model) => {
|
|
55
|
-
model.save();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const generator = new DocGen();
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
await generator.init();
|
|
64
|
-
console.log("✅ DTOs gerados com sucesso!");
|
|
65
|
-
} catch (err) {
|
|
66
|
-
console.error("❌ Erro ao gerar DTOs:", err);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
package/src/rules.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ApiExampleBuilder, ValidatorBuilder } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export class DocGenRules {
|
|
4
|
-
ignore: string[];
|
|
5
|
-
examples: Map<string, ApiExampleBuilder>;
|
|
6
|
-
validators: Map<string, string[]>;
|
|
7
|
-
|
|
8
|
-
constructor(params: { ignore: string[]; examples: ApiExampleBuilder[]; validators: ValidatorBuilder[] }) {
|
|
9
|
-
const { examples, ignore, validators } = params;
|
|
10
|
-
|
|
11
|
-
this.ignore = ignore;
|
|
12
|
-
|
|
13
|
-
if (!validators.length) {
|
|
14
|
-
console.warn("[doc-gen] Nenhum validator encontrado. Verifique seu docgen.config.ts*");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const allFields = validators.flatMap((validator) => validator.fields);
|
|
18
|
-
const uniqueFieldsToValidate = [...new Set(allFields)];
|
|
19
|
-
|
|
20
|
-
this.examples = new Map<string, ApiExampleBuilder>(
|
|
21
|
-
examples.flatMap((builder) => builder.fields.map((field) => [field, builder]))
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
this.validators = new Map<string, string[]>(
|
|
25
|
-
uniqueFieldsToValidate.map((field) => [
|
|
26
|
-
field,
|
|
27
|
-
validators.filter((validator) => validator.fields.includes(field)).map((validator) => validator.decorator.name),
|
|
28
|
-
])
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/static.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class Static {
|
|
2
|
-
static readonly AUTO_GENERATED_COMMENT = "// AUTO-GERADO: NÃO EDITAR MANUALMENTE. SUJEITO A PAULADAS!" as const;
|
|
3
|
-
|
|
4
|
-
static readonly STATIC_NAMES = [
|
|
5
|
-
"Alessandro",
|
|
6
|
-
"Pablo",
|
|
7
|
-
"Cláudio",
|
|
8
|
-
"Thiago",
|
|
9
|
-
"Guilherme",
|
|
10
|
-
"Dalton",
|
|
11
|
-
"Kaio",
|
|
12
|
-
"Gustavo",
|
|
13
|
-
"Cadu",
|
|
14
|
-
"Neyanne",
|
|
15
|
-
"John",
|
|
16
|
-
"Matheus",
|
|
17
|
-
"Davi",
|
|
18
|
-
] as const;
|
|
19
|
-
|
|
20
|
-
static getRandomString(values: string[]): string {
|
|
21
|
-
const idx = Math.floor(Math.random() * values.length);
|
|
22
|
-
return values[idx];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static getRandomNumber(min = 0, max = 1000): number {
|
|
26
|
-
return Math.floor(Math.random() * (max - min)) + min;
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/types/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module "tsx/esm";
|
package/src/types.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
export type FieldKind = "scalar" | "object" | "enum";
|
|
2
|
-
type FieldDefaultName = "now" | "autoincrement" | "cuid";
|
|
3
|
-
|
|
4
|
-
export type FieldType = "entity" | "dto";
|
|
5
|
-
|
|
6
|
-
export type DbName = string | null;
|
|
7
|
-
|
|
8
|
-
export type Scalar = "String" | "Int" | "BigInt" | "Float" | "Decimal" | "Boolean" | "DateTime" | "Json" | "Bytes";
|
|
9
|
-
|
|
10
|
-
export type Field = {
|
|
11
|
-
name: string;
|
|
12
|
-
dbName: string;
|
|
13
|
-
kind: FieldKind;
|
|
14
|
-
isList: boolean;
|
|
15
|
-
isRequired: boolean;
|
|
16
|
-
isUnique: boolean;
|
|
17
|
-
isId: boolean;
|
|
18
|
-
isReadOnly: boolean;
|
|
19
|
-
hasDefaultValue: boolean;
|
|
20
|
-
type: Scalar;
|
|
21
|
-
|
|
22
|
-
isGenerated: boolean;
|
|
23
|
-
isUpdatedAt: boolean;
|
|
24
|
-
|
|
25
|
-
nativeType: any;
|
|
26
|
-
default?: FieldDefault | string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export interface FieldDefault {
|
|
30
|
-
name: FieldDefaultName;
|
|
31
|
-
args: number[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type DocGenModel = {
|
|
35
|
-
name: string | null;
|
|
36
|
-
dbName: string | null;
|
|
37
|
-
schema: string | null;
|
|
38
|
-
readonly fields: Field[];
|
|
39
|
-
|
|
40
|
-
uniqueFields: string[][];
|
|
41
|
-
uniqueIndexes: ModelUniqueIndexes[];
|
|
42
|
-
primaryKey: null;
|
|
43
|
-
|
|
44
|
-
documentation?: string;
|
|
45
|
-
isGenerated?: boolean;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type ModelUniqueIndexes = {
|
|
49
|
-
name: string | null;
|
|
50
|
-
fields: any[];
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export class ValidatorBuilder {
|
|
54
|
-
decorator: ValidatorFactory | PropertyDecorator;
|
|
55
|
-
fields: string[];
|
|
56
|
-
|
|
57
|
-
constructor(decorator: PropertyDecorator, fields: string[]) {
|
|
58
|
-
this.decorator = decorator;
|
|
59
|
-
this.fields = fields;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export class ApiExampleBuilder {
|
|
64
|
-
fields: string[];
|
|
65
|
-
example: string | boolean | number;
|
|
66
|
-
|
|
67
|
-
constructor(fields: string[], example: string | boolean | number) {
|
|
68
|
-
this.fields = fields;
|
|
69
|
-
this.example = example;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type Rules = {
|
|
74
|
-
ignore: string[];
|
|
75
|
-
examples: ApiExampleBuilder[];
|
|
76
|
-
validators: ValidatorBuilder[];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
type ValidatorFactory = (...args: any[]) => PropertyDecorator;
|
|
80
|
-
|
|
81
|
-
export type Model = {
|
|
82
|
-
name: string;
|
|
83
|
-
dbName: string | null;
|
|
84
|
-
schema: string | null;
|
|
85
|
-
readonly fields: Field[];
|
|
86
|
-
|
|
87
|
-
uniqueFields: string[][];
|
|
88
|
-
uniqueIndexes: ModelUniqueIndexes[];
|
|
89
|
-
primaryKey: null;
|
|
90
|
-
|
|
91
|
-
documentation?: string;
|
|
92
|
-
isGenerated?: boolean;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export type ModelParams = { model: Model; examples: Map<string, ApiExampleBuilder>; validators: Map<string, string[]> };
|
|
96
|
-
export type FieldParams = {
|
|
97
|
-
examples: Map<string, ApiExampleBuilder>;
|
|
98
|
-
validators: Map<string, string[]>;
|
|
99
|
-
field: Field;
|
|
100
|
-
fieldType: FieldType;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export type DocGenParams = {
|
|
104
|
-
ignore: string[];
|
|
105
|
-
examples: ApiExampleBuilder[];
|
|
106
|
-
validators: ValidatorBuilder[];
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// field: Field, fieldType: FieldType
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"resolveJsonModule": true,
|
|
11
|
-
"skipLibCheck": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*.ts", "src/types/**/*.d.ts"],
|
|
14
|
-
"exclude": ["node_modules", "dist"]
|
|
15
|
-
}
|
|
File without changes
|
|
File without changes
|