@fincity/kirun-js 1.0.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 (217) hide show
  1. package/.prettierrc +9 -0
  2. package/__tests__/engine/function/system/array/AddFirstTest.ts +235 -0
  3. package/__tests__/engine/function/system/array/AddTest.ts +126 -0
  4. package/__tests__/engine/function/system/array/BinarySearchTest.ts +135 -0
  5. package/__tests__/engine/function/system/array/CompareTest.ts +48 -0
  6. package/__tests__/engine/function/system/array/CopyTest.ts +86 -0
  7. package/__tests__/engine/function/system/array/DeleteFirstTest.ts +103 -0
  8. package/__tests__/engine/function/system/array/DeleteFromTest.ts +232 -0
  9. package/__tests__/engine/function/system/array/DeleteLastTest.ts +103 -0
  10. package/__tests__/engine/function/system/array/DeleteTest.ts +110 -0
  11. package/__tests__/engine/function/system/array/DisjointTest.ts +184 -0
  12. package/__tests__/engine/function/system/array/Equals.ts +67 -0
  13. package/__tests__/engine/function/system/array/FillTest.ts +36 -0
  14. package/__tests__/engine/function/system/array/FrequencyTest.ts +97 -0
  15. package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +347 -0
  16. package/__tests__/engine/function/system/array/IndexOfTest.ts +267 -0
  17. package/__tests__/engine/function/system/array/InsertTest.ts +229 -0
  18. package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +213 -0
  19. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +253 -0
  20. package/__tests__/engine/function/system/array/MaxTest.ts +98 -0
  21. package/__tests__/engine/function/system/array/MinTest.ts +99 -0
  22. package/__tests__/engine/function/system/array/MisMatchTest.ts +215 -0
  23. package/__tests__/engine/function/system/array/ReverseTest.ts +235 -0
  24. package/__tests__/engine/function/system/array/RotateTest.ts +137 -0
  25. package/__tests__/engine/function/system/array/ShuffleTest.ts +154 -0
  26. package/__tests__/engine/function/system/array/SortTest.ts +130 -0
  27. package/__tests__/engine/function/system/array/SubArrayTest.ts +236 -0
  28. package/__tests__/engine/function/system/math/AddTest.ts +12 -0
  29. package/__tests__/engine/function/system/string/ConcatenateTest.ts +46 -0
  30. package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +38 -0
  31. package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +53 -0
  32. package/__tests__/engine/function/system/string/PostPadTest.ts +54 -0
  33. package/__tests__/engine/function/system/string/PrePadTest.ts +54 -0
  34. package/__tests__/engine/function/system/string/RegionMatchesTest.ts +78 -0
  35. package/__tests__/engine/function/system/string/ReverseTest.ts +36 -0
  36. package/__tests__/engine/function/system/string/SplitTest.ts +61 -0
  37. package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +126 -0
  38. package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +54 -0
  39. package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +146 -0
  40. package/__tests__/engine/function/system/string/ToStringTest.ts +43 -0
  41. package/__tests__/engine/function/system/string/TrimToTest.ts +28 -0
  42. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +26 -0
  43. package/__tests__/engine/runtime/KIRuntimeTest.ts +351 -0
  44. package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +128 -0
  45. package/__tests__/engine/runtime/expression/ExpressionTest.ts +33 -0
  46. package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +44 -0
  47. package/__tests__/engine/runtime/expression/tokenextractor/TokenValueExtractorTest.ts +72 -0
  48. package/__tests__/engine/util/LinkedListTest.ts +29 -0
  49. package/__tests__/engine/util/string/StringFormatterTest.ts +17 -0
  50. package/__tests__/indexTest.ts +33 -0
  51. package/dist/index.js +2 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/module.js +2 -0
  54. package/dist/module.js.map +1 -0
  55. package/dist/types.d.ts +430 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/package.json +54 -0
  58. package/src/engine/HybridRepository.ts +18 -0
  59. package/src/engine/Repository.ts +3 -0
  60. package/src/engine/constant/KIRunConstants.ts +7 -0
  61. package/src/engine/exception/ExecutionException.ts +12 -0
  62. package/src/engine/exception/KIRuntimeException.ts +12 -0
  63. package/src/engine/function/AbstractFunction.ts +76 -0
  64. package/src/engine/function/Function.ts +13 -0
  65. package/src/engine/function/system/GenerateEvent.ts +76 -0
  66. package/src/engine/function/system/If.ts +40 -0
  67. package/src/engine/function/system/array/AbstractArrayFunction.ts +158 -0
  68. package/src/engine/function/system/array/Add.ts +31 -0
  69. package/src/engine/function/system/array/AddFirst.ts +44 -0
  70. package/src/engine/function/system/array/BinarySearch.ts +66 -0
  71. package/src/engine/function/system/array/Compare.ts +150 -0
  72. package/src/engine/function/system/array/Copy.ts +56 -0
  73. package/src/engine/function/system/array/Delete.ts +63 -0
  74. package/src/engine/function/system/array/DeleteFirst.ts +22 -0
  75. package/src/engine/function/system/array/DeleteFrom.ts +51 -0
  76. package/src/engine/function/system/array/DeleteLast.ts +23 -0
  77. package/src/engine/function/system/array/Disjoint.ts +85 -0
  78. package/src/engine/function/system/array/Equals.ts +36 -0
  79. package/src/engine/function/system/array/Fill.ts +51 -0
  80. package/src/engine/function/system/array/Frequency.ts +68 -0
  81. package/src/engine/function/system/array/IndexOf.ts +56 -0
  82. package/src/engine/function/system/array/IndexOfArray.ts +67 -0
  83. package/src/engine/function/system/array/Insert.ts +48 -0
  84. package/src/engine/function/system/array/LastIndexOf.ts +62 -0
  85. package/src/engine/function/system/array/LastIndexOfArray.ts +70 -0
  86. package/src/engine/function/system/array/Max.ts +31 -0
  87. package/src/engine/function/system/array/Min.ts +32 -0
  88. package/src/engine/function/system/array/MisMatch.ts +66 -0
  89. package/src/engine/function/system/array/Reverse.ts +50 -0
  90. package/src/engine/function/system/array/Rotate.ts +43 -0
  91. package/src/engine/function/system/array/Shuffle.ts +31 -0
  92. package/src/engine/function/system/array/Sort.ts +70 -0
  93. package/src/engine/function/system/array/SubArray.ts +48 -0
  94. package/src/engine/function/system/context/Create.ts +73 -0
  95. package/src/engine/function/system/context/Get.ts +55 -0
  96. package/src/engine/function/system/context/SetFunction.ts +244 -0
  97. package/src/engine/function/system/loop/CountLoop.ts +55 -0
  98. package/src/engine/function/system/loop/RangeLoop.ts +120 -0
  99. package/src/engine/function/system/math/Add.ts +34 -0
  100. package/src/engine/function/system/math/GenericMathFunction.ts +80 -0
  101. package/src/engine/function/system/math/Hypotenuse.ts +57 -0
  102. package/src/engine/function/system/math/MathFunctionRepository.ts +63 -0
  103. package/src/engine/function/system/math/Maximum.ts +38 -0
  104. package/src/engine/function/system/math/Minimum.ts +38 -0
  105. package/src/engine/function/system/math/Random.ts +27 -0
  106. package/src/engine/function/system/string/AbstractStringFunction.ts +409 -0
  107. package/src/engine/function/system/string/Concatenate.ts +57 -0
  108. package/src/engine/function/system/string/DeleteForGivenLength.ts +82 -0
  109. package/src/engine/function/system/string/InsertAtGivenPosition.ts +72 -0
  110. package/src/engine/function/system/string/PostPad.ts +83 -0
  111. package/src/engine/function/system/string/PrePad.ts +73 -0
  112. package/src/engine/function/system/string/RegionMatches.ts +119 -0
  113. package/src/engine/function/system/string/ReplaceAtGivenPosition.ts +101 -0
  114. package/src/engine/function/system/string/Reverse.ts +62 -0
  115. package/src/engine/function/system/string/Split.ts +53 -0
  116. package/src/engine/function/system/string/StringFunctionRepository.ts +60 -0
  117. package/src/engine/function/system/string/ToString.ts +45 -0
  118. package/src/engine/function/system/string/TrimTo.ts +55 -0
  119. package/src/engine/json/JsonExpression.ts +11 -0
  120. package/src/engine/json/schema/Schema.ts +670 -0
  121. package/src/engine/json/schema/SchemaUtil.ts +145 -0
  122. package/src/engine/json/schema/array/ArraySchemaType.ts +44 -0
  123. package/src/engine/json/schema/object/AdditionalPropertiesType.ts +32 -0
  124. package/src/engine/json/schema/string/StringFormat.ts +7 -0
  125. package/src/engine/json/schema/type/MultipleType.ts +28 -0
  126. package/src/engine/json/schema/type/SchemaType.ts +11 -0
  127. package/src/engine/json/schema/type/SingleType.ts +23 -0
  128. package/src/engine/json/schema/type/Type.ts +6 -0
  129. package/src/engine/json/schema/type/TypeUtil.ts +25 -0
  130. package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +108 -0
  131. package/src/engine/json/schema/validator/ArrayValidator.ts +145 -0
  132. package/src/engine/json/schema/validator/BooleanValidator.ts +24 -0
  133. package/src/engine/json/schema/validator/NullValidator.ts +17 -0
  134. package/src/engine/json/schema/validator/NumberValidator.ts +115 -0
  135. package/src/engine/json/schema/validator/ObjectValidator.ts +184 -0
  136. package/src/engine/json/schema/validator/SchemaValidator.ts +141 -0
  137. package/src/engine/json/schema/validator/StringValidator.ts +97 -0
  138. package/src/engine/json/schema/validator/TypeValidator.ts +49 -0
  139. package/src/engine/json/schema/validator/exception/SchemaReferenceException.ts +19 -0
  140. package/src/engine/json/schema/validator/exception/SchemaValidationException.ts +22 -0
  141. package/src/engine/model/AbstractStatement.ts +29 -0
  142. package/src/engine/model/Argument.ts +36 -0
  143. package/src/engine/model/Event.ts +62 -0
  144. package/src/engine/model/EventResult.ts +34 -0
  145. package/src/engine/model/FunctionDefinition.ts +69 -0
  146. package/src/engine/model/FunctionOutput.ts +37 -0
  147. package/src/engine/model/FunctionOutputGenerator.ts +5 -0
  148. package/src/engine/model/FunctionSignature.ts +67 -0
  149. package/src/engine/model/Parameter.ts +97 -0
  150. package/src/engine/model/ParameterReference.ts +57 -0
  151. package/src/engine/model/ParameterReferenceType.ts +4 -0
  152. package/src/engine/model/ParameterType.ts +4 -0
  153. package/src/engine/model/Position.ts +40 -0
  154. package/src/engine/model/Statement.ts +101 -0
  155. package/src/engine/model/StatementGroup.ts +37 -0
  156. package/src/engine/namespaces/Namespaces.ts +11 -0
  157. package/src/engine/repository/KIRunFunctionRepository.ts +37 -0
  158. package/src/engine/repository/KIRunSchemaRepository.ts +24 -0
  159. package/src/engine/runtime/ContextElement.ts +28 -0
  160. package/src/engine/runtime/FunctionExecutionParameters.ts +74 -0
  161. package/src/engine/runtime/KIRuntime.ts +653 -0
  162. package/src/engine/runtime/StatementExecution.ts +61 -0
  163. package/src/engine/runtime/StatementMessage.ts +30 -0
  164. package/src/engine/runtime/StatementMessageType.ts +5 -0
  165. package/src/engine/runtime/expression/Expression.ts +330 -0
  166. package/src/engine/runtime/expression/ExpressionEvaluator.ts +305 -0
  167. package/src/engine/runtime/expression/ExpressionToken.ts +15 -0
  168. package/src/engine/runtime/expression/ExpressionTokenValue.ts +23 -0
  169. package/src/engine/runtime/expression/Operation.ts +190 -0
  170. package/src/engine/runtime/expression/exception/ExpressionEvaluationException.ts +15 -0
  171. package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +9 -0
  172. package/src/engine/runtime/expression/operators/binary/ArithmeticDivisionOperator.ts +9 -0
  173. package/src/engine/runtime/expression/operators/binary/ArithmeticInetgerDivisionOperator.ts +9 -0
  174. package/src/engine/runtime/expression/operators/binary/ArithmeticModulusOperator.ts +9 -0
  175. package/src/engine/runtime/expression/operators/binary/ArithmeticMultiplicationOperator.ts +9 -0
  176. package/src/engine/runtime/expression/operators/binary/ArithmeticSubtractionOperator.ts +9 -0
  177. package/src/engine/runtime/expression/operators/binary/ArrayOperator.ts +31 -0
  178. package/src/engine/runtime/expression/operators/binary/BinaryOperator.ts +15 -0
  179. package/src/engine/runtime/expression/operators/binary/BitwiseAndOperator.ts +9 -0
  180. package/src/engine/runtime/expression/operators/binary/BitwiseLeftShiftOperator.ts +9 -0
  181. package/src/engine/runtime/expression/operators/binary/BitwiseOrOperator.ts +9 -0
  182. package/src/engine/runtime/expression/operators/binary/BitwiseRightShiftOperator.ts +9 -0
  183. package/src/engine/runtime/expression/operators/binary/BitwiseUnsignedRightShiftOperator.ts +9 -0
  184. package/src/engine/runtime/expression/operators/binary/BitwiseXorOperator.ts +9 -0
  185. package/src/engine/runtime/expression/operators/binary/LogicalAndOperator.ts +25 -0
  186. package/src/engine/runtime/expression/operators/binary/LogicalEqualOperator.ts +13 -0
  187. package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanEqualOperator.ts +24 -0
  188. package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanOperator.ts +24 -0
  189. package/src/engine/runtime/expression/operators/binary/LogicalLessThanEqualOperator.ts +24 -0
  190. package/src/engine/runtime/expression/operators/binary/LogicalLessThanOperator.ts +24 -0
  191. package/src/engine/runtime/expression/operators/binary/LogicalNotEqualOperator.ts +13 -0
  192. package/src/engine/runtime/expression/operators/binary/LogicalOrOperator.ts +25 -0
  193. package/src/engine/runtime/expression/operators/binary/ObjectOperator.ts +24 -0
  194. package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryMinusOperator.ts +13 -0
  195. package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryPlusOperator.ts +13 -0
  196. package/src/engine/runtime/expression/operators/unary/BitwiseComplementOperator.ts +22 -0
  197. package/src/engine/runtime/expression/operators/unary/LogicalNotOperator.ts +22 -0
  198. package/src/engine/runtime/expression/operators/unary/UnaryOperator.ts +15 -0
  199. package/src/engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor.ts +64 -0
  200. package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +136 -0
  201. package/src/engine/runtime/graph/ExecutionGraph.ts +81 -0
  202. package/src/engine/runtime/graph/GraphVertex.ts +118 -0
  203. package/src/engine/runtime/graph/GraphVertexType.ts +4 -0
  204. package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +22 -0
  205. package/src/engine/runtime/tokenextractor/ContextTokenValueExtractor.ts +37 -0
  206. package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +32 -0
  207. package/src/engine/util/ArrayUtil.ts +23 -0
  208. package/src/engine/util/LinkedList.ts +229 -0
  209. package/src/engine/util/MapUtil.ts +86 -0
  210. package/src/engine/util/NullCheck.ts +3 -0
  211. package/src/engine/util/Tuples.ts +43 -0
  212. package/src/engine/util/primitive/PrimitiveUtil.ts +143 -0
  213. package/src/engine/util/string/StringBuilder.ts +59 -0
  214. package/src/engine/util/string/StringFormatter.ts +25 -0
  215. package/src/engine/util/string/StringUtil.ts +48 -0
  216. package/src/index.ts +13 -0
  217. package/tsconfig.json +6 -0
@@ -0,0 +1,128 @@
1
+ import { Schema } from '../../../../src/engine/json/schema/Schema';
2
+ import { ContextElement } from '../../../../src/engine/runtime/ContextElement';
3
+ import { ExpressionEvaluator } from '../../../../src/engine/runtime/expression/ExpressionEvaluator';
4
+ import { FunctionExecutionParameters } from '../../../../src/engine/runtime/FunctionExecutionParameters';
5
+
6
+ test('Expression Test', () => {
7
+ let phone = { phone1: '1234', phone2: '5678', phone3: '5678' };
8
+
9
+ let address = {
10
+ line1: 'Flat 202, PVR Estates',
11
+ line2: 'Nagvara',
12
+ city: 'Benguluru',
13
+ pin: '560048',
14
+ phone: phone,
15
+ };
16
+
17
+ let arr = [10, 20, 30];
18
+
19
+ let obj = {
20
+ studentName: 'Kumar',
21
+ math: 20,
22
+ isStudent: true,
23
+ address: address,
24
+ array: arr,
25
+ num: 1,
26
+ };
27
+
28
+ let inMap: Map<string, any> = new Map();
29
+ inMap.set('name', 'Kiran');
30
+ inMap.set('obj', obj);
31
+
32
+ let output: Map<string, Map<string, Map<string, any>>> = new Map([
33
+ ['step1', new Map([['output', inMap]])],
34
+ ['loop', new Map([['iteration', new Map([['index', 2]])]])],
35
+ ]);
36
+
37
+ let parameters: FunctionExecutionParameters = new FunctionExecutionParameters()
38
+ .setArguments(new Map())
39
+ .setContext(
40
+ new Map([
41
+ [
42
+ 'a',
43
+ new ContextElement(
44
+ Schema.ofArray('numbers', Schema.ofNumber('number')),
45
+ [1, 2],
46
+ ),
47
+ ],
48
+ ]),
49
+ )
50
+ .setSteps(output);
51
+
52
+ expect(
53
+ new ExpressionEvaluator(
54
+ 'Context.a[Steps.loop.iteration.index - 1] + Context.a[Steps.loop.iteration.index - 2]',
55
+ ).evaluate(parameters.getValuesMap()),
56
+ ).toBe(3);
57
+
58
+ expect(new ExpressionEvaluator('3 + 7').evaluate(parameters.getValuesMap())).toBe(10);
59
+ expect(new ExpressionEvaluator('"asdf"+333').evaluate(parameters.getValuesMap())).toBe(
60
+ 'asdf333',
61
+ );
62
+ expect(new ExpressionEvaluator('34 >> 2 = 8 ').evaluate(parameters.getValuesMap())).toBe(true);
63
+ expect(new ExpressionEvaluator('10*11+12*13*14/7').evaluate(parameters.getValuesMap())).toBe(
64
+ 422,
65
+ );
66
+
67
+ expect(
68
+ new ExpressionEvaluator('Steps.step1.output.name1').evaluate(parameters.getValuesMap()),
69
+ ).toBeUndefined();
70
+
71
+ expect(
72
+ new ExpressionEvaluator('"Kiran" = Steps.step1.output.name ').evaluate(
73
+ parameters.getValuesMap(),
74
+ ),
75
+ ).toBe(true);
76
+
77
+ expect(
78
+ new ExpressionEvaluator('null = Steps.step1.output.name1 ').evaluate(
79
+ parameters.getValuesMap(),
80
+ ),
81
+ ).toBe(true);
82
+
83
+ expect(
84
+ new ExpressionEvaluator('Steps.step1.output.obj.address.phone.phone2').evaluate(
85
+ parameters.getValuesMap(),
86
+ ),
87
+ ).toBe('5678');
88
+
89
+ expect(
90
+ new ExpressionEvaluator(
91
+ 'Steps.step1.output.obj.address.phone.phone2 = Steps.step1.output.obj.address.phone.phone2 ',
92
+ ).evaluate(parameters.getValuesMap()),
93
+ ).toBe(true);
94
+
95
+ expect(
96
+ new ExpressionEvaluator(
97
+ 'Steps.step1.output.obj.address.phone.phone2 != Steps.step1.output.address.obj.phone.phone1 ',
98
+ ).evaluate(parameters.getValuesMap()),
99
+ ).toBe(true);
100
+
101
+ expect(
102
+ new ExpressionEvaluator(
103
+ 'Steps.step1.output.obj.array[Steps.step1.output.obj.num +1]+2',
104
+ ).evaluate(parameters.getValuesMap()),
105
+ ).toBe(32);
106
+
107
+ expect(
108
+ new ExpressionEvaluator(
109
+ 'Steps.step1.output.obj.array[Steps.step1.output.obj.num +1]+Steps.step1.output.obj.array[Steps.step1.output.obj.num +1]',
110
+ ).evaluate(parameters.getValuesMap()),
111
+ ).toBe(60);
112
+
113
+ expect(
114
+ new ExpressionEvaluator(
115
+ 'Steps.step1.output.obj.array[Steps.step1.output.obj.num +1]+Steps.step1.output.obj.array[Steps.step1.output.obj.num +1]',
116
+ ).evaluate(parameters.getValuesMap()),
117
+ ).toBe(60);
118
+
119
+ expect(
120
+ new ExpressionEvaluator(
121
+ 'Steps.step1.output.obj.array[-Steps.step1.output.obj.num + 3]+2',
122
+ ).evaluate(parameters.getValuesMap()),
123
+ ).toBe(32);
124
+
125
+ expect(new ExpressionEvaluator('2.43*4.22+7.0987').evaluate(parameters.getValuesMap())).toBe(
126
+ 17.3533,
127
+ );
128
+ });
@@ -0,0 +1,33 @@
1
+ import { Expression } from '../../../../src/engine/runtime/expression/Expression';
2
+
3
+ test('Expression Test', () => {
4
+ expect(new Expression('2+3').toString()).toBe('(2+3)');
5
+ expect(new Expression('2.234 + 3 * 1.22243').toString()).toBe('((2.234)+(3*(1.22243)))');
6
+ expect(new Expression('10*11+12*13*14/7').toString()).toBe('((10*11)+(12*(13*(14/7))))');
7
+ expect(new Expression('34 << 2 = 8 ').toString()).toBe('((34<<2)=8)');
8
+
9
+ let ex: Expression = new Expression(
10
+ 'Context.a[Steps.loop.iteration.index - 1]+ Context.a[Steps.loop.iteration.index - 2]',
11
+ );
12
+
13
+ expect(ex.toString()).toBe(
14
+ '((Context.(a[((Steps.(loop.(iteration.index)))-1)))+(Context.(a[((Steps.(loop.(iteration.index)))-2))))',
15
+ );
16
+
17
+ ex = new Expression('Steps.step1.output.obj.array[Steps.step1.output.obj.num +1]+2');
18
+ expect(ex.toString()).toBe(
19
+ '((Steps.(step1.(output.(obj.(array[((Steps.(step1.(output.(obj.num))))+1))))))+2)',
20
+ );
21
+
22
+ let arrays: Expression = new Expression(
23
+ 'Context.a[Steps.loop.iteration.index][Steps.loop.iteration.index + 1]',
24
+ );
25
+ let deepObject: Expression = new Expression('Context.a.b.c');
26
+ let deepObjectWithArray: Expression = new Expression('Context.a.b[2].c');
27
+
28
+ expect(arrays.toString()).toBe(
29
+ '(Context.(a[((Steps.(loop.(iteration.index)))[((Steps.(loop.(iteration.index)))+1))))',
30
+ );
31
+ expect(deepObject.toString()).toBe('(Context.(a.(b.c)))');
32
+ expect(deepObjectWithArray.toString()).toBe('(Context.(a.(b[(2.c))))');
33
+ });
@@ -0,0 +1,44 @@
1
+ import { OutputMapTokenValueExtractor } from '../../../../../src/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractor';
2
+
3
+ test('OutputMapTokenValueExtractor Test', () => {
4
+ let phone: any = {
5
+ phone1: '1234',
6
+ phone2: '5678',
7
+ phone3: '5678',
8
+ };
9
+
10
+ let address: any = {
11
+ line1: 'Flat 202, PVR Estates',
12
+ line2: 'Nagvara',
13
+ city: 'Benguluru',
14
+ pin: '560048',
15
+ phone: phone,
16
+ };
17
+
18
+ let obj: any = {
19
+ studentName: 'Kumar',
20
+ math: 20,
21
+ isStudent: true,
22
+ address: address,
23
+ };
24
+
25
+ let output: Map<string, Map<string, Map<string, any>>> = new Map([
26
+ [
27
+ 'step1',
28
+ new Map([
29
+ [
30
+ 'output',
31
+ new Map([
32
+ ['zero', 0],
33
+ ['name', 'Kiran'],
34
+ ['obj', obj],
35
+ ]),
36
+ ],
37
+ ]),
38
+ ],
39
+ ]);
40
+
41
+ var omtv = new OutputMapTokenValueExtractor(output);
42
+ expect(omtv.getValue('Steps.step1.output.zero')).toBe(0);
43
+ expect(omtv.getValue('Steps.step1.output.obj.address.phone.phone2')).toBe('5678');
44
+ });
@@ -0,0 +1,72 @@
1
+ import { TokenValueExtractor } from '../../../../../src/engine/runtime/expression/tokenextractor/TokenValueExtractor';
2
+
3
+ class TestExtractor extends TokenValueExtractor {
4
+ protected getValueInternal(token: string): any {
5
+ return undefined;
6
+ }
7
+
8
+ public getPrefix(): string {
9
+ return 'Testing';
10
+ }
11
+
12
+ public retrieveElementFrom(
13
+ token: string,
14
+ parts: string[],
15
+ partNumber: number,
16
+ jsonElement: any,
17
+ ): any {
18
+ return super.retrieveElementFrom(token, parts, partNumber, jsonElement);
19
+ }
20
+ }
21
+
22
+ let extractor: TestExtractor;
23
+
24
+ beforeEach(() => {
25
+ extractor = new TestExtractor();
26
+ });
27
+
28
+ test('TokenValueExtractor Test', () => {
29
+ let darr0: number[] = [2, 4, 6];
30
+ let darr1: number[] = [3, 6, 9];
31
+ let darr2: number[] = [4, 8, 12, 16];
32
+
33
+ let darr: number[][] = [darr0, darr1, darr2];
34
+
35
+ let arr: number[] = [0, 2, 4, 6];
36
+ let b: any = {
37
+ c: 'K',
38
+ arr: arr,
39
+ darr: darr,
40
+ };
41
+
42
+ let a: any = { b: b };
43
+
44
+ let obj: any = { a: a, array: arr };
45
+
46
+ let token: string = '[2]';
47
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 0, arr)).toBe(4);
48
+
49
+ token = '[1][1]';
50
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 0, darr)).toBe(6);
51
+
52
+ token = '[2].length';
53
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 0, darr)).toBe(4);
54
+
55
+ token = 'a.b.c';
56
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 0, obj)).toBe('K');
57
+
58
+ token = 'a.b';
59
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 0, obj)).toBe(b);
60
+
61
+ token = 'a.b.c';
62
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 1, a)).toBe('K');
63
+
64
+ token = 'a.b.arr[2]';
65
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 1, a)).toBe(4);
66
+
67
+ token = 'a.b.darr[2][3]';
68
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 1, a)).toBe(16);
69
+
70
+ token = 'a.b.darr[2].length';
71
+ expect(extractor.retrieveElementFrom(token, token.split(new RegExp('\\.')), 1, a)).toBe(4);
72
+ });
@@ -0,0 +1,29 @@
1
+ import { LinkedList } from '../../../src/engine/util/LinkedList';
2
+
3
+ test('LinkedList Test', () => {
4
+ let x: LinkedList<number> = new LinkedList();
5
+ x.push(10);
6
+ x.push(20);
7
+ expect(x.isEmpty()).toBe(false);
8
+ expect(x.size()).toBe(2);
9
+ expect(x.pop()).toBe(20);
10
+ expect(x.isEmpty()).toBe(false);
11
+ expect(x.pop()).toBe(10);
12
+ expect(x.isEmpty()).toBe(true);
13
+
14
+ x = new LinkedList();
15
+ x.push(230);
16
+ x.push(231);
17
+ x.push(233);
18
+
19
+ expect(x.toArray()).toStrictEqual([233, 231, 230]);
20
+
21
+ x = new LinkedList([5, 6, 7]);
22
+ expect(x.toArray()).toStrictEqual([5, 6, 7]);
23
+
24
+ x = new LinkedList();
25
+ x.addAll([1, 2, 3]);
26
+ expect(x.toArray()).toStrictEqual([1, 2, 3]);
27
+ x.add(4);
28
+ expect(x.toArray()).toStrictEqual([1, 2, 3, 4]);
29
+ });
@@ -0,0 +1,17 @@
1
+ import { StringFormatter } from '../../../../src/engine/util/string/StringFormatter';
2
+
3
+ test('StringFormatter Test', () => {
4
+ expect(StringFormatter.format('Hello $', 'Kiran')).toBe('Hello Kiran');
5
+ expect(StringFormatter.format('\\$Hello $', 'Kiran')).toBe('$Hello Kiran');
6
+ expect(StringFormatter.format('Hi Hello How are you $?')).toBe('Hi Hello How are you $?');
7
+ expect(StringFormatter.format('Hi Hello How are you $$$$', '1', '2', '3')).toBe(
8
+ 'Hi Hello How are you 123$',
9
+ );
10
+ expect(StringFormatter.format('Hi Hello How are you \\$$$$', '1', '2', '3')).toBe(
11
+ 'Hi Hello How are you $123',
12
+ );
13
+ expect(StringFormatter.format('Hi Hello How are you $$$\\$', '1', '2')).toBe(
14
+ 'Hi Hello How are you 12$$',
15
+ );
16
+ expect(StringFormatter.format('Extra closing $ found', '}')).toBe('Extra closing } found');
17
+ });
@@ -0,0 +1,33 @@
1
+ import { HybridRepository } from '../src/index';
2
+
3
+ class TestRepository {
4
+ static TEST_INDEX: Map<string, string> = new Map<string, string>([
5
+ ['one', 'one'],
6
+ ['one1', 'one1'],
7
+ ]);
8
+
9
+ find(namespace: string, name: string): string | undefined {
10
+ return TestRepository.TEST_INDEX.get(name);
11
+ }
12
+ }
13
+
14
+ class TestRepository2 {
15
+ static TEST_INDEX: Map<string, string> = new Map<string, string>([
16
+ ['two', 'two'],
17
+ ['two1', 'two1'],
18
+ ]);
19
+
20
+ find(namespace: string, name: string): string | undefined {
21
+ return TestRepository2.TEST_INDEX.get(name);
22
+ }
23
+ }
24
+
25
+ test('Hybrid Repository Test', () => {
26
+ let hybrid: HybridRepository<string> = new HybridRepository<string>(
27
+ new TestRepository(),
28
+ new TestRepository2(),
29
+ );
30
+
31
+ expect(hybrid.find('', 'one')).toBe('one');
32
+ expect(hybrid.find('', 'two1')).toBe('two1');
33
+ });
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ function e(e,t){return Object.keys(t).forEach((function(r){"default"===r||"__esModule"===r||e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e}function t(e,t,r,s){Object.defineProperty(e,t,{get:r,set:s,enumerable:!0,configurable:!0})}var r={};t(r,"Tuple2",(()=>s)),t(r,"Tuple3",(()=>n)),t(r,"Tuple4",(()=>i));class s{constructor(e,t){this.f=e,this.s=t}getT1(){return this.f}getT2(){return this.s}}class n extends s{constructor(e,t,r){super(e,t),this.t=r}getT3(){return this.t}}class i extends n{constructor(e,t,r,s){super(e,t,r),this.fr=s}getT4(){return this.fr}}var a={};t(a,"HybridRepository",(()=>o));class o{constructor(...e){this.repos=e}find(e,t){for(let r of this.repos){let s=r.find(e,t);if(s)return s}}}var h={};t(h,"Schema",(()=>S));var u={};t(u,"Namespaces",(()=>l));class l{static SYSTEM="System";static SYSTEM_CTX="System.Context";static SYSTEM_LOOP="System.Loop";static SYSTEM_ARRAY="System.Array";static MATH="System.Math";static STRING="System.String";constructor(){}}function p(e){return null==e}class c{setSingleSchema(e){return this.singleSchema=e,this}setTupleSchema(e){return this.tupleSchema=e,this}getSingleSchema(){return this.singleSchema}getTupleSchema(){return this.tupleSchema}isSingleType(){return!p(this.singleSchema)}static of(...e){return 1==e.length?(new c).setSingleSchema(e[0]):(new c).setTupleSchema(e)}static from(e){if(!e)return;Array.isArray(e)&&c.of(...S.fromListOfSchemas(e));let t=S.from(e);return t?c.of(t):void 0}}class m{getBooleanValue(){return this.booleanValue}getSchemaValue(){return this.schemaValue}setBooleanValue(e){return this.booleanValue=e,this}setSchemaValue(e){return this.schemaValue=e,this}static from(e){if(!e)return;const t=new m;return t.booleanValue=e.booleanValue,t.schemaValue=e.schemaValue,t}}var g={};let f;var E;t(g,"SchemaType",(()=>f)),(E=f||(f={})).INTEGER="Integer",E.LONG="Long",E.FLOAT="Float",E.DOUBLE="Double",E.STRING="String",E.OBJECT="Object",E.ARRAY="Array",E.BOOLEAN="Boolean",E.NULL="Null";class T{}class A extends T{constructor(e){super(),this.type=e}getType(){return this.type}setType(e){return this.type=e,this}getAllowedSchemaTypes(){return this.type}contains(e){return this.type?.has(e)}}class d extends T{constructor(e){super(),this.type=e}getType(){return this.type}getAllowedSchemaTypes(){return new Set([this.type])}contains(e){return this.type==e}}class O{static of(...e){return 1==e.length?new d(e[0]):new A(new Set(e))}static from(e){return"string"==typeof e?O.of(e):Array.isArray(e)?O.of(...Array.of(e).map((e=>e)).map((e=>e))):void 0}}class S{static NULL=(new S).setNamespace(l.SYSTEM).setName("Null").setType(O.of(f.NULL)).setConstant(void 0);static TYPE_SCHEMA=(new S).setType(O.of(f.STRING)).setEnums(["INTEGER","LONG","FLOAT","DOUBLE","STRING","OBJECT","ARRAY","BOOLEAN","NULL"]);static SCHEMA=(new S).setNamespace(l.SYSTEM).setName("Schema").setType(O.of(f.OBJECT)).setProperties(new Map([["namespace",S.of("namespace",f.STRING).setDefaultValue("_")],["name",S.ofString("name")],["version",S.of("version",f.INTEGER).setDefaultValue(1)],["ref",S.ofString("ref")],["type",(new S).setAnyOf([S.TYPE_SCHEMA,S.ofArray("type",S.TYPE_SCHEMA)])],["anyOf",S.ofArray("anyOf",S.ofRef("#/"))],["allOf",S.ofArray("allOf",S.ofRef("#/"))],["oneOf",S.ofArray("oneOf",S.ofRef("#/"))],["not",S.ofRef("#/")],["title",S.ofString("title")],["description",S.ofString("description")],["id",S.ofString("id")],["examples",S.ofAny("examples")],["defaultValue",S.ofAny("defaultValue")],["comment",S.ofString("comment")],["enums",S.ofArray("enums",S.ofString("enums"))],["constant",S.ofAny("constant")],["pattern",S.ofString("pattern")],["format",S.of("format",f.STRING).setEnums(["DATETIME","TIME","DATE","EMAIL","REGEX"])],["minLength",S.ofInteger("minLength")],["maxLength",S.ofInteger("maxLength")],["multipleOf",S.ofLong("multipleOf")],["minimum",S.ofNumber("minimum")],["maximum",S.ofNumber("maximum")],["exclusiveMinimum",S.ofNumber("exclusiveMinimum")],["exclusiveMaximum",S.ofNumber("exclusiveMaximum")],["properties",S.of("properties",f.OBJECT).setAdditionalProperties((new m).setSchemaValue(S.ofRef("#/")))],["additionalProperties",(new S).setName("additionalProperty").setNamespace(l.SYSTEM).setAnyOf([S.ofBoolean("additionalProperty"),S.ofObject("additionalProperty").setRef("#/")]).setDefaultValue(!0)],["required",S.ofArray("required",S.ofString("required")).setDefaultValue([])],["propertyNames",S.ofRef("#/")],["minProperties",S.ofInteger("minProperties")],["maxProperties",S.ofInteger("maxProperties")],["patternProperties",S.of("patternProperties",f.OBJECT).setAdditionalProperties((new m).setSchemaValue(S.ofRef("#/")))],["items",(new S).setName("items").setAnyOf([S.ofRef("#/").setName("item"),S.ofArray("tuple",S.ofRef("#/"))])],["contains",S.ofRef("#/")],["minItems",S.ofInteger("minItems")],["maxItems",S.ofInteger("maxItems")],["uniqueItems",S.ofBoolean("uniqueItems")],["$defs",S.of("$defs",f.OBJECT).setAdditionalProperties((new m).setSchemaValue(S.ofRef("#/")))],["permission",S.ofString("permission")]])).setRequired([]);static ofString(e){return(new S).setType(O.of(f.STRING)).setName(e)}static ofInteger(e){return(new S).setType(O.of(f.INTEGER)).setName(e)}static ofFloat(e){return(new S).setType(O.of(f.FLOAT)).setName(e)}static ofLong(e){return(new S).setType(O.of(f.LONG)).setName(e)}static ofDouble(e){return(new S).setType(O.of(f.DOUBLE)).setName(e)}static ofAny(e){return(new S).setType(O.of(f.INTEGER,f.LONG,f.FLOAT,f.DOUBLE,f.STRING,f.BOOLEAN,f.ARRAY,f.NULL,f.OBJECT)).setName(e)}static ofAnyNotNull(e){return(new S).setType(O.of(f.INTEGER,f.LONG,f.FLOAT,f.DOUBLE,f.STRING,f.BOOLEAN,f.ARRAY,f.OBJECT)).setName(e)}static ofNumber(e){return(new S).setType(O.of(f.INTEGER,f.LONG,f.FLOAT,f.DOUBLE)).setName(e)}static ofBoolean(e){return(new S).setType(O.of(f.BOOLEAN)).setName(e)}static of(e,...t){return(new S).setType(O.of(...t)).setName(e)}static ofObject(e){return(new S).setType(O.of(f.OBJECT)).setName(e)}static ofRef(e){return(new S).setRef(e)}static ofArray(e,...t){return(new S).setType(O.of(f.ARRAY)).setName(e).setItems(c.of(...t))}static fromListOfSchemas(e){if(p(e)&&!Array.isArray(e))return[];let t=[];for(let r of Array.from(e)){let e=S.from(r);e&&t.push(e)}return t}static fromMapOfSchemas(e){if(p(e))return;const t=new Map;return Object.entries(e).forEach((([e,r])=>{let s=S.from(r);s&&t.set(e,s)})),t}static from(e,t=!1){if(p(e))return;let r=new S;return r.namespace=e.namespace,r.name=e.name,r.version=e.version,r.ref=e.ref,r.type=t?new d(f.STRING):O.from(r.type),r.anyOf=S.fromListOfSchemas(e.anyOf),r.allOf=S.fromListOfSchemas(e.allOf),r.oneOf=S.fromListOfSchemas(e.oneOf),r.not=S.from(e.not),r.description=e.description,r.examples=e.examples?[...e.examples]:void 0,r.defaultValue=e.defaultValue,r.comment=e.comment,r.enums=e.enums?[...e.enums]:void 0,r.constant=e.constant,r.pattern=e.pattern,r.format=e.format,r.minLength=e.minLength,r.maxLength=e.maxLength,r.multipleOf=e.multipleOf,r.minimum=e.minimum,r.maximum=e.maximum,r.exclusiveMinimum=e.exclusiveMinimum,r.exclusiveMaximum=e.exclusiveMaximum,r.properties=S.fromMapOfSchemas(e.properties),r.additionalProperties=m.from(e.additionalProperties),r.required=e.required,r.propertyNames=S.from(e.propertyNames,!0),r.minProperties=e.minProperties,r.maxProperties=e.maxProperties,r.patternProperties=S.fromMapOfSchemas(e.patternProperties),r.items=c.from(e.items),r.contains=S.from(e.contains),r.minItems=e.minItems,r.maxItems=e.maxItems,r.uniqueItems=e.uniqueItems,r.$defs=S.fromMapOfSchemas(e.$defs),r.permission=e.permission,r}namespace="_";version=1;getTitle(){return this.getFullName()}getFullName(){return this.namespace&&"_"!=this.namespace?this.namespace+"."+this.name:this.name}get$defs(){return this.$defs}set$defs(e){return this.$defs=e,this}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getVersion(){return this.version}setVersion(e){return this.version=e,this}getRef(){return this.ref}setRef(e){return this.ref=e,this}getType(){return this.type}setType(e){return this.type=e,this}getAnyOf(){return this.anyOf}setAnyOf(e){return this.anyOf=e,this}getAllOf(){return this.allOf}setAllOf(e){return this.allOf=e,this}getOneOf(){return this.oneOf}setOneOf(e){return this.oneOf=e,this}getNot(){return this.not}setNot(e){return this.not=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getExamples(){return this.examples}setExamples(e){return this.examples=e,this}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}getComment(){return this.comment}setComment(e){return this.comment=e,this}getEnums(){return this.enums}setEnums(e){return this.enums=e,this}getConstant(){return this.constant}setConstant(e){return this.constant=e,this}getPattern(){return this.pattern}setPattern(e){return this.pattern=e,this}getFormat(){return this.format}setFormat(e){return this.format=e,this}getMinLength(){return this.minLength}setMinLength(e){return this.minLength=e,this}getMaxLength(){return this.maxLength}setMaxLength(e){return this.maxLength=e,this}getMultipleOf(){return this.multipleOf}setMultipleOf(e){return this.multipleOf=e,this}getMinimum(){return this.minimum}setMinimum(e){return this.minimum=e,this}getMaximum(){return this.maximum}setMaximum(e){return this.maximum=e,this}getExclusiveMinimum(){return this.exclusiveMinimum}setExclusiveMinimum(e){return this.exclusiveMinimum=e,this}getExclusiveMaximum(){return this.exclusiveMaximum}setExclusiveMaximum(e){return this.exclusiveMaximum=e,this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}getAdditionalProperties(){return this.additionalProperties}setAdditionalProperties(e){return this.additionalProperties=e,this}getRequired(){return this.required}setRequired(e){return this.required=e,this}getPropertyNames(){return this.propertyNames}setPropertyNames(e){return this.propertyNames=e,this.propertyNames.type=new d(f.STRING),this}getMinProperties(){return this.minProperties}setMinProperties(e){return this.minProperties=e,this}getMaxProperties(){return this.maxProperties}setMaxProperties(e){return this.maxProperties=e,this}getPatternProperties(){return this.patternProperties}setPatternProperties(e){return this.patternProperties=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}getContains(){return this.contains}setContains(e){return this.contains=e,this}getMinItems(){return this.minItems}setMinItems(e){return this.minItems=e,this}getMaxItems(){return this.maxItems}setMaxItems(e){return this.maxItems=e,this}getUniqueItems(){return this.uniqueItems}setUniqueItems(e){return this.uniqueItems=e,this}getPermission(){return this.permission}setPermission(e){return this.permission=e,this}}var N={};t(N,"SchemaValidator",(()=>D));var I={};t(I,"KIRuntimeException",(()=>R));class R extends Error{constructor(e,t){super(e),this.cause=t}getCause(){return this.cause}}class w{static format(e,...t){if(!t||0==t.length)return e;let r="",s=0,n="",i=n,a=e.length;for(let o=0;o<a;o++)n=e.charAt(o),"$"==n&&"\\"==i?r=r.substring(0,o-1)+n:"$"==n&&s<t.length?r+=t[s++]:r+=n,i=n;return r.toString()}constructor(){}}class y{constructor(){}static nthIndex(e,t,r=0,s){if(!e)throw new R("String cannot be null");if(r<0||r>=e.length)throw new R(w.format("Cannot search from index : $",r));if(s<=0||s>e.length)throw new R(w.format("Cannot search for occurance : $",s));for(;r<e.length;){if(e.charAt(r)==t&&0==--s)return r;++r}return-1}static splitAtFirstOccurance(e,t){if(!e)return[void 0,void 0];let r=e.indexOf(t);return-1==r?[e,void 0]:[e.substring(0,r),e.substring(r+1)]}static isNullOrBlank(e){return!e||""==e.trim()}}class x extends Error{constructor(e,t,r){super(e.trim()?e+"-"+t:t),this.schemaPath=e,this.cause=r}getSchemaPath(){return this.schemaPath}getCause(){return this.cause}}class _ extends Error{constructor(e,t,r=[],s){super(t+(r?r.map((e=>e.message)).reduce(((e,t)=>e+"\n"+t),""):"")),this.schemaPath=e,this.cause=s}getSchemaPath(){return this.schemaPath}getCause(){return this.cause}}class v{static UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH="Unable to retrive schema from referenced path";static CYCLIC_REFERENCE_LIMIT_COUNTER=20;static getDefaultValue(e,t){if(e)return e.getConstant()?e.getConstant():e.getDefaultValue()?e.getDefaultValue():v.getDefaultValue(v.getSchemaFromRef(e,t,e.getRef()),t)}static getSchemaFromRef(e,t,r,s=0){if(++s==v.CYCLIC_REFERENCE_LIMIT_COUNTER)throw new _(r??"","Schema has a cyclic reference");if(!e||!r||y.isNullOrBlank(r))return;if(!r.startsWith("#")){var n=v.resolveExternalSchema(e,t,r);n&&(e=n.getT1(),r=n.getT2())}let i=r.split("/");return e=v.resolveInternalSchema(e,t,r,s,i,1)}static resolveInternalSchema(e,t,r,s,n,i){let a=e;for(;i<n.length;){if("$defs"===n[i]){if(++i>=n.length||!a.get$defs())throw new x(r,v.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);a=a.get$defs()?.get(n[i])}else{if(a&&(!a.getType()?.contains(f.OBJECT)||!a.getProperties()))throw new x(r,"Cannot retrievie schema from non Object type schemas");a=a.getProperties()?.get(n[i])}if(i++,!a)throw new x(r,v.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);if(!y.isNullOrBlank(a.getRef())&&(a=v.getSchemaFromRef(a,t,a.getRef(),s),!a))throw new x(r,v.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH)}return a}static resolveExternalSchema(e,t,r){if(!t)return;let n=y.splitAtFirstOccurance(e?.getRef()??"","/");if(!n[0])return;let i=y.splitAtFirstOccurance(n[0],".");if(!i[0]||!i[1])return;let a=t.find(i[0],i[1]);if(a){if(!n[1]||""===n[1])return new s(a,r);if(r="#/"+n[1],!a)throw new x(r,v.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);return new s(a,r)}}constructor(){}}class P{static validate(e,t,r,s){let n=[];return t.getOneOf()&&!t.getOneOf()?P.oneOf(e,t,r,s,n):t.getAllOf()&&!t.getAllOf()?P.allOf(e,t,r,s,n):t.getAnyOf()&&!t.getAnyOf()&&P.anyOf(e,t,r,s,n),s}static anyOf(e,t,r,s,n){let i=!1;for(let a of t.getAnyOf()??[])try{P.validate(e,a,r,s),i=!0;break}catch(e){i=!1,n.push(e)}if(!i)throw new _(D.path(e),"The value don't satisfy any of the schemas.",n)}static allOf(e,t,r,s,n){let i=0;for(let a of t.getAllOf()??[])try{P.validate(e,a,r,s),i++}catch(e){n.push(e)}if(i!==t.getAllOf()?.length)throw new _(D.path(e),"The value doesn't satisfy some of the schemas.",n)}static oneOf(e,t,r,s,n){let i=0;for(let a of t.getOneOf()??[])try{P.validate(e,a,r,s),i++}catch(e){n.push(e)}if(1!=i)throw new _(D.path(e),0==i?"The value does not satisfy any schema":"The value satisfy more than one schema",n)}constructor(){}}class M{static validate(e,t,r,s){if(p(s))throw new _(D.path(e),"Expected an array but found null");if(!Array.isArray(s))throw new _(D.path(e),s.toString()+" is not an Array");let n=s;return M.checkMinMaxItems(e,t,n),M.checkItems(e,t,r,n),M.checkUniqueItems(e,t,n),M.checkContains(e,t,r,n),s}static checkContains(e,t,r,s){if(!t.getContains())return;let n=!1;for(let i=0;i<s.length;i++){let a=e?[...e]:[];try{D.validate(a,t.getContains(),r,s[i]),n=!0;break}catch(e){n=!1}}if(!n)throw new _(D.path(e),"None of the items are of type contains schema")}static checkUniqueItems(e,t,r){if(t.getUniqueItems()&&t.getUniqueItems()){if(new Set(r).size!==r.length)throw new _(D.path(e),"Items on the array are not unique")}}static checkMinMaxItems(e,t,r){if(t.getMinItems()&&t.getMinItems()>r.length)throw new _(D.path(e),"Array should have minimum of "+t.getMinItems()+" elements");if(t.getMaxItems()&&t.getMaxItems()<r.length)throw new _(D.path(e),"Array can have maximum of "+t.getMaxItems()+" elements")}static checkItems(e,t,r,s){if(!t.getItems())return;let n=t.getItems();if(n.getSingleSchema())for(let t=0;t<s.length;t++){let i=e?[...e]:[],a=D.validate(i,n.getSingleSchema(),r,s[t]);s[t]=a}if(n.getTupleSchema()){if(n.getTupleSchema().length!==s.length)throw new _(D.path(e),"Expected an array with only "+n.getTupleSchema().length+" but found "+s.length);for(let t=0;t<s.length;t++){let i=e?[...e]:[],a=D.validate(i,n.getTupleSchema()[t],r,s[t]);s[t]=a}}}constructor(){}}class L{static validate(e,t,r,s){if(p(s))throw new _(D.path(t),"Expected a number but found null");if("number"!=typeof s)throw new _(D.path(t),s.toString()+" is not a "+e);let n=L.extractNumber(e,t,r,s);return L.checkRange(t,r,s,n),L.checkMultipleOf(t,r,s,n),s}static extractNumber(e,t,r,s){let n=s;try{e!=f.LONG&&e!=f.INTEGER||(n=Math.round(n))}catch(r){throw new _(D.path(t),s+" is not a number of type "+e,r)}if(p(n)||(e==f.LONG||e==f.INTEGER)&&n!=s)throw new _(D.path(t),s.toString()+" is not a number of type "+e);return n}static checkMultipleOf(e,t,r,s){if(t.getMultipleOf()){if(s%t.getMultipleOf()!=0)throw new _(D.path(e),r.toString()+" is not multiple of "+t.getMultipleOf())}}static checkRange(e,t,r,s){if(t.getMinimum()&&L.numberCompare(s,t.getMinimum())<0)throw new _(D.path(e),r.toString()+" should be greater than or equal to "+t.getMinimum());if(t.getMaximum()&&L.numberCompare(s,t.getMaximum())>0)throw new _(D.path(e),r.toString()+" should be less than or equal to "+t.getMaximum());if(t.getExclusiveMinimum()&&L.numberCompare(s,t.getExclusiveMinimum())<=0)throw new _(D.path(e),r.toString()+" should be greater than "+t.getExclusiveMinimum());if(t.getExclusiveMaximum()&&L.numberCompare(s,t.getExclusiveMaximum())>0)throw new _(D.path(e),r.toString()+" should be less than "+t.getExclusiveMaximum())}static numberCompare(e,t){return e-t}constructor(){}}class U{static validate(e,t,r,s){if(p(s))throw new _(D.path(e),"Expected an object but found null");if("object"!=typeof s||Array.isArray(s))throw new _(D.path(e),s.toString()+" is not an Object");let n=s,i=new Set(Object.keys(n));U.checkMinMaxProperties(e,t,i),t.getPropertyNames()&&U.checkPropertyNameSchema(e,t,r,i),t.getRequired()&&U.checkRequired(e,t,n),t.getProperties()&&U.checkProperties(e,t,r,n,i),t.getPatternProperties()&&U.checkPatternProperties(e,t,r,n,i),t.getAdditionalProperties()&&U.checkAddtionalProperties(e,t,r,n,i)}static checkPropertyNameSchema(e,t,r,s){for(let n of Array.from(s.values()))try{D.validate(e,t.getPropertyNames(),r,n)}catch(t){throw new _(D.path(e),"Property name '"+n+"' does not fit the property schema")}}static checkRequired(e,t,r){for(const s of t.getRequired()??[])if(p(r[s]))throw new _(D.path(e),s+" is mandatory")}static checkAddtionalProperties(e,t,r,s,n){let i=t.getAdditionalProperties();if(i.getSchemaValue())for(let t of Array.from(n.values())){let n=e?[...e]:[],a=D.validate(n,i.getSchemaValue(),r,s.get(t));s[t]=a}else if(!1===i.getBooleanValue()&&n.size)throw new _(D.path(e),n.toString()+" are additional properties which are not allowed.")}static checkPatternProperties(e,t,r,s,n){const i=new Map;for(const e of Array.from(t.getPatternProperties().keys()))i.set(e,new RegExp(e));for(const a of Array.from(n.values())){const o=e?[...e]:[];for(const e of Array.from(i.entries()))if(e[1].test(a)){const i=D.validate(o,t.getPatternProperties().get(e[0]),r,s[a]);s[a]=i,n.delete(a);break}}}static checkProperties(e,t,r,s,n){for(const i of Array.from(t.getProperties())){let t=s[i[0]];if(p(t))continue;let a=e?[...e]:[],o=D.validate(a,i[1],r,t);s[i[0]]=o,n.delete(i[0])}}static checkMinMaxProperties(e,t,r){if(t.getMinProperties()&&r.size<t.getMinProperties())throw new _(D.path(e),"Object should have minimum of "+t.getMinProperties()+" properties");if(t.getMaxProperties()&&r.size>t.getMaxProperties())throw new _(D.path(e),"Object can have maximum of "+t.getMaxProperties()+" properties")}constructor(){}}let C;var B;(B=C||(C={})).DATETIME="DATETIME",B.TIME="TIME",B.DATE="DATE",B.EMAIL="EMAIL",B.REGEX="REGEX";class b{static TIME=/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$/;static DATE=/^[0-9]{4,4}-([0][0-9]|[1][0-2])-(0[1-9]|[1-2][1-9]|3[01])$/;static DATETIME=/^[0-9]{4,4}-([0][0-9]|[1][0-2])-(0[1-9]|[1-2][1-9]|3[01])T([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$/;static validate(e,t,r){if(p(r))throw new _(D.path(e),"Expected a string but found null");if("string"!=typeof r)throw new _(D.path(e),r.toString()+" is not String");t.getFormat()==C.TIME?b.patternMatcher(e,t,r,b.TIME,"time pattern"):t.getFormat()==C.DATE?b.patternMatcher(e,t,r,b.DATE,"date pattern"):t.getFormat()==C.DATETIME?b.patternMatcher(e,t,r,b.DATETIME,"date time pattern"):t.getPattern()&&b.patternMatcher(e,t,r,new RegExp(t.getPattern()),"pattern "+t.getPattern());let s=r.length;if(t.getMinLength()&&s<t.getMinLength())throw new _(D.path(e),"Expected a minimum of "+t.getMinLength()+" characters");if(t.getMaxLength()&&s>t.getMinLength())throw new _(D.path(e),"Expected a maximum of "+t.getMaxLength()+" characters");return r}static patternMatcher(e,t,r,s,n){if(!s.test(r))throw new _(D.path(e),r.toString()+" is not matched with the "+n)}constructor(){}}class V{static validate(e,t,r,s,n){if(t==f.STRING)b.validate(e,r,n);else if(t==f.LONG||t==f.INTEGER||t==f.DOUBLE||t==f.FLOAT)L.validate(t,e,r,n);else if(t==f.BOOLEAN)(class{static validate(e,t,r){if(p(r))throw new _(D.path(e),"Expected a boolean but found null");if("boolean"!=typeof r)throw new _(D.path(e),r.toString()+" is not a boolean");return r}constructor(){}}).validate(e,r,n);else if(t==f.OBJECT)U.validate(e,r,s,n);else if(t==f.ARRAY)M.validate(e,r,s,n);else{if(t!=f.NULL)throw new _(D.path(e),t+" is not a valid type.");(class{static validate(e,t,r){if(r)throw new _(D.path(e),"Expected a null but found "+r);return r}constructor(){}}).validate(e,r,n)}return n}constructor(){}}class D{static path(e){return e?e.map((e=>e.getTitle()??"")).filter((e=>!!e)).reduce(((e,t,r)=>e+(0===r?"":".")+t),""):""}static validate(e,t,r,s){if(!t)return s;if(e||(e=new Array),e.push(t),p(s)&&!p(t.getDefaultValue()))return JSON.parse(JSON.stringify(t.getDefaultValue()));if(t.getConstant())return D.constantValidation(e,t,s);if(t.getEnums()&&!t.getEnums()?.length)return D.enumCheck(e,t,s);if(t.getType()&&D.typeValidation(e,t,r,s),!y.isNullOrBlank(t.getRef()))return D.validate(e,v.getSchemaFromRef(e[0],r,t.getRef()),r,s);if((t.getOneOf()||t.getAllOf()||t.getAnyOf())&&P.validate(e,t,r,s),t.getNot()){let n=!1;try{D.validate(e,t.getNot(),r,s),n=!0}catch(e){n=!1}if(n)throw new _(D.path(e),"Schema validated value in not condition.")}return s}static constantValidation(e,t,r){if(!t.getConstant().equals(r))throw new _(D.path(e),"Expecting a constant value : "+r);return r}static enumCheck(e,t,r){let s=!1;for(let e of t.getEnums()??[])if(e===r){s=!0;break}if(s)return r;throw new _(D.path(e),"Value is not one of "+t.getEnums())}static typeValidation(e,t,r,s){let n=!1,i=[];for(const a of Array.from(t.getType()?.getAllowedSchemaTypes()?.values()??[]))try{V.validate(e,a,t,r,s),n=!0;break}catch(e){n=!1,i.push(e)}if(!n)throw new _(D.path(e),"Value "+JSON.stringify(s)+" is not of valid type(s)",i)}constructor(){}}var k={};t(k,"KIRunConstants",(()=>G));class G{static NAMESPACE="namespace";static NAME="name";static ID="id";constructor(){}}var F={};t(F,"ExecutionException",(()=>$));class $ extends Error{constructor(e,t){super(e),this.cause=t}getCause(){return this.cause}}var Y={};t(Y,"AbstractFunction",(()=>H));class H{validateArguments(e){return Array.from(this.getSignature().getParameters().entries()).map((t=>{let r,n=t[0],i=t[1],a=e.get(t[0]);if(p(a))return new s(n,D.validate(void 0,i.getSchema(),void 0,void 0));if(!i?.isVariableArgument())return new s(n,D.validate(void 0,i.getSchema(),void 0,a));Array.isArray(a)?r=a:(r=[],r.push(a));for(const e of r)D.validate(void 0,i.getSchema(),void 0,e);return new s(n,a)})).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map)}execute(e){return e.setArguments(this.validateArguments(e.getArguments()??new Map)),this.internalExecute(e)}getProbableEventSignature(e){return this.getSignature().getEvents()}}var W={};t(W,"KIRuntime",(()=>ze));class j{constructor(e){this.expression=e}getExpression(){return this.expression}}class q{static OUTPUT="output";static ERROR="error";static ITERATION="iteration";static TRUE="true";static FALSE="false";static SCHEMA_NAME="Event";static SCHEMA=(new S).setNamespace(l.SYSTEM).setName(q.SCHEMA_NAME).setType(O.of(f.OBJECT)).setProperties(new Map([["name",S.ofString("name")],["parameters",S.ofObject("parameter").setAdditionalProperties((new m).setSchemaValue(S.SCHEMA))]]));constructor(e,t){this.name=e,this.parameters=t}getName(){return this.name}setName(e){return this.name=e,this}getParameters(){return this.parameters}setParameters(e){return this.parameters=e,this}static outputEventMapEntry(e){return q.eventMapEntry(q.OUTPUT,e)}static eventMapEntry(e,t){return[e,new q(e,t)]}}class X{constructor(e,t){this.name=e,this.result=t}getName(){return this.name}setName(e){return this.name=e,this}getResult(){return this.result}setResult(e){return this.result=e,this}static outputOf(e){return X.of(q.OUTPUT,e)}static of(e,t){return new X(e,t)}}class Q{index=0;constructor(e){if(p(e))throw new R("Function output is generating null");Array.isArray(e)&&e.length&&e[0]instanceof X?this.fo=e:(this.fo=[],this.generator=e)}next(){if(!this.generator)return this.index<this.fo.length?this.fo[this.index++]:void 0;const e=this.generator.next();return e&&this.fo.push(e),e}allResults(){return this.fo}}let J;var K;(K=J||(J={})).CONSTANT="CONSTANT",K.EXPRESSION="EXPRESSION";class z{static SCHEMA_NAME="Parameter";static SCHEMA=(new S).setNamespace(l.SYSTEM).setName(z.SCHEMA_NAME).setProperties(new Map([["schema",S.SCHEMA],["parameterName",S.ofString("parameterName")],["variableArgument",S.of("variableArgument",f.BOOLEAN).setDefaultValue(!1)]]));static EXPRESSION=(new S).setNamespace(l.SYSTEM).setName("ParameterExpression").setType(O.of(f.OBJECT)).setProperties(new Map([["isExpression",S.ofBoolean("isExpression").setDefaultValue(!0)],["value",S.ofAny("value")]]));variableArgument=!1;type=J.EXPRESSION;constructor(e,t){this.schema=t,this.parameterName=e}getSchema(){return this.schema}setSchema(e){return this.schema=e,this}getParameterName(){return this.parameterName}setParameterName(e){return this.parameterName=e,this}isVariableArgument(){return this.variableArgument}setVariableArgument(e){return this.variableArgument=e,this}getType(){return this.type}setType(e){return this.type=e,this}static ofEntry(e,t,r=!1,s=J.EXPRESSION){return[e,new z(e,t).setType(s).setVariableArgument(r)]}static of(e,t,r=!1,s=J.EXPRESSION){return new z(e,t).setType(s).setVariableArgument(r)}}let Z;var ee;(ee=Z||(Z={})).VALUE="VALUE",ee.EXPRESSION="EXPRESSION";class te{head=void 0;tail=void 0;length=0;constructor(e){if(e?.length){for(const t of e)if(this.head){const e=new re(t,this.tail);this.tail.next=e,this.tail=e}else this.tail=this.head=new re(t);this.length=e.length}}push(e){const t=new re(e,void 0,this.head);this.head?(this.head.previous=t,this.head=t):this.tail=this.head=t,this.length++}pop(){if(!this.head)throw Error("List is empty and cannot pop further.");const e=this.head.value;if(this.length--,this.head==this.tail)return this.head=this.tail=void 0,e;const t=this.head;return this.head=t.next,t.next=void 0,t.previous=void 0,this.head.previous=void 0,e}isEmpty(){return!this.length}size(){return this.length}get(e){if(e<0||e>=this.length)throw new Error(`${e} is out of bounds [0,${this.length}]`);let t=this.head;for(;e>0;)t=this.head.next,--e;return t.value}set(e,t){if(e<0||e>=this.length)throw new R(w.format("Index $ out of bound to set the value in linked list.",e));let r=this.head;for(;e>0;)r=this.head.next,--e;return r.value=t,this}toString(){let e=this.head,t="";for(;e;)t+=e.value,e=e.next,e&&(t+=", ");return`[${t}]`}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}peek(){if(!this.head)throw new Error("List is empty so cannot peak");return this.head.value}peekLast(){if(!this.tail)throw new Error("List is empty so cannot peak");return this.tail.value}getFirst(){if(!this.head)throw new Error("List is empty so cannot get first");return this.head.value}removeFirst(){return this.pop()}removeLast(){if(!this.tail)throw new Error("List is empty so cannot remove");--this.length;const e=this.tail.value;if(0==this.length)this.head=this.tail=void 0;else{const e=this.tail.previous;e.next=void 0,this.tail.previous=void 0,this.tail=e}return e}addAll(e){return e&&e.length?(e.forEach(this.add.bind(this)),this):this}add(e){return++this.length,this.tail||this.head?this.head===this.tail?(this.tail=new re(e,this.head),this.head.next=this.tail):(this.tail=new re(e,this.tail),this.tail.previous.next=this.tail):this.head=this.tail=new re(e),this}map(e,t){let r=new te,s=this.head,n=0;for(;s;)r.add(e(s.value,n)),s=s.next,++n;return r}forEach(e,t){let r=this.head,s=0;for(;r;)e(r.value,s),r=r.next,++s}}class re{constructor(e,t,r){this.value=e,this.next=r,this.previous=t}toString(){return""+this.value}}class se{constructor(e){this.str=e??""}append(e){return this.str+=e,this}toString(){return""+this.str}trim(){return this.str=this.str.trim(),this}setLength(e){return this.str=this.str.substring(0,e),this}length(){return this.str.length}charAt(e){return this.str.charAt(e)}deleteCharAt(e){return this.checkIndex(e),this.str=this.str.substring(0,e)+this.str.substring(e+1),this}insert(e,t){return this.str=this.str.substring(0,e)+t+this.str.substring(e),this}checkIndex(e){if(e>=this.str.length)throw new R(`Index ${e} is greater than or equal to ${this.str.length}`)}substring(e,t){return this.str.substring(e,t)}}class ne extends Error{constructor(e,t,r){super(w.format("$ : $",e,t)),this.cause=r}getCause(){return this.cause}}class ie{constructor(e){this.expression=e}getExpression(){return this.expression}toString(){return this.expression}}class ae{static MULTIPLICATION=new ae("*");static DIVISION=new ae("/");static INTEGER_DIVISION=new ae("//");static MOD=new ae("%");static ADDITION=new ae("+");static SUBTRACTION=new ae("-");static NOT=new ae("not");static AND=new ae("and");static OR=new ae("or");static LESS_THAN=new ae("<");static LESS_THAN_EQUAL=new ae("<=");static GREATER_THAN=new ae(">");static GREATER_THAN_EQUAL=new ae(">=");static EQUAL=new ae("=");static NOT_EQUAL=new ae("!=");static BITWISE_AND=new ae("&");static BITWISE_OR=new ae("|");static BITWISE_XOR=new ae("^");static BITWISE_COMPLEMENT=new ae("~");static BITWISE_LEFT_SHIFT=new ae("<<");static BITWISE_RIGHT_SHIFT=new ae(">>");static BITWISE_UNSIGNED_RIGHT_SHIFT=new ae(">>>");static UNARY_PLUS=new ae("UN: +","+");static UNARY_MINUS=new ae("UN: -","-");static UNARY_LOGICAL_NOT=new ae("UN: not","not");static UNARY_BITWISE_COMPLEMENT=new ae("UN: ~","~");static ARRAY_OPERATOR=new ae("[");static OBJECT_OPERATOR=new ae(".");static VALUE_OF=new Map([["MULTIPLICATION",ae.MULTIPLICATION],["DIVISION",ae.DIVISION],["INTEGER_DIVISON",ae.INTEGER_DIVISION],["MOD",ae.MOD],["ADDITION",ae.ADDITION],["SUBTRACTION",ae.SUBTRACTION],["NOT",ae.NOT],["AND",ae.AND],["OR",ae.OR],["LESS_THAN",ae.LESS_THAN],["LESS_THAN_EQUAL",ae.LESS_THAN_EQUAL],["GREATER_THAN",ae.GREATER_THAN],["GREATER_THAN_EQUAL",ae.GREATER_THAN_EQUAL],["EQUAL",ae.EQUAL],["NOT_EQUAL",ae.NOT_EQUAL],["BITWISE_AND",ae.BITWISE_AND],["BITWISE_OR",ae.BITWISE_OR],["BITWISE_XOR",ae.BITWISE_XOR],["BITWISE_COMPLEMENT",ae.BITWISE_COMPLEMENT],["BITWISE_LEFT_SHIFT",ae.BITWISE_LEFT_SHIFT],["BITWISE_RIGHT_SHIFT",ae.BITWISE_RIGHT_SHIFT],["BITWISE_UNSIGNED_RIGHT_SHIFT",ae.BITWISE_UNSIGNED_RIGHT_SHIFT],["UNARY_PLUS",ae.UNARY_PLUS],["UNARY_MINUS",ae.UNARY_MINUS],["UNARY_LOGICAL_NOT",ae.UNARY_LOGICAL_NOT],["UNARY_BITWISE_COMPLEMENT",ae.UNARY_BITWISE_COMPLEMENT],["ARRAY_OPERATOR",ae.ARRAY_OPERATOR],["OBJECT_OPERATOR",ae.OBJECT_OPERATOR]]);static UNARY_OPERATORS=new Set([ae.ADDITION,ae.SUBTRACTION,ae.NOT,ae.BITWISE_COMPLEMENT,ae.UNARY_PLUS,ae.UNARY_MINUS,ae.UNARY_LOGICAL_NOT,ae.UNARY_BITWISE_COMPLEMENT]);static ARITHMETIC_OPERATORS=new Set([ae.MULTIPLICATION,ae.DIVISION,ae.INTEGER_DIVISION,ae.MOD,ae.ADDITION,ae.SUBTRACTION]);static LOGICAL_OPERATORS=new Set([ae.NOT,ae.AND,ae.OR,ae.LESS_THAN,ae.LESS_THAN_EQUAL,ae.GREATER_THAN,ae.GREATER_THAN_EQUAL,ae.EQUAL,ae.NOT_EQUAL]);static BITWISE_OPERATORS=new Set([ae.BITWISE_AND,ae.BITWISE_COMPLEMENT,ae.BITWISE_LEFT_SHIFT,ae.BITWISE_OR,ae.BITWISE_RIGHT_SHIFT,ae.BITWISE_UNSIGNED_RIGHT_SHIFT,ae.BITWISE_XOR]);static OPERATOR_PRIORITY=new Map([[ae.UNARY_PLUS,1],[ae.UNARY_MINUS,1],[ae.UNARY_LOGICAL_NOT,1],[ae.UNARY_BITWISE_COMPLEMENT,1],[ae.ARRAY_OPERATOR,1],[ae.OBJECT_OPERATOR,1],[ae.MULTIPLICATION,2],[ae.DIVISION,2],[ae.INTEGER_DIVISION,2],[ae.MOD,2],[ae.ADDITION,3],[ae.SUBTRACTION,3],[ae.BITWISE_LEFT_SHIFT,4],[ae.BITWISE_RIGHT_SHIFT,4],[ae.BITWISE_UNSIGNED_RIGHT_SHIFT,4],[ae.LESS_THAN,5],[ae.LESS_THAN_EQUAL,5],[ae.GREATER_THAN,5],[ae.GREATER_THAN_EQUAL,5],[ae.EQUAL,6],[ae.NOT_EQUAL,6],[ae.BITWISE_AND,7],[ae.BITWISE_XOR,8],[ae.BITWISE_OR,9],[ae.AND,10],[ae.OR,11]]);static OPERATORS=new Set([...Array.from(ae.ARITHMETIC_OPERATORS),...Array.from(ae.LOGICAL_OPERATORS),...Array.from(ae.BITWISE_OPERATORS),ae.ARRAY_OPERATOR,ae.OBJECT_OPERATOR].map((e=>e.getOperator())));static OPERATION_VALUE_OF=new Map(Array.from(ae.VALUE_OF.entries()).map((([e,t])=>[t.getOperator(),t])));static UNARY_MAP=new Map([[ae.ADDITION,ae.UNARY_PLUS],[ae.SUBTRACTION,ae.UNARY_MINUS],[ae.NOT,ae.UNARY_LOGICAL_NOT],[ae.BITWISE_COMPLEMENT,ae.UNARY_BITWISE_COMPLEMENT],[ae.UNARY_PLUS,ae.UNARY_PLUS],[ae.UNARY_MINUS,ae.UNARY_MINUS],[ae.UNARY_LOGICAL_NOT,ae.UNARY_LOGICAL_NOT],[ae.UNARY_BITWISE_COMPLEMENT,ae.UNARY_BITWISE_COMPLEMENT]]);static BIGGEST_OPERATOR_SIZE=Array.from(ae.VALUE_OF.values()).map((e=>e.getOperator())).filter((e=>!e.startsWith("UN: "))).map((e=>e.length)).reduce(((e,t)=>e>t?e:t),0);constructor(e,t){this.operator=e,this.operatorName=t??e}getOperator(){return this.operator}getOperatorName(){return this.operatorName}valueOf(e){return ae.VALUE_OF.get(e)}toString(){return this.operator}}class oe extends ie{tokens=new te;ops=new te;constructor(e,t,r,s){super(e||""),t&&this.tokens.push(t),r&&this.tokens.push(r),s&&this.ops.push(s),this.evaluate()}getTokens(){return this.tokens}getOperations(){return this.ops}evaluate(){const e=this.expression.length;let t,r="",s=new se(""),n=0,i=!1;for(;n<e;){switch(r=this.expression[n],t=s.toString(),r){case" ":i=this.processTokenSepearator(s,t,i);break;case"(":n=this.processSubExpression(e,s,t,n,i),i=!1;break;case")":throw new ne(this.expression,"Extra closing parenthesis found");case"]":throw new ne(this.expression,"Extra closing square bracket found");default:let a=this.processOthers(r,e,s,t,n,i);n=a.getT1(),i=a.getT2(),i&&this.ops.peek()==ae.ARRAY_OPERATOR&&(a=this.process(e,s,n),n=a.getT1(),i=a.getT2())}++n}if(t=s.toString(),!y.isNullOrBlank(t)){if(ae.OPERATORS.has(t))throw new ne(this.expression,"Expression is ending with an operator");this.tokens.push(new ie(t))}}process(e,t,r){let n=1;for(++r;r<e&&0!=n;){let e=this.expression.charAt(r);"]"==e?--n:"["==e&&++n,0!=n&&(t.append(e),r++)}return this.tokens.push(new oe(t.toString())),t.setLength(0),new s(r,!1)}processOthers(e,t,r,n,i,a){let o=t-i;o=o<ae.BIGGEST_OPERATOR_SIZE?o:ae.BIGGEST_OPERATOR_SIZE;for(let e=o;e>0;e--){let t=this.expression.substring(i,i+e);if(ae.OPERATORS.has(t))return y.isNullOrBlank(n)||(this.tokens.push(new ie(n)),a=!1),this.checkUnaryOperator(this.tokens,this.ops,ae.OPERATION_VALUE_OF.get(t),a),a=!0,r.setLength(0),new s(i+e-1,a)}return r.append(e),new s(i,!1)}processSubExpression(e,t,r,s,n){if(ae.OPERATORS.has(r))this.checkUnaryOperator(this.tokens,this.ops,ae.OPERATION_VALUE_OF.get(r),n),t.setLength(0);else if(!y.isNullOrBlank(r))throw new ne(this.expression,w.format("Unkown token : $ found.",r));let i=1;const a=new se;let o=this.expression.charAt(s);for(s++;s<e&&i>0;)o=this.expression.charAt(s),"("==o?i++:")"==o&&i--,0!=i&&(a.append(o),s++);if(")"!=o)throw new ne(this.expression,"Missing a closed parenthesis");for(;a.length()>2&&"("==a.charAt(0)&&")"==a.charAt(a.length()-1);)a.deleteCharAt(0),a.setLength(a.length()-1);return this.tokens.push(new oe(a.toString().trim())),s}processTokenSepearator(e,t,r){return y.isNullOrBlank(t)||(ae.OPERATORS.has(t)?(this.checkUnaryOperator(this.tokens,this.ops,ae.OPERATION_VALUE_OF.get(t),r),r=!0):(this.tokens.push(new ie(t)),r=!1)),e.setLength(0),r}checkUnaryOperator(e,t,r,s){if(r)if(s||e.isEmpty()){if(!ae.UNARY_OPERATORS.has(r))throw new ne(this.expression,w.format("Extra operator $ found.",r));{const e=ae.UNARY_MAP.get(r);e&&t.push(e)}}else{for(;!t.isEmpty()&&this.hasPrecedence(r,t.peek());){let r=t.pop();if(ae.UNARY_OPERATORS.has(r)){let t=e.pop();e.push(new oe("",t,void 0,r))}else{let t=e.pop(),s=e.pop();e.push(new oe("",s,t,r))}}t.push(r)}}hasPrecedence(e,t){let r=ae.OPERATOR_PRIORITY.get(e),s=ae.OPERATOR_PRIORITY.get(t);if(!r||!s)throw new Error("Unknown operators provided");return s<r}toString(){if(this.ops.isEmpty())return 1==this.tokens.size()?this.tokens.get(0).toString():"Error: No tokens";let e=new se,t=0;const r=this.ops.toArray(),s=this.tokens.toArray();for(let n=0;n<r.length;n++)if(r[n].getOperator().startsWith("UN: "))e.append("(").append(r[n].getOperator().substring(4)).append(s[t]instanceof oe?s[t].toString():s[t]).append(")"),t++;else{if(0==t){const r=s[t++];e.insert(0,r.toString())}const i=s[t++];e.insert(0,r[n].getOperator()).insert(0,i.toString()).insert(0,"(").append(")")}return e.toString()}equals(e){return this.expression==e.expression}}class he extends ie{constructor(e,t){super(e),this.element=t}getTokenValue(){return this.element}getElement(){return this.element}toString(){return w.format("$: $",this.expression,this.element)}}class ue{nullCheck(e,t,r){if(p(e)||p(t))throw new $(w.format("$ cannot be applied to a null value",r.getOperatorName()))}}class le extends ue{apply(e,t){return this.nullCheck(e,t,ae.ADDITION),e+t}}class pe extends ue{apply(e,t){return this.nullCheck(e,t,ae.DIVISION),e/t}}class ce extends ue{apply(e,t){return this.nullCheck(e,t,ae.DIVISION),Math.floor(e/t)}}class me extends ue{apply(e,t){return this.nullCheck(e,t,ae.MOD),e%t}}class ge extends ue{apply(e,t){return this.nullCheck(e,t,ae.MULTIPLICATION),e*t}}class fe extends ue{apply(e,t){return this.nullCheck(e,t,ae.SUBTRACTION),e-t}}class Ee extends ue{apply(e,t){if(!e)throw new $("Cannot apply array operator on a null value");if(!t)throw new $("Cannot retrive null index value");if(!Array.isArray(e)&&"string"!=typeof e)throw new $(w.format("Cannot retrieve value from a primitive value $",e));if(t>=e.length)throw new $(w.format("Cannot retrieve index $ from the array of length $",t,e.length));return e[t]}}class Te extends ue{apply(e,t){return this.nullCheck(e,t,ae.BITWISE_AND),e&t}}class Ae extends ue{apply(e,t){return this.nullCheck(e,t,ae.BITWISE_LEFT_SHIFT),e<<t}}class de extends ue{apply(e,t){return this.nullCheck(e,t,ae.BITWISE_OR),e|t}}class Oe extends ue{apply(e,t){return this.nullCheck(e,t,ae.BITWISE_RIGHT_SHIFT),e>>t}}class Se extends ue{apply(e,t){return this.nullCheck(e,t,ae.BITWISE_UNSIGNED_RIGHT_SHIFT),e>>>t}}class Ne extends ue{apply(e,t){return this.nullCheck(e,t,ae.BITWISE_XOR),e^t}}class Ie{static findPrimitiveNullAsBoolean(e){if(!e)return new s(f.BOOLEAN,!1);let t=typeof e;if("object"===t)throw new $(w.format("$ is not a primitive type",e));let r=e;return"boolean"===t?new s(f.BOOLEAN,r):"string"===t?new s(f.STRING,r):Ie.findPrimitiveNumberType(r)}static findPrimitive(e){if(p(e))return new s(f.NULL,void 0);let t=typeof e;if("object"===t)throw new $(w.format("$ is not a primitive type",e));let r=e;return"boolean"===t?new s(f.BOOLEAN,r):"string"===t?new s(f.STRING,r):Ie.findPrimitiveNumberType(r)}static findPrimitiveNumberType(e){if(p(e)||Array.isArray(e)||"object"==typeof e)throw new $(w.format("Unable to convert $ to a number.",e));let t=e;try{let e=t;return Number.isInteger(e)?new s(f.LONG,e):new s(f.DOUBLE,e)}catch(e){throw new $(w.format("Unable to convert $ to a number.",t),e)}}static compare(e,t){if(e==t)return 0;if(p(e)||p(t))return p(e)?-1:1;if(Array.isArray(e)||Array.isArray(t)){if(Array.isArray(e)||Array.isArray(t)){if(e.length!=t.length)return e.length-t.length;for(let r=0;r<e.length;r++){let s=this.compare(e[r],t[r]);if(0!=s)return s}return 0}return Array.isArray(e)?-1:1}const r=typeof e,s=typeof t;return"object"!==r&&"object"!==s||"object"===r&&"object"===s&&Object.keys(e).forEach((r=>{let s=this.compare(e[r],t[r]);if(0!=s)return s})),this.comparePrimitive(e,t)}static comparePrimitive(e,t){return p(e)||p(t)?p(e)&&p(t)?0:p(e)?-1:1:e==t?0:"boolean"==typeof e||"boolean"==typeof t?e?-1:1:"string"==typeof e||"string"==typeof t?e+""<t+""?-1:1:"number"==typeof e||"number"==typeof t?e-t:0}static baseNumberType(e){return Number.isInteger(e)?f.LONG:f.DOUBLE}static toPrimitiveType(e){return e}constructor(){}}class Re extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);if(r.getT1()!=f.BOOLEAN)throw new $(w.format("Boolean value expected but found $",r.getT2()));if(s.getT1()!=f.BOOLEAN)throw new $(w.format("Boolean value expected but found $",s.getT2()));return r.getT2()&&s.getT2()}}class we extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);return r.getT2()==s.getT2()}}class ye extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);if(r.getT1()==f.BOOLEAN||s.getT1()==f.BOOLEAN)throw new $(w.format("Cannot compare >= with the values $ and $",r.getT2(),s.getT2()));return r.getT2()>=s.getT2()}}class xe extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);if(r.getT1()==f.BOOLEAN||s.getT1()==f.BOOLEAN)throw new $(w.format("Cannot compare > with the values $ and $",r.getT2(),s.getT2()));return r.getT2()>s.getT2()}}class _e extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);if(r.getT1()==f.BOOLEAN||s.getT1()==f.BOOLEAN)throw new $(w.format("Cannot compare <= with the values $ and $",r.getT2(),s.getT2()));return r.getT2()<=s.getT2()}}class ve extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);if(r.getT1()==f.BOOLEAN||s.getT1()==f.BOOLEAN)throw new $(w.format("Cannot compare < with the values $ and $",r.getT2(),s.getT2()));return r.getT2()<s.getT2()}}class Pe extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);return r.getT2()!=s.getT2()}}class Me extends ue{apply(e,t){const r=Ie.findPrimitiveNullAsBoolean(e),s=Ie.findPrimitiveNullAsBoolean(t);if(r.getT1()!=f.BOOLEAN)throw new $(w.format("Boolean value expected but found $",r.getT2()));if(s.getT1()!=f.BOOLEAN)throw new $(w.format("Boolean value expected but found $",s.getT2()));return r.getT2()||s.getT2()}}class Le extends ue{apply(e,t){if(!e)throw new $("Cannot apply array operator on a null value");if(!t)throw new $("Cannot retrive null property value");const r=typeof e;if(!Array.isArray(e)&&"string"!=r&&"object"!=r)throw new $(w.format("Cannot retrieve value from a primitive value $",e));return e[t]}}class Ue{nullCheck(e,t){if(p(e))throw new $(w.format("$ cannot be applied to a null value",t.getOperatorName()))}}class Ce extends Ue{apply(e){return this.nullCheck(e,ae.UNARY_MINUS),Ie.findPrimitiveNumberType(e),-e}}class Be extends Ue{apply(e){return this.nullCheck(e,ae.UNARY_PLUS),Ie.findPrimitiveNumberType(e),e}}class be extends Ue{apply(e){this.nullCheck(e,ae.UNARY_BITWISE_COMPLEMENT);let t=Ie.findPrimitiveNumberType(e);if(t.getT1()!=f.INTEGER&&t.getT1()!=f.LONG)throw new $(w.format("Unable to apply bitwise operator on $",e));return~e}}class Ve extends Ue{apply(e){if(this.nullCheck(e,ae.UNARY_LOGICAL_NOT),Ie.findPrimitiveNumberType(e).getT1()!=f.BOOLEAN)throw new $(w.format("Unable to apply bitwise operator on $",e));return!e}}class De{static REGEX_SQUARE_BRACKETS=/[\[\]]/;static REGEX_DOT=/\./;getValue(e){let t=this.getPrefix();if(!e.startsWith(t))throw new R(w.format("Token $ doesn't start with $",e,t));return this.getValueInternal(e)}retrieveElementFrom(e,t,r,s){if(p(s))return;if(t.length==r)return s;let n=t[r].split(De.REGEX_SQUARE_BRACKETS).map((e=>e.trim())).filter((e=>!y.isNullOrBlank(e))).reduce(((s,n,i)=>this.resolveForEachPartOfTokenWithBrackets(e,t,r,n,s,i)),s);return this.retrieveElementFrom(e,t,r+1,n)}resolveForEachPartOfTokenWithBrackets(e,t,r,s,n,i){if(!p(n)){if(0===i){if(Array.isArray(n)){if("length"===s)return n.length;try{let e=parseInt(s);if(isNaN(e))throw new Error(w.format("$ is not a number",e));if(e>=n.length)return;return n[e]}catch(t){throw new ne(e,w.format("$ couldn't be parsed into integer in $",s,e),t)}}return this.checkIfObject(e,t,r,n),n[s]}if(s?.startsWith('"')){if(!s.endsWith('"')||1==s.length||2==s.length)throw new ne(e,w.format("$ is missing a double quote or empty key found",e));return this.checkIfObject(e,t,r,n),n[s.substring(1,s.length-1)]}try{let t=parseInt(s);if(isNaN(t))throw new Error(w.format("$ is not a number",t));if(!Array.isArray(n))throw new ne(e,w.format("Expecting an array with index $ while processing the expression",t,e));if(t>=n.length)return;return n[t]}catch(t){throw new ne(e,w.format("$ couldn't be parsed into integer in $",s,e),t)}}}checkIfObject(e,t,r,s){if("object"!=typeof s||Array.isArray(s))throw new ne(e,w.format("Unable to retrive $ from $ in the path $",t[r],s.toString(),e))}}const ke=new Map([["true",!0],["false",!1],["null",void 0]]);class Ge extends De{static INSTANCE=new Ge;getValueInternal(e){if(!y.isNullOrBlank(e))return e=e.trim(),ke.has(e)?ke.get(e):e.startsWith('"')?this.processString(e):this.processNumbers(e)}processNumbers(e){try{let t;if(t=-1==e.indexOf(".")?parseInt(e):parseFloat(e),isNaN(t))throw new Error("Parse number error");return t}catch(t){throw new ne(e,w.format("Unable to parse the literal or expression $",e),t)}}processString(e){if(!e.endsWith('"'))throw new ne(e,w.format("String literal $ is not closed properly",e));return e.substring(1,e.length-1)}getPrefix(){return""}}class Fe{static UNARY_OPERATORS_MAP=new Map([[ae.UNARY_BITWISE_COMPLEMENT,new be],[ae.UNARY_LOGICAL_NOT,new Ve],[ae.UNARY_MINUS,new Ce],[ae.UNARY_PLUS,new Be]]);static BINARY_OPERATORS_MAP=new Map([[ae.ADDITION,new le],[ae.DIVISION,new pe],[ae.INTEGER_DIVISION,new ce],[ae.MOD,new me],[ae.MULTIPLICATION,new ge],[ae.SUBTRACTION,new fe],[ae.BITWISE_AND,new Te],[ae.BITWISE_LEFT_SHIFT,new Ae],[ae.BITWISE_OR,new de],[ae.BITWISE_RIGHT_SHIFT,new Oe],[ae.BITWISE_UNSIGNED_RIGHT_SHIFT,new Se],[ae.BITWISE_XOR,new Ne],[ae.AND,new Re],[ae.EQUAL,new we],[ae.GREATER_THAN,new xe],[ae.GREATER_THAN_EQUAL,new ye],[ae.LESS_THAN,new ve],[ae.LESS_THAN_EQUAL,new _e],[ae.OR,new Me],[ae.NOT_EQUAL,new Pe],[ae.ARRAY_OPERATOR,new Ee],[ae.OBJECT_OPERATOR,new Le]]);static UNARY_OPERATORS_MAP_KEY_SET=new Set(Fe.UNARY_OPERATORS_MAP.keys());constructor(e){e instanceof oe?(this.exp=e,this.expression=this.exp.getExpression()):this.expression=e}evaluate(e){return this.exp||(this.exp=new oe(this.expression)),this.evaluateExpression(this.exp,e)}getExpression(){return this.exp||(this.exp=new oe(this.expression)),this.exp}getExpressionString(){return this.expression}evaluateExpression(e,t){let r=e.getOperations(),s=e.getTokens();for(;!r.isEmpty();){let e=r.pop(),a=s.pop();if(Fe.UNARY_OPERATORS_MAP_KEY_SET.has(e))s.push(this.applyUnaryOperation(e,this.getValueFromToken(t,a)));else if(e==ae.OBJECT_OPERATOR||e==ae.ARRAY_OPERATOR)this.processObjectOrArrayOperator(t,r,s,e,a);else{const r=s.pop();var n=this.getValueFromToken(t,r),i=this.getValueFromToken(t,a);s.push(this.applyBinaryOperation(e,n,i))}}if(s.isEmpty())throw new $(w.format("Expression : $ evaluated to null",e));if(1!=s.size())throw new $(w.format("Expression : $ evaluated multiple values $",e,s));const a=s.get(0);if(a instanceof he)return a.getElement();if(!(a instanceof oe))return this.getValueFromToken(t,a);throw new $(w.format("Expression : $ evaluated to $",e,s.get(0)))}processObjectOrArrayOperator(e,t,r,s,n){const i=new te,a=new te;if(!s||!n)return;do{a.push(s),n instanceof oe?i.push(new he(n.toString(),this.evaluateExpression(n,e))):n&&i.push(n),n=r.isEmpty()?void 0:r.pop(),s=t.isEmpty()?void 0:t.pop()}while(s==ae.OBJECT_OPERATOR||s==ae.ARRAY_OPERATOR);n&&(n instanceof oe?i.push(new he(n.toString(),this.evaluateExpression(n,e))):i.push(n)),s&&t.push(s);let o=i.pop(),h=new se(o instanceof he?o.getTokenValue():o.toString());for(;!i.isEmpty();)o=i.pop(),s=a.pop(),h.append(s.getOperator()).append(o instanceof he?o.getTokenValue():o.toString()),s==ae.ARRAY_OPERATOR&&h.append("]");let u=h.toString(),l=u.substring(0,u.indexOf(".")+1);if(l.length>2&&e.has(l))r.push(new he(u,this.getValue(u,e)));else{let e;try{e=Ge.INSTANCE.getValue(u)}catch(t){e=u}r.push(new he(u,e))}}applyBinaryOperation(e,t,r){if("object"===typeof t||"object"===typeof r||Array.isArray(t)||Array.isArray(r))throw new ne(this.expression,w.format("Cannot evaluate expression $ $ $",t,e.getOperator(),r));let s=Fe.BINARY_OPERATORS_MAP.get(e);if(!s)throw new ne(this.expression,w.format("No operator found to evaluate $ $ $",t,e.getOperator(),r));return new he(e.toString(),s.apply(t,r))}applyUnaryOperation(e,t){if("object"===typeof t||Array.isArray(t))throw new ne(this.expression,w.format("The operator $ cannot be applied to $",e.getOperator(),t));let r=Fe.UNARY_OPERATORS_MAP.get(e);if(!r)throw new ne(this.expression,w.format("No Unary operator $ is found to apply on $",e.getOperator(),t));return new he(e.toString(),r.apply(t))}getValueFromToken(e,t){return t instanceof oe?this.evaluateExpression(t,e):t instanceof he?t.getElement():this.getValue(t.getExpression(),e)}getValue(e,t){if(e.length<=5)return Ge.INSTANCE.getValue(e);const r=e.substring(0,e.indexOf(".")+1);return(t.get(r)??Ge.INSTANCE).getValue(e)}}class $e extends De{static PREFIX="Arguments.";constructor(e){super(),this.args=e}getValueInternal(e){let t=e.split(De.REGEX_DOT);return this.retrieveElementFrom(e,t,2,this.args.get(t[1]))}getPrefix(){return $e.PREFIX}}class Ye extends De{static PREFIX="Context.";constructor(e){super(),this.context=e}getValueInternal(e){let t=e.split(De.REGEX_DOT),r=t[1],s=r.indexOf("["),n=2;return-1!=s&&(r=t[1].substring(0,s),t[1]=t[1].substring(s),n=1),this.retrieveElementFrom(e,t,n,this.context.get(r)?.getElement())}getPrefix(){return Ye.PREFIX}}class He extends De{static PREFIX="Steps.";constructor(e){super(),this.output=e}getValueInternal(e){let t=e.split(De.REGEX_DOT),r=1,s=this.output.get(t[r++]);if(!s||r>=t.length)return;let n=s.get(t[r++]);if(!n||r>=t.length)return;let i=n.get(t[r++]);return this.retrieveElementFrom(e,t,r,i)}getPrefix(){return He.PREFIX}}class We{count=0;valueExtractors=new Map;getContext(){return this.context}setContext(e){this.context=e;let t=new Ye(e);return this.valueExtractors.set(t.getPrefix(),t),this}getArguments(){return this.args}setArguments(e){this.args=e;let t=new $e(e);return this.valueExtractors.set(t.getPrefix(),t),this}getEvents(){return this.events}setEvents(e){return this.events=e,this}getStatementExecution(){return this.statementExecution}setStatementExecution(e){return this.statementExecution=e,this}getSteps(){return this.steps}setSteps(e){this.steps=e;let t=new He(e);return this.valueExtractors.set(t.getPrefix(),t),this}getCount(){return this.count}setCount(e){return this.count=e,this}getValuesMap(){return this.valueExtractors}}class je{outVertices=new Map;inVertices=new Set;constructor(e,t){this.data=t,this.graph=e}getData(){return this.data}setData(e){return this.data=e,this}getOutVertices(){return this.outVertices}setOutVertices(e){return this.outVertices=e,this}getInVertices(){return this.inVertices}setInVertices(e){return this.inVertices=e,this}getGraph(){return this.graph}setGraph(e){return this.graph=e,this}getKey(){return this.data.getUniqueKey()}addOutEdgeTo(e,t){return this.outVertices.has(e)||this.outVertices.set(e,new Set),this.outVertices.get(e).add(t),t.inVertices.add(new s(this,e)),t}addInEdgeTo(e,t){return this.inVertices.add(new s(e,t)),e.outVertices.has(t)||e.outVertices.set(t,new Set),e.outVertices.get(t).add(this),e}hasIncomingEdges(){return!!this.inVertices.size}hasOutgoingEdges(){return!!this.outVertices.size}getSubGraphOfType(e){let t=new qe(!0);var r=new te(Array.from(this.outVertices.get(e)??[]));for(r.map((e=>e.getData())).forEach((e=>t.addVertex(e)));!r.isEmpty();){var s=r.pop();Array.from(s.outVertices.values()).flatMap((e=>Array.from(e))).forEach((e=>{t.addVertex(e.getData()),r.add(e)}))}return t}toString(){var e=Array.from(this.getInVertices()).map((e=>e.getT1().getKey()+"("+e.getT2()+")")).join(", "),t=Array.from(this.outVertices.entries()).map((([e,t])=>e+": "+Array.from(t).map((e=>e.getKey())).join(","))).join("\n\t\t");return this.getKey()+":\n\tIn: "+e+"\n\tOut: \n\t\t"+t}}class qe{nodeMap=new Map;constructor(e=!1){this.isSubGrph=e}getVerticesData(){return Array.from(this.nodeMap.values()).map((e=>e.getData()))}addVertex(e){if(!this.nodeMap.has(e.getUniqueKey())){let t=new je(this,e);this.nodeMap.set(e.getUniqueKey(),t)}return this.nodeMap.get(e.getUniqueKey())}getVertex(e){return this.nodeMap.get(e)}getVertexData(e){if(this.nodeMap.has(e))return this.nodeMap.get(e).getData()}getVerticesWithNoIncomingEdges(){return Array.from(this.nodeMap.values()).filter((e=>!e.hasIncomingEdges()))}isCyclic(){let e,t=new te(this.getVerticesWithNoIncomingEdges()),r=new Set;for(;!t.isEmpty();){if(r.has(t.getFirst().getKey()))return!0;e=t.removeFirst(),r.add(e.getKey()),e.hasOutgoingEdges()&&t.addAll(Array.from(e.getOutVertices().values()).flatMap((e=>Array.from(e))))}return!1}addVertices(e){for(const t of e)this.addVertex(t)}getNodeMap(){return this.nodeMap}isSubGraph(){return this.isSubGrph}toString(){return"Execution Graph : \n"+Array.from(this.nodeMap.values()).map((e=>e.toString())).join("\n")}}class Xe{constructor(e,t){this.message=t,this.messageType=e}getMessageType(){return this.messageType}setMessageType(e){return this.messageType=e,this}getMessage(){return this.message}setMessage(e){return this.message=e,this}toString(){return`${this.messageType} : ${this.message}`}}class Qe{messages=new Array;dependencies=new Set;constructor(e){this.statement=e}getStatement(){return this.statement}setStatement(e){return this.statement=e,this}getMessages(){return this.messages}setMessages(e){return this.messages=e,this}getDependencies(){return this.dependencies}setDependencies(e){return this.dependencies=e,this}getUniqueKey(){return this.statement.getStatementName()}addMessage(e,t){this.messages.push(new Xe(e,t))}addDependency(e){this.dependencies.add(e)}getDepenedencies(){return this.dependencies}equals(e){if(!(e instanceof Qe))return!1;return e.statement.equals(this.statement)}}let Je;var Ke;(Ke=Je||(Je={})).ERROR="ERROR",Ke.WARNING="WARNING",Ke.MESSAGE="MESSAGE";class ze extends H{static PARAMETER_NEEDS_A_VALUE='Parameter "$" needs a value';static STEP_REGEX_PATTERN=new RegExp("Steps\\.([a-zA-Z0-9\\\\-]{1,})\\.([a-zA-Z0-9\\\\-]{1,})","g");static VERSION=1;static MAX_EXECUTION_ITERATIONS=1e7;constructor(e,t,r){if(super(),this.fd=e,this.fd.getVersion()>ze.VERSION)throw new R("Runtime is at a lower version "+ze.VERSION+" and trying to run code from version "+this.fd.getVersion()+".");this.fRepo=t,this.sRepo=r}getSignature(){return this.fd}getExecutionPlan(e){let t=new qe;for(let r of Array.from(this.fd.getSteps().values()))t.addVertex(this.prepareStatementExecution(e,r));let r=this.makeEdges(t);if(r.length)throw new R(w.format("Found these unresolved dependencies : $ ",r.map((e=>w.format("Steps.$.$",e.getT1(),e.getT2())))));return t}internalExecute(e){e.getContext()||e.setContext(new Map),e.getEvents()||e.setEvents(new Map),e.getSteps()||e.setSteps(new Map);let t=this.getExecutionPlan(e.getContext()),r=t.getVerticesData().filter((e=>e.getMessages().length)).map((e=>e.getStatement().getStatementName()+": \n"+e.getMessages().join(",")));if(r?.length)throw new R("Please fix the errors in the function definition before execution : \n"+r.join(",\n"));return this.executeGraph(t,e)}executeGraph(e,t){let r=new te;r.addAll(e.getVerticesWithNoIncomingEdges());let s=new te;for(;!(r.isEmpty()&&s.isEmpty()||t.getEvents()?.has(q.OUTPUT));)if(this.processBranchQue(t,r,s),this.processExecutionQue(t,r,s),t.setCount(t.getCount()+1),t.getCount()==ze.MAX_EXECUTION_ITERATIONS)throw new R("Execution locked in an infinite loop");if(!e.isSubGraph()&&!t.getEvents()?.size)throw new R("No events raised");return new Q(Array.from(t.getEvents()?.entries()??[]).flatMap((e=>e[1].map((t=>X.of(e[0],t))))))}processExecutionQue(e,t,r){if(!t.isEmpty()){let s=t.pop();this.allDependenciesResolvedVertex(s,e.getSteps())?this.executeVertex(s,e,r,t):t.add(s)}}processBranchQue(e,t,r){if(r.length){let s=r.pop();this.allDependenciesResolvedTuples(s.getT2(),e.getSteps())?this.executeBranch(e,t,s):r.add(s)}}executeBranch(e,t,r){let s,n=r.getT4();do{this.executeGraph(r.getT1(),e),s=r.getT3().next(),s&&(e.getSteps()?.has(n.getData().getStatement().getStatementName())||e.getSteps()?.set(n.getData().getStatement().getStatementName(),new Map),e.getSteps()?.get(n.getData().getStatement().getStatementName())?.set(s.getName(),this.resolveInternalExpressions(s.getResult(),e)))}while(s&&s.getName()!=q.OUTPUT);s?.getName()==q.OUTPUT&&n.getOutVertices().has(q.OUTPUT)&&(n?.getOutVertices()?.get(q.OUTPUT)??[]).forEach((e=>t.add(e)))}executeVertex(e,t,r,s){let n=e.getData().getStatement(),a=this.fRepo.find(n.getNamespace(),n.getName());if(!a)throw new R(w.format("$.$ function is not found.",n.getNamespace(),n.getName()));let o=a?.getSignature().getParameters(),h=this.getArgumentsFromParametersMap(t,n,o??new Map),u=t.getContext(),l=a.execute((new We).setContext(u).setArguments(h).setEvents(t.getEvents()).setSteps(t.getSteps()).setStatementExecution(e.getData()).setCount(t.getCount())),p=l.next();if(!p)throw new R(w.format("Executing $ returned no events",n.getStatementName()));let c=p.getName()==q.OUTPUT;if(t.getSteps()?.has(n.getStatementName())||t.getSteps().set(n.getStatementName(),new Map),t.getSteps().get(n.getStatementName()).set(p.getName(),this.resolveInternalExpressions(p.getResult(),t)),c){let t=e.getOutVertices().get(q.OUTPUT);t&&t.forEach((e=>s.add(e)))}else{let t=e.getSubGraphOfType(p.getName()),s=this.makeEdges(t);r.push(new i(t,s,l,e))}}resolveInternalExpressions(e,t){return e?Array.from(e.entries()).map((e=>new s(e[0],this.resolveInternalExpression(e[1],t)))).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map):e}resolveInternalExpression(e,t){if(p(e)||"object"!=typeof e)return e;if(e instanceof j){return new Fe(e.getExpression()).evaluate(t.getValuesMap())}if(Array.isArray(e)){let r=[];for(let s of e)r.push(this.resolveInternalExpression(s,t));return r}if("object"==typeof e){let r={};for(let s of Object.entries(e))r[s[0]]=this.resolveInternalExpression(s[1],t);return r}}allDependenciesResolvedTuples(e,t){for(let r of e){if(!t.has(r.getT1()))return!1;if(!t.get(r.getT1())?.get(r.getT2()))return!1}return!0}allDependenciesResolvedVertex(e,t){return!e.getInVertices().size||0==Array.from(e.getInVertices()).filter((e=>{let r=e.getT1().getData().getStatement().getStatementName(),s=e.getT2();return!(t.has(r)&&t.get(r)?.has(s))})).length}getArgumentsFromParametersMap(e,t,r){return Array.from(t.getParameterMap().entries()).map((t=>{let n,i=t[1];if(!i?.length)return new s(t[0],n);let a=r.get(t[0]);return a?(n=a.isVariableArgument()?i.map((t=>this.parameterReferenceEvaluation(e,t))).flatMap((e=>Array.isArray(e)?e:[e])):this.parameterReferenceEvaluation(e,i[0]),new s(t[0],n)):new s(t[0],void 0)})).filter((e=>!p(e.getT2()))).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map)}parameterReferenceEvaluation(e,t){let r;if(t.getType()==Z.VALUE)r=this.resolveInternalExpression(t.getValue(),e);else if(t.getType()==Z.EXPRESSION&&!y.isNullOrBlank(t.getExpression())){r=new Fe(t.getExpression()??"").evaluate(e.getValuesMap())}return r}prepareStatementExecution(e,t){let r=new Qe(t),s=this.fRepo.find(t.getNamespace(),t.getName());if(!s)throw new R(w.format("$.$ was not available",t.getNamespace(),t.getName()));let n=new Map(s.getSignature().getParameters());for(let s of Array.from(t.getParameterMap().entries())){let t=n.get(s[0]);if(!t)continue;let i=s[1];if(i.length){if(t.isVariableArgument())for(let s of i)this.parameterReferenceValidation(e,r,t,s);else{let s=i[0];this.parameterReferenceValidation(e,r,t,s)}n.delete(t.getParameterName())}else p(v.getDefaultValue(t.getSchema(),this.sRepo))&&r.addMessage(Je.ERROR,w.format(ze.PARAMETER_NEEDS_A_VALUE,t.getParameterName()))}if(!p(r.getStatement().getDependentStatements()))for(let e of r.getStatement().getDependentStatements())r.addDependency(e);if(n.size)for(let e of Array.from(n.values()))p(v.getDefaultValue(e.getSchema(),this.sRepo))&&r.addMessage(Je.ERROR,w.format(ze.PARAMETER_NEEDS_A_VALUE,e.getParameterName()));return r}parameterReferenceValidation(e,t,r,n){if(n){if(n.getType()==Z.VALUE){p(n.getValue())&&p(v.getDefaultValue(r.getSchema(),this.sRepo))&&t.addMessage(Je.ERROR,w.format(ze.PARAMETER_NEEDS_A_VALUE,r.getParameterName()));let e=new te;for(e.push(new s(r.getSchema(),n.getValue()));!e.isEmpty();){let r=e.pop();if(r.getT2()instanceof j)this.addDependencies(t,r.getT2().getExpression());else{if(p(r.getT1())||p(r.getT1().getType()))continue;if(r.getT1().getType()?.contains(f.ARRAY)&&Array.isArray(r.getT2())){let t=r.getT1().getItems();if(!t)continue;if(t.isSingleType())for(let n of r.getT2())e.push(new s(t.getSingleSchema(),n));else{let n=r.getT2();for(let r=0;r<n.length;r++)e.push(new s(t.getTupleSchema()[r],n[r]))}}else if(r.getT1().getType()?.contains(f.OBJECT)&&"object"==typeof r.getT2()){let n=r.getT1();if(n.getName()===z.EXPRESSION.getName()&&n.getNamespace()===z.EXPRESSION.getNamespace()){let e=r.getT2();e.isExpression&&this.addDependencies(t,e.value)}else if(n.getProperties())for(let t of Object.entries(r.getT2()))n.getProperties().has(t[0])&&e.push(new s(n.getProperties().get(t[0]),t[1]))}}}}else if(n.getType()==Z.EXPRESSION)if(y.isNullOrBlank(n.getExpression()))p(v.getDefaultValue(r.getSchema(),this.sRepo))&&t.addMessage(Je.ERROR,w.format(ze.PARAMETER_NEEDS_A_VALUE,r.getParameterName()));else try{this.addDependencies(t,n.getExpression())}catch(e){t.addMessage(Je.ERROR,w.format("Error evaluating $ : $",n.getExpression(),e))}}else p(v.getDefaultValue(r.getSchema(),this.sRepo))&&t.addMessage(Je.ERROR,w.format(ze.PARAMETER_NEEDS_A_VALUE,r.getParameterName()))}addDependencies(e,t){t&&Array.from(t.match(ze.STEP_REGEX_PATTERN)??[]).forEach((t=>e.addDependency(t)))}makeEdges(e){let t=e.getNodeMap().values(),r=[];for(let n of Array.from(t))for(let t of n.getData().getDependencies()){let i=t.indexOf(".",6),a=t.substring(6,i),o=t.indexOf(".",i+1),h=-1==o?t.substring(i+1):t.substring(i+1,o);e.getNodeMap().has(a)||r.push(new s(a,h));let u=e.getNodeMap().get(a);u&&n.addInEdgeTo(u,h)}return r}}e(module.exports,r),e(module.exports,{}),e(module.exports,a),e(module.exports,h),e(module.exports,g),e(module.exports,N),e(module.exports,k),e(module.exports,F),e(module.exports,I),e(module.exports,{}),e(module.exports,Y),e(module.exports,u),e(module.exports,W);
2
+ //# sourceMappingURL=index.js.map