@fincity/kirun-js 1.1.0 → 1.1.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.
- 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 +74 -20
- 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/RandomIntTest.ts +54 -0
- 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/SchemaValidatorTest.ts +29 -0
- package/__tests__/engine/runtime/KIRuntimeTest.ts +23 -12
- package/__tests__/engine/runtime/KIRuntimeWithDefinitionTest.ts +88 -0
- 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 +21 -7
- 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/array/AbstractArrayFunction.ts +5 -0
- package/src/engine/function/system/array/Delete.ts +23 -31
- package/src/engine/function/system/math/RandomFloat.ts +56 -0
- package/src/engine/function/system/math/RandomInt.ts +56 -0
- package/src/engine/json/schema/Schema.ts +4 -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/Event.ts +15 -0
- package/src/engine/model/FunctionDefinition.ts +76 -29
- package/src/engine/model/Parameter.ts +11 -0
- package/src/engine/model/ParameterReference.ts +8 -1
- package/src/engine/model/Position.ts +5 -0
- package/src/engine/model/Statement.ts +16 -0
- package/src/engine/model/StatementGroup.ts +7 -0
- package/src/engine/runtime/FunctionExecutionParameters.ts +30 -0
- package/src/engine/runtime/KIRuntime.ts +37 -24
- package/src/index.ts +2 -30
|
@@ -7,6 +7,7 @@ import { TypeUtil } from './type/TypeUtil';
|
|
|
7
7
|
import { Type } from './type/Type';
|
|
8
8
|
import { isNullValue } from '../../util/NullCheck';
|
|
9
9
|
import { SingleType } from './type/SingleType';
|
|
10
|
+
import { SchemaReferenceException } from './validator/exception/SchemaReferenceException';
|
|
10
11
|
|
|
11
12
|
const ADDITIONAL_PROPERTY: string = 'additionalProperty';
|
|
12
13
|
const ENUMS: string = 'enums';
|
|
@@ -279,14 +280,14 @@ export class Schema {
|
|
|
279
280
|
if (isNullValue(obj)) return undefined;
|
|
280
281
|
|
|
281
282
|
let schema: Schema = new Schema();
|
|
282
|
-
schema.namespace = obj.namespace;
|
|
283
|
+
schema.namespace = obj.namespace ?? TEMPORARY;
|
|
283
284
|
schema.name = obj.name;
|
|
284
285
|
|
|
285
|
-
schema.version = obj.version;
|
|
286
|
+
schema.version = obj.version ?? 1;
|
|
286
287
|
|
|
287
288
|
schema.ref = obj.ref;
|
|
288
289
|
|
|
289
|
-
if (!isStringSchema) schema.type = TypeUtil.from(
|
|
290
|
+
if (!isStringSchema) schema.type = TypeUtil.from(obj.type);
|
|
290
291
|
else schema.type = new SingleType(SchemaType.STRING);
|
|
291
292
|
|
|
292
293
|
schema.anyOf = Schema.fromListOfSchemas(obj.anyOf);
|
|
@@ -49,9 +49,9 @@ export class SchemaUtil {
|
|
|
49
49
|
let parts: string[] = ref.split('/');
|
|
50
50
|
let i: number = 1;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
if (i === parts.length) return schema;
|
|
53
53
|
|
|
54
|
-
return schema;
|
|
54
|
+
return SchemaUtil.resolveInternalSchema(schema, sRepository, ref, iteration, parts, i);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
private static resolveInternalSchema(
|
|
@@ -61,8 +61,9 @@ export class SchemaUtil {
|
|
|
61
61
|
iteration: number,
|
|
62
62
|
parts: string[],
|
|
63
63
|
i: number,
|
|
64
|
-
): Schema {
|
|
64
|
+
): Schema | undefined {
|
|
65
65
|
let schema: Schema | undefined = inSchema;
|
|
66
|
+
if (i === parts.length) return undefined;
|
|
66
67
|
while (i < parts.length) {
|
|
67
68
|
if (parts[i] === '$defs') {
|
|
68
69
|
i++;
|
|
@@ -117,7 +118,6 @@ export class SchemaUtil {
|
|
|
117
118
|
sRepository: Repository<Schema> | undefined,
|
|
118
119
|
ref: string,
|
|
119
120
|
): Tuple2<Schema, string> | undefined {
|
|
120
|
-
|
|
121
121
|
if (!sRepository) return undefined;
|
|
122
122
|
|
|
123
123
|
let nms = StringUtil.splitAtFirstOccurance(inSchem?.getRef() ?? '', '/');
|
|
@@ -12,12 +12,10 @@ export class TypeUtil {
|
|
|
12
12
|
|
|
13
13
|
public static from(types: any): Type | undefined {
|
|
14
14
|
if (typeof types === 'string') {
|
|
15
|
-
return
|
|
15
|
+
return new SingleType(types as SchemaType);
|
|
16
16
|
} else if (Array.isArray(types)) {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
.map((e) => e as any)
|
|
20
|
-
.map((e) => e as SchemaType),
|
|
17
|
+
return new MultipleType(
|
|
18
|
+
new Set(types.map((e) => e as any).map((e) => e as SchemaType)),
|
|
21
19
|
);
|
|
22
20
|
}
|
|
23
21
|
return undefined;
|
|
@@ -2,6 +2,7 @@ import { AdditionalPropertiesType } from '../json/schema/object/AdditionalProper
|
|
|
2
2
|
import { Schema } from '../json/schema/Schema';
|
|
3
3
|
import { SchemaType } from '../json/schema/type/SchemaType';
|
|
4
4
|
import { TypeUtil } from '../json/schema/type/TypeUtil';
|
|
5
|
+
import { SchemaReferenceException } from '../json/schema/validator/exception/SchemaReferenceException';
|
|
5
6
|
import { Namespaces } from '../namespaces/Namespaces';
|
|
6
7
|
|
|
7
8
|
export class Event {
|
|
@@ -59,4 +60,18 @@ export class Event {
|
|
|
59
60
|
): [string, Event] {
|
|
60
61
|
return [eventName, new Event(eventName, parameters)];
|
|
61
62
|
}
|
|
63
|
+
|
|
64
|
+
public static from(json: any): Event {
|
|
65
|
+
return new Event(
|
|
66
|
+
json.name,
|
|
67
|
+
new Map(
|
|
68
|
+
Object.entries(json.parameters ?? {}).map((e: any) => {
|
|
69
|
+
const eventSchema = Schema.from(e[1]);
|
|
70
|
+
if (!eventSchema)
|
|
71
|
+
throw new SchemaReferenceException('', 'Event expects a schema');
|
|
72
|
+
return [e[0], eventSchema];
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
62
77
|
}
|
|
@@ -7,39 +7,38 @@ import { Parameter } from './Parameter';
|
|
|
7
7
|
import { Statement } from './Statement';
|
|
8
8
|
import { StatementGroup } from './StatementGroup';
|
|
9
9
|
|
|
10
|
+
const SCHEMA_NAME1: string = 'FunctionDefinition';
|
|
11
|
+
const IN_SCHEMA = new Schema()
|
|
12
|
+
.setNamespace(Namespaces.SYSTEM)
|
|
13
|
+
.setName(SCHEMA_NAME1)
|
|
14
|
+
.setProperties(
|
|
15
|
+
new Map([
|
|
16
|
+
['name', Schema.ofString('name')],
|
|
17
|
+
['namespace', Schema.ofString('namespace')],
|
|
18
|
+
['parameters', Schema.ofArray('parameters', Parameter.SCHEMA)],
|
|
19
|
+
[
|
|
20
|
+
'events',
|
|
21
|
+
Schema.ofObject('events').setAdditionalProperties(
|
|
22
|
+
new AdditionalPropertiesType().setSchemaValue(Event.SCHEMA),
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
'steps',
|
|
27
|
+
Schema.ofObject('steps').setAdditionalProperties(
|
|
28
|
+
new AdditionalPropertiesType().setSchemaValue(Statement.SCHEMA),
|
|
29
|
+
),
|
|
30
|
+
],
|
|
31
|
+
]),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
IN_SCHEMA.getProperties()?.set('parts', Schema.ofArray('parts', IN_SCHEMA));
|
|
35
|
+
|
|
10
36
|
export class FunctionDefinition extends FunctionSignature {
|
|
11
|
-
|
|
12
|
-
public static readonly SCHEMA: Schema = new Schema()
|
|
13
|
-
.setNamespace(Namespaces.SYSTEM)
|
|
14
|
-
.setName(FunctionDefinition.SCHEMA_NAME1)
|
|
15
|
-
.setProperties(
|
|
16
|
-
new Map([
|
|
17
|
-
['name', Schema.ofString('name')],
|
|
18
|
-
['namespace', Schema.ofString('namespace')],
|
|
19
|
-
['parameters', Schema.ofArray('parameters', Parameter.SCHEMA)],
|
|
20
|
-
[
|
|
21
|
-
'events',
|
|
22
|
-
Schema.ofObject('events').setAdditionalProperties(
|
|
23
|
-
new AdditionalPropertiesType().setSchemaValue(Event.SCHEMA),
|
|
24
|
-
),
|
|
25
|
-
],
|
|
26
|
-
[
|
|
27
|
-
'parts',
|
|
28
|
-
Schema.ofObject('parts').setAdditionalProperties(
|
|
29
|
-
new AdditionalPropertiesType().setSchemaValue(FunctionSignature.SCHEMA),
|
|
30
|
-
),
|
|
31
|
-
],
|
|
32
|
-
[
|
|
33
|
-
'steps',
|
|
34
|
-
Schema.ofObject('steps').setAdditionalProperties(
|
|
35
|
-
new AdditionalPropertiesType().setSchemaValue(Statement.SCHEMA),
|
|
36
|
-
),
|
|
37
|
-
],
|
|
38
|
-
]),
|
|
39
|
-
);
|
|
37
|
+
public static readonly SCHEMA: Schema = IN_SCHEMA;
|
|
40
38
|
private version: number = 1;
|
|
41
39
|
private steps?: Map<string, Statement>;
|
|
42
40
|
private stepGroups?: Map<string, StatementGroup>;
|
|
41
|
+
private parts?: FunctionDefinition[];
|
|
43
42
|
|
|
44
43
|
constructor(name: string) {
|
|
45
44
|
super(name);
|
|
@@ -66,4 +65,52 @@ export class FunctionDefinition extends FunctionSignature {
|
|
|
66
65
|
this.stepGroups = stepGroups;
|
|
67
66
|
return this;
|
|
68
67
|
}
|
|
68
|
+
|
|
69
|
+
public getParts(): FunctionDefinition[] | undefined {
|
|
70
|
+
return this.parts;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public setParts(parts: FunctionDefinition[]): FunctionDefinition {
|
|
74
|
+
this.parts = parts;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public static from(json: any): FunctionDefinition {
|
|
79
|
+
if (!json) return new FunctionDefinition('unknown');
|
|
80
|
+
return new FunctionDefinition(json.name)
|
|
81
|
+
.setSteps(
|
|
82
|
+
new Map(
|
|
83
|
+
Object.values(json.steps ?? {})
|
|
84
|
+
.filter((e) => !!e)
|
|
85
|
+
.map((e: any) => [e.statementName, Statement.from(e)]),
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
.setStepGroups(
|
|
89
|
+
new Map(
|
|
90
|
+
Object.values(json.stepGroups ?? {})
|
|
91
|
+
.filter((e) => !!e)
|
|
92
|
+
.map((e: any) => [e.statementGroupName, StatementGroup.from(e)]),
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
.setParts(
|
|
96
|
+
Array.from(json.parts ?? [])
|
|
97
|
+
.filter((e) => !!e)
|
|
98
|
+
.map((e: any) => FunctionDefinition.from(e)),
|
|
99
|
+
)
|
|
100
|
+
.setVersion(json.version ?? 1)
|
|
101
|
+
.setEvents(
|
|
102
|
+
new Map(
|
|
103
|
+
Object.values(json.events ?? {})
|
|
104
|
+
.filter((e) => !!e)
|
|
105
|
+
.map((e: any) => [e.name, Event.from(e)]),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
.setParameters(
|
|
109
|
+
new Map(
|
|
110
|
+
Object.values(json.parameters ?? {})
|
|
111
|
+
.filter((e) => !!e)
|
|
112
|
+
.map((e: any) => [e.parameterName, Parameter.from(e)]),
|
|
113
|
+
),
|
|
114
|
+
) as FunctionDefinition;
|
|
115
|
+
}
|
|
69
116
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema } from '../json/schema/Schema';
|
|
2
2
|
import { SchemaType } from '../json/schema/type/SchemaType';
|
|
3
3
|
import { TypeUtil } from '../json/schema/type/TypeUtil';
|
|
4
|
+
import { SchemaReferenceException } from '../json/schema/validator/exception/SchemaReferenceException';
|
|
4
5
|
import { Namespaces } from '../namespaces/Namespaces';
|
|
5
6
|
import { ParameterType } from './ParameterType';
|
|
6
7
|
|
|
@@ -20,9 +21,11 @@ export class Parameter {
|
|
|
20
21
|
'variableArgument',
|
|
21
22
|
Schema.of('variableArgument', SchemaType.BOOLEAN).setDefaultValue(false),
|
|
22
23
|
],
|
|
24
|
+
['type', Schema.ofString('type').setEnums(['EXPRESSION', 'CONSTANT'])],
|
|
23
25
|
]),
|
|
24
26
|
);
|
|
25
27
|
|
|
28
|
+
// Place holder for the expression parameter when required to represent an expression in the value.
|
|
26
29
|
public static readonly EXPRESSION: Schema = new Schema()
|
|
27
30
|
.setNamespace(Namespaces.SYSTEM)
|
|
28
31
|
.setName('ParameterExpression')
|
|
@@ -94,4 +97,12 @@ export class Parameter {
|
|
|
94
97
|
): Parameter {
|
|
95
98
|
return new Parameter(name, schema).setType(type).setVariableArgument(variableArgument);
|
|
96
99
|
}
|
|
100
|
+
|
|
101
|
+
public static from(json: any): Parameter {
|
|
102
|
+
const paramSchema = Schema.from(json.schema);
|
|
103
|
+
if (!paramSchema) throw new SchemaReferenceException('', 'Parameter requires Schema');
|
|
104
|
+
return new Parameter(json.parameterName, paramSchema)
|
|
105
|
+
.setVariableArgument(!!json.variableArguments)
|
|
106
|
+
.setType(json.type ?? ParameterType.EXPRESSION);
|
|
107
|
+
}
|
|
97
108
|
}
|
|
@@ -12,9 +12,9 @@ export class ParameterReference {
|
|
|
12
12
|
.setType(TypeUtil.of(SchemaType.OBJECT))
|
|
13
13
|
.setProperties(
|
|
14
14
|
new Map([
|
|
15
|
-
['references', Schema.ofString('references')],
|
|
16
15
|
['value', Schema.ofAny('value')],
|
|
17
16
|
['expression', Schema.ofString('expression')],
|
|
17
|
+
['type', Schema.ofString('type').setEnums(['EXPRESSION', 'VALUE'])],
|
|
18
18
|
]),
|
|
19
19
|
);
|
|
20
20
|
private type: ParameterReferenceType;
|
|
@@ -54,4 +54,11 @@ export class ParameterReference {
|
|
|
54
54
|
public static ofValue(value: any): ParameterReference {
|
|
55
55
|
return new ParameterReference(ParameterReferenceType.VALUE).setValue(value);
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
public static from(json: any): ParameterReference[] {
|
|
59
|
+
if (!json) return [];
|
|
60
|
+
return Array.from(json).map((e: any) =>
|
|
61
|
+
new ParameterReference(e.type).setValue(e.value).setExpression(e.expression),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
57
64
|
}
|
|
@@ -98,4 +98,20 @@ export class Statement extends AbstractStatement {
|
|
|
98
98
|
public static ofEntry(statement: Statement): [string, Statement] {
|
|
99
99
|
return [statement.statementName, statement];
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
public static from(json: any): Statement {
|
|
103
|
+
return new Statement(json.statementName, json.namespace, json.name)
|
|
104
|
+
.setParameterMap(
|
|
105
|
+
new Map<string, ParameterReference[]>(
|
|
106
|
+
Object.entries(json.parameterMap ?? {}).map(([k, v]) => [
|
|
107
|
+
k,
|
|
108
|
+
ParameterReference.from(v),
|
|
109
|
+
]),
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
.setDependentStatements(json.dependentStatements)
|
|
113
|
+
.setPosition(Position.from(json.position))
|
|
114
|
+
.setComment(json.comment)
|
|
115
|
+
.setDescription(json.description) as Statement;
|
|
116
|
+
}
|
|
101
117
|
}
|
|
@@ -34,4 +34,11 @@ export class StatementGroup extends AbstractStatement {
|
|
|
34
34
|
this.statementGroupName = statementGroupName;
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
public static from(json: any): StatementGroup {
|
|
39
|
+
return new StatementGroup(json.statementGroupName)
|
|
40
|
+
.setPosition(Position.from(json.position))
|
|
41
|
+
.setComment(json.comment)
|
|
42
|
+
.setDescription(json.description) as StatementGroup;
|
|
43
|
+
}
|
|
37
44
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Function } from '../function/Function';
|
|
2
|
+
import { Schema } from '../json/schema/Schema';
|
|
3
|
+
import { Repository } from '../Repository';
|
|
1
4
|
import { ContextElement } from './ContextElement';
|
|
2
5
|
import { TokenValueExtractor } from './expression/tokenextractor/TokenValueExtractor';
|
|
3
6
|
import { StatementExecution } from './StatementExecution';
|
|
@@ -12,9 +15,19 @@ export class FunctionExecutionParameters {
|
|
|
12
15
|
private statementExecution?: StatementExecution;
|
|
13
16
|
private steps?: Map<string, Map<string, Map<string, any>>>;
|
|
14
17
|
private count: number = 0;
|
|
18
|
+
private functionRepository: Repository<Function>;
|
|
19
|
+
private schemaRepository: Repository<Schema>;
|
|
15
20
|
|
|
16
21
|
private valueExtractors: Map<string, TokenValueExtractor> = new Map();
|
|
17
22
|
|
|
23
|
+
public constructor(
|
|
24
|
+
functionRepository: Repository<Function>,
|
|
25
|
+
schemaRepository: Repository<Schema>,
|
|
26
|
+
) {
|
|
27
|
+
this.functionRepository = functionRepository;
|
|
28
|
+
this.schemaRepository = schemaRepository;
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
public getContext(): Map<string, ContextElement> | undefined {
|
|
19
32
|
return this.context;
|
|
20
33
|
}
|
|
@@ -71,4 +84,21 @@ export class FunctionExecutionParameters {
|
|
|
71
84
|
public getValuesMap(): Map<string, TokenValueExtractor> {
|
|
72
85
|
return this.valueExtractors;
|
|
73
86
|
}
|
|
87
|
+
|
|
88
|
+
public getFunctionRepository(): Repository<Function> {
|
|
89
|
+
return this.functionRepository;
|
|
90
|
+
}
|
|
91
|
+
public setFunctionRepository(
|
|
92
|
+
functionRepository: Repository<Function>,
|
|
93
|
+
): FunctionExecutionParameters {
|
|
94
|
+
this.functionRepository = functionRepository;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
public getSchemaRepository(): Repository<Schema> {
|
|
98
|
+
return this.schemaRepository;
|
|
99
|
+
}
|
|
100
|
+
public setSchemaRepository(schemaRepository: Repository<Schema>): FunctionExecutionParameters {
|
|
101
|
+
this.schemaRepository = schemaRepository;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
74
104
|
}
|
|
@@ -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,10 @@ 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
|
+
)
|
|
291
300
|
.setContext(context)
|
|
292
301
|
.setArguments(args)
|
|
293
302
|
.setEvents(inContext.getEvents()!)
|
|
@@ -455,10 +464,12 @@ export class KIRuntime extends AbstractFunction {
|
|
|
455
464
|
private prepareStatementExecution(
|
|
456
465
|
context: Map<string, ContextElement>,
|
|
457
466
|
s: Statement,
|
|
467
|
+
fRepo: Repository<Function>,
|
|
468
|
+
sRepo: Repository<Schema>,
|
|
458
469
|
): StatementExecution {
|
|
459
470
|
let se: StatementExecution = new StatementExecution(s);
|
|
460
471
|
|
|
461
|
-
let fun: Function | undefined =
|
|
472
|
+
let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
|
|
462
473
|
|
|
463
474
|
if (!fun) {
|
|
464
475
|
throw new KIRuntimeException(
|
|
@@ -475,7 +486,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
475
486
|
let refList: ParameterReference[] = param[1];
|
|
476
487
|
|
|
477
488
|
if (!refList.length) {
|
|
478
|
-
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
489
|
+
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
|
|
479
490
|
se.addMessage(
|
|
480
491
|
StatementMessageType.ERROR,
|
|
481
492
|
StringFormatter.format(
|
|
@@ -487,10 +498,11 @@ export class KIRuntime extends AbstractFunction {
|
|
|
487
498
|
}
|
|
488
499
|
|
|
489
500
|
if (p.isVariableArgument()) {
|
|
490
|
-
for (let ref of refList)
|
|
501
|
+
for (let ref of refList)
|
|
502
|
+
this.parameterReferenceValidation(context, se, p, ref, sRepo);
|
|
491
503
|
} else {
|
|
492
504
|
let ref: ParameterReference = refList[0];
|
|
493
|
-
this.parameterReferenceValidation(context, se, p, ref);
|
|
505
|
+
this.parameterReferenceValidation(context, se, p, ref, sRepo);
|
|
494
506
|
}
|
|
495
507
|
|
|
496
508
|
paramSet.delete(p.getParameterName());
|
|
@@ -503,7 +515,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
503
515
|
|
|
504
516
|
if (paramSet.size) {
|
|
505
517
|
for (let param of Array.from(paramSet.values())) {
|
|
506
|
-
if (isNullValue(SchemaUtil.getDefaultValue(param.getSchema(),
|
|
518
|
+
if (isNullValue(SchemaUtil.getDefaultValue(param.getSchema(), sRepo)))
|
|
507
519
|
se.addMessage(
|
|
508
520
|
StatementMessageType.ERROR,
|
|
509
521
|
StringFormatter.format(
|
|
@@ -522,11 +534,12 @@ export class KIRuntime extends AbstractFunction {
|
|
|
522
534
|
se: StatementExecution,
|
|
523
535
|
p: Parameter,
|
|
524
536
|
ref: ParameterReference,
|
|
537
|
+
sRepo: Repository<Schema>,
|
|
525
538
|
): void {
|
|
526
539
|
// Breaking this execution doesn't make sense.
|
|
527
540
|
|
|
528
541
|
if (!ref) {
|
|
529
|
-
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
542
|
+
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
|
|
530
543
|
se.addMessage(
|
|
531
544
|
StatementMessageType.ERROR,
|
|
532
545
|
StringFormatter.format(KIRuntime.PARAMETER_NEEDS_A_VALUE, p.getParameterName()),
|
|
@@ -534,7 +547,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
534
547
|
} else if (ref.getType() == ParameterReferenceType.VALUE) {
|
|
535
548
|
if (
|
|
536
549
|
isNullValue(ref.getValue()) &&
|
|
537
|
-
isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
550
|
+
isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo))
|
|
538
551
|
)
|
|
539
552
|
se.addMessage(
|
|
540
553
|
StatementMessageType.ERROR,
|
|
@@ -598,7 +611,7 @@ export class KIRuntime extends AbstractFunction {
|
|
|
598
611
|
}
|
|
599
612
|
} else if (ref.getType() == ParameterReferenceType.EXPRESSION) {
|
|
600
613
|
if (StringUtil.isNullOrBlank(ref.getExpression())) {
|
|
601
|
-
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(),
|
|
614
|
+
if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
|
|
602
615
|
se.addMessage(
|
|
603
616
|
StatementMessageType.ERROR,
|
|
604
617
|
StringFormatter.format(
|
package/src/index.ts
CHANGED
|
@@ -23,36 +23,6 @@ export * from './engine/runtime/KIRuntime';
|
|
|
23
23
|
export * from './engine/runtime/StatementMessageType';
|
|
24
24
|
export * from './engine/runtime/FunctionExecutionParameters';
|
|
25
25
|
export * from './engine/runtime/expression/Expression';
|
|
26
|
-
export * from './engine/runtime/expression/operators/unary/BitwiseComplementOperator';
|
|
27
|
-
export * from './engine/runtime/expression/operators/unary/LogicalNotOperator';
|
|
28
|
-
export * from './engine/runtime/expression/operators/unary/ArithmeticUnaryPlusOperator';
|
|
29
|
-
export * from './engine/runtime/expression/operators/unary/ArithmeticUnaryMinusOperator';
|
|
30
|
-
export * from './engine/runtime/expression/operators/unary/index';
|
|
31
|
-
export * from './engine/runtime/expression/operators/unary/UnaryOperator';
|
|
32
|
-
export * from './engine/runtime/expression/operators/binary/ArithmeticSubtractionOperator';
|
|
33
|
-
export * from './engine/runtime/expression/operators/binary/ArrayOperator';
|
|
34
|
-
export * from './engine/runtime/expression/operators/binary/BitwiseUnsignedRightShiftOperator';
|
|
35
|
-
export * from './engine/runtime/expression/operators/binary/LogicalLessThanEqualOperator';
|
|
36
|
-
export * from './engine/runtime/expression/operators/binary/ObjectOperator';
|
|
37
|
-
export * from './engine/runtime/expression/operators/binary/BitwiseLeftShiftOperator';
|
|
38
|
-
export * from './engine/runtime/expression/operators/binary/LogicalGreaterThanEqualOperator';
|
|
39
|
-
export * from './engine/runtime/expression/operators/binary/LogicalGreaterThanOperator';
|
|
40
|
-
export * from './engine/runtime/expression/operators/binary/ArithmeticMultiplicationOperator';
|
|
41
|
-
export * from './engine/runtime/expression/operators/binary/BitwiseRightShiftOperator';
|
|
42
|
-
export * from './engine/runtime/expression/operators/binary/BitwiseOrOperator';
|
|
43
|
-
export * from './engine/runtime/expression/operators/binary/LogicalNotEqualOperator';
|
|
44
|
-
export * from './engine/runtime/expression/operators/binary/ArithmeticAdditionOperator';
|
|
45
|
-
export * from './engine/runtime/expression/operators/binary/BitwiseAndOperator';
|
|
46
|
-
export * from './engine/runtime/expression/operators/binary/BinaryOperator';
|
|
47
|
-
export * from './engine/runtime/expression/operators/binary/LogicalAndOperator';
|
|
48
|
-
export * from './engine/runtime/expression/operators/binary/LogicalLessThanOperator';
|
|
49
|
-
export * from './engine/runtime/expression/operators/binary/LogicalOrOperator';
|
|
50
|
-
export * from './engine/runtime/expression/operators/binary/index';
|
|
51
|
-
export * from './engine/runtime/expression/operators/binary/ArithmeticDivisionOperator';
|
|
52
|
-
export * from './engine/runtime/expression/operators/binary/BitwiseXorOperator';
|
|
53
|
-
export * from './engine/runtime/expression/operators/binary/ArithmeticModulusOperator';
|
|
54
|
-
export * from './engine/runtime/expression/operators/binary/ArithmeticInetgerDivisionOperator';
|
|
55
|
-
export * from './engine/runtime/expression/operators/binary/LogicalEqualOperator';
|
|
56
26
|
export * from './engine/runtime/expression/tokenextractor/TokenValueExtractor';
|
|
57
27
|
export * from './engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor';
|
|
58
28
|
export * from './engine/runtime/expression/ExpressionEvaluator';
|
|
@@ -104,3 +74,5 @@ export * from './engine/model/Argument';
|
|
|
104
74
|
export * from './engine/model/ParameterReference';
|
|
105
75
|
export * from './engine/exception/ExecutionException';
|
|
106
76
|
export * from './engine/exception/KIRuntimeException';
|
|
77
|
+
export * from './engine/runtime/expression/operators/unary';
|
|
78
|
+
export * from './engine/runtime/expression/operators/binary';
|