@eventcatalogtest/studio
Version:
A drag and drop UI for distributed systems that keeps your diagrams where they belong – in your repo
52 lines (37 loc) • 1.8 kB
text/typescript
// src/utils/ruleEngine.js
import { Connection } from '@xyflow/react';
import eventConfig from '@/components/core/designer/nodes/core/event/config';
import serviceConfig from '@/components/core/designer/nodes/core/service/config';
import queryConfig from '@/components/core/designer/nodes/core/query/config';
import { useNodesStore } from '@/stores/nodes-store';
const nodeConfigs = {
event: eventConfig,
service: serviceConfig,
query: queryConfig,
};
// Check if connection is valid based on config rules
export const isValidConnection = (sourceType: string, targetType: string, connection: Connection) => {
const nodes = useNodesStore.getState().nodes;
const configurations = nodes.reduce((acc: any, node: any) => {
acc[node.type] = node.configuration;
return acc;
}, {});
const sourceConfig = configurations[sourceType as keyof typeof configurations];
const targetConfig = configurations[targetType as keyof typeof configurations];
if (!sourceConfig || !targetConfig) return false;
const sourceAccepts = sourceConfig.targetCanConnectTo.includes(targetType);
const targetAccepts = targetConfig.sourceCanConnectTo.includes(sourceType);
const customValidation =
sourceConfig.validateConnection?.(connection) ?? true;
return sourceAccepts && targetAccepts && customValidation;
};
export const getEdgeOptionsForConnection = (sourceType: string, targetType: string, connection: Connection) => {
const nodes = useNodesStore.getState().nodes;
const configurations = nodes.reduce((acc: any, node: any) => {
acc[node.type] = node.configuration;
return acc;
}, {});
const sourceConfig = configurations[sourceType as keyof typeof configurations];
if (!sourceConfig) return {};
return sourceConfig.getEdgeOptions?.(connection) ?? {};
};