UNPKG

@eclipse-emfcloud/model-validation

Version:

Generic model validation framework.

66 lines 2.94 kB
import { Diagnostic } from './diagnostic'; import { ValidationSubscription } from './validation-subscription'; import { Validator } from './validator'; /** * A service for validation of models. The validation algorithm is * delegated to pluggable {@link Validator}s. The service maintains the * last validation state computed for every model for retrieval at * any time. * * @template K the type of model identifier by which validation state is tracked */ export interface ModelValidationService<K> { /** * Add a validator to which the service shall delegate model validation. * * @param validator a validator to add to the service */ addValidator<M extends object = object>(validator: Validator<K, M>): void; /** * Compute the validation state of the given `model`. * The validation service is not required to support validation of sub-models * or individual elements of a model. * * @param modelId the unique identifier of the `model` to validate * @param model the model to validate * @returns the `model`'s validation state */ validate(modelId: K, model: object): Promise<Diagnostic>; /** * Obtain the current validation state of the given `model`, being that which * was most recently computed. * * @param modelId the unique identifier of a model * @returns the indicated model's most recent validation state, or `undefined` * if none has yet been computed for it */ getValidationState(modelId: K): Diagnostic | undefined; /** * Create a new subscription for notification of updates to the validation * state of models. If no `modelIds` are provided, then the subscription * will be notified of validation updates for all models tracked by this * validation manager. Otherwise, the subscription will be notified only * for the specific models identified. * * @template M the type of model to which to subscribe for validation updates * * @param modelIds zero or more model IDs to filter the subscription on * @returns the subscription */ subscribe<M extends object = object>(...modelIds: K[]): ValidationSubscription<K, M>; } export declare class ModelValidationServiceImpl<K> implements ModelValidationService<K> { private readonly _validators; private readonly _validationState; private readonly _subscriptions; private readonly _subscriptionsToAllModels; addValidator<M extends object = object>(validator: Validator<K, M>): void; validate(modelId: K, model: object): Promise<Diagnostic>; getValidationState(modelId: K): Diagnostic | undefined; subscribe<M extends object = object>(...modelIds: K[]): ValidationSubscription<K, M>; private addSubscription; private addAllSubscription; private deleteSubscription; private deleteAllSubscription; } //# sourceMappingURL=model-validation-service.d.ts.map