@whatwg-node/node-fetch
Advanced tools
Comparing version 0.4.0-alpha-20230215090500-a3d0322 to 0.4.0-alpha-20230515120642-be23d36
@@ -9,3 +9,3 @@ "use strict"; | ||
const url_1 = require("url"); | ||
const AbortError_js_1 = require("./AbortError.js"); | ||
const zlib_1 = require("zlib"); | ||
const Blob_js_1 = require("./Blob.js"); | ||
@@ -75,9 +75,4 @@ const Request_js_1 = require("./Request.js"); | ||
: null); | ||
const nodeHeaders = (0, utils_js_1.getHeadersObj)(fetchRequest.headers); | ||
const abortListener = function abortListener(event) { | ||
nodeRequest.destroy(); | ||
const reason = event.detail; | ||
reject(new AbortError_js_1.PonyfillAbortError(reason)); | ||
}; | ||
fetchRequest.signal.addEventListener('abort', abortListener); | ||
const headersSerializer = fetchRequest.headersSerializer || utils_js_1.getHeadersObj; | ||
const nodeHeaders = headersSerializer(fetchRequest.headers); | ||
const nodeRequest = requestFn(fetchRequest.url, { | ||
@@ -87,4 +82,20 @@ // signal: fetchRequest.signal will be added when v14 reaches EOL | ||
headers: nodeHeaders, | ||
signal: fetchRequest.signal, | ||
}); | ||
nodeRequest.once('response', nodeResponse => { | ||
let responseBody = nodeResponse; | ||
const contentEncoding = nodeResponse.headers['content-encoding']; | ||
switch (contentEncoding) { | ||
case 'x-gzip': | ||
case 'gzip': | ||
responseBody = nodeResponse.pipe((0, zlib_1.createGunzip)()); | ||
break; | ||
case 'x-deflate': | ||
case 'deflate': | ||
responseBody = nodeResponse.pipe((0, zlib_1.createInflate)()); | ||
break; | ||
case 'br': | ||
responseBody = nodeResponse.pipe((0, zlib_1.createBrotliDecompress)()); | ||
break; | ||
} | ||
if (nodeResponse.headers.location) { | ||
@@ -109,3 +120,3 @@ if (fetchRequest.redirect === 'error') { | ||
const responseHeaders = nodeResponse.headers; | ||
const ponyfillResponse = new Response_js_1.PonyfillResponse(nodeResponse, { | ||
const ponyfillResponse = new Response_js_1.PonyfillResponse(responseBody, { | ||
status: nodeResponse.statusCode, | ||
@@ -112,0 +123,0 @@ statusText: nodeResponse.statusMessage, |
@@ -47,2 +47,15 @@ "use strict"; | ||
} | ||
entries() { | ||
return this[Symbol.iterator](); | ||
} | ||
keys() { | ||
return this.map.keys(); | ||
} | ||
*values() { | ||
for (const values of this.map.values()) { | ||
for (const value of values) { | ||
yield value; | ||
} | ||
} | ||
} | ||
forEach(callback) { | ||
@@ -49,0 +62,0 @@ for (const [key, value] of this) { |
@@ -114,2 +114,8 @@ "use strict"; | ||
} | ||
keys() { | ||
return this.getMap().keys(); | ||
} | ||
values() { | ||
return this.getMap().values(); | ||
} | ||
entries() { | ||
@@ -116,0 +122,0 @@ return this.getMap().entries(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.URLSearchParams = exports.URL = exports.btoa = exports.TextDecoder = exports.TextEncoder = exports.Blob = exports.AbortError = exports.AbortSignal = exports.AbortController = exports.FormData = exports.File = exports.ReadableStream = exports.Response = exports.Request = exports.Body = exports.Headers = exports.fetch = void 0; | ||
exports.URLSearchParams = exports.URL = exports.btoa = exports.TextDecoder = exports.TextEncoder = exports.Blob = exports.FormData = exports.File = exports.ReadableStream = exports.Response = exports.Request = exports.Body = exports.Headers = exports.fetch = void 0; | ||
var fetch_js_1 = require("./fetch.js"); | ||
@@ -20,8 +20,2 @@ Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_js_1.fetchPonyfill; } }); | ||
Object.defineProperty(exports, "FormData", { enumerable: true, get: function () { return FormData_js_1.PonyfillFormData; } }); | ||
var AbortController_js_1 = require("./AbortController.js"); | ||
Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return AbortController_js_1.PonyfillAbortController; } }); | ||
var AbortSignal_js_1 = require("./AbortSignal.js"); | ||
Object.defineProperty(exports, "AbortSignal", { enumerable: true, get: function () { return AbortSignal_js_1.PonyfillAbortSignal; } }); | ||
var AbortError_js_1 = require("./AbortError.js"); | ||
Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return AbortError_js_1.PonyfillAbortError; } }); | ||
var Blob_js_1 = require("./Blob.js"); | ||
@@ -28,0 +22,0 @@ Object.defineProperty(exports, "Blob", { enumerable: true, get: function () { return Blob_js_1.PonyfillBlob; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillRequest = void 0; | ||
const AbortController_js_1 = require("./AbortController.js"); | ||
const Body_js_1 = require("./Body.js"); | ||
const Headers_js_1 = require("./Headers.js"); | ||
const utils_js_1 = require("./utils.js"); | ||
function isRequest(input) { | ||
@@ -44,3 +44,4 @@ return input[Symbol.toStringTag] === 'Request'; | ||
this.referrerPolicy = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.referrerPolicy) || 'no-referrer'; | ||
this.signal = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.signal) || new AbortController_js_1.PonyfillAbortController().signal; | ||
this.signal = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.signal) || new AbortController().signal; | ||
this.headersSerializer = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.headersSerializer) || utils_js_1.getHeadersObj; | ||
this.url = url || ''; | ||
@@ -47,0 +48,0 @@ const contentTypeInHeaders = this.headers.get('content-type'); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PonyfillResponse = void 0; | ||
const http_1 = require("http"); | ||
const Body_js_1 = require("./Body.js"); | ||
@@ -18,3 +19,3 @@ const Headers_js_1 = require("./Headers.js"); | ||
this.status = init.status || 200; | ||
this.statusText = init.statusText || 'OK'; | ||
this.statusText = init.statusText || http_1.STATUS_CODES[this.status] || 'OK'; | ||
this.url = init.url || ''; | ||
@@ -21,0 +22,0 @@ this.redirected = init.redirected || false; |
@@ -102,3 +102,6 @@ "use strict"; | ||
} | ||
get size() { | ||
return Object.keys(this.params).length; | ||
} | ||
} | ||
exports.PonyfillURLSearchParams = PonyfillURLSearchParams; |
@@ -6,3 +6,3 @@ import { createReadStream } from 'fs'; | ||
import { fileURLToPath } from 'url'; | ||
import { PonyfillAbortError } from './AbortError.js'; | ||
import { createBrotliDecompress, createGunzip, createInflate } from 'zlib'; | ||
import { PonyfillBlob } from './Blob.js'; | ||
@@ -72,9 +72,4 @@ import { PonyfillRequest } from './Request.js'; | ||
: null); | ||
const nodeHeaders = getHeadersObj(fetchRequest.headers); | ||
const abortListener = function abortListener(event) { | ||
nodeRequest.destroy(); | ||
const reason = event.detail; | ||
reject(new PonyfillAbortError(reason)); | ||
}; | ||
fetchRequest.signal.addEventListener('abort', abortListener); | ||
const headersSerializer = fetchRequest.headersSerializer || getHeadersObj; | ||
const nodeHeaders = headersSerializer(fetchRequest.headers); | ||
const nodeRequest = requestFn(fetchRequest.url, { | ||
@@ -84,4 +79,20 @@ // signal: fetchRequest.signal will be added when v14 reaches EOL | ||
headers: nodeHeaders, | ||
signal: fetchRequest.signal, | ||
}); | ||
nodeRequest.once('response', nodeResponse => { | ||
let responseBody = nodeResponse; | ||
const contentEncoding = nodeResponse.headers['content-encoding']; | ||
switch (contentEncoding) { | ||
case 'x-gzip': | ||
case 'gzip': | ||
responseBody = nodeResponse.pipe(createGunzip()); | ||
break; | ||
case 'x-deflate': | ||
case 'deflate': | ||
responseBody = nodeResponse.pipe(createInflate()); | ||
break; | ||
case 'br': | ||
responseBody = nodeResponse.pipe(createBrotliDecompress()); | ||
break; | ||
} | ||
if (nodeResponse.headers.location) { | ||
@@ -106,3 +117,3 @@ if (fetchRequest.redirect === 'error') { | ||
const responseHeaders = nodeResponse.headers; | ||
const ponyfillResponse = new PonyfillResponse(nodeResponse, { | ||
const ponyfillResponse = new PonyfillResponse(responseBody, { | ||
status: nodeResponse.statusCode, | ||
@@ -109,0 +120,0 @@ statusText: nodeResponse.statusMessage, |
@@ -44,2 +44,15 @@ import { PonyfillFile } from './File.js'; | ||
} | ||
entries() { | ||
return this[Symbol.iterator](); | ||
} | ||
keys() { | ||
return this.map.keys(); | ||
} | ||
*values() { | ||
for (const values of this.map.values()) { | ||
for (const value of values) { | ||
yield value; | ||
} | ||
} | ||
} | ||
forEach(callback) { | ||
@@ -46,0 +59,0 @@ for (const [key, value] of this) { |
@@ -111,2 +111,8 @@ function isHeadersLike(headers) { | ||
} | ||
keys() { | ||
return this.getMap().keys(); | ||
} | ||
values() { | ||
return this.getMap().values(); | ||
} | ||
entries() { | ||
@@ -113,0 +119,0 @@ return this.getMap().entries(); |
@@ -9,5 +9,2 @@ export { fetchPonyfill as fetch } from './fetch.js'; | ||
export { PonyfillFormData as FormData } from './FormData.js'; | ||
export { PonyfillAbortController as AbortController } from './AbortController.js'; | ||
export { PonyfillAbortSignal as AbortSignal } from './AbortSignal.js'; | ||
export { PonyfillAbortError as AbortError } from './AbortError.js'; | ||
export { PonyfillBlob as Blob } from './Blob.js'; | ||
@@ -14,0 +11,0 @@ export { PonyfillTextEncoder as TextEncoder, PonyfillTextDecoder as TextDecoder, PonyfillBtoa as btoa, } from './TextEncoderDecoder.js'; |
@@ -1,4 +0,4 @@ | ||
import { PonyfillAbortController } from './AbortController.js'; | ||
import { PonyfillBody } from './Body.js'; | ||
import { PonyfillHeaders } from './Headers.js'; | ||
import { getHeadersObj } from './utils.js'; | ||
function isRequest(input) { | ||
@@ -41,3 +41,4 @@ return input[Symbol.toStringTag] === 'Request'; | ||
this.referrerPolicy = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.referrerPolicy) || 'no-referrer'; | ||
this.signal = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.signal) || new PonyfillAbortController().signal; | ||
this.signal = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.signal) || new AbortController().signal; | ||
this.headersSerializer = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.headersSerializer) || getHeadersObj; | ||
this.url = url || ''; | ||
@@ -44,0 +45,0 @@ const contentTypeInHeaders = this.headers.get('content-type'); |
@@ -0,1 +1,2 @@ | ||
import { STATUS_CODES } from 'http'; | ||
import { PonyfillBody } from './Body.js'; | ||
@@ -15,3 +16,3 @@ import { PonyfillHeaders } from './Headers.js'; | ||
this.status = init.status || 200; | ||
this.statusText = init.statusText || 'OK'; | ||
this.statusText = init.statusText || STATUS_CODES[this.status] || 'OK'; | ||
this.url = init.url || ''; | ||
@@ -18,0 +19,0 @@ this.redirected = init.redirected || false; |
@@ -98,2 +98,5 @@ import FastQuerystring from 'fast-querystring'; | ||
} | ||
get size() { | ||
return Object.keys(this.params).length; | ||
} | ||
} |
{ | ||
"name": "@whatwg-node/node-fetch", | ||
"version": "0.4.0-alpha-20230215090500-a3d0322", | ||
"version": "0.4.0-alpha-20230515120642-be23d36", | ||
"description": "Fetch API implementation for Node", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"@types/node": "^18.0.6" | ||
}, | ||
"dependencies": { | ||
"@whatwg-node/events": "^0.0.2", | ||
"@whatwg-node/events": "0.1.0-alpha-20230515120642-be23d36", | ||
"busboy": "^1.6.0", | ||
@@ -12,0 +9,0 @@ "fast-querystring": "^1.1.1", |
/// <reference types="node" /> | ||
import { BlobOptions } from 'buffer'; | ||
interface BlobOptions { | ||
/** | ||
* @default 'utf8' | ||
*/ | ||
encoding?: BufferEncoding | undefined; | ||
/** | ||
* The Blob content-type. The intent is for `type` to convey | ||
* the MIME media type of the data, however no validation of the type format | ||
* is performed. | ||
*/ | ||
type?: string | undefined; | ||
} | ||
export declare class PonyfillBlob implements Blob { | ||
@@ -19,1 +30,2 @@ private blobParts; | ||
} | ||
export {}; |
@@ -12,4 +12,7 @@ import { PonyfillBlob } from './Blob.js'; | ||
[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>; | ||
entries(): IterableIterator<[string, FormDataEntryValue]>; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<FormDataEntryValue>; | ||
forEach(callback: (value: FormDataEntryValue, key: string, parent: this) => void): void; | ||
} | ||
export declare function getStreamFromFormData(formData: FormData, boundary?: string): PonyfillReadableStream<Uint8Array>; |
@@ -17,4 +17,6 @@ export type PonyfillHeadersInit = [string, string][] | Record<string, string | string[] | undefined> | Headers; | ||
forEach(callback: (value: string, key: string, parent: Headers) => void): void; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
entries(): IterableIterator<[string, string]>; | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
} |
@@ -9,5 +9,2 @@ export { fetchPonyfill as fetch } from './fetch.js'; | ||
export { PonyfillFormData as FormData } from './FormData.js'; | ||
export { PonyfillAbortController as AbortController } from './AbortController.js'; | ||
export { PonyfillAbortSignal as AbortSignal } from './AbortSignal.js'; | ||
export { PonyfillAbortError as AbortError } from './AbortError.js'; | ||
export { PonyfillBlob as Blob } from './Blob.js'; | ||
@@ -14,0 +11,0 @@ export { PonyfillTextEncoder as TextEncoder, PonyfillTextDecoder as TextDecoder, PonyfillBtoa as btoa, } from './TextEncoderDecoder.js'; |
@@ -6,5 +6,8 @@ import { BodyPonyfillInit, PonyfillBody, PonyfillBodyOptions } from './Body.js'; | ||
headers?: PonyfillHeadersInit; | ||
headersSerializer?: HeadersSerializer; | ||
}; | ||
type HeadersSerializer = (headers: Headers) => Record<string, string>; | ||
export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request { | ||
constructor(input: RequestInfo | URL, options?: RequestPonyfillInit); | ||
headersSerializer: HeadersSerializer; | ||
cache: RequestCache; | ||
@@ -26,1 +29,2 @@ credentials: RequestCredentials; | ||
} | ||
export {}; |
@@ -17,2 +17,3 @@ export declare class PonyfillURLSearchParams implements URLSearchParams { | ||
forEach(callback: (value: string, key: string, parent: URLSearchParams) => void): void; | ||
get size(): number; | ||
} |
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
5
127697
58
3110
6
+ Added@whatwg-node/events@0.1.0-alpha-20230515120642-be23d36(transitive)
- Removed@types/node@18.19.75(transitive)
- Removed@whatwg-node/events@0.0.2(transitive)
- Removedundici-types@5.26.5(transitive)
Updated@whatwg-node/events@0.1.0-alpha-20230515120642-be23d36