@dataql/react-native
Version:
DataQL React Native SDK with offline-first capabilities and clean API
121 lines (120 loc) • 3.54 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 InternalConnectionConfig {
privateToken: string;
appName: string;
databaseName: string;
mongodbUrl: string;
/** Internal connection timeout in milliseconds */
timeout?: number;
/** Internal retry configuration */
retryConfig?: {
maxRetries?: number;
retryDelay?: number;
};
}
export interface ConnectionOptions {
customConnection?: CustomRequestConnection;
workerBinding?: WorkerBinding;
}
export interface SyncConfig {
serverUrl?: string;
syncInterval?: number;
retryCount?: number;
batchSize?: number;
autoSync?: boolean;
customConnection?: CustomRequestConnection;
workerBinding?: WorkerBinding;
internalConnection?: InternalConnectionConfig;
}
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;
}
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 {
schemas: Record<string, any>;
appToken?: string;
databaseName?: string;
database?: DatabaseConfig;
syncConfig?: SyncConfig;
enableChangeListener?: boolean;
debug?: boolean;
env?: "development" | "staging" | "production" | "dev" | "prod";
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;
}
export type SyncEventType = "sync_start" | "sync_complete" | "sync_error" | "operation_synced";
export interface SyncEvent {
type: SyncEventType;
timestamp: Date;
data?: any;
error?: string;
}