hyperstack-react 0.3.0 → 0.3.2
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/dist/index.esm.js +30 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -6779,40 +6779,26 @@ class HyperStackError extends Error {
|
|
|
6779
6779
|
}
|
|
6780
6780
|
}
|
|
6781
6781
|
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
typeof obj.data === 'string');
|
|
6787
|
-
}
|
|
6788
|
-
function decompressGzip(base64Data) {
|
|
6789
|
-
const binaryString = atob(base64Data);
|
|
6790
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
6791
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
6792
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
6793
|
-
}
|
|
6794
|
-
const decompressed = inflate_1(bytes);
|
|
6795
|
-
return new TextDecoder().decode(decompressed);
|
|
6796
|
-
}
|
|
6797
|
-
function parseAndDecompress(jsonString) {
|
|
6798
|
-
const parsed = JSON.parse(jsonString);
|
|
6799
|
-
if (isCompressedFrame(parsed)) {
|
|
6800
|
-
const decompressedJson = decompressGzip(parsed.data);
|
|
6801
|
-
const frame = JSON.parse(decompressedJson);
|
|
6802
|
-
return frame;
|
|
6803
|
-
}
|
|
6804
|
-
return parsed;
|
|
6782
|
+
const GZIP_MAGIC_0 = 0x1f;
|
|
6783
|
+
const GZIP_MAGIC_1 = 0x8b;
|
|
6784
|
+
function isGzipData(data) {
|
|
6785
|
+
return data.length >= 2 && data[0] === GZIP_MAGIC_0 && data[1] === GZIP_MAGIC_1;
|
|
6805
6786
|
}
|
|
6806
6787
|
function isSnapshotFrame(frame) {
|
|
6807
6788
|
return frame.op === 'snapshot';
|
|
6808
6789
|
}
|
|
6809
6790
|
function parseFrame(data) {
|
|
6810
6791
|
if (typeof data === 'string') {
|
|
6811
|
-
return
|
|
6792
|
+
return JSON.parse(data);
|
|
6793
|
+
}
|
|
6794
|
+
const bytes = new Uint8Array(data);
|
|
6795
|
+
if (isGzipData(bytes)) {
|
|
6796
|
+
const decompressed = inflate_1(bytes);
|
|
6797
|
+
const jsonString = new TextDecoder().decode(decompressed);
|
|
6798
|
+
return JSON.parse(jsonString);
|
|
6812
6799
|
}
|
|
6813
|
-
const
|
|
6814
|
-
|
|
6815
|
-
return parseAndDecompress(jsonString);
|
|
6800
|
+
const jsonString = new TextDecoder('utf-8').decode(data);
|
|
6801
|
+
return JSON.parse(jsonString);
|
|
6816
6802
|
}
|
|
6817
6803
|
async function parseFrameFromBlob(blob) {
|
|
6818
6804
|
const arrayBuffer = await blob.arrayBuffer();
|
|
@@ -6887,8 +6873,8 @@ class ConnectionManager {
|
|
|
6887
6873
|
this.reconnectAttempts = 0;
|
|
6888
6874
|
this.updateState('connected');
|
|
6889
6875
|
this.startPingInterval();
|
|
6890
|
-
this.flushSubscriptionQueue();
|
|
6891
6876
|
this.resubscribeActive();
|
|
6877
|
+
this.flushSubscriptionQueue();
|
|
6892
6878
|
resolve();
|
|
6893
6879
|
};
|
|
6894
6880
|
this.ws.onmessage = async (event) => {
|
|
@@ -6947,12 +6933,24 @@ class ConnectionManager {
|
|
|
6947
6933
|
subscribe(subscription) {
|
|
6948
6934
|
const subKey = this.makeSubKey(subscription);
|
|
6949
6935
|
if (this.currentState === 'connected' && this.ws?.readyState === WebSocket.OPEN) {
|
|
6936
|
+
if (this.activeSubscriptions.has(subKey)) {
|
|
6937
|
+
console.log('[hyperstack] Skipping already active subscription:', subKey);
|
|
6938
|
+
return;
|
|
6939
|
+
}
|
|
6950
6940
|
const subMsg = { type: 'subscribe', ...subscription };
|
|
6941
|
+
console.log('[hyperstack] Sending subscribe:', subKey);
|
|
6951
6942
|
this.ws.send(JSON.stringify(subMsg));
|
|
6952
6943
|
this.activeSubscriptions.add(subKey);
|
|
6953
6944
|
}
|
|
6954
6945
|
else {
|
|
6955
|
-
this.subscriptionQueue.
|
|
6946
|
+
const alreadyQueued = this.subscriptionQueue.some((s) => this.makeSubKey(s) === subKey);
|
|
6947
|
+
if (alreadyQueued) {
|
|
6948
|
+
console.log('[hyperstack] Skipping duplicate queue entry:', subKey);
|
|
6949
|
+
}
|
|
6950
|
+
else {
|
|
6951
|
+
console.log('[hyperstack] Queuing subscription:', subKey, '| Queue:', this.subscriptionQueue.map(s => this.makeSubKey(s)));
|
|
6952
|
+
this.subscriptionQueue.push(subscription);
|
|
6953
|
+
}
|
|
6956
6954
|
}
|
|
6957
6955
|
}
|
|
6958
6956
|
unsubscribe(view, key) {
|
|
@@ -6973,6 +6971,7 @@ class ConnectionManager {
|
|
|
6973
6971
|
return `${subscription.view}:${subscription.key ?? '*'}:${subscription.partition ?? ''}`;
|
|
6974
6972
|
}
|
|
6975
6973
|
flushSubscriptionQueue() {
|
|
6974
|
+
console.log('[hyperstack] Flushing subscription queue:', this.subscriptionQueue.map(s => this.makeSubKey(s)));
|
|
6976
6975
|
while (this.subscriptionQueue.length > 0) {
|
|
6977
6976
|
const sub = this.subscriptionQueue.shift();
|
|
6978
6977
|
if (sub) {
|
|
@@ -6981,6 +6980,7 @@ class ConnectionManager {
|
|
|
6981
6980
|
}
|
|
6982
6981
|
}
|
|
6983
6982
|
resubscribeActive() {
|
|
6983
|
+
console.log('[hyperstack] Resubscribing active:', Array.from(this.activeSubscriptions));
|
|
6984
6984
|
for (const subKey of this.activeSubscriptions) {
|
|
6985
6985
|
const [view, key, partition] = subKey.split(':');
|
|
6986
6986
|
const subscription = {
|
|
@@ -6990,6 +6990,7 @@ class ConnectionManager {
|
|
|
6990
6990
|
};
|
|
6991
6991
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
6992
6992
|
const subMsg = { type: 'subscribe', ...subscription };
|
|
6993
|
+
console.log('[hyperstack] Resubscribe sending:', subKey);
|
|
6993
6994
|
this.ws.send(JSON.stringify(subMsg));
|
|
6994
6995
|
}
|
|
6995
6996
|
}
|