@asyncswap/eth-rpc 0.4.9 → 0.4.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @asyncswap/eth-rpc
2
2
 
3
+ ## 0.4.10
4
+
5
+ ### Patch Changes
6
+
7
+ - dc792b1: (refactor): change to `withHeaders` option and update BaseClient source
8
+ - Updated dependencies [dc792b1]
9
+ - @asyncswap/jsonrpc@0.4.9
10
+
3
11
  ## 0.4.9
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@asyncswap/eth-rpc",
3
3
  "description": "A library for ethereum execution clients apis.",
4
4
  "author": "Meek Msaki",
5
- "version": "0.4.9",
5
+ "version": "0.4.10",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
@@ -40,6 +40,6 @@
40
40
  "typescript": "^5"
41
41
  },
42
42
  "dependencies": {
43
- "@asyncswap/jsonrpc": "^0.4.8"
43
+ "@asyncswap/jsonrpc": "^0.4.9"
44
44
  }
45
45
  }
package/src/eth-api.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseClient } from "./base";
1
+ import { BaseClient } from "@asyncswap/jsonrpc";
2
2
 
3
3
  export class ExecutionClient extends BaseClient<EthMethodsSpec> {
4
4
  constructor(url: string) {
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
- export * from "./base";
2
1
  export * from "./eth-api";
package/src/base.ts DELETED
@@ -1,49 +0,0 @@
1
- import { JsonRpcClient } from "@asyncswap/jsonrpc";
2
-
3
- export type RpcMethodSpec = {
4
- params: readonly unknown[];
5
- result: unknown;
6
- };
7
- export type RpcSpecBase = Record<string, RpcMethodSpec>;
8
-
9
- export abstract class BaseClient<MethodsSpec extends RpcSpecBase> {
10
- rpc: JsonRpcClient<MethodsSpec>;
11
- protected headers: Record<string, string> = {};
12
-
13
- constructor(url: string) {
14
- this.rpc = new JsonRpcClient(url);
15
-
16
- return new Proxy(this, {
17
- get: (target: this, prop: string | symbol, receiver) => {
18
- // let real properties / methods through
19
- if (prop in target) {
20
- const value = Reflect.get(target, prop, receiver);
21
- if (typeof value === "function") {
22
- return (...args: any[]) => {
23
- const result = value.apply(target, args);
24
- // if method returns target, return proxy instead
25
- return result === target ? receiver : result;
26
- };
27
- }
28
- return value;
29
- }
30
- // dynamic rpc
31
- if (typeof prop !== "string") return undefined;
32
-
33
- const method = prop as keyof MethodsSpec;
34
-
35
- return (
36
- ...params: MethodsSpec[typeof method]["params"]
37
- ): MethodsSpec[typeof method]["result"] =>
38
- this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
39
- },
40
- });
41
- }
42
-
43
- setHeaders(headers: Record<string, string>) {
44
- this.headers = {
45
- ...headers,
46
- };
47
- return this;
48
- }
49
- }