@crawlee/core 4.0.0-beta.26 → 4.0.0-beta.260

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 (265) hide show
  1. package/README.md +15 -15
  2. package/byte-utils.d.ts +17 -0
  3. package/byte-utils.js +42 -0
  4. package/configuration.d.ts +77 -235
  5. package/configuration.js +159 -227
  6. package/debug.d.ts +36 -0
  7. package/debug.js +70 -0
  8. package/errors.d.ts +45 -18
  9. package/errors.js +58 -27
  10. package/events/event-manager.d.ts +78 -0
  11. package/events/{event_manager.js → event-manager.js} +12 -13
  12. package/events/index.d.ts +3 -3
  13. package/events/index.js +2 -3
  14. package/events/local-event-manager.d.ts +32 -0
  15. package/events/local-event-manager.js +101 -0
  16. package/events/system-info.d.ts +38 -0
  17. package/events/system-info.js +1 -0
  18. package/index.d.ts +9 -12
  19. package/index.js +10 -11
  20. package/internal.d.ts +8 -0
  21. package/internal.js +9 -0
  22. package/iterables.d.ts +79 -0
  23. package/iterables.js +134 -0
  24. package/log.d.ts +77 -1
  25. package/log.js +134 -1
  26. package/memory-storage/consts.d.ts +4 -0
  27. package/memory-storage/consts.js +4 -0
  28. package/memory-storage/index.d.ts +1 -0
  29. package/memory-storage/index.js +1 -0
  30. package/memory-storage/memory-storage.d.ts +43 -0
  31. package/memory-storage/memory-storage.js +158 -0
  32. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  33. package/memory-storage/resource-clients/common/base-client.js +6 -0
  34. package/memory-storage/resource-clients/dataset.d.ts +35 -0
  35. package/memory-storage/resource-clients/dataset.js +108 -0
  36. package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
  37. package/memory-storage/resource-clients/key-value-store.js +179 -0
  38. package/memory-storage/resource-clients/request-queue.d.ts +55 -0
  39. package/memory-storage/resource-clients/request-queue.js +413 -0
  40. package/memory-storage/utils.d.ts +16 -0
  41. package/memory-storage/utils.js +41 -0
  42. package/owned-or-injected.d.ts +58 -0
  43. package/owned-or-injected.js +98 -0
  44. package/package.json +23 -23
  45. package/proxy-configuration.d.ts +118 -0
  46. package/proxy-configuration.js +141 -0
  47. package/recoverable-state.d.ts +177 -0
  48. package/recoverable-state.js +268 -0
  49. package/request.d.ts +48 -93
  50. package/request.js +139 -232
  51. package/serialization.d.ts +0 -1
  52. package/serialization.js +18 -18
  53. package/service-locator.d.ts +168 -0
  54. package/service-locator.js +255 -0
  55. package/storages/batched-adds.d.ts +39 -0
  56. package/storages/batched-adds.js +78 -0
  57. package/storages/dataset.d.ts +105 -58
  58. package/storages/dataset.js +292 -150
  59. package/storages/index.d.ts +11 -12
  60. package/storages/index.js +7 -12
  61. package/storages/key-value-store-codec.d.ts +32 -0
  62. package/storages/key-value-store-codec.js +108 -0
  63. package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
  64. package/storages/key-value-store.js +767 -0
  65. package/storages/request-dedup-cache.d.ts +20 -0
  66. package/storages/request-dedup-cache.js +48 -0
  67. package/storages/{request_list.d.ts → request-list.d.ts} +33 -173
  68. package/storages/{request_list.js → request-list.js} +276 -255
  69. package/storages/request-loader.d.ts +127 -0
  70. package/storages/request-loader.js +36 -0
  71. package/storages/request-manager-tandem.d.ts +82 -0
  72. package/storages/request-manager-tandem.js +200 -0
  73. package/storages/request-manager.d.ts +119 -0
  74. package/storages/request-manager.js +1 -0
  75. package/storages/{request_provider.d.ts → request-queue.d.ts} +128 -159
  76. package/storages/request-queue.js +871 -0
  77. package/storages/storage-instance-manager.d.ts +86 -0
  78. package/storages/storage-instance-manager.js +256 -0
  79. package/storages/storage-stats.d.ts +48 -0
  80. package/storages/storage-stats.js +29 -0
  81. package/storages/transaction.d.ts +270 -0
  82. package/storages/transaction.js +296 -0
  83. package/storages/utils.d.ts +59 -11
  84. package/storages/utils.js +76 -16
  85. package/system-info/cpu-info.d.ts +67 -0
  86. package/system-info/cpu-info.js +216 -0
  87. package/system-info/memory-info.d.ts +31 -0
  88. package/system-info/memory-info.js +115 -0
  89. package/system-info/ps-tree.d.ts +17 -0
  90. package/system-info/ps-tree.js +144 -0
  91. package/system-info/runtime.d.ts +14 -0
  92. package/system-info/runtime.js +80 -0
  93. package/typedefs.d.ts +0 -6
  94. package/typedefs.js +0 -1
  95. package/url.d.ts +9 -0
  96. package/url.js +11 -0
  97. package/validators.d.ts +23 -18
  98. package/validators.js +14 -18
  99. package/autoscaling/autoscaled_pool.d.ts +0 -300
  100. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  101. package/autoscaling/autoscaled_pool.js +0 -533
  102. package/autoscaling/autoscaled_pool.js.map +0 -1
  103. package/autoscaling/index.d.ts +0 -4
  104. package/autoscaling/index.d.ts.map +0 -1
  105. package/autoscaling/index.js +0 -4
  106. package/autoscaling/index.js.map +0 -1
  107. package/autoscaling/snapshotter.d.ts +0 -189
  108. package/autoscaling/snapshotter.d.ts.map +0 -1
  109. package/autoscaling/snapshotter.js +0 -285
  110. package/autoscaling/snapshotter.js.map +0 -1
  111. package/autoscaling/system_status.d.ts +0 -181
  112. package/autoscaling/system_status.d.ts.map +0 -1
  113. package/autoscaling/system_status.js +0 -169
  114. package/autoscaling/system_status.js.map +0 -1
  115. package/configuration.d.ts.map +0 -1
  116. package/configuration.js.map +0 -1
  117. package/cookie_utils.d.ts +0 -43
  118. package/cookie_utils.d.ts.map +0 -1
  119. package/cookie_utils.js +0 -111
  120. package/cookie_utils.js.map +0 -1
  121. package/crawlers/context_pipeline.d.ts +0 -61
  122. package/crawlers/context_pipeline.d.ts.map +0 -1
  123. package/crawlers/context_pipeline.js +0 -99
  124. package/crawlers/context_pipeline.js.map +0 -1
  125. package/crawlers/crawler_commons.d.ts +0 -191
  126. package/crawlers/crawler_commons.d.ts.map +0 -1
  127. package/crawlers/crawler_commons.js +0 -108
  128. package/crawlers/crawler_commons.js.map +0 -1
  129. package/crawlers/crawler_utils.d.ts +0 -10
  130. package/crawlers/crawler_utils.d.ts.map +0 -1
  131. package/crawlers/crawler_utils.js +0 -12
  132. package/crawlers/crawler_utils.js.map +0 -1
  133. package/crawlers/error_snapshotter.d.ts +0 -60
  134. package/crawlers/error_snapshotter.d.ts.map +0 -1
  135. package/crawlers/error_snapshotter.js +0 -118
  136. package/crawlers/error_snapshotter.js.map +0 -1
  137. package/crawlers/error_tracker.d.ts +0 -55
  138. package/crawlers/error_tracker.d.ts.map +0 -1
  139. package/crawlers/error_tracker.js +0 -309
  140. package/crawlers/error_tracker.js.map +0 -1
  141. package/crawlers/index.d.ts +0 -7
  142. package/crawlers/index.d.ts.map +0 -1
  143. package/crawlers/index.js +0 -7
  144. package/crawlers/index.js.map +0 -1
  145. package/crawlers/internals/types.d.ts +0 -8
  146. package/crawlers/internals/types.d.ts.map +0 -1
  147. package/crawlers/internals/types.js +0 -2
  148. package/crawlers/internals/types.js.map +0 -1
  149. package/crawlers/statistics.d.ts +0 -213
  150. package/crawlers/statistics.d.ts.map +0 -1
  151. package/crawlers/statistics.js +0 -349
  152. package/crawlers/statistics.js.map +0 -1
  153. package/enqueue_links/enqueue_links.d.ts +0 -249
  154. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  155. package/enqueue_links/enqueue_links.js +0 -269
  156. package/enqueue_links/enqueue_links.js.map +0 -1
  157. package/enqueue_links/index.d.ts +0 -3
  158. package/enqueue_links/index.d.ts.map +0 -1
  159. package/enqueue_links/index.js +0 -3
  160. package/enqueue_links/index.js.map +0 -1
  161. package/enqueue_links/shared.d.ts +0 -73
  162. package/enqueue_links/shared.d.ts.map +0 -1
  163. package/enqueue_links/shared.js +0 -212
  164. package/enqueue_links/shared.js.map +0 -1
  165. package/errors.d.ts.map +0 -1
  166. package/errors.js.map +0 -1
  167. package/events/event_manager.d.ts +0 -52
  168. package/events/event_manager.d.ts.map +0 -1
  169. package/events/event_manager.js.map +0 -1
  170. package/events/index.d.ts.map +0 -1
  171. package/events/index.js.map +0 -1
  172. package/events/local_event_manager.d.ts +0 -27
  173. package/events/local_event_manager.d.ts.map +0 -1
  174. package/events/local_event_manager.js +0 -75
  175. package/events/local_event_manager.js.map +0 -1
  176. package/index.d.ts.map +0 -1
  177. package/index.js.map +0 -1
  178. package/log.d.ts.map +0 -1
  179. package/log.js.map +0 -1
  180. package/proxy_configuration.d.ts +0 -169
  181. package/proxy_configuration.d.ts.map +0 -1
  182. package/proxy_configuration.js +0 -247
  183. package/proxy_configuration.js.map +0 -1
  184. package/recoverable_state.d.ts +0 -123
  185. package/recoverable_state.d.ts.map +0 -1
  186. package/recoverable_state.js +0 -140
  187. package/recoverable_state.js.map +0 -1
  188. package/request.d.ts.map +0 -1
  189. package/request.js.map +0 -1
  190. package/router.d.ts +0 -134
  191. package/router.d.ts.map +0 -1
  192. package/router.js +0 -164
  193. package/router.js.map +0 -1
  194. package/serialization.d.ts.map +0 -1
  195. package/serialization.js.map +0 -1
  196. package/session_pool/consts.d.ts +0 -4
  197. package/session_pool/consts.d.ts.map +0 -1
  198. package/session_pool/consts.js +0 -4
  199. package/session_pool/consts.js.map +0 -1
  200. package/session_pool/errors.d.ts +0 -8
  201. package/session_pool/errors.d.ts.map +0 -1
  202. package/session_pool/errors.js +0 -12
  203. package/session_pool/errors.js.map +0 -1
  204. package/session_pool/events.d.ts +0 -3
  205. package/session_pool/events.d.ts.map +0 -1
  206. package/session_pool/events.js +0 -3
  207. package/session_pool/events.js.map +0 -1
  208. package/session_pool/index.d.ts +0 -6
  209. package/session_pool/index.d.ts.map +0 -1
  210. package/session_pool/index.js +0 -6
  211. package/session_pool/index.js.map +0 -1
  212. package/session_pool/session.d.ts +0 -186
  213. package/session_pool/session.d.ts.map +0 -1
  214. package/session_pool/session.js +0 -278
  215. package/session_pool/session.js.map +0 -1
  216. package/session_pool/session_pool.d.ts +0 -258
  217. package/session_pool/session_pool.d.ts.map +0 -1
  218. package/session_pool/session_pool.js +0 -387
  219. package/session_pool/session_pool.js.map +0 -1
  220. package/storages/access_checking.d.ts +0 -13
  221. package/storages/access_checking.d.ts.map +0 -1
  222. package/storages/access_checking.js +0 -14
  223. package/storages/access_checking.js.map +0 -1
  224. package/storages/dataset.d.ts.map +0 -1
  225. package/storages/dataset.js.map +0 -1
  226. package/storages/index.d.ts.map +0 -1
  227. package/storages/index.js.map +0 -1
  228. package/storages/key_value_store.d.ts.map +0 -1
  229. package/storages/key_value_store.js +0 -512
  230. package/storages/key_value_store.js.map +0 -1
  231. package/storages/request_list.d.ts.map +0 -1
  232. package/storages/request_list.js.map +0 -1
  233. package/storages/request_list_adapter.d.ts +0 -58
  234. package/storages/request_list_adapter.d.ts.map +0 -1
  235. package/storages/request_list_adapter.js +0 -81
  236. package/storages/request_list_adapter.js.map +0 -1
  237. package/storages/request_manager_tandem.d.ts +0 -68
  238. package/storages/request_manager_tandem.d.ts.map +0 -1
  239. package/storages/request_manager_tandem.js +0 -124
  240. package/storages/request_manager_tandem.js.map +0 -1
  241. package/storages/request_provider.d.ts.map +0 -1
  242. package/storages/request_provider.js +0 -591
  243. package/storages/request_provider.js.map +0 -1
  244. package/storages/request_queue.d.ts +0 -128
  245. package/storages/request_queue.d.ts.map +0 -1
  246. package/storages/request_queue.js +0 -320
  247. package/storages/request_queue.js.map +0 -1
  248. package/storages/request_queue_v2.d.ts +0 -87
  249. package/storages/request_queue_v2.d.ts.map +0 -1
  250. package/storages/request_queue_v2.js +0 -438
  251. package/storages/request_queue_v2.js.map +0 -1
  252. package/storages/sitemap_request_list.d.ts +0 -250
  253. package/storages/sitemap_request_list.d.ts.map +0 -1
  254. package/storages/sitemap_request_list.js +0 -431
  255. package/storages/sitemap_request_list.js.map +0 -1
  256. package/storages/storage_manager.d.ts +0 -62
  257. package/storages/storage_manager.d.ts.map +0 -1
  258. package/storages/storage_manager.js +0 -105
  259. package/storages/storage_manager.js.map +0 -1
  260. package/storages/utils.d.ts.map +0 -1
  261. package/storages/utils.js.map +0 -1
  262. package/typedefs.d.ts.map +0 -1
  263. package/typedefs.js.map +0 -1
  264. package/validators.d.ts.map +0 -1
  265. package/validators.js.map +0 -1
@@ -1,191 +0,0 @@
1
- import type { Dictionary, HttpRequestOptions, ProxyInfo, SendRequestOptions } from '@crawlee/types';
2
- import type { ReadonlyDeep, SetRequired } from 'type-fest';
3
- import type { Configuration } from '../configuration.js';
4
- import type { EnqueueLinksOptions } from '../enqueue_links/enqueue_links.js';
5
- import type { Log } from '../log.js';
6
- import type { Request, Source } from '../request.js';
7
- import type { Session } from '../session_pool/session.js';
8
- import type { Dataset } from '../storages/dataset.js';
9
- import { KeyValueStore, type RecordOptions } from '../storages/key_value_store.js';
10
- import type { RequestQueueOperationOptions } from '../storages/request_provider.js';
11
- /** @internal */
12
- export type IsAny<T> = 0 extends 1 & T ? true : false;
13
- /** @internal */
14
- export type WithRequired<T, K extends keyof T> = T & {
15
- [P in K]-?: T[P];
16
- };
17
- export type LoadedRequest<R extends Request> = WithRequired<R, 'id' | 'loadedUrl'>;
18
- /** @internal */
19
- export type LoadedContext<Context extends RestrictedCrawlingContext> = IsAny<Context> extends true ? Context : {
20
- request: LoadedRequest<Context['request']>;
21
- } & Omit<Context, 'request'>;
22
- export interface RestrictedCrawlingContext<UserData extends Dictionary = Dictionary> {
23
- id: string;
24
- session?: Session;
25
- /**
26
- * An object with information about currently used proxy by the crawler
27
- * and configured by the {@link ProxyConfiguration} class.
28
- */
29
- proxyInfo?: ProxyInfo;
30
- /**
31
- * The original {@link Request} object.
32
- */
33
- request: Request<UserData>;
34
- /**
35
- * This function allows you to push data to a {@link Dataset} specified by name, or the one currently used by the crawler.
36
- *
37
- * Shortcut for `crawler.pushData()`.
38
- *
39
- * @param [data] Data to be pushed to the default dataset.
40
- */
41
- pushData(data: ReadonlyDeep<Parameters<Dataset['pushData']>[0]>, datasetIdOrName?: string): Promise<void>;
42
- /**
43
- * This function automatically finds and enqueues links from the current page, adding them to the {@link RequestQueue}
44
- * currently used by the crawler.
45
- *
46
- * Optionally, the function allows you to filter the target links' URLs using an array of globs or regular expressions
47
- * and override settings of the enqueued {@link Request} objects.
48
- *
49
- * Check out the [Crawl a website with relative links](https://crawlee.dev/js/docs/examples/crawl-relative-links) example
50
- * for more details regarding its usage.
51
- *
52
- * **Example usage**
53
- *
54
- * ```ts
55
- * async requestHandler({ enqueueLinks }) {
56
- * await enqueueLinks({
57
- * globs: [
58
- * 'https://www.example.com/handbags/*',
59
- * ],
60
- * });
61
- * },
62
- * ```
63
- *
64
- * @param [options] All `enqueueLinks()` parameters are passed via an options object.
65
- */
66
- enqueueLinks: (options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, 'requestQueue' | 'robotsTxtFile'>>) => Promise<unknown>;
67
- /**
68
- * Add requests directly to the request queue.
69
- *
70
- * @param requests The requests to add
71
- * @param options Options for the request queue
72
- */
73
- addRequests: (requestsLike: ReadonlyDeep<(string | Source)[]>, options?: ReadonlyDeep<RequestQueueOperationOptions>) => Promise<void>;
74
- /**
75
- * Returns the state - a piece of mutable persistent data shared across all the request handler runs.
76
- */
77
- useState: <State extends Dictionary = Dictionary>(defaultValue?: State) => Promise<State>;
78
- /**
79
- * Get a key-value store with given name or id, or the default one for the crawler.
80
- */
81
- getKeyValueStore: (idOrName?: string) => Promise<Pick<KeyValueStore, 'id' | 'name' | 'getValue' | 'getAutoSavedValue' | 'setValue' | 'getPublicUrl'>>;
82
- /**
83
- * A preconfigured logger for the request handler.
84
- */
85
- log: Log;
86
- }
87
- export interface CrawlingContext<UserData extends Dictionary = Dictionary> extends RestrictedCrawlingContext<UserData> {
88
- /**
89
- * This function automatically finds and enqueues links from the current page, adding them to the {@link RequestQueue}
90
- * currently used by the crawler.
91
- *
92
- * Optionally, the function allows you to filter the target links' URLs using an array of globs or regular expressions
93
- * and override settings of the enqueued {@link Request} objects.
94
- *
95
- * Check out the [Crawl a website with relative links](https://crawlee.dev/js/docs/examples/crawl-relative-links) example
96
- * for more details regarding its usage.
97
- *
98
- * **Example usage**
99
- *
100
- * ```ts
101
- * async requestHandler({ enqueueLinks }) {
102
- * await enqueueLinks({
103
- * globs: [
104
- * 'https://www.example.com/handbags/*',
105
- * ],
106
- * });
107
- * },
108
- * ```
109
- *
110
- * @param [options] All `enqueueLinks()` parameters are passed via an options object.
111
- * @returns Promise that resolves to {@link BatchAddRequestsResult} object.
112
- */
113
- enqueueLinks(options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, 'requestQueue' | 'robotsTxtFile'>> & Pick<EnqueueLinksOptions, 'requestQueue' | 'robotsTxtFile'>): Promise<unknown>;
114
- /**
115
- * Fires HTTP request via the internal HTTP client, allowing to override the request options on the fly.
116
- *
117
- * This is handy when you work with a browser crawler but want to execute some requests outside it (e.g. API requests).
118
- * Check the [Skipping navigations for certain requests](https://crawlee.dev/js/docs/examples/skip-navigation) example for
119
- * more detailed explanation of how to do that.
120
- *
121
- * ```ts
122
- * async requestHandler({ sendRequest }) {
123
- * const { body } = await sendRequest({
124
- * // override headers only
125
- * headers: { ... },
126
- * });
127
- * },
128
- * ```
129
- */
130
- sendRequest: (requestOverrides?: Partial<HttpRequestOptions>, optionsOverrides?: SendRequestOptions) => Promise<Response>;
131
- /**
132
- * Register a function to be called at the very end of the request handling process. This is useful for resources that should be accessible to error handlers, for instance.
133
- */
134
- registerDeferredCleanup(cleanup: () => Promise<unknown>): void;
135
- }
136
- /**
137
- * A partial implementation of {@link RestrictedCrawlingContext} that stores parameters of calls to context methods for later inspection.
138
- *
139
- * @experimental
140
- */
141
- export declare class RequestHandlerResult {
142
- private config;
143
- private crawleeStateKey;
144
- private _keyValueStoreChanges;
145
- private pushDataCalls;
146
- private addRequestsCalls;
147
- constructor(config: Configuration, crawleeStateKey: string);
148
- /**
149
- * A record of calls to {@link RestrictedCrawlingContext.pushData}, {@link RestrictedCrawlingContext.addRequests}, {@link RestrictedCrawlingContext.enqueueLinks} made by a request handler.
150
- */
151
- get calls(): ReadonlyDeep<{
152
- pushData: Parameters<RestrictedCrawlingContext['pushData']>[];
153
- addRequests: Parameters<RestrictedCrawlingContext['addRequests']>[];
154
- }>;
155
- /**
156
- * A record of changes made to key-value stores by a request handler.
157
- */
158
- get keyValueStoreChanges(): ReadonlyDeep<Record<string, Record<string, {
159
- changedValue: unknown;
160
- options?: RecordOptions;
161
- }>>>;
162
- /**
163
- * Items added to datasets by a request handler.
164
- */
165
- get datasetItems(): ReadonlyDeep<{
166
- item: Dictionary;
167
- datasetIdOrName?: string;
168
- }[]>;
169
- /**
170
- * URLs enqueued to the request queue by a request handler, either via {@link RestrictedCrawlingContext.addRequests} or {@link RestrictedCrawlingContext.enqueueLinks}
171
- */
172
- get enqueuedUrls(): ReadonlyDeep<{
173
- url: string;
174
- label?: string;
175
- }[]>;
176
- /**
177
- * URL lists enqueued to the request queue by a request handler via {@link RestrictedCrawlingContext.addRequests} using the `requestsFromUrl` option.
178
- */
179
- get enqueuedUrlLists(): ReadonlyDeep<{
180
- listUrl: string;
181
- label?: string;
182
- }[]>;
183
- pushData: RestrictedCrawlingContext['pushData'];
184
- addRequests: RestrictedCrawlingContext['addRequests'];
185
- useState: RestrictedCrawlingContext['useState'];
186
- getKeyValueStore: RestrictedCrawlingContext['getKeyValueStore'];
187
- private idOrDefault;
188
- private getKeyValueStoreChangedValue;
189
- private setKeyValueStoreChangedValue;
190
- }
191
- //# sourceMappingURL=crawler_commons.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crawler_commons.d.ts","sourceRoot":"","sources":["../../src/crawlers/crawler_commons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MA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;;OAEG;IACH,IAAI,gBAAgB,IAAI,YAAY,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAgB1E;IAED,QAAQ,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAE7C;IAEF,WAAW,EAAE,yBAAyB,CAAC,aAAa,CAAC,CAEnD;IAEF,QAAQ,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAG7C;IAEF,gBAAgB,EAAE,yBAAyB,CAAC,kBAAkB,CAAC,CAa7D;IAEF,OAAO,CAAC,WAAW,CAAwF;IAE3G,OAAO,CAAC,4BAA4B,CAIlC;IAEF,OAAO,CAAC,4BAA4B,CASlC;CACL"}
@@ -1,108 +0,0 @@
1
- import { KeyValueStore } from '../storages/key_value_store.js';
2
- /**
3
- * A partial implementation of {@link RestrictedCrawlingContext} that stores parameters of calls to context methods for later inspection.
4
- *
5
- * @experimental
6
- */
7
- export class RequestHandlerResult {
8
- config;
9
- crawleeStateKey;
10
- _keyValueStoreChanges = {};
11
- pushDataCalls = [];
12
- addRequestsCalls = [];
13
- constructor(config, crawleeStateKey) {
14
- this.config = config;
15
- this.crawleeStateKey = crawleeStateKey;
16
- }
17
- /**
18
- * A record of calls to {@link RestrictedCrawlingContext.pushData}, {@link RestrictedCrawlingContext.addRequests}, {@link RestrictedCrawlingContext.enqueueLinks} made by a request handler.
19
- */
20
- get calls() {
21
- return {
22
- pushData: this.pushDataCalls,
23
- addRequests: this.addRequestsCalls,
24
- };
25
- }
26
- /**
27
- * A record of changes made to key-value stores by a request handler.
28
- */
29
- get keyValueStoreChanges() {
30
- return this._keyValueStoreChanges;
31
- }
32
- /**
33
- * Items added to datasets by a request handler.
34
- */
35
- get datasetItems() {
36
- return this.pushDataCalls.flatMap(([data, datasetIdOrName]) => (Array.isArray(data) ? data : [data]).map((item) => ({ item, datasetIdOrName })));
37
- }
38
- /**
39
- * URLs enqueued to the request queue by a request handler, either via {@link RestrictedCrawlingContext.addRequests} or {@link RestrictedCrawlingContext.enqueueLinks}
40
- */
41
- get enqueuedUrls() {
42
- const result = [];
43
- for (const [requests] of this.addRequestsCalls) {
44
- for (const request of requests) {
45
- if (typeof request === 'object' &&
46
- (!('requestsFromUrl' in request) || request.requestsFromUrl !== undefined) &&
47
- request.url !== undefined) {
48
- result.push({ url: request.url, label: request.label });
49
- }
50
- else if (typeof request === 'string') {
51
- result.push({ url: request });
52
- }
53
- }
54
- }
55
- return result;
56
- }
57
- /**
58
- * URL lists enqueued to the request queue by a request handler via {@link RestrictedCrawlingContext.addRequests} using the `requestsFromUrl` option.
59
- */
60
- get enqueuedUrlLists() {
61
- const result = [];
62
- for (const [requests] of this.addRequestsCalls) {
63
- for (const request of requests) {
64
- if (typeof request === 'object' &&
65
- 'requestsFromUrl' in request &&
66
- request.requestsFromUrl !== undefined) {
67
- result.push({ listUrl: request.requestsFromUrl, label: request.label });
68
- }
69
- }
70
- }
71
- return result;
72
- }
73
- pushData = async (data, datasetIdOrName) => {
74
- this.pushDataCalls.push([data, datasetIdOrName]);
75
- };
76
- addRequests = async (requests, options = {}) => {
77
- this.addRequestsCalls.push([requests, options]);
78
- };
79
- useState = async (defaultValue) => {
80
- const store = await this.getKeyValueStore(undefined);
81
- return await store.getAutoSavedValue(this.crawleeStateKey, defaultValue);
82
- };
83
- getKeyValueStore = async (idOrName) => {
84
- const store = await KeyValueStore.open(idOrName, { config: this.config });
85
- return {
86
- id: this.idOrDefault(idOrName),
87
- name: idOrName,
88
- getValue: async (key) => this.getKeyValueStoreChangedValue(idOrName, key) ?? (await store.getValue(key)),
89
- setValue: async (key, value, options) => {
90
- this.setKeyValueStoreChangedValue(idOrName, key, value, options);
91
- },
92
- getAutoSavedValue: store.getAutoSavedValue.bind(store),
93
- getPublicUrl: store.getPublicUrl.bind(store),
94
- };
95
- };
96
- idOrDefault = (idOrName) => idOrName ?? this.config.get('defaultKeyValueStoreId');
97
- getKeyValueStoreChangedValue = (idOrName, key) => {
98
- const id = this.idOrDefault(idOrName);
99
- this._keyValueStoreChanges[id] ??= {};
100
- return this.keyValueStoreChanges[id][key]?.changedValue ?? null;
101
- };
102
- setKeyValueStoreChangedValue = (idOrName, key, changedValue, options) => {
103
- const id = this.idOrDefault(idOrName);
104
- this._keyValueStoreChanges[id] ??= {};
105
- this._keyValueStoreChanges[id][key] = { changedValue, options };
106
- };
107
- }
108
- //# sourceMappingURL=crawler_commons.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crawler_commons.js","sourceRoot":"","sources":["../../src/crawlers/crawler_commons.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAsB,MAAM,gCAAgC,CAAC;AA6JnF;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IASjB;IACA;IATJ,qBAAqB,GACzB,EAAE,CAAC;IAEC,aAAa,GAAwD,EAAE,CAAC;IAExE,gBAAgB,GAA2D,EAAE,CAAC;IAEtF,YACY,MAAqB,EACrB,eAAuB;QADvB,WAAM,GAAN,MAAM,CAAe;QACrB,oBAAe,GAAf,eAAe,CAAQ;IAChC,CAAC;IAEJ;;OAEG;IACH,IAAI,KAAK;QAIL,OAAO;YACH,QAAQ,EAAE,IAAI,CAAC,aAAa;YAC5B,WAAW,EAAE,IAAI,CAAC,gBAAgB;SACrC,CAAC;IACN,CAAC;IAED;;OAEG;IACH,IAAI,oBAAoB;QAGpB,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,EAAE,CAC1D,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,EA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AC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC;YACtD,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;SAC/C,CAAC;IACN,CAAC,CAAC;IAEM,WAAW,GAAG,CAAC,QAAiB,EAAU,EAAE,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAEnG,4BAA4B,GAAG,CAAC,QAA4B,EAAE,GAAW,EAAE,EAAE;QACjF,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,IAAI,IAAI,CAAC;IACpE,CAAC,CAAC;IAEM,4BAA4B,GAAG,CACnC,QAA4B,EAC5B,GAAW,EACX,YAAqB,EACrB,OAAuB,EACzB,EAAE;QACA,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;IACpE,CAAC,CAAC;CACL"}
@@ -1,10 +0,0 @@
1
- import type { Session } from '../session_pool/session.js';
2
- /**
3
- * Handles timeout request
4
- * @internal
5
- */
6
- export declare function handleRequestTimeout({ session, errorMessage }: {
7
- session?: Session;
8
- errorMessage: string;
9
- }): void;
10
- //# sourceMappingURL=crawler_utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crawler_utils.d.ts","sourceRoot":"","sources":["../../src/crawlers/crawler_utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,QAK1G"}
@@ -1,12 +0,0 @@
1
- import { TimeoutError } from '@apify/timeout';
2
- /**
3
- * Handles timeout request
4
- * @internal
5
- */
6
- export function handleRequestTimeout({ session, errorMessage }) {
7
- session?.markBad();
8
- const timeoutMillis = errorMessage.match(/(\d+)\s?ms/)?.[1]; // first capturing group
9
- const timeoutSecs = Number(timeoutMillis) / 1000;
10
- throw new TimeoutError(`Navigation timed out after ${timeoutSecs} seconds.`);
11
- }
12
- //# sourceMappingURL=crawler_utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crawler_utils.js","sourceRoot":"","sources":["../../src/crawlers/crawler_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,OAAO,EAAE,YAAY,EAA+C;IACvG,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,wBAAwB;IACrF,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IACjD,MAAM,IAAI,YAAY,CAAC,8BAA8B,WAAW,WAAW,CAAC,CAAC;AACjF,CAAC"}
@@ -1,60 +0,0 @@
1
- import type { CrawlingContext } from '../crawlers/crawler_commons.js';
2
- import type { KeyValueStore } from '../storages/key_value_store.js';
3
- import type { ErrnoException } from './error_tracker.js';
4
- import type { SnapshottableProperties } from './internals/types.js';
5
- interface BrowserCrawlingContext {
6
- saveSnapshot: (options: {
7
- key: string;
8
- }) => Promise<void>;
9
- }
10
- export interface SnapshotResult {
11
- screenshotFileName?: string;
12
- htmlFileName?: string;
13
- }
14
- interface ErrorSnapshot {
15
- screenshotFileName?: string;
16
- screenshotFileUrl?: string;
17
- htmlFileName?: string;
18
- htmlFileUrl?: string;
19
- }
20
- /**
21
- * ErrorSnapshotter class is used to capture a screenshot of the page and a snapshot of the HTML when an error occurs during web crawling.
22
- *
23
- * This functionality is opt-in, and can be enabled via the crawler options:
24
- *
25
- * ```ts
26
- * const crawler = new BasicCrawler({
27
- * // ...
28
- * statisticsOptions: {
29
- * saveErrorSnapshots: true,
30
- * },
31
- * });
32
- * ```
33
- */
34
- export declare class ErrorSnapshotter {
35
- static readonly MAX_ERROR_CHARACTERS = 30;
36
- static readonly MAX_HASH_LENGTH = 30;
37
- static readonly MAX_FILENAME_LENGTH = 250;
38
- static readonly BASE_MESSAGE = "An error occurred";
39
- static readonly SNAPSHOT_PREFIX = "ERROR_SNAPSHOT";
40
- /**
41
- * Capture a snapshot of the error context.
42
- */
43
- captureSnapshot(error: ErrnoException, context: CrawlingContext & SnapshottableProperties): Promise<ErrorSnapshot>;
44
- /**
45
- * Captures a snapshot of the current page using the context.saveSnapshot function.
46
- * This function is applicable for browser contexts only.
47
- * Returns an object containing the filenames of the screenshot and HTML file.
48
- */
49
- contextCaptureSnapshot(context: BrowserCrawlingContext, fileName: string): Promise<SnapshotResult | undefined>;
50
- /**
51
- * Save the HTML snapshot of the page, and return the fileName with the extension.
52
- */
53
- saveHTMLSnapshot(html: string, keyValueStore: Pick<KeyValueStore, 'setValue'>, fileName: string): Promise<string | undefined>;
54
- /**
55
- * Generate a unique fileName for each error snapshot.
56
- */
57
- generateFilename(error: ErrnoException): string;
58
- }
59
- export {};
60
- //# sourceMappingURL=error_snapshotter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error_snapshotter.d.ts","sourceRoot":"","sources":["../../src/crawlers/error_snapshotter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,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Q,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAS9B;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM;CAyBlD"}
@@ -1,118 +0,0 @@
1
- import crypto from 'node:crypto';
2
- /**
3
- * ErrorSnapshotter class is used to capture a screenshot of the page and a snapshot of the HTML when an error occurs during web crawling.
4
- *
5
- * This functionality is opt-in, and can be enabled via the crawler options:
6
- *
7
- * ```ts
8
- * const crawler = new BasicCrawler({
9
- * // ...
10
- * statisticsOptions: {
11
- * saveErrorSnapshots: true,
12
- * },
13
- * });
14
- * ```
15
- */
16
- export class ErrorSnapshotter {
17
- static MAX_ERROR_CHARACTERS = 30;
18
- static MAX_HASH_LENGTH = 30;
19
- static MAX_FILENAME_LENGTH = 250;
20
- static BASE_MESSAGE = 'An error occurred';
21
- static SNAPSHOT_PREFIX = 'ERROR_SNAPSHOT';
22
- /**
23
- * Capture a snapshot of the error context.
24
- */
25
- async captureSnapshot(error, context) {
26
- try {
27
- const page = context?.page;
28
- const body = context?.body;
29
- const keyValueStore = await context?.getKeyValueStore();
30
- // If the key-value store is not available, or the body and page are not available, return empty filenames
31
- if (!keyValueStore || (!body && !page)) {
32
- return {};
33
- }
34
- const fileName = this.generateFilename(error);
35
- let screenshotFileName;
36
- let htmlFileName;
37
- if (page) {
38
- const capturedFiles = await this.contextCaptureSnapshot(context, fileName);
39
- if (capturedFiles) {
40
- screenshotFileName = capturedFiles.screenshotFileName;
41
- htmlFileName = capturedFiles.htmlFileName;
42
- }
43
- // If the snapshot for browsers failed to capture the HTML, try to capture it from the page content
44
- if (!htmlFileName) {
45
- const html = await page.content();
46
- htmlFileName = html ? await this.saveHTMLSnapshot(html, keyValueStore, fileName) : undefined;
47
- }
48
- }
49
- else if (typeof body === 'string') {
50
- // for non-browser contexts
51
- htmlFileName = await this.saveHTMLSnapshot(body, keyValueStore, fileName);
52
- }
53
- return {
54
- screenshotFileName,
55
- screenshotFileUrl: screenshotFileName && (await keyValueStore.getPublicUrl(screenshotFileName)),
56
- htmlFileName,
57
- htmlFileUrl: htmlFileName && (await keyValueStore.getPublicUrl(htmlFileName)),
58
- };
59
- }
60
- catch {
61
- return {};
62
- }
63
- }
64
- /**
65
- * Captures a snapshot of the current page using the context.saveSnapshot function.
66
- * This function is applicable for browser contexts only.
67
- * Returns an object containing the filenames of the screenshot and HTML file.
68
- */
69
- async contextCaptureSnapshot(context, fileName) {
70
- try {
71
- await context.saveSnapshot({ key: fileName });
72
- return {
73
- screenshotFileName: `${fileName}.jpg`,
74
- htmlFileName: `${fileName}.html`,
75
- };
76
- }
77
- catch {
78
- return undefined;
79
- }
80
- }
81
- /**
82
- * Save the HTML snapshot of the page, and return the fileName with the extension.
83
- */
84
- async saveHTMLSnapshot(html, keyValueStore, fileName) {
85
- try {
86
- await keyValueStore.setValue(fileName, html, { contentType: 'text/html' });
87
- return `${fileName}.html`;
88
- }
89
- catch {
90
- return undefined;
91
- }
92
- }
93
- /**
94
- * Generate a unique fileName for each error snapshot.
95
- */
96
- generateFilename(error) {
97
- const { SNAPSHOT_PREFIX, BASE_MESSAGE, MAX_HASH_LENGTH, MAX_ERROR_CHARACTERS, MAX_FILENAME_LENGTH } = ErrorSnapshotter;
98
- // Create a hash of the error stack trace
99
- const errorStackHash = crypto
100
- .createHash('sha1')
101
- .update(error.stack || error.message || '')
102
- .digest('hex')
103
- .slice(0, MAX_HASH_LENGTH);
104
- const errorMessagePrefix = (error.message || BASE_MESSAGE).slice(0, MAX_ERROR_CHARACTERS).trim();
105
- /**
106
- * Remove non-word characters from the start and end of a string.
107
- */
108
- const sanitizeString = (str) => {
109
- return str.replace(/^\W+|\W+$/g, '');
110
- };
111
- // Generate fileName and remove disallowed characters
112
- const fileName = `${SNAPSHOT_PREFIX}_${sanitizeString(errorStackHash)}_${sanitizeString(errorMessagePrefix)}`
113
- .replace(/\W+/g, '-') // Replace non-word characters with a dash
114
- .slice(0, MAX_FILENAME_LENGTH);
115
- return fileName;
116
- }
117
- }
118
- //# sourceMappingURL=error_snapshotter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error_snapshotter.js","sourceRoot":"","sources":["../../src/crawlers/error_snapshotter.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAwBjC;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,gBAAgB;IACzB,MAAM,CAAU,oBAAoB,GAAG,EAAE,CAAC;IAC1C,MAAM,CAAU,eAAe,GAAG,EAAE,CAAC;IACrC,MAAM,CAAU,mBAAmB,GAAG,GAAG,CAAC;IAC1C,MAAM,CAAU,YAAY,GAAG,mBAAmB,CAAC;IACnD,MAAM,CAAU,eAAe,GAAG,gBAAgB,CAAC;IAEnD;;OAEG;IACH,KAAK,CAAC,eAAe,CACjB,KAAqB,EACrB,OAAkD;QAElD,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;YAC3B,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;YAE3B,MAAM,aAAa,GAAG,MAAM,OAAO,EAAE,gBAAgB,EAAE,CAAC;YACxD,0GAA0G;YAC1G,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrC,OAAO,EAAE,CAAC;YACd,CAAC;YAED,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAE9C,IAAI,kBAAsC,CAAC;YAC3C,IAAI,YAAgC,CAAC;YAErC,IAAI,IAAI,EAAE,CAAC;gBACP,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,sBAAsB,CACnD,OAA4C,EAC5C,QAAQ,CACX,CAAC;gBAEF,IAAI,aAAa,EAAE,CAAC;oBAChB,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,CAAC;oBACtD,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC;gBAC9C,CAAC;gBAED,mGA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EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;YAC3E,OAAO,GAAG,QAAQ,OAAO,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,KAAqB;QAClC,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,GAC/F,gBAAgB,CAAC;QACrB,yCAAyC;QACzC,MAAM,cAAc,GAAG,MAAM;aACxB,UAAU,CAAC,MAAM,CAAC;aAClB,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;aAC1C,MAAM,CAAC,KAAK,CAAC;aACb,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;QAC/B,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,IAAI,EAAE,CAAC;QAEjG;;WAEG;QACH,MAAM,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;YAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC;QAEF,qDAAqD;QACrD,MAAM,QAAQ,GAAG,GAAG,eAAe,IAAI,cAAc,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,kBAAkB,CAAC,EAAE;aACxG,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,0CAA0C;aAC/D,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;QAEnC,OAAO,QAAQ,CAAC;IACpB,CAAC"}
@@ -1,55 +0,0 @@
1
- import type { CrawlingContext } from '../crawlers/crawler_commons.js';
2
- import { ErrorSnapshotter } from './error_snapshotter.js';
3
- import type { SnapshottableProperties } from './internals/types.js';
4
- /**
5
- * Node.js Error interface
6
- */
7
- export interface ErrnoException extends Error {
8
- errno?: number;
9
- code?: string | number;
10
- path?: string;
11
- syscall?: string;
12
- cause?: any;
13
- }
14
- export interface ErrorTrackerOptions {
15
- showErrorCode: boolean;
16
- showErrorName: boolean;
17
- showStackTrace: boolean;
18
- showFullStack: boolean;
19
- showErrorMessage: boolean;
20
- showFullMessage: boolean;
21
- saveErrorSnapshots: boolean;
22
- }
23
- /**
24
- * This class tracks errors and computes a summary of information like:
25
- * - where the errors happened
26
- * - what the error names are
27
- * - what the error codes are
28
- * - what is the general error message
29
- *
30
- * This is extremely useful when there are dynamic error messages, such as argument validation.
31
- *
32
- * Since the structure of the `tracker.result` object differs when using different options,
33
- * it's typed as `Record<string, unknown>`. The most deep object has a `count` property, which is a number.
34
- *
35
- * It's possible to get the total amount of errors via the `tracker.total` property.
36
- */
37
- export declare class ErrorTracker {
38
- #private;
39
- result: Record<string, unknown>;
40
- total: number;
41
- errorSnapshotter?: ErrorSnapshotter;
42
- constructor(options?: Partial<ErrorTrackerOptions>);
43
- private updateGroup;
44
- add(error: ErrnoException): void;
45
- /**
46
- * This method is async, because it captures a snapshot of the error context.
47
- * We added this new method to avoid breaking changes.
48
- */
49
- addAsync(error: ErrnoException, context?: CrawlingContext): Promise<void>;
50
- getUniqueErrorCount(): number;
51
- getMostPopularErrors(count: number): [number, string[]][];
52
- captureSnapshot(storage: Record<string, unknown>, error: ErrnoException, context: CrawlingContext & SnapshottableProperties): Promise<void>;
53
- reset(): void;
54
- }
55
- //# sourceMappingURL=error_tracker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error_tracker.d.ts","sourceRoot":"","sources":["../../src/crawlers/error_tracker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,s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