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.
- package/LICENSE +202 -0
- package/README.md +3 -0
- package/bundle/assets/help/README.md +113 -0
- package/bundle/assets/help/cli-help-knowledge.md +1382 -0
- package/bundle/assets/sounds/README.md +74 -0
- package/bundle/assets/sounds/confirmation-required.wav +0 -0
- package/bundle/assets/sounds/response-complete.wav +0 -0
- package/bundle/assets/sounds/selection-made.wav +0 -0
- package/bundle/dvcode.js +4442 -0
- package/bundle/fix-binary-permissions.js +215 -0
- package/bundle/login/templates/authSelectPage.html +870 -0
- package/bundle/login/templates/deepv.ico +0 -0
- package/bundle/login/templates/feishu.ico +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/darwin-arm64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/darwin-x64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/linux-x64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/win32-arm64-rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/win32-ia32-rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/win32-x64-rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/download.js +357 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/index.d.ts +1 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/index.js +42 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/postinstall.js +121 -0
- package/bundle/node_modules/@vscode/ripgrep/package.json +24 -0
- package/bundle/node_modules/undici/LICENSE +21 -0
- package/bundle/node_modules/undici/README.md +472 -0
- package/bundle/node_modules/undici/docs/docs/api/Agent.md +83 -0
- package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
- package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
- package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +151 -0
- package/bundle/node_modules/undici/docs/docs/api/Client.md +281 -0
- package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
- package/bundle/node_modules/undici/docs/docs/api/Connector.md +115 -0
- package/bundle/node_modules/undici/docs/docs/api/ContentType.md +57 -0
- package/bundle/node_modules/undici/docs/docs/api/Cookies.md +101 -0
- package/bundle/node_modules/undici/docs/docs/api/Debug.md +62 -0
- package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +204 -0
- package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +1200 -0
- package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/bundle/node_modules/undici/docs/docs/api/Errors.md +49 -0
- package/bundle/node_modules/undici/docs/docs/api/EventSource.md +45 -0
- package/bundle/node_modules/undici/docs/docs/api/Fetch.md +52 -0
- package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +262 -0
- package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/bundle/node_modules/undici/docs/docs/api/MockClient.md +77 -0
- package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
- package/bundle/node_modules/undici/docs/docs/api/MockPool.md +548 -0
- package/bundle/node_modules/undici/docs/docs/api/Pool.md +84 -0
- package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
- package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +227 -0
- package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +96 -0
- package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +45 -0
- package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +117 -0
- package/bundle/node_modules/undici/docs/docs/api/Util.md +25 -0
- package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +85 -0
- package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +20 -0
- package/bundle/node_modules/undici/index-fetch.js +35 -0
- package/bundle/node_modules/undici/index.d.ts +3 -0
- package/bundle/node_modules/undici/index.js +183 -0
- package/bundle/node_modules/undici/lib/api/abort-signal.js +59 -0
- package/bundle/node_modules/undici/lib/api/api-connect.js +110 -0
- package/bundle/node_modules/undici/lib/api/api-pipeline.js +252 -0
- package/bundle/node_modules/undici/lib/api/api-request.js +199 -0
- package/bundle/node_modules/undici/lib/api/api-stream.js +209 -0
- package/bundle/node_modules/undici/lib/api/api-upgrade.js +110 -0
- package/bundle/node_modules/undici/lib/api/index.js +7 -0
- package/bundle/node_modules/undici/lib/api/readable.js +558 -0
- package/bundle/node_modules/undici/lib/api/util.js +95 -0
- package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
- package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +461 -0
- package/bundle/node_modules/undici/lib/core/connect.js +164 -0
- package/bundle/node_modules/undici/lib/core/constants.js +143 -0
- package/bundle/node_modules/undici/lib/core/diagnostics.js +196 -0
- package/bundle/node_modules/undici/lib/core/errors.js +244 -0
- package/bundle/node_modules/undici/lib/core/request.js +397 -0
- package/bundle/node_modules/undici/lib/core/symbols.js +68 -0
- package/bundle/node_modules/undici/lib/core/tree.js +160 -0
- package/bundle/node_modules/undici/lib/core/util.js +988 -0
- package/bundle/node_modules/undici/lib/dispatcher/agent.js +135 -0
- package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +206 -0
- package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +1615 -0
- package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +798 -0
- package/bundle/node_modules/undici/lib/dispatcher/client.js +614 -0
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +161 -0
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
- package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +151 -0
- package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +159 -0
- package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +122 -0
- package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +191 -0
- package/bundle/node_modules/undici/lib/dispatcher/pool.js +118 -0
- package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +275 -0
- package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
- package/bundle/node_modules/undici/lib/global.js +32 -0
- package/bundle/node_modules/undici/lib/handler/cache-handler.js +448 -0
- package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
- package/bundle/node_modules/undici/lib/handler/decorator-handler.js +67 -0
- package/bundle/node_modules/undici/lib/handler/redirect-handler.js +227 -0
- package/bundle/node_modules/undici/lib/handler/retry-handler.js +342 -0
- package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +96 -0
- package/bundle/node_modules/undici/lib/handler/wrap-handler.js +95 -0
- package/bundle/node_modules/undici/lib/interceptor/cache.js +372 -0
- package/bundle/node_modules/undici/lib/interceptor/dns.js +432 -0
- package/bundle/node_modules/undici/lib/interceptor/dump.js +111 -0
- package/bundle/node_modules/undici/lib/interceptor/redirect.js +21 -0
- package/bundle/node_modules/undici/lib/interceptor/response-error.js +95 -0
- package/bundle/node_modules/undici/lib/interceptor/retry.js +19 -0
- package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +97 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.js +498 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.js.map +1 -0
- package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
- package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
- package/bundle/node_modules/undici/lib/llhttp/utils.js +15 -0
- package/bundle/node_modules/undici/lib/llhttp/utils.js.map +1 -0
- package/bundle/node_modules/undici/lib/mock/mock-agent.js +224 -0
- package/bundle/node_modules/undici/lib/mock/mock-call-history.js +248 -0
- package/bundle/node_modules/undici/lib/mock/mock-client.js +64 -0
- package/bundle/node_modules/undici/lib/mock/mock-errors.js +19 -0
- package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
- package/bundle/node_modules/undici/lib/mock/mock-pool.js +64 -0
- package/bundle/node_modules/undici/lib/mock/mock-symbols.js +31 -0
- package/bundle/node_modules/undici/lib/mock/mock-utils.js +433 -0
- package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
- package/bundle/node_modules/undici/lib/util/cache.js +368 -0
- package/bundle/node_modules/undici/lib/util/date.js +259 -0
- package/bundle/node_modules/undici/lib/util/stats.js +32 -0
- package/bundle/node_modules/undici/lib/util/timers.js +423 -0
- package/bundle/node_modules/undici/lib/web/cache/cache.js +862 -0
- package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
- package/bundle/node_modules/undici/lib/web/cache/util.js +45 -0
- package/bundle/node_modules/undici/lib/web/cookies/constants.js +12 -0
- package/bundle/node_modules/undici/lib/web/cookies/index.js +199 -0
- package/bundle/node_modules/undici/lib/web/cookies/parse.js +322 -0
- package/bundle/node_modules/undici/lib/web/cookies/util.js +282 -0
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +399 -0
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +484 -0
- package/bundle/node_modules/undici/lib/web/eventsource/util.js +37 -0
- package/bundle/node_modules/undici/lib/web/fetch/LICENSE +21 -0
- package/bundle/node_modules/undici/lib/web/fetch/body.js +532 -0
- package/bundle/node_modules/undici/lib/web/fetch/constants.js +131 -0
- package/bundle/node_modules/undici/lib/web/fetch/data-url.js +744 -0
- package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
- package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +501 -0
- package/bundle/node_modules/undici/lib/web/fetch/formdata.js +263 -0
- package/bundle/node_modules/undici/lib/web/fetch/global.js +40 -0
- package/bundle/node_modules/undici/lib/web/fetch/headers.js +719 -0
- package/bundle/node_modules/undici/lib/web/fetch/index.js +2258 -0
- package/bundle/node_modules/undici/lib/web/fetch/request.js +1099 -0
- package/bundle/node_modules/undici/lib/web/fetch/response.js +636 -0
- package/bundle/node_modules/undici/lib/web/fetch/util.js +1782 -0
- package/bundle/node_modules/undici/lib/web/fetch/webidl.js +740 -0
- package/bundle/node_modules/undici/lib/web/websocket/connection.js +325 -0
- package/bundle/node_modules/undici/lib/web/websocket/constants.js +126 -0
- package/bundle/node_modules/undici/lib/web/websocket/events.js +331 -0
- package/bundle/node_modules/undici/lib/web/websocket/frame.js +138 -0
- package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +70 -0
- package/bundle/node_modules/undici/lib/web/websocket/receiver.js +454 -0
- package/bundle/node_modules/undici/lib/web/websocket/sender.js +109 -0
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +83 -0
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +485 -0
- package/bundle/node_modules/undici/lib/web/websocket/util.js +338 -0
- package/bundle/node_modules/undici/lib/web/websocket/websocket.js +686 -0
- package/bundle/node_modules/undici/package.json +149 -0
- package/bundle/node_modules/undici/scripts/strip-comments.js +10 -0
- package/bundle/node_modules/undici/types/README.md +6 -0
- package/bundle/node_modules/undici/types/agent.d.ts +35 -0
- package/bundle/node_modules/undici/types/api.d.ts +43 -0
- package/bundle/node_modules/undici/types/balanced-pool.d.ts +29 -0
- package/bundle/node_modules/undici/types/cache-interceptor.d.ts +172 -0
- package/bundle/node_modules/undici/types/cache.d.ts +36 -0
- package/bundle/node_modules/undici/types/client-stats.d.ts +15 -0
- package/bundle/node_modules/undici/types/client.d.ts +110 -0
- package/bundle/node_modules/undici/types/connector.d.ts +34 -0
- package/bundle/node_modules/undici/types/content-type.d.ts +21 -0
- package/bundle/node_modules/undici/types/cookies.d.ts +30 -0
- package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +66 -0
- package/bundle/node_modules/undici/types/dispatcher.d.ts +281 -0
- package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +21 -0
- package/bundle/node_modules/undici/types/errors.d.ts +171 -0
- package/bundle/node_modules/undici/types/eventsource.d.ts +61 -0
- package/bundle/node_modules/undici/types/fetch.d.ts +210 -0
- package/bundle/node_modules/undici/types/formdata.d.ts +108 -0
- package/bundle/node_modules/undici/types/global-dispatcher.d.ts +9 -0
- package/bundle/node_modules/undici/types/global-origin.d.ts +7 -0
- package/bundle/node_modules/undici/types/h2c-client.d.ts +75 -0
- package/bundle/node_modules/undici/types/handlers.d.ts +15 -0
- package/bundle/node_modules/undici/types/header.d.ts +160 -0
- package/bundle/node_modules/undici/types/index.d.ts +75 -0
- package/bundle/node_modules/undici/types/interceptors.d.ts +34 -0
- package/bundle/node_modules/undici/types/mock-agent.d.ts +68 -0
- package/bundle/node_modules/undici/types/mock-call-history.d.ts +111 -0
- package/bundle/node_modules/undici/types/mock-client.d.ts +25 -0
- package/bundle/node_modules/undici/types/mock-errors.d.ts +12 -0
- package/bundle/node_modules/undici/types/mock-interceptor.d.ts +93 -0
- package/bundle/node_modules/undici/types/mock-pool.d.ts +25 -0
- package/bundle/node_modules/undici/types/patch.d.ts +29 -0
- package/bundle/node_modules/undici/types/pool-stats.d.ts +19 -0
- package/bundle/node_modules/undici/types/pool.d.ts +41 -0
- package/bundle/node_modules/undici/types/proxy-agent.d.ts +29 -0
- package/bundle/node_modules/undici/types/readable.d.ts +68 -0
- package/bundle/node_modules/undici/types/retry-agent.d.ts +8 -0
- package/bundle/node_modules/undici/types/retry-handler.d.ts +116 -0
- package/bundle/node_modules/undici/types/util.d.ts +18 -0
- package/bundle/node_modules/undici/types/utility.d.ts +7 -0
- package/bundle/node_modules/undici/types/webidl.d.ts +266 -0
- package/bundle/node_modules/undici/types/websocket.d.ts +184 -0
- package/bundle/sandbox-macos-permissive-closed.sb +26 -0
- package/bundle/sandbox-macos-permissive-open.sb +19 -0
- package/bundle/sandbox-macos-permissive-proxied.sb +31 -0
- package/bundle/sandbox-macos-restrictive-closed.sb +87 -0
- package/bundle/sandbox-macos-restrictive-open.sb +90 -0
- package/bundle/sandbox-macos-restrictive-proxied.sb +92 -0
- package/package.json +137 -0
|
@@ -0,0 +1,862 @@
|
|
|
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
|
+
}
|