@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
@@ -0,0 +1,77 @@
1
+ import { DateTime } 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 { Namespaces } from '../../../namespaces/Namespaces';
7
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
8
+ import { MapUtil } from '../../../util/MapUtil';
9
+ import { AbstractDateFunction } from './AbstractDateFunction';
10
+
11
+ export class FromNow extends AbstractDateFunction {
12
+ public static readonly PARAMETER_FROM_NAME = 'from';
13
+ public static readonly PARAMETER_FROM = new Parameter(
14
+ FromNow.PARAMETER_FROM_NAME,
15
+ Schema.ofRef(Namespaces.DATE + '.Timestamp').setDefaultValue(''),
16
+ );
17
+ public static readonly PARAMETER_LOCALE_NAME = 'locale';
18
+ public static readonly PARAMETER_LOCALE = new Parameter(
19
+ FromNow.PARAMETER_LOCALE_NAME,
20
+ Schema.ofString(FromNow.PARAMETER_LOCALE_NAME).setDefaultValue('system'),
21
+ );
22
+
23
+ public static readonly PARAMETER_FORMAT_NAME = 'format';
24
+ public static readonly PARAMETER_FORMAT = new Parameter(
25
+ FromNow.PARAMETER_FORMAT_NAME,
26
+ Schema.ofString(FromNow.PARAMETER_FORMAT_NAME)
27
+ .setEnums(['LONG', 'SHORT', 'NARROW'])
28
+ .setDefaultValue('LONG'),
29
+ );
30
+
31
+ public static readonly PARAMETER_ROUND_NAME = 'round';
32
+ public static readonly PARAMETER_ROUND = new Parameter(
33
+ FromNow.PARAMETER_ROUND_NAME,
34
+ Schema.ofBoolean(FromNow.PARAMETER_ROUND_NAME).setDefaultValue(true),
35
+ );
36
+
37
+ public constructor() {
38
+ super(
39
+ 'FromNow',
40
+ AbstractDateFunction.EVENT_STRING,
41
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
42
+ FromNow.PARAMETER_FORMAT,
43
+ FromNow.PARAMETER_FROM,
44
+ AbstractDateFunction.PARAMETER_VARIABLE_UNIT,
45
+ FromNow.PARAMETER_ROUND,
46
+ FromNow.PARAMETER_LOCALE,
47
+ );
48
+ }
49
+
50
+ public internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
51
+ const from1 = context.getArguments()?.get(FromNow.PARAMETER_FROM_NAME);
52
+ const fromDate = from1 === '' ? DateTime.now() : DateTime.fromISO(from1);
53
+ const given = context.getArguments()?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
54
+ const givenDate = DateTime.fromISO(given);
55
+
56
+ const units = context.getArguments()?.get(FromNow.PARAMETER_UNIT_NAME);
57
+ const format = context.getArguments()?.get(FromNow.PARAMETER_FORMAT_NAME);
58
+ const round = context.getArguments()?.get(FromNow.PARAMETER_ROUND_NAME);
59
+ const locale = context.getArguments()?.get(FromNow.PARAMETER_LOCALE_NAME);
60
+
61
+ const options: any = { base: fromDate, style: format?.toLowerCase(), round, locale };
62
+ if (units?.length > 0) {
63
+ options.unit = units.map((e: string) => e.toLowerCase());
64
+ }
65
+
66
+ return Promise.resolve(
67
+ new FunctionOutput([
68
+ EventResult.outputOf(
69
+ MapUtil.of(
70
+ AbstractDateFunction.EVENT_RESULT_NAME,
71
+ givenDate.toRelative(options) ?? 'Unknown',
72
+ ),
73
+ ),
74
+ ]),
75
+ );
76
+ }
77
+ }
@@ -0,0 +1,20 @@
1
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { AbstractDateFunction } from './AbstractDateFunction';
5
+ import { MapUtil } from '../../../util/MapUtil';
6
+ import { DateTime } from 'luxon';
7
+
8
+ export class GetCurrentTimestamp extends AbstractDateFunction {
9
+ public constructor() {
10
+ super('GetCurrentTimestamp', AbstractDateFunction.EVENT_TIMESTAMP);
11
+ }
12
+
13
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
14
+ return new FunctionOutput([
15
+ EventResult.outputOf(
16
+ MapUtil.of(AbstractDateFunction.EVENT_TIMESTAMP_NAME, DateTime.now().toISO()),
17
+ ),
18
+ ]);
19
+ }
20
+ }
@@ -0,0 +1,74 @@
1
+ import { Parameter } from '../../../model/Parameter';
2
+ import { AbstractDateFunction } from './AbstractDateFunction';
3
+ import { Event } from '../../../model/Event';
4
+ import { Schema } from '../../../json/schema/Schema';
5
+ import { MapUtil } from '../../../util/MapUtil';
6
+ import { FunctionOutput } from '../../../model/FunctionOutput';
7
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
8
+ import { DateTime } from 'luxon';
9
+ import { EventResult } from '../../../model/EventResult';
10
+
11
+ export class GetNames extends AbstractDateFunction {
12
+ public static readonly EVENT_NAMES_NAME = 'names';
13
+ public static readonly PARAMETER_UNIT_NAME = 'unit';
14
+ public static readonly PARAMETER_LOCALE_NAME = 'locale';
15
+
16
+ constructor() {
17
+ super(
18
+ 'GetNames',
19
+ new Event(
20
+ GetNames.EVENT_NAMES_NAME,
21
+ MapUtil.of(
22
+ GetNames.EVENT_NAMES_NAME,
23
+ Schema.ofArray(
24
+ GetNames.EVENT_NAMES_NAME,
25
+ Schema.ofString(GetNames.EVENT_NAMES_NAME),
26
+ ),
27
+ ),
28
+ ),
29
+ new Parameter(
30
+ GetNames.PARAMETER_UNIT_NAME,
31
+ Schema.ofString(GetNames.PARAMETER_UNIT_NAME).setEnums([
32
+ 'TIMEZONES',
33
+ 'MONTHS',
34
+ 'WEEKDAYS',
35
+ ]),
36
+ ),
37
+ new Parameter(
38
+ GetNames.PARAMETER_LOCALE_NAME,
39
+ Schema.ofString(GetNames.PARAMETER_LOCALE_NAME).setDefaultValue('system'),
40
+ ),
41
+ );
42
+ }
43
+
44
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
45
+ const unit = context.getArguments()?.get(GetNames.PARAMETER_UNIT_NAME);
46
+ const locale = context.getArguments()?.get(GetNames.PARAMETER_LOCALE_NAME);
47
+
48
+ return new FunctionOutput([
49
+ EventResult.outputOf(
50
+ MapUtil.of(GetNames.EVENT_NAMES_NAME, this.getNames(unit, locale)),
51
+ ),
52
+ ]);
53
+ }
54
+
55
+ private getNames(unit: string, locale: string): string[] {
56
+ if (unit === 'TIMEZONES') {
57
+ return Intl.supportedValuesOf('timeZone');
58
+ }
59
+
60
+ if (unit === 'MONTHS') {
61
+ return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((month) =>
62
+ DateTime.now().setLocale(locale).set({ month }).toFormat('MMMM'),
63
+ );
64
+ }
65
+
66
+ if (unit === 'WEEKDAYS') {
67
+ return [1, 2, 3, 4, 5, 6, 7].map((day) =>
68
+ DateTime.now().setLocale(locale).set({ month: 7, day }).toFormat('EEEE'),
69
+ );
70
+ }
71
+
72
+ return [];
73
+ }
74
+ }
@@ -0,0 +1,62 @@
1
+ import { Schema } from '../../../json/schema/Schema';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { Parameter } from '../../../model/Parameter';
5
+ import { Namespaces } from '../../../namespaces/Namespaces';
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 IsBetween extends AbstractDateFunction {
12
+ public static readonly PARAMETER_START_TIMESTAMP_NAME = 'startTimestamp';
13
+ public static readonly PARAMETER_END_TIMESTAMP_NAME = 'endTimestamp';
14
+
15
+ public static readonly PARAMETER_CHECK_TIMESTAMP_NAME = 'checkTimestamp';
16
+
17
+ constructor() {
18
+ super(
19
+ 'IsBetween',
20
+ IsBetween.EVENT_BOOLEAN,
21
+ Parameter.of(
22
+ IsBetween.PARAMETER_START_TIMESTAMP_NAME,
23
+ Schema.ofRef(Namespaces.DATE + '.Timestamp'),
24
+ ),
25
+ Parameter.of(
26
+ IsBetween.PARAMETER_END_TIMESTAMP_NAME,
27
+ Schema.ofRef(Namespaces.DATE + '.Timestamp'),
28
+ ),
29
+ Parameter.of(
30
+ IsBetween.PARAMETER_CHECK_TIMESTAMP_NAME,
31
+ Schema.ofRef(Namespaces.DATE + '.Timestamp'),
32
+ ),
33
+ );
34
+ }
35
+
36
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
37
+ const startTimestamp = context
38
+ .getArguments()
39
+ ?.get(IsBetween.PARAMETER_START_TIMESTAMP_NAME);
40
+ const endTimestamp = context.getArguments()?.get(IsBetween.PARAMETER_END_TIMESTAMP_NAME);
41
+ const checkTimestamp = context
42
+ .getArguments()
43
+ ?.get(IsBetween.PARAMETER_CHECK_TIMESTAMP_NAME);
44
+
45
+ let startDateTime = getDateTime(startTimestamp);
46
+ let endDateTime = getDateTime(endTimestamp);
47
+ const checkDateTime = getDateTime(checkTimestamp);
48
+
49
+ if (startDateTime > endDateTime) {
50
+ [startDateTime, endDateTime] = [endDateTime, startDateTime];
51
+ }
52
+
53
+ return new FunctionOutput([
54
+ EventResult.outputOf(
55
+ MapUtil.of(
56
+ IsBetween.EVENT_RESULT_NAME,
57
+ startDateTime <= checkDateTime && checkDateTime <= endDateTime,
58
+ ),
59
+ ),
60
+ ]);
61
+ }
62
+ }
@@ -1,43 +1,57 @@
1
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
2
- import { Schema } from "../../../json/schema/Schema";
1
+ import { Schema } from '../../../json/schema/Schema';
3
2
  import { Event } from '../../../model/Event';
4
- import { EventResult } from "../../../model/EventResult";
5
- import { FunctionOutput } from "../../../model/FunctionOutput";
6
- import { FunctionSignature } from "../../../model/FunctionSignature";
7
- import { Parameter } from "../../../model/Parameter";
8
- import { Namespaces } from "../../../namespaces/Namespaces";
9
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
10
- import { MapUtil } from "../../../util/MapUtil";
11
- import { isNullValue } from "../../../util/NullCheck";
12
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
13
- import { AbstractFunction } from "../../AbstractFunction";
14
-
15
-
16
- const VALUE : string = "isoDate";
17
-
18
- const OUTPUT : string = "output";
19
-
20
- const SIGNATURE = new FunctionSignature('IsValidISODate')
21
- .setNamespace(Namespaces.DATE)
22
- .setParameters(MapUtil.of(VALUE, Parameter.of(VALUE, Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
23
- .setEvents(MapUtil.of(OUTPUT , new Event(OUTPUT , MapUtil.of(OUTPUT, Schema.ofBoolean(OUTPUT)))));
24
-
25
- export class IsValidISODate extends AbstractFunction{
26
-
27
- public getSignature(): FunctionSignature {
28
- return SIGNATURE;
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 { AbstractDateFunction } from './AbstractDateFunction';
12
+ import { DateTime } from 'luxon';
13
+
14
+ export class IsValidISODate extends AbstractFunction {
15
+ private static readonly SIGNATURE = new FunctionSignature('IsValidISODate')
16
+ .setNamespace(Namespaces.DATE)
17
+ .setParameters(
18
+ new Map([
19
+ Parameter.ofEntry(
20
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
21
+ Schema.ofString(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME),
22
+ ),
23
+ ]),
24
+ )
25
+ .setEvents(
26
+ new Map([
27
+ Event.outputEventMapEntry(
28
+ MapUtil.of(
29
+ AbstractDateFunction.EVENT_RESULT_NAME,
30
+ Schema.ofBoolean(AbstractDateFunction.EVENT_RESULT_NAME),
31
+ ),
32
+ ),
33
+ ]),
34
+ );
35
+
36
+ protected internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
37
+ const timestamp = context
38
+ .getArguments()
39
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
40
+
41
+ const dt = DateTime.fromISO(timestamp);
42
+
43
+ return Promise.resolve(
44
+ new FunctionOutput([
45
+ EventResult.outputOf(
46
+ MapUtil.of(
47
+ AbstractDateFunction.EVENT_RESULT_NAME,
48
+ dt.isValid,
49
+ ),
50
+ ),
51
+ ]),
52
+ );
29
53
  }
30
-
31
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
32
-
33
- var date = context.getArguments()?.get(VALUE);
34
-
35
- if(isNullValue(date))
36
- throw new KIRuntimeException("Please provide a valid date object");
37
-
38
- return new FunctionOutput([ EventResult.of(OUTPUT , MapUtil.of( OUTPUT , ValidDateTimeUtil.validate(date)))]);
39
-
54
+ public getSignature(): FunctionSignature {
55
+ return IsValidISODate.SIGNATURE;
40
56
  }
41
-
42
-
43
- }
57
+ }
@@ -0,0 +1,72 @@
1
+ import { DateTime } from 'luxon';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionSignature } from '../../../model/FunctionSignature';
5
+ import { Namespaces } from '../../../namespaces/Namespaces';
6
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
7
+ import { MapUtil } from '../../../util/MapUtil';
8
+ import { AbstractFunction } from '../../AbstractFunction';
9
+ import { AbstractDateFunction } from './AbstractDateFunction';
10
+ import { Parameter } from '../../../model/Parameter';
11
+ import { Schema } from '../../../json/schema/Schema';
12
+ import { getDateTime } from './common';
13
+
14
+ export class LastFirstOf extends AbstractFunction {
15
+ private readonly signature: FunctionSignature;
16
+ private readonly isLast: boolean;
17
+
18
+ constructor(isLast: boolean) {
19
+ super();
20
+
21
+ this.isLast = isLast;
22
+ this.signature = new FunctionSignature(isLast ? 'LastOf' : 'FirstOf')
23
+ .setNamespace(Namespaces.DATE)
24
+ .setParameters(
25
+ new Map([
26
+ [
27
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
28
+ new Parameter(
29
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
30
+ Schema.ofRef(Namespaces.DATE + '.Timestamp'),
31
+ ).setVariableArgument(true),
32
+ ],
33
+ ]),
34
+ )
35
+ .setEvents(
36
+ new Map([
37
+ [
38
+ AbstractDateFunction.EVENT_TIMESTAMP_NAME,
39
+ AbstractDateFunction.EVENT_TIMESTAMP,
40
+ ],
41
+ ]),
42
+ );
43
+ }
44
+
45
+ public getSignature(): FunctionSignature {
46
+ return this.signature;
47
+ }
48
+
49
+ protected internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
50
+ const timestamps = context
51
+ .getArguments()
52
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
53
+
54
+ if (!timestamps?.length) {
55
+ throw new Error('No timestamps provided');
56
+ }
57
+
58
+ const dateTimes: DateTime[] = timestamps.map((ts: string) => getDateTime(ts));
59
+ dateTimes.sort((a, b) => a.toMillis() - b.toMillis());
60
+
61
+ return Promise.resolve(
62
+ new FunctionOutput([
63
+ EventResult.outputOf(
64
+ MapUtil.of(
65
+ AbstractDateFunction.EVENT_TIMESTAMP_NAME,
66
+ dateTimes[this.isLast ? dateTimes.length - 1 : 0].toISO(),
67
+ ),
68
+ ),
69
+ ]),
70
+ );
71
+ }
72
+ }
@@ -0,0 +1,43 @@
1
+ import { Schema } from '../../../json/schema/Schema';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { Parameter } from '../../../model/Parameter';
5
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
6
+ import { MapUtil } from '../../../util/MapUtil';
7
+ import { AbstractDateFunction } from './AbstractDateFunction';
8
+ import { getDateTime } from './common';
9
+
10
+ export class SetTimeZone extends AbstractDateFunction {
11
+ public static readonly PARAMETER_TIMEZONE_NAME: string = 'timezone';
12
+
13
+ constructor() {
14
+ super(
15
+ 'SetTimeZone',
16
+ AbstractDateFunction.EVENT_TIMESTAMP,
17
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
18
+ Parameter.of(
19
+ SetTimeZone.PARAMETER_TIMEZONE_NAME,
20
+ Schema.ofString(SetTimeZone.PARAMETER_TIMEZONE_NAME),
21
+ ),
22
+ );
23
+ }
24
+
25
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
26
+ const timestamp = context
27
+ .getArguments()
28
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
29
+
30
+ const dateTime = getDateTime(timestamp);
31
+
32
+ const timeZone = context.getArguments()?.get(SetTimeZone.PARAMETER_TIMEZONE_NAME);
33
+
34
+ return new FunctionOutput([
35
+ EventResult.outputOf(
36
+ MapUtil.of(
37
+ AbstractDateFunction.EVENT_RESULT_NAME,
38
+ dateTime.setZone(timeZone).toISO()!,
39
+ ),
40
+ ),
41
+ ]);
42
+ }
43
+ }
@@ -0,0 +1,44 @@
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 StartEndOf extends AbstractDateFunction {
12
+ private readonly isStart: boolean;
13
+
14
+ constructor(isStart: boolean) {
15
+ super(
16
+ isStart ? 'StartOf' : 'EndOf',
17
+ AbstractDateFunction.EVENT_TIMESTAMP,
18
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
19
+ AbstractDateFunction.PARAMETER_UNIT,
20
+ );
21
+
22
+ this.isStart = isStart;
23
+ }
24
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
25
+ const timestamp = context
26
+ .getArguments()
27
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
28
+
29
+ const dateTime = getDateTime(timestamp);
30
+
31
+ const unit = context
32
+ .getArguments()
33
+ ?.get(AbstractDateFunction.PARAMETER_UNIT_NAME)
34
+ ?.toLowerCase();
35
+
36
+ const newDateTime = this.isStart ? dateTime.startOf(unit) : dateTime.endOf(unit);
37
+
38
+ return new FunctionOutput([
39
+ EventResult.outputOf(
40
+ MapUtil.of(AbstractDateFunction.EVENT_TIMESTAMP_NAME, newDateTime.toISO()),
41
+ ),
42
+ ]);
43
+ }
44
+ }
@@ -0,0 +1,64 @@
1
+ import { FunctionOutput } from '../../../model/FunctionOutput';
2
+ import { Namespaces } from '../../../namespaces/Namespaces';
3
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
4
+ import { MapUtil } from '../../../util/MapUtil';
5
+ import { Event } from '../../../model/Event';
6
+ import { EventResult } from '../../../model/EventResult';
7
+
8
+ import { AbstractDateFunction } from './AbstractDateFunction';
9
+ import { getDateTime } from './common';
10
+ import { Schema } from '../../../json/schema/Schema';
11
+
12
+ export class TimeAs extends AbstractDateFunction {
13
+ public static readonly EVENT_TIME_OBJECT_NAME = 'object';
14
+ public static readonly EVENT_TIME_ARRAY_NAME = 'array';
15
+
16
+ private readonly isArray: boolean;
17
+
18
+ constructor(isArray: boolean) {
19
+ super(
20
+ isArray ? 'TimeAsArray' : 'TimeAsObject',
21
+ new Event(
22
+ Event.OUTPUT,
23
+ MapUtil.of(
24
+ isArray ? TimeAs.EVENT_TIME_ARRAY_NAME : TimeAs.EVENT_TIME_OBJECT_NAME,
25
+ isArray
26
+ ? Schema.ofArray(
27
+ TimeAs.EVENT_TIME_ARRAY_NAME,
28
+ Schema.ofInteger('timeParts'),
29
+ )
30
+ : Schema.ofRef(Namespaces.DATE + '.TimeObject'),
31
+ ),
32
+ ),
33
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
34
+ );
35
+
36
+ this.isArray = isArray;
37
+ }
38
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
39
+ const timestamp = context
40
+ .getArguments()
41
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
42
+
43
+ const dateTime = getDateTime(timestamp).toObject();
44
+
45
+ return new FunctionOutput([
46
+ EventResult.outputOf(
47
+ MapUtil.of(
48
+ this.isArray ? TimeAs.EVENT_TIME_ARRAY_NAME : TimeAs.EVENT_TIME_OBJECT_NAME,
49
+ this.isArray
50
+ ? [
51
+ dateTime.year,
52
+ dateTime.month,
53
+ dateTime.day,
54
+ dateTime.hour,
55
+ dateTime.minute,
56
+ dateTime.second,
57
+ dateTime.millisecond,
58
+ ]
59
+ : dateTime,
60
+ ),
61
+ ),
62
+ ]);
63
+ }
64
+ }
@@ -0,0 +1,54 @@
1
+ import { DateTime } from 'luxon';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { FunctionSignature } from '../../../model/FunctionSignature';
5
+ import { Namespaces } from '../../../namespaces/Namespaces';
6
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
7
+ import { MapUtil } from '../../../util/MapUtil';
8
+ import { AbstractFunction } from '../../AbstractFunction';
9
+ import { AbstractDateFunction } from './AbstractDateFunction';
10
+
11
+ export class TimestampToEpoch extends AbstractFunction {
12
+ private readonly signature: FunctionSignature;
13
+ private readonly isSeconds: boolean;
14
+
15
+ constructor(name: string, isSeconds: boolean) {
16
+ super();
17
+
18
+ this.isSeconds = isSeconds;
19
+ this.signature = new FunctionSignature(name)
20
+ .setNamespace(Namespaces.DATE)
21
+ .setParameters(
22
+ new Map([
23
+ [
24
+ AbstractDateFunction.PARAMETER_TIMESTAMP_NAME,
25
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
26
+ ],
27
+ ]),
28
+ )
29
+ .setEvents(
30
+ new Map([
31
+ [AbstractDateFunction.EVENT_RESULT_NAME, AbstractDateFunction.EVENT_LONG],
32
+ ]),
33
+ );
34
+ }
35
+
36
+ public getSignature(): FunctionSignature {
37
+ return this.signature;
38
+ }
39
+
40
+ protected internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
41
+ const timestamp = context
42
+ .getArguments()
43
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
44
+ const epoch = this.isSeconds
45
+ ? DateTime.fromISO(timestamp).toSeconds()
46
+ : DateTime.fromISO(timestamp).toMillis();
47
+
48
+ return Promise.resolve(
49
+ new FunctionOutput([
50
+ EventResult.outputOf(MapUtil.of(AbstractDateFunction.EVENT_RESULT_NAME, epoch)),
51
+ ]),
52
+ );
53
+ }
54
+ }
@@ -0,0 +1,49 @@
1
+ import { Schema } from '../../../json/schema/Schema';
2
+ import { EventResult } from '../../../model/EventResult';
3
+ import { FunctionOutput } from '../../../model/FunctionOutput';
4
+ import { Parameter } from '../../../model/Parameter';
5
+ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
6
+ import { MapUtil } from '../../../util/MapUtil';
7
+ import { AbstractDateFunction } from './AbstractDateFunction';
8
+ import { getDateTime } from './common';
9
+
10
+ export class ToDateString extends AbstractDateFunction {
11
+ public static readonly PARAMETER_FORMAT_NAME = 'format';
12
+ public static readonly PARAMETER_LOCALE_NAME = 'locale';
13
+
14
+ constructor() {
15
+ super(
16
+ 'ToDateString',
17
+ AbstractDateFunction.EVENT_STRING,
18
+ AbstractDateFunction.PARAMETER_TIMESTAMP,
19
+ Parameter.of(
20
+ ToDateString.PARAMETER_FORMAT_NAME,
21
+ Schema.ofString(ToDateString.PARAMETER_FORMAT_NAME),
22
+ ),
23
+ Parameter.of(
24
+ ToDateString.PARAMETER_LOCALE_NAME,
25
+ Schema.ofString(ToDateString.PARAMETER_LOCALE_NAME).setDefaultValue(''),
26
+ ),
27
+ );
28
+ }
29
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
30
+ const timestamp = context
31
+ .getArguments()
32
+ ?.get(AbstractDateFunction.PARAMETER_TIMESTAMP_NAME);
33
+
34
+ const dateTime = getDateTime(timestamp);
35
+
36
+ const format = context.getArguments()?.get(ToDateString.PARAMETER_FORMAT_NAME);
37
+ let locale = context.getArguments()?.get(ToDateString.PARAMETER_LOCALE_NAME);
38
+ if (locale === '') locale = 'system';
39
+
40
+ return new FunctionOutput([
41
+ EventResult.outputOf(
42
+ MapUtil.of(
43
+ AbstractDateFunction.EVENT_RESULT_NAME,
44
+ dateTime.toFormat(format, { locale }),
45
+ ),
46
+ ),
47
+ ]);
48
+ }
49
+ }