@hedystia/types 1.10.1 → 1.10.2
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/index.cjs +21 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.cts +19 -0
- package/dist/types.d.mts +19 -0
- package/dist/utils.cjs +50 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +5 -0
- package/dist/utils.d.mts +5 -0
- package/dist/utils.mjs +50 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +16 -12
- package/readme.md +2 -2
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -2
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"}
|
package/dist/index.d.cts
ADDED
|
@@ -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
|
package/dist/index.d.mts
ADDED
|
@@ -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"}
|
package/dist/types.d.cts
ADDED
|
@@ -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
|
package/dist/types.d.mts
ADDED
|
@@ -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"}
|
package/dist/utils.d.cts
ADDED
package/dist/utils.d.mts
ADDED
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.
|
|
3
|
+
"version": "1.10.2",
|
|
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": "
|
|
7
|
+
"@hedystia/validations": "workspace:*"
|
|
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": "
|
|
39
|
-
"
|
|
34
|
+
"build": "tsdown --config-loader unrun",
|
|
35
|
+
"publish": "npm publish --access public",
|
|
36
|
+
"dev": "tsdown --watch"
|
|
40
37
|
},
|
|
41
38
|
"repository": {
|
|
42
39
|
"type": "git",
|
|
43
|
-
"url": "https://github.com/Hedystia/
|
|
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.
|
|
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/
|
|
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/
|
|
171
|
+
- [GitHub Issues](https://github.com/Hedystia/Hedystia/issues)
|
|
172
172
|
- [Discord Server](https://hedystia.com/support)
|
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});
|