@workglow/task-graph 0.0.69 → 0.0.71

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/bun.js CHANGED
@@ -12,15 +12,14 @@ import { compileSchema as compileSchema2 } from "@workglow/util";
12
12
  import { areSemanticallyCompatible, EventEmitter } from "@workglow/util";
13
13
 
14
14
  // src/task/TaskTypes.ts
15
- var TaskStatus;
16
- ((TaskStatus2) => {
17
- TaskStatus2["PENDING"] = "PENDING";
18
- TaskStatus2["DISABLED"] = "DISABLED";
19
- TaskStatus2["PROCESSING"] = "PROCESSING";
20
- TaskStatus2["COMPLETED"] = "COMPLETED";
21
- TaskStatus2["ABORTING"] = "ABORTING";
22
- TaskStatus2["FAILED"] = "FAILED";
23
- })(TaskStatus ||= {});
15
+ var TaskStatus = {
16
+ PENDING: "PENDING",
17
+ DISABLED: "DISABLED",
18
+ PROCESSING: "PROCESSING",
19
+ COMPLETED: "COMPLETED",
20
+ ABORTING: "ABORTING",
21
+ FAILED: "FAILED"
22
+ };
24
23
 
25
24
  // src/task-graph/Dataflow.ts
26
25
  var DATAFLOW_ALL_PORTS = "*";
@@ -45,10 +44,10 @@ class Dataflow {
45
44
  }
46
45
  value = undefined;
47
46
  provenance = {};
48
- status = "PENDING" /* PENDING */;
47
+ status = TaskStatus.PENDING;
49
48
  error;
50
49
  reset() {
51
- this.status = "PENDING" /* PENDING */;
50
+ this.status = TaskStatus.PENDING;
52
51
  this.error = undefined;
53
52
  this.value = undefined;
54
53
  this.provenance = {};
@@ -60,22 +59,22 @@ class Dataflow {
60
59
  return;
61
60
  this.status = status;
62
61
  switch (status) {
63
- case "PROCESSING" /* PROCESSING */:
62
+ case TaskStatus.PROCESSING:
64
63
  this.emit("start");
65
64
  break;
66
- case "COMPLETED" /* COMPLETED */:
65
+ case TaskStatus.COMPLETED:
67
66
  this.emit("complete");
68
67
  break;
69
- case "ABORTING" /* ABORTING */:
68
+ case TaskStatus.ABORTING:
70
69
  this.emit("abort");
71
70
  break;
72
- case "PENDING" /* PENDING */:
71
+ case TaskStatus.PENDING:
73
72
  this.emit("reset");
74
73
  break;
75
- case "FAILED" /* FAILED */:
74
+ case TaskStatus.FAILED:
76
75
  this.emit("error", this.error);
77
76
  break;
78
- case "DISABLED" /* DISABLED */:
77
+ case TaskStatus.DISABLED:
79
78
  this.emit("disabled");
80
79
  break;
81
80
  }
@@ -329,7 +328,7 @@ class TaskRunner {
329
328
  }
330
329
  }
331
330
  async runReactive(overrides = {}) {
332
- if (this.task.status === "PROCESSING" /* PROCESSING */) {
331
+ if (this.task.status === TaskStatus.PROCESSING) {
333
332
  return this.task.runOutputData;
334
333
  }
335
334
  this.task.setInput(overrides);
@@ -373,13 +372,13 @@ class TaskRunner {
373
372
  return Object.keys(reactiveResult || {}) >= Object.keys(output || {}) ? reactiveResult : output ?? {};
374
373
  }
375
374
  async handleStart(config = {}) {
376
- if (this.task.status === "PROCESSING" /* PROCESSING */)
375
+ if (this.task.status === TaskStatus.PROCESSING)
377
376
  return;
378
377
  this.nodeProvenance = {};
379
378
  this.running = true;
380
379
  this.task.startedAt = new Date;
381
380
  this.task.progress = 0;
382
- this.task.status = "PROCESSING" /* PROCESSING */;
381
+ this.task.status = TaskStatus.PROCESSING;
383
382
  this.abortController = new AbortController;
384
383
  this.abortController.signal.addEventListener("abort", () => {
385
384
  this.handleAbort();
@@ -405,9 +404,9 @@ class TaskRunner {
405
404
  this.reactiveRunning = true;
406
405
  }
407
406
  async handleAbort() {
408
- if (this.task.status === "ABORTING" /* ABORTING */)
407
+ if (this.task.status === TaskStatus.ABORTING)
409
408
  return;
410
- this.task.status = "ABORTING" /* ABORTING */;
409
+ this.task.status = TaskStatus.ABORTING;
411
410
  this.task.progress = 100;
412
411
  this.task.error = new TaskAbortedError;
413
412
  this.task.emit("abort", this.task.error);
@@ -417,11 +416,11 @@ class TaskRunner {
417
416
  this.reactiveRunning = false;
418
417
  }
419
418
  async handleComplete() {
420
- if (this.task.status === "COMPLETED" /* COMPLETED */)
419
+ if (this.task.status === TaskStatus.COMPLETED)
421
420
  return;
422
421
  this.task.completedAt = new Date;
423
422
  this.task.progress = 100;
424
- this.task.status = "COMPLETED" /* COMPLETED */;
423
+ this.task.status = TaskStatus.COMPLETED;
425
424
  this.abortController = undefined;
426
425
  this.nodeProvenance = {};
427
426
  this.task.emit("complete");
@@ -431,9 +430,9 @@ class TaskRunner {
431
430
  this.reactiveRunning = false;
432
431
  }
433
432
  async handleDisable() {
434
- if (this.task.status === "DISABLED" /* DISABLED */)
433
+ if (this.task.status === TaskStatus.DISABLED)
435
434
  return;
436
- this.task.status = "DISABLED" /* DISABLED */;
435
+ this.task.status = TaskStatus.DISABLED;
437
436
  this.task.progress = 100;
438
437
  this.task.completedAt = new Date;
439
438
  this.abortController = undefined;
@@ -447,14 +446,14 @@ class TaskRunner {
447
446
  async handleError(err) {
448
447
  if (err instanceof TaskAbortedError)
449
448
  return this.handleAbort();
450
- if (this.task.status === "FAILED" /* FAILED */)
449
+ if (this.task.status === TaskStatus.FAILED)
451
450
  return;
452
451
  if (this.task.hasChildren()) {
453
452
  this.task.subGraph.abort();
454
453
  }
455
454
  this.task.completedAt = new Date;
456
455
  this.task.progress = 100;
457
- this.task.status = "FAILED" /* FAILED */;
456
+ this.task.status = TaskStatus.FAILED;
458
457
  this.task.error = err instanceof TaskError ? err : new TaskFailedError(err?.message || "Task failed");
459
458
  this.abortController = undefined;
460
459
  this.nodeProvenance = {};
@@ -542,7 +541,7 @@ class Task {
542
541
  runInputData = {};
543
542
  runOutputData = {};
544
543
  config;
545
- status = "PENDING" /* PENDING */;
544
+ status = TaskStatus.PENDING;
546
545
  progress = 0;
547
546
  createdAt = new Date;
548
547
  startedAt;
@@ -972,24 +971,24 @@ class DependencyBasedScheduler {
972
971
  this.reset();
973
972
  }
974
973
  isTaskReady(task) {
975
- if (task.status === "DISABLED" /* DISABLED */) {
974
+ if (task.status === TaskStatus.DISABLED) {
976
975
  return false;
977
976
  }
978
977
  const sourceDataflows = this.dag.getSourceDataflows(task.config.id);
979
978
  if (sourceDataflows.length > 0) {
980
- const allIncomingDisabled = sourceDataflows.every((df) => df.status === "DISABLED" /* DISABLED */);
979
+ const allIncomingDisabled = sourceDataflows.every((df) => df.status === TaskStatus.DISABLED);
981
980
  if (allIncomingDisabled) {
982
981
  return false;
983
982
  }
984
983
  }
985
- const dependencies = sourceDataflows.filter((df) => df.status !== "DISABLED" /* DISABLED */).map((dataflow) => dataflow.sourceTaskId);
984
+ const dependencies = sourceDataflows.filter((df) => df.status !== TaskStatus.DISABLED).map((dataflow) => dataflow.sourceTaskId);
986
985
  return dependencies.every((dep) => this.completedTasks.has(dep));
987
986
  }
988
987
  async waitForNextTask() {
989
988
  if (this.pendingTasks.size === 0)
990
989
  return null;
991
990
  for (const task of Array.from(this.pendingTasks)) {
992
- if (task.status === "DISABLED" /* DISABLED */) {
991
+ if (task.status === TaskStatus.DISABLED) {
993
992
  this.pendingTasks.delete(task);
994
993
  }
995
994
  }
@@ -1020,7 +1019,7 @@ class DependencyBasedScheduler {
1020
1019
  onTaskCompleted(taskId) {
1021
1020
  this.completedTasks.add(taskId);
1022
1021
  for (const task of Array.from(this.pendingTasks)) {
1023
- if (task.status === "DISABLED" /* DISABLED */) {
1022
+ if (task.status === TaskStatus.DISABLED) {
1024
1023
  this.pendingTasks.delete(task);
1025
1024
  }
1026
1025
  }
@@ -1123,7 +1122,7 @@ class TaskGraphRunner {
1123
1122
  const results = [];
1124
1123
  try {
1125
1124
  for await (const task of this.reactiveScheduler.tasks()) {
1126
- if (task.status === "PENDING" /* PENDING */) {
1125
+ if (task.status === TaskStatus.PENDING) {
1127
1126
  task.resetInputData();
1128
1127
  this.copyInputFromEdgesToNode(task);
1129
1128
  }
@@ -1220,7 +1219,7 @@ class TaskGraphRunner {
1220
1219
  return;
1221
1220
  const dataflows = graph.getTargetDataflows(node.config.id);
1222
1221
  const effectiveStatus = status ?? node.status;
1223
- if (node instanceof ConditionalTask && effectiveStatus === "COMPLETED" /* COMPLETED */) {
1222
+ if (node instanceof ConditionalTask && effectiveStatus === TaskStatus.COMPLETED) {
1224
1223
  const branches = node.config.branches ?? [];
1225
1224
  const portToBranch = new Map;
1226
1225
  for (const branch of branches) {
@@ -1231,9 +1230,9 @@ class TaskGraphRunner {
1231
1230
  const branchId = portToBranch.get(dataflow.sourceTaskPortId);
1232
1231
  if (branchId !== undefined) {
1233
1232
  if (activeBranches.has(branchId)) {
1234
- dataflow.setStatus("COMPLETED" /* COMPLETED */);
1233
+ dataflow.setStatus(TaskStatus.COMPLETED);
1235
1234
  } else {
1236
- dataflow.setStatus("DISABLED" /* DISABLED */);
1235
+ dataflow.setStatus(TaskStatus.DISABLED);
1237
1236
  }
1238
1237
  } else {
1239
1238
  dataflow.setStatus(effectiveStatus);
@@ -1258,22 +1257,22 @@ class TaskGraphRunner {
1258
1257
  while (changed) {
1259
1258
  changed = false;
1260
1259
  for (const task of graph.getTasks()) {
1261
- if (task.status !== "PENDING" /* PENDING */) {
1260
+ if (task.status !== TaskStatus.PENDING) {
1262
1261
  continue;
1263
1262
  }
1264
1263
  const incomingDataflows = graph.getSourceDataflows(task.config.id);
1265
1264
  if (incomingDataflows.length === 0) {
1266
1265
  continue;
1267
1266
  }
1268
- const allDisabled = incomingDataflows.every((df) => df.status === "DISABLED" /* DISABLED */);
1267
+ const allDisabled = incomingDataflows.every((df) => df.status === TaskStatus.DISABLED);
1269
1268
  if (allDisabled) {
1270
- task.status = "DISABLED" /* DISABLED */;
1269
+ task.status = TaskStatus.DISABLED;
1271
1270
  task.progress = 100;
1272
1271
  task.completedAt = new Date;
1273
1272
  task.emit("disabled");
1274
1273
  task.emit("status", task.status);
1275
1274
  graph.getTargetDataflows(task.config.id).forEach((dataflow) => {
1276
- dataflow.setStatus("DISABLED" /* DISABLED */);
1275
+ dataflow.setStatus(TaskStatus.DISABLED);
1277
1276
  });
1278
1277
  this.processScheduler.onTaskCompleted(task.config.id);
1279
1278
  changed = true;
@@ -1302,7 +1301,7 @@ class TaskGraphRunner {
1302
1301
  };
1303
1302
  }
1304
1303
  resetTask(graph, task, runId) {
1305
- task.status = "PENDING" /* PENDING */;
1304
+ task.status = TaskStatus.PENDING;
1306
1305
  task.resetInputData();
1307
1306
  task.runOutputData = {};
1308
1307
  task.error = undefined;
@@ -1379,7 +1378,7 @@ class TaskGraphRunner {
1379
1378
  }
1380
1379
  async handleError(error) {
1381
1380
  await Promise.allSettled(this.graph.getTasks().map(async (task) => {
1382
- if (["PROCESSING" /* PROCESSING */].includes(task.status)) {
1381
+ if (task.status === TaskStatus.PROCESSING) {
1383
1382
  task.abort();
1384
1383
  }
1385
1384
  }));
@@ -1391,7 +1390,7 @@ class TaskGraphRunner {
1391
1390
  }
1392
1391
  async handleAbort() {
1393
1392
  this.graph.getTasks().map(async (task) => {
1394
- if (["PROCESSING" /* PROCESSING */].includes(task.status)) {
1393
+ if (task.status === TaskStatus.PROCESSING) {
1395
1394
  task.abort();
1396
1395
  }
1397
1396
  });
@@ -1403,7 +1402,7 @@ class TaskGraphRunner {
1403
1402
  }
1404
1403
  async handleDisable() {
1405
1404
  await Promise.allSettled(this.graph.getTasks().map(async (task) => {
1406
- if (["PENDING" /* PENDING */].includes(task.status)) {
1405
+ if (task.status === TaskStatus.PENDING) {
1407
1406
  return task.disable();
1408
1407
  }
1409
1408
  }));
@@ -2969,4 +2968,4 @@ export {
2969
2968
  ArrayTask
2970
2969
  };
2971
2970
 
2972
- //# debugId=27CCA088711684C364756E2164756E21
2971
+ //# debugId=2F96C85065C7570864756E2164756E21