@@ -37,20 +37,27 @@ const tables: Record<string, Row[]> = {
3737 ...Object . fromEntries ( Object . keys ( TARGETS ) . map ( ( k ) => [ `t_${ k } ` , [ { id : `${ k } _1` , name : `${ k } title` } ] ] ) ) ,
3838} ;
3939
40- function makeService ( unreadable ?: string ) {
40+ /** The two engine members the enrichment reads; `unreadable` names a target whose declaration throws. */
41+ function makeEngine ( rows : Record < string , Row [ ] > , unreadable ?: string ) {
4142 const reads : string [ ] = [ ] ;
42- const warn = vi . fn ( ) ;
4343 const engine = {
4444 getSchema ( object : string ) {
4545 if ( object === unreadable ) throw new Error ( 'declaration unavailable' ) ;
4646 return schemas [ object ] ;
4747 } ,
48- async find ( object : string , options ?: { where ?: { id ?: { $in ?: string [ ] } } } ) {
48+ // Each table holds the one row a read can ask for, so the double answers the
49+ // table whole: what is pinned is WHICH objects are read, not the query.
50+ async find ( object : string ) {
4951 reads . push ( object ) ;
50- const wanted = options ?. where ?. id ?. $in ;
51- return ( tables [ object ] ?? [ ] ) . filter ( ( r ) => ! wanted || wanted . includes ( String ( r . id ) ) ) ;
52+ return rows [ object ] ?? [ ] ;
5253 } ,
5354 } ;
55+ return { engine, reads } ;
56+ }
57+
58+ function makeService ( unreadable ?: string ) {
59+ const warn = vi . fn ( ) ;
60+ const { engine, reads } = makeEngine ( tables , unreadable ) ;
5461 const service = new ApprovalService ( { engine : engine as any , logger : { info ( ) { } , warn, error ( ) { } , debug ( ) { } } } ) ;
5562 // `enrichRows` is private; its public callers drag the whole request lifecycle in.
5663 const enrich = ( rows : Row [ ] ) => ( service as unknown as { enrichRows ( r : Row [ ] ) : Promise < void > } ) . enrichRows ( rows ) ;
0 commit comments