@isdk/proxy 0.1.1 → 0.1.3
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 +249 -9
- package/README.md +249 -7
- package/dist/index.d.mts +374 -41
- package/dist/index.d.ts +374 -41
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/README.md +249 -7
- package/docs/classes/OfflineCacheMissError.md +426 -0
- package/docs/classes/SmartCache.md +81 -13
- package/docs/functions/createCachedFetch.md +1 -1
- package/docs/functions/createFetchWithCache.md +1 -1
- package/docs/functions/extractData.md +34 -5
- package/docs/functions/fetchWithCache.md +18 -9
- package/docs/functions/generateCacheKey.md +34 -4
- package/docs/functions/getSiteConfig.md +39 -0
- package/docs/functions/isAllowed.md +35 -8
- package/docs/functions/isCacheable.md +27 -0
- package/docs/functions/isGlob.md +23 -0
- package/docs/functions/isMatch.md +44 -0
- package/docs/functions/prefetch.md +33 -0
- package/docs/globals.md +15 -0
- package/docs/interfaces/BodyFilterConfig.md +77 -0
- package/docs/interfaces/CacheEntry.md +9 -9
- package/docs/interfaces/CacheMetadata.md +8 -8
- package/docs/interfaces/CacheRule.md +80 -0
- package/docs/interfaces/FetchWithCacheContext.md +44 -16
- package/docs/interfaces/FetchWithCacheOptions.md +40 -12
- package/docs/interfaces/KeyFilterConfig.md +11 -7
- package/docs/interfaces/PrefetchOptions.md +107 -0
- package/docs/interfaces/PrefetchRequest.md +31 -0
- package/docs/interfaces/PrefetchResult.md +47 -0
- package/docs/interfaces/ProxyConfig.md +4 -4
- package/docs/interfaces/SiteCacheConfig.md +56 -11
- package/docs/interfaces/SmartCacheOptions.md +32 -6
- package/docs/variables/OfflineCacheMissErrorCode.md +18 -0
- package/package.json +5 -3
|
@@ -6,19 +6,42 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: SiteCacheConfig
|
|
8
8
|
|
|
9
|
-
Defined in: [types.ts:
|
|
9
|
+
Defined in: [packages/proxy/src/types.ts:81](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L81)
|
|
10
10
|
|
|
11
11
|
站点级缓存配置
|
|
12
12
|
|
|
13
13
|
## Properties
|
|
14
14
|
|
|
15
|
+
### body?
|
|
16
|
+
|
|
17
|
+
> `optional` **body**: [`BodyFilterConfig`](BodyFilterConfig.md)
|
|
18
|
+
|
|
19
|
+
Defined in: [packages/proxy/src/types.ts:104](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L104)
|
|
20
|
+
|
|
21
|
+
请求体过滤配置 (仅限 JSON 类型)。
|
|
22
|
+
当方法为 POST/PUT/PATCH 且为 JSON 格式时,用于从 Body 中提取特定字段参与指纹计算。
|
|
23
|
+
|
|
24
|
+
***
|
|
25
|
+
|
|
26
|
+
### cacheRules?
|
|
27
|
+
|
|
28
|
+
> `optional` **cacheRules**: [`CacheRule`](CacheRule.md)[]
|
|
29
|
+
|
|
30
|
+
Defined in: [packages/proxy/src/types.ts:93](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L93)
|
|
31
|
+
|
|
32
|
+
精细化缓存规则列表。
|
|
33
|
+
如果配置了此项,请求必须匹配其中至少一条规则才会被允许进入缓存流程。
|
|
34
|
+
适用于只希望缓存特定 API 接口的场景。
|
|
35
|
+
|
|
36
|
+
***
|
|
37
|
+
|
|
15
38
|
### cookies?
|
|
16
39
|
|
|
17
40
|
> `optional` **cookies**: [`KeyFilterConfig`](KeyFilterConfig.md)
|
|
18
41
|
|
|
19
|
-
Defined in: [types.ts:
|
|
42
|
+
Defined in: [packages/proxy/src/types.ts:99](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L99)
|
|
20
43
|
|
|
21
|
-
Cookie
|
|
44
|
+
Cookie 过滤配置:决定哪些 Cookie 字段参与缓存指纹计算
|
|
22
45
|
|
|
23
46
|
***
|
|
24
47
|
|
|
@@ -26,9 +49,9 @@ Cookie 过滤配置
|
|
|
26
49
|
|
|
27
50
|
> `optional` **forceCache**: `boolean`
|
|
28
51
|
|
|
29
|
-
Defined in: [types.ts:
|
|
52
|
+
Defined in: [packages/proxy/src/types.ts:108](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L108)
|
|
30
53
|
|
|
31
|
-
|
|
54
|
+
强制缓存:是否忽略 `Cache-Control: no-store` 等指令强制入库。
|
|
32
55
|
|
|
33
56
|
***
|
|
34
57
|
|
|
@@ -36,9 +59,31 @@ Defined in: [types.ts:26](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
|
|
|
36
59
|
|
|
37
60
|
> `optional` **headers**: [`KeyFilterConfig`](KeyFilterConfig.md)
|
|
38
61
|
|
|
39
|
-
Defined in: [types.ts:
|
|
62
|
+
Defined in: [packages/proxy/src/types.ts:97](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L97)
|
|
63
|
+
|
|
64
|
+
请求头过滤配置:决定哪些 Header 参与缓存指纹计算
|
|
65
|
+
|
|
66
|
+
***
|
|
67
|
+
|
|
68
|
+
### methods?
|
|
69
|
+
|
|
70
|
+
> `optional` **methods**: `string`[]
|
|
71
|
+
|
|
72
|
+
Defined in: [packages/proxy/src/types.ts:87](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L87)
|
|
73
|
+
|
|
74
|
+
允许缓存的 HTTP 方法列表。
|
|
75
|
+
默认值: ['GET', 'HEAD']。
|
|
76
|
+
若要缓存 POST/PUT,必须在此显式添加,并确保后端响应满足缓存条件(或开启 `forceCache`)。
|
|
77
|
+
|
|
78
|
+
***
|
|
79
|
+
|
|
80
|
+
### offline?
|
|
81
|
+
|
|
82
|
+
> `optional` **offline**: `boolean`
|
|
83
|
+
|
|
84
|
+
Defined in: [packages/proxy/src/types.ts:110](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L110)
|
|
40
85
|
|
|
41
|
-
|
|
86
|
+
严格离线模式:不发起任何网络请求,只读缓存。缓存未命中时抛出 OfflineCacheMissError
|
|
42
87
|
|
|
43
88
|
***
|
|
44
89
|
|
|
@@ -46,9 +91,9 @@ Defined in: [types.ts:20](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
|
|
|
46
91
|
|
|
47
92
|
> `optional` **query**: [`KeyFilterConfig`](KeyFilterConfig.md)
|
|
48
93
|
|
|
49
|
-
Defined in: [types.ts:
|
|
94
|
+
Defined in: [packages/proxy/src/types.ts:95](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L95)
|
|
50
95
|
|
|
51
|
-
Query
|
|
96
|
+
Query 参数过滤配置:决定哪些查询参数参与缓存指纹 (Cache Key) 的计算
|
|
52
97
|
|
|
53
98
|
***
|
|
54
99
|
|
|
@@ -56,6 +101,6 @@ Query 参数过滤配置
|
|
|
56
101
|
|
|
57
102
|
> `optional` **staleIfError**: `boolean`
|
|
58
103
|
|
|
59
|
-
Defined in: [types.ts:
|
|
104
|
+
Defined in: [packages/proxy/src/types.ts:106](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L106)
|
|
60
105
|
|
|
61
|
-
|
|
106
|
+
容错机制:当后端请求失败(网络错误或 5xx)且存在旧缓存时,是否强制返回旧缓存
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: SmartCacheOptions
|
|
8
8
|
|
|
9
|
-
Defined in: [core/SmartCache.ts:10](https://github.com/isdk/proxy.js/blob/
|
|
9
|
+
Defined in: [packages/proxy/src/core/SmartCache.ts:10](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/SmartCache.ts#L10)
|
|
10
10
|
|
|
11
11
|
SmartCache 选项
|
|
12
12
|
|
|
@@ -16,19 +16,45 @@ SmartCache 选项
|
|
|
16
16
|
|
|
17
17
|
> `optional` **maxMemorySize**: `number`
|
|
18
18
|
|
|
19
|
-
Defined in: [core/SmartCache.ts:14](https://github.com/isdk/proxy.js/blob/
|
|
19
|
+
Defined in: [packages/proxy/src/core/SmartCache.ts:14](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/SmartCache.ts#L14)
|
|
20
20
|
|
|
21
21
|
内存缓存阈值(字节)。响应体大小超过此值时,Body 将只存入磁盘,而 Meta 仍保留在内存。默认 1MB。
|
|
22
22
|
|
|
23
23
|
***
|
|
24
24
|
|
|
25
|
+
### maxTotalMemorySize?
|
|
26
|
+
|
|
27
|
+
> `optional` **maxTotalMemorySize**: `number`
|
|
28
|
+
|
|
29
|
+
Defined in: [packages/proxy/src/core/SmartCache.ts:16](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/SmartCache.ts#L16)
|
|
30
|
+
|
|
31
|
+
内存缓存总大小阈值(字节)。默认 100MB。超过此值将清空内存缓存。
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
25
35
|
### memoryOptions?
|
|
26
36
|
|
|
27
|
-
> `optional` **memoryOptions**: `
|
|
37
|
+
> `optional` **memoryOptions**: `object`
|
|
38
|
+
|
|
39
|
+
Defined in: [packages/proxy/src/core/SmartCache.ts:18](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/SmartCache.ts#L18)
|
|
40
|
+
|
|
41
|
+
透传给 L1 (Memory) 的高级配置 (secondary-cache LRUCache options)
|
|
42
|
+
|
|
43
|
+
#### Index Signature
|
|
44
|
+
|
|
45
|
+
\[`key`: `string`\]: `any`
|
|
46
|
+
|
|
47
|
+
#### capacity?
|
|
48
|
+
|
|
49
|
+
> `optional` **capacity**: `number`
|
|
50
|
+
|
|
51
|
+
#### cleanInterval?
|
|
52
|
+
|
|
53
|
+
> `optional` **cleanInterval**: `number`
|
|
28
54
|
|
|
29
|
-
|
|
55
|
+
#### expires?
|
|
30
56
|
|
|
31
|
-
|
|
57
|
+
> `optional` **expires**: `number`
|
|
32
58
|
|
|
33
59
|
***
|
|
34
60
|
|
|
@@ -36,6 +62,6 @@ Defined in: [core/SmartCache.ts:16](https://github.com/isdk/proxy.js/blob/bed37f
|
|
|
36
62
|
|
|
37
63
|
> `optional` **storagePath**: `string`
|
|
38
64
|
|
|
39
|
-
Defined in: [core/SmartCache.ts:12](https://github.com/isdk/proxy.js/blob/
|
|
65
|
+
Defined in: [packages/proxy/src/core/SmartCache.ts:12](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/SmartCache.ts#L12)
|
|
40
66
|
|
|
41
67
|
磁盘缓存的物理路径。如果不提供,将默认使用系统临时目录。
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / OfflineCacheMissErrorCode
|
|
6
|
+
|
|
7
|
+
# Variable: OfflineCacheMissErrorCode
|
|
8
|
+
|
|
9
|
+
> `const` **OfflineCacheMissErrorCode**: `OfflineCacheMiss` = `ErrorCode.OfflineCacheMiss`
|
|
10
|
+
|
|
11
|
+
Defined in: [packages/proxy/src/errors.ts:14](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/errors.ts#L14)
|
|
12
|
+
|
|
13
|
+
Offline 缓存未命中错误代码
|
|
14
|
+
|
|
15
|
+
当处于 offline 模式且请求的 URL 没有对应缓存时抛出。
|
|
16
|
+
这帮助调用者区分:
|
|
17
|
+
- 网络请求失败(其他错误类型)
|
|
18
|
+
- offline 模式下缓存不存在(本错误)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isdk/proxy",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A framework-agnostic, high-performance hybrid caching middleware with SWR, request collapsing, and stale-if-error support.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Riceball LEE <snowyu.lee@gmail.com>",
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@isdk/common-error": "^0.2.0",
|
|
22
|
+
"@isdk/common-error": "^0.2.2",
|
|
24
23
|
"cacache": "^20.0.4",
|
|
25
24
|
"events-ex": "^2.3.1",
|
|
26
25
|
"http-cache-semantics": "^4.2.0",
|
|
27
26
|
"lodash-es": "^4.18.1",
|
|
28
27
|
"nanoid": "^5.1.11",
|
|
28
|
+
"picomatch": "^4.0.4",
|
|
29
|
+
"secondary-cache": "^2.1.0",
|
|
29
30
|
"util-ex": "^2.5.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"@types/jsdom": "^27.0.0",
|
|
41
42
|
"@types/lodash-es": "^4.17.12",
|
|
42
43
|
"@types/node": "^20.0.0",
|
|
44
|
+
"@types/picomatch": "^4.0.3",
|
|
43
45
|
"@typescript-eslint/eslint-plugin": "~8.41.0",
|
|
44
46
|
"eslint": "^9.34.0",
|
|
45
47
|
"eslint-config-prettier": "^10.1.8",
|