Skip to content

Commit

Permalink
FIX: Load JSON contents into context eagerly
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Apr 18, 2024
1 parent bc15afc commit 51d1924
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bids-validator/src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,10 @@ export class BIDSContext implements Context {
this.modality = ''
this.sidecar = {}
this.columns = new ColumnsMap()
this.json = {} as Record<string, any>
this.associations = {} as ContextAssociations
}

get json(): Promise<Record<string, any>> {
return this.file
.text()
.then((text) => JSON.parse(text))
.catch((error) => {})
}
get path(): string {
return this.file.path
}
Expand Down Expand Up @@ -193,12 +188,23 @@ export class BIDSContext implements Context {
return
}

async loadJSON(): Promise<void> {
if (this.extension !== '.json') {
return
}
this.json = await this.file
.text()
.then((text) => JSON.parse(text))
.catch((error) => {})
}

async asyncLoads() {
await Promise.allSettled([
this.loadSidecar(),
this.loadColumns(),
this.loadAssociations(),
this.loadNiftiHeader(),
this.loadJSON(),
])
}
}

0 comments on commit 51d1924

Please sign in to comment.