Skip to content

Commit

Permalink
feat: add d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Jul 1, 2024
1 parent 8faef74 commit 53555f4
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 98 deletions.
2 changes: 2 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// inquirer-search-list doesn't provide an available types
declare module 'inquirer-search-list';
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
16 changes: 3 additions & 13 deletions types/command/baseSubCommand.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }[];
Expand Down
30 changes: 1 addition & 29 deletions types/command/call.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>} A promise that resolves with the result of the method call.
*/
callMethod(method: any, params: any): Promise<any>;
/**
* Processes address after prompting for input.
* @param {any} aelf The AElf instance.
* @param {any} wallet The wallet instance.
* @param {Object.<string, any>} answerInput The input parameters.
* @returns {Promise<any>} A promise that resolves with the processed result.
*/
processAddressAfterPrompt(aelf: any, wallet: any, answerInput: { [key: string]: any }): Promise<any>;
/**
* Runs the command.
* @param {Command} commander The Commander instance.
* @param {...any[]} args Additional arguments passed to the command.
* @returns {Promise<void>} A promise that resolves when the command execution completes.
*/
run(commander: Command, ...args: any[]): Promise<void>;
}
export default CallCommand;
2 changes: 1 addition & 1 deletion types/command/dappServer/HKDF.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class HKDF {
declare class HKDF {
constructor(hash: string, salt: Buffer, initialKey: string);
private hashMethod: string;
private hashLength: number;
Expand Down
17 changes: 1 addition & 16 deletions types/command/dappServer/encrypt.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
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;
private remoteKeyPair: ec.KeyPair;
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;
6 changes: 3 additions & 3 deletions types/command/dappServer/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
}

export default DeployCommand;
export default DappServerCommand;
19 changes: 0 additions & 19 deletions types/command/dappServer/sign.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion types/command/dappServer/socket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<any>;
Expand Down
2 changes: 1 addition & 1 deletion types/command/dappServer/utils.d.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions types/command/send.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
}
12 changes: 4 additions & 8 deletions types/rc/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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;
4 changes: 2 additions & 2 deletions types/utils/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -21,7 +21,7 @@ export interface PasswordValidatorDesc {
export interface EndpointValidatorDesc {
type: string;
required: boolean;
regex: RegExp;
pattern: RegExp;
message: string;
}

Expand Down
2 changes: 2 additions & 0 deletions types/utils/userHomeDir.d.ts
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 17 additions & 3 deletions types/utils/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { Ora } from 'ora';
import { DistinctQuestion } from 'inquirer';
export function promisify<T>(fn: (...args: any[]) => void, firstData?: boolean): (...args: any[]) => Promise<T>;
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<any>;
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<any>;
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<any>;

0 comments on commit 53555f4

Please sign in to comment.