@fincity/kirun-js 2.3.1 → 2.3.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/date/DateToEpochTest.ts +74 -0
- package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +53 -0
- package/__tests__/engine/function/system/date/EpochToDateTest.ts +105 -0
- package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +35 -0
- package/__tests__/engine/function/system/date/GetDateTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetDayTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetFullYearTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetHoursTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetMinutesTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetMonthTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetSecondsTest.ts +85 -0
- package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +59 -0
- package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +83 -0
- package/__tests__/engine/function/system/date/GetTimeTest.ts +86 -0
- package/__tests__/engine/function/system/date/IsLeapYearTest.ts +85 -0
- package/__tests__/engine/function/system/date/IsValidISODateTest.ts +79 -0
- package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +55 -0
- package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +54 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +5 -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 +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +2 -0
- package/src/engine/function/system/date/AbstractDateFunction.ts +104 -0
- package/src/engine/function/system/date/DateFunctionRepository.ts +56 -0
- package/src/engine/function/system/date/DateToEpoch.ts +39 -0
- package/src/engine/function/system/date/DifferenceOfTimestamps.ts +45 -0
- package/src/engine/function/system/date/EpochToDate.ts +76 -0
- package/src/engine/function/system/date/GetCurrentTimeStamp.ts +36 -0
- package/src/engine/function/system/date/GetTimeAsArray.ts +48 -0
- package/src/engine/function/system/date/GetTimeAsObject.ts +66 -0
- package/src/engine/function/system/date/IsValidISODate.ts +43 -0
- package/src/engine/function/system/date/MaximumTimestamp.ts +73 -0
- package/src/engine/function/system/date/MinimumTimestamp.ts +74 -0
- package/src/engine/namespaces/Namespaces.ts +1 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +4 -0
- package/src/engine/repository/KIRunSchemaRepository.ts +1 -0
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +14 -15
- package/src/engine/util/ValidDateTimeUtil.ts +119 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
2
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
3
|
+
import { Event } from '../../../model/Event';
|
|
4
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
5
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
6
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
7
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
8
|
+
import { EventResult } from "../../../model/EventResult";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const OUTPUT = 'date';
|
|
12
|
+
|
|
13
|
+
const SIGNATURE: FunctionSignature = new FunctionSignature("GetCurrentTimeStamp")
|
|
14
|
+
.setNamespace(Namespaces.DATE)
|
|
15
|
+
.setParameters(new Map([]))
|
|
16
|
+
.setEvents(new Map([
|
|
17
|
+
Event.outputEventMapEntry(
|
|
18
|
+
new Map([[OUTPUT, Schema.ofRef(`${Namespaces.DATE}.timeStamp`)]]),
|
|
19
|
+
),
|
|
20
|
+
]));
|
|
21
|
+
|
|
22
|
+
export class GetCurrentTimeStamp extends AbstractFunction{
|
|
23
|
+
|
|
24
|
+
public getSignature(): FunctionSignature {
|
|
25
|
+
|
|
26
|
+
return SIGNATURE;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
31
|
+
|
|
32
|
+
const date : string = new Date(Date.now()).toISOString();
|
|
33
|
+
|
|
34
|
+
return new FunctionOutput([EventResult.of(OUTPUT, new Map([ [OUTPUT, date]]))]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
2
|
+
import { ArraySchemaType } from "../../../json/schema/array/ArraySchemaType";
|
|
3
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
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 { MapUtil } from "../../../util/MapUtil";
|
|
12
|
+
import { isNullValue } from "../../../util/NullCheck";
|
|
13
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
14
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const VALUE:string = "isoDate";
|
|
18
|
+
|
|
19
|
+
const OUTPUT:string = "result";
|
|
20
|
+
|
|
21
|
+
const SIGNATURE = new FunctionSignature('GetTimeAsArray')
|
|
22
|
+
.setNamespace(Namespaces.DATE)
|
|
23
|
+
.setParameters(MapUtil.of(VALUE, Parameter.of(VALUE, Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
|
|
24
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT , Schema.ofArray(OUTPUT).setItems(ArraySchemaType.of(Schema.ofNumber("number")))]]))]))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export class GetTimeAsArray extends AbstractFunction{
|
|
28
|
+
|
|
29
|
+
public getSignature(): FunctionSignature {
|
|
30
|
+
return SIGNATURE;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
34
|
+
|
|
35
|
+
var inputDate = context.getArguments()?.get(VALUE);
|
|
36
|
+
|
|
37
|
+
if(isNullValue(inputDate) || !ValidDateTimeUtil.validate(inputDate))
|
|
38
|
+
throw new KIRuntimeException("Please provide a valid date object");
|
|
39
|
+
|
|
40
|
+
const date = new Date(inputDate);
|
|
41
|
+
|
|
42
|
+
const outputArray = [ date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()
|
|
43
|
+
, date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()];
|
|
44
|
+
|
|
45
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT , outputArray]]))]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
2
|
+
import { ArraySchemaType } from "../../../json/schema/array/ArraySchemaType";
|
|
3
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
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 { MapUtil } from "../../../util/MapUtil";
|
|
12
|
+
import { isNullValue } from "../../../util/NullCheck";
|
|
13
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
14
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const VALUE:string = "isoDate";
|
|
18
|
+
|
|
19
|
+
const OUTPUT:string = "result";
|
|
20
|
+
|
|
21
|
+
const SIGNATURE = new FunctionSignature('GetTimeAsObject')
|
|
22
|
+
.setNamespace(Namespaces.DATE)
|
|
23
|
+
.setParameters(MapUtil.of(VALUE, Parameter.of(VALUE, Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
|
|
24
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT ,
|
|
25
|
+
Schema.ofObject(OUTPUT).setProperties(new Map(
|
|
26
|
+
[
|
|
27
|
+
["year", Schema.ofNumber("year")],
|
|
28
|
+
["month", Schema.ofNumber("month")],
|
|
29
|
+
["day", Schema.ofNumber("day")],
|
|
30
|
+
["hours", Schema.ofNumber("hours")],
|
|
31
|
+
["minutes", Schema.ofNumber("minutes")],
|
|
32
|
+
["seconds", Schema.ofNumber("seconds")],
|
|
33
|
+
["milliseconds", Schema.ofNumber("milliseconds")]
|
|
34
|
+
]
|
|
35
|
+
))]]))]));
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export class GetTimeAsObject extends AbstractFunction{
|
|
39
|
+
|
|
40
|
+
public getSignature(): FunctionSignature {
|
|
41
|
+
return SIGNATURE;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
45
|
+
|
|
46
|
+
var inputDate = context.getArguments()?.get(VALUE);
|
|
47
|
+
|
|
48
|
+
if(isNullValue(inputDate) || !ValidDateTimeUtil.validate(inputDate))
|
|
49
|
+
throw new KIRuntimeException("Please provide a valid date object");
|
|
50
|
+
|
|
51
|
+
const date = new Date(inputDate);
|
|
52
|
+
|
|
53
|
+
const outputObject = {
|
|
54
|
+
year: date.getUTCFullYear(),
|
|
55
|
+
month: date.getUTCMonth() + 1,
|
|
56
|
+
day: date.getUTCDate(),
|
|
57
|
+
hours: date.getUTCHours(),
|
|
58
|
+
minutes: date.getUTCMinutes(),
|
|
59
|
+
seconds: date.getUTCSeconds(),
|
|
60
|
+
milliseconds: date.getUTCMilliseconds()
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT , outputObject]]))]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
2
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
3
|
+
import { Event } from '../../../model/Event';
|
|
4
|
+
import { EventResult } from "../../../model/EventResult";
|
|
5
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
6
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
7
|
+
import { Parameter } from "../../../model/Parameter";
|
|
8
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
9
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
10
|
+
import { MapUtil } from "../../../util/MapUtil";
|
|
11
|
+
import { isNullValue } from "../../../util/NullCheck";
|
|
12
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
13
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const VALUE : string = "isoDate";
|
|
17
|
+
|
|
18
|
+
const OUTPUT : string = "output";
|
|
19
|
+
|
|
20
|
+
const SIGNATURE = new FunctionSignature('IsValidISODate')
|
|
21
|
+
.setNamespace(Namespaces.DATE)
|
|
22
|
+
.setParameters(MapUtil.of(VALUE, Parameter.of(VALUE, Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
|
|
23
|
+
.setEvents(MapUtil.of(OUTPUT , new Event(OUTPUT , MapUtil.of(OUTPUT, Schema.ofBoolean(OUTPUT)))));
|
|
24
|
+
|
|
25
|
+
export class IsValidISODate extends AbstractFunction{
|
|
26
|
+
|
|
27
|
+
public getSignature(): FunctionSignature {
|
|
28
|
+
return SIGNATURE;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
32
|
+
|
|
33
|
+
var date = context.getArguments()?.get(VALUE);
|
|
34
|
+
|
|
35
|
+
if(isNullValue(date))
|
|
36
|
+
throw new KIRuntimeException("Please provide a valid date object");
|
|
37
|
+
|
|
38
|
+
return new FunctionOutput([ EventResult.of(OUTPUT , MapUtil.of( OUTPUT , ValidDateTimeUtil.validate(date)))]);
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
2
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
3
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
4
|
+
import { Parameter } from "../../../model/Parameter";
|
|
5
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
6
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
7
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
8
|
+
import { Event } from "../../../model/Event";
|
|
9
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
10
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
11
|
+
import { EventResult } from "../../../model/EventResult";
|
|
12
|
+
|
|
13
|
+
const VALUE = "isoDates";
|
|
14
|
+
|
|
15
|
+
const OUTPUT = "result";
|
|
16
|
+
|
|
17
|
+
const ERROR_MESSAGE = "Please provide a valid date";
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const SIGNATURE : FunctionSignature = new FunctionSignature('MaximumTimestamp')
|
|
22
|
+
.setNamespace(Namespaces.DATE)
|
|
23
|
+
.setParameters(new Map([[VALUE, Parameter.of(VALUE, Schema.ofString(VALUE).setRef(Namespaces.DATE + ".timeStamp")).setVariableArgument(true)]]))
|
|
24
|
+
.setEvents(new Map([[OUTPUT, new Event(OUTPUT, new Map([[OUTPUT, Schema.ofString(OUTPUT).setRef(Namespaces.DATE + ".timeStamp")]]))]]));
|
|
25
|
+
|
|
26
|
+
export class MaximumTimestamp extends AbstractFunction {
|
|
27
|
+
|
|
28
|
+
public getSignature(): FunctionSignature {
|
|
29
|
+
return SIGNATURE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
33
|
+
|
|
34
|
+
const dates = context?.getArguments()?.get(VALUE);
|
|
35
|
+
|
|
36
|
+
const size = dates.length;
|
|
37
|
+
|
|
38
|
+
if(size === 0){
|
|
39
|
+
throw new KIRuntimeException(ERROR_MESSAGE)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
else if (size == 1) {
|
|
43
|
+
|
|
44
|
+
const firstDate: string = dates[0];
|
|
45
|
+
|
|
46
|
+
if (!ValidDateTimeUtil.validate(firstDate))
|
|
47
|
+
|
|
48
|
+
throw new KIRuntimeException(ERROR_MESSAGE);
|
|
49
|
+
|
|
50
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, firstDate]]))]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let maxIndex: number = 0;
|
|
54
|
+
let max : number = new Date(dates[0]).getTime();
|
|
55
|
+
|
|
56
|
+
for(let i=1;i<size;i++){
|
|
57
|
+
|
|
58
|
+
const date: string = dates[i];
|
|
59
|
+
|
|
60
|
+
if(!ValidDateTimeUtil.validate(date))
|
|
61
|
+
throw new KIRuntimeException(ERROR_MESSAGE);
|
|
62
|
+
|
|
63
|
+
const current: number = new Date(date).getTime();
|
|
64
|
+
|
|
65
|
+
if(current > max){
|
|
66
|
+
max = current;
|
|
67
|
+
maxIndex = i;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, dates[maxIndex]]]))]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
2
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
3
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
4
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
5
|
+
import { Parameter } from "../../../model/Parameter";
|
|
6
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
7
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
8
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
9
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
10
|
+
import { EventResult } from "../../../model/EventResult";
|
|
11
|
+
import { Event } from "../../../model/Event";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const VALUE: string = "isoDates";
|
|
16
|
+
|
|
17
|
+
const OUTPUT: string = "result";
|
|
18
|
+
|
|
19
|
+
const ERROR_MESSAGE: string = "Please provide a valid date";
|
|
20
|
+
|
|
21
|
+
const SIGNATURE : FunctionSignature = new FunctionSignature('MinimumTimestamp')
|
|
22
|
+
.setNamespace(Namespaces.DATE)
|
|
23
|
+
.setParameters(new Map([[VALUE, Parameter.of(VALUE, Schema.ofString(VALUE).setRef(Namespaces.DATE + ".timeStamp")).setVariableArgument(true)]]))
|
|
24
|
+
.setEvents(new Map([[OUTPUT , new Event(OUTPUT, new Map([[OUTPUT, Schema.ofString(OUTPUT).setRef(Namespaces.DATE + ".timeStamp")]]))]]));
|
|
25
|
+
|
|
26
|
+
export class MinimumTimestamp extends AbstractFunction{
|
|
27
|
+
|
|
28
|
+
public getSignature(): FunctionSignature {
|
|
29
|
+
return SIGNATURE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
33
|
+
|
|
34
|
+
const dates = context?.getArguments()?.get(VALUE);
|
|
35
|
+
|
|
36
|
+
const size = dates.length;
|
|
37
|
+
|
|
38
|
+
if(size === 0){
|
|
39
|
+
throw new KIRuntimeException(ERROR_MESSAGE)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
else if (size == 1) {
|
|
43
|
+
|
|
44
|
+
const firstDate: string = dates[0];
|
|
45
|
+
|
|
46
|
+
if (!ValidDateTimeUtil.validate(firstDate))
|
|
47
|
+
|
|
48
|
+
throw new KIRuntimeException(ERROR_MESSAGE);
|
|
49
|
+
|
|
50
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, firstDate]]))]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let minIndex: number = 0;
|
|
54
|
+
let min : number = new Date(dates[0]).getTime();
|
|
55
|
+
|
|
56
|
+
for(let i=1;i<size;i++){
|
|
57
|
+
|
|
58
|
+
const date: string = dates[i];
|
|
59
|
+
|
|
60
|
+
if(!ValidDateTimeUtil.validate(date))
|
|
61
|
+
throw new KIRuntimeException(ERROR_MESSAGE);
|
|
62
|
+
|
|
63
|
+
const current: number = new Date(date).getTime();
|
|
64
|
+
|
|
65
|
+
if(current < min){
|
|
66
|
+
min = current;
|
|
67
|
+
minIndex = i;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, dates[minIndex]]]))]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Function } from '../function/Function';
|
|
2
2
|
import { ArrayFunctionRepository } from '../function/system/array/ArrayFunctionRepository';
|
|
3
|
+
import { Join } from '../function/system/array/Join';
|
|
3
4
|
import { Create } from '../function/system/context/Create';
|
|
4
5
|
import { Get } from '../function/system/context/Get';
|
|
5
6
|
import { SetFunction } from '../function/system/context/SetFunction';
|
|
@@ -13,6 +14,7 @@ import { MathFunctionRepository } from '../function/system/math/MathFunctionRepo
|
|
|
13
14
|
import { ObjectFunctionRepository } from '../function/system/object/ObjectFunctionRepository';
|
|
14
15
|
import { Print } from '../function/system/Print';
|
|
15
16
|
import { StringFunctionRepository } from '../function/system/string/StringFunctionRepository';
|
|
17
|
+
import { DateFunctionRepository } from '../function/system/date/DateFunctionRepository';
|
|
16
18
|
import { Wait } from '../function/system/Wait';
|
|
17
19
|
import { HybridRepository } from '../HybridRepository';
|
|
18
20
|
import { Namespaces } from '../namespaces/Namespaces';
|
|
@@ -39,6 +41,7 @@ const map: Map<string, Map<string, Function>> = new Map([
|
|
|
39
41
|
mapEntry(new GenerateEvent()),
|
|
40
42
|
mapEntry(new Print()),
|
|
41
43
|
mapEntry(new Wait()),
|
|
44
|
+
mapEntry(new Join()),
|
|
42
45
|
]),
|
|
43
46
|
],
|
|
44
47
|
]);
|
|
@@ -65,6 +68,7 @@ export class KIRunFunctionRepository extends HybridRepository<Function> {
|
|
|
65
68
|
new StringFunctionRepository(),
|
|
66
69
|
new ArrayFunctionRepository(),
|
|
67
70
|
new ObjectFunctionRepository(),
|
|
71
|
+
new DateFunctionRepository(),
|
|
68
72
|
);
|
|
69
73
|
}
|
|
70
74
|
}
|
|
@@ -12,6 +12,7 @@ const map: Map<string, Schema> = new Map([
|
|
|
12
12
|
['long', Schema.ofLong('long').setNamespace(Namespaces.SYSTEM)],
|
|
13
13
|
['number', Schema.ofNumber('number').setNamespace(Namespaces.SYSTEM)],
|
|
14
14
|
['string', Schema.ofString('string').setNamespace(Namespaces.SYSTEM)],
|
|
15
|
+
['Date.timeStamp', Schema.ofString('timeStamp').setNamespace(Namespaces.DATE)],
|
|
15
16
|
[Parameter.EXPRESSION.getName()!, Parameter.EXPRESSION],
|
|
16
17
|
[Schema.NULL.getName()!, Schema.NULL],
|
|
17
18
|
[Schema.SCHEMA.getName()!, Schema.SCHEMA],
|
|
@@ -96,7 +96,7 @@ export class ExpressionEvaluator {
|
|
|
96
96
|
|
|
97
97
|
public constructor(exp: Expression | string) {
|
|
98
98
|
if (exp instanceof Expression) {
|
|
99
|
-
this.exp = exp
|
|
99
|
+
this.exp = exp;
|
|
100
100
|
this.expression = this.exp.getExpression();
|
|
101
101
|
} else {
|
|
102
102
|
this.expression = exp;
|
|
@@ -163,7 +163,7 @@ export class ExpressionEvaluator {
|
|
|
163
163
|
): string {
|
|
164
164
|
let newExpression = expression;
|
|
165
165
|
|
|
166
|
-
for (
|
|
166
|
+
for (let tuple of tuples.toArray()) {
|
|
167
167
|
if (tuple.getT2() == -1)
|
|
168
168
|
throw new ExpressionEvaluationException(
|
|
169
169
|
expression,
|
|
@@ -212,14 +212,14 @@ export class ExpressionEvaluator {
|
|
|
212
212
|
} else if (operator == Operation.CONDITIONAL_TERNARY_OPERATOR) {
|
|
213
213
|
const token2: ExpressionToken = tokens.pop();
|
|
214
214
|
const token3: ExpressionToken = tokens.pop();
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
let v1 = this.getValueFromToken(valuesMap, token3);
|
|
216
|
+
let v2 = this.getValueFromToken(valuesMap, token2);
|
|
217
|
+
let v3 = this.getValueFromToken(valuesMap, token);
|
|
218
218
|
tokens.push(this.applyTernaryOperation(operator, v1, v2, v3));
|
|
219
219
|
} else {
|
|
220
220
|
const token2: ExpressionToken = tokens.pop();
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
let v1 = this.getValueFromToken(valuesMap, token2);
|
|
222
|
+
let v2 = this.getValueFromToken(valuesMap, token);
|
|
223
223
|
tokens.push(this.applyBinaryOperation(operator, v1, v2));
|
|
224
224
|
}
|
|
225
225
|
}
|
|
@@ -235,8 +235,7 @@ export class ExpressionEvaluator {
|
|
|
235
235
|
);
|
|
236
236
|
|
|
237
237
|
const token: ExpressionToken = tokens.get(0);
|
|
238
|
-
if (token instanceof ExpressionTokenValue)
|
|
239
|
-
return (token as ExpressionTokenValue).getElement();
|
|
238
|
+
if (token instanceof ExpressionTokenValue) return token.getElement();
|
|
240
239
|
else if (!(token instanceof Expression)) return this.getValueFromToken(valuesMap, token);
|
|
241
240
|
|
|
242
241
|
throw new ExecutionException(
|
|
@@ -262,7 +261,7 @@ export class ExpressionEvaluator {
|
|
|
262
261
|
objTokens.push(
|
|
263
262
|
new ExpressionTokenValue(
|
|
264
263
|
token.toString(),
|
|
265
|
-
this.evaluateExpression(token
|
|
264
|
+
this.evaluateExpression(token, valuesMap),
|
|
266
265
|
),
|
|
267
266
|
);
|
|
268
267
|
else if (token) objTokens.push(token);
|
|
@@ -275,7 +274,7 @@ export class ExpressionEvaluator {
|
|
|
275
274
|
objTokens.push(
|
|
276
275
|
new ExpressionTokenValue(
|
|
277
276
|
token.toString(),
|
|
278
|
-
this.evaluateExpression(token
|
|
277
|
+
this.evaluateExpression(token, valuesMap),
|
|
279
278
|
),
|
|
280
279
|
);
|
|
281
280
|
else objTokens.push(token);
|
|
@@ -296,7 +295,7 @@ export class ExpressionEvaluator {
|
|
|
296
295
|
|
|
297
296
|
let sb: StringBuilder = new StringBuilder(
|
|
298
297
|
objToken instanceof ExpressionTokenValue
|
|
299
|
-
?
|
|
298
|
+
? objToken.getTokenValue()
|
|
300
299
|
: objToken.toString(),
|
|
301
300
|
);
|
|
302
301
|
|
|
@@ -305,7 +304,7 @@ export class ExpressionEvaluator {
|
|
|
305
304
|
operator = objOperations.pop();
|
|
306
305
|
sb.append(operator.getOperator()).append(
|
|
307
306
|
objToken instanceof ExpressionTokenValue
|
|
308
|
-
?
|
|
307
|
+
? objToken.getTokenValue()
|
|
309
308
|
: objToken.toString(),
|
|
310
309
|
);
|
|
311
310
|
if (operator == Operation.ARRAY_OPERATOR) sb.append(']');
|
|
@@ -414,9 +413,9 @@ export class ExpressionEvaluator {
|
|
|
414
413
|
token: ExpressionToken,
|
|
415
414
|
): any {
|
|
416
415
|
if (token instanceof Expression) {
|
|
417
|
-
return this.evaluateExpression(token
|
|
416
|
+
return this.evaluateExpression(token, valuesMap);
|
|
418
417
|
} else if (token instanceof ExpressionTokenValue) {
|
|
419
|
-
return
|
|
418
|
+
return token.getElement();
|
|
420
419
|
}
|
|
421
420
|
return this.getValue(token.getExpression(), valuesMap);
|
|
422
421
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
|
|
2
|
+
export class ValidDateTimeUtil{
|
|
3
|
+
|
|
4
|
+
private constructor(){
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
public static isLeapYear( year : number) : boolean{
|
|
8
|
+
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public static validYearRange( year : number) :boolean {
|
|
12
|
+
return year < 275761 && year > -271821;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static validMonthRange( month: number) : boolean{
|
|
16
|
+
return month <= 12 && month > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static validDate( year : number, month: number, date: number) : boolean{
|
|
20
|
+
|
|
21
|
+
if (date <= 0 || month <= 0)
|
|
22
|
+
return false;
|
|
23
|
+
|
|
24
|
+
switch (month) {
|
|
25
|
+
case 2:
|
|
26
|
+
return ValidDateTimeUtil.validYearRange(year) && ValidDateTimeUtil.validMonthRange(month) && (ValidDateTimeUtil.isLeapYear(year) && date < 30)
|
|
27
|
+
|| (!ValidDateTimeUtil.isLeapYear(year) && date < 29);
|
|
28
|
+
|
|
29
|
+
case 4:
|
|
30
|
+
case 6:
|
|
31
|
+
case 9:
|
|
32
|
+
case 11:
|
|
33
|
+
return ValidDateTimeUtil.validYearRange(year) && ValidDateTimeUtil.validMonthRange(month) && date <= 30;
|
|
34
|
+
|
|
35
|
+
default:
|
|
36
|
+
return ValidDateTimeUtil.validYearRange(year) && ValidDateTimeUtil.validMonthRange(month) && date <= 31;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
public static validHourRange( hour: number) : boolean{
|
|
43
|
+
return hour < 24 && hour >= 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static validMinuteSecondRange( minute : number) : boolean{
|
|
47
|
+
return minute < 60 && minute >= 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static validMilliSecondRange( millis: number) : boolean {
|
|
51
|
+
return millis < 1000 && millis >= 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static validateWithOptionalMillis( portion: string): boolean {
|
|
55
|
+
|
|
56
|
+
return ValidDateTimeUtil.validMilliSecondRange(ValidDateTimeUtil.convertToInt(portion.substring(1, 4))) && ValidDateTimeUtil.validateLocalTime(portion.substring(4));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public getYear( date: string) : number{
|
|
60
|
+
|
|
61
|
+
const first: string = date.charAt(0);
|
|
62
|
+
if (first == '+' || first == '-') {
|
|
63
|
+
const year : number = ValidDateTimeUtil.convertToInt(date.substring(1, 7));
|
|
64
|
+
return first == '-' ? year * -1 : year;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return ValidDateTimeUtil.convertToInt(date.substring(0, 4));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public static validateLocalTime( offset: string ) : boolean{
|
|
71
|
+
|
|
72
|
+
if (offset.charAt(0) == 'Z')
|
|
73
|
+
return true;
|
|
74
|
+
|
|
75
|
+
if (offset.length != 6)
|
|
76
|
+
return false;
|
|
77
|
+
|
|
78
|
+
return (offset.charAt(0) == '+' || offset.charAt(0) == '-')
|
|
79
|
+
&& (ValidDateTimeUtil.validHourRange(ValidDateTimeUtil.convertToInt(offset.substring(1, 3))) && offset.charAt(3) == ':'
|
|
80
|
+
&& ValidDateTimeUtil.validMinuteSecondRange(ValidDateTimeUtil.convertToInt(offset.substring(4, offset.length - 1))));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public static validate( date: string) : boolean {
|
|
84
|
+
|
|
85
|
+
if (date.length < 20 || date.length > 32)
|
|
86
|
+
return false; // as date time should have minimum of 20 characters and maximum of 32 characters
|
|
87
|
+
|
|
88
|
+
const first: string = date.charAt(0); // checking first index whether '+' or '-' or any digit
|
|
89
|
+
|
|
90
|
+
if (first == '+' || first == '-') {
|
|
91
|
+
|
|
92
|
+
const a : boolean = date.charAt(7) == '-' && date.charAt(10) == '-' && date.charAt(13) == 'T'
|
|
93
|
+
&& date.charAt(16) == ':' && date.charAt(19) == ':' && date.charAt(22) == '.';
|
|
94
|
+
|
|
95
|
+
return a && ValidDateTimeUtil.validDate(ValidDateTimeUtil.convertToInt(date.substring(1, 7)), ValidDateTimeUtil.convertToInt(date.substring(8, 10)),
|
|
96
|
+
ValidDateTimeUtil.convertToInt(date.substring(11, 13))) && ValidDateTimeUtil.validHourRange(ValidDateTimeUtil.convertToInt(date.substring(14, 16)))
|
|
97
|
+
&& ValidDateTimeUtil.validMinuteSecondRange(ValidDateTimeUtil.convertToInt(date.substring(17, 19)))
|
|
98
|
+
&& ValidDateTimeUtil.validMinuteSecondRange(ValidDateTimeUtil.convertToInt(date.substring(20, 22)))
|
|
99
|
+
&& ValidDateTimeUtil.validateWithOptionalMillis(date.substring(22));
|
|
100
|
+
} else {
|
|
101
|
+
|
|
102
|
+
const a : boolean = date.charAt(4) == '-' && date.charAt(7) == '-' && date.charAt(10) == 'T'
|
|
103
|
+
&& date.charAt(13) == ':' && date.charAt(16) == ':' && date.charAt(19) == '.';
|
|
104
|
+
|
|
105
|
+
return a && ValidDateTimeUtil.validDate(ValidDateTimeUtil.convertToInt(date.substring(0, 4)), ValidDateTimeUtil.convertToInt(date.substring(5, 7)),
|
|
106
|
+
ValidDateTimeUtil.convertToInt(date.substring(8, 10))) && ValidDateTimeUtil.validHourRange(ValidDateTimeUtil.convertToInt(date.substring(11, 13)))
|
|
107
|
+
&& ValidDateTimeUtil.validMinuteSecondRange(ValidDateTimeUtil.convertToInt(date.substring(14, 16)))
|
|
108
|
+
&& ValidDateTimeUtil.validMinuteSecondRange(ValidDateTimeUtil.convertToInt(date.substring(17, 19)))
|
|
109
|
+
&& ValidDateTimeUtil.validateWithOptionalMillis(date.substring(19));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private static convertToInt( num : string ) : number{ // adding exception
|
|
115
|
+
var parsed = parseInt(num);
|
|
116
|
+
return isNaN(parsed) ? Number.MIN_VALUE : parsed;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|