@ezetgalaxy/titan 26.9.1 → 26.9.3
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 +17 -5
- package/index.js +177 -112
- package/package.json +19 -5
- package/templates/common/app/titan.d.ts +87 -0
- package/templates/extension/node_modules/.bin/esbuild +16 -0
- package/templates/extension/node_modules/.bin/esbuild.cmd +17 -0
- package/templates/extension/node_modules/.bin/esbuild.ps1 +28 -0
- package/templates/extension/node_modules/.bin/titanpl-sdk +16 -0
- package/templates/extension/node_modules/.bin/titanpl-sdk.cmd +17 -0
- package/templates/extension/node_modules/.bin/titanpl-sdk.ps1 +28 -0
- package/templates/extension/node_modules/.package-lock.json +111 -0
- package/templates/extension/node_modules/@esbuild/win32-x64/README.md +3 -0
- package/templates/extension/node_modules/@esbuild/win32-x64/esbuild.exe +0 -0
- package/templates/extension/node_modules/@esbuild/win32-x64/package.json +20 -0
- package/templates/extension/node_modules/@titanpl/core/LICENSE +15 -0
- package/templates/extension/node_modules/@titanpl/core/README.md +127 -0
- package/templates/extension/node_modules/@titanpl/core/globals.d.ts +17 -0
- package/templates/extension/node_modules/@titanpl/core/index.js +250 -0
- package/templates/extension/node_modules/@titanpl/core/native/target/release/titan_core.dll +0 -0
- package/templates/extension/node_modules/@titanpl/core/package.json +41 -0
- package/templates/extension/node_modules/@titanpl/core/titan.json +115 -0
- package/templates/extension/node_modules/chokidar/LICENSE +21 -0
- package/templates/extension/node_modules/chokidar/README.md +305 -0
- package/templates/extension/node_modules/chokidar/handler.d.ts +90 -0
- package/templates/extension/node_modules/chokidar/handler.js +632 -0
- package/templates/extension/node_modules/chokidar/index.d.ts +217 -0
- package/templates/extension/node_modules/chokidar/index.js +822 -0
- package/templates/extension/node_modules/chokidar/package.json +63 -0
- package/templates/extension/node_modules/esbuild/LICENSE.md +21 -0
- package/templates/extension/node_modules/esbuild/README.md +3 -0
- package/templates/extension/node_modules/esbuild/bin/esbuild +223 -0
- package/templates/extension/node_modules/esbuild/install.js +289 -0
- package/templates/extension/node_modules/esbuild/lib/main.d.ts +716 -0
- package/templates/extension/node_modules/esbuild/lib/main.js +2242 -0
- package/templates/extension/node_modules/esbuild/package.json +49 -0
- package/templates/extension/node_modules/readdirp/LICENSE +21 -0
- package/templates/extension/node_modules/readdirp/README.md +120 -0
- package/templates/extension/node_modules/readdirp/index.d.ts +108 -0
- package/templates/extension/node_modules/readdirp/index.js +272 -0
- package/templates/extension/node_modules/readdirp/package.json +66 -0
- package/templates/extension/node_modules/titanpl-sdk/LICENSE +15 -0
- package/templates/extension/node_modules/titanpl-sdk/README.md +109 -0
- package/templates/extension/node_modules/titanpl-sdk/assets/titanpl-sdk.png +0 -0
- package/templates/extension/node_modules/titanpl-sdk/bin/run.js +251 -0
- package/templates/extension/node_modules/titanpl-sdk/index.d.ts +46 -0
- package/templates/extension/node_modules/titanpl-sdk/index.js +5 -0
- package/templates/extension/node_modules/titanpl-sdk/package.json +33 -0
- package/templates/{rust-js → extension/node_modules/titanpl-sdk/templates}/Dockerfile +4 -17
- package/templates/extension/node_modules/titanpl-sdk/templates/app/actions/hello.js +5 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/app/app.js +10 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/jsconfig.json +19 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/Cargo.lock +2839 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/Cargo.toml +27 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/src/action_management.rs +131 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/src/errors.rs +10 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/src/extensions.rs +640 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/src/main.rs +345 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/server/src/utils.rs +33 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/titan/bundle.js +65 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/titan/dev.js +113 -0
- package/templates/extension/node_modules/titanpl-sdk/templates/titan/titan.js +98 -0
- package/templates/extension/package-lock.json +522 -0
- package/templates/extension/package.json +4 -3
- package/templates/rust-ts/app/actions/hello.ts +1 -1
- package/templates/rust-ts/titan/runtime.d.ts +1 -0
- package/templates/rust-ts/titan/runtime.js +1 -0
- package/templates/rust-ts/titan/titan.d.ts +117 -117
- package/templates/rust-ts/titan/titan.js +1 -1
- package/templates/ts/app/actions/hello.ts +1 -1
- package/templates/ts/titan/builder.js +121 -121
- package/templates/ts/titan/runtime.d.ts +1 -0
- package/templates/ts/titan/runtime.js +1 -1
- package/templates/ts/titan/titan.d.ts +117 -117
- package/templates/ts/titan/titan.js +1 -1
- package/titanpl-sdk/node_modules/.package-lock.json +17 -0
- package/titanpl-sdk/node_modules/@titanpl/core/LICENSE +15 -0
- package/titanpl-sdk/node_modules/@titanpl/core/README.md +127 -0
- package/titanpl-sdk/node_modules/@titanpl/core/globals.d.ts +17 -0
- package/titanpl-sdk/node_modules/@titanpl/core/index.js +250 -0
- package/titanpl-sdk/node_modules/@titanpl/core/native/target/release/titan_core.dll +0 -0
- package/titanpl-sdk/node_modules/@titanpl/core/package.json +41 -0
- package/titanpl-sdk/node_modules/@titanpl/core/titan.json +115 -0
- package/titanpl-sdk/package-lock.json +28 -0
- package/titanpl-sdk/package.json +6 -3
- package/templates/rust-js/_gitignore +0 -38
- package/templates/rust-js/app/titan.d.ts +0 -101
- package/templates/rust-ts/Dockerfile +0 -66
- package/templates/rust-ts/_dockerignore +0 -3
- package/templates/rust-ts/_gitignore +0 -38
- package/templates/ts/Dockerfile +0 -40
- package/templates/ts/_dockerignore +0 -3
- package/templates/ts/_gitignore +0 -38
- /package/templates/{js → common}/Dockerfile +0 -0
- /package/templates/{js → common}/_dockerignore +0 -0
- /package/templates/{js → common}/_gitignore +0 -0
- /package/templates/{rust-js/_dockerignore → extension/node_modules/titanpl-sdk/templates/.dockerignore} +0 -0
- /package/templates/{js → extension/node_modules/titanpl-sdk/templates}/app/titan.d.ts +0 -0
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
// -- Module Definitions (for imports from "titan") --
|
|
3
|
-
|
|
4
|
-
export interface RouteHandler {
|
|
5
|
-
reply(value: any): void;
|
|
6
|
-
action(name: string): void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface TitanBuilder {
|
|
10
|
-
get(route: string): RouteHandler;
|
|
11
|
-
post(route: string): RouteHandler;
|
|
12
|
-
log(module: string, msg: string): void;
|
|
13
|
-
start(port?: number, msg?: string): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// The default export from titan.js is the Builder
|
|
17
|
-
declare const builder: TitanBuilder;
|
|
18
|
-
export default builder;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Define a Titan Action with type inference.
|
|
22
|
-
*/
|
|
23
|
-
export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// -- Global Definitions (Runtime Environment) --
|
|
27
|
-
|
|
28
|
-
declare global {
|
|
29
|
-
/**
|
|
30
|
-
* The Titan Request Object passed to actions.
|
|
31
|
-
*/
|
|
32
|
-
interface TitanRequest {
|
|
33
|
-
body: any;
|
|
34
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
35
|
-
path: string;
|
|
36
|
-
headers: {
|
|
37
|
-
host?: string;
|
|
38
|
-
"content-type"?: string;
|
|
39
|
-
"user-agent"?: string;
|
|
40
|
-
authorization?: string;
|
|
41
|
-
[key: string]: string | undefined;
|
|
42
|
-
};
|
|
43
|
-
params: Record<string, string>;
|
|
44
|
-
query: Record<string, string>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface DbConnection {
|
|
48
|
-
/**
|
|
49
|
-
* Execute a SQL query.
|
|
50
|
-
* @param sql The SQL query string.
|
|
51
|
-
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
52
|
-
*/
|
|
53
|
-
query(sql: string, params?: any[]): any[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Global defineAction (available without import in runtime, though imports are preferred in TS)
|
|
58
|
-
*/
|
|
59
|
-
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Global Request Object
|
|
63
|
-
* Available automatically in actions.
|
|
64
|
-
*/
|
|
65
|
-
var req: TitanRequest;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Titan Runtime Utilities
|
|
69
|
-
* (Available globally in the runtime, e.g. inside actions)
|
|
70
|
-
*/
|
|
71
|
-
const t: {
|
|
72
|
-
/**
|
|
73
|
-
* Log messages to the server console with Titan formatting.
|
|
74
|
-
*/
|
|
75
|
-
log(...args: any[]): void;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Read a file contents as string.
|
|
79
|
-
* @param path Relative path to the file from project root.
|
|
80
|
-
*/
|
|
81
|
-
read(path: string): string;
|
|
82
|
-
|
|
83
|
-
fetch(url: string, options?: {
|
|
84
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
85
|
-
headers?: Record<string, string>;
|
|
86
|
-
body?: string | object;
|
|
87
|
-
}): {
|
|
88
|
-
ok: boolean;
|
|
89
|
-
status?: number;
|
|
90
|
-
body?: string;
|
|
91
|
-
error?: string;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
jwt: {
|
|
95
|
-
sign(
|
|
96
|
-
payload: object,
|
|
97
|
-
secret: string,
|
|
98
|
-
options?: { expiresIn?: string | number }
|
|
99
|
-
): string;
|
|
100
|
-
verify(token: string, secret: string): any;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
password: {
|
|
104
|
-
hash(password: string): string;
|
|
105
|
-
verify(password: string, hash: string): boolean;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
db: {
|
|
109
|
-
connect(url: string): DbConnection;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Titan Validator (Zod-compatible)
|
|
114
|
-
*/
|
|
115
|
-
valid: any;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
1
|
+
|
|
2
|
+
// -- Module Definitions (for imports from "titan") --
|
|
3
|
+
|
|
4
|
+
export interface RouteHandler {
|
|
5
|
+
reply(value: any): void;
|
|
6
|
+
action(name: string): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TitanBuilder {
|
|
10
|
+
get(route: string): RouteHandler;
|
|
11
|
+
post(route: string): RouteHandler;
|
|
12
|
+
log(module: string, msg: string): void;
|
|
13
|
+
start(port?: number, msg?: string): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// The default export from titan.js is the Builder
|
|
17
|
+
declare const builder: TitanBuilder;
|
|
18
|
+
export default builder;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Define a Titan Action with type inference.
|
|
22
|
+
*/
|
|
23
|
+
export declare function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// -- Global Definitions (Runtime Environment) --
|
|
27
|
+
|
|
28
|
+
declare global {
|
|
29
|
+
/**
|
|
30
|
+
* The Titan Request Object passed to actions.
|
|
31
|
+
*/
|
|
32
|
+
interface TitanRequest {
|
|
33
|
+
body: any;
|
|
34
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
35
|
+
path: string;
|
|
36
|
+
headers: {
|
|
37
|
+
host?: string;
|
|
38
|
+
"content-type"?: string;
|
|
39
|
+
"user-agent"?: string;
|
|
40
|
+
authorization?: string;
|
|
41
|
+
[key: string]: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
params: Record<string, string>;
|
|
44
|
+
query: Record<string, string>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface DbConnection {
|
|
48
|
+
/**
|
|
49
|
+
* Execute a SQL query.
|
|
50
|
+
* @param sql The SQL query string.
|
|
51
|
+
* @param params (Optional) Parameters for the query ($1, $2, etc).
|
|
52
|
+
*/
|
|
53
|
+
query(sql: string, params?: any[]): any[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Global defineAction (available without import in runtime, though imports are preferred in TS)
|
|
58
|
+
*/
|
|
59
|
+
function defineAction<T>(actionFn: (req: TitanRequest) => T): (req: TitanRequest) => T;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Global Request Object
|
|
63
|
+
* Available automatically in actions.
|
|
64
|
+
*/
|
|
65
|
+
var req: TitanRequest;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Titan Runtime Utilities
|
|
69
|
+
* (Available globally in the runtime, e.g. inside actions)
|
|
70
|
+
*/
|
|
71
|
+
const t: {
|
|
72
|
+
/**
|
|
73
|
+
* Log messages to the server console with Titan formatting.
|
|
74
|
+
*/
|
|
75
|
+
log(...args: any[]): void;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Read a file contents as string.
|
|
79
|
+
* @param path Relative path to the file from project root.
|
|
80
|
+
*/
|
|
81
|
+
read(path: string): string;
|
|
82
|
+
|
|
83
|
+
fetch(url: string, options?: {
|
|
84
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
body?: string | object;
|
|
87
|
+
}): {
|
|
88
|
+
ok: boolean;
|
|
89
|
+
status?: number;
|
|
90
|
+
body?: string;
|
|
91
|
+
error?: string;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
jwt: {
|
|
95
|
+
sign(
|
|
96
|
+
payload: object,
|
|
97
|
+
secret: string,
|
|
98
|
+
options?: { expiresIn?: string | number }
|
|
99
|
+
): string;
|
|
100
|
+
verify(token: string, secret: string): any;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
password: {
|
|
104
|
+
hash(password: string): string;
|
|
105
|
+
verify(password: string, hash: string): boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
db: {
|
|
109
|
+
connect(url: string): DbConnection;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Titan Validator (Zod-compatible)
|
|
114
|
+
*/
|
|
115
|
+
valid: any;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "titanpl-sdk",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"node_modules/@titanpl/core": {
|
|
8
|
+
"version": "1.0.1",
|
|
9
|
+
"resolved": "https://registry.npmjs.org/@titanpl/core/-/core-1.0.1.tgz",
|
|
10
|
+
"integrity": "sha512-5zcDMNnf+oghKkQMiPBFuhLlRy2IASyWMAAMgfqa4AzoXxiw2BzzfN0B2EA76Dy9AhCeK2mY84Zm+FSE7ANVFg==",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18.0.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +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
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Titan Core Library
|
|
2
|
+
// Provides standard library features using native bindings.
|
|
3
|
+
|
|
4
|
+
// Native bindings are expected to be available globally or via t.native
|
|
5
|
+
// adjusting based on typical Titan behavior.
|
|
6
|
+
// We bind them to local variables for cleaner usage.
|
|
7
|
+
|
|
8
|
+
const native_fs_read_file = globalThis.fs_read_file;
|
|
9
|
+
const native_fs_write_file = globalThis.fs_write_file;
|
|
10
|
+
const native_fs_readdir = globalThis.fs_readdir;
|
|
11
|
+
const native_fs_mkdir = globalThis.fs_mkdir;
|
|
12
|
+
const native_fs_exists = globalThis.fs_exists;
|
|
13
|
+
const native_fs_stat = globalThis.fs_stat;
|
|
14
|
+
const native_fs_remove = globalThis.fs_remove;
|
|
15
|
+
const native_path_cwd = globalThis.path_cwd;
|
|
16
|
+
const native_crypto_hash = globalThis.crypto_hash;
|
|
17
|
+
const native_crypto_random_bytes = globalThis.crypto_random_bytes;
|
|
18
|
+
const native_crypto_uuid = globalThis.crypto_uuid;
|
|
19
|
+
const native_os_info = globalThis.os_info;
|
|
20
|
+
const native_net_resolve = globalThis.net_resolve;
|
|
21
|
+
const native_net_ip = globalThis.net_ip;
|
|
22
|
+
const native_proc_info = globalThis.proc_info;
|
|
23
|
+
const native_time_sleep = globalThis.time_sleep;
|
|
24
|
+
|
|
25
|
+
// --- FS ---
|
|
26
|
+
const fs = {
|
|
27
|
+
readFile: (path) => {
|
|
28
|
+
if (!native_fs_read_file) throw new Error("Native fs_read_file not found");
|
|
29
|
+
return native_fs_read_file(path);
|
|
30
|
+
},
|
|
31
|
+
writeFile: (path, content) => {
|
|
32
|
+
if (!native_fs_write_file) throw new Error("Native fs_write_file not found");
|
|
33
|
+
native_fs_write_file(path, content);
|
|
34
|
+
},
|
|
35
|
+
readdir: (path) => {
|
|
36
|
+
if (!native_fs_readdir) throw new Error("Native fs_readdir not found");
|
|
37
|
+
return JSON.parse(native_fs_readdir(path));
|
|
38
|
+
},
|
|
39
|
+
mkdir: (path) => {
|
|
40
|
+
if (!native_fs_mkdir) throw new Error("Native fs_mkdir not found");
|
|
41
|
+
native_fs_mkdir(path);
|
|
42
|
+
},
|
|
43
|
+
exists: (path) => {
|
|
44
|
+
if (!native_fs_exists) throw new Error("Native fs_exists not found");
|
|
45
|
+
return native_fs_exists(path);
|
|
46
|
+
},
|
|
47
|
+
stat: (path) => {
|
|
48
|
+
if (!native_fs_stat) throw new Error("Native fs_stat not found");
|
|
49
|
+
return JSON.parse(native_fs_stat(path));
|
|
50
|
+
},
|
|
51
|
+
remove: (path) => {
|
|
52
|
+
if (!native_fs_remove) throw new Error("Native fs_remove not found");
|
|
53
|
+
native_fs_remove(path);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// --- Path ---
|
|
58
|
+
// Basic implementation for POSIX-like paths (Titan mostly runs on servers/containers)
|
|
59
|
+
const path = {
|
|
60
|
+
join: (...args) => {
|
|
61
|
+
return args
|
|
62
|
+
.map((part, i) => {
|
|
63
|
+
if (i === 0) return part.trim().replace(/[\/]*$/g, '');
|
|
64
|
+
return part.trim().replace(/(^[\/]*|[\/]*$)/g, '');
|
|
65
|
+
})
|
|
66
|
+
.filter(x => x.length)
|
|
67
|
+
.join('/');
|
|
68
|
+
},
|
|
69
|
+
resolve: (...args) => {
|
|
70
|
+
let resolved = '';
|
|
71
|
+
for (let arg of args) {
|
|
72
|
+
resolved = path.join(resolved, arg);
|
|
73
|
+
}
|
|
74
|
+
if (!resolved.startsWith('/') && native_path_cwd) {
|
|
75
|
+
resolved = path.join(native_path_cwd(), resolved);
|
|
76
|
+
}
|
|
77
|
+
return resolved;
|
|
78
|
+
},
|
|
79
|
+
extname: (p) => {
|
|
80
|
+
const parts = p.split('.');
|
|
81
|
+
return parts.length > 1 && !p.startsWith('.') ? '.' + parts.pop() : '';
|
|
82
|
+
},
|
|
83
|
+
dirname: (p) => {
|
|
84
|
+
const parts = p.split('/');
|
|
85
|
+
parts.pop();
|
|
86
|
+
return parts.join('/') || '.';
|
|
87
|
+
},
|
|
88
|
+
basename: (p) => p.split('/').pop()
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// --- Crypto ---
|
|
92
|
+
const crypto = {
|
|
93
|
+
hash: (algo, data) => native_crypto_hash(algo, data),
|
|
94
|
+
randomBytes: (size) => native_crypto_random_bytes(size),
|
|
95
|
+
uuid: () => native_crypto_uuid(),
|
|
96
|
+
base64: {
|
|
97
|
+
encode: (str) => btoa(str), // Boa supports btoa/atob
|
|
98
|
+
decode: (str) => atob(str),
|
|
99
|
+
},
|
|
100
|
+
compare: (a, b) => {
|
|
101
|
+
if (a.length !== b.length) return false;
|
|
102
|
+
// Constant time comparison not guaranteed here in JS easily without specialized tricks
|
|
103
|
+
let mismatch = 0;
|
|
104
|
+
for (let i = 0; i < a.length; ++i) {
|
|
105
|
+
mismatch |= (a.charCodeAt(i) ^ b.charCodeAt(i));
|
|
106
|
+
}
|
|
107
|
+
return mismatch === 0;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// --- OS ---
|
|
112
|
+
const os = {
|
|
113
|
+
platform: () => {
|
|
114
|
+
const info = JSON.parse(native_os_info());
|
|
115
|
+
return info.platform;
|
|
116
|
+
},
|
|
117
|
+
cpus: () => {
|
|
118
|
+
const info = JSON.parse(native_os_info());
|
|
119
|
+
return info.cpus;
|
|
120
|
+
},
|
|
121
|
+
totalMemory: () => {
|
|
122
|
+
const info = JSON.parse(native_os_info());
|
|
123
|
+
return info.totalMemory;
|
|
124
|
+
},
|
|
125
|
+
freeMemory: () => {
|
|
126
|
+
const info = JSON.parse(native_os_info());
|
|
127
|
+
return info.freeMemory;
|
|
128
|
+
},
|
|
129
|
+
tmpdir: () => '/tmp' // Default for now, generic
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// --- Net ---
|
|
133
|
+
const net = {
|
|
134
|
+
resolveDNS: (hostname) => JSON.parse(native_net_resolve(hostname)),
|
|
135
|
+
ip: () => native_net_ip(),
|
|
136
|
+
ping: (host) => {
|
|
137
|
+
// Mock ping or simple verify
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// --- Proc ---
|
|
143
|
+
// Memoize static info if needed, but here we call native
|
|
144
|
+
const proc = {
|
|
145
|
+
pid: () => {
|
|
146
|
+
const info = JSON.parse(native_proc_info());
|
|
147
|
+
return info.pid;
|
|
148
|
+
},
|
|
149
|
+
uptime: () => {
|
|
150
|
+
const info = JSON.parse(native_proc_info());
|
|
151
|
+
return info.uptime;
|
|
152
|
+
},
|
|
153
|
+
memory: () => {
|
|
154
|
+
// Optional: return full memory usage if possible
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// --- Time ---
|
|
160
|
+
const time = {
|
|
161
|
+
sleep: (ms) => native_time_sleep(ms),
|
|
162
|
+
now: () => Date.now(),
|
|
163
|
+
timestamp: () => new Date().toISOString()
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// --- URL ---
|
|
167
|
+
// Simple URLSearchParams polyfill for V8 runtime
|
|
168
|
+
class TitanURLSearchParams {
|
|
169
|
+
constructor(init = '') {
|
|
170
|
+
this._params = {};
|
|
171
|
+
if (typeof init === 'string') {
|
|
172
|
+
const query = init.startsWith('?') ? init.slice(1) : init;
|
|
173
|
+
query.split('&').forEach(pair => {
|
|
174
|
+
const [key, value] = pair.split('=').map(decodeURIComponent);
|
|
175
|
+
if (key) this._params[key] = value || '';
|
|
176
|
+
});
|
|
177
|
+
} else if (typeof init === 'object') {
|
|
178
|
+
Object.assign(this._params, init);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
get(key) { return this._params[key] || null; }
|
|
182
|
+
set(key, value) { this._params[key] = String(value); }
|
|
183
|
+
has(key) { return key in this._params; }
|
|
184
|
+
delete(key) { delete this._params[key]; }
|
|
185
|
+
toString() {
|
|
186
|
+
return Object.entries(this._params)
|
|
187
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
188
|
+
.join('&');
|
|
189
|
+
}
|
|
190
|
+
entries() { return Object.entries(this._params); }
|
|
191
|
+
keys() { return Object.keys(this._params); }
|
|
192
|
+
values() { return Object.values(this._params); }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const url = {
|
|
196
|
+
parse: (str) => {
|
|
197
|
+
// Basic URL parsing if native URL is available
|
|
198
|
+
if (typeof URL !== 'undefined') {
|
|
199
|
+
return new URL(str);
|
|
200
|
+
}
|
|
201
|
+
// Simple fallback parser
|
|
202
|
+
const match = str.match(/^(https?:)\/\/([^/:]+)(?::(\d+))?(\/[^?#]*)?(\?[^#]*)?(#.*)?$/);
|
|
203
|
+
if (!match) throw new Error('Invalid URL');
|
|
204
|
+
return {
|
|
205
|
+
protocol: match[1],
|
|
206
|
+
hostname: match[2],
|
|
207
|
+
port: match[3] || '',
|
|
208
|
+
pathname: match[4] || '/',
|
|
209
|
+
search: match[5] || '',
|
|
210
|
+
hash: match[6] || ''
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
format: (obj) => obj.toString ? obj.toString() : String(obj),
|
|
214
|
+
SearchParams: TitanURLSearchParams
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// Create the main core export object (following titan-valid pattern)
|
|
219
|
+
const core = {
|
|
220
|
+
fs,
|
|
221
|
+
path,
|
|
222
|
+
crypto,
|
|
223
|
+
os,
|
|
224
|
+
net,
|
|
225
|
+
proc,
|
|
226
|
+
time,
|
|
227
|
+
url
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
t.fs = fs;
|
|
232
|
+
t.path = path;
|
|
233
|
+
t.crypto = crypto;
|
|
234
|
+
t.os = os;
|
|
235
|
+
t.net = net;
|
|
236
|
+
t.proc = proc;
|
|
237
|
+
t.time = time;
|
|
238
|
+
t.url = url;
|
|
239
|
+
|
|
240
|
+
// Attach core as unified namespace (main access point)
|
|
241
|
+
t.core = core;
|
|
242
|
+
|
|
243
|
+
// Register as extension under multiple names for compatibility
|
|
244
|
+
t["titan-core"] = core;
|
|
245
|
+
t["@titanpl/core"] = core;
|
|
246
|
+
|
|
247
|
+
// Also register in t.exts
|
|
248
|
+
if (!t.exts) t.exts = {};
|
|
249
|
+
t.exts["titan-core"] = core;
|
|
250
|
+
t.exts["@titanpl/core"] = core;
|