@drift-labs/sdk 2.52.0-beta.4 → 2.52.0-beta.5

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.52.0-beta.4
1
+ 2.52.0-beta.5
@@ -28,6 +28,7 @@ class OrderSubscriber {
28
28
  commitment: this.commitment,
29
29
  skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
30
30
  resubTimeoutMs: config.subscriptionConfig.resubTimeoutMs,
31
+ resyncIntervalMs: config.subscriptionConfig.resyncIntervalMs,
31
32
  });
32
33
  }
33
34
  if ((_a = config.fastDecode) !== null && _a !== void 0 ? _a : true) {
@@ -5,12 +5,15 @@ export declare class WebsocketSubscription {
5
5
  private commitment;
6
6
  private skipInitialLoad;
7
7
  private resubTimeoutMs?;
8
+ private resyncIntervalMs?;
8
9
  private subscriber?;
9
- constructor({ orderSubscriber, commitment, skipInitialLoad, resubTimeoutMs, }: {
10
+ private resyncTimeoutId?;
11
+ constructor({ orderSubscriber, commitment, skipInitialLoad, resubTimeoutMs, resyncIntervalMs, }: {
10
12
  orderSubscriber: OrderSubscriber;
11
13
  commitment: Commitment;
12
14
  skipInitialLoad?: boolean;
13
15
  resubTimeoutMs?: number;
16
+ resyncIntervalMs?: number;
14
17
  });
15
18
  subscribe(): Promise<void>;
16
19
  unsubscribe(): Promise<void>;
@@ -4,11 +4,12 @@ exports.WebsocketSubscription = void 0;
4
4
  const memcmp_1 = require("../memcmp");
5
5
  const webSocketProgramAccountSubscriber_1 = require("../accounts/webSocketProgramAccountSubscriber");
6
6
  class WebsocketSubscription {
7
- constructor({ orderSubscriber, commitment, skipInitialLoad = false, resubTimeoutMs, }) {
7
+ constructor({ orderSubscriber, commitment, skipInitialLoad = false, resubTimeoutMs, resyncIntervalMs, }) {
8
8
  this.orderSubscriber = orderSubscriber;
9
9
  this.commitment = commitment;
10
10
  this.skipInitialLoad = skipInitialLoad;
11
11
  this.resubTimeoutMs = resubTimeoutMs;
12
+ this.resyncIntervalMs = resyncIntervalMs;
12
13
  }
13
14
  async subscribe() {
14
15
  if (this.subscriber) {
@@ -25,12 +26,35 @@ class WebsocketSubscription {
25
26
  if (!this.skipInitialLoad) {
26
27
  await this.orderSubscriber.fetch();
27
28
  }
29
+ if (this.resyncIntervalMs) {
30
+ const recursiveResync = () => {
31
+ this.resyncTimeoutId = setTimeout(() => {
32
+ this.orderSubscriber
33
+ .fetch()
34
+ .catch((e) => {
35
+ console.error('Failed to resync in OrderSubscriber');
36
+ console.log(e);
37
+ })
38
+ .finally(() => {
39
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
+ if (!this.resyncTimeoutId)
41
+ return;
42
+ recursiveResync();
43
+ });
44
+ }, this.resyncIntervalMs);
45
+ };
46
+ recursiveResync();
47
+ }
28
48
  }
29
49
  async unsubscribe() {
30
50
  if (!this.subscriber)
31
51
  return;
32
52
  await this.subscriber.unsubscribe();
33
53
  this.subscriber = undefined;
54
+ if (this.resyncTimeoutId !== undefined) {
55
+ clearTimeout(this.resyncTimeoutId);
56
+ this.resyncTimeoutId = undefined;
57
+ }
34
58
  }
35
59
  }
36
60
  exports.WebsocketSubscription = WebsocketSubscription;
@@ -11,6 +11,7 @@ export type OrderSubscriberConfig = {
11
11
  type: 'websocket';
12
12
  skipInitialLoad?: boolean;
13
13
  resubTimeoutMs?: number;
14
+ resyncIntervalMs?: number;
14
15
  commitment?: Commitment;
15
16
  };
16
17
  fastDecode?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.52.0-beta.4",
3
+ "version": "2.52.0-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -39,6 +39,7 @@ export class OrderSubscriber {
39
39
  commitment: this.commitment,
40
40
  skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
41
41
  resubTimeoutMs: config.subscriptionConfig.resubTimeoutMs,
42
+ resyncIntervalMs: config.subscriptionConfig.resyncIntervalMs,
42
43
  });
43
44
  }
44
45
  if (config.fastDecode ?? true) {
@@ -9,24 +9,29 @@ export class WebsocketSubscription {
9
9
  private commitment: Commitment;
10
10
  private skipInitialLoad: boolean;
11
11
  private resubTimeoutMs?: number;
12
+ private resyncIntervalMs?: number;
12
13
 
13
14
  private subscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
15
+ private resyncTimeoutId?: NodeJS.Timeout;
14
16
 
15
17
  constructor({
16
18
  orderSubscriber,
17
19
  commitment,
18
20
  skipInitialLoad = false,
19
21
  resubTimeoutMs,
22
+ resyncIntervalMs,
20
23
  }: {
21
24
  orderSubscriber: OrderSubscriber;
22
25
  commitment: Commitment;
23
26
  skipInitialLoad?: boolean;
24
27
  resubTimeoutMs?: number;
28
+ resyncIntervalMs?: number;
25
29
  }) {
26
30
  this.orderSubscriber = orderSubscriber;
27
31
  this.commitment = commitment;
28
32
  this.skipInitialLoad = skipInitialLoad;
29
33
  this.resubTimeoutMs = resubTimeoutMs;
34
+ this.resyncIntervalMs = resyncIntervalMs;
30
35
  }
31
36
 
32
37
  public async subscribe(): Promise<void> {
@@ -61,11 +66,34 @@ export class WebsocketSubscription {
61
66
  if (!this.skipInitialLoad) {
62
67
  await this.orderSubscriber.fetch();
63
68
  }
69
+
70
+ if (this.resyncIntervalMs) {
71
+ const recursiveResync = () => {
72
+ this.resyncTimeoutId = setTimeout(() => {
73
+ this.orderSubscriber
74
+ .fetch()
75
+ .catch((e) => {
76
+ console.error('Failed to resync in OrderSubscriber');
77
+ console.log(e);
78
+ })
79
+ .finally(() => {
80
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
81
+ if (!this.resyncTimeoutId) return;
82
+ recursiveResync();
83
+ });
84
+ }, this.resyncIntervalMs);
85
+ };
86
+ recursiveResync();
87
+ }
64
88
  }
65
89
 
66
90
  public async unsubscribe(): Promise<void> {
67
91
  if (!this.subscriber) return;
68
92
  await this.subscriber.unsubscribe();
69
93
  this.subscriber = undefined;
94
+ if (this.resyncTimeoutId !== undefined) {
95
+ clearTimeout(this.resyncTimeoutId);
96
+ this.resyncTimeoutId = undefined;
97
+ }
70
98
  }
71
99
  }
@@ -14,6 +14,7 @@ export type OrderSubscriberConfig = {
14
14
  type: 'websocket';
15
15
  skipInitialLoad?: boolean;
16
16
  resubTimeoutMs?: number;
17
+ resyncIntervalMs?: number;
17
18
  commitment?: Commitment;
18
19
  };
19
20
  fastDecode?: boolean;