Added basic schema to field-configuration
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Field_Configuration } from '@efforting.tech/data/field-configuration';
|
||||
import { Schema, Field_Configuration } from '@efforting.tech/data/field-configuration';
|
||||
|
||||
|
||||
function mandatory_anything(value) {
|
||||
@@ -15,7 +15,8 @@ function string_coercion_function(value) {
|
||||
|
||||
|
||||
|
||||
const fc = new Field_Configuration('Some_Field', null, string_coercion_function, 'Anything that could be a string');
|
||||
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));
|
||||
@@ -23,9 +24,27 @@ 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) ]);
|
||||
// console.log([ fc.load(undefined, 'Some configuration') ]);
|
||||
// console.log([ fc.load(true) ]);
|
||||
|
||||
|
||||
//fc.validate(undefined);
|
||||
console.log(fc.load(undefined, 'New thingamabob object'));
|
||||
//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' } }
|
||||
|
||||
Reference in New Issue
Block a user