@titanpl/core 2.0.9 → 2.1.1
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 +80 -1
- package/configure.js +50 -50
- package/globals.d.ts +3 -0
- package/index.d.ts +748 -265
- package/index.js +111 -54
- package/native/target/release/titan_core.dll +0 -0
- package/package.json +1 -1
- package/titan.json +22 -2
- package/native/target/release/libtitan_core.so +0 -0
package/index.d.ts
CHANGED
|
@@ -1,265 +1,748 @@
|
|
|
1
|
-
// Type definitions for @titanpl/core
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
1
|
+
// Type definitions for @titanpl/core
|
|
2
|
+
// Project: https://github.com/titanpl/core
|
|
3
|
+
// Definitions by: TitanPL Team
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Titan {
|
|
7
|
+
interface Runtime {
|
|
8
|
+
/**
|
|
9
|
+
* # @titanpl/core
|
|
10
|
+
* The official Core Standard Library for Titan Planet - a high-performance JavaScript runtime extension.
|
|
11
|
+
*
|
|
12
|
+
* ## Overview
|
|
13
|
+
* `@titanpl/core` provides essential standard library modules for Titan applications, bridging high-performance Rust native implementations with an easy-to-use JavaScript API.
|
|
14
|
+
*
|
|
15
|
+
* ## Usage
|
|
16
|
+
* The extension automatically attaches to the Titan runtime. You can access it via `t.core` or the `t` global object alias.
|
|
17
|
+
*
|
|
18
|
+
* ```javascript
|
|
19
|
+
* // Access via t.core (Recommended)
|
|
20
|
+
* const { fs, crypto, os } = t.core;
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
"@titanpl/core": TitanCore.Core;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Alias for @titanpl/core
|
|
27
|
+
*/
|
|
28
|
+
"titan-core": TitanCore.Core;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ### `fs` (File System)
|
|
32
|
+
* Perform synchronous file system operations using high-performance native bindings.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```javascript
|
|
36
|
+
* const content = t.fs.readFile("config.json");
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
fs: TitanCore.FileSystem;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ### `path` (Path Manipulation)
|
|
43
|
+
* Utilities for handling file paths across different operating systems.
|
|
44
|
+
*/
|
|
45
|
+
path: TitanCore.Path;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* ### `crypto` (Cryptography)
|
|
49
|
+
* Cryptographic utilities using native Rust implementations.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```javascript
|
|
53
|
+
* const hash = t.crypto.hash("sha256", "hii");
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
crypto: TitanCore.Crypto;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Operating System API - Deep system introspection.
|
|
60
|
+
*
|
|
61
|
+
* Access CPU counts, memory status, and platform-specific environment details.
|
|
62
|
+
*
|
|
63
|
+
* @use Multi-threaded scaling, resource monitoring, and platform-aware logic.
|
|
64
|
+
*/
|
|
65
|
+
os: TitanCore.OS;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Network API - Low-level networking and DNS utilities.
|
|
69
|
+
*
|
|
70
|
+
* Resolve hostnames and perform network health checks with sub-millisecond precision.
|
|
71
|
+
*
|
|
72
|
+
* @use Discovering service IP addresses, verifying network connectivity.
|
|
73
|
+
*/
|
|
74
|
+
net: TitanCore.Net;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Process API - Runtime execution control and monitoring.
|
|
78
|
+
*
|
|
79
|
+
* Monitor the current Titan process, its PID, uptime, and memory heap footprint.
|
|
80
|
+
*
|
|
81
|
+
* @use Health checks, performance profiling, and process identification.
|
|
82
|
+
*/
|
|
83
|
+
proc: TitanCore.Process;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Time API - High-resolution timing and scheduling.
|
|
87
|
+
*
|
|
88
|
+
* Precise timestamps and blocking delays for synchronized operations.
|
|
89
|
+
*
|
|
90
|
+
* @use Benchmarking actions, adding retry delays, and generation of ISO timestamps.
|
|
91
|
+
* @suggestion Use `t.time.sleep` sparingly as it pauses the execution isolate.
|
|
92
|
+
*/
|
|
93
|
+
time: TitanCore.Time;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* URL API - Robust URL parsing and construction.
|
|
97
|
+
*
|
|
98
|
+
* compliant URL parser that breaks down protocols, hostnames, and query parameters.
|
|
99
|
+
*
|
|
100
|
+
* @use Parsing incoming request URLs, building outgoing fetch URLs.
|
|
101
|
+
*/
|
|
102
|
+
url: TitanCore.URLModule;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Buffer API - High-performance binary data handling.
|
|
106
|
+
*
|
|
107
|
+
* Optimized for Base64 coding, Hex conversion, and UTF-8 byte stream management.
|
|
108
|
+
*
|
|
109
|
+
* @use Handling file uploads, processing binary payloads, and hashing non-string data.
|
|
110
|
+
*/
|
|
111
|
+
buffer: TitanCore.BufferModule;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Local Storage API - High-performance in-memory key-value store.
|
|
115
|
+
*
|
|
116
|
+
* **Performance:** ~150,000+ operations/sec.
|
|
117
|
+
*
|
|
118
|
+
* - ⚡ RwLock<HashMap> implementation (~0.006ms per read)
|
|
119
|
+
* - 🚀 ~1000x faster than file-based storage
|
|
120
|
+
* - 💾 In-memory only (volatile)
|
|
121
|
+
*
|
|
122
|
+
* @use Perfect for caching frequently accessed data within a single process.
|
|
123
|
+
* @suggestion Use for metadata, temporary counters, and cross-action shared state.
|
|
124
|
+
*/
|
|
125
|
+
ls: TitanCore.LocalStorage;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Alias for `t.ls` - Local Storage
|
|
129
|
+
*/
|
|
130
|
+
localStorage: TitanCore.LocalStorage;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Session API - High-performance session management.
|
|
134
|
+
*
|
|
135
|
+
* Isolate data per-user session with sub-millisecond access times.
|
|
136
|
+
*
|
|
137
|
+
* @use Shopping carts, user preferences, and authentication tokens.
|
|
138
|
+
* @suggestion Store JSON strings and parse them on retrieval for complex objects.
|
|
139
|
+
*/
|
|
140
|
+
session: TitanCore.Session;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Cookie API - Standard-compliant HTTP cookie management.
|
|
144
|
+
*
|
|
145
|
+
* Easily set, retrieve, and delete cookies with support for HTTPOnly and SameSite.
|
|
146
|
+
*
|
|
147
|
+
* @use Tracking user sessions, storing client-side preferences.
|
|
148
|
+
* @suggestion Always use `httpOnly: true` for sensitive session cookies.
|
|
149
|
+
*/
|
|
150
|
+
cookies: TitanCore.Cookies;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* ### **`response` (HTTP Response Builder)**
|
|
154
|
+
* Utilities for constructing HTTP responses.
|
|
155
|
+
* All response methods return a standardized ResponseObject consumed by the Titan Rust HTTP server.
|
|
156
|
+
*/
|
|
157
|
+
response: TitanCore.ResponseModule;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Core namespace - Unified access to all APIs
|
|
161
|
+
*/
|
|
162
|
+
core: TitanCore.Core;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* # Drift - Orchestration Engine
|
|
168
|
+
*
|
|
169
|
+
* Revolutionary system for high-performance asynchronous operations using a **Deterministic Replay-based Suspension** model.
|
|
170
|
+
*
|
|
171
|
+
* ## Mechanism
|
|
172
|
+
* Drift utilizes a suspension model similar to **Algebraic Effects**. When a `drift()` operation is encountered,
|
|
173
|
+
* the runtime suspends the isolate, offloads the task to the background Tokio executor, and frees the isolate
|
|
174
|
+
* to handle other requests. Upon completion, the code is efficiently **re-played** with the result injected.
|
|
175
|
+
*
|
|
176
|
+
* @param promise - The promise or expression to drift.
|
|
177
|
+
* @returns The resolved value of the input promise.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```javascript
|
|
181
|
+
* const resp = drift(t.fetch("http://api.titan.com"));
|
|
182
|
+
* console.log(resp.body);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
function drift<T>(promise: Promise<T> | T): T;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Titan Core Global Namespace
|
|
189
|
+
*/
|
|
190
|
+
namespace TitanCore {
|
|
191
|
+
/**
|
|
192
|
+
* Core module containing all standard library APIs
|
|
193
|
+
*/
|
|
194
|
+
interface Core {
|
|
195
|
+
fs: FileSystem;
|
|
196
|
+
path: Path;
|
|
197
|
+
crypto: Crypto;
|
|
198
|
+
os: OS;
|
|
199
|
+
net: Net;
|
|
200
|
+
proc: Process;
|
|
201
|
+
time: Time;
|
|
202
|
+
url: URLModule;
|
|
203
|
+
buffer: BufferModule;
|
|
204
|
+
ls: LocalStorage;
|
|
205
|
+
session: Session;
|
|
206
|
+
cookies: Cookies;
|
|
207
|
+
response: ResponseModule;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ==================== File System ====================
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* File System API - Native file operations backed by Rust
|
|
214
|
+
*/
|
|
215
|
+
interface FileSystem {
|
|
216
|
+
/**
|
|
217
|
+
* Read file content as UTF-8 string.
|
|
218
|
+
* @param path File path.
|
|
219
|
+
*/
|
|
220
|
+
readFile(path: string): string;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Write string content to file.
|
|
224
|
+
* @param path Target file path.
|
|
225
|
+
* @param content String content to write.
|
|
226
|
+
*/
|
|
227
|
+
writeFile(path: string, content: string): void;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* List directory contents.
|
|
231
|
+
* @param path Directory path.
|
|
232
|
+
*/
|
|
233
|
+
readdir(path: string): string[];
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Create a directory (recursive).
|
|
237
|
+
* @param path Directory path to create.
|
|
238
|
+
*/
|
|
239
|
+
mkdir(path: string): void;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Check if path exists.
|
|
243
|
+
* @param path Path to check.
|
|
244
|
+
*/
|
|
245
|
+
exists(path: string): boolean;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Get file statistics.
|
|
249
|
+
* @param path Path to stat.
|
|
250
|
+
* @returns Statistics object `{ type: "file" | "directory", size: number }`.
|
|
251
|
+
*/
|
|
252
|
+
stat(path: string): Stats;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Remove file or directory (recursive).
|
|
256
|
+
* @param path Path to remove.
|
|
257
|
+
*/
|
|
258
|
+
remove(path: string): void;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* File/directory statistics
|
|
263
|
+
*/
|
|
264
|
+
interface Stats {
|
|
265
|
+
/** File size in bytes */
|
|
266
|
+
size: number;
|
|
267
|
+
/** True if path is a file */
|
|
268
|
+
isFile: boolean;
|
|
269
|
+
/** True if path is a directory */
|
|
270
|
+
isDir: boolean;
|
|
271
|
+
/** Last modified timestamp (milliseconds since epoch) */
|
|
272
|
+
modified: number;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ==================== Path ====================
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Path API - Cross-platform path manipulation
|
|
279
|
+
*/
|
|
280
|
+
interface Path {
|
|
281
|
+
/**
|
|
282
|
+
* Joins path segments using platform-specific separator
|
|
283
|
+
* @param args - Path segments to join
|
|
284
|
+
* @returns Joined path
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* t.path.join('app', 'actions', 'test.js') // "app/actions/test.js"
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
join(...args: string[]): string;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Resolves path segments to an absolute path
|
|
294
|
+
* @param args - Path segments to resolve
|
|
295
|
+
* @returns Absolute path
|
|
296
|
+
*/
|
|
297
|
+
resolve(...args: string[]): string;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Returns the file extension including the dot
|
|
301
|
+
* @param path - File path
|
|
302
|
+
* @returns Extension (e.g., ".js", ".json") or empty string
|
|
303
|
+
*/
|
|
304
|
+
extname(path: string): string;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Returns the directory name of a path
|
|
308
|
+
* @param path - File or directory path
|
|
309
|
+
* @returns Parent directory path
|
|
310
|
+
*/
|
|
311
|
+
dirname(path: string): string;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Returns the last portion of a path (filename)
|
|
315
|
+
* @param path - Path to extract basename from
|
|
316
|
+
* @returns Filename or directory name
|
|
317
|
+
*/
|
|
318
|
+
basename(path: string): string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ==================== Crypto ====================
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Cryptography API - Hashing, encryption, and random generation
|
|
325
|
+
*/
|
|
326
|
+
interface Crypto {
|
|
327
|
+
/**
|
|
328
|
+
* Hash data.
|
|
329
|
+
* @param algorithm Algorithm to use: `sha256`, `sha512`, `md5`.
|
|
330
|
+
* @param data Data to hash.
|
|
331
|
+
*/
|
|
332
|
+
hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): string;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Generate random bytes as hex string.
|
|
336
|
+
* @param size Number of bytes.
|
|
337
|
+
*/
|
|
338
|
+
randomBytes(size: number): string;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Generate a UUID v4.
|
|
342
|
+
*/
|
|
343
|
+
uuid(): string;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Constant-time comparison to prevent timing attacks.
|
|
347
|
+
* @param hash The reference hash.
|
|
348
|
+
* @param target The hash to compare against.
|
|
349
|
+
*/
|
|
350
|
+
compare(hash: string, target: string): boolean;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* AES-256-GCM Encrypt.
|
|
354
|
+
* @param algorithm Encryption algorithm.
|
|
355
|
+
* @param key 32-byte key.
|
|
356
|
+
* @param plaintext Data to encrypt.
|
|
357
|
+
* @returns Base64 encoded ciphertext.
|
|
358
|
+
*/
|
|
359
|
+
encrypt(algorithm: string, key: string, plaintext: string): string;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* AES-256-GCM Decrypt.
|
|
363
|
+
* @param algorithm Decryption algorithm.
|
|
364
|
+
* @param key Matching 32-byte key.
|
|
365
|
+
* @param ciphertext Base64 encoded ciphertext.
|
|
366
|
+
*/
|
|
367
|
+
decrypt(algorithm: string, key: string, ciphertext: string): string;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* HMAC calculation.
|
|
371
|
+
* @param algorithm `hmac-sha256` or `hmac-sha512`.
|
|
372
|
+
* @param key Secret key.
|
|
373
|
+
* @param message Message to sign.
|
|
374
|
+
*/
|
|
375
|
+
hashKeyed(algorithm: 'hmac-sha256' | 'hmac-sha512', key: string, message: string): string;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ==================== OS ====================
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Operating System API - System information
|
|
382
|
+
*/
|
|
383
|
+
interface OS {
|
|
384
|
+
/** OS platform (e.g., `linux`, `windows`). */
|
|
385
|
+
platform(): string;
|
|
386
|
+
/** Number of CPU cores. */
|
|
387
|
+
cpus(): number;
|
|
388
|
+
/** Total system memory in bytes. */
|
|
389
|
+
totalMemory(): number;
|
|
390
|
+
/** Free system memory in bytes. */
|
|
391
|
+
freeMemory(): number;
|
|
392
|
+
/** Temporary directory path. */
|
|
393
|
+
tmpdir(): string;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// ==================== Network ====================
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Network API - DNS resolution and IP utilities
|
|
400
|
+
*/
|
|
401
|
+
interface Net {
|
|
402
|
+
/** Resolve hostname to IP addresses. */
|
|
403
|
+
resolveDNS(hostname: string): string[];
|
|
404
|
+
/** Get local IP address. */
|
|
405
|
+
ip(): string;
|
|
406
|
+
/** Ping (not fully implemented). */
|
|
407
|
+
ping(host: string): boolean;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ==================== Process ====================
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Process API - Runtime process information
|
|
414
|
+
*/
|
|
415
|
+
interface Process {
|
|
416
|
+
/** Process ID. */
|
|
417
|
+
pid(): number;
|
|
418
|
+
/** System uptime in seconds. */
|
|
419
|
+
uptime(): number;
|
|
420
|
+
/** Memory usage statistics. */
|
|
421
|
+
memory(): Record<string, any>;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ==================== Time ====================
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Time API - Time utilities and delays
|
|
428
|
+
*/
|
|
429
|
+
interface Time {
|
|
430
|
+
/** Sleep for specified milliseconds. */
|
|
431
|
+
sleep(ms: number): void;
|
|
432
|
+
/** Current timestamp (ms). */
|
|
433
|
+
now(): number;
|
|
434
|
+
/** Current ISO timestamp. */
|
|
435
|
+
timestamp(): string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// ==================== URL ====================
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* URL API - URL parsing and manipulation
|
|
442
|
+
*/
|
|
443
|
+
interface URLModule {
|
|
444
|
+
/**
|
|
445
|
+
* Parses a URL string into components
|
|
446
|
+
* @param url - URL string to parse
|
|
447
|
+
* @returns Parsed URL object
|
|
448
|
+
*/
|
|
449
|
+
parse(url: string): UrlObject;
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Formats a URL object into a string
|
|
453
|
+
* @param urlObj - URL object to format
|
|
454
|
+
* @returns URL string
|
|
455
|
+
*/
|
|
456
|
+
format(urlObj: any): string;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* URLSearchParams constructor
|
|
460
|
+
*/
|
|
461
|
+
SearchParams: typeof TitanURLSearchParams;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Parsed URL components
|
|
466
|
+
*/
|
|
467
|
+
interface UrlObject {
|
|
468
|
+
protocol: string;
|
|
469
|
+
hostname: string;
|
|
470
|
+
port: string;
|
|
471
|
+
pathname: string;
|
|
472
|
+
search: string;
|
|
473
|
+
hash: string;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* URLSearchParams - Query string parsing and manipulation
|
|
478
|
+
*/
|
|
479
|
+
class TitanURLSearchParams {
|
|
480
|
+
constructor(init?: string | Record<string, string>);
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Gets a query parameter value
|
|
484
|
+
* @param key - Parameter name
|
|
485
|
+
* @returns Parameter value or null
|
|
486
|
+
*/
|
|
487
|
+
get(key: string): string | null;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Sets a query parameter
|
|
491
|
+
* @param key - Parameter name
|
|
492
|
+
* @param value - Parameter value
|
|
493
|
+
*/
|
|
494
|
+
set(key: string, value: string): void;
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Checks if parameter exists
|
|
498
|
+
* @param key - Parameter name
|
|
499
|
+
* @returns true if exists
|
|
500
|
+
*/
|
|
501
|
+
has(key: string): boolean;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Deletes a query parameter
|
|
505
|
+
* @param key - Parameter name
|
|
506
|
+
*/
|
|
507
|
+
delete(key: string): void;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Converts to query string
|
|
511
|
+
* @returns URL-encoded query string
|
|
512
|
+
*/
|
|
513
|
+
toString(): string;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Returns all key-value pairs
|
|
517
|
+
* @returns Array of [key, value] tuples
|
|
518
|
+
*/
|
|
519
|
+
entries(): [string, string][];
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Returns all parameter names
|
|
523
|
+
* @returns Array of keys
|
|
524
|
+
*/
|
|
525
|
+
keys(): string[];
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Returns all parameter values
|
|
529
|
+
* @returns Array of values
|
|
530
|
+
*/
|
|
531
|
+
values(): string[];
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// ==================== Buffer ====================
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Buffer API - Binary data encoding and decoding
|
|
538
|
+
*/
|
|
539
|
+
interface BufferModule {
|
|
540
|
+
/** Decode Base64 string. */
|
|
541
|
+
fromBase64(str: string): Uint8Array;
|
|
542
|
+
/** Encode to Base64. */
|
|
543
|
+
toBase64(bytes: Uint8Array | string): string;
|
|
544
|
+
/** Decode Hex string. */
|
|
545
|
+
fromHex(str: string): Uint8Array;
|
|
546
|
+
/** Encode to Hex. */
|
|
547
|
+
toHex(bytes: Uint8Array | string): string;
|
|
548
|
+
/** Encode UTF-8 string to bytes. */
|
|
549
|
+
fromUtf8(str: string): Uint8Array;
|
|
550
|
+
/** Decode bytes to UTF-8 string. */
|
|
551
|
+
toUtf8(bytes: Uint8Array): string;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// ==================== Local Storage ====================
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Local Storage API - High-performance in-memory key-value store
|
|
558
|
+
*
|
|
559
|
+
* **Implementation:** Native Rust RwLock<HashMap>
|
|
560
|
+
*
|
|
561
|
+
* **Performance Benchmarks (10,000 operations):**
|
|
562
|
+
* - 📖 Read: ~156,250 ops/sec (0.0064ms avg)
|
|
563
|
+
* - ✍️ Write: ~89,286 ops/sec (0.0112ms avg)
|
|
564
|
+
* - 🔄 Mixed: ~125,000 ops/sec (0.008ms avg)
|
|
565
|
+
*
|
|
566
|
+
* **Characteristics:**
|
|
567
|
+
* - ⚡ ~1000x faster than file-based storage
|
|
568
|
+
* - 💾 In-memory only (data lost on server restart)
|
|
569
|
+
* - 🔒 Thread-safe with RwLock (multiple readers, single writer)
|
|
570
|
+
* - 🚫 Not shared across multiple processes
|
|
571
|
+
*
|
|
572
|
+
* **Use Cases:**
|
|
573
|
+
* - Request-scoped state sharing
|
|
574
|
+
* - Temporary caching within a process
|
|
575
|
+
* - High-frequency read/write operations
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* // Store user data temporarily
|
|
580
|
+
* t.ls.set('user:123', JSON.stringify({ name: 'Alice', role: 'admin' }));
|
|
581
|
+
*
|
|
582
|
+
* // Retrieve and parse
|
|
583
|
+
* const userData = JSON.parse(t.ls.get('user:123') || '{}');
|
|
584
|
+
*
|
|
585
|
+
* // Check all keys
|
|
586
|
+
* const allKeys = t.ls.keys(); // ['user:123', ...]
|
|
587
|
+
*
|
|
588
|
+
* // Clean up
|
|
589
|
+
* t.ls.remove('user:123');
|
|
590
|
+
* t.ls.clear(); // Remove all data
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
interface LocalStorage {
|
|
594
|
+
/** Get value. */
|
|
595
|
+
get(key: string): string | null;
|
|
596
|
+
/** Set value. */
|
|
597
|
+
set(key: string, value: string): void;
|
|
598
|
+
/** Remove key. */
|
|
599
|
+
remove(key: string): void;
|
|
600
|
+
/** Clear all storage. */
|
|
601
|
+
clear(): void;
|
|
602
|
+
/** List all keys. */
|
|
603
|
+
keys(): string[];
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// ==================== Session ====================
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Session API - High-performance session state management
|
|
610
|
+
*
|
|
611
|
+
* **Implementation:** Native Rust RwLock<HashMap> with composite keys
|
|
612
|
+
*
|
|
613
|
+
* **Performance:** Same as LocalStorage (~89K-156K ops/sec)
|
|
614
|
+
*
|
|
615
|
+
* **Characteristics:**
|
|
616
|
+
* - 🔐 Session-scoped storage (isolated per session ID)
|
|
617
|
+
* - ⚡ Sub-millisecond operations
|
|
618
|
+
* - 💾 In-memory only (not persistent)
|
|
619
|
+
* - 🔑 Composite key format: `{sessionId}:{key}`
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* // Store shopping cart for session
|
|
624
|
+
* const sessionId = 'sess_abc123';
|
|
625
|
+
* t.session.set(sessionId, 'cart', JSON.stringify([1, 2, 3]));
|
|
626
|
+
*
|
|
627
|
+
* // Retrieve cart
|
|
628
|
+
* const cart = JSON.parse(t.session.get(sessionId, 'cart') || '[]');
|
|
629
|
+
*
|
|
630
|
+
* // Clear entire session
|
|
631
|
+
* t.session.clear(sessionId);
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
interface Session {
|
|
635
|
+
/** Get session value. */
|
|
636
|
+
get(sessionId: string, key: string): string | null;
|
|
637
|
+
/** Set session value. */
|
|
638
|
+
set(sessionId: string, key: string, value: string): void;
|
|
639
|
+
/** Delete session value. */
|
|
640
|
+
delete(sessionId: string, key: string): void;
|
|
641
|
+
/** Clear entire session. */
|
|
642
|
+
clear(sessionId: string): void;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// ==================== Cookies ====================
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Cookie API - HTTP cookie parsing and setting
|
|
649
|
+
*/
|
|
650
|
+
interface Cookies {
|
|
651
|
+
/** Parse cookie from request headers. */
|
|
652
|
+
get(req: any, name: string): string | null;
|
|
653
|
+
/** Set Set-Cookie header on response. Options: `{ httpOnly, secure, sameSite, path, maxAge }`. */
|
|
654
|
+
set(res: any, name: string, value: string, options?: CookieOptions): void;
|
|
655
|
+
/** Delete cookie (expire). */
|
|
656
|
+
delete(res: any, name: string): void;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Cookie configuration options
|
|
661
|
+
*/
|
|
662
|
+
interface CookieOptions {
|
|
663
|
+
/** Maximum age in seconds */
|
|
664
|
+
maxAge?: number;
|
|
665
|
+
/** Cookie path (default: "/") */
|
|
666
|
+
path?: string;
|
|
667
|
+
/** HTTP-only flag (prevents JavaScript access) */
|
|
668
|
+
httpOnly?: boolean;
|
|
669
|
+
/** Secure flag (HTTPS only) */
|
|
670
|
+
secure?: boolean;
|
|
671
|
+
/** SameSite policy: "Strict", "Lax", or "None" */
|
|
672
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ==================== Response ====================
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Response API - Advanced HTTP Response Control
|
|
679
|
+
*/
|
|
680
|
+
interface ResponseModule {
|
|
681
|
+
/**
|
|
682
|
+
* Construct a fully custom ResponseObject.
|
|
683
|
+
*/
|
|
684
|
+
(options: ResponseOptions): ResponseObject;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Send plain UTF-8 text.
|
|
688
|
+
* Automatically sets `Content-Type: text/plain; charset=utf-8`.
|
|
689
|
+
* @param content Content to send.
|
|
690
|
+
* @param status HTTP status code.
|
|
691
|
+
*/
|
|
692
|
+
text(content: string, status?: number): ResponseObject;
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Send an HTML document.
|
|
696
|
+
* Automatically sets `Content-Type: text/html; charset=utf-8`.
|
|
697
|
+
* @param content HTML content.
|
|
698
|
+
* @param status HTTP status code.
|
|
699
|
+
*/
|
|
700
|
+
html(content: string, status?: number): ResponseObject;
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Send JSON-encoded data from a JavaScript object.
|
|
704
|
+
* Automatically sets `Content-Type: application/json`.
|
|
705
|
+
* @param content JSON-serializable object.
|
|
706
|
+
* @param status HTTP status code.
|
|
707
|
+
*/
|
|
708
|
+
json(content: any, status?: number): ResponseObject;
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Create a Redirect response.
|
|
712
|
+
* @param url Target URL.
|
|
713
|
+
* @param status HTTP status (default: 302).
|
|
714
|
+
*/
|
|
715
|
+
redirect(url: string, status?: number): ResponseObject;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Create an empty response.
|
|
719
|
+
* @param status HTTP status (default: 204).
|
|
720
|
+
*/
|
|
721
|
+
empty(status?: number): ResponseObject;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Options for customizing the response
|
|
726
|
+
*/
|
|
727
|
+
interface ResponseOptions {
|
|
728
|
+
/** HTTP Status Code (e.g., 200, 404, 500) */
|
|
729
|
+
status?: number;
|
|
730
|
+
/** Custom HTTP Headers */
|
|
731
|
+
headers?: Record<string, string>;
|
|
732
|
+
/** Response Body */
|
|
733
|
+
body?: string;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Standardized Response Object consumed by the Titan Rust HTTP server.
|
|
738
|
+
*/
|
|
739
|
+
interface ResponseObject {
|
|
740
|
+
type: "response";
|
|
741
|
+
status: number;
|
|
742
|
+
headers: Record<string, string>;
|
|
743
|
+
body: string;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export { };
|