Skip to content

Commit 0b83d0d

Browse files
authored
Merge pull request #1004 from joshunrau/fix-set-issue
2 parents a6df1b4 + fc6b6b8 commit 0b83d0d

9 files changed

Lines changed: 7364 additions & 5565 deletions

File tree

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { yearsPassed } from '@douglasneuroinformatics/libjs';
1+
import { replacer, yearsPassed } from '@douglasneuroinformatics/libjs';
22
import { reviver } from '@douglasneuroinformatics/libjs';
33
import { linearRegression } from '@douglasneuroinformatics/libstats';
44
import { Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common';
5-
import type { Json, ScalarInstrument } from '@opendatacapture/runtime-core';
5+
import type { ScalarInstrument } from '@opendatacapture/runtime-core';
66
import type {
77
CreateInstrumentRecordData,
88
InstrumentRecord,
@@ -49,7 +49,7 @@ export class InstrumentRecordsService {
4949
}
5050

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

6565
await this.subjectsService.findById(subjectId);
6666
await this.sessionsService.findById(sessionId);
67-
if (!instrument.validationSchema.safeParse(data).success) {
67+
68+
const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
69+
if (!parseResult.success) {
70+
console.error(parseResult.error.issues);
6871
throw new UnprocessableEntityException(
69-
`Data received does not pass validation schema of instrument '${instrument.id}'`
72+
`Data received for record does not pass validation schema of instrument '${instrument.id}'`
7073
);
7174
}
75+
7276
return this.instrumentRecordModel.create({
7377
data: {
7478
computedMeasures: instrument.measures
75-
? this.instrumentMeasuresService.computeMeasures(instrument.measures, data)
79+
? this.instrumentMeasuresService.computeMeasures(instrument.measures, parseResult.data)
7680
: null,
77-
data,
81+
data: this.serializeData(parseResult.data),
7882
date,
7983
group: groupId
8084
? {
@@ -271,7 +275,7 @@ export class InstrumentRecordsService {
271275

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

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

288292
const sessionId = session.id;
289293

290-
const revivedData = JSON.parse(JSON.stringify(data), reviver) as Json;
291-
292-
if (!instrument.validationSchema.safeParse(revivedData).success) {
294+
const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
295+
if (!parseResult.success) {
296+
console.error(parseResult.error.issues);
293297
throw new UnprocessableEntityException(
294298
`Data received for record at index '${i}' does not pass validation schema of instrument '${instrument.id}'`
295299
);
@@ -298,9 +302,9 @@ export class InstrumentRecordsService {
298302
const createdRecord = await this.instrumentRecordModel.create({
299303
data: {
300304
computedMeasures: instrument.measures
301-
? this.instrumentMeasuresService.computeMeasures(instrument.measures, revivedData)
305+
? this.instrumentMeasuresService.computeMeasures(instrument.measures, parseResult.data)
302306
: null,
303-
data,
307+
data: this.serializeData(parseResult.data),
304308
date,
305309
group: groupId
306310
? {
@@ -356,4 +360,12 @@ export class InstrumentRecordsService {
356360
}
357361
}
358362
}
363+
364+
private parseJson(data: unknown) {
365+
return JSON.parse(JSON.stringify(data), reviver) as unknown;
366+
}
367+
368+
private serializeData(data: unknown) {
369+
return JSON.parse(JSON.stringify(data, replacer)) as unknown;
370+
}
359371
}

apps/outreach/src/plugins/starlight-plugin-typedoc/logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export class StarlightTypeDocLogger extends Logger {
2222
this.#logger.error(message);
2323
break;
2424
}
25-
case LogLevel.Warn: {
26-
this.#logger.warn(message);
27-
break;
28-
}
2925
case LogLevel.Verbose: {
3026
this.#logger.debug(message);
3127
break;
3228
}
29+
case LogLevel.Warn: {
30+
this.#logger.warn(message);
31+
break;
32+
}
3333
default: {
3434
this.#logger.info(message);
3535
break;

apps/playground/src/vim/adapter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,13 +1077,6 @@ export default class EditorAdapter {
10771077
this.state[key] = value;
10781078

10791079
switch (key) {
1080-
// @ts-expect-error - maintain behavior of legacy code
1081-
case 'theme': {
1082-
this.theme = value as string;
1083-
this.editor.updateOptions({
1084-
theme: this.theme
1085-
});
1086-
}
10871080
case 'indentWithTabs': {
10881081
const model = this.editor.getModel()!;
10891082
model.updateOptions({ insertSpaces: !value });
@@ -1098,6 +1091,13 @@ export default class EditorAdapter {
10981091
model.updateOptions({ tabSize: tabSize });
10991092
break;
11001093
}
1094+
// @ts-expect-error - maintain behavior of legacy code
1095+
case 'theme': {
1096+
this.theme = value as string;
1097+
this.editor.updateOptions({
1098+
theme: this.theme
1099+
});
1100+
}
11011101
}
11021102
}
11031103

apps/playground/src/vim/command-dispatcher.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ export class CommandDispatcher {
266266
processCommand(adapter: EditorAdapter, vim: VimState, command: KeyMapping) {
267267
vim.inputState.repeatOverride = command.repeatOverride;
268268
switch (command.type) {
269+
case 'action':
270+
this.processAction(adapter, vim, command);
271+
break;
272+
case 'ex':
273+
case 'keyToEx':
274+
this.processEx(adapter, vim, command);
275+
break;
269276
case 'motion':
270277
this.processMotion(adapter, vim, command);
271278
break;
@@ -275,16 +282,9 @@ export class CommandDispatcher {
275282
case 'operatorMotion':
276283
this.processOperatorMotion(adapter, vim, command);
277284
break;
278-
case 'action':
279-
this.processAction(adapter, vim, command);
280-
break;
281285
case 'search':
282286
this.processSearch(adapter, vim, command);
283287
break;
284-
case 'ex':
285-
case 'keyToEx':
286-
this.processEx(adapter, vim, command);
287-
break;
288288
default:
289289
break;
290290
}

apps/playground/src/vim/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ export const getEventKeyName = (e: IKeyboardEvent | KeyboardEvent, skip = false)
9898
let skipOnlyShiftCheck = skip;
9999

100100
switch (e.keyCode) {
101-
case KeyCode.Shift:
102-
case KeyCode.Meta:
103101
case KeyCode.Alt:
104102
case KeyCode.Ctrl:
103+
case KeyCode.Meta:
104+
case KeyCode.Shift:
105105
return key;
106106
case KeyCode.Escape:
107107
skipOnlyShiftCheck = true;

apps/playground/src/vim/ex-command-dispatcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ export class ExCommandDispatcher {
265265
return parseInt(numberMatch[1]!, 10) - 1;
266266
}
267267
switch (inputStream.next()) {
268-
case '.':
269-
return this.parseLineSpecOffset_(inputStream, adapter.getCursor().line);
270268
case '$':
271269
return this.parseLineSpecOffset_(inputStream, adapter.lastLine());
272270
case "'":
@@ -278,11 +276,13 @@ export class ExCommandDispatcher {
278276
const markPos = getMarkPos(adapter, adapter.state.vim, markName);
279277
if (!markPos) throw new Error('Mark not set');
280278
return this.parseLineSpecOffset_(inputStream, markPos.line);
281-
case '-':
282279
case '+':
280+
case '-':
283281
inputStream.backUp(1);
284282
// Offset is relative to current line if not otherwise specified.
285283
return this.parseLineSpecOffset_(inputStream, adapter.getCursor().line);
284+
case '.':
285+
return this.parseLineSpecOffset_(inputStream, adapter.getCursor().line);
286286
default:
287287
inputStream.backUp(1);
288288
return;

apps/playground/src/vim/motions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export const motions: { [key: string]: MotionFunc } = {
211211
const cur = head;
212212
switch (vim.lastMotion) {
213213
case this.moveByDisplayLines:
214-
case this.moveByScroll:
215214
case this.moveByLines:
215+
case this.moveByScroll:
216216
case this.moveToColumn:
217217
case this.moveToEol:
218218
break;
@@ -238,8 +238,8 @@ export const motions: { [key: string]: MotionFunc } = {
238238
// was going to the end of a line, moving vertically we should go to
239239
// the end of the line, etc.
240240
switch (vim.lastMotion) {
241-
case this.moveByLines:
242241
case this.moveByDisplayLines:
242+
case this.moveByLines:
243243
case this.moveByScroll:
244244
case this.moveToColumn:
245245
case this.moveToEol:

apps/web/src/features/upload/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ export function interpretZodValue(
217217
}
218218
return { success: true, value: date };
219219
}
220+
case 'ZodEnum':
221+
return interpretZodValue(entry, 'ZodString', isOptional);
220222
case 'ZodNumber':
221223
if (isNumberLike(entry)) {
222224
return { success: true, value: parseNumber(entry) };
@@ -231,8 +233,6 @@ export function interpretZodValue(
231233
return { message: `Invalid ZodSet: ${entry}`, success: false };
232234
case 'ZodString':
233235
return { success: true, value: entry };
234-
case 'ZodEnum':
235-
return interpretZodValue(entry, 'ZodString', isOptional);
236236
default:
237237
return { message: `Invalid ZodType: ${zType satisfies never}`, success: false };
238238
}

0 commit comments

Comments
 (0)