3333 */
3434
3535import { afterAll , beforeAll , describe , expect , it } from 'vitest' ;
36+ import type { DriverQuery } from '@objectstack/spec/contracts' ;
37+ import type { FilterCondition } from '@objectstack/spec/data' ;
3638import { SqlDriver } from './sql-driver.js' ;
3739import { DIALECT_CELLS , declareDialectCell , type DialectCell } from './live-dialect-matrix.testkit.js' ;
3840
@@ -119,8 +121,9 @@ describe('[#20280] a MySQL connection asks mysql2 for a DATE as its wire text',
119121function measure ( cell : DialectCell ) : void {
120122 describe ( `[#20280] a date reads back the day it stores — ${ cell . label } ` , ( ) => {
121123 let driver : SqlDriver ;
122- const ids = async ( where : Record < string , unknown > ) =>
123- ( await driver . find ( TABLE , { where } as any , NO_AUDIT ) ) . map ( ( r : any ) => r . id ) . sort ( ) ;
124+ const ids = async ( where : FilterCondition ) =>
125+ ( await driver . find ( TABLE , { where } , NO_AUDIT ) ) . map ( ( r : any ) => r . id ) . sort ( ) ;
126+ const findOne = async ( id : string ) : Promise < any > => driver . findOne ( TABLE , { where : { id } } , NO_AUDIT ) ;
124127
125128 beforeAll ( async ( ) => {
126129 driver = new SqlDriver ( cell . config ( ) ) ;
@@ -148,28 +151,29 @@ function measure(cell: DialectCell): void {
148151 } ) ;
149152
150153 it ( 'find() and findOne() present the stored day' , async ( ) => {
151- const rows = await driver . find ( TABLE , { } as any , NO_AUDIT ) ;
154+ const rows = await driver . find ( TABLE , { } , NO_AUDIT ) ;
152155 expect ( Object . fromEntries ( rows . map ( ( r : any ) => [ r . id , r . placed_on ] ) ) )
153156 . toEqual ( Object . fromEntries ( ROWS . map ( ( r ) => [ r . id , r . placed_on ] ) ) ) ;
154157 for ( const row of ROWS ) {
155- const one : any = await driver . findOne ( TABLE , { where : { id : row . id } } as any , NO_AUDIT ) ;
156- expect ( one ?. placed_on , row . id ) . toBe ( row . placed_on ) ;
158+ expect ( ( await findOne ( row . id ) ) ?. placed_on , row . id ) . toBe ( row . placed_on ) ;
157159 }
158160 } ) ;
159161
160162 it ( 'a groupBy key, distinct() and min / max present the stored day' , async ( ) => {
161- const grouped = await driver . aggregate ( TABLE , {
163+ const byDay : DriverQuery = {
162164 groupBy : [ 'placed_on' ] ,
163165 aggregations : [ { function : 'count' , alias : 'n' } ] ,
164- } as any ) ;
166+ } ;
167+ const grouped = await driver . aggregate ( TABLE , byDay ) ;
165168 expect ( grouped . map ( ( r : any ) => r . placed_on ) . sort ( ) ) . toEqual ( [ ...DAYS ] . sort ( ) ) ;
166169 expect ( ( await driver . distinct ( TABLE , 'placed_on' , undefined , NO_AUDIT ) ) . sort ( ) ) . toEqual ( [ ...DAYS ] . sort ( ) ) ;
167- const [ range ] : any [ ] = await driver . aggregate ( TABLE , {
170+ const firstAndLast : DriverQuery = {
168171 aggregations : [
169172 { function : 'min' , field : 'placed_on' , alias : 'first' } ,
170173 { function : 'max' , field : 'placed_on' , alias : 'last' } ,
171174 ] ,
172- } as any ) ;
175+ } ;
176+ const [ range ] : any [ ] = await driver . aggregate ( TABLE , firstAndLast ) ;
173177 expect ( range . first ) . toBe ( '0009-03-04' ) ;
174178 expect ( range . last ) . toBe ( '2026-03-04' ) ;
175179 } ) ;
@@ -181,7 +185,7 @@ function measure(cell: DialectCell): void {
181185 } ) ;
182186
183187 it ( 'a datetime is presented as before: right on SQLite and PostgreSQL, a MySQL year below 100 still folded (observed)' , async ( ) => {
184- const rows = await driver . find ( TABLE , { } as any , NO_AUDIT ) ;
188+ const rows = await driver . find ( TABLE , { } , NO_AUDIT ) ;
185189 expect ( Object . fromEntries ( rows . map ( ( r : any ) => [ r . id , r . opened_at ] ) ) )
186190 . toEqual ( Object . fromEntries ( ROWS . map ( ( r ) => [ r . id , presentedInstant ( cell , r ) ] ) ) ) ;
187191 } ) ;
@@ -203,9 +207,9 @@ function measure(cell: DialectCell): void {
203207
204208 it ( 'a write then a read round-trips a year below 100 — create, update, findOne' , async ( ) => {
205209 await driver . create ( TABLE , { id : 'rt' , placed_on : '0042-01-31' } , NO_AUDIT ) ;
206- expect ( ( await driver . findOne ( TABLE , { where : { id : 'rt' } } as any , NO_AUDIT ) as any ) ?. placed_on ) . toBe ( '0042-01-31' ) ;
210+ expect ( ( await findOne ( 'rt' ) ) ?. placed_on ) . toBe ( '0042-01-31' ) ;
207211 await driver . update ( TABLE , 'rt' , { placed_on : '0001-12-31' } , NO_AUDIT ) ;
208- expect ( ( await driver . findOne ( TABLE , { where : { id : 'rt' } } as any , NO_AUDIT ) as any ) ?. placed_on ) . toBe ( '0001-12-31' ) ;
212+ expect ( ( await findOne ( 'rt' ) ) ?. placed_on ) . toBe ( '0001-12-31' ) ;
209213 } ) ;
210214 } ) ;
211215}
0 commit comments