svelte-reflector 1.0.2 → 1.0.3

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.
@@ -1,4 +1,4 @@
1
1
  import "dotenv/config";
2
2
  export declare function reflector(manual?: boolean): Promise<{
3
3
  name: string;
4
- } | undefined>;
4
+ }>;
@@ -53,12 +53,12 @@ export async function reflector(manual = false) {
53
53
  const { components, paths } = data;
54
54
  if (!components) {
55
55
  console.warn("[reflector] OpenAPI sem components; abortando.");
56
- return { name: "vite-plugin-generate-doc" };
56
+ return breakReflector();
57
57
  }
58
58
  const r = new Reflector({ components, paths });
59
59
  r.build();
60
60
  r.localSave(data);
61
- breakReflector();
61
+ return breakReflector();
62
62
  }
63
63
  function breakReflector() {
64
64
  return {
@@ -1,6 +1,7 @@
1
1
  export declare function stripState(attr: string): string;
2
2
  export declare function toCamelCase(str: string): string;
3
3
  export declare function sanitizeKey(name: string): string;
4
+ export declare function sanitizeNumber(texto: string): string;
4
5
  export declare function capitalizeFirstLetter(text: string): string;
5
6
  export declare function splitByUppercase(text: string): string[];
6
7
  export declare function createDangerMessage(text: string): void;
@@ -22,6 +22,9 @@ export function sanitizeKey(name) {
22
22
  }
23
23
  return toCamelCase(name);
24
24
  }
25
+ export function sanitizeNumber(texto) {
26
+ return texto.replace(/["']/g, "");
27
+ }
25
28
  export function capitalizeFirstLetter(text) {
26
29
  if (!text)
27
30
  return "";
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
3
  import { Source } from "./file.js";
4
- import { getEndpointAndModuleName } from "./helpers/helpers.js";
4
+ import { getEndpointAndModuleName, splitByUppercase } from "./helpers/helpers.js";
5
5
  import { Schema } from "./schema.js";
6
6
  import { Module } from "./module.js";
7
7
  const methods = ["get", "patch", "post", "put", "delete"];
@@ -12,7 +12,7 @@ export class Reflector {
12
12
  generatedDir = `${this.dir}/reflector`;
13
13
  localDoc = new Source({ path: path.resolve(process.cwd(), `${this.dir}/backup.json`) });
14
14
  src = new Source({ path: path.resolve(process.cwd(), this.generatedDir) });
15
- schemaFile = new Source({ path: path.resolve(process.cwd(), `${this.dir}/schemas.ts`) });
15
+ schemaFile = new Source({ path: path.resolve(process.cwd(), `${this.generatedDir}/schemas.ts`) });
16
16
  files;
17
17
  schemas;
18
18
  modules;
@@ -54,11 +54,14 @@ export class Reflector {
54
54
  if (!object[method])
55
55
  continue;
56
56
  operations.push({ ...object[method], apiMethod: method });
57
- const tags = object[method].tags;
58
- if (!entity && tags) {
59
- entity = tags.join("").split("/").join("");
57
+ if (!entity) {
58
+ const teste = object[method].operationId.split("_")[0];
59
+ const x = splitByUppercase(teste);
60
+ const aaa = x.filter((y) => y !== "Controller");
61
+ entity = aaa.join("");
60
62
  }
61
63
  }
64
+ // console.warn(entity)
62
65
  if (!entity)
63
66
  continue;
64
67
  const existingOps = methodsMap.get(entity);
package/dist/module.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
3
  import { Source } from "./file.js";
4
- import { capitalizeFirstLetter, createDangerMessage, stripState } from "./helpers/helpers.js";
4
+ import { capitalizeFirstLetter, stripState } from "./helpers/helpers.js";
5
5
  import { Method } from "./method.js";
6
6
  export class Module {
7
7
  name;
@@ -25,9 +25,9 @@ export class Module {
25
25
  });
26
26
  // não vão entrar metodos que não tiverem uma resposta tipada
27
27
  this.methods = methods.filter((op) => {
28
- if (!op.request.responseType) {
29
- createDangerMessage(`Método [ ${op.name} ] do módulo [ ${this.moduleName} ] sem tipagem na resposta.`);
30
- }
28
+ // if (!op.request.responseType) {
29
+ // createDangerMessage(`Método [ ${op.name} ] do módulo [ ${this.moduleName} ] sem tipagem na resposta.`);
30
+ // }
31
31
  return op.request.responseType;
32
32
  });
33
33
  this.parameters = this.getParameters();
@@ -54,7 +54,6 @@ export class Module {
54
54
  type: bodyType,
55
55
  });
56
56
  }
57
- // console.warn(method);
58
57
  console.warn(attributeType);
59
58
  if (attributeType === "entity") {
60
59
  moduleAtributes.add(`entity = $state<${responseType} | undefined>()`);
@@ -113,7 +112,7 @@ export class Module {
113
112
  const cleanEntries = Array.from(entries).filter((x) => x != "type any");
114
113
  if (cleanEntries.length === 0)
115
114
  return "";
116
- return `import { ${cleanEntries} } from '$api/schemas';`;
115
+ return `import { ${cleanEntries} } from '$reflector/schemas';`;
117
116
  }
118
117
  buildClass(modulesAttributes) {
119
118
  const initAssignments = modulesAttributes.map((attr) => `this.${stripState(attr)}`).join(";");
package/dist/property.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { sanitizeNumber } from "./helpers/helpers.js";
1
2
  import { ReflectorInput } from "./helpers/input.js";
2
3
  const inputs = new ReflectorInput();
3
4
  export class ZodProperty {
@@ -64,13 +65,14 @@ export class ZodProperty {
64
65
  return `${x}.default(${this.example})`;
65
66
  case "number": {
66
67
  const number = JSON.stringify(this.example) ?? 1;
67
- return `${x}.default(${number})`;
68
+ return `${x}.default(${sanitizeNumber(number)})`;
68
69
  }
69
70
  case "array": {
70
- if (!value.items || !("$ref" in value.items))
71
- return `${x}.default([])`;
71
+ if (!value.items || !("$ref" in value.items)) {
72
+ return `${this.name}: z.${this.type}(z.${value.items?.type || "string"}())${this.isNullable()}.default([])`;
73
+ }
72
74
  const dto = this.getDtoName(value.items.$ref);
73
- return `${this.name}: z.array(${dto}Schema).default(Array(10).fill(${dto}Schema.parse({})))`;
75
+ return `${this.name}: z.array(${dto}Schema).default(new Array(10).fill(${dto}Schema.parse({})))`;
74
76
  }
75
77
  case "object":
76
78
  return `${this.name}: z.any()`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",