Skip to content
Permalink
Browse files

fix: update deps

  • Loading branch information...
BelfordZ committed Apr 24, 2019
1 parent 784c786 commit f8de381ee92d53143dea5b6efddf9dd2fe697862
@@ -1,12 +1,12 @@
#!/usr/bin/env node
const program = require('commander');
const server = require('../build/server');
const server = require('../build');

program
.version(require('./get-version'))
.option('-s, --schema [schema]', 'JSON string or a Path/Url pointing to an OpenRPC Schema')
.option('-d, --document [openrpcDocument]', 'JSON string or a Path/Url pointing to an OpenRPC Schema')
.action(() => {
server('http', 3333, program.schema)
server('http', 3333, program.openrpcDocument)
.catch((e) => {
console.error(e);
process.exit(1);

Large diffs are not rendered by default.

@@ -30,8 +30,8 @@
"publish": "npm run build"
},
"dependencies": {
"@open-rpc/meta-schema": "^1.2.2",
"@open-rpc/schema-utils-js": "^1.5.1",
"@open-rpc/meta-schema": "^1.3.1",
"@open-rpc/schema-utils-js": "^1.8.0",
"ajv": "^6.10.0",
"body-parser": "^1.18.3",
"connect": "^3.6.6",
@@ -41,7 +41,7 @@
"lodash": "^4.17.11"
},
"devDependencies": {
"@open-rpc/examples": "^1.2.1",
"@open-rpc/examples": "^1.3.0",
"@types/connect": "^3.4.32",
"@types/cors": "^2.8.4",
"@types/jest": "^24.0.11",
@@ -50,6 +50,7 @@
"jest": "^24.1.0",
"json-schema-ref-parser": "^6.1.0",
"ts-jest": "^24.0.0",
"tslint": "^5.14.0"
"tslint": "^5.14.0",
"typescript": "^3.4.5"
}
}
@@ -1,6 +1,6 @@
import { generateMethodHandler } from "./generate-method-handler";
import { types } from "@open-rpc/meta-schema";
import { MethodCallValidator } from "@open-rpc/schema-utils-js";
import { OpenRPC } from "@open-rpc/meta-schema";

describe("generateMethodHandler", () => {
const exampleSchema = {
@@ -16,7 +16,7 @@ describe("generateMethodHandler", () => {
},
],
openrpc: "1.0.0-rc1",
} as types.OpenRPC;
} as OpenRPC;

it("returns a function given a method and a validator", () => {
const exampleValidator = new MethodCallValidator(exampleSchema);
@@ -1,12 +1,12 @@
import { Ajv } from "ajv";
import { JSONRPCCallbackTypePlain, JSONRPCError } from "jayson/promise";
import { types } from "@open-rpc/meta-schema";
import * as _ from "lodash";
import { generateResponse } from "./genererate-response";
import { MethodCallValidator } from "@open-rpc/schema-utils-js";
import { MethodObject } from "@open-rpc/meta-schema";

export const generateMethodHandler = (
method: types.MethodObject,
method: MethodObject,
validator: MethodCallValidator,
) => {
return async (args: any, cb: any) => {
@@ -1,13 +1,13 @@
import { forEach } from "lodash";
import { parse } from "@open-rpc/schema-utils-js";
import { parseOpenRPCDocument } from "@open-rpc/schema-utils-js";
import examples from "@open-rpc/examples";
import { types } from "@open-rpc/meta-schema";
import { generateMethodMapping } from "./generate-method-mapping";
import { OpenRPC } from "@open-rpc/meta-schema";

describe("buildMethodHandlerMapping doesnt error on any examples", () => {
forEach(examples, (example: types.OpenRPC, exampleName: string) => {
forEach(examples, (example: OpenRPC, exampleName: string) => {
it(exampleName, async () => {
const parsedExample = await parse(JSON.stringify(example)) as types.OpenRPC;
const parsedExample = await parseOpenRPCDocument(JSON.stringify(example)) as OpenRPC;
const mapping = generateMethodMapping(parsedExample);
expect(typeof mapping).toBe("object");
expect(Object.keys(mapping).length).toBe(parsedExample.methods.length);
@@ -1,14 +1,14 @@
import { types } from "@open-rpc/meta-schema";
import { MethodHandlerType } from "jayson/promise";
import { MethodCallValidator } from "@open-rpc/schema-utils-js";
import { generateMethodHandler } from "./generate-method-handler";
import { OpenRPC, MethodObject } from "@open-rpc/meta-schema";

export interface IMemo { [k: string]: MethodHandlerType; }

export const generateMethodMapping = (openrpcSchema: types.OpenRPC) => {
export const generateMethodMapping = (openrpcSchema: OpenRPC) => {
const validator = new MethodCallValidator(openrpcSchema);

return openrpcSchema.methods.reduce((memo, method: types.MethodObject) => {
return openrpcSchema.methods.reduce((memo, method: MethodObject) => {
memo[method.name] = generateMethodHandler(method, validator);
return memo;
}, {} as IMemo);
@@ -1,5 +1,5 @@
import { generateResponse } from "./genererate-response";
import { types } from "@open-rpc/meta-schema";
import { MethodObject } from "@open-rpc/meta-schema";

describe("generateResponse", () => {
describe("default case - no examples", () => {
@@ -45,7 +45,7 @@ describe("generateResponse", () => {
paramStructure: "by-name",
params: [{ name: "tats", schema: { type: "number" } }],
result: { name: "bar", schema: { type: "number" } },
} as types.MethodObject;
} as MethodObject;

const result = await generateResponse(exampleMethod, { tats: 123 });
expect(result).toBe(321);
@@ -1,23 +1,23 @@
const jsf = require("json-schema-faker"); // tslint:disable-line

import { types } from "@open-rpc/meta-schema";
import { find, isMatch, map } from "lodash";
import { ExampleObject, ExamplePairingObject, ContentDescriptorObject, MethodObject } from "@open-rpc/meta-schema";

export const generateResponse = async (method: types.MethodObject, args: any): Promise<any> => {
const result = method.result as types.ContentDescriptorObject;
export const generateResponse = async (method: MethodObject, args: any): Promise<any> => {
const result = method.result as ContentDescriptorObject;
const schemaForResponse = result.schema;

if (method.examples) {
const argList = method.paramStructure === "by-name" ? Object.values(args) : args;

const examples = method.examples as types.ExamplePairingObject[];
const examples = method.examples as ExamplePairingObject[];

const foundExample = find(
examples,
({ params }) => isMatch(map(params, "value"), argList),
);
if (foundExample) {
const foundExampleResult = foundExample.result as types.ExampleObject;
const foundExampleResult = foundExample.result as ExampleObject;
return foundExampleResult.value;
}
}
@@ -1,15 +1,15 @@
import * as jayson from "jayson";
import { parse } from "@open-rpc/schema-utils-js";
import { parseOpenRPCDocument } from "@open-rpc/schema-utils-js";
import { generateMethodMapping } from "./generate-method-mapping";
import cors from "cors";
import { json as jsonParser } from "body-parser";
import connect, { HandleFunction } from "connect";
import { RequestHandler } from "express-serve-static-core";
import { types } from "@open-rpc/meta-schema";
import { OpenRPC } from "@open-rpc/meta-schema";

const server = async (protocol: string, port: number | string, schemaLocation: any) => {
const app = connect();
const schema = await parse(schemaLocation) as types.OpenRPC;
const schema = await parseOpenRPCDocument(schemaLocation) as OpenRPC;
const methods = {
...generateMethodMapping(schema),
"rpc.discover": (args: any, cb: any) => {
@@ -21,7 +21,7 @@ const server = async (protocol: string, port: number | string, schemaLocation: a

app.use(cors({ origin: "*" }) as HandleFunction);
app.use(jsonParser());
app.use(jsonRpcServer.middleware() as HandleFunction);
app.use(jsonRpcServer.middleware() as unknown as HandleFunction);
app.listen(port);
};

@@ -8,7 +8,6 @@
"declaration": true,
"outDir": "./build",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true
"esModuleInterop": true
}
}

0 comments on commit f8de381

Please sign in to comment.
You can’t perform that action at this time.