UNPKG

@squiz/dxp

Version:

The common dxp library for cli commands

416 lines (415 loc) • 10.8 kB
/*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ /// <reference types="node" /> import { AuthService } from '@squiz/mercury-auth'; import { ConsoleService } from '@squiz/mercury-console'; import { HttpService } from '@squiz/mercury-http'; import { StorageService } from '@squiz/mercury-storage'; import { AnyConstructor, AnyFunction } from '@squiz/mercury-support'; import { exec, ExecOptions, execSync } from 'child_process'; import { UUID } from 'io-ts-types/lib/UUID'; import { Observable } from 'rxjs'; import { Command, Commandable, CommandParent, Commands } from '../Commands/Command.dto'; import { CommandContextEntities } from './Context.entities.dto'; import { CommandContextExternal } from './Context.external.dto'; /** * TODO: * @export * @interface CommandContextAssert */ export interface CommandContextAssert { /** * TODO: * @template T TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isArray<T>(item: unknown, message?: string): asserts item is Array<T>; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isBoolean(item: unknown, message?: string): asserts item is boolean; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isCommand(item: unknown, message?: string): asserts item is Command; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isCommandable(item: unknown, message?: string): asserts item is Commandable; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isConstructor(item: unknown, message?: string): asserts item is AnyConstructor; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isFunction(item: unknown, message?: string): asserts item is AnyFunction; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isIoUuid(item: unknown, message?: string): asserts item is UUID; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isNumber(item: unknown, message?: string): asserts item is number; /** * TODO: * @param {unknown} item TODO: * @param {string} [message] TODO: * @memberof CommandContextAssert */ isString(item: unknown, message?: string): asserts item is string; } /** * TODO: * @export * @interface CommandContextPaths */ export interface CommandContextPaths { /** * TODO: * @type {string} * @memberof CommandContextPaths */ config: string; /** * TODO: * @type {string} * @memberof CommandContextPaths */ plugins: string; /** * TODO: * @type {string} * @memberof CommandContextPaths */ root: string; } /** * TODO: * @export * @interface CommandContext */ export interface CommandContext { /** * TODO: * @type {CommandContextAssert} * @memberof CommandContext */ assert: CommandContextAssert; /** * The auth service. * @type {AuthService} * @memberof CommandContext */ authService: AuthService; /** * TODO: * @type {Array<string>} * @memberof CommandContext */ commandList: Array<string>; /** * TODO: * @type {Commands} * @memberof CommandContext */ commands: Commands; /** * The console service. * @type {ConsoleService} * @memberof CommandContext */ consoleService: ConsoleService; /** * TODO: * @type {Command} * @memberof CommandContext */ currentCommand: Command; /** * TODO: * @type {string} * @memberof CommandContext */ EOL: string; /** * TODO: * @type {CommandContextEntities} * @memberof CommandContext */ entities: CommandContextEntities; /** * TODO: * @type {typeof exec} * @memberof CommandContext */ exec: typeof exec; /** * TODO: * @type {typeof execSync} * @memberof CommandContext */ execSync: typeof execSync; /** * TODO: * @type {CommandContextExternal} * @memberof CommandContext */ external: CommandContextExternal; /** * TODO: * @type {Record<string, unknown>} * @memberof CommandContext */ flags: Record<string, unknown>; /** * TODO: * @type {Array<string>} * @memberof CommandContext */ input: Array<string>; /** * TODO: * @type {boolean} * @memberof CommandContext */ isDebugging: boolean; /** * The http service. * @type {HttpService} * @memberof CommandContext */ httpService: HttpService; /** * TODO: * @type {CommandParent} * @memberof CommandContext */ parent: CommandParent; /** * TODO: * @type {CommandContextPaths} * @memberof CommandContext */ paths: CommandContextPaths; /** * TODO: * @type {NodeJS.Platform} * @memberof CommandContext */ platform: NodeJS.Platform; /** * TODO: * @type {Record<string, Array<string>>} * @memberof CommandContext */ pluginList: Record<string, Array<string>>; /** * The storage service. * @type {StorageService} * @memberof CommandContext */ storageService: StorageService; /** * TODO: * @template T TODO: * @param {(command: Command, commandFullName: string) => T} callback TODO: * @returns {Array<T>} TODO: * @memberof CommandContext */ commandsMap<T>(callback: (command: Command, commandFullName: string) => T): Array<T>; /** * TODO: * @returns {string} TODO: * @memberof CommandContext */ createHelp(): string; /** * TODO: * @param {string} message TODO: * @returns {CommandContextExternal['Ora']} TODO: * @memberof CommandContext */ createSpinner(message: string): CommandContextExternal['Ora']; /** * TODO: * @param {(() => Array<string> | string | void)} callback TODO: * @memberof CommandContext */ debug(callback: () => Array<string> | string | void): void; /** * TODO: * @returns {Command} TODO: * @memberof CommandContext */ determineCurrentCommand(): Command; /** * TODO: * @param {string} command TODO: * @param {ExecOptions} [options] TODO: * @returns {Observable<string>} TODO: * @memberof CommandContext */ exec$(command: string, options?: ExecOptions): Observable<string>; /** * TODO: * @param {string} command TODO: * @param {ExecOptions} [options] TODO: * @returns {Promise<string>} TODO: * @memberof CommandContext */ execAsPromised(command: string, options?: ExecOptions): Promise<string>; /** * TODO: * @template T TODO: * @param {(Observable<T> | Promise<T> | T)} source TODO: * @returns {Observable<T>} TODO: * @memberof CommandContext */ observe<T>(source: Observable<T> | Promise<T> | T): Observable<T>; /** * TODO: * @template T TODO: * @param {unknown} item TODO: * @memberof CommandContext * @returns {boolean} TODO: */ isArray<T>(item: unknown): item is Array<T>; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isBoolean(item: unknown): item is boolean; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isCommand(item: unknown): item is Command; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isCommandable(item: unknown): item is Commandable; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isConstructor(item: unknown): item is AnyConstructor; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isFunction(item: unknown): item is AnyFunction; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isIoUuid(item: unknown): item is UUID; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isNumber(item: unknown): item is number; /** * TODO: * @param {unknown} item TODO: * @returns {boolean} TODO: * @memberof CommandContext */ isString(item: unknown): item is string; /** * TODO: * @memberof CommandContext */ loadCommands(): void; /** * TODO: * @param {number} [exitCode] TODO: * @memberof CommandContext */ showHelp(exitCode?: number): void; /** * TODO: * @param {string} value TODO: * @returns {string} TODO: * @memberof CommandContext */ stringHashShort(value: string): string; } /** * TODO: * @export * @interface CommandContextNewDto */ export interface CommandContextNewDto { /** * The auth service. * @type {AuthService} * @memberof CommandContextNewDto */ authService: AuthService; /** * The console service. * @type {ConsoleService} * @memberof CommandContextNewDto */ consoleService: ConsoleService; /** * The http service. * @type {HttpService} * @memberof CommandContextNewDto */ httpService: HttpService; /** * TODO: * @type {string} * @memberof CommandContextNewDto */ rootPath: string; /** * The storage service. * @type {StorageService} * @memberof CommandContextNewDto */ storageService: StorageService; }