@@ -40,6 +40,7 @@ export type QueryASTNodeType =
4040 | 'offset'
4141 | 'subquery'
4242 | 'aggregate'
43+ | 'window'
4344 | 'field'
4445 | 'literal'
4546 | 'operator'
@@ -58,7 +59,7 @@ export interface QueryASTNode {
5859 */
5960export interface SelectNode extends QueryASTNode {
6061 type : 'select' ;
61- fields : ( FieldNode | AggregateNode ) [ ] ;
62+ fields : ( FieldNode | AggregateNode | WindowNode ) [ ] ;
6263 distinct ?: boolean ;
6364}
6465
@@ -79,6 +80,11 @@ export interface WhereNode extends QueryASTNode {
7980 condition : OperatorNode ;
8081}
8182
83+ /**
84+ * Join execution strategy hint (ObjectStack Spec v0.7.1)
85+ */
86+ export type JoinStrategy = 'auto' | 'database' | 'hash' | 'loop' ;
87+
8288/**
8389 * JOIN clause node (Phase 3.3.4)
8490 */
@@ -88,6 +94,7 @@ export interface JoinNode extends QueryASTNode {
8894 table : string ;
8995 alias ?: string ;
9096 on : OperatorNode ;
97+ strategy ?: JoinStrategy ; // Execution strategy hint for cross-datasource joins
9198}
9299
93100/**
@@ -140,10 +147,73 @@ export interface SubqueryNode extends QueryASTNode {
140147 */
141148export interface AggregateNode extends QueryASTNode {
142149 type : 'aggregate' ;
143- function : 'count' | 'sum' | 'avg' | 'min' | 'max' | 'first' | 'last' ;
150+ function : 'count' | 'sum' | 'avg' | 'min' | 'max' | 'first' | 'last' | 'count_distinct' | 'array_agg' | 'string_agg' ;
144151 field ?: FieldNode ;
145152 alias ?: string ;
146153 distinct ?: boolean ;
154+ separator ?: string ; // For string_agg function
155+ }
156+
157+ /**
158+ * Window function type (ObjectStack Spec v0.7.1)
159+ */
160+ export type WindowFunction =
161+ | 'row_number'
162+ | 'rank'
163+ | 'dense_rank'
164+ | 'percent_rank'
165+ | 'lag'
166+ | 'lead'
167+ | 'first_value'
168+ | 'last_value'
169+ | 'sum'
170+ | 'avg'
171+ | 'count'
172+ | 'min'
173+ | 'max' ;
174+
175+ /**
176+ * Window frame unit (ObjectStack Spec v0.7.1)
177+ */
178+ export type WindowFrameUnit = 'rows' | 'range' ;
179+
180+ /**
181+ * Window frame boundary (ObjectStack Spec v0.7.1)
182+ */
183+ export type WindowFrameBoundary =
184+ | 'unbounded_preceding'
185+ | 'unbounded_following'
186+ | 'current_row'
187+ | { type : 'preceding' ; offset : number }
188+ | { type : 'following' ; offset : number } ;
189+
190+ /**
191+ * Window frame specification (ObjectStack Spec v0.7.1)
192+ */
193+ export interface WindowFrame {
194+ unit : WindowFrameUnit ;
195+ start : WindowFrameBoundary ;
196+ end ?: WindowFrameBoundary ; // Defaults to CURRENT ROW if not specified
197+ }
198+
199+ /**
200+ * Window function node (ObjectStack Spec v0.7.1)
201+ */
202+ export interface WindowNode extends QueryASTNode {
203+ type : 'window' ;
204+ function : WindowFunction ;
205+ field ?: FieldNode ; // For aggregate window functions
206+ alias : string ;
207+ partitionBy ?: FieldNode [ ] ;
208+ orderBy ?: Array < {
209+ field : FieldNode ;
210+ direction : 'asc' | 'desc' ;
211+ } > ;
212+ frame ?: WindowFrame ;
213+
214+ // For LAG/LEAD functions
215+ offset ?: number ;
216+ defaultValue ?: LiteralNode ;
147217}
148218
149219/**
@@ -719,6 +789,199 @@ export interface AdvancedValidationError {
719789 context ?: Record < string , any > ;
720790}
721791
792+ /**
793+ * =============================================================================
794+ * ObjectStack Spec v0.7.1: Object-Level Validation Framework
795+ * =============================================================================
796+ */
797+
798+ /**
799+ * Base validation interface (ObjectStack Spec v0.7.1)
800+ */
801+ export interface BaseValidation {
802+ /** Unique validation name (snake_case) */
803+ name : string ;
804+
805+ /** Display label for the validation */
806+ label ?: string ;
807+
808+ /** Description of what this validation does */
809+ description ?: string ;
810+
811+ /** Whether this validation is currently active */
812+ active : boolean ;
813+
814+ /** When this validation should run */
815+ events : Array < 'insert' | 'update' | 'delete' > ;
816+
817+ /** Severity of validation failure */
818+ severity : 'error' | 'warning' | 'info' ;
819+
820+ /** Error message to display on failure */
821+ message : string ;
822+
823+ /** Tags for categorization */
824+ tags ?: string [ ] ;
825+ }
826+
827+ /**
828+ * Script-based validation (ObjectStack Spec v0.7.1)
829+ * Uses expression language to define conditions
830+ */
831+ export interface ScriptValidation extends BaseValidation {
832+ type : 'script' ;
833+
834+ /** Expression that must evaluate to true */
835+ condition : string ;
836+ }
837+
838+ /**
839+ * Uniqueness validation (ObjectStack Spec v0.7.1)
840+ * Ensures field combinations are unique
841+ */
842+ export interface UniquenessValidation extends BaseValidation {
843+ type : 'unique' ;
844+
845+ /** Fields that must be unique together */
846+ fields : string [ ] ;
847+
848+ /** Optional scope expression (e.g., "tenant_id = ${current_tenant}") */
849+ scope ?: string ;
850+
851+ /** Whether comparison is case-sensitive */
852+ caseSensitive ?: boolean ;
853+ }
854+
855+ /**
856+ * State machine validation (ObjectStack Spec v0.7.1)
857+ * Enforces valid state transitions
858+ */
859+ export interface StateMachineValidation extends BaseValidation {
860+ type : 'state_machine' ;
861+
862+ /** Field containing the state */
863+ stateField : string ;
864+
865+ /** Allowed state transitions */
866+ transitions : Array < {
867+ /** Source state(s) */
868+ from : string | string [ ] ;
869+
870+ /** Target state */
871+ to : string ;
872+
873+ /** Optional condition that must be true */
874+ condition ?: string ;
875+ } > ;
876+ }
877+
878+ /**
879+ * Cross-field validation (ObjectStack Spec v0.7.1)
880+ * Validates relationships between multiple fields
881+ */
882+ export interface CrossFieldValidation extends BaseValidation {
883+ type : 'cross_field' ;
884+
885+ /** Fields involved in the validation */
886+ fields : string [ ] ;
887+
888+ /** Condition expression involving multiple fields */
889+ condition : string ;
890+ }
891+
892+ /**
893+ * Async/remote validation (ObjectStack Spec v0.7.1)
894+ * Calls external endpoint for validation
895+ */
896+ export interface AsyncValidation extends BaseValidation {
897+ type : 'async' ;
898+
899+ /** API endpoint to call */
900+ endpoint : string ;
901+
902+ /** HTTP method */
903+ method ?: 'GET' | 'POST' ;
904+
905+ /** Debounce delay in milliseconds */
906+ debounce ?: number ;
907+
908+ /** Cache configuration */
909+ cache ?: {
910+ enabled : boolean ;
911+ ttl ?: number ; // Time to live in seconds
912+ } ;
913+ }
914+
915+ /**
916+ * Conditional validation (ObjectStack Spec v0.7.1)
917+ * Applies nested rules only when condition is met
918+ */
919+ export interface ConditionalValidation extends BaseValidation {
920+ type : 'conditional' ;
921+
922+ /** Condition that determines if rules should apply */
923+ condition : string ;
924+
925+ /** Nested validation rules to apply when condition is true */
926+ rules : ObjectValidationRule [ ] ;
927+ }
928+
929+ /**
930+ * Format validation (ObjectStack Spec v0.7.1)
931+ * Validates field format using regex or predefined patterns
932+ */
933+ export interface FormatValidation extends BaseValidation {
934+ type : 'format' ;
935+
936+ /** Field to validate */
937+ field : string ;
938+
939+ /** Regex pattern or predefined format name */
940+ pattern : string | RegExp ;
941+
942+ /** Predefined format (email, url, phone, etc.) */
943+ format ?: 'email' | 'url' | 'phone' | 'ipv4' | 'ipv6' | 'uuid' | 'iso_date' | 'credit_card' ;
944+
945+ /** Validation flags for regex (i, g, m, etc.) */
946+ flags ?: string ;
947+ }
948+
949+ /**
950+ * Range validation (ObjectStack Spec v0.7.1)
951+ * Validates numeric or date ranges
952+ */
953+ export interface RangeValidation extends BaseValidation {
954+ type : 'range' ;
955+
956+ /** Field to validate */
957+ field : string ;
958+
959+ /** Minimum value (inclusive) */
960+ min ?: number | string | Date ;
961+
962+ /** Maximum value (inclusive) */
963+ max ?: number | string | Date ;
964+
965+ /** Whether min is exclusive */
966+ minExclusive ?: boolean ;
967+
968+ /** Whether max is exclusive */
969+ maxExclusive ?: boolean ;
970+ }
971+
972+ /**
973+ * Union type for all validation rules (ObjectStack Spec v0.7.1)
974+ */
975+ export type ObjectValidationRule =
976+ | ScriptValidation
977+ | UniquenessValidation
978+ | StateMachineValidation
979+ | CrossFieldValidation
980+ | AsyncValidation
981+ | ConditionalValidation
982+ | FormatValidation
983+ | RangeValidation ;
984+
722985/**
723986 * =============================================================================
724987 * Phase 3.6: DriverInterface - Database Driver Abstraction
0 commit comments