/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ import { type FieldSet } from '../@types/index.js'; import type { ICounterCommands } from '../@types/db-types.js'; export interface AssignCounterValuesInput { fields: FieldSet; /** * The document data being written. Mutated in place — counter sites * are overwritten with allocator-assigned values (on create / when * no previous value exists) or with the previous version's value * (on update). Caller-supplied counter values are NOT trusted, even * on create: they are always replaced by `nextCounterValue` or by * the previous version's value. */ data: Record; /** * Reconstructed fields from the previous version (update path only). * * When provided, counter values are copied forward from here rather * than re-allocated — counter fields are immutable across versions * of the same document. If the previous version is missing a value * for a counter (e.g. the field was added to the collection after * the document was created), a new value is allocated lazily so * subsequent updates always see a populated counter. * * When omitted (create / duplicate / restore-as-new), every counter * site is freshly allocated. */ previousData?: Record; counters: ICounterCommands; } /** * Populate every counter field in `data` with its canonical value * before the document is flattened and persisted. Called by the * lifecycle layer immediately before `db.commands.documents * .createDocumentVersion` so the values land in `store_numeric` on * the same write. * * Behaviour by lifecycle path: * * - create: `previousData` is undefined → every counter field is * freshly allocated, any caller-supplied value is * overwritten. * * - update: `previousData` is the prior version's reconstructed * fields → counter values are copied forward. Lazy * backfill fires for any counter the prior version is * missing (e.g. field added post-hoc). * * - duplicate: caller strips counter values from the cloned source * before invoking the create path → fresh allocation * applies. (The strip itself is enforced by passing * `previousData: undefined`; even if the clone retains * the source's value, the create path overwrites it.) */ export declare function assignCounterValues({ fields, data, previousData, counters, }: AssignCounterValuesInput): Promise;