@chainflip/rpc 1.8.7 → 1.8.8

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/Client.cjs CHANGED
@@ -1,41 +1,72 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/Client.ts
2
- var _assertion = require('@chainflip/utils/assertion');
3
-
2
+ var _async = require('@chainflip/utils/async');
4
3
 
5
4
 
6
5
  var _commoncjs = require('./common.cjs');
7
6
  var Client = (_class = class {
8
- constructor(url) {;_class.prototype.__init.call(this);
7
+ constructor(url) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
9
8
  this.url = url;
10
9
  }
11
10
  __init() {this.lastRequestId = 0}
11
+ __init2() {this.timer = null}
12
+ __init3() {this.requestMap = /* @__PURE__ */ new Map()}
12
13
  getRequestId() {
13
- return String(++this.lastRequestId);
14
+ try {
15
+ return crypto.randomUUID();
16
+ } catch (e) {
17
+ return String(++this.lastRequestId);
18
+ }
14
19
  }
15
20
  formatRequest(method, params) {
16
21
  return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
17
22
  }
18
- parseSingleResponse(response) {
23
+ handleResponse(response, clonedMap) {
24
+ const clonedItem = clonedMap.get(response.id);
25
+ if (!clonedItem) return;
26
+ clonedMap.delete(response.id);
19
27
  if (!response.success) {
20
- throw response.error;
21
- }
22
- const parseResult = _commoncjs.rpcResponse.safeParse(response.result);
23
- if (!parseResult.success) {
24
- throw new Error("Malformed RPC response received");
28
+ return clonedItem.deferred.reject(response.error);
25
29
  }
26
- if ("error" in parseResult.data) {
27
- throw new Error(
28
- `RPC error [${parseResult.data.error.code}]: ${parseResult.data.error.message}`
30
+ const rpcResponse = response.result;
31
+ if ("error" in rpcResponse) {
32
+ return clonedItem.deferred.reject(
33
+ new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`)
29
34
  );
30
35
  }
31
- _assertion.assert.call(void 0, "result" in parseResult.data);
32
- return parseResult.data;
33
- }
34
- async sendRequest(method, ...params) {
35
- const [response] = await this.send([this.formatRequest(method, params)]);
36
- if (!response.success) throw response.error;
37
- const parseResult = this.parseSingleResponse(response);
38
- return _commoncjs.rpcResult[method].parse(parseResult.result);
36
+ const parseResult = _commoncjs.rpcResult[clonedItem.method].safeParse(rpcResponse.result);
37
+ if (parseResult.error) {
38
+ return clonedItem.deferred.reject(parseResult.error);
39
+ }
40
+ clonedItem.deferred.resolve(parseResult.data);
41
+ }
42
+ handleErrorResponse(error, clonedMap) {
43
+ for (const [id] of clonedMap) {
44
+ this.handleResponse({ id, success: false, error }, clonedMap);
45
+ }
46
+ }
47
+ async handleBatch() {
48
+ const clonedMap = new Map(this.requestMap);
49
+ this.requestMap.clear();
50
+ const requests = [...clonedMap.values()].map((item) => item.body);
51
+ await this.send(requests, clonedMap);
52
+ clonedMap.forEach((item) => {
53
+ item.deferred.reject(new Error("Could not find the result for the request"));
54
+ });
55
+ }
56
+ sendRequest(method, ...params) {
57
+ if (!_commoncjs.rpcResult[method]) {
58
+ return Promise.reject(new Error(`Unknown method: ${method}`));
59
+ }
60
+ const deferred = _async.deferredPromise.call(void 0, );
61
+ const body = this.formatRequest(method, params);
62
+ this.requestMap.set(body.id, { deferred, body, method });
63
+ if (!this.timer) {
64
+ this.timer = setTimeout(() => {
65
+ this.timer = null;
66
+ void this.handleBatch();
67
+ }, 0);
68
+ }
69
+ return deferred.promise;
39
70
  }
40
71
  methods() {
41
72
  return Object.keys(_commoncjs.rpcResult).sort();
package/dist/Client.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { RpcMethod, JsonRpcRequest, RpcRequest, RpcResult } from './common.cjs';
1
+ import { DeferredPromise } from '@chainflip/utils/async';
2
+ import { RpcMethod, JsonRpcRequest, RpcResult, JsonRpcResponse, RpcRequest } from './common.cjs';
2
3
  import '@chainflip/utils/types';
3
4
  import 'zod';
4
5
  import './parsers.cjs';
@@ -6,26 +7,31 @@ import './parsers.cjs';
6
7
  type Response = {
7
8
  success: true;
8
9
  id: string;
9
- result: unknown;
10
+ result: JsonRpcResponse;
10
11
  } | {
11
12
  success: false;
12
13
  id: string;
13
14
  error: Error;
14
15
  };
16
+ type RequestMap = Map<string, {
17
+ deferred: DeferredPromise<RpcResult<RpcMethod>>;
18
+ body: JsonRpcRequest<RpcMethod>;
19
+ method: RpcMethod;
20
+ }>;
15
21
  declare abstract class Client {
16
22
  protected readonly url: string;
17
23
  private lastRequestId;
24
+ private timer;
25
+ private requestMap;
18
26
  constructor(url: string);
19
- protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[]): Promise<Response[]>;
20
- protected getRequestId(): string;
21
- protected formatRequest<T extends RpcMethod>(method: T, params: RpcRequest[T]): JsonRpcRequest<T>;
22
- protected parseSingleResponse(response: Response): {
23
- id: string | number;
24
- jsonrpc: "2.0";
25
- result?: any;
26
- };
27
+ protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
28
+ private getRequestId;
29
+ private formatRequest;
30
+ protected handleResponse(response: Response, clonedMap: RequestMap): void;
31
+ protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
32
+ private handleBatch;
27
33
  sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
28
34
  methods(): RpcMethod[];
29
35
  }
30
36
 
31
- export { type Response, Client as default };
37
+ export { type RequestMap, type Response, Client as default };
package/dist/Client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { RpcMethod, JsonRpcRequest, RpcRequest, RpcResult } from './common.js';
1
+ import { DeferredPromise } from '@chainflip/utils/async';
2
+ import { RpcMethod, JsonRpcRequest, RpcResult, JsonRpcResponse, RpcRequest } from './common.js';
2
3
  import '@chainflip/utils/types';
3
4
  import 'zod';
4
5
  import './parsers.js';
@@ -6,26 +7,31 @@ import './parsers.js';
6
7
  type Response = {
7
8
  success: true;
8
9
  id: string;
9
- result: unknown;
10
+ result: JsonRpcResponse;
10
11
  } | {
11
12
  success: false;
12
13
  id: string;
13
14
  error: Error;
14
15
  };
16
+ type RequestMap = Map<string, {
17
+ deferred: DeferredPromise<RpcResult<RpcMethod>>;
18
+ body: JsonRpcRequest<RpcMethod>;
19
+ method: RpcMethod;
20
+ }>;
15
21
  declare abstract class Client {
16
22
  protected readonly url: string;
17
23
  private lastRequestId;
24
+ private timer;
25
+ private requestMap;
18
26
  constructor(url: string);
19
- protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[]): Promise<Response[]>;
20
- protected getRequestId(): string;
21
- protected formatRequest<T extends RpcMethod>(method: T, params: RpcRequest[T]): JsonRpcRequest<T>;
22
- protected parseSingleResponse(response: Response): {
23
- id: string | number;
24
- jsonrpc: "2.0";
25
- result?: any;
26
- };
27
+ protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
28
+ private getRequestId;
29
+ private formatRequest;
30
+ protected handleResponse(response: Response, clonedMap: RequestMap): void;
31
+ protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
32
+ private handleBatch;
27
33
  sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
28
34
  methods(): RpcMethod[];
29
35
  }
30
36
 
31
- export { type Response, Client as default };
37
+ export { type RequestMap, type Response, Client as default };
package/dist/Client.mjs CHANGED
@@ -1,41 +1,72 @@
1
1
  // src/Client.ts
2
- import { assert } from "@chainflip/utils/assertion";
2
+ import { deferredPromise } from "@chainflip/utils/async";
3
3
  import {
4
- rpcResult,
5
- rpcResponse
4
+ rpcResult
6
5
  } from "./common.mjs";
7
6
  var Client = class {
8
7
  constructor(url) {
9
8
  this.url = url;
10
9
  }
11
10
  lastRequestId = 0;
11
+ timer = null;
12
+ requestMap = /* @__PURE__ */ new Map();
12
13
  getRequestId() {
13
- return String(++this.lastRequestId);
14
+ try {
15
+ return crypto.randomUUID();
16
+ } catch {
17
+ return String(++this.lastRequestId);
18
+ }
14
19
  }
15
20
  formatRequest(method, params) {
16
21
  return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
17
22
  }
18
- parseSingleResponse(response) {
23
+ handleResponse(response, clonedMap) {
24
+ const clonedItem = clonedMap.get(response.id);
25
+ if (!clonedItem) return;
26
+ clonedMap.delete(response.id);
19
27
  if (!response.success) {
20
- throw response.error;
21
- }
22
- const parseResult = rpcResponse.safeParse(response.result);
23
- if (!parseResult.success) {
24
- throw new Error("Malformed RPC response received");
28
+ return clonedItem.deferred.reject(response.error);
25
29
  }
26
- if ("error" in parseResult.data) {
27
- throw new Error(
28
- `RPC error [${parseResult.data.error.code}]: ${parseResult.data.error.message}`
30
+ const rpcResponse = response.result;
31
+ if ("error" in rpcResponse) {
32
+ return clonedItem.deferred.reject(
33
+ new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`)
29
34
  );
30
35
  }
31
- assert("result" in parseResult.data);
32
- return parseResult.data;
33
- }
34
- async sendRequest(method, ...params) {
35
- const [response] = await this.send([this.formatRequest(method, params)]);
36
- if (!response.success) throw response.error;
37
- const parseResult = this.parseSingleResponse(response);
38
- return rpcResult[method].parse(parseResult.result);
36
+ const parseResult = rpcResult[clonedItem.method].safeParse(rpcResponse.result);
37
+ if (parseResult.error) {
38
+ return clonedItem.deferred.reject(parseResult.error);
39
+ }
40
+ clonedItem.deferred.resolve(parseResult.data);
41
+ }
42
+ handleErrorResponse(error, clonedMap) {
43
+ for (const [id] of clonedMap) {
44
+ this.handleResponse({ id, success: false, error }, clonedMap);
45
+ }
46
+ }
47
+ async handleBatch() {
48
+ const clonedMap = new Map(this.requestMap);
49
+ this.requestMap.clear();
50
+ const requests = [...clonedMap.values()].map((item) => item.body);
51
+ await this.send(requests, clonedMap);
52
+ clonedMap.forEach((item) => {
53
+ item.deferred.reject(new Error("Could not find the result for the request"));
54
+ });
55
+ }
56
+ sendRequest(method, ...params) {
57
+ if (!rpcResult[method]) {
58
+ return Promise.reject(new Error(`Unknown method: ${method}`));
59
+ }
60
+ const deferred = deferredPromise();
61
+ const body = this.formatRequest(method, params);
62
+ this.requestMap.set(body.id, { deferred, body, method });
63
+ if (!this.timer) {
64
+ this.timer = setTimeout(() => {
65
+ this.timer = null;
66
+ void this.handleBatch();
67
+ }, 0);
68
+ }
69
+ return deferred.promise;
39
70
  }
40
71
  methods() {
41
72
  return Object.keys(rpcResult).sort();
@@ -1,13 +1,7 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class;// src/HttpClient.ts
2
- var _async = require('@chainflip/utils/async');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/HttpClient.ts
3
2
  var _Clientcjs = require('./Client.cjs'); var _Clientcjs2 = _interopRequireDefault(_Clientcjs);
4
-
5
-
6
- var _commoncjs = require('./common.cjs');
7
- var HttpClient = (_class = class extends _Clientcjs2.default {constructor(...args) { super(...args); _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
8
- __init() {this.timer = null}
9
- __init2() {this.requestMap = /* @__PURE__ */ new Map()}
10
- async send(request) {
3
+ var HttpClient = class extends _Clientcjs2.default {
4
+ async send(request, requestMap) {
11
5
  let res;
12
6
  try {
13
7
  res = await fetch(this.url, {
@@ -18,70 +12,23 @@ var HttpClient = (_class = class extends _Clientcjs2.default {constructor(...arg
18
12
  }
19
13
  });
20
14
  } catch (error) {
21
- return request.map((r) => ({
22
- id: r.id,
23
- success: false,
24
- error: new Error("Network error", { cause: error })
25
- }));
15
+ this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
16
+ return;
26
17
  }
27
18
  if (!res.ok) {
28
- return request.map((r) => ({
29
- id: r.id,
30
- success: false,
31
- error: new Error(`HTTP error: ${res.status}`)
32
- }));
19
+ this.handleErrorResponse(new Error(`HTTP error: ${res.status}`), requestMap);
20
+ return;
33
21
  }
34
22
  try {
35
23
  const jsonRpcResponse = await res.json();
36
- return jsonRpcResponse.map((r) => ({ id: r.id, success: true, result: r }));
37
- } catch (cause) {
38
- return request.map((r) => ({
39
- id: r.id,
40
- success: false,
41
- error: new Error("Invalid JSON response", { cause })
42
- }));
43
- }
44
- }
45
- sendRequest(method, ...params) {
46
- const deferred = _async.deferredPromise.call(void 0, );
47
- const body = this.formatRequest(method, params);
48
- this.requestMap.set(body.id, { deferred, body, method });
49
- if (!this.timer) {
50
- this.timer = setTimeout(() => {
51
- this.timer = null;
52
- void this.sendBatch();
53
- }, 0);
54
- }
55
- return deferred.promise;
56
- }
57
- async sendBatch() {
58
- const clonedMap = new Map(this.requestMap);
59
- this.requestMap.clear();
60
- const requests = [...clonedMap.values()].map((item) => item.body);
61
- const responses = await this.send(requests);
62
- for (const response of responses) {
63
- const clonedItem = clonedMap.get(response.id);
64
- if (!clonedItem) {
65
- continue;
66
- }
67
- if (!response.success) {
68
- clonedItem.deferred.reject(response.error);
69
- continue;
70
- }
71
- try {
72
- const parseResult = this.parseSingleResponse(response);
73
- clonedItem.deferred.resolve(_commoncjs.rpcResult[clonedItem.method].parse(parseResult.result));
74
- } catch (e) {
75
- clonedItem.deferred.reject(e);
76
- } finally {
77
- clonedMap.delete(response.id);
24
+ for (const r of jsonRpcResponse) {
25
+ this.handleResponse({ id: r.id, success: true, result: r }, requestMap);
78
26
  }
27
+ } catch (cause) {
28
+ this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
79
29
  }
80
- clonedMap.forEach((item) => {
81
- item.deferred.reject(new Error("Could not find the result for the request"));
82
- });
83
30
  }
84
- }, _class);
31
+ };
85
32
 
86
33
 
87
34
  exports.default = HttpClient;
@@ -1,15 +1,12 @@
1
- import Client, { Response } from './Client.cjs';
2
- import { RpcMethod, JsonRpcRequest, RpcRequest, RpcResult } from './common.cjs';
1
+ import Client, { RequestMap } from './Client.cjs';
2
+ import { RpcMethod, JsonRpcRequest } from './common.cjs';
3
+ import '@chainflip/utils/async';
3
4
  import '@chainflip/utils/types';
4
5
  import 'zod';
5
6
  import './parsers.cjs';
6
7
 
7
8
  declare class HttpClient extends Client {
8
- private timer;
9
- private requestMap;
10
- protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[]): Promise<Response[]>;
11
- sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
12
- private sendBatch;
9
+ protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[], requestMap: RequestMap): Promise<void>;
13
10
  }
14
11
 
15
12
  export { HttpClient as default };
@@ -1,15 +1,12 @@
1
- import Client, { Response } from './Client.js';
2
- import { RpcMethod, JsonRpcRequest, RpcRequest, RpcResult } from './common.js';
1
+ import Client, { RequestMap } from './Client.js';
2
+ import { RpcMethod, JsonRpcRequest } from './common.js';
3
+ import '@chainflip/utils/async';
3
4
  import '@chainflip/utils/types';
4
5
  import 'zod';
5
6
  import './parsers.js';
6
7
 
7
8
  declare class HttpClient extends Client {
8
- private timer;
9
- private requestMap;
10
- protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[]): Promise<Response[]>;
11
- sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
12
- private sendBatch;
9
+ protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[], requestMap: RequestMap): Promise<void>;
13
10
  }
14
11
 
15
12
  export { HttpClient as default };
@@ -1,13 +1,7 @@
1
1
  // src/HttpClient.ts
2
- import { deferredPromise } from "@chainflip/utils/async";
3
2
  import Client from "./Client.mjs";
4
- import {
5
- rpcResult
6
- } from "./common.mjs";
7
3
  var HttpClient = class extends Client {
8
- timer = null;
9
- requestMap = /* @__PURE__ */ new Map();
10
- async send(request) {
4
+ async send(request, requestMap) {
11
5
  let res;
12
6
  try {
13
7
  res = await fetch(this.url, {
@@ -18,68 +12,21 @@ var HttpClient = class extends Client {
18
12
  }
19
13
  });
20
14
  } catch (error) {
21
- return request.map((r) => ({
22
- id: r.id,
23
- success: false,
24
- error: new Error("Network error", { cause: error })
25
- }));
15
+ this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
16
+ return;
26
17
  }
27
18
  if (!res.ok) {
28
- return request.map((r) => ({
29
- id: r.id,
30
- success: false,
31
- error: new Error(`HTTP error: ${res.status}`)
32
- }));
19
+ this.handleErrorResponse(new Error(`HTTP error: ${res.status}`), requestMap);
20
+ return;
33
21
  }
34
22
  try {
35
23
  const jsonRpcResponse = await res.json();
36
- return jsonRpcResponse.map((r) => ({ id: r.id, success: true, result: r }));
37
- } catch (cause) {
38
- return request.map((r) => ({
39
- id: r.id,
40
- success: false,
41
- error: new Error("Invalid JSON response", { cause })
42
- }));
43
- }
44
- }
45
- sendRequest(method, ...params) {
46
- const deferred = deferredPromise();
47
- const body = this.formatRequest(method, params);
48
- this.requestMap.set(body.id, { deferred, body, method });
49
- if (!this.timer) {
50
- this.timer = setTimeout(() => {
51
- this.timer = null;
52
- void this.sendBatch();
53
- }, 0);
54
- }
55
- return deferred.promise;
56
- }
57
- async sendBatch() {
58
- const clonedMap = new Map(this.requestMap);
59
- this.requestMap.clear();
60
- const requests = [...clonedMap.values()].map((item) => item.body);
61
- const responses = await this.send(requests);
62
- for (const response of responses) {
63
- const clonedItem = clonedMap.get(response.id);
64
- if (!clonedItem) {
65
- continue;
66
- }
67
- if (!response.success) {
68
- clonedItem.deferred.reject(response.error);
69
- continue;
70
- }
71
- try {
72
- const parseResult = this.parseSingleResponse(response);
73
- clonedItem.deferred.resolve(rpcResult[clonedItem.method].parse(parseResult.result));
74
- } catch (e) {
75
- clonedItem.deferred.reject(e);
76
- } finally {
77
- clonedMap.delete(response.id);
24
+ for (const r of jsonRpcResponse) {
25
+ this.handleResponse({ id: r.id, success: true, result: r }, requestMap);
78
26
  }
27
+ } catch (cause) {
28
+ this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
79
29
  }
80
- clonedMap.forEach((item) => {
81
- item.deferred.reject(new Error("Could not find the result for the request"));
82
- });
83
30
  }
84
31
  };
85
32
  export {
package/dist/WsClient.cjs CHANGED
@@ -1,111 +1,124 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/WsClient.ts
2
2
  var _async = require('@chainflip/utils/async');
3
+ var _zod = require('zod');
3
4
  var _Clientcjs = require('./Client.cjs'); var _Clientcjs2 = _interopRequireDefault(_Clientcjs);
4
5
  var _commoncjs = require('./common.cjs');
6
+ var CONNECTING = "CONNECTING";
5
7
  var READY = "READY";
6
8
  var DISCONNECT = "DISCONNECT";
7
9
  var WsClient = (_class = class extends _Clientcjs2.default {
8
- constructor(url, WebSocket = globalThis.WebSocket) {
9
- super(url);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);;
10
- this.WebSocket = WebSocket;
11
- }
12
10
 
13
11
  __init() {this.reconnectAttempts = 0}
14
12
  __init2() {this.emitter = new EventTarget()}
15
- __init3() {this.requestMap = /* @__PURE__ */ new Map()}
16
- async close() {
17
- await this.handleClose();
13
+ __init3() {this.inFlightRequestMap = /* @__PURE__ */ new Map()}
14
+
15
+ __init4() {this.shouldConnect = true}
16
+ constructor(url, { timeout = 3e4 } = {}) {
17
+ super(url);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);;
18
+ this.timeout = timeout;
18
19
  }
19
- async handleClose() {
20
+ async close() {
21
+ this.shouldConnect = false;
20
22
  if (!this.ws) return;
21
- this.ws.removeEventListener("close", this.handleDisconnect);
23
+ await this.handleDisconnect();
24
+ const waitForClose = this.ws.readyState === WebSocket.OPEN;
22
25
  this.ws.close();
23
- if (this.ws.readyState !== this.WebSocket.CLOSED) {
24
- await _async.once.call(void 0, this.ws, "close");
25
- }
26
+ if (waitForClose) await _async.once.call(void 0, this.ws, "close");
27
+ this.ws = void 0;
26
28
  }
27
29
  async connectionReady() {
28
30
  if (!this.ws) {
29
31
  return this.connect();
30
32
  }
31
- if (this.ws.readyState !== this.WebSocket.OPEN) {
33
+ if (this.ws.readyState !== WebSocket.OPEN) {
32
34
  await _async.once.call(void 0, this.emitter, READY, { timeout: 3e4 });
33
35
  }
34
36
  return this.ws;
35
37
  }
36
- __init4() {this.handleDisconnect = async () => {
38
+ __init5() {this.handleDisconnect = async () => {
37
39
  this.emitter.dispatchEvent(new Event(DISCONNECT));
38
- this.requestMap.forEach((request) => {
40
+ this.inFlightRequestMap.forEach((request) => {
39
41
  request.reject(new Error("disconnected"));
40
42
  });
41
- this.requestMap.clear();
43
+ this.inFlightRequestMap.clear();
44
+ if (!this.shouldConnect) return;
42
45
  const backoff = 250 * 2 ** this.reconnectAttempts;
43
46
  await _async.sleep.call(void 0, backoff);
44
47
  await this.connect().catch(() => {
45
48
  this.reconnectAttempts = Math.min(this.reconnectAttempts + 1, 6);
46
49
  });
47
50
  }}
48
- __init5() {this.handleMessage = (data) => {
51
+ __init6() {this.handleMessage = (data) => {
49
52
  const parsedData = JSON.parse(data.data);
50
- const response = _commoncjs.rpcResponse.safeParse(parsedData);
51
- if (!response.success) return;
52
- const { id } = response.data;
53
- _optionalChain([this, 'access', _6 => _6.requestMap, 'access', _7 => _7.get, 'call', _8 => _8(id), 'optionalAccess', _9 => _9.resolve, 'call', _10 => _10(response.data)]);
53
+ const responses = _zod.z.array(_commoncjs.rpcResponse).safeParse(parsedData);
54
+ if (!responses.success) return;
55
+ for (const response of responses.data) {
56
+ const { id } = response;
57
+ _optionalChain([this, 'access', _6 => _6.inFlightRequestMap, 'access', _7 => _7.get, 'call', _8 => _8(id), 'optionalAccess', _9 => _9.resolve, 'call', _10 => _10(response)]);
58
+ }
54
59
  }}
55
60
  async connect() {
56
- const socket = new this.WebSocket(this.url);
61
+ this.shouldConnect = true;
62
+ this.emitter.dispatchEvent(new Event(CONNECTING));
63
+ const socket = new WebSocket(this.url);
57
64
  this.ws = socket;
58
65
  this.ws.addEventListener("message", this.handleMessage);
66
+ let connected = false;
67
+ const handleConnectionError = () => {
68
+ if (!connected) {
69
+ void this.handleDisconnect();
70
+ }
71
+ };
59
72
  this.ws.addEventListener("close", this.handleDisconnect, { once: true });
60
- await _async.once.call(void 0, this.ws, "open", { timeout: 3e4 });
73
+ this.ws.addEventListener("error", handleConnectionError, { once: true });
74
+ await _async.once.call(void 0, this.ws, "open", { timeout: this.timeout });
75
+ connected = true;
61
76
  this.ws.addEventListener("error", () => {
62
77
  socket.close();
63
78
  });
64
79
  this.emitter.dispatchEvent(new Event(READY));
80
+ this.ws.removeEventListener("error", handleConnectionError);
65
81
  this.reconnectAttempts = 0;
66
82
  return socket;
67
83
  }
68
- async send(requests) {
69
- const responses = [];
70
- for (const data of requests) {
71
- const MAX_RETRIES = 5;
72
- for (let i = 0; i < MAX_RETRIES; i += 1) {
73
- let socket;
74
- try {
75
- socket = await this.connectionReady();
76
- } catch (e) {
77
- continue;
78
- }
79
- socket.send(JSON.stringify(data));
80
- const request = _async.deferredPromise.call(void 0, );
81
- this.requestMap.set(data.id, request);
82
- const controller = new AbortController();
83
- const result = await Promise.race([
84
- _async.sleep.call(void 0, 3e4, { signal: controller.signal }).then(
85
- () => ({ success: false, retry: false, error: new Error("timeout") })
84
+ async send(requests, requestMap) {
85
+ const MAX_RETRIES = 5;
86
+ let socket;
87
+ for (let i = 0; i < MAX_RETRIES; i += 1) {
88
+ try {
89
+ socket = await this.connectionReady();
90
+ } catch (e) {
91
+ continue;
92
+ }
93
+ }
94
+ if (!socket) {
95
+ this.handleErrorResponse(new Error("failed to connect"), requestMap);
96
+ return;
97
+ }
98
+ socket.send(JSON.stringify(requests));
99
+ const promises = [];
100
+ for (const [id] of requestMap) {
101
+ const result = _async.deferredPromise.call(void 0, );
102
+ const controller = new AbortController();
103
+ this.inFlightRequestMap.set(id, result);
104
+ promises.push(
105
+ Promise.race([
106
+ _async.sleep.call(void 0, this.timeout, { signal: controller.signal }).then(
107
+ () => ({ id, success: false, error: new Error("timeout") })
86
108
  ),
87
- request.promise.then(
88
- (r) => ({ success: true, result: r }),
89
- (error) => ({ success: false, error, retry: true })
109
+ result.promise.then(
110
+ (r) => ({ id, success: true, result: r }),
111
+ (error) => ({ id, success: false, error })
90
112
  )
91
- ]).finally(() => {
92
- this.requestMap.delete(data.id);
113
+ ]).then((response) => {
114
+ this.handleResponse(response, requestMap);
115
+ }).finally(() => {
116
+ this.inFlightRequestMap.delete(id);
93
117
  controller.abort();
94
- });
95
- if (result.success || !result.retry) {
96
- responses.push({ ...result, id: data.id });
97
- break;
98
- }
99
- if (i === MAX_RETRIES - 1) {
100
- responses.push({
101
- success: false,
102
- error: new Error("max retries exceeded"),
103
- id: data.id
104
- });
105
- }
106
- }
118
+ })
119
+ );
107
120
  }
108
- return responses;
121
+ await Promise.all(promises);
109
122
  }
110
123
  }, _class);
111
124
 
@@ -1,23 +1,26 @@
1
- import Client, { Response } from './Client.cjs';
2
- import { RpcMethod, JsonRpcRequest } from './common.cjs';
1
+ import Client, { RequestMap } from './Client.cjs';
2
+ import { JsonRpcRequest, RpcMethod } from './common.cjs';
3
+ import '@chainflip/utils/async';
3
4
  import '@chainflip/utils/types';
4
5
  import 'zod';
5
6
  import './parsers.cjs';
6
7
 
7
8
  declare class WsClient extends Client {
8
- private readonly WebSocket;
9
9
  private ws?;
10
10
  private reconnectAttempts;
11
11
  private emitter;
12
- private requestMap;
13
- constructor(url: string, WebSocket?: typeof globalThis.WebSocket);
12
+ private inFlightRequestMap;
13
+ private readonly timeout;
14
+ private shouldConnect;
15
+ constructor(url: string, { timeout }?: {
16
+ timeout?: number;
17
+ });
14
18
  close(): Promise<void>;
15
- private handleClose;
16
19
  private connectionReady;
17
20
  private handleDisconnect;
18
21
  private handleMessage;
19
22
  private connect;
20
- protected send<const T extends RpcMethod>(requests: JsonRpcRequest<T>[]): Promise<Response[]>;
23
+ protected send(requests: JsonRpcRequest<RpcMethod>[], requestMap: RequestMap): Promise<void>;
21
24
  }
22
25
 
23
26
  export { WsClient as default };
@@ -1,23 +1,26 @@
1
- import Client, { Response } from './Client.js';
2
- import { RpcMethod, JsonRpcRequest } from './common.js';
1
+ import Client, { RequestMap } from './Client.js';
2
+ import { JsonRpcRequest, RpcMethod } from './common.js';
3
+ import '@chainflip/utils/async';
3
4
  import '@chainflip/utils/types';
4
5
  import 'zod';
5
6
  import './parsers.js';
6
7
 
7
8
  declare class WsClient extends Client {
8
- private readonly WebSocket;
9
9
  private ws?;
10
10
  private reconnectAttempts;
11
11
  private emitter;
12
- private requestMap;
13
- constructor(url: string, WebSocket?: typeof globalThis.WebSocket);
12
+ private inFlightRequestMap;
13
+ private readonly timeout;
14
+ private shouldConnect;
15
+ constructor(url: string, { timeout }?: {
16
+ timeout?: number;
17
+ });
14
18
  close(): Promise<void>;
15
- private handleClose;
16
19
  private connectionReady;
17
20
  private handleDisconnect;
18
21
  private handleMessage;
19
22
  private connect;
20
- protected send<const T extends RpcMethod>(requests: JsonRpcRequest<T>[]): Promise<Response[]>;
23
+ protected send(requests: JsonRpcRequest<RpcMethod>[], requestMap: RequestMap): Promise<void>;
21
24
  }
22
25
 
23
26
  export { WsClient as default };
package/dist/WsClient.mjs CHANGED
@@ -1,44 +1,47 @@
1
1
  // src/WsClient.ts
2
2
  import { deferredPromise, once, sleep } from "@chainflip/utils/async";
3
+ import { z } from "zod";
3
4
  import Client from "./Client.mjs";
4
5
  import { rpcResponse } from "./common.mjs";
6
+ var CONNECTING = "CONNECTING";
5
7
  var READY = "READY";
6
8
  var DISCONNECT = "DISCONNECT";
7
9
  var WsClient = class extends Client {
8
- constructor(url, WebSocket = globalThis.WebSocket) {
9
- super(url);
10
- this.WebSocket = WebSocket;
11
- }
12
10
  ws;
13
11
  reconnectAttempts = 0;
14
12
  emitter = new EventTarget();
15
- requestMap = /* @__PURE__ */ new Map();
16
- async close() {
17
- await this.handleClose();
13
+ inFlightRequestMap = /* @__PURE__ */ new Map();
14
+ timeout;
15
+ shouldConnect = true;
16
+ constructor(url, { timeout = 3e4 } = {}) {
17
+ super(url);
18
+ this.timeout = timeout;
18
19
  }
19
- async handleClose() {
20
+ async close() {
21
+ this.shouldConnect = false;
20
22
  if (!this.ws) return;
21
- this.ws.removeEventListener("close", this.handleDisconnect);
23
+ await this.handleDisconnect();
24
+ const waitForClose = this.ws.readyState === WebSocket.OPEN;
22
25
  this.ws.close();
23
- if (this.ws.readyState !== this.WebSocket.CLOSED) {
24
- await once(this.ws, "close");
25
- }
26
+ if (waitForClose) await once(this.ws, "close");
27
+ this.ws = void 0;
26
28
  }
27
29
  async connectionReady() {
28
30
  if (!this.ws) {
29
31
  return this.connect();
30
32
  }
31
- if (this.ws.readyState !== this.WebSocket.OPEN) {
33
+ if (this.ws.readyState !== WebSocket.OPEN) {
32
34
  await once(this.emitter, READY, { timeout: 3e4 });
33
35
  }
34
36
  return this.ws;
35
37
  }
36
38
  handleDisconnect = async () => {
37
39
  this.emitter.dispatchEvent(new Event(DISCONNECT));
38
- this.requestMap.forEach((request) => {
40
+ this.inFlightRequestMap.forEach((request) => {
39
41
  request.reject(new Error("disconnected"));
40
42
  });
41
- this.requestMap.clear();
43
+ this.inFlightRequestMap.clear();
44
+ if (!this.shouldConnect) return;
42
45
  const backoff = 250 * 2 ** this.reconnectAttempts;
43
46
  await sleep(backoff);
44
47
  await this.connect().catch(() => {
@@ -47,65 +50,75 @@ var WsClient = class extends Client {
47
50
  };
48
51
  handleMessage = (data) => {
49
52
  const parsedData = JSON.parse(data.data);
50
- const response = rpcResponse.safeParse(parsedData);
51
- if (!response.success) return;
52
- const { id } = response.data;
53
- this.requestMap.get(id)?.resolve(response.data);
53
+ const responses = z.array(rpcResponse).safeParse(parsedData);
54
+ if (!responses.success) return;
55
+ for (const response of responses.data) {
56
+ const { id } = response;
57
+ this.inFlightRequestMap.get(id)?.resolve(response);
58
+ }
54
59
  };
55
60
  async connect() {
56
- const socket = new this.WebSocket(this.url);
61
+ this.shouldConnect = true;
62
+ this.emitter.dispatchEvent(new Event(CONNECTING));
63
+ const socket = new WebSocket(this.url);
57
64
  this.ws = socket;
58
65
  this.ws.addEventListener("message", this.handleMessage);
66
+ let connected = false;
67
+ const handleConnectionError = () => {
68
+ if (!connected) {
69
+ void this.handleDisconnect();
70
+ }
71
+ };
59
72
  this.ws.addEventListener("close", this.handleDisconnect, { once: true });
60
- await once(this.ws, "open", { timeout: 3e4 });
73
+ this.ws.addEventListener("error", handleConnectionError, { once: true });
74
+ await once(this.ws, "open", { timeout: this.timeout });
75
+ connected = true;
61
76
  this.ws.addEventListener("error", () => {
62
77
  socket.close();
63
78
  });
64
79
  this.emitter.dispatchEvent(new Event(READY));
80
+ this.ws.removeEventListener("error", handleConnectionError);
65
81
  this.reconnectAttempts = 0;
66
82
  return socket;
67
83
  }
68
- async send(requests) {
69
- const responses = [];
70
- for (const data of requests) {
71
- const MAX_RETRIES = 5;
72
- for (let i = 0; i < MAX_RETRIES; i += 1) {
73
- let socket;
74
- try {
75
- socket = await this.connectionReady();
76
- } catch {
77
- continue;
78
- }
79
- socket.send(JSON.stringify(data));
80
- const request = deferredPromise();
81
- this.requestMap.set(data.id, request);
82
- const controller = new AbortController();
83
- const result = await Promise.race([
84
- sleep(3e4, { signal: controller.signal }).then(
85
- () => ({ success: false, retry: false, error: new Error("timeout") })
84
+ async send(requests, requestMap) {
85
+ const MAX_RETRIES = 5;
86
+ let socket;
87
+ for (let i = 0; i < MAX_RETRIES; i += 1) {
88
+ try {
89
+ socket = await this.connectionReady();
90
+ } catch {
91
+ continue;
92
+ }
93
+ }
94
+ if (!socket) {
95
+ this.handleErrorResponse(new Error("failed to connect"), requestMap);
96
+ return;
97
+ }
98
+ socket.send(JSON.stringify(requests));
99
+ const promises = [];
100
+ for (const [id] of requestMap) {
101
+ const result = deferredPromise();
102
+ const controller = new AbortController();
103
+ this.inFlightRequestMap.set(id, result);
104
+ promises.push(
105
+ Promise.race([
106
+ sleep(this.timeout, { signal: controller.signal }).then(
107
+ () => ({ id, success: false, error: new Error("timeout") })
86
108
  ),
87
- request.promise.then(
88
- (r) => ({ success: true, result: r }),
89
- (error) => ({ success: false, error, retry: true })
109
+ result.promise.then(
110
+ (r) => ({ id, success: true, result: r }),
111
+ (error) => ({ id, success: false, error })
90
112
  )
91
- ]).finally(() => {
92
- this.requestMap.delete(data.id);
113
+ ]).then((response) => {
114
+ this.handleResponse(response, requestMap);
115
+ }).finally(() => {
116
+ this.inFlightRequestMap.delete(id);
93
117
  controller.abort();
94
- });
95
- if (result.success || !result.retry) {
96
- responses.push({ ...result, id: data.id });
97
- break;
98
- }
99
- if (i === MAX_RETRIES - 1) {
100
- responses.push({
101
- success: false,
102
- error: new Error("max retries exceeded"),
103
- id: data.id
104
- });
105
- }
106
- }
118
+ })
119
+ );
107
120
  }
108
- return responses;
121
+ await Promise.all(promises);
109
122
  }
110
123
  };
111
124
  export {
package/dist/common.cjs CHANGED
@@ -26,7 +26,7 @@
26
26
  var _parserscjs = require('./parsers.cjs');
27
27
 
28
28
  var rpcResult = {
29
- broker_requestSwapDepositAddress: _parserscjs.brokerRequestSwapDepositAddress,
29
+ broker_request_swap_deposit_address: _parserscjs.brokerRequestSwapDepositAddress,
30
30
  broker_request_swap_parameter_encoding: _parserscjs.requestSwapParameterEncoding,
31
31
  cf_request_swap_parameter_encoding: _parserscjs.requestSwapParameterEncoding,
32
32
  cf_accounts: _parserscjs.cfAccounts,
package/dist/common.d.cts CHANGED
@@ -65,18 +65,18 @@ type RequestSwapParameterEncodingParams = [
65
65
  dcaParams?: Nullish<DcaParams>
66
66
  ];
67
67
  type RpcRequest = WithHash<{
68
- broker_requestSwapDepositAddress: [
68
+ broker_request_swap_deposit_address: [
69
69
  sourceAsset: UncheckedAssetAndChain,
70
70
  destinationAsset: UncheckedAssetAndChain,
71
71
  destinationAddress: string,
72
72
  brokerCommission: number,
73
- ccmMetadata?: Nullish<CcmParams>,
74
- boostFee?: Nullish<number>,
75
- affiliateFees?: Nullish<{
73
+ ccmMetadata: Nullish<CcmParams>,
74
+ boostFee: Nullish<number>,
75
+ affiliateFees: Nullish<{
76
76
  account: string;
77
77
  bps: number;
78
78
  }[]>,
79
- fillOrKillParams?: Nullish<FillOrKillParams>,
79
+ fillOrKillParams: FillOrKillParams,
80
80
  dcaParams?: Nullish<DcaParams>
81
81
  ];
82
82
  broker_request_swap_parameter_encoding: RequestSwapParameterEncodingParams;
@@ -154,7 +154,7 @@ type RpcRequest = WithHash<{
154
154
  chain_getBlockHash: [blockHeight?: number];
155
155
  };
156
156
  declare const rpcResult: {
157
- readonly broker_requestSwapDepositAddress: z.ZodObject<{
157
+ readonly broker_request_swap_deposit_address: z.ZodObject<{
158
158
  address: z.ZodString;
159
159
  issued_block: z.ZodNumber;
160
160
  channel_id: z.ZodNumber;
package/dist/common.d.ts CHANGED
@@ -65,18 +65,18 @@ type RequestSwapParameterEncodingParams = [
65
65
  dcaParams?: Nullish<DcaParams>
66
66
  ];
67
67
  type RpcRequest = WithHash<{
68
- broker_requestSwapDepositAddress: [
68
+ broker_request_swap_deposit_address: [
69
69
  sourceAsset: UncheckedAssetAndChain,
70
70
  destinationAsset: UncheckedAssetAndChain,
71
71
  destinationAddress: string,
72
72
  brokerCommission: number,
73
- ccmMetadata?: Nullish<CcmParams>,
74
- boostFee?: Nullish<number>,
75
- affiliateFees?: Nullish<{
73
+ ccmMetadata: Nullish<CcmParams>,
74
+ boostFee: Nullish<number>,
75
+ affiliateFees: Nullish<{
76
76
  account: string;
77
77
  bps: number;
78
78
  }[]>,
79
- fillOrKillParams?: Nullish<FillOrKillParams>,
79
+ fillOrKillParams: FillOrKillParams,
80
80
  dcaParams?: Nullish<DcaParams>
81
81
  ];
82
82
  broker_request_swap_parameter_encoding: RequestSwapParameterEncodingParams;
@@ -154,7 +154,7 @@ type RpcRequest = WithHash<{
154
154
  chain_getBlockHash: [blockHeight?: number];
155
155
  };
156
156
  declare const rpcResult: {
157
- readonly broker_requestSwapDepositAddress: z.ZodObject<{
157
+ readonly broker_request_swap_deposit_address: z.ZodObject<{
158
158
  address: z.ZodString;
159
159
  issued_block: z.ZodNumber;
160
160
  channel_id: z.ZodNumber;
package/dist/common.mjs CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  } from "./parsers.mjs";
27
27
  import { rpcResponse } from "./parsers.mjs";
28
28
  var rpcResult = {
29
- broker_requestSwapDepositAddress: brokerRequestSwapDepositAddress,
29
+ broker_request_swap_deposit_address: brokerRequestSwapDepositAddress,
30
30
  broker_request_swap_parameter_encoding: requestSwapParameterEncoding,
31
31
  cf_request_swap_parameter_encoding: requestSwapParameterEncoding,
32
32
  cf_accounts: cfAccounts,
package/dist/index.d.cts CHANGED
@@ -5,5 +5,6 @@ export { c as constants } from './constants-jLrn-AnI.cjs';
5
5
  export { RpcLimitOrder, RpcRangeOrder } from './parsers.cjs';
6
6
  export { RpcMethod, RpcRequest as RpcParams, RpcResult } from './common.cjs';
7
7
  import './Client.cjs';
8
+ import '@chainflip/utils/async';
8
9
  import 'zod';
9
10
  import '@chainflip/utils/types';
package/dist/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export { c as constants } from './constants-jLrn-AnI.js';
5
5
  export { RpcLimitOrder, RpcRangeOrder } from './parsers.js';
6
6
  export { RpcMethod, RpcRequest as RpcParams, RpcResult } from './common.js';
7
7
  import './Client.js';
8
+ import '@chainflip/utils/async';
8
9
  import 'zod';
9
10
  import '@chainflip/utils/types';
package/dist/parsers.cjs CHANGED
@@ -45,7 +45,7 @@ var rename = (mapping) => (obj) => Object.fromEntries(
45
45
  ])
46
46
  );
47
47
  var rpcBaseResponse = _zod.z.object({
48
- id: _zod.z.union([_zod.z.string(), _zod.z.number()]),
48
+ id: _zod.z.string(),
49
49
  jsonrpc: _zod.z.literal("2.0")
50
50
  });
51
51
  var nonNullish = _zod.z.any().refine(_guard.isNotNullish, { message: "Value must not be null or undefined" });
@@ -99,20 +99,20 @@ type Rename<T, U extends Record<string, string>> = Omit<T, keyof U> & {
99
99
  [K in keyof U as NonNullable<U[K]>]: K extends keyof T ? T[K] : never;
100
100
  };
101
101
  declare const rpcResponse: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
102
- id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
102
+ id: z.ZodString;
103
103
  jsonrpc: z.ZodLiteral<"2.0">;
104
104
  }, {
105
105
  result: z.ZodEffects<z.ZodAny, any, any>;
106
106
  }>, "strip", z.ZodTypeAny, {
107
- id: string | number;
107
+ id: string;
108
108
  jsonrpc: "2.0";
109
109
  result?: any;
110
110
  }, {
111
- id: string | number;
111
+ id: string;
112
112
  jsonrpc: "2.0";
113
113
  result?: any;
114
114
  }>, z.ZodObject<z.objectUtil.extendShape<{
115
- id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
115
+ id: z.ZodString;
116
116
  jsonrpc: z.ZodLiteral<"2.0">;
117
117
  }, {
118
118
  error: z.ZodObject<{
@@ -126,14 +126,14 @@ declare const rpcResponse: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
126
126
  message: string;
127
127
  }>;
128
128
  }>, "strip", z.ZodTypeAny, {
129
- id: string | number;
129
+ id: string;
130
130
  jsonrpc: "2.0";
131
131
  error: {
132
132
  code: number;
133
133
  message: string;
134
134
  };
135
135
  }, {
136
- id: string | number;
136
+ id: string;
137
137
  jsonrpc: "2.0";
138
138
  error: {
139
139
  code: number;
package/dist/parsers.d.ts CHANGED
@@ -99,20 +99,20 @@ type Rename<T, U extends Record<string, string>> = Omit<T, keyof U> & {
99
99
  [K in keyof U as NonNullable<U[K]>]: K extends keyof T ? T[K] : never;
100
100
  };
101
101
  declare const rpcResponse: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
102
- id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
102
+ id: z.ZodString;
103
103
  jsonrpc: z.ZodLiteral<"2.0">;
104
104
  }, {
105
105
  result: z.ZodEffects<z.ZodAny, any, any>;
106
106
  }>, "strip", z.ZodTypeAny, {
107
- id: string | number;
107
+ id: string;
108
108
  jsonrpc: "2.0";
109
109
  result?: any;
110
110
  }, {
111
- id: string | number;
111
+ id: string;
112
112
  jsonrpc: "2.0";
113
113
  result?: any;
114
114
  }>, z.ZodObject<z.objectUtil.extendShape<{
115
- id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
115
+ id: z.ZodString;
116
116
  jsonrpc: z.ZodLiteral<"2.0">;
117
117
  }, {
118
118
  error: z.ZodObject<{
@@ -126,14 +126,14 @@ declare const rpcResponse: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
126
126
  message: string;
127
127
  }>;
128
128
  }>, "strip", z.ZodTypeAny, {
129
- id: string | number;
129
+ id: string;
130
130
  jsonrpc: "2.0";
131
131
  error: {
132
132
  code: number;
133
133
  message: string;
134
134
  };
135
135
  }, {
136
- id: string | number;
136
+ id: string;
137
137
  jsonrpc: "2.0";
138
138
  error: {
139
139
  code: number;
package/dist/parsers.mjs CHANGED
@@ -45,7 +45,7 @@ var rename = (mapping) => (obj) => Object.fromEntries(
45
45
  ])
46
46
  );
47
47
  var rpcBaseResponse = z.object({
48
- id: z.union([z.string(), z.number()]),
48
+ id: z.string(),
49
49
  jsonrpc: z.literal("2.0")
50
50
  });
51
51
  var nonNullish = z.any().refine(isNotNullish, { message: "Value must not be null or undefined" });
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@chainflip/rpc",
3
- "version": "1.8.7",
3
+ "version": "1.8.8",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "@chainflip/utils": "0.6.0",
6
+ "@chainflip/utils": "0.7.0",
7
7
  "zod": "^3.24.2"
8
8
  },
9
9
  "devDependencies": {
10
- "@types/node": "^22.13.8",
11
- "@types/ws": "^8.5.14",
10
+ "@types/node": "^22.13.10",
11
+ "@types/ws": "^8.18.0",
12
12
  "ws": "^8.18.1"
13
13
  },
14
14
  "files": [