Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Mar 20, 2018
1 parent 3ad4407 commit 210b723
Show file tree
Hide file tree
Showing 7 changed files with 2,603 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ typings/
# dotenv environment variables file
.env

*~
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: node_js
sudo: false

env:
- SENECA_VER=seneca@3.x.x
- SENECA_VER=seneca@plugin
- SENECA_VER=senecajs/seneca

node_js:
- '8'
- '6'
- '4'

before_script:
- npm uninstall seneca
- npm install $SENECA_VER

after_script:
- npm run coveralls
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# seneca-owner
Seneca plugin to add user ownership annotations to entities.
[Seneca](senecajs.org) plugin providing messages for a generic key-value store.

[![Npm][BadgeNpm]][Npm]
[![Travis][BadgeTravis]][Travis]
[![Coveralls][BadgeCoveralls]][Coveralls]



## Quick Example

```
Seneca()
.use('kv')
.act('role:kv,cmd:set,key:foo,val:bar', function() {
this.act('role:kv,cmd:get,key:foo', function(ignore, out) {
console.log(out.val) // prints 'bar'
})
})
```


## Inbound Messages

* `role:kv,cmd:set`; params: `key`: string, `val`: object
* `role:kv,cmd:get`; params: `key`: string
* `role:kv,cmd:del`; params: `key`: string


## Implementations

* Self: transient memory store
* Redis: [`seneca-redis-owner`](https://github.com/voxgig/seneca-redis-owner)


[BadgeCoveralls]: https://coveralls.io/repos/voxgig/seneca-owner/badge.svg?branch=master&service=github
[BadgeNpm]: https://badge.fury.io/js/seneca-owner.svg
[BadgeTravis]: https://travis-ci.org/voxgig/seneca-owner.svg?branch=master
[Coveralls]: https://coveralls.io/github/voxgig/seneca-owner?branch=master
[Npm]: https://www.npmjs.com/package/seneca-owner
[Travis]: https://travis-ci.org/voxgig/seneca-owner?branch=master
51 changes: 51 additions & 0 deletions owner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright (c) 2018 voxgig and other contributors, MIT License */
'use strict'

const Optioner = require('optioner')

const Joi = Optioner.Joi

const optioner = Optioner({
userprop: Joi.string().default('user'),
entprop: Joi.string().default('ent'),
inbound: Joi.array().required(),
annotate: Joi.array().required(),
})

module.exports = function owner(options) {
const seneca = this
const opts = optioner.check(options)
const userprop = opts.userprop
const entprop = opts.entprop

// console.log(userprop, entprop)

opts.inbound.forEach(function(msgpat) {
seneca.wrap(msgpat, function(msg, reply) {
// TODO: error if userprop not found: configurable
var userdata = msg[userprop]


// TODO: fixedargs should be renamed
this.fixedargs[userprop] = userdata

this.prior(msg, reply)
})
})

opts.annotate.forEach(function(msgpat) {
seneca.add(msgpat, function(msg, reply) {
var userdata = msg[userprop]
var ent = msg[entprop]

// TODO: make these props configurable too
ent.user = userdata.id
ent.org = userdata.org

this.prior(msg, reply)
})
})
}

const intern = (module.exports.intern = {
})
Loading

0 comments on commit 210b723

Please sign in to comment.