Last active
August 26, 2020 20:49
-
-
Save linux-china/ef7ef71d63dab3bcdc0d771d77fe79b0 to your computer and use it in GitHub Desktop.
CloudFlare KV JavaScript API with jsdoc support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* cloudflare KV Namespace | |
*/ | |
class KVNameSpace { | |
/** | |
* Write key-value pairs | |
* @param {string} key - key | |
* @param {(string|ArrayBuffer|ReadableStream)} value - value | |
* @param {{[expiration]: number, [expirationTtl]: number, [metadata]: {}}} [options] - putting options | |
* @return {Promise} | |
*/ | |
put(key, value, options) { | |
} | |
/** | |
* Read key-value pairs | |
* @param {string} key - key | |
* @param {('text'|'json'|'arrayBuffer'|'stream')} [type] - result type, such as text(default), json, arrayBuffer, stream | |
* @return {Promise<(string|ArrayBuffer|ReadableStream)>} value | |
*/ | |
get(key, type) { | |
} | |
/** | |
* Read key-value pairs with metadata | |
* @param {string} key - key | |
* @return {Promise<ValueWithMetadata>} | |
*/ | |
getWithMetadata(key) { | |
} | |
/** | |
* List keys | |
* @param {{[prefix]: string, [limit]: number, [cursor]: string}} [options] - list options | |
* @return {Promise<ListResult>} | |
*/ | |
list(options) { | |
} | |
/** | |
* Delete key-value pairs | |
* @param {string} key - key | |
* @return {Promise} | |
*/ | |
delete(key) { | |
} | |
} | |
class ListResult { | |
/** | |
* keys | |
* @type {KeyMetadata[]} | |
*/ | |
keys = [] | |
/** | |
* list completed? | |
* @type {boolean} | |
*/ | |
list_complete = true | |
/** | |
* cursor | |
* @type {string} | |
*/ | |
cursor = 'xxx' | |
} | |
class KeyMetadata { | |
/** | |
* key name | |
* @type {string} | |
*/ | |
name = '' | |
/** | |
* absolute expired timestamp | |
* @type {number} | |
*/ | |
expiration = 1000 | |
/** | |
* key metadata | |
* @type {{}} | |
*/ | |
metadata = {} | |
} | |
class ValueWithMetadata { | |
/** | |
* | |
* @type {(string|ArrayBuffer|ReadableStream)} | |
*/ | |
value = '' | |
/** | |
* key metadata | |
* @type {KeyMetadata} | |
*/ | |
metadata = new KeyMetadata() | |
} | |
const KV_MVNSEARCH = new KVNameSpace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment