undici 6.19.7 → 7.0.0-alpha.1

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.
Files changed (115) hide show
  1. package/README.md +5 -9
  2. package/docs/docs/api/Agent.md +0 -3
  3. package/docs/docs/api/Client.md +0 -2
  4. package/docs/docs/api/Dispatcher.md +204 -6
  5. package/docs/docs/api/EnvHttpProxyAgent.md +0 -1
  6. package/docs/docs/api/Fetch.md +1 -0
  7. package/docs/docs/api/Pool.md +0 -1
  8. package/docs/docs/api/RetryHandler.md +1 -1
  9. package/index.js +0 -4
  10. package/lib/api/api-connect.js +3 -1
  11. package/lib/api/api-pipeline.js +3 -4
  12. package/lib/api/api-request.js +29 -46
  13. package/lib/api/api-stream.js +36 -49
  14. package/lib/api/api-upgrade.js +5 -3
  15. package/lib/api/readable.js +71 -27
  16. package/lib/core/connect.js +39 -24
  17. package/lib/core/errors.js +17 -4
  18. package/lib/core/request.js +7 -5
  19. package/lib/core/symbols.js +0 -1
  20. package/lib/core/tree.js +6 -0
  21. package/lib/core/util.js +1 -11
  22. package/lib/dispatcher/agent.js +3 -17
  23. package/lib/dispatcher/balanced-pool.js +27 -11
  24. package/lib/dispatcher/client-h1.js +44 -39
  25. package/lib/dispatcher/client.js +3 -27
  26. package/lib/dispatcher/dispatcher-base.js +2 -34
  27. package/lib/dispatcher/dispatcher.js +3 -24
  28. package/lib/dispatcher/pool.js +3 -6
  29. package/lib/dispatcher/proxy-agent.js +3 -6
  30. package/lib/handler/decorator-handler.js +24 -0
  31. package/lib/handler/redirect-handler.js +9 -0
  32. package/lib/handler/retry-handler.js +22 -3
  33. package/lib/interceptor/dump.js +2 -2
  34. package/lib/interceptor/redirect.js +11 -14
  35. package/lib/interceptor/response-error.js +89 -0
  36. package/lib/llhttp/constants.d.ts +97 -0
  37. package/lib/llhttp/constants.js +412 -192
  38. package/lib/llhttp/constants.js.map +1 -0
  39. package/lib/llhttp/llhttp-wasm.js +11 -1
  40. package/lib/llhttp/llhttp_simd-wasm.js +11 -1
  41. package/lib/llhttp/utils.d.ts +2 -0
  42. package/lib/llhttp/utils.js +9 -9
  43. package/lib/llhttp/utils.js.map +1 -0
  44. package/lib/mock/mock-client.js +2 -2
  45. package/lib/mock/mock-pool.js +2 -2
  46. package/lib/mock/mock-symbols.js +1 -0
  47. package/lib/util/timers.js +324 -44
  48. package/lib/web/cookies/index.js +15 -13
  49. package/lib/web/cookies/parse.js +2 -2
  50. package/lib/web/eventsource/eventsource-stream.js +9 -8
  51. package/lib/web/eventsource/eventsource.js +10 -6
  52. package/lib/web/fetch/body.js +31 -11
  53. package/lib/web/fetch/data-url.js +1 -1
  54. package/lib/web/fetch/formdata-parser.js +1 -2
  55. package/lib/web/fetch/formdata.js +28 -37
  56. package/lib/web/fetch/headers.js +1 -1
  57. package/lib/web/fetch/index.js +7 -8
  58. package/lib/web/fetch/request.js +11 -28
  59. package/lib/web/fetch/response.js +13 -41
  60. package/lib/web/fetch/symbols.js +0 -1
  61. package/lib/web/fetch/util.js +3 -12
  62. package/lib/web/fetch/webidl.js +73 -62
  63. package/lib/web/websocket/connection.js +26 -174
  64. package/lib/web/websocket/constants.js +1 -1
  65. package/lib/web/websocket/frame.js +45 -3
  66. package/lib/web/websocket/receiver.js +28 -26
  67. package/lib/web/websocket/sender.js +18 -13
  68. package/lib/web/websocket/util.js +20 -74
  69. package/lib/web/websocket/websocket.js +294 -70
  70. package/package.json +16 -29
  71. package/scripts/strip-comments.js +3 -1
  72. package/types/agent.d.ts +7 -7
  73. package/types/api.d.ts +24 -24
  74. package/types/balanced-pool.d.ts +11 -11
  75. package/types/client.d.ts +11 -12
  76. package/types/diagnostics-channel.d.ts +10 -10
  77. package/types/dispatcher.d.ts +96 -97
  78. package/types/env-http-proxy-agent.d.ts +2 -2
  79. package/types/errors.d.ts +53 -47
  80. package/types/eventsource.d.ts +0 -2
  81. package/types/fetch.d.ts +8 -8
  82. package/types/formdata.d.ts +7 -7
  83. package/types/global-dispatcher.d.ts +4 -4
  84. package/types/global-origin.d.ts +5 -5
  85. package/types/handlers.d.ts +4 -4
  86. package/types/header.d.ts +157 -1
  87. package/types/index.d.ts +42 -46
  88. package/types/interceptors.d.ts +10 -8
  89. package/types/mock-agent.d.ts +18 -18
  90. package/types/mock-client.d.ts +4 -4
  91. package/types/mock-errors.d.ts +3 -3
  92. package/types/mock-interceptor.d.ts +19 -19
  93. package/types/mock-pool.d.ts +4 -4
  94. package/types/patch.d.ts +0 -42
  95. package/types/pool-stats.d.ts +8 -8
  96. package/types/pool.d.ts +12 -12
  97. package/types/proxy-agent.d.ts +4 -4
  98. package/types/readable.d.ts +14 -9
  99. package/types/retry-agent.d.ts +1 -1
  100. package/types/retry-handler.d.ts +8 -8
  101. package/types/util.d.ts +3 -3
  102. package/types/utility.d.ts +7 -0
  103. package/types/webidl.d.ts +22 -4
  104. package/types/websocket.d.ts +1 -3
  105. package/docs/docs/api/DispatchInterceptor.md +0 -60
  106. package/lib/interceptor/redirect-interceptor.js +0 -21
  107. package/lib/web/fetch/file.js +0 -126
  108. package/lib/web/fileapi/encoding.js +0 -290
  109. package/lib/web/fileapi/filereader.js +0 -344
  110. package/lib/web/fileapi/progressevent.js +0 -78
  111. package/lib/web/fileapi/symbols.js +0 -10
  112. package/lib/web/fileapi/util.js +0 -391
  113. package/lib/web/websocket/symbols.js +0 -12
  114. package/types/file.d.ts +0 -39
  115. package/types/filereader.d.ts +0 -54
@@ -1,344 +0,0 @@
1
- 'use strict'
2
-
3
- const {
4
- staticPropertyDescriptors,
5
- readOperation,
6
- fireAProgressEvent
7
- } = require('./util')
8
- const {
9
- kState,
10
- kError,
11
- kResult,
12
- kEvents,
13
- kAborted
14
- } = require('./symbols')
15
- const { webidl } = require('../fetch/webidl')
16
- const { kEnumerableProperty } = require('../../core/util')
17
-
18
- class FileReader extends EventTarget {
19
- constructor () {
20
- super()
21
-
22
- this[kState] = 'empty'
23
- this[kResult] = null
24
- this[kError] = null
25
- this[kEvents] = {
26
- loadend: null,
27
- error: null,
28
- abort: null,
29
- load: null,
30
- progress: null,
31
- loadstart: null
32
- }
33
- }
34
-
35
- /**
36
- * @see https://w3c.github.io/FileAPI/#dfn-readAsArrayBuffer
37
- * @param {import('buffer').Blob} blob
38
- */
39
- readAsArrayBuffer (blob) {
40
- webidl.brandCheck(this, FileReader)
41
-
42
- webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsArrayBuffer')
43
-
44
- blob = webidl.converters.Blob(blob, { strict: false })
45
-
46
- // The readAsArrayBuffer(blob) method, when invoked,
47
- // must initiate a read operation for blob with ArrayBuffer.
48
- readOperation(this, blob, 'ArrayBuffer')
49
- }
50
-
51
- /**
52
- * @see https://w3c.github.io/FileAPI/#readAsBinaryString
53
- * @param {import('buffer').Blob} blob
54
- */
55
- readAsBinaryString (blob) {
56
- webidl.brandCheck(this, FileReader)
57
-
58
- webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsBinaryString')
59
-
60
- blob = webidl.converters.Blob(blob, { strict: false })
61
-
62
- // The readAsBinaryString(blob) method, when invoked,
63
- // must initiate a read operation for blob with BinaryString.
64
- readOperation(this, blob, 'BinaryString')
65
- }
66
-
67
- /**
68
- * @see https://w3c.github.io/FileAPI/#readAsDataText
69
- * @param {import('buffer').Blob} blob
70
- * @param {string?} encoding
71
- */
72
- readAsText (blob, encoding = undefined) {
73
- webidl.brandCheck(this, FileReader)
74
-
75
- webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsText')
76
-
77
- blob = webidl.converters.Blob(blob, { strict: false })
78
-
79
- if (encoding !== undefined) {
80
- encoding = webidl.converters.DOMString(encoding, 'FileReader.readAsText', 'encoding')
81
- }
82
-
83
- // The readAsText(blob, encoding) method, when invoked,
84
- // must initiate a read operation for blob with Text and encoding.
85
- readOperation(this, blob, 'Text', encoding)
86
- }
87
-
88
- /**
89
- * @see https://w3c.github.io/FileAPI/#dfn-readAsDataURL
90
- * @param {import('buffer').Blob} blob
91
- */
92
- readAsDataURL (blob) {
93
- webidl.brandCheck(this, FileReader)
94
-
95
- webidl.argumentLengthCheck(arguments, 1, 'FileReader.readAsDataURL')
96
-
97
- blob = webidl.converters.Blob(blob, { strict: false })
98
-
99
- // The readAsDataURL(blob) method, when invoked, must
100
- // initiate a read operation for blob with DataURL.
101
- readOperation(this, blob, 'DataURL')
102
- }
103
-
104
- /**
105
- * @see https://w3c.github.io/FileAPI/#dfn-abort
106
- */
107
- abort () {
108
- // 1. If this's state is "empty" or if this's state is
109
- // "done" set this's result to null and terminate
110
- // this algorithm.
111
- if (this[kState] === 'empty' || this[kState] === 'done') {
112
- this[kResult] = null
113
- return
114
- }
115
-
116
- // 2. If this's state is "loading" set this's state to
117
- // "done" and set this's result to null.
118
- if (this[kState] === 'loading') {
119
- this[kState] = 'done'
120
- this[kResult] = null
121
- }
122
-
123
- // 3. If there are any tasks from this on the file reading
124
- // task source in an affiliated task queue, then remove
125
- // those tasks from that task queue.
126
- this[kAborted] = true
127
-
128
- // 4. Terminate the algorithm for the read method being processed.
129
- // TODO
130
-
131
- // 5. Fire a progress event called abort at this.
132
- fireAProgressEvent('abort', this)
133
-
134
- // 6. If this's state is not "loading", fire a progress
135
- // event called loadend at this.
136
- if (this[kState] !== 'loading') {
137
- fireAProgressEvent('loadend', this)
138
- }
139
- }
140
-
141
- /**
142
- * @see https://w3c.github.io/FileAPI/#dom-filereader-readystate
143
- */
144
- get readyState () {
145
- webidl.brandCheck(this, FileReader)
146
-
147
- switch (this[kState]) {
148
- case 'empty': return this.EMPTY
149
- case 'loading': return this.LOADING
150
- case 'done': return this.DONE
151
- }
152
- }
153
-
154
- /**
155
- * @see https://w3c.github.io/FileAPI/#dom-filereader-result
156
- */
157
- get result () {
158
- webidl.brandCheck(this, FileReader)
159
-
160
- // The result attribute’s getter, when invoked, must return
161
- // this's result.
162
- return this[kResult]
163
- }
164
-
165
- /**
166
- * @see https://w3c.github.io/FileAPI/#dom-filereader-error
167
- */
168
- get error () {
169
- webidl.brandCheck(this, FileReader)
170
-
171
- // The error attribute’s getter, when invoked, must return
172
- // this's error.
173
- return this[kError]
174
- }
175
-
176
- get onloadend () {
177
- webidl.brandCheck(this, FileReader)
178
-
179
- return this[kEvents].loadend
180
- }
181
-
182
- set onloadend (fn) {
183
- webidl.brandCheck(this, FileReader)
184
-
185
- if (this[kEvents].loadend) {
186
- this.removeEventListener('loadend', this[kEvents].loadend)
187
- }
188
-
189
- if (typeof fn === 'function') {
190
- this[kEvents].loadend = fn
191
- this.addEventListener('loadend', fn)
192
- } else {
193
- this[kEvents].loadend = null
194
- }
195
- }
196
-
197
- get onerror () {
198
- webidl.brandCheck(this, FileReader)
199
-
200
- return this[kEvents].error
201
- }
202
-
203
- set onerror (fn) {
204
- webidl.brandCheck(this, FileReader)
205
-
206
- if (this[kEvents].error) {
207
- this.removeEventListener('error', this[kEvents].error)
208
- }
209
-
210
- if (typeof fn === 'function') {
211
- this[kEvents].error = fn
212
- this.addEventListener('error', fn)
213
- } else {
214
- this[kEvents].error = null
215
- }
216
- }
217
-
218
- get onloadstart () {
219
- webidl.brandCheck(this, FileReader)
220
-
221
- return this[kEvents].loadstart
222
- }
223
-
224
- set onloadstart (fn) {
225
- webidl.brandCheck(this, FileReader)
226
-
227
- if (this[kEvents].loadstart) {
228
- this.removeEventListener('loadstart', this[kEvents].loadstart)
229
- }
230
-
231
- if (typeof fn === 'function') {
232
- this[kEvents].loadstart = fn
233
- this.addEventListener('loadstart', fn)
234
- } else {
235
- this[kEvents].loadstart = null
236
- }
237
- }
238
-
239
- get onprogress () {
240
- webidl.brandCheck(this, FileReader)
241
-
242
- return this[kEvents].progress
243
- }
244
-
245
- set onprogress (fn) {
246
- webidl.brandCheck(this, FileReader)
247
-
248
- if (this[kEvents].progress) {
249
- this.removeEventListener('progress', this[kEvents].progress)
250
- }
251
-
252
- if (typeof fn === 'function') {
253
- this[kEvents].progress = fn
254
- this.addEventListener('progress', fn)
255
- } else {
256
- this[kEvents].progress = null
257
- }
258
- }
259
-
260
- get onload () {
261
- webidl.brandCheck(this, FileReader)
262
-
263
- return this[kEvents].load
264
- }
265
-
266
- set onload (fn) {
267
- webidl.brandCheck(this, FileReader)
268
-
269
- if (this[kEvents].load) {
270
- this.removeEventListener('load', this[kEvents].load)
271
- }
272
-
273
- if (typeof fn === 'function') {
274
- this[kEvents].load = fn
275
- this.addEventListener('load', fn)
276
- } else {
277
- this[kEvents].load = null
278
- }
279
- }
280
-
281
- get onabort () {
282
- webidl.brandCheck(this, FileReader)
283
-
284
- return this[kEvents].abort
285
- }
286
-
287
- set onabort (fn) {
288
- webidl.brandCheck(this, FileReader)
289
-
290
- if (this[kEvents].abort) {
291
- this.removeEventListener('abort', this[kEvents].abort)
292
- }
293
-
294
- if (typeof fn === 'function') {
295
- this[kEvents].abort = fn
296
- this.addEventListener('abort', fn)
297
- } else {
298
- this[kEvents].abort = null
299
- }
300
- }
301
- }
302
-
303
- // https://w3c.github.io/FileAPI/#dom-filereader-empty
304
- FileReader.EMPTY = FileReader.prototype.EMPTY = 0
305
- // https://w3c.github.io/FileAPI/#dom-filereader-loading
306
- FileReader.LOADING = FileReader.prototype.LOADING = 1
307
- // https://w3c.github.io/FileAPI/#dom-filereader-done
308
- FileReader.DONE = FileReader.prototype.DONE = 2
309
-
310
- Object.defineProperties(FileReader.prototype, {
311
- EMPTY: staticPropertyDescriptors,
312
- LOADING: staticPropertyDescriptors,
313
- DONE: staticPropertyDescriptors,
314
- readAsArrayBuffer: kEnumerableProperty,
315
- readAsBinaryString: kEnumerableProperty,
316
- readAsText: kEnumerableProperty,
317
- readAsDataURL: kEnumerableProperty,
318
- abort: kEnumerableProperty,
319
- readyState: kEnumerableProperty,
320
- result: kEnumerableProperty,
321
- error: kEnumerableProperty,
322
- onloadstart: kEnumerableProperty,
323
- onprogress: kEnumerableProperty,
324
- onload: kEnumerableProperty,
325
- onabort: kEnumerableProperty,
326
- onerror: kEnumerableProperty,
327
- onloadend: kEnumerableProperty,
328
- [Symbol.toStringTag]: {
329
- value: 'FileReader',
330
- writable: false,
331
- enumerable: false,
332
- configurable: true
333
- }
334
- })
335
-
336
- Object.defineProperties(FileReader, {
337
- EMPTY: staticPropertyDescriptors,
338
- LOADING: staticPropertyDescriptors,
339
- DONE: staticPropertyDescriptors
340
- })
341
-
342
- module.exports = {
343
- FileReader
344
- }
@@ -1,78 +0,0 @@
1
- 'use strict'
2
-
3
- const { webidl } = require('../fetch/webidl')
4
-
5
- const kState = Symbol('ProgressEvent state')
6
-
7
- /**
8
- * @see https://xhr.spec.whatwg.org/#progressevent
9
- */
10
- class ProgressEvent extends Event {
11
- constructor (type, eventInitDict = {}) {
12
- type = webidl.converters.DOMString(type, 'ProgressEvent constructor', 'type')
13
- eventInitDict = webidl.converters.ProgressEventInit(eventInitDict ?? {})
14
-
15
- super(type, eventInitDict)
16
-
17
- this[kState] = {
18
- lengthComputable: eventInitDict.lengthComputable,
19
- loaded: eventInitDict.loaded,
20
- total: eventInitDict.total
21
- }
22
- }
23
-
24
- get lengthComputable () {
25
- webidl.brandCheck(this, ProgressEvent)
26
-
27
- return this[kState].lengthComputable
28
- }
29
-
30
- get loaded () {
31
- webidl.brandCheck(this, ProgressEvent)
32
-
33
- return this[kState].loaded
34
- }
35
-
36
- get total () {
37
- webidl.brandCheck(this, ProgressEvent)
38
-
39
- return this[kState].total
40
- }
41
- }
42
-
43
- webidl.converters.ProgressEventInit = webidl.dictionaryConverter([
44
- {
45
- key: 'lengthComputable',
46
- converter: webidl.converters.boolean,
47
- defaultValue: () => false
48
- },
49
- {
50
- key: 'loaded',
51
- converter: webidl.converters['unsigned long long'],
52
- defaultValue: () => 0
53
- },
54
- {
55
- key: 'total',
56
- converter: webidl.converters['unsigned long long'],
57
- defaultValue: () => 0
58
- },
59
- {
60
- key: 'bubbles',
61
- converter: webidl.converters.boolean,
62
- defaultValue: () => false
63
- },
64
- {
65
- key: 'cancelable',
66
- converter: webidl.converters.boolean,
67
- defaultValue: () => false
68
- },
69
- {
70
- key: 'composed',
71
- converter: webidl.converters.boolean,
72
- defaultValue: () => false
73
- }
74
- ])
75
-
76
- module.exports = {
77
- ProgressEvent
78
- }
@@ -1,10 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- kState: Symbol('FileReader state'),
5
- kResult: Symbol('FileReader result'),
6
- kError: Symbol('FileReader error'),
7
- kLastProgressEventFired: Symbol('FileReader last progress event fired timestamp'),
8
- kEvents: Symbol('FileReader events'),
9
- kAborted: Symbol('FileReader aborted')
10
- }