@whatwg-node/node-fetch 0.7.18 → 0.7.19-alpha-20250507123452-fcbe4f1b230a420fdf82832fcaba10f27b872611

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/cjs/FormData.js CHANGED
@@ -74,54 +74,65 @@ class PonyfillFormData {
74
74
  }
75
75
  exports.PonyfillFormData = PonyfillFormData;
76
76
  function getStreamFromFormData(formData, boundary = '---') {
77
- const entries = [];
77
+ let entriesIterator;
78
78
  let sentInitialHeader = false;
79
- return new ReadableStream_js_1.PonyfillReadableStream({
80
- start: controller => {
81
- formData.forEach((value, key) => {
82
- if (!sentInitialHeader) {
83
- controller.enqueue(node_buffer_1.Buffer.from(`--${boundary}\r\n`));
84
- sentInitialHeader = true;
79
+ let currentAsyncIterator;
80
+ let hasBefore = false;
81
+ function handleNextEntry(controller) {
82
+ const { done, value } = entriesIterator.next();
83
+ if (done) {
84
+ controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}--\r\n`));
85
+ return controller.close();
86
+ }
87
+ if (hasBefore) {
88
+ controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}\r\n`));
89
+ }
90
+ if (value) {
91
+ const [key, blobOrString] = value;
92
+ if (typeof blobOrString === 'string') {
93
+ controller.enqueue(node_buffer_1.Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
94
+ controller.enqueue(node_buffer_1.Buffer.from(blobOrString));
95
+ }
96
+ else {
97
+ let filenamePart = '';
98
+ if (blobOrString.name) {
99
+ filenamePart = `; filename="${blobOrString.name}"`;
85
100
  }
86
- entries.push([key, value]);
87
- });
88
- if (!sentInitialHeader) {
89
- controller.enqueue(node_buffer_1.Buffer.from(`--${boundary}--\r\n`));
90
- controller.close();
101
+ controller.enqueue(node_buffer_1.Buffer.from(`Content-Disposition: form-data; name="${key}"${filenamePart}\r\n`));
102
+ controller.enqueue(node_buffer_1.Buffer.from(`Content-Type: ${blobOrString.type || 'application/octet-stream'}\r\n\r\n`));
103
+ const entryStream = blobOrString.stream();
104
+ currentAsyncIterator = entryStream[Symbol.asyncIterator]();
91
105
  }
106
+ hasBefore = true;
107
+ }
108
+ }
109
+ return new ReadableStream_js_1.PonyfillReadableStream({
110
+ start: () => {
111
+ entriesIterator = formData.entries();
92
112
  },
93
- pull: async (controller) => {
94
- const entry = entries.shift();
95
- if (entry) {
96
- const [key, value] = entry;
97
- if (typeof value === 'string') {
98
- controller.enqueue(node_buffer_1.Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
99
- controller.enqueue(node_buffer_1.Buffer.from(value));
100
- }
101
- else {
102
- let filenamePart = '';
103
- if (value.name) {
104
- filenamePart = `; filename="${value.name}"`;
113
+ pull: controller => {
114
+ if (!sentInitialHeader) {
115
+ sentInitialHeader = true;
116
+ return controller.enqueue(node_buffer_1.Buffer.from(`--${boundary}\r\n`));
117
+ }
118
+ if (currentAsyncIterator) {
119
+ return currentAsyncIterator.next().then(({ done, value }) => {
120
+ if (done) {
121
+ currentAsyncIterator = undefined;
105
122
  }
106
- controller.enqueue(node_buffer_1.Buffer.from(`Content-Disposition: form-data; name="${key}"${filenamePart}\r\n`));
107
- controller.enqueue(node_buffer_1.Buffer.from(`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`));
108
- const entryStream = value.stream();
109
- for await (const chunk of entryStream) {
110
- controller.enqueue(chunk);
123
+ if (value) {
124
+ return controller.enqueue(value);
111
125
  }
112
- }
113
- if (entries.length === 0) {
114
- controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}--\r\n`));
115
- controller.close();
116
- }
117
- else {
118
- controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}\r\n`));
119
- }
120
- }
121
- else {
122
- controller.enqueue(node_buffer_1.Buffer.from(`\r\n--${boundary}--\r\n`));
123
- controller.close();
126
+ else {
127
+ return handleNextEntry(controller);
128
+ }
129
+ });
124
130
  }
131
+ return handleNextEntry(controller);
132
+ },
133
+ cancel: err => {
134
+ entriesIterator?.return?.(err);
135
+ currentAsyncIterator?.return?.(err);
125
136
  },
126
137
  });
127
138
  }
package/esm/FormData.js CHANGED
@@ -69,54 +69,65 @@ export class PonyfillFormData {
69
69
  }
70
70
  }
71
71
  export function getStreamFromFormData(formData, boundary = '---') {
72
- const entries = [];
72
+ let entriesIterator;
73
73
  let sentInitialHeader = false;
74
- return new PonyfillReadableStream({
75
- start: controller => {
76
- formData.forEach((value, key) => {
77
- if (!sentInitialHeader) {
78
- controller.enqueue(Buffer.from(`--${boundary}\r\n`));
79
- sentInitialHeader = true;
74
+ let currentAsyncIterator;
75
+ let hasBefore = false;
76
+ function handleNextEntry(controller) {
77
+ const { done, value } = entriesIterator.next();
78
+ if (done) {
79
+ controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`));
80
+ return controller.close();
81
+ }
82
+ if (hasBefore) {
83
+ controller.enqueue(Buffer.from(`\r\n--${boundary}\r\n`));
84
+ }
85
+ if (value) {
86
+ const [key, blobOrString] = value;
87
+ if (typeof blobOrString === 'string') {
88
+ controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
89
+ controller.enqueue(Buffer.from(blobOrString));
90
+ }
91
+ else {
92
+ let filenamePart = '';
93
+ if (blobOrString.name) {
94
+ filenamePart = `; filename="${blobOrString.name}"`;
80
95
  }
81
- entries.push([key, value]);
82
- });
83
- if (!sentInitialHeader) {
84
- controller.enqueue(Buffer.from(`--${boundary}--\r\n`));
85
- controller.close();
96
+ controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"${filenamePart}\r\n`));
97
+ controller.enqueue(Buffer.from(`Content-Type: ${blobOrString.type || 'application/octet-stream'}\r\n\r\n`));
98
+ const entryStream = blobOrString.stream();
99
+ currentAsyncIterator = entryStream[Symbol.asyncIterator]();
86
100
  }
101
+ hasBefore = true;
102
+ }
103
+ }
104
+ return new PonyfillReadableStream({
105
+ start: () => {
106
+ entriesIterator = formData.entries();
87
107
  },
88
- pull: async (controller) => {
89
- const entry = entries.shift();
90
- if (entry) {
91
- const [key, value] = entry;
92
- if (typeof value === 'string') {
93
- controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"\r\n\r\n`));
94
- controller.enqueue(Buffer.from(value));
95
- }
96
- else {
97
- let filenamePart = '';
98
- if (value.name) {
99
- filenamePart = `; filename="${value.name}"`;
108
+ pull: controller => {
109
+ if (!sentInitialHeader) {
110
+ sentInitialHeader = true;
111
+ return controller.enqueue(Buffer.from(`--${boundary}\r\n`));
112
+ }
113
+ if (currentAsyncIterator) {
114
+ return currentAsyncIterator.next().then(({ done, value }) => {
115
+ if (done) {
116
+ currentAsyncIterator = undefined;
100
117
  }
101
- controller.enqueue(Buffer.from(`Content-Disposition: form-data; name="${key}"${filenamePart}\r\n`));
102
- controller.enqueue(Buffer.from(`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`));
103
- const entryStream = value.stream();
104
- for await (const chunk of entryStream) {
105
- controller.enqueue(chunk);
118
+ if (value) {
119
+ return controller.enqueue(value);
106
120
  }
107
- }
108
- if (entries.length === 0) {
109
- controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`));
110
- controller.close();
111
- }
112
- else {
113
- controller.enqueue(Buffer.from(`\r\n--${boundary}\r\n`));
114
- }
115
- }
116
- else {
117
- controller.enqueue(Buffer.from(`\r\n--${boundary}--\r\n`));
118
- controller.close();
121
+ else {
122
+ return handleNextEntry(controller);
123
+ }
124
+ });
119
125
  }
126
+ return handleNextEntry(controller);
127
+ },
128
+ cancel: err => {
129
+ entriesIterator?.return?.(err);
130
+ currentAsyncIterator?.return?.(err);
120
131
  },
121
132
  });
122
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.18",
3
+ "version": "0.7.19-alpha-20250507123452-fcbe4f1b230a420fdf82832fcaba10f27b872611",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {