@crawlee/core 4.0.0-beta.17 → 4.0.0-beta.170

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 (287) hide show
  1. package/README.md +14 -14
  2. package/autoscaling/autoscaled_pool.d.ts +73 -177
  3. package/autoscaling/autoscaled_pool.js +182 -329
  4. package/autoscaling/concurrency_system.d.ts +268 -0
  5. package/autoscaling/concurrency_system.js +364 -0
  6. package/autoscaling/cpu_load_signal.d.ts +43 -0
  7. package/autoscaling/cpu_load_signal.js +47 -0
  8. package/autoscaling/event_loop_load_signal.d.ts +51 -0
  9. package/autoscaling/event_loop_load_signal.js +60 -0
  10. package/autoscaling/index.d.ts +6 -1
  11. package/autoscaling/index.js +6 -1
  12. package/autoscaling/load_signal.d.ts +98 -0
  13. package/autoscaling/load_signal.js +103 -0
  14. package/autoscaling/memory_load_signal.d.ts +47 -0
  15. package/autoscaling/memory_load_signal.js +106 -0
  16. package/autoscaling/snapshotter.d.ts +58 -163
  17. package/autoscaling/snapshotter.js +45 -263
  18. package/autoscaling/storage_backend_load_signal.d.ts +56 -0
  19. package/autoscaling/storage_backend_load_signal.js +73 -0
  20. package/autoscaling/system_status.d.ts +70 -92
  21. package/autoscaling/system_status.js +92 -122
  22. package/autoscaling/weighted_avg.d.ts +5 -0
  23. package/autoscaling/weighted_avg.js +14 -0
  24. package/byte_utils.d.ts +17 -0
  25. package/byte_utils.js +42 -0
  26. package/configuration.d.ts +96 -223
  27. package/configuration.js +170 -222
  28. package/cookie_utils.d.ts +3 -2
  29. package/cookie_utils.js +18 -7
  30. package/crawlers/context_pipeline.d.ts +10 -1
  31. package/crawlers/context_pipeline.js +31 -8
  32. package/crawlers/crawler_commons.d.ts +128 -124
  33. package/crawlers/crawler_commons.js +1 -108
  34. package/crawlers/error_snapshotter.d.ts +2 -5
  35. package/crawlers/error_snapshotter.js +5 -6
  36. package/crawlers/error_tracker.d.ts +0 -1
  37. package/crawlers/error_tracker.js +0 -1
  38. package/crawlers/index.d.ts +1 -3
  39. package/crawlers/index.js +0 -3
  40. package/crawlers/internals/types.d.ts +0 -1
  41. package/crawlers/internals/types.js +0 -1
  42. package/crawlers/statistics.d.ts +194 -79
  43. package/crawlers/statistics.js +382 -201
  44. package/debug.d.ts +36 -0
  45. package/debug.js +70 -0
  46. package/enqueue_links/enqueue_links.d.ts +61 -154
  47. package/enqueue_links/enqueue_links.js +40 -232
  48. package/enqueue_links/index.d.ts +0 -1
  49. package/enqueue_links/index.js +0 -1
  50. package/enqueue_links/shared.d.ts +55 -28
  51. package/enqueue_links/shared.js +116 -69
  52. package/errors.d.ts +82 -4
  53. package/errors.js +101 -5
  54. package/events/event_manager.d.ts +35 -9
  55. package/events/event_manager.js +12 -13
  56. package/events/index.d.ts +0 -1
  57. package/events/index.js +0 -1
  58. package/events/local_event_manager.d.ts +15 -3
  59. package/events/local_event_manager.js +39 -13
  60. package/http.d.ts +9 -0
  61. package/http.js +28 -0
  62. package/index.d.ts +7 -5
  63. package/index.js +8 -4
  64. package/iterables.d.ts +79 -0
  65. package/iterables.js +134 -0
  66. package/log.d.ts +77 -1
  67. package/log.js +134 -1
  68. package/memory-storage/consts.d.ts +4 -0
  69. package/memory-storage/consts.js +4 -0
  70. package/memory-storage/index.d.ts +1 -0
  71. package/memory-storage/index.js +1 -0
  72. package/memory-storage/memory-storage.d.ts +44 -0
  73. package/memory-storage/memory-storage.js +160 -0
  74. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  75. package/memory-storage/resource-clients/common/base-client.js +6 -0
  76. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  77. package/memory-storage/resource-clients/dataset.js +106 -0
  78. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  79. package/memory-storage/resource-clients/key-value-store.js +199 -0
  80. package/memory-storage/resource-clients/request-queue.d.ts +77 -0
  81. package/memory-storage/resource-clients/request-queue.js +414 -0
  82. package/memory-storage/utils.d.ts +16 -0
  83. package/memory-storage/utils.js +41 -0
  84. package/owned_or_injected.d.ts +58 -0
  85. package/owned_or_injected.js +98 -0
  86. package/package.json +17 -16
  87. package/proxy_configuration.d.ts +22 -128
  88. package/proxy_configuration.js +32 -144
  89. package/recoverable_state.d.ts +84 -51
  90. package/recoverable_state.js +175 -72
  91. package/request.d.ts +57 -16
  92. package/request.js +130 -69
  93. package/router.d.ts +193 -21
  94. package/router.js +188 -43
  95. package/serialization.d.ts +0 -1
  96. package/serialization.js +15 -15
  97. package/service_locator.d.ts +165 -0
  98. package/service_locator.js +253 -0
  99. package/session_pool/consts.d.ts +1 -2
  100. package/session_pool/consts.js +1 -2
  101. package/session_pool/errors.d.ts +0 -1
  102. package/session_pool/errors.js +0 -1
  103. package/session_pool/fingerprint.d.ts +9 -0
  104. package/session_pool/fingerprint.js +30 -0
  105. package/session_pool/index.d.ts +0 -2
  106. package/session_pool/index.js +0 -2
  107. package/session_pool/session.d.ts +40 -90
  108. package/session_pool/session.js +103 -160
  109. package/session_pool/session_pool.d.ts +85 -101
  110. package/session_pool/session_pool.js +254 -210
  111. package/storages/batched_adds.d.ts +37 -0
  112. package/storages/batched_adds.js +73 -0
  113. package/storages/dataset.d.ts +114 -56
  114. package/storages/dataset.js +292 -149
  115. package/storages/index.d.ts +9 -9
  116. package/storages/index.js +7 -9
  117. package/storages/key_value_store.d.ts +186 -48
  118. package/storages/key_value_store.js +452 -170
  119. package/storages/key_value_store_codec.d.ts +32 -0
  120. package/storages/key_value_store_codec.js +113 -0
  121. package/storages/request_dedup_cache.d.ts +22 -0
  122. package/storages/request_dedup_cache.js +48 -0
  123. package/storages/request_list.d.ts +54 -129
  124. package/storages/request_list.js +272 -245
  125. package/storages/request_loader.d.ts +133 -0
  126. package/storages/request_loader.js +36 -0
  127. package/storages/request_manager.d.ts +109 -0
  128. package/storages/request_manager.js +1 -0
  129. package/storages/request_manager_tandem.d.ts +55 -23
  130. package/storages/request_manager_tandem.js +139 -57
  131. package/storages/request_queue.d.ts +286 -48
  132. package/storages/request_queue.js +757 -218
  133. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +43 -91
  134. package/storages/sitemap_request_loader.js +439 -0
  135. package/storages/storage_instance_manager.d.ts +87 -0
  136. package/storages/storage_instance_manager.js +256 -0
  137. package/storages/storage_stats.d.ts +48 -0
  138. package/storages/storage_stats.js +29 -0
  139. package/storages/throttling_request_manager.d.ts +223 -0
  140. package/storages/throttling_request_manager.js +835 -0
  141. package/storages/transaction.d.ts +260 -0
  142. package/storages/transaction.js +287 -0
  143. package/storages/utils.d.ts +59 -11
  144. package/storages/utils.js +75 -15
  145. package/system-info/cpu-info.d.ts +67 -0
  146. package/system-info/cpu-info.js +216 -0
  147. package/system-info/memory-info.d.ts +31 -0
  148. package/system-info/memory-info.js +115 -0
  149. package/system-info/ps-tree.d.ts +17 -0
  150. package/system-info/ps-tree.js +144 -0
  151. package/system-info/runtime.d.ts +14 -0
  152. package/system-info/runtime.js +80 -0
  153. package/typedefs.d.ts +0 -6
  154. package/typedefs.js +0 -1
  155. package/url.d.ts +9 -0
  156. package/url.js +11 -0
  157. package/validators.d.ts +23 -18
  158. package/validators.js +14 -18
  159. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  160. package/autoscaling/autoscaled_pool.js.map +0 -1
  161. package/autoscaling/index.d.ts.map +0 -1
  162. package/autoscaling/index.js.map +0 -1
  163. package/autoscaling/snapshotter.d.ts.map +0 -1
  164. package/autoscaling/snapshotter.js.map +0 -1
  165. package/autoscaling/system_status.d.ts.map +0 -1
  166. package/autoscaling/system_status.js.map +0 -1
  167. package/configuration.d.ts.map +0 -1
  168. package/configuration.js.map +0 -1
  169. package/cookie_utils.d.ts.map +0 -1
  170. package/cookie_utils.js.map +0 -1
  171. package/crawlers/context_pipeline.d.ts.map +0 -1
  172. package/crawlers/context_pipeline.js.map +0 -1
  173. package/crawlers/crawler_commons.d.ts.map +0 -1
  174. package/crawlers/crawler_commons.js.map +0 -1
  175. package/crawlers/crawler_utils.d.ts +0 -10
  176. package/crawlers/crawler_utils.d.ts.map +0 -1
  177. package/crawlers/crawler_utils.js +0 -12
  178. package/crawlers/crawler_utils.js.map +0 -1
  179. package/crawlers/error_snapshotter.d.ts.map +0 -1
  180. package/crawlers/error_snapshotter.js.map +0 -1
  181. package/crawlers/error_tracker.d.ts.map +0 -1
  182. package/crawlers/error_tracker.js.map +0 -1
  183. package/crawlers/index.d.ts.map +0 -1
  184. package/crawlers/index.js.map +0 -1
  185. package/crawlers/internals/types.d.ts.map +0 -1
  186. package/crawlers/internals/types.js.map +0 -1
  187. package/crawlers/statistics.d.ts.map +0 -1
  188. package/crawlers/statistics.js.map +0 -1
  189. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  190. package/enqueue_links/enqueue_links.js.map +0 -1
  191. package/enqueue_links/index.d.ts.map +0 -1
  192. package/enqueue_links/index.js.map +0 -1
  193. package/enqueue_links/shared.d.ts.map +0 -1
  194. package/enqueue_links/shared.js.map +0 -1
  195. package/errors.d.ts.map +0 -1
  196. package/errors.js.map +0 -1
  197. package/events/event_manager.d.ts.map +0 -1
  198. package/events/event_manager.js.map +0 -1
  199. package/events/index.d.ts.map +0 -1
  200. package/events/index.js.map +0 -1
  201. package/events/local_event_manager.d.ts.map +0 -1
  202. package/events/local_event_manager.js.map +0 -1
  203. package/http_clients/base-http-client.d.ts +0 -140
  204. package/http_clients/base-http-client.d.ts.map +0 -1
  205. package/http_clients/base-http-client.js +0 -40
  206. package/http_clients/base-http-client.js.map +0 -1
  207. package/http_clients/form-data-like.d.ts +0 -67
  208. package/http_clients/form-data-like.d.ts.map +0 -1
  209. package/http_clients/form-data-like.js +0 -5
  210. package/http_clients/form-data-like.js.map +0 -1
  211. package/http_clients/got-scraping-http-client.d.ts +0 -20
  212. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  213. package/http_clients/got-scraping-http-client.js +0 -85
  214. package/http_clients/got-scraping-http-client.js.map +0 -1
  215. package/http_clients/index.d.ts +0 -3
  216. package/http_clients/index.d.ts.map +0 -1
  217. package/http_clients/index.js +0 -3
  218. package/http_clients/index.js.map +0 -1
  219. package/index.d.ts.map +0 -1
  220. package/index.js.map +0 -1
  221. package/log.d.ts.map +0 -1
  222. package/log.js.map +0 -1
  223. package/proxy_configuration.d.ts.map +0 -1
  224. package/proxy_configuration.js.map +0 -1
  225. package/recoverable_state.d.ts.map +0 -1
  226. package/recoverable_state.js.map +0 -1
  227. package/request.d.ts.map +0 -1
  228. package/request.js.map +0 -1
  229. package/router.d.ts.map +0 -1
  230. package/router.js.map +0 -1
  231. package/serialization.d.ts.map +0 -1
  232. package/serialization.js.map +0 -1
  233. package/session_pool/consts.d.ts.map +0 -1
  234. package/session_pool/consts.js.map +0 -1
  235. package/session_pool/errors.d.ts.map +0 -1
  236. package/session_pool/errors.js.map +0 -1
  237. package/session_pool/events.d.ts +0 -3
  238. package/session_pool/events.d.ts.map +0 -1
  239. package/session_pool/events.js +0 -3
  240. package/session_pool/events.js.map +0 -1
  241. package/session_pool/index.d.ts.map +0 -1
  242. package/session_pool/index.js.map +0 -1
  243. package/session_pool/session.d.ts.map +0 -1
  244. package/session_pool/session.js.map +0 -1
  245. package/session_pool/session_pool.d.ts.map +0 -1
  246. package/session_pool/session_pool.js.map +0 -1
  247. package/storages/access_checking.d.ts +0 -13
  248. package/storages/access_checking.d.ts.map +0 -1
  249. package/storages/access_checking.js +0 -14
  250. package/storages/access_checking.js.map +0 -1
  251. package/storages/dataset.d.ts.map +0 -1
  252. package/storages/dataset.js.map +0 -1
  253. package/storages/index.d.ts.map +0 -1
  254. package/storages/index.js.map +0 -1
  255. package/storages/key_value_store.d.ts.map +0 -1
  256. package/storages/key_value_store.js.map +0 -1
  257. package/storages/request_list.d.ts.map +0 -1
  258. package/storages/request_list.js.map +0 -1
  259. package/storages/request_list_adapter.d.ts +0 -58
  260. package/storages/request_list_adapter.d.ts.map +0 -1
  261. package/storages/request_list_adapter.js +0 -81
  262. package/storages/request_list_adapter.js.map +0 -1
  263. package/storages/request_manager_tandem.d.ts.map +0 -1
  264. package/storages/request_manager_tandem.js.map +0 -1
  265. package/storages/request_provider.d.ts +0 -371
  266. package/storages/request_provider.d.ts.map +0 -1
  267. package/storages/request_provider.js +0 -585
  268. package/storages/request_provider.js.map +0 -1
  269. package/storages/request_queue.d.ts.map +0 -1
  270. package/storages/request_queue.js.map +0 -1
  271. package/storages/request_queue_v2.d.ts +0 -87
  272. package/storages/request_queue_v2.d.ts.map +0 -1
  273. package/storages/request_queue_v2.js +0 -438
  274. package/storages/request_queue_v2.js.map +0 -1
  275. package/storages/sitemap_request_list.d.ts.map +0 -1
  276. package/storages/sitemap_request_list.js +0 -430
  277. package/storages/sitemap_request_list.js.map +0 -1
  278. package/storages/storage_manager.d.ts +0 -58
  279. package/storages/storage_manager.d.ts.map +0 -1
  280. package/storages/storage_manager.js +0 -105
  281. package/storages/storage_manager.js.map +0 -1
  282. package/storages/utils.d.ts.map +0 -1
  283. package/storages/utils.js.map +0 -1
  284. package/typedefs.d.ts.map +0 -1
  285. package/typedefs.js.map +0 -1
  286. package/validators.d.ts.map +0 -1
  287. package/validators.js.map +0 -1
@@ -1,24 +1,39 @@
1
- import { EventEmitter } from 'node:events';
2
- import type { Log } from '@apify/log';
3
- import { Configuration } from '../configuration.js';
1
+ import type { ISessionPool, SessionState } from '@crawlee/types';
2
+ import { z } from 'zod';
4
3
  import type { PersistenceOptions } from '../crawlers/statistics.js';
5
- import type { EventManager } from '../events/event_manager.js';
6
- import { KeyValueStore } from '../storages/key_value_store.js';
4
+ import type { CrawleeLogger } from '../log.js';
7
5
  import type { SessionOptions } from './session.js';
8
6
  import { Session } from './session.js';
7
+ declare const SESSION_REUSE_STRATEGIES: readonly ['random', 'round-robin', 'use-until-failure'];
8
+ export type SessionReuseStrategy = (typeof SESSION_REUSE_STRATEGIES)[number];
9
+ declare const persistedSessionPoolState: z.ZodObject<{
10
+ usableSessionsCount: z.ZodNumber;
11
+ retiredSessionsCount: z.ZodNumber;
12
+ sessions: z.ZodArray<z.ZodCustom<SessionState, SessionState>>;
13
+ }, z.core.$strip>;
14
+ /**
15
+ * The shape of the persisted {@link SessionPool} record, as returned by {@link SessionPool.getState}.
16
+ * @internal
17
+ */
18
+ export type SessionPoolPersistedState = z.infer<typeof persistedSessionPoolState>;
9
19
  /**
10
20
  * Factory user-function which creates customized {@link Session} instances.
11
21
  */
12
22
  export interface CreateSession {
13
23
  /**
14
- * @param sessionPool Pool requesting the new session.
15
- * @param options
24
+ * @param options.sessionOptions Per-call session options already merged with the pool-wide defaults.
16
25
  */
17
- (sessionPool: SessionPool, options?: {
26
+ (options?: {
18
27
  sessionOptions?: SessionOptions;
19
28
  }): Session | Promise<Session>;
20
29
  }
21
30
  export interface SessionPoolOptions {
31
+ /**
32
+ * Unique identifier for this session pool instance. Used to generate a unique
33
+ * persistence key when `persistStateKey` is not provided.
34
+ * If not provided, an auto-incrementing ID is used.
35
+ */
36
+ id?: string | number;
22
37
  /**
23
38
  * Maximum size of the pool. Indicates how many sessions are rotated.
24
39
  * @default 1000
@@ -29,24 +44,26 @@ export interface SessionPoolOptions {
29
44
  /** Name or Id of `KeyValueStore` where is the `SessionPool` state stored. */
30
45
  persistStateKeyValueStoreId?: string;
31
46
  /**
32
- * Session pool persists it's state under this key in Key value store.
33
- * @default SESSION_POOL_STATE
47
+ * Session pool persists its state under this key in Key value store.
48
+ * @default CRAWLEE_SESSION_POOL_STATE_{id}
34
49
  */
35
50
  persistStateKey?: string;
36
51
  /**
37
52
  * Custom function that should return a `Session` instance, or a promise resolving to such instance.
38
- * Any error thrown from this function will terminate the process.
39
- * Function receives `SessionPool` instance as a parameter
53
+ * Any error thrown from this function will terminate the process. Receives `{ sessionOptions }`
54
+ * already merged from the pool-wide defaults and the per-call overrides.
40
55
  */
41
56
  createSessionFunction?: CreateSession;
42
57
  /**
43
- * Specifies which response status codes are considered as blocked.
44
- * Session connected to such request will be marked as retired.
45
- * @default [401, 403, 429]
58
+ * Strategy for picking sessions from the pool.
59
+ * - `'random'` (default): fills the pool up to `maxPoolSize`, then picks a random usable session
60
+ * - `'round-robin'`: fills the pool up to `maxPoolSize`, then reuses sessions cycling through them in order
61
+ * - `'use-until-failure'`: always reuses the same session until it is retired, then moves to the next one
62
+ * @default 'random'
46
63
  */
47
- blockedStatusCodes?: number[];
64
+ sessionReuseStrategy?: SessionReuseStrategy;
48
65
  /** @internal */
49
- log?: Log;
66
+ log?: CrawleeLogger;
50
67
  /**
51
68
  * Control how and when to persist the state of the session pool.
52
69
  */
@@ -58,20 +75,8 @@ export interface SessionPoolOptions {
58
75
  * When some session is marked as blocked, it is removed and new one is created instead (the pool never returns an unusable session).
59
76
  * Learn more in the {@doclink guides/session-management | Session management guide}.
60
77
  *
61
- * You can create one by calling the {@link SessionPool.open} function.
62
- *
63
- * Session pool is already integrated into crawlers, and it can significantly improve your scraper
64
- * performance with just 2 lines of code.
65
- *
66
- * **Example usage:**
67
- *
68
- * ```javascript
69
- * const crawler = new CheerioCrawler({
70
- * useSessionPool: true,
71
- * persistCookiesPerSession: true,
72
- * // ...
73
- * })
74
- * ```
78
+ * Session pool is already integrated into crawlers and is always active.
79
+ * All public methods are lazy-initialized — the pool initializes itself on first use.
75
80
  *
76
81
  * You can configure the pool with many options. See the {@link SessionPoolOptions}.
77
82
  * Session pool is by default persisted in default {@link KeyValueStore}.
@@ -81,7 +86,7 @@ export interface SessionPoolOptions {
81
86
  * **Advanced usage:**
82
87
  *
83
88
  * ```javascript
84
- * const sessionPool = await SessionPool.open({
89
+ * const sessionPool = new SessionPool({
85
90
  * maxPoolSize: 25,
86
91
  * sessionOptions:{
87
92
  * maxAgeSecs: 10,
@@ -117,40 +122,24 @@ export interface SessionPoolOptions {
117
122
  *
118
123
  * @category Scaling
119
124
  */
120
- export declare class SessionPool extends EventEmitter {
121
- readonly config: Configuration;
122
- protected log: Log;
123
- protected maxPoolSize: number;
124
- protected createSessionFunction: CreateSession;
125
- protected keyValueStore: KeyValueStore;
126
- protected sessions: Session[];
127
- protected sessionMap: Map<string, Session>;
128
- protected sessionOptions: SessionOptions;
129
- protected persistStateKeyValueStoreId?: string;
130
- protected persistStateKey: string;
131
- protected _listener: () => Promise<void>;
132
- protected events: EventManager;
133
- protected readonly blockedStatusCodes: number[];
134
- protected persistenceOptions: PersistenceOptions;
135
- protected isInitialized: boolean;
136
- private queue;
137
- /**
138
- * @internal
139
- */
140
- constructor(options?: SessionPoolOptions, config?: Configuration);
125
+ export declare class SessionPool implements ISessionPool {
126
+ #private;
127
+ readonly id: string;
128
+ constructor(options?: SessionPoolOptions);
141
129
  /**
142
130
  * Gets count of usable sessions in the pool.
143
131
  */
144
- get usableSessionsCount(): number;
132
+ usableSessionsCount(): Promise<number>;
145
133
  /**
146
134
  * Gets count of retired sessions in the pool.
147
135
  */
148
- get retiredSessionsCount(): number;
136
+ retiredSessionsCount(): Promise<number>;
149
137
  /**
150
138
  * Starts periodic state persistence and potentially loads SessionPool state from {@link KeyValueStore}.
151
- * It is called automatically by the {@link SessionPool.open} function.
139
+ * Called automatically on first use of any public method.
152
140
  */
153
- initialize(): Promise<void>;
141
+ private ensureInitialized;
142
+ private setupPool;
154
143
  /**
155
144
  * Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
156
145
  * but this allows you to add more sessions once the max pool size is reached.
@@ -170,89 +159,84 @@ export declare class SessionPool extends EventEmitter {
170
159
  * If there is space for new session, it creates and returns new session.
171
160
  * If the session pool is full, it picks a session from the pool,
172
161
  * If the picked session is usable it is returned, otherwise it creates and returns a new one.
162
+ * @param [sessionId] If provided, it returns the usable session with this id, `undefined` otherwise.
173
163
  */
174
- getSession(): Promise<Session>;
164
+ getSession(sessionId?: string): Promise<Session | undefined>;
175
165
  /**
176
- * Gets session based on the provided session id or `undefined.
166
+ * Discards all sessions in the pool, both usable and retired, resetting it to a blank state.
167
+ *
168
+ * The persisted record is left alone - use {@link SessionPool.resetStore} to clear that as well.
177
169
  */
178
- getSession(sessionId: string): Promise<Session>;
170
+ reset(): void;
179
171
  /**
180
- * @param options - Override the persistence options provided in the constructor
172
+ * Clears the persisted pool record, leaving the in-memory sessions alone.
173
+ *
174
+ * Throws while the state is still being persisted periodically - the next PERSIST_STATE event would write
175
+ * the record straight back. Call {@link SessionPool.teardown} first, or use {@link SessionPool.reset}
176
+ * to discard the sessions themselves. A no-op if persistence is disabled.
181
177
  */
182
- resetStore(options?: PersistenceOptions): Promise<void>;
178
+ resetStore(): Promise<void>;
183
179
  /**
184
180
  * Returns an object representing the internal state of the `SessionPool` instance.
185
- * Note that the object's fields can change in future releases.
181
+ * @internal
186
182
  */
187
- getState(): {
188
- usableSessionsCount: number;
189
- retiredSessionsCount: number;
190
- // @ts-ignore optional peer dependency or compatibility with es2022
191
- sessions: import("./session.js").SessionState[];
192
- };
183
+ getState(): Promise<SessionPoolPersistedState>;
193
184
  /**
194
185
  * Persists the current state of the `SessionPool` into the default {@link KeyValueStore}.
195
186
  * The state is persisted automatically in regular intervals.
196
- * @param options - Override the persistence options provided in the constructor
197
187
  */
198
- persistState(options?: PersistenceOptions): Promise<void>;
188
+ persistState(): Promise<void>;
189
+ [Symbol.asyncDispose](): Promise<void>;
199
190
  /**
200
- * Removes listener from `persistState` event.
191
+ * Stops the periodic state persistence and persists the state one last time.
201
192
  * This function should be called after you are done with using the `SessionPool` instance.
193
+ * Using the pool again afterwards initializes it anew.
202
194
  */
203
195
  teardown(): Promise<void>;
204
- /**
205
- * SessionPool should not work before initialization.
206
- */
207
- protected _throwIfNotInitialized(): void;
208
196
  /**
209
197
  * Removes retired `Session` instances from `SessionPool`.
210
198
  */
211
- protected _removeRetiredSessions(): void;
199
+ private removeRetiredSessions;
212
200
  /**
213
201
  * Adds `Session` instance to `SessionPool`.
214
202
  * @param newSession `Session` instance to be added.
215
203
  */
216
- protected _addSession(newSession: Session): void;
204
+ private registerSession;
217
205
  /**
218
206
  * Gets random index.
219
207
  */
220
- protected _getRandomIndex(): number;
208
+ private getRandomIndex;
221
209
  /**
222
210
  * Creates new session without any extra behavior.
223
- * @param sessionPool
224
211
  * @param [options]
225
212
  * @param [options.sessionOptions] The configuration options for the session being created.
226
213
  * @returns New session.
227
214
  */
228
- protected _defaultCreateSessionFunction(sessionPool: SessionPool, options?: {
229
- sessionOptions?: SessionOptions;
230
- }): Promise<Session>;
215
+ private defaultCreateSessionFunction;
216
+ /**
217
+ * Invokes `createSessionFunction` with `sessionOptions` already merged from pool-wide defaults and
218
+ * the supplied per-call overrides, so custom implementations don't need to spread `pool.sessionOptions` themselves.
219
+ *
220
+ * A default {@link SessionFingerprint} is generated up front (host OS as
221
+ * `platform`, a random valid `browser`/`device` for that platform). Pool-wide
222
+ * and per-call options override it, and a persisted fingerprint coming
223
+ * through `maybeLoadSessionPool` naturally wins because it arrives in
224
+ * `perCallOptions`.
225
+ */
226
+ private invokeCreateSessionFunction;
231
227
  /**
232
228
  * Creates new session and adds it to the pool.
233
229
  * @returns Newly created `Session` instance.
234
230
  */
235
- protected _createSession(): Promise<Session>;
231
+ private createSession;
236
232
  /**
237
233
  * Decides whether there is enough space for creating new session.
238
234
  */
239
- protected _hasSpaceForSession(): boolean;
240
- /**
241
- * Picks random session from the `SessionPool`.
242
- * @returns Picked `Session`.
243
- */
244
- protected _pickSession(): Session;
235
+ private hasSpaceForSession;
245
236
  /**
246
- * Potentially loads `SessionPool`.
247
- * If the state was persisted it loads the `SessionPool` from the persisted state.
248
- */
249
- protected _maybeLoadSessionPool(): Promise<void>;
250
- /**
251
- * Opens a SessionPool and returns a promise resolving to an instance
252
- * of the {@link SessionPool} class that is already initialized.
253
- *
254
- * For more details and code examples, see the {@link SessionPool} class.
237
+ * Picks a session from the `SessionPool` according to the configured `sessionReuseStrategy`.
238
+ * Returns `undefined` when no session should be reused and a new one should be created instead.
255
239
  */
256
- static open(options?: SessionPoolOptions, config?: Configuration): Promise<SessionPool>;
240
+ private pickSession;
257
241
  }
258
- //# sourceMappingURL=session_pool.d.ts.map
242
+ export {};