@crawlee/fs-storage 4.0.0-beta.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ <h1 align="center">
2
+ <a href="https://crawlee.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true" />
5
+ <img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500" />
6
+ </picture>
7
+ </a>
8
+ <br />
9
+ <small>A web scraping and browser automation library</small>
10
+ </h1>
11
+
12
+ <p align="center">
13
+ <a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" width="250" height="55"/></a>
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" /></a>
18
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" /></a>
19
+ <a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" /></a>
20
+ <a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" /></a>
21
+ </p>
22
+
23
+ Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
24
+
25
+ Your crawlers will appear human-like and fly under the radar of modern bot protections even with the default configuration. Crawlee gives you the tools to crawl the web for links, scrape data, and store it to disk or cloud while staying configurable to suit your project's needs.
26
+
27
+ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package.
28
+
29
+ > 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
30
+
31
+ > Do you prefer 🐍 Python instead of JavaScript? [👉 Checkout Crawlee for Python 👈](https://github.com/apify/crawlee-python).
32
+
33
+ ## Installation
34
+
35
+ We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
36
+
37
+ > Crawlee requires **Node.js 16 or higher**.
38
+
39
+ ### With Crawlee CLI
40
+
41
+ The fastest way to try Crawlee out is to use the **Crawlee CLI** and choose the **Getting started example**. The CLI will install all the necessary dependencies and add boilerplate code for you to play with.
42
+
43
+ ```bash
44
+ npx crawlee create my-crawler
45
+ ```
46
+
47
+ ```bash
48
+ cd my-crawler
49
+ npm start
50
+ ```
51
+
52
+ ### Manual installation
53
+ If you prefer adding Crawlee **into your own project**, try the example below. Because it uses `PlaywrightCrawler` we also need to install [Playwright](https://playwright.dev). It's not bundled with Crawlee to reduce install size.
54
+
55
+ ```bash
56
+ npm install crawlee playwright
57
+ ```
58
+
59
+ ```js
60
+ import { PlaywrightCrawler, Dataset } from 'crawlee';
61
+
62
+ // PlaywrightCrawler crawls the web using a headless
63
+ // browser controlled by the Playwright library.
64
+ const crawler = new PlaywrightCrawler({
65
+ // Use the requestHandler to process each of the crawled pages.
66
+ async requestHandler({ request, page, enqueueLinks, log }) {
67
+ const title = await page.title();
68
+ log.info(`Title of ${request.loadedUrl} is '${title}'`);
69
+
70
+ // Save results as JSON to ./storage/datasets/default
71
+ await Dataset.pushData({ title, url: request.loadedUrl });
72
+
73
+ // Extract links from the current page
74
+ // and add them to the crawling queue.
75
+ await enqueueLinks();
76
+ },
77
+ // Uncomment this option to see the browser window.
78
+ // headless: false,
79
+ });
80
+
81
+ // Add first URL to the queue and start the crawl.
82
+ await crawler.run(['https://crawlee.dev']);
83
+ ```
84
+
85
+ By default, Crawlee stores data to `./storage` in the current working directory. You can override this directory via Crawlee configuration. For details, see [Configuration guide](https://crawlee.dev/js/docs/guides/configuration), [Request storage](https://crawlee.dev/js/docs/guides/request-storage) and [Result storage](https://crawlee.dev/js/docs/guides/result-storage).
86
+
87
+ ### Installing pre-release versions
88
+
89
+ We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm [list of releases](https://www.npmjs.com/package/crawlee?activeTab=versions). If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:
90
+
91
+ ```bash
92
+ npm install crawlee@next
93
+ ```
94
+
95
+ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need to specify dependency overrides in your `package.json` file so that you don't end up with multiple versions of Crawlee installed:
96
+
97
+ ```json
98
+ {
99
+ "overrides": {
100
+ "apify": {
101
+ "@crawlee/core": "$crawlee",
102
+ "@crawlee/types": "$crawlee",
103
+ "@crawlee/utils": "$crawlee"
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ ## 🛠 Features
110
+
111
+ - Single interface for **HTTP and headless browser** crawling
112
+ - Persistent **queue** for URLs to crawl (breadth & depth first)
113
+ - Pluggable **storage** of both tabular data and files
114
+ - Automatic **scaling** with available system resources
115
+ - Integrated **proxy rotation** and session management
116
+ - Lifecycles customizable with **hooks**
117
+ - **CLI** to bootstrap your projects
118
+ - Configurable **routing**, **error handling** and **retries**
119
+ - **Dockerfiles** ready to deploy
120
+ - Written in **TypeScript** with generics
121
+
122
+ ### 👾 HTTP crawling
123
+
124
+ - Zero config **HTTP2 support**, even for proxies
125
+ - Automatic generation of **browser-like headers**
126
+ - Replication of browser **TLS fingerprints**
127
+ - Integrated fast **HTML parsers**. Cheerio and JSDOM
128
+ - Yes, you can scrape **JSON APIs** as well
129
+
130
+ ### 💻 Real browser crawling
131
+
132
+ - JavaScript **rendering** and **screenshots**
133
+ - **Headless** and **headful** support
134
+ - Zero-config generation of **human-like fingerprints**
135
+ - Automatic **browser management**
136
+ - Use **Playwright** and **Puppeteer** with the same interface
137
+ - **Chrome**, **Firefox**, **Webkit** and many others
138
+
139
+ ## Usage on the Apify platform
140
+
141
+ Crawlee is open-source and runs anywhere, but since it's developed by [Apify](https://apify.com), it's easy to set up on the Apify platform and run in the cloud. Visit the [Apify SDK website](https://sdk.apify.com) to learn more about deploying Crawlee to the Apify platform.
142
+
143
+ ## Support
144
+
145
+ If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/crawlee/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
146
+
147
+ ## Contributing
148
+
149
+ Your code contributions are welcome, and you'll be praised to eternity! If you have any ideas for improvements, either submit an issue or create a pull request. For contribution guidelines and the code of conduct, see [CONTRIBUTING.md](https://github.com/apify/crawlee/blob/master/CONTRIBUTING.md).
150
+
151
+ ## License
152
+
153
+ This project is licensed under the Apache License 2.0 - see the [LICENSE.md](https://github.com/apify/crawlee/blob/master/LICENSE.md) file for details.
@@ -0,0 +1,88 @@
1
+ import type * as storage from '@crawlee/types';
2
+ import type { CrawleeLogger } from '@crawlee/types';
3
+ import { DatasetBackend } from './resource-clients/dataset.js';
4
+ import { KeyValueStoreBackend } from './resource-clients/key-value-store.js';
5
+ import { RequestQueueBackend } from './resource-clients/request-queue.js';
6
+ export interface FileSystemStorageOptions {
7
+ /**
8
+ * Path to directory where the data will be saved.
9
+ */
10
+ localDataDirectory: string;
11
+ /**
12
+ * Optional logger for FileSystemStorageBackend warnings.
13
+ */
14
+ logger?: CrawleeLogger;
15
+ /**
16
+ * How the on-disk request queues opened by this backend are expected to be accessed.
17
+ *
18
+ * With `'single'` (the default), this process asserts it is the *sole* consumer of every request
19
+ * queue it opens: on open, any requests that a previous run left *in progress* (e.g. after a
20
+ * crash) are reclaimed immediately, so they become fetchable again right away. This is the right
21
+ * behavior for the common single-process crawl.
22
+ *
23
+ * Use `'shared'` if multiple processes share the same on-disk request queue concurrently (for
24
+ * example, the {@link parallel scraping setup | "Parallel Scraping Guide"}). In that mode an
25
+ * in-progress request is treated as a potential live peer's lock and is only reclaimed once that
26
+ * lock expires on the wall clock, so two workers won't process the same request at once.
27
+ *
28
+ * @default 'single'
29
+ */
30
+ requestQueueAccess?: 'single' | 'shared';
31
+ }
32
+ /**
33
+ * A file-system storage backend backed by the native `@crawlee/fs-storage-native` Rust extension.
34
+ *
35
+ * The native extension owns the on-disk format, timestamps, item counting, request-queue locking and
36
+ * state persistence. This class is responsible for resolving the user-facing `id` / `name` / `alias`
37
+ * identifiers to native storages, caching the opened backends (so that `storageExists`, `purge` and
38
+ * `teardown` can operate over them), and exposing them through the `@crawlee/types` interfaces.
39
+ */
40
+ export declare class FileSystemStorageBackend implements storage.StorageBackend {
41
+ readonly localDataDirectory: string;
42
+ readonly datasetsDirectory: string;
43
+ readonly keyValueStoresDirectory: string;
44
+ readonly requestQueuesDirectory: string;
45
+ readonly logger?: CrawleeLogger;
46
+ readonly requestQueueAccess: 'single' | 'shared';
47
+ readonly keyValueStoreBackendCache: KeyValueStoreBackend[];
48
+ readonly datasetBackendCache: DatasetBackend[];
49
+ readonly requestQueueBackendCache: RequestQueueBackend[];
50
+ constructor(options: FileSystemStorageOptions);
51
+ /**
52
+ * Return a cache key that includes the resolved storage directory, so that two
53
+ * `FileSystemStorageBackend` instances pointing at different directories get separate cache
54
+ * partitions, by including the storage directory in the cache key.
55
+ */
56
+ getStorageBackendCacheKey(): string;
57
+ private static resolveStorageKey;
58
+ createDatasetBackend(options?: storage.CreateDatasetBackendOptions): Promise<storage.DatasetBackend>;
59
+ createKeyValueStoreBackend(options?: storage.CreateKeyValueStoreBackendOptions): Promise<storage.KeyValueStoreBackend>;
60
+ createRequestQueueBackend(options?: storage.CreateRequestQueueBackendOptions): Promise<storage.RequestQueueBackend>;
61
+ storageExists(id: string, type: 'Dataset' | 'KeyValueStore' | 'RequestQueue'): Promise<boolean>;
62
+ /**
63
+ * Resolve the real `id` of the on-disk storage identified by `entryNameOrId` under `baseDirectory`,
64
+ * or `undefined` if none matches. The storage's real id lives in its directory's
65
+ * `__metadata__.json`; the directory itself is named after the storage's `name ?? id`. So this
66
+ * first tries the directory named exactly `entryNameOrId` (reading its metadata id), then falls
67
+ * back to scanning sibling directories for one whose metadata id equals `entryNameOrId` (the case
68
+ * of a storage opened by name and later looked up by its auto-assigned id).
69
+ */
70
+ private static resolveStorageIdOnDisk;
71
+ /** Read the `id` field from a storage directory's `__metadata__.json`, or `undefined` if absent. */
72
+ private static readMetadataId;
73
+ /**
74
+ * Cleans up the default storages before the run starts:
75
+ * - the default dataset;
76
+ * - all records from the default key-value store, except for the "INPUT" key;
77
+ * - the default request queue.
78
+ */
79
+ purge(): Promise<void>;
80
+ /**
81
+ * This method should be called at the end of the process, to ensure all data is saved.
82
+ *
83
+ * It persists the state of every opened request queue so that requests fetched but not yet handled
84
+ * are not stuck (until their lock expires) for the next consumer of the same on-disk queue.
85
+ */
86
+ teardown(): Promise<void>;
87
+ }
88
+ //# sourceMappingURL=file-system-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-system-storage.d.ts","sourceRoot":"","sources":["../src/file-system-storage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQpD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,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IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
@@ -0,0 +1,230 @@
1
+ import { opendir, readFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { s } from '@sapphire/shapeshift';
4
+ import { FileSystemDatasetClient as NativeDatasetBackend, FileSystemKeyValueStoreClient as NativeKeyValueStoreBackend, FileSystemRequestQueueClient as NativeRequestQueueBackend, } from '@crawlee/fs-storage-native';
5
+ import { DatasetBackend } from './resource-clients/dataset.js';
6
+ import { KeyValueStoreBackend } from './resource-clients/key-value-store.js';
7
+ import { RequestQueueBackend } from './resource-clients/request-queue.js';
8
+ /**
9
+ * A file-system storage backend backed by the native `@crawlee/fs-storage-native` Rust extension.
10
+ *
11
+ * The native extension owns the on-disk format, timestamps, item counting, request-queue locking and
12
+ * state persistence. This class is responsible for resolving the user-facing `id` / `name` / `alias`
13
+ * identifiers to native storages, caching the opened backends (so that `storageExists`, `purge` and
14
+ * `teardown` can operate over them), and exposing them through the `@crawlee/types` interfaces.
15
+ */
16
+ export class FileSystemStorageBackend {
17
+ localDataDirectory;
18
+ datasetsDirectory;
19
+ keyValueStoresDirectory;
20
+ requestQueuesDirectory;
21
+ logger;
22
+ requestQueueAccess;
23
+ keyValueStoreBackendCache = [];
24
+ datasetBackendCache = [];
25
+ requestQueueBackendCache = [];
26
+ constructor(options) {
27
+ s.object({
28
+ localDataDirectory: s.string(),
29
+ requestQueueAccess: s.enum(['single', 'shared']).optional(),
30
+ }).parse(options);
31
+ this.logger = options.logger;
32
+ this.requestQueueAccess = options.requestQueueAccess ?? 'single';
33
+ this.localDataDirectory = options.localDataDirectory;
34
+ this.datasetsDirectory = resolve(this.localDataDirectory, 'datasets');
35
+ this.keyValueStoresDirectory = resolve(this.localDataDirectory, 'key_value_stores');
36
+ this.requestQueuesDirectory = resolve(this.localDataDirectory, 'request_queues');
37
+ }
38
+ /**
39
+ * Return a cache key that includes the resolved storage directory, so that two
40
+ * `FileSystemStorageBackend` instances pointing at different directories get separate cache
41
+ * partitions, by including the storage directory in the cache key.
42
+ */
43
+ getStorageBackendCacheKey() {
44
+ return `FileSystemStorageBackend:${resolve(this.localDataDirectory)}`;
45
+ }
46
+ static resolveStorageKey(options) {
47
+ const isAlias = 'alias' in options && !!options.alias;
48
+ const rawKey = isAlias ? options.alias : (options.name ?? options.id);
49
+ // Normalize the internal __default__ alias to the user-facing 'default' name.
50
+ const cacheKey = rawKey === '__default__' ? 'default' : rawKey;
51
+ return { id: options.id, name: options.name, alias: options.alias, cacheKey };
52
+ }
53
+ async createDatasetBackend(options = {}) {
54
+ const { id, name, alias, cacheKey } = FileSystemStorageBackend.resolveStorageKey(options);
55
+ if (cacheKey) {
56
+ const found = this.datasetBackendCache.find((store) => store.id === cacheKey ||
57
+ store.name?.toLowerCase() === cacheKey.toLowerCase() ||
58
+ store.cacheKey.toLowerCase() === cacheKey.toLowerCase());
59
+ if (found) {
60
+ return found;
61
+ }
62
+ }
63
+ const nativeBackend = await NativeDatasetBackend.open(id, name, alias, this.localDataDirectory);
64
+ const newStore = await DatasetBackend.create({
65
+ name: alias ? undefined : (name ?? cacheKey),
66
+ cacheKey: cacheKey ?? '',
67
+ nativeBackend,
68
+ logger: this.logger,
69
+ });
70
+ this.datasetBackendCache.push(newStore);
71
+ return newStore;
72
+ }
73
+ async createKeyValueStoreBackend(options = {}) {
74
+ const { id, name, alias, cacheKey } = FileSystemStorageBackend.resolveStorageKey(options);
75
+ if (cacheKey) {
76
+ const found = this.keyValueStoreBackendCache.find((store) => store.id === cacheKey ||
77
+ store.name?.toLowerCase() === cacheKey.toLowerCase() ||
78
+ store.cacheKey.toLowerCase() === cacheKey.toLowerCase());
79
+ if (found) {
80
+ return found;
81
+ }
82
+ }
83
+ const nativeBackend = await NativeKeyValueStoreBackend.open(id, name, alias, this.localDataDirectory);
84
+ const newStore = await KeyValueStoreBackend.create({
85
+ name: alias ? undefined : (name ?? cacheKey),
86
+ cacheKey: cacheKey ?? '',
87
+ nativeBackend,
88
+ logger: this.logger,
89
+ });
90
+ this.keyValueStoreBackendCache.push(newStore);
91
+ return newStore;
92
+ }
93
+ async createRequestQueueBackend(options = {}) {
94
+ const { id, name, alias, cacheKey } = FileSystemStorageBackend.resolveStorageKey(options);
95
+ if (cacheKey) {
96
+ const found = this.requestQueueBackendCache.find((queue) => queue.id === cacheKey ||
97
+ queue.name?.toLowerCase() === cacheKey.toLowerCase() ||
98
+ queue.cacheKey.toLowerCase() === cacheKey.toLowerCase());
99
+ if (found) {
100
+ return found;
101
+ }
102
+ }
103
+ const nativeBackend = await NativeRequestQueueBackend.open(id, name, alias, this.localDataDirectory,
104
+ // useTestClock — always real wall-clock outside of native tests.
105
+ undefined, this.requestQueueAccess);
106
+ const newStore = await RequestQueueBackend.create({
107
+ name: alias ? undefined : (name ?? cacheKey),
108
+ cacheKey: cacheKey ?? '',
109
+ nativeBackend,
110
+ logger: this.logger,
111
+ });
112
+ this.requestQueueBackendCache.push(newStore);
113
+ return newStore;
114
+ }
115
+ async storageExists(id, type) {
116
+ let backends;
117
+ let baseDir;
118
+ switch (type) {
119
+ case 'Dataset':
120
+ backends = this.datasetBackendCache;
121
+ baseDir = this.datasetsDirectory;
122
+ break;
123
+ case 'KeyValueStore':
124
+ backends = this.keyValueStoreBackendCache;
125
+ baseDir = this.keyValueStoresDirectory;
126
+ break;
127
+ case 'RequestQueue':
128
+ backends = this.requestQueueBackendCache;
129
+ baseDir = this.requestQueuesDirectory;
130
+ break;
131
+ default:
132
+ return false;
133
+ }
134
+ // Check the in-memory cache by actual storage ID first.
135
+ if (backends.some((store) => store.id === id)) {
136
+ return true;
137
+ }
138
+ // Otherwise, resolve any on-disk storage that matches the queried string — either by its
139
+ // directory name, or (for a storage opened by name, whose directory is named after the name)
140
+ // by scanning the `__metadata__.json` files for a matching id.
141
+ //
142
+ // A directory-name match does NOT by itself prove the string is the storage's *id*: the
143
+ // directory is named after `name ?? id`, so `named-storage`/`on-disk` (a name or alias) also
144
+ // has a matching directory. We therefore read the real id from the metadata and only report
145
+ // existence when it equals the queried string. This matches upstream PR #3800/#3808 and
146
+ // prevents a named storage from being re-resolved as `{ id: name }` on a subsequent run.
147
+ const resolvedId = await FileSystemStorageBackend.resolveStorageIdOnDisk(baseDir, id);
148
+ return resolvedId === id;
149
+ }
150
+ /**
151
+ * Resolve the real `id` of the on-disk storage identified by `entryNameOrId` under `baseDirectory`,
152
+ * or `undefined` if none matches. The storage's real id lives in its directory's
153
+ * `__metadata__.json`; the directory itself is named after the storage's `name ?? id`. So this
154
+ * first tries the directory named exactly `entryNameOrId` (reading its metadata id), then falls
155
+ * back to scanning sibling directories for one whose metadata id equals `entryNameOrId` (the case
156
+ * of a storage opened by name and later looked up by its auto-assigned id).
157
+ */
158
+ static async resolveStorageIdOnDisk(baseDirectory, entryNameOrId) {
159
+ // Directory named exactly after the string: return its real (metadata) id, which may differ
160
+ // from the string when the string is a name rather than an id.
161
+ const directId = await FileSystemStorageBackend.readMetadataId(resolve(baseDirectory, entryNameOrId));
162
+ if (directId !== undefined) {
163
+ return directId;
164
+ }
165
+ // No such directory — scan siblings for one whose metadata id matches the string.
166
+ let directories;
167
+ try {
168
+ directories = await opendir(baseDirectory);
169
+ }
170
+ catch {
171
+ return undefined;
172
+ }
173
+ for await (const directory of directories) {
174
+ if (!directory.isDirectory()) {
175
+ continue;
176
+ }
177
+ const metadataId = await FileSystemStorageBackend.readMetadataId(resolve(baseDirectory, directory.name));
178
+ if (metadataId === entryNameOrId) {
179
+ return metadataId;
180
+ }
181
+ }
182
+ return undefined;
183
+ }
184
+ /** Read the `id` field from a storage directory's `__metadata__.json`, or `undefined` if absent. */
185
+ static async readMetadataId(storageDirectory) {
186
+ try {
187
+ const fileContent = await readFile(resolve(storageDirectory, '__metadata__.json'), 'utf8');
188
+ return JSON.parse(fileContent).id;
189
+ }
190
+ catch {
191
+ // Directory missing, or no/unreadable metadata file — no id to report.
192
+ return undefined;
193
+ }
194
+ }
195
+ /**
196
+ * Cleans up the default storages before the run starts:
197
+ * - the default dataset;
198
+ * - all records from the default key-value store, except for the "INPUT" key;
199
+ * - the default request queue.
200
+ */
201
+ async purge() {
202
+ // Resolve the default stores up front so leftover on-disk records are purged even when the
203
+ // store has not been opened in this process yet (e.g. a fresh run over a pre-existing
204
+ // directory). Opening caches the backend, so the subsequent purge operates on a real backend.
205
+ // The default store is opened via the internal `__default__` alias (see resolveStorageIdentifier
206
+ // in @crawlee/core), which resolves to the `default` cache key — match that here so we purge the
207
+ // very backend the default open would return rather than creating a divergent one.
208
+ const [defaultKeyValueStore, defaultDataset, defaultRequestQueue] = await Promise.all([
209
+ this.createKeyValueStoreBackend({ alias: '__default__' }),
210
+ this.createDatasetBackend({ alias: '__default__' }),
211
+ this.createRequestQueueBackend({ alias: '__default__' }),
212
+ ]);
213
+ await Promise.all([
214
+ // Preserve the run input (INPUT) when purging the default key-value store.
215
+ defaultKeyValueStore.purgeExceptInput(),
216
+ defaultDataset.purge(),
217
+ defaultRequestQueue.purge(),
218
+ ]);
219
+ }
220
+ /**
221
+ * This method should be called at the end of the process, to ensure all data is saved.
222
+ *
223
+ * It persists the state of every opened request queue so that requests fetched but not yet handled
224
+ * are not stuck (until their lock expires) for the next consumer of the same on-disk queue.
225
+ */
226
+ async teardown() {
227
+ await Promise.all(this.requestQueueBackendCache.map(async (queue) => queue.persistState()));
228
+ }
229
+ }
230
+ //# sourceMappingURL=file-system-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-system-storage.js","sourceRoot":"","sources":["../src/file-system-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAEzC,OAAO,EACH,uBAAuB,IAAI,oBAAoB,EAC/C,6BAA6B,IAAI,0BAA0B,EAC3D,4BAA4B,IAAI,yBAAyB,GAC5D,MAAM,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C,GAAG,CAAC;YAClF,IAAI,CAAC,0BAA0B,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAkC;YAC1F,IAAI,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAA4B;YAC9E,IAAI,CAAC,yBAAyB,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAiC;SAC3F,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC;YACd,2EAA2E;YAC3E,oBAAoB,CAAC,gBAAgB,EAAE;YACvC,cAAc,CAAC,KAAK,EAAE;YACtB,mBAAmB,CAAC,KAAK,EAAE;SAC9B,CAAC,CAAC;IACP,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ;QACV,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IAChG,CAAC;CACJ"}
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './file-system-storage.js';
2
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './file-system-storage.js';
2
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@crawlee/fs-storage",
3
+ "version": "4.0.0-beta.67",
4
+ "description": "A file-system storage implementation of the Apify API",
5
+ "engines": {
6
+ "node": ">=22.0.0"
7
+ },
8
+ "type": "module",
9
+ "exports": {
10
+ ".": "./index.js",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "keywords": [
14
+ "apify",
15
+ "api",
16
+ "filesystem"
17
+ ],
18
+ "author": {
19
+ "name": "Apify",
20
+ "email": "support@apify.com",
21
+ "url": "https://apify.com"
22
+ },
23
+ "contributors": [
24
+ "Vlad Frangu <kingdgrizzle@gmail.com>"
25
+ ],
26
+ "license": "Apache-2.0",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/apify/crawlee"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/apify/crawlee/issues"
33
+ },
34
+ "homepage": "https://crawlee.dev",
35
+ "scripts": {
36
+ "build": "pnpm clean && pnpm compile && pnpm copy",
37
+ "clean": "rimraf ./dist",
38
+ "compile": "tsc -p tsconfig.build.json",
39
+ "copy": "tsx ../../scripts/copy.ts"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "dependencies": {
45
+ "@crawlee/fs-storage-native": "0.1.5-beta.18",
46
+ "@crawlee/types": "4.0.0-beta.67",
47
+ "@sapphire/shapeshift": "^4.0.0"
48
+ },
49
+ "lerna": {
50
+ "command": {
51
+ "publish": {
52
+ "assets": []
53
+ }
54
+ }
55
+ },
56
+ "gitHead": "921ed3d4c8ba88785af737523de5c66a483559c0"
57
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared base for the file-system resource backends. The native id is read once from the native
3
+ * metadata at construction time (in each backend's `create()`), so the synchronous `id` getter —
4
+ * required by `FileSystemStorageBackend.storageExists` and the cache lookups — does not have to await.
5
+ */
6
+ export declare abstract class CachedIdClient {
7
+ /** The storage id assigned by the native client. Set once by the subclass `create()`. */
8
+ protected _cachedId: string;
9
+ /** The storage id assigned by the native client. */
10
+ get id(): string;
11
+ }
12
+ //# sourceMappingURL=cached-id-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cached-id-client.d.ts","sourceRoot":"","sources":["../../src/resource-clients/cached-id-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAAsB,cAAc;IAChC,yFAAyF;IACzF,SAAS,CAAC,SAAS,EAAG,MAAM,CAAC;IAE7B,oDAAoD;IACpD,IAAI,EAAE,IAAI,MAAM,CAEf;CACJ"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Shared base for the file-system resource backends. The native id is read once from the native
3
+ * metadata at construction time (in each backend's `create()`), so the synchronous `id` getter —
4
+ * required by `FileSystemStorageBackend.storageExists` and the cache lookups — does not have to await.
5
+ */
6
+ export class CachedIdClient {
7
+ /** The storage id assigned by the native client. Set once by the subclass `create()`. */
8
+ _cachedId;
9
+ /** The storage id assigned by the native client. */
10
+ get id() {
11
+ return this._cachedId;
12
+ }
13
+ }
14
+ //# sourceMappingURL=cached-id-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cached-id-client.js","sourceRoot":"","sources":["../../src/resource-clients/cached-id-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAgB,cAAc;IAChC,yFAAyF;IAC/E,SAAS,CAAU;IAE7B,oDAAoD;IACpD,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;CACJ"}
@@ -0,0 +1,37 @@
1
+ import type * as storage from '@crawlee/types';
2
+ import type { CrawleeLogger, Dictionary } from '@crawlee/types';
3
+ import type { FileSystemDatasetClient as NativeFileSystemDatasetBackend } from '@crawlee/fs-storage-native';
4
+ import { CachedIdClient } from './cached-id-client.js';
5
+ export interface DatasetBackendOptions {
6
+ /** The user-facing storage name, or `undefined` for unnamed (alias / default) storages. */
7
+ name?: string;
8
+ /**
9
+ * The key used for cache lookup in {@link FileSystemStorageBackend}. For named storages this equals
10
+ * the name; for alias (unnamed) storages it is the alias string. Falls back to the storage id.
11
+ */
12
+ cacheKey: string;
13
+ nativeBackend: NativeFileSystemDatasetBackend;
14
+ logger?: CrawleeLogger;
15
+ }
16
+ /**
17
+ * A file-system dataset backend backed by the native `@crawlee/fs-storage-native` Rust extension.
18
+ *
19
+ * This class is a thin adapter: it forwards each operation to the native client (which owns the
20
+ * on-disk format, timestamps and item counting) and converts results into the shapes expected by
21
+ * the `@crawlee/types` interfaces.
22
+ */
23
+ export declare class DatasetBackend<Data extends Dictionary = Dictionary> extends CachedIdClient implements storage.DatasetBackend<Data> {
24
+ readonly name?: string;
25
+ readonly cacheKey: string;
26
+ private readonly nativeBackend;
27
+ private readonly logger?;
28
+ constructor(options: DatasetBackendOptions);
29
+ get datasetDirectory(): string;
30
+ static create<Data extends Dictionary = Dictionary>(options: DatasetBackendOptions): Promise<DatasetBackend<Data>>;
31
+ getMetadata(): Promise<storage.DatasetInfo>;
32
+ drop(): Promise<void>;
33
+ purge(): Promise<void>;
34
+ pushData(items: Data[]): Promise<void>;
35
+ getData(options?: storage.DatasetBackendListOptions): Promise<storage.PaginatedList<Data>>;
36
+ }
37
+ //# sourceMappingURL=dataset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../src/resource-clients/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAO,KAAK,EAAE,uBAAuB,IAAI,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5G,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAYvD,MAAM,WAAW,qBAAqB;IAClC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,8BAA8B,CAAC;IAC9C,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,qBAAa,cAAc,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,CAC5D,SAAQ,cACR,YAAW,OAAO,CAAC,cA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