noice-json-rpc
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
/// <reference path="../typings/index.d.ts" /> | ||
/// <reference types="node" /> | ||
import { JsonRpc2 } from './json-rpc2'; | ||
@@ -3,0 +3,0 @@ import { EventEmitter } from 'events'; |
@@ -1,2 +0,1 @@ | ||
/// <reference path="../typings/index.d.ts" /> | ||
"use strict"; | ||
@@ -21,3 +20,3 @@ const events_1 = require('events'); | ||
if (!socket) { | ||
throw new TypeError("socket cannot be undefined or null"); | ||
throw new TypeError('socket cannot be undefined or null'); | ||
} | ||
@@ -32,3 +31,3 @@ this._socket = socket; | ||
processMessage(messageStr) { | ||
this._logMessage(messageStr, "receive"); | ||
this._logMessage(messageStr, 'receive'); | ||
let message; | ||
@@ -84,3 +83,3 @@ // Ensure JSON is not malformed | ||
for (let messageStr of this._requestQueue) { | ||
this._logMessage(messageStr, "send"); | ||
this._logMessage(messageStr, 'send'); | ||
this._socket.send(messageStr); | ||
@@ -93,3 +92,3 @@ } | ||
if (this._consoleLog) { | ||
console.log(`Client ${direction === "send" ? ">" : "<"}`, message); | ||
console.log(`Client ${direction === 'send' ? '>' : '<'}`, message); | ||
} | ||
@@ -121,3 +120,3 @@ if (this._emitLog) { | ||
if (!Proxy) { | ||
throw new Error("api() requires ES6 Proxy. Please use an ES6 compatible engine"); | ||
throw new Error('api() requires ES6 Proxy. Please use an ES6 compatible engine'); | ||
} | ||
@@ -130,3 +129,3 @@ return new Proxy({}, { | ||
// Special handling for prototype so console intellisense works on noice objects | ||
if (prop === "__proto__" || prop === "prototype") { | ||
if (prop === '__proto__' || prop === 'prototype') { | ||
return Object.prototype; | ||
@@ -137,7 +136,7 @@ } | ||
} | ||
else if (prop.substr(0, 2) === "on" && prop.length > 3) { | ||
else if (prop.substr(0, 2) === 'on' && prop.length > 3) { | ||
const method = prop[2].toLowerCase() + prop.substr(3); | ||
target[prop] = (handler) => this.on(`${prefix}${method}`, handler); | ||
} | ||
else if (prop.substr(0, 4) === "emit" && prop.length > 5) { | ||
else if (prop.substr(0, 4) === 'emit' && prop.length > 5) { | ||
const method = prop[4].toLowerCase() + prop.substr(5); | ||
@@ -170,3 +169,3 @@ target[prop] = (params) => this.notify(`${prefix}${method}`, params); | ||
if (!server) { | ||
throw new TypeError("server cannot be undefined or null"); | ||
throw new TypeError('server cannot be undefined or null'); | ||
} | ||
@@ -179,3 +178,3 @@ this._socketServer = server; | ||
processMessage(messageStr, socket) { | ||
this._logMessage(messageStr, "receive"); | ||
this._logMessage(messageStr, 'receive'); | ||
let request; | ||
@@ -190,4 +189,4 @@ // Ensure JSON is not malformed | ||
// Ensure method is atleast defined | ||
if (request && request.method && typeof request.method == "string") { | ||
if (request.id && typeof request.id === "number") { | ||
if (request && request.method && typeof request.method === 'string') { | ||
if (request.id && typeof request.id === 'number') { | ||
const handler = this._exposedMethodsMap.get(request.method); | ||
@@ -236,3 +235,3 @@ // Handler is defined so lets call it | ||
if (this._consoleLog) { | ||
console.log(`Server ${direction === "send" ? ">" : "<"}`, messageStr); | ||
console.log(`Server ${direction === 'send' ? '>' : '<'}`, messageStr); | ||
} | ||
@@ -245,3 +244,3 @@ if (this._emitLog) { | ||
const messageStr = JSON.stringify(message); | ||
this._logMessage(messageStr, "send"); | ||
this._logMessage(messageStr, 'send'); | ||
socket.send(messageStr); | ||
@@ -256,3 +255,3 @@ } | ||
_errorFromCode(code, data, method) { | ||
let message = ""; | ||
let message = ''; | ||
switch (code) { | ||
@@ -266,6 +265,6 @@ case -32603 /* InternalError */: | ||
case -32600 /* InvalidRequest */: | ||
message = "InvalidRequest: JSON sent is not a valid request object"; | ||
message = 'InvalidRequest: JSON sent is not a valid request object'; | ||
break; | ||
case -32700 /* ParseError */: | ||
message = "ParseError: invalid JSON received"; | ||
message = 'ParseError: invalid JSON received'; | ||
break; | ||
@@ -286,3 +285,3 @@ } | ||
else { | ||
throw new Error("SocketServer does not support broadcasting. No 'clients: LikeSocket[]' property found"); | ||
throw new Error('SocketServer does not support broadcasting. No "clients: LikeSocket[]" property found'); | ||
} | ||
@@ -298,3 +297,3 @@ } | ||
if (!Proxy) { | ||
throw new Error("api() requires ES6 Proxy. Please use an ES6 compatible engine"); | ||
throw new Error('api() requires ES6 Proxy. Please use an ES6 compatible engine'); | ||
} | ||
@@ -306,3 +305,3 @@ return new Proxy({}, { | ||
} | ||
if (prop === "__proto__" || prop === "prototype") { | ||
if (prop === '__proto__' || prop === 'prototype') { | ||
return Object.prototype; | ||
@@ -313,17 +312,17 @@ } | ||
} | ||
else if (prop.substr(0, 2) === "on" && prop.length > 3) { | ||
else if (prop.substr(0, 2) === 'on' && prop.length > 3) { | ||
const method = prop[2].toLowerCase() + prop.substr(3); | ||
target[prop] = (handler) => this.on(`${prefix}${method}`, handler); | ||
} | ||
else if (prop.substr(0, 4) === "emit" && prop.length > 5) { | ||
else if (prop.substr(0, 4) === 'emit' && prop.length > 5) { | ||
const method = prop[4].toLowerCase() + prop.substr(5); | ||
target[prop] = (params) => this.notify(`${prefix}${method}`, params); | ||
} | ||
else if (prop === "expose") { | ||
else if (prop === 'expose') { | ||
target[prop] = (module) => { | ||
if (!module || typeof module !== "object") { | ||
throw new Error("Expected an iterable object to expose functions"); | ||
if (!module || typeof module !== 'object') { | ||
throw new Error('Expected an iterable object to expose functions'); | ||
} | ||
for (let funcName in module) { | ||
if (typeof module[funcName] === "function") { | ||
if (typeof module[funcName] === 'function') { | ||
this.expose(`${prefix}${funcName}`, module[funcName].bind(module)); | ||
@@ -330,0 +329,0 @@ } |
{ | ||
"name": "noice-json-rpc", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Noice Json RPC exposes a clean ES6 Proxy and Promise based interface for JSON-RPC2 Clients and Servers", | ||
@@ -15,2 +15,3 @@ "main": "lib/noice-json-rpc.js", | ||
"test": "istanbul cover node_modules/.bin/_mocha -- -R spec out/*.test.js", | ||
"tslint": "tslint -c tslint.json src/*.ts tests/*.ts", | ||
"mocha-debug": "mocha --debug-brk -R spec out/*.test.js", | ||
@@ -43,9 +44,17 @@ "coveralls": "cat coverage/lcov.info | node_modules/.bin/coveralls", | ||
"devDependencies": { | ||
"@types/chai": "^3.4.34", | ||
"@types/mocha": "^2.2.32", | ||
"@types/node": "^6.0.43", | ||
"@types/sinon": "^1.16.31", | ||
"@types/ws": "0.0.34", | ||
"chai": "^3.5.0", | ||
"chrome-remote-debug-protocol": "^1.0.1", | ||
"coveralls": "^2.11.11", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^2.5.3", | ||
"sinon": "^1.17.4", | ||
"tslint": "^3.15.1", | ||
"typescript": "^2.0.3", | ||
"ws": "^1.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
26274
6
0
91
14
504