@cosmjs/json-rpc
Advanced tools
Comparing version 0.26.6 to 0.26.8
@@ -44,7 +44,5 @@ "use strict"; | ||
} | ||
// TODO: replace with Object.values when available (ES2017+) | ||
const values = Object.getOwnPropertyNames(data).map((key) => data[key]); | ||
return values.every(isJsonCompatibleValue); | ||
return Object.values(data).every(isJsonCompatibleValue); | ||
} | ||
exports.isJsonCompatibleDictionary = isJsonCompatibleDictionary; | ||
//# sourceMappingURL=compatibility.js.map |
@@ -10,33 +10,33 @@ "use strict"; | ||
it("returns true for primitive types", () => { | ||
expect(compatibility_1.isJsonCompatibleValue(null)).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue(0)).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue(1)).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue("abc")).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue(true)).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue(false)).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)(null)).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)(0)).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)(1)).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)("abc")).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)(true)).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)(false)).toEqual(true); | ||
}); | ||
it("returns true for arrays", () => { | ||
expect(compatibility_1.isJsonCompatibleValue([1, 2, 3])).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue([1, "2", true, null])).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue([1, "2", true, null, [1, "2", true, null]])).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue([{ a: 123 }])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)([1, 2, 3])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)([1, "2", true, null])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)([1, "2", true, null, [1, "2", true, null]])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)([{ a: 123 }])).toEqual(true); | ||
}); | ||
it("returns true for simple dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleValue({ a: 123 })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue({ a: "abc" })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue({ a: true })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue({ a: null })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: 123 })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: "abc" })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: true })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: null })).toEqual(true); | ||
}); | ||
it("returns true for dict with array", () => { | ||
expect(compatibility_1.isJsonCompatibleValue({ a: [1, 2, 3] })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleValue({ a: [1, "2", true, null] })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: [1, 2, 3] })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: [1, "2", true, null] })).toEqual(true); | ||
}); | ||
it("returns true for nested dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleValue({ a: { b: 123 } })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({ a: { b: 123 } })).toEqual(true); | ||
}); | ||
it("returns false for functions", () => { | ||
expect(compatibility_1.isJsonCompatibleValue(sum)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleValue)(sum)).toEqual(false); | ||
}); | ||
it("returns true for empty dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleValue({})).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleValue)({})).toEqual(true); | ||
}); | ||
@@ -46,24 +46,24 @@ }); | ||
it("returns false for primitive types", () => { | ||
expect(compatibility_1.isJsonCompatibleArray(null)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray(undefined)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray(0)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray(1)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray("abc")).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray(true)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray(false)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(null)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(undefined)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(0)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(1)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)("abc")).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(true)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(false)).toEqual(false); | ||
}); | ||
it("returns true for arrays", () => { | ||
expect(compatibility_1.isJsonCompatibleArray([1, 2, 3])).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleArray([1, "2", true, null])).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleArray([1, "2", true, null, [1, "2", true, null]])).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleArray([{ a: 123 }])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleArray)([1, 2, 3])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleArray)([1, "2", true, null])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleArray)([1, "2", true, null, [1, "2", true, null]])).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleArray)([{ a: 123 }])).toEqual(true); | ||
}); | ||
it("returns false for dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleArray({ a: 123 })).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray({ a: "abc" })).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray({ a: true })).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleArray({ a: null })).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)({ a: 123 })).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)({ a: "abc" })).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)({ a: true })).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)({ a: null })).toEqual(false); | ||
}); | ||
it("returns false for functions", () => { | ||
expect(compatibility_1.isJsonCompatibleArray(sum)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleArray)(sum)).toEqual(false); | ||
}); | ||
@@ -73,36 +73,36 @@ }); | ||
it("returns false for primitive types", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary(null)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(undefined)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(0)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(1)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary("abc")).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(true)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(false)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(null)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(undefined)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(0)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(1)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)("abc")).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(true)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(false)).toEqual(false); | ||
}); | ||
it("returns false for other objects", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary(new Uint8Array([0x00]))).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(/123/)).toEqual(false); | ||
expect(compatibility_1.isJsonCompatibleDictionary(new Date())).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(new Uint8Array([0x00]))).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(/123/)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(new Date())).toEqual(false); | ||
}); | ||
it("returns false for arrays", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary([1, 2, 3])).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)([1, 2, 3])).toEqual(false); | ||
}); | ||
it("returns false for functions", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary(sum)).toEqual(false); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)(sum)).toEqual(false); | ||
}); | ||
it("returns true for empty dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary({})).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({})).toEqual(true); | ||
}); | ||
it("returns true for simple dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: 123 })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: "abc" })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: true })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: null })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: 123 })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: "abc" })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: true })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: null })).toEqual(true); | ||
}); | ||
it("returns true for dict with array", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: [1, 2, 3] })).toEqual(true); | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: [1, "2", true, null] })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: [1, 2, 3] })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: [1, "2", true, null] })).toEqual(true); | ||
}); | ||
it("returns true for nested dicts", () => { | ||
expect(compatibility_1.isJsonCompatibleDictionary({ a: { b: 123 } })).toEqual(true); | ||
expect((0, compatibility_1.isJsonCompatibleDictionary)({ a: { b: 123 } })).toEqual(true); | ||
}); | ||
@@ -109,0 +109,0 @@ }); |
@@ -7,3 +7,3 @@ "use strict"; | ||
it("returns a string or number", () => { | ||
const id = id_1.makeJsonRpcId(); | ||
const id = (0, id_1.makeJsonRpcId)(); | ||
expect(["string", "number"]).toContain(typeof id); | ||
@@ -13,7 +13,7 @@ }); | ||
const ids = new Set([ | ||
id_1.makeJsonRpcId(), | ||
id_1.makeJsonRpcId(), | ||
id_1.makeJsonRpcId(), | ||
id_1.makeJsonRpcId(), | ||
id_1.makeJsonRpcId(), | ||
(0, id_1.makeJsonRpcId)(), | ||
(0, id_1.makeJsonRpcId)(), | ||
(0, id_1.makeJsonRpcId)(), | ||
(0, id_1.makeJsonRpcId)(), | ||
(0, id_1.makeJsonRpcId)(), | ||
]); | ||
@@ -20,0 +20,0 @@ expect(ids.size).toEqual(5); |
export { makeJsonRpcId } from "./id"; | ||
export { JsonRpcClient, SimpleMessagingConnection } from "./jsonrpcclient"; | ||
export { parseJsonRpcId, parseJsonRpcRequest, parseJsonRpcResponse, parseJsonRpcErrorResponse, parseJsonRpcSuccessResponse, } from "./parse"; | ||
export { isJsonRpcErrorResponse, isJsonRpcSuccessResponse, JsonRpcError, JsonRpcErrorResponse, JsonRpcId, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, jsonRpcCode, } from "./types"; | ||
export { parseJsonRpcErrorResponse, parseJsonRpcId, parseJsonRpcRequest, parseJsonRpcResponse, parseJsonRpcSuccessResponse, } from "./parse"; | ||
export { isJsonRpcErrorResponse, isJsonRpcSuccessResponse, jsonRpcCode, JsonRpcError, JsonRpcErrorResponse, JsonRpcId, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, } from "./types"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jsonRpcCode = exports.isJsonRpcSuccessResponse = exports.isJsonRpcErrorResponse = exports.parseJsonRpcSuccessResponse = exports.parseJsonRpcErrorResponse = exports.parseJsonRpcResponse = exports.parseJsonRpcRequest = exports.parseJsonRpcId = exports.JsonRpcClient = exports.makeJsonRpcId = void 0; | ||
exports.jsonRpcCode = exports.isJsonRpcSuccessResponse = exports.isJsonRpcErrorResponse = exports.parseJsonRpcSuccessResponse = exports.parseJsonRpcResponse = exports.parseJsonRpcRequest = exports.parseJsonRpcId = exports.parseJsonRpcErrorResponse = exports.JsonRpcClient = exports.makeJsonRpcId = void 0; | ||
var id_1 = require("./id"); | ||
@@ -9,6 +9,6 @@ Object.defineProperty(exports, "makeJsonRpcId", { enumerable: true, get: function () { return id_1.makeJsonRpcId; } }); | ||
var parse_1 = require("./parse"); | ||
Object.defineProperty(exports, "parseJsonRpcErrorResponse", { enumerable: true, get: function () { return parse_1.parseJsonRpcErrorResponse; } }); | ||
Object.defineProperty(exports, "parseJsonRpcId", { enumerable: true, get: function () { return parse_1.parseJsonRpcId; } }); | ||
Object.defineProperty(exports, "parseJsonRpcRequest", { enumerable: true, get: function () { return parse_1.parseJsonRpcRequest; } }); | ||
Object.defineProperty(exports, "parseJsonRpcResponse", { enumerable: true, get: function () { return parse_1.parseJsonRpcResponse; } }); | ||
Object.defineProperty(exports, "parseJsonRpcErrorResponse", { enumerable: true, get: function () { return parse_1.parseJsonRpcErrorResponse; } }); | ||
Object.defineProperty(exports, "parseJsonRpcSuccessResponse", { enumerable: true, get: function () { return parse_1.parseJsonRpcSuccessResponse; } }); | ||
@@ -15,0 +15,0 @@ var types_1 = require("./types"); |
@@ -18,6 +18,6 @@ "use strict"; | ||
const filteredStream = this.connection.responseStream.filter((r) => r.id === request.id); | ||
const pendingResponses = stream_1.firstEvent(filteredStream); | ||
const pendingResponses = (0, stream_1.firstEvent)(filteredStream); | ||
this.connection.sendRequest(request); | ||
const response = await pendingResponses; | ||
if (types_1.isJsonRpcErrorResponse(response)) { | ||
if ((0, types_1.isJsonRpcErrorResponse)(response)) { | ||
const error = response.error; | ||
@@ -24,0 +24,0 @@ throw new Error(`JSON RPC error: code=${error.code}; message='${error.message}'`); |
@@ -16,3 +16,3 @@ "use strict"; | ||
worker.onmessage = (event) => { | ||
listener.next(parse_1.parseJsonRpcResponse(event.data)); | ||
listener.next((0, parse_1.parseJsonRpcResponse)(event.data)); | ||
}; | ||
@@ -19,0 +19,0 @@ }, |
@@ -11,3 +11,3 @@ "use strict"; | ||
function parseJsonRpcId(data) { | ||
if (!compatibility_1.isJsonCompatibleDictionary(data)) { | ||
if (!(0, compatibility_1.isJsonCompatibleDictionary)(data)) { | ||
throw new Error("Data must be JSON compatible dictionary"); | ||
@@ -23,3 +23,3 @@ } | ||
function parseJsonRpcRequest(data) { | ||
if (!compatibility_1.isJsonCompatibleDictionary(data)) { | ||
if (!(0, compatibility_1.isJsonCompatibleDictionary)(data)) { | ||
throw new Error("Data must be JSON compatible dictionary"); | ||
@@ -38,3 +38,3 @@ } | ||
} | ||
if (!compatibility_1.isJsonCompatibleArray(data.params) && !compatibility_1.isJsonCompatibleDictionary(data.params)) { | ||
if (!(0, compatibility_1.isJsonCompatibleArray)(data.params) && !(0, compatibility_1.isJsonCompatibleDictionary)(data.params)) { | ||
throw new Error("Invalid params field"); | ||
@@ -61,3 +61,3 @@ } | ||
} | ||
else if (compatibility_1.isJsonCompatibleValue(error.data)) { | ||
else if ((0, compatibility_1.isJsonCompatibleValue)(error.data)) { | ||
maybeUndefinedData = error.data; | ||
@@ -68,7 +68,11 @@ } | ||
} | ||
return Object.assign({ code: error.code, message: error.message }, (maybeUndefinedData !== undefined ? { data: maybeUndefinedData } : {})); | ||
return { | ||
code: error.code, | ||
message: error.message, | ||
...(maybeUndefinedData !== undefined ? { data: maybeUndefinedData } : {}), | ||
}; | ||
} | ||
/** Throws if data is not a JsonRpcErrorResponse */ | ||
function parseJsonRpcErrorResponse(data) { | ||
if (!compatibility_1.isJsonCompatibleDictionary(data)) { | ||
if (!(0, compatibility_1.isJsonCompatibleDictionary)(data)) { | ||
throw new Error("Data must be JSON compatible dictionary"); | ||
@@ -83,3 +87,3 @@ } | ||
} | ||
if (typeof data.error === "undefined" || !compatibility_1.isJsonCompatibleDictionary(data.error)) { | ||
if (typeof data.error === "undefined" || !(0, compatibility_1.isJsonCompatibleDictionary)(data.error)) { | ||
throw new Error("Invalid error field"); | ||
@@ -96,3 +100,3 @@ } | ||
function parseJsonRpcSuccessResponse(data) { | ||
if (!compatibility_1.isJsonCompatibleDictionary(data)) { | ||
if (!(0, compatibility_1.isJsonCompatibleDictionary)(data)) { | ||
throw new Error("Data must be JSON compatible dictionary"); | ||
@@ -99,0 +103,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
}; | ||
expect(parse_1.parseJsonRpcId(request)).toEqual(123); | ||
expect((0, parse_1.parseJsonRpcId)(request)).toEqual(123); | ||
}); | ||
@@ -24,3 +24,3 @@ it("works for string IDs", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcId(request)).toEqual("329fg3b"); | ||
expect((0, parse_1.parseJsonRpcId)(request)).toEqual("329fg3b"); | ||
}); | ||
@@ -35,3 +35,3 @@ it("returns null for invaid IDs", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcId(request)).toBeNull(); | ||
expect((0, parse_1.parseJsonRpcId)(request)).toBeNull(); | ||
} | ||
@@ -46,3 +46,3 @@ // wrong type (object) | ||
}; | ||
expect(parse_1.parseJsonRpcId(request)).toBeNull(); | ||
expect((0, parse_1.parseJsonRpcId)(request)).toBeNull(); | ||
} | ||
@@ -57,3 +57,3 @@ // wrong type (Array) | ||
}; | ||
expect(parse_1.parseJsonRpcId(request)).toBeNull(); | ||
expect((0, parse_1.parseJsonRpcId)(request)).toBeNull(); | ||
} | ||
@@ -68,3 +68,3 @@ // wrong type (null) | ||
}; | ||
expect(parse_1.parseJsonRpcId(request)).toBeNull(); | ||
expect((0, parse_1.parseJsonRpcId)(request)).toBeNull(); | ||
} | ||
@@ -84,3 +84,3 @@ }); | ||
}; | ||
expect(parse_1.parseJsonRpcErrorResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcErrorResponse)(response)).toEqual(response); | ||
}); | ||
@@ -96,3 +96,3 @@ it("works for error with string ID", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcErrorResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcErrorResponse)(response)).toEqual(response); | ||
}); | ||
@@ -108,3 +108,3 @@ it("works for error with null ID", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcErrorResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcErrorResponse)(response)).toEqual(response); | ||
}); | ||
@@ -121,3 +121,3 @@ it("works for error with null data", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcErrorResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcErrorResponse)(response)).toEqual(response); | ||
}); | ||
@@ -133,14 +133,14 @@ it("works for error with unset data", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcErrorResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcErrorResponse)(response)).toEqual(response); | ||
}); | ||
it("throws for invalid type", () => { | ||
const expectedError = /data must be JSON compatible dictionary/i; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(undefined)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse(null)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse(false)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse("error")).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse(42)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse(() => true)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse({ foo: () => true })).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcErrorResponse({ foo: () => new Uint8Array([]) })).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(undefined)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(null)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(false)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)("error")).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(42)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(() => true)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)({ foo: () => true })).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)({ foo: () => new Uint8Array([]) })).toThrowError(expectedError); | ||
}); | ||
@@ -158,3 +158,3 @@ it("throws for invalid version", () => { | ||
}; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
} | ||
@@ -171,3 +171,3 @@ // wrong version | ||
}; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
} | ||
@@ -183,3 +183,3 @@ // unset | ||
}; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
} | ||
@@ -198,3 +198,3 @@ }); | ||
}; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(response)).toThrowError(/invalid id field/i); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(response)).toThrowError(/invalid id field/i); | ||
} | ||
@@ -210,3 +210,3 @@ // unset | ||
}; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(response)).toThrowError(/invalid id field/i); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(response)).toThrowError(/invalid id field/i); | ||
} | ||
@@ -220,3 +220,3 @@ }); | ||
}; | ||
expect(() => parse_1.parseJsonRpcErrorResponse(response)).toThrowError(/invalid error field/i); | ||
expect(() => (0, parse_1.parseJsonRpcErrorResponse)(response)).toThrowError(/invalid error field/i); | ||
}); | ||
@@ -233,3 +233,3 @@ }); | ||
}; | ||
expect(parse_1.parseJsonRpcSuccessResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcSuccessResponse)(response)).toEqual(response); | ||
}); | ||
@@ -242,3 +242,3 @@ it("works for response with null result", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcSuccessResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcSuccessResponse)(response)).toEqual(response); | ||
}); | ||
@@ -251,3 +251,3 @@ it("works for response with number ID", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcSuccessResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcSuccessResponse)(response)).toEqual(response); | ||
}); | ||
@@ -260,13 +260,13 @@ it("works for response with string ID", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcSuccessResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcSuccessResponse)(response)).toEqual(response); | ||
}); | ||
it("throws for invalid type", () => { | ||
const expectedError = /data must be JSON compatible dictionary/i; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(undefined)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(null)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(false)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcSuccessResponse("success")).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(42)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(() => true)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcSuccessResponse({ foo: () => true })).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(undefined)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(null)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(false)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)("success")).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(42)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(() => true)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)({ foo: () => true })).toThrowError(expectedError); | ||
}); | ||
@@ -281,3 +281,3 @@ it("throws for invalid version", () => { | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
} | ||
@@ -291,3 +291,3 @@ // wrong version | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
} | ||
@@ -300,3 +300,3 @@ // unset | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/got unexpected jsonrpc version/i); | ||
} | ||
@@ -312,3 +312,3 @@ }); | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/invalid id field/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/invalid id field/i); | ||
} | ||
@@ -322,3 +322,3 @@ // wrong type | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/invalid id field/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/invalid id field/i); | ||
} | ||
@@ -331,3 +331,3 @@ // unset | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/invalid id field/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/invalid id field/i); | ||
} | ||
@@ -344,3 +344,3 @@ }); | ||
}; | ||
expect(() => parse_1.parseJsonRpcSuccessResponse(response)).toThrowError(/invalid result field/i); | ||
expect(() => (0, parse_1.parseJsonRpcSuccessResponse)(response)).toThrowError(/invalid result field/i); | ||
}); | ||
@@ -355,3 +355,3 @@ }); | ||
}; | ||
expect(parse_1.parseJsonRpcResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcResponse)(response)).toEqual(response); | ||
}); | ||
@@ -368,3 +368,3 @@ it("works for error response", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcResponse(response)).toEqual(response); | ||
expect((0, parse_1.parseJsonRpcResponse)(response)).toEqual(response); | ||
}); | ||
@@ -381,3 +381,3 @@ it("favours error if response is error and success at the same time", () => { | ||
}; | ||
expect(parse_1.parseJsonRpcResponse(response)).toEqual({ | ||
expect((0, parse_1.parseJsonRpcResponse)(response)).toEqual({ | ||
jsonrpc: "2.0", | ||
@@ -393,10 +393,10 @@ id: 123, | ||
const expectedError = /data must be JSON compatible dictionary/i; | ||
expect(() => parse_1.parseJsonRpcResponse(undefined)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse(null)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse(false)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse("error")).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse(42)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse(() => true)).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse({ foo: () => true })).toThrowError(expectedError); | ||
expect(() => parse_1.parseJsonRpcResponse({ foo: () => new Uint8Array([]) })).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(undefined)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(null)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(false)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)("error")).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(42)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(() => true)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)({ foo: () => true })).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)({ foo: () => new Uint8Array([]) })).toThrowError(expectedError); | ||
}); | ||
@@ -412,3 +412,3 @@ it("throws for invalid version", () => { | ||
}; | ||
expect(() => parse_1.parseJsonRpcResponse(response)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(response)).toThrowError(expectedError); | ||
} | ||
@@ -422,3 +422,3 @@ // wrong version | ||
}; | ||
expect(() => parse_1.parseJsonRpcResponse(response)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(response)).toThrowError(expectedError); | ||
} | ||
@@ -431,3 +431,3 @@ // unset | ||
}; | ||
expect(() => parse_1.parseJsonRpcResponse(response)).toThrowError(expectedError); | ||
expect(() => (0, parse_1.parseJsonRpcResponse)(response)).toThrowError(expectedError); | ||
} | ||
@@ -434,0 +434,0 @@ }); |
@@ -11,6 +11,6 @@ "use strict"; | ||
try { | ||
request = parse_1.parseJsonRpcRequest(event.data); | ||
request = (0, parse_1.parseJsonRpcRequest)(event.data); | ||
} | ||
catch (error) { | ||
const requestId = parse_1.parseJsonRpcId(event.data); | ||
const requestId = (0, parse_1.parseJsonRpcId)(event.data); | ||
const errorResponse = { | ||
@@ -27,3 +27,3 @@ jsonrpc: "2.0", | ||
let paramsString; | ||
if (compatibility_1.isJsonCompatibleDictionary(request.params)) { | ||
if ((0, compatibility_1.isJsonCompatibleDictionary)(request.params)) { | ||
paramsString = JSON.stringify(request.params); | ||
@@ -30,0 +30,0 @@ } |
{ | ||
"name": "@cosmjs/json-rpc", | ||
"version": "0.26.6", | ||
"version": "0.26.8", | ||
"description": "Framework for implementing a JSON-RPC 2.0 API", | ||
@@ -33,3 +33,3 @@ "contributors": [ | ||
"format-text": "prettier --write \"./*.md\"", | ||
"test-node": "node --require esm jasmine-testrunner.js", | ||
"test-node": "yarn node jasmine-testrunner.js", | ||
"test-edge": "yarn pack-web && karma start --single-run --browsers Edge", | ||
@@ -46,3 +46,3 @@ "test-firefox": "yarn pack-web && karma start --single-run --browsers Firefox", | ||
"dependencies": { | ||
"@cosmjs/stream": "0.26.6", | ||
"@cosmjs/stream": "0.26.8", | ||
"xstream": "^11.14.0" | ||
@@ -57,4 +57,4 @@ }, | ||
"@types/karma-jasmine-html-reporter": "^1", | ||
"@typescript-eslint/eslint-plugin": "^4.28", | ||
"@typescript-eslint/parser": "^4.28", | ||
"@typescript-eslint/eslint-plugin": "^5.13.0", | ||
"@typescript-eslint/parser": "^5.13.0", | ||
"eslint": "^7.5", | ||
@@ -68,6 +68,5 @@ "eslint-config-prettier": "^8.3.0", | ||
"glob": "^7.1.6", | ||
"jasmine": "^3.8", | ||
"jasmine-core": "^3.7.1", | ||
"jasmine": "^3.99", | ||
"jasmine-spec-reporter": "^6", | ||
"karma": "^6.1.1", | ||
"karma": "^6.3.14", | ||
"karma-chrome-launcher": "^3.1.0", | ||
@@ -82,4 +81,4 @@ "karma-firefox-launcher": "^2.1.0", | ||
"ts-node": "^8", | ||
"typedoc": "^0.21", | ||
"typescript": "~4.3", | ||
"typedoc": "^0.22", | ||
"typescript": "~4.4", | ||
"webpack": "^5.32.0", | ||
@@ -86,0 +85,0 @@ "webpack-cli": "^4.6.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
76980
32
1039
+ Added@cosmjs/stream@0.26.8(transitive)
- Removed@cosmjs/stream@0.26.6(transitive)
Updated@cosmjs/stream@0.26.8