Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(rpc): added null and boolean to batch rpc #736

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 bollean for batch client
homura marked this conversation as resolved.
Show resolved Hide resolved
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 @@
/* eslint-disable */
public createBatchRequest = <
N extends keyof Base,
P extends (string | number | object)[],
P extends JSONValue[],

Check warning on line 88 in packages/rpc/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/rpc/src/index.ts#L88

Added line #L88 was not covered by tests
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
Loading