/** * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options */ /** * @module ai/aisdk/validateoperations */ import { type Editor } from "@ckeditor/ckeditor5-core"; import { type Operation } from "@ckeditor/ckeditor5-engine"; /** * A failure found by {@link ~validateOperations} while trial-applying a patch's operations. */ export interface OperationValidationFailure { /** * What kind of failure occurred: `'unsupported'` for an operation the `DocumentCompare` API does not support, * `'invalid'` for one that failed to trial-apply against a copy of the current document. */ reason: string; /** * The operation that failed. */ operation: Operation; /** * The underlying error thrown while trial-applying the operation, set when `reason` is `'invalid'`. */ cause?: Error; } /** * Trial-applies `operations` on temporary copies of the document's roots, to confirm they apply cleanly before they are * applied for real, so an unapplicable set is caught up front instead of failing mid-way, leaving the document corrupt. * * Each root (plus the graveyard, for remove/merge targets) is deep-cloned into a detached * {@link module:engine/model/documentfragment~ModelDocumentFragment}, and every operation is cloned and re-rooted onto * those copies and trial-applied there — `_validate()` then `_execute()`, as the real apply runs them. Marker * operations are skipped: they cannot fail structurally, so there is nothing to validate. Nothing is applied to the * live document. * * The function does not throw errors itself, instead it returns the first failure it finds (or `null` when the * operations all apply cleanly), and leaves it to the caller to throw the appropriate error. * * @returns The first operation failure, or `null` when all operations apply cleanly. */ export declare function validateOperations(editor: Editor, operations: Array): OperationValidationFailure | null;