/** * 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 { DocumentLifecycleContext } from './context.js'; export interface CopyToLocaleResult { revision: number; documentId: string; documentVersionId: string; /** Source locale read for the copy. */ sourceLocale: string; /** Target locale into which the source's localized leaves were written. */ targetLocale: string; /** * Number of localized field values copied from source to target. Useful * for UI toasts ("Copied 4 fields from EN to FR"). A zero result means * the source had no localized content to copy into the target under the * chosen merge rule (e.g. `overwrite: false` and target was already * fully populated). */ fieldsUpdated: number; } /** * Copy a document's content from one locale into another, in place on * the same document. * * Reads the source and target locales separately (the storage layer * resolves localized fields to flat single-locale shapes when given a * specific `resolveLocale`). A schema-aware merge walker decides, leaf * by leaf, whether to take the source's value or keep the target's, * driven by the `overwrite` flag. The merged tree is written via * `createDocumentVersion({ action: 'copy_to_locale', locale: target })` * — the existing cross-locale carry-forward in the storage primitive * preserves every *other* locale's rows untouched. * * Non-localized fields are never altered by this operation: they live * on `locale: 'all'` rows and the merge walker passes the target's * value through so the write does not blank them. * * Path is sticky and lives on default-locale only; this operation never * touches `byline_document_paths`. Status resets to the workflow * default — translations land as drafts. * * Flow: * 1. `assertActorCanPerform('update')` — same gate as a translation save. * 2. Reject if `sourceLocale === targetLocale`. * 3. Fetch source via `getDocumentById({ locale: sourceLocale })`. * 4. Fetch target via `getDocumentById({ locale: targetLocale })`. * 5. `mergeLocaleData(definition.fields, source.fields, target.fields, overwrite)`. * 6. `hooks.beforeUpdate({ data, originalData, collectionPath, copyToLocale })`. * 7. `createDocumentVersion({ documentId, action: 'copy_to_locale', * locale: targetLocale, documentData, previousVersionId, status })`. * 8. `hooks.afterUpdate({ ..., copyToLocale })`. */ export declare function copyToLocale(ctx: DocumentLifecycleContext, params: { documentId: string; expectedRevision: number; sourceLocale: string; targetLocale: string; overwrite: boolean; }): Promise;