@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,38 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { Event } from '../../../model/Event';
|
|
3
|
+
import { EventResult } from '../../../model/EventResult';
|
|
4
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
6
|
+
import { Parameter } from '../../../model/Parameter';
|
|
7
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
8
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
9
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
10
|
+
|
|
11
|
+
const VALUE = 'value';
|
|
12
|
+
|
|
13
|
+
const SIGNATURE = new FunctionSignature('Maximum')
|
|
14
|
+
.setNamespace(Namespaces.MATH)
|
|
15
|
+
.setParameters(
|
|
16
|
+
new Map([
|
|
17
|
+
[VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE)).setVariableArgument(true)],
|
|
18
|
+
]),
|
|
19
|
+
)
|
|
20
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofNumber(VALUE)]]))]));
|
|
21
|
+
|
|
22
|
+
export class Maximum extends AbstractFunction {
|
|
23
|
+
public getSignature(): FunctionSignature {
|
|
24
|
+
return SIGNATURE;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
28
|
+
let nums: number[] = context.getArguments()?.get(VALUE);
|
|
29
|
+
|
|
30
|
+
return new FunctionOutput([
|
|
31
|
+
EventResult.outputOf(
|
|
32
|
+
new Map([
|
|
33
|
+
[VALUE, Math.sqrt(nums.reduce((a, c) => ((!a && a !== 0) || c > a ? c : a)))],
|
|
34
|
+
]),
|
|
35
|
+
),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { Event } from '../../../model/Event';
|
|
3
|
+
import { EventResult } from '../../../model/EventResult';
|
|
4
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
6
|
+
import { Parameter } from '../../../model/Parameter';
|
|
7
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
8
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
9
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
10
|
+
|
|
11
|
+
const VALUE = 'value';
|
|
12
|
+
|
|
13
|
+
const SIGNATURE = new FunctionSignature('Minimum')
|
|
14
|
+
.setNamespace(Namespaces.MATH)
|
|
15
|
+
.setParameters(
|
|
16
|
+
new Map([
|
|
17
|
+
[VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE)).setVariableArgument(true)],
|
|
18
|
+
]),
|
|
19
|
+
)
|
|
20
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofNumber(VALUE)]]))]));
|
|
21
|
+
|
|
22
|
+
export class Minimum extends AbstractFunction {
|
|
23
|
+
public getSignature(): FunctionSignature {
|
|
24
|
+
return SIGNATURE;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
28
|
+
let nums: number[] = context.getArguments()?.get(VALUE);
|
|
29
|
+
|
|
30
|
+
return new FunctionOutput([
|
|
31
|
+
EventResult.outputOf(
|
|
32
|
+
new Map([
|
|
33
|
+
[VALUE, Math.sqrt(nums.reduce((a, c) => ((!a && a !== 0) || c < a ? c : a)))],
|
|
34
|
+
]),
|
|
35
|
+
),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { Event } from '../../../model/Event';
|
|
3
|
+
import { EventResult } from '../../../model/EventResult';
|
|
4
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
6
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
7
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
8
|
+
import { MapUtil } from '../../../util/MapUtil';
|
|
9
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
10
|
+
|
|
11
|
+
const VALUE = 'value';
|
|
12
|
+
export class Random extends AbstractFunction {
|
|
13
|
+
private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Random')
|
|
14
|
+
.setNamespace(Namespaces.MATH)
|
|
15
|
+
.setEvents(
|
|
16
|
+
new Map<string, Event>([
|
|
17
|
+
Event.outputEventMapEntry(MapUtil.of(VALUE, Schema.ofDouble(VALUE))),
|
|
18
|
+
]),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
public getSignature(): FunctionSignature {
|
|
22
|
+
return Random.SIGNATURE;
|
|
23
|
+
}
|
|
24
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
25
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[VALUE, Math.random()]]))]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { Event } from '../../../model/Event';
|
|
3
|
+
import { EventResult } from '../../../model/EventResult';
|
|
4
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
6
|
+
import { Parameter } from '../../../model/Parameter';
|
|
7
|
+
import { Function } from '../../Function';
|
|
8
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
9
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
10
|
+
import { MapUtil } from '../../../util/MapUtil';
|
|
11
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
12
|
+
|
|
13
|
+
export abstract class AbstractStringFunction extends AbstractFunction {
|
|
14
|
+
public static readonly PARAMETER_STRING_NAME: string = 'string';
|
|
15
|
+
|
|
16
|
+
public static readonly PARAMETER_SEARCH_STRING_NAME: string = 'searchString';
|
|
17
|
+
|
|
18
|
+
public static readonly PARAMETER_SECOND_STRING_NAME: string = 'secondString';
|
|
19
|
+
|
|
20
|
+
public static readonly PARAMETER_THIRD_STRING_NAME: string = 'thirdString';
|
|
21
|
+
|
|
22
|
+
public static readonly PARAMETER_INDEX_NAME: string = 'index';
|
|
23
|
+
|
|
24
|
+
public static readonly PARAMETER_SECOND_INDEX_NAME: string = 'secondIndex';
|
|
25
|
+
|
|
26
|
+
public static readonly EVENT_RESULT_NAME: string = 'result';
|
|
27
|
+
|
|
28
|
+
protected static readonly PARAMETER_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_STRING_NAME));
|
|
29
|
+
|
|
30
|
+
protected static readonly PARAMETER_SECOND_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_SECOND_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_SECOND_STRING_NAME));
|
|
31
|
+
|
|
32
|
+
protected static readonly PARAMETER_THIRD_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_THIRD_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_THIRD_STRING_NAME));
|
|
33
|
+
|
|
34
|
+
protected static readonly PARAMETER_INDEX: Parameter =new Parameter(AbstractStringFunction.PARAMETER_INDEX_NAME,Schema.ofInteger(AbstractStringFunction.PARAMETER_INDEX_NAME));
|
|
35
|
+
|
|
36
|
+
protected static readonly PARAMETER_SECOND_INDEX: Parameter =new Parameter(AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME,Schema.ofInteger(AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME));
|
|
37
|
+
|
|
38
|
+
protected static readonly PARAMETER_SEARCH_STRING: Parameter =new Parameter(AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME,Schema.ofString(AbstractStringFunction.PARAMETER_STRING_NAME));
|
|
39
|
+
|
|
40
|
+
protected static readonly EVENT_STRING: Event =new Event(Event.OUTPUT,
|
|
41
|
+
MapUtil.of(
|
|
42
|
+
AbstractStringFunction.EVENT_RESULT_NAME,
|
|
43
|
+
Schema.ofString(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
protected static readonly EVENT_BOOLEAN: Event =new Event(Event.OUTPUT,
|
|
48
|
+
MapUtil.of(
|
|
49
|
+
AbstractStringFunction.EVENT_RESULT_NAME,
|
|
50
|
+
Schema.ofBoolean(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
protected static readonly EVENT_INT: Event =new Event(Event.OUTPUT,
|
|
55
|
+
MapUtil.of(
|
|
56
|
+
AbstractStringFunction.EVENT_RESULT_NAME,
|
|
57
|
+
Schema.ofInteger(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
protected static readonly EVENT_ARRAY: Event =new Event(Event.OUTPUT,
|
|
62
|
+
MapUtil.of(
|
|
63
|
+
AbstractStringFunction.EVENT_RESULT_NAME,
|
|
64
|
+
Schema.ofArray(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
private signature: FunctionSignature;
|
|
69
|
+
|
|
70
|
+
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
71
|
+
super();
|
|
72
|
+
const paramMap: Map<string, Parameter> = new Map();
|
|
73
|
+
parameter.forEach((e) => paramMap.set(e.getParameterName(), e));
|
|
74
|
+
|
|
75
|
+
this.signature = new FunctionSignature(functionName)
|
|
76
|
+
.setNamespace(namespace)
|
|
77
|
+
.setParameters(paramMap)
|
|
78
|
+
.setEvents(MapUtil.of(event.getName(), event));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public getSignature(): FunctionSignature {
|
|
82
|
+
return this.signature;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public static ofEntryAsStringBooleanOutput(
|
|
86
|
+
name: string,
|
|
87
|
+
fun: (a: string, b: string) => boolean,
|
|
88
|
+
): [string, Function] {
|
|
89
|
+
return [
|
|
90
|
+
name,
|
|
91
|
+
new (class extends AbstractStringFunction {
|
|
92
|
+
constructor(
|
|
93
|
+
namespace: string,
|
|
94
|
+
functionName: string,
|
|
95
|
+
event: Event,
|
|
96
|
+
...parameter: Parameter[]
|
|
97
|
+
) {
|
|
98
|
+
super(namespace, functionName, event, ...parameter);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
102
|
+
let s: string = context
|
|
103
|
+
?.getArguments()
|
|
104
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
105
|
+
let ss: string = context
|
|
106
|
+
?.getArguments()
|
|
107
|
+
?.get(AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME);
|
|
108
|
+
|
|
109
|
+
return new FunctionOutput([
|
|
110
|
+
EventResult.outputOf(
|
|
111
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s, ss)),
|
|
112
|
+
),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
})(
|
|
116
|
+
Namespaces.STRING,
|
|
117
|
+
name,
|
|
118
|
+
AbstractStringFunction.EVENT_BOOLEAN,
|
|
119
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
120
|
+
AbstractStringFunction.PARAMETER_SEARCH_STRING,
|
|
121
|
+
),
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public static ofEntryAsStringAndIntegerStringOutput(
|
|
126
|
+
name: string,
|
|
127
|
+
fun: (a: string, b: number) => string,
|
|
128
|
+
): [string, Function] {
|
|
129
|
+
return [
|
|
130
|
+
name,
|
|
131
|
+
new (class extends AbstractStringFunction {
|
|
132
|
+
constructor(
|
|
133
|
+
namespace: string,
|
|
134
|
+
functionName: string,
|
|
135
|
+
event: Event,
|
|
136
|
+
...parameter: Parameter[]
|
|
137
|
+
) {
|
|
138
|
+
super(namespace, functionName, event, ...parameter);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
142
|
+
let s: string = context
|
|
143
|
+
?.getArguments()
|
|
144
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
145
|
+
let count: number = context
|
|
146
|
+
?.getArguments()
|
|
147
|
+
?.get(AbstractStringFunction.PARAMETER_INDEX_NAME);
|
|
148
|
+
|
|
149
|
+
return new FunctionOutput([
|
|
150
|
+
EventResult.outputOf(
|
|
151
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s, count)),
|
|
152
|
+
),
|
|
153
|
+
]);
|
|
154
|
+
}
|
|
155
|
+
})(
|
|
156
|
+
Namespaces.STRING,
|
|
157
|
+
name,
|
|
158
|
+
AbstractStringFunction.EVENT_STRING,
|
|
159
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
160
|
+
AbstractStringFunction.PARAMETER_INDEX,
|
|
161
|
+
),
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public static ofEntryAsStringIntegerOutput(
|
|
166
|
+
name: string,
|
|
167
|
+
fun: (a: string, b: string) => number,
|
|
168
|
+
): [string, Function] {
|
|
169
|
+
return [
|
|
170
|
+
name,
|
|
171
|
+
new (class extends AbstractStringFunction {
|
|
172
|
+
constructor(
|
|
173
|
+
namespace: string,
|
|
174
|
+
functionName: string,
|
|
175
|
+
event: Event,
|
|
176
|
+
...parameter: Parameter[]
|
|
177
|
+
) {
|
|
178
|
+
super(namespace, functionName, event, ...parameter);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
182
|
+
let s1: string = context
|
|
183
|
+
?.getArguments()
|
|
184
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
185
|
+
let s2: string = context
|
|
186
|
+
?.getArguments()
|
|
187
|
+
?.get(AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME);
|
|
188
|
+
|
|
189
|
+
return new FunctionOutput([
|
|
190
|
+
EventResult.outputOf(
|
|
191
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s1, s2)),
|
|
192
|
+
),
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
})(
|
|
196
|
+
Namespaces.STRING,
|
|
197
|
+
name,
|
|
198
|
+
AbstractStringFunction.EVENT_INT,
|
|
199
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
200
|
+
AbstractStringFunction.PARAMETER_SEARCH_STRING,
|
|
201
|
+
),
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public static ofEntryString(name: string, fun: (a: string) => string): [string, Function] {
|
|
206
|
+
return [
|
|
207
|
+
name,
|
|
208
|
+
new (class extends AbstractStringFunction {
|
|
209
|
+
constructor(
|
|
210
|
+
namespace: string,
|
|
211
|
+
functionName: string,
|
|
212
|
+
event: Event,
|
|
213
|
+
...parameter: Parameter[]
|
|
214
|
+
) {
|
|
215
|
+
super(namespace, functionName, event, ...parameter);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
219
|
+
let s: string = context
|
|
220
|
+
?.getArguments()
|
|
221
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
222
|
+
|
|
223
|
+
return new FunctionOutput([
|
|
224
|
+
EventResult.outputOf(
|
|
225
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s)),
|
|
226
|
+
),
|
|
227
|
+
]);
|
|
228
|
+
}
|
|
229
|
+
})(
|
|
230
|
+
Namespaces.STRING,
|
|
231
|
+
name,
|
|
232
|
+
AbstractStringFunction.EVENT_STRING,
|
|
233
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
234
|
+
),
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
public static ofEntryStringBooleanOutput(
|
|
238
|
+
name: string,
|
|
239
|
+
fun: (a: string) => boolean,
|
|
240
|
+
): [string, Function] {
|
|
241
|
+
return [
|
|
242
|
+
name,
|
|
243
|
+
new (class extends AbstractStringFunction {
|
|
244
|
+
constructor(
|
|
245
|
+
namespace: string,
|
|
246
|
+
functionName: string,
|
|
247
|
+
event: Event,
|
|
248
|
+
...parameter: Parameter[]
|
|
249
|
+
) {
|
|
250
|
+
super(namespace, functionName, event, ...parameter);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
254
|
+
let s: string = context
|
|
255
|
+
?.getArguments()
|
|
256
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
257
|
+
|
|
258
|
+
return new FunctionOutput([
|
|
259
|
+
EventResult.outputOf(
|
|
260
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s)),
|
|
261
|
+
),
|
|
262
|
+
]);
|
|
263
|
+
}
|
|
264
|
+
})(
|
|
265
|
+
Namespaces.STRING,
|
|
266
|
+
name,
|
|
267
|
+
AbstractStringFunction.EVENT_BOOLEAN,
|
|
268
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
269
|
+
),
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
public static ofEntryAsStringStringIntegerIntegerOutput(
|
|
274
|
+
name: string,
|
|
275
|
+
fun: (a: string, b: string, c: number) => number,
|
|
276
|
+
): [string, Function] {
|
|
277
|
+
return [
|
|
278
|
+
name,
|
|
279
|
+
new (class extends AbstractStringFunction {
|
|
280
|
+
constructor(
|
|
281
|
+
namespace: string,
|
|
282
|
+
functionName: string,
|
|
283
|
+
event: Event,
|
|
284
|
+
...parameter: Parameter[]
|
|
285
|
+
) {
|
|
286
|
+
super(namespace, functionName, event, ...parameter);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
290
|
+
let s: string = context
|
|
291
|
+
?.getArguments()
|
|
292
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
293
|
+
let ss: string = context
|
|
294
|
+
?.getArguments()
|
|
295
|
+
?.get(AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME);
|
|
296
|
+
|
|
297
|
+
let ind: number = context
|
|
298
|
+
?.getArguments()
|
|
299
|
+
?.get(AbstractStringFunction.PARAMETER_INDEX_NAME);
|
|
300
|
+
|
|
301
|
+
return new FunctionOutput([
|
|
302
|
+
EventResult.outputOf(
|
|
303
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s, ss, ind)),
|
|
304
|
+
),
|
|
305
|
+
]);
|
|
306
|
+
}
|
|
307
|
+
})(
|
|
308
|
+
Namespaces.STRING,
|
|
309
|
+
name,
|
|
310
|
+
AbstractStringFunction.EVENT_INT,
|
|
311
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
312
|
+
AbstractStringFunction.PARAMETER_SEARCH_STRING,
|
|
313
|
+
AbstractStringFunction.PARAMETER_INDEX,
|
|
314
|
+
),
|
|
315
|
+
];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
public static ofEntryAsStringIntegerIntegerStringOutput(
|
|
319
|
+
name: string,
|
|
320
|
+
fun: (a: string, b: number, c: number) => string,
|
|
321
|
+
): [string, Function] {
|
|
322
|
+
return [
|
|
323
|
+
name,
|
|
324
|
+
new (class extends AbstractStringFunction {
|
|
325
|
+
constructor(
|
|
326
|
+
namespace: string,
|
|
327
|
+
functionName: string,
|
|
328
|
+
event: Event,
|
|
329
|
+
...parameter: Parameter[]
|
|
330
|
+
) {
|
|
331
|
+
super(namespace, functionName, event, ...parameter);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
335
|
+
let s: string = context
|
|
336
|
+
?.getArguments()
|
|
337
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
338
|
+
let ind1: number = context
|
|
339
|
+
?.getArguments()
|
|
340
|
+
?.get(AbstractStringFunction.PARAMETER_INDEX_NAME);
|
|
341
|
+
|
|
342
|
+
let ind2: number = context
|
|
343
|
+
?.getArguments()
|
|
344
|
+
?.get(AbstractStringFunction.PARAMETER_SECOND_INDEX_NAME);
|
|
345
|
+
|
|
346
|
+
return new FunctionOutput([
|
|
347
|
+
EventResult.outputOf(
|
|
348
|
+
MapUtil.of(
|
|
349
|
+
AbstractStringFunction.EVENT_RESULT_NAME,
|
|
350
|
+
fun(s, ind1, ind2),
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
]);
|
|
354
|
+
}
|
|
355
|
+
})(
|
|
356
|
+
Namespaces.STRING,
|
|
357
|
+
name,
|
|
358
|
+
AbstractStringFunction.EVENT_INT,
|
|
359
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
360
|
+
AbstractStringFunction.PARAMETER_INDEX,
|
|
361
|
+
AbstractStringFunction.PARAMETER_SECOND_INDEX,
|
|
362
|
+
),
|
|
363
|
+
];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public static ofEntryAsStringStringStringStringOutput(
|
|
367
|
+
name: string,
|
|
368
|
+
fun: (a: string, b: string, c: string) => string,
|
|
369
|
+
): [string, Function] {
|
|
370
|
+
return [
|
|
371
|
+
name,
|
|
372
|
+
new (class extends AbstractStringFunction {
|
|
373
|
+
constructor(
|
|
374
|
+
namespace: string,
|
|
375
|
+
functionName: string,
|
|
376
|
+
event: Event,
|
|
377
|
+
...parameter: Parameter[]
|
|
378
|
+
) {
|
|
379
|
+
super(namespace, functionName, event, ...parameter);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
383
|
+
let s1: string = context
|
|
384
|
+
?.getArguments()
|
|
385
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
386
|
+
let s2: string = context
|
|
387
|
+
?.getArguments()
|
|
388
|
+
?.get(AbstractStringFunction.PARAMETER_SECOND_STRING_NAME);
|
|
389
|
+
let s3: string = context
|
|
390
|
+
?.getArguments()
|
|
391
|
+
?.get(AbstractStringFunction.PARAMETER_THIRD_STRING_NAME);
|
|
392
|
+
|
|
393
|
+
return new FunctionOutput([
|
|
394
|
+
EventResult.outputOf(
|
|
395
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s1, s2, s3)),
|
|
396
|
+
),
|
|
397
|
+
]);
|
|
398
|
+
}
|
|
399
|
+
})(
|
|
400
|
+
Namespaces.STRING,
|
|
401
|
+
name,
|
|
402
|
+
AbstractStringFunction.EVENT_STRING,
|
|
403
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
404
|
+
AbstractStringFunction.PARAMETER_SECOND_STRING,
|
|
405
|
+
AbstractStringFunction.PARAMETER_THIRD_STRING,
|
|
406
|
+
),
|
|
407
|
+
];
|
|
408
|
+
}
|
|
409
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { SchemaType } from '../../../json/schema/type/SchemaType';
|
|
3
|
+
import { SingleType } from '../../../json/schema/type/SingleType';
|
|
4
|
+
import { Event } from '../../../model/Event';
|
|
5
|
+
import { EventResult } from '../../../model/EventResult';
|
|
6
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
7
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
8
|
+
import { Parameter } from '../../../model/Parameter';
|
|
9
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
10
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
11
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
12
|
+
|
|
13
|
+
export class Concatenate extends AbstractFunction {
|
|
14
|
+
public static VALUE: string = 'value';
|
|
15
|
+
|
|
16
|
+
private static SCHEMA: Schema = new Schema()
|
|
17
|
+
.setName(Concatenate.VALUE)
|
|
18
|
+
.setType(new SingleType(SchemaType.STRING));
|
|
19
|
+
|
|
20
|
+
private static SIGNATURE: FunctionSignature = new FunctionSignature('Concatenate')
|
|
21
|
+
.setNamespace(Namespaces.STRING)
|
|
22
|
+
.setParameters(
|
|
23
|
+
new Map([
|
|
24
|
+
[
|
|
25
|
+
Concatenate.VALUE,
|
|
26
|
+
new Parameter( Concatenate.VALUE, Concatenate.SCHEMA).setVariableArgument(true),
|
|
27
|
+
],
|
|
28
|
+
]),
|
|
29
|
+
)
|
|
30
|
+
.setEvents(
|
|
31
|
+
new Map([
|
|
32
|
+
Event.outputEventMapEntry(
|
|
33
|
+
new Map([[Concatenate.VALUE, Schema.ofString(Concatenate.VALUE)]]),
|
|
34
|
+
),
|
|
35
|
+
]),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
public constructor() {
|
|
39
|
+
super();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public getSignature(): FunctionSignature {
|
|
43
|
+
return Concatenate.SIGNATURE;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
47
|
+
let contextArgs: string[] = context.getArguments()?.get(Concatenate.VALUE);
|
|
48
|
+
|
|
49
|
+
let concatenatedString: string = '';
|
|
50
|
+
|
|
51
|
+
contextArgs.reduce((curr, next) => (concatenatedString = curr + next), concatenatedString);
|
|
52
|
+
|
|
53
|
+
return new FunctionOutput([
|
|
54
|
+
EventResult.outputOf(new Map([[Concatenate.VALUE, concatenatedString]])),
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { Event } from '../../../model/Event';
|
|
3
|
+
import { EventResult } from '../../../model/EventResult';
|
|
4
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
6
|
+
import { Parameter } from '../../../model/Parameter';
|
|
7
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
8
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
9
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
10
|
+
|
|
11
|
+
export class DeleteForGivenLength extends AbstractFunction {
|
|
12
|
+
public static readonly PARAMETER_STRING_NAME: string = 'string';
|
|
13
|
+
|
|
14
|
+
public static readonly PARAMETER_AT_START_NAME: string = 'startPosition';
|
|
15
|
+
|
|
16
|
+
public static readonly PARAMETER_AT_END_NAME: string = 'endPosition';
|
|
17
|
+
|
|
18
|
+
public static readonly EVENT_RESULT_NAME: string = 'result';
|
|
19
|
+
|
|
20
|
+
protected readonly PARAMETER_STRING: Parameter =new Parameter(DeleteForGivenLength.PARAMETER_STRING_NAME,Schema.ofString(DeleteForGivenLength.PARAMETER_STRING_NAME));
|
|
21
|
+
|
|
22
|
+
protected readonly PARAMETER_AT_START: Parameter =new Parameter(DeleteForGivenLength.PARAMETER_AT_START_NAME,Schema.ofInteger(DeleteForGivenLength.PARAMETER_AT_START_NAME));
|
|
23
|
+
|
|
24
|
+
protected readonly PARAMETER_AT_END: Parameter =new Parameter(DeleteForGivenLength.PARAMETER_AT_END_NAME,Schema.ofInteger(DeleteForGivenLength.PARAMETER_AT_END_NAME));
|
|
25
|
+
|
|
26
|
+
protected readonly EVENT_STRING: Event =new Event(Event.OUTPUT,
|
|
27
|
+
new Map([
|
|
28
|
+
[
|
|
29
|
+
DeleteForGivenLength.EVENT_RESULT_NAME,
|
|
30
|
+
Schema.ofString(DeleteForGivenLength.EVENT_RESULT_NAME),
|
|
31
|
+
],
|
|
32
|
+
]),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
private signature: FunctionSignature = new FunctionSignature('DeleteForGivenLength')
|
|
36
|
+
.setNamespace(Namespaces.STRING)
|
|
37
|
+
.setParameters(
|
|
38
|
+
new Map([
|
|
39
|
+
[this.PARAMETER_STRING.getParameterName(), this.PARAMETER_STRING],
|
|
40
|
+
[this.PARAMETER_AT_START.getParameterName(), this.PARAMETER_AT_START],
|
|
41
|
+
[this.PARAMETER_AT_END.getParameterName(), this.PARAMETER_AT_END],
|
|
42
|
+
]),
|
|
43
|
+
)
|
|
44
|
+
.setEvents(new Map([[this.EVENT_STRING.getName(), this.EVENT_STRING]]));
|
|
45
|
+
|
|
46
|
+
public constructor() {
|
|
47
|
+
super();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getSignature(): FunctionSignature {
|
|
51
|
+
return this.signature;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
|
|
55
|
+
let inputString: string = context
|
|
56
|
+
?.getArguments()
|
|
57
|
+
?.get(DeleteForGivenLength.PARAMETER_STRING_NAME);
|
|
58
|
+
let startPosition: number = context
|
|
59
|
+
?.getArguments()
|
|
60
|
+
?.get(DeleteForGivenLength.PARAMETER_AT_START_NAME);
|
|
61
|
+
let endPosition: number = context
|
|
62
|
+
?.getArguments()
|
|
63
|
+
?.get(DeleteForGivenLength.PARAMETER_AT_END_NAME);
|
|
64
|
+
|
|
65
|
+
if (endPosition >= startPosition) {
|
|
66
|
+
let outputString: string = '';
|
|
67
|
+
|
|
68
|
+
outputString += inputString.substring(0, startPosition);
|
|
69
|
+
outputString += inputString.substring(endPosition);
|
|
70
|
+
|
|
71
|
+
return new FunctionOutput([
|
|
72
|
+
EventResult.outputOf(
|
|
73
|
+
new Map([[DeleteForGivenLength.EVENT_RESULT_NAME, outputString.toString()]]),
|
|
74
|
+
),
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return new FunctionOutput([
|
|
79
|
+
EventResult.outputOf(new Map([[DeleteForGivenLength.EVENT_RESULT_NAME, inputString]])),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
}
|