@titanpl/core 1.0.1 → 2.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.
package/LICENSE CHANGED
@@ -1,15 +1,15 @@
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
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
15
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,127 +1,127 @@
1
- # @titanpl/core
2
-
3
- The official Core Standard Library for **Titan Planet** - a high-performance JavaScript runtime.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @titanpl/core
9
- ```
10
-
11
- ## Overview
12
-
13
- `@titanpl/core` provides essential standard library modules for Titan applications:
14
-
15
- | Module | Description |
16
- |--------|-------------|
17
- | `fs` | File system operations (read, write, mkdir, exists, stat, remove) |
18
- | `path` | Path manipulation utilities (join, resolve, extname, dirname, basename) |
19
- | `crypto` | Cryptographic functions (hash, randomBytes, uuid, base64) |
20
- | `os` | Operating system information (platform, cpus, memory) |
21
- | `net` | Network utilities (DNS resolve, IP address) |
22
- | `proc` | Process information (pid, uptime) |
23
- | `time` | Time utilities (sleep, now, timestamp) |
24
- | `url` | URL parsing and manipulation |
25
-
26
- ## Usage
27
-
28
- Once installed, the extension automatically attaches to the Titan runtime:
29
-
30
- ```javascript
31
- // Access via t.core
32
- const content = t.core.fs.readFile("config.json");
33
- const joined = t.core.path.join("foo", "bar", "baz.txt");
34
- const uuid = t.core.crypto.uuid();
35
-
36
- // Or via individual modules on t
37
- const exists = t.fs.exists("./data");
38
- const now = t.time.now();
39
- ```
40
-
41
- ## API Reference
42
-
43
- ### fs (File System)
44
-
45
- ```javascript
46
- t.fs.readFile(path) // Read file contents as string
47
- t.fs.writeFile(path, content) // Write string to file
48
- t.fs.readdir(path) // List directory contents
49
- t.fs.mkdir(path) // Create directory
50
- t.fs.exists(path) // Check if path exists
51
- t.fs.stat(path) // Get file/directory stats
52
- t.fs.remove(path) // Remove file or directory
53
- ```
54
-
55
- ### path
56
-
57
- ```javascript
58
- t.path.join(...parts) // Join path segments
59
- t.path.resolve(...parts) // Resolve to absolute path
60
- t.path.extname(path) // Get file extension
61
- t.path.dirname(path) // Get directory name
62
- t.path.basename(path) // Get file name
63
- ```
64
-
65
- ### crypto
66
-
67
- ```javascript
68
- t.crypto.hash(algo, data) // Hash data (sha256, sha512, etc.)
69
- t.crypto.randomBytes(size) // Generate random bytes
70
- t.crypto.uuid() // Generate UUID v4
71
- t.crypto.base64.encode(str) // Base64 encode
72
- t.crypto.base64.decode(str) // Base64 decode
73
- t.crypto.compare(a, b) // Constant-time string comparison
74
- ```
75
-
76
- ### os
77
-
78
- ```javascript
79
- t.os.platform() // Get OS platform
80
- t.os.cpus() // Get CPU count
81
- t.os.totalMemory() // Get total memory
82
- t.os.freeMemory() // Get free memory
83
- t.os.tmpdir() // Get temp directory path
84
- ```
85
-
86
- ### net
87
-
88
- ```javascript
89
- t.net.resolveDNS(hostname) // Resolve DNS
90
- t.net.ip() // Get local IP address
91
- ```
92
-
93
- ### proc
94
-
95
- ```javascript
96
- t.proc.pid() // Get process ID
97
- t.proc.uptime() // Get process uptime
98
- ```
99
-
100
- ### time
101
-
102
- ```javascript
103
- t.time.sleep(ms) // Sleep for milliseconds
104
- t.time.now() // Get current timestamp (ms)
105
- t.time.timestamp() // Get ISO timestamp string
106
- ```
107
-
108
- ### url
109
-
110
- ```javascript
111
- t.url.parse(urlString) // Parse URL string
112
- t.url.format(urlObject) // Format URL object to string
113
- new t.url.SearchParams(query) // Parse query string
114
- ```
115
-
116
- ## Native Bindings
117
-
118
- This extension includes native Rust bindings for high-performance file system and OS operations. The native library is automatically loaded when available.
119
-
120
- ## Requirements
121
-
122
- - Titan SDK >= 0.1.7
123
- - Node.js >= 18.0.0 (for development)
124
-
125
- ## License
126
-
127
- ISC © ezetgalaxy
1
+ # @titanpl/core
2
+ The official Core Standard Library for Titan Planet - a high-performance JavaScript runtime extension.
3
+
4
+ ## Overview
5
+ `@titanpl/core` provides essential standard library modules for Titan applications, bridging high-performance Rust native implementations with an easy-to-use JavaScript API.
6
+
7
+ ## Installation
8
+ ```bash
9
+ npm install @titanpl/core
10
+ ```
11
+
12
+ ## Usage
13
+ The extension automatically attaches to the Titan runtime. You can access it via `t.core` or the `t` global object alias.
14
+
15
+ ```javascript
16
+ // Access via t.core (Recommended)
17
+ const { fs, crypto, os } = t.core;
18
+
19
+ // Read a file
20
+ const content = fs.readFile("config.json");
21
+
22
+ // Generate UUID
23
+ const id = crypto.uuid();
24
+ ```
25
+
26
+ ## API Reference
27
+
28
+ ### `fs` (File System)
29
+ Perform synchronous file system operations.
30
+ - `fs.readFile(path: string): string` - Read file content as UTF-8 string.
31
+ - `fs.writeFile(path: string, content: string): void` - Write string content to file.
32
+ - `fs.exists(path: string): boolean` - Check if path exists.
33
+ - `fs.mkdir(path: string): void` - Create a directory (recursive).
34
+ - `fs.remove(path: string): void` - Remove file or directory.
35
+ - `fs.readdir(path: string): string[]` - List directory contents.
36
+ - `fs.stat(path: string): object` - Get file statistics (`{ type: "file"|"directory", size: number }`).
37
+
38
+ ### `path` (Path Manipulation)
39
+ Utilities for handling file paths.
40
+ - `path.join(...parts: string[]): string` - Join path segments.
41
+ - `path.resolve(...parts: string[]): string` - Resolve path to absolute.
42
+ - `path.dirname(path: string): string` - Get directory name.
43
+ - `path.basename(path: string): string` - Get base file name.
44
+ - `path.extname(path: string): string` - Get file extension.
45
+
46
+ ### `crypto` (Cryptography)
47
+ Cryptographic utilities using native Rust implementations.
48
+ - `crypto.hash(algo: string, data: string): string` - Hash data. Supported algos: `sha256`, `sha512`, `md5`.
49
+ - `crypto.randomBytes(size: number): string` - Generate random bytes as hex string.
50
+ - `crypto.uuid(): string` - Generate a UUID v4.
51
+ - `crypto.compare(hash: string, target: string): boolean` - Constant-time comparison.
52
+ - `crypto.encrypt(algorithm: string, key: string, plaintext: string): string` - AES-256-GCM Encrypt (Returns Base64).
53
+ - `crypto.decrypt(algorithm: string, key: string, ciphertext: string): string` - AES-256-GCM Decrypt.
54
+ - `crypto.hashKeyed(algo: string, key: string, message: string): string` - HMAC-SHA256/512.
55
+
56
+ **Example:**
57
+ ```javascript
58
+ const hash = t.core.crypto.hash("sha256", "hii");
59
+ const valid = t.core.crypto.compare(
60
+ "a1a3b09875f9e9acade5623e1cca680009a6c9e0452489931cfa5b0041f4d290",
61
+ hash
62
+ );
63
+ ```
64
+
65
+ ### `buffer` (Buffer Utilities)
66
+ Utilities for binary data manipulation.
67
+ - `buffer.fromBase64(str: string): Uint8Array` - Decode Base64 string.
68
+ - `buffer.toBase64(bytes: Uint8Array|string): string` - Encode to Base64.
69
+ - `buffer.fromHex(str: string): Uint8Array` - Decode Hex string.
70
+ - `buffer.toHex(bytes: Uint8Array|string): string` - Encode to Hex.
71
+ - `buffer.fromUtf8(str: string): Uint8Array` - Encode UTF-8 string to bytes.
72
+ - `buffer.toUtf8(bytes: Uint8Array): string` - Decode bytes to UTF-8 string.
73
+
74
+ ### `ls` / `localStorage` (Persistent Storage)
75
+ Key-value storage persisted to disk (via Sled).
76
+ - `ls.get(key: string): string|null` - Get value.
77
+ - `ls.set(key: string, value: string): void` - Set value.
78
+ - `ls.remove(key: string): void` - Remove key.
79
+ - `ls.clear(): void` - Clear all storage.
80
+ - `ls.keys(): string[]` - List all keys.
81
+
82
+ ### `session` (Server-side Sessions)
83
+ Session management backed by persistent storage.
84
+ - `session.get(sessionId: string, key: string): string|null` - Get session value.
85
+ - `session.set(sessionId: string, key: string, value: string): void` - Set session value.
86
+ - `session.delete(sessionId: string, key: string): void` - Delete session value.
87
+ - `session.clear(sessionId: string): void` - Clear entire session.
88
+
89
+ ### `cookies` (HTTP Cookies)
90
+ Cookie parsing and serialization.
91
+ - `cookies.get(req: object, name: string): string|null` - Parse cookie from request headers.
92
+ - `cookies.set(res: object, name: string, value: string, options: object): void` - Set `Set-Cookie` header on response. Options: `{ httpOnly, secure, sameSite, path, maxAge }`.
93
+ - `cookies.delete(res: object, name: string): void` - Delete cookie (expire).
94
+
95
+ ### `os` (Operating System)
96
+ Get system information.
97
+ - `os.platform(): string` - OS platform (e.g., `linux`, `windows`).
98
+ - `os.cpus(): number` - Number of CPU cores.
99
+ - `os.totalMemory(): number` - Total system memory in bytes.
100
+ - `os.freeMemory(): number` - Free system memory in bytes.
101
+ - `os.tmpdir(): string` - Temporary directory path.
102
+
103
+ ### `net` (Network)
104
+ Network utilities.
105
+ - `net.resolveDNS(hostname: string): string[]` - Resolve hostname to IP addresses.
106
+ - `net.ip(): string` - Get local IP address.
107
+
108
+ ### `proc` (Process)
109
+ Current process information.
110
+ - `proc.pid(): number` - Process ID.
111
+ - `proc.uptime(): number` - System uptime in seconds.
112
+
113
+ ### `time` (Time)
114
+ Time utilities.
115
+ - `time.sleep(ms: number): void` - Sleep for specified milliseconds.
116
+ - `time.now(): number` - Current timestamp (ms).
117
+ - `time.timestamp(): string` - Current ISO timestamp.
118
+
119
+ ### `url` (URL)
120
+ URL parsing and manipulation.
121
+ - `url.parse(urlString: string): URLObject` - Parse URL string.
122
+ - `url.format(urlObject: object): string` - Format URL object.
123
+ - `new url.SearchParams(query: string|object)` - Handle query strings.
124
+
125
+ ## Native Bindings
126
+ This extension includes native Rust bindings for high-performance operations. The native library is automatically loaded by the Titan Runtime.
127
+
package/globals.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- declare var t: any;
2
- declare var fs_read_file: any;
3
- declare var fs_write_file: any;
4
- declare var fs_readdir: any;
5
- declare var fs_mkdir: any;
6
- declare var fs_exists: any;
7
- declare var fs_stat: any;
8
- declare var fs_remove: any;
9
- declare var path_cwd: any;
10
- declare var crypto_hash: any;
11
- declare var crypto_random_bytes: any;
12
- declare var crypto_uuid: any;
13
- declare var os_info: any;
14
- declare var net_resolve: any;
15
- declare var net_ip: any;
16
- declare var proc_info: any;
17
- declare var time_sleep: any;
1
+ declare var t: any;
2
+ declare var fs_read_file: any;
3
+ declare var fs_write_file: any;
4
+ declare var fs_readdir: any;
5
+ declare var fs_mkdir: any;
6
+ declare var fs_exists: any;
7
+ declare var fs_stat: any;
8
+ declare var fs_remove: any;
9
+ declare var path_cwd: any;
10
+ declare var crypto_hash: any;
11
+ declare var crypto_random_bytes: any;
12
+ declare var crypto_uuid: any;
13
+ declare var os_info: any;
14
+ declare var net_resolve: any;
15
+ declare var net_ip: any;
16
+ declare var proc_info: any;
17
+ declare var time_sleep: any;