@fincity/kirun-js 1.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.
Files changed (217) hide show
  1. package/.prettierrc +9 -0
  2. package/__tests__/engine/function/system/array/AddFirstTest.ts +235 -0
  3. package/__tests__/engine/function/system/array/AddTest.ts +126 -0
  4. package/__tests__/engine/function/system/array/BinarySearchTest.ts +135 -0
  5. package/__tests__/engine/function/system/array/CompareTest.ts +48 -0
  6. package/__tests__/engine/function/system/array/CopyTest.ts +86 -0
  7. package/__tests__/engine/function/system/array/DeleteFirstTest.ts +103 -0
  8. package/__tests__/engine/function/system/array/DeleteFromTest.ts +232 -0
  9. package/__tests__/engine/function/system/array/DeleteLastTest.ts +103 -0
  10. package/__tests__/engine/function/system/array/DeleteTest.ts +110 -0
  11. package/__tests__/engine/function/system/array/DisjointTest.ts +184 -0
  12. package/__tests__/engine/function/system/array/Equals.ts +67 -0
  13. package/__tests__/engine/function/system/array/FillTest.ts +36 -0
  14. package/__tests__/engine/function/system/array/FrequencyTest.ts +97 -0
  15. package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +347 -0
  16. package/__tests__/engine/function/system/array/IndexOfTest.ts +267 -0
  17. package/__tests__/engine/function/system/array/InsertTest.ts +229 -0
  18. package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +213 -0
  19. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +253 -0
  20. package/__tests__/engine/function/system/array/MaxTest.ts +98 -0
  21. package/__tests__/engine/function/system/array/MinTest.ts +99 -0
  22. package/__tests__/engine/function/system/array/MisMatchTest.ts +215 -0
  23. package/__tests__/engine/function/system/array/ReverseTest.ts +235 -0
  24. package/__tests__/engine/function/system/array/RotateTest.ts +137 -0
  25. package/__tests__/engine/function/system/array/ShuffleTest.ts +154 -0
  26. package/__tests__/engine/function/system/array/SortTest.ts +130 -0
  27. package/__tests__/engine/function/system/array/SubArrayTest.ts +236 -0
  28. package/__tests__/engine/function/system/math/AddTest.ts +12 -0
  29. package/__tests__/engine/function/system/string/ConcatenateTest.ts +46 -0
  30. package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +38 -0
  31. package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +53 -0
  32. package/__tests__/engine/function/system/string/PostPadTest.ts +54 -0
  33. package/__tests__/engine/function/system/string/PrePadTest.ts +54 -0
  34. package/__tests__/engine/function/system/string/RegionMatchesTest.ts +78 -0
  35. package/__tests__/engine/function/system/string/ReverseTest.ts +36 -0
  36. package/__tests__/engine/function/system/string/SplitTest.ts +61 -0
  37. package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +126 -0
  38. package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +54 -0
  39. package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +146 -0
  40. package/__tests__/engine/function/system/string/ToStringTest.ts +43 -0
  41. package/__tests__/engine/function/system/string/TrimToTest.ts +28 -0
  42. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +26 -0
  43. package/__tests__/engine/runtime/KIRuntimeTest.ts +351 -0
  44. package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +128 -0
  45. package/__tests__/engine/runtime/expression/ExpressionTest.ts +33 -0
  46. package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +44 -0
  47. package/__tests__/engine/runtime/expression/tokenextractor/TokenValueExtractorTest.ts +72 -0
  48. package/__tests__/engine/util/LinkedListTest.ts +29 -0
  49. package/__tests__/engine/util/string/StringFormatterTest.ts +17 -0
  50. package/__tests__/indexTest.ts +33 -0
  51. package/dist/index.js +2 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/module.js +2 -0
  54. package/dist/module.js.map +1 -0
  55. package/dist/types.d.ts +430 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/package.json +54 -0
  58. package/src/engine/HybridRepository.ts +18 -0
  59. package/src/engine/Repository.ts +3 -0
  60. package/src/engine/constant/KIRunConstants.ts +7 -0
  61. package/src/engine/exception/ExecutionException.ts +12 -0
  62. package/src/engine/exception/KIRuntimeException.ts +12 -0
  63. package/src/engine/function/AbstractFunction.ts +76 -0
  64. package/src/engine/function/Function.ts +13 -0
  65. package/src/engine/function/system/GenerateEvent.ts +76 -0
  66. package/src/engine/function/system/If.ts +40 -0
  67. package/src/engine/function/system/array/AbstractArrayFunction.ts +158 -0
  68. package/src/engine/function/system/array/Add.ts +31 -0
  69. package/src/engine/function/system/array/AddFirst.ts +44 -0
  70. package/src/engine/function/system/array/BinarySearch.ts +66 -0
  71. package/src/engine/function/system/array/Compare.ts +150 -0
  72. package/src/engine/function/system/array/Copy.ts +56 -0
  73. package/src/engine/function/system/array/Delete.ts +63 -0
  74. package/src/engine/function/system/array/DeleteFirst.ts +22 -0
  75. package/src/engine/function/system/array/DeleteFrom.ts +51 -0
  76. package/src/engine/function/system/array/DeleteLast.ts +23 -0
  77. package/src/engine/function/system/array/Disjoint.ts +85 -0
  78. package/src/engine/function/system/array/Equals.ts +36 -0
  79. package/src/engine/function/system/array/Fill.ts +51 -0
  80. package/src/engine/function/system/array/Frequency.ts +68 -0
  81. package/src/engine/function/system/array/IndexOf.ts +56 -0
  82. package/src/engine/function/system/array/IndexOfArray.ts +67 -0
  83. package/src/engine/function/system/array/Insert.ts +48 -0
  84. package/src/engine/function/system/array/LastIndexOf.ts +62 -0
  85. package/src/engine/function/system/array/LastIndexOfArray.ts +70 -0
  86. package/src/engine/function/system/array/Max.ts +31 -0
  87. package/src/engine/function/system/array/Min.ts +32 -0
  88. package/src/engine/function/system/array/MisMatch.ts +66 -0
  89. package/src/engine/function/system/array/Reverse.ts +50 -0
  90. package/src/engine/function/system/array/Rotate.ts +43 -0
  91. package/src/engine/function/system/array/Shuffle.ts +31 -0
  92. package/src/engine/function/system/array/Sort.ts +70 -0
  93. package/src/engine/function/system/array/SubArray.ts +48 -0
  94. package/src/engine/function/system/context/Create.ts +73 -0
  95. package/src/engine/function/system/context/Get.ts +55 -0
  96. package/src/engine/function/system/context/SetFunction.ts +244 -0
  97. package/src/engine/function/system/loop/CountLoop.ts +55 -0
  98. package/src/engine/function/system/loop/RangeLoop.ts +120 -0
  99. package/src/engine/function/system/math/Add.ts +34 -0
  100. package/src/engine/function/system/math/GenericMathFunction.ts +80 -0
  101. package/src/engine/function/system/math/Hypotenuse.ts +57 -0
  102. package/src/engine/function/system/math/MathFunctionRepository.ts +63 -0
  103. package/src/engine/function/system/math/Maximum.ts +38 -0
  104. package/src/engine/function/system/math/Minimum.ts +38 -0
  105. package/src/engine/function/system/math/Random.ts +27 -0
  106. package/src/engine/function/system/string/AbstractStringFunction.ts +409 -0
  107. package/src/engine/function/system/string/Concatenate.ts +57 -0
  108. package/src/engine/function/system/string/DeleteForGivenLength.ts +82 -0
  109. package/src/engine/function/system/string/InsertAtGivenPosition.ts +72 -0
  110. package/src/engine/function/system/string/PostPad.ts +83 -0
  111. package/src/engine/function/system/string/PrePad.ts +73 -0
  112. package/src/engine/function/system/string/RegionMatches.ts +119 -0
  113. package/src/engine/function/system/string/ReplaceAtGivenPosition.ts +101 -0
  114. package/src/engine/function/system/string/Reverse.ts +62 -0
  115. package/src/engine/function/system/string/Split.ts +53 -0
  116. package/src/engine/function/system/string/StringFunctionRepository.ts +60 -0
  117. package/src/engine/function/system/string/ToString.ts +45 -0
  118. package/src/engine/function/system/string/TrimTo.ts +55 -0
  119. package/src/engine/json/JsonExpression.ts +11 -0
  120. package/src/engine/json/schema/Schema.ts +670 -0
  121. package/src/engine/json/schema/SchemaUtil.ts +145 -0
  122. package/src/engine/json/schema/array/ArraySchemaType.ts +44 -0
  123. package/src/engine/json/schema/object/AdditionalPropertiesType.ts +32 -0
  124. package/src/engine/json/schema/string/StringFormat.ts +7 -0
  125. package/src/engine/json/schema/type/MultipleType.ts +28 -0
  126. package/src/engine/json/schema/type/SchemaType.ts +11 -0
  127. package/src/engine/json/schema/type/SingleType.ts +23 -0
  128. package/src/engine/json/schema/type/Type.ts +6 -0
  129. package/src/engine/json/schema/type/TypeUtil.ts +25 -0
  130. package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +108 -0
  131. package/src/engine/json/schema/validator/ArrayValidator.ts +145 -0
  132. package/src/engine/json/schema/validator/BooleanValidator.ts +24 -0
  133. package/src/engine/json/schema/validator/NullValidator.ts +17 -0
  134. package/src/engine/json/schema/validator/NumberValidator.ts +115 -0
  135. package/src/engine/json/schema/validator/ObjectValidator.ts +184 -0
  136. package/src/engine/json/schema/validator/SchemaValidator.ts +141 -0
  137. package/src/engine/json/schema/validator/StringValidator.ts +97 -0
  138. package/src/engine/json/schema/validator/TypeValidator.ts +49 -0
  139. package/src/engine/json/schema/validator/exception/SchemaReferenceException.ts +19 -0
  140. package/src/engine/json/schema/validator/exception/SchemaValidationException.ts +22 -0
  141. package/src/engine/model/AbstractStatement.ts +29 -0
  142. package/src/engine/model/Argument.ts +36 -0
  143. package/src/engine/model/Event.ts +62 -0
  144. package/src/engine/model/EventResult.ts +34 -0
  145. package/src/engine/model/FunctionDefinition.ts +69 -0
  146. package/src/engine/model/FunctionOutput.ts +37 -0
  147. package/src/engine/model/FunctionOutputGenerator.ts +5 -0
  148. package/src/engine/model/FunctionSignature.ts +67 -0
  149. package/src/engine/model/Parameter.ts +97 -0
  150. package/src/engine/model/ParameterReference.ts +57 -0
  151. package/src/engine/model/ParameterReferenceType.ts +4 -0
  152. package/src/engine/model/ParameterType.ts +4 -0
  153. package/src/engine/model/Position.ts +40 -0
  154. package/src/engine/model/Statement.ts +101 -0
  155. package/src/engine/model/StatementGroup.ts +37 -0
  156. package/src/engine/namespaces/Namespaces.ts +11 -0
  157. package/src/engine/repository/KIRunFunctionRepository.ts +37 -0
  158. package/src/engine/repository/KIRunSchemaRepository.ts +24 -0
  159. package/src/engine/runtime/ContextElement.ts +28 -0
  160. package/src/engine/runtime/FunctionExecutionParameters.ts +74 -0
  161. package/src/engine/runtime/KIRuntime.ts +653 -0
  162. package/src/engine/runtime/StatementExecution.ts +61 -0
  163. package/src/engine/runtime/StatementMessage.ts +30 -0
  164. package/src/engine/runtime/StatementMessageType.ts +5 -0
  165. package/src/engine/runtime/expression/Expression.ts +330 -0
  166. package/src/engine/runtime/expression/ExpressionEvaluator.ts +305 -0
  167. package/src/engine/runtime/expression/ExpressionToken.ts +15 -0
  168. package/src/engine/runtime/expression/ExpressionTokenValue.ts +23 -0
  169. package/src/engine/runtime/expression/Operation.ts +190 -0
  170. package/src/engine/runtime/expression/exception/ExpressionEvaluationException.ts +15 -0
  171. package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +9 -0
  172. package/src/engine/runtime/expression/operators/binary/ArithmeticDivisionOperator.ts +9 -0
  173. package/src/engine/runtime/expression/operators/binary/ArithmeticInetgerDivisionOperator.ts +9 -0
  174. package/src/engine/runtime/expression/operators/binary/ArithmeticModulusOperator.ts +9 -0
  175. package/src/engine/runtime/expression/operators/binary/ArithmeticMultiplicationOperator.ts +9 -0
  176. package/src/engine/runtime/expression/operators/binary/ArithmeticSubtractionOperator.ts +9 -0
  177. package/src/engine/runtime/expression/operators/binary/ArrayOperator.ts +31 -0
  178. package/src/engine/runtime/expression/operators/binary/BinaryOperator.ts +15 -0
  179. package/src/engine/runtime/expression/operators/binary/BitwiseAndOperator.ts +9 -0
  180. package/src/engine/runtime/expression/operators/binary/BitwiseLeftShiftOperator.ts +9 -0
  181. package/src/engine/runtime/expression/operators/binary/BitwiseOrOperator.ts +9 -0
  182. package/src/engine/runtime/expression/operators/binary/BitwiseRightShiftOperator.ts +9 -0
  183. package/src/engine/runtime/expression/operators/binary/BitwiseUnsignedRightShiftOperator.ts +9 -0
  184. package/src/engine/runtime/expression/operators/binary/BitwiseXorOperator.ts +9 -0
  185. package/src/engine/runtime/expression/operators/binary/LogicalAndOperator.ts +25 -0
  186. package/src/engine/runtime/expression/operators/binary/LogicalEqualOperator.ts +13 -0
  187. package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanEqualOperator.ts +24 -0
  188. package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanOperator.ts +24 -0
  189. package/src/engine/runtime/expression/operators/binary/LogicalLessThanEqualOperator.ts +24 -0
  190. package/src/engine/runtime/expression/operators/binary/LogicalLessThanOperator.ts +24 -0
  191. package/src/engine/runtime/expression/operators/binary/LogicalNotEqualOperator.ts +13 -0
  192. package/src/engine/runtime/expression/operators/binary/LogicalOrOperator.ts +25 -0
  193. package/src/engine/runtime/expression/operators/binary/ObjectOperator.ts +24 -0
  194. package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryMinusOperator.ts +13 -0
  195. package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryPlusOperator.ts +13 -0
  196. package/src/engine/runtime/expression/operators/unary/BitwiseComplementOperator.ts +22 -0
  197. package/src/engine/runtime/expression/operators/unary/LogicalNotOperator.ts +22 -0
  198. package/src/engine/runtime/expression/operators/unary/UnaryOperator.ts +15 -0
  199. package/src/engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor.ts +64 -0
  200. package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +136 -0
  201. package/src/engine/runtime/graph/ExecutionGraph.ts +81 -0
  202. package/src/engine/runtime/graph/GraphVertex.ts +118 -0
  203. package/src/engine/runtime/graph/GraphVertexType.ts +4 -0
  204. package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +22 -0
  205. package/src/engine/runtime/tokenextractor/ContextTokenValueExtractor.ts +37 -0
  206. package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +32 -0
  207. package/src/engine/util/ArrayUtil.ts +23 -0
  208. package/src/engine/util/LinkedList.ts +229 -0
  209. package/src/engine/util/MapUtil.ts +86 -0
  210. package/src/engine/util/NullCheck.ts +3 -0
  211. package/src/engine/util/Tuples.ts +43 -0
  212. package/src/engine/util/primitive/PrimitiveUtil.ts +143 -0
  213. package/src/engine/util/string/StringBuilder.ts +59 -0
  214. package/src/engine/util/string/StringFormatter.ts +25 -0
  215. package/src/engine/util/string/StringUtil.ts +48 -0
  216. package/src/index.ts +13 -0
  217. package/tsconfig.json +6 -0
@@ -0,0 +1,62 @@
1
+ import { AdditionalPropertiesType } from '../json/schema/object/AdditionalPropertiesType';
2
+ import { Schema } from '../json/schema/Schema';
3
+ import { SchemaType } from '../json/schema/type/SchemaType';
4
+ import { TypeUtil } from '../json/schema/type/TypeUtil';
5
+ import { Namespaces } from '../namespaces/Namespaces';
6
+
7
+ export class Event {
8
+ public static readonly OUTPUT: string = 'output';
9
+ public static readonly ERROR: string = 'error';
10
+ public static readonly ITERATION: string = 'iteration';
11
+ public static readonly TRUE: string = 'true';
12
+ public static readonly FALSE: string = 'false';
13
+ public static readonly SCHEMA_NAME: string = 'Event';
14
+ public static readonly SCHEMA: Schema = new Schema()
15
+ .setNamespace(Namespaces.SYSTEM)
16
+ .setName(Event.SCHEMA_NAME)
17
+ .setType(TypeUtil.of(SchemaType.OBJECT))
18
+ .setProperties(
19
+ new Map([
20
+ ['name', Schema.ofString('name')],
21
+ [
22
+ 'parameters',
23
+ Schema.ofObject('parameter').setAdditionalProperties(
24
+ new AdditionalPropertiesType().setSchemaValue(Schema.SCHEMA),
25
+ ),
26
+ ],
27
+ ]),
28
+ );
29
+ private name: string;
30
+ private parameters: Map<string, Schema>;
31
+
32
+ constructor(name: string, parameters: Map<string, Schema>) {
33
+ this.name = name;
34
+ this.parameters = parameters;
35
+ }
36
+
37
+ public getName(): string {
38
+ return this.name;
39
+ }
40
+ public setName(name: string): Event {
41
+ this.name = name;
42
+ return this;
43
+ }
44
+ public getParameters(): Map<string, Schema> {
45
+ return this.parameters;
46
+ }
47
+ public setParameters(parameters: Map<string, Schema>): Event {
48
+ this.parameters = parameters;
49
+ return this;
50
+ }
51
+
52
+ public static outputEventMapEntry(parameters: Map<string, Schema>): [string, Event] {
53
+ return Event.eventMapEntry(Event.OUTPUT, parameters);
54
+ }
55
+
56
+ public static eventMapEntry(
57
+ eventName: string,
58
+ parameters: Map<string, Schema>,
59
+ ): [string, Event] {
60
+ return [eventName, new Event(eventName, parameters)];
61
+ }
62
+ }
@@ -0,0 +1,34 @@
1
+ import { Event } from './Event';
2
+
3
+ export class EventResult {
4
+ private name: string;
5
+ private result: Map<string, any>;
6
+
7
+ constructor(name: string, result: Map<string, any>) {
8
+ this.name = name;
9
+ this.result = result;
10
+ }
11
+
12
+ public getName(): string {
13
+ return this.name;
14
+ }
15
+ public setName(name: string): EventResult {
16
+ this.name = name;
17
+ return this;
18
+ }
19
+ public getResult(): Map<string, any> {
20
+ return this.result;
21
+ }
22
+ public setResult(result: Map<string, any>): EventResult {
23
+ this.result = result;
24
+ return this;
25
+ }
26
+
27
+ public static outputOf(result: Map<string, any>): EventResult {
28
+ return EventResult.of(Event.OUTPUT, result);
29
+ }
30
+
31
+ public static of(eventName: string, result: Map<string, any>): EventResult {
32
+ return new EventResult(eventName, result);
33
+ }
34
+ }
@@ -0,0 +1,69 @@
1
+ import { AdditionalPropertiesType } from '../json/schema/object/AdditionalPropertiesType';
2
+ import { Schema } from '../json/schema/Schema';
3
+ import { Namespaces } from '../namespaces/Namespaces';
4
+ import { Event } from './Event';
5
+ import { FunctionSignature } from './FunctionSignature';
6
+ import { Parameter } from './Parameter';
7
+ import { Statement } from './Statement';
8
+ import { StatementGroup } from './StatementGroup';
9
+
10
+ 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
+ );
40
+ private version: number = 1;
41
+ private steps?: Map<string, Statement>;
42
+ private stepGroups?: Map<string, StatementGroup>;
43
+
44
+ constructor(name: string) {
45
+ super(name);
46
+ }
47
+
48
+ public getVersion(): number {
49
+ return this.version;
50
+ }
51
+ public setVersion(version: number): FunctionDefinition {
52
+ this.version = version;
53
+ return this;
54
+ }
55
+ public getSteps(): Map<string, Statement> {
56
+ return this.steps ?? new Map();
57
+ }
58
+ public setSteps(steps: Map<string, Statement>): FunctionDefinition {
59
+ this.steps = steps;
60
+ return this;
61
+ }
62
+ public getStepGroups(): Map<string, StatementGroup> | undefined {
63
+ return this.stepGroups;
64
+ }
65
+ public setStepGroups(stepGroups: Map<string, StatementGroup>): FunctionDefinition {
66
+ this.stepGroups = stepGroups;
67
+ return this;
68
+ }
69
+ }
@@ -0,0 +1,37 @@
1
+ import { KIRuntimeException } from '../exception/KIRuntimeException';
2
+ import { isNullValue } from '../util/NullCheck';
3
+ import { EventResult } from './EventResult';
4
+ import { FunctionOutputGenerator } from './FunctionOutputGenerator';
5
+
6
+ export class FunctionOutput {
7
+ private fo: EventResult[];
8
+
9
+ private index: number = 0;
10
+ private generator?: FunctionOutputGenerator;
11
+
12
+ public constructor(arg: EventResult[] | FunctionOutputGenerator) {
13
+ if (isNullValue(arg)) throw new KIRuntimeException('Function output is generating null');
14
+
15
+ if (Array.isArray(arg) && arg.length && arg[0] instanceof EventResult) {
16
+ this.fo = arg as EventResult[];
17
+ } else {
18
+ this.fo = [];
19
+ this.generator = arg as FunctionOutputGenerator;
20
+ }
21
+ }
22
+
23
+ public next(): EventResult | undefined {
24
+ if (!this.generator) {
25
+ if (this.index < this.fo.length) return this.fo[this.index++];
26
+ return undefined;
27
+ }
28
+
29
+ const er: EventResult | undefined = this.generator.next();
30
+ if (er) this.fo.push(er);
31
+ return er;
32
+ }
33
+
34
+ public allResults(): EventResult[] {
35
+ return this.fo;
36
+ }
37
+ }
@@ -0,0 +1,5 @@
1
+ import { EventResult } from './EventResult';
2
+
3
+ export interface FunctionOutputGenerator {
4
+ next(): EventResult | undefined;
5
+ }
@@ -0,0 +1,67 @@
1
+ import { AdditionalPropertiesType } from '../json/schema/object/AdditionalPropertiesType';
2
+ import { Schema } from '../json/schema/Schema';
3
+ import { Namespaces } from '../namespaces/Namespaces';
4
+ import { Event } from './Event';
5
+ import { Parameter } from './Parameter';
6
+
7
+ export class FunctionSignature {
8
+ private static readonly SCHEMA_NAME: string = 'FunctionSignature';
9
+ public static readonly SCHEMA: Schema = new Schema()
10
+ .setNamespace(Namespaces.SYSTEM)
11
+ .setName(FunctionSignature.SCHEMA_NAME)
12
+ .setProperties(
13
+ new Map([
14
+ ['name', Schema.ofString('name')],
15
+ ['namespace', Schema.ofString('namespace')],
16
+ [
17
+ 'parameters',
18
+ Schema.ofObject('parameters').setAdditionalProperties(
19
+ new AdditionalPropertiesType().setSchemaValue(Parameter.SCHEMA),
20
+ ),
21
+ ],
22
+ [
23
+ 'events',
24
+ Schema.ofObject('events').setAdditionalProperties(
25
+ new AdditionalPropertiesType().setSchemaValue(Event.SCHEMA),
26
+ ),
27
+ ],
28
+ ]),
29
+ );
30
+ private namespace: string = '_';
31
+ private name: string;
32
+ private parameters: Map<string, Parameter> = new Map();
33
+ private events: Map<string, Event> = new Map();
34
+
35
+ constructor(name: string) {
36
+ this.name = name;
37
+ }
38
+
39
+ public getNamespace(): string {
40
+ return this.namespace;
41
+ }
42
+ public setNamespace(namespace: string): FunctionSignature {
43
+ this.namespace = namespace;
44
+ return this;
45
+ }
46
+ public getName(): string {
47
+ return this.name;
48
+ }
49
+ public setName(name: string): FunctionSignature {
50
+ this.name = name;
51
+ return this;
52
+ }
53
+ public getParameters(): Map<string, Parameter> {
54
+ return this.parameters;
55
+ }
56
+ public setParameters(parameters: Map<string, Parameter>): FunctionSignature {
57
+ this.parameters = parameters;
58
+ return this;
59
+ }
60
+ public getEvents(): Map<string, Event> {
61
+ return this.events;
62
+ }
63
+ public setEvents(events: Map<string, Event>): FunctionSignature {
64
+ this.events = events;
65
+ return this;
66
+ }
67
+ }
@@ -0,0 +1,97 @@
1
+ import { Schema } from '../json/schema/Schema';
2
+ import { SchemaType } from '../json/schema/type/SchemaType';
3
+ import { TypeUtil } from '../json/schema/type/TypeUtil';
4
+ import { Namespaces } from '../namespaces/Namespaces';
5
+ import { ParameterType } from './ParameterType';
6
+
7
+ const VALUE: string = 'value';
8
+
9
+ export class Parameter {
10
+ private static readonly SCHEMA_NAME: string = 'Parameter';
11
+
12
+ public static readonly SCHEMA: Schema = new Schema()
13
+ .setNamespace(Namespaces.SYSTEM)
14
+ .setName(Parameter.SCHEMA_NAME)
15
+ .setProperties(
16
+ new Map([
17
+ ['schema', Schema.SCHEMA],
18
+ ['parameterName', Schema.ofString('parameterName')],
19
+ [
20
+ 'variableArgument',
21
+ Schema.of('variableArgument', SchemaType.BOOLEAN).setDefaultValue(false),
22
+ ],
23
+ ]),
24
+ );
25
+
26
+ public static readonly EXPRESSION: Schema = new Schema()
27
+ .setNamespace(Namespaces.SYSTEM)
28
+ .setName('ParameterExpression')
29
+ .setType(TypeUtil.of(SchemaType.OBJECT))
30
+ .setProperties(
31
+ new Map([
32
+ ['isExpression', Schema.ofBoolean('isExpression').setDefaultValue(true)],
33
+ [VALUE, Schema.ofAny(VALUE)],
34
+ ]),
35
+ );
36
+
37
+ private schema: Schema;
38
+
39
+ private parameterName: string;
40
+ private variableArgument: boolean = false;
41
+ private type: ParameterType = ParameterType.EXPRESSION;
42
+
43
+ constructor(parameterName: string, schema: Schema) {
44
+ this.schema = schema;
45
+ this.parameterName = parameterName;
46
+ }
47
+
48
+ public getSchema(): Schema {
49
+ return this.schema;
50
+ }
51
+ public setSchema(schema: Schema): Parameter {
52
+ this.schema = schema;
53
+ return this;
54
+ }
55
+ public getParameterName(): string {
56
+ return this.parameterName;
57
+ }
58
+ public setParameterName(parameterName: string): Parameter {
59
+ this.parameterName = parameterName;
60
+ return this;
61
+ }
62
+ public isVariableArgument(): boolean {
63
+ return this.variableArgument;
64
+ }
65
+ public setVariableArgument(variableArgument: boolean): Parameter {
66
+ this.variableArgument = variableArgument;
67
+ return this;
68
+ }
69
+ public getType(): ParameterType {
70
+ return this.type;
71
+ }
72
+ public setType(type: ParameterType): Parameter {
73
+ this.type = type;
74
+ return this;
75
+ }
76
+
77
+ public static ofEntry(
78
+ name: string,
79
+ schema: Schema,
80
+ variableArgument: boolean = false,
81
+ type: ParameterType = ParameterType.EXPRESSION,
82
+ ): [string, Parameter] {
83
+ return [
84
+ name,
85
+ new Parameter(name, schema).setType(type).setVariableArgument(variableArgument),
86
+ ];
87
+ }
88
+
89
+ public static of(
90
+ name: string,
91
+ schema: Schema,
92
+ variableArgument: boolean = false,
93
+ type: ParameterType = ParameterType.EXPRESSION,
94
+ ): Parameter {
95
+ return new Parameter(name, schema).setType(type).setVariableArgument(variableArgument);
96
+ }
97
+ }
@@ -0,0 +1,57 @@
1
+ import { Schema } from '../json/schema/Schema';
2
+ import { SchemaType } from '../json/schema/type/SchemaType';
3
+ import { TypeUtil } from '../json/schema/type/TypeUtil';
4
+ import { Namespaces } from '../namespaces/Namespaces';
5
+ import { ParameterReferenceType } from './ParameterReferenceType';
6
+
7
+ export class ParameterReference {
8
+ private static readonly SCHEMA_NAME: string = 'ParameterReference';
9
+ public static readonly SCHEMA: Schema = new Schema()
10
+ .setNamespace(Namespaces.SYSTEM)
11
+ .setName(ParameterReference.SCHEMA_NAME)
12
+ .setType(TypeUtil.of(SchemaType.OBJECT))
13
+ .setProperties(
14
+ new Map([
15
+ ['references', Schema.ofString('references')],
16
+ ['value', Schema.ofAny('value')],
17
+ ['expression', Schema.ofString('expression')],
18
+ ]),
19
+ );
20
+ private type: ParameterReferenceType;
21
+ private value: any;
22
+ private expression?: string;
23
+
24
+ constructor(type: ParameterReferenceType) {
25
+ this.type = type;
26
+ }
27
+
28
+ public getType(): ParameterReferenceType {
29
+ return this.type;
30
+ }
31
+ public setType(type: ParameterReferenceType): ParameterReference {
32
+ this.type = type;
33
+ return this;
34
+ }
35
+ public getValue(): any {
36
+ return this.value;
37
+ }
38
+ public setValue(value: any): ParameterReference {
39
+ this.value = value;
40
+ return this;
41
+ }
42
+ public getExpression(): string | undefined {
43
+ return this.expression;
44
+ }
45
+ public setExpression(expression: string): ParameterReference {
46
+ this.expression = expression;
47
+ return this;
48
+ }
49
+
50
+ public static ofExpression(value: any): ParameterReference {
51
+ return new ParameterReference(ParameterReferenceType.EXPRESSION).setExpression(value);
52
+ }
53
+
54
+ public static ofValue(value: any): ParameterReference {
55
+ return new ParameterReference(ParameterReferenceType.VALUE).setValue(value);
56
+ }
57
+ }
@@ -0,0 +1,4 @@
1
+ export enum ParameterReferenceType {
2
+ VALUE = 'VALUE',
3
+ EXPRESSION = 'EXPRESSION',
4
+ }
@@ -0,0 +1,4 @@
1
+ export enum ParameterType {
2
+ CONSTANT = 'CONSTANT',
3
+ EXPRESSION = 'EXPRESSION',
4
+ }
@@ -0,0 +1,40 @@
1
+ import { Schema } from '../json/schema/Schema';
2
+ import { SchemaType } from '../json/schema/type/SchemaType';
3
+ import { TypeUtil } from '../json/schema/type/TypeUtil';
4
+ import { Namespaces } from '../namespaces/Namespaces';
5
+
6
+ export class Position {
7
+ public static readonly SCHEMA_NAME: string = 'Position';
8
+ public static readonly SCHEMA: Schema = new Schema()
9
+ .setNamespace(Namespaces.SYSTEM)
10
+ .setName(Position.SCHEMA_NAME)
11
+ .setType(TypeUtil.of(SchemaType.OBJECT))
12
+ .setProperties(
13
+ new Map([
14
+ ['left', Schema.ofFloat('left')],
15
+ ['top', Schema.ofFloat('top')],
16
+ ]),
17
+ );
18
+ private left: number;
19
+ private top: number;
20
+
21
+ constructor(left: number, top: number) {
22
+ this.left = left;
23
+ this.top = top;
24
+ }
25
+
26
+ public getLeft(): number {
27
+ return this.left;
28
+ }
29
+ public setLeft(left: number): Position {
30
+ this.left = left;
31
+ return this;
32
+ }
33
+ public getTop(): number {
34
+ return this.top;
35
+ }
36
+ public setTop(top: number): Position {
37
+ this.top = top;
38
+ return this;
39
+ }
40
+ }
@@ -0,0 +1,101 @@
1
+ import { AdditionalPropertiesType } from '../json/schema/object/AdditionalPropertiesType';
2
+ import { Schema } from '../json/schema/Schema';
3
+ import { SchemaType } from '../json/schema/type/SchemaType';
4
+ import { TypeUtil } from '../json/schema/type/TypeUtil';
5
+ import { Namespaces } from '../namespaces/Namespaces';
6
+ import { AbstractStatement } from './AbstractStatement';
7
+ import { ParameterReference } from './ParameterReference';
8
+ import { Position } from './Position';
9
+
10
+ export class Statement extends AbstractStatement {
11
+ public static readonly SCHEMA_NAME: string = 'Statement';
12
+ public static readonly SCHEMA: Schema = new Schema()
13
+ .setNamespace(Namespaces.SYSTEM)
14
+ .setName(Statement.SCHEMA_NAME)
15
+ .setType(TypeUtil.of(SchemaType.OBJECT))
16
+ .setProperties(
17
+ new Map([
18
+ ['statementName', Schema.ofString('statementName')],
19
+ ['comment', Schema.ofString('comment')],
20
+ ['description', Schema.ofString('description')],
21
+ ['namespace', Schema.ofString('namespace')],
22
+ ['name', Schema.ofString('name')],
23
+ [
24
+ 'dependentStatements',
25
+ Schema.ofArray('dependentstatement', Schema.ofString('dependentstatement')),
26
+ ],
27
+ [
28
+ 'parameterMap',
29
+ new Schema()
30
+ .setName('parameterMap')
31
+ .setAdditionalProperties(
32
+ new AdditionalPropertiesType().setSchemaValue(
33
+ Schema.ofArray('parameterReference', ParameterReference.SCHEMA),
34
+ ),
35
+ ),
36
+ ],
37
+ ['position', Position.SCHEMA],
38
+ ]),
39
+ );
40
+ private statementName: string;
41
+ private namespace: string;
42
+ private name: string;
43
+ private parameterMap?: Map<string, ParameterReference[]>;
44
+ private dependentStatements?: string[];
45
+
46
+ public constructor(statementName: string, namespace: string, name: string) {
47
+ super();
48
+ this.statementName = statementName;
49
+ this.namespace = namespace;
50
+ this.name = name;
51
+ }
52
+
53
+ public getStatementName(): string {
54
+ return this.statementName;
55
+ }
56
+ public setStatementName(statementName: string): Statement {
57
+ this.statementName = statementName;
58
+ return this;
59
+ }
60
+ public getNamespace(): string {
61
+ return this.namespace;
62
+ }
63
+ public setNamespace(namespace: string): Statement {
64
+ this.namespace = namespace;
65
+ return this;
66
+ }
67
+ public getName(): string {
68
+ return this.name;
69
+ }
70
+ public setName(name: string): Statement {
71
+ this.name = name;
72
+ return this;
73
+ }
74
+ public getParameterMap(): Map<string, ParameterReference[]> {
75
+ if (!this.parameterMap) {
76
+ this.parameterMap = new Map();
77
+ }
78
+ return this.parameterMap;
79
+ }
80
+ public setParameterMap(parameterMap: Map<string, ParameterReference[]>): Statement {
81
+ this.parameterMap = parameterMap;
82
+ return this;
83
+ }
84
+ public getDependentStatements(): string[] {
85
+ return this.dependentStatements ?? [];
86
+ }
87
+ public setDependentStatements(dependentStatements: string[]): Statement {
88
+ this.dependentStatements = dependentStatements;
89
+ return this;
90
+ }
91
+
92
+ public equals(obj: any): boolean {
93
+ if (!(obj instanceof Statement)) return false;
94
+ let s: Statement = obj as Statement;
95
+ return s.statementName == this.statementName;
96
+ }
97
+
98
+ public static ofEntry(statement: Statement): [string, Statement] {
99
+ return [statement.statementName, statement];
100
+ }
101
+ }
@@ -0,0 +1,37 @@
1
+ import { Schema } from '../json/schema/Schema';
2
+ import { SchemaType } from '../json/schema/type/SchemaType';
3
+ import { TypeUtil } from '../json/schema/type/TypeUtil';
4
+ import { Namespaces } from '../namespaces/Namespaces';
5
+ import { AbstractStatement } from './AbstractStatement';
6
+ import { Position } from './Position';
7
+
8
+ export class StatementGroup extends AbstractStatement {
9
+ private static readonly SCHEMA_NAME: string = 'StatementGroup';
10
+ public static readonly SCHEMA: Schema = new Schema()
11
+ .setNamespace(Namespaces.SYSTEM)
12
+ .setName(StatementGroup.SCHEMA_NAME)
13
+ .setType(TypeUtil.of(SchemaType.OBJECT))
14
+ .setProperties(
15
+ new Map([
16
+ ['statementGroupName', Schema.ofString('statementGroupName')],
17
+ ['comment', Schema.ofString('comment')],
18
+ ['description', Schema.ofString('description')],
19
+ ['position', Position.SCHEMA],
20
+ ]),
21
+ );
22
+
23
+ private statementGroupName: string;
24
+
25
+ constructor(statementGroupName: string) {
26
+ super();
27
+ this.statementGroupName = statementGroupName;
28
+ }
29
+
30
+ public getStatementGroupName(): string {
31
+ return this.statementGroupName;
32
+ }
33
+ public setStatementGroupName(statementGroupName: string): StatementGroup {
34
+ this.statementGroupName = statementGroupName;
35
+ return this;
36
+ }
37
+ }
@@ -0,0 +1,11 @@
1
+ export class Namespaces {
2
+ public static readonly SYSTEM: string = 'System';
3
+ public static readonly SYSTEM_CTX: string = 'System.Context';
4
+ public static readonly SYSTEM_LOOP: string = 'System.Loop';
5
+ public static readonly SYSTEM_ARRAY: string = 'System.Array';
6
+
7
+ public static readonly MATH: string = 'System.Math';
8
+ public static readonly STRING: string = 'System.String';
9
+
10
+ private constructor() {}
11
+ }
@@ -0,0 +1,37 @@
1
+ import { Function } from '../function/Function';
2
+ import { Create } from '../function/system/context/Create';
3
+ import { Get } from '../function/system/context/Get';
4
+ import { SetFunction } from '../function/system/context/SetFunction';
5
+ import { GenerateEvent } from '../function/system/GenerateEvent';
6
+ import { If } from '../function/system/If';
7
+ import { CountLoop } from '../function/system/loop/CountLoop';
8
+ import { RangeLoop } from '../function/system/loop/RangeLoop';
9
+ import { MathFunctionRepository } from '../function/system/math/MathFunctionRepository';
10
+ import { HybridRepository } from '../HybridRepository';
11
+ import { Namespaces } from '../namespaces/Namespaces';
12
+
13
+ function entry(fun: Function): [string, Function] {
14
+ return [fun.getSignature().getName(), fun];
15
+ }
16
+
17
+ const map: Map<string, Map<string, Function>> = new Map([
18
+ [
19
+ Namespaces.SYSTEM_CTX,
20
+ new Map([entry(new Create()), entry(new Get()), entry(new SetFunction())]),
21
+ ],
22
+ [Namespaces.SYSTEM_LOOP, new Map([entry(new RangeLoop()), entry(new CountLoop())])],
23
+ [Namespaces.SYSTEM, new Map([entry(new If()), entry(new GenerateEvent())])],
24
+ ]);
25
+
26
+ export class KIRunFunctionRepository extends HybridRepository<Function> {
27
+ public constructor() {
28
+ super(
29
+ {
30
+ find(namespace: string, name: string): Function | undefined {
31
+ return map.get(namespace)?.get(name);
32
+ },
33
+ },
34
+ new MathFunctionRepository(),
35
+ );
36
+ }
37
+ }