Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class BIDSContextDataset implements Dataset {
schema: Schema
pseudofileExtensions: Set<string>

// Opaque object for HED validator
hedSchemas: object | undefined | null = undefined

constructor(
args: Partial<BIDSContextDataset>,
) {
Expand Down
25 changes: 12 additions & 13 deletions src/validators/hed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ function sidecarValueHasHed(sidecarValue: unknown) {
)
}

let hedSchemas: object | undefined | null = undefined

async function setHedSchemas(datasetDescriptionJson = {}) {
async function setHedSchemas(dataset: BIDSContextDataset) {
if (dataset.hedSchemas !== undefined) {
return [] as HedIssue[]
}
const datasetDescriptionData = new hedValidator.bids.BidsJsonFile(
'/dataset_description.json',
datasetDescriptionJson,
dataset.dataset_description,
null,
)
try {
hedSchemas = await hedValidator.bids.buildBidsSchemas(
dataset.hedSchemas = await hedValidator.bids.buildBidsSchemas(
datasetDescriptionData,
null,
)
return [] as HedIssue[]
} catch (issueError) {
hedSchemas = null
dataset.hedSchemas = null
return hedValidator.bids.BidsHedIssue.fromHedIssues(
issueError,
datasetDescriptionData.file,
Expand All @@ -59,22 +60,20 @@ export async function hedValidate(
let hedValidationIssues = [] as HedIssue[]

try {
if (context.extension == '.tsv' && context.columns) {
if (context.extension === '.tsv' && context.columns) {
if (!('HED' in context.columns) && !sidecarHasHed(context.sidecar)) {
return
}
hedValidationIssues = await setHedSchemas(context.dataset.dataset_description)
hedValidationIssues = await setHedSchemas(context.dataset)

file = await buildHedTsvFile(context)
} else if (context.extension == '.json' && sidecarHasHed(context.json)) {
hedValidationIssues = hedValidationIssues = await setHedSchemas(
context.dataset.dataset_description,
)
} else if (context.extension === '.json' && sidecarHasHed(context.json)) {
hedValidationIssues = hedValidationIssues = await setHedSchemas(context.dataset)
file = buildHedSidecarFile(context)
}

if (file) {
hedValidationIssues.push(...file.validate(hedSchemas))
hedValidationIssues.push(...file.validate(context.dataset.hedSchemas))
}
} catch (error) {
context.dataset.issues.add({
Expand Down