@fincity/kirun-js 1.5.2 → 1.6.3

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 (39) hide show
  1. package/__tests__/engine/json/schema/validator/ArrayContainsValidatorTest.ts +339 -0
  2. package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +142 -0
  3. package/__tests__/engine/json/schema/validator/ArraySchemaTypeTest.ts +191 -0
  4. package/__tests__/engine/json/schema/validator/ArrayValidatorTest.ts +152 -0
  5. package/__tests__/engine/json/schema/validator/ObjectPropertiesTest.ts +23 -0
  6. package/__tests__/engine/json/schema/validator/ObjectValidatorTest.ts +280 -0
  7. package/__tests__/engine/json/schema/validator/SchemaAnyOfValidatorTest.ts +20 -3
  8. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +21 -5
  9. package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +0 -2
  10. package/__tests__/engine/repository/RepositoryFilterTest.ts +39 -0
  11. package/__tests__/engine/runtime/KIRuntimeFunctionInFunction.ts +6 -0
  12. package/__tests__/engine/runtime/KIRuntimeMessagesTest.ts +179 -0
  13. package/__tests__/engine/runtime/KIRuntimeTest.ts +6 -0
  14. package/__tests__/indexTest.ts +12 -0
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/module.js +1 -1
  18. package/dist/module.js.map +1 -1
  19. package/dist/types.d.ts +23 -12
  20. package/dist/types.d.ts.map +1 -1
  21. package/package.json +1 -1
  22. package/src/engine/HybridRepository.ts +8 -0
  23. package/src/engine/Repository.ts +1 -0
  24. package/src/engine/function/system/Print.ts +1 -1
  25. package/src/engine/function/system/array/ArrayFunctionRepository.ts +10 -0
  26. package/src/engine/function/system/math/MathFunctionRepository.ts +10 -1
  27. package/src/engine/function/system/string/StringFunctionRepository.ts +10 -0
  28. package/src/engine/json/schema/Schema.ts +82 -32
  29. package/src/engine/json/schema/SchemaUtil.ts +6 -3
  30. package/src/engine/json/schema/array/ArraySchemaType.ts +13 -2
  31. package/src/engine/json/schema/validator/ArrayValidator.ts +135 -24
  32. package/src/engine/json/schema/validator/ObjectValidator.ts +9 -4
  33. package/src/engine/model/Event.ts +2 -2
  34. package/src/engine/model/FunctionDefinition.ts +3 -3
  35. package/src/engine/model/FunctionSignature.ts +6 -3
  36. package/src/engine/model/Statement.ts +4 -6
  37. package/src/engine/repository/KIRunFunctionRepository.ts +9 -0
  38. package/src/engine/repository/KIRunSchemaRepository.ts +8 -0
  39. package/src/engine/runtime/KIRuntime.ts +36 -48
@@ -0,0 +1,339 @@
1
+ import {
2
+ ArraySchemaType,
3
+ ArrayValidator,
4
+ isNullValue,
5
+ KIRunSchemaRepository,
6
+ Schema,
7
+ SchemaType,
8
+ Type,
9
+ TypeUtil,
10
+ } from '../../../../../src';
11
+
12
+ const repo = new KIRunSchemaRepository();
13
+
14
+ test('schema array contains test ', () => {
15
+ let tupleS: Schema[] = [
16
+ Schema.ofString('item1'),
17
+ Schema.ofInteger('item2'),
18
+ Schema.ofObject('item3'),
19
+ ];
20
+
21
+ let ast: ArraySchemaType = new ArraySchemaType();
22
+ ast.setTupleSchema(tupleS);
23
+
24
+ let schema: Schema = Schema.ofArray('arraySchema')
25
+ .setItems(ast)
26
+ .setContains(Schema.ofObject('containsS'));
27
+
28
+ let obj = {
29
+ val: false,
30
+ };
31
+
32
+ let array: any[] = ['jimmy', 31, obj];
33
+
34
+ expect(ArrayValidator.validate([], schema, repo, array)).toStrictEqual(array);
35
+ });
36
+
37
+ test('schema array error contains test ', () => {
38
+ let tupleS: Schema[] = [
39
+ Schema.ofString('item1'),
40
+ Schema.ofInteger('item2'),
41
+ Schema.ofObject('item3'),
42
+ ];
43
+
44
+ let ast: ArraySchemaType = new ArraySchemaType();
45
+ ast.setTupleSchema(tupleS);
46
+
47
+ let schema: Schema = Schema.ofArray('arraySchema')
48
+ .setItems(ast)
49
+ .setContains(Schema.ofBoolean('containsS'));
50
+
51
+ let obj = {
52
+ val: false,
53
+ };
54
+
55
+ let array: any[] = ['jimmy', 31, obj];
56
+
57
+ expect(() => ArrayValidator.validate([], schema, repo, array)).toThrow(
58
+ 'None of the items are of type contains schema',
59
+ );
60
+ });
61
+
62
+ test('schema array min contains test ', () => {
63
+ let tupleS: Schema[] = [
64
+ Schema.ofString('item1'),
65
+ Schema.ofInteger('item2'),
66
+ Schema.ofObject('item3'),
67
+ Schema.ofBoolean('item4'),
68
+ Schema.ofObject('item5'),
69
+ ];
70
+
71
+ let ast: ArraySchemaType = new ArraySchemaType();
72
+ ast.setTupleSchema(tupleS);
73
+
74
+ let schema: Schema = Schema.ofArray('arraySchema')
75
+ .setItems(ast)
76
+ .setContains(Schema.ofObject('containsS'))
77
+ .setMinContains(2);
78
+
79
+ let obj = {
80
+ val: false,
81
+ };
82
+ let obj1 = {
83
+ name: 'mcgill',
84
+ };
85
+
86
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
87
+
88
+ expect(ArrayValidator.validate([], schema, repo, array)).toStrictEqual(array);
89
+ });
90
+
91
+ test('schema array max contains test ', () => {
92
+ let tupleS: Schema[] = [
93
+ Schema.ofString('item1'),
94
+ Schema.ofInteger('item2'),
95
+ Schema.ofObject('item3'),
96
+ Schema.ofBoolean('item4'),
97
+ Schema.ofObject('item5'),
98
+ ];
99
+
100
+ let ast: ArraySchemaType = new ArraySchemaType();
101
+ ast.setTupleSchema(tupleS);
102
+
103
+ let schema: Schema = Schema.ofArray('arraySchema')
104
+ .setItems(ast)
105
+ .setContains(Schema.ofObject('containsS'))
106
+ .setMaxContains(3);
107
+
108
+ let obj = {
109
+ val: false,
110
+ };
111
+ let obj1 = {
112
+ name: 'mcgill',
113
+ };
114
+
115
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
116
+
117
+ expect(ArrayValidator.validate([], schema, repo, array)).toStrictEqual(array);
118
+ });
119
+
120
+ test('schema array min contains test ', () => {
121
+ let tupleS: Schema[] = [
122
+ Schema.ofString('item1'),
123
+ Schema.ofInteger('item2'),
124
+ Schema.ofObject('item3'),
125
+ Schema.ofBoolean('item4'),
126
+ Schema.ofObject('item5'),
127
+ ];
128
+
129
+ let ast: ArraySchemaType = new ArraySchemaType();
130
+ ast.setTupleSchema(tupleS);
131
+
132
+ let schema: Schema = Schema.ofArray('arraySchema')
133
+ .setItems(ast)
134
+ .setContains(Schema.ofObject('containsS'))
135
+ .setMinContains(4);
136
+
137
+ let obj = {
138
+ val: false,
139
+ };
140
+ let obj1 = {
141
+ name: 'mcgill',
142
+ };
143
+
144
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
145
+
146
+ expect(() => ArrayValidator.validate([], schema, repo, array)).toThrow(
147
+ 'The minimum number of the items of type contains schema should be ' +
148
+ schema.getMinContains() +
149
+ ' but found 2',
150
+ );
151
+ });
152
+
153
+ test('schema array max contains test ', () => {
154
+ let tupleS: Schema[] = [
155
+ Schema.ofString('item1'),
156
+ Schema.ofInteger('item2'),
157
+ Schema.ofObject('item3'),
158
+ Schema.ofBoolean('item4'),
159
+ Schema.ofObject('item5'),
160
+ ];
161
+
162
+ let ast: ArraySchemaType = new ArraySchemaType();
163
+ ast.setTupleSchema(tupleS);
164
+
165
+ let schema: Schema = Schema.ofArray('arraySchema')
166
+ .setItems(ast)
167
+ .setContains(Schema.ofObject('containsS'))
168
+ .setMaxContains(1);
169
+
170
+ let obj = {
171
+ val: false,
172
+ };
173
+ let obj1 = {
174
+ name: 'mcgill',
175
+ };
176
+
177
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
178
+
179
+ expect(() => ArrayValidator.validate([], schema, repo, array)).toThrow(
180
+ 'The maximum number of the items of type contains schema should be ' +
181
+ schema.getMaxContains() +
182
+ ' but found 2',
183
+ );
184
+ });
185
+
186
+ test('schema array min error contains test ', () => {
187
+ let tupleS: Schema[] = [
188
+ Schema.ofString('item1'),
189
+ Schema.ofInteger('item2'),
190
+ Schema.ofObject('item3'),
191
+ Schema.ofBoolean('item4'),
192
+ Schema.ofObject('item5'),
193
+ ];
194
+
195
+ let ast: ArraySchemaType = new ArraySchemaType();
196
+ ast.setTupleSchema(tupleS);
197
+
198
+ let schema: Schema = Schema.ofArray('arraySchema')
199
+ .setItems(ast)
200
+ .setContains(Schema.ofObject('containsS'))
201
+ .setMinContains(4);
202
+
203
+ let obj = {
204
+ val: false,
205
+ };
206
+ let obj1 = {
207
+ name: 'mcgill',
208
+ };
209
+
210
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
211
+
212
+ expect(() => ArrayValidator.validate([], schema, repo, array)).toThrow(
213
+ 'The minimum number of the items of type contains schema should be ' +
214
+ schema.getMinContains() +
215
+ ' but found 2',
216
+ );
217
+ });
218
+
219
+ test('schema array min max contains test ', () => {
220
+ let tupleS: Schema[] = [
221
+ Schema.ofString('item1'),
222
+ Schema.ofInteger('item2'),
223
+ Schema.ofObject('item3'),
224
+ Schema.ofBoolean('item4'),
225
+ Schema.ofObject('item5'),
226
+ ];
227
+
228
+ let ast: ArraySchemaType = new ArraySchemaType();
229
+ ast.setTupleSchema(tupleS);
230
+
231
+ let schema: Schema = Schema.ofArray('arraySchema')
232
+ .setItems(ast)
233
+ .setContains(Schema.ofObject('containsS'))
234
+ .setMinContains(1)
235
+ .setMaxContains(3);
236
+
237
+ let obj = {
238
+ val: false,
239
+ };
240
+ let obj1 = {
241
+ name: 'mcgill',
242
+ };
243
+
244
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
245
+
246
+ expect(ArrayValidator.validate([], schema, repo, array)).toBe(array);
247
+ });
248
+
249
+ test('schema array min max contains test ', () => {
250
+ let tupleS: Schema[] = [
251
+ Schema.ofString('item1'),
252
+ Schema.ofInteger('item2'),
253
+ Schema.ofObject('item3'),
254
+ Schema.ofBoolean('item4'),
255
+ Schema.ofObject('item5'),
256
+ ];
257
+
258
+ let ast: ArraySchemaType = new ArraySchemaType();
259
+ ast.setTupleSchema(tupleS);
260
+
261
+ let schema: Schema = Schema.ofArray('arraySchema')
262
+ .setItems(ast)
263
+ .setContains(Schema.ofObject('containsS'))
264
+ .setMinContains(1)
265
+ .setMaxContains(0);
266
+
267
+ let obj = {
268
+ val: false,
269
+ };
270
+ let obj1 = {
271
+ name: 'mcgill',
272
+ };
273
+
274
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
275
+
276
+ expect(() => ArrayValidator.validate([], schema, repo, array)).toThrow(
277
+ 'The maximum number of the items of type contains schema should be ' +
278
+ schema.getMaxContains() +
279
+ ' but found 2',
280
+ );
281
+ });
282
+
283
+ test('schema array min max contains without contains test ', () => {
284
+ let tupleS: Schema[] = [
285
+ Schema.ofString('item1'),
286
+ Schema.ofInteger('item2'),
287
+ Schema.ofObject('item3'),
288
+ Schema.ofBoolean('item4'),
289
+ Schema.ofObject('item5'),
290
+ ];
291
+
292
+ let ast: ArraySchemaType = new ArraySchemaType();
293
+ ast.setTupleSchema(tupleS);
294
+
295
+ let schema: Schema = Schema.ofArray('arraySchema')
296
+ .setItems(ast)
297
+ .setMinContains(5)
298
+ .setMaxContains(45);
299
+
300
+ let obj = {
301
+ val: false,
302
+ };
303
+ let obj1 = {
304
+ name: 'mcgill',
305
+ };
306
+
307
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
308
+
309
+ expect(ArrayValidator.validate([], schema, repo, array)).toBe(array);
310
+ });
311
+
312
+ test('schema array min max contains without contains test ', () => {
313
+ let tupleS: Schema[] = [
314
+ Schema.ofString('item1'),
315
+ Schema.ofInteger('item2'),
316
+ Schema.ofObject('item3'),
317
+ Schema.ofBoolean('item4'),
318
+ Schema.ofObject('item5'),
319
+ ];
320
+
321
+ let ast: ArraySchemaType = new ArraySchemaType();
322
+ ast.setTupleSchema(tupleS);
323
+
324
+ let schema: Schema = Schema.ofArray('arraySchema')
325
+ .setItems(ast)
326
+ .setMinContains(1)
327
+ .setMaxContains(0);
328
+
329
+ let obj = {
330
+ val: false,
331
+ };
332
+ let obj1 = {
333
+ name: 'mcgill',
334
+ };
335
+
336
+ let array: any[] = ['jimmy', 31, obj, true, obj1];
337
+
338
+ expect(ArrayValidator.validate([], schema, repo, array)).toBe(array);
339
+ });
@@ -0,0 +1,142 @@
1
+ import { KIRunSchemaRepository, SchemaValidator } from '../../../../../src';
2
+ import { Schema } from '../../../../../src/engine/json/schema/Schema';
3
+
4
+ const repo = new KIRunSchemaRepository();
5
+ test('schemaArray With Single Test', () => {
6
+ let schema = Schema.from({
7
+ type: 'ARRAY',
8
+ items: {
9
+ singleSchema: {
10
+ type: 'OBJECT',
11
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
12
+ },
13
+ },
14
+ additionalItems: false,
15
+ });
16
+
17
+ let obj = [
18
+ {
19
+ name: 'amigo1',
20
+ },
21
+ {
22
+ age: 24,
23
+ },
24
+ false,
25
+ 'exampleString',
26
+ ];
27
+
28
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrow();
29
+ });
30
+
31
+ test('schemaArray With out Single fail Test', () => {
32
+ let schema = Schema.from({
33
+ type: 'ARRAY',
34
+ items: {
35
+ type: 'OBJECT',
36
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
37
+ },
38
+
39
+ additionalItems: false,
40
+ });
41
+
42
+ let obj = [
43
+ {
44
+ name: 'amigo1',
45
+ },
46
+ {
47
+ age: 24,
48
+ },
49
+ false,
50
+ 'exampleString',
51
+ ];
52
+
53
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrow();
54
+ });
55
+
56
+ test('schemaArrayWithSingle pass Test', () => {
57
+ let schema = Schema.from({
58
+ type: 'ARRAY',
59
+ items: {
60
+ singleSchema: {
61
+ type: 'OBJECT',
62
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
63
+ },
64
+ },
65
+
66
+ additionalItems: false,
67
+ });
68
+
69
+ let obj = [
70
+ {
71
+ name: 'amigo1',
72
+ },
73
+ {
74
+ age: 24,
75
+ },
76
+ ];
77
+
78
+ expect(SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
79
+ });
80
+
81
+ test('schemaArray With Tuple Test ', () => {
82
+ let schema = Schema.from({
83
+ type: 'ARRAY',
84
+ items: {
85
+ tupleSchema: [
86
+ {
87
+ type: 'OBJECT',
88
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
89
+ required: ['age'],
90
+ },
91
+ { type: 'STRING', minLength: 2 },
92
+ { type: 'INTEGER', minimum: 10 },
93
+ ],
94
+ },
95
+ additionalItems: true,
96
+ });
97
+
98
+ let obj = [
99
+ {
100
+ name: 'amigo1',
101
+ age: 24,
102
+ },
103
+ 'string type',
104
+
105
+ 11,
106
+ false,
107
+ 12.34,
108
+ 'mla',
109
+ ];
110
+ console.log(JSON.stringify(schema, undefined, 2));
111
+
112
+ expect(SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
113
+ });
114
+
115
+ test('schemaArray With out Tuple Test ', () => {
116
+ let schema = Schema.from({
117
+ type: 'ARRAY',
118
+ items: [
119
+ {
120
+ type: 'OBJECT',
121
+ properties: { name: { type: 'STRING' }, age: { type: 'INTEGER' } },
122
+ required: ['age'],
123
+ },
124
+ { type: 'STRING', minLength: 2 },
125
+ { type: 'ARRAY', items: { type: 'INTEGER' }, additionalItems: false },
126
+ ],
127
+ additionalItems: true,
128
+ });
129
+
130
+ let obj = [
131
+ {
132
+ name: 'amigo1',
133
+ age: 21,
134
+ },
135
+ 'second string',
136
+ [1, 2, 31231],
137
+ 'additional items was added here with true and false',
138
+ true,
139
+ false,
140
+ ];
141
+ expect(SchemaValidator.validate([], schema, repo, obj)).toBe(obj);
142
+ });
@@ -0,0 +1,191 @@
1
+ import {
2
+ AdditionalType,
3
+ ArraySchemaType,
4
+ ArrayValidator,
5
+ KIRunSchemaRepository,
6
+ Schema,
7
+ SchemaValidator,
8
+ } from '../../../../../src';
9
+
10
+ const repo = new KIRunSchemaRepository();
11
+
12
+ test('schema array validator test for single', () => {
13
+ let ast = new ArraySchemaType();
14
+ ast.setSingleSchema(Schema.ofInteger('ast'));
15
+
16
+ const schema: Schema = Schema.ofArray('schema').setItems(ast);
17
+
18
+ let arr = [12, 23, 54, 45];
19
+
20
+ expect(ArrayValidator.validate([], schema, repo, arr)).toStrictEqual(arr);
21
+ });
22
+
23
+ test('schema array validator test for tuple', () => {
24
+ let tupleS: Schema[] = [
25
+ Schema.ofInteger('item1'),
26
+ Schema.ofString('item2'),
27
+ Schema.ofObject('item3'),
28
+ ];
29
+
30
+ let ast = new ArraySchemaType();
31
+ ast.setTupleSchema(tupleS);
32
+
33
+ const schema: Schema = Schema.ofArray('schema').setItems(ast);
34
+
35
+ let arr = [12, 'surendhar', { a: 'val1', b: 'val2' }];
36
+
37
+ expect(ArrayValidator.validate([], schema, repo, arr)).toStrictEqual(arr);
38
+ });
39
+
40
+ test('schema array validator test for single', () => {
41
+ let ast = new ArraySchemaType();
42
+ ast.setSingleSchema(Schema.ofInteger('ast'));
43
+
44
+ const schema: Schema = Schema.ofArray('schema')
45
+ .setItems(ast)
46
+ .setAdditionalItems(new AdditionalType().setBooleanValue(false));
47
+
48
+ let arr = [12, 23, 54, 45];
49
+
50
+ expect(ArrayValidator.validate([], schema, repo, arr)).toStrictEqual(arr);
51
+ });
52
+
53
+ test('schema array validator test for tuple', () => {
54
+ let tupleS: Schema[] = [
55
+ Schema.ofInteger('item1'),
56
+ Schema.ofString('item2'),
57
+ Schema.ofObject('item3'),
58
+ ];
59
+
60
+ let ast = new ArraySchemaType();
61
+ ast.setTupleSchema(tupleS);
62
+
63
+ const schema: Schema = Schema.ofArray('schema')
64
+ .setItems(ast)
65
+ .setAdditionalItems(new AdditionalType().setBooleanValue(true));
66
+
67
+ let arr = [12, 'surendhar', { a: 'val1', b: 'val2' }, 1, 2, 4];
68
+
69
+ expect(ArrayValidator.validate([], schema, repo, arr)).toStrictEqual(arr);
70
+ });
71
+
72
+ test('schema array validator test for tuple with add schema', () => {
73
+ let tupleS: Schema[] = [
74
+ Schema.ofInteger('item1'),
75
+ Schema.ofString('item2'),
76
+ Schema.ofObject('item3'),
77
+ ];
78
+
79
+ let ast = new ArraySchemaType();
80
+ ast.setTupleSchema(tupleS);
81
+
82
+ const schema: Schema = Schema.ofArray('schema')
83
+ .setItems(ast)
84
+ .setAdditionalItems(new AdditionalType().setSchemaValue(Schema.ofInteger('itemInt')));
85
+
86
+ let arr = [12, 'surendhar', { a: 'val1', b: 'val2' }, 1, 2];
87
+
88
+ expect(ArrayValidator.validate([], schema, repo, arr)).toStrictEqual(arr);
89
+ });
90
+
91
+ test('schema array validator test for tuple with add schema fail', () => {
92
+ let tupleS: Schema[] = [
93
+ Schema.ofInteger('item1'),
94
+ Schema.ofString('item2'),
95
+ Schema.ofObject('item3'),
96
+ ];
97
+
98
+ let ast = new ArraySchemaType();
99
+ ast.setTupleSchema(tupleS);
100
+
101
+ const schema: Schema = Schema.ofArray('schema')
102
+ .setItems(ast)
103
+ .setAdditionalItems(new AdditionalType().setSchemaValue(Schema.ofInteger('itemInt')));
104
+
105
+ let arr = [12, 'surendhar', { a: 'val1', b: 'val2' }, 1, 2, 4, 'surendhar'];
106
+
107
+ expect(() => ArrayValidator.validate([], schema, repo, arr)).toThrow();
108
+ });
109
+
110
+ test('schema array validator test for tuple with add schema fail', () => {
111
+ let tupleS: Schema[] = [Schema.ofInteger('item1'), Schema.ofString('item2')];
112
+
113
+ let ast = new ArraySchemaType();
114
+ ast.setTupleSchema(tupleS);
115
+
116
+ const schema: Schema = Schema.ofArray('schema')
117
+ .setItems(ast)
118
+ .setAdditionalItems(new AdditionalType().setSchemaValue(Schema.ofInteger('itemInt')));
119
+
120
+ let arr = [12, 'surendhar', { a: 'val1', b: 'val2' }, 1, 2, 4, ['ve', 23, 'ctor']];
121
+
122
+ expect(() => ArrayValidator.validate([], schema, repo, arr)).toThrow();
123
+ });
124
+
125
+ test('schema array validator test for single with additional', () => {
126
+ let ast = new ArraySchemaType();
127
+ ast.setSingleSchema(Schema.ofInteger('ast'));
128
+
129
+ const schema: Schema = Schema.ofArray('schema')
130
+ .setItems(ast)
131
+ .setAdditionalItems(new AdditionalType().setBooleanValue(true));
132
+
133
+ let arr = [12, 23, 54, 45, 'abcd', 'df'];
134
+
135
+ expect(() => ArrayValidator.validate([], schema, repo, arr)).toThrow();
136
+ });
137
+
138
+ test('schema array validator test for tuple without additional', () => {
139
+ let tupleS: Schema[] = [
140
+ Schema.ofInteger('item1'),
141
+ Schema.ofString('item2'),
142
+ Schema.ofObject('item3'),
143
+ ];
144
+
145
+ let ast = new ArraySchemaType();
146
+ ast.setTupleSchema(tupleS);
147
+
148
+ const schema: Schema = Schema.ofArray('schema').setItems(ast);
149
+
150
+ let arr = [12, 'surendhar', { a: 'val1', b: 'val2' }, 'add'];
151
+
152
+ expect(() => ArrayValidator.validate([], schema, repo, arr)).toThrow();
153
+ });
154
+
155
+ test('schema array validator tuple schema with json object', () => {
156
+ let tupleS: Schema[] = [
157
+ Schema.ofInteger('item1'),
158
+ Schema.ofString('item2'),
159
+ Schema.ofObject('item3'),
160
+ ];
161
+
162
+ let ast = new ArraySchemaType();
163
+ ast.setTupleSchema(tupleS);
164
+
165
+ const schema: Schema = Schema.ofArray('schema').setItems(ast);
166
+
167
+ let obj = [1, 'asd', { val: 'stringtype' }, 'stringOnemore'];
168
+
169
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
170
+ });
171
+
172
+ test('schema array validator tuple schema similar to json object', () => {
173
+ let tupleS: Schema[] = [
174
+ Schema.ofInteger('item1'),
175
+ Schema.ofString('item2'),
176
+ Schema.ofBoolean('item3'),
177
+ ];
178
+
179
+ let ast = new ArraySchemaType();
180
+ ast.setTupleSchema(tupleS);
181
+
182
+ let objSc = Schema.ofObject('obj');
183
+
184
+ const schema: Schema = Schema.ofArray('schema')
185
+ .setItems(ast)
186
+ .setAdditionalItems(new AdditionalType().setSchemaValue(objSc));
187
+
188
+ let obj = [1, 'asd', true, { val: 'stringtype' }, false];
189
+
190
+ expect(() => SchemaValidator.validate([], schema, repo, obj)).toThrowError();
191
+ });