@passcod/faith 0.0.4 → 0.0.5

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
@@ -1,14 +1,15 @@
1
1
  # fáith - Rust-powered fetch API for Node.js
2
2
 
3
- /ˈɸaːθj/ — pronounced FATH, like FATHER without the ER. This is an old irish word with the same
4
- root as "fetch", meaning _poet_, _soothsayer_, _seer_, and later, _prophet_.
3
+ /ˈɸaːθj/ — pronounced FATH, like FATHER without the ER. This is an old irish word that is a folk
4
+ etymology of "fetch", and means _poet_, _soothsayer_, _seer_, and later, _prophet_.
5
5
 
6
6
  Fáith is of course a pun with _faith_, and is meant to be a _faithful_ implementation of the fetch
7
7
  API for Node.js, but using a Rust-based network stack instead of undici + libuv.
8
8
 
9
9
  Most `fetch` implementations for Node.js are based on the Node.js TCP stack (via libuv) and cannot
10
10
  easily work around its limitations. The native fetch implementation, `undici`, explicitly targets
11
- HTTP/1.1, and doesn't support HTTP/2+, among many other complaints.
11
+ HTTP/1.1, and doesn't support HTTP/2+, among many other complaints (of course, for HTTP/1, undici
12
+ is a very good effort! it just feels like a bit of an outdated choice today).
12
13
 
13
14
  Fáith tries to bring a Node.js fetch that is closer to the browser's fetch, notably by having
14
15
  transparent support for HTTP/2 and HTTP/3, IPv6 and IPv4 using the "Happy Eyeballs" algorithm, a
@@ -40,14 +41,36 @@ async function example() {
40
41
  ### Fetch with options
41
42
 
42
43
  ```javascript
44
+ import { fetch } from '@passcod/faith';
45
+
46
+ const response = await fetch('https://httpbin.org/post', {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Content-Type': 'application/json',
50
+ 'X-Custom-Header': 'value'
51
+ },
52
+ body: JSON.stringify({ message: 'Hello' }),
53
+ });
54
+ ```
55
+
56
+ ### Fetch with HTTP cache
57
+
58
+ ```javascript
59
+ import { fetch, Agent } from '@passcod/faith';
60
+
61
+ const agent = new Agent({
62
+ cache: {
63
+ store: 'memory',
64
+ },
65
+ });
43
66
  const response = await fetch('https://httpbin.org/post', {
67
+ agent,
44
68
  method: 'POST',
45
69
  headers: {
46
70
  'Content-Type': 'application/json',
47
71
  'X-Custom-Header': 'value'
48
72
  },
49
73
  body: JSON.stringify({ message: 'Hello' }),
50
- timeout: 30 // seconds
51
74
  });
52
75
  ```
53
76
 
package/index.d.ts CHANGED
@@ -42,6 +42,8 @@ export declare class Agent {
42
42
  *
43
43
  * - `requestsSent`
44
44
  * - `responsesReceived`
45
+ * - `bodiesStarted`
46
+ * - `bodiesFinished`
45
47
  */
46
48
  stats(): AgentStats
47
49
  }
@@ -49,6 +51,16 @@ export declare class Agent {
49
51
  export declare class AgentStats {
50
52
  requestsSent: number
51
53
  responsesReceived: number
54
+ /**
55
+ * Number of response body streams that have been started (converted from raw body to stream).
56
+ * This happens when `.body`, `.text()`, `.json()`, `.bytes()`, or similar methods are called.
57
+ */
58
+ bodiesStarted: number
59
+ /**
60
+ * Number of response body streams that have been fully consumed.
61
+ * When `bodies_started - bodies_finished > 0`, there are bodies holding connections open.
62
+ */
63
+ bodiesFinished: number
52
64
  }
53
65
 
54
66
  /**
@@ -64,8 +76,10 @@ export declare class FaithResponse {
64
76
  *
65
77
  * Note that Fáith does not provide a custom `Headers` class; instead the Web API `Headers` structure
66
78
  * is used directly and constructed by Fáith when needed.
79
+ *
80
+ * This is a function as an internal implementation detail and the wrapper makes it a property.
67
81
  */
68
- get headers(): Array<[string, string]>
82
+ headers(): Array<[string, string]>
69
83
  /**
70
84
  * The `ok` read-only property of the `Response` interface contains a boolean stating whether the
71
85
  * response was successful (status in the range 200-299) or not.
@@ -136,10 +150,17 @@ get bodyUsed(): boolean
136
150
  * contents, or `null` for any actual HTTP response that has no body, such as `HEAD` requests and
137
151
  * `204 No Content` responses.
138
152
  *
139
- * Note that browsers currently do not return `null` for those responses, but the spec requires it.
140
- * Fáith chooses to respect the spec rather than the browsers in this case.
153
+ * Note that browsers currently do not return `null` for those responses, but the spec requires
154
+ * it. Fáith chooses to respect the spec rather than the browsers in this case.
155
+ *
156
+ * An important consideration exists in conjunction with the connection pool: if you start the
157
+ * body stream, this will hold the connection until the stream is fully consumed. If another
158
+ * request is started during that time, and you don't have an available connection in the pool
159
+ * for the host already, the new request will open one.
160
+ *
161
+ * Note that this is a function as an implementation detail; the wrapper makes it a property.
141
162
  */
142
- get body(): ReadableStream<Buffer> | null
163
+ body(): ReadableStream<Buffer> | null
143
164
  /**
144
165
  * The `bytes()` method of the `Response` interface takes a `Response` stream and reads it to
145
166
  * completion. It returns a promise that resolves with a `Uint8Array`.
@@ -166,6 +187,18 @@ text(): Async<string>
166
187
  * efficient access, consider handling the response body as a stream.
167
188
  */
168
189
  json(): Async<any>
190
+ /**
191
+ * The `trailers()` read-only property of the `Response` interface returns a promise that
192
+ * resolves to either `null` or a `Headers` structure that contains the HTTP/2 or /3 trailing
193
+ * headers.
194
+ *
195
+ * This was once in the spec as a getter but was removed as it wasn't implemented by any browser.
196
+ *
197
+ * Note that this will never resolve if you don't also consume the body in some way.
198
+ *
199
+ * This is an async fn as an internal implementation detail and the wrapper makes it a property.
200
+ */
201
+ trailers(): Promise<Array<[string, string]> | null>
169
202
  /**
170
203
  * The `clone()` method of the `Response` interface creates a clone of a response object, identical
171
204
  * in every way, but stored in a different variable.
package/index.js CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('@passcod/faith-android-arm64')
79
79
  const bindingPackageVersion = require('@passcod/faith-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('@passcod/faith-android-arm-eabi')
95
95
  const bindingPackageVersion = require('@passcod/faith-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('@passcod/faith-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('@passcod/faith-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('@passcod/faith-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('@passcod/faith-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('@passcod/faith-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('@passcod/faith-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('@passcod/faith-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('@passcod/faith-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('@passcod/faith-darwin-universal')
184
184
  const bindingPackageVersion = require('@passcod/faith-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('@passcod/faith-darwin-x64')
200
200
  const bindingPackageVersion = require('@passcod/faith-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('@passcod/faith-darwin-arm64')
216
216
  const bindingPackageVersion = require('@passcod/faith-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('@passcod/faith-freebsd-x64')
236
236
  const bindingPackageVersion = require('@passcod/faith-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('@passcod/faith-freebsd-arm64')
252
252
  const bindingPackageVersion = require('@passcod/faith-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('@passcod/faith-linux-x64-musl')
273
273
  const bindingPackageVersion = require('@passcod/faith-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('@passcod/faith-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('@passcod/faith-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('@passcod/faith-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('@passcod/faith-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('@passcod/faith-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('@passcod/faith-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('@passcod/faith-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('@passcod/faith-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('@passcod/faith-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('@passcod/faith-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('@passcod/faith-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('@passcod/faith-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('@passcod/faith-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('@passcod/faith-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('@passcod/faith-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('@passcod/faith-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('@passcod/faith-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('@passcod/faith-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('@passcod/faith-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('@passcod/faith-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('@passcod/faith-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('@passcod/faith-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('@passcod/faith-openharmony-arm64')
478
478
  const bindingPackageVersion = require('@passcod/faith-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('@passcod/faith-openharmony-x64')
494
494
  const bindingPackageVersion = require('@passcod/faith-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('@passcod/faith-openharmony-arm')
510
510
  const bindingPackageVersion = require('@passcod/faith-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.0.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.0.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@passcod/faith",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "fáith: a Rust-powered fetch",
5
5
  "repository": "https://github.com/passcod/faith",
6
6
  "author": {
@@ -10,11 +10,13 @@
10
10
  },
11
11
  "license": "Apache-2.0 OR MIT",
12
12
  "main": "wrapper.js",
13
+ "module": "wrapper.mjs",
13
14
  "types": "wrapper.d.ts",
14
15
  "files": [
15
16
  "index.js",
16
17
  "index.d.ts",
17
18
  "wrapper.js",
19
+ "wrapper.mjs",
18
20
  "wrapper.d.ts"
19
21
  ],
20
22
  "napi": {
@@ -41,7 +43,7 @@
41
43
  "test:only": "tape test/*.test.js",
42
44
  "test:integration": "tape test/integration/*.test.js",
43
45
  "prepublishOnly": "napi prepublish -t npm",
44
- "version": "node -e \"const fs=require('fs');const pkg=require('./package.json');let cargo=fs.readFileSync('Cargo.toml','utf8');cargo=cargo.replace(/^version = \\\".*\\\"/m,'version = \\\"'+pkg.version+'\\\"');fs.writeFileSync('Cargo.toml',cargo)\" && cargo check && git add Cargo.toml Cargo.lock"
46
+ "version": "node -e \"const fs=require('fs');const pkg=require('./package.json');let cargo=fs.readFileSync('Cargo.toml','utf8');cargo=cargo.replace(/^version = \\\".*\\\"/m,'version = \\\"'+pkg.version+'\\\"');fs.writeFileSync('Cargo.toml',cargo)\" && npm run build && git add index.js Cargo.toml Cargo.lock"
45
47
  },
46
48
  "keywords": [
47
49
  "fetch",
@@ -61,17 +63,17 @@
61
63
  "node": ">= 20"
62
64
  },
63
65
  "optionalDependencies": {
64
- "@passcod/faith-darwin-arm64": "0.0.4",
65
- "@passcod/faith-android-arm64": "0.0.4",
66
- "@passcod/faith-win32-arm64-msvc": "0.0.4",
67
- "@passcod/faith-linux-arm64-gnu": "0.0.4",
68
- "@passcod/faith-linux-arm64-musl": "0.0.4",
69
- "@passcod/faith-android-arm-eabi": "0.0.4",
70
- "@passcod/faith-linux-arm-gnueabihf": "0.0.4",
71
- "@passcod/faith-darwin-x64": "0.0.4",
72
- "@passcod/faith-win32-x64-msvc": "0.0.4",
73
- "@passcod/faith-freebsd-x64": "0.0.4",
74
- "@passcod/faith-linux-x64-gnu": "0.0.4",
75
- "@passcod/faith-linux-x64-musl": "0.0.4"
66
+ "@passcod/faith-darwin-arm64": "0.0.5",
67
+ "@passcod/faith-android-arm64": "0.0.5",
68
+ "@passcod/faith-win32-arm64-msvc": "0.0.5",
69
+ "@passcod/faith-linux-arm64-gnu": "0.0.5",
70
+ "@passcod/faith-linux-arm64-musl": "0.0.5",
71
+ "@passcod/faith-android-arm-eabi": "0.0.5",
72
+ "@passcod/faith-linux-arm-gnueabihf": "0.0.5",
73
+ "@passcod/faith-darwin-x64": "0.0.5",
74
+ "@passcod/faith-win32-x64-msvc": "0.0.5",
75
+ "@passcod/faith-freebsd-x64": "0.0.5",
76
+ "@passcod/faith-linux-x64-gnu": "0.0.5",
77
+ "@passcod/faith-linux-x64-musl": "0.0.5"
76
78
  }
77
79
  }
package/wrapper.d.ts CHANGED
@@ -264,8 +264,13 @@ export class Response {
264
264
  * contents, or `null` for any actual HTTP response that has no body, such as `HEAD` requests and
265
265
  * `204 No Content` responses.
266
266
  *
267
- * Note that browsers currently do not return `null` for those responses, but the spec requires it.
268
- * Fáith chooses to respect the spec rather than the browsers in this case.
267
+ * Note that browsers currently do not return `null` for those responses, but the spec requires
268
+ * it. Fáith chooses to respect the spec rather than the browsers in this case.
269
+ *
270
+ * An important consideration exists in conjunction with the connection pool: if you start the
271
+ * body stream, this will hold the connection until the stream is fully consumed. If another
272
+ * request is started during that time, and you don't have an available connection in the pool
273
+ * for the host already, the new request will open one.
269
274
  */
270
275
  readonly body: ReadableStream<Uint8Array> | null;
271
276
 
@@ -317,6 +322,16 @@ export class Response {
317
322
  */
318
323
  formData(): Promise<FormData>;
319
324
 
325
+ /**
326
+ * The `trailers()` method of the `Response` interface returns a promise that resolves to either
327
+ * `null` or a `Headers` structure that contains the HTTP/2 or /3 trailing headers.
328
+ *
329
+ * This was once in the spec as a getter but was removed as it wasn't implemented by any browser.
330
+ *
331
+ * Note that this will never resolve if you don't also consume the body in some way.
332
+ */
333
+ trailers(): Promise<Headers | null>;
334
+
320
335
  /**
321
336
  * The `clone()` method of the `Response` interface creates a clone of a response object, identical
322
337
  * in every way, but stored in a different variable.
package/wrapper.js CHANGED
@@ -27,26 +27,11 @@ class Response {
27
27
  constructor(nativeResponse) {
28
28
  this.#nativeResponse = nativeResponse;
29
29
 
30
- // Create a Headers object from the array of header pairs
31
- const headers = new Headers();
32
- const headerPairs = this.#nativeResponse.headers;
33
- if (Array.isArray(headerPairs)) {
34
- for (const [name, value] of headerPairs) {
35
- headers.append(name, value);
36
- }
37
- }
38
-
39
- Object.defineProperty(this, "headers", {
40
- get: () => headers,
41
- enumerable: true,
42
- configurable: true,
43
- });
44
-
45
30
  const nativeProto = Object.getPrototypeOf(this.#nativeResponse);
46
31
  const descriptors = Object.getOwnPropertyDescriptors(nativeProto);
47
32
 
48
33
  for (const [key, descriptor] of Object.entries(descriptors)) {
49
- if (descriptor.get && key !== "headers") {
34
+ if (descriptor.get) {
50
35
  Object.defineProperty(this, key, {
51
36
  get: () => this.#nativeResponse[key],
52
37
  enumerable: true,
@@ -56,6 +41,36 @@ class Response {
56
41
  }
57
42
  }
58
43
 
44
+ get headers() {
45
+ const headers = new Headers();
46
+ const headerPairs = this.#nativeResponse.headers();
47
+ if (Array.isArray(headerPairs)) {
48
+ for (const [name, value] of headerPairs) {
49
+ headers.append(name, value);
50
+ }
51
+ }
52
+ return headers;
53
+ }
54
+
55
+ get trailers() {
56
+ return (async () => {
57
+ const headerPairs = await this.#nativeResponse.trailers();
58
+ if (!Array.isArray(headerPairs)) {
59
+ return null;
60
+ }
61
+
62
+ const headers = new Headers();
63
+ for (const [name, value] of headerPairs) {
64
+ headers.append(name, value);
65
+ }
66
+ return headers;
67
+ })();
68
+ }
69
+
70
+ get body() {
71
+ return this.#nativeResponse.body();
72
+ }
73
+
59
74
  /**
60
75
  * Convert response body to text (UTF-8)
61
76
  * @returns {Promise<string>}
package/wrapper.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import faith from "./wrapper.js";
2
+ const {
3
+ Agent,
4
+ CacheMode,
5
+ CacheStore,
6
+ Credentials,
7
+ Duplex,
8
+ ERROR_CODES,
9
+ FAITH_VERSION,
10
+ fetch,
11
+ Http3Congestion,
12
+ Redirect,
13
+ REQWEST_VERSION,
14
+ Response,
15
+ USER_AGENT,
16
+ } = faith;
17
+
18
+ export {
19
+ Agent,
20
+ CacheMode,
21
+ CacheStore,
22
+ Credentials,
23
+ Duplex,
24
+ ERROR_CODES,
25
+ FAITH_VERSION,
26
+ fetch,
27
+ Http3Congestion,
28
+ Redirect,
29
+ REQWEST_VERSION,
30
+ Response,
31
+ USER_AGENT,
32
+ };