From 0b92d9af7a4f4fbee63a279a8f0d04ad9c482739 Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Wed, 25 Oct 2023 17:21:50 +0200 Subject: [PATCH] chore: default settings are just a function --- src/core/settings.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/settings.ts b/src/core/settings.ts index e5a9c240..70a7480f 100644 --- a/src/core/settings.ts +++ b/src/core/settings.ts @@ -28,24 +28,25 @@ const ModalFormSettingsSchema = object({ type ModalFormSettingsPartial = Output; -const DEFAULT_SETTINGS: ModalFormSettings = { - editorPosition: 'right', - formDefinitions: [], -}; - export function getDefaultSettings(): ModalFormSettings { - return { ...DEFAULT_SETTINGS }; + return { editorPosition: 'right', formDefinitions: []}; } export class NullSettingsError { readonly _tag = 'NullSettingsError'; } +/** + * Parses the settings and returns a validation error if the settings are invalid. + * The reason why we don't return default settings when the settings are invalid is because + * in case of default settings there are several operations that could be skipped, + * like migrations and validation. + */ export function parseSettings(maybeSettings: unknown): E.Either { return pipe( maybeSettings, E.fromNullable(new NullSettingsError()), - E.chainW((s) => parse(ModalFormSettingsSchema, { ...DEFAULT_SETTINGS, ...s })), + E.chainW((s) => parse(ModalFormSettingsSchema, { ...getDefaultSettings(), ...s })), ) }