peerpigeon 0.0.8 → 0.1.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/README.md +34 -0
- package/examples/browser/index.html +104 -16
- package/examples/browser/ui.js +381 -0
- package/examples/debug-configuration.js +171 -0
- package/examples/node/storage-spaces-test.js +329 -0
- package/examples/node/storage-test.js +141 -6
- package/index.js +3 -0
- package/package.json +13 -8
- package/server/index.js +12 -12
- package/src/CleanupManager.js +20 -18
- package/src/ConnectionManager.js +407 -102
- package/src/CryptoManager.js +28 -26
- package/src/DebugLogger.js +211 -0
- package/src/DistributedStorageManager.js +490 -102
- package/src/EnvironmentDetector.js +3 -1
- package/src/EventEmitter.js +1 -0
- package/src/EvictionManager.js +26 -24
- package/src/GossipManager.js +69 -33
- package/src/LexicalStorageInterface.js +332 -0
- package/src/MediaManager.js +12 -10
- package/src/MeshOptimizer.js +30 -28
- package/src/PeerConnection.js +621 -159
- package/src/PeerDiscovery.js +19 -17
- package/src/PeerPigeonMesh.js +241 -33
- package/src/SignalingClient.js +59 -44
- package/src/SignalingHandler.js +280 -51
- package/src/StorageManager.js +7 -5
- package/src/TimerUtils.js +1 -0
- package/src/WebDHT.js +125 -123
- package/websocket-server/server.js +31 -103
package/README.md
CHANGED
|
@@ -152,6 +152,40 @@ mesh.addEventListener('messageReceived', (data) => {
|
|
|
152
152
|
});
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
### 🐛 Debug Configuration
|
|
156
|
+
|
|
157
|
+
PeerPigeon includes a comprehensive debug system that allows you to control console output at a granular level. **By default, all console logging is disabled** to prevent noise in production.
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
import { PeerPigeonMesh, DebugLogger } from 'peerpigeon';
|
|
161
|
+
|
|
162
|
+
// Enable debugging for specific modules
|
|
163
|
+
DebugLogger.enableModules(['GossipManager', 'ConnectionManager']);
|
|
164
|
+
|
|
165
|
+
// Enable all debugging (development mode)
|
|
166
|
+
DebugLogger.enableAll();
|
|
167
|
+
|
|
168
|
+
// Enable debugging conditionally
|
|
169
|
+
if (process.env.NODE_ENV === 'development') {
|
|
170
|
+
DebugLogger.enableAll();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Create your mesh with debug output enabled
|
|
174
|
+
const mesh = new PeerPigeonMesh(options);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Available Debug Modules:**
|
|
178
|
+
- `PeerPigeonMesh` - Main mesh lifecycle events
|
|
179
|
+
- `GossipManager` - Message propagation debugging
|
|
180
|
+
- `ConnectionManager` - Peer connection management
|
|
181
|
+
- `PeerConnection` - Individual WebRTC connections
|
|
182
|
+
- `WebDHT` - Distributed hash table operations
|
|
183
|
+
- `CryptoManager` - Encryption operations
|
|
184
|
+
- `MediaManager` - Audio/video streaming
|
|
185
|
+
- And many more...
|
|
186
|
+
|
|
187
|
+
See [docs/DEBUG.md](docs/DEBUG.md) for complete documentation.
|
|
188
|
+
|
|
155
189
|
### WebDHT (Distributed Hash Table) Examples
|
|
156
190
|
|
|
157
191
|
```javascript
|
|
@@ -51,6 +51,22 @@
|
|
|
51
51
|
</div>
|
|
52
52
|
</div>
|
|
53
53
|
|
|
54
|
+
<div class="connected-peers" aria-expanded="false">
|
|
55
|
+
<div class="section-header">
|
|
56
|
+
<h2>
|
|
57
|
+
<button id="connected-peers-toggle" class="toggle-btn" aria-expanded="false">
|
|
58
|
+
▶ Connected Peers
|
|
59
|
+
</button>
|
|
60
|
+
<span id="connected-peers-count" class="count-badge">0</span>
|
|
61
|
+
</h2>
|
|
62
|
+
</div>
|
|
63
|
+
<div id="connected-peers-content" class="collapsible-content" style="display: none;">
|
|
64
|
+
<div id="peers-list" class="peers-list">
|
|
65
|
+
<p class="empty-state">No peers connected</p>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
54
70
|
<div class="media" aria-expanded="false">
|
|
55
71
|
<div class="section-header">
|
|
56
72
|
<h2>
|
|
@@ -132,22 +148,6 @@
|
|
|
132
148
|
</div>
|
|
133
149
|
</div>
|
|
134
150
|
|
|
135
|
-
<div class="connected-peers" aria-expanded="false">
|
|
136
|
-
<div class="section-header">
|
|
137
|
-
<h2>
|
|
138
|
-
<button id="connected-peers-toggle" class="toggle-btn" aria-expanded="false">
|
|
139
|
-
▶ Connected Peers
|
|
140
|
-
</button>
|
|
141
|
-
<span id="connected-peers-count" class="count-badge">0</span>
|
|
142
|
-
</h2>
|
|
143
|
-
</div>
|
|
144
|
-
<div id="connected-peers-content" class="collapsible-content" style="display: none;">
|
|
145
|
-
<div id="peers-list" class="peers-list">
|
|
146
|
-
<p class="empty-state">No peers connected</p>
|
|
147
|
-
</div>
|
|
148
|
-
</div>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
151
|
<div class="manual-connection" aria-expanded="false">
|
|
152
152
|
<div class="section-header">
|
|
153
153
|
<h2>
|
|
@@ -644,6 +644,94 @@
|
|
|
644
644
|
<h3>Storage Operations Log</h3>
|
|
645
645
|
<div id="storage-log" class="storage-log"></div>
|
|
646
646
|
</div>
|
|
647
|
+
|
|
648
|
+
<!-- Lexical Storage Interface -->
|
|
649
|
+
<div class="lexical-storage">
|
|
650
|
+
<h3>🔗 Lexical Storage Interface (GUN-like API)</h3>
|
|
651
|
+
<p class="feature-description">Chain operations like: <code>storage.get('users').get('alice').put({name: 'Alice'})</code></p>
|
|
652
|
+
|
|
653
|
+
<!-- Lexical Operations -->
|
|
654
|
+
<div class="lexical-operations">
|
|
655
|
+
<h4>Chain Operations</h4>
|
|
656
|
+
<div class="input-group">
|
|
657
|
+
<label for="lexical-path">Path (dot notation):</label>
|
|
658
|
+
<input type="text" id="lexical-path" placeholder="users.alice" value="demo.user1">
|
|
659
|
+
</div>
|
|
660
|
+
<div class="input-group">
|
|
661
|
+
<label for="lexical-data">Data (JSON):</label>
|
|
662
|
+
<textarea id="lexical-data" rows="3" placeholder='{"name": "Alice", "age": 30}'></textarea>
|
|
663
|
+
</div>
|
|
664
|
+
<div class="input-group">
|
|
665
|
+
<label for="lexical-property">Property to get:</label>
|
|
666
|
+
<input type="text" id="lexical-property" placeholder="name" value="name">
|
|
667
|
+
</div>
|
|
668
|
+
|
|
669
|
+
<div class="button-group">
|
|
670
|
+
<button id="lexical-put-btn" class="btn primary">Put Data</button>
|
|
671
|
+
<button id="lexical-get-btn" class="btn secondary">Get Property</button>
|
|
672
|
+
<button id="lexical-val-btn" class="btn secondary">Get Full Object</button>
|
|
673
|
+
<button id="lexical-update-btn" class="btn tertiary">Update</button>
|
|
674
|
+
<button id="lexical-delete-btn" class="btn warning">Delete</button>
|
|
675
|
+
</div>
|
|
676
|
+
</div>
|
|
677
|
+
|
|
678
|
+
<!-- Set Operations -->
|
|
679
|
+
<div class="lexical-sets">
|
|
680
|
+
<h4>Set Operations</h4>
|
|
681
|
+
<div class="input-group">
|
|
682
|
+
<label for="lexical-set-path">Set Path:</label>
|
|
683
|
+
<input type="text" id="lexical-set-path" placeholder="users.alice.friends" value="demo.friends">
|
|
684
|
+
</div>
|
|
685
|
+
<div class="input-group">
|
|
686
|
+
<label for="lexical-set-data">Set Data (JSON object):</label>
|
|
687
|
+
<textarea id="lexical-set-data" rows="2" placeholder='{"bob": {"name": "Bob"}, "charlie": {"name": "Charlie"}}'></textarea>
|
|
688
|
+
</div>
|
|
689
|
+
|
|
690
|
+
<div class="button-group">
|
|
691
|
+
<button id="lexical-set-btn" class="btn primary">Set Data</button>
|
|
692
|
+
<button id="lexical-map-btn" class="btn secondary">Map & Log</button>
|
|
693
|
+
</div>
|
|
694
|
+
</div>
|
|
695
|
+
|
|
696
|
+
<!-- Property Access Demo -->
|
|
697
|
+
<div class="lexical-proxy">
|
|
698
|
+
<h4>Property Access (Proxy)</h4>
|
|
699
|
+
<div class="input-group">
|
|
700
|
+
<label for="lexical-proxy-path">Property Path:</label>
|
|
701
|
+
<input type="text" id="lexical-proxy-path" placeholder="users.alice.settings.theme" value="demo.settings.theme">
|
|
702
|
+
</div>
|
|
703
|
+
<div class="input-group">
|
|
704
|
+
<label for="lexical-proxy-value">Value:</label>
|
|
705
|
+
<input type="text" id="lexical-proxy-value" placeholder="dark" value="dark">
|
|
706
|
+
</div>
|
|
707
|
+
|
|
708
|
+
<div class="button-group">
|
|
709
|
+
<button id="lexical-proxy-set-btn" class="btn primary">Set via Proxy</button>
|
|
710
|
+
<button id="lexical-proxy-get-btn" class="btn secondary">Get via Proxy</button>
|
|
711
|
+
</div>
|
|
712
|
+
</div>
|
|
713
|
+
|
|
714
|
+
<!-- Utility Operations -->
|
|
715
|
+
<div class="lexical-utils">
|
|
716
|
+
<h4>Utility Methods</h4>
|
|
717
|
+
<div class="input-group">
|
|
718
|
+
<label for="lexical-util-path">Path:</label>
|
|
719
|
+
<input type="text" id="lexical-util-path" placeholder="demo.user1" value="demo.user1">
|
|
720
|
+
</div>
|
|
721
|
+
|
|
722
|
+
<div class="button-group">
|
|
723
|
+
<button id="lexical-exists-btn" class="btn tertiary">Check Exists</button>
|
|
724
|
+
<button id="lexical-keys-btn" class="btn tertiary">Get Keys</button>
|
|
725
|
+
<button id="lexical-path-btn" class="btn tertiary">Get Path</button>
|
|
726
|
+
</div>
|
|
727
|
+
</div>
|
|
728
|
+
|
|
729
|
+
<!-- Lexical Results -->
|
|
730
|
+
<div class="lexical-results">
|
|
731
|
+
<h4>Lexical Operations Results</h4>
|
|
732
|
+
<div id="lexical-log" class="storage-log"></div>
|
|
733
|
+
</div>
|
|
734
|
+
</div>
|
|
647
735
|
</div>
|
|
648
736
|
</div>
|
|
649
737
|
|
package/examples/browser/ui.js
CHANGED
|
@@ -916,6 +916,370 @@ export class PeerPigeonUI {
|
|
|
916
916
|
e.target.value = '';
|
|
917
917
|
});
|
|
918
918
|
}
|
|
919
|
+
|
|
920
|
+
// Setup Lexical Storage Interface
|
|
921
|
+
this.setupLexicalStorageControls();
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
setupLexicalStorageControls() {
|
|
925
|
+
// Chain Operations
|
|
926
|
+
const lexicalPutBtn = document.getElementById('lexical-put-btn');
|
|
927
|
+
const lexicalGetBtn = document.getElementById('lexical-get-btn');
|
|
928
|
+
const lexicalValBtn = document.getElementById('lexical-val-btn');
|
|
929
|
+
const lexicalUpdateBtn = document.getElementById('lexical-update-btn');
|
|
930
|
+
const lexicalDeleteBtn = document.getElementById('lexical-delete-btn');
|
|
931
|
+
|
|
932
|
+
// Set Operations
|
|
933
|
+
const lexicalSetBtn = document.getElementById('lexical-set-btn');
|
|
934
|
+
const lexicalMapBtn = document.getElementById('lexical-map-btn');
|
|
935
|
+
|
|
936
|
+
// Property Access
|
|
937
|
+
const lexicalProxySetBtn = document.getElementById('lexical-proxy-set-btn');
|
|
938
|
+
const lexicalProxyGetBtn = document.getElementById('lexical-proxy-get-btn');
|
|
939
|
+
|
|
940
|
+
// Utility Operations
|
|
941
|
+
const lexicalExistsBtn = document.getElementById('lexical-exists-btn');
|
|
942
|
+
const lexicalKeysBtn = document.getElementById('lexical-keys-btn');
|
|
943
|
+
const lexicalPathBtn = document.getElementById('lexical-path-btn');
|
|
944
|
+
|
|
945
|
+
// Chain Operations Event Handlers
|
|
946
|
+
if (lexicalPutBtn) {
|
|
947
|
+
lexicalPutBtn.addEventListener('click', async () => {
|
|
948
|
+
const path = document.getElementById('lexical-path')?.value?.trim();
|
|
949
|
+
const data = document.getElementById('lexical-data')?.value?.trim();
|
|
950
|
+
|
|
951
|
+
if (!path || !data) {
|
|
952
|
+
this.addLexicalLogEntry('❌ Error: Both path and data are required');
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
try {
|
|
957
|
+
const parsedData = JSON.parse(data);
|
|
958
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
959
|
+
const pathParts = path.split('.');
|
|
960
|
+
|
|
961
|
+
let current = lex;
|
|
962
|
+
for (const part of pathParts) {
|
|
963
|
+
current = current.get(part);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
await current.put(parsedData);
|
|
967
|
+
this.addLexicalLogEntry(`✅ Put data at path: ${path}`);
|
|
968
|
+
} catch (error) {
|
|
969
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if (lexicalGetBtn) {
|
|
975
|
+
lexicalGetBtn.addEventListener('click', async () => {
|
|
976
|
+
const path = document.getElementById('lexical-path')?.value?.trim();
|
|
977
|
+
const property = document.getElementById('lexical-property')?.value?.trim();
|
|
978
|
+
|
|
979
|
+
if (!path || !property) {
|
|
980
|
+
this.addLexicalLogEntry('❌ Error: Both path and property are required');
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
try {
|
|
985
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
986
|
+
const pathParts = path.split('.');
|
|
987
|
+
|
|
988
|
+
let current = lex;
|
|
989
|
+
for (const part of pathParts) {
|
|
990
|
+
current = current.get(part);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
const value = await current.get(property).val();
|
|
994
|
+
this.addLexicalLogEntry(`📄 ${path}.${property}: ${JSON.stringify(value)}`);
|
|
995
|
+
} catch (error) {
|
|
996
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
if (lexicalValBtn) {
|
|
1002
|
+
lexicalValBtn.addEventListener('click', async () => {
|
|
1003
|
+
const path = document.getElementById('lexical-path')?.value?.trim();
|
|
1004
|
+
|
|
1005
|
+
if (!path) {
|
|
1006
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
try {
|
|
1011
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1012
|
+
const pathParts = path.split('.');
|
|
1013
|
+
|
|
1014
|
+
let current = lex;
|
|
1015
|
+
for (const part of pathParts) {
|
|
1016
|
+
current = current.get(part);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
const value = await current.val();
|
|
1020
|
+
this.addLexicalLogEntry(`📄 Full object at ${path}: ${JSON.stringify(value, null, 2)}`);
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if (lexicalUpdateBtn) {
|
|
1028
|
+
lexicalUpdateBtn.addEventListener('click', async () => {
|
|
1029
|
+
const path = document.getElementById('lexical-path')?.value?.trim();
|
|
1030
|
+
const data = document.getElementById('lexical-data')?.value?.trim();
|
|
1031
|
+
|
|
1032
|
+
if (!path || !data) {
|
|
1033
|
+
this.addLexicalLogEntry('❌ Error: Both path and data are required');
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
try {
|
|
1038
|
+
const parsedData = JSON.parse(data);
|
|
1039
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1040
|
+
const pathParts = path.split('.');
|
|
1041
|
+
|
|
1042
|
+
let current = lex;
|
|
1043
|
+
for (const part of pathParts) {
|
|
1044
|
+
current = current.get(part);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
await current.update(parsedData);
|
|
1048
|
+
this.addLexicalLogEntry(`✅ Updated data at path: ${path}`);
|
|
1049
|
+
} catch (error) {
|
|
1050
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
if (lexicalDeleteBtn) {
|
|
1056
|
+
lexicalDeleteBtn.addEventListener('click', async () => {
|
|
1057
|
+
const path = document.getElementById('lexical-path')?.value?.trim();
|
|
1058
|
+
|
|
1059
|
+
if (!path) {
|
|
1060
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
try {
|
|
1065
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1066
|
+
const pathParts = path.split('.');
|
|
1067
|
+
|
|
1068
|
+
let current = lex;
|
|
1069
|
+
for (const part of pathParts) {
|
|
1070
|
+
current = current.get(part);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
await current.delete();
|
|
1074
|
+
this.addLexicalLogEntry(`✅ Deleted data at path: ${path}`);
|
|
1075
|
+
} catch (error) {
|
|
1076
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// Set Operations Event Handlers
|
|
1082
|
+
if (lexicalSetBtn) {
|
|
1083
|
+
lexicalSetBtn.addEventListener('click', async () => {
|
|
1084
|
+
const path = document.getElementById('lexical-set-path')?.value?.trim();
|
|
1085
|
+
const data = document.getElementById('lexical-set-data')?.value?.trim();
|
|
1086
|
+
|
|
1087
|
+
if (!path || !data) {
|
|
1088
|
+
this.addLexicalLogEntry('❌ Error: Both path and data are required');
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
try {
|
|
1093
|
+
const parsedData = JSON.parse(data);
|
|
1094
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1095
|
+
const pathParts = path.split('.');
|
|
1096
|
+
|
|
1097
|
+
let current = lex;
|
|
1098
|
+
for (const part of pathParts) {
|
|
1099
|
+
current = current.get(part);
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
await current.set(parsedData);
|
|
1103
|
+
this.addLexicalLogEntry(`✅ Set data at path: ${path}`);
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
if (lexicalMapBtn) {
|
|
1111
|
+
lexicalMapBtn.addEventListener('click', async () => {
|
|
1112
|
+
const path = document.getElementById('lexical-set-path')?.value?.trim();
|
|
1113
|
+
|
|
1114
|
+
if (!path) {
|
|
1115
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
try {
|
|
1120
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1121
|
+
const pathParts = path.split('.');
|
|
1122
|
+
|
|
1123
|
+
let current = lex;
|
|
1124
|
+
for (const part of pathParts) {
|
|
1125
|
+
current = current.get(part);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
const mapResults = [];
|
|
1129
|
+
const unsubscribe = current.map().on((value, key) => {
|
|
1130
|
+
mapResults.push({ key, value });
|
|
1131
|
+
this.addLexicalLogEntry(`🗺️ Map result - ${key}: ${JSON.stringify(value)}`);
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
// Stop mapping after a short delay
|
|
1135
|
+
setTimeout(() => {
|
|
1136
|
+
if (unsubscribe) unsubscribe();
|
|
1137
|
+
this.addLexicalLogEntry(`✅ Map operation completed with ${mapResults.length} results`);
|
|
1138
|
+
}, 1000);
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// Property Access Event Handlers
|
|
1146
|
+
if (lexicalProxySetBtn) {
|
|
1147
|
+
lexicalProxySetBtn.addEventListener('click', async () => {
|
|
1148
|
+
const path = document.getElementById('lexical-proxy-path')?.value?.trim();
|
|
1149
|
+
const value = document.getElementById('lexical-proxy-value')?.value?.trim();
|
|
1150
|
+
|
|
1151
|
+
if (!path || !value) {
|
|
1152
|
+
this.addLexicalLogEntry('❌ Error: Both path and value are required');
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
try {
|
|
1157
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1158
|
+
const pathParts = path.split('.');
|
|
1159
|
+
|
|
1160
|
+
// Use proxy property access
|
|
1161
|
+
let current = lex;
|
|
1162
|
+
for (const part of pathParts.slice(0, -1)) {
|
|
1163
|
+
current = current[part];
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
const lastPart = pathParts[pathParts.length - 1];
|
|
1167
|
+
await current[lastPart].put(value);
|
|
1168
|
+
|
|
1169
|
+
this.addLexicalLogEntry(`✅ Set via proxy: ${path} = ${value}`);
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
if (lexicalProxyGetBtn) {
|
|
1177
|
+
lexicalProxyGetBtn.addEventListener('click', async () => {
|
|
1178
|
+
const path = document.getElementById('lexical-proxy-path')?.value?.trim();
|
|
1179
|
+
|
|
1180
|
+
if (!path) {
|
|
1181
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
try {
|
|
1186
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1187
|
+
const pathParts = path.split('.');
|
|
1188
|
+
|
|
1189
|
+
// Use proxy property access
|
|
1190
|
+
let current = lex;
|
|
1191
|
+
for (const part of pathParts.slice(0, -1)) {
|
|
1192
|
+
current = current[part];
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
const lastPart = pathParts[pathParts.length - 1];
|
|
1196
|
+
const value = await current[lastPart].val();
|
|
1197
|
+
|
|
1198
|
+
this.addLexicalLogEntry(`📄 Proxy get ${path}: ${JSON.stringify(value)}`);
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// Utility Operations Event Handlers
|
|
1206
|
+
if (lexicalExistsBtn) {
|
|
1207
|
+
lexicalExistsBtn.addEventListener('click', async () => {
|
|
1208
|
+
const path = document.getElementById('lexical-util-path')?.value?.trim();
|
|
1209
|
+
|
|
1210
|
+
if (!path) {
|
|
1211
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
try {
|
|
1216
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1217
|
+
const pathParts = path.split('.');
|
|
1218
|
+
|
|
1219
|
+
let current = lex;
|
|
1220
|
+
for (const part of pathParts) {
|
|
1221
|
+
current = current.get(part);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
const exists = await current.exists();
|
|
1225
|
+
this.addLexicalLogEntry(`🔍 ${path} exists: ${exists}`);
|
|
1226
|
+
} catch (error) {
|
|
1227
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
if (lexicalKeysBtn) {
|
|
1233
|
+
lexicalKeysBtn.addEventListener('click', async () => {
|
|
1234
|
+
const path = document.getElementById('lexical-util-path')?.value?.trim();
|
|
1235
|
+
|
|
1236
|
+
if (!path) {
|
|
1237
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
try {
|
|
1242
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1243
|
+
const pathParts = path.split('.');
|
|
1244
|
+
|
|
1245
|
+
let current = lex;
|
|
1246
|
+
for (const part of pathParts) {
|
|
1247
|
+
current = current.get(part);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
const keys = await current.keys();
|
|
1251
|
+
this.addLexicalLogEntry(`🔑 Keys at ${path}: [${keys.join(', ')}]`);
|
|
1252
|
+
} catch (error) {
|
|
1253
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
if (lexicalPathBtn) {
|
|
1259
|
+
lexicalPathBtn.addEventListener('click', async () => {
|
|
1260
|
+
const path = document.getElementById('lexical-util-path')?.value?.trim();
|
|
1261
|
+
|
|
1262
|
+
if (!path) {
|
|
1263
|
+
this.addLexicalLogEntry('❌ Error: Path is required');
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
try {
|
|
1268
|
+
const lex = this.mesh.distributedStorage.lexical();
|
|
1269
|
+
const pathParts = path.split('.');
|
|
1270
|
+
|
|
1271
|
+
let current = lex;
|
|
1272
|
+
for (const part of pathParts) {
|
|
1273
|
+
current = current.get(part);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
const fullPath = current.getPath();
|
|
1277
|
+
this.addLexicalLogEntry(`🛤️ Full storage path: ${fullPath}`);
|
|
1278
|
+
} catch (error) {
|
|
1279
|
+
this.addLexicalLogEntry(`❌ Error: ${error.message}`);
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
919
1283
|
}
|
|
920
1284
|
|
|
921
1285
|
async handleStorageStore(isUpdate = false) {
|
|
@@ -1006,6 +1370,23 @@ export class PeerPigeonUI {
|
|
|
1006
1370
|
}
|
|
1007
1371
|
}
|
|
1008
1372
|
|
|
1373
|
+
addLexicalLogEntry(message) {
|
|
1374
|
+
const logElement = document.getElementById('lexical-log');
|
|
1375
|
+
if (!logElement) return;
|
|
1376
|
+
|
|
1377
|
+
const entry = document.createElement('div');
|
|
1378
|
+
entry.className = 'log-entry';
|
|
1379
|
+
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
|
1380
|
+
|
|
1381
|
+
logElement.appendChild(entry);
|
|
1382
|
+
logElement.scrollTop = logElement.scrollHeight;
|
|
1383
|
+
|
|
1384
|
+
// Keep only last 100 entries
|
|
1385
|
+
while (logElement.children.length > 100) {
|
|
1386
|
+
logElement.removeChild(logElement.firstChild);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1009
1390
|
updateStorageStatus() {
|
|
1010
1391
|
if (!this.mesh.distributedStorage) {
|
|
1011
1392
|
document.getElementById('storage-status').textContent = 'Not Available';
|