Started textnodes, renamed tool with wrong name, started field configuration system

This commit is contained in:
2026-04-08 23:32:05 +02:00
parent d2900bfd12
commit a088f97e2e
7 changed files with 62 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
import { Invalid_Data } from '@efforting.tech/errors';
export class Field_Configuration {
constructor(name, validator=null, expected=undefined) {
Object.assign(this, { name, validator, expected });
}
check_validation(value) {
const { validator } = this;
return !validator || validator(value);
}
validate(value, target=undefined) {
const { validator, name, expected } = this;
if (!this.check_validation(value)) {
throw new Invalid_Data({
name, validator, value,
target, expected,
});
}
}
}

View File

@@ -1,5 +1,18 @@
import { inspect } from 'node:util';
// § GROUP: Configuration field errors
export class Invalid_Data extends Error {
constructor(data) {
const { value, target, expected, validator, name } = data;
const type = value === null ? 'null' : typeof value;
const target_info = target ? inspect(target) : 'unknown target';
const expected_desc = expected ?? `data that would pass validation using ${validator}`;
super(`Data validation failed for field "${name}" of ${target_info}. Encountered data of type "${type}" while expecting "${expected_desc}".`);
this.data = data;
}
}
// § GROUP: Resolving errors
export class Item_Unresolvable extends Error {