{"version":3,"file":"cache.mjs","sources":["../../../lib/util/cache.js"],"sourcesContent":["'use strict'\n\nconst {\n  safeHTTPMethods,\n  pathHasQueryOrFragment,\n  hasSafeIterator,\n  isValidHTTPToken\n} = require('../core/util')\n\nconst { serializePathWithQuery } = require('../core/util')\n\nconst MAX_DELTA_SECONDS = 2147483647\nconst RESTRICTIVE_DIRECTIVE_NAMES = ['no-store', 'private', 'no-cache']\nconst kInvalidCacheControlDirectives = Symbol('invalid cache-control directives')\n\nfunction trimOWS (value) {\n  return value.replace(/^[\\t ]+|[\\t ]+$/g, '')\n}\n\nfunction arrayIncludes (array, value) {\n  for (let i = 0; i < array.length; i++) {\n    if (array[i] === value) {\n      return true\n    }\n  }\n\n  return false\n}\n\nfunction trimOWSStart (value) {\n  return value.replace(/^[\\t ]+/, '')\n}\n\nfunction trimOWSEnd (value) {\n  return value.replace(/[\\t ]+$/, '')\n}\n\nfunction findUnescapedQuote (value, start) {\n  let escaped = false\n  for (let i = start; i < value.length; i++) {\n    if (escaped) {\n      escaped = false\n    } else if (value[i] === '\\\\') {\n      escaped = true\n    } else if (value[i] === '\"') {\n      return i\n    }\n  }\n\n  return -1\n}\n\nfunction splitCacheControlHeaderValue (value) {\n  const directives = []\n  let start = 0\n  let quoteStart = -1\n  let inQuote = false\n  let escaped = false\n\n  for (let i = 0; i < value.length; i++) {\n    if (inQuote) {\n      if (escaped) {\n        escaped = false\n      } else if (value[i] === '\\\\') {\n        escaped = true\n      } else if (value[i] === '\"') {\n        inQuote = false\n        quoteStart = -1\n      }\n    } else if (value[i] === '\"') {\n      inQuote = true\n      quoteStart = i\n    } else if (value[i] === ',') {\n      directives.push({ value: value.substring(start, i), fromMalformedQuote: false })\n      start = i + 1\n    }\n  }\n\n  if (!inQuote) {\n    directives.push({ value: value.substring(start), fromMalformedQuote: false })\n    return directives\n  }\n\n  const tail = value.substring(start)\n  const quoteOffset = quoteStart - start\n  let tailStart = 0\n  for (let i = 0; i < tail.length; i++) {\n    if (tail[i] === ',') {\n      directives.push({\n        value: tail.substring(tailStart, i),\n        fromMalformedQuote: tailStart > quoteOffset\n      })\n      tailStart = i + 1\n    }\n  }\n\n  directives.push({\n    value: tail.substring(tailStart),\n    fromMalformedQuote: tailStart > quoteOffset\n  })\n  return directives\n}\n\nfunction markInvalidCacheControlDirective (directives, key) {\n  let invalidDirectives = directives[kInvalidCacheControlDirectives]\n\n  if (invalidDirectives === undefined) {\n    invalidDirectives = new Set()\n    Object.defineProperty(directives, kInvalidCacheControlDirectives, {\n      value: invalidDirectives\n    })\n  }\n\n  invalidDirectives.add(key)\n}\n\nfunction hasInvalidCacheControlDirective (directives, key) {\n  return directives[kInvalidCacheControlDirectives]?.has(key) === true\n}\n\nfunction getMalformedRestrictiveDirectiveName (key) {\n  for (const directiveName of RESTRICTIVE_DIRECTIVE_NAMES) {\n    if (\n      key.startsWith(directiveName) &&\n      key.length > directiveName.length &&\n      !isValidHTTPToken(key[directiveName.length])\n    ) {\n      return directiveName\n    }\n  }\n\n  let tokenOnlyKey = ''\n  let hasInvalidTokenChar = false\n  for (let i = 0; i < key.length; i++) {\n    if (isValidHTTPToken(key[i])) {\n      tokenOnlyKey += key[i]\n    } else {\n      hasInvalidTokenChar = true\n    }\n  }\n\n  if (hasInvalidTokenChar && arrayIncludes(RESTRICTIVE_DIRECTIVE_NAMES, tokenOnlyKey)) {\n    return tokenOnlyKey\n  }\n}\n\n/**\n * @param {import('../../types/dispatcher.d.ts').default.DispatchOptions} opts\n */\nfunction makeCacheKey (opts) {\n  const origin = opts.origin ? opts.origin.toString() : ''\n\n  let fullPath = opts.path || '/'\n\n  if (opts.query && !pathHasQueryOrFragment(fullPath)) {\n    fullPath = serializePathWithQuery(fullPath, opts.query)\n  }\n\n  return {\n    origin,\n    method: opts.method,\n    path: fullPath,\n    headers: opts.headers\n  }\n}\n\nfunction appendHeader (headers, key, val) {\n  const headerName = key.toLowerCase()\n  const current = headers[headerName]\n  const values = Array.isArray(val) ? val : [val]\n\n  if (current === undefined) {\n    headers[headerName] = Array.isArray(val) ? val.slice() : val\n  } else if (Array.isArray(current)) {\n    current.push(...values)\n  } else {\n    headers[headerName] = [current, ...values]\n  }\n}\n\n/**\n * @param {Record<string, string[] | string>}\n * @returns {Record<string, string[] | string>}\n */\nfunction normalizeHeaders (opts) {\n  let headers\n  if (opts.headers == null) {\n    headers = {}\n  } else if (typeof opts.headers === 'object') {\n    headers = {}\n\n    if (hasSafeIterator(opts.headers)) {\n      if (Array.isArray(opts.headers)) {\n        // Array format: could be flat alternating [k, v, k, v, ...]\n        // or array-of-pairs [[k, v], ...]\n        const first = opts.headers[0]\n        if (Array.isArray(first)) {\n          for (const x of opts.headers) {\n            if (!Array.isArray(x)) {\n              throw new Error('opts.headers is not a valid header map')\n            }\n            const [key, val] = x\n            if (typeof key !== 'string' || typeof val !== 'string') {\n              throw new Error('opts.headers is not a valid header map')\n            }\n            appendHeader(headers, key, val)\n          }\n        } else {\n          // Flat alternating array [k, v, k, v, ...]\n          const len = opts.headers.length\n          if (len % 2 !== 0) {\n            throw new Error('opts.headers is not a valid header map')\n          }\n          for (let i = 0; i < len; i += 2) {\n            const key = opts.headers[i]\n            const val = opts.headers[i + 1]\n            if (typeof key !== 'string' || (typeof val !== 'string' && !Array.isArray(val))) {\n              throw new Error('opts.headers is not a valid header map')\n            }\n            if (typeof val === 'string') {\n              appendHeader(headers, key, val)\n            } else {\n              const mapped = []\n              for (let j = 0; j < val.length; j++) {\n                const v = val[j]\n                mapped.push(typeof v === 'string' ? v : v.toString('latin1'))\n              }\n              appendHeader(headers, key, mapped)\n            }\n          }\n        }\n      } else {\n        // Non-array iterable (e.g. Map) — use original iteration logic\n        for (const x of opts.headers) {\n          if (!Array.isArray(x)) {\n            throw new Error('opts.headers is not a valid header map')\n          }\n          const [key, val] = x\n          if (typeof key !== 'string' || typeof val !== 'string') {\n            throw new Error('opts.headers is not a valid header map')\n          }\n          appendHeader(headers, key, val)\n        }\n      }\n    } else {\n      for (const key of Object.keys(opts.headers)) {\n        appendHeader(headers, key, opts.headers[key])\n      }\n    }\n  } else {\n    throw new Error('opts.headers is not an object')\n  }\n\n  return headers\n}\n\n/**\n * @param {any} key\n */\nfunction assertCacheKey (key) {\n  if (typeof key !== 'object') {\n    throw new TypeError(`expected key to be object, got ${typeof key}`)\n  }\n\n  for (const property of ['origin', 'method', 'path']) {\n    if (typeof key[property] !== 'string') {\n      throw new TypeError(`expected key.${property} to be string, got ${typeof key[property]}`)\n    }\n  }\n\n  if (key.headers !== undefined && typeof key.headers !== 'object') {\n    throw new TypeError(`expected headers to be object, got ${typeof key}`)\n  }\n}\n\n/**\n * @param {any} value\n */\nfunction assertCacheValue (value) {\n  if (typeof value !== 'object') {\n    throw new TypeError(`expected value to be object, got ${typeof value}`)\n  }\n\n  for (const property of ['statusCode', 'cachedAt', 'staleAt', 'deleteAt']) {\n    if (typeof value[property] !== 'number') {\n      throw new TypeError(`expected value.${property} to be number, got ${typeof value[property]}`)\n    }\n  }\n\n  if (typeof value.statusMessage !== 'string') {\n    throw new TypeError(`expected value.statusMessage to be string, got ${typeof value.statusMessage}`)\n  }\n\n  if (value.headers != null && typeof value.headers !== 'object') {\n    throw new TypeError(`expected value.rawHeaders to be object, got ${typeof value.headers}`)\n  }\n\n  if (value.vary !== undefined && typeof value.vary !== 'object') {\n    throw new TypeError(`expected value.vary to be object, got ${typeof value.vary}`)\n  }\n\n  if (value.etag !== undefined && typeof value.etag !== 'string') {\n    throw new TypeError(`expected value.etag to be string, got ${typeof value.etag}`)\n  }\n}\n\n/**\n * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-cache-control\n * @see https://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml\n\n * @param {string | string[]} header\n * @returns {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives}\n */\nfunction parseCacheControlHeader (header) {\n  /**\n   * @type {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives}\n   */\n  const output = {}\n  const invalidNumericDirectives = new Set()\n  const invalidNoArgumentDirectives = new Set()\n\n  const directives = splitCacheControlHeaderValue(Array.isArray(header) ? header.join(',') : header)\n\n  for (let i = 0; i < directives.length; i++) {\n    const directiveRecord = directives[i]\n    const directive = directiveRecord.value.toLowerCase()\n    const fromMalformedQuote = directiveRecord.fromMalformedQuote\n    const keyValueDelimiter = directive.indexOf('=')\n\n    let key\n    let value\n    let keyHasTrailingWhitespace = false\n    let valueHasLeadingWhitespace = false\n    if (keyValueDelimiter !== -1) {\n      const rawKey = directive.substring(0, keyValueDelimiter)\n      const rawValue = directive.substring(keyValueDelimiter + 1)\n\n      keyHasTrailingWhitespace = trimOWSEnd(rawKey) !== rawKey\n      valueHasLeadingWhitespace = trimOWSStart(rawValue) !== rawValue\n      key = trimOWS(rawKey)\n      value = trimOWSStart(rawValue)\n    } else {\n      key = trimOWS(directive)\n    }\n\n    const malformedRestrictiveDirectiveName = getMalformedRestrictiveDirectiveName(key)\n    if (malformedRestrictiveDirectiveName !== undefined) {\n      output[malformedRestrictiveDirectiveName] = true\n      continue\n    }\n\n    switch (key) {\n      case 'min-fresh':\n      case 'max-stale':\n      case 'max-age':\n      case 's-maxage':\n      case 'stale-while-revalidate':\n      case 'stale-if-error': {\n        if (fromMalformedQuote || invalidNumericDirectives.has(key)) {\n          continue\n        }\n\n        if (value === undefined || keyHasTrailingWhitespace || valueHasLeadingWhitespace) {\n          delete output[key]\n          invalidNumericDirectives.add(key)\n          markInvalidCacheControlDirective(output, key)\n          continue\n        }\n\n        if (\n          value.length >= 2 &&\n          value[0] === '\"' &&\n          value[value.length - 1] === '\"'\n        ) {\n          value = value.substring(1, value.length - 1)\n        }\n\n        if (!/^[0-9]+$/.test(value)) {\n          delete output[key]\n          invalidNumericDirectives.add(key)\n          markInvalidCacheControlDirective(output, key)\n          continue\n        }\n\n        const parsedValue = Math.min(parseInt(value, 10), MAX_DELTA_SECONDS)\n\n        if (key === 'min-fresh') {\n          if (!(key in output) || output[key] < parsedValue) {\n            output[key] = parsedValue\n          }\n        } else if (!(key in output) || output[key] > parsedValue) {\n          output[key] = parsedValue\n        }\n\n        break\n      }\n      case 'private':\n      case 'no-cache': {\n        if (fromMalformedQuote) {\n          output[key] = true\n          break\n        }\n\n        if (value !== undefined && value.length === 0) {\n          output[key] = true\n          break\n        }\n\n        if (value) {\n          // The private and no-cache directives can be unqualified (aka just\n          //  `private` or `no-cache`) or qualified (w/ a value). When they're\n          //  qualified, it's a list of headers like `no-cache=header1`,\n          //  `no-cache=\"header1\"`, or `no-cache=\"header1, header2\"`\n          // If we're given multiple headers, the comma messes us up since\n          //  we split the full header by commas. So, let's loop through the\n          //  remaining parts in front of us until we find one that contains a\n          //  closing quote. We can then skip the consumed quoted-list fragments and\n          //  continue parsing like normal.\n          // https://www.rfc-editor.org/rfc/rfc9111.html#name-no-cache-2\n          if (value[0] === '\"') {\n            // Something like `no-cache=\"some-header\"` OR `no-cache=\"some-header, another-header\"`.\n            value = trimOWSEnd(value)\n\n            let fieldList = ''\n            let lastQuotedPart = i\n            let foundEndingQuote = false\n            const closingQuote = findUnescapedQuote(value, 1)\n\n            if (closingQuote !== -1) {\n              fieldList = value.substring(1, closingQuote)\n              foundEndingQuote = true\n            } else {\n              // Something like `no-cache=\"some-header, another-header\"`\n              //  This can still be something invalid, e.g. `no-cache=\"some-header, ...`\n              const fieldListParts = [value.substring(1)]\n\n              for (let j = i + 1; j < directives.length; j++) {\n                const nextPart = trimOWS(directives[j].value)\n                const closingQuote = findUnescapedQuote(nextPart, 0)\n\n                lastQuotedPart = j\n\n                if (closingQuote !== -1) {\n                  fieldListParts.push(nextPart.substring(0, closingQuote))\n                  foundEndingQuote = true\n                  break\n                }\n\n                fieldListParts.push(nextPart)\n              }\n\n              fieldList = fieldListParts.join(',')\n            }\n\n            if (!foundEndingQuote) {\n              output[key] = true\n              break\n            }\n\n            i = lastQuotedPart\n\n            const headers = fieldList.split(',')\n            let validFieldNames = true\n            for (let j = 0; j < headers.length; j++) {\n              headers[j] = trimOWS(headers[j])\n              if (!isValidHTTPToken(headers[j])) {\n                validFieldNames = false\n              }\n            }\n\n            if (!validFieldNames) {\n              output[key] = true\n            } else if (output[key] !== true) {\n              if (key in output) {\n                output[key] = output[key].concat(headers)\n              } else {\n                output[key] = headers\n              }\n            }\n          } else {\n            // Something like `no-cache=some-header`\n            const fieldName = trimOWS(value)\n\n            if (!isValidHTTPToken(fieldName)) {\n              output[key] = true\n            } else if (output[key] !== true) {\n              if (key in output) {\n                output[key] = output[key].concat(fieldName)\n              } else {\n                output[key] = [fieldName]\n              }\n            }\n          }\n\n          break\n        }\n      }\n      // eslint-disable-next-line no-fallthrough\n      case 'public':\n      case 'must-revalidate':\n      case 'proxy-revalidate':\n      case 'immutable':\n      case 'no-transform':\n      case 'must-understand':\n      case 'only-if-cached':\n        if (fromMalformedQuote || invalidNoArgumentDirectives.has(key)) {\n          continue\n        }\n\n        if (value !== undefined) {\n          // These are qualified (something like `public=...`) when they aren't\n          //  allowed to be, skip all instances of the malformed directive.\n          delete output[key]\n          invalidNoArgumentDirectives.add(key)\n          continue\n        }\n\n        output[key] = true\n        break\n      case 'no-store':\n        output[key] = true\n        break\n      default:\n        // Ignore unknown directives as per https://www.rfc-editor.org/rfc/rfc9111.html#section-5.2.3-1\n        continue\n    }\n  }\n\n  return output\n}\n\n/**\n * @param {string | string[]} varyHeader Vary header from the server\n * @returns {string[]}\n */\nfunction splitVaryHeader (varyHeader) {\n  const values = Array.isArray(varyHeader) ? varyHeader : [varyHeader]\n  const output = []\n\n  for (let i = 0; i < values.length; i++) {\n    const parts = values[i].split(',')\n    for (let j = 0; j < parts.length; j++) {\n      output.push(parts[j])\n    }\n  }\n\n  return output\n}\n\n/**\n * @param {string | string[]} varyHeader Vary header from the server\n * @returns {boolean}\n */\nfunction hasVaryStar (varyHeader) {\n  const values = splitVaryHeader(varyHeader)\n  for (let i = 0; i < values.length; i++) {\n    if (trimOWS(values[i]).indexOf('*') !== -1) {\n      return true\n    }\n  }\n\n  return false\n}\n\n/**\n * @param {string | string[]} varyHeader Vary header from the server\n * @param {Record<string, string | string[]>} headers Request headers\n * @returns {Record<string, string | string[] | null> | undefined}\n */\nfunction parseVaryHeader (varyHeader, headers) {\n  if (hasVaryStar(varyHeader)) {\n    return headers\n  }\n\n  const output = /** @type {Record<string, string | string[] | null>} */ ({})\n\n  const varyingHeaders = splitVaryHeader(varyHeader)\n\n  for (const header of varyingHeaders) {\n    const trimmedHeader = trimOWS(header).toLowerCase()\n\n    if (trimmedHeader.length === 0) {\n      continue\n    }\n\n    if (!isValidHTTPToken(trimmedHeader)) {\n      return undefined\n    }\n\n    const headerValue = headers[trimmedHeader]\n    output[trimmedHeader] = Array.isArray(headerValue) ? headerValue.slice() : headerValue ?? null\n  }\n\n  return output\n}\n\n/**\n * @param {string | string[]} varyHeader Vary header from the server\n * @returns {boolean}\n */\nfunction isInvalidOrWildcardVaryHeader (varyHeader) {\n  return hasVaryStar(varyHeader) || parseVaryHeader(varyHeader, {}) === undefined\n}\n\n/**\n * Note: this deviates from the spec a little. Empty etags (\"\", W/\"\") are valid,\n *  however, including them in cached resposnes serves little to no purpose.\n *\n * @see https://www.rfc-editor.org/rfc/rfc9110.html#name-etag\n *\n * @param {string} etag\n * @returns {boolean}\n */\nfunction isEtagUsable (etag) {\n  if (etag.length <= 2) {\n    // Shortest an etag can be is two chars (just \"\"). This is where we deviate\n    //  from the spec requiring a min of 3 chars however\n    return false\n  }\n\n  if (etag[0] === '\"' && etag[etag.length - 1] === '\"') {\n    // ETag: \"\"asd123\"\" or ETag: \"W/\"asd123\"\", kinda undefined behavior in the\n    //  spec. Some servers will accept these while others don't.\n    // ETag: \"asd123\"\n    return !(etag[1] === '\"' || etag.startsWith('\"W/'))\n  }\n\n  if (etag.startsWith('W/\"') && etag[etag.length - 1] === '\"') {\n    // ETag: W/\"\", also where we deviate from the spec & require a min of 3\n    //  chars\n    // ETag: for W/\"\", W/\"asd123\"\n    return etag.length !== 4\n  }\n\n  // Anything else\n  return false\n}\n\n/**\n * @param {unknown} store\n * @returns {asserts store is import('../../types/cache-interceptor.d.ts').default.CacheStore}\n */\nfunction assertCacheStore (store, name = 'CacheStore') {\n  if (typeof store !== 'object' || store === null) {\n    throw new TypeError(`expected type of ${name} to be a CacheStore, got ${store === null ? 'null' : typeof store}`)\n  }\n\n  for (const fn of ['get', 'createWriteStream', 'delete']) {\n    if (typeof store[fn] !== 'function') {\n      throw new TypeError(`${name} needs to have a \\`${fn}()\\` function`)\n    }\n  }\n}\n/**\n * @param {unknown} methods\n * @returns {asserts methods is import('../../types/cache-interceptor.d.ts').default.CacheMethods[]}\n */\nfunction assertCacheMethods (methods, name = 'CacheMethods') {\n  if (!Array.isArray(methods)) {\n    throw new TypeError(`expected type of ${name} needs to be an array, got ${methods === null ? 'null' : typeof methods}`)\n  }\n\n  if (methods.length === 0) {\n    throw new TypeError(`${name} needs to have at least one method`)\n  }\n\n  for (const method of methods) {\n    if (!arrayIncludes(safeHTTPMethods, method)) {\n      throw new TypeError(`element of ${name}-array needs to be one of following values: ${safeHTTPMethods.join(', ')}, got ${method}`)\n    }\n  }\n}\n\n/**\n * Creates a string key for request deduplication purposes.\n * This key is used to identify in-flight requests that can be shared.\n * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} cacheKey\n * @param {Set<string>} [excludeHeaders] Set of lowercase header names to exclude from the key\n * @returns {string}\n */\nfunction makeDeduplicationKey (cacheKey, excludeHeaders) {\n  // Use JSON.stringify to produce a collision-resistant key.\n  // Previous format used `:` and `=` delimiters without escaping, which\n  // allowed different header sets to produce identical keys (e.g.\n  // {a:\"x:b=y\"} vs {a:\"x\", b:\"y\"}). See: https://github.com/nodejs/undici/issues/5012\n  const headers = {}\n\n  if (cacheKey.headers) {\n    const sortedHeaders = Object.keys(cacheKey.headers).sort()\n    for (const header of sortedHeaders) {\n      // Skip excluded headers\n      if (excludeHeaders?.has(header.toLowerCase())) {\n        continue\n      }\n      headers[header] = cacheKey.headers[header]\n    }\n  }\n\n  return JSON.stringify([cacheKey.origin, cacheKey.method, cacheKey.path, headers])\n}\n\nmodule.exports = {\n  makeCacheKey,\n  normalizeHeaders,\n  assertCacheKey,\n  assertCacheValue,\n  parseCacheControlHeader,\n  hasInvalidCacheControlDirective,\n  parseVaryHeader,\n  hasVaryStar,\n  isInvalidOrWildcardVaryHeader,\n  isEtagUsable,\n  assertCacheMethods,\n  assertCacheStore,\n  makeDeduplicationKey\n}\n"],"names":["safeHTTPMethods","pathHasQueryOrFragment","hasSafeIterator","isValidHTTPToken","require$$0","serializePathWithQuery","RESTRICTIVE_DIRECTIVE_NAMES","kInvalidCacheControlDirectives","Symbol","trimOWS","value","replace","arrayIncludes","array","i","length","trimOWSStart","trimOWSEnd","findUnescapedQuote","start","escaped","markInvalidCacheControlDirective","directives","key","invalidDirectives","undefined","Set","Object","defineProperty","add","getMalformedRestrictiveDirectiveName","directiveName","startsWith","tokenOnlyKey","hasInvalidTokenChar","appendHeader","headers","val","headerName","toLowerCase","current","values","Array","isArray","slice","push","splitVaryHeader","varyHeader","output","parts","split","j","hasVaryStar","indexOf","parseVaryHeader","varyingHeaders","header","trimmedHeader","headerValue","cache","makeCacheKey","opts","origin","toString","fullPath","path","query","method","normalizeHeaders","Error","first","x","len","mapped","v","keys","assertCacheKey","TypeError","property","assertCacheValue","statusMessage","vary","etag","parseCacheControlHeader","invalidNumericDirectives","invalidNoArgumentDirectives","quoteStart","inQuote","substring","fromMalformedQuote","tail","quoteOffset","tailStart","splitCacheControlHeaderValue","join","directiveRecord","directive","keyValueDelimiter","keyHasTrailingWhitespace","valueHasLeadingWhitespace","rawKey","rawValue","malformedRestrictiveDirectiveName","has","test","parsedValue","Math","min","parseInt","fieldList","lastQuotedPart","foundEndingQuote","closingQuote","fieldListParts","nextPart","validFieldNames","concat","fieldName","hasInvalidCacheControlDirective","isInvalidOrWildcardVaryHeader","isEtagUsable","assertCacheMethods","methods","name","assertCacheStore","store","fn","makeDeduplicationKey","cacheKey","excludeHeaders","sortedHeaders","sort","JSON","stringify"],"m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