@fincity/kirun-js 1.1.2 → 1.1.5
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/array/AddFirstTest.ts +29 -7
- package/__tests__/engine/function/system/array/AddTest.ts +21 -5
- package/__tests__/engine/function/system/array/BinarySearchTest.ts +26 -7
- package/__tests__/engine/function/system/array/CompareTest.ts +5 -1
- package/__tests__/engine/function/system/array/CopyTest.ts +22 -7
- package/__tests__/engine/function/system/array/DeleteFirstTest.ts +21 -5
- package/__tests__/engine/function/system/array/DeleteFromTest.ts +17 -4
- package/__tests__/engine/function/system/array/DeleteLastTest.ts +21 -5
- package/__tests__/engine/function/system/array/DeleteTest.ts +25 -6
- package/__tests__/engine/function/system/array/DisjointTest.ts +13 -3
- package/__tests__/engine/function/system/array/Equals.ts +13 -3
- package/__tests__/engine/function/system/array/FillTest.ts +5 -1
- package/__tests__/engine/function/system/array/FrequencyTest.ts +13 -3
- package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +29 -7
- package/__tests__/engine/function/system/array/IndexOfTest.ts +21 -5
- package/__tests__/engine/function/system/array/InsertTest.ts +25 -6
- package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +21 -5
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +25 -6
- package/__tests__/engine/function/system/array/MaxTest.ts +33 -24
- package/__tests__/engine/function/system/array/MinTest.ts +33 -24
- package/__tests__/engine/function/system/array/MisMatchTest.ts +17 -4
- package/__tests__/engine/function/system/array/ReverseTest.ts +21 -5
- package/__tests__/engine/function/system/array/RotateTest.ts +13 -3
- package/__tests__/engine/function/system/array/ShuffleTest.ts +9 -2
- package/__tests__/engine/function/system/array/SortTest.ts +21 -5
- package/__tests__/engine/function/system/array/SubArrayTest.ts +21 -5
- package/__tests__/engine/function/system/context/SetFunctionTest.ts +13 -3
- package/__tests__/engine/function/system/math/AddTest.ts +5 -3
- package/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +108 -0
- package/__tests__/engine/function/system/math/MaximumTest.ts +38 -0
- package/__tests__/engine/function/system/math/MinimumTest.ts +38 -0
- package/__tests__/engine/function/system/math/RandomFloatTest.ts +83 -0
- package/__tests__/engine/function/system/math/RandomIntTest.ts +13 -5
- package/__tests__/engine/function/system/string/ConcatenateTest.ts +9 -2
- package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +9 -2
- package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +13 -3
- package/__tests__/engine/function/system/string/PostPadTest.ts +13 -3
- package/__tests__/engine/function/system/string/PrePadTest.ts +13 -3
- package/__tests__/engine/function/system/string/RegionMatchesTest.ts +13 -3
- package/__tests__/engine/function/system/string/ReverseTest.ts +10 -3
- package/__tests__/engine/function/system/string/SplitTest.ts +9 -2
- package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +13 -3
- package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +9 -2
- package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +33 -8
- package/__tests__/engine/function/system/string/ToStringTest.ts +10 -3
- package/__tests__/engine/function/system/string/TrimToTest.ts +9 -2
- package/__tests__/engine/json/schema/SchemaUtil.ts +3 -0
- package/__tests__/engine/json/schema/type/TypeUtilTest.ts +10 -0
- package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +38 -0
- package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +67 -0
- package/__tests__/engine/runtime/KIRuntimeTest.ts +23 -12
- package/__tests__/engine/runtime/KIRuntimeWithDefinitionTest.ts +9 -10
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +5 -1
- 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 +11 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/AbstractFunction.ts +14 -5
- package/src/engine/function/system/math/Maximum.ts +1 -1
- package/src/engine/function/system/math/Minimum.ts +1 -1
- package/src/engine/function/system/math/RandomFloat.ts +2 -2
- package/src/engine/json/schema/Schema.ts +3 -3
- package/src/engine/json/schema/SchemaUtil.ts +4 -4
- package/src/engine/json/schema/type/TypeUtil.ts +3 -5
- package/src/engine/json/schema/validator/SchemaValidator.ts +4 -1
- package/src/engine/model/AbstractStatement.ts +10 -0
- package/src/engine/runtime/FunctionExecutionParameters.ts +48 -0
- package/src/engine/runtime/KIRuntime.ts +38 -24
|
@@ -43,15 +43,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
43
43
|
|
|
44
44
|
private fd: FunctionDefinition;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
private sRepo: Repository<Schema>;
|
|
49
|
-
|
|
50
|
-
public constructor(
|
|
51
|
-
fd: FunctionDefinition,
|
|
52
|
-
functionRepository: Repository<Function>,
|
|
53
|
-
schemaRepository: Repository<Schema>,
|
|
54
|
-
) {
|
|
46
|
+
public constructor(fd: FunctionDefinition) {
|
|
55
47
|
super();
|
|
56
48
|
this.fd = fd;
|
|
57
49
|
if (this.fd.getVersion() > KIRuntime.VERSION) {
|
|
@@ -63,9 +55,6 @@ export class KIRuntime extends AbstractFunction {
|
|
|
63
55
|
'.',
|
|
64
56
|
);
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
this.fRepo = functionRepository;
|
|
68
|
-
this.sRepo = schemaRepository;
|
|
69
58
|
}
|
|
70
59
|
|
|
71
60
|
public getSignature(): FunctionSignature {
|
|
@@ -74,10 +63,18 @@ export class KIRuntime extends AbstractFunction {
|
|
|
74
63
|
|
|
75
64
|
private async getExecutionPlan(
|
|
76
65
|
context: Map<string, ContextElement>,
|
|
66
|
+
fep: FunctionExecutionParameters,
|
|
77
67
|
): Promise<ExecutionGraph<string, StatementExecution>> {
|
|
78
68
|
let g: ExecutionGraph<string, StatementExecution> = new ExecutionGraph();
|
|
79
69
|
for (let s of Array.from(this.fd.getSteps().values()))
|
|
80
|
-
g.addVertex(
|
|
70
|
+
g.addVertex(
|
|
71
|
+
this.prepareStatementExecution(
|
|
72
|
+
context,
|
|
73
|
+
s,
|
|
74
|
+
fep.getFunctionRepository(),
|
|
75
|
+
fep.getSchemaRepository(),
|
|
76
|
+
),
|
|
77
|
+
);
|
|
81
78
|
|
|
82
79
|
let unresolvedList: Tuple2<string, string>[] = this.makeEdges(g);
|
|
83
80
|
|
|
@@ -106,6 +103,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
106
103
|
|
|
107
104
|
let eGraph: ExecutionGraph<string, StatementExecution> = await this.getExecutionPlan(
|
|
108
105
|
inContext.getContext()!,
|
|
106
|
+
inContext,
|
|
109
107
|
);
|
|
110
108
|
|
|
111
109
|
// if (logger.isDebugEnabled()) {
|
|
@@ -185,7 +183,14 @@ export class KIRuntime extends AbstractFunction {
|
|
|
185
183
|
|
|
186
184
|
if (!(await this.allDependenciesResolvedVertex(vertex, inContext.getSteps()!)))
|
|
187
185
|
executionQue.add(vertex);
|
|
188
|
-
else
|
|
186
|
+
else
|
|
187
|
+
await this.executeVertex(
|
|
188
|
+
vertex,
|
|
189
|
+
inContext,
|
|
190
|
+
branchQue,
|
|
191
|
+
executionQue,
|
|
192
|
+
inContext.getFunctionRepository(),
|
|
193
|
+
);
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
196
|
|
|
@@ -265,10 +270,11 @@ export class KIRuntime extends AbstractFunction {
|
|
|
265
270
|
>
|
|
266
271
|
>,
|
|
267
272
|
executionQue: LinkedList<GraphVertex<string, StatementExecution>>,
|
|
273
|
+
fRepo: Repository<Function>,
|
|
268
274
|
) {
|
|
269
275
|
let s: Statement = vertex.getData().getStatement();
|
|
270
276
|
|
|
271
|
-
let fun: Function | undefined =
|
|
277
|
+
let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
|
|
272
278
|
|
|
273
279
|
if (!fun) {
|
|
274
280
|
throw new KIRuntimeException(
|
|
@@ -287,7 +293,11 @@ export class KIRuntime extends AbstractFunction {
|
|
|
287
293
|
let context: Map<string, ContextElement> = inContext.getContext()!;
|
|
288
294
|
|
|
289
295
|
let result: FunctionOutput = await fun.execute(
|
|
290
|
-
new FunctionExecutionParameters(
|
|
296
|
+
new FunctionExecutionParameters(
|
|
297
|
+
inContext.getFunctionRepository(),
|
|
298
|
+
inContext.getSchemaRepository(),
|
|
299
|
+
)
|
|
300
|
+
.setValuesMap(inContext.getValuesMap())
|
|
291
301
|
.setContext(context)
|
|
292
302
|
.setArguments(args)
|
|
293
303
|
.setEvents(inContext.getEvents()!)
|
|
@@ -455,10 +465,12 @@ export class KIRuntime extends AbstractFunction {
|
|
|
455
465
|
private prepareStatementExecution(
|
|
456
466
|
context: Map<string, ContextElement>,
|
|
457
467
|
s: Statement,
|
|
468
|
+
fRepo: Repository<Function>,
|
|
469
|
+
sRepo: Repository<Schema>,
|
|
458
470
|
): StatementExecution {
|
|
459
471
|
let se: StatementExecution = new StatementExecution(s);
|
|
460
472
|
|
|
461
|
-
let fun: Function | undefined =
|
|
473
|
+
let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
|
|
462
474
|
|
|
463
475
|
if (!fun) {
|
|
464
476
|
throw new KIRuntimeException(
|
|
@@ -475,7 +487,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
475
487
|
let refList: ParameterReference[] = param[1];
|
|
476
488
|
|
|
477
489
|
if (!refList.length) {
|
|
478
|
-
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
490
|
+
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
|
|
479
491
|
se.addMessage(
|
|
480
492
|
StatementMessageType.ERROR,
|
|
481
493
|
StringFormatter.format(
|
|
@@ -487,10 +499,11 @@ export class KIRuntime extends AbstractFunction {
|
|
|
487
499
|
}
|
|
488
500
|
|
|
489
501
|
if (p.isVariableArgument()) {
|
|
490
|
-
for (let ref of refList)
|
|
502
|
+
for (let ref of refList)
|
|
503
|
+
this.parameterReferenceValidation(context, se, p, ref, sRepo);
|
|
491
504
|
} else {
|
|
492
505
|
let ref: ParameterReference = refList[0];
|
|
493
|
-
this.parameterReferenceValidation(context, se, p, ref);
|
|
506
|
+
this.parameterReferenceValidation(context, se, p, ref, sRepo);
|
|
494
507
|
}
|
|
495
508
|
|
|
496
509
|
paramSet.delete(p.getParameterName());
|
|
@@ -503,7 +516,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
503
516
|
|
|
504
517
|
if (paramSet.size) {
|
|
505
518
|
for (let param of Array.from(paramSet.values())) {
|
|
506
|
-
if (isNullValue(SchemaUtil.getDefaultValue(param.getSchema(),
|
|
519
|
+
if (isNullValue(SchemaUtil.getDefaultValue(param.getSchema(), sRepo)))
|
|
507
520
|
se.addMessage(
|
|
508
521
|
StatementMessageType.ERROR,
|
|
509
522
|
StringFormatter.format(
|
|
@@ -522,11 +535,12 @@ export class KIRuntime extends AbstractFunction {
|
|
|
522
535
|
se: StatementExecution,
|
|
523
536
|
p: Parameter,
|
|
524
537
|
ref: ParameterReference,
|
|
538
|
+
sRepo: Repository<Schema>,
|
|
525
539
|
): void {
|
|
526
540
|
// Breaking this execution doesn't make sense.
|
|
527
541
|
|
|
528
542
|
if (!ref) {
|
|
529
|
-
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
543
|
+
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
|
|
530
544
|
se.addMessage(
|
|
531
545
|
StatementMessageType.ERROR,
|
|
532
546
|
StringFormatter.format(KIRuntime.PARAMETER_NEEDS_A_VALUE, p.getParameterName()),
|
|
@@ -534,7 +548,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
534
548
|
} else if (ref.getType() == ParameterReferenceType.VALUE) {
|
|
535
549
|
if (
|
|
536
550
|
isNullValue(ref.getValue()) &&
|
|
537
|
-
isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
551
|
+
isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo))
|
|
538
552
|
)
|
|
539
553
|
se.addMessage(
|
|
540
554
|
StatementMessageType.ERROR,
|
|
@@ -598,7 +612,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
598
612
|
}
|
|
599
613
|
} else if (ref.getType() == ParameterReferenceType.EXPRESSION) {
|
|
600
614
|
if (StringUtil.isNullOrBlank(ref.getExpression())) {
|
|
601
|
-
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
615
|
+
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
|
|
602
616
|
se.addMessage(
|
|
603
617
|
StatementMessageType.ERROR,
|
|
604
618
|
StringFormatter.format(
|