This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Workers KV API endpoints. Signed-off-by: Terin Stock <terin@cloudflare.com>
- Loading branch information
1 parent
fbce975
commit f3a9131
Showing
4 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (C) 2014-present Cloudflare, Inc. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const prototypal = require('es-class'); | ||
const auto = require('autocreate'); | ||
|
||
const Resource = require('../Resource'); | ||
const method = require('../method'); | ||
|
||
/** | ||
* EnterpriseZoneWorkersKV represents the accounts/:accountId/storage/kv/namespaces API endpoint. | ||
* | ||
* @class EnterpriseZoneWorkersKV | ||
* @hideconstructor | ||
* @extends Resource | ||
*/ | ||
module.exports = auto( | ||
prototypal({ | ||
extends: Resource, | ||
path: 'accounts/:accountId/storage/kv/namespaces/:namespaceId', | ||
|
||
/** | ||
* browse allows for listing all the keys of a namespace | ||
* | ||
* @function browse | ||
* @memberof EnterpriseZoneWorkersKV | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} namespace_id - The namespace ID | ||
* @returns {Promise<Object>} The KV response object. | ||
*/ | ||
browse: method({ | ||
method: 'GET', | ||
path: 'keys', | ||
}), | ||
/** | ||
* add allows for creating a key-value pair in a namespace | ||
* | ||
* @function add | ||
* @memberof EnterpriseZoneWorkersKV | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} namespace_id - The namespace ID | ||
* @param {string} value - The value to store | ||
* @returns {Promise<Object>} The KV response object | ||
*/ | ||
add: method({ | ||
method: 'PUT', | ||
path: 'values/:id', | ||
}), | ||
/** | ||
* read allows for reading the contents of key in a namespace | ||
* | ||
* @function read | ||
* @memberof EnterpriseZoneWorkersKV | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} namespace_id - The namespace ID | ||
* @param {string} key_name - The key name | ||
* @returns {Promise<Object>} The KV response object | ||
*/ | ||
read: method({ | ||
method: 'GET', | ||
path: 'values/:id', | ||
json: false, | ||
contentType: 'text/plain', | ||
}), | ||
/** | ||
* del allows for deleting a key and its contents in a namespace | ||
* | ||
* @function del | ||
* @memberof EnterpriseZoneWorkersKV | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} namespace_id - The namespace ID | ||
* @param {string} key_name - The key name | ||
* @returns {Promise<Object>} The KV response object | ||
*/ | ||
del: method({ | ||
method: 'DELETE', | ||
path: 'values/:id', | ||
}), | ||
/** | ||
* addMulti allows for creating multiple key-value pairs in a namespace | ||
* | ||
* @function addMulti | ||
* @memberof EnterpriseZoneWorkersKV | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} namespace_id - The namespace ID | ||
* @param {Array<Object>} data - An array containing key-vaue pair Objects to add | ||
* @returns {Promise<Object>} The KV response object | ||
*/ | ||
addMulti: method({ | ||
method: 'PUT', | ||
path: 'bulk', | ||
}), | ||
/** | ||
* delMulti allows for deleting multiple key-value pairs in a namespace | ||
* | ||
* @function delMulti | ||
* @memberof EnterpriseZoneWorkersKV | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} namespace_id - The namespace ID | ||
* @param {Array<String>} data - The array with keys to delete | ||
* @returns {Promise<Object>} The KV response object | ||
*/ | ||
delMulti: method({ | ||
method: 'DELETE', | ||
path: 'bulk', | ||
}), | ||
}) | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2014-present Cloudflare, Inc. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const prototypal = require('es-class'); | ||
const auto = require('autocreate'); | ||
|
||
const Resource = require('../Resource'); | ||
const method = require('../method'); | ||
|
||
/** | ||
* EnterpriseZoneWorkersKVNamespaces represents the accounts/:accountId/storage/kv/namespaces API endpoint. | ||
* | ||
* @class EnterpriseZoneWorkersKVNamespaces | ||
* @hideconstructor | ||
* @extends Resource | ||
*/ | ||
module.exports = auto( | ||
prototypal({ | ||
extends: Resource, | ||
path: 'accounts/:accountId/storage/kv/namespaces', | ||
|
||
includeBasic: ['browse', 'add', 'del'], | ||
|
||
/** | ||
* browse allows for listing all of a zone's workers namespaces | ||
* | ||
* @function browse | ||
* @memberof EnterpriseZoneWorkersKVNamespaces | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @returns {Promise<Object>} The namespace response object. | ||
*/ | ||
/** | ||
* add allows for creating a workers namespace | ||
* | ||
* @function add | ||
* @memberof EnterpriseZoneWorkersKVNamespaces | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {Object} config - The namespace object | ||
* @returns {Promise<Object>} The namespace response object. | ||
*/ | ||
/** | ||
* del allows for deleting a workers namespace | ||
* | ||
* @function del | ||
* @memberof EnterpriseZoneWorkersKVNamespaces | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} id - The namespace id | ||
* @returns {Promise<Object>} The namespace response object. | ||
*/ | ||
/** | ||
* edit allows for renaming a workers namespace | ||
* | ||
* @function edit | ||
* @memberof EnterpriseZoneWorkersKVNamespaces | ||
* @instance | ||
* @async | ||
* @param {string} account_id - The account ID | ||
* @param {string} id - The namespace id | ||
* @param {Object} config - The namespace object | ||
* @returns {Promise<Object>} The namespace response object. | ||
*/ | ||
edit: method({ | ||
method: 'PUT', | ||
path: ':id', | ||
}), | ||
}) | ||
); |