svelte-reflector 1.1.4 → 1.1.6
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/core/method/generators/MethodApiCallBuilder.js +0 -5
- package/dist/core/method/generators/MethodGenerator.d.ts +1 -0
- package/dist/core/method/generators/MethodGenerator.js +25 -11
- package/dist/core/method/generators/MethodPropsBuilder.d.ts +1 -0
- package/dist/core/method/generators/MethodPropsBuilder.js +16 -1
- package/dist/props/primitive.property.d.ts +1 -1
- package/dist/schema.js +2 -5
- package/package.json +1 -1
|
@@ -47,11 +47,6 @@ 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(` try{
|
|
51
|
-
// isFormValid(this.forms.create)
|
|
52
|
-
// } finally {
|
|
53
|
-
// this.loading = false
|
|
54
|
-
// }`);
|
|
55
50
|
}
|
|
56
51
|
if (hasHeaders) {
|
|
57
52
|
outside.push(`const headers = this.headers.bundle()`);
|
|
@@ -11,13 +11,17 @@ export class MethodGenerator {
|
|
|
11
11
|
const { inside, outside } = this.apiCallBuilder.build(method);
|
|
12
12
|
const props = this.propsBuilder.build(method);
|
|
13
13
|
const methodReturn = this.buildMethodReturn(method);
|
|
14
|
-
const additionalMethod = this.buildAdditionalMethod(method);
|
|
14
|
+
// const additionalMethod = this.buildAdditionalMethod(method);
|
|
15
|
+
const pathsInfo = this.propsBuilder.getPaths(method);
|
|
16
|
+
const paramsType = this.buildParamsType(method, pathsInfo);
|
|
15
17
|
return `
|
|
16
18
|
${description}
|
|
17
|
-
async ${method.name}(
|
|
18
|
-
const {onError, onSuccess} = behavior
|
|
19
|
+
async ${method.name}(params?: ${paramsType}) {
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
const behavior = params?.behavior ?? new Behavior();
|
|
22
|
+
const { onError, onSuccess } = behavior;
|
|
23
|
+
|
|
24
|
+
this.loading = true;
|
|
21
25
|
${props}
|
|
22
26
|
const endpoint = ${endpoint}
|
|
23
27
|
|
|
@@ -25,19 +29,29 @@ export class MethodGenerator {
|
|
|
25
29
|
|
|
26
30
|
try {
|
|
27
31
|
${inside}
|
|
28
|
-
await onSuccess?.(response)
|
|
32
|
+
await onSuccess?.(response);
|
|
29
33
|
|
|
30
|
-
return ${methodReturn}
|
|
31
|
-
} catch(e) {
|
|
34
|
+
return ${methodReturn};
|
|
35
|
+
} catch (e) {
|
|
32
36
|
const parsedError = JSON.parse((e as Error).message) as ApiErrorResponse;
|
|
33
37
|
return await onError?.(parsedError);
|
|
34
38
|
} finally {
|
|
35
|
-
this.loading = false
|
|
39
|
+
this.loading = false;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
buildParamsType(method, paramsPaths) {
|
|
46
|
+
const behaviorType = `Behavior<${method.responseTypeInterface}, ApiErrorResponse>`;
|
|
47
|
+
if (paramsPaths) {
|
|
48
|
+
return `{
|
|
49
|
+
behavior?: ${behaviorType};${paramsPaths}
|
|
50
|
+
}`;
|
|
51
|
+
}
|
|
52
|
+
return `{
|
|
53
|
+
behavior?: ${behaviorType};
|
|
54
|
+
}`;
|
|
41
55
|
}
|
|
42
56
|
buildDescription(method) {
|
|
43
57
|
return `/** ${method.description ?? ""} */`;
|
|
@@ -62,7 +76,7 @@ export class MethodGenerator {
|
|
|
62
76
|
}
|
|
63
77
|
return `
|
|
64
78
|
async ${method.name}AndClear(behavior: Behavior = new Behavior()) {
|
|
65
|
-
const data = await this.${method.name}(behavior)
|
|
79
|
+
const data = await this.${method.name}({behavior})
|
|
66
80
|
|
|
67
81
|
if (data) {
|
|
68
82
|
this.clearForms()
|
|
@@ -6,13 +6,28 @@ export class MethodPropsBuilder {
|
|
|
6
6
|
lines.push(`const { ${this.joinNames(querys)} } = this.querys.bundle()`);
|
|
7
7
|
}
|
|
8
8
|
if (paths.length > 0) {
|
|
9
|
-
lines.push(`const { ${this.joinNames(paths)} } = this.paths`);
|
|
9
|
+
lines.push(`const { ${this.joinNames(paths)} } = params?.paths ?? this.paths`);
|
|
10
10
|
}
|
|
11
11
|
if (cookies.length > 0) {
|
|
12
12
|
lines.push(`const cookies = this.cookies`);
|
|
13
13
|
}
|
|
14
14
|
return lines.join("\n");
|
|
15
15
|
}
|
|
16
|
+
getPaths(method) {
|
|
17
|
+
const { paths } = method.analyzers.props;
|
|
18
|
+
if (paths.length === 0)
|
|
19
|
+
return;
|
|
20
|
+
const paramsPaths = `
|
|
21
|
+
paths?: {
|
|
22
|
+
${paths
|
|
23
|
+
.map((path) => {
|
|
24
|
+
const type = path.rawType ?? path.type;
|
|
25
|
+
return `${path.name}: ${type}`;
|
|
26
|
+
})
|
|
27
|
+
.join("\n")}
|
|
28
|
+
}`;
|
|
29
|
+
return paramsPaths;
|
|
30
|
+
}
|
|
16
31
|
joinNames(props) {
|
|
17
32
|
return props.map((x) => x.name).join(", ");
|
|
18
33
|
}
|
package/dist/schema.js
CHANGED
|
@@ -48,12 +48,9 @@ export class Schema {
|
|
|
48
48
|
keys.push(prop.classBuild());
|
|
49
49
|
bundleParams.push(prop.bundleBuild());
|
|
50
50
|
});
|
|
51
|
-
const
|
|
52
|
-
const constructorCode = hasAttributes
|
|
53
|
-
? `constructor(params?: { data?: ${this.name}Interface | undefined, empty?: boolean }) {
|
|
51
|
+
const constructorCode = `constructor(params?: { data?: ${this.name}Interface | undefined, empty?: boolean }) {
|
|
54
52
|
${constructorThis.join(";\n")}
|
|
55
|
-
}
|
|
56
|
-
: "";
|
|
53
|
+
}`;
|
|
57
54
|
this.schema = `
|
|
58
55
|
export class ${this.name} {
|
|
59
56
|
${keys.join(";")}
|