@fincity/kirun-js 2.5.0 → 2.7.0
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/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/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/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 +13 -7
- package/dist/types.d.ts.map +1 -1
- package/generator/generateValidationCSV.ts +6 -1
- package/generator/validation-js.csv +0 -0
- package/package.json +4 -1
- package/src/engine/function/system/object/ObjectConvert.ts +73 -0
- package/src/engine/function/system/object/ObjectPutValue.ts +0 -2
- 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/util/json/ConvertorUtil.ts +51 -0
- package/src/engine/util/json/ValidatorUtil.ts +29 -0
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrayValidator,
|
|
3
|
+
BooleanValidator,
|
|
4
|
+
KIRunSchemaRepository,
|
|
5
|
+
MapUtil,
|
|
6
|
+
NumberValidator,
|
|
7
|
+
Schema,
|
|
8
|
+
SchemaType,
|
|
9
|
+
StringValidator,
|
|
10
|
+
TypeValidator,
|
|
11
|
+
} from '../../../../../src';
|
|
12
|
+
import { StringConvertor } from '../../../../../src/engine/json/schema/convertor/StringConvertor';
|
|
13
|
+
import { ConversionMode } from '../../../../../src/engine/json/schema/convertor/enums/ConversionMode';
|
|
14
|
+
import { NumberConvertor } from '../../../../../src/engine/json/schema/convertor/NumberConvertor';
|
|
15
|
+
import { BooleanConvertor } from '../../../../../src/engine/json/schema/convertor/BooleanConvertor';
|
|
16
|
+
import { NullConvertor } from '../../../../../src/engine/json/schema/convertor/NullConvertor';
|
|
17
|
+
|
|
18
|
+
const repo = new KIRunSchemaRepository();
|
|
19
|
+
|
|
20
|
+
test('Type Validator for Number', async () => {
|
|
21
|
+
const element = { value: 123 };
|
|
22
|
+
const schema = new Schema();
|
|
23
|
+
|
|
24
|
+
const result = await TypeValidator.validate(
|
|
25
|
+
[],
|
|
26
|
+
SchemaType.INTEGER,
|
|
27
|
+
schema,
|
|
28
|
+
repo,
|
|
29
|
+
element.value,
|
|
30
|
+
);
|
|
31
|
+
expect(result).toEqual(NumberValidator.validate(SchemaType.INTEGER, [], schema, element.value));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('Type Validator for String', async () => {
|
|
35
|
+
const element = { value: 'string' };
|
|
36
|
+
const schema = new Schema();
|
|
37
|
+
|
|
38
|
+
const result = await TypeValidator.validate([], SchemaType.STRING, schema, repo, element.value);
|
|
39
|
+
expect(result).toEqual(StringValidator.validate([], schema, element.value));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Type Validator for Boolean', async () => {
|
|
43
|
+
const element = { value: true };
|
|
44
|
+
const schema = new Schema();
|
|
45
|
+
|
|
46
|
+
const result = await TypeValidator.validate(
|
|
47
|
+
[],
|
|
48
|
+
SchemaType.BOOLEAN,
|
|
49
|
+
schema,
|
|
50
|
+
repo,
|
|
51
|
+
element.value,
|
|
52
|
+
);
|
|
53
|
+
expect(result).toEqual(BooleanValidator.validate([], schema, element.value));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('Type Validator for Array', async () => {
|
|
57
|
+
const schema = new Schema();
|
|
58
|
+
const array = ['abc'];
|
|
59
|
+
|
|
60
|
+
const result = await TypeValidator.validate([], SchemaType.ARRAY, schema, repo, array);
|
|
61
|
+
const expected = await ArrayValidator.validate([], schema, repo, array);
|
|
62
|
+
expect(result).toEqual(expected);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('Type Validator for Null', async () => {
|
|
66
|
+
const schema = new Schema();
|
|
67
|
+
|
|
68
|
+
const result = await TypeValidator.validate([], SchemaType.NULL, schema, repo, null);
|
|
69
|
+
expect(result).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('Type Validator with String Conversion', async () => {
|
|
73
|
+
const element = { value: 'string' };
|
|
74
|
+
const schema = new Schema();
|
|
75
|
+
|
|
76
|
+
const result = await TypeValidator.validate(
|
|
77
|
+
[],
|
|
78
|
+
SchemaType.STRING,
|
|
79
|
+
schema,
|
|
80
|
+
repo,
|
|
81
|
+
element.value,
|
|
82
|
+
true,
|
|
83
|
+
ConversionMode.STRICT,
|
|
84
|
+
);
|
|
85
|
+
expect(result).toEqual(
|
|
86
|
+
StringConvertor.convert([], schema, ConversionMode.STRICT, element.value),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('Type Validator with Number Conversion', async () => {
|
|
91
|
+
const element = { value: '12345' };
|
|
92
|
+
const schema = new Schema();
|
|
93
|
+
|
|
94
|
+
const result = await TypeValidator.validate(
|
|
95
|
+
[],
|
|
96
|
+
SchemaType.INTEGER,
|
|
97
|
+
schema,
|
|
98
|
+
repo,
|
|
99
|
+
element.value,
|
|
100
|
+
true,
|
|
101
|
+
ConversionMode.STRICT,
|
|
102
|
+
);
|
|
103
|
+
expect(result).toEqual(
|
|
104
|
+
NumberConvertor.convert(
|
|
105
|
+
[],
|
|
106
|
+
SchemaType.INTEGER,
|
|
107
|
+
schema,
|
|
108
|
+
ConversionMode.STRICT,
|
|
109
|
+
element.value,
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('Type Validator with Boolean Conversion', async () => {
|
|
115
|
+
const element = { value: 'true' };
|
|
116
|
+
const schema = new Schema();
|
|
117
|
+
|
|
118
|
+
const result = await TypeValidator.validate(
|
|
119
|
+
[],
|
|
120
|
+
SchemaType.BOOLEAN,
|
|
121
|
+
schema,
|
|
122
|
+
repo,
|
|
123
|
+
element.value,
|
|
124
|
+
true,
|
|
125
|
+
ConversionMode.STRICT,
|
|
126
|
+
);
|
|
127
|
+
expect(result).toEqual(
|
|
128
|
+
BooleanConvertor.convert([], schema, ConversionMode.STRICT, element.value),
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('Type Validator with Null Conversion', async () => {
|
|
133
|
+
const element = null;
|
|
134
|
+
const schema = new Schema();
|
|
135
|
+
|
|
136
|
+
const result = await TypeValidator.validate(
|
|
137
|
+
[],
|
|
138
|
+
SchemaType.NULL,
|
|
139
|
+
schema,
|
|
140
|
+
repo,
|
|
141
|
+
element,
|
|
142
|
+
true,
|
|
143
|
+
ConversionMode.STRICT,
|
|
144
|
+
);
|
|
145
|
+
expect(result).toEqual(NullConvertor.convert([], schema, ConversionMode.STRICT, element));
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('Boolean Convertor Array', async () => {
|
|
149
|
+
const schema = Schema.ofArray('boolean', Schema.ofBoolean('boolean'));
|
|
150
|
+
|
|
151
|
+
const booleanArray: (string | number | boolean)[] = [true, false, 'yes', 'no', 'y', 'n', 1, 0];
|
|
152
|
+
|
|
153
|
+
const expectedArray: boolean[] = [true, false, true, false, true, false, true, false];
|
|
154
|
+
|
|
155
|
+
const result: any = await TypeValidator.validate(
|
|
156
|
+
[],
|
|
157
|
+
SchemaType.ARRAY,
|
|
158
|
+
schema,
|
|
159
|
+
repo,
|
|
160
|
+
booleanArray,
|
|
161
|
+
true,
|
|
162
|
+
ConversionMode.STRICT,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(result).toEqual(expectedArray);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('Number Convertor Array', async () => {
|
|
169
|
+
const schema = Schema.ofArray('number', Schema.ofNumber('number'));
|
|
170
|
+
|
|
171
|
+
const numberArray = ['11', '11.12', '11192371231', '1123.123', '0'];
|
|
172
|
+
|
|
173
|
+
const expectedArray = [11, 11.12, 11192371231, 1123.123, 0];
|
|
174
|
+
|
|
175
|
+
const result = await TypeValidator.validate(
|
|
176
|
+
[],
|
|
177
|
+
SchemaType.ARRAY,
|
|
178
|
+
schema,
|
|
179
|
+
repo,
|
|
180
|
+
numberArray,
|
|
181
|
+
true,
|
|
182
|
+
ConversionMode.LENIENT,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
expect(result).toEqual(expectedArray);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('Object Conversion', async () => {
|
|
189
|
+
const numberArray: string[] = ['11', '11.12', '11192371231', '1123.123', '0'];
|
|
190
|
+
|
|
191
|
+
const object = {
|
|
192
|
+
int: '1997',
|
|
193
|
+
long: '123123123',
|
|
194
|
+
float: '123.12',
|
|
195
|
+
double: '123.1232',
|
|
196
|
+
booleanTrue: 'true',
|
|
197
|
+
booleanFalse: 'false',
|
|
198
|
+
string: 12314,
|
|
199
|
+
numberArray: numberArray,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const schema: Schema = Schema.ofObject('jsonObject').setProperties(
|
|
203
|
+
MapUtil.of(
|
|
204
|
+
'int',
|
|
205
|
+
Schema.ofNumber('int'),
|
|
206
|
+
'long',
|
|
207
|
+
Schema.ofLong('long'),
|
|
208
|
+
'float',
|
|
209
|
+
Schema.ofFloat('float'),
|
|
210
|
+
'double',
|
|
211
|
+
Schema.ofNumber('double'),
|
|
212
|
+
'booleanTrue',
|
|
213
|
+
Schema.ofBoolean('booleanTrue'),
|
|
214
|
+
'booleanFalse',
|
|
215
|
+
Schema.ofBoolean('booleanFalse'),
|
|
216
|
+
'string',
|
|
217
|
+
Schema.ofString('string'),
|
|
218
|
+
'numberArray',
|
|
219
|
+
Schema.ofArray('number', Schema.ofNumber('number')),
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const expectedObject = {
|
|
224
|
+
int: 1997,
|
|
225
|
+
long: 123123123,
|
|
226
|
+
float: 123.12,
|
|
227
|
+
double: 123.1232,
|
|
228
|
+
booleanTrue: true,
|
|
229
|
+
booleanFalse: false,
|
|
230
|
+
string: '12314',
|
|
231
|
+
numberArray: [11, 11.12, 11192371231, 1123.123, 0],
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const result: any = await TypeValidator.validate(
|
|
235
|
+
[],
|
|
236
|
+
SchemaType.OBJECT,
|
|
237
|
+
schema,
|
|
238
|
+
repo,
|
|
239
|
+
object,
|
|
240
|
+
true,
|
|
241
|
+
ConversionMode.STRICT,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
expect(result).toEqual(expectedObject);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('Object of Object Conversion', async () => {
|
|
248
|
+
const innerObject = {
|
|
249
|
+
innerInt: '42',
|
|
250
|
+
innerString: 'innerValue',
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const outerObject = {
|
|
254
|
+
innerObject: innerObject,
|
|
255
|
+
outerInt: '100',
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const innerSchema: Schema = Schema.ofObject('innerObject').setProperties(
|
|
259
|
+
MapUtil.of(
|
|
260
|
+
'innerInt',
|
|
261
|
+
Schema.ofNumber('innerInt'),
|
|
262
|
+
'innerString',
|
|
263
|
+
Schema.ofString('innerString'),
|
|
264
|
+
),
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const outerSchema: Schema = Schema.ofObject('outerObject').setProperties(
|
|
268
|
+
MapUtil.of('innerObject', innerSchema, 'outerInt', Schema.ofNumber('outerInt')),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const expectedOuterObject = {
|
|
272
|
+
innerObject: {
|
|
273
|
+
innerInt: 42,
|
|
274
|
+
innerString: 'innerValue',
|
|
275
|
+
},
|
|
276
|
+
outerInt: 100,
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const result: any = await TypeValidator.validate(
|
|
280
|
+
[],
|
|
281
|
+
SchemaType.OBJECT,
|
|
282
|
+
outerSchema,
|
|
283
|
+
repo,
|
|
284
|
+
outerObject,
|
|
285
|
+
true,
|
|
286
|
+
ConversionMode.STRICT,
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
expect(result).toEqual(expectedOuterObject);
|
|
290
|
+
});
|