@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.
Files changed (124) 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/MathFunctionRepositoryTest.ts +2 -2
  22. package/__tests__/engine/function/system/math/MaximumTest.ts +3 -2
  23. package/__tests__/engine/function/system/math/MinimumTest.ts +18 -20
  24. package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
  25. package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
  26. package/__tests__/engine/json/schema/covnertor/BooleanConvertorTest.ts +55 -0
  27. package/__tests__/engine/json/schema/covnertor/NullConvertorTest.ts +47 -0
  28. package/__tests__/engine/json/schema/covnertor/NumberConvertorTest.ts +154 -0
  29. package/__tests__/engine/json/schema/covnertor/StringConvertorTest.ts +56 -0
  30. package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +9 -7
  31. package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +3 -3
  32. package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +1 -9
  33. package/__tests__/engine/json/schema/validator/TypeValidatorTest.ts +290 -0
  34. package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
  35. package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -0
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/module.js +1 -1
  39. package/dist/module.js.map +1 -1
  40. package/dist/types.d.ts +27 -20
  41. package/dist/types.d.ts.map +1 -1
  42. package/generator/generateValidationCSV.ts +52 -38
  43. package/generator/validation-js.csv +470 -166
  44. package/package.json +11 -6
  45. package/src/engine/function/AbstractFunction.ts +1 -1
  46. package/src/engine/function/system/Print.ts +19 -5
  47. package/src/engine/function/system/Wait.ts +1 -1
  48. package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
  49. package/src/engine/function/system/array/Fill.ts +1 -1
  50. package/src/engine/function/system/array/Frequency.ts +0 -1
  51. package/src/engine/function/system/array/IndexOf.ts +4 -4
  52. package/src/engine/function/system/array/LastIndexOf.ts +3 -3
  53. package/src/engine/function/system/array/Rotate.ts +1 -1
  54. package/src/engine/function/system/array/Shuffle.ts +1 -1
  55. package/src/engine/function/system/array/Sort.ts +1 -1
  56. package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
  57. package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
  58. package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
  59. package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
  60. package/src/engine/function/system/date/FromDateString.ts +44 -0
  61. package/src/engine/function/system/date/FromNow.ts +77 -0
  62. package/src/engine/function/system/date/GetCurrent.ts +20 -0
  63. package/src/engine/function/system/date/GetNames.ts +74 -0
  64. package/src/engine/function/system/date/IsBetween.ts +62 -0
  65. package/src/engine/function/system/date/IsValidISODate.ts +54 -40
  66. package/src/engine/function/system/date/LastFirstOf.ts +72 -0
  67. package/src/engine/function/system/date/SetTimeZone.ts +43 -0
  68. package/src/engine/function/system/date/StartEndOf.ts +44 -0
  69. package/src/engine/function/system/date/TimeAs.ts +64 -0
  70. package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
  71. package/src/engine/function/system/date/ToDateString.ts +49 -0
  72. package/src/engine/function/system/date/common.ts +9 -0
  73. package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
  74. package/src/engine/function/system/math/RandomAny.ts +57 -0
  75. package/src/engine/function/system/object/ObjectConvert.ts +99 -0
  76. package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
  77. package/src/engine/function/system/object/ObjectPutValue.ts +0 -2
  78. package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
  79. package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
  80. package/src/engine/json/schema/SchemaUtil.ts +1 -1
  81. package/src/engine/json/schema/convertor/BooleanConvertor.ts +76 -0
  82. package/src/engine/json/schema/convertor/NullConvertor.ts +31 -0
  83. package/src/engine/json/schema/convertor/NumberConvertor.ts +117 -0
  84. package/src/engine/json/schema/convertor/StringConvertor.ts +41 -0
  85. package/src/engine/json/schema/convertor/enums/ConversionMode.ts +11 -0
  86. package/src/engine/json/schema/convertor/exception/SchemaConversionException.ts +39 -0
  87. package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +96 -36
  88. package/src/engine/json/schema/validator/ArrayValidator.ts +15 -7
  89. package/src/engine/json/schema/validator/ObjectValidator.ts +24 -13
  90. package/src/engine/json/schema/validator/SchemaValidator.ts +74 -22
  91. package/src/engine/json/schema/validator/TypeValidator.ts +136 -23
  92. package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
  93. package/src/engine/util/json/ConvertorUtil.ts +51 -0
  94. package/src/engine/util/json/ValidatorUtil.ts +29 -0
  95. package/src/engine/util/string/StringUtil.ts +12 -0
  96. package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
  97. package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
  98. package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
  99. package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
  100. package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
  101. package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
  102. package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
  103. package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
  104. package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
  105. package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
  106. package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
  107. package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
  108. package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
  109. package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
  110. package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
  111. package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
  112. package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
  113. package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
  114. package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
  115. package/src/engine/function/system/date/DateToEpoch.ts +0 -39
  116. package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
  117. package/src/engine/function/system/date/EpochToDate.ts +0 -76
  118. package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
  119. package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
  120. package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
  121. package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
  122. package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
  123. package/src/engine/function/system/math/RandomFloat.ts +0 -56
  124. 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.5.0",
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.7.0",
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": "^28.1.8",
38
- "jest": "^29.5.0",
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.1.0",
42
+ "ts-jest": "^29.2.5",
42
43
  "ts-loader": "^9.3.1",
43
- "typescript": "^5.1.3"
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([Parameter.ofEntry(Print.VALUES, Schema.ofAny(Print.VALUES), true)]),
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
- var values = context.getArguments()?.get(Print.VALUES);
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
- var condition = context.getArguments()?.get(Wait.MILLIS);
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 PARAMETER_ANY_NOT_NULL: Parameter = Parameter.of(
153
+ public static readonly PARAMETER_ANY_ELEMENT_OBJECT: Parameter = Parameter.of(
154
154
  'elementObject',
155
- Schema.ofAnyNotNull('elementObject'),
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();
@@ -18,7 +18,7 @@ export class Fill extends AbstractArrayFunction {
18
18
  Fill.PARAMETER_INT_LENGTH,
19
19
  Fill.PARAMETER_ANY,
20
20
  ],
21
- Fill.EVENT_RESULT_EMPTY,
21
+ Fill.EVENT_RESULT_ARRAY,
22
22
  );
23
23
  }
24
24
 
@@ -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.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
+ }