@fincity/kirun-js 1.0.5 → 1.1.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.
Files changed (118) hide show
  1. package/__tests__/engine/function/system/array/AddFirstTest.ts +13 -12
  2. package/__tests__/engine/function/system/array/AddTest.ts +11 -11
  3. package/__tests__/engine/function/system/array/BinarySearchTest.ts +29 -14
  4. package/__tests__/engine/function/system/array/CompareTest.ts +3 -3
  5. package/__tests__/engine/function/system/array/CopyTest.ts +5 -5
  6. package/__tests__/engine/function/system/array/DeleteFirstTest.ts +10 -10
  7. package/__tests__/engine/function/system/array/DeleteFromTest.ts +8 -8
  8. package/__tests__/engine/function/system/array/DeleteLastTest.ts +10 -10
  9. package/__tests__/engine/function/system/array/DeleteTest.ts +60 -25
  10. package/__tests__/engine/function/system/array/DisjointTest.ts +6 -7
  11. package/__tests__/engine/function/system/array/Equals.ts +5 -5
  12. package/__tests__/engine/function/system/array/FillTest.ts +5 -5
  13. package/__tests__/engine/function/system/array/FrequencyTest.ts +11 -11
  14. package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +14 -20
  15. package/__tests__/engine/function/system/array/IndexOfTest.ts +26 -14
  16. package/__tests__/engine/function/system/array/InsertTest.ts +12 -12
  17. package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +9 -12
  18. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +16 -16
  19. package/__tests__/engine/function/system/array/MaxTest.ts +18 -18
  20. package/__tests__/engine/function/system/array/MinTest.ts +18 -18
  21. package/__tests__/engine/function/system/array/MisMatchTest.ts +8 -11
  22. package/__tests__/engine/function/system/array/ReverseTest.ts +12 -12
  23. package/__tests__/engine/function/system/array/RotateTest.ts +6 -6
  24. package/__tests__/engine/function/system/array/ShuffleTest.ts +7 -4
  25. package/__tests__/engine/function/system/array/SortTest.ts +10 -10
  26. package/__tests__/engine/function/system/array/SubArrayTest.ts +19 -10
  27. package/__tests__/engine/function/system/context/SetFunctionTest.ts +24 -5
  28. package/__tests__/engine/function/system/math/AddTest.ts +2 -2
  29. package/__tests__/engine/function/system/math/RandomIntTest.ts +46 -0
  30. package/__tests__/engine/function/system/string/ConcatenateTest.ts +4 -4
  31. package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +8 -4
  32. package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +6 -6
  33. package/__tests__/engine/function/system/string/PostPadTest.ts +6 -6
  34. package/__tests__/engine/function/system/string/PrePadTest.ts +8 -8
  35. package/__tests__/engine/function/system/string/RegionMatchesTest.ts +15 -6
  36. package/__tests__/engine/function/system/string/ReverseTest.ts +6 -6
  37. package/__tests__/engine/function/system/string/SplitTest.ts +8 -4
  38. package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +35 -11
  39. package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +14 -5
  40. package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +40 -16
  41. package/__tests__/engine/function/system/string/ToStringTest.ts +6 -6
  42. package/__tests__/engine/function/system/string/TrimToTest.ts +8 -6
  43. package/__tests__/engine/runtime/KIRuntimeTest.ts +148 -155
  44. package/__tests__/engine/runtime/KIRuntimeWithDefinitionTest.ts +89 -0
  45. package/__tests__/engine/util/LinkedListTest.ts +9 -0
  46. package/dist/index.js +1 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/module.js +1 -1
  49. package/dist/module.js.map +1 -1
  50. package/dist/types.d.ts +267 -109
  51. package/dist/types.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/engine/function/AbstractFunction.ts +5 -3
  54. package/src/engine/function/Function.ts +1 -1
  55. package/src/engine/function/system/GenerateEvent.ts +1 -1
  56. package/src/engine/function/system/If.ts +1 -1
  57. package/src/engine/function/system/array/AbstractArrayFunction.ts +5 -0
  58. package/src/engine/function/system/array/Add.ts +1 -1
  59. package/src/engine/function/system/array/AddFirst.ts +1 -1
  60. package/src/engine/function/system/array/BinarySearch.ts +1 -1
  61. package/src/engine/function/system/array/Compare.ts +1 -1
  62. package/src/engine/function/system/array/Copy.ts +1 -1
  63. package/src/engine/function/system/array/Delete.ts +24 -32
  64. package/src/engine/function/system/array/DeleteFirst.ts +1 -1
  65. package/src/engine/function/system/array/DeleteFrom.ts +1 -1
  66. package/src/engine/function/system/array/DeleteLast.ts +1 -1
  67. package/src/engine/function/system/array/Disjoint.ts +1 -1
  68. package/src/engine/function/system/array/Equals.ts +2 -2
  69. package/src/engine/function/system/array/Fill.ts +1 -1
  70. package/src/engine/function/system/array/Frequency.ts +1 -1
  71. package/src/engine/function/system/array/IndexOf.ts +1 -1
  72. package/src/engine/function/system/array/IndexOfArray.ts +1 -1
  73. package/src/engine/function/system/array/Insert.ts +1 -1
  74. package/src/engine/function/system/array/LastIndexOf.ts +1 -1
  75. package/src/engine/function/system/array/LastIndexOfArray.ts +1 -1
  76. package/src/engine/function/system/array/Max.ts +1 -1
  77. package/src/engine/function/system/array/Min.ts +1 -1
  78. package/src/engine/function/system/array/MisMatch.ts +1 -1
  79. package/src/engine/function/system/array/Reverse.ts +1 -1
  80. package/src/engine/function/system/array/Rotate.ts +1 -1
  81. package/src/engine/function/system/array/Shuffle.ts +1 -1
  82. package/src/engine/function/system/array/Sort.ts +1 -1
  83. package/src/engine/function/system/array/SubArray.ts +1 -1
  84. package/src/engine/function/system/context/Create.ts +1 -1
  85. package/src/engine/function/system/context/Get.ts +1 -1
  86. package/src/engine/function/system/context/SetFunction.ts +1 -1
  87. package/src/engine/function/system/loop/CountLoop.ts +1 -1
  88. package/src/engine/function/system/loop/RangeLoop.ts +1 -1
  89. package/src/engine/function/system/math/Add.ts +2 -4
  90. package/src/engine/function/system/math/GenericMathFunction.ts +2 -4
  91. package/src/engine/function/system/math/Hypotenuse.ts +2 -6
  92. package/src/engine/function/system/math/Maximum.ts +2 -4
  93. package/src/engine/function/system/math/Minimum.ts +2 -4
  94. package/src/engine/function/system/math/Random.ts +1 -1
  95. package/src/engine/function/system/math/RandomFloat.ts +56 -0
  96. package/src/engine/function/system/math/RandomInt.ts +56 -0
  97. package/src/engine/function/system/string/AbstractStringFunction.ts +24 -8
  98. package/src/engine/function/system/string/Concatenate.ts +2 -2
  99. package/src/engine/function/system/string/DeleteForGivenLength.ts +25 -15
  100. package/src/engine/function/system/string/InsertAtGivenPosition.ts +17 -7
  101. package/src/engine/function/system/string/PostPad.ts +20 -10
  102. package/src/engine/function/system/string/PrePad.ts +17 -7
  103. package/src/engine/function/system/string/RegionMatches.ts +40 -22
  104. package/src/engine/function/system/string/ReplaceAtGivenPosition.ts +26 -13
  105. package/src/engine/function/system/string/Reverse.ts +4 -3
  106. package/src/engine/function/system/string/Split.ts +13 -4
  107. package/src/engine/function/system/string/ToString.ts +9 -5
  108. package/src/engine/function/system/string/TrimTo.ts +13 -6
  109. package/src/engine/json/schema/Schema.ts +1 -0
  110. package/src/engine/model/Event.ts +15 -0
  111. package/src/engine/model/FunctionDefinition.ts +76 -29
  112. package/src/engine/model/Parameter.ts +11 -0
  113. package/src/engine/model/ParameterReference.ts +8 -1
  114. package/src/engine/model/Position.ts +5 -0
  115. package/src/engine/model/Statement.ts +16 -0
  116. package/src/engine/model/StatementGroup.ts +7 -0
  117. package/src/engine/runtime/KIRuntime.ts +26 -24
  118. package/src/index.ts +71 -20
@@ -18,22 +18,35 @@ export class ReplaceAtGivenPosition extends AbstractFunction {
18
18
 
19
19
  protected static readonly EVENT_RESULT_NAME: string = 'result';
20
20
 
21
- protected static PARAMETER_STRING: Parameter =new Parameter(ReplaceAtGivenPosition.PARAMETER_STRING_NAME,Schema.ofString(ReplaceAtGivenPosition.PARAMETER_STRING_NAME));
21
+ protected static PARAMETER_STRING: Parameter = new Parameter(
22
+ ReplaceAtGivenPosition.PARAMETER_STRING_NAME,
23
+ Schema.ofString(ReplaceAtGivenPosition.PARAMETER_STRING_NAME),
24
+ );
22
25
 
23
- protected static PARAMETER_AT_START: Parameter =new Parameter(ReplaceAtGivenPosition.PARAMETER_AT_START_NAME,Schema.ofInteger(ReplaceAtGivenPosition.PARAMETER_AT_START_NAME));
26
+ protected static PARAMETER_AT_START: Parameter = new Parameter(
27
+ ReplaceAtGivenPosition.PARAMETER_AT_START_NAME,
28
+ Schema.ofInteger(ReplaceAtGivenPosition.PARAMETER_AT_START_NAME),
29
+ );
24
30
 
25
- protected static PARAMETER_AT_LENGTH: Parameter =new Parameter(ReplaceAtGivenPosition.PARAMETER_AT_LENGTH_NAME,Schema.ofInteger(ReplaceAtGivenPosition.PARAMETER_AT_LENGTH_NAME));
31
+ protected static PARAMETER_AT_LENGTH: Parameter = new Parameter(
32
+ ReplaceAtGivenPosition.PARAMETER_AT_LENGTH_NAME,
33
+ Schema.ofInteger(ReplaceAtGivenPosition.PARAMETER_AT_LENGTH_NAME),
34
+ );
26
35
 
27
- protected static PARAMETER_REPLACE_STRING: Parameter =new Parameter(ReplaceAtGivenPosition.PARAMETER_REPLACE_STRING_NAME,Schema.ofString(ReplaceAtGivenPosition.PARAMETER_REPLACE_STRING_NAME));
36
+ protected static PARAMETER_REPLACE_STRING: Parameter = new Parameter(
37
+ ReplaceAtGivenPosition.PARAMETER_REPLACE_STRING_NAME,
38
+ Schema.ofString(ReplaceAtGivenPosition.PARAMETER_REPLACE_STRING_NAME),
39
+ );
28
40
 
29
- protected static EVENT_STRING: Event =new Event(Event.OUTPUT,
30
- new Map([
31
- [
32
- ReplaceAtGivenPosition.EVENT_RESULT_NAME,
33
- Schema.ofString(ReplaceAtGivenPosition.EVENT_RESULT_NAME),
34
- ],
35
- ]),
36
- );
41
+ protected static EVENT_STRING: Event = new Event(
42
+ Event.OUTPUT,
43
+ new Map([
44
+ [
45
+ ReplaceAtGivenPosition.EVENT_RESULT_NAME,
46
+ Schema.ofString(ReplaceAtGivenPosition.EVENT_RESULT_NAME),
47
+ ],
48
+ ]),
49
+ );
37
50
 
38
51
  private signature: FunctionSignature = new FunctionSignature('ReplaceAtGivenPosition')
39
52
  .setNamespace(Namespaces.STRING)
@@ -70,7 +83,7 @@ export class ReplaceAtGivenPosition extends AbstractFunction {
70
83
  return this.signature;
71
84
  }
72
85
 
73
- protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
86
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
74
87
  let inputString: string = context
75
88
  ?.getArguments()
76
89
  ?.get(ReplaceAtGivenPosition.PARAMETER_STRING_NAME);
@@ -20,8 +20,9 @@ export class Reverse extends AbstractFunction {
20
20
  new Map([
21
21
  [
22
22
  this.VALUE,
23
- new Parameter(this.VALUE,Schema.ofString(this.VALUE))
24
- .setVariableArgument(true),
23
+ new Parameter(this.VALUE, Schema.ofString(this.VALUE)).setVariableArgument(
24
+ true,
25
+ ),
25
26
  ],
26
27
  ]),
27
28
  )
@@ -48,7 +49,7 @@ export class Reverse extends AbstractFunction {
48
49
  return this.SIGNATURE;
49
50
  }
50
51
 
51
- protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
52
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
52
53
  let acutalString: string = context.getArguments()?.get(this.VALUE);
53
54
  let stringLength: number = acutalString.length - 1;
54
55
  let reversedString: string = '';
@@ -14,11 +14,20 @@ export class Split extends AbstractFunction {
14
14
  protected readonly PARAMETER_SPLIT_STRING_NAME: string = 'searchString';
15
15
  protected readonly EVENT_RESULT_NAME: string = 'result';
16
16
 
17
- protected readonly PARAMETER_STRING: Parameter =new Parameter(this.PARAMETER_STRING_NAME,Schema.ofString(this.PARAMETER_STRING_NAME));
17
+ protected readonly PARAMETER_STRING: Parameter = new Parameter(
18
+ this.PARAMETER_STRING_NAME,
19
+ Schema.ofString(this.PARAMETER_STRING_NAME),
20
+ );
18
21
 
19
- protected readonly PARAMETER_SPLIT_STRING: Parameter =new Parameter(this.PARAMETER_SPLIT_STRING_NAME,Schema.ofString(this.PARAMETER_SPLIT_STRING_NAME));
22
+ protected readonly PARAMETER_SPLIT_STRING: Parameter = new Parameter(
23
+ this.PARAMETER_SPLIT_STRING_NAME,
24
+ Schema.ofString(this.PARAMETER_SPLIT_STRING_NAME),
25
+ );
20
26
 
21
- protected readonly EVENT_ARRAY: Event =new Event(Event.OUTPUT,MapUtil.of(this.EVENT_RESULT_NAME, Schema.ofArray(this.EVENT_RESULT_NAME)));
27
+ protected readonly EVENT_ARRAY: Event = new Event(
28
+ Event.OUTPUT,
29
+ MapUtil.of(this.EVENT_RESULT_NAME, Schema.ofArray(this.EVENT_RESULT_NAME)),
30
+ );
22
31
 
23
32
  public getSignature(): FunctionSignature {
24
33
  return new FunctionSignature('Split')
@@ -42,7 +51,7 @@ export class Split extends AbstractFunction {
42
51
  super();
43
52
  }
44
53
 
45
- protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
54
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
46
55
  let s1: string = context.getArguments()?.get(this.PARAMETER_STRING_NAME);
47
56
  let s2: string = context.getArguments()?.get(this.PARAMETER_SPLIT_STRING_NAME);
48
57
 
@@ -13,11 +13,15 @@ export class ToString extends AbstractFunction {
13
13
 
14
14
  protected readonly EVENT_RESULT_NAME: string = 'result';
15
15
 
16
- protected readonly PARAMETER_INPUT_ANYTYPE: Parameter =new Parameter(this.PARAMETER_INPUT_ANYTYPE_NAME,Schema.ofAny(this.PARAMETER_INPUT_ANYTYPE_NAME));
16
+ protected readonly PARAMETER_INPUT_ANYTYPE: Parameter = new Parameter(
17
+ this.PARAMETER_INPUT_ANYTYPE_NAME,
18
+ Schema.ofAny(this.PARAMETER_INPUT_ANYTYPE_NAME),
19
+ );
17
20
 
18
- protected readonly EVENT_STRING: Event =new Event(Event.OUTPUT,
19
- new Map([[this.EVENT_RESULT_NAME, Schema.ofString(this.EVENT_RESULT_NAME)]]),
20
- );
21
+ protected readonly EVENT_STRING: Event = new Event(
22
+ Event.OUTPUT,
23
+ new Map([[this.EVENT_RESULT_NAME, Schema.ofString(this.EVENT_RESULT_NAME)]]),
24
+ );
21
25
 
22
26
  public getSignature(): FunctionSignature {
23
27
  return new FunctionSignature('ToString')
@@ -34,7 +38,7 @@ export class ToString extends AbstractFunction {
34
38
  super();
35
39
  }
36
40
 
37
- protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
41
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
38
42
  let input: any = context.getArguments()?.get(this.PARAMETER_INPUT_ANYTYPE_NAME);
39
43
  let output: string = input + '';
40
44
 
@@ -15,13 +15,20 @@ export class TrimTo extends AbstractFunction {
15
15
 
16
16
  public static readonly EVENT_RESULT_NAME: string = 'result';
17
17
 
18
- protected static readonly PARAMETER_STRING: Parameter =new Parameter(TrimTo.PARAMETER_STRING_NAME,Schema.ofString(TrimTo.PARAMETER_STRING_NAME));
18
+ protected static readonly PARAMETER_STRING: Parameter = new Parameter(
19
+ TrimTo.PARAMETER_STRING_NAME,
20
+ Schema.ofString(TrimTo.PARAMETER_STRING_NAME),
21
+ );
19
22
 
20
- protected static readonly PARAMETER_LENGTH: Parameter =new Parameter(TrimTo.PARAMETER_LENGTH_NAME,Schema.ofInteger(TrimTo.PARAMETER_LENGTH_NAME));
23
+ protected static readonly PARAMETER_LENGTH: Parameter = new Parameter(
24
+ TrimTo.PARAMETER_LENGTH_NAME,
25
+ Schema.ofInteger(TrimTo.PARAMETER_LENGTH_NAME),
26
+ );
21
27
 
22
- protected static readonly EVENT_STRING: Event =new Event(Event.OUTPUT,
23
- new Map([[TrimTo.EVENT_RESULT_NAME, Schema.ofString(TrimTo.EVENT_RESULT_NAME)]]),
24
- );
28
+ protected static readonly EVENT_STRING: Event = new Event(
29
+ Event.OUTPUT,
30
+ new Map([[TrimTo.EVENT_RESULT_NAME, Schema.ofString(TrimTo.EVENT_RESULT_NAME)]]),
31
+ );
25
32
 
26
33
  private signature: FunctionSignature = new FunctionSignature('TrimTo')
27
34
  .setNamespace(Namespaces.STRING)
@@ -41,7 +48,7 @@ export class TrimTo extends AbstractFunction {
41
48
  super();
42
49
  }
43
50
 
44
- protected internalExecute(context: FunctionExecutionParameters): FunctionOutput {
51
+ protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
45
52
  let inputString: string = context.getArguments()?.get(TrimTo.PARAMETER_STRING_NAME);
46
53
  let length: number = context.getArguments()?.get(TrimTo.PARAMETER_LENGTH_NAME);
47
54
 
@@ -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';
@@ -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
- private static readonly SCHEMA_NAME1: string = 'FunctionDefinition';
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
  }
@@ -37,4 +37,9 @@ export class Position {
37
37
  this.top = top;
38
38
  return this;
39
39
  }
40
+
41
+ public static from(json: any): Position {
42
+ if (!json) return new Position(-1, -1);
43
+ return new Position(json.left, json.top);
44
+ }
40
45
  }
@@ -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
  }
@@ -72,9 +72,9 @@ export class KIRuntime extends AbstractFunction {
72
72
  return this.fd;
73
73
  }
74
74
 
75
- private getExecutionPlan(
75
+ private async getExecutionPlan(
76
76
  context: Map<string, ContextElement>,
77
- ): ExecutionGraph<string, StatementExecution> {
77
+ ): Promise<ExecutionGraph<string, StatementExecution>> {
78
78
  let g: ExecutionGraph<string, StatementExecution> = new ExecutionGraph();
79
79
  for (let s of Array.from(this.fd.getSteps().values()))
80
80
  g.addVertex(this.prepareStatementExecution(context, s));
@@ -95,14 +95,16 @@ export class KIRuntime extends AbstractFunction {
95
95
  return g;
96
96
  }
97
97
 
98
- protected internalExecute(inContext: FunctionExecutionParameters): FunctionOutput {
98
+ protected async internalExecute(
99
+ inContext: FunctionExecutionParameters,
100
+ ): Promise<FunctionOutput> {
99
101
  if (!inContext.getContext()) inContext.setContext(new Map());
100
102
 
101
103
  if (!inContext.getEvents()) inContext.setEvents(new Map());
102
104
 
103
105
  if (!inContext.getSteps()) inContext.setSteps(new Map());
104
106
 
105
- let eGraph: ExecutionGraph<string, StatementExecution> = this.getExecutionPlan(
107
+ let eGraph: ExecutionGraph<string, StatementExecution> = await this.getExecutionPlan(
106
108
  inContext.getContext()!,
107
109
  );
108
110
 
@@ -123,13 +125,13 @@ export class KIRuntime extends AbstractFunction {
123
125
  );
124
126
  }
125
127
 
126
- return this.executeGraph(eGraph, inContext);
128
+ return await this.executeGraph(eGraph, inContext);
127
129
  }
128
130
 
129
- private executeGraph(
131
+ private async executeGraph(
130
132
  eGraph: ExecutionGraph<string, StatementExecution>,
131
133
  inContext: FunctionExecutionParameters,
132
- ): FunctionOutput {
134
+ ): Promise<FunctionOutput> {
133
135
  let executionQue: LinkedList<GraphVertex<string, StatementExecution>> = new LinkedList();
134
136
  executionQue.addAll(eGraph.getVerticesWithNoIncomingEdges());
135
137
 
@@ -146,8 +148,8 @@ export class KIRuntime extends AbstractFunction {
146
148
  (!executionQue.isEmpty() || !branchQue.isEmpty()) &&
147
149
  !inContext.getEvents()?.has(Event.OUTPUT)
148
150
  ) {
149
- this.processBranchQue(inContext, executionQue, branchQue);
150
- this.processExecutionQue(inContext, executionQue, branchQue);
151
+ await this.processBranchQue(inContext, executionQue, branchQue);
152
+ await this.processExecutionQue(inContext, executionQue, branchQue);
151
153
 
152
154
  inContext.setCount(inContext.getCount() + 1);
153
155
 
@@ -166,7 +168,7 @@ export class KIRuntime extends AbstractFunction {
166
168
  );
167
169
  }
168
170
 
169
- private processExecutionQue(
171
+ private async processExecutionQue(
170
172
  inContext: FunctionExecutionParameters,
171
173
  executionQue: LinkedList<GraphVertex<string, StatementExecution>>,
172
174
  branchQue: LinkedList<
@@ -177,17 +179,17 @@ export class KIRuntime extends AbstractFunction {
177
179
  GraphVertex<string, StatementExecution>
178
180
  >
179
181
  >,
180
- ): void {
182
+ ) {
181
183
  if (!executionQue.isEmpty()) {
182
184
  let vertex: GraphVertex<string, StatementExecution> = executionQue.pop();
183
185
 
184
- if (!this.allDependenciesResolvedVertex(vertex, inContext.getSteps()!))
186
+ if (!(await this.allDependenciesResolvedVertex(vertex, inContext.getSteps()!)))
185
187
  executionQue.add(vertex);
186
- else this.executeVertex(vertex, inContext, branchQue, executionQue);
188
+ else await this.executeVertex(vertex, inContext, branchQue, executionQue);
187
189
  }
188
190
  }
189
191
 
190
- private processBranchQue(
192
+ private async processBranchQue(
191
193
  inContext: FunctionExecutionParameters,
192
194
  executionQue: LinkedList<GraphVertex<string, StatementExecution>>,
193
195
  branchQue: LinkedList<
@@ -198,7 +200,7 @@ export class KIRuntime extends AbstractFunction {
198
200
  GraphVertex<string, StatementExecution>
199
201
  >
200
202
  >,
201
- ): void {
203
+ ) {
202
204
  if (branchQue.length) {
203
205
  let branch: Tuple4<
204
206
  ExecutionGraph<string, StatementExecution>,
@@ -207,13 +209,13 @@ export class KIRuntime extends AbstractFunction {
207
209
  GraphVertex<string, StatementExecution>
208
210
  > = branchQue.pop();
209
211
 
210
- if (!this.allDependenciesResolvedTuples(branch.getT2(), inContext.getSteps()!))
212
+ if (!(await this.allDependenciesResolvedTuples(branch.getT2(), inContext.getSteps()!)))
211
213
  branchQue.add(branch);
212
- else this.executeBranch(inContext, executionQue, branch);
214
+ else await this.executeBranch(inContext, executionQue, branch);
213
215
  }
214
216
  }
215
217
 
216
- private executeBranch(
218
+ private async executeBranch(
217
219
  inContext: FunctionExecutionParameters,
218
220
  executionQue: LinkedList<GraphVertex<string, StatementExecution>>,
219
221
  branch: Tuple4<
@@ -222,12 +224,12 @@ export class KIRuntime extends AbstractFunction {
222
224
  FunctionOutput,
223
225
  GraphVertex<string, StatementExecution>
224
226
  >,
225
- ): void {
227
+ ) {
226
228
  let vertex: GraphVertex<string, StatementExecution> = branch.getT4();
227
229
  let nextOutput: EventResult | undefined = undefined;
228
230
 
229
231
  do {
230
- this.executeGraph(branch.getT1(), inContext);
232
+ await this.executeGraph(branch.getT1(), inContext);
231
233
  nextOutput = branch.getT3().next();
232
234
 
233
235
  if (nextOutput) {
@@ -241,7 +243,7 @@ export class KIRuntime extends AbstractFunction {
241
243
  ?.get(vertex.getData().getStatement().getStatementName())
242
244
  ?.set(
243
245
  nextOutput.getName(),
244
- this.resolveInternalExpressions(nextOutput.getResult(), inContext),
246
+ await this.resolveInternalExpressions(nextOutput.getResult(), inContext),
245
247
  );
246
248
  }
247
249
  } while (nextOutput && nextOutput.getName() != Event.OUTPUT);
@@ -251,7 +253,7 @@ export class KIRuntime extends AbstractFunction {
251
253
  }
252
254
  }
253
255
 
254
- private executeVertex(
256
+ private async executeVertex(
255
257
  vertex: GraphVertex<string, StatementExecution>,
256
258
  inContext: FunctionExecutionParameters,
257
259
  branchQue: LinkedList<
@@ -263,7 +265,7 @@ export class KIRuntime extends AbstractFunction {
263
265
  >
264
266
  >,
265
267
  executionQue: LinkedList<GraphVertex<string, StatementExecution>>,
266
- ): void {
268
+ ) {
267
269
  let s: Statement = vertex.getData().getStatement();
268
270
 
269
271
  let fun: Function | undefined = this.fRepo.find(s.getNamespace(), s.getName());
@@ -284,7 +286,7 @@ export class KIRuntime extends AbstractFunction {
284
286
 
285
287
  let context: Map<string, ContextElement> = inContext.getContext()!;
286
288
 
287
- let result: FunctionOutput = fun.execute(
289
+ let result: FunctionOutput = await fun.execute(
288
290
  new FunctionExecutionParameters()
289
291
  .setContext(context)
290
292
  .setArguments(args)