@pipelex/mthds-ui 0.42.0 → 0.44.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.
@@ -1077,25 +1077,56 @@ function pipeRefOf(node) {
1077
1077
  return makePipeRef(node.domain_code, node.pipe_code);
1078
1078
  }
1079
1079
  function findStuffByDigest(spec, digest) {
1080
- var _a, _b, _c, _d;
1080
+ var _a, _b;
1081
1081
  const consumer = findConsumer(spec, digest);
1082
- for (const node of spec.nodes) {
1083
- for (const output of (_b = (_a = node.io) == null ? void 0 : _a.outputs) != null ? _b : []) {
1084
- if (output.digest === digest) {
1085
- const producerPipeRef = pipeRefOf(node);
1086
- return __spreadValues(__spreadValues({
1087
- item: output
1088
- }, producerPipeRef ? { producerPipeRef } : {}), consumer ? { consumer } : {});
1089
- }
1090
- }
1082
+ const produced = findProducer(spec, digest);
1083
+ if (produced) {
1084
+ const producerPipeRef = pipeRefOf(produced.node);
1085
+ return __spreadValues(__spreadValues({
1086
+ item: produced.item
1087
+ }, producerPipeRef ? { producerPipeRef } : {}), consumer ? { consumer } : {});
1091
1088
  }
1092
1089
  for (const node of spec.nodes) {
1093
- for (const input of (_d = (_c = node.io) == null ? void 0 : _c.inputs) != null ? _d : []) {
1090
+ for (const input of (_b = (_a = node.io) == null ? void 0 : _a.inputs) != null ? _b : []) {
1094
1091
  if (input.digest === digest) return __spreadValues({ item: input }, consumer ? { consumer } : {});
1095
1092
  }
1096
1093
  }
1097
1094
  return null;
1098
1095
  }
1096
+ function findProducer(spec, digest) {
1097
+ var _a, _b, _c, _d;
1098
+ const listing = [];
1099
+ for (const node of spec.nodes) {
1100
+ const item = (_b = (_a = node.io) == null ? void 0 : _a.outputs) == null ? void 0 : _b.find((output) => output.digest === digest);
1101
+ if (item) listing.push({ node, item });
1102
+ }
1103
+ if (listing.length <= 1) return listing[0];
1104
+ const children = /* @__PURE__ */ new Map();
1105
+ for (const edge of (_c = spec.edges) != null ? _c : []) {
1106
+ if (edge.kind !== "contains") continue;
1107
+ const contained = children.get(edge.source);
1108
+ if (contained) contained.push(edge.target);
1109
+ else children.set(edge.source, [edge.target]);
1110
+ }
1111
+ const listed = new Set(listing.map(({ node }) => node.id));
1112
+ return (_d = listing.find(({ node }) => !containsAnyOf(node.id, children, listed))) != null ? _d : (
1113
+ // A containment cycle, which a valid spec cannot hold: the first listing.
1114
+ listing[0]
1115
+ );
1116
+ }
1117
+ function containsAnyOf(id, children, targets) {
1118
+ var _a, _b;
1119
+ const seen = /* @__PURE__ */ new Set([id]);
1120
+ const pending = [...(_a = children.get(id)) != null ? _a : []];
1121
+ while (pending.length > 0) {
1122
+ const next = pending.pop();
1123
+ if (seen.has(next)) continue;
1124
+ if (targets.has(next)) return true;
1125
+ seen.add(next);
1126
+ pending.push(...(_b = children.get(next)) != null ? _b : []);
1127
+ }
1128
+ return false;
1129
+ }
1099
1130
  function findConsumer(spec, digest) {
1100
1131
  var _a, _b;
1101
1132
  for (const node of spec.nodes) {
@@ -2869,4 +2900,4 @@ export {
2869
2900
  applySimpleFrames,
2870
2901
  GRAPH_STYLE_PIPELINES
2871
2902
  };
2872
- //# sourceMappingURL=chunk-HPARBH6K.js.map
2903
+ //# sourceMappingURL=chunk-5E3UJI2I.js.map