@fincity/kirun-js 1.9.0 → 2.0.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 +118 -75
- package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +3 -3
- package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +2 -2
- package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +8 -8
- package/__tests__/engine/json/schema/SchemaUtil.ts +1 -1
- package/__tests__/engine/json/schema/type/TypeUtilTest.ts +1 -1
- package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +24 -19
- package/__tests__/engine/json/schema/validator/ArrayContainsValidatorTest.ts +22 -22
- package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +10 -10
- package/__tests__/engine/json/schema/validator/ArraySchemaTypeTest.ts +22 -22
- package/__tests__/engine/json/schema/validator/ArrayValidatorTest.ts +13 -13
- package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +10 -9
- package/__tests__/engine/json/schema/validator/NullValidatorTest.ts +13 -0
- package/__tests__/engine/json/schema/validator/ObjectPropertiesTest.ts +4 -4
- package/__tests__/engine/json/schema/validator/ObjectValidatorTest.ts +32 -28
- package/__tests__/engine/json/schema/validator/SchemaAnyOfValidatorTest.ts +184 -182
- package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +43 -32
- package/__tests__/engine/json/schema/validator/StringFormatSchemaValidatorTest.ts +24 -24
- package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +14 -14
- package/__tests__/engine/repository/KIRunFunctionRepositoryTest.ts +7 -7
- package/__tests__/engine/repository/RepositoryFilterTest.ts +7 -7
- package/__tests__/engine/runtime/KIRuntimeDependencyTest.ts +60 -7
- package/__tests__/engine/runtime/KIRuntimeFunctionInFunction.ts +11 -7
- package/__tests__/engine/runtime/KIRuntimeNoParamMapTest.ts +2 -2
- package/__tests__/engine/runtime/KIRuntimeNoValuesTest.ts +2 -2
- package/__tests__/engine/runtime/KIRuntimeTest.ts +8 -6
- package/__tests__/engine/runtime/KIRuntimeTestWithoutGenEvent.ts +4 -1
- package/__tests__/engine/runtime/KIRuntimeUndefinedParamTest.ts +4 -4
- package/__tests__/engine/runtime/KIRuntimeValuesEmptyTest.ts +6 -6
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +35 -0
- package/__tests__/indexTest.ts +10 -10
- 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 +17 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/HybridRepository.ts +5 -5
- package/src/engine/Repository.ts +2 -2
- package/src/engine/function/AbstractFunction.ts +35 -31
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +8 -6
- package/src/engine/function/system/math/MathFunctionRepository.ts +7 -5
- package/src/engine/function/system/object/ObjectFunctionRepository.ts +7 -5
- package/src/engine/function/system/string/StringFunctionRepository.ts +8 -6
- package/src/engine/json/schema/SchemaUtil.ts +33 -30
- package/src/engine/json/schema/validator/ArrayValidator.ts +25 -20
- package/src/engine/json/schema/validator/NullValidator.ts +6 -7
- package/src/engine/json/schema/validator/ObjectValidator.ts +32 -14
- package/src/engine/json/schema/validator/SchemaValidator.ts +15 -11
- package/src/engine/json/schema/validator/TypeValidator.ts +5 -5
- package/src/engine/model/Statement.ts +13 -3
- package/src/engine/repository/KIRunFunctionRepository.ts +3 -2
- package/src/engine/repository/KIRunSchemaRepository.ts +7 -5
- package/src/engine/runtime/KIRuntime.ts +25 -20
- package/src/engine/util/duplicate.ts +1 -1
|
@@ -13,10 +13,10 @@ export class SchemaUtil {
|
|
|
13
13
|
|
|
14
14
|
private static readonly CYCLIC_REFERENCE_LIMIT_COUNTER: number = 20;
|
|
15
15
|
|
|
16
|
-
public static getDefaultValue(
|
|
16
|
+
public static async getDefaultValue(
|
|
17
17
|
s: Schema | undefined,
|
|
18
18
|
sRepository: Repository<Schema> | undefined,
|
|
19
|
-
): any {
|
|
19
|
+
): Promise<any> {
|
|
20
20
|
if (!s) return undefined;
|
|
21
21
|
|
|
22
22
|
if (s.getConstant()) return s.getConstant();
|
|
@@ -24,45 +24,46 @@ export class SchemaUtil {
|
|
|
24
24
|
if (!isNullValue(s.getDefaultValue())) return s.getDefaultValue();
|
|
25
25
|
|
|
26
26
|
return SchemaUtil.getDefaultValue(
|
|
27
|
-
SchemaUtil.getSchemaFromRef(s, sRepository, s.getRef()),
|
|
27
|
+
await SchemaUtil.getSchemaFromRef(s, sRepository, s.getRef()),
|
|
28
28
|
sRepository,
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
public static hasDefaultValueOrNullSchemaType(
|
|
32
|
+
public static async hasDefaultValueOrNullSchemaType(
|
|
33
33
|
s: Schema | undefined,
|
|
34
34
|
sRepository: Repository<Schema> | undefined,
|
|
35
|
-
): boolean {
|
|
36
|
-
if (!s) return false;
|
|
37
|
-
if (s.getConstant()) return true;
|
|
35
|
+
): Promise<boolean> {
|
|
36
|
+
if (!s) return Promise.resolve(false);
|
|
37
|
+
if (s.getConstant()) return Promise.resolve(true);
|
|
38
38
|
|
|
39
|
-
if (!isNullValue(s.getDefaultValue())) return true;
|
|
39
|
+
if (!isNullValue(s.getDefaultValue())) return Promise.resolve(true);
|
|
40
40
|
|
|
41
41
|
if (isNullValue(s.getRef())) {
|
|
42
|
-
if (s.getType()?.getAllowedSchemaTypes().has(SchemaType.NULL))
|
|
43
|
-
|
|
42
|
+
if (s.getType()?.getAllowedSchemaTypes().has(SchemaType.NULL))
|
|
43
|
+
return Promise.resolve(true);
|
|
44
|
+
return Promise.resolve(false);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
return this.hasDefaultValueOrNullSchemaType(
|
|
47
|
-
SchemaUtil.getSchemaFromRef(s, sRepository, s.getRef()),
|
|
48
|
+
await SchemaUtil.getSchemaFromRef(s, sRepository, s.getRef()),
|
|
48
49
|
sRepository,
|
|
49
50
|
);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
public static getSchemaFromRef(
|
|
53
|
+
public static async getSchemaFromRef(
|
|
53
54
|
schema: Schema,
|
|
54
55
|
sRepository: Repository<Schema> | undefined,
|
|
55
56
|
ref: string | undefined,
|
|
56
57
|
iteration: number = 0,
|
|
57
|
-
): Schema | undefined {
|
|
58
|
+
): Promise<Schema | undefined> {
|
|
58
59
|
iteration++;
|
|
59
60
|
if (iteration == SchemaUtil.CYCLIC_REFERENCE_LIMIT_COUNTER)
|
|
60
61
|
throw new SchemaValidationException(ref ?? '', 'Schema has a cyclic reference');
|
|
61
62
|
|
|
62
|
-
if (!schema || !ref || StringUtil.isNullOrBlank(ref)) return undefined;
|
|
63
|
+
if (!schema || !ref || StringUtil.isNullOrBlank(ref)) return Promise.resolve(undefined);
|
|
63
64
|
|
|
64
65
|
if (!ref.startsWith('#')) {
|
|
65
|
-
var tuple = SchemaUtil.resolveExternalSchema(schema, sRepository, ref);
|
|
66
|
+
var tuple = await SchemaUtil.resolveExternalSchema(schema, sRepository, ref);
|
|
66
67
|
if (tuple) {
|
|
67
68
|
schema = tuple.getT1();
|
|
68
69
|
ref = tuple.getT2();
|
|
@@ -72,19 +73,21 @@ export class SchemaUtil {
|
|
|
72
73
|
let parts: string[] = ref.split('/');
|
|
73
74
|
let i: number = 1;
|
|
74
75
|
|
|
75
|
-
if (i === parts.length) return schema;
|
|
76
|
+
if (i === parts.length) return Promise.resolve(schema);
|
|
76
77
|
|
|
77
|
-
return
|
|
78
|
+
return Promise.resolve(
|
|
79
|
+
SchemaUtil.resolveInternalSchema(schema, sRepository, ref, iteration, parts, i),
|
|
80
|
+
);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
private static resolveInternalSchema(
|
|
83
|
+
private static async resolveInternalSchema(
|
|
81
84
|
inSchema: Schema,
|
|
82
85
|
sRepository: Repository<Schema> | undefined,
|
|
83
86
|
ref: string,
|
|
84
87
|
iteration: number,
|
|
85
88
|
parts: string[],
|
|
86
89
|
i: number,
|
|
87
|
-
): Schema | undefined {
|
|
90
|
+
): Promise<Schema | undefined> {
|
|
88
91
|
let schema: Schema | undefined = inSchema;
|
|
89
92
|
if (i === parts.length) return undefined;
|
|
90
93
|
while (i < parts.length) {
|
|
@@ -120,7 +123,7 @@ export class SchemaUtil {
|
|
|
120
123
|
);
|
|
121
124
|
|
|
122
125
|
if (!StringUtil.isNullOrBlank(schema.getRef())) {
|
|
123
|
-
schema = SchemaUtil.getSchemaFromRef(
|
|
126
|
+
schema = await SchemaUtil.getSchemaFromRef(
|
|
124
127
|
schema,
|
|
125
128
|
sRepository,
|
|
126
129
|
schema.getRef(),
|
|
@@ -133,25 +136,25 @@ export class SchemaUtil {
|
|
|
133
136
|
);
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
|
-
return schema;
|
|
139
|
+
return Promise.resolve(schema);
|
|
137
140
|
}
|
|
138
141
|
|
|
139
|
-
private static resolveExternalSchema(
|
|
142
|
+
private static async resolveExternalSchema(
|
|
140
143
|
inSchem: Schema,
|
|
141
144
|
sRepository: Repository<Schema> | undefined,
|
|
142
145
|
ref: string,
|
|
143
|
-
): Tuple2<Schema, string> | undefined {
|
|
144
|
-
if (!sRepository) return undefined;
|
|
146
|
+
): Promise<Tuple2<Schema, string> | undefined> {
|
|
147
|
+
if (!sRepository) return Promise.resolve(undefined);
|
|
145
148
|
|
|
146
149
|
let nms = StringUtil.splitAtFirstOccurance(ref ?? '', '/');
|
|
147
|
-
if (!nms[0]) return undefined;
|
|
150
|
+
if (!nms[0]) return Promise.resolve(undefined);
|
|
148
151
|
|
|
149
152
|
let nmspnm = StringUtil.splitAtFirstOccurance(nms[0], '.');
|
|
150
|
-
if (!nmspnm[0] || !nmspnm[1]) return undefined;
|
|
153
|
+
if (!nmspnm[0] || !nmspnm[1]) return Promise.resolve(undefined);
|
|
151
154
|
|
|
152
|
-
let schema = sRepository.find(nmspnm[0], nmspnm[1]);
|
|
153
|
-
if (!schema) return undefined;
|
|
154
|
-
if (!nms[1] || nms[1] === '') return new Tuple2(schema, ref);
|
|
155
|
+
let schema = await sRepository.find(nmspnm[0], nmspnm[1]);
|
|
156
|
+
if (!schema) return Promise.resolve(undefined);
|
|
157
|
+
if (!nms[1] || nms[1] === '') return Promise.resolve(new Tuple2(schema, ref));
|
|
155
158
|
|
|
156
159
|
ref = '#/' + nms[1];
|
|
157
160
|
|
|
@@ -161,7 +164,7 @@ export class SchemaUtil {
|
|
|
161
164
|
SchemaUtil.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH,
|
|
162
165
|
);
|
|
163
166
|
|
|
164
|
-
return new Tuple2(schema, ref);
|
|
167
|
+
return Promise.resolve(new Tuple2(schema, ref));
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
private constructor() {}
|
|
@@ -6,12 +6,12 @@ import { SchemaValidationException } from './exception/SchemaValidationException
|
|
|
6
6
|
import { SchemaValidator } from './SchemaValidator';
|
|
7
7
|
|
|
8
8
|
export class ArrayValidator {
|
|
9
|
-
public static validate(
|
|
9
|
+
public static async validate(
|
|
10
10
|
parents: Schema[],
|
|
11
11
|
schema: Schema,
|
|
12
12
|
repository: Repository<Schema> | undefined,
|
|
13
13
|
element: any,
|
|
14
|
-
): any {
|
|
14
|
+
): Promise<any> {
|
|
15
15
|
if (isNullValue(element))
|
|
16
16
|
throw new SchemaValidationException(
|
|
17
17
|
SchemaValidator.path(parents),
|
|
@@ -28,16 +28,16 @@ export class ArrayValidator {
|
|
|
28
28
|
|
|
29
29
|
ArrayValidator.checkMinMaxItems(parents, schema, array);
|
|
30
30
|
|
|
31
|
-
ArrayValidator.checkItems(parents, schema, repository, array);
|
|
31
|
+
await ArrayValidator.checkItems(parents, schema, repository, array);
|
|
32
32
|
|
|
33
33
|
ArrayValidator.checkUniqueItems(parents, schema, array);
|
|
34
34
|
|
|
35
|
-
ArrayValidator.checkContains(schema, parents, repository, array);
|
|
35
|
+
await ArrayValidator.checkContains(schema, parents, repository, array);
|
|
36
36
|
|
|
37
37
|
return element;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
private static checkContains(
|
|
40
|
+
private static async checkContains(
|
|
41
41
|
schema: Schema,
|
|
42
42
|
parents: Schema[],
|
|
43
43
|
repository: Repository<Schema> | undefined,
|
|
@@ -45,7 +45,7 @@ export class ArrayValidator {
|
|
|
45
45
|
) {
|
|
46
46
|
if (isNullValue(schema.getContains())) return;
|
|
47
47
|
|
|
48
|
-
let count = ArrayValidator.countContains(
|
|
48
|
+
let count = await ArrayValidator.countContains(
|
|
49
49
|
parents,
|
|
50
50
|
schema,
|
|
51
51
|
repository,
|
|
@@ -79,19 +79,24 @@ export class ArrayValidator {
|
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
public static countContains(
|
|
82
|
+
public static async countContains(
|
|
83
83
|
parents: Schema[],
|
|
84
84
|
schema: Schema,
|
|
85
85
|
repository: Repository<Schema> | undefined,
|
|
86
86
|
array: any[],
|
|
87
87
|
stopOnFirst?: boolean,
|
|
88
|
-
): number {
|
|
88
|
+
): Promise<number> {
|
|
89
89
|
let count = 0;
|
|
90
90
|
for (let i = 0; i < array.length; i++) {
|
|
91
91
|
let newParents: Schema[] = !parents ? [] : [...parents];
|
|
92
92
|
|
|
93
93
|
try {
|
|
94
|
-
SchemaValidator.validate(
|
|
94
|
+
await SchemaValidator.validate(
|
|
95
|
+
newParents,
|
|
96
|
+
schema.getContains(),
|
|
97
|
+
repository,
|
|
98
|
+
array[i],
|
|
99
|
+
);
|
|
95
100
|
count++;
|
|
96
101
|
if (stopOnFirst) break;
|
|
97
102
|
} catch (err) {}
|
|
@@ -127,7 +132,7 @@ export class ArrayValidator {
|
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
|
|
130
|
-
public static checkItems(
|
|
135
|
+
public static async checkItems(
|
|
131
136
|
parents: Schema[],
|
|
132
137
|
schema: Schema,
|
|
133
138
|
repository: Repository<Schema> | undefined,
|
|
@@ -140,7 +145,7 @@ export class ArrayValidator {
|
|
|
140
145
|
if (type.getSingleSchema()) {
|
|
141
146
|
for (let i = 0; i < array.length; i++) {
|
|
142
147
|
let newParents: Schema[] = !parents ? [] : [...parents];
|
|
143
|
-
let element: any = SchemaValidator.validate(
|
|
148
|
+
let element: any = await SchemaValidator.validate(
|
|
144
149
|
newParents,
|
|
145
150
|
type.getSingleSchema(),
|
|
146
151
|
repository,
|
|
@@ -164,13 +169,13 @@ export class ArrayValidator {
|
|
|
164
169
|
);
|
|
165
170
|
}
|
|
166
171
|
|
|
167
|
-
this.checkItemsInTupleSchema(parents, repository, array, type);
|
|
172
|
+
await this.checkItemsInTupleSchema(parents, repository, array, type);
|
|
168
173
|
|
|
169
|
-
this.checkAdditionalItems(parents, schema, repository, array, type);
|
|
174
|
+
await this.checkAdditionalItems(parents, schema, repository, array, type);
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
|
|
173
|
-
private static checkItemsInTupleSchema(
|
|
178
|
+
private static async checkItemsInTupleSchema(
|
|
174
179
|
parents: Schema[],
|
|
175
180
|
repository: Repository<Schema> | undefined,
|
|
176
181
|
array: any[],
|
|
@@ -178,7 +183,7 @@ export class ArrayValidator {
|
|
|
178
183
|
) {
|
|
179
184
|
for (let i = 0; i < type.getTupleSchema()?.length!; i++) {
|
|
180
185
|
let newParents: Schema[] = !parents ? [] : [...parents];
|
|
181
|
-
let element: any = SchemaValidator.validate(
|
|
186
|
+
let element: any = await SchemaValidator.validate(
|
|
182
187
|
newParents,
|
|
183
188
|
type.getTupleSchema()![i],
|
|
184
189
|
repository,
|
|
@@ -188,7 +193,7 @@ export class ArrayValidator {
|
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
|
|
191
|
-
private static checkAdditionalItems(
|
|
196
|
+
private static async checkAdditionalItems(
|
|
192
197
|
parents: Schema[],
|
|
193
198
|
schema: Schema,
|
|
194
199
|
repository: Repository<Schema> | undefined,
|
|
@@ -209,7 +214,7 @@ export class ArrayValidator {
|
|
|
209
214
|
'No Additional Items are defined',
|
|
210
215
|
);
|
|
211
216
|
|
|
212
|
-
this.checkEachItemInAdditionalItems(
|
|
217
|
+
await this.checkEachItemInAdditionalItems(
|
|
213
218
|
parents,
|
|
214
219
|
schema,
|
|
215
220
|
repository,
|
|
@@ -219,7 +224,7 @@ export class ArrayValidator {
|
|
|
219
224
|
);
|
|
220
225
|
} else if (additionalSchemaType?.getSchemaValue()) {
|
|
221
226
|
let schemaType = additionalSchemaType.getSchemaValue();
|
|
222
|
-
this.checkEachItemInAdditionalItems(
|
|
227
|
+
await this.checkEachItemInAdditionalItems(
|
|
223
228
|
parents,
|
|
224
229
|
schema,
|
|
225
230
|
repository,
|
|
@@ -231,7 +236,7 @@ export class ArrayValidator {
|
|
|
231
236
|
}
|
|
232
237
|
}
|
|
233
238
|
|
|
234
|
-
private static checkEachItemInAdditionalItems(
|
|
239
|
+
private static async checkEachItemInAdditionalItems(
|
|
235
240
|
parents: Schema[],
|
|
236
241
|
schema: Schema,
|
|
237
242
|
repository: Repository<Schema> | undefined,
|
|
@@ -241,7 +246,7 @@ export class ArrayValidator {
|
|
|
241
246
|
) {
|
|
242
247
|
for (let i = type.getTupleSchema()?.length!; i < array.length; i++) {
|
|
243
248
|
let newParents: Schema[] = !parents ? [] : [...parents];
|
|
244
|
-
let element: any = SchemaValidator.validate(
|
|
249
|
+
let element: any = await SchemaValidator.validate(
|
|
245
250
|
newParents,
|
|
246
251
|
schemaType!,
|
|
247
252
|
repository,
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { isNullValue } from '../../../util/NullCheck';
|
|
1
2
|
import { Schema } from '../Schema';
|
|
2
3
|
import { SchemaValidationException } from './exception/SchemaValidationException';
|
|
3
4
|
import { SchemaValidator } from './SchemaValidator';
|
|
4
5
|
|
|
5
6
|
export class NullValidator {
|
|
6
7
|
public static validate(parents: Schema[], schema: Schema, element: any): any {
|
|
7
|
-
if (element)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return element;
|
|
8
|
+
if (isNullValue(element)) return element;
|
|
9
|
+
throw new SchemaValidationException(
|
|
10
|
+
SchemaValidator.path(parents),
|
|
11
|
+
'Expected a null but found ' + element,
|
|
12
|
+
);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
private constructor() {}
|
|
@@ -6,7 +6,7 @@ import { SchemaValidationException } from './exception/SchemaValidationException
|
|
|
6
6
|
import { SchemaValidator } from './SchemaValidator';
|
|
7
7
|
|
|
8
8
|
export class ObjectValidator {
|
|
9
|
-
public static validate(
|
|
9
|
+
public static async validate(
|
|
10
10
|
parents: Schema[],
|
|
11
11
|
schema: Schema,
|
|
12
12
|
repository: Repository<Schema> | undefined,
|
|
@@ -30,7 +30,7 @@ export class ObjectValidator {
|
|
|
30
30
|
ObjectValidator.checkMinMaxProperties(parents, schema, keys);
|
|
31
31
|
|
|
32
32
|
if (schema.getPropertyNames()) {
|
|
33
|
-
ObjectValidator.checkPropertyNameSchema(parents, schema, repository, keys);
|
|
33
|
+
await ObjectValidator.checkPropertyNameSchema(parents, schema, repository, keys);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (schema.getRequired()) {
|
|
@@ -38,19 +38,31 @@ export class ObjectValidator {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (schema.getProperties()) {
|
|
41
|
-
ObjectValidator.checkProperties(parents, schema, repository, jsonObject, keys);
|
|
41
|
+
await ObjectValidator.checkProperties(parents, schema, repository, jsonObject, keys);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (schema.getPatternProperties()) {
|
|
45
|
-
ObjectValidator.checkPatternProperties(
|
|
45
|
+
await ObjectValidator.checkPatternProperties(
|
|
46
|
+
parents,
|
|
47
|
+
schema,
|
|
48
|
+
repository,
|
|
49
|
+
jsonObject,
|
|
50
|
+
keys,
|
|
51
|
+
);
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
if (schema.getAdditionalProperties()) {
|
|
49
|
-
ObjectValidator.checkAddtionalProperties(
|
|
55
|
+
await ObjectValidator.checkAddtionalProperties(
|
|
56
|
+
parents,
|
|
57
|
+
schema,
|
|
58
|
+
repository,
|
|
59
|
+
jsonObject,
|
|
60
|
+
keys,
|
|
61
|
+
);
|
|
50
62
|
}
|
|
51
63
|
}
|
|
52
64
|
|
|
53
|
-
private static checkPropertyNameSchema(
|
|
65
|
+
private static async checkPropertyNameSchema(
|
|
54
66
|
parents: Schema[],
|
|
55
67
|
schema: Schema,
|
|
56
68
|
repository: Repository<Schema> | undefined,
|
|
@@ -58,7 +70,7 @@ export class ObjectValidator {
|
|
|
58
70
|
) {
|
|
59
71
|
for (let key of Array.from(keys.values())) {
|
|
60
72
|
try {
|
|
61
|
-
SchemaValidator.validate(
|
|
73
|
+
await SchemaValidator.validate(
|
|
62
74
|
parents,
|
|
63
75
|
schema.getPropertyNames() as Schema,
|
|
64
76
|
repository,
|
|
@@ -84,7 +96,7 @@ export class ObjectValidator {
|
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
private static checkAddtionalProperties(
|
|
99
|
+
private static async checkAddtionalProperties(
|
|
88
100
|
parents: Schema[],
|
|
89
101
|
schema: Schema,
|
|
90
102
|
repository: Repository<Schema> | undefined,
|
|
@@ -96,7 +108,7 @@ export class ObjectValidator {
|
|
|
96
108
|
for (let key of Array.from(keys.values())) {
|
|
97
109
|
let newParents: Schema[] = !parents ? [] : [...parents];
|
|
98
110
|
|
|
99
|
-
let element: any = SchemaValidator.validate(
|
|
111
|
+
let element: any = await SchemaValidator.validate(
|
|
100
112
|
newParents,
|
|
101
113
|
apt.getSchemaValue(),
|
|
102
114
|
repository,
|
|
@@ -114,7 +126,7 @@ export class ObjectValidator {
|
|
|
114
126
|
}
|
|
115
127
|
}
|
|
116
128
|
|
|
117
|
-
private static checkPatternProperties(
|
|
129
|
+
private static async checkPatternProperties(
|
|
118
130
|
parents: Schema[],
|
|
119
131
|
schema: Schema,
|
|
120
132
|
repository: Repository<Schema> | undefined,
|
|
@@ -132,7 +144,7 @@ export class ObjectValidator {
|
|
|
132
144
|
|
|
133
145
|
for (const e of Array.from(compiledPatterns.entries())) {
|
|
134
146
|
if (e[1].test(key)) {
|
|
135
|
-
const element: any = SchemaValidator.validate(
|
|
147
|
+
const element: any = await SchemaValidator.validate(
|
|
136
148
|
newParents,
|
|
137
149
|
schema.getPatternProperties()!.get(e[0]),
|
|
138
150
|
repository,
|
|
@@ -146,7 +158,7 @@ export class ObjectValidator {
|
|
|
146
158
|
}
|
|
147
159
|
}
|
|
148
160
|
|
|
149
|
-
private static checkProperties(
|
|
161
|
+
private static async checkProperties(
|
|
150
162
|
parents: Schema[],
|
|
151
163
|
schema: Schema,
|
|
152
164
|
repository: Repository<Schema> | undefined,
|
|
@@ -157,12 +169,18 @@ export class ObjectValidator {
|
|
|
157
169
|
let value: any = jsonObject[each[0]];
|
|
158
170
|
|
|
159
171
|
if (!jsonObject.hasOwnProperty(each[0]) && isNullValue(value)) {
|
|
160
|
-
const defValue = SchemaUtil.getDefaultValue(each[1], repository);
|
|
172
|
+
const defValue = await SchemaUtil.getDefaultValue(each[1], repository);
|
|
161
173
|
if (isNullValue(defValue)) continue;
|
|
162
174
|
}
|
|
163
175
|
|
|
164
176
|
let newParents: Schema[] = !parents ? [] : [...parents];
|
|
165
|
-
let element: any = SchemaValidator.validate(
|
|
177
|
+
let element: any = await SchemaValidator.validate(
|
|
178
|
+
newParents,
|
|
179
|
+
each[1],
|
|
180
|
+
repository,
|
|
181
|
+
value,
|
|
182
|
+
);
|
|
183
|
+
|
|
166
184
|
jsonObject[each[0]] = element;
|
|
167
185
|
keys.delete(each[0]);
|
|
168
186
|
}
|
|
@@ -4,7 +4,6 @@ import { isNullValue } from '../../../util/NullCheck';
|
|
|
4
4
|
import { StringUtil } from '../../../util/string/StringUtil';
|
|
5
5
|
import { Schema } from '../Schema';
|
|
6
6
|
import { SchemaUtil } from '../SchemaUtil';
|
|
7
|
-
import { SchemaType } from '../type/SchemaType';
|
|
8
7
|
import { AnyOfAllOfOneOfValidator } from './AnyOfAllOfOneOfValidator';
|
|
9
8
|
import { SchemaValidationException } from './exception/SchemaValidationException';
|
|
10
9
|
import { TypeValidator } from './TypeValidator';
|
|
@@ -19,12 +18,12 @@ export class SchemaValidator {
|
|
|
19
18
|
.reduce((a, c, i) => a + (i === 0 ? '' : '.') + c, '');
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
public static validate(
|
|
21
|
+
public static async validate(
|
|
23
22
|
parents: Schema[] | undefined,
|
|
24
23
|
schema: Schema | undefined,
|
|
25
24
|
repository: Repository<Schema> | undefined,
|
|
26
25
|
element: any,
|
|
27
|
-
): any {
|
|
26
|
+
): Promise<any> {
|
|
28
27
|
if (!schema) {
|
|
29
28
|
throw new SchemaValidationException(
|
|
30
29
|
SchemaValidator.path(parents),
|
|
@@ -58,13 +57,13 @@ export class SchemaValidator {
|
|
|
58
57
|
);
|
|
59
58
|
|
|
60
59
|
if (schema.getType()) {
|
|
61
|
-
SchemaValidator.typeValidation(parents, schema, repository, element);
|
|
60
|
+
await SchemaValidator.typeValidation(parents, schema, repository, element);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
if (!StringUtil.isNullOrBlank(schema.getRef())) {
|
|
65
|
-
return SchemaValidator.validate(
|
|
64
|
+
return await SchemaValidator.validate(
|
|
66
65
|
parents,
|
|
67
|
-
SchemaUtil.getSchemaFromRef(parents[0], repository, schema.getRef()),
|
|
66
|
+
await SchemaUtil.getSchemaFromRef(parents[0], repository, schema.getRef()),
|
|
68
67
|
repository,
|
|
69
68
|
element,
|
|
70
69
|
);
|
|
@@ -77,7 +76,12 @@ export class SchemaValidator {
|
|
|
77
76
|
if (schema.getNot()) {
|
|
78
77
|
let flag: boolean = false;
|
|
79
78
|
try {
|
|
80
|
-
SchemaValidator.validate(
|
|
79
|
+
let x = await SchemaValidator.validate(
|
|
80
|
+
parents,
|
|
81
|
+
schema.getNot(),
|
|
82
|
+
repository,
|
|
83
|
+
element,
|
|
84
|
+
);
|
|
81
85
|
flag = true;
|
|
82
86
|
} catch (err) {
|
|
83
87
|
flag = false;
|
|
@@ -120,7 +124,7 @@ export class SchemaValidator {
|
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
|
|
123
|
-
public static typeValidation(
|
|
127
|
+
public static async typeValidation(
|
|
124
128
|
parents: Schema[],
|
|
125
129
|
schema: Schema,
|
|
126
130
|
repository: Repository<Schema> | undefined,
|
|
@@ -128,10 +132,10 @@ export class SchemaValidator {
|
|
|
128
132
|
) {
|
|
129
133
|
let valid: boolean = false;
|
|
130
134
|
let list: SchemaValidationException[] = [];
|
|
131
|
-
|
|
132
|
-
for (
|
|
135
|
+
let type;
|
|
136
|
+
for (type of Array.from(schema.getType()?.getAllowedSchemaTypes()?.values() ?? [])) {
|
|
133
137
|
try {
|
|
134
|
-
TypeValidator.validate(parents, type, schema, repository, element);
|
|
138
|
+
await TypeValidator.validate(parents, type, schema, repository, element);
|
|
135
139
|
valid = true;
|
|
136
140
|
break;
|
|
137
141
|
} catch (err: any) {
|
|
@@ -11,13 +11,13 @@ import { SchemaValidator } from './SchemaValidator';
|
|
|
11
11
|
import { StringValidator } from './StringValidator';
|
|
12
12
|
|
|
13
13
|
export class TypeValidator {
|
|
14
|
-
public static validate(
|
|
14
|
+
public static async validate(
|
|
15
15
|
parents: Schema[],
|
|
16
16
|
type: SchemaType,
|
|
17
17
|
schema: Schema,
|
|
18
|
-
repository: Repository<Schema> |undefined,
|
|
18
|
+
repository: Repository<Schema> | undefined,
|
|
19
19
|
element: any,
|
|
20
|
-
): any {
|
|
20
|
+
): Promise<any> {
|
|
21
21
|
if (type == SchemaType.STRING) {
|
|
22
22
|
StringValidator.validate(parents, schema, element);
|
|
23
23
|
} else if (
|
|
@@ -30,9 +30,9 @@ export class TypeValidator {
|
|
|
30
30
|
} else if (type == SchemaType.BOOLEAN) {
|
|
31
31
|
BooleanValidator.validate(parents, schema, element);
|
|
32
32
|
} else if (type == SchemaType.OBJECT) {
|
|
33
|
-
ObjectValidator.validate(parents, schema, repository, element);
|
|
33
|
+
await ObjectValidator.validate(parents, schema, repository, element);
|
|
34
34
|
} else if (type == SchemaType.ARRAY) {
|
|
35
|
-
ArrayValidator.validate(parents, schema, repository, element);
|
|
35
|
+
await ArrayValidator.validate(parents, schema, repository, element);
|
|
36
36
|
} else if (type == SchemaType.NULL) {
|
|
37
37
|
NullValidator.validate(parents, schema, element);
|
|
38
38
|
} else {
|
|
@@ -21,9 +21,19 @@ export class Statement extends AbstractStatement {
|
|
|
21
21
|
['name', Schema.ofString('name')],
|
|
22
22
|
[
|
|
23
23
|
'dependentStatements',
|
|
24
|
-
Schema.ofObject('dependentstatement')
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Schema.ofObject('dependentstatement')
|
|
25
|
+
.setAdditionalProperties(
|
|
26
|
+
new AdditionalType().setSchemaValue(Schema.ofBoolean('exists')),
|
|
27
|
+
)
|
|
28
|
+
.setDefaultValue({}),
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
'executeIftrue',
|
|
32
|
+
Schema.ofObject('executeIftrue')
|
|
33
|
+
.setAdditionalProperties(
|
|
34
|
+
new AdditionalType().setSchemaValue(Schema.ofBoolean('exists')),
|
|
35
|
+
)
|
|
36
|
+
.setDefaultValue({}),
|
|
27
37
|
],
|
|
28
38
|
[
|
|
29
39
|
'parameterMap',
|
|
@@ -45,10 +45,11 @@ export class KIRunFunctionRepository extends HybridRepository<Function> {
|
|
|
45
45
|
public constructor() {
|
|
46
46
|
super(
|
|
47
47
|
{
|
|
48
|
-
find(namespace: string, name: string): Function | undefined {
|
|
48
|
+
async find(namespace: string, name: string): Promise<Function | undefined> {
|
|
49
49
|
return map.get(namespace)?.get(name);
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
async filter(name: string): Promise<string[]> {
|
|
52
53
|
return Array.from(filterableNames).filter(
|
|
53
54
|
(e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1,
|
|
54
55
|
);
|
|
@@ -20,13 +20,15 @@ const map: Map<string, Schema> = new Map([
|
|
|
20
20
|
const filterableNames = Array.from(map.values()).map((e) => e.getFullName());
|
|
21
21
|
|
|
22
22
|
export class KIRunSchemaRepository implements Repository<Schema> {
|
|
23
|
-
public find(namespace: string, name: string): Schema | undefined {
|
|
24
|
-
if (Namespaces.SYSTEM != namespace) return undefined;
|
|
23
|
+
public async find(namespace: string, name: string): Promise<Schema | undefined> {
|
|
24
|
+
if (Namespaces.SYSTEM != namespace) return Promise.resolve(undefined);
|
|
25
25
|
|
|
26
|
-
return map.get(name);
|
|
26
|
+
return Promise.resolve(map.get(name));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
public filter(name: string): string[] {
|
|
30
|
-
return
|
|
29
|
+
public async filter(name: string): Promise<string[]> {
|
|
30
|
+
return Promise.resolve(
|
|
31
|
+
filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
|
|
32
|
+
);
|
|
31
33
|
}
|
|
32
34
|
}
|