Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@open-rpc/schema-utils-js

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-rpc/schema-utils-js - npm Package Compare versions

Comparing version 1.6.1 to 1.6.2

23

build/src/generate-method-id.d.ts

@@ -1,9 +0,14 @@

import { types } from "@open-rpc/meta-schema";
import { MethodObject, ContentDescriptorObject } from "@open-rpc/meta-schema";
/**
* Provides an error interface for handling when we are unable to find a contentDescriptor in a methodObject
* when it is expected.
*
* @category Errors
*
*/
export declare class ContentDescriptorNotFoundInMethodError extends Error {
method: types.MethodObject;
contentDescriptor: types.ContentDescriptorObject;
export declare class ContentDescriptorNotFoundInMethodError implements Error {
method: MethodObject;
contentDescriptor: ContentDescriptorObject;
name: string;
message: string;
/**

@@ -13,3 +18,3 @@ * @param method OpenRPC Method which was used for the lookup

*/
constructor(method: types.MethodObject, contentDescriptor: types.ContentDescriptorObject);
constructor(method: MethodObject, contentDescriptor: ContentDescriptorObject);
}

@@ -48,4 +53,6 @@ /**

*
* @category GenerateID
*
*/
export declare function generateMethodParamId(method: types.MethodObject, contentDescriptor: types.ContentDescriptorObject): string;
export declare function generateMethodParamId(method: MethodObject, contentDescriptor: ContentDescriptorObject): string;
/**

@@ -81,3 +88,5 @@ * Create a unique identifier for a result within a given method.

*
* @category GenerateID
*
*/
export declare function generateMethodResultId(method: types.MethodObject, contentDescriptor: types.ContentDescriptorObject): string;
export declare function generateMethodResultId(method: MethodObject, contentDescriptor: ContentDescriptorObject): string;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });

@@ -20,5 +7,7 @@ var lodash_1 = require("lodash");

* when it is expected.
*
* @category Errors
*
*/
var ContentDescriptorNotFoundInMethodError = /** @class */ (function (_super) {
__extends(ContentDescriptorNotFoundInMethodError, _super);
var ContentDescriptorNotFoundInMethodError = /** @class */ (function () {
/**

@@ -29,15 +18,13 @@ * @param method OpenRPC Method which was used for the lookup

function ContentDescriptorNotFoundInMethodError(method, contentDescriptor) {
var _this =
/* istanbul ignore next */
_super.call(this, [
this.method = method;
this.contentDescriptor = contentDescriptor;
this.name = "OpenRPCDocumentDereferencingError";
this.message = [
"Content Descriptor not found in method.",
"Method: " + JSON.stringify(method, undefined, " "),
"ContentDescriptor: " + JSON.stringify(contentDescriptor, undefined, " "),
].join("\n")) /* istanbul ignore next */ || this;
_this.method = method;
_this.contentDescriptor = contentDescriptor;
return _this;
].join("\n");
}
return ContentDescriptorNotFoundInMethodError;
}(Error));
}());
exports.ContentDescriptorNotFoundInMethodError = ContentDescriptorNotFoundInMethodError;

@@ -76,2 +63,4 @@ /**

*
* @category GenerateID
*
*/

@@ -117,2 +106,4 @@ function generateMethodParamId(method, contentDescriptor) {

*
* @category GenerateID
*
*/

@@ -119,0 +110,0 @@ function generateMethodResultId(method, contentDescriptor) {

@@ -1,5 +0,5 @@

import { types } from "@open-rpc/meta-schema";
declare type TGetOpenRPCDocument = (schema: string) => Promise<types.OpenRPC>;
import { OpenRPC } from "@open-rpc/meta-schema";
declare type TGetOpenRPCDocument = (schema: string) => Promise<OpenRPC>;
declare const fetchUrlSchemaFile: TGetOpenRPCDocument;
declare const readSchemaFromFile: (schema: string) => Promise<any>;
declare const readSchemaFromFile: TGetOpenRPCDocument;
export { fetchUrlSchemaFile, readSchemaFromFile };

@@ -1,3 +0,3 @@

import { types } from "@open-rpc/meta-schema";
import ParameterValidationError from "./parameter-validation-error";
import MethodCallParameterValidationError from "./parameter-validation-error";
import { OpenRPC } from "@open-rpc/meta-schema";
/**

@@ -23,3 +23,3 @@ * A class to assist in validating method calls to an OpenRPC-based service. Generated Clients,

*/
constructor(document: types.OpenRPC);
constructor(document: OpenRPC);
/**

@@ -43,3 +43,3 @@ * Validates a particular method call against the OpenRPC definition for the method.

*/
validate(methodName: string, params: any[]): ParameterValidationError[];
validate(methodName: string, params: any[]): MethodCallParameterValidationError[];
}

@@ -7,2 +7,3 @@ "use strict";

var method_call_validator_1 = __importDefault(require("./method-call-validator"));
var parameter_validation_error_1 = __importDefault(require("./parameter-validation-error"));
var getExampleSchema = function () { return ({

@@ -49,4 +50,4 @@ info: { title: "123", version: "1" },

expect(result.length).toBe(1);
expect(result[0]).toBeInstanceOf(Error);
expect(result[0]).toBeInstanceOf(parameter_validation_error_1.default);
});
});
import { ErrorObject } from "ajv";
import { types } from "@open-rpc/meta-schema";
import { Schema } from "@open-rpc/meta-schema";
/**
* Provides an error interface for handling when a function call has invalid parameters.
*/
export default class MethodCallParameterValidationError extends Error {
export default class MethodCallParameterValidationError implements Error {
paramIndex: number;
expectedSchema: types.Schema;
expectedSchema: Schema;
receievedParam: any;
private errors;
name: string;
message: string;
/**

@@ -18,3 +20,3 @@ * @param paramIndex The index of the param that for this error (index

*/
constructor(paramIndex: number, expectedSchema: types.Schema, receievedParam: any, errors: ErrorObject[]);
constructor(paramIndex: number, expectedSchema: Schema, receievedParam: any, errors: ErrorObject[]);
}
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });

@@ -19,4 +6,3 @@ /**

*/
var MethodCallParameterValidationError = /** @class */ (function (_super) {
__extends(MethodCallParameterValidationError, _super);
var MethodCallParameterValidationError = /** @class */ (function () {
/**

@@ -30,3 +16,8 @@ * @param paramIndex The index of the param that for this error (index

function MethodCallParameterValidationError(paramIndex, expectedSchema, receievedParam, errors) {
var _this = _super.call(this, [
this.paramIndex = paramIndex;
this.expectedSchema = expectedSchema;
this.receievedParam = receievedParam;
this.errors = errors;
this.name = "OpenRPCDocumentDereferencingError";
this.message = [
"Expected param in position ",

@@ -39,11 +30,6 @@ paramIndex,

".",
].join("")) /* istanbul ignore next */ || this;
_this.paramIndex = paramIndex;
_this.expectedSchema = expectedSchema;
_this.receievedParam = receievedParam;
_this.errors = errors;
return _this;
].join("");
}
return MethodCallParameterValidationError;
}(Error));
}());
exports.default = MethodCallParameterValidationError;

@@ -7,2 +7,3 @@ "use strict";

var parameter_validation_error_1 = __importDefault(require("./parameter-validation-error"));
var parameter_validation_error_2 = __importDefault(require("./parameter-validation-error"));
describe("ParameterValidationError", function () {

@@ -17,4 +18,4 @@ var errorObj = {

var error = new parameter_validation_error_1.default(1, { type: "number" }, "hey mom", [errorObj]);
expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(parameter_validation_error_2.default);
});
});

@@ -1,6 +0,11 @@

import { types } from "@open-rpc/meta-schema";
import { OpenRPC } from "@open-rpc/meta-schema";
/**
* Provides an error interface for OpenRPC Document dereferencing problems
*
* @category Errors
*
*/
export declare class OpenRPCDocumentDereferencingError extends Error {
export declare class OpenRPCDocumentDereferencingError implements Error {
name: string;
message: string;
/**

@@ -31,9 +36,9 @@ * @param e The error that originated from jsonSchemaRefParser

*
* const { types } from "@open-rpc/meta-schema"
* const { OpenRPC } from "@open-rpc/meta-schema"
* const { parseOpenRPCDocument } from "@open-rpc/schema-utils-js";
*
* try {
* const fromUrl = await parseOpenRPCDocument("example.com/openrpc.json") as types.OpenRPC;
* const fromFile = await parseOpenRPCDocument("example.com/openrpc.json") as types.OpenRPC;
* const fromString = await parseOpenRPCDocument('{ "openrpc": "1.0.0", ... }') as types.OpenRPC;
* const fromUrl = await parseOpenRPCDocument("example.com/openrpc.json") as OpenRPC;
* const fromFile = await parseOpenRPCDocument("example.com/openrpc.json") as OpenRPC;
* const fromString = await parseOpenRPCDocument('{ "openrpc": "1.0.0", ... }') as OpenRPC;
* const fromCwd = await parseOpenRPCDocument() as types.OpenRPC; // default

@@ -46,2 +51,2 @@ * } catch (e) {

*/
export default function parseOpenRPCDocument(schema?: string | types.OpenRPC): Promise<types.OpenRPC>;
export default function parseOpenRPCDocument(schema?: string | OpenRPC): Promise<OpenRPC>;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -77,5 +64,7 @@ return new (P || (P = Promise))(function (resolve, reject) {

* Provides an error interface for OpenRPC Document dereferencing problems
*
* @category Errors
*
*/
var OpenRPCDocumentDereferencingError = /** @class */ (function (_super) {
__extends(OpenRPCDocumentDereferencingError, _super);
var OpenRPCDocumentDereferencingError = /** @class */ (function () {
/**

@@ -85,7 +74,7 @@ * @param e The error that originated from jsonSchemaRefParser

function OpenRPCDocumentDereferencingError(e) {
/* istanbul ignore next */
return _super.call(this, "The json schema provided cannot be dereferenced. Received Error: \n " + e.message) || this;
this.name = "OpenRPCDocumentDereferencingError";
this.message = "The json schema provided cannot be dereferenced. Received Error: \n " + e.message;
}
return OpenRPCDocumentDereferencingError;
}(Error));
}());
exports.OpenRPCDocumentDereferencingError = OpenRPCDocumentDereferencingError;

@@ -112,9 +101,9 @@ /**

*
* const { types } from "@open-rpc/meta-schema"
* const { OpenRPC } from "@open-rpc/meta-schema"
* const { parseOpenRPCDocument } from "@open-rpc/schema-utils-js";
*
* try {
* const fromUrl = await parseOpenRPCDocument("example.com/openrpc.json") as types.OpenRPC;
* const fromFile = await parseOpenRPCDocument("example.com/openrpc.json") as types.OpenRPC;
* const fromString = await parseOpenRPCDocument('{ "openrpc": "1.0.0", ... }') as types.OpenRPC;
* const fromUrl = await parseOpenRPCDocument("example.com/openrpc.json") as OpenRPC;
* const fromFile = await parseOpenRPCDocument("example.com/openrpc.json") as OpenRPC;
* const fromString = await parseOpenRPCDocument('{ "openrpc": "1.0.0", ... }') as OpenRPC;
* const fromCwd = await parseOpenRPCDocument() as types.OpenRPC; // default

@@ -121,0 +110,0 @@ * } catch (e) {

@@ -55,5 +55,2 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _this = this;

@@ -66,3 +63,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

var _fs = __importStar(require("fs-extra"));
var parse_open_rpc_document_1 = __importDefault(require("./parse-open-rpc-document"));
var parse_open_rpc_document_1 = __importStar(require("./parse-open-rpc-document"));
var validate_open_rpc_document_1 = require("./validate-open-rpc-document");
var fs = _fs;

@@ -172,4 +170,3 @@ var workingSchema = {

expect.assertions(1);
fs.readJson.mockClear();
fs.readJson.mockResolvedValue(__assign({}, workingSchema, { methods: [
var testDocument = __assign({}, workingSchema, { methods: [
{

@@ -188,11 +185,10 @@ name: "foo",

},
] }));
return expect(parse_open_rpc_document_1.default())
] });
return expect(parse_open_rpc_document_1.default(testDocument))
.rejects
.toThrow("The json schema provided cannot be dereferenced");
.toBeInstanceOf(parse_open_rpc_document_1.OpenRPCDocumentDereferencingError);
});
it("rejects when the schema is invalid", function () {
expect.assertions(1);
fs.readJson.mockClear();
fs.readJson.mockResolvedValue(__assign({}, workingSchema, { methods: [
var testDocument = __assign({}, workingSchema, { methods: [
{

@@ -212,6 +208,6 @@ name: "foo",

},
] }));
return expect(parse_open_rpc_document_1.default())
] });
return expect(parse_open_rpc_document_1.default(testDocument))
.rejects
.toThrow(/Error validating OpenRPC Document against @open-rpc\/meta-schema./);
.toBeInstanceOf(validate_open_rpc_document_1.OpenRPCDocumentValidationError);
});

@@ -218,0 +214,0 @@ it("rejects when the json provided is invalid from file", function () {

@@ -1,12 +0,17 @@

import { types } from "@open-rpc/meta-schema";
import Ajv from "ajv";
import { OpenRPC } from "@open-rpc/meta-schema";
import { ErrorObject } from "ajv";
/**
* Provides an error interface for OpenRPC Document validation
*
* @category Errors
*
*/
export declare class OpenRPCDocumentValidationError extends Error {
export declare class OpenRPCDocumentValidationError implements Error {
private errors;
name: string;
message: string;
/**
* @param errors The errors received by ajv.errors.
*/
constructor(errors: Ajv.ErrorObject[]);
constructor(errors: ErrorObject[]);
}

@@ -33,2 +38,2 @@ /**

*/
export default function validateOpenRPCDocument(document: types.OpenRPC): OpenRPCDocumentValidationError | true;
export default function validateOpenRPCDocument(document: OpenRPC): OpenRPCDocumentValidationError | true;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -29,5 +16,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

* Provides an error interface for OpenRPC Document validation
*
* @category Errors
*
*/
var OpenRPCDocumentValidationError = /** @class */ (function (_super) {
__extends(OpenRPCDocumentValidationError, _super);
var OpenRPCDocumentValidationError = /** @class */ (function () {
/**

@@ -37,12 +26,12 @@ * @param errors The errors received by ajv.errors.

function OpenRPCDocumentValidationError(errors) {
var _this = _super.call(this, [
this.errors = errors;
this.name = "OpenRPCDocumentDereferencingError";
this.message = [
"Error validating OpenRPC Document against @open-rpc/meta-schema.",
"The errors found are as follows:",
JSON.stringify(errors, undefined, " "),
].join("\n")) /* istanbul ignore next */ || this;
_this.errors = errors;
return _this;
].join("\n");
}
return OpenRPCDocumentValidationError;
}(Error));
}());
exports.OpenRPCDocumentValidationError = OpenRPCDocumentValidationError;

@@ -49,0 +38,0 @@ /**

@@ -0,1 +1,13 @@

## [1.6.2](https://github.com/open-rpc/schema-utils-js/compare/1.6.1...1.6.2) (2019-04-12)
### Bug Fixes
* constrain typing more ([af5ce00](https://github.com/open-rpc/schema-utils-js/commit/af5ce00))
* general improvements ([3641370](https://github.com/open-rpc/schema-utils-js/commit/3641370))
* readme formatting ([58dcc9a](https://github.com/open-rpc/schema-utils-js/commit/58dcc9a))
* tests passing again ([4157813](https://github.com/open-rpc/schema-utils-js/commit/4157813))
* update badges ([445262d](https://github.com/open-rpc/schema-utils-js/commit/445262d))
* update to new meta-schema ([7ae6f8d](https://github.com/open-rpc/schema-utils-js/commit/7ae6f8d))
## [1.6.1](https://github.com/open-rpc/schema-utils-js/compare/1.6.0...1.6.1) (2019-04-12)

@@ -2,0 +14,0 @@

{
"name": "@open-rpc/schema-utils-js",
"private": false,
"version": "1.6.1",
"version": "1.6.2",
"description": "",

@@ -31,3 +31,3 @@ "main": "build/src/index.js",

"dependencies": {
"@open-rpc/meta-schema": "^1.2.2",
"@open-rpc/meta-schema": "^1.3.1",
"ajv": "^6.10.0",

@@ -34,0 +34,0 @@ "fs-extra": "^7.0.1",

# OpenRPC Utils For Javascript
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=open-rpc/schema-utils-js)](https://dependabot.com)
[![codecov](https://codecov.io/gh/open-rpc/schema-utils-js/branch/master/graph/badge.svg)](https://codecov.io/gh/open-rpc/schema-utils-js)
<center>
<span>
<img alt="CircleCI branch" src="https://img.shields.io/circleci/project/github/open-rpc/schema-utils-js/master.svg">
<img src="https://codecov.io/gh/open-rpc/schema-utils-js/branch/master/graph/badge.svg" />
<img alt="Dependabot status" src="https://api.dependabot.com/badges/status?host=github&repo=open-rpc/schema-utils-js" />
<img alt="Chat on Discord" src="https://img.shields.io/badge/chat-on%20discord-7289da.svg" />
<img alt="npm" src="https://img.shields.io/npm/dt/@open-rpc/schema-utils-js.svg" />
<img alt="GitHub release" src="https://img.shields.io/github/release/open-rpc/schema-utils-js.svg" />
<img alt="GitHub commits since latest release" src="https://img.shields.io/github/commits-since/open-rpc/schema-utils-js/latest.svg" />
</span>
</center>
### Contributing
How to contribute, build and release are outlined in [CONTRIBUTING.md](CONTRIBUTING.md), [BUILDING.md](BUILDING.md) and [RELEASING.md](RELEASING.md) respectively. Commits in this repository follow the [CONVENTIONAL_COMMITS.md](CONVENTIONAL_COMMITS.md) specification.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc