@fincity/kirun-js 1.1.2 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/__tests__/engine/function/system/array/AddFirstTest.ts +29 -7
  2. package/__tests__/engine/function/system/array/AddTest.ts +21 -5
  3. package/__tests__/engine/function/system/array/BinarySearchTest.ts +26 -7
  4. package/__tests__/engine/function/system/array/CompareTest.ts +5 -1
  5. package/__tests__/engine/function/system/array/CopyTest.ts +22 -7
  6. package/__tests__/engine/function/system/array/DeleteFirstTest.ts +21 -5
  7. package/__tests__/engine/function/system/array/DeleteFromTest.ts +17 -4
  8. package/__tests__/engine/function/system/array/DeleteLastTest.ts +21 -5
  9. package/__tests__/engine/function/system/array/DeleteTest.ts +25 -6
  10. package/__tests__/engine/function/system/array/DisjointTest.ts +13 -3
  11. package/__tests__/engine/function/system/array/Equals.ts +13 -3
  12. package/__tests__/engine/function/system/array/FillTest.ts +5 -1
  13. package/__tests__/engine/function/system/array/FrequencyTest.ts +13 -3
  14. package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +29 -7
  15. package/__tests__/engine/function/system/array/IndexOfTest.ts +21 -5
  16. package/__tests__/engine/function/system/array/InsertTest.ts +25 -6
  17. package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +21 -5
  18. package/__tests__/engine/function/system/array/LastIndexOfTest.ts +25 -6
  19. package/__tests__/engine/function/system/array/MaxTest.ts +33 -24
  20. package/__tests__/engine/function/system/array/MinTest.ts +33 -24
  21. package/__tests__/engine/function/system/array/MisMatchTest.ts +17 -4
  22. package/__tests__/engine/function/system/array/ReverseTest.ts +21 -5
  23. package/__tests__/engine/function/system/array/RotateTest.ts +13 -3
  24. package/__tests__/engine/function/system/array/ShuffleTest.ts +9 -2
  25. package/__tests__/engine/function/system/array/SortTest.ts +21 -5
  26. package/__tests__/engine/function/system/array/SubArrayTest.ts +21 -5
  27. package/__tests__/engine/function/system/context/SetFunctionTest.ts +13 -3
  28. package/__tests__/engine/function/system/math/AddTest.ts +5 -3
  29. package/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +108 -0
  30. package/__tests__/engine/function/system/math/MaximumTest.ts +38 -0
  31. package/__tests__/engine/function/system/math/MinimumTest.ts +38 -0
  32. package/__tests__/engine/function/system/math/RandomFloatTest.ts +83 -0
  33. package/__tests__/engine/function/system/math/RandomIntTest.ts +13 -5
  34. package/__tests__/engine/function/system/string/ConcatenateTest.ts +9 -2
  35. package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +9 -2
  36. package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +13 -3
  37. package/__tests__/engine/function/system/string/PostPadTest.ts +13 -3
  38. package/__tests__/engine/function/system/string/PrePadTest.ts +13 -3
  39. package/__tests__/engine/function/system/string/RegionMatchesTest.ts +13 -3
  40. package/__tests__/engine/function/system/string/ReverseTest.ts +10 -3
  41. package/__tests__/engine/function/system/string/SplitTest.ts +9 -2
  42. package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +13 -3
  43. package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +9 -2
  44. package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +33 -8
  45. package/__tests__/engine/function/system/string/ToStringTest.ts +10 -3
  46. package/__tests__/engine/function/system/string/TrimToTest.ts +9 -2
  47. package/__tests__/engine/json/schema/SchemaUtil.ts +3 -0
  48. package/__tests__/engine/json/schema/type/TypeUtilTest.ts +10 -0
  49. package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +38 -0
  50. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +67 -0
  51. package/__tests__/engine/runtime/KIRuntimeTest.ts +23 -12
  52. package/__tests__/engine/runtime/KIRuntimeWithDefinitionTest.ts +9 -10
  53. package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +5 -1
  54. package/dist/index.js +1 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/module.js +1 -1
  57. package/dist/module.js.map +1 -1
  58. package/dist/types.d.ts +11 -2
  59. package/dist/types.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/engine/function/AbstractFunction.ts +14 -5
  62. package/src/engine/function/system/math/Maximum.ts +1 -1
  63. package/src/engine/function/system/math/Minimum.ts +1 -1
  64. package/src/engine/function/system/math/RandomFloat.ts +2 -2
  65. package/src/engine/json/schema/Schema.ts +3 -3
  66. package/src/engine/json/schema/SchemaUtil.ts +4 -4
  67. package/src/engine/json/schema/type/TypeUtil.ts +3 -5
  68. package/src/engine/json/schema/validator/SchemaValidator.ts +4 -1
  69. package/src/engine/model/AbstractStatement.ts +10 -0
  70. package/src/engine/runtime/FunctionExecutionParameters.ts +48 -0
  71. package/src/engine/runtime/KIRuntime.ts +38 -24
@@ -43,15 +43,7 @@ export class KIRuntime extends AbstractFunction {
43
43
 
44
44
  private fd: FunctionDefinition;
45
45
 
46
- private fRepo: Repository<Function>;
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(this.prepareStatementExecution(context, s));
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 await this.executeVertex(vertex, inContext, branchQue, executionQue);
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 = this.fRepo.find(s.getNamespace(), s.getName());
277
+ let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
272
278
 
273
279
  if (!fun) {
274
280
  throw new KIRuntimeException(
@@ -287,7 +293,11 @@ export class KIRuntime extends AbstractFunction {
287
293
  let context: Map<string, ContextElement> = inContext.getContext()!;
288
294
 
289
295
  let result: FunctionOutput = await fun.execute(
290
- new FunctionExecutionParameters()
296
+ new FunctionExecutionParameters(
297
+ inContext.getFunctionRepository(),
298
+ inContext.getSchemaRepository(),
299
+ )
300
+ .setValuesMap(inContext.getValuesMap())
291
301
  .setContext(context)
292
302
  .setArguments(args)
293
303
  .setEvents(inContext.getEvents()!)
@@ -455,10 +465,12 @@ export class KIRuntime extends AbstractFunction {
455
465
  private prepareStatementExecution(
456
466
  context: Map<string, ContextElement>,
457
467
  s: Statement,
468
+ fRepo: Repository<Function>,
469
+ sRepo: Repository<Schema>,
458
470
  ): StatementExecution {
459
471
  let se: StatementExecution = new StatementExecution(s);
460
472
 
461
- let fun: Function | undefined = this.fRepo.find(s.getNamespace(), s.getName());
473
+ let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
462
474
 
463
475
  if (!fun) {
464
476
  throw new KIRuntimeException(
@@ -475,7 +487,7 @@ export class KIRuntime extends AbstractFunction {
475
487
  let refList: ParameterReference[] = param[1];
476
488
 
477
489
  if (!refList.length) {
478
- if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), this.sRepo)))
490
+ if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
479
491
  se.addMessage(
480
492
  StatementMessageType.ERROR,
481
493
  StringFormatter.format(
@@ -487,10 +499,11 @@ export class KIRuntime extends AbstractFunction {
487
499
  }
488
500
 
489
501
  if (p.isVariableArgument()) {
490
- for (let ref of refList) this.parameterReferenceValidation(context, se, p, ref);
502
+ for (let ref of refList)
503
+ this.parameterReferenceValidation(context, se, p, ref, sRepo);
491
504
  } else {
492
505
  let ref: ParameterReference = refList[0];
493
- this.parameterReferenceValidation(context, se, p, ref);
506
+ this.parameterReferenceValidation(context, se, p, ref, sRepo);
494
507
  }
495
508
 
496
509
  paramSet.delete(p.getParameterName());
@@ -503,7 +516,7 @@ export class KIRuntime extends AbstractFunction {
503
516
 
504
517
  if (paramSet.size) {
505
518
  for (let param of Array.from(paramSet.values())) {
506
- if (isNullValue(SchemaUtil.getDefaultValue(param.getSchema(), this.sRepo)))
519
+ if (isNullValue(SchemaUtil.getDefaultValue(param.getSchema(), sRepo)))
507
520
  se.addMessage(
508
521
  StatementMessageType.ERROR,
509
522
  StringFormatter.format(
@@ -522,11 +535,12 @@ export class KIRuntime extends AbstractFunction {
522
535
  se: StatementExecution,
523
536
  p: Parameter,
524
537
  ref: ParameterReference,
538
+ sRepo: Repository<Schema>,
525
539
  ): void {
526
540
  // Breaking this execution doesn't make sense.
527
541
 
528
542
  if (!ref) {
529
- if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), this.sRepo)))
543
+ if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
530
544
  se.addMessage(
531
545
  StatementMessageType.ERROR,
532
546
  StringFormatter.format(KIRuntime.PARAMETER_NEEDS_A_VALUE, p.getParameterName()),
@@ -534,7 +548,7 @@ export class KIRuntime extends AbstractFunction {
534
548
  } else if (ref.getType() == ParameterReferenceType.VALUE) {
535
549
  if (
536
550
  isNullValue(ref.getValue()) &&
537
- isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), this.sRepo))
551
+ isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo))
538
552
  )
539
553
  se.addMessage(
540
554
  StatementMessageType.ERROR,
@@ -598,7 +612,7 @@ export class KIRuntime extends AbstractFunction {
598
612
  }
599
613
  } else if (ref.getType() == ParameterReferenceType.EXPRESSION) {
600
614
  if (StringUtil.isNullOrBlank(ref.getExpression())) {
601
- if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), this.sRepo)))
615
+ if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
602
616
  se.addMessage(
603
617
  StatementMessageType.ERROR,
604
618
  StringFormatter.format(