From 37530e3734d4ca89e67b539a860e397cb44f35de Mon Sep 17 00:00:00 2001 From: Quentin Roy Date: Wed, 27 Sep 2023 11:12:42 +0200 Subject: [PATCH] convert-touchstone: cosmetics --- .../src/convert-touchstone.ts | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/packages/convert-touchstone/src/convert-touchstone.ts b/packages/convert-touchstone/src/convert-touchstone.ts index 53539011..95195b39 100644 --- a/packages/convert-touchstone/src/convert-touchstone.ts +++ b/packages/convert-touchstone/src/convert-touchstone.ts @@ -1,13 +1,14 @@ import * as sax from 'sax'; import type StaticDesign from '@lightmill/static-design'; -export type ExperimentBase = { +export type Experiment = { author: string; description: string; id: string; }; -export type RunBase = { id: string }; -export type Run = RunBase & { +export type WithId = { id: string }; +export type Run = { + id: string; tasks: Array; }; export type Trial = ( @@ -18,9 +19,9 @@ export type Trial = ( export type Block = ({ practice: false; number: number } | { practice: true }) & FactorValues; export type FactorValues = Record; -export type BaseTask = { type: string; id: string }; -export type UndefinedTask = BaseTask & Record; -export type DesignConfig = ExperimentBase & +export type MinimalTask = { type: string; id: string }; +export type UndefinedTask = MinimalTask & Record; +export type DesignConfig = Experiment & ConstructorParameters>[0]; type TypeParserKey = 'integer' | 'float' | 'string'; @@ -43,18 +44,18 @@ type DefinedMapper = | T | Array; type MapperOptions = { - preBlock?: Mapper<[Block, RunBase, ExperimentBase], T>; - postBlock?: Mapper<[Block, RunBase, ExperimentBase], T>; - trial?: Mapper<[Trial, Block, RunBase, ExperimentBase], T>; - preRun?: Mapper<[RunBase, ExperimentBase], T>; - postRun?: Mapper<[RunBase, ExperimentBase], T>; + preBlock?: Mapper<[Block, WithId, Experiment], T>; + postBlock?: Mapper<[Block, WithId, Experiment], T>; + trial?: Mapper<[Trial, Block, WithId, Experiment], T>; + preRun?: Mapper<[WithId, Experiment], T>; + postRun?: Mapper<[WithId, Experiment], T>; }; type DefinedMapperOptions = { - preBlock?: DefinedMapper<[Block, RunBase, ExperimentBase], T>; - postBlock?: DefinedMapper<[Block, RunBase, ExperimentBase], T>; - trial?: DefinedMapper<[Trial, Block, RunBase, ExperimentBase], T>; - preRun?: DefinedMapper<[RunBase, ExperimentBase], T>; - postRun?: DefinedMapper<[RunBase, ExperimentBase], T>; + preBlock?: DefinedMapper<[Block, WithId, Experiment], T>; + postBlock?: DefinedMapper<[Block, WithId, Experiment], T>; + trial?: DefinedMapper<[Trial, Block, WithId, Experiment], T>; + preRun?: DefinedMapper<[WithId, Experiment], T>; + postRun?: DefinedMapper<[WithId, Experiment], T>; }; /** @@ -84,7 +85,7 @@ type DefinedMapperOptions = { * convertTouchStone(data, { preBlocks, postBlocks, postRuns, preRuns }) * .then(doSomething); */ -export default function convertTouchstone( +export default function convertTouchstone( touchStoneXML: string | { pipe: (arg0: sax.SAXStream) => void }, opts: DefinedMapperOptions> & Required>, 'trial'>>, @@ -128,8 +129,8 @@ export default function convertTouchstone( const getPostRunTasks = createTaskGetter(postRun, getTaskId); const getTrialTasks = createTaskGetter(trial, getTaskId); - let experiment: DesignConfig | null = null; - let currentRun: Run | null = null; + let experiment: DesignConfig | null = null; + let currentRun: Run | null = null; let currentBlock: Block | null = null; // Handlers to be called on open tag events. @@ -390,18 +391,18 @@ class IdManager { } } -function createTaskGetter( +function createTaskGetter( mapper: DefinedMapper> | undefined, getId: (type: string, requestedId?: string) => string, ): (...args: FArgs) => Array; -function createTaskGetter( +function createTaskGetter( mapper: Mapper> | undefined, getId: (type: string, requestedId?: string) => string, -): (...args: FArgs) => Array; -function createTaskGetter( +): (...args: FArgs) => Array; +function createTaskGetter( mapper: Mapper> | undefined, getId: (type: string, requestedId?: string) => string, -): (...args: FArgs) => Array { +): (...args: FArgs) => Array { if (mapper == null) { return () => []; } @@ -437,7 +438,7 @@ function createTaskGetter( function createDefaultTrialMapper() { let lastPracticeTrialId = 0; - return function (trial: Trial, block: Block): BaseTask { + return function (trial: Trial, block: Block): MinimalTask { let id: string; if (trial.practice || block.practice) { lastPracticeTrialId += 1;