@open-rpc/schema-utils-js
Advanced tools
Comparing version 2.0.0 to 2.0.1
import { OpenrpcDocument as OpenRPC } from "@open-rpc/meta-schema"; | ||
import referenceResolver from "@json-schema-tools/reference-resolver"; | ||
export declare type ReferenceResolver = typeof referenceResolver; | ||
export type ReferenceResolver = typeof referenceResolver; | ||
/** | ||
@@ -5,0 +5,0 @@ * Provides an error interface for OpenRPC Document dereferencing problems |
@@ -28,3 +28,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -69,3 +69,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
this.name = "OpenRPCDocumentDereferencingError"; | ||
this.message = "The json schema provided cannot be dereferenced. Received Error: \n " + e; | ||
this.message = "The json schema provided cannot be dereferenced. Received Error: \n ".concat(e); | ||
} | ||
@@ -95,7 +95,7 @@ return OpenRPCDocumentDereferencingError; | ||
"unable to eval pointer against OpenRPC Document.", | ||
"error type: " + err_1.name, | ||
"instance: " + err_1.instance, | ||
"token: " + err_1.token, | ||
"pointer: " + $ref, | ||
"reference object: " + fast_safe_stringify_1.default(item) | ||
"error type: ".concat(err_1.name), | ||
"instance: ".concat(err_1.instance), | ||
"token: ".concat(err_1.token), | ||
"pointer: ".concat($ref), | ||
"reference object: ".concat((0, fast_safe_stringify_1.default)(item)) | ||
].join("\n")); | ||
@@ -155,5 +155,5 @@ case 4: return [2 /*return*/]; | ||
"Unable to parse reference inside of JSONSchema", | ||
s.title ? "Schema Title: " + s.title : "", | ||
"error message: " + e_1.message, | ||
"schema in question: " + fast_safe_stringify_1.default(s) | ||
s.title ? "Schema Title: ".concat(s.title) : "", | ||
"error message: ".concat(e_1.message), | ||
"schema in question: ".concat((0, fast_safe_stringify_1.default)(s)) | ||
].join("\n")); | ||
@@ -160,0 +160,0 @@ case 4: return [2 /*return*/]; |
@@ -23,4 +23,4 @@ "use strict"; | ||
"Content Descriptor not found in method.", | ||
"Method: " + JSON.stringify(method, undefined, " "), | ||
"ContentDescriptor: " + JSON.stringify(contentDescriptor, undefined, " "), | ||
"Method: ".concat(JSON.stringify(method, undefined, " ")), | ||
"ContentDescriptor: ".concat(JSON.stringify(contentDescriptor, undefined, " ")), | ||
].join("\n"); | ||
@@ -67,3 +67,3 @@ } | ||
function generateMethodParamId(method, contentDescriptor) { | ||
var pos = helper_functions_1.findIndex(method.params, function (o) { return o.name == contentDescriptor.name; }); | ||
var pos = (0, helper_functions_1.findIndex)(method.params, function (o) { return o.name == contentDescriptor.name; }); | ||
if (pos === -1) { | ||
@@ -82,5 +82,5 @@ throw new ContentDescriptorNotFoundInMethodError(method, contentDescriptor); | ||
var paramCD = method.params[pos]; | ||
paramId = paramCD.name + "/" + pos.toString(); | ||
paramId = "".concat(paramCD.name, "/").concat(pos.toString()); | ||
} | ||
return method.name + "/" + paramId; | ||
return "".concat(method.name, "/").concat(paramId); | ||
} | ||
@@ -126,4 +126,4 @@ exports.generateMethodParamId = generateMethodParamId; | ||
} | ||
return method.name + "/result"; | ||
return "".concat(method.name, "/result"); | ||
} | ||
exports.generateMethodResultId = generateMethodResultId; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -47,3 +47,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, fs_extra_1.readJson(filePath)]; | ||
return [4 /*yield*/, (0, fs_extra_1.readJson)(filePath)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -53,6 +53,6 @@ case 2: | ||
if (e_1.message.includes("SyntaxError")) { | ||
throw new Error("Failed to parse json in file " + filePath); | ||
throw new Error("Failed to parse json in file ".concat(filePath)); | ||
} | ||
else { | ||
throw new Error("Unable to read openrpc.json file located at " + filePath); | ||
throw new Error("Unable to read openrpc.json file located at ".concat(filePath)); | ||
} | ||
@@ -59,0 +59,0 @@ return [3 /*break*/, 3]; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -50,3 +50,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
_a.trys.push([0, 3, , 4]); | ||
return [4 /*yield*/, isomorphic_fetch_1.default(schema)]; | ||
return [4 /*yield*/, (0, isomorphic_fetch_1.default)(schema)]; | ||
case 1: | ||
@@ -58,3 +58,3 @@ response = _a.sent(); | ||
e_1 = _a.sent(); | ||
throw new Error("Unable to download openrpc.json file located at the url: " + schema); | ||
throw new Error("Unable to download openrpc.json file located at the url: ".concat(schema)); | ||
case 4: return [2 /*return*/]; | ||
@@ -61,0 +61,0 @@ } |
import { OpenrpcDocument as OpenRPC } from "@open-rpc/meta-schema"; | ||
export declare type TGetOpenRPCDocument = (schema: string) => Promise<OpenRPC>; | ||
export type TGetOpenRPCDocument = (schema: string) => Promise<OpenRPC>; |
@@ -1,2 +0,2 @@ | ||
declare type TPredicate = (value: any) => boolean; | ||
type TPredicate = (value: any) => boolean; | ||
/** | ||
@@ -3,0 +3,0 @@ * finds array index of array object which matches predicate |
@@ -10,3 +10,3 @@ "use strict"; | ||
*/ | ||
exports.findIndex = function (array, predicate) { | ||
var findIndex = function (array, predicate) { | ||
var length = array == null ? 0 : array.length; | ||
@@ -24,2 +24,3 @@ if (!length) { | ||
}; | ||
exports.findIndex = findIndex; | ||
/** | ||
@@ -30,3 +31,3 @@ * Removes false and null values from array | ||
*/ | ||
exports.compact = function (array) { | ||
var compact = function (array) { | ||
var index = 0; | ||
@@ -42,2 +43,3 @@ var result = []; | ||
}; | ||
exports.compact = compact; | ||
/** | ||
@@ -49,3 +51,3 @@ * finds an array elements which matches the predicate | ||
*/ | ||
exports.find = function (array, predicate) { | ||
var find = function (array, predicate) { | ||
var length = array == null ? 0 : array.length; | ||
@@ -63,2 +65,3 @@ if (!length) { | ||
}; | ||
exports.find = find; | ||
/** | ||
@@ -71,3 +74,3 @@ * compares OpenrpcDocuments | ||
*/ | ||
exports.rpcDocIsEqual = function (doc1, doc2) { | ||
var rpcDocIsEqual = function (doc1, doc2) { | ||
var doc1Keys = Object.keys(doc1); | ||
@@ -88,3 +91,3 @@ var doc2Keys = Object.keys(doc2); | ||
else if (typeof doc1[key] === 'object' && typeof doc2[key] === 'object') { | ||
if (!exports.rpcDocIsEqual(doc1[key], doc2[key])) { | ||
if (!(0, exports.rpcDocIsEqual)(doc1[key], doc2[key])) { | ||
return false; | ||
@@ -99,1 +102,2 @@ } | ||
}; | ||
exports.rpcDocIsEqual = rpcDocIsEqual; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -41,5 +45,5 @@ return result; | ||
var noop = function (schema) { | ||
return Promise.reject("Not Implemented, passed: " + schema); | ||
return Promise.reject("Not Implemented, passed: ".concat(schema)); | ||
}; | ||
var parseOpenRPCDocument = parse_open_rpc_document_1.default(get_open_rpc_document_from_url_1.default, noop); | ||
var parseOpenRPCDocument = (0, parse_open_rpc_document_1.default)(get_open_rpc_document_from_url_1.default, noop); | ||
exports.parseOpenRPCDocument = parseOpenRPCDocument; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -44,3 +48,3 @@ return result; | ||
var get_open_rpc_document_from_url_1 = __importDefault(require("./get-open-rpc-document-from-url")); | ||
var parseOpenRPCDocument = parse_open_rpc_document_1.default(get_open_rpc_document_from_url_1.default, get_open_rpc_document_from_file_1.default); | ||
var parseOpenRPCDocument = (0, parse_open_rpc_document_1.default)(get_open_rpc_document_from_url_1.default, get_open_rpc_document_from_file_1.default); | ||
exports.parseOpenRPCDocument = parseOpenRPCDocument; |
@@ -45,3 +45,3 @@ "use strict"; | ||
} | ||
_this.ajvValidator.addSchema(param.schema, generate_method_id_1.generateMethodParamId(method, param)); | ||
_this.ajvValidator.addSchema(param.schema, (0, generate_method_id_1.generateMethodParamId)(method, param)); | ||
}); | ||
@@ -74,3 +74,3 @@ }); | ||
} | ||
var method = helper_functions_1.find(this.document.methods, function (o) { return o.name == methodName; }); | ||
var method = (0, helper_functions_1.find)(this.document.methods, function (o) { return o.name == methodName; }); | ||
if (!method) { | ||
@@ -80,3 +80,3 @@ return new method_not_found_error_1.default(methodName, this.document, params); | ||
var paramMap = method.params; | ||
return helper_functions_1.compact(paramMap.map(function (param, index) { | ||
return (0, helper_functions_1.compact)(paramMap.map(function (param, index) { | ||
var id; | ||
@@ -102,3 +102,3 @@ if (method.paramStructure === "by-position") { | ||
if (param.schema !== undefined) { | ||
var idForMethod = generate_method_id_1.generateMethodParamId(method, param); | ||
var idForMethod = (0, generate_method_id_1.generateMethodParamId)(method, param); | ||
var isValid = _this.ajvValidator.validate(idForMethod, input); | ||
@@ -105,0 +105,0 @@ var errors = _this.ajvValidator.errors; |
@@ -19,10 +19,10 @@ "use strict"; | ||
var msg = [ | ||
"Method Not Found Error for OpenRPC API named \"" + openrpcDocument.info.title + "\"", | ||
"The requested method: \"" + methodName + "\" not a valid method.", | ||
"Method Not Found Error for OpenRPC API named \"".concat(openrpcDocument.info.title, "\""), | ||
"The requested method: \"".concat(methodName, "\" not a valid method."), | ||
]; | ||
if (openrpcDocument.methods.length > 0) { | ||
msg.push("Valid method names are as follows: " + openrpcDocument.methods.map(function (_a) { | ||
msg.push("Valid method names are as follows: ".concat(openrpcDocument.methods.map(function (_a) { | ||
var name = _a.name; | ||
return name; | ||
}).join(", ")); | ||
}).join(", "))); | ||
} | ||
@@ -29,0 +29,0 @@ var stringedParams; |
@@ -16,4 +16,4 @@ "use strict"; | ||
var msg = [ | ||
"Method Ref Unexpected Error for OpenRPC API named \"" + openrpcDocument.info.title + "\"", | ||
"The requested ref has not been resolved: \"" + methodRef + "\" not a valid dereferenced method.", | ||
"Method Ref Unexpected Error for OpenRPC API named \"".concat(openrpcDocument.info.title, "\""), | ||
"The requested ref has not been resolved: \"".concat(methodRef, "\" not a valid dereferenced method."), | ||
]; | ||
@@ -20,0 +20,0 @@ this.message = msg.join("\n"); |
@@ -20,3 +20,3 @@ "use strict"; | ||
this.message = [ | ||
"Expected param at " + (typeof paramIndex === "string" ? "key" : "position") + ": ", | ||
"Expected param at ".concat(typeof paramIndex === "string" ? "key" : "position", ": "), | ||
paramIndex, | ||
@@ -23,0 +23,0 @@ " to match the json schema: ", |
@@ -15,3 +15,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -29,3 +33,3 @@ if (k2 === undefined) k2 = k; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -49,3 +53,3 @@ return result; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -162,3 +166,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
if (parseOptions.validate) { | ||
isValid = validate_open_rpc_document_1.default(parsedSchema); | ||
isValid = (0, validate_open_rpc_document_1.default)(parsedSchema); | ||
if (isValid instanceof validate_open_rpc_document_1.OpenRPCDocumentValidationError) { | ||
@@ -171,7 +175,7 @@ throw isValid; | ||
if (!(parseOptions.resolver !== undefined)) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, dereference_document_1.default(parsedSchema, parseOptions.resolver)]; | ||
return [4 /*yield*/, (0, dereference_document_1.default)(parsedSchema, parseOptions.resolver)]; | ||
case 7: | ||
postDeref = _a.sent(); | ||
return [3 /*break*/, 10]; | ||
case 8: return [4 /*yield*/, dereference_document_1.default(parsedSchema, reference_resolver_1.default)]; | ||
case 8: return [4 /*yield*/, (0, dereference_document_1.default)(parsedSchema, reference_resolver_1.default)]; | ||
case 9: | ||
@@ -182,3 +186,3 @@ postDeref = _a.sent(); | ||
if (parseOptions.validate) { | ||
isValid = validate_open_rpc_document_1.default(postDeref); | ||
isValid = (0, validate_open_rpc_document_1.default)(postDeref); | ||
if (isValid instanceof validate_open_rpc_document_1.OpenRPCDocumentValidationError) { | ||
@@ -185,0 +189,0 @@ throw isValid; |
@@ -20,2 +20,3 @@ "use strict"; | ||
var ajv_1 = __importDefault(require("ajv")); | ||
var meta_schema_2 = __importDefault(require("@json-schema-tools/meta-schema")); | ||
/** | ||
@@ -67,2 +68,3 @@ * @ignore | ||
var ajv = new ajv_1.default(); | ||
ajv.addSchema(meta_schema_2.default, "https://meta.json-schema.tools"); | ||
var metaSchemaCopy = __assign({}, meta_schema_1.default); | ||
@@ -73,3 +75,14 @@ delete metaSchemaCopy.definitions.JSONSchema.$id; | ||
delete metaSchemaCopy.$id; | ||
ajv.validate(metaSchemaCopy, document); | ||
try { | ||
ajv.validate(metaSchemaCopy, document); | ||
} | ||
catch (e) { | ||
throw new Error([ | ||
'schema-utils-js: Internal Error', | ||
'-----', | ||
e, | ||
'-----', | ||
'If you see this report it: https://github.com/open-rpc/schema-utils-js/issues', | ||
].join('\n')); | ||
} | ||
if (ajv.errors) { | ||
@@ -76,0 +89,0 @@ return new OpenRPCDocumentValidationError(ajv.errors); |
{ | ||
"name": "@open-rpc/schema-utils-js", | ||
"private": false, | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "", | ||
@@ -33,6 +33,6 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@json-schema-tools/dereferencer": "1.6.2", | ||
"@json-schema-tools/meta-schema": "1.7.5", | ||
"@json-schema-tools/reference-resolver": "1.2.5", | ||
"@open-rpc/meta-schema": "1.14.2", | ||
"@json-schema-tools/dereferencer": "^1.6.3", | ||
"@json-schema-tools/meta-schema": "^1.7.5", | ||
"@json-schema-tools/reference-resolver": "^1.2.6", | ||
"@open-rpc/meta-schema": "^1.14.9", | ||
"ajv": "^6.10.0", | ||
@@ -50,3 +50,3 @@ "detect-node": "^2.0.4", | ||
"@types/isomorphic-fetch": "0.0.36", | ||
"@types/jest": "^26.0.5", | ||
"@types/jest": "^29.5.12", | ||
"@types/json-schema": "^7.0.3", | ||
@@ -59,8 +59,8 @@ "@types/node-fetch": "^2.1.6", | ||
"eslint": "^7.17.0", | ||
"jest": "^25.1.0", | ||
"jest": "^29.7.0", | ||
"json-schema": "^0.4.0", | ||
"rimraf": "^3.0.0", | ||
"ts-jest": "^25.0.0", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^3.3.3333", | ||
"ts-jest": "^29.1.2", | ||
"typedoc": "^0.25.13", | ||
"typescript": "^4.9.5", | ||
"webpack": "^5.1.3", | ||
@@ -67,0 +67,0 @@ "webpack-cli": "^5.1.4" |
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
87698
1673
+ Added@json-schema-tools/dereferencer@1.6.3(transitive)
+ Added@json-schema-tools/reference-resolver@1.2.6(transitive)
+ Added@open-rpc/meta-schema@1.14.9(transitive)
- Removed@json-schema-tools/dereferencer@1.6.2(transitive)
- Removed@json-schema-tools/reference-resolver@1.2.5(transitive)
- Removed@open-rpc/meta-schema@1.14.2(transitive)