@fincity/kirun-js 1.9.0 → 2.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 (56) hide show
  1. package/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +118 -75
  2. package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +3 -3
  3. package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +2 -2
  4. package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +8 -8
  5. package/__tests__/engine/json/schema/SchemaUtil.ts +1 -1
  6. package/__tests__/engine/json/schema/type/TypeUtilTest.ts +1 -1
  7. package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +24 -19
  8. package/__tests__/engine/json/schema/validator/ArrayContainsValidatorTest.ts +22 -22
  9. package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +10 -10
  10. package/__tests__/engine/json/schema/validator/ArraySchemaTypeTest.ts +22 -22
  11. package/__tests__/engine/json/schema/validator/ArrayValidatorTest.ts +13 -13
  12. package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +10 -9
  13. package/__tests__/engine/json/schema/validator/NullValidatorTest.ts +13 -0
  14. package/__tests__/engine/json/schema/validator/ObjectPropertiesTest.ts +4 -4
  15. package/__tests__/engine/json/schema/validator/ObjectValidatorTest.ts +32 -28
  16. package/__tests__/engine/json/schema/validator/SchemaAnyOfValidatorTest.ts +184 -182
  17. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +43 -32
  18. package/__tests__/engine/json/schema/validator/StringFormatSchemaValidatorTest.ts +24 -24
  19. package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +14 -14
  20. package/__tests__/engine/repository/KIRunFunctionRepositoryTest.ts +7 -7
  21. package/__tests__/engine/repository/RepositoryFilterTest.ts +7 -7
  22. package/__tests__/engine/runtime/KIRuntimeDependencyTest.ts +60 -7
  23. package/__tests__/engine/runtime/KIRuntimeFunctionInFunction.ts +11 -7
  24. package/__tests__/engine/runtime/KIRuntimeNoParamMapTest.ts +2 -2
  25. package/__tests__/engine/runtime/KIRuntimeNoValuesTest.ts +2 -2
  26. package/__tests__/engine/runtime/KIRuntimeTest.ts +8 -6
  27. package/__tests__/engine/runtime/KIRuntimeTestWithoutGenEvent.ts +4 -1
  28. package/__tests__/engine/runtime/KIRuntimeUndefinedParamTest.ts +4 -4
  29. package/__tests__/engine/runtime/KIRuntimeValuesEmptyTest.ts +6 -6
  30. package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +35 -0
  31. package/__tests__/indexTest.ts +10 -10
  32. package/dist/index.js +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/module.js +1 -1
  35. package/dist/module.js.map +1 -1
  36. package/dist/types.d.ts +17 -17
  37. package/dist/types.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/engine/HybridRepository.ts +5 -5
  40. package/src/engine/Repository.ts +2 -2
  41. package/src/engine/function/AbstractFunction.ts +35 -31
  42. package/src/engine/function/system/array/ArrayFunctionRepository.ts +8 -6
  43. package/src/engine/function/system/math/MathFunctionRepository.ts +7 -5
  44. package/src/engine/function/system/object/ObjectFunctionRepository.ts +7 -5
  45. package/src/engine/function/system/string/StringFunctionRepository.ts +8 -6
  46. package/src/engine/json/schema/SchemaUtil.ts +33 -30
  47. package/src/engine/json/schema/validator/ArrayValidator.ts +25 -20
  48. package/src/engine/json/schema/validator/NullValidator.ts +6 -7
  49. package/src/engine/json/schema/validator/ObjectValidator.ts +32 -14
  50. package/src/engine/json/schema/validator/SchemaValidator.ts +15 -11
  51. package/src/engine/json/schema/validator/TypeValidator.ts +5 -5
  52. package/src/engine/model/Statement.ts +13 -3
  53. package/src/engine/repository/KIRunFunctionRepository.ts +3 -2
  54. package/src/engine/repository/KIRunSchemaRepository.ts +7 -5
  55. package/src/engine/runtime/KIRuntime.ts +25 -20
  56. package/src/engine/util/duplicate.ts +1 -1
@@ -73,7 +73,7 @@ export class KIRuntime extends AbstractFunction {
73
73
  ): Promise<ExecutionGraph<string, StatementExecution>> {
74
74
  let g: ExecutionGraph<string, StatementExecution> = new ExecutionGraph();
75
75
  for (let s of Array.from(this.fd.getSteps().values()))
76
- g.addVertex(this.prepareStatementExecution(s, fRepo, sRepo));
76
+ g.addVertex(await this.prepareStatementExecution(s, fRepo, sRepo));
77
77
 
78
78
  let unresolved = this.makeEdges(g);
79
79
 
@@ -303,19 +303,18 @@ export class KIRuntime extends AbstractFunction {
303
303
  let s: Statement = vertex.getData().getStatement();
304
304
 
305
305
  if (s.getExecuteIftrue().size) {
306
- const outputTokenValueExtrator = inContext
307
- .getValuesMap()
308
- .get(OutputMapTokenValueExtractor.PREFIX);
309
-
310
306
  const allTrue = (Array.from(s.getExecuteIftrue().entries()) ?? [])
311
307
  .filter((e) => e[1])
312
- .map(([e]) => outputTokenValueExtrator?.getValue(e))
313
- .every((e) => !isNullValue(e));
308
+ .map(([e]) => {
309
+ const v = new ExpressionEvaluator(e).evaluate(inContext.getValuesMap());
310
+ return v;
311
+ })
312
+ .every((e) => !isNullValue(e) && e !== false);
314
313
 
315
314
  if (!allTrue) return;
316
315
  }
317
316
 
318
- let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
317
+ let fun: Function | undefined = await fRepo.find(s.getNamespace(), s.getName());
319
318
 
320
319
  if (!fun) {
321
320
  throw new KIRuntimeException(
@@ -551,25 +550,25 @@ export class KIRuntime extends AbstractFunction {
551
550
  return ret;
552
551
  }
553
552
 
554
- private prepareStatementExecution(
553
+ private async prepareStatementExecution(
555
554
  s: Statement,
556
555
  fRepo: Repository<Function>,
557
556
  sRepo: Repository<Schema>,
558
- ): StatementExecution {
557
+ ): Promise<StatementExecution> {
559
558
  let se: StatementExecution = new StatementExecution(s);
560
559
 
561
- let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
560
+ let fun: Function | undefined = await fRepo.find(s.getNamespace(), s.getName());
562
561
 
563
562
  if (!fun) {
564
563
  se.addMessage(
565
564
  StatementMessageType.ERROR,
566
565
  StringFormatter.format('$.$ is not available', s.getNamespace(), s.getName()),
567
566
  );
568
- return se;
567
+ return Promise.resolve(se);
569
568
  }
570
569
 
571
570
  let paramSet: Map<string, Parameter> = new Map(fun.getSignature().getParameters());
572
- if (!s.getParameterMap()) return se;
571
+ if (!s.getParameterMap()) return Promise.resolve(se);
573
572
  for (let param of Array.from(s.getParameterMap().entries())) {
574
573
  let p: Parameter | undefined = paramSet.get(param[0]);
575
574
  if (!p) continue;
@@ -577,7 +576,7 @@ export class KIRuntime extends AbstractFunction {
577
576
  let refList: ParameterReference[] = Array.from(param[1]?.values() ?? []);
578
577
 
579
578
  if (!refList.length && !p.isVariableArgument()) {
580
- if (!SchemaUtil.hasDefaultValueOrNullSchemaType(p.getSchema(), sRepo))
579
+ if (!(await SchemaUtil.hasDefaultValueOrNullSchemaType(p.getSchema(), sRepo)))
581
580
  se.addMessage(
582
581
  StatementMessageType.ERROR,
583
582
  StringFormatter.format(
@@ -604,10 +603,16 @@ export class KIRuntime extends AbstractFunction {
604
603
  for (let statement of se.getStatement().getDependentStatements().entries())
605
604
  if (statement[1]) se.addDependency(statement[0]);
606
605
  }
606
+
607
+ if (!isNullValue(se.getStatement().getExecuteIftrue())) {
608
+ for (let statement of se.getStatement().getExecuteIftrue().entries())
609
+ if (statement[1]) this.addDependencies(se, statement[0]);
610
+ }
611
+
607
612
  if (paramSet.size) {
608
613
  for (let param of Array.from(paramSet.values())) {
609
614
  if (param.isVariableArgument()) continue;
610
- if (!SchemaUtil.hasDefaultValueOrNullSchemaType(param.getSchema(), sRepo))
615
+ if (!(await SchemaUtil.hasDefaultValueOrNullSchemaType(param.getSchema(), sRepo)))
611
616
  se.addMessage(
612
617
  StatementMessageType.ERROR,
613
618
  StringFormatter.format(
@@ -618,19 +623,19 @@ export class KIRuntime extends AbstractFunction {
618
623
  }
619
624
  }
620
625
 
621
- return se;
626
+ return Promise.resolve(se);
622
627
  }
623
628
 
624
- private parameterReferenceValidation(
629
+ private async parameterReferenceValidation(
625
630
  se: StatementExecution,
626
631
  p: Parameter,
627
632
  ref: ParameterReference,
628
633
  sRepo: Repository<Schema>,
629
- ): void {
634
+ ): Promise<void> {
630
635
  // Breaking this execution doesn't make sense.
631
636
 
632
637
  if (!ref) {
633
- if (isNullValue(SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
638
+ if (isNullValue(await SchemaUtil.getDefaultValue(p.getSchema(), sRepo)))
634
639
  se.addMessage(
635
640
  StatementMessageType.ERROR,
636
641
  StringFormatter.format(KIRuntime.PARAMETER_NEEDS_A_VALUE, p.getParameterName()),
@@ -638,7 +643,7 @@ export class KIRuntime extends AbstractFunction {
638
643
  } else if (ref.getType() == ParameterReferenceType.VALUE) {
639
644
  if (
640
645
  isNullValue(ref.getValue()) &&
641
- !SchemaUtil.hasDefaultValueOrNullSchemaType(p.getSchema(), sRepo)
646
+ !(await SchemaUtil.hasDefaultValueOrNullSchemaType(p.getSchema(), sRepo))
642
647
  )
643
648
  se.addMessage(
644
649
  StatementMessageType.ERROR,
@@ -1,5 +1,5 @@
1
1
  export function duplicate(obj: any): any {
2
2
  if (!obj) return obj;
3
- if (structuredClone) return structuredClone(obj);
3
+ if (globalThis.structuredClone) return globalThis.structuredClone(obj);
4
4
  return JSON.parse(JSON.stringify(obj));
5
5
  }