Query Query protocol schemas
Sort Node
Represents "Order By".
Source: packages/spec/src/data/query.zod.ts
import { AggregationFunction, AggregationNode, FieldNode, FullTextSearch, JoinNode, JoinStrategy, JoinType, Query, SortNode, WindowFunction, WindowFunctionNode, WindowSpec } from '@objectstack/spec/data' ;
import type { AggregationFunction, AggregationNode, FieldNode, FullTextSearch, JoinNode, JoinStrategy, JoinType, Query, SortNode, WindowFunction, WindowFunctionNode, WindowSpec } from '@objectstack/spec/data' ;
// Validate data
const result = AggregationFunction. parse (data);
count
sum
avg
min
max
count_distinct
array_agg
string_agg
Property Type Required Description function Enum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct' | 'array_agg' | 'string_agg'>✅ Aggregation function field stringoptional Field to aggregate (optional for COUNT(*)) alias string✅ Result column alias distinct booleanoptional Apply DISTINCT before aggregation filter [__schema0](./__schema0)optional Filter/Condition to apply to the aggregation (FILTER WHERE clause)
This schema accepts one of the following structures:
Type: string
Property Type Required Description field string✅ fields [#](./#)[]optional alias stringoptional
Property Type Required Description query string✅ Search query text fields string[]optional Fields to search in (if not specified, searches all text fields) fuzzy boolean✅ Enable fuzzy matching (tolerates typos) operator Enum<'and' | 'or'>✅ Logical operator between terms boost Record<string, number>optional Field-specific relevance boosting (field name -> boost factor) minScore numberoptional Minimum relevance score threshold language stringoptional Language for text analysis (e.g., "en", "zh", "es") highlight boolean✅ Enable search result highlighting
Property Type Required Description type Enum<'inner' | 'left' | 'right' | 'full'>✅ Join type strategy Enum<'auto' | 'database' | 'hash' | 'loop'>optional Execution strategy hint object string✅ Object/table to join alias stringoptional Table alias on [__schema0](./__schema0)✅ Join condition subquery [__schema1](./__schema1)optional Subquery instead of object
Property Type Required Description object string✅ Object name (e.g. account) fields [__schema0](./__schema0)[]optional Fields to retrieve where [__schema1](./__schema1)optional Filtering criteria (WHERE) search Objectoptional Full-text search configuration ($search parameter) orderBy Object[]optional Sorting instructions (ORDER BY) limit numberoptional Max records to return (LIMIT) offset numberoptional Records to skip (OFFSET) top numberoptional Alias for limit (OData compatibility) cursor Record<string, any>optional Cursor for keyset pagination joins Object[]optional Explicit Table Joins aggregations Object[]optional Aggregation functions groupBy string[]optional GROUP BY fields having [__schema1](./__schema1)optional HAVING clause for aggregation filtering windowFunctions Object[]optional Window functions with OVER clause distinct booleanoptional SELECT DISTINCT flag expand Record<string, [#](./#)>optional Recursive relation loading map. Keys are lookup/master_detail field names; values are nested QueryAST objects that control select, filter, sort, and further expansion on the related object. The engine resolves expand via batch $in queries (driver-agnostic) with a default max depth of 3.
Property Type Required Description field string✅ order Enum<'asc' | 'desc'>✅
row_number
rank
dense_rank
percent_rank
lag
lead
first_value
last_value
sum
avg
count
min
max
Property Type Required Description function Enum<'row_number' | 'rank' | 'dense_rank' | 'percent_rank' | 'lag' | 'lead' | 'first_value' | 'last_value' | 'sum' | 'avg' | 'count' | 'min' | 'max'>✅ Window function name field stringoptional Field to operate on (for aggregate window functions) alias string✅ Result column alias over Object✅ Window specification (OVER clause)
Property Type Required Description partitionBy string[]optional PARTITION BY fields orderBy Object[]optional ORDER BY specification frame Objectoptional Window frame specification