Skip to content

Commit 935c8c3

Browse files
committed
feat: update version to 0.5.1 and enhance connection validation logic for data type compatibility
1 parent 1f83bbe commit 935c8c3

3 files changed

Lines changed: 59 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-wireflow",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"type": "module",
55
"main": "dist/index.cjs",
66
"module": "dist/index.js",

src/core/connection/validation.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,58 @@ describe("canConnectPorts - data type compatibility", () => {
252252
const inPort: Port = { id: "in", nodeId: "b", type: "input", label: "in", position: "left", dataType: "json" };
253253
expect(canConnectPorts(outPort, inPort, defA, defB)).toBe(true);
254254
});
255+
256+
it("uses port dataType when multiple definitions share same id (instances pattern)", () => {
257+
// Simulates a node with multiple PortDefinitions that share the same id
258+
// but have different dataTypes, selected via `instances` function.
259+
// Example: artifact-io with scope-out having typed-object, object, string, binary variants
260+
const defWithMultipleSameIdPorts = baseNodeDef("ArtifactIO", [
261+
{ id: "scope-out", type: "output", label: "Scope (Typed Object)", position: "right", dataType: "typed-object", instances: () => 0 },
262+
{ id: "scope-out", type: "output", label: "Scope (Object)", position: "right", dataType: "object", instances: () => 0 },
263+
{ id: "scope-out", type: "output", label: "Scope (String)", position: "right", dataType: "string", instances: () => 1 }, // Active one
264+
{ id: "scope-out", type: "output", label: "Scope (Binary)", position: "right", dataType: "binary", instances: () => 0 },
265+
]);
266+
const defConsumer = baseNodeDef("Consumer", [
267+
{ id: "in", type: "input", label: "in", position: "left", dataType: "string" },
268+
]);
269+
270+
// The derived Port has dataType: "string" from the active definition
271+
const derivedPort: Port = {
272+
id: "scope-out",
273+
definitionId: "scope-out",
274+
nodeId: "artifact",
275+
type: "output",
276+
label: "Scope (String)",
277+
position: "right",
278+
dataType: "string", // Set during port derivation from active PortDefinition
279+
};
280+
const consumerPort: Port = {
281+
id: "in",
282+
nodeId: "consumer",
283+
type: "input",
284+
label: "in",
285+
position: "left",
286+
dataType: "string",
287+
};
288+
289+
// Should connect because Port.dataType is "string" (not "typed-object" from first matching definition)
290+
expect(canConnectPorts(derivedPort, consumerPort, defWithMultipleSameIdPorts, defConsumer)).toBe(true);
291+
292+
// Verify incompatible type is rejected
293+
const binaryConsumer = baseNodeDef("BinaryConsumer", [
294+
{ id: "in", type: "input", label: "in", position: "left", dataType: "binary" },
295+
]);
296+
const binaryPort: Port = {
297+
id: "in",
298+
nodeId: "binary-consumer",
299+
type: "input",
300+
label: "in",
301+
position: "left",
302+
dataType: "binary",
303+
};
304+
// Should NOT connect because string !== binary
305+
expect(canConnectPorts(derivedPort, binaryPort, defWithMultipleSameIdPorts, binaryConsumer)).toBe(false);
306+
});
255307
});
256308

257309
describe("canConnectPorts - maxConnections default/unlimited", () => {

src/core/connection/validation.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@ export const canConnectNormalizedPorts = (
6868
}
6969

7070
// Check data type compatibility
71+
// Port.dataType is set during derivation from the active PortDefinition,
72+
// so it takes priority. Only fall back to PortDefinition lookup when Port.dataType is not set.
73+
// This is important when multiple PortDefinitions share the same id but have different
74+
// dataTypes (selected via instances function).
7175
const sourcePortDef = getPortDefinition(sourcePort, sourceDefinition);
7276
const targetPortDef = getPortDefinition(targetPort, targetDefinition);
73-
const sourceTypes = mergePortDataTypes(
74-
sourcePort.dataType,
75-
mergePortDataTypes(sourcePortDef?.dataType, sourcePortDef?.dataTypes),
76-
);
77-
const targetTypes = mergePortDataTypes(
78-
targetPort.dataType,
79-
mergePortDataTypes(targetPortDef?.dataType, targetPortDef?.dataTypes),
80-
);
77+
const sourceTypes = sourcePort.dataType ?? mergePortDataTypes(sourcePortDef?.dataType, sourcePortDef?.dataTypes);
78+
const targetTypes = targetPort.dataType ?? mergePortDataTypes(targetPortDef?.dataType, targetPortDef?.dataTypes);
8179
if (!arePortDataTypesCompatible(sourceTypes, targetTypes)) {
8280
return false;
8381
}

0 commit comments

Comments
 (0)