feat: json

This commit is contained in:
Waradu 2025-05-10 15:18:40 +02:00
parent 29b6801e53
commit 1946eabe31
No known key found for this signature in database
GPG key ID: F85AAC8BA8B8DAAD
2 changed files with 12 additions and 1 deletions

3
src/index.d.ts vendored
View file

@ -49,7 +49,8 @@ export class WireKVSDatabase extends EventEmitter {
disconnect(): void;
getAllEntries(): Promise<DatabaseEntry[]>;
get(key: string): Promise<any>;
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>;

View file

@ -130,6 +130,16 @@ class WireKVSDatabase extends EventEmitter {
return response.data;
}
async json(key) {
const response = await axios.get(
`${API_BASE_URL}/database/${this.id}/${key}`,
{
headers: { Authorization: this.accessKey },
}
);
return JSON.parse(response.data);
}
async set(key, value) {
await axios.post(`${API_BASE_URL}/database/${this.id}/${key}`, value, {
headers: { Authorization: this.accessKey },