All files / src operation.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 6/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                        84x       83x 83x   72x   11x   11x         129x   129x       22x   22x       486x       11x           23x  
import Node from 'type/node';
import Repository from 'repository';
 
export interface OperationInput {
	readonly repository: Repository;
	readonly account: Node;
}
 
abstract class Operation<Input extends OperationInput, Output> {
	private input: Input;
 
	public constructor(input: Input) {
		this.input = input;
	}
 
	public async perform(): Promise<Output> {
		try {
			const result = await this.performInternal();
 
			return result;
		} catch (error) {
			this.logFailure(error);
 
			throw error;
		}
	}
 
	protected getRepository(): Repository {
		const input = this.getInput();
 
		return input.repository;
	}
 
	protected getAccount(): Node {
		const input = this.getInput();
 
		return input.account;
	}
 
	protected getInput(): Input {
		return this.input;
	}
 
	private logFailure(error: Error): void {
		console.error(error);
	}
 
	protected abstract performInternal(): Promise<Output>;
}
 
export default Operation;