Skip to content

Commit

Permalink
no longer pass undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
au-re committed Sep 14, 2023
1 parent 63f05b3 commit 2f0b4db
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ exports[`running a node updates the input of its children 1`] = `
}
`;

exports[`running a node with a missing value does not override the default value in the target node 1`] = `
{
"n1": {
"input": {
"data1": "TEST DATA",
},
},
"n2": {
"input": {
"data1": "TEST DATA",
"data2": "DEFAULT_DATA_2",
},
},
}
`;

exports[`running a node with several connections to a child should update the child correctly 1`] = `
{
"n1": {
Expand Down
25 changes: 25 additions & 0 deletions packages/@pufflig/ps-chains/src/engines/dataflow/runFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
mappedExample,
multiInput,
multiInputWithOutput,
multiNodes,
multistep,
severalConnections,
simpleExec,
Expand Down Expand Up @@ -493,3 +494,27 @@ test("running a node with several connections to a child should update the child
expect(onNodeRunError).toHaveBeenCalledTimes(0);
expect(res).toMatchSnapshot();
});

/**
* (1.1)a -> (2.1)a
* (1.2)x -> (2.2)b
*/
test("running a node with a missing value does not override the default value in the target node", async () => {
const onNodeInputUpdate = jest.fn();
const onNodeRunComplete = jest.fn();
const onNodeRunError = jest.fn();
const res = await runFlow(
multiNodes,
"n1",
{ data1: "TEST DATA" },
{
onNodeRunComplete,
onNodeInputUpdate,
onNodeRunError,
}
);
expect(onNodeInputUpdate).toHaveBeenCalledTimes(2);
expect(onNodeRunComplete).toHaveBeenCalledTimes(1);
expect(onNodeRunError).toHaveBeenCalledTimes(0);
expect(res).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,20 @@ test("map the outputs of a node to the inputs of a node", async () => {
}
`);
});

test("ignore undefined values that are part of the output", async () => {
const res = mapOutputToInput(
{ 1: "a" },
{
"1": ["1", "3"],
"2": ["2"],
}
);

expect(res).toMatchInlineSnapshot(`
{
"1": "a",
"3": "a",
}
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export function getEdgeMap(edges: FlowEdge[]): Record<string, string[]> {
export function mapOutputToInput(output: Record<string, ParamValue>, map: Record<string, string[]>) {
const res: Record<string, ParamValue> = {};
for (const [key, value] of Object.entries(map)) {
value.forEach((v) => (res[v] = output[key]));
value.forEach((v) => {
// if a value is not part of the output, do not map it
if (output[key] !== undefined) {
// assign the output value to the input at the target key
res[v] = output[key];
}
});
}
return res;
}
93 changes: 93 additions & 0 deletions packages/@pufflig/ps-chains/src/mocks/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
joinNodeConfig,
loopNodeConfig,
multiInputDataNode,
passthroughNode,
simpleDataNode,
simpleExecNode,
} from "./nodes";
Expand Down Expand Up @@ -730,3 +731,95 @@ export const severalConnections: Flow = {
},
state: {},
};

export const multiNodes: Flow = {
nodeTypes: {
multi_output_node: {
name: "multiOutputNode",
inputs: [
{
name: "data1",
type: "text",
defaultValue: "DEFAULT_DATA_1",
description: "",
id: "data1",
},
],
outputs: [
{
name: "data1",
type: "text",
defaultValue: "",
description: "",
id: "data1",
},
{
name: "data2",
type: "text",
defaultValue: "",
description: "",
id: "data2",
},
],
...passthroughNode,
},
multi_input_node: {
name: "multiInputNode",
inputs: [
{
name: "data1",
type: "text",
defaultValue: "DEFAULT_DATA_1",
description: "",
id: "data1",
},
{
name: "data2",
type: "text",
defaultValue: "DEFAULT_DATA_2",
description: "",
id: "data2",
},
],
outputs: [
{
name: "data1",
type: "text",
defaultValue: "",
description: "",
id: "data1",
},
],
...passthroughNode,
},
},
definition: {
edges: {
e1: {
id: "e1",
source: "n1",
target: "n2",
sourceHandle: "data1",
targetHandle: "data1",
},
e2: {
id: "e2",
source: "n1",
target: "n2",
sourceHandle: "data2",
targetHandle: "data2",
},
},
nodes: {
n1: {
id: "n1",
type: "multi_output_node",
},
n2: {
id: "n2",
type: "multi_input_node",
},
},
},
state: {},
};
3 changes: 0 additions & 3 deletions websites/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "2.3.1"
},
"browserslist": {
"production": [
">0.5%",
Expand Down

0 comments on commit 2f0b4db

Please sign in to comment.