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,636 @@
1
+ 'use strict'
2
+
3
+ const { Headers, HeadersList, fill, getHeadersGuard, setHeadersGuard, setHeadersList } = require('./headers')
4
+ const { extractBody, cloneBody, mixinBody, hasFinalizationRegistry, streamRegistry, bodyUnusable } = require('./body')
5
+ const util = require('../../core/util')
6
+ const nodeUtil = require('node:util')
7
+ const { kEnumerableProperty } = util
8
+ const {
9
+ isValidReasonPhrase,
10
+ isCancelled,
11
+ isAborted,
12
+ serializeJavascriptValueToJSONString,
13
+ isErrorLike,
14
+ isomorphicEncode,
15
+ environmentSettingsObject: relevantRealm
16
+ } = require('./util')
17
+ const {
18
+ redirectStatusSet,
19
+ nullBodyStatus
20
+ } = require('./constants')
21
+ const { webidl } = require('./webidl')
22
+ const { URLSerializer } = require('./data-url')
23
+ const { kConstruct } = require('../../core/symbols')
24
+ const assert = require('node:assert')
25
+ const { types } = require('node:util')
26
+
27
+ const textEncoder = new TextEncoder('utf-8')
28
+
29
+ // https://fetch.spec.whatwg.org/#response-class
30
+ class Response {
31
+ /** @type {Headers} */
32
+ #headers
33
+
34
+ #state
35
+
36
+ // Creates network error Response.
37
+ static error () {
38
+ // The static error() method steps are to return the result of creating a
39
+ // Response object, given a new network error, "immutable", and this’s
40
+ // relevant Realm.
41
+ const responseObject = fromInnerResponse(makeNetworkError(), 'immutable')
42
+
43
+ return responseObject
44
+ }
45
+
46
+ // https://fetch.spec.whatwg.org/#dom-response-json
47
+ static json (data, init = undefined) {
48
+ webidl.argumentLengthCheck(arguments, 1, 'Response.json')
49
+
50
+ if (init !== null) {
51
+ init = webidl.converters.ResponseInit(init)
52
+ }
53
+
54
+ // 1. Let bytes the result of running serialize a JavaScript value to JSON bytes on data.
55
+ const bytes = textEncoder.encode(
56
+ serializeJavascriptValueToJSONString(data)
57
+ )
58
+
59
+ // 2. Let body be the result of extracting bytes.
60
+ const body = extractBody(bytes)
61
+
62
+ // 3. Let responseObject be the result of creating a Response object, given a new response,
63
+ // "response", and this’s relevant Realm.
64
+ const responseObject = fromInnerResponse(makeResponse({}), 'response')
65
+
66
+ // 4. Perform initialize a response given responseObject, init, and (body, "application/json").
67
+ initializeResponse(responseObject, init, { body: body[0], type: 'application/json' })
68
+
69
+ // 5. Return responseObject.
70
+ return responseObject
71
+ }
72
+
73
+ // Creates a redirect Response that redirects to url with status status.
74
+ static redirect (url, status = 302) {
75
+ webidl.argumentLengthCheck(arguments, 1, 'Response.redirect')
76
+
77
+ url = webidl.converters.USVString(url)
78
+ status = webidl.converters['unsigned short'](status)
79
+
80
+ // 1. Let parsedURL be the result of parsing url with current settings
81
+ // object’s API base URL.
82
+ // 2. If parsedURL is failure, then throw a TypeError.
83
+ // TODO: base-URL?
84
+ let parsedURL
85
+ try {
86
+ parsedURL = new URL(url, relevantRealm.settingsObject.baseUrl)
87
+ } catch (err) {
88
+ throw new TypeError(`Failed to parse URL from ${url}`, { cause: err })
89
+ }
90
+
91
+ // 3. If status is not a redirect status, then throw a RangeError.
92
+ if (!redirectStatusSet.has(status)) {
93
+ throw new RangeError(`Invalid status code ${status}`)
94
+ }
95
+
96
+ // 4. Let responseObject be the result of creating a Response object,
97
+ // given a new response, "immutable", and this’s relevant Realm.
98
+ const responseObject = fromInnerResponse(makeResponse({}), 'immutable')
99
+
100
+ // 5. Set responseObject’s response’s status to status.
101
+ responseObject.#state.status = status
102
+
103
+ // 6. Let value be parsedURL, serialized and isomorphic encoded.
104
+ const value = isomorphicEncode(URLSerializer(parsedURL))
105
+
106
+ // 7. Append `Location`/value to responseObject’s response’s header list.
107
+ responseObject.#state.headersList.append('location', value, true)
108
+
109
+ // 8. Return responseObject.
110
+ return responseObject
111
+ }
112
+
113
+ // https://fetch.spec.whatwg.org/#dom-response
114
+ constructor (body = null, init = undefined) {
115
+ webidl.util.markAsUncloneable(this)
116
+
117
+ if (body === kConstruct) {
118
+ return
119
+ }
120
+
121
+ if (body !== null) {
122
+ body = webidl.converters.BodyInit(body)
123
+ }
124
+
125
+ init = webidl.converters.ResponseInit(init)
126
+
127
+ // 1. Set this’s response to a new response.
128
+ this.#state = makeResponse({})
129
+
130
+ // 2. Set this’s headers to a new Headers object with this’s relevant
131
+ // Realm, whose header list is this’s response’s header list and guard
132
+ // is "response".
133
+ this.#headers = new Headers(kConstruct)
134
+ setHeadersGuard(this.#headers, 'response')
135
+ setHeadersList(this.#headers, this.#state.headersList)
136
+
137
+ // 3. Let bodyWithType be null.
138
+ let bodyWithType = null
139
+
140
+ // 4. If body is non-null, then set bodyWithType to the result of extracting body.
141
+ if (body != null) {
142
+ const [extractedBody, type] = extractBody(body)
143
+ bodyWithType = { body: extractedBody, type }
144
+ }
145
+
146
+ // 5. Perform initialize a response given this, init, and bodyWithType.
147
+ initializeResponse(this, init, bodyWithType)
148
+ }
149
+
150
+ // Returns response’s type, e.g., "cors".
151
+ get type () {
152
+ webidl.brandCheck(this, Response)
153
+
154
+ // The type getter steps are to return this’s response’s type.
155
+ return this.#state.type
156
+ }
157
+
158
+ // Returns response’s URL, if it has one; otherwise the empty string.
159
+ get url () {
160
+ webidl.brandCheck(this, Response)
161
+
162
+ const urlList = this.#state.urlList
163
+
164
+ // The url getter steps are to return the empty string if this’s
165
+ // response’s URL is null; otherwise this’s response’s URL,
166
+ // serialized with exclude fragment set to true.
167
+ const url = urlList[urlList.length - 1] ?? null
168
+
169
+ if (url === null) {
170
+ return ''
171
+ }
172
+
173
+ return URLSerializer(url, true)
174
+ }
175
+
176
+ // Returns whether response was obtained through a redirect.
177
+ get redirected () {
178
+ webidl.brandCheck(this, Response)
179
+
180
+ // The redirected getter steps are to return true if this’s response’s URL
181
+ // list has more than one item; otherwise false.
182
+ return this.#state.urlList.length > 1
183
+ }
184
+
185
+ // Returns response’s status.
186
+ get status () {
187
+ webidl.brandCheck(this, Response)
188
+
189
+ // The status getter steps are to return this’s response’s status.
190
+ return this.#state.status
191
+ }
192
+
193
+ // Returns whether response’s status is an ok status.
194
+ get ok () {
195
+ webidl.brandCheck(this, Response)
196
+
197
+ // The ok getter steps are to return true if this’s response’s status is an
198
+ // ok status; otherwise false.
199
+ return this.#state.status >= 200 && this.#state.status <= 299
200
+ }
201
+
202
+ // Returns response’s status message.
203
+ get statusText () {
204
+ webidl.brandCheck(this, Response)
205
+
206
+ // The statusText getter steps are to return this’s response’s status
207
+ // message.
208
+ return this.#state.statusText
209
+ }
210
+
211
+ // Returns response’s headers as Headers.
212
+ get headers () {
213
+ webidl.brandCheck(this, Response)
214
+
215
+ // The headers getter steps are to return this’s headers.
216
+ return this.#headers
217
+ }
218
+
219
+ get body () {
220
+ webidl.brandCheck(this, Response)
221
+
222
+ return this.#state.body ? this.#state.body.stream : null
223
+ }
224
+
225
+ get bodyUsed () {
226
+ webidl.brandCheck(this, Response)
227
+
228
+ return !!this.#state.body && util.isDisturbed(this.#state.body.stream)
229
+ }
230
+
231
+ // Returns a clone of response.
232
+ clone () {
233
+ webidl.brandCheck(this, Response)
234
+
235
+ // 1. If this is unusable, then throw a TypeError.
236
+ if (bodyUnusable(this.#state)) {
237
+ throw webidl.errors.exception({
238
+ header: 'Response.clone',
239
+ message: 'Body has already been consumed.'
240
+ })
241
+ }
242
+
243
+ // 2. Let clonedResponse be the result of cloning this’s response.
244
+ const clonedResponse = cloneResponse(this.#state)
245
+
246
+ // 3. Return the result of creating a Response object, given
247
+ // clonedResponse, this’s headers’s guard, and this’s relevant Realm.
248
+ return fromInnerResponse(clonedResponse, getHeadersGuard(this.#headers))
249
+ }
250
+
251
+ [nodeUtil.inspect.custom] (depth, options) {
252
+ if (options.depth === null) {
253
+ options.depth = 2
254
+ }
255
+
256
+ options.colors ??= true
257
+
258
+ const properties = {
259
+ status: this.status,
260
+ statusText: this.statusText,
261
+ headers: this.headers,
262
+ body: this.body,
263
+ bodyUsed: this.bodyUsed,
264
+ ok: this.ok,
265
+ redirected: this.redirected,
266
+ type: this.type,
267
+ url: this.url
268
+ }
269
+
270
+ return `Response ${nodeUtil.formatWithOptions(options, properties)}`
271
+ }
272
+
273
+ /**
274
+ * @param {Response} response
275
+ */
276
+ static getResponseHeaders (response) {
277
+ return response.#headers
278
+ }
279
+
280
+ /**
281
+ * @param {Response} response
282
+ * @param {Headers} newHeaders
283
+ */
284
+ static setResponseHeaders (response, newHeaders) {
285
+ response.#headers = newHeaders
286
+ }
287
+
288
+ /**
289
+ * @param {Response} response
290
+ */
291
+ static getResponseState (response) {
292
+ return response.#state
293
+ }
294
+
295
+ /**
296
+ * @param {Response} response
297
+ * @param {any} newState
298
+ */
299
+ static setResponseState (response, newState) {
300
+ response.#state = newState
301
+ }
302
+ }
303
+
304
+ const { getResponseHeaders, setResponseHeaders, getResponseState, setResponseState } = Response
305
+ Reflect.deleteProperty(Response, 'getResponseHeaders')
306
+ Reflect.deleteProperty(Response, 'setResponseHeaders')
307
+ Reflect.deleteProperty(Response, 'getResponseState')
308
+ Reflect.deleteProperty(Response, 'setResponseState')
309
+
310
+ mixinBody(Response, getResponseState)
311
+
312
+ Object.defineProperties(Response.prototype, {
313
+ type: kEnumerableProperty,
314
+ url: kEnumerableProperty,
315
+ status: kEnumerableProperty,
316
+ ok: kEnumerableProperty,
317
+ redirected: kEnumerableProperty,
318
+ statusText: kEnumerableProperty,
319
+ headers: kEnumerableProperty,
320
+ clone: kEnumerableProperty,
321
+ body: kEnumerableProperty,
322
+ bodyUsed: kEnumerableProperty,
323
+ [Symbol.toStringTag]: {
324
+ value: 'Response',
325
+ configurable: true
326
+ }
327
+ })
328
+
329
+ Object.defineProperties(Response, {
330
+ json: kEnumerableProperty,
331
+ redirect: kEnumerableProperty,
332
+ error: kEnumerableProperty
333
+ })
334
+
335
+ // https://fetch.spec.whatwg.org/#concept-response-clone
336
+ function cloneResponse (response) {
337
+ // To clone a response response, run these steps:
338
+
339
+ // 1. If response is a filtered response, then return a new identical
340
+ // filtered response whose internal response is a clone of response’s
341
+ // internal response.
342
+ if (response.internalResponse) {
343
+ return filterResponse(
344
+ cloneResponse(response.internalResponse),
345
+ response.type
346
+ )
347
+ }
348
+
349
+ // 2. Let newResponse be a copy of response, except for its body.
350
+ const newResponse = makeResponse({ ...response, body: null })
351
+
352
+ // 3. If response’s body is non-null, then set newResponse’s body to the
353
+ // result of cloning response’s body.
354
+ if (response.body != null) {
355
+ newResponse.body = cloneBody(newResponse, response.body)
356
+ }
357
+
358
+ // 4. Return newResponse.
359
+ return newResponse
360
+ }
361
+
362
+ function makeResponse (init) {
363
+ return {
364
+ aborted: false,
365
+ rangeRequested: false,
366
+ timingAllowPassed: false,
367
+ requestIncludesCredentials: false,
368
+ type: 'default',
369
+ status: 200,
370
+ timingInfo: null,
371
+ cacheState: '',
372
+ statusText: '',
373
+ ...init,
374
+ headersList: init?.headersList
375
+ ? new HeadersList(init?.headersList)
376
+ : new HeadersList(),
377
+ urlList: init?.urlList ? [...init.urlList] : []
378
+ }
379
+ }
380
+
381
+ function makeNetworkError (reason) {
382
+ const isError = isErrorLike(reason)
383
+ return makeResponse({
384
+ type: 'error',
385
+ status: 0,
386
+ error: isError
387
+ ? reason
388
+ : new Error(reason ? String(reason) : reason),
389
+ aborted: reason && reason.name === 'AbortError'
390
+ })
391
+ }
392
+
393
+ // @see https://fetch.spec.whatwg.org/#concept-network-error
394
+ function isNetworkError (response) {
395
+ return (
396
+ // A network error is a response whose type is "error",
397
+ response.type === 'error' &&
398
+ // status is 0
399
+ response.status === 0
400
+ )
401
+ }
402
+
403
+ function makeFilteredResponse (response, state) {
404
+ state = {
405
+ internalResponse: response,
406
+ ...state
407
+ }
408
+
409
+ return new Proxy(response, {
410
+ get (target, p) {
411
+ return p in state ? state[p] : target[p]
412
+ },
413
+ set (target, p, value) {
414
+ assert(!(p in state))
415
+ target[p] = value
416
+ return true
417
+ }
418
+ })
419
+ }
420
+
421
+ // https://fetch.spec.whatwg.org/#concept-filtered-response
422
+ function filterResponse (response, type) {
423
+ // Set response to the following filtered response with response as its
424
+ // internal response, depending on request’s response tainting:
425
+ if (type === 'basic') {
426
+ // A basic filtered response is a filtered response whose type is "basic"
427
+ // and header list excludes any headers in internal response’s header list
428
+ // whose name is a forbidden response-header name.
429
+
430
+ // Note: undici does not implement forbidden response-header names
431
+ return makeFilteredResponse(response, {
432
+ type: 'basic',
433
+ headersList: response.headersList
434
+ })
435
+ } else if (type === 'cors') {
436
+ // A CORS filtered response is a filtered response whose type is "cors"
437
+ // and header list excludes any headers in internal response’s header
438
+ // list whose name is not a CORS-safelisted response-header name, given
439
+ // internal response’s CORS-exposed header-name list.
440
+
441
+ // Note: undici does not implement CORS-safelisted response-header names
442
+ return makeFilteredResponse(response, {
443
+ type: 'cors',
444
+ headersList: response.headersList
445
+ })
446
+ } else if (type === 'opaque') {
447
+ // An opaque filtered response is a filtered response whose type is
448
+ // "opaque", URL list is the empty list, status is 0, status message
449
+ // is the empty byte sequence, header list is empty, and body is null.
450
+
451
+ return makeFilteredResponse(response, {
452
+ type: 'opaque',
453
+ urlList: Object.freeze([]),
454
+ status: 0,
455
+ statusText: '',
456
+ body: null
457
+ })
458
+ } else if (type === 'opaqueredirect') {
459
+ // An opaque-redirect filtered response is a filtered response whose type
460
+ // is "opaqueredirect", status is 0, status message is the empty byte
461
+ // sequence, header list is empty, and body is null.
462
+
463
+ return makeFilteredResponse(response, {
464
+ type: 'opaqueredirect',
465
+ status: 0,
466
+ statusText: '',
467
+ headersList: [],
468
+ body: null
469
+ })
470
+ } else {
471
+ assert(false)
472
+ }
473
+ }
474
+
475
+ // https://fetch.spec.whatwg.org/#appropriate-network-error
476
+ function makeAppropriateNetworkError (fetchParams, err = null) {
477
+ // 1. Assert: fetchParams is canceled.
478
+ assert(isCancelled(fetchParams))
479
+
480
+ // 2. Return an aborted network error if fetchParams is aborted;
481
+ // otherwise return a network error.
482
+ return isAborted(fetchParams)
483
+ ? makeNetworkError(Object.assign(new DOMException('The operation was aborted.', 'AbortError'), { cause: err }))
484
+ : makeNetworkError(Object.assign(new DOMException('Request was cancelled.'), { cause: err }))
485
+ }
486
+
487
+ // https://whatpr.org/fetch/1392.html#initialize-a-response
488
+ function initializeResponse (response, init, body) {
489
+ // 1. If init["status"] is not in the range 200 to 599, inclusive, then
490
+ // throw a RangeError.
491
+ if (init.status !== null && (init.status < 200 || init.status > 599)) {
492
+ throw new RangeError('init["status"] must be in the range of 200 to 599, inclusive.')
493
+ }
494
+
495
+ // 2. If init["statusText"] does not match the reason-phrase token production,
496
+ // then throw a TypeError.
497
+ if ('statusText' in init && init.statusText != null) {
498
+ // See, https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2:
499
+ // reason-phrase = *( HTAB / SP / VCHAR / obs-text )
500
+ if (!isValidReasonPhrase(String(init.statusText))) {
501
+ throw new TypeError('Invalid statusText')
502
+ }
503
+ }
504
+
505
+ // 3. Set response’s response’s status to init["status"].
506
+ if ('status' in init && init.status != null) {
507
+ getResponseState(response).status = init.status
508
+ }
509
+
510
+ // 4. Set response’s response’s status message to init["statusText"].
511
+ if ('statusText' in init && init.statusText != null) {
512
+ getResponseState(response).statusText = init.statusText
513
+ }
514
+
515
+ // 5. If init["headers"] exists, then fill response’s headers with init["headers"].
516
+ if ('headers' in init && init.headers != null) {
517
+ fill(getResponseHeaders(response), init.headers)
518
+ }
519
+
520
+ // 6. If body was given, then:
521
+ if (body) {
522
+ // 1. If response's status is a null body status, then throw a TypeError.
523
+ if (nullBodyStatus.includes(response.status)) {
524
+ throw webidl.errors.exception({
525
+ header: 'Response constructor',
526
+ message: `Invalid response status code ${response.status}`
527
+ })
528
+ }
529
+
530
+ // 2. Set response's body to body's body.
531
+ getResponseState(response).body = body.body
532
+
533
+ // 3. If body's type is non-null and response's header list does not contain
534
+ // `Content-Type`, then append (`Content-Type`, body's type) to response's header list.
535
+ if (body.type != null && !getResponseState(response).headersList.contains('content-type', true)) {
536
+ getResponseState(response).headersList.append('content-type', body.type, true)
537
+ }
538
+ }
539
+ }
540
+
541
+ /**
542
+ * @see https://fetch.spec.whatwg.org/#response-create
543
+ * @param {any} innerResponse
544
+ * @param {'request' | 'immutable' | 'request-no-cors' | 'response' | 'none'} guard
545
+ * @returns {Response}
546
+ */
547
+ function fromInnerResponse (innerResponse, guard) {
548
+ const response = new Response(kConstruct)
549
+ setResponseState(response, innerResponse)
550
+ const headers = new Headers(kConstruct)
551
+ setResponseHeaders(response, headers)
552
+ setHeadersList(headers, innerResponse.headersList)
553
+ setHeadersGuard(headers, guard)
554
+
555
+ if (hasFinalizationRegistry && innerResponse.body?.stream) {
556
+ // If the target (response) is reclaimed, the cleanup callback may be called at some point with
557
+ // the held value provided for it (innerResponse.body.stream). The held value can be any value:
558
+ // a primitive or an object, even undefined. If the held value is an object, the registry keeps
559
+ // a strong reference to it (so it can pass it to the cleanup callback later). Reworded from
560
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
561
+ streamRegistry.register(response, new WeakRef(innerResponse.body.stream))
562
+ }
563
+
564
+ return response
565
+ }
566
+
567
+ // https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
568
+ webidl.converters.XMLHttpRequestBodyInit = function (V, prefix, name) {
569
+ if (typeof V === 'string') {
570
+ return webidl.converters.USVString(V, prefix, name)
571
+ }
572
+
573
+ if (webidl.is.Blob(V)) {
574
+ return V
575
+ }
576
+
577
+ if (ArrayBuffer.isView(V) || types.isArrayBuffer(V)) {
578
+ return V
579
+ }
580
+
581
+ if (webidl.is.FormData(V)) {
582
+ return V
583
+ }
584
+
585
+ if (webidl.is.URLSearchParams(V)) {
586
+ return V
587
+ }
588
+
589
+ return webidl.converters.DOMString(V, prefix, name)
590
+ }
591
+
592
+ // https://fetch.spec.whatwg.org/#bodyinit
593
+ webidl.converters.BodyInit = function (V, prefix, argument) {
594
+ if (webidl.is.ReadableStream(V)) {
595
+ return V
596
+ }
597
+
598
+ // Note: the spec doesn't include async iterables,
599
+ // this is an undici extension.
600
+ if (V?.[Symbol.asyncIterator]) {
601
+ return V
602
+ }
603
+
604
+ return webidl.converters.XMLHttpRequestBodyInit(V, prefix, argument)
605
+ }
606
+
607
+ webidl.converters.ResponseInit = webidl.dictionaryConverter([
608
+ {
609
+ key: 'status',
610
+ converter: webidl.converters['unsigned short'],
611
+ defaultValue: () => 200
612
+ },
613
+ {
614
+ key: 'statusText',
615
+ converter: webidl.converters.ByteString,
616
+ defaultValue: () => ''
617
+ },
618
+ {
619
+ key: 'headers',
620
+ converter: webidl.converters.HeadersInit
621
+ }
622
+ ])
623
+
624
+ webidl.is.Response = webidl.util.MakeTypeAssertion(Response)
625
+
626
+ module.exports = {
627
+ isNetworkError,
628
+ makeNetworkError,
629
+ makeResponse,
630
+ makeAppropriateNetworkError,
631
+ filterResponse,
632
+ Response,
633
+ cloneResponse,
634
+ fromInnerResponse,
635
+ getResponseState
636
+ }