@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.
Files changed (275) hide show
  1. package/AExpr.d.ts +11 -0
  2. package/AExpr.js +37 -0
  3. package/AExpr.js.map +1 -0
  4. package/Constants.d.ts +3 -0
  5. package/Constants.js +2 -5
  6. package/Constants.js.map +1 -1
  7. package/IWalker.d.ts +19 -0
  8. package/IWalker.js +2 -0
  9. package/IWalker.js.map +1 -0
  10. package/README.md +69 -1
  11. package/_Expr.d.ts +1 -0
  12. package/_Expr.js +52 -0
  13. package/_Expr.js.map +1 -0
  14. package/ast/AbstractValue.d.ts +7 -0
  15. package/ast/AbstractValue.js +27 -0
  16. package/ast/AbstractValue.js.map +1 -0
  17. package/ast/Bindings.d.ts +1 -2
  18. package/ast/Bindings.js +1 -5
  19. package/ast/Bindings.js.map +1 -1
  20. package/ast/Constan.d.ts +11 -0
  21. package/ast/Constan.js +2 -0
  22. package/ast/Constan.js.map +1 -0
  23. package/ast/Context.js +8 -12
  24. package/ast/Context.js.map +1 -1
  25. package/ast/Expr.d.ts +23 -0
  26. package/ast/Expr.js +90 -0
  27. package/ast/Expr.js.map +1 -0
  28. package/ast/IExpr.d.ts +16 -0
  29. package/ast/IExpr.js +2 -0
  30. package/ast/IExpr.js.map +1 -0
  31. package/ast/IParser.d.ts +14 -0
  32. package/ast/IParser.js +2 -0
  33. package/ast/IParser.js.map +1 -0
  34. package/ast/IStackEntry.d.ts +13 -0
  35. package/ast/IStackEntry.js +2 -0
  36. package/ast/IStackEntry.js.map +1 -0
  37. package/ast/JsonParser.d.ts +25 -0
  38. package/ast/JsonParser.js +60 -0
  39. package/ast/JsonParser.js.map +1 -0
  40. package/ast/KeyDesc.d.ts +2 -4
  41. package/ast/KeyDesc.js +4 -9
  42. package/ast/KeyDesc.js.map +1 -1
  43. package/ast/MultiArgs.js +1 -5
  44. package/ast/MultiArgs.js.map +1 -1
  45. package/ast/PArray.d.ts +1 -10
  46. package/ast/PArray.js +67 -53
  47. package/ast/PArray.js.map +1 -1
  48. package/ast/PObject.d.ts +1 -17
  49. package/ast/PObject.js +130 -108
  50. package/ast/PObject.js.map +1 -1
  51. package/ast/RefDesc.d.ts +5 -0
  52. package/ast/RefDesc.js +12 -0
  53. package/ast/RefDesc.js.map +1 -0
  54. package/ast/Selector.d.ts +19 -5
  55. package/ast/Selector.js +31 -9
  56. package/ast/Selector.js.map +1 -1
  57. package/ast/StackEntry.d.ts +24 -0
  58. package/ast/StackEntry.js +121 -0
  59. package/ast/StackEntry.js.map +1 -0
  60. package/ast/StringParser.d.ts +16 -0
  61. package/ast/StringParser.js +303 -0
  62. package/ast/StringParser.js.map +1 -0
  63. package/ast/Unset.d.ts +2 -2
  64. package/ast/Unset.js +2 -6
  65. package/ast/Unset.js.map +1 -1
  66. package/ast/ValueDesc.d.ts +4 -0
  67. package/ast/ValueDesc.js +9 -0
  68. package/ast/ValueDesc.js.map +1 -0
  69. package/ast/functions.d.ts +1 -0
  70. package/ast/functions.js +8 -0
  71. package/ast/functions.js.map +1 -0
  72. package/browser.d.ts +52 -55
  73. package/browser.js +53 -117
  74. package/browser.js.map +1 -1
  75. package/errors/InvalidValueError.d.ts +4 -0
  76. package/errors/InvalidValueError.js +6 -0
  77. package/errors/InvalidValueError.js.map +1 -0
  78. package/errors/NotYetImplementedError.d.ts +3 -0
  79. package/errors/NotYetImplementedError.js +6 -0
  80. package/errors/NotYetImplementedError.js.map +1 -0
  81. package/errors/UnsupportedInputError.d.ts +3 -0
  82. package/errors/UnsupportedInputError.js +6 -0
  83. package/errors/UnsupportedInputError.js.map +1 -0
  84. package/functions.d.ts +9 -0
  85. package/functions.js +107 -0
  86. package/functions.js.map +1 -0
  87. package/index.d.ts +1 -1
  88. package/index.js +5 -64
  89. package/index.js.map +1 -1
  90. package/operators/AbstractCompare.d.ts +23 -0
  91. package/operators/AbstractCompare.js +100 -0
  92. package/operators/AbstractCompare.js.map +1 -0
  93. package/operators/AbstractFunction.d.ts +6 -0
  94. package/operators/AbstractFunction.js +10 -0
  95. package/operators/AbstractFunction.js.map +1 -0
  96. package/operators/AbstractJunctor.d.ts +13 -0
  97. package/operators/AbstractJunctor.js +31 -0
  98. package/operators/AbstractJunctor.js.map +1 -0
  99. package/operators/AbstractJunctorArray.d.ts +18 -0
  100. package/operators/AbstractJunctorArray.js +63 -0
  101. package/operators/AbstractJunctorArray.js.map +1 -0
  102. package/operators/AbstractOperator.d.ts +6 -6
  103. package/operators/AbstractOperator.js +12 -31
  104. package/operators/AbstractOperator.js.map +1 -1
  105. package/operators/Components.d.ts +30 -0
  106. package/operators/Components.js +140 -0
  107. package/operators/Components.js.map +1 -0
  108. package/operators/arithmetic/Avg.d.ts +2 -2
  109. package/operators/arithmetic/Avg.js +2 -6
  110. package/operators/arithmetic/Avg.js.map +1 -1
  111. package/operators/arithmetic/Count.d.ts +2 -2
  112. package/operators/arithmetic/Count.js +2 -6
  113. package/operators/arithmetic/Count.js.map +1 -1
  114. package/operators/arithmetic/Max.d.ts +2 -2
  115. package/operators/arithmetic/Max.js +2 -6
  116. package/operators/arithmetic/Max.js.map +1 -1
  117. package/operators/arithmetic/Min.d.ts +2 -2
  118. package/operators/arithmetic/Min.js +2 -6
  119. package/operators/arithmetic/Min.js.map +1 -1
  120. package/operators/arithmetic/Multiply.d.ts +2 -2
  121. package/operators/arithmetic/Multiply.js +2 -6
  122. package/operators/arithmetic/Multiply.js.map +1 -1
  123. package/operators/arithmetic/Sum.d.ts +2 -2
  124. package/operators/arithmetic/Sum.js +2 -6
  125. package/operators/arithmetic/Sum.js.map +1 -1
  126. package/operators/array/First.d.ts +2 -4
  127. package/operators/array/First.js +9 -15
  128. package/operators/array/First.js.map +1 -1
  129. package/operators/array/Last.d.ts +2 -4
  130. package/operators/array/Last.js +9 -15
  131. package/operators/array/Last.js.map +1 -1
  132. package/operators/array/Map.d.ts +5 -6
  133. package/operators/array/Map.js +14 -20
  134. package/operators/array/Map.js.map +1 -1
  135. package/operators/compare/EqualDesc.d.ts +6 -7
  136. package/operators/compare/EqualDesc.js +13 -11
  137. package/operators/compare/EqualDesc.js.map +1 -1
  138. package/operators/compare/EqualDescLookup.d.ts +2 -2
  139. package/operators/compare/EqualDescLookup.js +24 -31
  140. package/operators/compare/EqualDescLookup.js.map +1 -1
  141. package/operators/compare/GreaterThen.d.ts +3 -4
  142. package/operators/compare/GreaterThen.js +3 -7
  143. package/operators/compare/GreaterThen.js.map +1 -1
  144. package/operators/compare/GreaterThenEqual.d.ts +3 -4
  145. package/operators/compare/GreaterThenEqual.js +3 -7
  146. package/operators/compare/GreaterThenEqual.js.map +1 -1
  147. package/operators/compare/In.d.ts +3 -4
  148. package/operators/compare/In.js +3 -7
  149. package/operators/compare/In.js.map +1 -1
  150. package/operators/compare/IsNotNull.d.ts +3 -3
  151. package/operators/compare/IsNotNull.js +3 -7
  152. package/operators/compare/IsNotNull.js.map +1 -1
  153. package/operators/compare/IsNull.d.ts +3 -3
  154. package/operators/compare/IsNull.js +3 -7
  155. package/operators/compare/IsNull.js.map +1 -1
  156. package/operators/compare/LessThen.d.ts +3 -3
  157. package/operators/compare/LessThen.js +3 -6
  158. package/operators/compare/LessThen.js.map +1 -1
  159. package/operators/compare/LessThenEqual.d.ts +3 -4
  160. package/operators/compare/LessThenEqual.js +3 -7
  161. package/operators/compare/LessThenEqual.js.map +1 -1
  162. package/operators/compare/Like.d.ts +3 -4
  163. package/operators/compare/Like.js +3 -7
  164. package/operators/compare/Like.js.map +1 -1
  165. package/operators/compare/NotEqual.d.ts +3 -4
  166. package/operators/compare/NotEqual.js +3 -7
  167. package/operators/compare/NotEqual.js.map +1 -1
  168. package/operators/compare/NotIn.d.ts +3 -4
  169. package/operators/compare/NotIn.js +3 -7
  170. package/operators/compare/NotIn.js.map +1 -1
  171. package/operators/compare/Regex.d.ts +2 -6
  172. package/operators/compare/Regex.js +28 -33
  173. package/operators/compare/Regex.js.map +1 -1
  174. package/operators/date/Date.d.ts +2 -2
  175. package/operators/date/Date.js +3 -6
  176. package/operators/date/Date.js.map +1 -1
  177. package/operators/date/DateToString.d.ts +4 -5
  178. package/operators/date/DateToString.js +15 -20
  179. package/operators/date/DateToString.js.map +1 -1
  180. package/operators/date/Day.d.ts +2 -2
  181. package/operators/date/Day.js +2 -6
  182. package/operators/date/Day.js.map +1 -1
  183. package/operators/date/Month.d.ts +2 -2
  184. package/operators/date/Month.js +2 -6
  185. package/operators/date/Month.js.map +1 -1
  186. package/operators/date/Year.d.ts +2 -2
  187. package/operators/date/Year.js +2 -6
  188. package/operators/date/Year.js.map +1 -1
  189. package/operators/logic/AndDesc.d.ts +5 -7
  190. package/operators/logic/AndDesc.js +16 -21
  191. package/operators/logic/AndDesc.js.map +1 -1
  192. package/operators/logic/AndDescLookup.d.ts +2 -2
  193. package/operators/logic/AndDescLookup.js +1 -5
  194. package/operators/logic/AndDescLookup.js.map +1 -1
  195. package/operators/logic/NotDesc.d.ts +8 -0
  196. package/operators/logic/NotDesc.js +21 -0
  197. package/operators/logic/NotDesc.js.map +1 -0
  198. package/operators/logic/OrDesc.d.ts +5 -7
  199. package/operators/logic/OrDesc.js +5 -21
  200. package/operators/logic/OrDesc.js.map +1 -1
  201. package/operators/stage/AbstractSection.d.ts +7 -0
  202. package/operators/stage/AbstractSection.js +11 -0
  203. package/operators/stage/AbstractSection.js.map +1 -0
  204. package/operators/stage/Group.d.ts +4 -10
  205. package/operators/stage/Group.js +33 -39
  206. package/operators/stage/Group.js.map +1 -1
  207. package/operators/stage/Limit.d.ts +2 -2
  208. package/operators/stage/Limit.js +2 -6
  209. package/operators/stage/Limit.js.map +1 -1
  210. package/operators/stage/Match.d.ts +2 -8
  211. package/operators/stage/Match.js +2 -20
  212. package/operators/stage/Match.js.map +1 -1
  213. package/operators/stage/Project.d.ts +2 -8
  214. package/operators/stage/Project.js +17 -21
  215. package/operators/stage/Project.js.map +1 -1
  216. package/operators/stage/Query..d.ts +1 -0
  217. package/operators/stage/Query..js +3 -0
  218. package/operators/stage/Query..js.map +1 -0
  219. package/operators/stage/Skip.d.ts +2 -6
  220. package/operators/stage/Skip.js +6 -11
  221. package/operators/stage/Skip.js.map +1 -1
  222. package/operators/stage/Sort.d.ts +2 -6
  223. package/operators/stage/Sort.js +6 -11
  224. package/operators/stage/Sort.js.map +1 -1
  225. package/operators/string/Substr.d.ts +2 -4
  226. package/operators/string/Substr.js +19 -22
  227. package/operators/string/Substr.js.map +1 -1
  228. package/operators/string/ToFloat.d.ts +2 -3
  229. package/operators/string/ToFloat.js +9 -15
  230. package/operators/string/ToFloat.js.map +1 -1
  231. package/operators/string/ToInt.d.ts +2 -3
  232. package/operators/string/ToInt.js +9 -15
  233. package/operators/string/ToInt.js.map +1 -1
  234. package/operators/string/ToLower.d.ts +2 -3
  235. package/operators/string/ToLower.js +9 -15
  236. package/operators/string/ToLower.js.map +1 -1
  237. package/operators/string/ToUpper.d.ts +2 -4
  238. package/operators/string/ToUpper.js +9 -15
  239. package/operators/string/ToUpper.js.map +1 -1
  240. package/package.json +2 -1
  241. package/walker/lookup/ILookupFn.d.ts +2 -2
  242. package/walker/lookup/ILookupFn.js +1 -2
  243. package/walker/lookup/LookupWalker.d.ts +11 -11
  244. package/walker/lookup/LookupWalker.js +19 -23
  245. package/walker/lookup/LookupWalker.js.map +1 -1
  246. package/IMangoWalker.d.ts +0 -19
  247. package/IMangoWalker.js +0 -3
  248. package/IMangoWalker.js.map +0 -1
  249. package/MangoExpression.d.ts +0 -15
  250. package/MangoExpression.js +0 -88
  251. package/MangoExpression.js.map +0 -1
  252. package/ast/PAst.d.ts +0 -42
  253. package/ast/PAst.js +0 -158
  254. package/ast/PAst.js.map +0 -1
  255. package/ast/PValue.d.ts +0 -10
  256. package/ast/PValue.js +0 -22
  257. package/ast/PValue.js.map +0 -1
  258. package/ast/Value.d.ts +0 -3
  259. package/ast/Value.js +0 -8
  260. package/ast/Value.js.map +0 -1
  261. package/ast/ValueRef.d.ts +0 -4
  262. package/ast/ValueRef.js +0 -11
  263. package/ast/ValueRef.js.map +0 -1
  264. package/operators/Operators.d.ts +0 -35
  265. package/operators/Operators.js +0 -149
  266. package/operators/Operators.js.map +0 -1
  267. package/operators/compare/AbstractCompare.d.ts +0 -5
  268. package/operators/compare/AbstractCompare.js +0 -14
  269. package/operators/compare/AbstractCompare.js.map +0 -1
  270. package/operators/logic/AbstractLogic.d.ts +0 -3
  271. package/operators/logic/AbstractLogic.js +0 -8
  272. package/operators/logic/AbstractLogic.js.map +0 -1
  273. package/operators/logic/Not.d.ts +0 -8
  274. package/operators/logic/Not.js +0 -22
  275. 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":"","sources":["../../src/AExpr.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAE7C,MAAM,OAAO,KAAK;IAGhB,MAAM,CAAC,IAAI,CAAC,IAAU;QACpB,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,YAAoB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAE9B,CAAC;IAGD,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,OAAO,CAAc,CAAC;IACnE,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,OAAO,CAAc,CAAC;IACnE,CAAC;IAGD,cAAc,CAAC,YAAY,GAAG,IAAI;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,eAAe,CAAsB,CAAC;QAC5F,MAAM,GAAG,GAAQ,EAAE,CAAA;QACnB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;YACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC;YACtC,IAAI,GAAG,YAAY,OAAO,EAAE,CAAC;gBAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC;gBACrC,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;oBAC/B,GAAG,CAAC,QAAQ,CAAC,GAAG,GAAG,YAAY,GAAG,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
@@ -1,2 +1,5 @@
1
1
  export declare const AUTO_EQUAL_CONV_SUPPORT = "AUTO_EQUAL_CONV_SUPPORT";
2
2
  export declare const NUMBER_PROJECT_SUPPORT = "NUMBER_PROJECT_SUPPORT";
3
+ export type ClassType<T> = {
4
+ new (...args: any[]): T;
5
+ };
package/Constants.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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":";;;AAAa,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AACpD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC"}
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
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IWalker.js.map
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
  [![Dependency Status](https://david-dm.org/allgemein/mango-expressions.svg)](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,7 @@
1
+ import { Expr } from './Expr.js';
2
+ import { IStackEntry } from "./IStackEntry.js";
3
+ import { IExpr } from "./IExpr.js";
4
+ export declare abstract class AbstractValue extends Expr {
5
+ parse(entry: IStackEntry, parital: any): IExpr;
6
+ toJson(): any;
7
+ }
@@ -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
@@ -1,7 +1,6 @@
1
- import { PAst } from './PAst';
2
1
  import { ClassType } from '@allgemein/schema-api';
3
2
  export interface IBinding<X> {
4
- on: ClassType<PAst<any>>;
3
+ on: ClassType<any>;
5
4
  use: ClassType<X>;
6
5
  }
7
6
  export declare class Bindings<X> {
package/ast/Bindings.js CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";
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
@@ -1 +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"}
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"}
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Constan.js.map
@@ -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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 (0, lodash_1.has)(this.data, ctxt);
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 (0, lodash_1.get)(this.data, k, null);
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] = (0, lodash_1.isObjectLike)(value) ? {} : null;
34
+ this.data[k] = isObjectLike(value) ? {} : null;
38
35
  }
39
- if ((0, lodash_1.isObjectLike)()) {
40
- this.data[k] = (0, lodash_1.assign)(this.data[k], value);
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 = (0, lodash_1.merge)(this.data, ctx.data);
44
+ this.data = merge(this.data, ctx.data);
48
45
  }
49
46
  }
50
- exports.Context = Context;
51
47
  //# sourceMappingURL=Context.js.map
@@ -1 +1 @@
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"}
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Expr.js","sourceRoot":"","sources":["../../../src/ast/Expr.ts"],"names":[],"mappings":"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"}
package/ast/IExpr.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { IStackEntry } from "./IStackEntry.js";
2
+ export interface IExpr {
3
+ /**
4
+ *
5
+ *
6
+ * @param entry
7
+ * @param partial
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
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IExpr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IExpr.js","sourceRoot":"","sources":["../../../src/ast/IExpr.ts"],"names":[],"mappings":""}
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IParser.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IStackEntry.js.map
@@ -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
+ }