@titanpl/core 2.1.0 → 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/globals.d.ts +3 -0
- package/index.d.ts +209 -390
- package/index.js +23 -1
- package/native/target/release/titan_core.dll +0 -0
- package/package.json +1 -1
- package/titan.json +21 -1
- package/native/target/release/libtitan_core.so +0 -0
package/README.md
CHANGED
|
@@ -106,9 +106,12 @@ Network utilities.
|
|
|
106
106
|
- `net.ip(): string` - Get local IP address.
|
|
107
107
|
|
|
108
108
|
### `proc` (Process)
|
|
109
|
-
|
|
109
|
+
Process management and system information.
|
|
110
110
|
- `proc.pid(): number` - Process ID.
|
|
111
111
|
- `proc.uptime(): number` - System uptime in seconds.
|
|
112
|
+
- `proc.run(command: string, args?: string[]): { pid: number }` - Spawn a new process.
|
|
113
|
+
- `proc.kill(pid: number): boolean` - Kill a process by PID.
|
|
114
|
+
- `proc.list(): object[]` - List all running processes (`{ pid, name, cmd, memory, cpu }`).
|
|
112
115
|
|
|
113
116
|
### `time` (Time)
|
|
114
117
|
Time utilities.
|
|
@@ -122,6 +125,82 @@ URL parsing and manipulation.
|
|
|
122
125
|
- `url.format(urlObject: object): string` - Format URL object.
|
|
123
126
|
- `new url.SearchParams(query: string|object)` - Handle query strings.
|
|
124
127
|
|
|
128
|
+
### **`response` (HTTP Response Builder)**
|
|
129
|
+
|
|
130
|
+
Utilities for constructing HTTP responses.
|
|
131
|
+
All response methods return a standardized ResponseObject consumed by the Titan Rust HTTP server.
|
|
132
|
+
|
|
133
|
+
- `response.text(content: string, status?: number): ResponseObject` – Send plain text.
|
|
134
|
+
- `response.html(content: string, status?: number): ResponseObject` – Send HTML content.
|
|
135
|
+
- `response.json(data: any, status?: number): ResponseObject` – Send JSON-encoded data.
|
|
136
|
+
|
|
137
|
+
### **`response.text(content: string, status?: number)`**
|
|
138
|
+
|
|
139
|
+
Send plain UTF-8 text.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
return t.response.text("Hello World");
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Automatically sets:
|
|
146
|
+
|
|
147
|
+
* `Content-Type: text/plain; charset=utf-8`
|
|
148
|
+
|
|
149
|
+
### **`response.html(content: string, status?: number)`**
|
|
150
|
+
|
|
151
|
+
Send an HTML document.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
return t.response.html("<h1>Hello</h1>");
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Automatically sets:
|
|
158
|
+
|
|
159
|
+
* `Content-Type: text/html; charset=utf-8`
|
|
160
|
+
|
|
161
|
+
### **`response.json(data: any, status?: number)`**
|
|
162
|
+
|
|
163
|
+
Send JSON from a JavaScript object.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
return t.response.json({ ok: true });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Automatically sets:
|
|
170
|
+
|
|
171
|
+
* `Content-Type: application/json`
|
|
172
|
+
|
|
173
|
+
JSON serialization:
|
|
174
|
+
|
|
175
|
+
* Objects, arrays, primitives, and nested structures are supported.
|
|
176
|
+
|
|
177
|
+
### **ResponseObject**
|
|
178
|
+
|
|
179
|
+
Standard structure returned by all response methods:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
{
|
|
183
|
+
type: "response",
|
|
184
|
+
status: number,
|
|
185
|
+
headers: { [key: string]: string },
|
|
186
|
+
body: string
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### **Examples**
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// Text
|
|
194
|
+
t.response.text("pong");
|
|
195
|
+
|
|
196
|
+
// HTML
|
|
197
|
+
t.response.html("<h1>Welcome</h1>");
|
|
198
|
+
|
|
199
|
+
// JSON
|
|
200
|
+
t.response.json({ version: "1.0.0" });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
|
|
125
204
|
## Native Bindings
|
|
126
205
|
This extension includes native Rust bindings for high-performance operations. The native library is automatically loaded by the Titan Runtime.
|
|
127
206
|
|
package/globals.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -6,9 +6,19 @@ declare global {
|
|
|
6
6
|
namespace Titan {
|
|
7
7
|
interface Runtime {
|
|
8
8
|
/**
|
|
9
|
-
* @titanpl/core
|
|
9
|
+
* # @titanpl/core
|
|
10
|
+
* The official Core Standard Library for Titan Planet - a high-performance JavaScript runtime extension.
|
|
10
11
|
*
|
|
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
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
"@titanpl/core": TitanCore.Core;
|
|
14
24
|
|
|
@@ -18,66 +28,100 @@ declare global {
|
|
|
18
28
|
"titan-core": TitanCore.Core;
|
|
19
29
|
|
|
20
30
|
/**
|
|
21
|
-
* File System
|
|
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
|
+
* ```
|
|
22
38
|
*/
|
|
23
39
|
fs: TitanCore.FileSystem;
|
|
24
40
|
|
|
25
41
|
/**
|
|
26
|
-
*
|
|
42
|
+
* ### `path` (Path Manipulation)
|
|
43
|
+
* Utilities for handling file paths across different operating systems.
|
|
27
44
|
*/
|
|
28
45
|
path: TitanCore.Path;
|
|
29
46
|
|
|
30
47
|
/**
|
|
31
|
-
*
|
|
48
|
+
* ### `crypto` (Cryptography)
|
|
49
|
+
* Cryptographic utilities using native Rust implementations.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```javascript
|
|
53
|
+
* const hash = t.crypto.hash("sha256", "hii");
|
|
54
|
+
* ```
|
|
32
55
|
*/
|
|
33
56
|
crypto: TitanCore.Crypto;
|
|
34
57
|
|
|
35
58
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
*/
|
|
38
65
|
os: TitanCore.OS;
|
|
39
66
|
|
|
40
67
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
*/
|
|
43
74
|
net: TitanCore.Net;
|
|
44
75
|
|
|
45
76
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
*/
|
|
48
83
|
proc: TitanCore.Process;
|
|
49
84
|
|
|
50
85
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
*/
|
|
53
93
|
time: TitanCore.Time;
|
|
54
94
|
|
|
55
95
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
*/
|
|
58
102
|
url: TitanCore.URLModule;
|
|
59
103
|
|
|
60
104
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
*/
|
|
63
111
|
buffer: TitanCore.BufferModule;
|
|
64
112
|
|
|
65
113
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* t.ls.set('user:123', 'John Doe');
|
|
78
|
-
* const name = t.ls.get('user:123'); // "John Doe"
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
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
|
+
*/
|
|
81
125
|
ls: TitanCore.LocalStorage;
|
|
82
126
|
|
|
83
127
|
/**
|
|
@@ -86,42 +130,30 @@ declare global {
|
|
|
86
130
|
localStorage: TitanCore.LocalStorage;
|
|
87
131
|
|
|
88
132
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* t.session.set('sess_abc', 'cart', '[1,2,3]');
|
|
100
|
-
* const cart = t.session.get('sess_abc', 'cart');
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
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
|
+
*/
|
|
103
140
|
session: TitanCore.Session;
|
|
104
141
|
|
|
105
142
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
*/
|
|
108
150
|
cookies: TitanCore.Cookies;
|
|
109
151
|
|
|
110
152
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
* - Custom headers
|
|
116
|
-
* - Content-Type management
|
|
117
|
-
* - Redirects
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* return t.response.text("Hello World");
|
|
122
|
-
* return t.response.json({ ok: true }, { status: 201 });
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
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
|
+
*/
|
|
125
157
|
response: TitanCore.ResponseModule;
|
|
126
158
|
|
|
127
159
|
/**
|
|
@@ -131,6 +163,27 @@ declare global {
|
|
|
131
163
|
}
|
|
132
164
|
}
|
|
133
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
|
+
|
|
134
187
|
/**
|
|
135
188
|
* Titan Core Global Namespace
|
|
136
189
|
*/
|
|
@@ -161,50 +214,46 @@ declare global {
|
|
|
161
214
|
*/
|
|
162
215
|
interface FileSystem {
|
|
163
216
|
/**
|
|
164
|
-
*
|
|
165
|
-
* @param path
|
|
166
|
-
* @returns File content as string
|
|
167
|
-
* @throws Error if file doesn't exist or cannot be read
|
|
217
|
+
* Read file content as UTF-8 string.
|
|
218
|
+
* @param path File path.
|
|
168
219
|
*/
|
|
169
220
|
readFile(path: string): string;
|
|
170
221
|
|
|
171
222
|
/**
|
|
172
|
-
*
|
|
173
|
-
* @param path
|
|
174
|
-
* @param content
|
|
223
|
+
* Write string content to file.
|
|
224
|
+
* @param path Target file path.
|
|
225
|
+
* @param content String content to write.
|
|
175
226
|
*/
|
|
176
227
|
writeFile(path: string, content: string): void;
|
|
177
228
|
|
|
178
229
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param path
|
|
181
|
-
* @returns Array of file/directory names
|
|
230
|
+
* List directory contents.
|
|
231
|
+
* @param path Directory path.
|
|
182
232
|
*/
|
|
183
233
|
readdir(path: string): string[];
|
|
184
234
|
|
|
185
235
|
/**
|
|
186
|
-
*
|
|
187
|
-
* @param path
|
|
236
|
+
* Create a directory (recursive).
|
|
237
|
+
* @param path Directory path to create.
|
|
188
238
|
*/
|
|
189
239
|
mkdir(path: string): void;
|
|
190
240
|
|
|
191
241
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param path
|
|
194
|
-
* @returns true if exists, false otherwise
|
|
242
|
+
* Check if path exists.
|
|
243
|
+
* @param path Path to check.
|
|
195
244
|
*/
|
|
196
245
|
exists(path: string): boolean;
|
|
197
246
|
|
|
198
247
|
/**
|
|
199
|
-
*
|
|
200
|
-
* @param path
|
|
201
|
-
* @returns
|
|
248
|
+
* Get file statistics.
|
|
249
|
+
* @param path Path to stat.
|
|
250
|
+
* @returns Statistics object `{ type: "file" | "directory", size: number }`.
|
|
202
251
|
*/
|
|
203
252
|
stat(path: string): Stats;
|
|
204
253
|
|
|
205
254
|
/**
|
|
206
|
-
*
|
|
207
|
-
* @param path
|
|
255
|
+
* Remove file or directory (recursive).
|
|
256
|
+
* @param path Path to remove.
|
|
208
257
|
*/
|
|
209
258
|
remove(path: string): void;
|
|
210
259
|
}
|
|
@@ -276,83 +325,54 @@ declare global {
|
|
|
276
325
|
*/
|
|
277
326
|
interface Crypto {
|
|
278
327
|
/**
|
|
279
|
-
*
|
|
280
|
-
* @param algorithm
|
|
281
|
-
* @param data
|
|
282
|
-
* @returns Hex-encoded hash string
|
|
283
|
-
* @example
|
|
284
|
-
* ```typescript
|
|
285
|
-
* const hash = t.crypto.hash('sha256', 'hello world');
|
|
286
|
-
* ```
|
|
328
|
+
* Hash data.
|
|
329
|
+
* @param algorithm Algorithm to use: `sha256`, `sha512`, `md5`.
|
|
330
|
+
* @param data Data to hash.
|
|
287
331
|
*/
|
|
288
332
|
hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): string;
|
|
289
333
|
|
|
290
334
|
/**
|
|
291
|
-
*
|
|
292
|
-
* @param size
|
|
293
|
-
* @returns Hex-encoded random string
|
|
335
|
+
* Generate random bytes as hex string.
|
|
336
|
+
* @param size Number of bytes.
|
|
294
337
|
*/
|
|
295
338
|
randomBytes(size: number): string;
|
|
296
339
|
|
|
297
340
|
/**
|
|
298
|
-
*
|
|
299
|
-
* @returns UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000")
|
|
341
|
+
* Generate a UUID v4.
|
|
300
342
|
*/
|
|
301
343
|
uuid(): string;
|
|
302
344
|
|
|
303
345
|
/**
|
|
304
|
-
*
|
|
346
|
+
* Constant-time comparison to prevent timing attacks.
|
|
347
|
+
* @param hash The reference hash.
|
|
348
|
+
* @param target The hash to compare against.
|
|
305
349
|
*/
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Encodes string to Base64
|
|
309
|
-
* @param str - String to encode
|
|
310
|
-
* @returns Base64-encoded string
|
|
311
|
-
*/
|
|
312
|
-
encode(str: string): string;
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Decodes Base64 string
|
|
316
|
-
* @param str - Base64-encoded string
|
|
317
|
-
* @returns Decoded string
|
|
318
|
-
*/
|
|
319
|
-
decode(str: string): string;
|
|
320
|
-
};
|
|
350
|
+
compare(hash: string, target: string): boolean;
|
|
321
351
|
|
|
322
352
|
/**
|
|
323
|
-
*
|
|
324
|
-
* @param algorithm
|
|
325
|
-
* @param key -
|
|
326
|
-
* @param plaintext
|
|
327
|
-
* @returns Base64
|
|
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.
|
|
328
358
|
*/
|
|
329
359
|
encrypt(algorithm: string, key: string, plaintext: string): string;
|
|
330
360
|
|
|
331
361
|
/**
|
|
332
|
-
*
|
|
333
|
-
* @param algorithm
|
|
334
|
-
* @param key -
|
|
335
|
-
* @param ciphertext
|
|
336
|
-
* @returns Decrypted plaintext
|
|
362
|
+
* AES-256-GCM Decrypt.
|
|
363
|
+
* @param algorithm Decryption algorithm.
|
|
364
|
+
* @param key Matching 32-byte key.
|
|
365
|
+
* @param ciphertext Base64 encoded ciphertext.
|
|
337
366
|
*/
|
|
338
367
|
decrypt(algorithm: string, key: string, ciphertext: string): string;
|
|
339
368
|
|
|
340
369
|
/**
|
|
341
|
-
*
|
|
342
|
-
* @param algorithm
|
|
343
|
-
* @param key
|
|
344
|
-
* @param message
|
|
345
|
-
* @returns Hex-encoded HMAC
|
|
370
|
+
* HMAC calculation.
|
|
371
|
+
* @param algorithm `hmac-sha256` or `hmac-sha512`.
|
|
372
|
+
* @param key Secret key.
|
|
373
|
+
* @param message Message to sign.
|
|
346
374
|
*/
|
|
347
375
|
hashKeyed(algorithm: 'hmac-sha256' | 'hmac-sha512', key: string, message: string): string;
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Constant-time string comparison (prevents timing attacks)
|
|
351
|
-
* @param a - First string
|
|
352
|
-
* @param b - Second string
|
|
353
|
-
* @returns true if strings are equal
|
|
354
|
-
*/
|
|
355
|
-
compare(a: string, b: string): boolean;
|
|
356
376
|
}
|
|
357
377
|
|
|
358
378
|
// ==================== OS ====================
|
|
@@ -361,34 +381,15 @@ declare global {
|
|
|
361
381
|
* Operating System API - System information
|
|
362
382
|
*/
|
|
363
383
|
interface OS {
|
|
364
|
-
/**
|
|
365
|
-
* Returns the operating system platform
|
|
366
|
-
* @returns Platform name (e.g., "windows", "linux", "darwin")
|
|
367
|
-
*/
|
|
384
|
+
/** OS platform (e.g., `linux`, `windows`). */
|
|
368
385
|
platform(): string;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Returns the number of logical CPU cores
|
|
372
|
-
* @returns Number of CPUs
|
|
373
|
-
*/
|
|
386
|
+
/** Number of CPU cores. */
|
|
374
387
|
cpus(): number;
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Returns total system memory in bytes
|
|
378
|
-
* @returns Total memory in bytes
|
|
379
|
-
*/
|
|
388
|
+
/** Total system memory in bytes. */
|
|
380
389
|
totalMemory(): number;
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Returns free system memory in bytes
|
|
384
|
-
* @returns Free memory in bytes
|
|
385
|
-
*/
|
|
390
|
+
/** Free system memory in bytes. */
|
|
386
391
|
freeMemory(): number;
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Returns the system temporary directory path
|
|
390
|
-
* @returns Temp directory path
|
|
391
|
-
*/
|
|
392
|
+
/** Temporary directory path. */
|
|
392
393
|
tmpdir(): string;
|
|
393
394
|
}
|
|
394
395
|
|
|
@@ -398,24 +399,11 @@ declare global {
|
|
|
398
399
|
* Network API - DNS resolution and IP utilities
|
|
399
400
|
*/
|
|
400
401
|
interface Net {
|
|
401
|
-
/**
|
|
402
|
-
* Resolves hostname to IP addresses
|
|
403
|
-
* @param hostname - Domain name to resolve
|
|
404
|
-
* @returns Array of IP addresses
|
|
405
|
-
*/
|
|
402
|
+
/** Resolve hostname to IP addresses. */
|
|
406
403
|
resolveDNS(hostname: string): string[];
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Returns the local machine's IP address
|
|
410
|
-
* @returns Local IP address
|
|
411
|
-
*/
|
|
404
|
+
/** Get local IP address. */
|
|
412
405
|
ip(): string;
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Pings a host (currently always returns true)
|
|
416
|
-
* @param host - Host to ping
|
|
417
|
-
* @returns Always true
|
|
418
|
-
*/
|
|
406
|
+
/** Ping (not fully implemented). */
|
|
419
407
|
ping(host: string): boolean;
|
|
420
408
|
}
|
|
421
409
|
|
|
@@ -425,22 +413,11 @@ declare global {
|
|
|
425
413
|
* Process API - Runtime process information
|
|
426
414
|
*/
|
|
427
415
|
interface Process {
|
|
428
|
-
/**
|
|
429
|
-
* Returns the current process ID
|
|
430
|
-
* @returns Process ID (PID)
|
|
431
|
-
*/
|
|
416
|
+
/** Process ID. */
|
|
432
417
|
pid(): number;
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Returns the process uptime in seconds
|
|
436
|
-
* @returns Uptime in seconds
|
|
437
|
-
*/
|
|
418
|
+
/** System uptime in seconds. */
|
|
438
419
|
uptime(): number;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Returns memory usage statistics
|
|
442
|
-
* @returns Memory usage object
|
|
443
|
-
*/
|
|
420
|
+
/** Memory usage statistics. */
|
|
444
421
|
memory(): Record<string, any>;
|
|
445
422
|
}
|
|
446
423
|
|
|
@@ -450,23 +427,11 @@ declare global {
|
|
|
450
427
|
* Time API - Time utilities and delays
|
|
451
428
|
*/
|
|
452
429
|
interface Time {
|
|
453
|
-
/**
|
|
454
|
-
* Pauses execution for the specified duration
|
|
455
|
-
* @param ms - Milliseconds to sleep
|
|
456
|
-
* @warning This blocks the V8 isolate - use sparingly!
|
|
457
|
-
*/
|
|
430
|
+
/** Sleep for specified milliseconds. */
|
|
458
431
|
sleep(ms: number): void;
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Returns the current timestamp in milliseconds
|
|
462
|
-
* @returns Milliseconds since Unix epoch
|
|
463
|
-
*/
|
|
432
|
+
/** Current timestamp (ms). */
|
|
464
433
|
now(): number;
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Returns the current time as an ISO 8601 string
|
|
468
|
-
* @returns ISO timestamp (e.g., "2024-01-25T10:30:00.000Z")
|
|
469
|
-
*/
|
|
434
|
+
/** Current ISO timestamp. */
|
|
470
435
|
timestamp(): string;
|
|
471
436
|
}
|
|
472
437
|
|
|
@@ -572,46 +537,17 @@ declare global {
|
|
|
572
537
|
* Buffer API - Binary data encoding and decoding
|
|
573
538
|
*/
|
|
574
539
|
interface BufferModule {
|
|
575
|
-
/**
|
|
576
|
-
* Decodes Base64 string to bytes
|
|
577
|
-
* @param str - Base64-encoded string
|
|
578
|
-
* @returns Uint8Array of decoded bytes
|
|
579
|
-
*/
|
|
540
|
+
/** Decode Base64 string. */
|
|
580
541
|
fromBase64(str: string): Uint8Array;
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* Encodes bytes or string to Base64
|
|
584
|
-
* @param bytes - Uint8Array or string to encode
|
|
585
|
-
* @returns Base64-encoded string
|
|
586
|
-
*/
|
|
542
|
+
/** Encode to Base64. */
|
|
587
543
|
toBase64(bytes: Uint8Array | string): string;
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Decodes hex string to bytes
|
|
591
|
-
* @param str - Hex-encoded string
|
|
592
|
-
* @returns Uint8Array of decoded bytes
|
|
593
|
-
*/
|
|
544
|
+
/** Decode Hex string. */
|
|
594
545
|
fromHex(str: string): Uint8Array;
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Encodes bytes or string to hex
|
|
598
|
-
* @param bytes - Uint8Array or string to encode
|
|
599
|
-
* @returns Hex-encoded string
|
|
600
|
-
*/
|
|
546
|
+
/** Encode to Hex. */
|
|
601
547
|
toHex(bytes: Uint8Array | string): string;
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Encodes UTF-8 string to bytes
|
|
605
|
-
* @param str - String to encode
|
|
606
|
-
* @returns Uint8Array of UTF-8 bytes
|
|
607
|
-
*/
|
|
548
|
+
/** Encode UTF-8 string to bytes. */
|
|
608
549
|
fromUtf8(str: string): Uint8Array;
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Decodes UTF-8 bytes to string
|
|
612
|
-
* @param bytes - Uint8Array of UTF-8 bytes
|
|
613
|
-
* @returns Decoded string
|
|
614
|
-
*/
|
|
550
|
+
/** Decode bytes to UTF-8 string. */
|
|
615
551
|
toUtf8(bytes: Uint8Array): string;
|
|
616
552
|
}
|
|
617
553
|
|
|
@@ -655,75 +591,15 @@ declare global {
|
|
|
655
591
|
* ```
|
|
656
592
|
*/
|
|
657
593
|
interface LocalStorage {
|
|
658
|
-
/**
|
|
659
|
-
* Retrieves a value from local storage
|
|
660
|
-
*
|
|
661
|
-
* **Performance:** ~0.0064ms per operation (~156,250 ops/sec)
|
|
662
|
-
*
|
|
663
|
-
* @param key - Storage key
|
|
664
|
-
* @returns Stored value or null if not found
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* ```typescript
|
|
668
|
-
* const value = t.ls.get('myKey');
|
|
669
|
-
* if (value !== null) {
|
|
670
|
-
* console.log('Found:', value);
|
|
671
|
-
* }
|
|
672
|
-
* ```
|
|
673
|
-
*/
|
|
594
|
+
/** Get value. */
|
|
674
595
|
get(key: string): string | null;
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* Stores a value in local storage
|
|
678
|
-
*
|
|
679
|
-
* **Performance:** ~0.0112ms per operation (~89,286 ops/sec)
|
|
680
|
-
*
|
|
681
|
-
* @param key - Storage key
|
|
682
|
-
* @param value - Value to store (will be converted to string)
|
|
683
|
-
*
|
|
684
|
-
* @example
|
|
685
|
-
* ```typescript
|
|
686
|
-
* t.ls.set('counter', '42');
|
|
687
|
-
* t.ls.set('config', JSON.stringify({ theme: 'dark' }));
|
|
688
|
-
* ```
|
|
689
|
-
*/
|
|
596
|
+
/** Set value. */
|
|
690
597
|
set(key: string, value: string): void;
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Removes a specific key from local storage
|
|
694
|
-
*
|
|
695
|
-
* @param key - Key to remove
|
|
696
|
-
*
|
|
697
|
-
* @example
|
|
698
|
-
* ```typescript
|
|
699
|
-
* t.ls.remove('tempData');
|
|
700
|
-
* ```
|
|
701
|
-
*/
|
|
598
|
+
/** Remove key. */
|
|
702
599
|
remove(key: string): void;
|
|
703
|
-
|
|
704
|
-
/**
|
|
705
|
-
* Clears all data from local storage
|
|
706
|
-
*
|
|
707
|
-
* @warning This removes ALL keys - use with caution!
|
|
708
|
-
*
|
|
709
|
-
* @example
|
|
710
|
-
* ```typescript
|
|
711
|
-
* t.ls.clear(); // All data removed
|
|
712
|
-
* ```
|
|
713
|
-
*/
|
|
600
|
+
/** Clear all storage. */
|
|
714
601
|
clear(): void;
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* Returns all keys currently in local storage
|
|
718
|
-
*
|
|
719
|
-
* @returns Array of all storage keys
|
|
720
|
-
*
|
|
721
|
-
* @example
|
|
722
|
-
* ```typescript
|
|
723
|
-
* const keys = t.ls.keys();
|
|
724
|
-
* console.log('Stored keys:', keys); // ['user:1', 'config', ...]
|
|
725
|
-
* ```
|
|
726
|
-
*/
|
|
602
|
+
/** List all keys. */
|
|
727
603
|
keys(): string[];
|
|
728
604
|
}
|
|
729
605
|
|
|
@@ -756,47 +632,13 @@ declare global {
|
|
|
756
632
|
* ```
|
|
757
633
|
*/
|
|
758
634
|
interface Session {
|
|
759
|
-
/**
|
|
760
|
-
* Retrieves a value from a session
|
|
761
|
-
*
|
|
762
|
-
* **Performance:** ~0.0064ms per operation
|
|
763
|
-
*
|
|
764
|
-
* @param sessionId - Unique session identifier
|
|
765
|
-
* @param key - Key within the session
|
|
766
|
-
* @returns Stored value or null if not found
|
|
767
|
-
*/
|
|
635
|
+
/** Get session value. */
|
|
768
636
|
get(sessionId: string, key: string): string | null;
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Stores a value in a session
|
|
772
|
-
*
|
|
773
|
-
* **Performance:** ~0.0112ms per operation
|
|
774
|
-
*
|
|
775
|
-
* @param sessionId - Unique session identifier
|
|
776
|
-
* @param key - Key within the session
|
|
777
|
-
* @param value - Value to store
|
|
778
|
-
*/
|
|
637
|
+
/** Set session value. */
|
|
779
638
|
set(sessionId: string, key: string, value: string): void;
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* Deletes a specific key from a session
|
|
783
|
-
*
|
|
784
|
-
* @param sessionId - Session identifier
|
|
785
|
-
* @param key - Key to delete
|
|
786
|
-
*/
|
|
639
|
+
/** Delete session value. */
|
|
787
640
|
delete(sessionId: string, key: string): void;
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* Clears all data for a session
|
|
791
|
-
*
|
|
792
|
-
* @param sessionId - Session identifier to clear
|
|
793
|
-
*
|
|
794
|
-
* @example
|
|
795
|
-
* ```typescript
|
|
796
|
-
* // Remove all session data when user logs out
|
|
797
|
-
* t.session.clear('sess_abc123');
|
|
798
|
-
* ```
|
|
799
|
-
*/
|
|
641
|
+
/** Clear entire session. */
|
|
800
642
|
clear(sessionId: string): void;
|
|
801
643
|
}
|
|
802
644
|
|
|
@@ -806,36 +648,11 @@ declare global {
|
|
|
806
648
|
* Cookie API - HTTP cookie parsing and setting
|
|
807
649
|
*/
|
|
808
650
|
interface Cookies {
|
|
809
|
-
/**
|
|
810
|
-
* Parses and retrieves a cookie from request headers
|
|
811
|
-
*
|
|
812
|
-
* @param req - Request object with headers
|
|
813
|
-
* @param name - Cookie name
|
|
814
|
-
* @returns Cookie value (URL-decoded) or null
|
|
815
|
-
*
|
|
816
|
-
* @example
|
|
817
|
-
* ```typescript
|
|
818
|
-
* const sessionId = t.cookies.get(req, 'session_id');
|
|
819
|
-
* ```
|
|
820
|
-
*/
|
|
651
|
+
/** Parse cookie from request headers. */
|
|
821
652
|
get(req: any, name: string): string | null;
|
|
822
|
-
|
|
823
|
-
/**
|
|
824
|
-
* Sets a cookie in the response headers
|
|
825
|
-
*
|
|
826
|
-
* @param res - Response object
|
|
827
|
-
* @param name - Cookie name
|
|
828
|
-
* @param value - Cookie value (will be URL-encoded)
|
|
829
|
-
* @param options - Cookie options (maxAge, path, httpOnly, etc.)
|
|
830
|
-
*/
|
|
653
|
+
/** Set Set-Cookie header on response. Options: `{ httpOnly, secure, sameSite, path, maxAge }`. */
|
|
831
654
|
set(res: any, name: string, value: string, options?: CookieOptions): void;
|
|
832
|
-
|
|
833
|
-
/**
|
|
834
|
-
* Deletes a cookie by setting maxAge=0
|
|
835
|
-
*
|
|
836
|
-
* @param res - Response object
|
|
837
|
-
* @param name - Cookie name to delete
|
|
838
|
-
*/
|
|
655
|
+
/** Delete cookie (expire). */
|
|
839
656
|
delete(res: any, name: string): void;
|
|
840
657
|
}
|
|
841
658
|
|
|
@@ -862,42 +679,44 @@ declare global {
|
|
|
862
679
|
*/
|
|
863
680
|
interface ResponseModule {
|
|
864
681
|
/**
|
|
865
|
-
*
|
|
866
|
-
* @param options - Response configuration
|
|
682
|
+
* Construct a fully custom ResponseObject.
|
|
867
683
|
*/
|
|
868
684
|
(options: ResponseOptions): ResponseObject;
|
|
869
685
|
|
|
870
686
|
/**
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
* @param
|
|
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.
|
|
874
691
|
*/
|
|
875
|
-
text(content: string,
|
|
692
|
+
text(content: string, status?: number): ResponseObject;
|
|
876
693
|
|
|
877
694
|
/**
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
* @param
|
|
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.
|
|
881
699
|
*/
|
|
882
|
-
html(content: string,
|
|
700
|
+
html(content: string, status?: number): ResponseObject;
|
|
883
701
|
|
|
884
702
|
/**
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
* @param
|
|
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.
|
|
888
707
|
*/
|
|
889
|
-
json(content: any,
|
|
708
|
+
json(content: any, status?: number): ResponseObject;
|
|
890
709
|
|
|
891
710
|
/**
|
|
892
|
-
*
|
|
893
|
-
* @param url
|
|
894
|
-
* @param status
|
|
711
|
+
* Create a Redirect response.
|
|
712
|
+
* @param url Target URL.
|
|
713
|
+
* @param status HTTP status (default: 302).
|
|
895
714
|
*/
|
|
896
715
|
redirect(url: string, status?: number): ResponseObject;
|
|
897
716
|
|
|
898
717
|
/**
|
|
899
|
-
*
|
|
900
|
-
* @param status
|
|
718
|
+
* Create an empty response.
|
|
719
|
+
* @param status HTTP status (default: 204).
|
|
901
720
|
*/
|
|
902
721
|
empty(status?: number): ResponseObject;
|
|
903
722
|
}
|
|
@@ -915,10 +734,10 @@ declare global {
|
|
|
915
734
|
}
|
|
916
735
|
|
|
917
736
|
/**
|
|
918
|
-
* Standardized Response Object
|
|
737
|
+
* Standardized Response Object consumed by the Titan Rust HTTP server.
|
|
919
738
|
*/
|
|
920
739
|
interface ResponseObject {
|
|
921
|
-
|
|
740
|
+
type: "response";
|
|
922
741
|
status: number;
|
|
923
742
|
headers: Record<string, string>;
|
|
924
743
|
body: string;
|
package/index.js
CHANGED
|
@@ -137,6 +137,9 @@ const native_os_info = natives.os_info;
|
|
|
137
137
|
const native_net_resolve = natives.net_resolve;
|
|
138
138
|
const native_net_ip = natives.net_ip;
|
|
139
139
|
const native_proc_info = natives.proc_info;
|
|
140
|
+
const native_proc_run = natives.proc_run;
|
|
141
|
+
const native_proc_kill = natives.proc_kill;
|
|
142
|
+
const native_proc_list = natives.proc_list;
|
|
140
143
|
const native_time_sleep = natives.time_sleep;
|
|
141
144
|
|
|
142
145
|
const native_ls_get = natives.ls_get;
|
|
@@ -551,7 +554,26 @@ const proc = {
|
|
|
551
554
|
const info = JSON.parse(native_proc_info());
|
|
552
555
|
return info.uptime;
|
|
553
556
|
},
|
|
554
|
-
memory: () => ({})
|
|
557
|
+
memory: () => ({}),
|
|
558
|
+
run: (command, args = []) => {
|
|
559
|
+
if (!native_proc_run) throw new Error("Native proc_run not found");
|
|
560
|
+
const res = native_proc_run(command, JSON.stringify(args));
|
|
561
|
+
if (typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res);
|
|
562
|
+
try {
|
|
563
|
+
return JSON.parse(res);
|
|
564
|
+
} catch (e) { return {}; }
|
|
565
|
+
},
|
|
566
|
+
kill: (pid) => {
|
|
567
|
+
if (!native_proc_kill) return false;
|
|
568
|
+
return native_proc_kill(pid);
|
|
569
|
+
},
|
|
570
|
+
list: () => {
|
|
571
|
+
if (!native_proc_list) return [];
|
|
572
|
+
const res = native_proc_list();
|
|
573
|
+
try {
|
|
574
|
+
return JSON.parse(res);
|
|
575
|
+
} catch (e) { return []; }
|
|
576
|
+
}
|
|
555
577
|
};
|
|
556
578
|
|
|
557
579
|
// --- Time ---
|
|
Binary file
|
package/package.json
CHANGED
package/titan.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/core",
|
|
3
3
|
"description": "The official Core Standard Library for Titan Planet",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"native": {
|
|
7
7
|
"path": "native/target/release/titan_core.dll",
|
|
@@ -103,6 +103,26 @@
|
|
|
103
103
|
"parameters": [],
|
|
104
104
|
"result": "string"
|
|
105
105
|
},
|
|
106
|
+
"proc_run": {
|
|
107
|
+
"symbol": "proc_run",
|
|
108
|
+
"parameters": [
|
|
109
|
+
"string",
|
|
110
|
+
"string"
|
|
111
|
+
],
|
|
112
|
+
"result": "string"
|
|
113
|
+
},
|
|
114
|
+
"proc_kill": {
|
|
115
|
+
"symbol": "proc_kill",
|
|
116
|
+
"parameters": [
|
|
117
|
+
"f64"
|
|
118
|
+
],
|
|
119
|
+
"result": "bool"
|
|
120
|
+
},
|
|
121
|
+
"proc_list": {
|
|
122
|
+
"symbol": "proc_list",
|
|
123
|
+
"parameters": [],
|
|
124
|
+
"result": "string"
|
|
125
|
+
},
|
|
106
126
|
"time_sleep": {
|
|
107
127
|
"symbol": "time_sleep",
|
|
108
128
|
"parameters": [
|
|
Binary file
|