import { DataContainer, Reference, AggregatedReference, DerivedReference, GroupedRefeference, ResolvedReference, ListItem, ModelDefinition, Property, PropertyAggregate, ValueMappingConfig, ModelMetadata, IndicesController, ChangeDetector, AutoGeneratePropertiesOption, ModelQualityConfig, AttributeQualityConfig, ValidatorErrorType, QueryReference, RawItem } from '@dcupl/common'; import { ModelParser } from '../index.js'; export declare const EntryMetadataValues: { REF_VALUE: string; }; export type ValidatorReturnValue = { isValid: boolean; type: ValidatorErrorType; }; export declare class DcuplModel { private modelParser; properties: Map; references: Map; attributeQualityConfigs: Map; key: string; private log; initialDefinition: ModelDefinition; private data; private autoCreatedRows; private pendingAutoCreatedContainers; private autoCreatedInUpdate; private inPartialAutoCreatedPass; supportsAutoCreation: boolean; autoGenerateKey: boolean; autoGenerateProperties: boolean; autoGeneratePropertiesOption: AutoGeneratePropertiesOption; private inferredKeyedRows; keyProperty: string | readonly string[]; keyPropertySeparator?: string; valueMappings: ValueMappingConfig[]; meta?: ModelMetadata | undefined; qualityConfig: ModelQualityConfig; indicesController: IndicesController; cdRef: ChangeDetector; private groupedRefReverseIndex; private derivedReferenceIndexedKeys; private pendingItemKeys; private missedReferenceKeys; private missesToPending; constructor(modelParser: ModelParser); init(modelDefinition: ModelDefinition): void; /** * Drops what the previous definition set (attributes and their quality configs, the model's * quality config), so `init` + `applyPropertiesAndReferences` build the model from a replaced * definition as for a new model, while lists keep this instance (#408). */ resetDefinition(): void; applyPropertiesAndReferences(modelDefinition: ModelDefinition): void; private setAttributeQualityConfig; getModelDefinition(): ModelDefinition; /** * Adds a property for every attribute that inference finds in the leading rows of `container` * (one row by default, `sampleSize` or all rows when deep) and the model does not have yet. * Properties the model has keep their type, so inference runs only when one of those rows names * an attribute the model does not know (#503, #519). * * `changedItemKeys`: the items an update changed or inserted, given when it removed none. The * rows with a key kept their order and, unless changed, their attributes since the last * inference, so of the keyed rows the last inference read only the changed ones can name a new * attribute. Rows without a key can move (a merge puts them last, init reads a lone `set` as it * is) and are always read, as are the keyed rows past that count. */ generatePropertiesFromContainer(container: DataContainer, changedItemKeys?: ReadonlySet): void; /** * Whether one of the first `rowLimit` rows has an attribute that is no property, and how many of * them have a key. With `known`, the first `known.keyedRows` rows with a key are skipped unless * they changed: the last inference read them. */ private scanInferenceWindow; private getReferenceKeys; /** A definition error init re-detects on every run (#417); same gate as `setError`. */ private setDefinitionError; private sharedErrorDescriptions; private sharedErrorDescription; /** * Sets a validation error for this model. * Requires both global quality controller AND model-specific quality to be enabled. */ private setError; /** * Emit one `UnknownColumn` error per (model, attribute) for columns in the * source that are NOT declared on the model. The data for those columns is * silently dropped during ingest — this surfaces that data loss without * failing the load. See dcupl#183. */ private emitUnknownColumnErrors; /** * Coerces and validates one basic property of a raw row and stores it on * `dataEntry`. Returns whether a value was stored — `false` when the raw * value is missing or the coercion or a strict validator rejects it. */ private processBasicProperty; private handleValidators; private getWrongDataTypeError; /** * Detects a lossy numeric coercion: the raw value was successfully coerced to a * number, but information was silently dropped — either trailing/embedded * non-numeric content (e.g. "1.2 lbs" → 1.2), a dropped leading zero on int and * float properties (e.g. "06112" → 6112, "007" → 7: postal codes and article * numbers lose their text, #520, #550), or fractional truncation for int * properties (e.g. "1.2" → 1). Representation-only differences that preserve the * value (trailing zeros, surrounding whitespace, "4.0" → 4, "0", "0.5", "-0.0") * are not considered lossy. */ private isLossyNumericCoercion; private getLossyCoercionError; private getValueAsArray; private processStringProperty; private processIntProperty; private processFloatProperty; private processJSONProperty; /** * A boolean is kept as is. A string follows {@link parseBooleanString}: 'true'/'false'/'1'/'0' * (case-insensitive) become booleans, any other string is a WrongDataType and the value stays * undefined (#364). Numbers are strict too: 1 and 0 become true and false, any other number is a * WrongDataType. Any other value, such as an object or an array, is a WrongDataType as well (#402). * With `forceStrictDataType` only real booleans pass. */ private processBooleanProperty; private processDateProperty; /** The NullValue error of a non-nullable reference with an explicit null, as for a property (#215). */ private getNullReferenceError; private processSingleValuedReference; private processMultiValuedReference; getViewKeys(): string[]; /** * Records one `NonUniqueKey` per row that a later row with the same key * replaced in the container's `set` payload. ModelParser dedupes the rows * before processing (the last row wins as a whole) and keeps the replaced * keys beside the container, so every full apply reports them again (#369). */ private emitNonUniqueKeyErrors; /** Forgets every listed miss, before a step-1 pass over all of this model's rows (#425). */ resetMissedReferenceKeys(): void; /** Lists `itemKey` under the remote key its reference `referenceKey` did not find (#425). */ private recordMissedReference; /** Moves the appended misses into `byRemoteKey`, where a row resolved again is listed once (#425, #590). */ private foldMissedReferences; private addMissedReference; /** * The stored items whose reference `referenceKey` did not find one of * `remoteKeys` when it was last resolved, and drops those entries (#425): * the caller re-resolves the items, which lists them again if they still miss. */ takeItemsMissingReferenceKeys(referenceKey: string, remoteKeys: Iterable): Set; /** Whether `remoteModel` holds the item `key`, or is about to within this model's step-1 pass (#411). */ private hasRemoteEntry; /** * The keys of the given rows when this model has a basic reference to * itself, for `pendingItemKeys` (#411); `undefined` otherwise. */ getPendingItemKeys(rows: ListType[]): Set | undefined; addBasicPropertiesAndReferences(container: DataContainer): void; addQueryReferences(container: DataContainer): void; /** * Runs one query reference again for the given raw rows on the partial * path (#429). Each row's previous value is dropped first, so a row without * a hit ends up as on init(), where the attribute was never set. */ recomputeQueryReference(qR: QueryReference, rawRows: readonly RawItem[]): void; /** * The owner rows, among `rawRows`, whose query reference result a change of * the target items `targetKeys` can alter (#429): the rows whose current * value lists one of those items, and the rows whose query matches one of * the items that exist now. Only for a query whose result is the set of * matching items (see ModelParser.planQueryReferences): the other rows keep * the same set of matches, so the same result. */ getRowsAffectedByTargetItems(qR: QueryReference, rawRows: readonly RawItem[], targetKeys: ReadonlySet): RawItem[]; /** The query a query reference runs for one raw row: its template filled from the row. */ private getQueryReferenceQuery; private applyQueryReference; private isValidValueMapping; private mapRawValueUsingValueMapping; private handleAutoCreationAndReturnKey; /** * Queues the pass of an auto-created item. While the parser defers the passes (step 1 of init() * and of the partial path), it runs them all after every model's step 1 * (ModelParser.processPendingAutoCreatedItems, #604, #619); otherwise the pass runs at the next * yield, one pass per callback, in order. A callback that finds the queue empty does nothing. */ private queueAutoCreatedContainer; /** * The next queued container, without the rows a row of the model's own data replaced since * (forgetAutoCreatedRows): the row's item is processed as the model's data. */ private takeAutoCreatedContainer; /** * The first half of the queued passes of auto-created items, those they queue included: their * basic properties and references. Returns the containers, for finishAutoCreatedPasses once * every queued item of every model has its basic attributes (#604, #619). */ addBasicsOfPendingAutoCreatedContainers(partial: boolean): DataContainer[]; /** * The second half of the passes addBasicsOfPendingAutoCreatedContainers began: query, resolved * and derived attributes, read from the basic attributes of every item, the auto-created ones * included (#619). */ finishAutoCreatedPasses(containers: DataContainer[], partial: boolean): void; /** Starts the bookkeeping of the items a referrer auto-creates in an update() (#604). */ clearAutoCreatedInUpdate(): void; /** The keys of the auto-created items that a referrer created in the running update() (#604). */ getItemsAutoCreatedInUpdate(): string[]; /** * Runs the pass of the given basic `attributes` again for the items a referrer auto-created in * the running update(), whose errors the partial path removed before it consolidated the * model's own rows (#604): init() records them after that consolidation. */ reprocessItemsAutoCreatedInUpdate(attributes: ReadonlySet): void; /** Whether the item is one a referrer auto-created and no row of the model's data holds (#598). */ isAutoCreatedItem(itemKey: string): boolean; /** * Adds the items a referrer auto-created in the running update() to the indices a read built * before it (#599): a plain index lists every item under its value, `undefined` included, so the * new item goes under its own value, as a rebuild would put it (adding it twice changes nothing). * A context index (aggregate, sections, suggest) and a deep index are dropped instead: the next * read rebuilds them. */ addItemsAutoCreatedInUpdateToIndices(): void; /** * `rows` are rows of the model's own data: an item a referrer auto-created before is the row's * item from now on, and stays when its referrers go (#598). */ forgetAutoCreatedRows(rows: readonly RawItem[]): void; /** The pass of an auto-created item: its basic attributes, then the attributes read from them. */ private addContainer; /** The basic properties and references of auto-created items. False: the container is invalid. */ private addContainerBasics; /** The query, resolved and derived attributes of auto-created items, after their basic ones. */ private finishContainer; private measureAutoGenerateData; addResolvedReferences(container: DataContainer): void; /** * Rebuilds resolved references for ALL items in this model * Used in partial updates when source references change * @param specificReferences - Optional set of specific reference keys to rebuild */ rebuildResolvedReferencesForAllItems(specificReferences?: Set): void; addDerivedReferencesGroupedReferencesDerivedPropertiesAndExpressionProperties(container: DataContainer): void; /** * Evaluates an expression property onto the item. With `index: true` its index follows the * stored value: the item leaves the entry of its previous value and joins the new one. These * are the only two places an expression value is written (the full and the partial path), so * the index is never stale and a partial update keeps it (#430). */ private handleExpressionProperty; private handleDerivedProperties; reRunDerivedPropertiesBasedOnResolves(container: DataContainer): void; private handleSingleValuedDerivedProperties; private handleMultiValuedDerivedProperties; private handleDerivedReferences; private asStringArray; private buildReverseIndexForReference; private ensureReverseIndex; private handleGroupedReferences; resetData(): void; resetIndexMap(): void; /** * Drops model-level indices derived from the given attributes after a * partial update (#243): lazily built plain indices (facets/pivot * fallback), context-hashed indices (aggregate/sections/suggest) and * deep-query indices are built from data a partial update silently * invalidates — the next read rebuilds them from current data. A * reference's plain index stays: it is maintained eagerly during * processing, and the generic lazy rebuild cannot reproduce its shape. So * does the plain index of an expression property with `index: true` (#430). * Not so for grouped and query references: nothing fills their plain index, * on init() either, so the first read builds it lazily and a partial update * must drop it (#609). * * Which attribute an index belongs to comes from the indices controller's * record, not from the index name: cutting `the_customer.country_` * at `_` reads `the`, and `price` matched `price_net` (#358). */ resetIndicesForChangedAttributes(attributeKeys: Set): void; deleteDataEntries(data: DataContainer): void; getItemCount(): number; getAttributes(): (Reference | Property)[]; getAttribute(key: string): Reference | Property | undefined; getReferencesRelevantForDependencyGraph(): Reference[]; getBasicReferences(): Reference[]; getQueryReferences(): QueryReference[]; getResolvedReferences(): ResolvedReference[]; getGroupedReferences(): GroupedRefeference[]; getDerivedReferences(): DerivedReference[]; getAggregatedReferences(): AggregatedReference[]; getBasicProperties(): Property[]; getDerivedProperties(): Property[]; getDerivedPropertiesForBasicAndDerivedReferences(): Property[]; getDerivedPropertiesForResolvedReferences(): Property[]; getDerivedReferencesForResolvedReferences(): DerivedReference[]; getExpressionProperties(): Property[]; getAggregatedProperties(): PropertyAggregate[]; hasBasicReferences(): boolean; hasQueryReferences(): boolean; hasResolvedReferences(): boolean; hasGroupedReferences(): boolean; hasDerivedReferences(): boolean; hasBasicProperties(): boolean; hasDerivedProperties(): boolean; hasDerivedPropertiesForBasicReferences(): boolean; hasDerivedPropertiesBasedOnResolvedReferences(): boolean; hasDerivedReferencesBasedOnResolvedReferences(): boolean; hasExpressionProperties(): boolean; hasAggregatedProperties(): boolean; getData(options?: { itemKeys: string[]; }): Map; getDataAsArray(): ListType[]; getEntry(key: string): ListType | undefined; private setRefValue; /** * The raw rows of the items a referrer auto-created so far, by key: a copy, so the items a * partial update auto-creates while it runs stay out of it (#608). */ getAutoCreatedRows(): Map; /** * Re-derives the given attributes of the auto-created `rows` (getAutoCreatedRows() before the * update) that are still items and not rows of `container` (#608). A partial update that * re-derives an attribute's errors for every row drops the errors of every item, but * reprocesses only the container's rows: init() records the auto-created items' errors when * the referrer creates them, after the model's own rows and their aggregates, so the partial * path re-derives them after its cleanUpErrors() too. An item the update auto-created records * its errors itself, so it is not in `rows`. */ reprocessAutoCreatedRows(container: DataContainer, attributes: ReadonlySet, rows: ReadonlyMap): void; /** * Processes only specific basic properties and references (Step 1) * @param container - Data container to process * @param attributesToProcess - Set of attribute keys to process */ addBasicPropertiesAndReferencesPartial(container: DataContainer, attributesToProcess: Set, pendingItemKeys?: Set | undefined): void; /** * Processes only specific query and resolved references (Step 2) * @param container - Data container to process * @param attributesToProcess - Set of attribute keys to process */ addQueryAndResolvedReferencesPartial(container: DataContainer, attributesToProcess: Set): void; /** * Creates an expanded context object for expression evaluation * Resolves references so expressions can access nested properties like productRef.baseCost */ private createExpressionContext; /** * Helper to recursively expand nested references (up to one level deep to avoid infinite recursion) */ private createNestedContext; /** * Processes only specific derived/grouped references and derived/expression properties (Step 3) * @param container - Data container to process * @param attributesToProcess - Set of attribute keys to process */ addDerivedAndExpressionAttributesPartial(container: DataContainer, attributesToProcess: Set): void; /** * Re-runs only specific derived properties based on resolved references (Step 4) * @param container - Data container to process * @param attributesToProcess - Set of attribute keys to process */ reRunDerivedPropertiesBasedOnResolvesPartial(container: DataContainer, attributesToProcess: Set): void; }