export interface ICommandManagerOptions { prefix?: RegExp | string; optionPrefixes?: string[]; } export interface IParameter { type: TTypeConverterFn; required?: boolean; def?: any; rest?: boolean; catchAll?: boolean; option?: false; } export declare type TOption = { option: true; shortcut?: string; type: TTypeConverterFn; isSwitch?: boolean; def?: any; }; /** * A signature - a set of parameters - for a command * * `undefined` is included as an allowed value here because if you have an array of signature objects, * TypeScript will interpret that array's type as being an array of a union of each signature within that array, * with each of those signatures having the other signatures' properties that they don't have as optional properties. * E.g. `[{foo: 5}, {bar: "text"}]` would have the type `({foo: number, bar?: undefined} | {foo?: undefined, bar: string})[]` * If you then wanted to pass this type to a generic that expects an array of TSignatures, it would be rejected because * of the optional properties with `undefined` as their type. Including `undefined` here fixes this. */ export declare type TSignature = Record | TOption | undefined>; export declare type TSafeSignature = Record | TOption>; export interface IMatchedArgument { parameter: IParameter; value: any; usesDefaultValue?: true; } export interface IMatchedOption { option: TOption; value: any; usesDefaultValue?: true; } export declare type IMatchedSignature = Record | IMatchedOption>; export declare function isMatchedArgument(value: IMatchedArgument | IMatchedOption): value is IMatchedArgument; export declare type TPreFilterFn = (command: ICommandDefinition, context: TContext) => boolean | Promise; export declare type TPostFilterFn = (command: IMatchedCommand, context: TContext) => boolean | Promise; export interface ICommandConfig { prefix?: string | RegExp; preFilters?: TPreFilterFn[]; postFilters?: TPostFilterFn[]; extra?: TExtra; } export interface ICommandDefinition { id: number; prefix: RegExp | null; originalPrefix: string | RegExp | null; triggers: RegExp[]; originalTriggers: Array; signatures: TSignature[]; preFilters: TPreFilterFn[]; postFilters: TPostFilterFn[]; config: ICommandConfig | null; } export declare type TBaseError = { error: string; }; export declare type TOrError = T | TError; export declare function isError(value: TOrError): value is TBaseError; export interface IMatchedCommand extends ICommandDefinition { values: IMatchedSignature; error?: never; } export interface IFindMatchingCommandError extends TBaseError { command: ICommandDefinition; } export declare type TTypeConverterFn = ((value: any) => TReturnType) | ((value: any, context: TContext) => TReturnType);