import { SchemaBase } from './dsl.js'; import type { DtoField, DtoMessage, DtoArrayField, DtoObjectField } from './dto.js'; import type { RefSchema } from './ref.js'; import type { ControllerMethodSchema } from './controller.js'; // Page actions: what a user can do ON a page (e.g. submit, approve, reject). // Distinguished from the cross-domain Action (journey): page actions live in // the page skeleton (PageDef.actions / PageSchema.pageDef) and describe the // page's own operation surface; journey actions describe what happens along a // business line (page / controller / third / db / task). Subclasses use // `type` as the discriminator. /** An action a user can perform on a page (e.g. submit, approve, reject). * Subclasses use `type` as the discriminator. */ export interface PageActionSchema extends SchemaBase { type: string; } export function definePageAction(name: string, description?: string): PageActionSchema { return { name, description, type: 'gesture' }; } /** Parameter data source for a call argument. */ export type DataRef = | { type: 'route'; key: string } | { type: 'data'; key: string } | { type: 'value'; value: unknown }; /** Create a route-parameter reference. */ export function route(key: string): DataRef { return { type: 'route', key }; } /** Create a page-data reference. */ export function data(key: string): DataRef { return { type: 'data', key }; } export interface CallAction extends PageActionSchema { type: 'call'; func: ControllerMethodSchema; args?: Record; } export function call(func: ControllerMethodSchema, args?: Record): CallAction { return { name: func.name, type: 'call', func, args }; } /** Assign a call's result to a page data field. * React: setState({ [field]: await ... }). Mini-program: this.setData({ [field]: ... }). */ export interface SetDataAction extends PageActionSchema { type: 'setData'; call: CallAction; field: DtoField; } export function setData(call: CallAction, field: DtoField): SetDataAction { return { name: 'setData', type: 'setData', call, field }; }