@allgemein/mango-expressions 1.3.3 → 1.4.0
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/AExpr.d.ts +11 -0
- package/AExpr.js +37 -0
- package/AExpr.js.map +1 -0
- package/Constants.d.ts +3 -0
- package/Constants.js +2 -5
- package/Constants.js.map +1 -1
- package/IWalker.d.ts +19 -0
- package/IWalker.js +2 -0
- package/IWalker.js.map +1 -0
- package/README.md +69 -1
- package/_Expr.d.ts +1 -0
- package/_Expr.js +52 -0
- package/_Expr.js.map +1 -0
- package/ast/AbstractValue.d.ts +7 -0
- package/ast/AbstractValue.js +27 -0
- package/ast/AbstractValue.js.map +1 -0
- package/ast/Bindings.d.ts +1 -2
- package/ast/Bindings.js +1 -5
- package/ast/Bindings.js.map +1 -1
- package/ast/Constan.d.ts +11 -0
- package/ast/Constan.js +2 -0
- package/ast/Constan.js.map +1 -0
- package/ast/Context.js +8 -12
- package/ast/Context.js.map +1 -1
- package/ast/Expr.d.ts +23 -0
- package/ast/Expr.js +90 -0
- package/ast/Expr.js.map +1 -0
- package/ast/IExpr.d.ts +16 -0
- package/ast/IExpr.js +2 -0
- package/ast/IExpr.js.map +1 -0
- package/ast/IParser.d.ts +14 -0
- package/ast/IParser.js +2 -0
- package/ast/IParser.js.map +1 -0
- package/ast/IStackEntry.d.ts +13 -0
- package/ast/IStackEntry.js +2 -0
- package/ast/IStackEntry.js.map +1 -0
- package/ast/JsonParser.d.ts +25 -0
- package/ast/JsonParser.js +60 -0
- package/ast/JsonParser.js.map +1 -0
- package/ast/KeyDesc.d.ts +2 -4
- package/ast/KeyDesc.js +4 -9
- package/ast/KeyDesc.js.map +1 -1
- package/ast/MultiArgs.js +1 -5
- package/ast/MultiArgs.js.map +1 -1
- package/ast/PArray.d.ts +1 -10
- package/ast/PArray.js +67 -53
- package/ast/PArray.js.map +1 -1
- package/ast/PObject.d.ts +1 -17
- package/ast/PObject.js +130 -108
- package/ast/PObject.js.map +1 -1
- package/ast/RefDesc.d.ts +5 -0
- package/ast/RefDesc.js +12 -0
- package/ast/RefDesc.js.map +1 -0
- package/ast/Selector.d.ts +19 -5
- package/ast/Selector.js +31 -9
- package/ast/Selector.js.map +1 -1
- package/ast/StackEntry.d.ts +24 -0
- package/ast/StackEntry.js +121 -0
- package/ast/StackEntry.js.map +1 -0
- package/ast/StringParser.d.ts +16 -0
- package/ast/StringParser.js +303 -0
- package/ast/StringParser.js.map +1 -0
- package/ast/Unset.d.ts +2 -2
- package/ast/Unset.js +2 -6
- package/ast/Unset.js.map +1 -1
- package/ast/ValueDesc.d.ts +4 -0
- package/ast/ValueDesc.js +9 -0
- package/ast/ValueDesc.js.map +1 -0
- package/ast/functions.d.ts +1 -0
- package/ast/functions.js +8 -0
- package/ast/functions.js.map +1 -0
- package/browser.d.ts +52 -55
- package/browser.js +53 -117
- package/browser.js.map +1 -1
- package/errors/InvalidValueError.d.ts +4 -0
- package/errors/InvalidValueError.js +6 -0
- package/errors/InvalidValueError.js.map +1 -0
- package/errors/NotYetImplementedError.d.ts +3 -0
- package/errors/NotYetImplementedError.js +6 -0
- package/errors/NotYetImplementedError.js.map +1 -0
- package/errors/UnsupportedInputError.d.ts +3 -0
- package/errors/UnsupportedInputError.js +6 -0
- package/errors/UnsupportedInputError.js.map +1 -0
- package/functions.d.ts +9 -0
- package/functions.js +107 -0
- package/functions.js.map +1 -0
- package/index.d.ts +1 -1
- package/index.js +5 -64
- package/index.js.map +1 -1
- package/operators/AbstractCompare.d.ts +23 -0
- package/operators/AbstractCompare.js +100 -0
- package/operators/AbstractCompare.js.map +1 -0
- package/operators/AbstractFunction.d.ts +6 -0
- package/operators/AbstractFunction.js +10 -0
- package/operators/AbstractFunction.js.map +1 -0
- package/operators/AbstractJunctor.d.ts +13 -0
- package/operators/AbstractJunctor.js +31 -0
- package/operators/AbstractJunctor.js.map +1 -0
- package/operators/AbstractJunctorArray.d.ts +18 -0
- package/operators/AbstractJunctorArray.js +63 -0
- package/operators/AbstractJunctorArray.js.map +1 -0
- package/operators/AbstractOperator.d.ts +6 -6
- package/operators/AbstractOperator.js +12 -31
- package/operators/AbstractOperator.js.map +1 -1
- package/operators/Components.d.ts +30 -0
- package/operators/Components.js +140 -0
- package/operators/Components.js.map +1 -0
- package/operators/arithmetic/Avg.d.ts +2 -2
- package/operators/arithmetic/Avg.js +2 -6
- package/operators/arithmetic/Avg.js.map +1 -1
- package/operators/arithmetic/Count.d.ts +2 -2
- package/operators/arithmetic/Count.js +2 -6
- package/operators/arithmetic/Count.js.map +1 -1
- package/operators/arithmetic/Max.d.ts +2 -2
- package/operators/arithmetic/Max.js +2 -6
- package/operators/arithmetic/Max.js.map +1 -1
- package/operators/arithmetic/Min.d.ts +2 -2
- package/operators/arithmetic/Min.js +2 -6
- package/operators/arithmetic/Min.js.map +1 -1
- package/operators/arithmetic/Multiply.d.ts +2 -2
- package/operators/arithmetic/Multiply.js +2 -6
- package/operators/arithmetic/Multiply.js.map +1 -1
- package/operators/arithmetic/Sum.d.ts +2 -2
- package/operators/arithmetic/Sum.js +2 -6
- package/operators/arithmetic/Sum.js.map +1 -1
- package/operators/array/First.d.ts +2 -4
- package/operators/array/First.js +9 -15
- package/operators/array/First.js.map +1 -1
- package/operators/array/Last.d.ts +2 -4
- package/operators/array/Last.js +9 -15
- package/operators/array/Last.js.map +1 -1
- package/operators/array/Map.d.ts +5 -6
- package/operators/array/Map.js +14 -20
- package/operators/array/Map.js.map +1 -1
- package/operators/compare/EqualDesc.d.ts +6 -7
- package/operators/compare/EqualDesc.js +13 -11
- package/operators/compare/EqualDesc.js.map +1 -1
- package/operators/compare/EqualDescLookup.d.ts +2 -2
- package/operators/compare/EqualDescLookup.js +24 -31
- package/operators/compare/EqualDescLookup.js.map +1 -1
- package/operators/compare/GreaterThen.d.ts +3 -4
- package/operators/compare/GreaterThen.js +3 -7
- package/operators/compare/GreaterThen.js.map +1 -1
- package/operators/compare/GreaterThenEqual.d.ts +3 -4
- package/operators/compare/GreaterThenEqual.js +3 -7
- package/operators/compare/GreaterThenEqual.js.map +1 -1
- package/operators/compare/In.d.ts +3 -4
- package/operators/compare/In.js +3 -7
- package/operators/compare/In.js.map +1 -1
- package/operators/compare/IsNotNull.d.ts +3 -3
- package/operators/compare/IsNotNull.js +3 -7
- package/operators/compare/IsNotNull.js.map +1 -1
- package/operators/compare/IsNull.d.ts +3 -3
- package/operators/compare/IsNull.js +3 -7
- package/operators/compare/IsNull.js.map +1 -1
- package/operators/compare/LessThen.d.ts +3 -3
- package/operators/compare/LessThen.js +3 -6
- package/operators/compare/LessThen.js.map +1 -1
- package/operators/compare/LessThenEqual.d.ts +3 -4
- package/operators/compare/LessThenEqual.js +3 -7
- package/operators/compare/LessThenEqual.js.map +1 -1
- package/operators/compare/Like.d.ts +3 -4
- package/operators/compare/Like.js +3 -7
- package/operators/compare/Like.js.map +1 -1
- package/operators/compare/NotEqual.d.ts +3 -4
- package/operators/compare/NotEqual.js +3 -7
- package/operators/compare/NotEqual.js.map +1 -1
- package/operators/compare/NotIn.d.ts +3 -4
- package/operators/compare/NotIn.js +3 -7
- package/operators/compare/NotIn.js.map +1 -1
- package/operators/compare/Regex.d.ts +2 -6
- package/operators/compare/Regex.js +28 -33
- package/operators/compare/Regex.js.map +1 -1
- package/operators/date/Date.d.ts +2 -2
- package/operators/date/Date.js +3 -6
- package/operators/date/Date.js.map +1 -1
- package/operators/date/DateToString.d.ts +4 -5
- package/operators/date/DateToString.js +15 -20
- package/operators/date/DateToString.js.map +1 -1
- package/operators/date/Day.d.ts +2 -2
- package/operators/date/Day.js +2 -6
- package/operators/date/Day.js.map +1 -1
- package/operators/date/Month.d.ts +2 -2
- package/operators/date/Month.js +2 -6
- package/operators/date/Month.js.map +1 -1
- package/operators/date/Year.d.ts +2 -2
- package/operators/date/Year.js +2 -6
- package/operators/date/Year.js.map +1 -1
- package/operators/logic/AndDesc.d.ts +5 -7
- package/operators/logic/AndDesc.js +16 -21
- package/operators/logic/AndDesc.js.map +1 -1
- package/operators/logic/AndDescLookup.d.ts +2 -2
- package/operators/logic/AndDescLookup.js +1 -5
- package/operators/logic/AndDescLookup.js.map +1 -1
- package/operators/logic/NotDesc.d.ts +8 -0
- package/operators/logic/NotDesc.js +21 -0
- package/operators/logic/NotDesc.js.map +1 -0
- package/operators/logic/OrDesc.d.ts +5 -7
- package/operators/logic/OrDesc.js +5 -21
- package/operators/logic/OrDesc.js.map +1 -1
- package/operators/stage/AbstractSection.d.ts +7 -0
- package/operators/stage/AbstractSection.js +11 -0
- package/operators/stage/AbstractSection.js.map +1 -0
- package/operators/stage/Group.d.ts +4 -10
- package/operators/stage/Group.js +33 -39
- package/operators/stage/Group.js.map +1 -1
- package/operators/stage/Limit.d.ts +2 -2
- package/operators/stage/Limit.js +2 -6
- package/operators/stage/Limit.js.map +1 -1
- package/operators/stage/Match.d.ts +2 -8
- package/operators/stage/Match.js +2 -20
- package/operators/stage/Match.js.map +1 -1
- package/operators/stage/Project.d.ts +2 -8
- package/operators/stage/Project.js +17 -21
- package/operators/stage/Project.js.map +1 -1
- package/operators/stage/Query..d.ts +1 -0
- package/operators/stage/Query..js +3 -0
- package/operators/stage/Query..js.map +1 -0
- package/operators/stage/Skip.d.ts +2 -6
- package/operators/stage/Skip.js +6 -11
- package/operators/stage/Skip.js.map +1 -1
- package/operators/stage/Sort.d.ts +2 -6
- package/operators/stage/Sort.js +6 -11
- package/operators/stage/Sort.js.map +1 -1
- package/operators/string/Substr.d.ts +2 -4
- package/operators/string/Substr.js +19 -22
- package/operators/string/Substr.js.map +1 -1
- package/operators/string/ToFloat.d.ts +2 -3
- package/operators/string/ToFloat.js +9 -15
- package/operators/string/ToFloat.js.map +1 -1
- package/operators/string/ToInt.d.ts +2 -3
- package/operators/string/ToInt.js +9 -15
- package/operators/string/ToInt.js.map +1 -1
- package/operators/string/ToLower.d.ts +2 -3
- package/operators/string/ToLower.js +9 -15
- package/operators/string/ToLower.js.map +1 -1
- package/operators/string/ToUpper.d.ts +2 -4
- package/operators/string/ToUpper.js +9 -15
- package/operators/string/ToUpper.js.map +1 -1
- package/package.json +2 -1
- package/walker/lookup/ILookupFn.d.ts +2 -2
- package/walker/lookup/ILookupFn.js +1 -2
- package/walker/lookup/LookupWalker.d.ts +11 -11
- package/walker/lookup/LookupWalker.js +19 -23
- package/walker/lookup/LookupWalker.js.map +1 -1
- package/IMangoWalker.d.ts +0 -19
- package/IMangoWalker.js +0 -3
- package/IMangoWalker.js.map +0 -1
- package/MangoExpression.d.ts +0 -15
- package/MangoExpression.js +0 -88
- package/MangoExpression.js.map +0 -1
- package/ast/PAst.d.ts +0 -42
- package/ast/PAst.js +0 -158
- package/ast/PAst.js.map +0 -1
- package/ast/PValue.d.ts +0 -10
- package/ast/PValue.js +0 -22
- package/ast/PValue.js.map +0 -1
- package/ast/Value.d.ts +0 -3
- package/ast/Value.js +0 -8
- package/ast/Value.js.map +0 -1
- package/ast/ValueRef.d.ts +0 -4
- package/ast/ValueRef.js +0 -11
- package/ast/ValueRef.js.map +0 -1
- package/operators/Operators.d.ts +0 -35
- package/operators/Operators.js +0 -149
- package/operators/Operators.js.map +0 -1
- package/operators/compare/AbstractCompare.d.ts +0 -5
- package/operators/compare/AbstractCompare.js +0 -14
- package/operators/compare/AbstractCompare.js.map +0 -1
- package/operators/logic/AbstractLogic.d.ts +0 -3
- package/operators/logic/AbstractLogic.js +0 -8
- package/operators/logic/AbstractLogic.js.map +0 -1
- package/operators/logic/Not.d.ts +0 -8
- package/operators/logic/Not.js +0 -22
- package/operators/logic/Not.js.map +0 -1
package/AExpr.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Expr } from "./ast/Expr.js";
|
|
2
|
+
import { KeyDesc } from "./ast/KeyDesc.js";
|
|
3
|
+
import { RefDesc } from "./ast/RefDesc.js";
|
|
4
|
+
export declare class AExpr {
|
|
5
|
+
private expr;
|
|
6
|
+
static from(expr: Expr): AExpr;
|
|
7
|
+
constructor(expr: Expr);
|
|
8
|
+
getKeys(): KeyDesc[];
|
|
9
|
+
getRefs(): RefDesc[];
|
|
10
|
+
getKeyValueMap(value_escape?: string): any;
|
|
11
|
+
}
|
package/AExpr.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { KeyDesc } from "./ast/KeyDesc.js";
|
|
2
|
+
import { RefDesc } from "./ast/RefDesc.js";
|
|
3
|
+
import { AbstractCompare } from "./operators/AbstractCompare.js";
|
|
4
|
+
import { ValueDesc } from "./ast/ValueDesc.js";
|
|
5
|
+
export class AExpr {
|
|
6
|
+
static from(expr) {
|
|
7
|
+
return new AExpr(expr);
|
|
8
|
+
}
|
|
9
|
+
constructor(expr) {
|
|
10
|
+
this.expr = expr;
|
|
11
|
+
}
|
|
12
|
+
getKeys() {
|
|
13
|
+
return this.expr.collect(x => x instanceof KeyDesc);
|
|
14
|
+
}
|
|
15
|
+
getRefs() {
|
|
16
|
+
return this.expr.collect(x => x instanceof RefDesc);
|
|
17
|
+
}
|
|
18
|
+
getKeyValueMap(value_escape = '\'') {
|
|
19
|
+
const comparers = this.expr.collect(x => x instanceof AbstractCompare);
|
|
20
|
+
const map = {};
|
|
21
|
+
for (const comparer of comparers) {
|
|
22
|
+
const key = comparer.getLeftSide();
|
|
23
|
+
const value = comparer.getRightSide();
|
|
24
|
+
if (key instanceof KeyDesc) {
|
|
25
|
+
const keyValue = key.getValue() + '';
|
|
26
|
+
if (value instanceof ValueDesc) {
|
|
27
|
+
map[keyValue] = `${value_escape}${value.getValue()}${value_escape}`;
|
|
28
|
+
}
|
|
29
|
+
else if (value instanceof RefDesc) {
|
|
30
|
+
map[keyValue] = value.getValue();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return map;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=AExpr.js.map
|
package/AExpr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AExpr.js","sourceRoot":"","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G,KAAK,CAAC,QAAQ,EAAE,GAAG,YAAY,EAAE,CAAC;gBACtE,CAAC;qBAAM,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;oBACpC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/Constants.d.ts
CHANGED
package/Constants.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.NUMBER_PROJECT_SUPPORT = exports.AUTO_EQUAL_CONV_SUPPORT = void 0;
|
|
4
|
-
exports.AUTO_EQUAL_CONV_SUPPORT = 'AUTO_EQUAL_CONV_SUPPORT';
|
|
5
|
-
exports.NUMBER_PROJECT_SUPPORT = 'NUMBER_PROJECT_SUPPORT';
|
|
1
|
+
export const AUTO_EQUAL_CONV_SUPPORT = 'AUTO_EQUAL_CONV_SUPPORT';
|
|
2
|
+
export const NUMBER_PROJECT_SUPPORT = 'NUMBER_PROJECT_SUPPORT';
|
|
6
3
|
//# sourceMappingURL=Constants.js.map
|
package/Constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC"}
|
package/IWalker.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Expr } from './ast/Expr.js';
|
|
2
|
+
export interface IWalkerControl {
|
|
3
|
+
abort?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface IWalker {
|
|
6
|
+
/**
|
|
7
|
+
* return the array
|
|
8
|
+
*
|
|
9
|
+
* @param ast
|
|
10
|
+
*/
|
|
11
|
+
visitArray(ast: Expr, ctrl?: IWalkerControl): any[];
|
|
12
|
+
leaveArray(res: any[], ast: Expr): any;
|
|
13
|
+
visitObject(ast: Expr, ctrl?: IWalkerControl): any;
|
|
14
|
+
leaveObject(res: any, ast: Expr): any;
|
|
15
|
+
onValue(ast: Expr, ctrl?: IWalkerControl): any;
|
|
16
|
+
onOperator(ast: Expr, valueRes: any, ctrl?: IWalkerControl): any;
|
|
17
|
+
visitOperator(ast: Expr, ctrl?: IWalkerControl): any;
|
|
18
|
+
leaveOperator(res: any, ast: Expr): any;
|
|
19
|
+
}
|
package/IWalker.js
ADDED
package/IWalker.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IWalker.js","sourceRoot":"","sources":["../../src/IWalker.ts"],"names":[],"mappings":""}
|
package/README.md
CHANGED
|
@@ -5,6 +5,74 @@
|
|
|
5
5
|
[](https://david-dm.org/allgemein/mango-expressionse)
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
Implemetation of mongo-like quering pipeline interpreter.
|
|
8
|
+
Implemetation of mongo-like quering pipeline interpreter.
|
|
9
9
|
(@see: https://docs.mongodb.com/manual/reference/operator/aggregation/)
|
|
10
10
|
|
|
11
|
+
`@allgemein/mango-expressions` parses plain JSON query descriptors that look like MongoDB
|
|
12
|
+
aggregation/query operators (`$eq`, `$and`, `$or`, `$in`, `$match`, `$group`, ...) into a typed
|
|
13
|
+
AST of expression nodes, and also lets you build that AST programmatically. The resulting
|
|
14
|
+
expression tree can be serialized back to JSON, walked/visited (e.g. to build a lookup/validation
|
|
15
|
+
function), or analysed (collect referenced keys and value/key mappings).
|
|
16
|
+
|
|
17
|
+
It is useful whenever you need a mongo-like, JSON-serializable query language independent of an
|
|
18
|
+
actual MongoDB connection, e.g. for filtering in-memory objects, building REST query languages, or
|
|
19
|
+
translating between different query representations.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm i @allgemein/mango-expressions
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Parsing a mango/mongo-like expression
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {expr} from '@allgemein/mango-expressions/functions';
|
|
33
|
+
|
|
34
|
+
const cond = expr({id: 1, role: 'admin'});
|
|
35
|
+
console.log(cond.toJson());
|
|
36
|
+
// => {$and: [{id: {$eq: 1}}, {role: {$eq: 'admin'}}]}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Building expressions programmatically
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import {And, Eq, Value, Ref} from '@allgemein/mango-expressions';
|
|
43
|
+
|
|
44
|
+
const condition = And(
|
|
45
|
+
Eq('tableName', Value('condition_keeper')),
|
|
46
|
+
Eq('tableId', Ref('id'))
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
console.log(condition.toJson());
|
|
50
|
+
// => {$and: [{tableName: {$eq: 'condition_keeper'}}, {tableId: {$eq: '$id'}}]}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Analysing an expression tree
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import {And, Eq, Value, Ref} from '@allgemein/mango-expressions';
|
|
57
|
+
import {AExpr} from '@allgemein/mango-expressions/AExpr';
|
|
58
|
+
|
|
59
|
+
const condition = And(Eq('tableName', Value('condition_keeper')), Eq('tableId', Ref('id')));
|
|
60
|
+
const analysed = AExpr.from(condition);
|
|
61
|
+
|
|
62
|
+
const keys = analysed.getKeys(); // referenced source keys
|
|
63
|
+
const refs = analysed.getRefs(); // referenced target keys ($-references)
|
|
64
|
+
const map = analysed.getKeyValueMap(); // key -> value/reference mapping
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
* Parse plain JSON mongo-like query descriptors into a typed AST (`expr(...)`)
|
|
70
|
+
* Comparison operators: `Eq`, `NotEqual`, `GreaterThen(Equal)`, `LessThen(Equal)`, `In`, `NotIn`,
|
|
71
|
+
`Like`, `Regex`, `IsNull`, `IsNotNull`
|
|
72
|
+
* Logical operators: `And`, `Or`, `Not`
|
|
73
|
+
* Pipeline/stage operators: `Match`, `Project`, `Group`, `Sort`, `Limit`, `Skip`
|
|
74
|
+
* Arithmetic/array/string/date operators: `Sum`, `Avg`, `Min`, `Max`, `Count`, `Multiply`,
|
|
75
|
+
`Map`, `First`, `Last`, `Substr`, `ToInt`, `ToFloat`, `ToLower`, `ToUpper`, `Date`,
|
|
76
|
+
`DateToString`, `Day`, `Month`, `Year`
|
|
77
|
+
* Serialize any expression tree back to its JSON representation via `toJson()`
|
|
78
|
+
* Analyse expressions with `AExpr` to collect referenced keys, references, and key/value maps
|
package/_Expr.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/_Expr.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
// import {PAst} from './ast/PAst';
|
|
3
|
+
//
|
|
4
|
+
// import {ValueRef} from './ast/ValueRef';
|
|
5
|
+
// import {Value} from './ast/Value';
|
|
6
|
+
// import {PArray} from './ast/PArray.js';
|
|
7
|
+
// import {PObject} from './ast/PObject.js';
|
|
8
|
+
// import {Operators} from './operators/Operators';
|
|
9
|
+
// import {IWalker} from './IWalker.js';
|
|
10
|
+
// import {Context} from './ast/Context.js';
|
|
11
|
+
// import {AUTO_EQUAL_CONV_SUPPORT} from './Constants.js';
|
|
12
|
+
// import {ClassType} from '@allgemein/schema-api';
|
|
13
|
+
// import {isArray, isBoolean, isDate, isNull, isNumber, isObjectLike, isString} from "@allgemein/base";
|
|
14
|
+
//
|
|
15
|
+
// export class Expr extends PAst<any> {
|
|
16
|
+
//
|
|
17
|
+
// // readonly root: PAst<any> = null;
|
|
18
|
+
//
|
|
19
|
+
// static parse(def: any): Expr {
|
|
20
|
+
// return new Expr(def);
|
|
21
|
+
// }
|
|
22
|
+
//
|
|
23
|
+
// constructor(def: any) {
|
|
24
|
+
// // default change object assignment to value
|
|
25
|
+
// const ctxt = new Context();
|
|
26
|
+
// ctxt.set(AUTO_EQUAL_CONV_SUPPORT, true);
|
|
27
|
+
// this.root = this.interprete(def, null, ctxt);
|
|
28
|
+
// }
|
|
29
|
+
//
|
|
30
|
+
// // getByKey(key: string) {
|
|
31
|
+
// // return this.root.getByKey(key);
|
|
32
|
+
// // }
|
|
33
|
+
// //
|
|
34
|
+
// // getRoot() {
|
|
35
|
+
// // return this.root;
|
|
36
|
+
// // }
|
|
37
|
+
//
|
|
38
|
+
//
|
|
39
|
+
//
|
|
40
|
+
//
|
|
41
|
+
// // visit(o: IWalker) {
|
|
42
|
+
// // return this.root.visit(o);
|
|
43
|
+
// // }
|
|
44
|
+
//
|
|
45
|
+
//
|
|
46
|
+
//
|
|
47
|
+
// // toJson() {
|
|
48
|
+
// // return this.root.toJson();
|
|
49
|
+
// // }
|
|
50
|
+
//
|
|
51
|
+
// }
|
|
52
|
+
//# sourceMappingURL=_Expr.js.map
|
package/_Expr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_Expr.js","sourceRoot":"","sources":["../../src/_Expr.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC,EAAE;AACF,2CAA2C;AAC3C,qCAAqC;AACrC,0CAA0C;AAC1C,4CAA4C;AAC5C,mDAAmD;AACnD,wCAAwC;AACxC,4CAA4C;AAC5C,0DAA0D;AAC1D,mDAAmD;AACnD,wGAAwG;AACxG,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,mCAAmC;AACnC,4BAA4B;AAC5B,MAAM;AACN,EAAE;AACF,4BAA4B;AAC5B,mDAAmD;AACnD,kCAAkC;AAClC,+CAA+C;AAC/C,oDAAoD;AACpD,MAAM;AACN,EAAE;AACF,+BAA+B;AAC/B,yCAAyC;AACzC,SAAS;AACT,OAAO;AACP,mBAAmB;AACnB,2BAA2B;AAC3B,SAAS;AACT,EAAE;AACF,EAAE;AACF,EAAE;AACF,EAAE;AACF,2BAA2B;AAC3B,oCAAoC;AACpC,SAAS;AACT,EAAE;AACF,EAAE;AACF,EAAE;AACF,kBAAkB;AAClB,oCAAoC;AACpC,SAAS;AACT,EAAE;AACF,IAAI"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Expr } from './Expr.js';
|
|
2
|
+
import { AbstractCompare } from "../operators/AbstractCompare.js";
|
|
3
|
+
export class AbstractValue extends Expr {
|
|
4
|
+
parse(entry, parital) {
|
|
5
|
+
const parent = entry.getParentComp();
|
|
6
|
+
if (parent instanceof AbstractCompare) {
|
|
7
|
+
parent.setRightSide(this);
|
|
8
|
+
this.setParent(parent);
|
|
9
|
+
}
|
|
10
|
+
else if (parent instanceof Expr) {
|
|
11
|
+
this.setParent(parent);
|
|
12
|
+
}
|
|
13
|
+
this.value = parital;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
// getByKey(key: string): Expr {
|
|
17
|
+
// throw new NotYetImplementedError();
|
|
18
|
+
// }
|
|
19
|
+
//
|
|
20
|
+
// visit(o: IWalker): any {
|
|
21
|
+
// return o.onValue(this);
|
|
22
|
+
// }
|
|
23
|
+
toJson() {
|
|
24
|
+
return this.value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=AbstractValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractValue.js","sourceRoot":"","sources":["../../../src/ast/AbstractValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAGhE,MAAM,OAAgB,aAAc,SAAQ,IAAI;IAE9C,KAAK,CAAC,KAAkB,EAAE,OAAY;QACpC,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,EAAE,CAAA;QACpC,IAAI,MAAM,YAAY,eAAe,EAAE,CAAC;YACtC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;aAAM,IAAI,MAAM,YAAY,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gCAAgC;IAChC,wCAAwC;IACxC,IAAI;IACJ,EAAE;IACF,2BAA2B;IAC3B,4BAA4B;IAC5B,IAAI;IAEJ,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
package/ast/Bindings.d.ts
CHANGED
package/ast/Bindings.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Bindings = void 0;
|
|
4
|
-
class Bindings {
|
|
1
|
+
export class Bindings {
|
|
5
2
|
constructor(name) {
|
|
6
3
|
this.list = [];
|
|
7
4
|
this.name = name;
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.Bindings = Bindings;
|
|
11
7
|
//# sourceMappingURL=Bindings.js.map
|
package/ast/Bindings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bindings.js","sourceRoot":"","sources":["../../../src/ast/Bindings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Bindings.js","sourceRoot":"","sources":["../../../src/ast/Bindings.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,QAAQ;IAMnB,YAAY,IAAY;QAFxB,SAAI,GAAkB,EAAE,CAAC;QAGvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CAEF"}
|
package/ast/Constan.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClassType } from "../Constants.js";
|
|
2
|
+
export type PATH_KEY = string | number;
|
|
3
|
+
export interface IHint {
|
|
4
|
+
comp: ClassType<any>;
|
|
5
|
+
/**
|
|
6
|
+
* Resolve partial in partial_key and partial_rest
|
|
7
|
+
*
|
|
8
|
+
* @param partial
|
|
9
|
+
*/
|
|
10
|
+
resolve: (partial: any) => [any, any];
|
|
11
|
+
}
|
package/ast/Constan.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constan.js","sourceRoot":"","sources":["../../../src/ast/Constan.ts"],"names":[],"mappings":""}
|
package/ast/Context.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Context = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
class Context {
|
|
1
|
+
import { merge, has, get, isObjectLike, assign } from '@allgemein/base';
|
|
2
|
+
export class Context {
|
|
6
3
|
constructor(k) {
|
|
7
4
|
this.data = {};
|
|
8
5
|
this.key = k;
|
|
@@ -13,7 +10,7 @@ class Context {
|
|
|
13
10
|
* @param ctxt
|
|
14
11
|
*/
|
|
15
12
|
has(ctxt) {
|
|
16
|
-
return
|
|
13
|
+
return has(this.data, ctxt);
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
16
|
* get context value
|
|
@@ -22,7 +19,7 @@ class Context {
|
|
|
22
19
|
*/
|
|
23
20
|
get(k) {
|
|
24
21
|
if (k) {
|
|
25
|
-
return
|
|
22
|
+
return get(this.data, k, null);
|
|
26
23
|
}
|
|
27
24
|
return this.data;
|
|
28
25
|
}
|
|
@@ -34,18 +31,17 @@ class Context {
|
|
|
34
31
|
*/
|
|
35
32
|
set(k, value) {
|
|
36
33
|
if (!this.has(k)) {
|
|
37
|
-
this.data[k] =
|
|
34
|
+
this.data[k] = isObjectLike(value) ? {} : null;
|
|
38
35
|
}
|
|
39
|
-
if (
|
|
40
|
-
this.data[k] =
|
|
36
|
+
if (isObjectLike()) {
|
|
37
|
+
this.data[k] = assign(this.data[k], value);
|
|
41
38
|
}
|
|
42
39
|
else {
|
|
43
40
|
this.data[k] = value;
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
merge(ctx) {
|
|
47
|
-
this.data =
|
|
44
|
+
this.data = merge(this.data, ctx.data);
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
|
-
exports.Context = Context;
|
|
51
47
|
//# sourceMappingURL=Context.js.map
|
package/ast/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../src/ast/Context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../src/ast/Context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEtE,MAAM,OAAO,OAAO;IAMlB,YAAY,CAAmB;QAF/B,SAAI,GAAyB,EAAE,CAAC;QAG9B,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IAGD;;;;OAIG;IACH,GAAG,CAAC,CAAU;QACZ,IAAI,CAAC,EAAE,CAAC;YACN,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAGD;;;;;OAKG;IACH,GAAG,CAAC,CAAS,EAAE,KAAU;QACvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,CAAC;QACD,IAAI,YAAY,EAAE,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC;IAEH,CAAC;IAGD,KAAK,CAAC,GAAY;QAChB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CAEF"}
|
package/ast/Expr.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IExpr } from "./IExpr.js";
|
|
2
|
+
import { IStackEntry } from "./IStackEntry.js";
|
|
3
|
+
export declare abstract class Expr implements IExpr {
|
|
4
|
+
/**
|
|
5
|
+
* Reference to the root expression
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
root: IExpr;
|
|
10
|
+
parent: IExpr;
|
|
11
|
+
value: any;
|
|
12
|
+
parse(entry: IStackEntry, partial: any, key: string | number): IExpr;
|
|
13
|
+
isOp(): boolean;
|
|
14
|
+
isGroup(): boolean;
|
|
15
|
+
getChildren(): IExpr[];
|
|
16
|
+
getValue(): any;
|
|
17
|
+
setValue(v: any): void;
|
|
18
|
+
getParent(): IExpr;
|
|
19
|
+
setParent(parent: IExpr): void;
|
|
20
|
+
getRootExpression(): IExpr;
|
|
21
|
+
collect(fn: (x: IExpr) => boolean): IExpr[];
|
|
22
|
+
toJson(): any;
|
|
23
|
+
}
|
package/ast/Expr.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { isArray, isNumber, isString } from '@allgemein/base';
|
|
2
|
+
export class Expr {
|
|
3
|
+
parse(entry, partial, key) {
|
|
4
|
+
const parent = entry.getParentComp();
|
|
5
|
+
if (parent) {
|
|
6
|
+
this.setParent(parent);
|
|
7
|
+
}
|
|
8
|
+
entry.enqueue(partial, key);
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
isOp() {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
isGroup() {
|
|
15
|
+
return isArray(this.value);
|
|
16
|
+
}
|
|
17
|
+
getChildren() {
|
|
18
|
+
if (this.value instanceof Expr) {
|
|
19
|
+
return [this.value];
|
|
20
|
+
}
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
getValue() {
|
|
24
|
+
return this.value;
|
|
25
|
+
}
|
|
26
|
+
setValue(v) {
|
|
27
|
+
this.value = v;
|
|
28
|
+
// this.applyParent(v);
|
|
29
|
+
}
|
|
30
|
+
getParent() {
|
|
31
|
+
return this.parent;
|
|
32
|
+
}
|
|
33
|
+
setParent(parent) {
|
|
34
|
+
this.parent = parent;
|
|
35
|
+
}
|
|
36
|
+
getRootExpression() {
|
|
37
|
+
if (this.parent) {
|
|
38
|
+
return this.parent.getRootExpression();
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
collect(fn) {
|
|
43
|
+
const queue = [this];
|
|
44
|
+
const ret = [];
|
|
45
|
+
while (queue.length > 0) {
|
|
46
|
+
const first = queue.shift();
|
|
47
|
+
if (fn(first)) {
|
|
48
|
+
ret.push(first);
|
|
49
|
+
}
|
|
50
|
+
const child = first.getChildren();
|
|
51
|
+
child.forEach(x => queue.push(x));
|
|
52
|
+
}
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
55
|
+
toJson() {
|
|
56
|
+
let obj = null;
|
|
57
|
+
let key = this.getParent();
|
|
58
|
+
const value = this.getValue();
|
|
59
|
+
if (isNumber(key)) {
|
|
60
|
+
// is possibly part of an array, so return only the value
|
|
61
|
+
if (value instanceof Expr) {
|
|
62
|
+
obj = value.toJson();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
obj = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (isString(key)) {
|
|
69
|
+
// is an object, so return an object with key
|
|
70
|
+
if (value instanceof Expr) {
|
|
71
|
+
obj = { [key]: value.toJson() };
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
obj = { [key]: value };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (key instanceof Expr) {
|
|
78
|
+
const _key = key.toJson();
|
|
79
|
+
// is an object, so return an object with key
|
|
80
|
+
if (value instanceof Expr) {
|
|
81
|
+
obj = { [_key]: value.toJson() };
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
obj = { [_key]: value };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return obj;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=Expr.js.map
|
package/ast/Expr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Expr.js","sourceRoot":"","sources":["../../../src/ast/Expr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAK5D,MAAM,OAAgB,IAAI;IAkBxB,KAAK,CAAC,KAAkB,EAAE,OAAY,EAAE,GAAoB;QAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,EAAE,CAAA;QACpC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,OAAO,OAAO,CAAC,IAAI,C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
8
|
+
* @param parent
|
|
9
|
+
*/
|
|
10
|
+
parse?(entry: IStackEntry, partial: any, key?: string | number): IExpr;
|
|
11
|
+
toJson(): any;
|
|
12
|
+
getRootExpression(): IExpr;
|
|
13
|
+
getParent(): IExpr;
|
|
14
|
+
getChildren(): IExpr[];
|
|
15
|
+
setParent(parent: IExpr): void;
|
|
16
|
+
}
|
package/ast/IExpr.js
ADDED
package/ast/IExpr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IExpr.js","sourceRoot":"","sources":["../../../src/ast/IExpr.ts"],"names":[],"mappings":""}
|
package/ast/IParser.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IStackEntry, CALLBACK } from "./IStackEntry.js";
|
|
2
|
+
import { IHint, PATH_KEY } from "./Constan.js";
|
|
3
|
+
export interface IParser {
|
|
4
|
+
/**
|
|
5
|
+
* Add new partial in queue with
|
|
6
|
+
*
|
|
7
|
+
* @param partial
|
|
8
|
+
* @param path
|
|
9
|
+
* @param callback - when da
|
|
10
|
+
* @param hint
|
|
11
|
+
*/
|
|
12
|
+
enqueue(partial: any, path: PATH_KEY[], callback?: CALLBACK, hint?: IHint): IStackEntry;
|
|
13
|
+
keep(param: IStackEntry): void;
|
|
14
|
+
}
|
package/ast/IParser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IParser.js","sourceRoot":"","sources":["../../../src/ast/IParser.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IExpr } from "./IExpr.js";
|
|
2
|
+
import { IHint, PATH_KEY } from "./Constan.js";
|
|
3
|
+
export type CALLBACK = (result: IStackEntry) => void;
|
|
4
|
+
export interface IStackEntry {
|
|
5
|
+
parent: IStackEntry;
|
|
6
|
+
children: IStackEntry[];
|
|
7
|
+
partial: any;
|
|
8
|
+
pathToPartial: PATH_KEY[];
|
|
9
|
+
callback?: CALLBACK;
|
|
10
|
+
comp: IExpr;
|
|
11
|
+
enqueue(partial: any, path?: PATH_KEY, callback?: CALLBACK, hint?: IHint): void;
|
|
12
|
+
getParentComp(): IExpr;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IStackEntry.js","sourceRoot":"","sources":["../../../src/ast/IStackEntry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IExpr } from "./IExpr.js";
|
|
2
|
+
import { IParser } from "./IParser.js";
|
|
3
|
+
import { CALLBACK, IStackEntry } from "./IStackEntry.js";
|
|
4
|
+
import { StackEntry } from "./StackEntry.js";
|
|
5
|
+
import { IHint } from "./Constan.js";
|
|
6
|
+
/**
|
|
7
|
+
* Parser iterate over mango object and build the AST
|
|
8
|
+
*
|
|
9
|
+
* - Selectors (Key) - referring value
|
|
10
|
+
* - Value - Constant fixed values in value
|
|
11
|
+
* - ValueRef - Reference to a selector
|
|
12
|
+
* - Operators have a leftSide and a rightSide
|
|
13
|
+
* - Functions - Operate on passed values
|
|
14
|
+
*
|
|
15
|
+
* - DFS is used
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare class JsonParser implements IParser {
|
|
19
|
+
root: StackEntry;
|
|
20
|
+
forward: StackEntry[];
|
|
21
|
+
constructor(partial: any);
|
|
22
|
+
enqueue(partial: any, path: string[], callback?: CALLBACK, hint?: IHint): IStackEntry;
|
|
23
|
+
keep(entry: StackEntry): void;
|
|
24
|
+
parse(): IExpr;
|
|
25
|
+
}
|