svelte-reflector 1.0.30 → 1.0.32
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 +4 -4
- package/dist/method.js +4 -4
- package/dist/module.d.ts +3 -2
- package/dist/module.js +63 -63
- package/dist/primitive-property.js +2 -2
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -109,16 +109,16 @@ export class Reflector {
|
|
|
109
109
|
type ValidatorResult = string | null;
|
|
110
110
|
type ValidatorFn<T> = (v: T) => ValidatorResult;
|
|
111
111
|
|
|
112
|
-
export class Behavior { onError?: (e) => void; onSuccess?: () => void }
|
|
112
|
+
export class Behavior { onError?: (e) => void; onSuccess?: (v) => void }
|
|
113
113
|
|
|
114
114
|
export class BuildedInput<T> {
|
|
115
115
|
value = $state<T>(null as any);
|
|
116
116
|
display = $state<T>(null as any);
|
|
117
117
|
required: boolean;
|
|
118
118
|
placeholder: T;
|
|
119
|
-
|
|
119
|
+
readonly validator?: ValidatorFn<T>;
|
|
120
120
|
|
|
121
|
-
constructor(params: { key?: T; example: T; required: boolean; validator?: ValidatorFn<T> }) {
|
|
121
|
+
constructor(params: { key?: T | undefined; example: T; required: boolean; validator?: ValidatorFn<T> }) {
|
|
122
122
|
const { example, required, key, validator } = params;
|
|
123
123
|
|
|
124
124
|
const initial = key ?? example;
|
|
@@ -140,7 +140,7 @@ export class Reflector {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export function build<T>(params: {
|
|
143
|
-
key?: T;
|
|
143
|
+
key?: T | undefined;
|
|
144
144
|
example: T;
|
|
145
145
|
required: boolean;
|
|
146
146
|
validator?: ValidatorFn<T>;
|
package/dist/method.js
CHANGED
|
@@ -68,9 +68,9 @@ export class Method {
|
|
|
68
68
|
};
|
|
69
69
|
const [diamond, response] = preBuild();
|
|
70
70
|
if (this.request.attributeType === "list") {
|
|
71
|
-
beforeResponse.push(`
|
|
71
|
+
beforeResponse.push(`this.list = ${this.request.responseType}.from(response.data)`);
|
|
72
72
|
const inside = `
|
|
73
|
-
${response} await repo.api.get
|
|
73
|
+
${response} await repo.api.get<${diamond}, unknown>({
|
|
74
74
|
endpoint,
|
|
75
75
|
queryData: { ${this.gee(this.querys)} }
|
|
76
76
|
})
|
|
@@ -152,11 +152,11 @@ export class Method {
|
|
|
152
152
|
|
|
153
153
|
try{
|
|
154
154
|
${inside}
|
|
155
|
-
onSuccess?.()
|
|
155
|
+
onSuccess?.(response)
|
|
156
156
|
|
|
157
157
|
return ${this.methodReturn()}
|
|
158
158
|
} catch(e) {
|
|
159
|
-
onError?.(e)
|
|
159
|
+
return onError?.(e)
|
|
160
160
|
} finally {
|
|
161
161
|
this.loading = false
|
|
162
162
|
}
|
package/dist/module.d.ts
CHANGED
|
@@ -16,12 +16,11 @@ export declare class Module {
|
|
|
16
16
|
path: string;
|
|
17
17
|
});
|
|
18
18
|
private buildClassProps;
|
|
19
|
+
private buildMethod;
|
|
19
20
|
private creator;
|
|
20
21
|
private getPath;
|
|
21
22
|
private getAdditionalMethod;
|
|
22
|
-
private buildMethods;
|
|
23
23
|
private getParameters;
|
|
24
|
-
private buildImports;
|
|
25
24
|
private buildClass;
|
|
26
25
|
private buildConstructor;
|
|
27
26
|
buildFile(params: {
|
|
@@ -29,5 +28,7 @@ export declare class Module {
|
|
|
29
28
|
moduleTypes: string[];
|
|
30
29
|
moduleInit: string[];
|
|
31
30
|
moduleClear: string[];
|
|
31
|
+
classImports: string;
|
|
32
|
+
buildedMethods: string[];
|
|
32
33
|
}): string;
|
|
33
34
|
}
|
package/dist/module.js
CHANGED
|
@@ -19,7 +19,6 @@ export class Module {
|
|
|
19
19
|
"// AUTO GERADO. QUEM ALTERAR GOSTA DE RAPAZES!\n",
|
|
20
20
|
'import repo from "$repository/main"',
|
|
21
21
|
'import { Behavior, build, BuildedInput } from "$reflector/reflector.svelte";',
|
|
22
|
-
'import { PUBLIC_ENVIRONMENT } from "$env/static/public";',
|
|
23
22
|
]);
|
|
24
23
|
this.name = capitalizeFirstLetter(name);
|
|
25
24
|
this.path = path;
|
|
@@ -30,12 +29,17 @@ export class Module {
|
|
|
30
29
|
});
|
|
31
30
|
});
|
|
32
31
|
const { cookies, headers, paths, querys } = this.getParameters();
|
|
33
|
-
const
|
|
34
|
-
|
|
32
|
+
const allBuilded = this.creator({
|
|
33
|
+
cookies,
|
|
34
|
+
headers,
|
|
35
|
+
paths,
|
|
36
|
+
querys,
|
|
37
|
+
});
|
|
38
|
+
this.moduleConstructor = this.buildConstructor(allBuilded.form);
|
|
35
39
|
//sempre por último
|
|
36
40
|
this.src = new Source({
|
|
37
41
|
path: this.getPath(),
|
|
38
|
-
data: this.buildFile(
|
|
42
|
+
data: this.buildFile(allBuilded),
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
45
|
buildClassProps(params) {
|
|
@@ -71,6 +75,12 @@ export class Module {
|
|
|
71
75
|
`;
|
|
72
76
|
return [buildedInterface, buildedClass].join(";");
|
|
73
77
|
}
|
|
78
|
+
buildMethod(params) {
|
|
79
|
+
const { hasEntity, hasForm, method } = params;
|
|
80
|
+
const canAddClearMethod = hasForm && hasEntity;
|
|
81
|
+
let additionalMethod = this.getAdditionalMethod({ canAddClearMethod, method });
|
|
82
|
+
return [method.build(), additionalMethod].join("\n");
|
|
83
|
+
}
|
|
74
84
|
creator(params) {
|
|
75
85
|
const { cookies, headers, paths, querys } = params;
|
|
76
86
|
const buildedModuleTypes = [];
|
|
@@ -85,36 +95,36 @@ export class Module {
|
|
|
85
95
|
moduleInit.add(`this.clear${capitalizeFirstLetter(capitalizedName)}()`);
|
|
86
96
|
moduleClear.add(`clear${capitalizedName}() { this.${name} = new ${capitalizedName}() }`);
|
|
87
97
|
};
|
|
88
|
-
|
|
89
|
-
querys
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
getParams({ name
|
|
98
|
-
}
|
|
99
|
-
if (paths.length > 0) {
|
|
100
|
-
getParams({ name: "paths", props: paths });
|
|
101
|
-
}
|
|
102
|
-
if (cookies.length > 0) {
|
|
103
|
-
getParams({ name: "cookies", props: cookies });
|
|
98
|
+
const argEntries = [
|
|
99
|
+
{ name: "querys", props: querys },
|
|
100
|
+
{ name: "headers", props: headers },
|
|
101
|
+
{ name: "paths", props: paths },
|
|
102
|
+
{ name: "cookies", props: cookies },
|
|
103
|
+
];
|
|
104
|
+
for (const { name, props } of argEntries) {
|
|
105
|
+
if (!props.length)
|
|
106
|
+
continue;
|
|
107
|
+
getParams({ name, props });
|
|
104
108
|
}
|
|
109
|
+
const hasForm = this.methods.some((m) => m.request.attributeType === "form");
|
|
110
|
+
const hasEntity = this.methods.some((m) => m.request.attributeType === "entity");
|
|
105
111
|
const form = [];
|
|
112
|
+
const formSet = new Set();
|
|
113
|
+
const entries = new Set();
|
|
114
|
+
const methods = [];
|
|
106
115
|
for (const method of this.methods) {
|
|
107
116
|
const { bodyType, responseType, attributeType } = method.request;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
if (method.request.bodyType === "string") {
|
|
118
|
+
createDangerMessage(`Metodo ${method.name} foi ignorado por possuir um body inválido.`);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
112
121
|
if (attributeType === "form" && bodyType) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
122
|
+
const name = method.name;
|
|
123
|
+
const type = bodyType;
|
|
124
|
+
form.push({ name, type });
|
|
125
|
+
formSet.add(`${name}: new ${type}()`);
|
|
117
126
|
}
|
|
127
|
+
methods.push(this.buildMethod({ hasEntity, hasForm, method }));
|
|
118
128
|
if (attributeType === "entity") {
|
|
119
129
|
const entityName = treatByUppercase(method.request.responseType ?? "");
|
|
120
130
|
moduleAttributes.add(`${entityName} = $state<${responseType} | undefined>()`);
|
|
@@ -126,11 +136,16 @@ export class Module {
|
|
|
126
136
|
moduleInit.add("this.clearList()");
|
|
127
137
|
moduleClear.add(`clearList() { this.list = [] }`);
|
|
128
138
|
}
|
|
139
|
+
if (bodyType) {
|
|
140
|
+
entries.add(`${bodyType}`);
|
|
141
|
+
}
|
|
142
|
+
if (responseType) {
|
|
143
|
+
entries.add(`type ${responseType}Interface`);
|
|
144
|
+
entries.add(`${responseType}`);
|
|
145
|
+
}
|
|
129
146
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
formSet.add(`${f.name}: new ${f.type}()`);
|
|
133
|
-
}
|
|
147
|
+
const cleanEntries = Array.from(entries).filter((x) => x != "type any");
|
|
148
|
+
const classImports = `import { ${cleanEntries} } from '$reflector/schemas.svelte';`;
|
|
134
149
|
if (formSet.size > 0) {
|
|
135
150
|
moduleAttributes.add(`
|
|
136
151
|
forms = $state({
|
|
@@ -144,12 +159,16 @@ export class Module {
|
|
|
144
159
|
clearForms() { this.forms = this.buildForms(true) };
|
|
145
160
|
`);
|
|
146
161
|
}
|
|
162
|
+
// return this.methods.map((method) => {
|
|
163
|
+
// });
|
|
147
164
|
return {
|
|
148
165
|
moduleAttributes: Array.from(moduleAttributes),
|
|
149
166
|
moduleTypes: buildedModuleTypes,
|
|
150
167
|
moduleInit: Array.from(moduleInit),
|
|
151
168
|
moduleClear: Array.from(moduleClear),
|
|
152
169
|
form,
|
|
170
|
+
classImports,
|
|
171
|
+
buildedMethods: methods,
|
|
153
172
|
};
|
|
154
173
|
}
|
|
155
174
|
getPath() {
|
|
@@ -178,15 +197,8 @@ export class Module {
|
|
|
178
197
|
}
|
|
179
198
|
return additionalMethod;
|
|
180
199
|
}
|
|
181
|
-
buildMethods() {
|
|
182
|
-
|
|
183
|
-
const hasEntity = this.methods.some((m) => m.request.attributeType === "entity");
|
|
184
|
-
const canAddClearMethod = hasForm && hasEntity;
|
|
185
|
-
return this.methods.map((method) => {
|
|
186
|
-
let additionalMethod = this.getAdditionalMethod({ canAddClearMethod, method });
|
|
187
|
-
return [method.build(), additionalMethod].join("\n");
|
|
188
|
-
});
|
|
189
|
-
}
|
|
200
|
+
// private buildMethods() {
|
|
201
|
+
// }
|
|
190
202
|
getParameters() {
|
|
191
203
|
const queryMap = new Map();
|
|
192
204
|
const headerMap = new Map();
|
|
@@ -206,25 +218,11 @@ export class Module {
|
|
|
206
218
|
querys: Array.from(queryMap.values()),
|
|
207
219
|
};
|
|
208
220
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const { bodyType, responseType, apiType } = method.request;
|
|
213
|
-
if (bodyType) {
|
|
214
|
-
entries.add(`${bodyType}`);
|
|
215
|
-
}
|
|
216
|
-
if (responseType) {
|
|
217
|
-
entries.add(`type ${responseType}Interface`);
|
|
218
|
-
entries.add(`${responseType}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const cleanEntries = Array.from(entries).filter((x) => x != "type any");
|
|
222
|
-
if (cleanEntries.length === 0)
|
|
223
|
-
return "";
|
|
224
|
-
return `import { ${cleanEntries} } from '$reflector/schemas.svelte';`;
|
|
225
|
-
}
|
|
221
|
+
// private buildImportsAndProps() {}
|
|
222
|
+
// private buildImports() {
|
|
223
|
+
// }
|
|
226
224
|
buildClass(params) {
|
|
227
|
-
const { moduleInit, moduleAttributes, moduleClear } = params;
|
|
225
|
+
const { moduleInit, moduleAttributes, moduleClear, buildedMethods } = params;
|
|
228
226
|
const reset = moduleAttributes.length > 1
|
|
229
227
|
? `reset() {
|
|
230
228
|
${moduleInit.join(";")}
|
|
@@ -236,7 +234,7 @@ export class Module {
|
|
|
236
234
|
|
|
237
235
|
${this.moduleConstructor}
|
|
238
236
|
|
|
239
|
-
${
|
|
237
|
+
${buildedMethods.join("\n")}
|
|
240
238
|
|
|
241
239
|
${moduleClear.join("\n\n")}
|
|
242
240
|
|
|
@@ -265,14 +263,16 @@ export class Module {
|
|
|
265
263
|
return teste;
|
|
266
264
|
}
|
|
267
265
|
buildFile(params) {
|
|
268
|
-
const { moduleInit, moduleTypes, moduleAttributes, moduleClear } = params;
|
|
266
|
+
const { moduleInit, moduleTypes, moduleAttributes, moduleClear, classImports, buildedMethods } = params;
|
|
269
267
|
return `
|
|
270
268
|
${Array.from(this.imports).join(";")}
|
|
271
|
-
${
|
|
269
|
+
${classImports}
|
|
270
|
+
|
|
271
|
+
const PUBLIC_ENVIRONMENT = import.meta.env.PUBLIC_ENVIRONMENT;
|
|
272
272
|
|
|
273
273
|
${moduleTypes.join(";")}
|
|
274
274
|
|
|
275
|
-
${this.buildClass({ moduleAttributes, moduleInit, moduleClear })}
|
|
275
|
+
${this.buildClass({ moduleAttributes, moduleInit, moduleClear, buildedMethods })}
|
|
276
276
|
`;
|
|
277
277
|
}
|
|
278
278
|
}
|
|
@@ -36,7 +36,7 @@ export class PrimitiveProp {
|
|
|
36
36
|
getEmptyExample(params) {
|
|
37
37
|
const { schemaObject, type } = params;
|
|
38
38
|
if (type === "number") {
|
|
39
|
-
return
|
|
39
|
+
return 1;
|
|
40
40
|
}
|
|
41
41
|
else if (type === "boolean") {
|
|
42
42
|
return false;
|
|
@@ -45,7 +45,7 @@ export class PrimitiveProp {
|
|
|
45
45
|
return `'${schemaObject.enum[0]}'`;
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
return "
|
|
48
|
+
return "";
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
thisDot() {
|