@rkmodules/rules 0.0.163 → 0.0.164

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.cjs.js CHANGED
@@ -589,6 +589,30 @@ function mergeTrees() {
589
589
  return out;
590
590
  }
591
591
 
592
+ function mergeWithOrder() {
593
+ var objects = [];
594
+ for (var _i = 0; _i < arguments.length; _i++) {
595
+ objects[_i] = arguments[_i];
596
+ }
597
+ var merged = {};
598
+ var keys = [];
599
+ objects.forEach(function (obj) {
600
+ Object.keys(obj).forEach(function (key) {
601
+ if (!keys.includes(key)) {
602
+ keys.push(key);
603
+ }
604
+ });
605
+ });
606
+ keys.forEach(function (key) {
607
+ for (var i = objects.length - 1; i >= 0; i--) {
608
+ if (key in objects[i]) {
609
+ merged[key] = objects[i][key];
610
+ break;
611
+ }
612
+ }
613
+ });
614
+ return merged;
615
+ }
592
616
  function isReference(value) {
593
617
  return (typeof value === "string" && !!value.match(/^<([\w\.]+)>$/)
594
618
  // value.startsWith("<") &&
@@ -7059,16 +7083,22 @@ OutputNode.displayName = "OutputNode";
7059
7083
 
7060
7084
  var DynamicOutput = React.memo(function (_a) {
7061
7085
  var id = _a.id, data = _a.data, selected = _a.selected;
7062
- var _b = __read(React.useState({}), 2), outputs = _b[0], setOutputs = _b[1];
7086
+ var outputDefs = data.outputDefs || {};
7087
+ Object.keys(data.outputs || {}).forEach(function (key) {
7088
+ if (!outputDefs[key]) {
7089
+ outputDefs[key] = { type: "any", label: key };
7090
+ }
7091
+ });
7092
+ var _b = __read(React.useState(outputDefs), 2), outputs = _b[0], setOutputs = _b[1];
7063
7093
  var engine = useEngine();
7064
7094
  React.useEffect(function () {
7065
7095
  return engine.subscribe("functionResult", function (event) {
7066
7096
  if (event.name === id) {
7067
7097
  var result = event.result || {};
7068
- setOutputs(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
7098
+ setOutputs(mergeWithOrder(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
7069
7099
  name,
7070
7100
  { type: "any", label: name },
7071
- ]; })));
7101
+ ]; })), outputs));
7072
7102
  }
7073
7103
  });
7074
7104
  }, []);
@@ -7295,6 +7325,7 @@ function createNode(engine, id, fncall, options) {
7295
7325
  description: calledFn === null || calledFn === void 0 ? void 0 : calledFn.description,
7296
7326
  inputs: fncall.inputs,
7297
7327
  params: fncall.params,
7328
+ outputs: {},
7298
7329
  inputDefs: __assign(__assign({}, fncall.inputDefs), calledFn === null || calledFn === void 0 ? void 0 : calledFn.inputs),
7299
7330
  paramDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.params) || {},
7300
7331
  outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
@@ -7316,6 +7347,16 @@ function createEdge(nodeId, ref) {
7316
7347
  targetHandle: "".concat(nodeId, "-").concat(safeName(ref.name)),
7317
7348
  };
7318
7349
  }
7350
+ function addOutputToNode(nodes, ref, targetId) {
7351
+ var _a;
7352
+ var node = nodes[ref.refNode];
7353
+ if (!node) {
7354
+ console.warn("Node not found: " + ref.refNode);
7355
+ console.log(nodes, ref, targetId);
7356
+ return;
7357
+ }
7358
+ node.data.outputs = __assign(__assign({}, node.data.outputs), (_a = {}, _a[ref.refField] = "".concat(targetId, ".").concat(ref.name), _a));
7359
+ }
7319
7360
  /**
7320
7361
  * flow state stores nodes and edges for the flow graph these can be updated when the function changes
7321
7362
  * using setFn
@@ -7346,6 +7387,7 @@ var useFlowState = zustand.create(function (set, get) { return ({
7346
7387
  }
7347
7388
  var oldKeys = Object.keys((oldFn === null || oldFn === void 0 ? void 0 : oldFn.body) || {});
7348
7389
  var newKeys = Object.keys(fn.body || {});
7390
+ var edgesToAdd = [];
7349
7391
  // remove all the nodes that were removed
7350
7392
  Object.keys(nodes).forEach(function (key) {
7351
7393
  if (!newKeys.includes(key)) {
@@ -7377,7 +7419,7 @@ var useFlowState = zustand.create(function (set, get) { return ({
7377
7419
  // add edges
7378
7420
  var refs = getReferences(fncall.inputs || {});
7379
7421
  refs.forEach(function (ref) {
7380
- edges.push(createEdge(key_1, ref));
7422
+ edgesToAdd.push([key_1, ref]);
7381
7423
  });
7382
7424
  }
7383
7425
  // make sure there is an input node if inputs are defined
@@ -7402,7 +7444,7 @@ var useFlowState = zustand.create(function (set, get) { return ({
7402
7444
  // add edges
7403
7445
  var refs = getReferences(fncall.inputs || {});
7404
7446
  refs.forEach(function (ref) {
7405
- edges.push(createEdge(key, ref));
7447
+ edgesToAdd.push([key, ref]);
7406
7448
  });
7407
7449
  });
7408
7450
  // update the changed nodes
@@ -7424,9 +7466,14 @@ var useFlowState = zustand.create(function (set, get) { return ({
7424
7466
  edges = edges === null || edges === void 0 ? void 0 : edges.filter(function (e) { return e.target !== key; });
7425
7467
  // add the edge
7426
7468
  refs.forEach(function (ref) {
7427
- edges.push(createEdge(key, ref));
7469
+ edgesToAdd.push([key, ref]);
7428
7470
  });
7429
7471
  });
7472
+ edgesToAdd.forEach(function (_a) {
7473
+ var _b = __read(_a, 2), nodeId = _b[0], ref = _b[1];
7474
+ edges.push(createEdge(nodeId, ref));
7475
+ addOutputToNode(nodes, ref, nodeId);
7476
+ });
7430
7477
  // console.log("final graph", nodes, edges);
7431
7478
  // update the function, nodes and edges
7432
7479
  set({ fn: fn, nodes: nodes, edges: edges });
@@ -8738,6 +8785,7 @@ exports.isSingleTon = isSingleTon;
8738
8785
  exports.isTree = isTree;
8739
8786
  exports.mapTree = mapTree;
8740
8787
  exports.mapTreeBranch = mapTreeBranch;
8788
+ exports.mergeWithOrder = mergeWithOrder;
8741
8789
  exports.nAryOnTree = nAryOnTree;
8742
8790
  exports.nAryOnTreeBranch = nAryOnTreeBranch;
8743
8791
  exports.normalizePaths = normalizePaths;