@whatwg-node/fetch 0.0.2 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @whatwg-node/fetch
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 486c35d: Export Event API
8
+
9
+ ## 0.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 16aff71: Fix missing TextEncoder and TextDecoder in the default ponyfill
14
+
15
+ ## 0.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - b83d7f3: Faster TextEncoder & TextDecoder with Buffer in Node
20
+ - b83d7f3: Ponyfill for WebCrypto API
21
+
22
+ ### Patch Changes
23
+
24
+ - b83d7f3: Bump undici version
25
+ - b83d7f3: Now ponyfills Event API
26
+
3
27
  ## 0.0.2
4
28
 
5
29
  ### Patch Changes
@@ -18,6 +18,8 @@ module.exports = function createNodePonyfill(opts = {}) {
18
18
  ponyfills.TransformStream = globalThis.TransformStream;
19
19
  ponyfills.Blob = globalThis.Blob;
20
20
  ponyfills.crypto = globalThis.crypto;
21
+ ponyfills.Event = globalThis.Event;
22
+ ponyfills.EventTarget = globalThis.EventTarget;
21
23
 
22
24
  if (!ponyfills.AbortController) {
23
25
  const abortControllerModule = require("abort-controller");
@@ -50,6 +52,22 @@ module.exports = function createNodePonyfill(opts = {}) {
50
52
  }
51
53
  }
52
54
 
55
+ ponyfills.TextEncoder = function TextEncoder() {
56
+ return {
57
+ encode(str) {
58
+ return Buffer.from(str, "utf8");
59
+ }
60
+ }
61
+ }
62
+
63
+ ponyfills.TextDecoder = function TextDecoder() {
64
+ return {
65
+ decode(buf) {
66
+ return buf.toString("utf8");
67
+ }
68
+ }
69
+ }
70
+
53
71
  // ReadableStream doesn't handle aborting properly, so we need to patch it
54
72
  ponyfills.ReadableStream = class PonyfillReadableStream extends ponyfills.ReadableStream {
55
73
  constructor(underlyingSource, ...opts) {
@@ -98,6 +116,11 @@ module.exports = function createNodePonyfill(opts = {}) {
98
116
  ponyfills.crypto = cryptoModule.webcrypto;
99
117
  }
100
118
 
119
+ if (!ponyfills.crypto) {
120
+ const cryptoPonyfill = require('@peculiar/webcrypto');
121
+ ponyfills.crypto = new cryptoPonyfill.Crypto();
122
+ }
123
+
101
124
  // If any of classes of Fetch API is missing, we need to ponyfill them.
102
125
  if (!ponyfills.fetch ||
103
126
  !ponyfills.Request ||
@@ -10,6 +10,10 @@ const TransformStream = globalThis.TransformStream;
10
10
  const Blob = globalThis.Blob;
11
11
  const File = globalThis.File;
12
12
  const crypto = globalThis.crypto;
13
+ const TextDecoder = globalThis.TextDecoder;
14
+ const TextEncoder = globalThis.TextEncoder;
15
+ const Event = globalThis.Event;
16
+ const EventTarget = globalThis.EventTarget;
13
17
 
14
18
  export const create = () => globalThis;
15
19
  export {
@@ -25,4 +29,8 @@ export {
25
29
  Blob,
26
30
  File,
27
31
  crypto,
32
+ TextDecoder,
33
+ TextEncoder,
34
+ Event,
35
+ EventTarget,
28
36
  };
@@ -10,4 +10,8 @@ module.exports.TransformStream = globalThis.TransformStream;
10
10
  module.exports.Blob = globalThis.Blob;
11
11
  module.exports.File = globalThis.File;
12
12
  module.exports.crypto = globalThis.crypto;
13
+ module.exports.TextEncoder = globalThis.TextEncoder;
14
+ module.exports.TextDecoder = globalThis.TextDecoder;
15
+ module.exports.Event = globalThis.Event;
16
+ module.exports.EventTarget = globalThis.EventTarget;
13
17
  module.exports.createFetch = () => globalThis;
package/dist/index.d.ts CHANGED
@@ -12,6 +12,10 @@ declare const _TransformStream: typeof TransformStream;
12
12
  declare const _Blob: typeof Blob;
13
13
  declare const _File: typeof File;
14
14
  declare const _crypto: typeof crypto;
15
+ declare const _TextEncoder: typeof TextEncoder;
16
+ declare const _TextDecoder: typeof TextDecoder;
17
+ declare const _Event: typeof Event;
18
+ declare const _EventTarget: typeof EventTarget;
15
19
 
16
20
  declare module "@whatwg-node/fetch" {
17
21
  export const fetch: typeof _fetch;
@@ -26,6 +30,10 @@ declare module "@whatwg-node/fetch" {
26
30
  export const Blob: typeof _Blob;
27
31
  export const File: typeof _File;
28
32
  export const crypto: typeof _crypto;
33
+ export const TextDecoder: typeof _TextDecoder;
34
+ export const TextEncoder: typeof _TextEncoder;
35
+ export const Event: typeof _Event;
36
+ export const EventTarget: typeof EventTarget;
29
37
  export interface FormDataLimits {
30
38
  /* Max field name size (in bytes). Default: 100. */
31
39
  fieldNameSize?: number;
@@ -55,6 +63,10 @@ declare module "@whatwg-node/fetch" {
55
63
  Blob: typeof _Blob,
56
64
  File: typeof _File,
57
65
  crypto: typeof _crypto
66
+ TextEncoder: typeof _TextEncoder,
67
+ TextDecoder: typeof _TextDecoder,
68
+ Event: typeof _Event,
69
+ EventTarget: typeof EventTarget
58
70
  });
59
71
  }
60
72
 
@@ -14,4 +14,11 @@ module.exports.TransformStream = ponyfills.TransformStream;
14
14
  module.exports.Blob = ponyfills.Blob;
15
15
  module.exports.File = ponyfills.File;
16
16
  module.exports.crypto = ponyfills.crypto;
17
+ module.exports.TextEncoder = ponyfills.TextEncoder;
18
+ module.exports.TextDecoder = ponyfills.TextDecoder;
19
+
20
+ require('event-target-polyfill');
21
+ module.exports.Event = ponyfills.Event;
22
+ module.exports.EventTarget = ponyfills.EventTarget;
23
+
17
24
  exports.createFetch = createNodePonyfill;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/fetch",
3
- "version": "0.0.2",
3
+ "version": "0.2.0",
4
4
  "description": "Cross Platform Smart Fetch Ponyfill",
5
5
  "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
6
6
  "repository": {
@@ -18,12 +18,14 @@
18
18
  "index": "dist/deno-ponyfill.ts"
19
19
  },
20
20
  "dependencies": {
21
+ "@peculiar/webcrypto": "^1.4.0",
21
22
  "abort-controller": "^3.0.0",
22
23
  "busboy": "^1.6.0",
24
+ "event-target-polyfill": "^0.0.3",
23
25
  "form-data-encoder": "^1.7.1",
24
26
  "formdata-node": "^4.3.1",
25
27
  "node-fetch": "^2.6.7",
26
- "undici": "5.5.1",
28
+ "undici": "^5.8.0",
27
29
  "web-streams-polyfill": "^3.2.0"
28
30
  },
29
31
  "publishConfig": {