Skip to content

oracular / validateConfig

Function: validateConfig() ​

ts
function validateConfig(config): EngineConfig;

Defined in: validate.ts:24

Checks a config exactly as createState and deserialize do, without building a state, and returns the normalized copy they would store: only the recognised keys, in a fixed order, with every undefined dropped, so it survives a JSON round trip unchanged. Use it to fail fast at startup or in a test, or on a config loaded from a file, before the engine runs.

Parameters ​

ParameterTypeDescription
configunknownThe config to check. Typed unknown so parsed JSON can be passed as it is.

Returns ​

EngineConfig

A fresh, normalized EngineConfig. config is not mutated.

Throws ​

TypeError when a value has the wrong type or a key is not recognised.

Throws ​

RangeError when a number is out of range: a prior outside (0, 1), a signal weight of 0, or a weight, priorStrength, learning.gain or learning.priorEpisodes beyond 1e6.

Example ​

ts
import { readFileSync } from 'node:fs';
import { validateConfig } from 'oracular';

// Throws with the offending path in the message, e.g. config.intents["upgrade"].prior
const config = validateConfig(JSON.parse(readFileSync('oracular.config.json', 'utf8')));

Released under the MIT License.