feat(ui): better types for validateConnection

This commit is contained in:
psychedelicious 2024-05-19 01:10:49 +10:00
parent 972398d203
commit 78f9f3ee95

View File

@ -6,12 +6,18 @@ import { validateConnectionTypes } from 'features/nodes/store/util/validateConne
import type { AnyNode } from 'features/nodes/types/invocation';
import type { Connection as NullableConnection, Edge } from 'reactflow';
import type { O } from 'ts-toolbelt';
import { assert } from 'tsafe';
type Connection = O.NonNullable<NullableConnection>;
export type ValidateConnectionResult = {
isValid: boolean;
export type ValidateConnectionResult =
| {
isValid: true;
messageTKey?: string;
}
| {
isValid: false;
messageTKey: string;
};
export type ValidateConnectionFunc = (
@ -22,10 +28,20 @@ export type ValidateConnectionFunc = (
ignoreEdge: Edge | null
) => ValidateConnectionResult;
export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => ({
export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => {
if (isValid) {
return {
isValid,
messageTKey,
});
};
} else {
assert(messageTKey !== undefined);
return {
isValid,
messageTKey,
};
}
};
const getEqualityPredicate =
(c: Connection) =>