nextcloud-node-client
Version:
Nextcloud client API for node.js TypeScript applications
80 lines (79 loc) • 2.35 kB
TypeScript
import Client from "./client";
/**
* The potential states that a command can have.
* When a command is created, the state is "initial"
* When the execution has started, the status is "running"
* When the execution has finsihed, the status can be "succes" or "failed"
*/
export declare enum CommandStatus {
/**
* When a command is created, the state is "initial"
*/
initial = "initial",
/**
* When the execution has started, the status is "running"
*/
running = "running",
/**
* After successful execution of the command, the status is "success"
*/
success = "success",
/**
* After unsuccessfull execution of the command, the status is "failed"
*/
failed = "failed"
}
/**
* when the command has finished, the client can get the result of the command execution
*/
export interface CommandResultMetaData {
errors: string[];
messages: string[];
timeElapsed: number;
}
/**
* The command class represents a potential long running activity.
* This activity has been wrapped into an object to ease the tracking of the processing state.
* Create a command with receiver information, execute the command and check the status and progress.
* Check the result when finsished.
*/
export default abstract class Command {
protected client: Client;
protected status: CommandStatus;
protected percentCompleted: number;
protected resultMetaData: CommandResultMetaData;
constructor(client: Client);
/**
* final execute the command
* @async
* @final
* @returns {Promise<void>}
*/
execute(): Promise<void>;
/**
* execute the command
* @async
* @returns {Promise<void>}
*/
protected abstract onExecute(): Promise<void>;
/**
* returns true, if the command has been finished
* @returns {boolean}
*/
isFinished(): boolean;
/**
* returns the status of the command
* @returns {CommandStatus}
*/
getStatus(): CommandStatus;
/**
* returns the completion percentage of the command
* @returns {number} percentage of completion
*/
getPercentCompleted(): number;
/**
* returns the result meta data of the command
* @returns {null|any} the result of the command
*/
getResultMetaData(): CommandResultMetaData;
}