@machinemetrics/io-adapter-lib 2.38.0 → 2.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.38.1]
4
+ - Fixed 'amount' argument for count op
5
+
3
6
  ## [2.38.0]
4
7
  - Added object-keys and object-values transforms
5
8
 
@@ -10,13 +10,13 @@ const TransformState = require('./transformState');
10
10
  * the counter will be incremented before the output value is emitted.
11
11
  */
12
12
  class RisingEdgeCounterFilter extends TransformState {
13
- constructor({ engine, path, args: { mergeWindow, accum = {}, reset = {} } }) {
13
+ constructor({ engine, path, args: { mergeWindow, amount = {}, reset = {} } }) {
14
14
  super();
15
15
 
16
16
  this.mergeWindow = mergeWindow || 0;
17
17
  this.engine = engine;
18
- this.accumExpression = accum.compiledExpression;
19
- this.accumSources = engine.expressionService.expressionTriggers(`${path}.accum`);
18
+ this.accumExpression = amount.compiledExpression;
19
+ this.accumSources = engine.expressionService.expressionTriggers(`${path}.amount`);
20
20
  this.resetExpression = reset.compiledExpression;
21
21
  this.resetSources = engine.expressionService.expressionTriggers(`${path}.reset`);
22
22
 
@@ -37,12 +37,12 @@ class RisingEdgeCounterFilter extends TransformState {
37
37
  defaultAttribute: 'amount',
38
38
  });
39
39
 
40
- let accum = _.get(defn.args, 'amount', defn.args.count);
41
- if (!_.isUndefined(accum)) {
40
+ let amount = _.get(defn.args, 'amount', defn.args.count);
41
+ if (!_.isUndefined(amount)) {
42
42
  try {
43
- const expression = accum.toString();
43
+ const expression = amount.toString();
44
44
  const compiledExpression = configUtil.compileExpression(expression, this.op);
45
- accum = { expression, compiledExpression };
45
+ amount = { expression, compiledExpression };
46
46
  } catch (err) {
47
47
  configUtil.throwConfigError(`Problem evaluating expression: ${err.message}`, this.op);
48
48
  }
@@ -64,12 +64,12 @@ class RisingEdgeCounterFilter extends TransformState {
64
64
  configUtil.requirePositive(mergeWindow, 'merge-window', this.op);
65
65
  }
66
66
 
67
- defn.args = { accum, reset, mergeWindow };
67
+ defn.args = { amount, reset, mergeWindow };
68
68
  }
69
69
 
70
70
  static getExpressions(configUtil, body, info) {
71
71
  return [
72
- ...configUtil.getExpressions(body, { ...info, field: 'accum' }, true),
72
+ ...configUtil.getExpressions(body, { ...info, field: 'amount' }, true),
73
73
  ...configUtil.getExpressions(body, { ...info, field: 'reset' }),
74
74
  ];
75
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machinemetrics/io-adapter-lib",
3
- "version": "2.38.0",
3
+ "version": "2.38.1",
4
4
  "description": "Configuration and engine implementation for MachineMetrics AdapterScripts and adapters",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",
@@ -34,3 +34,7 @@ variables:
34
34
  var7:
35
35
  - source: active
36
36
  - count: ppc
37
+ var8:
38
+ - source: active
39
+ - count:
40
+ amount: ppc
@@ -224,4 +224,23 @@ describe('rising-edge-counter full engine config file tests', function () {
224
224
  [14, 8], [17, 10], [17, 12], [20, 14],
225
225
  ]);
226
226
  });
227
+
228
+ it('count by expression 3', function () {
229
+ const engine = new EngineV2(config);
230
+ const builder = new Builder(config);
231
+ builder.build(engine);
232
+
233
+ const source = testUtils.valueSource();
234
+ testUtils.attachEngineTransformValidator(engine, engine.variablePool.var8, source);
235
+
236
+ source.sendValue('ppc', 7, 0);
237
+ source.sendValues('active', [[false, 0], [true, 2], [false, 4], [true, 6]]);
238
+ source.sendValue('ppc', 3, 7);
239
+ source.sendValues('active', [[false, 8], [true, 10], [false, 12], [true, 14]]);
240
+
241
+ engine.validateFilter([
242
+ [0, 0], [7, 2], [7, 4], [14, 6], [14, 7],
243
+ [14, 8], [17, 10], [17, 12], [20, 14],
244
+ ]);
245
+ });
227
246
  });