(configureOptions)
| 59 | } |
| 60 | |
| 61 | export function makeUseAxios(configureOptions) { |
| 62 | /** |
| 63 | * @type {import('lru-cache')} |
| 64 | */ |
| 65 | let cache |
| 66 | let axiosInstance |
| 67 | let defaultOptions |
| 68 | |
| 69 | const __ssrPromises = [] |
| 70 | |
| 71 | function resetConfigure() { |
| 72 | cache = new LRUCache({ max: 500 }) |
| 73 | axiosInstance = StaticAxios |
| 74 | defaultOptions = DEFAULT_OPTIONS |
| 75 | } |
| 76 | |
| 77 | function configure(options = {}) { |
| 78 | if (options.axios !== undefined) { |
| 79 | axiosInstance = options.axios |
| 80 | } |
| 81 | |
| 82 | if (options.cache !== undefined) { |
| 83 | cache = options.cache |
| 84 | } |
| 85 | |
| 86 | if (options.defaultOptions !== undefined) { |
| 87 | defaultOptions = { ...DEFAULT_OPTIONS, ...options.defaultOptions } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | resetConfigure() |
| 92 | configure(configureOptions) |
| 93 | |
| 94 | function loadCache(data) { |
| 95 | cache.load(data) |
| 96 | } |
| 97 | |
| 98 | async function serializeCache() { |
| 99 | const ssrPromisesCopy = [...__ssrPromises] |
| 100 | |
| 101 | __ssrPromises.length = 0 |
| 102 | |
| 103 | await Promise.all(ssrPromisesCopy) |
| 104 | |
| 105 | return cache.dump() |
| 106 | } |
| 107 | |
| 108 | function clearCache() { |
| 109 | cache.clear() |
| 110 | } |
| 111 | |
| 112 | return Object.assign(useAxios, { |
| 113 | __ssrPromises, |
| 114 | resetConfigure, |
| 115 | configure, |
| 116 | loadCache, |
| 117 | serializeCache, |
| 118 | clearCache |
no test coverage detected
searching dependent graphs…