nest-prisma_doc-gen 1.0.20 → 1.0.22

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.
@@ -6,7 +6,7 @@ export class DocGenDto {
6
6
  name;
7
7
  // file: DocGenFile;
8
8
  fields = [];
9
- imports = new Set([`${Static.AUTO_GENERATED_COMMENT}`, `import { ApiProperty } from '@nestjs/swagger'`]);
9
+ imports = new Set([`${Static.AUTO_GENERATED_COMMENT}`, `import { ApiProperty, IntersectionType } from '@nestjs/swagger'`]);
10
10
  classValidators = new Set();
11
11
  enums = new Set();
12
12
  constructor(model) {
@@ -32,7 +32,9 @@ export class DocGenDto {
32
32
  else if (field.isEnum) {
33
33
  this.enums.add(field.type);
34
34
  }
35
- return field.build();
35
+ return `class ${Helper.capitalizeFirstSafe(field.name)}Dto {
36
+ ${field.build()}
37
+ }`;
36
38
  })
37
39
  .join("\n\n");
38
40
  if (this.enums.size > 0) {
@@ -40,10 +42,11 @@ export class DocGenDto {
40
42
  this.imports.add(`import { ${Array.from(this.enums)} } from '@prisma/client';`);
41
43
  }
42
44
  this.imports.add(`import { ${Array.from(this.classValidators)} } from '${config.validatorPath}';`);
45
+ const intersections = this.fields.map((field) => Helper.capitalizeFirstSafe(field.name) + "Dto");
43
46
  return [
44
47
  `${Array.from(this.imports).join("\n")}`,
45
- `class ${this.name}Dto {
46
- ${sanitizedFields}
48
+ `${sanitizedFields}`,
49
+ `class ${this.name}Dto extends IntersectionType(${intersections.join(",")}) {
47
50
  }`,
48
51
  `class ${this.name}Id {
49
52
  @ApiProperty({ type: 'string', example: 'cmfxu4njg000008l52v7t8qze', required: true })
@@ -15,11 +15,47 @@ export class DocGenModel {
15
15
  this.response = new DocGenResponse(model);
16
16
  this.dto = new DocGenDto(model);
17
17
  this.exports = [`export * from './types/${Helper.toKebab(this.name)}'`];
18
+ const teste = new Map();
19
+ const bla = [...this.dto.fields, ...this.response.fields];
20
+ bla.forEach((field) => {
21
+ let a = teste.get(field.name);
22
+ if (!a) {
23
+ a = [];
24
+ teste.set(field.name, a);
25
+ }
26
+ a.push(field.fieldType);
27
+ });
28
+ const fdm = `
29
+ export namespace Input {
30
+ ${Array.from(teste)
31
+ .map(([fieldName, fieldTypes]) => {
32
+ const name = Helper.capitalizeFirstSafe(fieldName);
33
+ const types = fieldTypes.map((type) => Helper.capitalizeFirstSafe(type));
34
+ return `
35
+ export namespace ${name} {
36
+ ${types
37
+ .map((type) => {
38
+ return `
39
+ export type ${type} = ${name + type}
40
+ export const ${type} = ${name + type}
41
+ `;
42
+ })
43
+ .join(";")}
44
+ }
45
+ `;
46
+ })
47
+ .join(";")}
48
+ }
49
+ `;
18
50
  const intaaa = `
19
51
  export namespace ${this.name} {
52
+ export const Dto = ${this.name}Dto;
20
53
  export type Dto = ${this.name}Dto;
54
+ export const Res = ${this.name}Res;
21
55
  export type Res = ${this.name}Res;
56
+ export const Id = ${this.name}Id;
22
57
  export type Id = ${this.name}Id;
58
+ ${fdm}
23
59
  }
24
60
  `;
25
61
  const data = [this.dto.build(), this.response.build(), intaaa].join("");
@@ -1,3 +1,4 @@
1
+ import { Helper } from "../utils/helpers.js";
1
2
  import { DocGenField } from "./field.js";
2
3
  export class DocGenResponse {
3
4
  name;
@@ -18,13 +19,12 @@ export class DocGenResponse {
18
19
  if (field.isEnum) {
19
20
  this.enums.add(field.type);
20
21
  }
21
- return field.build();
22
+ return `class ${Helper.capitalizeFirstSafe(field.name)}Res {
23
+ ${field.build()}
24
+ }`;
22
25
  })
23
26
  .join("\n\n");
24
- return [
25
- `class ${this.name}Res {
26
- ${sanitizedFields}
27
- }`,
28
- ].join("\n\n");
27
+ const intersections = this.fields.map((field) => Helper.capitalizeFirstSafe(field.name) + "Res");
28
+ return [`${sanitizedFields}`, `class ${this.name}Res extends IntersectionType(${intersections.join(",")}) {}`].join("\n\n");
29
29
  }
30
30
  }
package/dist/file.js CHANGED
@@ -2,7 +2,6 @@ import { promises as fs } from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import * as prettier from "prettier";
4
4
  const ROOT = process.cwd();
5
- console.log(ROOT);
6
5
  const OUT_DIR = path.join(ROOT, "src/types/docgen");
7
6
  export class DocGenFile {
8
7
  outDir;
package/dist/main.js CHANGED
@@ -6,7 +6,7 @@ import prismaPkg from "@prisma/internals";
6
6
  import { PrismaUtils } from "./utils/prisma-utils.js";
7
7
  import { DocGenGeneric } from "./entities/generic.js";
8
8
  import { DocGenFile } from "./file.js";
9
- import { Helper } from "./utils/helpers.js";
9
+ // import { Helper } from "./utils/helpers.js";
10
10
  const { getDMMF } = prismaPkg;
11
11
  const ROOT = process.cwd();
12
12
  const PRISMA_DIR = path.join(ROOT, "src");
@@ -18,7 +18,7 @@ export class DocGen {
18
18
  models;
19
19
  generic = new DocGenGeneric();
20
20
  indexFile;
21
- fieldFile;
21
+ // fieldFile!: DocGenFile;
22
22
  async init() {
23
23
  const prismaDataModel = await PrismaUtils.readPrismaFolderDatamodel(PRISMA_DIR);
24
24
  const { datamodel } = await getDMMF({ datamodel: prismaDataModel });
@@ -37,19 +37,19 @@ export class DocGen {
37
37
  build() {
38
38
  this.generic.build();
39
39
  this.fields.file.save();
40
- const indexFileData = [`export * from './fields.types'`];
40
+ const indexFileData = [];
41
41
  const fields = [];
42
- const enumsSet = new Set();
43
- const classValidatorsSet = new Set();
42
+ // const enumsSet = new Set<string>();
43
+ // const classValidatorsSet = new Set<string>();
44
44
  for (const model of this.models) {
45
45
  indexFileData.push(...model.exports);
46
46
  fields.push(...model.dto.fields);
47
- for (const e of model.dto.enums) {
48
- enumsSet.add(e);
49
- }
50
- for (const classValidator of model.dto.classValidators) {
51
- classValidatorsSet.add(classValidator);
52
- }
47
+ // for (const e of model.dto.enums) {
48
+ // enumsSet.add(e);
49
+ // }
50
+ // for (const classValidator of model.dto.classValidators) {
51
+ // classValidatorsSet.add(classValidator);
52
+ // }
53
53
  model.save();
54
54
  }
55
55
  indexFileData.push("export * as DG from 'src/types/docgen/index';");
@@ -59,43 +59,43 @@ export class DocGen {
59
59
  continue;
60
60
  fieldMap.set(field.name, field);
61
61
  }
62
- const imports = new Set([`import { ApiProperty } from '@nestjs/swagger'`]);
63
- const validators = `import { ${Array.from(classValidatorsSet)} } from 'src/_nest/validators';`;
64
- const exportTypes = [];
65
- const fieldClasses = Array.from(fieldMap)
66
- .map(([_, field]) => {
67
- field.isRequired = true;
68
- const name = Helper.capitalizeFirstSafe(field.name);
69
- exportTypes.push(`
70
- export type ${name} = ${name}Dto
71
- `);
72
- return `
73
- class ${name}Dto {
74
- ${field.build()}
75
- }
76
- `;
77
- })
78
- .join("\n");
79
- imports.add(`import { ${Array.from(enumsSet)} } from '@prisma/client';`);
80
- imports.add(validators);
81
- const teste = `
82
- export namespace Input {
83
- ${exportTypes.join(";")}
84
- }
85
- `;
86
- const fieldFileContent = [Array.from(imports).join("\n"), fieldClasses, teste];
87
- this.fieldFile = new DocGenFile({
88
- fileName: "fields.types.ts",
89
- dir: "",
90
- data: fieldFileContent.join("\n"),
91
- });
62
+ // const imports = new Set([`import { ApiProperty } from '@nestjs/swagger'`]);
63
+ // const validators = `import { ${Array.from(classValidatorsSet)} } from 'src/_nest/validators';`;
64
+ // const exportTypes: string[] = [];
65
+ // const fieldClasses = Array.from(fieldMap)
66
+ // .map(([_, field]) => {
67
+ // field.isRequired = true;
68
+ // const name = Helper.capitalizeFirstSafe(field.name);
69
+ // exportTypes.push(`
70
+ // export const ${name} = ${name}Dto
71
+ // `);
72
+ // return `
73
+ // class ${name}Dto {
74
+ // ${field.build()}
75
+ // }
76
+ // `;
77
+ // })
78
+ // .join("\n");
79
+ // imports.add(`import { ${Array.from(enumsSet)} } from '@prisma/client';`);
80
+ // imports.add(validators);
81
+ // const teste = `
82
+ // export namespace Input {
83
+ // ${exportTypes.join(";")}
84
+ // }
85
+ // `;
86
+ // const fieldFileContent = [Array.from(imports).join("\n"), fieldClasses, teste];
87
+ // this.fieldFile = new DocGenFile({
88
+ // fileName: "fields.types.ts",
89
+ // dir: "",
90
+ // data: fieldFileContent.join("\n"),
91
+ // });
92
92
  this.indexFile = new DocGenFile({
93
93
  fileName: "index.ts",
94
94
  dir: "",
95
95
  data: indexFileData.join("\n"),
96
96
  });
97
97
  this.indexFile.save();
98
- this.fieldFile.save();
98
+ // this.fieldFile.save();
99
99
  }
100
100
  }
101
101
  const generator = new DocGen();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nest-prisma_doc-gen",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Auto generates ApiProperties from schema.prisma",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",