@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,118 @@
1
+ import { LinkedList } from '../../util/LinkedList';
2
+ import { Tuple2 } from '../../util/Tuples';
3
+ import { ExecutionGraph } from './ExecutionGraph';
4
+ import { GraphVertexType } from './GraphVertexType';
5
+
6
+ export class GraphVertex<K, T extends GraphVertexType<K>> {
7
+ private data: T;
8
+ private outVertices: Map<string, Set<GraphVertex<K, T>>> = new Map();
9
+ private inVertices: Set<Tuple2<GraphVertex<K, T>, string>> = new Set();
10
+ private graph: ExecutionGraph<K, T>;
11
+
12
+ public constructor(graph: ExecutionGraph<K, T>, data: T) {
13
+ this.data = data;
14
+ this.graph = graph;
15
+ }
16
+
17
+ public getData(): T {
18
+ return this.data;
19
+ }
20
+ public setData(data: T): GraphVertex<K, T> {
21
+ this.data = data;
22
+ return this;
23
+ }
24
+ public getOutVertices(): Map<string, Set<GraphVertex<K, T>>> {
25
+ return this.outVertices;
26
+ }
27
+ public setOutVertices(outVertices: Map<string, Set<GraphVertex<K, T>>>): GraphVertex<K, T> {
28
+ this.outVertices = outVertices;
29
+ return this;
30
+ }
31
+ public getInVertices(): Set<Tuple2<GraphVertex<K, T>, string>> {
32
+ return this.inVertices;
33
+ }
34
+ public setInVertices(inVertices: Set<Tuple2<GraphVertex<K, T>, string>>): GraphVertex<K, T> {
35
+ this.inVertices = inVertices;
36
+ return this;
37
+ }
38
+ public getGraph(): ExecutionGraph<K, T> {
39
+ return this.graph;
40
+ }
41
+ public setGraph(graph: ExecutionGraph<K, T>): GraphVertex<K, T> {
42
+ this.graph = graph;
43
+ return this;
44
+ }
45
+
46
+ public getKey(): K {
47
+ return this.data.getUniqueKey();
48
+ }
49
+
50
+ // public addOutEdgeTo(type: string, data:T) :GraphVertex<K, T> {
51
+ // return this.addOutEdgeTo(type, this.graph.addVertex(data));
52
+ // }
53
+
54
+ // public GraphVertex<K, T> addInEdgeTo(T data, String type) {
55
+ // return this.addInEdgeTo(this.graph.addVertex(data), type);
56
+ // }
57
+
58
+ public addOutEdgeTo(type: string, vertex: GraphVertex<K, T>): GraphVertex<K, T> {
59
+ if (!this.outVertices.has(type)) this.outVertices.set(type, new Set());
60
+ this.outVertices.get(type)!.add(vertex);
61
+ vertex.inVertices.add(new Tuple2(this, type));
62
+ return vertex;
63
+ }
64
+
65
+ public addInEdgeTo(vertex: GraphVertex<K, T>, type: string): GraphVertex<K, T> {
66
+ this.inVertices.add(new Tuple2(vertex, type));
67
+ if (!vertex.outVertices.has(type)) vertex.outVertices.set(type, new Set());
68
+ vertex.outVertices.get(type)!.add(this);
69
+ return vertex;
70
+ }
71
+
72
+ public hasIncomingEdges(): boolean {
73
+ return !!this.inVertices.size;
74
+ }
75
+
76
+ public hasOutgoingEdges(): boolean {
77
+ return !!this.outVertices.size;
78
+ }
79
+
80
+ public getSubGraphOfType(type: string): ExecutionGraph<K, T> {
81
+ let subGraph: ExecutionGraph<K, T> = new ExecutionGraph(true);
82
+
83
+ var typeVertices = new LinkedList(Array.from(this.outVertices.get(type) ?? []));
84
+
85
+ typeVertices.map((e) => e.getData()).forEach((e) => subGraph.addVertex(e));
86
+
87
+ while (!typeVertices.isEmpty()) {
88
+ var vertex = typeVertices.pop();
89
+ Array.from(vertex.outVertices.values())
90
+ .flatMap((e) => Array.from(e))
91
+ .forEach((e) => {
92
+ subGraph.addVertex(e.getData());
93
+ typeVertices.add(e);
94
+ });
95
+ }
96
+
97
+ return subGraph;
98
+ }
99
+
100
+ public toString(): string {
101
+ var ins = Array.from(this.getInVertices())
102
+ .map((e) => e.getT1().getKey() + '(' + e.getT2() + ')')
103
+ .join(', ');
104
+
105
+ var outs = Array.from(this.outVertices.entries())
106
+ .map(
107
+ ([key, value]) =>
108
+ key +
109
+ ': ' +
110
+ Array.from(value)
111
+ .map((e) => e.getKey())
112
+ .join(','),
113
+ )
114
+ .join('\n\t\t');
115
+
116
+ return this.getKey() + ':\n\tIn: ' + ins + '\n\tOut: \n\t\t' + outs;
117
+ }
118
+ }
@@ -0,0 +1,4 @@
1
+ export interface GraphVertexType<K> {
2
+ getUniqueKey(): K;
3
+ getDepenedencies(): Set<string>;
4
+ }
@@ -0,0 +1,22 @@
1
+ import { TokenValueExtractor } from '../expression/tokenextractor/TokenValueExtractor';
2
+
3
+ export class ArgumentsTokenValueExtractor extends TokenValueExtractor {
4
+ public static readonly PREFIX: string = 'Arguments.';
5
+
6
+ private args: Map<string, any>;
7
+
8
+ public constructor(args: Map<string, any>) {
9
+ super();
10
+ this.args = args;
11
+ }
12
+
13
+ protected getValueInternal(token: string): any {
14
+ let parts: string[] = token.split(TokenValueExtractor.REGEX_DOT);
15
+
16
+ return this.retrieveElementFrom(token, parts, 2, this.args.get(parts[1]));
17
+ }
18
+
19
+ public getPrefix(): string {
20
+ return ArgumentsTokenValueExtractor.PREFIX;
21
+ }
22
+ }
@@ -0,0 +1,37 @@
1
+ import { ContextElement } from '../ContextElement';
2
+ import { TokenValueExtractor } from '../expression/tokenextractor/TokenValueExtractor';
3
+
4
+ export class ContextTokenValueExtractor extends TokenValueExtractor {
5
+ public static readonly PREFIX: string = 'Context.';
6
+
7
+ private context: Map<string, ContextElement>;
8
+
9
+ public constructor(context: Map<string, ContextElement>) {
10
+ super();
11
+ this.context = context;
12
+ }
13
+
14
+ protected getValueInternal(token: string): any {
15
+ let parts: string[] = token.split(TokenValueExtractor.REGEX_DOT);
16
+
17
+ let key: string = parts[1];
18
+ let bIndex: number = key.indexOf('[');
19
+ let fromIndex = 2;
20
+ if (bIndex != -1) {
21
+ key = parts[1].substring(0, bIndex);
22
+ parts[1] = parts[1].substring(bIndex);
23
+ fromIndex = 1;
24
+ }
25
+
26
+ return this.retrieveElementFrom(
27
+ token,
28
+ parts,
29
+ fromIndex,
30
+ this.context.get(key)?.getElement(),
31
+ );
32
+ }
33
+
34
+ public getPrefix(): string {
35
+ return ContextTokenValueExtractor.PREFIX;
36
+ }
37
+ }
@@ -0,0 +1,32 @@
1
+ import { TokenValueExtractor } from '../expression/tokenextractor/TokenValueExtractor';
2
+
3
+ export class OutputMapTokenValueExtractor extends TokenValueExtractor {
4
+ public static readonly PREFIX: string = 'Steps.';
5
+
6
+ private output: Map<string, Map<string, Map<string, any>>>;
7
+
8
+ public constructor(output: Map<string, Map<string, Map<string, any>>>) {
9
+ super();
10
+ this.output = output;
11
+ }
12
+
13
+ protected getValueInternal(token: string): any {
14
+ let parts: string[] = token.split(TokenValueExtractor.REGEX_DOT);
15
+
16
+ let ind: number = 1;
17
+
18
+ let events: Map<string, Map<string, any>> | undefined = this.output.get(parts[ind++]);
19
+ if (!events || ind >= parts.length) return undefined;
20
+
21
+ let eachEvent: Map<string, any> | undefined = events.get(parts[ind++]);
22
+ if (!eachEvent || ind >= parts.length) return undefined;
23
+
24
+ let element: any = eachEvent.get(parts[ind++]);
25
+
26
+ return this.retrieveElementFrom(token, parts, ind, element);
27
+ }
28
+
29
+ public getPrefix(): string {
30
+ return OutputMapTokenValueExtractor.PREFIX;
31
+ }
32
+ }
@@ -0,0 +1,23 @@
1
+ export class ArrayUtil {
2
+ public static removeAListFrom(source: any[], removeList: any[]): void {
3
+ if (!removeList || !source || !source.length || !removeList.length) return;
4
+
5
+ const e: Set<any> = new Set<any>(removeList);
6
+
7
+ for (let i = 0; i < source.length; i++) {
8
+ if (!e.has(source[i])) continue;
9
+ source.splice(i, 1);
10
+ i--;
11
+ }
12
+ }
13
+
14
+ public static of<K>(...k: K[]): K[] {
15
+ const copy: K[] = new Array(k.length);
16
+
17
+ for (let i = 0; i < k.length; i++) copy[i] = k[i];
18
+
19
+ return copy;
20
+ }
21
+
22
+ private constructor() {}
23
+ }
@@ -0,0 +1,229 @@
1
+ import { KIRuntimeException } from '../exception/KIRuntimeException';
2
+ import { StringFormatter } from './string/StringFormatter';
3
+
4
+ export class LinkedList<T> {
5
+ private head?: Node<T> = undefined;
6
+ private tail?: Node<T> = undefined;
7
+ public length: number = 0;
8
+
9
+ public constructor(list?: T[]) {
10
+ if (list?.length) {
11
+ for (const t of list) {
12
+ if (!this.head) {
13
+ this.tail = this.head = new Node(t);
14
+ } else {
15
+ const node = new Node(t, this.tail);
16
+ this.tail!.next = node;
17
+ this.tail = node;
18
+ }
19
+ }
20
+ this.length = list.length;
21
+ }
22
+ }
23
+
24
+ public push(value: T) {
25
+ const node = new Node(value, undefined, this.head);
26
+ if (!this.head) {
27
+ this.tail = this.head = node;
28
+ } else {
29
+ this.head.previous = node;
30
+ this.head = node;
31
+ }
32
+ this.length++;
33
+ }
34
+
35
+ public pop(): T {
36
+ if (!this.head) {
37
+ throw Error("List is empty and cannot pop further.");
38
+ }
39
+ const value: T = this.head!.value;
40
+ this.length--;
41
+
42
+ if (this.head == this.tail) {
43
+ this.head = this.tail = undefined;
44
+ return value;
45
+ }
46
+
47
+ const node: Node<T> = this.head!;
48
+
49
+ this.head = node.next;
50
+ node.next = undefined;
51
+ node.previous = undefined;
52
+ this.head!.previous = undefined;
53
+ return value;
54
+ }
55
+
56
+ public isEmpty(): boolean {
57
+ return !this.length;
58
+ }
59
+
60
+ public size(): number {
61
+ return this.length;
62
+ }
63
+
64
+ public get(index: number): T {
65
+ if (index < 0 || index >= this.length) {
66
+ throw new Error(`${index} is out of bounds [0,${this.length}]`);
67
+ }
68
+
69
+ let x = this.head;
70
+ while (index > 0) {
71
+ x = this.head!.next;
72
+ --index;
73
+ }
74
+
75
+ return x!.value;
76
+ }
77
+
78
+ public set(index: number, value: T): LinkedList<T> {
79
+ if (index < 0 || index >= this.length)
80
+ throw new KIRuntimeException(
81
+ StringFormatter.format(
82
+ 'Index $ out of bound to set the value in linked list.',
83
+ index,
84
+ ),
85
+ );
86
+
87
+ let x = this.head;
88
+ while (index > 0) {
89
+ x = this.head!.next;
90
+ --index;
91
+ }
92
+ x!.value = value;
93
+ return this;
94
+ }
95
+
96
+ public toString(): string {
97
+ let x = this.head;
98
+ let str: string = '';
99
+
100
+ while (x) {
101
+ str += x.value;
102
+ x = x.next;
103
+ if (x) str += ', ';
104
+ }
105
+
106
+ return `[${str}]`;
107
+ }
108
+
109
+ public toArray(): T[] {
110
+ let arr: T[] = [];
111
+
112
+ let x = this.head;
113
+
114
+ while (x) {
115
+ arr.push(x.value);
116
+ x = x.next;
117
+ }
118
+
119
+ return arr;
120
+ }
121
+
122
+ public peek(): T {
123
+ if (!this.head) {
124
+ throw new Error("List is empty so cannot peak");
125
+ }
126
+
127
+ return this.head.value;
128
+ }
129
+
130
+ public peekLast(): T {
131
+ if (!this.tail) {
132
+ throw new Error("List is empty so cannot peak");
133
+ }
134
+ return this.tail.value;
135
+ }
136
+
137
+ public getFirst(): T {
138
+ if (!this.head){
139
+ throw new Error("List is empty so cannot get first");
140
+ }
141
+ return this.head.value;
142
+ }
143
+
144
+ public removeFirst(): T {
145
+ return this.pop();
146
+ }
147
+
148
+ public removeLast(): T {
149
+ if (!this.tail) {
150
+ throw new Error("List is empty so cannot remove");
151
+ }
152
+ --this.length;
153
+ const v: T = this.tail.value;
154
+ if (this.length == 0) {
155
+ this.head = this.tail = undefined;
156
+ } else {
157
+ const n = this.tail.previous;
158
+ n!.next = undefined;
159
+ this.tail.previous = undefined;
160
+ this.tail = n;
161
+ }
162
+
163
+ return v;
164
+ }
165
+
166
+ public addAll(list: T[]): LinkedList<T> {
167
+ if (!list || !list.length) return this;
168
+ list.forEach(this.add.bind(this));
169
+ return this;
170
+ }
171
+
172
+ public add(t: T): LinkedList<T> {
173
+ ++this.length;
174
+ if (!this.tail && !this.head) {
175
+ this.head = this.tail = new Node(t);
176
+ } else if (this.head === this.tail) {
177
+ this.tail = new Node(t, this.head);
178
+ this.head!.next = this.tail;
179
+ } else {
180
+ this.tail = new Node(t, this.tail);
181
+ this.tail.previous!.next = this.tail;
182
+ }
183
+ return this;
184
+ }
185
+
186
+ public map<U>(
187
+ callbackfn: (value: T, index: number) => U,
188
+ thisArg?: any,
189
+ ): LinkedList<U> {
190
+ let newList: LinkedList<U> = new LinkedList();
191
+
192
+ let x = this.head;
193
+
194
+ let index: number = 0;
195
+ while (x) {
196
+ newList.add(callbackfn(x.value, index));
197
+ x = x.next;
198
+ ++index;
199
+ }
200
+
201
+ return newList;
202
+ }
203
+
204
+ public forEach(callbackfn: (value: T, index: number) => void, thisArg?: any): void {
205
+ let x = this.head;
206
+ let index: number = 0;
207
+ while (x) {
208
+ callbackfn(x.value, index);
209
+ x = x.next;
210
+ ++index;
211
+ }
212
+ }
213
+ }
214
+
215
+ class Node<T> {
216
+ public value: T;
217
+ public next?: Node<T>;
218
+ public previous?: Node<T>;
219
+
220
+ constructor(t: T, previous?: Node<T>, next?: Node<T>) {
221
+ this.value = t;
222
+ this.next = next;
223
+ this.previous = previous;
224
+ }
225
+
226
+ public toString(): string {
227
+ return '' + this.value;
228
+ }
229
+ }
@@ -0,0 +1,86 @@
1
+ import { isNullValue } from './NullCheck';
2
+
3
+ export class MapUtil {
4
+ public static of<K, V>(
5
+ k1?: K,
6
+ v1?: V,
7
+ k2?: K,
8
+ v2?: V,
9
+ k3?: K,
10
+ v3?: V,
11
+ k4?: K,
12
+ v4?: V,
13
+ k5?: K,
14
+ v5?: V,
15
+ k6?: K,
16
+ v6?: V,
17
+ k7?: K,
18
+ v7?: V,
19
+ k8?: K,
20
+ v8?: V,
21
+ k9?: K,
22
+ v9?: V,
23
+ k10?: K,
24
+ v10?: V,
25
+ ): Map<K, V> {
26
+ const map: Map<K, V> = new Map();
27
+
28
+ if (k1 && v1) map.set(k1, v1);
29
+
30
+ if (k2 && v2) map.set(k2, v2);
31
+
32
+ if (k3 && v3) map.set(k3, v3);
33
+
34
+ if (k4 && v4) map.set(k4, v4);
35
+
36
+ if (k5 && v5) map.set(k5, v5);
37
+
38
+ if (k6 && v6) map.set(k6, v6);
39
+
40
+ if (k7 && v7) map.set(k7, v7);
41
+
42
+ if (k8 && v8) map.set(k8, v8);
43
+
44
+ if (k9 && v9) map.set(k9, v9);
45
+
46
+ if (k10 && v10) map.set(k10, v10);
47
+
48
+ return map;
49
+ }
50
+
51
+ public static ofArrayEntries<K, V>(...entry: [K, V][]): Map<K, V> {
52
+ const map: Map<K, V> = new Map();
53
+
54
+ for (const [k, v] of entry) {
55
+ map.set(k, v);
56
+ }
57
+
58
+ return map;
59
+ }
60
+
61
+ public static entry<K, V>(k: K, v: V): MapEntry<K, V> {
62
+ return new MapEntry(k, v);
63
+ }
64
+
65
+ public static ofEntries<K, V>(...entry: MapEntry<K, V>[]): Map<K, V> {
66
+ const map: Map<K, V> = new Map();
67
+
68
+ for (const eachEntry of entry) {
69
+ map.set(eachEntry.k, eachEntry.v);
70
+ }
71
+
72
+ return map;
73
+ }
74
+
75
+ private constructor() {}
76
+ }
77
+
78
+ export class MapEntry<K, V> {
79
+ k: K;
80
+ v: V;
81
+
82
+ public constructor(k: K, v: V) {
83
+ this.k = k;
84
+ this.v = v;
85
+ }
86
+ }
@@ -0,0 +1,3 @@
1
+ export function isNullValue(v: any): boolean {
2
+ return v === null || v === undefined;
3
+ }
@@ -0,0 +1,43 @@
1
+ export class Tuple2<F, S> {
2
+ private f: F;
3
+ private s: S;
4
+
5
+ constructor(f: F, s: S) {
6
+ this.f = f;
7
+ this.s = s;
8
+ }
9
+
10
+ public getT1(): F {
11
+ return this.f;
12
+ }
13
+
14
+ public getT2(): S {
15
+ return this.s;
16
+ }
17
+ }
18
+
19
+ export class Tuple3<F, S, T> extends Tuple2<F, S> {
20
+ private t: T;
21
+
22
+ constructor(f: F, s: S, t: T) {
23
+ super(f, s);
24
+ this.t = t;
25
+ }
26
+
27
+ public getT3(): T {
28
+ return this.t;
29
+ }
30
+ }
31
+
32
+ export class Tuple4<F, S, T, FR> extends Tuple3<F, S, T> {
33
+ private fr: FR;
34
+
35
+ constructor(f: F, s: S, t: T, fr: FR) {
36
+ super(f, s, t);
37
+ this.fr = fr;
38
+ }
39
+
40
+ public getT4(): FR {
41
+ return this.fr;
42
+ }
43
+ }