Skip to content

Commit

Permalink
Merge pull request DouglasNeuroInformatics#1004 from joshunrau/fix-se…
Browse files Browse the repository at this point in the history
…t-issue
  • Loading branch information
joshunrau authored Oct 22, 2024
2 parents a6df1b4 + fc6b6b8 commit 0b83d0d
Show file tree
Hide file tree
Showing 9 changed files with 7,364 additions and 5,565 deletions.
38 changes: 25 additions & 13 deletions apps/api/src/instrument-records/instrument-records.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { yearsPassed } from '@douglasneuroinformatics/libjs';
import { replacer, yearsPassed } from '@douglasneuroinformatics/libjs';
import { reviver } from '@douglasneuroinformatics/libjs';
import { linearRegression } from '@douglasneuroinformatics/libstats';
import { Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common';
import type { Json, ScalarInstrument } from '@opendatacapture/runtime-core';
import type { ScalarInstrument } from '@opendatacapture/runtime-core';
import type {
CreateInstrumentRecordData,
InstrumentRecord,
Expand Down Expand Up @@ -49,7 +49,7 @@ export class InstrumentRecordsService {
}

async create(
{ data, date, groupId, instrumentId, sessionId, subjectId }: CreateInstrumentRecordData,
{ data: rawData, date, groupId, instrumentId, sessionId, subjectId }: CreateInstrumentRecordData,
options?: EntityOperationOptions
): Promise<InstrumentRecordModel> {
if (groupId) {
Expand All @@ -64,17 +64,21 @@ export class InstrumentRecordsService {

await this.subjectsService.findById(subjectId);
await this.sessionsService.findById(sessionId);
if (!instrument.validationSchema.safeParse(data).success) {

const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
if (!parseResult.success) {
console.error(parseResult.error.issues);
throw new UnprocessableEntityException(
`Data received does not pass validation schema of instrument '${instrument.id}'`
`Data received for record does not pass validation schema of instrument '${instrument.id}'`
);
}

return this.instrumentRecordModel.create({
data: {
computedMeasures: instrument.measures
? this.instrumentMeasuresService.computeMeasures(instrument.measures, data)
? this.instrumentMeasuresService.computeMeasures(instrument.measures, parseResult.data)
: null,
data,
data: this.serializeData(parseResult.data),
date,
group: groupId
? {
Expand Down Expand Up @@ -271,7 +275,7 @@ export class InstrumentRecordsService {

try {
for (let i = 0; i < records.length; i++) {
const { data, date, subjectId } = records[i]!;
const { data: rawData, date, subjectId } = records[i]!;
await this.createSubjectIfNotFound(subjectId);

const session = await this.sessionsService.create({
Expand All @@ -287,9 +291,9 @@ export class InstrumentRecordsService {

const sessionId = session.id;

const revivedData = JSON.parse(JSON.stringify(data), reviver) as Json;

if (!instrument.validationSchema.safeParse(revivedData).success) {
const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
if (!parseResult.success) {
console.error(parseResult.error.issues);
throw new UnprocessableEntityException(
`Data received for record at index '${i}' does not pass validation schema of instrument '${instrument.id}'`
);
Expand All @@ -298,9 +302,9 @@ export class InstrumentRecordsService {
const createdRecord = await this.instrumentRecordModel.create({
data: {
computedMeasures: instrument.measures
? this.instrumentMeasuresService.computeMeasures(instrument.measures, revivedData)
? this.instrumentMeasuresService.computeMeasures(instrument.measures, parseResult.data)
: null,
data,
data: this.serializeData(parseResult.data),
date,
group: groupId
? {
Expand Down Expand Up @@ -356,4 +360,12 @@ export class InstrumentRecordsService {
}
}
}

private parseJson(data: unknown) {
return JSON.parse(JSON.stringify(data), reviver) as unknown;
}

private serializeData(data: unknown) {
return JSON.parse(JSON.stringify(data, replacer)) as unknown;
}
}
8 changes: 4 additions & 4 deletions apps/outreach/src/plugins/starlight-plugin-typedoc/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export class StarlightTypeDocLogger extends Logger {
this.#logger.error(message);
break;
}
case LogLevel.Warn: {
this.#logger.warn(message);
break;
}
case LogLevel.Verbose: {
this.#logger.debug(message);
break;
}
case LogLevel.Warn: {
this.#logger.warn(message);
break;
}
default: {
this.#logger.info(message);
break;
Expand Down
14 changes: 7 additions & 7 deletions apps/playground/src/vim/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,6 @@ export default class EditorAdapter {
this.state[key] = value;

switch (key) {
// @ts-expect-error - maintain behavior of legacy code
case 'theme': {
this.theme = value as string;
this.editor.updateOptions({
theme: this.theme
});
}
case 'indentWithTabs': {
const model = this.editor.getModel()!;
model.updateOptions({ insertSpaces: !value });
Expand All @@ -1098,6 +1091,13 @@ export default class EditorAdapter {
model.updateOptions({ tabSize: tabSize });
break;
}
// @ts-expect-error - maintain behavior of legacy code
case 'theme': {
this.theme = value as string;
this.editor.updateOptions({
theme: this.theme
});
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions apps/playground/src/vim/command-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ export class CommandDispatcher {
processCommand(adapter: EditorAdapter, vim: VimState, command: KeyMapping) {
vim.inputState.repeatOverride = command.repeatOverride;
switch (command.type) {
case 'action':
this.processAction(adapter, vim, command);
break;
case 'ex':
case 'keyToEx':
this.processEx(adapter, vim, command);
break;
case 'motion':
this.processMotion(adapter, vim, command);
break;
Expand All @@ -275,16 +282,9 @@ export class CommandDispatcher {
case 'operatorMotion':
this.processOperatorMotion(adapter, vim, command);
break;
case 'action':
this.processAction(adapter, vim, command);
break;
case 'search':
this.processSearch(adapter, vim, command);
break;
case 'ex':
case 'keyToEx':
this.processEx(adapter, vim, command);
break;
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/vim/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export const getEventKeyName = (e: IKeyboardEvent | KeyboardEvent, skip = false)
let skipOnlyShiftCheck = skip;

switch (e.keyCode) {
case KeyCode.Shift:
case KeyCode.Meta:
case KeyCode.Alt:
case KeyCode.Ctrl:
case KeyCode.Meta:
case KeyCode.Shift:
return key;
case KeyCode.Escape:
skipOnlyShiftCheck = true;
Expand Down
6 changes: 3 additions & 3 deletions apps/playground/src/vim/ex-command-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ export class ExCommandDispatcher {
return parseInt(numberMatch[1]!, 10) - 1;
}
switch (inputStream.next()) {
case '.':
return this.parseLineSpecOffset_(inputStream, adapter.getCursor().line);
case '$':
return this.parseLineSpecOffset_(inputStream, adapter.lastLine());
case "'":
Expand All @@ -278,11 +276,13 @@ export class ExCommandDispatcher {
const markPos = getMarkPos(adapter, adapter.state.vim, markName);
if (!markPos) throw new Error('Mark not set');
return this.parseLineSpecOffset_(inputStream, markPos.line);
case '-':
case '+':
case '-':
inputStream.backUp(1);
// Offset is relative to current line if not otherwise specified.
return this.parseLineSpecOffset_(inputStream, adapter.getCursor().line);
case '.':
return this.parseLineSpecOffset_(inputStream, adapter.getCursor().line);
default:
inputStream.backUp(1);
return;
Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/vim/motions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export const motions: { [key: string]: MotionFunc } = {
const cur = head;
switch (vim.lastMotion) {
case this.moveByDisplayLines:
case this.moveByScroll:
case this.moveByLines:
case this.moveByScroll:
case this.moveToColumn:
case this.moveToEol:
break;
Expand All @@ -238,8 +238,8 @@ export const motions: { [key: string]: MotionFunc } = {
// was going to the end of a line, moving vertically we should go to
// the end of the line, etc.
switch (vim.lastMotion) {
case this.moveByLines:
case this.moveByDisplayLines:
case this.moveByLines:
case this.moveByScroll:
case this.moveToColumn:
case this.moveToEol:
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/features/upload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export function interpretZodValue(
}
return { success: true, value: date };
}
case 'ZodEnum':
return interpretZodValue(entry, 'ZodString', isOptional);
case 'ZodNumber':
if (isNumberLike(entry)) {
return { success: true, value: parseNumber(entry) };
Expand All @@ -231,8 +233,6 @@ export function interpretZodValue(
return { message: `Invalid ZodSet: ${entry}`, success: false };
case 'ZodString':
return { success: true, value: entry };
case 'ZodEnum':
return interpretZodValue(entry, 'ZodString', isOptional);
default:
return { message: `Invalid ZodType: ${zType satisfies never}`, success: false };
}
Expand Down
Loading

0 comments on commit 0b83d0d

Please sign in to comment.