Skip to content

Commit 4394dd6

Browse files
committed
initial
1 parent 375d44a commit 4394dd6

File tree

3 files changed

+152
-108
lines changed

3 files changed

+152
-108
lines changed

README.md

+125-104
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,167 @@
1-
# @seneca/config
1+
# @seneca/batch-processor
22

3-
> _Seneca Config_ is a plugin for [Seneca](http://senecajs.org)
3+
> _Seneca BatchProcessor_ is a plugin for [Seneca](http://senecajs.org)
44
5-
Live configuration plugin for the Seneca framework.
5+
INTRO
66

7-
Unlike static configuration, this plugin lets you store keyed
8-
configuration in your deployed persistent storage so that you can
9-
change it on the live system. This is useful for things like currency
10-
exchange rates, feature flags, A/B testing etc.
11-
12-
13-
[![npm version](https://img.shields.io/npm/v/@seneca/config.svg)](https://npmjs.com/package/@seneca/config)
14-
[![build](https://github.com/senecajs/SenecaConfig/actions/workflows/build.yml/badge.svg)](https://github.com/senecajs/SenecaConfig/actions/workflows/build.yml)
15-
[![Coverage Status](https://coveralls.io/repos/github/senecajs/SenecaConfig/badge.svg?branch=main)](https://coveralls.io/github/senecajs/SenecaConfig?branch=main)
16-
[![Known Vulnerabilities](https://snyk.io/test/github/senecajs/SenecaConfig/badge.svg)](https://snyk.io/test/github/senecajs/SenecaConfig)
7+
[![npm version](https://img.shields.io/npm/v/@seneca/batch-processor.svg)](https://npmjs.com/package/@seneca/batch-processor)
8+
[![build](https://github.com/senecajs/SenecaBatchProcessor/actions/workflows/build.yml/badge.svg)](https://github.com/senecajs/SenecaBatchProcessor/actions/workflows/build.yml)
9+
[![Coverage Status](https://coveralls.io/repos/github/senecajs/SenecaBatchProcessor/badge.svg?branch=main)](https://coveralls.io/github/senecajs/SenecaBatchProcessor?branch=main)
10+
[![Known Vulnerabilities](https://snyk.io/test/github/senecajs/SenecaBatchProcessor/badge.svg)](https://snyk.io/test/github/senecajs/SenecaBatchProcessor)
1711
[![DeepScan grade](https://deepscan.io/api/teams/5016/projects/26547/branches/846930/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5016&pid=26547&bid=846930)
18-
[![Maintainability](https://api.codeclimate.com/v1/badges/3e5e5c11a17dbfbdd894/maintainability)](https://codeclimate.com/github/senecajs/SenecaConfig/maintainability)
12+
[![Maintainability](https://api.codeclimate.com/v1/badges/3e5e5c11a17dbfbdd894/maintainability)](https://codeclimate.com/github/senecajs/SenecaBatchProcessor/maintainability)
1913

2014
| ![Voxgig](https://www.voxgig.com/res/img/vgt01r.png) | This open source module is sponsored and supported by [Voxgig](https://www.voxgig.com). |
2115
| ---------------------------------------------------- | --------------------------------------------------------------------------------------- |
2216

2317
## Install
2418

2519
```sh
26-
$ npm install @seneca/Config
20+
$ npm install @seneca/batch-processor
2721
```
2822

23+
2924
## Quick Example
3025

3126
```js
32-
seneca.use('Config', {})
33-
34-
const initRes = await seneca.post('sys:config,init:val,key:a,val:1')
35-
// === { ok: true, key: 'a', val: 1, entry: { key: 'a', val: 1 } }
3627

37-
const getRes = await seneca.post('sys:config,get:val,key:a')
38-
// === { ok: true, key: 'a', val: 1, entry: { key: 'a', val: 1 } }
39-
40-
const setRes = await seneca.post('sys:config,set:val,key:a,val:2')
41-
// === { ok: true, key: 'a', val: 1, entry: { key: 'a', val: 2 } }
28+
// Seneca setup script:
29+
30+
seneca.use('BatchProcessor', {
31+
send: {
32+
mode: 'async', // wait for transition, global setting
33+
},
34+
where: {
35+
'aim:foo,color:red': {
36+
match: { // on out
37+
'ok:true': {
38+
send: [ // zero or more next messages
39+
{
40+
msg: {
41+
aim: 'bar',
42+
color: 'blue',
43+
planet: 'out~planet' // dot path ref (see npm package `inks`)
44+
order: 'ctx~place.order~Number' // Gubu validation expression
45+
}
46+
},
47+
{
48+
mode: 'sync', // use .act, don't await
49+
msg: 'aim:bar,color:green,planet:out~planet',
50+
body: { // msg has precedence
51+
order: 'ctx~place.order~Number'
52+
}
53+
}
54+
]
55+
}
56+
}
57+
}
58+
}
59+
})
60+
61+
62+
// Within aim:foo,color:red action script:
63+
64+
const process = seneca.export('BatchProcessor/process')
65+
66+
let out = {ok:true,planet:'mars'}
67+
let ctx = {place:{order:1}} // for data not returned by message action
68+
out = await process(seneca, ctx, out)
69+
// send = [{aim:bar,color:blue,planet:mars,order:1}, {aim:bar,color:green,planet:mars,order:1}]
70+
// out = {ok:true,planet:'mars',batch:BATCHID,run:RUNID}
4271

4372
```
4473

45-
## More Examples
46-
47-
Review the [unit tests](test/Config.test.ts) for more examples.
48-
49-
50-
51-
<!--START:options-->
52-
53-
54-
## Options
55-
56-
* `debug` : boolean
57-
* `numparts` : number
58-
* `canon` : object
59-
* `init$` : boolean
60-
61-
62-
<!--END:options-->
63-
64-
<!--START:action-list-->
65-
66-
67-
## Action Patterns
68-
69-
* [sys:config,get:val](#-sysconfiggetval-)
70-
* [sys:config,init:val](#-sysconfiginitval-)
71-
* [sys:config,list:val](#-sysconfiglistval-)
72-
* [sys:config,map:val](#-sysconfigmapval-)
73-
* [sys:config,set:val](#-sysconfigsetval-)
74-
75-
76-
<!--END:action-list-->
77-
78-
<!--START:action-desc-->
79-
74+
The message send operations are executed by the plugin with code equivalent to:
8075

81-
## Action Descriptions
82-
83-
### &laquo; `sys:config,get:val` &raquo;
84-
85-
Get a config value by key.
86-
87-
88-
#### Parameters
89-
90-
91-
* __key__ : _string_
92-
93-
94-
----------
95-
### &laquo; `sys:config,init:val` &raquo;
96-
97-
Initialise a config value by key (must not exist).
98-
99-
100-
#### Parameters
101-
102-
103-
* __key__ : _string_
104-
* __existing__ : _boolean_ (optional, default: `false`)
105-
106-
107-
----------
108-
### &laquo; `sys:config,list:val` &raquo;
109-
110-
List config values by query.
111-
112-
113-
#### Parameters
76+
```js
77+
await seneca.post({aim:'bar',color:'blue',planet:'mars',order:1})
78+
seneca.act({aim:bar,color:green,planet:mars,order:1})
79+
```
11480

11581

116-
* __q__ : _object_ (optional, default: `{}`)
82+
## More Examples
11783

11884

119-
----------
120-
### &laquo; `sys:config,map:val` &raquo;
85+
```js
12186

122-
Get a map of config values by key prefix (dot separated).
87+
// Seneca setup script:
88+
89+
seneca.use('BatchProcessor', {
90+
send: {
91+
mode: 'async', // wait for transition, global setting
92+
},
93+
where: {
94+
'aim:foo,color:red': {
95+
match: {
96+
'*': { // catch all if no other patterns match
97+
// Create BatchMonitor entry if ctx.BatchMonitorEntry$ defined
98+
entry: 'fail' // entry state, entry.info={why:'batch-process-no-match'}
99+
},
100+
'ok:false': {
101+
entry: { state: 'fail', info: { why: 'out~why' } },
102+
send: { // if single msg, no array needed
103+
// ctx has original message in msg$
104+
// out~ means entire contents of out object
105+
msg: 'aim:monitor,fail:msg,msg:ctx~msg$,out:out~'
106+
}
107+
},
108+
'ok:true': { // matches are in same Patrun set, so usual Seneca pattern rules apply
109+
entry: 'done', // only created after all msgs sent
110+
send: [ // zero or more next messages
111+
{
112+
msg: {
113+
aim: 'bar',
114+
color: 'blue',
115+
planet: 'out~planet' // dot path ref
116+
order: 'ctx~place.order~Number' // Gubu validation expression
117+
}
118+
},
119+
{
120+
mode: 'sync', // use .act, don't await
121+
msg: 'aim:bar,color:green,planet:out~planet',
122+
body: { // msg has precedence
123+
order: 'ctx~place.order~Number'
124+
}
125+
}
126+
]
127+
}
128+
}
129+
}
130+
}
131+
})
132+
133+
134+
// Within aim:foo,color:red action script:
135+
136+
const process = seneca.export('BatchProcessor/process')
137+
const bme = seneca.BatchMonitor(...).entry(...)
138+
139+
let out = {ok:true,planet:'mars'}
140+
let ctx = {place:{order:1},BatchMonitorEntry$:bme}
141+
out = await process(seneca, ctx, out)
142+
// send = [{aim:bar,color:blue,planet:mars,order:1}, {aim:bar,color:green,planet:mars,order:1}]
143+
// out = {ok:true,planet:'mars',batch:BATCHID,run:RUNID}
144+
145+
// The ctx object is used for returning additional information, such as send msg results.
146+
// ctx = {place:{order:1}, result$:[{msg:,out:,bgn:,end:,dur:},...]}
123147

148+
```
124149

125-
#### Parameters
126150

127151

128-
* __prefix__ : _string_
129152

153+
Review the [unit tests](test/BatchProcessor.test.ts) for more examples.
130154

131-
----------
132-
### &laquo; `sys:config,set:val` &raquo;
133155

134-
Set a config value by key (must exist).
135156

157+
<!--START:options-->
136158

137-
#### Parameters
138159

139160

140-
* __key__ : _string_
161+
<!--END:options-->
141162

163+
<!--START:action-list-->
142164

143-
----------
144165

145166

146167
<!--END:action-desc-->

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
"@seneca/doc": "^7.2.0",
4343
"@seneca/maintain": "^0.1.0",
4444
"@types/jest": "^29.5.12",
45-
"@types/node": "^20.11.21",
46-
"esbuild": "^0.20.1",
45+
"@types/node": "^20.14.2",
46+
"esbuild": "^0.21.4",
4747
"esbuild-jest": "^0.5.0",
4848
"jest": "^29.7.0",
49-
"prettier": "3.2.5",
49+
"prettier": "3.3.1",
5050
"seneca-msg-test": "^4.1.0",
51-
"typescript": "^5.3.3"
51+
"typescript": "^5.4.5"
5252
},
5353
"peerDependencies": {
5454
"@seneca/entity-util": ">=2",

test/quick.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
const Seneca = require('seneca')
4+
5+
6+
run()
7+
8+
async function run() {
9+
const s0 =
10+
Seneca()
11+
.test()
12+
.message('a:1', async function a1(msg, meta) {
13+
console.log('meta',meta)
14+
console.log('pact',this.private$)
15+
16+
return {x:msg.x}
17+
})
18+
19+
console.log(await s0.post('a:1,x:1'))
20+
21+
}
22+
23+

0 commit comments

Comments
 (0)