@crawlee/core 4.0.0-beta.77 → 4.0.0-beta.79

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.
@@ -26,9 +26,9 @@ export declare class MemoryStorageBackend implements storage.StorageBackend {
26
26
  */
27
27
  getStorageBackendCacheKey(): string;
28
28
  private static resolveStorageKey;
29
- createDatasetBackend(options?: storage.CreateDatasetBackendOptions): Promise<storage.DatasetBackend>;
30
- createKeyValueStoreBackend(options?: storage.CreateKeyValueStoreBackendOptions): Promise<storage.KeyValueStoreBackend>;
31
- createRequestQueueBackend(options?: storage.CreateRequestQueueBackendOptions): Promise<RequestQueueBackend>;
29
+ createDatasetBackend(options?: storage.StorageIdentifier): Promise<storage.DatasetBackend>;
30
+ createKeyValueStoreBackend(options?: storage.StorageIdentifier): Promise<storage.KeyValueStoreBackend>;
31
+ createRequestQueueBackend(options?: storage.StorageIdentifier): Promise<RequestQueueBackend>;
32
32
  storageExists(id: string, type: 'Dataset' | 'KeyValueStore' | 'RequestQueue'): Promise<boolean>;
33
33
  /**
34
34
  * Cleans up the default storages before the run starts. For the in-memory storage this simply
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/core",
3
- "version": "4.0.0-beta.77",
3
+ "version": "4.0.0-beta.79",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -53,9 +53,9 @@
53
53
  "@apify/pseudo_url": "^2.0.59",
54
54
  "@apify/timeout": "^0.3.2",
55
55
  "@apify/utilities": "^2.15.5",
56
- "@crawlee/fs-storage": "4.0.0-beta.77",
57
- "@crawlee/types": "4.0.0-beta.77",
58
- "@crawlee/utils": "4.0.0-beta.77",
56
+ "@crawlee/fs-storage": "4.0.0-beta.79",
57
+ "@crawlee/types": "4.0.0-beta.79",
58
+ "@crawlee/utils": "4.0.0-beta.79",
59
59
  "@sapphire/async-queue": "^1.5.5",
60
60
  "@sapphire/shapeshift": "^4.0.0",
61
61
  "@vladfrangu/async_event_emitter": "^2.4.6",
@@ -79,5 +79,5 @@
79
79
  }
80
80
  }
81
81
  },
82
- "gitHead": "671ef0dab0f67275d0db5c289b940ea100ad3ef9"
82
+ "gitHead": "e897f0881c8142a1fd32f315263751296b4f1a22"
83
83
  }
@@ -460,8 +460,8 @@ export interface DatasetReducer<T, Data> {
460
460
  (memo: T, item: Data, index: number): Awaitable<T>;
461
461
  }
462
462
  export interface DatasetOptions {
463
- id: string;
464
- name?: string;
463
+ /** Resolved metadata for the dataset, as returned by the backend's `getMetadata()`. */
464
+ metadata: DatasetInfo;
465
465
  backend: DatasetBackend;
466
466
  }
467
467
  export interface DatasetContent<Data> {
@@ -97,8 +97,8 @@ export class Dataset {
97
97
  */
98
98
  constructor(options, config = Configuration.getGlobalConfig()) {
99
99
  this.config = config;
100
- this.id = options.id;
101
- this.name = options.name;
100
+ this.id = options.metadata.id;
101
+ this.name = options.metadata.name;
102
102
  this.backend = options.backend;
103
103
  this.log = serviceLocator.getLogger().child({ prefix: 'Dataset' });
104
104
  }
@@ -1,4 +1,4 @@
1
- import type { Dictionary, KeyValueStoreBackend } from '@crawlee/types';
1
+ import type { Dictionary, KeyValueStoreBackend, KeyValueStoreInfo } from '@crawlee/types';
2
2
  import { Configuration } from '../configuration.js';
3
3
  import type { Awaitable } from '../typedefs.js';
4
4
  import type { KeyValueStoreStats } from './storage_stats.js';
@@ -509,8 +509,8 @@ export interface KeyConsumer {
509
509
  }): Awaitable<void>;
510
510
  }
511
511
  export interface KeyValueStoreOptions {
512
- id: string;
513
- name?: string;
512
+ /** Resolved metadata for the key-value store, as returned by the backend's `getMetadata()`. */
513
+ metadata: KeyValueStoreInfo;
514
514
  backend: KeyValueStoreBackend;
515
515
  }
516
516
  /**
@@ -85,8 +85,8 @@ export class KeyValueStore {
85
85
  */
86
86
  constructor(options, config = Configuration.getGlobalConfig()) {
87
87
  this.config = config;
88
- this.id = options.id;
89
- this.name = options.name;
88
+ this.id = options.metadata.id;
89
+ this.name = options.metadata.name;
90
90
  this.backend = options.backend;
91
91
  }
92
92
  /**
@@ -50,12 +50,9 @@ export declare class RequestQueue implements IStorage, IRequestManager {
50
50
  protected readonly config: Configuration;
51
51
  id: string;
52
52
  name?: string;
53
- timeoutSecs: number;
54
- clientKey: string;
55
53
  backend: RequestQueueBackend;
56
54
  protected proxyConfiguration?: ProxyConfiguration;
57
55
  log: CrawleeLogger;
58
- private isInitialized;
59
56
  protected requestCache: LruCache<RequestLruItem>;
60
57
  /**
61
58
  * Remembers the `requestId` of every request already submitted to the client — including background
@@ -294,8 +291,8 @@ interface RequestLruItem {
294
291
  forefront: boolean;
295
292
  }
296
293
  export interface RequestQueueOptions {
297
- id: string;
298
- name?: string;
294
+ /** Resolved metadata for the request queue, as returned by the backend's `getMetadata()`. */
295
+ metadata: RequestQueueInfo;
299
296
  backend: RequestQueueBackend;
300
297
  /**
301
298
  * Used to pass the proxy configuration for the `requestsFromUrl` objects.
@@ -2,7 +2,6 @@ import { inspect } from 'node:util';
2
2
  import { chunkedAsyncIterable, downloadListOfUrls, getObjectType, isAsyncIterable, isIterable, peekableAsyncIterable, sleep, } from '@crawlee/utils';
3
3
  import ow from 'ow';
4
4
  import { LruCache } from '@apify/datastructures';
5
- import { cryptoRandomObjectId } from '@apify/utilities';
6
5
  import { Configuration } from '../configuration.js';
7
6
  import { Request } from '../request.js';
8
7
  import { serviceLocator } from '../service_locator.js';
@@ -59,12 +58,9 @@ export class RequestQueue {
59
58
  config;
60
59
  id;
61
60
  name;
62
- timeoutSecs = 30;
63
- clientKey = cryptoRandomObjectId();
64
61
  backend;
65
62
  proxyConfiguration;
66
63
  log;
67
- isInitialized = false;
68
64
  requestCache;
69
65
  /**
70
66
  * Remembers the `requestId` of every request already submitted to the client — including background
@@ -98,8 +94,8 @@ export class RequestQueue {
98
94
  */
99
95
  constructor(options, config = Configuration.getGlobalConfig()) {
100
96
  this.config = config;
101
- this.id = options.id;
102
- this.name = options.name;
97
+ this.id = options.metadata.id;
98
+ this.name = options.metadata.name;
103
99
  this.events = serviceLocator.getEventManager();
104
100
  this.backend = options.backend;
105
101
  this.proxyConfiguration = options.proxyConfiguration;
@@ -734,19 +730,6 @@ export class RequestQueue {
734
730
  });
735
731
  queue.proxyConfiguration = options.proxyConfiguration;
736
732
  queue.httpClient = options.httpClient;
737
- if (!queue.isInitialized) {
738
- // Re-create the request queue backend with clientKey and timeoutSecs so that
739
- // request locking works correctly for API-backed implementations.
740
- // TODO: clientKey/timeoutSecs are Apify-platform concerns and should eventually be pushed
741
- // down into the Apify SDK's client implementation, aligning with crawlee-python's approach
742
- // where locking is handled internally by the backend (see crawlee-python PR #1194).
743
- queue.backend = await storageBackend.createRequestQueueBackend({
744
- id: queue.id,
745
- clientKey: queue.clientKey,
746
- timeoutSecs: queue.timeoutSecs,
747
- });
748
- queue.isInitialized = true;
749
- }
750
733
  return queue;
751
734
  }
752
735
  }
@@ -187,11 +187,9 @@ export class StorageInstanceManager {
187
187
  // Cache miss — create the sub-backend and storage instance.
188
188
  const subBackend = await backendOpener();
189
189
  const storageInfo = await subBackend.getMetadata();
190
- const instance = new cls({
191
- id: storageInfo.id,
192
- name: storageInfo.name,
193
- backend: subBackend,
194
- });
190
+ // Storage frontends are thin wrappers over the backend. We hand them the resolved metadata
191
+ // we just fetched (so `id`/`name` etc. are available synchronously) along with the backend.
192
+ const instance = new cls({ metadata: storageInfo, backend: subBackend });
195
193
  // Atomic cache writes (no awaits between these).
196
194
  this.cache.set(cls, instance, backendCacheKey, alias);
197
195
  return instance;