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

seneca

Package Overview
Dependencies
Maintainers
2
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seneca - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

68

lib/entity.js

@@ -34,4 +34,2 @@ /* Copyright (c) 2010-2012 Richard Rodger */

// use as a quick test to identify Entity objects
self.entity$ = true

@@ -48,2 +46,5 @@

self.make$ = function() {
var seneca_instance = (this && this.seneca) ? this : si
//console.log('entity.make '+seneca_instance)
var args = [].slice.call(arguments)

@@ -63,6 +64,17 @@

var name = args.pop() || props.name$
var base = args.pop() || props.base$
var zone = args.pop() || props.zone$
var name, base, zone
if( _.isString(props.entity$) ) {
var m = /\$?(\w+|-)\/(\w+|-)\/(\w+|-)/.exec(props.entity$)
if( m ) {
zone = '-' == m[1] ? void 0 : m[1]
base = '-' == m[2] ? void 0 : m[2]
name = '-' == m[3] ? void 0 : m[3]
}
}
name = args.pop() || props.name$
base = args.pop() || props.base$
zone = args.pop() || props.zone$
var new$ = {}

@@ -73,5 +85,6 @@ new$.name = name || $.name;

var entity = new Entity(new$,si);
var entity = new Entity(new$,seneca_instance);
for( var p in props ) {

@@ -163,23 +176,21 @@ if( props.hasOwnProperty(p) && '$'!=p.charAt(p.length-1) && '$'!=p.charAt(0) ) {

if( opt ) {
// change type
$.zone = opt.zone || $.zone
$.base = opt.base || $.base
$.name = opt.name || $.name
$.zone = void 0==opt.zone ? $.zone : opt.zone
$.base = void 0==opt.base ? $.base : opt.base
$.name = void 0==opt.name ? $.name : opt.name
}
return ( opt.string ? [$.zone,$.base,$.name].join('/')
: opt.array ? [$.zone,$.base,$.name]
: opt.object ? {zone:$.zone,base:$.base,name:$.name}
: [$.zone,$.base,$.name] )
}
else return [$.zone,$.base,$.name]
return ( void 0==opt || opt.string || opt.string$ ) ?
[ (opt&&opt.string$?'$':'')+
(void 0==$.zone?'-':$.zone),
void 0==$.base?'-':$.base,
void 0==$.name?'-':$.name].join('/')
: opt.array ? [$.zone,$.base,$.name]
: opt.array$ ? [$.zone,$.base,$.name]
: opt.object ? {zone:$.zone,base:$.base,name:$.name}
: opt.object$ ? {zone$:$.zone,base$:$.base,name$:$.name}
: [$.zone,$.base,$.name]
}
// TODO: remove
self.canonstr$ = function() {
return self.canon$().join('/')
}
// data = object, or true|undef = include $, false = exclude $

@@ -214,4 +225,9 @@ self.data$ = function(data) {

self.clone$ = function() {
return self.make$(self.data$())
}
self.toString = function() {
var sb = [self.canon$().join('/'),':{id=',self.id,';']
var sb = ['$',self.canon$({string:true}),':{id=',self.id,';']
var hasp = 0

@@ -241,2 +257,6 @@ var fields = self.fields$()

// use as a quick test to identify Entity objects
self.entity$ = self.canon$()
return self

@@ -246,2 +266,2 @@ }

exports.Entity = Entity;
exports.Entity = Entity;

@@ -1,2 +0,3 @@

/* Copyright (c) 2012 Richard Rodger */
/* Copyright (c) 2013 Richard Rodger */
"use strict";

@@ -54,3 +55,3 @@

if( data && keymap ) {
if( !_.isUndefined(data) && keymap ) {
keymap.d = data

@@ -115,6 +116,8 @@ }

if( data ) {
if( !_.isUndefined(data) ) {
//console.dir(path)
var part = path[path.length-1]
delete part.km.v[part.v]
if( part && part.km && part.km.v ) {
delete part.km.v[part.v]
}
}

@@ -166,6 +169,37 @@ }

self.toString = function() {
return util.inspect(top,false,null)
self.toString = function(dstr) {
dstr = _.isFunction(dstr) ? dstr : function(d){return '<'+d+'>'}
function indent(o,d) {
for(var i = 0; i < d; i++ ) {
o.push(' ')
}
}
function walk(n,o,d){
o.push('\n')
if( !_.isUndefined(n.d) ) {
indent(o,d)
o.push(dstr(n.d))
}
if( n.k ) {
indent(o,d)
o.push(n.k+':')
}
if( n.v ) {
d++
for( var p in n.v ) {
o.push('\n')
indent(o,d)
o.push((p||'*')+' ->')
walk(n.v[p],o,d+1)
}
}
}
var o = []
walk(top,o,0)
return o.join('')
}
self.toJSON = function(indent) {

@@ -182,2 +216,2 @@ return JSON.stringify(top,function(key,val){

exports.Router = Router
exports.Router = Router

@@ -5,3 +5,3 @@ /* Copyright (c) 2010-2013 Richard Rodger */

var VERSION = '0.5.5'
var VERSION = '0.5.6'

@@ -230,3 +230,9 @@ var common = require('./common')

var self = new events.EventEmitter()
function Seneca(){
events.EventEmitter.call(this)
}
util.inherits(Seneca, events.EventEmitter)
var self = new Seneca()
self.version = VERSION

@@ -390,9 +396,15 @@ self.id = nid()

sd.add = function(args,paramspec,actfunc) {
sd.add = function(args,paramspec,actfunc,actmeta) {
if( _.isFunction(paramspec) ) {
actmeta = actfunc || {}
actfunc = paramspec
paramspec = null
}
actfunc.plugin_nameref = nameref
actfunc.log = sd.log
self.add.call(sd,args,paramspec,actfunc)
else {
actmeta = actmeta || {}
}
actmeta.plugin_nameref = nameref
actmeta.log = sd.log
self.add.call(sd,args,paramspec,actfunc,actmeta)
}

@@ -591,3 +603,5 @@

self.make = function() {
return $.entity.make$.apply(self,arguments)
var si = (this && this.seneca) ? this : self
//console.log('make: '+si)
return $.entity.make$.apply(si,arguments)
}

@@ -649,3 +663,3 @@ self.make$ = self.make

function makedispatch(act,handlerspec) {//,opts) {
function makedispatch(act,handlerspec) {
return function( req, res, next ) {

@@ -687,3 +701,14 @@

handler( req, res, args, act, responder, handlerspec)
var si = req.seneca || instance
var respond = function(err,obj){
responder.call(si,req,res,handlerspec,err,obj)
}
var act_si = function(args,done){
act.call(si,args,done)
}
handler( req, res, args, act_si, respond, handlerspec)
}

@@ -693,2 +718,8 @@ }

function defaulthandler(req,res,args,act,respond) {
act(args,respond)
}
/*
function defaulthandler(req,res,args,act,responder,handlerspec) {

@@ -704,9 +735,9 @@ var si = req.seneca || instance

}
*/
function defaultresponder(req,res,handlerspec,err,obj) {
var outobj;
if (obj !== null && typeof obj === 'object') {
if( _.isObject(obj) ) {
outobj = _.clone(obj)

@@ -743,2 +774,5 @@

}
else if( _.isUndefined(obj) ) {
outobj = ''
}
else {

@@ -762,4 +796,2 @@ outobj = obj;

return httprouter(function(http){

@@ -787,3 +819,3 @@ for( var fname in pin ) {

handlerspec.handler = handlerspec.handler || (_.isFunction(handler) ? handler : defaulthandler)
var dispatch = makedispatch(act,handlerspec)//,{auth:urlspec.auth})
var dispatch = makedispatch(act,handlerspec)
var fullurl = url+urlspec.suffix

@@ -797,3 +829,3 @@ self.log.debug('http',m,fullurl)

if( 0 == mC ) {
var dispatch = makedispatch(act,defaulthandler)//,{auth:urlspec.auth})
var dispatch = makedispatch(act,defaulthandler)
var fullurl = url+urlspec.suffix

@@ -886,10 +918,13 @@ self.log.debug('http','get',fullurl)

self.add = function(args,paramspec,actfunc) {
self.add = function(args,paramspec,actfunc,actmeta) {
var pb
if( _.isFunction(paramspec) ) {
actmeta = actfunc || {}
actfunc = paramspec
}
else {
pb = parambulator(paramspec)
actmeta = actmeta || {}
if( _.isObject(paramspec) ) {
actmeta.parambulator = parambulator(paramspec)
}
}

@@ -901,23 +936,30 @@

actfunc.parambulator = pb
if( !_.isObject(actmeta) || _.isFunction(actmeta) ) {
throw self.fail({code:'seneca/actmeta_not_object',args:args})
}
self.log.info('add',args)
var addroute = true
var parent = findact(args)
var parentmeta = findact(args)
if( parent ) {
if( parent.handle ) {
parent.handle(actfunc)
if( parentmeta ) {
if( _.isFunction(parentmeta.handle) ) {
parentmeta.handle(actfunc)
addroute = false
}
else {
actfunc.parent = parent
actmeta.parentmeta = parentmeta
}
}
actfunc.argpattern = common.owndesc(args)
actmeta.argpattern = common.owndesc(args)
actmeta.id = nid()
actmeta.func = actfunc
if( addroute ) {
$.actrouter.add(args,actfunc)
var plugin_name = (actmeta.plugin_nameref && actmeta.plugin_nameref[0]) || '-'
var plugin_tag = (actmeta.plugin_nameref && actmeta.plugin_nameref[1]) || '-'
self.log.info('add',plugin_name,plugin_tag,args,actmeta.id)
$.actrouter.add(args,actmeta)
}

@@ -950,4 +992,4 @@ }

function findact(args) {
var actfunc = $.actrouter.find(args)
return actfunc
var actmeta = $.actrouter.find(args)
return actmeta
}

@@ -965,4 +1007,15 @@

self.actroutes = function(){
return $.actrouter.toString(function(d){
var s = 'F='+d.id
while( d.parentmeta ) {
d = d.parentmeta
s+=';'+d.id
}
return s
})
}
function do_act(instance,actfunc,isparent,origargs,cb){
function do_act(instance,actmeta,isparent,origargs,cb){
var act_start = new Date().getTime()

@@ -981,26 +1034,29 @@

// FIX: make this error nice to handle for calling code - git rid of circular ref
if( actfunc.parambulator ) {
actfunc.parambulator.validate(args,function(err){
if( actmeta.parambulator ) {
actmeta.parambulator.validate(args,function(err){
// FIX: should have an error code
if( err ) return instance.fail(err,cb)
return perform(actfunc)
return perform(actmeta)
})
} else return perform(actfunc);
} else return perform(actmeta);
function perform(actfunc) {
var actid = nid()
function perform(actmeta) {
var plugin_nameref = actfunc.plugin_nameref||['-','-']
// TODO: doesn't really work, as requires all sub actions to use 'this'
var actid = ((instance.fixedargs&&instance.fixedargs.actid)?instance.fixedargs.actid+'/':'')+nid()
var plugin_nameref = actmeta.plugin_nameref||['-','-']
self.log.debug('act',plugin_nameref[0]||'-',plugin_nameref[1]||'-',actid,'IN',function(){
return actfunc.descdata ? actfunc.descdata(args) : descdata(args)
return [actmeta.descdata ? actmeta.descdata(args) : descdata(args), actmeta.id]
})
args.actid$ = actid
//args.actid$ = actid
var delegate = instance.delegate()
var delegate = instance.delegate({actid$:actid})
try {
instance.emit('act-in', actfunc.argpattern, actid, args)
instance.emit('act-in', actmeta.argpattern, actid, args)

@@ -1011,5 +1067,5 @@

var args = arrayify(arguments)
if( _.isFunction(actfunc.log) ) {
if( _.isFunction(actmeta.log) ) {
var entries = [args[0]].concat(actid).concat(args.slice(1))
actfunc.log.apply(instance,entries)
actmeta.log.apply(instance,entries)
}

@@ -1023,5 +1079,5 @@ else {

if( actfunc.parent ) {
if( actmeta.parentmeta ) {
delegate.parent = function(args,cb) {
do_act(delegate,actfunc.parent,true,args,cb)
do_act(delegate,actmeta.parentmeta,true,args,cb)
}

@@ -1038,3 +1094,3 @@ }

$.stats.act.called++
actfunc.call(delegate,callargs,function(err){
actmeta.func.call(delegate,callargs,function(err){
var args = arrayify(arguments)

@@ -1056,3 +1112,3 @@

emitargs.unshift(actid)
emitargs.unshift(actfunc.argpattern)
emitargs.unshift(actmeta.argpattern)
emitargs.unshift('act-out')

@@ -1064,3 +1120,3 @@ instance.emit.apply(instance,emitargs)

self.log.debug('act',plugin_nameref[0]||'-',plugin_nameref[1]||'-',actid,'OUT',function(){
return _.flatten([ actfunc.descdata ? actfunc.descdata(args.slice(1)) : descdata(args.slice(1)) ], true)
return [ _.flatten([ actmeta.descdata ? actmeta.descdata(args.slice(1)) : descdata(args.slice(1)) ], true), actmeta.id ]
})

@@ -1077,3 +1133,3 @@

$.stats.act.failed++
self.log.error('act','err',actid, error.message, stackfirst(error) )
self.log.error('act','err',actid, error.message, actmeta.id, stackfirst(error) )
throw instance.fail( descerror({code:'seneca/act_error',args:args},error) )

@@ -1114,5 +1170,5 @@ }

var instance = this && this.seneca ? this : self
var actfunc = findact(args)
var actmeta = findact(args)
if( !actfunc ) {
if( !actmeta ) {
if( _.isUndefined(args.default$) ) {

@@ -1126,3 +1182,3 @@ instance.fail({code:'seneca/act_not_found',args:args},cb)

}
else do_act(instance,actfunc,false,args,cb)
else do_act(instance,actmeta,false,args,cb)
}

@@ -1136,3 +1192,2 @@

_.each( pinthis.pinact(pin), function(actpattern){
//console.log('WRAP '+util.inspect(actpattern))
pinthis.add(actpattern,function(args,done){

@@ -1254,7 +1309,16 @@ wrapper.call(this,args,done)

// loop over a list of items recursively
// list can be an integer - number of times to recurse
function recurse(list,work,done) {
var ctxt = this
list = _.clone(list)
//console.log('RECURSE:'+list)
if( _.isNumber(list) ) {
var size = list
list = new Array(size)
for(var i = 0; i < size; i++){
list[i]=i
}
}
else {
list = _.clone(list)
}

@@ -1265,5 +1329,4 @@ function next(err,out){

var item = list.shift()
//console.log('RECUR:'+item)
if( item ) {
if( void 0 !== item ) {
work.call(ctxt,item,next)

@@ -1322,2 +1385,3 @@ }

copydata: common.copydata,
router: function(){ return new Router() }
}

@@ -1324,0 +1388,0 @@

@@ -33,2 +33,3 @@ /* Copyright (c) 2012-2013 Richard Rodger, BSD License */

/* opts.map = { canon: [cmds] }
* canon is in string format zone/base/name, with empty or - indicating undefined
* opts.taglen = length of instance tag, default 3

@@ -51,3 +52,3 @@ */

else {
entspecs.push({canon:'//',cmds:allcmds})
entspecs.push({canon:'-/-/-',cmds:allcmds})
}

@@ -64,8 +65,24 @@

storedesc.push(entspec.canon)
var m = /^(\w*)\/(\w*)\/(\w*)$/.exec(entspec.canon)
var name = m[3], base = m[2], zone = m[1]
// TODO: support base/name and name, error handling
var entargs = {}
var zone,base,name
var m = /^(\w*|-)\/(\w*|-)\/(\w*|-)$/.exec(entspec.canon)
if( m ) {
zone = m[1]
base = m[2]
name = m[3]
}
else if( m = /^(\w*|-)\/(\w*|-)$/.exec(entspec.canon) ) {
base = m[1]
name = m[2]
}
else if( m = /^(\w*|-)$/.exec(entspec.canon) ) {
name = m[2]
}
zone = '-'===zone ? void 0 : zone
base = '-'===base ? void 0 : base
name = '-'===name ? void 0 : name
var entargs = {}
name && (entargs.name = name)

@@ -72,0 +89,0 @@ base && (entargs.base = base)

@@ -12,6 +12,6 @@ {

],
"version": "0.5.5",
"version": "0.5.6",
"license": "MIT",
"homepage": "https://senecajs.org",
"author": "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)",
"homepage": "http://senecajs.org",
"author": "Richard Rodger (http://richardrodger.com/)",
"contributors": [

@@ -21,3 +21,4 @@ "Richard Rodger <richard@ricebridge.com> (http://richardrodger.com/)",

"Marian Radulescu <marian.radulescu@gmail.com>",
"Alexandru Mircea <mircea.alexandru@gmail.com>"
"Alexandru Mircea <mircea.alexandru@gmail.com>",
"Cristian Ianto <cristian.ianto@nearform.com>"
],

@@ -24,0 +25,0 @@ "engines": {

@@ -7,6 +7,6 @@ /* Copyright (c) 2010-2013 Richard Rodger */

var uuid = require('node-uuid')
var fs = require('fs')
function list(si,entmap,qent,q,cb) {

@@ -31,2 +31,6 @@ var list = []

if( !_.isFunction(ent.make$) ) {
ent = entset[id] = qent.make$(ent)
}
list.push(ent)

@@ -92,4 +96,5 @@ })

function do_save(id) {
var mement = ent.clone$()
if( id ) {
ent.id = id
mement.id = id
}

@@ -100,6 +105,6 @@

entmap[base][name][ent.id] = ent
entmap[base][name][mement.id] = mement
si.log.debug(function(){return['save/'+(create?'insert':'update'),ent.canon$({string:1}),ent,desc]})
cb(null,ent)
si.log.debug(function(){return['save/'+(create?'insert':'update'),ent.canon$({string:1}),mement,desc]})
cb(null,mement)
}

@@ -116,3 +121,3 @@ },

this.log.debug(function(){return['load',q,qent.canon$({string:1}),,ent,desc]})
cb(err, ent)
cb(err, ent ? ent.clone$() : null )
})

@@ -184,2 +189,29 @@ },

this.add({role:store.name,cmd:'export'},function(args,done){
var entjson = JSON.stringify(entmap)
fs.writeFile(args.file,entjson,function(err){
done(err,{ok:!!err})
})
})
this.add({role:store.name,cmd:'import'},function(args,done){
try {
fs.readFile(args.file,function(err,entjson){
if( entjson ) {
try {
entmap = JSON.parse(entjson)
done(err,{ok:!!err})
}
catch(e){
done(e)
}
}
})
}
catch(e){
done(e)
}
})
cb(null,{name:store.name,tag:tag})

@@ -186,0 +218,0 @@ })

@@ -16,3 +16,3 @@ # seneca - Node.js module

Current Version: 0.5.5
Current Version: 0.5.6

@@ -19,0 +19,0 @@ Tested on: node 0.8.16

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