@titanpl/native 1.0.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.
Files changed (3) hide show
  1. package/index.js +39 -0
  2. package/package.json +18 -0
  3. package/t.native.d.ts +2043 -0
package/t.native.d.ts ADDED
@@ -0,0 +1,2043 @@
1
+ // =============================================================================
2
+ // Titan Planet — Type Definitions
3
+ // Framework: JavaScript-first backend compiled to native Rust + Axum binary
4
+ // Version: v26 (Stable)
5
+ // Docs: https://titan-docs-ez.vercel.app/docs
6
+ // GitHub: https://github.com/ezet-galaxy/titanpl
7
+ // =============================================================================
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Module Definitions — Imports from "titan"
11
+ // ---------------------------------------------------------------------------
12
+
13
+ /**
14
+ * Represents a normalized HTTP request object passed to every Titan action.
15
+ *
16
+ * This object is **stable, predictable, and serializable** — it is identical
17
+ * across both development (`titan dev`) and production (native binary) modes.
18
+ *
19
+ * @example
20
+ * ```js
21
+ * // Accessing the request inside an action
22
+ * export function getUser(req) {
23
+ * const userId = req.params.id; // Route parameter
24
+ * const page = req.query.page; // Query string ?page=2
25
+ * const data = req.body; // Parsed JSON body (POST/PUT/PATCH)
26
+ * const auth = req.headers["authorization"];
27
+ * return { userId, page, data, auth };
28
+ * }
29
+ * ```
30
+ *
31
+ * @see https://titan-docs-ez.vercel.app/docs/03-actions — Actions documentation
32
+ * @see https://titan-docs-ez.vercel.app/docs/02-routes — Routes & parameters
33
+ */
34
+ export interface TitanRequest {
35
+ /**
36
+ * The parsed request body.
37
+ *
38
+ * - For `POST`, `PUT`, and `PATCH` requests, this contains the parsed JSON payload.
39
+ * - For `GET` and `DELETE` requests, this is typically `null`.
40
+ *
41
+ * Titan automatically parses `application/json` bodies — no middleware needed.
42
+ *
43
+ * @example
44
+ * ```js
45
+ * export function createUser(req) {
46
+ * const { name, email } = req.body;
47
+ * return { created: true, name, email };
48
+ * }
49
+ * ```
50
+ */
51
+ body: any;
52
+
53
+ /**
54
+ * The HTTP method of the incoming request.
55
+ *
56
+ * Titan performs automatic method matching at the route level, so each
57
+ * action typically handles a single method. However, you can inspect
58
+ * this property to branch logic if needed.
59
+ *
60
+ * @example
61
+ * ```js
62
+ * export function handler(req) {
63
+ * if (req.method === "POST") return createItem(req.body);
64
+ * if (req.method === "GET") return listItems();
65
+ * }
66
+ * ```
67
+ */
68
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
69
+
70
+ /**
71
+ * The full URL path of the request (e.g., `"/user/42"`).
72
+ *
73
+ * This is the raw matched path including resolved dynamic segments.
74
+ */
75
+ path: string;
76
+
77
+ /**
78
+ * All HTTP request headers as a flat key-value map.
79
+ *
80
+ * Header names are **lowercased** (e.g., `"content-type"`, `"authorization"`).
81
+ * A header may be `undefined` if it was not sent by the client.
82
+ *
83
+ * @example
84
+ * ```js
85
+ * export function secureAction(req) {
86
+ * const token = req.headers["authorization"];
87
+ * if (!token) return { error: "Unauthorized" };
88
+ * // ...
89
+ * }
90
+ * ```
91
+ */
92
+ headers: Record<string, string | undefined>;
93
+
94
+ /**
95
+ * Dynamic route parameters extracted from the URL path.
96
+ *
97
+ * Defined by route segments like `:id` or typed segments like `:id<number>`.
98
+ * Values are always delivered as **strings** — cast them as needed.
99
+ *
100
+ * @example
101
+ * ```js
102
+ * // Route: /user/:id<number>
103
+ * export function getUser(req) {
104
+ * const id = Number(req.params.id); // "42" → 42
105
+ * return { id };
106
+ * }
107
+ * ```
108
+ *
109
+ * @see https://titan-docs-ez.vercel.app/docs/02-routes — Dynamic routes
110
+ */
111
+ params: Record<string, string>;
112
+
113
+ /**
114
+ * Parsed query string parameters from the URL.
115
+ *
116
+ * For a request to `/search?q=titan&page=2`, this would be:
117
+ * `{ q: "titan", page: "2" }`.
118
+ *
119
+ * Values are always strings. Returns an empty object `{}` when no
120
+ * query parameters are present.
121
+ *
122
+ * @example
123
+ * ```js
124
+ * // GET /products?category=electronics&limit=10
125
+ * export function listProducts(req) {
126
+ * const category = req.query.category; // "electronics"
127
+ * const limit = Number(req.query.limit) || 20;
128
+ * return { category, limit };
129
+ * }
130
+ * ```
131
+ */
132
+ query: Record<string, string>;
133
+ }
134
+
135
+ /**
136
+ * Wraps an action handler function with type-safe request typing.
137
+ *
138
+ * `defineAction` is an optional helper that provides IntelliSense and
139
+ * type-checking for your action's `req` parameter and return value.
140
+ * It is **purely a development-time utility** — at runtime it simply
141
+ * returns the same function unchanged (zero overhead).
142
+ *
143
+ * @typeParam T - The return type of the action handler.
144
+ * @param handler - The action function that receives a `TitanRequest` and returns `T`.
145
+ * @returns The same handler function with proper type annotations.
146
+ *
147
+ * @example
148
+ * ```js
149
+ * import { defineAction } from "titan";
150
+ *
151
+ * export const getUser = defineAction((req) => {
152
+ * // req is fully typed as TitanRequest
153
+ * const id = Number(req.params.id);
154
+ * return { id, method: req.method };
155
+ * });
156
+ * ```
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * // TypeScript — with explicit return type
161
+ * import { defineAction } from "titan";
162
+ *
163
+ * interface UserResponse { id: number; name: string; }
164
+ *
165
+ * export const getUser = defineAction<UserResponse>((req) => {
166
+ * return { id: Number(req.params.id), name: "Titan" };
167
+ * });
168
+ * ```
169
+ *
170
+ * @see https://titan-docs-ez.vercel.app/docs/03-actions — Action definition patterns
171
+ */
172
+ export function defineAction<T>(
173
+ handler: (req: TitanRequest) => T
174
+ ): (req: TitanRequest) => T;
175
+
176
+ /**
177
+ * Built-in Rust-powered HTTP client.
178
+ *
179
+ * Re-exported from the `t` global for module-style imports.
180
+ * @see {@link TitanRuntimeUtils.fetch} for full documentation.
181
+ */
182
+ export const fetch: typeof t.fetch;
183
+
184
+ /**
185
+ * Action-scoped logging utility.
186
+ *
187
+ * Re-exported from the `t` global for module-style imports.
188
+ * @see {@link TitanRuntimeUtils.log} for full documentation.
189
+ */
190
+ export const log: typeof t.log;
191
+
192
+ /**
193
+ * Synchronous file reader for local files.
194
+ *
195
+ * Re-exported from the `t` global for module-style imports.
196
+ * @see {@link TitanRuntimeUtils.read} for full documentation.
197
+ */
198
+ export const read: typeof t.read;
199
+
200
+ /**
201
+ * JWT (JSON Web Token) signing and verification utilities.
202
+ *
203
+ * Re-exported from the `t` global for module-style imports.
204
+ * @see {@link TitanRuntimeUtils.jwt} for full documentation.
205
+ */
206
+ export const jwt: typeof t.jwt;
207
+
208
+ /**
209
+ * Secure password hashing and verification (bcrypt-based).
210
+ *
211
+ * Re-exported from the `t` global for module-style imports.
212
+ * @see {@link TitanRuntimeUtils.password} for full documentation.
213
+ */
214
+ export const password: typeof t.password;
215
+
216
+ /**
217
+ * Database connection and query interface.
218
+ *
219
+ * Re-exported from the `t` global for module-style imports.
220
+ * @see {@link TitanRuntimeUtils.db} for full documentation.
221
+ */
222
+ export const db: typeof t.db;
223
+
224
+ /**
225
+ * Async file system operations (read, write, mkdir, stat, etc.).
226
+ *
227
+ * Re-exported from the `t` global for module-style imports.
228
+ * @see {@link TitanCore.FileSystem} for full documentation.
229
+ */
230
+ export const fs: typeof t.fs;
231
+
232
+ /**
233
+ * Path manipulation utilities (join, resolve, extname, etc.).
234
+ *
235
+ * Re-exported from the `t` global for module-style imports.
236
+ * @see {@link TitanCore.Path} for full documentation.
237
+ */
238
+ export const path: typeof t.path;
239
+
240
+ /**
241
+ * Cryptographic utilities (hashing, encryption, UUIDs, etc.).
242
+ *
243
+ * Re-exported from the `t` global for module-style imports.
244
+ * @see {@link TitanCore.Crypto} for full documentation.
245
+ */
246
+ export const crypto: typeof t.crypto;
247
+
248
+ /**
249
+ * Buffer encoding/decoding utilities (Base64, Hex, UTF-8).
250
+ *
251
+ * Re-exported from the `t` global for module-style imports.
252
+ * @see {@link TitanCore.BufferModule} for full documentation.
253
+ */
254
+ export const buffer: typeof t.buffer;
255
+
256
+ /**
257
+ * Persistent key-value local storage (shorthand alias).
258
+ *
259
+ * Re-exported from the `t` global for module-style imports.
260
+ * @see {@link TitanCore.LocalStorage} for full documentation.
261
+ */
262
+ export const ls: typeof t.ls;
263
+
264
+ /**
265
+ * Persistent key-value local storage.
266
+ *
267
+ * Re-exported from the `t` global for module-style imports.
268
+ * @see {@link TitanCore.LocalStorage} for full documentation.
269
+ */
270
+ export const localStorage: typeof t.localStorage;
271
+
272
+ /**
273
+ * Server-side session management by session ID.
274
+ *
275
+ * Re-exported from the `t` global for module-style imports.
276
+ * @see {@link TitanCore.Session} for full documentation.
277
+ */
278
+ export const session: typeof t.session;
279
+
280
+ /**
281
+ * HTTP cookie read/write/delete utilities.
282
+ *
283
+ * Re-exported from the `t` global for module-style imports.
284
+ * @see {@link TitanCore.Cookies} for full documentation.
285
+ */
286
+ export const cookies: typeof t.cookies;
287
+
288
+ /**
289
+ * Operating system information (platform, CPU count, memory).
290
+ *
291
+ * Re-exported from the `t` global for module-style imports.
292
+ * @see {@link TitanCore.OS} for full documentation.
293
+ */
294
+ export const os: typeof t.os;
295
+
296
+ /**
297
+ * Network utilities (DNS resolution, IP lookup, ping).
298
+ *
299
+ * Re-exported from the `t` global for module-style imports.
300
+ * @see {@link TitanCore.Net} for full documentation.
301
+ */
302
+ export const net: typeof t.net;
303
+
304
+ /**
305
+ * Process-level information (PID, uptime, memory usage).
306
+ *
307
+ * Re-exported from the `t` global for module-style imports.
308
+ * @see {@link TitanCore.Process} for full documentation.
309
+ */
310
+ export const proc: typeof t.proc;
311
+
312
+ /**
313
+ * Time utilities (sleep, timestamps, high-resolution clock).
314
+ *
315
+ * Re-exported from the `t` global for module-style imports.
316
+ * @see {@link TitanCore.Time} for full documentation.
317
+ */
318
+ export const time: typeof t.time;
319
+
320
+ /**
321
+ * URL parsing and formatting utilities.
322
+ *
323
+ * Re-exported from the `t` global for module-style imports.
324
+ * @see {@link TitanCore.URLModule} for full documentation.
325
+ */
326
+ export const url: typeof t.url;
327
+
328
+ /**
329
+ * Runtime validation utilities.
330
+ *
331
+ * Provides schema-based validation for request data. Works with
332
+ * the `@titanpl/valid` package for advanced validation rules.
333
+ *
334
+ * @see https://titan-docs-ez.vercel.app/docs/12-sdk — TitanPl SDK
335
+ */
336
+ export const valid: any;
337
+
338
+
339
+ // ---------------------------------------------------------------------------
340
+ // Global Definitions — Runtime Environment
341
+ // ---------------------------------------------------------------------------
342
+
343
+ declare global {
344
+
345
+ // -----------------------------------------------------------------------
346
+ // Drift — Asynchronous Orchestration Engine
347
+ // -----------------------------------------------------------------------
348
+
349
+ /**
350
+ * # Drift — Deterministic Replay-based Suspension Engine
351
+ *
352
+ * `drift` is Titan's revolutionary mechanism for handling asynchronous
353
+ * operations inside the **strictly synchronous Gravity V8 runtime**.
354
+ *
355
+ * ## How it works
356
+ *
357
+ * When the runtime encounters a `drift()` call:
358
+ *
359
+ * 1. **Suspend** — The current V8 isolate is suspended (not blocked).
360
+ * 2. **Offload** — The async task is dispatched to Rust's Tokio executor.
361
+ * 3. **Free** — The isolate is released to handle other incoming requests.
362
+ * 4. **Replay** — Once the task completes, the action code is **re-played**
363
+ * from the beginning with the resolved value injected deterministically.
364
+ *
365
+ * This model is conceptually similar to **Algebraic Effects** — your code
366
+ * reads as synchronous while the runtime handles concurrency under the hood.
367
+ *
368
+ * ## Important notes
369
+ *
370
+ * - `drift` is the **only** way to await promises in Titan actions.
371
+ * - The action function may be re-executed (replayed) — avoid side effects
372
+ * before the `drift` call that shouldn't be repeated.
373
+ * - Can be used with any Titan API that returns a `Promise` (e.g.,
374
+ * `t.fetch`, `t.db.connect`, `t.password.hash`, `t.fs.readFile`, etc.).
375
+ *
376
+ * @typeParam T - The resolved type of the promise.
377
+ * @param promise - The promise or expression to drift (suspend and resolve).
378
+ * @returns The synchronously resolved value of the input promise.
379
+ *
380
+ * @example
381
+ * ```js
382
+ * // Basic fetch with drift
383
+ * export function getExternalData(req) {
384
+ * const resp = drift(t.fetch("https://api.example.com/data"));
385
+ * return { ok: resp.ok, data: JSON.parse(resp.body) };
386
+ * }
387
+ * ```
388
+ *
389
+ * @example
390
+ * ```js
391
+ * // Multiple drift calls (sequential)
392
+ * export function processOrder(req) {
393
+ * const user = drift(t.fetch("https://api.example.com/user/1"));
394
+ * const order = drift(t.fetch("https://api.example.com/order/99"));
395
+ * return { user: JSON.parse(user.body), order: JSON.parse(order.body) };
396
+ * }
397
+ * ```
398
+ *
399
+ * @example
400
+ * ```js
401
+ * // Drift with database operations
402
+ * export function getUsers(req) {
403
+ * const conn = drift(t.db.connect(process.env.DATABASE_URL));
404
+ * const users = drift(conn.query("SELECT * FROM users LIMIT 10"));
405
+ * return { users };
406
+ * }
407
+ * ```
408
+ *
409
+ * @see https://titan-docs-ez.vercel.app/docs/14-drift — Drift documentation
410
+ * @see https://titan-docs-ez.vercel.app/docs/runtime-architecture — Gravity Runtime
411
+ */
412
+ var drift: <T>(promise: Promise<T> | T) => T;
413
+
414
+
415
+ // -----------------------------------------------------------------------
416
+ // Database Connection Interface
417
+ // -----------------------------------------------------------------------
418
+
419
+ /**
420
+ * Represents an active database connection returned by `t.db.connect()`.
421
+ *
422
+ * Provides a single `query()` method for executing SQL statements with
423
+ * optional parameterized values to prevent SQL injection.
424
+ *
425
+ * @example
426
+ * ```js
427
+ * export function listUsers(req) {
428
+ * const conn = drift(t.db.connect(process.env.DATABASE_URL));
429
+ *
430
+ * // Simple query
431
+ * const all = drift(conn.query("SELECT * FROM users"));
432
+ *
433
+ * // Parameterized query (safe from SQL injection)
434
+ * const one = drift(conn.query(
435
+ * "SELECT * FROM users WHERE id = $1",
436
+ * [req.params.id]
437
+ * ));
438
+ *
439
+ * return { all, user: one[0] };
440
+ * }
441
+ * ```
442
+ *
443
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs
444
+ */
445
+ interface DbConnection {
446
+ /**
447
+ * Execute a SQL query against the connected database.
448
+ *
449
+ * Supports parameterized queries using positional placeholders (`$1`, `$2`, etc.)
450
+ * to prevent SQL injection attacks.
451
+ *
452
+ * @param sql - The SQL query string. Use `$1`, `$2`, ... for parameter placeholders.
453
+ * @param params - Optional array of values to bind to the query placeholders (in order).
454
+ * @returns A promise that resolves to an array of result rows (as plain objects).
455
+ *
456
+ * @example
457
+ * ```js
458
+ * // SELECT with parameters
459
+ * const users = drift(conn.query(
460
+ * "SELECT * FROM users WHERE role = $1 AND active = $2",
461
+ * ["admin", true]
462
+ * ));
463
+ *
464
+ * // INSERT
465
+ * drift(conn.query(
466
+ * "INSERT INTO users (name, email) VALUES ($1, $2)",
467
+ * ["Alice", "alice@example.com"]
468
+ * ));
469
+ *
470
+ * // UPDATE
471
+ * drift(conn.query(
472
+ * "UPDATE users SET name = $1 WHERE id = $2",
473
+ * ["Bob", 42]
474
+ * ));
475
+ * ```
476
+ */
477
+ query(sql: string, params?: any[]): Promise<any[]>;
478
+ }
479
+
480
+
481
+ // -----------------------------------------------------------------------
482
+ // Titan Runtime Utils — The `t` / `Titan` global object
483
+ // -----------------------------------------------------------------------
484
+
485
+ /**
486
+ * The Titan Runtime Utilities interface — the core API surface available
487
+ * globally as `t` (or `Titan`) in every action.
488
+ *
489
+ * All methods on `t` are powered by native Rust implementations under
490
+ * the hood, providing near-zero overhead and memory safety. Async methods
491
+ * must be consumed via the `drift()` operator.
492
+ *
493
+ * @example
494
+ * ```js
495
+ * // The `t` object is always available — no imports needed
496
+ * export function myAction(req) {
497
+ * t.log("Request received:", req.method, req.path);
498
+ * const resp = drift(t.fetch("https://api.example.com/data"));
499
+ * return { status: resp.status, body: JSON.parse(resp.body) };
500
+ * }
501
+ * ```
502
+ *
503
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Complete Runtime APIs reference
504
+ */
505
+ interface TitanRuntimeUtils {
506
+
507
+ // -------------------------------------------------------------------
508
+ // Core I/O
509
+ // -------------------------------------------------------------------
510
+
511
+ /**
512
+ * Action-scoped, sandboxed logging utility.
513
+ *
514
+ * Writes messages to the Titan **Gravity Logs** system. Logs are
515
+ * prefixed with the action name for easy filtering and debugging.
516
+ * Accepts any number of arguments of any type (they are serialized
517
+ * automatically).
518
+ *
519
+ * Output in the terminal appears as:
520
+ * ```
521
+ * [Titan] log(myAction): your message here
522
+ * ```
523
+ *
524
+ * @param args - One or more values to log (strings, numbers, objects, etc.).
525
+ *
526
+ * @example
527
+ * ```js
528
+ * t.log("Processing user", req.params.id);
529
+ * t.log("Body received:", req.body);
530
+ * t.log("Multiple", "values", { are: "supported" }, 42);
531
+ * ```
532
+ *
533
+ * @see https://titan-docs-ez.vercel.app/docs/06-logs — Gravity Logs
534
+ */
535
+ log(...args: any[]): void;
536
+
537
+ /**
538
+ * Synchronously reads the contents of a local file as a UTF-8 string.
539
+ *
540
+ * This is a **blocking, synchronous** operation — suitable for reading
541
+ * small configuration files, templates, or static assets at startup.
542
+ * For larger or async file operations, prefer `t.fs.readFile()` with `drift()`.
543
+ *
544
+ * @param path - Absolute or relative path to the file to read.
545
+ * @returns The file contents as a UTF-8 string.
546
+ * @throws If the file does not exist or cannot be read.
547
+ *
548
+ * @example
549
+ * ```js
550
+ * export function getConfig(req) {
551
+ * const raw = t.read("./config.json");
552
+ * return JSON.parse(raw);
553
+ * }
554
+ * ```
555
+ *
556
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs
557
+ */
558
+ read(path: string): string;
559
+
560
+ /**
561
+ * Built-in Rust-powered HTTP client for making outbound requests.
562
+ *
563
+ * Powered by Rust's native HTTP stack — **not** `node-fetch` or any
564
+ * JS-based client. Provides high-performance, non-blocking HTTP calls.
565
+ *
566
+ * Returns a `Promise` — use with `drift()` to resolve it inside an action.
567
+ *
568
+ * @param url - The target URL to request (must include protocol, e.g. `"https://..."`).
569
+ * @param options - Optional request configuration.
570
+ * @param options.method - HTTP method. Defaults to `"GET"`.
571
+ * @param options.headers - Key-value map of request headers.
572
+ * @param options.body - Request body. Strings are sent as-is; objects are
573
+ * automatically JSON-serialized with `Content-Type: application/json`.
574
+ *
575
+ * @returns A promise resolving to a response object with:
576
+ * - `ok` — `true` if the status code is 2xx.
577
+ * - `status` — The HTTP status code (e.g., `200`, `404`, `500`).
578
+ * - `body` — The response body as a string (parse with `JSON.parse()` if needed).
579
+ * - `error` — An error message string if the request failed at the network level.
580
+ *
581
+ * @example
582
+ * ```js
583
+ * // Simple GET
584
+ * export function getData(req) {
585
+ * const resp = drift(t.fetch("https://api.example.com/items"));
586
+ * return JSON.parse(resp.body);
587
+ * }
588
+ * ```
589
+ *
590
+ * @example
591
+ * ```js
592
+ * // POST with JSON body and headers
593
+ * export function createItem(req) {
594
+ * const resp = drift(t.fetch("https://api.example.com/items", {
595
+ * method: "POST",
596
+ * headers: {
597
+ * "Authorization": "Bearer " + process.env.API_KEY,
598
+ * "Content-Type": "application/json"
599
+ * },
600
+ * body: { name: req.body.name, price: req.body.price }
601
+ * }));
602
+ *
603
+ * if (!resp.ok) return { error: "Failed", status: resp.status };
604
+ * return JSON.parse(resp.body);
605
+ * }
606
+ * ```
607
+ *
608
+ * @example
609
+ * ```js
610
+ * // Error handling
611
+ * export function safeFetch(req) {
612
+ * const resp = drift(t.fetch("https://unreliable-api.com/data"));
613
+ * if (resp.error) return { error: resp.error };
614
+ * if (!resp.ok) return { error: `HTTP ${resp.status}` };
615
+ * return JSON.parse(resp.body);
616
+ * }
617
+ * ```
618
+ *
619
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.fetch)
620
+ */
621
+ fetch(url: string, options?: {
622
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
623
+ headers?: Record<string, string>;
624
+ body?: string | object;
625
+ }): Promise<{
626
+ ok: boolean;
627
+ status?: number;
628
+ body?: string;
629
+ error?: string;
630
+ }>;
631
+
632
+
633
+ // -------------------------------------------------------------------
634
+ // Authentication & Security
635
+ // -------------------------------------------------------------------
636
+
637
+ /**
638
+ * JSON Web Token (JWT) utilities for stateless authentication.
639
+ *
640
+ * Provides `sign` and `verify` methods backed by Rust cryptographic
641
+ * implementations. Ideal for issuing access tokens and validating
642
+ * incoming Bearer tokens in API actions.
643
+ *
644
+ * > **Note:** Both methods are **synchronous** — no `drift()` needed.
645
+ *
646
+ * @example
647
+ * ```js
648
+ * // Sign a token
649
+ * export function login(req) {
650
+ * const { username, password } = req.body;
651
+ * // ... validate credentials ...
652
+ * const token = t.jwt.sign(
653
+ * { sub: userId, role: "admin" },
654
+ * process.env.JWT_SECRET,
655
+ * { expiresIn: "7d" }
656
+ * );
657
+ * return { token };
658
+ * }
659
+ *
660
+ * // Verify a token
661
+ * export function protectedAction(req) {
662
+ * const token = req.headers["authorization"]?.replace("Bearer ", "");
663
+ * try {
664
+ * const payload = t.jwt.verify(token, process.env.JWT_SECRET);
665
+ * return { userId: payload.sub, role: payload.role };
666
+ * } catch (e) {
667
+ * return t.response.json({ error: "Invalid token" }, 401);
668
+ * }
669
+ * }
670
+ * ```
671
+ *
672
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.jwt)
673
+ */
674
+ jwt: {
675
+ /**
676
+ * Create a signed JWT from a payload object.
677
+ *
678
+ * @param payload - The data to encode in the token (e.g., `{ sub: "user123", role: "admin" }`).
679
+ * Avoid putting sensitive data here — JWTs are encoded, not encrypted.
680
+ * @param secret - The secret key used for HMAC signing. Store in environment variables.
681
+ * @param options - Optional signing options.
682
+ * @param options.expiresIn - Token expiration time.
683
+ * Accepts duration strings (`"1h"`, `"7d"`, `"30m"`) or
684
+ * a number representing seconds.
685
+ * @returns The signed JWT as a string (e.g., `"eyJhbGciOi..."`).
686
+ *
687
+ * @example
688
+ * ```js
689
+ * const token = t.jwt.sign({ userId: 1 }, "my-secret", { expiresIn: "24h" });
690
+ * ```
691
+ */
692
+ sign(payload: object, secret: string, options?: { expiresIn?: string | number }): string;
693
+
694
+ /**
695
+ * Verify and decode a JWT, returning the original payload.
696
+ *
697
+ * @param token - The JWT string to verify.
698
+ * @param secret - The secret key used to verify the signature.
699
+ * @returns The decoded payload object if the token is valid and not expired.
700
+ * @throws If the token is invalid, expired, or the signature doesn't match.
701
+ *
702
+ * @example
703
+ * ```js
704
+ * try {
705
+ * const payload = t.jwt.verify(token, process.env.JWT_SECRET);
706
+ * t.log("User:", payload.sub);
707
+ * } catch (err) {
708
+ * t.log("Token verification failed");
709
+ * }
710
+ * ```
711
+ */
712
+ verify(token: string, secret: string): any;
713
+ };
714
+
715
+ /**
716
+ * Secure password hashing and verification powered by bcrypt (Rust implementation).
717
+ *
718
+ * Both methods return `Promise` values — use `drift()` to resolve them.
719
+ *
720
+ * @example
721
+ * ```js
722
+ * // Registration: hash the password before storing
723
+ * export function register(req) {
724
+ * const { email, password } = req.body;
725
+ * const hashed = drift(t.password.hash(password));
726
+ * // Store `hashed` in your database
727
+ * return { success: true, email };
728
+ * }
729
+ *
730
+ * // Login: compare submitted password against stored hash
731
+ * export function login(req) {
732
+ * const { email, password } = req.body;
733
+ * // Retrieve `storedHash` from your database
734
+ * const valid = drift(t.password.verify(password, storedHash));
735
+ * if (!valid) return t.response.json({ error: "Invalid credentials" }, 401);
736
+ * return { token: t.jwt.sign({ email }, process.env.JWT_SECRET) };
737
+ * }
738
+ * ```
739
+ *
740
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.password)
741
+ */
742
+ password: {
743
+ /**
744
+ * Hash a plain-text password using bcrypt.
745
+ *
746
+ * Automatically generates a secure salt. The resulting hash string
747
+ * includes the salt, making it safe to store directly in a database.
748
+ *
749
+ * @param password - The plain-text password to hash.
750
+ * @returns A promise resolving to the bcrypt hash string.
751
+ *
752
+ * @example
753
+ * ```js
754
+ * const hash = drift(t.password.hash("my-secure-password"));
755
+ * // hash → "$2b$12$LJ3m4ys..."
756
+ * ```
757
+ */
758
+ hash(password: string): Promise<string>;
759
+
760
+ /**
761
+ * Verify a plain-text password against a previously hashed value.
762
+ *
763
+ * @param password - The plain-text password to check.
764
+ * @param hash - The bcrypt hash string to compare against.
765
+ * @returns A promise resolving to `true` if the password matches, `false` otherwise.
766
+ *
767
+ * @example
768
+ * ```js
769
+ * const isValid = drift(t.password.verify("my-password", storedHash));
770
+ * if (!isValid) return { error: "Wrong password" };
771
+ * ```
772
+ */
773
+ verify(password: string, hash: string): Promise<boolean>;
774
+ };
775
+
776
+
777
+ // -------------------------------------------------------------------
778
+ // Database
779
+ // -------------------------------------------------------------------
780
+
781
+ /**
782
+ * Database connection interface.
783
+ *
784
+ * Establish connections to SQL databases (PostgreSQL, MySQL, SQLite, etc.)
785
+ * using a connection URL. Returns a `DbConnection` instance for executing queries.
786
+ *
787
+ * > **Important:** `connect()` returns a `Promise` — always wrap it with `drift()`.
788
+ *
789
+ * @example
790
+ * ```js
791
+ * export function getUsers(req) {
792
+ * const conn = drift(t.db.connect(process.env.DATABASE_URL));
793
+ * const users = drift(conn.query("SELECT id, name, email FROM users"));
794
+ * return { users };
795
+ * }
796
+ * ```
797
+ *
798
+ * @example
799
+ * ```js
800
+ * // Full CRUD example
801
+ * export function createUser(req) {
802
+ * const conn = drift(t.db.connect(process.env.DATABASE_URL));
803
+ * const { name, email } = req.body;
804
+ *
805
+ * drift(conn.query(
806
+ * "INSERT INTO users (name, email) VALUES ($1, $2)",
807
+ * [name, email]
808
+ * ));
809
+ *
810
+ * return { created: true, name, email };
811
+ * }
812
+ * ```
813
+ *
814
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.db)
815
+ */
816
+ db: {
817
+ /**
818
+ * Establish a database connection.
819
+ *
820
+ * @param url - A database connection string.
821
+ *
822
+ * Supported formats:
823
+ * - PostgreSQL: `"postgres://user:pass@host:5432/dbname"`
824
+ * - MySQL: `"mysql://user:pass@host:3306/dbname"`
825
+ * - SQLite: `"sqlite://./data.db"`
826
+ *
827
+ * @returns A promise resolving to a {@link DbConnection} instance.
828
+ *
829
+ * @example
830
+ * ```js
831
+ * const conn = drift(
832
+ * t.db.connect("postgres://admin:secret@localhost:5432/mydb")
833
+ * );
834
+ * ```
835
+ */
836
+ connect(url: string): Promise<DbConnection>;
837
+
838
+ /**
839
+ * Execute a SQL query using the default database connection.
840
+ *
841
+ * Uses the configured `DATABASE_URL` internally.
842
+ * Ideal for simple and one-off queries.
843
+ *
844
+ * @example
845
+ * ```js
846
+ * const users = drift(
847
+ * t.db.query("SELECT * FROM users")
848
+ * );
849
+ * ```
850
+ *
851
+ * @example
852
+ * ```js
853
+ * const user = drift(
854
+ * t.db.query(
855
+ * "SELECT * FROM users WHERE id = $1",
856
+ * [42]
857
+ * )
858
+ * );
859
+ * ```
860
+ *
861
+ * @example
862
+ * ```js
863
+ * const sql = drift(t.fs.readFile("./db/login.sql"));
864
+ * const rows = drift(t.db.query(sql, [email, hash]));
865
+ * ```
866
+ *
867
+ * @param sql - SQL query string.
868
+ * @param params - Optional positional parameters.
869
+ * @returns A promise resolving to query result rows.
870
+ */
871
+ query(sql: string, params?: any[]): Promise<any[]>;
872
+ };
873
+
874
+
875
+
876
+ // -------------------------------------------------------------------
877
+ // File System & Paths
878
+ // -------------------------------------------------------------------
879
+
880
+ /**
881
+ * Asynchronous file system operations.
882
+ *
883
+ * Provides async methods for reading, writing, and managing files and
884
+ * directories. All methods return `Promise` — use `drift()` to resolve.
885
+ *
886
+ * @see {@link TitanCore.FileSystem} for method signatures.
887
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.fs)
888
+ */
889
+ fs: TitanCore.FileSystem;
890
+
891
+ /**
892
+ * Path manipulation utilities.
893
+ *
894
+ * All methods are **synchronous** — no `drift()` needed. Provides
895
+ * cross-platform path joining, resolving, and component extraction.
896
+ *
897
+ * @see {@link TitanCore.Path} for method signatures.
898
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.path)
899
+ */
900
+ path: TitanCore.Path;
901
+
902
+
903
+ // -------------------------------------------------------------------
904
+ // Cryptography & Encoding
905
+ // -------------------------------------------------------------------
906
+
907
+ /**
908
+ * Cryptographic utilities powered by Rust's native crypto libraries.
909
+ *
910
+ * Includes hashing (SHA-256, SHA-512, MD5), HMAC, symmetric encryption/decryption,
911
+ * random bytes generation, and UUID creation. Async methods require `drift()`.
912
+ *
913
+ * @see {@link TitanCore.Crypto} for method signatures.
914
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.crypto)
915
+ */
916
+ crypto: TitanCore.Crypto;
917
+
918
+ /**
919
+ * Buffer encoding and decoding utilities for Base64, Hex, and UTF-8 conversions.
920
+ *
921
+ * All methods are **synchronous** — no `drift()` needed.
922
+ *
923
+ * @see {@link TitanCore.BufferModule} for method signatures.
924
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.buffer)
925
+ */
926
+ buffer: TitanCore.BufferModule;
927
+
928
+
929
+ // -------------------------------------------------------------------
930
+ // Storage & State
931
+ // -------------------------------------------------------------------
932
+
933
+ /**
934
+ * Persistent key-value local storage (shorthand alias for `t.localStorage`).
935
+ *
936
+ * Data persists across requests and server restarts. All methods are
937
+ * **synchronous**. Useful for caching, feature flags, or small config values.
938
+ *
939
+ * @use Perfect for caching frequently accessed data and complex objects within a single process.
940
+ * @suggestion Use `setObject`/`getObject` for complex data structures to maintain types.
941
+
942
+ * @see {@link TitanCore.LocalStorage} for method signatures.
943
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.ls)
944
+ */
945
+ ls: TitanCore.LocalStorage;
946
+
947
+ /**
948
+ * Persistent key-value local storage.
949
+ *
950
+ * Data persists across requests and server restarts. All methods are
951
+ * **synchronous**. Identical to `t.ls` — use whichever alias you prefer.
952
+ *
953
+ * @see {@link TitanCore.LocalStorage} for method signatures.
954
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.localStorage)
955
+ */
956
+ localStorage: TitanCore.LocalStorage;
957
+
958
+ /**
959
+ * Server-side session management.
960
+ *
961
+ * Store and retrieve data by session ID. Sessions are scoped per client
962
+ * and useful for tracking authentication state, user preferences, or
963
+ * multi-step form data.
964
+ *
965
+ * All methods are **synchronous**.
966
+ *
967
+ * @see {@link TitanCore.Session} for method signatures.
968
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.session)
969
+ */
970
+ session: TitanCore.Session;
971
+
972
+ /**
973
+ * HTTP cookie utilities for reading, setting, and deleting cookies.
974
+ *
975
+ * @see {@link TitanCore.Cookies} for method signatures.
976
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.cookies)
977
+ */
978
+ cookies: TitanCore.Cookies;
979
+
980
+
981
+ // -------------------------------------------------------------------
982
+ // System & Network
983
+ // -------------------------------------------------------------------
984
+
985
+ /**
986
+ * Operating system information.
987
+ *
988
+ * Retrieve platform details, CPU count, and memory statistics of the
989
+ * host machine running the Titan server.
990
+ *
991
+ * @see {@link TitanCore.OS} for method signatures.
992
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.os)
993
+ */
994
+ os: TitanCore.OS;
995
+
996
+ /**
997
+ * Network utilities for DNS resolution, IP lookup, and host pinging.
998
+ *
999
+ * All methods return `Promise` — use `drift()` to resolve.
1000
+ *
1001
+ * @see {@link TitanCore.Net} for method signatures.
1002
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.net)
1003
+ */
1004
+ net: TitanCore.Net;
1005
+
1006
+ /**
1007
+ * Process-level information for the running Titan server binary.
1008
+ *
1009
+ * All methods are **synchronous**.
1010
+ *
1011
+ * @see {@link TitanCore.Process} for method signatures.
1012
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.proc)
1013
+ */
1014
+ proc: TitanCore.Process;
1015
+
1016
+
1017
+ // -------------------------------------------------------------------
1018
+ // Utilities
1019
+ // -------------------------------------------------------------------
1020
+
1021
+ /**
1022
+ * Time-related utilities including sleep, timestamps, and high-resolution clock.
1023
+ *
1024
+ * `t.time.sleep()` is async (requires `drift()`); other methods are synchronous.
1025
+ *
1026
+ * @see {@link TitanCore.Time} for method signatures.
1027
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.time)
1028
+ */
1029
+ time: TitanCore.Time;
1030
+
1031
+ /**
1032
+ * URL parsing and formatting utilities.
1033
+ *
1034
+ * @see {@link TitanCore.URLModule} for method signatures.
1035
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs (t.url)
1036
+ */
1037
+ url: TitanCore.URLModule;
1038
+
1039
+ /**
1040
+
1041
+ /**
1042
+ * Runtime validation utilities.
1043
+ *
1044
+ * Provides schema-based validation for request payloads and other data.
1045
+ * Works with the `@titanpl/valid` package for advanced rules.
1046
+ *
1047
+ * @see https://www.npmjs.com/package/@titanpl/valid — TitanPl Valid Extension
1048
+ */
1049
+ valid: any;
1050
+
1051
+ /**
1052
+ * Extension index signature — allows access to dynamically loaded
1053
+ * Titan Extensions registered via `titan create ext`.
1054
+ *
1055
+ * Custom extensions attach their methods to the `t` object at runtime,
1056
+ * making them available as `t.myExtension.someMethod()`.
1057
+ *
1058
+ * @see https://titan-docs-ez.vercel.app/docs/10-extensions — Extensions documentation
1059
+ */
1060
+ [key: string]: any;
1061
+
1062
+
1063
+ }
1064
+
1065
+ /**
1066
+ * The primary global Titan runtime object.
1067
+ *
1068
+ * Available in every action without imports. Provides access to all
1069
+ * built-in Titan APIs: HTTP client, logging, JWT, database, file system,
1070
+ * crypto, storage, sessions, cookies, OS info, networking, and more.
1071
+ *
1072
+ * @example
1073
+ * ```js
1074
+ * export function myAction(req) {
1075
+ * t.log("Hello from Titan!");
1076
+ * return { message: "It works" };
1077
+ * }
1078
+ * ```
1079
+ *
1080
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Full API reference
1081
+ * @see https://titan-docs-ez.vercel.app/docs/13-titan-core — TitanCore Runtime APIs
1082
+ */
1083
+ const t: TitanRuntimeUtils;
1084
+
1085
+ /**
1086
+ * Alias for the `t` global runtime object.
1087
+ *
1088
+ * `Titan` and `t` are interchangeable — use whichever you prefer.
1089
+ * Both reference the exact same runtime utilities instance.
1090
+ *
1091
+ * @example
1092
+ * ```js
1093
+ * export function myAction(req) {
1094
+ * Titan.log("Using the Titan alias");
1095
+ * const resp = drift(Titan.fetch("https://api.example.com"));
1096
+ * return JSON.parse(resp.body);
1097
+ * }
1098
+ * ```
1099
+ */
1100
+ const Titan: TitanRuntimeUtils;
1101
+
1102
+
1103
+ // -----------------------------------------------------------------------
1104
+ // TitanCore Namespace — Detailed Sub-module Interfaces
1105
+ // -----------------------------------------------------------------------
1106
+
1107
+ namespace TitanCore {
1108
+ interface TitanResponse {
1109
+ readonly __titan_response: true;
1110
+ }
1111
+ /**
1112
+ * Asynchronous file system operations.
1113
+ *
1114
+ * All methods return `Promise` and must be used with `drift()`.
1115
+ *
1116
+ * @example
1117
+ * ```js
1118
+ * export function fileOps(req) {
1119
+ * // Check if a file exists
1120
+ * const exists = drift(t.fs.exists("./data/config.json"));
1121
+ *
1122
+ * // Read a file
1123
+ * const content = drift(t.fs.readFile("./data/config.json"));
1124
+ *
1125
+ * // Write a file
1126
+ * drift(t.fs.writeFile("./data/output.json", JSON.stringify({ ok: true })));
1127
+ *
1128
+ * // Create a directory
1129
+ * drift(t.fs.mkdir("./data/backups"));
1130
+ *
1131
+ * // List directory contents
1132
+ * const files = drift(t.fs.readdir("./data"));
1133
+ *
1134
+ * // Get file metadata
1135
+ * const info = drift(t.fs.stat("./data/config.json"));
1136
+ * t.log("Size:", info.size, "Is file:", info.isFile);
1137
+ *
1138
+ * // Delete a file
1139
+ * drift(t.fs.remove("./data/temp.txt"));
1140
+ *
1141
+ * return { exists, files, info };
1142
+ * }
1143
+ * ```
1144
+ *
1145
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.fs)
1146
+ */
1147
+ interface FileSystem {
1148
+ /**
1149
+ * Read the entire contents of a file as a UTF-8 string.
1150
+ *
1151
+ * @param path - Path to the file to read.
1152
+ * @returns A promise resolving to the file contents.
1153
+ * @throws If the file does not exist or cannot be read.
1154
+ */
1155
+ readFile(path: string): Promise<string>;
1156
+
1157
+ /**
1158
+ * Write a string to a file, creating or overwriting it.
1159
+ *
1160
+ * @param path - Path to the file to write.
1161
+ * @param content - The string content to write.
1162
+ * @returns A promise that resolves when writing is complete.
1163
+ */
1164
+ writeFile(path: string, content: string): Promise<void>;
1165
+
1166
+ /**
1167
+ * List the names of all entries in a directory.
1168
+ *
1169
+ * @param path - Path to the directory.
1170
+ * @returns A promise resolving to an array of file/directory names.
1171
+ */
1172
+ readdir(path: string): Promise<string[]>;
1173
+
1174
+ /**
1175
+ * Create a directory (and parent directories if needed).
1176
+ *
1177
+ * @param path - Path of the directory to create.
1178
+ * @returns A promise that resolves when the directory is created.
1179
+ */
1180
+ mkdir(path: string): Promise<void>;
1181
+
1182
+ /**
1183
+ * Check whether a file or directory exists at the given path.
1184
+ *
1185
+ * @param path - Path to check.
1186
+ * @returns A promise resolving to `true` if the path exists, `false` otherwise.
1187
+ */
1188
+ exists(path: string): Promise<boolean>;
1189
+
1190
+ /**
1191
+ * Get metadata about a file or directory.
1192
+ *
1193
+ * @param path - Path to the file or directory.
1194
+ * @returns A promise resolving to a stat object with:
1195
+ * - `size` — File size in bytes.
1196
+ * - `isFile` — `true` if the path is a regular file.
1197
+ * - `isDir` — `true` if the path is a directory.
1198
+ * - `modified` — Last modification time as a Unix timestamp (ms).
1199
+ */
1200
+ stat(path: string): Promise<{
1201
+ size: number;
1202
+ isFile: boolean;
1203
+ isDir: boolean;
1204
+ modified: number;
1205
+ }>;
1206
+
1207
+ /**
1208
+ * Delete a file or directory.
1209
+ *
1210
+ * @param path - Path to the file or directory to remove.
1211
+ * @returns A promise that resolves when the removal is complete.
1212
+ * @throws If the path does not exist.
1213
+ */
1214
+ remove(path: string): Promise<void>;
1215
+ }
1216
+
1217
+ /**
1218
+ * Cross-platform path manipulation utilities.
1219
+ *
1220
+ * All methods are **synchronous** — no `drift()` needed.
1221
+ *
1222
+ * @example
1223
+ * ```js
1224
+ * const full = t.path.join("data", "users", "profile.json");
1225
+ * // → "data/users/profile.json"
1226
+ *
1227
+ * const abs = t.path.resolve("./config.json");
1228
+ * // → "/app/config.json"
1229
+ *
1230
+ * t.path.extname("photo.png"); // → ".png"
1231
+ * t.path.dirname("/a/b/c.txt"); // → "/a/b"
1232
+ * t.path.basename("/a/b/c.txt"); // → "c.txt"
1233
+ * ```
1234
+ *
1235
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.path)
1236
+ */
1237
+ interface Path {
1238
+ /**
1239
+ * Join multiple path segments into a single normalized path.
1240
+ *
1241
+ * @param args - Two or more path segments to join.
1242
+ * @returns The joined and normalized path string.
1243
+ *
1244
+ * @example
1245
+ * ```js
1246
+ * t.path.join("data", "users", "profile.json");
1247
+ * // → "data/users/profile.json"
1248
+ * ```
1249
+ */
1250
+ join(...args: string[]): string;
1251
+
1252
+ /**
1253
+ * Resolve a sequence of paths into an absolute path.
1254
+ *
1255
+ * @param args - Path segments. Relative segments are resolved against the working directory.
1256
+ * @returns The resolved absolute path string.
1257
+ *
1258
+ * @example
1259
+ * ```js
1260
+ * t.path.resolve("./config.json");
1261
+ * // → "/app/config.json"
1262
+ * ```
1263
+ */
1264
+ resolve(...args: string[]): string;
1265
+
1266
+ /**
1267
+ * Get the file extension (including the leading dot).
1268
+ *
1269
+ * @param path - The file path.
1270
+ * @returns The extension string (e.g., `".json"`, `".png"`), or `""` if none.
1271
+ */
1272
+ extname(path: string): string;
1273
+
1274
+ /**
1275
+ * Get the directory portion of a path.
1276
+ *
1277
+ * @param path - The file path.
1278
+ * @returns The directory path (e.g., `"/a/b"` from `"/a/b/c.txt"`).
1279
+ */
1280
+ dirname(path: string): string;
1281
+
1282
+ /**
1283
+ * Get the last segment (filename) of a path.
1284
+ *
1285
+ * @param path - The file path.
1286
+ * @returns The filename (e.g., `"c.txt"` from `"/a/b/c.txt"`).
1287
+ */
1288
+ basename(path: string): string;
1289
+ }
1290
+
1291
+ /**
1292
+ * Cryptographic operations powered by Rust's native crypto libraries.
1293
+ *
1294
+ * Includes hashing, HMAC, symmetric encryption/decryption, random bytes,
1295
+ * UUID generation, and constant-time comparison.
1296
+ *
1297
+ * Async methods (`hash`, `encrypt`, `decrypt`, `hashKeyed`) require `drift()`.
1298
+ * Sync methods (`randomBytes`, `uuid`, `compare`) do not.
1299
+ *
1300
+ * @example
1301
+ * ```js
1302
+ * export function cryptoDemo(req) {
1303
+ * // Hash a string
1304
+ * const sha = drift(t.crypto.hash("sha256", "hello world"));
1305
+ *
1306
+ * // Generate a UUID
1307
+ * const id = t.crypto.uuid();
1308
+ *
1309
+ * // Random bytes (hex-encoded)
1310
+ * const rand = t.crypto.randomBytes(32);
1311
+ *
1312
+ * // HMAC signing
1313
+ * const sig = drift(t.crypto.hashKeyed("hmac-sha256", "secret", "message"));
1314
+ *
1315
+ * // Encrypt / Decrypt
1316
+ * const encrypted = drift(t.crypto.encrypt("aes-256-gcm", "my-key", "secret data"));
1317
+ * const decrypted = drift(t.crypto.decrypt("aes-256-gcm", "my-key", encrypted));
1318
+ *
1319
+ * return { sha, id, rand, sig, decrypted };
1320
+ * }
1321
+ * ```
1322
+ *
1323
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.crypto)
1324
+ */
1325
+ interface Crypto {
1326
+ /**
1327
+ * Compute a cryptographic hash of the input data.
1328
+ *
1329
+ * @param algorithm - The hash algorithm: `"sha256"`, `"sha512"`, or `"md5"`.
1330
+ * @param data - The string to hash.
1331
+ * @returns A promise resolving to the hex-encoded hash string.
1332
+ *
1333
+ * @example
1334
+ * ```js
1335
+ * const hash = drift(t.crypto.hash("sha256", "hello"));
1336
+ * // → "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
1337
+ * ```
1338
+ */
1339
+ hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): Promise<string>;
1340
+
1341
+ /**
1342
+ * Generate cryptographically secure random bytes as a hex string.
1343
+ *
1344
+ * This is a **synchronous** operation — no `drift()` needed.
1345
+ *
1346
+ * @param size - Number of random bytes to generate.
1347
+ * @returns A hex-encoded string of `size` random bytes (length = `size * 2`).
1348
+ *
1349
+ * @example
1350
+ * ```js
1351
+ * const secret = t.crypto.randomBytes(32);
1352
+ * // → "a1b2c3d4e5f6..." (64 hex chars)
1353
+ * ```
1354
+ */
1355
+ randomBytes(size: number): string;
1356
+
1357
+ /**
1358
+ * Generate a random UUID v4 string.
1359
+ *
1360
+ * This is a **synchronous** operation — no `drift()` needed.
1361
+ *
1362
+ * @returns A UUID v4 string (e.g., `"550e8400-e29b-41d4-a716-446655440000"`).
1363
+ *
1364
+ * @example
1365
+ * ```js
1366
+ * const id = t.crypto.uuid();
1367
+ * // → "f47ac10b-58cc-4372-a567-0e02b2c3d479"
1368
+ * ```
1369
+ */
1370
+ uuid(): string;
1371
+
1372
+ /**
1373
+ * Perform a constant-time string comparison to prevent timing attacks.
1374
+ *
1375
+ * This is a **synchronous** operation — no `drift()` needed.
1376
+ *
1377
+ * @param hash - The first string (typically a hash or token).
1378
+ * @param target - The second string to compare against.
1379
+ * @returns `true` if the strings are identical, `false` otherwise.
1380
+ *
1381
+ * @example
1382
+ * ```js
1383
+ * const isMatch = t.crypto.compare(computedHash, expectedHash);
1384
+ * ```
1385
+ */
1386
+ compare(hash: string, target: string): boolean;
1387
+
1388
+ /**
1389
+ * Encrypt data using a symmetric encryption algorithm.
1390
+ *
1391
+ * @param algorithm - The encryption algorithm (e.g., `"aes-256-gcm"`).
1392
+ * @param key - The encryption key string.
1393
+ * @param plaintext - The data to encrypt.
1394
+ * @returns A promise resolving to the encrypted ciphertext string.
1395
+ *
1396
+ * @example
1397
+ * ```js
1398
+ * const encrypted = drift(t.crypto.encrypt("aes-256-gcm", myKey, "secret data"));
1399
+ * ```
1400
+ */
1401
+ encrypt(algorithm: string, key: string, plaintext: string): Promise<string>;
1402
+
1403
+ /**
1404
+ * Decrypt data previously encrypted with `t.crypto.encrypt()`.
1405
+ *
1406
+ * @param algorithm - The same algorithm used for encryption.
1407
+ * @param key - The same key used for encryption.
1408
+ * @param ciphertext - The encrypted string to decrypt.
1409
+ * @returns A promise resolving to the original plaintext string.
1410
+ *
1411
+ * @example
1412
+ * ```js
1413
+ * const plaintext = drift(t.crypto.decrypt("aes-256-gcm", myKey, encrypted));
1414
+ * ```
1415
+ */
1416
+ decrypt(algorithm: string, key: string, ciphertext: string): Promise<string>;
1417
+
1418
+ /**
1419
+ * Compute an HMAC (Hash-based Message Authentication Code).
1420
+ *
1421
+ * Useful for verifying message integrity and authenticity
1422
+ * (e.g., webhook signature validation).
1423
+ *
1424
+ * @param algorithm - The HMAC algorithm: `"hmac-sha256"` or `"hmac-sha512"`.
1425
+ * @param key - The secret key for the HMAC.
1426
+ * @param message - The message to authenticate.
1427
+ * @returns A promise resolving to the hex-encoded HMAC string.
1428
+ *
1429
+ * @example
1430
+ * ```js
1431
+ * // Verify a webhook signature
1432
+ * export function webhook(req) {
1433
+ * const signature = req.headers["x-signature"];
1434
+ * const computed = drift(t.crypto.hashKeyed(
1435
+ * "hmac-sha256",
1436
+ * process.env.WEBHOOK_SECRET,
1437
+ * JSON.stringify(req.body)
1438
+ * ));
1439
+ * if (!t.crypto.compare(computed, signature)) {
1440
+ * return t.response.json({ error: "Invalid signature" }, 401);
1441
+ * }
1442
+ * return { verified: true };
1443
+ * }
1444
+ * ```
1445
+ */
1446
+ hashKeyed(algorithm: 'hmac-sha256' | 'hmac-sha512', key: string, message: string): Promise<string>;
1447
+ }
1448
+
1449
+ /**
1450
+ * Buffer encoding and decoding utilities.
1451
+ *
1452
+ * Convert between `string`, `Uint8Array`, Base64, Hex, and UTF-8
1453
+ * representations. All methods are **synchronous** — no `drift()` needed.
1454
+ *
1455
+ * @example
1456
+ * ```js
1457
+ * // Base64 encode/decode
1458
+ * const encoded = t.buffer.toBase64("Hello, Titan!");
1459
+ * const decoded = t.buffer.toUtf8(t.buffer.fromBase64(encoded));
1460
+ *
1461
+ * // Hex encode/decode
1462
+ * const hex = t.buffer.toHex("Hello");
1463
+ * const bytes = t.buffer.fromHex(hex);
1464
+ * ```
1465
+ *
1466
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.buffer)
1467
+ */
1468
+ interface BufferModule {
1469
+ /**
1470
+ * Decode a Base64-encoded string into a `Uint8Array`.
1471
+ *
1472
+ * @param str - The Base64-encoded string.
1473
+ * @returns The decoded byte array.
1474
+ */
1475
+ fromBase64(str: string): Uint8Array;
1476
+
1477
+ /**
1478
+ * Encode bytes or a string to Base64.
1479
+ *
1480
+ * @param bytes - A `Uint8Array` or plain string to encode.
1481
+ * @returns The Base64-encoded string.
1482
+ */
1483
+ toBase64(bytes: Uint8Array | string): string;
1484
+
1485
+ /**
1486
+ * Decode a hex-encoded string into a `Uint8Array`.
1487
+ *
1488
+ * @param str - The hex-encoded string (e.g., `"48656c6c6f"`).
1489
+ * @returns The decoded byte array.
1490
+ */
1491
+ fromHex(str: string): Uint8Array;
1492
+
1493
+ /**
1494
+ * Encode bytes or a string to hexadecimal.
1495
+ *
1496
+ * @param bytes - A `Uint8Array` or plain string to encode.
1497
+ * @returns The hex-encoded string.
1498
+ */
1499
+ toHex(bytes: Uint8Array | string): string;
1500
+
1501
+ /**
1502
+ * Encode a UTF-8 string into a `Uint8Array`.
1503
+ *
1504
+ * @param str - The string to encode.
1505
+ * @returns The UTF-8 encoded byte array.
1506
+ */
1507
+ fromUtf8(str: string): Uint8Array;
1508
+
1509
+ /**
1510
+ * Decode a `Uint8Array` back into a UTF-8 string.
1511
+ *
1512
+ * @param bytes - The byte array to decode.
1513
+ * @returns The decoded UTF-8 string.
1514
+ */
1515
+ toUtf8(bytes: Uint8Array): string;
1516
+ }
1517
+
1518
+ /**
1519
+ * Persistent server-side key-value storage.
1520
+ *
1521
+ * Data persists across requests and server restarts. Accessible via
1522
+ * `t.ls` (shorthand) or `t.localStorage` (full name).
1523
+ *
1524
+ * Values are stored as strings — serialize complex objects with
1525
+ * `JSON.stringify()` and parse with `JSON.parse()`.
1526
+ *
1527
+ * All methods are **synchronous** — no `drift()` needed.
1528
+ *
1529
+ * @example
1530
+ * ```js
1531
+ * // Set and retrieve values
1532
+ * t.ls.set("app:version", "2.0.0");
1533
+ * const version = t.ls.get("app:version"); // → "2.0.0"
1534
+ *
1535
+ * // Store objects (serialize manually)
1536
+ * t.ls.set("config", JSON.stringify({ theme: "dark", lang: "en" }));
1537
+ * const config = JSON.parse(t.ls.get("config"));
1538
+ *
1539
+ * // List all keys
1540
+ * const allKeys = t.ls.keys(); // → ["app:version", "config"]
1541
+ *
1542
+ * // Delete a key
1543
+ * t.ls.remove("app:version");
1544
+ *
1545
+ * // Clear all stored data
1546
+ * t.ls.clear();
1547
+ * ```
1548
+ *
1549
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.ls / t.localStorage)
1550
+ */
1551
+ interface LocalStorage {
1552
+ /**
1553
+ * Retrieve the value associated with a key.
1554
+ *
1555
+ * @param key - The storage key.
1556
+ * @returns The stored string value, or `null` if the key does not exist.
1557
+ */
1558
+ get(key: string): string | null;
1559
+
1560
+ /**
1561
+ * Store a value under the given key (creates or overwrites).
1562
+ *
1563
+ * @param key - The storage key.
1564
+ * @param value - The string value to store.
1565
+ */
1566
+ set(key: string, value: string): void;
1567
+
1568
+ /**
1569
+ * Delete a single key from storage.
1570
+ *
1571
+ * @param key - The key to remove. No error if the key doesn't exist.
1572
+ */
1573
+ remove(key: string): void;
1574
+
1575
+ /**
1576
+ * Clear all keys and values from local storage.
1577
+ *
1578
+ * ⚠️ **Destructive** — removes everything. Use with caution.
1579
+ */
1580
+ clear(): void;
1581
+
1582
+ /**
1583
+ * Get a list of all stored keys.
1584
+ *
1585
+ * @returns An array of all key names currently in storage.
1586
+ */
1587
+ keys(): string[];
1588
+
1589
+ /** Stores a complex JavaScript object using V8 serialization and Base64 encoding. */
1590
+ setObject(key: string, value: any): void;
1591
+ /** Retrieves and deserializes a complex JavaScript object. Returns null if not found or invalid. */
1592
+ getObject<T = any>(key: string): T | null;
1593
+
1594
+ /**
1595
+ * Serialize a JavaScript value to a V8-compatible binary format.
1596
+ *
1597
+ * **Features:**
1598
+ * - Supports Map, Set, Date, RegExp, BigInt, TypedArray
1599
+ * - Supports Circular references
1600
+ * - ~50x faster than JSON.stringify
1601
+ *
1602
+ * @param value The value to serialize.
1603
+ */
1604
+ serialize(value: any): Uint8Array;
1605
+
1606
+ /**
1607
+ * Deserialize a V8-compatible binary format back to a JavaScript value.
1608
+ *
1609
+ * @param bytes The binary data to deserialize.
1610
+ */
1611
+ deserialize(bytes: Uint8Array): any;
1612
+
1613
+ /**
1614
+ * Register a class for hydration/serialization support.
1615
+ */
1616
+ register(ClassRef: Function, hydrateFn?: Function, typeName?: string): void;
1617
+
1618
+ /**
1619
+ * Hydrate a custom object from data.
1620
+ */
1621
+ hydrate(typeName: string, data: object): any;
1622
+ }
1623
+
1624
+ /**
1625
+ * Server-side session management scoped by session ID.
1626
+ *
1627
+ * Sessions store ephemeral per-client data on the server. Each session
1628
+ * is identified by a unique `sessionId` (typically from a cookie or token).
1629
+ *
1630
+ * All methods are **synchronous** — no `drift()` needed.
1631
+ *
1632
+ * @example
1633
+ * ```js
1634
+ * export function setPreference(req) {
1635
+ * const sid = req.headers["x-session-id"];
1636
+ * t.session.set(sid, "theme", "dark");
1637
+ * t.session.set(sid, "lang", "en");
1638
+ * return { saved: true };
1639
+ * }
1640
+ *
1641
+ * export function getPreference(req) {
1642
+ * const sid = req.headers["x-session-id"];
1643
+ * const theme = t.session.get(sid, "theme");
1644
+ * return { theme };
1645
+ * }
1646
+ *
1647
+ * export function logout(req) {
1648
+ * const sid = req.headers["x-session-id"];
1649
+ * t.session.clear(sid); // Destroy entire session
1650
+ * return { loggedOut: true };
1651
+ * }
1652
+ * ```
1653
+ *
1654
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.session)
1655
+ */
1656
+ interface Session {
1657
+ /**
1658
+ * Retrieve a value from a session.
1659
+ *
1660
+ * @param sessionId - The unique session identifier.
1661
+ * @param key - The key to look up within the session.
1662
+ * @returns The stored value, or `null` if not found.
1663
+ */
1664
+ get(sessionId: string, key: string): string | null;
1665
+
1666
+ /**
1667
+ * Store a value in a session (creates or overwrites).
1668
+ *
1669
+ * @param sessionId - The unique session identifier.
1670
+ * @param key - The key to store under.
1671
+ * @param value - The string value to store.
1672
+ */
1673
+ set(sessionId: string, key: string, value: string): void;
1674
+
1675
+ /**
1676
+ * Delete a single key from a session.
1677
+ *
1678
+ * @param sessionId - The unique session identifier.
1679
+ * @param key - The key to delete.
1680
+ */
1681
+ delete(sessionId: string, key: string): void;
1682
+
1683
+ /**
1684
+ * Destroy an entire session, removing all its data.
1685
+ *
1686
+ * @param sessionId - The unique session identifier to clear.
1687
+ */
1688
+ clear(sessionId: string): void;
1689
+ }
1690
+
1691
+ /**
1692
+ * HTTP cookie management utilities.
1693
+ *
1694
+ * Read, set, and delete cookies from incoming requests and outgoing responses.
1695
+ *
1696
+ * @example
1697
+ * ```js
1698
+ * export function handleCookies(req) {
1699
+ * // Read a cookie from the request
1700
+ * const token = t.cookies.get(req, "auth_token");
1701
+ *
1702
+ * // Set a cookie (attach to response)
1703
+ * t.cookies.set(req, "visited", "true", {
1704
+ * httpOnly: true,
1705
+ * secure: true,
1706
+ * maxAge: 86400 // 1 day in seconds
1707
+ * });
1708
+ *
1709
+ * // Delete a cookie
1710
+ * t.cookies.delete(req, "old_cookie");
1711
+ *
1712
+ * return { hasToken: !!token };
1713
+ * }
1714
+ * ```
1715
+ *
1716
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.cookies)
1717
+ */
1718
+ interface Cookies {
1719
+ /**
1720
+ * Read a cookie value from the request.
1721
+ *
1722
+ * @param req - The Titan request object (or response context).
1723
+ * @param name - The cookie name.
1724
+ * @returns The cookie value string, or `null` if the cookie is not present.
1725
+ */
1726
+ get(req: any, name: string): string | null;
1727
+
1728
+ /**
1729
+ * Set a cookie on the response.
1730
+ *
1731
+ * @param res - The response context object.
1732
+ * @param name - The cookie name.
1733
+ * @param value - The cookie value.
1734
+ * @param options - Optional cookie attributes (e.g., `httpOnly`, `secure`, `maxAge`, `path`, `sameSite`).
1735
+ */
1736
+ set(res: any, name: string, value: string, options?: any): void;
1737
+
1738
+ /**
1739
+ * Delete a cookie by setting its expiration in the past.
1740
+ *
1741
+ * @param res - The response context object.
1742
+ * @param name - The cookie name to delete.
1743
+ */
1744
+ delete(res: any, name: string): void;
1745
+ }
1746
+
1747
+ /**
1748
+ * Operating system information about the host running the Titan server.
1749
+ *
1750
+ * All methods are **synchronous** — no `drift()` needed.
1751
+ *
1752
+ * @example
1753
+ * ```js
1754
+ * export function serverInfo(req) {
1755
+ * return {
1756
+ * platform: t.os.platform(), // e.g., "linux"
1757
+ * cpus: t.os.cpus(), // e.g., 8
1758
+ * totalMemory: t.os.totalMemory(), // bytes
1759
+ * freeMemory: t.os.freeMemory(), // bytes
1760
+ * tmpdir: t.os.tmpdir() // e.g., "/tmp"
1761
+ * };
1762
+ * }
1763
+ * ```
1764
+ *
1765
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.os)
1766
+ */
1767
+ interface OS {
1768
+ /**
1769
+ * Get the operating system platform identifier.
1770
+ *
1771
+ * @returns A string like `"linux"`, `"darwin"` (macOS), or `"win32"` (Windows).
1772
+ */
1773
+ platform(): string;
1774
+
1775
+ /**
1776
+ * Get the number of logical CPU cores available.
1777
+ *
1778
+ * @returns The number of CPU cores.
1779
+ */
1780
+ cpus(): number;
1781
+
1782
+ /**
1783
+ * Get the total system memory in bytes.
1784
+ *
1785
+ * @returns Total memory in bytes.
1786
+ */
1787
+ totalMemory(): number;
1788
+
1789
+ /**
1790
+ * Get the currently available (free) system memory in bytes.
1791
+ *
1792
+ * @returns Free memory in bytes.
1793
+ */
1794
+ freeMemory(): number;
1795
+
1796
+ /**
1797
+ * Get the path to the system's temporary directory.
1798
+ *
1799
+ * @returns The temporary directory path (e.g., `"/tmp"`).
1800
+ */
1801
+ tmpdir(): string;
1802
+ }
1803
+
1804
+ /**
1805
+ * Network utility functions.
1806
+ *
1807
+ * All methods return `Promise` — use `drift()` to resolve.
1808
+ *
1809
+ * @example
1810
+ * ```js
1811
+ * export function networkInfo(req) {
1812
+ * const ips = drift(t.net.resolveDNS("example.com"));
1813
+ * const myIp = drift(t.net.ip());
1814
+ * const reachable = drift(t.net.ping("8.8.8.8"));
1815
+ * return { ips, myIp, reachable };
1816
+ * }
1817
+ * ```
1818
+ *
1819
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.net)
1820
+ */
1821
+ interface Net {
1822
+ /**
1823
+ * Resolve a hostname to its IP addresses via DNS lookup.
1824
+ *
1825
+ * @param hostname - The domain to resolve (e.g., `"example.com"`).
1826
+ * @returns A promise resolving to an array of IP address strings.
1827
+ */
1828
+ resolveDNS(hostname: string): Promise<string[]>;
1829
+
1830
+ /**
1831
+ * Get the public IP address of the current server.
1832
+ *
1833
+ * @returns A promise resolving to the server's public IP string.
1834
+ */
1835
+ ip(): Promise<string>;
1836
+
1837
+ /**
1838
+ * Ping a host to check if it is reachable.
1839
+ *
1840
+ * @param host - The hostname or IP address to ping.
1841
+ * @returns A promise resolving to `true` if the host responds, `false` otherwise.
1842
+ */
1843
+ ping(host: string): Promise<boolean>;
1844
+ }
1845
+
1846
+ /**
1847
+ * Process-level information about the running Titan server binary.
1848
+ *
1849
+ * All methods are **synchronous** — no `drift()` needed.
1850
+ *
1851
+ * @example
1852
+ * ```js
1853
+ * export function processInfo(req) {
1854
+ * return {
1855
+ * pid: t.proc.pid(), // e.g., 12345
1856
+ * uptime: t.proc.uptime(), // seconds since start
1857
+ * memory: t.proc.memory() // { rss, heapTotal, heapUsed, ... }
1858
+ * };
1859
+ * }
1860
+ * ```
1861
+ *
1862
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.proc)
1863
+ */
1864
+ interface Process {
1865
+ /**
1866
+ * Get the process ID (PID) of the Titan server.
1867
+ *
1868
+ * @returns The numeric process ID.
1869
+ */
1870
+ pid(): number;
1871
+
1872
+ /**
1873
+ * Get the server uptime in seconds since the process started.
1874
+ *
1875
+ * @returns Uptime in seconds.
1876
+ */
1877
+ uptime(): number;
1878
+
1879
+ /**
1880
+ * Get memory usage statistics for the server process.
1881
+ *
1882
+ * @returns An object with memory metrics (e.g., `rss`, `heapTotal`, `heapUsed`).
1883
+ */
1884
+ memory(): Record<string, any>;
1885
+ }
1886
+
1887
+ /**
1888
+ * Time-related utilities.
1889
+ *
1890
+ * `sleep()` is async (requires `drift()`). `now()` and `timestamp()` are synchronous.
1891
+ *
1892
+ * @example
1893
+ * ```js
1894
+ * export function timeDemo(req) {
1895
+ * const start = t.time.now(); // High-resolution ms timestamp
1896
+ * drift(t.time.sleep(100)); // Wait 100ms
1897
+ * const elapsed = t.time.now() - start;
1898
+ * const iso = t.time.timestamp(); // "2026-01-15T12:30:45.123Z"
1899
+ * return { elapsed, iso };
1900
+ * }
1901
+ * ```
1902
+ *
1903
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.time)
1904
+ */
1905
+ interface Time {
1906
+ /**
1907
+ * Pause execution for the given number of milliseconds.
1908
+ *
1909
+ * Returns a `Promise` — use `drift()` to suspend the action without blocking
1910
+ * the entire server. Useful for rate limiting, retry delays, or testing.
1911
+ *
1912
+ * @param ms - Duration to sleep in milliseconds.
1913
+ * @returns A promise that resolves after the specified duration.
1914
+ *
1915
+ * @example
1916
+ * ```js
1917
+ * drift(t.time.sleep(500)); // Wait 500ms
1918
+ * ```
1919
+ */
1920
+ sleep(ms: number): Promise<void>;
1921
+
1922
+ /**
1923
+ * Get the current time as a high-resolution millisecond timestamp.
1924
+ *
1925
+ * This is a **synchronous** operation.
1926
+ *
1927
+ * @returns A numeric timestamp in milliseconds (similar to `Date.now()`).
1928
+ */
1929
+ now(): number;
1930
+
1931
+ /**
1932
+ * Get the current time as an ISO 8601 formatted string.
1933
+ *
1934
+ * This is a **synchronous** operation.
1935
+ *
1936
+ * @returns An ISO timestamp string (e.g., `"2026-01-15T12:30:45.123Z"`).
1937
+ */
1938
+ timestamp(): string;
1939
+ }
1940
+
1941
+ /**
1942
+ * URL parsing and formatting utilities.
1943
+ *
1944
+ * @example
1945
+ * ```js
1946
+ * const parsed = t.url.parse("https://example.com/path?q=titan&page=1");
1947
+ * // → { protocol: "https:", host: "example.com", pathname: "/path", ... }
1948
+ *
1949
+ * const url = t.url.format({
1950
+ * protocol: "https:",
1951
+ * host: "api.example.com",
1952
+ * pathname: "/v2/users"
1953
+ * });
1954
+ * // → "https://api.example.com/v2/users"
1955
+ * ```
1956
+ *
1957
+ * @see https://titan-docs-ez.vercel.app/docs/04-runtime-apis — Runtime APIs (t.url)
1958
+ */
1959
+ interface URLModule {
1960
+ /**
1961
+ * Parse a URL string into its component parts.
1962
+ *
1963
+ * @param url - The URL string to parse.
1964
+ * @returns An object with URL components (protocol, host, pathname, search, hash, etc.).
1965
+ */
1966
+ parse(url: string): any;
1967
+
1968
+ /**
1969
+ * Format a URL object back into a URL string.
1970
+ *
1971
+ * @param urlObj - An object with URL components.
1972
+ * @returns The formatted URL string.
1973
+ */
1974
+ format(urlObj: any): string;
1975
+
1976
+ /**
1977
+ * URL search parameters utility (similar to the Web API `URLSearchParams`).
1978
+ */
1979
+ SearchParams: any;
1980
+ }
1981
+
1982
+ }
1983
+
1984
+ /**
1985
+ * Node-compatible `process` global (Titan Shim).
1986
+ *
1987
+ * This is a lightweight compatibility layer intended
1988
+ * for supporting common Node libraries.
1989
+ *
1990
+ * Internally backed by:
1991
+ * - t.proc
1992
+ * - t.os
1993
+ * - t.time
1994
+ */
1995
+ const process: {
1996
+ /** Process ID */
1997
+ pid: number;
1998
+
1999
+ /** Platform (linux, win32, darwin) */
2000
+ platform: string;
2001
+
2002
+ /** CPU architecture */
2003
+ arch: string;
2004
+
2005
+ /** Node version string (shimmed) */
2006
+ version: string;
2007
+
2008
+ /** Version object */
2009
+ versions: {
2010
+ node: string;
2011
+ titan: string;
2012
+ };
2013
+
2014
+ /** Environment variables */
2015
+ env: Record<string, string | undefined>;
2016
+
2017
+ /** CLI arguments */
2018
+ argv: string[];
2019
+
2020
+ /** Current working directory */
2021
+ cwd(): string;
2022
+
2023
+ /** Uptime in seconds */
2024
+ uptime(): number;
2025
+
2026
+ /** High resolution time */
2027
+ hrtime: {
2028
+ (time?: [number, number]): [number, number];
2029
+ bigint(): bigint;
2030
+ };
2031
+
2032
+ /** Memory usage info */
2033
+ memoryUsage(): Record<string, any>;
2034
+
2035
+ /** No-op event listener (compat only) */
2036
+ on(event: string, listener: (...args: any[]) => void): void;
2037
+
2038
+ /** Exit stub (throws in Titan runtime) */
2039
+ exit(code?: number): never;
2040
+ };
2041
+ }
2042
+
2043
+ export { };