import {type MaybeRef} from '@vueuse/core'; import {type Variant} from '@myparcel-pdk/common'; import {type OneOrMore, type PromiseOr} from '@myparcel/ts-utils'; import {type AdminAction, type AdminIcon} from '../data'; import {type ActionContext, type ActionContextWithResponse, type QueryHandler} from '../actions'; import {type Translation} from './language.types'; import { type ActionParameters, type ActionResponse, type AdminActionEndpointMap, type MaybeAdminAction, } from './actions'; interface BaseActionDefinition { disabled?: MaybeRef; icon?: AdminIcon; label?: Translation; notifications?: OneOrMore; standalone?: boolean; variant?: MaybeRef; afterHandle?(...args: unknown[]): PromiseOr; beforeHandle?(...args: unknown[]): PromiseOr; handler(...args: unknown[]): PromiseOr; } export interface NamedActionDefinition extends BaseActionDefinition { name: A; afterHandle?(context: ActionContextWithResponse): PromiseOr>; beforeHandle?(context: ActionContext): PromiseOr>; handler: QueryHandler; } export interface GenericActionDefinition extends BaseActionDefinition { name?: never; id: string; afterHandle?(context: ActionContextWithResponse): PromiseOr; beforeHandle?(context: ActionContext): PromiseOr; handler(context: ActionContext): PromiseOr; } export type AnyActionDefinition = A extends AdminAction ? NamedActionDefinition : GenericActionDefinition; export type ActionDefinition = AnyActionDefinition & { id: string; parameters?: ActionParameters; }; /** * The final action type that can be executed. */ export type ResolvedAction = BaseActionDefinition & { id: string; standalone?: boolean; handler(parameters?: ActionParameters | Record): PromiseOr; };