deepv-code 1.0.182 → 1.0.183

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 (193) hide show
  1. package/bundle/dvcode.js +635 -635
  2. package/package.json +1 -1
  3. package/bundle/assets/help/README.md +0 -113
  4. package/bundle/assets/sounds/README.md +0 -74
  5. package/bundle/node_modules/undici/LICENSE +0 -21
  6. package/bundle/node_modules/undici/README.md +0 -472
  7. package/bundle/node_modules/undici/docs/docs/api/Agent.md +0 -83
  8. package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +0 -99
  9. package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +0 -30
  10. package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +0 -151
  11. package/bundle/node_modules/undici/docs/docs/api/Client.md +0 -281
  12. package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +0 -27
  13. package/bundle/node_modules/undici/docs/docs/api/Connector.md +0 -115
  14. package/bundle/node_modules/undici/docs/docs/api/ContentType.md +0 -57
  15. package/bundle/node_modules/undici/docs/docs/api/Cookies.md +0 -101
  16. package/bundle/node_modules/undici/docs/docs/api/Debug.md +0 -62
  17. package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +0 -204
  18. package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +0 -1200
  19. package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +0 -159
  20. package/bundle/node_modules/undici/docs/docs/api/Errors.md +0 -49
  21. package/bundle/node_modules/undici/docs/docs/api/EventSource.md +0 -45
  22. package/bundle/node_modules/undici/docs/docs/api/Fetch.md +0 -52
  23. package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +0 -262
  24. package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +0 -603
  25. package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -197
  26. package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -43
  27. package/bundle/node_modules/undici/docs/docs/api/MockClient.md +0 -77
  28. package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +0 -12
  29. package/bundle/node_modules/undici/docs/docs/api/MockPool.md +0 -548
  30. package/bundle/node_modules/undici/docs/docs/api/Pool.md +0 -84
  31. package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +0 -35
  32. package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +0 -227
  33. package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +0 -96
  34. package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +0 -45
  35. package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +0 -117
  36. package/bundle/node_modules/undici/docs/docs/api/Util.md +0 -25
  37. package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +0 -85
  38. package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +0 -91
  39. package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -64
  40. package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +0 -190
  41. package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +0 -127
  42. package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -20
  43. package/bundle/node_modules/undici/index-fetch.js +0 -35
  44. package/bundle/node_modules/undici/index.d.ts +0 -3
  45. package/bundle/node_modules/undici/index.js +0 -183
  46. package/bundle/node_modules/undici/lib/api/abort-signal.js +0 -59
  47. package/bundle/node_modules/undici/lib/api/api-connect.js +0 -110
  48. package/bundle/node_modules/undici/lib/api/api-pipeline.js +0 -252
  49. package/bundle/node_modules/undici/lib/api/api-request.js +0 -199
  50. package/bundle/node_modules/undici/lib/api/api-stream.js +0 -209
  51. package/bundle/node_modules/undici/lib/api/api-upgrade.js +0 -110
  52. package/bundle/node_modules/undici/lib/api/index.js +0 -7
  53. package/bundle/node_modules/undici/lib/api/readable.js +0 -558
  54. package/bundle/node_modules/undici/lib/api/util.js +0 -95
  55. package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +0 -234
  56. package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +0 -461
  57. package/bundle/node_modules/undici/lib/core/connect.js +0 -164
  58. package/bundle/node_modules/undici/lib/core/constants.js +0 -143
  59. package/bundle/node_modules/undici/lib/core/diagnostics.js +0 -196
  60. package/bundle/node_modules/undici/lib/core/errors.js +0 -244
  61. package/bundle/node_modules/undici/lib/core/request.js +0 -397
  62. package/bundle/node_modules/undici/lib/core/symbols.js +0 -68
  63. package/bundle/node_modules/undici/lib/core/tree.js +0 -160
  64. package/bundle/node_modules/undici/lib/core/util.js +0 -988
  65. package/bundle/node_modules/undici/lib/dispatcher/agent.js +0 -135
  66. package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +0 -206
  67. package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +0 -1615
  68. package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +0 -798
  69. package/bundle/node_modules/undici/lib/dispatcher/client.js +0 -614
  70. package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +0 -161
  71. package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +0 -48
  72. package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +0 -151
  73. package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +0 -159
  74. package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +0 -122
  75. package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +0 -191
  76. package/bundle/node_modules/undici/lib/dispatcher/pool.js +0 -118
  77. package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +0 -275
  78. package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +0 -35
  79. package/bundle/node_modules/undici/lib/global.js +0 -32
  80. package/bundle/node_modules/undici/lib/handler/cache-handler.js +0 -448
  81. package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +0 -124
  82. package/bundle/node_modules/undici/lib/handler/decorator-handler.js +0 -67
  83. package/bundle/node_modules/undici/lib/handler/redirect-handler.js +0 -227
  84. package/bundle/node_modules/undici/lib/handler/retry-handler.js +0 -342
  85. package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +0 -96
  86. package/bundle/node_modules/undici/lib/handler/wrap-handler.js +0 -95
  87. package/bundle/node_modules/undici/lib/interceptor/cache.js +0 -372
  88. package/bundle/node_modules/undici/lib/interceptor/dns.js +0 -432
  89. package/bundle/node_modules/undici/lib/interceptor/dump.js +0 -111
  90. package/bundle/node_modules/undici/lib/interceptor/redirect.js +0 -21
  91. package/bundle/node_modules/undici/lib/interceptor/response-error.js +0 -95
  92. package/bundle/node_modules/undici/lib/interceptor/retry.js +0 -19
  93. package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  94. package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +0 -97
  95. package/bundle/node_modules/undici/lib/llhttp/constants.js +0 -498
  96. package/bundle/node_modules/undici/lib/llhttp/constants.js.map +0 -1
  97. package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +0 -15
  98. package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +0 -15
  99. package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +0 -2
  100. package/bundle/node_modules/undici/lib/llhttp/utils.js +0 -15
  101. package/bundle/node_modules/undici/lib/llhttp/utils.js.map +0 -1
  102. package/bundle/node_modules/undici/lib/mock/mock-agent.js +0 -224
  103. package/bundle/node_modules/undici/lib/mock/mock-call-history.js +0 -248
  104. package/bundle/node_modules/undici/lib/mock/mock-client.js +0 -64
  105. package/bundle/node_modules/undici/lib/mock/mock-errors.js +0 -19
  106. package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +0 -209
  107. package/bundle/node_modules/undici/lib/mock/mock-pool.js +0 -64
  108. package/bundle/node_modules/undici/lib/mock/mock-symbols.js +0 -31
  109. package/bundle/node_modules/undici/lib/mock/mock-utils.js +0 -433
  110. package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +0 -43
  111. package/bundle/node_modules/undici/lib/util/cache.js +0 -368
  112. package/bundle/node_modules/undici/lib/util/date.js +0 -259
  113. package/bundle/node_modules/undici/lib/util/stats.js +0 -32
  114. package/bundle/node_modules/undici/lib/util/timers.js +0 -423
  115. package/bundle/node_modules/undici/lib/web/cache/cache.js +0 -862
  116. package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +0 -152
  117. package/bundle/node_modules/undici/lib/web/cache/util.js +0 -45
  118. package/bundle/node_modules/undici/lib/web/cookies/constants.js +0 -12
  119. package/bundle/node_modules/undici/lib/web/cookies/index.js +0 -199
  120. package/bundle/node_modules/undici/lib/web/cookies/parse.js +0 -322
  121. package/bundle/node_modules/undici/lib/web/cookies/util.js +0 -282
  122. package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +0 -399
  123. package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +0 -484
  124. package/bundle/node_modules/undici/lib/web/eventsource/util.js +0 -37
  125. package/bundle/node_modules/undici/lib/web/fetch/LICENSE +0 -21
  126. package/bundle/node_modules/undici/lib/web/fetch/body.js +0 -532
  127. package/bundle/node_modules/undici/lib/web/fetch/constants.js +0 -131
  128. package/bundle/node_modules/undici/lib/web/fetch/data-url.js +0 -744
  129. package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +0 -46
  130. package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +0 -501
  131. package/bundle/node_modules/undici/lib/web/fetch/formdata.js +0 -263
  132. package/bundle/node_modules/undici/lib/web/fetch/global.js +0 -40
  133. package/bundle/node_modules/undici/lib/web/fetch/headers.js +0 -719
  134. package/bundle/node_modules/undici/lib/web/fetch/index.js +0 -2258
  135. package/bundle/node_modules/undici/lib/web/fetch/request.js +0 -1099
  136. package/bundle/node_modules/undici/lib/web/fetch/response.js +0 -636
  137. package/bundle/node_modules/undici/lib/web/fetch/util.js +0 -1782
  138. package/bundle/node_modules/undici/lib/web/fetch/webidl.js +0 -740
  139. package/bundle/node_modules/undici/lib/web/websocket/connection.js +0 -325
  140. package/bundle/node_modules/undici/lib/web/websocket/constants.js +0 -126
  141. package/bundle/node_modules/undici/lib/web/websocket/events.js +0 -331
  142. package/bundle/node_modules/undici/lib/web/websocket/frame.js +0 -138
  143. package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +0 -70
  144. package/bundle/node_modules/undici/lib/web/websocket/receiver.js +0 -454
  145. package/bundle/node_modules/undici/lib/web/websocket/sender.js +0 -109
  146. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +0 -83
  147. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +0 -485
  148. package/bundle/node_modules/undici/lib/web/websocket/util.js +0 -338
  149. package/bundle/node_modules/undici/lib/web/websocket/websocket.js +0 -686
  150. package/bundle/node_modules/undici/package.json +0 -149
  151. package/bundle/node_modules/undici/scripts/strip-comments.js +0 -10
  152. package/bundle/node_modules/undici/types/README.md +0 -6
  153. package/bundle/node_modules/undici/types/agent.d.ts +0 -35
  154. package/bundle/node_modules/undici/types/api.d.ts +0 -43
  155. package/bundle/node_modules/undici/types/balanced-pool.d.ts +0 -29
  156. package/bundle/node_modules/undici/types/cache-interceptor.d.ts +0 -172
  157. package/bundle/node_modules/undici/types/cache.d.ts +0 -36
  158. package/bundle/node_modules/undici/types/client-stats.d.ts +0 -15
  159. package/bundle/node_modules/undici/types/client.d.ts +0 -110
  160. package/bundle/node_modules/undici/types/connector.d.ts +0 -34
  161. package/bundle/node_modules/undici/types/content-type.d.ts +0 -21
  162. package/bundle/node_modules/undici/types/cookies.d.ts +0 -30
  163. package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +0 -66
  164. package/bundle/node_modules/undici/types/dispatcher.d.ts +0 -281
  165. package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +0 -21
  166. package/bundle/node_modules/undici/types/errors.d.ts +0 -171
  167. package/bundle/node_modules/undici/types/eventsource.d.ts +0 -61
  168. package/bundle/node_modules/undici/types/fetch.d.ts +0 -210
  169. package/bundle/node_modules/undici/types/formdata.d.ts +0 -108
  170. package/bundle/node_modules/undici/types/global-dispatcher.d.ts +0 -9
  171. package/bundle/node_modules/undici/types/global-origin.d.ts +0 -7
  172. package/bundle/node_modules/undici/types/h2c-client.d.ts +0 -75
  173. package/bundle/node_modules/undici/types/handlers.d.ts +0 -15
  174. package/bundle/node_modules/undici/types/header.d.ts +0 -160
  175. package/bundle/node_modules/undici/types/index.d.ts +0 -75
  176. package/bundle/node_modules/undici/types/interceptors.d.ts +0 -34
  177. package/bundle/node_modules/undici/types/mock-agent.d.ts +0 -68
  178. package/bundle/node_modules/undici/types/mock-call-history.d.ts +0 -111
  179. package/bundle/node_modules/undici/types/mock-client.d.ts +0 -25
  180. package/bundle/node_modules/undici/types/mock-errors.d.ts +0 -12
  181. package/bundle/node_modules/undici/types/mock-interceptor.d.ts +0 -93
  182. package/bundle/node_modules/undici/types/mock-pool.d.ts +0 -25
  183. package/bundle/node_modules/undici/types/patch.d.ts +0 -29
  184. package/bundle/node_modules/undici/types/pool-stats.d.ts +0 -19
  185. package/bundle/node_modules/undici/types/pool.d.ts +0 -41
  186. package/bundle/node_modules/undici/types/proxy-agent.d.ts +0 -29
  187. package/bundle/node_modules/undici/types/readable.d.ts +0 -68
  188. package/bundle/node_modules/undici/types/retry-agent.d.ts +0 -8
  189. package/bundle/node_modules/undici/types/retry-handler.d.ts +0 -116
  190. package/bundle/node_modules/undici/types/util.d.ts +0 -18
  191. package/bundle/node_modules/undici/types/utility.d.ts +0 -7
  192. package/bundle/node_modules/undici/types/webidl.d.ts +0 -266
  193. package/bundle/node_modules/undici/types/websocket.d.ts +0 -184
@@ -1,532 +0,0 @@
1
- 'use strict'
2
-
3
- const util = require('../../core/util')
4
- const {
5
- ReadableStreamFrom,
6
- readableStreamClose,
7
- createDeferredPromise,
8
- fullyReadBody,
9
- extractMimeType,
10
- utf8DecodeBytes
11
- } = require('./util')
12
- const { FormData, setFormDataState } = require('./formdata')
13
- const { webidl } = require('./webidl')
14
- const { Blob } = require('node:buffer')
15
- const assert = require('node:assert')
16
- const { isErrored, isDisturbed } = require('node:stream')
17
- const { isArrayBuffer } = require('node:util/types')
18
- const { serializeAMimeType } = require('./data-url')
19
- const { multipartFormDataParser } = require('./formdata-parser')
20
- let random
21
-
22
- try {
23
- const crypto = require('node:crypto')
24
- random = (max) => crypto.randomInt(0, max)
25
- } catch {
26
- random = (max) => Math.floor(Math.random() * max)
27
- }
28
-
29
- const textEncoder = new TextEncoder()
30
- function noop () {}
31
-
32
- const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
33
- let streamRegistry
34
-
35
- if (hasFinalizationRegistry) {
36
- streamRegistry = new FinalizationRegistry((weakRef) => {
37
- const stream = weakRef.deref()
38
- if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
39
- stream.cancel('Response object has been garbage collected').catch(noop)
40
- }
41
- })
42
- }
43
-
44
- // https://fetch.spec.whatwg.org/#concept-bodyinit-extract
45
- function extractBody (object, keepalive = false) {
46
- // 1. Let stream be null.
47
- let stream = null
48
-
49
- // 2. If object is a ReadableStream object, then set stream to object.
50
- if (webidl.is.ReadableStream(object)) {
51
- stream = object
52
- } else if (webidl.is.Blob(object)) {
53
- // 3. Otherwise, if object is a Blob object, set stream to the
54
- // result of running object’s get stream.
55
- stream = object.stream()
56
- } else {
57
- // 4. Otherwise, set stream to a new ReadableStream object, and set
58
- // up stream with byte reading support.
59
- stream = new ReadableStream({
60
- async pull (controller) {
61
- const buffer = typeof source === 'string' ? textEncoder.encode(source) : source
62
-
63
- if (buffer.byteLength) {
64
- controller.enqueue(buffer)
65
- }
66
-
67
- queueMicrotask(() => readableStreamClose(controller))
68
- },
69
- start () {},
70
- type: 'bytes'
71
- })
72
- }
73
-
74
- // 5. Assert: stream is a ReadableStream object.
75
- assert(webidl.is.ReadableStream(stream))
76
-
77
- // 6. Let action be null.
78
- let action = null
79
-
80
- // 7. Let source be null.
81
- let source = null
82
-
83
- // 8. Let length be null.
84
- let length = null
85
-
86
- // 9. Let type be null.
87
- let type = null
88
-
89
- // 10. Switch on object:
90
- if (typeof object === 'string') {
91
- // Set source to the UTF-8 encoding of object.
92
- // Note: setting source to a Uint8Array here breaks some mocking assumptions.
93
- source = object
94
-
95
- // Set type to `text/plain;charset=UTF-8`.
96
- type = 'text/plain;charset=UTF-8'
97
- } else if (webidl.is.URLSearchParams(object)) {
98
- // URLSearchParams
99
-
100
- // spec says to run application/x-www-form-urlencoded on body.list
101
- // this is implemented in Node.js as apart of an URLSearchParams instance toString method
102
- // See: https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/url.js#L490
103
- // and https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/url.js#L1100
104
-
105
- // Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.
106
- source = object.toString()
107
-
108
- // Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
109
- type = 'application/x-www-form-urlencoded;charset=UTF-8'
110
- } else if (isArrayBuffer(object)) {
111
- // BufferSource/ArrayBuffer
112
-
113
- // Set source to a copy of the bytes held by object.
114
- source = new Uint8Array(object.slice())
115
- } else if (ArrayBuffer.isView(object)) {
116
- // BufferSource/ArrayBufferView
117
-
118
- // Set source to a copy of the bytes held by object.
119
- source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
120
- } else if (webidl.is.FormData(object)) {
121
- const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
122
- const prefix = `--${boundary}\r\nContent-Disposition: form-data`
123
-
124
- /*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
125
- const escape = (str) =>
126
- str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22')
127
- const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n')
128
-
129
- // Set action to this step: run the multipart/form-data
130
- // encoding algorithm, with object’s entry list and UTF-8.
131
- // - This ensures that the body is immutable and can't be changed afterwords
132
- // - That the content-length is calculated in advance.
133
- // - And that all parts are pre-encoded and ready to be sent.
134
-
135
- const blobParts = []
136
- const rn = new Uint8Array([13, 10]) // '\r\n'
137
- length = 0
138
- let hasUnknownSizeValue = false
139
-
140
- for (const [name, value] of object) {
141
- if (typeof value === 'string') {
142
- const chunk = textEncoder.encode(prefix +
143
- `; name="${escape(normalizeLinefeeds(name))}"` +
144
- `\r\n\r\n${normalizeLinefeeds(value)}\r\n`)
145
- blobParts.push(chunk)
146
- length += chunk.byteLength
147
- } else {
148
- const chunk = textEncoder.encode(`${prefix}; name="${escape(normalizeLinefeeds(name))}"` +
149
- (value.name ? `; filename="${escape(value.name)}"` : '') + '\r\n' +
150
- `Content-Type: ${
151
- value.type || 'application/octet-stream'
152
- }\r\n\r\n`)
153
- blobParts.push(chunk, value, rn)
154
- if (typeof value.size === 'number') {
155
- length += chunk.byteLength + value.size + rn.byteLength
156
- } else {
157
- hasUnknownSizeValue = true
158
- }
159
- }
160
- }
161
-
162
- // CRLF is appended to the body to function with legacy servers and match other implementations.
163
- // https://github.com/curl/curl/blob/3434c6b46e682452973972e8313613dfa58cd690/lib/mime.c#L1029-L1030
164
- // https://github.com/form-data/form-data/issues/63
165
- const chunk = textEncoder.encode(`--${boundary}--\r\n`)
166
- blobParts.push(chunk)
167
- length += chunk.byteLength
168
- if (hasUnknownSizeValue) {
169
- length = null
170
- }
171
-
172
- // Set source to object.
173
- source = object
174
-
175
- action = async function * () {
176
- for (const part of blobParts) {
177
- if (part.stream) {
178
- yield * part.stream()
179
- } else {
180
- yield part
181
- }
182
- }
183
- }
184
-
185
- // Set type to `multipart/form-data; boundary=`,
186
- // followed by the multipart/form-data boundary string generated
187
- // by the multipart/form-data encoding algorithm.
188
- type = `multipart/form-data; boundary=${boundary}`
189
- } else if (webidl.is.Blob(object)) {
190
- // Blob
191
-
192
- // Set source to object.
193
- source = object
194
-
195
- // Set length to object’s size.
196
- length = object.size
197
-
198
- // If object’s type attribute is not the empty byte sequence, set
199
- // type to its value.
200
- if (object.type) {
201
- type = object.type
202
- }
203
- } else if (typeof object[Symbol.asyncIterator] === 'function') {
204
- // If keepalive is true, then throw a TypeError.
205
- if (keepalive) {
206
- throw new TypeError('keepalive')
207
- }
208
-
209
- // If object is disturbed or locked, then throw a TypeError.
210
- if (util.isDisturbed(object) || object.locked) {
211
- throw new TypeError(
212
- 'Response body object should not be disturbed or locked'
213
- )
214
- }
215
-
216
- stream =
217
- webidl.is.ReadableStream(object) ? object : ReadableStreamFrom(object)
218
- }
219
-
220
- // 11. If source is a byte sequence, then set action to a
221
- // step that returns source and length to source’s length.
222
- if (typeof source === 'string' || util.isBuffer(source)) {
223
- length = Buffer.byteLength(source)
224
- }
225
-
226
- // 12. If action is non-null, then run these steps in in parallel:
227
- if (action != null) {
228
- // Run action.
229
- let iterator
230
- stream = new ReadableStream({
231
- async start () {
232
- iterator = action(object)[Symbol.asyncIterator]()
233
- },
234
- async pull (controller) {
235
- const { value, done } = await iterator.next()
236
- if (done) {
237
- // When running action is done, close stream.
238
- queueMicrotask(() => {
239
- controller.close()
240
- controller.byobRequest?.respond(0)
241
- })
242
- } else {
243
- // Whenever one or more bytes are available and stream is not errored,
244
- // enqueue a Uint8Array wrapping an ArrayBuffer containing the available
245
- // bytes into stream.
246
- if (!isErrored(stream)) {
247
- const buffer = new Uint8Array(value)
248
- if (buffer.byteLength) {
249
- controller.enqueue(buffer)
250
- }
251
- }
252
- }
253
- return controller.desiredSize > 0
254
- },
255
- async cancel (reason) {
256
- await iterator.return()
257
- },
258
- type: 'bytes'
259
- })
260
- }
261
-
262
- // 13. Let body be a body whose stream is stream, source is source,
263
- // and length is length.
264
- const body = { stream, source, length }
265
-
266
- // 14. Return (body, type).
267
- return [body, type]
268
- }
269
-
270
- // https://fetch.spec.whatwg.org/#bodyinit-safely-extract
271
- function safelyExtractBody (object, keepalive = false) {
272
- // To safely extract a body and a `Content-Type` value from
273
- // a byte sequence or BodyInit object object, run these steps:
274
-
275
- // 1. If object is a ReadableStream object, then:
276
- if (webidl.is.ReadableStream(object)) {
277
- // Assert: object is neither disturbed nor locked.
278
- // istanbul ignore next
279
- assert(!util.isDisturbed(object), 'The body has already been consumed.')
280
- // istanbul ignore next
281
- assert(!object.locked, 'The stream is locked.')
282
- }
283
-
284
- // 2. Return the results of extracting object.
285
- return extractBody(object, keepalive)
286
- }
287
-
288
- function cloneBody (instance, body) {
289
- // To clone a body body, run these steps:
290
-
291
- // https://fetch.spec.whatwg.org/#concept-body-clone
292
-
293
- // 1. Let « out1, out2 » be the result of teeing body’s stream.
294
- const [out1, out2] = body.stream.tee()
295
-
296
- if (hasFinalizationRegistry) {
297
- streamRegistry.register(instance, new WeakRef(out1))
298
- }
299
-
300
- // 2. Set body’s stream to out1.
301
- body.stream = out1
302
-
303
- // 3. Return a body whose stream is out2 and other members are copied from body.
304
- return {
305
- stream: out2,
306
- length: body.length,
307
- source: body.source
308
- }
309
- }
310
-
311
- function throwIfAborted (state) {
312
- if (state.aborted) {
313
- throw new DOMException('The operation was aborted.', 'AbortError')
314
- }
315
- }
316
-
317
- function bodyMixinMethods (instance, getInternalState) {
318
- const methods = {
319
- blob () {
320
- // The blob() method steps are to return the result of
321
- // running consume body with this and the following step
322
- // given a byte sequence bytes: return a Blob whose
323
- // contents are bytes and whose type attribute is this’s
324
- // MIME type.
325
- return consumeBody(this, (bytes) => {
326
- let mimeType = bodyMimeType(getInternalState(this))
327
-
328
- if (mimeType === null) {
329
- mimeType = ''
330
- } else if (mimeType) {
331
- mimeType = serializeAMimeType(mimeType)
332
- }
333
-
334
- // Return a Blob whose contents are bytes and type attribute
335
- // is mimeType.
336
- return new Blob([bytes], { type: mimeType })
337
- }, instance, getInternalState)
338
- },
339
-
340
- arrayBuffer () {
341
- // The arrayBuffer() method steps are to return the result
342
- // of running consume body with this and the following step
343
- // given a byte sequence bytes: return a new ArrayBuffer
344
- // whose contents are bytes.
345
- return consumeBody(this, (bytes) => {
346
- return new Uint8Array(bytes).buffer
347
- }, instance, getInternalState)
348
- },
349
-
350
- text () {
351
- // The text() method steps are to return the result of running
352
- // consume body with this and UTF-8 decode.
353
- return consumeBody(this, utf8DecodeBytes, instance, getInternalState)
354
- },
355
-
356
- json () {
357
- // The json() method steps are to return the result of running
358
- // consume body with this and parse JSON from bytes.
359
- return consumeBody(this, parseJSONFromBytes, instance, getInternalState)
360
- },
361
-
362
- formData () {
363
- // The formData() method steps are to return the result of running
364
- // consume body with this and the following step given a byte sequence bytes:
365
- return consumeBody(this, (value) => {
366
- // 1. Let mimeType be the result of get the MIME type with this.
367
- const mimeType = bodyMimeType(getInternalState(this))
368
-
369
- // 2. If mimeType is non-null, then switch on mimeType’s essence and run
370
- // the corresponding steps:
371
- if (mimeType !== null) {
372
- switch (mimeType.essence) {
373
- case 'multipart/form-data': {
374
- // 1. ... [long step]
375
- // 2. If that fails for some reason, then throw a TypeError.
376
- const parsed = multipartFormDataParser(value, mimeType)
377
-
378
- // 3. Return a new FormData object, appending each entry,
379
- // resulting from the parsing operation, to its entry list.
380
- const fd = new FormData()
381
- setFormDataState(fd, parsed)
382
-
383
- return fd
384
- }
385
- case 'application/x-www-form-urlencoded': {
386
- // 1. Let entries be the result of parsing bytes.
387
- const entries = new URLSearchParams(value.toString())
388
-
389
- // 2. If entries is failure, then throw a TypeError.
390
-
391
- // 3. Return a new FormData object whose entry list is entries.
392
- const fd = new FormData()
393
-
394
- for (const [name, value] of entries) {
395
- fd.append(name, value)
396
- }
397
-
398
- return fd
399
- }
400
- }
401
- }
402
-
403
- // 3. Throw a TypeError.
404
- throw new TypeError(
405
- 'Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".'
406
- )
407
- }, instance, getInternalState)
408
- },
409
-
410
- bytes () {
411
- // The bytes() method steps are to return the result of running consume body
412
- // with this and the following step given a byte sequence bytes: return the
413
- // result of creating a Uint8Array from bytes in this’s relevant realm.
414
- return consumeBody(this, (bytes) => {
415
- return new Uint8Array(bytes)
416
- }, instance, getInternalState)
417
- }
418
- }
419
-
420
- return methods
421
- }
422
-
423
- function mixinBody (prototype, getInternalState) {
424
- Object.assign(prototype.prototype, bodyMixinMethods(prototype, getInternalState))
425
- }
426
-
427
- /**
428
- * @see https://fetch.spec.whatwg.org/#concept-body-consume-body
429
- * @param {any} object internal state
430
- * @param {(value: unknown) => unknown} convertBytesToJSValue
431
- * @param {any} instance
432
- * @param {(target: any) => any} getInternalState
433
- */
434
- async function consumeBody (object, convertBytesToJSValue, instance, getInternalState) {
435
- webidl.brandCheck(object, instance)
436
-
437
- const state = getInternalState(object)
438
-
439
- // 1. If object is unusable, then return a promise rejected
440
- // with a TypeError.
441
- if (bodyUnusable(state)) {
442
- throw new TypeError('Body is unusable: Body has already been read')
443
- }
444
-
445
- throwIfAborted(state)
446
-
447
- // 2. Let promise be a new promise.
448
- const promise = createDeferredPromise()
449
-
450
- // 3. Let errorSteps given error be to reject promise with error.
451
- const errorSteps = (error) => promise.reject(error)
452
-
453
- // 4. Let successSteps given a byte sequence data be to resolve
454
- // promise with the result of running convertBytesToJSValue
455
- // with data. If that threw an exception, then run errorSteps
456
- // with that exception.
457
- const successSteps = (data) => {
458
- try {
459
- promise.resolve(convertBytesToJSValue(data))
460
- } catch (e) {
461
- errorSteps(e)
462
- }
463
- }
464
-
465
- // 5. If object’s body is null, then run successSteps with an
466
- // empty byte sequence.
467
- if (state.body == null) {
468
- successSteps(Buffer.allocUnsafe(0))
469
- return promise.promise
470
- }
471
-
472
- // 6. Otherwise, fully read object’s body given successSteps,
473
- // errorSteps, and object’s relevant global object.
474
- fullyReadBody(state.body, successSteps, errorSteps)
475
-
476
- // 7. Return promise.
477
- return promise.promise
478
- }
479
-
480
- /**
481
- * @see https://fetch.spec.whatwg.org/#body-unusable
482
- * @param {any} object internal state
483
- */
484
- function bodyUnusable (object) {
485
- const body = object.body
486
-
487
- // An object including the Body interface mixin is
488
- // said to be unusable if its body is non-null and
489
- // its body’s stream is disturbed or locked.
490
- return body != null && (body.stream.locked || util.isDisturbed(body.stream))
491
- }
492
-
493
- /**
494
- * @see https://infra.spec.whatwg.org/#parse-json-bytes-to-a-javascript-value
495
- * @param {Uint8Array} bytes
496
- */
497
- function parseJSONFromBytes (bytes) {
498
- return JSON.parse(utf8DecodeBytes(bytes))
499
- }
500
-
501
- /**
502
- * @see https://fetch.spec.whatwg.org/#concept-body-mime-type
503
- * @param {any} requestOrResponse internal state
504
- */
505
- function bodyMimeType (requestOrResponse) {
506
- // 1. Let headers be null.
507
- // 2. If requestOrResponse is a Request object, then set headers to requestOrResponse’s request’s header list.
508
- // 3. Otherwise, set headers to requestOrResponse’s response’s header list.
509
- /** @type {import('./headers').HeadersList} */
510
- const headers = requestOrResponse.headersList
511
-
512
- // 4. Let mimeType be the result of extracting a MIME type from headers.
513
- const mimeType = extractMimeType(headers)
514
-
515
- // 5. If mimeType is failure, then return null.
516
- if (mimeType === 'failure') {
517
- return null
518
- }
519
-
520
- // 6. Return mimeType.
521
- return mimeType
522
- }
523
-
524
- module.exports = {
525
- extractBody,
526
- safelyExtractBody,
527
- cloneBody,
528
- mixinBody,
529
- streamRegistry,
530
- hasFinalizationRegistry,
531
- bodyUnusable
532
- }
@@ -1,131 +0,0 @@
1
- 'use strict'
2
-
3
- const corsSafeListedMethods = /** @type {const} */ (['GET', 'HEAD', 'POST'])
4
- const corsSafeListedMethodsSet = new Set(corsSafeListedMethods)
5
-
6
- const nullBodyStatus = /** @type {const} */ ([101, 204, 205, 304])
7
-
8
- const redirectStatus = /** @type {const} */ ([301, 302, 303, 307, 308])
9
- const redirectStatusSet = new Set(redirectStatus)
10
-
11
- /**
12
- * @see https://fetch.spec.whatwg.org/#block-bad-port
13
- */
14
- const badPorts = /** @type {const} */ ([
15
- '1', '7', '9', '11', '13', '15', '17', '19', '20', '21', '22', '23', '25', '37', '42', '43', '53', '69', '77', '79',
16
- '87', '95', '101', '102', '103', '104', '109', '110', '111', '113', '115', '117', '119', '123', '135', '137',
17
- '139', '143', '161', '179', '389', '427', '465', '512', '513', '514', '515', '526', '530', '531', '532',
18
- '540', '548', '554', '556', '563', '587', '601', '636', '989', '990', '993', '995', '1719', '1720', '1723',
19
- '2049', '3659', '4045', '4190', '5060', '5061', '6000', '6566', '6665', '6666', '6667', '6668', '6669', '6679',
20
- '6697', '10080'
21
- ])
22
- const badPortsSet = new Set(badPorts)
23
-
24
- /**
25
- * @see https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-header
26
- */
27
- const referrerPolicyTokens = /** @type {const} */ ([
28
- 'no-referrer',
29
- 'no-referrer-when-downgrade',
30
- 'same-origin',
31
- 'origin',
32
- 'strict-origin',
33
- 'origin-when-cross-origin',
34
- 'strict-origin-when-cross-origin',
35
- 'unsafe-url'
36
- ])
37
-
38
- /**
39
- * @see https://w3c.github.io/webappsec-referrer-policy/#referrer-policies
40
- */
41
- const referrerPolicy = /** @type {const} */ ([
42
- '',
43
- ...referrerPolicyTokens
44
- ])
45
- const referrerPolicyTokensSet = new Set(referrerPolicyTokens)
46
-
47
- const requestRedirect = /** @type {const} */ (['follow', 'manual', 'error'])
48
-
49
- const safeMethods = /** @type {const} */ (['GET', 'HEAD', 'OPTIONS', 'TRACE'])
50
- const safeMethodsSet = new Set(safeMethods)
51
-
52
- const requestMode = /** @type {const} */ (['navigate', 'same-origin', 'no-cors', 'cors'])
53
-
54
- const requestCredentials = /** @type {const} */ (['omit', 'same-origin', 'include'])
55
-
56
- const requestCache = /** @type {const} */ ([
57
- 'default',
58
- 'no-store',
59
- 'reload',
60
- 'no-cache',
61
- 'force-cache',
62
- 'only-if-cached'
63
- ])
64
-
65
- /**
66
- * @see https://fetch.spec.whatwg.org/#request-body-header-name
67
- */
68
- const requestBodyHeader = /** @type {const} */ ([
69
- 'content-encoding',
70
- 'content-language',
71
- 'content-location',
72
- 'content-type',
73
- // See https://github.com/nodejs/undici/issues/2021
74
- // 'Content-Length' is a forbidden header name, which is typically
75
- // removed in the Headers implementation. However, undici doesn't
76
- // filter out headers, so we add it here.
77
- 'content-length'
78
- ])
79
-
80
- /**
81
- * @see https://fetch.spec.whatwg.org/#enumdef-requestduplex
82
- */
83
- const requestDuplex = /** @type {const} */ ([
84
- 'half'
85
- ])
86
-
87
- /**
88
- * @see http://fetch.spec.whatwg.org/#forbidden-method
89
- */
90
- const forbiddenMethods = /** @type {const} */ (['CONNECT', 'TRACE', 'TRACK'])
91
- const forbiddenMethodsSet = new Set(forbiddenMethods)
92
-
93
- const subresource = /** @type {const} */ ([
94
- 'audio',
95
- 'audioworklet',
96
- 'font',
97
- 'image',
98
- 'manifest',
99
- 'paintworklet',
100
- 'script',
101
- 'style',
102
- 'track',
103
- 'video',
104
- 'xslt',
105
- ''
106
- ])
107
- const subresourceSet = new Set(subresource)
108
-
109
- module.exports = {
110
- subresource,
111
- forbiddenMethods,
112
- requestBodyHeader,
113
- referrerPolicy,
114
- requestRedirect,
115
- requestMode,
116
- requestCredentials,
117
- requestCache,
118
- redirectStatus,
119
- corsSafeListedMethods,
120
- nullBodyStatus,
121
- safeMethods,
122
- badPorts,
123
- requestDuplex,
124
- subresourceSet,
125
- badPortsSet,
126
- redirectStatusSet,
127
- corsSafeListedMethodsSet,
128
- safeMethodsSet,
129
- forbiddenMethodsSet,
130
- referrerPolicyTokens: referrerPolicyTokensSet
131
- }