@isdk/proxy 0.1.1
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/README.cn.md +138 -0
- package/README.md +129 -0
- package/dist/index.d.mts +213 -0
- package/dist/index.d.ts +213 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/docs/README.md +133 -0
- package/docs/classes/SmartCache.md +148 -0
- package/docs/functions/createCachedFetch.md +52 -0
- package/docs/functions/createFetchWithCache.md +52 -0
- package/docs/functions/extractData.md +39 -0
- package/docs/functions/fetchWithCache.md +39 -0
- package/docs/functions/generateCacheKey.md +27 -0
- package/docs/functions/isAllowed.md +38 -0
- package/docs/globals.md +29 -0
- package/docs/interfaces/CacheEntry.md +123 -0
- package/docs/interfaces/CacheMetadata.md +88 -0
- package/docs/interfaces/FetchWithCacheContext.md +161 -0
- package/docs/interfaces/FetchWithCacheOptions.md +103 -0
- package/docs/interfaces/KeyFilterConfig.md +33 -0
- package/docs/interfaces/ProxyConfig.md +41 -0
- package/docs/interfaces/SiteCacheConfig.md +61 -0
- package/docs/interfaces/SmartCacheOptions.md +41 -0
- package/package.json +101 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / SiteCacheConfig
|
|
6
|
+
|
|
7
|
+
# Interface: SiteCacheConfig
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:16](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L16)
|
|
10
|
+
|
|
11
|
+
站点级缓存配置
|
|
12
|
+
|
|
13
|
+
## Properties
|
|
14
|
+
|
|
15
|
+
### cookies?
|
|
16
|
+
|
|
17
|
+
> `optional` **cookies**: [`KeyFilterConfig`](KeyFilterConfig.md)
|
|
18
|
+
|
|
19
|
+
Defined in: [types.ts:22](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L22)
|
|
20
|
+
|
|
21
|
+
Cookie 过滤配置
|
|
22
|
+
|
|
23
|
+
***
|
|
24
|
+
|
|
25
|
+
### forceCache?
|
|
26
|
+
|
|
27
|
+
> `optional` **forceCache**: `boolean`
|
|
28
|
+
|
|
29
|
+
Defined in: [types.ts:26](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L26)
|
|
30
|
+
|
|
31
|
+
是否强制缓存一切响应(无视 no-store 等不缓存指令),用于极端的离线可用容错场景
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### headers?
|
|
36
|
+
|
|
37
|
+
> `optional` **headers**: [`KeyFilterConfig`](KeyFilterConfig.md)
|
|
38
|
+
|
|
39
|
+
Defined in: [types.ts:20](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L20)
|
|
40
|
+
|
|
41
|
+
请求头过滤配置
|
|
42
|
+
|
|
43
|
+
***
|
|
44
|
+
|
|
45
|
+
### query?
|
|
46
|
+
|
|
47
|
+
> `optional` **query**: [`KeyFilterConfig`](KeyFilterConfig.md)
|
|
48
|
+
|
|
49
|
+
Defined in: [types.ts:18](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L18)
|
|
50
|
+
|
|
51
|
+
Query 参数过滤配置
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
|
|
55
|
+
### staleIfError?
|
|
56
|
+
|
|
57
|
+
> `optional` **staleIfError**: `boolean`
|
|
58
|
+
|
|
59
|
+
Defined in: [types.ts:24](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L24)
|
|
60
|
+
|
|
61
|
+
当后端请求失败且存在旧缓存时,是否强制返回旧缓存(容错机制)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / SmartCacheOptions
|
|
6
|
+
|
|
7
|
+
# Interface: SmartCacheOptions
|
|
8
|
+
|
|
9
|
+
Defined in: [core/SmartCache.ts:10](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/SmartCache.ts#L10)
|
|
10
|
+
|
|
11
|
+
SmartCache 选项
|
|
12
|
+
|
|
13
|
+
## Properties
|
|
14
|
+
|
|
15
|
+
### maxMemorySize?
|
|
16
|
+
|
|
17
|
+
> `optional` **maxMemorySize**: `number`
|
|
18
|
+
|
|
19
|
+
Defined in: [core/SmartCache.ts:14](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/SmartCache.ts#L14)
|
|
20
|
+
|
|
21
|
+
内存缓存阈值(字节)。响应体大小超过此值时,Body 将只存入磁盘,而 Meta 仍保留在内存。默认 1MB。
|
|
22
|
+
|
|
23
|
+
***
|
|
24
|
+
|
|
25
|
+
### memoryOptions?
|
|
26
|
+
|
|
27
|
+
> `optional` **memoryOptions**: `Partial`\<`KeyvCacheableMemoryOptions`\>
|
|
28
|
+
|
|
29
|
+
Defined in: [core/SmartCache.ts:16](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/SmartCache.ts#L16)
|
|
30
|
+
|
|
31
|
+
透传给 L1 (Memory) 的高级配置
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### storagePath?
|
|
36
|
+
|
|
37
|
+
> `optional` **storagePath**: `string`
|
|
38
|
+
|
|
39
|
+
Defined in: [core/SmartCache.ts:12](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/SmartCache.ts#L12)
|
|
40
|
+
|
|
41
|
+
磁盘缓存的物理路径。如果不提供,将默认使用系统临时目录。
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@isdk/proxy",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A framework-agnostic, high-performance hybrid caching middleware with SWR, request collapsing, and stale-if-error support.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Riceball LEE <snowyu.lee@gmail.com>",
|
|
7
|
+
"homepage": "https://github.com/isdk/proxy.js",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git://github.com/isdk/proxy.js.git"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"require": "./dist/index.js",
|
|
18
|
+
"import": "./dist/index.mjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@cacheable/memory": "^2.0.8",
|
|
23
|
+
"@isdk/common-error": "^0.2.0",
|
|
24
|
+
"cacache": "^20.0.4",
|
|
25
|
+
"events-ex": "^2.3.1",
|
|
26
|
+
"http-cache-semantics": "^4.2.0",
|
|
27
|
+
"lodash-es": "^4.18.1",
|
|
28
|
+
"nanoid": "^5.1.11",
|
|
29
|
+
"util-ex": "^2.5.2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
33
|
+
"@eslint/eslintrc": "^3.3.3",
|
|
34
|
+
"@eslint/js": "^9.39.2",
|
|
35
|
+
"@fastify/cookie": "^11.0.2",
|
|
36
|
+
"@fastify/formbody": "^8.0.2",
|
|
37
|
+
"@types/cacache": "^20.0.1",
|
|
38
|
+
"@types/http-cache-semantics": "^4.2.0",
|
|
39
|
+
"@types/jest": "^29.5.14",
|
|
40
|
+
"@types/jsdom": "^27.0.0",
|
|
41
|
+
"@types/lodash-es": "^4.17.12",
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "~8.41.0",
|
|
44
|
+
"eslint": "^9.34.0",
|
|
45
|
+
"eslint-config-prettier": "^10.1.8",
|
|
46
|
+
"eslint-plugin-tsdoc": "^0.4.0",
|
|
47
|
+
"fastify": "^5.6.1",
|
|
48
|
+
"prettier": "^3.6.2",
|
|
49
|
+
"terser": "^5.44.0",
|
|
50
|
+
"tsup": "^8.5.0",
|
|
51
|
+
"tsx": "^4.20.5",
|
|
52
|
+
"type-fest": "^4.41.0",
|
|
53
|
+
"typedoc": "^0.28.16",
|
|
54
|
+
"typedoc-plugin-markdown": "^4.8.1",
|
|
55
|
+
"typescript": "~5.7.3",
|
|
56
|
+
"vite": "^7.1.4",
|
|
57
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
58
|
+
"vitest": "^3.2.4",
|
|
59
|
+
"vitest-fetch-mock": "^0.4.5"
|
|
60
|
+
},
|
|
61
|
+
"files": [
|
|
62
|
+
"docs",
|
|
63
|
+
"dist"
|
|
64
|
+
],
|
|
65
|
+
"keywords": [
|
|
66
|
+
"cache",
|
|
67
|
+
"swr",
|
|
68
|
+
"stale-while-revalidate",
|
|
69
|
+
"middleware",
|
|
70
|
+
"proxy",
|
|
71
|
+
"cacache",
|
|
72
|
+
"lru",
|
|
73
|
+
"request-collapsing",
|
|
74
|
+
"framework-agnostic",
|
|
75
|
+
"hybrid-cache"
|
|
76
|
+
],
|
|
77
|
+
"maintainers": [
|
|
78
|
+
"Riceball LEE <snowyu.lee@gmail.com>"
|
|
79
|
+
],
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=20.11.1"
|
|
82
|
+
},
|
|
83
|
+
"types": "./dist/index.d.ts",
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build-fast": "tsup",
|
|
86
|
+
"build": "pnpm run build-fast --dts-resolve --dts && pnpm run doc:md",
|
|
87
|
+
"clean": "rm -fr web docs dist",
|
|
88
|
+
"doc": "typedoc --plugin none --out web",
|
|
89
|
+
"doc:md": "typedoc --plugin typedoc-plugin-markdown --out docs",
|
|
90
|
+
"style": "pnpm run format:base -c && pnpm run lint",
|
|
91
|
+
"style:fix": "pnpm run format:fix && pnpm run lint:fix",
|
|
92
|
+
"format": "pnpm run format:base -c",
|
|
93
|
+
"format:base": "prettier \"src/**/*.{ts,tsx,js,jsx,css,scss,sass,less,md}\"",
|
|
94
|
+
"format:fix": "pnpm run format:base --write",
|
|
95
|
+
"lint": "eslint .",
|
|
96
|
+
"lint:fix": "pnpm run lint --fix",
|
|
97
|
+
"test": "vitest run",
|
|
98
|
+
"release": "pnpm run clean && pnpm run build && git add -f docs && git ci -m 'docs: update API docs' && pnpm dlx commit-and-tag-version -s",
|
|
99
|
+
"release.alpha": "pnpm run release -- --prerelease alpha"
|
|
100
|
+
}
|
|
101
|
+
}
|