/** * 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 { CollectionDefinition, IDbAdapter } from '../@types/index.js'; import type { BylineLogger } from '../lib/logger.js'; /** * Snapshot of a collection's current registration: the DB row id, the * schema version stamped on new `documentVersions` rows, and the fingerprint * that was recorded the last time the bootstrap ran. Cached on the core * instance for the lifetime of the process. */ export interface CollectionRecord { collectionId: string; version: number; schemaHash: string; } export interface EnsureCollectionsInput { definitions: readonly CollectionDefinition[]; db: IDbAdapter; logger?: BylineLogger; } /** * Reconcile every registered `CollectionDefinition` with its row in the * `collections` table. Runs once at startup from `initBylineCore()`. * * Behaviour per collection: * 1. Compute the data-shape fingerprint. * 2. If no row exists: insert with `version = definition.version ?? 1` * and the fingerprint. * 3. If a row exists and the fingerprint matches: no-op. * 4. If a row exists and the fingerprint differs: * - `definition.version` pinned explicitly and `> stored.version` → use it * - `definition.version` pinned explicitly and `<= stored.version` → throw * - otherwise → auto-bump to `stored.version + 1` * Then write back `{ config, version, schema_hash, updated_at }`. * * Returns a `Map` to be cached on the core instance * so downstream callers (lifecycle, upload, client handle) can resolve * `(collectionId, collectionVersion)` without another DB round-trip. */ export declare function ensureCollections({ definitions, db, logger, }: EnsureCollectionsInput): Promise>;