svelte-reflector 1.1.1 → 1.1.3
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.
|
@@ -47,7 +47,11 @@ export class MethodApiCallBuilder {
|
|
|
47
47
|
const outside = [];
|
|
48
48
|
if (hasData) {
|
|
49
49
|
outside.push(`const data = this.forms.${method.name}.bundle()`);
|
|
50
|
-
outside.push(`
|
|
50
|
+
// outside.push(` try{
|
|
51
|
+
// isFormValid(this.forms.create)
|
|
52
|
+
// } finally {
|
|
53
|
+
// this.loading = false
|
|
54
|
+
// }`);
|
|
51
55
|
}
|
|
52
56
|
if (hasHeaders) {
|
|
53
57
|
outside.push(`const headers = this.headers.bundle()`);
|
package/dist/main.js
CHANGED
|
@@ -106,8 +106,10 @@ export class Reflector {
|
|
|
106
106
|
'import { build, BuildedInput } from "$reflector/reflector.svelte";',
|
|
107
107
|
'import { validateInputs } from "$lib/sanitizers/validateFormats";',
|
|
108
108
|
`import type {${Array.from(enumTypes.values())}} from "$reflector/enums"`,
|
|
109
|
+
"import { PUBLIC_ENVIRONMENT } from '$env/static/public';",
|
|
110
|
+
"const isEmpty = PUBLIC_ENVIRONMENT !== 'DEV';",
|
|
109
111
|
...treatedSchemas,
|
|
110
|
-
].join("\n
|
|
112
|
+
].join("\n"));
|
|
111
113
|
this.schemaFile.save();
|
|
112
114
|
const buildFunctions = new ReflectorFile().fileContent;
|
|
113
115
|
this.typesSrc.changeData(buildFunctions);
|
|
@@ -75,7 +75,7 @@ export class PrimitiveProp {
|
|
|
75
75
|
if (this.emptyExample === sanitizedExample()) {
|
|
76
76
|
return sanitizedExample();
|
|
77
77
|
}
|
|
78
|
-
return `params?.empty ? ${this.emptyExample} : ${sanitizedExample()}`;
|
|
78
|
+
return `params?.empty || isEmpty ? ${this.emptyExample} : ${sanitizedExample()}`;
|
|
79
79
|
};
|
|
80
80
|
return `
|
|
81
81
|
build({ key: params?.data?.${name}, placeholder: ${sanitizedExample()}, example: ${buildedExample()}, required: ${required}, ${buildedValidator()}})
|
|
@@ -96,7 +96,7 @@ export class PrimitiveProp {
|
|
|
96
96
|
return `${this.name}${req}: ${this.rawType}`;
|
|
97
97
|
}
|
|
98
98
|
patchBuild() {
|
|
99
|
-
return `readonly ${this.name} = $derived.by(() => '${this.name}' in page.params ? page.params.${this.name} : mockedParams.${this.name})
|
|
99
|
+
return `readonly ${this.name} = $derived.by(() => '${this.name}' in page.params ? page.params.${this.name} : mockedParams.${this.name}) as string | null;`;
|
|
100
100
|
}
|
|
101
101
|
queryBuild() {
|
|
102
102
|
return `readonly ${this.name} = $derived(new QueryBuilder({ key: '${this.name}', value: ${this.emptyExample} }))`;
|
package/dist/reflector.js
CHANGED
|
@@ -75,14 +75,14 @@ export class ReflectorFile {
|
|
|
75
75
|
this.key = key;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
add() {
|
|
78
|
+
add = () => {
|
|
79
79
|
if (!this.selected) return;
|
|
80
80
|
const values = [...this.values, this.selected] as string[];
|
|
81
81
|
changeArrayParam({ key: this.key, values });
|
|
82
82
|
this.selected = null;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
remove(index: number) {
|
|
85
|
+
remove = (index: number) => {
|
|
86
86
|
const values = [
|
|
87
87
|
...this.values.slice(0, index),
|
|
88
88
|
...this.values.slice(index + 1),
|
|
@@ -108,12 +108,20 @@ export class ReflectorFile {
|
|
|
108
108
|
const arrayOfBuildedInputs = Object.values(schema) as BuildedInput<unknown>[];
|
|
109
109
|
|
|
110
110
|
const isValid = arrayOfBuildedInputs.every((a) => {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const result = a?.validate?.() ?? null;
|
|
112
|
+
|
|
113
|
+
if (result) {
|
|
114
|
+
throw new Error(\`O valor \${a.value} do campo está incorreto. \${result}\`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return result === null;
|
|
113
118
|
});
|
|
114
119
|
|
|
115
120
|
if (!isValid) {
|
|
116
|
-
toast.error(
|
|
121
|
+
toast.error(
|
|
122
|
+
'Erro ao fazer a requisição',
|
|
123
|
+
'Um ou mais campos preenchidos estão incorretos.'
|
|
124
|
+
);
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
return isValid;
|