12
12
* object in the schema for reference.
13
13
*/
14
14
// @ts -nocheck
15
- import { SEPARATOR } from '../deps/path.ts'
15
+ import { SEPARATOR , globToRegExp } from '../deps/path.ts'
16
16
import { GenericSchema , Schema } from '../types/schema.ts'
17
17
import { BIDSContext } from '../schema/context.ts'
18
18
import { lookupModality } from '../schema/modalities.ts'
@@ -56,7 +56,7 @@ function findRuleMatches(schema, context) {
56
56
export function _findRuleMatches ( node , path , context ) {
57
57
if (
58
58
( 'path' in node && context . file . name . endsWith ( node . path ) ) ||
59
- ( 'stem' in node && context . file . name . startsWith ( node . stem ) ) ||
59
+ ( 'stem' in node && context . file . name . match ( globToRegExp ( node . stem + '*' ) ) ) ||
60
60
( 'suffixes' in node && node . suffixes . includes ( context . suffix ) )
61
61
) {
62
62
context . filenameRules . push ( path )
@@ -74,27 +74,18 @@ export function _findRuleMatches(node, path, context) {
74
74
75
75
export async function datatypeFromDirectory ( schema , context ) {
76
76
const subEntity = schema . objects . entities . subject . name
77
- const subFormat = schema . objects . formats [ subEntity . format ]
78
77
const sesEntity = schema . objects . entities . session . name
79
- const sesFormat = schema . objects . formats [ sesEntity . format ]
80
78
const parts = context . file . path . split ( SEPARATOR )
81
- let datatypeIndex = 2
82
- if ( parts [ 0 ] !== '' ) {
83
- // we assume paths have leading '/'
84
- }
85
- // Ignoring associated data for now
86
- const subParts = parts [ 1 ] . split ( '-' )
87
- if ( ! ( subParts . length === 2 && subParts [ 0 ] === subEntity ) ) {
88
- // first directory must be subject
89
- }
90
- if ( parts . length < 3 ) {
79
+ let datatypeIndex = parts . length - 2
80
+ if ( datatypeIndex < 1 ) {
91
81
return Promise . resolve ( )
92
82
}
93
- const sesParts = parts [ 2 ] . split ( '-' )
94
- if ( sesParts . length === 2 && sesParts [ 0 ] === sesEntity ) {
95
- datatypeIndex = 3
96
- }
97
83
const dirDatatype = parts [ datatypeIndex ]
84
+ if ( dirDatatype === 'phenotype' ) {
85
+ // Phenotype is a pseudo-datatype for now.
86
+ context . datatype = dirDatatype
87
+ return Promise . resolve ( )
88
+ }
98
89
for ( let key in schema . rules . modalities ) {
99
90
if ( schema . rules . modalities [ key ] . datatypes . includes ( dirDatatype ) ) {
100
91
context . modality = key
@@ -154,9 +145,9 @@ function entitiesExtensionsInRule(
154
145
) : boolean {
155
146
const rule = schema [ path ]
156
147
const fileEntities = Object . keys ( context . entities )
157
- const ruleEntities = Object . keys ( rule . entities ) . map ( ( key ) =>
148
+ const ruleEntities = rule . entities ? Object . keys ( rule . entities ) . map ( ( key ) =>
158
149
lookupEntityLiteral ( key , schema ) ,
159
- )
150
+ ) : [ ]
160
151
const extInRule =
161
152
! rule . extensions ||
162
153
( rule . extensions && rule . extensions . includes ( context . extension ) )
0 commit comments