deepv-code 1.0.182

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 (223) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +3 -0
  3. package/bundle/assets/help/README.md +113 -0
  4. package/bundle/assets/help/cli-help-knowledge.md +1382 -0
  5. package/bundle/assets/sounds/README.md +74 -0
  6. package/bundle/assets/sounds/confirmation-required.wav +0 -0
  7. package/bundle/assets/sounds/response-complete.wav +0 -0
  8. package/bundle/assets/sounds/selection-made.wav +0 -0
  9. package/bundle/dvcode.js +4442 -0
  10. package/bundle/fix-binary-permissions.js +215 -0
  11. package/bundle/login/templates/authSelectPage.html +870 -0
  12. package/bundle/login/templates/deepv.ico +0 -0
  13. package/bundle/login/templates/feishu.ico +0 -0
  14. package/bundle/node_modules/@vscode/ripgrep/bin/darwin-arm64-rg +0 -0
  15. package/bundle/node_modules/@vscode/ripgrep/bin/darwin-x64-rg +0 -0
  16. package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm-rg +0 -0
  17. package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm64-rg +0 -0
  18. package/bundle/node_modules/@vscode/ripgrep/bin/linux-x64-rg +0 -0
  19. package/bundle/node_modules/@vscode/ripgrep/bin/rg.exe +0 -0
  20. package/bundle/node_modules/@vscode/ripgrep/bin/win32-arm64-rg.exe +0 -0
  21. package/bundle/node_modules/@vscode/ripgrep/bin/win32-ia32-rg.exe +0 -0
  22. package/bundle/node_modules/@vscode/ripgrep/bin/win32-x64-rg.exe +0 -0
  23. package/bundle/node_modules/@vscode/ripgrep/lib/download.js +357 -0
  24. package/bundle/node_modules/@vscode/ripgrep/lib/index.d.ts +1 -0
  25. package/bundle/node_modules/@vscode/ripgrep/lib/index.js +42 -0
  26. package/bundle/node_modules/@vscode/ripgrep/lib/postinstall.js +121 -0
  27. package/bundle/node_modules/@vscode/ripgrep/package.json +24 -0
  28. package/bundle/node_modules/undici/LICENSE +21 -0
  29. package/bundle/node_modules/undici/README.md +472 -0
  30. package/bundle/node_modules/undici/docs/docs/api/Agent.md +83 -0
  31. package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
  32. package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
  33. package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +151 -0
  34. package/bundle/node_modules/undici/docs/docs/api/Client.md +281 -0
  35. package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
  36. package/bundle/node_modules/undici/docs/docs/api/Connector.md +115 -0
  37. package/bundle/node_modules/undici/docs/docs/api/ContentType.md +57 -0
  38. package/bundle/node_modules/undici/docs/docs/api/Cookies.md +101 -0
  39. package/bundle/node_modules/undici/docs/docs/api/Debug.md +62 -0
  40. package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +204 -0
  41. package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +1200 -0
  42. package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
  43. package/bundle/node_modules/undici/docs/docs/api/Errors.md +49 -0
  44. package/bundle/node_modules/undici/docs/docs/api/EventSource.md +45 -0
  45. package/bundle/node_modules/undici/docs/docs/api/Fetch.md +52 -0
  46. package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +262 -0
  47. package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
  48. package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
  49. package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
  50. package/bundle/node_modules/undici/docs/docs/api/MockClient.md +77 -0
  51. package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
  52. package/bundle/node_modules/undici/docs/docs/api/MockPool.md +548 -0
  53. package/bundle/node_modules/undici/docs/docs/api/Pool.md +84 -0
  54. package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
  55. package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +227 -0
  56. package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +96 -0
  57. package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +45 -0
  58. package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +117 -0
  59. package/bundle/node_modules/undici/docs/docs/api/Util.md +25 -0
  60. package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +85 -0
  61. package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
  62. package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
  63. package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
  64. package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
  65. package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +20 -0
  66. package/bundle/node_modules/undici/index-fetch.js +35 -0
  67. package/bundle/node_modules/undici/index.d.ts +3 -0
  68. package/bundle/node_modules/undici/index.js +183 -0
  69. package/bundle/node_modules/undici/lib/api/abort-signal.js +59 -0
  70. package/bundle/node_modules/undici/lib/api/api-connect.js +110 -0
  71. package/bundle/node_modules/undici/lib/api/api-pipeline.js +252 -0
  72. package/bundle/node_modules/undici/lib/api/api-request.js +199 -0
  73. package/bundle/node_modules/undici/lib/api/api-stream.js +209 -0
  74. package/bundle/node_modules/undici/lib/api/api-upgrade.js +110 -0
  75. package/bundle/node_modules/undici/lib/api/index.js +7 -0
  76. package/bundle/node_modules/undici/lib/api/readable.js +558 -0
  77. package/bundle/node_modules/undici/lib/api/util.js +95 -0
  78. package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
  79. package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +461 -0
  80. package/bundle/node_modules/undici/lib/core/connect.js +164 -0
  81. package/bundle/node_modules/undici/lib/core/constants.js +143 -0
  82. package/bundle/node_modules/undici/lib/core/diagnostics.js +196 -0
  83. package/bundle/node_modules/undici/lib/core/errors.js +244 -0
  84. package/bundle/node_modules/undici/lib/core/request.js +397 -0
  85. package/bundle/node_modules/undici/lib/core/symbols.js +68 -0
  86. package/bundle/node_modules/undici/lib/core/tree.js +160 -0
  87. package/bundle/node_modules/undici/lib/core/util.js +988 -0
  88. package/bundle/node_modules/undici/lib/dispatcher/agent.js +135 -0
  89. package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +206 -0
  90. package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +1615 -0
  91. package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +798 -0
  92. package/bundle/node_modules/undici/lib/dispatcher/client.js +614 -0
  93. package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +161 -0
  94. package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
  95. package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +151 -0
  96. package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +159 -0
  97. package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +122 -0
  98. package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +191 -0
  99. package/bundle/node_modules/undici/lib/dispatcher/pool.js +118 -0
  100. package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +275 -0
  101. package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  102. package/bundle/node_modules/undici/lib/global.js +32 -0
  103. package/bundle/node_modules/undici/lib/handler/cache-handler.js +448 -0
  104. package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
  105. package/bundle/node_modules/undici/lib/handler/decorator-handler.js +67 -0
  106. package/bundle/node_modules/undici/lib/handler/redirect-handler.js +227 -0
  107. package/bundle/node_modules/undici/lib/handler/retry-handler.js +342 -0
  108. package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +96 -0
  109. package/bundle/node_modules/undici/lib/handler/wrap-handler.js +95 -0
  110. package/bundle/node_modules/undici/lib/interceptor/cache.js +372 -0
  111. package/bundle/node_modules/undici/lib/interceptor/dns.js +432 -0
  112. package/bundle/node_modules/undici/lib/interceptor/dump.js +111 -0
  113. package/bundle/node_modules/undici/lib/interceptor/redirect.js +21 -0
  114. package/bundle/node_modules/undici/lib/interceptor/response-error.js +95 -0
  115. package/bundle/node_modules/undici/lib/interceptor/retry.js +19 -0
  116. package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  117. package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +97 -0
  118. package/bundle/node_modules/undici/lib/llhttp/constants.js +498 -0
  119. package/bundle/node_modules/undici/lib/llhttp/constants.js.map +1 -0
  120. package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
  121. package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
  122. package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
  123. package/bundle/node_modules/undici/lib/llhttp/utils.js +15 -0
  124. package/bundle/node_modules/undici/lib/llhttp/utils.js.map +1 -0
  125. package/bundle/node_modules/undici/lib/mock/mock-agent.js +224 -0
  126. package/bundle/node_modules/undici/lib/mock/mock-call-history.js +248 -0
  127. package/bundle/node_modules/undici/lib/mock/mock-client.js +64 -0
  128. package/bundle/node_modules/undici/lib/mock/mock-errors.js +19 -0
  129. package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
  130. package/bundle/node_modules/undici/lib/mock/mock-pool.js +64 -0
  131. package/bundle/node_modules/undici/lib/mock/mock-symbols.js +31 -0
  132. package/bundle/node_modules/undici/lib/mock/mock-utils.js +433 -0
  133. package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  134. package/bundle/node_modules/undici/lib/util/cache.js +368 -0
  135. package/bundle/node_modules/undici/lib/util/date.js +259 -0
  136. package/bundle/node_modules/undici/lib/util/stats.js +32 -0
  137. package/bundle/node_modules/undici/lib/util/timers.js +423 -0
  138. package/bundle/node_modules/undici/lib/web/cache/cache.js +862 -0
  139. package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  140. package/bundle/node_modules/undici/lib/web/cache/util.js +45 -0
  141. package/bundle/node_modules/undici/lib/web/cookies/constants.js +12 -0
  142. package/bundle/node_modules/undici/lib/web/cookies/index.js +199 -0
  143. package/bundle/node_modules/undici/lib/web/cookies/parse.js +322 -0
  144. package/bundle/node_modules/undici/lib/web/cookies/util.js +282 -0
  145. package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +399 -0
  146. package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +484 -0
  147. package/bundle/node_modules/undici/lib/web/eventsource/util.js +37 -0
  148. package/bundle/node_modules/undici/lib/web/fetch/LICENSE +21 -0
  149. package/bundle/node_modules/undici/lib/web/fetch/body.js +532 -0
  150. package/bundle/node_modules/undici/lib/web/fetch/constants.js +131 -0
  151. package/bundle/node_modules/undici/lib/web/fetch/data-url.js +744 -0
  152. package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
  153. package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +501 -0
  154. package/bundle/node_modules/undici/lib/web/fetch/formdata.js +263 -0
  155. package/bundle/node_modules/undici/lib/web/fetch/global.js +40 -0
  156. package/bundle/node_modules/undici/lib/web/fetch/headers.js +719 -0
  157. package/bundle/node_modules/undici/lib/web/fetch/index.js +2258 -0
  158. package/bundle/node_modules/undici/lib/web/fetch/request.js +1099 -0
  159. package/bundle/node_modules/undici/lib/web/fetch/response.js +636 -0
  160. package/bundle/node_modules/undici/lib/web/fetch/util.js +1782 -0
  161. package/bundle/node_modules/undici/lib/web/fetch/webidl.js +740 -0
  162. package/bundle/node_modules/undici/lib/web/websocket/connection.js +325 -0
  163. package/bundle/node_modules/undici/lib/web/websocket/constants.js +126 -0
  164. package/bundle/node_modules/undici/lib/web/websocket/events.js +331 -0
  165. package/bundle/node_modules/undici/lib/web/websocket/frame.js +138 -0
  166. package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +70 -0
  167. package/bundle/node_modules/undici/lib/web/websocket/receiver.js +454 -0
  168. package/bundle/node_modules/undici/lib/web/websocket/sender.js +109 -0
  169. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +83 -0
  170. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +485 -0
  171. package/bundle/node_modules/undici/lib/web/websocket/util.js +338 -0
  172. package/bundle/node_modules/undici/lib/web/websocket/websocket.js +686 -0
  173. package/bundle/node_modules/undici/package.json +149 -0
  174. package/bundle/node_modules/undici/scripts/strip-comments.js +10 -0
  175. package/bundle/node_modules/undici/types/README.md +6 -0
  176. package/bundle/node_modules/undici/types/agent.d.ts +35 -0
  177. package/bundle/node_modules/undici/types/api.d.ts +43 -0
  178. package/bundle/node_modules/undici/types/balanced-pool.d.ts +29 -0
  179. package/bundle/node_modules/undici/types/cache-interceptor.d.ts +172 -0
  180. package/bundle/node_modules/undici/types/cache.d.ts +36 -0
  181. package/bundle/node_modules/undici/types/client-stats.d.ts +15 -0
  182. package/bundle/node_modules/undici/types/client.d.ts +110 -0
  183. package/bundle/node_modules/undici/types/connector.d.ts +34 -0
  184. package/bundle/node_modules/undici/types/content-type.d.ts +21 -0
  185. package/bundle/node_modules/undici/types/cookies.d.ts +30 -0
  186. package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +66 -0
  187. package/bundle/node_modules/undici/types/dispatcher.d.ts +281 -0
  188. package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +21 -0
  189. package/bundle/node_modules/undici/types/errors.d.ts +171 -0
  190. package/bundle/node_modules/undici/types/eventsource.d.ts +61 -0
  191. package/bundle/node_modules/undici/types/fetch.d.ts +210 -0
  192. package/bundle/node_modules/undici/types/formdata.d.ts +108 -0
  193. package/bundle/node_modules/undici/types/global-dispatcher.d.ts +9 -0
  194. package/bundle/node_modules/undici/types/global-origin.d.ts +7 -0
  195. package/bundle/node_modules/undici/types/h2c-client.d.ts +75 -0
  196. package/bundle/node_modules/undici/types/handlers.d.ts +15 -0
  197. package/bundle/node_modules/undici/types/header.d.ts +160 -0
  198. package/bundle/node_modules/undici/types/index.d.ts +75 -0
  199. package/bundle/node_modules/undici/types/interceptors.d.ts +34 -0
  200. package/bundle/node_modules/undici/types/mock-agent.d.ts +68 -0
  201. package/bundle/node_modules/undici/types/mock-call-history.d.ts +111 -0
  202. package/bundle/node_modules/undici/types/mock-client.d.ts +25 -0
  203. package/bundle/node_modules/undici/types/mock-errors.d.ts +12 -0
  204. package/bundle/node_modules/undici/types/mock-interceptor.d.ts +93 -0
  205. package/bundle/node_modules/undici/types/mock-pool.d.ts +25 -0
  206. package/bundle/node_modules/undici/types/patch.d.ts +29 -0
  207. package/bundle/node_modules/undici/types/pool-stats.d.ts +19 -0
  208. package/bundle/node_modules/undici/types/pool.d.ts +41 -0
  209. package/bundle/node_modules/undici/types/proxy-agent.d.ts +29 -0
  210. package/bundle/node_modules/undici/types/readable.d.ts +68 -0
  211. package/bundle/node_modules/undici/types/retry-agent.d.ts +8 -0
  212. package/bundle/node_modules/undici/types/retry-handler.d.ts +116 -0
  213. package/bundle/node_modules/undici/types/util.d.ts +18 -0
  214. package/bundle/node_modules/undici/types/utility.d.ts +7 -0
  215. package/bundle/node_modules/undici/types/webidl.d.ts +266 -0
  216. package/bundle/node_modules/undici/types/websocket.d.ts +184 -0
  217. package/bundle/sandbox-macos-permissive-closed.sb +26 -0
  218. package/bundle/sandbox-macos-permissive-open.sb +19 -0
  219. package/bundle/sandbox-macos-permissive-proxied.sb +31 -0
  220. package/bundle/sandbox-macos-restrictive-closed.sb +87 -0
  221. package/bundle/sandbox-macos-restrictive-open.sb +90 -0
  222. package/bundle/sandbox-macos-restrictive-proxied.sb +92 -0
  223. package/package.json +137 -0
@@ -0,0 +1,532 @@
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
+ }
@@ -0,0 +1,131 @@
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
+ }