@fincity/kirun-js 2.5.0 → 2.8.2
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/__tests__/engine/function/system/WaitTest.ts +1 -1
- package/__tests__/engine/function/system/array/AddFirstTest.ts +2 -6
- package/__tests__/engine/function/system/array/IndexOfTest.ts +8 -13
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +9 -28
- package/__tests__/engine/function/system/date/AddSubtractTimeTest.ts +93 -0
- package/__tests__/engine/function/system/date/DateFunctionRepositoryTest.ts +96 -0
- package/__tests__/engine/function/system/date/DifferenceTest.ts +93 -0
- package/__tests__/engine/function/system/date/EpochToTimestampTest.ts +133 -0
- package/__tests__/engine/function/system/date/FromDateStringTest.ts +51 -0
- package/__tests__/engine/function/system/date/FromNowTest.ts +71 -0
- package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +19 -27
- package/__tests__/engine/function/system/date/GetNamesTest.ts +105 -0
- package/__tests__/engine/function/system/date/IsBetweenTest.ts +53 -0
- package/__tests__/engine/function/system/date/IsValidISODateTest.ts +42 -54
- package/__tests__/engine/function/system/date/LastFirstOfTest.ts +64 -0
- package/__tests__/engine/function/system/date/SetTimeZoneTest.ts +48 -0
- package/__tests__/engine/function/system/date/StartEndOfTest.ts +53 -0
- package/__tests__/engine/function/system/date/TimeAsTest.ts +24 -0
- package/__tests__/engine/function/system/date/TimestampToEpochTest.ts +45 -0
- package/__tests__/engine/function/system/date/ToDateStringTest.ts +48 -0
- package/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +2 -2
- package/__tests__/engine/function/system/math/MaximumTest.ts +3 -2
- package/__tests__/engine/function/system/math/MinimumTest.ts +18 -20
- package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
- package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
- package/__tests__/engine/json/schema/covnertor/BooleanConvertorTest.ts +55 -0
- package/__tests__/engine/json/schema/covnertor/NullConvertorTest.ts +47 -0
- package/__tests__/engine/json/schema/covnertor/NumberConvertorTest.ts +154 -0
- package/__tests__/engine/json/schema/covnertor/StringConvertorTest.ts +56 -0
- package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +9 -7
- package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +3 -3
- package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +1 -9
- package/__tests__/engine/json/schema/validator/TypeValidatorTest.ts +290 -0
- package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
- package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +27 -20
- package/dist/types.d.ts.map +1 -1
- package/generator/generateValidationCSV.ts +52 -38
- package/generator/validation-js.csv +470 -166
- package/package.json +11 -6
- package/src/engine/function/AbstractFunction.ts +1 -1
- package/src/engine/function/system/Print.ts +19 -5
- package/src/engine/function/system/Wait.ts +1 -1
- package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
- package/src/engine/function/system/array/Fill.ts +1 -1
- package/src/engine/function/system/array/Frequency.ts +0 -1
- package/src/engine/function/system/array/IndexOf.ts +4 -4
- package/src/engine/function/system/array/LastIndexOf.ts +3 -3
- package/src/engine/function/system/array/Rotate.ts +1 -1
- package/src/engine/function/system/array/Shuffle.ts +1 -1
- package/src/engine/function/system/array/Sort.ts +1 -1
- package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
- package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
- package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
- package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
- package/src/engine/function/system/date/FromDateString.ts +44 -0
- package/src/engine/function/system/date/FromNow.ts +77 -0
- package/src/engine/function/system/date/GetCurrent.ts +20 -0
- package/src/engine/function/system/date/GetNames.ts +74 -0
- package/src/engine/function/system/date/IsBetween.ts +62 -0
- package/src/engine/function/system/date/IsValidISODate.ts +54 -40
- package/src/engine/function/system/date/LastFirstOf.ts +72 -0
- package/src/engine/function/system/date/SetTimeZone.ts +43 -0
- package/src/engine/function/system/date/StartEndOf.ts +44 -0
- package/src/engine/function/system/date/TimeAs.ts +64 -0
- package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
- package/src/engine/function/system/date/ToDateString.ts +49 -0
- package/src/engine/function/system/date/common.ts +9 -0
- package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
- package/src/engine/function/system/math/RandomAny.ts +57 -0
- package/src/engine/function/system/object/ObjectConvert.ts +99 -0
- package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
- package/src/engine/function/system/object/ObjectPutValue.ts +0 -2
- package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
- package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
- package/src/engine/json/schema/SchemaUtil.ts +1 -1
- package/src/engine/json/schema/convertor/BooleanConvertor.ts +76 -0
- package/src/engine/json/schema/convertor/NullConvertor.ts +31 -0
- package/src/engine/json/schema/convertor/NumberConvertor.ts +117 -0
- package/src/engine/json/schema/convertor/StringConvertor.ts +41 -0
- package/src/engine/json/schema/convertor/enums/ConversionMode.ts +11 -0
- package/src/engine/json/schema/convertor/exception/SchemaConversionException.ts +39 -0
- package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +96 -36
- package/src/engine/json/schema/validator/ArrayValidator.ts +15 -7
- package/src/engine/json/schema/validator/ObjectValidator.ts +24 -13
- package/src/engine/json/schema/validator/SchemaValidator.ts +74 -22
- package/src/engine/json/schema/validator/TypeValidator.ts +136 -23
- package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
- package/src/engine/util/json/ConvertorUtil.ts +51 -0
- package/src/engine/util/json/ValidatorUtil.ts +29 -0
- package/src/engine/util/string/StringUtil.ts +12 -0
- package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
- package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
- package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
- package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
- package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
- package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
- package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
- package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
- package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
- package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
- package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
- package/src/engine/function/system/date/DateToEpoch.ts +0 -39
- package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
- package/src/engine/function/system/date/EpochToDate.ts +0 -76
- package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
- package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
- package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
- package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
- package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
- package/src/engine/function/system/math/RandomFloat.ts +0 -56
- package/src/engine/function/system/math/RandomInt.ts +0 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fincity/kirun-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Javascript Runtime for Kinetic Instructions",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,16 +31,17 @@
|
|
|
31
31
|
"author": "Kiran Kumar Grandhi",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@parcel/packager-ts": "^2.
|
|
34
|
+
"@parcel/packager-ts": "^2.12.0",
|
|
35
35
|
"@parcel/transformer-typescript-types": "^2.7.0",
|
|
36
36
|
"@tsconfig/recommended": "^1.0.1",
|
|
37
|
-
"@types/jest": "^
|
|
38
|
-
"
|
|
37
|
+
"@types/jest": "^29.5.14",
|
|
38
|
+
"@types/luxon": "^3.4.2",
|
|
39
|
+
"jest": "^29.7.0",
|
|
39
40
|
"parcel": "^2.7.0",
|
|
40
41
|
"prettier": "2.7.1",
|
|
41
|
-
"ts-jest": "^29.
|
|
42
|
+
"ts-jest": "^29.2.5",
|
|
42
43
|
"ts-loader": "^9.3.1",
|
|
43
|
-
"typescript": "^5.
|
|
44
|
+
"typescript": "^5.6.3"
|
|
44
45
|
},
|
|
45
46
|
"jest": {
|
|
46
47
|
"transform": {
|
|
@@ -52,5 +53,9 @@
|
|
|
52
53
|
"tsx",
|
|
53
54
|
"js"
|
|
54
55
|
]
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@fincity/kirun-js": "file:",
|
|
59
|
+
"luxon": "^3.5.0"
|
|
55
60
|
}
|
|
56
61
|
}
|
|
@@ -100,7 +100,7 @@ export abstract class AbstractFunction implements Function {
|
|
|
100
100
|
);
|
|
101
101
|
context.setArguments(args);
|
|
102
102
|
try {
|
|
103
|
-
return this.internalExecute(context);
|
|
103
|
+
return await this.internalExecute(context);
|
|
104
104
|
} catch (err: any) {
|
|
105
105
|
const signature = this.getSignature();
|
|
106
106
|
throw new KIRuntimeException(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from '../../json/schema/Schema';
|
|
2
|
-
import { SchemaType } from '../../json/schema/type/SchemaType';
|
|
3
2
|
import { Event } from '../../model/Event';
|
|
4
3
|
import { EventResult } from '../../model/EventResult';
|
|
5
4
|
import { FunctionOutput } from '../../model/FunctionOutput';
|
|
@@ -11,21 +10,36 @@ import { AbstractFunction } from '../AbstractFunction';
|
|
|
11
10
|
|
|
12
11
|
export class Print extends AbstractFunction {
|
|
13
12
|
private static readonly VALUES: string = 'values';
|
|
13
|
+
private static readonly STREAM: string = 'stream';
|
|
14
|
+
|
|
15
|
+
private static readonly LOG: string = 'LOG';
|
|
16
|
+
private static readonly ERROR: string = 'ERROR';
|
|
14
17
|
|
|
15
18
|
private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Print')
|
|
16
19
|
.setNamespace(Namespaces.SYSTEM)
|
|
17
20
|
.setParameters(
|
|
18
|
-
new Map([
|
|
19
|
-
|
|
21
|
+
new Map([
|
|
22
|
+
Parameter.ofEntry(Print.VALUES, Schema.ofAny(Print.VALUES), true),
|
|
23
|
+
Parameter.ofEntry(
|
|
24
|
+
Print.STREAM,
|
|
25
|
+
Schema.ofString(Print.STREAM)
|
|
26
|
+
.setEnums([Print.LOG, Print.ERROR])
|
|
27
|
+
.setDefaultValue(Print.LOG),
|
|
28
|
+
),
|
|
29
|
+
]),
|
|
30
|
+
)
|
|
31
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map())]));
|
|
20
32
|
|
|
21
33
|
public getSignature(): FunctionSignature {
|
|
22
34
|
return Print.SIGNATURE;
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
26
|
-
|
|
38
|
+
let values = context.getArguments()?.get(Print.VALUES);
|
|
39
|
+
|
|
40
|
+
const stream = context.getArguments()?.get(Print.STREAM);
|
|
27
41
|
|
|
28
|
-
console?.log(...values);
|
|
42
|
+
(stream === Print.LOG ? console?.log : console?.error)?.(...values);
|
|
29
43
|
|
|
30
44
|
return new FunctionOutput([EventResult.outputOf(new Map())]);
|
|
31
45
|
}
|
|
@@ -28,7 +28,7 @@ export class Wait extends AbstractFunction {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
31
|
-
|
|
31
|
+
let condition = context.getArguments()?.get(Wait.MILLIS);
|
|
32
32
|
|
|
33
33
|
await new Promise((resolve) => setTimeout(resolve, condition));
|
|
34
34
|
|
|
@@ -150,9 +150,9 @@ export abstract class AbstractArrayFunction extends AbstractFunction {
|
|
|
150
150
|
Schema.ofAny('element'),
|
|
151
151
|
);
|
|
152
152
|
|
|
153
|
-
public static readonly
|
|
153
|
+
public static readonly PARAMETER_ANY_ELEMENT_OBJECT: Parameter = Parameter.of(
|
|
154
154
|
'elementObject',
|
|
155
|
-
Schema.
|
|
155
|
+
Schema.ofAny('elementObject'),
|
|
156
156
|
);
|
|
157
157
|
|
|
158
158
|
public static readonly PARAMETER_ANY_VAR_ARGS: Parameter = Parameter.of(
|
|
@@ -165,7 +165,7 @@ export abstract class AbstractArrayFunction extends AbstractFunction {
|
|
|
165
165
|
Schema.ofArray('eachResult', Schema.ofAny('eachResult')),
|
|
166
166
|
);
|
|
167
167
|
|
|
168
|
-
private signature: FunctionSignature;
|
|
168
|
+
private readonly signature: FunctionSignature;
|
|
169
169
|
|
|
170
170
|
protected constructor(functionName: string, parameters: Parameter[], event: Event) {
|
|
171
171
|
super();
|
|
@@ -2,7 +2,6 @@ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
|
2
2
|
import { EventResult } from '../../../model/EventResult';
|
|
3
3
|
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
4
|
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
-
import { isNullValue } from '../../../util/NullCheck';
|
|
6
5
|
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
7
6
|
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
8
7
|
|
|
@@ -2,7 +2,6 @@ import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
|
2
2
|
import { EventResult } from '../../../model/EventResult';
|
|
3
3
|
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
4
4
|
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
5
|
-
import { isNullValue } from '../../../util/NullCheck';
|
|
6
5
|
import { PrimitiveUtil } from '../../../util/primitive/PrimitiveUtil';
|
|
7
6
|
import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
8
7
|
|
|
@@ -12,7 +11,7 @@ export class IndexOf extends AbstractArrayFunction {
|
|
|
12
11
|
'IndexOf',
|
|
13
12
|
[
|
|
14
13
|
IndexOf.PARAMETER_ARRAY_SOURCE,
|
|
15
|
-
IndexOf.
|
|
14
|
+
IndexOf.PARAMETER_ANY_ELEMENT_OBJECT,
|
|
16
15
|
IndexOf.PARAMETER_INT_FIND_FROM,
|
|
17
16
|
],
|
|
18
17
|
IndexOf.EVENT_RESULT_INTEGER,
|
|
@@ -24,7 +23,9 @@ export class IndexOf extends AbstractArrayFunction {
|
|
|
24
23
|
?.getArguments()
|
|
25
24
|
?.get(IndexOf.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
let find = context
|
|
27
|
+
?.getArguments()
|
|
28
|
+
?.get(IndexOf.PARAMETER_ANY_ELEMENT_OBJECT.getParameterName());
|
|
28
29
|
|
|
29
30
|
let len: number = context
|
|
30
31
|
?.getArguments()
|
|
@@ -34,7 +35,6 @@ export class IndexOf extends AbstractArrayFunction {
|
|
|
34
35
|
return new FunctionOutput([
|
|
35
36
|
EventResult.outputOf(new Map([[IndexOf.EVENT_RESULT_NAME, -1]])),
|
|
36
37
|
]);
|
|
37
|
-
|
|
38
38
|
if (len < 0 || len > source.length)
|
|
39
39
|
throw new KIRuntimeException(
|
|
40
40
|
'The size of the search index of the array is greater than the size of the array',
|
|
@@ -11,7 +11,7 @@ export class LastIndexOf extends AbstractArrayFunction {
|
|
|
11
11
|
'LastIndexOf',
|
|
12
12
|
[
|
|
13
13
|
LastIndexOf.PARAMETER_ARRAY_SOURCE,
|
|
14
|
-
LastIndexOf.
|
|
14
|
+
LastIndexOf.PARAMETER_ANY_ELEMENT_OBJECT,
|
|
15
15
|
LastIndexOf.PARAMETER_INT_FIND_FROM,
|
|
16
16
|
],
|
|
17
17
|
LastIndexOf.EVENT_RESULT_INTEGER,
|
|
@@ -23,9 +23,9 @@ export class LastIndexOf extends AbstractArrayFunction {
|
|
|
23
23
|
?.getArguments()
|
|
24
24
|
?.get(LastIndexOf.PARAMETER_ARRAY_SOURCE.getParameterName());
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
let find = context
|
|
27
27
|
?.getArguments()
|
|
28
|
-
?.get(LastIndexOf.
|
|
28
|
+
?.get(LastIndexOf.PARAMETER_ANY_ELEMENT_OBJECT.getParameterName());
|
|
29
29
|
|
|
30
30
|
let len = context
|
|
31
31
|
?.getArguments()
|
|
@@ -5,7 +5,7 @@ import { AbstractArrayFunction } from './AbstractArrayFunction';
|
|
|
5
5
|
|
|
6
6
|
export class Shuffle extends AbstractArrayFunction {
|
|
7
7
|
public constructor() {
|
|
8
|
-
super('Shuffle', [Shuffle.PARAMETER_ARRAY_SOURCE], Shuffle.
|
|
8
|
+
super('Shuffle', [Shuffle.PARAMETER_ARRAY_SOURCE], Shuffle.EVENT_RESULT_ARRAY);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
@@ -1,54 +1,61 @@
|
|
|
1
|
-
import { Schema } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { isNullValue } from "../../../util/NullCheck";
|
|
13
|
-
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
14
|
-
import { Function } from "../../../../engine/function/Function";
|
|
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 { MapUtil } from '../../../util/MapUtil';
|
|
10
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
11
|
+
import { Function } from '../../Function';
|
|
15
12
|
|
|
16
13
|
export abstract class AbstractDateFunction extends AbstractFunction {
|
|
14
|
+
private readonly signature: FunctionSignature;
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
public static readonly PARAMETER_TIMESTAMP_NAME: string = 'isoTimeStamp';
|
|
19
17
|
|
|
20
|
-
public static readonly
|
|
21
|
-
|
|
22
|
-
public static readonly PARAMETER_DATE_NAME: string = 'isoDate';
|
|
18
|
+
public static readonly PARAMETER_TIMESTAMP_NAME_ONE: string = 'isoTimeStamp1';
|
|
19
|
+
public static readonly PARAMETER_TIMESTAMP_NAME_TWO: string = 'isoTimeStamp2';
|
|
23
20
|
|
|
24
|
-
public static readonly
|
|
21
|
+
public static readonly PARAMETER_UNIT_NAME: string = 'unit';
|
|
25
22
|
|
|
26
|
-
public static readonly
|
|
23
|
+
public static readonly PARAMETER_NUMBER_NAME: string = 'number';
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
AbstractDateFunction.PARAMETER_DATE_NAME,
|
|
32
|
-
Schema.ofString(this.PARAMETER_DATE_NAME).setRef(Namespaces.DATE + ".timeStamp")
|
|
25
|
+
public static readonly PARAMETER_TIMESTAMP: Parameter = new Parameter(
|
|
26
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
|
|
27
|
+
Schema.ofRef(Namespaces.DATE + '.Timestamp'),
|
|
33
28
|
);
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
AbstractDateFunction.
|
|
37
|
-
Schema.
|
|
30
|
+
public static readonly PARAMETER_TIMESTAMP_ONE: Parameter = new Parameter(
|
|
31
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_ONE,
|
|
32
|
+
Schema.ofRef(Namespaces.DATE + '.Timestamp'),
|
|
38
33
|
);
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
AbstractDateFunction.
|
|
42
|
-
Schema.
|
|
35
|
+
public static readonly PARAMETER_TIMESTAMP_TWO: Parameter = new Parameter(
|
|
36
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_TWO,
|
|
37
|
+
Schema.ofRef(Namespaces.DATE + '.Timestamp'),
|
|
43
38
|
);
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
public static readonly PARAMETER_VARIABLE_UNIT: Parameter = new Parameter(
|
|
41
|
+
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
42
|
+
Schema.ofRef(Namespaces.DATE + '.Timeunit'),
|
|
43
|
+
).setVariableArgument(true);
|
|
44
|
+
|
|
45
|
+
public static readonly PARAMETER_UNIT: Parameter = new Parameter(
|
|
46
46
|
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
47
|
-
Schema.
|
|
48
|
-
.setEnums(["YEAR" , "MONTH" , "DAY" , "HOUR" , "MINUTE" , "SECOND" , "MILLISECOND"])
|
|
47
|
+
Schema.ofRef(Namespaces.DATE + '.Timeunit'),
|
|
49
48
|
);
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
public static readonly PARAMETER_NUMBER: Parameter = new Parameter(
|
|
51
|
+
AbstractDateFunction.PARAMETER_NUMBER_NAME,
|
|
52
|
+
Schema.ofInteger(AbstractDateFunction.PARAMETER_NUMBER_NAME),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
public static readonly EVENT_RESULT_NAME: string = 'result';
|
|
56
|
+
public static readonly EVENT_TIMESTAMP_NAME: string = 'isoTimeStamp';
|
|
57
|
+
|
|
58
|
+
public static readonly EVENT_INT: Event = new Event(
|
|
52
59
|
Event.OUTPUT,
|
|
53
60
|
MapUtil.of(
|
|
54
61
|
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
@@ -56,107 +63,218 @@ export abstract class AbstractDateFunction extends AbstractFunction {
|
|
|
56
63
|
),
|
|
57
64
|
);
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
public static readonly EVENT_STRING: Event = new Event(
|
|
67
|
+
Event.OUTPUT,
|
|
68
|
+
MapUtil.of(
|
|
69
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
70
|
+
Schema.ofString(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
public static readonly EVENT_LONG: Event = new Event(
|
|
60
75
|
Event.OUTPUT,
|
|
61
76
|
MapUtil.of(
|
|
62
77
|
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
63
|
-
Schema.
|
|
64
|
-
)
|
|
78
|
+
Schema.ofLong(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
79
|
+
),
|
|
65
80
|
);
|
|
66
81
|
|
|
67
|
-
protected static readonly
|
|
82
|
+
protected static readonly EVENT_BOOLEAN: Event = new Event(
|
|
68
83
|
Event.OUTPUT,
|
|
69
84
|
MapUtil.of(
|
|
70
85
|
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
71
|
-
Schema.
|
|
72
|
-
)
|
|
73
|
-
);
|
|
86
|
+
Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
public static readonly EVENT_TIMESTAMP: Event = new Event(
|
|
91
|
+
Event.OUTPUT,
|
|
92
|
+
MapUtil.of(
|
|
93
|
+
AbstractDateFunction.EVENT_TIMESTAMP_NAME,
|
|
94
|
+
Schema.ofRef(Namespaces.DATE + '.Timestamp'),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
74
97
|
|
|
75
98
|
public getSignature(): FunctionSignature {
|
|
76
99
|
return this.signature;
|
|
77
100
|
}
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
81
|
-
|
|
102
|
+
constructor(functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
82
103
|
super();
|
|
83
|
-
const paramMap: Map<string, Parameter> = new Map();
|
|
84
|
-
parameter.forEach((e) => paramMap.set(e.getParameterName(), e));
|
|
85
104
|
|
|
86
105
|
this.signature = new FunctionSignature(functionName)
|
|
87
|
-
.setNamespace(
|
|
88
|
-
.setParameters(paramMap)
|
|
106
|
+
.setNamespace(Namespaces.DATE)
|
|
89
107
|
.setEvents(MapUtil.of(event.getName(), event));
|
|
90
108
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
public static ofEntryDateAndBooleanOutput(name: string, fun: ( date : string) => boolean) : [string, Function] {
|
|
94
|
-
|
|
95
|
-
return [name, new (class extends AbstractDateFunction {
|
|
96
|
-
|
|
97
|
-
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
98
|
-
super(namespace, functionName, event, ...parameter);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
102
|
-
|
|
103
|
-
const date = context.getArguments()?.get(AbstractDateFunction.PARAMETER_DATE_NAME);
|
|
104
|
-
|
|
105
|
-
if(isNullValue(date) || !ValidDateTimeUtil.validate(date))
|
|
106
|
-
throw new KIRuntimeException("Please provide a valid date.");
|
|
107
|
-
|
|
108
|
-
return new FunctionOutput([EventResult.outputOf(MapUtil.of(AbstractDateFunction.EVENT_RESULT_NAME, fun(date)))]);
|
|
109
|
+
if (!parameter?.length) return;
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
})(Namespaces.DATE, name, AbstractDateFunction.EVENT_BOOLEAN, AbstractDateFunction.PARAMETER_DATE)];
|
|
111
|
+
const paramMap: Map<string, Parameter> = new Map();
|
|
112
|
+
parameter.forEach((e) => paramMap.set(e.getParameterName(), e));
|
|
113
|
+
this.signature.setParameters(paramMap);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
public static
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
public static ofEntryTimestampAndIntegerOutput(
|
|
117
|
+
name: string,
|
|
118
|
+
fun: (isoTimestamp: string) => number,
|
|
119
|
+
): [string, Function] {
|
|
120
|
+
return [
|
|
121
|
+
name,
|
|
122
|
+
new (class extends AbstractDateFunction {
|
|
123
|
+
protected async internalExecute(
|
|
124
|
+
context: FunctionExecutionParameters,
|
|
125
|
+
): Promise<FunctionOutput> {
|
|
126
|
+
return new FunctionOutput([
|
|
127
|
+
EventResult.outputOf(
|
|
128
|
+
MapUtil.of(
|
|
129
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
130
|
+
fun(
|
|
131
|
+
context
|
|
132
|
+
.getArguments()
|
|
133
|
+
?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME),
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
})(name, AbstractDateFunction.EVENT_INT, AbstractDateFunction.PARAMETER_TIMESTAMP),
|
|
140
|
+
];
|
|
133
141
|
}
|
|
134
142
|
|
|
135
|
-
public static
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
public static ofEntryTimestampAndBooleanOutput(
|
|
144
|
+
name: string,
|
|
145
|
+
fun: (isoTimestamp: string) => boolean,
|
|
146
|
+
): [string, Function] {
|
|
147
|
+
return [
|
|
148
|
+
name,
|
|
149
|
+
new (class extends AbstractDateFunction {
|
|
150
|
+
protected async internalExecute(
|
|
151
|
+
context: FunctionExecutionParameters,
|
|
152
|
+
): Promise<FunctionOutput> {
|
|
153
|
+
return new FunctionOutput([
|
|
154
|
+
EventResult.outputOf(
|
|
155
|
+
MapUtil.of(
|
|
156
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
157
|
+
fun(
|
|
158
|
+
context
|
|
159
|
+
.getArguments()
|
|
160
|
+
?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME),
|
|
161
|
+
),
|
|
162
|
+
),
|
|
163
|
+
),
|
|
164
|
+
]);
|
|
140
165
|
}
|
|
166
|
+
})(name, AbstractDateFunction.EVENT_BOOLEAN, AbstractDateFunction.PARAMETER_TIMESTAMP),
|
|
167
|
+
];
|
|
168
|
+
}
|
|
141
169
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
170
|
+
public static ofEntryTimestampAndStringOutput(
|
|
171
|
+
name: string,
|
|
172
|
+
fun: (isoTimestamp: string) => string,
|
|
173
|
+
): [string, Function] {
|
|
174
|
+
return [
|
|
175
|
+
name,
|
|
176
|
+
new (class extends AbstractDateFunction {
|
|
177
|
+
protected async internalExecute(
|
|
178
|
+
context: FunctionExecutionParameters,
|
|
179
|
+
): Promise<FunctionOutput> {
|
|
180
|
+
return new FunctionOutput([
|
|
181
|
+
EventResult.outputOf(
|
|
182
|
+
MapUtil.of(
|
|
183
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
184
|
+
fun(
|
|
185
|
+
context
|
|
186
|
+
.getArguments()
|
|
187
|
+
?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME),
|
|
188
|
+
),
|
|
189
|
+
),
|
|
190
|
+
),
|
|
191
|
+
]);
|
|
155
192
|
}
|
|
156
|
-
})(
|
|
157
|
-
|
|
193
|
+
})(name, AbstractDateFunction.EVENT_STRING, AbstractDateFunction.PARAMETER_TIMESTAMP),
|
|
194
|
+
];
|
|
195
|
+
}
|
|
158
196
|
|
|
159
|
-
|
|
160
|
-
|
|
197
|
+
public static ofEntryTimestampIntegerAndTimestampOutput(
|
|
198
|
+
name: string,
|
|
199
|
+
fun: (isoTimestamp: string, integer: number) => string,
|
|
200
|
+
): [string, Function] {
|
|
201
|
+
return [
|
|
202
|
+
name,
|
|
203
|
+
new (class extends AbstractDateFunction {
|
|
204
|
+
protected async internalExecute(
|
|
205
|
+
context: FunctionExecutionParameters,
|
|
206
|
+
): Promise<FunctionOutput> {
|
|
207
|
+
return new FunctionOutput([
|
|
208
|
+
EventResult.outputOf(
|
|
209
|
+
MapUtil.of(
|
|
210
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
211
|
+
fun(
|
|
212
|
+
context
|
|
213
|
+
.getArguments()
|
|
214
|
+
?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME),
|
|
215
|
+
context
|
|
216
|
+
.getArguments()
|
|
217
|
+
?.get(AbstractDateFunction.PARAMETER_NUMBER_NAME),
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
]);
|
|
222
|
+
}
|
|
223
|
+
})(
|
|
224
|
+
name,
|
|
225
|
+
AbstractDateFunction.EVENT_INT,
|
|
226
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP,
|
|
227
|
+
AbstractDateFunction.PARAMETER_NUMBER,
|
|
228
|
+
),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
161
231
|
|
|
162
|
-
|
|
232
|
+
public static ofEntryTimestampTimestampAndTOutput<T>(
|
|
233
|
+
name: string,
|
|
234
|
+
event: Event,
|
|
235
|
+
fun: (ts1: string, ts2: string, ...parameters: any[]) => T,
|
|
236
|
+
...parameters: Parameter[]
|
|
237
|
+
): [string, Function] {
|
|
238
|
+
return [
|
|
239
|
+
name,
|
|
240
|
+
new (class extends AbstractDateFunction {
|
|
241
|
+
protected async internalExecute(
|
|
242
|
+
context: FunctionExecutionParameters,
|
|
243
|
+
): Promise<FunctionOutput> {
|
|
244
|
+
const args = [];
|
|
245
|
+
|
|
246
|
+
if (parameters?.length) {
|
|
247
|
+
args.push(
|
|
248
|
+
...parameters.map((e) =>
|
|
249
|
+
context.getArguments()?.get(e.getParameterName()),
|
|
250
|
+
),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return new FunctionOutput([
|
|
255
|
+
EventResult.outputOf(
|
|
256
|
+
MapUtil.of(
|
|
257
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
258
|
+
fun(
|
|
259
|
+
context
|
|
260
|
+
.getArguments()
|
|
261
|
+
?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_ONE),
|
|
262
|
+
context
|
|
263
|
+
.getArguments()
|
|
264
|
+
?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME_TWO),
|
|
265
|
+
args,
|
|
266
|
+
),
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
]);
|
|
270
|
+
}
|
|
271
|
+
})(
|
|
272
|
+
name,
|
|
273
|
+
event,
|
|
274
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_ONE,
|
|
275
|
+
AbstractDateFunction.PARAMETER_TIMESTAMP_TWO,
|
|
276
|
+
...parameters,
|
|
277
|
+
),
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
}
|