prismadoc 1.0.36 → 1.0.38

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.
@@ -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();
@@ -170,11 +170,16 @@ export class DocGenField {
170
170
  if (this.isArray) {
171
171
  return `${this.type}[]`;
172
172
  }
173
+ else if (!this.isRequired && this.fieldType === "res") {
174
+ return `${this.type} | null`;
175
+ }
173
176
  else {
174
177
  return this.type;
175
178
  }
176
179
  };
177
- const optionalFlag = this.isRequired ? "!" : "?";
180
+ let optionalFlag = "?";
181
+ if (this.isRequired || this.fieldType === "res")
182
+ optionalFlag = "!";
178
183
  const validators = this.sanitizeValidators();
179
184
  const apiExample = this.buildApiExample().join(", ");
180
185
  return {
@@ -189,7 +194,7 @@ export class DocGenField {
189
194
  return [apiProperty, ...validators, atributes].join("\n");
190
195
  }
191
196
  else {
192
- return [apiProperty, atributes].join("\n");
197
+ return [apiProperty, "@Expose()", atributes].join("\n");
193
198
  }
194
199
  }
195
200
  }
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
@@ -29,7 +29,5 @@ export class DocGenRules {
29
29
  });
30
30
  });
31
31
  this.validators = aaaValidators;
32
- // this.validators = new Map<string, {decorator: string, inside?: Inside}>(
33
- // );
34
32
  }
35
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prismadoc",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "description": "Auto generates ApiProperties from schema.prisma",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",