@dataql/react-native
Version:
DataQL React Native SDK with offline-first capabilities and clean API
76 lines (75 loc) • 2.08 kB
TypeScript
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;
}
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>;
}
export interface WorkerBinding {
fetch(request: Request): Promise<Response>;
}
export interface ConnectionOptions {
customConnection?: CustomRequestConnection;
workerBinding?: WorkerBinding;
workerUrl?: string;
}
export interface SyncConfig {
serverUrl?: string;
workerUrl?: string;
syncInterval?: number;
retryCount?: number;
batchSize?: number;
autoSync?: boolean;
customConnection?: CustomRequestConnection;
workerBinding?: WorkerBinding;
}
export interface DataQLReactNativeConfig {
schemas: Record<string, any>;
appToken?: string;
databaseName?: string;
syncConfig?: SyncConfig;
enableChangeListener?: boolean;
debug?: boolean;
env?: "dev" | "prod";
devPrefix?: string;
}
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;
}
export type SyncEventType = "sync_start" | "sync_complete" | "sync_error" | "operation_synced";
export interface SyncEvent {
type: SyncEventType;
timestamp: Date;
data?: any;
error?: string;
}