mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
feat: pinned dependencies
This commit is contained in:
parent
ed142c6ca2
commit
8d03709482
@ -1,10 +1,6 @@
|
||||
//@ts-check
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
const path = require('path');
|
||||
const TerserWebpackPlugin = require('terser-webpack-plugin');
|
||||
const { DefinePlugin } = require('webpack');
|
||||
|
||||
const { version } = require('../package.json');
|
||||
|
||||
const COPYRIGHT = `
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint-disable */
|
||||
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint-disable */
|
||||
|
||||
const { create: createAxios } = require('axios').default;
|
||||
const { setupCache } = require('axios-cache-interceptor');
|
||||
const { log } = console;
|
||||
|
||||
38
package.json
38
package.json
@ -56,28 +56,28 @@
|
||||
"colors": "1.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"cache-parser": "^1.2.4",
|
||||
"fast-defer": "^1.1.7",
|
||||
"object-code": "^1.3.0"
|
||||
"cache-parser": "1.2.4",
|
||||
"fast-defer": "1.1.8",
|
||||
"object-code": "1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^1.3.3",
|
||||
"@swc-node/register": "^1.6.8",
|
||||
"@swc/helpers": "^0.5.3",
|
||||
"@types/jsdom": "^21.1.2",
|
||||
"@types/node": "^20.5.0",
|
||||
"@types/webpack": "^5.28.1",
|
||||
"auto-changelog": "^2.4.0",
|
||||
"axios": "^1.4.0",
|
||||
"c8": "^8.0.1",
|
||||
"es-check": "^7.1.1",
|
||||
"jsdom": "^23.0.1",
|
||||
"ts-loader": "^9.4.3",
|
||||
"tslib": "^2.5.3",
|
||||
"typescript": "^5.1.3",
|
||||
"@biomejs/biome": "1.4.1",
|
||||
"@swc-node/register": "1.6.8",
|
||||
"@swc/helpers": "0.5.3",
|
||||
"@types/jsdom": "21.1.6",
|
||||
"@types/node": "20.10.4",
|
||||
"@types/webpack": "5.28.5",
|
||||
"auto-changelog": "2.4.0",
|
||||
"axios": "1.6.2",
|
||||
"c8": "8.0.1",
|
||||
"es-check": "7.1.1",
|
||||
"jsdom": "23.0.1",
|
||||
"ts-loader": "9.5.1",
|
||||
"tslib": "2.6.2",
|
||||
"typescript": "5.3.3",
|
||||
"vitepress": "1.0.0-rc.31",
|
||||
"webpack": "^5.86.0",
|
||||
"webpack-cli": "^5.1.4"
|
||||
"webpack": "5.89.0",
|
||||
"webpack-cli": "5.1.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"axios": "^1"
|
||||
|
||||
87
pnpm-lock.yaml
generated
87
pnpm-lock.yaml
generated
@ -9,66 +9,66 @@ overrides:
|
||||
|
||||
dependencies:
|
||||
cache-parser:
|
||||
specifier: ^1.2.4
|
||||
specifier: 1.2.4
|
||||
version: 1.2.4
|
||||
fast-defer:
|
||||
specifier: ^1.1.7
|
||||
specifier: 1.1.8
|
||||
version: 1.1.8
|
||||
object-code:
|
||||
specifier: ^1.3.0
|
||||
specifier: 1.3.0
|
||||
version: 1.3.0
|
||||
|
||||
devDependencies:
|
||||
'@biomejs/biome':
|
||||
specifier: ^1.3.3
|
||||
specifier: 1.4.1
|
||||
version: 1.4.1
|
||||
'@swc-node/register':
|
||||
specifier: ^1.6.8
|
||||
specifier: 1.6.8
|
||||
version: 1.6.8(@swc/core@1.3.96)(typescript@5.3.3)
|
||||
'@swc/helpers':
|
||||
specifier: ^0.5.3
|
||||
specifier: 0.5.3
|
||||
version: 0.5.3
|
||||
'@types/jsdom':
|
||||
specifier: ^21.1.2
|
||||
specifier: 21.1.6
|
||||
version: 21.1.6
|
||||
'@types/node':
|
||||
specifier: ^20.5.0
|
||||
version: 20.5.0
|
||||
specifier: 20.10.4
|
||||
version: 20.10.4
|
||||
'@types/webpack':
|
||||
specifier: ^5.28.1
|
||||
specifier: 5.28.5
|
||||
version: 5.28.5(@swc/core@1.3.96)(webpack-cli@5.1.4)
|
||||
auto-changelog:
|
||||
specifier: ^2.4.0
|
||||
specifier: 2.4.0
|
||||
version: 2.4.0
|
||||
axios:
|
||||
specifier: ^1.4.0
|
||||
specifier: 1.6.2
|
||||
version: 1.6.2
|
||||
c8:
|
||||
specifier: ^8.0.1
|
||||
specifier: 8.0.1
|
||||
version: 8.0.1
|
||||
es-check:
|
||||
specifier: ^7.1.1
|
||||
specifier: 7.1.1
|
||||
version: 7.1.1
|
||||
jsdom:
|
||||
specifier: ^23.0.1
|
||||
specifier: 23.0.1
|
||||
version: 23.0.1
|
||||
ts-loader:
|
||||
specifier: ^9.4.3
|
||||
specifier: 9.5.1
|
||||
version: 9.5.1(typescript@5.3.3)(webpack@5.89.0)
|
||||
tslib:
|
||||
specifier: ^2.5.3
|
||||
specifier: 2.6.2
|
||||
version: 2.6.2
|
||||
typescript:
|
||||
specifier: ^5.1.3
|
||||
specifier: 5.3.3
|
||||
version: 5.3.3
|
||||
vitepress:
|
||||
specifier: 1.0.0-rc.31
|
||||
version: 1.0.0-rc.31(@algolia/client-search@4.19.1)(@types/node@20.5.0)(axios@1.6.2)(search-insights@2.6.0)(typescript@5.3.3)
|
||||
version: 1.0.0-rc.31(@algolia/client-search@4.19.1)(@types/node@20.10.4)(axios@1.6.2)(search-insights@2.6.0)(typescript@5.3.3)
|
||||
webpack:
|
||||
specifier: ^5.86.0
|
||||
specifier: 5.89.0
|
||||
version: 5.89.0(@swc/core@1.3.96)(webpack-cli@5.1.4)
|
||||
webpack-cli:
|
||||
specifier: ^5.1.4
|
||||
specifier: 5.1.4
|
||||
version: 5.1.4(webpack@5.89.0)
|
||||
|
||||
packages:
|
||||
@ -923,7 +923,7 @@ packages:
|
||||
/@types/jsdom@21.1.6:
|
||||
resolution: {integrity: sha512-/7kkMsC+/kMs7gAYmmBR9P0vGTnOoLhQhyhQJSlXGI5bzTHp6xdo0TtKWQAsz6pmSAeVqKSbqeyP6hytqr9FDw==}
|
||||
dependencies:
|
||||
'@types/node': 20.5.0
|
||||
'@types/node': 20.10.4
|
||||
'@types/tough-cookie': 4.0.2
|
||||
parse5: 7.1.2
|
||||
dev: true
|
||||
@ -953,8 +953,10 @@ packages:
|
||||
resolution: {integrity: sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==}
|
||||
dev: true
|
||||
|
||||
/@types/node@20.5.0:
|
||||
resolution: {integrity: sha512-Mgq7eCtoTjT89FqNoTzzXg2XvCi5VMhRV6+I2aYanc6kQCBImeNaAYRs/DyoVqk1YEUJK5gN9VO7HRIdz4Wo3Q==}
|
||||
/@types/node@20.10.4:
|
||||
resolution: {integrity: sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==}
|
||||
dependencies:
|
||||
undici-types: 5.26.5
|
||||
dev: true
|
||||
|
||||
/@types/tough-cookie@4.0.2:
|
||||
@ -976,7 +978,7 @@ packages:
|
||||
/@types/webpack@5.28.5(@swc/core@1.3.96)(webpack-cli@5.1.4):
|
||||
resolution: {integrity: sha512-wR87cgvxj3p6D0Crt1r5avwqffqPXUkNlnQ1mjU93G7gCuFjufZR4I6j8cz5g1F1tTYpfOOFvly+cmIQwL9wvw==}
|
||||
dependencies:
|
||||
'@types/node': 20.5.0
|
||||
'@types/node': 20.10.4
|
||||
tapable: 2.2.1
|
||||
webpack: 5.89.0(@swc/core@1.3.96)(webpack-cli@5.1.4)
|
||||
transitivePeerDependencies:
|
||||
@ -997,7 +999,7 @@ packages:
|
||||
vite: ^4.0.0 || ^5.0.0
|
||||
vue: ^3.2.25
|
||||
dependencies:
|
||||
vite: 5.0.5(@types/node@20.5.0)
|
||||
vite: 5.0.5(@types/node@20.10.4)
|
||||
vue: 3.3.8(typescript@5.3.3)
|
||||
dev: true
|
||||
|
||||
@ -1409,7 +1411,7 @@ packages:
|
||||
handlebars: 4.7.7
|
||||
node-fetch: 2.6.11
|
||||
parse-github-url: 1.0.2
|
||||
semver: 7.5.1
|
||||
semver: 7.5.4
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
dev: true
|
||||
@ -2189,7 +2191,7 @@ packages:
|
||||
resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==}
|
||||
engines: {node: '>= 10.13.0'}
|
||||
dependencies:
|
||||
'@types/node': 20.5.0
|
||||
'@types/node': 20.10.4
|
||||
merge-stream: 2.0.0
|
||||
supports-color: 8.1.1
|
||||
dev: true
|
||||
@ -2569,11 +2571,6 @@ packages:
|
||||
resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==}
|
||||
dev: true
|
||||
|
||||
/punycode@2.3.0:
|
||||
resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/punycode@2.3.1:
|
||||
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
||||
engines: {node: '>=6'}
|
||||
@ -2715,14 +2712,6 @@ packages:
|
||||
engines: {node: '>=8.16.0'}
|
||||
dev: true
|
||||
|
||||
/semver@7.5.1:
|
||||
resolution: {integrity: sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==}
|
||||
engines: {node: '>=10'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
lru-cache: 6.0.0
|
||||
dev: true
|
||||
|
||||
/semver@7.5.4:
|
||||
resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==}
|
||||
engines: {node: '>=10'}
|
||||
@ -2935,7 +2924,7 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dependencies:
|
||||
psl: 1.9.0
|
||||
punycode: 2.3.0
|
||||
punycode: 2.3.1
|
||||
universalify: 0.2.0
|
||||
url-parse: 1.5.10
|
||||
dev: true
|
||||
@ -2993,6 +2982,10 @@ packages:
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/undici-types@5.26.5:
|
||||
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
||||
dev: true
|
||||
|
||||
/unist-util-is@6.0.0:
|
||||
resolution: {integrity: sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==}
|
||||
dependencies:
|
||||
@ -3045,7 +3038,7 @@ packages:
|
||||
/uri-js@4.4.1:
|
||||
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
||||
dependencies:
|
||||
punycode: 2.3.0
|
||||
punycode: 2.3.1
|
||||
dev: true
|
||||
|
||||
/url-parse@1.5.10:
|
||||
@ -3090,7 +3083,7 @@ packages:
|
||||
vfile-message: 4.0.2
|
||||
dev: true
|
||||
|
||||
/vite@5.0.5(@types/node@20.5.0):
|
||||
/vite@5.0.5(@types/node@20.10.4):
|
||||
resolution: {integrity: sha512-OekeWqR9Ls56f3zd4CaxzbbS11gqYkEiBtnWFFgYR2WV8oPJRRKq0mpskYy/XaoCL3L7VINDhqqOMNDiYdGvGg==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
hasBin: true
|
||||
@ -3118,7 +3111,7 @@ packages:
|
||||
terser:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/node': 20.5.0
|
||||
'@types/node': 20.10.4
|
||||
esbuild: 0.19.5
|
||||
postcss: 8.4.32
|
||||
rollup: 4.4.1
|
||||
@ -3126,7 +3119,7 @@ packages:
|
||||
fsevents: 2.3.3
|
||||
dev: true
|
||||
|
||||
/vitepress@1.0.0-rc.31(@algolia/client-search@4.19.1)(@types/node@20.5.0)(axios@1.6.2)(search-insights@2.6.0)(typescript@5.3.3):
|
||||
/vitepress@1.0.0-rc.31(@algolia/client-search@4.19.1)(@types/node@20.10.4)(axios@1.6.2)(search-insights@2.6.0)(typescript@5.3.3):
|
||||
resolution: {integrity: sha512-ikH9pIjOOAbyoYAGBVfTz8TzuXp+UoWaIRMU4bw/oiTg8R65SbAaGKY84xx6TuL+f4VqUJ8lhzW82YyxSLvstA==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
@ -3151,7 +3144,7 @@ packages:
|
||||
mrmime: 1.0.1
|
||||
shikiji: 0.7.4
|
||||
shikiji-transformers: 0.7.4
|
||||
vite: 5.0.5(@types/node@20.5.0)
|
||||
vite: 5.0.5(@types/node@20.10.4)
|
||||
vue: 3.3.8(typescript@5.3.3)
|
||||
transitivePeerDependencies:
|
||||
- '@algolia/client-search'
|
||||
|
||||
1
src/cache/axios.ts
vendored
1
src/cache/axios.ts
vendored
@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import type {
|
||||
AxiosInstance,
|
||||
AxiosInterceptorManager,
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
import { deferred } from 'fast-defer';
|
||||
import type { AxiosCacheInstance, CacheAxiosResponse } from '../cache/axios';
|
||||
import { Header } from '../header/headers';
|
||||
import type { CachedResponse, CachedStorageValue, LoadingStorageValue } from '../storage/types';
|
||||
import type {
|
||||
CachedResponse,
|
||||
CachedStorageValue,
|
||||
LoadingStorageValue
|
||||
} from '../storage/types';
|
||||
import type { RequestInterceptor } from './build';
|
||||
import { ConfigWithCache, createValidateStatus, isMethodIn, updateStaleRequest } from './util';
|
||||
import {
|
||||
ConfigWithCache,
|
||||
createValidateStatus,
|
||||
isMethodIn,
|
||||
updateStaleRequest
|
||||
} from './util';
|
||||
|
||||
export function defaultRequestInterceptor(axios: AxiosCacheInstance) {
|
||||
const onFulfilled: RequestInterceptor['onFulfilled'] = async (config) => {
|
||||
@ -49,24 +58,23 @@ export function defaultRequestInterceptor(axios: AxiosCacheInstance) {
|
||||
|
||||
// Not cached, continue the request, and mark it as fetching
|
||||
// biome-ignore lint/suspicious/noConfusingLabels: required to break condition in simultaneous accesses
|
||||
ignoreAndRequest: if (cache.state === 'empty' || cache.state === 'stale' || overrideCache) {
|
||||
/**
|
||||
* This checks for simultaneous access to a new key. The js event loop jumps on the
|
||||
* first await statement, so the second (asynchronous call) request may have already
|
||||
* started executing.
|
||||
*/
|
||||
ignoreAndRequest: if (
|
||||
cache.state === 'empty' ||
|
||||
cache.state === 'stale' ||
|
||||
overrideCache
|
||||
) {
|
||||
// This checks for simultaneous access to a new key. The js event loop jumps on the
|
||||
// first await statement, so the second (asynchronous call) request may have already
|
||||
// started executing.
|
||||
if (axios.waiting[config.id] && !overrideCache) {
|
||||
cache = (await axios.storage.get(config.id, config)) as
|
||||
| CachedStorageValue
|
||||
| LoadingStorageValue;
|
||||
|
||||
/**
|
||||
* This check is required when a request has it own cache deleted manually, lets
|
||||
* say by a `axios.storage.delete(key)` and has a concurrent loading request.
|
||||
* Because in this case, the cache will be empty and may still has a pending key
|
||||
* on waiting map.
|
||||
*/
|
||||
//@ts-expect-error read above
|
||||
// @ts-expect-error This check is required when a request has it own cache deleted manually, lets
|
||||
// say by a `axios.storage.delete(key)` and has a concurrent loading request.
|
||||
// Because in this case, the cache will be empty and may still has a pending key
|
||||
// on waiting map.
|
||||
if (cache.state !== 'empty') {
|
||||
if (__ACI_DEV__) {
|
||||
axios.debug({
|
||||
@ -82,11 +90,8 @@ export function defaultRequestInterceptor(axios: AxiosCacheInstance) {
|
||||
// Create a deferred to resolve other requests for the same key when it's completed
|
||||
axios.waiting[config.id] = deferred();
|
||||
|
||||
/**
|
||||
* Adds a default reject handler to catch when the request gets aborted without
|
||||
* others waiting for it.
|
||||
*/
|
||||
|
||||
// Adds a default reject handler to catch when the request gets aborted without
|
||||
// others waiting for it.
|
||||
axios.waiting[config.id]!.catch(() => undefined);
|
||||
|
||||
await axios.storage.set(
|
||||
@ -102,13 +107,11 @@ export function defaultRequestInterceptor(axios: AxiosCacheInstance) {
|
||||
: // Typescript doesn't know that cache.state here can only be 'empty' or 'stale'
|
||||
(cache.state as 'stale'),
|
||||
|
||||
// Eslint complains a lot :)
|
||||
|
||||
data: cache.data as any,
|
||||
|
||||
// If the cache is empty and asked to override it, use the current timestamp
|
||||
|
||||
createdAt: overrideCache && !cache.createdAt ? Date.now() : (cache.createdAt as any)
|
||||
createdAt:
|
||||
overrideCache && !cache.createdAt ? Date.now() : (cache.createdAt as any)
|
||||
},
|
||||
config
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user