json-rpc-protocol
Version:
JSON-RPC 2 protocol messages parsing and formatting
47 lines • 1.5 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.response = exports.request = exports.notification = exports.error = void 0;
var errors_1 = require("./errors");
// ===================================================================
var toJson = JSON.stringify;
// ===================================================================
// Note: `id` may be null if the identifier of the corresponding
// quests could not be detected.
exports.error = function (id, err) {
if (err == null || typeof err.toJsonRpcError !== 'function') {
err = new errors_1.JsonRpcError();
}
// Hide internal errors.
var errorPayload = err.toJsonRpcError();
return toJson({
error: errorPayload,
id: id,
jsonrpc: '2.0'
});
};
// -------------------------------------------------------------------
exports.notification = function (method, params) {
return toJson({
jsonrpc: '2.0',
method: method,
params: params
});
};
// -------------------------------------------------------------------
exports.request = function (id, method, params) {
return toJson({
id: id,
jsonrpc: '2.0',
method: method,
params: params
});
};
// -------------------------------------------------------------------
exports.response = function (id, result) {
return toJson({
id: id,
jsonrpc: '2.0',
result: result
});
};
//# sourceMappingURL=format.js.map
;