@ezetgalaxy/titan 26.9.1 → 26.9.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/README.md +17 -5
- package/index.js +177 -112
- package/package.json +17 -4
- package/templates/{js → common}/app/titan.d.ts +1 -1
- package/templates/rust-ts/app/actions/hello.ts +1 -1
- package/templates/rust-ts/titan/runtime.d.ts +1 -0
- package/templates/rust-ts/titan/runtime.js +1 -0
- package/templates/rust-ts/titan/titan.d.ts +117 -117
- package/templates/rust-ts/titan/titan.js +1 -1
- package/templates/ts/app/actions/hello.ts +1 -1
- package/templates/ts/titan/builder.js +121 -121
- package/templates/ts/titan/runtime.d.ts +1 -0
- package/templates/ts/titan/runtime.js +1 -1
- package/templates/ts/titan/titan.d.ts +117 -117
- package/templates/ts/titan/titan.js +1 -1
- package/templates/rust-js/Dockerfile +0 -66
- package/templates/rust-js/_dockerignore +0 -3
- package/templates/rust-js/_gitignore +0 -38
- package/templates/rust-js/app/titan.d.ts +0 -101
- package/templates/rust-ts/Dockerfile +0 -66
- package/templates/rust-ts/_dockerignore +0 -3
- package/templates/rust-ts/_gitignore +0 -38
- package/templates/ts/Dockerfile +0 -40
- package/templates/ts/_dockerignore +0 -3
- package/templates/ts/_gitignore +0 -38
- /package/templates/{js → common}/Dockerfile +0 -0
- /package/templates/{js → common}/_dockerignore +0 -0
- /package/templates/{js → common}/_gitignore +0 -0
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
// -- Module Definitions (for imports from "titan") --
|
|
3
|
-
|
|
4
|
-
export interface RouteHandler {
|
|
5
|
-
reply(value: any): void;
|
|
6
|
-
action(name: string): void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface TitanBuilder {
|
|
10
|
-
get(route: string): RouteHandler;
|
|
11
|
-
post(route: string): RouteHandler;
|
|
12
|
-
log(module: string, msg: string): void;
|
|
13
|
-
start(port?: number, msg?: string): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// The default export from titan.js is the Builder
|
|
17
|
-
declare const builder: TitanBuilder;
|
|
18
|
-
export default builder;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Define a Titan Action with type inference.
|
|
22
|
-
*/
|
|
23
|
-
export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// -- Global Definitions (Runtime Environment) --
|
|
27
|
-
|
|
28
|
-
declare global {
|
|
29
|
-
/**
|
|
30
|
-
* The Titan Request Object passed to actions.
|
|
31
|
-
*/
|
|
32
|
-
interface TitanRequest {
|
|
33
|
-
body: any;
|
|
34
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
35
|
-
path: string;
|
|
36
|
-
headers: {
|
|
37
|
-
host?: string;
|
|
38
|
-
"content-type"?: string;
|
|
39
|
-
"user-agent"?: string;
|
|
40
|
-
authorization?: string;
|
|
41
|
-
[key: string]: string | undefined;
|
|
42
|
-
};
|
|
43
|
-
params: Record<string, string>;
|
|
44
|
-
query: Record<string, string>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface DbConnection {
|
|
48
|
-
/**
|
|
49
|
-
* Execute a SQL query.
|
|
50
|
-
* @param sql The SQL query string.
|
|
51
|
-
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
52
|
-
*/
|
|
53
|
-
query(sql: string, params?: any[]): any[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Global defineAction (available without import in runtime, though imports are preferred in TS)
|
|
58
|
-
*/
|
|
59
|
-
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Global Request Object
|
|
63
|
-
* Available automatically in actions.
|
|
64
|
-
*/
|
|
65
|
-
var req: TitanRequest;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Titan Runtime Utilities
|
|
69
|
-
* (Available globally in the runtime, e.g. inside actions)
|
|
70
|
-
*/
|
|
71
|
-
const t: {
|
|
72
|
-
/**
|
|
73
|
-
* Log messages to the server console with Titan formatting.
|
|
74
|
-
*/
|
|
75
|
-
log(...args: any[]): void;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Read a file contents as string.
|
|
79
|
-
* @param path Relative path to the file from project root.
|
|
80
|
-
*/
|
|
81
|
-
read(path: string): string;
|
|
82
|
-
|
|
83
|
-
fetch(url: string, options?: {
|
|
84
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
85
|
-
headers?: Record<string, string>;
|
|
86
|
-
body?: string | object;
|
|
87
|
-
}): {
|
|
88
|
-
ok: boolean;
|
|
89
|
-
status?: number;
|
|
90
|
-
body?: string;
|
|
91
|
-
error?: string;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
jwt: {
|
|
95
|
-
sign(
|
|
96
|
-
payload: object,
|
|
97
|
-
secret: string,
|
|
98
|
-
options?: { expiresIn?: string | number }
|
|
99
|
-
): string;
|
|
100
|
-
verify(token: string, secret: string): any;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
password: {
|
|
104
|
-
hash(password: string): string;
|
|
105
|
-
verify(password: string, hash: string): boolean;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
db: {
|
|
109
|
-
connect(url: string): DbConnection;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Titan Validator (Zod-compatible)
|
|
114
|
-
*/
|
|
115
|
-
valid: any;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
1
|
+
|
|
2
|
+
// -- Module Definitions (for imports from "titan") --
|
|
3
|
+
|
|
4
|
+
export interface RouteHandler {
|
|
5
|
+
reply(value: any): void;
|
|
6
|
+
action(name: string): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TitanBuilder {
|
|
10
|
+
get(route: string): RouteHandler;
|
|
11
|
+
post(route: string): RouteHandler;
|
|
12
|
+
log(module: string, msg: string): void;
|
|
13
|
+
start(port?: number, msg?: string): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The default export from titan.js is the Builder
|
|
17
|
+
declare const builder: TitanBuilder;
|
|
18
|
+
export default builder;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Define a Titan Action with type inference.
|
|
22
|
+
*/
|
|
23
|
+
export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// -- Global Definitions (Runtime Environment) --
|
|
27
|
+
|
|
28
|
+
declare global {
|
|
29
|
+
/**
|
|
30
|
+
* The Titan Request Object passed to actions.
|
|
31
|
+
*/
|
|
32
|
+
interface TitanRequest {
|
|
33
|
+
body: any;
|
|
34
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
35
|
+
path: string;
|
|
36
|
+
headers: {
|
|
37
|
+
host?: string;
|
|
38
|
+
"content-type"?: string;
|
|
39
|
+
"user-agent"?: string;
|
|
40
|
+
authorization?: string;
|
|
41
|
+
[key: string]: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
params: Record<string, string>;
|
|
44
|
+
query: Record<string, string>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface DbConnection {
|
|
48
|
+
/**
|
|
49
|
+
* Execute a SQL query.
|
|
50
|
+
* @param sql The SQL query string.
|
|
51
|
+
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
52
|
+
*/
|
|
53
|
+
query(sql: string, params?: any[]): any[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Global defineAction (available without import in runtime, though imports are preferred in TS)
|
|
58
|
+
*/
|
|
59
|
+
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Global Request Object
|
|
63
|
+
* Available automatically in actions.
|
|
64
|
+
*/
|
|
65
|
+
var req: TitanRequest;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Titan Runtime Utilities
|
|
69
|
+
* (Available globally in the runtime, e.g. inside actions)
|
|
70
|
+
*/
|
|
71
|
+
const t: {
|
|
72
|
+
/**
|
|
73
|
+
* Log messages to the server console with Titan formatting.
|
|
74
|
+
*/
|
|
75
|
+
log(...args: any[]): void;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Read a file contents as string.
|
|
79
|
+
* @param path Relative path to the file from project root.
|
|
80
|
+
*/
|
|
81
|
+
read(path: string): string;
|
|
82
|
+
|
|
83
|
+
fetch(url: string, options?: {
|
|
84
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
body?: string | object;
|
|
87
|
+
}): {
|
|
88
|
+
ok: boolean;
|
|
89
|
+
status?: number;
|
|
90
|
+
body?: string;
|
|
91
|
+
error?: string;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
jwt: {
|
|
95
|
+
sign(
|
|
96
|
+
payload: object,
|
|
97
|
+
secret: string,
|
|
98
|
+
options?: { expiresIn?: string | number }
|
|
99
|
+
): string;
|
|
100
|
+
verify(token: string, secret: string): any;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
password: {
|
|
104
|
+
hash(password: string): string;
|
|
105
|
+
verify(password: string, hash: string): boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
db: {
|
|
109
|
+
connect(url: string): DbConnection;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Titan Validator (Zod-compatible)
|
|
114
|
+
*/
|
|
115
|
+
valid: any;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { bundle } from "./bundle.js";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
6
|
-
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
7
|
-
|
|
8
|
-
const routes = {};
|
|
9
|
-
const dynamicRoutes = {};
|
|
10
|
-
const actionMap = {};
|
|
11
|
-
|
|
12
|
-
function addRoute(method, route) {
|
|
13
|
-
const key = `${method.toUpperCase()}:${route}`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
reply(value) {
|
|
18
|
-
routes[key] = {
|
|
19
|
-
type: typeof value === "object" ? "json" : "text",
|
|
20
|
-
value
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
action(name) {
|
|
25
|
-
if (route.includes(":")) {
|
|
26
|
-
if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
|
|
27
|
-
dynamicRoutes[method].push({
|
|
28
|
-
method: method.toUpperCase(),
|
|
29
|
-
pattern: route,
|
|
30
|
-
action: name
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
routes[key] = {
|
|
34
|
-
type: "action",
|
|
35
|
-
value: name
|
|
36
|
-
};
|
|
37
|
-
actionMap[key] = name;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @typedef {Object} RouteHandler
|
|
45
|
-
* @property {(value: any) => void} reply - Send a direct response
|
|
46
|
-
* @property {(name: string) => void} action - Bind to a server-side action
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Titan App Builder
|
|
51
|
-
*/
|
|
52
|
-
const t = {
|
|
53
|
-
/**
|
|
54
|
-
* Define a GET route
|
|
55
|
-
* @param {string} route
|
|
56
|
-
* @returns {RouteHandler}
|
|
57
|
-
*/
|
|
58
|
-
get(route) {
|
|
59
|
-
return addRoute("GET", route);
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Define a POST route
|
|
64
|
-
* @param {string} route
|
|
65
|
-
* @returns {RouteHandler}
|
|
66
|
-
*/
|
|
67
|
-
post(route) {
|
|
68
|
-
return addRoute("POST", route);
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
log(module, msg) {
|
|
72
|
-
console.log(`[\x1b[35m${module}\x1b[0m] ${msg}`);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Start the Titan Server
|
|
77
|
-
* @param {number} [port=3000]
|
|
78
|
-
* @param {string} [msg=""]
|
|
79
|
-
*/
|
|
80
|
-
async start(port = 3000, msg = "") {
|
|
81
|
-
try {
|
|
82
|
-
console.log(cyan("[Titan] Preparing runtime..."));
|
|
83
|
-
await bundle();
|
|
84
|
-
|
|
85
|
-
const base = path.join(process.cwd(), "server");
|
|
86
|
-
if (!fs.existsSync(base)) {
|
|
87
|
-
fs.mkdirSync(base, { recursive: true });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const routesPath = path.join(base, "routes.json");
|
|
91
|
-
const actionMapPath = path.join(base, "action_map.json");
|
|
92
|
-
|
|
93
|
-
fs.writeFileSync(
|
|
94
|
-
routesPath,
|
|
95
|
-
JSON.stringify(
|
|
96
|
-
{
|
|
97
|
-
__config: { port },
|
|
98
|
-
routes,
|
|
99
|
-
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
100
|
-
},
|
|
101
|
-
null,
|
|
102
|
-
2
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
fs.writeFileSync(
|
|
107
|
-
actionMapPath,
|
|
108
|
-
JSON.stringify(actionMap, null, 2)
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
console.log(green("✔ Titan metadata written successfully"));
|
|
112
|
-
if (msg) console.log(cyan(msg));
|
|
113
|
-
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.error(`\x1b[31m[Titan] Build Error: ${e.message}\x1b[0m`);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export default t;
|
|
1
|
+
import { bundle } from "./bundle.js";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
6
|
+
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
7
|
+
|
|
8
|
+
const routes = {};
|
|
9
|
+
const dynamicRoutes = {};
|
|
10
|
+
const actionMap = {};
|
|
11
|
+
|
|
12
|
+
function addRoute(method, route) {
|
|
13
|
+
const key = `${method.toUpperCase()}:${route}`;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
reply(value) {
|
|
18
|
+
routes[key] = {
|
|
19
|
+
type: typeof value === "object" ? "json" : "text",
|
|
20
|
+
value
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
action(name) {
|
|
25
|
+
if (route.includes(":")) {
|
|
26
|
+
if (!dynamicRoutes[method]) dynamicRoutes[method] = [];
|
|
27
|
+
dynamicRoutes[method].push({
|
|
28
|
+
method: method.toUpperCase(),
|
|
29
|
+
pattern: route,
|
|
30
|
+
action: name
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
routes[key] = {
|
|
34
|
+
type: "action",
|
|
35
|
+
value: name
|
|
36
|
+
};
|
|
37
|
+
actionMap[key] = name;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {Object} RouteHandler
|
|
45
|
+
* @property {(value: any) => void} reply - Send a direct response
|
|
46
|
+
* @property {(name: string) => void} action - Bind to a server-side action
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Titan App Builder
|
|
51
|
+
*/
|
|
52
|
+
const t = {
|
|
53
|
+
/**
|
|
54
|
+
* Define a GET route
|
|
55
|
+
* @param {string} route
|
|
56
|
+
* @returns {RouteHandler}
|
|
57
|
+
*/
|
|
58
|
+
get(route) {
|
|
59
|
+
return addRoute("GET", route);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Define a POST route
|
|
64
|
+
* @param {string} route
|
|
65
|
+
* @returns {RouteHandler}
|
|
66
|
+
*/
|
|
67
|
+
post(route) {
|
|
68
|
+
return addRoute("POST", route);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
log(module, msg) {
|
|
72
|
+
console.log(`[\x1b[35m${module}\x1b[0m] ${msg}`);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Start the Titan Server
|
|
77
|
+
* @param {number} [port=3000]
|
|
78
|
+
* @param {string} [msg=""]
|
|
79
|
+
*/
|
|
80
|
+
async start(port = 3000, msg = "") {
|
|
81
|
+
try {
|
|
82
|
+
console.log(cyan("[Titan] Preparing runtime..."));
|
|
83
|
+
await bundle();
|
|
84
|
+
|
|
85
|
+
const base = path.join(process.cwd(), "server");
|
|
86
|
+
if (!fs.existsSync(base)) {
|
|
87
|
+
fs.mkdirSync(base, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const routesPath = path.join(base, "routes.json");
|
|
91
|
+
const actionMapPath = path.join(base, "action_map.json");
|
|
92
|
+
|
|
93
|
+
fs.writeFileSync(
|
|
94
|
+
routesPath,
|
|
95
|
+
JSON.stringify(
|
|
96
|
+
{
|
|
97
|
+
__config: { port },
|
|
98
|
+
routes,
|
|
99
|
+
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
100
|
+
},
|
|
101
|
+
null,
|
|
102
|
+
2
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
fs.writeFileSync(
|
|
107
|
+
actionMapPath,
|
|
108
|
+
JSON.stringify(actionMap, null, 2)
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
console.log(green("✔ Titan metadata written successfully"));
|
|
112
|
+
if (msg) console.log(cyan(msg));
|
|
113
|
+
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.error(`\x1b[31m[Titan] Build Error: ${e.message}\x1b[0m`);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export default t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function defineAction<Req = any, Res = any>(handler: (req: Req) => Res): (req: Req) => Res;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const defineAction = (handler) => handler;
|
|
1
|
+
export const defineAction = (handler) => handler;
|