svelte-reflector 1.0.28 → 1.0.30

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 CHANGED
@@ -101,7 +101,6 @@ export class Reflector {
101
101
  });
102
102
  this.schemaFile.changeData([
103
103
  'import { build, BuildedInput } from "$reflector/reflector.svelte";',
104
- 'import { validateInputs } from "$lib/sanitizers/validateFormats";',
105
104
  // ...Array.from(enums),
106
105
  ...treatedSchemas,
107
106
  ].join("\n\n"));
package/dist/method.d.ts CHANGED
@@ -5,6 +5,7 @@ export declare class Method {
5
5
  name: string;
6
6
  description: string | undefined;
7
7
  endpoint: string;
8
+ isValid: boolean;
8
9
  request: Request;
9
10
  paths: PrimitiveProp[];
10
11
  headers: PrimitiveProp[];
@@ -18,6 +19,7 @@ export declare class Method {
18
19
  private readonly gee;
19
20
  private getProps;
20
21
  private buildCallMethod;
22
+ private readonly methodReturn;
21
23
  build(): string;
22
24
  private buildDescription;
23
25
  }
package/dist/method.js CHANGED
@@ -6,6 +6,7 @@ export class Method {
6
6
  // zodProperties: Property[];
7
7
  description;
8
8
  endpoint;
9
+ isValid = true;
9
10
  request;
10
11
  paths = [];
11
12
  headers = [];
@@ -62,31 +63,35 @@ export class Method {
62
63
  }
63
64
  buildCallMethod() {
64
65
  const beforeResponse = [];
65
- // const props = this.getProps();
66
- const diamond = this.request.responseType ? `${this.request.responseType}Interface` : "null";
67
- if (this.request.apiType === "get") {
68
- if (this.request.attributeType === "list") {
69
- beforeResponse.push(`const {data: { data }} = response`, "\n\n", `this.list = ${this.request.responseType}.from(data)`);
70
- const inside = `
71
- const response = await repo.api.get<{data: ${diamond}}, unknown>({
66
+ const preBuild = () => {
67
+ return this.request.responseType ? [`${this.request.responseType}Interface`, "const response ="] : ["null", ""];
68
+ };
69
+ const [diamond, response] = preBuild();
70
+ if (this.request.attributeType === "list") {
71
+ beforeResponse.push(`const {data: { data }} = response`, "\n\n", `this.list = ${this.request.responseType}.from(data)`);
72
+ const inside = `
73
+ ${response} await repo.api.get<{data: ${diamond}}, unknown>({
72
74
  endpoint,
73
75
  queryData: { ${this.gee(this.querys)} }
74
76
  })
75
77
  ${beforeResponse.join(";")}
76
78
  `;
77
- return { inside, outside: "" };
78
- }
79
- else if (this.request.attributeType === "entity") {
80
- const entityName = treatByUppercase(this.request.responseType ?? "");
79
+ return { inside, outside: "" };
80
+ }
81
+ else if (this.request.attributeType === "entity") {
82
+ if (this.request.responseType) {
83
+ const entityName = treatByUppercase(this.request.responseType);
81
84
  beforeResponse.push(`this.${entityName} = new ${this.request.responseType}(response)`);
82
- const inside = `
83
- const response = await repo.api.get<${diamond}, unknown>({
85
+ }
86
+ let querys = this.querys.length > 0 ? `queryData: {${this.querys.map((q) => q.name).join(",")}}` : "";
87
+ const inside = `
88
+ ${response} await repo.api.get<${diamond}, unknown>({
84
89
  endpoint,
90
+ ${querys}
85
91
  })
86
92
  ${beforeResponse.join(";")}
87
93
  `;
88
- return { inside, outside: "" };
89
- }
94
+ return { inside, outside: "" };
90
95
  }
91
96
  else if (this.request.apiType === "post" || this.request.apiType === "put" || this.request.apiType === "patch") {
92
97
  let data;
@@ -101,7 +106,7 @@ export class Method {
101
106
  }
102
107
  const outside = ["this.loading = true", data, headers].join("\n");
103
108
  const inside = `
104
- const response = await repo.api.${this.request.apiType}<${diamond}>({
109
+ ${response} await repo.api.${this.request.apiType}<${diamond}>({
105
110
  endpoint,
106
111
  ${hasData ? "data," : ""}
107
112
  ${hasHeaders ? "headers," : ""}
@@ -111,7 +116,7 @@ export class Method {
111
116
  }
112
117
  else if (this.request.apiType === "delete") {
113
118
  const inside = `
114
- const response = await repo.api.delete<${diamond}, unknown>({
119
+ ${response} await repo.api.delete<${diamond}, unknown>({
115
120
  endpoint,
116
121
  })
117
122
  `;
@@ -120,28 +125,28 @@ export class Method {
120
125
  }
121
126
  return { inside: "", outside: "" };
122
127
  }
128
+ methodReturn = () => {
129
+ if (this.request.attributeType === "list") {
130
+ return "this.list";
131
+ }
132
+ if (!this.request.responseType) {
133
+ // this.isValid = false;
134
+ }
135
+ return this.request.responseType ? `new ${this.request.responseType}(response)` : "null";
136
+ };
123
137
  build() {
124
138
  const { inside, outside } = this.buildCallMethod();
125
139
  if (this.name === "list")
126
140
  this.name = "listAll";
127
- // const hasProprierties = this.querys.length > 0;
128
- // if (!hasProprierties && this.request.apiType === "delete") {
129
- // createDangerMessage(`${this.name} não vai funcionar, pois não aceita parâmetros na requisição.`);
130
- // }
131
141
  const description = this.buildDescription();
132
142
  const a = "`";
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
- };
143
+ const endpoint = `${a}${getFullEndpoint(this.endpoint)}${a}`;
139
144
  return `
140
145
  ${description}
141
146
  async ${this.name}(behavior: Behavior = new Behavior()) {
142
147
  const {onError, onSuccess} = behavior
143
148
  ${this.getProps()}
144
- const endpoint = ${a}${getFullEndpoint(this.endpoint)}${a}
149
+ const endpoint = ${endpoint}
145
150
 
146
151
  ${outside}
147
152
 
@@ -149,7 +154,7 @@ export class Method {
149
154
  ${inside}
150
155
  onSuccess?.()
151
156
 
152
- return ${methodReturn()}
157
+ return ${this.methodReturn()}
153
158
  } catch(e) {
154
159
  onError?.(e)
155
160
  } finally {
package/dist/module.js CHANGED
@@ -86,6 +86,11 @@ export class Module {
86
86
  moduleClear.add(`clear${capitalizedName}() { this.${name} = new ${capitalizedName}() }`);
87
87
  };
88
88
  if (querys.length > 0) {
89
+ querys.forEach((q) => {
90
+ if (q.name === "permissions") {
91
+ // console.log(q);
92
+ }
93
+ });
89
94
  getParams({ name: "querys", props: querys });
90
95
  }
91
96
  if (headers.length > 0) {
@@ -100,6 +105,10 @@ export class Module {
100
105
  const form = [];
101
106
  for (const method of this.methods) {
102
107
  const { bodyType, responseType, attributeType } = method.request;
108
+ // if (!method.isValid) {
109
+ // console.log(`Método ${method.name} não foi adicionado devido à falta de tipagem na resposta`)
110
+ // continue;
111
+ // }
103
112
  if (attributeType === "form" && bodyType) {
104
113
  form.push({
105
114
  name: method.name,
@@ -216,6 +225,11 @@ export class Module {
216
225
  }
217
226
  buildClass(params) {
218
227
  const { moduleInit, moduleAttributes, moduleClear } = params;
228
+ const reset = moduleAttributes.length > 1
229
+ ? `reset() {
230
+ ${moduleInit.join(";")}
231
+ }`
232
+ : "";
219
233
  return `
220
234
  export class ${this.moduleName}Module {
221
235
  ${moduleAttributes.join(";")}
@@ -226,9 +240,7 @@ export class Module {
226
240
 
227
241
  ${moduleClear.join("\n\n")}
228
242
 
229
- reset() {
230
- ${moduleInit.join(";")}
231
- }
243
+ ${reset}
232
244
  }
233
245
  `;
234
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",