svelte-reflector 1.0.28 → 1.0.31

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"));
@@ -110,16 +109,16 @@ export class Reflector {
110
109
  type ValidatorResult = string | null;
111
110
  type ValidatorFn<T> = (v: T) => ValidatorResult;
112
111
 
113
- export class Behavior { onError?: (e) => void; onSuccess?: () => void }
112
+ export class Behavior { onError?: (e) => void; onSuccess?: (v) => void }
114
113
 
115
114
  export class BuildedInput<T> {
116
115
  value = $state<T>(null as any);
117
116
  display = $state<T>(null as any);
118
117
  required: boolean;
119
118
  placeholder: T;
120
- private readonly validator?: ValidatorFn<T>;
119
+ readonly validator?: ValidatorFn<T>;
121
120
 
122
- constructor(params: { key?: T; example: T; required: boolean; validator?: ValidatorFn<T> }) {
121
+ constructor(params: { key?: T | undefined; example: T; required: boolean; validator?: ValidatorFn<T> }) {
123
122
  const { example, required, key, validator } = params;
124
123
 
125
124
  const initial = key ?? example;
@@ -141,7 +140,7 @@ export class Reflector {
141
140
  }
142
141
 
143
142
  export function build<T>(params: {
144
- key?: T;
143
+ key?: T | undefined;
145
144
  example: T;
146
145
  required: boolean;
147
146
  validator?: ValidatorFn<T>;
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(`this.list = ${this.request.responseType}.from(response.data)`);
72
+ const inside = `
73
+ ${response} await repo.api.get<${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,38 +125,38 @@ 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
 
148
153
  try{
149
154
  ${inside}
150
- onSuccess?.()
155
+ onSuccess?.(response)
151
156
 
152
- return ${methodReturn()}
157
+ return ${this.methodReturn()}
153
158
  } catch(e) {
154
- onError?.(e)
159
+ return onError?.(e)
155
160
  } finally {
156
161
  this.loading = false
157
162
  }
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
  }
@@ -36,7 +36,7 @@ export class PrimitiveProp {
36
36
  getEmptyExample(params) {
37
37
  const { schemaObject, type } = params;
38
38
  if (type === "number") {
39
- return 0;
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() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "1.0.28",
3
+ "version": "1.0.31",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",