Validators using zod
This commit is contained in:
@@ -7,7 +7,8 @@ import { join } from "@std/path";
|
||||
import { type Bmod, BMOD_EXTENSION, client_copy, read_bmod, write_bmod } from "$/common/bmod.ts";
|
||||
import { check_references, load_order, type LoadedMod } from "$/common/mod_check.ts";
|
||||
import type { ModListing } from "$/common/mod_loader.ts";
|
||||
import { FORMAT_VERSION, is_object } from "$/common/mod_data.ts";
|
||||
import { data_file, FORMAT_VERSION } from "$/common/mod_data.ts";
|
||||
import { is_object, json_object } from "$/common/schema.ts";
|
||||
import { sha256 } from "$/common/utils.ts";
|
||||
|
||||
export interface ServerMod {
|
||||
@@ -118,11 +119,12 @@ function change_config(bmod: Bmod, config_dir: string, problems: string[]) {
|
||||
problems.push(`${file}: isn't valid json: ${(e as Error).message}`);
|
||||
return;
|
||||
}
|
||||
if (!is_object(json) || json.format_version !== FORMAT_VERSION || !is_object(json.config)) {
|
||||
const config_file = data_file("config", json_object).safeParse(json);
|
||||
if (!config_file.success) {
|
||||
problems.push(`${file}: must be { "format_version": ${FORMAT_VERSION}, "config": { ... } }`);
|
||||
return;
|
||||
}
|
||||
const changed = apply_config(bmod.data.config ?? {}, json.config);
|
||||
const changed = apply_config(bmod.data.config ?? {}, config_file.data.config as Record<string, unknown>);
|
||||
problems.push(...changed.problems.map((problem) => `${file}: ${problem}`));
|
||||
bmod.data.config = changed.config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user