mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): better types for validateConnection
This commit is contained in:
parent
972398d203
commit
78f9f3ee95
@ -6,13 +6,19 @@ import { validateConnectionTypes } from 'features/nodes/store/util/validateConne
|
|||||||
import type { AnyNode } from 'features/nodes/types/invocation';
|
import type { AnyNode } from 'features/nodes/types/invocation';
|
||||||
import type { Connection as NullableConnection, Edge } from 'reactflow';
|
import type { Connection as NullableConnection, Edge } from 'reactflow';
|
||||||
import type { O } from 'ts-toolbelt';
|
import type { O } from 'ts-toolbelt';
|
||||||
|
import { assert } from 'tsafe';
|
||||||
|
|
||||||
type Connection = O.NonNullable<NullableConnection>;
|
type Connection = O.NonNullable<NullableConnection>;
|
||||||
|
|
||||||
export type ValidateConnectionResult = {
|
export type ValidateConnectionResult =
|
||||||
isValid: boolean;
|
| {
|
||||||
messageTKey?: string;
|
isValid: true;
|
||||||
};
|
messageTKey?: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
isValid: false;
|
||||||
|
messageTKey: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type ValidateConnectionFunc = (
|
export type ValidateConnectionFunc = (
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
@ -22,10 +28,20 @@ export type ValidateConnectionFunc = (
|
|||||||
ignoreEdge: Edge | null
|
ignoreEdge: Edge | null
|
||||||
) => ValidateConnectionResult;
|
) => ValidateConnectionResult;
|
||||||
|
|
||||||
export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => ({
|
export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => {
|
||||||
isValid,
|
if (isValid) {
|
||||||
messageTKey,
|
return {
|
||||||
});
|
isValid,
|
||||||
|
messageTKey,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
assert(messageTKey !== undefined);
|
||||||
|
return {
|
||||||
|
isValid,
|
||||||
|
messageTKey,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getEqualityPredicate =
|
const getEqualityPredicate =
|
||||||
(c: Connection) =>
|
(c: Connection) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user