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,368 +0,0 @@
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
- }
@@ -1,259 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
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 }