Fix cloning

This commit is contained in:
Aleksandr Kraiz
2023-06-01 16:47:46 +04:00
parent e9ba554fe8
commit 1a6bb1627f
3 changed files with 11 additions and 8 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.19.14",
"version": "0.19.15",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.19.14",
"version": "0.19.15",
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.21.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.19.14",
"version": "0.19.15",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -21,7 +21,6 @@ import futuresTradeInfoSchema from './schemas/futuresTradeInfoSchema.js';
import { objectKeys } from '../../../utils/objectKeys.js';
// import assertError from '../../../utils/assertError.js';
// import errorSchema from './schemas/errorSchema';
import clone from 'just-clone';
const UNSUBSCRIBE = 'u';
@@ -170,6 +169,10 @@ const nonExistentMessageRegex = /Could not cancel nonexistent subscription: (.*)
// message: Json
// resolve: () => void
// };
type Subscriptions = Partial<{
[K in keyof Subscription]: Partial<Record<string, Subscription[K]>>
}>;
class AggregatorWS {
private ws?: WebSocket | undefined;
@@ -179,9 +182,7 @@ class AggregatorWS {
// https://stackoverflow.com/questions/19304157/getting-the-reason-why-websockets-closed-with-close-code-1006
private isClosedIntentionally = false;
readonly subscriptions: Partial<{
[K in keyof Subscription]: Partial<Record<string, Subscription[K]>>
}> = {};
readonly subscriptions: Subscriptions = {};
public onInit: (() => void) | undefined
@@ -377,7 +378,9 @@ class AggregatorWS {
this.ws.onopen = () => {
// Re-subscribe to all subscriptions
if (isReconnect) {
const subscriptionsToReconnect = clone(this.subscriptions);
// Deep copy of subscriptions
const subscriptionsToReconnect = structuredClone(this.subscriptions);
objectKeys(this.subscriptions).forEach((subType) => {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this.subscriptions[subType];