@jbrowse/jexl 2.3.1 → 3.0.2
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 +27 -0
- package/LICENSE.txt +1 -0
- package/README.md +77 -85
- package/dist/Expression.d.ts +2 -12
- package/dist/Expression.js +5 -27
- package/dist/Expression.js.map +1 -1
- package/dist/Jexl.d.ts +6 -40
- package/dist/Jexl.js +7 -49
- package/dist/Jexl.js.map +1 -1
- package/dist/Lexer.js +3 -1
- package/dist/Lexer.js.map +1 -1
- package/dist/evaluator/Evaluator.d.ts +14 -55
- package/dist/evaluator/Evaluator.js +14 -73
- package/dist/evaluator/Evaluator.js.map +1 -1
- package/dist/evaluator/handlers.d.ts +19 -18
- package/dist/evaluator/handlers.js +54 -62
- package/dist/evaluator/handlers.js.map +1 -1
- package/dist/grammar.d.ts +3 -4
- package/dist/grammar.js +16 -39
- package/dist/grammar.js.map +1 -1
- package/dist/parser/Parser.js +16 -3
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/states.js +7 -3
- package/dist/parser/states.js.map +1 -1
- package/esm/Expression.d.ts +2 -12
- package/esm/Expression.js +5 -27
- package/esm/Expression.js.map +1 -1
- package/esm/Jexl.d.ts +6 -40
- package/esm/Jexl.js +7 -49
- package/esm/Jexl.js.map +1 -1
- package/esm/Lexer.js +3 -1
- package/esm/Lexer.js.map +1 -1
- package/esm/evaluator/Evaluator.d.ts +14 -55
- package/esm/evaluator/Evaluator.js +14 -73
- package/esm/evaluator/Evaluator.js.map +1 -1
- package/esm/evaluator/handlers.d.ts +19 -18
- package/esm/evaluator/handlers.js +54 -62
- package/esm/evaluator/handlers.js.map +1 -1
- package/esm/grammar.d.ts +3 -4
- package/esm/grammar.js +16 -39
- package/esm/grammar.js.map +1 -1
- package/esm/parser/Parser.js +16 -3
- package/esm/parser/Parser.js.map +1 -1
- package/esm/parser/states.js +7 -3
- package/esm/parser/states.js.map +1 -1
- package/package.json +10 -8
- package/src/Expression.ts +5 -36
- package/src/Jexl.ts +7 -54
- package/src/Lexer.ts +3 -1
- package/src/evaluator/Evaluator.ts +14 -92
- package/src/evaluator/handlers.ts +54 -68
- package/src/grammar.ts +17 -38
- package/src/parser/Parser.ts +13 -3
- package/src/parser/states.ts +7 -3
- package/src/types.ts +4 -1
- package/dist/PromiseSync.d.ts +0 -13
- package/dist/PromiseSync.js +0 -80
- package/dist/PromiseSync.js.map +0 -1
- package/esm/PromiseSync.d.ts +0 -13
- package/esm/PromiseSync.js +0 -78
- package/esm/PromiseSync.js.map +0 -1
- package/src/PromiseSync.ts +0 -86
package/esm/grammar.js
CHANGED
|
@@ -12,7 +12,6 @@ export const getGrammar = () => ({
|
|
|
12
12
|
'.': { type: 'dot' },
|
|
13
13
|
'[': { type: 'openBracket' },
|
|
14
14
|
']': { type: 'closeBracket' },
|
|
15
|
-
'|': { type: 'pipe' },
|
|
16
15
|
'{': { type: 'openCurl' },
|
|
17
16
|
'}': { type: 'closeCurl' },
|
|
18
17
|
':': { type: 'colon' },
|
|
@@ -90,24 +89,22 @@ export const getGrammar = () => ({
|
|
|
90
89
|
type: 'binaryOp',
|
|
91
90
|
precedence: 10,
|
|
92
91
|
evalOnDemand: (left, right) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
92
|
+
const leftVal = left.eval();
|
|
93
|
+
if (!leftVal) {
|
|
94
|
+
return leftVal;
|
|
95
|
+
}
|
|
96
|
+
return right.eval();
|
|
99
97
|
}
|
|
100
98
|
},
|
|
101
99
|
'||': {
|
|
102
100
|
type: 'binaryOp',
|
|
103
101
|
precedence: 10,
|
|
104
102
|
evalOnDemand: (left, right) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
103
|
+
const leftVal = left.eval();
|
|
104
|
+
if (leftVal) {
|
|
105
|
+
return leftVal;
|
|
106
|
+
}
|
|
107
|
+
return right.eval();
|
|
111
108
|
}
|
|
112
109
|
},
|
|
113
110
|
in: {
|
|
@@ -144,32 +141,12 @@ export const getGrammar = () => ({
|
|
|
144
141
|
* All of these are pre-evaluated to their actual values before calling
|
|
145
142
|
* the function.
|
|
146
143
|
*
|
|
147
|
-
* The Jexl function should return
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* appropriate when the function would normally return a value, but
|
|
153
|
-
* cannot due to some other failure.
|
|
154
|
-
*/
|
|
155
|
-
functions: {},
|
|
156
|
-
/**
|
|
157
|
-
* A map of transform names to transform functions. A transform function
|
|
158
|
-
* takes one ore more arguemnts:
|
|
159
|
-
*
|
|
160
|
-
* - {*} val: A value to be transformed
|
|
161
|
-
* - {*} ...args: A variable number of arguments passed to this transform.
|
|
162
|
-
* All of these are pre-evaluated to their actual values before calling
|
|
163
|
-
* the function.
|
|
164
|
-
*
|
|
165
|
-
* The transform function should return either the transformed value, or
|
|
166
|
-
* a Promises/A+ Promise object that resolves with the value and rejects
|
|
167
|
-
* or throws only when an unrecoverable error occurs. Transforms should
|
|
168
|
-
* generally return undefined when they don't make sense to be used on the
|
|
169
|
-
* given value type, rather than throw/reject. An error is only
|
|
170
|
-
* appropriate when the transform would normally return a value, but
|
|
171
|
-
* cannot due to some other failure.
|
|
144
|
+
* The Jexl function should return the resulting value, or throw when an
|
|
145
|
+
* unrecoverable error occurs. Functions should generally return undefined
|
|
146
|
+
* when they don't make sense to be used on the given value type, rather
|
|
147
|
+
* than throw. An error is only appropriate when the function would normally
|
|
148
|
+
* return a value, but cannot due to some other failure.
|
|
172
149
|
*/
|
|
173
|
-
|
|
150
|
+
functions: {}
|
|
174
151
|
});
|
|
175
152
|
//# sourceMappingURL=grammar.js.map
|
package/esm/grammar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../src/grammar.ts"],"names":[],"mappings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;gBACD,OAAO,KAAK,CAAA;YACd,CAAC;SACF;QACD,GAAG,EAAE;YACH,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,QAAQ;YACpB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK;SACxB;QACD,GAAG,EAAE;YACH,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,CAAC;YACb,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;YACjD,CAAC;SACF;KACF;IAED;;;;;;;;;;;;;OAaG;IACH,SAAS,EAAE,EAAE;CACd,CAAC,CAAA"}
|
package/esm/parser/Parser.js
CHANGED
|
@@ -55,12 +55,20 @@ class Parser {
|
|
|
55
55
|
const stopState = this._subParser.addToken(token);
|
|
56
56
|
if (stopState) {
|
|
57
57
|
this._endSubExpression();
|
|
58
|
-
if (
|
|
58
|
+
if (stopState === '_semicolon') {
|
|
59
|
+
handlers.semicolon.call(this);
|
|
60
|
+
}
|
|
61
|
+
else if (this._parentStop) {
|
|
59
62
|
return stopState;
|
|
60
63
|
}
|
|
61
|
-
|
|
64
|
+
else {
|
|
65
|
+
this._state = stopState;
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
}
|
|
69
|
+
else if (token.type === 'semicolon' && this._stopMap[token.type]) {
|
|
70
|
+
return this._stopMap[token.type];
|
|
71
|
+
}
|
|
64
72
|
else if (state.tokenTypes?.[token.type]) {
|
|
65
73
|
const typeOpts = state.tokenTypes[token.type];
|
|
66
74
|
let handleFunc = handlers[token.type];
|
|
@@ -107,7 +115,9 @@ class Parser {
|
|
|
107
115
|
this._endSubExpression();
|
|
108
116
|
}
|
|
109
117
|
if (this._sequenceExpressions) {
|
|
110
|
-
|
|
118
|
+
if (this._tree) {
|
|
119
|
+
this._sequenceExpressions.push(this._tree);
|
|
120
|
+
}
|
|
111
121
|
const sequence = {
|
|
112
122
|
type: 'SequenceExpression',
|
|
113
123
|
expressions: this._sequenceExpressions
|
|
@@ -191,6 +201,9 @@ class Parser {
|
|
|
191
201
|
this._parentStop = true;
|
|
192
202
|
endStates = this._stopMap;
|
|
193
203
|
}
|
|
204
|
+
if (states[this._state].completable && !endStates.semicolon) {
|
|
205
|
+
endStates = { ...endStates, semicolon: '_semicolon' };
|
|
206
|
+
}
|
|
194
207
|
this._subParser = new Parser(this._grammar, this._lexer, exprStr, endStates);
|
|
195
208
|
}
|
|
196
209
|
}
|
package/esm/parser/Parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../src/parser/Parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AASpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM;IAgBV,YACE,OAAgB,EAChB,KAAY,EACZ,MAAe,EACf,OAA6B;QAE7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,MAAM,GAAG,eAAe,CAAA;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAA;QAC5B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,EAAE,CAAA;IAC/B,CAAC;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAY;QACnB,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;QACjE,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,SAAS,G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,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;YACrC,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACH,mBAAmB,CAAC,OAAgB;QAClC,IAAI,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,SAAS,CAAA;QAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;YACvB,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC3B,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;YAC5D,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,CAAA;QACvD,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;IAC9E,CAAC;CACF;AAED,eAAe,MAAM,CAAA"}
|
package/esm/parser/states.js
CHANGED
|
@@ -53,6 +53,7 @@ export const states = {
|
|
|
53
53
|
binaryOp: { toState: 'expectOperand' },
|
|
54
54
|
pipe: { toState: 'expectTransform' },
|
|
55
55
|
dot: { toState: 'traverse' },
|
|
56
|
+
openBracket: { toState: 'filter' },
|
|
56
57
|
question: { toState: 'ternaryMid', handler: h.ternaryStart },
|
|
57
58
|
semicolon: { handler: h.semicolon }
|
|
58
59
|
},
|
|
@@ -82,7 +83,8 @@ export const states = {
|
|
|
82
83
|
dot: { toState: 'traverse' },
|
|
83
84
|
openBracket: { toState: 'filter' },
|
|
84
85
|
pipe: { toState: 'expectTransform' },
|
|
85
|
-
question: { toState: 'ternaryMid', handler: h.ternaryStart }
|
|
86
|
+
question: { toState: 'ternaryMid', handler: h.ternaryStart },
|
|
87
|
+
semicolon: { handler: h.semicolon }
|
|
86
88
|
},
|
|
87
89
|
completable: true
|
|
88
90
|
},
|
|
@@ -92,7 +94,8 @@ export const states = {
|
|
|
92
94
|
dot: { toState: 'traverse' },
|
|
93
95
|
openBracket: { toState: 'filter' },
|
|
94
96
|
pipe: { toState: 'expectTransform' },
|
|
95
|
-
question: { toState: 'ternaryMid', handler: h.ternaryStart }
|
|
97
|
+
question: { toState: 'ternaryMid', handler: h.ternaryStart },
|
|
98
|
+
semicolon: { handler: h.semicolon }
|
|
96
99
|
},
|
|
97
100
|
completable: true
|
|
98
101
|
},
|
|
@@ -103,7 +106,8 @@ export const states = {
|
|
|
103
106
|
openBracket: { toState: 'filter' },
|
|
104
107
|
openParen: { toState: 'argVal', handler: h.functionCall },
|
|
105
108
|
pipe: { toState: 'expectTransform' },
|
|
106
|
-
question: { toState: 'ternaryMid', handler: h.ternaryStart }
|
|
109
|
+
question: { toState: 'ternaryMid', handler: h.ternaryStart },
|
|
110
|
+
semicolon: { handler: h.semicolon }
|
|
107
111
|
},
|
|
108
112
|
completable: true
|
|
109
113
|
},
|
package/esm/parser/states.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"states.js","sourceRoot":"","sources":["../../src/parser/states.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,CAAC,MAAM,eAAe,CAAA;AAmBlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,MAAM,MAAM,GAAW;IAC5B,aAAa,EAAE;QACb,UAAU,EAAE;YACV,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE;YACnC,cAAc,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE;YAC1C,UAAU,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;YACrC,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;YACvC,QAAQ,EAAE,EAAE,OAAO,EAA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SAAS,EAAE,aAAa;SACzB;KACF;IACD,QAAQ,EAAE;QACR,UAAU,EAAE,CAAC,CAAC,QAAQ;QACtB,SAAS,EAAE;YACT,KAAK,EAAE,UAAU;YACjB,YAAY,EAAE,aAAa;SAC5B;KACF;IACD,UAAU,EAAE;QACV,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,SAAS,EAAE;YACT,KAAK,EAAE,YAAY;SACpB;KACF;IACD,UAAU,EAAE;QACV,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,WAAW,EAAE,IAAI;KAClB;CACF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jbrowse/jexl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "A fork of the jexl lang for jbrowse",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -51,15 +51,17 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/TomFrost/jexl",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
54
|
+
"@eslint/js": "^10.0.1",
|
|
55
|
+
"@types/node": "^25.3.3",
|
|
56
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
57
|
+
"eslint": "^10.0.2",
|
|
56
58
|
"eslint-plugin-import": "^2.32.0",
|
|
57
|
-
"eslint-plugin-unicorn": "^
|
|
58
|
-
"prettier": "^3.
|
|
59
|
-
"rimraf": "^6.1.
|
|
59
|
+
"eslint-plugin-unicorn": "^63.0.0",
|
|
60
|
+
"prettier": "^3.8.1",
|
|
61
|
+
"rimraf": "^6.1.3",
|
|
60
62
|
"typescript": "^5.9.3",
|
|
61
|
-
"typescript-eslint": "^8.
|
|
62
|
-
"vitest": "^4.0.
|
|
63
|
+
"typescript-eslint": "^8.56.1",
|
|
64
|
+
"vitest": "^4.0.18"
|
|
63
65
|
},
|
|
64
66
|
"publishConfig": {
|
|
65
67
|
"access": "public"
|
package/src/Expression.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import Lexer from './Lexer.ts'
|
|
7
|
-
import PromiseSync from './PromiseSync.ts'
|
|
8
7
|
import Evaluator from './evaluator/Evaluator.ts'
|
|
9
8
|
import Parser from './parser/Parser.ts'
|
|
10
9
|
|
|
@@ -15,8 +14,6 @@ interface Grammar {
|
|
|
15
14
|
[key: string]: any
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
type PromiseConstructor = typeof Promise | typeof PromiseSync
|
|
19
|
-
|
|
20
17
|
class Expression {
|
|
21
18
|
_grammar: Grammar
|
|
22
19
|
_exprStr: string
|
|
@@ -44,44 +41,16 @@ class Expression {
|
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @param {Object} [context] A mapping of variables to values, which will be
|
|
49
|
-
* made accessible to the Jexl expression when evaluating it
|
|
50
|
-
* @returns {Promise<*>} resolves with the result of the evaluation.
|
|
51
|
-
*/
|
|
52
|
-
eval(context = {}) {
|
|
53
|
-
return this._eval(context, Promise)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Synchronously evaluates the expression within an optional context.
|
|
44
|
+
* Evaluates the expression within an optional context.
|
|
58
45
|
* @param {Object} [context] A mapping of variables to values, which will be
|
|
59
46
|
* made accessible to the Jexl expression when evaluating it
|
|
60
47
|
* @returns {*} the result of the evaluation.
|
|
61
48
|
* @throws {*} on error
|
|
62
49
|
*/
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
throw res.error
|
|
68
|
-
}
|
|
69
|
-
throw new Error(typeof res.error === 'string' ? res.error : JSON.stringify(res.error))
|
|
70
|
-
}
|
|
71
|
-
return res.value
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
_eval(context: any, promise: PromiseConstructor) {
|
|
75
|
-
return promise.resolve().then(() => {
|
|
76
|
-
const ast = this._getAst()
|
|
77
|
-
const evaluator = new Evaluator(
|
|
78
|
-
this._grammar,
|
|
79
|
-
context,
|
|
80
|
-
undefined,
|
|
81
|
-
promise
|
|
82
|
-
)
|
|
83
|
-
return evaluator.eval(ast!)
|
|
84
|
-
})
|
|
50
|
+
eval(context = {}) {
|
|
51
|
+
const ast = this._getAst()
|
|
52
|
+
const evaluator = new Evaluator(this._grammar, context)
|
|
53
|
+
return evaluator.eval(ast!)
|
|
85
54
|
}
|
|
86
55
|
|
|
87
56
|
_getAst() {
|
package/src/Jexl.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { getGrammar } from './grammar.ts'
|
|
|
9
9
|
interface Grammar {
|
|
10
10
|
elements: Record<string, any>
|
|
11
11
|
functions: Record<string, (...args: any[]) => any>
|
|
12
|
-
transforms: Record<string, (val: any, ...args: any[]) => any>
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -39,13 +38,11 @@ class Jexl {
|
|
|
39
38
|
* @param {number} precedence The operator's precedence
|
|
40
39
|
* @param {function} fn A function to run to calculate the result. The function
|
|
41
40
|
* will be called with two arguments: left and right, denoting the values
|
|
42
|
-
* on either side of the operator. It should return
|
|
43
|
-
* value, or a Promise that resolves with the resulting value.
|
|
41
|
+
* on either side of the operator. It should return the resulting value.
|
|
44
42
|
* @param {boolean} [manualEval] If true, the `left` and `right` arguments
|
|
45
43
|
* will be wrapped in objects with an `eval` function. Calling
|
|
46
|
-
* left.eval() or right.eval() will return
|
|
47
|
-
*
|
|
48
|
-
* operands.
|
|
44
|
+
* left.eval() or right.eval() will return that operand's actual value.
|
|
45
|
+
* This is useful to conditionally evaluate operands.
|
|
49
46
|
*/
|
|
50
47
|
addBinaryOp(
|
|
51
48
|
operator: string,
|
|
@@ -88,8 +85,7 @@ class Jexl {
|
|
|
88
85
|
* @param {string} operator The operator string to be added
|
|
89
86
|
* @param {function} fn A function to run to calculate the result. The function
|
|
90
87
|
* will be called with one argument: the literal value to the right of the
|
|
91
|
-
* operator. It should return
|
|
92
|
-
* that resolves with the resulting value.
|
|
88
|
+
* operator. It should return the resulting value.
|
|
93
89
|
*/
|
|
94
90
|
addUnaryOp(operator: string, fn: (right: any) => any) {
|
|
95
91
|
this._addGrammarElement(operator, {
|
|
@@ -99,28 +95,6 @@ class Jexl {
|
|
|
99
95
|
})
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
/**
|
|
103
|
-
* Adds or replaces a transform function in this Jexl instance.
|
|
104
|
-
* @param {string} name The name of the transform function, as it will be used
|
|
105
|
-
* within Jexl expressions
|
|
106
|
-
* @param {function} fn The function to be executed when this transform is
|
|
107
|
-
* invoked. It will be provided with at least one argument:
|
|
108
|
-
* - {*} value: The value to be transformed
|
|
109
|
-
* - {...*} args: The arguments for this transform
|
|
110
|
-
*/
|
|
111
|
-
addTransform(name: string, fn: (val: any, ...args: any[]) => any) {
|
|
112
|
-
this._grammar.transforms[name] = fn
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Syntactic sugar for calling {@link #addTransform} repeatedly. This function
|
|
117
|
-
* accepts a map of one or more transform names to their transform function.
|
|
118
|
-
* @param {{}} map A map of transform names to transform functions
|
|
119
|
-
*/
|
|
120
|
-
addTransforms(map: Record<string, (val: any, ...args: any[]) => any>) {
|
|
121
|
-
Object.assign(this._grammar.transforms, map)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
98
|
/**
|
|
125
99
|
* Creates an Expression object from the given Jexl expression string, and
|
|
126
100
|
* immediately compiles it. The returned Expression object can then be
|
|
@@ -154,37 +128,16 @@ class Jexl {
|
|
|
154
128
|
}
|
|
155
129
|
|
|
156
130
|
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {string} name The name of the transform function
|
|
159
|
-
* @returns {function} The transform function
|
|
160
|
-
*/
|
|
161
|
-
getTransform(name: string) {
|
|
162
|
-
return this._grammar.transforms[name]
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Asynchronously evaluates a Jexl string within an optional context.
|
|
167
|
-
* @param {string} expression The Jexl expression to be evaluated
|
|
168
|
-
* @param {Object} [context] A mapping of variables to values, which will be
|
|
169
|
-
* made accessible to the Jexl expression when evaluating it
|
|
170
|
-
* @returns {Promise<*>} resolves with the result of the evaluation.
|
|
171
|
-
*/
|
|
172
|
-
eval(expression: string, context = {}) {
|
|
173
|
-
const exprObj = this.createExpression(expression)
|
|
174
|
-
return exprObj.eval(context)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Synchronously evaluates a Jexl string within an optional context.
|
|
131
|
+
* Evaluates a Jexl string within an optional context.
|
|
179
132
|
* @param {string} expression The Jexl expression to be evaluated
|
|
180
133
|
* @param {Object} [context] A mapping of variables to values, which will be
|
|
181
134
|
* made accessible to the Jexl expression when evaluating it
|
|
182
135
|
* @returns {*} the result of the evaluation.
|
|
183
136
|
* @throws {*} on error
|
|
184
137
|
*/
|
|
185
|
-
|
|
138
|
+
eval(expression: string, context = {}) {
|
|
186
139
|
const exprObj = this.createExpression(expression)
|
|
187
|
-
return exprObj.
|
|
140
|
+
return exprObj.eval(context)
|
|
188
141
|
}
|
|
189
142
|
|
|
190
143
|
/**
|
package/src/Lexer.ts
CHANGED
|
@@ -12,9 +12,6 @@ interface Grammar {
|
|
|
12
12
|
[key: string]: any
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
16
|
-
type PromiseConstructor = typeof Promise | any
|
|
17
|
-
|
|
18
15
|
/**
|
|
19
16
|
* The Evaluator takes a Jexl expression tree as generated by the
|
|
20
17
|
* {@link Parser} and calculates its value within a given context. The
|
|
@@ -26,127 +23,52 @@ type PromiseConstructor = typeof Promise | any
|
|
|
26
23
|
* @param {{}} grammar A grammar object against which to evaluate the expression
|
|
27
24
|
* tree
|
|
28
25
|
* @param {{}} [context] A map of variable keys to their values. This will be
|
|
29
|
-
* accessed to resolve the value of each non-relative identifier.
|
|
30
|
-
* Promise values will be passed to the expression as their resolved
|
|
31
|
-
* value.
|
|
26
|
+
* accessed to resolve the value of each non-relative identifier.
|
|
32
27
|
* @param {{}|Array<{}|Array>} [relativeContext] A map or array to be accessed
|
|
33
28
|
* to resolve the value of a relative identifier.
|
|
34
|
-
* @param {function} promise A constructor for the Promise class to be used;
|
|
35
|
-
* probably either Promise or PromiseSync.
|
|
36
29
|
*/
|
|
37
30
|
class Evaluator {
|
|
38
31
|
_grammar: Grammar
|
|
39
32
|
_context: any
|
|
40
33
|
_relContext: any
|
|
41
|
-
Promise: PromiseConstructor
|
|
42
34
|
|
|
43
|
-
constructor(
|
|
44
|
-
grammar: Grammar,
|
|
45
|
-
context?: any,
|
|
46
|
-
relativeContext?: any,
|
|
47
|
-
promise: PromiseConstructor = Promise
|
|
48
|
-
) {
|
|
35
|
+
constructor(grammar: Grammar, context?: any, relativeContext?: any) {
|
|
49
36
|
this._grammar = grammar
|
|
50
37
|
this._context = context || {}
|
|
51
38
|
this._relContext = relativeContext || this._context
|
|
52
|
-
this.Promise = promise
|
|
53
39
|
}
|
|
54
40
|
|
|
55
41
|
/**
|
|
56
42
|
* Evaluates an expression tree within the configured context.
|
|
57
43
|
* @param {{}} ast An expression tree object
|
|
58
|
-
* @returns {
|
|
44
|
+
* @returns {*} the resulting value of the expression.
|
|
59
45
|
*/
|
|
60
46
|
eval(ast: AstNode) {
|
|
61
|
-
return
|
|
62
|
-
return (handlers as any)[ast.type].call(this, ast)
|
|
63
|
-
})
|
|
47
|
+
return (handlers as any)[ast.type].call(this, ast)
|
|
64
48
|
}
|
|
65
49
|
|
|
66
50
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
51
|
+
* Evaluates each expression within an array, and delivers the response as an
|
|
52
|
+
* array with the resulting values at the same indexes as their originating
|
|
53
|
+
* expressions.
|
|
70
54
|
* @param {Array<string>} arr An array of expression strings to be evaluated
|
|
71
|
-
* @returns {
|
|
55
|
+
* @returns {Array<{}>} the result array
|
|
72
56
|
*/
|
|
73
57
|
evalArray(arr: AstNode[]) {
|
|
74
|
-
return
|
|
58
|
+
return arr.map((elem: AstNode) => this.eval(elem))
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* as their value.
|
|
62
|
+
* Evaluates each expression within a map, and delivers the response as a map
|
|
63
|
+
* with the same keys, but with the evaluated result for each as their value.
|
|
81
64
|
* @param {{}} map A map of expression names to expression trees to be
|
|
82
65
|
* evaluated
|
|
83
|
-
* @returns {
|
|
66
|
+
* @returns {{}} the result map.
|
|
84
67
|
*/
|
|
85
68
|
evalMap(map: Record<string, AstNode>) {
|
|
86
69
|
const entries = Object.entries(map)
|
|
87
|
-
const
|
|
88
|
-
return
|
|
89
|
-
Object.fromEntries(entries.map(([key], idx) => [key, vals[idx]]))
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Applies a filter expression with relative identifier elements to a subject.
|
|
95
|
-
* The intent is for the subject to be an array of subjects that will be
|
|
96
|
-
* individually used as the relative context against the provided expression
|
|
97
|
-
* tree. Only the elements whose expressions result in a truthy value will be
|
|
98
|
-
* included in the resulting array.
|
|
99
|
-
*
|
|
100
|
-
* If the subject is not an array of values, it will be converted to a single-
|
|
101
|
-
* element array before running the filter.
|
|
102
|
-
* @param {*} subject The value to be filtered usually an array. If this value is
|
|
103
|
-
* not an array, it will be converted to an array with this value as the
|
|
104
|
-
* only element.
|
|
105
|
-
* @param {{}} expr The expression tree to run against each subject. If the
|
|
106
|
-
* tree evaluates to a truthy result, then the value will be included in
|
|
107
|
-
* the returned array otherwise, it will be eliminated.
|
|
108
|
-
* @returns {Promise<Array>} resolves with an array of values that passed the
|
|
109
|
-
* expression filter.
|
|
110
|
-
* @private
|
|
111
|
-
*/
|
|
112
|
-
_filterRelative(subject: any, expr: AstNode) {
|
|
113
|
-
const arr = Array.isArray(subject)
|
|
114
|
-
? subject
|
|
115
|
-
: subject == null
|
|
116
|
-
? []
|
|
117
|
-
: [subject]
|
|
118
|
-
|
|
119
|
-
const promises = arr.map((elem) =>
|
|
120
|
-
new Evaluator(this._grammar, this._context, elem, this.Promise).eval(expr)
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
return this.Promise.all(promises).then((values: any[]) =>
|
|
124
|
-
arr.filter((_, idx) => values[idx])
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Applies a static filter expression to a subject value. If the filter
|
|
130
|
-
* expression evaluates to boolean true, the subject is returned if false,
|
|
131
|
-
* undefined.
|
|
132
|
-
*
|
|
133
|
-
* For any other resulting value of the expression, this function will attempt
|
|
134
|
-
* to respond with the property at that name or index of the subject.
|
|
135
|
-
* @param {*} subject The value to be filtered. Usually an Array (for which
|
|
136
|
-
* the expression would generally resolve to a numeric index) or an
|
|
137
|
-
* Object (for which the expression would generally resolve to a string
|
|
138
|
-
* indicating a property name)
|
|
139
|
-
* @param {{}} expr The expression tree to run against the subject
|
|
140
|
-
* @returns {Promise<*>} resolves with the value of the drill-down.
|
|
141
|
-
* @private
|
|
142
|
-
*/
|
|
143
|
-
_filterStatic(subject: any, expr: AstNode) {
|
|
144
|
-
return this.eval(expr).then((res: any) => {
|
|
145
|
-
if (typeof res === 'boolean') {
|
|
146
|
-
return res ? subject : undefined
|
|
147
|
-
}
|
|
148
|
-
return subject?.[res]
|
|
149
|
-
})
|
|
70
|
+
const vals = entries.map(([_, ast]) => this.eval(ast))
|
|
71
|
+
return Object.fromEntries(entries.map(([key], idx) => [key, vals[idx]]))
|
|
150
72
|
}
|
|
151
73
|
}
|
|
152
74
|
|