@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/index.js
CHANGED
|
@@ -111,6 +111,9 @@ function local_utf8_decode(bytes) {
|
|
|
111
111
|
// Native bindings are loaded by the runtime into t["@titanpl/core"]
|
|
112
112
|
const natives = t["@titanpl/core"] || {};
|
|
113
113
|
|
|
114
|
+
console.log("[TitanCore] Available natives:", Object.keys(natives));
|
|
115
|
+
|
|
116
|
+
|
|
114
117
|
|
|
115
118
|
// Native Function bindings
|
|
116
119
|
const native_fs_read_file = natives.fs_read_file;
|
|
@@ -134,6 +137,9 @@ const native_os_info = natives.os_info;
|
|
|
134
137
|
const native_net_resolve = natives.net_resolve;
|
|
135
138
|
const native_net_ip = natives.net_ip;
|
|
136
139
|
const native_proc_info = natives.proc_info;
|
|
140
|
+
const native_proc_run = natives.proc_run;
|
|
141
|
+
const native_proc_kill = natives.proc_kill;
|
|
142
|
+
const native_proc_list = natives.proc_list;
|
|
137
143
|
const native_time_sleep = natives.time_sleep;
|
|
138
144
|
|
|
139
145
|
const native_ls_get = natives.ls_get;
|
|
@@ -341,81 +347,53 @@ const buffer = {
|
|
|
341
347
|
};
|
|
342
348
|
|
|
343
349
|
// --- Local Storage ---
|
|
344
|
-
/**
|
|
350
|
+
/** High-performance in-memory Local Storage (backed by native RwLock<HashMap>) */
|
|
345
351
|
const ls = {
|
|
346
352
|
get: (key) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const db = JSON.parse(content || "{}");
|
|
350
|
-
return db[key] || null;
|
|
351
|
-
} catch (e) { return null; }
|
|
353
|
+
if (!native_ls_get) throw new Error("Native ls_get not found");
|
|
354
|
+
return native_ls_get(key);
|
|
352
355
|
},
|
|
353
356
|
set: (key, value) => {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
try { db = JSON.parse(fs.readFile("titan_storage.json") || "{}"); } catch (e) { }
|
|
357
|
-
db[key] = String(value);
|
|
358
|
-
fs.writeFile("titan_storage.json", JSON.stringify(db));
|
|
359
|
-
} catch (e) { }
|
|
357
|
+
if (!native_ls_set) throw new Error("Native ls_set not found");
|
|
358
|
+
native_ls_set(key, String(value));
|
|
360
359
|
},
|
|
361
360
|
remove: (key) => {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
try { db = JSON.parse(fs.readFile("titan_storage.json") || "{}"); } catch (e) { }
|
|
365
|
-
delete db[key];
|
|
366
|
-
fs.writeFile("titan_storage.json", JSON.stringify(db));
|
|
367
|
-
} catch (e) { }
|
|
361
|
+
if (!native_ls_remove) throw new Error("Native ls_remove not found");
|
|
362
|
+
native_ls_remove(key);
|
|
368
363
|
},
|
|
369
364
|
clear: () => {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
} catch (e) { }
|
|
365
|
+
if (!native_ls_clear) throw new Error("Native ls_clear not found");
|
|
366
|
+
native_ls_clear();
|
|
373
367
|
},
|
|
374
368
|
keys: () => {
|
|
369
|
+
if (!native_ls_keys) throw new Error("Native ls_keys not found");
|
|
370
|
+
const result = native_ls_keys();
|
|
375
371
|
try {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
372
|
+
return JSON.parse(result);
|
|
373
|
+
} catch (e) {
|
|
374
|
+
return [];
|
|
375
|
+
}
|
|
379
376
|
}
|
|
380
377
|
};
|
|
381
378
|
|
|
382
379
|
// --- Sessions ---
|
|
383
|
-
/**
|
|
380
|
+
/** High-performance in-memory Session Management (backed by native RwLock<HashMap>) */
|
|
384
381
|
const session = {
|
|
385
382
|
get: (sessionId, key) => {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const db = JSON.parse(content || "{}");
|
|
389
|
-
const sessionData = db[sessionId] || {};
|
|
390
|
-
return sessionData[key] || null;
|
|
391
|
-
} catch (e) { return null; }
|
|
383
|
+
if (!native_session_get) throw new Error("Native session_get not found");
|
|
384
|
+
return native_session_get(sessionId, key);
|
|
392
385
|
},
|
|
393
386
|
set: (sessionId, key, value) => {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
try { db = JSON.parse(fs.readFile("titan_sessions.json") || "{}"); } catch (e) { }
|
|
397
|
-
if (!db[sessionId]) db[sessionId] = {};
|
|
398
|
-
db[sessionId][key] = String(value);
|
|
399
|
-
fs.writeFile("titan_sessions.json", JSON.stringify(db));
|
|
400
|
-
} catch (e) { }
|
|
387
|
+
if (!native_session_set) throw new Error("Native session_set not found");
|
|
388
|
+
native_session_set(sessionId, key, String(value));
|
|
401
389
|
},
|
|
402
390
|
delete: (sessionId, key) => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
try { db = JSON.parse(fs.readFile("titan_sessions.json") || "{}"); } catch (e) { }
|
|
406
|
-
if (db[sessionId]) {
|
|
407
|
-
delete db[sessionId][key];
|
|
408
|
-
fs.writeFile("titan_sessions.json", JSON.stringify(db));
|
|
409
|
-
}
|
|
410
|
-
} catch (e) { }
|
|
391
|
+
if (!native_session_delete) throw new Error("Native session_delete not found");
|
|
392
|
+
native_session_delete(sessionId, key);
|
|
411
393
|
},
|
|
412
394
|
clear: (sessionId) => {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
try { db = JSON.parse(fs.readFile("titan_sessions.json") || "{}"); } catch (e) { }
|
|
416
|
-
delete db[sessionId];
|
|
417
|
-
fs.writeFile("titan_sessions.json", JSON.stringify(db));
|
|
418
|
-
} catch (e) { }
|
|
395
|
+
if (!native_session_clear) throw new Error("Native session_clear not found");
|
|
396
|
+
native_session_clear(sessionId);
|
|
419
397
|
}
|
|
420
398
|
};
|
|
421
399
|
|
|
@@ -463,6 +441,64 @@ const cookies = {
|
|
|
463
441
|
}
|
|
464
442
|
};
|
|
465
443
|
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
// --- Response ---
|
|
447
|
+
/** Advanced HTTP Response Management */
|
|
448
|
+
const response = (options) => {
|
|
449
|
+
return {
|
|
450
|
+
_isResponse: true,
|
|
451
|
+
status: options.status || 200,
|
|
452
|
+
headers: options.headers || {},
|
|
453
|
+
body: options.body || ""
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
response.text = (content, options = {}) => {
|
|
458
|
+
return {
|
|
459
|
+
_isResponse: true,
|
|
460
|
+
status: options.status || 200,
|
|
461
|
+
headers: { "Content-Type": "text/plain", ...(options.headers || {}) },
|
|
462
|
+
body: content
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
response.html = (content, options = {}) => {
|
|
467
|
+
return {
|
|
468
|
+
_isResponse: true,
|
|
469
|
+
status: options.status || 200,
|
|
470
|
+
headers: { "Content-Type": "text/html; charset=utf-8", ...(options.headers || {}) },
|
|
471
|
+
body: content
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
response.json = (content, options = {}) => {
|
|
476
|
+
return {
|
|
477
|
+
_isResponse: true,
|
|
478
|
+
status: options.status || 200,
|
|
479
|
+
headers: { "Content-Type": "application/json", ...(options.headers || {}) },
|
|
480
|
+
body: JSON.stringify(content)
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
response.redirect = (url, status = 302) => {
|
|
485
|
+
return {
|
|
486
|
+
_isResponse: true,
|
|
487
|
+
status: status,
|
|
488
|
+
headers: { "Location": url },
|
|
489
|
+
body: ""
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
response.empty = (status = 204) => {
|
|
494
|
+
return {
|
|
495
|
+
_isResponse: true,
|
|
496
|
+
status: status,
|
|
497
|
+
headers: {},
|
|
498
|
+
body: ""
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
|
|
466
502
|
// --- OS ---
|
|
467
503
|
const os = {
|
|
468
504
|
platform: () => {
|
|
@@ -518,7 +554,26 @@ const proc = {
|
|
|
518
554
|
const info = JSON.parse(native_proc_info());
|
|
519
555
|
return info.uptime;
|
|
520
556
|
},
|
|
521
|
-
memory: () => ({})
|
|
557
|
+
memory: () => ({}),
|
|
558
|
+
run: (command, args = []) => {
|
|
559
|
+
if (!native_proc_run) throw new Error("Native proc_run not found");
|
|
560
|
+
const res = native_proc_run(command, JSON.stringify(args));
|
|
561
|
+
if (typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res);
|
|
562
|
+
try {
|
|
563
|
+
return JSON.parse(res);
|
|
564
|
+
} catch (e) { return {}; }
|
|
565
|
+
},
|
|
566
|
+
kill: (pid) => {
|
|
567
|
+
if (!native_proc_kill) return false;
|
|
568
|
+
return native_proc_kill(pid);
|
|
569
|
+
},
|
|
570
|
+
list: () => {
|
|
571
|
+
if (!native_proc_list) return [];
|
|
572
|
+
const res = native_proc_list();
|
|
573
|
+
try {
|
|
574
|
+
return JSON.parse(res);
|
|
575
|
+
} catch (e) { return []; }
|
|
576
|
+
}
|
|
522
577
|
};
|
|
523
578
|
|
|
524
579
|
// --- Time ---
|
|
@@ -591,7 +646,8 @@ const core = {
|
|
|
591
646
|
buffer, // t.core.buffer
|
|
592
647
|
ls,
|
|
593
648
|
session,
|
|
594
|
-
cookies
|
|
649
|
+
cookies,
|
|
650
|
+
response
|
|
595
651
|
};
|
|
596
652
|
|
|
597
653
|
t.fs = fs;
|
|
@@ -609,6 +665,7 @@ t.ls = ls;
|
|
|
609
665
|
t.localStorage = ls;
|
|
610
666
|
t.session = session;
|
|
611
667
|
t.cookies = cookies;
|
|
668
|
+
t.response = response;
|
|
612
669
|
|
|
613
670
|
// Attach core as unified namespace (main access point)
|
|
614
671
|
t.core = core;
|
|
Binary file
|
package/package.json
CHANGED
package/titan.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/core",
|
|
3
3
|
"description": "The official Core Standard Library for Titan Planet",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"native": {
|
|
7
|
-
"path": "native/target/release/
|
|
7
|
+
"path": "native/target/release/titan_core.dll",
|
|
8
8
|
"functions": {
|
|
9
9
|
"fs_read_file": {
|
|
10
10
|
"symbol": "fs_read_file",
|
|
@@ -103,6 +103,26 @@
|
|
|
103
103
|
"parameters": [],
|
|
104
104
|
"result": "string"
|
|
105
105
|
},
|
|
106
|
+
"proc_run": {
|
|
107
|
+
"symbol": "proc_run",
|
|
108
|
+
"parameters": [
|
|
109
|
+
"string",
|
|
110
|
+
"string"
|
|
111
|
+
],
|
|
112
|
+
"result": "string"
|
|
113
|
+
},
|
|
114
|
+
"proc_kill": {
|
|
115
|
+
"symbol": "proc_kill",
|
|
116
|
+
"parameters": [
|
|
117
|
+
"f64"
|
|
118
|
+
],
|
|
119
|
+
"result": "bool"
|
|
120
|
+
},
|
|
121
|
+
"proc_list": {
|
|
122
|
+
"symbol": "proc_list",
|
|
123
|
+
"parameters": [],
|
|
124
|
+
"result": "string"
|
|
125
|
+
},
|
|
106
126
|
"time_sleep": {
|
|
107
127
|
"symbol": "time_sleep",
|
|
108
128
|
"parameters": [
|
|
Binary file
|