@fincity/kirun-js 2.3.1 → 2.4.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/__tests__/engine/function/system/date/AddTimeTest.ts +115 -0
- 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/function/system/date/SubtractTimeTest.ts +95 -0
- package/__tests__/engine/repository/RepositoryFilterTest.ts +5 -4
- 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/generator/generateValidationCSV.ts +87 -0
- package/generator/validation-js.csv +1146 -0
- package/package.json +4 -4
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +2 -0
- package/src/engine/function/system/date/AbstractDateFunction.ts +162 -0
- package/src/engine/function/system/date/DateFunctionRepository.ts +159 -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/function/system/math/MathFunctionRepository.ts +9 -9
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fincity/kirun-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Javascript Runtime for Kinetic Instructions",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"@parcel/transformer-typescript-types": "^2.7.0",
|
|
36
36
|
"@tsconfig/recommended": "^1.0.1",
|
|
37
37
|
"@types/jest": "^28.1.8",
|
|
38
|
+
"jest": "^29.5.0",
|
|
38
39
|
"parcel": "^2.7.0",
|
|
39
40
|
"prettier": "2.7.1",
|
|
40
|
-
"
|
|
41
|
+
"ts-jest": "^29.1.0",
|
|
41
42
|
"ts-loader": "^9.3.1",
|
|
42
|
-
"
|
|
43
|
-
"ts-jest": "^29.1.0"
|
|
43
|
+
"typescript": "^5.1.3"
|
|
44
44
|
},
|
|
45
45
|
"jest": {
|
|
46
46
|
"transform": {
|
|
@@ -33,6 +33,7 @@ import { Insert } from './Insert';
|
|
|
33
33
|
import { InsertLast } from './InsertLast';
|
|
34
34
|
import { RemoveDuplicates } from './RemoveDuplicates';
|
|
35
35
|
import { ArrayToObject } from './ArrayToObject';
|
|
36
|
+
import { Join } from './Join';
|
|
36
37
|
|
|
37
38
|
export class ArrayFunctionRepository implements Repository<Function> {
|
|
38
39
|
private static readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
|
|
@@ -66,6 +67,7 @@ export class ArrayFunctionRepository implements Repository<Function> {
|
|
|
66
67
|
mapEntry(new InsertLast()),
|
|
67
68
|
mapEntry(new RemoveDuplicates()),
|
|
68
69
|
mapEntry(new ArrayToObject()),
|
|
70
|
+
mapEntry(new Join())
|
|
69
71
|
);
|
|
70
72
|
|
|
71
73
|
private static readonly filterableNames = Array.from(
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
2
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
3
|
+
import { Event } from "../../../model/Event";
|
|
4
|
+
import { Parameter } from "../../../model/Parameter";
|
|
5
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
6
|
+
import { MapUtil } from "../../../util/MapUtil";
|
|
7
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
8
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
9
|
+
import { EventResult } from "../../../model/EventResult";
|
|
10
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
11
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
12
|
+
import { isNullValue } from "../../../util/NullCheck";
|
|
13
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
14
|
+
import { Function } from "../../../../engine/function/Function";
|
|
15
|
+
|
|
16
|
+
export abstract class AbstractDateFunction extends AbstractFunction {
|
|
17
|
+
|
|
18
|
+
private signature: FunctionSignature;
|
|
19
|
+
|
|
20
|
+
public static readonly EVENT_RESULT_NAME: string = 'result';
|
|
21
|
+
|
|
22
|
+
public static readonly PARAMETER_DATE_NAME: string = 'isoDate';
|
|
23
|
+
|
|
24
|
+
public static readonly PARAMETER_FIELD_NAME: string = 'value';
|
|
25
|
+
|
|
26
|
+
public static readonly PARAMETER_INT_NAME: string = "intValue";
|
|
27
|
+
|
|
28
|
+
public static readonly PARAMETER_UNIT_NAME: string = "unit";
|
|
29
|
+
|
|
30
|
+
protected static readonly PARAMETER_DATE: Parameter = new Parameter(
|
|
31
|
+
AbstractDateFunction.PARAMETER_DATE_NAME,
|
|
32
|
+
Schema.ofString(this.PARAMETER_DATE_NAME).setRef(Namespaces.DATE + ".timeStamp")
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
protected static readonly PARAMETER_FIELD : Parameter = new Parameter(
|
|
36
|
+
AbstractDateFunction.PARAMETER_FIELD_NAME,
|
|
37
|
+
Schema.ofInteger(this.PARAMETER_FIELD_NAME)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
protected static readonly PARAMETER_INT : Parameter = new Parameter(
|
|
41
|
+
AbstractDateFunction.PARAMETER_INT_NAME,
|
|
42
|
+
Schema.ofInteger(this.PARAMETER_INT_NAME)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
protected static readonly PARAMETER_UNIT : Parameter = new Parameter(
|
|
46
|
+
AbstractDateFunction.PARAMETER_UNIT_NAME,
|
|
47
|
+
Schema.ofString(this.PARAMETER_UNIT_NAME)
|
|
48
|
+
.setEnums(["YEAR" , "MONTH" , "DAY" , "HOUR" , "MINUTE" , "SECOND" , "MILLISECOND"])
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
protected static readonly EVENT_INT: Event = new Event(
|
|
52
|
+
Event.OUTPUT,
|
|
53
|
+
MapUtil.of(
|
|
54
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
55
|
+
Schema.ofInteger(AbstractDateFunction.EVENT_RESULT_NAME),
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
protected static readonly EVENT_BOOLEAN: Event = new Event(
|
|
60
|
+
Event.OUTPUT,
|
|
61
|
+
MapUtil.of(
|
|
62
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
63
|
+
Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME)
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
protected static readonly EVENT_DATE : Event = new Event(
|
|
68
|
+
Event.OUTPUT,
|
|
69
|
+
MapUtil.of(
|
|
70
|
+
AbstractDateFunction.EVENT_RESULT_NAME,
|
|
71
|
+
Schema.ofString(AbstractDateFunction.EVENT_RESULT_NAME).setRef(Namespaces.DATE + ".timeStamp")
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
public getSignature(): FunctionSignature {
|
|
76
|
+
return this.signature;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
81
|
+
|
|
82
|
+
super();
|
|
83
|
+
const paramMap: Map<string, Parameter> = new Map();
|
|
84
|
+
parameter.forEach((e) => paramMap.set(e.getParameterName(), e));
|
|
85
|
+
|
|
86
|
+
this.signature = new FunctionSignature(functionName)
|
|
87
|
+
.setNamespace(namespace)
|
|
88
|
+
.setParameters(paramMap)
|
|
89
|
+
.setEvents(MapUtil.of(event.getName(), event));
|
|
90
|
+
|
|
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
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
})(Namespaces.DATE, name, AbstractDateFunction.EVENT_BOOLEAN, AbstractDateFunction.PARAMETER_DATE)];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public static ofEntryDateAndIntegerOutput(name: string, fun: (date: string) => number) : [string, Function] {
|
|
117
|
+
|
|
118
|
+
return [name, new (class extends AbstractDateFunction {
|
|
119
|
+
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
120
|
+
super(namespace, functionName, event, ...parameter);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
124
|
+
|
|
125
|
+
const date = context.getArguments()?.get(AbstractDateFunction.PARAMETER_DATE_NAME);
|
|
126
|
+
|
|
127
|
+
if(isNullValue(date) || !ValidDateTimeUtil.validate(date))
|
|
128
|
+
throw new KIRuntimeException("Please provide a valid date object");
|
|
129
|
+
|
|
130
|
+
return new FunctionOutput([EventResult.outputOf(MapUtil.of( AbstractDateFunction.EVENT_RESULT_NAME, fun(date)))])
|
|
131
|
+
}
|
|
132
|
+
})(Namespaces.DATE, name, AbstractDateFunction.EVENT_INT, AbstractDateFunction.PARAMETER_DATE)];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public static ofEntryDateWithIntegerUnitWithOutputName( functionName: string,
|
|
136
|
+
func: (date: string, amount: number, unit: string) => string): [string, Function] {
|
|
137
|
+
return [functionName, new (class extends AbstractDateFunction {
|
|
138
|
+
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
139
|
+
super(namespace, functionName, event, ...parameter);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
143
|
+
|
|
144
|
+
const date = context.getArguments()?.get(AbstractDateFunction.PARAMETER_DATE_NAME);
|
|
145
|
+
|
|
146
|
+
if(isNullValue(date) || !ValidDateTimeUtil.validate(date))
|
|
147
|
+
throw new KIRuntimeException("Please provide a valid date object");
|
|
148
|
+
|
|
149
|
+
const value = context.getArguments()?.get(AbstractDateFunction.PARAMETER_INT_NAME);
|
|
150
|
+
|
|
151
|
+
const unit = context.getArguments()?.get(AbstractDateFunction.PARAMETER_UNIT_NAME);
|
|
152
|
+
|
|
153
|
+
return new FunctionOutput([EventResult.outputOf(MapUtil.of( AbstractDateFunction.EVENT_RESULT_NAME, func(date, value , unit)))]);
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
})(Namespaces.DATE, functionName, AbstractDateFunction.EVENT_DATE,
|
|
157
|
+
AbstractDateFunction.PARAMETER_DATE, AbstractDateFunction.PARAMETER_INT, AbstractDateFunction.PARAMETER_UNIT)];
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
2
|
+
import { Repository } from "../../../Repository";
|
|
3
|
+
import { MapUtil } from "../../../util/MapUtil";
|
|
4
|
+
import { AbstractDateFunction } from "./AbstractDateFunction";
|
|
5
|
+
import { Function } from '../../Function';
|
|
6
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
7
|
+
import mapEntry from '../../../util/mapEntry';
|
|
8
|
+
import { DateToEpoch } from "./DateToEpoch";
|
|
9
|
+
import { DifferenceOfTimestamps } from "./DifferenceOfTimestamps";
|
|
10
|
+
import { EpochToDate } from "./EpochToDate";
|
|
11
|
+
import { GetCurrentTimeStamp } from "./GetCurrentTimeStamp";
|
|
12
|
+
import { GetTimeAsArray } from "./GetTimeAsArray";
|
|
13
|
+
import { GetTimeAsObject } from "./GetTimeAsObject";
|
|
14
|
+
import { IsValidISODate } from "./IsValidISODate";
|
|
15
|
+
import { MaximumTimestamp } from "./MaximumTimestamp";
|
|
16
|
+
import { MinimumTimestamp } from "./MinimumTimestamp";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export class DateFunctionRepository implements Repository<Function> {
|
|
20
|
+
|
|
21
|
+
private static readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
|
|
22
|
+
|
|
23
|
+
mapEntry(new DateToEpoch()),
|
|
24
|
+
mapEntry(new EpochToDate()),
|
|
25
|
+
mapEntry(new GetCurrentTimeStamp()),
|
|
26
|
+
mapEntry(new DifferenceOfTimestamps()),
|
|
27
|
+
mapEntry(new IsValidISODate()),
|
|
28
|
+
mapEntry(new GetTimeAsArray()),
|
|
29
|
+
mapEntry(new GetTimeAsObject()),
|
|
30
|
+
mapEntry(new MaximumTimestamp()),
|
|
31
|
+
mapEntry(new MinimumTimestamp()),
|
|
32
|
+
|
|
33
|
+
AbstractDateFunction.ofEntryDateAndBooleanOutput("IsLeapYear", date => {
|
|
34
|
+
const year = new Date(date).getUTCFullYear();
|
|
35
|
+
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
|
|
36
|
+
}),
|
|
37
|
+
|
|
38
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetDate", date => new Date(date).getUTCDate()),
|
|
39
|
+
|
|
40
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetDay", date => new Date(date).getUTCDay()),
|
|
41
|
+
|
|
42
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetFullYear", date => new Date(date).getUTCFullYear()),
|
|
43
|
+
|
|
44
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetMonth", date => new Date(date).getUTCMonth()),
|
|
45
|
+
|
|
46
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetHours", date => new Date(date).getUTCHours()),
|
|
47
|
+
|
|
48
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetMinutes", date => new Date(date).getUTCMinutes()),
|
|
49
|
+
|
|
50
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetSeconds", date => new Date(date).getUTCSeconds()),
|
|
51
|
+
|
|
52
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetMilliSeconds", date => new Date(date).getUTCMilliseconds()),
|
|
53
|
+
|
|
54
|
+
AbstractDateFunction.ofEntryDateAndIntegerOutput("GetTime" , date => new Date(date).getTime()),
|
|
55
|
+
|
|
56
|
+
AbstractDateFunction.ofEntryDateWithIntegerUnitWithOutputName("AddTime",
|
|
57
|
+
(date , value , unit) => this.changeAmountToUnit(date, unit, value, true)
|
|
58
|
+
),
|
|
59
|
+
|
|
60
|
+
AbstractDateFunction.ofEntryDateWithIntegerUnitWithOutputName("SubtractTime",
|
|
61
|
+
(date , value , unit) => this.changeAmountToUnit(date, unit, value, false)
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
private static readonly filterableNames = Array.from(
|
|
66
|
+
DateFunctionRepository.repoMap.values(),
|
|
67
|
+
).map((e) => e.getSignature().getFullName());
|
|
68
|
+
|
|
69
|
+
private static changeAmountToUnit(inputDate: string , unit: string, value: number, isAdd: boolean): string{
|
|
70
|
+
|
|
71
|
+
const amount = isAdd ? value : -1 * value;
|
|
72
|
+
|
|
73
|
+
const date = this.getFullUTCDate(inputDate);
|
|
74
|
+
const originalOffset = this.getTimezoneOffset(inputDate);
|
|
75
|
+
|
|
76
|
+
switch(unit){
|
|
77
|
+
|
|
78
|
+
case "MILLISECOND" : date.setMilliseconds(date.getMilliseconds() + amount);
|
|
79
|
+
break;
|
|
80
|
+
case "SECOND" : date.setSeconds(date.getSeconds() + amount);
|
|
81
|
+
break;
|
|
82
|
+
case "MINUTE" : date.setMinutes(date.getMinutes() + amount);
|
|
83
|
+
break;
|
|
84
|
+
case "HOUR" : date.setHours(date.getHours() + amount);
|
|
85
|
+
break;
|
|
86
|
+
case "DAY" : date.setDate(date.getDate() + amount);
|
|
87
|
+
break;
|
|
88
|
+
case "MONTH" : date.setMonth(date.getMonth() + amount);
|
|
89
|
+
break;
|
|
90
|
+
case "YEAR" : date.setFullYear(date.getFullYear() + amount);
|
|
91
|
+
break;
|
|
92
|
+
default :
|
|
93
|
+
throw new KIRuntimeException("No such unit: " + unit)
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return this.formatDate(date, originalOffset);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private static getTimezoneOffset(dateString: string): string {
|
|
101
|
+
const lastChar = dateString.charAt(dateString.length - 1);
|
|
102
|
+
if (lastChar === 'Z') return '+00:00';
|
|
103
|
+
|
|
104
|
+
const offsetStart = dateString.indexOf('+') !== -1 ? dateString.lastIndexOf('+') : dateString.lastIndexOf('-');
|
|
105
|
+
if (offsetStart === -1) return '+00:00';
|
|
106
|
+
|
|
107
|
+
let offset = dateString.substring(offsetStart);
|
|
108
|
+
if (offset.length === 3) {
|
|
109
|
+
offset = offset.substring(0, 1) + '0' + offset.substring(1) + ':00';
|
|
110
|
+
} else if (offset.length === 5) {
|
|
111
|
+
offset = offset.substring(0, 3) + ':' + offset.substring(3);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return offset;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private static getFullUTCDate(inputDate:string): Date {
|
|
118
|
+
|
|
119
|
+
if(inputDate.lastIndexOf('+') !== -1)
|
|
120
|
+
inputDate = inputDate.substring(0, inputDate.lastIndexOf('+')) + 'Z';
|
|
121
|
+
else if(inputDate.lastIndexOf('-') !== -1)
|
|
122
|
+
inputDate = inputDate.substring(0, inputDate.lastIndexOf('-')) + 'Z';
|
|
123
|
+
|
|
124
|
+
const date: Date = new Date(inputDate);
|
|
125
|
+
|
|
126
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1,
|
|
127
|
+
date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(),
|
|
128
|
+
date.getUTCSeconds(), date.getUTCMilliseconds()));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private static formatDate(date: Date, offset: string): string {
|
|
132
|
+
const pad = (num: number) => num.toString().padStart(2, '0');
|
|
133
|
+
|
|
134
|
+
const year = date.getUTCMonth() === 0 ? date.getUTCFullYear() - 1 : date.getUTCFullYear();
|
|
135
|
+
const month = pad(date.getUTCMonth() === 0 ? 12 : date.getUTCMonth());
|
|
136
|
+
const day = pad(date.getUTCDate());
|
|
137
|
+
const hours = pad(date.getUTCHours());
|
|
138
|
+
const minutes = pad(date.getUTCMinutes());
|
|
139
|
+
const seconds = pad(date.getUTCSeconds());
|
|
140
|
+
const milliseconds = pad(date.getUTCMilliseconds());
|
|
141
|
+
|
|
142
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}${offset}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
find(namespace: string, name: string): Promise<Function | undefined> {
|
|
146
|
+
if (namespace != Namespaces.DATE) {
|
|
147
|
+
return Promise.resolve(undefined);
|
|
148
|
+
}
|
|
149
|
+
return Promise.resolve(DateFunctionRepository.repoMap.get(name));
|
|
150
|
+
}
|
|
151
|
+
filter(name: string): Promise<string[]> {
|
|
152
|
+
|
|
153
|
+
return Promise.resolve(
|
|
154
|
+
DateFunctionRepository.filterableNames.filter(
|
|
155
|
+
(e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1,
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
2
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
3
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
4
|
+
import { Event } from '../../../model/Event';
|
|
5
|
+
import { Parameter } from "../../../model/Parameter";
|
|
6
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
7
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
8
|
+
import { MapUtil } from "../../../util/MapUtil";
|
|
9
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
10
|
+
import { isNullValue } from "../../../util/NullCheck";
|
|
11
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
12
|
+
import { EventResult } from "../../../model/EventResult";
|
|
13
|
+
import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
14
|
+
|
|
15
|
+
const OUTPUT : string = "result";
|
|
16
|
+
|
|
17
|
+
const VALUE : string = "isoDate";
|
|
18
|
+
|
|
19
|
+
export class DateToEpoch extends AbstractFunction{
|
|
20
|
+
|
|
21
|
+
public getSignature(): FunctionSignature {
|
|
22
|
+
|
|
23
|
+
return new FunctionSignature('DateToEpoch')
|
|
24
|
+
.setNamespace(Namespaces.DATE)
|
|
25
|
+
.setParameters(MapUtil.of(VALUE, Parameter.of(VALUE,Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
|
|
26
|
+
.setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT, Schema.ofLong(OUTPUT)]]))]));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
30
|
+
|
|
31
|
+
var date = context.getArguments()?.get(VALUE);
|
|
32
|
+
|
|
33
|
+
if(isNullValue(date) || !ValidDateTimeUtil.validate(date))
|
|
34
|
+
throw new KIRuntimeException("Please provide a valid date object");
|
|
35
|
+
|
|
36
|
+
const epochMillis = new Date(date).getTime();
|
|
37
|
+
return new FunctionOutput([ EventResult.of(OUTPUT , MapUtil.of( OUTPUT , epochMillis))]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
2
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
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 { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
|
|
10
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
11
|
+
|
|
12
|
+
const DATE_ONE: string = "isoDateOne";
|
|
13
|
+
const DATE_TWO: string = "isoDateTwo";
|
|
14
|
+
const OUTPUT: string = "result";
|
|
15
|
+
|
|
16
|
+
const SIGNATURE: FunctionSignature = new FunctionSignature('DifferenceOfTimestamps')
|
|
17
|
+
.setNamespace(Namespaces.DATE)
|
|
18
|
+
.setParameters(
|
|
19
|
+
new Map([
|
|
20
|
+
[DATE_ONE, new Parameter(DATE_ONE, Schema.ofString(DATE_ONE).setRef(Namespaces.DATE+".timeStamp"))],
|
|
21
|
+
[DATE_TWO, new Parameter(DATE_TWO, Schema.ofString(DATE_TWO).setRef(Namespaces.DATE+".timeStamp"))]
|
|
22
|
+
])
|
|
23
|
+
);;
|
|
24
|
+
|
|
25
|
+
export class DifferenceOfTimestamps extends AbstractFunction {
|
|
26
|
+
|
|
27
|
+
public getSignature(): FunctionSignature {
|
|
28
|
+
return SIGNATURE;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
32
|
+
|
|
33
|
+
const firstDate:string = context?.getArguments()?.get(DATE_ONE);
|
|
34
|
+
const secondDate:string = context?.getArguments()?.get(DATE_TWO);
|
|
35
|
+
|
|
36
|
+
if(!ValidDateTimeUtil.validate(firstDate) || !ValidDateTimeUtil.validate(secondDate))
|
|
37
|
+
throw new KIRuntimeException("Please provide valid ISO date for both the given dates.");
|
|
38
|
+
|
|
39
|
+
const fDate: Date = new Date(firstDate);
|
|
40
|
+
const sDate: Date = new Date(secondDate);
|
|
41
|
+
|
|
42
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, (sDate.getTime() - fDate.getTime())/60000]]))]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Schema } from "../../../json/schema/Schema";
|
|
2
|
+
import { FunctionOutput } from "../../../model/FunctionOutput";
|
|
3
|
+
import { FunctionSignature } from "../../../model/FunctionSignature";
|
|
4
|
+
import { Event } from '../../../model/Event';
|
|
5
|
+
import { Parameter } from "../../../model/Parameter";
|
|
6
|
+
import { Namespaces } from "../../../namespaces/Namespaces";
|
|
7
|
+
import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
|
|
8
|
+
import { AbstractFunction } from "../../AbstractFunction";
|
|
9
|
+
import { isNullValue } from "../../../util/NullCheck";
|
|
10
|
+
import { KIRuntimeException } from "../../../exception/KIRuntimeException";
|
|
11
|
+
import { EventResult } from "../../../model/EventResult";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const VALUE = 'epoch';
|
|
15
|
+
const OUTPUT = 'date';
|
|
16
|
+
const ERROR_MSG: string = "Please provide a valid value for epoch.";
|
|
17
|
+
|
|
18
|
+
const SIGNATURE = new FunctionSignature('EpochToDate')
|
|
19
|
+
.setNamespace(Namespaces.DATE)
|
|
20
|
+
.setParameters(
|
|
21
|
+
new Map([
|
|
22
|
+
[
|
|
23
|
+
VALUE,
|
|
24
|
+
new Parameter(
|
|
25
|
+
VALUE,
|
|
26
|
+
new Schema().setAnyOf([
|
|
27
|
+
Schema.ofInteger(VALUE),
|
|
28
|
+
Schema.ofLong(VALUE),
|
|
29
|
+
Schema.ofString(VALUE),
|
|
30
|
+
]),
|
|
31
|
+
),
|
|
32
|
+
],
|
|
33
|
+
]),
|
|
34
|
+
)
|
|
35
|
+
.setEvents(
|
|
36
|
+
new Map([
|
|
37
|
+
Event.outputEventMapEntry(
|
|
38
|
+
new Map([[OUTPUT, Schema.ofRef(`${Namespaces.DATE}.timeStamp`)]]),
|
|
39
|
+
),
|
|
40
|
+
]),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export class EpochToDate extends AbstractFunction{
|
|
44
|
+
|
|
45
|
+
public getSignature(): FunctionSignature {
|
|
46
|
+
return SIGNATURE;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
50
|
+
|
|
51
|
+
var epoch : any = context.getArguments()?.get(VALUE);
|
|
52
|
+
|
|
53
|
+
if(isNullValue(epoch))
|
|
54
|
+
throw new KIRuntimeException(ERROR_MSG);
|
|
55
|
+
|
|
56
|
+
if(typeof epoch === 'boolean')
|
|
57
|
+
throw new KIRuntimeException(ERROR_MSG);
|
|
58
|
+
|
|
59
|
+
if(typeof epoch === 'string')
|
|
60
|
+
epoch = parseInt(epoch)
|
|
61
|
+
|
|
62
|
+
if(isNaN(epoch))
|
|
63
|
+
throw new KIRuntimeException(ERROR_MSG);
|
|
64
|
+
|
|
65
|
+
epoch = epoch > 999999999999 ? epoch : epoch * 1000;
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
return new FunctionOutput([
|
|
69
|
+
EventResult.outputOf(new Map([
|
|
70
|
+
[OUTPUT, new Date(epoch).toISOString()]
|
|
71
|
+
]))
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}
|
|
@@ -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
|
+
}
|