@chainflip/rpc 2.0.7 → 2.1.0-beta.1

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.
Files changed (44) hide show
  1. package/dist/Client.cjs +88 -91
  2. package/dist/Client.d.cts +30 -33
  3. package/dist/Client.d.mts +40 -0
  4. package/dist/Client.mjs +87 -90
  5. package/dist/HttpClient.cjs +33 -32
  6. package/dist/HttpClient.d.cts +5 -10
  7. package/dist/HttpClient.d.mts +9 -0
  8. package/dist/HttpClient.mjs +32 -31
  9. package/dist/WsClient.cjs +119 -124
  10. package/dist/WsClient.d.cts +22 -24
  11. package/dist/WsClient.d.mts +26 -0
  12. package/dist/WsClient.mjs +117 -122
  13. package/dist/_virtual/rolldown_runtime.cjs +19 -0
  14. package/dist/_virtual/rolldown_runtime.mjs +18 -0
  15. package/dist/common.cjs +55 -98
  16. package/dist/common.d.cts +30509 -26329
  17. package/dist/common.d.mts +31128 -0
  18. package/dist/common.mjs +54 -98
  19. package/dist/constants.cjs +16 -7
  20. package/dist/constants.d.cts +11 -1
  21. package/dist/constants.d.mts +11 -0
  22. package/dist/constants.mjs +12 -9
  23. package/dist/index.cjs +12 -10
  24. package/dist/index.d.cts +7 -11
  25. package/dist/index.d.mts +7 -0
  26. package/dist/index.mjs +5 -10
  27. package/dist/parsers.cjs +794 -750
  28. package/dist/parsers.d.cts +36279 -31216
  29. package/dist/parsers.d.mts +37053 -0
  30. package/dist/parsers.mjs +738 -746
  31. package/dist/types.cjs +0 -1
  32. package/dist/types.d.cts +6 -9
  33. package/dist/{types.d.ts → types.d.mts} +6 -9
  34. package/dist/types.mjs +1 -0
  35. package/package.json +6 -6
  36. package/dist/Client.d.ts +0 -43
  37. package/dist/HttpClient.d.ts +0 -13
  38. package/dist/WsClient.d.ts +0 -27
  39. package/dist/common.d.ts +0 -26948
  40. package/dist/constants-jLrn-AnI.d.cts +0 -13
  41. package/dist/constants-jLrn-AnI.d.ts +0 -13
  42. package/dist/constants.d.ts +0 -1
  43. package/dist/index.d.ts +0 -11
  44. package/dist/parsers.d.ts +0 -31990
package/dist/Client.cjs CHANGED
@@ -1,93 +1,90 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/Client.ts
2
- var _async = require('@chainflip/utils/async');
1
+ const require_common = require('./common.cjs');
2
+ let _chainflip_utils_async = require("@chainflip/utils/async");
3
3
 
4
+ //#region src/Client.ts
5
+ var Client = class {
6
+ lastRequestId = 0;
7
+ timer = null;
8
+ requestMap = /* @__PURE__ */ new Map();
9
+ archiveNodeUrl;
10
+ eventTarget = new EventTarget();
11
+ constructor(url, opts = {}) {
12
+ this.url = url;
13
+ this.archiveNodeUrl = opts.archiveNodeUrl;
14
+ }
15
+ getRequestId() {
16
+ try {
17
+ return crypto.randomUUID();
18
+ } catch {
19
+ return String(++this.lastRequestId);
20
+ }
21
+ }
22
+ formatRequest(method, params) {
23
+ return {
24
+ jsonrpc: "2.0",
25
+ id: this.getRequestId(),
26
+ method,
27
+ params
28
+ };
29
+ }
30
+ handleResponse(response, clonedMap) {
31
+ const clonedItem = clonedMap.get(response.id);
32
+ if (!clonedItem) return;
33
+ clonedMap.delete(response.id);
34
+ if (!response.success) return clonedItem.deferred.reject(response.error);
35
+ const rpcResponse = response.result;
36
+ if ("error" in rpcResponse) return clonedItem.deferred.reject(/* @__PURE__ */ new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`));
37
+ const parseResult = require_common.rpcResult[clonedItem.method].safeParse(rpcResponse.result);
38
+ if (parseResult.error) return clonedItem.deferred.reject(parseResult.error);
39
+ clonedItem.deferred.resolve(parseResult.data);
40
+ }
41
+ handleErrorResponse(error, clonedMap) {
42
+ for (const [id] of clonedMap) this.handleResponse({
43
+ id,
44
+ success: false,
45
+ error
46
+ }, clonedMap);
47
+ }
48
+ async handleBatch() {
49
+ const clonedMap = new Map(this.requestMap);
50
+ this.requestMap.clear();
51
+ const requests = [...clonedMap.values()].map((item) => item.body);
52
+ await this.send(requests, clonedMap);
53
+ clonedMap.forEach((item) => {
54
+ item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
55
+ });
56
+ }
57
+ sendRequest(method, ...params) {
58
+ if (!require_common.rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
59
+ const deferred = (0, _chainflip_utils_async.deferredPromise)();
60
+ const body = this.formatRequest(method, params);
61
+ this.requestMap.set(body.id, {
62
+ deferred,
63
+ body,
64
+ method
65
+ });
66
+ if (!this.timer) this.timer = setTimeout(() => {
67
+ this.timer = null;
68
+ this.handleBatch();
69
+ }, 0);
70
+ return deferred.promise.catch((error) => {
71
+ if (error instanceof Error) {
72
+ if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
73
+ this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
74
+ method,
75
+ params
76
+ } }));
77
+ return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
78
+ }
79
+ Error.captureStackTrace(error);
80
+ }
81
+ throw error;
82
+ });
83
+ }
84
+ methods() {
85
+ return Object.keys(require_common.rpcResult).sort();
86
+ }
87
+ };
4
88
 
5
- var _commoncjs = require('./common.cjs');
6
- var Client = (_class = class {
7
- constructor(url, opts = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);
8
- this.url = url;
9
- this.archiveNodeUrl = opts.archiveNodeUrl;
10
- }
11
- __init() {this.lastRequestId = 0}
12
- __init2() {this.timer = null}
13
- __init3() {this.requestMap = /* @__PURE__ */ new Map()}
14
-
15
- __init4() {this.eventTarget = new EventTarget()}
16
- getRequestId() {
17
- try {
18
- return crypto.randomUUID();
19
- } catch (e) {
20
- return String(++this.lastRequestId);
21
- }
22
- }
23
- formatRequest(method, params) {
24
- return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
25
- }
26
- handleResponse(response, clonedMap) {
27
- const clonedItem = clonedMap.get(response.id);
28
- if (!clonedItem) return;
29
- clonedMap.delete(response.id);
30
- if (!response.success) {
31
- return clonedItem.deferred.reject(response.error);
32
- }
33
- const rpcResponse = response.result;
34
- if ("error" in rpcResponse) {
35
- return clonedItem.deferred.reject(
36
- new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`)
37
- );
38
- }
39
- const parseResult = _commoncjs.rpcResult[clonedItem.method].safeParse(rpcResponse.result);
40
- if (parseResult.error) {
41
- return clonedItem.deferred.reject(parseResult.error);
42
- }
43
- clonedItem.deferred.resolve(parseResult.data);
44
- }
45
- handleErrorResponse(error, clonedMap) {
46
- for (const [id] of clonedMap) {
47
- this.handleResponse({ id, success: false, error }, clonedMap);
48
- }
49
- }
50
- async handleBatch() {
51
- const clonedMap = new Map(this.requestMap);
52
- this.requestMap.clear();
53
- const requests = [...clonedMap.values()].map((item) => item.body);
54
- await this.send(requests, clonedMap);
55
- clonedMap.forEach((item) => {
56
- item.deferred.reject(new Error("Could not find the result for the request"));
57
- });
58
- }
59
- sendRequest(method, ...params) {
60
- if (!_commoncjs.rpcResult[method]) {
61
- return Promise.reject(new Error(`Unknown method: ${method}`));
62
- }
63
- const deferred = _async.deferredPromise.call(void 0, );
64
- const body = this.formatRequest(method, params);
65
- this.requestMap.set(body.id, { deferred, body, method });
66
- if (!this.timer) {
67
- this.timer = setTimeout(() => {
68
- this.timer = null;
69
- void this.handleBatch();
70
- }, 0);
71
- }
72
- return deferred.promise.catch((error) => {
73
- if (error instanceof Error) {
74
- if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
75
- this.eventTarget.dispatchEvent(
76
- new CustomEvent("archiveNodeFallback", { detail: { method, params } })
77
- );
78
- return new this.constructor(
79
- this.archiveNodeUrl
80
- ).sendRequest(method, ...params);
81
- }
82
- Error.captureStackTrace(error);
83
- }
84
- throw error;
85
- });
86
- }
87
- methods() {
88
- return Object.keys(_commoncjs.rpcResult).sort();
89
- }
90
- }, _class);
91
-
92
-
93
- exports.default = Client;
89
+ //#endregion
90
+ module.exports = Client;
package/dist/Client.d.cts CHANGED
@@ -1,43 +1,40 @@
1
- import { DeferredPromise } from '@chainflip/utils/async';
2
- import { RpcMethod, JsonRpcRequest, RpcResult, JsonRpcResponse, RpcRequest } from './common.cjs';
3
- import '@chainflip/utils/chainflip';
4
- import '@chainflip/utils/types';
5
- import 'zod';
6
- import './parsers.cjs';
1
+ import { JsonRpcRequest, JsonRpcResponse, RpcMethod, RpcRequest, RpcResult } from "./common.cjs";
2
+ import { DeferredPromise } from "@chainflip/utils/async";
7
3
 
4
+ //#region src/Client.d.ts
8
5
  type Response = {
9
- success: true;
10
- id: string;
11
- result: JsonRpcResponse;
6
+ success: true;
7
+ id: string;
8
+ result: JsonRpcResponse;
12
9
  } | {
13
- success: false;
14
- id: string;
15
- error: Error;
10
+ success: false;
11
+ id: string;
12
+ error: Error;
16
13
  };
17
14
  type RequestMap = Map<string, {
18
- deferred: DeferredPromise<RpcResult<RpcMethod>>;
19
- body: JsonRpcRequest<RpcMethod>;
20
- method: RpcMethod;
15
+ deferred: DeferredPromise<RpcResult<RpcMethod>>;
16
+ body: JsonRpcRequest<RpcMethod>;
17
+ method: RpcMethod;
21
18
  }>;
22
19
  type ClientOpts = {
23
- archiveNodeUrl?: string;
20
+ archiveNodeUrl?: string;
24
21
  };
25
22
  declare abstract class Client {
26
- protected readonly url: string;
27
- private lastRequestId;
28
- private timer;
29
- private requestMap;
30
- private readonly archiveNodeUrl?;
31
- readonly eventTarget: EventTarget;
32
- constructor(url: string, opts?: ClientOpts);
33
- protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
34
- private getRequestId;
35
- private formatRequest;
36
- protected handleResponse(response: Response, clonedMap: RequestMap): void;
37
- protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
38
- private handleBatch;
39
- sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
40
- methods(): RpcMethod[];
23
+ protected readonly url: string;
24
+ private lastRequestId;
25
+ private timer;
26
+ private requestMap;
27
+ private readonly archiveNodeUrl?;
28
+ readonly eventTarget: EventTarget;
29
+ constructor(url: string, opts?: ClientOpts);
30
+ protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
31
+ private getRequestId;
32
+ private formatRequest;
33
+ protected handleResponse(response: Response, clonedMap: RequestMap): void;
34
+ protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
35
+ private handleBatch;
36
+ sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
37
+ methods(): RpcMethod[];
41
38
  }
42
-
43
- export { type ClientOpts, type RequestMap, type Response, Client as default };
39
+ //#endregion
40
+ export { ClientOpts, RequestMap, Response, Client as default };
@@ -0,0 +1,40 @@
1
+ import { JsonRpcRequest, JsonRpcResponse, RpcMethod, RpcRequest, RpcResult } from "./common.mjs";
2
+ import { DeferredPromise } from "@chainflip/utils/async";
3
+
4
+ //#region src/Client.d.ts
5
+ type Response = {
6
+ success: true;
7
+ id: string;
8
+ result: JsonRpcResponse;
9
+ } | {
10
+ success: false;
11
+ id: string;
12
+ error: Error;
13
+ };
14
+ type RequestMap = Map<string, {
15
+ deferred: DeferredPromise<RpcResult<RpcMethod>>;
16
+ body: JsonRpcRequest<RpcMethod>;
17
+ method: RpcMethod;
18
+ }>;
19
+ type ClientOpts = {
20
+ archiveNodeUrl?: string;
21
+ };
22
+ declare abstract class Client {
23
+ protected readonly url: string;
24
+ private lastRequestId;
25
+ private timer;
26
+ private requestMap;
27
+ private readonly archiveNodeUrl?;
28
+ readonly eventTarget: EventTarget;
29
+ constructor(url: string, opts?: ClientOpts);
30
+ protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
31
+ private getRequestId;
32
+ private formatRequest;
33
+ protected handleResponse(response: Response, clonedMap: RequestMap): void;
34
+ protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
35
+ private handleBatch;
36
+ sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
37
+ methods(): RpcMethod[];
38
+ }
39
+ //#endregion
40
+ export { ClientOpts, RequestMap, Response, Client as default };
package/dist/Client.mjs CHANGED
@@ -1,93 +1,90 @@
1
- // src/Client.ts
1
+ import { rpcResult } from "./common.mjs";
2
2
  import { deferredPromise } from "@chainflip/utils/async";
3
- import {
4
- rpcResult
5
- } from "./common.mjs";
3
+
4
+ //#region src/Client.ts
6
5
  var Client = class {
7
- constructor(url, opts = {}) {
8
- this.url = url;
9
- this.archiveNodeUrl = opts.archiveNodeUrl;
10
- }
11
- lastRequestId = 0;
12
- timer = null;
13
- requestMap = /* @__PURE__ */ new Map();
14
- archiveNodeUrl;
15
- eventTarget = new EventTarget();
16
- getRequestId() {
17
- try {
18
- return crypto.randomUUID();
19
- } catch {
20
- return String(++this.lastRequestId);
21
- }
22
- }
23
- formatRequest(method, params) {
24
- return { jsonrpc: "2.0", id: this.getRequestId(), method, params };
25
- }
26
- handleResponse(response, clonedMap) {
27
- const clonedItem = clonedMap.get(response.id);
28
- if (!clonedItem) return;
29
- clonedMap.delete(response.id);
30
- if (!response.success) {
31
- return clonedItem.deferred.reject(response.error);
32
- }
33
- const rpcResponse = response.result;
34
- if ("error" in rpcResponse) {
35
- return clonedItem.deferred.reject(
36
- new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`)
37
- );
38
- }
39
- const parseResult = rpcResult[clonedItem.method].safeParse(rpcResponse.result);
40
- if (parseResult.error) {
41
- return clonedItem.deferred.reject(parseResult.error);
42
- }
43
- clonedItem.deferred.resolve(parseResult.data);
44
- }
45
- handleErrorResponse(error, clonedMap) {
46
- for (const [id] of clonedMap) {
47
- this.handleResponse({ id, success: false, error }, clonedMap);
48
- }
49
- }
50
- async handleBatch() {
51
- const clonedMap = new Map(this.requestMap);
52
- this.requestMap.clear();
53
- const requests = [...clonedMap.values()].map((item) => item.body);
54
- await this.send(requests, clonedMap);
55
- clonedMap.forEach((item) => {
56
- item.deferred.reject(new Error("Could not find the result for the request"));
57
- });
58
- }
59
- sendRequest(method, ...params) {
60
- if (!rpcResult[method]) {
61
- return Promise.reject(new Error(`Unknown method: ${method}`));
62
- }
63
- const deferred = deferredPromise();
64
- const body = this.formatRequest(method, params);
65
- this.requestMap.set(body.id, { deferred, body, method });
66
- if (!this.timer) {
67
- this.timer = setTimeout(() => {
68
- this.timer = null;
69
- void this.handleBatch();
70
- }, 0);
71
- }
72
- return deferred.promise.catch((error) => {
73
- if (error instanceof Error) {
74
- if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
75
- this.eventTarget.dispatchEvent(
76
- new CustomEvent("archiveNodeFallback", { detail: { method, params } })
77
- );
78
- return new this.constructor(
79
- this.archiveNodeUrl
80
- ).sendRequest(method, ...params);
81
- }
82
- Error.captureStackTrace(error);
83
- }
84
- throw error;
85
- });
86
- }
87
- methods() {
88
- return Object.keys(rpcResult).sort();
89
- }
90
- };
91
- export {
92
- Client as default
6
+ lastRequestId = 0;
7
+ timer = null;
8
+ requestMap = /* @__PURE__ */ new Map();
9
+ archiveNodeUrl;
10
+ eventTarget = new EventTarget();
11
+ constructor(url, opts = {}) {
12
+ this.url = url;
13
+ this.archiveNodeUrl = opts.archiveNodeUrl;
14
+ }
15
+ getRequestId() {
16
+ try {
17
+ return crypto.randomUUID();
18
+ } catch {
19
+ return String(++this.lastRequestId);
20
+ }
21
+ }
22
+ formatRequest(method, params) {
23
+ return {
24
+ jsonrpc: "2.0",
25
+ id: this.getRequestId(),
26
+ method,
27
+ params
28
+ };
29
+ }
30
+ handleResponse(response, clonedMap) {
31
+ const clonedItem = clonedMap.get(response.id);
32
+ if (!clonedItem) return;
33
+ clonedMap.delete(response.id);
34
+ if (!response.success) return clonedItem.deferred.reject(response.error);
35
+ const rpcResponse = response.result;
36
+ if ("error" in rpcResponse) return clonedItem.deferred.reject(/* @__PURE__ */ new Error(`RPC error [${rpcResponse.error.code}]: ${rpcResponse.error.message}`));
37
+ const parseResult = rpcResult[clonedItem.method].safeParse(rpcResponse.result);
38
+ if (parseResult.error) return clonedItem.deferred.reject(parseResult.error);
39
+ clonedItem.deferred.resolve(parseResult.data);
40
+ }
41
+ handleErrorResponse(error, clonedMap) {
42
+ for (const [id] of clonedMap) this.handleResponse({
43
+ id,
44
+ success: false,
45
+ error
46
+ }, clonedMap);
47
+ }
48
+ async handleBatch() {
49
+ const clonedMap = new Map(this.requestMap);
50
+ this.requestMap.clear();
51
+ const requests = [...clonedMap.values()].map((item) => item.body);
52
+ await this.send(requests, clonedMap);
53
+ clonedMap.forEach((item) => {
54
+ item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
55
+ });
56
+ }
57
+ sendRequest(method, ...params) {
58
+ if (!rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
59
+ const deferred = deferredPromise();
60
+ const body = this.formatRequest(method, params);
61
+ this.requestMap.set(body.id, {
62
+ deferred,
63
+ body,
64
+ method
65
+ });
66
+ if (!this.timer) this.timer = setTimeout(() => {
67
+ this.timer = null;
68
+ this.handleBatch();
69
+ }, 0);
70
+ return deferred.promise.catch((error) => {
71
+ if (error instanceof Error) {
72
+ if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
73
+ this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
74
+ method,
75
+ params
76
+ } }));
77
+ return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
78
+ }
79
+ Error.captureStackTrace(error);
80
+ }
81
+ throw error;
82
+ });
83
+ }
84
+ methods() {
85
+ return Object.keys(rpcResult).sort();
86
+ }
93
87
  };
88
+
89
+ //#endregion
90
+ export { Client as default };
@@ -1,34 +1,35 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/HttpClient.ts
2
- var _Clientcjs = require('./Client.cjs'); var _Clientcjs2 = _interopRequireDefault(_Clientcjs);
3
- var HttpClient = class extends _Clientcjs2.default {
4
- async send(request, requestMap) {
5
- let res;
6
- try {
7
- res = await fetch(this.url, {
8
- body: JSON.stringify(request),
9
- method: "POST",
10
- headers: {
11
- "Content-Type": "application/json"
12
- }
13
- });
14
- } catch (error) {
15
- this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
16
- return;
17
- }
18
- if (!res.ok) {
19
- this.handleErrorResponse(new Error(`HTTP error: ${res.status}`), requestMap);
20
- return;
21
- }
22
- try {
23
- const jsonRpcResponse = await res.json();
24
- for (const r of jsonRpcResponse) {
25
- this.handleResponse({ id: r.id, success: true, result: r }, requestMap);
26
- }
27
- } catch (cause) {
28
- this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
29
- }
30
- }
31
- };
1
+ const require_Client = require('./Client.cjs');
32
2
 
3
+ //#region src/HttpClient.ts
4
+ var HttpClient = class extends require_Client {
5
+ async send(request, requestMap) {
6
+ let res;
7
+ try {
8
+ res = await fetch(this.url, {
9
+ body: JSON.stringify(request),
10
+ method: "POST",
11
+ headers: { "Content-Type": "application/json" }
12
+ });
13
+ } catch (error) {
14
+ this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
15
+ return;
16
+ }
17
+ if (!res.ok) {
18
+ this.handleErrorResponse(/* @__PURE__ */ new Error(`HTTP error: ${res.status}`), requestMap);
19
+ return;
20
+ }
21
+ try {
22
+ const jsonRpcResponse = await res.json();
23
+ for (const r of jsonRpcResponse) this.handleResponse({
24
+ id: r.id,
25
+ success: true,
26
+ result: r
27
+ }, requestMap);
28
+ } catch (cause) {
29
+ this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
30
+ }
31
+ }
32
+ };
33
33
 
34
- exports.default = HttpClient;
34
+ //#endregion
35
+ module.exports = HttpClient;
@@ -1,13 +1,8 @@
1
- import Client, { RequestMap } from './Client.cjs';
2
- import { RpcMethod, JsonRpcRequest } from './common.cjs';
3
- import '@chainflip/utils/async';
4
- import '@chainflip/utils/chainflip';
5
- import '@chainflip/utils/types';
6
- import 'zod';
7
- import './parsers.cjs';
1
+ import { JsonRpcRequest, RpcMethod } from "./common.cjs";
2
+ import Client, { RequestMap } from "./Client.cjs";
8
3
 
4
+ //#region src/HttpClient.d.ts
9
5
  declare class HttpClient extends Client {
10
- protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[], requestMap: RequestMap): Promise<void>;
6
+ protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[], requestMap: RequestMap): Promise<void>;
11
7
  }
12
-
13
- export { HttpClient as default };
8
+ export = HttpClient;
@@ -0,0 +1,9 @@
1
+ import { JsonRpcRequest, RpcMethod } from "./common.mjs";
2
+ import Client, { RequestMap } from "./Client.mjs";
3
+
4
+ //#region src/HttpClient.d.ts
5
+ declare class HttpClient extends Client {
6
+ protected send<const T extends RpcMethod>(request: JsonRpcRequest<T>[], requestMap: RequestMap): Promise<void>;
7
+ }
8
+ //#endregion
9
+ export { HttpClient as default };
@@ -1,34 +1,35 @@
1
- // src/HttpClient.ts
2
1
  import Client from "./Client.mjs";
2
+
3
+ //#region src/HttpClient.ts
3
4
  var HttpClient = class extends Client {
4
- async send(request, requestMap) {
5
- let res;
6
- try {
7
- res = await fetch(this.url, {
8
- body: JSON.stringify(request),
9
- method: "POST",
10
- headers: {
11
- "Content-Type": "application/json"
12
- }
13
- });
14
- } catch (error) {
15
- this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
16
- return;
17
- }
18
- if (!res.ok) {
19
- this.handleErrorResponse(new Error(`HTTP error: ${res.status}`), requestMap);
20
- return;
21
- }
22
- try {
23
- const jsonRpcResponse = await res.json();
24
- for (const r of jsonRpcResponse) {
25
- this.handleResponse({ id: r.id, success: true, result: r }, requestMap);
26
- }
27
- } catch (cause) {
28
- this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
29
- }
30
- }
31
- };
32
- export {
33
- HttpClient as default
5
+ async send(request, requestMap) {
6
+ let res;
7
+ try {
8
+ res = await fetch(this.url, {
9
+ body: JSON.stringify(request),
10
+ method: "POST",
11
+ headers: { "Content-Type": "application/json" }
12
+ });
13
+ } catch (error) {
14
+ this.handleErrorResponse(new Error("Network error", { cause: error }), requestMap);
15
+ return;
16
+ }
17
+ if (!res.ok) {
18
+ this.handleErrorResponse(/* @__PURE__ */ new Error(`HTTP error: ${res.status}`), requestMap);
19
+ return;
20
+ }
21
+ try {
22
+ const jsonRpcResponse = await res.json();
23
+ for (const r of jsonRpcResponse) this.handleResponse({
24
+ id: r.id,
25
+ success: true,
26
+ result: r
27
+ }, requestMap);
28
+ } catch (cause) {
29
+ this.handleErrorResponse(new Error("Invalid JSON response", { cause }), requestMap);
30
+ }
31
+ }
34
32
  };
33
+
34
+ //#endregion
35
+ export { HttpClient as default };