import { AttributeValidatorConfig, DataContainer, QualityAnalyzer, ScriptController } from '@dcupl/common'; import { DcuplModel, ModelParser } from '../model-parser/index.js'; import { DcuplApi } from '../dcupl/dcupl-api.js'; /** Key prefix of the models that publish the error records (#444: built on first read). */ export declare const ERROR_TRACKING_MODEL_PREFIX = "$DcuplErrorTracking"; /** * QualityController manages data quality validation and error tracking. * * TWO-TIER VALIDATION SYSTEM: * For validation to occur, BOTH conditions must be true: * 1. Global flag: qualityController.enabled (set via errorTracking.enabled OR quality.enabled in init options) * 2. Per-model flag: model.qualityConfig.enabled (defined in each model's quality configuration) * * This allows fine-grained control: disable validation globally for performance, * or enable/disable validation for specific models. */ export declare class QualityController { scriptsController: ScriptController; enabled: boolean; maxErrorsPerGroup: number; private errors; private errorCounts; private errorsChangedSinceInitData; private pendingErrorTrackingContainers; private definitionErrorKeys; private unstoredDefinitionErrors; private log; values: QualityAnalyzer.AnalyticsValues; modelParser: ModelParser | undefined; dcupl: DcuplApi; constructor(scriptsController: ScriptController); private getErrorGroupKey; /** * Exact occurrence count for an error group, independent of the per-group * storage cap (#177). Lets consolidation reflect the true number of affected * rows even when stored error objects are capped at maxErrorsPerGroup. */ private getGroupCount; setError(error: QualityAnalyzer.DcuplError): void; /** * Records a model-definition error that init re-detects from the registered definitions on every * run (attribute checks when a model is built, `validateModels`), so `resetDefinitionErrors` can * drop exactly these before the next run (#417). Registration errors (an invalid definition passed * to `models.set`, loader errors) go through `setError` and stay. */ setDefinitionError(error: QualityAnalyzer.DcuplError): void; /** * Drops the `InvalidModelDefinition` errors recorded when a definition for `modelKey` was * rejected at registration (an invalid `models.set`, a loader file): a valid `models.set` * replaces the whole definition for the key, so they no longer describe it (#417). */ removeRejectedDefinitionErrors(modelKey: string): void; /** * Drops the errors recorded with `setDefinitionError` (#417). init calls it before it builds the * models and runs `validateModels`, which record them again from the current definitions: without * it, a changed definition kept the old definition's errors and every re-init counted the same * errors once more. */ resetDefinitionErrors(): void; getErrorCounts(): Array<{ model?: string; attribute?: string; errorType: string; count: number; }>; /** * One entry per (model, attribute, errorType) group with the exact * occurrence count and how many error objects were actually retained under * the `maxErrorsPerGroup` cap (#204). Sized by group count, not error count, * so it stays small no matter how many errors a dataset produces. */ getErrorSummary(): QualityAnalyzer.ErrorGroupSummary[]; /** * Stamps `groupTotal` / `truncated` onto every retained error object so the * `$DcuplErrorTrackingErrors` rows themselves reveal when their group was * capped (#204). Mutates in place: bounded by the number of stored errors, * no per-error allocation. */ private stampGroupTotals; removeError(key: string): void; getError(key: string): QualityAnalyzer.DcuplError | undefined; getErrors(): QualityAnalyzer.DcuplError[]; resetErrors(): void; resetModelErrors(): void; /** Drops every model error recorded for `modelKey`: `models.remove` unregisters the model (#420). */ removeErrorsOfModel(modelKey: string): void; resetValidationErrors(): void; /** * Resets every error that the data processing pipeline re-detects during a * full (re-)initialization: reference, property and data-container errors. * * Without this, errors such as RemoteReferenceKeyNotFound accumulate on each * update() cycle because resetValidationErrors() only clears InvalidValidator * errors (see issue #174, Bug 2). * * Model-definition errors ('ModelDefinitionError') and loader errors * (type 'loader') are preserved because init() does not re-generate them. */ resetDataErrors(): void; /** * Consolidates the per-row errors of `model` into per-attribute aggregates * once its rows are processed. `attributes` limits it to those attributes — * a partial update consolidates only the attributes it reprocessed (#368). */ cleanUpErrors(model: DcuplModel, dataContainer: DataContainer, attributes?: ReadonlySet): void; private buildColumnCoercionError; private buildAbsentColumnError; getModelErrors(modelKey: string): QualityAnalyzer.InternalModelError[]; /** * Clean up errors for specific items and attributes only * @param model - The model to clean errors for * @param itemKeys - Set of item keys to clean errors for * @param attributesOrErrorType - Optional set of attribute keys to clean errors for, or errorType for backwards compatibility * @param errorType - Optional error type to filter by */ cleanUpErrorsForItems(model: DcuplModel, itemKeys: Set, attributesOrErrorType?: Set | QualityAnalyzer.ModelErrorType, errorType?: QualityAnalyzer.ModelErrorType): void; /** * Get errors for specific items * @param modelKey - The model key * @param itemKeys - Set of item keys to get errors for * @returns Array of errors for the specified items */ getErrorsForItems(modelKey: string, itemKeys: Set): QualityAnalyzer.InternalModelError[]; /** * Validate specific items and attributes only (partial validation) * @param model - The model to validate * @param itemKeys - Set of item keys to validate * @param attributes - Set of attribute keys to validate * @returns Array of validation errors found */ validateItemsPartial(model: DcuplModel, itemKeys: Set, attributes: Set): QualityAnalyzer.InternalModelError[]; /** * Prepares the error records of `model` for a partial update, so that the * update leaves the same records and summary() counts as init() on the same * data (#368). Removes the errors the update re-derives: * - every data error of a deleted item; * - the attribute errors of the changed items for the changed attributes — * step 1 of the partial path reprocesses exactly these rows (`itemKeys`) * and `attributes`; * - the `unique` errors when rows changed: the check compares all rows and * finishPartialUpdate() re-runs it. * * Returns the attributes whose errors must be derived from every row * instead; all their attribute errors are removed and the partial path * reprocesses them for all rows: * - an attribute with a per-attribute aggregate (UndefinedAttribute, * WrongDataType): the aggregate stands for rows the update does not * reprocess; * - an attribute with an error group capped by `maxErrorsPerGroup`: its * unstored errors cannot be removed one by one; * - a `unique` attribute with strict handling when rows changed: init() * dropped the duplicate values, only reprocessing restores them for the * re-check. */ prepareErrorsForPartialUpdate(model: DcuplModel, attributes: ReadonlySet, itemKeys: ReadonlySet, deletedItemKeys: ReadonlySet): Set; /** * Completes the error records of `model` after a partial update (#368), the * way init() does: consolidates the reprocessed `attributes` into * per-attribute aggregates (cleanUpErrors) and, when rows changed, re-runs * the `unique` validators (whose errors prepareErrorsForPartialUpdate() * removed). `dataContainer` is the model's complete merged container. */ finishPartialUpdate(model: DcuplModel, dataContainer: DataContainer, attributes: ReadonlySet, rowsChanged: boolean): void; private getUniqueAttributes; /** Strict unless the attribute's quality config says `'loose'` (as validateUnique decides). */ private isStrictValidatorHandling; /** * Whether the error records changed since initData() last published them to the * $DcuplErrorTracking* models; a partial update skips the rebuild otherwise (#368). */ hasErrorChangesSinceInitData(): boolean; initData(): Promise; /** * Builds $DcuplErrorTrackingErrors / -Summary from the error set the last init()/update() * published, if no read built them since (#444). Every read of a $DcuplErrorTracking* model * calls it first (ModelParser.prepareModelForRead), so a read returns what the build at * init()/update() returned, and a read between two updates never sees an older set (#174). * The rows go in through the parser's data processing, which leaves the change tracker and the * error records alone. * * A read while an apply is suspended mid-processing is not guarded: reads were never queued * behind applies, and what such a read sees of the error models is the state the apply has * reached. */ materializeErrorTrackingModels(): void; /** * Drops the snapshot initData() queued and nothing has read, without building it. A full init() * calls it right after prepareModels() reset the error-tracking models: the containers of the * last apply are still queued, so the init pipeline processes them again, as before #444, and * initData() stages the new set at its end. Replaying the unread snapshot as well would serve * rows of an apply that is gone: after a full apply that fails (getErrors() is empty then), or * for models that left the queue before init(). */ discardPendingErrorTrackingSnapshot(): void; /** Empties the rows and the indices of $DcuplErrorTrackingErrors and -Summary. */ private resetErrorTrackingRowModels; /** * Whether a list over a $DcuplErrorTracking* model exists, the hidden `__global_list__…` lists * of `query.execute` / `fn.*` included. The apply refreshes such a list right after * initData(), so initData() builds the models for it at once (#444). */ private hasErrorTrackingLists; initErrorTrackingModels(): void; initAnalyticsValues(): void; private calculateUnusedAttributes; private calculateCounts; private calculateTiming; private calculateSizes; private calculateErrorTrackingFacet; private calculateSizesForModels; calculateUnusedData(): number; private getDataWithAttributes; private getUnusedAttributesFromModel; private getUnusedAttributes; validateAttribute(value: any, validators: AttributeValidatorConfig, attribute: string): QualityAnalyzer.InternalModelError[]; validateAttributesAfterInitialization(model: DcuplModel): QualityAnalyzer.InternalModelError[]; private validateUnique; private validateEmail; private validateMin; private validateMax; private validateStartsWith; private validateEndsWith; private validateIncludes; private validateMinLength; private validateMaxLength; private validateEnum; private validatePattern; }