Comparing version 0.5.2 to 0.5.3
/* Copyright (c) 2010-2013 Ricebridge */ | ||
"use strict"; | ||
// FIX: this file is an anti-pattern | ||
// NOTE: make these dependencies lazy? | ||
@@ -142,2 +144,6 @@ var assert = exports.assert = require('assert') | ||
if( obj ) { | ||
if( obj.entity$ ) { | ||
return obj.toString() | ||
} | ||
var isarr = _.isArray(obj) | ||
@@ -144,0 +150,0 @@ var sb = [ isarr?'[':'{' ] |
@@ -34,3 +34,6 @@ /* Copyright (c) 2010-2012 Richard Rodger */ | ||
// use as a quick test to identify Entity objects | ||
self.entity$ = true | ||
// args: (<zone>,<base>,<name>,<props>) | ||
@@ -178,3 +181,3 @@ // can be partially specified: | ||
// data = object, or true|undef = include $, fale = exclude $ | ||
// data = object, or true|undef = include $, false = exclude $ | ||
self.data$ = function(data) { | ||
@@ -188,2 +191,4 @@ if( _.isObject(data) ) { | ||
} | ||
return self | ||
} | ||
@@ -208,15 +213,24 @@ else { | ||
self.toString = function() { | ||
var sb = [self.canon$().join('/'),':{']; | ||
var hasp = 0; | ||
var fields = self.fields$(); | ||
fields.sort(); | ||
var sb = [self.canon$().join('/'),':{id=',self.id,';'] | ||
var hasp = 0 | ||
var fields = self.fields$() | ||
fields.sort() | ||
for( var fI = 0; fI < fields.length; fI++ ) { | ||
hasp = 1; | ||
sb.push(fields[fI]); | ||
sb.push('='); | ||
sb.push(self[fields[fI]]); | ||
sb.push(';'); | ||
if( 'id' == fields[fI] ) continue; | ||
hasp = 1 | ||
sb.push(fields[fI]) | ||
sb.push('=') | ||
if( _.isDate(self[fields[fI]]) ) { | ||
sb.push( self[fields[fI]].toISOString() ) | ||
} | ||
else { | ||
sb.push(self[fields[fI]]) | ||
} | ||
sb.push(';') | ||
} | ||
sb[sb.length-hasp]='}'; | ||
return sb.join(''); | ||
sb[sb.length-hasp]='}' | ||
return sb.join('') | ||
} | ||
@@ -223,0 +237,0 @@ |
@@ -334,3 +334,2 @@ | ||
var re = new RegExp('^' + path + '$', 'i'); | ||
//console.log(re) | ||
return re | ||
@@ -337,0 +336,0 @@ } |
@@ -251,3 +251,2 @@ /* Copyright (c) 2013 Richard Rodger */ | ||
return function() { | ||
//console.log('LOG makelogger:'+common.arrayify(arguments)) | ||
var args = common.arrayify(arguments) | ||
@@ -268,3 +267,2 @@ args.unshift(level) | ||
var makelog = exports.makelog = function( logrouter ) { | ||
//console.log(logrouter.toString()) | ||
@@ -285,5 +283,3 @@ var log = function(level,type) { | ||
var handler = logrouter.find(routing) | ||
//console.log(util.inspect(routing)+' -> '+!!handler) | ||
if( handler ) { | ||
@@ -345,3 +341,8 @@ if( _.isFunction(args[args.length-1]) ) { | ||
else if( keys[key] ) { | ||
entry[key]=kv[1] | ||
if( entry[key] ) { | ||
entry[key] += ','+kv[1] | ||
} | ||
else { | ||
entry[key]=kv[1] | ||
} | ||
} | ||
@@ -348,0 +349,0 @@ } |
@@ -122,59 +122,6 @@ /* Copyright (c) 2012 Richard Rodger */ | ||
/* | ||
self.findall = function( pat ) { | ||
function descend(parentkey,keymap,match,checkkeys,acc) { | ||
//console.log('descend:'+parentkey+' keymap='+_.keys(keymap)+' match:'+JSON.stringify(match)+' checkkeys='+_.keys(checkkeys)) | ||
delete checkkeys[parentkey] | ||
var key = keymap.k | ||
var found = false | ||
var val = pat[key] | ||
var valmap = keymap.v | ||
if( val && valmap ) { | ||
var gexval = gex(val) | ||
var found = false | ||
for( var v in valmap ) { | ||
if( gexval.on(v) ) { | ||
found = true | ||
var newmatch = _.extend({},match) | ||
newmatch[key]=v | ||
var newcheckkeys = _.extend({},checkkeys) | ||
newcheckkeys[key]=1 | ||
descend( key, valmap[v], newmatch, newcheckkeys, acc ) | ||
} | ||
} | ||
if( !found && valmap[''] ) { | ||
descend( key, valmap[''], _.extend({},match), _.extend({},checkkeys), acc ) | ||
} | ||
} | ||
if( 0 == _.keys(checkkeys).length ) { | ||
//console.log('found:'+JSON.stringify(match)) | ||
acc.push({match:match,data:keymap.d}) | ||
} | ||
} | ||
var acc = [] | ||
descend('',top,{},_.extend({},pat),acc) | ||
return acc | ||
} | ||
*/ | ||
// values can be veratim, glob, or array of globs | ||
self.findall = function( pat ) { | ||
//console.log('findall') | ||
//console.dir(pat) | ||
function descend(keymap,match,missing,acc) { | ||
//console.log('\ndescend',[keymap,match,acc]) | ||
@@ -186,4 +133,2 @@ if( keymap.v ) { | ||
for( var val in keymap.v ) { | ||
//console.log('key='+key+' pat='+pat[key]+' '+val+':'+gexval.on(val)) | ||
var itermatch = _.extend({},match) | ||
@@ -198,3 +143,2 @@ var itermissing = _.extend({},missing) | ||
//console.log( 'mlen='+(_.keys(itermissing).length) + 'nkm:'+JSON.stringify(nextkeymap) ) | ||
if( 0 == _.keys(itermissing).length && nextkeymap && nextkeymap.d ) { | ||
@@ -211,3 +155,2 @@ acc.push({match:itermatch,data:nextkeymap.d}) | ||
if( nextkeymap ) { | ||
//console.log('nomatch descend') | ||
descend(nextkeymap, _.extend({},itermatch), _.extend({},itermissing), acc) | ||
@@ -214,0 +157,0 @@ } |
@@ -34,3 +34,5 @@ /* Copyright (c) 2010-2013 Richard Rodger */ | ||
var argsparser = require('./argsparser') | ||
// default plugins | ||
@@ -169,2 +171,7 @@ var connect_plugin = require('../plugin/connect') | ||
try { | ||
if( ~name.indexOf('..') || ~name.indexOf('/') ) { | ||
// yes, control flow. I will burn in Hell. | ||
throw new Error("not a built-in: '"+name+"', [SKIP]") | ||
} | ||
var builtin_path = '../plugin/'+name | ||
@@ -177,3 +184,3 @@ plugindesc.searched_paths.push(builtin_path) | ||
catch(e) { | ||
if( e.message && -1 != e.message.indexOf("'"+builtin_path+"'") ) { | ||
if( e.message && ( -1 != e.message.indexOf("'"+builtin_path+"'") || ~e.message.indexOf('[SKIP]')) ) { | ||
var use_require = opts.require || module.parent.require || require | ||
@@ -224,3 +231,3 @@ | ||
var self = new events.EventEmitter() | ||
self.version = '0.5.2' | ||
self.version = '0.5.3' | ||
self.id = nid() | ||
@@ -230,2 +237,7 @@ | ||
opts = deepextend({ | ||
status_interval: 60000 | ||
},opts) | ||
// legacy api | ||
@@ -250,3 +262,3 @@ if( 'print'==opts.log ) { | ||
opts.log.map = [ | ||
{level:'info',type:'init,status',handler:'print'}, | ||
{level:'info',type:'hello,status',handler:'print'}, | ||
{level:'error',handler:'print'} | ||
@@ -262,2 +274,3 @@ ] | ||
$.plugins = {} | ||
@@ -391,6 +404,9 @@ $.services = [] | ||
self.act({role:'config',cmd:'get',base:fullname,default$:{}},self.err(cbfunc,function(fullname_config){ | ||
self.act({role:'config',cmd:'get',base:plugin.name,default$:{}},self.err(cbfunc,function(name_config){ | ||
var opts = _.extend({},name_config,fullname_config,plugin.opts||{}) | ||
do_register(opts) | ||
})) | ||
if( fullname != plugin.name ) { | ||
self.act({role:'config',cmd:'get',base:plugin.name,default$:{}},self.err(cbfunc,function(name_config){ | ||
var opts = _.extend({},name_config,fullname_config,plugin.opts||{}) | ||
do_register(opts) | ||
})) | ||
} | ||
else return do_register( _.extend({},fullname_config,plugin.opts||{}) ) | ||
})) | ||
@@ -451,3 +467,3 @@ | ||
// FIX: probably does not work | ||
self.result = function(cb,win){ | ||
@@ -636,3 +652,3 @@ if( !_.isFunction(cb) ) throw self.fail({code:'seneca/result_handler_no_callback_function'}) | ||
function makedispatch(act,handlerspec,opts) { | ||
function makedispatch(act,handlerspec) {//,opts) { | ||
return function( req, res, next ) { | ||
@@ -655,5 +671,6 @@ | ||
if( handlerspec.redirect && 'application/x-www-form-urlencoded' == req.headers['content-type']) { | ||
handlerspec.responder = function(req,res,err,obj) { | ||
handlerspec.responder = function(req,res,handlerspec,err,obj) { | ||
// TODO: put obj into engagement if present | ||
@@ -674,3 +691,3 @@ var url = handlerspec.redirect | ||
handler( req, res, args, act, responder) | ||
handler( req, res, args, act, responder, handlerspec) | ||
} | ||
@@ -680,6 +697,7 @@ } | ||
function defaulthandler(req,res,args,act,responder) { | ||
function defaulthandler(req,res,args,act,responder,handlerspec) { | ||
var si = req.seneca || instance | ||
act.call(si,args,function(){ | ||
var responder_args = arrayify(arguments) | ||
responder_args.unshift(handlerspec) | ||
responder_args.unshift(res) | ||
@@ -693,4 +711,36 @@ responder_args.unshift(req) | ||
function defaultresponder(req,res,err,obj) { | ||
var objstr = err ? JSON.stringify({error:''+err}) : safe_json_stringify(obj) | ||
function defaultresponder(req,res,handlerspec,err,obj) { | ||
var outobj = _.clone(obj) | ||
// TODO: test filtering | ||
var remove_dollar = false | ||
if( !_.isUndefined(handlerspec.filter) ) { | ||
if( _.isFunction( handlerspec.filter ) ) { | ||
outobj = handlerspec.filter(outobj) | ||
} | ||
else if( _.isArray( handlerspec.filter ) ) { | ||
_.each(handlerspec.filter,function(p){ | ||
delete outobj[p] | ||
remove_dollar = remove_dollar || '$'==p | ||
}) | ||
} | ||
} | ||
// default filter | ||
// removes $ from entity objects | ||
else { | ||
remove_dollar = true | ||
} | ||
if( remove_dollar ) { | ||
_.keys(outobj,function(k){ | ||
if(~k.indexOf('$')){ | ||
delete outobj[k] | ||
} | ||
}) | ||
} | ||
var objstr = err ? JSON.stringify({error:''+err}) : safe_json_stringify(outobj) | ||
var code = err ? 500 : 200; | ||
@@ -715,3 +765,3 @@ | ||
var urlspec = spec.map[fname] | ||
var urlspec = spec.map.hasOwnProperty(fname) ? spec.map[fname] : null | ||
if( !urlspec ) continue; | ||
@@ -733,6 +783,7 @@ | ||
handlerspec.handler = handlerspec.handler || (_.isFunction(handler) ? handler : defaulthandler) | ||
var dispatch = makedispatch(act,handlerspec,{auth:urlspec.auth}) | ||
var dispatch = makedispatch(act,handlerspec)//,{auth:urlspec.auth}) | ||
var fullurl = url+urlspec.suffix | ||
self.log.debug('http',m,fullurl) | ||
http[m](fullurl, dispatch) | ||
mC++ | ||
} | ||
@@ -742,4 +793,5 @@ } | ||
if( 0 == mC ) { | ||
var dispatch = makedispatch(act,defaulthandler,{auth:urlspec.auth}) | ||
var dispatch = makedispatch(act,defaulthandler)//,{auth:urlspec.auth}) | ||
var fullurl = url+urlspec.suffix | ||
self.log.debug('http','get',fullurl) | ||
http.get(fullurl, dispatch) | ||
@@ -781,2 +833,4 @@ } | ||
self.pin = function( pattern, pinopts ) { | ||
var thispin = this | ||
var methodkeys = [] | ||
@@ -793,3 +847,3 @@ for( var key in pattern ) { | ||
var api = {toString:function(){return 'api'}} | ||
var api = {toString:function(){return 'pin:'+descdata(pattern,1)+'/'+thispin}} | ||
@@ -808,4 +862,5 @@ //for( var mI = 0; mI < methods.length; mI++ ) { | ||
api[methodname] = function(args,cb) { | ||
var si = this && this.seneca ? this : thispin | ||
var fullargs = _.extend({},args,mpat) | ||
self.act.call(this,fullargs,cb) | ||
si.act.call(si,fullargs,cb) | ||
} | ||
@@ -818,4 +873,4 @@ }) | ||
var methodname = pinopts.include[i] | ||
if( self[methodname] ) { | ||
api[methodname] = common.delegate(self,self[methodname]) | ||
if( thispin[methodname] ) { | ||
api[methodname] = common.delegate(thispin,thispin[methodname]) | ||
} | ||
@@ -850,3 +905,3 @@ } | ||
var addroute = true | ||
var parent = self.findact(args) | ||
var parent = findact(args) | ||
@@ -893,4 +948,3 @@ if( parent ) { | ||
// TODO: make private, as actfunc should not be called outside of seneca.act() | ||
self.findact = function(args) { | ||
function findact(args) { | ||
var actfunc = $.actrouter.find(args) | ||
@@ -905,10 +959,21 @@ return actfunc | ||
self.pinact = function(pattern) { | ||
return _.map( $.actrouter.findall(pattern), function(desc) {return desc.match} ) | ||
} | ||
function do_act(instance,actfunc,isparent,args,cb){ | ||
function do_act(instance,actfunc,isparent,origargs,cb){ | ||
var act_start = new Date().getTime() | ||
if( !_.isFunction(cb) ) { | ||
throw new Error('not a func') | ||
throw self.fail({code:'seneca/act_no_callback',args:origargs}) | ||
} | ||
if( !_.isObject(origargs) ) { | ||
throw self.fail({code:'seneca/act_no_args'}) | ||
} | ||
var args = _.clone(origargs) | ||
// FIX: make this error nice to handle for calling code - git rid of circular ref | ||
@@ -942,3 +1007,2 @@ if( actfunc.parambulator ) { | ||
// automate actid log insertion | ||
delegate.log = function() { | ||
@@ -970,2 +1034,3 @@ var args = arrayify(arguments) | ||
$.stats.act.called++ | ||
actfunc.call(delegate,callargs,function(err){ | ||
@@ -975,2 +1040,3 @@ var args = arrayify(arguments) | ||
if( err ) { | ||
$.stats.act.failed++ | ||
instance.log.error('act','err',actid,err.message,stackfirst(err) ) | ||
@@ -998,2 +1064,3 @@ | ||
$.stats.act.completed++ | ||
cb.apply(isparent?instance:delegate,args) | ||
@@ -1006,2 +1073,3 @@ } | ||
$.stats.act.failed++ | ||
self.log.error('act','err',actid, error.message, stackfirst(error) ) | ||
@@ -1014,7 +1082,32 @@ throw instance.fail( descerror({code:'seneca/act_error',args:args},error) ) | ||
self.act = function(args,cb) { | ||
cb = cb || noop | ||
function handle_act_args(orig) { | ||
var args,cb | ||
if( _.isString(orig[0]) ) { | ||
try { | ||
cb = _.isFunction(orig[2]) ? orig[2] : _.isFunction(orig[1]) ? orig[1] : noop | ||
var argsobj = _.isObject(orig[1]) ? orig[1] : {} | ||
args = _.extend({},argsobj,argsparser.parse(orig[0])) | ||
} | ||
catch( e ) { | ||
throw self.fail({code:'seneca/string-args-syntax-error',argstr:orig[0],args:orig[1]}) | ||
} | ||
} | ||
else { | ||
cb = _.isFunction(orig[1]) ? orig[1] : _.isFunction(orig[0]) ? orig[0] : noop | ||
args = _.extend({},_.isObject(orig[0])) ? orig[0] : {} | ||
} | ||
return [args,cb] | ||
} | ||
self.act = function() { | ||
var argscb = handle_act_args(arrayify(arguments)) | ||
var args = argscb[0] | ||
var cb = argscb[1] | ||
var instance = this && this.seneca ? this : self | ||
var actfunc = instance.findact(args) | ||
var actfunc = findact(args) | ||
@@ -1036,2 +1129,11 @@ if( !actfunc ) { | ||
self.wrap = function(pin,wrapper){ | ||
var pinthis = this || self | ||
_.each( pinthis.pinact(pin), function(actpattern){ | ||
//console.log('WRAP '+util.inspect(actpattern)) | ||
pinthis.add(actpattern,function(args,done){ | ||
wrapper.call(this,args,done) | ||
}) | ||
}) | ||
} | ||
@@ -1077,3 +1179,3 @@ | ||
plugindesc.opts = _.extend(plugindesc.opts,plugin_opts||{}) | ||
plugindesc.opts = _.extend(plugindesc.opts||{},plugin_opts||{}) | ||
@@ -1148,3 +1250,26 @@ resolve_plugin(plugindesc,self,opts) | ||
// loop over a list of items recursively | ||
function recurse(list,work,done) { | ||
var ctxt = this | ||
list = _.clone(list) | ||
//console.log('RECURSE:'+list) | ||
function next(err,out){ | ||
if( err ) return done(err,out); | ||
var item = list.shift() | ||
//console.log('RECUR:'+item) | ||
if( item ) { | ||
work.call(ctxt,item,next) | ||
} | ||
else { | ||
done.call(ctxt,err,out) | ||
} | ||
} | ||
next.call(ctxt) | ||
} | ||
function deepextend(tar) { | ||
@@ -1171,4 +1296,19 @@ _.each(Array.prototype.slice.call(arguments, 1), function(src) { | ||
// remove any props containing $ | ||
function clean(obj) { | ||
if( obj ) { | ||
for( var p in obj ) { | ||
if( ~p.indexOf('$') ) { | ||
delete obj[p] | ||
} | ||
} | ||
} | ||
return obj | ||
} | ||
self.util = { | ||
deepextend: deepextend, | ||
recurse: recurse, | ||
clean: clean, | ||
copydata: common.copydata, | ||
@@ -1184,65 +1324,16 @@ } | ||
self.delegate = function(fixedargs) { | ||
/* | ||
var delegate = { | ||
version: self.version, | ||
var self = this | ||
register: common.delegate(self,self.register), | ||
log: common.delegate(self,self.log), | ||
logroute: common.delegate(self,self.logroute), | ||
make: common.delegate(self,self.make), | ||
service: common.delegate(self,self.service), | ||
plugin: common.delegate(self,self.plugin), | ||
api: common.delegate(self,self.api), | ||
add: common.delegate(self,self.add), | ||
findact: common.delegate(self,self.findact), | ||
hasact: common.delegate(self,self.hasact), | ||
close: common.delegate(self,self.close), | ||
pin: common.delegate(self,self.pin), | ||
use: common.delegate(self,self.use), | ||
err: common.delegate(self,self.err), | ||
http: common.delegate(self,self.http), | ||
httprouter: common.delegate(self,self.httprouter), | ||
inrepl: common.delegate(self,self.inrepl), | ||
startrepl: common.delegate(self,self.startrepl), | ||
ready: common.delegate(self,self.ready), | ||
seneca: common.delegate(self,self.seneca), | ||
fail: common.delegate(self,self.fail), | ||
result: common.delegate(self,self.result), | ||
compose: common.delegate(self,self.compose), | ||
var delegate = Object.create(self) | ||
var act = delegate.act | ||
util: self.util, | ||
store: self.store, | ||
delegate.act = function(){ | ||
var argscb = handle_act_args(arrayify(arguments)) | ||
loghandler: init.loghandler, | ||
module: init.module, | ||
test: init.test, | ||
} | ||
// can't override fixedargs | ||
var args = _.extend({},argscb[0],fixedargs) | ||
if( _.isObject(fixedargs) ) { | ||
delegate.act = common.delegate(self,function(args,cb){ | ||
// can't override | ||
var fullargs = _.extend({},args,fixedargs) | ||
return self.act(fullargs,cb) | ||
}) | ||
delegate.toString = common.delegate(self,function(){ | ||
return toString(common.owndesc(fixedargs,1,true)) | ||
}) | ||
} | ||
else { | ||
delegate.act = common.delegate(self,self.act) | ||
delegate.toString = common.delegate(self,self.toString) | ||
} | ||
var cb = argscb[1] | ||
*/ | ||
var self = this | ||
var delegate = Object.create(self) | ||
var act = delegate.act | ||
delegate.act = function(args,cb){ | ||
// can't override | ||
var fullargs = _.extend({},args,fixedargs) | ||
return act.call(this,fullargs,cb) | ||
return act.call(this,args,cb) | ||
} | ||
@@ -1287,2 +1378,5 @@ | ||
} | ||
else if( _.isObject(data) && data.entity$ ) { | ||
return data.toString() | ||
} | ||
else { | ||
@@ -1325,3 +1419,8 @@ if( data.seneca && data.seneca.nodesc ) return '[skipping...]'; | ||
// private context | ||
var $ = {} | ||
var $ = { | ||
stats:{ | ||
start:new Date().getTime(), | ||
act:{called:0,completed:0,failed:0} | ||
} | ||
} | ||
@@ -1331,4 +1430,4 @@ | ||
var seneca = new Seneca($,opts) | ||
seneca.log.info('init','start') | ||
$.pushready('init') | ||
@@ -1338,5 +1437,18 @@ | ||
try { | ||
seneca.log.info('init','end') | ||
seneca.log.info('init','wait') | ||
$.whenready(function(){ | ||
// opts.status_log has precendence | ||
// if not defined, run status log if there are services | ||
var status_log = !_.isUndefined(opts.status_log) ? opts.status_log : 0 < $.services.length | ||
if( status_log && 0 < opts.status_interval ) { | ||
setInterval(function(){ | ||
var stats = {alive:(new Date().getTime()-$.stats.start),act:$.stats.act} | ||
self.log.info('status',stats) | ||
},opts.status_interval) | ||
} | ||
seneca.log.info('init','end') | ||
seneca.log.info('hello',seneca.toString()) | ||
seneca.emit('ready',err,seneca) | ||
@@ -1435,4 +1547,4 @@ }) | ||
// plugin registration, args are actually si,opts,cb | ||
if( args[0] && args[0].seneca ) { | ||
// plugin registration, args are actually opts,cb, and this==seneca instance | ||
if( this && this.seneca ) { | ||
return plugin_func.apply(this,args) | ||
@@ -1442,3 +1554,3 @@ } | ||
// call require('pluginname')(pluginopts,senecaopts) | ||
var si = init(args[1]||{}) | ||
var si = init(args[1]||{log:{map:[]},status_interval:0}) | ||
si.use(plugin_func,args[0]||{}) | ||
@@ -1445,0 +1557,0 @@ return si.pin(pin,{include:['seneca']}) |
@@ -11,3 +11,23 @@ /* Copyright (c) 2012-2013 Richard Rodger, BSD License */ | ||
/* | ||
Standard meta-query parameters: | ||
sort$: {fieldname: +/-1}; sort by single fieldname, -1 => descending, +1 => ascending | ||
limit$: size (integer); number of results to return | ||
skip$: size (integer); number of results to skip over | ||
fields$: array of field names to include | ||
these can all be used together | ||
native$: anything; pass value to database connection as store specific query | ||
everything else is ignored | ||
each store needs to document this value format | ||
TODO: custom ids - use id$ for custom id | ||
*/ | ||
/* opts.map = { canon: [cmds] } | ||
@@ -44,3 +64,3 @@ * opts.taglen = length of instance tag, default 3 | ||
var m = /^(\w*)\/(\w*)\/(\w*)$/.exec(entspec.canon) | ||
var name = m[3], base = m[2], tenant = m[1] | ||
var name = m[3], base = m[2], zone = m[1] | ||
@@ -52,3 +72,3 @@ // TODO: support base/name and name, error handling | ||
base && (entargs.base = base) | ||
tenant && (entargs.tenant = tenant) | ||
zone && (entargs.zone = zone) | ||
@@ -55,0 +75,0 @@ for( var cI = 0; cI < entspec.cmds.length; cI++ ) { |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "homepage": "https://senecajs.org", | ||
"underscore": "~1.4.2", | ||
"gex": "~0.0.3", | ||
"gex": "~0.1.1", | ||
"parambulator": "~0.1.1", | ||
@@ -42,3 +42,4 @@ "async": "~0.1.22", | ||
"chai": "~1.4.2", | ||
"nid": "~0.3.0" | ||
"nid": "~0.3.0", | ||
"pegjs": "~0.7.0" | ||
}, | ||
@@ -45,0 +46,0 @@ "main": "lib/seneca", |
@@ -14,14 +14,15 @@ /* Copyright (c) 2012-2013 Richard Rodger */ | ||
var config = {} | ||
var ref = {config:{}} | ||
if( opts.file ) { | ||
fs.readFile( opts.file, function(err,text){ | ||
if( err ) return cb(err); | ||
config = JSON.parse(text) | ||
cb() | ||
}) | ||
// TODO: need an async way to this | ||
//fs.readFile( opts.file, function(err,text){ | ||
//if( err ) return cb(err); | ||
var text = fs.readFileSync( opts.file ) | ||
ref.config = JSON.parse(text) | ||
cb() | ||
} | ||
else if( _.isObject(opts.object) ) { | ||
config = _.extend({},opts.object) | ||
ref.config = _.extend({},opts.object) | ||
@@ -32,5 +33,6 @@ cb() | ||
seneca.add({role:'config',cmd:'get'},function(args,cb){ | ||
var base = args.base || null | ||
var root = base ? (config[base]||{}) : config | ||
var root = base ? (ref.config[base]||{}) : ref.config | ||
var val = args.key ? root[args.key] : root | ||
@@ -37,0 +39,0 @@ |
@@ -34,2 +34,17 @@ /* Copyright (c) 2010-2013 Richard Rodger */ | ||
// sort first | ||
if( q.sort$ ) { | ||
for( var sf in q.sort$ ) break; | ||
var sd = q.sort$[sf] < 0 ? -1 : 1 | ||
list = list.sort(function(a,b){ | ||
return sd * ( a[sf] < b[sf] ? -1 : a[sf] === b[sf] ? 0 : 1 ) | ||
}) | ||
} | ||
if( q.skip$ ) { | ||
list = list.slice(q.skip$) | ||
} | ||
if( q.limit$ ) { | ||
@@ -39,7 +54,2 @@ list = list.slice(0,q.limit$) | ||
if( q.sort$ ) { | ||
list = list.sort(function(a,b){ | ||
return a[q.sort$] < b[q.sort$] ? -1 : a[q.sort$] === b[q.sort$] ? 0 : 1 | ||
}) | ||
} | ||
@@ -46,0 +56,0 @@ cb.call(si,null,list) |
@@ -6,2 +6,3 @@ /* Copyright (c) 2011-2013 Richard Rodger */ | ||
var fs = require('fs') | ||
var util = require('util') | ||
@@ -12,7 +13,8 @@ var nid = require('nid') | ||
module.exports = function(opts,cb) { | ||
module.exports = function(opts,register) { | ||
var name = 'util' | ||
var pluginseneca = this | ||
// legacy cmd | ||
this.add({role:name,cmd:'quickcode'},function(args,cb){ | ||
this.add({role:name,cmd:'quickcode'},function(args,done){ | ||
args.len = args.length || args.len | ||
@@ -30,3 +32,3 @@ var len = args.len ? parseInt(args.len,10) : 8 | ||
cb(null,actnid()) | ||
done(null,actnid()) | ||
}) | ||
@@ -39,3 +41,3 @@ | ||
// TODO: allow specials based on ent canon: name,base,zone props | ||
this.add({role:name,cmd:'generate_id'},function(args,cb){ | ||
this.add({role:name,cmd:'generate_id'},function(args,done){ | ||
var actnid, length = args.length || 6 | ||
@@ -49,9 +51,56 @@ if( length < 65 ) { | ||
cb(null,actnid()) | ||
done(null,actnid()) | ||
}) | ||
this.add( | ||
{role:name,cmd:'ensure_entity'}, | ||
{ required$:['pin','entmap'], | ||
pin:{type$:'object'}, | ||
entmap:{type$:'object'} }, | ||
function(args,done){ | ||
var entmap = args.entmap | ||
pluginseneca.wrap(args.pin,function(args,done){ | ||
var seneca = this | ||
seneca.util.recurse( | ||
_.keys(entmap), | ||
function(entarg,next){ | ||
//console.log('work entarg:'+entarg+' args:'+util.inspect(args)) | ||
// ent id | ||
if( _.isString(args[entarg]) ) { | ||
entmap[entarg].load$( args[entarg], function(err,ent){ | ||
if(err) return done(err) | ||
args[entarg]=ent | ||
return next(null,args) | ||
}) | ||
} | ||
// ent JSON - contains $:{name,base,zone} | ||
else if( _.isObject(args[entarg]) && args[entarg].$ ) { | ||
args[entarg] = entmap[entarg].make$(args[entarg]) | ||
return next(null,args) | ||
} | ||
else return next(null,args); | ||
}, | ||
function(err,args) { | ||
//console.log('done: '+util.inspect(args)) | ||
if( err ) return done(err); | ||
return seneca.parent(args,done) | ||
} | ||
) | ||
}) | ||
done() | ||
}) | ||
var browser_js | ||
cb(null,{ | ||
register(null,{ | ||
name:name, | ||
@@ -58,0 +107,0 @@ service: function(req,res,next) { |
{ | ||
"author": "", | ||
"name": "util", | ||
@@ -7,7 +6,4 @@ "description": "Seneca util", | ||
"main": "lib/util.js", | ||
"engines": { | ||
"node": "~0.4.12" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} |
@@ -16,3 +16,3 @@ # seneca - Node.js module | ||
Current Version: 0.5.2 | ||
Current Version: 0.5.3 | ||
@@ -19,0 +19,0 @@ Tested on: node 0.8.16 |
@@ -30,3 +30,3 @@ "use strict"; | ||
assert.equal(false, bar.bol) | ||
assert.equal(new Date(2020,1,1).toISOString(), bar.wen.toISOString()) | ||
assert.equal(new Date(2020,1,1).toISOString(), _.isDate(bar.wen) ? bar.wen.toISOString() : bar.wen ) | ||
@@ -277,2 +277,3 @@ assert.equal(''+[2,3],''+bar.arr) | ||
function retry(){ | ||
//console.log(testcount+' '+si.__testcount) | ||
if( testcount <= si.__testcount || retryCnt > RETRY_LIMIT ) { | ||
@@ -279,0 +280,0 @@ console.log('CLOSE') |
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
6004
472799
16
45
+ Addedpegjs@~0.7.0
+ Addedpegjs@0.7.0(transitive)
- Removedgex@0.0.3(transitive)
Updatedgex@~0.1.1