wirekvs-js/src/index.d.ts
2025-05-10 15:18:40 +02:00

75 lines
No EOL
1.9 KiB
TypeScript

import { EventEmitter } from 'events';
import { AxiosResponse } from 'axios';
export interface DatabaseConfig {
name: string;
allowPublicWrites?: boolean;
allowPublicReads?: boolean;
allowPublicModifications?: boolean;
allowSpecificPublicReads?: boolean;
}
export interface WebSocketMessage {
type: string;
message?: string;
[key: string]: any;
}
export interface DatabaseEntry {
key: string;
value: any;
}
export interface SearchQuery {
[key: string]: any;
}
export interface DatabaseInfo {
id: string;
name: string;
allowPublicWrites: boolean;
allowPublicReads: boolean;
allowPublicModifications: boolean;
allowSpecificPublicReads: boolean;
}
export class WireKVSDatabase extends EventEmitter {
constructor(id: string, accessKey: string);
id: string;
accessKey: string;
ws: WebSocket | null;
isConnected: boolean;
on(event: 'connected' | 'disconnected' | 'error', listener: (...args: any[]) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
off(event: string, handler?: (...args: any[]) => void): this;
disconnect(): void;
getAllEntries(): Promise<DatabaseEntry[]>;
get(key: string): Promise<string>;
json<T extends object>(key: string): Promise<T>;
set(key: string, value: any): Promise<void>;
update(key: string, value: any): Promise<void>;
delete(key: string): Promise<void>;
search(query: SearchQuery): Promise<DatabaseEntry[]>;
}
export class WireKVS {
constructor(token: string);
token: string;
static connect(id: string, accessKey: string): WireKVSDatabase;
listDatabases(): Promise<DatabaseInfo[]>;
createDatabase(config: DatabaseConfig): Promise<DatabaseInfo>;
updateDatabase(id: string, config: Partial<DatabaseConfig>): Promise<DatabaseInfo>;
deleteDatabase(id: string): Promise<void>;
truncateDatabase(id: string): Promise<void>;
database(id: string, accessKey: string): WireKVSDatabase;
}
export default WireKVS;