/** * Database Action type definitions */ import { DatabaseActionType } from './enums'; import { IWhereClause } from './query.interface'; import { IAggregationOperations } from './aggregation.interface'; /** * Database action definition */ export interface IActionDefinition { /** Human-readable name */ name: string; /** Unique tag in format: database_tag:action_tag */ tag: string; /** Table/collection name */ tableName: string; /** Action type */ operation: DatabaseActionType | string; /** Description of what this action does */ description?: string; /** Query template with placeholders */ template: IActionTemplate; /** Filter template for UPDATE/DELETE operations */ filterTemplate?: IWhereClause; /** Created timestamp */ createdAt?: Date; /** Updated timestamp */ updatedAt?: Date; } /** * Action template with placeholders * Placeholders use {{variableName}} syntax */ export interface IActionTemplate { /** Select columns (for QUERY) */ select?: string[]; /** Where conditions (supports placeholders) */ where?: IWhereClause | string; /** Order by configuration */ orderBy?: IActionOrderBy[]; /** Limit (supports placeholder) */ limit?: number | string; /** Offset (supports placeholder) */ offset?: number | string; /** Records to insert (for INSERT) */ records?: Record[] | string; /** Conflict columns for upsert */ conflictColumns?: string[]; /** Aggregation operations (for AGGREGATE) */ operations?: IAggregationOperations; /** Raw query (for RAW_SQL) */ query?: string; /** Query parameters (for RAW_SQL) */ params?: (string | number | boolean)[]; } /** * Order by in action template */ export interface IActionOrderBy { /** Column name (supports placeholder) */ column: string; /** Sort order (supports placeholder) */ order: 'ASC' | 'DESC' | string; } /** * Options for creating a database action */ export interface IActionCreateOptions { /** Human-readable name */ name: string; /** Unique tag in format: database_tag:action_tag */ tag: string; /** Table/collection name */ tableName: string; /** Action type */ operation: DatabaseActionType | string; /** Description of what this action does */ description?: string; /** Query template with placeholders */ template: IActionTemplate; /** Filter template for UPDATE/DELETE operations */ filterTemplate?: IWhereClause; } /** * Options for updating a database action */ export interface IActionUpdateOptions { /** Action tag to update */ tag: string; /** New name */ name?: string; /** New description */ description?: string; /** New template */ template?: IActionTemplate; /** New filter template */ filterTemplate?: IWhereClause; } /** * Options for executing a database action */ export interface IActionExecuteOptions { /** Product tag */ product: string; /** Environment */ env: string; /** Database tag */ database: string; /** Action tag (without database prefix) */ action: string; /** Input values for template placeholders */ input: Record; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for result caching */ cache?: string; } /** * Result of action execution * Type varies based on action type */ export type IActionResult = T; /** * Placeholder definition for action templates */ export interface IPlaceholder { /** Placeholder name (without braces) */ name: string; /** Expected type */ type?: 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object'; /** Required flag */ required?: boolean; /** Default value if not provided */ defaultValue?: any; /** Validation regex */ validation?: string; } /** * Parsed template with extracted placeholders */ export interface IParsedTemplate { /** Original template */ original: IActionTemplate; /** Extracted placeholders */ placeholders: IPlaceholder[]; /** Template with placeholders resolved */ resolve(input: Record): IActionTemplate; }