Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bootme

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bootme - npm Package Compare versions

Comparing version 0.0.14 to 0.0.16

76

lib/pipeline.js
'use strict'
const q = require('workq')
const Hoek = require('hoek')
const error = require('debug')('pipeline:error')

@@ -70,10 +69,14 @@ const State = require('./state')

*/
hasResult(name) {
return !!this.results.get(name)
}
/**
*
*
* @param {any} name
* @returns
* @memberof Pipeline
*/
getResult(name) {
const res = this.results.get(name)
if (res === undefined) {
throw new Error(`Task result "${name}" not available`)
}
return res
return this.results.get(name)
}

@@ -93,3 +96,8 @@ /**

} catch (err) {
error(`Error during rollback process %O`, err)
error(
`Task <%s:%s> Error during rollback process %O`,
task.constructor.name,
task.name,
err
)
}

@@ -102,5 +110,6 @@ }

* @param {any} task
* @memberof Task
* @param {any} state
* @memberof Pipeline
*/
async bootSubTask(task, state) {
async executeTask(task, state) {
this.registry.addTask(task)

@@ -113,5 +122,13 @@

if (typeof task.config === 'function') {
const config = await task.config(state)
let config = await task.config(state)
config = Object.assign(
config,
this.registry.preTaskConfigs.get(task.name, config)
)
task.setConfig(config)
} else {
task.config = Object.assign(
task.config,
this.registry.preTaskConfigs.get(task.name, task.config)
)
task.setConfig(task.config)

@@ -130,3 +147,3 @@ }

state.pipeline.results.set(`${task.name}`, result)
this.results.set(`${task.name}`, result)

@@ -144,3 +161,6 @@ await task.executeHooks('onAfter', state)

if (this.errored) {
error('Abort Pipeline cause Task error %O', this.pipeError)
error(
'Abort Pipeline error %O',
this.pipeError
)
break

@@ -163,3 +183,8 @@ }

} catch (err) {
error('Task <%s> onInit error %O', task.name, err)
error(
'Task <%s:%s> onInit error %O',
task.constructor.name,
task.name,
err
)
this.results.set(`${task.name}:onInit:error`, err)

@@ -179,3 +204,8 @@ await this.rollback(err)

} catch (err) {
error('Task <%s> onBefore error %O', task.name, err)
error(
'Task <%s:%s> onBefore error %O',
task.constructor.name,
task.name,
err
)
this.results.set(`${task.name}:onBefore:error`, err)

@@ -201,3 +231,8 @@ await this.rollback(err)

} catch (err) {
error('Task <%s> action error %O', task.name, err)
error(
'Task <%s:%s> action error %O',
task.constructor.name,
task.name,
err
)
this.results.set(`${task.name}:error`, err)

@@ -217,3 +252,8 @@ await this.rollback(err)

} catch (err) {
error('Task <%s> onAfter error %O', task.name, err)
error(
'Task <%s:%s> onAfter error %O',
task.constructor.name,
task.name,
err
)
this.results.set(`${task.name}:onAfter:error`, err)

@@ -220,0 +260,0 @@ await this.rollback(err)

@@ -17,5 +17,5 @@ 'use strict'

this.tasks = []
this.preTaskConfigs = new Map()
this.sharedConfig = {
basePath: process.cwd(),
env: process.env
basePath: process.cwd()
}

@@ -39,2 +39,12 @@ }

*
* @param {any} taskName
* @param {any} value
* @memberof Registry
*/
setConfig(taskName, value) {
this.preTaskConfigs.set(taskName, value)
}
/**
*
*
* @param {any} name

@@ -66,6 +76,8 @@ * @memberof Registry

}
const exists = this.tasks.find(t => t.name === task.name)
const t = this.tasks.find(t => t.name === task.name)
if (exists) {
throw new Error(`The Task "${task.name}" already exists`)
if (t) {
throw new Error(
`The Task <${t.constructor.name}:${t.name}> already exists`
)
}

@@ -72,0 +84,0 @@

@@ -16,12 +16,12 @@ 'use strict'

* @param {any} queue
* @param {any} parentTask
* @param {any} task
* @memberof Parent
*/
constructor(queue, parentTask, pipeline) {
if (!(parentTask instanceof Task)) {
throw new TypeError('The ParentTask must be a Task instance')
constructor(queue, task, pipeline) {
if (!(task instanceof Task)) {
throw new TypeError('The Task must be a Task instance')
}
this.queue = queue
this.parentTask = parentTask
this.task = task
this.pipeline = pipeline

@@ -32,2 +32,33 @@ }

*
* @param {any} name
* @returns
* @memberof State
*/
getValue(name) {
const res = this.pipeline.results.get(name)
if (res === undefined) {
for (var key in this.task.config) {
if (this.task.config[key]) {
return this.task.config[key]
}
}
}
return res
}
/**
*
*
* @param {any} task
* @param {any} state
* @memberof State
*/
async addTask(task) {
const state = this
await this.pipeline.executeTask(task, state)
}
/**
*
*
* @param {any} fn

@@ -43,7 +74,8 @@ * @memberof Parent

try {
await fn(new State(child, this.parentTask, this.pipeline))
await fn(new State(child, this.task, this.pipeline))
} catch (err) {
debug(
'Task <%s> execute rollback routines cause (Job) error',
this.parentTask.name
'Task <%s:%s> execute rollback routines cause (Job) error',
this.task.constructor.name,
this.task.name
)

@@ -56,4 +88,5 @@

error(
'Task <%s> error during (Job) rollback routine',
this.parentTask.name
'Task <%s:%s> error during (Job) rollback routine',
this.task.constructor.name,
this.task.name
)

@@ -60,0 +93,0 @@ }

@@ -43,3 +43,5 @@ 'use strict'

*/
validateConfig() {}
validateConfig(value) {
return value
}
/**

@@ -64,8 +66,16 @@ *

if (result.error) {
error(`Invalid config schema. Task "${this.name}"`)
throw result.error
if (result) {
if (result.error) {
error(
'Task <%s:%s> Invalid config schema',
this.constructor.name,
this.name
)
throw result.error
} else if (result.value) {
this.config = result.value
} else {
this.config = config
}
}
this.config = result.value
}

@@ -84,3 +94,4 @@

throw new TypeError(
`Action handler must be a function. Task "${this.name}"`
`Task <${this.constructor.name}:${this
.name}> Action handler must be a function`
)

@@ -103,4 +114,4 @@ }

throw new TypeError(
`Hook handler of must be a function or Task instance. Task "${this
.name}"`
`Task <${this.constructor.name}:${this
.name}> Hook handler of must be a function or Task instance`
)

@@ -110,3 +121,6 @@ }

if (supportedHooks.indexOf(name) === -1) {
throw new Error(`Hook not supported! Task "${this.name}"`)
throw new TypeError(
`Task <${this.constructor.name}:${this
.name}> Hook "${name}" not supported!`
)
}

@@ -127,3 +141,6 @@

if (typeof this.action !== 'function') {
throw new TypeError(`Action must be a function. Task "${this.name}"`)
throw new TypeError(
`Task <${this.constructor.name}:${this
.name}> Action must be a function. Actual ${typeof this.action}`
)
}

@@ -144,6 +161,11 @@

if (supportedHooks.indexOf(name) === -1) {
throw new Error(`${name} hook not supported!`)
throw new TypeError(
`Task <${this.constructor.name}:${this
.name}> Hook "${name}" not supported!`
)
}
debug(`Task <${this.name}> execute ${name} hooks`)
debug(
`Task <${this.constructor.name}:${this.name}> execute "${name}" hooks`
)

@@ -153,3 +175,3 @@ for (let hook of this[name]) {

if (hook instanceof Task) {
await state.pipeline.bootSubTask(hook, state)
await state.addTask(hook, state)
} else {

@@ -167,3 +189,5 @@ await hook.call(this, state)

async rollback(err) {
debug(`Task <${this.name}> execute rollback routines`)
debug(
`Task <${this.constructor.name}:${this.name}> execute rollback routines`
)

@@ -170,0 +194,0 @@ for (let hook of this.onError) {

{
"name": "bootme",
"version": "0.0.14",
"version": "0.0.16",
"description": "",
"main": "index.js",
"scripts": {
"test": "tap test/*.test.js test/*/*.test.js"
"test": "tap -j4 \"test/*.test.js\" \"test/*/*.test.js\""
},

@@ -21,4 +21,2 @@ "repository": {

"debug": "^3.1.0",
"hoek": "^5.0.2",
"joi": "^13.0.1",
"workq": "^1.1.1"

@@ -25,0 +23,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc