Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema): Improve type annotations of schema.context #1886

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

effigies
Copy link
Collaborator

@effigies effigies commented Aug 5, 2024

This is intended to give better guidance to tooling that would auto-generate classes or interfaces for the validation context.

For example, we can run:

bst export | jq .meta.context | npx quicktype --src-lang schema --lang ts -t Context --just-types
export interface Context {
    /**
     * Associated files, indexed by suffix, selected according to the inheritance principle
     */
    associations: Associations;
    /**
     * TSV columns, indexed by column header, values are arrays with column contents
     */
    columns?: { [key: string]: string[] };
    /**
     * Properties and contents of the entire dataset
     */
    dataset: Dataset;
    /**
     * Datatype of current file, for examples, anat
     */
    datatype?: string;
    /**
     * Entities parsed from the current filename
     */
    entities?: { [key: string]: string };
    /**
     * Extension of current file including initial dot
     */
    extension?: string;
    /**
     * Parsed contents of gzip header
     */
    gzip?: Gzip;
    /**
     * Contents of the current JSON file
     */
    json?: { [key: string]: any };
    /**
     * Modality of current file, for examples, MRI
     */
    modality?: string;
    /**
     * Parsed contents of NIfTI header referenced elsewhere in schema.
     */
    nifti_header?: NiftiHeader;
    /**
     * Parsed contents of OME-XML header, which may be found in OME-TIFF or OME-ZARR files
     */
    ome?: Ome;
    /**
     * Path of the current file
     */
    path: string;
    /**
     * The BIDS specification schema
     */
    schema: { [key: string]: any };
    /**
     * Sidecar metadata constructed via the inheritance principle
     */
    sidecar: { [key: string]: any };
    /**
     * Length of the current file in bytes
     */
    size: number;
    /**
     * Properties and contents of the current subject
     */
    subject: Subject;
    /**
     * Suffix of current file
     */
    suffix?: string;
    /**
     * TIFF file format metadata
     */
    tiff?: Tiff;
}

/**
 * Associated files, indexed by suffix, selected according to the inheritance principle
 */
export interface Associations {
    /**
     * ASL context file
     */
    aslcontext?: Aslcontext;
    /**
     * B value file
     */
    bval?: Bval;
    /**
     * B vector file
     */
    bvec?: Bvec;
    /**
     * Channels file
     */
    channels?: Channels;
    /**
     * Coordinate system file
     */
    coordsystem?: Coordsystem;
    /**
     * Events file
     */
    events?: Events;
    /**
     * M0 scan file
     */
    m0scan?: M0Scan;
    /**
     * Magnitude image file
     */
    magnitude?: Magnitude;
    /**
     * Magnitude1 image file
     */
    magnitude1?: Magnitude1;
}

/**
 * ASL context file
 */
export interface Aslcontext {
    /**
     * Number of rows in aslcontext.tsv
     */
    n_rows: number;
    /**
     * Path to associated aslcontext file
     */
    path: string;
    /**
     * Contents of the volume_type column
     */
    volume_type: string[];
}

/**
 * B value file
 */
export interface Bval {
    /**
     * Number of columns in bval file
     */
    n_cols: number;
    /**
     * Number of rows in bval file
     */
    n_rows: number;
    /**
     * Path to associated bval file
     */
    path: string;
    /**
     * B-values contained in bval file
     */
    values: number[];
}

/**
 * B vector file
 */
export interface Bvec {
    /**
     * Number of columns in bvec file
     */
    n_cols: number;
    /**
     * Number of rows in bvec file
     */
    n_rows: number;
    /**
     * Path to associated bvec file
     */
    path: string;
}

/**
 * Channels file
 */
export interface Channels {
    /**
     * Path to associated channels file
     */
    path: string;
    /**
     * Contents of the type column
     */
    type: string[];
}

/**
 * Coordinate system file
 */
export interface Coordsystem {
    /**
     * Path to associated coordsystem file
     */
    path: string;
}

/**
 * Events file
 */
export interface Events {
    /**
     * Contents of the onset column
     */
    onset: string[];
    /**
     * Path to associated events file
     */
    path: string;
}

/**
 * M0 scan file
 */
export interface M0Scan {
    /**
     * Path to associated M0 scan file
     */
    path: string;
}

/**
 * Magnitude image file
 */
export interface Magnitude {
    /**
     * Path to associated magnitude file
     */
    path: string;
}

/**
 * Magnitude1 image file
 */
export interface Magnitude1 {
    /**
     * Path to associated magnitude1 file
     */
    path: string;
}

/**
 * Properties and contents of the entire dataset
 */
export interface Dataset {
    /**
     * Contents of /dataset_description.json
     */
    dataset_description: { [key: string]: any };
    /**
     * Data types present in the dataset
     */
    datatypes: string[];
    /**
     * Set of ignored files
     */
    ignored: string[];
    /**
     * Modalities present in the dataset
     */
    modalities: string[];
    /**
     * Collections of subjects in dataset
     */
    subjects: Subjects;
    /**
     * Tree view of all files in dataset
     */
    tree: { [key: string]: any };
}

/**
 * Collections of subjects in dataset
 */
export interface Subjects {
    /**
     * The participant_id column of participants.tsv
     */
    participant_id?: string[];
    /**
     * The union of participant_id columns in phenotype files
     */
    phenotype?: string[];
    /**
     * Subjects as determined by sub-*/ directories
     */
    sub_dirs: string[];
}

/**
 * Parsed contents of gzip header
 */
export interface Gzip {
    /**
     * Comment
     */
    comment?: string;
    /**
     * Filename
     */
    filename: string;
    /**
     * Modification time, unix timestamp
     */
    timestamp: number;
}

/**
 * Parsed contents of NIfTI header referenced elsewhere in schema.
 */
export interface NiftiHeader {
    /**
     * Data seq dimensions.
     */
    dim: number[];
    /**
     * Metadata about dimensions data.
     */
    dim_info: DimInfo;
    /**
     * Grid spacings (unit per dimension).
     */
    pixdim: number[];
    /**
     * Use of the quaternion fields.
     */
    qform_code: number;
    /**
     * Use of the affine fields.
     */
    sform_code: number;
    /**
     * Data array shape, equal to dim[1:dim[0] + 1]
     */
    shape: number[];
    /**
     * Voxel sizes, equal to pixdim[1:dim[0] + 1]
     */
    voxel_sizes: number[];
    /**
     * Units of pixdim[1..4]
     */
    xyzt_units: XyztUnits;
}

/**
 * Metadata about dimensions data.
 */
export interface DimInfo {
    /**
     * These fields encode which spatial dimension (1, 2, or 3).
     */
    freq: number;
    /**
     * Corresponds to which acquisition dimension for MRI data.
     */
    phase: number;
    /**
     * Slice dimensions.
     */
    slice: number;
}

/**
 * Units of pixdim[1..4]
 */
export interface XyztUnits {
    /**
     * String representing the unit of inter-volume intervals.
     */
    t: T;
    /**
     * String representing the unit of voxel spacing.
     */
    xyz: Xyz;
}

/**
 * String representing the unit of inter-volume intervals.
 */
export enum T {
    Msec = "msec",
    SEC = "sec",
    Unknown = "unknown",
    Usec = "usec",
}

/**
 * String representing the unit of voxel spacing.
 */
export enum Xyz {
    Meter = "meter",
    Mm = "mm",
    Um = "um",
    Unknown = "unknown",
}

/**
 * Parsed contents of OME-XML header, which may be found in OME-TIFF or OME-ZARR files
 */
export interface Ome {
    /**
     * Pixels / @PhysicalSizeX
     */
    PhysicalSizeX?: number;
    /**
     * Pixels / @PhysicalSizeXUnit
     */
    PhysicalSizeXUnit?: string;
    /**
     * Pixels / @PhysicalSizeY
     */
    PhysicalSizeY?: number;
    /**
     * Pixels / @PhysicalSizeYUnit
     */
    PhysicalSizeYUnit?: string;
    /**
     * Pixels / @PhysicalSizeZ
     */
    PhysicalSizeZ?: number;
    /**
     * Pixels / @PhysicalSizeZUnit
     */
    PhysicalSizeZUnit?: string;
}

/**
 * Properties and contents of the current subject
 */
export interface Subject {
    /**
     * Collections of sessions in subject
     */
    sessions: Sessions;
}

/**
 * Collections of sessions in subject
 */
export interface Sessions {
    /**
     * The union of session_id columns in phenotype files
     */
    phenotype?: string[];
    /**
     * Sessions as determined by ses-*/ directories
     */
    ses_dirs: string[];
    /**
     * The session_id column of sessions.tsv
     */
    session_id?: string[];
}

/**
 * TIFF file format metadata
 */
export interface Tiff {
    /**
     * TIFF file format version (the second 2-byte block)
     */
    version: number;
}

Without this patch, most of these interfaces get [property: string]: any; as well, e.g.,

export interface Tiff {
    /**
     * TIFF file format version (the second 2-byte block)
     */
    version?: number;
    [property: string]: any;
}

@effigies effigies added schema Issues related to the YAML schema representation of the specification. Patch version release. exclude-from-changelog This item will not feature in the automatically generated changelog labels Aug 5, 2024
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.06%. Comparing base (0e506f0) to head (86010ea).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1886   +/-   ##
=======================================
  Coverage   88.06%   88.06%           
=======================================
  Files          16       16           
  Lines        1391     1391           
=======================================
  Hits         1225     1225           
  Misses        166      166           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@effigies effigies force-pushed the schema/additionalProperties branch from b01096a to 0d902b5 Compare August 5, 2024 23:52
@effigies effigies changed the title feat(schema): Add additionalProperties=false to context objects feat(schema): Improve type annotations of schema.context Aug 6, 2024
Copy link
Member

@rwblair rwblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be nice if there was an easy way to default additionalProperties: false but I haven't been able to find one.

@effigies effigies merged commit 98645a1 into bids-standard:master Aug 14, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude-from-changelog This item will not feature in the automatically generated changelog schema Issues related to the YAML schema representation of the specification. Patch version release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants