svelte-reflector 1.0.8 → 1.0.9

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/method.d.ts CHANGED
@@ -14,5 +14,5 @@ export declare class Method {
14
14
  private getParams;
15
15
  private buildCallMethod;
16
16
  private buildDescription;
17
- build(): string | undefined;
17
+ build(): string;
18
18
  }
package/dist/method.js CHANGED
@@ -59,25 +59,27 @@ export class Method {
59
59
  }
60
60
  if (this.request.attributeType === "list") {
61
61
  beforeResponse.push(`const {data: { data }, ...params} = response`, "\n\n", `this.list = data`, `repo.intercept.rebuild(this.parameters, params)`);
62
- return `
62
+ const inside = `
63
63
  ${afterResponse.join(";")}
64
64
  const response = await repo.api.get<{data: ${this.request.responseType}}, unknown>({
65
- endpoint,
65
+ endpoint,
66
66
  ${query}
67
67
  })
68
68
  ${beforeResponse.join(";")}
69
69
  `;
70
+ return { inside, outside: "" };
70
71
  }
71
72
  else if (this.request.attributeType === "entity") {
72
73
  beforeResponse.push(`this.entity = response`);
73
- return `
74
+ const inside = `
74
75
  ${afterResponse.join(";")}
75
76
  const response = await repo.api.get<${this.request.responseType}, unknown>({
76
- endpoint,
77
+ endpoint,
77
78
  ${query}
78
79
  })
79
80
  ${beforeResponse.join(";")}
80
81
  `;
82
+ return { inside, outside: "" };
81
83
  }
82
84
  }
83
85
  else if (this.request.apiType === "post" || this.request.apiType === "put" || this.request.apiType === "patch") {
@@ -85,40 +87,38 @@ export class Method {
85
87
  if (this.request.bodyType) {
86
88
  data = `const data = repo.intercept.bundle(this.forms.${this.name})`;
87
89
  }
88
- return `
89
- ${data}
90
-
90
+ const outside = ["this.loading = true", data].join("\n");
91
+ const inside = `
91
92
  const response = await repo.api.post<${this.request.responseType}>({
92
93
  endpoint,
93
- ${data ? "data" : ""}
94
+ data
94
95
  })
95
96
  `;
97
+ return { outside, inside };
96
98
  }
97
99
  else if (this.request.apiType === "delete") {
98
100
  const props = this.zodProperties.map((x) => x.name).join(",");
99
101
  const propsString = props.length > 0 ? `const {${props}} = this.parameters` : "";
100
- return `
102
+ const inside = `
101
103
  ${propsString}
102
104
 
103
105
  const response = await repo.api.delete<${this.request.responseType ?? "null"}, unknown>({
104
- endpoint,
106
+ endpoint,
105
107
  ${query}
106
108
  })
107
109
 
108
110
  this.clearEntity()
109
111
  `;
112
+ const outside = "";
113
+ return { inside, outside };
110
114
  }
111
- return "";
115
+ return { inside: "", outside: "" };
112
116
  }
113
117
  buildDescription() {
114
118
  return `/** ${this.description ?? ""} */`;
115
119
  }
116
120
  build() {
117
- const content = this.buildCallMethod();
118
- if (!content) {
119
- createDangerMessage(`Método ${this.name} (${this.request.apiType}) não foi gerado: buildCallMethod vazio`);
120
- return;
121
- }
121
+ const { inside, outside } = this.buildCallMethod();
122
122
  if (this.name === "list")
123
123
  this.name = "listAll";
124
124
  const hasProprierties = this.zodProperties.length > 0;
@@ -132,8 +132,10 @@ export class Method {
132
132
  const {onError, onSuccess} = behavior
133
133
  const endpoint = "${getEndpoint(this.endpoint)}"
134
134
 
135
+ ${outside}
136
+
135
137
  try{
136
- ${content}
138
+ ${inside}
137
139
  onSuccess?.()
138
140
 
139
141
  return response
@@ -141,6 +143,8 @@ export class Method {
141
143
  } catch(e) {
142
144
  onError?.()
143
145
  }
146
+
147
+ this.loading = false
144
148
  }
145
149
  `;
146
150
  }
package/dist/module.js CHANGED
@@ -48,7 +48,7 @@ export class Module {
48
48
  }
49
49
  creator() {
50
50
  const buildedModuleTypes = [];
51
- const moduleAttributes = new Set();
51
+ const moduleAttributes = new Set().add("loading = $state<boolean>(false)");
52
52
  const moduleInit = new Set([]);
53
53
  const moduleClear = new Set([]);
54
54
  if (this.parameters.length > 0) {
@@ -175,7 +175,7 @@ export class Module {
175
175
 
176
176
  ${moduleClear.join("\n\n")}
177
177
 
178
- clearAll() {
178
+ reset() {
179
179
  ${moduleInit.join(";")}
180
180
  }
181
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",