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 +2 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.js +18 -10
- package/package.json +1 -1
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
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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(";")}
|