svelte-reflector 1.0.24 → 1.0.26
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/array.property.d.ts +2 -0
- package/dist/array.property.js +22 -7
- package/dist/helpers/helpers.js +12 -6
- package/dist/method.js +11 -6
- package/dist/primitive-property.js +3 -1
- package/dist/property.js +3 -2
- package/dist/schema.js +4 -0
- package/package.json +1 -1
package/dist/array.property.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { SchemaObject } from "./types/open-api-spec.interface.js";
|
|
|
2
2
|
export declare class ArrayProp {
|
|
3
3
|
name: string;
|
|
4
4
|
type: string;
|
|
5
|
+
isSpecial: boolean;
|
|
5
6
|
constructor(params: {
|
|
6
7
|
name: string;
|
|
7
8
|
schemaObject: SchemaObject;
|
|
@@ -13,4 +14,5 @@ export declare class ArrayProp {
|
|
|
13
14
|
classBuild(): string;
|
|
14
15
|
interfaceBuild(): string;
|
|
15
16
|
bundleBuild(): string;
|
|
17
|
+
staticBuild(): string;
|
|
16
18
|
}
|
package/dist/array.property.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export class ArrayProp {
|
|
2
2
|
name;
|
|
3
3
|
type;
|
|
4
|
+
isSpecial = false;
|
|
4
5
|
constructor(params) {
|
|
5
6
|
const { name, schemaObject, schemaName } = params;
|
|
6
7
|
this.name = this.treatName(name);
|
|
@@ -17,22 +18,36 @@ export class ArrayProp {
|
|
|
17
18
|
const { schemaObject, schemaName } = params;
|
|
18
19
|
let name = schemaName;
|
|
19
20
|
const teste = schemaObject.items;
|
|
20
|
-
if (teste
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (!teste)
|
|
22
|
+
return name;
|
|
23
|
+
if ("$ref" in teste) {
|
|
24
|
+
return teste.$ref.split("/").at(-1);
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
this.isSpecial = true;
|
|
27
|
+
return teste.type || "string";
|
|
25
28
|
}
|
|
26
29
|
constructorBuild() {
|
|
27
|
-
|
|
30
|
+
const result = this.isSpecial ? "" : `.map((param) => new ${this.type}(param))`;
|
|
31
|
+
return `this.${this.name} = params?.${this.name}${result} ?? []`;
|
|
28
32
|
}
|
|
29
33
|
classBuild() {
|
|
30
34
|
return `${this.name}: ${this.type}[]`;
|
|
31
35
|
}
|
|
32
36
|
interfaceBuild() {
|
|
33
|
-
|
|
37
|
+
const aType = this.isSpecial ? this.type : `${this.type}Interface`;
|
|
38
|
+
return `${this.name}: ${aType}[]`;
|
|
34
39
|
}
|
|
35
40
|
bundleBuild() {
|
|
36
|
-
|
|
41
|
+
const result = this.isSpecial ? "" : ".map((obj) => obj.bundle())";
|
|
42
|
+
return `${this.name}: this.${this.name}${result}`;
|
|
43
|
+
}
|
|
44
|
+
staticBuild() {
|
|
45
|
+
const result = this.isSpecial ? "obj" : `new ${this.type}(obj)`;
|
|
46
|
+
const aType = this.isSpecial ? this.type : `${this.type}Interface`;
|
|
47
|
+
return `
|
|
48
|
+
static from(data: ${aType}[]) {
|
|
49
|
+
return data.map((obj) => ${result});
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
37
52
|
}
|
|
38
53
|
}
|
package/dist/helpers/helpers.js
CHANGED
|
@@ -91,13 +91,19 @@ export function getEndpoint(rawEndpoint) {
|
|
|
91
91
|
return filteredEntitys.join("/");
|
|
92
92
|
}
|
|
93
93
|
export function getFullEndpoint(rawEndpoint) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.filter(
|
|
94
|
+
return rawEndpoint
|
|
95
|
+
.split("/")
|
|
96
|
+
.filter(Boolean)
|
|
97
97
|
.map((str) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
// pega somente params no formato "{algumaCoisa}"
|
|
99
|
+
const match = new RegExp(/^\{(.+)\}$/).exec(str);
|
|
100
|
+
if (match) {
|
|
101
|
+
const key = match[1]; // sem { }
|
|
102
|
+
return `\${paths.${key}}`; // gera "${paths.key}" como texto
|
|
103
|
+
}
|
|
104
|
+
return str;
|
|
105
|
+
})
|
|
106
|
+
.join("/");
|
|
101
107
|
}
|
|
102
108
|
export function treatenEnum(enums) {
|
|
103
109
|
const a = enums.map((e) => `"${e}"`);
|
package/dist/method.js
CHANGED
|
@@ -55,9 +55,9 @@ export class Method {
|
|
|
55
55
|
const paths = this.gee(this.paths);
|
|
56
56
|
const cookies = this.gee(this.cookies);
|
|
57
57
|
return `
|
|
58
|
-
${querys.length > 0 ? `const
|
|
59
|
-
${paths.length > 0 ? `const
|
|
60
|
-
${cookies.length > 0 ? `const
|
|
58
|
+
${querys.length > 0 ? `const querys = this.querys.bundle()` : ""};
|
|
59
|
+
${paths.length > 0 ? `const paths = this.paths.bundle()` : ""};
|
|
60
|
+
${cookies.length > 0 ? `const cookies = this.cookies.bundle()` : ""};
|
|
61
61
|
`;
|
|
62
62
|
}
|
|
63
63
|
buildCallMethod() {
|
|
@@ -66,7 +66,7 @@ export class Method {
|
|
|
66
66
|
const diamond = this.request.responseType ? `${this.request.responseType}Interface` : "null";
|
|
67
67
|
if (this.request.apiType === "get") {
|
|
68
68
|
if (this.request.attributeType === "list") {
|
|
69
|
-
beforeResponse.push(`const {data: { data }} = response`, "\n\n", `this.list = data`);
|
|
69
|
+
beforeResponse.push(`const {data: { data }} = response`, "\n\n", `this.list = ${this.request.responseType}.from(data)`);
|
|
70
70
|
const inside = `
|
|
71
71
|
const response = await repo.api.get<{data: ${diamond}}, unknown>({
|
|
72
72
|
endpoint,
|
|
@@ -130,7 +130,12 @@ export class Method {
|
|
|
130
130
|
// }
|
|
131
131
|
const description = this.buildDescription();
|
|
132
132
|
const a = "`";
|
|
133
|
-
const methodReturn =
|
|
133
|
+
const methodReturn = () => {
|
|
134
|
+
if (this.request.attributeType === "list") {
|
|
135
|
+
return "this.list";
|
|
136
|
+
}
|
|
137
|
+
return this.request.responseType ? `new ${this.request.responseType}(response)` : "null";
|
|
138
|
+
};
|
|
134
139
|
return `
|
|
135
140
|
${description}
|
|
136
141
|
async ${this.name}(behavior: Behavior = new Behavior()) {
|
|
@@ -144,7 +149,7 @@ export class Method {
|
|
|
144
149
|
${inside}
|
|
145
150
|
onSuccess?.()
|
|
146
151
|
|
|
147
|
-
return ${methodReturn}
|
|
152
|
+
return ${methodReturn()}
|
|
148
153
|
} catch(e) {
|
|
149
154
|
onError?.(e)
|
|
150
155
|
} finally {
|
|
@@ -7,7 +7,9 @@ export class PrimitiveProp {
|
|
|
7
7
|
buildedConst;
|
|
8
8
|
constructor(params) {
|
|
9
9
|
const { name, schemaObject, required } = params;
|
|
10
|
-
const { example, type } = schemaObject;
|
|
10
|
+
const { example: rawExample, type: rawType } = schemaObject;
|
|
11
|
+
const type = rawType ?? "string";
|
|
12
|
+
const example = rawExample ?? this.getEmptyExample({ type, schemaObject });
|
|
11
13
|
this.name = this.treatName(name);
|
|
12
14
|
this.rawType = type ?? "any";
|
|
13
15
|
this.type = `BuildedInput<${type}>`;
|
package/dist/property.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {} from "./types/open-api-spec.interface.js";
|
|
2
|
-
import {} from "./types/types.js";
|
|
1
|
+
// import { type ParameterLocation, type ReferenceObject, type SchemaObject } from "./types/open-api-spec.interface.js";
|
|
2
|
+
// import { type Example, type ReflectorParamType } from "./types/types.js";
|
|
3
|
+
export {};
|
|
3
4
|
// export class SchemaProp {
|
|
4
5
|
// inParam?: ParameterLocation | undefined;
|
|
5
6
|
// reflectorType: ReflectorParamType;
|
package/dist/schema.js
CHANGED
|
@@ -52,6 +52,7 @@ export class Schema {
|
|
|
52
52
|
const constructorThis = [];
|
|
53
53
|
const keys = [];
|
|
54
54
|
const bundleParams = [];
|
|
55
|
+
let staticMethod = "";
|
|
55
56
|
this.primitiveProps.forEach((prop) => {
|
|
56
57
|
constructorThis.push(prop.constructorBuild());
|
|
57
58
|
bundleParams.push(prop.bundleBuild());
|
|
@@ -61,6 +62,7 @@ export class Schema {
|
|
|
61
62
|
constructorThis.push(prop.constructorBuild());
|
|
62
63
|
keys.push(prop.classBuild());
|
|
63
64
|
bundleParams.push(prop.bundleBuild());
|
|
65
|
+
staticMethod = prop.staticBuild();
|
|
64
66
|
});
|
|
65
67
|
this.objectProps.forEach((prop) => {
|
|
66
68
|
constructorThis.push(prop.constructorBuild());
|
|
@@ -75,6 +77,8 @@ export class Schema {
|
|
|
75
77
|
${constructorThis.join(";\n")}
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
${staticMethod}
|
|
81
|
+
|
|
78
82
|
bundle(){
|
|
79
83
|
return { ${bundleParams.join(",")} }
|
|
80
84
|
}
|