diff options
Diffstat (limited to 'packages/json-schemas')
28 files changed, 265 insertions, 354 deletions
diff --git a/packages/json-schemas/CHANGELOG.md b/packages/json-schemas/CHANGELOG.md index 9f080adeb..28f38acc5 100644 --- a/packages/json-schemas/CHANGELOG.md +++ b/packages/json-schemas/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG -v0.6.7 - _Nov. 14, 2017_ ------------------------- +## v0.7.0 - _December 20, 2017_ + + * Rename `subscriptionOptsSchema` to `blockRangeSchema` (#272) + +## v0.6.7 - _November 14, 2017_ + * Re-publish JSON-schema previously published under NPM package 0x-json-schemas diff --git a/packages/json-schemas/README.md b/packages/json-schemas/README.md index d89f57a5e..9166f50c1 100644 --- a/packages/json-schemas/README.md +++ b/packages/json-schemas/README.md @@ -1,16 +1,16 @@ -json-schemas ------------- +## @0xproject/json-schemas Contains 0x-related json schemas -## Install: +## Installation ```bash -npm install @0xproject/json-schemas --save +yarn add @0xproject/json-schemas ``` -## Usage: -``` +## Usage + +```javascript import {SchemaValidator, ValidatorResult, schemas} from '@0xproject/json-schemas'; const {orderSchema} = schemas; @@ -22,3 +22,41 @@ const order = { const validatorResult: ValidatorResult = validator.validate(order, orderSchema); // Contains all errors const isValid: boolean = validator.isValid(order, orderSchema); // Only returns boolean ``` + +## Contributing + +We strongly encourage that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository. + +Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. + +### Install Dependencies + +If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: + +```bash +yarn config set workspaces-experimental true +``` + +Then install dependencies + +```bash +yarn install +``` + +### Build + +```bash +yarn build +``` + +### Lint + +```bash +yarn lint +``` + +### Run Tests + +```bash +yarn test +``` diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 52deb2254..4b500eab3 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,46 +1,45 @@ { - "name": "@0xproject/json-schemas", - "version": "0.6.9", - "description": "0x-related json schemas", - "main": "lib/src/index.js", - "types": "lib/src/index.d.ts", - "scripts": { - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", - "test": "run-s clean build run_mocha", - "test:circleci": "yarn test", - "run_mocha": "mocha lib/test/**/*_test.js", - "clean": "shx rm -rf _bundles lib test_temp", - "build": "tsc" - }, - "repository": { - "type": "git", - "url": "https://github.com/0xProject/0x.js.git" - }, - "author": "", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" - }, - "homepage": "https://github.com/0xProject/0x.js/packages/json-schemas/README.md", - "dependencies": { - "jsonschema": "^1.2.0", - "lodash.values": "^4.3.0" - }, - "devDependencies": { - "@0xproject/tslint-config": "^0.2.0", - "@0xproject/utils": "^0.0.1", - "@types/lodash.foreach": "^4.5.3", - "@types/lodash.values": "^4.3.3", - "@types/mocha": "^2.2.42", - "bignumber.js": "~4.1.0", - "chai": "^4.0.1", - "chai-typescript-typings": "^0.0.1", - "dirty-chai": "^2.0.1", - "lodash.foreach": "^4.5.0", - "mocha": "^4.0.1", - "npm-run-all": "^4.1.2", - "shx": "^0.2.2", - "tslint": "5.8.0", - "typescript": "~2.6.1" - } + "name": "@0xproject/json-schemas", + "version": "0.7.4", + "description": "0x-related json schemas", + "main": "lib/src/index.js", + "types": "lib/src/index.d.ts", + "scripts": { + "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "test": "run-s clean build run_mocha", + "test:circleci": "yarn test", + "run_mocha": "mocha lib/test/**/*_test.js", + "clean": "shx rm -rf _bundles lib test_temp", + "build": "tsc" + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x.js.git" + }, + "author": "", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x.js/issues" + }, + "homepage": "https://github.com/0xProject/0x.js/packages/json-schemas/README.md", + "dependencies": { + "jsonschema": "^1.2.0", + "lodash.values": "^4.3.0" + }, + "devDependencies": { + "@0xproject/tslint-config": "^0.4.3", + "@0xproject/utils": "^0.2.1", + "@types/lodash.foreach": "^4.5.3", + "@types/lodash.values": "^4.3.3", + "@types/mocha": "^2.2.42", + "chai": "^4.0.1", + "chai-typescript-typings": "^0.0.2", + "dirty-chai": "^2.0.1", + "lodash.foreach": "^4.5.0", + "mocha": "^4.0.1", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "tslint": "5.8.0", + "typescript": "~2.6.1" + } } diff --git a/packages/json-schemas/schemas/subscription_opts_schema.ts b/packages/json-schemas/schemas/block_range_schema.ts index a476e6963..1f6a63151 100644 --- a/packages/json-schemas/schemas/subscription_opts_schema.ts +++ b/packages/json-schemas/schemas/block_range_schema.ts @@ -10,11 +10,11 @@ export const blockParamSchema = { ], }; -export const subscriptionOptsSchema = { - id: '/SubscriptionOpts', +export const blockRangeSchema = { + id: '/BlockRange', properties: { - fromBlock: {$ref: '/BlockParam'}, - toBlock: {$ref: '/BlockParam'}, + fromBlock: { $ref: '/BlockParam' }, + toBlock: { $ref: '/BlockParam' }, }, type: 'object', }; diff --git a/packages/json-schemas/schemas/ec_signature_schema.ts b/packages/json-schemas/schemas/ec_signature_schema.ts index 2b769f3b6..71b840dd8 100644 --- a/packages/json-schemas/schemas/ec_signature_schema.ts +++ b/packages/json-schemas/schemas/ec_signature_schema.ts @@ -12,8 +12,8 @@ export const ecSignatureSchema = { minimum: 27, maximum: 28, }, - r: {$ref: '/ECSignatureParameter'}, - s: {$ref: '/ECSignatureParameter'}, + r: { $ref: '/ECSignatureParameter' }, + s: { $ref: '/ECSignatureParameter' }, }, required: ['v', 'r', 's'], type: 'object', diff --git a/packages/json-schemas/schemas/index_filter_values_schema.ts b/packages/json-schemas/schemas/index_filter_values_schema.ts index f7e323e45..3374d63e0 100644 --- a/packages/json-schemas/schemas/index_filter_values_schema.ts +++ b/packages/json-schemas/schemas/index_filter_values_schema.ts @@ -1,11 +1,7 @@ export const indexFilterValuesSchema = { id: '/IndexFilterValues', additionalProperties: { - oneOf: [ - {$ref: '/Number'}, - {$ref: '/Address'}, - {$ref: '/OrderHashSchema'}, - ], + oneOf: [{ $ref: '/Number' }, { $ref: '/Address' }, { $ref: '/OrderHashSchema' }], }, type: 'object', }; diff --git a/packages/json-schemas/schemas/order_cancel_schema.ts b/packages/json-schemas/schemas/order_cancel_schema.ts index ac7d2ee20..ad23d01cc 100644 --- a/packages/json-schemas/schemas/order_cancel_schema.ts +++ b/packages/json-schemas/schemas/order_cancel_schema.ts @@ -3,8 +3,8 @@ export const orderCancellationRequestsSchema = { type: 'array', items: { properties: { - order: {$ref: '/Order'}, - takerTokenCancelAmount: {$ref: '/Number'}, + order: { $ref: '/Order' }, + takerTokenCancelAmount: { $ref: '/Number' }, }, required: ['order', 'takerTokenCancelAmount'], type: 'object', diff --git a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts index 4ef7b069a..61f2c8849 100644 --- a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts +++ b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts @@ -3,8 +3,8 @@ export const orderFillOrKillRequestsSchema = { type: 'array', items: { properties: { - signedOrder: {$ref: '/SignedOrder'}, - fillTakerAmount: {$ref: '/Number'}, + signedOrder: { $ref: '/SignedOrder' }, + fillTakerAmount: { $ref: '/Number' }, }, required: ['signedOrder', 'fillTakerAmount'], type: 'object', diff --git a/packages/json-schemas/schemas/order_fill_requests_schema.ts b/packages/json-schemas/schemas/order_fill_requests_schema.ts index ec19dd9f8..419d0670f 100644 --- a/packages/json-schemas/schemas/order_fill_requests_schema.ts +++ b/packages/json-schemas/schemas/order_fill_requests_schema.ts @@ -3,8 +3,8 @@ export const orderFillRequestsSchema = { type: 'array', items: { properties: { - signedOrder: {$ref: '/SignedOrder'}, - takerTokenFillAmount: {$ref: '/Number'}, + signedOrder: { $ref: '/SignedOrder' }, + takerTokenFillAmount: { $ref: '/Number' }, }, required: ['signedOrder', 'takerTokenFillAmount'], type: 'object', diff --git a/packages/json-schemas/schemas/order_schemas.ts b/packages/json-schemas/schemas/order_schemas.ts index 3cce49351..6f17224ad 100644 --- a/packages/json-schemas/schemas/order_schemas.ts +++ b/packages/json-schemas/schemas/order_schemas.ts @@ -1,22 +1,30 @@ export const orderSchema = { id: '/Order', properties: { - maker: {$ref: '/Address'}, - taker: {$ref: '/Address'}, - makerFee: {$ref: '/Number'}, - takerFee: {$ref: '/Number'}, - makerTokenAmount: {$ref: '/Number'}, - takerTokenAmount: {$ref: '/Number'}, - makerTokenAddress: {$ref: '/Address'}, - takerTokenAddress: {$ref: '/Address'}, - salt: {$ref: '/Number'}, - feeRecipient: {$ref: '/Address'}, - expirationUnixTimestampSec: {$ref: '/Number'}, - exchangeContractAddress: {$ref: '/Address'}, + maker: { $ref: '/Address' }, + taker: { $ref: '/Address' }, + makerFee: { $ref: '/Number' }, + takerFee: { $ref: '/Number' }, + makerTokenAmount: { $ref: '/Number' }, + takerTokenAmount: { $ref: '/Number' }, + makerTokenAddress: { $ref: '/Address' }, + takerTokenAddress: { $ref: '/Address' }, + salt: { $ref: '/Number' }, + feeRecipient: { $ref: '/Address' }, + expirationUnixTimestampSec: { $ref: '/Number' }, + exchangeContractAddress: { $ref: '/Address' }, }, required: [ - 'maker', 'taker', 'makerFee', 'takerFee', 'makerTokenAmount', 'takerTokenAmount', - 'salt', 'feeRecipient', 'expirationUnixTimestampSec', 'exchangeContractAddress', + 'maker', + 'taker', + 'makerFee', + 'takerFee', + 'makerTokenAmount', + 'takerTokenAmount', + 'salt', + 'feeRecipient', + 'expirationUnixTimestampSec', + 'exchangeContractAddress', ], type: 'object', }; @@ -27,7 +35,7 @@ export const signedOrderSchema = { { $ref: '/Order' }, { properties: { - ecSignature: {$ref: '/ECSignature'}, + ecSignature: { $ref: '/ECSignature' }, }, required: ['ecSignature'], }, diff --git a/packages/json-schemas/schemas/relayer_api_error_response_schema.ts b/packages/json-schemas/schemas/relayer_api_error_response_schema.ts index eacbb2bce..27fdb166f 100644 --- a/packages/json-schemas/schemas/relayer_api_error_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_error_response_schema.ts @@ -2,16 +2,16 @@ export const relayerApiErrorResponseSchema = { id: '/RelayerApiErrorResponse', type: 'object', properties: { - code: {type: 'number'}, - reason: {type: 'string'}, + code: { type: 'number' }, + reason: { type: 'string' }, validationErrors: { type: 'array', items: { type: 'object', properties: { - field: {type: 'string'}, - code: {type: 'number'}, - reason: {type: 'string'}, + field: { type: 'string' }, + code: { type: 'number' }, + reason: { type: 'string' }, }, required: ['field', 'code', 'reason'], }, diff --git a/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts b/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts index 645660844..eaaf777a1 100644 --- a/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts @@ -2,18 +2,23 @@ export const relayerApiFeesPayloadSchema = { id: '/RelayerApiFeesPayload', type: 'object', properties: { - exchangeContractAddress: {$ref: '/Address'}, - maker: {$ref: '/Address'}, - taker: {$ref: '/Address'}, - makerTokenAddress: {$ref: '/Address'}, - takerTokenAddress: {$ref: '/Address'}, - makerTokenAmount: {$ref: '/Number'}, - takerTokenAmount: {$ref: '/Number'}, - expirationUnixTimestampSec: {$ref: '/Number'}, - salt: {$ref: '/Number'}, + exchangeContractAddress: { $ref: '/Address' }, + maker: { $ref: '/Address' }, + taker: { $ref: '/Address' }, + makerTokenAddress: { $ref: '/Address' }, + takerTokenAddress: { $ref: '/Address' }, + makerTokenAmount: { $ref: '/Number' }, + takerTokenAmount: { $ref: '/Number' }, + expirationUnixTimestampSec: { $ref: '/Number' }, + salt: { $ref: '/Number' }, }, required: [ - 'exchangeContractAddress', 'maker', 'taker', 'makerTokenAddress', 'takerTokenAddress', - 'expirationUnixTimestampSec', 'salt', + 'exchangeContractAddress', + 'maker', + 'taker', + 'makerTokenAddress', + 'takerTokenAddress', + 'expirationUnixTimestampSec', + 'salt', ], }; diff --git a/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts b/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts index 86e51feb0..e7440613f 100644 --- a/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts @@ -2,9 +2,9 @@ export const relayerApiFeesResponseSchema = { id: '/RelayerApiFeesResponse', type: 'object', properties: { - makerFee: {$ref: '/Number'}, - takerFee: {$ref: '/Number'}, - feeRecipient: {$ref: '/Address'}, + makerFee: { $ref: '/Number' }, + takerFee: { $ref: '/Number' }, + feeRecipient: { $ref: '/Address' }, }, required: ['makerFee', 'takerFee', 'feeRecipient'], }; diff --git a/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts b/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts index 2f71531c6..d93fa73d6 100644 --- a/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts @@ -2,10 +2,10 @@ export const relayerApiOrderbookChannelSubscribeSchema = { id: '/RelayerApiOrderbookChannelSubscribe', type: 'object', properties: { - type: {enum: ['subscribe']}, - channel: {enum: ['orderbook']}, - requestId: {type: 'number'}, - payload: {$ref: '/RelayerApiOrderbookChannelSubscribePayload'}, + type: { enum: ['subscribe'] }, + channel: { enum: ['orderbook'] }, + requestId: { type: 'number' }, + payload: { $ref: '/RelayerApiOrderbookChannelSubscribePayload' }, }, required: ['type', 'channel', 'requestId', 'payload'], }; @@ -14,10 +14,10 @@ export const relayerApiOrderbookChannelSubscribePayload = { id: '/RelayerApiOrderbookChannelSubscribePayload', type: 'object', properties: { - baseTokenAddress: {$ref: '/Address'}, - quoteTokenAddress: {$ref: '/Address'}, - snapshot: {type: 'boolean'}, - limit: {type: 'number'}, + baseTokenAddress: { $ref: '/Address' }, + quoteTokenAddress: { $ref: '/Address' }, + snapshot: { type: 'boolean' }, + limit: { type: 'number' }, }, required: ['baseTokenAddress', 'quoteTokenAddress'], }; diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts index 99037865e..fe1510d5b 100644 --- a/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts @@ -2,10 +2,10 @@ export const relayerApiOrderbookChannelSnapshotSchema = { id: '/RelayerApiOrderbookChannelSnapshot', type: 'object', properties: { - type: {enum: ['snapshot']}, - channel: {enum: ['orderbook']}, - requestId: {type: 'number'}, - payload: {$ref: '/RelayerApiOrderbookChannelSnapshotPayload'}, + type: { enum: ['snapshot'] }, + channel: { enum: ['orderbook'] }, + requestId: { type: 'number' }, + payload: { $ref: '/RelayerApiOrderbookChannelSnapshotPayload' }, }, required: ['type', 'channel', 'requestId', 'payload'], }; @@ -14,8 +14,8 @@ export const relayerApiOrderbookChannelSnapshotPayload = { id: '/RelayerApiOrderbookChannelSnapshotPayload', type: 'object', properties: { - bids: {$ref: '/signedOrdersSchema'}, - asks: {$ref: '/signedOrdersSchema'}, + bids: { $ref: '/signedOrdersSchema' }, + asks: { $ref: '/signedOrdersSchema' }, }, required: ['bids', 'asks'], }; diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts index 90cfd8749..9a6d83d4c 100644 --- a/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts @@ -2,10 +2,10 @@ export const relayerApiOrderbookChannelUpdateSchema = { id: '/RelayerApiOrderbookChannelUpdate', type: 'object', properties: { - type: {enum: ['update']}, - channel: {enum: ['orderbook']}, - requestId: {type: 'number'}, - payload: {$ref: '/SignedOrder'}, + type: { enum: ['update'] }, + channel: { enum: ['orderbook'] }, + requestId: { type: 'number' }, + payload: { $ref: '/SignedOrder' }, }, required: ['type', 'channel', 'requestId', 'payload'], }; diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts index b592d4f8e..5c409c807 100644 --- a/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts @@ -2,8 +2,8 @@ export const relayerApiOrderBookResponseSchema = { id: '/RelayerApiOrderBookResponse', type: 'object', properties: { - bids: {$ref: '/signedOrdersSchema'}, - asks: {$ref: '/signedOrdersSchema'}, + bids: { $ref: '/signedOrdersSchema' }, + asks: { $ref: '/signedOrdersSchema' }, }, required: ['bids', 'asks'], }; diff --git a/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts b/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts index 8ecab1424..5009c7955 100644 --- a/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts @@ -3,8 +3,8 @@ export const relayerApiTokenPairsResponseSchema = { type: 'array', items: { properties: { - tokenA: {$ref: '/RelayerApiTokenTradeInfo'}, - tokenB: {$ref: '/RelayerApiTokenTradeInfo'}, + tokenA: { $ref: '/RelayerApiTokenTradeInfo' }, + tokenB: { $ref: '/RelayerApiTokenTradeInfo' }, }, required: ['tokenA', 'tokenB'], type: 'object', @@ -15,10 +15,10 @@ export const relayerApiTokenTradeInfoSchema = { id: '/RelayerApiTokenTradeInfo', type: 'object', properties: { - address: {$ref: '/Address'}, - minAmount: {$ref: '/Number'}, - maxAmount: {$ref: '/Number'}, - precision: {type: 'number'}, + address: { $ref: '/Address' }, + minAmount: { $ref: '/Number' }, + maxAmount: { $ref: '/Number' }, + precision: { type: 'number' }, }, required: ['address'], }; diff --git a/packages/json-schemas/schemas/signed_orders_schema.ts b/packages/json-schemas/schemas/signed_orders_schema.ts index c4c4a68ac..34d956836 100644 --- a/packages/json-schemas/schemas/signed_orders_schema.ts +++ b/packages/json-schemas/schemas/signed_orders_schema.ts @@ -1,5 +1,5 @@ export const signedOrdersSchema = { id: '/signedOrdersSchema', type: 'array', - items: {$ref: '/SignedOrder'}, + items: { $ref: '/SignedOrder' }, }; diff --git a/packages/json-schemas/schemas/token_schema.ts b/packages/json-schemas/schemas/token_schema.ts index aca4d4ad2..e64565c8b 100644 --- a/packages/json-schemas/schemas/token_schema.ts +++ b/packages/json-schemas/schemas/token_schema.ts @@ -1,10 +1,10 @@ export const tokenSchema = { id: '/Token', properties: { - name: {type: 'string'}, - symbol: {type: 'string'}, - decimals: {type: 'number'}, - address: {$ref: '/Address'}, + name: { type: 'string' }, + symbol: { type: 'string' }, + decimals: { type: 'number' }, + address: { $ref: '/Address' }, }, required: ['name', 'symbol', 'decimals', 'address'], type: 'object', diff --git a/packages/json-schemas/schemas/tx_data_schema.ts b/packages/json-schemas/schemas/tx_data_schema.ts index 41eaadd3c..4274c553f 100644 --- a/packages/json-schemas/schemas/tx_data_schema.ts +++ b/packages/json-schemas/schemas/tx_data_schema.ts @@ -7,25 +7,16 @@ export const jsNumber = { export const txDataSchema = { id: '/TxData', properties: { - from: {$ref: '/Address'}, - to: {$ref: '/Address'}, + from: { $ref: '/Address' }, + to: { $ref: '/Address' }, value: { - oneOf: [ - {$ref: '/Number'}, - {$ref: '/JsNumber'}, - ], + oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }], }, gas: { - oneOf: [ - {$ref: '/Number'}, - {$ref: '/JsNumber'}, - ], + oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }], }, gasPrice: { - oneOf: [ - {$ref: '/Number'}, - {$ref: '/JsNumber'}, - ], + oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }], }, data: { type: 'string', diff --git a/packages/json-schemas/scripts/postpublish.js b/packages/json-schemas/scripts/postpublish.js index 7fa452b08..16d67e03f 100644 --- a/packages/json-schemas/scripts/postpublish.js +++ b/packages/json-schemas/scripts/postpublish.js @@ -3,12 +3,13 @@ const packageJSON = require('../package.json'); const subPackageName = packageJSON.name; -postpublish_utils.getLatestTagAndVersionAsync(subPackageName) +postpublish_utils + .getLatestTagAndVersionAsync(subPackageName) .then(function(result) { const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version); const assets = []; return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets); }) - .catch (function(err) { + .catch(function(err) { throw err; }); diff --git a/packages/json-schemas/src/index.ts b/packages/json-schemas/src/index.ts index b7cae277e..9d8470348 100644 --- a/packages/json-schemas/src/index.ts +++ b/packages/json-schemas/src/index.ts @@ -1,4 +1,4 @@ -export {ValidatorResult, Schema} from 'jsonschema'; +export { ValidatorResult, Schema } from 'jsonschema'; -export {SchemaValidator} from './schema_validator'; -export {schemas} from './schemas'; +export { SchemaValidator } from './schema_validator'; +export { schemas } from './schemas'; diff --git a/packages/json-schemas/src/schema_validator.ts b/packages/json-schemas/src/schema_validator.ts index c91f49340..e13326d2a 100644 --- a/packages/json-schemas/src/schema_validator.ts +++ b/packages/json-schemas/src/schema_validator.ts @@ -1,18 +1,18 @@ -import {Schema, Validator, ValidatorResult} from 'jsonschema'; +import { Schema, Validator, ValidatorResult } from 'jsonschema'; import values = require('lodash.values'); -import {schemas} from './schemas'; +import { schemas } from './schemas'; export class SchemaValidator { - private validator: Validator; + private _validator: Validator; constructor() { - this.validator = new Validator(); + this._validator = new Validator(); for (const schema of values(schemas)) { - this.validator.addSchema(schema, schema.id); + this._validator.addSchema(schema, schema.id); } } public addSchema(schema: Schema) { - this.validator.addSchema(schema, schema.id); + this._validator.addSchema(schema, schema.id); } // In order to validate a complex JS object using jsonschema, we must replace any complex // sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other @@ -20,7 +20,7 @@ export class SchemaValidator { // then parse it. The resultant object can then be checked using jsonschema. public validate(instance: any, schema: Schema): ValidatorResult { const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance)); - return this.validator.validate(jsonSchemaCompatibleObject, schema); + return this._validator.validate(jsonSchemaCompatibleObject, schema); } public isValid(instance: any, schema: Schema): boolean { const isValid = this.validate(instance, schema).errors.length === 0; diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts index 69164cbc7..5cb07acfe 100644 --- a/packages/json-schemas/src/schemas.ts +++ b/packages/json-schemas/src/schemas.ts @@ -1,39 +1,15 @@ -import { - addressSchema, - numberSchema, -} from '../schemas/basic_type_schemas'; -import { - ecSignatureParameterSchema, - ecSignatureSchema, -} from '../schemas/ec_signature_schema'; -import { - indexFilterValuesSchema, -} from '../schemas/index_filter_values_schema'; -import { - orderCancellationRequestsSchema, -} from '../schemas/order_cancel_schema'; -import { - orderFillOrKillRequestsSchema, -} from '../schemas/order_fill_or_kill_requests_schema'; -import { - orderFillRequestsSchema, -} from '../schemas/order_fill_requests_schema'; -import { - orderHashSchema, -} from '../schemas/order_hash_schema'; -import { - orderSchema, - signedOrderSchema, -} from '../schemas/order_schemas'; -import { - relayerApiErrorResponseSchema, -} from '../schemas/relayer_api_error_response_schema'; -import { - relayerApiFeesPayloadSchema, -} from '../schemas/relayer_api_fees_payload_schema'; -import { - relayerApiFeesResponseSchema, -} from '../schemas/relayer_api_fees_response_schema'; +import { addressSchema, numberSchema } from '../schemas/basic_type_schemas'; +import { blockParamSchema, blockRangeSchema } from '../schemas/block_range_schema'; +import { ecSignatureParameterSchema, ecSignatureSchema } from '../schemas/ec_signature_schema'; +import { indexFilterValuesSchema } from '../schemas/index_filter_values_schema'; +import { orderCancellationRequestsSchema } from '../schemas/order_cancel_schema'; +import { orderFillOrKillRequestsSchema } from '../schemas/order_fill_or_kill_requests_schema'; +import { orderFillRequestsSchema } from '../schemas/order_fill_requests_schema'; +import { orderHashSchema } from '../schemas/order_hash_schema'; +import { orderSchema, signedOrderSchema } from '../schemas/order_schemas'; +import { relayerApiErrorResponseSchema } from '../schemas/relayer_api_error_response_schema'; +import { relayerApiFeesPayloadSchema } from '../schemas/relayer_api_fees_payload_schema'; +import { relayerApiFeesResponseSchema } from '../schemas/relayer_api_fees_response_schema'; import { relayerApiOrderbookChannelSubscribePayload, relayerApiOrderbookChannelSubscribeSchema, @@ -42,30 +18,15 @@ import { relayerApiOrderbookChannelSnapshotPayload, relayerApiOrderbookChannelSnapshotSchema, } from '../schemas/relayer_api_orderbook_channel_snapshot_schema'; -import { - relayerApiOrderbookChannelUpdateSchema, -} from '../schemas/relayer_api_orderbook_channel_update_response_schema'; -import { - relayerApiOrderBookResponseSchema, -} from '../schemas/relayer_api_orderbook_response_schema'; +import { relayerApiOrderbookChannelUpdateSchema } from '../schemas/relayer_api_orderbook_channel_update_response_schema'; +import { relayerApiOrderBookResponseSchema } from '../schemas/relayer_api_orderbook_response_schema'; import { relayerApiTokenPairsResponseSchema, relayerApiTokenTradeInfoSchema, } from '../schemas/relayer_api_token_pairs_response_schema'; -import { - signedOrdersSchema, -} from '../schemas/signed_orders_schema'; -import { - blockParamSchema, - subscriptionOptsSchema, -} from '../schemas/subscription_opts_schema'; -import { - tokenSchema, -} from '../schemas/token_schema'; -import { - jsNumber, - txDataSchema, -} from '../schemas/tx_data_schema'; +import { signedOrdersSchema } from '../schemas/signed_orders_schema'; +import { tokenSchema } from '../schemas/token_schema'; +import { jsNumber, txDataSchema } from '../schemas/tx_data_schema'; export const schemas = { numberSchema, @@ -81,7 +42,7 @@ export const schemas = { signedOrderSchema, signedOrdersSchema, blockParamSchema, - subscriptionOptsSchema, + blockRangeSchema, tokenSchema, jsNumber, txDataSchema, diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 8a2f9407d..7b058781d 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -1,11 +1,10 @@ -import {promisify} from '@0xproject/utils'; -import BigNumber from 'bignumber.js'; +import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as dirtyChai from 'dirty-chai'; import forEach = require('lodash.foreach'); import 'mocha'; -import {schemas, SchemaValidator} from '../src/index'; +import { schemas, SchemaValidator } from '../src/index'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -16,7 +15,6 @@ const { addressSchema, ecSignatureSchema, ecSignatureParameterSchema, - indexFilterValuesSchema, orderCancellationRequestsSchema, orderFillOrKillRequestsSchema, orderFillRequestsSchema, @@ -25,7 +23,7 @@ const { signedOrderSchema, signedOrdersSchema, blockParamSchema, - subscriptionOptsSchema, + blockRangeSchema, tokenSchema, jsNumber, txDataSchema, @@ -96,9 +94,9 @@ describe('Schema', () => { }); it('should fail for invalid parameters', () => { const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter + '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters - '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x + '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x ]; const shouldFail = true; validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail); @@ -124,11 +122,7 @@ describe('Schema', () => { const v = 27; const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33'; const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254'; - const testCases = [ - {}, - {v}, - {r, s, v: 31}, - ]; + const testCases = [{}, { v }, { r, s, v: 31 }]; const shouldFail = true; validateAgainstSchema(testCases, ecSignatureSchema, shouldFail); }); @@ -154,39 +148,24 @@ describe('Schema', () => { }); describe('#blockParamSchema', () => { it('should validate valid block param', () => { - const testCases = [ - 42, - 'latest', - 'pending', - 'earliest', - ]; + const testCases = [42, 'latest', 'pending', 'earliest']; validateAgainstSchema(testCases, blockParamSchema); }); it('should fail for invalid block param', () => { - const testCases = [ - {}, - '42', - 'pemding', - ]; + const testCases = [{}, '42', 'pemding']; const shouldFail = true; validateAgainstSchema(testCases, blockParamSchema, shouldFail); }); }); - describe('#subscriptionOptsSchema', () => { + describe('#blockRangeSchema', () => { it('should validate valid subscription opts', () => { - const testCases = [ - {fromBlock: 42, toBlock: 'latest'}, - {fromBlock: 42}, - {}, - ]; - validateAgainstSchema(testCases, subscriptionOptsSchema); + const testCases = [{ fromBlock: 42, toBlock: 'latest' }, { fromBlock: 42 }, {}]; + validateAgainstSchema(testCases, blockRangeSchema); }); it('should fail for invalid subscription opts', () => { - const testCases = [ - {fromBlock: '42'}, - ]; + const testCases = [{ fromBlock: '42' }]; const shouldFail = true; - validateAgainstSchema(testCases, subscriptionOptsSchema, shouldFail); + validateAgainstSchema(testCases, blockRangeSchema, shouldFail); }); }); describe('#tokenSchema', () => { @@ -198,9 +177,7 @@ describe('Schema', () => { url: 'https://0xproject.com', }; it('should validate valid token', () => { - const testCases = [ - token, - ]; + const testCases = [token]; validateAgainstSchema(testCases, tokenSchema); }); it('should fail for invalid token', () => { @@ -237,9 +214,7 @@ describe('Schema', () => { }; describe('#orderSchema', () => { it('should validate valid order', () => { - const testCases = [ - order, - ]; + const testCases = [order]; validateAgainstSchema(testCases, orderSchema); }); it('should fail for invalid order', () => { @@ -269,28 +244,18 @@ describe('Schema', () => { }; describe('#signedOrdersSchema', () => { it('should validate valid signed orders', () => { - const testCases = [ - [signedOrder], - [], - ]; + const testCases = [[signedOrder], []]; validateAgainstSchema(testCases, signedOrdersSchema); }); it('should fail for invalid signed orders', () => { - const testCases = [ - [ - signedOrder, - 1, - ], - ]; + const testCases = [[signedOrder, 1]]; const shouldFail = true; validateAgainstSchema(testCases, signedOrdersSchema, shouldFail); }); }); describe('#signedOrderSchema', () => { it('should validate valid signed order', () => { - const testCases = [ - signedOrder, - ]; + const testCases = [signedOrder]; validateAgainstSchema(testCases, signedOrderSchema); }); it('should fail for invalid signed order', () => { @@ -312,9 +277,7 @@ describe('Schema', () => { }, ]; it('should validate valid order fill or kill requests', () => { - const testCases = [ - orderFillOrKillRequests, - ]; + const testCases = [orderFillOrKillRequests]; validateAgainstSchema(testCases, orderFillOrKillRequestsSchema); }); it('should fail for invalid order fill or kill requests', () => { @@ -338,9 +301,7 @@ describe('Schema', () => { }, ]; it('should validate valid order cancellation requests', () => { - const testCases = [ - orderCancellationRequests, - ]; + const testCases = [orderCancellationRequests]; validateAgainstSchema(testCases, orderCancellationRequestsSchema); }); it('should fail for invalid order cancellation requests', () => { @@ -364,9 +325,7 @@ describe('Schema', () => { }, ]; it('should validate valid order fill requests', () => { - const testCases = [ - orderFillRequests, - ]; + const testCases = [orderFillRequests]; validateAgainstSchema(testCases, orderFillRequestsSchema); }); it('should fail for invalid order fill requests', () => { @@ -561,12 +520,8 @@ describe('Schema', () => { channel: 'orderbook', requestId: 2, payload: { - bids: [ - signedOrder, - ], - asks: [ - signedOrder, - ], + bids: [signedOrder], + asks: [signedOrder], }, }, ]; @@ -579,12 +534,8 @@ describe('Schema', () => { channel: 'orderbook', requestId: 2, payload: { - bids: [ - signedOrder, - ], - asks: [ - signedOrder, - ], + bids: [signedOrder], + asks: [signedOrder], }, }, { @@ -592,24 +543,16 @@ describe('Schema', () => { channel: 'bar', requestId: 2, payload: { - bids: [ - signedOrder, - ], - asks: [ - signedOrder, - ], + bids: [signedOrder], + asks: [signedOrder], }, }, { type: 'snapshot', channel: 'orderbook', payload: { - bids: [ - signedOrder, - ], - asks: [ - signedOrder, - ], + bids: [signedOrder], + asks: [signedOrder], }, }, { @@ -617,12 +560,8 @@ describe('Schema', () => { channel: 'orderbook', requestId: '2', payload: { - bids: [ - signedOrder, - ], - asks: [ - signedOrder, - ], + bids: [signedOrder], + asks: [signedOrder], }, }, { @@ -630,9 +569,7 @@ describe('Schema', () => { channel: 'orderbook', requestId: 2, payload: { - bids: [ - signedOrder, - ], + bids: [signedOrder], }, }, { @@ -640,9 +577,7 @@ describe('Schema', () => { channel: 'orderbook', requestId: 2, payload: { - asks: [ - signedOrder, - ], + asks: [signedOrder], }, }, { @@ -650,12 +585,8 @@ describe('Schema', () => { channel: 'orderbook', requestId: 2, payload: { - bids: [ - signedOrder, - ], - asks: [ - {}, - ], + bids: [signedOrder], + asks: [{}], }, }, { @@ -663,12 +594,8 @@ describe('Schema', () => { channel: 'orderbook', requestId: 2, payload: { - bids: [ - {}, - ], - asks: [ - signedOrder, - ], + bids: [{}], + asks: [signedOrder], }, }, ]; @@ -943,18 +870,11 @@ describe('Schema', () => { }); describe('#jsNumberSchema', () => { it('should validate valid js number', () => { - const testCases = [ - 1, - 42, - ]; + const testCases = [1, 42]; validateAgainstSchema(testCases, jsNumber); }); it('should fail for invalid js number', () => { - const testCases = [ - NaN, - -1, - new BigNumber(1), - ]; + const testCases = [NaN, -1, new BigNumber(1)]; const shouldFail = true; validateAgainstSchema(testCases, jsNumber, shouldFail); }); diff --git a/packages/json-schemas/tsconfig.json b/packages/json-schemas/tsconfig.json index 40c2f0c8c..88a467ccb 100644 --- a/packages/json-schemas/tsconfig.json +++ b/packages/json-schemas/tsconfig.json @@ -1,17 +1,7 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "lib": [ "es2017", "dom"], - "outDir": "lib", - "sourceMap": true, - "declaration": true, - "noImplicitAny": true, - "strictNullChecks": true - }, - "include": [ - "./src/**/*", - "./test/**/*", - "../../node_modules/chai-typescript-typings/index.d.ts" - ] + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "lib" + }, + "include": ["./src/**/*", "./test/**/*", "../../node_modules/chai-typescript-typings/index.d.ts"] } diff --git a/packages/json-schemas/tslint.json b/packages/json-schemas/tslint.json index a07795151..ffaefe83a 100644 --- a/packages/json-schemas/tslint.json +++ b/packages/json-schemas/tslint.json @@ -1,5 +1,3 @@ { - "extends": [ - "@0xproject/tslint-config" - ] + "extends": ["@0xproject/tslint-config"] } |