@fincity/kirun-js 1.3.1 → 1.4.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/json/schema/validator/SchemaValidatorTest.ts +51 -1
- package/__tests__/engine/runtime/KIRuntimeWithDefinitionTest.ts +76 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluatorTernaryOperatorTest.ts +42 -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 +35 -20
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/engine/function/AbstractFunction.ts +72 -38
- package/src/engine/function/system/GenerateEvent.ts +1 -2
- package/src/engine/function/system/string/Reverse.ts +1 -1
- package/src/engine/json/schema/Schema.ts +119 -2
- package/src/engine/json/schema/SchemaUtil.ts +1 -1
- package/src/engine/json/schema/array/ArraySchemaType.ts +6 -0
- package/src/engine/json/schema/type/MultipleType.ts +5 -2
- package/src/engine/json/schema/type/SingleType.ts +4 -2
- package/src/engine/json/schema/validator/ObjectValidator.ts +2 -3
- package/src/engine/model/AbstractStatement.ts +10 -0
- package/src/engine/model/Event.ts +12 -5
- package/src/engine/model/FunctionDefinition.ts +1 -2
- package/src/engine/model/FunctionSignature.ts +14 -4
- package/src/engine/model/Parameter.ts +13 -3
- package/src/engine/model/ParameterReference.ts +12 -3
- package/src/engine/model/Position.ts +1 -1
- package/src/engine/model/Statement.ts +33 -7
- package/src/engine/model/StatementGroup.ts +22 -2
- package/src/engine/runtime/KIRuntime.ts +3 -2
- package/src/engine/runtime/expression/Expression.ts +120 -0
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +26 -0
- package/src/engine/runtime/expression/Operation.ts +10 -0
- package/src/engine/runtime/expression/operators/ternary/ConditionalTernaryOperator.ts +7 -0
- package/src/engine/runtime/expression/operators/ternary/TernaryOperator.ts +15 -0
- package/src/engine/runtime/expression/operators/ternary/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/engine/json/schema/object/AdditionalPropertiesType.ts +0 -32
|
@@ -40,6 +40,8 @@ import { UnaryOperator } from './operators/unary/UnaryOperator';
|
|
|
40
40
|
import { LiteralTokenValueExtractor } from './tokenextractor/LiteralTokenValueExtractor';
|
|
41
41
|
import { TokenValueExtractor } from './tokenextractor/TokenValueExtractor';
|
|
42
42
|
import { Tuple2 } from '../../util/Tuples';
|
|
43
|
+
import { ConditionalTernaryOperator } from './operators/ternary';
|
|
44
|
+
import { TernaryOperator } from './operators/ternary/TernaryOperator';
|
|
43
45
|
|
|
44
46
|
export class ExpressionEvaluator {
|
|
45
47
|
private static readonly UNARY_OPERATORS_MAP: Map<Operation, UnaryOperator> = new Map([
|
|
@@ -49,6 +51,10 @@ export class ExpressionEvaluator {
|
|
|
49
51
|
[Operation.UNARY_PLUS, new ArithmeticUnaryPlusOperator()],
|
|
50
52
|
]);
|
|
51
53
|
|
|
54
|
+
private static readonly TERNARY_OPERATORS_MAP: Map<Operation, TernaryOperator> = new Map([
|
|
55
|
+
[Operation.CONDITIONAL_TERNARY_OPERATOR, new ConditionalTernaryOperator()],
|
|
56
|
+
]);
|
|
57
|
+
|
|
52
58
|
private static readonly BINARY_OPERATORS_MAP: Map<Operation, BinaryOperator> = new Map([
|
|
53
59
|
[Operation.ADDITION, new ArithmeticAdditionOperator()],
|
|
54
60
|
[Operation.DIVISION, new ArithmeticDivisionOperator()],
|
|
@@ -195,6 +201,13 @@ export class ExpressionEvaluator {
|
|
|
195
201
|
operator == Operation.ARRAY_OPERATOR
|
|
196
202
|
) {
|
|
197
203
|
this.processObjectOrArrayOperator(valuesMap, ops, tokens, operator, token);
|
|
204
|
+
} else if (operator == Operation.CONDITIONAL_TERNARY_OPERATOR) {
|
|
205
|
+
const token2: ExpressionToken = tokens.pop();
|
|
206
|
+
const token3: ExpressionToken = tokens.pop();
|
|
207
|
+
var v1 = this.getValueFromToken(valuesMap, token3);
|
|
208
|
+
var v2 = this.getValueFromToken(valuesMap, token2);
|
|
209
|
+
var v3 = this.getValueFromToken(valuesMap, token);
|
|
210
|
+
tokens.push(this.applyTernaryOperation(operator, v1, v2, v3));
|
|
198
211
|
} else {
|
|
199
212
|
const token2: ExpressionToken = tokens.pop();
|
|
200
213
|
var v1 = this.getValueFromToken(valuesMap, token2);
|
|
@@ -295,6 +308,19 @@ export class ExpressionEvaluator {
|
|
|
295
308
|
}
|
|
296
309
|
}
|
|
297
310
|
|
|
311
|
+
private applyTernaryOperation(operator: Operation, v1: any, v2: any, v3: any): ExpressionToken {
|
|
312
|
+
let op: TernaryOperator | undefined =
|
|
313
|
+
ExpressionEvaluator.TERNARY_OPERATORS_MAP.get(operator);
|
|
314
|
+
|
|
315
|
+
if (!op)
|
|
316
|
+
throw new ExpressionEvaluationException(
|
|
317
|
+
this.expression,
|
|
318
|
+
StringFormatter.format('No operator found to evaluate $', this.getExpression()),
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
return new ExpressionTokenValue(operator.toString(), op.apply(v1, v2, v3));
|
|
322
|
+
}
|
|
323
|
+
|
|
298
324
|
private applyBinaryOperation(operator: Operation, v1: any, v2: any): ExpressionToken {
|
|
299
325
|
let typv1: string = typeof v1;
|
|
300
326
|
let typv2: string = typeof v2;
|
|
@@ -34,6 +34,8 @@ export class Operation {
|
|
|
34
34
|
|
|
35
35
|
public static readonly NULLISH_COALESCING_OPERATOR: Operation = new Operation('??');
|
|
36
36
|
|
|
37
|
+
public static readonly CONDITIONAL_TERNARY_OPERATOR: Operation = new Operation('?');
|
|
38
|
+
|
|
37
39
|
private static readonly VALUE_OF: Map<string, Operation> = new Map([
|
|
38
40
|
['MULTIPLICATION', Operation.MULTIPLICATION],
|
|
39
41
|
['DIVISION', Operation.DIVISION],
|
|
@@ -64,6 +66,7 @@ export class Operation {
|
|
|
64
66
|
['ARRAY_OPERATOR', Operation.ARRAY_OPERATOR],
|
|
65
67
|
['OBJECT_OPERATOR', Operation.OBJECT_OPERATOR],
|
|
66
68
|
['NULLISH_COALESCING_OPERATOR', Operation.NULLISH_COALESCING_OPERATOR],
|
|
69
|
+
['CONDITIONAL_TERNARY_OPERATOR', Operation.CONDITIONAL_TERNARY_OPERATOR],
|
|
67
70
|
]);
|
|
68
71
|
|
|
69
72
|
public static readonly UNARY_OPERATORS: Set<Operation> = new Set([
|
|
@@ -109,6 +112,10 @@ export class Operation {
|
|
|
109
112
|
Operation.BITWISE_XOR,
|
|
110
113
|
]);
|
|
111
114
|
|
|
115
|
+
public static readonly CONDITIONAL_OPERATORS: Set<Operation> = new Set([
|
|
116
|
+
Operation.CONDITIONAL_TERNARY_OPERATOR,
|
|
117
|
+
]);
|
|
118
|
+
|
|
112
119
|
public static readonly OPERATOR_PRIORITY: Map<Operation, number> = new Map([
|
|
113
120
|
[Operation.UNARY_PLUS, 1],
|
|
114
121
|
[Operation.UNARY_MINUS, 1],
|
|
@@ -137,6 +144,7 @@ export class Operation {
|
|
|
137
144
|
[Operation.AND, 10],
|
|
138
145
|
[Operation.OR, 11],
|
|
139
146
|
[Operation.NULLISH_COALESCING_OPERATOR, 11],
|
|
147
|
+
[Operation.CONDITIONAL_TERNARY_OPERATOR, 12],
|
|
140
148
|
]);
|
|
141
149
|
|
|
142
150
|
public static readonly OPERATORS: Set<string> = new Set(
|
|
@@ -146,6 +154,7 @@ export class Operation {
|
|
|
146
154
|
...Array.from(Operation.BITWISE_OPERATORS),
|
|
147
155
|
Operation.ARRAY_OPERATOR,
|
|
148
156
|
Operation.OBJECT_OPERATOR,
|
|
157
|
+
...Array.from(Operation.CONDITIONAL_OPERATORS),
|
|
149
158
|
].map((e) => e.getOperator()),
|
|
150
159
|
);
|
|
151
160
|
|
|
@@ -156,6 +165,7 @@ export class Operation {
|
|
|
156
165
|
...Array.from(Operation.BITWISE_OPERATORS),
|
|
157
166
|
Operation.ARRAY_OPERATOR,
|
|
158
167
|
Operation.OBJECT_OPERATOR,
|
|
168
|
+
...Array.from(Operation.CONDITIONAL_OPERATORS),
|
|
159
169
|
]
|
|
160
170
|
.filter((e) => !e.shouldBeWrappedInSpace())
|
|
161
171
|
.map((e) => e.getOperator()),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExecutionException } from '../../../../exception/ExecutionException';
|
|
2
|
+
import { isNullValue } from '../../../../util/NullCheck';
|
|
3
|
+
import { StringFormatter } from '../../../../util/string/StringFormatter';
|
|
4
|
+
import { Operation } from '../../Operation';
|
|
5
|
+
|
|
6
|
+
export abstract class TernaryOperator {
|
|
7
|
+
public abstract apply(t: any, u: any, v: any): any;
|
|
8
|
+
|
|
9
|
+
public nullCheck(e1: any, e2: any, e3: any, op: Operation): void {
|
|
10
|
+
if (isNullValue(e1) || isNullValue(e2) || isNullValue(e3))
|
|
11
|
+
throw new ExecutionException(
|
|
12
|
+
StringFormatter.format('$ cannot be applied to a null value', op.getOperatorName()),
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ConditionalTernaryOperator';
|
package/src/index.ts
CHANGED
|
@@ -53,7 +53,6 @@ export * from './engine/json/schema/type/TypeUtil';
|
|
|
53
53
|
export * from './engine/json/schema/type/MultipleType';
|
|
54
54
|
export * from './engine/json/schema/type/Type';
|
|
55
55
|
export * from './engine/json/schema/type/SchemaType';
|
|
56
|
-
export * from './engine/json/schema/object/AdditionalPropertiesType';
|
|
57
56
|
export * from './engine/json/schema/SchemaUtil';
|
|
58
57
|
export * from './engine/json/schema/string/StringFormat';
|
|
59
58
|
export * from './engine/HybridRepository';
|
|
@@ -77,3 +76,4 @@ export * from './engine/exception/ExecutionException';
|
|
|
77
76
|
export * from './engine/exception/KIRuntimeException';
|
|
78
77
|
export * from './engine/runtime/expression/operators/unary';
|
|
79
78
|
export * from './engine/runtime/expression/operators/binary';
|
|
79
|
+
export * from './engine/runtime/expression/operators/ternary';
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Schema } from '../Schema';
|
|
2
|
-
|
|
3
|
-
export class AdditionalPropertiesType {
|
|
4
|
-
private booleanValue?: boolean;
|
|
5
|
-
private schemaValue?: Schema;
|
|
6
|
-
|
|
7
|
-
public getBooleanValue(): boolean | undefined {
|
|
8
|
-
return this.booleanValue;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public getSchemaValue(): Schema | undefined {
|
|
12
|
-
return this.schemaValue;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public setBooleanValue(booleanValue: boolean): AdditionalPropertiesType {
|
|
16
|
-
this.booleanValue = booleanValue;
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public setSchemaValue(schemaValue: Schema): AdditionalPropertiesType {
|
|
21
|
-
this.schemaValue = schemaValue;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static from(obj: any): AdditionalPropertiesType | undefined {
|
|
26
|
-
if (!obj) return undefined;
|
|
27
|
-
const ad = new AdditionalPropertiesType();
|
|
28
|
-
ad.booleanValue = obj.booleanValue;
|
|
29
|
-
ad.schemaValue = obj.schemaValue;
|
|
30
|
-
return ad;
|
|
31
|
-
}
|
|
32
|
-
}
|