MCPcopy Index your code
hub / github.com/nodejs/node / #batchCacheOperations

Method #batchCacheOperations

deps/undici/src/lib/web/cache/cache.js:537–666  ·  view source on GitHub ↗

* @see https://w3c.github.io/ServiceWorker/#batch-cache-operations-algorithm * @param {CacheBatchOperation[]} operations * @returns {requestResponseList}

(operations)

Source from the content-addressed store, hash-verified

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 }

Callers 3

addAllMethod · 0.95
putMethod · 0.95
deleteMethod · 0.95

Calls 6

#queryCacheMethod · 0.95
exceptionMethod · 0.80
assertFunction · 0.50
urlIsHttpHttpsSchemeFunction · 0.50
indexOfMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected