Skip to content

Commit 243e081

Browse files
committed
feat: Add DatasetType passlist to allow applications to limit support
1 parent dd0b080 commit 243e081

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

src/issues/list.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ export const bidsIssues: IssueDefinitionRecord = {
170170
severity: 'error',
171171
reason: 'A json sidecar file was found without a corresponding data file',
172172
},
173+
UNSUPPORTED_DATASET_TYPE: {
174+
severity: 'error',
175+
reason: 'This DatasetType is not supported by the application.',
176+
},
173177
BLACKLISTED_MODALITY: {
174178
severity: 'error',
175179
reason: 'The modality in this file is blacklisted through validator configuration.',

src/setup/options.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Deno.test('options parsing', async (t) => {
1010
json: true,
1111
color: false,
1212
blacklistModalities: [],
13+
datasetTypes: [],
1314
maxRows: 1000,
1415
})
1516
})

src/setup/options.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ export type ValidatorOptions = {
2828
color?: boolean
2929
recursive?: boolean
3030
outfile?: string
31+
datasetTypes: string[]
3132
blacklistModalities: string[]
3233
prune?: boolean
3334
maxRows?: number
3435
}
3536

37+
const datasetType = new EnumType<string>(
38+
schema.objects.metadata.DatasetType.enum as string[],
39+
)
40+
3641
const modalityType = new EnumType<string>(
3742
Object.keys(schema.rules.modalities),
3843
)
@@ -69,6 +74,12 @@ export const validateCommand: Command<void, void, any, string[], void> = new Com
6974
'--filenameMode',
7075
'Enable filename checks for newline separated filenames read from stdin',
7176
)
77+
.type('datasetType', datasetType)
78+
.option(
79+
'--datasetTypes <...datasetTypes:datasetType>',
80+
'Permitted dataset types to validate against (default: all)',
81+
{ default: [] as string[] },
82+
)
7283
.type('modality', modalityType)
7384
.option(
7485
'--blacklistModalities <...modalities:modality>',

src/tests/regression.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Deno.test('Regression tests', async (t) => {
2424
debug: 'ERROR',
2525
ignoreNiftiHeaders: true,
2626
blacklistModalities: [],
27+
datasetTypes: [],
2728
})
2829
assert(result.issues.get({ code: 'NOT_INCLUDED' }).length == 1)
2930
assert(result.issues.get({ code: 'SCANS_FILENAME_NOT_MATCH_DATASET' }).length == 0)
@@ -37,6 +38,7 @@ Deno.test('Regression tests', async (t) => {
3738
debug: 'ERROR',
3839
ignoreNiftiHeaders: true,
3940
blacklistModalities: [],
41+
datasetTypes: [],
4042
})
4143
assert(result.issues.get({ code: 'NOT_INCLUDED' }).length == 0)
4244
assert(result.issues.get({ code: 'SCANS_FILENAME_NOT_MATCH_DATASET' }).length == 0)

src/validators/bids.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Deno.test('Smoke tests of main validation function', async (t) => {
1414
debug: 'INFO',
1515
ignoreNiftiHeaders: true,
1616
blacklistModalities: [],
17+
datasetTypes: [],
1718
})
1819
assert(result.issues.get({ code: 'BLACKLISTED_MODALITY' }).length === 0)
1920

@@ -22,6 +23,7 @@ Deno.test('Smoke tests of main validation function', async (t) => {
2223
debug: 'INFO',
2324
ignoreNiftiHeaders: true,
2425
blacklistModalities: ['MRI'],
26+
datasetTypes: [],
2527
})
2628
assert(result.issues.get({ code: 'BLACKLISTED_MODALITY' }).length === 1)
2729

@@ -30,6 +32,7 @@ Deno.test('Smoke tests of main validation function', async (t) => {
3032
debug: 'INFO',
3133
ignoreNiftiHeaders: true,
3234
blacklistModalities: ['MEG'],
35+
datasetTypes: [],
3336
})
3437
assert(result.issues.get({ code: 'BLACKLISTED_MODALITY' }).length === 0)
3538

@@ -38,6 +41,7 @@ Deno.test('Smoke tests of main validation function', async (t) => {
3841
debug: 'INFO',
3942
ignoreNiftiHeaders: true,
4043
blacklistModalities: ['MEG', 'MRI'],
44+
datasetTypes: [],
4145
})
4246
assert(result.issues.get({ code: 'BLACKLISTED_MODALITY' }).length === 1)
4347
})
@@ -48,6 +52,7 @@ Deno.test('Smoke tests of main validation function', async (t) => {
4852
datasetPath: '/dataset',
4953
debug: 'INFO',
5054
blacklistModalities: [],
55+
datasetTypes: [],
5156
},
5257
{
5358
ignore: [{ location: '/dataset_description.json' }],

src/validators/bids.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export async function validate(
7272
})
7373
}
7474

75+
// Empty list defaults to allow all
76+
if (options.datasetTypes.length) {
77+
const datasetType = (dsContext.dataset_description.DatasetType ?? 'raw') as string
78+
if (!options.datasetTypes.includes(datasetType)) {
79+
dsContext.issues.add({
80+
code: 'UNSUPPORTED_DATASET_TYPE',
81+
location: '/dataset_description.json',
82+
issueMessage: `"DatasetType": "${datasetType}"`,
83+
})
84+
}
85+
}
86+
7587
const bidsDerivatives: FileTree[] = []
7688
const nonstdDerivatives: FileTree[] = []
7789
fileTree.directories = fileTree.directories.filter((dir) => {

0 commit comments

Comments
 (0)