/** * 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/field-types.js'; import type { BylineLogger } from '../lib/logger.js'; export interface DocumentFieldIssue { field: string; message: string; /** * `required` marks a value that is absent but declared non-optional — the * shape schema tightening produces. Every other failure, including a custom * `validate` callback's message, is `invalid`: it describes a value that is * present and wrong, or a container that cannot be stored. Nothing branches * on this to decide whether a write proceeds; it exists so callers can tell * an editor what is missing separately from what is wrong. */ kind: 'required' | 'invalid'; } export interface DocumentFieldValidationDetails { reason: 'invalid_document_fields'; issues: DocumentFieldIssue[]; } type CallbackSite = 'validate' | 'condition' | 'schema'; /** * Validate schema data without transforming or stripping persistence values. * * Never throws. Three things here run schema-author code and can fail on data * they did not anticipate: `validate`, `condition`, and the per-field Zod * schema, whose `validation.rules` may carry a throwing `custom` predicate or a * malformed `pattern` that fails while the schema is being built. A validator * calling `value.trim()` meets a historical version that lacks the field. A raw * exception would abort the walk, discarding the issues already collected, and * escape as an unhandled error rather than a field result. * * Each site is therefore isolated and a failure recorded as an `invalid` issue, * so an ordinary save still refuses the write, and a caller using this for * diagnostics only — restore — is never blocked by it. The editor-facing * message is fixed; the exception goes to `onCallbackError`. */ export declare function validateDocumentFields(fields: FieldSet, data: Record, options?: { locale?: string; /** Browser-only presentation precheck; the lifecycle never exempts hidden fields. */ respectConditions?: boolean; /** Pending uploads are validated after transport by the lifecycle. */ skip?: (path: string) => boolean; /** * Receives the real exception when a schema-author callback throws, for * server-side diagnostics. The editor only ever sees `CALLBACK_FAILED`. */ onCallbackError?: (detail: { path: string; site: CallbackSite; error: unknown; }) => void; }): DocumentFieldIssue[]; /** * Enforce the collection's declared field contract over prepared content. * * Every versioned write passes through this except a restore, which is exempt * structurally rather than by a parameter here — see `assertWritableContent` * in the lifecycle's `persistence.ts` for why, and for what that exemption * does and does not promise. */ export declare function assertDocumentFields(fields: FieldSet, data: Record, locale?: string, logger?: Pick): void; /** Accept live errors and serialized reports, discarding all non-contract data. */ export declare function getDocumentFieldValidationDetails(error: unknown): DocumentFieldValidationDetails | null; export {};