@whatwg-node/node-fetch
Advanced tools
Comparing version 0.7.6-alpha-20250106140930-8f2bc40b53a3e961bb9767f6e5d6ae64f5bf9866 to 0.7.6-alpha-20250106172915-e3e79162475cede19c6fd63458cb73e68a450518
@@ -13,2 +13,4 @@ "use strict"; | ||
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
const node_buffer_1 = require("node:buffer"); | ||
const ReadableStream_js_1 = require("./ReadableStream.js"); | ||
@@ -18,12 +20,12 @@ const utils_js_1 = require("./utils.js"); | ||
if (typeof blobPart === 'string') { | ||
return Buffer.from(blobPart); | ||
return node_buffer_1.Buffer.from(blobPart); | ||
} | ||
else if (Buffer.isBuffer(blobPart)) { | ||
else if (node_buffer_1.Buffer.isBuffer(blobPart)) { | ||
return blobPart; | ||
} | ||
else if ((0, utils_js_1.isArrayBufferView)(blobPart)) { | ||
return Buffer.from(blobPart.buffer, blobPart.byteOffset, blobPart.byteLength); | ||
return node_buffer_1.Buffer.from(blobPart.buffer, blobPart.byteOffset, blobPart.byteLength); | ||
} | ||
else { | ||
return Buffer.from(blobPart); | ||
return node_buffer_1.Buffer.from(blobPart); | ||
} | ||
@@ -86,3 +88,3 @@ } | ||
return blobPart.bytes().then(bytes => { | ||
this._buffer = Buffer.from(bytes); | ||
this._buffer = node_buffer_1.Buffer.from(bytes); | ||
return this._buffer; | ||
@@ -93,3 +95,3 @@ }); | ||
return blobPart.arrayBuffer().then(arrayBuf => { | ||
this._buffer = Buffer.from(arrayBuf, undefined, blobPart.size); | ||
this._buffer = node_buffer_1.Buffer.from(arrayBuf, undefined, blobPart.size); | ||
return this._buffer; | ||
@@ -111,3 +113,3 @@ }); | ||
jobs.push(blobPart.arrayBuffer().then(arrayBuf => { | ||
bufferChunks[i] = Buffer.from(arrayBuf, undefined, blobPart.size); | ||
bufferChunks[i] = node_buffer_1.Buffer.from(arrayBuf, undefined, blobPart.size); | ||
})); | ||
@@ -118,3 +120,3 @@ return undefined; | ||
jobs.push(blobPart.bytes().then(bytes => { | ||
bufferChunks[i] = Buffer.from(bytes); | ||
bufferChunks[i] = node_buffer_1.Buffer.from(bytes); | ||
})); | ||
@@ -128,9 +130,9 @@ return undefined; | ||
if (jobs.length > 0) { | ||
return Promise.all(jobs).then(() => Buffer.concat(bufferChunks, this._size || undefined)); | ||
return Promise.all(jobs).then(() => node_buffer_1.Buffer.concat(bufferChunks, this._size || undefined)); | ||
} | ||
return (0, utils_js_1.fakePromise)(Buffer.concat(bufferChunks, this._size || undefined)); | ||
return (0, utils_js_1.fakePromise)(node_buffer_1.Buffer.concat(bufferChunks, this._size || undefined)); | ||
} | ||
arrayBuffer() { | ||
if (this._buffer) { | ||
// @ts-expect-error - `Buffer` and `ArrayBuffer` are compatible | ||
// @ts-ignore - Mismatch between Buffer and ArrayBuffer | ||
return (0, utils_js_1.fakePromise)(this._buffer); | ||
@@ -146,3 +148,3 @@ } | ||
} | ||
// @ts-expect-error - `Buffer` and `ArrayBuffer` are compatible | ||
// @ts-ignore - Mismatch between Buffer and ArrayBuffer | ||
return this.buffer(); | ||
@@ -155,3 +157,3 @@ } | ||
if (this.blobParts.length === 1) { | ||
if (Buffer.isBuffer(this.blobParts[0])) { | ||
if (node_buffer_1.Buffer.isBuffer(this.blobParts[0])) { | ||
this._buffer = this.blobParts[0]; | ||
@@ -161,3 +163,3 @@ return (0, utils_js_1.fakePromise)(this.blobParts[0]); | ||
if (this.blobParts[0] instanceof Uint8Array) { | ||
this._buffer = Buffer.from(this.blobParts[0]); | ||
this._buffer = node_buffer_1.Buffer.from(this.blobParts[0]); | ||
return (0, utils_js_1.fakePromise)(this.blobParts[0]); | ||
@@ -222,3 +224,3 @@ } | ||
if (typeof blobPart === 'string') { | ||
this._size += Buffer.byteLength(blobPart); | ||
this._size += node_buffer_1.Buffer.byteLength(blobPart); | ||
} | ||
@@ -280,3 +282,3 @@ else if (hasSizeProperty(blobPart)) { | ||
return blobPart.bytes().then(bytes => { | ||
const buf = Buffer.from(bytes); | ||
const buf = node_buffer_1.Buffer.from(bytes); | ||
controller.enqueue(buf); | ||
@@ -287,3 +289,3 @@ }); | ||
return blobPart.arrayBuffer().then(arrayBuffer => { | ||
const buf = Buffer.from(arrayBuffer, undefined, blobPart.size); | ||
const buf = node_buffer_1.Buffer.from(arrayBuffer, undefined, blobPart.size); | ||
controller.enqueue(buf); | ||
@@ -290,0 +292,0 @@ }); |
@@ -5,3 +5,5 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const stream_1 = require("stream"); | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
const node_buffer_1 = require("node:buffer"); | ||
const node_stream_1 = require("node:stream"); | ||
const busboy_1 = tslib_1.__importDefault(require("busboy")); | ||
@@ -45,3 +47,3 @@ const Blob_js_1 = require("./Blob.js"); | ||
if (this._generatedBody?.readable?.destroyed && this._buffer) { | ||
this._generatedBody.readable = stream_1.Readable.from(this._buffer); | ||
this._generatedBody.readable = node_stream_1.Readable.from(this._buffer); | ||
} | ||
@@ -232,2 +234,3 @@ if (this._generatedBody) { | ||
const errMessage = err.message || err.toString(); | ||
// @ts-ignore - `cause` is in `TypeError`in node | ||
reject(new TypeError(errMessage, err.cause)); | ||
@@ -251,3 +254,3 @@ }); | ||
return this.bodyInit.bytes().then(bytes => { | ||
this._buffer = Buffer.from(bytes); | ||
this._buffer = node_buffer_1.Buffer.from(bytes); | ||
return this._buffer; | ||
@@ -258,3 +261,3 @@ }); | ||
return this.bodyInit.arrayBuffer().then(buf => { | ||
this._buffer = Buffer.from(buf, undefined, buf.byteLength); | ||
this._buffer = node_buffer_1.Buffer.from(buf, undefined, buf.byteLength); | ||
return this._buffer; | ||
@@ -269,3 +272,3 @@ }); | ||
} | ||
this._buffer = Buffer.concat(chunks); | ||
this._buffer = node_buffer_1.Buffer.concat(chunks); | ||
return this._buffer; | ||
@@ -278,3 +281,3 @@ }); | ||
arrayBuffer() { | ||
// @ts-expect-error - `Buffer` and `ArrayBuffer` are compatible | ||
// @ts-ignore - Mismatch between Buffer and ArrayBuffer | ||
return this.buffer(); | ||
@@ -325,3 +328,3 @@ } | ||
if (typeof bodyInit === 'string') { | ||
const buffer = Buffer.from(bodyInit); | ||
const buffer = node_buffer_1.Buffer.from(bodyInit); | ||
const contentLength = buffer.byteLength; | ||
@@ -334,3 +337,3 @@ return { | ||
bodyFactory() { | ||
const readable = stream_1.Readable.from(buffer); | ||
const readable = node_stream_1.Readable.from(buffer); | ||
return new ReadableStream_js_1.PonyfillReadableStream(readable); | ||
@@ -340,3 +343,3 @@ }, | ||
} | ||
if (Buffer.isBuffer(bodyInit)) { | ||
if (node_buffer_1.Buffer.isBuffer(bodyInit)) { | ||
return { | ||
@@ -348,3 +351,3 @@ bodyType: BodyInitType.Buffer, | ||
bodyFactory() { | ||
const readable = stream_1.Readable.from(bodyInit); | ||
const readable = node_stream_1.Readable.from(bodyInit); | ||
const body = new ReadableStream_js_1.PonyfillReadableStream(readable); | ||
@@ -356,3 +359,3 @@ return body; | ||
if ((0, utils_js_1.isArrayBufferView)(bodyInit)) { | ||
const buffer = Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength); | ||
const buffer = node_buffer_1.Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength); | ||
return { | ||
@@ -364,3 +367,3 @@ bodyType: BodyInitType.Buffer, | ||
bodyFactory() { | ||
const readable = stream_1.Readable.from(buffer); | ||
const readable = node_stream_1.Readable.from(buffer); | ||
const body = new ReadableStream_js_1.PonyfillReadableStream(readable); | ||
@@ -391,3 +394,3 @@ return body; | ||
const contentLength = bodyInit.byteLength; | ||
const buffer = Buffer.from(bodyInit, undefined, bodyInit.byteLength); | ||
const buffer = node_buffer_1.Buffer.from(bodyInit, undefined, bodyInit.byteLength); | ||
return { | ||
@@ -399,3 +402,3 @@ bodyType: BodyInitType.Buffer, | ||
bodyFactory() { | ||
const readable = stream_1.Readable.from(buffer); | ||
const readable = node_stream_1.Readable.from(buffer); | ||
const body = new ReadableStream_js_1.PonyfillReadableStream(readable); | ||
@@ -406,3 +409,3 @@ return body; | ||
} | ||
if (bodyInit instanceof stream_1.Readable) { | ||
if (bodyInit instanceof node_stream_1.Readable) { | ||
return { | ||
@@ -425,3 +428,3 @@ bodyType: BodyInitType.Readable, | ||
bodyFactory() { | ||
const body = new ReadableStream_js_1.PonyfillReadableStream(stream_1.Readable.from(bodyInit.toString())); | ||
const body = new ReadableStream_js_1.PonyfillReadableStream(node_stream_1.Readable.from(bodyInit.toString())); | ||
return body; | ||
@@ -458,3 +461,3 @@ }, | ||
bodyFactory() { | ||
const readable = stream_1.Readable.from(bodyInit); | ||
const readable = node_stream_1.Readable.from(bodyInit); | ||
return new ReadableStream_js_1.PonyfillReadableStream(readable); | ||
@@ -461,0 +464,0 @@ }, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchPonyfill = fetchPonyfill; | ||
const fs_1 = require("fs"); | ||
const url_1 = require("url"); | ||
const node_buffer_1 = require("node:buffer"); | ||
const node_fs_1 = require("node:fs"); | ||
const node_url_1 = require("node:url"); | ||
const fetchCurl_js_1 = require("./fetchCurl.js"); | ||
@@ -14,4 +15,4 @@ const fetchNodeHttp_js_1 = require("./fetchNodeHttp.js"); | ||
function getResponseForFile(url) { | ||
const path = (0, url_1.fileURLToPath)(url); | ||
const readable = (0, fs_1.createReadStream)(path); | ||
const path = (0, node_url_1.fileURLToPath)(url); | ||
const readable = (0, node_fs_1.createReadStream)(path); | ||
return new Response_js_1.PonyfillResponse(readable); | ||
@@ -23,3 +24,3 @@ } | ||
if (mimeType.endsWith(BASE64_SUFFIX)) { | ||
const buffer = Buffer.from(data, 'base64url'); | ||
const buffer = node_buffer_1.Buffer.from(data, 'base64url'); | ||
const realMimeType = mimeType.slice(0, -BASE64_SUFFIX.length); | ||
@@ -26,0 +27,0 @@ return new Response_js_1.PonyfillResponse(buffer, { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchCurl = fetchCurl; | ||
const stream_1 = require("stream"); | ||
const tls_1 = require("tls"); | ||
const node_stream_1 = require("node:stream"); | ||
const promises_1 = require("node:stream/promises"); | ||
const node_tls_1 = require("node:tls"); | ||
const Response_js_1 = require("./Response.js"); | ||
@@ -20,3 +21,3 @@ const utils_js_1 = require("./utils.js"); | ||
else { | ||
curlHandle.setOpt('CAINFO_BLOB', tls_1.rootCertificates.join('\n')); | ||
curlHandle.setOpt('CAINFO_BLOB', node_tls_1.rootCertificates.join('\n')); | ||
} | ||
@@ -38,3 +39,3 @@ curlHandle.enable(CurlFeature.StreamResponse); | ||
? fetchRequest.body | ||
: stream_1.Readable.from(fetchRequest.body) | ||
: node_stream_1.Readable.from(fetchRequest.body) | ||
: null); | ||
@@ -105,5 +106,4 @@ if (nodeReadable) { | ||
curlHandle.once('stream', function streamListener(stream, status, headersBuf) { | ||
const outputStream = new stream_1.PassThrough(); | ||
stream_1.promises | ||
.pipeline(stream, outputStream, { | ||
const outputStream = new node_stream_1.PassThrough(); | ||
(0, promises_1.pipeline)(stream, outputStream, { | ||
end: true, | ||
@@ -110,0 +110,0 @@ signal: fetchRequest['_signal'] ?? undefined, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchNodeHttp = fetchNodeHttp; | ||
const http_1 = require("http"); | ||
const https_1 = require("https"); | ||
const stream_1 = require("stream"); | ||
const zlib_1 = require("zlib"); | ||
const node_http_1 = require("node:http"); | ||
const node_https_1 = require("node:https"); | ||
const node_stream_1 = require("node:stream"); | ||
const promises_1 = require("node:stream/promises"); | ||
const node_zlib_1 = require("node:zlib"); | ||
const Request_js_1 = require("./Request.js"); | ||
@@ -14,6 +15,6 @@ const Response_js_1 = require("./Response.js"); | ||
if (url.startsWith('http:')) { | ||
return http_1.request; | ||
return node_http_1.request; | ||
} | ||
else if (url.startsWith('https:')) { | ||
return https_1.request; | ||
return node_https_1.request; | ||
} | ||
@@ -29,3 +30,3 @@ throw new Error(`Unsupported protocol: ${url.split(':')[0] || url}`); | ||
? fetchRequest.body | ||
: stream_1.Readable.from(fetchRequest.body) | ||
: node_stream_1.Readable.from(fetchRequest.body) | ||
: null); | ||
@@ -61,17 +62,17 @@ const headersSerializer = fetchRequest.headersSerializer || utils_js_1.getHeadersObj; | ||
case 'gzip': | ||
outputStream = (0, zlib_1.createGunzip)(); | ||
outputStream = (0, node_zlib_1.createGunzip)(); | ||
break; | ||
case 'x-deflate': | ||
case 'deflate': | ||
outputStream = (0, zlib_1.createInflate)(); | ||
outputStream = (0, node_zlib_1.createInflate)(); | ||
break; | ||
case 'x-deflate-raw': | ||
case 'deflate-raw': | ||
outputStream = (0, zlib_1.createInflateRaw)(); | ||
outputStream = (0, node_zlib_1.createInflateRaw)(); | ||
break; | ||
case 'br': | ||
outputStream = (0, zlib_1.createBrotliDecompress)(); | ||
outputStream = (0, node_zlib_1.createBrotliDecompress)(); | ||
break; | ||
default: | ||
outputStream = new stream_1.PassThrough(); | ||
outputStream = new node_stream_1.PassThrough(); | ||
} | ||
@@ -96,4 +97,3 @@ if (nodeResponse.headers.location) { | ||
} | ||
stream_1.promises | ||
.pipeline(nodeResponse, outputStream, { | ||
(0, promises_1.pipeline)(nodeResponse, outputStream, { | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
@@ -109,3 +109,3 @@ end: true, | ||
const statusCode = nodeResponse.statusCode || 200; | ||
let statusText = nodeResponse.statusMessage || http_1.STATUS_CODES[statusCode]; | ||
let statusText = nodeResponse.statusMessage || node_http_1.STATUS_CODES[statusCode]; | ||
if (statusText == null) { | ||
@@ -112,0 +112,0 @@ statusText = ''; |
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.getStreamFromFormData = getStreamFromFormData; | ||
const node_buffer_1 = require("node:buffer"); | ||
const IteratorObject_js_1 = require("./IteratorObject.js"); | ||
@@ -83,3 +84,3 @@ const ReadableStream_js_1 = require("./ReadableStream.js"); | ||
if (!sentInitialHeader) { | ||
controller.enqueue(Buffer.from(`--${boundary}\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`--${boundary}\r\n`)); | ||
sentInitialHeader = true; | ||
@@ -90,3 +91,3 @@ } | ||
if (!sentInitialHeader) { | ||
controller.enqueue(Buffer.from(`--${boundary}--\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`--${boundary}--\r\n`)); | ||
controller.close(); | ||
@@ -100,4 +101,4 @@ } | ||
if (typeof value === 'string') { | ||
controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`)); | ||
controller.enqueue(Buffer.from(value)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(value)); | ||
} | ||
@@ -109,4 +110,4 @@ else { | ||
} | ||
controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"${filenamePart}\r\n`)); | ||
controller.enqueue(Buffer.from(`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`Content-Disposition: form-data; name="${key}"${filenamePart}\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`)); | ||
const entryStream = value.stream(); | ||
@@ -118,11 +119,11 @@ for await (const chunk of entryStream) { | ||
if (entries.length === 0) { | ||
controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}--\r\n`)); | ||
controller.close(); | ||
} | ||
else { | ||
controller.enqueue(Buffer.from(`\r\n--${boundary}\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}\r\n`)); | ||
} | ||
} | ||
else { | ||
controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`)); | ||
controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}--\r\n`)); | ||
controller.close(); | ||
@@ -129,0 +130,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillReadableStream = void 0; | ||
const stream_1 = require("stream"); | ||
const node_buffer_1 = require("node:buffer"); | ||
const node_stream_1 = require("node:stream"); | ||
const utils_js_1 = require("./utils.js"); | ||
@@ -13,3 +14,3 @@ function createController(desiredSize, readable) { | ||
enqueue(chunk) { | ||
const buf = typeof chunk === 'string' ? Buffer.from(chunk) : chunk; | ||
const buf = typeof chunk === 'string' ? node_buffer_1.Buffer.from(chunk) : chunk; | ||
if (!flushed) { | ||
@@ -41,3 +42,3 @@ chunks.push(buf); | ||
if (chunks.length > 0) { | ||
const concatenated = chunks.length > 1 ? Buffer.concat(chunks) : chunks[0]; | ||
const concatenated = chunks.length > 1 ? node_buffer_1.Buffer.concat(chunks) : chunks[0]; | ||
readable.push(concatenated); | ||
@@ -65,3 +66,3 @@ chunks = []; | ||
else if (isReadableStream(underlyingSource)) { | ||
this.readable = stream_1.Readable.fromWeb(underlyingSource); | ||
this.readable = node_stream_1.Readable.fromWeb(underlyingSource); | ||
} | ||
@@ -86,3 +87,3 @@ else { | ||
}; | ||
this.readable = new stream_1.Readable({ | ||
this.readable = new node_stream_1.Readable({ | ||
read(desiredSize) { | ||
@@ -219,3 +220,3 @@ if (ongoing) { | ||
static from(iterable) { | ||
return new PonyfillReadableStream(stream_1.Readable.from(iterable)); | ||
return new PonyfillReadableStream(node_stream_1.Readable.from(iterable)); | ||
} | ||
@@ -222,0 +223,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillRequest = void 0; | ||
const http_1 = require("http"); | ||
const https_1 = require("https"); | ||
const node_http_1 = require("node:http"); | ||
const node_https_1 = require("node:https"); | ||
const Body_js_1 = require("./Body.js"); | ||
@@ -73,6 +73,6 @@ const Headers_js_1 = require("./Headers.js"); | ||
} | ||
else if (protocol.startsWith('http:') && requestInit.agent instanceof http_1.Agent) { | ||
else if (protocol.startsWith('http:') && requestInit.agent instanceof node_http_1.Agent) { | ||
this.agent = requestInit.agent; | ||
} | ||
else if (protocol.startsWith('https:') && requestInit.agent instanceof https_1.Agent) { | ||
else if (protocol.startsWith('https:') && requestInit.agent instanceof node_https_1.Agent) { | ||
this.agent = requestInit.agent; | ||
@@ -79,0 +79,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillResponse = void 0; | ||
const http_1 = require("http"); | ||
const node_http_1 = require("node:http"); | ||
const Body_js_1 = require("./Body.js"); | ||
@@ -17,3 +17,3 @@ const Headers_js_1 = require("./Headers.js"); | ||
this.status = init?.status || 200; | ||
this.statusText = init?.statusText || http_1.STATUS_CODES[this.status] || 'OK'; | ||
this.statusText = init?.statusText || node_http_1.STATUS_CODES[this.status] || 'OK'; | ||
this.url = init?.url || ''; | ||
@@ -20,0 +20,0 @@ this.redirected = init?.redirected || false; |
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.PonyfillBtoa = PonyfillBtoa; | ||
const node_buffer_1 = require("node:buffer"); | ||
const utils_js_1 = require("./utils.js"); | ||
@@ -13,3 +14,3 @@ class PonyfillTextEncoder { | ||
encode(input) { | ||
return Buffer.from(input, this.encoding); | ||
return node_buffer_1.Buffer.from(input, this.encoding); | ||
} | ||
@@ -38,9 +39,9 @@ encodeInto(source, destination) { | ||
decode(input) { | ||
if (Buffer.isBuffer(input)) { | ||
if (node_buffer_1.Buffer.isBuffer(input)) { | ||
return input.toString(this.encoding); | ||
} | ||
if ((0, utils_js_1.isArrayBufferView)(input)) { | ||
return Buffer.from(input.buffer, input.byteOffset, input.byteLength).toString(this.encoding); | ||
return node_buffer_1.Buffer.from(input.buffer, input.byteOffset, input.byteLength).toString(this.encoding); | ||
} | ||
return Buffer.from(input).toString(this.encoding); | ||
return node_buffer_1.Buffer.from(input).toString(this.encoding); | ||
} | ||
@@ -50,3 +51,3 @@ } | ||
function PonyfillBtoa(input) { | ||
return Buffer.from(input, 'binary').toString('base64'); | ||
return node_buffer_1.Buffer.from(input, 'binary').toString('base64'); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillURL = void 0; | ||
const buffer_1 = require("buffer"); | ||
const crypto_1 = require("crypto"); | ||
const tslib_1 = require("tslib"); | ||
const node_buffer_1 = tslib_1.__importDefault(require("node:buffer")); | ||
const node_crypto_1 = require("node:crypto"); | ||
class PonyfillURL extends URL { | ||
@@ -10,3 +11,3 @@ // This part is only needed to handle `PonyfillBlob` objects | ||
static createObjectURL(blob) { | ||
const blobUrl = `blob:whatwgnode:${(0, crypto_1.randomUUID)()}`; | ||
const blobUrl = `blob:whatwgnode:${(0, node_crypto_1.randomUUID)()}`; | ||
this.blobRegistry.set(blobUrl, blob); | ||
@@ -24,5 +25,5 @@ return blobUrl; | ||
static getBlobFromURL(url) { | ||
return (this.blobRegistry.get(url) || (0, buffer_1.resolveObjectURL)(url)); | ||
return (this.blobRegistry.get(url) || node_buffer_1.default?.resolveObjectURL?.(url)); | ||
} | ||
} | ||
exports.PonyfillURL = PonyfillURL; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillWritableStream = void 0; | ||
const stream_1 = require("stream"); | ||
const node_stream_1 = require("node:stream"); | ||
const utils_js_1 = require("./utils.js"); | ||
@@ -9,7 +9,7 @@ class PonyfillWritableStream { | ||
constructor(underlyingSink) { | ||
if (underlyingSink instanceof stream_1.Writable) { | ||
if (underlyingSink instanceof node_stream_1.Writable) { | ||
this.writable = underlyingSink; | ||
} | ||
else if (underlyingSink) { | ||
const writable = new stream_1.Writable({ | ||
const writable = new node_stream_1.Writable({ | ||
write(chunk, _encoding, callback) { | ||
@@ -99,3 +99,3 @@ try { | ||
else { | ||
this.writable = new stream_1.Writable(); | ||
this.writable = new node_stream_1.Writable(); | ||
} | ||
@@ -102,0 +102,0 @@ } |
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
import { Buffer } from 'node:buffer'; | ||
import { PonyfillReadableStream } from './ReadableStream.js'; | ||
@@ -117,3 +119,3 @@ import { fakePromise, isArrayBufferView } from './utils.js'; | ||
if (this._buffer) { | ||
// @ts-expect-error - `Buffer` and `ArrayBuffer` are compatible | ||
// @ts-ignore - Mismatch between Buffer and ArrayBuffer | ||
return fakePromise(this._buffer); | ||
@@ -129,3 +131,3 @@ } | ||
} | ||
// @ts-expect-error - `Buffer` and `ArrayBuffer` are compatible | ||
// @ts-ignore - Mismatch between Buffer and ArrayBuffer | ||
return this.buffer(); | ||
@@ -132,0 +134,0 @@ } |
@@ -1,2 +0,4 @@ | ||
import { Readable } from 'stream'; | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
import { Buffer } from 'node:buffer'; | ||
import { Readable } from 'node:stream'; | ||
import busboy from 'busboy'; | ||
@@ -226,2 +228,3 @@ import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js'; | ||
const errMessage = err.message || err.toString(); | ||
// @ts-ignore - `cause` is in `TypeError`in node | ||
reject(new TypeError(errMessage, err.cause)); | ||
@@ -269,3 +272,3 @@ }); | ||
arrayBuffer() { | ||
// @ts-expect-error - `Buffer` and `ArrayBuffer` are compatible | ||
// @ts-ignore - Mismatch between Buffer and ArrayBuffer | ||
return this.buffer(); | ||
@@ -272,0 +275,0 @@ } |
@@ -1,3 +0,4 @@ | ||
import { createReadStream } from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { Buffer } from 'node:buffer'; | ||
import { createReadStream } from 'node:fs'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { fetchCurl } from './fetchCurl.js'; | ||
@@ -4,0 +5,0 @@ import { fetchNodeHttp } from './fetchNodeHttp.js'; |
@@ -1,3 +0,4 @@ | ||
import { PassThrough, Readable, promises as streamPromises } from 'stream'; | ||
import { rootCertificates } from 'tls'; | ||
import { PassThrough, Readable } from 'node:stream'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import { rootCertificates } from 'node:tls'; | ||
import { PonyfillResponse } from './Response.js'; | ||
@@ -101,4 +102,3 @@ import { createDeferredPromise, defaultHeadersSerializer, isNodeReadable } from './utils.js'; | ||
const outputStream = new PassThrough(); | ||
streamPromises | ||
.pipeline(stream, outputStream, { | ||
pipeline(stream, outputStream, { | ||
end: true, | ||
@@ -105,0 +105,0 @@ signal: fetchRequest['_signal'] ?? undefined, |
@@ -1,5 +0,6 @@ | ||
import { request as httpRequest, STATUS_CODES } from 'http'; | ||
import { request as httpsRequest } from 'https'; | ||
import { PassThrough, Readable, promises as streamPromises } from 'stream'; | ||
import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'zlib'; | ||
import { request as httpRequest, STATUS_CODES } from 'node:http'; | ||
import { request as httpsRequest } from 'node:https'; | ||
import { PassThrough, Readable } from 'node:stream'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib'; | ||
import { PonyfillRequest } from './Request.js'; | ||
@@ -90,4 +91,3 @@ import { PonyfillResponse } from './Response.js'; | ||
} | ||
streamPromises | ||
.pipeline(nodeResponse, outputStream, { | ||
pipeline(nodeResponse, outputStream, { | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
@@ -94,0 +94,0 @@ end: true, |
@@ -0,1 +1,2 @@ | ||
import { Buffer } from 'node:buffer'; | ||
import { PonyfillIteratorObject } from './IteratorObject.js'; | ||
@@ -2,0 +3,0 @@ import { PonyfillReadableStream } from './ReadableStream.js'; |
@@ -1,2 +0,3 @@ | ||
import { Readable } from 'stream'; | ||
import { Buffer } from 'node:buffer'; | ||
import { Readable } from 'node:stream'; | ||
import { fakePromise } from './utils.js'; | ||
@@ -3,0 +4,0 @@ function createController(desiredSize, readable) { |
@@ -1,3 +0,3 @@ | ||
import { Agent as HTTPAgent } from 'http'; | ||
import { Agent as HTTPSAgent } from 'https'; | ||
import { Agent as HTTPAgent } from 'node:http'; | ||
import { Agent as HTTPSAgent } from 'node:https'; | ||
import { PonyfillBody } from './Body.js'; | ||
@@ -4,0 +4,0 @@ import { isHeadersLike, PonyfillHeaders } from './Headers.js'; |
@@ -1,2 +0,2 @@ | ||
import { STATUS_CODES } from 'http'; | ||
import { STATUS_CODES } from 'node:http'; | ||
import { PonyfillBody } from './Body.js'; | ||
@@ -3,0 +3,0 @@ import { isHeadersLike, PonyfillHeaders } from './Headers.js'; |
@@ -0,1 +1,2 @@ | ||
import { Buffer } from 'node:buffer'; | ||
import { isArrayBufferView } from './utils.js'; | ||
@@ -2,0 +3,0 @@ export class PonyfillTextEncoder { |
@@ -1,3 +0,3 @@ | ||
import { resolveObjectURL } from 'buffer'; | ||
import { randomUUID } from 'crypto'; | ||
import NodeBuffer from 'node:buffer'; | ||
import { randomUUID } from 'node:crypto'; | ||
export class PonyfillURL extends URL { | ||
@@ -20,4 +20,4 @@ // This part is only needed to handle `PonyfillBlob` objects | ||
static getBlobFromURL(url) { | ||
return (this.blobRegistry.get(url) || resolveObjectURL(url)); | ||
return (this.blobRegistry.get(url) || NodeBuffer?.resolveObjectURL?.(url)); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Writable } from 'stream'; | ||
import { Writable } from 'node:stream'; | ||
import { fakePromise } from './utils.js'; | ||
@@ -3,0 +3,0 @@ export class PonyfillWritableStream { |
{ | ||
"name": "@whatwg-node/node-fetch", | ||
"version": "0.7.6-alpha-20250106140930-8f2bc40b53a3e961bb9767f6e5d6ae64f5bf9866", | ||
"version": "0.7.6-alpha-20250106172915-e3e79162475cede19c6fd63458cb73e68a450518", | ||
"description": "Fetch API implementation for Node", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -0,1 +1,2 @@ | ||
import { Buffer } from 'node:buffer'; | ||
interface BlobOptions { | ||
@@ -2,0 +3,0 @@ /** |
@@ -1,2 +0,3 @@ | ||
import { Readable } from 'stream'; | ||
import { Buffer } from 'node:buffer'; | ||
import { Readable } from 'node:stream'; | ||
import { PonyfillBlob } from './Blob.js'; | ||
@@ -3,0 +4,0 @@ import { PonyfillFormData } from './FormData.js'; |
@@ -1,2 +0,2 @@ | ||
import { Readable } from 'stream'; | ||
import { Readable } from 'node:stream'; | ||
export declare class PonyfillReadableStream<T> implements ReadableStream<T> { | ||
@@ -3,0 +3,0 @@ readable: Readable; |
@@ -1,3 +0,3 @@ | ||
import { Agent as HTTPAgent } from 'http'; | ||
import { Agent as HTTPSAgent } from 'https'; | ||
import { Agent as HTTPAgent } from 'node:http'; | ||
import { Agent as HTTPSAgent } from 'node:https'; | ||
import { BodyPonyfillInit, PonyfillBody, PonyfillBodyOptions } from './Body.js'; | ||
@@ -4,0 +4,0 @@ import { PonyfillHeadersInit } from './Headers.js'; |
@@ -0,1 +1,2 @@ | ||
import { Buffer } from 'node:buffer'; | ||
export declare class PonyfillTextEncoder implements TextEncoder { | ||
@@ -2,0 +3,0 @@ encoding: BufferEncoding; |
@@ -1,2 +0,2 @@ | ||
import { Readable } from 'stream'; | ||
import { Readable } from 'node:stream'; | ||
export declare function getHeadersObj(headers: Headers): Record<string, string>; | ||
@@ -3,0 +3,0 @@ export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[]; |
@@ -1,2 +0,2 @@ | ||
import { Writable } from 'stream'; | ||
import { Writable } from 'node:stream'; | ||
export declare class PonyfillWritableStream<W = any> implements WritableStream<W> { | ||
@@ -3,0 +3,0 @@ writable: Writable; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
222516
5635
10
0