Change assert.doesConformToShema interface
This commit is contained in:
@@ -22,9 +22,6 @@ import { decorators } from './utils/decorators';
|
|||||||
import { signatureUtils } from './utils/signature_utils';
|
import { signatureUtils } from './utils/signature_utils';
|
||||||
import { utils } from './utils/utils';
|
import { utils } from './utils/utils';
|
||||||
|
|
||||||
assert.schemaValidator.addSchema(zeroExPrivateNetworkConfigSchema);
|
|
||||||
assert.schemaValidator.addSchema(zeroExPublicNetworkConfigSchema);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ZeroEx class is the single entry-point into the 0x.js library. It contains all of the library's functionality
|
* The ZeroEx class is the single entry-point into the 0x.js library. It contains all of the library's functionality
|
||||||
* and all calls to the library should be made through a ZeroEx instance.
|
* and all calls to the library should be made through a ZeroEx instance.
|
||||||
@@ -168,7 +165,10 @@ export class ZeroEx {
|
|||||||
*/
|
*/
|
||||||
constructor(provider: Web3Provider, config: ZeroExConfig) {
|
constructor(provider: Web3Provider, config: ZeroExConfig) {
|
||||||
assert.isWeb3Provider('provider', provider);
|
assert.isWeb3Provider('provider', provider);
|
||||||
assert.doesConformToSchema('config', config, zeroExConfigSchema);
|
assert.doesConformToSchema('config', config, zeroExConfigSchema, [
|
||||||
|
zeroExPrivateNetworkConfigSchema,
|
||||||
|
zeroExPublicNetworkConfigSchema,
|
||||||
|
]);
|
||||||
const artifactJSONs = _.values(artifacts);
|
const artifactJSONs = _.values(artifacts);
|
||||||
const abiArrays = _.map(artifactJSONs, artifact => artifact.abi);
|
const abiArrays = _.map(artifactJSONs, artifact => artifact.abi);
|
||||||
this._abiDecoder = new AbiDecoder(abiArrays);
|
this._abiDecoder = new AbiDecoder(abiArrays);
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import * as _ from 'lodash';
|
|||||||
import * as validUrl from 'valid-url';
|
import * as validUrl from 'valid-url';
|
||||||
|
|
||||||
const HEX_REGEX = /^0x[0-9A-F]*$/i;
|
const HEX_REGEX = /^0x[0-9A-F]*$/i;
|
||||||
const schemaValidator = new SchemaValidator();
|
|
||||||
|
|
||||||
export const assert = {
|
export const assert = {
|
||||||
schemaValidator,
|
|
||||||
isBigNumber(variableName: string, value: BigNumber): void {
|
isBigNumber(variableName: string, value: BigNumber): void {
|
||||||
const isBigNumber = _.isObject(value) && (value as any).isBigNumber;
|
const isBigNumber = _.isObject(value) && (value as any).isBigNumber;
|
||||||
this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
|
this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
|
||||||
@@ -68,8 +66,10 @@ export const assert = {
|
|||||||
const isWeb3Provider = _.isFunction(value.send) || _.isFunction(value.sendAsync);
|
const isWeb3Provider = _.isFunction(value.send) || _.isFunction(value.sendAsync);
|
||||||
this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value));
|
this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value));
|
||||||
},
|
},
|
||||||
doesConformToSchema(variableName: string, value: any, schema: Schema): void {
|
doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void {
|
||||||
const validationResult = this.schemaValidator.validate(value, schema);
|
const schemaValidator = new SchemaValidator();
|
||||||
|
_.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator));
|
||||||
|
const validationResult = schemaValidator.validate(value, schema);
|
||||||
const hasValidationErrors = validationResult.errors.length > 0;
|
const hasValidationErrors = validationResult.errors.length > 0;
|
||||||
const msg = `Expected ${variableName} to conform to schema ${schema.id}
|
const msg = `Expected ${variableName} to conform to schema ${schema.id}
|
||||||
Encountered: ${JSON.stringify(value, null, '\t')}
|
Encountered: ${JSON.stringify(value, null, '\t')}
|
||||||
|
|||||||
Reference in New Issue
Block a user