UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

56 lines (55 loc) 2.18 kB
import { type GlobalConfiguration, Configuration, type ApplicationScope, type ConfigurationUpdater, type Validators } from "../internal.mjs"; /** * @typeParam S - the type of the validator factory */ declare abstract class AbstractValidators<S> implements Validators<S> { /** * A function that converts the thrown error to `AssertionError`. */ private static readonly CONVERT_TO_ASSERTION_ERROR; protected readonly scope: ApplicationScope; private requireThatConfiguration; private assertThatConfiguration; private checkIfConfiguration; protected readonly context: Map<string, unknown>; /** * Creates a new instance. * * @param scope - the application configuration * @param configuration - the configuration to use for new validators * @throws TypeError if any of the arguments are `undefined` or `null` */ protected constructor(scope: ApplicationScope, configuration: Configuration); /** * @returns the application configuration */ getScope(): ApplicationScope; getRequireThatConfiguration(): Configuration; /** * Returns the configuration for `assertThat` factory methods. * * @returns the configuration for `assertThat` factory methods */ protected getAssertThatConfiguration(): Configuration; /** * Returns the configuration for `checkIf` factory methods. * * @returns the configuration for `checkIf` factory methods */ protected getCheckIfConfiguration(): Configuration; updateConfiguration(): ConfigurationUpdater; updateConfiguration(updater: (configuration: ConfigurationUpdater) => void): this; /** * Set the configuration used by new validators. * * @param configuration - the updated configuration * @throws TypeError if `configuration` is null */ setConfiguration(configuration: Configuration): void; getContext(): Map<string, unknown>; getGlobalConfiguration(): GlobalConfiguration; abstract copy(): S; abstract removeContext(name: string): this; abstract withContext(value: unknown, name: string): this; } export { AbstractValidators };