Skip to content

Commit 3b64628

Browse files
committed
rf(hed): Move hedSchemas onto context.dataset
1 parent cad0cae commit 3b64628

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/schema/context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export class BIDSContextDataset implements Dataset {
3939
schema: Schema
4040
pseudofileExtensions: Set<string>
4141

42+
// Opaque object for HED validator
43+
hedSchemas: object | undefined | null = undefined
44+
4245
constructor(
4346
args: Partial<BIDSContextDataset>,
4447
) {

src/validators/hed.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,23 @@ function sidecarValueHasHed(sidecarValue: unknown) {
2222
)
2323
}
2424

25-
let hedSchemas: object | undefined | null = undefined
26-
27-
async function setHedSchemas(datasetDescriptionJson = {}) {
28-
if (hedSchemas !== undefined) {
25+
async function setHedSchemas(dataset: BIDSContextDataset) {
26+
if (dataset.hedSchemas !== undefined) {
2927
return [] as HedIssue[]
3028
}
3129
const datasetDescriptionData = new hedValidator.bids.BidsJsonFile(
3230
'/dataset_description.json',
33-
datasetDescriptionJson,
31+
dataset.dataset_description,
3432
null,
3533
)
3634
try {
37-
hedSchemas = await hedValidator.bids.buildBidsSchemas(
35+
dataset.hedSchemas = await hedValidator.bids.buildBidsSchemas(
3836
datasetDescriptionData,
3937
null,
4038
)
4139
return [] as HedIssue[]
4240
} catch (issueError) {
43-
hedSchemas = null
41+
dataset.hedSchemas = null
4442
return hedValidator.bids.BidsHedIssue.fromHedIssues(
4543
issueError,
4644
datasetDescriptionData.file,
@@ -66,18 +64,16 @@ export async function hedValidate(
6664
if (!('HED' in context.columns) && !sidecarHasHed(context.sidecar)) {
6765
return
6866
}
69-
hedValidationIssues = await setHedSchemas(context.dataset.dataset_description)
67+
hedValidationIssues = await setHedSchemas(context.dataset)
7068

7169
file = await buildHedTsvFile(context)
7270
} else if (context.extension === '.json' && sidecarHasHed(context.json)) {
73-
hedValidationIssues = hedValidationIssues = await setHedSchemas(
74-
context.dataset.dataset_description,
75-
)
71+
hedValidationIssues = hedValidationIssues = await setHedSchemas(context.dataset)
7672
file = buildHedSidecarFile(context)
7773
}
7874

7975
if (file) {
80-
hedValidationIssues.push(...file.validate(hedSchemas))
76+
hedValidationIssues.push(...file.validate(context.dataset.hedSchemas))
8177
}
8278
} catch (error) {
8379
context.dataset.issues.add({

0 commit comments

Comments
 (0)