
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Beads is a Koa like, general purpose middleware layer for nodejs.
app.when(function *() {
return isReady;
}).use(function *(next) {
// do sth
yield next;
// do sth later
});
// will be fired as soon as possible
app.use(function *(next) {
// do sth
yield next;
// do sth later
});
// add wrap for middleware (adding logger, and log BEGIN and END)
var wrap = function(middleware) {
return function *(_next) {
this.logger = require("log4js").getLogger('YOUR MIDDLEWARE NAME');
this.logger.debug('BEGIN');
var next = function *() {
yield _next;
this.logger = require("log4js").getLogger('YOUR MIDDLEWARE NAME');
}
yield middleware.call(this, next);
this.logger.debug('END');
};
};
app.wrap(wrap).when(function *() {
return isReady;
}).use(function *(next) {
// do sth
yield next;
// do sth later
});
Simple dependency resolution system
Use app.when. See the example below.
Dependency Test -> Functions whose dependency was satisfied -> RUN those functions one by one -> Dependency Test
Shared context among middlewares
Use co
and generators
for middlewares
var context = {};
var app = new (require("../index.js"))(context);
app.use(function *(next) {
console.log("set mark1!");
this.mark1 = true;
yield next;
});
app.when(function *() {
return this.mark1;
}).use(function *(next) {
console.log("mark1 set, set mark2!");
this.mark2 = true;
yield next;
});
app.when(function *() {
return this.mark2;
}).use(function *(next) {
console.log("mark2 set!");
yield next;
});
app.when(function *() {
return this.mark1;
}).use(function *(next) {
console.log("mark1 set!");
yield next;
});
app.use(function *(next){
var start = new Date;
console.log("timer start");
yield next;
var t = new Date - start;
console.log("timer end");
console.log(t + "ms");
});
app.run(function(err, context) {
console.log("Output Context: " + JSON.stringify(context));
});
The output:
set mark1!
timer start
mark1 set, set mark2!
mark1 set!
mark2 set!
Output Context: {"mark1":true,"mark2":true}
timer end
2ms
$ npm install beads
You can use the --harmony
flag when using node 0.11+.
Or, you can use gnode if you are using node 0.10 or below.
Because sometimes you may want to add wrapper for some middleware, add logger or profile. So it's useful to have app.wrap.
You can't use yield inside a regular function!
http://stackoverflow.com/questions/20834113/syntaxerror-unexpected-identifier-generators-in-es6
每次依赖条件已解决,执行一批插件。
插件 A, B 依赖于条件1,插件 C, D 依赖于条件2。
B中会解决条件2。
那么A, B的顺序不确定,但是A, B都先于C, D执行。
如果不是成批执行,
若定义顺序为 B C D A 则实际运行顺序为
B C D A,A的条件本早已满足,却在最后被执行了。
为此依赖必须单独与函数体存在。
否则在执行函数前无法知道依赖是否满足,
但是执行函数可能改变依赖条件,
这样就无法实现无损的依赖判断。
FAQs
beads
The npm package beads receives a total of 1 weekly downloads. As such, beads popularity was classified as not popular.
We found that beads 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.