Add Robot_JoyIt driver
This commit is contained in:
14
node_modules/json-rpc-2.0/README.md
generated
vendored
14
node_modules/json-rpc-2.0/README.md
generated
vendored
@@ -176,7 +176,11 @@ client.notify("log", { message: "Hello, World!" });
|
||||
Just like `JSONRPCServer`, you can inject custom params to `JSONRPCClient` too:
|
||||
|
||||
```javascript
|
||||
const client = new JSONRPCClient(
|
||||
interface AuthToken {
|
||||
token: string;
|
||||
}
|
||||
|
||||
const client = new JSONRPCClient<AuthToken>(
|
||||
// It can also take a custom parameter as the second parameter.
|
||||
(jsonRPCRequest, { token }) =>
|
||||
fetch("http://localhost/json-rpc", {
|
||||
@@ -363,8 +367,10 @@ server.addMethodAdvanced(
|
||||
}
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
// Remove the added method
|
||||
```typescript
|
||||
// You can remove the added method if needed
|
||||
server.removeMethod("doSomething");
|
||||
```
|
||||
|
||||
@@ -426,6 +432,10 @@ import {
|
||||
TypedJSONRPCServerAndClient,
|
||||
} from "json-rpc-2.0";
|
||||
|
||||
// Use `type` instead of `interface`. In TypeScript, interface can be exnteded,
|
||||
// so the type checker considers the possibility of the interface being extended,
|
||||
// resulting in an error.
|
||||
// Reference: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces
|
||||
type Methods = {
|
||||
echo(params: { message: string }): string;
|
||||
sum(params: { x: number; y: number }): number;
|
||||
|
||||
1
node_modules/json-rpc-2.0/dist/client.spec.d.ts
generated
vendored
1
node_modules/json-rpc-2.0/dist/client.spec.d.ts
generated
vendored
@@ -1 +0,0 @@
|
||||
export {};
|
||||
430
node_modules/json-rpc-2.0/dist/client.spec.js
generated
vendored
430
node_modules/json-rpc-2.0/dist/client.spec.js
generated
vendored
@@ -1,430 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var mocha_1 = require("mocha");
|
||||
var chai_1 = require("chai");
|
||||
var sinon = require("sinon");
|
||||
var _1 = require(".");
|
||||
(0, mocha_1.describe)("JSONRPCClient", function () {
|
||||
var client;
|
||||
var id;
|
||||
var lastRequest;
|
||||
var lastClientParams;
|
||||
var resolve;
|
||||
var reject;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
id = 0;
|
||||
lastRequest = undefined;
|
||||
resolve = undefined;
|
||||
reject = undefined;
|
||||
var send = function (request, clientParams) {
|
||||
lastRequest = request;
|
||||
lastClientParams = clientParams;
|
||||
return new Promise(function (givenResolve, givenReject) {
|
||||
resolve = givenResolve;
|
||||
reject = givenReject;
|
||||
});
|
||||
};
|
||||
client = new _1.JSONRPCClient(send, function () { return ++id; });
|
||||
});
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
(0, mocha_1.describe)("requesting", function () {
|
||||
var result;
|
||||
var error;
|
||||
var promise;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
result = undefined;
|
||||
error = undefined;
|
||||
promise = client.request("foo", ["bar"], { token: "" }).then(function (givenResult) { return (result = givenResult); }, function (givenError) { return (error = givenError); });
|
||||
});
|
||||
(0, mocha_1.it)("should send the request", function () {
|
||||
(0, chai_1.expect)(lastRequest).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
method: "foo",
|
||||
params: ["bar"],
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("succeeded on client side", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.describe)("and succeeded on server side too", function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
response = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
result: "foo",
|
||||
};
|
||||
client.receive(response);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should resolve the result", function () {
|
||||
(0, chai_1.expect)(result).to.equal(response.result);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("and succeeded on server side with falsy but defined result", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
client.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
result: 0,
|
||||
});
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should resolve the result", function () {
|
||||
(0, chai_1.expect)(result).to.equal(0);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("but failed on server side", function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
response = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
error: {
|
||||
code: 0,
|
||||
message: "This is a test. Do not panic.",
|
||||
data: { optional: "data" },
|
||||
},
|
||||
};
|
||||
client.receive(response);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject with the error message, code and data", function () {
|
||||
(0, chai_1.expect)(error.message).to.equal(response.error.message);
|
||||
(0, chai_1.expect)(error.code).to.equal(response.error.code);
|
||||
(0, chai_1.expect)(error.data).to.equal(response.error.data);
|
||||
});
|
||||
(0, mocha_1.it)("should reject with a JSONRPCErrorException", function () {
|
||||
(0, chai_1.expect)(error instanceof Error).to.be.true;
|
||||
(0, chai_1.expect)(error instanceof _1.JSONRPCErrorException).to.be.true;
|
||||
(0, chai_1.expect)(error.toObject()).to.deep.equal(response.error);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("but server responded invalid response", function () {
|
||||
(0, mocha_1.describe)("like having both result and error", function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
response = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
result: "foo",
|
||||
error: {
|
||||
code: 0,
|
||||
message: "bar",
|
||||
},
|
||||
};
|
||||
client.receive(response);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject", function () {
|
||||
(0, chai_1.expect)(error).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("like not having both result and error", function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
response = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
};
|
||||
client.receive(response);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject", function () {
|
||||
(0, chai_1.expect)(error).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("but I reject all pending requests", function () {
|
||||
var message;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
message = "Connection is closed.";
|
||||
client.rejectAllPendingRequests(message);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject the request", function () {
|
||||
(0, chai_1.expect)(error.message).to.equal(message);
|
||||
});
|
||||
(0, mocha_1.describe)("receiving a response", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
client.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: id,
|
||||
result: "foo",
|
||||
});
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should not resolve the promise again", function () {
|
||||
(0, chai_1.expect)(result).to.be.undefined;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("failed on client side", function () {
|
||||
var expected;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
expected = new Error("This is a test. Do not panic.");
|
||||
reject(expected);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject the promise", function () {
|
||||
(0, chai_1.expect)(error.message).to.equal(expected.message);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("failed on client side with no error object", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
reject(undefined);
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject the promise", function () {
|
||||
(0, chai_1.expect)(error.message).to.equal("Failed to send a request");
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("failed on client side with an error object without message", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
reject({});
|
||||
return promise;
|
||||
});
|
||||
(0, mocha_1.it)("should reject the promise", function () {
|
||||
(0, chai_1.expect)(error.message).to.equal("Failed to send a request");
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting batch", function () {
|
||||
var requests;
|
||||
var actualResponses;
|
||||
var expectedResponses;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
requests = [
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, method: "foo" },
|
||||
{ jsonrpc: _1.JSONRPC, id: 1, method: "foo2" },
|
||||
];
|
||||
client
|
||||
.requestAdvanced(requests, { token: "" })
|
||||
.then(function (responses) { return (actualResponses = responses); });
|
||||
resolve();
|
||||
expectedResponses = [
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, result: "foo" },
|
||||
{ jsonrpc: _1.JSONRPC, id: 1, result: "foo2" },
|
||||
];
|
||||
client.receive(expectedResponses);
|
||||
});
|
||||
(0, mocha_1.it)("should send requests in batch", function () {
|
||||
(0, chai_1.expect)(lastRequest).to.deep.equal(requests);
|
||||
});
|
||||
(0, mocha_1.it)("should return responses", function () {
|
||||
(0, chai_1.expect)(actualResponses).to.deep.equal(expectedResponses);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting with client params", function () {
|
||||
var expected;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
expected = { token: "baz" };
|
||||
client.request("foo", undefined, expected);
|
||||
});
|
||||
(0, mocha_1.it)("should pass the client params to send function", function () {
|
||||
(0, chai_1.expect)(lastClientParams).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting with timeout", function () {
|
||||
var delay;
|
||||
var fakeTimers;
|
||||
var promise;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers = sinon.useFakeTimers();
|
||||
delay = 1000;
|
||||
promise = client.timeout(delay).request("foo");
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.describe)("timing out", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers.tick(delay);
|
||||
});
|
||||
(0, mocha_1.it)("should reject", function () {
|
||||
return promise.then(function () { return Promise.reject(new Error("Expected to fail")); }, function () { return undefined; });
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("not timing out", function () {
|
||||
var result;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
result = "foo";
|
||||
client.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: lastRequest.id,
|
||||
result: result,
|
||||
});
|
||||
});
|
||||
(0, mocha_1.it)("should respond", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var actual;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, promise];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
(0, chai_1.expect)(actual).to.equal(result);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting advanced with timeout", function () {
|
||||
var delay;
|
||||
var fakeTimers;
|
||||
var promise;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers = sinon.useFakeTimers();
|
||||
delay = 1000;
|
||||
promise = client.timeout(delay).requestAdvanced({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: ++id,
|
||||
method: "foo",
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.describe)("timing out", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers.tick(delay);
|
||||
});
|
||||
(0, mocha_1.it)("should reject", function () {
|
||||
return promise.then(function (result) {
|
||||
if (!result.error) {
|
||||
return Promise.reject(new Error("Expected to fail"));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("not timing out", function () {
|
||||
var result;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
result = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: lastRequest.id,
|
||||
result: result,
|
||||
};
|
||||
client.receive(result);
|
||||
});
|
||||
(0, mocha_1.it)("should respond", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var actual;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, promise];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
(0, chai_1.expect)(actual).to.deep.equal(result);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting with custom timeout error response", function () {
|
||||
var delay;
|
||||
var fakeTimers;
|
||||
var errorCode;
|
||||
var errorMessage;
|
||||
var errorData;
|
||||
var promise;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers = sinon.useFakeTimers();
|
||||
delay = 1000;
|
||||
errorCode = 123;
|
||||
errorMessage = "Custom error message";
|
||||
errorData = "Custom error data";
|
||||
promise = client
|
||||
.timeout(delay, function (id) {
|
||||
return (0, _1.createJSONRPCErrorResponse)(id, errorCode, errorMessage, errorData);
|
||||
})
|
||||
.requestAdvanced({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: ++id,
|
||||
method: "foo",
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.describe)("timing out", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers.tick(delay);
|
||||
});
|
||||
(0, mocha_1.it)("should reject with the custom error", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var actual, expected;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, promise];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
expected = {
|
||||
code: errorCode,
|
||||
message: errorMessage,
|
||||
data: errorData,
|
||||
};
|
||||
(0, chai_1.expect)(actual.error).to.deep.equal(expected);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("notifying", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
client.notify("foo", ["bar"], { token: "" });
|
||||
});
|
||||
(0, mocha_1.it)("should send the notification", function () {
|
||||
(0, chai_1.expect)(lastRequest).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
method: "foo",
|
||||
params: ["bar"],
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("notifying with client params", function () {
|
||||
var expected;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
expected = { token: "baz" };
|
||||
client.notify("foo", undefined, expected);
|
||||
});
|
||||
(0, mocha_1.it)("should pass the client params to send function", function () {
|
||||
(0, chai_1.expect)(lastClientParams).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
1
node_modules/json-rpc-2.0/dist/index.spec.d.ts
generated
vendored
1
node_modules/json-rpc-2.0/dist/index.spec.d.ts
generated
vendored
@@ -1 +0,0 @@
|
||||
import "mocha";
|
||||
40
node_modules/json-rpc-2.0/dist/index.spec.js
generated
vendored
40
node_modules/json-rpc-2.0/dist/index.spec.js
generated
vendored
@@ -1,40 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("mocha");
|
||||
var chai_1 = require("chai");
|
||||
var _1 = require(".");
|
||||
describe("JSONRPCClient and JSONRPCServer", function () {
|
||||
var server;
|
||||
var client;
|
||||
var id;
|
||||
beforeEach(function () {
|
||||
id = 0;
|
||||
server = new _1.JSONRPCServer();
|
||||
client = new _1.JSONRPCClient(function (request) {
|
||||
return server.receive(request).then(function (response) {
|
||||
if (response) {
|
||||
client.receive(response);
|
||||
}
|
||||
});
|
||||
}, function () { return ++id; });
|
||||
});
|
||||
it("sending a request should resolve the result", function () {
|
||||
beforeEach(function () {
|
||||
server.addMethod("foo", function () { return "bar"; });
|
||||
return client
|
||||
.request("foo", undefined)
|
||||
.then(function (result) { return (0, chai_1.expect)(result).to.equal("bar"); });
|
||||
});
|
||||
});
|
||||
it("sending a notification should send a notification", function () {
|
||||
var received;
|
||||
beforeEach(function () {
|
||||
server.addMethod("foo", function (_a) {
|
||||
var text = _a[0];
|
||||
return (received = text);
|
||||
});
|
||||
client.notify("foo", ["bar"]);
|
||||
(0, chai_1.expect)(received).to.equal("bar");
|
||||
});
|
||||
});
|
||||
});
|
||||
1
node_modules/json-rpc-2.0/dist/interfaces.spec.d.ts
generated
vendored
1
node_modules/json-rpc-2.0/dist/interfaces.spec.d.ts
generated
vendored
@@ -1 +0,0 @@
|
||||
import "mocha";
|
||||
201
node_modules/json-rpc-2.0/dist/interfaces.spec.js
generated
vendored
201
node_modules/json-rpc-2.0/dist/interfaces.spec.js
generated
vendored
@@ -1,201 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("mocha");
|
||||
var chai_1 = require("chai");
|
||||
var client_1 = require("./client");
|
||||
var server_1 = require("./server");
|
||||
var server_and_client_1 = require("./server-and-client");
|
||||
describe("interfaces", function () {
|
||||
describe("independent server and client", function () {
|
||||
var client;
|
||||
var server;
|
||||
beforeEach(function () {
|
||||
client = new client_1.JSONRPCClient(function (request) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var response;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receive(request)];
|
||||
case 1:
|
||||
response = _a.sent();
|
||||
if (response) {
|
||||
client.receive(response);
|
||||
}
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
server = new server_1.JSONRPCServer();
|
||||
});
|
||||
describe("calling method with no args no return", function () {
|
||||
var noArgsNoReturnCalled;
|
||||
beforeEach(function () {
|
||||
noArgsNoReturnCalled = false;
|
||||
server.addMethod("noArgsNoReturn", function () {
|
||||
noArgsNoReturnCalled = true;
|
||||
});
|
||||
return client.request("noArgsNoReturn");
|
||||
});
|
||||
it("should call the method", function () {
|
||||
(0, chai_1.expect)(noArgsNoReturnCalled).to.be.true;
|
||||
});
|
||||
});
|
||||
describe("calling method with no args", function () {
|
||||
var expected;
|
||||
var actual;
|
||||
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
expected = "return value";
|
||||
server.addMethod("noArgs", function () {
|
||||
return expected;
|
||||
});
|
||||
return [4 /*yield*/, client.request("noArgs")];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should call the method", function () {
|
||||
(0, chai_1.expect)(actual).to.equal(expected);
|
||||
});
|
||||
});
|
||||
describe("calling method with object args", function () {
|
||||
var actual;
|
||||
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
server.addMethod("objectArgs", function (_a) {
|
||||
var foo = _a.foo, bar = _a.bar;
|
||||
return "".concat(foo, ".").concat(bar);
|
||||
});
|
||||
return [4 /*yield*/, client.request("objectArgs", {
|
||||
foo: "string value",
|
||||
bar: 123,
|
||||
})];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should call the method", function () {
|
||||
(0, chai_1.expect)(actual).to.equal("string value.123");
|
||||
});
|
||||
});
|
||||
describe("calling method with array args", function () {
|
||||
var actual;
|
||||
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
server.addMethod("arrayArgs", function (_a) {
|
||||
var foo = _a[0], bar = _a[1];
|
||||
return "".concat(foo, ".").concat(bar);
|
||||
});
|
||||
return [4 /*yield*/, client.request("arrayArgs", ["string value", 123])];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should call the method", function () {
|
||||
(0, chai_1.expect)(actual).to.equal("string value.123");
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("server and client", function () {
|
||||
var serverAndClientA;
|
||||
var serverAndClientB;
|
||||
beforeEach(function () {
|
||||
serverAndClientA = new server_and_client_1.JSONRPCServerAndClient(new server_1.JSONRPCServer(), new client_1.JSONRPCClient(function (request) {
|
||||
return serverAndClientB.receiveAndSend(request);
|
||||
}));
|
||||
serverAndClientB = new server_and_client_1.JSONRPCServerAndClient(new server_1.JSONRPCServer(), new client_1.JSONRPCClient(function (request) {
|
||||
return serverAndClientA.receiveAndSend(request);
|
||||
}));
|
||||
serverAndClientA.addMethod("echo", function (_a) {
|
||||
var message = _a.message;
|
||||
return message;
|
||||
});
|
||||
serverAndClientB.addMethod("sum", function (_a) {
|
||||
var x = _a.x, y = _a.y;
|
||||
return x + y;
|
||||
});
|
||||
});
|
||||
describe("calling method from server A to B", function () {
|
||||
var actual;
|
||||
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, serverAndClientA.request("sum", { x: 1, y: 2 })];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should call the method", function () {
|
||||
(0, chai_1.expect)(actual).to.equal(3);
|
||||
});
|
||||
});
|
||||
describe("calling method from server B to A", function () {
|
||||
var expected;
|
||||
var actual;
|
||||
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
expected = "hello";
|
||||
return [4 /*yield*/, serverAndClientB.request("echo", { message: expected })];
|
||||
case 1:
|
||||
actual = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should call the method", function () {
|
||||
(0, chai_1.expect)(actual).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
1
node_modules/json-rpc-2.0/dist/server-and-client.spec.d.ts
generated
vendored
1
node_modules/json-rpc-2.0/dist/server-and-client.spec.d.ts
generated
vendored
@@ -1 +0,0 @@
|
||||
export {};
|
||||
244
node_modules/json-rpc-2.0/dist/server-and-client.spec.js
generated
vendored
244
node_modules/json-rpc-2.0/dist/server-and-client.spec.js
generated
vendored
@@ -1,244 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var mocha_1 = require("mocha");
|
||||
var chai_1 = require("chai");
|
||||
var sinon = require("sinon");
|
||||
var _1 = require(".");
|
||||
var client_1 = require("./client");
|
||||
(0, mocha_1.describe)("JSONRPCServerAndClient", function () {
|
||||
var serverAndClient1;
|
||||
var serverAndClient2;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
serverAndClient1 = new _1.JSONRPCServerAndClient(new _1.JSONRPCServer(), new client_1.JSONRPCClient(function (payload) {
|
||||
return serverAndClient2.receiveAndSend(payload, undefined);
|
||||
}));
|
||||
serverAndClient2 = new _1.JSONRPCServerAndClient(new _1.JSONRPCServer(), new client_1.JSONRPCClient(function (payload, params) {
|
||||
return serverAndClient1.receiveAndSend(payload, params);
|
||||
}));
|
||||
serverAndClient1.addMethod("echo1", function (_a) {
|
||||
var message = _a.message;
|
||||
return message;
|
||||
});
|
||||
serverAndClient1.addMethodAdvanced("echo1-2", function (jsonRPCRequest, params) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, ({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: jsonRPCRequest.id,
|
||||
result: "".concat(params === null || params === void 0 ? void 0 : params.userID, " said ").concat(jsonRPCRequest.params.message),
|
||||
})];
|
||||
});
|
||||
}); });
|
||||
serverAndClient2.addMethod("echo2", function (_a) {
|
||||
var message = _a.message;
|
||||
return message;
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
(0, mocha_1.describe)("requesting from server 1", function () {
|
||||
var result;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, serverAndClient1.request("echo2", { message: "foo" })];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should request to server 2", function () {
|
||||
(0, chai_1.expect)(result).to.equal("foo");
|
||||
});
|
||||
(0, mocha_1.describe)("removing the method", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
serverAndClient2.removeMethod("echo2");
|
||||
});
|
||||
(0, mocha_1.describe)("requesting from server 1", function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, serverAndClient1.requestAdvanced({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "echo2",
|
||||
params: { message: "foo" },
|
||||
})];
|
||||
case 1:
|
||||
response = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should return not found", function () {
|
||||
var _a;
|
||||
(0, chai_1.expect)((_a = response.error) === null || _a === void 0 ? void 0 : _a.code).to.equal(_1.JSONRPCErrorCode.MethodNotFound);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting from server 2", function () {
|
||||
var result;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, serverAndClient2.request("echo1", { message: "bar" })];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should request to server 1", function () {
|
||||
(0, chai_1.expect)(result).to.equal("bar");
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting from server 1 using advanced method", function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var request;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
request = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "echo1-2",
|
||||
params: { message: "test" },
|
||||
};
|
||||
return [4 /*yield*/, serverAndClient2.requestAdvanced(request, {
|
||||
userID: "baz",
|
||||
})];
|
||||
case 1:
|
||||
response = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should request to server 1", function () {
|
||||
(0, chai_1.expect)(response.result).to.equal("baz said test");
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting in batch", function () {
|
||||
var responses;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var requests;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
requests = [
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, method: "echo2", params: { message: "1" } },
|
||||
{ jsonrpc: _1.JSONRPC, id: 1, method: "echo2", params: { message: "2" } },
|
||||
];
|
||||
return [4 /*yield*/, serverAndClient1.requestAdvanced(requests)];
|
||||
case 1:
|
||||
responses = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should return responses", function () {
|
||||
(0, chai_1.expect)(responses).to.deep.equal([
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, result: "1" },
|
||||
{ jsonrpc: _1.JSONRPC, id: 1, result: "2" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("receiving invalid JSON-RPC message", function () {
|
||||
var promise;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
promise = serverAndClient1.receiveAndSend({});
|
||||
});
|
||||
(0, mocha_1.it)("should fail", function () {
|
||||
return promise.then(function () { return Promise.reject(new Error("Expected to fail")); }, function () { return undefined; });
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("having a pending request", function () {
|
||||
var promise;
|
||||
var resolve;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
serverAndClient2.addMethod("hang", function () {
|
||||
return new Promise(function (givenResolve) { return (resolve = givenResolve); });
|
||||
});
|
||||
promise = serverAndClient1.request("hang", undefined);
|
||||
});
|
||||
(0, mocha_1.describe)("rejecting all pending requests", function () {
|
||||
var message;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
message = "Connection is closed.";
|
||||
serverAndClient1.rejectAllPendingRequests(message);
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.it)("should reject the pending request", function () {
|
||||
return promise.then(function () { return Promise.reject(new Error("Expected to fail")); }, function (error) { return (0, chai_1.expect)(error.message).to.equal(message); });
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting with timeout", function () {
|
||||
var fakeTimers;
|
||||
var delay;
|
||||
var resolve;
|
||||
var promise;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers = sinon.useFakeTimers();
|
||||
delay = 100;
|
||||
serverAndClient2.addMethod("timeout", function () { return new Promise(function (givenResolve) { return (resolve = givenResolve); }); });
|
||||
promise = serverAndClient1.timeout(delay).request("timeout");
|
||||
});
|
||||
(0, mocha_1.describe)("timing out", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
fakeTimers.tick(delay);
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.it)("should reject", function () {
|
||||
return promise.then(function () { return Promise.reject(new Error("Expected to fail")); }, function () { return undefined; });
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("not timing out", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
resolve();
|
||||
});
|
||||
(0, mocha_1.it)("should succeed", function () {
|
||||
return promise;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
1
node_modules/json-rpc-2.0/dist/server.spec.d.ts
generated
vendored
1
node_modules/json-rpc-2.0/dist/server.spec.d.ts
generated
vendored
@@ -1 +0,0 @@
|
||||
export {};
|
||||
746
node_modules/json-rpc-2.0/dist/server.spec.js
generated
vendored
746
node_modules/json-rpc-2.0/dist/server.spec.js
generated
vendored
@@ -1,746 +0,0 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var mocha_1 = require("mocha");
|
||||
var chai_1 = require("chai");
|
||||
var _1 = require(".");
|
||||
(0, mocha_1.describe)("JSONRPCServer", function () {
|
||||
var server;
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
response = null;
|
||||
server = new _1.JSONRPCServer();
|
||||
});
|
||||
var waitUntil = function (predicate) {
|
||||
return Promise.resolve().then(function () {
|
||||
if (!predicate()) {
|
||||
return waitUntil(predicate);
|
||||
}
|
||||
});
|
||||
};
|
||||
(0, mocha_1.describe)("having an echo method", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
var echoMethod = function (_a, serverParams) {
|
||||
var text = _a.text;
|
||||
if (serverParams) {
|
||||
return "".concat(serverParams.userID, " said ").concat(text);
|
||||
}
|
||||
else {
|
||||
return text;
|
||||
}
|
||||
};
|
||||
server.addMethod("echo", echoMethod);
|
||||
});
|
||||
(0, mocha_1.describe)("receiving a request to the method", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
return server
|
||||
.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "echo",
|
||||
params: { text: "foo" },
|
||||
})
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should echo the text", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
result: "foo",
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("receiving a request to the method with user ID", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
return server
|
||||
.receiveJSON(JSON.stringify({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "echo",
|
||||
params: { text: "foo" },
|
||||
}), { userID: "bar" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should echo the text with the user ID", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
result: "bar said foo",
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("removing the echo method", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.removeMethod("echo");
|
||||
});
|
||||
(0, mocha_1.describe)("receiving a request to the method", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
return server
|
||||
.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "echo",
|
||||
params: { text: "foo" },
|
||||
})
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should respond not found", function () {
|
||||
var _a;
|
||||
(0, chai_1.expect)((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.code).to.equal(_1.JSONRPCErrorCode.MethodNotFound);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("responding undefined", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethod("ack", function () { return undefined; });
|
||||
return server
|
||||
.receive({ jsonrpc: _1.JSONRPC, id: 0, method: "ack" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should response with null result", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
result: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("throwing", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethod("throw", function () {
|
||||
throw new Error("Test throwing");
|
||||
});
|
||||
return server
|
||||
.receive({ jsonrpc: _1.JSONRPC, id: 0, method: "throw" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should respond error", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
error: {
|
||||
code: 0,
|
||||
message: "Test throwing",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("throwing JSONRPCErrorException", function () {
|
||||
var expected;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
expected = {
|
||||
message: "thrown",
|
||||
code: 1234,
|
||||
data: {
|
||||
foo: "bar",
|
||||
},
|
||||
};
|
||||
server.addMethod("throw", function () {
|
||||
throw new _1.JSONRPCErrorException(expected.message, expected.code, expected.data);
|
||||
});
|
||||
return server
|
||||
.receive({ jsonrpc: _1.JSONRPC, id: 0, method: "throw" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should respond error with custom code and data", function () {
|
||||
(0, chai_1.expect)(response.error).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("rejecting", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethodAdvanced("reject", function () {
|
||||
return Promise.reject(new Error("Test rejecting"));
|
||||
});
|
||||
return server
|
||||
.receive({ jsonrpc: _1.JSONRPC, id: 0, method: "reject" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should respond error", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
error: {
|
||||
code: 0,
|
||||
message: "Test rejecting",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("responding to a notification", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethod("foo", function () { return "foo"; });
|
||||
return server
|
||||
.receive({ jsonrpc: _1.JSONRPC, method: "foo" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should not respond", function () {
|
||||
(0, chai_1.expect)(response).to.be.null;
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("error on a notification", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethod("foo", function () { return Promise.reject(new Error("foo")); });
|
||||
return server
|
||||
.receive({ jsonrpc: _1.JSONRPC, method: "foo" })
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should not respond", function () {
|
||||
(0, chai_1.expect)(response).to.be.null;
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("responding null to a request", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethodAdvanced("foo", function () { return Promise.resolve(null); });
|
||||
return server
|
||||
.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "foo",
|
||||
})
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should respond error", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
error: {
|
||||
code: _1.JSONRPCErrorCode.InternalError,
|
||||
message: "Internal error",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("receiving a request to an unknown method", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
return server
|
||||
.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "foo",
|
||||
})
|
||||
.then(function (givenResponse) { return (response = givenResponse); });
|
||||
});
|
||||
(0, mocha_1.it)("should respond error", function () {
|
||||
(0, chai_1.expect)(response).to.deep.equal({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
error: {
|
||||
code: _1.JSONRPCErrorCode.MethodNotFound,
|
||||
message: "Method not found",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
[{}, "", "invalid JSON"].forEach(function (invalidJSON) {
|
||||
(0, mocha_1.describe)("receiving an invalid JSON (".concat(invalidJSON, ")"), function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receiveJSON(invalidJSON)];
|
||||
case 1:
|
||||
response = (_a.sent());
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should respond an error", function () {
|
||||
(0, chai_1.expect)(response.error.code).to.equal(_1.JSONRPCErrorCode.ParseError);
|
||||
});
|
||||
});
|
||||
});
|
||||
[
|
||||
{},
|
||||
{ jsonrpc: _1.JSONRPC },
|
||||
{ jsonrpc: _1.JSONRPC + "invalid", method: "" },
|
||||
].forEach(function (invalidRequest) {
|
||||
(0, mocha_1.describe)("receiving an invalid request (".concat(JSON.stringify(invalidRequest), ")"), function () {
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receive(invalidRequest)];
|
||||
case 1:
|
||||
response = (_a.sent());
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should respond an error", function () {
|
||||
(0, chai_1.expect)(response.error.code).to.equal(_1.JSONRPCErrorCode.InvalidRequest);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("having a custom mapErrorToJSONRPCErrorResponse method", function () {
|
||||
var errorMessagePrefix;
|
||||
var errorData;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
errorMessagePrefix = "Error: ";
|
||||
errorData = {
|
||||
foo: "bar",
|
||||
};
|
||||
server.mapErrorToJSONRPCErrorResponse = function (id, error) {
|
||||
return (0, _1.createJSONRPCErrorResponse)(id, error.code, "".concat(errorMessagePrefix).concat(error.message), errorData);
|
||||
};
|
||||
});
|
||||
(0, mocha_1.describe)("rejecting", function () {
|
||||
var errorCode;
|
||||
var errorMessage;
|
||||
var response;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
errorCode = 123;
|
||||
errorMessage = "test message";
|
||||
server.addMethod("throw", function () {
|
||||
var error = new Error(errorMessage);
|
||||
error.code = errorCode;
|
||||
throw error;
|
||||
});
|
||||
return [4 /*yield*/, server.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "throw",
|
||||
})];
|
||||
case 1:
|
||||
response = (_a.sent());
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should respond a custom error code", function () {
|
||||
(0, chai_1.expect)(response.error.code).to.equal(errorCode);
|
||||
});
|
||||
(0, mocha_1.it)("should respond a custom error message", function () {
|
||||
(0, chai_1.expect)(response.error.message).to.equal("".concat(errorMessagePrefix).concat(errorMessage));
|
||||
});
|
||||
(0, mocha_1.it)("should respond a custom error data", function () {
|
||||
(0, chai_1.expect)(response.error.data).to.deep.equal(errorData);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("having an async method", function () {
|
||||
var methodName;
|
||||
var receivedRequest;
|
||||
var receivedServerParams;
|
||||
var returnedResponse;
|
||||
var returnFromMethod;
|
||||
var throwFromMethod;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
methodName = "foo";
|
||||
server.addMethodAdvanced(methodName, function (request, serverParams) {
|
||||
receivedRequest = request;
|
||||
receivedServerParams = serverParams;
|
||||
return new Promise(function (resolve, reject) {
|
||||
returnedResponse = {
|
||||
id: request.id,
|
||||
jsonrpc: _1.JSONRPC,
|
||||
result: {
|
||||
foo: "bar",
|
||||
},
|
||||
};
|
||||
returnFromMethod = function () {
|
||||
resolve(returnedResponse);
|
||||
};
|
||||
throwFromMethod = function (error) {
|
||||
reject(error);
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("using middleware", function () {
|
||||
var middlewareCalled;
|
||||
var nextReturned;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
middlewareCalled = false;
|
||||
nextReturned = false;
|
||||
server.applyMiddleware(function (next, request, serverParams) {
|
||||
middlewareCalled = true;
|
||||
return next(request, serverParams).then(function (result) {
|
||||
nextReturned = true;
|
||||
return result;
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting", function () {
|
||||
var givenRequest;
|
||||
var givenServerParams;
|
||||
var actualResponse;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
givenRequest = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: methodName,
|
||||
params: { foo: "bar" },
|
||||
};
|
||||
givenServerParams = { userID: "baz" };
|
||||
server
|
||||
.receive(givenRequest, givenServerParams)
|
||||
.then(function (response) { return (actualResponse = response); });
|
||||
return consumeAllEvents();
|
||||
});
|
||||
(0, mocha_1.it)("should call the middleware", function () {
|
||||
(0, chai_1.expect)(middlewareCalled).to.be.true;
|
||||
});
|
||||
(0, mocha_1.it)("should receive a request", function () {
|
||||
(0, chai_1.expect)(receivedRequest).to.deep.equal(givenRequest);
|
||||
});
|
||||
(0, mocha_1.it)("should received server params", function () {
|
||||
(0, chai_1.expect)(receivedServerParams).to.deep.equal(givenServerParams);
|
||||
});
|
||||
(0, mocha_1.it)("should not return from the next middleware yet", function () {
|
||||
(0, chai_1.expect)(nextReturned).to.be.false;
|
||||
});
|
||||
(0, mocha_1.describe)("finishing the request", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
returnFromMethod();
|
||||
return consumeAllEvents();
|
||||
});
|
||||
(0, mocha_1.it)("should return from the next middleware", function () {
|
||||
(0, chai_1.expect)(nextReturned).to.be.true;
|
||||
});
|
||||
(0, mocha_1.it)("should return a response", function () {
|
||||
(0, chai_1.expect)(actualResponse).to.deep.equal(returnedResponse);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("using another middleware", function () {
|
||||
var secondMiddlewareCalled;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
secondMiddlewareCalled = false;
|
||||
server.applyMiddleware(function (next, request, serverParams) {
|
||||
secondMiddlewareCalled = true;
|
||||
return next(request, serverParams);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: methodName,
|
||||
params: {},
|
||||
});
|
||||
});
|
||||
(0, mocha_1.it)("should call the first middleware", function () {
|
||||
(0, chai_1.expect)(middlewareCalled).to.be.true;
|
||||
});
|
||||
(0, mocha_1.it)("should call the second middleware", function () {
|
||||
(0, chai_1.expect)(secondMiddlewareCalled).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("using a middleware that changes request and server params", function () {
|
||||
var changedParams;
|
||||
var changedServerParams;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
changedParams = {
|
||||
foo: "bar",
|
||||
};
|
||||
changedServerParams = {
|
||||
userID: "changed user ID",
|
||||
};
|
||||
server.applyMiddleware(function (next, request) {
|
||||
return next(__assign(__assign({}, request), { params: changedParams }), changedServerParams);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting", function () {
|
||||
var givenRequest;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
givenRequest = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: methodName,
|
||||
params: {
|
||||
foo: "foo",
|
||||
},
|
||||
};
|
||||
server.receive(givenRequest);
|
||||
returnFromMethod();
|
||||
return consumeAllEvents();
|
||||
});
|
||||
(0, mocha_1.it)("should change the request", function () {
|
||||
var expectedRequest = __assign(__assign({}, givenRequest), { params: changedParams });
|
||||
(0, chai_1.expect)(receivedRequest).to.deep.equal(expectedRequest);
|
||||
});
|
||||
(0, mocha_1.it)("should change the server params", function () {
|
||||
(0, chai_1.expect)(receivedServerParams).to.deep.equal(changedServerParams);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("using a middleware that changes response", function () {
|
||||
var changedResponse;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.applyMiddleware(function (next, request, serverParams) {
|
||||
return next(request, serverParams).then(function (response) {
|
||||
changedResponse = {
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: response.id,
|
||||
result: {
|
||||
foo: new Date().toString(),
|
||||
},
|
||||
};
|
||||
return changedResponse;
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("requesting", function () {
|
||||
var actualResponse;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server
|
||||
.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: methodName,
|
||||
params: {},
|
||||
})
|
||||
.then(function (response) { return (actualResponse = response); });
|
||||
returnFromMethod();
|
||||
return consumeAllEvents();
|
||||
});
|
||||
(0, mocha_1.it)("should return the changed response", function () {
|
||||
(0, chai_1.expect)(actualResponse).to.deep.equal(changedResponse);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("using middleware that catches exception", function () {
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.applyMiddleware(function (next, request, serverParams) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
return [4 /*yield*/, next(request, serverParams)];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
case 2:
|
||||
error_1 = _a.sent();
|
||||
return [2 /*return*/, (0, _1.createJSONRPCErrorResponse)(request.id, error_1.code || _1.JSONRPCErrorCode.InternalError, error_1.message)];
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
(0, mocha_1.describe)("throwing", function () {
|
||||
var error;
|
||||
var actualResponse;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server
|
||||
.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: methodName,
|
||||
params: {},
|
||||
})
|
||||
.then(function (response) { return (actualResponse = response); });
|
||||
error = { code: 123, message: "test" };
|
||||
throwFromMethod(error);
|
||||
return consumeAllEvents();
|
||||
});
|
||||
(0, mocha_1.it)("should catch the exception on middleware", function () {
|
||||
var expected = (0, _1.createJSONRPCErrorResponse)(0, error.code, error.message);
|
||||
(0, chai_1.expect)(actualResponse).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("throwing from non-advanced method", function () {
|
||||
var message;
|
||||
var code;
|
||||
var actualResponse;
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
message = "thrown from non-advanced method";
|
||||
code = 456;
|
||||
server.addMethod("throw", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
throw { message: message, code: code };
|
||||
});
|
||||
}); });
|
||||
return [4 /*yield*/, server.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: "throw",
|
||||
})];
|
||||
case 1:
|
||||
actualResponse = (_a.sent());
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should catch the exception on middleware", function () {
|
||||
var expected = (0, _1.createJSONRPCErrorResponse)(0, code, message);
|
||||
(0, chai_1.expect)(actualResponse).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("using multiple middleware", function () {
|
||||
var count;
|
||||
var first;
|
||||
var second;
|
||||
var third;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
count = 0;
|
||||
server.applyMiddleware(function (next, request, serverParams) {
|
||||
first = ++count;
|
||||
return next(request, serverParams);
|
||||
}, function (next, request, serverParams) {
|
||||
second = ++count;
|
||||
return next(request, serverParams);
|
||||
}, function (next, request, serverParams) {
|
||||
third = ++count;
|
||||
return next(request, serverParams);
|
||||
});
|
||||
server.receive({
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: 0,
|
||||
method: methodName,
|
||||
});
|
||||
return consumeAllEvents();
|
||||
});
|
||||
(0, mocha_1.it)("should call middleware in the applied order", function () {
|
||||
(0, chai_1.expect)([first, second, third]).to.deep.equal([1, 2, 3]);
|
||||
});
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("receiving batch requests", function () {
|
||||
var responses;
|
||||
(0, mocha_1.beforeEach)(function () {
|
||||
server.addMethod("echo", function (_a) {
|
||||
var message = _a.message;
|
||||
return message;
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("of 3 requests", function () {
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receive([
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, method: "echo", params: { message: "1" } },
|
||||
{ jsonrpc: _1.JSONRPC, id: 1, method: "echo", params: { message: "2" } },
|
||||
{ jsonrpc: _1.JSONRPC, id: 2, method: "echo", params: { message: "3" } },
|
||||
])];
|
||||
case 1:
|
||||
responses = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should return 3 responses", function () {
|
||||
(0, chai_1.expect)(responses.map(function (response) { return response.result; })).to.deep.equal(["1", "2", "3"]);
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("of 1 request", function () {
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receive([
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, method: "echo", params: { message: "1" } },
|
||||
])];
|
||||
case 1:
|
||||
responses = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should return 1 response", function () {
|
||||
(0, chai_1.expect)(responses.result).to.equal("1");
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("of notifications", function () {
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receive([
|
||||
{ jsonrpc: _1.JSONRPC, method: "echo", params: { message: "1" } },
|
||||
])];
|
||||
case 1:
|
||||
responses = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should return null", function () {
|
||||
(0, chai_1.expect)(responses).to.be.null;
|
||||
});
|
||||
});
|
||||
(0, mocha_1.describe)("of a valid and an invalid request", function () {
|
||||
(0, mocha_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, server.receive([
|
||||
1,
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, method: "echo", params: { message: "1" } },
|
||||
])];
|
||||
case 1:
|
||||
responses = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
(0, mocha_1.it)("should return a failure and a success response", function () {
|
||||
(0, chai_1.expect)(responses).to.deep.equal([
|
||||
{
|
||||
jsonrpc: _1.JSONRPC,
|
||||
id: null,
|
||||
error: {
|
||||
code: _1.JSONRPCErrorCode.InvalidRequest,
|
||||
message: "Invalid Request",
|
||||
},
|
||||
},
|
||||
{ jsonrpc: _1.JSONRPC, id: 0, result: "1" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
var consumeAllEvents = function () { return new Promise(function (resolve) { return setTimeout(resolve, 0); }); };
|
||||
10
node_modules/json-rpc-2.0/package.json
generated
vendored
10
node_modules/json-rpc-2.0/package.json
generated
vendored
@@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "json-rpc-2.0",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"description": "JSON-RPC 2.0 client and server",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"!*.spec.js",
|
||||
"!*.spec.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"format": "pretty-quick || echo \"Failed to format. Continuing...\"",
|
||||
@@ -28,12 +30,12 @@
|
||||
"homepage": "https://github.com/shogowada/json-rpc-2.0#readme",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.0",
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "^14.18.12",
|
||||
"@types/sinon": "^10.0.11",
|
||||
"chai": "^4.3.6",
|
||||
"del-cli": "^3.0.1",
|
||||
"mocha": "^9.2.2",
|
||||
"mocha": "^11.7.1",
|
||||
"prettier": "^2.6.1",
|
||||
"pretty-quick": "^3.1.3",
|
||||
"sinon": "^10.0.0",
|
||||
|
||||
Reference in New Issue
Block a user