@cadenza.io/core 1.11.16 → 1.12.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.
package/dist/index.mjs CHANGED
@@ -896,7 +896,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
896
896
  if (this.result instanceof Promise) {
897
897
  return this.executeAsync();
898
898
  }
899
- this.postProcess();
899
+ const nextNodes = this.postProcess();
900
+ if (nextNodes instanceof Promise) {
901
+ return nextNodes;
902
+ }
903
+ this.nextNodes = nextNodes;
900
904
  }
901
905
  return this.nextNodes;
902
906
  }
@@ -912,7 +916,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
912
916
  }
913
917
  async executeAsync() {
914
918
  await this.workAsync();
915
- this.postProcess();
919
+ const nextNodes = this.postProcess();
920
+ if (nextNodes instanceof Promise) {
921
+ return nextNodes;
922
+ }
923
+ this.nextNodes = nextNodes;
916
924
  return this.nextNodes;
917
925
  }
918
926
  work() {
@@ -998,7 +1006,20 @@ var GraphNode = class _GraphNode extends SignalEmitter {
998
1006
  if (Array.isArray(this.result)) {
999
1007
  this.onError(`Returning arrays is not allowed. Returned: ${this.result}`);
1000
1008
  }
1001
- this.nextNodes = this.divide();
1009
+ const nextNodes = this.divide();
1010
+ if (nextNodes instanceof Promise) {
1011
+ return this.postProcessAsync(nextNodes);
1012
+ }
1013
+ this.nextNodes = nextNodes;
1014
+ this.finalize();
1015
+ return this.nextNodes;
1016
+ }
1017
+ async postProcessAsync(nextNodes) {
1018
+ this.nextNodes = await nextNodes;
1019
+ this.finalize();
1020
+ return this.nextNodes;
1021
+ }
1022
+ finalize() {
1002
1023
  if (this.nextNodes.length === 0) {
1003
1024
  this.completeSubgraph();
1004
1025
  }
@@ -1055,6 +1076,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1055
1076
  if (((_a = this.result) == null ? void 0 : _a.next) && typeof this.result.next === "function") {
1056
1077
  const generator = this.result;
1057
1078
  let current = generator.next();
1079
+ if (current instanceof Promise) {
1080
+ return this.divideAsync(current);
1081
+ }
1058
1082
  while (!current.done && current.value !== void 0) {
1059
1083
  const outputValidation = this.task.validateOutput(current.value);
1060
1084
  if (outputValidation !== true) {
@@ -1098,6 +1122,28 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1098
1122
  });
1099
1123
  return newNodes;
1100
1124
  }
1125
+ async divideAsync(current) {
1126
+ const nextNodes = [];
1127
+ const _current = await current;
1128
+ const outputValidation = this.task.validateOutput(_current.value);
1129
+ if (outputValidation !== true) {
1130
+ this.onError(outputValidation.__validationErrors);
1131
+ return nextNodes;
1132
+ } else {
1133
+ nextNodes.push(...this.generateNewNodes(_current.value));
1134
+ }
1135
+ for await (const result of this.result) {
1136
+ const outputValidation2 = this.task.validateOutput(result);
1137
+ if (outputValidation2 !== true) {
1138
+ this.onError(outputValidation2.__validationErrors);
1139
+ return [];
1140
+ } else {
1141
+ nextNodes.push(...this.generateNewNodes(result));
1142
+ }
1143
+ }
1144
+ this.divided = true;
1145
+ return nextNodes;
1146
+ }
1101
1147
  generateNewNodes(result) {
1102
1148
  const groupId = uuid3();
1103
1149
  const newNodes = [];