@whatwg-node/node-fetch
Advanced tools
Comparing version 0.5.10-alpha-20240321134843-2ae7764efe55eb7970cab335a048aebb4a6d3b0f to 0.5.10-alpha-20240322103629-07f53b56429d0c2dcdb6dcd240226e0f599203e0
@@ -165,5 +165,4 @@ "use strict"; | ||
}); | ||
bb.on('error', (err = 'An error occurred while parsing the form data') => { | ||
const errMessage = err.message || err.toString(); | ||
reject(new TypeError(errMessage, err.cause)); | ||
bb.on('error', err => { | ||
reject(err); | ||
}); | ||
@@ -170,0 +169,0 @@ _body?.readable.pipe(bb); |
@@ -10,3 +10,2 @@ "use strict"; | ||
const Response_js_1 = require("./Response.js"); | ||
const URL_js_1 = require("./URL.js"); | ||
const utils_js_1 = require("./utils.js"); | ||
@@ -41,15 +40,2 @@ const BASE64_SUFFIX = ';base64'; | ||
} | ||
function getResponseForBlob(url) { | ||
const blob = URL_js_1.PonyfillURL.getBlobFromURL(url); | ||
if (!blob) { | ||
throw new TypeError('Invalid Blob URL'); | ||
} | ||
return new Response_js_1.PonyfillResponse(blob, { | ||
status: 200, | ||
headers: { | ||
'content-type': blob.type, | ||
'content-length': blob.size.toString(), | ||
}, | ||
}); | ||
} | ||
function isURL(obj) { | ||
@@ -72,6 +58,2 @@ return obj != null && obj.href != null; | ||
} | ||
if (fetchRequest.url.startsWith('blob:')) { | ||
const response = getResponseForBlob(fetchRequest.url); | ||
return (0, utils_js_1.fakePromise)(response); | ||
} | ||
if (globalThis.libcurl) { | ||
@@ -78,0 +60,0 @@ return (0, fetchCurl_js_1.fetchCurl)(fetchRequest); |
@@ -59,3 +59,8 @@ "use strict"; | ||
if (curlHandle.isOpen) { | ||
curlHandle.pause(CurlPause.Recv); | ||
try { | ||
curlHandle.pause(CurlPause.Recv); | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
} | ||
@@ -72,2 +77,5 @@ }; | ||
else { | ||
if (error.message === 'Operation was aborted by an application callback') { | ||
error.message = 'The operation was aborted.'; | ||
} | ||
reject(error); | ||
@@ -74,0 +82,0 @@ } |
@@ -5,4 +5,2 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const buffer_1 = require("buffer"); | ||
const crypto_1 = require("crypto"); | ||
const fast_querystring_1 = tslib_1.__importDefault(require("fast-querystring")); | ||
@@ -55,20 +53,3 @@ const fast_url_parser_1 = tslib_1.__importDefault(require("@kamilkisiela/fast-url-parser")); | ||
} | ||
static createObjectURL(blob) { | ||
const blobUrl = `blob:whatwgnode:${(0, crypto_1.randomUUID)()}`; | ||
this.blobRegistry.set(blobUrl, blob); | ||
return blobUrl; | ||
} | ||
static resolveObjectURL(url) { | ||
if (!this.blobRegistry.has(url)) { | ||
URL.revokeObjectURL(url); | ||
} | ||
else { | ||
this.blobRegistry.delete(url); | ||
} | ||
} | ||
static getBlobFromURL(url) { | ||
return (this.blobRegistry.get(url) || (0, buffer_1.resolveObjectURL)(url)); | ||
} | ||
} | ||
exports.PonyfillURL = PonyfillURL; | ||
PonyfillURL.blobRegistry = new Map(); |
@@ -161,5 +161,4 @@ import { Readable } from 'stream'; | ||
}); | ||
bb.on('error', (err = 'An error occurred while parsing the form data') => { | ||
const errMessage = err.message || err.toString(); | ||
reject(new TypeError(errMessage, err.cause)); | ||
bb.on('error', err => { | ||
reject(err); | ||
}); | ||
@@ -166,0 +165,0 @@ _body?.readable.pipe(bb); |
@@ -7,3 +7,2 @@ import { createReadStream } from 'fs'; | ||
import { PonyfillResponse } from './Response.js'; | ||
import { PonyfillURL } from './URL.js'; | ||
import { fakePromise } from './utils.js'; | ||
@@ -38,15 +37,2 @@ const BASE64_SUFFIX = ';base64'; | ||
} | ||
function getResponseForBlob(url) { | ||
const blob = PonyfillURL.getBlobFromURL(url); | ||
if (!blob) { | ||
throw new TypeError('Invalid Blob URL'); | ||
} | ||
return new PonyfillResponse(blob, { | ||
status: 200, | ||
headers: { | ||
'content-type': blob.type, | ||
'content-length': blob.size.toString(), | ||
}, | ||
}); | ||
} | ||
function isURL(obj) { | ||
@@ -69,6 +55,2 @@ return obj != null && obj.href != null; | ||
} | ||
if (fetchRequest.url.startsWith('blob:')) { | ||
const response = getResponseForBlob(fetchRequest.url); | ||
return fakePromise(response); | ||
} | ||
if (globalThis.libcurl) { | ||
@@ -75,0 +57,0 @@ return fetchCurl(fetchRequest); |
@@ -56,3 +56,8 @@ import { PassThrough, Readable } from 'stream'; | ||
if (curlHandle.isOpen) { | ||
curlHandle.pause(CurlPause.Recv); | ||
try { | ||
curlHandle.pause(CurlPause.Recv); | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
} | ||
@@ -69,2 +74,5 @@ }; | ||
else { | ||
if (error.message === 'Operation was aborted by an application callback') { | ||
error.message = 'The operation was aborted.'; | ||
} | ||
reject(error); | ||
@@ -71,0 +79,0 @@ } |
@@ -1,3 +0,1 @@ | ||
import { resolveObjectURL } from 'buffer'; | ||
import { randomUUID } from 'crypto'; | ||
import FastQuerystring from 'fast-querystring'; | ||
@@ -50,19 +48,2 @@ import FastUrl from '@kamilkisiela/fast-url-parser'; | ||
} | ||
static createObjectURL(blob) { | ||
const blobUrl = `blob:whatwgnode:${randomUUID()}`; | ||
this.blobRegistry.set(blobUrl, blob); | ||
return blobUrl; | ||
} | ||
static resolveObjectURL(url) { | ||
if (!this.blobRegistry.has(url)) { | ||
URL.revokeObjectURL(url); | ||
} | ||
else { | ||
this.blobRegistry.delete(url); | ||
} | ||
} | ||
static getBlobFromURL(url) { | ||
return (this.blobRegistry.get(url) || resolveObjectURL(url)); | ||
} | ||
} | ||
PonyfillURL.blobRegistry = new Map(); |
{ | ||
"name": "@whatwg-node/node-fetch", | ||
"version": "0.5.10-alpha-20240321134843-2ae7764efe55eb7970cab335a048aebb4a6d3b0f", | ||
"version": "0.5.10-alpha-20240322103629-07f53b56429d0c2dcdb6dcd240226e0f599203e0", | ||
"description": "Fetch API implementation for Node", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
/// <reference types="packages/node-fetch/src/declarations.js" /> | ||
import FastUrl from '@kamilkisiela/fast-url-parser'; | ||
import { PonyfillBlob } from './Blob.js'; | ||
import { PonyfillURLSearchParams } from './URLSearchParams.js'; | ||
@@ -16,6 +15,2 @@ export declare class PonyfillURL extends FastUrl implements URL { | ||
toJSON(): string; | ||
private static blobRegistry; | ||
static createObjectURL(blob: Blob): string; | ||
static resolveObjectURL(url: string): void; | ||
static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152180
3866