svelte-reflector 1.0.50 → 1.0.52
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/helpers/helpers.d.ts +0 -1
- package/dist/helpers/helpers.js +13 -4
- package/dist/main.d.ts +2 -0
- package/dist/main.js +10 -0
- package/dist/props/array.property.js +1 -1
- package/dist/props/enum.property.d.ts +2 -0
- package/dist/props/enum.property.js +15 -4
- package/dist/props/object.property.js +2 -1
- package/dist/props/primitive.property.d.ts +3 -0
- package/dist/props/primitive.property.js +5 -0
- package/dist/schema.js +1 -1
- package/package.json +1 -1
|
@@ -13,4 +13,3 @@ export declare function getEndpointAndModuleName(rawEndpoint: string): {
|
|
|
13
13
|
};
|
|
14
14
|
export declare function getEndpoint(rawEndpoint: string): string;
|
|
15
15
|
export declare function getFullEndpoint(rawEndpoint: string): string;
|
|
16
|
-
export declare function treatenEnum(enums: string[]): string;
|
package/dist/helpers/helpers.js
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
const trashWords = new Set([
|
|
11
11
|
"Kyc",
|
|
12
12
|
"Get",
|
|
13
|
+
"Update",
|
|
14
|
+
"Close",
|
|
15
|
+
"Find",
|
|
16
|
+
"Change",
|
|
17
|
+
"List",
|
|
18
|
+
"Create",
|
|
13
19
|
"Customer",
|
|
14
20
|
"Response",
|
|
15
21
|
"Res",
|
|
@@ -17,7 +23,10 @@ const trashWords = new Set([
|
|
|
17
23
|
"Admin",
|
|
18
24
|
"Default",
|
|
19
25
|
"Owner",
|
|
26
|
+
"Repo",
|
|
27
|
+
"Formatted",
|
|
20
28
|
"Member",
|
|
29
|
+
"Dto",
|
|
21
30
|
"Public",
|
|
22
31
|
]);
|
|
23
32
|
export function toCamelCase(str) {
|
|
@@ -105,7 +114,7 @@ export function getFullEndpoint(rawEndpoint) {
|
|
|
105
114
|
})
|
|
106
115
|
.join("/");
|
|
107
116
|
}
|
|
108
|
-
export function treatenEnum(enums) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
117
|
+
// export function treatenEnum(enums: string[]) {
|
|
118
|
+
// const a = enums.map((e) => `"${e}"`);
|
|
119
|
+
// return ` z.literal([${a}])`;
|
|
120
|
+
// }
|
package/dist/main.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Schema } from "./schema.js";
|
|
|
3
3
|
import type { ComponentsObject, PathsObject, OpenAPIObject } from "./types/open-api-spec.interface.js";
|
|
4
4
|
import type { FieldValidators } from "./types/types.js";
|
|
5
5
|
import { Module } from "./module.js";
|
|
6
|
+
export declare const enumTypes: Map<string, string>;
|
|
6
7
|
export declare class Reflector {
|
|
7
8
|
readonly components: ComponentsObject;
|
|
8
9
|
readonly paths: PathsObject;
|
|
@@ -12,6 +13,7 @@ export declare class Reflector {
|
|
|
12
13
|
readonly typesSrc: Source;
|
|
13
14
|
readonly schemaFile: Source;
|
|
14
15
|
readonly fieldsFile: Source;
|
|
16
|
+
readonly enumFile: Source;
|
|
15
17
|
files: Source[];
|
|
16
18
|
schemas: Schema[];
|
|
17
19
|
modules: Module[];
|
package/dist/main.js
CHANGED
|
@@ -7,6 +7,7 @@ import { Module } from "./module.js";
|
|
|
7
7
|
import { baseDir, generatedDir } from "./vars.global.js";
|
|
8
8
|
import { ReflectorFile } from "./reflector.js";
|
|
9
9
|
// import { Module } from "./module.js";
|
|
10
|
+
export const enumTypes = new Map();
|
|
10
11
|
export class Reflector {
|
|
11
12
|
components;
|
|
12
13
|
paths;
|
|
@@ -16,6 +17,7 @@ export class Reflector {
|
|
|
16
17
|
typesSrc = new Source({ path: path.resolve(process.cwd(), `${generatedDir}/reflector.svelte.ts`) });
|
|
17
18
|
schemaFile = new Source({ path: path.resolve(process.cwd(), `${generatedDir}/schemas.svelte.ts`) });
|
|
18
19
|
fieldsFile = new Source({ path: path.resolve(process.cwd(), `${generatedDir}/fields.ts`) });
|
|
20
|
+
enumFile = new Source({ path: path.resolve(process.cwd(), `${generatedDir}/enums.ts`) });
|
|
19
21
|
files;
|
|
20
22
|
schemas;
|
|
21
23
|
modules;
|
|
@@ -103,6 +105,7 @@ export class Reflector {
|
|
|
103
105
|
this.schemaFile.changeData([
|
|
104
106
|
'import { build, BuildedInput } from "$reflector/reflector.svelte";',
|
|
105
107
|
'import { validateInputs } from "$lib/sanitizers/validateFormats";',
|
|
108
|
+
`import {${Array.from(enumTypes.values())}} from "$reflector/enums"`,
|
|
106
109
|
// ...Array.from(enums),
|
|
107
110
|
...treatedSchemas,
|
|
108
111
|
].join("\n\n"));
|
|
@@ -122,6 +125,13 @@ export class Reflector {
|
|
|
122
125
|
continue;
|
|
123
126
|
module.src.save();
|
|
124
127
|
}
|
|
128
|
+
const enumss = Array.from(enumTypes)
|
|
129
|
+
.map(([types, key]) => {
|
|
130
|
+
return `export enum ${key} { ${types} }`;
|
|
131
|
+
})
|
|
132
|
+
.join(";");
|
|
133
|
+
this.enumFile.changeData(enumss);
|
|
134
|
+
this.enumFile.save();
|
|
125
135
|
return {};
|
|
126
136
|
}
|
|
127
137
|
localSave(data) {
|
|
@@ -26,7 +26,7 @@ export class ArrayProp {
|
|
|
26
26
|
return schemaName;
|
|
27
27
|
if (items && !("$ref" in items) && items.enum) {
|
|
28
28
|
this.isPrimitiveType = true;
|
|
29
|
-
const enumType = new EnumProp({ enums: items.enum, name: this.name, required: true }).type;
|
|
29
|
+
const enumType = new EnumProp({ enums: items.enum, name: this.name, required: true, entityName: schemaName }).type;
|
|
30
30
|
return `(${enumType})`;
|
|
31
31
|
}
|
|
32
32
|
if ("$ref" in items) {
|
|
@@ -2,6 +2,7 @@ export declare class EnumProp {
|
|
|
2
2
|
name: string;
|
|
3
3
|
isParam: boolean;
|
|
4
4
|
readonly type: string;
|
|
5
|
+
enumName: string;
|
|
5
6
|
private readonly isRequired;
|
|
6
7
|
private readonly example;
|
|
7
8
|
constructor(params: {
|
|
@@ -9,6 +10,7 @@ export declare class EnumProp {
|
|
|
9
10
|
enums: string[];
|
|
10
11
|
required: boolean;
|
|
11
12
|
isParam?: boolean;
|
|
13
|
+
entityName: string;
|
|
12
14
|
});
|
|
13
15
|
classBuild(): string;
|
|
14
16
|
constructorBuild(): string;
|
|
@@ -1,27 +1,38 @@
|
|
|
1
|
+
import { splitByUppercase, treatByUppercase } from "../helpers/helpers.js";
|
|
2
|
+
import { enumTypes } from "../main.js";
|
|
1
3
|
export class EnumProp {
|
|
2
4
|
name;
|
|
3
5
|
isParam;
|
|
4
6
|
type;
|
|
7
|
+
enumName;
|
|
5
8
|
isRequired;
|
|
6
9
|
example;
|
|
7
10
|
constructor(params) {
|
|
8
|
-
const { name, required, isParam, enums } = params;
|
|
11
|
+
const { name, required, isParam, enums, entityName } = params;
|
|
9
12
|
this.name = name;
|
|
10
13
|
this.isParam = !!isParam;
|
|
11
14
|
this.isRequired = required;
|
|
12
15
|
this.type = enums.map((e) => `'${e}'`).join("|");
|
|
16
|
+
const types = enumTypes.get(enums.join(","));
|
|
17
|
+
if (!types) {
|
|
18
|
+
const teste = splitByUppercase(treatByUppercase(entityName)).map((x) => x.toUpperCase());
|
|
19
|
+
const naaa = `ENUM_${teste.join("_")}_${this.name.toUpperCase()}`.split("_");
|
|
20
|
+
const aaa = [...new Set(naaa)].join("_");
|
|
21
|
+
enumTypes.set(enums.join(","), aaa);
|
|
22
|
+
}
|
|
13
23
|
this.example = enums[0];
|
|
24
|
+
this.enumName = enumTypes.get(enums.join(",")) ?? "";
|
|
14
25
|
}
|
|
15
26
|
classBuild() {
|
|
16
27
|
const req = this.isRequired ? "" : "?";
|
|
17
|
-
return `${this.name}${req}: BuildedInput<${this.
|
|
28
|
+
return `${this.name}${req}: BuildedInput<${this.enumName}>`;
|
|
18
29
|
}
|
|
19
30
|
constructorBuild() {
|
|
20
|
-
return `this.${this.name} = build({ key: params?.data?.${this.name}, placeholder:
|
|
31
|
+
return `this.${this.name} = build({ key: params?.data?.${this.name}, placeholder: ${this.enumName}.${this.example}, example: ${this.enumName}.${this.example}, required: ${this.isRequired}})`;
|
|
21
32
|
}
|
|
22
33
|
interfaceBuild() {
|
|
23
34
|
const req = this.isRequired ? "" : "?";
|
|
24
|
-
return `${this.name}${req}: ${this.
|
|
35
|
+
return `${this.name}${req}: ${this.enumName}`;
|
|
25
36
|
}
|
|
26
37
|
bundleBuild() {
|
|
27
38
|
return `${this.name}: this.${this.name}?.value`;
|
|
@@ -19,7 +19,8 @@ export class ObjectProp {
|
|
|
19
19
|
classBuild() {
|
|
20
20
|
const req = this.required ? "" : "?";
|
|
21
21
|
const nullable = this.isNullable ? "| null" : "";
|
|
22
|
-
|
|
22
|
+
const defaultVar = this.isNullable ? "null" : `new ${this.type}`;
|
|
23
|
+
return `${this.name}${req} = $state<${this.type} ${nullable}>(${defaultVar})`;
|
|
23
24
|
}
|
|
24
25
|
interfaceBuild() {
|
|
25
26
|
const req = this.required ? "" : "?";
|
|
@@ -100,3 +100,8 @@ export class PrimitiveProp {
|
|
|
100
100
|
return `${this.name}: ${this.thisDot()}${this.name}?.value`;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
export class PrimitivePropParam extends PrimitiveProp {
|
|
104
|
+
classBuild() {
|
|
105
|
+
return `${this.name} = $derived.by(() => page.params.${this.name})`;
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/schema.js
CHANGED
|
@@ -95,7 +95,7 @@ export class Schema {
|
|
|
95
95
|
continue;
|
|
96
96
|
}
|
|
97
97
|
else if (value.enum) {
|
|
98
|
-
this.enumProps.push(new EnumProp({ enums: value.enum, name, required }));
|
|
98
|
+
this.enumProps.push(new EnumProp({ enums: value.enum, name, required, entityName: schemaName }));
|
|
99
99
|
continue;
|
|
100
100
|
}
|
|
101
101
|
const validator = validators.get(key);
|