Comparing version 0.0.27 to 0.0.28
@@ -58,2 +58,8 @@ 'use strict' | ||
*/ | ||
async action() {} | ||
/** | ||
* | ||
* | ||
* @memberof Task | ||
*/ | ||
async init() {} | ||
@@ -121,3 +127,3 @@ /** | ||
*/ | ||
action(fn) { | ||
setAction(fn) { | ||
if (typeof fn !== 'function') { | ||
@@ -137,22 +143,32 @@ throw new TypeError( | ||
* | ||
* @param {any} name | ||
* @param {any} fn | ||
* @memberof Task | ||
*/ | ||
addHook(name, fn) { | ||
if (typeof fn !== 'function' && !(fn instanceof Task)) { | ||
setInit(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError( | ||
`Task <${this.constructor.name}:${this | ||
.name}> Hook handler of must be a function or Task instance` | ||
.name}> Init handler must be a function` | ||
) | ||
} | ||
if (supportedHooks.indexOf(name) === -1) { | ||
this.init = fn | ||
return this | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Task | ||
*/ | ||
setRollback(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError( | ||
`Task <${this.constructor.name}:${this | ||
.name}> Hook "${name}" not supported!` | ||
.name}> Rollback handler must be a function` | ||
) | ||
} | ||
this[name].push(fn) | ||
this.rollback = fn | ||
@@ -164,17 +180,24 @@ return this | ||
* | ||
* @param {any} queue | ||
* @returns | ||
* @param {any} name | ||
* @param {any} fn | ||
* @memberof Task | ||
*/ | ||
async start(queue) { | ||
if (typeof this.action !== 'function') { | ||
addHook(name, fn) { | ||
if (typeof fn !== 'function' && !(fn instanceof Task)) { | ||
throw new TypeError( | ||
`Task <${this.constructor.name}:${this | ||
.name}> Action must be a function. Actual ${typeof this.action}` | ||
.name}> Hook handler of must be a function or Task instance` | ||
) | ||
} | ||
const result = await this.action(queue) | ||
if (supportedHooks.indexOf(name) === -1) { | ||
throw new TypeError( | ||
`Task <${this.constructor.name}:${this | ||
.name}> Hook "${name}" not supported!` | ||
) | ||
} | ||
return result | ||
this[name].push(fn) | ||
return this | ||
} | ||
@@ -181,0 +204,0 @@ /** |
{ | ||
"name": "bootme", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tap -j4 \"test/*.test.js\" \"test/*/*.test.js\"" | ||
"test": "tap -j4 \"test/*.test.js\" \"test/*/*.test.js\" --coverage", | ||
"coverage": "npm run test -- --cov --coverage-report=html" | ||
}, | ||
@@ -22,2 +23,5 @@ "keywords": [ | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"homepage": "https://github.com/StarpTech/bootme#readme", | ||
@@ -29,4 +33,5 @@ "dependencies": { | ||
"devDependencies": { | ||
"delay": "^2.0.0", | ||
"tap": "^10.7.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202467
12
683
2