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