@adt/json-rpc
Advanced tools
Comparing version 0.0.1-SNAPSHOT.19 to 0.0.1-SNAPSHOT.20
@@ -16,14 +16,2 @@ 'use strict'; | ||
/** | ||
* TODO: Implementation | ||
* Parses Json to JsonRpc object | ||
* @param {String} str | ||
* @return JsonRpcElement | ||
*/ | ||
JsonRpcElement.parse = function (str) { | ||
// TODO: | ||
}; | ||
JsonRpcElement.prototype = Object.freeze(Object.create(null, /** @lends JsonRpcElement.prototype */{ | ||
@@ -409,3 +397,3 @@ jsonrpc: { value: "2.0" }, | ||
/** | ||
* Serialize request to object to string | ||
* Serialize request object to string | ||
* @return {String} | ||
@@ -505,2 +493,82 @@ */ | ||
//import JsonRpcElement from "./JsonRpcElement"; | ||
/** | ||
* Parses Json to JsonRpc object | ||
* @param {String} str String to parse | ||
* @param {Boolean} [weak=false] Don't check for existence of "jsonrpc" property in object | ||
* @return JsonRpcElement | ||
*/ | ||
var parse = function parse(str, weak) { | ||
var u = "undefined"; | ||
var obj = void 0; | ||
try { | ||
obj = JSON.parse(str); | ||
} catch (e) { | ||
throw new Error("String " + str + " is not a valid JSON"); | ||
} | ||
if (weak === true && "jsonrpc" in obj === false) { | ||
// TODO: Dedicated exception | ||
throw new Error("Missing 'jsonrpc' property in unserialized. You can omit this check by using the `weak` param"); | ||
} | ||
var _obj = obj, | ||
id = _obj.id, | ||
method = _obj.method, | ||
result = _obj.result, | ||
error = _obj.error, | ||
params = _obj.params; | ||
if ((typeof id === "undefined" ? "undefined" : _typeof(id)) !== u) { | ||
// Request or response | ||
if ((typeof method === "undefined" ? "undefined" : _typeof(method)) !== u) { | ||
if ((typeof params === "undefined" ? "undefined" : _typeof(params)) === u) { | ||
throw new Error("Missing 'method' property in unserialized object"); | ||
} | ||
return JsonRpcRequest({ | ||
id: id, method: method, params: params | ||
}); | ||
} else if ((typeof result === "undefined" ? "undefined" : _typeof(result)) !== u) { | ||
return JsonRpcResponseResult({ | ||
id: id, result: result | ||
}); | ||
} else if ((typeof error === "undefined" ? "undefined" : _typeof(error)) !== u) { | ||
var code = error.code, | ||
message = error.message, | ||
data = error.data; | ||
return JsonRpcResponseError({ | ||
id: id, | ||
error: JsonRpcError({ | ||
code: code, message: message, data: data | ||
}) | ||
}); | ||
} else { | ||
// TODO: Dedicated Exception | ||
throw new Error("Unserialized object is not a valid JSON-RPC element"); | ||
} | ||
} else { | ||
// Event | ||
return JsonRpcEvent({ | ||
method: method, params: params | ||
}); | ||
} | ||
}; | ||
JsonRpcElement.parse = parse; | ||
JsonRpcElement.fromJson = parse; | ||
exports.JsonRpcElement = JsonRpcElement; | ||
@@ -507,0 +575,0 @@ exports.JsonRpcError = JsonRpcError; |
@@ -12,14 +12,2 @@ /** | ||
/** | ||
* TODO: Implementation | ||
* Parses Json to JsonRpc object | ||
* @param {String} str | ||
* @return JsonRpcElement | ||
*/ | ||
JsonRpcElement.parse = function (str) { | ||
// TODO: | ||
}; | ||
JsonRpcElement.prototype = Object.freeze(Object.create(null, /** @lends JsonRpcElement.prototype */{ | ||
@@ -405,3 +393,3 @@ jsonrpc: { value: "2.0" }, | ||
/** | ||
* Serialize request to object to string | ||
* Serialize request object to string | ||
* @return {String} | ||
@@ -501,2 +489,82 @@ */ | ||
//import JsonRpcElement from "./JsonRpcElement"; | ||
/** | ||
* Parses Json to JsonRpc object | ||
* @param {String} str String to parse | ||
* @param {Boolean} [weak=false] Don't check for existence of "jsonrpc" property in object | ||
* @return JsonRpcElement | ||
*/ | ||
var parse = function parse(str, weak) { | ||
var u = "undefined"; | ||
var obj = void 0; | ||
try { | ||
obj = JSON.parse(str); | ||
} catch (e) { | ||
throw new Error("String " + str + " is not a valid JSON"); | ||
} | ||
if (weak === true && "jsonrpc" in obj === false) { | ||
// TODO: Dedicated exception | ||
throw new Error("Missing 'jsonrpc' property in unserialized. You can omit this check by using the `weak` param"); | ||
} | ||
var _obj = obj, | ||
id = _obj.id, | ||
method = _obj.method, | ||
result = _obj.result, | ||
error = _obj.error, | ||
params = _obj.params; | ||
if ((typeof id === "undefined" ? "undefined" : _typeof(id)) !== u) { | ||
// Request or response | ||
if ((typeof method === "undefined" ? "undefined" : _typeof(method)) !== u) { | ||
if ((typeof params === "undefined" ? "undefined" : _typeof(params)) === u) { | ||
throw new Error("Missing 'method' property in unserialized object"); | ||
} | ||
return JsonRpcRequest({ | ||
id: id, method: method, params: params | ||
}); | ||
} else if ((typeof result === "undefined" ? "undefined" : _typeof(result)) !== u) { | ||
return JsonRpcResponseResult({ | ||
id: id, result: result | ||
}); | ||
} else if ((typeof error === "undefined" ? "undefined" : _typeof(error)) !== u) { | ||
var code = error.code, | ||
message = error.message, | ||
data = error.data; | ||
return JsonRpcResponseError({ | ||
id: id, | ||
error: JsonRpcError({ | ||
code: code, message: message, data: data | ||
}) | ||
}); | ||
} else { | ||
// TODO: Dedicated Exception | ||
throw new Error("Unserialized object is not a valid JSON-RPC element"); | ||
} | ||
} else { | ||
// Event | ||
return JsonRpcEvent({ | ||
method: method, params: params | ||
}); | ||
} | ||
}; | ||
JsonRpcElement.parse = parse; | ||
JsonRpcElement.fromJson = parse; | ||
export { JsonRpcElement, JsonRpcError, JsonRpcEvent, JsonRpcRequest, JsonRpcResponse, JsonRpcResponseError, JsonRpcResponseResult }; |
@@ -24,14 +24,2 @@ (function (global, factory) { | ||
/** | ||
* TODO: Implementation | ||
* Parses Json to JsonRpc object | ||
* @param {String} str | ||
* @return JsonRpcElement | ||
*/ | ||
JsonRpcElement.parse = function (str) { | ||
// TODO: | ||
}; | ||
JsonRpcElement.prototype = Object.freeze(Object.create(null, /** @lends JsonRpcElement.prototype */{ | ||
@@ -417,3 +405,3 @@ jsonrpc: { value: "2.0" }, | ||
/** | ||
* Serialize request to object to string | ||
* Serialize request object to string | ||
* @return {String} | ||
@@ -513,2 +501,82 @@ */ | ||
//import JsonRpcElement from "./JsonRpcElement"; | ||
/** | ||
* Parses Json to JsonRpc object | ||
* @param {String} str String to parse | ||
* @param {Boolean} [weak=false] Don't check for existence of "jsonrpc" property in object | ||
* @return JsonRpcElement | ||
*/ | ||
var parse = function parse(str, weak) { | ||
var u = "undefined"; | ||
var obj = void 0; | ||
try { | ||
obj = JSON.parse(str); | ||
} catch (e) { | ||
throw new Error("String " + str + " is not a valid JSON"); | ||
} | ||
if (weak === true && "jsonrpc" in obj === false) { | ||
// TODO: Dedicated exception | ||
throw new Error("Missing 'jsonrpc' property in unserialized. You can omit this check by using the `weak` param"); | ||
} | ||
var _obj = obj, | ||
id = _obj.id, | ||
method = _obj.method, | ||
result = _obj.result, | ||
error = _obj.error, | ||
params = _obj.params; | ||
if ((typeof id === "undefined" ? "undefined" : _typeof(id)) !== u) { | ||
// Request or response | ||
if ((typeof method === "undefined" ? "undefined" : _typeof(method)) !== u) { | ||
if ((typeof params === "undefined" ? "undefined" : _typeof(params)) === u) { | ||
throw new Error("Missing 'method' property in unserialized object"); | ||
} | ||
return JsonRpcRequest({ | ||
id: id, method: method, params: params | ||
}); | ||
} else if ((typeof result === "undefined" ? "undefined" : _typeof(result)) !== u) { | ||
return JsonRpcResponseResult({ | ||
id: id, result: result | ||
}); | ||
} else if ((typeof error === "undefined" ? "undefined" : _typeof(error)) !== u) { | ||
var code = error.code, | ||
message = error.message, | ||
data = error.data; | ||
return JsonRpcResponseError({ | ||
id: id, | ||
error: JsonRpcError({ | ||
code: code, message: message, data: data | ||
}) | ||
}); | ||
} else { | ||
// TODO: Dedicated Exception | ||
throw new Error("Unserialized object is not a valid JSON-RPC element"); | ||
} | ||
} else { | ||
// Event | ||
return JsonRpcEvent({ | ||
method: method, params: params | ||
}); | ||
} | ||
}; | ||
JsonRpcElement.parse = parse; | ||
JsonRpcElement.fromJson = parse; | ||
exports.JsonRpcElement = JsonRpcElement; | ||
@@ -515,0 +583,0 @@ exports.JsonRpcError = JsonRpcError; |
{ | ||
"name": "@adt/json-rpc", | ||
"version": "0.0.1-SNAPSHOT.19", | ||
"version": "0.0.1-SNAPSHOT.20", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/JsonRpc.cjs.js", |
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
47745
1359