titanpl 7.0.0 → 7.0.1
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 +1 -1
- package/packages/cli/package.json +4 -4
- package/packages/cli/src/commands/build-ext.js +17 -4
- package/packages/engine-darwin-arm64/package.json +1 -1
- package/packages/engine-linux-x64/package.json +1 -1
- package/packages/engine-win32-x64/bin/titan-server.exe +0 -0
- package/packages/engine-win32-x64/package.json +1 -1
- package/packages/native/index.d.ts +27 -0
- package/packages/native/index.js +1 -0
- package/packages/native/package.json +1 -1
- package/packages/native/t.native.d.ts +99 -3
- package/packages/packet/package.json +1 -1
- package/packages/route/package.json +1 -1
- package/packages/sdk/package.json +1 -1
- package/templates/extension/README_WASM.md +38 -0
- package/templates/extension/package.json +2 -2
- package/templates/js/package.json +7 -7
- package/templates/rust-js/package.json +4 -4
- package/templates/rust-ts/package.json +4 -4
- package/templates/ts/package.json +7 -7
- package/packages/core-source/LICENSE +0 -15
- package/packages/core-source/README.md +0 -128
- package/packages/core-source/V8_SERIALIZATION.md +0 -125
- package/packages/core-source/configure.js +0 -50
- package/packages/core-source/globals.d.ts +0 -2238
- package/packages/core-source/index.d.ts +0 -515
- package/packages/core-source/index.js +0 -639
- package/packages/core-source/jsconfig.json +0 -12
- package/packages/core-source/mkctx.config.json +0 -7
- package/packages/core-source/native/Cargo.lock +0 -1559
- package/packages/core-source/native/Cargo.toml +0 -30
- package/packages/core-source/native/src/crypto_impl.rs +0 -139
- package/packages/core-source/native/src/lib.rs +0 -702
- package/packages/core-source/native/src/storage_impl.rs +0 -73
- package/packages/core-source/native/src/v8_impl.rs +0 -93
- package/packages/core-source/package-lock.json +0 -1464
- package/packages/core-source/package.json +0 -53
- package/packages/core-source/tests/buffer.test.js +0 -78
- package/packages/core-source/tests/cookies.test.js +0 -117
- package/packages/core-source/tests/crypto.test.js +0 -142
- package/packages/core-source/tests/fs.test.js +0 -176
- package/packages/core-source/tests/ls.test.js +0 -149
- package/packages/core-source/tests/net.test.js +0 -84
- package/packages/core-source/tests/os.test.js +0 -81
- package/packages/core-source/tests/path.test.js +0 -102
- package/packages/core-source/tests/response.test.js +0 -146
- package/packages/core-source/tests/session.test.js +0 -110
- package/packages/core-source/tests/setup.js +0 -325
- package/packages/core-source/tests/time.test.js +0 -57
- package/packages/core-source/tests/url.test.js +0 -82
- package/packages/core-source/titan-ext.d.ts +0 -2
- package/packages/core-source/titan.json +0 -9
- package/packages/core-source/vitest.config.js +0 -8
- package/templates/extension/README.md +0 -69
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
# V8 Serialization Support for Local Storage
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
Added native V8 serialization support to the `ls` (Local Storage) module in `@titanpl/core`. This enables efficient storage and retrieval of complex JavaScript objects including `Map`, `Set`, `Date`, `Uint8Array`, and other types that cannot be properly serialized with JSON.
|
|
6
|
-
|
|
7
|
-
## Changes Made
|
|
8
|
-
|
|
9
|
-
### 1. JavaScript Implementation (`index.js`)
|
|
10
|
-
|
|
11
|
-
Added four new methods to the `ls` object:
|
|
12
|
-
|
|
13
|
-
#### `ls.serialize(value: any): Uint8Array`
|
|
14
|
-
- Serializes any JavaScript value using native V8 serialization
|
|
15
|
-
- Returns a `Uint8Array` containing the binary representation
|
|
16
|
-
- Supports complex types: `Map`, `Set`, `Date`, `RegExp`, `BigInt`, `Uint8Array`, etc.
|
|
17
|
-
- Handles circular references
|
|
18
|
-
- ~50x faster than JSON for large objects
|
|
19
|
-
|
|
20
|
-
#### `ls.deserialize(bytes: Uint8Array): any`
|
|
21
|
-
- Deserializes V8 binary format back to JavaScript values
|
|
22
|
-
- Restores original object types (Map stays Map, Set stays Set, etc.)
|
|
23
|
-
- Handles all types supported by V8 serialization
|
|
24
|
-
|
|
25
|
-
#### `ls.setObject(key: string, value: any): void`
|
|
26
|
-
- High-level wrapper for storing complex objects
|
|
27
|
-
- Automatically serializes using V8, encodes to Base64, and stores
|
|
28
|
-
- Preserves object types and structure
|
|
29
|
-
|
|
30
|
-
#### `ls.getObject(key: string): any | null`
|
|
31
|
-
- High-level wrapper for retrieving complex objects
|
|
32
|
-
- Automatically retrieves, decodes from Base64, and deserializes
|
|
33
|
-
- Returns `null` if key doesn't exist or deserialization fails
|
|
34
|
-
|
|
35
|
-
### 2. Native Bindings
|
|
36
|
-
|
|
37
|
-
The native V8 serialization functions were already implemented in Rust:
|
|
38
|
-
- `native_serialize` - V8 ValueSerializer implementation
|
|
39
|
-
- `native_deserialize` - V8 ValueDeserializer implementation
|
|
40
|
-
|
|
41
|
-
These are exposed through the `natives` object and bound in `index.js`.
|
|
42
|
-
|
|
43
|
-
### 3. TypeScript Definitions
|
|
44
|
-
|
|
45
|
-
The TypeScript definitions in `globals.d.ts` already included complete type definitions for all four methods with comprehensive JSDoc documentation.
|
|
46
|
-
|
|
47
|
-
### 4. Documentation
|
|
48
|
-
|
|
49
|
-
The `README.md` already documented the new functions:
|
|
50
|
-
```javascript
|
|
51
|
-
- ls.setObject(key: string, value: any): void
|
|
52
|
-
- ls.getObject(key: string): any
|
|
53
|
-
- ls.serialize(value: any): Uint8Array
|
|
54
|
-
- ls.deserialize(bytes: Uint8Array): any
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Usage Examples
|
|
58
|
-
|
|
59
|
-
### Basic Serialization
|
|
60
|
-
```javascript
|
|
61
|
-
import { ls } from '@titanpl/core';
|
|
62
|
-
|
|
63
|
-
const data = {
|
|
64
|
-
users: new Map([['alice', { role: 'admin' }]]),
|
|
65
|
-
tags: new Set(['active', 'verified']),
|
|
66
|
-
created: new Date()
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// Low-level API
|
|
70
|
-
const bytes = ls.serialize(data);
|
|
71
|
-
const restored = ls.deserialize(bytes);
|
|
72
|
-
|
|
73
|
-
// High-level API
|
|
74
|
-
ls.setObject('session', data);
|
|
75
|
-
const session = ls.getObject('session');
|
|
76
|
-
// session.users instanceof Map → true
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Complex Nested Structures
|
|
80
|
-
```javascript
|
|
81
|
-
const gameState = {
|
|
82
|
-
players: new Map([
|
|
83
|
-
['player1', {
|
|
84
|
-
inventory: new Set(['sword', 'shield']),
|
|
85
|
-
stats: { hp: 100, mp: 50 }
|
|
86
|
-
}]
|
|
87
|
-
]),
|
|
88
|
-
startTime: new Date()
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
ls.setObject('game:session1', gameState);
|
|
92
|
-
const loaded = ls.getObject('game:session1');
|
|
93
|
-
// All types preserved: Map, Set, Date
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Advantages Over JSON
|
|
97
|
-
|
|
98
|
-
1. **Type Preservation**: Map, Set, Date, RegExp, BigInt, Uint8Array stay as-is
|
|
99
|
-
2. **Performance**: ~50x faster for large objects
|
|
100
|
-
3. **Circular References**: Handles circular object references
|
|
101
|
-
4. **Binary Efficiency**: More compact binary representation
|
|
102
|
-
|
|
103
|
-
## Testing
|
|
104
|
-
|
|
105
|
-
Tests are already in place in `tests/ls.test.js`:
|
|
106
|
-
- Basic serialize/deserialize tests
|
|
107
|
-
- setObject/getObject tests with fallback to JSON
|
|
108
|
-
- Handles non-existent keys gracefully
|
|
109
|
-
|
|
110
|
-
## Files Modified
|
|
111
|
-
|
|
112
|
-
1. `index.js` - Added native bindings and ls methods
|
|
113
|
-
2. No changes needed to:
|
|
114
|
-
- `globals.d.ts` (already had type definitions)
|
|
115
|
-
- `README.md` (already documented)
|
|
116
|
-
- `tests/ls.test.js` (already had tests)
|
|
117
|
-
- Native Rust code (already implemented)
|
|
118
|
-
|
|
119
|
-
## Example File
|
|
120
|
-
|
|
121
|
-
Created `examples/v8-serialization-example.js` with comprehensive demonstrations of:
|
|
122
|
-
- Basic V8 serialization
|
|
123
|
-
- Complex object storage
|
|
124
|
-
- Nested structures
|
|
125
|
-
- Performance comparisons with JSON
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { readFileSync, existsSync, writeFileSync } from 'fs';
|
|
2
|
-
import { resolve, dirname } from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { platform as _platform } from 'os';
|
|
5
|
-
import { spawnSync } from 'child_process';
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
const platform = _platform();
|
|
10
|
-
const titanConfigPath = resolve(__dirname, 'titan.json');
|
|
11
|
-
|
|
12
|
-
console.log(`Configuring titan.json for platform: ${platform}`);
|
|
13
|
-
|
|
14
|
-
// 1. Platform-specific output file name
|
|
15
|
-
let libFile = "";
|
|
16
|
-
if (platform === "win32") {
|
|
17
|
-
libFile = "titan_core.dll";
|
|
18
|
-
} else if (platform === "darwin") {
|
|
19
|
-
libFile = "libtitan_core.dylib";
|
|
20
|
-
} else {
|
|
21
|
-
libFile = "libtitan_core.so";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const nativeDir = resolve(__dirname, "native");
|
|
25
|
-
const expectedBinary = resolve(nativeDir, "target/release", libFile);
|
|
26
|
-
|
|
27
|
-
// 2. Build if binary missing
|
|
28
|
-
if (!existsSync(expectedBinary)) {
|
|
29
|
-
console.log(`Native binary missing.`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 3. Update titan.json
|
|
33
|
-
try {
|
|
34
|
-
const content = readFileSync(titanConfigPath, "utf8");
|
|
35
|
-
const titanConfig = JSON.parse(content);
|
|
36
|
-
|
|
37
|
-
const relativeLibPath = `native/target/release/${libFile}`;
|
|
38
|
-
|
|
39
|
-
if (!titanConfig.native) {
|
|
40
|
-
titanConfig.native = {};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
titanConfig.native.path = relativeLibPath;
|
|
44
|
-
|
|
45
|
-
writeFileSync(titanConfigPath, JSON.stringify(titanConfig, null, 2));
|
|
46
|
-
console.log(`Updated titan.json to use native binary: ${relativeLibPath}`);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error("Error updating titan.json:", error);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|