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,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@titanpl/core",
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "The official Core Standard Library for Titan Planet - provides fs, path, crypto, os, net, proc, time, and url modules",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"configure": "node configure.js",
|
|
10
|
+
"postinstall": "node configure.js",
|
|
11
|
+
"build:native": "cd native && cargo build --release && cd .. && npm run configure",
|
|
12
|
+
"test:ext": "titan run ext",
|
|
13
|
+
"test": "vitest run",
|
|
14
|
+
"test:debug": "TITAN_DEBUG=true npm test",
|
|
15
|
+
"test:watch": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"titan",
|
|
19
|
+
"titanpl",
|
|
20
|
+
"titan-planet",
|
|
21
|
+
"runtime",
|
|
22
|
+
"core",
|
|
23
|
+
"fs",
|
|
24
|
+
"path",
|
|
25
|
+
"crypto",
|
|
26
|
+
"os",
|
|
27
|
+
"extension",
|
|
28
|
+
"titanpl-sdk"
|
|
29
|
+
],
|
|
30
|
+
"author": "ezetgalaxy",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"files": [
|
|
33
|
+
"index.js",
|
|
34
|
+
"configure.js",
|
|
35
|
+
"titan.json",
|
|
36
|
+
"globals.d.ts",
|
|
37
|
+
"index.d.ts",
|
|
38
|
+
"native/target/release/*.dll",
|
|
39
|
+
"native/target/release/*.so",
|
|
40
|
+
"native/target/release/*.dylib",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0",
|
|
45
|
+
"@ezetgalaxy/titan": ">=26.10.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"esbuild": "^0.27.2"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@titanpl/valid": "^1.1.1"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/buffer.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the buffer module (Base64 encoding/decoding)
|
|
5
|
+
* Pure JS API - no mocks required
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { buffer } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('buffer', () => {
|
|
11
|
+
describe('toBase64()', () => {
|
|
12
|
+
it('should encode string to base64', () => {
|
|
13
|
+
const result = buffer.toBase64('Hello World');
|
|
14
|
+
expect(result.replace(/=+$/, '')).toBe('SGVsbG8gV29ybGQ');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should encode empty string', () => {
|
|
18
|
+
expect(buffer.toBase64('')).toBe('');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should handle special characters', () => {
|
|
22
|
+
const result = buffer.toBase64('Hola ñ');
|
|
23
|
+
expect(result).toBeTruthy();
|
|
24
|
+
expect(typeof result).toBe('string');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should encode Uint8Array', () => {
|
|
28
|
+
const bytes = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
|
|
29
|
+
const result = buffer.toBase64(bytes);
|
|
30
|
+
expect(result.replace(/=+$/, '')).toBe('SGVsbG8');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should handle binary data', () => {
|
|
34
|
+
const bytes = new Uint8Array([0, 1, 2, 255, 254]);
|
|
35
|
+
const encoded = buffer.toBase64(bytes);
|
|
36
|
+
expect(encoded).toBeTruthy();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('fromBase64()', () => {
|
|
41
|
+
it('should decode base64 to Uint8Array', () => {
|
|
42
|
+
const result = buffer.fromBase64('SGVsbG8gV29ybGQ=');
|
|
43
|
+
expect(result).toBeInstanceOf(Uint8Array);
|
|
44
|
+
const validBytes = result.filter(b => b >= 32 && b <= 126);
|
|
45
|
+
const text = new TextDecoder().decode(validBytes);
|
|
46
|
+
expect(text).toContain('Hello World');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should handle empty string', () => {
|
|
50
|
+
const result = buffer.fromBase64('');
|
|
51
|
+
expect(result).toBeInstanceOf(Uint8Array);
|
|
52
|
+
expect(result.length).toBe(0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should ignore invalid characters', () => {
|
|
56
|
+
const result = buffer.fromBase64('SGVs bG8='); // with space
|
|
57
|
+
expect(result).toBeInstanceOf(Uint8Array);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('roundtrip', () => {
|
|
62
|
+
it('should encode and decode correctly', () => {
|
|
63
|
+
const original = 'Test string 123!@#';
|
|
64
|
+
const encoded = buffer.toBase64(original);
|
|
65
|
+
const decoded = buffer.fromBase64(encoded);
|
|
66
|
+
const filtered = decoded.filter(b => b !== 0);
|
|
67
|
+
const result = new TextDecoder().decode(filtered);
|
|
68
|
+
expect(result).toBe(original);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should work with simple binary data', () => {
|
|
72
|
+
const original = new Uint8Array([65, 66, 67]); // ABC
|
|
73
|
+
const encoded = buffer.toBase64(original);
|
|
74
|
+
const decoded = buffer.fromBase64(encoded);
|
|
75
|
+
expect(decoded.slice(0, original.length)).toEqual(original);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/cookies.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the cookies module
|
|
5
|
+
* Pure JS API - no mocks required
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { cookies } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('cookies', () => {
|
|
11
|
+
describe('get()', () => {
|
|
12
|
+
it('should extract cookie from request', () => {
|
|
13
|
+
const req = {
|
|
14
|
+
headers: {
|
|
15
|
+
cookie: 'session=abc123; user=john'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
expect(cookies.get(req, 'session')).toBe('abc123');
|
|
20
|
+
expect(cookies.get(req, 'user')).toBe('john');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return null if cookie does not exist', () => {
|
|
24
|
+
const req = {
|
|
25
|
+
headers: {
|
|
26
|
+
cookie: 'session=abc123'
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
expect(cookies.get(req, 'nonexistent')).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should return null if no headers', () => {
|
|
34
|
+
expect(cookies.get({}, 'session')).toBeNull();
|
|
35
|
+
expect(cookies.get({ headers: {} }, 'session')).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return null if req is null/undefined', () => {
|
|
39
|
+
expect(cookies.get(null, 'session')).toBeNull();
|
|
40
|
+
expect(cookies.get(undefined, 'session')).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should handle cookie at start of string', () => {
|
|
44
|
+
const req = {
|
|
45
|
+
headers: { cookie: 'first=value; second=other' }
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
expect(cookies.get(req, 'first')).toBe('value');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should handle values with special characters', () => {
|
|
52
|
+
const req = {
|
|
53
|
+
headers: { cookie: 'token=eyJhbGciOiJIUzI1NiJ9.test' }
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
expect(cookies.get(req, 'token')).toBe('eyJhbGciOiJIUzI1NiJ9.test');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('set()', () => {
|
|
61
|
+
it('should set basic cookie', () => {
|
|
62
|
+
const res = {};
|
|
63
|
+
cookies.set(res, 'session', 'abc123');
|
|
64
|
+
|
|
65
|
+
expect(res.headers['Set-Cookie']).toBe('session=abc123');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should set cookie with options', () => {
|
|
69
|
+
const res = {};
|
|
70
|
+
cookies.set(res, 'auth', 'token123', {
|
|
71
|
+
httpOnly: true,
|
|
72
|
+
secure: true,
|
|
73
|
+
sameSite: 'Strict',
|
|
74
|
+
maxAge: 3600,
|
|
75
|
+
path: '/'
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const cookie = res.headers['Set-Cookie'];
|
|
79
|
+
expect(cookie).toContain('auth=token123');
|
|
80
|
+
expect(cookie).toContain('HttpOnly');
|
|
81
|
+
expect(cookie).toContain('Secure');
|
|
82
|
+
expect(cookie).toContain('SameSite=Strict');
|
|
83
|
+
expect(cookie).toContain('Max-Age=3600');
|
|
84
|
+
expect(cookie).toContain('Path=/');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should handle multiple cookies', () => {
|
|
88
|
+
const res = {};
|
|
89
|
+
cookies.set(res, 'first', 'value1');
|
|
90
|
+
cookies.set(res, 'second', 'value2');
|
|
91
|
+
|
|
92
|
+
expect(Array.isArray(res.headers['Set-Cookie'])).toBe(true);
|
|
93
|
+
expect(res.headers['Set-Cookie']).toHaveLength(2);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should not fail if res is null', () => {
|
|
97
|
+
expect(() => cookies.set(null, 'test', 'value')).not.toThrow();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should create headers if they do not exist', () => {
|
|
101
|
+
const res = {};
|
|
102
|
+
cookies.set(res, 'new', 'cookie');
|
|
103
|
+
|
|
104
|
+
expect(res.headers).toBeDefined();
|
|
105
|
+
expect(res.headers['Set-Cookie']).toBe('new=cookie');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('delete()', () => {
|
|
110
|
+
it.skip('should delete cookie by setting empty value', () => {
|
|
111
|
+
const res = {};
|
|
112
|
+
cookies.delete(res, 'session');
|
|
113
|
+
|
|
114
|
+
expect(res.headers['Set-Cookie']).toContain('session=');
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/crypto.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the crypto module
|
|
5
|
+
* Uses emulated natives wrapping Node.js crypto
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { crypto } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('crypto', () => {
|
|
11
|
+
describe('hash()', () => {
|
|
12
|
+
it('should generate SHA256 hash', () => {
|
|
13
|
+
const hash = crypto.hash('sha256', 'hello');
|
|
14
|
+
|
|
15
|
+
expect(hash).toBe('2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should generate SHA512 hash', () => {
|
|
19
|
+
const hash = crypto.hash('sha512', 'hello');
|
|
20
|
+
|
|
21
|
+
expect(hash).toHaveLength(128); // SHA512 = 64 bytes = 128 hex chars
|
|
22
|
+
expect(hash).toMatch(/^[a-f0-9]+$/);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return different hashes for different inputs', () => {
|
|
26
|
+
const hash1 = crypto.hash('sha256', 'hello');
|
|
27
|
+
const hash2 = crypto.hash('sha256', 'world');
|
|
28
|
+
|
|
29
|
+
expect(hash1).not.toBe(hash2);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should return same hash for same input', () => {
|
|
33
|
+
const hash1 = crypto.hash('sha256', 'consistent');
|
|
34
|
+
const hash2 = crypto.hash('sha256', 'consistent');
|
|
35
|
+
|
|
36
|
+
expect(hash1).toBe(hash2);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('randomBytes()', () => {
|
|
41
|
+
it('should generate random bytes in hex', () => {
|
|
42
|
+
const bytes = crypto.randomBytes(16);
|
|
43
|
+
|
|
44
|
+
expect(bytes).toHaveLength(32); // 16 bytes = 32 hex chars
|
|
45
|
+
expect(bytes).toMatch(/^[a-f0-9]+$/);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should generate different values each time', () => {
|
|
49
|
+
const bytes1 = crypto.randomBytes(16);
|
|
50
|
+
const bytes2 = crypto.randomBytes(16);
|
|
51
|
+
|
|
52
|
+
expect(bytes1).not.toBe(bytes2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should respect specified size', () => {
|
|
56
|
+
expect(crypto.randomBytes(8)).toHaveLength(16);
|
|
57
|
+
expect(crypto.randomBytes(32)).toHaveLength(64);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('uuid()', () => {
|
|
62
|
+
it('should generate valid UUID v4', () => {
|
|
63
|
+
const uuid = crypto.uuid();
|
|
64
|
+
|
|
65
|
+
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should generate unique UUIDs', () => {
|
|
69
|
+
const uuids = new Set();
|
|
70
|
+
for (let i = 0; i < 100; i++) {
|
|
71
|
+
uuids.add(crypto.uuid());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
expect(uuids.size).toBe(100);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('encrypt() and decrypt()', () => {
|
|
79
|
+
it('should encrypt and decrypt text', () => {
|
|
80
|
+
const key = '12345678901234567890123456789012'; // 32 bytes
|
|
81
|
+
const plaintext = 'Secret message';
|
|
82
|
+
|
|
83
|
+
const encrypted = crypto.encrypt('aes-256-gcm', key, plaintext);
|
|
84
|
+
const decrypted = crypto.decrypt('aes-256-gcm', key, encrypted);
|
|
85
|
+
|
|
86
|
+
expect(decrypted).toBe(plaintext);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should generate different ciphertexts for same plaintext', () => {
|
|
90
|
+
const key = '12345678901234567890123456789012';
|
|
91
|
+
const plaintext = 'Same message';
|
|
92
|
+
|
|
93
|
+
const encrypted1 = crypto.encrypt('aes-256-gcm', key, plaintext);
|
|
94
|
+
const encrypted2 = crypto.encrypt('aes-256-gcm', key, plaintext);
|
|
95
|
+
|
|
96
|
+
// Due to random IV, they should be different
|
|
97
|
+
expect(encrypted1).not.toBe(encrypted2);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should handle empty text', () => {
|
|
101
|
+
const key = '12345678901234567890123456789012';
|
|
102
|
+
|
|
103
|
+
const encrypted = crypto.encrypt('aes-256-gcm', key, '');
|
|
104
|
+
const decrypted = crypto.decrypt('aes-256-gcm', key, encrypted);
|
|
105
|
+
|
|
106
|
+
expect(decrypted).toBe('');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('compare()', () => {
|
|
111
|
+
it('should return true for equal strings', () => {
|
|
112
|
+
expect(crypto.compare('abc', 'abc')).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return false for different strings', () => {
|
|
116
|
+
expect(crypto.compare('abc', 'def')).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('hashKeyed()', () => {
|
|
121
|
+
it('should generate HMAC-SHA256', () => {
|
|
122
|
+
const hmac = crypto.hashKeyed('sha256', 'secret-key', 'message');
|
|
123
|
+
|
|
124
|
+
expect(hmac).toHaveLength(64); // SHA256 = 32 bytes = 64 hex
|
|
125
|
+
expect(hmac).toMatch(/^[a-f0-9]+$/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should generate different HMACs with different keys', () => {
|
|
129
|
+
const hmac1 = crypto.hashKeyed('sha256', 'key1', 'message');
|
|
130
|
+
const hmac2 = crypto.hashKeyed('sha256', 'key2', 'message');
|
|
131
|
+
|
|
132
|
+
expect(hmac1).not.toBe(hmac2);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should be consistent with same parameters', () => {
|
|
136
|
+
const hmac1 = crypto.hashKeyed('sha256', 'key', 'msg');
|
|
137
|
+
const hmac2 = crypto.hashKeyed('sha256', 'key', 'msg');
|
|
138
|
+
|
|
139
|
+
expect(hmac1).toBe(hmac2);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tests/fs.test.js
|
|
3
|
+
*
|
|
4
|
+
* Tests for the fs module
|
|
5
|
+
* Uses emulated natives wrapping Node.js fs
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
8
|
+
import { fs, path } from '../index.js';
|
|
9
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
describe('fs', () => {
|
|
14
|
+
let testDir;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
testDir = mkdtempSync(join(tmpdir(), 'titanpl-test-'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
try {
|
|
22
|
+
rmSync(testDir, { recursive: true, force: true });
|
|
23
|
+
} catch { }
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('writeFile() and readFile()', () => {
|
|
27
|
+
it('should write and read text file', () => {
|
|
28
|
+
const filePath = join(testDir, 'test.txt');
|
|
29
|
+
const content = 'Hello, Titan!';
|
|
30
|
+
|
|
31
|
+
fs.writeFile(filePath, content);
|
|
32
|
+
const result = fs.readFile(filePath);
|
|
33
|
+
|
|
34
|
+
expect(result).toBe(content);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should handle multiline content', () => {
|
|
38
|
+
const filePath = join(testDir, 'multiline.txt');
|
|
39
|
+
const content = 'Line 1\nLine 2\nLine 3';
|
|
40
|
+
|
|
41
|
+
fs.writeFile(filePath, content);
|
|
42
|
+
const result = fs.readFile(filePath);
|
|
43
|
+
|
|
44
|
+
expect(result).toBe(content);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should overwrite existing file', () => {
|
|
48
|
+
const filePath = join(testDir, 'overwrite.txt');
|
|
49
|
+
|
|
50
|
+
fs.writeFile(filePath, 'Original');
|
|
51
|
+
fs.writeFile(filePath, 'Updated');
|
|
52
|
+
|
|
53
|
+
expect(fs.readFile(filePath)).toBe('Updated');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should handle JSON', () => {
|
|
57
|
+
const filePath = join(testDir, 'data.json');
|
|
58
|
+
const data = { name: 'Test', value: 42 };
|
|
59
|
+
|
|
60
|
+
fs.writeFile(filePath, JSON.stringify(data));
|
|
61
|
+
const result = JSON.parse(fs.readFile(filePath));
|
|
62
|
+
|
|
63
|
+
expect(result).toEqual(data);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('exists()', () => {
|
|
68
|
+
it('should return true for existing file', () => {
|
|
69
|
+
const filePath = join(testDir, 'exists.txt');
|
|
70
|
+
fs.writeFile(filePath, 'test');
|
|
71
|
+
|
|
72
|
+
expect(fs.exists(filePath)).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should return false for non-existing file', () => {
|
|
76
|
+
expect(fs.exists(join(testDir, 'nonexistent.txt'))).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should work with directories', () => {
|
|
80
|
+
expect(fs.exists(testDir)).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('mkdir()', () => {
|
|
85
|
+
it('should create directory', () => {
|
|
86
|
+
const dirPath = join(testDir, 'newdir');
|
|
87
|
+
|
|
88
|
+
fs.mkdir(dirPath);
|
|
89
|
+
|
|
90
|
+
expect(fs.exists(dirPath)).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should create nested directories (recursive)', () => {
|
|
94
|
+
const dirPath = join(testDir, 'a', 'b', 'c');
|
|
95
|
+
|
|
96
|
+
fs.mkdir(dirPath);
|
|
97
|
+
|
|
98
|
+
expect(fs.exists(dirPath)).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('readdir()', () => {
|
|
103
|
+
it('should list directory contents', () => {
|
|
104
|
+
fs.writeFile(join(testDir, 'file1.txt'), 'a');
|
|
105
|
+
fs.writeFile(join(testDir, 'file2.txt'), 'b');
|
|
106
|
+
|
|
107
|
+
const files = fs.readdir(testDir);
|
|
108
|
+
|
|
109
|
+
expect(files).toContain('file1.txt');
|
|
110
|
+
expect(files).toContain('file2.txt');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should return empty array for empty directory', () => {
|
|
114
|
+
const emptyDir = join(testDir, 'empty');
|
|
115
|
+
fs.mkdir(emptyDir);
|
|
116
|
+
|
|
117
|
+
const files = fs.readdir(emptyDir);
|
|
118
|
+
|
|
119
|
+
expect(files).toEqual([]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should return empty array if not exists', () => {
|
|
123
|
+
const files = fs.readdir(join(testDir, 'nonexistent'));
|
|
124
|
+
|
|
125
|
+
expect(files).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('stat()', () => {
|
|
130
|
+
it('should return file stats', () => {
|
|
131
|
+
const filePath = join(testDir, 'stat-test.txt');
|
|
132
|
+
fs.writeFile(filePath, 'Hello World');
|
|
133
|
+
|
|
134
|
+
const stat = fs.stat(filePath);
|
|
135
|
+
|
|
136
|
+
expect(stat.isFile).toBe(true);
|
|
137
|
+
expect(stat.isDir).toBe(false);
|
|
138
|
+
expect(stat.size).toBeGreaterThan(0);
|
|
139
|
+
expect(stat.modified).toBeGreaterThan(0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should return directory stats', () => {
|
|
143
|
+
const stat = fs.stat(testDir);
|
|
144
|
+
|
|
145
|
+
expect(stat.isFile).toBe(false);
|
|
146
|
+
expect(stat.isDir).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should return empty object if not exists', () => {
|
|
150
|
+
const stat = fs.stat(join(testDir, 'nonexistent'));
|
|
151
|
+
|
|
152
|
+
expect(stat).toEqual({});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('remove()', () => {
|
|
157
|
+
it('should remove file', () => {
|
|
158
|
+
const filePath = join(testDir, 'to-delete.txt');
|
|
159
|
+
fs.writeFile(filePath, 'delete me');
|
|
160
|
+
|
|
161
|
+
expect(fs.exists(filePath)).toBe(true);
|
|
162
|
+
fs.remove(filePath);
|
|
163
|
+
expect(fs.exists(filePath)).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should remove directory with contents', () => {
|
|
167
|
+
const dirPath = join(testDir, 'to-delete-dir');
|
|
168
|
+
fs.mkdir(dirPath);
|
|
169
|
+
fs.writeFile(join(dirPath, 'file.txt'), 'content');
|
|
170
|
+
|
|
171
|
+
fs.remove(dirPath);
|
|
172
|
+
|
|
173
|
+
expect(fs.exists(dirPath)).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|