From 8f59647f36a3548f049e97d55f7fd546704904cb Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 22 Nov 2018 10:46:10 +0000 Subject: [PATCH] refactor: extract types that are shared --- src/lib/modules/console/index.ts | 19 +++---------------- src/lib/modules/console/suggestions.ts | 14 +++----------- src/typings/embark.d.ts | 18 ++++++++++++++++++ src/typings/embarkConfig.d.ts | 3 +++ src/typings/logger.d.ts | 4 ++++ 5 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 src/typings/embark.d.ts create mode 100644 src/typings/embarkConfig.d.ts create mode 100644 src/typings/logger.d.ts diff --git a/src/lib/modules/console/index.ts b/src/lib/modules/console/index.ts index 54b906d82..2ad0ce3ec 100644 --- a/src/lib/modules/console/index.ts +++ b/src/lib/modules/console/index.ts @@ -6,26 +6,13 @@ const EmbarkJS = require("embarkjs"); const IpfsApi = require("ipfs-api"); const stringify = require("json-stringify-safe"); import Web3 from "web3"; +import { Embark, Events } from "../../../typings/embark"; import Suggestions from "./suggestions"; declare const __: any; -interface Events { - on: any; - request: any; - emit: any; - once: any; - setCommandHandler: any; -} - -interface EmbarkApi { - events: Events; - registerAPICall: any; - registerConsoleCommand: any; -} - class Console { - private embark: EmbarkApi; + private embark: Embark; private events: Events; private plugins: any; private version: string; @@ -36,7 +23,7 @@ class Console { private cmdHistoryFile: string; private suggestions: Suggestions; - constructor(embark: any, options: any) { + constructor(embark: Embark, options: any) { this.embark = embark; this.events = options.events; this.plugins = options.plugins; diff --git a/src/lib/modules/console/suggestions.ts b/src/lib/modules/console/suggestions.ts index 42ba03077..6f90c9177 100644 --- a/src/lib/modules/console/suggestions.ts +++ b/src/lib/modules/console/suggestions.ts @@ -1,14 +1,6 @@ const fuzzySearch = require("../../utils/utils").fuzzySearch; -interface Events { - on: any; - request: any; -} - -interface EmbarkApi { - events: Events; - registerAPICall: any; -} +import { Embark, Events } from "../../../typings/embark"; interface ContractsManager { [key: string]: any; @@ -23,11 +15,11 @@ interface Suggestion { type SuggestionsList = Suggestion[]; export default class Suggestions { - private embark: EmbarkApi; + private embark: Embark; private events: Events; private contracts: ContractsManager; - constructor(embark: EmbarkApi, options?: object) { + constructor(embark: Embark, options?: object) { this.embark = embark; this.events = embark.events; this.contracts = {}; diff --git a/src/typings/embark.d.ts b/src/typings/embark.d.ts new file mode 100644 index 000000000..e27c0a5b2 --- /dev/null +++ b/src/typings/embark.d.ts @@ -0,0 +1,18 @@ +import { Logger } from "./logger"; + +export interface Events { + on: any; + request: any; + emit: any; + once: any; + setCommandHandler: any; +} + +export interface Embark { + events: Events; + registerAPICall: any; + registerConsoleCommand: any; + logger: Logger; + config: {}; + registerActionForEvent(name: string, action: (callback: () => void) => void): void; +} diff --git a/src/typings/embarkConfig.d.ts b/src/typings/embarkConfig.d.ts new file mode 100644 index 000000000..1917dcd6e --- /dev/null +++ b/src/typings/embarkConfig.d.ts @@ -0,0 +1,3 @@ +export interface EmbarkConfig { + contracts: [string]; +} diff --git a/src/typings/logger.d.ts b/src/typings/logger.d.ts new file mode 100644 index 000000000..9dd3a5542 --- /dev/null +++ b/src/typings/logger.d.ts @@ -0,0 +1,4 @@ +export interface Logger { + info(text: string): void; + error(text: string): void; +}