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.

refactor: store raw values via `Dataset.exportToValue`

Martin Adámek0c1d1a8fa5b7
diff --git a/packages/core/src/storages/dataset.ts b/packages/core/src/storages/dataset.ts
index b3d95435e..f31d343bc 100644
--- a/packages/core/src/storages/dataset.ts
+++ b/packages/core/src/storages/dataset.ts
@@ -296,8 +296,8 @@ export class Dataset<Data extends Dictionary = Dictionary> {
async exportToValue(key?: string, options: RecordOptions & { keyValueStoreName?: string } = {}) {
const { keyValueStoreName, ...recordOptions } = options;
const kvStore = await KeyValueStore.open(keyValueStoreName ?? null);
-
- await kvStore.setValue(key || 'OUTPUT', await this.client.listItems(), recordOptions);
+ const value = await this.client.listItems();
+ await kvStore.setValue(key ?? 'OUTPUT', value.items, recordOptions);
}
/**
diff --git a/test/core/storages/dataset.test.ts b/test/core/storages/dataset.test.ts
index 02562f683..7d61abe5b 100644
--- a/test/core/storages/dataset.test.ts
+++ b/test/core/storages/dataset.test.ts
@@ -488,19 +488,16 @@ describe('dataset', () => {
await dataset.pushData(dataToPush);
await dataset.exportToValue('HELLO');
- const kvData = await KeyValueStore.getValue<{ items: [] }>('HELLO');
-
- expect(kvData.items).toEqual(dataToPush);
+ const kvData = await KeyValueStore.getValue('HELLO');
+ expect(kvData).toEqual(dataToPush);
});
it('Should work as a static method for the default dataset', async () => {
await Dataset.pushData(dataToPush);
-
await Dataset.exportToValue('TEST-123-123');
- const kvData = await KeyValueStore.getValue<{ items: [] }>('TEST-123-123');
-
- expect(kvData.items).toEqual(dataToPush);
+ const kvData = await KeyValueStore.getValue('TEST-123-123');
+ expect(kvData).toEqual(dataToPush);
});
});
});