rekwest 4.5.0 → 4.5.2

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.
package/README.md CHANGED
@@ -123,7 +123,8 @@ console.log(res.body);
123
123
  * `baseURL` **{string | URL}** The base URL to use in cases where `url` is a relative URL
124
124
  * `body` **{string | Array | ArrayBuffer | ArrayBufferView | AsyncIterator | Blob | Buffer | DataView | File |
125
125
  FormData | Iterator | Object | Readable | SharedArrayBuffer | URLSearchParams}** The body to send with the request
126
- * `cookies` **{boolean | Array<[k, v]> | Cookies | Object | URLSearchParams}** `Default: true` The cookies to add to
126
+ * `cookies` **{boolean | Array<[k, v]> | Array<string\> | Cookies | Object | URLSearchParams}** `Default: true` The
127
+ cookies to add to
127
128
  the request
128
129
  * `cookiesTTL` **{boolean}** `Default: false` Controls enablement of TTL for the cookies cache
129
130
  * `credentials` **{include | omit | same-origin}** `Default: same-origin` Controls credentials in case of cross-origin
@@ -150,9 +151,9 @@ console.log(res.body);
150
151
  extended [http.IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
151
152
  or [http2.ClientHttp2Stream](https://nodejs.org/api/http2.html#class-clienthttp2stream) which is respectively
152
153
  readable and duplex streams
153
- * if `degist: true` & `parse: true`
154
+ * if `digest: true` & `parse: true`
154
155
  * `body` **{string | Array | Buffer | Object}** The body based on its content type
155
- * if `degist: false`
156
+ * if `digest: false`
156
157
  * `arrayBuffer` **{AsyncFunction}** Reads the response and returns **ArrayBuffer**
157
158
  * `blob` **{AsyncFunction}** Reads the response and returns **Blob**
158
159
  * `body` **{AsyncFunction}** Reads the response and returns **Buffer** if `parse: false`
package/dist/cookies.js CHANGED
@@ -4,7 +4,16 @@ exports.__esModule = true;
4
4
  exports.Cookies = void 0;
5
5
  var _utils = require("./utils");
6
6
  class Cookies extends URLSearchParams {
7
+ static #finalizers = new Set();
7
8
  static jar = new Map();
9
+ static #register(target, value) {
10
+ const finalizer = new FinalizationRegistry(heldValue => {
11
+ clearTimeout(heldValue);
12
+ this.#finalizers.delete(finalizer);
13
+ });
14
+ finalizer.register(target, value);
15
+ this.#finalizers.add(finalizer);
16
+ }
8
17
  #chronometry = new Map();
9
18
  get [Symbol.toStringTag]() {
10
19
  return this.constructor.name;
@@ -43,10 +52,15 @@ class Cookies extends URLSearchParams {
43
52
  maxAge
44
53
  } = ttl;
45
54
  [maxAge, expires].filter(it => Number.isInteger(it)).some(ms => {
55
+ const ref = new WeakRef(this);
46
56
  const tid = setTimeout(() => {
47
- this.#chronometry.delete(cookie);
48
- this.delete(cookie);
57
+ const ctx = ref.deref();
58
+ if (ctx) {
59
+ ctx.#chronometry.delete(cookie);
60
+ ctx.delete(cookie);
61
+ }
49
62
  }, Math.max(ms, 0));
63
+ this.constructor.#register(this, tid);
50
64
  return this.#chronometry.set(cookie, tid);
51
65
  });
52
66
  });
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@babel/eslint-parser": "^7.21.8",
14
14
  "@babel/preset-env": "^7.22.4",
15
15
  "c8": "^7.14.0",
16
- "eslint": "^8.41.0",
16
+ "eslint": "^8.42.0",
17
17
  "eslint-config-ultra-refined": "^2.15.0",
18
18
  "mocha": "^10.2.0"
19
19
  },
@@ -31,6 +31,7 @@
31
31
  ],
32
32
  "homepage": "https://github.com/bricss/rekwest#readme",
33
33
  "keywords": [
34
+ "alpn",
34
35
  "backoff",
35
36
  "brotli",
36
37
  "cookie",
@@ -48,7 +49,8 @@
48
49
  "redirect",
49
50
  "retry",
50
51
  "retry-after",
51
- "stream"
52
+ "stream",
53
+ "upload"
52
54
  ],
53
55
  "license": "MIT",
54
56
  "name": "rekwest",
@@ -67,5 +69,5 @@
67
69
  "test:bail": "mocha --bail",
68
70
  "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
69
71
  },
70
- "version": "4.5.0"
72
+ "version": "4.5.2"
71
73
  }
package/src/cookies.mjs CHANGED
@@ -5,8 +5,19 @@ import {
5
5
 
6
6
  export class Cookies extends URLSearchParams {
7
7
 
8
+ static #finalizers = new Set();
8
9
  static jar = new Map();
9
10
 
11
+ static #register(target, value) {
12
+ const finalizer = new FinalizationRegistry((heldValue) => {
13
+ clearTimeout(heldValue);
14
+ this.#finalizers.delete(finalizer);
15
+ });
16
+
17
+ finalizer.register(target, value);
18
+ this.#finalizers.add(finalizer);
19
+ }
20
+
10
21
  #chronometry = new Map();
11
22
 
12
23
  get [Symbol.toStringTag]() {
@@ -54,11 +65,18 @@ export class Cookies extends URLSearchParams {
54
65
  maxAge,
55
66
  expires,
56
67
  ].filter((it) => Number.isInteger(it)).some((ms) => {
68
+ const ref = new WeakRef(this);
57
69
  const tid = setTimeout(() => {
58
- this.#chronometry.delete(cookie);
59
- this.delete(cookie);
70
+ const ctx = ref.deref();
71
+
72
+ if (ctx) {
73
+ ctx.#chronometry.delete(cookie);
74
+ ctx.delete(cookie);
75
+ }
60
76
  }, Math.max(ms, 0));
61
77
 
78
+ this.constructor.#register(this, tid);
79
+
62
80
  return this.#chronometry.set(cookie, tid);
63
81
  });
64
82
  });