@hedystia/types 1.10.2 → 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.
- package/.turbo/turbo-build.log +27 -0
- package/package.json +3 -3
- package/src/index.ts +24 -0
- package/src/types.ts +16 -0
- package/src/utils.ts +94 -0
- package/tsconfig.json +3 -0
- package/tsdown.config.ts +13 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
[0m[2m[35m$[0m [2m[1mtsdown --config-loader unrun[0m
|
|
3
|
+
[34mℹ[39m tsdown [2mv0.21.2[22m powered by rolldown [2mv1.0.0-rc.9[22m
|
|
4
|
+
[34mℹ[39m config file: [4m/home/zastinian/Documents/codes/Framework/Packages/types/tsdown.config.ts[24m (unrun)
|
|
5
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
6
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
7
|
+
[34mℹ[39m Build start
|
|
8
|
+
[34mℹ[39m Cleaning 14 files
|
|
9
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m1.22 kB[22m [2m│ gzip: 0.52 kB[22m
|
|
10
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mutils.cjs.map [2m4.09 kB[22m [2m│ gzip: 1.34 kB[22m
|
|
11
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mutils.cjs [2m2.25 kB[22m [2m│ gzip: 0.74 kB[22m
|
|
12
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.cjs.map [2m1.86 kB[22m [2m│ gzip: 0.75 kB[22m
|
|
13
|
+
[34mℹ[39m [33m[CJS][39m 4 files, total: 9.42 kB
|
|
14
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m0.36 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
15
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mtypes.d.cts[39m [2m0.41 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
16
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mutils.d.cts[39m [2m0.16 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
17
|
+
[34mℹ[39m [33m[CJS][39m 3 files, total: 0.94 kB
|
|
18
|
+
[32m✔[39m Build complete in [32m774ms[39m
|
|
19
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m0.98 kB[22m [2m│ gzip: 0.44 kB[22m
|
|
20
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils.mjs.map [2m3.80 kB[22m [2m│ gzip: 1.28 kB[22m
|
|
21
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mutils.mjs [2m2.13 kB[22m [2m│ gzip: 0.77 kB[22m
|
|
22
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [2m1.78 kB[22m [2m│ gzip: 0.74 kB[22m
|
|
23
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m0.36 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
24
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mtypes.d.mts[39m [2m0.41 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
25
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mutils.d.mts[39m [2m0.16 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
26
|
+
[34mℹ[39m [34m[ESM][39m 7 files, total: 9.63 kB
|
|
27
|
+
[32m✔[39m Build complete in [32m779ms[39m
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hedystia/types",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.3",
|
|
4
4
|
"description": "Next-gen TypeScript framework for building type-safe APIs at lightspeed",
|
|
5
5
|
"homepage": "https://docs.hedystia.com/plugins/types",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@hedystia/validations": "
|
|
7
|
+
"@hedystia/validations": "^1.10.2"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/bun": "^1.3.3"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsdown --config-loader unrun",
|
|
35
|
-
"publish": "
|
|
35
|
+
"publish": "bun publish --access public",
|
|
36
36
|
"dev": "tsdown --watch"
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
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
package/tsdown.config.ts
ADDED
|
@@ -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
|
+
});
|