/** * 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 { DocumentPatch } from '../../patches/index.js'; import type { DocumentLifecycleContext } from './context.js'; export interface UpdateDocumentResult { documentId: string; documentVersionId: string; revision: number; } export interface UpdateDocumentWithPatchesResult { documentId: string; documentVersionId: string; revision: number; } /** * Update a document via full replacement (PUT semantics). * * Unlike the previous implementation, this now fetches the current version * from storage to provide a real `originalData` to hooks. * * Flow: * 1. Fetch current document via `getDocumentById({ reconstruct: true })` * 2. Normalize date and numeric fields * 3. `hooks.beforeUpdate({ data, originalData, collectionPath })`, then normalize numerics again * 4. `db.commands.documents.createDocumentVersion(...)` (action = 'update') * 5. `hooks.afterUpdate({ data, originalData, collectionPath, documentId, documentVersionId })` */ type UpdateDocumentParams = { documentId: string; expectedRevision: number; data: Record; locale?: string; /** * Explicit path override. When omitted, the previous version's path * carries forward unchanged (sticky). The lifecycle never re-derives * `path` from the source field on update — that is an explicit user * action driven by the admin path widget. */ path?: string; /** * The editorial advertised-locale set. `undefined` leaves the existing * set untouched (sticky — document-grain, like `path`); an explicit array * (empty included) replaces it wholesale. Driven by the admin * available-locales sidebar widget. See docs/08-internationalization/index.md. */ availableLocales?: string[]; }; export declare function updateDocument(ctx: DocumentLifecycleContext, params: UpdateDocumentParams): Promise; /** Maintenance-only replacement; status is derived from the guarded observation. */ export declare function replaceDocumentFieldsPreservingStatus(ctx: DocumentLifecycleContext, params: Pick): Promise; /** * Update a document via patch application. * * Flow: * 1. Fetch current document via `getDocumentById({ reconstruct: true })` * 2. Validate the observed document revision before preparation * 3. `applyPatches(definition, originalData, patches)` → `nextData` * 4. Normalize date and numeric fields * 5. `hooks.beforeUpdate({ data: nextData, originalData, collectionPath })`, then normalize numerics again * 6. `db.commands.documents.createDocumentVersion(...)` (action = 'update') * 7. `hooks.afterUpdate({ data: nextData, originalData, collectionPath, documentId, documentVersionId })` * * @throws {BylineError} ERR_DOCUMENT_STALE if the observed revision is stale. * @throws {BylineError} ERR_PATCH_FAILED if `applyPatches` fails. */ export declare function updateDocumentWithPatches(ctx: DocumentLifecycleContext, params: { documentId: string; expectedRevision: number; patches: DocumentPatch[]; locale?: string; /** * Explicit path override (typically supplied alongside patches when * the admin path widget has been edited). When omitted, sticky from * the previous version. */ path?: string; /** * The editorial advertised-locale set (typically supplied alongside * patches when the admin available-locales widget has been edited). * `undefined` leaves the existing set untouched (sticky); an explicit * array replaces it wholesale. See docs/08-internationalization/index.md. */ availableLocales?: string[]; }): Promise; /** Combined patch/content and optional metadata save, with one guarded commit. */ export declare function saveDocument(ctx: DocumentLifecycleContext, params: Parameters[1]): Promise; export {};