@titanpl/core 2.0.8 → 2.1.0

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,929 @@
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 Extension - Titan Core Standard Library
10
+ *
11
+ * High-performance runtime APIs for file I/O, cryptography, networking, and data storage.
12
+ */
13
+ "@titanpl/core": TitanCore.Core;
14
+
15
+ /**
16
+ * Alias for @titanpl/core
17
+ */
18
+ "titan-core": TitanCore.Core;
19
+
20
+ /**
21
+ * File System API - Native file operations
22
+ */
23
+ fs: TitanCore.FileSystem;
24
+
25
+ /**
26
+ * Path API - Cross-platform path manipulation
27
+ */
28
+ path: TitanCore.Path;
29
+
30
+ /**
31
+ * Cryptography API - Hashing, encryption, random generation
32
+ */
33
+ crypto: TitanCore.Crypto;
34
+
35
+ /**
36
+ * Operating System API - System information
37
+ */
38
+ os: TitanCore.OS;
39
+
40
+ /**
41
+ * Network API - DNS resolution and IP utilities
42
+ */
43
+ net: TitanCore.Net;
44
+
45
+ /**
46
+ * Process API - Runtime process information
47
+ */
48
+ proc: TitanCore.Process;
49
+
50
+ /**
51
+ * Time API - Time utilities and delays
52
+ */
53
+ time: TitanCore.Time;
54
+
55
+ /**
56
+ * URL API - URL parsing and manipulation
57
+ */
58
+ url: TitanCore.URLModule;
59
+
60
+ /**
61
+ * Buffer API - Binary data encoding/decoding
62
+ */
63
+ buffer: TitanCore.BufferModule;
64
+
65
+ /**
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
+ */
81
+ ls: TitanCore.LocalStorage;
82
+
83
+ /**
84
+ * Alias for `t.ls` - Local Storage
85
+ */
86
+ localStorage: TitanCore.LocalStorage;
87
+
88
+ /**
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
+ */
103
+ session: TitanCore.Session;
104
+
105
+ /**
106
+ * Cookie API - HTTP cookie parsing and setting
107
+ */
108
+ cookies: TitanCore.Cookies;
109
+
110
+ /**
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
+ */
125
+ response: TitanCore.ResponseModule;
126
+
127
+ /**
128
+ * Core namespace - Unified access to all APIs
129
+ */
130
+ core: TitanCore.Core;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Titan Core Global Namespace
136
+ */
137
+ namespace TitanCore {
138
+ /**
139
+ * Core module containing all standard library APIs
140
+ */
141
+ interface Core {
142
+ fs: FileSystem;
143
+ path: Path;
144
+ crypto: Crypto;
145
+ os: OS;
146
+ net: Net;
147
+ proc: Process;
148
+ time: Time;
149
+ url: URLModule;
150
+ buffer: BufferModule;
151
+ ls: LocalStorage;
152
+ session: Session;
153
+ cookies: Cookies;
154
+ response: ResponseModule;
155
+ }
156
+
157
+ // ==================== File System ====================
158
+
159
+ /**
160
+ * File System API - Native file operations backed by Rust
161
+ */
162
+ interface FileSystem {
163
+ /**
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
168
+ */
169
+ readFile(path: string): string;
170
+
171
+ /**
172
+ * Writes content to file (creates if doesn't exist)
173
+ * @param path - Target file path
174
+ * @param content - Content to write
175
+ */
176
+ writeFile(path: string, content: string): void;
177
+
178
+ /**
179
+ * Reads directory contents
180
+ * @param path - Directory path
181
+ * @returns Array of file/directory names
182
+ */
183
+ readdir(path: string): string[];
184
+
185
+ /**
186
+ * Creates directory recursively (like `mkdir -p`)
187
+ * @param path - Directory path to create
188
+ */
189
+ mkdir(path: string): void;
190
+
191
+ /**
192
+ * Checks if path exists
193
+ * @param path - Path to check
194
+ * @returns true if exists, false otherwise
195
+ */
196
+ exists(path: string): boolean;
197
+
198
+ /**
199
+ * Returns file/directory statistics
200
+ * @param path - Path to stat
201
+ * @returns Stats object with size, type, and modification time
202
+ */
203
+ stat(path: string): Stats;
204
+
205
+ /**
206
+ * Removes file or directory (recursive for directories)
207
+ * @param path - Path to remove
208
+ */
209
+ remove(path: string): void;
210
+ }
211
+
212
+ /**
213
+ * File/directory statistics
214
+ */
215
+ interface Stats {
216
+ /** File size in bytes */
217
+ size: number;
218
+ /** True if path is a file */
219
+ isFile: boolean;
220
+ /** True if path is a directory */
221
+ isDir: boolean;
222
+ /** Last modified timestamp (milliseconds since epoch) */
223
+ modified: number;
224
+ }
225
+
226
+ // ==================== Path ====================
227
+
228
+ /**
229
+ * Path API - Cross-platform path manipulation
230
+ */
231
+ interface Path {
232
+ /**
233
+ * Joins path segments using platform-specific separator
234
+ * @param args - Path segments to join
235
+ * @returns Joined path
236
+ * @example
237
+ * ```typescript
238
+ * t.path.join('app', 'actions', 'test.js') // "app/actions/test.js"
239
+ * ```
240
+ */
241
+ join(...args: string[]): string;
242
+
243
+ /**
244
+ * Resolves path segments to an absolute path
245
+ * @param args - Path segments to resolve
246
+ * @returns Absolute path
247
+ */
248
+ resolve(...args: string[]): string;
249
+
250
+ /**
251
+ * Returns the file extension including the dot
252
+ * @param path - File path
253
+ * @returns Extension (e.g., ".js", ".json") or empty string
254
+ */
255
+ extname(path: string): string;
256
+
257
+ /**
258
+ * Returns the directory name of a path
259
+ * @param path - File or directory path
260
+ * @returns Parent directory path
261
+ */
262
+ dirname(path: string): string;
263
+
264
+ /**
265
+ * Returns the last portion of a path (filename)
266
+ * @param path - Path to extract basename from
267
+ * @returns Filename or directory name
268
+ */
269
+ basename(path: string): string;
270
+ }
271
+
272
+ // ==================== Crypto ====================
273
+
274
+ /**
275
+ * Cryptography API - Hashing, encryption, and random generation
276
+ */
277
+ interface Crypto {
278
+ /**
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
+ * ```
287
+ */
288
+ hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): string;
289
+
290
+ /**
291
+ * Generates cryptographically secure random bytes
292
+ * @param size - Number of bytes to generate
293
+ * @returns Hex-encoded random string
294
+ */
295
+ randomBytes(size: number): string;
296
+
297
+ /**
298
+ * Generates a UUID v4 string
299
+ * @returns UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000")
300
+ */
301
+ uuid(): string;
302
+
303
+ /**
304
+ * Base64 encoding/decoding utilities
305
+ */
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
+ };
321
+
322
+ /**
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
328
+ */
329
+ encrypt(algorithm: string, key: string, plaintext: string): string;
330
+
331
+ /**
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
337
+ */
338
+ decrypt(algorithm: string, key: string, ciphertext: string): string;
339
+
340
+ /**
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
346
+ */
347
+ 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
+ }
357
+
358
+ // ==================== OS ====================
359
+
360
+ /**
361
+ * Operating System API - System information
362
+ */
363
+ interface OS {
364
+ /**
365
+ * Returns the operating system platform
366
+ * @returns Platform name (e.g., "windows", "linux", "darwin")
367
+ */
368
+ platform(): string;
369
+
370
+ /**
371
+ * Returns the number of logical CPU cores
372
+ * @returns Number of CPUs
373
+ */
374
+ cpus(): number;
375
+
376
+ /**
377
+ * Returns total system memory in bytes
378
+ * @returns Total memory in bytes
379
+ */
380
+ totalMemory(): number;
381
+
382
+ /**
383
+ * Returns free system memory in bytes
384
+ * @returns Free memory in bytes
385
+ */
386
+ freeMemory(): number;
387
+
388
+ /**
389
+ * Returns the system temporary directory path
390
+ * @returns Temp directory path
391
+ */
392
+ tmpdir(): string;
393
+ }
394
+
395
+ // ==================== Network ====================
396
+
397
+ /**
398
+ * Network API - DNS resolution and IP utilities
399
+ */
400
+ interface Net {
401
+ /**
402
+ * Resolves hostname to IP addresses
403
+ * @param hostname - Domain name to resolve
404
+ * @returns Array of IP addresses
405
+ */
406
+ resolveDNS(hostname: string): string[];
407
+
408
+ /**
409
+ * Returns the local machine's IP address
410
+ * @returns Local IP address
411
+ */
412
+ ip(): string;
413
+
414
+ /**
415
+ * Pings a host (currently always returns true)
416
+ * @param host - Host to ping
417
+ * @returns Always true
418
+ */
419
+ ping(host: string): boolean;
420
+ }
421
+
422
+ // ==================== Process ====================
423
+
424
+ /**
425
+ * Process API - Runtime process information
426
+ */
427
+ interface Process {
428
+ /**
429
+ * Returns the current process ID
430
+ * @returns Process ID (PID)
431
+ */
432
+ pid(): number;
433
+
434
+ /**
435
+ * Returns the process uptime in seconds
436
+ * @returns Uptime in seconds
437
+ */
438
+ uptime(): number;
439
+
440
+ /**
441
+ * Returns memory usage statistics
442
+ * @returns Memory usage object
443
+ */
444
+ memory(): Record<string, any>;
445
+ }
446
+
447
+ // ==================== Time ====================
448
+
449
+ /**
450
+ * Time API - Time utilities and delays
451
+ */
452
+ 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
+ */
458
+ sleep(ms: number): void;
459
+
460
+ /**
461
+ * Returns the current timestamp in milliseconds
462
+ * @returns Milliseconds since Unix epoch
463
+ */
464
+ 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
+ */
470
+ timestamp(): string;
471
+ }
472
+
473
+ // ==================== URL ====================
474
+
475
+ /**
476
+ * URL API - URL parsing and manipulation
477
+ */
478
+ interface URLModule {
479
+ /**
480
+ * Parses a URL string into components
481
+ * @param url - URL string to parse
482
+ * @returns Parsed URL object
483
+ */
484
+ parse(url: string): UrlObject;
485
+
486
+ /**
487
+ * Formats a URL object into a string
488
+ * @param urlObj - URL object to format
489
+ * @returns URL string
490
+ */
491
+ format(urlObj: any): string;
492
+
493
+ /**
494
+ * URLSearchParams constructor
495
+ */
496
+ SearchParams: typeof TitanURLSearchParams;
497
+ }
498
+
499
+ /**
500
+ * Parsed URL components
501
+ */
502
+ interface UrlObject {
503
+ protocol: string;
504
+ hostname: string;
505
+ port: string;
506
+ pathname: string;
507
+ search: string;
508
+ hash: string;
509
+ }
510
+
511
+ /**
512
+ * URLSearchParams - Query string parsing and manipulation
513
+ */
514
+ class TitanURLSearchParams {
515
+ constructor(init?: string | Record<string, string>);
516
+
517
+ /**
518
+ * Gets a query parameter value
519
+ * @param key - Parameter name
520
+ * @returns Parameter value or null
521
+ */
522
+ get(key: string): string | null;
523
+
524
+ /**
525
+ * Sets a query parameter
526
+ * @param key - Parameter name
527
+ * @param value - Parameter value
528
+ */
529
+ set(key: string, value: string): void;
530
+
531
+ /**
532
+ * Checks if parameter exists
533
+ * @param key - Parameter name
534
+ * @returns true if exists
535
+ */
536
+ has(key: string): boolean;
537
+
538
+ /**
539
+ * Deletes a query parameter
540
+ * @param key - Parameter name
541
+ */
542
+ delete(key: string): void;
543
+
544
+ /**
545
+ * Converts to query string
546
+ * @returns URL-encoded query string
547
+ */
548
+ toString(): string;
549
+
550
+ /**
551
+ * Returns all key-value pairs
552
+ * @returns Array of [key, value] tuples
553
+ */
554
+ entries(): [string, string][];
555
+
556
+ /**
557
+ * Returns all parameter names
558
+ * @returns Array of keys
559
+ */
560
+ keys(): string[];
561
+
562
+ /**
563
+ * Returns all parameter values
564
+ * @returns Array of values
565
+ */
566
+ values(): string[];
567
+ }
568
+
569
+ // ==================== Buffer ====================
570
+
571
+ /**
572
+ * Buffer API - Binary data encoding and decoding
573
+ */
574
+ interface BufferModule {
575
+ /**
576
+ * Decodes Base64 string to bytes
577
+ * @param str - Base64-encoded string
578
+ * @returns Uint8Array of decoded bytes
579
+ */
580
+ 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
+ */
587
+ 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
+ */
594
+ 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
+ */
601
+ 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
+ */
608
+ 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
+ */
615
+ toUtf8(bytes: Uint8Array): string;
616
+ }
617
+
618
+ // ==================== Local Storage ====================
619
+
620
+ /**
621
+ * Local Storage API - High-performance in-memory key-value store
622
+ *
623
+ * **Implementation:** Native Rust RwLock<HashMap>
624
+ *
625
+ * **Performance Benchmarks (10,000 operations):**
626
+ * - 📖 Read: ~156,250 ops/sec (0.0064ms avg)
627
+ * - ✍️ Write: ~89,286 ops/sec (0.0112ms avg)
628
+ * - 🔄 Mixed: ~125,000 ops/sec (0.008ms avg)
629
+ *
630
+ * **Characteristics:**
631
+ * - ⚡ ~1000x faster than file-based storage
632
+ * - 💾 In-memory only (data lost on server restart)
633
+ * - 🔒 Thread-safe with RwLock (multiple readers, single writer)
634
+ * - 🚫 Not shared across multiple processes
635
+ *
636
+ * **Use Cases:**
637
+ * - Request-scoped state sharing
638
+ * - Temporary caching within a process
639
+ * - High-frequency read/write operations
640
+ *
641
+ * @example
642
+ * ```typescript
643
+ * // Store user data temporarily
644
+ * t.ls.set('user:123', JSON.stringify({ name: 'Alice', role: 'admin' }));
645
+ *
646
+ * // Retrieve and parse
647
+ * const userData = JSON.parse(t.ls.get('user:123') || '{}');
648
+ *
649
+ * // Check all keys
650
+ * const allKeys = t.ls.keys(); // ['user:123', ...]
651
+ *
652
+ * // Clean up
653
+ * t.ls.remove('user:123');
654
+ * t.ls.clear(); // Remove all data
655
+ * ```
656
+ */
657
+ 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
+ */
674
+ 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
+ */
690
+ 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
+ */
702
+ 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
+ */
714
+ 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
+ */
727
+ keys(): string[];
728
+ }
729
+
730
+ // ==================== Session ====================
731
+
732
+ /**
733
+ * Session API - High-performance session state management
734
+ *
735
+ * **Implementation:** Native Rust RwLock<HashMap> with composite keys
736
+ *
737
+ * **Performance:** Same as LocalStorage (~89K-156K ops/sec)
738
+ *
739
+ * **Characteristics:**
740
+ * - 🔐 Session-scoped storage (isolated per session ID)
741
+ * - ⚡ Sub-millisecond operations
742
+ * - 💾 In-memory only (not persistent)
743
+ * - 🔑 Composite key format: `{sessionId}:{key}`
744
+ *
745
+ * @example
746
+ * ```typescript
747
+ * // Store shopping cart for session
748
+ * const sessionId = 'sess_abc123';
749
+ * t.session.set(sessionId, 'cart', JSON.stringify([1, 2, 3]));
750
+ *
751
+ * // Retrieve cart
752
+ * const cart = JSON.parse(t.session.get(sessionId, 'cart') || '[]');
753
+ *
754
+ * // Clear entire session
755
+ * t.session.clear(sessionId);
756
+ * ```
757
+ */
758
+ 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
+ */
768
+ 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
+ */
779
+ 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
+ */
787
+ 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
+ */
800
+ clear(sessionId: string): void;
801
+ }
802
+
803
+ // ==================== Cookies ====================
804
+
805
+ /**
806
+ * Cookie API - HTTP cookie parsing and setting
807
+ */
808
+ 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
+ */
821
+ 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
+ */
831
+ 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
+ */
839
+ delete(res: any, name: string): void;
840
+ }
841
+
842
+ /**
843
+ * Cookie configuration options
844
+ */
845
+ interface CookieOptions {
846
+ /** Maximum age in seconds */
847
+ maxAge?: number;
848
+ /** Cookie path (default: "/") */
849
+ path?: string;
850
+ /** HTTP-only flag (prevents JavaScript access) */
851
+ httpOnly?: boolean;
852
+ /** Secure flag (HTTPS only) */
853
+ secure?: boolean;
854
+ /** SameSite policy: "Strict", "Lax", or "None" */
855
+ sameSite?: 'Strict' | 'Lax' | 'None';
856
+ }
857
+
858
+ // ==================== Response ====================
859
+
860
+ /**
861
+ * Response API - Advanced HTTP Response Control
862
+ */
863
+ interface ResponseModule {
864
+ /**
865
+ * Creates a fully custom response
866
+ * @param options - Response configuration
867
+ */
868
+ (options: ResponseOptions): ResponseObject;
869
+
870
+ /**
871
+ * Creates a Plain Text response (Content-Type: text/plain)
872
+ * @param content - Text content
873
+ * @param options - Additional options
874
+ */
875
+ text(content: string, options?: ResponseOptions): ResponseObject;
876
+
877
+ /**
878
+ * Creates an HTML response (Content-Type: text/html)
879
+ * @param content - HTML content
880
+ * @param options - Additional options
881
+ */
882
+ html(content: string, options?: ResponseOptions): ResponseObject;
883
+
884
+ /**
885
+ * Creates a JSON response (Content-Type: application/json)
886
+ * @param content - JSON serializable object
887
+ * @param options - Additional options
888
+ */
889
+ json(content: any, options?: ResponseOptions): ResponseObject;
890
+
891
+ /**
892
+ * Creates a Redirect response (301/302)
893
+ * @param url - URL to redirect to
894
+ * @param status - HTTP Status Code (default: 302)
895
+ */
896
+ redirect(url: string, status?: number): ResponseObject;
897
+
898
+ /**
899
+ * Creates an empty response (e.g., 204 No Content)
900
+ * @param status - HTTP Status Code (default: 204)
901
+ */
902
+ empty(status?: number): ResponseObject;
903
+ }
904
+
905
+ /**
906
+ * Options for customizing the response
907
+ */
908
+ interface ResponseOptions {
909
+ /** HTTP Status Code (e.g., 200, 404, 500) */
910
+ status?: number;
911
+ /** Custom HTTP Headers */
912
+ headers?: Record<string, string>;
913
+ /** Response Body */
914
+ body?: string;
915
+ }
916
+
917
+ /**
918
+ * Standardized Response Object for the Runtime
919
+ */
920
+ interface ResponseObject {
921
+ _isResponse: true;
922
+ status: number;
923
+ headers: Record<string, string>;
924
+ body: string;
925
+ }
926
+ }
927
+ }
928
+
929
+ export { };