@crawlee/basic 4.0.0-beta.85 → 4.0.0-beta.87

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.
@@ -1,4 +1,4 @@
1
- import type { AddRequestsBatchedOptions, AddRequestsBatchedResult, AutoscaledPoolOptions, Configuration, CrawleeLogger, CrawlingContext, DatasetExportOptions, EnqueueLinksOptions, EventManager, FinalStatistics, GetUserDataFromRequest, IProxyConfiguration, IRequestLoader, IRequestManager, Request, RequestsLike, RouterHandler, RouterRoutes, SkippedRequestCallback, Source, StatisticsOptions, StatisticState, StorageIdentifier } from '@crawlee/core';
1
+ import type { AddRequestsBatchedOptions, AddRequestsBatchedResult, AutoscaledPoolOptions, Configuration, CrawleeLogger, CrawlingContext, DatasetExportOptions, EnqueueLinksOptions, EventManager, FinalStatistics, GetUserDataFromRequest, IProxyConfiguration, IRequestLoader, IRequestManager, Request, RequestsLike, RouterHandler, RouterRoutes, SkippedRequestCallback, Source, StatisticsOptions, StatisticState, StorageIdentifier, TypedRequestsLike } from '@crawlee/core';
2
2
  import { AutoscaledPool, ContextPipeline, Dataset, RequestQueue, Statistics } from '@crawlee/core';
3
3
  import type { Awaitable, BaseHttpClient, BatchAddRequestsResult, Dictionary, ISession, ISessionPool, ProxyInfo, SetStatusMessageOptions, StorageBackend } from '@crawlee/types';
4
4
  import { RobotsTxtFile } from '@crawlee/utils';
@@ -16,17 +16,17 @@ export type RequestHandler<Context extends CrawlingContext = CrawlingContext> =
16
16
  * difference between `BaseContext` and `ExtendedContext`) are only available as a `Partial`.
17
17
  */
18
18
  export type ErrorHandler<BaseContext extends CrawlingContext = CrawlingContext, ExtendedContext extends BaseContext = BaseContext> = (inputs: BaseContext & Partial<ExtendedContext>, error: Error) => Awaitable<void>;
19
- export interface StatusMessageCallbackParams<Context extends CrawlingContext = BasicCrawlingContext, Crawler extends BasicCrawler<any> = BasicCrawler<Context>> {
19
+ export interface StatusMessageCallbackParams<Context extends CrawlingContext = BasicCrawlingContext, Crawler extends BasicCrawler<any, any, any, any> = BasicCrawler<Context>> {
20
20
  state: StatisticState;
21
21
  crawler: Crawler;
22
22
  previousState: StatisticState;
23
23
  message: string;
24
24
  }
25
- export type StatusMessageCallback<Context extends CrawlingContext = BasicCrawlingContext, Crawler extends BasicCrawler<any> = BasicCrawler<Context>> = (params: StatusMessageCallbackParams<Context, Crawler>) => Awaitable<void>;
25
+ export type StatusMessageCallback<Context extends CrawlingContext = BasicCrawlingContext, Crawler extends BasicCrawler<any, any, any, any> = BasicCrawler<Context>> = (params: StatusMessageCallbackParams<Context, Crawler>) => Awaitable<void>;
26
26
  export type RequireContextPipeline<DefaultContextType extends CrawlingContext, FinalContextType extends DefaultContextType> = DefaultContextType extends FinalContextType ? {} : {
27
27
  contextPipelineBuilder: () => ContextPipeline<CrawlingContext, FinalContextType>;
28
28
  };
29
- export interface BasicCrawlerOptions<Context extends CrawlingContext = CrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension> {
29
+ export interface BasicCrawlerOptions<Context extends CrawlingContext = CrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>> {
30
30
  /**
31
31
  * User-provided function that performs the logic of the crawler. It is called for each URL to crawl.
32
32
  *
@@ -44,7 +44,7 @@ export interface BasicCrawlerOptions<Context extends CrawlingContext = CrawlingC
44
44
  * The exceptions are logged to the request using the
45
45
  * {@link Request.pushErrorMessage|`Request.pushErrorMessage()`} function.
46
46
  */
47
- requestHandler?: RequestHandler<ExtendedContext>;
47
+ requestHandler?: RouterHandler<ExtendedContext, Routes> | RequestHandler<ExtendedContext>;
48
48
  /**
49
49
  * Allows the user to extend the crawling context with custom functionality (helpers, references, etc.).
50
50
  *
@@ -387,7 +387,7 @@ interface CrawlerIdentity {
387
387
  /** Whether `id` came from the user (as opposed to being derived from `instanceIndex`). */
388
388
  readonly hasExplicitId: boolean;
389
389
  }
390
- export declare class BasicCrawler<Context extends CrawlingContext = CrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension> {
390
+ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>> {
391
391
  #private;
392
392
  protected static readonly CRAWLEE_STATE_KEY = "CRAWLEE_STATE";
393
393
  /**
@@ -447,7 +447,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingCont
447
447
  * Default {@link Router} instance that will be used if we don't specify any {@link BasicCrawlerOptions.requestHandler|`requestHandler`}.
448
448
  * See {@link Router.addHandler|`router.addHandler()`} and {@link Router.addDefaultHandler|`router.addDefaultHandler()`}.
449
449
  */
450
- readonly router: RouterHandler<Context>;
450
+ readonly router: RouterHandler<Context, Routes>;
451
451
  private _basicContextPipeline?;
452
452
  /**
453
453
  * The basic part of the context pipeline. Unlike the subclass pipeline, this
@@ -565,7 +565,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingCont
565
565
  /**
566
566
  * All `BasicCrawler` parameters are passed via an options object.
567
567
  */
568
- constructor(options?: BasicCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<CrawlingContext, Context>);
568
+ constructor(options?: BasicCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes> & RequireContextPipeline<CrawlingContext, Context>);
569
569
  /**
570
570
  * Determines if the given HTTP status code is an error status code given
571
571
  * the default behaviour and user-set preferences.
@@ -617,7 +617,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingCont
617
617
  * @param [requests] The requests to add.
618
618
  * @param [options] Options for the request queue.
619
619
  */
620
- run(requests?: RequestsLike, options?: CrawlerRunOptions): Promise<FinalStatistics>;
620
+ run(requests?: TypedRequestsLike<Routes>, options?: CrawlerRunOptions): Promise<FinalStatistics>;
621
621
  /**
622
622
  * Gracefully stops the current run of the crawler.
623
623
  *
@@ -674,7 +674,7 @@ export declare class BasicCrawler<Context extends CrawlingContext = CrawlingCont
674
674
  * @param requests The requests to add
675
675
  * @param options Options for the request queue
676
676
  */
677
- addRequests(requests: ReadonlyDeep<RequestsLike>, options?: CrawlerAddRequestsOptions): Promise<CrawlerAddRequestsResult>;
677
+ addRequests(requests: ReadonlyDeep<TypedRequestsLike<Routes>>, options?: CrawlerAddRequestsOptions): Promise<CrawlerAddRequestsResult>;
678
678
  /**
679
679
  * Pushes data to the specified {@link Dataset}, or the default crawler {@link Dataset} by calling {@link Dataset.pushData}.
680
680
  */
@@ -643,7 +643,7 @@ export class BasicCrawler {
643
643
  await purgeDefaultStorages({
644
644
  onlyPurgeOnce: true,
645
645
  storageBackend: serviceLocator.getStorageBackend(),
646
- config: serviceLocator.getConfiguration(),
646
+ configuration: serviceLocator.getConfiguration(),
647
647
  });
648
648
  if (requests) {
649
649
  await this.addRequests(requests, addRequestsOptions);
@@ -754,7 +754,7 @@ export class BasicCrawler {
754
754
  // The first crawler instance uses the default queue (null identifier);
755
755
  // subsequent instances get their own queue via a unique alias so they don't collide.
756
756
  const identifier = this.identity.instanceIndex === 0 ? null : { alias: `__default_${this.identity.id}__` };
757
- const requestQueue = await RequestQueue.open(identifier, { config: serviceLocator.getConfiguration() });
757
+ const requestQueue = await RequestQueue.open(identifier, { configuration: serviceLocator.getConfiguration() });
758
758
  return this.ownedRequestQueue.set(requestQueue);
759
759
  }
760
760
  /**
@@ -794,7 +794,7 @@ export class BasicCrawler {
794
794
  target.userData = await validateUserData(target.label, schema, target.userData ?? {});
795
795
  }
796
796
  async useState(defaultValue = {}) {
797
- const kvs = await KeyValueStore.open(null, { config: serviceLocator.getConfiguration() });
797
+ const kvs = await KeyValueStore.open(null, { configuration: serviceLocator.getConfiguration() });
798
798
  if (this.identity.hasExplicitId) {
799
799
  const stateKey = `${BasicCrawler.CRAWLEE_STATE_KEY}_${this.identity.id}`;
800
800
  return kvs.getAutoSavedValue(stateKey, defaultValue);
@@ -913,7 +913,7 @@ export class BasicCrawler {
913
913
  */
914
914
  async getDataset(identifier) {
915
915
  return Dataset.open(identifier, {
916
- config: serviceLocator.getConfiguration(),
916
+ configuration: serviceLocator.getConfiguration(),
917
917
  });
918
918
  }
919
919
  /**
@@ -1042,7 +1042,7 @@ export class BasicCrawler {
1042
1042
  await this.requestManager.persistState().catch((err) => {
1043
1043
  if (err.message.includes('Cannot persist state.')) {
1044
1044
  this.log.error("The crawler attempted to persist its request list's state and failed due to missing or " +
1045
- 'invalid config. Make sure to use either RequestList.open() or the "stateKeyPrefix" option of RequestList ' +
1045
+ 'invalid configuration. Make sure to use either RequestList.open() or the "stateKeyPrefix" option of RequestList ' +
1046
1046
  'constructor to ensure your crawling state is persisted through host migrations and restarts.');
1047
1047
  }
1048
1048
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/basic",
3
- "version": "4.0.0-beta.85",
3
+ "version": "4.0.0-beta.87",
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.3.2",
44
44
  "@apify/utilities": "^2.15.5",
45
- "@crawlee/core": "4.0.0-beta.85",
46
- "@crawlee/http-client": "4.0.0-beta.85",
47
- "@crawlee/types": "4.0.0-beta.85",
48
- "@crawlee/utils": "4.0.0-beta.85",
45
+ "@crawlee/core": "4.0.0-beta.87",
46
+ "@crawlee/http-client": "4.0.0-beta.87",
47
+ "@crawlee/types": "4.0.0-beta.87",
48
+ "@crawlee/utils": "4.0.0-beta.87",
49
49
  "csv-stringify": "^6.5.2",
50
50
  "fs-extra": "^11.3.0",
51
51
  "ow": "^2.0.0",
@@ -54,7 +54,7 @@
54
54
  "type-fest": "^4.41.0"
55
55
  },
56
56
  "optionalDependencies": {
57
- "@crawlee/impit-client": "^4.0.0-beta.85"
57
+ "@crawlee/impit-client": "^4.0.0-beta.87"
58
58
  },
59
59
  "lerna": {
60
60
  "command": {
@@ -63,5 +63,5 @@
63
63
  }
64
64
  }
65
65
  },
66
- "gitHead": "8d6d3cd9da3dc9cb0b7822b28eb317019b6806bc"
66
+ "gitHead": "1b7604cd77b694460aac4448b4555444fa1b2bdb"
67
67
  }