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,862 +0,0 @@
1
- 'use strict'
2
-
3
- const { kConstruct } = require('../../core/symbols')
4
- const { urlEquals, getFieldValues } = require('./util')
5
- const { kEnumerableProperty, isDisturbed } = require('../../core/util')
6
- const { webidl } = require('../fetch/webidl')
7
- const { cloneResponse, fromInnerResponse, getResponseState } = require('../fetch/response')
8
- const { Request, fromInnerRequest, getRequestState } = require('../fetch/request')
9
- const { fetching } = require('../fetch/index')
10
- const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require('../fetch/util')
11
- const assert = require('node:assert')
12
-
13
- /**
14
- * @see https://w3c.github.io/ServiceWorker/#dfn-cache-batch-operation
15
- * @typedef {Object} CacheBatchOperation
16
- * @property {'delete' | 'put'} type
17
- * @property {any} request
18
- * @property {any} response
19
- * @property {import('../../types/cache').CacheQueryOptions} options
20
- */
21
-
22
- /**
23
- * @see https://w3c.github.io/ServiceWorker/#dfn-request-response-list
24
- * @typedef {[any, any][]} requestResponseList
25
- */
26
-
27
- class Cache {
28
- /**
29
- * @see https://w3c.github.io/ServiceWorker/#dfn-relevant-request-response-list
30
- * @type {requestResponseList}
31
- */
32
- #relevantRequestResponseList
33
-
34
- constructor () {
35
- if (arguments[0] !== kConstruct) {
36
- webidl.illegalConstructor()
37
- }
38
-
39
- webidl.util.markAsUncloneable(this)
40
- this.#relevantRequestResponseList = arguments[1]
41
- }
42
-
43
- async match (request, options = {}) {
44
- webidl.brandCheck(this, Cache)
45
-
46
- const prefix = 'Cache.match'
47
- webidl.argumentLengthCheck(arguments, 1, prefix)
48
-
49
- request = webidl.converters.RequestInfo(request, prefix, 'request')
50
- options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
51
-
52
- const p = this.#internalMatchAll(request, options, 1)
53
-
54
- if (p.length === 0) {
55
- return
56
- }
57
-
58
- return p[0]
59
- }
60
-
61
- async matchAll (request = undefined, options = {}) {
62
- webidl.brandCheck(this, Cache)
63
-
64
- const prefix = 'Cache.matchAll'
65
- if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
66
- options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
67
-
68
- return this.#internalMatchAll(request, options)
69
- }
70
-
71
- async add (request) {
72
- webidl.brandCheck(this, Cache)
73
-
74
- const prefix = 'Cache.add'
75
- webidl.argumentLengthCheck(arguments, 1, prefix)
76
-
77
- request = webidl.converters.RequestInfo(request, prefix, 'request')
78
-
79
- // 1.
80
- const requests = [request]
81
-
82
- // 2.
83
- const responseArrayPromise = this.addAll(requests)
84
-
85
- // 3.
86
- return await responseArrayPromise
87
- }
88
-
89
- async addAll (requests) {
90
- webidl.brandCheck(this, Cache)
91
-
92
- const prefix = 'Cache.addAll'
93
- webidl.argumentLengthCheck(arguments, 1, prefix)
94
-
95
- // 1.
96
- const responsePromises = []
97
-
98
- // 2.
99
- const requestList = []
100
-
101
- // 3.
102
- for (let request of requests) {
103
- if (request === undefined) {
104
- throw webidl.errors.conversionFailed({
105
- prefix,
106
- argument: 'Argument 1',
107
- types: ['undefined is not allowed']
108
- })
109
- }
110
-
111
- request = webidl.converters.RequestInfo(request)
112
-
113
- if (typeof request === 'string') {
114
- continue
115
- }
116
-
117
- // 3.1
118
- const r = getRequestState(request)
119
-
120
- // 3.2
121
- if (!urlIsHttpHttpsScheme(r.url) || r.method !== 'GET') {
122
- throw webidl.errors.exception({
123
- header: prefix,
124
- message: 'Expected http/s scheme when method is not GET.'
125
- })
126
- }
127
- }
128
-
129
- // 4.
130
- /** @type {ReturnType<typeof fetching>[]} */
131
- const fetchControllers = []
132
-
133
- // 5.
134
- for (const request of requests) {
135
- // 5.1
136
- const r = getRequestState(new Request(request))
137
-
138
- // 5.2
139
- if (!urlIsHttpHttpsScheme(r.url)) {
140
- throw webidl.errors.exception({
141
- header: prefix,
142
- message: 'Expected http/s scheme.'
143
- })
144
- }
145
-
146
- // 5.4
147
- r.initiator = 'fetch'
148
- r.destination = 'subresource'
149
-
150
- // 5.5
151
- requestList.push(r)
152
-
153
- // 5.6
154
- const responsePromise = createDeferredPromise()
155
-
156
- // 5.7
157
- fetchControllers.push(fetching({
158
- request: r,
159
- processResponse (response) {
160
- // 1.
161
- if (response.type === 'error' || response.status === 206 || response.status < 200 || response.status > 299) {
162
- responsePromise.reject(webidl.errors.exception({
163
- header: 'Cache.addAll',
164
- message: 'Received an invalid status code or the request failed.'
165
- }))
166
- } else if (response.headersList.contains('vary')) { // 2.
167
- // 2.1
168
- const fieldValues = getFieldValues(response.headersList.get('vary'))
169
-
170
- // 2.2
171
- for (const fieldValue of fieldValues) {
172
- // 2.2.1
173
- if (fieldValue === '*') {
174
- responsePromise.reject(webidl.errors.exception({
175
- header: 'Cache.addAll',
176
- message: 'invalid vary field value'
177
- }))
178
-
179
- for (const controller of fetchControllers) {
180
- controller.abort()
181
- }
182
-
183
- return
184
- }
185
- }
186
- }
187
- },
188
- processResponseEndOfBody (response) {
189
- // 1.
190
- if (response.aborted) {
191
- responsePromise.reject(new DOMException('aborted', 'AbortError'))
192
- return
193
- }
194
-
195
- // 2.
196
- responsePromise.resolve(response)
197
- }
198
- }))
199
-
200
- // 5.8
201
- responsePromises.push(responsePromise.promise)
202
- }
203
-
204
- // 6.
205
- const p = Promise.all(responsePromises)
206
-
207
- // 7.
208
- const responses = await p
209
-
210
- // 7.1
211
- const operations = []
212
-
213
- // 7.2
214
- let index = 0
215
-
216
- // 7.3
217
- for (const response of responses) {
218
- // 7.3.1
219
- /** @type {CacheBatchOperation} */
220
- const operation = {
221
- type: 'put', // 7.3.2
222
- request: requestList[index], // 7.3.3
223
- response // 7.3.4
224
- }
225
-
226
- operations.push(operation) // 7.3.5
227
-
228
- index++ // 7.3.6
229
- }
230
-
231
- // 7.5
232
- const cacheJobPromise = createDeferredPromise()
233
-
234
- // 7.6.1
235
- let errorData = null
236
-
237
- // 7.6.2
238
- try {
239
- this.#batchCacheOperations(operations)
240
- } catch (e) {
241
- errorData = e
242
- }
243
-
244
- // 7.6.3
245
- queueMicrotask(() => {
246
- // 7.6.3.1
247
- if (errorData === null) {
248
- cacheJobPromise.resolve(undefined)
249
- } else {
250
- // 7.6.3.2
251
- cacheJobPromise.reject(errorData)
252
- }
253
- })
254
-
255
- // 7.7
256
- return cacheJobPromise.promise
257
- }
258
-
259
- async put (request, response) {
260
- webidl.brandCheck(this, Cache)
261
-
262
- const prefix = 'Cache.put'
263
- webidl.argumentLengthCheck(arguments, 2, prefix)
264
-
265
- request = webidl.converters.RequestInfo(request, prefix, 'request')
266
- response = webidl.converters.Response(response, prefix, 'response')
267
-
268
- // 1.
269
- let innerRequest = null
270
-
271
- // 2.
272
- if (webidl.is.Request(request)) {
273
- innerRequest = getRequestState(request)
274
- } else { // 3.
275
- innerRequest = getRequestState(new Request(request))
276
- }
277
-
278
- // 4.
279
- if (!urlIsHttpHttpsScheme(innerRequest.url) || innerRequest.method !== 'GET') {
280
- throw webidl.errors.exception({
281
- header: prefix,
282
- message: 'Expected an http/s scheme when method is not GET'
283
- })
284
- }
285
-
286
- // 5.
287
- const innerResponse = getResponseState(response)
288
-
289
- // 6.
290
- if (innerResponse.status === 206) {
291
- throw webidl.errors.exception({
292
- header: prefix,
293
- message: 'Got 206 status'
294
- })
295
- }
296
-
297
- // 7.
298
- if (innerResponse.headersList.contains('vary')) {
299
- // 7.1.
300
- const fieldValues = getFieldValues(innerResponse.headersList.get('vary'))
301
-
302
- // 7.2.
303
- for (const fieldValue of fieldValues) {
304
- // 7.2.1
305
- if (fieldValue === '*') {
306
- throw webidl.errors.exception({
307
- header: prefix,
308
- message: 'Got * vary field value'
309
- })
310
- }
311
- }
312
- }
313
-
314
- // 8.
315
- if (innerResponse.body && (isDisturbed(innerResponse.body.stream) || innerResponse.body.stream.locked)) {
316
- throw webidl.errors.exception({
317
- header: prefix,
318
- message: 'Response body is locked or disturbed'
319
- })
320
- }
321
-
322
- // 9.
323
- const clonedResponse = cloneResponse(innerResponse)
324
-
325
- // 10.
326
- const bodyReadPromise = createDeferredPromise()
327
-
328
- // 11.
329
- if (innerResponse.body != null) {
330
- // 11.1
331
- const stream = innerResponse.body.stream
332
-
333
- // 11.2
334
- const reader = stream.getReader()
335
-
336
- // 11.3
337
- readAllBytes(reader, bodyReadPromise.resolve, bodyReadPromise.reject)
338
- } else {
339
- bodyReadPromise.resolve(undefined)
340
- }
341
-
342
- // 12.
343
- /** @type {CacheBatchOperation[]} */
344
- const operations = []
345
-
346
- // 13.
347
- /** @type {CacheBatchOperation} */
348
- const operation = {
349
- type: 'put', // 14.
350
- request: innerRequest, // 15.
351
- response: clonedResponse // 16.
352
- }
353
-
354
- // 17.
355
- operations.push(operation)
356
-
357
- // 19.
358
- const bytes = await bodyReadPromise.promise
359
-
360
- if (clonedResponse.body != null) {
361
- clonedResponse.body.source = bytes
362
- }
363
-
364
- // 19.1
365
- const cacheJobPromise = createDeferredPromise()
366
-
367
- // 19.2.1
368
- let errorData = null
369
-
370
- // 19.2.2
371
- try {
372
- this.#batchCacheOperations(operations)
373
- } catch (e) {
374
- errorData = e
375
- }
376
-
377
- // 19.2.3
378
- queueMicrotask(() => {
379
- // 19.2.3.1
380
- if (errorData === null) {
381
- cacheJobPromise.resolve()
382
- } else { // 19.2.3.2
383
- cacheJobPromise.reject(errorData)
384
- }
385
- })
386
-
387
- return cacheJobPromise.promise
388
- }
389
-
390
- async delete (request, options = {}) {
391
- webidl.brandCheck(this, Cache)
392
-
393
- const prefix = 'Cache.delete'
394
- webidl.argumentLengthCheck(arguments, 1, prefix)
395
-
396
- request = webidl.converters.RequestInfo(request, prefix, 'request')
397
- options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
398
-
399
- /**
400
- * @type {Request}
401
- */
402
- let r = null
403
-
404
- if (webidl.is.Request(request)) {
405
- r = getRequestState(request)
406
-
407
- if (r.method !== 'GET' && !options.ignoreMethod) {
408
- return false
409
- }
410
- } else {
411
- assert(typeof request === 'string')
412
-
413
- r = getRequestState(new Request(request))
414
- }
415
-
416
- /** @type {CacheBatchOperation[]} */
417
- const operations = []
418
-
419
- /** @type {CacheBatchOperation} */
420
- const operation = {
421
- type: 'delete',
422
- request: r,
423
- options
424
- }
425
-
426
- operations.push(operation)
427
-
428
- const cacheJobPromise = createDeferredPromise()
429
-
430
- let errorData = null
431
- let requestResponses
432
-
433
- try {
434
- requestResponses = this.#batchCacheOperations(operations)
435
- } catch (e) {
436
- errorData = e
437
- }
438
-
439
- queueMicrotask(() => {
440
- if (errorData === null) {
441
- cacheJobPromise.resolve(!!requestResponses?.length)
442
- } else {
443
- cacheJobPromise.reject(errorData)
444
- }
445
- })
446
-
447
- return cacheJobPromise.promise
448
- }
449
-
450
- /**
451
- * @see https://w3c.github.io/ServiceWorker/#dom-cache-keys
452
- * @param {any} request
453
- * @param {import('../../types/cache').CacheQueryOptions} options
454
- * @returns {Promise<readonly Request[]>}
455
- */
456
- async keys (request = undefined, options = {}) {
457
- webidl.brandCheck(this, Cache)
458
-
459
- const prefix = 'Cache.keys'
460
-
461
- if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
462
- options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
463
-
464
- // 1.
465
- let r = null
466
-
467
- // 2.
468
- if (request !== undefined) {
469
- // 2.1
470
- if (webidl.is.Request(request)) {
471
- // 2.1.1
472
- r = getRequestState(request)
473
-
474
- // 2.1.2
475
- if (r.method !== 'GET' && !options.ignoreMethod) {
476
- return []
477
- }
478
- } else if (typeof request === 'string') { // 2.2
479
- r = getRequestState(new Request(request))
480
- }
481
- }
482
-
483
- // 4.
484
- const promise = createDeferredPromise()
485
-
486
- // 5.
487
- // 5.1
488
- const requests = []
489
-
490
- // 5.2
491
- if (request === undefined) {
492
- // 5.2.1
493
- for (const requestResponse of this.#relevantRequestResponseList) {
494
- // 5.2.1.1
495
- requests.push(requestResponse[0])
496
- }
497
- } else { // 5.3
498
- // 5.3.1
499
- const requestResponses = this.#queryCache(r, options)
500
-
501
- // 5.3.2
502
- for (const requestResponse of requestResponses) {
503
- // 5.3.2.1
504
- requests.push(requestResponse[0])
505
- }
506
- }
507
-
508
- // 5.4
509
- queueMicrotask(() => {
510
- // 5.4.1
511
- const requestList = []
512
-
513
- // 5.4.2
514
- for (const request of requests) {
515
- const requestObject = fromInnerRequest(
516
- request,
517
- undefined,
518
- new AbortController().signal,
519
- 'immutable'
520
- )
521
- // 5.4.2.1
522
- requestList.push(requestObject)
523
- }
524
-
525
- // 5.4.3
526
- promise.resolve(Object.freeze(requestList))
527
- })
528
-
529
- return promise.promise
530
- }
531
-
532
- /**
533
- * @see https://w3c.github.io/ServiceWorker/#batch-cache-operations-algorithm
534
- * @param {CacheBatchOperation[]} operations
535
- * @returns {requestResponseList}
536
- */
537
- #batchCacheOperations (operations) {
538
- // 1.
539
- const cache = this.#relevantRequestResponseList
540
-
541
- // 2.
542
- const backupCache = [...cache]
543
-
544
- // 3.
545
- const addedItems = []
546
-
547
- // 4.1
548
- const resultList = []
549
-
550
- try {
551
- // 4.2
552
- for (const operation of operations) {
553
- // 4.2.1
554
- if (operation.type !== 'delete' && operation.type !== 'put') {
555
- throw webidl.errors.exception({
556
- header: 'Cache.#batchCacheOperations',
557
- message: 'operation type does not match "delete" or "put"'
558
- })
559
- }
560
-
561
- // 4.2.2
562
- if (operation.type === 'delete' && operation.response != null) {
563
- throw webidl.errors.exception({
564
- header: 'Cache.#batchCacheOperations',
565
- message: 'delete operation should not have an associated response'
566
- })
567
- }
568
-
569
- // 4.2.3
570
- if (this.#queryCache(operation.request, operation.options, addedItems).length) {
571
- throw new DOMException('???', 'InvalidStateError')
572
- }
573
-
574
- // 4.2.4
575
- let requestResponses
576
-
577
- // 4.2.5
578
- if (operation.type === 'delete') {
579
- // 4.2.5.1
580
- requestResponses = this.#queryCache(operation.request, operation.options)
581
-
582
- // TODO: the spec is wrong, this is needed to pass WPTs
583
- if (requestResponses.length === 0) {
584
- return []
585
- }
586
-
587
- // 4.2.5.2
588
- for (const requestResponse of requestResponses) {
589
- const idx = cache.indexOf(requestResponse)
590
- assert(idx !== -1)
591
-
592
- // 4.2.5.2.1
593
- cache.splice(idx, 1)
594
- }
595
- } else if (operation.type === 'put') { // 4.2.6
596
- // 4.2.6.1
597
- if (operation.response == null) {
598
- throw webidl.errors.exception({
599
- header: 'Cache.#batchCacheOperations',
600
- message: 'put operation should have an associated response'
601
- })
602
- }
603
-
604
- // 4.2.6.2
605
- const r = operation.request
606
-
607
- // 4.2.6.3
608
- if (!urlIsHttpHttpsScheme(r.url)) {
609
- throw webidl.errors.exception({
610
- header: 'Cache.#batchCacheOperations',
611
- message: 'expected http or https scheme'
612
- })
613
- }
614
-
615
- // 4.2.6.4
616
- if (r.method !== 'GET') {
617
- throw webidl.errors.exception({
618
- header: 'Cache.#batchCacheOperations',
619
- message: 'not get method'
620
- })
621
- }
622
-
623
- // 4.2.6.5
624
- if (operation.options != null) {
625
- throw webidl.errors.exception({
626
- header: 'Cache.#batchCacheOperations',
627
- message: 'options must not be defined'
628
- })
629
- }
630
-
631
- // 4.2.6.6
632
- requestResponses = this.#queryCache(operation.request)
633
-
634
- // 4.2.6.7
635
- for (const requestResponse of requestResponses) {
636
- const idx = cache.indexOf(requestResponse)
637
- assert(idx !== -1)
638
-
639
- // 4.2.6.7.1
640
- cache.splice(idx, 1)
641
- }
642
-
643
- // 4.2.6.8
644
- cache.push([operation.request, operation.response])
645
-
646
- // 4.2.6.10
647
- addedItems.push([operation.request, operation.response])
648
- }
649
-
650
- // 4.2.7
651
- resultList.push([operation.request, operation.response])
652
- }
653
-
654
- // 4.3
655
- return resultList
656
- } catch (e) { // 5.
657
- // 5.1
658
- this.#relevantRequestResponseList.length = 0
659
-
660
- // 5.2
661
- this.#relevantRequestResponseList = backupCache
662
-
663
- // 5.3
664
- throw e
665
- }
666
- }
667
-
668
- /**
669
- * @see https://w3c.github.io/ServiceWorker/#query-cache
670
- * @param {any} requestQuery
671
- * @param {import('../../types/cache').CacheQueryOptions} options
672
- * @param {requestResponseList} targetStorage
673
- * @returns {requestResponseList}
674
- */
675
- #queryCache (requestQuery, options, targetStorage) {
676
- /** @type {requestResponseList} */
677
- const resultList = []
678
-
679
- const storage = targetStorage ?? this.#relevantRequestResponseList
680
-
681
- for (const requestResponse of storage) {
682
- const [cachedRequest, cachedResponse] = requestResponse
683
- if (this.#requestMatchesCachedItem(requestQuery, cachedRequest, cachedResponse, options)) {
684
- resultList.push(requestResponse)
685
- }
686
- }
687
-
688
- return resultList
689
- }
690
-
691
- /**
692
- * @see https://w3c.github.io/ServiceWorker/#request-matches-cached-item-algorithm
693
- * @param {any} requestQuery
694
- * @param {any} request
695
- * @param {any | null} response
696
- * @param {import('../../types/cache').CacheQueryOptions | undefined} options
697
- * @returns {boolean}
698
- */
699
- #requestMatchesCachedItem (requestQuery, request, response = null, options) {
700
- // if (options?.ignoreMethod === false && request.method === 'GET') {
701
- // return false
702
- // }
703
-
704
- const queryURL = new URL(requestQuery.url)
705
-
706
- const cachedURL = new URL(request.url)
707
-
708
- if (options?.ignoreSearch) {
709
- cachedURL.search = ''
710
-
711
- queryURL.search = ''
712
- }
713
-
714
- if (!urlEquals(queryURL, cachedURL, true)) {
715
- return false
716
- }
717
-
718
- if (
719
- response == null ||
720
- options?.ignoreVary ||
721
- !response.headersList.contains('vary')
722
- ) {
723
- return true
724
- }
725
-
726
- const fieldValues = getFieldValues(response.headersList.get('vary'))
727
-
728
- for (const fieldValue of fieldValues) {
729
- if (fieldValue === '*') {
730
- return false
731
- }
732
-
733
- const requestValue = request.headersList.get(fieldValue)
734
- const queryValue = requestQuery.headersList.get(fieldValue)
735
-
736
- // If one has the header and the other doesn't, or one has
737
- // a different value than the other, return false
738
- if (requestValue !== queryValue) {
739
- return false
740
- }
741
- }
742
-
743
- return true
744
- }
745
-
746
- #internalMatchAll (request, options, maxResponses = Infinity) {
747
- // 1.
748
- let r = null
749
-
750
- // 2.
751
- if (request !== undefined) {
752
- if (webidl.is.Request(request)) {
753
- // 2.1.1
754
- r = getRequestState(request)
755
-
756
- // 2.1.2
757
- if (r.method !== 'GET' && !options.ignoreMethod) {
758
- return []
759
- }
760
- } else if (typeof request === 'string') {
761
- // 2.2.1
762
- r = getRequestState(new Request(request))
763
- }
764
- }
765
-
766
- // 5.
767
- // 5.1
768
- const responses = []
769
-
770
- // 5.2
771
- if (request === undefined) {
772
- // 5.2.1
773
- for (const requestResponse of this.#relevantRequestResponseList) {
774
- responses.push(requestResponse[1])
775
- }
776
- } else { // 5.3
777
- // 5.3.1
778
- const requestResponses = this.#queryCache(r, options)
779
-
780
- // 5.3.2
781
- for (const requestResponse of requestResponses) {
782
- responses.push(requestResponse[1])
783
- }
784
- }
785
-
786
- // 5.4
787
- // We don't implement CORs so we don't need to loop over the responses, yay!
788
-
789
- // 5.5.1
790
- const responseList = []
791
-
792
- // 5.5.2
793
- for (const response of responses) {
794
- // 5.5.2.1
795
- const responseObject = fromInnerResponse(response, 'immutable')
796
-
797
- responseList.push(responseObject.clone())
798
-
799
- if (responseList.length >= maxResponses) {
800
- break
801
- }
802
- }
803
-
804
- // 6.
805
- return Object.freeze(responseList)
806
- }
807
- }
808
-
809
- Object.defineProperties(Cache.prototype, {
810
- [Symbol.toStringTag]: {
811
- value: 'Cache',
812
- configurable: true
813
- },
814
- match: kEnumerableProperty,
815
- matchAll: kEnumerableProperty,
816
- add: kEnumerableProperty,
817
- addAll: kEnumerableProperty,
818
- put: kEnumerableProperty,
819
- delete: kEnumerableProperty,
820
- keys: kEnumerableProperty
821
- })
822
-
823
- const cacheQueryOptionConverters = [
824
- {
825
- key: 'ignoreSearch',
826
- converter: webidl.converters.boolean,
827
- defaultValue: () => false
828
- },
829
- {
830
- key: 'ignoreMethod',
831
- converter: webidl.converters.boolean,
832
- defaultValue: () => false
833
- },
834
- {
835
- key: 'ignoreVary',
836
- converter: webidl.converters.boolean,
837
- defaultValue: () => false
838
- }
839
- ]
840
-
841
- webidl.converters.CacheQueryOptions = webidl.dictionaryConverter(cacheQueryOptionConverters)
842
-
843
- webidl.converters.MultiCacheQueryOptions = webidl.dictionaryConverter([
844
- ...cacheQueryOptionConverters,
845
- {
846
- key: 'cacheName',
847
- converter: webidl.converters.DOMString
848
- }
849
- ])
850
-
851
- webidl.converters.Response = webidl.interfaceConverter(
852
- webidl.is.Response,
853
- 'Response'
854
- )
855
-
856
- webidl.converters['sequence<RequestInfo>'] = webidl.sequenceConverter(
857
- webidl.converters.RequestInfo
858
- )
859
-
860
- module.exports = {
861
- Cache
862
- }