@titanpl/core 2.0.9 → 2.1.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/README.md +80 -1
- package/configure.js +50 -50
- package/globals.d.ts +3 -0
- package/index.d.ts +748 -265
- package/index.js +111 -54
- package/native/target/release/titan_core.dll +0 -0
- package/package.json +1 -1
- package/titan.json +22 -2
- package/native/target/release/libtitan_core.so +0 -0
package/README.md
CHANGED
|
@@ -106,9 +106,12 @@ Network utilities.
|
|
|
106
106
|
- `net.ip(): string` - Get local IP address.
|
|
107
107
|
|
|
108
108
|
### `proc` (Process)
|
|
109
|
-
|
|
109
|
+
Process management and system information.
|
|
110
110
|
- `proc.pid(): number` - Process ID.
|
|
111
111
|
- `proc.uptime(): number` - System uptime in seconds.
|
|
112
|
+
- `proc.run(command: string, args?: string[]): { pid: number }` - Spawn a new process.
|
|
113
|
+
- `proc.kill(pid: number): boolean` - Kill a process by PID.
|
|
114
|
+
- `proc.list(): object[]` - List all running processes (`{ pid, name, cmd, memory, cpu }`).
|
|
112
115
|
|
|
113
116
|
### `time` (Time)
|
|
114
117
|
Time utilities.
|
|
@@ -122,6 +125,82 @@ URL parsing and manipulation.
|
|
|
122
125
|
- `url.format(urlObject: object): string` - Format URL object.
|
|
123
126
|
- `new url.SearchParams(query: string|object)` - Handle query strings.
|
|
124
127
|
|
|
128
|
+
### **`response` (HTTP Response Builder)**
|
|
129
|
+
|
|
130
|
+
Utilities for constructing HTTP responses.
|
|
131
|
+
All response methods return a standardized ResponseObject consumed by the Titan Rust HTTP server.
|
|
132
|
+
|
|
133
|
+
- `response.text(content: string, status?: number): ResponseObject` – Send plain text.
|
|
134
|
+
- `response.html(content: string, status?: number): ResponseObject` – Send HTML content.
|
|
135
|
+
- `response.json(data: any, status?: number): ResponseObject` – Send JSON-encoded data.
|
|
136
|
+
|
|
137
|
+
### **`response.text(content: string, status?: number)`**
|
|
138
|
+
|
|
139
|
+
Send plain UTF-8 text.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
return t.response.text("Hello World");
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Automatically sets:
|
|
146
|
+
|
|
147
|
+
* `Content-Type: text/plain; charset=utf-8`
|
|
148
|
+
|
|
149
|
+
### **`response.html(content: string, status?: number)`**
|
|
150
|
+
|
|
151
|
+
Send an HTML document.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
return t.response.html("<h1>Hello</h1>");
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Automatically sets:
|
|
158
|
+
|
|
159
|
+
* `Content-Type: text/html; charset=utf-8`
|
|
160
|
+
|
|
161
|
+
### **`response.json(data: any, status?: number)`**
|
|
162
|
+
|
|
163
|
+
Send JSON from a JavaScript object.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
return t.response.json({ ok: true });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Automatically sets:
|
|
170
|
+
|
|
171
|
+
* `Content-Type: application/json`
|
|
172
|
+
|
|
173
|
+
JSON serialization:
|
|
174
|
+
|
|
175
|
+
* Objects, arrays, primitives, and nested structures are supported.
|
|
176
|
+
|
|
177
|
+
### **ResponseObject**
|
|
178
|
+
|
|
179
|
+
Standard structure returned by all response methods:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
{
|
|
183
|
+
type: "response",
|
|
184
|
+
status: number,
|
|
185
|
+
headers: { [key: string]: string },
|
|
186
|
+
body: string
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### **Examples**
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// Text
|
|
194
|
+
t.response.text("pong");
|
|
195
|
+
|
|
196
|
+
// HTML
|
|
197
|
+
t.response.html("<h1>Welcome</h1>");
|
|
198
|
+
|
|
199
|
+
// JSON
|
|
200
|
+
t.response.json({ version: "1.0.0" });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
|
|
125
204
|
## Native Bindings
|
|
126
205
|
This extension includes native Rust bindings for high-performance operations. The native library is automatically loaded by the Titan Runtime.
|
|
127
206
|
|
package/configure.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { readFileSync, existsSync, writeFileSync } from 'fs';
|
|
2
|
-
import { resolve, dirname } from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { platform as _platform } from 'os';
|
|
5
|
-
import { spawnSync } from 'child_process';
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
const platform = _platform();
|
|
10
|
-
const titanConfigPath = resolve(__dirname, 'titan.json');
|
|
11
|
-
|
|
12
|
-
console.log(`Configuring titan.json for platform: ${platform}`);
|
|
13
|
-
|
|
14
|
-
// 1. Platform-specific output file name
|
|
15
|
-
let libFile = "";
|
|
16
|
-
if (platform === "win32") {
|
|
17
|
-
libFile = "titan_core.dll";
|
|
18
|
-
} else if (platform === "darwin") {
|
|
19
|
-
libFile = "libtitan_core.dylib";
|
|
20
|
-
} else {
|
|
21
|
-
libFile = "libtitan_core.so";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const nativeDir = resolve(__dirname, "native");
|
|
25
|
-
const expectedBinary = resolve(nativeDir, "target/release", libFile);
|
|
26
|
-
|
|
27
|
-
// 2. Build if binary missing
|
|
28
|
-
if (!existsSync(expectedBinary)) {
|
|
29
|
-
console.log(`Native binary missing.`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 3. Update titan.json
|
|
33
|
-
try {
|
|
34
|
-
const content = readFileSync(titanConfigPath, "utf8");
|
|
35
|
-
const titanConfig = JSON.parse(content);
|
|
36
|
-
|
|
37
|
-
const relativeLibPath = `native/target/release/${libFile}`;
|
|
38
|
-
|
|
39
|
-
if (!titanConfig.native) {
|
|
40
|
-
titanConfig.native = {};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
titanConfig.native.path = relativeLibPath;
|
|
44
|
-
|
|
45
|
-
writeFileSync(titanConfigPath, JSON.stringify(titanConfig, null, 2));
|
|
46
|
-
console.log(`Updated titan.json to use native binary: ${relativeLibPath}`);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error("Error updating titan.json:", error);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
1
|
+
import { readFileSync, existsSync, writeFileSync } from 'fs';
|
|
2
|
+
import { resolve, dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { platform as _platform } from 'os';
|
|
5
|
+
import { spawnSync } from 'child_process';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const platform = _platform();
|
|
10
|
+
const titanConfigPath = resolve(__dirname, 'titan.json');
|
|
11
|
+
|
|
12
|
+
console.log(`Configuring titan.json for platform: ${platform}`);
|
|
13
|
+
|
|
14
|
+
// 1. Platform-specific output file name
|
|
15
|
+
let libFile = "";
|
|
16
|
+
if (platform === "win32") {
|
|
17
|
+
libFile = "titan_core.dll";
|
|
18
|
+
} else if (platform === "darwin") {
|
|
19
|
+
libFile = "libtitan_core.dylib";
|
|
20
|
+
} else {
|
|
21
|
+
libFile = "libtitan_core.so";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const nativeDir = resolve(__dirname, "native");
|
|
25
|
+
const expectedBinary = resolve(nativeDir, "target/release", libFile);
|
|
26
|
+
|
|
27
|
+
// 2. Build if binary missing
|
|
28
|
+
if (!existsSync(expectedBinary)) {
|
|
29
|
+
console.log(`Native binary missing.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 3. Update titan.json
|
|
33
|
+
try {
|
|
34
|
+
const content = readFileSync(titanConfigPath, "utf8");
|
|
35
|
+
const titanConfig = JSON.parse(content);
|
|
36
|
+
|
|
37
|
+
const relativeLibPath = `native/target/release/${libFile}`;
|
|
38
|
+
|
|
39
|
+
if (!titanConfig.native) {
|
|
40
|
+
titanConfig.native = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
titanConfig.native.path = relativeLibPath;
|
|
44
|
+
|
|
45
|
+
writeFileSync(titanConfigPath, JSON.stringify(titanConfig, null, 2));
|
|
46
|
+
console.log(`Updated titan.json to use native binary: ${relativeLibPath}`);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("Error updating titan.json:", error);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
package/globals.d.ts
CHANGED