svelte-reflector 1.0.3 → 1.0.4
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 +0 -1
- package/dist/module.js +14 -8
- package/package.json +1 -1
package/dist/main.js
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;
|
|
@@ -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,11 +59,11 @@ 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") {
|
|
66
|
+
this.imports.push(`import z from "zod";`);
|
|
62
67
|
moduleAtributes.add(`list = $state<${responseType}[]>([])`);
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -66,11 +71,13 @@ export class Module {
|
|
|
66
71
|
for (const f of form) {
|
|
67
72
|
formSet.add(`${f.name}: repo.newForm(${f.type}Schema)`);
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
if (formSet.size > 0) {
|
|
75
|
+
moduleAtributes.add(`
|
|
70
76
|
forms = $state({
|
|
71
77
|
${Array.from(formSet)}
|
|
72
78
|
})
|
|
73
79
|
`);
|
|
80
|
+
}
|
|
74
81
|
return {
|
|
75
82
|
moduleAtributes: Array.from(moduleAtributes),
|
|
76
83
|
moduleTypes: buildedModuleTypes,
|
|
@@ -135,7 +142,6 @@ export class Module {
|
|
|
135
142
|
buildFile(modulesAttributes, moduleTypes) {
|
|
136
143
|
return `
|
|
137
144
|
${this.imports.join(";")}
|
|
138
|
-
import z from "zod";
|
|
139
145
|
${this.buildImports()}
|
|
140
146
|
|
|
141
147
|
${moduleTypes.join(";")}
|