@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,9 @@
1
+ import { Operation } from '../../Operation';
2
+ import { BinaryOperator } from './BinaryOperator';
3
+
4
+ export class BitwiseLeftShiftOperator extends BinaryOperator {
5
+ public apply(t: any, u: any): any {
6
+ this.nullCheck(t, u, Operation.BITWISE_LEFT_SHIFT);
7
+ return t << u;
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Operation } from '../../Operation';
2
+ import { BinaryOperator } from './BinaryOperator';
3
+
4
+ export class BitwiseOrOperator extends BinaryOperator {
5
+ public apply(t: any, u: any): any {
6
+ this.nullCheck(t, u, Operation.BITWISE_OR);
7
+ return t | u;
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Operation } from '../../Operation';
2
+ import { BinaryOperator } from './BinaryOperator';
3
+
4
+ export class BitwiseRightShiftOperator extends BinaryOperator {
5
+ public apply(t: any, u: any): any {
6
+ this.nullCheck(t, u, Operation.BITWISE_RIGHT_SHIFT);
7
+ return t >> u;
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Operation } from '../../Operation';
2
+ import { BinaryOperator } from './BinaryOperator';
3
+
4
+ export class BitwiseUnsignedRightShiftOperator extends BinaryOperator {
5
+ public apply(t: any, u: any): any {
6
+ this.nullCheck(t, u, Operation.BITWISE_UNSIGNED_RIGHT_SHIFT);
7
+ return t >>> u;
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Operation } from '../../Operation';
2
+ import { BinaryOperator } from './BinaryOperator';
3
+
4
+ export class BitwiseXorOperator extends BinaryOperator {
5
+ public apply(t: any, u: any): any {
6
+ this.nullCheck(t, u, Operation.BITWISE_XOR);
7
+ return t ^ u;
8
+ }
9
+ }
@@ -0,0 +1,25 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { BinaryOperator } from './BinaryOperator';
7
+
8
+ export class LogicalAndOperator extends BinaryOperator {
9
+ public apply(t: any, u: any): any {
10
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
11
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
12
+
13
+ if (tType.getT1() != SchemaType.BOOLEAN)
14
+ throw new ExecutionException(
15
+ StringFormatter.format('Boolean value expected but found $', tType.getT2()),
16
+ );
17
+
18
+ if (uType.getT1() != SchemaType.BOOLEAN)
19
+ throw new ExecutionException(
20
+ StringFormatter.format('Boolean value expected but found $', uType.getT2()),
21
+ );
22
+
23
+ return tType.getT2() && uType.getT2();
24
+ }
25
+ }
@@ -0,0 +1,13 @@
1
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
2
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
3
+ import { Tuple2 } from '../../../../util/Tuples';
4
+ import { BinaryOperator } from './BinaryOperator';
5
+
6
+ export class LogicalEqualOperator extends BinaryOperator {
7
+ public apply(t: any, u: any): any {
8
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
9
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
10
+
11
+ return tType.getT2() == uType.getT2();
12
+ }
13
+ }
@@ -0,0 +1,24 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { BinaryOperator } from './BinaryOperator';
7
+
8
+ export class LogicalGreaterThanEqualOperator extends BinaryOperator {
9
+ public apply(t: any, u: any): any {
10
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
11
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
12
+
13
+ if (tType.getT1() == SchemaType.BOOLEAN || uType.getT1() == SchemaType.BOOLEAN)
14
+ throw new ExecutionException(
15
+ StringFormatter.format(
16
+ 'Cannot compare >= with the values $ and $',
17
+ tType.getT2(),
18
+ uType.getT2(),
19
+ ),
20
+ );
21
+
22
+ return tType.getT2() >= uType.getT2();
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { BinaryOperator } from './BinaryOperator';
7
+
8
+ export class LogicalGreaterThanOperator extends BinaryOperator {
9
+ public apply(t: any, u: any): any {
10
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
11
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
12
+
13
+ if (tType.getT1() == SchemaType.BOOLEAN || uType.getT1() == SchemaType.BOOLEAN)
14
+ throw new ExecutionException(
15
+ StringFormatter.format(
16
+ 'Cannot compare > with the values $ and $',
17
+ tType.getT2(),
18
+ uType.getT2(),
19
+ ),
20
+ );
21
+
22
+ return tType.getT2() > uType.getT2();
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { BinaryOperator } from './BinaryOperator';
7
+
8
+ export class LogicalLessThanEqualOperator extends BinaryOperator {
9
+ public apply(t: any, u: any): any {
10
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
11
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
12
+
13
+ if (tType.getT1() == SchemaType.BOOLEAN || uType.getT1() == SchemaType.BOOLEAN)
14
+ throw new ExecutionException(
15
+ StringFormatter.format(
16
+ 'Cannot compare <= with the values $ and $',
17
+ tType.getT2(),
18
+ uType.getT2(),
19
+ ),
20
+ );
21
+
22
+ return tType.getT2() <= uType.getT2();
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { BinaryOperator } from './BinaryOperator';
7
+
8
+ export class LogicalLessThanOperator extends BinaryOperator {
9
+ public apply(t: any, u: any): any {
10
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
11
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
12
+
13
+ if (tType.getT1() == SchemaType.BOOLEAN || uType.getT1() == SchemaType.BOOLEAN)
14
+ throw new ExecutionException(
15
+ StringFormatter.format(
16
+ 'Cannot compare < with the values $ and $',
17
+ tType.getT2(),
18
+ uType.getT2(),
19
+ ),
20
+ );
21
+
22
+ return tType.getT2() < uType.getT2();
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
2
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
3
+ import { Tuple2 } from '../../../../util/Tuples';
4
+ import { BinaryOperator } from './BinaryOperator';
5
+
6
+ export class LogicalNotEqualOperator extends BinaryOperator {
7
+ public apply(t: any, u: any): any {
8
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
9
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
10
+
11
+ return tType.getT2() != uType.getT2();
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { BinaryOperator } from './BinaryOperator';
7
+
8
+ export class LogicalOrOperator extends BinaryOperator {
9
+ public apply(t: any, u: any): any {
10
+ const tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(t);
11
+ const uType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNullAsBoolean(u);
12
+
13
+ if (tType.getT1() != SchemaType.BOOLEAN)
14
+ throw new ExecutionException(
15
+ StringFormatter.format('Boolean value expected but found $', tType.getT2()),
16
+ );
17
+
18
+ if (uType.getT1() != SchemaType.BOOLEAN)
19
+ throw new ExecutionException(
20
+ StringFormatter.format('Boolean value expected but found $', uType.getT2()),
21
+ );
22
+
23
+ return tType.getT2() || uType.getT2();
24
+ }
25
+ }
@@ -0,0 +1,24 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
3
+ import { BinaryOperator } from './BinaryOperator';
4
+
5
+ export class ObjectOperator extends BinaryOperator {
6
+ public apply(t: any, u: any): any {
7
+ if (!t) {
8
+ throw new ExecutionException('Cannot apply array operator on a null value');
9
+ }
10
+
11
+ if (!u) {
12
+ throw new ExecutionException('Cannot retrive null property value');
13
+ }
14
+
15
+ const x: string = typeof t;
16
+
17
+ if (!Array.isArray(t) && x != 'string' && x != 'object') {
18
+ throw new ExecutionException(
19
+ StringFormatter.format('Cannot retrieve value from a primitive value $', t),
20
+ );
21
+ }
22
+ return t[u];
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
2
+ import { Operation } from '../../Operation';
3
+ import { UnaryOperator } from './UnaryOperator';
4
+
5
+ export class ArithmeticUnaryMinusOperator extends UnaryOperator {
6
+ public apply(t: any): any {
7
+ this.nullCheck(t, Operation.UNARY_MINUS);
8
+
9
+ PrimitiveUtil.findPrimitiveNumberType(t);
10
+
11
+ return -t;
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
2
+ import { Operation } from '../../Operation';
3
+ import { UnaryOperator } from './UnaryOperator';
4
+
5
+ export class ArithmeticUnaryPlusOperator extends UnaryOperator {
6
+ public apply(t: any): any {
7
+ this.nullCheck(t, Operation.UNARY_PLUS);
8
+
9
+ PrimitiveUtil.findPrimitiveNumberType(t);
10
+
11
+ return t;
12
+ }
13
+ }
@@ -0,0 +1,22 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { Operation } from '../../Operation';
7
+ import { UnaryOperator } from './UnaryOperator';
8
+
9
+ export class BitwiseComplementOperator extends UnaryOperator {
10
+ public apply(t: any): any {
11
+ this.nullCheck(t, Operation.UNARY_BITWISE_COMPLEMENT);
12
+
13
+ let tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNumberType(t);
14
+
15
+ if (tType.getT1() != SchemaType.INTEGER && tType.getT1() != SchemaType.LONG)
16
+ throw new ExecutionException(
17
+ StringFormatter.format('Unable to apply bitwise operator on $', t),
18
+ );
19
+
20
+ return ~t;
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { SchemaType } from '../../../../json/schema/type/SchemaType';
3
+ import { PrimitiveUtil } from '../../../../util/primitive/PrimitiveUtil';
4
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
5
+ import { Tuple2 } from '../../../../util/Tuples';
6
+ import { Operation } from '../../Operation';
7
+ import { UnaryOperator } from './UnaryOperator';
8
+
9
+ export class LogicalNotOperator extends UnaryOperator {
10
+ public apply(t: any): any {
11
+ this.nullCheck(t, Operation.UNARY_LOGICAL_NOT);
12
+
13
+ let tType: Tuple2<SchemaType, any> = PrimitiveUtil.findPrimitiveNumberType(t);
14
+
15
+ if (tType.getT1() != SchemaType.BOOLEAN)
16
+ throw new ExecutionException(
17
+ StringFormatter.format('Unable to apply bitwise operator on $', t),
18
+ );
19
+
20
+ return !t;
21
+ }
22
+ }
@@ -0,0 +1,15 @@
1
+ import { ExecutionException } from '../../../../exception/ExecutionException';
2
+ import { isNullValue } from '../../../../util/NullCheck';
3
+ import { StringFormatter } from '../../../../util/string/StringFormatter';
4
+ import { Operation } from '../../Operation';
5
+
6
+ export abstract class UnaryOperator {
7
+ public abstract apply(t: any): any;
8
+
9
+ public nullCheck(e1: any, op: Operation): void {
10
+ if (isNullValue(e1))
11
+ throw new ExecutionException(
12
+ StringFormatter.format('$ cannot be applied to a null value', op.getOperatorName()),
13
+ );
14
+ }
15
+ }
@@ -0,0 +1,64 @@
1
+ import { StringFormatter } from '../../../util/string/StringFormatter';
2
+ import { StringUtil } from '../../../util/string/StringUtil';
3
+ import { ExpressionEvaluationException } from '../exception/ExpressionEvaluationException';
4
+ import { TokenValueExtractor } from './TokenValueExtractor';
5
+
6
+ const KEYWORDS: Map<string, any> = new Map([
7
+ ['true', true],
8
+ ['false', false],
9
+ ['null', undefined],
10
+ ]);
11
+
12
+ export class LiteralTokenValueExtractor extends TokenValueExtractor {
13
+ public static readonly INSTANCE: LiteralTokenValueExtractor = new LiteralTokenValueExtractor();
14
+
15
+ protected getValueInternal(token: string): any {
16
+ if (StringUtil.isNullOrBlank(token)) return undefined;
17
+
18
+ token = token.trim();
19
+
20
+ if (KEYWORDS.has(token)) return KEYWORDS.get(token);
21
+
22
+ if (token.startsWith('"')) {
23
+ return this.processString(token);
24
+ }
25
+
26
+ return this.processNumbers(token);
27
+ }
28
+
29
+ private processNumbers(token: string): any {
30
+ try {
31
+ let ind: number = token.indexOf('.');
32
+ let v: number;
33
+ if (ind == -1) {
34
+ v = parseInt(token);
35
+ } else {
36
+ v = parseFloat(token);
37
+ }
38
+
39
+ if (isNaN(v)) throw new Error('Parse number error');
40
+
41
+ return v;
42
+ } catch (err: any) {
43
+ throw new ExpressionEvaluationException(
44
+ token,
45
+ StringFormatter.format('Unable to parse the literal or expression $', token),
46
+ err,
47
+ );
48
+ }
49
+ }
50
+
51
+ private processString(token: string): any {
52
+ if (!token.endsWith('"'))
53
+ throw new ExpressionEvaluationException(
54
+ token,
55
+ StringFormatter.format('String literal $ is not closed properly', token),
56
+ );
57
+
58
+ return token.substring(1, token.length - 1);
59
+ }
60
+
61
+ public getPrefix(): string {
62
+ return '';
63
+ }
64
+ }
@@ -0,0 +1,136 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { isNullValue } from '../../../util/NullCheck';
3
+ import { StringFormatter } from '../../../util/string/StringFormatter';
4
+ import { StringUtil } from '../../../util/string/StringUtil';
5
+ import { ExpressionEvaluationException } from '../exception/ExpressionEvaluationException';
6
+
7
+ export abstract class TokenValueExtractor {
8
+ private static readonly REGEX_SQUARE_BRACKETS: RegExp = /[\[\]]/;
9
+ public static readonly REGEX_DOT: RegExp = /\./;
10
+
11
+ public getValue(token: string): any {
12
+ let prefix: string = this.getPrefix();
13
+
14
+ if (!token.startsWith(prefix))
15
+ throw new KIRuntimeException(
16
+ StringFormatter.format("Token $ doesn't start with $", token, prefix),
17
+ );
18
+
19
+ return this.getValueInternal(token);
20
+ }
21
+
22
+ protected retrieveElementFrom(
23
+ token: string,
24
+ parts: string[],
25
+ partNumber: number,
26
+ jsonElement: any,
27
+ ): any {
28
+ if (isNullValue(jsonElement)) return undefined;
29
+
30
+ if (parts.length == partNumber) return jsonElement;
31
+
32
+ let bElement: any = parts[partNumber]
33
+ .split(TokenValueExtractor.REGEX_SQUARE_BRACKETS)
34
+ .map((e) => e.trim())
35
+ .filter((e) => !StringUtil.isNullOrBlank(e))
36
+ .reduce(
37
+ (a, c, i) =>
38
+ this.resolveForEachPartOfTokenWithBrackets(token, parts, partNumber, c, a, i),
39
+ jsonElement,
40
+ );
41
+
42
+ return this.retrieveElementFrom(token, parts, partNumber + 1, bElement);
43
+ }
44
+
45
+ protected resolveForEachPartOfTokenWithBrackets(
46
+ token: string,
47
+ parts: string[],
48
+ partNumber: number,
49
+ c: string,
50
+ a: any,
51
+ i: any,
52
+ ): any {
53
+ if (isNullValue(a)) return undefined;
54
+
55
+ if (i === 0) {
56
+ if (Array.isArray(a)) {
57
+ if (c === 'length') return a.length;
58
+ try {
59
+ let index: number = parseInt(c);
60
+ if (isNaN(index)) {
61
+ throw new Error(StringFormatter.format('$ is not a number', index));
62
+ }
63
+ if (index >= a.length) return undefined;
64
+
65
+ return a[index];
66
+ } catch (err: any) {
67
+ throw new ExpressionEvaluationException(
68
+ token,
69
+ StringFormatter.format("$ couldn't be parsed into integer in $", c, token),
70
+ err,
71
+ );
72
+ }
73
+ }
74
+
75
+ this.checkIfObject(token, parts, partNumber, a);
76
+ return a[c];
77
+ } else if (c?.startsWith('"')) {
78
+ if (!c.endsWith('"') || c.length == 1 || c.length == 2)
79
+ throw new ExpressionEvaluationException(
80
+ token,
81
+ StringFormatter.format('$ is missing a double quote or empty key found', token),
82
+ );
83
+
84
+ this.checkIfObject(token, parts, partNumber, a);
85
+ return a[c.substring(1, c.length - 1)];
86
+ }
87
+
88
+ try {
89
+ let index: number = parseInt(c);
90
+ if (isNaN(index)) {
91
+ throw new Error(StringFormatter.format('$ is not a number', index));
92
+ }
93
+ if (!Array.isArray(a))
94
+ throw new ExpressionEvaluationException(
95
+ token,
96
+ StringFormatter.format(
97
+ 'Expecting an array with index $ while processing the expression',
98
+ index,
99
+ token,
100
+ ),
101
+ );
102
+
103
+ if (index >= a.length) return undefined;
104
+
105
+ return a[index];
106
+ } catch (err: any) {
107
+ throw new ExpressionEvaluationException(
108
+ token,
109
+ StringFormatter.format("$ couldn't be parsed into integer in $", c, token),
110
+ err,
111
+ );
112
+ }
113
+ }
114
+
115
+ private checkIfObject(
116
+ token: string,
117
+ parts: string[],
118
+ partNumber: number,
119
+ jsonElement: any,
120
+ ): void {
121
+ if (typeof jsonElement != 'object' || Array.isArray(jsonElement))
122
+ throw new ExpressionEvaluationException(
123
+ token,
124
+ StringFormatter.format(
125
+ 'Unable to retrive $ from $ in the path $',
126
+ parts[partNumber],
127
+ jsonElement.toString(),
128
+ token,
129
+ ),
130
+ );
131
+ }
132
+
133
+ protected abstract getValueInternal(token: string): any;
134
+
135
+ public abstract getPrefix(): string;
136
+ }
@@ -0,0 +1,81 @@
1
+ import { LinkedList } from '../../util/LinkedList';
2
+ import { GraphVertex } from './GraphVertex';
3
+ import { GraphVertexType } from './GraphVertexType';
4
+
5
+ export class ExecutionGraph<K, T extends GraphVertexType<K>> {
6
+ private nodeMap: Map<K, GraphVertex<K, T>> = new Map();
7
+ private isSubGrph: boolean;
8
+
9
+ public constructor(isSubGrph: boolean = false) {
10
+ this.isSubGrph = isSubGrph;
11
+ }
12
+
13
+ public getVerticesData(): T[] {
14
+ return Array.from(this.nodeMap.values()).map((e) => e.getData());
15
+ }
16
+
17
+ public addVertex(data: T): GraphVertex<K, T> {
18
+ if (!this.nodeMap.has(data.getUniqueKey())) {
19
+ let t = new GraphVertex(this, data);
20
+ this.nodeMap.set(data.getUniqueKey(), t);
21
+ }
22
+ return this.nodeMap.get(data.getUniqueKey())!;
23
+ }
24
+
25
+ public getVertex(key: K): GraphVertex<K, T> | undefined {
26
+ return this.nodeMap.get(key);
27
+ }
28
+
29
+ public getVertexData(key: K): T | undefined {
30
+ if (this.nodeMap.has(key)) return this.nodeMap.get(key)!.getData();
31
+ return undefined;
32
+ }
33
+
34
+ public getVerticesWithNoIncomingEdges(): GraphVertex<K, T>[] {
35
+ return Array.from(this.nodeMap.values()).filter((e) => !e.hasIncomingEdges());
36
+ }
37
+
38
+ public isCyclic(): boolean {
39
+ let list: LinkedList<GraphVertex<K, T>> = new LinkedList(
40
+ this.getVerticesWithNoIncomingEdges(),
41
+ );
42
+ let visited: Set<K> = new Set();
43
+
44
+ let vertex: GraphVertex<K, T>;
45
+ while (!list.isEmpty()) {
46
+ if (visited.has(list.getFirst().getKey())) return true;
47
+
48
+ vertex = list.removeFirst();
49
+
50
+ visited.add(vertex.getKey());
51
+ if (vertex.hasOutgoingEdges())
52
+ list.addAll(
53
+ Array.from(vertex.getOutVertices().values()).flatMap((e) => Array.from(e)),
54
+ );
55
+ }
56
+
57
+ return false;
58
+ }
59
+
60
+ public addVertices(values: T[]): void {
61
+ for (const value of values) this.addVertex(value);
62
+ }
63
+
64
+ public getNodeMap(): Map<K, GraphVertex<K, T>> {
65
+ return this.nodeMap;
66
+ }
67
+
68
+ public isSubGraph(): boolean {
69
+ return this.isSubGrph;
70
+ }
71
+
72
+ public toString(): string {
73
+ return (
74
+ 'Execution Graph : \n' +
75
+ Array.from(this.nodeMap.values())
76
+
77
+ .map((e) => e.toString())
78
+ .join('\n')
79
+ );
80
+ }
81
+ }