@crawlee/basic 4.0.0-beta.209 → 4.0.0-beta.210

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.
@@ -143,6 +143,9 @@ export declare class SessionPool implements ISessionPool {
143
143
  * Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
144
144
  * but this allows you to add more sessions once the max pool size is reached.
145
145
  * This also allows you to add session with overridden session options (e.g. with specific session id).
146
+ *
147
+ * If the pool already contains a session with the same id, it is replaced when it is no longer usable
148
+ * (e.g. retired), and an error is thrown otherwise.
146
149
  * @param [options] The configuration options for the session being added to the session pool.
147
150
  */
148
151
  addSession(options?: Session | SessionOptions): Promise<void>;
@@ -215,15 +215,21 @@ export class SessionPool {
215
215
  * Adds a new session to the session pool. The pool automatically creates sessions up to the maximum size of the pool,
216
216
  * but this allows you to add more sessions once the max pool size is reached.
217
217
  * This also allows you to add session with overridden session options (e.g. with specific session id).
218
+ *
219
+ * If the pool already contains a session with the same id, it is replaced when it is no longer usable
220
+ * (e.g. retired), and an error is thrown otherwise.
218
221
  * @param [options] The configuration options for the session being added to the session pool.
219
222
  */
220
223
  async addSession(options = {}) {
221
224
  await this.ensureInitialized();
222
225
  const { id } = options;
223
226
  if (id) {
224
- const sessionExists = this.#sessionMap.has(id);
225
- if (sessionExists) {
226
- throw new Error(`Cannot add session with id '${id}' as it already exists in the pool`);
227
+ const existingSession = this.#sessionMap.get(id);
228
+ if (existingSession) {
229
+ if (existingSession.isUsable()) {
230
+ throw new Error(`Cannot add session with id '${id}' as it already exists in the pool`);
231
+ }
232
+ this.#removeSession(existingSession);
227
233
  }
228
234
  }
229
235
  if (!this.hasSpaceForSession()) {
@@ -349,6 +355,14 @@ export class SessionPool {
349
355
  return false;
350
356
  });
351
357
  }
358
+ /**
359
+ * Removes a `Session` instance from `SessionPool`.
360
+ */
361
+ #removeSession(session) {
362
+ this.#state.currentValue.sessions = this.#state.currentValue.sessions.filter((storedSession) => storedSession !== session);
363
+ this.#sessionMap.delete(session.id);
364
+ this.#log.debug(`Removed Session - ${session.id}`);
365
+ }
352
366
  /**
353
367
  * Adds `Session` instance to `SessionPool`.
354
368
  * @param newSession `Session` instance to be added.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/basic",
3
- "version": "4.0.0-beta.209",
3
+ "version": "4.0.0-beta.210",
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": "^3.0.1",
43
43
  "@apify/timeout": "^1.0.1",
44
44
  "@apify/utilities": "^3.0.1",
45
- "@crawlee/core": "4.0.0-beta.209",
46
- "@crawlee/http-client": "4.0.0-beta.209",
47
- "@crawlee/types": "4.0.0-beta.209",
48
- "@crawlee/utils": "4.0.0-beta.209",
45
+ "@crawlee/core": "4.0.0-beta.210",
46
+ "@crawlee/http-client": "4.0.0-beta.210",
47
+ "@crawlee/types": "4.0.0-beta.210",
48
+ "@crawlee/utils": "4.0.0-beta.210",
49
49
  "@sapphire/async-queue": "^1.5.5",
50
50
  "@standard-schema/spec": "^1.0.0",
51
51
  "csv-stringify": "^6.5.2",
@@ -57,7 +57,7 @@
57
57
  "zod": "^4.5.4"
58
58
  },
59
59
  "optionalDependencies": {
60
- "@crawlee/impit-client": "4.0.0-beta.209"
60
+ "@crawlee/impit-client": "4.0.0-beta.210"
61
61
  },
62
62
  "lerna": {
63
63
  "command": {
@@ -66,5 +66,5 @@
66
66
  }
67
67
  }
68
68
  },
69
- "gitHead": "ccf82c59e230033a34bddcbecb1f4a8e803eaa11"
69
+ "gitHead": "037dff5d651d88e96749cc79d17bc6d1e154f4e1"
70
70
  }