diff --git a/experiments/os1.mjs b/experiments/os1.mjs index f5a028d..88c7a4f 100644 --- a/experiments/os1.mjs +++ b/experiments/os1.mjs @@ -2,35 +2,6 @@ import { inspect } from 'node:util'; -class Not_Storable_Error extends Error { - constructor(data) { - const { storage, value, property, id } = data; - const type = value === null ? 'null' : typeof value; - const location = property ? `property "${property}" of record #${id}` : `record #${id}`; - super(`Cannot store value of type "${type}" in ${location}: ${inspect(value)}`); - this.data = data; - } -} - -class Not_Mutable_Error extends Error { - constructor(data) { - const { storage, value, property, id } = data; - const type = value === null ? 'null' : typeof value; - const location = property ? `property "${property}" of record #${id}` : `record #${id}`; - super(`Cannot set ${location}: record is immutable (tried to store value of type "${type}": ${inspect(value)})`); - this.data = data; - } -} - -class No_Such_Object_Index_Error extends Error { - constructor(data) { - const { storage, property, id } = data; - const location = property ? `property "${property}" of record #${id}` : `record #${id}`; - super(`Cannot get ${location}: no such record index`); - this.data = data; - } -} - function load_descriptor({ type, value }, { storage, mutable }) { if (type === 'primitive') { diff --git a/experiments/res1.mjs b/experiments/res1.mjs index 06c045b..df90ae9 100644 --- a/experiments/res1.mjs +++ b/experiments/res1.mjs @@ -1,13 +1,5 @@ -import { inspect } from 'node:util'; -class Item_Unresolvable extends Error { - constructor(data) { - const { resolver, item } = data; - const type = item === null ? 'null' : typeof item; - super(`Cannot resolve item ${inspect(item)} of type "${type}" using resolver ${resolver}`); - this.data = data; - } -} + class Abstract_Resolver { resolve(item) { @@ -63,3 +55,4 @@ tr.rules.set('string', () => 'World'); console.log(cr.resolve('HELLO')); console.log(cr.resolve('hello')); +console.log(cr.resolve(123)); diff --git a/package-manifest.yaml b/package-manifest.yaml index 99cad4f..016d1b5 100644 --- a/package-manifest.yaml +++ b/package-manifest.yaml @@ -4,3 +4,15 @@ packages: documentation: documentation/object-graph-storage description: Lightweight persistent storage for structured data. version: 0.1.0 + + rule-processing: + path: source/rule-processing + documentation: documentation/rule-processing + description: Rule based visitors, transformers, resolvers, processors, operators, aggregators and such. + version: 0.1.0 + + errors: + path: source/errors.mjs + documentation: documentation/errors + description: Library wide error definitions + version: 0.1.0 diff --git a/source/errors.mjs b/source/errors.mjs new file mode 100644 index 0000000..98d6a00 --- /dev/null +++ b/source/errors.mjs @@ -0,0 +1,45 @@ +import { inspect } from 'node:util'; + +// § GROUP: Resolving errors + +export class Item_Unresolvable extends Error { + constructor(data) { + const { resolver, item } = data; + const type = item === null ? 'null' : typeof item; + super(`Cannot resolve item ${inspect(item)} of type "${type}" using resolver ${resolver}`); + this.data = data; + } +} + + +// § GROUP: Storage errors + +export class Not_Storable_Error extends Error { + constructor(data) { + const { storage, value, property, id } = data; + const type = value === null ? 'null' : typeof value; + const location = property ? `property "${property}" of record #${id}` : `record #${id}`; + super(`Cannot store value of type "${type}" in ${location}: ${inspect(value)}`); + this.data = data; + } +} + +export class Not_Mutable_Error extends Error { + constructor(data) { + const { storage, value, property, id } = data; + const type = value === null ? 'null' : typeof value; + const location = property ? `property "${property}" of record #${id}` : `record #${id}`; + super(`Cannot set ${location}: record is immutable (tried to store value of type "${type}": ${inspect(value)})`); + this.data = data; + } +} + +export class No_Such_Object_Index_Error extends Error { + constructor(data) { + const { storage, property, id } = data; + const location = property ? `property "${property}" of record #${id}` : `record #${id}`; + super(`Cannot get ${location}: no such record index`); + this.data = data; + } +} +