Include web3 types via typeRoots and factor out common parts of tsconfig.json

This commit is contained in:
Leonid Logvinov 2018-01-04 18:56:30 +01:00
parent e6a783aff8
commit 27d9fba785
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
32 changed files with 82 additions and 161 deletions

View File

@ -78,7 +78,7 @@
"typedoc": "~0.8.0", "typedoc": "~0.8.0",
"typescript": "~2.6.1", "typescript": "~2.6.1",
"web3-provider-engine": "^13.0.1", "web3-provider-engine": "^13.0.1",
"web3-typescript-typings": "^0.7.2", "web3-typescript-typings": "^0.9.0",
"webpack": "^3.1.0" "webpack": "^3.1.0"
}, },
"dependencies": { "dependencies": {

View File

@ -213,12 +213,17 @@ export class ZeroEx {
* @param networkId The id of the network your provider is connected to * @param networkId The id of the network your provider is connected to
*/ */
public setProvider(provider: Web3Provider, networkId: number): void { public setProvider(provider: Web3Provider, networkId: number): void {
this._web3Wrapper.setProvider(provider, networkId); this._web3Wrapper.setProvider(provider);
(this.exchange as any)._invalidateContractInstances(); (this.exchange as any)._invalidateContractInstances();
(this.exchange as any)._setNetworkId(networkId);
(this.tokenRegistry as any)._invalidateContractInstance(); (this.tokenRegistry as any)._invalidateContractInstance();
(this.tokenRegistry as any)._setNetworkId(networkId);
(this.token as any)._invalidateContractInstances(); (this.token as any)._invalidateContractInstances();
(this.token as any)._setNetworkId(networkId);
(this.proxy as any)._invalidateContractInstance(); (this.proxy as any)._invalidateContractInstance();
(this.proxy as any)._setNetworkId(networkId);
(this.etherToken as any)._invalidateContractInstance(); (this.etherToken as any)._invalidateContractInstance();
(this.etherToken as any)._setNetworkId(networkId);
} }
/** /**
* Get user Ethereum addresses available through the supplied web3 provider available for sending transactions. * Get user Ethereum addresses available through the supplied web3 provider available for sending transactions.

View File

@ -177,6 +177,9 @@ export class ContractWrapper {
this._onLogStateChanged.bind(this, isRemoved), this._onLogStateChanged.bind(this, isRemoved),
); );
} }
private _setNetworkId(networkId: number): void {
this._networkId = networkId;
}
private _stopBlockAndLogStream(): void { private _stopBlockAndLogStream(): void {
if (_.isUndefined(this._blockAndLogStreamerIfExists)) { if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
throw new Error(ZeroExError.SubscriptionNotFound); throw new Error(ZeroExError.SubscriptionNotFound);

View File

@ -1,21 +1,14 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es2015", "dom"],
"outDir": "lib", "outDir": "lib",
"sourceMap": true, "strict": false
"declaration": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"strictNullChecks": true
}, },
"include": [ "include": [
"./src/**/*", "./src/**/*",
"./test/**/*", "./test/**/*",
"../../node_modules/types-bn/index.d.ts", "../../node_modules/types-bn/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts", "../../node_modules/types-ethereumjs-util/index.d.ts",
"../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts", "../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts" "../../node_modules/chai-as-promised-typescript-typings/index.d.ts"
] ]

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2015", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": ["./src/**/*", "./test/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] "include": ["./src/**/*", "./test/**/*"]
} }

View File

@ -18,9 +18,6 @@ export const assert = {
`${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`, `${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`,
); );
}, },
isUndefined(value: any, variableName?: string): void {
this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value));
},
isString(variableName: string, value: string): void { isString(variableName: string, value: string): void {
this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value)); this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value));
}, },
@ -77,11 +74,11 @@ Validation errors: ${validationResult.errors.join(', ')}`;
this.assert(!hasValidationErrors, msg); this.assert(!hasValidationErrors, msg);
}, },
isHttpUrl(variableName: string, value: any): void { isHttpUrl(variableName: string, value: any): void {
const isValidUrl = validUrl.isWebUri(value); const isValidUrl = !_.isUndefined(validUrl.isWebUri(value));
this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'http url', value)); this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'http url', value));
}, },
isUri(variableName: string, value: any): void { isUri(variableName: string, value: any): void {
const isValidUri = validUrl.isUri(value); const isValidUri = !_.isUndefined(validUrl.isUri(value));
this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value)); this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value));
}, },
assert(condition: boolean, message: string): void { assert(condition: boolean, message: string): void {

View File

@ -22,16 +22,6 @@ describe('Assertions', () => {
invalidInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.throw()); invalidInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.throw());
}); });
}); });
describe('#isUndefined', () => {
it('should not throw for valid input', () => {
const validInputs = [undefined];
validInputs.forEach(input => expect(assert.isUndefined.bind(assert, input, variableName)).to.not.throw());
});
it('should throw for invalid input', () => {
const invalidInputs = ['test', 42, false, { random: 'test' }];
invalidInputs.forEach(input => expect(assert.isUndefined.bind(assert, input, variableName)).to.throw());
});
});
describe('#isString', () => { describe('#isString', () => {
it('should not throw for valid input', () => { it('should not throw for valid input', () => {
const validInputs = ['hello', 'goodbye']; const validInputs = ['hello', 'goodbye'];
@ -44,7 +34,7 @@ describe('Assertions', () => {
}); });
describe('#isFunction', () => { describe('#isFunction', () => {
it('should not throw for valid input', () => { it('should not throw for valid input', () => {
const validInputs = [BigNumber, assert.isString.bind(this)]; const validInputs = [BigNumber, assert.isString];
validInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.not.throw()); validInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.not.throw());
}); });
it('should throw for invalid input', () => { it('should throw for invalid input', () => {

View File

@ -1,18 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2017", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": [ "include": ["./src/**/*", "./test/**/*", "../../node_modules/chai-typescript-typings/index.d.ts"]
"./src/**/*",
"./test/**/*",
"../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/web3-typescript-typings/index.d.ts"
]
} }

View File

@ -59,6 +59,6 @@
"tslint": "5.8.0", "tslint": "5.8.0",
"typedoc": "~0.8.0", "typedoc": "~0.8.0",
"typescript": "~2.6.1", "typescript": "~2.6.1",
"web3-typescript-typings": "^0.7.2" "web3-typescript-typings": "^0.9.0"
} }
} }

View File

@ -1,19 +1,12 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2015", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": [ "include": [
"./src/**/*", "./src/**/*",
"./test/**/*", "./test/**/*",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts", "../../node_modules/chai-as-promised-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts", "../../node_modules/chai-typescript-typings/index.d.ts"
"../../node_modules/web3-typescript-typings/index.d.ts"
] ]
} }

View File

@ -1,4 +1,4 @@
interface BinaryPaths { export interface BinaryPaths {
[key: string]: string; [key: string]: string;
} }

View File

@ -24,7 +24,7 @@ export class Contract implements Web3.ContractInstance {
this._validator = new SchemaValidator(); this._validator = new SchemaValidator();
} }
private _populateFunctions(): void { private _populateFunctions(): void {
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function); const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function) as Web3.FunctionAbi[];
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
if (functionAbi.constant) { if (functionAbi.constant) {
const cbStyleCallFunction = this._contract[functionAbi.name].call; const cbStyleCallFunction = this._contract[functionAbi.name].call;
@ -42,7 +42,7 @@ export class Contract implements Web3.ContractInstance {
}); });
} }
private _populateEvents(): void { private _populateEvents(): void {
const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event); const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event) as Web3.EventAbi[];
_.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => { _.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => {
this[eventAbi.name] = this._contract[eventAbi.name]; this[eventAbi.name] = this._contract[eventAbi.name];
}); });

View File

@ -52,7 +52,7 @@
"types-bn": "^0.0.1", "types-bn": "^0.0.1",
"types-ethereumjs-util": "0xProject/types-ethereumjs-util", "types-ethereumjs-util": "0xProject/types-ethereumjs-util",
"typescript": "~2.6.1", "typescript": "~2.6.1",
"web3-typescript-typings": "^0.7.2", "web3-typescript-typings": "^0.9.0",
"yargs": "^10.0.3" "yargs": "^10.0.3"
}, },
"dependencies": { "dependencies": {

View File

@ -1,16 +1,15 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"outDir": "./lib/", "outDir": "lib",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"baseUrl": ".", "baseUrl": ".",
"declaration": false,
"strictNullChecks": false,
"strictFunctionTypes": false,
"allowJs": true "allowJs": true
}, },
"include": [ "include": [
"../../node_modules/types-ethereumjs-util/index.d.ts", "../../node_modules/types-ethereumjs-util/index.d.ts",
"../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts", "../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts", "../../node_modules/chai-as-promised-typescript-typings/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts", "../../node_modules/types-ethereumjs-util/index.d.ts",

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2017", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": [ "include": [
"./src/**/*", "./src/**/*",

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"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"] "include": ["./src/**/*", "./test/**/*", "../../node_modules/chai-typescript-typings/index.d.ts"]
} }

View File

@ -36,7 +36,7 @@
"source-map-loader": "^0.1.6", "source-map-loader": "^0.1.6",
"tslint": "5.8.0", "tslint": "5.8.0",
"typescript": "~2.6.1", "typescript": "~2.6.1",
"web3-typescript-typings": "^0.7.2", "web3-typescript-typings": "^0.9.0",
"webpack": "^3.1.0", "webpack": "^3.1.0",
"webpack-node-externals": "^1.6.0" "webpack-node-externals": "^1.6.0"
} }

View File

@ -1,5 +1,5 @@
export const configs = { export const configs = {
DISPENSER_ADDRESS: process.env.DISPENSER_ADDRESS.toLowerCase(), DISPENSER_ADDRESS: (process.env.DISPENSER_ADDRESS as string).toLowerCase(),
DISPENSER_PRIVATE_KEY: process.env.DISPENSER_PRIVATE_KEY, DISPENSER_PRIVATE_KEY: process.env.DISPENSER_PRIVATE_KEY,
ENVIRONMENT: process.env.FAUCET_ENVIRONMENT, ENVIRONMENT: process.env.FAUCET_ENVIRONMENT,
ROLLBAR_ACCESS_KEY: process.env.FAUCET_ROLLBAR_ACCESS_KEY, ROLLBAR_ACCESS_KEY: process.env.FAUCET_ROLLBAR_ACCESS_KEY,

View File

@ -3,7 +3,7 @@ import EthereumTx = require('ethereumjs-tx');
import { configs } from './configs'; import { configs } from './configs';
import { utils } from './utils'; import { utils } from './utils';
type Callback = (err: Error, accounts: any) => void; type Callback = (err: Error | null, accounts: any) => void;
export const idManagement = { export const idManagement = {
getAccounts(callback: Callback) { getAccounts(callback: Callback) {
@ -15,7 +15,7 @@ export const idManagement = {
}, },
signTransaction(txData: object, callback: Callback) { signTransaction(txData: object, callback: Callback) {
const tx = new EthereumTx(txData); const tx = new EthereumTx(txData);
const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY, 'hex'); const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex');
tx.sign(privateKeyBuffer); tx.sign(privateKeyBuffer);
const rawTx = `0x${tx.serialize().toString('hex')}`; const rawTx = `0x${tx.serialize().toString('hex')}`;
callback(null, rawTx); callback(null, rawTx);

View File

@ -38,10 +38,10 @@ export class RequestQueue {
} }
protected start() { protected start() {
this.queueIntervalId = timers.setInterval(() => { this.queueIntervalId = timers.setInterval(() => {
if (this.queue.length === 0) { const recipientAddress = this.queue.shift();
if (_.isUndefined(recipientAddress)) {
return; return;
} }
const recipientAddress = this.queue.shift();
// tslint:disable-next-line:no-floating-promises // tslint:disable-next-line:no-floating-promises
this.processNextRequestFireAndForgetAsync(recipientAddress); this.processNextRequestFireAndForgetAsync(recipientAddress);
}, this.queueIntervalMs); }, this.queueIntervalMs);

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2015", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"experimentalDecorators": true
}, },
"include": ["../../node_modules/web3-typescript-typings/index.d.ts", "./src/ts/**/*"] "include": ["./src/ts/**/*"]
} }

View File

@ -1,11 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2015", "dom"],
"outDir": "lib",
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": ["./src/**/*"] "include": ["./src/**/*"]
} }

View File

@ -1,19 +1,11 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2015", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"strictNullChecks": true
}, },
"include": [ "include": [
"./src/**/*", "./src/**/*",
"./test/**/*", "./test/**/*",
"../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts", "../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/types-bn/index.d.ts", "../../node_modules/types-bn/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts", "../../node_modules/types-ethereumjs-util/index.d.ts",

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2017", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": ["./rules/**/*"] "include": ["./rules/**/*"]
} }

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2017", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] "include": ["./src/**/*"]
} }

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2017", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": ["./src/**/*"] "include": ["./src/**/*"]
} }

View File

@ -26,7 +26,7 @@
"shx": "^0.2.2", "shx": "^0.2.2",
"tslint": "5.8.0", "tslint": "5.8.0",
"typescript": "~2.6.1", "typescript": "~2.6.1",
"web3-typescript-typings": "^0.7.2" "web3-typescript-typings": "^0.9.0"
}, },
"dependencies": { "dependencies": {
"@0xproject/utils": "^0.1.2", "@0xproject/utils": "^0.1.2",

View File

@ -33,7 +33,7 @@ export class Web3Wrapper {
public getContractDefaults(): Partial<TxData> { public getContractDefaults(): Partial<TxData> {
return this._defaults; return this._defaults;
} }
public setProvider(provider: Web3.Provider, networkId: number) { public setProvider(provider: Web3.Provider) {
this._web3.setProvider(provider); this._web3.setProvider(provider);
} }
public isAddress(address: string): boolean { public isAddress(address: string): boolean {

View File

@ -1,13 +1,7 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "outDir": "lib"
"target": "es5",
"lib": ["es2017", "dom"],
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true
}, },
"include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] "include": ["./src/**/*"]
} }

View File

@ -101,7 +101,7 @@
"style-loader": "0.13.x", "style-loader": "0.13.x",
"tslint": "5.8.0", "tslint": "5.8.0",
"typescript": "~2.6.1", "typescript": "~2.6.1",
"web3-typescript-typings": "^0.7.2", "web3-typescript-typings": "^0.9.0",
"webpack": "^3.1.0", "webpack": "^3.1.0",
"webpack-dev-middleware": "^1.10.0", "webpack-dev-middleware": "^1.10.0",
"webpack-dev-server": "^2.5.0" "webpack-dev-server": "^2.5.0"

View File

@ -1,18 +1,16 @@
{ {
"extends": "../../tsconfig",
"compilerOptions": { "compilerOptions": {
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"outDir": "./transpiled/", "outDir": "./transpiled/",
"sourceMap": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react", "jsx": "react",
"baseUrl": "./", "baseUrl": "./",
"allowJs": true, "allowJs": true,
"strictNullChecks": true,
"declaration": false,
"paths": { "paths": {
"*": ["node_modules/@types/*", "*"] "*": ["node_modules/@types/*", "*"]
} }
}, },
"include": ["./ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] "include": ["./ts/**/*"]
} }

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es2017", "dom"],
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true,
"noImplicitReturns": true,
"pretty": true,
"strict": true,
"typeRoots": ["node_modules/@types", "node_modules/web3-typescript-typings"]
}
}