@whatwg-node/fetch 0.0.2 → 0.1.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,17 @@
1
1
  # @whatwg-node/fetch
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b83d7f3: Faster TextEncoder & TextDecoder with Buffer in Node
8
+ - b83d7f3: Ponyfill for WebCrypto API
9
+
10
+ ### Patch Changes
11
+
12
+ - b83d7f3: Bump undici version
13
+ - b83d7f3: Now ponyfills Event API
14
+
3
15
  ## 0.0.2
4
16
 
5
17
  ### Patch Changes
@@ -50,6 +50,22 @@ module.exports = function createNodePonyfill(opts = {}) {
50
50
  }
51
51
  }
52
52
 
53
+ ponyfills.TextEncoder = function TextEncoder() {
54
+ return {
55
+ encode(str) {
56
+ return Buffer.from(str, "utf8");
57
+ }
58
+ }
59
+ }
60
+
61
+ ponyfills.TextDecoder = function TextDecoder() {
62
+ return {
63
+ decode(buf) {
64
+ return buf.toString("utf8");
65
+ }
66
+ }
67
+ }
68
+
53
69
  // ReadableStream doesn't handle aborting properly, so we need to patch it
54
70
  ponyfills.ReadableStream = class PonyfillReadableStream extends ponyfills.ReadableStream {
55
71
  constructor(underlyingSource, ...opts) {
@@ -98,6 +114,11 @@ module.exports = function createNodePonyfill(opts = {}) {
98
114
  ponyfills.crypto = cryptoModule.webcrypto;
99
115
  }
100
116
 
117
+ if (!ponyfills.crypto) {
118
+ const cryptoPonyfill = require('@peculiar/webcrypto');
119
+ ponyfills.crypto = new cryptoPonyfill.Crypto();
120
+ }
121
+
101
122
  // If any of classes of Fetch API is missing, we need to ponyfill them.
102
123
  if (!ponyfills.fetch ||
103
124
  !ponyfills.Request ||
@@ -10,6 +10,8 @@ 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;
13
15
 
14
16
  export const create = () => globalThis;
15
17
  export {
@@ -25,4 +27,6 @@ export {
25
27
  Blob,
26
28
  File,
27
29
  crypto,
30
+ TextDecoder,
31
+ TextEncoder,
28
32
  };
@@ -10,4 +10,6 @@ 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;
13
15
  module.exports.createFetch = () => globalThis;
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ 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;
15
17
 
16
18
  declare module "@whatwg-node/fetch" {
17
19
  export const fetch: typeof _fetch;
@@ -26,6 +28,8 @@ declare module "@whatwg-node/fetch" {
26
28
  export const Blob: typeof _Blob;
27
29
  export const File: typeof _File;
28
30
  export const crypto: typeof _crypto;
31
+ export const TextDecoder: typeof _TextDecoder;
32
+ export const TextEncoder: typeof _TextEncoder;
29
33
  export interface FormDataLimits {
30
34
  /* Max field name size (in bytes). Default: 100. */
31
35
  fieldNameSize?: number;
@@ -55,6 +59,8 @@ declare module "@whatwg-node/fetch" {
55
59
  Blob: typeof _Blob,
56
60
  File: typeof _File,
57
61
  crypto: typeof _crypto
62
+ TextEncoder: typeof _TextEncoder,
63
+ TextDecoder: typeof _TextDecoder
58
64
  });
59
65
  }
60
66
 
@@ -15,3 +15,5 @@ module.exports.Blob = ponyfills.Blob;
15
15
  module.exports.File = ponyfills.File;
16
16
  module.exports.crypto = ponyfills.crypto;
17
17
  exports.createFetch = createNodePonyfill;
18
+
19
+ require('event-target-polyfill');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/fetch",
3
- "version": "0.0.2",
3
+ "version": "0.1.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": {