Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Merge branch 'develop' into feature/storage_delete_fix

Ondra Urban4ab1654995f1
diff --cc src/key_value_store.js
index e0d8a3470,43c2e6ea8..1c02cfff8
--- a/src/key_value_store.js
+++ b/src/key_value_store.js
@@@ -125,28 -147,46 +147,48 @@@ export const maybeStringify = (value, o
* // Delete record
* await store.delete('some-key');
* ```
- *
- * @param {String} storeId - ID of the key-value store.
* @hideconstructor
+ * @see {@linkcode Apify.getValue|Apify.getValue()}
+ * @see {@linkcode Apify.setValue|Apify.setValue()}
*/
export class KeyValueStore {
- constructor(storeId) {
+ constructor(storeId, storeName) {
checkParamOrThrow(storeId, 'storeId', 'String');
+ checkParamOrThrow(storeName, 'storeName', 'Maybe String');
this.storeId = storeId;
+ this.storeName = storeName;
}
- // TODO: Move here the Apify.getValue()/setValue() documentation, and link it from there.
- // This place should be the main source of information.
-
/**
- * Gets a record from the current key-value store using its key.
- * For more details, see [Apify.getValue](#module-Apify-getValue).
+ * Gets a value from the key-value store.
*
- * @param {String} key Record key.
- * @return {Promise}
+ * The function returns a promise that resolves to the record value,
+ * whose JavaScript type depends on the MIME content type of the record.
+ * Records with the `application/json`
+ * content type are automatically parsed and returned as a JavaScript object.
+ * Similarly, records with `text/plain` content types are returned as a string.
+ * For all other content types, the value is returned as a raw
+ * <a href="https://nodejs.org/api/buffer.html"><code>Buffer</code></a> instance.
+ *
+ * If the record does not exist, the functions resolves to `null`.
+ *
+ * To save or delete a value in the key-value store, use the
+ * {@linkcode KeyValueStore#setValue|KeyValueStore.setValue()} function.
+ *
+ * **Example usage:**
+ *
+ * ```javascript
+ * const store = await Apify.openKeyValueStore('my-screenshots');
+ * const buffer = await store.getValue('screenshot1.png');
+ * ```
+ *
+ * @param {String} key
+ * Key of the record.
+ * @returns {Promise}
+ * Returns a promise that resolves to an object, string
+ * or <a href="https://nodejs.org/api/buffer.html"><code>Buffer</code></a>, depending
+ * on the MIME content type of the record.
*/
getValue(key) {
validateGetValueParams(key);