@titanpl/core 2.1.0 → 2.1.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 CHANGED
@@ -106,9 +106,12 @@ Network utilities.
106
106
  - `net.ip(): string` - Get local IP address.
107
107
 
108
108
  ### `proc` (Process)
109
- Current process information.
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
@@ -13,4 +13,7 @@ declare var os_info: any;
13
13
  declare var net_resolve: any;
14
14
  declare var net_ip: any;
15
15
  declare var proc_info: any;
16
+ declare var proc_run: any;
17
+ declare var proc_kill: any;
18
+ declare var proc_list: any;
16
19
  declare var time_sleep: any;
package/index.d.ts CHANGED
@@ -6,9 +6,19 @@ declare global {
6
6
  namespace Titan {
7
7
  interface Runtime {
8
8
  /**
9
- * @titanpl/core Extension - Titan Core Standard Library
9
+ * # @titanpl/core
10
+ * The official Core Standard Library for Titan Planet - a high-performance JavaScript runtime extension.
10
11
  *
11
- * High-performance runtime APIs for file I/O, cryptography, networking, and data storage.
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 API - Native file operations
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
- * Path API - Cross-platform path manipulation
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
- * Cryptography API - Hashing, encryption, random generation
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
- * Operating System API - System information
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
- * Network API - DNS resolution and IP utilities
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
- * Process API - Runtime process information
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
- * Time API - Time utilities and delays
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
- * URL API - URL parsing and manipulation
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
- * Buffer API - Binary data encoding/decoding
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
- * Local Storage API - High-performance in-memory key-value store
67
- *
68
- * **Performance:** ~156,250 reads/sec, ~89,286 writes/sec
69
- *
70
- * - ⚡ RwLock<HashMap> implementation (~0.006ms per read)
71
- * - 🚀 ~1000x faster than file-based storage
72
- * - 💾 In-memory only (data lost on restart)
73
- * - 🔄 Perfect for request-scoped state sharing
74
- *
75
- * @example
76
- * ```typescript
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
- * Session API - High-performance session state management
90
- *
91
- * **Performance:** ~156,250 reads/sec, ~89,286 writes/sec
92
- *
93
- * - RwLock<HashMap> implementation
94
- * - 🔐 Session-scoped key-value storage
95
- * - 💨 Sub-millisecond operations
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
- * Cookie API - HTTP cookie parsing and setting
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
- * Response API - Advanced HTTP Response Management
112
- *
113
- * Enables full control over HTTP responses including:
114
- * - Custom status codes
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
- * Reads file content as UTF-8 string
165
- * @param path - Absolute or relative file 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
- * Writes content to file (creates if doesn't exist)
173
- * @param path - Target file path
174
- * @param content - Content to write
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
- * Reads directory contents
180
- * @param path - Directory 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
- * Creates directory recursively (like `mkdir -p`)
187
- * @param path - Directory path to create
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
- * Checks if path exists
193
- * @param path - Path to check
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
- * Returns file/directory statistics
200
- * @param path - Path to stat
201
- * @returns Stats object with size, type, and modification time
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
- * Removes file or directory (recursive for directories)
207
- * @param path - Path to remove
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
- * Computes hash of data using specified algorithm
280
- * @param algorithm - Hash algorithm: "sha256", "sha512", "md5"
281
- * @param data - Data to hash
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
- * Generates cryptographically secure random bytes
292
- * @param size - Number of bytes to generate
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
- * Generates a UUID v4 string
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
- * Base64 encoding/decoding utilities
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
- base64: {
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
- * Encrypts data using AES-256-GCM
324
- * @param algorithm - Encryption algorithm (e.g., "aes-256-gcm")
325
- * @param key - Encryption key (32 bytes for AES-256)
326
- * @param plaintext - Data to encrypt
327
- * @returns Base64-encoded ciphertext
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
- * Decrypts data using AES-256-GCM
333
- * @param algorithm - Decryption algorithm (e.g., "aes-256-gcm")
334
- * @param key - Decryption key (must match encryption key)
335
- * @param ciphertext - Base64-encoded 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
- * Computes HMAC (Hash-based Message Authentication Code)
342
- * @param algorithm - HMAC algorithm: "hmac-sha256", "hmac-sha512"
343
- * @param key - Secret key
344
- * @param message - Message to authenticate
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,23 +413,32 @@ declare global {
425
413
  * Process API - Runtime process information
426
414
  */
427
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>;
428
422
  /**
429
- * Returns the current process ID
430
- * @returns Process ID (PID)
423
+ * Spawn a subprocess.
424
+ * @param command The executable to run.
425
+ * @param args Arguments to pass.
426
+ * @returns Object containing the PID of the spawned process, e.g. `{ pid: 1234 }`.
431
427
  */
432
- pid(): number;
428
+ run(command: string, args: string[]): { pid: number };
433
429
 
434
430
  /**
435
- * Returns the process uptime in seconds
436
- * @returns Uptime in seconds
431
+ * Kill a process by PID.
432
+ * @param pid Process ID to kill.
433
+ * @returns True if the signal was sent successfully.
437
434
  */
438
- uptime(): number;
435
+ kill(pid: number): boolean;
439
436
 
440
437
  /**
441
- * Returns memory usage statistics
442
- * @returns Memory usage object
438
+ * List running processes.
439
+ * @returns Array of process information objects.
443
440
  */
444
- memory(): Record<string, any>;
441
+ list(): Array<{ pid: number, name: string, cmd: string, cpu?: number, memory?: number }>;
445
442
  }
446
443
 
447
444
  // ==================== Time ====================
@@ -450,23 +447,11 @@ declare global {
450
447
  * Time API - Time utilities and delays
451
448
  */
452
449
  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
- */
450
+ /** Sleep for specified milliseconds. */
458
451
  sleep(ms: number): void;
459
-
460
- /**
461
- * Returns the current timestamp in milliseconds
462
- * @returns Milliseconds since Unix epoch
463
- */
452
+ /** Current timestamp (ms). */
464
453
  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
- */
454
+ /** Current ISO timestamp. */
470
455
  timestamp(): string;
471
456
  }
472
457
 
@@ -572,46 +557,17 @@ declare global {
572
557
  * Buffer API - Binary data encoding and decoding
573
558
  */
574
559
  interface BufferModule {
575
- /**
576
- * Decodes Base64 string to bytes
577
- * @param str - Base64-encoded string
578
- * @returns Uint8Array of decoded bytes
579
- */
560
+ /** Decode Base64 string. */
580
561
  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
- */
562
+ /** Encode to Base64. */
587
563
  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
- */
564
+ /** Decode Hex string. */
594
565
  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
- */
566
+ /** Encode to Hex. */
601
567
  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
- */
568
+ /** Encode UTF-8 string to bytes. */
608
569
  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
- */
570
+ /** Decode bytes to UTF-8 string. */
615
571
  toUtf8(bytes: Uint8Array): string;
616
572
  }
617
573
 
@@ -655,75 +611,15 @@ declare global {
655
611
  * ```
656
612
  */
657
613
  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
- */
614
+ /** Get value. */
674
615
  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
- */
616
+ /** Set value. */
690
617
  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
- */
618
+ /** Remove key. */
702
619
  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
- */
620
+ /** Clear all storage. */
714
621
  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
- */
622
+ /** List all keys. */
727
623
  keys(): string[];
728
624
  }
729
625
 
@@ -756,47 +652,13 @@ declare global {
756
652
  * ```
757
653
  */
758
654
  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
- */
655
+ /** Get session value. */
768
656
  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
- */
657
+ /** Set session value. */
779
658
  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
- */
659
+ /** Delete session value. */
787
660
  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
- */
661
+ /** Clear entire session. */
800
662
  clear(sessionId: string): void;
801
663
  }
802
664
 
@@ -806,36 +668,11 @@ declare global {
806
668
  * Cookie API - HTTP cookie parsing and setting
807
669
  */
808
670
  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
- */
671
+ /** Parse cookie from request headers. */
821
672
  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
- */
673
+ /** Set Set-Cookie header on response. Options: `{ httpOnly, secure, sameSite, path, maxAge }`. */
831
674
  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
- */
675
+ /** Delete cookie (expire). */
839
676
  delete(res: any, name: string): void;
840
677
  }
841
678
 
@@ -862,42 +699,44 @@ declare global {
862
699
  */
863
700
  interface ResponseModule {
864
701
  /**
865
- * Creates a fully custom response
866
- * @param options - Response configuration
702
+ * Construct a fully custom ResponseObject.
867
703
  */
868
704
  (options: ResponseOptions): ResponseObject;
869
705
 
870
706
  /**
871
- * Creates a Plain Text response (Content-Type: text/plain)
872
- * @param content - Text content
873
- * @param options - Additional options
707
+ * Send plain UTF-8 text.
708
+ * Automatically sets `Content-Type: text/plain; charset=utf-8`.
709
+ * @param content Content to send.
710
+ * @param status HTTP status code.
874
711
  */
875
- text(content: string, options?: ResponseOptions): ResponseObject;
712
+ text(content: string, status?: number): ResponseObject;
876
713
 
877
714
  /**
878
- * Creates an HTML response (Content-Type: text/html)
879
- * @param content - HTML content
880
- * @param options - Additional options
715
+ * Send an HTML document.
716
+ * Automatically sets `Content-Type: text/html; charset=utf-8`.
717
+ * @param content HTML content.
718
+ * @param status HTTP status code.
881
719
  */
882
- html(content: string, options?: ResponseOptions): ResponseObject;
720
+ html(content: string, status?: number): ResponseObject;
883
721
 
884
722
  /**
885
- * Creates a JSON response (Content-Type: application/json)
886
- * @param content - JSON serializable object
887
- * @param options - Additional options
723
+ * Send JSON-encoded data from a JavaScript object.
724
+ * Automatically sets `Content-Type: application/json`.
725
+ * @param content JSON-serializable object.
726
+ * @param status HTTP status code.
888
727
  */
889
- json(content: any, options?: ResponseOptions): ResponseObject;
728
+ json(content: any, status?: number): ResponseObject;
890
729
 
891
730
  /**
892
- * Creates a Redirect response (301/302)
893
- * @param url - URL to redirect to
894
- * @param status - HTTP Status Code (default: 302)
731
+ * Create a Redirect response.
732
+ * @param url Target URL.
733
+ * @param status HTTP status (default: 302).
895
734
  */
896
735
  redirect(url: string, status?: number): ResponseObject;
897
736
 
898
737
  /**
899
- * Creates an empty response (e.g., 204 No Content)
900
- * @param status - HTTP Status Code (default: 204)
738
+ * Create an empty response.
739
+ * @param status HTTP status (default: 204).
901
740
  */
902
741
  empty(status?: number): ResponseObject;
903
742
  }
@@ -915,10 +754,10 @@ declare global {
915
754
  }
916
755
 
917
756
  /**
918
- * Standardized Response Object for the Runtime
757
+ * Standardized Response Object consumed by the Titan Rust HTTP server.
919
758
  */
920
759
  interface ResponseObject {
921
- _isResponse: true;
760
+ type: "response";
922
761
  status: number;
923
762
  headers: Record<string, string>;
924
763
  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,28 @@ 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) {
565
+ throw new Error(`Failed to parse process response: ${res}`);
566
+ }
567
+ },
568
+ kill: (pid) => {
569
+ if (!native_proc_kill) return false;
570
+ return native_proc_kill(pid);
571
+ },
572
+ list: () => {
573
+ if (!native_proc_list) return [];
574
+ const res = native_proc_list();
575
+ try {
576
+ return JSON.parse(res);
577
+ } catch (e) { return []; }
578
+ }
555
579
  };
556
580
 
557
581
  // --- Time ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/core",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "The official Core Standard Library for Titan Planet - provides fs, path, crypto, os, net, proc, time, and url modules",
5
5
  "main": "index.js",
6
6
  "type": "module",
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.0",
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": [