titanpl 6.0.0 → 7.0.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.
Files changed (227) hide show
  1. package/package.json +2 -6
  2. package/packages/cli/index.js +25 -11
  3. package/packages/cli/package.json +4 -4
  4. package/packages/cli/src/commands/build-ext.js +157 -0
  5. package/packages/cli/src/commands/build.js +12 -0
  6. package/packages/cli/src/commands/create.js +160 -0
  7. package/packages/cli/src/commands/init.js +5 -11
  8. package/packages/cli/src/commands/run-ext.js +104 -0
  9. package/{titanpl-sdk → packages/core-source}/LICENSE +1 -1
  10. package/packages/core-source/README.md +128 -0
  11. package/packages/core-source/V8_SERIALIZATION.md +125 -0
  12. package/packages/core-source/configure.js +50 -0
  13. package/packages/core-source/globals.d.ts +2238 -0
  14. package/packages/core-source/index.d.ts +515 -0
  15. package/packages/core-source/index.js +639 -0
  16. package/packages/core-source/jsconfig.json +12 -0
  17. package/packages/core-source/mkctx.config.json +7 -0
  18. package/packages/core-source/native/Cargo.lock +1559 -0
  19. package/packages/core-source/native/Cargo.toml +30 -0
  20. package/packages/core-source/native/src/crypto_impl.rs +139 -0
  21. package/packages/core-source/native/src/lib.rs +702 -0
  22. package/packages/core-source/native/src/storage_impl.rs +73 -0
  23. package/packages/core-source/native/src/v8_impl.rs +93 -0
  24. package/packages/core-source/package-lock.json +1464 -0
  25. package/packages/core-source/package.json +53 -0
  26. package/packages/core-source/tests/buffer.test.js +78 -0
  27. package/packages/core-source/tests/cookies.test.js +117 -0
  28. package/packages/core-source/tests/crypto.test.js +142 -0
  29. package/packages/core-source/tests/fs.test.js +176 -0
  30. package/packages/core-source/tests/ls.test.js +149 -0
  31. package/packages/core-source/tests/net.test.js +84 -0
  32. package/packages/core-source/tests/os.test.js +81 -0
  33. package/packages/core-source/tests/path.test.js +102 -0
  34. package/packages/core-source/tests/response.test.js +146 -0
  35. package/packages/core-source/tests/session.test.js +110 -0
  36. package/packages/core-source/tests/setup.js +325 -0
  37. package/packages/core-source/tests/time.test.js +57 -0
  38. package/packages/core-source/tests/url.test.js +82 -0
  39. package/packages/core-source/titan-ext.d.ts +2 -0
  40. package/packages/core-source/titan.json +9 -0
  41. package/packages/core-source/vitest.config.js +8 -0
  42. package/packages/engine-darwin-arm64/README.md +0 -2
  43. package/packages/engine-darwin-arm64/package.json +1 -1
  44. package/packages/engine-linux-x64/README.md +0 -2
  45. package/packages/engine-linux-x64/package.json +1 -1
  46. package/packages/engine-win32-x64/README.md +0 -1
  47. package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
  48. package/packages/engine-win32-x64/package.json +1 -1
  49. package/packages/native/README.md +0 -1
  50. package/packages/native/index.d.ts +25 -4
  51. package/packages/native/index.js +7 -0
  52. package/packages/native/package.json +2 -2
  53. package/packages/native/t.native.d.ts +167 -2
  54. package/packages/packet/index.js +103 -94
  55. package/packages/packet/package.json +1 -1
  56. package/packages/route/package.json +1 -1
  57. package/packages/sdk/index.js +2 -0
  58. package/packages/sdk/package.json +18 -0
  59. package/packages/sdk/test/index.js +120 -0
  60. package/templates/common/_tanfig.json +19 -13
  61. package/templates/extension/index.d.ts +26 -22
  62. package/templates/extension/index.js +15 -15
  63. package/templates/extension/native/Cargo.toml +5 -3
  64. package/templates/extension/native/src/lib.rs +2 -3
  65. package/templates/extension/package.json +10 -20
  66. package/templates/extension/titan.json +5 -16
  67. package/templates/extension/utils/registerExtension.js +44 -0
  68. package/templates/js/package.json +8 -8
  69. package/templates/rust-js/package.json +5 -5
  70. package/templates/rust-ts/package.json +5 -5
  71. package/templates/ts/package.json +8 -8
  72. package/packages/packet/node_modules/typescript/LICENSE.txt +0 -55
  73. package/packages/packet/node_modules/typescript/README.md +0 -50
  74. package/packages/packet/node_modules/typescript/SECURITY.md +0 -41
  75. package/packages/packet/node_modules/typescript/ThirdPartyNoticeText.txt +0 -193
  76. package/packages/packet/node_modules/typescript/bin/tsc +0 -2
  77. package/packages/packet/node_modules/typescript/bin/tsserver +0 -2
  78. package/packages/packet/node_modules/typescript/lib/_tsc.js +0 -133818
  79. package/packages/packet/node_modules/typescript/lib/_tsserver.js +0 -659
  80. package/packages/packet/node_modules/typescript/lib/_typingsInstaller.js +0 -222
  81. package/packages/packet/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +0 -2122
  82. package/packages/packet/node_modules/typescript/lib/de/diagnosticMessages.generated.json +0 -2122
  83. package/packages/packet/node_modules/typescript/lib/es/diagnosticMessages.generated.json +0 -2122
  84. package/packages/packet/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +0 -2122
  85. package/packages/packet/node_modules/typescript/lib/it/diagnosticMessages.generated.json +0 -2122
  86. package/packages/packet/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +0 -2122
  87. package/packages/packet/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +0 -2122
  88. package/packages/packet/node_modules/typescript/lib/lib.d.ts +0 -22
  89. package/packages/packet/node_modules/typescript/lib/lib.decorators.d.ts +0 -384
  90. package/packages/packet/node_modules/typescript/lib/lib.decorators.legacy.d.ts +0 -22
  91. package/packages/packet/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +0 -41
  92. package/packages/packet/node_modules/typescript/lib/lib.dom.d.ts +0 -39429
  93. package/packages/packet/node_modules/typescript/lib/lib.dom.iterable.d.ts +0 -571
  94. package/packages/packet/node_modules/typescript/lib/lib.es2015.collection.d.ts +0 -147
  95. package/packages/packet/node_modules/typescript/lib/lib.es2015.core.d.ts +0 -597
  96. package/packages/packet/node_modules/typescript/lib/lib.es2015.d.ts +0 -28
  97. package/packages/packet/node_modules/typescript/lib/lib.es2015.generator.d.ts +0 -77
  98. package/packages/packet/node_modules/typescript/lib/lib.es2015.iterable.d.ts +0 -605
  99. package/packages/packet/node_modules/typescript/lib/lib.es2015.promise.d.ts +0 -81
  100. package/packages/packet/node_modules/typescript/lib/lib.es2015.proxy.d.ts +0 -128
  101. package/packages/packet/node_modules/typescript/lib/lib.es2015.reflect.d.ts +0 -144
  102. package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.d.ts +0 -46
  103. package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -326
  104. package/packages/packet/node_modules/typescript/lib/lib.es2016.array.include.d.ts +0 -116
  105. package/packages/packet/node_modules/typescript/lib/lib.es2016.d.ts +0 -21
  106. package/packages/packet/node_modules/typescript/lib/lib.es2016.full.d.ts +0 -23
  107. package/packages/packet/node_modules/typescript/lib/lib.es2016.intl.d.ts +0 -31
  108. package/packages/packet/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +0 -21
  109. package/packages/packet/node_modules/typescript/lib/lib.es2017.d.ts +0 -26
  110. package/packages/packet/node_modules/typescript/lib/lib.es2017.date.d.ts +0 -31
  111. package/packages/packet/node_modules/typescript/lib/lib.es2017.full.d.ts +0 -23
  112. package/packages/packet/node_modules/typescript/lib/lib.es2017.intl.d.ts +0 -44
  113. package/packages/packet/node_modules/typescript/lib/lib.es2017.object.d.ts +0 -49
  114. package/packages/packet/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +0 -135
  115. package/packages/packet/node_modules/typescript/lib/lib.es2017.string.d.ts +0 -45
  116. package/packages/packet/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +0 -53
  117. package/packages/packet/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -77
  118. package/packages/packet/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +0 -53
  119. package/packages/packet/node_modules/typescript/lib/lib.es2018.d.ts +0 -24
  120. package/packages/packet/node_modules/typescript/lib/lib.es2018.full.d.ts +0 -24
  121. package/packages/packet/node_modules/typescript/lib/lib.es2018.intl.d.ts +0 -83
  122. package/packages/packet/node_modules/typescript/lib/lib.es2018.promise.d.ts +0 -30
  123. package/packages/packet/node_modules/typescript/lib/lib.es2018.regexp.d.ts +0 -37
  124. package/packages/packet/node_modules/typescript/lib/lib.es2019.array.d.ts +0 -79
  125. package/packages/packet/node_modules/typescript/lib/lib.es2019.d.ts +0 -24
  126. package/packages/packet/node_modules/typescript/lib/lib.es2019.full.d.ts +0 -24
  127. package/packages/packet/node_modules/typescript/lib/lib.es2019.intl.d.ts +0 -23
  128. package/packages/packet/node_modules/typescript/lib/lib.es2019.object.d.ts +0 -33
  129. package/packages/packet/node_modules/typescript/lib/lib.es2019.string.d.ts +0 -37
  130. package/packages/packet/node_modules/typescript/lib/lib.es2019.symbol.d.ts +0 -24
  131. package/packages/packet/node_modules/typescript/lib/lib.es2020.bigint.d.ts +0 -765
  132. package/packages/packet/node_modules/typescript/lib/lib.es2020.d.ts +0 -27
  133. package/packages/packet/node_modules/typescript/lib/lib.es2020.date.d.ts +0 -42
  134. package/packages/packet/node_modules/typescript/lib/lib.es2020.full.d.ts +0 -24
  135. package/packages/packet/node_modules/typescript/lib/lib.es2020.intl.d.ts +0 -474
  136. package/packages/packet/node_modules/typescript/lib/lib.es2020.number.d.ts +0 -28
  137. package/packages/packet/node_modules/typescript/lib/lib.es2020.promise.d.ts +0 -47
  138. package/packages/packet/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +0 -99
  139. package/packages/packet/node_modules/typescript/lib/lib.es2020.string.d.ts +0 -44
  140. package/packages/packet/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -41
  141. package/packages/packet/node_modules/typescript/lib/lib.es2021.d.ts +0 -23
  142. package/packages/packet/node_modules/typescript/lib/lib.es2021.full.d.ts +0 -24
  143. package/packages/packet/node_modules/typescript/lib/lib.es2021.intl.d.ts +0 -166
  144. package/packages/packet/node_modules/typescript/lib/lib.es2021.promise.d.ts +0 -48
  145. package/packages/packet/node_modules/typescript/lib/lib.es2021.string.d.ts +0 -33
  146. package/packages/packet/node_modules/typescript/lib/lib.es2021.weakref.d.ts +0 -78
  147. package/packages/packet/node_modules/typescript/lib/lib.es2022.array.d.ts +0 -121
  148. package/packages/packet/node_modules/typescript/lib/lib.es2022.d.ts +0 -25
  149. package/packages/packet/node_modules/typescript/lib/lib.es2022.error.d.ts +0 -75
  150. package/packages/packet/node_modules/typescript/lib/lib.es2022.full.d.ts +0 -24
  151. package/packages/packet/node_modules/typescript/lib/lib.es2022.intl.d.ts +0 -145
  152. package/packages/packet/node_modules/typescript/lib/lib.es2022.object.d.ts +0 -26
  153. package/packages/packet/node_modules/typescript/lib/lib.es2022.regexp.d.ts +0 -39
  154. package/packages/packet/node_modules/typescript/lib/lib.es2022.string.d.ts +0 -25
  155. package/packages/packet/node_modules/typescript/lib/lib.es2023.array.d.ts +0 -924
  156. package/packages/packet/node_modules/typescript/lib/lib.es2023.collection.d.ts +0 -21
  157. package/packages/packet/node_modules/typescript/lib/lib.es2023.d.ts +0 -22
  158. package/packages/packet/node_modules/typescript/lib/lib.es2023.full.d.ts +0 -24
  159. package/packages/packet/node_modules/typescript/lib/lib.es2023.intl.d.ts +0 -56
  160. package/packages/packet/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +0 -65
  161. package/packages/packet/node_modules/typescript/lib/lib.es2024.collection.d.ts +0 -29
  162. package/packages/packet/node_modules/typescript/lib/lib.es2024.d.ts +0 -26
  163. package/packages/packet/node_modules/typescript/lib/lib.es2024.full.d.ts +0 -24
  164. package/packages/packet/node_modules/typescript/lib/lib.es2024.object.d.ts +0 -29
  165. package/packages/packet/node_modules/typescript/lib/lib.es2024.promise.d.ts +0 -35
  166. package/packages/packet/node_modules/typescript/lib/lib.es2024.regexp.d.ts +0 -25
  167. package/packages/packet/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +0 -68
  168. package/packages/packet/node_modules/typescript/lib/lib.es2024.string.d.ts +0 -29
  169. package/packages/packet/node_modules/typescript/lib/lib.es5.d.ts +0 -4601
  170. package/packages/packet/node_modules/typescript/lib/lib.es6.d.ts +0 -23
  171. package/packages/packet/node_modules/typescript/lib/lib.esnext.array.d.ts +0 -35
  172. package/packages/packet/node_modules/typescript/lib/lib.esnext.collection.d.ts +0 -96
  173. package/packages/packet/node_modules/typescript/lib/lib.esnext.d.ts +0 -29
  174. package/packages/packet/node_modules/typescript/lib/lib.esnext.decorators.d.ts +0 -28
  175. package/packages/packet/node_modules/typescript/lib/lib.esnext.disposable.d.ts +0 -193
  176. package/packages/packet/node_modules/typescript/lib/lib.esnext.error.d.ts +0 -24
  177. package/packages/packet/node_modules/typescript/lib/lib.esnext.float16.d.ts +0 -445
  178. package/packages/packet/node_modules/typescript/lib/lib.esnext.full.d.ts +0 -24
  179. package/packages/packet/node_modules/typescript/lib/lib.esnext.intl.d.ts +0 -21
  180. package/packages/packet/node_modules/typescript/lib/lib.esnext.iterator.d.ts +0 -148
  181. package/packages/packet/node_modules/typescript/lib/lib.esnext.promise.d.ts +0 -34
  182. package/packages/packet/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +0 -25
  183. package/packages/packet/node_modules/typescript/lib/lib.scripthost.d.ts +0 -322
  184. package/packages/packet/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +0 -41
  185. package/packages/packet/node_modules/typescript/lib/lib.webworker.d.ts +0 -13150
  186. package/packages/packet/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +0 -23
  187. package/packages/packet/node_modules/typescript/lib/lib.webworker.iterable.d.ts +0 -340
  188. package/packages/packet/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +0 -2122
  189. package/packages/packet/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +0 -2122
  190. package/packages/packet/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +0 -2122
  191. package/packages/packet/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +0 -2122
  192. package/packages/packet/node_modules/typescript/lib/tsc.js +0 -8
  193. package/packages/packet/node_modules/typescript/lib/tsserver.js +0 -8
  194. package/packages/packet/node_modules/typescript/lib/tsserverlibrary.d.ts +0 -17
  195. package/packages/packet/node_modules/typescript/lib/tsserverlibrary.js +0 -21
  196. package/packages/packet/node_modules/typescript/lib/typesMap.json +0 -497
  197. package/packages/packet/node_modules/typescript/lib/typescript.d.ts +0 -11437
  198. package/packages/packet/node_modules/typescript/lib/typescript.js +0 -200276
  199. package/packages/packet/node_modules/typescript/lib/typingsInstaller.js +0 -8
  200. package/packages/packet/node_modules/typescript/lib/watchGuard.js +0 -53
  201. package/packages/packet/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -2122
  202. package/packages/packet/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -2122
  203. package/packages/packet/node_modules/typescript/package.json +0 -120
  204. package/titanpl-sdk/README.md +0 -111
  205. package/titanpl-sdk/assets/titanpl-sdk.png +0 -0
  206. package/titanpl-sdk/bin/run.js +0 -274
  207. package/titanpl-sdk/index.js +0 -5
  208. package/titanpl-sdk/package-lock.json +0 -28
  209. package/titanpl-sdk/package.json +0 -40
  210. package/titanpl-sdk/templates/app/actions/hello.js +0 -5
  211. package/titanpl-sdk/templates/app/app.js +0 -7
  212. package/titanpl-sdk/templates/jsconfig.json +0 -19
  213. package/titanpl-sdk/templates/server/Cargo.toml +0 -52
  214. package/titanpl-sdk/templates/server/src/action_management.rs +0 -175
  215. package/titanpl-sdk/templates/server/src/errors.rs +0 -12
  216. package/titanpl-sdk/templates/server/src/extensions/builtin.rs +0 -1060
  217. package/titanpl-sdk/templates/server/src/extensions/external.rs +0 -338
  218. package/titanpl-sdk/templates/server/src/extensions/mod.rs +0 -580
  219. package/titanpl-sdk/templates/server/src/extensions/titan_core.js +0 -249
  220. package/titanpl-sdk/templates/server/src/fast_path.rs +0 -719
  221. package/titanpl-sdk/templates/server/src/main.rs +0 -607
  222. package/titanpl-sdk/templates/server/src/runtime.rs +0 -284
  223. package/titanpl-sdk/templates/server/src/utils.rs +0 -33
  224. package/titanpl-sdk/templates/titan/bundle.js +0 -259
  225. package/titanpl-sdk/templates/titan/dev.js +0 -390
  226. package/titanpl-sdk/templates/titan/error-box.js +0 -277
  227. package/titanpl-sdk/templates/titan/titan.js +0 -129
@@ -0,0 +1,639 @@
1
+ const b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2
+
3
+ function local_btoa(input) {
4
+ let str = String(input);
5
+ let output = '';
6
+
7
+ for (let i = 0; i < str.length; i += 3) {
8
+ const char1 = str.charCodeAt(i);
9
+ const char2 = str.charCodeAt(i + 1);
10
+ const char3 = str.charCodeAt(i + 2);
11
+
12
+ const enc1 = char1 >> 2;
13
+ const enc2 = ((char1 & 3) << 4) | (char2 >> 4);
14
+ let enc3 = ((char2 & 15) << 2) | (char3 >> 6);
15
+ let enc4 = char3 & 63;
16
+
17
+ if (isNaN(char2)) {
18
+ enc3 = enc4 = 64;
19
+ } else if (isNaN(char3)) {
20
+ enc4 = 64;
21
+ }
22
+
23
+ output += b64chars.charAt(enc1) + b64chars.charAt(enc2);
24
+ output += (enc3 === 64) ? '=' : b64chars.charAt(enc3);
25
+ output += (enc4 === 64) ? '=' : b64chars.charAt(enc4);
26
+ }
27
+
28
+ return output;
29
+ }
30
+
31
+ function local_atob(input) {
32
+ // Remove whitespace and padding '='
33
+ let str = String(input).replace(/[\t\n\f\r =]/g, "");
34
+ let output = '';
35
+
36
+ for (let i = 0; i < str.length; i += 4) {
37
+ const c1Str = str.charAt(i);
38
+ const c2Str = str.charAt(i + 1);
39
+ const c3Str = str.charAt(i + 2);
40
+ const c4Str = str.charAt(i + 3);
41
+
42
+ const e1 = b64chars.indexOf(c1Str);
43
+ const e2 = c2Str ? b64chars.indexOf(c2Str) : -1;
44
+ const e3 = c3Str ? b64chars.indexOf(c3Str) : -1;
45
+ const e4 = c4Str ? b64chars.indexOf(c4Str) : -1;
46
+
47
+ // e1 and e2 are required
48
+ if (e1 < 0 || e2 < 0) continue;
49
+
50
+ // Shift and mask to reconstruct bytes
51
+ const c1 = (e1 << 2) | (e2 >> 4);
52
+ output += String.fromCharCode(c1);
53
+
54
+ if (e3 !== -1) {
55
+ const c2 = ((e2 & 15) << 4) | (e3 >> 2);
56
+ output += String.fromCharCode(c2);
57
+ }
58
+ if (e4 !== -1) {
59
+ const c3 = ((e3 & 3) << 6) | e4;
60
+ output += String.fromCharCode(c3);
61
+ }
62
+ }
63
+
64
+ return output;
65
+ }
66
+
67
+ function local_utf8_encode(str) {
68
+ let result = [];
69
+ for (let i = 0; i < str.length; i++) {
70
+ let c = str.charCodeAt(i);
71
+ if (c < 0x80) { result.push(c); }
72
+ else if (c < 0x800) {
73
+ result.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
74
+ }
75
+ else if (c < 0xd800 || c >= 0xe000) {
76
+ result.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
77
+ }
78
+ else {
79
+ i++;
80
+ c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
81
+ result.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 0x3f), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
82
+ }
83
+ }
84
+ return new Uint8Array(result);
85
+ }
86
+
87
+ function local_utf8_decode(bytes) {
88
+ let str = "";
89
+ let i = 0;
90
+ while (i < bytes.length) {
91
+ let c = bytes[i++];
92
+ if (c > 127) {
93
+ if (c > 191 && c < 224) {
94
+ c = ((c & 31) << 6) | (bytes[i++] & 63);
95
+ } else if (c > 223 && c < 240) {
96
+ c = ((c & 15) << 12) | ((bytes[i++] & 63) << 6) | (bytes[i++] & 63);
97
+ } else if (c > 239 && c < 248) {
98
+ c = ((c & 7) << 18) | ((bytes[i++] & 63) << 12) | ((bytes[i++] & 63) << 6) | (bytes[i++] & 63);
99
+ }
100
+ }
101
+ if (c <= 0xffff) str += String.fromCharCode(c);
102
+ else if (c <= 0x10ffff) {
103
+ c -= 0x10000;
104
+ str += String.fromCharCode(c >> 10 | 0xd800) + String.fromCharCode(c & 0x3ff | 0xdc00);
105
+ }
106
+ }
107
+ return str;
108
+ }
109
+
110
+
111
+ // Native bindings are loaded by the runtime into t["@titanpl/core"]
112
+ const natives = t["@titanpl/core"] || {};
113
+
114
+ // --- FS ---
115
+ /** File System module */
116
+ const fs = {
117
+ /** Reads file content as string. Supports options: { encoding: 'utf8' } or encoding name string. */
118
+ readFile: (path, options) => {
119
+ const encoding = typeof options === 'string' ? options : (options && options.encoding);
120
+ const res = natives.fs_read_file(path);
121
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res);
122
+ return res;
123
+ },
124
+ /** Writes content to file */
125
+ writeFile: (path, content) => {
126
+ const res = natives.fs_write_file(path, content);
127
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res);
128
+ },
129
+ /** Reads directory contents */
130
+ readdir: (path) => {
131
+ const res = natives.fs_readdir(path);
132
+ try {
133
+ return typeof res === 'string' ? JSON.parse(res) : res;
134
+ } catch (e) {
135
+ return [];
136
+ }
137
+ },
138
+ /** Creates direction recursively */
139
+ mkdir: (path) => {
140
+ const res = natives.fs_mkdir(path);
141
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res);
142
+ },
143
+ /** Checks if path exists */
144
+ exists: (path) => {
145
+ return natives.fs_exists(path);
146
+ },
147
+ /** Returns file stats */
148
+ stat: (path) => {
149
+ const res = natives.fs_stat(path);
150
+ try {
151
+ return typeof res === 'string' ? JSON.parse(res) : res;
152
+ } catch (e) {
153
+ return {};
154
+ }
155
+ },
156
+ /** Removes file or directory */
157
+ remove: (path) => {
158
+ const res = natives.fs_remove(path);
159
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res);
160
+ }
161
+ };
162
+
163
+ // --- Path ---
164
+ /** Path manipulation module */
165
+ const path = {
166
+ join: (...args) => {
167
+ return args
168
+ .map((part, i) => {
169
+ if (!part) return '';
170
+ let p = part.replace(/\\/g, '/');
171
+ if (i === 0) return p.trim().replace(/[\/]*$/g, '');
172
+ return p.trim().replace(/(^[\/]*|[\/]*$)/g, '');
173
+ })
174
+ .filter(x => x.length)
175
+ .join('/');
176
+ },
177
+ resolve: (...args) => {
178
+ let resolved = '';
179
+ for (let arg of args) {
180
+ resolved = path.join(resolved, arg);
181
+ }
182
+ if (!resolved.startsWith('/')) {
183
+ const isWindowsAbs = /^[a-zA-Z]:\\/.test(resolved) || resolved.startsWith('\\');
184
+ if (!isWindowsAbs && natives.path_cwd) {
185
+ const cwd = natives.path_cwd();
186
+ if (cwd) {
187
+ resolved = path.join(cwd, resolved);
188
+ }
189
+ }
190
+ }
191
+ return resolved;
192
+ },
193
+ extname: (p) => {
194
+ const parts = p.split('.');
195
+ return parts.length > 1 && !p.startsWith('.') ? '.' + parts.pop() : '';
196
+ },
197
+ dirname: (p) => {
198
+ const parts = p.split('/');
199
+ parts.pop();
200
+ return parts.join('/') || '.';
201
+ },
202
+ basename: (p) => p.split('/').pop()
203
+ };
204
+
205
+ // --- Crypto ---
206
+ /** Cryptography module */
207
+ const crypto = {
208
+ hash: (algo, data) => natives.crypto_hash ? natives.crypto_hash(algo, data) : "",
209
+ randomBytes: (size) => natives.crypto_random_bytes ? natives.crypto_random_bytes(size) : "",
210
+ uuid: () => natives.crypto_uuid ? natives.crypto_uuid() : "",
211
+ base64: {
212
+ encode: (str) => local_btoa(str),
213
+ decode: (str) => local_atob(str),
214
+ },
215
+ // Extended API
216
+ /** Encrypts data using AES-256-GCM. Returns Base64 string. */
217
+ encrypt: (algorithm, key, plaintext) => {
218
+ const res = natives.crypto_encrypt(algorithm, JSON.stringify({ key, plaintext }));
219
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res.substring(6));
220
+ return res;
221
+ },
222
+ /** Decrypts data using AES-256-GCM. Returns plaintext string. */
223
+ decrypt: (algorithm, key, ciphertext) => {
224
+ const res = natives.crypto_decrypt(algorithm, JSON.stringify({ key, ciphertext }));
225
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res.substring(6));
226
+ return res;
227
+ },
228
+ /** Computes HMAC-SHA256/512. Returns Hex string. */
229
+ hashKeyed: (algorithm, key, message) => {
230
+ const res = natives.crypto_hash_keyed(algorithm, JSON.stringify({ key, message }));
231
+ if (res && typeof res === 'string' && res.startsWith("ERROR:")) throw new Error(res.substring(6));
232
+ return res;
233
+ },
234
+ /** Constant-time string comparison */
235
+ compare: (a, b) => {
236
+ if (natives.crypto_compare) return natives.crypto_compare(a, b);
237
+ // Fallback insecure
238
+ if (a.length !== b.length) return false;
239
+ let mismatch = 0;
240
+ for (let i = 0; i < a.length; ++i) {
241
+ mismatch |= (a.charCodeAt(i) ^ b.charCodeAt(i));
242
+ }
243
+ return mismatch === 0;
244
+ }
245
+ };
246
+
247
+ // --- Buffer ---
248
+ // Helper for hex
249
+ function hexToBytes(hex) {
250
+ const bytes = new Uint8Array(hex.length / 2);
251
+ for (let i = 0; i < bytes.length; i++) {
252
+ bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
253
+ }
254
+ return bytes;
255
+ }
256
+ function bytesToHex(bytes) {
257
+ return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
258
+ }
259
+
260
+ /** Buffer utility module */
261
+ const buffer = {
262
+ /** Creates Uint8Array from Base64 string */
263
+ fromBase64: (str) => {
264
+ const binary = local_atob(str);
265
+ const bytes = new Uint8Array(binary.length);
266
+ for (let i = 0; i < binary.length; i++) {
267
+ bytes[i] = binary.charCodeAt(i);
268
+ }
269
+ return bytes;
270
+ },
271
+ /** encoded Uint8Array or String to Base64 string */
272
+ toBase64: (bytes) => {
273
+ let binary = '';
274
+ if (typeof bytes === 'string') {
275
+ return local_btoa(bytes);
276
+ }
277
+ // Uint8Array
278
+ const len = bytes.byteLength;
279
+ for (let i = 0; i < len; i++) {
280
+ binary += String.fromCharCode(bytes[i]);
281
+ }
282
+ return local_btoa(binary);
283
+ },
284
+ /** Creates Uint8Array from Hex string */
285
+ fromHex: (str) => hexToBytes(str),
286
+ /** Encodes bytes to Hex string */
287
+ toHex: (bytes) => {
288
+ if (typeof bytes === 'string') {
289
+ return bytesToHex(local_utf8_encode(bytes));
290
+ }
291
+ return bytesToHex(bytes);
292
+ },
293
+ /** Creates Uint8Array from UTF-8 string */
294
+ fromUtf8: (str) => local_utf8_encode(str),
295
+ /** Decodes bytes to UTF-8 string */
296
+ toUtf8: (bytes) => local_utf8_decode(bytes)
297
+ };
298
+
299
+ // --- Local Storage ---
300
+ /** High-performance in-memory Local Storage (backed by native RwLock<HashMap>) */
301
+ const ls = {
302
+ get: (key) => {
303
+ return natives.ls_get(key);
304
+ },
305
+ set: (key, value) => {
306
+ natives.ls_set(key, String(value));
307
+ },
308
+ remove: (key) => {
309
+ natives.ls_remove(key);
310
+ },
311
+ clear: () => {
312
+ natives.ls_clear();
313
+ },
314
+ keys: () => {
315
+ const result = natives.ls_keys();
316
+ try {
317
+ return typeof result === 'string' ? JSON.parse(result) : result;
318
+ } catch (e) {
319
+ return [];
320
+ }
321
+ },
322
+ /** Native V8 serialization - supports Map, Set, Date, Uint8Array, etc. */
323
+ serialize: (value) => {
324
+ return t.serialize ? t.serialize(value) : (natives.serialize ? natives.serialize(value) : null);
325
+ },
326
+ /** Native V8 deserialization - restores complex JS objects */
327
+ deserialize: (bytes) => {
328
+ return t.deserialize ? t.deserialize(bytes) : (natives.deserialize ? natives.deserialize(bytes) : null);
329
+ },
330
+ /** Store a complex JS object using native V8 serialization */
331
+ setObject: (key, value) => {
332
+ if (!natives.serialize) return;
333
+ const bytes = natives.serialize(value);
334
+ const base64 = buffer.toBase64(bytes);
335
+ natives.ls_set(key, base64);
336
+ },
337
+ /** Retrieve and restore a complex JS object */
338
+ getObject: (key) => {
339
+ if (!natives.deserialize) return null;
340
+ const base64 = natives.ls_get(key);
341
+ if (!base64) return null;
342
+ try {
343
+ const bytes = buffer.fromBase64(base64);
344
+ return natives.deserialize(bytes);
345
+ } catch (e) {
346
+ return null;
347
+ }
348
+ }
349
+ };
350
+
351
+ // --- Sessions ---
352
+ /** High-performance in-memory Session Management (backed by native RwLock<HashMap>) */
353
+ const session = {
354
+ get: (sessionId, key) => {
355
+ return natives.session_get(sessionId, key);
356
+ },
357
+ set: (sessionId, key, value) => {
358
+ natives.session_set(sessionId, key, String(value));
359
+ },
360
+ delete: (sessionId, key) => {
361
+ natives.session_delete(sessionId, key);
362
+ },
363
+ clear: (sessionId) => {
364
+ natives.session_clear(sessionId);
365
+ }
366
+ };
367
+
368
+
369
+ // --- Cookies ---
370
+ /** HTTP Cookie Utilities */
371
+ const cookies = {
372
+ /** Parses cookie from request headers */
373
+ get: (req, name) => {
374
+ if (!req || !req.headers) return null;
375
+ const cookieHeader = req.headers.cookie;
376
+ if (!cookieHeader) return null;
377
+ const cookies = cookieHeader.split(';');
378
+ for (let c of cookies) {
379
+ const [k, v] = c.trim().split('=');
380
+ if (k === name) return decodeURIComponent(v);
381
+ }
382
+ return null;
383
+ },
384
+ /** Sets Set-Cookie header on response */
385
+ set: (res, name, value, options = {}) => {
386
+ if (!res || !res.setHeader) return;
387
+ let cookie = `${name}=${encodeURIComponent(value)}`;
388
+ if (options.maxAge) cookie += `; Max-Age=${options.maxAge}`;
389
+ if (options.path) cookie += `; Path=${options.path}`;
390
+ if (options.httpOnly) cookie += `; HttpOnly`;
391
+ if (options.secure) cookie += `; Secure`;
392
+ if (options.sameSite) cookie += `; SameSite=${options.sameSite}`;
393
+
394
+ let prev = res.getHeader ? res.getHeader('Set-Cookie') : null;
395
+ if (prev) {
396
+ if (Array.isArray(prev)) {
397
+ prev.push(cookie);
398
+ res.setHeader('Set-Cookie', prev);
399
+ } else {
400
+ res.setHeader('Set-Cookie', [prev, cookie]);
401
+ }
402
+ } else {
403
+ res.setHeader('Set-Cookie', cookie);
404
+ }
405
+ },
406
+ /** Deletes cookie by setting maxAge=0 */
407
+ delete: (res, name) => {
408
+ cookies.set(res, name, "", { maxAge: 0, path: '/' });
409
+ }
410
+ };
411
+
412
+
413
+
414
+ // --- Response ---
415
+ /** Advanced HTTP Response Management */
416
+ const response = (options) => {
417
+ return {
418
+ _isResponse: true,
419
+ status: options.status || 200,
420
+ headers: options.headers || {},
421
+ body: options.body || ""
422
+ };
423
+ };
424
+
425
+ response.text = (content, options = {}) => {
426
+ return {
427
+ _isResponse: true,
428
+ status: options.status || 200,
429
+ headers: { "Content-Type": "text/plain", ...(options.headers || {}) },
430
+ body: content
431
+ };
432
+ };
433
+
434
+ response.html = (content, options = {}) => {
435
+ return {
436
+ _isResponse: true,
437
+ status: options.status || 200,
438
+ headers: { "Content-Type": "text/html; charset=utf-8", ...(options.headers || {}) },
439
+ body: content
440
+ };
441
+ };
442
+
443
+ response.json = (content, options = {}) => {
444
+ return {
445
+ _isResponse: true,
446
+ status: options.status || 200,
447
+ headers: { "Content-Type": "application/json", ...(options.headers || {}) },
448
+ body: JSON.stringify(content)
449
+ };
450
+ };
451
+
452
+ response.redirect = (url, status = 302) => {
453
+ return {
454
+ _isResponse: true,
455
+ status: status,
456
+ headers: { "Location": url },
457
+ body: ""
458
+ };
459
+ };
460
+
461
+ response.empty = (status = 204) => {
462
+ return {
463
+ _isResponse: true,
464
+ status: status,
465
+ headers: {},
466
+ body: ""
467
+ };
468
+ };
469
+
470
+ // --- OS ---
471
+ const os = {
472
+ platform: () => {
473
+ if (!natives.os_info) return "unknown";
474
+ const result = natives.os_info();
475
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
476
+ return info.platform;
477
+ },
478
+ cpus: () => {
479
+ if (!natives.os_info) return 1;
480
+ const result = natives.os_info();
481
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
482
+ return info.cpus;
483
+ },
484
+ totalMemory: () => {
485
+ if (!natives.os_info) return 0;
486
+ const result = natives.os_info();
487
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
488
+ return info.totalMemory;
489
+ },
490
+ freeMemory: () => {
491
+ if (!natives.os_info) return 0;
492
+ const result = natives.os_info();
493
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
494
+ return info.freeMemory;
495
+ },
496
+ tmpdir: () => {
497
+ if (!natives.os_info) return '/tmp';
498
+ try {
499
+ const result = natives.os_info();
500
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
501
+ return info.tempDir || '/tmp';
502
+ } catch (e) {
503
+ return '/tmp';
504
+ }
505
+ }
506
+ };
507
+
508
+ // --- Net ---
509
+ const net = {
510
+ resolveDNS: (hostname) => {
511
+ if (!natives.net_resolve) return [];
512
+ const result = natives.net_resolve(hostname);
513
+ return typeof result === 'string' ? JSON.parse(result) : result;
514
+ },
515
+ ip: () => natives.net_ip ? natives.net_ip() : "127.0.0.1",
516
+ ping: (host) => true
517
+ };
518
+
519
+ // --- Proc ---
520
+ const proc = {
521
+ pid: () => {
522
+ if (!natives.proc_info) return 0;
523
+ const result = natives.proc_info();
524
+ if (!result) return 0;
525
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
526
+ return info.pid;
527
+ },
528
+ uptime: () => {
529
+ if (!natives.proc_info) return 0;
530
+ const result = natives.proc_info();
531
+ if (!result) return 0;
532
+ const info = typeof result === 'string' ? JSON.parse(result) : result;
533
+ return info.uptime;
534
+ },
535
+ memory: () => ({})
536
+ };
537
+
538
+ // --- Time ---
539
+ const time = {
540
+ sleep: (ms) => {
541
+ if (natives.time_sleep) natives.time_sleep(ms);
542
+ },
543
+ now: () => Date.now(),
544
+ timestamp: () => new Date().toISOString()
545
+ };
546
+
547
+ // --- URL ---
548
+ class TitanURLSearchParams {
549
+ constructor(init = '') {
550
+ this._params = {};
551
+ if (typeof init === 'string') {
552
+ const query = init.startsWith('?') ? init.slice(1) : init;
553
+ query.split('&').forEach(pair => {
554
+ const [key, value] = pair.split('=').map(decodeURIComponent);
555
+ if (key) this._params[key] = value || '';
556
+ });
557
+ } else if (typeof init === 'object') {
558
+ Object.assign(this._params, init);
559
+ }
560
+ }
561
+ get(key) { return this._params[key] || null; }
562
+ set(key, value) { this._params[key] = String(value); }
563
+ has(key) { return key in this._params; }
564
+ delete(key) { delete this._params[key]; }
565
+ toString() {
566
+ return Object.entries(this._params)
567
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
568
+ .join('&');
569
+ }
570
+ entries() { return Object.entries(this._params); }
571
+ keys() { return Object.keys(this._params); }
572
+ values() { return Object.values(this._params); }
573
+ }
574
+
575
+ const url = {
576
+ parse: (str) => {
577
+ if (typeof URL !== 'undefined') {
578
+ return new URL(str);
579
+ }
580
+ const match = str.match(/^(https?:)\/\/([^/:]+)(?::(\d+))?(\/[^?#]*)?(\?[^#]*)?(#.*)?$/);
581
+ if (!match) throw new Error('Invalid URL');
582
+ return {
583
+ protocol: match[1],
584
+ hostname: match[2],
585
+ port: match[3] || '',
586
+ pathname: match[4] || '/',
587
+ search: match[5] || '',
588
+ hash: match[6] || ''
589
+ };
590
+ },
591
+ format: (obj) => obj.toString ? obj.toString() : String(obj),
592
+ SearchParams: TitanURLSearchParams
593
+ };
594
+
595
+ // Create the main core export object (following titan-valid pattern)
596
+ const core = {
597
+ fs,
598
+ path,
599
+ crypto,
600
+ os,
601
+ net,
602
+ proc,
603
+ time,
604
+ url,
605
+ buffer, // t.core.buffer
606
+ ls,
607
+ session,
608
+ cookies,
609
+ response
610
+ };
611
+
612
+ t.fs = fs;
613
+ t.path = path;
614
+ t.crypto = crypto;
615
+ t.os = os;
616
+ t.net = net;
617
+ t.proc = proc;
618
+ t.time = time;
619
+ t.url = url;
620
+
621
+ // New Global Modules
622
+ t.buffer = buffer;
623
+ t.ls = ls;
624
+ t.localStorage = ls;
625
+ t.session = session;
626
+ t.cookies = cookies;
627
+ t.response = response;
628
+
629
+ // Attach core as unified namespace (main access point)
630
+ t.core = core;
631
+
632
+ // Register as extension under multiple names for compatibility
633
+ t["titan-core"] = core;
634
+ t["@titanpl/core"] = core;
635
+
636
+ // Also register in t.exts
637
+ if (!t.exts) t.exts = {};
638
+ t.exts["titan-core"] = core;
639
+ t.exts["@titanpl/core"] = core;
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "CommonJS",
5
+ "allowSyntheticDefaultImports": true,
6
+ "checkJs": false
7
+ },
8
+ "exclude": [
9
+ "node_modules",
10
+ "native"
11
+ ]
12
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "src": ".",
3
+ "ignore": "mkctx.config.json, pnpm-lock.yaml, **/.titan/, mkctx/, node_modules/, .git/, dist/, build/, target/, .next/, out/, .cache, package-lock.json, *.log, temp/, tmp/, coverage/, .nyc_output, .env, .env.local, .env.development.local, .env.test.local, .env.production.local, npm-debug.log*, yarn-debug.log*, yarn-error.log*, .npm, .yarn-integrity, .parcel-cache, .vuepress/dist, .svelte-kit, **/*.rs.bk, .idea/, .vscode/, .DS_Store, Thumbs.db, *.swp, *.swo, .~lock.*, Cargo.lock, .cargo/registry/, .cargo/git/, .rustup/, *.pdb, *.dSYM/, *.so, *.dll, *.dylib, *.exe, *.lib, *.a, *.o, *.rlib, *.d, *.tmp, *.bak, *.orig, *.rej, *.pyc, *.pyo, *.class, *.jar, *.war, *.ear, *.zip, *.tar.gz, *.rar, *.7z, *.iso, *.img, *.dmg, *.pdf, *.doc, *.docx, *.xls, *.xlsx, *.ppt, *.pptx",
4
+ "output": "./mkctx",
5
+ "first_comment": "/* Project Context */",
6
+ "last_comment": "/* End of Context */"
7
+ }