@ezetgalaxy/titan 26.13.4 → 26.13.6
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/package.json +2 -2
- package/templates/common/Dockerfile +1 -1
- package/templates/common/_gitignore +2 -0
- package/templates/common/app/{titan.d.ts → t.native.d.ts} +41 -35
- package/templates/common/app/t.native.js +39 -0
- package/templates/js/app/app.js +1 -4
- package/templates/{common → js}/eslint.config.js +0 -3
- package/templates/js/jsconfig.json +6 -0
- package/templates/js/package.json +1 -1
- package/templates/js/titan/dev.js +23 -0
- package/templates/rust-js/app/app.js +2 -4
- package/templates/rust-js/eslint.config.js +5 -0
- package/templates/rust-js/jsconfig.json +6 -0
- package/templates/rust-js/package.json +1 -1
- package/templates/rust-ts/app/actions/hello.ts +1 -1
- package/templates/rust-ts/app/app.ts +2 -4
- package/templates/rust-ts/eslint.config.js +12 -0
- package/templates/rust-ts/package.json +2 -1
- package/templates/rust-ts/titan/titan.d.ts +4 -114
- package/templates/rust-ts/titan/titan.js +0 -2
- package/templates/rust-ts/tsconfig.json +7 -1
- package/templates/ts/app/actions/hello.ts +1 -1
- package/templates/ts/app/app.ts +1 -4
- package/templates/ts/eslint.config.js +12 -0
- package/templates/ts/package.json +2 -1
- package/templates/ts/titan/titan.d.ts +1 -233
- package/templates/ts/titan/titan.js +3 -3
- package/templates/ts/tsconfig.json +14 -3
- package/templates/rust-ts/titan/runtime.d.ts +0 -1
- package/templates/rust-ts/titan/runtime.js +0 -1
- package/templates/ts/titan/runtime.d.ts +0 -1
- package/templates/ts/titan/runtime.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezetgalaxy/titan",
|
|
3
|
-
"version": "26.13.
|
|
3
|
+
"version": "26.13.6",
|
|
4
4
|
"description": "Titan Planet is a JavaScript-first backend framework that embeds JS actions into a Rust + Axum server and ships as a single native binary. Routes are compiled to static metadata; only actions run in the embedded JS runtime. No Node.js. No event loop in production.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "ezetgalaxy",
|
|
@@ -75,4 +75,4 @@
|
|
|
75
75
|
"@vitest/ui": "^4.0.17",
|
|
76
76
|
"vitest": "^4.0.17"
|
|
77
77
|
}
|
|
78
|
-
}
|
|
78
|
+
}
|
|
@@ -1,23 +1,45 @@
|
|
|
1
|
-
|
|
2
1
|
// -- Module Definitions (for imports from "titan") --
|
|
3
2
|
|
|
4
|
-
export interface
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export interface TitanRequest {
|
|
4
|
+
body: any;
|
|
5
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
6
|
+
path: string;
|
|
7
|
+
headers: Record<string, string | undefined>;
|
|
8
|
+
params: Record<string, string>;
|
|
9
|
+
query: Record<string, string>;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export function defineAction<T>(
|
|
13
|
+
handler: (req: TitanRequest) => T
|
|
14
|
+
): (req: TitanRequest) => T;
|
|
15
|
+
|
|
16
|
+
export const fetch: typeof t.fetch;
|
|
17
|
+
export const log: typeof t.log;
|
|
18
|
+
export const read: typeof t.read;
|
|
19
|
+
|
|
20
|
+
export const jwt: typeof t.jwt;
|
|
21
|
+
export const password: typeof t.password;
|
|
22
|
+
export const db: typeof t.db;
|
|
23
|
+
|
|
24
|
+
export const fs: typeof t.fs;
|
|
25
|
+
export const path: typeof t.path;
|
|
26
|
+
|
|
27
|
+
export const crypto: typeof t.crypto;
|
|
28
|
+
export const buffer: typeof t.buffer;
|
|
29
|
+
|
|
30
|
+
export const ls: typeof t.ls;
|
|
31
|
+
export const localStorage: typeof t.localStorage;
|
|
32
|
+
export const session: typeof t.session;
|
|
33
|
+
export const cookies: typeof t.cookies;
|
|
15
34
|
|
|
16
|
-
|
|
17
|
-
export const
|
|
18
|
-
export
|
|
35
|
+
export const os: typeof t.os;
|
|
36
|
+
export const net: typeof t.net;
|
|
37
|
+
export const proc: typeof t.proc;
|
|
19
38
|
|
|
20
|
-
export
|
|
39
|
+
export const time: typeof t.time;
|
|
40
|
+
export const url: typeof t.url;
|
|
41
|
+
export const response: typeof t.response;
|
|
42
|
+
export const valid: any;
|
|
21
43
|
|
|
22
44
|
// -- Global Definitions (Runtime Environment) --
|
|
23
45
|
|
|
@@ -39,7 +61,6 @@ export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (re
|
|
|
39
61
|
* const resp = drift t.fetch("http://api.titan.com");
|
|
40
62
|
* ```
|
|
41
63
|
*/
|
|
42
|
-
declare var drift: <T>(promise: Promise<T> | T) => T;
|
|
43
64
|
|
|
44
65
|
declare global {
|
|
45
66
|
/**
|
|
@@ -47,29 +68,12 @@ declare global {
|
|
|
47
68
|
*/
|
|
48
69
|
var drift: <T>(promise: Promise<T> | T) => T;
|
|
49
70
|
|
|
50
|
-
|
|
51
|
-
body: any;
|
|
52
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
53
|
-
path: string;
|
|
54
|
-
headers: {
|
|
55
|
-
host?: string;
|
|
56
|
-
"content-type"?: string;
|
|
57
|
-
"user-agent"?: string;
|
|
58
|
-
authorization?: string;
|
|
59
|
-
[key: string]: string | undefined;
|
|
60
|
-
};
|
|
61
|
-
params: Record<string, string>;
|
|
62
|
-
query: Record<string, string>;
|
|
63
|
-
}
|
|
71
|
+
|
|
64
72
|
|
|
65
73
|
interface DbConnection {
|
|
66
74
|
query(sql: string, params?: any[]): any[];
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
70
|
-
|
|
71
|
-
var req: TitanRequest;
|
|
72
|
-
|
|
73
77
|
interface TitanRuntimeUtils {
|
|
74
78
|
log(...args: any[]): void;
|
|
75
79
|
read(path: string): string;
|
|
@@ -77,12 +81,12 @@ declare global {
|
|
|
77
81
|
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
78
82
|
headers?: Record<string, string>;
|
|
79
83
|
body?: string | object;
|
|
80
|
-
}): {
|
|
84
|
+
}): Promise<{
|
|
81
85
|
ok: boolean;
|
|
82
86
|
status?: number;
|
|
83
87
|
body?: string;
|
|
84
88
|
error?: string;
|
|
85
|
-
}
|
|
89
|
+
}>;
|
|
86
90
|
|
|
87
91
|
jwt: {
|
|
88
92
|
sign(payload: object, secret: string, options?: { expiresIn?: string | number }): string;
|
|
@@ -247,3 +251,5 @@ declare global {
|
|
|
247
251
|
}
|
|
248
252
|
}
|
|
249
253
|
}
|
|
254
|
+
|
|
255
|
+
export { };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// titan.js - Named exports for users who prefer imports over the global `t`
|
|
2
|
+
|
|
3
|
+
export const fetch = t.fetch;
|
|
4
|
+
export const log = t.log;
|
|
5
|
+
export const read = t.read;
|
|
6
|
+
|
|
7
|
+
// Authentication & Security
|
|
8
|
+
export const jwt = t.jwt;
|
|
9
|
+
export const password = t.password;
|
|
10
|
+
|
|
11
|
+
// Database
|
|
12
|
+
export const db = t.db;
|
|
13
|
+
|
|
14
|
+
// File System & Path
|
|
15
|
+
export const fs = t.fs;
|
|
16
|
+
export const path = t.path;
|
|
17
|
+
|
|
18
|
+
// Crypto & Buffer
|
|
19
|
+
export const crypto = t.crypto;
|
|
20
|
+
export const buffer = t.buffer;
|
|
21
|
+
|
|
22
|
+
// Storage & Sessions
|
|
23
|
+
export const ls = t.ls;
|
|
24
|
+
export const localStorage = t.localStorage;
|
|
25
|
+
export const session = t.session;
|
|
26
|
+
export const cookies = t.cookies;
|
|
27
|
+
|
|
28
|
+
// System
|
|
29
|
+
export const os = t.os;
|
|
30
|
+
export const net = t.net;
|
|
31
|
+
export const proc = t.proc;
|
|
32
|
+
|
|
33
|
+
// Utilities
|
|
34
|
+
export const time = t.time;
|
|
35
|
+
export const url = t.url;
|
|
36
|
+
export const response = t.response;
|
|
37
|
+
export const valid = t.valid;
|
|
38
|
+
|
|
39
|
+
export const defineAction = (handler) => handler;
|
package/templates/js/app/app.js
CHANGED
|
@@ -247,6 +247,28 @@ async function startRustServer(retryCount = 0) {
|
|
|
247
247
|
});
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
function prepareRuntime() {
|
|
251
|
+
try {
|
|
252
|
+
const nm = path.join(process.cwd(), "node_modules");
|
|
253
|
+
const titanPkg = path.join(nm, "@titan");
|
|
254
|
+
const routePkg = path.join(titanPkg, "route");
|
|
255
|
+
|
|
256
|
+
if (!fs.existsSync(nm)) fs.mkdirSync(nm, { recursive: true });
|
|
257
|
+
if (!fs.existsSync(titanPkg)) fs.mkdirSync(titanPkg, { recursive: true });
|
|
258
|
+
|
|
259
|
+
if (!fs.existsSync(routePkg)) {
|
|
260
|
+
fs.mkdirSync(routePkg, { recursive: true });
|
|
261
|
+
fs.writeFileSync(path.join(routePkg, "package.json"), JSON.stringify({
|
|
262
|
+
name: "@titan/route",
|
|
263
|
+
main: "../../../titan/titan.js",
|
|
264
|
+
type: "module"
|
|
265
|
+
}, null, 2));
|
|
266
|
+
}
|
|
267
|
+
} catch (e) {
|
|
268
|
+
// Ignore errors
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
250
272
|
/**
|
|
251
273
|
* Rebuild JS runtime
|
|
252
274
|
* RULE: Only show "✖ Runtime preparation failed" on error
|
|
@@ -297,6 +319,7 @@ async function rebuild() {
|
|
|
297
319
|
}
|
|
298
320
|
|
|
299
321
|
async function startDev() {
|
|
322
|
+
prepareRuntime();
|
|
300
323
|
const root = process.cwd();
|
|
301
324
|
const actionsDir = path.join(root, "app", "actions");
|
|
302
325
|
let hasRust = false;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import t from "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import t from "@titan/route";
|
|
5
2
|
|
|
6
3
|
t.post("/hello").action("hello") // pass a json payload { "name": "titan" }
|
|
4
|
+
|
|
7
5
|
t.get("/rust").action("rust_hello") // This route uses a rust action
|
|
8
6
|
|
|
9
7
|
t.get("/").reply("Ready to land on Titan Planet 🚀");
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import t from "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import t from "@titan/route";
|
|
5
2
|
|
|
6
3
|
t.post("/hello").action("hello") // pass a json payload { "name": "titan" }
|
|
4
|
+
|
|
7
5
|
t.get("/rust").action("rust_hello") // This route uses a rust action
|
|
8
6
|
|
|
9
7
|
t.get("/").reply("Ready to land on Titan Planet 🚀");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
// -- Module Definitions (for imports from "titan") --
|
|
3
2
|
|
|
3
|
+
export * from "./runtime.js";
|
|
4
|
+
|
|
4
5
|
export interface RouteHandler {
|
|
5
6
|
reply(value: any): void;
|
|
6
7
|
action(name: string): void;
|
|
@@ -10,120 +11,9 @@ export interface TitanBuilder {
|
|
|
10
11
|
get(route: string): RouteHandler;
|
|
11
12
|
post(route: string): RouteHandler;
|
|
12
13
|
log(module: string, msg: string): void;
|
|
13
|
-
start(port?: number, msg?: string): Promise<void>;
|
|
14
|
+
start(port?: number, msg?: string, threads?: number): Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
// The default export from titan.js is the Builder
|
|
17
17
|
declare const builder: TitanBuilder;
|
|
18
18
|
export const Titan: TitanBuilder;
|
|
19
|
-
export default builder;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Define a Titan Action with type inference.
|
|
23
|
-
*/
|
|
24
|
-
export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// -- Global Definitions (Runtime Environment) --
|
|
28
|
-
|
|
29
|
-
declare global {
|
|
30
|
-
/**
|
|
31
|
-
* The Titan Request Object passed to actions.
|
|
32
|
-
*/
|
|
33
|
-
interface TitanRequest {
|
|
34
|
-
body: any;
|
|
35
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
36
|
-
path: string;
|
|
37
|
-
headers: {
|
|
38
|
-
host?: string;
|
|
39
|
-
"content-type"?: string;
|
|
40
|
-
"user-agent"?: string;
|
|
41
|
-
authorization?: string;
|
|
42
|
-
[key: string]: string | undefined;
|
|
43
|
-
};
|
|
44
|
-
params: Record<string, string>;
|
|
45
|
-
query: Record<string, string>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface DbConnection {
|
|
49
|
-
/**
|
|
50
|
-
* Execute a SQL query.
|
|
51
|
-
* @param sql The SQL query string.
|
|
52
|
-
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
53
|
-
*/
|
|
54
|
-
query(sql: string, params?: any[]): any[];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Global defineAction (available without import in runtime, though imports are preferred in TS)
|
|
59
|
-
*/
|
|
60
|
-
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Global Request Object
|
|
64
|
-
* Available automatically in actions.
|
|
65
|
-
*/
|
|
66
|
-
var req: TitanRequest;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Titan Runtime Utilities
|
|
70
|
-
* (Available globally in the runtime, e.g. inside actions)
|
|
71
|
-
*/
|
|
72
|
-
interface TitanRuntimeUtils {
|
|
73
|
-
/**
|
|
74
|
-
* Log messages to the server console with Titan formatting.
|
|
75
|
-
*/
|
|
76
|
-
log(...args: any[]): void;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Read a file contents as string.
|
|
80
|
-
* @param path Relative path to the file from project root.
|
|
81
|
-
*/
|
|
82
|
-
read(path: string): string;
|
|
83
|
-
|
|
84
|
-
fetch(url: string, options?: {
|
|
85
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
86
|
-
headers?: Record<string, string>;
|
|
87
|
-
body?: string | object;
|
|
88
|
-
}): {
|
|
89
|
-
ok: boolean;
|
|
90
|
-
status?: number;
|
|
91
|
-
body?: string;
|
|
92
|
-
error?: string;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
jwt: {
|
|
96
|
-
sign(
|
|
97
|
-
payload: object,
|
|
98
|
-
secret: string,
|
|
99
|
-
options?: { expiresIn?: string | number }
|
|
100
|
-
): string;
|
|
101
|
-
verify(token: string, secret: string): any;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
password: {
|
|
105
|
-
hash(password: string): string;
|
|
106
|
-
verify(password: string, hash: string): boolean;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
db: {
|
|
110
|
-
connect(url: string): DbConnection;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Titan Validator (Zod-compatible)
|
|
115
|
-
*/
|
|
116
|
-
valid: any;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Titan Runtime Utilities
|
|
121
|
-
* (Available globally in the runtime, e.g. inside actions)
|
|
122
|
-
*/
|
|
123
|
-
const t: TitanRuntimeUtils;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Titan Runtime Utilities (Alias for t)
|
|
127
|
-
*/
|
|
128
|
-
const Titan: TitanRuntimeUtils;
|
|
129
|
-
}
|
|
19
|
+
export default builder;
|
package/templates/ts/app/app.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
// -- Module Definitions (for imports from "titan") --
|
|
3
2
|
|
|
4
3
|
export interface RouteHandler {
|
|
@@ -15,235 +14,4 @@ export interface TitanBuilder {
|
|
|
15
14
|
|
|
16
15
|
declare const builder: TitanBuilder;
|
|
17
16
|
export const Titan: TitanBuilder;
|
|
18
|
-
export default builder;
|
|
19
|
-
|
|
20
|
-
export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
21
|
-
|
|
22
|
-
// -- Global Definitions (Runtime Environment) --
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* # Drift - Orchestration Engine
|
|
26
|
-
*
|
|
27
|
-
* Revolutionary system for high-performance asynchronous operations using a **Deterministic Replay-based Suspension** model.
|
|
28
|
-
*
|
|
29
|
-
* ## Mechanism
|
|
30
|
-
* Drift utilizes a suspension model similar to **Algebraic Effects**. When a `drift()` operation is encountered,
|
|
31
|
-
* the runtime suspends the isolate, offloads the task to the background Tokio executor, and frees the isolate
|
|
32
|
-
* to handle other requests. Upon completion, the code is efficiently **re-played** with the result injected.
|
|
33
|
-
*
|
|
34
|
-
* @param promise - The promise or expression to drift.
|
|
35
|
-
* @returns The resolved value of the input promise.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```javascript
|
|
39
|
-
* const resp = drift t.fetch("http://api.titan.com");
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare var drift: <T>(promise: Promise<T> | T) => T;
|
|
43
|
-
|
|
44
|
-
declare global {
|
|
45
|
-
/**
|
|
46
|
-
* Titan Global Drift
|
|
47
|
-
*/
|
|
48
|
-
var drift: <T>(promise: Promise<T> | T) => T;
|
|
49
|
-
|
|
50
|
-
interface TitanRequest {
|
|
51
|
-
body: any;
|
|
52
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
53
|
-
path: string;
|
|
54
|
-
headers: {
|
|
55
|
-
host?: string;
|
|
56
|
-
"content-type"?: string;
|
|
57
|
-
"user-agent"?: string;
|
|
58
|
-
authorization?: string;
|
|
59
|
-
[key: string]: string | undefined;
|
|
60
|
-
};
|
|
61
|
-
params: Record<string, string>;
|
|
62
|
-
query: Record<string, string>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface DbConnection {
|
|
66
|
-
query(sql: string, params?: any[]): any[];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
70
|
-
|
|
71
|
-
var req: TitanRequest;
|
|
72
|
-
|
|
73
|
-
interface TitanRuntimeUtils {
|
|
74
|
-
log(...args: any[]): void;
|
|
75
|
-
read(path: string): string;
|
|
76
|
-
fetch(url: string, options?: {
|
|
77
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
78
|
-
headers?: Record<string, string>;
|
|
79
|
-
body?: string | object;
|
|
80
|
-
}): {
|
|
81
|
-
ok: boolean;
|
|
82
|
-
status?: number;
|
|
83
|
-
body?: string;
|
|
84
|
-
error?: string;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
jwt: {
|
|
88
|
-
sign(payload: object, secret: string, options?: { expiresIn?: string | number }): string;
|
|
89
|
-
verify(token: string, secret: string): any;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
password: {
|
|
93
|
-
hash(password: string): string;
|
|
94
|
-
verify(password: string, hash: string): boolean;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/** ### `db` (Database Connection) */
|
|
98
|
-
db: {
|
|
99
|
-
connect(url: string): DbConnection;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/** ### `fs` (File System) */
|
|
103
|
-
fs: TitanCore.FileSystem;
|
|
104
|
-
|
|
105
|
-
/** ### `path` (Path Manipulation) */
|
|
106
|
-
path: TitanCore.Path;
|
|
107
|
-
|
|
108
|
-
/** ### `crypto` (Cryptography) */
|
|
109
|
-
crypto: TitanCore.Crypto;
|
|
110
|
-
|
|
111
|
-
/** ### `buffer` (Buffer Utilities) */
|
|
112
|
-
buffer: TitanCore.BufferModule;
|
|
113
|
-
|
|
114
|
-
/** ### `ls` / `localStorage` (Persistent Storage) */
|
|
115
|
-
ls: TitanCore.LocalStorage;
|
|
116
|
-
localStorage: TitanCore.LocalStorage;
|
|
117
|
-
|
|
118
|
-
/** ### `session` (Server-side Sessions) */
|
|
119
|
-
session: TitanCore.Session;
|
|
120
|
-
|
|
121
|
-
/** ### `cookies` (HTTP Cookies) */
|
|
122
|
-
cookies: TitanCore.Cookies;
|
|
123
|
-
|
|
124
|
-
/** ### `os` (Operating System) */
|
|
125
|
-
os: TitanCore.OS;
|
|
126
|
-
|
|
127
|
-
/** ### `net` (Network) */
|
|
128
|
-
net: TitanCore.Net;
|
|
129
|
-
|
|
130
|
-
/** ### `proc` (Process) */
|
|
131
|
-
proc: TitanCore.Process;
|
|
132
|
-
|
|
133
|
-
/** ### `time` (Time) */
|
|
134
|
-
time: TitanCore.Time;
|
|
135
|
-
|
|
136
|
-
/** ### `url` (URL) */
|
|
137
|
-
url: TitanCore.URLModule;
|
|
138
|
-
|
|
139
|
-
/** ### `response` (HTTP Response Builder) */
|
|
140
|
-
response: TitanCore.ResponseModule;
|
|
141
|
-
|
|
142
|
-
valid: any;
|
|
143
|
-
[key: string]: any;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const t: TitanRuntimeUtils;
|
|
147
|
-
const Titan: TitanRuntimeUtils;
|
|
148
|
-
|
|
149
|
-
namespace TitanCore {
|
|
150
|
-
interface FileSystem {
|
|
151
|
-
readFile(path: string): string;
|
|
152
|
-
writeFile(path: string, content: string): void;
|
|
153
|
-
readdir(path: string): string[];
|
|
154
|
-
mkdir(path: string): void;
|
|
155
|
-
exists(path: string): boolean;
|
|
156
|
-
stat(path: string): { size: number, isFile: boolean, isDir: boolean, modified: number };
|
|
157
|
-
remove(path: string): void;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
interface Path {
|
|
161
|
-
join(...args: string[]): string;
|
|
162
|
-
resolve(...args: string[]): string;
|
|
163
|
-
extname(path: string): string;
|
|
164
|
-
dirname(path: string): string;
|
|
165
|
-
basename(path: string): string;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
interface Crypto {
|
|
169
|
-
hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): string;
|
|
170
|
-
randomBytes(size: number): string;
|
|
171
|
-
uuid(): string;
|
|
172
|
-
compare(hash: string, target: string): boolean;
|
|
173
|
-
encrypt(algorithm: string, key: string, plaintext: string): string;
|
|
174
|
-
decrypt(algorithm: string, key: string, ciphertext: string): string;
|
|
175
|
-
hashKeyed(algorithm: 'hmac-sha256' | 'hmac-sha512', key: string, message: string): string;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
interface BufferModule {
|
|
179
|
-
fromBase64(str: string): Uint8Array;
|
|
180
|
-
toBase64(bytes: Uint8Array | string): string;
|
|
181
|
-
fromHex(str: string): Uint8Array;
|
|
182
|
-
toHex(bytes: Uint8Array | string): string;
|
|
183
|
-
fromUtf8(str: string): Uint8Array;
|
|
184
|
-
toUtf8(bytes: Uint8Array): string;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
interface LocalStorage {
|
|
188
|
-
get(key: string): string | null;
|
|
189
|
-
set(key: string, value: string): void;
|
|
190
|
-
remove(key: string): void;
|
|
191
|
-
clear(): void;
|
|
192
|
-
keys(): string[];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
interface Session {
|
|
196
|
-
get(sessionId: string, key: string): string | null;
|
|
197
|
-
set(sessionId: string, key: string, value: string): void;
|
|
198
|
-
delete(sessionId: string, key: string): void;
|
|
199
|
-
clear(sessionId: string): void;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
interface Cookies {
|
|
203
|
-
get(req: any, name: string): string | null;
|
|
204
|
-
set(res: any, name: string, value: string, options?: any): void;
|
|
205
|
-
delete(res: any, name: string): void;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
interface OS {
|
|
209
|
-
platform(): string;
|
|
210
|
-
cpus(): number;
|
|
211
|
-
totalMemory(): number;
|
|
212
|
-
freeMemory(): number;
|
|
213
|
-
tmpdir(): string;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
interface Net {
|
|
217
|
-
resolveDNS(hostname: string): string[];
|
|
218
|
-
ip(): string;
|
|
219
|
-
ping(host: string): boolean;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
interface Process {
|
|
223
|
-
pid(): number;
|
|
224
|
-
uptime(): number;
|
|
225
|
-
memory(): Record<string, any>;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
interface Time {
|
|
229
|
-
sleep(ms: number): void;
|
|
230
|
-
now(): number;
|
|
231
|
-
timestamp(): string;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
interface URLModule {
|
|
235
|
-
parse(url: string): any;
|
|
236
|
-
format(urlObj: any): string;
|
|
237
|
-
SearchParams: any;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
interface ResponseModule {
|
|
241
|
-
(options: any): any;
|
|
242
|
-
text(content: string, status?: number): any;
|
|
243
|
-
html(content: string, status?: number): any;
|
|
244
|
-
json(content: any, status?: number): any;
|
|
245
|
-
redirect(url: string, status?: number): any;
|
|
246
|
-
empty(status?: number): any;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
17
|
+
export default builder;
|
|
@@ -2,7 +2,6 @@ import { bundle } from "./bundle.js";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
|
-
export * from "./runtime.js";
|
|
6
5
|
|
|
7
6
|
const cyan = (t) => `\x1b[36m${t}\x1b[0m`;
|
|
8
7
|
const green = (t) => `\x1b[32m${t}\x1b[0m`;
|
|
@@ -78,8 +77,9 @@ const t = {
|
|
|
78
77
|
* @param {number} [port=3000]
|
|
79
78
|
* @param {string} [msg=""]
|
|
80
79
|
* @param {number} [threads]
|
|
80
|
+
* @param {number} [stack_mb]
|
|
81
81
|
*/
|
|
82
|
-
async start(port = 3000, msg = "", threads) {
|
|
82
|
+
async start(port = 3000, msg = "", threads, stack_mb) {
|
|
83
83
|
try {
|
|
84
84
|
console.log(cyan("[Titan] Preparing runtime..."));
|
|
85
85
|
await bundle();
|
|
@@ -96,7 +96,7 @@ const t = {
|
|
|
96
96
|
routesPath,
|
|
97
97
|
JSON.stringify(
|
|
98
98
|
{
|
|
99
|
-
__config: { port, threads },
|
|
99
|
+
__config: { port, threads, stack_mb },
|
|
100
100
|
routes,
|
|
101
101
|
__dynamic_routes: Object.values(dynamicRoutes).flat()
|
|
102
102
|
},
|
|
@@ -9,8 +9,19 @@
|
|
|
9
9
|
"skipLibCheck": true,
|
|
10
10
|
"baseUrl": ".",
|
|
11
11
|
"paths": {
|
|
12
|
-
"
|
|
12
|
+
"@titan/native": [
|
|
13
|
+
"app/t.native"
|
|
14
|
+
],
|
|
15
|
+
"@titan/route": [
|
|
16
|
+
"./titan/titan"
|
|
17
|
+
],
|
|
18
|
+
"*": [
|
|
19
|
+
"./app/*"
|
|
20
|
+
]
|
|
13
21
|
}
|
|
14
22
|
},
|
|
15
|
-
"include": [
|
|
16
|
-
|
|
23
|
+
"include": [
|
|
24
|
+
"app/**/*",
|
|
25
|
+
"titan/**/*"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function defineAction<Req = any, Res = any>(handler: (req: Req) => Res): (req: Req) => Res;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const defineAction = (handler) => handler;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function defineAction<Req = any, Res = any>(handler: (req: Req) => Res): (req: Req) => Res;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const defineAction = (handler) => handler;
|