import type { NexaApp } from '../app/NexaApp'; import type { FieldPath } from '../firestore/FieldPath'; import type { User } from '../auth/authTypes'; export interface NexaConfig { projectId: string; apiKey?: string; endpoint?: string; enablePersistence?: boolean; cacheStrategy?: 'network-first' | 'cache-first'; } export interface AuthResponse { token: string; user: User; expiresIn?: number; } export type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'array-contains-any' | 'in' | 'not-in'; export interface QueryConstraint { type: 'where' | 'orderBy' | 'limit' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore'; fieldPath?: string | FieldPath; opStr?: WhereFilterOp | string; value?: any; directionStr?: 'asc' | 'desc'; limitValue?: number; docSnapshot?: any; cursorValues?: any[]; } export interface SnapshotMetadata { readonly hasPendingWrites: boolean; readonly fromCache: boolean; } export interface DocumentChange { type: 'added' | 'modified' | 'removed'; doc: QueryDocumentSnapshot; oldIndex: number; newIndex: number; } export interface DocumentReference { type: 'document'; path: string; db: NexaApp; patch?: (data: Partial) => Promise; } export interface CollectionReference { type: 'collection'; path: string; db: NexaApp; } export interface Query { type: 'query' | 'collection'; path: string; db: NexaApp; constraints?: QueryConstraint[]; } export interface SnapshotOptions { serverTimestamps?: 'estimate' | 'previous' | 'none'; } export interface DocumentSnapshot { id: string; ref: DocumentReference; metadata: SnapshotMetadata; exists: () => boolean; data: (options?: SnapshotOptions) => T | null; get: (fieldPath: string | FieldPath) => any; } export interface QueryDocumentSnapshot { id: string; ref: DocumentReference; metadata: SnapshotMetadata; exists: () => boolean; data: (options?: SnapshotOptions) => T; get: (fieldPath: string | FieldPath) => any; } export interface QuerySnapshot { docs: QueryDocumentSnapshot[]; forEach: (callback: (doc: QueryDocumentSnapshot) => void) => void; empty: boolean; size: number; metadata: SnapshotMetadata; docChanges: () => DocumentChange[]; } export interface AggregateField { type: 'count' | 'sum' | 'average'; fieldPath?: string | FieldPath; _returnType?: T; } export type AggregateSpec = Record>; export type AggregateSpecData = { [K in keyof T]: T[K] extends AggregateField ? R : number; }; export interface AggregateQuerySnapshot = { count: number; }> { type: 'AggregateQuerySnapshot'; query: Query | CollectionReference; data: () => T; } export interface DatabaseReference { path: string; get: () => Promise; set: (data: any) => Promise; update: (data: any) => Promise; delete?: () => Promise; remove: () => Promise; onDataChanged?: (callback: (data: any) => void) => () => void; onValue?: (callback: (data: any) => void) => () => void; } export interface UploadOptions { contextType?: 'chat' | 'public_post'; contextId?: string; fileId?: string; onProgress?: (percent: number) => void; } export interface StorageReference { path?: string; name?: string; fullPath?: string; upload?: (file: File | Blob, options?: UploadOptions) => Promise<{ url: string; path: string; }>; getDownloadURL?: () => Promise; put?: (file: File | Blob, options?: UploadOptions | ((percent: number) => void), onProgress?: (percent: number) => void) => Promise<{ url: string; success: boolean; fileId?: string; proxyViewUrl?: string; proxyDownloadUrl?: string; metadata?: any; }>; delete?: () => Promise<{ success: boolean; message?: string; }>; } export interface WriteBatch { set: (docRef: DocumentReference, data: any) => WriteBatch; update: (docRef: DocumentReference, data: any) => WriteBatch; patch: (docRef: DocumentReference, data: any) => WriteBatch; delete: (docRef: DocumentReference) => WriteBatch; commit: () => Promise; } export interface OfflineJob { id: string; type: 'set' | 'patch' | 'delete'; path: string; data?: any; idempotencyKey?: string; precondition?: { exists?: boolean; updateTime?: string; }; timestamp?: number; merge?: boolean; state?: 'pending' | 'acknowledged' | 'rejected'; retryCount?: number; leaseOwner?: string; leaseExpiresAt?: number; sequenceNumber?: number; lastError?: string; } export interface Transaction { get: (docRef: DocumentReference) => Promise>; set: (docRef: DocumentReference, data: any) => Transaction; update: (docRef: DocumentReference, data: any) => Transaction; patch: (docRef: DocumentReference, data: any) => Transaction; delete: (docRef: DocumentReference) => Transaction; }