@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.d.mts CHANGED
@@ -232,12 +232,15 @@ declare class GraphNode extends SignalEmitter implements Graph {
232
232
  emitWithMetadata(signal: string, ctx: AnyObject): void;
233
233
  emitMetricsWithMetadata(signal: string, ctx: AnyObject): void;
234
234
  onProgress(progress: number): void;
235
- postProcess(): void;
235
+ postProcess(): GraphNode[] | Promise<GraphNode[]>;
236
+ postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
237
+ finalize(): void;
236
238
  onError(error: unknown, errorData?: AnyObject): void;
237
239
  retry(prevResult?: any): Promise<TaskResult>;
238
240
  retryAsync(prevResult?: any): Promise<TaskResult>;
239
241
  delayRetry(): Promise<void>;
240
- divide(): GraphNode[];
242
+ divide(): GraphNode[] | Promise<GraphNode[]>;
243
+ divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
241
244
  generateNewNodes(result: any): GraphNode[];
242
245
  differentiate(task: Task): GraphNode;
243
246
  migrate(ctx: any): GraphNode;
package/dist/index.d.ts CHANGED
@@ -232,12 +232,15 @@ declare class GraphNode extends SignalEmitter implements Graph {
232
232
  emitWithMetadata(signal: string, ctx: AnyObject): void;
233
233
  emitMetricsWithMetadata(signal: string, ctx: AnyObject): void;
234
234
  onProgress(progress: number): void;
235
- postProcess(): void;
235
+ postProcess(): GraphNode[] | Promise<GraphNode[]>;
236
+ postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
237
+ finalize(): void;
236
238
  onError(error: unknown, errorData?: AnyObject): void;
237
239
  retry(prevResult?: any): Promise<TaskResult>;
238
240
  retryAsync(prevResult?: any): Promise<TaskResult>;
239
241
  delayRetry(): Promise<void>;
240
- divide(): GraphNode[];
242
+ divide(): GraphNode[] | Promise<GraphNode[]>;
243
+ divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
241
244
  generateNewNodes(result: any): GraphNode[];
242
245
  differentiate(task: Task): GraphNode;
243
246
  migrate(ctx: any): GraphNode;
package/dist/index.js CHANGED
@@ -934,7 +934,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
934
934
  if (this.result instanceof Promise) {
935
935
  return this.executeAsync();
936
936
  }
937
- this.postProcess();
937
+ const nextNodes = this.postProcess();
938
+ if (nextNodes instanceof Promise) {
939
+ return nextNodes;
940
+ }
941
+ this.nextNodes = nextNodes;
938
942
  }
939
943
  return this.nextNodes;
940
944
  }
@@ -950,7 +954,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
950
954
  }
951
955
  async executeAsync() {
952
956
  await this.workAsync();
953
- this.postProcess();
957
+ const nextNodes = this.postProcess();
958
+ if (nextNodes instanceof Promise) {
959
+ return nextNodes;
960
+ }
961
+ this.nextNodes = nextNodes;
954
962
  return this.nextNodes;
955
963
  }
956
964
  work() {
@@ -1036,7 +1044,20 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1036
1044
  if (Array.isArray(this.result)) {
1037
1045
  this.onError(`Returning arrays is not allowed. Returned: ${this.result}`);
1038
1046
  }
1039
- this.nextNodes = this.divide();
1047
+ const nextNodes = this.divide();
1048
+ if (nextNodes instanceof Promise) {
1049
+ return this.postProcessAsync(nextNodes);
1050
+ }
1051
+ this.nextNodes = nextNodes;
1052
+ this.finalize();
1053
+ return this.nextNodes;
1054
+ }
1055
+ async postProcessAsync(nextNodes) {
1056
+ this.nextNodes = await nextNodes;
1057
+ this.finalize();
1058
+ return this.nextNodes;
1059
+ }
1060
+ finalize() {
1040
1061
  if (this.nextNodes.length === 0) {
1041
1062
  this.completeSubgraph();
1042
1063
  }
@@ -1093,6 +1114,9 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1093
1114
  if (((_a = this.result) == null ? void 0 : _a.next) && typeof this.result.next === "function") {
1094
1115
  const generator = this.result;
1095
1116
  let current = generator.next();
1117
+ if (current instanceof Promise) {
1118
+ return this.divideAsync(current);
1119
+ }
1096
1120
  while (!current.done && current.value !== void 0) {
1097
1121
  const outputValidation = this.task.validateOutput(current.value);
1098
1122
  if (outputValidation !== true) {
@@ -1136,6 +1160,28 @@ var GraphNode = class _GraphNode extends SignalEmitter {
1136
1160
  });
1137
1161
  return newNodes;
1138
1162
  }
1163
+ async divideAsync(current) {
1164
+ const nextNodes = [];
1165
+ const _current = await current;
1166
+ const outputValidation = this.task.validateOutput(_current.value);
1167
+ if (outputValidation !== true) {
1168
+ this.onError(outputValidation.__validationErrors);
1169
+ return nextNodes;
1170
+ } else {
1171
+ nextNodes.push(...this.generateNewNodes(_current.value));
1172
+ }
1173
+ for await (const result of this.result) {
1174
+ const outputValidation2 = this.task.validateOutput(result);
1175
+ if (outputValidation2 !== true) {
1176
+ this.onError(outputValidation2.__validationErrors);
1177
+ return [];
1178
+ } else {
1179
+ nextNodes.push(...this.generateNewNodes(result));
1180
+ }
1181
+ }
1182
+ this.divided = true;
1183
+ return nextNodes;
1184
+ }
1139
1185
  generateNewNodes(result) {
1140
1186
  const groupId = (0, import_uuid3.v4)();
1141
1187
  const newNodes = [];