@fincity/kirun-js 1.5.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/__tests__/engine/json/schema/validator/ArrayContainsValidatorTest.ts +339 -0
  2. package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +142 -0
  3. package/__tests__/engine/json/schema/validator/ArraySchemaTypeTest.ts +191 -0
  4. package/__tests__/engine/json/schema/validator/ArrayValidatorTest.ts +152 -0
  5. package/__tests__/engine/json/schema/validator/ObjectPropertiesTest.ts +23 -0
  6. package/__tests__/engine/json/schema/validator/ObjectValidatorTest.ts +280 -0
  7. package/__tests__/engine/json/schema/validator/SchemaAnyOfValidatorTest.ts +20 -3
  8. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +21 -5
  9. package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +0 -2
  10. package/__tests__/engine/repository/RepositoryFilterTest.ts +39 -0
  11. package/__tests__/engine/runtime/KIRuntimeFunctionInFunction.ts +6 -0
  12. package/__tests__/engine/runtime/KIRuntimeMessagesTest.ts +179 -0
  13. package/__tests__/engine/runtime/KIRuntimeTest.ts +6 -0
  14. package/__tests__/indexTest.ts +12 -0
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/module.js +1 -1
  18. package/dist/module.js.map +1 -1
  19. package/dist/types.d.ts +23 -12
  20. package/dist/types.d.ts.map +1 -1
  21. package/package.json +1 -1
  22. package/src/engine/HybridRepository.ts +8 -0
  23. package/src/engine/Repository.ts +1 -0
  24. package/src/engine/function/system/Print.ts +1 -1
  25. package/src/engine/function/system/array/ArrayFunctionRepository.ts +10 -0
  26. package/src/engine/function/system/math/MathFunctionRepository.ts +10 -1
  27. package/src/engine/function/system/string/StringFunctionRepository.ts +10 -0
  28. package/src/engine/json/schema/Schema.ts +82 -32
  29. package/src/engine/json/schema/SchemaUtil.ts +6 -3
  30. package/src/engine/json/schema/array/ArraySchemaType.ts +13 -2
  31. package/src/engine/json/schema/validator/ArrayValidator.ts +135 -24
  32. package/src/engine/json/schema/validator/ObjectValidator.ts +9 -4
  33. package/src/engine/model/Event.ts +2 -2
  34. package/src/engine/model/FunctionDefinition.ts +3 -3
  35. package/src/engine/model/FunctionSignature.ts +6 -3
  36. package/src/engine/model/Statement.ts +4 -6
  37. package/src/engine/repository/KIRunFunctionRepository.ts +9 -0
  38. package/src/engine/repository/KIRunSchemaRepository.ts +8 -0
  39. package/src/engine/runtime/KIRuntime.ts +36 -48
@@ -13,12 +13,20 @@ const map: Map<string, Schema> = new Map([
13
13
  ['number', Schema.ofNumber('number').setNamespace(Namespaces.SYSTEM)],
14
14
  ['string', Schema.ofString('string').setNamespace(Namespaces.SYSTEM)],
15
15
  [Parameter.EXPRESSION.getName()!, Parameter.EXPRESSION],
16
+ [Schema.NULL.getName()!, Schema.NULL],
17
+ [Schema.SCHEMA.getName()!, Schema.SCHEMA],
16
18
  ]);
17
19
 
20
+ const filterableNames = Array.from(map.values()).map((e) => e.getFullName());
21
+
18
22
  export class KIRunSchemaRepository implements Repository<Schema> {
19
23
  public find(namespace: string, name: string): Schema | undefined {
20
24
  if (Namespaces.SYSTEM != namespace) return undefined;
21
25
 
22
26
  return map.get(name);
23
27
  }
28
+
29
+ public filter(name: string): string[] {
30
+ return filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1);
31
+ }
24
32
  }
@@ -68,19 +68,22 @@ export class KIRuntime extends AbstractFunction {
68
68
  }
69
69
 
70
70
  public async getExecutionPlan(
71
- fep: FunctionExecutionParameters,
72
- ): Promise<Tuple2<Tuple2<string, string>[], ExecutionGraph<string, StatementExecution>>> {
71
+ fRepo: Repository<Function>,
72
+ sRepo: Repository<Schema>,
73
+ ): Promise<ExecutionGraph<string, StatementExecution>> {
73
74
  let g: ExecutionGraph<string, StatementExecution> = new ExecutionGraph();
74
75
  for (let s of Array.from(this.fd.getSteps().values()))
75
- g.addVertex(
76
- this.prepareStatementExecution(
77
- s,
78
- fep.getFunctionRepository(),
79
- fep.getSchemaRepository(),
80
- ),
81
- );
76
+ g.addVertex(this.prepareStatementExecution(s, fRepo, sRepo));
77
+
78
+ let unresolved = this.makeEdges(g);
79
+
80
+ Array.from(unresolved.getT2().entries()).forEach((e) => {
81
+ let ex = g.getNodeMap().get(e[0])?.getData();
82
+ if (!ex) return;
83
+ ex.addMessage(StatementMessageType.ERROR, e[1]);
84
+ });
82
85
 
83
- return new Tuple2(this.makeEdges(g), g);
86
+ return g;
84
87
  }
85
88
 
86
89
  protected async internalExecute(
@@ -105,36 +108,13 @@ export class KIRuntime extends AbstractFunction {
105
108
  console.log(`EID: ${inContext.getExecutionId()} Parameters: `, inContext);
106
109
  }
107
110
 
108
- let eGraph: Tuple2<
109
- Tuple2<string, string>[],
110
- ExecutionGraph<string, StatementExecution>
111
- > = await this.getExecutionPlan(inContext);
111
+ let eGraph: ExecutionGraph<string, StatementExecution> = await this.getExecutionPlan(
112
+ inContext.getFunctionRepository(),
113
+ inContext.getSchemaRepository(),
114
+ );
112
115
 
113
116
  if (this.debugMode) {
114
- console.log(`EID: ${inContext.getExecutionId()} ${eGraph.getT2()?.toString()}`);
115
- }
116
-
117
- let unresolvedList: Tuple2<string, string>[] = eGraph.getT1();
118
-
119
- if (this.debugMode && unresolvedList.length) {
120
- console.log(`EID: ${inContext.getExecutionId()} Unresolved Dependencies: `);
121
- console.log(
122
- `EID: ${inContext.getExecutionId()} `,
123
- unresolvedList.map((e) =>
124
- StringFormatter.format('Steps.$.$', e.getT1(), e.getT2()),
125
- ),
126
- );
127
- }
128
-
129
- if (unresolvedList.length) {
130
- throw new KIRuntimeException(
131
- StringFormatter.format(
132
- 'Found these unresolved dependencies : $ ',
133
- unresolvedList.map((e) =>
134
- StringFormatter.format('Steps.$.$', e.getT1(), e.getT2()),
135
- ),
136
- ),
137
- );
117
+ console.log(`EID: ${inContext.getExecutionId()} ${eGraph?.toString()}`);
138
118
  }
139
119
 
140
120
  // if (logger.isDebugEnabled()) {
@@ -143,7 +123,6 @@ export class KIRuntime extends AbstractFunction {
143
123
  // }
144
124
 
145
125
  let messages: string[] = eGraph
146
- .getT2()
147
126
  .getVerticesData()
148
127
  .filter((e) => e.getMessages().length)
149
128
  .map((e) => e.getStatement().getStatementName() + ': \n' + e.getMessages().join(','));
@@ -155,7 +134,7 @@ export class KIRuntime extends AbstractFunction {
155
134
  );
156
135
  }
157
136
 
158
- return await this.executeGraph(eGraph.getT2(), inContext);
137
+ return await this.executeGraph(eGraph, inContext);
159
138
  }
160
139
 
161
140
  private async executeGraph(
@@ -414,7 +393,7 @@ export class KIRuntime extends AbstractFunction {
414
393
 
415
394
  if (!isOutput) {
416
395
  let subGraph = vertex.getSubGraphOfType(er.getName());
417
- let unResolvedDependencies: Tuple2<string, string>[] = this.makeEdges(subGraph);
396
+ let unResolvedDependencies: Tuple2<string, string>[] = this.makeEdges(subGraph).getT1();
418
397
  branchQue.push(new Tuple4(subGraph, unResolvedDependencies, result, vertex));
419
398
  } else {
420
399
  let out: Set<GraphVertex<string, StatementExecution>> | undefined = vertex
@@ -566,9 +545,11 @@ export class KIRuntime extends AbstractFunction {
566
545
  let fun: Function | undefined = fRepo.find(s.getNamespace(), s.getName());
567
546
 
568
547
  if (!fun) {
569
- throw new KIRuntimeException(
570
- StringFormatter.format('$.$ was not available', s.getNamespace(), s.getName()),
548
+ se.addMessage(
549
+ StatementMessageType.ERROR,
550
+ StringFormatter.format('$.$ is not available', s.getNamespace(), s.getName()),
571
551
  );
552
+ return se;
572
553
  }
573
554
 
574
555
  let paramSet: Map<string, Parameter> = new Map(fun.getSignature().getParameters());
@@ -736,10 +717,13 @@ export class KIRuntime extends AbstractFunction {
736
717
  );
737
718
  }
738
719
 
739
- public makeEdges(graph: ExecutionGraph<string, StatementExecution>): Tuple2<string, string>[] {
720
+ public makeEdges(
721
+ graph: ExecutionGraph<string, StatementExecution>,
722
+ ): Tuple2<Tuple2<string, string>[], Map<string, string>> {
740
723
  let values = graph.getNodeMap().values();
741
724
 
742
725
  let retValue: Tuple2<string, string>[] = [];
726
+ let retMap: Map<string, string> = new Map();
743
727
 
744
728
  for (let e of Array.from(values)) {
745
729
  for (let d of e.getData().getDependencies()) {
@@ -751,13 +735,17 @@ export class KIRuntime extends AbstractFunction {
751
735
  ? d.substring(secondDot + 1)
752
736
  : d.substring(secondDot + 1, eventDot);
753
737
 
754
- if (!graph.getNodeMap().has(step)) retValue.push(new Tuple2(step, event));
738
+ if (!graph.getNodeMap().has(step)) {
739
+ retValue.push(new Tuple2(step, event));
740
+ retMap.set(
741
+ e.getData().getStatement().getStatementName(),
755
742
 
756
- let st = graph.getNodeMap()!.get(step);
757
- if (st) e.addInEdgeTo(st, event);
743
+ StringFormatter.format('Unable to find the step with name $', step),
744
+ );
745
+ } else e.addInEdgeTo(graph.getNodeMap().get(step)!, event);
758
746
  }
759
747
  }
760
748
 
761
- return retValue;
749
+ return new Tuple2(retValue, retMap);
762
750
  }
763
751
  }