
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
colt()
.createUser('marc', {email: 'marc@livingdocs.io', name: 'Marc Bachmann'})
.createDocumentForUser('document', 'marc', {title: 'Foobar'})
.fire(function done (err, resInCallback) {
// resInCallback equals resAsReturn
// resAsReturn.user equals {id: 1, name: 'Marc Bachmann', ema...}
})
var colt = require('colt')
Is a colt api instance
Creates a new colt api instance
Extends colt1 with all the methods from colt2
Returns a new colt api instance with all the methods from colt
Is used to register a method, content contains a name and a value object.
Returns an object which contains all colt methods you registered
yourMethodName
is the name of a method you registered using colt.register
Are methods which accept a node type callback callback(err, res)
res
contains all values which get populated during the execution
// Register methods
var colt = require('colt').forge()
colt.register('set', function (content) {
return content.value
})
colt.register('createUser', function (content, callback) {
request.post('/users', function (err, user) { callback(err, user) })
})
colt.register({name: 'createDocumentForUser', evaluate: false}, function (content, callback) {
var data = _.extend(content.args[1], {user_id: this[content.args[0]].id })
request.post('/documents', data, function (err, document) {
callback(err, document)
})
})
// The main module returns a colt api instance
// If you register methods on this instance, they will be global
// and will be returned if you require colt.
var colt = require('colt')
colt.load('methodName', function (content[, callback]){
// content = {name: 'valueKey', value: value}
})
// create a new instance
var chain = colt.forge()
// Or clone an instance
chain = colt.clone()
// You can use .mixin to inherit from specific colt instances
chain.mixin(colt)
chain.load('set', function (content) { callback(null, content.value) })
// Execute a registered method
var res = chain().set('user', {id: 1}).exec(callback)
function callback (err) {
if (err) throw err
// res.user is the result of the method defined in chain.load('set', ...
}
// exit
chain.exec(callback)
chain.fire(callback)
chain.end(callback)
describe 'User api:', ->
// Colt version
before (done) ->
@res = colt()
.createUser('normalUser')
.createUser('adminUser', {admin: true})
.createDocumentForUser('document', 'normalUser', {title: 'Foobar'})
.end(done)
// What this would look like with async.js
// This structures get really complex if you want
// to create relations and depend on previous results
before (done) ->
async.series
normalUser: (done) =>
userSupport.createUser (err, user) =>
@_userId = user.id
done(err, user)
document: (done) ->
userSupport.createDocument({
title: 'Foobar',
user_id: @_userId
}, done)
adminUser: (done) -> userSupport.createUser({admin: true}, done)
, (err, res) =>
@res = res
done(err)
it 'requires admin access to access users endpoint', (done) ->
request.get('/users')
.withUser(@res.normalUser)
.expect(401)
.end(done)
it 'allows admins to access the page', (done) ->
request.get('/users')
.withUser(@res.adminUser)
.expect(200)
.end(done)
FAQs
A sequencing library with a chainable api
The npm package colt receives a total of 907 weekly downloads. As such, colt popularity was classified as not popular.
We found that colt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.