nest-prisma_doc-gen 1.0.3 → 1.0.5

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 (52) hide show
  1. package/dist/config.type.js +16 -0
  2. package/dist/entities/dto-generator.js +7 -5
  3. package/dist/entities/entity-generator.js +4 -4
  4. package/dist/entities/field.js +7 -7
  5. package/dist/index.js +0 -1
  6. package/dist/main.js +8 -6
  7. package/dist/rules.js +1 -1
  8. package/dist/schemas/config.schema.json +79 -0
  9. package/dist/static.js +0 -22
  10. package/dist/testes.js +21 -0
  11. package/dist/types.js +1 -17
  12. package/dist/utils/config-loader.js +33 -0
  13. package/dist/utils/copy-schemas.js +10 -0
  14. package/dist/{helpers → utils}/helpers.js +3 -0
  15. package/dist/utils/loader.js +47 -0
  16. package/package.json +12 -8
  17. package/dist/entities/dto-generator.d.ts +0 -13
  18. package/dist/entities/entity-generator.d.ts +0 -12
  19. package/dist/entities/enum.d.ts +0 -22
  20. package/dist/entities/field.d.ts +0 -24
  21. package/dist/entities/model.d.ts +0 -11
  22. package/dist/field.type.d.ts +0 -7
  23. package/dist/file.d.ts +0 -11
  24. package/dist/helpers/helpers.d.ts +0 -14
  25. package/dist/helpers/loader.d.ts +0 -4
  26. package/dist/helpers/loader.js +0 -50
  27. package/dist/helpers/propeties.static.d.ts +0 -2
  28. package/dist/index.d.ts +0 -2
  29. package/dist/main.d.ts +0 -13
  30. package/dist/rules.d.ts +0 -11
  31. package/dist/static.d.ts +0 -6
  32. package/dist/types.d.ts +0 -79
  33. package/src/entities/dto-generator.ts +0 -61
  34. package/src/entities/entity-generator.ts +0 -55
  35. package/src/entities/enum.ts +0 -47
  36. package/src/entities/field.ts +0 -190
  37. package/src/entities/model.ts +0 -23
  38. package/src/entities/validator.ts +0 -17
  39. package/src/field.type.ts +0 -27
  40. package/src/file.ts +0 -34
  41. package/src/helpers/helpers.ts +0 -152
  42. package/src/helpers/loader.ts +0 -60
  43. package/src/helpers/propeties.static.ts +0 -3
  44. package/src/index.ts +0 -2
  45. package/src/main.ts +0 -68
  46. package/src/rules.ts +0 -31
  47. package/src/static.ts +0 -28
  48. package/src/types/global.d.ts +0 -1
  49. package/src/types.ts +0 -109
  50. package/tsconfig.build.json +0 -5
  51. package/tsconfig.json +0 -15
  52. /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 "../helpers/helpers.js";
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.forEach((field) => {
14
+ for (const field of model.fields) {
15
15
  if (field.isUpdatedAt || field.isId || field.name === "createdAt" || field.kind === "object")
16
- return;
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.forEach((v) => this.classValidators.add(v.name));
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 "../helpers/helpers.js";
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.forEach((field) => {
13
+ for (const field of model.fields) {
14
14
  if (field.kind === "object")
15
- return;
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`,
@@ -1,6 +1,5 @@
1
- import { Helper } from "../helpers/helpers.js";
2
- import { config } from "../helpers/loader.js";
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
- findedDecorators.forEach((name) => {
69
+ for (const name of findedDecorators) {
71
70
  this.processValidator(name);
72
- });
71
+ }
73
72
  }
74
73
  }
75
74
  setType() {
@@ -89,6 +88,7 @@ export class DocGenField {
89
88
  const fieldName = this.scalarField.name;
90
89
  const props = [];
91
90
  const scalarDbName = this.scalarField.dbName ?? "genericDbName";
91
+ console.log(this.scalarField);
92
92
  if (this.isEntity) {
93
93
  if (this.isList) {
94
94
  props.push(`example: [generateExample(${this.type})]`);
@@ -103,7 +103,7 @@ export class DocGenField {
103
103
  else if (helpers.isDate(this.scalarField)) {
104
104
  props.push(`example: '2025-09-03T03:00:00.000Z'`);
105
105
  }
106
- else if (this.scalarField.isId || (this.scalarField.isReadOnly && scalarDbName.split("_").includes("id"))) {
106
+ else if (this.scalarField.isId || Helper.splitByUpperCase(this.scalarField.name).includes("Id")) {
107
107
  props.push(`example: 'cmfxu4njg000008l52v7t8qze'`);
108
108
  }
109
109
  else if (this.scalarField.type === "Boolean") {
@@ -113,7 +113,7 @@ export class DocGenField {
113
113
  props.push(`example: ${this.scalarField.type}[0]`);
114
114
  }
115
115
  else if (this.scalarField.type === "Int") {
116
- props.push(`example: ${Static.getRandomNumber()}`);
116
+ props.push(`example: 777`);
117
117
  }
118
118
  else if (this.scalarField.type === "String") {
119
119
  props.push(`example: 'ordinary string'`);
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { DocGenRules } from "./rules.js";
2
- export { DocGenConfig } from "./helpers/loader.js";
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 "./helpers/helpers.js";
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.forEach((model) => {
29
- model.fields.forEach((field) => fieldSet.add(`'${field.name}'`));
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.forEach((model) => {
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.name),
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 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
- }
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/");
@@ -137,6 +137,9 @@ export class Helper {
137
137
  else
138
138
  return "any";
139
139
  }
140
+ static splitByUpperCase(str) {
141
+ return str.split(/(?=[A-Z])/);
142
+ }
140
143
  isDate(field) {
141
144
  return field.kind === "scalar" && field.type === "DateTime";
142
145
  }
@@ -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",
3
+ "version": "1.0.5",
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
- "generate": "node dist/tools/generate-dtos.js"
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
- "nest-prisma_doc-gen": "^1.0.1",
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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -1,7 +0,0 @@
1
- import { DocGenFile } from "./file.js";
2
- export declare class DocFields {
3
- fields: string;
4
- file: DocGenFile;
5
- constructor(fields: string);
6
- build(): string;
7
- }
package/dist/file.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare class DocGenFile {
2
- outDir: string;
3
- data: string;
4
- constructor(params: {
5
- fileName: string;
6
- dir: string;
7
- data: string;
8
- customDir?: string;
9
- });
10
- save(): Promise<void>;
11
- }
@@ -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
- }
@@ -1,4 +0,0 @@
1
- import "tsx/esm";
2
- import { DocGenRules } from "../index.js";
3
- export declare let rules: DocGenRules;
4
- export declare function loadDocGenConfig(): Promise<any>;
@@ -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();
@@ -1,2 +0,0 @@
1
- export declare const FIELD_NAMES: readonly [""];
2
- export type FieldName = (typeof FIELD_NAMES)[number];
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { DocGenRules } from "./rules.js";
2
- export { DocGenConfig } from "./helpers/loader.js";