Files
apophis-fastify/src/domain/formula.ts
T

52 lines
1.8 KiB
TypeScript
Raw Normal View History

/**
* APOSTL AST Types
* Formula parsing and evaluation types for the APOSTL contract language.
*/
export type FormulaNode =
| { type: 'literal'; value: boolean | number | string | null }
| { type: 'variable'; name: string; accessor?: string[] | undefined }
| { type: 'comparison'; op: Comparator; left: FormulaNode; right: FormulaNode }
| { type: 'boolean'; op: BooleanOperator; left: FormulaNode; right: FormulaNode }
| { type: 'conditional'; condition: FormulaNode; then: FormulaNode; else: FormulaNode }
| { type: 'quantified'; quantifier: 'for' | 'exists'; variable: string; collection: OperationCall; body: FormulaNode }
| { type: 'operation'; header: OperationHeader; parameter: OperationParameter; accessor?: string[] | undefined }
| { type: 'previous'; inner: FormulaNode }
| { type: 'status'; code: number }
export type Comparator = '==' | '!=' | '<=' | '>=' | '<' | '>' | 'matches'
export type BooleanOperator = '&&' | '||' | '=>'
export type OperationPathSegment =
| { type: 'text'; value: string }
| { type: 'expression'; expression: FormulaNode }
export type OperationHeader =
| 'request_body'
| 'response_body'
| 'response_payload'
| 'response_code'
| 'request_headers'
| 'response_headers'
| 'query_params'
| 'cookies'
| 'response_time'
| 'request_params'
| 'redirect_count'
| 'redirect_url'
| 'redirect_status'
| 'timeout_occurred'
| 'timeout_value'
| 'request_files'
| 'request_fields'
| 'stream_chunks'
| 'stream_duration'
| string
export type OperationParameter =
| { type: 'this' }
| { type: 'call'; method: 'GET'; path: OperationPathSegment[] }
export type OperationCall = { header: OperationHeader; parameter: OperationParameter; accessor?: string[] | undefined }
export interface ParseResult {
readonly ast: FormulaNode
readonly raw: string
}