Skip to content

Commit

Permalink
fix: use open-rpc client-js instead of Jayson
Browse files Browse the repository at this point in the history
fixes #123
fixes #96
  • Loading branch information
shanejonas committed May 15, 2019
1 parent 90a5e0d commit d800816
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
43 changes: 12 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const cleanBuildDir = async (destinationDirectoryName: string): Promise<any> =>
const compileTemplate = async (
openrpcDocument: OpenRPC,
language: string,
methodTypings: MethodTypings
methodTypings: MethodTypings,
): Promise<string> => {
const template = language === "rust" ? rsTemplate : jsTemplate;
return template({
Expand Down
3 changes: 2 additions & 1 deletion templates/typescript/static/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"dependencies": {
"@open-rpc/meta-schema": "^1.3.1",
"@open-rpc/schema-utils-js": "^1.8.0",
"jayson": "^2.1.2",
"@open-rpc/client-js": "0.0.0-development",
"lodash": "4.17.11"
},
"devDependencies": {
"typescript": "^3.2.4",
"@types/ws": "^6.0.1",
"@types/json-schema": "7.0.3",
"tslint": "^5.13.1",
"typedoc": "^0.14.2"
Expand Down
30 changes: 26 additions & 4 deletions templates/typescript/templated/exported-class.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@ import { template } from "lodash";

export default template(`
// Code generated by @open-rpc/client-generator DO NOT EDIT.
import * as jayson from "jayson/promise";
import { RequestManager, WebSocketTransport, HTTPTransport, Client } from '@open-rpc/client-js';
import ajv from "ajv";
import _ from "lodash";
import { OpenRPC, MethodObject, ContentDescriptorObject } from "@open-rpc/meta-schema";
import { MethodCallValidator } from "@open-rpc/schema-utils-js";
<%= methodTypings.getAllUniqueTypings("typescript") %>
interface IOptions {
transport: {
type: "websocket" | "http" | "https";
host: string;
port: number;
}
}
export default class <%= className %> {
public rpc: jayson.Client;
public rpc: Client;
private validator: MethodCallValidator;
private openrpcDocument: OpenRPC;
constructor(options: any) {
constructor(options: IOptions) {
this.openrpcDocument = <%= JSON.stringify(openrpcDocument) %>;
if (options.transport === undefined || options.transport.type === undefined) {
throw new Error("Invalid constructor params");
}
this.rpc = (jayson.Client as any)[options.transport.type](options.transport);
let transport;
switch (options.transport.type) {
case 'http':
case 'https':
transport = new HTTPTransport(options.transport.type + "://" + options.transport.host + ":" + options.transport.port)
break;
case 'websocket':
transport = new WebSocketTransport("ws://" + options.transport.host + ":" + options.transport.port)
break;
default:
throw new Error("unsupported transport");
break;
}
this.rpc = new Client(new RequestManager([transport]));
this.validator = new MethodCallValidator(this.openrpcDocument);
}
Expand Down

0 comments on commit d800816

Please sign in to comment.