rezilient.js
Version:
Rezilient.js - Revolutionary offline-first framework with AI-awareness, principle-driven development, carbon-conscious computing, and self-healing capabilities
219 lines (186 loc) • 6.12 kB
TypeScript
// TypeScript definitions for Rezilient.js Framework
// Generated for version 2.1.0
declare module 'rezilient.js' {
// Core Store Types
export interface StoreState {
[key: string]: any;
}
export type StoreSubscriber<T = StoreState> = (state: T) => void;
export type StoreUpdater<T = StoreState> = (state: T) => T;
// Main Rezilient Store (Primary Interface)
export class RezilientStore<T = StoreState> {
constructor(initialState: T);
get(): T;
set(newState: T): void;
update(updater: StoreUpdater<T>): void;
subscribe(subscriber: StoreSubscriber<T>): () => void;
unsubscribe(subscriber: StoreSubscriber<T>): void;
reset(): void;
}
// Legacy/Internal Aliases (for backward compatibility)
export const AetherStore: typeof RezilientStore;
export const RezStore: typeof RezilientStore;
// Persistent Store
export class RezilientPersistentStore<T = StoreState> extends RezilientStore<T> {
constructor(key: string, initialState: T);
initialize(): Promise<void>;
clear(): Promise<void>;
}
// Legacy/Internal Aliases
export const PersistentStore: typeof RezilientPersistentStore;
export const RezPersistentStore: typeof RezilientPersistentStore;
// Component Types
export interface ComponentOptions {
syncOnOnline?: boolean;
trackSyncState?: boolean;
}
export class RezilientComponent {
isOnline: boolean;
syncEngine: SyncEngine | null;
syncState: any;
eventListeners: Array<{
element: EventTarget;
event: string;
handler: EventListener;
}>;
constructor(options?: ComponentOptions);
initialize(): void;
onMount(): void;
onUnmount(): void;
onOnline(): void;
onOffline(): void;
onSyncStateChange(state: any): void;
setupSyncEngine(syncEngine: SyncEngine): void;
cleanup(): void;
}
// Legacy/Internal Aliases
export const AetherComponent: typeof RezilientComponent;
export const RezComponent: typeof RezilientComponent;
// Sync Engine Types
export interface SyncOptions {
endpoint?: string;
retryAttempts?: number;
retryDelay?: number;
conflictStrategy?: 'LastWriteWins' | 'ServerWins' | ConflictResolver;
carbonAware?: boolean;
batchSize?: number;
timeout?: number;
}
export interface Mutation {
id?: string;
type: string;
payload: any;
timestamp?: number;
retryCount?: number;
}
export type ConflictResolver = (localMutation: Mutation, serverState: any) => Mutation | null;
export class SyncEngine {
isOnline: boolean;
isSyncing: boolean;
retryAttempts: number;
retryDelay: number;
conflictStrategy: string | ConflictResolver;
constructor(options?: SyncOptions);
addMutation(mutation: Mutation): Promise<void>;
processQueue(): Promise<void>;
getQueue(): Promise<Mutation[]>;
clearQueue(): Promise<void>;
syncMutation(mutation: Mutation): Promise<any>;
addEventListener(event: string, listener: EventListener): () => void;
removeEventListener(event: string, listener: EventListener): void;
}
// Carbon Aware Scheduler
export interface SchedulerOptions {
carbonPriority?: 'low' | 'normal' | 'high';
maxDelay?: number;
}
export class CarbonAwareScheduler {
constructor();
schedule(taskId: string, task: () => void, options?: SchedulerOptions): void;
isOptimalTime(): boolean;
getCarbonFootprint(): number;
getOptimalTimes(): Date[];
}
// React Hooks
export function useRezilientStore<T = StoreState>(store: RezilientStore<T>): [T, (newState: T) => void];
export function useRezStore<T = StoreState>(store: RezilientStore<T>): [T, (newState: T) => void];
export function useAetherStore<T = StoreState>(store: RezilientStore<T>): [T, (newState: T) => void];
export function useSyncEngine(options?: SyncOptions): SyncEngine;
export function usePersistentStore<T = StoreState>(
key: string,
initialState: T
): { value: T; setValue: (newValue: T) => void };
export function useRezilientPersistentStore<T = StoreState>(
key: string,
initialState: T
): { value: T; setValue: (newValue: T) => void };
export function useRezPersistentStore<T = StoreState>(
key: string,
initialState: T
): { value: T; setValue: (newValue: T) => void };
export function useNetworkState(): {
isOnline: boolean;
isOffline: boolean;
};
// Revolutionary Features
export interface PrincipleOptions {
sustainability?: boolean;
accessibility?: 'A' | 'AA' | 'AAA';
inclusivity?: boolean;
privacy?: 'basic' | 'strict';
}
export class AetherPrinciples {
constructor(options?: PrincipleOptions);
validate(component: any): { passed: boolean; violations: string[] };
enforce(component: any): void;
}
// AI Aware Features
export interface AIOptions {
biasDetection?: boolean;
ethicalConstraints?: boolean;
fairnessMetrics?: string[];
}
export class AetherAIAware {
constructor(options?: AIOptions);
predict(data: any): Promise<any>;
getBiasReport(): any;
detectBias(data: any): boolean;
}
// Environment Detection
export class EnvironmentDetector {
isNode(): boolean;
isBrowser(): boolean;
isProduction(): boolean;
hasLocalStorage(): boolean;
hasIndexedDB(): boolean;
getEnvironmentInfo(): {
platform: string;
runtime: string;
features: string[];
};
}
// Utility Types
export interface FrameworkConfig {
environment?: 'development' | 'production';
carbonAware?: boolean;
biasDetection?: boolean;
offlineFirst?: boolean;
accessibility?: 'A' | 'AA' | 'AAA';
performance?: 'standard' | 'optimized';
logging?: 'verbose' | 'normal' | 'error' | 'silent';
}
export function configure(config: FrameworkConfig): void;
// Constants
export const SYNC_EVENTS: {
STATUS_CHANGE: string;
PROGRESS_UPDATE: string;
SYNC_ERROR: string;
MUTATION_SYNCED: string;
};
export const SYNC_STATUS: {
IDLE: string;
SYNCING: string;
ERROR: string;
OFFLINE: string;
};
}