Skip to content

Commit 65d5da0

Browse files
authored
Merge pull request #471 from open-rpc/feat/allow-transport-passed
feat: allow transport passed + added raw json reporter
2 parents 2f565e0 + d4b6e7d commit 65d5da0

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"bin",
1515
"build"
1616
],
17-
"main": "build/coverage.js",
17+
"main": "build/index.js",
1818
"author": "",
1919
"license": "Apache-2.0",
2020
"dependencies": {

src/coverage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@ export default async (options: IOptions) => {
109109
}
110110
}
111111

112-
options.reporter(exampleCalls, options.openrpcDocument);
112+
return options.reporter(exampleCalls, options.openrpcDocument);
113113
};

src/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import consoleReporter from "./reporters/console";
22
import coverage from "./coverage";
33
import HTTPTransport from "./transports/HTTPTransport";
44
import jsonReporter from "./reporters/json";
5+
import rawReporter from "./reporters/raw";
56
import { OpenrpcDocument } from "@open-rpc/meta-schema";
7+
import { ITransport } from "./transports/ITransport";
68

79
const reporters = {
810
console: consoleReporter,
911
json: jsonReporter,
12+
raw: rawReporter,
1013
};
1114

1215
const transports = {
@@ -17,16 +20,17 @@ interface IOptions {
1720
openrpcDocument: OpenrpcDocument;
1821
skip?: string[];
1922
only?: string[];
20-
reporter: "console" | "json";
21-
transport: "http";
23+
reporter: "console" | "json" | "raw";
24+
transport: "http" | ITransport;
2225
}
2326

2427
export default async (options: IOptions) => {
28+
const transport = typeof options.transport === "function" ? options.transport : transports[options.transport || "http"];
2529
return coverage({
2630
reporter: reporters[options.reporter || "console"],
2731
openrpcDocument: options.openrpcDocument,
2832
skip: options.skip || [],
2933
only: options.only || [],
30-
transport: transports[options.transport || "http"],
34+
transport: transport,
3135
});
3236
};

src/reporters/raw.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { OpenrpcDocument } from "@open-rpc/meta-schema";
2+
3+
export default (callResults: any[], schema: OpenrpcDocument) => {
4+
return callResults;
5+
};

src/transports/HTTPTransport.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import fetch from "isomorphic-fetch";
2+
import { ITransport } from "./ITransport";
23
let id = 1;
34

4-
export default (url: string, method: string, params: any[]) => {
5+
const httpTransport: ITransport = async (url: string, method: string, params: any[]) => {
56
return fetch(url, {
67
method: "POST",
78
headers: { "Content-Type": "application/json" },
@@ -15,3 +16,5 @@ export default (url: string, method: string, params: any[]) => {
1516
return r.json();
1617
});
1718
};
19+
20+
export default httpTransport;

src/transports/ITransport.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ITransport = (url: string, method: string, params: any) => Promise<any>;

0 commit comments

Comments
 (0)