@@ -5,14 +5,24 @@ import type { BIDSFile } from '../types/filetree.ts'
55import type { BIDSContext } from './context.ts'
66import { loadTSV } from '../files/tsv.ts'
77import { parseBvalBvec } from '../files/dwi.ts'
8- import { walkBack } from '../files/inheritance.ts'
8+ import { readSidecars , walkBack } from '../files/inheritance.ts'
99import { evalCheck } from './applyRules.ts'
1010import { expressionFunctions } from './expressionLanguage.ts'
1111
12+ interface WithSidecar {
13+ sidecar : Record < string , unknown >
14+ }
15+
1216function defaultAssociation ( file : BIDSFile , _options : any ) : Promise < { path : string } > {
1317 return Promise . resolve ( { path : file . path } )
1418}
1519
20+ async function constructSidecar ( file : BIDSFile ) : Promise < Record < string , unknown > > {
21+ const sidecars = await readSidecars ( file )
22+ // Note ordering here gives precedence to the more specific sidecar
23+ return sidecars . values ( ) . reduce ( ( acc , json ) => ( { ...json , ...acc } ) , { } )
24+ }
25+
1626/**
1727 * This object describes lookup functions for files associated to data files in a bids dataset.
1828 * For any given data file we iterate over the associations defined schema.meta.associations.
@@ -22,14 +32,15 @@ function defaultAssociation(file: BIDSFile, _options: any): Promise<{ path: stri
2232 * Many associations only consist of a path; this object is for more complex associations.
2333 */
2434const associationLookup = {
25- events : async ( file : BIDSFile , options : { maxRows : number } ) : Promise < Events > => {
35+ events : async ( file : BIDSFile , options : { maxRows : number } ) : Promise < Events & WithSidecar > => {
2636 const columns = await loadTSV ( file , options . maxRows )
2737 . catch ( ( e ) => {
2838 return new Map ( )
2939 } )
3040 return {
3141 path : file . path ,
3242 onset : columns . get ( 'onset' ) || [ ] ,
43+ sidecar : await constructSidecar ( file ) ,
3344 }
3445 } ,
3546 aslcontext : async (
0 commit comments