@crawlee/core 4.0.0-beta.99 → 4.0.0-rc.1

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.
Files changed (133) hide show
  1. package/README.md +1 -1
  2. package/configuration.d.ts +16 -47
  3. package/configuration.js +13 -25
  4. package/debug.js +4 -4
  5. package/errors.d.ts +28 -38
  6. package/errors.js +33 -47
  7. package/events/event_manager.d.ts +2 -2
  8. package/events/event_manager.js +7 -6
  9. package/events/index.d.ts +1 -0
  10. package/events/local_event_manager.d.ts +1 -8
  11. package/events/local_event_manager.js +13 -13
  12. package/events/system_info.d.ts +38 -0
  13. package/index.d.ts +2 -8
  14. package/index.js +4 -8
  15. package/internal.d.ts +8 -0
  16. package/internal.js +9 -0
  17. package/log.d.ts +10 -11
  18. package/log.js +52 -20
  19. package/memory-storage/memory-storage.d.ts +15 -18
  20. package/memory-storage/memory-storage.js +80 -58
  21. package/memory-storage/resource-clients/dataset.d.ts +1 -6
  22. package/memory-storage/resource-clients/dataset.js +23 -31
  23. package/memory-storage/resource-clients/key-value-store.d.ts +1 -10
  24. package/memory-storage/resource-clients/key-value-store.js +43 -67
  25. package/memory-storage/resource-clients/request-queue.d.ts +1 -42
  26. package/memory-storage/resource-clients/request-queue.js +109 -117
  27. package/owned_or_injected.d.ts +1 -3
  28. package/owned_or_injected.js +17 -17
  29. package/package.json +17 -20
  30. package/proxy_configuration.d.ts +21 -26
  31. package/proxy_configuration.js +35 -25
  32. package/recoverable_state.d.ts +104 -47
  33. package/recoverable_state.js +199 -74
  34. package/request.d.ts +20 -107
  35. package/request.js +78 -244
  36. package/serialization.js +17 -16
  37. package/service_locator.d.ts +22 -10
  38. package/service_locator.js +59 -48
  39. package/storages/batched_adds.d.ts +37 -0
  40. package/storages/batched_adds.js +73 -0
  41. package/storages/dataset.d.ts +13 -8
  42. package/storages/dataset.js +149 -40
  43. package/storages/index.d.ts +4 -4
  44. package/storages/index.js +2 -4
  45. package/storages/key_value_store.d.ts +16 -35
  46. package/storages/key_value_store.js +223 -110
  47. package/storages/key_value_store_codec.js +6 -11
  48. package/storages/request_dedup_cache.d.ts +1 -4
  49. package/storages/request_dedup_cache.js +15 -15
  50. package/storages/request_list.d.ts +9 -104
  51. package/storages/request_list.js +236 -233
  52. package/storages/request_loader.d.ts +49 -18
  53. package/storages/request_loader.js +36 -1
  54. package/storages/request_manager.d.ts +86 -0
  55. package/storages/request_manager_tandem.d.ts +14 -38
  56. package/storages/request_manager_tandem.js +67 -64
  57. package/storages/request_queue.d.ts +23 -50
  58. package/storages/request_queue.js +371 -226
  59. package/storages/storage_instance_manager.d.ts +2 -4
  60. package/storages/storage_instance_manager.js +21 -21
  61. package/storages/storage_stats.d.ts +1 -1
  62. package/storages/storage_stats.js +4 -4
  63. package/storages/transaction.d.ts +270 -0
  64. package/storages/transaction.js +296 -0
  65. package/storages/utils.d.ts +6 -3
  66. package/storages/utils.js +11 -2
  67. package/system-info/runtime.js +7 -7
  68. package/url.d.ts +9 -0
  69. package/url.js +11 -0
  70. package/validators.d.ts +23 -25
  71. package/validators.js +14 -25
  72. package/autoscaling/autoscaled_pool.d.ts +0 -213
  73. package/autoscaling/autoscaled_pool.js +0 -378
  74. package/autoscaling/client_load_signal.d.ts +0 -59
  75. package/autoscaling/client_load_signal.js +0 -73
  76. package/autoscaling/concurrency_system.d.ts +0 -283
  77. package/autoscaling/concurrency_system.js +0 -350
  78. package/autoscaling/cpu_load_signal.d.ts +0 -44
  79. package/autoscaling/cpu_load_signal.js +0 -46
  80. package/autoscaling/event_loop_load_signal.d.ts +0 -54
  81. package/autoscaling/event_loop_load_signal.js +0 -60
  82. package/autoscaling/index.d.ts +0 -9
  83. package/autoscaling/index.js +0 -9
  84. package/autoscaling/load_signal.d.ts +0 -99
  85. package/autoscaling/load_signal.js +0 -103
  86. package/autoscaling/memory_load_signal.d.ts +0 -56
  87. package/autoscaling/memory_load_signal.js +0 -106
  88. package/autoscaling/snapshotter.d.ts +0 -87
  89. package/autoscaling/snapshotter.js +0 -67
  90. package/autoscaling/system_status.d.ts +0 -161
  91. package/autoscaling/system_status.js +0 -139
  92. package/autoscaling/weighted_avg.d.ts +0 -5
  93. package/autoscaling/weighted_avg.js +0 -14
  94. package/cookie_utils.d.ts +0 -44
  95. package/cookie_utils.js +0 -122
  96. package/crawlers/context_pipeline.d.ts +0 -70
  97. package/crawlers/context_pipeline.js +0 -122
  98. package/crawlers/crawler_commons.d.ts +0 -257
  99. package/crawlers/crawler_commons.js +0 -107
  100. package/crawlers/error_snapshotter.d.ts +0 -59
  101. package/crawlers/error_snapshotter.js +0 -117
  102. package/crawlers/error_tracker.d.ts +0 -54
  103. package/crawlers/error_tracker.js +0 -308
  104. package/crawlers/index.d.ts +0 -5
  105. package/crawlers/index.js +0 -5
  106. package/crawlers/internals/types.d.ts +0 -7
  107. package/crawlers/statistics.d.ts +0 -209
  108. package/crawlers/statistics.js +0 -350
  109. package/enqueue_links/enqueue_links.d.ts +0 -264
  110. package/enqueue_links/enqueue_links.js +0 -271
  111. package/enqueue_links/index.d.ts +0 -2
  112. package/enqueue_links/index.js +0 -2
  113. package/enqueue_links/shared.d.ts +0 -83
  114. package/enqueue_links/shared.js +0 -221
  115. package/router.d.ts +0 -309
  116. package/router.js +0 -309
  117. package/session_pool/consts.d.ts +0 -3
  118. package/session_pool/consts.js +0 -3
  119. package/session_pool/errors.d.ts +0 -7
  120. package/session_pool/errors.js +0 -11
  121. package/session_pool/fingerprint.d.ts +0 -9
  122. package/session_pool/fingerprint.js +0 -30
  123. package/session_pool/index.d.ts +0 -4
  124. package/session_pool/index.js +0 -4
  125. package/session_pool/session.d.ts +0 -161
  126. package/session_pool/session.js +0 -218
  127. package/session_pool/session_pool.d.ts +0 -246
  128. package/session_pool/session_pool.js +0 -386
  129. package/storages/access_checking.d.ts +0 -12
  130. package/storages/access_checking.js +0 -17
  131. package/storages/sitemap_request_loader.d.ts +0 -249
  132. package/storages/sitemap_request_loader.js +0 -432
  133. /package/{crawlers/internals/types.js → events/system_info.js} +0 -0
@@ -1,8 +1,9 @@
1
- import type { BaseHttpClient, Dictionary } from '@crawlee/types';
1
+ import type { BaseHttpClient } from '@crawlee/http-client';
2
+ import type { Dictionary } from '@crawlee/types';
2
3
  import type { Configuration } from '../configuration.js';
3
4
  import type { IProxyConfiguration } from '../proxy_configuration.js';
4
5
  import { Request, type RequestOptions, type Source } from '../request.js';
5
- import type { IRequestLoader } from './request_loader.js';
6
+ import type { IRequestLoader, RequestLoaderStatus } from './request_loader.js';
6
7
  import type { IRequestManager } from './request_manager.js';
7
8
  /** @internal */
8
9
  export declare const STATE_PERSISTENCE_KEY = "REQUEST_LIST_STATE";
@@ -126,7 +127,8 @@ export interface RequestListOptions {
126
127
  * ```
127
128
  *
128
129
  * Note that the preferred (and simpler) way to persist the state of crawling of the `RequestList`
129
- * is to use the `stateKeyPrefix` parameter instead.
130
+ * is to use the `stateKeyPrefix` parameter instead. When both are set, a record persisted under
131
+ * {@link RequestListOptions.persistStateKey} takes precedence over this option.
130
132
  */
131
133
  state?: RequestListState;
132
134
  /**
@@ -216,73 +218,29 @@ export interface RequestListOptions {
216
218
  * @category Sources
217
219
  */
218
220
  export declare class RequestList implements IRequestLoader {
219
- private log;
221
+ #private;
220
222
  /**
221
223
  * Array of all requests from all sources, in the order as they appeared in sources.
222
224
  * All requests in the array have distinct uniqueKey!
223
225
  * @internal
224
226
  */
225
227
  readonly requests: (Request | RequestOptions)[];
226
- /** Index to the next item in requests array to fetch. All previous requests are either handled or in progress. */
227
- private nextIndex;
228
- /** Dictionary, key is Request.uniqueKey, value is corresponding index in the requests array. */
229
- private uniqueKeyToIndex;
230
228
  /**
231
229
  * Set of `uniqueKey`s of requests that were returned by fetchNextRequest().
232
230
  * @internal
233
231
  */
234
- inProgress: Set<string>;
235
- /**
236
- * `uniqueKey`s of requests that were in progress when the state was last persisted and thus need to be
237
- * re-crawled after a restart. They are served before advancing through the rest of the sources.
238
- * @internal
239
- */
240
- private requestsToRetry;
241
- /**
242
- * Starts as true because until we handle the first request, the list is effectively persisted by doing nothing.
243
- * @internal
244
- */
245
- isStatePersisted: boolean;
232
+ get inProgress(): Set<string>;
246
233
  /**
247
234
  * Starts as false because we don't know yet and sources might change in the meantime (eg. download from live list).
248
235
  * @internal
249
236
  */
250
237
  areRequestsPersisted: boolean;
251
- private isLoading;
252
- private isInitialized;
253
- private persistStateKey?;
254
- private persistRequestsKey?;
255
- private initialState?;
256
- private store?;
257
- private keepDuplicateUrls;
258
- private sources;
259
- private sourcesFunction?;
260
- private proxyConfiguration?;
261
- private httpClient?;
262
238
  /**
263
239
  * To create new instance of `RequestList` we need to use `RequestList.open()` factory method.
264
240
  * @param options All `RequestList` configuration options
265
241
  * @internal
266
242
  */
267
243
  private constructor();
268
- /**
269
- * Loads all remote sources of URLs and potentially starts periodic state persistence.
270
- * This function must be called before you can start using the instance in a meaningful way.
271
- */
272
- private initialize;
273
- /**
274
- * Adds previously persisted Requests, as retrieved from the key-value store.
275
- * This needs to be done in a memory efficient way. We should update the input
276
- * to a Stream once apify-client supports streams.
277
- */
278
- private addPersistedRequests;
279
- /**
280
- * Add Requests from both options.sources and options.sourcesFunction.
281
- * This function is called only when persisted sources were not loaded.
282
- * We need to avoid keeping both sources and requests in memory
283
- * to reduce memory footprint with very large sources.
284
- */
285
- private addRequestsFromSources;
286
244
  /**
287
245
  * @inheritDoc
288
246
  */
@@ -293,21 +251,6 @@ export declare class RequestList implements IRequestLoader {
293
251
  * leaking the listener (and the requests it retains) on the shared event manager.
294
252
  */
295
253
  teardown(): Promise<void>;
296
- /**
297
- * Unlike persistState(), this is used only internally, since the sources
298
- * are automatically persisted at RequestList initialization (if the persistRequestsKey is set),
299
- * but there's no reason to persist it again afterwards, because RequestList is immutable.
300
- */
301
- private persistRequests;
302
- /**
303
- * Restores RequestList state from a state object.
304
- */
305
- private restoreState;
306
- /**
307
- * Attempts to load state and requests using the `RequestList` configuration
308
- * and returns a tuple of [state, requests] where each may be null if not loaded.
309
- */
310
- private loadStateAndPersistedRequests;
311
254
  /**
312
255
  * Returns an object representing the internal state of the `RequestList` instance.
313
256
  * Note that the object's fields can change in future releases.
@@ -316,11 +259,7 @@ export declare class RequestList implements IRequestLoader {
316
259
  /**
317
260
  * @inheritDoc
318
261
  */
319
- isEmpty(): Promise<boolean>;
320
- /**
321
- * @inheritDoc
322
- */
323
- isFinished(): Promise<boolean>;
262
+ checkReadiness(): Promise<RequestLoaderStatus>;
324
263
  /**
325
264
  * @inheritDoc
326
265
  */
@@ -329,39 +268,10 @@ export declare class RequestList implements IRequestLoader {
329
268
  * @inheritDoc
330
269
  */
331
270
  [Symbol.asyncIterator](): AsyncGenerator<Request<Dictionary>, void, unknown>;
332
- private ensureRequest;
333
271
  /**
334
272
  * @inheritDoc
335
273
  */
336
274
  markRequestAsHandled(request: Request): Promise<void>;
337
- /**
338
- * Adds all fetched requests from a URL from a remote resource.
339
- */
340
- private addFetchedRequests;
341
- private getPersistedState;
342
- /**
343
- * Fetches URLs from requestsFromUrl and returns them in format of list of requests
344
- */
345
- private fetchRequestsFromUrl;
346
- /**
347
- * Adds given request.
348
- * If the `source` parameter is a string or plain object and not an instance
349
- * of a `Request`, then the function creates a `Request` instance.
350
- */
351
- private addRequest;
352
- /**
353
- * Helper function that validates unique key.
354
- * Throws an error if uniqueKey is not a non-empty string.
355
- */
356
- private ensureUniqueKeyValid;
357
- /**
358
- * Checks that a request is currently being processed and throws an error if not.
359
- */
360
- private ensureInProgress;
361
- /**
362
- * Throws an error if request list wasn't initialized.
363
- */
364
- private ensureIsInitialized;
365
275
  /**
366
276
  * Returns the total number of unique requests present in the `RequestList`.
367
277
  */
@@ -434,10 +344,6 @@ export declare class RequestList implements IRequestLoader {
434
344
  * options and the `sources` parameter supersedes the {@link RequestListOptions.sources} option.
435
345
  */
436
346
  static open(listNameOrOptions: string | null | RequestListOptions, sources?: RequestListSource[], options?: RequestListOptions): Promise<RequestList>;
437
- /**
438
- * @internal wraps public utility for mocking purposes
439
- */
440
- private _downloadListOfUrls;
441
347
  }
442
348
  /**
443
349
  * Represents state of a {@link RequestList}. It can be used to resume a {@link RequestList} which has been previously processed.
@@ -463,6 +369,5 @@ export interface RequestListState {
463
369
  /** Array of request keys representing those that being processed at the moment. */
464
370
  inProgress: string[];
465
371
  }
466
- type RequestListSource = string | Source;
372
+ export type RequestListSource = string | Source;
467
373
  export type RequestListSourcesFunction = () => Promise<RequestListSource[]>;
468
- export {};