Fixed bug in makefile due to renaming the tool script before, bumped version, made factories for easier schema definition

This commit is contained in:
2026-04-09 20:11:50 +02:00
parent 0cdc4e271b
commit ae40c680de
7 changed files with 37 additions and 2 deletions

50
experiments/config1.mjs Normal file
View File

@@ -0,0 +1,50 @@
import { Schema, Field_Configuration } from '@efforting.tech/data/field-configuration';
function mandatory_anything(value) {
return value !== undefined;
}
function string_coercion_function(value) {
if (value === undefined) {
throw new Error('Undefined not allowed');
}
return String(value);
}
const fc = new Field_Configuration(null, string_coercion_function, null, 'Anything that could be a string');
const fd = new Field_Configuration(null, string_coercion_function, () => 'baz', 'A string. Defaults to \'baz\'');
console.log(fc.check_validation(undefined));
console.log(fc.check_validation(true));
console.log([ fc.coerce(123) ]);
console.log([ fc.coerce(true) ]);
// console.log([ fc.load(undefined, 'Some configuration') ]);
// console.log([ fc.load(true) ]);
//fc.validate(undefined);
//console.log(fc.load(undefined, 'New thingamabob object'));
const s = new Schema({
foo: fc,
bar: fd,
});
const s2 = new Schema({
thing: fc,
stuff: s,
});
console.log(s2.load({
stuff: { foo: 'Hello World' },
thing: 123,
}));
// { thing: '123', stuff: { foo: 'Hello World', bar: 'baz' } }