@lodestar/api 1.19.0 → 1.20.0-dev.0cb3998a2a

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 (228) hide show
  1. package/README.md +10 -17
  2. package/lib/beacon/client/beacon.d.ts +4 -3
  3. package/lib/beacon/client/beacon.js +3 -36
  4. package/lib/beacon/client/beacon.js.map +1 -1
  5. package/lib/beacon/client/config.d.ts +4 -3
  6. package/lib/beacon/client/config.js +3 -6
  7. package/lib/beacon/client/config.js.map +1 -1
  8. package/lib/beacon/client/debug.d.ts +4 -3
  9. package/lib/beacon/client/debug.js +4 -45
  10. package/lib/beacon/client/debug.js.map +1 -1
  11. package/lib/beacon/client/events.d.ts +5 -2
  12. package/lib/beacon/client/events.js +33 -35
  13. package/lib/beacon/client/events.js.map +1 -1
  14. package/lib/beacon/client/index.d.ts +8 -3
  15. package/lib/beacon/client/index.js +3 -2
  16. package/lib/beacon/client/index.js.map +1 -1
  17. package/lib/beacon/client/lightclient.d.ts +4 -3
  18. package/lib/beacon/client/lightclient.js +4 -7
  19. package/lib/beacon/client/lightclient.js.map +1 -1
  20. package/lib/beacon/client/lodestar.d.ts +4 -3
  21. package/lib/beacon/client/lodestar.js +4 -7
  22. package/lib/beacon/client/lodestar.js.map +1 -1
  23. package/lib/beacon/client/node.d.ts +4 -3
  24. package/lib/beacon/client/node.js +4 -7
  25. package/lib/beacon/client/node.js.map +1 -1
  26. package/lib/beacon/client/proof.d.ts +5 -4
  27. package/lib/beacon/client/proof.js +5 -61
  28. package/lib/beacon/client/proof.js.map +1 -1
  29. package/lib/beacon/client/validator.d.ts +4 -3
  30. package/lib/beacon/client/validator.js +4 -7
  31. package/lib/beacon/client/validator.js.map +1 -1
  32. package/lib/beacon/index.d.ts +5 -5
  33. package/lib/beacon/index.js.map +1 -1
  34. package/lib/beacon/routes/beacon/block.d.ts +286 -167
  35. package/lib/beacon/routes/beacon/block.js +317 -117
  36. package/lib/beacon/routes/beacon/block.js.map +1 -1
  37. package/lib/beacon/routes/beacon/index.d.ts +6 -588
  38. package/lib/beacon/routes/beacon/index.js +16 -26
  39. package/lib/beacon/routes/beacon/index.js.map +1 -1
  40. package/lib/beacon/routes/beacon/pool.d.ts +155 -117
  41. package/lib/beacon/routes/beacon/pool.js +146 -42
  42. package/lib/beacon/routes/beacon/pool.js.map +1 -1
  43. package/lib/beacon/routes/beacon/rewards.d.ts +113 -101
  44. package/lib/beacon/routes/beacon/rewards.js +98 -63
  45. package/lib/beacon/routes/beacon/rewards.js.map +1 -1
  46. package/lib/beacon/routes/beacon/state.d.ts +172 -226
  47. package/lib/beacon/routes/beacon/state.js +204 -126
  48. package/lib/beacon/routes/beacon/state.js.map +1 -1
  49. package/lib/beacon/routes/config.d.ts +21 -36
  50. package/lib/beacon/routes/config.js +45 -24
  51. package/lib/beacon/routes/config.js.map +1 -1
  52. package/lib/beacon/routes/debug.d.ts +22 -104
  53. package/lib/beacon/routes/debug.js +53 -45
  54. package/lib/beacon/routes/debug.js.map +1 -1
  55. package/lib/beacon/routes/events.d.ts +24 -20
  56. package/lib/beacon/routes/events.js +40 -18
  57. package/lib/beacon/routes/events.js.map +1 -1
  58. package/lib/beacon/routes/index.d.ts +19 -19
  59. package/lib/beacon/routes/index.js +1 -0
  60. package/lib/beacon/routes/index.js.map +1 -1
  61. package/lib/beacon/routes/lightclient.d.ts +34 -56
  62. package/lib/beacon/routes/lightclient.js +108 -48
  63. package/lib/beacon/routes/lightclient.js.map +1 -1
  64. package/lib/beacon/routes/lodestar.d.ts +74 -148
  65. package/lib/beacon/routes/lodestar.js +126 -77
  66. package/lib/beacon/routes/lodestar.js.map +1 -1
  67. package/lib/beacon/routes/node.d.ts +48 -82
  68. package/lib/beacon/routes/node.js +90 -57
  69. package/lib/beacon/routes/node.js.map +1 -1
  70. package/lib/beacon/routes/proof.d.ts +25 -31
  71. package/lib/beacon/routes/proof.js +44 -24
  72. package/lib/beacon/routes/proof.js.map +1 -1
  73. package/lib/beacon/routes/validator.d.ts +524 -325
  74. package/lib/beacon/routes/validator.js +468 -213
  75. package/lib/beacon/routes/validator.js.map +1 -1
  76. package/lib/beacon/server/beacon.d.ts +3 -4
  77. package/lib/beacon/server/beacon.js +4 -57
  78. package/lib/beacon/server/beacon.js.map +1 -1
  79. package/lib/beacon/server/config.d.ts +3 -4
  80. package/lib/beacon/server/config.js +4 -5
  81. package/lib/beacon/server/config.js.map +1 -1
  82. package/lib/beacon/server/debug.d.ts +3 -4
  83. package/lib/beacon/server/debug.js +4 -54
  84. package/lib/beacon/server/debug.js.map +1 -1
  85. package/lib/beacon/server/events.d.ts +4 -4
  86. package/lib/beacon/server/events.js +17 -23
  87. package/lib/beacon/server/events.js.map +1 -1
  88. package/lib/beacon/server/index.d.ts +7 -8
  89. package/lib/beacon/server/index.js +13 -14
  90. package/lib/beacon/server/index.js.map +1 -1
  91. package/lib/beacon/server/lightclient.d.ts +3 -4
  92. package/lib/beacon/server/lightclient.js +4 -5
  93. package/lib/beacon/server/lightclient.js.map +1 -1
  94. package/lib/beacon/server/lodestar.d.ts +3 -4
  95. package/lib/beacon/server/lodestar.js +4 -5
  96. package/lib/beacon/server/lodestar.js.map +1 -1
  97. package/lib/beacon/server/node.d.ts +3 -4
  98. package/lib/beacon/server/node.js +4 -18
  99. package/lib/beacon/server/node.js.map +1 -1
  100. package/lib/beacon/server/proof.d.ts +3 -4
  101. package/lib/beacon/server/proof.js +4 -36
  102. package/lib/beacon/server/proof.js.map +1 -1
  103. package/lib/beacon/server/validator.d.ts +3 -4
  104. package/lib/beacon/server/validator.js +4 -21
  105. package/lib/beacon/server/validator.js.map +1 -1
  106. package/lib/builder/client.d.ts +4 -6
  107. package/lib/builder/client.js +3 -9
  108. package/lib/builder/client.js.map +1 -1
  109. package/lib/builder/index.d.ts +8 -5
  110. package/lib/builder/index.js +4 -1
  111. package/lib/builder/index.js.map +1 -1
  112. package/lib/builder/routes.d.ts +25 -39
  113. package/lib/builder/routes.js +78 -34
  114. package/lib/builder/routes.js.map +1 -1
  115. package/lib/builder/server/index.d.ts +6 -6
  116. package/lib/builder/server/index.js +7 -8
  117. package/lib/builder/server/index.js.map +1 -1
  118. package/lib/index.d.ts +9 -6
  119. package/lib/index.js +5 -4
  120. package/lib/index.js.map +1 -1
  121. package/lib/keymanager/client.d.ts +4 -3
  122. package/lib/keymanager/client.js +4 -7
  123. package/lib/keymanager/client.js.map +1 -1
  124. package/lib/keymanager/index.d.ts +5 -4
  125. package/lib/keymanager/index.js +1 -1
  126. package/lib/keymanager/index.js.map +1 -1
  127. package/lib/keymanager/routes.d.ts +155 -177
  128. package/lib/keymanager/routes.js +236 -123
  129. package/lib/keymanager/routes.js.map +1 -1
  130. package/lib/keymanager/server/index.d.ts +6 -6
  131. package/lib/keymanager/server/index.js +7 -8
  132. package/lib/keymanager/server/index.js.map +1 -1
  133. package/lib/server/index.d.ts +2 -0
  134. package/lib/server/index.js +3 -0
  135. package/lib/server/index.js.map +1 -0
  136. package/lib/utils/client/error.d.ts +6 -0
  137. package/lib/utils/client/error.js +8 -0
  138. package/lib/utils/client/error.js.map +1 -0
  139. package/lib/utils/client/httpClient.d.ts +38 -76
  140. package/lib/utils/client/httpClient.js +201 -153
  141. package/lib/utils/client/httpClient.js.map +1 -1
  142. package/lib/utils/client/index.d.ts +6 -2
  143. package/lib/utils/client/index.js +6 -2
  144. package/lib/utils/client/index.js.map +1 -1
  145. package/lib/utils/client/method.d.ts +11 -0
  146. package/lib/utils/client/method.js +27 -0
  147. package/lib/utils/client/method.js.map +1 -0
  148. package/lib/utils/client/request.d.ts +33 -0
  149. package/lib/utils/client/request.js +66 -0
  150. package/lib/utils/client/request.js.map +1 -0
  151. package/lib/utils/client/response.d.ts +36 -0
  152. package/lib/utils/client/response.js +167 -0
  153. package/lib/utils/client/response.js.map +1 -0
  154. package/lib/utils/codecs.d.ts +28 -0
  155. package/lib/utils/codecs.js +105 -0
  156. package/lib/utils/codecs.js.map +1 -0
  157. package/lib/utils/fork.d.ts +7 -0
  158. package/lib/utils/fork.js +29 -0
  159. package/lib/utils/fork.js.map +1 -0
  160. package/lib/utils/headers.d.ts +37 -0
  161. package/lib/utils/headers.js +134 -0
  162. package/lib/utils/headers.js.map +1 -0
  163. package/lib/utils/httpStatusCode.js.map +1 -0
  164. package/lib/utils/index.d.ts +1 -1
  165. package/lib/utils/index.js +1 -1
  166. package/lib/utils/index.js.map +1 -1
  167. package/lib/utils/metadata.d.ts +88 -0
  168. package/lib/utils/metadata.js +126 -0
  169. package/lib/utils/metadata.js.map +1 -0
  170. package/lib/utils/schema.d.ts +31 -17
  171. package/lib/utils/schema.js +18 -6
  172. package/lib/utils/schema.js.map +1 -1
  173. package/lib/utils/serdes.d.ts +3 -0
  174. package/lib/utils/serdes.js +13 -0
  175. package/lib/utils/serdes.js.map +1 -1
  176. package/lib/utils/server/{errors.d.ts → error.d.ts} +2 -2
  177. package/lib/utils/server/{errors.js → error.js} +1 -1
  178. package/lib/utils/server/error.js.map +1 -0
  179. package/lib/utils/server/handler.d.ts +11 -0
  180. package/lib/utils/server/handler.js +115 -0
  181. package/lib/utils/server/handler.js.map +1 -0
  182. package/lib/utils/server/index.d.ts +5 -4
  183. package/lib/utils/server/index.js +5 -4
  184. package/lib/utils/server/index.js.map +1 -1
  185. package/lib/utils/server/method.d.ts +35 -0
  186. package/lib/utils/server/method.js +2 -0
  187. package/lib/utils/server/method.js.map +1 -0
  188. package/lib/utils/server/parser.d.ts +3 -0
  189. package/lib/utils/server/parser.js +20 -0
  190. package/lib/utils/server/parser.js.map +1 -0
  191. package/lib/utils/server/route.d.ts +20 -0
  192. package/lib/utils/server/route.js +19 -0
  193. package/lib/utils/server/route.js.map +1 -0
  194. package/lib/utils/types.d.ts +116 -104
  195. package/lib/utils/types.js +2 -155
  196. package/lib/utils/types.js.map +1 -1
  197. package/lib/utils/urlFormat.d.ts +2 -2
  198. package/lib/utils/urlFormat.js +3 -3
  199. package/lib/utils/urlFormat.js.map +1 -1
  200. package/lib/utils/wireFormat.d.ts +8 -0
  201. package/lib/utils/wireFormat.js +23 -0
  202. package/lib/utils/wireFormat.js.map +1 -0
  203. package/package.json +10 -7
  204. package/lib/interfaces.d.ts +0 -44
  205. package/lib/interfaces.js +0 -2
  206. package/lib/interfaces.js.map +0 -1
  207. package/lib/utils/acceptHeader.d.ts +0 -9
  208. package/lib/utils/acceptHeader.js +0 -62
  209. package/lib/utils/acceptHeader.js.map +0 -1
  210. package/lib/utils/client/client.d.ts +0 -29
  211. package/lib/utils/client/client.js +0 -88
  212. package/lib/utils/client/client.js.map +0 -1
  213. package/lib/utils/client/httpStatusCode.js.map +0 -1
  214. package/lib/utils/routes.d.ts +0 -6
  215. package/lib/utils/routes.js +0 -31
  216. package/lib/utils/routes.js.map +0 -1
  217. package/lib/utils/server/errors.js.map +0 -1
  218. package/lib/utils/server/genericJsonServer.d.ts +0 -13
  219. package/lib/utils/server/genericJsonServer.js +0 -32
  220. package/lib/utils/server/genericJsonServer.js.map +0 -1
  221. package/lib/utils/server/registerRoute.d.ts +0 -3
  222. package/lib/utils/server/registerRoute.js +0 -13
  223. package/lib/utils/server/registerRoute.js.map +0 -1
  224. package/lib/utils/server/types.d.ts +0 -22
  225. package/lib/utils/server/types.js +0 -2
  226. package/lib/utils/server/types.js.map +0 -1
  227. /package/lib/utils/{client/httpStatusCode.d.ts → httpStatusCode.d.ts} +0 -0
  228. /package/lib/utils/{client/httpStatusCode.js → httpStatusCode.js} +0 -0
package/README.md CHANGED
@@ -1,36 +1,29 @@
1
1
  # Lodestar Eth Consensus API
2
2
 
3
3
  [![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
4
- [![ETH Beacon APIs Spec v2.1.0](https://img.shields.io/badge/ETH%20beacon--APIs-2.1.0-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.1.0)
4
+ [![ETH Beacon APIs Spec v2.5.0](https://img.shields.io/badge/ETH%20beacon--APIs-2.5.0-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.5.0)
5
5
  ![ES Version](https://img.shields.io/badge/ES-2021-yellow)
6
6
  ![Node Version](https://img.shields.io/badge/node-22.x-green)
7
7
 
8
8
  > This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
9
9
 
10
- Typescript REST client for the [Ethereum Consensus API spec](https://github.com/ethereum/beacon-apis)
10
+ Typescript REST client for the [Ethereum Consensus API](https://github.com/ethereum/beacon-apis)
11
11
 
12
12
  ## Usage
13
13
 
14
- We use more typesafe approach for the API client, where all the errors are returned not thrown. This approach is more easy to document and better to handle all possible error cases.
14
+ The REST client extends the native [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), it behaves very similar in terms of error and response handling. It returns the same [Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response) with additional methods to simplify usage and it allows to override all [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) if needed.
15
15
 
16
16
  ```typescript
17
- import {getClient, HttpError} from "@lodestar/api";
17
+ import {getClient} from "@lodestar/api";
18
18
  import {config} from "@lodestar/config/default";
19
19
 
20
20
  const api = getClient({baseUrl: "http://localhost:9596"}, {config});
21
21
 
22
- api.beacon
23
- .getStateValidator(
24
- "head",
25
- "0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f7329267a8811c397529dac52ae1342ba58c95"
26
- )
27
- .then((res) => {
28
- if (res.ok) {
29
- console.log("Your balance is:", res.response.data.balance, res.ok, res.status);
30
- } else {
31
- console.error(res.status, res.error.code, res.error.message);
32
- }
33
- });
22
+ const res = await api.beacon.getStateValidator({stateId: "head", validatorId: 0});
23
+
24
+ const validator = res.value();
25
+
26
+ console.log("The validator balance is: ", validator.balance);
34
27
  ```
35
28
 
36
29
  ## Prerequisites
@@ -45,7 +38,7 @@ You will need to go over the [specification](https://github.com/ethereum/beacon-
45
38
  ## Getting started
46
39
 
47
40
  - Follow the [installation guide](https://chainsafe.github.io/lodestar/) to install Lodestar.
48
- - Quickly try out the whole stack by [starting a local testnet](https://chainsafe.github.io/lodestar/advanced-topics/setting-up-a-testnet/).
41
+ - Quickly try out the whole stack by [starting a local testnet](https://chainsafe.github.io/lodestar/contribution/advanced-topics/setting-up-a-testnet/).
49
42
 
50
43
  ## Contributors
51
44
 
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { Api } from "../routes/beacon/index.js";
3
- import { IHttpClient } from "../../utils/client/index.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/beacon/index.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
6
  * REST HTTP client for beacon routes
6
7
  */
7
- export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=beacon.d.ts.map
@@ -1,42 +1,9 @@
1
- import { routesData, getReqSerializers, getReturnTypes } from "../routes/beacon/index.js";
2
- import { generateGenericJsonClient, getFetchOptsSerializers } from "../../utils/client/index.js";
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/beacon/index.js";
3
3
  /**
4
4
  * REST HTTP client for beacon routes
5
5
  */
6
6
  export function getClient(config, httpClient) {
7
- const reqSerializers = getReqSerializers(config);
8
- const returnTypes = getReturnTypes();
9
- // Some routes return JSON, use a client auto-generator
10
- const client = generateGenericJsonClient(routesData, reqSerializers, returnTypes, httpClient);
11
- const fetchOptsSerializer = getFetchOptsSerializers(routesData, reqSerializers);
12
- return {
13
- ...client,
14
- async getBlock(blockId, format) {
15
- if (format === "ssz") {
16
- const res = await httpClient.arrayBuffer({
17
- ...fetchOptsSerializer.getBlock(blockId, format),
18
- });
19
- return {
20
- ok: true,
21
- response: new Uint8Array(res.body),
22
- status: res.status,
23
- };
24
- }
25
- return client.getBlock(blockId, format);
26
- },
27
- async getBlockV2(blockId, format) {
28
- if (format === "ssz") {
29
- const res = await httpClient.arrayBuffer({
30
- ...fetchOptsSerializer.getBlockV2(blockId, format),
31
- });
32
- return {
33
- ok: true,
34
- response: new Uint8Array(res.body),
35
- status: res.status,
36
- };
37
- }
38
- return client.getBlockV2(blockId, format);
39
- },
40
- };
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
41
8
  }
42
9
  //# sourceMappingURL=beacon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"beacon.js","sourceRoot":"","sources":["../../../src/beacon/client/beacon.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAU,MAAM,2BAA2B,CAAC;AAChH,OAAO,EAAc,yBAAyB,EAAE,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AAI5G;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,MAAM,cAAc,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,uDAAuD;IACvD,MAAM,MAAM,GAAG,yBAAyB,CAAgB,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAQ,CAAC;IACpH,MAAM,mBAAmB,GAAG,uBAAuB,CAAgB,UAAU,EAAE,cAAc,CAAC,CAAC;IAE/F,OAAO;QACL,GAAG,MAAM;QACT,KAAK,CAAC,QAAQ,CAAoC,OAAgB,EAAE,MAAU;YAC5E,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;gBACrB,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC;oBACvC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;iBACjD,CAAC,CAAC;gBACH,OAAO;oBACL,EAAE,EAAE,IAAI;oBACR,QAAQ,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;oBAClC,MAAM,EAAE,GAAG,CAAC,MAAM;iBACC,CAAC;YACxB,CAAC;YACD,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;QACD,KAAK,CAAC,UAAU,CAAoC,OAAgB,EAAE,MAAU;YAC9E,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;gBACrB,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC;oBACvC,GAAG,mBAAmB,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC;iBACnD,CAAC,CAAC;gBACH,OAAO;oBACL,EAAE,EAAE,IAAI;oBACR,QAAQ,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;oBAClC,MAAM,EAAE,GAAG,CAAC,MAAM;iBACG,CAAC;YAC1B,CAAC;YACD,OAAO,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"beacon.js","sourceRoot":"","sources":["../../../src/beacon/client/beacon.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAY,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAIpE;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,OAAO,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { IHttpClient } from "../../utils/client/index.js";
3
- import { Api } from "../routes/config.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/config.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
6
  * REST HTTP client for config routes
6
7
  */
7
- export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=config.d.ts.map
@@ -1,12 +1,9 @@
1
- import { generateGenericJsonClient } from "../../utils/client/index.js";
2
- import { getReqSerializers, getReturnTypes, routesData } from "../routes/config.js";
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/config.js";
3
3
  /**
4
4
  * REST HTTP client for config routes
5
5
  */
6
6
  export function getClient(config, httpClient) {
7
- const reqSerializers = getReqSerializers();
8
- const returnTypes = getReturnTypes();
9
- // All routes return JSON, use a client auto-generator
10
- return generateGenericJsonClient(routesData, reqSerializers, returnTypes, httpClient);
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
11
8
  }
12
9
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/beacon/client/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,yBAAyB,EAAc,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAM,iBAAiB,EAAE,cAAc,EAAY,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAEjG;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,sDAAsD;IACtD,OAAO,yBAAyB,CAAgB,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AACvG,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/beacon/client/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAY,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAI9D;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,OAAO,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { IHttpClient } from "../../utils/client/index.js";
3
- import { Api } from "../routes/debug.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/debug.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
6
  * REST HTTP client for debug routes
6
7
  */
7
- export declare function getClient(_config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=debug.d.ts.map
@@ -1,50 +1,9 @@
1
- import { HttpStatusCode } from "../../utils/client/httpStatusCode.js";
2
- import { generateGenericJsonClient, getFetchOptsSerializers } from "../../utils/client/index.js";
3
- import { getReqSerializers, getReturnTypes, routesData } from "../routes/debug.js";
4
- // As Jul 2022, it takes up to 3 mins to download states so make this 5 mins for reservation
5
- const GET_STATE_TIMEOUT_MS = 5 * 60 * 1000;
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/debug.js";
6
3
  /**
7
4
  * REST HTTP client for debug routes
8
5
  */
9
- export function getClient(_config, httpClient) {
10
- const reqSerializers = getReqSerializers();
11
- const returnTypes = getReturnTypes();
12
- // Some routes return JSON, use a client auto-generator
13
- const client = generateGenericJsonClient(routesData, reqSerializers, returnTypes, httpClient);
14
- // For `getState()` generate request serializer
15
- const fetchOptsSerializers = getFetchOptsSerializers(routesData, reqSerializers);
16
- return {
17
- ...client,
18
- // TODO: Debug the type issue
19
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
- // @ts-expect-error
21
- async getState(stateId, format) {
22
- if (format === "ssz") {
23
- const res = await httpClient.arrayBuffer({
24
- ...fetchOptsSerializers.getState(stateId, format),
25
- timeoutMs: GET_STATE_TIMEOUT_MS,
26
- });
27
- return {
28
- ok: true,
29
- response: new Uint8Array(res.body),
30
- status: res.status,
31
- };
32
- }
33
- return client.getState(stateId, format);
34
- },
35
- // TODO: Debug the type issue
36
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
37
- // @ts-expect-error
38
- async getStateV2(stateId, format) {
39
- if (format === "ssz") {
40
- const res = await httpClient.arrayBuffer({
41
- ...fetchOptsSerializers.getStateV2(stateId, format),
42
- timeoutMs: GET_STATE_TIMEOUT_MS,
43
- });
44
- return { ok: true, response: new Uint8Array(res.body), status: res.status };
45
- }
46
- return client.getStateV2(stateId, format);
47
- },
48
- };
6
+ export function getClient(config, httpClient) {
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
49
8
  }
50
9
  //# sourceMappingURL=debug.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/beacon/client/debug.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAC,yBAAyB,EAAE,uBAAuB,EAAc,MAAM,6BAA6B,CAAC;AAE5G,OAAO,EAAM,iBAAiB,EAAE,cAAc,EAAY,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAEhG,4FAA4F;AAC5F,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3C;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB,EAAE,UAAuB;IACzE,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,uDAAuD;IACvD,MAAM,MAAM,GAAG,yBAAyB,CAAgB,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC7G,+CAA+C;IAC/C,MAAM,oBAAoB,GAAG,uBAAuB,CAAgB,UAAU,EAAE,cAAc,CAAC,CAAC;IAEhG,OAAO;QACL,GAAG,MAAM;QAET,6BAA6B;QAC7B,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,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAI7D;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,OAAO,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,6 +1,9 @@
1
- import { Api } from "../routes/events.js";
1
+ import { ChainForkConfig } from "@lodestar/config";
2
+ import { ApiClientMethods } from "../../utils/client/method.js";
3
+ import { Endpoints } from "../routes/events.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
2
5
  /**
3
6
  * REST HTTP client for events routes
4
7
  */
5
- export declare function getClient(baseUrl: string): Api;
8
+ export declare function getClient(config: ChainForkConfig, baseUrl: string): ApiClient;
6
9
  //# sourceMappingURL=events.d.ts.map
@@ -1,50 +1,48 @@
1
- import { routesData, getEventSerdes } from "../routes/events.js";
2
- import { stringifyQuery, urlJoin } from "../../utils/client/format.js";
3
1
  import { getEventSource } from "../../utils/client/eventSource.js";
4
- import { HttpStatusCode } from "../../utils/client/httpStatusCode.js";
2
+ import { stringifyQuery, urlJoin } from "../../utils/client/format.js";
3
+ import { ApiResponse } from "../../utils/client/response.js";
4
+ import { getDefinitions, getEventSerdes } from "../routes/events.js";
5
5
  /**
6
6
  * REST HTTP client for events routes
7
7
  */
8
- export function getClient(baseUrl) {
8
+ export function getClient(config, baseUrl) {
9
+ const definitions = getDefinitions(config);
9
10
  const eventSerdes = getEventSerdes();
10
11
  return {
11
- eventstream: async (topics, signal, onEvent) => {
12
+ eventstream: async ({ topics, signal, onEvent, onError, onClose }) => {
12
13
  const query = stringifyQuery({ topics });
13
- const url = `${urlJoin(baseUrl, routesData.eventstream.url)}?${query}`;
14
+ const url = `${urlJoin(baseUrl, definitions.eventstream.url)}?${query}`;
14
15
  // eslint-disable-next-line @typescript-eslint/naming-convention
15
16
  const EventSource = await getEventSource();
16
17
  const eventSource = new EventSource(url);
17
- try {
18
- await new Promise((resolve, reject) => {
19
- for (const topic of topics) {
20
- eventSource.addEventListener(topic, ((event) => {
21
- const message = eventSerdes.fromJson(topic, JSON.parse(event.data));
22
- onEvent({ type: topic, message });
23
- }));
24
- }
25
- // EventSource will try to reconnect always on all errors
26
- // `eventSource.onerror` events are informative but don't indicate the EventSource closed
27
- // The only way to abort the connection from the client is via eventSource.close()
28
- eventSource.onerror = function onerror(err) {
29
- const errEs = err;
30
- // Consider 400 and 500 status errors unrecoverable, close the eventsource
31
- if (errEs.status === 400) {
32
- reject(Error(`400 Invalid topics: ${errEs.message}`));
33
- }
34
- if (errEs.status === 500) {
35
- reject(Error(`500 Internal Server Error: ${errEs.message}`));
36
- }
37
- // TODO: else log the error somewhere
38
- // console.log("eventstream client error", errEs);
39
- };
40
- // And abort resolve the promise so finally {} eventSource.close()
41
- signal.addEventListener("abort", () => resolve(), { once: true });
42
- });
43
- }
44
- finally {
18
+ const close = () => {
45
19
  eventSource.close();
20
+ onClose?.();
21
+ signal.removeEventListener("abort", close);
22
+ };
23
+ signal.addEventListener("abort", close, { once: true });
24
+ for (const topic of topics) {
25
+ eventSource.addEventListener(topic, (event) => {
26
+ const message = eventSerdes.fromJson(topic, JSON.parse(event.data));
27
+ onEvent({ type: topic, message });
28
+ });
46
29
  }
47
- return { ok: true, response: undefined, status: HttpStatusCode.OK };
30
+ // EventSource will try to reconnect always on all errors
31
+ // `eventSource.onerror` events are informative but don't indicate the EventSource closed
32
+ // The only way to abort the connection from the client is via eventSource.close()
33
+ eventSource.onerror = function onerror(err) {
34
+ const errEs = err;
35
+ // Ignore noisy errors due to beacon node being offline
36
+ if (!errEs.message?.includes("ECONNREFUSED")) {
37
+ // If there is no message it likely indicates that the server closed the connection
38
+ onError?.(new Error(errEs.message ?? "Server closed connection"));
39
+ }
40
+ // Consider 400 and 500 status errors unrecoverable, close the eventsource
41
+ if (errEs.status === 400 || errEs.status === 500) {
42
+ close();
43
+ }
44
+ };
45
+ return new ApiResponse(definitions.eventstream);
48
46
  },
49
47
  };
50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yF;YACzF,kFAAkF;YAClF,WAAW,CAAC,OAAO,GAAG,SAAS,OAAO,CAAC,GAAG;gBACxC,MAAM,KAAK,GAAG,GAAkC,CAAC;gBAEjD,uDAAuD;gBACvD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;oBAC7C,mFAAmF;oBACnF,OAAO,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,0BAA0B,CAAC,CAAC,CAAC;gBACpE,CAAC;gBAED,0EAA0E;gBAC1E,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBACjD,KAAK,EAAE,CAAC;gBACV,CAAC;YACH,CAAC,CAAC;YAEF,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC,WAA6D,CAAC,CAAC;QACpG,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,13 +1,18 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { Api } from "../routes/index.js";
3
- import { IHttpClient, HttpClientOptions, HttpClientModules } from "../../utils/client/index.js";
2
+ import { ApiClientMethods, HttpClientModules, HttpClientOptions, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/index.js";
4
4
  type ClientModules = HttpClientModules & {
5
5
  config: ChainForkConfig;
6
6
  httpClient?: IHttpClient;
7
7
  };
8
+ export type ApiClient = {
9
+ [K in keyof Endpoints]: ApiClientMethods<Endpoints[K]>;
10
+ } & {
11
+ httpClient: IHttpClient;
12
+ };
8
13
  /**
9
14
  * REST HTTP client for all routes
10
15
  */
11
- export declare function getClient(opts: HttpClientOptions, modules: ClientModules): Api;
16
+ export declare function getClient(opts: HttpClientOptions, modules: ClientModules): ApiClient;
12
17
  export {};
13
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { HttpClient } from "../../utils/client/index.js";
1
+ import { HttpClient, } from "../../utils/client/index.js";
2
2
  import * as beacon from "./beacon.js";
3
3
  import * as configApi from "./config.js";
4
4
  import * as debug from "./debug.js";
@@ -18,12 +18,13 @@ export function getClient(opts, modules) {
18
18
  beacon: beacon.getClient(config, httpClient),
19
19
  config: configApi.getClient(config, httpClient),
20
20
  debug: debug.getClient(config, httpClient),
21
- events: events.getClient(httpClient.baseUrl),
21
+ events: events.getClient(config, httpClient.baseUrl),
22
22
  lightclient: lightclient.getClient(config, httpClient),
23
23
  lodestar: lodestar.getClient(config, httpClient),
24
24
  node: node.getClient(config, httpClient),
25
25
  proof: proof.getClient(config, httpClient),
26
26
  validator: validator.getClient(config, httpClient),
27
+ httpClient,
27
28
  };
28
29
  }
29
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/beacon/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,UAAU,EAAuC,MAAM,6BAA6B,CAAC;AAE1G,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAO5C;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAuB,EAAE,OAAsB;IACvE,MAAM,EAAC,MAAM,EAAC,GAAG,OAAO,CAAC;IACzB,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEvE,OAAO;QACL,MAAM,EAAE,MAAM,CAA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M,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEvE,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QAC5C,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QAC/C,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QAC1C,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC;QACpD,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QACtD,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QAChD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QACxC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QAC1C,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;QAClD,UAAU;KACX,CAAC;AACJ,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { Api } from "../routes/lightclient.js";
3
- import { IHttpClient } from "../../utils/client/index.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/lightclient.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
6
  * REST HTTP client for lightclient routes
6
7
  */
7
- export declare function getClient(_config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=lightclient.d.ts.map
@@ -1,12 +1,9 @@
1
- import { routesData, getReqSerializers, getReturnTypes } from "../routes/lightclient.js";
2
- import { generateGenericJsonClient } from "../../utils/client/index.js";
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/lightclient.js";
3
3
  /**
4
4
  * REST HTTP client for lightclient routes
5
5
  */
6
- export function getClient(_config, httpClient) {
7
- const reqSerializers = getReqSerializers();
8
- const returnTypes = getReturnTypes();
9
- // All routes return JSON, use a client auto-generator
10
- return generateGenericJsonClient(routesData, reqSerializers, returnTypes, httpClient);
6
+ export function getClient(config, httpClient) {
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
11
8
  }
12
9
  //# sourceMappingURL=lightclient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lightclient.js","sourceRoot":"","sources":["../../../src/beacon/client/lightclient.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAc,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAEnF;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB,EAAE,UAAuB;IACzE,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,sDAAsD;IACtD,OAAO,yBAAyB,CAAgB,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AACvG,CAAC"}
1
+ {"version":3,"file":"lightclient.js","sourceRoot":"","sources":["../../../src/beacon/client/lightclient.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAY,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAInE;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,OAAO,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { Api } from "../routes/lodestar.js";
3
- import { IHttpClient } from "../../utils/client/index.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/lodestar.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
6
  * REST HTTP client for lodestar routes
6
7
  */
7
- export declare function getClient(_config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=lodestar.d.ts.map
@@ -1,12 +1,9 @@
1
- import { routesData, getReqSerializers, getReturnTypes } from "../routes/lodestar.js";
2
- import { generateGenericJsonClient } from "../../utils/client/index.js";
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/lodestar.js";
3
3
  /**
4
4
  * REST HTTP client for lodestar routes
5
5
  */
6
- export function getClient(_config, httpClient) {
7
- const reqSerializers = getReqSerializers();
8
- const returnTypes = getReturnTypes();
9
- // All routes return JSON, use a client auto-generator
10
- return generateGenericJsonClient(routesData, reqSerializers, returnTypes, httpClient);
6
+ export function getClient(config, httpClient) {
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
11
8
  }
12
9
  //# sourceMappingURL=lodestar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lodestar.js","sourceRoot":"","sources":["../../../src/beacon/client/lodestar.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAc,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAEnF;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB,EAAE,UAAuB;IACzE,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,sDAAsD;IACtD,OAAO,yBAAyB,CAAgB,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AACvG,CAAC"}
1
+ {"version":3,"file":"lodestar.js","sourceRoot":"","sources":["../../../src/beacon/client/lodestar.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAY,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAIhE;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,OAAO,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { IHttpClient } from "../../utils/client/index.js";
3
- import { Api } from "../routes/node.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/node.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
6
  * REST HTTP client for beacon routes
6
7
  */
7
- export declare function getClient(_config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=node.d.ts.map
@@ -1,12 +1,9 @@
1
- import { generateGenericJsonClient } from "../../utils/client/index.js";
2
- import { getReqSerializers, getReturnTypes, routesData } from "../routes/node.js";
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/node.js";
3
3
  /**
4
4
  * REST HTTP client for beacon routes
5
5
  */
6
- export function getClient(_config, httpClient) {
7
- const reqSerializers = getReqSerializers();
8
- const returnTypes = getReturnTypes();
9
- // All routes return JSON, use a client auto-generator
10
- return generateGenericJsonClient(routesData, reqSerializers, returnTypes, httpClient);
6
+ export function getClient(config, httpClient) {
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
11
8
  }
12
9
  //# sourceMappingURL=node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/beacon/client/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,yBAAyB,EAAc,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAM,iBAAiB,EAAE,cAAc,EAAY,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAE/F;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB,EAAE,UAAuB;IACzE,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,sDAAsD;IACtD,OAAO,yBAAyB,CAAgB,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AACvG,CAAC"}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/beacon/client/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAY,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAI5D;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAuB,EAAE,UAAuB;IACxE,OAAO,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AACpE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { ChainForkConfig } from "@lodestar/config";
2
- import { Api } from "../routes/proof.js";
3
- import { IHttpClient } from "../../utils/client/index.js";
2
+ import { ApiClientMethods, IHttpClient } from "../../utils/client/index.js";
3
+ import { Endpoints } from "../routes/proof.js";
4
+ export type ApiClient = ApiClientMethods<Endpoints>;
4
5
  /**
5
- * REST HTTP client for lightclient routes
6
+ * REST HTTP client for proof routes
6
7
  */
7
- export declare function getClient(_config: ChainForkConfig, httpClient: IHttpClient): Api;
8
+ export declare function getClient(config: ChainForkConfig, httpClient: IHttpClient): ApiClient;
8
9
  //# sourceMappingURL=proof.d.ts.map
@@ -1,65 +1,9 @@
1
- import { ProofType } from "@chainsafe/persistent-merkle-tree";
2
- import { routesData, getReqSerializers } from "../routes/proof.js";
3
- import { getFetchOptsSerializers, HttpError } from "../../utils/client/index.js";
4
- import { HttpStatusCode } from "../../utils/client/httpStatusCode.js";
1
+ import { createApiClientMethods } from "../../utils/client/index.js";
2
+ import { getDefinitions } from "../routes/proof.js";
5
3
  /**
6
- * REST HTTP client for lightclient routes
4
+ * REST HTTP client for proof routes
7
5
  */
8
- export function getClient(_config, httpClient) {
9
- const reqSerializers = getReqSerializers();
10
- // For `getStateProof()` generate request serializer
11
- const fetchOptsSerializers = getFetchOptsSerializers(routesData, reqSerializers);
12
- return {
13
- async getStateProof(stateId, descriptor) {
14
- try {
15
- const res = await httpClient.arrayBuffer(fetchOptsSerializers.getStateProof(stateId, descriptor));
16
- // reuse the response ArrayBuffer
17
- if (!Number.isInteger(res.body.byteLength / 32)) {
18
- throw new Error("Invalid proof data: Length not divisible by 32");
19
- }
20
- const proof = {
21
- type: ProofType.compactMulti,
22
- descriptor,
23
- leaves: Array.from({ length: res.body.byteLength / 32 }, (_, i) => new Uint8Array(res.body, i * 32, 32)),
24
- };
25
- return { ok: true, response: { data: proof }, status: HttpStatusCode.OK };
26
- }
27
- catch (err) {
28
- if (err instanceof HttpError) {
29
- return {
30
- ok: false,
31
- error: { code: err.status, message: err.message, operationId: "proof.getStateProof" },
32
- status: err.status,
33
- };
34
- }
35
- throw err;
36
- }
37
- },
38
- async getBlockProof(blockId, descriptor) {
39
- try {
40
- const res = await httpClient.arrayBuffer(fetchOptsSerializers.getBlockProof(blockId, descriptor));
41
- // reuse the response ArrayBuffer
42
- if (!Number.isInteger(res.body.byteLength / 32)) {
43
- throw new Error("Invalid proof data: Length not divisible by 32");
44
- }
45
- const proof = {
46
- type: ProofType.compactMulti,
47
- descriptor,
48
- leaves: Array.from({ length: res.body.byteLength / 32 }, (_, i) => new Uint8Array(res.body, i * 32, 32)),
49
- };
50
- return { ok: true, response: { data: proof }, status: HttpStatusCode.OK };
51
- }
52
- catch (err) {
53
- if (err instanceof HttpError) {
54
- return {
55
- ok: false,
56
- error: { code: err.status, message: err.message, operationId: "proof.getStateProof" },
57
- status: err.status,
58
- };
59
- }
60
- throw err;
61
- }
62
- },
63
- };
6
+ export function getClient(config, httpClient) {
7
+ return createApiClientMethods(getDefinitions(config), httpClient);
64
8
  }
65
9
  //# sourceMappingURL=proof.js.map