Skip to content

Commit

Permalink
refactor(rpc): added null and boolean to batch rpc (#736)
Browse files Browse the repository at this point in the history
Co-authored-by: Chen Yu <[email protected]>
  • Loading branch information
homura and Keith-CY authored Aug 2, 2024
1 parent 3763977 commit 3cf82d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-gorillas-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/rpc": minor
---

refactor: added null and boolean for batch client
4 changes: 2 additions & 2 deletions packages/rpc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Base } from "./Base";
import { Method } from "./method";
import { JSONValue, Method } from "./method";
import { CKBComponents } from "./types/api";
import { formatter as paramsFormatter } from "./paramsFormatter";
import * as resultFormatter from "./resultFormatter";
Expand Down Expand Up @@ -85,7 +85,7 @@ export class CKBRPC extends Base {
/* eslint-disable */
public createBatchRequest = <
N extends keyof Base,
P extends (string | number | object)[],
P extends JSONValue[],
R = any[]
>(
params: [method: N, ...rest: P][] = []
Expand Down
9 changes: 7 additions & 2 deletions packages/rpc/src/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { DEFAULT_RPC_TIMEOUT } from ".";
import AbortController from "abort-controller";
import fetch_ from "cross-fetch";

type JSONPrimitive = string | number | boolean | null;
type JSONArray = JSONValue[];
type JSONObject = { [key: string]: JSONValue };
export type JSONValue = JSONPrimitive | JSONArray | JSONObject;

export class Method {
#name: string;
#config: RPCConfig;
Expand Down Expand Up @@ -41,7 +46,7 @@ export class Method {
}

/* eslint-disable @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types */
public call = async (...params: (string | number | object)[]) => {
public call = async (...params: JSONValue[]) => {
const payload = this.getPayload(...params);
const controller = new AbortController();
const signal = controller.signal as AbortSignal;
Expand Down Expand Up @@ -72,7 +77,7 @@ export class Method {
return res;
};

public getPayload = (...params: (string | number | object)[]) => {
public getPayload = (...params: JSONValue[]) => {
const data = params.map(
(p, i) =>
(this.#options.paramsFormatters[i] &&
Expand Down

1 comment on commit 3cf82d9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 New canary release: 0.0.0-canary-3cf82d9-20240802041808

npm install @ckb-lumos/[email protected]

Please sign in to comment.