titanpl 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/package.json +1 -1
  2. package/packages/cli/package.json +4 -4
  3. package/packages/cli/src/commands/build-ext.js +17 -4
  4. package/packages/engine-darwin-arm64/package.json +1 -1
  5. package/packages/engine-linux-x64/package.json +1 -1
  6. package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
  7. package/packages/engine-win32-x64/package.json +1 -1
  8. package/packages/native/index.d.ts +27 -0
  9. package/packages/native/index.js +1 -0
  10. package/packages/native/package.json +1 -1
  11. package/packages/native/t.native.d.ts +99 -3
  12. package/packages/packet/package.json +1 -1
  13. package/packages/route/package.json +1 -1
  14. package/packages/sdk/package.json +1 -1
  15. package/templates/extension/README_WASM.md +38 -0
  16. package/templates/extension/package.json +2 -2
  17. package/templates/js/package.json +7 -7
  18. package/templates/rust-js/package.json +4 -4
  19. package/templates/rust-ts/package.json +4 -4
  20. package/templates/ts/package.json +7 -7
  21. package/packages/core-source/LICENSE +0 -15
  22. package/packages/core-source/README.md +0 -128
  23. package/packages/core-source/V8_SERIALIZATION.md +0 -125
  24. package/packages/core-source/configure.js +0 -50
  25. package/packages/core-source/globals.d.ts +0 -2238
  26. package/packages/core-source/index.d.ts +0 -515
  27. package/packages/core-source/index.js +0 -639
  28. package/packages/core-source/jsconfig.json +0 -12
  29. package/packages/core-source/mkctx.config.json +0 -7
  30. package/packages/core-source/native/Cargo.lock +0 -1559
  31. package/packages/core-source/native/Cargo.toml +0 -30
  32. package/packages/core-source/native/src/crypto_impl.rs +0 -139
  33. package/packages/core-source/native/src/lib.rs +0 -702
  34. package/packages/core-source/native/src/storage_impl.rs +0 -73
  35. package/packages/core-source/native/src/v8_impl.rs +0 -93
  36. package/packages/core-source/package-lock.json +0 -1464
  37. package/packages/core-source/package.json +0 -53
  38. package/packages/core-source/tests/buffer.test.js +0 -78
  39. package/packages/core-source/tests/cookies.test.js +0 -117
  40. package/packages/core-source/tests/crypto.test.js +0 -142
  41. package/packages/core-source/tests/fs.test.js +0 -176
  42. package/packages/core-source/tests/ls.test.js +0 -149
  43. package/packages/core-source/tests/net.test.js +0 -84
  44. package/packages/core-source/tests/os.test.js +0 -81
  45. package/packages/core-source/tests/path.test.js +0 -102
  46. package/packages/core-source/tests/response.test.js +0 -146
  47. package/packages/core-source/tests/session.test.js +0 -110
  48. package/packages/core-source/tests/setup.js +0 -325
  49. package/packages/core-source/tests/time.test.js +0 -57
  50. package/packages/core-source/tests/url.test.js +0 -82
  51. package/packages/core-source/titan-ext.d.ts +0 -2
  52. package/packages/core-source/titan.json +0 -9
  53. package/packages/core-source/vitest.config.js +0 -8
  54. package/templates/extension/README.md +0 -69
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "titanpl",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/cli",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "The unified CLI for Titan Planet. Use it to create, manage, build, and deploy high-performance backend projects.",
5
5
  "keywords": [
6
6
  "titanpl",
@@ -29,11 +29,11 @@
29
29
  "tit": "./index.js"
30
30
  },
31
31
  "optionalDependencies": {
32
- "@titanpl/engine-win32-x64": "7.0.0",
33
- "@titanpl/engine-linux-x64": "7.0.0"
32
+ "@titanpl/engine-win32-x64": "7.0.1",
33
+ "@titanpl/engine-linux-x64": "7.0.1"
34
34
  },
35
35
  "dependencies": {
36
- "@titanpl/packet": "7.0.0",
36
+ "@titanpl/packet": "7.0.1",
37
37
  "prompts": "^2.4.2",
38
38
  "commander": "^11.0.0",
39
39
  "chalk": "^4.1.2"
@@ -38,10 +38,23 @@ async function buildWasmExtension(titanJson) {
38
38
  try {
39
39
  // We assume wasm-pack or similar is used, or just bare cargo with wasm32 target
40
40
  // The spec mentions: native/pkg/my_ext.wasm, which is wasm-pack's default
41
- execSync('wasm-pack build --target web', { cwd: nativeDir, stdio: 'inherit' });
41
+ console.log(chalk.gray(" Running wasm-pack..."));
42
+ execSync('wasm-pack build --target web --no-typescript', { cwd: nativeDir, stdio: 'ignore' });
42
43
  } catch (err) {
43
- console.log(chalk.red(" Wasm compilation failed. Make sure 'wasm-pack' is installed."));
44
- return;
44
+ console.log(chalk.yellow("! wasm-pack failed, attempting raw cargo build..."));
45
+ try {
46
+ execSync('cargo build --target wasm32-unknown-unknown --release', { cwd: nativeDir, stdio: 'ignore' });
47
+ const pkgDir = path.join(nativeDir, 'pkg');
48
+ if (!fs.existsSync(pkgDir)) fs.mkdirSync(pkgDir);
49
+
50
+ const targetWasm = path.join(nativeDir, `target/wasm32-unknown-unknown/release/${crateName}.wasm`);
51
+ const destWasm = path.join(pkgDir, `${crateName}_bg.wasm`);
52
+ fs.copyFileSync(targetWasm, destWasm);
53
+ console.log(chalk.green("✔ Raw Wasm compilation successful."));
54
+ } catch (cargoErr) {
55
+ console.log(chalk.red("✖ Wasm compilation failed. Make sure Rust and wasm32-unknown-unknown target are installed."));
56
+ return;
57
+ }
45
58
  }
46
59
 
47
60
  console.log(chalk.gray(" Generating bindings..."));
@@ -95,7 +108,7 @@ async function buildNativeExtension(titanJson) {
95
108
 
96
109
  console.log(chalk.gray(" Compiling Rust native library..."));
97
110
  try {
98
- execSync('cargo build --release', { cwd: nativeDir, stdio: 'inherit' });
111
+ execSync('cargo build --release', { cwd: nativeDir, stdio: 'ignore' });
99
112
  } catch (err) {
100
113
  console.log(chalk.red("✖ Native compilation failed."));
101
114
  return;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-darwin-arm64",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "os": [
5
5
  "darwin"
6
6
  ],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-linux-x64",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "os": [
5
5
  "linux"
6
6
  ],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-win32-x64",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "os": [
5
5
  "win32"
6
6
  ],
@@ -37,6 +37,21 @@ export interface WebSocketModule {
37
37
  }
38
38
 
39
39
  export const db: any;
40
+ /**
41
+ * WebSocket communication utilities.
42
+ *
43
+ * @example
44
+ * ```js
45
+ * import { ws } from "@titanpl/native";
46
+ *
47
+ * export default function chat(req) {
48
+ * if (req.event === "open") {
49
+ * ws.send(req.socketId, "Welcome!");
50
+ * ws.broadcast("Someone joined.");
51
+ * }
52
+ * }
53
+ * ```
54
+ */
40
55
  export const ws: WebSocketModule;
41
56
  export const path: any;
42
57
  export const jwt: any;
@@ -52,6 +67,18 @@ export const net: any;
52
67
  export const proc: any;
53
68
  export const time: any;
54
69
  export const url: any;
70
+ /**
71
+ * HTTP Response builder utilities.
72
+ *
73
+ * @example
74
+ * ```js
75
+ * import { response } from "@titanpl/native";
76
+ *
77
+ * export function get(req) {
78
+ * return response.json({ hello: "world" });
79
+ * }
80
+ * ```
81
+ */
55
82
  export const response: any;
56
83
  export const valid: any;
57
84
 
@@ -39,6 +39,7 @@ export const time = t.time;
39
39
  export const url = t.url;
40
40
  export const response = t.response;
41
41
  export const valid = t.valid;
42
+ export const drift = globalThis.drift;
42
43
 
43
44
  // Serialization
44
45
  export const serialize = t.serialize;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/native",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Titan native utilities package",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -236,6 +236,18 @@ export const db: typeof t.db;
236
236
  /**
237
237
  * WebSocket communication utilities.
238
238
  *
239
+ * @example
240
+ * ```js
241
+ * import { ws } from "@titanpl/native";
242
+ *
243
+ * export default function chat(req) {
244
+ * if (req.event === "open") {
245
+ * ws.send(req.socketId, "Welcome!");
246
+ * ws.broadcast("Someone joined.");
247
+ * }
248
+ * }
249
+ * ```
250
+ *
239
251
  * Re-exported from the `t` global for module-style imports.
240
252
  * @see {@link TitanRuntimeUtils.ws} for full documentation.
241
253
  */
@@ -373,6 +385,23 @@ export const time: typeof t.time;
373
385
  */
374
386
  export const url: typeof t.url;
375
387
 
388
+ /**
389
+ * HTTP Response builder utilities.
390
+ *
391
+ * @example
392
+ * ```js
393
+ * import { response } from "@titanpl/native";
394
+ *
395
+ * export function get(req) {
396
+ * return response.json({ hello: "world" });
397
+ * }
398
+ * ```
399
+ *
400
+ * Re-exported from the `t` global for module-style imports.
401
+ * @see {@link TitanRuntimeUtils.response} for full documentation.
402
+ */
403
+ export const response: typeof t.response;
404
+
376
405
  /**
377
406
  * Runtime validation utilities.
378
407
  *
@@ -732,10 +761,12 @@ declare global {
732
761
  *
733
762
  * @example
734
763
  * ```js
764
+ * import { ws } from "@titanpl/native";
765
+ *
735
766
  * export default function chat(req) {
736
767
  * if (req.event === "open") {
737
- * t.ws.send(req.socketId, "Welcome!");
738
- * t.ws.broadcast("Someone joined.");
768
+ * ws.send(req.socketId, "Welcome!");
769
+ * ws.broadcast("Someone joined.");
739
770
  * }
740
771
  * }
741
772
  * ```
@@ -1178,6 +1209,26 @@ declare global {
1178
1209
  url: TitanCore.URLModule;
1179
1210
 
1180
1211
  /**
1212
+ * HTTP Response builder utilities.
1213
+ *
1214
+ * Provides helpers for crafting standardized HTTP responses, such as JSON,
1215
+ * HTML, redirects, or raw text.
1216
+ *
1217
+ * @example
1218
+ * ```js
1219
+ * import { response } from "@titanpl/native";
1220
+ *
1221
+ * export function get(req) {
1222
+ * if (!req.headers.authorization) {
1223
+ * return response.json({ error: "Unauthorized" }, 401);
1224
+ * }
1225
+ * return response.html("<h1>Welcome</h1>");
1226
+ * }
1227
+ * ```
1228
+ *
1229
+ * @see https://titanpl.vercel.app/docs/how-to-use/05-runtime-apis — Runtime APIs (t.response)
1230
+ */
1231
+ response: TitanCore.ResponseModule;
1181
1232
 
1182
1233
  /**
1183
1234
  * Runtime validation utilities.
@@ -1249,6 +1300,51 @@ declare global {
1249
1300
  interface TitanResponse {
1250
1301
  readonly __titan_response: true;
1251
1302
  }
1303
+
1304
+ /**
1305
+ * Response builder interfaces.
1306
+ */
1307
+ interface ResponseModule {
1308
+ /**
1309
+ * Return a JSON response with an optional status code and headers.
1310
+ *
1311
+ * @param data - The object or value to serialize to JSON.
1312
+ * @param status - The HTTP status code (default: 200).
1313
+ * @param headers - Optional custom headers.
1314
+ * @returns A standard Titan response.
1315
+ */
1316
+ json(data: any, status?: number, headers?: Record<string, string>): TitanResponse;
1317
+
1318
+ /**
1319
+ * Return an HTML response with an optional status code and headers.
1320
+ *
1321
+ * @param html - The HTML string to return.
1322
+ * @param status - The HTTP status code (default: 200).
1323
+ * @param headers - Optional custom headers.
1324
+ * @returns A standard Titan response.
1325
+ */
1326
+ html(html: string, status?: number, headers?: Record<string, string>): TitanResponse;
1327
+
1328
+ /**
1329
+ * Return a plain text response with an optional status code and headers.
1330
+ *
1331
+ * @param text - The string to return.
1332
+ * @param status - The HTTP status code (default: 200).
1333
+ * @param headers - Optional custom headers.
1334
+ * @returns A standard Titan response.
1335
+ */
1336
+ text(text: string, status?: number, headers?: Record<string, string>): TitanResponse;
1337
+
1338
+ /**
1339
+ * Issue an HTTP redirect to a specific URL.
1340
+ *
1341
+ * @param url - The destination URL.
1342
+ * @param status - The redirect status code (default: 302).
1343
+ * @param headers - Optional custom headers.
1344
+ * @returns A standard Titan response.
1345
+ */
1346
+ redirect(url: string, status?: number, headers?: Record<string, string>): TitanResponse;
1347
+ }
1252
1348
  /**
1253
1349
  * Asynchronous file system operations.
1254
1350
  *
@@ -2200,7 +2296,7 @@ declare global {
2200
2296
  * - t.os
2201
2297
  * - t.time
2202
2298
  */
2203
- const process: {
2299
+ var process: {
2204
2300
  /** Process ID */
2205
2301
  pid: number;
2206
2302
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/packet",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "The bundler for TitanPl servers.",
5
5
  "keywords": [
6
6
  "bundler",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/route",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Titan routing DSL",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/sdk",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "The official SDK for Titan Planet extensions and testing.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,38 @@
1
+ # TitanPL Native & WebAssembly Extensions
2
+
3
+ One of the definitive features of TitanPL v7+ is its dynamic, zero-configuration native extension bridge. You no longer have to manually define function signatures or types within `titan.json`.
4
+
5
+ ## The Hybrid IPC Native Bridge
6
+
7
+ The `NativeHost` bridge natively detects argument types over IPC at runtime. Whether you pass floating-point numbers (`f64`), complex strings, or JSON-stringified objects:
8
+
9
+ 1. **Dynamic C-ABI Interop:** The host inspects the payload dynamically and generates the correct C-struct register combinations on-the-fly (`f64`, `*const c_char`, combinations).
10
+ 2. **Safe Void execution:** Memory protections natively peek at returned pointer segments, preventing SEGFAULT crashes. `void` returns are safely handled transparently.
11
+
12
+ ### Writing WebAssembly (WASM)
13
+
14
+ Because Titan CLI utilizes `wasm-pack` without unnecessary logs, compiling WebAssembly plugins from Rust is completely silent and incredibly robust.
15
+
16
+ To build a fresh, silent WASM extension:
17
+ ```bash
18
+ titan build ext
19
+ ```
20
+ The CLI suppresses stdout output (`stdio: 'ignore'`) allowing clean build processes unless a fatal compiler failure occurs.
21
+
22
+ ### Best Practices: The `@titanpl/native` Namespace
23
+
24
+ Never use the globally injected `t.*` prefixes in Modern TitanPL scripts (unless deploying backward-compatible code). Instead, simply use the modular native imports:
25
+
26
+ ```js
27
+ // BEFORE (Not Recommended)
28
+ const data = t.fs.readFile("example.txt");
29
+ const hash = t.crypto.hash("sha256", "test");
30
+
31
+ // AFTER (Recommended)
32
+ import { fs, crypto, drift } from "@titanpl/native";
33
+
34
+ const data = fs.readFile("example.txt");
35
+ const hash = crypto.hash("sha256", "test");
36
+ ```
37
+
38
+ By transitioning to `@titanpl/native`, you gain absolute Type Completion (via the newly restructured `d.ts` declaration maps) explicitly tailored to ESM semantics.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-extension",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "A high-performance TitanPL extension.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -11,6 +11,6 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "@titanpl/sdk": "7.0.0"
14
+ "@titanpl/sdk": "7.0.1"
15
15
  }
16
16
  }
@@ -6,16 +6,16 @@
6
6
  "template": "js"
7
7
  },
8
8
  "dependencies": {
9
- "@titanpl/cli": "7.0.0",
10
- "@titanpl/route": "7.0.0",
11
- "@titanpl/native": "7.0.0",
9
+ "@titanpl/cli": "7.0.1",
10
+ "@titanpl/route": "7.0.1",
11
+ "@titanpl/native": "7.0.1",
12
12
  "@titanpl/core": "7.0.0",
13
13
  "@titanpl/node": "latest",
14
- "@titanpl/packet": "7.0.0"
14
+ "@titanpl/packet": "7.0.1"
15
15
  },
16
16
  "optionalDependencies": {
17
- "@titanpl/engine-linux-x64": "7.0.0",
18
- "@titanpl/engine-win32-x64": "7.0.0"
17
+ "@titanpl/engine-linux-x64": "7.0.1",
18
+ "@titanpl/engine-win32-x64": "7.0.1"
19
19
  },
20
20
  "scripts": {
21
21
  "build": "titan build",
@@ -28,5 +28,5 @@
28
28
  "eslint": "^9.39.2",
29
29
  "eslint-plugin-titanpl": "latest"
30
30
  },
31
- "version": "7.0.0"
31
+ "version": "7.0.1"
32
32
  }
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "titanpl",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "A Titan Planet server",
5
5
  "type": "module",
6
6
  "titan": {
7
7
  "template": "rust-js"
8
8
  },
9
9
  "dependencies": {
10
- "@titanpl/cli": "7.0.0",
11
- "@titanpl/route": "7.0.0",
12
- "@titanpl/native": "7.0.0",
10
+ "@titanpl/cli": "7.0.1",
11
+ "@titanpl/route": "7.0.1",
12
+ "@titanpl/native": "7.0.1",
13
13
  "@titanpl/core": "7.0.0",
14
14
  "@titanpl/node": "latest"
15
15
  },
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "titanpl",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "A Titan Planet server (Rust + TypeScript)",
5
5
  "type": "module",
6
6
  "titan": {
7
7
  "template": "rust-ts"
8
8
  },
9
9
  "dependencies": {
10
- "@titanpl/cli": "7.0.0",
11
- "@titanpl/route": "7.0.0",
12
- "@titanpl/native": "7.0.0",
10
+ "@titanpl/cli": "7.0.1",
11
+ "@titanpl/route": "7.0.1",
12
+ "@titanpl/native": "7.0.1",
13
13
  "@titanpl/core": "7.0.0",
14
14
  "@titanpl/node": "latest",
15
15
  "typescript": "^5.0.0"
@@ -6,18 +6,18 @@
6
6
  "template": "ts"
7
7
  },
8
8
  "dependencies": {
9
- "@titanpl/cli": "7.0.0",
10
- "@titanpl/route": "7.0.0",
11
- "@titanpl/native": "7.0.0",
9
+ "@titanpl/cli": "7.0.1",
10
+ "@titanpl/route": "7.0.1",
11
+ "@titanpl/native": "7.0.1",
12
12
  "@titanpl/core": "7.0.0",
13
13
  "@titanpl/node": "latest",
14
- "@titanpl/packet": "7.0.0",
14
+ "@titanpl/packet": "7.0.1",
15
15
  "typescript": "^5.0.0"
16
16
  },
17
17
  "optionalDependencies": {
18
18
  "@titanpl/engine-linux-arm64": "2.0.5",
19
- "@titanpl/engine-linux-x64": "7.0.0",
20
- "@titanpl/engine-win32-x64": "7.0.0"
19
+ "@titanpl/engine-linux-x64": "7.0.1",
20
+ "@titanpl/engine-win32-x64": "7.0.1"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "titan build",
@@ -31,5 +31,5 @@
31
31
  "eslint-plugin-titanpl": "latest",
32
32
  "@typescript-eslint/parser": "^8.54.0"
33
33
  },
34
- "version": "7.0.0"
34
+ "version": "7.0.1"
35
35
  }
@@ -1,15 +0,0 @@
1
- ISC License
2
-
3
- Copyright (c) 2025, Ezet Galaxy
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted, provided that the above
7
- copyright notice and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -1,128 +0,0 @@
1
- # @titanpl/core
2
-
3
- The official Core Standard Library for Titan Planet - a high-performance JavaScript runtime extension. This library bridges high-performance Rust native implementations with an easy-to-use JavaScript API.
4
-
5
- ## Overview
6
-
7
- `@titanpl/core` provides essential standard library modules for Titan applications, covering file system operations, cryptography, process management, networking, and more. All modules are implemented as native Rust extensions for maximum performance.
8
-
9
- ## Installation
10
-
11
- ```bash
12
- npm install @titanpl/core
13
- ```
14
-
15
- ## Usage
16
-
17
- The extension automatically attaches to the Titan runtime.
18
-
19
- ### Modern ESM Import (Highly Recommended)
20
- Best for IDE support, autocompletion, and type checking.
21
- ```javascript
22
- import { fs, crypto, ls } from "@titanpl/core";
23
-
24
- const content = fs.readFile("config.json");
25
- ```
26
-
27
- ---
28
-
29
- ## API Reference
30
-
31
- ### `fs` (File System)
32
- Synchronous file system operations.
33
- - `fs.readFile(path: string): string` - Read file content as UTF-8 string.
34
- - `fs.writeFile(path: string, content: string): void` - Write string content to file.
35
- - `fs.exists(path: string): boolean` - Check if a path exists.
36
- - `fs.mkdir(path: string): void` - Create a directory (recursive).
37
- - `fs.remove(path: string): void` - Remove file or directory.
38
- - `fs.readdir(path: string): string[]` - List directory contents.
39
- - `fs.stat(path: string): object` - Get file statistics `{ isFile: boolean, isDir: boolean, size: number, modified: number }`.
40
-
41
- ### `path` (Path Manipulation)
42
- Utilities for handling file paths.
43
- - `path.join(...parts: string[]): string` - Join path segments using platform-specific separators.
44
- - `path.resolve(...parts: string[]): string` - Resolve path to an absolute path.
45
- - `path.dirname(path: string): string` - Get the directory name of a path.
46
- - `path.basename(path: string): string` - Get the base name (filename) of a path.
47
- - `path.extname(path: string): string` - Get the extension of a path (including the dot).
48
-
49
- ### `crypto` (Cryptography)
50
- Secure cryptographic utilities.
51
- - `crypto.hash(algo: string, data: string): string` - Hash data (e.g., `sha256`, `sha512`).
52
- - `crypto.randomBytes(size: number): string` - Generate random bytes as a hex string.
53
- - `crypto.uuid(): string` - Generate a UUID v4.
54
- - `crypto.encrypt(algorithm: string, key: string, plaintext: string): string` - Encrypt text using native Rust implementations.
55
- - `crypto.decrypt(algorithm: string, key: string, ciphertext: string): string` - Decrypt text.
56
- - `crypto.hashKeyed(algo: string, key: string, message: string): string` - Keyed-hash (HMAC) support.
57
- - `crypto.compare(hash: string, target: string): boolean` - Securely compare two strings in constant time.
58
-
59
- ### `buffer` (Buffer Utilities)
60
- Utilities for binary and data encoding.
61
- - `buffer.fromBase64(str: string): Uint8Array` - Decode Base64 string to bytes.
62
- - `buffer.toBase64(bytes: Uint8Array|string): string` - Encode bytes or string to Base64.
63
-
64
- ### `os` (Operating System)
65
- Retrieve system-level information.
66
- - `os.platform(): string` - OS platform (e.g., `linux`, `windows`, `darwin`).
67
- - `os.cpus(): number` - Number of logical CPU cores.
68
- - `os.totalMemory(): number` - Total system memory in bytes.
69
- - `os.freeMemory(): number` - Free system memory in bytes.
70
- - `os.tmpdir(): string` - Path to the system temporary directory.
71
-
72
- ### `net` (Network)
73
- Basic network utilities.
74
- - `net.resolveDNS(hostname: string): string[]` - Resolve a hostname to IP addresses.
75
- - `net.ip(): string` - Get the local system IP address.
76
-
77
- ### `proc` (Process Management)
78
- Manage and query system processes.
79
- - `proc.pid(): number` - Get the Process ID of the current Titan runtime.
80
- - `proc.info(): object` - Get basic info about the current process.
81
- - `proc.run(command: string, args?: string[], cwd?: string): object` - Spawn a background process.
82
- - `proc.kill(pid: number): boolean` - Terminate a process by PID.
83
- - `proc.list(): object[]` - List all running system processes with CPU and memory usage.
84
-
85
- ### `time` (Time Utilities)
86
- - `time.sleep(ms: number): void` - Synchronously block execution for `ms` milliseconds.
87
- - `time.now(): number` - Returns `Date.now()`.
88
-
89
- ### `ls` (Persistent Local Storage)
90
- High-performance key-value storage persisted to disk.
91
- - `ls.get(key: string): string|null` - Retrieve a string value.
92
- - `ls.set(key: string, value: string): void` - Persist a string value.
93
- - `ls.remove(key: string): void` - Delete a key.
94
- - `ls.clear(): void` - Clear all stored data.
95
- - `ls.keys(): string[]` - List all stored keys.
96
- - `ls.setObject(key: string, value: any): void` - Store a complex JS object using native V8 serialization.
97
- - `ls.getObject(key: string): any` - Retrieve and restore a complex JS object.
98
- - `ls.serialize(value: any): Uint8Array` - Native V8 serialization (supports Map, Set, Date, Uint8Array).
99
- - `ls.deserialize(bytes: Uint8Array): any` - Native V8 deserialization.
100
-
101
- ### `session` (Session Management)
102
- - `session.get(sid: string, key: string): string|null` - Get session data.
103
- - `session.set(sid: string, key: string, value: string): void` - Set session data.
104
- - `session.delete(sid: string, key: string): void` - Delete session data.
105
- - `session.clear(sid: string): void` - Clear an entire session.
106
-
107
- ### `cookies` (HTTP Cookies)
108
- - `cookies.get(req: object, name: string): string|null` - Extract cookie value from request.
109
- - `cookies.set(res: object, name: string, value: string, options?: object): void` - Attach `Set-Cookie` to response.
110
-
111
- ### `url` (URL Parsing)
112
- - `url.parse(str: string): URL` - Parse a URL string into a native URL object.
113
- - `new url.SearchParams(init?: string)` - Construct query parameters.
114
-
115
- ### `response` (HTTP Response Builder)
116
- Helper for constructing standardized Titan responses.
117
- - `response.text(content: string, options?: object): object` - Create a plain text response.
118
- - `response.json(data: any, options?: object): object` - Create a JSON response.
119
- - `response.html(content: string, options?: object): object` - Create an HTML response.
120
- - `response.redirect(url: string, status?: number): object` - Create a redirect response.
121
-
122
- ---
123
-
124
- ## Native Bindings
125
- This extension includes native Rust bindings for high-performance operations. The native binary is automatically loaded by the Titan Runtime during initialization.
126
-
127
- ## License
128
- ISC