@hedystia/types 1.10.0 → 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 +35 -20
- package/readme.md +172 -0
- 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,28 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hedystia/types",
|
|
3
|
-
"version": "1.10.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./dist/index.js"
|
|
9
|
-
},
|
|
10
|
-
"private": false,
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "tsup",
|
|
14
|
-
"dev": "bun --watch --no-clear-screen run src/index.ts"
|
|
15
|
-
},
|
|
3
|
+
"version": "1.10.2",
|
|
4
|
+
"description": "Next-gen TypeScript framework for building type-safe APIs at lightspeed",
|
|
5
|
+
"homepage": "https://docs.hedystia.com/plugins/types",
|
|
16
6
|
"dependencies": {
|
|
17
|
-
"@hedystia/validations": "
|
|
7
|
+
"@hedystia/validations": "workspace:*"
|
|
18
8
|
},
|
|
19
9
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@types/bun": "^1.3.3",
|
|
22
|
-
"tsup": "^8.3.5"
|
|
10
|
+
"@types/bun": "^1.3.3"
|
|
23
11
|
},
|
|
24
12
|
"peerDependencies": {
|
|
25
|
-
"@hedystia/validations": ">= 1.10.0",
|
|
26
13
|
"typescript": ">= 5.0.0"
|
|
27
14
|
},
|
|
28
15
|
"peerDependenciesMeta": {
|
|
@@ -30,14 +17,42 @@
|
|
|
30
17
|
"optional": true
|
|
31
18
|
}
|
|
32
19
|
},
|
|
20
|
+
"private": false,
|
|
21
|
+
"keywords": [
|
|
22
|
+
"hedystia",
|
|
23
|
+
"framework",
|
|
24
|
+
"typescript",
|
|
25
|
+
"api",
|
|
26
|
+
"type-safe",
|
|
27
|
+
"bun",
|
|
28
|
+
"server",
|
|
29
|
+
"backend",
|
|
30
|
+
"web"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown --config-loader unrun",
|
|
35
|
+
"publish": "npm publish --access public",
|
|
36
|
+
"dev": "tsdown --watch"
|
|
37
|
+
},
|
|
33
38
|
"repository": {
|
|
34
39
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/Hedystia/
|
|
40
|
+
"url": "https://github.com/Hedystia/Hedystia"
|
|
36
41
|
},
|
|
37
42
|
"author": {
|
|
38
43
|
"name": "Zastinian",
|
|
39
44
|
"email": "contact@zastinian.com",
|
|
40
45
|
"url": "https://github.com/Zastinian"
|
|
41
46
|
},
|
|
42
|
-
"type": "commonjs"
|
|
47
|
+
"type": "commonjs",
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"main": "./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
|
+
}
|
|
43
58
|
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<p>
|
|
3
|
+
<strong>🚀 Hedystia Framework</strong>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
<strong>Next-gen TypeScript framework for building type-safe APIs at lightspeed! ⚡</strong>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p>
|
|
11
|
+
<a href="https://docs.hedystia.com"><img src="https://img.shields.io/badge/Docs-blue?style=flat-square" alt="Documentation"></a>
|
|
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
|
+
<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/Hedystia.svg?style=flat-square" alt="license"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/Bun-powered-FFD43B?style=flat-square&logo=bun" alt="Bun powered">
|
|
16
|
+
</p>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
## 🌟 Superpowers
|
|
20
|
+
|
|
21
|
+
- 🌐 **Multi-runtime support** - Bun (default), Deno, Node.js, Vercel, Cloudflare Workers, Fastly Compute, Lambda, etc.
|
|
22
|
+
- 🔒 **End-to-end type safety** - From params to response, full TypeScript integration
|
|
23
|
+
- ⚡ **Bun-native performance** - Built for Bun runtime with native validation
|
|
24
|
+
- 🧩 **Client integration** - Auto-generated type-safe HTTP client
|
|
25
|
+
- 🛡️ **Validation built-in** - Zod integration for runtime safety
|
|
26
|
+
- 🔌 **Extensible architecture** - Middleware, hooks and macros system
|
|
27
|
+
- 📝 **Standard Schema** - Compatibility with the standard schema so you can use it with Zod, Arktype, etc.
|
|
28
|
+
|
|
29
|
+
## 🚀 Launch in 30 Seconds
|
|
30
|
+
|
|
31
|
+
1. Install with Bun:
|
|
32
|
+
```bash
|
|
33
|
+
bun add hedystia
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2. Create your first API:
|
|
37
|
+
```typescript
|
|
38
|
+
import { Hedystia, h } from "hedystia";
|
|
39
|
+
|
|
40
|
+
const app = new Hedystia()
|
|
41
|
+
.get("/hello/:name", (ctx) => `Hello ${ctx.params.name}!`, {
|
|
42
|
+
params: h.object({ name: h.string() }),
|
|
43
|
+
response: h.string()
|
|
44
|
+
})
|
|
45
|
+
.listen(3000);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
3. Generate client and consume API:
|
|
49
|
+
```typescript
|
|
50
|
+
import { createClient } from "@hedystia/client";
|
|
51
|
+
|
|
52
|
+
const client = createClient<typeof app>("http://localhost:3000");
|
|
53
|
+
|
|
54
|
+
// Fully typed request!
|
|
55
|
+
const { data } = await client.hello.name("World").get();
|
|
56
|
+
console.log(data); // "Hello World!"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 💡 Why Developers Love Hedystia
|
|
60
|
+
|
|
61
|
+
### 🔄 Full-stack Type Safety
|
|
62
|
+
```typescript
|
|
63
|
+
// Server-side validation
|
|
64
|
+
.post("/users", (ctx) => {...}, {
|
|
65
|
+
body: h.object({
|
|
66
|
+
email: h.email(),
|
|
67
|
+
age: h.number()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Client-side types
|
|
72
|
+
await client.users.post({
|
|
73
|
+
body: {
|
|
74
|
+
email: "user@example.com", // Autocompletes!
|
|
75
|
+
age: 25 // Type-checked
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 📖 Swagger Integration
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { swagger } from "@hedystia/swagger";
|
|
84
|
+
|
|
85
|
+
const swaggerPlugin = swagger({
|
|
86
|
+
title: "My API",
|
|
87
|
+
description: "An example API with Swagger",
|
|
88
|
+
version: "1.0.0",
|
|
89
|
+
tags: [
|
|
90
|
+
{ name: "users", description: "User operations" },
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
app.use("/swagger", swaggerPlugin.plugin(app));
|
|
95
|
+
|
|
96
|
+
app.listen(3000);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### ⚡ Performance First
|
|
100
|
+
- Bun runtime optimized
|
|
101
|
+
- Faster by default
|
|
102
|
+
- Own type validation system
|
|
103
|
+
- Faster than Express
|
|
104
|
+
- Built-in response compression
|
|
105
|
+
|
|
106
|
+
### 🧩 Modern Feature Set
|
|
107
|
+
```typescript
|
|
108
|
+
// File uploads
|
|
109
|
+
.post("/upload", async (ctx) => {
|
|
110
|
+
const formData = await ctx.body; // FormData type
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// Binary responses
|
|
114
|
+
.get("/pdf", () => new Blob([...]), {
|
|
115
|
+
response: h.instanceof(Blob)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
// Nested routing
|
|
119
|
+
.group("/api/v1", (v1) => v1
|
|
120
|
+
.group("/users", (users) => users
|
|
121
|
+
.get("/:id", ...)
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 🛠️ Development Roadmap
|
|
127
|
+
|
|
128
|
+
### Core Features
|
|
129
|
+
- ✅ HTTP Methods: GET, POST, PUT, PATCH, DELETE
|
|
130
|
+
- ✅ Response Types: JSON, Text, FormData, Blob, ArrayBuffer
|
|
131
|
+
- ✅ Router Groups & Middleware
|
|
132
|
+
- ✅ Type-safe Client Generation
|
|
133
|
+
- ✅ WebSocket Support
|
|
134
|
+
- ✅ Adapter System to work with other frameworks
|
|
135
|
+
|
|
136
|
+
### Advanced Capabilities
|
|
137
|
+
- ✅ Standard Schema Compatibility
|
|
138
|
+
- ✅ Hooks System (onRequest, onError, etc)
|
|
139
|
+
- ✅ Macro System for Auth/Rate Limiting
|
|
140
|
+
- ✅ OpenAPI - Swagger Integration
|
|
141
|
+
|
|
142
|
+
## 💼 Production Ready
|
|
143
|
+
```typescript
|
|
144
|
+
// Error handling
|
|
145
|
+
.onError((err, ctx) => {
|
|
146
|
+
ctx.set.status(500);
|
|
147
|
+
return {
|
|
148
|
+
error: err.message
|
|
149
|
+
};
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
// Rate limiting macro
|
|
153
|
+
.macro({
|
|
154
|
+
rateLimit: () => ({
|
|
155
|
+
resolve: async (ctx) => {
|
|
156
|
+
// Implement your logic
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 📜 License
|
|
163
|
+
MIT License © 2026 Hedystia
|
|
164
|
+
|
|
165
|
+
## 📖 Documentation
|
|
166
|
+
- [Full Documentation](https://docs.hedystia.com)
|
|
167
|
+
- [Getting Started Guide](https://docs.hedystia.com/framework/getting-started)
|
|
168
|
+
- [API Reference](https://docs.hedystia.com/framework/overview)
|
|
169
|
+
|
|
170
|
+
## 🗣️ Community
|
|
171
|
+
- [GitHub Issues](https://github.com/Hedystia/Hedystia/issues)
|
|
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});
|