UNPKG

@dataql/react-native

Version:

DataQL React Native SDK with offline-first capabilities and clean API

157 lines (139 loc) 4.37 kB
export interface SyncStatus { isOnline: boolean; lastSyncTime: Date | null; pendingOperations: number; failedOperations: number; syncInProgress: boolean; syncError?: string; } export interface OfflineOperation { id: string; type: "create" | "update" | "upsert" | "delete"; tableName: string; data: any; timestamp: Date; status: "pending" | "syncing" | "synced" | "failed"; retryCount: number; error?: string; } // Custom request connection interface for routing DataQL requests through other SDKs export interface CustomRequestConnection { /** * Custom request method that will be used instead of fetch * @param url The target URL for the request * @param options Request options including method, headers, body * @returns Promise that resolves to a Response-like object */ request(url: string, options: RequestInit): Promise<Response>; } // Legacy workerBinding interface for backward compatibility export interface WorkerBinding { fetch(request: Request): Promise<Response>; } // Internal connection interface for direct database access export interface InternalConnectionConfig { privateToken: string; appName: string; databaseName: string; mongodbUrl: string; /** Internal connection timeout in milliseconds */ timeout?: number; /** Internal retry configuration */ retryConfig?: { maxRetries?: number; retryDelay?: number; }; } // Connection options - can use either new custom connection or legacy workerBinding export interface ConnectionOptions { // New custom connection interface customConnection?: CustomRequestConnection; // Legacy workerBinding for backward compatibility workerBinding?: WorkerBinding; } export interface SyncConfig { serverUrl?: string; // Make serverUrl optional for backward compatibility syncInterval?: number; // milliseconds retryCount?: number; batchSize?: number; autoSync?: boolean; // Network transport options customConnection?: CustomRequestConnection; workerBinding?: WorkerBinding; internalConnection?: InternalConnectionConfig; } // User-facing database configuration (simplified) export interface DatabaseConfig { /** Database name (required - each client gets their own database) */ name: string; /** Database connection URL (optional - uses main database URL if not provided. Database type auto-detected from URL protocol) */ url?: string; } // Internal database configuration (with all options) export interface InternalDatabaseConfig extends Omit<DatabaseConfig, "url"> { /** Database connection URL (required for internal use) */ url: string; /** Internal connection pool settings */ pool?: { min?: number; max?: number; acquireTimeoutMillis?: number; idleTimeoutMillis?: number; }; /** Internal SSL/TLS configuration */ ssl?: | boolean | { rejectUnauthorized?: boolean; ca?: string; cert?: string; key?: string; }; /** Internal timeout configuration */ timeout?: number; /** Internal retry configuration */ retryConfig?: { maxRetries?: number; retryDelay?: number; }; } export interface DataQLReactNativeConfig { // Core configuration schemas: Record<string, any>; // Schema definitions for tables appToken?: string; // Optional app token for authentication // Database configuration databaseName?: string; // Optional database name (defaults to a generated name) database?: DatabaseConfig; // Direct database connection configuration // Sync configuration syncConfig?: SyncConfig; // Optional configurations enableChangeListener?: boolean; debug?: boolean; env?: "development" | "staging" | "production" | "dev" | "prod"; // Support both new and legacy environment names devPrefix?: string; internalConnection?: InternalConnectionConfig; } export interface QueryResult<T = any> { data: T[]; error?: string; isFromCache: boolean; lastUpdated?: Date; } export interface MutationResult { success: boolean; data?: any; error?: string; offlineId?: string; isCreate?: boolean; // For upsert operations to indicate if record was created or updated } export type SyncEventType = | "sync_start" | "sync_complete" | "sync_error" | "operation_synced"; export interface SyncEvent { type: SyncEventType; timestamp: Date; data?: any; error?: string; }