2525 */
2626
2727import { describe , it , expect , beforeAll , afterAll } from 'vitest' ;
28+ import type { EngineAggregateOptions , FilterCondition } from '@objectstack/spec/data' ;
2829import { ObjectQL } from '@objectstack/objectql' ;
2930import { SqlDriver } from '@objectstack/driver-sql' ;
3031import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol' ;
@@ -129,7 +130,7 @@ describe('[#20203] where — an epoch-ms number on a date field, engine and REST
129130 it ( `${ op } : ${ onDate . join ( ', ' ) } on both doors; nothing on an empty table; the datetime control reads the instant` , async ( ) => {
130131 for ( const [ state , expectDate , expectDatetime ] of [ [ 'populated' , onDate , onDatetime ] , [ 'empty' , [ ] , [ ] ] ] as const ) {
131132 const { engine, post } = doors [ state ] ;
132- expect ( sortedIds ( await engine . find ( OBJECT , { where : { placed_on : comparand } } as any ) ) , `engine, ${ state } ` ) . toEqual ( expectDate ) ;
133+ expect ( sortedIds ( await engine . find ( OBJECT , { where : { placed_on : comparand } } ) ) , `engine, ${ state } ` ) . toEqual ( expectDate ) ;
133134 expect ( sortedIds ( await post ( { where : { placed_on : comparand } } ) ) , `REST, ${ state } ` ) . toEqual ( expectDate ) ;
134135 expect ( sortedIds ( await post ( { where : { opened_at : comparand } } ) ) , `datetime control, ${ state } ` ) . toEqual ( expectDatetime ) ;
135136 }
@@ -138,7 +139,7 @@ describe('[#20203] where — an epoch-ms number on a date field, engine and REST
138139} ) ;
139140
140141describe ( '[#20203] a per-aggregation filter counts what its where twin counts' , ( ) => {
141- const perAggregation = ( filter : unknown ) => ( {
142+ const perAggregation = ( filter : FilterCondition ) : EngineAggregateOptions => ( {
142143 aggregations : [ { function : 'count' , alias : 'n' } , { function : 'count' , alias : 'm' , filter } ] ,
143144 } ) ;
144145 for ( const [ op , comparand , onDate ] of OPERATORS ) {
@@ -147,15 +148,15 @@ describe('[#20203] a per-aggregation filter counts what its where twin counts',
147148 const { engine, post } = doors [ state ] ;
148149 const expected = state === 'populated' ? onDate . length : 0 ;
149150 const query = perAggregation ( { placed_on : comparand } ) ;
150- expect ( ( await engine . aggregate ( OBJECT , query as any ) ) [ 0 ] ?. m , `engine, ${ state } ` ) . toBe ( expected ) ;
151+ expect ( ( await engine . aggregate ( OBJECT , query ) ) [ 0 ] ?. m , `engine, ${ state } ` ) . toBe ( expected ) ;
151152 expect ( ( await post ( query ) ) [ 0 ] ?. m , `REST, ${ state } ` ) . toBe ( expected ) ;
152153 }
153154 } ) ;
154155 }
155156} ) ;
156157
157158describe ( '[#20203] having on max(date) reads the number as a calendar day' , ( ) => {
158- const grouped = ( having : unknown ) => ( {
159+ const grouped = ( having : FilterCondition ) : EngineAggregateOptions => ( {
159160 groupBy : [ 'customer_id' ] ,
160161 aggregations : [
161162 { function : 'max' , field : 'placed_on' , alias : 'last_placed' } ,
@@ -164,7 +165,7 @@ describe('[#20203] having on max(date) reads the number as a calendar day', () =
164165 having,
165166 } ) ;
166167 // c1: last_placed 2026-01-10 · c2: 2026-03-01 · c3: 2026-02-01
167- const HAVING : ReadonlyArray < readonly [ string , Record < string , unknown > , string [ ] ] > = [
168+ const HAVING : ReadonlyArray < readonly [ string , FilterCondition , string [ ] ] > = [
168169 [ '$gt on max(date)' , { last_placed : { $gt : N } } , [ 'c2' ] ] ,
169170 [ '$eq on max(date)' , { last_placed : { $eq : N } } , [ 'c3' ] ] ,
170171 [ '$in on max(date)' , { last_placed : { $in : [ N , N_JAN10 ] } } , [ 'c1' , 'c3' ] ] ,
@@ -176,7 +177,7 @@ describe('[#20203] having on max(date) reads the number as a calendar day', () =
176177 const { engine, post } = doors [ state ] ;
177178 const expected = state === 'populated' ? kept : [ ] ;
178179 const q = grouped ( having ) ;
179- expect ( ( await engine . aggregate ( OBJECT , q as any ) ) . map ( ( r : any ) => r . customer_id ) . sort ( ) , `engine, ${ state } ` ) . toEqual ( expected ) ;
180+ expect ( ( await engine . aggregate ( OBJECT , q ) ) . map ( ( r : any ) => r . customer_id ) . sort ( ) , `engine, ${ state } ` ) . toEqual ( expected ) ;
180181 expect ( ( await post ( q ) ) . map ( ( r ) => r . customer_id ) . sort ( ) , `REST, ${ state } ` ) . toEqual ( expected ) ;
181182 }
182183 } ) ;
0 commit comments