-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkv.js
More file actions
48 lines (42 loc) · 1.13 KB
/
kv.js
File metadata and controls
48 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
export class KV {
/**
*
* @param {*} kv cloudflare KV binding
*/
constructor(kv) {
this.kv = kv
}
async putJSON(key, value, options = {}) {
return await this.kv.put(key, JSON.stringify(value), options)
}
async getJSON(key, options = {}) {
let r = await this.kv.get(key, options)
if (r) r = JSON.parse(r)
return r
}
async get(key, options = {}) {
return await this.kv.get(key, options)
}
async getWithMetadata(key, options = {}) {
return await this.kv.getWithMetadata(key, options)
}
/**
*
* @param {string} key key string
* @param {string|ReadableStream|ArrayBuffer} value value string
* @param {object} [options]
* @param {string} [options.expiration] when to expire in seconds since epoch
* @param {string} [options.expirationTtl] Ttl in seconds.
* @param {object} [options.metadata] metadata object to store with the value.
* @returns
*/
async put(key, value, options = {}) {
return await this.kv.put(key, value)
}
async delete(key) {
return await this.kv.delete(key)
}
async list(options = {}) {
return await this.kv.list(options)
}
}