@whatwg-node/node-fetch 0.5.9-rc-20240321102718-57ccbfe78e06414846e24e5963375b6d12521601 → 0.5.10-alpha-20240321134843-2ae7764efe55eb7970cab335a048aebb4a6d3b0f

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/cjs/Body.js CHANGED
@@ -162,8 +162,9 @@ class PonyfillBody {
162
162
  bb.on('close', () => {
163
163
  resolve(formData);
164
164
  });
165
- bb.on('error', err => {
166
- reject(err);
165
+ bb.on('error', (err = 'An error occurred while parsing the form data') => {
166
+ const errMessage = err.message || err.toString();
167
+ reject(new TypeError(errMessage, err.cause));
167
168
  });
168
169
  _body?.readable.pipe(bb);
169
170
  });
package/cjs/URL.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillURL = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const buffer_1 = require("buffer");
6
+ const crypto_1 = require("crypto");
5
7
  const fast_querystring_1 = tslib_1.__importDefault(require("fast-querystring"));
6
8
  const fast_url_parser_1 = tslib_1.__importDefault(require("@kamilkisiela/fast-url-parser"));
7
9
  const URLSearchParams_js_1 = require("./URLSearchParams.js");
@@ -49,5 +51,22 @@ class PonyfillURL extends fast_url_parser_1.default {
49
51
  toJSON() {
50
52
  return this.toString();
51
53
  }
54
+ static createObjectURL(blob) {
55
+ const blobUrl = `blob:whatwgnode:${(0, crypto_1.randomUUID)()}`;
56
+ this.blobRegistry.set(blobUrl, blob);
57
+ return blobUrl;
58
+ }
59
+ static resolveObjectURL(url) {
60
+ if (!this.blobRegistry.has(url)) {
61
+ URL.revokeObjectURL(url);
62
+ }
63
+ else {
64
+ this.blobRegistry.delete(url);
65
+ }
66
+ }
67
+ static getBlobFromURL(url) {
68
+ return (this.blobRegistry.get(url) || (0, buffer_1.resolveObjectURL)(url));
69
+ }
52
70
  }
53
71
  exports.PonyfillURL = PonyfillURL;
72
+ PonyfillURL.blobRegistry = new Map();
package/cjs/fetch.js CHANGED
@@ -7,6 +7,7 @@ const fetchCurl_js_1 = require("./fetchCurl.js");
7
7
  const fetchNodeHttp_js_1 = require("./fetchNodeHttp.js");
8
8
  const Request_js_1 = require("./Request.js");
9
9
  const Response_js_1 = require("./Response.js");
10
+ const URL_js_1 = require("./URL.js");
10
11
  const utils_js_1 = require("./utils.js");
11
12
  const BASE64_SUFFIX = ';base64';
12
13
  function getResponseForFile(url) {
@@ -36,6 +37,19 @@ function getResponseForDataUri(url) {
36
37
  },
37
38
  });
38
39
  }
40
+ function getResponseForBlob(url) {
41
+ const blob = URL_js_1.PonyfillURL.getBlobFromURL(url);
42
+ if (!blob) {
43
+ throw new TypeError('Invalid Blob URL');
44
+ }
45
+ return new Response_js_1.PonyfillResponse(blob, {
46
+ status: 200,
47
+ headers: {
48
+ 'content-type': blob.type,
49
+ 'content-length': blob.size.toString(),
50
+ },
51
+ });
52
+ }
39
53
  function isURL(obj) {
40
54
  return obj != null && obj.href != null;
41
55
  }
@@ -53,6 +67,10 @@ function fetchPonyfill(info, init) {
53
67
  const response = getResponseForFile(fetchRequest.url);
54
68
  return (0, utils_js_1.fakePromise)(response);
55
69
  }
70
+ if (fetchRequest.url.startsWith('blob:')) {
71
+ const response = getResponseForBlob(fetchRequest.url);
72
+ return (0, utils_js_1.fakePromise)(response);
73
+ }
56
74
  if (globalThis.libcurl) {
57
75
  return (0, fetchCurl_js_1.fetchCurl)(fetchRequest);
58
76
  }
package/esm/Body.js CHANGED
@@ -158,8 +158,9 @@ export class PonyfillBody {
158
158
  bb.on('close', () => {
159
159
  resolve(formData);
160
160
  });
161
- bb.on('error', err => {
162
- reject(err);
161
+ bb.on('error', (err = 'An error occurred while parsing the form data') => {
162
+ const errMessage = err.message || err.toString();
163
+ reject(new TypeError(errMessage, err.cause));
163
164
  });
164
165
  _body?.readable.pipe(bb);
165
166
  });
package/esm/URL.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { resolveObjectURL } from 'buffer';
2
+ import { randomUUID } from 'crypto';
1
3
  import FastQuerystring from 'fast-querystring';
2
4
  import FastUrl from '@kamilkisiela/fast-url-parser';
3
5
  import { PonyfillURLSearchParams } from './URLSearchParams.js';
@@ -45,4 +47,21 @@ export class PonyfillURL extends FastUrl {
45
47
  toJSON() {
46
48
  return this.toString();
47
49
  }
50
+ static createObjectURL(blob) {
51
+ const blobUrl = `blob:whatwgnode:${randomUUID()}`;
52
+ this.blobRegistry.set(blobUrl, blob);
53
+ return blobUrl;
54
+ }
55
+ static resolveObjectURL(url) {
56
+ if (!this.blobRegistry.has(url)) {
57
+ URL.revokeObjectURL(url);
58
+ }
59
+ else {
60
+ this.blobRegistry.delete(url);
61
+ }
62
+ }
63
+ static getBlobFromURL(url) {
64
+ return (this.blobRegistry.get(url) || resolveObjectURL(url));
65
+ }
48
66
  }
67
+ PonyfillURL.blobRegistry = new Map();
package/esm/fetch.js CHANGED
@@ -4,6 +4,7 @@ import { fetchCurl } from './fetchCurl.js';
4
4
  import { fetchNodeHttp } from './fetchNodeHttp.js';
5
5
  import { PonyfillRequest } from './Request.js';
6
6
  import { PonyfillResponse } from './Response.js';
7
+ import { PonyfillURL } from './URL.js';
7
8
  import { fakePromise } from './utils.js';
8
9
  const BASE64_SUFFIX = ';base64';
9
10
  function getResponseForFile(url) {
@@ -33,6 +34,19 @@ function getResponseForDataUri(url) {
33
34
  },
34
35
  });
35
36
  }
37
+ function getResponseForBlob(url) {
38
+ const blob = PonyfillURL.getBlobFromURL(url);
39
+ if (!blob) {
40
+ throw new TypeError('Invalid Blob URL');
41
+ }
42
+ return new PonyfillResponse(blob, {
43
+ status: 200,
44
+ headers: {
45
+ 'content-type': blob.type,
46
+ 'content-length': blob.size.toString(),
47
+ },
48
+ });
49
+ }
36
50
  function isURL(obj) {
37
51
  return obj != null && obj.href != null;
38
52
  }
@@ -50,6 +64,10 @@ export function fetchPonyfill(info, init) {
50
64
  const response = getResponseForFile(fetchRequest.url);
51
65
  return fakePromise(response);
52
66
  }
67
+ if (fetchRequest.url.startsWith('blob:')) {
68
+ const response = getResponseForBlob(fetchRequest.url);
69
+ return fakePromise(response);
70
+ }
53
71
  if (globalThis.libcurl) {
54
72
  return fetchCurl(fetchRequest);
55
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.9-rc-20240321102718-57ccbfe78e06414846e24e5963375b6d12521601",
3
+ "version": "0.5.10-alpha-20240321134843-2ae7764efe55eb7970cab335a048aebb4a6d3b0f",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
package/typings/URL.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="packages/node-fetch/src/declarations.js" />
2
2
  import FastUrl from '@kamilkisiela/fast-url-parser';
3
+ import { PonyfillBlob } from './Blob.cjs';
3
4
  import { PonyfillURLSearchParams } from './URLSearchParams.cjs';
4
5
  export declare class PonyfillURL extends FastUrl implements URL {
5
6
  constructor(url: string, base?: string | URL);
@@ -12,4 +13,8 @@ export declare class PonyfillURL extends FastUrl implements URL {
12
13
  set password(value: string);
13
14
  toString(): string;
14
15
  toJSON(): string;
16
+ private static blobRegistry;
17
+ static createObjectURL(blob: Blob): string;
18
+ static resolveObjectURL(url: string): void;
19
+ static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined;
15
20
  }
package/typings/URL.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="packages/node-fetch/src/declarations.js" />
2
2
  import FastUrl from '@kamilkisiela/fast-url-parser';
3
+ import { PonyfillBlob } from './Blob.js';
3
4
  import { PonyfillURLSearchParams } from './URLSearchParams.js';
4
5
  export declare class PonyfillURL extends FastUrl implements URL {
5
6
  constructor(url: string, base?: string | URL);
@@ -12,4 +13,8 @@ export declare class PonyfillURL extends FastUrl implements URL {
12
13
  set password(value: string);
13
14
  toString(): string;
14
15
  toJSON(): string;
16
+ private static blobRegistry;
17
+ static createObjectURL(blob: Blob): string;
18
+ static resolveObjectURL(url: string): void;
19
+ static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined;
15
20
  }