Detalhes do pacote

@whatwg-node/fetch

ardatan29.9mMIT0.10.8

Cross Platform Smart Fetch Ponyfill

readme (leia-me)

WhatWG Node

This repository contains a set of environment(Browser, Node.js, Deno, Cloudflare Workers, Bun, etc.) agnostic packages for the WhatWG standards.

Node.js currently is the only exception that doesn't fully support those standards so whatwg-node packages ponyfill the missing parts without modifying or monkey-patching the native global APIs like polyfills.

Polyfill patches the native parts of an environment while ponyfill just exports the “patched” stuff without touching the environment’s internals. We prefer pony filling because it prevents us from breaking other libraries and environmental functionalities. In case a ponyfill is imported in an environment that already has that API built in like newer Node.js, Cloudflare Workers, Bun, Deno or Browser, no ponyfills are added to your built application bundle. So you have a generic package that works in all environments.

Packages

@whatwg-node/fetch

A ponyfill package for the Fetch Standard.

@whatwg-node/events

A ponyfill package for the DOM Events Standard.

@whatwg-node/server

A platform-independent JavaScript HTTP server adapter implementation that uses the Fetch Standard to handle requests. The HTTP server implemented with this library can be used in any JS environment like Node.js, Deno, Cloudflare Workers, Bun, etc. For Node.js, it transpiles Node.js specific APIs to the standard ones, and for other environments, it uses the standard APIs directly. Even if your environment doesn't use Fetch API for the server implementation, you can still use fetch method to handle requests.

fetchache

A fetch wrapper that allows you to respect HTTP caching strategies on non-browser environments with a key-value cache implementation. It follows the HTTP Caching and Conditional Requests standards.

changelog (log de mudanças)

@whatwg-node/fetch

0.10.8

Patch Changes

  • #2424 28c4ad9 Thanks @ardatan! - Performance optimizations

    • Avoid creating AbortController and AbortSignal if not needed with new Request because it is expensive
    • Avoid creating a map for Headers and try to re-use the init object for Headers for performance with a single-line writeHead.
    • Avoid creating Buffer for string bodies for performance
    • Use setHeaders which accepts Headers since Node 18 if needed to forward Headers to Node
  • Updated dependencies [28c4ad9]:

    • @whatwg-node/node-fetch@0.7.21

0.10.7

Patch Changes

  • #2383 9527e8f Thanks @ardatan! - Some implementations like compression npm package do not implement response.write(data, callback) signature, but whatwg-node/server waits for it to finish the response stream. Then it causes the response stream hangs when the compression package takes the stream over when the response data is larger than its threshold.

    It is actually a bug in compression package; expressjs/compression#46 But since it is a common mistake, we prefer to workaround this on our end.

    Now after calling response.write, it no longer uses callback but first it checks the result;

    if it is true, it means stream is drained and we can call response.end immediately. else if it is false, it means the stream is not drained yet, so we can wait for the drain event to call response.end.

  • Updated dependencies [9527e8f]:

    • @whatwg-node/node-fetch@0.7.19

0.10.6

Patch Changes

0.10.5

Patch Changes

  • #2093 31f021a Thanks @ardatan! - Fixes the TypeError: bodyInit.stream is not a function error thrown when @whatwg-node/server is used with node:http2 and attempts the incoming HTTP/2 request to parse with Request.json, Request.text, Request.formData, or Request.blob methods.

  • Updated dependencies [31f021a]:

    • @whatwg-node/node-fetch@0.7.11

0.10.4

Patch Changes

  • #2082 b217e30 Thanks @ardatan! - dependencies updates:

  • #2079 090b4b0 Thanks @ardatan! - Fix the bug when set-cookies given is ignored in HeadersInit;

    import { Headers } from '@whatwg-node/fetch'
    
    const headers = new Headers([
      ['set-cookie', 'a=b'],
      ['set-cookie', 'c=d']
    ])
    expect(headers.getSetCookie()).toEqual(['a=b', 'c=d']) // Previously it was empty
    
  • Updated dependencies [090b4b0]:

    • @whatwg-node/node-fetch@0.7.10

0.10.3

Patch Changes

  • #1961 2785c80 Thanks @ardatan! - ReadableStream's Symbol.asyncIterator now returns AsyncIterableIterator like before even if it is ok to return AsyncIterator right now. It is safer to return AsyncIterableIterator because it is a common mistake to use AsyncIterator as AsyncIterable.
  • Updated dependencies [2785c80]:
    • @whatwg-node/node-fetch@0.7.7

0.10.2

Patch Changes

0.10.1

Patch Changes

  • c68f5ad Thanks @ardatan! - Pass errors to ReadableStream's cancel method properly when it is piped, and piped stream is cancelled

    Implement ReadableStream.from

  • Updated dependencies [c68f5ad]:

    • @whatwg-node/node-fetch@0.7.1

0.10.0

Minor Changes

Patch Changes

  • Updated dependencies [6c006e1]:
    • @whatwg-node/node-fetch@0.7.0

0.9.23

Patch Changes

  • Updated dependencies [637185f]:
    • @whatwg-node/node-fetch@0.6.0

0.9.22

Patch Changes

  • 77dd1c3 Thanks @ardatan! - Use `globalThis` instead of `window` for the global object reference

    Fixes the issues with Deno

  • Updated dependencies [9281e02]:

    • @whatwg-node/node-fetch@0.5.27

0.9.21

Patch Changes

  • #1577 99c4344 Thanks @ardatan! - - Improve native ReadableStream handling inside ponyfills
    • Use waitUntil instead of floating promises
    • Handle early termination in WritableStream
    • Handle waitUntil correctly within a dummy call of ServerAdapter.fetch method
  • Updated dependencies [99c4344]:
    • @whatwg-node/node-fetch@0.5.23

0.9.20

Patch Changes

  • #1566 de1e95a Thanks @ardatan! - Avoid constructing DecompressionStream to check supported encodings

  • Updated dependencies [de1e95a]:

    • @whatwg-node/node-fetch@0.5.22

0.9.19

Patch Changes

  • #1495 bebc159 Thanks @ardatan! - Implement `CompressionStream`, `WritableStream` and `TransformStream`

  • Updated dependencies [bebc159]:

    • @whatwg-node/node-fetch@0.5.16

0.9.18

Patch Changes

  • #1328 36904b4 Thanks @ardatan! - Add skipPonyfill flag to createFetch to skip ponyfills and use the native Fetch implementation for Node.js

0.9.17

Patch Changes

0.9.16

Patch Changes

0.9.15

Patch Changes

0.9.14

Patch Changes

  • 68ac24c Thanks @ardatan! - Support TypeScript 5.2.2

  • Updated dependencies [f7e507f]:

    • @whatwg-node/node-fetch@0.5.0

0.9.13

Patch Changes

  • 854b778 Thanks @ardatan! - Do not try to import node-libcurl in Deno and Bun

0.9.12

Patch Changes

  • a8467ab Thanks @ardatan! - Fake promise's then method may not take a callback function

  • Updated dependencies [a8467ab]:

    • @whatwg-node/node-fetch@0.4.17

0.9.11

Patch Changes

  • 96efb10 Thanks @ardatan! - Ignore content-length while reading the request body

  • Updated dependencies [96efb10]:

    • @whatwg-node/node-fetch@0.4.16

0.9.10

Patch Changes

  • #806 9b6911a Thanks @ardatan! - Return Buffer instead of ArrayBuffer in .arrayBuffer due to a bug in Node.js that returns a bigger ArrayBuffer causing memory overflow
  • Updated dependencies [9b6911a]:
    • @whatwg-node/node-fetch@0.4.15

0.9.9

Patch Changes

  • #567 f8715cd Thanks @ardatan! - ### Faster HTTP Client experience in Node.js with HTTP/2 support

    If you install node-libcurl seperately, @whatwg-node/fetch will select libcurl instead of node:http which is faster.

    See benchmarks

  • Updated dependencies [f8715cd]:

    • @whatwg-node/node-fetch@0.4.8

0.9.8

Patch Changes

  • a1c2140 Thanks @ardatan! - Do not use async iterators to consume incoming Readable stream

  • Updated dependencies [a1c2140]:

    • @whatwg-node/node-fetch@0.4.7

0.9.7

Patch Changes

  • 124bbe5 Thanks @ardatan! - Implement Headers.getSetCookie and a custom serializer for node.inspect

  • Updated dependencies [124bbe5]:

    • @whatwg-node/node-fetch@0.4.6

0.9.6

Patch Changes

0.9.5

Patch Changes

0.9.4

Patch Changes

0.9.3

Patch Changes

  • d7d9d9f Thanks @ardatan! - Bump internal packages

  • Updated dependencies [d7d9d9f]:

    • @whatwg-node/node-fetch@0.4.2

0.9.2

Patch Changes

0.9.1

Patch Changes

0.9.0

Minor Changes

Patch Changes

0.8.8

Patch Changes

0.8.7

Patch Changes

0.8.6

Patch Changes

  • #427 e8bda7c Thanks @Rugvip! - Restructure type declarations to avoid polluting global namespace.

  • Updated dependencies [f3ce0e8]:

    • @whatwg-node/node-fetch@0.3.6

0.8.5

Patch Changes

0.8.4

Patch Changes

  • 207ee1d Thanks @ardatan! - Detect Deno if the module is imported via 'npm:' or any other Node compatibility method

0.8.3

Patch Changes

0.8.2

Patch Changes

0.8.1

Patch Changes

  • Updated dependencies [c7b9c8a, f28ce1f]:
    • @whatwg-node/node-fetch@0.3.0

0.8.0

Minor Changes

Patch Changes

0.7.1

Patch Changes

  • Updated dependencies [2d6e4aa, 94150b3]:
    • @whatwg-node/node-fetch@0.1.0

0.7.0

Minor Changes

Patch Changes

  • Updated dependencies [390510b]:
    • @whatwg-node/node-fetch@0.0.6

0.6.9

Patch Changes

0.6.8

Patch Changes

  • Updated dependencies [01dc91e]:
    • @whatwg-node/node-fetch@0.0.4

0.6.7

Patch Changes

  • Updated dependencies [8edd68d, b6c9ac0]:
    • @whatwg-node/node-fetch@0.0.3

0.6.6

Patch Changes

  • Updated dependencies [155c354, 260d86f]:
    • @whatwg-node/node-fetch@0.0.2

0.6.5

Patch Changes

0.6.4

Patch Changes

0.6.3

Patch Changes

0.6.2

Patch Changes

0.6.1

Patch Changes

  • 9752cca Thanks @ardatan! - Remove unnecessary ponyfill for the envs supporting Fetch by default

0.6.0

Minor Changes

  • #241 563cfaa Thanks @ardatan! - Drop itty-router in favor of new URLPattern in the fetch ponyfill

Patch Changes

0.5.4

Patch Changes

0.5.3

Patch Changes

0.5.2

Patch Changes

0.5.1

Patch Changes

0.5.0

Minor Changes

0.4.7

Patch Changes

  • e59cbb6 Thanks @ardatan! - Do not patch global Headers if it is native, and support URL as a first parameter of fetch

0.4.6

Patch Changes

  • c918527 Thanks @ardatan! - Bump Undici

  • #148 eb10500 Thanks @ardatan! - - On Node 14, fix the return method of Response.body's AsyncIterator to close HTTP connection correctly

    • On Node 14, handle ReadableStream's cancel correctly if Response.body is a ReadableStream
    • Do not modify ReadableStream.cancel's behavior but handle it internally
    • On Node 18, do not combine Response.body's return and AbortController which causes a memory leak

0.4.5

Patch Changes

0.4.4

Patch Changes

  • 9502102 Thanks @ardatan! - Breaking Change: Event API is no longer available in this ponyfill; use @whatwg-node/events instead.

0.4.3

Patch Changes

  • c9f05f2 Thanks @ardatan! - Add ponyfills for Response.redirect, Response.json and Response.error

0.4.2

Patch Changes

  • 7f37b6d Thanks @ardatan! - fix(fetch): respect filesLimit even with fieldsFirst

0.4.1

Patch Changes

0.4.0

Minor Changes

  • 005937c Thanks @ardatan! - feat(fetch): new fieldsFirst option to allow async stream consumption for multipart forms

  • effc03d Thanks @ardatan! - Bun Support

0.3.2

Patch Changes

  • 982fa96 Thanks @ardatan! - fix(ponyfill/btoa): handle incoming value as binary encoding

0.3.1

Patch Changes

0.3.0

Minor Changes

0.2.9

Patch Changes

0.2.3

Minor Changes

  • 486c35d: Export Event API

0.1.1

Patch Changes

  • 16aff71: Fix missing TextEncoder and TextDecoder in the default ponyfill

0.1.0

Minor Changes

  • b83d7f3: Faster TextEncoder & TextDecoder with Buffer in Node
  • b83d7f3: Ponyfill for WebCrypto API

Patch Changes

  • b83d7f3: Bump undici version
  • b83d7f3: Now ponyfills Event API

0.0.2

Patch Changes

  • 3207383: Fix TS typings

0.0.1

Patch Changes

  • 889eccf: NEW RELEASES