@crawlee/basic 4.0.0-beta.144 → 4.0.0-beta.145

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.
@@ -176,8 +176,8 @@ export interface BasicCrawlerOptions<Context extends CrawlingContext = CrawlingC
176
176
  * single budget. Each crawler still builds and drives its own {@link AutoscaledPool}; only the load/scaling
177
177
  * accounting is shared.
178
178
  *
179
- * Mutually exclusive with the `minConcurrency`/`maxConcurrency`/`maxRequestsPerMinute` shortcuts, which configure
180
- * the default system this one replaces — combining the two throws.
179
+ * Mutually exclusive with the `minConcurrency`/`maxConcurrency`/`initialConcurrency`/`maxRequestsPerMinute`
180
+ * shortcuts, which configure the default system this one replaces — combining the two throws.
181
181
  *
182
182
  * You own a supplied system's lifecycle: `start()` it before `run()` (which throws otherwise) and `stop()` it once
183
183
  * every crawler borrowing it has finished. The crawler does neither on your behalf.
@@ -197,6 +197,12 @@ export interface BasicCrawlerOptions<Context extends CrawlingContext = CrawlingC
197
197
  * {@link ConcurrencySystem}.
198
198
  */
199
199
  maxConcurrency?: number;
200
+ /**
201
+ * Sets the concurrency (parallelism) the crawl starts with, before any scaling happens. Shortcut for the
202
+ * {@link ConcurrencySystemOptions.desiredConcurrency|`desiredConcurrency`} option of the crawler's default
203
+ * {@link ConcurrencySystem}. Defaults to `minConcurrency`.
204
+ */
205
+ initialConcurrency?: number;
200
206
  /**
201
207
  * The maximum number of requests per minute the crawler should run.
202
208
  * By default, this is set to `Infinity`, but we can pass any positive, non-zero integer.
@@ -478,6 +484,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingCont
478
484
  logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
479
485
  minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
480
486
  maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
487
+ initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
481
488
  maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
482
489
  keepAlive: z.ZodOptional<z.ZodBoolean>;
483
490
  statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
@@ -489,7 +496,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingCont
489
496
  constructor(options?: BasicCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> & RequireContextPipeline<CrawlingContext, Context>);
490
497
  /**
491
498
  * Builds the crawler-owned default {@link ConcurrencySystem} from the resolved
492
- * `minConcurrency`/`maxConcurrency`/`maxRequestsPerMinute` shortcuts. Not called when a
499
+ * `minConcurrency`/`maxConcurrency`/`initialConcurrency`/`maxRequestsPerMinute` shortcuts. Not called when a
493
500
  * {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} was injected.
494
501
  *
495
502
  * Subclasses may override this to tune the default system (e.g. {@link HttpCrawler} raises the starting
@@ -271,6 +271,7 @@ export class BasicCrawler {
271
271
  // AutoscaledPool shorthands
272
272
  minConcurrency: schemas.anyNumber.optional(),
273
273
  maxConcurrency: schemas.anyNumber.optional(),
274
+ initialConcurrency: schemas.anyNumber.optional(),
274
275
  maxRequestsPerMinute: schemas.anyNumber
275
276
  .refine((value) => Number.isInteger(value) || value === Infinity, 'Expected an integer or infinite number')
276
277
  .refine((value) => value >= 1, 'Expected a number greater than or equal to 1')
@@ -293,15 +294,18 @@ export class BasicCrawler {
293
294
  // Service locator options
294
295
  configuration, storageBackend, eventManager, logger,
295
296
  // AutoscaledPool shorthands
296
- minConcurrency, maxConcurrency, maxRequestsPerMinute, blockedStatusCodes: blockedStatusCodesInput, retryOnBlocked, respectRobotsTxtFile, transactionalStorage, onSkippedRequest, requestHandler, requestHandlerTimeoutSecs, errorHandler, failedRequestHandler, statusMessageLoggingInterval, statusMessageCallback, statistics, httpClient, id, } = parsedOptions;
297
+ minConcurrency, maxConcurrency, initialConcurrency, maxRequestsPerMinute, blockedStatusCodes: blockedStatusCodesInput, retryOnBlocked, respectRobotsTxtFile, transactionalStorage, onSkippedRequest, requestHandler, requestHandlerTimeoutSecs, errorHandler, failedRequestHandler, statusMessageLoggingInterval, statusMessageCallback, statistics, httpClient, id, } = parsedOptions;
297
298
  // All concurrency configuration lives on the `ConcurrencySystem`, so the shortcuts have nowhere to go once
298
299
  // one is supplied - and silently dropping a `maxConcurrency` the user asked for is how crawls end up
299
300
  // hammering a site.
300
301
  if (concurrencySystem !== undefined &&
301
- (minConcurrency !== undefined || maxConcurrency !== undefined || maxRequestsPerMinute !== undefined)) {
302
- throw new Error('The `minConcurrency`/`maxConcurrency`/`maxRequestsPerMinute` shortcuts cannot be combined with ' +
303
- '`concurrencySystem` - they configure the default `ConcurrencySystem` that a supplied one ' +
304
- 'replaces. Pass them to the `ConcurrencySystem` constructor instead.');
302
+ (minConcurrency !== undefined ||
303
+ maxConcurrency !== undefined ||
304
+ initialConcurrency !== undefined ||
305
+ maxRequestsPerMinute !== undefined)) {
306
+ throw new Error('The `minConcurrency`/`maxConcurrency`/`initialConcurrency`/`maxRequestsPerMinute` shortcuts ' +
307
+ 'cannot be combined with `concurrencySystem` - they configure the default `ConcurrencySystem` ' +
308
+ 'that a supplied one replaces. Pass them to the `ConcurrencySystem` constructor instead.');
305
309
  }
306
310
  // Create per-crawler service locator if custom services were provided.
307
311
  // This wraps every method on the crawler instance so that calls to the global `serviceLocator`
@@ -528,6 +532,9 @@ export class BasicCrawler {
528
532
  minConcurrency,
529
533
  maxConcurrency,
530
534
  maxTasksPerMinute: maxRequestsPerMinute,
535
+ // Spread conditionally - an explicit `undefined` would clobber a subclass default, see
536
+ // `HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS`.
537
+ ...(initialConcurrency !== undefined && { desiredConcurrency: initialConcurrency }),
531
538
  log: this.log,
532
539
  }));
533
540
  }
@@ -537,7 +544,7 @@ export class BasicCrawler {
537
544
  }
538
545
  /**
539
546
  * Builds the crawler-owned default {@link ConcurrencySystem} from the resolved
540
- * `minConcurrency`/`maxConcurrency`/`maxRequestsPerMinute` shortcuts. Not called when a
547
+ * `minConcurrency`/`maxConcurrency`/`initialConcurrency`/`maxRequestsPerMinute` shortcuts. Not called when a
541
548
  * {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} was injected.
542
549
  *
543
550
  * Subclasses may override this to tune the default system (e.g. {@link HttpCrawler} raises the starting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/basic",
3
- "version": "4.0.0-beta.144",
3
+ "version": "4.0.0-beta.145",
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"
@@ -42,10 +42,10 @@
42
42
  "@apify/datastructures": "^2.0.0",
43
43
  "@apify/timeout": "^0.4.4",
44
44
  "@apify/utilities": "^2.15.5",
45
- "@crawlee/core": "4.0.0-beta.144",
46
- "@crawlee/http-client": "4.0.0-beta.144",
47
- "@crawlee/types": "4.0.0-beta.144",
48
- "@crawlee/utils": "4.0.0-beta.144",
45
+ "@crawlee/core": "4.0.0-beta.145",
46
+ "@crawlee/http-client": "4.0.0-beta.145",
47
+ "@crawlee/types": "4.0.0-beta.145",
48
+ "@crawlee/utils": "4.0.0-beta.145",
49
49
  "csv-stringify": "^6.5.2",
50
50
  "tldts": "^7.0.6",
51
51
  "tslib": "^2.8.1",
@@ -53,7 +53,7 @@
53
53
  "zod": "^4.4.3"
54
54
  },
55
55
  "optionalDependencies": {
56
- "@crawlee/impit-client": "^4.0.0-beta.144"
56
+ "@crawlee/impit-client": "^4.0.0-beta.145"
57
57
  },
58
58
  "lerna": {
59
59
  "command": {
@@ -62,5 +62,5 @@
62
62
  }
63
63
  }
64
64
  },
65
- "gitHead": "4acf68a225909523047f872cbdeb87428bfc560d"
65
+ "gitHead": "e8b4d50265b9e433ae61c69d16cc1fee00a4d7e9"
66
66
  }