import type { ADFEntity, ADFEntityMark } from '../types'; export interface MarkValidationResult { errorCode?: ValidationError['code']; message?: string; newMark?: ADFEntityMark; originalMark: ADFEntityMark; valid: boolean; } export interface Output { entity?: ADFEntity; valid: boolean; } export interface NodeValidationResult { entity?: ADFEntity; marksValidationOutput?: MarkValidationResult[]; valid: boolean; } export interface ValidatorContent { allowUnsupportedBlock: boolean; allowUnsupportedInline: boolean; isTupleLike?: boolean; items: Array>; maxItems?: number; minItems?: number; optional?: boolean; type: 'array'; } export type AttributesSpec = { maximum: number; minimum: number; optional?: boolean; type: 'number'; } | { maximum: number; minimum: number; optional?: boolean; type: 'integer'; } | { optional?: boolean; type: 'boolean'; } | { minLength?: number; optional?: boolean; pattern?: RegExp; type: 'string'; validatorFn?: string; } | { optional?: boolean; type: 'enum'; values: Array; } | { optional?: boolean; type: 'object'; } | { isTupleLike?: boolean; items: Array; maxItems?: number; minItems?: number; optional?: boolean; type: 'array'; } | ValidatorSpecAttrs; export interface ValidatorSpecAttrs { optional?: boolean; props: { [key: string]: AttributesSpec; }; } export interface ValidatorSpec { maxItems?: number; minItems?: number; props?: { attrs?: ValidatorSpecAttrs; content?: ValidatorContent; marks?: { items: Array>; maxItems?: number; optional?: boolean; type: 'array'; }; text?: AttributesSpec; type?: { type: 'enum'; values: Array; }; }; required?: Array; } export interface ValidationErrorMap { DEPRECATED: never; INVALID_ATTRIBUTES: { attrs: Array; }; INVALID_CONTENT: { parentType?: string; }; INVALID_CONTENT_LENGTH: { length: number; requiredLength: number; type: RequiredContentLength; }; INVALID_TEXT: never; INVALID_TYPE: never; MISSING_PROPERTIES: { props: Array; }; REDUNDANT_ATTRIBUTES: { attrs: Array; }; REDUNDANT_MARKS: { marks: Array; }; REDUNDANT_PROPERTIES: { props: Array; }; UNSUPPORTED_ATTRIBUTES: { attrs: Array; }; } export type RequiredContentLength = 'minimum' | 'maximum'; export type Content = Array>; export type ValidationErrorType = keyof ValidationErrorMap; export interface ValidationError { code: ValidationErrorType; message: string; meta?: object; } export type ErrorCallback = (entity: ADFEntity, error: ValidationError, options: ErrorCallbackOptions) => ADFEntity | undefined; export type ValidationMode = 'strict' | 'loose'; export interface ValidationOptions { allowPrivateAttributes?: boolean; mode?: ValidationMode; } export interface SpecValidatorResult { hasValidated: boolean; result?: NodeValidationResult; } export type Err = (code: T, msg: string, meta?: T extends keyof ValidationErrorMap ? ValidationErrorMap[T] : never) => NodeValidationResult; export interface ErrorCallbackOptions { allowNestedTables?: boolean; allowUnsupportedBlock?: boolean; allowUnsupportedInline?: boolean; isMark?: any; isNodeAttribute?: boolean; } export type Validate = (entity: ADFEntity, errorCallback?: ErrorCallback, allowed?: Content, parentSpec?: ValidatorSpec) => Output; export type CreateSpecReturn = Record>;