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.
- package/package.json +2 -6
- package/packages/cli/index.js +25 -11
- package/packages/cli/package.json +4 -4
- package/packages/cli/src/commands/build-ext.js +157 -0
- package/packages/cli/src/commands/build.js +12 -0
- package/packages/cli/src/commands/create.js +160 -0
- package/packages/cli/src/commands/init.js +5 -11
- package/packages/cli/src/commands/run-ext.js +104 -0
- package/{titanpl-sdk → packages/core-source}/LICENSE +1 -1
- package/packages/core-source/README.md +128 -0
- package/packages/core-source/V8_SERIALIZATION.md +125 -0
- package/packages/core-source/configure.js +50 -0
- package/packages/core-source/globals.d.ts +2238 -0
- package/packages/core-source/index.d.ts +515 -0
- package/packages/core-source/index.js +639 -0
- package/packages/core-source/jsconfig.json +12 -0
- package/packages/core-source/mkctx.config.json +7 -0
- package/packages/core-source/native/Cargo.lock +1559 -0
- package/packages/core-source/native/Cargo.toml +30 -0
- package/packages/core-source/native/src/crypto_impl.rs +139 -0
- package/packages/core-source/native/src/lib.rs +702 -0
- package/packages/core-source/native/src/storage_impl.rs +73 -0
- package/packages/core-source/native/src/v8_impl.rs +93 -0
- package/packages/core-source/package-lock.json +1464 -0
- package/packages/core-source/package.json +53 -0
- package/packages/core-source/tests/buffer.test.js +78 -0
- package/packages/core-source/tests/cookies.test.js +117 -0
- package/packages/core-source/tests/crypto.test.js +142 -0
- package/packages/core-source/tests/fs.test.js +176 -0
- package/packages/core-source/tests/ls.test.js +149 -0
- package/packages/core-source/tests/net.test.js +84 -0
- package/packages/core-source/tests/os.test.js +81 -0
- package/packages/core-source/tests/path.test.js +102 -0
- package/packages/core-source/tests/response.test.js +146 -0
- package/packages/core-source/tests/session.test.js +110 -0
- package/packages/core-source/tests/setup.js +325 -0
- package/packages/core-source/tests/time.test.js +57 -0
- package/packages/core-source/tests/url.test.js +82 -0
- package/packages/core-source/titan-ext.d.ts +2 -0
- package/packages/core-source/titan.json +9 -0
- package/packages/core-source/vitest.config.js +8 -0
- package/packages/engine-darwin-arm64/README.md +0 -2
- package/packages/engine-darwin-arm64/package.json +1 -1
- package/packages/engine-linux-x64/README.md +0 -2
- package/packages/engine-linux-x64/package.json +1 -1
- package/packages/engine-win32-x64/README.md +0 -1
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +1 -1
- package/packages/native/README.md +0 -1
- package/packages/native/index.d.ts +25 -4
- package/packages/native/index.js +7 -0
- package/packages/native/package.json +2 -2
- package/packages/native/t.native.d.ts +167 -2
- package/packages/packet/index.js +103 -94
- package/packages/packet/package.json +1 -1
- package/packages/route/package.json +1 -1
- package/packages/sdk/index.js +2 -0
- package/packages/sdk/package.json +18 -0
- package/packages/sdk/test/index.js +120 -0
- package/templates/common/_tanfig.json +19 -13
- package/templates/extension/index.d.ts +26 -22
- package/templates/extension/index.js +15 -15
- package/templates/extension/native/Cargo.toml +5 -3
- package/templates/extension/native/src/lib.rs +2 -3
- package/templates/extension/package.json +10 -20
- package/templates/extension/titan.json +5 -16
- package/templates/extension/utils/registerExtension.js +44 -0
- package/templates/js/package.json +8 -8
- package/templates/rust-js/package.json +5 -5
- package/templates/rust-ts/package.json +5 -5
- package/templates/ts/package.json +8 -8
- package/packages/packet/node_modules/typescript/LICENSE.txt +0 -55
- package/packages/packet/node_modules/typescript/README.md +0 -50
- package/packages/packet/node_modules/typescript/SECURITY.md +0 -41
- package/packages/packet/node_modules/typescript/ThirdPartyNoticeText.txt +0 -193
- package/packages/packet/node_modules/typescript/bin/tsc +0 -2
- package/packages/packet/node_modules/typescript/bin/tsserver +0 -2
- package/packages/packet/node_modules/typescript/lib/_tsc.js +0 -133818
- package/packages/packet/node_modules/typescript/lib/_tsserver.js +0 -659
- package/packages/packet/node_modules/typescript/lib/_typingsInstaller.js +0 -222
- package/packages/packet/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/de/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/es/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/it/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/lib.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.decorators.d.ts +0 -384
- package/packages/packet/node_modules/typescript/lib/lib.decorators.legacy.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.dom.d.ts +0 -39429
- package/packages/packet/node_modules/typescript/lib/lib.dom.iterable.d.ts +0 -571
- package/packages/packet/node_modules/typescript/lib/lib.es2015.collection.d.ts +0 -147
- package/packages/packet/node_modules/typescript/lib/lib.es2015.core.d.ts +0 -597
- package/packages/packet/node_modules/typescript/lib/lib.es2015.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.es2015.generator.d.ts +0 -77
- package/packages/packet/node_modules/typescript/lib/lib.es2015.iterable.d.ts +0 -605
- package/packages/packet/node_modules/typescript/lib/lib.es2015.promise.d.ts +0 -81
- package/packages/packet/node_modules/typescript/lib/lib.es2015.proxy.d.ts +0 -128
- package/packages/packet/node_modules/typescript/lib/lib.es2015.reflect.d.ts +0 -144
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.d.ts +0 -46
- package/packages/packet/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +0 -326
- package/packages/packet/node_modules/typescript/lib/lib.es2016.array.include.d.ts +0 -116
- package/packages/packet/node_modules/typescript/lib/lib.es2016.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2016.full.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2016.intl.d.ts +0 -31
- package/packages/packet/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2017.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2017.date.d.ts +0 -31
- package/packages/packet/node_modules/typescript/lib/lib.es2017.full.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2017.intl.d.ts +0 -44
- package/packages/packet/node_modules/typescript/lib/lib.es2017.object.d.ts +0 -49
- package/packages/packet/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +0 -135
- package/packages/packet/node_modules/typescript/lib/lib.es2017.string.d.ts +0 -45
- package/packages/packet/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +0 -53
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +0 -77
- package/packages/packet/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +0 -53
- package/packages/packet/node_modules/typescript/lib/lib.es2018.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2018.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2018.intl.d.ts +0 -83
- package/packages/packet/node_modules/typescript/lib/lib.es2018.promise.d.ts +0 -30
- package/packages/packet/node_modules/typescript/lib/lib.es2018.regexp.d.ts +0 -37
- package/packages/packet/node_modules/typescript/lib/lib.es2019.array.d.ts +0 -79
- package/packages/packet/node_modules/typescript/lib/lib.es2019.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2019.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2019.intl.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2019.object.d.ts +0 -33
- package/packages/packet/node_modules/typescript/lib/lib.es2019.string.d.ts +0 -37
- package/packages/packet/node_modules/typescript/lib/lib.es2019.symbol.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2020.bigint.d.ts +0 -765
- package/packages/packet/node_modules/typescript/lib/lib.es2020.d.ts +0 -27
- package/packages/packet/node_modules/typescript/lib/lib.es2020.date.d.ts +0 -42
- package/packages/packet/node_modules/typescript/lib/lib.es2020.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2020.intl.d.ts +0 -474
- package/packages/packet/node_modules/typescript/lib/lib.es2020.number.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.es2020.promise.d.ts +0 -47
- package/packages/packet/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +0 -99
- package/packages/packet/node_modules/typescript/lib/lib.es2020.string.d.ts +0 -44
- package/packages/packet/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.es2021.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.es2021.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2021.intl.d.ts +0 -166
- package/packages/packet/node_modules/typescript/lib/lib.es2021.promise.d.ts +0 -48
- package/packages/packet/node_modules/typescript/lib/lib.es2021.string.d.ts +0 -33
- package/packages/packet/node_modules/typescript/lib/lib.es2021.weakref.d.ts +0 -78
- package/packages/packet/node_modules/typescript/lib/lib.es2022.array.d.ts +0 -121
- package/packages/packet/node_modules/typescript/lib/lib.es2022.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2022.error.d.ts +0 -75
- package/packages/packet/node_modules/typescript/lib/lib.es2022.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2022.intl.d.ts +0 -145
- package/packages/packet/node_modules/typescript/lib/lib.es2022.object.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2022.regexp.d.ts +0 -39
- package/packages/packet/node_modules/typescript/lib/lib.es2022.string.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2023.array.d.ts +0 -924
- package/packages/packet/node_modules/typescript/lib/lib.es2023.collection.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.es2023.d.ts +0 -22
- package/packages/packet/node_modules/typescript/lib/lib.es2023.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2023.intl.d.ts +0 -56
- package/packages/packet/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +0 -65
- package/packages/packet/node_modules/typescript/lib/lib.es2024.collection.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es2024.d.ts +0 -26
- package/packages/packet/node_modules/typescript/lib/lib.es2024.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.es2024.object.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es2024.promise.d.ts +0 -35
- package/packages/packet/node_modules/typescript/lib/lib.es2024.regexp.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +0 -68
- package/packages/packet/node_modules/typescript/lib/lib.es2024.string.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.es5.d.ts +0 -4601
- package/packages/packet/node_modules/typescript/lib/lib.es6.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.esnext.array.d.ts +0 -35
- package/packages/packet/node_modules/typescript/lib/lib.esnext.collection.d.ts +0 -96
- package/packages/packet/node_modules/typescript/lib/lib.esnext.d.ts +0 -29
- package/packages/packet/node_modules/typescript/lib/lib.esnext.decorators.d.ts +0 -28
- package/packages/packet/node_modules/typescript/lib/lib.esnext.disposable.d.ts +0 -193
- package/packages/packet/node_modules/typescript/lib/lib.esnext.error.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.esnext.float16.d.ts +0 -445
- package/packages/packet/node_modules/typescript/lib/lib.esnext.full.d.ts +0 -24
- package/packages/packet/node_modules/typescript/lib/lib.esnext.intl.d.ts +0 -21
- package/packages/packet/node_modules/typescript/lib/lib.esnext.iterator.d.ts +0 -148
- package/packages/packet/node_modules/typescript/lib/lib.esnext.promise.d.ts +0 -34
- package/packages/packet/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +0 -25
- package/packages/packet/node_modules/typescript/lib/lib.scripthost.d.ts +0 -322
- package/packages/packet/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +0 -41
- package/packages/packet/node_modules/typescript/lib/lib.webworker.d.ts +0 -13150
- package/packages/packet/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +0 -23
- package/packages/packet/node_modules/typescript/lib/lib.webworker.iterable.d.ts +0 -340
- package/packages/packet/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/tsc.js +0 -8
- package/packages/packet/node_modules/typescript/lib/tsserver.js +0 -8
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.d.ts +0 -17
- package/packages/packet/node_modules/typescript/lib/tsserverlibrary.js +0 -21
- package/packages/packet/node_modules/typescript/lib/typesMap.json +0 -497
- package/packages/packet/node_modules/typescript/lib/typescript.d.ts +0 -11437
- package/packages/packet/node_modules/typescript/lib/typescript.js +0 -200276
- package/packages/packet/node_modules/typescript/lib/typingsInstaller.js +0 -8
- package/packages/packet/node_modules/typescript/lib/watchGuard.js +0 -53
- package/packages/packet/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +0 -2122
- package/packages/packet/node_modules/typescript/package.json +0 -120
- package/titanpl-sdk/README.md +0 -111
- package/titanpl-sdk/assets/titanpl-sdk.png +0 -0
- package/titanpl-sdk/bin/run.js +0 -274
- package/titanpl-sdk/index.js +0 -5
- package/titanpl-sdk/package-lock.json +0 -28
- package/titanpl-sdk/package.json +0 -40
- package/titanpl-sdk/templates/app/actions/hello.js +0 -5
- package/titanpl-sdk/templates/app/app.js +0 -7
- package/titanpl-sdk/templates/jsconfig.json +0 -19
- package/titanpl-sdk/templates/server/Cargo.toml +0 -52
- package/titanpl-sdk/templates/server/src/action_management.rs +0 -175
- package/titanpl-sdk/templates/server/src/errors.rs +0 -12
- package/titanpl-sdk/templates/server/src/extensions/builtin.rs +0 -1060
- package/titanpl-sdk/templates/server/src/extensions/external.rs +0 -338
- package/titanpl-sdk/templates/server/src/extensions/mod.rs +0 -580
- package/titanpl-sdk/templates/server/src/extensions/titan_core.js +0 -249
- package/titanpl-sdk/templates/server/src/fast_path.rs +0 -719
- package/titanpl-sdk/templates/server/src/main.rs +0 -607
- package/titanpl-sdk/templates/server/src/runtime.rs +0 -284
- package/titanpl-sdk/templates/server/src/utils.rs +0 -33
- package/titanpl-sdk/templates/titan/bundle.js +0 -259
- package/titanpl-sdk/templates/titan/dev.js +0 -390
- package/titanpl-sdk/templates/titan/error-box.js +0 -277
- 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
|
+
});
|
|
@@ -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.
|
|
@@ -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.
|
|
@@ -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.
|
|
Binary file
|
|
@@ -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
|
|
27
|
-
|
|
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;
|
package/packages/native/index.js
CHANGED
|
@@ -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": "
|
|
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": "
|
|
23
|
+
"@titanpl/core": "7.0.0",
|
|
24
24
|
"@titanpl/node": "latest"
|
|
25
25
|
}
|
|
26
26
|
}
|