@ezetgalaxy/titan 26.12.8 → 26.13.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/README.md CHANGED
@@ -223,192 +223,5 @@ Titan compiles your entire app—JS/TS code, Rust code, and server logic—into
223
223
 
224
224
  ---
225
225
 
226
- # 🧱 Architecture: Multi-Threaded, Strictly Synchronous V8 Runtime
227
226
 
228
- TitanPl is **not** a Node.js framework, TitanPl have Gravity Runtime. It is a **Rust server with embedded V8 engines** that executes JavaScript/TypeScript **synchronously**.
229
-
230
- ### Key Architectural Principles:
231
-
232
- * **No Event Loop in Workers**: Unlike Node.js, Titan workers do **not** run an event loop. Code executes synchronously from request entry to response exit.
233
- * **Request-Driven Execution**: Each worker processes one request at a time, blocks until completion, then awaits the next request.
234
- * **Blocking I/O**: All I/O operations (HTTP, DB, file system) block the worker thread. Scaling is achieved by increasing worker threads, not through async I/O.
235
- * **Deterministic Execution**: All code runs linearly, making debugging predictable and straightforward.
236
- * **True Isolation**: Each worker owns an independent V8 isolate with zero shared state or cross-worker communication.
237
- * **No `require` or `import.meta`**: Use ES6 imports only. Dependencies are bundled with esbuild.
238
- * **No Async/Await**: JavaScript actions cannot use Promises, `async/await`, `setTimeout`, or any other asynchronous primitives.
239
-
240
- ### Synchronous Execution Model:
241
-
242
- ```
243
- ┌─────────────────────────────────────────────────────────────────┐
244
- │ Incoming HTTP Request │
245
- └─────────────────────┬───────────────────────────────────────────┘
246
-
247
-
248
- ┌────────────────────────┐
249
- │ Axum HTTP Server │
250
- │ (Rust, async) │
251
- └────────┬───────────────┘
252
-
253
- │ Dispatch to Worker
254
-
255
- ┌──────────────────────────────────┐
256
- │ Worker Thread (Rust) │
257
- │ ┌────────────────────────────┐ │
258
- │ │ V8 Isolate │ │
259
- │ │ ┌──────────────────────┐ │ │
260
- │ │ │ Execute Action │ │ │ ◄── Synchronous, blocking execution
261
- │ │ │ (JavaScript/TS) │ │ │
262
- │ │ │ │ │ │
263
- │ │ │ t.fetch() ──────────┼──┼──┼──► Blocks until HTTP response
264
- │ │ │ │ │ │ │
265
- │ │ │ ▼ │ │ │
266
- │ │ │ return { ... } │ │ │
267
- │ │ └──────────────────────┘ │ │
268
- │ └────────────────────────────┘ │
269
- └──────────┬───────────────────────┘
270
-
271
- │ Return response
272
-
273
- ┌─────────────────────────┐
274
- │ HTTP Response Sent │
275
- └─────────────────────────┘
276
- ```
277
-
278
- ### Performance Characteristics:
279
-
280
- * **Cold Start**: ~3-5ms (embedded runtime eliminates disk I/O)
281
- * **Action Execute**: ~100-500µs
282
- * **Memory/Worker**: ~40-80MB (configurable via V8 flags)
283
- * **Throughput**: ~10k - 19k req/sec @ 200 concurrent connections
284
- * **Latency**: ~14-17ms (p50), ~30ms (p97.5)
285
-
286
- ### When to Use TitanPL:
287
-
288
- ✅ **Perfect for:**
289
- * CPU-bound or compute-heavy services
290
- * Deterministic execution requirements
291
- * Linear debugging workflows
292
- * Predictable memory usage per worker
293
- * Crash isolation (one worker crash doesn't affect others)
294
-
295
- ❌ **Not ideal for:**
296
- * I/O-heavy services with high concurrency (use Node.js, Deno, or Bun)
297
- * Applications requiring `setTimeout`, Promises, or async/await
298
- * Real-time event-driven architectures
299
-
300
- ### Migration from Async Patterns:
301
-
302
- If you're coming from Node.js, **do not** try to use async patterns:
303
-
304
- ```javascript
305
- // ❌ This will NOT work
306
- export const fetchUser = defineAction(async (req) => {
307
- const response = await t.fetch("https://api.example.com/user");
308
- return response;
309
- });
310
-
311
- // ✅ Use synchronous blocking calls instead
312
- export const fetchUser = defineAction((req) => {
313
- const response = t.fetch("https://api.example.com/user"); // Blocks until complete
314
- return response;
315
- });
316
- ```
317
-
318
- ---
319
-
320
- # 🚀 TitanPL Gravity Multi-Threaded Architecture
321
-
322
- ### What this means:
323
-
324
- * **Each CPU core runs JavaScript independently**
325
- * **Every request is handled in parallel**
326
- * **Zero lock contention**
327
- * **Linear scaling with core count**
328
- * **Massive throughput increase under real traffic**
329
-
330
- No tricks. No fake concurrency.
331
- Just **native multi-threaded JavaScript execution**, powered by Rust.
332
-
333
- ---
334
-
335
- # 🧠 How It Works
336
-
337
- TitanPL spins up a **worker pool**, where each worker owns:
338
-
339
- * Its own V8 isolate
340
- * Its own context
341
- * Its own compiled actions
342
- * **No event loop** (synchronous execution only)
343
-
344
- Workers never share a lock, never block each other, and never wait for global state.
345
-
346
- This gives TitanPL a performance profile similar to:
347
-
348
- * Deno’s multi-isolate approach
349
- * Chrome’s process-per-tab architecture
350
- * High-performance Rust servers like Actix or Hyper
351
-
352
- But executed **directly for JavaScript with synchronous semantics**.
353
-
354
- ---
355
-
356
- # ⚡ Real Performance Gains
357
-
358
- TitanPL demonstrates:
359
-
360
- * **10× lower contention** compared with previous versions
361
- * **2× higher throughput** on multi-core systems
362
- * **Stable latency at 500–800 concurrent clients**
363
- * **True hardware utilization**, not single-threaded bottlenecks
364
-
365
- Example on an 8-core machine:
366
-
367
- ```
368
- Before: 5k–6k req/sec
369
- Now: 10k–12k+ req/sec
370
- ```
371
-
372
- ---
373
-
374
- # 🛠 Why Multi-Threading Matters
375
-
376
- Traditional JavaScript runtimes:
377
-
378
- * Run user code on **one thread**
379
- * Rely heavily on **async I/O** to “fake” concurrency
380
- * Collapse under CPU-heavy workloads
381
-
382
- TitanPL eliminates this limitation:
383
-
384
- ### Every worker can execute CPU-bound JavaScript simultaneously — **zero blocking**.
385
-
386
- This is ideal for:
387
-
388
- * AI systems
389
- * Gaming backends
390
- * Real-time analytics
391
- * Compute-heavy actions
392
- * Multi-user concurrency
393
-
394
- ---
395
-
396
- # 🌌 TitanPL: The Future of JavaScript Backend Engines
397
-
398
- With native Rust + V8 multi-threading, TitanPL becomes:
399
-
400
- * Faster than single-threaded Node
401
- * More scalable under load
402
- * Safer and more predictable
403
- * Architecturally modern
404
- * Ready for enterprise-grade traffic
405
-
406
- ---
407
-
408
-
409
-
410
- **Titan v26 — Stable**
411
- * Production-ready Hybrid Runtime
412
- * Strict TypeScript Support
413
- * Native Rust Performance
414
- * Zero-Config Cloud Deployment
227
+ **To know more read docs 💟 **Titan Planet docs:** https://titan-docs-ez.vercel.app/docs**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezetgalaxy/titan",
3
- "version": "26.12.8",
3
+ "version": "26.13.0",
4
4
  "description": "Titan Planet is a JavaScript-first backend framework that embeds JS actions into a Rust + Axum server and ships as a single native binary. Routes are compiled to static metadata; only actions run in the embedded JS runtime. No Node.js. No event loop in production.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -61,6 +61,6 @@ COPY --from=builder /app/server/actions /app/actions
61
61
  # Copy only Titan extensions
62
62
  COPY --from=builder /app/.ext ./.ext
63
63
 
64
- EXPOSE 3000
64
+ EXPOSE 5100
65
65
 
66
66
  CMD ["./titan-server"]
@@ -13,23 +13,40 @@ export interface TitanBuilder {
13
13
  start(port?: number, msg?: string): Promise<void>;
14
14
  }
15
15
 
16
- // The default export from titan.js is the Builder
17
16
  declare const builder: TitanBuilder;
18
17
  export const Titan: TitanBuilder;
19
18
  export default builder;
20
19
 
21
- /**
22
- * Define a Titan Action with type inference.
23
- */
24
20
  export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
25
21
 
26
-
27
22
  // -- Global Definitions (Runtime Environment) --
28
23
 
24
+ /**
25
+ * # Drift - Orchestration Engine
26
+ *
27
+ * Revolutionary system for high-performance asynchronous operations using a **Deterministic Replay-based Suspension** model.
28
+ *
29
+ * ## Mechanism
30
+ * Drift utilizes a suspension model similar to **Algebraic Effects**. When a `drift()` operation is encountered,
31
+ * the runtime suspends the isolate, offloads the task to the background Tokio executor, and frees the isolate
32
+ * to handle other requests. Upon completion, the code is efficiently **re-played** with the result injected.
33
+ *
34
+ * @param promise - The promise or expression to drift.
35
+ * @returns The resolved value of the input promise.
36
+ *
37
+ * @example
38
+ * ```javascript
39
+ * const resp = drift t.fetch("http://api.titan.com");
40
+ * ```
41
+ */
42
+ declare var drift: <T>(promise: Promise<T> | T) => T;
43
+
29
44
  declare global {
30
45
  /**
31
- * The Titan Request Object passed to actions.
46
+ * Titan Global Drift
32
47
  */
48
+ var drift: <T>(promise: Promise<T> | T) => T;
49
+
33
50
  interface TitanRequest {
34
51
  body: any;
35
52
  method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
@@ -46,41 +63,16 @@ declare global {
46
63
  }
47
64
 
48
65
  interface DbConnection {
49
- /**
50
- * Execute a SQL query.
51
- * @param sql The SQL query string.
52
- * @param params (Optional) Parameters for the query ($1, $2, etc).
53
- */
54
66
  query(sql: string, params?: any[]): any[];
55
67
  }
56
68
 
57
- /**
58
- * Global defineAction (available without import in runtime)
59
- */
60
69
  function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
61
70
 
62
- /**
63
- * Global Request Object
64
- * Available automatically in actions.
65
- */
66
71
  var req: TitanRequest;
67
72
 
68
- /**
69
- * Titan Runtime Utilities
70
- * (Available globally in the runtime, e.g. inside actions)
71
- */
72
73
  interface TitanRuntimeUtils {
73
- /**
74
- * Log messages to the server console with Titan formatting.
75
- */
76
74
  log(...args: any[]): void;
77
-
78
- /**
79
- * Read a file contents as string.
80
- * @param path Relative path to the file from project root.
81
- */
82
75
  read(path: string): string;
83
-
84
76
  fetch(url: string, options?: {
85
77
  method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
86
78
  headers?: Record<string, string>;
@@ -93,11 +85,7 @@ declare global {
93
85
  };
94
86
 
95
87
  jwt: {
96
- sign(
97
- payload: object,
98
- secret: string,
99
- options?: { expiresIn?: string | number }
100
- ): string;
88
+ sign(payload: object, secret: string, options?: { expiresIn?: string | number }): string;
101
89
  verify(token: string, secret: string): any;
102
90
  };
103
91
 
@@ -106,27 +94,156 @@ declare global {
106
94
  verify(password: string, hash: string): boolean;
107
95
  };
108
96
 
97
+ /** ### `db` (Database Connection) */
109
98
  db: {
110
99
  connect(url: string): DbConnection;
111
100
  };
112
101
 
113
- /**
114
- * Titan Validator (Zod-compatible)
115
- */
116
- valid: any;
102
+ /** ### `fs` (File System) */
103
+ fs: TitanCore.FileSystem;
104
+
105
+ /** ### `path` (Path Manipulation) */
106
+ path: TitanCore.Path;
107
+
108
+ /** ### `crypto` (Cryptography) */
109
+ crypto: TitanCore.Crypto;
117
110
 
118
- // Allow extensions
111
+ /** ### `buffer` (Buffer Utilities) */
112
+ buffer: TitanCore.BufferModule;
113
+
114
+ /** ### `ls` / `localStorage` (Persistent Storage) */
115
+ ls: TitanCore.LocalStorage;
116
+ localStorage: TitanCore.LocalStorage;
117
+
118
+ /** ### `session` (Server-side Sessions) */
119
+ session: TitanCore.Session;
120
+
121
+ /** ### `cookies` (HTTP Cookies) */
122
+ cookies: TitanCore.Cookies;
123
+
124
+ /** ### `os` (Operating System) */
125
+ os: TitanCore.OS;
126
+
127
+ /** ### `net` (Network) */
128
+ net: TitanCore.Net;
129
+
130
+ /** ### `proc` (Process) */
131
+ proc: TitanCore.Process;
132
+
133
+ /** ### `time` (Time) */
134
+ time: TitanCore.Time;
135
+
136
+ /** ### `url` (URL) */
137
+ url: TitanCore.URLModule;
138
+
139
+ /** ### `response` (HTTP Response Builder) */
140
+ response: TitanCore.ResponseModule;
141
+
142
+ valid: any;
119
143
  [key: string]: any;
120
144
  }
121
145
 
122
- /**
123
- * Titan Runtime Utilities
124
- * (Available globally in the runtime, e.g. inside actions)
125
- */
126
146
  const t: TitanRuntimeUtils;
127
-
128
- /**
129
- * Titan Runtime Utilities (Alias for t)
130
- */
131
147
  const Titan: TitanRuntimeUtils;
148
+
149
+ namespace TitanCore {
150
+ interface FileSystem {
151
+ readFile(path: string): string;
152
+ writeFile(path: string, content: string): void;
153
+ readdir(path: string): string[];
154
+ mkdir(path: string): void;
155
+ exists(path: string): boolean;
156
+ stat(path: string): { size: number, isFile: boolean, isDir: boolean, modified: number };
157
+ remove(path: string): void;
158
+ }
159
+
160
+ interface Path {
161
+ join(...args: string[]): string;
162
+ resolve(...args: string[]): string;
163
+ extname(path: string): string;
164
+ dirname(path: string): string;
165
+ basename(path: string): string;
166
+ }
167
+
168
+ interface Crypto {
169
+ hash(algorithm: 'sha256' | 'sha512' | 'md5', data: string): string;
170
+ randomBytes(size: number): string;
171
+ uuid(): string;
172
+ compare(hash: string, target: string): boolean;
173
+ encrypt(algorithm: string, key: string, plaintext: string): string;
174
+ decrypt(algorithm: string, key: string, ciphertext: string): string;
175
+ hashKeyed(algorithm: 'hmac-sha256' | 'hmac-sha512', key: string, message: string): string;
176
+ }
177
+
178
+ interface BufferModule {
179
+ fromBase64(str: string): Uint8Array;
180
+ toBase64(bytes: Uint8Array | string): string;
181
+ fromHex(str: string): Uint8Array;
182
+ toHex(bytes: Uint8Array | string): string;
183
+ fromUtf8(str: string): Uint8Array;
184
+ toUtf8(bytes: Uint8Array): string;
185
+ }
186
+
187
+ interface LocalStorage {
188
+ get(key: string): string | null;
189
+ set(key: string, value: string): void;
190
+ remove(key: string): void;
191
+ clear(): void;
192
+ keys(): string[];
193
+ }
194
+
195
+ interface Session {
196
+ get(sessionId: string, key: string): string | null;
197
+ set(sessionId: string, key: string, value: string): void;
198
+ delete(sessionId: string, key: string): void;
199
+ clear(sessionId: string): void;
200
+ }
201
+
202
+ interface Cookies {
203
+ get(req: any, name: string): string | null;
204
+ set(res: any, name: string, value: string, options?: any): void;
205
+ delete(res: any, name: string): void;
206
+ }
207
+
208
+ interface OS {
209
+ platform(): string;
210
+ cpus(): number;
211
+ totalMemory(): number;
212
+ freeMemory(): number;
213
+ tmpdir(): string;
214
+ }
215
+
216
+ interface Net {
217
+ resolveDNS(hostname: string): string[];
218
+ ip(): string;
219
+ ping(host: string): boolean;
220
+ }
221
+
222
+ interface Process {
223
+ pid(): number;
224
+ uptime(): number;
225
+ memory(): Record<string, any>;
226
+ }
227
+
228
+ interface Time {
229
+ sleep(ms: number): void;
230
+ now(): number;
231
+ timestamp(): string;
232
+ }
233
+
234
+ interface URLModule {
235
+ parse(url: string): any;
236
+ format(urlObj: any): string;
237
+ SearchParams: any;
238
+ }
239
+
240
+ interface ResponseModule {
241
+ (options: any): any;
242
+ text(content: string, status?: number): any;
243
+ html(content: string, status?: number): any;
244
+ json(content: any, status?: number): any;
245
+ redirect(url: string, status?: number): any;
246
+ empty(status?: number): any;
247
+ }
248
+ }
132
249
  }
@@ -7,4 +7,4 @@ t.post("/hello").action("hello") // pass a json payload { "name": "titan" }
7
7
 
8
8
  t.get("/").reply("Ready to land on Titan Planet 🚀");
9
9
 
10
- t.start(3000, "Titan Running!");
10
+ t.start(5100, "Titan Running!");
@@ -8,6 +8,7 @@ use serde_json::Value;
8
8
  #[derive(Debug, Deserialize, Clone)]
9
9
  pub struct RouteVal {
10
10
  pub r#type: String,
11
+ #[serde(alias = "target")]
11
12
  pub value: Value,
12
13
  }
13
14