@@ -22,6 +22,20 @@ const silentLogger = () => ({ info: vi.fn(), warn: vi.fn(), debug: vi.fn() });
2222
2323const PAIR_FIELDS = { thread_id : { } , body : { } , object_name : { } , record_id : { } } ;
2424
25+ /**
26+ * What the stand-in answers: the comments with no stamped pair (the only rows
27+ * this gate pre-scans), or the requested parent ids the caller may read.
28+ */
29+ function standInRows (
30+ opts : { comments ?: Array < Record < string , unknown > > ; readable ?: Record < string , string [ ] > } ,
31+ object : string ,
32+ requested : unknown ,
33+ ) : Array < Record < string , unknown > > {
34+ if ( object === 'sys_comment' ) return ( opts . comments ?? [ ] ) . filter ( ( r ) => r . object_name == null ) ;
35+ const ids = Array . isArray ( requested ) ? requested . map ( String ) : [ ] ;
36+ return ids . filter ( ( id ) => ( opts . readable ?. [ object ] ?? [ ] ) . includes ( id ) ) . map ( ( id ) => ( { id } ) ) ;
37+ }
38+
2539type Mw = ( ctx : CommentReadMiddlewareCtx , next : ( ) => Promise < void > ) => Promise < void > ;
2640
2741/** A stand-in engine: one registry, the D5 questions answered by name, every find recorded. */
@@ -50,13 +64,7 @@ function standIn(opts: {
5064 : undefined ,
5165 find : async ( object : string , options : any ) => {
5266 finds . push ( { object, options } ) ;
53- const rows =
54- object === 'sys_comment'
55- ? ( opts . comments ?? [ ] ) . filter ( ( r ) => r . object_name == null )
56- : ( ( options ?. where ?. id ?. $in ?? [ ] ) as unknown [ ] )
57- . map ( String )
58- . filter ( ( id ) => ( opts . readable ?. [ object ] ?? [ ] ) . includes ( id ) )
59- . map ( ( id ) => ( { id } ) ) ;
67+ const rows = standInRows ( opts , object , options ?. where ?. id ?. $in ) ;
6068 return typeof options ?. limit === 'number' ? rows . slice ( 0 , options . limit ) : rows ;
6169 } ,
6270 } ;
0 commit comments