|
1 |
| -# @seneca/config |
| 1 | +# @seneca/batch-processor |
2 | 2 |
|
3 |
| -> _Seneca Config_ is a plugin for [Seneca](http://senecajs.org) |
| 3 | +> _Seneca BatchProcessor_ is a plugin for [Seneca](http://senecajs.org) |
4 | 4 |
|
5 |
| -Live configuration plugin for the Seneca framework. |
| 5 | +INTRO |
6 | 6 |
|
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 |
| -[](https://npmjs.com/package/@seneca/config) |
14 |
| -[](https://github.com/senecajs/SenecaConfig/actions/workflows/build.yml) |
15 |
| -[](https://coveralls.io/github/senecajs/SenecaConfig?branch=main) |
16 |
| -[](https://snyk.io/test/github/senecajs/SenecaConfig) |
| 7 | +[](https://npmjs.com/package/@seneca/batch-processor) |
| 8 | +[](https://github.com/senecajs/SenecaBatchProcessor/actions/workflows/build.yml) |
| 9 | +[](https://coveralls.io/github/senecajs/SenecaBatchProcessor?branch=main) |
| 10 | +[](https://snyk.io/test/github/senecajs/SenecaBatchProcessor) |
17 | 11 | [](https://deepscan.io/dashboard#view=project&tid=5016&pid=26547&bid=846930)
|
18 |
| -[](https://codeclimate.com/github/senecajs/SenecaConfig/maintainability) |
| 12 | +[](https://codeclimate.com/github/senecajs/SenecaBatchProcessor/maintainability) |
19 | 13 |
|
20 | 14 | |  | This open source module is sponsored and supported by [Voxgig](https://www.voxgig.com). |
|
21 | 15 | | ---------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
22 | 16 |
|
23 | 17 | ## Install
|
24 | 18 |
|
25 | 19 | ```sh
|
26 |
| -$ npm install @seneca/Config |
| 20 | +$ npm install @seneca/batch-processor |
27 | 21 | ```
|
28 | 22 |
|
| 23 | + |
29 | 24 | ## Quick Example
|
30 | 25 |
|
31 | 26 | ```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 } } |
36 | 27 |
|
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} |
42 | 71 |
|
43 | 72 | ```
|
44 | 73 |
|
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: |
80 | 75 |
|
81 |
| -## Action Descriptions |
82 |
| - |
83 |
| -### « `sys:config,get:val` » |
84 |
| - |
85 |
| -Get a config value by key. |
86 |
| - |
87 |
| - |
88 |
| -#### Parameters |
89 |
| - |
90 |
| - |
91 |
| -* __key__ : _string_ |
92 |
| - |
93 |
| - |
94 |
| ----------- |
95 |
| -### « `sys:config,init:val` » |
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 |
| -### « `sys:config,list:val` » |
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 | +``` |
114 | 80 |
|
115 | 81 |
|
116 |
| -* __q__ : _object_ (optional, default: `{}`) |
| 82 | +## More Examples |
117 | 83 |
|
118 | 84 |
|
119 |
| ----------- |
120 |
| -### « `sys:config,map:val` » |
| 85 | +```js |
121 | 86 |
|
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:},...]} |
123 | 147 |
|
| 148 | +``` |
124 | 149 |
|
125 |
| -#### Parameters |
126 | 150 |
|
127 | 151 |
|
128 |
| -* __prefix__ : _string_ |
129 | 152 |
|
| 153 | +Review the [unit tests](test/BatchProcessor.test.ts) for more examples. |
130 | 154 |
|
131 |
| ----------- |
132 |
| -### « `sys:config,set:val` » |
133 | 155 |
|
134 |
| -Set a config value by key (must exist). |
135 | 156 |
|
| 157 | +<!--START:options--> |
136 | 158 |
|
137 |
| -#### Parameters |
138 | 159 |
|
139 | 160 |
|
140 |
| -* __key__ : _string_ |
| 161 | +<!--END:options--> |
141 | 162 |
|
| 163 | +<!--START:action-list--> |
142 | 164 |
|
143 |
| ----------- |
144 | 165 |
|
145 | 166 |
|
146 | 167 | <!--END:action-desc-->
|
|
0 commit comments