@emartech/data-aggregator-language
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -29,3 +29,3 @@ { | ||
}, | ||
"version": "2.1.0" | ||
"version": "2.1.1" | ||
} |
@@ -8,8 +8,5 @@ 'use strict'; | ||
const interpreterFactory = require('./interpreter'); | ||
const Period = require('../lib/period/period'); | ||
const evaluate = (lexer, parser, interpreter) => (text) => { | ||
const lexResult = lexer.tokenize(text); | ||
parser.input = lexResult.tokens; | ||
const createAggregator = (lexer, parser, interpreter) => (text) => { | ||
parser.input = lexer.tokenize(text).tokens; | ||
const cst = parser.additionExpression(); | ||
@@ -33,7 +30,8 @@ const value = interpreter.visit(cst); | ||
const AggregatorInterpreter = interpreterFactory(parser); | ||
const interpreter = new AggregatorInterpreter(); | ||
module.exports = (input) => (text) => { | ||
const interpreter = new AggregatorInterpreter(Period.create(input)); | ||
return evaluate(lexer, parser, interpreter)(text); | ||
module.exports = (input) => { | ||
interpreter.period = input; | ||
return createAggregator(lexer, parser, interpreter); | ||
}; | ||
})(); |
@@ -6,8 +6,11 @@ 'use strict'; | ||
describe('The Aggregator Grammar', () => { | ||
const input = [ | ||
{ date: '2017-08-15', campaigns: { email: { open: 3 }, values_for_test: [4, 10, 2] } }, | ||
{ date: '2017-08-16', campaigns: { email: { open: 4 }, values_for_test: [2, 9] } } | ||
]; | ||
const aggregate = subject(input); | ||
let aggregate; | ||
before(() => { | ||
aggregate = subject([ | ||
{ date: '2017-08-15', campaigns: { email: { open: 3 }, values_for_test: [4, 10, 2] } }, | ||
{ date: '2017-08-16', campaigns: { email: { open: 4 }, values_for_test: [2, 9] } } | ||
]); | ||
}); | ||
describe('Binary Operands', () => { | ||
@@ -14,0 +17,0 @@ it('has a last operator', () => { |
'use strict'; | ||
const Period = require('../lib/period/period'); | ||
module.exports = (parser) => { | ||
@@ -7,8 +9,12 @@ const BaseCstVisitor = parser.getBaseCstVisitorConstructor(); | ||
class AggregatorInterpreter extends BaseCstVisitor { | ||
constructor(period) { | ||
constructor() { | ||
super(); | ||
this._period = period; | ||
this._period = null; | ||
this.validateVisitor(); | ||
} | ||
set period(period) { | ||
this._period = Period.create(period); | ||
} | ||
additionExpression(ctx) { | ||
@@ -15,0 +21,0 @@ return this.visit(ctx.lhs) + this._accumulateAdditiveRhs(ctx.rhs); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20895
461
0