diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 0000000..dc5cbf1 --- /dev/null +++ b/global.d.ts @@ -0,0 +1,2 @@ +// inquirer-search-list doesn't provide an available types +declare module 'inquirer-search-list'; diff --git a/tsconfig.json b/tsconfig.json index 0b97820..1744afa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,13 @@ "declaration": true, "declarationMap": true, "moduleResolution": "node", - "noImplicitAny": true, + "noImplicitAny": false, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "allowJs": true, - "allowSyntheticDefaultImports": false, + "checkJs": true, + "allowSyntheticDefaultImports": true, "noEmit": true } } diff --git a/types/command/baseSubCommand.d.ts b/types/command/baseSubCommand.d.ts index 5f69f42..b414a65 100644 --- a/types/command/baseSubCommand.d.ts +++ b/types/command/baseSubCommand.d.ts @@ -5,19 +5,9 @@ import type { Options as OraOptions } from 'ora'; import Registry from '../rc/index'; declare class BaseSubCommand { - static getUniConfig(commander: any): {}; + static getUniConfig(commander: Command): { [key: string]: any }; static parseBoolean(val: any): any; - static normalizeConfig(obj: any): {}; - /** - * @param {string} commandName sub command name - * @param {{ [key: string]: any }[]} parameters sub command parameters - * @param {string} description sub command description - * @param {{ [key: string]: any }[]} options sub command options - * @param {string[]} usage make examples - * @param {Registry} rc instance of Registry - * @param {{ [key: string]: any }} validatorDesc rules of async-validator - * @param {{ [key: string]: any }} oraOptions an ora options - */ + static normalizeConfig(obj: any): { [key: string]: any }; constructor( commandName: string, parameters: { [key: string]: any }[] | undefined, @@ -26,7 +16,7 @@ declare class BaseSubCommand { usage: string[] | undefined, rc: Registry, validatorDesc?: { [key: string]: any }, - oraOptions?: OraOptions, + oraOptions?: OraOptions ); commandName: string; parameters: { [key: string]: any }[]; diff --git a/types/command/call.d.ts b/types/command/call.d.ts index 9fac99e..d754dce 100644 --- a/types/command/call.d.ts +++ b/types/command/call.d.ts @@ -3,44 +3,16 @@ import BaseSubCommand from './baseSubCommand'; import Registry from '../rc/index'; import { CallCommandParameter } from '../utils/constants'; declare class CallCommand extends BaseSubCommand { - /** - * Creates an instance of CallCommand. - * @param {Registry} rc The instance of the Registry. - * @param {string} [name] The name of the command. - * @param {string} [description] The description of the command. - * @param {Object[]} [parameters] The parameters for the command. - * @param {string[]} [usage] The usage examples for the command. - * @param {any[]} [options] The options for the command. - */ constructor( rc: Registry, name?: string, description?: string, parameters?: CallCommandParameter[], usage?: string[], - options?: any[], + options?: any[] ); - /** - * Calls a method with specified parameters. - * @param {any} method The method to call. - * @param {any} params The parameters for the method call. - * @returns {Promise} A promise that resolves with the result of the method call. - */ callMethod(method: any, params: any): Promise; - /** - * Processes address after prompting for input. - * @param {any} aelf The AElf instance. - * @param {any} wallet The wallet instance. - * @param {Object.} answerInput The input parameters. - * @returns {Promise} A promise that resolves with the processed result. - */ processAddressAfterPrompt(aelf: any, wallet: any, answerInput: { [key: string]: any }): Promise; - /** - * Runs the command. - * @param {Command} commander The Commander instance. - * @param {...any[]} args Additional arguments passed to the command. - * @returns {Promise} A promise that resolves when the command execution completes. - */ run(commander: Command, ...args: any[]): Promise; } export default CallCommand; diff --git a/types/command/dappServer/HKDF.d.ts b/types/command/dappServer/HKDF.d.ts index 79d0377..a854ee8 100644 --- a/types/command/dappServer/HKDF.d.ts +++ b/types/command/dappServer/HKDF.d.ts @@ -1,4 +1,4 @@ -class HKDF { +declare class HKDF { constructor(hash: string, salt: Buffer, initialKey: string); private hashMethod: string; private hashLength: number; diff --git a/types/command/dappServer/encrypt.d.ts b/types/command/dappServer/encrypt.d.ts index 69cb598..93f10ea 100644 --- a/types/command/dappServer/encrypt.d.ts +++ b/types/command/dappServer/encrypt.d.ts @@ -1,6 +1,6 @@ import { ec } from 'elliptic'; -class Encrypt { +declare class Encrypt { constructor(algorithm: string, remotePublicKey: string, random: string, cipher?: string); private keyPair: ec.KeyPair; private cipher: string; @@ -8,25 +8,10 @@ class Encrypt { private sharedKey: Buffer; private derivedKey: Buffer; - /** - * Encrypts the given data. - * @param data - The data to be encrypted, base64 string. - * @returns An object containing the encrypted result and the initialization vector (iv). - */ encrypt(data: string): { encryptedResult: string; iv: string }; - /** - * Decrypts the given data. - * @param encrypted - The encrypted data, base64 string. - * @param iv - The initialization vector, hex string. - * @returns The decrypted data, base64 string. - */ decrypt(encrypted: string, iv: string): string; - /** - * Gets the public key. - * @returns The public key in hex string format. - */ getPublicKey(): string; } export default Encrypt; diff --git a/types/command/dappServer/index.d.ts b/types/command/dappServer/index.d.ts index 0314a66..569440a 100644 --- a/types/command/dappServer/index.d.ts +++ b/types/command/dappServer/index.d.ts @@ -1,10 +1,10 @@ import { Command } from 'commander'; import BaseSubCommand from '../baseSubCommand'; -import Registry from '../rc/index'; +import Registry from '../../rc/index'; -class DeployCommand extends BaseSubCommand { +declare class DappServerCommand extends BaseSubCommand { constructor(rc: Registry); run(commander: Command, ...args: any[]): Promise; } -export default DeployCommand; +export default DappServerCommand; diff --git a/types/command/dappServer/sign.d.ts b/types/command/dappServer/sign.d.ts index 723ed0d..8a6a7ee 100644 --- a/types/command/dappServer/sign.d.ts +++ b/types/command/dappServer/sign.d.ts @@ -1,29 +1,10 @@ import { ec } from 'elliptic'; declare class Sign { - /** - * static verify - * @param {string} algorithm ec algorithm - * @param {string} publicKey hex string, remote dapp public key - * @param {Buffer} msg message to be verified - * @param {string} signature remote dapp signature - * @return {boolean} result - */ static verify(algorithm: string, publicKey: string, msg: Buffer, signature: string): boolean; constructor(algorithm: string, publicKey: string); keyPair: ec.KeyPair; remoteKeyPair: ec.KeyPair; - /** - * sign message - * @param {Buffer} msg message to be signed - * @return {string} signature - */ sign(msg: Buffer): string; - /** - * verify signature - * @param {Buffer} msg message to be verified - * @param {string} signature hex string - * @return {boolean} result - */ verify(msg: Buffer, signature: string): boolean; getPublicKey(): string; } diff --git a/types/command/dappServer/socket.d.ts b/types/command/dappServer/socket.d.ts index 525bf5a..6eef934 100644 --- a/types/command/dappServer/socket.d.ts +++ b/types/command/dappServer/socket.d.ts @@ -37,6 +37,7 @@ interface Result { interface Client { emit(event: string, data: any): void; disconnect(close?: boolean): void; + on(event: string, cb: Function): void; } declare class Socket { private aelf: any; @@ -48,7 +49,7 @@ declare class Socket { constructor(options: SocketOptions); - private responseFormat(id: string, result: any, errors: any): Result; + private responseFormat(id: string, result?: any, errors?: any): { id: string; result: Result }; private send(client: Client, result: Result, action: string, appId: string): void; private handleConnection(client: Client): void; private deserializeParams(request: Message): Promise; diff --git a/types/command/dappServer/utils.d.ts b/types/command/dappServer/utils.d.ts index 6c911c9..13b2824 100644 --- a/types/command/dappServer/utils.d.ts +++ b/types/command/dappServer/utils.d.ts @@ -1,3 +1,3 @@ export function serializeMessage(data: any): string; export function deserializeMessage(str: string): any; -export function checkTimestamp(time: number | string, timeBuffer?: number): boolean; +export function checkTimestamp(time: string, timeBuffer?: number): boolean; diff --git a/types/command/send.d.ts b/types/command/send.d.ts index 4d4098a..6f3f991 100644 --- a/types/command/send.d.ts +++ b/types/command/send.d.ts @@ -3,4 +3,5 @@ import Registry from '../rc/index'; export default SendCommand; declare class SendCommand extends CallCommand { constructor(rc: Registry); + callMethod(method: any, params: any): Promise; } diff --git a/types/rc/index.d.ts b/types/rc/index.d.ts index bc31f8d..8bb6469 100644 --- a/types/rc/index.d.ts +++ b/types/rc/index.d.ts @@ -1,13 +1,9 @@ -class Registry { +declare class Registry { + constructor(); static getFileOrNot(file: string, defaultContent?: string): any; static getFileOrCreate(file: string): string; - static loadConfig(content?: string): {}; + static loadConfig(content?: string): { [key: string]: any }; static getConfigFromEnv(): { [key: string]: any }; - /** - * obj only contains one level field - * @param {Object} obj - * @return {string[]} the array of content - */ static stringify(obj?: { [key: string]: any }): string[]; globalConfigLoc: string; aelfConfig: { [key: string]: any }; @@ -21,7 +17,7 @@ class Registry { setOption(key: string, value: any): void; saveOption(key: string, value: any, filePath?: any): any; deleteConfig(key: string, filePath?: any): any; - getFileConfigs(filePath?: string): {}; + getFileConfigs(filePath?: string): { [key: string]: any }; getConfigs(): { [key: string]: any }; } export default Registry; diff --git a/types/utils/constants.d.ts b/types/utils/constants.d.ts index 8c756a1..27b245d 100644 --- a/types/utils/constants.d.ts +++ b/types/utils/constants.d.ts @@ -6,7 +6,7 @@ export interface CallCommandParameter { pageSize?: number; choices?: string[]; suffix: string; - extraName?: string; + extraName?: string[]; filter?: (input: any) => string; } export const callCommandParameters: CallCommandParameter[]; @@ -21,7 +21,7 @@ export interface PasswordValidatorDesc { export interface EndpointValidatorDesc { type: string; required: boolean; - regex: RegExp; + pattern: RegExp; message: string; } diff --git a/types/utils/userHomeDir.d.ts b/types/utils/userHomeDir.d.ts index 23fd9a6..ee7dc3d 100644 --- a/types/utils/userHomeDir.d.ts +++ b/types/utils/userHomeDir.d.ts @@ -1,5 +1,7 @@ export let userHomeDir: any; export const home: string; +export function getUid(): number | null; export function isFakeRoot(): boolean; +export function isWindows(): boolean; export function isRootUser(uid: number): boolean; export const ROOT_USER: boolean; diff --git a/types/utils/utils.d.ts b/types/utils/utils.d.ts index 42cd50c..6114817 100644 --- a/types/utils/utils.d.ts +++ b/types/utils/utils.d.ts @@ -1,13 +1,27 @@ import { Ora } from 'ora'; +import { DistinctQuestion } from 'inquirer'; export function promisify(fn: (...args: any[]) => void, firstData?: boolean): (...args: any[]) => Promise; export function camelCase(str: string): string; export function getContractMethods(contract?: { [key: string]: any }): string[]; export function getContractInstance(contractAddress: string, aelf: any, wallet: any, oraInstance: Ora): Promise; export function getMethod(method: any, contract: any): any; -export function promptTolerateSeveralTimes({ processAfterPrompt, pattern, times, prompt }: any, oraInstance: Ora): Object; +export function promptTolerateSeveralTimes( + { + processAfterPrompt, + pattern, + times, + prompt + }: { + processAfterPrompt: Function; + pattern: string | RegExp; + times: number; + prompt: DistinctQuestion; + }, + oraInstance: Ora +): Promise<{ [key: string]: any }>; export function isAElfContract(str: string): boolean; -export function getTxResult(aelf: any, txId: string, times?: number, delay?: number, timeLimit?: number): any; +export function getTxResult(aelf: any, txId: string, times?: number, delay?: number, timeLimit?: number): Promise; export function parseJSON(str?: string): any; export function randomId(): string; -export function getParams(method: any): Promise<{}>; +export function getParams(method: any): Promise<{ [key: string]: any }>; export function deserializeLogs(aelf: any, logs?: any[]): Promise;