Started textnodes, renamed tool with wrong name, started field configuration system
This commit is contained in:
16
experiments/config.mjs
Normal file
16
experiments/config.mjs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Field_Configuration } from '@efforting.tech/data/field-configuration';
|
||||||
|
|
||||||
|
|
||||||
|
function mandatory_anything(value) {
|
||||||
|
return value !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const fc = new Field_Configuration('Some_Field', mandatory_anything, 'Anything defined');
|
||||||
|
|
||||||
|
|
||||||
|
console.log(fc.check_validation(undefined));
|
||||||
|
console.log(fc.check_validation(true));
|
||||||
|
|
||||||
|
//fc.validate(undefined);
|
||||||
|
fc.validate(undefined, 'New thingamabob object');
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@efforting.tech/errors": "link:../build/packages/errors",
|
"@efforting.tech/errors": "link:../build/packages/errors",
|
||||||
"@efforting.tech/rule-processing": "link:../build/packages/rule-processing"
|
"@efforting.tech/rule-processing": "link:../build/packages/rule-processing",
|
||||||
|
"@efforting.tech/data": "link:../build/packages/data"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0
experiments/textnodes.mjs
Normal file
0
experiments/textnodes.mjs
Normal file
@@ -21,6 +21,12 @@ packages:
|
|||||||
internal-dependencies:
|
internal-dependencies:
|
||||||
- errors
|
- errors
|
||||||
|
|
||||||
|
data:
|
||||||
|
path: source/data
|
||||||
|
#documentation: documentation/data
|
||||||
|
description: Data management
|
||||||
|
internal-dependencies:
|
||||||
|
- errors
|
||||||
|
|
||||||
wip-packages:
|
wip-packages:
|
||||||
object-graph-storage:
|
object-graph-storage:
|
||||||
|
|||||||
24
source/data/field-configuration.mjs
Normal file
24
source/data/field-configuration.mjs
Normal 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,18 @@
|
|||||||
import { inspect } from 'node:util';
|
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
|
// § GROUP: Resolving errors
|
||||||
|
|
||||||
export class Item_Unresolvable extends Error {
|
export class Item_Unresolvable extends Error {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ for (const [package_name, package_data] of Object.entries(manifest.packages)) {
|
|||||||
const exports_map = {};
|
const exports_map = {};
|
||||||
for (const file of linked_sources) {
|
for (const file of linked_sources) {
|
||||||
const name = path.basename(file, '.mjs');
|
const name = path.basename(file, '.mjs');
|
||||||
const key = name === pkg.name ? '.' : `./${name}`;
|
const key = name === path.basename(pkg.name) ? '.' : `./${name}`;
|
||||||
exports_map[key] = `./${file}`;
|
exports_map[key] = `./${file}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user