@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.
- package/.prettierrc +9 -0
- package/__tests__/engine/function/system/array/AddFirstTest.ts +235 -0
- package/__tests__/engine/function/system/array/AddTest.ts +126 -0
- package/__tests__/engine/function/system/array/BinarySearchTest.ts +135 -0
- package/__tests__/engine/function/system/array/CompareTest.ts +48 -0
- package/__tests__/engine/function/system/array/CopyTest.ts +86 -0
- package/__tests__/engine/function/system/array/DeleteFirstTest.ts +103 -0
- package/__tests__/engine/function/system/array/DeleteFromTest.ts +232 -0
- package/__tests__/engine/function/system/array/DeleteLastTest.ts +103 -0
- package/__tests__/engine/function/system/array/DeleteTest.ts +110 -0
- package/__tests__/engine/function/system/array/DisjointTest.ts +184 -0
- package/__tests__/engine/function/system/array/Equals.ts +67 -0
- package/__tests__/engine/function/system/array/FillTest.ts +36 -0
- package/__tests__/engine/function/system/array/FrequencyTest.ts +97 -0
- package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +347 -0
- package/__tests__/engine/function/system/array/IndexOfTest.ts +267 -0
- package/__tests__/engine/function/system/array/InsertTest.ts +229 -0
- package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +213 -0
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +253 -0
- package/__tests__/engine/function/system/array/MaxTest.ts +98 -0
- package/__tests__/engine/function/system/array/MinTest.ts +99 -0
- package/__tests__/engine/function/system/array/MisMatchTest.ts +215 -0
- package/__tests__/engine/function/system/array/ReverseTest.ts +235 -0
- package/__tests__/engine/function/system/array/RotateTest.ts +137 -0
- package/__tests__/engine/function/system/array/ShuffleTest.ts +154 -0
- package/__tests__/engine/function/system/array/SortTest.ts +130 -0
- package/__tests__/engine/function/system/array/SubArrayTest.ts +236 -0
- package/__tests__/engine/function/system/math/AddTest.ts +12 -0
- package/__tests__/engine/function/system/string/ConcatenateTest.ts +46 -0
- package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +38 -0
- package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +53 -0
- package/__tests__/engine/function/system/string/PostPadTest.ts +54 -0
- package/__tests__/engine/function/system/string/PrePadTest.ts +54 -0
- package/__tests__/engine/function/system/string/RegionMatchesTest.ts +78 -0
- package/__tests__/engine/function/system/string/ReverseTest.ts +36 -0
- package/__tests__/engine/function/system/string/SplitTest.ts +61 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +126 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +54 -0
- package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +146 -0
- package/__tests__/engine/function/system/string/ToStringTest.ts +43 -0
- package/__tests__/engine/function/system/string/TrimToTest.ts +28 -0
- package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +26 -0
- package/__tests__/engine/runtime/KIRuntimeTest.ts +351 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +128 -0
- package/__tests__/engine/runtime/expression/ExpressionTest.ts +33 -0
- package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +44 -0
- package/__tests__/engine/runtime/expression/tokenextractor/TokenValueExtractorTest.ts +72 -0
- package/__tests__/engine/util/LinkedListTest.ts +29 -0
- package/__tests__/engine/util/string/StringFormatterTest.ts +17 -0
- package/__tests__/indexTest.ts +33 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +430 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +54 -0
- package/src/engine/HybridRepository.ts +18 -0
- package/src/engine/Repository.ts +3 -0
- package/src/engine/constant/KIRunConstants.ts +7 -0
- package/src/engine/exception/ExecutionException.ts +12 -0
- package/src/engine/exception/KIRuntimeException.ts +12 -0
- package/src/engine/function/AbstractFunction.ts +76 -0
- package/src/engine/function/Function.ts +13 -0
- package/src/engine/function/system/GenerateEvent.ts +76 -0
- package/src/engine/function/system/If.ts +40 -0
- package/src/engine/function/system/array/AbstractArrayFunction.ts +158 -0
- package/src/engine/function/system/array/Add.ts +31 -0
- package/src/engine/function/system/array/AddFirst.ts +44 -0
- package/src/engine/function/system/array/BinarySearch.ts +66 -0
- package/src/engine/function/system/array/Compare.ts +150 -0
- package/src/engine/function/system/array/Copy.ts +56 -0
- package/src/engine/function/system/array/Delete.ts +63 -0
- package/src/engine/function/system/array/DeleteFirst.ts +22 -0
- package/src/engine/function/system/array/DeleteFrom.ts +51 -0
- package/src/engine/function/system/array/DeleteLast.ts +23 -0
- package/src/engine/function/system/array/Disjoint.ts +85 -0
- package/src/engine/function/system/array/Equals.ts +36 -0
- package/src/engine/function/system/array/Fill.ts +51 -0
- package/src/engine/function/system/array/Frequency.ts +68 -0
- package/src/engine/function/system/array/IndexOf.ts +56 -0
- package/src/engine/function/system/array/IndexOfArray.ts +67 -0
- package/src/engine/function/system/array/Insert.ts +48 -0
- package/src/engine/function/system/array/LastIndexOf.ts +62 -0
- package/src/engine/function/system/array/LastIndexOfArray.ts +70 -0
- package/src/engine/function/system/array/Max.ts +31 -0
- package/src/engine/function/system/array/Min.ts +32 -0
- package/src/engine/function/system/array/MisMatch.ts +66 -0
- package/src/engine/function/system/array/Reverse.ts +50 -0
- package/src/engine/function/system/array/Rotate.ts +43 -0
- package/src/engine/function/system/array/Shuffle.ts +31 -0
- package/src/engine/function/system/array/Sort.ts +70 -0
- package/src/engine/function/system/array/SubArray.ts +48 -0
- package/src/engine/function/system/context/Create.ts +73 -0
- package/src/engine/function/system/context/Get.ts +55 -0
- package/src/engine/function/system/context/SetFunction.ts +244 -0
- package/src/engine/function/system/loop/CountLoop.ts +55 -0
- package/src/engine/function/system/loop/RangeLoop.ts +120 -0
- package/src/engine/function/system/math/Add.ts +34 -0
- package/src/engine/function/system/math/GenericMathFunction.ts +80 -0
- package/src/engine/function/system/math/Hypotenuse.ts +57 -0
- package/src/engine/function/system/math/MathFunctionRepository.ts +63 -0
- package/src/engine/function/system/math/Maximum.ts +38 -0
- package/src/engine/function/system/math/Minimum.ts +38 -0
- package/src/engine/function/system/math/Random.ts +27 -0
- package/src/engine/function/system/string/AbstractStringFunction.ts +409 -0
- package/src/engine/function/system/string/Concatenate.ts +57 -0
- package/src/engine/function/system/string/DeleteForGivenLength.ts +82 -0
- package/src/engine/function/system/string/InsertAtGivenPosition.ts +72 -0
- package/src/engine/function/system/string/PostPad.ts +83 -0
- package/src/engine/function/system/string/PrePad.ts +73 -0
- package/src/engine/function/system/string/RegionMatches.ts +119 -0
- package/src/engine/function/system/string/ReplaceAtGivenPosition.ts +101 -0
- package/src/engine/function/system/string/Reverse.ts +62 -0
- package/src/engine/function/system/string/Split.ts +53 -0
- package/src/engine/function/system/string/StringFunctionRepository.ts +60 -0
- package/src/engine/function/system/string/ToString.ts +45 -0
- package/src/engine/function/system/string/TrimTo.ts +55 -0
- package/src/engine/json/JsonExpression.ts +11 -0
- package/src/engine/json/schema/Schema.ts +670 -0
- package/src/engine/json/schema/SchemaUtil.ts +145 -0
- package/src/engine/json/schema/array/ArraySchemaType.ts +44 -0
- package/src/engine/json/schema/object/AdditionalPropertiesType.ts +32 -0
- package/src/engine/json/schema/string/StringFormat.ts +7 -0
- package/src/engine/json/schema/type/MultipleType.ts +28 -0
- package/src/engine/json/schema/type/SchemaType.ts +11 -0
- package/src/engine/json/schema/type/SingleType.ts +23 -0
- package/src/engine/json/schema/type/Type.ts +6 -0
- package/src/engine/json/schema/type/TypeUtil.ts +25 -0
- package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +108 -0
- package/src/engine/json/schema/validator/ArrayValidator.ts +145 -0
- package/src/engine/json/schema/validator/BooleanValidator.ts +24 -0
- package/src/engine/json/schema/validator/NullValidator.ts +17 -0
- package/src/engine/json/schema/validator/NumberValidator.ts +115 -0
- package/src/engine/json/schema/validator/ObjectValidator.ts +184 -0
- package/src/engine/json/schema/validator/SchemaValidator.ts +141 -0
- package/src/engine/json/schema/validator/StringValidator.ts +97 -0
- package/src/engine/json/schema/validator/TypeValidator.ts +49 -0
- package/src/engine/json/schema/validator/exception/SchemaReferenceException.ts +19 -0
- package/src/engine/json/schema/validator/exception/SchemaValidationException.ts +22 -0
- package/src/engine/model/AbstractStatement.ts +29 -0
- package/src/engine/model/Argument.ts +36 -0
- package/src/engine/model/Event.ts +62 -0
- package/src/engine/model/EventResult.ts +34 -0
- package/src/engine/model/FunctionDefinition.ts +69 -0
- package/src/engine/model/FunctionOutput.ts +37 -0
- package/src/engine/model/FunctionOutputGenerator.ts +5 -0
- package/src/engine/model/FunctionSignature.ts +67 -0
- package/src/engine/model/Parameter.ts +97 -0
- package/src/engine/model/ParameterReference.ts +57 -0
- package/src/engine/model/ParameterReferenceType.ts +4 -0
- package/src/engine/model/ParameterType.ts +4 -0
- package/src/engine/model/Position.ts +40 -0
- package/src/engine/model/Statement.ts +101 -0
- package/src/engine/model/StatementGroup.ts +37 -0
- package/src/engine/namespaces/Namespaces.ts +11 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +37 -0
- package/src/engine/repository/KIRunSchemaRepository.ts +24 -0
- package/src/engine/runtime/ContextElement.ts +28 -0
- package/src/engine/runtime/FunctionExecutionParameters.ts +74 -0
- package/src/engine/runtime/KIRuntime.ts +653 -0
- package/src/engine/runtime/StatementExecution.ts +61 -0
- package/src/engine/runtime/StatementMessage.ts +30 -0
- package/src/engine/runtime/StatementMessageType.ts +5 -0
- package/src/engine/runtime/expression/Expression.ts +330 -0
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +305 -0
- package/src/engine/runtime/expression/ExpressionToken.ts +15 -0
- package/src/engine/runtime/expression/ExpressionTokenValue.ts +23 -0
- package/src/engine/runtime/expression/Operation.ts +190 -0
- package/src/engine/runtime/expression/exception/ExpressionEvaluationException.ts +15 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticDivisionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticInetgerDivisionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticModulusOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticMultiplicationOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticSubtractionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArrayOperator.ts +31 -0
- package/src/engine/runtime/expression/operators/binary/BinaryOperator.ts +15 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseAndOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseLeftShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseOrOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseRightShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseUnsignedRightShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseXorOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/LogicalAndOperator.ts +25 -0
- package/src/engine/runtime/expression/operators/binary/LogicalEqualOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanEqualOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalLessThanEqualOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalLessThanOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalNotEqualOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/binary/LogicalOrOperator.ts +25 -0
- package/src/engine/runtime/expression/operators/binary/ObjectOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryMinusOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryPlusOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/unary/BitwiseComplementOperator.ts +22 -0
- package/src/engine/runtime/expression/operators/unary/LogicalNotOperator.ts +22 -0
- package/src/engine/runtime/expression/operators/unary/UnaryOperator.ts +15 -0
- package/src/engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor.ts +64 -0
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +136 -0
- package/src/engine/runtime/graph/ExecutionGraph.ts +81 -0
- package/src/engine/runtime/graph/GraphVertex.ts +118 -0
- package/src/engine/runtime/graph/GraphVertexType.ts +4 -0
- package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +22 -0
- package/src/engine/runtime/tokenextractor/ContextTokenValueExtractor.ts +37 -0
- package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +32 -0
- package/src/engine/util/ArrayUtil.ts +23 -0
- package/src/engine/util/LinkedList.ts +229 -0
- package/src/engine/util/MapUtil.ts +86 -0
- package/src/engine/util/NullCheck.ts +3 -0
- package/src/engine/util/Tuples.ts +43 -0
- package/src/engine/util/primitive/PrimitiveUtil.ts +143 -0
- package/src/engine/util/string/StringBuilder.ts +59 -0
- package/src/engine/util/string/StringFormatter.ts +25 -0
- package/src/engine/util/string/StringUtil.ts +48 -0
- package/src/index.ts +13 -0
- package/tsconfig.json +6 -0
|
@@ -0,0 +1,62 @@
|
|
|
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 LastIndexOf extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super(
|
|
11
|
+
'LastIndexOf',
|
|
12
|
+
[
|
|
13
|
+
LastIndexOf.PARAMETER_ARRAY_SOURCE,
|
|
14
|
+
LastIndexOf.PARAMETER_ANY_NOT_NULL,
|
|
15
|
+
LastIndexOf.PARAMETER_INT_FIND_FROM,
|
|
16
|
+
],
|
|
17
|
+
LastIndexOf.EVENT_RESULT_INTEGER,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
22
|
+
let source: any[] = context
|
|
23
|
+
?.getArguments()
|
|
24
|
+
?.get(LastIndexOf.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
25
|
+
|
|
26
|
+
var find = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(LastIndexOf.PARAMETER_ANY_NOT_NULL.getParameterName());
|
|
29
|
+
|
|
30
|
+
let len = context
|
|
31
|
+
?.getArguments()
|
|
32
|
+
?.get(LastIndexOf.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
33
|
+
|
|
34
|
+
if (source.length == 0)
|
|
35
|
+
return new FunctionOutput([
|
|
36
|
+
EventResult.outputOf(new Map([[LastIndexOf.EVENT_RESULT_INTEGER.getName(), -1]])),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
if (len < 0 || len > source.length)
|
|
40
|
+
throw new KIRuntimeException(
|
|
41
|
+
"The value of length shouldn't the exceed the size of the array or shouldn't be in terms",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
let index: number = -1;
|
|
45
|
+
|
|
46
|
+
if (typeof find == null || typeof find == undefined)
|
|
47
|
+
throw new KIRuntimeException(
|
|
48
|
+
'Please provide the valid find object or primitive in order to verify',
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
for (let i: number = source.length - 1; i >= len; i--) {
|
|
52
|
+
if (PrimitiveUtil.compare(source[i], find) == 0) {
|
|
53
|
+
index = i;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return new FunctionOutput([
|
|
59
|
+
EventResult.outputOf(new Map([[LastIndexOf.EVENT_RESULT_INTEGER.getName(), index]])),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 LastIndexOfArray extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super(
|
|
11
|
+
'LastIndexOfArray',
|
|
12
|
+
[
|
|
13
|
+
LastIndexOfArray.PARAMETER_ARRAY_SOURCE,
|
|
14
|
+
LastIndexOfArray.PARAMETER_ARRAY_SECOND_SOURCE,
|
|
15
|
+
LastIndexOfArray.PARAMETER_INT_FIND_FROM,
|
|
16
|
+
],
|
|
17
|
+
LastIndexOfArray.EVENT_RESULT_INTEGER,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
22
|
+
let source: any[] = context
|
|
23
|
+
?.getArguments()
|
|
24
|
+
?.get(LastIndexOfArray.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
25
|
+
|
|
26
|
+
let secondSource: any[] = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(LastIndexOfArray.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
|
|
29
|
+
|
|
30
|
+
let from: any = context
|
|
31
|
+
?.getArguments()
|
|
32
|
+
?.get(LastIndexOfArray.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
33
|
+
|
|
34
|
+
if (source.length == 0)
|
|
35
|
+
return new FunctionOutput([
|
|
36
|
+
EventResult.outputOf(
|
|
37
|
+
new Map([[LastIndexOfArray.EVENT_RESULT_ARRAY.getName(), -1]]),
|
|
38
|
+
),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
if (from < 0 || from > source.length || secondSource.length > source.length)
|
|
42
|
+
throw new KIRuntimeException(
|
|
43
|
+
'Given from index is more than the size of the source array',
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
let secondSourceSize: number = secondSource.length;
|
|
47
|
+
let index: number = -1;
|
|
48
|
+
|
|
49
|
+
for (let i: number = from; i < source.length; i++) {
|
|
50
|
+
let j: number = 0;
|
|
51
|
+
if (PrimitiveUtil.compare(source[i], secondSource[j]) == 0) {
|
|
52
|
+
while (j < secondSourceSize) {
|
|
53
|
+
if (PrimitiveUtil.compare(source[i + j], secondSource[j]) != 0) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
j++;
|
|
57
|
+
}
|
|
58
|
+
if (j == secondSourceSize) {
|
|
59
|
+
index = i;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return new FunctionOutput([
|
|
65
|
+
EventResult.outputOf(
|
|
66
|
+
new Map([[LastIndexOfArray.EVENT_RESULT_INTEGER.getName(), index]]),
|
|
67
|
+
),
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
7
|
+
|
|
8
|
+
export class Max extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super('Max', [Max.PARAMETER_ARRAY_SOURCE_PRIMITIVE], Max.EVENT_RESULT_ANY);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
14
|
+
let source: any[] = context
|
|
15
|
+
?.getArguments()
|
|
16
|
+
?.get(Max.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName());
|
|
17
|
+
|
|
18
|
+
if (source.length == 0) throw new KIRuntimeException('Search source array cannot be empty');
|
|
19
|
+
|
|
20
|
+
let max: any = source[0];
|
|
21
|
+
for (let i: number = 1; i < source.length; i++) {
|
|
22
|
+
let y: any = source[i];
|
|
23
|
+
if (PrimitiveUtil.comparePrimitive(max, y) >= 0) continue;
|
|
24
|
+
max = y;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return new FunctionOutput([
|
|
28
|
+
EventResult.outputOf(new Map([[Max.EVENT_RESULT_ANY.getName(), max]])),
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
7
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
8
|
+
|
|
9
|
+
export class Min extends AbstractArrayFunction {
|
|
10
|
+
public constructor() {
|
|
11
|
+
super('Min', [Min.PARAMETER_ARRAY_SOURCE_PRIMITIVE], Min.EVENT_RESULT_ANY);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
15
|
+
let source: any[] = context
|
|
16
|
+
?.getArguments()
|
|
17
|
+
?.get(Min.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName());
|
|
18
|
+
|
|
19
|
+
if (source.length == 0) throw new KIRuntimeException('Search source array cannot be empty');
|
|
20
|
+
|
|
21
|
+
let min: any = undefined;
|
|
22
|
+
for (let i: number = 0; i < source.length; i++) {
|
|
23
|
+
if (isNullValue(source[i])) continue;
|
|
24
|
+
if (min === undefined || PrimitiveUtil.comparePrimitive(source[i], min) < 0)
|
|
25
|
+
min = source[i];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new FunctionOutput([
|
|
29
|
+
EventResult.outputOf(new Map([[Min.EVENT_RESULT_ANY.getName(), min]])),
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 MisMatch extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'MisMatch',
|
|
11
|
+
[
|
|
12
|
+
MisMatch.PARAMETER_ARRAY_SOURCE,
|
|
13
|
+
MisMatch.PARAMETER_INT_FIND_FROM,
|
|
14
|
+
MisMatch.PARAMETER_ARRAY_SECOND_SOURCE,
|
|
15
|
+
MisMatch.PARAMETER_INT_SECOND_SOURCE_FROM,
|
|
16
|
+
MisMatch.PARAMETER_INT_LENGTH,
|
|
17
|
+
],
|
|
18
|
+
MisMatch.EVENT_RESULT_INTEGER,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
23
|
+
let firstSource: any[] = context
|
|
24
|
+
?.getArguments()
|
|
25
|
+
?.get(MisMatch.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
26
|
+
|
|
27
|
+
let firstFind: number = context
|
|
28
|
+
?.getArguments()
|
|
29
|
+
?.get(MisMatch.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
30
|
+
|
|
31
|
+
let secondSource: any[] = context
|
|
32
|
+
?.getArguments()
|
|
33
|
+
?.get(MisMatch.PARAMETER_ARRAY_SECOND_SOURCE.getParameterName());
|
|
34
|
+
|
|
35
|
+
let secondFind: number = context
|
|
36
|
+
?.getArguments()
|
|
37
|
+
?.get(MisMatch.PARAMETER_INT_SECOND_SOURCE_FROM.getParameterName());
|
|
38
|
+
|
|
39
|
+
let length: number = context
|
|
40
|
+
?.getArguments()
|
|
41
|
+
?.get(MisMatch.PARAMETER_INT_LENGTH.getParameterName());
|
|
42
|
+
|
|
43
|
+
// write check conditions
|
|
44
|
+
|
|
45
|
+
let first: number = firstFind < firstSource.length && firstFind > 0 ? firstFind : 0;
|
|
46
|
+
let second: number = secondFind < secondSource.length && secondFind > 0 ? secondFind : 0;
|
|
47
|
+
|
|
48
|
+
if (first + length >= firstSource.length || second + length > secondSource.length)
|
|
49
|
+
throw new KIRuntimeException(
|
|
50
|
+
'The size of the array for first and second which was being requested is more than size of the given array',
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let index: number = -1;
|
|
54
|
+
|
|
55
|
+
for (let i: number = 0; i < length; i++) {
|
|
56
|
+
if (firstSource[first + i] != secondSource[second + i]) {
|
|
57
|
+
index = i;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return new FunctionOutput([
|
|
63
|
+
EventResult.outputOf(new Map([[MisMatch.EVENT_RESULT_INTEGER.getName(), index]])),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 Reverse extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'Reverse',
|
|
11
|
+
[
|
|
12
|
+
Reverse.PARAMETER_ARRAY_SOURCE,
|
|
13
|
+
Reverse.PARAMETER_INT_SOURCE_FROM,
|
|
14
|
+
Reverse.PARAMETER_INT_LENGTH,
|
|
15
|
+
],
|
|
16
|
+
Reverse.EVENT_RESULT_EMPTY,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
21
|
+
let source: any[] = context
|
|
22
|
+
?.getArguments()
|
|
23
|
+
?.get(Reverse.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
24
|
+
|
|
25
|
+
let st: number = context
|
|
26
|
+
?.getArguments()
|
|
27
|
+
?.get(Reverse.PARAMETER_INT_SOURCE_FROM.getParameterName());
|
|
28
|
+
|
|
29
|
+
let len: number = context
|
|
30
|
+
?.getArguments()
|
|
31
|
+
?.get(Reverse.PARAMETER_INT_LENGTH.getParameterName());
|
|
32
|
+
|
|
33
|
+
if (len == -1) len = source.length - st;
|
|
34
|
+
|
|
35
|
+
if (len >= source.length || len < 0 || st < 0)
|
|
36
|
+
throw new KIRuntimeException(
|
|
37
|
+
'Please provide start point between the start and end indexes or provide the length which was less than the source size ',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
let endpoint: number = st + len - 1;
|
|
41
|
+
while (st <= endpoint) {
|
|
42
|
+
let first: any = source[st];
|
|
43
|
+
let last: any = source[endpoint];
|
|
44
|
+
source[st++] = last;
|
|
45
|
+
source[endpoint--] = first;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EventResult } from '../../../model/EventResult';
|
|
2
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
3
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
4
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
5
|
+
|
|
6
|
+
export class Rotate extends AbstractArrayFunction {
|
|
7
|
+
public constructor() {
|
|
8
|
+
super(
|
|
9
|
+
'Rotate',
|
|
10
|
+
[Rotate.PARAMETER_ARRAY_SOURCE, Rotate.PARAMETER_ROTATE_LENGTH],
|
|
11
|
+
Rotate.EVENT_RESULT_EMPTY,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
16
|
+
let source: any[] = context
|
|
17
|
+
?.getArguments()
|
|
18
|
+
?.get(Rotate.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
19
|
+
|
|
20
|
+
let rotLen: number = context
|
|
21
|
+
?.getArguments()
|
|
22
|
+
?.get(Rotate.PARAMETER_ROTATE_LENGTH.getParameterName());
|
|
23
|
+
|
|
24
|
+
if (source.length == 0) return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
25
|
+
|
|
26
|
+
let size: number = source.length;
|
|
27
|
+
rotLen = rotLen % size;
|
|
28
|
+
|
|
29
|
+
this.rotate(source, 0, rotLen - 1);
|
|
30
|
+
this.rotate(source, rotLen, size - 1);
|
|
31
|
+
this.rotate(source, 0, size - 1);
|
|
32
|
+
|
|
33
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private rotate(elements: any[], start: number, end: number): void {
|
|
37
|
+
while (start < end) {
|
|
38
|
+
let temp: any = elements[start];
|
|
39
|
+
elements[start++] = elements[end];
|
|
40
|
+
elements[end--] = temp;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EventResult } from '../../../model/EventResult';
|
|
2
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
3
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
4
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
5
|
+
|
|
6
|
+
export class Shuffle extends AbstractArrayFunction {
|
|
7
|
+
public constructor() {
|
|
8
|
+
super('Shuffle', [Shuffle.PARAMETER_ARRAY_SOURCE], Shuffle.EVENT_RESULT_EMPTY);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
12
|
+
let source: any[] = context
|
|
13
|
+
?.getArguments()
|
|
14
|
+
?.get(Shuffle.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
15
|
+
|
|
16
|
+
if (source.length <= 1) return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
17
|
+
|
|
18
|
+
let x: number = 0;
|
|
19
|
+
let size: number = source.length;
|
|
20
|
+
|
|
21
|
+
for (let i: number = 0; i < size; i++) {
|
|
22
|
+
let y: number = Math.floor(Math.random() * size) % size;
|
|
23
|
+
let temp: any = source[x];
|
|
24
|
+
source[x] = source[y];
|
|
25
|
+
source[y] = temp;
|
|
26
|
+
x = y;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
|
|
6
|
+
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
7
|
+
|
|
8
|
+
export class Sort extends AbstractArrayFunction {
|
|
9
|
+
public constructor() {
|
|
10
|
+
super(
|
|
11
|
+
'Sort',
|
|
12
|
+
[
|
|
13
|
+
Sort.PARAMETER_ARRAY_SOURCE_PRIMITIVE,
|
|
14
|
+
Sort.PARAMETER_INT_FIND_FROM,
|
|
15
|
+
Sort.PARAMETER_INT_LENGTH,
|
|
16
|
+
Sort.PARAMETER_BOOLEAN_ASCENDING,
|
|
17
|
+
],
|
|
18
|
+
Sort.EVENT_RESULT_EMPTY,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
23
|
+
let source: any[] = context
|
|
24
|
+
?.getArguments()
|
|
25
|
+
?.get(Sort.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName());
|
|
26
|
+
|
|
27
|
+
let start: number = context
|
|
28
|
+
?.getArguments()
|
|
29
|
+
?.get(Sort.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
30
|
+
|
|
31
|
+
let len: number = context
|
|
32
|
+
?.getArguments()
|
|
33
|
+
?.get(Sort.PARAMETER_INT_LENGTH.getParameterName());
|
|
34
|
+
|
|
35
|
+
let ascending: boolean = context
|
|
36
|
+
?.getArguments()
|
|
37
|
+
?.get(Sort.PARAMETER_BOOLEAN_ASCENDING.getParameterName());
|
|
38
|
+
|
|
39
|
+
if (source.length == 0)
|
|
40
|
+
return new FunctionOutput([
|
|
41
|
+
EventResult.outputOf(new Map([[Sort.EVENT_RESULT_EMPTY.getName(), source]])),
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
if (len == -1) len = source.length - start;
|
|
45
|
+
|
|
46
|
+
if (start < 0 || start >= source.length || start + len > source.length)
|
|
47
|
+
throw new KIRuntimeException(
|
|
48
|
+
'Given start point is more than the size of the array or not available at that point',
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let slicedArray: any[] = source.slice(start, start + len + 1);
|
|
52
|
+
|
|
53
|
+
slicedArray.sort((a, b) => compareFunction(a, b, ascending));
|
|
54
|
+
|
|
55
|
+
source.splice(start, len, ...slicedArray);
|
|
56
|
+
|
|
57
|
+
return new FunctionOutput([
|
|
58
|
+
EventResult.outputOf(new Map([[Sort.EVENT_RESULT_EMPTY.getName(), source]])),
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function compareFunction(a: any, b: any, ascending: boolean): number {
|
|
64
|
+
if (a === b) return 0;
|
|
65
|
+
if (a === null) return 1;
|
|
66
|
+
if (b === null) return -1;
|
|
67
|
+
if (!ascending) return a < b ? -1 : 1;
|
|
68
|
+
|
|
69
|
+
return a < b ? 1 : -1;
|
|
70
|
+
}
|
|
@@ -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 { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
6
|
+
|
|
7
|
+
export class SubArray extends AbstractArrayFunction {
|
|
8
|
+
public constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'SubArray',
|
|
11
|
+
[
|
|
12
|
+
SubArray.PARAMETER_ARRAY_SOURCE,
|
|
13
|
+
SubArray.PARAMETER_INT_FIND_FROM,
|
|
14
|
+
SubArray.PARAMETER_INT_LENGTH,
|
|
15
|
+
],
|
|
16
|
+
SubArray.EVENT_RESULT_ARRAY,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
21
|
+
let source: any[] = context
|
|
22
|
+
?.getArguments()
|
|
23
|
+
?.get(SubArray.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
24
|
+
|
|
25
|
+
let start: number = context
|
|
26
|
+
?.getArguments()
|
|
27
|
+
?.get(SubArray.PARAMETER_INT_FIND_FROM.getParameterName());
|
|
28
|
+
|
|
29
|
+
let len: number = context
|
|
30
|
+
?.getArguments()
|
|
31
|
+
?.get(SubArray.PARAMETER_INT_LENGTH.getParameterName());
|
|
32
|
+
|
|
33
|
+
if (len == -1) len = source.length - start;
|
|
34
|
+
|
|
35
|
+
if (len <= 0) return new FunctionOutput([EventResult.outputOf(new Map([]))]);
|
|
36
|
+
|
|
37
|
+
if (!(start >= 0 && start < source.length) || start + len > source.length)
|
|
38
|
+
throw new KIRuntimeException(
|
|
39
|
+
'Given find from point is more than the source size array or the Requested length for the subarray was more than the source size',
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
let slicedArray: any[] = source.slice(start, start + len);
|
|
43
|
+
|
|
44
|
+
return new FunctionOutput([
|
|
45
|
+
EventResult.outputOf(new Map([[SubArray.EVENT_RESULT_ARRAY.getName(), slicedArray]])),
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
3
|
+
import { StringFormat } from '../../../json/schema/string/StringFormat';
|
|
4
|
+
import { SchemaType } from '../../../json/schema/type/SchemaType';
|
|
5
|
+
import { TypeUtil } from '../../../json/schema/type/TypeUtil';
|
|
6
|
+
import { Event } from '../../../model/Event';
|
|
7
|
+
import { EventResult } from '../../../model/EventResult';
|
|
8
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
9
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
10
|
+
import { Parameter } from '../../../model/Parameter';
|
|
11
|
+
import { ParameterType } from '../../../model/ParameterType';
|
|
12
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
13
|
+
import { ContextElement } from '../../../runtime/ContextElement';
|
|
14
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
15
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
16
|
+
import { StringFormatter } from '../../../util/string/StringFormatter';
|
|
17
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
18
|
+
|
|
19
|
+
const NAME = 'name';
|
|
20
|
+
const SCHEMA = 'schema';
|
|
21
|
+
|
|
22
|
+
const SIGNATURE: FunctionSignature = new FunctionSignature('Create')
|
|
23
|
+
.setNamespace(Namespaces.SYSTEM_CTX)
|
|
24
|
+
.setParameters(
|
|
25
|
+
new Map([
|
|
26
|
+
Parameter.ofEntry(
|
|
27
|
+
NAME,
|
|
28
|
+
new Schema()
|
|
29
|
+
.setName(NAME)
|
|
30
|
+
.setType(TypeUtil.of(SchemaType.STRING))
|
|
31
|
+
.setMinLength(1)
|
|
32
|
+
.setFormat(StringFormat.REGEX)
|
|
33
|
+
.setPattern('^[a-zA-Z_$][a-zA-Z_$0-9]*$'),
|
|
34
|
+
false,
|
|
35
|
+
ParameterType.CONSTANT,
|
|
36
|
+
),
|
|
37
|
+
Parameter.ofEntry(SCHEMA, Schema.SCHEMA, false, ParameterType.CONSTANT),
|
|
38
|
+
]),
|
|
39
|
+
)
|
|
40
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map())]));
|
|
41
|
+
|
|
42
|
+
export class Create extends AbstractFunction {
|
|
43
|
+
public getSignature(): FunctionSignature {
|
|
44
|
+
return SIGNATURE;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
48
|
+
const name: string = context?.getArguments()?.get(NAME);
|
|
49
|
+
|
|
50
|
+
if (context?.getContext()?.has(name))
|
|
51
|
+
throw new KIRuntimeException(
|
|
52
|
+
StringFormatter.format("Context already has an element for '$' ", name),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
let s: Schema | undefined = Schema.from(context?.getArguments()?.get(SCHEMA));
|
|
56
|
+
|
|
57
|
+
if (!s) {
|
|
58
|
+
throw new KIRuntimeException('Schema is not supplied.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
context
|
|
62
|
+
.getContext()!
|
|
63
|
+
.set(
|
|
64
|
+
name,
|
|
65
|
+
new ContextElement(
|
|
66
|
+
s,
|
|
67
|
+
isNullValue(s.getDefaultValue()) ? undefined : s.getDefaultValue(),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return new FunctionOutput([EventResult.outputOf(new Map())]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
2
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
3
|
+
import { StringFormat } from '../../../json/schema/string/StringFormat';
|
|
4
|
+
import { SchemaType } from '../../../json/schema/type/SchemaType';
|
|
5
|
+
import { TypeUtil } from '../../../json/schema/type/TypeUtil';
|
|
6
|
+
import { Event } from '../../../model/Event';
|
|
7
|
+
import { EventResult } from '../../../model/EventResult';
|
|
8
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
9
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
10
|
+
import { Parameter } from '../../../model/Parameter';
|
|
11
|
+
import { ParameterType } from '../../../model/ParameterType';
|
|
12
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
13
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
14
|
+
import { StringFormatter } from '../../../util/string/StringFormatter';
|
|
15
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
16
|
+
|
|
17
|
+
const NAME = 'name';
|
|
18
|
+
const VALUE = 'value';
|
|
19
|
+
const SIGNATURE = new FunctionSignature('Get')
|
|
20
|
+
.setNamespace(Namespaces.SYSTEM_CTX)
|
|
21
|
+
.setParameters(
|
|
22
|
+
new Map([
|
|
23
|
+
Parameter.ofEntry(
|
|
24
|
+
NAME,
|
|
25
|
+
new Schema()
|
|
26
|
+
.setName(NAME)
|
|
27
|
+
.setType(TypeUtil.of(SchemaType.STRING))
|
|
28
|
+
.setMinLength(1)
|
|
29
|
+
.setFormat(StringFormat.REGEX)
|
|
30
|
+
.setPattern('^[a-zA-Z_$][a-zA-Z_$0-9]*$'),
|
|
31
|
+
false,
|
|
32
|
+
ParameterType.CONSTANT,
|
|
33
|
+
),
|
|
34
|
+
]),
|
|
35
|
+
)
|
|
36
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofAny(VALUE)]]))]));
|
|
37
|
+
|
|
38
|
+
export class Get extends AbstractFunction {
|
|
39
|
+
public getSignature(): FunctionSignature {
|
|
40
|
+
return SIGNATURE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
44
|
+
const name: string = context?.getArguments()?.get(NAME);
|
|
45
|
+
|
|
46
|
+
if (!context.getContext()?.has(name))
|
|
47
|
+
throw new KIRuntimeException(
|
|
48
|
+
StringFormatter.format("Context don't have an element for '$' ", name),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return new FunctionOutput([
|
|
52
|
+
EventResult.outputOf(new Map([VALUE, context.getContext()?.get(name)?.getElement()])),
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
}
|