Fixed bug in makefile due to renaming the tool script before, bumped version, made factories for easier schema definition
This commit is contained in:
2
Makefile
2
Makefile
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
build/packages:
|
build/packages:
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
node tools/stage-for-pnpn.mjs package-manifest.yaml source $@
|
node tools/stage-for-pnpm.mjs package-manifest.yaml source $@
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
cd build/packages && ./publish-all.sh
|
cd build/packages && ./publish-all.sh
|
||||||
|
|||||||
9
experiments/config2.mjs
Normal file
9
experiments/config2.mjs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import * as F from '@efforting.tech/data/field-configuration-factories';
|
||||||
|
|
||||||
|
const s = new F.Schema({
|
||||||
|
foo: F.value(123, 'The value'),
|
||||||
|
bar: F.factory((t) => `Field ${t.field_name} was not set`, 'The factory'),
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
console.log(s.load()) // { foo: 123, bar: 'Field bar was not set' }
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
scope: '@efforting.tech'
|
scope: '@efforting.tech'
|
||||||
registry: 'https://npm.efforting.tech/'
|
registry: 'https://npm.efforting.tech/'
|
||||||
version: 0.2.4
|
version: 0.2.5
|
||||||
|
|
||||||
author:
|
author:
|
||||||
name: 'Mikael Lövqvist'
|
name: 'Mikael Lövqvist'
|
||||||
|
|||||||
5
package.json
Normal file
5
package.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"experiments": "^0.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
source/data/field-configuration-factories.mjs
Normal file
20
source/data/field-configuration-factories.mjs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Field_Configuration } from './field-configuration.mjs';
|
||||||
|
export { Schema } from './field-configuration.mjs';
|
||||||
|
|
||||||
|
//constructor(validation_function=null, coercion_function=null, factory_function=null, expected_description=undefined) {
|
||||||
|
|
||||||
|
export function value(default_value, description) {
|
||||||
|
return new Field_Configuration(null, null, () => default_value, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function factory(factory_function, description) {
|
||||||
|
return new Field_Configuration(null, null, factory_function, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function typed_value(coercion_function, default_value, description) {
|
||||||
|
return new Field_Configuration(null, coercion_function, () => default_value, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function typed_factory(coercion_function, factory_function, description) {
|
||||||
|
return new Field_Configuration(null, coercion_function, factory_function, description);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Data_Validation_Failed, Data_Coercion_Failed, Superfluous_Data_Field } from '@efforting.tech/errors';
|
import { Data_Validation_Failed, Data_Coercion_Failed, Superfluous_Data_Field } from '@efforting.tech/errors';
|
||||||
|
|
||||||
|
|
||||||
export class Field_Configuration {
|
export class Field_Configuration {
|
||||||
constructor(validation_function=null, coercion_function=null, factory_function=null, expected_description=undefined) {
|
constructor(validation_function=null, coercion_function=null, factory_function=null, expected_description=undefined) {
|
||||||
Object.assign(this, { validation_function, coercion_function, factory_function, expected_description });
|
Object.assign(this, { validation_function, coercion_function, factory_function, expected_description });
|
||||||
|
|||||||
Reference in New Issue
Block a user