add types

This commit is contained in:
obvtiger 2025-05-10 14:51:07 +02:00
commit 4a771ae1d4
7 changed files with 1019 additions and 0 deletions

74
src/index.d.ts vendored Normal file
View file

@ -0,0 +1,74 @@
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<any>;
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;