import { Draft } from 'immer'; import { DataSourceListener, IDataSourceValidator, IDataSource, DataSourceOptions, FilterFn } from '../ArchbaseDataSource'; /** * Estados possíveis do DataSource */ type DataSourceState = 'browse' | 'edit' | 'insert'; /** * Configuração para ArchbaseDataSourceV2 */ export interface ArchbaseDataSourceV2Config { name: string; label?: string; records?: T[]; validator?: IDataSourceValidator; onStateChange?: (prevRecords: T[], newRecords: T[]) => void; onFieldError?: (fieldName: string, error: string) => void; onError?: (error: string, originalError?: any) => void; } /** * ArchbaseDataSourceV2 - Versão V2 com Immer * * Esta implementação: * - Garante imutabilidade completa com Immer * - Interface simplificada focada em funcionalidade V2 * - Suporte a operações em arrays com type safety * - Event system compatível com V1 */ export declare class ArchbaseDataSourceV2 implements IDataSource { private name; private label; private records; private currentIndex; private state; private listeners; private originalRecord; private validator?; private lastDataChangedAt; private active; private onStateChange?; private onFieldError?; private onError?; constructor(config: ArchbaseDataSourceV2Config); getName(): string; getLabel(): string; isActive(): boolean; close(): void; getCurrentRecord(): T | undefined; getCurrentIndex(): number; getTotalRecords(): number; isEmpty(): boolean; first(): this; last(): this; next(): this; prior(): this; goToRecord(index: number): T | undefined; isFirst(): boolean; isLast(): boolean; isBOF(): boolean; isEOF(): boolean; isBrowsing(): boolean; isEditing(): boolean; isInserting(): boolean; edit(): this; cancel(): this; insert(record: T): this; save(callback?: Function): Promise; remove(callback?: Function): Promise; setFieldValue(fieldName: string, value: any): this; getFieldValue(fieldName: string): any; appendToFieldArray(fieldName: K, item: T[K] extends Array ? U : never): void; updateFieldArrayItem(fieldName: K, index: number, updater: (draft: T[K] extends Array ? Draft : never) => void): void; removeFromFieldArray(fieldName: K, index: number): void; insertIntoFieldArray(fieldName: K, index: number, item: T[K] extends Array ? U : never): void; getFieldArray(fieldName: K): T[K] extends Array ? U[] : never; isFieldArray(fieldName: K): boolean; /** * Abre o DataSource com os dados fornecidos. * Aceita tanto o formato completo DataSourceOptions quanto um formato simplificado { records: T[] } */ open(options: DataSourceOptions | { records: T[]; }): void; clear(): void; /** * Define os dados do DataSource. * Quando apenas records é informado, os valores de paginação são derivados automaticamente. */ setData(options: DataSourceOptions | { records: T[]; }): void; getOptions(): DataSourceOptions; refreshData(options?: DataSourceOptions): void; browseRecords(): T[]; getGrandTotalRecords(): number; getCurrentPage(): number; getTotalPages(): number; isEmptyField(fieldName: string): boolean; goToPage(pageNumber: number): this; gotoRecordByData(record: T): boolean; disabledAllListeners(): this; enableAllListeners(): this; addFieldChangeListener(fieldName: string, listener: (fieldName: string, oldValue: any, newValue: any) => void): this; removeFieldChangeListener(fieldName: string, listener: (fieldName: string, oldValue: any, newValue: any) => void): this; addFilter(filterFn: FilterFn): this; removeFilter(filterFn: FilterFn): this; clearFilters(): this; locate(values: any): boolean; locateByFilter(filterFn: (record: T) => boolean): boolean; validate(): boolean; addListener(...listeners: DataSourceListener[]): this; removeListener(...listeners: DataSourceListener[]): this; private emit; getRecords(): T[]; setRecords(records: T[]): void; getDebugSnapshot(): { name: string; recordCount: number; currentIndex: number; currentRecord: T; state: DataSourceState; listeners: number; }; private validateDataSourceActive; private notifyStateChange; private setNestedValue; private getNestedValue; } export {};