@allgemein/mango-expressions 1.1.1 → 1.3.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.
Files changed (201) hide show
  1. package/Constants.js +1 -2
  2. package/Constants.js.map +1 -1
  3. package/IMangoWalker.d.ts +8 -8
  4. package/IMangoWalker.js +1 -2
  5. package/IMangoWalker.js.map +1 -1
  6. package/LICENSE +1 -1
  7. package/MangoExpression.d.ts +8 -4
  8. package/MangoExpression.js +35 -25
  9. package/MangoExpression.js.map +1 -1
  10. package/ast/Bindings.d.ts +11 -0
  11. package/ast/Bindings.js +11 -0
  12. package/ast/Bindings.js.map +1 -0
  13. package/ast/Context.js +8 -9
  14. package/ast/Context.js.map +1 -1
  15. package/ast/KeyDesc.d.ts +10 -0
  16. package/ast/KeyDesc.js +20 -0
  17. package/ast/KeyDesc.js.map +1 -0
  18. package/ast/MultiArgs.js +1 -2
  19. package/ast/MultiArgs.js.map +1 -1
  20. package/ast/PArray.d.ts +3 -5
  21. package/ast/PArray.js +19 -17
  22. package/ast/PArray.js.map +1 -1
  23. package/ast/PAst.d.ts +23 -8
  24. package/ast/PAst.js +114 -8
  25. package/ast/PAst.js.map +1 -1
  26. package/ast/PObject.d.ts +10 -9
  27. package/ast/PObject.js +58 -33
  28. package/ast/PObject.js.map +1 -1
  29. package/ast/PValue.d.ts +4 -4
  30. package/ast/PValue.js +7 -5
  31. package/ast/PValue.js.map +1 -1
  32. package/ast/Selector.d.ts +6 -0
  33. package/ast/Selector.js +13 -0
  34. package/ast/Selector.js.map +1 -0
  35. package/ast/Unset.js +1 -2
  36. package/ast/Unset.js.map +1 -1
  37. package/ast/Value.js +1 -2
  38. package/ast/Value.js.map +1 -1
  39. package/ast/ValueRef.d.ts +1 -0
  40. package/ast/ValueRef.js +4 -2
  41. package/ast/ValueRef.js.map +1 -1
  42. package/browser.d.ts +4 -4
  43. package/browser.js +8 -9
  44. package/browser.js.map +1 -1
  45. package/index.d.ts +1 -1
  46. package/index.js +5 -6
  47. package/index.js.map +1 -1
  48. package/operators/AbstractOperator.d.ts +3 -7
  49. package/operators/AbstractOperator.js +24 -15
  50. package/operators/AbstractOperator.js.map +1 -1
  51. package/operators/Operators.d.ts +2 -1
  52. package/operators/Operators.js +7 -8
  53. package/operators/Operators.js.map +1 -1
  54. package/operators/arithmetic/Avg.d.ts +1 -1
  55. package/operators/arithmetic/Avg.js +1 -2
  56. package/operators/arithmetic/Avg.js.map +1 -1
  57. package/operators/arithmetic/Count.d.ts +1 -1
  58. package/operators/arithmetic/Count.js +1 -2
  59. package/operators/arithmetic/Count.js.map +1 -1
  60. package/operators/arithmetic/Max.d.ts +1 -1
  61. package/operators/arithmetic/Max.js +1 -2
  62. package/operators/arithmetic/Max.js.map +1 -1
  63. package/operators/arithmetic/Min.d.ts +1 -1
  64. package/operators/arithmetic/Min.js +1 -2
  65. package/operators/arithmetic/Min.js.map +1 -1
  66. package/operators/arithmetic/Multiply.d.ts +1 -1
  67. package/operators/arithmetic/Multiply.js +1 -2
  68. package/operators/arithmetic/Multiply.js.map +1 -1
  69. package/operators/arithmetic/Sum.d.ts +1 -1
  70. package/operators/arithmetic/Sum.js +1 -2
  71. package/operators/arithmetic/Sum.js.map +1 -1
  72. package/operators/array/First.d.ts +1 -2
  73. package/operators/array/First.js +4 -5
  74. package/operators/array/First.js.map +1 -1
  75. package/operators/array/Last.d.ts +1 -2
  76. package/operators/array/Last.js +4 -5
  77. package/operators/array/Last.js.map +1 -1
  78. package/operators/array/Map.d.ts +3 -3
  79. package/operators/array/Map.js +8 -9
  80. package/operators/array/Map.js.map +1 -1
  81. package/operators/compare/AbstractCompare.d.ts +2 -2
  82. package/operators/compare/AbstractCompare.js +4 -4
  83. package/operators/compare/AbstractCompare.js.map +1 -1
  84. package/operators/compare/EqualDesc.d.ts +10 -0
  85. package/operators/compare/EqualDesc.js +21 -0
  86. package/operators/compare/EqualDesc.js.map +1 -0
  87. package/operators/compare/EqualDescLookup.d.ts +5 -0
  88. package/operators/compare/EqualDescLookup.js +37 -0
  89. package/operators/compare/EqualDescLookup.js.map +1 -0
  90. package/operators/compare/GreaterThen.d.ts +1 -2
  91. package/operators/compare/GreaterThen.js +1 -2
  92. package/operators/compare/GreaterThen.js.map +1 -1
  93. package/operators/compare/GreaterThenEqual.d.ts +1 -2
  94. package/operators/compare/GreaterThenEqual.js +1 -2
  95. package/operators/compare/GreaterThenEqual.js.map +1 -1
  96. package/operators/compare/In.d.ts +1 -2
  97. package/operators/compare/In.js +1 -2
  98. package/operators/compare/In.js.map +1 -1
  99. package/operators/compare/IsNotNull.d.ts +1 -3
  100. package/operators/compare/IsNotNull.js +1 -2
  101. package/operators/compare/IsNotNull.js.map +1 -1
  102. package/operators/compare/IsNull.d.ts +1 -3
  103. package/operators/compare/IsNull.js +1 -2
  104. package/operators/compare/IsNull.js.map +1 -1
  105. package/operators/compare/LessThen.d.ts +1 -2
  106. package/operators/compare/LessThen.js +1 -2
  107. package/operators/compare/LessThen.js.map +1 -1
  108. package/operators/compare/LessThenEqual.d.ts +1 -2
  109. package/operators/compare/LessThenEqual.js +1 -2
  110. package/operators/compare/LessThenEqual.js.map +1 -1
  111. package/operators/compare/Like.d.ts +1 -2
  112. package/operators/compare/Like.js +1 -2
  113. package/operators/compare/Like.js.map +1 -1
  114. package/operators/compare/NotEqual.d.ts +1 -2
  115. package/operators/compare/NotEqual.js +1 -2
  116. package/operators/compare/NotEqual.js.map +1 -1
  117. package/operators/compare/NotIn.d.ts +1 -2
  118. package/operators/compare/NotIn.js +1 -2
  119. package/operators/compare/NotIn.js.map +1 -1
  120. package/operators/compare/Regex.d.ts +1 -2
  121. package/operators/compare/Regex.js +4 -5
  122. package/operators/compare/Regex.js.map +1 -1
  123. package/operators/date/Date.d.ts +1 -1
  124. package/operators/date/Date.js +1 -2
  125. package/operators/date/Date.js.map +1 -1
  126. package/operators/date/DateToString.d.ts +2 -3
  127. package/operators/date/DateToString.js +8 -9
  128. package/operators/date/DateToString.js.map +1 -1
  129. package/operators/date/Day.d.ts +1 -1
  130. package/operators/date/Day.js +1 -2
  131. package/operators/date/Day.js.map +1 -1
  132. package/operators/date/Month.d.ts +1 -1
  133. package/operators/date/Month.js +1 -2
  134. package/operators/date/Month.js.map +1 -1
  135. package/operators/date/Year.d.ts +1 -1
  136. package/operators/date/Year.js +1 -2
  137. package/operators/date/Year.js.map +1 -1
  138. package/operators/logic/AbstractLogic.d.ts +3 -0
  139. package/operators/logic/AbstractLogic.js +8 -0
  140. package/operators/logic/AbstractLogic.js.map +1 -0
  141. package/operators/logic/AndDesc.d.ts +10 -0
  142. package/operators/logic/AndDesc.js +31 -0
  143. package/operators/logic/AndDesc.js.map +1 -0
  144. package/operators/logic/AndDescLookup.d.ts +5 -0
  145. package/operators/logic/AndDescLookup.js +12 -0
  146. package/operators/logic/AndDescLookup.js.map +1 -0
  147. package/operators/logic/Not.d.ts +3 -2
  148. package/operators/logic/Not.js +3 -4
  149. package/operators/logic/Not.js.map +1 -1
  150. package/operators/logic/OrDesc.d.ts +10 -0
  151. package/operators/logic/OrDesc.js +31 -0
  152. package/operators/logic/OrDesc.js.map +1 -0
  153. package/operators/stage/Group.d.ts +3 -3
  154. package/operators/stage/Group.js +17 -11
  155. package/operators/stage/Group.js.map +1 -1
  156. package/operators/stage/Limit.d.ts +1 -5
  157. package/operators/stage/Limit.js +7 -6
  158. package/operators/stage/Limit.js.map +1 -1
  159. package/operators/stage/Match.d.ts +2 -2
  160. package/operators/stage/Match.js +7 -5
  161. package/operators/stage/Match.js.map +1 -1
  162. package/operators/stage/Project.d.ts +2 -2
  163. package/operators/stage/Project.js +9 -7
  164. package/operators/stage/Project.js.map +1 -1
  165. package/operators/stage/Skip.d.ts +2 -2
  166. package/operators/stage/Skip.js +7 -5
  167. package/operators/stage/Skip.js.map +1 -1
  168. package/operators/stage/Sort.d.ts +2 -2
  169. package/operators/stage/Sort.js +7 -5
  170. package/operators/stage/Sort.js.map +1 -1
  171. package/operators/string/Substr.d.ts +1 -2
  172. package/operators/string/Substr.js +5 -6
  173. package/operators/string/Substr.js.map +1 -1
  174. package/operators/string/ToFloat.d.ts +1 -1
  175. package/operators/string/ToFloat.js +4 -5
  176. package/operators/string/ToFloat.js.map +1 -1
  177. package/operators/string/ToInt.d.ts +1 -1
  178. package/operators/string/ToInt.js +4 -5
  179. package/operators/string/ToInt.js.map +1 -1
  180. package/operators/string/ToLower.d.ts +1 -1
  181. package/operators/string/ToLower.js +4 -5
  182. package/operators/string/ToLower.js.map +1 -1
  183. package/operators/string/ToUpper.d.ts +1 -2
  184. package/operators/string/ToUpper.js +4 -5
  185. package/operators/string/ToUpper.js.map +1 -1
  186. package/package.json +7 -62
  187. package/walker/lookup/ILookupFn.d.ts +4 -0
  188. package/walker/lookup/ILookupFn.js +3 -0
  189. package/walker/lookup/ILookupFn.js.map +1 -0
  190. package/walker/lookup/LookupWalker.d.ts +15 -0
  191. package/walker/lookup/LookupWalker.js +99 -0
  192. package/walker/lookup/LookupWalker.js.map +1 -0
  193. package/operators/compare/Equal.d.ts +0 -8
  194. package/operators/compare/Equal.js +0 -15
  195. package/operators/compare/Equal.js.map +0 -1
  196. package/operators/logic/And.d.ts +0 -7
  197. package/operators/logic/And.js +0 -23
  198. package/operators/logic/And.js.map +0 -1
  199. package/operators/logic/Or.d.ts +0 -7
  200. package/operators/logic/Or.js +0 -23
  201. 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":["../../../src/Constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AACpD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC","file":"Constants.js","sourcesContent":["export const AUTO_EQUAL_CONV_SUPPORT = 'AUTO_EQUAL_CONV_SUPPORT';\nexport const NUMBER_PROJECT_SUPPORT = 'NUMBER_PROJECT_SUPPORT';\n\n\n\n\n"],"sourceRoot":"."}
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, ctrl?: IMangoWalkerControl): any[];
12
- leaveArray(res: any[], ast: PAst): any;
13
- visitObject(ast: PAst, ctrl?: IMangoWalkerControl): any;
14
- leaveObject(res: any, ast: PAst): any;
15
- onValue(ast: PAst, ctrl?: IMangoWalkerControl): any;
16
- onOperator(ast: PAst, valueRes: any, ctrl?: IMangoWalkerControl): any;
17
- visitOperator(ast: PAst, ctrl?: IMangoWalkerControl): any;
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
@@ -1,4 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
-
4
- //# sourceMappingURL=IMangoWalker.js.map
3
+ //# sourceMappingURL=IMangoWalker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/IMangoWalker.ts"],"names":[],"mappings":"","file":"IMangoWalker.js","sourcesContent":["import {PAst} from './ast/PAst';\n\nexport interface IMangoWalkerControl {\n abort?: boolean;\n}\n\nexport interface IMangoWalker {\n\n // on(entry: any): any;\n\n /**\n * return the array\n *\n * @param ast\n */\n visitArray(ast: PAst, ctrl?: IMangoWalkerControl): any[];\n\n leaveArray(res: any[], ast: PAst): any;\n\n visitObject(ast: PAst, ctrl?: IMangoWalkerControl): any;\n\n leaveObject(res: any, ast: PAst): any;\n\n onValue(ast: PAst, ctrl?: IMangoWalkerControl): any;\n\n onOperator(ast: PAst, valueRes: any, ctrl?: IMangoWalkerControl): any;\n\n visitOperator(ast: PAst, ctrl?: IMangoWalkerControl): any;\n\n leaveOperator(res: any, ast: PAst): any;\n\n}\n"],"sourceRoot":"."}
1
+ {"version":3,"file":"IMangoWalker.js","sourceRoot":"","sources":["../../src/IMangoWalker.ts"],"names":[],"mappings":""}
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2020 Robert Kania
3
+ Copyright (c) 2018 Robert Kania
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person
6
6
  obtaining a copy of this software and associated documentation
@@ -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
- getKey(key: string): PAst;
8
- getRoot(): PAst;
9
- interprete(def: any, p?: PAst, ctxt?: Context): 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
  }
@@ -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
- getKey(key) {
21
- return this.root.getKey(key);
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.context);
30
+ context.merge(p.getContext());
31
31
  }
32
- // context.key = sourceKey ? sourceKey : undefined;
33
32
  let result = null;
34
- if (_.isString(def) ||
35
- _.isNumber(def) ||
36
- _.isDate(def) ||
37
- _.isNull(def) ||
38
- _.isBoolean(def)) {
39
- const isRef = _.isString(def) && def.match(/^\$(.+)/);
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 = new ValueRef_1.ValueRef(this, isRef[1], p, context);
40
+ result = this.create(ValueRef_1.ValueRef, isRef[1], p, context);
42
41
  }
43
42
  else {
44
- result = new Value_1.Value(this, def, p, context);
43
+ result = this.create(Value_1.Value, def, p, context);
45
44
  }
46
45
  }
47
- else if (_.isArray(def)) {
48
- result = new PArray_1.PArray(this, def, p, context);
46
+ else if ((0, lodash_1.isArray)(def)) {
47
+ result = this.create(PArray_1.PArray, def, p, context);
49
48
  }
50
- else if (_.isObjectLike(def)) {
51
- const k = _.keys(def);
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
- const operator = Operators_1.Operators.create(operatorKey, this, p, context);
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 = new PObject_1.PObject(this, def, p, context);
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/MangoExpression.ts"],"names":[],"mappings":";;;AACA,4BAA4B;AAC5B,6CAAwC;AACxC,uCAAkC;AAClC,yCAAoC;AACpC,2CAAsC;AACtC,qDAAgD;AAEhD,2CAAsC;AACtC,2CAAoD;AAEpD,MAAa,eAAe;IAI1B,YAAY,GAAQ;QAFX,SAAI,GAAS,IAAI,CAAC;QAGzB,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,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAGD,UAAU,CAAC,GAAQ,EAAE,CAAQ,EAAE,IAAc;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,iBAAO,EAAE,CAAC;QAC5C,IAAI,CAAC,EAAE;YACL,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;YACvB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAC1B;QACD,mDAAmD;QACnD,IAAI,MAAM,GAAS,IA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;gBAChC,MAAM,QAAQ,GAAG,qBAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;gBACjE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;oBACnC,MAAM,IAAI,KAAK,CAAC,YAAY,WAAW,4BAA4B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;iBAC3F;gBACD,MAAM,GAAG,QAAQ,CAAC;aACnB;iBAAM;gBACL,MAAM,GAAG,IAAI,iBAAO,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;aAC7C;SACF;QAED,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAC;SACnD;QAED,OAAO,MAAM,CAAC;IAEhB,CAAC;IAGD,KAAK,CAAC,CAAe;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;CAEF;AAvED,0CAuEC","file":"MangoExpression.js","sourcesContent":["import {PAst} from './ast/PAst';\nimport * as _ from 'lodash';\nimport {ValueRef} from './ast/ValueRef';\nimport {Value} from './ast/Value';\nimport {PArray} from './ast/PArray';\nimport {PObject} from './ast/PObject';\nimport {Operators} from './operators/Operators';\nimport {IMangoWalker} from './IMangoWalker';\nimport {Context} from './ast/Context';\nimport {AUTO_EQUAL_CONV_SUPPORT} from './Constants';\n\nexport class MangoExpression {\n\n readonly root: PAst = null;\n\n constructor(def: any) {\n // default change object assignment to value\n const ctxt = new Context();\n ctxt.set(AUTO_EQUAL_CONV_SUPPORT, true);\n this.root = this.interprete(def, null, ctxt);\n }\n\n getKey(key: string) {\n return this.root.getKey(key);\n }\n\n getRoot() {\n return this.root;\n }\n\n\n interprete(def: any, p?: PAst, ctxt?: Context) {\n const context = ctxt ? ctxt : new Context();\n if (p) {\n context.key = ctxt.key;\n context.merge(p.context);\n }\n // context.key = sourceKey ? sourceKey : undefined;\n let result: PAst = null;\n if (_.isString(def) ||\n _.isNumber(def) ||\n _.isDate(def) ||\n _.isNull(def) ||\n _.isBoolean(def)) {\n const isRef = _.isString(def) && def.match(/^\\$(.+)/);\n if (isRef) {\n result = new ValueRef(this, isRef[1], p, context);\n } else {\n result = new Value(this, def, p, context);\n }\n } else if (_.isArray(def)) {\n result = new PArray(this, def, p, context);\n } else if (_.isObjectLike(def)) {\n const k = _.keys(def);\n // TODO make multiple $registry work\n const operators = k.filter(x => /^\\$/.test(x) && Operators.has(x.substr(1)));\n if (operators.length === 1) {\n const operatorKey = operators[0];\n const follow = def[operatorKey];\n const operator = Operators.create(operatorKey, this, p, context);\n if (!operator.validate(follow, def)) {\n throw new Error(`operator ${operatorKey} has no valid definition ${JSON.stringify(def)}`);\n }\n result = operator;\n } else {\n result = new PObject(this, def, p, context);\n }\n }\n\n if (!result) {\n throw new Error(`not yet implemented for ${def}`);\n }\n\n return result;\n\n }\n\n\n visit(o: IMangoWalker) {\n return this.root.visit(o);\n }\n\n}\n"],"sourceRoot":"."}
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,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,QAAQ,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I;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
+ }
@@ -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 _ = require("lodash");
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 _.has(this.data, ctxt);
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 _.get(this.data, k, null);
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] = _.isObjectLike(value) ? {} : null;
37
+ this.data[k] = (0, lodash_1.isObjectLike)(value) ? {} : null;
38
38
  }
39
- if (_.isObjectLike()) {
40
- this.data[k] = _.assign(this.data[k], value);
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 = _.merge(this.data, ctx.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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ast/Context.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAE5B,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,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAGD;;;;OAIG;IACH,GAAG,CAAC,CAAU;QACZ,IAAI,CAAC,EAAE;YACL,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;SAClC;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;YAChB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SAClD;QACD,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC9C;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;SACtB;IAEH,CAAC;IAGD,KAAK,CAAC,GAAY;QAChB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;CAEF;AAxDD,0BAwDC","file":"Context.js","sourcesContent":["import * as _ from 'lodash';\n\nexport class Context {\n\n key: string | number;\n\n data: { [k: string]: any } = {};\n\n constructor(k?: string | number) {\n this.key = k;\n }\n\n /**\n * check if some context is set\n *\n * @param ctxt\n */\n has(ctxt: string) {\n return _.has(this.data, ctxt);\n }\n\n\n /**\n * get context value\n *\n * @param k\n */\n get(k?: string) {\n if (k) {\n return _.get(this.data, k, null);\n }\n return this.data;\n }\n\n\n /**\n * set a context value\n *\n * @param k\n * @param value\n */\n set(k: string, value: any) {\n if (!this.has(k)) {\n this.data[k] = _.isObjectLike(value) ? {} : null;\n }\n if (_.isObjectLike()) {\n this.data[k] = _.assign(this.data[k], value);\n } else {\n this.data[k] = value;\n }\n\n }\n\n\n merge(ctx: Context) {\n this.data = _.merge(this.data, ctx.data);\n }\n\n}\n"],"sourceRoot":".."}
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"}
@@ -0,0 +1,10 @@
1
+ import { Selector } from "./Selector";
2
+ export declare class KeyDesc extends Selector {
3
+ toJson(): {
4
+ $key: string;
5
+ };
6
+ }
7
+ /**
8
+ * Key
9
+ */
10
+ export declare function Key(k: string): KeyDesc;
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
@@ -7,5 +7,4 @@ class MultiArgs {
7
7
  }
8
8
  }
9
9
  exports.MultiArgs = MultiArgs;
10
-
11
- //# sourceMappingURL=MultiArgs.js.map
10
+ //# sourceMappingURL=MultiArgs.js.map
@@ -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","file":"MultiArgs.js","sourcesContent":["export class MultiArgs {\n readonly args: any[];\n\n constructor(...args: any[]) {\n this.args = args;\n }\n\n\n}\n"],"sourceRoot":".."}
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
- items: PAst[];
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
- constructor(e, kv, p, ctxt) {
8
- super(e, p, ctxt);
9
- this.items = [];
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.items) {
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.items[i] = this.base.interprete(kv[i], this, ctxt);
32
+ this.value[i] = this.getRootExpression().interprete(kv[i], this, ctxt);
36
33
  }
37
34
  }
38
35
  visit(o) {
39
36
  const state = {};
40
- const res = o.visitArray(this, state);
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.items.length; i++) {
45
- res.push(this.items[i].visit(o));
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 o.leaveArray(res, this);
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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AAG,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE;YACxB,OAAO,GAAG,CAAC;SACZ;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAClC;QACD,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;CAGF;AApDD,wBAoDC","file":"PArray.js","sourcesContent":["import {PAst} from './PAst';\nimport {MangoExpression} from '../MangoExpression';\nimport {IMangoWalker, IMangoWalkerControl} from '../IMangoWalker';\nimport {Context} from './Context';\n\nexport class PArray extends PAst {\n\n items: PAst[] = [];\n\n\n constructor(e: MangoExpression, kv: any[], p?: PAst, ctxt?: Context) {\n super(e, p, ctxt);\n this.interprete(kv);\n }\n\n getKey(key: string): PAst {\n for (const item of this.items) {\n const found = item.getKey(key);\n if (found) {\n return found;\n }\n }\n return null;\n }\n\n keys() {\n const keys: string[] = [];\n for (const item of this.items) {\n const subkey = item.keys();\n subkey.forEach((x: string) => {\n keys.push(x);\n });\n }\n return keys;\n }\n\n interprete(kv: any) {\n for (let i = 0; i < kv.length; i++) {\n const ctxt = new Context();\n ctxt.key = i;\n this.items[i] = this.base.interprete(kv[i], this, ctxt);\n }\n }\n\n visit(o: IMangoWalker): any {\n const state: IMangoWalkerControl = {};\n const res = o.visitArray(this, state);\n if (state && state.abort) {\n return res;\n }\n for (let i = 0; i < this.items.length; i++) {\n res.push(this.items[i].visit(o));\n }\n return o.leaveArray(res, this);\n }\n\n\n}\n\n\n"],"sourceRoot":".."}
1
+ {"version":3,"file":"PArray.js","sourceRoot":"","sources":["../../../src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,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAe;QACnB,MAAM,KAAK,GAAwB,EAAE,CAAC;QACtC,IAAI,GAAG,GAAU,EAAE,CAAC;QACpB,IAAG,CAAC,CAAC,UAAU,EAAC,CAAC;YACf,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,GAAG,CAAC;QACb,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,IAAG,CAAC,CAAC,UAAU,EAAC,CAAC;YACf,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,GAAG,CAAC;IAGb,CAAC;CAGF;AA1DD,wBA0DC"}
package/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
- readonly base: MangoExpression;
6
- readonly parent: PAst;
7
- readonly key: string | number;
8
- readonly context: Context;
9
- constructor(e: MangoExpression, p: PAst, ctxt?: Context);
4
+ export declare abstract class PAst<X> {
5
+ private rootExpression;
6
+ private parent;
7
+ private key;
8
+ private 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 getKey(key: string): PAst;
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
- constructor(e, p, ctxt) {
7
- this.context = new Context_1.Context();
8
- this.base = e;
9
- this.parent = p;
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.context.merge(ctxt);
85
+ this.getContext().merge(ctxt);
13
86
  }
14
87
  }
15
88
  keys() {
16
- const keys = [this.key];
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