Bindra API Reference
Complete API documentation for Bindra v2.0.
Core Classes
- DataSource - Main reactive data management class
- Container - Dependency injection container for DataSources
- Validator - Validation system for data integrity
Utilities
- Performance - debounce, throttle, and timing utilities
- Observable - Reactive primitives (signals, reactive objects)
- EventEmitter - Event system for lifecycle hooks
Type Definitions
- Types - TypeScript interfaces and type definitions
- Configuration - Configuration options for all features
Quick Links
DataSource API
typescript
class DataSource<T> {
// Properties
data: T[] | null
current: T | null
loading: boolean
currentPage: number
hasMore: boolean
// CRUD Operations
fetch(query?: QueryOptions): Promise<T[]>
create(record: Partial<T>): Promise<T>
update(id: number, changes: Partial<T>): Promise<T>
delete(id: number): Promise<void>
// Batch Operations
createBatch(records: Partial<T>[]): Promise<T[]>
updateBatch(updates: BatchUpdate<T>[]): Promise<T[]>
deleteBatch(ids: number[]): Promise<void>
// Pagination
fetchMore(): Promise<T[]>
fetchPage(page: number): Promise<T[]>
// Navigation
next(): void
prev(): void
goto(index: number): void
findById(id: number): T | undefined
// Caching
clearCache(): void
invalidateCache(key?: string): void
// WebSocket
connectWebSocket(): void
disconnectWebSocket(): void
sendWebSocketMessage(data: any): void
// Events
on(event: string, handler: Function): void
off(event: string, handler?: Function): void
emit(event: string, data?: any): void
}Container API
typescript
class Container {
register<T>(name: string, dataSource: DataSource<T>): Promise<void>
get<T>(name: string): Promise<DataSource<T>>
has(name: string): boolean
unregister(name: string): Promise<void>
list(): string[]
clear(): Promise<void>
getStatus(name: string): 'initializing' | 'ready' | 'not-found'
}Validator API
typescript
class Validator<T> {
addRule(field: keyof T, rule: ValidationRule): void
validate(data: Partial<T>): ValidationResult
validateField(field: keyof T, value: any): ValidationError[]
}Configuration Examples
Full DataSource Configuration
typescript
const dataSource = new DataSource<User>({
// Data mode
data: [], // Local data
url: 'https://api.example.com/users', // Remote API
// Pagination
pagination: {
enabled: true,
pageSize: 20,
strategy: 'offset' | 'cursor',
cursorField: 'id'
},
// Caching
cache: {
enabled: true,
ttl: 300000 // 5 minutes
},
// Real-time
realtime: {
enabled: true,
url: 'wss://api.example.com/ws',
reconnect: true,
reconnectInterval: 5000
},
// Security
security: {
csrfToken: 'token',
csrfHeader: 'X-CSRF-Token',
sanitizeFields: ['name', 'bio']
},
// Validation
validation: {
name: [
{ type: 'required', message: 'Required' },
{ type: 'minLength', value: 3 }
]
},
// Features
optimisticUpdates: true,
retryAttempts: 3,
retryDelay: 1000
});Events
CRUD Events
created- Record createdupdated- Record updateddeleted- Record deletedfetched- Data fetchederror- Error occurred
Real-time Events
ws:connected- WebSocket connectedws:disconnected- WebSocket disconnectedws:error- WebSocket errorrealtime:message- Custom WebSocket message
Navigation Events
currentChanged- Current record changed