@0xobelisk/sui-client 1.2.0-pre.16 → 1.2.0-pre.18

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/dubhe.d.ts CHANGED
@@ -127,7 +127,12 @@ export declare class Dubhe {
127
127
  last_update_digest?: string;
128
128
  value?: any;
129
129
  }): Promise<StorageItemResponse<IndexerSchema> | undefined>;
130
- subscribe(types: SubscribableType[], handleData: (data: any) => void): Promise<WebSocket>;
130
+ subscribe({ types, handleData, onOpen, onClose, }: {
131
+ types: SubscribableType[];
132
+ handleData: (data: any) => void;
133
+ onOpen?: () => void;
134
+ onClose?: () => void;
135
+ }): Promise<WebSocket>;
131
136
  /**
132
137
  * else:
133
138
  * it will generate signer from the mnemonic with the given derivePathParams.
package/dist/index.js CHANGED
@@ -1341,8 +1341,13 @@ var SuiIndexerClient = class {
1341
1341
  value: result
1342
1342
  };
1343
1343
  }
1344
- async subscribe(types, handleData) {
1345
- return this.http.subscribe(types, handleData);
1344
+ async subscribe({
1345
+ types,
1346
+ handleData,
1347
+ onOpen,
1348
+ onClose
1349
+ }) {
1350
+ return this.http.subscribe({ types, handleData, onOpen, onClose });
1346
1351
  }
1347
1352
  };
1348
1353
 
@@ -1480,10 +1485,17 @@ var Http = class {
1480
1485
  );
1481
1486
  }
1482
1487
  }
1483
- async subscribe(types, handleData) {
1488
+ async subscribe({
1489
+ types,
1490
+ handleData,
1491
+ onOpen,
1492
+ onClose
1493
+ }) {
1484
1494
  const ws = createWebSocketClient(this.wsEndpoint);
1485
1495
  ws.onopen = () => {
1486
- console.log("Connected to the WebSocket server");
1496
+ if (onOpen) {
1497
+ onOpen();
1498
+ }
1487
1499
  const subscribeMessage = JSON.stringify(types);
1488
1500
  ws.send(subscribeMessage);
1489
1501
  };
@@ -1491,7 +1503,9 @@ var Http = class {
1491
1503
  handleData(JSON.parse(event.data.toString()));
1492
1504
  };
1493
1505
  ws.onclose = () => {
1494
- console.log("Disconnected from the WebSocket server");
1506
+ if (onClose) {
1507
+ onClose();
1508
+ }
1495
1509
  };
1496
1510
  ws.onerror = (error) => {
1497
1511
  console.error(`WebSocket error:`, error);
@@ -2526,8 +2540,18 @@ var Dubhe = class {
2526
2540
  });
2527
2541
  return response;
2528
2542
  }
2529
- async subscribe(types, handleData) {
2530
- return this.suiIndexerClient.subscribe(types, handleData);
2543
+ async subscribe({
2544
+ types,
2545
+ handleData,
2546
+ onOpen,
2547
+ onClose
2548
+ }) {
2549
+ return this.suiIndexerClient.subscribe({
2550
+ types,
2551
+ handleData,
2552
+ onOpen,
2553
+ onClose
2554
+ });
2531
2555
  }
2532
2556
  /**
2533
2557
  * else: