harbor run -t openthoughts/tasktrove-mix-h2-language-balanced-v2-mix-h2-lang-balanced-0452harbor download openthoughts/tasktrove-mix-h2-language-balanced-v2-mix-h2-lang-balanced-0452solution file
import { SETTINGS_DEFAULT } from "~/settings";
import { AutoTimelineSettings } from "./types";
import { isDefined, isDefinedAsBoolean, isDefinedAsString } from "./utils";
/**
* Fetches the tags to find and timeline specific settings override.
*
* @param source - The markdown code block source, a.k.a. the content inside the code block.
* @returns Partial settings to override the global ones.
*/
export function parseMarkdownBlockSource(source: string): {
readonly tagsToFind: string[];
readonly settingsOverride: Partial<AutoTimelineSettings>;
} {
const sourceEntries = source.split("\n");
if (!source.length)
return { tagsToFind: [] as string[], settingsOverride: {} } as const;
const tagsToFind = sourceEntries[0]
.split(SETTINGS_DEFAULT.markdownBlockTagsToFindSeparator)
.map((e) => e.trim());
sourceEntries.shift();
return {
tagsToFind,
settingsOverride: sourceEntries.reduce((accumulator, element) => {
return {
...accumulator,
...parseSingleLine(element),
};
}, {} as Partial<AutoTimelineSettings>),
} as const;
}
type OverridableSettingKey = (typeof acceptedSettingsOverride)[number];
const acceptedSettingsOverride = [
"dateDisplayFormat",
"applyAdditonalConditionFormatting",
] as const;
/**
* Checks if a given string is part of the settings keys that can be overriden.
*
* @param value - A given settings key.
* @returns the typeguard boolean `true` if the key is indeed overridable.
*/
function isOverridableSettingsKey(
value: string
): value is OverridableSettingKey {
// @ts-expect-error
return acceptedSettingsOverride.includes(value);
}
/**
* Will apply the needed formatting to a setting value based of it's key.
*
* @param key - The settings key.
* @param value - The value associated to this value.
* @returns Undefined if unvalid or the actual expected value.
*/
function formatValueFromKey(
key: string,
value: string
): AutoTimelineSettings[OverridableSettingKey] | undefined {
if (!isOverridableSettingsKey(key)) return undefined;
if (isDefinedAsString(SETTINGS_DEFAULT[key])) return value;
if
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py