@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/index.d.ts CHANGED
@@ -1,265 +1,748 @@
1
- // Type definitions for @titanpl/core
2
- // This file facilitates type inference when this extension is installed in a Titan project.
3
-
4
- declare global {
5
- namespace Titan {
6
- interface Runtime {
7
- /**
8
- * @titanpl/core Extension - Titan Core Standard Library
9
- */
10
- "@titanpl/core": TitanCore.Core;
11
-
12
- /**
13
- * Alias for @titanpl/core
14
- */
15
- "titan-core": TitanCore.Core;
16
-
17
- /** File System module */
18
- fs: TitanCore.FileSystem;
19
- /** Path manipulation module */
20
- path: TitanCore.Path;
21
- /** Cryptography module */
22
- crypto: TitanCore.Crypto;
23
- /** Operating System module */
24
- os: TitanCore.OS;
25
- /** Network module */
26
- net: TitanCore.Net;
27
- /** Process module */
28
- proc: TitanCore.Process;
29
- /** Time module */
30
- time: TitanCore.Time;
31
- /** URL module */
32
- url: TitanCore.URLModule;
33
- /** Buffer utility module */
34
- buffer: TitanCore.BufferModule;
35
- /** Local Storage module */
36
- ls: TitanCore.LocalStorage;
37
- /** Local Storage alias */
38
- localStorage: TitanCore.LocalStorage;
39
- /** Session management */
40
- session: TitanCore.Session;
41
- /** Cookie utilities */
42
- cookies: TitanCore.Cookies;
43
- /** Core namespace alias */
44
- core: TitanCore.Core;
45
- }
46
- }
47
-
48
- /**
49
- * Titan Core Global Namespace
50
- */
51
- namespace TitanCore {
52
- interface Core {
53
- fs: FileSystem;
54
- path: Path;
55
- crypto: Crypto;
56
- os: OS;
57
- net: Net;
58
- proc: Process;
59
- time: Time;
60
- url: URLModule;
61
- buffer: BufferModule;
62
- ls: LocalStorage;
63
- session: Session;
64
- cookies: Cookies;
65
- }
66
-
67
- // --- File System ---
68
- interface FileSystem {
69
- /** Reads file content as UTF-8 string */
70
- readFile(path: string): string;
71
- /** Writes content to file */
72
- writeFile(path: string, content: string): void;
73
- /** Reads directory contents */
74
- readdir(path: string): string[];
75
- /** Creates directory recursively */
76
- mkdir(path: string): void;
77
- /** Checks if path exists */
78
- exists(path: string): boolean;
79
- /** Returns file stats */
80
- stat(path: string): Stats;
81
- /** Removes file or directory */
82
- remove(path: string): void;
83
- }
84
-
85
- interface Stats {
86
- size: number;
87
- isFile: boolean;
88
- isDir: boolean;
89
- modified: number;
90
- }
91
-
92
- // --- Path ---
93
- interface Path {
94
- /** Joins path segments */
95
- join(...args: string[]): string;
96
- /** Resolves path segments to an absolute path */
97
- resolve(...args: string[]): string;
98
- /** Returns the extension of the path */
99
- extname(path: string): string;
100
- /** Returns the directory name of a path */
101
- dirname(path: string): string;
102
- /** Returns the last portion of a path */
103
- basename(path: string): string;
104
- }
105
-
106
- // --- Crypto ---
107
- interface Crypto {
108
- /** Computes hash of data using specified algorithm (e.g., 'sha256', 'sha512') */
109
- hash(algorithm: string, data: string): string;
110
- /** Generates random bytes as a hex string */
111
- randomBytes(size: number): string;
112
- /** Generates a UUID v4 string */
113
- uuid(): string;
114
- base64: {
115
- encode(str: string): string;
116
- decode(str: string): string;
117
- };
118
- /** Encrypts data using AES-256-GCM. Returns Base64 string. */
119
- encrypt(algorithm: string, key: string, plaintext: string): string;
120
- /** Decrypts data using AES-256-GCM. Returns plaintext string. */
121
- decrypt(algorithm: string, key: string, ciphertext: string): string;
122
- /** Computes HMAC-SHA256/512. Returns Hex string. */
123
- hashKeyed(algorithm: string, key: string, message: string): string;
124
- /** Constant-time string comparison */
125
- compare(a: string, b: string): boolean;
126
- }
127
-
128
- // --- OS ---
129
- interface OS {
130
- /** Returns the operating system platform */
131
- platform(): string;
132
- /** Returns the number of logical CPUs */
133
- cpus(): number;
134
- /** Returns total system memory in bytes */
135
- totalMemory(): number;
136
- /** Returns free system memory in bytes */
137
- freeMemory(): number;
138
- /** Returns the system temporary directory */
139
- tmpdir(): string;
140
- }
141
-
142
- // --- Net ---
143
- interface Net {
144
- /** Resolves hostname to IP addresses */
145
- resolveDNS(hostname: string): string[];
146
- /** Returns the local machine's IP address */
147
- ip(): string;
148
- /** Pings a host (mock implementation always returns true) */
149
- ping(host: string): boolean;
150
- }
151
-
152
- // --- Process ---
153
- interface Process {
154
- /** Returns the current process ID */
155
- pid(): number;
156
- /** Returns the process uptime in seconds */
157
- uptime(): number;
158
- /** Returns memory usage statistics */
159
- memory(): Record<string, any>;
160
- }
161
-
162
- // --- Time ---
163
- interface Time {
164
- /** Pauses execution for the specified number of milliseconds */
165
- sleep(ms: number): void;
166
- /** Returns the number of milliseconds elapsed since the epoch */
167
- now(): number;
168
- /** Returns the current time as an ISO string */
169
- timestamp(): string;
170
- }
171
-
172
- // --- URL ---
173
- interface URLModule {
174
- /** Parses a URL string */
175
- parse(url: string): UrlObject;
176
- /** Formats a URL object into a string */
177
- format(urlObj: any): string;
178
- /** URLSearchParams constructor */
179
- SearchParams: typeof TitanURLSearchParams;
180
- }
181
-
182
- interface UrlObject {
183
- protocol: string;
184
- hostname: string;
185
- port: string;
186
- pathname: string;
187
- search: string;
188
- hash: string;
189
- }
190
-
191
- class TitanURLSearchParams {
192
- constructor(init?: string | Record<string, string>);
193
- get(key: string): string | null;
194
- set(key: string, value: string): void;
195
- has(key: string): boolean;
196
- delete(key: string): void;
197
- toString(): string;
198
- entries(): [string, string][];
199
- keys(): string[];
200
- values(): string[];
201
- }
202
-
203
- // --- Buffer ---
204
- interface BufferModule {
205
- /** Creates Uint8Array from Base64 string */
206
- fromBase64(str: string): Uint8Array;
207
- /** Encodes Uint8Array or String to Base64 string */
208
- toBase64(bytes: Uint8Array | string): string;
209
- /** Creates Uint8Array from Hex string */
210
- fromHex(str: string): Uint8Array;
211
- /** Encodes bytes to Hex string */
212
- toHex(bytes: Uint8Array | string): string;
213
- /** Creates Uint8Array from UTF-8 string */
214
- fromUtf8(str: string): Uint8Array;
215
- /** Decodes bytes to UTF-8 string */
216
- toUtf8(bytes: Uint8Array): string;
217
- }
218
-
219
- // --- Local Storage ---
220
- interface LocalStorage {
221
- /** Gets a value from local storage */
222
- get(key: string): string | null;
223
- /** Sets a value in local storage */
224
- set(key: string, value: string): void;
225
- /** Removes a value from local storage */
226
- remove(key: string): void;
227
- /** Clears all local storage */
228
- clear(): void;
229
- /** Returns all keys in local storage */
230
- keys(): string[];
231
- }
232
-
233
- // --- Session ---
234
- interface Session {
235
- /** Gets a value from a session */
236
- get(sessionId: string, key: string): string | null;
237
- /** Sets a value in a session */
238
- set(sessionId: string, key: string, value: string): void;
239
- /** Deletes a value from a session */
240
- delete(sessionId: string, key: string): void;
241
- /** Clears a session */
242
- clear(sessionId: string): void;
243
- }
244
-
245
- // --- Cookies ---
246
- interface Cookies {
247
- /** Parses cookie from request headers */
248
- get(req: any, name: string): string | null;
249
- /** Sets Set-Cookie header on response */
250
- set(res: any, name: string, value: string, options?: CookieOptions): void;
251
- /** Deletes cookie by setting maxAge=0 */
252
- delete(res: any, name: string): void;
253
- }
254
-
255
- interface CookieOptions {
256
- maxAge?: number;
257
- path?: string;
258
- httpOnly?: boolean;
259
- secure?: boolean;
260
- sameSite?: string;
261
- }
262
- }
263
- }
264
-
265
- export { };
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 { };