mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-21 05:16:20 -07:00
fix(config): validate AnkiConnect and field grouping settings (#257)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { DEFAULT_CONFIG } from '../../definitions';
|
||||
import type { ResolveContext } from '../context';
|
||||
import { asBoolean, isObject } from '../shared';
|
||||
import { applyModernValue } from './modern-value';
|
||||
|
||||
type FieldGroupingConfigKey = 'isKiku' | 'isSenren';
|
||||
|
||||
export function applyFieldGroupingConfigResolution(
|
||||
context: ResolveContext,
|
||||
ankiConnect: Record<string, unknown>,
|
||||
key: FieldGroupingConfigKey,
|
||||
): void {
|
||||
const source = ankiConnect[key];
|
||||
if (!isObject(source)) {
|
||||
if (source !== undefined) {
|
||||
context.warn(
|
||||
`ankiConnect.${key}`,
|
||||
source,
|
||||
DEFAULT_CONFIG.ankiConnect[key],
|
||||
'Expected object.',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (const booleanKey of ['enabled', 'deleteDuplicateInAuto'] as const) {
|
||||
applyModernValue(
|
||||
context,
|
||||
source,
|
||||
booleanKey,
|
||||
`ankiConnect.${key}.${booleanKey}`,
|
||||
asBoolean,
|
||||
DEFAULT_CONFIG.ankiConnect[key][booleanKey],
|
||||
(value) => {
|
||||
context.resolved.ankiConnect[key][booleanKey] = value;
|
||||
},
|
||||
'Expected boolean.',
|
||||
);
|
||||
}
|
||||
|
||||
applyModernValue(
|
||||
context,
|
||||
source,
|
||||
'fieldGrouping',
|
||||
`ankiConnect.${key}.fieldGrouping`,
|
||||
(value) => (value === 'auto' || value === 'manual' || value === 'disabled' ? value : undefined),
|
||||
DEFAULT_CONFIG.ankiConnect[key].fieldGrouping,
|
||||
(value) => {
|
||||
context.resolved.ankiConnect[key].fieldGrouping = value;
|
||||
},
|
||||
'Expected auto, manual, or disabled.',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user