deepv-code 1.0.182 → 1.0.185

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 +757 -753
  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,191 +0,0 @@
1
- 'use strict'
2
-
3
- const { PoolStats } = require('../util/stats.js')
4
- const DispatcherBase = require('./dispatcher-base')
5
- const FixedQueue = require('./fixed-queue')
6
- const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
7
-
8
- const kClients = Symbol('clients')
9
- const kNeedDrain = Symbol('needDrain')
10
- const kQueue = Symbol('queue')
11
- const kClosedResolve = Symbol('closed resolve')
12
- const kOnDrain = Symbol('onDrain')
13
- const kOnConnect = Symbol('onConnect')
14
- const kOnDisconnect = Symbol('onDisconnect')
15
- const kOnConnectionError = Symbol('onConnectionError')
16
- const kGetDispatcher = Symbol('get dispatcher')
17
- const kAddClient = Symbol('add client')
18
- const kRemoveClient = Symbol('remove client')
19
-
20
- class PoolBase extends DispatcherBase {
21
- constructor () {
22
- super()
23
-
24
- this[kQueue] = new FixedQueue()
25
- this[kClients] = []
26
- this[kQueued] = 0
27
-
28
- const pool = this
29
-
30
- this[kOnDrain] = function onDrain (origin, targets) {
31
- const queue = pool[kQueue]
32
-
33
- let needDrain = false
34
-
35
- while (!needDrain) {
36
- const item = queue.shift()
37
- if (!item) {
38
- break
39
- }
40
- pool[kQueued]--
41
- needDrain = !this.dispatch(item.opts, item.handler)
42
- }
43
-
44
- this[kNeedDrain] = needDrain
45
-
46
- if (!this[kNeedDrain] && pool[kNeedDrain]) {
47
- pool[kNeedDrain] = false
48
- pool.emit('drain', origin, [pool, ...targets])
49
- }
50
-
51
- if (pool[kClosedResolve] && queue.isEmpty()) {
52
- Promise
53
- .all(pool[kClients].map(c => c.close()))
54
- .then(pool[kClosedResolve])
55
- }
56
- }
57
-
58
- this[kOnConnect] = (origin, targets) => {
59
- pool.emit('connect', origin, [pool, ...targets])
60
- }
61
-
62
- this[kOnDisconnect] = (origin, targets, err) => {
63
- pool.emit('disconnect', origin, [pool, ...targets], err)
64
- }
65
-
66
- this[kOnConnectionError] = (origin, targets, err) => {
67
- pool.emit('connectionError', origin, [pool, ...targets], err)
68
- }
69
- }
70
-
71
- get [kBusy] () {
72
- return this[kNeedDrain]
73
- }
74
-
75
- get [kConnected] () {
76
- return this[kClients].filter(client => client[kConnected]).length
77
- }
78
-
79
- get [kFree] () {
80
- return this[kClients].filter(client => client[kConnected] && !client[kNeedDrain]).length
81
- }
82
-
83
- get [kPending] () {
84
- let ret = this[kQueued]
85
- for (const { [kPending]: pending } of this[kClients]) {
86
- ret += pending
87
- }
88
- return ret
89
- }
90
-
91
- get [kRunning] () {
92
- let ret = 0
93
- for (const { [kRunning]: running } of this[kClients]) {
94
- ret += running
95
- }
96
- return ret
97
- }
98
-
99
- get [kSize] () {
100
- let ret = this[kQueued]
101
- for (const { [kSize]: size } of this[kClients]) {
102
- ret += size
103
- }
104
- return ret
105
- }
106
-
107
- get stats () {
108
- return new PoolStats(this)
109
- }
110
-
111
- async [kClose] () {
112
- if (this[kQueue].isEmpty()) {
113
- await Promise.all(this[kClients].map(c => c.close()))
114
- } else {
115
- await new Promise((resolve) => {
116
- this[kClosedResolve] = resolve
117
- })
118
- }
119
- }
120
-
121
- async [kDestroy] (err) {
122
- while (true) {
123
- const item = this[kQueue].shift()
124
- if (!item) {
125
- break
126
- }
127
- item.handler.onError(err)
128
- }
129
-
130
- await Promise.all(this[kClients].map(c => c.destroy(err)))
131
- }
132
-
133
- [kDispatch] (opts, handler) {
134
- const dispatcher = this[kGetDispatcher]()
135
-
136
- if (!dispatcher) {
137
- this[kNeedDrain] = true
138
- this[kQueue].push({ opts, handler })
139
- this[kQueued]++
140
- } else if (!dispatcher.dispatch(opts, handler)) {
141
- dispatcher[kNeedDrain] = true
142
- this[kNeedDrain] = !this[kGetDispatcher]()
143
- }
144
-
145
- return !this[kNeedDrain]
146
- }
147
-
148
- [kAddClient] (client) {
149
- client
150
- .on('drain', this[kOnDrain])
151
- .on('connect', this[kOnConnect])
152
- .on('disconnect', this[kOnDisconnect])
153
- .on('connectionError', this[kOnConnectionError])
154
-
155
- this[kClients].push(client)
156
-
157
- if (this[kNeedDrain]) {
158
- queueMicrotask(() => {
159
- if (this[kNeedDrain]) {
160
- this[kOnDrain](client[kUrl], [this, client])
161
- }
162
- })
163
- }
164
-
165
- return this
166
- }
167
-
168
- [kRemoveClient] (client) {
169
- client.close(() => {
170
- const idx = this[kClients].indexOf(client)
171
- if (idx !== -1) {
172
- this[kClients].splice(idx, 1)
173
- }
174
- })
175
-
176
- this[kNeedDrain] = this[kClients].some(dispatcher => (
177
- !dispatcher[kNeedDrain] &&
178
- dispatcher.closed !== true &&
179
- dispatcher.destroyed !== true
180
- ))
181
- }
182
- }
183
-
184
- module.exports = {
185
- PoolBase,
186
- kClients,
187
- kNeedDrain,
188
- kAddClient,
189
- kRemoveClient,
190
- kGetDispatcher
191
- }
@@ -1,118 +0,0 @@
1
- 'use strict'
2
-
3
- const {
4
- PoolBase,
5
- kClients,
6
- kNeedDrain,
7
- kAddClient,
8
- kGetDispatcher,
9
- kRemoveClient
10
- } = require('./pool-base')
11
- const Client = require('./client')
12
- const {
13
- InvalidArgumentError
14
- } = require('../core/errors')
15
- const util = require('../core/util')
16
- const { kUrl } = require('../core/symbols')
17
- const buildConnector = require('../core/connect')
18
-
19
- const kOptions = Symbol('options')
20
- const kConnections = Symbol('connections')
21
- const kFactory = Symbol('factory')
22
-
23
- function defaultFactory (origin, opts) {
24
- return new Client(origin, opts)
25
- }
26
-
27
- class Pool extends PoolBase {
28
- constructor (origin, {
29
- connections,
30
- factory = defaultFactory,
31
- connect,
32
- connectTimeout,
33
- tls,
34
- maxCachedSessions,
35
- socketPath,
36
- autoSelectFamily,
37
- autoSelectFamilyAttemptTimeout,
38
- allowH2,
39
- clientTtl,
40
- ...options
41
- } = {}) {
42
- if (connections != null && (!Number.isFinite(connections) || connections < 0)) {
43
- throw new InvalidArgumentError('invalid connections')
44
- }
45
-
46
- if (typeof factory !== 'function') {
47
- throw new InvalidArgumentError('factory must be a function.')
48
- }
49
-
50
- if (connect != null && typeof connect !== 'function' && typeof connect !== 'object') {
51
- throw new InvalidArgumentError('connect must be a function or an object')
52
- }
53
-
54
- super()
55
-
56
- if (typeof connect !== 'function') {
57
- connect = buildConnector({
58
- ...tls,
59
- maxCachedSessions,
60
- allowH2,
61
- socketPath,
62
- timeout: connectTimeout,
63
- ...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
64
- ...connect
65
- })
66
- }
67
-
68
- this[kConnections] = connections || null
69
- this[kUrl] = util.parseOrigin(origin)
70
- this[kOptions] = { ...util.deepClone(options), connect, allowH2, clientTtl }
71
- this[kOptions].interceptors = options.interceptors
72
- ? { ...options.interceptors }
73
- : undefined
74
- this[kFactory] = factory
75
-
76
- this.on('connect', (origin, targets) => {
77
- if (clientTtl != null && clientTtl > 0) {
78
- for (const target of targets) {
79
- Object.assign(target, { ttl: Date.now() })
80
- }
81
- }
82
- })
83
-
84
- this.on('connectionError', (origin, targets, error) => {
85
- // If a connection error occurs, we remove the client from the pool,
86
- // and emit a connectionError event. They will not be re-used.
87
- // Fixes https://github.com/nodejs/undici/issues/3895
88
- for (const target of targets) {
89
- // Do not use kRemoveClient here, as it will close the client,
90
- // but the client cannot be closed in this state.
91
- const idx = this[kClients].indexOf(target)
92
- if (idx !== -1) {
93
- this[kClients].splice(idx, 1)
94
- }
95
- }
96
- })
97
- }
98
-
99
- [kGetDispatcher] () {
100
- const clientTtlOption = this[kOptions].clientTtl
101
- for (const client of this[kClients]) {
102
- // check ttl of client and if it's stale, remove it from the pool
103
- if (clientTtlOption != null && clientTtlOption > 0 && client.ttl && ((Date.now() - client.ttl) > clientTtlOption)) {
104
- this[kRemoveClient](client)
105
- } else if (!client[kNeedDrain]) {
106
- return client
107
- }
108
- }
109
-
110
- if (!this[kConnections] || this[kClients].length < this[kConnections]) {
111
- const dispatcher = this[kFactory](this[kUrl], this[kOptions])
112
- this[kAddClient](dispatcher)
113
- return dispatcher
114
- }
115
- }
116
- }
117
-
118
- module.exports = Pool
@@ -1,275 +0,0 @@
1
- 'use strict'
2
-
3
- const { kProxy, kClose, kDestroy, kDispatch, kConnector } = require('../core/symbols')
4
- const { URL } = require('node:url')
5
- const Agent = require('./agent')
6
- const Pool = require('./pool')
7
- const DispatcherBase = require('./dispatcher-base')
8
- const { InvalidArgumentError, RequestAbortedError, SecureProxyConnectionError } = require('../core/errors')
9
- const buildConnector = require('../core/connect')
10
- const Client = require('./client')
11
-
12
- const kAgent = Symbol('proxy agent')
13
- const kClient = Symbol('proxy client')
14
- const kProxyHeaders = Symbol('proxy headers')
15
- const kRequestTls = Symbol('request tls settings')
16
- const kProxyTls = Symbol('proxy tls settings')
17
- const kConnectEndpoint = Symbol('connect endpoint function')
18
- const kTunnelProxy = Symbol('tunnel proxy')
19
-
20
- function defaultProtocolPort (protocol) {
21
- return protocol === 'https:' ? 443 : 80
22
- }
23
-
24
- function defaultFactory (origin, opts) {
25
- return new Pool(origin, opts)
26
- }
27
-
28
- const noop = () => {}
29
-
30
- class ProxyClient extends DispatcherBase {
31
- #client = null
32
- constructor (origin, opts) {
33
- if (typeof origin === 'string') {
34
- origin = new URL(origin)
35
- }
36
-
37
- if (origin.protocol !== 'http:' && origin.protocol !== 'https:') {
38
- throw new InvalidArgumentError('ProxyClient only supports http and https protocols')
39
- }
40
-
41
- super()
42
-
43
- this.#client = new Client(origin, opts)
44
- }
45
-
46
- async [kClose] () {
47
- await this.#client.close()
48
- }
49
-
50
- async [kDestroy] () {
51
- await this.#client.destroy()
52
- }
53
-
54
- async [kDispatch] (opts, handler) {
55
- const { method, origin } = opts
56
- if (method === 'CONNECT') {
57
- this.#client[kConnector]({
58
- origin,
59
- port: opts.port || defaultProtocolPort(opts.protocol),
60
- path: opts.host,
61
- signal: opts.signal,
62
- headers: {
63
- ...this[kProxyHeaders],
64
- host: opts.host
65
- },
66
- servername: this[kProxyTls]?.servername || opts.servername
67
- },
68
- (err, socket) => {
69
- if (err) {
70
- handler.callback(err)
71
- } else {
72
- handler.callback(null, { socket, statusCode: 200 })
73
- }
74
- }
75
- )
76
- return
77
- }
78
- if (typeof origin === 'string') {
79
- opts.origin = new URL(origin)
80
- }
81
-
82
- return this.#client.dispatch(opts, handler)
83
- }
84
- }
85
- class ProxyAgent extends DispatcherBase {
86
- constructor (opts) {
87
- if (!opts || (typeof opts === 'object' && !(opts instanceof URL) && !opts.uri)) {
88
- throw new InvalidArgumentError('Proxy uri is mandatory')
89
- }
90
-
91
- const { clientFactory = defaultFactory } = opts
92
- if (typeof clientFactory !== 'function') {
93
- throw new InvalidArgumentError('Proxy opts.clientFactory must be a function.')
94
- }
95
-
96
- const { proxyTunnel = true } = opts
97
-
98
- super()
99
-
100
- const url = this.#getUrl(opts)
101
- const { href, origin, port, protocol, username, password, hostname: proxyHostname } = url
102
-
103
- this[kProxy] = { uri: href, protocol }
104
- this[kRequestTls] = opts.requestTls
105
- this[kProxyTls] = opts.proxyTls
106
- this[kProxyHeaders] = opts.headers || {}
107
-
108
- if (opts.auth && opts.token) {
109
- throw new InvalidArgumentError('opts.auth cannot be used in combination with opts.token')
110
- } else if (opts.auth) {
111
- /* @deprecated in favour of opts.token */
112
- this[kProxyHeaders]['proxy-authorization'] = `Basic ${opts.auth}`
113
- } else if (opts.token) {
114
- this[kProxyHeaders]['proxy-authorization'] = opts.token
115
- } else if (username && password) {
116
- this[kProxyHeaders]['proxy-authorization'] = `Basic ${Buffer.from(`${decodeURIComponent(username)}:${decodeURIComponent(password)}`).toString('base64')}`
117
- }
118
-
119
- const factory = (!proxyTunnel && protocol === 'http:')
120
- ? (origin, options) => {
121
- if (origin.protocol === 'http:') {
122
- return new ProxyClient(origin, options)
123
- }
124
- return new Client(origin, options)
125
- }
126
- : undefined
127
-
128
- const connect = buildConnector({ ...opts.proxyTls })
129
- this[kConnectEndpoint] = buildConnector({ ...opts.requestTls })
130
- this[kClient] = clientFactory(url, { connect, factory })
131
- this[kTunnelProxy] = proxyTunnel
132
- this[kAgent] = new Agent({
133
- ...opts,
134
- connect: async (opts, callback) => {
135
- let requestedPath = opts.host
136
- if (!opts.port) {
137
- requestedPath += `:${defaultProtocolPort(opts.protocol)}`
138
- }
139
- try {
140
- const { socket, statusCode } = await this[kClient].connect({
141
- origin,
142
- port,
143
- path: requestedPath,
144
- signal: opts.signal,
145
- headers: {
146
- ...this[kProxyHeaders],
147
- host: opts.host
148
- },
149
- servername: this[kProxyTls]?.servername || proxyHostname
150
- })
151
- if (statusCode !== 200) {
152
- socket.on('error', noop).destroy()
153
- callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`))
154
- }
155
- if (opts.protocol !== 'https:') {
156
- callback(null, socket)
157
- return
158
- }
159
- let servername
160
- if (this[kRequestTls]) {
161
- servername = this[kRequestTls].servername
162
- } else {
163
- servername = opts.servername
164
- }
165
- this[kConnectEndpoint]({ ...opts, servername, httpSocket: socket }, callback)
166
- } catch (err) {
167
- if (err.code === 'ERR_TLS_CERT_ALTNAME_INVALID') {
168
- // Throw a custom error to avoid loop in client.js#connect
169
- callback(new SecureProxyConnectionError(err))
170
- } else {
171
- callback(err)
172
- }
173
- }
174
- }
175
- })
176
- }
177
-
178
- dispatch (opts, handler) {
179
- const headers = buildHeaders(opts.headers)
180
- throwIfProxyAuthIsSent(headers)
181
-
182
- if (headers && !('host' in headers) && !('Host' in headers)) {
183
- const { host } = new URL(opts.origin)
184
- headers.host = host
185
- }
186
-
187
- if (!this.#shouldConnect(new URL(opts.origin))) {
188
- opts.path = opts.origin + opts.path
189
- }
190
-
191
- return this[kAgent].dispatch(
192
- {
193
- ...opts,
194
- headers
195
- },
196
- handler
197
- )
198
- }
199
-
200
- /**
201
- * @param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts
202
- * @returns {URL}
203
- */
204
- #getUrl (opts) {
205
- if (typeof opts === 'string') {
206
- return new URL(opts)
207
- } else if (opts instanceof URL) {
208
- return opts
209
- } else {
210
- return new URL(opts.uri)
211
- }
212
- }
213
-
214
- async [kClose] () {
215
- await this[kAgent].close()
216
- await this[kClient].close()
217
- }
218
-
219
- async [kDestroy] () {
220
- await this[kAgent].destroy()
221
- await this[kClient].destroy()
222
- }
223
-
224
- #shouldConnect (uri) {
225
- if (typeof uri === 'string') {
226
- uri = new URL(uri)
227
- }
228
- if (this[kTunnelProxy]) {
229
- return true
230
- }
231
- if (uri.protocol !== 'http:' || this[kProxy].protocol !== 'http:') {
232
- return true
233
- }
234
- return false
235
- }
236
- }
237
-
238
- /**
239
- * @param {string[] | Record<string, string>} headers
240
- * @returns {Record<string, string>}
241
- */
242
- function buildHeaders (headers) {
243
- // When using undici.fetch, the headers list is stored
244
- // as an array.
245
- if (Array.isArray(headers)) {
246
- /** @type {Record<string, string>} */
247
- const headersPair = {}
248
-
249
- for (let i = 0; i < headers.length; i += 2) {
250
- headersPair[headers[i]] = headers[i + 1]
251
- }
252
-
253
- return headersPair
254
- }
255
-
256
- return headers
257
- }
258
-
259
- /**
260
- * @param {Record<string, string>} headers
261
- *
262
- * Previous versions of ProxyAgent suggests the Proxy-Authorization in request headers
263
- * Nevertheless, it was changed and to avoid a security vulnerability by end users
264
- * this check was created.
265
- * It should be removed in the next major version for performance reasons
266
- */
267
- function throwIfProxyAuthIsSent (headers) {
268
- const existProxyAuth = headers && Object.keys(headers)
269
- .find((key) => key.toLowerCase() === 'proxy-authorization')
270
- if (existProxyAuth) {
271
- throw new InvalidArgumentError('Proxy-Authorization should be sent in ProxyAgent constructor')
272
- }
273
- }
274
-
275
- module.exports = ProxyAgent
@@ -1,35 +0,0 @@
1
- 'use strict'
2
-
3
- const Dispatcher = require('./dispatcher')
4
- const RetryHandler = require('../handler/retry-handler')
5
-
6
- class RetryAgent extends Dispatcher {
7
- #agent = null
8
- #options = null
9
- constructor (agent, options = {}) {
10
- super(options)
11
- this.#agent = agent
12
- this.#options = options
13
- }
14
-
15
- dispatch (opts, handler) {
16
- const retry = new RetryHandler({
17
- ...opts,
18
- retryOptions: this.#options
19
- }, {
20
- dispatch: this.#agent.dispatch.bind(this.#agent),
21
- handler
22
- })
23
- return this.#agent.dispatch(opts, retry)
24
- }
25
-
26
- close () {
27
- return this.#agent.close()
28
- }
29
-
30
- destroy () {
31
- return this.#agent.destroy()
32
- }
33
- }
34
-
35
- module.exports = RetryAgent
@@ -1,32 +0,0 @@
1
- 'use strict'
2
-
3
- // We include a version number for the Dispatcher API. In case of breaking changes,
4
- // this version number must be increased to avoid conflicts.
5
- const globalDispatcher = Symbol.for('undici.globalDispatcher.1')
6
- const { InvalidArgumentError } = require('./core/errors')
7
- const Agent = require('./dispatcher/agent')
8
-
9
- if (getGlobalDispatcher() === undefined) {
10
- setGlobalDispatcher(new Agent())
11
- }
12
-
13
- function setGlobalDispatcher (agent) {
14
- if (!agent || typeof agent.dispatch !== 'function') {
15
- throw new InvalidArgumentError('Argument agent must implement Agent')
16
- }
17
- Object.defineProperty(globalThis, globalDispatcher, {
18
- value: agent,
19
- writable: true,
20
- enumerable: false,
21
- configurable: false
22
- })
23
- }
24
-
25
- function getGlobalDispatcher () {
26
- return globalThis[globalDispatcher]
27
- }
28
-
29
- module.exports = {
30
- setGlobalDispatcher,
31
- getGlobalDispatcher
32
- }