@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,56 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { MapUtil } from '../../../util/MapUtil';
6
+ import { isNullValue } from '../../../util/NullCheck';
7
+ import { StringFormatter } from '../../../util/string/StringFormatter';
8
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
9
+
10
+ export class Copy extends AbstractArrayFunction {
11
+ public constructor() {
12
+ super(
13
+ 'Copy',
14
+ [
15
+ Copy.PARAMETER_ARRAY_SOURCE,
16
+ Copy.PARAMETER_INT_SOURCE_FROM,
17
+ Copy.PARAMETER_INT_LENGTH,
18
+ Copy.PARAMETER_BOOLEAN_DEEP_COPY,
19
+ ],
20
+ Copy.EVENT_RESULT_ARRAY,
21
+ );
22
+ }
23
+
24
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
25
+ var source = context?.getArguments()?.get(Copy.PARAMETER_ARRAY_SOURCE.getParameterName());
26
+ var srcfrom = context
27
+ ?.getArguments()
28
+ ?.get(Copy.PARAMETER_INT_SOURCE_FROM.getParameterName());
29
+ var length = context?.getArguments()?.get(Copy.PARAMETER_INT_LENGTH.getParameterName());
30
+
31
+ if (length == -1) length = source.length - srcfrom;
32
+
33
+ if (srcfrom + length > source.length)
34
+ throw new KIRuntimeException(
35
+ StringFormatter.format(
36
+ 'Array has no elements from $ to $ as the array size is $',
37
+ srcfrom,
38
+ srcfrom + length,
39
+ source.length,
40
+ ),
41
+ );
42
+
43
+ var deep = context
44
+ ?.getArguments()
45
+ ?.get(Copy.PARAMETER_BOOLEAN_DEEP_COPY.getParameterName());
46
+
47
+ const ja: any[] = new Array(length);
48
+
49
+ for (let i = srcfrom; i < srcfrom + length; i++) {
50
+ if (!isNullValue(source[i]))
51
+ ja[i - srcfrom] = deep ? JSON.parse(JSON.stringify(source[i])) : source[i];
52
+ }
53
+
54
+ return new FunctionOutput([EventResult.outputOf(MapUtil.of(Copy.EVENT_RESULT_NAME, ja))]);
55
+ }
56
+ }
@@ -0,0 +1,63 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
+
7
+ export class Delete extends AbstractArrayFunction {
8
+ public constructor() {
9
+ super(
10
+ 'Delete',
11
+ [
12
+ AbstractArrayFunction.PARAMETER_ARRAY_SOURCE_PRIMITIVE,
13
+ AbstractArrayFunction.PARAMETER_ARRAY_SECOND_SOURCE,
14
+ ],
15
+ AbstractArrayFunction.EVENT_RESULT_EMPTY,
16
+ );
17
+ }
18
+
19
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
20
+ let source: any[] = context
21
+ ?.getArguments()
22
+ ?.get(Delete.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName());
23
+
24
+ let deletable: any[] = context
25
+ ?.getArguments()
26
+ ?.get(Delete.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
27
+
28
+ if (source.length == 0 || deletable.length == 0 || deletable.length > source.length)
29
+ throw new KIRuntimeException(
30
+ 'Expected a source or deletable for an array but not found any or the deletable size of the array is more than the source array',
31
+ );
32
+
33
+ let deletableSize: number = deletable.length;
34
+
35
+ let index: number = -1;
36
+
37
+ for (let i = 0; i < source.length; i++) {
38
+ let j: number = 0;
39
+ if (source[i] !== null && deletable[j] !== null && source[i] == deletable[j]) {
40
+ while (j < deletableSize) {
41
+ if (
42
+ source[i] == null ||
43
+ deletable[j] == null ||
44
+ source[i + j] != deletable[j]
45
+ ) {
46
+ break;
47
+ }
48
+ j++;
49
+ }
50
+ if (j == deletableSize) {
51
+ index = i;
52
+ break;
53
+ }
54
+ }
55
+ }
56
+
57
+ if (index != -1) {
58
+ source.splice(index, deletableSize);
59
+ }
60
+
61
+ return new FunctionOutput([EventResult.outputOf(new Map([]))]);
62
+ }
63
+ }
@@ -0,0 +1,22 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
+
7
+ export class DeleteFirst extends AbstractArrayFunction {
8
+ public constructor() {
9
+ super('DeleteFirst', [DeleteFirst.PARAMETER_ARRAY_SOURCE], DeleteFirst.EVENT_RESULT_EMPTY);
10
+ }
11
+
12
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
13
+ let source: any[] = context
14
+ ?.getArguments()
15
+ ?.get(DeleteFirst.PARAMETER_ARRAY_SOURCE.getParameterName());
16
+
17
+ if (source.length == 0) throw new KIRuntimeException('Given source array is empty');
18
+
19
+ source.shift();
20
+ return new FunctionOutput([EventResult.outputOf(new Map([]))]);
21
+ }
22
+ }
@@ -0,0 +1,51 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
+
7
+ export class DeleteFrom extends AbstractArrayFunction {
8
+ public constructor() {
9
+ super(
10
+ 'DeleteFrom',
11
+ [
12
+ DeleteFrom.PARAMETER_ARRAY_SOURCE,
13
+ DeleteFrom.PARAMETER_INT_SOURCE_FROM,
14
+ DeleteFrom.PARAMETER_INT_LENGTH,
15
+ ],
16
+ DeleteFrom.EVENT_RESULT_EMPTY,
17
+ );
18
+ }
19
+
20
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
21
+ let source: any[] = context
22
+ ?.getArguments()
23
+ ?.get(DeleteFrom.PARAMETER_ARRAY_SOURCE.getParameterName());
24
+
25
+ let start: number = context
26
+ ?.getArguments()
27
+ ?.get(DeleteFrom.PARAMETER_INT_SOURCE_FROM.getParameterName());
28
+
29
+ let len: number = context
30
+ ?.getArguments()
31
+ ?.get(DeleteFrom.PARAMETER_INT_LENGTH.getParameterName());
32
+
33
+ if (source.length == 0) throw new KIRuntimeException('There are no elements to be deleted');
34
+
35
+ if (start >= source.length || start < 0)
36
+ throw new KIRuntimeException(
37
+ 'The int source for the array should be in between 0 and length of the array ',
38
+ );
39
+
40
+ if (len == -1) len = source.length - start;
41
+
42
+ if (start + len > source.length)
43
+ throw new KIRuntimeException(
44
+ 'Requested length to be deleted is more than the size of array ',
45
+ );
46
+
47
+ source.splice(start, len);
48
+
49
+ return new FunctionOutput([EventResult.outputOf(new Map([]))]);
50
+ }
51
+ }
@@ -0,0 +1,23 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
+
7
+ export class DeleteLast extends AbstractArrayFunction {
8
+ public constructor() {
9
+ super('DeleteLast', [DeleteLast.PARAMETER_ARRAY_SOURCE], DeleteLast.EVENT_RESULT_EMPTY);
10
+ }
11
+
12
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
13
+ let source: any[] = context
14
+ ?.getArguments()
15
+ ?.get(DeleteLast.PARAMETER_ARRAY_SOURCE.getParameterName());
16
+
17
+ if (source.length == 0) throw new KIRuntimeException('Given source array is empty');
18
+
19
+ source.pop();
20
+
21
+ return new FunctionOutput([EventResult.outputOf(new Map([]))]);
22
+ }
23
+ }
@@ -0,0 +1,85 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
+
7
+ export class Disjoint extends AbstractArrayFunction {
8
+ public constructor() {
9
+ super(
10
+ 'Disjoint',
11
+ [
12
+ Disjoint.PARAMETER_ARRAY_SOURCE,
13
+ Disjoint.PARAMETER_INT_SOURCE_FROM,
14
+ Disjoint.PARAMETER_ARRAY_SECOND_SOURCE,
15
+ Disjoint.PARAMETER_INT_SECOND_SOURCE_FROM,
16
+ Disjoint.PARAMETER_INT_LENGTH,
17
+ ],
18
+ Disjoint.EVENT_RESULT_ARRAY,
19
+ );
20
+ }
21
+
22
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
23
+ let firstSource: any[] = context
24
+ ?.getArguments()
25
+ ?.get(Disjoint.PARAMETER_ARRAY_SOURCE.getParameterName());
26
+
27
+ let first: number = context
28
+ ?.getArguments()
29
+ ?.get(Disjoint.PARAMETER_INT_SOURCE_FROM.getParameterName());
30
+
31
+ let secondSource: any[] = context
32
+ ?.getArguments()
33
+ ?.get(Disjoint.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
34
+
35
+ let second: number = context
36
+ ?.getArguments()
37
+ ?.get(Disjoint.PARAMETER_INT_SECOND_SOURCE_FROM.getParameterName());
38
+
39
+ let len: number = context
40
+ ?.getArguments()
41
+ ?.get(Disjoint.PARAMETER_INT_LENGTH.getParameterName());
42
+
43
+ if (len == -1)
44
+ len =
45
+ firstSource.length <= secondSource.length
46
+ ? firstSource.length - first
47
+ : secondSource.length - second;
48
+
49
+ if (
50
+ len > firstSource.length ||
51
+ len > secondSource.length ||
52
+ first + len > firstSource.length ||
53
+ second + len > secondSource.length
54
+ )
55
+ throw new KIRuntimeException(
56
+ 'The length which was being requested is more than than the size either source array or second source array',
57
+ );
58
+
59
+ let set1: Set<any> = new Set<any>();
60
+ let set2: Set<any> = new Set<any>();
61
+
62
+ for (let i: number = 0; i < len; i++) set1.add(firstSource[i + first]);
63
+
64
+ for (let i: number = 0; i < len; i++) set2.add(secondSource[i + second]);
65
+
66
+ let set3: Set<any> = new Set<any>();
67
+
68
+ set1.forEach((element) => {
69
+ if (set2.has(element)) set2.delete(element);
70
+ else set3.add(element);
71
+ });
72
+
73
+ set2.forEach((element) => {
74
+ if (!set1.has(element)) set3.add(element);
75
+ });
76
+
77
+ let disjointArray: any[] = [];
78
+
79
+ set3.forEach((element) => disjointArray.push(element));
80
+
81
+ return new FunctionOutput([
82
+ EventResult.outputOf(new Map([[Disjoint.EVENT_RESULT_ARRAY.getName(), disjointArray]])),
83
+ ]);
84
+ }
85
+ }
@@ -0,0 +1,36 @@
1
+ import { EventResult } from '../../../model/EventResult';
2
+ import { FunctionOutput } from '../../../model/FunctionOutput';
3
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
4
+ import { MapUtil } from '../../../util/MapUtil';
5
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
6
+ import { Compare } from './Compare';
7
+
8
+ export class Equals extends AbstractArrayFunction {
9
+ public constructor() {
10
+ super(
11
+ 'Equals',
12
+ [
13
+ Equals.PARAMETER_ARRAY_SOURCE,
14
+ Equals.PARAMETER_INT_SOURCE_FROM,
15
+ Equals.PARAMETER_ARRAY_FIND,
16
+ Equals.PARAMETER_INT_FIND_FROM,
17
+ Equals.PARAMETER_INT_LENGTH,
18
+ ],
19
+ Equals.EVENT_RESULT_BOOLEAN,
20
+ );
21
+ }
22
+
23
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
24
+ let compare: Compare = new Compare();
25
+
26
+ let fo: FunctionOutput = compare.execute(context);
27
+
28
+ let resultMap: Map<string, any> = fo.allResults()[0].getResult();
29
+
30
+ let v: number = resultMap.get(Equals.EVENT_RESULT_NAME);
31
+
32
+ return new FunctionOutput([
33
+ EventResult.outputOf(MapUtil.of(Equals.EVENT_RESULT_NAME, v == 0)),
34
+ ]);
35
+ }
36
+ }
@@ -0,0 +1,51 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { MapUtil } from '../../../util/MapUtil';
6
+ import { isNullValue } from '../../../util/NullCheck';
7
+ import { StringFormatter } from '../../../util/string/StringFormatter';
8
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
9
+
10
+ export class Fill extends AbstractArrayFunction {
11
+ public constructor() {
12
+ super(
13
+ 'Fill',
14
+ [
15
+ Fill.PARAMETER_ARRAY_SOURCE,
16
+ Fill.PARAMETER_INT_SOURCE_FROM,
17
+ Fill.PARAMETER_INT_LENGTH,
18
+ Fill.PARAMETER_ANY,
19
+ ],
20
+ Fill.EVENT_RESULT_EMPTY,
21
+ );
22
+ }
23
+
24
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
25
+ var source = context?.getArguments()?.get(Fill.PARAMETER_ARRAY_SOURCE.getParameterName());
26
+ var srcfrom = context
27
+ ?.getArguments()
28
+ ?.get(Fill.PARAMETER_INT_SOURCE_FROM.getParameterName());
29
+ var length = context?.getArguments()?.get(Fill.PARAMETER_INT_LENGTH.getParameterName());
30
+ var element = context?.getArguments()?.get(Fill.PARAMETER_ANY.getParameterName());
31
+
32
+ if (srcfrom < 0)
33
+ throw new KIRuntimeException(
34
+ StringFormatter.format('Arrays out of bound trying to access $ index', srcfrom),
35
+ );
36
+
37
+ if (length == -1) length = source.length - srcfrom;
38
+
39
+ let add = srcfrom + length - source.length;
40
+
41
+ if (add > 0) {
42
+ for (let i = 0; i < add; i++) source.push();
43
+ }
44
+
45
+ for (let i = srcfrom; i < srcfrom + length; i++) {
46
+ source[i] = isNullValue(element) ? element : JSON.parse(JSON.stringify(element));
47
+ }
48
+
49
+ return new FunctionOutput([EventResult.outputOf(MapUtil.of())]);
50
+ }
51
+ }
@@ -0,0 +1,68 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { isNullValue } from '../../../util/NullCheck';
6
+ import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
7
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
8
+
9
+ export class Frequency extends AbstractArrayFunction {
10
+ FunctionOutput: any;
11
+
12
+ public constructor() {
13
+ super(
14
+ 'Frequency',
15
+ [
16
+ Frequency.PARAMETER_ARRAY_SOURCE,
17
+ Frequency.PARAMETER_ANY,
18
+ Frequency.PARAMETER_INT_SOURCE_FROM,
19
+ Frequency.PARAMETER_INT_LENGTH,
20
+ ],
21
+ Frequency.EVENT_RESULT_INTEGER,
22
+ );
23
+ }
24
+
25
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
26
+ let source: any[] = context
27
+ ?.getArguments()
28
+ ?.get(Frequency.PARAMETER_ARRAY_SOURCE.getParameterName());
29
+
30
+ let find: any = context?.getArguments()?.get(Frequency.PARAMETER_ANY.getParameterName());
31
+
32
+ let start: number = context
33
+ ?.getArguments()
34
+ ?.get(Frequency.PARAMETER_INT_SOURCE_FROM.getParameterName());
35
+
36
+ let length: number = context
37
+ ?.getArguments()
38
+ ?.get(Frequency.PARAMETER_INT_LENGTH.getParameterName());
39
+
40
+ if (source.length == 0)
41
+ return new FunctionOutput([
42
+ EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_INTEGER.getName(), 0]])),
43
+ ]);
44
+
45
+ if (start > source.length)
46
+ throw new KIRuntimeException('Given start point is more than the size of source');
47
+
48
+ if (isNullValue(find))
49
+ throw new KIRuntimeException('Given find was null. Hence cannot be found in the array');
50
+
51
+ let end: number = start + length;
52
+
53
+ if (length == -1) end = source.length - start;
54
+
55
+ if (end > source.length)
56
+ throw new KIRuntimeException('Given length is more than the size of source');
57
+
58
+ let frequency: number = 0;
59
+
60
+ for (let i: number = start; i < end && i < source.length; i++) {
61
+ if (PrimitiveUtil.compare(source[i], find) == 0) frequency++;
62
+ }
63
+
64
+ return new FunctionOutput([
65
+ EventResult.outputOf(new Map([[Frequency.EVENT_RESULT_INTEGER.getName(), frequency]])),
66
+ ]);
67
+ }
68
+ }
@@ -0,0 +1,56 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { isNullValue } from '../../../util/NullCheck';
6
+ import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
7
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
8
+
9
+ export class IndexOf extends AbstractArrayFunction {
10
+ public constructor() {
11
+ super(
12
+ 'IndexOf',
13
+ [
14
+ IndexOf.PARAMETER_ARRAY_SOURCE,
15
+ IndexOf.PARAMETER_ANY_NOT_NULL,
16
+ IndexOf.PARAMETER_INT_FIND_FROM,
17
+ ],
18
+ IndexOf.EVENT_RESULT_INTEGER,
19
+ );
20
+ }
21
+
22
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
23
+ let source: any[] = context
24
+ ?.getArguments()
25
+ ?.get(IndexOf.PARAMETER_ARRAY_SOURCE.getParameterName());
26
+
27
+ var find = context?.getArguments()?.get(IndexOf.PARAMETER_ANY_NOT_NULL.getParameterName());
28
+
29
+ let len: number = context
30
+ ?.getArguments()
31
+ ?.get(IndexOf.PARAMETER_INT_FIND_FROM.getParameterName());
32
+
33
+ if (source.length == 0)
34
+ return new FunctionOutput([
35
+ EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_INTEGER.getName(), -1]])),
36
+ ]);
37
+
38
+ if (len < 0 || len > source.length)
39
+ throw new KIRuntimeException(
40
+ 'The size of the search index of the array is greater than the size of the array',
41
+ );
42
+
43
+ let index: number = -1;
44
+
45
+ for (let i: number = len; i < source.length; i++) {
46
+ if (PrimitiveUtil.compare(source[i], find) == 0) {
47
+ index = i;
48
+ break;
49
+ }
50
+ }
51
+
52
+ return new FunctionOutput([
53
+ EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_INTEGER.getName(), index]])),
54
+ ]);
55
+ }
56
+ }
@@ -0,0 +1,67 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
6
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
7
+
8
+ export class IndexOfArray extends AbstractArrayFunction {
9
+ public constructor() {
10
+ super(
11
+ 'IndexOfArray',
12
+ [
13
+ IndexOfArray.PARAMETER_ARRAY_SOURCE,
14
+ IndexOfArray.PARAMETER_ARRAY_SECOND_SOURCE,
15
+ IndexOfArray.PARAMETER_INT_FIND_FROM,
16
+ ],
17
+ IndexOfArray.EVENT_RESULT_INTEGER,
18
+ );
19
+ }
20
+
21
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
22
+ let source: any[] = context
23
+ ?.getArguments()
24
+ ?.get(IndexOfArray.PARAMETER_ARRAY_SOURCE.getParameterName());
25
+
26
+ let secondSource: any[] = context
27
+ ?.getArguments()
28
+ ?.get(IndexOfArray.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
29
+
30
+ let from: number = context
31
+ ?.getArguments()
32
+ ?.get(IndexOfArray.PARAMETER_INT_FIND_FROM.getParameterName());
33
+
34
+ if (source.length == 0 || secondSource.length == 0)
35
+ return new FunctionOutput([
36
+ EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_INTEGER.getName(), -1]])),
37
+ ]);
38
+
39
+ if (from < 0 || from > source.length || source.length < secondSource.length)
40
+ throw new KIRuntimeException(
41
+ 'Given from second source is more than the size of the source array',
42
+ );
43
+
44
+ let secondSourceSize: number = secondSource.length;
45
+ let index: number = -1;
46
+
47
+ for (let i: number = from; i < source.length; i++) {
48
+ let j: number = 0;
49
+ if (PrimitiveUtil.compare(source[i], secondSource[j]) == 0) {
50
+ while (j < secondSourceSize) {
51
+ if (PrimitiveUtil.compare(source[i + j], secondSource[j]) != 0) {
52
+ break;
53
+ }
54
+ j++;
55
+ }
56
+ if (j == secondSourceSize) {
57
+ index = i;
58
+ break;
59
+ }
60
+ }
61
+ }
62
+
63
+ return new FunctionOutput([
64
+ EventResult.outputOf(new Map([[IndexOfArray.EVENT_RESULT_INTEGER.getName(), index]])),
65
+ ]);
66
+ }
67
+ }
@@ -0,0 +1,48 @@
1
+ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
5
+ import { isNullValue } from '../../../util/NullCheck';
6
+ import { AbstractArrayFunction } from './AbstractArrayFunction';
7
+
8
+ export class Insert extends AbstractArrayFunction {
9
+ public constructor() {
10
+ super(
11
+ 'Insert',
12
+ [Insert.PARAMETER_ARRAY_SOURCE, Insert.PARAMETER_INT_OFFSET, Insert.PARAMETER_ANY],
13
+ Insert.EVENT_RESULT_EMPTY,
14
+ );
15
+ }
16
+
17
+ protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
18
+ let source: any[] = context
19
+ ?.getArguments()
20
+ ?.get(Insert.PARAMETER_ARRAY_SOURCE.getParameterName());
21
+
22
+ let offset: number = context
23
+ ?.getArguments()
24
+ ?.get(Insert.PARAMETER_INT_OFFSET.getParameterName());
25
+
26
+ var output = context?.getArguments()?.get(Insert.PARAMETER_ANY.getParameterName());
27
+
28
+ if (isNullValue(output) || isNullValue(offset) || offset > source.length)
29
+ throw new KIRuntimeException('Please valid resouces to insert at the correct location');
30
+
31
+ if (source.length == 0) {
32
+ if (offset == 0) source.push(output);
33
+ return new FunctionOutput([EventResult.outputOf(new Map([]))]);
34
+ }
35
+
36
+ source.push(output);
37
+ let len: number = source.length - 1;
38
+ offset++; // to insert at that point
39
+
40
+ while (len >= offset) {
41
+ let temp: any = source[len - 1];
42
+ source[len - 1] = source[len];
43
+ source[len--] = temp;
44
+ }
45
+
46
+ return new FunctionOutput([EventResult.outputOf(new Map([]))]);
47
+ }
48
+ }