@allgemein/mango-expressions 1.1.1 → 1.3.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/Constants.js +1 -2
- package/Constants.js.map +1 -1
- package/IMangoWalker.d.ts +8 -8
- package/IMangoWalker.js +1 -2
- package/IMangoWalker.js.map +1 -1
- package/LICENSE +1 -1
- package/MangoExpression.d.ts +8 -4
- package/MangoExpression.js +35 -25
- package/MangoExpression.js.map +1 -1
- package/ast/Bindings.d.ts +11 -0
- package/ast/Bindings.js +11 -0
- package/ast/Bindings.js.map +1 -0
- package/ast/Context.js +8 -9
- package/ast/Context.js.map +1 -1
- package/ast/KeyDesc.d.ts +10 -0
- package/ast/KeyDesc.js +20 -0
- package/ast/KeyDesc.js.map +1 -0
- package/ast/MultiArgs.js +1 -2
- package/ast/MultiArgs.js.map +1 -1
- package/ast/PArray.d.ts +3 -5
- package/ast/PArray.js +19 -17
- package/ast/PArray.js.map +1 -1
- package/ast/PAst.d.ts +23 -8
- package/ast/PAst.js +114 -8
- package/ast/PAst.js.map +1 -1
- package/ast/PObject.d.ts +10 -9
- package/ast/PObject.js +58 -33
- package/ast/PObject.js.map +1 -1
- package/ast/PValue.d.ts +4 -4
- package/ast/PValue.js +7 -5
- package/ast/PValue.js.map +1 -1
- package/ast/Selector.d.ts +6 -0
- package/ast/Selector.js +13 -0
- package/ast/Selector.js.map +1 -0
- package/ast/Unset.js +1 -2
- package/ast/Unset.js.map +1 -1
- package/ast/Value.js +1 -2
- package/ast/Value.js.map +1 -1
- package/ast/ValueRef.d.ts +1 -0
- package/ast/ValueRef.js +4 -2
- package/ast/ValueRef.js.map +1 -1
- package/browser.d.ts +5 -5
- package/browser.js +12 -10
- package/browser.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +5 -6
- package/index.js.map +1 -1
- package/operators/AbstractOperator.d.ts +3 -7
- package/operators/AbstractOperator.js +24 -15
- package/operators/AbstractOperator.js.map +1 -1
- package/operators/Operators.d.ts +2 -1
- package/operators/Operators.js +7 -8
- package/operators/Operators.js.map +1 -1
- package/operators/arithmetic/Avg.d.ts +1 -1
- package/operators/arithmetic/Avg.js +1 -2
- package/operators/arithmetic/Avg.js.map +1 -1
- package/operators/arithmetic/Count.d.ts +1 -1
- package/operators/arithmetic/Count.js +1 -2
- package/operators/arithmetic/Count.js.map +1 -1
- package/operators/arithmetic/Max.d.ts +1 -1
- package/operators/arithmetic/Max.js +1 -2
- package/operators/arithmetic/Max.js.map +1 -1
- package/operators/arithmetic/Min.d.ts +1 -1
- package/operators/arithmetic/Min.js +1 -2
- package/operators/arithmetic/Min.js.map +1 -1
- package/operators/arithmetic/Multiply.d.ts +1 -1
- package/operators/arithmetic/Multiply.js +1 -2
- package/operators/arithmetic/Multiply.js.map +1 -1
- package/operators/arithmetic/Sum.d.ts +1 -1
- package/operators/arithmetic/Sum.js +1 -2
- package/operators/arithmetic/Sum.js.map +1 -1
- package/operators/array/First.d.ts +1 -2
- package/operators/array/First.js +4 -5
- package/operators/array/First.js.map +1 -1
- package/operators/array/Last.d.ts +1 -2
- package/operators/array/Last.js +4 -5
- package/operators/array/Last.js.map +1 -1
- package/operators/array/Map.d.ts +3 -3
- package/operators/array/Map.js +8 -9
- package/operators/array/Map.js.map +1 -1
- package/operators/compare/AbstractCompare.d.ts +2 -2
- package/operators/compare/AbstractCompare.js +4 -4
- package/operators/compare/AbstractCompare.js.map +1 -1
- package/operators/compare/EqualDesc.d.ts +10 -0
- package/operators/compare/EqualDesc.js +21 -0
- package/operators/compare/EqualDesc.js.map +1 -0
- package/operators/compare/EqualDescLookup.d.ts +5 -0
- package/operators/compare/EqualDescLookup.js +37 -0
- package/operators/compare/EqualDescLookup.js.map +1 -0
- package/operators/compare/GreaterThen.d.ts +1 -2
- package/operators/compare/GreaterThen.js +1 -2
- package/operators/compare/GreaterThen.js.map +1 -1
- package/operators/compare/GreaterThenEqual.d.ts +1 -2
- package/operators/compare/GreaterThenEqual.js +1 -2
- package/operators/compare/GreaterThenEqual.js.map +1 -1
- package/operators/compare/In.d.ts +1 -2
- package/operators/compare/In.js +1 -2
- package/operators/compare/In.js.map +1 -1
- package/operators/compare/IsNotNull.d.ts +1 -3
- package/operators/compare/IsNotNull.js +1 -2
- package/operators/compare/IsNotNull.js.map +1 -1
- package/operators/compare/IsNull.d.ts +1 -3
- package/operators/compare/IsNull.js +1 -2
- package/operators/compare/IsNull.js.map +1 -1
- package/operators/compare/LessThen.d.ts +1 -2
- package/operators/compare/LessThen.js +1 -2
- package/operators/compare/LessThen.js.map +1 -1
- package/operators/compare/LessThenEqual.d.ts +1 -2
- package/operators/compare/LessThenEqual.js +1 -2
- package/operators/compare/LessThenEqual.js.map +1 -1
- package/operators/compare/Like.d.ts +1 -2
- package/operators/compare/Like.js +1 -2
- package/operators/compare/Like.js.map +1 -1
- package/operators/compare/NotEqual.d.ts +1 -2
- package/operators/compare/NotEqual.js +1 -2
- package/operators/compare/NotEqual.js.map +1 -1
- package/operators/compare/NotIn.d.ts +1 -2
- package/operators/compare/NotIn.js +1 -2
- package/operators/compare/NotIn.js.map +1 -1
- package/operators/compare/Regex.d.ts +1 -2
- package/operators/compare/Regex.js +4 -5
- package/operators/compare/Regex.js.map +1 -1
- package/operators/date/Date.d.ts +1 -1
- package/operators/date/Date.js +1 -2
- package/operators/date/Date.js.map +1 -1
- package/operators/date/DateToString.d.ts +2 -3
- package/operators/date/DateToString.js +8 -9
- package/operators/date/DateToString.js.map +1 -1
- package/operators/date/Day.d.ts +1 -1
- package/operators/date/Day.js +1 -2
- package/operators/date/Day.js.map +1 -1
- package/operators/date/Month.d.ts +1 -1
- package/operators/date/Month.js +1 -2
- package/operators/date/Month.js.map +1 -1
- package/operators/date/Year.d.ts +1 -1
- package/operators/date/Year.js +1 -2
- package/operators/date/Year.js.map +1 -1
- package/operators/logic/AbstractLogic.d.ts +3 -0
- package/operators/logic/AbstractLogic.js +8 -0
- package/operators/logic/AbstractLogic.js.map +1 -0
- package/operators/logic/AndDesc.d.ts +10 -0
- package/operators/logic/AndDesc.js +31 -0
- package/operators/logic/AndDesc.js.map +1 -0
- package/operators/logic/AndDescLookup.d.ts +5 -0
- package/operators/logic/AndDescLookup.js +12 -0
- package/operators/logic/AndDescLookup.js.map +1 -0
- package/operators/logic/Not.d.ts +3 -2
- package/operators/logic/Not.js +3 -4
- package/operators/logic/Not.js.map +1 -1
- package/operators/logic/OrDesc.d.ts +10 -0
- package/operators/logic/OrDesc.js +31 -0
- package/operators/logic/OrDesc.js.map +1 -0
- package/operators/stage/Group.d.ts +3 -3
- package/operators/stage/Group.js +17 -11
- package/operators/stage/Group.js.map +1 -1
- package/operators/stage/Limit.d.ts +1 -5
- package/operators/stage/Limit.js +7 -6
- package/operators/stage/Limit.js.map +1 -1
- package/operators/stage/Match.d.ts +2 -2
- package/operators/stage/Match.js +7 -5
- package/operators/stage/Match.js.map +1 -1
- package/operators/stage/Project.d.ts +2 -2
- package/operators/stage/Project.js +9 -7
- package/operators/stage/Project.js.map +1 -1
- package/operators/stage/Skip.d.ts +2 -2
- package/operators/stage/Skip.js +7 -5
- package/operators/stage/Skip.js.map +1 -1
- package/operators/stage/Sort.d.ts +2 -2
- package/operators/stage/Sort.js +7 -5
- package/operators/stage/Sort.js.map +1 -1
- package/operators/string/Substr.d.ts +1 -2
- package/operators/string/Substr.js +5 -6
- package/operators/string/Substr.js.map +1 -1
- package/operators/string/ToFloat.d.ts +1 -1
- package/operators/string/ToFloat.js +4 -5
- package/operators/string/ToFloat.js.map +1 -1
- package/operators/string/ToInt.d.ts +1 -1
- package/operators/string/ToInt.js +4 -5
- package/operators/string/ToInt.js.map +1 -1
- package/operators/string/ToLower.d.ts +1 -1
- package/operators/string/ToLower.js +4 -5
- package/operators/string/ToLower.js.map +1 -1
- package/operators/string/ToUpper.d.ts +1 -2
- package/operators/string/ToUpper.js +4 -5
- package/operators/string/ToUpper.js.map +1 -1
- package/package.json +7 -62
- package/walker/lookup/ILookupFn.d.ts +4 -0
- package/walker/lookup/ILookupFn.js +3 -0
- package/walker/lookup/ILookupFn.js.map +1 -0
- package/walker/lookup/LookupWalker.d.ts +15 -0
- package/walker/lookup/LookupWalker.js +99 -0
- package/walker/lookup/LookupWalker.js.map +1 -0
- package/operators/compare/Equal.d.ts +0 -8
- package/operators/compare/Equal.js +0 -15
- package/operators/compare/Equal.js.map +0 -1
- package/operators/logic/And.d.ts +0 -7
- package/operators/logic/And.js +0 -23
- package/operators/logic/And.js.map +0 -1
- package/operators/logic/Or.d.ts +0 -7
- package/operators/logic/Or.js +0 -23
- package/operators/logic/Or.js.map +0 -1
package/Constants.js
CHANGED
|
@@ -3,5 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NUMBER_PROJECT_SUPPORT = exports.AUTO_EQUAL_CONV_SUPPORT = void 0;
|
|
4
4
|
exports.AUTO_EQUAL_CONV_SUPPORT = 'AUTO_EQUAL_CONV_SUPPORT';
|
|
5
5
|
exports.NUMBER_PROJECT_SUPPORT = 'NUMBER_PROJECT_SUPPORT';
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=Constants.js.map
|
|
6
|
+
//# sourceMappingURL=Constants.js.map
|
package/Constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AACpD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC"}
|
package/IMangoWalker.d.ts
CHANGED
|
@@ -8,12 +8,12 @@ export interface IMangoWalker {
|
|
|
8
8
|
*
|
|
9
9
|
* @param ast
|
|
10
10
|
*/
|
|
11
|
-
visitArray(ast: PAst
|
|
12
|
-
leaveArray(res: any[], ast: PAst): any;
|
|
13
|
-
visitObject(ast: PAst
|
|
14
|
-
leaveObject(res: any, ast: PAst): any;
|
|
15
|
-
onValue(ast: PAst
|
|
16
|
-
onOperator(ast: PAst
|
|
17
|
-
visitOperator(ast: PAst
|
|
18
|
-
leaveOperator(res: any, ast: PAst): any;
|
|
11
|
+
visitArray(ast: PAst<any>, ctrl?: IMangoWalkerControl): any[];
|
|
12
|
+
leaveArray(res: any[], ast: PAst<any>): any;
|
|
13
|
+
visitObject(ast: PAst<any>, ctrl?: IMangoWalkerControl): any;
|
|
14
|
+
leaveObject(res: any, ast: PAst<any>): any;
|
|
15
|
+
onValue(ast: PAst<any>, ctrl?: IMangoWalkerControl): any;
|
|
16
|
+
onOperator(ast: PAst<any>, valueRes: any, ctrl?: IMangoWalkerControl): any;
|
|
17
|
+
visitOperator(ast: PAst<any>, ctrl?: IMangoWalkerControl): any;
|
|
18
|
+
leaveOperator(res: any, ast: PAst<any>): any;
|
|
19
19
|
}
|
package/IMangoWalker.js
CHANGED
package/IMangoWalker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"IMangoWalker.js","sourceRoot":"","sources":["../../src/IMangoWalker.ts"],"names":[],"mappings":""}
|
package/LICENSE
CHANGED
package/MangoExpression.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { PAst } from './ast/PAst';
|
|
2
2
|
import { IMangoWalker } from './IMangoWalker';
|
|
3
3
|
import { Context } from './ast/Context';
|
|
4
|
+
import { ClassType } from '@allgemein/schema-api';
|
|
4
5
|
export declare class MangoExpression {
|
|
5
|
-
readonly root: PAst
|
|
6
|
+
readonly root: PAst<any>;
|
|
6
7
|
constructor(def: any);
|
|
7
|
-
|
|
8
|
-
getRoot(): PAst
|
|
9
|
-
interprete(def: any, p?: PAst
|
|
8
|
+
getByKey(key: string): PAst<any>;
|
|
9
|
+
getRoot(): PAst<any>;
|
|
10
|
+
interprete(def: any, p?: PAst<any>, ctxt?: Context): PAst<any>;
|
|
11
|
+
getOperator(operatorKey: string, operatorValue: any, def: any, parent: PAst<any>, context: Context): import(".").AbstractOperator<any>;
|
|
12
|
+
create<X extends PAst<any>>(root: ClassType<X>, def: any, p?: PAst<any>, ctxt?: Context): X;
|
|
10
13
|
visit(o: IMangoWalker): any;
|
|
14
|
+
toJson(): any;
|
|
11
15
|
}
|
package/MangoExpression.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MangoExpression = void 0;
|
|
4
|
-
const _ = require("lodash");
|
|
5
4
|
const ValueRef_1 = require("./ast/ValueRef");
|
|
6
5
|
const Value_1 = require("./ast/Value");
|
|
7
6
|
const PArray_1 = require("./ast/PArray");
|
|
@@ -9,6 +8,7 @@ const PObject_1 = require("./ast/PObject");
|
|
|
9
8
|
const Operators_1 = require("./operators/Operators");
|
|
10
9
|
const Context_1 = require("./ast/Context");
|
|
11
10
|
const Constants_1 = require("./Constants");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
12
|
class MangoExpression {
|
|
13
13
|
constructor(def) {
|
|
14
14
|
this.root = null;
|
|
@@ -17,8 +17,8 @@ class MangoExpression {
|
|
|
17
17
|
ctxt.set(Constants_1.AUTO_EQUAL_CONV_SUPPORT, true);
|
|
18
18
|
this.root = this.interprete(def, null, ctxt);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return this.root.
|
|
20
|
+
getByKey(key) {
|
|
21
|
+
return this.root.getByKey(key);
|
|
22
22
|
}
|
|
23
23
|
getRoot() {
|
|
24
24
|
return this.root;
|
|
@@ -27,41 +27,36 @@ class MangoExpression {
|
|
|
27
27
|
const context = ctxt ? ctxt : new Context_1.Context();
|
|
28
28
|
if (p) {
|
|
29
29
|
context.key = ctxt.key;
|
|
30
|
-
context.merge(p.
|
|
30
|
+
context.merge(p.getContext());
|
|
31
31
|
}
|
|
32
|
-
// context.key = sourceKey ? sourceKey : undefined;
|
|
33
32
|
let result = null;
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const isRef =
|
|
33
|
+
if ((0, lodash_1.isString)(def) ||
|
|
34
|
+
(0, lodash_1.isNumber)(def) ||
|
|
35
|
+
(0, lodash_1.isDate)(def) ||
|
|
36
|
+
(0, lodash_1.isNull)(def) ||
|
|
37
|
+
(0, lodash_1.isBoolean)(def)) {
|
|
38
|
+
const isRef = (0, lodash_1.isString)(def) && def.match(/^\$(.+)/);
|
|
40
39
|
if (isRef) {
|
|
41
|
-
result =
|
|
40
|
+
result = this.create(ValueRef_1.ValueRef, isRef[1], p, context);
|
|
42
41
|
}
|
|
43
42
|
else {
|
|
44
|
-
result =
|
|
43
|
+
result = this.create(Value_1.Value, def, p, context);
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
else if (
|
|
48
|
-
result =
|
|
46
|
+
else if ((0, lodash_1.isArray)(def)) {
|
|
47
|
+
result = this.create(PArray_1.PArray, def, p, context);
|
|
49
48
|
}
|
|
50
|
-
else if (
|
|
51
|
-
const k =
|
|
49
|
+
else if ((0, lodash_1.isObjectLike)(def)) {
|
|
50
|
+
const k = Object.keys(def);
|
|
52
51
|
// TODO make multiple $registry work
|
|
53
52
|
const operators = k.filter(x => /^\$/.test(x) && Operators_1.Operators.has(x.substr(1)));
|
|
54
53
|
if (operators.length === 1) {
|
|
55
54
|
const operatorKey = operators[0];
|
|
56
55
|
const follow = def[operatorKey];
|
|
57
|
-
|
|
58
|
-
if (!operator.validate(follow, def)) {
|
|
59
|
-
throw new Error(`operator ${operatorKey} has no valid definition ${JSON.stringify(def)}`);
|
|
60
|
-
}
|
|
61
|
-
result = operator;
|
|
56
|
+
result = this.getOperator(operatorKey, follow, def, p, context);
|
|
62
57
|
}
|
|
63
58
|
else {
|
|
64
|
-
result =
|
|
59
|
+
result = this.create(PObject_1.PObject, def, p, context);
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
62
|
if (!result) {
|
|
@@ -69,10 +64,25 @@ class MangoExpression {
|
|
|
69
64
|
}
|
|
70
65
|
return result;
|
|
71
66
|
}
|
|
67
|
+
getOperator(operatorKey, operatorValue, def, parent, context) {
|
|
68
|
+
const operator = Operators_1.Operators.create(operatorKey, this, parent, context);
|
|
69
|
+
operator.interprete(this, operatorValue, parent, context);
|
|
70
|
+
// if (!operator.validate(operatorValue, def)) {
|
|
71
|
+
// throw new Error(`operator ${operatorKey} has no valid definition ${JSON.stringify(def)}`);
|
|
72
|
+
// }
|
|
73
|
+
return operator;
|
|
74
|
+
}
|
|
75
|
+
create(root, def, p, ctxt) {
|
|
76
|
+
const x = Reflect.construct(root, []);
|
|
77
|
+
x.interprete(this, def, p, ctxt);
|
|
78
|
+
return x;
|
|
79
|
+
}
|
|
72
80
|
visit(o) {
|
|
73
81
|
return this.root.visit(o);
|
|
74
82
|
}
|
|
83
|
+
toJson() {
|
|
84
|
+
return this.root.toJson();
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
87
|
exports.MangoExpression = MangoExpression;
|
|
77
|
-
|
|
78
|
-
//# sourceMappingURL=MangoExpression.js.map
|
|
88
|
+
//# sourceMappingURL=MangoExpression.js.map
|
package/MangoExpression.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"file":"MangoExpression.js","sourceRoot":"","sources":["../../src/MangoExpression.ts"],"names":[],"mappings":";;;AAEA,6CAAwC;AACxC,uCAAkC;AAClC,yCAAoC;AACpC,2CAAsC;AACtC,qDAAgD;AAEhD,2CAAsC;AACtC,2CAAoD;AAEpD,mCAA4F;AAE5F,MAAa,eAAe;IAI1B,YAAY,GAAQ;QAFX,SAAI,GAAc,IAAI,CAAC;QAG9B,4CAA4C;QAC5C,MAAM,IAAI,GAAG,IAAI,iBAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,GAAG,CAAC,mCAAuB,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG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AE,OAAO,CAAC,CAAC;QAC1D,gDAAgD;QAChD,+FAA+F;QAC/F,IAAI;QACJ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAGD,MAAM,CAAsB,IAAkB,EAAE,GAAQ,EAAE,CAAa,EAAE,IAAc;QACrF,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAM,CAAC;QAC3C,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QACjC,OAAO,CAAC,CAAC;IACX,CAAC;IAGD,KAAK,CAAC,CAAe;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAID,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CAEF;AAzFD,0CAyFC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PAst } from './PAst';
|
|
2
|
+
import { ClassType } from '@allgemein/schema-api';
|
|
3
|
+
export interface IBinding<X> {
|
|
4
|
+
on: ClassType<PAst<any>>;
|
|
5
|
+
use: ClassType<X>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Bindings<X> {
|
|
8
|
+
name: string;
|
|
9
|
+
list: IBinding<X>[];
|
|
10
|
+
constructor(name: string);
|
|
11
|
+
}
|
package/ast/Bindings.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bindings = void 0;
|
|
4
|
+
class Bindings {
|
|
5
|
+
constructor(name) {
|
|
6
|
+
this.list = [];
|
|
7
|
+
this.name = name;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Bindings = Bindings;
|
|
11
|
+
//# sourceMappingURL=Bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bindings.js","sourceRoot":"","sources":["../../../src/ast/Bindings.ts"],"names":[],"mappings":";;;AAQA,MAAa,QAAQ;IAMnB,YAAY,IAAY;QAFxB,SAAI,GAAkB,EAAE,CAAC;QAGvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CAEF;AAVD,4BAUC"}
|
package/ast/Context.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Context = void 0;
|
|
4
|
-
const
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
5
|
class Context {
|
|
6
6
|
constructor(k) {
|
|
7
7
|
this.data = {};
|
|
@@ -13,7 +13,7 @@ class Context {
|
|
|
13
13
|
* @param ctxt
|
|
14
14
|
*/
|
|
15
15
|
has(ctxt) {
|
|
16
|
-
return
|
|
16
|
+
return (0, lodash_1.has)(this.data, ctxt);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* get context value
|
|
@@ -22,7 +22,7 @@ class Context {
|
|
|
22
22
|
*/
|
|
23
23
|
get(k) {
|
|
24
24
|
if (k) {
|
|
25
|
-
return
|
|
25
|
+
return (0, lodash_1.get)(this.data, k, null);
|
|
26
26
|
}
|
|
27
27
|
return this.data;
|
|
28
28
|
}
|
|
@@ -34,19 +34,18 @@ class Context {
|
|
|
34
34
|
*/
|
|
35
35
|
set(k, value) {
|
|
36
36
|
if (!this.has(k)) {
|
|
37
|
-
this.data[k] =
|
|
37
|
+
this.data[k] = (0, lodash_1.isObjectLike)(value) ? {} : null;
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
40
|
-
this.data[k] =
|
|
39
|
+
if ((0, lodash_1.isObjectLike)()) {
|
|
40
|
+
this.data[k] = (0, lodash_1.assign)(this.data[k], value);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
this.data[k] = value;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
merge(ctx) {
|
|
47
|
-
this.data =
|
|
47
|
+
this.data = (0, lodash_1.merge)(this.data, ctx.data);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
exports.Context = Context;
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=Context.js.map
|
|
51
|
+
//# sourceMappingURL=Context.js.map
|
package/ast/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ast/Context.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../src/ast/Context.ts"],"names":[],"mappings":";;;AAAA,mCAA6D;AAE7D,MAAa,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,IAAA,YAAG,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IAGD;;;;OAIG;IACH,GAAG,CAAC,CAAU;QACZ,IAAI,CAAC,EAAE,CAAC;YACN,OAAO,IAAA,YAAG,EAAC,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,IAAA,qBAAY,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,CAAC;QACD,IAAI,IAAA,qBAAY,GAAE,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAA,eAAM,EAAC,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,IAAA,cAAK,EAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CAEF;AAxDD,0BAwDC"}
|
package/ast/KeyDesc.d.ts
ADDED
package/ast/KeyDesc.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyDesc = void 0;
|
|
4
|
+
exports.Key = Key;
|
|
5
|
+
const Selector_1 = require("./Selector");
|
|
6
|
+
class KeyDesc extends Selector_1.Selector {
|
|
7
|
+
toJson() {
|
|
8
|
+
return { $key: this.getValue() };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.KeyDesc = KeyDesc;
|
|
12
|
+
/**
|
|
13
|
+
* Key
|
|
14
|
+
*/
|
|
15
|
+
function Key(k) {
|
|
16
|
+
const desc = new KeyDesc();
|
|
17
|
+
desc.setValue(k);
|
|
18
|
+
return desc;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=KeyDesc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyDesc.js","sourceRoot":"","sources":["../../../src/ast/KeyDesc.ts"],"names":[],"mappings":";;;AAcA,kBAIC;AAlBD,yCAAoC;AAGpC,MAAa,OAAQ,SAAQ,mBAAQ;IAEnC,MAAM;QACJ,OAAO,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAC,CAAC;IACjC,CAAC;CAEF;AAND,0BAMC;AAED;;GAEG;AACH,SAAgB,GAAG,CAAC,CAAS;IAC3B,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;IAC3B,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/ast/MultiArgs.js
CHANGED
package/ast/MultiArgs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ast/MultiArgs.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAGpB,YAAY,GAAG,IAAW;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CAGF;AARD,8BAQC"
|
|
1
|
+
{"version":3,"file":"MultiArgs.js","sourceRoot":"","sources":["../../../src/ast/MultiArgs.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAGpB,YAAY,GAAG,IAAW;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CAGF;AARD,8BAQC"}
|
package/ast/PArray.d.ts
CHANGED
|
@@ -2,11 +2,9 @@ import { PAst } from './PAst';
|
|
|
2
2
|
import { MangoExpression } from '../MangoExpression';
|
|
3
3
|
import { IMangoWalker } from '../IMangoWalker';
|
|
4
4
|
import { Context } from './Context';
|
|
5
|
-
export declare class PArray extends PAst {
|
|
6
|
-
|
|
7
|
-
constructor(e: MangoExpression, kv: any[], p?: PAst, ctxt?: Context);
|
|
8
|
-
getKey(key: string): PAst;
|
|
5
|
+
export declare class PArray extends PAst<PAst<any>[]> {
|
|
6
|
+
getByKey(key: string): PAst<any>;
|
|
9
7
|
keys(): string[];
|
|
10
|
-
interprete(kv: any): void;
|
|
8
|
+
interprete(e: MangoExpression, kv: any[], p?: PAst<any>, ctxt?: Context): void;
|
|
11
9
|
visit(o: IMangoWalker): any;
|
|
12
10
|
}
|
package/ast/PArray.js
CHANGED
|
@@ -4,14 +4,9 @@ exports.PArray = void 0;
|
|
|
4
4
|
const PAst_1 = require("./PAst");
|
|
5
5
|
const Context_1 = require("./Context");
|
|
6
6
|
class PArray extends PAst_1.PAst {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.interprete(kv);
|
|
11
|
-
}
|
|
12
|
-
getKey(key) {
|
|
13
|
-
for (const item of this.items) {
|
|
14
|
-
const found = item.getKey(key);
|
|
7
|
+
getByKey(key) {
|
|
8
|
+
for (const item of this.getValue()) {
|
|
9
|
+
const found = item.getByKey(key);
|
|
15
10
|
if (found) {
|
|
16
11
|
return found;
|
|
17
12
|
}
|
|
@@ -20,7 +15,7 @@ class PArray extends PAst_1.PAst {
|
|
|
20
15
|
}
|
|
21
16
|
keys() {
|
|
22
17
|
const keys = [];
|
|
23
|
-
for (const item of this.
|
|
18
|
+
for (const item of this.getValue()) {
|
|
24
19
|
const subkey = item.keys();
|
|
25
20
|
subkey.forEach((x) => {
|
|
26
21
|
keys.push(x);
|
|
@@ -28,25 +23,32 @@ class PArray extends PAst_1.PAst {
|
|
|
28
23
|
}
|
|
29
24
|
return keys;
|
|
30
25
|
}
|
|
31
|
-
interprete(kv) {
|
|
26
|
+
interprete(e, kv, p, ctxt) {
|
|
27
|
+
super.enviroment(e, p, ctxt);
|
|
28
|
+
this.value = [];
|
|
32
29
|
for (let i = 0; i < kv.length; i++) {
|
|
33
30
|
const ctxt = new Context_1.Context();
|
|
34
31
|
ctxt.key = i;
|
|
35
|
-
this.
|
|
32
|
+
this.value[i] = this.getRootExpression().interprete(kv[i], this, ctxt);
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
visit(o) {
|
|
39
36
|
const state = {};
|
|
40
|
-
|
|
37
|
+
let res = [];
|
|
38
|
+
if (o.visitArray) {
|
|
39
|
+
res = o.visitArray(this, state);
|
|
40
|
+
}
|
|
41
41
|
if (state && state.abort) {
|
|
42
42
|
return res;
|
|
43
43
|
}
|
|
44
|
-
for (let i = 0; i < this.
|
|
45
|
-
res.push(this.
|
|
44
|
+
for (let i = 0; i < this.getValue().length; i++) {
|
|
45
|
+
res.push(this.getValue()[i].visit(o));
|
|
46
|
+
}
|
|
47
|
+
if (o.leaveArray) {
|
|
48
|
+
return o.leaveArray(res, this);
|
|
46
49
|
}
|
|
47
|
-
return
|
|
50
|
+
return res;
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
exports.PArray = PArray;
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=PArray.js.map
|
|
54
|
+
//# sourceMappingURL=PArray.js.map
|
package/ast/PArray.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ast/PArray.ts"],"names":[],"mappings":";;;AAAA,iCAA4B;AAG5B,uCAAkC;AAElC,MAAa,MAAO,SAAQ,
|
|
1
|
+
{"version":3,"file":"PArray.js","sourceRoot":"","sources":["../../../src/ast/PArray.ts"],"names":[],"mappings":";;;AAAA,iCAA4B;AAG5B,uCAAkC;AAElC,MAAa,MAAO,SAAQ,WAAiB;IAG3C,QAAQ,CAAC,GAAW;QAClB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACnC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACjC,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI;QACF,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE;gBAC3B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU,CAAC,CAAkB,EAAE,EAAS,EAAE,CAAa,EAA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ast/PAst.d.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import { MangoExpression } from '../MangoExpression';
|
|
2
2
|
import { IMangoWalker } from '../IMangoWalker';
|
|
3
3
|
import { Context } from './Context';
|
|
4
|
-
export declare abstract class PAst {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export declare abstract class PAst<X> {
|
|
5
|
+
private rootExpression;
|
|
6
|
+
parent: PAst<any>;
|
|
7
|
+
key: string | number | PAst<string>;
|
|
8
|
+
context: Context;
|
|
9
|
+
value: X;
|
|
10
|
+
interprete(e: MangoExpression, value: X, p?: PAst<any>, ctxt?: Context): void;
|
|
11
|
+
enviroment(e: MangoExpression, p?: PAst<any>, ctxt?: Context): void;
|
|
12
|
+
getKey(): string | number | PAst<string>;
|
|
13
|
+
setKey(key: string | PAst<string>): void;
|
|
14
|
+
getKeyString(): string | number;
|
|
15
|
+
getValue(): X;
|
|
16
|
+
setValue(v: X): void;
|
|
17
|
+
applyParent(v: X): void;
|
|
18
|
+
getRootExpression(): MangoExpression;
|
|
19
|
+
setRootExpression(base: MangoExpression): void;
|
|
20
|
+
getParentExpression(): PAst<any>;
|
|
21
|
+
setParentExpression(base: PAst<any>): void;
|
|
22
|
+
getContext(): Context;
|
|
23
|
+
mergeWith(ctxt: Context): void;
|
|
10
24
|
keys(): (string | number)[];
|
|
11
25
|
/**
|
|
12
26
|
* function execute on self and parents
|
|
@@ -14,7 +28,7 @@ export declare abstract class PAst {
|
|
|
14
28
|
* @param fn
|
|
15
29
|
* @param self
|
|
16
30
|
*/
|
|
17
|
-
backwardCall(fn: (x: PAst) => boolean, self?: boolean): any;
|
|
31
|
+
backwardCall(fn: (x: PAst<any>) => boolean, self?: boolean): any;
|
|
18
32
|
/**
|
|
19
33
|
* check if the self or nodes branch is in some sublying context
|
|
20
34
|
*
|
|
@@ -22,6 +36,7 @@ export declare abstract class PAst {
|
|
|
22
36
|
* @param selfCheck
|
|
23
37
|
*/
|
|
24
38
|
isInContext(ctxt: string, selfCheck?: boolean): boolean;
|
|
25
|
-
abstract
|
|
39
|
+
abstract getByKey(key: string): PAst<any>;
|
|
26
40
|
abstract visit(o: IMangoWalker): any;
|
|
41
|
+
toJson(): any;
|
|
27
42
|
}
|
package/ast/PAst.js
CHANGED
|
@@ -2,18 +2,91 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PAst = void 0;
|
|
4
4
|
const Context_1 = require("./Context");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
5
6
|
class PAst {
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
interprete(e, value, p, ctxt) {
|
|
8
|
+
this.enviroment(e, p, ctxt);
|
|
9
|
+
if (!(0, lodash_1.isUndefined)(value)) {
|
|
10
|
+
this.value = this.getRootExpression().interprete(value, this, this.getContext());
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
enviroment(e, p, ctxt) {
|
|
14
|
+
this.setRootExpression(e);
|
|
15
|
+
if (p) {
|
|
16
|
+
this.setParentExpression(p);
|
|
17
|
+
}
|
|
18
|
+
if (ctxt) {
|
|
19
|
+
this.mergeWith(ctxt);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getKey() {
|
|
23
|
+
return this.key;
|
|
24
|
+
}
|
|
25
|
+
setKey(key) {
|
|
26
|
+
this.key = key;
|
|
27
|
+
}
|
|
28
|
+
getKeyString() {
|
|
29
|
+
if (this.key instanceof PAst) {
|
|
30
|
+
return this.key.getValue();
|
|
31
|
+
}
|
|
32
|
+
return this.key;
|
|
33
|
+
}
|
|
34
|
+
getValue() {
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
setValue(v) {
|
|
38
|
+
this.value = v;
|
|
39
|
+
this.applyParent(v);
|
|
40
|
+
}
|
|
41
|
+
applyParent(v) {
|
|
42
|
+
if (v) {
|
|
43
|
+
if (v instanceof PAst) {
|
|
44
|
+
v.setParentExpression(this);
|
|
45
|
+
}
|
|
46
|
+
else if ((0, lodash_1.isArray)(v)) {
|
|
47
|
+
for (const e of v) {
|
|
48
|
+
if (e instanceof PAst) {
|
|
49
|
+
e.setParentExpression(this);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if ((0, lodash_1.isObjectLike)(v)) {
|
|
54
|
+
for (const e of (0, lodash_1.keys)(v)) {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
if (v[e] instanceof PAst) {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
v[e].setParentExpression(this);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getRootExpression() {
|
|
65
|
+
return this.rootExpression;
|
|
66
|
+
}
|
|
67
|
+
setRootExpression(base) {
|
|
68
|
+
this.rootExpression = base;
|
|
69
|
+
}
|
|
70
|
+
getParentExpression() {
|
|
71
|
+
return this.parent;
|
|
72
|
+
}
|
|
73
|
+
setParentExpression(base) {
|
|
74
|
+
this.parent = base;
|
|
75
|
+
}
|
|
76
|
+
getContext() {
|
|
77
|
+
if (!this.context) {
|
|
78
|
+
this.context = new Context_1.Context();
|
|
79
|
+
}
|
|
80
|
+
return this.context;
|
|
81
|
+
}
|
|
82
|
+
mergeWith(ctxt) {
|
|
10
83
|
if (ctxt) {
|
|
11
84
|
this.key = ctxt.key;
|
|
12
|
-
this.
|
|
85
|
+
this.getContext().merge(ctxt);
|
|
13
86
|
}
|
|
14
87
|
}
|
|
15
88
|
keys() {
|
|
16
|
-
const keys = [this.
|
|
89
|
+
const keys = [this.getKeyString()];
|
|
17
90
|
return keys;
|
|
18
91
|
}
|
|
19
92
|
/**
|
|
@@ -46,7 +119,40 @@ class PAst {
|
|
|
46
119
|
}
|
|
47
120
|
return false;
|
|
48
121
|
}
|
|
122
|
+
toJson() {
|
|
123
|
+
let obj = null;
|
|
124
|
+
let key = this.getKey();
|
|
125
|
+
const value = this.getValue();
|
|
126
|
+
if ((0, lodash_1.isNumber)(key)) {
|
|
127
|
+
// is possibly part of an array, so return only the value
|
|
128
|
+
if (value instanceof PAst) {
|
|
129
|
+
obj = value.toJson();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
obj = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if ((0, lodash_1.isString)(key)) {
|
|
136
|
+
// is an object, so return an object with key
|
|
137
|
+
if (value instanceof PAst) {
|
|
138
|
+
obj = { [key]: value.toJson() };
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
obj = { [key]: value };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else if (key instanceof PAst) {
|
|
145
|
+
const _key = key.getValue();
|
|
146
|
+
// is an object, so return an object with key
|
|
147
|
+
if (value instanceof PAst) {
|
|
148
|
+
obj = { [_key]: value.toJson() };
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
obj = { [_key]: value };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return obj;
|
|
155
|
+
}
|
|
49
156
|
}
|
|
50
157
|
exports.PAst = PAst;
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=PAst.js.map
|
|
158
|
+
//# sourceMappingURL=PAst.js.map
|