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,325 @@
1
+ /**
2
+ * tests/setup.js
3
+ *
4
+ * Emulates Rust native functions for testing.
5
+ * Equivalent to what @t8n/micro-gravity/setup would do.
6
+ *
7
+ * MOCKED:
8
+ * - DB (PostgreSQL connection) - No way to test without a real DB
9
+ *
10
+ * EMULATED (JS implementation that simulates Rust behavior):
11
+ * - fs_* (uses Node.js fs)
12
+ * - crypto_* (uses Node.js crypto)
13
+ * - ls_* (uses in-memory Map)
14
+ * - session_* (uses in-memory Map)
15
+ * - os_*, net_*, proc_*, time_*, path_cwd
16
+ */
17
+
18
+ import { vi } from 'vitest';
19
+ import * as nodeFs from 'node:fs';
20
+ import * as nodePath from 'node:path';
21
+ import * as nodeCrypto from 'node:crypto';
22
+ import * as nodeOs from 'node:os';
23
+
24
+ // In-memory storage for ls and session
25
+ const localStorage = new Map();
26
+ const sessionStorage = new Map();
27
+
28
+ // Initialize global `t` object with native functions
29
+ globalThis.t = globalThis.t || {};
30
+ globalThis.t["@titanpl/core"] = globalThis.t["@titanpl/core"] || {};
31
+ globalThis.t.native = globalThis.t.native || {};
32
+ globalThis.t.core = globalThis.t.core || {};
33
+
34
+ const ext = globalThis.t["@titanpl/core"];
35
+
36
+ // ============================================
37
+ // FILE SYSTEM - Emulation using Node.js fs
38
+ // ============================================
39
+
40
+ ext.fs_read_file = (path) => {
41
+ try {
42
+ return nodeFs.readFileSync(path, 'utf-8');
43
+ } catch (e) {
44
+ return `ERROR: ${e.message}`;
45
+ }
46
+ };
47
+
48
+ ext.fs_write_file = (path, content) => {
49
+ nodeFs.writeFileSync(path, content, 'utf-8');
50
+ };
51
+
52
+ ext.fs_readdir = (path) => {
53
+ try {
54
+ return JSON.stringify(nodeFs.readdirSync(path));
55
+ } catch {
56
+ return '[]';
57
+ }
58
+ };
59
+
60
+ ext.fs_mkdir = (path) => {
61
+ nodeFs.mkdirSync(path, { recursive: true });
62
+ };
63
+
64
+ ext.fs_exists = (path) => {
65
+ return nodeFs.existsSync(path);
66
+ };
67
+
68
+ ext.fs_stat = (path) => {
69
+ try {
70
+ const stat = nodeFs.statSync(path);
71
+ return JSON.stringify({
72
+ size: stat.size,
73
+ isFile: stat.isFile(),
74
+ isDir: stat.isDirectory(),
75
+ modified: stat.mtimeMs
76
+ });
77
+ } catch {
78
+ return '{}';
79
+ }
80
+ };
81
+
82
+ ext.fs_remove = (path) => {
83
+ try {
84
+ const stat = nodeFs.statSync(path);
85
+ if (stat.isDirectory()) {
86
+ nodeFs.rmSync(path, { recursive: true });
87
+ } else {
88
+ nodeFs.unlinkSync(path);
89
+ }
90
+ } catch { }
91
+ };
92
+
93
+ ext.path_cwd = () => process.cwd();
94
+
95
+ // ============================================
96
+ // CRYPTO - Emulation using Node.js crypto
97
+ // ============================================
98
+
99
+ ext.crypto_hash = (algo, data) => {
100
+ try {
101
+ const hash = nodeCrypto.createHash(algo);
102
+ hash.update(data);
103
+ return hash.digest('hex');
104
+ } catch (e) {
105
+ return `ERROR: ${e.message}`;
106
+ }
107
+ };
108
+
109
+ ext.crypto_random_bytes = (size) => {
110
+ return nodeCrypto.randomBytes(size).toString('hex');
111
+ };
112
+
113
+ ext.crypto_uuid = () => {
114
+ return nodeCrypto.randomUUID();
115
+ };
116
+
117
+ ext.crypto_encrypt = (algo, jsonArgs) => {
118
+ try {
119
+ const { key, plaintext } = JSON.parse(jsonArgs);
120
+ const keyBuffer = Buffer.alloc(32);
121
+ Buffer.from(key).copy(keyBuffer);
122
+ const iv = nodeCrypto.randomBytes(12);
123
+ const cipher = nodeCrypto.createCipheriv('aes-256-gcm', keyBuffer, iv);
124
+ let encrypted = cipher.update(plaintext, 'utf8', 'hex');
125
+ encrypted += cipher.final('hex');
126
+ const authTag = cipher.getAuthTag().toString('hex');
127
+ return iv.toString('hex') + ':' + authTag + ':' + encrypted;
128
+ } catch (e) {
129
+ return `ERROR: ${e.message}`;
130
+ }
131
+ };
132
+
133
+ ext.crypto_decrypt = (algo, jsonArgs) => {
134
+ try {
135
+ const { key, ciphertext } = JSON.parse(jsonArgs);
136
+ const [ivHex, authTagHex, encrypted] = ciphertext.split(':');
137
+ const keyBuffer = Buffer.alloc(32);
138
+ Buffer.from(key).copy(keyBuffer);
139
+ const iv = Buffer.from(ivHex, 'hex');
140
+ const authTag = Buffer.from(authTagHex, 'hex');
141
+ const decipher = nodeCrypto.createDecipheriv('aes-256-gcm', keyBuffer, iv);
142
+ decipher.setAuthTag(authTag);
143
+ let decrypted = decipher.update(encrypted, 'hex', 'utf8');
144
+ decrypted += decipher.final('utf8');
145
+ return decrypted;
146
+ } catch (e) {
147
+ return `ERROR: ${e.message}`;
148
+ }
149
+ };
150
+
151
+ ext.crypto_hash_keyed = (algo, jsonArgs) => {
152
+ try {
153
+ const { key, message } = JSON.parse(jsonArgs);
154
+ const hmac = nodeCrypto.createHmac(algo === 'sha256' ? 'sha256' : 'sha512', key);
155
+ hmac.update(message);
156
+ return hmac.digest('hex');
157
+ } catch (e) {
158
+ return `ERROR: ${e.message}`;
159
+ }
160
+ };
161
+
162
+ ext.crypto_compare = (a, b) => {
163
+ return nodeCrypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
164
+ };
165
+
166
+ // ============================================
167
+ // LOCAL STORAGE - In-memory emulation
168
+ // ============================================
169
+
170
+ ext.ls_get = (key) => {
171
+ return localStorage.get(key) || '';
172
+ };
173
+
174
+ ext.ls_set = (key, value) => {
175
+ localStorage.set(key, value);
176
+ };
177
+
178
+ ext.ls_remove = (key) => {
179
+ localStorage.delete(key);
180
+ };
181
+
182
+ ext.ls_clear = () => {
183
+ localStorage.clear();
184
+ };
185
+
186
+ ext.ls_keys = () => {
187
+ return JSON.stringify([...localStorage.keys()]);
188
+ };
189
+
190
+ // Simplified V8 serialization (uses JSON as fallback)
191
+ ext.serialize = (value) => {
192
+ try {
193
+ const json = JSON.stringify(value);
194
+ return new TextEncoder().encode(json);
195
+ } catch {
196
+ return null;
197
+ }
198
+ };
199
+
200
+ ext.deserialize = (bytes) => {
201
+ try {
202
+ const json = new TextDecoder().decode(bytes);
203
+ return JSON.parse(json);
204
+ } catch {
205
+ return null;
206
+ }
207
+ };
208
+
209
+ // ============================================
210
+ // SESSION - In-memory emulation
211
+ // ============================================
212
+
213
+ ext.session_get = (sid, key) => {
214
+ return sessionStorage.get(`${sid}:${key}`) || '';
215
+ };
216
+
217
+ ext.session_set = (sid, jsonArgs) => {
218
+ const { key, value } = JSON.parse(jsonArgs);
219
+ sessionStorage.set(`${sid}:${key}`, value);
220
+ };
221
+
222
+ ext.session_delete = (sid, key) => {
223
+ sessionStorage.delete(`${sid}:${key}`);
224
+ };
225
+
226
+ ext.session_clear = (sid) => {
227
+ for (const key of sessionStorage.keys()) {
228
+ if (key.startsWith(`${sid}:`)) {
229
+ sessionStorage.delete(key);
230
+ }
231
+ }
232
+ };
233
+
234
+ // ============================================
235
+ // OS - Emulation using Node.js os
236
+ // ============================================
237
+
238
+ ext.os_info = () => {
239
+ return JSON.stringify({
240
+ platform: nodeOs.platform(),
241
+ cpus: nodeOs.cpus().length,
242
+ totalMemory: nodeOs.totalmem(),
243
+ freeMemory: nodeOs.freemem(),
244
+ tmpdir: nodeOs.tmpdir()
245
+ });
246
+ };
247
+
248
+ // ============================================
249
+ // NET - Basic emulation
250
+ // ============================================
251
+
252
+ ext.net_resolve = (hostname) => {
253
+ return JSON.stringify(['127.0.0.1']);
254
+ };
255
+
256
+ ext.net_ip = () => {
257
+ const interfaces = nodeOs.networkInterfaces();
258
+ for (const name of Object.keys(interfaces)) {
259
+ for (const iface of interfaces[name]) {
260
+ if (iface.family === 'IPv4' && !iface.internal) {
261
+ return iface.address;
262
+ }
263
+ }
264
+ }
265
+ return '127.0.0.1';
266
+ };
267
+
268
+ // ============================================
269
+ // PROC - Basic emulation
270
+ // ============================================
271
+
272
+ ext.proc_info = () => {
273
+ return JSON.stringify({
274
+ pid: process.pid,
275
+ uptime: process.uptime()
276
+ });
277
+ };
278
+
279
+ ext.proc_run = (jsonArgs) => {
280
+ return JSON.stringify({ ok: false, error: 'Disabled in tests' });
281
+ };
282
+
283
+ ext.proc_kill = (pid) => {
284
+ return false;
285
+ };
286
+
287
+ ext.proc_list = () => {
288
+ return JSON.stringify([]);
289
+ };
290
+
291
+ // ============================================
292
+ // TIME
293
+ // ============================================
294
+
295
+ ext.time_sleep = (ms) => {
296
+ const end = Date.now() + ms;
297
+ while (Date.now() < end) { }
298
+ };
299
+
300
+ // ============================================
301
+ // DATABASE - MOCK (only real mock)
302
+ // ============================================
303
+
304
+ globalThis.t.db = {
305
+ connect: vi.fn().mockReturnValue({
306
+ query: vi.fn().mockResolvedValue({ rows: [] }),
307
+ execute: vi.fn().mockResolvedValue({ rowCount: 0 }),
308
+ close: vi.fn()
309
+ })
310
+ };
311
+
312
+ // ============================================
313
+ // Helpers to clear state between tests
314
+ // ============================================
315
+
316
+ export function clearStorage() {
317
+ localStorage.clear();
318
+ sessionStorage.clear();
319
+ }
320
+
321
+ import { beforeEach } from 'vitest';
322
+
323
+ beforeEach(() => {
324
+ clearStorage();
325
+ });
@@ -0,0 +1,57 @@
1
+ /**
2
+ * tests/time.test.js
3
+ *
4
+ * Tests for the time module
5
+ * time.now() - Pure JS (Date.now())
6
+ * time.sleep() - Native emulated
7
+ */
8
+ import { describe, it, expect } from 'vitest';
9
+ import { time } from '../index.js';
10
+
11
+ describe('time', () => {
12
+ describe('now()', () => {
13
+ it('should return current timestamp', () => {
14
+ const before = Date.now();
15
+ const result = time.now();
16
+ const after = Date.now();
17
+
18
+ expect(result).toBeGreaterThanOrEqual(before);
19
+ expect(result).toBeLessThanOrEqual(after);
20
+ });
21
+
22
+ it('should return number', () => {
23
+ expect(typeof time.now()).toBe('number');
24
+ });
25
+
26
+ it('should increment over time', async () => {
27
+ const first = time.now();
28
+ await new Promise(r => setTimeout(r, 10));
29
+ const second = time.now();
30
+
31
+ expect(second).toBeGreaterThan(first);
32
+ });
33
+ });
34
+
35
+ describe('sleep()', () => {
36
+ it('should pause execution', () => {
37
+ const start = Date.now();
38
+ time.sleep(50);
39
+ const elapsed = Date.now() - start;
40
+
41
+ // Should have passed at least 40ms (margin of error)
42
+ expect(elapsed).toBeGreaterThanOrEqual(40);
43
+ });
44
+
45
+ it('should accept small values', () => {
46
+ expect(() => time.sleep(1)).not.toThrow();
47
+ });
48
+
49
+ it('should handle 0ms', () => {
50
+ const start = Date.now();
51
+ time.sleep(0);
52
+ const elapsed = Date.now() - start;
53
+
54
+ expect(elapsed).toBeLessThan(100);
55
+ });
56
+ });
57
+ });
@@ -0,0 +1,82 @@
1
+ /**
2
+ * tests/url.test.js
3
+ *
4
+ * Tests for the url module
5
+ * Pure JS API - uses native URL and URLSearchParams
6
+ */
7
+ import { describe, it, expect } from 'vitest';
8
+ import { url } from '../index.js';
9
+
10
+ describe('url', () => {
11
+ describe('parse()', () => {
12
+ it('should parse complete URL', () => {
13
+ const parsed = url.parse('https://example.com:8080/path?query=value#hash');
14
+
15
+ expect(parsed.protocol).toBe('https:');
16
+ expect(parsed.hostname).toBe('example.com');
17
+ expect(parsed.port).toBe('8080');
18
+ expect(parsed.pathname).toBe('/path');
19
+ expect(parsed.search).toBe('?query=value');
20
+ expect(parsed.hash).toBe('#hash');
21
+ });
22
+
23
+ it('should parse simple URL', () => {
24
+ const parsed = url.parse('https://example.com');
25
+
26
+ expect(parsed.hostname).toBe('example.com');
27
+ expect(parsed.pathname).toBe('/');
28
+ });
29
+
30
+ it('should return null for invalid URL', () => {
31
+ expect(url.parse('not-a-url')).toBeNull();
32
+ expect(url.parse('')).toBeNull();
33
+ });
34
+
35
+ it('should handle query params', () => {
36
+ const parsed = url.parse('https://api.example.com/search?q=test&page=1');
37
+
38
+ expect(parsed.searchParams.get('q')).toBe('test');
39
+ expect(parsed.searchParams.get('page')).toBe('1');
40
+ });
41
+
42
+ it('should handle URLs with authentication', () => {
43
+ const parsed = url.parse('https://user:pass@example.com/path');
44
+
45
+ expect(parsed.username).toBe('user');
46
+ expect(parsed.password).toBe('pass');
47
+ });
48
+ });
49
+
50
+ describe('SearchParams', () => {
51
+ it('should create URLSearchParams instance', () => {
52
+ const params = new url.SearchParams('foo=bar&baz=qux');
53
+
54
+ expect(params.get('foo')).toBe('bar');
55
+ expect(params.get('baz')).toBe('qux');
56
+ });
57
+
58
+ it('should serialize to string', () => {
59
+ const params = new url.SearchParams();
60
+ params.append('key', 'value');
61
+ params.append('another', 'test');
62
+
63
+ expect(params.toString()).toContain('key=value');
64
+ expect(params.toString()).toContain('another=test');
65
+ });
66
+
67
+ it('should handle encoded values', () => {
68
+ const params = new url.SearchParams();
69
+ params.set('message', 'Hello World!');
70
+
71
+ expect(params.toString()).toContain('Hello');
72
+ });
73
+
74
+ it('should iterate over entries', () => {
75
+ const params = new url.SearchParams('a=1&b=2&c=3');
76
+ const entries = [...params.entries()];
77
+
78
+ expect(entries).toHaveLength(3);
79
+ expect(entries[0]).toEqual(['a', '1']);
80
+ });
81
+ });
82
+ });
@@ -0,0 +1,2 @@
1
+ // titan-ext.d.ts
2
+ /// <reference path="./globals.d.ts" />
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@titanpl/core",
3
+ "type": "native",
4
+ "entry": "index.js",
5
+ "native": {
6
+ "windows": "native/target/release/titan_core.dll",
7
+ "linux": "native/target/release/libtitan_core.so"
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ // vitest.config.ts
2
+ import { defineConfig } from 'vitest/config';
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ setupFiles: ['@tgrv/microgravity/setup'],
7
+ }
8
+ });
@@ -9,5 +9,3 @@ This package is the compiled core Rust + Axum server embedded with the Boa JavaS
9
9
  This package is listed as an "optional dependency" in `@titanpl/cli`. During package installation, your package manager identifies the OS and automatically downloads this binary if it matches `darwin` + `arm64`. You do not need to install it directly.
10
10
 
11
11
  When you run `titan start`, the CLI locates this binary and executes it as your web server.
12
-
13
- **Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux and macOS versions are in development (dev only) for the new architecture and will be launched later.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-darwin-arm64",
3
- "version": "6.0.0",
3
+ "version": "7.0.0",
4
4
  "os": [
5
5
  "darwin"
6
6
  ],
@@ -7,5 +7,3 @@ This package holds the core Rust + Axum high-performance web server tightly coup
7
7
 
8
8
  ## How it works
9
9
  You don't need to manually interact with this module. It acts as an optional dependency resolved by `#titanpl/cli`. If you run TitanPlanet on a Linux x64 machine, npm/yarn automatically downloads this native binary to run your application.
10
-
11
- **Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-linux-x64",
3
- "version": "6.0.0",
3
+ "version": "7.0.0",
4
4
  "os": [
5
5
  "linux"
6
6
  ],
@@ -8,4 +8,3 @@ This module provides the highly concurrent Rust-based server binary (`titan.exe`
8
8
  ## How it works
9
9
  Like the other engine packages, this works entirely behind the scenes. When `@titanpl/cli` is installed on a Windows instance, it fetches this `.exe` runtime. The CLI then maps your built assets and JS routes into the binary for deployment.
10
10
 
11
- **Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-win32-x64",
3
- "version": "6.0.0",
3
+ "version": "7.0.0",
4
4
  "os": [
5
5
  "win32"
6
6
  ],
@@ -8,4 +8,3 @@ It acts as the low-level communication bridge offering type definitions and util
8
8
  ## How it works
9
9
  You can import tools and primitives from this package into your server-side actions alongside `@titanpl/core` when you want direct low-level interaction or need access to platform operations that interact directly with the C/Rust engine.
10
10
 
11
- **Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
@@ -22,12 +22,22 @@ export function defineAction<T = any>(handler: (req: Request) => T | Promise<T>)
22
22
  export function fetch(url: string, options?: any): any;
23
23
  export function drift<T>(op: any): T;
24
24
 
25
+ export interface ShareContext {
26
+ get(key: string): any;
27
+ set(key: string, value: any): void;
28
+ delete(key: string): void;
29
+ keys(): string[];
30
+ broadcast(event: string, payload: any): void;
31
+ }
32
+
25
33
  // Add more as needed based on native/index.js
26
- export const db: any;
27
- export const ws: {
28
- send(id: string, message: string): void;
34
+ export interface WebSocketModule {
35
+ send(socketId: string, message: string): void;
29
36
  broadcast(message: string): void;
30
- };
37
+ }
38
+
39
+ export const db: any;
40
+ export const ws: WebSocketModule;
31
41
  export const path: any;
32
42
  export const jwt: any;
33
43
  export const password: any;
@@ -36,6 +46,7 @@ export const buffer: any;
36
46
  export const ls: any;
37
47
  export const session: any;
38
48
  export const cookies: any;
49
+ export const shareContext: ShareContext;
39
50
  export const os: any;
40
51
  export const net: any;
41
52
  export const proc: any;
@@ -43,3 +54,13 @@ export const time: any;
43
54
  export const url: any;
44
55
  export const response: any;
45
56
  export const valid: any;
57
+
58
+ // Serialization
59
+ /** Binary-serializes a JavaScript value using V8's fast internal format. */
60
+ export function serialize(value: any): Uint8Array;
61
+ /** Binary-serializes a JavaScript value using V8's fast internal format. Alias for serialize. */
62
+ export function serialise(value: any): Uint8Array;
63
+ /** Deserializes a Uint8Array back into its original JavaScript value/object. */
64
+ export function deserialize(buffer: Uint8Array): any;
65
+ /** Deserializes a Uint8Array back into its original JavaScript value/object. Alias for deserialize. */
66
+ export function deserialise(buffer: Uint8Array): any;
@@ -27,6 +27,7 @@ export const ls = t.ls;
27
27
  export const localStorage = t.localStorage;
28
28
  export const session = t.session;
29
29
  export const cookies = t.cookies;
30
+ export const shareContext = t.shareContext;
30
31
 
31
32
  // System
32
33
  export const os = t.os;
@@ -39,4 +40,10 @@ export const url = t.url;
39
40
  export const response = t.response;
40
41
  export const valid = t.valid;
41
42
 
43
+ // Serialization
44
+ export const serialize = t.serialize;
45
+ export const serialise = t.serialise;
46
+ export const deserialize = t.deserialize;
47
+ export const deserialise = t.deserialise;
48
+
42
49
  export const defineAction = (handler) => handler;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/native",
3
- "version": "6.0.0",
3
+ "version": "7.0.0",
4
4
  "description": "Titan native utilities package",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@titanpl/core": "latest",
23
+ "@titanpl/core": "7.0.0",
24
24
  "@titanpl/node": "latest"
25
25
  }
26
26
  }