@titanpl/core 2.0.8 → 2.1.0

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/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;
@@ -341,81 +344,53 @@ const buffer = {
341
344
  };
342
345
 
343
346
  // --- Local Storage ---
344
- /** Persistent Local Storage */
347
+ /** High-performance in-memory Local Storage (backed by native RwLock<HashMap>) */
345
348
  const ls = {
346
349
  get: (key) => {
347
- try {
348
- const content = fs.readFile("titan_storage.json");
349
- const db = JSON.parse(content || "{}");
350
- return db[key] || null;
351
- } catch (e) { return null; }
350
+ if (!native_ls_get) throw new Error("Native ls_get not found");
351
+ return native_ls_get(key);
352
352
  },
353
353
  set: (key, value) => {
354
- try {
355
- let db = {};
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) { }
354
+ if (!native_ls_set) throw new Error("Native ls_set not found");
355
+ native_ls_set(key, String(value));
360
356
  },
361
357
  remove: (key) => {
362
- try {
363
- let db = {};
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) { }
358
+ if (!native_ls_remove) throw new Error("Native ls_remove not found");
359
+ native_ls_remove(key);
368
360
  },
369
361
  clear: () => {
370
- try {
371
- fs.writeFile("titan_storage.json", "{}");
372
- } catch (e) { }
362
+ if (!native_ls_clear) throw new Error("Native ls_clear not found");
363
+ native_ls_clear();
373
364
  },
374
365
  keys: () => {
366
+ if (!native_ls_keys) throw new Error("Native ls_keys not found");
367
+ const result = native_ls_keys();
375
368
  try {
376
- let db = JSON.parse(fs.readFile("titan_storage.json") || "{}");
377
- return Object.keys(db);
378
- } catch (e) { return []; }
369
+ return JSON.parse(result);
370
+ } catch (e) {
371
+ return [];
372
+ }
379
373
  }
380
374
  };
381
375
 
382
376
  // --- Sessions ---
383
- /** Server-side Session Management */
377
+ /** High-performance in-memory Session Management (backed by native RwLock<HashMap>) */
384
378
  const session = {
385
379
  get: (sessionId, key) => {
386
- try {
387
- const content = fs.readFile("titan_sessions.json");
388
- const db = JSON.parse(content || "{}");
389
- const sessionData = db[sessionId] || {};
390
- return sessionData[key] || null;
391
- } catch (e) { return null; }
380
+ if (!native_session_get) throw new Error("Native session_get not found");
381
+ return native_session_get(sessionId, key);
392
382
  },
393
383
  set: (sessionId, key, value) => {
394
- try {
395
- let db = {};
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) { }
384
+ if (!native_session_set) throw new Error("Native session_set not found");
385
+ native_session_set(sessionId, key, String(value));
401
386
  },
402
387
  delete: (sessionId, key) => {
403
- try {
404
- let db = {};
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) { }
388
+ if (!native_session_delete) throw new Error("Native session_delete not found");
389
+ native_session_delete(sessionId, key);
411
390
  },
412
391
  clear: (sessionId) => {
413
- try {
414
- let db = {};
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) { }
392
+ if (!native_session_clear) throw new Error("Native session_clear not found");
393
+ native_session_clear(sessionId);
419
394
  }
420
395
  };
421
396
 
@@ -463,6 +438,64 @@ const cookies = {
463
438
  }
464
439
  };
465
440
 
441
+
442
+
443
+ // --- Response ---
444
+ /** Advanced HTTP Response Management */
445
+ const response = (options) => {
446
+ return {
447
+ _isResponse: true,
448
+ status: options.status || 200,
449
+ headers: options.headers || {},
450
+ body: options.body || ""
451
+ };
452
+ };
453
+
454
+ response.text = (content, options = {}) => {
455
+ return {
456
+ _isResponse: true,
457
+ status: options.status || 200,
458
+ headers: { "Content-Type": "text/plain", ...(options.headers || {}) },
459
+ body: content
460
+ };
461
+ };
462
+
463
+ response.html = (content, options = {}) => {
464
+ return {
465
+ _isResponse: true,
466
+ status: options.status || 200,
467
+ headers: { "Content-Type": "text/html; charset=utf-8", ...(options.headers || {}) },
468
+ body: content
469
+ };
470
+ };
471
+
472
+ response.json = (content, options = {}) => {
473
+ return {
474
+ _isResponse: true,
475
+ status: options.status || 200,
476
+ headers: { "Content-Type": "application/json", ...(options.headers || {}) },
477
+ body: JSON.stringify(content)
478
+ };
479
+ };
480
+
481
+ response.redirect = (url, status = 302) => {
482
+ return {
483
+ _isResponse: true,
484
+ status: status,
485
+ headers: { "Location": url },
486
+ body: ""
487
+ };
488
+ };
489
+
490
+ response.empty = (status = 204) => {
491
+ return {
492
+ _isResponse: true,
493
+ status: status,
494
+ headers: {},
495
+ body: ""
496
+ };
497
+ };
498
+
466
499
  // --- OS ---
467
500
  const os = {
468
501
  platform: () => {
@@ -591,7 +624,8 @@ const core = {
591
624
  buffer, // t.core.buffer
592
625
  ls,
593
626
  session,
594
- cookies
627
+ cookies,
628
+ response
595
629
  };
596
630
 
597
631
  t.fs = fs;
@@ -609,6 +643,7 @@ t.ls = ls;
609
643
  t.localStorage = ls;
610
644
  t.session = session;
611
645
  t.cookies = cookies;
646
+ t.response = response;
612
647
 
613
648
  // Attach core as unified namespace (main access point)
614
649
  t.core = core;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/core",
3
- "version": "2.0.8",
3
+ "version": "2.1.0",
4
4
  "description": "The official Core Standard Library for Titan Planet - provides fs, path, crypto, os, net, proc, time, and url modules",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/titan.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@titanpl/core",
3
3
  "description": "The official Core Standard Library for Titan Planet",
4
- "version": "2.0.7",
4
+ "version": "2.1.0",
5
5
  "main": "index.js",
6
6
  "native": {
7
7
  "path": "native/target/release/titan_core.dll",