@adt/json-rpc
Advanced tools
Comparing version 0.0.1-SNAPSHOT.6 to 0.0.1-SNAPSHOT.9
@@ -17,2 +17,3 @@ 'use strict'; | ||
/** | ||
* TODO: Implementation | ||
* Parses Json to JsonRpc object | ||
@@ -36,2 +37,41 @@ * @param {String} str | ||
const validateId = o => { | ||
if ( ( "id" in o ) === false ) { | ||
throw new Error("Required 'id' param is not present"); | ||
} | ||
}; | ||
const validateMethod = method => { | ||
const methodType = typeof method; | ||
if ( methodType !== "string" ) { | ||
throw new Error("Method must be a string, but '" + methodType + "' given"); | ||
} | ||
}; | ||
const validateParams = params => { | ||
const paramsType = typeof params; | ||
const paramsIsArray = Array.isArray(params); | ||
if ( paramsType === "undefined" ) { | ||
return; | ||
} | ||
if ( paramsIsArray === false && ( paramsType !== "object" && paramsType !== "undefined" ) ) { | ||
throw new Error("Params must be an array, object or undefined, but '" + paramsType + "' given"); | ||
} | ||
}; | ||
const validateArguments = args => { | ||
if ( typeof args === "undefined") { | ||
throw new Error("Required parameters object not present"); | ||
} | ||
}; | ||
/** | ||
@@ -51,2 +91,4 @@ * JSON-RPC Error object | ||
validateArguments(o); | ||
if ( typeof o.code !== "number" ) { | ||
@@ -114,34 +156,2 @@ throw "Error code must be integer"; | ||
const validateId = o => { | ||
if ( ( "id" in o ) === false ) { | ||
throw new Error("Required 'id' param is not present"); | ||
} | ||
}; | ||
const validateMethod = method => { | ||
const methodType = typeof method; | ||
if ( methodType !== "string" ) { | ||
throw new Error("Method must be a string, but '" + methodType + "' given"); | ||
} | ||
}; | ||
const validateParams = params => { | ||
const paramsType = typeof params; | ||
const paramsIsArray = Array.isArray(params); | ||
if ( paramsType === "undefined" ) { | ||
return; | ||
} | ||
if ( paramsIsArray === false && ( paramsType !== "object" && paramsType !== "undefined" ) ) { | ||
throw new Error("Params must be an array, object or undefined, but '" + paramsType + "' given"); | ||
} | ||
}; | ||
// TODO: For now this is only one level shallow copy, but should be real deep copy with omitting functions | ||
@@ -182,5 +192,3 @@ const copyParams = params => { | ||
if ( (this instanceof JsonRpcEvent) === false ) { | ||
return new JsonRpcEvent(o); | ||
} | ||
validateArguments(o); | ||
@@ -213,3 +221,3 @@ validateMethod(o.method); | ||
* @class | ||
* @param {Object} o | ||
* @param {Object} o Parameters object | ||
* @param {String} o.method | ||
@@ -221,6 +229,3 @@ * @param {Array|Object|undefined} o.params Params must be an Array, Object or undefined | ||
/*if ( (this instanceof JsonRpcRequest) === false ) { | ||
return new JsonRpcRequest(o); | ||
}*/ | ||
validateArguments(o); | ||
validateMethod(o.method); | ||
@@ -292,6 +297,3 @@ const method = o.method; | ||
if ( ( this instanceof JsonRpcResponseError ) === false ) { | ||
return new JsonRpcResponseError(o); | ||
} | ||
validateArguments(o); | ||
validateId(o); | ||
@@ -323,6 +325,3 @@ | ||
if ( (this instanceof JsonRpcResponseResult ) === false ) { | ||
return new JsonRpcResponseResult(o); | ||
} | ||
validateArguments(o); | ||
validateId(o); | ||
@@ -329,0 +328,0 @@ |
@@ -13,2 +13,3 @@ /** | ||
/** | ||
* TODO: Implementation | ||
* Parses Json to JsonRpc object | ||
@@ -32,2 +33,41 @@ * @param {String} str | ||
const validateId = o => { | ||
if ( ( "id" in o ) === false ) { | ||
throw new Error("Required 'id' param is not present"); | ||
} | ||
}; | ||
const validateMethod = method => { | ||
const methodType = typeof method; | ||
if ( methodType !== "string" ) { | ||
throw new Error("Method must be a string, but '" + methodType + "' given"); | ||
} | ||
}; | ||
const validateParams = params => { | ||
const paramsType = typeof params; | ||
const paramsIsArray = Array.isArray(params); | ||
if ( paramsType === "undefined" ) { | ||
return; | ||
} | ||
if ( paramsIsArray === false && ( paramsType !== "object" && paramsType !== "undefined" ) ) { | ||
throw new Error("Params must be an array, object or undefined, but '" + paramsType + "' given"); | ||
} | ||
}; | ||
const validateArguments = args => { | ||
if ( typeof args === "undefined") { | ||
throw new Error("Required parameters object not present"); | ||
} | ||
}; | ||
/** | ||
@@ -47,2 +87,4 @@ * JSON-RPC Error object | ||
validateArguments(o); | ||
if ( typeof o.code !== "number" ) { | ||
@@ -110,34 +152,2 @@ throw "Error code must be integer"; | ||
const validateId = o => { | ||
if ( ( "id" in o ) === false ) { | ||
throw new Error("Required 'id' param is not present"); | ||
} | ||
}; | ||
const validateMethod = method => { | ||
const methodType = typeof method; | ||
if ( methodType !== "string" ) { | ||
throw new Error("Method must be a string, but '" + methodType + "' given"); | ||
} | ||
}; | ||
const validateParams = params => { | ||
const paramsType = typeof params; | ||
const paramsIsArray = Array.isArray(params); | ||
if ( paramsType === "undefined" ) { | ||
return; | ||
} | ||
if ( paramsIsArray === false && ( paramsType !== "object" && paramsType !== "undefined" ) ) { | ||
throw new Error("Params must be an array, object or undefined, but '" + paramsType + "' given"); | ||
} | ||
}; | ||
// TODO: For now this is only one level shallow copy, but should be real deep copy with omitting functions | ||
@@ -178,5 +188,3 @@ const copyParams = params => { | ||
if ( (this instanceof JsonRpcEvent) === false ) { | ||
return new JsonRpcEvent(o); | ||
} | ||
validateArguments(o); | ||
@@ -209,3 +217,3 @@ validateMethod(o.method); | ||
* @class | ||
* @param {Object} o | ||
* @param {Object} o Parameters object | ||
* @param {String} o.method | ||
@@ -217,6 +225,3 @@ * @param {Array|Object|undefined} o.params Params must be an Array, Object or undefined | ||
/*if ( (this instanceof JsonRpcRequest) === false ) { | ||
return new JsonRpcRequest(o); | ||
}*/ | ||
validateArguments(o); | ||
validateMethod(o.method); | ||
@@ -288,6 +293,3 @@ const method = o.method; | ||
if ( ( this instanceof JsonRpcResponseError ) === false ) { | ||
return new JsonRpcResponseError(o); | ||
} | ||
validateArguments(o); | ||
validateId(o); | ||
@@ -319,6 +321,3 @@ | ||
if ( (this instanceof JsonRpcResponseResult ) === false ) { | ||
return new JsonRpcResponseResult(o); | ||
} | ||
validateArguments(o); | ||
validateId(o); | ||
@@ -325,0 +324,0 @@ |
@@ -25,2 +25,3 @@ (function (global, factory) { | ||
/** | ||
* TODO: Implementation | ||
* Parses Json to JsonRpc object | ||
@@ -44,2 +45,41 @@ * @param {String} str | ||
const validateId = o => { | ||
if ( ( "id" in o ) === false ) { | ||
throw new Error("Required 'id' param is not present"); | ||
} | ||
}; | ||
const validateMethod = method => { | ||
const methodType = typeof method; | ||
if ( methodType !== "string" ) { | ||
throw new Error("Method must be a string, but '" + methodType + "' given"); | ||
} | ||
}; | ||
const validateParams = params => { | ||
const paramsType = typeof params; | ||
const paramsIsArray = Array.isArray(params); | ||
if ( paramsType === "undefined" ) { | ||
return; | ||
} | ||
if ( paramsIsArray === false && ( paramsType !== "object" && paramsType !== "undefined" ) ) { | ||
throw new Error("Params must be an array, object or undefined, but '" + paramsType + "' given"); | ||
} | ||
}; | ||
const validateArguments = args => { | ||
if ( typeof args === "undefined") { | ||
throw new Error("Required parameters object not present"); | ||
} | ||
}; | ||
/** | ||
@@ -59,2 +99,4 @@ * JSON-RPC Error object | ||
validateArguments(o); | ||
if ( typeof o.code !== "number" ) { | ||
@@ -122,34 +164,2 @@ throw "Error code must be integer"; | ||
const validateId = o => { | ||
if ( ( "id" in o ) === false ) { | ||
throw new Error("Required 'id' param is not present"); | ||
} | ||
}; | ||
const validateMethod = method => { | ||
const methodType = typeof method; | ||
if ( methodType !== "string" ) { | ||
throw new Error("Method must be a string, but '" + methodType + "' given"); | ||
} | ||
}; | ||
const validateParams = params => { | ||
const paramsType = typeof params; | ||
const paramsIsArray = Array.isArray(params); | ||
if ( paramsType === "undefined" ) { | ||
return; | ||
} | ||
if ( paramsIsArray === false && ( paramsType !== "object" && paramsType !== "undefined" ) ) { | ||
throw new Error("Params must be an array, object or undefined, but '" + paramsType + "' given"); | ||
} | ||
}; | ||
// TODO: For now this is only one level shallow copy, but should be real deep copy with omitting functions | ||
@@ -190,5 +200,3 @@ const copyParams = params => { | ||
if ( (this instanceof JsonRpcEvent) === false ) { | ||
return new JsonRpcEvent(o); | ||
} | ||
validateArguments(o); | ||
@@ -221,3 +229,3 @@ validateMethod(o.method); | ||
* @class | ||
* @param {Object} o | ||
* @param {Object} o Parameters object | ||
* @param {String} o.method | ||
@@ -229,6 +237,3 @@ * @param {Array|Object|undefined} o.params Params must be an Array, Object or undefined | ||
/*if ( (this instanceof JsonRpcRequest) === false ) { | ||
return new JsonRpcRequest(o); | ||
}*/ | ||
validateArguments(o); | ||
validateMethod(o.method); | ||
@@ -300,6 +305,3 @@ const method = o.method; | ||
if ( ( this instanceof JsonRpcResponseError ) === false ) { | ||
return new JsonRpcResponseError(o); | ||
} | ||
validateArguments(o); | ||
validateId(o); | ||
@@ -331,6 +333,3 @@ | ||
if ( (this instanceof JsonRpcResponseResult ) === false ) { | ||
return new JsonRpcResponseResult(o); | ||
} | ||
validateArguments(o); | ||
validateId(o); | ||
@@ -337,0 +336,0 @@ |
{ | ||
"name": "@adt/json-rpc", | ||
"version": "0.0.1-SNAPSHOT.6", | ||
"version": "0.0.1-SNAPSHOT.9", | ||
"license" : "MIT", | ||
@@ -21,2 +21,5 @@ "main": "dist/JsonRpc.cjs.js", | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
@@ -23,0 +26,0 @@ "CHANGELOG.md", |
@@ -14,3 +14,3 @@ # JsonRpc | ||
npm install @adc/json-rpc | ||
npm install @adt/json-rpc | ||
@@ -17,0 +17,0 @@ ## Why i should use Json-RPC? |
Sorry, the diff of this file is not supported yet
29544
777