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,368 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ safeHTTPMethods
5
+ } = require('../core/util')
6
+
7
+ /**
8
+ * @param {import('../../types/dispatcher.d.ts').default.DispatchOptions} opts
9
+ */
10
+ function makeCacheKey (opts) {
11
+ if (!opts.origin) {
12
+ throw new Error('opts.origin is undefined')
13
+ }
14
+
15
+ return {
16
+ origin: opts.origin.toString(),
17
+ method: opts.method,
18
+ path: opts.path,
19
+ headers: opts.headers
20
+ }
21
+ }
22
+
23
+ /**
24
+ * @param {Record<string, string[] | string>}
25
+ * @return {Record<string, string[] | string>}
26
+ */
27
+ function normaliseHeaders (opts) {
28
+ let headers
29
+ if (opts.headers == null) {
30
+ headers = {}
31
+ } else if (typeof opts.headers[Symbol.iterator] === 'function') {
32
+ headers = {}
33
+ for (const x of opts.headers) {
34
+ if (!Array.isArray(x)) {
35
+ throw new Error('opts.headers is not a valid header map')
36
+ }
37
+ const [key, val] = x
38
+ if (typeof key !== 'string' || typeof val !== 'string') {
39
+ throw new Error('opts.headers is not a valid header map')
40
+ }
41
+ headers[key.toLowerCase()] = val
42
+ }
43
+ } else if (typeof opts.headers === 'object') {
44
+ headers = {}
45
+
46
+ for (const key of Object.keys(opts.headers)) {
47
+ headers[key.toLowerCase()] = opts.headers[key]
48
+ }
49
+ } else {
50
+ throw new Error('opts.headers is not an object')
51
+ }
52
+
53
+ return headers
54
+ }
55
+
56
+ /**
57
+ * @param {any} key
58
+ */
59
+ function assertCacheKey (key) {
60
+ if (typeof key !== 'object') {
61
+ throw new TypeError(`expected key to be object, got ${typeof key}`)
62
+ }
63
+
64
+ for (const property of ['origin', 'method', 'path']) {
65
+ if (typeof key[property] !== 'string') {
66
+ throw new TypeError(`expected key.${property} to be string, got ${typeof key[property]}`)
67
+ }
68
+ }
69
+
70
+ if (key.headers !== undefined && typeof key.headers !== 'object') {
71
+ throw new TypeError(`expected headers to be object, got ${typeof key}`)
72
+ }
73
+ }
74
+
75
+ /**
76
+ * @param {any} value
77
+ */
78
+ function assertCacheValue (value) {
79
+ if (typeof value !== 'object') {
80
+ throw new TypeError(`expected value to be object, got ${typeof value}`)
81
+ }
82
+
83
+ for (const property of ['statusCode', 'cachedAt', 'staleAt', 'deleteAt']) {
84
+ if (typeof value[property] !== 'number') {
85
+ throw new TypeError(`expected value.${property} to be number, got ${typeof value[property]}`)
86
+ }
87
+ }
88
+
89
+ if (typeof value.statusMessage !== 'string') {
90
+ throw new TypeError(`expected value.statusMessage to be string, got ${typeof value.statusMessage}`)
91
+ }
92
+
93
+ if (value.headers != null && typeof value.headers !== 'object') {
94
+ throw new TypeError(`expected value.rawHeaders to be object, got ${typeof value.headers}`)
95
+ }
96
+
97
+ if (value.vary !== undefined && typeof value.vary !== 'object') {
98
+ throw new TypeError(`expected value.vary to be object, got ${typeof value.vary}`)
99
+ }
100
+
101
+ if (value.etag !== undefined && typeof value.etag !== 'string') {
102
+ throw new TypeError(`expected value.etag to be string, got ${typeof value.etag}`)
103
+ }
104
+ }
105
+
106
+ /**
107
+ * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-cache-control
108
+ * @see https://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml
109
+
110
+ * @param {string | string[]} header
111
+ * @returns {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives}
112
+ */
113
+ function parseCacheControlHeader (header) {
114
+ /**
115
+ * @type {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives}
116
+ */
117
+ const output = {}
118
+
119
+ let directives
120
+ if (Array.isArray(header)) {
121
+ directives = []
122
+
123
+ for (const directive of header) {
124
+ directives.push(...directive.split(','))
125
+ }
126
+ } else {
127
+ directives = header.split(',')
128
+ }
129
+
130
+ for (let i = 0; i < directives.length; i++) {
131
+ const directive = directives[i].toLowerCase()
132
+ const keyValueDelimiter = directive.indexOf('=')
133
+
134
+ let key
135
+ let value
136
+ if (keyValueDelimiter !== -1) {
137
+ key = directive.substring(0, keyValueDelimiter).trimStart()
138
+ value = directive.substring(keyValueDelimiter + 1)
139
+ } else {
140
+ key = directive.trim()
141
+ }
142
+
143
+ switch (key) {
144
+ case 'min-fresh':
145
+ case 'max-stale':
146
+ case 'max-age':
147
+ case 's-maxage':
148
+ case 'stale-while-revalidate':
149
+ case 'stale-if-error': {
150
+ if (value === undefined || value[0] === ' ') {
151
+ continue
152
+ }
153
+
154
+ if (
155
+ value.length >= 2 &&
156
+ value[0] === '"' &&
157
+ value[value.length - 1] === '"'
158
+ ) {
159
+ value = value.substring(1, value.length - 1)
160
+ }
161
+
162
+ const parsedValue = parseInt(value, 10)
163
+ // eslint-disable-next-line no-self-compare
164
+ if (parsedValue !== parsedValue) {
165
+ continue
166
+ }
167
+
168
+ if (key === 'max-age' && key in output && output[key] >= parsedValue) {
169
+ continue
170
+ }
171
+
172
+ output[key] = parsedValue
173
+
174
+ break
175
+ }
176
+ case 'private':
177
+ case 'no-cache': {
178
+ if (value) {
179
+ // The private and no-cache directives can be unqualified (aka just
180
+ // `private` or `no-cache`) or qualified (w/ a value). When they're
181
+ // qualified, it's a list of headers like `no-cache=header1`,
182
+ // `no-cache="header1"`, or `no-cache="header1, header2"`
183
+ // If we're given multiple headers, the comma messes us up since
184
+ // we split the full header by commas. So, let's loop through the
185
+ // remaining parts in front of us until we find one that ends in a
186
+ // quote. We can then just splice all of the parts in between the
187
+ // starting quote and the ending quote out of the directives array
188
+ // and continue parsing like normal.
189
+ // https://www.rfc-editor.org/rfc/rfc9111.html#name-no-cache-2
190
+ if (value[0] === '"') {
191
+ // Something like `no-cache="some-header"` OR `no-cache="some-header, another-header"`.
192
+
193
+ // Add the first header on and cut off the leading quote
194
+ const headers = [value.substring(1)]
195
+
196
+ let foundEndingQuote = value[value.length - 1] === '"'
197
+ if (!foundEndingQuote) {
198
+ // Something like `no-cache="some-header, another-header"`
199
+ // This can still be something invalid, e.g. `no-cache="some-header, ...`
200
+ for (let j = i + 1; j < directives.length; j++) {
201
+ const nextPart = directives[j]
202
+ const nextPartLength = nextPart.length
203
+
204
+ headers.push(nextPart.trim())
205
+
206
+ if (nextPartLength !== 0 && nextPart[nextPartLength - 1] === '"') {
207
+ foundEndingQuote = true
208
+ break
209
+ }
210
+ }
211
+ }
212
+
213
+ if (foundEndingQuote) {
214
+ let lastHeader = headers[headers.length - 1]
215
+ if (lastHeader[lastHeader.length - 1] === '"') {
216
+ lastHeader = lastHeader.substring(0, lastHeader.length - 1)
217
+ headers[headers.length - 1] = lastHeader
218
+ }
219
+
220
+ if (key in output) {
221
+ output[key] = output[key].concat(headers)
222
+ } else {
223
+ output[key] = headers
224
+ }
225
+ }
226
+ } else {
227
+ // Something like `no-cache=some-header`
228
+ if (key in output) {
229
+ output[key] = output[key].concat(value)
230
+ } else {
231
+ output[key] = [value]
232
+ }
233
+ }
234
+
235
+ break
236
+ }
237
+ }
238
+ // eslint-disable-next-line no-fallthrough
239
+ case 'public':
240
+ case 'no-store':
241
+ case 'must-revalidate':
242
+ case 'proxy-revalidate':
243
+ case 'immutable':
244
+ case 'no-transform':
245
+ case 'must-understand':
246
+ case 'only-if-cached':
247
+ if (value) {
248
+ // These are qualified (something like `public=...`) when they aren't
249
+ // allowed to be, skip
250
+ continue
251
+ }
252
+
253
+ output[key] = true
254
+ break
255
+ default:
256
+ // Ignore unknown directives as per https://www.rfc-editor.org/rfc/rfc9111.html#section-5.2.3-1
257
+ continue
258
+ }
259
+ }
260
+
261
+ return output
262
+ }
263
+
264
+ /**
265
+ * @param {string | string[]} varyHeader Vary header from the server
266
+ * @param {Record<string, string | string[]>} headers Request headers
267
+ * @returns {Record<string, string | string[]>}
268
+ */
269
+ function parseVaryHeader (varyHeader, headers) {
270
+ if (typeof varyHeader === 'string' && varyHeader.includes('*')) {
271
+ return headers
272
+ }
273
+
274
+ const output = /** @type {Record<string, string | string[] | null>} */ ({})
275
+
276
+ const varyingHeaders = typeof varyHeader === 'string'
277
+ ? varyHeader.split(',')
278
+ : varyHeader
279
+
280
+ for (const header of varyingHeaders) {
281
+ const trimmedHeader = header.trim().toLowerCase()
282
+
283
+ output[trimmedHeader] = headers[trimmedHeader] ?? null
284
+ }
285
+
286
+ return output
287
+ }
288
+
289
+ /**
290
+ * Note: this deviates from the spec a little. Empty etags ("", W/"") are valid,
291
+ * however, including them in cached resposnes serves little to no purpose.
292
+ *
293
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-etag
294
+ *
295
+ * @param {string} etag
296
+ * @returns {boolean}
297
+ */
298
+ function isEtagUsable (etag) {
299
+ if (etag.length <= 2) {
300
+ // Shortest an etag can be is two chars (just ""). This is where we deviate
301
+ // from the spec requiring a min of 3 chars however
302
+ return false
303
+ }
304
+
305
+ if (etag[0] === '"' && etag[etag.length - 1] === '"') {
306
+ // ETag: ""asd123"" or ETag: "W/"asd123"", kinda undefined behavior in the
307
+ // spec. Some servers will accept these while others don't.
308
+ // ETag: "asd123"
309
+ return !(etag[1] === '"' || etag.startsWith('"W/'))
310
+ }
311
+
312
+ if (etag.startsWith('W/"') && etag[etag.length - 1] === '"') {
313
+ // ETag: W/"", also where we deviate from the spec & require a min of 3
314
+ // chars
315
+ // ETag: for W/"", W/"asd123"
316
+ return etag.length !== 4
317
+ }
318
+
319
+ // Anything else
320
+ return false
321
+ }
322
+
323
+ /**
324
+ * @param {unknown} store
325
+ * @returns {asserts store is import('../../types/cache-interceptor.d.ts').default.CacheStore}
326
+ */
327
+ function assertCacheStore (store, name = 'CacheStore') {
328
+ if (typeof store !== 'object' || store === null) {
329
+ throw new TypeError(`expected type of ${name} to be a CacheStore, got ${store === null ? 'null' : typeof store}`)
330
+ }
331
+
332
+ for (const fn of ['get', 'createWriteStream', 'delete']) {
333
+ if (typeof store[fn] !== 'function') {
334
+ throw new TypeError(`${name} needs to have a \`${fn}()\` function`)
335
+ }
336
+ }
337
+ }
338
+ /**
339
+ * @param {unknown} methods
340
+ * @returns {asserts methods is import('../../types/cache-interceptor.d.ts').default.CacheMethods[]}
341
+ */
342
+ function assertCacheMethods (methods, name = 'CacheMethods') {
343
+ if (!Array.isArray(methods)) {
344
+ throw new TypeError(`expected type of ${name} needs to be an array, got ${methods === null ? 'null' : typeof methods}`)
345
+ }
346
+
347
+ if (methods.length === 0) {
348
+ throw new TypeError(`${name} needs to have at least one method`)
349
+ }
350
+
351
+ for (const method of methods) {
352
+ if (!safeHTTPMethods.includes(method)) {
353
+ throw new TypeError(`element of ${name}-array needs to be one of following values: ${safeHTTPMethods.join(', ')}, got ${method}`)
354
+ }
355
+ }
356
+ }
357
+
358
+ module.exports = {
359
+ makeCacheKey,
360
+ normaliseHeaders,
361
+ assertCacheKey,
362
+ assertCacheValue,
363
+ parseCacheControlHeader,
364
+ parseVaryHeader,
365
+ isEtagUsable,
366
+ assertCacheMethods,
367
+ assertCacheStore
368
+ }
@@ -0,0 +1,259 @@
1
+ 'use strict'
2
+
3
+ const IMF_DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
4
+ const IMF_SPACES = [4, 7, 11, 16, 25]
5
+ const IMF_MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
6
+ const IMF_COLONS = [19, 22]
7
+
8
+ const ASCTIME_SPACES = [3, 7, 10, 19]
9
+
10
+ const RFC850_DAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
11
+
12
+ /**
13
+ * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-date-time-formats
14
+ *
15
+ * @param {string} date
16
+ * @param {Date} [now]
17
+ * @returns {Date | undefined}
18
+ */
19
+ function parseHttpDate (date, now) {
20
+ // Sun, 06 Nov 1994 08:49:37 GMT ; IMF-fixdate
21
+ // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
22
+ // Sunday, 06-Nov-94 08:49:37 GMT ; obsolete RFC 850 format
23
+
24
+ date = date.toLowerCase()
25
+
26
+ switch (date[3]) {
27
+ case ',': return parseImfDate(date)
28
+ case ' ': return parseAscTimeDate(date)
29
+ default: return parseRfc850Date(date, now)
30
+ }
31
+ }
32
+
33
+ /**
34
+ * @see https://httpwg.org/specs/rfc9110.html#preferred.date.format
35
+ *
36
+ * @param {string} date
37
+ * @returns {Date | undefined}
38
+ */
39
+ function parseImfDate (date) {
40
+ if (date.length !== 29) {
41
+ return undefined
42
+ }
43
+
44
+ if (!date.endsWith('gmt')) {
45
+ // Unsupported timezone
46
+ return undefined
47
+ }
48
+
49
+ for (const spaceInx of IMF_SPACES) {
50
+ if (date[spaceInx] !== ' ') {
51
+ return undefined
52
+ }
53
+ }
54
+
55
+ for (const colonIdx of IMF_COLONS) {
56
+ if (date[colonIdx] !== ':') {
57
+ return undefined
58
+ }
59
+ }
60
+
61
+ const dayName = date.substring(0, 3)
62
+ if (!IMF_DAYS.includes(dayName)) {
63
+ return undefined
64
+ }
65
+
66
+ const dayString = date.substring(5, 7)
67
+ const day = Number.parseInt(dayString)
68
+ if (isNaN(day) || (day < 10 && dayString[0] !== '0')) {
69
+ // Not a number, 0, or it's less than 10 and didn't start with a 0
70
+ return undefined
71
+ }
72
+
73
+ const month = date.substring(8, 11)
74
+ const monthIdx = IMF_MONTHS.indexOf(month)
75
+ if (monthIdx === -1) {
76
+ return undefined
77
+ }
78
+
79
+ const year = Number.parseInt(date.substring(12, 16))
80
+ if (isNaN(year)) {
81
+ return undefined
82
+ }
83
+
84
+ const hourString = date.substring(17, 19)
85
+ const hour = Number.parseInt(hourString)
86
+ if (isNaN(hour) || (hour < 10 && hourString[0] !== '0')) {
87
+ return undefined
88
+ }
89
+
90
+ const minuteString = date.substring(20, 22)
91
+ const minute = Number.parseInt(minuteString)
92
+ if (isNaN(minute) || (minute < 10 && minuteString[0] !== '0')) {
93
+ return undefined
94
+ }
95
+
96
+ const secondString = date.substring(23, 25)
97
+ const second = Number.parseInt(secondString)
98
+ if (isNaN(second) || (second < 10 && secondString[0] !== '0')) {
99
+ return undefined
100
+ }
101
+
102
+ return new Date(Date.UTC(year, monthIdx, day, hour, minute, second))
103
+ }
104
+
105
+ /**
106
+ * @see https://httpwg.org/specs/rfc9110.html#obsolete.date.formats
107
+ *
108
+ * @param {string} date
109
+ * @returns {Date | undefined}
110
+ */
111
+ function parseAscTimeDate (date) {
112
+ // This is assumed to be in UTC
113
+
114
+ if (date.length !== 24) {
115
+ return undefined
116
+ }
117
+
118
+ for (const spaceIdx of ASCTIME_SPACES) {
119
+ if (date[spaceIdx] !== ' ') {
120
+ return undefined
121
+ }
122
+ }
123
+
124
+ const dayName = date.substring(0, 3)
125
+ if (!IMF_DAYS.includes(dayName)) {
126
+ return undefined
127
+ }
128
+
129
+ const month = date.substring(4, 7)
130
+ const monthIdx = IMF_MONTHS.indexOf(month)
131
+ if (monthIdx === -1) {
132
+ return undefined
133
+ }
134
+
135
+ const dayString = date.substring(8, 10)
136
+ const day = Number.parseInt(dayString)
137
+ if (isNaN(day) || (day < 10 && dayString[0] !== ' ')) {
138
+ return undefined
139
+ }
140
+
141
+ const hourString = date.substring(11, 13)
142
+ const hour = Number.parseInt(hourString)
143
+ if (isNaN(hour) || (hour < 10 && hourString[0] !== '0')) {
144
+ return undefined
145
+ }
146
+
147
+ const minuteString = date.substring(14, 16)
148
+ const minute = Number.parseInt(minuteString)
149
+ if (isNaN(minute) || (minute < 10 && minuteString[0] !== '0')) {
150
+ return undefined
151
+ }
152
+
153
+ const secondString = date.substring(17, 19)
154
+ const second = Number.parseInt(secondString)
155
+ if (isNaN(second) || (second < 10 && secondString[0] !== '0')) {
156
+ return undefined
157
+ }
158
+
159
+ const year = Number.parseInt(date.substring(20, 24))
160
+ if (isNaN(year)) {
161
+ return undefined
162
+ }
163
+
164
+ return new Date(Date.UTC(year, monthIdx, day, hour, minute, second))
165
+ }
166
+
167
+ /**
168
+ * @see https://httpwg.org/specs/rfc9110.html#obsolete.date.formats
169
+ *
170
+ * @param {string} date
171
+ * @param {Date} [now]
172
+ * @returns {Date | undefined}
173
+ */
174
+ function parseRfc850Date (date, now = new Date()) {
175
+ if (!date.endsWith('gmt')) {
176
+ // Unsupported timezone
177
+ return undefined
178
+ }
179
+
180
+ const commaIndex = date.indexOf(',')
181
+ if (commaIndex === -1) {
182
+ return undefined
183
+ }
184
+
185
+ if ((date.length - commaIndex - 1) !== 23) {
186
+ return undefined
187
+ }
188
+
189
+ const dayName = date.substring(0, commaIndex)
190
+ if (!RFC850_DAYS.includes(dayName)) {
191
+ return undefined
192
+ }
193
+
194
+ if (
195
+ date[commaIndex + 1] !== ' ' ||
196
+ date[commaIndex + 4] !== '-' ||
197
+ date[commaIndex + 8] !== '-' ||
198
+ date[commaIndex + 11] !== ' ' ||
199
+ date[commaIndex + 14] !== ':' ||
200
+ date[commaIndex + 17] !== ':' ||
201
+ date[commaIndex + 20] !== ' '
202
+ ) {
203
+ return undefined
204
+ }
205
+
206
+ const dayString = date.substring(commaIndex + 2, commaIndex + 4)
207
+ const day = Number.parseInt(dayString)
208
+ if (isNaN(day) || (day < 10 && dayString[0] !== '0')) {
209
+ // Not a number, or it's less than 10 and didn't start with a 0
210
+ return undefined
211
+ }
212
+
213
+ const month = date.substring(commaIndex + 5, commaIndex + 8)
214
+ const monthIdx = IMF_MONTHS.indexOf(month)
215
+ if (monthIdx === -1) {
216
+ return undefined
217
+ }
218
+
219
+ // As of this point year is just the decade (i.e. 94)
220
+ let year = Number.parseInt(date.substring(commaIndex + 9, commaIndex + 11))
221
+ if (isNaN(year)) {
222
+ return undefined
223
+ }
224
+
225
+ const currentYear = now.getUTCFullYear()
226
+ const currentDecade = currentYear % 100
227
+ const currentCentury = Math.floor(currentYear / 100)
228
+
229
+ if (year > currentDecade && year - currentDecade >= 50) {
230
+ // Over 50 years in future, go to previous century
231
+ year += (currentCentury - 1) * 100
232
+ } else {
233
+ year += currentCentury * 100
234
+ }
235
+
236
+ const hourString = date.substring(commaIndex + 12, commaIndex + 14)
237
+ const hour = Number.parseInt(hourString)
238
+ if (isNaN(hour) || (hour < 10 && hourString[0] !== '0')) {
239
+ return undefined
240
+ }
241
+
242
+ const minuteString = date.substring(commaIndex + 15, commaIndex + 17)
243
+ const minute = Number.parseInt(minuteString)
244
+ if (isNaN(minute) || (minute < 10 && minuteString[0] !== '0')) {
245
+ return undefined
246
+ }
247
+
248
+ const secondString = date.substring(commaIndex + 18, commaIndex + 20)
249
+ const second = Number.parseInt(secondString)
250
+ if (isNaN(second) || (second < 10 && secondString[0] !== '0')) {
251
+ return undefined
252
+ }
253
+
254
+ return new Date(Date.UTC(year, monthIdx, day, hour, minute, second))
255
+ }
256
+
257
+ module.exports = {
258
+ parseHttpDate
259
+ }
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ kConnected,
5
+ kPending,
6
+ kRunning,
7
+ kSize,
8
+ kFree,
9
+ kQueued
10
+ } = require('../core/symbols')
11
+
12
+ class ClientStats {
13
+ constructor (client) {
14
+ this.connected = client[kConnected]
15
+ this.pending = client[kPending]
16
+ this.running = client[kRunning]
17
+ this.size = client[kSize]
18
+ }
19
+ }
20
+
21
+ class PoolStats {
22
+ constructor (pool) {
23
+ this.connected = pool[kConnected]
24
+ this.free = pool[kFree]
25
+ this.pending = pool[kPending]
26
+ this.queued = pool[kQueued]
27
+ this.running = pool[kRunning]
28
+ this.size = pool[kSize]
29
+ }
30
+ }
31
+
32
+ module.exports = { ClientStats, PoolStats }