feat: json
This commit is contained in:
parent
29b6801e53
commit
1946eabe31
2 changed files with 12 additions and 1 deletions
3
src/index.d.ts
vendored
3
src/index.d.ts
vendored
|
@ -49,7 +49,8 @@ export class WireKVSDatabase extends EventEmitter {
|
||||||
disconnect(): void;
|
disconnect(): void;
|
||||||
|
|
||||||
getAllEntries(): Promise<DatabaseEntry[]>;
|
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>;
|
set(key: string, value: any): Promise<void>;
|
||||||
update(key: string, value: any): Promise<void>;
|
update(key: string, value: any): Promise<void>;
|
||||||
delete(key: string): Promise<void>;
|
delete(key: string): Promise<void>;
|
||||||
|
|
10
src/index.js
10
src/index.js
|
@ -130,6 +130,16 @@ class WireKVSDatabase extends EventEmitter {
|
||||||
return response.data;
|
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) {
|
async set(key, value) {
|
||||||
await axios.post(`${API_BASE_URL}/database/${this.id}/${key}`, value, {
|
await axios.post(`${API_BASE_URL}/database/${this.id}/${key}`, value, {
|
||||||
headers: { Authorization: this.accessKey },
|
headers: { Authorization: this.accessKey },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue