@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.
- package/__tests__/engine/function/system/WaitTest.ts +1 -1
- package/__tests__/engine/function/system/array/AddFirstTest.ts +2 -6
- package/__tests__/engine/function/system/array/IndexOfTest.ts +8 -13
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +9 -28
- package/__tests__/engine/function/system/date/AddSubtractTimeTest.ts +93 -0
- package/__tests__/engine/function/system/date/DateFunctionRepositoryTest.ts +96 -0
- package/__tests__/engine/function/system/date/DifferenceTest.ts +93 -0
- package/__tests__/engine/function/system/date/EpochToTimestampTest.ts +133 -0
- package/__tests__/engine/function/system/date/FromDateStringTest.ts +51 -0
- package/__tests__/engine/function/system/date/FromNowTest.ts +71 -0
- package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +19 -27
- package/__tests__/engine/function/system/date/GetNamesTest.ts +105 -0
- package/__tests__/engine/function/system/date/IsBetweenTest.ts +53 -0
- package/__tests__/engine/function/system/date/IsValidISODateTest.ts +42 -54
- package/__tests__/engine/function/system/date/LastFirstOfTest.ts +64 -0
- package/__tests__/engine/function/system/date/SetTimeZoneTest.ts +48 -0
- package/__tests__/engine/function/system/date/StartEndOfTest.ts +53 -0
- package/__tests__/engine/function/system/date/TimeAsTest.ts +24 -0
- package/__tests__/engine/function/system/date/TimestampToEpochTest.ts +45 -0
- package/__tests__/engine/function/system/date/ToDateStringTest.ts +48 -0
- package/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +2 -2
- package/__tests__/engine/function/system/math/MaximumTest.ts +3 -2
- package/__tests__/engine/function/system/math/MinimumTest.ts +18 -20
- package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
- package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
- package/__tests__/engine/json/schema/covnertor/BooleanConvertorTest.ts +55 -0
- package/__tests__/engine/json/schema/covnertor/NullConvertorTest.ts +47 -0
- package/__tests__/engine/json/schema/covnertor/NumberConvertorTest.ts +154 -0
- package/__tests__/engine/json/schema/covnertor/StringConvertorTest.ts +56 -0
- package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +9 -7
- package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +3 -3
- package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +1 -9
- package/__tests__/engine/json/schema/validator/TypeValidatorTest.ts +290 -0
- package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
- package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +27 -20
- package/dist/types.d.ts.map +1 -1
- package/generator/generateValidationCSV.ts +52 -38
- package/generator/validation-js.csv +470 -166
- package/package.json +11 -6
- package/src/engine/function/AbstractFunction.ts +1 -1
- package/src/engine/function/system/Print.ts +19 -5
- package/src/engine/function/system/Wait.ts +1 -1
- package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
- package/src/engine/function/system/array/Fill.ts +1 -1
- package/src/engine/function/system/array/Frequency.ts +0 -1
- package/src/engine/function/system/array/IndexOf.ts +4 -4
- package/src/engine/function/system/array/LastIndexOf.ts +3 -3
- package/src/engine/function/system/array/Rotate.ts +1 -1
- package/src/engine/function/system/array/Shuffle.ts +1 -1
- package/src/engine/function/system/array/Sort.ts +1 -1
- package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
- package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
- package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
- package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
- package/src/engine/function/system/date/FromDateString.ts +44 -0
- package/src/engine/function/system/date/FromNow.ts +77 -0
- package/src/engine/function/system/date/GetCurrent.ts +20 -0
- package/src/engine/function/system/date/GetNames.ts +74 -0
- package/src/engine/function/system/date/IsBetween.ts +62 -0
- package/src/engine/function/system/date/IsValidISODate.ts +54 -40
- package/src/engine/function/system/date/LastFirstOf.ts +72 -0
- package/src/engine/function/system/date/SetTimeZone.ts +43 -0
- package/src/engine/function/system/date/StartEndOf.ts +44 -0
- package/src/engine/function/system/date/TimeAs.ts +64 -0
- package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
- package/src/engine/function/system/date/ToDateString.ts +49 -0
- package/src/engine/function/system/date/common.ts +9 -0
- package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
- package/src/engine/function/system/math/RandomAny.ts +57 -0
- package/src/engine/function/system/object/ObjectConvert.ts +99 -0
- package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
- package/src/engine/function/system/object/ObjectPutValue.ts +0 -2
- package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
- package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
- package/src/engine/json/schema/SchemaUtil.ts +1 -1
- package/src/engine/json/schema/convertor/BooleanConvertor.ts +76 -0
- package/src/engine/json/schema/convertor/NullConvertor.ts +31 -0
- package/src/engine/json/schema/convertor/NumberConvertor.ts +117 -0
- package/src/engine/json/schema/convertor/StringConvertor.ts +41 -0
- package/src/engine/json/schema/convertor/enums/ConversionMode.ts +11 -0
- package/src/engine/json/schema/convertor/exception/SchemaConversionException.ts +39 -0
- package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +96 -36
- package/src/engine/json/schema/validator/ArrayValidator.ts +15 -7
- package/src/engine/json/schema/validator/ObjectValidator.ts +24 -13
- package/src/engine/json/schema/validator/SchemaValidator.ts +74 -22
- package/src/engine/json/schema/validator/TypeValidator.ts +136 -23
- package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
- package/src/engine/util/json/ConvertorUtil.ts +51 -0
- package/src/engine/util/json/ValidatorUtil.ts +29 -0
- package/src/engine/util/string/StringUtil.ts +12 -0
- package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
- package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
- package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
- package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
- package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
- package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
- package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
- package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
- package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
- package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
- package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
- package/src/engine/function/system/date/DateToEpoch.ts +0 -39
- package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
- package/src/engine/function/system/date/EpochToDate.ts +0 -76
- package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
- package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
- package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
- package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
- package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
- package/src/engine/function/system/math/RandomFloat.ts +0 -56
- package/src/engine/function/system/math/RandomInt.ts +0 -56
|
@@ -7,8 +7,22 @@ import { SchemaUtil } from '../SchemaUtil';
|
|
|
7
7
|
import { AnyOfAllOfOneOfValidator } from './AnyOfAllOfOneOfValidator';
|
|
8
8
|
import { SchemaValidationException } from './exception/SchemaValidationException';
|
|
9
9
|
import { TypeValidator } from './TypeValidator';
|
|
10
|
+
import { ConversionMode } from '../convertor/enums/ConversionMode';
|
|
11
|
+
import { SchemaType } from '../type/SchemaType';
|
|
10
12
|
|
|
11
13
|
export class SchemaValidator {
|
|
14
|
+
private static readonly ORDER: Record<SchemaType, number> = {
|
|
15
|
+
[SchemaType.OBJECT]: 0,
|
|
16
|
+
[SchemaType.ARRAY]: 1,
|
|
17
|
+
[SchemaType.DOUBLE]: 2,
|
|
18
|
+
[SchemaType.FLOAT]: 3,
|
|
19
|
+
[SchemaType.LONG]: 4,
|
|
20
|
+
[SchemaType.INTEGER]: 5,
|
|
21
|
+
[SchemaType.STRING]: 6,
|
|
22
|
+
[SchemaType.BOOLEAN]: 7,
|
|
23
|
+
[SchemaType.NULL]: 8,
|
|
24
|
+
};
|
|
25
|
+
|
|
12
26
|
public static path(parents: Schema[] | undefined): string {
|
|
13
27
|
if (!parents) return '';
|
|
14
28
|
|
|
@@ -23,6 +37,8 @@ export class SchemaValidator {
|
|
|
23
37
|
schema: Schema | undefined,
|
|
24
38
|
repository: Repository<Schema> | undefined,
|
|
25
39
|
element: any,
|
|
40
|
+
convert?: boolean,
|
|
41
|
+
mode?: ConversionMode,
|
|
26
42
|
): Promise<any> {
|
|
27
43
|
if (!schema) {
|
|
28
44
|
throw new SchemaValidationException(
|
|
@@ -32,7 +48,7 @@ export class SchemaValidator {
|
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
if (!parents) {
|
|
35
|
-
parents =
|
|
51
|
+
parents = [];
|
|
36
52
|
}
|
|
37
53
|
parents.push(schema);
|
|
38
54
|
|
|
@@ -56,8 +72,22 @@ export class SchemaValidator {
|
|
|
56
72
|
' format.',
|
|
57
73
|
);
|
|
58
74
|
|
|
75
|
+
if (convert === true && isNullValue(schema.getType())) {
|
|
76
|
+
throw new SchemaValidationException(
|
|
77
|
+
this.path(parents),
|
|
78
|
+
'Type is missing in schema for declared ' + mode,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
59
82
|
if (schema.getType()) {
|
|
60
|
-
await SchemaValidator.typeValidation(
|
|
83
|
+
element = await SchemaValidator.typeValidation(
|
|
84
|
+
parents,
|
|
85
|
+
schema,
|
|
86
|
+
repository,
|
|
87
|
+
element,
|
|
88
|
+
convert,
|
|
89
|
+
mode,
|
|
90
|
+
);
|
|
61
91
|
}
|
|
62
92
|
|
|
63
93
|
if (!StringUtil.isNullOrBlank(schema.getRef())) {
|
|
@@ -66,21 +96,32 @@ export class SchemaValidator {
|
|
|
66
96
|
await SchemaUtil.getSchemaFromRef(parents[0], repository, schema.getRef()),
|
|
67
97
|
repository,
|
|
68
98
|
element,
|
|
99
|
+
convert,
|
|
100
|
+
mode,
|
|
69
101
|
);
|
|
70
102
|
}
|
|
71
103
|
|
|
72
104
|
if (schema.getOneOf() || schema.getAllOf() || schema.getAnyOf()) {
|
|
73
|
-
AnyOfAllOfOneOfValidator.validate(
|
|
105
|
+
element = await AnyOfAllOfOneOfValidator.validate(
|
|
106
|
+
parents,
|
|
107
|
+
schema,
|
|
108
|
+
repository,
|
|
109
|
+
element,
|
|
110
|
+
convert,
|
|
111
|
+
mode,
|
|
112
|
+
);
|
|
74
113
|
}
|
|
75
114
|
|
|
76
115
|
if (schema.getNot()) {
|
|
77
|
-
let flag: boolean
|
|
116
|
+
let flag: boolean;
|
|
78
117
|
try {
|
|
79
|
-
|
|
118
|
+
await SchemaValidator.validate(
|
|
80
119
|
parents,
|
|
81
120
|
schema.getNot(),
|
|
82
121
|
repository,
|
|
83
122
|
element,
|
|
123
|
+
convert,
|
|
124
|
+
mode,
|
|
84
125
|
);
|
|
85
126
|
flag = true;
|
|
86
127
|
} catch (err) {
|
|
@@ -129,28 +170,39 @@ export class SchemaValidator {
|
|
|
129
170
|
schema: Schema,
|
|
130
171
|
repository: Repository<Schema> | undefined,
|
|
131
172
|
element: any,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
173
|
+
convert?: boolean,
|
|
174
|
+
mode?: ConversionMode,
|
|
175
|
+
): Promise<any> {
|
|
176
|
+
const allowedTypes: SchemaType[] = Array.from(
|
|
177
|
+
schema.getType()?.getAllowedSchemaTypes()?.values() ?? [],
|
|
178
|
+
).sort(
|
|
179
|
+
(a: SchemaType, b: SchemaType) =>
|
|
180
|
+
(this.ORDER[a] ?? Infinity) - (this.ORDER[b] ?? Infinity),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
let errors: SchemaValidationException[] = [];
|
|
184
|
+
|
|
185
|
+
for (const type of allowedTypes) {
|
|
137
186
|
try {
|
|
138
|
-
await TypeValidator.validate(
|
|
139
|
-
|
|
140
|
-
|
|
187
|
+
return await TypeValidator.validate(
|
|
188
|
+
parents,
|
|
189
|
+
type,
|
|
190
|
+
schema,
|
|
191
|
+
repository,
|
|
192
|
+
element,
|
|
193
|
+
convert,
|
|
194
|
+
mode,
|
|
195
|
+
);
|
|
141
196
|
} catch (err: any) {
|
|
142
|
-
|
|
143
|
-
list.push(err);
|
|
197
|
+
errors.push(err);
|
|
144
198
|
}
|
|
145
199
|
}
|
|
146
200
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
153
|
-
}
|
|
201
|
+
throw new SchemaValidationException(
|
|
202
|
+
SchemaValidator.path(parents),
|
|
203
|
+
'Value ' + JSON.stringify(element) + ' is not of valid type(s)',
|
|
204
|
+
errors,
|
|
205
|
+
);
|
|
154
206
|
}
|
|
155
207
|
|
|
156
208
|
private constructor() {}
|
|
@@ -3,12 +3,19 @@ import { Schema } from '../Schema';
|
|
|
3
3
|
import { SchemaType } from '../type/SchemaType';
|
|
4
4
|
import { ArrayValidator } from './ArrayValidator';
|
|
5
5
|
import { BooleanValidator } from './BooleanValidator';
|
|
6
|
-
import { SchemaValidationException } from './exception/SchemaValidationException';
|
|
7
6
|
import { NullValidator } from './NullValidator';
|
|
8
7
|
import { NumberValidator } from './NumberValidator';
|
|
9
8
|
import { ObjectValidator } from './ObjectValidator';
|
|
10
|
-
import { SchemaValidator } from './SchemaValidator';
|
|
11
9
|
import { StringValidator } from './StringValidator';
|
|
10
|
+
import { ConversionMode } from '../convertor/enums/ConversionMode';
|
|
11
|
+
import { ConvertorUtil } from '../../../util/json/ConvertorUtil';
|
|
12
|
+
import { StringFormatter } from '../../../util/string/StringFormatter';
|
|
13
|
+
import { StringConvertor } from '../convertor/StringConvertor';
|
|
14
|
+
import { NumberConvertor } from '../convertor/NumberConvertor';
|
|
15
|
+
import { BooleanConvertor } from '../convertor/BooleanConvertor';
|
|
16
|
+
import { NullConvertor } from '../convertor/NullConvertor';
|
|
17
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
18
|
+
import { ValidatorUtil } from '../../../util/json/ValidatorUtil';
|
|
12
19
|
|
|
13
20
|
export class TypeValidator {
|
|
14
21
|
public static async validate(
|
|
@@ -17,32 +24,138 @@ export class TypeValidator {
|
|
|
17
24
|
schema: Schema,
|
|
18
25
|
repository: Repository<Schema> | undefined,
|
|
19
26
|
element: any,
|
|
27
|
+
convert?: boolean,
|
|
28
|
+
mode?: ConversionMode,
|
|
20
29
|
): Promise<any> {
|
|
21
|
-
if (type == SchemaType.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} else if (type == SchemaType.BOOLEAN) {
|
|
31
|
-
BooleanValidator.validate(parents, schema, element);
|
|
32
|
-
} else if (type == SchemaType.OBJECT) {
|
|
33
|
-
await ObjectValidator.validate(parents, schema, repository, element);
|
|
30
|
+
if (type == SchemaType.OBJECT) {
|
|
31
|
+
return await ObjectValidator.validate(
|
|
32
|
+
parents,
|
|
33
|
+
schema,
|
|
34
|
+
repository,
|
|
35
|
+
element,
|
|
36
|
+
convert,
|
|
37
|
+
mode,
|
|
38
|
+
);
|
|
34
39
|
} else if (type == SchemaType.ARRAY) {
|
|
35
|
-
await ArrayValidator.validate(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
return await ArrayValidator.validate(
|
|
41
|
+
parents,
|
|
42
|
+
schema,
|
|
43
|
+
repository,
|
|
44
|
+
element,
|
|
45
|
+
convert,
|
|
46
|
+
mode,
|
|
42
47
|
);
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
return
|
|
50
|
+
return this.handleTypeValidationAndConversion(
|
|
51
|
+
parents,
|
|
52
|
+
type,
|
|
53
|
+
schema,
|
|
54
|
+
element,
|
|
55
|
+
convert,
|
|
56
|
+
mode,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private static async handleTypeValidationAndConversion(
|
|
61
|
+
parents: Schema[],
|
|
62
|
+
type: SchemaType,
|
|
63
|
+
schema: Schema,
|
|
64
|
+
element: any,
|
|
65
|
+
convert?: boolean,
|
|
66
|
+
mode?: ConversionMode,
|
|
67
|
+
): Promise<any> {
|
|
68
|
+
const cElement = convert
|
|
69
|
+
? this.convertElement(parents, type, schema, element, mode ?? ConversionMode.STRICT)
|
|
70
|
+
: element;
|
|
71
|
+
|
|
72
|
+
return await this.validateElement(
|
|
73
|
+
parents,
|
|
74
|
+
type,
|
|
75
|
+
schema,
|
|
76
|
+
cElement,
|
|
77
|
+
mode ?? ConversionMode.STRICT,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private static convertElement(
|
|
82
|
+
parents: Schema[],
|
|
83
|
+
type: SchemaType,
|
|
84
|
+
schema: Schema,
|
|
85
|
+
element: any,
|
|
86
|
+
mode: ConversionMode,
|
|
87
|
+
): any | null {
|
|
88
|
+
if (isNullValue(type)) {
|
|
89
|
+
return ConvertorUtil.handleUnConvertibleValueWithDefault(
|
|
90
|
+
parents,
|
|
91
|
+
mode,
|
|
92
|
+
element,
|
|
93
|
+
schema.getDefaultValue() ?? null,
|
|
94
|
+
StringFormatter.format('$ is not a valid type for conversion.', type),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
switch (type) {
|
|
99
|
+
case SchemaType.STRING:
|
|
100
|
+
return StringConvertor.convert(parents, schema, mode, element);
|
|
101
|
+
case SchemaType.INTEGER:
|
|
102
|
+
case SchemaType.LONG:
|
|
103
|
+
case SchemaType.DOUBLE:
|
|
104
|
+
case SchemaType.FLOAT:
|
|
105
|
+
return NumberConvertor.convert(parents, type, schema, mode, element);
|
|
106
|
+
case SchemaType.BOOLEAN:
|
|
107
|
+
return BooleanConvertor.convert(parents, schema, mode, element);
|
|
108
|
+
case SchemaType.NULL:
|
|
109
|
+
return NullConvertor.convert(parents, schema, mode, element);
|
|
110
|
+
default:
|
|
111
|
+
return ConvertorUtil.handleUnConvertibleValueWithDefault(
|
|
112
|
+
parents,
|
|
113
|
+
mode,
|
|
114
|
+
element,
|
|
115
|
+
schema.getDefaultValue() ?? null,
|
|
116
|
+
StringFormatter.format('$ is not a valid type for conversion.', type),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private static validateElement(
|
|
122
|
+
parents: Schema[],
|
|
123
|
+
type: SchemaType,
|
|
124
|
+
schema: Schema,
|
|
125
|
+
element: any,
|
|
126
|
+
mode: ConversionMode,
|
|
127
|
+
): any | null {
|
|
128
|
+
if (isNullValue(type)) {
|
|
129
|
+
return ValidatorUtil.handleValidationError(
|
|
130
|
+
parents,
|
|
131
|
+
mode,
|
|
132
|
+
element,
|
|
133
|
+
schema.getDefaultValue() ?? null,
|
|
134
|
+
StringFormatter.format('$ is not a valid type.', type),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
switch (type) {
|
|
139
|
+
case SchemaType.STRING:
|
|
140
|
+
return StringValidator.validate(parents, schema, element);
|
|
141
|
+
case SchemaType.INTEGER:
|
|
142
|
+
case SchemaType.LONG:
|
|
143
|
+
case SchemaType.DOUBLE:
|
|
144
|
+
case SchemaType.FLOAT:
|
|
145
|
+
return NumberValidator.validate(type, parents, schema, element);
|
|
146
|
+
case SchemaType.BOOLEAN:
|
|
147
|
+
return BooleanValidator.validate(parents, schema, element);
|
|
148
|
+
case SchemaType.NULL:
|
|
149
|
+
return NullValidator.validate(parents, schema, element);
|
|
150
|
+
default:
|
|
151
|
+
return ValidatorUtil.handleValidationError(
|
|
152
|
+
parents,
|
|
153
|
+
mode,
|
|
154
|
+
element,
|
|
155
|
+
schema.getDefaultValue() ?? null,
|
|
156
|
+
StringFormatter.format('$ is not a valid type.', type),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
46
159
|
}
|
|
47
160
|
|
|
48
161
|
private constructor() {}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Schema } from '../json/schema/Schema';
|
|
1
|
+
import { AdditionalType, Schema } from '../json/schema/Schema';
|
|
2
2
|
import { Parameter } from '../model/Parameter';
|
|
3
3
|
import { Namespaces } from '../namespaces/Namespaces';
|
|
4
4
|
import { Repository } from '../Repository';
|
|
5
|
+
import { MapUtil } from '../util/MapUtil';
|
|
5
6
|
|
|
6
7
|
const map: Map<string, Schema> = new Map([
|
|
7
8
|
['any', Schema.ofAny('any').setNamespace(Namespaces.SYSTEM)],
|
|
@@ -12,7 +13,59 @@ const map: Map<string, Schema> = new Map([
|
|
|
12
13
|
['long', Schema.ofLong('long').setNamespace(Namespaces.SYSTEM)],
|
|
13
14
|
['number', Schema.ofNumber('number').setNamespace(Namespaces.SYSTEM)],
|
|
14
15
|
['string', Schema.ofString('string').setNamespace(Namespaces.SYSTEM)],
|
|
15
|
-
['
|
|
16
|
+
['Timestamp', Schema.ofString('Timestamp').setNamespace(Namespaces.DATE)],
|
|
17
|
+
[
|
|
18
|
+
'Timeunit',
|
|
19
|
+
Schema.ofString('Timeunit')
|
|
20
|
+
.setNamespace(Namespaces.DATE)
|
|
21
|
+
.setEnums([
|
|
22
|
+
'YEARS',
|
|
23
|
+
'QUARTERS',
|
|
24
|
+
'MONTHS',
|
|
25
|
+
'WEEKS',
|
|
26
|
+
'DAYS',
|
|
27
|
+
'HOURS',
|
|
28
|
+
'MINUTES',
|
|
29
|
+
'SECONDS',
|
|
30
|
+
'MILLISECONDS',
|
|
31
|
+
]),
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'Duration',
|
|
35
|
+
Schema.ofObject('Duration')
|
|
36
|
+
.setNamespace(Namespaces.DATE)
|
|
37
|
+
.setProperties(
|
|
38
|
+
MapUtil.ofArrayEntries(
|
|
39
|
+
['years', Schema.ofInteger('years')],
|
|
40
|
+
['quarters', Schema.ofInteger('quarters')],
|
|
41
|
+
['months', Schema.ofInteger('months')],
|
|
42
|
+
['weeks', Schema.ofInteger('weeks')],
|
|
43
|
+
['days', Schema.ofInteger('days')],
|
|
44
|
+
['hours', Schema.ofInteger('hours')],
|
|
45
|
+
['minutes', Schema.ofInteger('minutes')],
|
|
46
|
+
['seconds', Schema.ofLong('seconds')],
|
|
47
|
+
['milliseconds', Schema.ofLong('milliseconds')],
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
.setAdditionalItems(AdditionalType.from(false)!),
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
'TimeObject',
|
|
54
|
+
Schema.ofObject('TimeObject')
|
|
55
|
+
.setNamespace(Namespaces.DATE)
|
|
56
|
+
.setProperties(
|
|
57
|
+
MapUtil.ofArrayEntries(
|
|
58
|
+
['year', Schema.ofInteger('year')],
|
|
59
|
+
['month', Schema.ofInteger('month')],
|
|
60
|
+
['day', Schema.ofInteger('day')],
|
|
61
|
+
['hour', Schema.ofInteger('hour')],
|
|
62
|
+
['minute', Schema.ofInteger('minute')],
|
|
63
|
+
['second', Schema.ofLong('second')],
|
|
64
|
+
['millisecond', Schema.ofLong('millisecond')],
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
.setAdditionalItems(AdditionalType.from(false)!),
|
|
68
|
+
],
|
|
16
69
|
[Parameter.EXPRESSION.getName()!, Parameter.EXPRESSION],
|
|
17
70
|
[Schema.NULL.getName()!, Schema.NULL],
|
|
18
71
|
[Schema.SCHEMA.getName()!, Schema.SCHEMA],
|
|
@@ -22,7 +75,8 @@ const filterableNames = Array.from(map.values()).map((e) => e.getFullName());
|
|
|
22
75
|
|
|
23
76
|
export class KIRunSchemaRepository implements Repository<Schema> {
|
|
24
77
|
public async find(namespace: string, name: string): Promise<Schema | undefined> {
|
|
25
|
-
if (Namespaces.SYSTEM != namespace
|
|
78
|
+
if (Namespaces.SYSTEM != namespace && Namespaces.DATE != namespace)
|
|
79
|
+
return Promise.resolve(undefined);
|
|
26
80
|
|
|
27
81
|
return Promise.resolve(map.get(name));
|
|
28
82
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Schema } from '../../json/schema/Schema';
|
|
2
|
+
import { ConversionMode } from '../../json/schema/convertor/enums/ConversionMode';
|
|
3
|
+
import { SchemaConversionException } from '../../json/schema/convertor/exception/SchemaConversionException';
|
|
4
|
+
import { SchemaValidator } from '../../json/schema/validator/SchemaValidator';
|
|
5
|
+
|
|
6
|
+
export class ConvertorUtil {
|
|
7
|
+
public static handleUnConvertibleValue(
|
|
8
|
+
parents: Schema[],
|
|
9
|
+
mode: ConversionMode | null,
|
|
10
|
+
element: any,
|
|
11
|
+
errorMessage: string,
|
|
12
|
+
): any | null {
|
|
13
|
+
return this.handleUnConvertibleValueWithDefault(parents, mode, element, null, errorMessage);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static handleUnConvertibleValueWithDefault(
|
|
17
|
+
parents: Schema[],
|
|
18
|
+
mode: ConversionMode | null,
|
|
19
|
+
element: any,
|
|
20
|
+
defaultValue: any,
|
|
21
|
+
errorMessage: string,
|
|
22
|
+
): any | null {
|
|
23
|
+
if (mode === null) {
|
|
24
|
+
mode = ConversionMode.STRICT;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
switch (mode) {
|
|
28
|
+
case ConversionMode.STRICT:
|
|
29
|
+
throw new SchemaConversionException(
|
|
30
|
+
SchemaValidator.path(parents),
|
|
31
|
+
element,
|
|
32
|
+
errorMessage,
|
|
33
|
+
mode,
|
|
34
|
+
);
|
|
35
|
+
case ConversionMode.LENIENT:
|
|
36
|
+
return null;
|
|
37
|
+
case ConversionMode.USE_DEFAULT:
|
|
38
|
+
return defaultValue;
|
|
39
|
+
case ConversionMode.SKIP:
|
|
40
|
+
return element;
|
|
41
|
+
default:
|
|
42
|
+
throw new SchemaConversionException(
|
|
43
|
+
SchemaValidator.path(parents),
|
|
44
|
+
element,
|
|
45
|
+
'Invalid conversion mode',
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private constructor() {}
|
|
51
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Schema } from '../../json/schema/Schema';
|
|
2
|
+
import { ConversionMode } from '../../json/schema/convertor/enums/ConversionMode';
|
|
3
|
+
import { SchemaValidationException } from '../../json/schema/validator/exception/SchemaValidationException';
|
|
4
|
+
import { SchemaValidator } from '../../json/schema/validator/SchemaValidator';
|
|
5
|
+
|
|
6
|
+
export class ValidatorUtil {
|
|
7
|
+
public static handleValidationError(
|
|
8
|
+
parents: Schema[],
|
|
9
|
+
mode: ConversionMode,
|
|
10
|
+
element: any,
|
|
11
|
+
defaultValue: any,
|
|
12
|
+
errorMessage: string,
|
|
13
|
+
): any | null {
|
|
14
|
+
mode = mode ?? ConversionMode.STRICT;
|
|
15
|
+
|
|
16
|
+
switch (mode) {
|
|
17
|
+
case ConversionMode.STRICT:
|
|
18
|
+
throw new SchemaValidationException(SchemaValidator.path(parents), errorMessage);
|
|
19
|
+
case ConversionMode.LENIENT:
|
|
20
|
+
return null;
|
|
21
|
+
case ConversionMode.USE_DEFAULT:
|
|
22
|
+
return defaultValue;
|
|
23
|
+
case ConversionMode.SKIP:
|
|
24
|
+
return element;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private constructor() {}
|
|
29
|
+
}
|
|
@@ -42,6 +42,18 @@ export class StringUtil {
|
|
|
42
42
|
return [str.substring(0, index), str.substring(index + 1)];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
public static splitAtLastOccurance(
|
|
46
|
+
str: string,
|
|
47
|
+
c: string,
|
|
48
|
+
): [string | undefined, string | undefined] {
|
|
49
|
+
if (!str) return [undefined, undefined];
|
|
50
|
+
|
|
51
|
+
let index: number = str.lastIndexOf(c);
|
|
52
|
+
if (index == -1) return [str, undefined];
|
|
53
|
+
|
|
54
|
+
return [str.substring(0, index), str.substring(index + 1)];
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
public static isNullOrBlank(str: string | undefined): boolean {
|
|
46
58
|
return !str || str.trim() == '';
|
|
47
59
|
}
|
|
@@ -1,115 +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 addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
15
|
-
|
|
16
|
-
if (!addTimeFunction) {
|
|
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( () => addTimeFunction.execute(fep)).rejects.toThrow();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('Add Time 1', async () => {
|
|
30
|
-
|
|
31
|
-
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
32
|
-
|
|
33
|
-
if (!addTimeFunction) {
|
|
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 addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-14T00:02:34.633-05:30');
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('Add Time 2', async () => {
|
|
47
|
-
|
|
48
|
-
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
49
|
-
|
|
50
|
-
if (!addTimeFunction) {
|
|
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 addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2025-10-13T23:52:34.633-05:30');
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
test('Add Time 2', async () => {
|
|
65
|
-
|
|
66
|
-
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
67
|
-
|
|
68
|
-
if (!addTimeFunction) {
|
|
69
|
-
throw new Error("Function not found");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
fep.setArguments(new Map<string, any>([
|
|
73
|
-
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
74
|
-
[AbstractDateFunction.PARAMETER_INT_NAME, 3],
|
|
75
|
-
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'MONTH']
|
|
76
|
-
]));
|
|
77
|
-
|
|
78
|
-
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-12-13T23:52:34.633-05:30');
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
test('Add Time 3', async () => {
|
|
82
|
-
|
|
83
|
-
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
84
|
-
|
|
85
|
-
if (!addTimeFunction) {
|
|
86
|
-
throw new Error("Function not found");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
fep.setArguments(new Map<string, any>([
|
|
90
|
-
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
91
|
-
[AbstractDateFunction.PARAMETER_INT_NAME, 10],
|
|
92
|
-
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
|
|
93
|
-
]));
|
|
94
|
-
|
|
95
|
-
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-13T23:52:44.633-05:30');
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
test('Add Time 4', async () => {
|
|
101
|
-
|
|
102
|
-
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
103
|
-
|
|
104
|
-
if (!addTimeFunction) {
|
|
105
|
-
throw new Error("Function not found");
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
fep.setArguments(new Map<string, any>([
|
|
109
|
-
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
110
|
-
[AbstractDateFunction.PARAMETER_INT_NAME, 5],
|
|
111
|
-
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'YEAR']
|
|
112
|
-
]));
|
|
113
|
-
|
|
114
|
-
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2029-09-13T23:52:34.633-05:30');
|
|
115
|
-
})
|