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' } }