@openfn/project 0.10.0 → 0.10.1

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 (2) hide show
  1. package/dist/index.js +25 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -361,11 +361,17 @@ var mapWorkflow = (workflow) => {
361
361
  } else {
362
362
  e.source_job_id = node.id;
363
363
  }
364
- if (rules.condition === true) {
365
- e.condition_type = "always";
366
- } else if (rules.condition === false) {
367
- e.condition_type = "never";
368
- } else if (typeof rules.condition === "string") {
364
+ if (rules.condition) {
365
+ if (typeof rules.condition === "boolean") {
366
+ e.condition_type = rules.condition ? "always" : "never";
367
+ } else if (rules.condition.match(
368
+ /^(always|never|on_job_success|on_job_failure)$/
369
+ )) {
370
+ e.condition_type = rules.condition;
371
+ } else {
372
+ e.condition_type = "js_expression";
373
+ e.condition_expression = rules.condition;
374
+ }
369
375
  }
370
376
  wfState.edges.push(e);
371
377
  });
@@ -652,20 +658,23 @@ var from_app_state_default = (state, meta = {}, config = {}) => {
652
658
  proj.workflows = stateJson.workflows.map(mapWorkflow2);
653
659
  return new Project(proj, config);
654
660
  };
655
- var mapTriggerEdgeCondition = (edge) => {
661
+ var mapEdge = (edge) => {
656
662
  const e = {
657
663
  disabled: !edge.enabled
658
664
  };
659
- if (edge.condition_type === "always") {
660
- e.condition = true;
661
- } else if (edge.condition_type === "never") {
662
- e.condition = false;
663
- } else {
665
+ if (edge.condition_type === "js_expression") {
664
666
  e.condition = edge.condition_expression;
667
+ } else if (edge.condition_type) {
668
+ e.condition = edge.condition_type;
669
+ }
670
+ if (edge.condition_label) {
671
+ e.name = edge.condition_label;
672
+ }
673
+ if (edge.id) {
674
+ e.openfn = {
675
+ uuid: edge.id
676
+ };
665
677
  }
666
- e.openfn = {
667
- uuid: edge.id
668
- };
669
678
  return e;
670
679
  };
671
680
  var mapWorkflow2 = (workflow) => {
@@ -693,7 +702,7 @@ var mapWorkflow2 = (workflow) => {
693
702
  if (!target) {
694
703
  throw new Error(`Failed to find ${edge.target_job_id}`);
695
704
  }
696
- obj[slugify(target.name)] = mapTriggerEdgeCondition(edge);
705
+ obj[slugify(target.name)] = mapEdge(edge);
697
706
  return obj;
698
707
  }, {})
699
708
  });
@@ -723,7 +732,7 @@ var mapWorkflow2 = (workflow) => {
723
732
  if (outboundEdges.length) {
724
733
  s.next = outboundEdges.reduce((next, edge) => {
725
734
  const target = jobs.find((j) => j.id === edge.target_job_id);
726
- next[slugify(target.name)] = mapTriggerEdgeCondition(edge);
735
+ next[slugify(target.name)] = mapEdge(edge);
727
736
  return next;
728
737
  }, {});
729
738
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/project",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Read, serialize, replicate and sync OpenFn projects",
5
5
  "type": "module",
6
6
  "exports": {