Comparing version 0.0.8 to 0.0.9
import Task, { RunResult } from './Task'; | ||
import Keisatsu from './Keisatsu'; | ||
import Keisatsu, { Options } from './Keisatsu'; | ||
interface TaskObj { | ||
@@ -12,5 +12,6 @@ name: string; | ||
private hq; | ||
private options; | ||
private tasks; | ||
private taskPlans; | ||
constructor(hq: Keisatsu); | ||
constructor(hq: Keisatsu, options?: Options); | ||
get(property: string): any; | ||
@@ -17,0 +18,0 @@ set(property: string, value: any): void; |
@@ -15,4 +15,5 @@ "use strict"; | ||
class Agent { | ||
constructor(hq) { | ||
constructor(hq, options = {}) { | ||
this.hq = hq; | ||
this.options = options; | ||
this.tasks = {}; | ||
@@ -38,5 +39,5 @@ this.taskPlans = {}; | ||
if (typeof task === 'string' || task instanceof String) { | ||
return this.tasks[task].run(undefined, lastResult); | ||
return this.tasks[task].run(undefined, lastResult, this.options); | ||
} | ||
return this.tasks[task.name].run(task.seed, lastResult); | ||
return this.tasks[task.name].run(task.seed, lastResult, this.options); | ||
} | ||
@@ -43,0 +44,0 @@ runTasks(taskPlan) { |
import Agent from './Agent'; | ||
export interface Options { | ||
throwErrors?: boolean; | ||
} | ||
export default abstract class Keisatsu { | ||
private options; | ||
private agents; | ||
constructor(); | ||
constructor(options?: Options); | ||
registerAgent<T extends Agent>(agent: { | ||
@@ -6,0 +10,0 @@ new (...args: any[]): T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Keisatsu { | ||
constructor() { | ||
constructor(options = { throwErrors: false }) { | ||
this.options = options; | ||
this.agents = {}; | ||
} | ||
registerAgent(agent) { | ||
const newAgent = new agent(this); | ||
const newAgent = new agent(this, this.options); | ||
this.agents[agent.name] = newAgent; | ||
@@ -10,0 +11,0 @@ return newAgent; |
import Agent from './Agent'; | ||
import Keisatsu from './Keisatsu'; | ||
import Keisatsu, { Options } from './Keisatsu'; | ||
export interface RunResult { | ||
@@ -15,3 +15,3 @@ success: boolean; | ||
fail(error: Error): RunResult; | ||
run(seed?: any, lastResult?: any): Promise<RunResult>; | ||
run(seed?: any, lastResult?: any, options?: Options): Promise<RunResult>; | ||
} |
@@ -22,10 +22,16 @@ "use strict"; | ||
} | ||
run(seed, lastResult) { | ||
run(seed, lastResult, options = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (options.throwErrors) { | ||
const result = yield this.action(seed, lastResult); | ||
return this.succeed(result); | ||
} | ||
catch (e) { | ||
return this.fail(e); | ||
else { | ||
try { | ||
const result = yield this.action(seed, lastResult); | ||
return this.succeed(result); | ||
} | ||
catch (e) { | ||
return this.fail(e); | ||
} | ||
} | ||
@@ -32,0 +38,0 @@ }); |
{ | ||
"name": "keisatsu", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Task runner based on yakuza", | ||
@@ -5,0 +5,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21866
190