svelte-reflector 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.
package/dist/main.js CHANGED
@@ -61,7 +61,6 @@ export class Reflector {
61
61
  entity = aaa.join("");
62
62
  }
63
63
  }
64
- // console.warn(entity)
65
64
  if (!entity)
66
65
  continue;
67
66
  const existingOps = methodsMap.get(entity);
@@ -85,6 +84,8 @@ export class Reflector {
85
84
  this.schemaFile.changeData([`import z from 'zod';`, ...this.schemas.map((s) => `${s.schema} ${s.type}`)].join("\n\n"));
86
85
  this.schemaFile.save();
87
86
  for (const module of this.modules) {
87
+ if (module.methods.length === 0)
88
+ continue;
88
89
  module.src.save();
89
90
  }
90
91
  return {};
package/dist/module.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare class Module {
6
6
  readonly endpoint: string;
7
7
  readonly moduleName: string;
8
8
  readonly src: Source;
9
- imports: string[];
9
+ imports: Set<string>;
10
10
  parameters: string[];
11
11
  methods: Method[];
12
12
  constructor(params: {
package/dist/module.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
3
  import { Source } from "./file.js";
4
- import { capitalizeFirstLetter, stripState } from "./helpers/helpers.js";
4
+ import { capitalizeFirstLetter, createDangerMessage, stripState } from "./helpers/helpers.js";
5
5
  import { Method } from "./method.js";
6
6
  export class Module {
7
7
  name;
@@ -14,7 +14,7 @@ export class Module {
14
14
  constructor(params) {
15
15
  const { name, operations, endpoint, dir, moduleName } = params;
16
16
  this.moduleName = moduleName;
17
- this.imports = ["// AUTO GERADO. QUEM ALTERAR GOSTA DE RAPAZES!\n", 'import repo from "$repository/main"'];
17
+ this.imports = new Set(["// AUTO GERADO. QUEM ALTERAR GOSTA DE RAPAZES!\n", 'import repo from "$repository/main"']);
18
18
  this.name = capitalizeFirstLetter(name);
19
19
  this.endpoint = endpoint;
20
20
  const methods = operations.map((operation) => {
@@ -25,10 +25,15 @@ export class Module {
25
25
  });
26
26
  // não vão entrar metodos que não tiverem uma resposta tipada
27
27
  this.methods = methods.filter((op) => {
28
- // if (!op.request.responseType) {
29
- // createDangerMessage(`Método [ ${op.name} ] do módulo [ ${this.moduleName} ] sem tipagem na resposta.`);
30
- // }
31
- return op.request.responseType;
28
+ const responseTypeOk = op.request.responseType;
29
+ const propertiesOk = op.zodProperties.length > 0;
30
+ if (!responseTypeOk) {
31
+ createDangerMessage(`Método [ ${op.name} ] do módulo [ ${this.moduleName} ] sem tipagem na resposta.`);
32
+ }
33
+ else if (!propertiesOk) {
34
+ createDangerMessage(`Método [ ${op.name} ] do módulo [ ${this.moduleName} ] com tipagem incorreta.`);
35
+ }
36
+ return responseTypeOk && propertiesOk;
32
37
  });
33
38
  this.parameters = this.getParameters();
34
39
  const { moduleAtributes, moduleTypes } = this.creator();
@@ -54,23 +59,27 @@ export class Module {
54
59
  type: bodyType,
55
60
  });
56
61
  }
57
- console.warn(attributeType);
58
62
  if (attributeType === "entity") {
59
63
  moduleAtributes.add(`entity = $state<${responseType} | undefined>()`);
60
64
  }
61
65
  else if (attributeType === "list") {
62
66
  moduleAtributes.add(`list = $state<${responseType}[]>([])`);
63
67
  }
68
+ if (attributeType === "list" || this.parameters.length > 0) {
69
+ this.imports.add(`import z from "zod";`);
70
+ }
64
71
  }
65
72
  const formSet = new Set();
66
73
  for (const f of form) {
67
74
  formSet.add(`${f.name}: repo.newForm(${f.type}Schema)`);
68
75
  }
69
- moduleAtributes.add(`
76
+ if (formSet.size > 0) {
77
+ moduleAtributes.add(`
70
78
  forms = $state({
71
79
  ${Array.from(formSet)}
72
80
  })
73
81
  `);
82
+ }
74
83
  return {
75
84
  moduleAtributes: Array.from(moduleAtributes),
76
85
  moduleTypes: buildedModuleTypes,
@@ -134,8 +143,7 @@ export class Module {
134
143
  }
135
144
  buildFile(modulesAttributes, moduleTypes) {
136
145
  return `
137
- ${this.imports.join(";")}
138
- import z from "zod";
146
+ ${Array.from(this.imports).join(";")}
139
147
  ${this.buildImports()}
140
148
 
141
149
  ${moduleTypes.join(";")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",