@fincity/kirun-js 2.7.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.
Files changed (100) hide show
  1. package/__tests__/engine/function/system/WaitTest.ts +1 -1
  2. package/__tests__/engine/function/system/array/AddFirstTest.ts +2 -6
  3. package/__tests__/engine/function/system/array/IndexOfTest.ts +8 -13
  4. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +9 -28
  5. package/__tests__/engine/function/system/date/AddSubtractTimeTest.ts +93 -0
  6. package/__tests__/engine/function/system/date/DateFunctionRepositoryTest.ts +96 -0
  7. package/__tests__/engine/function/system/date/DifferenceTest.ts +93 -0
  8. package/__tests__/engine/function/system/date/EpochToTimestampTest.ts +133 -0
  9. package/__tests__/engine/function/system/date/FromDateStringTest.ts +51 -0
  10. package/__tests__/engine/function/system/date/FromNowTest.ts +71 -0
  11. package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +19 -27
  12. package/__tests__/engine/function/system/date/GetNamesTest.ts +105 -0
  13. package/__tests__/engine/function/system/date/IsBetweenTest.ts +53 -0
  14. package/__tests__/engine/function/system/date/IsValidISODateTest.ts +42 -54
  15. package/__tests__/engine/function/system/date/LastFirstOfTest.ts +64 -0
  16. package/__tests__/engine/function/system/date/SetTimeZoneTest.ts +48 -0
  17. package/__tests__/engine/function/system/date/StartEndOfTest.ts +53 -0
  18. package/__tests__/engine/function/system/date/TimeAsTest.ts +24 -0
  19. package/__tests__/engine/function/system/date/TimestampToEpochTest.ts +45 -0
  20. package/__tests__/engine/function/system/date/ToDateStringTest.ts +48 -0
  21. package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
  22. package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
  23. package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
  24. package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -0
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/module.js +1 -1
  28. package/dist/module.js.map +1 -1
  29. package/dist/types.d.ts +14 -13
  30. package/dist/types.d.ts.map +1 -1
  31. package/generator/generateValidationCSV.ts +51 -42
  32. package/generator/validation-js.csv +0 -0
  33. package/package.json +9 -7
  34. package/src/engine/function/AbstractFunction.ts +1 -1
  35. package/src/engine/function/system/Print.ts +19 -5
  36. package/src/engine/function/system/Wait.ts +1 -1
  37. package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
  38. package/src/engine/function/system/array/Fill.ts +1 -1
  39. package/src/engine/function/system/array/Frequency.ts +0 -1
  40. package/src/engine/function/system/array/IndexOf.ts +4 -4
  41. package/src/engine/function/system/array/LastIndexOf.ts +3 -3
  42. package/src/engine/function/system/array/Rotate.ts +1 -1
  43. package/src/engine/function/system/array/Shuffle.ts +1 -1
  44. package/src/engine/function/system/array/Sort.ts +1 -1
  45. package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
  46. package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
  47. package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
  48. package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
  49. package/src/engine/function/system/date/FromDateString.ts +44 -0
  50. package/src/engine/function/system/date/FromNow.ts +77 -0
  51. package/src/engine/function/system/date/GetCurrent.ts +20 -0
  52. package/src/engine/function/system/date/GetNames.ts +74 -0
  53. package/src/engine/function/system/date/IsBetween.ts +62 -0
  54. package/src/engine/function/system/date/IsValidISODate.ts +54 -40
  55. package/src/engine/function/system/date/LastFirstOf.ts +72 -0
  56. package/src/engine/function/system/date/SetTimeZone.ts +43 -0
  57. package/src/engine/function/system/date/StartEndOf.ts +44 -0
  58. package/src/engine/function/system/date/TimeAs.ts +64 -0
  59. package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
  60. package/src/engine/function/system/date/ToDateString.ts +49 -0
  61. package/src/engine/function/system/date/common.ts +9 -0
  62. package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
  63. package/src/engine/function/system/math/RandomAny.ts +57 -0
  64. package/src/engine/function/system/object/ObjectConvert.ts +45 -19
  65. package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
  66. package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
  67. package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
  68. package/src/engine/json/schema/SchemaUtil.ts +1 -1
  69. package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
  70. package/src/engine/util/string/StringUtil.ts +12 -0
  71. package/tsconfig.json +1 -2
  72. package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
  73. package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
  74. package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
  75. package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
  76. package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
  77. package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
  78. package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
  79. package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
  80. package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
  81. package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
  82. package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
  83. package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
  84. package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
  85. package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
  86. package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
  87. package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
  88. package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
  89. package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
  90. package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
  91. package/src/engine/function/system/date/DateToEpoch.ts +0 -39
  92. package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
  93. package/src/engine/function/system/date/EpochToDate.ts +0 -76
  94. package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
  95. package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
  96. package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
  97. package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
  98. package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
  99. package/src/engine/function/system/math/RandomFloat.ts +0 -56
  100. package/src/engine/function/system/math/RandomInt.ts +0 -56
@@ -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.PARAMETER_ANY_NOT_NULL,
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
- var find = context?.getArguments()?.get(IndexOf.PARAMETER_ANY_NOT_NULL.getParameterName());
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.PARAMETER_ANY_NOT_NULL,
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
- var find = context
26
+ let find = context
27
27
  ?.getArguments()
28
- ?.get(LastIndexOf.PARAMETER_ANY_NOT_NULL.getParameterName());
28
+ ?.get(LastIndexOf.PARAMETER_ANY_ELEMENT_OBJECT.getParameterName());
29
29
 
30
30
  let len = context
31
31
  ?.getArguments()
@@ -8,7 +8,7 @@ export class Rotate extends AbstractArrayFunction {
8
8
  super(
9
9
  'Rotate',
10
10
  [Rotate.PARAMETER_ARRAY_SOURCE, Rotate.PARAMETER_ROTATE_LENGTH],
11
- Rotate.EVENT_RESULT_ANY,
11
+ Rotate.EVENT_RESULT_ARRAY,
12
12
  );
13
13
  }
14
14
 
@@ -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.EVENT_RESULT_ANY);
8
+ super('Shuffle', [Shuffle.PARAMETER_ARRAY_SOURCE], Shuffle.EVENT_RESULT_ARRAY);
9
9
  }
10
10
 
11
11
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -17,7 +17,7 @@ export class Sort extends AbstractArrayFunction {
17
17
  Sort.PARAMETER_BOOLEAN_ASCENDING,
18
18
  Sort.PARAMETER_KEY_PATH,
19
19
  ],
20
- Sort.EVENT_RESULT_ANY,
20
+ Sort.EVENT_RESULT_ARRAY,
21
21
  );
22
22
  }
23
23
 
@@ -1,54 +1,61 @@
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";
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
- private signature: FunctionSignature;
16
+ public static readonly PARAMETER_TIMESTAMP_NAME: string = 'isoTimeStamp';
19
17
 
20
- public static readonly EVENT_RESULT_NAME: string = 'result';
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 PARAMETER_FIELD_NAME: string = 'value';
21
+ public static readonly PARAMETER_UNIT_NAME: string = 'unit';
25
22
 
26
- public static readonly PARAMETER_INT_NAME: string = "intValue";
23
+ public static readonly PARAMETER_NUMBER_NAME: string = 'number';
27
24
 
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")
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
- protected static readonly PARAMETER_FIELD : Parameter = new Parameter(
36
- AbstractDateFunction.PARAMETER_FIELD_NAME,
37
- Schema.ofInteger(this.PARAMETER_FIELD_NAME)
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
- protected static readonly PARAMETER_INT : Parameter = new Parameter(
41
- AbstractDateFunction.PARAMETER_INT_NAME,
42
- Schema.ofInteger(this.PARAMETER_INT_NAME)
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
- protected static readonly PARAMETER_UNIT : Parameter = new Parameter(
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.ofString(this.PARAMETER_UNIT_NAME)
48
- .setEnums(["YEAR" , "MONTH" , "DAY" , "HOUR" , "MINUTE" , "SECOND" , "MILLISECOND"])
47
+ Schema.ofRef(Namespaces.DATE + '.Timeunit'),
49
48
  );
50
49
 
51
- protected static readonly EVENT_INT: Event = new Event(
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
- protected static readonly EVENT_BOOLEAN: Event = new Event(
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.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME)
64
- )
78
+ Schema.ofLong(AbstractDateFunction.EVENT_RESULT_NAME),
79
+ ),
65
80
  );
66
81
 
67
- protected static readonly EVENT_DATE : Event = new Event(
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.ofString(AbstractDateFunction.EVENT_RESULT_NAME).setRef(Namespaces.DATE + ".timeStamp")
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(namespace)
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 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)];
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 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);
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
- 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
-
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
- })(Namespaces.DATE, functionName, AbstractDateFunction.EVENT_DATE,
157
- AbstractDateFunction.PARAMETER_DATE, AbstractDateFunction.PARAMETER_INT, AbstractDateFunction.PARAMETER_UNIT)];
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
+ }
@@ -0,0 +1,99 @@
1
+ import { DurationLikeObject } from 'luxon';
2
+ import { Schema } from '../../../json/schema/Schema';
3
+ import { EventResult } from '../../../model/EventResult';
4
+ import { FunctionOutput } from '../../../model/FunctionOutput';
5
+ import { Parameter } from '../../../model/Parameter';
6
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
7
+ import { MapUtil } from '../../../util/MapUtil';
8
+ import { AbstractDateFunction } from './AbstractDateFunction';
9
+ import { getDateTime } from './common';
10
+
11
+ export class AddSubtractTime extends AbstractDateFunction {
12
+ public static readonly PARAMETER_YEARS_NAME = 'years';
13
+ public static readonly PARAMETER_MONTHS_NAME = 'months';
14
+ public static readonly PARAMETER_DAYS_NAME = 'days';
15
+ public static readonly PARAMETER_HOURS_NAME = 'hours';
16
+ public static readonly PARAMETER_MINUTES_NAME = 'minutes';
17
+ public static readonly PARAMETER_SECONDS_NAME = 'seconds';
18
+ public static readonly PARAMETER_MILLISECONDS_NAME = 'milliseconds';
19
+
20
+ private readonly isAdd: boolean;
21
+
22
+ constructor(isAdd: boolean) {
23
+ super(
24
+ isAdd ? 'AddTime' : 'SubtractTime',
25
+ AbstractDateFunction.EVENT_TIMESTAMP,
26
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
27
+ Parameter.of(
28
+ AddSubtractTime.PARAMETER_YEARS_NAME,
29
+ Schema.ofNumber(AddSubtractTime.PARAMETER_YEARS_NAME).setDefaultValue(0),
30
+ ),
31
+ Parameter.of(
32
+ AddSubtractTime.PARAMETER_MONTHS_NAME,
33
+ Schema.ofNumber(AddSubtractTime.PARAMETER_MONTHS_NAME).setDefaultValue(0),
34
+ ),
35
+ Parameter.of(
36
+ AddSubtractTime.PARAMETER_DAYS_NAME,
37
+ Schema.ofNumber(AddSubtractTime.PARAMETER_DAYS_NAME).setDefaultValue(0),
38
+ ),
39
+ Parameter.of(
40
+ AddSubtractTime.PARAMETER_HOURS_NAME,
41
+ Schema.ofNumber(AddSubtractTime.PARAMETER_HOURS_NAME).setDefaultValue(0),
42
+ ),
43
+ Parameter.of(
44
+ AddSubtractTime.PARAMETER_MINUTES_NAME,
45
+ Schema.ofNumber(AddSubtractTime.PARAMETER_MINUTES_NAME).setDefaultValue(0),
46
+ ),
47
+ Parameter.of(
48
+ AddSubtractTime.PARAMETER_SECONDS_NAME,
49
+ Schema.ofNumber(AddSubtractTime.PARAMETER_SECONDS_NAME).setDefaultValue(0),
50
+ ),
51
+ Parameter.of(
52
+ AddSubtractTime.PARAMETER_MILLISECONDS_NAME,
53
+ Schema.ofNumber(AddSubtractTime.PARAMETER_MILLISECONDS_NAME).setDefaultValue(0),
54
+ ),
55
+ );
56
+
57
+ this.isAdd = isAdd;
58
+ }
59
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
60
+ const timestamp = context
61
+ .getArguments()
62
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
63
+
64
+ const dateTime = getDateTime(timestamp);
65
+ const years = context.getArguments()?.get(AddSubtractTime.PARAMETER_YEARS_NAME);
66
+ const months = context.getArguments()?.get(AddSubtractTime.PARAMETER_MONTHS_NAME);
67
+ const days = context.getArguments()?.get(AddSubtractTime.PARAMETER_DAYS_NAME);
68
+ const hours = context.getArguments()?.get(AddSubtractTime.PARAMETER_HOURS_NAME);
69
+ const minutes = context.getArguments()?.get(AddSubtractTime.PARAMETER_MINUTES_NAME);
70
+ const seconds = context.getArguments()?.get(AddSubtractTime.PARAMETER_SECONDS_NAME);
71
+ const milliseconds = context
72
+ .getArguments()
73
+ ?.get(AddSubtractTime.PARAMETER_MILLISECONDS_NAME);
74
+
75
+ const options = {
76
+ years,
77
+ months,
78
+ days,
79
+ hours,
80
+ minutes,
81
+ seconds,
82
+ milliseconds,
83
+ } as DurationLikeObject;
84
+
85
+ let newDateTime;
86
+
87
+ if (this.isAdd) {
88
+ newDateTime = dateTime.plus(options);
89
+ } else {
90
+ newDateTime = dateTime.minus(options);
91
+ }
92
+
93
+ return new FunctionOutput([
94
+ EventResult.outputOf(
95
+ MapUtil.of(AbstractDateFunction.EVENT_TIMESTAMP_NAME, newDateTime.toISO()),
96
+ ),
97
+ ]);
98
+ }
99
+ }