@hedystia/types 1.10.1 → 1.10.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.
@@ -0,0 +1,27 @@
1
+
2
+ $ tsdown --config-loader unrun
3
+ ℹ tsdown v0.21.2 powered by rolldown v1.0.0-rc.9
4
+ ℹ config file: /home/zastinian/Documents/codes/Framework/Packages/types/tsdown.config.ts (unrun)
5
+ ℹ entry: src/index.ts
6
+ ℹ tsconfig: tsconfig.json
7
+ ℹ Build start
8
+ ℹ Cleaning 14 files
9
+ ℹ [CJS] dist/index.cjs 1.22 kB │ gzip: 0.52 kB
10
+ ℹ [CJS] dist/utils.cjs.map 4.09 kB │ gzip: 1.34 kB
11
+ ℹ [CJS] dist/utils.cjs 2.25 kB │ gzip: 0.74 kB
12
+ ℹ [CJS] dist/index.cjs.map 1.86 kB │ gzip: 0.75 kB
13
+ ℹ [CJS] 4 files, total: 9.42 kB
14
+ ℹ [CJS] dist/index.d.cts 0.36 kB │ gzip: 0.23 kB
15
+ ℹ [CJS] dist/types.d.cts 0.41 kB │ gzip: 0.24 kB
16
+ ℹ [CJS] dist/utils.d.cts 0.16 kB │ gzip: 0.14 kB
17
+ ℹ [CJS] 3 files, total: 0.94 kB
18
+ ✔ Build complete in 774ms
19
+ ℹ [ESM] dist/index.mjs 0.98 kB │ gzip: 0.44 kB
20
+ ℹ [ESM] dist/utils.mjs.map 3.80 kB │ gzip: 1.28 kB
21
+ ℹ [ESM] dist/utils.mjs 2.13 kB │ gzip: 0.77 kB
22
+ ℹ [ESM] dist/index.mjs.map 1.78 kB │ gzip: 0.74 kB
23
+ ℹ [ESM] dist/index.d.mts 0.36 kB │ gzip: 0.23 kB
24
+ ℹ [ESM] dist/types.d.mts 0.41 kB │ gzip: 0.24 kB
25
+ ℹ [ESM] dist/utils.d.mts 0.16 kB │ gzip: 0.14 kB
26
+ ℹ [ESM] 7 files, total: 9.63 kB
27
+ ✔ Build complete in 779ms
package/dist/index.cjs ADDED
@@ -0,0 +1,21 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_utils = require("./utils.cjs");
3
+ let fs_promises = require("fs/promises");
4
+ //#region src/index.ts
5
+ async function generateTypes(routes, filePath) {
6
+ await (0, fs_promises.writeFile)(filePath, `// Automatic Hedystia type generation\nexport type AppRoutes=[${routes.map((route) => {
7
+ const responseType = require_utils.schemaToTypeString(route.response);
8
+ const paramsType = require_utils.schemaToTypeString(route.params);
9
+ const queryType = require_utils.schemaToTypeString(route.query);
10
+ const bodyType = require_utils.schemaToTypeString(route.body);
11
+ const headersType = require_utils.schemaToTypeString(route.headers);
12
+ const dataType = require_utils.schemaToTypeString(route.data);
13
+ const errorType = require_utils.schemaToTypeString(route.error);
14
+ return `{method:"${route.method}";path:"${route.path}";params:${paramsType};query:${queryType};body:${bodyType};headers:${headersType};response:${responseType};data:${dataType};error:${errorType}}`;
15
+ }).join(",")}];`, "utf8");
16
+ }
17
+ //#endregion
18
+ exports.generateTypes = generateTypes;
19
+ exports.schemaToTypeString = require_utils.schemaToTypeString;
20
+
21
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["schemaToTypeString"],"sources":["../src/index.ts"],"sourcesContent":["import { writeFile } from \"fs/promises\";\nimport type { RouteInfo } from \"./types\";\nimport { schemaToTypeString } from \"./utils\";\n\nexport async function generateTypes(routes: RouteInfo[], filePath: string): Promise<void> {\n const typeDefinitions = routes\n .map((route) => {\n const responseType = schemaToTypeString(route.response);\n const paramsType = schemaToTypeString(route.params);\n const queryType = schemaToTypeString(route.query);\n const bodyType = schemaToTypeString(route.body);\n const headersType = schemaToTypeString(route.headers);\n const dataType = schemaToTypeString(route.data);\n const errorType = schemaToTypeString(route.error);\n return `{method:\"${route.method}\";path:\"${route.path}\";params:${paramsType};query:${queryType};body:${bodyType};headers:${headersType};response:${responseType};data:${dataType};error:${errorType}}`;\n })\n .join(\",\");\n\n const content = `// Automatic Hedystia type generation\\nexport type AppRoutes=[${typeDefinitions}];`;\n await writeFile(filePath, content, \"utf8\");\n}\nexport type { TypeGeneratorOptions } from \"./types\";\nexport type { RouteInfo };\nexport { schemaToTypeString };\n"],"mappings":";;;;AAIA,eAAsB,cAAc,QAAqB,UAAiC;AAexF,QAAA,GAAA,YAAA,WAAgB,UADA,iEAbQ,OACrB,KAAK,UAAU;EACd,MAAM,eAAeA,cAAAA,mBAAmB,MAAM,SAAS;EACvD,MAAM,aAAaA,cAAAA,mBAAmB,MAAM,OAAO;EACnD,MAAM,YAAYA,cAAAA,mBAAmB,MAAM,MAAM;EACjD,MAAM,WAAWA,cAAAA,mBAAmB,MAAM,KAAK;EAC/C,MAAM,cAAcA,cAAAA,mBAAmB,MAAM,QAAQ;EACrD,MAAM,WAAWA,cAAAA,mBAAmB,MAAM,KAAK;EAC/C,MAAM,YAAYA,cAAAA,mBAAmB,MAAM,MAAM;AACjD,SAAO,YAAY,MAAM,OAAO,UAAU,MAAM,KAAK,WAAW,WAAW,SAAS,UAAU,QAAQ,SAAS,WAAW,YAAY,YAAY,aAAa,QAAQ,SAAS,SAAS,UAAU;GACnM,CACD,KAAK,IAAI,CAEqF,KAC9D,OAAO"}
@@ -0,0 +1,8 @@
1
+ import { RouteInfo, TypeGeneratorOptions } from "./types.cjs";
2
+ import { schemaToTypeString } from "./utils.cjs";
3
+
4
+ //#region src/index.d.ts
5
+ declare function generateTypes(routes: RouteInfo[], filePath: string): Promise<void>;
6
+ //#endregion
7
+ export { type RouteInfo, type TypeGeneratorOptions, generateTypes, schemaToTypeString };
8
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,8 @@
1
+ import { RouteInfo, TypeGeneratorOptions } from "./types.mjs";
2
+ import { schemaToTypeString } from "./utils.mjs";
3
+
4
+ //#region src/index.d.ts
5
+ declare function generateTypes(routes: RouteInfo[], filePath: string): Promise<void>;
6
+ //#endregion
7
+ export { type RouteInfo, type TypeGeneratorOptions, generateTypes, schemaToTypeString };
8
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,19 @@
1
+ import { schemaToTypeString } from "./utils.mjs";
2
+ import { writeFile } from "fs/promises";
3
+ //#region src/index.ts
4
+ async function generateTypes(routes, filePath) {
5
+ await writeFile(filePath, `// Automatic Hedystia type generation\nexport type AppRoutes=[${routes.map((route) => {
6
+ const responseType = schemaToTypeString(route.response);
7
+ const paramsType = schemaToTypeString(route.params);
8
+ const queryType = schemaToTypeString(route.query);
9
+ const bodyType = schemaToTypeString(route.body);
10
+ const headersType = schemaToTypeString(route.headers);
11
+ const dataType = schemaToTypeString(route.data);
12
+ const errorType = schemaToTypeString(route.error);
13
+ return `{method:"${route.method}";path:"${route.path}";params:${paramsType};query:${queryType};body:${bodyType};headers:${headersType};response:${responseType};data:${dataType};error:${errorType}}`;
14
+ }).join(",")}];`, "utf8");
15
+ }
16
+ //#endregion
17
+ export { generateTypes, schemaToTypeString };
18
+
19
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { writeFile } from \"fs/promises\";\nimport type { RouteInfo } from \"./types\";\nimport { schemaToTypeString } from \"./utils\";\n\nexport async function generateTypes(routes: RouteInfo[], filePath: string): Promise<void> {\n const typeDefinitions = routes\n .map((route) => {\n const responseType = schemaToTypeString(route.response);\n const paramsType = schemaToTypeString(route.params);\n const queryType = schemaToTypeString(route.query);\n const bodyType = schemaToTypeString(route.body);\n const headersType = schemaToTypeString(route.headers);\n const dataType = schemaToTypeString(route.data);\n const errorType = schemaToTypeString(route.error);\n return `{method:\"${route.method}\";path:\"${route.path}\";params:${paramsType};query:${queryType};body:${bodyType};headers:${headersType};response:${responseType};data:${dataType};error:${errorType}}`;\n })\n .join(\",\");\n\n const content = `// Automatic Hedystia type generation\\nexport type AppRoutes=[${typeDefinitions}];`;\n await writeFile(filePath, content, \"utf8\");\n}\nexport type { TypeGeneratorOptions } from \"./types\";\nexport type { RouteInfo };\nexport { schemaToTypeString };\n"],"mappings":";;;AAIA,eAAsB,cAAc,QAAqB,UAAiC;AAexF,OAAM,UAAU,UADA,iEAbQ,OACrB,KAAK,UAAU;EACd,MAAM,eAAe,mBAAmB,MAAM,SAAS;EACvD,MAAM,aAAa,mBAAmB,MAAM,OAAO;EACnD,MAAM,YAAY,mBAAmB,MAAM,MAAM;EACjD,MAAM,WAAW,mBAAmB,MAAM,KAAK;EAC/C,MAAM,cAAc,mBAAmB,MAAM,QAAQ;EACrD,MAAM,WAAW,mBAAmB,MAAM,KAAK;EAC/C,MAAM,YAAY,mBAAmB,MAAM,MAAM;AACjD,SAAO,YAAY,MAAM,OAAO,UAAU,MAAM,KAAK,WAAW,WAAW,SAAS,UAAU,QAAQ,SAAS,WAAW,YAAY,YAAY,aAAa,QAAQ,SAAS,SAAS,UAAU;GACnM,CACD,KAAK,IAAI,CAEqF,KAC9D,OAAO"}
@@ -0,0 +1,19 @@
1
+ //#region src/types.d.ts
2
+ interface RouteInfo {
3
+ method: string;
4
+ path: string;
5
+ params?: unknown;
6
+ query?: unknown;
7
+ headers?: unknown;
8
+ body?: unknown;
9
+ response?: unknown;
10
+ data?: unknown;
11
+ error?: unknown;
12
+ }
13
+ type TypeGeneratorOptions = {
14
+ includeSubscriptions?: boolean;
15
+ includeWebSocket?: boolean;
16
+ };
17
+ //#endregion
18
+ export { RouteInfo, TypeGeneratorOptions };
19
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1,19 @@
1
+ //#region src/types.d.ts
2
+ interface RouteInfo {
3
+ method: string;
4
+ path: string;
5
+ params?: unknown;
6
+ query?: unknown;
7
+ headers?: unknown;
8
+ body?: unknown;
9
+ response?: unknown;
10
+ data?: unknown;
11
+ error?: unknown;
12
+ }
13
+ type TypeGeneratorOptions = {
14
+ includeSubscriptions?: boolean;
15
+ includeWebSocket?: boolean;
16
+ };
17
+ //#endregion
18
+ export { RouteInfo, TypeGeneratorOptions };
19
+ //# sourceMappingURL=types.d.mts.map
package/dist/utils.cjs ADDED
@@ -0,0 +1,50 @@
1
+ let _hedystia_validations = require("@hedystia/validations");
2
+ //#region src/utils.ts
3
+ function schemaToTypeString(schema) {
4
+ if (!schema) return "any";
5
+ if (schema instanceof _hedystia_validations.StringSchemaType) return "string";
6
+ if (schema instanceof _hedystia_validations.NumberSchemaType) return "number";
7
+ if (schema instanceof _hedystia_validations.BooleanSchemaType) return "boolean";
8
+ if (schema instanceof _hedystia_validations.NullSchemaType) return "null";
9
+ if (schema instanceof _hedystia_validations.AnySchemaType) return "any";
10
+ if (schema instanceof _hedystia_validations.OptionalSchema) {
11
+ const inner = schema.innerSchema;
12
+ return `${schemaToTypeString(inner)} | undefined`;
13
+ }
14
+ if (schema instanceof _hedystia_validations.ArraySchema) {
15
+ const inner = schema.innerSchema;
16
+ const innerType = schemaToTypeString(inner);
17
+ return innerType.includes("|") || innerType.includes("{") ? `(${innerType})[]` : `${innerType}[]`;
18
+ }
19
+ if (schema instanceof _hedystia_validations.UnionSchema) {
20
+ const schemas = schema.schemas || [];
21
+ if (schemas.length === 0) return "any";
22
+ return schemas.map((s) => schemaToTypeString(s)).join(" | ");
23
+ }
24
+ if (schema instanceof _hedystia_validations.LiteralSchema) {
25
+ const val = schema.value;
26
+ return typeof val === "string" ? `'${val}'` : String(val);
27
+ }
28
+ if (schema instanceof _hedystia_validations.InstanceOfSchema) {
29
+ const ctor = schema.classConstructor;
30
+ return ctor ? ctor.name : "object";
31
+ }
32
+ if (schema instanceof _hedystia_validations.ObjectSchemaType) {
33
+ const definition = schema.definition;
34
+ if (!definition || Object.keys(definition).length === 0) return "{}";
35
+ const validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
36
+ return `{${Object.entries(definition).map(([key, value]) => {
37
+ const finalKey = validIdentifierRegex.test(key) ? key : `"${key}"`;
38
+ const isOptional = value instanceof _hedystia_validations.OptionalSchema;
39
+ const optionalMarker = isOptional ? "?" : "";
40
+ let typeStr = schemaToTypeString(value);
41
+ if (isOptional) typeStr = typeStr.replace(" | undefined", "");
42
+ return `${finalKey}${optionalMarker}:${typeStr}`;
43
+ }).join(";")}}`;
44
+ }
45
+ return "any";
46
+ }
47
+ //#endregion
48
+ exports.schemaToTypeString = schemaToTypeString;
49
+
50
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","names":["StringSchemaType","NumberSchemaType","BooleanSchemaType","NullSchemaType","AnySchemaType","OptionalSchema","ArraySchema","UnionSchema","LiteralSchema","InstanceOfSchema","ObjectSchemaType"],"sources":["../src/utils.ts"],"sourcesContent":["import {\n AnySchemaType,\n ArraySchema,\n BooleanSchemaType,\n InstanceOfSchema,\n LiteralSchema,\n NullSchemaType,\n NumberSchemaType,\n ObjectSchemaType,\n OptionalSchema,\n StringSchemaType,\n UnionSchema,\n} from \"@hedystia/validations\";\n\nexport function schemaToTypeString(schema: any): string {\n if (!schema) {\n return \"any\";\n }\n\n if (schema instanceof StringSchemaType) {\n return \"string\";\n }\n if (schema instanceof NumberSchemaType) {\n return \"number\";\n }\n if (schema instanceof BooleanSchemaType) {\n return \"boolean\";\n }\n if (schema instanceof NullSchemaType) {\n return \"null\";\n }\n if (schema instanceof AnySchemaType) {\n return \"any\";\n }\n\n if (schema instanceof OptionalSchema) {\n const inner = (schema as any).innerSchema;\n return `${schemaToTypeString(inner)} | undefined`;\n }\n\n if (schema instanceof ArraySchema) {\n const inner = (schema as any).innerSchema;\n const innerType = schemaToTypeString(inner);\n return innerType.includes(\"|\") || innerType.includes(\"{\")\n ? `(${innerType})[]`\n : `${innerType}[]`;\n }\n\n if (schema instanceof UnionSchema) {\n const schemas = (schema as any).schemas || [];\n if (schemas.length === 0) {\n return \"any\";\n }\n return schemas.map((s: any) => schemaToTypeString(s)).join(\" | \");\n }\n\n if (schema instanceof LiteralSchema) {\n const val = (schema as any).value;\n return typeof val === \"string\" ? `'${val}'` : String(val);\n }\n\n if (schema instanceof InstanceOfSchema) {\n const ctor = (schema as any).classConstructor;\n return ctor ? ctor.name : \"object\";\n }\n\n if (schema instanceof ObjectSchemaType) {\n const definition = (schema as any).definition;\n if (!definition || Object.keys(definition).length === 0) {\n return \"{}\";\n }\n\n const validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n const properties = Object.entries(definition)\n .map(([key, value]) => {\n const finalKey = validIdentifierRegex.test(key) ? key : `\"${key}\"`;\n const isOptional = value instanceof OptionalSchema;\n const optionalMarker = isOptional ? \"?\" : \"\";\n\n let typeStr = schemaToTypeString(value);\n\n if (isOptional) {\n typeStr = typeStr.replace(\" | undefined\", \"\");\n }\n\n return `${finalKey}${optionalMarker}:${typeStr}`;\n })\n .join(\";\");\n\n return `{${properties}}`;\n }\n\n return \"any\";\n}\n"],"mappings":";;AAcA,SAAgB,mBAAmB,QAAqB;AACtD,KAAI,CAAC,OACH,QAAO;AAGT,KAAI,kBAAkBA,sBAAAA,iBACpB,QAAO;AAET,KAAI,kBAAkBC,sBAAAA,iBACpB,QAAO;AAET,KAAI,kBAAkBC,sBAAAA,kBACpB,QAAO;AAET,KAAI,kBAAkBC,sBAAAA,eACpB,QAAO;AAET,KAAI,kBAAkBC,sBAAAA,cACpB,QAAO;AAGT,KAAI,kBAAkBC,sBAAAA,gBAAgB;EACpC,MAAM,QAAS,OAAe;AAC9B,SAAO,GAAG,mBAAmB,MAAM,CAAC;;AAGtC,KAAI,kBAAkBC,sBAAAA,aAAa;EACjC,MAAM,QAAS,OAAe;EAC9B,MAAM,YAAY,mBAAmB,MAAM;AAC3C,SAAO,UAAU,SAAS,IAAI,IAAI,UAAU,SAAS,IAAI,GACrD,IAAI,UAAU,OACd,GAAG,UAAU;;AAGnB,KAAI,kBAAkBC,sBAAAA,aAAa;EACjC,MAAM,UAAW,OAAe,WAAW,EAAE;AAC7C,MAAI,QAAQ,WAAW,EACrB,QAAO;AAET,SAAO,QAAQ,KAAK,MAAW,mBAAmB,EAAE,CAAC,CAAC,KAAK,MAAM;;AAGnE,KAAI,kBAAkBC,sBAAAA,eAAe;EACnC,MAAM,MAAO,OAAe;AAC5B,SAAO,OAAO,QAAQ,WAAW,IAAI,IAAI,KAAK,OAAO,IAAI;;AAG3D,KAAI,kBAAkBC,sBAAAA,kBAAkB;EACtC,MAAM,OAAQ,OAAe;AAC7B,SAAO,OAAO,KAAK,OAAO;;AAG5B,KAAI,kBAAkBC,sBAAAA,kBAAkB;EACtC,MAAM,aAAc,OAAe;AACnC,MAAI,CAAC,cAAc,OAAO,KAAK,WAAW,CAAC,WAAW,EACpD,QAAO;EAGT,MAAM,uBAAuB;AAiB7B,SAAO,IAhBY,OAAO,QAAQ,WAAW,CAC1C,KAAK,CAAC,KAAK,WAAW;GACrB,MAAM,WAAW,qBAAqB,KAAK,IAAI,GAAG,MAAM,IAAI,IAAI;GAChE,MAAM,aAAa,iBAAiBL,sBAAAA;GACpC,MAAM,iBAAiB,aAAa,MAAM;GAE1C,IAAI,UAAU,mBAAmB,MAAM;AAEvC,OAAI,WACF,WAAU,QAAQ,QAAQ,gBAAgB,GAAG;AAG/C,UAAO,GAAG,WAAW,eAAe,GAAG;IACvC,CACD,KAAK,IAAI,CAEU;;AAGxB,QAAO"}
@@ -0,0 +1,5 @@
1
+ //#region src/utils.d.ts
2
+ declare function schemaToTypeString(schema: any): string;
3
+ //#endregion
4
+ export { schemaToTypeString };
5
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1,5 @@
1
+ //#region src/utils.d.ts
2
+ declare function schemaToTypeString(schema: any): string;
3
+ //#endregion
4
+ export { schemaToTypeString };
5
+ //# sourceMappingURL=utils.d.mts.map
package/dist/utils.mjs ADDED
@@ -0,0 +1,50 @@
1
+ import { AnySchemaType, ArraySchema, BooleanSchemaType, InstanceOfSchema, LiteralSchema, NullSchemaType, NumberSchemaType, ObjectSchemaType, OptionalSchema, StringSchemaType, UnionSchema } from "@hedystia/validations";
2
+ //#region src/utils.ts
3
+ function schemaToTypeString(schema) {
4
+ if (!schema) return "any";
5
+ if (schema instanceof StringSchemaType) return "string";
6
+ if (schema instanceof NumberSchemaType) return "number";
7
+ if (schema instanceof BooleanSchemaType) return "boolean";
8
+ if (schema instanceof NullSchemaType) return "null";
9
+ if (schema instanceof AnySchemaType) return "any";
10
+ if (schema instanceof OptionalSchema) {
11
+ const inner = schema.innerSchema;
12
+ return `${schemaToTypeString(inner)} | undefined`;
13
+ }
14
+ if (schema instanceof ArraySchema) {
15
+ const inner = schema.innerSchema;
16
+ const innerType = schemaToTypeString(inner);
17
+ return innerType.includes("|") || innerType.includes("{") ? `(${innerType})[]` : `${innerType}[]`;
18
+ }
19
+ if (schema instanceof UnionSchema) {
20
+ const schemas = schema.schemas || [];
21
+ if (schemas.length === 0) return "any";
22
+ return schemas.map((s) => schemaToTypeString(s)).join(" | ");
23
+ }
24
+ if (schema instanceof LiteralSchema) {
25
+ const val = schema.value;
26
+ return typeof val === "string" ? `'${val}'` : String(val);
27
+ }
28
+ if (schema instanceof InstanceOfSchema) {
29
+ const ctor = schema.classConstructor;
30
+ return ctor ? ctor.name : "object";
31
+ }
32
+ if (schema instanceof ObjectSchemaType) {
33
+ const definition = schema.definition;
34
+ if (!definition || Object.keys(definition).length === 0) return "{}";
35
+ const validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
36
+ return `{${Object.entries(definition).map(([key, value]) => {
37
+ const finalKey = validIdentifierRegex.test(key) ? key : `"${key}"`;
38
+ const isOptional = value instanceof OptionalSchema;
39
+ const optionalMarker = isOptional ? "?" : "";
40
+ let typeStr = schemaToTypeString(value);
41
+ if (isOptional) typeStr = typeStr.replace(" | undefined", "");
42
+ return `${finalKey}${optionalMarker}:${typeStr}`;
43
+ }).join(";")}}`;
44
+ }
45
+ return "any";
46
+ }
47
+ //#endregion
48
+ export { schemaToTypeString };
49
+
50
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import {\n AnySchemaType,\n ArraySchema,\n BooleanSchemaType,\n InstanceOfSchema,\n LiteralSchema,\n NullSchemaType,\n NumberSchemaType,\n ObjectSchemaType,\n OptionalSchema,\n StringSchemaType,\n UnionSchema,\n} from \"@hedystia/validations\";\n\nexport function schemaToTypeString(schema: any): string {\n if (!schema) {\n return \"any\";\n }\n\n if (schema instanceof StringSchemaType) {\n return \"string\";\n }\n if (schema instanceof NumberSchemaType) {\n return \"number\";\n }\n if (schema instanceof BooleanSchemaType) {\n return \"boolean\";\n }\n if (schema instanceof NullSchemaType) {\n return \"null\";\n }\n if (schema instanceof AnySchemaType) {\n return \"any\";\n }\n\n if (schema instanceof OptionalSchema) {\n const inner = (schema as any).innerSchema;\n return `${schemaToTypeString(inner)} | undefined`;\n }\n\n if (schema instanceof ArraySchema) {\n const inner = (schema as any).innerSchema;\n const innerType = schemaToTypeString(inner);\n return innerType.includes(\"|\") || innerType.includes(\"{\")\n ? `(${innerType})[]`\n : `${innerType}[]`;\n }\n\n if (schema instanceof UnionSchema) {\n const schemas = (schema as any).schemas || [];\n if (schemas.length === 0) {\n return \"any\";\n }\n return schemas.map((s: any) => schemaToTypeString(s)).join(\" | \");\n }\n\n if (schema instanceof LiteralSchema) {\n const val = (schema as any).value;\n return typeof val === \"string\" ? `'${val}'` : String(val);\n }\n\n if (schema instanceof InstanceOfSchema) {\n const ctor = (schema as any).classConstructor;\n return ctor ? ctor.name : \"object\";\n }\n\n if (schema instanceof ObjectSchemaType) {\n const definition = (schema as any).definition;\n if (!definition || Object.keys(definition).length === 0) {\n return \"{}\";\n }\n\n const validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n const properties = Object.entries(definition)\n .map(([key, value]) => {\n const finalKey = validIdentifierRegex.test(key) ? key : `\"${key}\"`;\n const isOptional = value instanceof OptionalSchema;\n const optionalMarker = isOptional ? \"?\" : \"\";\n\n let typeStr = schemaToTypeString(value);\n\n if (isOptional) {\n typeStr = typeStr.replace(\" | undefined\", \"\");\n }\n\n return `${finalKey}${optionalMarker}:${typeStr}`;\n })\n .join(\";\");\n\n return `{${properties}}`;\n }\n\n return \"any\";\n}\n"],"mappings":";;AAcA,SAAgB,mBAAmB,QAAqB;AACtD,KAAI,CAAC,OACH,QAAO;AAGT,KAAI,kBAAkB,iBACpB,QAAO;AAET,KAAI,kBAAkB,iBACpB,QAAO;AAET,KAAI,kBAAkB,kBACpB,QAAO;AAET,KAAI,kBAAkB,eACpB,QAAO;AAET,KAAI,kBAAkB,cACpB,QAAO;AAGT,KAAI,kBAAkB,gBAAgB;EACpC,MAAM,QAAS,OAAe;AAC9B,SAAO,GAAG,mBAAmB,MAAM,CAAC;;AAGtC,KAAI,kBAAkB,aAAa;EACjC,MAAM,QAAS,OAAe;EAC9B,MAAM,YAAY,mBAAmB,MAAM;AAC3C,SAAO,UAAU,SAAS,IAAI,IAAI,UAAU,SAAS,IAAI,GACrD,IAAI,UAAU,OACd,GAAG,UAAU;;AAGnB,KAAI,kBAAkB,aAAa;EACjC,MAAM,UAAW,OAAe,WAAW,EAAE;AAC7C,MAAI,QAAQ,WAAW,EACrB,QAAO;AAET,SAAO,QAAQ,KAAK,MAAW,mBAAmB,EAAE,CAAC,CAAC,KAAK,MAAM;;AAGnE,KAAI,kBAAkB,eAAe;EACnC,MAAM,MAAO,OAAe;AAC5B,SAAO,OAAO,QAAQ,WAAW,IAAI,IAAI,KAAK,OAAO,IAAI;;AAG3D,KAAI,kBAAkB,kBAAkB;EACtC,MAAM,OAAQ,OAAe;AAC7B,SAAO,OAAO,KAAK,OAAO;;AAG5B,KAAI,kBAAkB,kBAAkB;EACtC,MAAM,aAAc,OAAe;AACnC,MAAI,CAAC,cAAc,OAAO,KAAK,WAAW,CAAC,WAAW,EACpD,QAAO;EAGT,MAAM,uBAAuB;AAiB7B,SAAO,IAhBY,OAAO,QAAQ,WAAW,CAC1C,KAAK,CAAC,KAAK,WAAW;GACrB,MAAM,WAAW,qBAAqB,KAAK,IAAI,GAAG,MAAM,IAAI,IAAI;GAChE,MAAM,aAAa,iBAAiB;GACpC,MAAM,iBAAiB,aAAa,MAAM;GAE1C,IAAI,UAAU,mBAAmB,MAAM;AAEvC,OAAI,WACF,WAAU,QAAQ,QAAQ,gBAAgB,GAAG;AAG/C,UAAO,GAAG,WAAW,eAAe,GAAG;IACvC,CACD,KAAK,IAAI,CAEU;;AAGxB,QAAO"}
package/package.json CHANGED
@@ -1,24 +1,20 @@
1
1
  {
2
2
  "name": "@hedystia/types",
3
- "version": "1.10.1",
3
+ "version": "1.10.3",
4
4
  "description": "Next-gen TypeScript framework for building type-safe APIs at lightspeed",
5
+ "homepage": "https://docs.hedystia.com/plugins/types",
5
6
  "dependencies": {
6
- "@hedystia/validations": "^1.10.1"
7
+ "@hedystia/validations": "^1.10.2"
7
8
  },
8
9
  "devDependencies": {
9
- "@types/bun": "^1.3.3",
10
- "tsup": "^8.3.5"
10
+ "@types/bun": "^1.3.3"
11
11
  },
12
12
  "peerDependencies": {
13
- "@hedystia/validations": ">= 1.10.0",
14
13
  "typescript": ">= 5.0.0"
15
14
  },
16
15
  "peerDependenciesMeta": {
17
16
  "typescript": {
18
17
  "optional": true
19
- },
20
- "@hedystia/validations": {
21
- "optional": false
22
18
  }
23
19
  },
24
20
  "private": false,
@@ -35,12 +31,13 @@
35
31
  ],
36
32
  "license": "MIT",
37
33
  "scripts": {
38
- "build": "tsup",
39
- "dev": "bun --watch --no-clear-screen run src/index.ts"
34
+ "build": "tsdown --config-loader unrun",
35
+ "publish": "bun publish --access public",
36
+ "dev": "tsdown --watch"
40
37
  },
41
38
  "repository": {
42
39
  "type": "git",
43
- "url": "https://github.com/Hedystia/Framework"
40
+ "url": "https://github.com/Hedystia/Hedystia"
44
41
  },
45
42
  "author": {
46
43
  "name": "Zastinian",
@@ -50,5 +47,12 @@
50
47
  "type": "commonjs",
51
48
  "types": "./dist/index.d.ts",
52
49
  "main": "./dist/index.js",
53
- "module": "./dist/index.js"
50
+ "module": "./dist/index.mjs",
51
+ "exports": {
52
+ ".": {
53
+ "types": "./dist/index.d.ts",
54
+ "import": "./dist/index.mjs",
55
+ "require": "./dist/index.js"
56
+ }
57
+ }
54
58
  }
package/readme.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <a href="https://docs.hedystia.com"><img src="https://img.shields.io/badge/Docs-blue?style=flat-square" alt="Documentation"></a>
12
12
  <a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/v/hedystia.svg?style=flat-square" alt="npm version"></a>
13
13
  <a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/dm/hedystia.svg?style=flat-square" alt="npm downloads"></a>
14
- <a href="LICENSE"><img src="https://img.shields.io/github/license/Hedystia/Framework.svg?style=flat-square" alt="license"></a>
14
+ <a href="LICENSE"><img src="https://img.shields.io/github/license/Hedystia/Hedystia.svg?style=flat-square" alt="license"></a>
15
15
  <img src="https://img.shields.io/badge/Bun-powered-FFD43B?style=flat-square&logo=bun" alt="Bun powered">
16
16
  </p>
17
17
  </div>
@@ -168,5 +168,5 @@ MIT License © 2026 Hedystia
168
168
  - [API Reference](https://docs.hedystia.com/framework/overview)
169
169
 
170
170
  ## 🗣️ Community
171
- - [GitHub Issues](https://github.com/Hedystia/Framework/issues)
171
+ - [GitHub Issues](https://github.com/Hedystia/Hedystia/issues)
172
172
  - [Discord Server](https://hedystia.com/support)
package/src/index.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { writeFile } from "fs/promises";
2
+ import type { RouteInfo } from "./types";
3
+ import { schemaToTypeString } from "./utils";
4
+
5
+ export async function generateTypes(routes: RouteInfo[], filePath: string): Promise<void> {
6
+ const typeDefinitions = routes
7
+ .map((route) => {
8
+ const responseType = schemaToTypeString(route.response);
9
+ const paramsType = schemaToTypeString(route.params);
10
+ const queryType = schemaToTypeString(route.query);
11
+ const bodyType = schemaToTypeString(route.body);
12
+ const headersType = schemaToTypeString(route.headers);
13
+ const dataType = schemaToTypeString(route.data);
14
+ const errorType = schemaToTypeString(route.error);
15
+ return `{method:"${route.method}";path:"${route.path}";params:${paramsType};query:${queryType};body:${bodyType};headers:${headersType};response:${responseType};data:${dataType};error:${errorType}}`;
16
+ })
17
+ .join(",");
18
+
19
+ const content = `// Automatic Hedystia type generation\nexport type AppRoutes=[${typeDefinitions}];`;
20
+ await writeFile(filePath, content, "utf8");
21
+ }
22
+ export type { TypeGeneratorOptions } from "./types";
23
+ export type { RouteInfo };
24
+ export { schemaToTypeString };
package/src/types.ts ADDED
@@ -0,0 +1,16 @@
1
+ export interface RouteInfo {
2
+ method: string;
3
+ path: string;
4
+ params?: unknown;
5
+ query?: unknown;
6
+ headers?: unknown;
7
+ body?: unknown;
8
+ response?: unknown;
9
+ data?: unknown;
10
+ error?: unknown;
11
+ }
12
+
13
+ export type TypeGeneratorOptions = {
14
+ includeSubscriptions?: boolean;
15
+ includeWebSocket?: boolean;
16
+ };
package/src/utils.ts ADDED
@@ -0,0 +1,94 @@
1
+ import {
2
+ AnySchemaType,
3
+ ArraySchema,
4
+ BooleanSchemaType,
5
+ InstanceOfSchema,
6
+ LiteralSchema,
7
+ NullSchemaType,
8
+ NumberSchemaType,
9
+ ObjectSchemaType,
10
+ OptionalSchema,
11
+ StringSchemaType,
12
+ UnionSchema,
13
+ } from "@hedystia/validations";
14
+
15
+ export function schemaToTypeString(schema: any): string {
16
+ if (!schema) {
17
+ return "any";
18
+ }
19
+
20
+ if (schema instanceof StringSchemaType) {
21
+ return "string";
22
+ }
23
+ if (schema instanceof NumberSchemaType) {
24
+ return "number";
25
+ }
26
+ if (schema instanceof BooleanSchemaType) {
27
+ return "boolean";
28
+ }
29
+ if (schema instanceof NullSchemaType) {
30
+ return "null";
31
+ }
32
+ if (schema instanceof AnySchemaType) {
33
+ return "any";
34
+ }
35
+
36
+ if (schema instanceof OptionalSchema) {
37
+ const inner = (schema as any).innerSchema;
38
+ return `${schemaToTypeString(inner)} | undefined`;
39
+ }
40
+
41
+ if (schema instanceof ArraySchema) {
42
+ const inner = (schema as any).innerSchema;
43
+ const innerType = schemaToTypeString(inner);
44
+ return innerType.includes("|") || innerType.includes("{")
45
+ ? `(${innerType})[]`
46
+ : `${innerType}[]`;
47
+ }
48
+
49
+ if (schema instanceof UnionSchema) {
50
+ const schemas = (schema as any).schemas || [];
51
+ if (schemas.length === 0) {
52
+ return "any";
53
+ }
54
+ return schemas.map((s: any) => schemaToTypeString(s)).join(" | ");
55
+ }
56
+
57
+ if (schema instanceof LiteralSchema) {
58
+ const val = (schema as any).value;
59
+ return typeof val === "string" ? `'${val}'` : String(val);
60
+ }
61
+
62
+ if (schema instanceof InstanceOfSchema) {
63
+ const ctor = (schema as any).classConstructor;
64
+ return ctor ? ctor.name : "object";
65
+ }
66
+
67
+ if (schema instanceof ObjectSchemaType) {
68
+ const definition = (schema as any).definition;
69
+ if (!definition || Object.keys(definition).length === 0) {
70
+ return "{}";
71
+ }
72
+
73
+ const validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
74
+ const properties = Object.entries(definition)
75
+ .map(([key, value]) => {
76
+ const finalKey = validIdentifierRegex.test(key) ? key : `"${key}"`;
77
+ const isOptional = value instanceof OptionalSchema;
78
+ const optionalMarker = isOptional ? "?" : "";
79
+
80
+ let typeStr = schemaToTypeString(value);
81
+
82
+ if (isOptional) {
83
+ typeStr = typeStr.replace(" | undefined", "");
84
+ }
85
+
86
+ return `${finalKey}${optionalMarker}:${typeStr}`;
87
+ })
88
+ .join(";");
89
+
90
+ return `{${properties}}`;
91
+ }
92
+
93
+ return "any";
94
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../tsconfig.json"
3
+ }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts"],
5
+ format: ["cjs", "esm"],
6
+ dts: true,
7
+ sourcemap: true,
8
+ treeshake: true,
9
+ clean: true,
10
+ unbundle: true,
11
+ outputOptions: { exports: "named" },
12
+ deps: { neverBundle: ["@hedystia/validations", "bun"] },
13
+ });
package/dist/index.d.ts DELETED
@@ -1,21 +0,0 @@
1
- interface RouteInfo {
2
- method: string;
3
- path: string;
4
- params?: unknown;
5
- query?: unknown;
6
- headers?: unknown;
7
- body?: unknown;
8
- response?: unknown;
9
- data?: unknown;
10
- error?: unknown;
11
- }
12
- type TypeGeneratorOptions = {
13
- includeSubscriptions?: boolean;
14
- includeWebSocket?: boolean;
15
- };
16
-
17
- declare function schemaToTypeString(schema: any): string;
18
-
19
- declare function generateTypes(routes: RouteInfo[], filePath: string): Promise<void>;
20
-
21
- export { type RouteInfo, type TypeGeneratorOptions, generateTypes, schemaToTypeString };
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var g=(e,n)=>{for(var o in n)u(e,o,{get:n[o],enumerable:!0})},b=(e,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of T(n))!S.call(e,r)&&r!==o&&u(e,r,{get:()=>n[r],enumerable:!(a=l(n,r))||a.enumerable});return e};var h=e=>b(u({},"__esModule",{value:!0}),e);var x={};g(x,{generateTypes:()=>j,schemaToTypeString:()=>i});module.exports=h(x);var d=require("fs/promises");var t=require("@hedystia/validations");function i(e){if(!e)return"any";if(e instanceof t.StringSchemaType)return"string";if(e instanceof t.NumberSchemaType)return"number";if(e instanceof t.BooleanSchemaType)return"boolean";if(e instanceof t.NullSchemaType)return"null";if(e instanceof t.AnySchemaType)return"any";if(e instanceof t.OptionalSchema){let n=e.innerSchema;return`${i(n)} | undefined`}if(e instanceof t.ArraySchema){let n=e.innerSchema,o=i(n);return o.includes("|")||o.includes("{")?`(${o})[]`:`${o}[]`}if(e instanceof t.UnionSchema){let n=e.schemas||[];return n.length===0?"any":n.map(o=>i(o)).join(" | ")}if(e instanceof t.LiteralSchema){let n=e.value;return typeof n=="string"?`'${n}'`:String(n)}if(e instanceof t.InstanceOfSchema){let n=e.classConstructor;return n?n.name:"object"}if(e instanceof t.ObjectSchemaType){let n=e.definition;if(!n||Object.keys(n).length===0)return"{}";let o=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/;return`{${Object.entries(n).map(([r,p])=>{let c=o.test(r)?r:`"${r}"`,y=p instanceof t.OptionalSchema,f=y?"?":"",s=i(p);return y&&(s=s.replace(" | undefined","")),`${c}${f}:${s}`}).join(";")}}`}return"any"}async function j(e,n){let a=`// Automatic Hedystia type generation
2
- export type AppRoutes=[${e.map(r=>{let p=i(r.response),c=i(r.params),y=i(r.query),f=i(r.body),s=i(r.headers),m=i(r.data),$=i(r.error);return`{method:"${r.method}";path:"${r.path}";params:${c};query:${y};body:${f};headers:${s};response:${p};data:${m};error:${$}}`}).join(",")}];`;await(0,d.writeFile)(n,a,"utf8")}0&&(module.exports={generateTypes,schemaToTypeString});