
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Cofy is a bridge connecting callback style object to sequential style in co environment with one punch.
Cofy is a bridge connecting callback style object to sequential style in co or koa environment with one punch.
##Installation
$ npm install cofy --save
use cofy in redis.
'use strict';
var co = require("co");
var cofy = require("cofy");
var redis = require('redis');
//enable redis to has a co ablitiy.
cofy.class(redis.RedisClient);
//now we can use mysql in co
var client = redis.createClient(6379,'localhost');
co(function * () {
//use class.$fn
var r1 = yield client.$set('a' ,1);
var r2 = yield client.$get('a');
var r3 = yield client.$hmset('h' , {k1:'v1' , k2:'v2'});
var r4 = yield client.$hget('h' ,'k1');
console.log(r1,r2);
console.log(r3,r4);
})();
use cofy in mysql.
'use strict';
var co = require("co");
var cofy = require("cofy");
var mysql = require('mysql');
//(felixge/node-mysql) has no extends entrance. so we can do this.
var PoolConnection = require('mysql/lib/PoolConnection.js');
var Pool = require('mysql/lib/Pool.js');
var PoolCluster = require('mysql/lib/PoolCluster.js');
//enable mysql to has a co ablitiy.
cofy.class(PoolConnection);
cofy.class(Pool);
cofy.class(PoolCluster);
var pool = mysql.createPool({
host: "localhost",
database: "db",
user: "root",
password: "pass",
});
//now we can use mysql in co
co(function * () {
var con = yield pool.$getConnection();
//pay attention on precedence of operator! yield < [] .
var result = (yield con.$query("select 1+1"))[0];
console.log(result);
con.release();
})();
//use it in transaction
co(function*(){
var con ;
try{
con = yield pool.$getConnection();
yield con.$beginTransaction();
yield con.$query("select some");
yield con.$query("insert some");
yield con.$query("update some");
yield con.$commit();
}catch(e){
yield con.$rollback();
console.error(e);
//to do
}finally{
if(con){
con.release();
}
}
})();
use cofy in request.
'use strict';
var request = require('request');
var cofy = require('cofy');
var co = require('co');
var $request = cofy.fn(request);
co(function*(){
var r = yield $request({url:"http://www.google.com"});
console.log(r);
})();
cofy nodejs fs api:
'use strict';
var cofy = require('../');
var co = require('co');
var fs = require('fs');
cofy(fs);
//fs.exists callback function has no error. we call set `throwable` to false.
fs.$exists = cofy.object(fs.exists , false ,fs);
co(function*(){
var file = '/hello.txt';
if(!(yield fs.$exists(file))){
return;
}
var r = yield fs.$readFile(file,'utf8');
console.log('fda' , r);
//also you can use it in old way
fs.readFile(file , 'utf8' , function(e,r){
if(e){
throw e;
}
console.log(r);
});
})();
Enalbe a class or a object or a function to has co ability.
constructor {function} - cofy target.the constructor of the class;throwable {bool} - if throwable is true the first argument of callback function arguments will be deemed as a exception.if throwable is false,no exception will be throwed ,all arguments will be returned. default is true.methods {array} - Array,if exists ,cofy will only cofy the methods in the target.prefix {string} - cofy will add function to the target(except target is function),the function name has a prefix. default is $.object {function} - cofy target.the constructor of the class;throwable {bool} - if throwable is true the first argument of callback function arguments will be deemed as a exception.if throwable is false,no exception will be throwed ,all arguments will be returned. default is true.context {object} - the function execute context.methods {array} - Array,if exists ,cofy will only cofy the methods in the target.prefix {string} - cofy will add function to the target(except target is function),the function name has a prefix. default is $.fn {function} - cofy a function; function(args , cb) -> yeild function(args)throwable {bool} - if throwable is true the first argument of callback function arguments will be deemed as a exception.if throwable is false,no exception will be throwed ,all arguments will be returned. default is true.context {object} - the function execute context.FAQs
Cofy is a bridge connecting callback style object to sequential style in co environment with one punch.
We found that cofy 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.