@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
@@ -1,95 +0,0 @@
1
- import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
2
- import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
3
- import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
4
-
5
-
6
- const dfr : DateFunctionRepository = new DateFunctionRepository();
7
-
8
- const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
9
- new KIRunFunctionRepository(),
10
- new KIRunSchemaRepository());
11
-
12
- test('check for invalid dates', async () => {
13
-
14
- const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
15
-
16
- if (!subtractTimeFunction) {
17
- throw new Error("Function not found");
18
- }
19
-
20
- fep.setArguments(new Map<string, any>([
21
- [AbstractDateFunction.PARAMETER_DATE_NAME, '2029-15-05T06:04:18.073Z'],
22
- [AbstractDateFunction.PARAMETER_INT_NAME, 10],
23
- [AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
24
- ]));
25
-
26
- await expect( () => subtractTimeFunction.execute(fep)).rejects.toThrow();
27
- });
28
-
29
- test('Subtract Time 1', async () => {
30
-
31
- const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
32
-
33
- if (!subtractTimeFunction) {
34
- throw new Error("Function not found");
35
- }
36
-
37
- fep.setArguments(new Map<string, any>([
38
- [AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
39
- [AbstractDateFunction.PARAMETER_INT_NAME, 10],
40
- [AbstractDateFunction.PARAMETER_UNIT_NAME, 'MINUTE']
41
- ]));
42
-
43
- expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-13T23:42:34.633-05:30');
44
- });
45
-
46
- test('Subtract Time 2', async () => {
47
-
48
- const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
49
-
50
- if (!subtractTimeFunction) {
51
- throw new Error("Function not found");
52
- }
53
-
54
- fep.setArguments(new Map<string, any>([
55
- [AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
56
- [AbstractDateFunction.PARAMETER_INT_NAME, 13],
57
- [AbstractDateFunction.PARAMETER_UNIT_NAME, 'MONTH']
58
- ]));
59
-
60
- expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2023-08-13T23:52:34.633-05:30');
61
- });
62
-
63
- test('Subtract Time 3', async () => {
64
-
65
- const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
66
-
67
- if (!subtractTimeFunction) {
68
- throw new Error("Function not found");
69
- }
70
-
71
- fep.setArguments(new Map<string, any>([
72
- [AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
73
- [AbstractDateFunction.PARAMETER_INT_NAME, 70],
74
- [AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
75
- ]));
76
-
77
- expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-13T23:51:24.633-05:30');
78
- });
79
-
80
- test('Subtract Time 4', async () => {
81
-
82
- const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
83
-
84
- if (!subtractTimeFunction) {
85
- throw new Error("Function not found");
86
- }
87
-
88
- fep.setArguments(new Map<string, any>([
89
- [AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
90
- [AbstractDateFunction.PARAMETER_INT_NAME, 5],
91
- [AbstractDateFunction.PARAMETER_UNIT_NAME, 'YEAR']
92
- ]));
93
-
94
- expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2019-09-13T23:52:34.633-05:30');
95
- });
@@ -1,39 +0,0 @@
1
- import { Schema } from "../../../json/schema/Schema";
2
- import { FunctionOutput } from "../../../model/FunctionOutput";
3
- import { FunctionSignature } from "../../../model/FunctionSignature";
4
- import { Event } from '../../../model/Event';
5
- import { Parameter } from "../../../model/Parameter";
6
- import { Namespaces } from "../../../namespaces/Namespaces";
7
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
8
- import { MapUtil } from "../../../util/MapUtil";
9
- import { AbstractFunction } from "../../AbstractFunction";
10
- import { isNullValue } from "../../../util/NullCheck";
11
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
12
- import { EventResult } from "../../../model/EventResult";
13
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
14
-
15
- const OUTPUT : string = "result";
16
-
17
- const VALUE : string = "isoDate";
18
-
19
- export class DateToEpoch extends AbstractFunction{
20
-
21
- public getSignature(): FunctionSignature {
22
-
23
- return new FunctionSignature('DateToEpoch')
24
- .setNamespace(Namespaces.DATE)
25
- .setParameters(MapUtil.of(VALUE, Parameter.of(VALUE,Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
26
- .setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT, Schema.ofLong(OUTPUT)]]))]));
27
- }
28
-
29
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
30
-
31
- var date = context.getArguments()?.get(VALUE);
32
-
33
- if(isNullValue(date) || !ValidDateTimeUtil.validate(date))
34
- throw new KIRuntimeException("Please provide a valid date object");
35
-
36
- const epochMillis = new Date(date).getTime();
37
- return new FunctionOutput([ EventResult.of(OUTPUT , MapUtil.of( OUTPUT , epochMillis))]);
38
- }
39
- }
@@ -1,45 +0,0 @@
1
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
2
- import { Schema } from "../../../json/schema/Schema";
3
- import { EventResult } from "../../../model/EventResult";
4
- import { FunctionOutput } from "../../../model/FunctionOutput";
5
- import { FunctionSignature } from "../../../model/FunctionSignature";
6
- import { Parameter } from "../../../model/Parameter";
7
- import { Namespaces } from "../../../namespaces/Namespaces";
8
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
9
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
10
- import { AbstractFunction } from "../../AbstractFunction";
11
-
12
- const DATE_ONE: string = "isoDateOne";
13
- const DATE_TWO: string = "isoDateTwo";
14
- const OUTPUT: string = "result";
15
-
16
- const SIGNATURE: FunctionSignature = new FunctionSignature('DifferenceOfTimestamps')
17
- .setNamespace(Namespaces.DATE)
18
- .setParameters(
19
- new Map([
20
- [DATE_ONE, new Parameter(DATE_ONE, Schema.ofString(DATE_ONE).setRef(Namespaces.DATE+".timeStamp"))],
21
- [DATE_TWO, new Parameter(DATE_TWO, Schema.ofString(DATE_TWO).setRef(Namespaces.DATE+".timeStamp"))]
22
- ])
23
- );;
24
-
25
- export class DifferenceOfTimestamps extends AbstractFunction {
26
-
27
- public getSignature(): FunctionSignature {
28
- return SIGNATURE;
29
- }
30
-
31
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
32
-
33
- const firstDate:string = context?.getArguments()?.get(DATE_ONE);
34
- const secondDate:string = context?.getArguments()?.get(DATE_TWO);
35
-
36
- if(!ValidDateTimeUtil.validate(firstDate) || !ValidDateTimeUtil.validate(secondDate))
37
- throw new KIRuntimeException("Please provide valid ISO date for both the given dates.");
38
-
39
- const fDate: Date = new Date(firstDate);
40
- const sDate: Date = new Date(secondDate);
41
-
42
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, (sDate.getTime() - fDate.getTime())/60000]]))]);
43
- }
44
-
45
- }
@@ -1,76 +0,0 @@
1
- import { Schema } from "../../../json/schema/Schema";
2
- import { FunctionOutput } from "../../../model/FunctionOutput";
3
- import { FunctionSignature } from "../../../model/FunctionSignature";
4
- import { Event } from '../../../model/Event';
5
- import { Parameter } from "../../../model/Parameter";
6
- import { Namespaces } from "../../../namespaces/Namespaces";
7
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
8
- import { AbstractFunction } from "../../AbstractFunction";
9
- import { isNullValue } from "../../../util/NullCheck";
10
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
11
- import { EventResult } from "../../../model/EventResult";
12
-
13
-
14
- const VALUE = 'epoch';
15
- const OUTPUT = 'date';
16
- const ERROR_MSG: string = "Please provide a valid value for epoch.";
17
-
18
- const SIGNATURE = new FunctionSignature('EpochToDate')
19
- .setNamespace(Namespaces.DATE)
20
- .setParameters(
21
- new Map([
22
- [
23
- VALUE,
24
- new Parameter(
25
- VALUE,
26
- new Schema().setAnyOf([
27
- Schema.ofInteger(VALUE),
28
- Schema.ofLong(VALUE),
29
- Schema.ofString(VALUE),
30
- ]),
31
- ),
32
- ],
33
- ]),
34
- )
35
- .setEvents(
36
- new Map([
37
- Event.outputEventMapEntry(
38
- new Map([[OUTPUT, Schema.ofRef(`${Namespaces.DATE}.timeStamp`)]]),
39
- ),
40
- ]),
41
- );
42
-
43
- export class EpochToDate extends AbstractFunction{
44
-
45
- public getSignature(): FunctionSignature {
46
- return SIGNATURE;
47
- }
48
-
49
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
50
-
51
- var epoch : any = context.getArguments()?.get(VALUE);
52
-
53
- if(isNullValue(epoch))
54
- throw new KIRuntimeException(ERROR_MSG);
55
-
56
- if(typeof epoch === 'boolean')
57
- throw new KIRuntimeException(ERROR_MSG);
58
-
59
- if(typeof epoch === 'string')
60
- epoch = parseInt(epoch)
61
-
62
- if(isNaN(epoch))
63
- throw new KIRuntimeException(ERROR_MSG);
64
-
65
- epoch = epoch > 999999999999 ? epoch : epoch * 1000;
66
-
67
-
68
- return new FunctionOutput([
69
- EventResult.outputOf(new Map([
70
- [OUTPUT, new Date(epoch).toISOString()]
71
- ]))
72
- ]);
73
-
74
- }
75
-
76
- }
@@ -1,36 +0,0 @@
1
- import { FunctionOutput } from "../../../model/FunctionOutput";
2
- import { FunctionSignature } from "../../../model/FunctionSignature";
3
- import { Event } from '../../../model/Event';
4
- import { Namespaces } from "../../../namespaces/Namespaces";
5
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
6
- import { AbstractFunction } from "../../AbstractFunction";
7
- import { Schema } from "../../../json/schema/Schema";
8
- import { EventResult } from "../../../model/EventResult";
9
-
10
-
11
- const OUTPUT = 'date';
12
-
13
- const SIGNATURE: FunctionSignature = new FunctionSignature("GetCurrentTimeStamp")
14
- .setNamespace(Namespaces.DATE)
15
- .setParameters(new Map([]))
16
- .setEvents(new Map([
17
- Event.outputEventMapEntry(
18
- new Map([[OUTPUT, Schema.ofRef(`${Namespaces.DATE}.timeStamp`)]]),
19
- ),
20
- ]));
21
-
22
- export class GetCurrentTimeStamp extends AbstractFunction{
23
-
24
- public getSignature(): FunctionSignature {
25
-
26
- return SIGNATURE;
27
- }
28
-
29
-
30
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
31
-
32
- const date : string = new Date(Date.now()).toISOString();
33
-
34
- return new FunctionOutput([EventResult.of(OUTPUT, new Map([ [OUTPUT, date]]))]);
35
- }
36
- }
@@ -1,48 +0,0 @@
1
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
2
- import { ArraySchemaType } from "../../../json/schema/array/ArraySchemaType";
3
- import { Schema } from "../../../json/schema/Schema";
4
- import { Event } from '../../../model/Event';
5
- import { EventResult } from "../../../model/EventResult";
6
- import { FunctionOutput } from "../../../model/FunctionOutput";
7
- import { FunctionSignature } from "../../../model/FunctionSignature";
8
- import { Parameter } from "../../../model/Parameter";
9
- import { Namespaces } from "../../../namespaces/Namespaces";
10
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
11
- import { MapUtil } from "../../../util/MapUtil";
12
- import { isNullValue } from "../../../util/NullCheck";
13
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
14
- import { AbstractFunction } from "../../AbstractFunction";
15
-
16
-
17
- const VALUE:string = "isoDate";
18
-
19
- const OUTPUT:string = "result";
20
-
21
- const SIGNATURE = new FunctionSignature('GetTimeAsArray')
22
- .setNamespace(Namespaces.DATE)
23
- .setParameters(MapUtil.of(VALUE, Parameter.of(VALUE, Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
24
- .setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT , Schema.ofArray(OUTPUT).setItems(ArraySchemaType.of(Schema.ofNumber("number")))]]))]))
25
-
26
-
27
- export class GetTimeAsArray extends AbstractFunction{
28
-
29
- public getSignature(): FunctionSignature {
30
- return SIGNATURE;
31
- }
32
-
33
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
34
-
35
- var inputDate = context.getArguments()?.get(VALUE);
36
-
37
- if(isNullValue(inputDate) || !ValidDateTimeUtil.validate(inputDate))
38
- throw new KIRuntimeException("Please provide a valid date object");
39
-
40
- const date = new Date(inputDate);
41
-
42
- const outputArray = [ date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()
43
- , date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()];
44
-
45
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT , outputArray]]))]);
46
- }
47
-
48
- }
@@ -1,66 +0,0 @@
1
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
2
- import { ArraySchemaType } from "../../../json/schema/array/ArraySchemaType";
3
- import { Schema } from "../../../json/schema/Schema";
4
- import { Event } from '../../../model/Event';
5
- import { EventResult } from "../../../model/EventResult";
6
- import { FunctionOutput } from "../../../model/FunctionOutput";
7
- import { FunctionSignature } from "../../../model/FunctionSignature";
8
- import { Parameter } from "../../../model/Parameter";
9
- import { Namespaces } from "../../../namespaces/Namespaces";
10
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
11
- import { MapUtil } from "../../../util/MapUtil";
12
- import { isNullValue } from "../../../util/NullCheck";
13
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
14
- import { AbstractFunction } from "../../AbstractFunction";
15
-
16
-
17
- const VALUE:string = "isoDate";
18
-
19
- const OUTPUT:string = "result";
20
-
21
- const SIGNATURE = new FunctionSignature('GetTimeAsObject')
22
- .setNamespace(Namespaces.DATE)
23
- .setParameters(MapUtil.of(VALUE, Parameter.of(VALUE, Schema.ofRef(Namespaces.DATE + ".timeStamp"))))
24
- .setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT ,
25
- Schema.ofObject(OUTPUT).setProperties(new Map(
26
- [
27
- ["year", Schema.ofNumber("year")],
28
- ["month", Schema.ofNumber("month")],
29
- ["day", Schema.ofNumber("day")],
30
- ["hours", Schema.ofNumber("hours")],
31
- ["minutes", Schema.ofNumber("minutes")],
32
- ["seconds", Schema.ofNumber("seconds")],
33
- ["milliseconds", Schema.ofNumber("milliseconds")]
34
- ]
35
- ))]]))]));
36
-
37
-
38
- export class GetTimeAsObject extends AbstractFunction{
39
-
40
- public getSignature(): FunctionSignature {
41
- return SIGNATURE;
42
- }
43
-
44
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
45
-
46
- var inputDate = context.getArguments()?.get(VALUE);
47
-
48
- if(isNullValue(inputDate) || !ValidDateTimeUtil.validate(inputDate))
49
- throw new KIRuntimeException("Please provide a valid date object");
50
-
51
- const date = new Date(inputDate);
52
-
53
- const outputObject = {
54
- year: date.getUTCFullYear(),
55
- month: date.getUTCMonth() + 1,
56
- day: date.getUTCDate(),
57
- hours: date.getUTCHours(),
58
- minutes: date.getUTCMinutes(),
59
- seconds: date.getUTCSeconds(),
60
- milliseconds: date.getUTCMilliseconds()
61
- };
62
-
63
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT , outputObject]]))]);
64
- }
65
-
66
- }
@@ -1,73 +0,0 @@
1
- import { Schema } from "../../../json/schema/Schema";
2
- import { FunctionOutput } from "../../../model/FunctionOutput";
3
- import { FunctionSignature } from "../../../model/FunctionSignature";
4
- import { Parameter } from "../../../model/Parameter";
5
- import { Namespaces } from "../../../namespaces/Namespaces";
6
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
7
- import { AbstractFunction } from "../../AbstractFunction";
8
- import { Event } from "../../../model/Event";
9
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
10
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
11
- import { EventResult } from "../../../model/EventResult";
12
-
13
- const VALUE = "isoDates";
14
-
15
- const OUTPUT = "result";
16
-
17
- const ERROR_MESSAGE = "Please provide a valid date";
18
-
19
-
20
-
21
- const SIGNATURE : FunctionSignature = new FunctionSignature('MaximumTimestamp')
22
- .setNamespace(Namespaces.DATE)
23
- .setParameters(new Map([[VALUE, Parameter.of(VALUE, Schema.ofString(VALUE).setRef(Namespaces.DATE + ".timeStamp")).setVariableArgument(true)]]))
24
- .setEvents(new Map([[OUTPUT, new Event(OUTPUT, new Map([[OUTPUT, Schema.ofString(OUTPUT).setRef(Namespaces.DATE + ".timeStamp")]]))]]));
25
-
26
- export class MaximumTimestamp extends AbstractFunction {
27
-
28
- public getSignature(): FunctionSignature {
29
- return SIGNATURE;
30
- }
31
-
32
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
33
-
34
- const dates = context?.getArguments()?.get(VALUE);
35
-
36
- const size = dates.length;
37
-
38
- if(size === 0){
39
- throw new KIRuntimeException(ERROR_MESSAGE)
40
- }
41
-
42
- else if (size == 1) {
43
-
44
- const firstDate: string = dates[0];
45
-
46
- if (!ValidDateTimeUtil.validate(firstDate))
47
-
48
- throw new KIRuntimeException(ERROR_MESSAGE);
49
-
50
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, firstDate]]))]);
51
- }
52
-
53
- let maxIndex: number = 0;
54
- let max : number = new Date(dates[0]).getTime();
55
-
56
- for(let i=1;i<size;i++){
57
-
58
- const date: string = dates[i];
59
-
60
- if(!ValidDateTimeUtil.validate(date))
61
- throw new KIRuntimeException(ERROR_MESSAGE);
62
-
63
- const current: number = new Date(date).getTime();
64
-
65
- if(current > max){
66
- max = current;
67
- maxIndex = i;
68
- }
69
- }
70
-
71
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, dates[maxIndex]]]))]);
72
- }
73
- }
@@ -1,74 +0,0 @@
1
- import { KIRuntimeException } from "../../../exception/KIRuntimeException";
2
- import { Schema } from "../../../json/schema/Schema";
3
- import { FunctionOutput } from "../../../model/FunctionOutput";
4
- import { FunctionSignature } from "../../../model/FunctionSignature";
5
- import { Parameter } from "../../../model/Parameter";
6
- import { Namespaces } from "../../../namespaces/Namespaces";
7
- import { FunctionExecutionParameters } from "../../../runtime/FunctionExecutionParameters";
8
- import { ValidDateTimeUtil } from "../../../util/ValidDateTimeUtil";
9
- import { AbstractFunction } from "../../AbstractFunction";
10
- import { EventResult } from "../../../model/EventResult";
11
- import { Event } from "../../../model/Event";
12
-
13
-
14
-
15
- const VALUE: string = "isoDates";
16
-
17
- const OUTPUT: string = "result";
18
-
19
- const ERROR_MESSAGE: string = "Please provide a valid date";
20
-
21
- const SIGNATURE : FunctionSignature = new FunctionSignature('MinimumTimestamp')
22
- .setNamespace(Namespaces.DATE)
23
- .setParameters(new Map([[VALUE, Parameter.of(VALUE, Schema.ofString(VALUE).setRef(Namespaces.DATE + ".timeStamp")).setVariableArgument(true)]]))
24
- .setEvents(new Map([[OUTPUT , new Event(OUTPUT, new Map([[OUTPUT, Schema.ofString(OUTPUT).setRef(Namespaces.DATE + ".timeStamp")]]))]]));
25
-
26
- export class MinimumTimestamp extends AbstractFunction{
27
-
28
- public getSignature(): FunctionSignature {
29
- return SIGNATURE;
30
- }
31
-
32
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
33
-
34
- const dates = context?.getArguments()?.get(VALUE);
35
-
36
- const size = dates.length;
37
-
38
- if(size === 0){
39
- throw new KIRuntimeException(ERROR_MESSAGE)
40
- }
41
-
42
- else if (size == 1) {
43
-
44
- const firstDate: string = dates[0];
45
-
46
- if (!ValidDateTimeUtil.validate(firstDate))
47
-
48
- throw new KIRuntimeException(ERROR_MESSAGE);
49
-
50
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, firstDate]]))]);
51
- }
52
-
53
- let minIndex: number = 0;
54
- let min : number = new Date(dates[0]).getTime();
55
-
56
- for(let i=1;i<size;i++){
57
-
58
- const date: string = dates[i];
59
-
60
- if(!ValidDateTimeUtil.validate(date))
61
- throw new KIRuntimeException(ERROR_MESSAGE);
62
-
63
- const current: number = new Date(date).getTime();
64
-
65
- if(current < min){
66
- min = current;
67
- minIndex = i;
68
- }
69
- }
70
-
71
- return new FunctionOutput([EventResult.outputOf(new Map([[OUTPUT, dates[minIndex]]]))]);
72
- }
73
-
74
- }
@@ -1,56 +0,0 @@
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
-
12
- export class RandomFloat extends AbstractFunction {
13
- public static readonly MIN_VALUE = 'minValue';
14
-
15
- public static readonly MAX_VALUE = 'maxValue';
16
-
17
- public static readonly VALUE = 'value';
18
-
19
- private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('RandomFloat')
20
- .setParameters(
21
- MapUtil.of(
22
- RandomFloat.MIN_VALUE,
23
- Parameter.of(
24
- RandomFloat.MIN_VALUE,
25
- Schema.ofFloat(RandomFloat.MIN_VALUE).setDefaultValue(0),
26
- ),
27
- RandomFloat.MAX_VALUE,
28
- Parameter.of(
29
- RandomFloat.MAX_VALUE,
30
- Schema.ofFloat(RandomFloat.MAX_VALUE).setDefaultValue(2147483647),
31
- ),
32
- ),
33
- )
34
- .setNamespace(Namespaces.MATH)
35
- .setEvents(
36
- new Map<string, Event>([
37
- Event.outputEventMapEntry(
38
- MapUtil.of(RandomFloat.VALUE, Schema.ofFloat(RandomFloat.VALUE)),
39
- ),
40
- ]),
41
- );
42
-
43
- public getSignature(): FunctionSignature {
44
- return RandomFloat.SIGNATURE;
45
- }
46
-
47
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
48
- let min: number = context.getArguments()?.get(RandomFloat.MIN_VALUE);
49
-
50
- let max: number = context.getArguments()?.get(RandomFloat.MAX_VALUE);
51
-
52
- let num: number = Math.random() * (max - min) + min;
53
-
54
- return new FunctionOutput([EventResult.outputOf(new Map([[RandomFloat.VALUE, num]]))]);
55
- }
56
- }
@@ -1,56 +0,0 @@
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
-
12
- export class RandomInt extends AbstractFunction {
13
- public static readonly MIN_VALUE = 'minValue';
14
-
15
- public static readonly MAX_VALUE = 'maxValue';
16
-
17
- public static readonly VALUE = 'value';
18
-
19
- private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('RandomInt')
20
- .setParameters(
21
- MapUtil.of(
22
- RandomInt.MIN_VALUE,
23
- Parameter.of(
24
- RandomInt.MIN_VALUE,
25
- Schema.ofInteger(RandomInt.MIN_VALUE).setDefaultValue(0),
26
- ),
27
- RandomInt.MAX_VALUE,
28
- Parameter.of(
29
- RandomInt.MAX_VALUE,
30
- Schema.ofInteger(RandomInt.MAX_VALUE).setDefaultValue(2147483647),
31
- ),
32
- ),
33
- )
34
- .setNamespace(Namespaces.MATH)
35
- .setEvents(
36
- new Map<string, Event>([
37
- Event.outputEventMapEntry(
38
- MapUtil.of(RandomInt.VALUE, Schema.ofInteger(RandomInt.VALUE)),
39
- ),
40
- ]),
41
- );
42
-
43
- public getSignature(): FunctionSignature {
44
- return RandomInt.SIGNATURE;
45
- }
46
-
47
- protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
48
- let min: number = context.getArguments()?.get(RandomInt.MIN_VALUE);
49
-
50
- let max: number = context.getArguments()?.get(RandomInt.MAX_VALUE);
51
-
52
- let num: number = Math.floor(Math.random() * (max - min) + min);
53
-
54
- return new FunctionOutput([EventResult.outputOf(new Map([[RandomInt.VALUE, num]]))]);
55
- }
56
- }