import { z } from 'zod'; import { Evt } from 'evt'; import { ioSchema, T_IO_DISPLAY_METHOD_NAMES, T_IO_METHOD_NAMES, T_IO_PROPS, T_IO_RETURNS, T_IO_STATE } from '../ioSchema'; import { IOPromiseValidator } from './IOPromise'; declare type IoSchema = typeof ioSchema; export interface ComponentInstance { methodName: MN; label: string; props?: T_IO_PROPS; state: T_IO_STATE; isStateful?: boolean; isOptional?: boolean; isMultiple?: boolean; validationErrorMessage?: string | undefined; multipleProps?: { defaultValue?: T_IO_RETURNS[] | null; }; } export declare type ComponentRenderInfo = Omit, 'state'>; export declare type ComponentReturnValue = T_IO_RETURNS; export declare type MaybeMultipleComponentReturnValue = T_IO_RETURNS | T_IO_RETURNS[]; export declare type IOComponentMap = { [MethodName in T_IO_METHOD_NAMES]: IOComponent; }; export declare type AnyIOComponent = IOComponentMap[keyof IoSchema]; export declare type DisplayComponentMap = { [MethodName in T_IO_DISPLAY_METHOD_NAMES]: IOComponent; }; export declare type AnyDisplayComponent = DisplayComponentMap[T_IO_DISPLAY_METHOD_NAMES]; /** * The internal model underlying each IOPromise, responsible for constructing * the data transmitted to Interval for an IO component, and handling responses * received from Interval. */ export default class IOComponent { schema: IoSchema[MethodName]; instance: ComponentInstance; resolver: ((v: MaybeMultipleComponentReturnValue | undefined) => void) | undefined; returnValue: Promise | undefined>; onStateChangeHandler: (() => void) | undefined; handleStateChange: ((incomingState: z.infer) => Promise>>) | undefined; onPropsUpdate: (() => T_IO_PROPS) | undefined; validator: IOPromiseValidator | undefined> | undefined; resolvesImmediately: boolean; /** * @param options.methodName - The component's method name from ioSchema, used * to determine the valid types for communication with Interval. * @param options.label - The UI label to be displayed to the action runner. * @param options.initialProps - The properties send to Interval for the initial * render call. * @param options.handleStateChange - A handler that converts new state received * from Interval into a new set of props. * @param options.isOptional - If true, the input can be omitted by the action * runner, in which case the component will accept and return `undefined`. */ constructor({ methodName, label, initialProps, onStateChange, isOptional, isMultiple, validator, multipleProps, displayResolvesImmediately, onPropsUpdate, }: { methodName: MethodName; label: string; initialProps?: T_IO_PROPS; onStateChange?: (incomingState: T_IO_STATE) => Promise>>; isOptional?: boolean; isMultiple?: boolean; validator?: IOPromiseValidator | undefined>; multipleProps?: { defaultValue?: T_IO_RETURNS[] | null; }; displayResolvesImmediately?: boolean; onPropsUpdate?: Evt>; }); handleValidation(returnValue: MaybeMultipleComponentReturnValue | undefined): Promise; setReturnValue(value: z.input): void; setState(newState: z.infer): Promise>; setProps(newProps: z.input): void; getInstance(): ComponentInstance; get label(): string; onStateChange(handler: () => void): void; getRenderInfo(): ComponentRenderInfo; } export {};