@isdk/proxy 0.1.1 → 0.1.2

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.
@@ -6,16 +6,19 @@
6
6
 
7
7
  # Function: isAllowed()
8
8
 
9
- > **isAllowed**(`key`, `config?`): `boolean`
9
+ > **isAllowed**(`key`, `config?`, `defaultAllowed?`): `boolean`
10
10
 
11
- Defined in: [utils/isAllowed.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/utils/isAllowed.ts#L15)
11
+ Defined in: [utils/isAllowed.ts:37](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/utils/isAllowed.ts#L37)
12
12
 
13
13
  判断给定的键是否允许参与缓存指纹计算。
14
14
 
15
- 优先级逻辑:
16
- 1. 如果配置了 `include` (白名单),则只有存在于 `include` 中的键才会被允许。
17
- 2. 否则,如果配置了 `exclude` (黑名单),则存在于 `exclude` 中的键将被拒绝。
18
- 3. 如果都没有配置,默认允许所有键。
15
+ **优先级逻辑**:
16
+ 1. `exclude` 命中 → 返回 `false`(优先级最高,会覆盖前面的结果)
17
+ 2. `include` 存在且命中 → 返回 `true`
18
+ 3. `include` 存在但不命中 → 返回 `false`
19
+ 4. 都没有配置 → 使用 `defaultAllowed`(未传则返回 `undefined`)
20
+
21
+ **注意**:`include` 和 `exclude` 可以同时配置,此时 `exclude` 优先级更高。
19
22
 
20
23
  ## Parameters
21
24
 
@@ -29,10 +32,34 @@ Defined in: [utils/isAllowed.ts:15](https://github.com/isdk/proxy.js/blob/bed37f
29
32
 
30
33
  [`KeyFilterConfig`](../interfaces/KeyFilterConfig.md)
31
34
 
32
- 过滤配置
35
+ 过滤配置,支持 `include`(白名单)和 `exclude`(黑名单)
36
+
37
+ ### defaultAllowed?
38
+
39
+ `boolean`
40
+
41
+ 当没有配置或配置未命中时的默认值(可选)
33
42
 
34
43
  ## Returns
35
44
 
36
45
  `boolean`
37
46
 
38
- 是否允许
47
+ 是否允许。返回 `boolean` 或 `undefined`(当没有配置且未传 defaultAllowed 时)
48
+
49
+ ## Example
50
+
51
+ ```typescript
52
+ // 无配置
53
+ isAllowed('key'); // undefined
54
+
55
+ // 白名单
56
+ isAllowed('id', { include: ['id', 'name'] }); // true
57
+ isAllowed('email', { include: ['id', 'name'] }); // false
58
+
59
+ // 黑名单
60
+ isAllowed('password', { exclude: ['password'] }); // false
61
+ isAllowed('name', { exclude: ['password'] }); // undefined
62
+
63
+ // 设置默认值
64
+ isAllowed('name', { exclude: ['password'] }, true); // true
65
+ ```
@@ -0,0 +1,23 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / isGlob
6
+
7
+ # Function: isGlob()
8
+
9
+ > **isGlob**(`str`): `boolean`
10
+
11
+ Defined in: [utils/matcher.ts:7](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/utils/matcher.ts#L7)
12
+
13
+ 判断一个模式是否为 Glob 模式
14
+
15
+ ## Parameters
16
+
17
+ ### str
18
+
19
+ `string`
20
+
21
+ ## Returns
22
+
23
+ `boolean`
@@ -0,0 +1,44 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / isMatch
6
+
7
+ # Function: isMatch()
8
+
9
+ > **isMatch**(`pattern`, `value`, `usePrefix`): `boolean`
10
+
11
+ Defined in: [utils/matcher.ts:25](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/utils/matcher.ts#L25)
12
+
13
+ 通用匹配函数
14
+
15
+ 逻辑优先级:
16
+ 1. 如果 pattern 是数组,遵循:(匹配任一正向模式) 且 (不匹配任一负向模式)。
17
+ 2. 如果 pattern 是 RegExp 对象,直接使用 regex.test(value)。
18
+ 3. 如果 pattern 是 "/regex/flags" 格式的字符串,转为 RegExp 后使用 test。
19
+ 4. 如果 pattern 是 Glob 字符串,使用 picomatch 进行匹配。
20
+ 5. 否则,根据 usePrefix 参数进行前缀匹配或精确匹配。
21
+
22
+ ## Parameters
23
+
24
+ ### pattern
25
+
26
+ 匹配模式 (RegExp 或 字符串 或 数组)
27
+
28
+ `string` | `RegExp` | (`string` \| `RegExp`)[]
29
+
30
+ ### value
31
+
32
+ `string`
33
+
34
+ 要匹配的值
35
+
36
+ ### usePrefix
37
+
38
+ `boolean` = `false`
39
+
40
+ 是否在普通字符串匹配时启用前缀匹配 (默认为 false,即精确匹配)
41
+
42
+ ## Returns
43
+
44
+ `boolean`
package/docs/globals.md CHANGED
@@ -10,8 +10,10 @@
10
10
 
11
11
  ## Interfaces
12
12
 
13
+ - [BodyFilterConfig](interfaces/BodyFilterConfig.md)
13
14
  - [CacheEntry](interfaces/CacheEntry.md)
14
15
  - [CacheMetadata](interfaces/CacheMetadata.md)
16
+ - [CacheRule](interfaces/CacheRule.md)
15
17
  - [FetchWithCacheContext](interfaces/FetchWithCacheContext.md)
16
18
  - [FetchWithCacheOptions](interfaces/FetchWithCacheOptions.md)
17
19
  - [KeyFilterConfig](interfaces/KeyFilterConfig.md)
@@ -26,4 +28,7 @@
26
28
  - [extractData](functions/extractData.md)
27
29
  - [fetchWithCache](functions/fetchWithCache.md)
28
30
  - [generateCacheKey](functions/generateCacheKey.md)
31
+ - [getSiteConfig](functions/getSiteConfig.md)
29
32
  - [isAllowed](functions/isAllowed.md)
33
+ - [isGlob](functions/isGlob.md)
34
+ - [isMatch](functions/isMatch.md)
@@ -0,0 +1,77 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / BodyFilterConfig
6
+
7
+ # Interface: BodyFilterConfig
8
+
9
+ Defined in: [types.ts:13](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L13)
10
+
11
+ 缓存键过滤配置
12
+
13
+ 用于定义在生成缓存指纹时,哪些字段应该被包含或排除。
14
+
15
+ ## Extends
16
+
17
+ - [`KeyFilterConfig`](KeyFilterConfig.md)
18
+
19
+ ## Properties
20
+
21
+ ### exclude?
22
+
23
+ > `optional` **exclude**: (`string` \| `RegExp`)[]
24
+
25
+ Defined in: [types.ts:10](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L10)
26
+
27
+ 排除(黑名单):用于排除像 `timestamp`、`nonce` 等干扰缓存命中的动态字段。支持字符串、Glob 模式或正则表达式。
28
+
29
+ #### Inherited from
30
+
31
+ [`KeyFilterConfig`](KeyFilterConfig.md).[`exclude`](KeyFilterConfig.md#exclude)
32
+
33
+ ***
34
+
35
+ ### extract?
36
+
37
+ > `optional` **extract**: `string` \| `RegExp`
38
+
39
+ Defined in: [types.ts:18](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L18)
40
+
41
+ 用于非 JSON (文本) Body 的提取正则表达式。
42
+ 如果包含捕获组,则提取捕获组内容作为指纹;否则提取整个匹配部分。
43
+
44
+ ***
45
+
46
+ ### include?
47
+
48
+ > `optional` **include**: (`string` \| `RegExp`)[]
49
+
50
+ Defined in: [types.ts:8](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L8)
51
+
52
+ 仅包含(白名单):如果设置,只有这些字段会参与 Key 的计算。支持字符串、Glob 模式或正则表达式。
53
+
54
+ #### Inherited from
55
+
56
+ [`KeyFilterConfig`](KeyFilterConfig.md).[`include`](KeyFilterConfig.md#include)
57
+
58
+ ***
59
+
60
+ ### maxLength?
61
+
62
+ > `optional` **maxLength**: `number`
63
+
64
+ Defined in: [types.ts:25](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L25)
65
+
66
+ 用于正则匹配/提取 Body 时的最大长度限制,默认 1024 (1KB)
67
+
68
+ ***
69
+
70
+ ### sort?
71
+
72
+ > `optional` **sort**: `boolean`
73
+
74
+ Defined in: [types.ts:23](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L23)
75
+
76
+ 是否对提取出的捕获组进行排序。
77
+ 开启后可解决 Body 中参数顺序不一致导致的指纹失效问题。
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: CacheEntry
8
8
 
9
- Defined in: [types.ts:55](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L55)
9
+ Defined in: [types.ts:137](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L137)
10
10
 
11
11
  完整的缓存条目
12
12
 
@@ -20,7 +20,7 @@ Defined in: [types.ts:55](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
20
20
 
21
21
  > **body**: `any`
22
22
 
23
- Defined in: [types.ts:57](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L57)
23
+ Defined in: [types.ts:139](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L139)
24
24
 
25
25
  响应体数据:小文件为 Buffer,大文件为可读流
26
26
 
@@ -30,7 +30,7 @@ Defined in: [types.ts:57](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
30
30
 
31
31
  > **headers**: `Record`\<`string`, `string`\>
32
32
 
33
- Defined in: [types.ts:39](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L39)
33
+ Defined in: [types.ts:121](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L121)
34
34
 
35
35
  响应头对象
36
36
 
@@ -44,7 +44,7 @@ Defined in: [types.ts:39](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
44
44
 
45
45
  > **method**: `string`
46
46
 
47
- Defined in: [types.ts:45](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L45)
47
+ Defined in: [types.ts:127](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L127)
48
48
 
49
49
  原始请求方法
50
50
 
@@ -58,7 +58,7 @@ Defined in: [types.ts:45](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
58
58
 
59
59
  > **policy**: `any`
60
60
 
61
- Defined in: [types.ts:41](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L41)
61
+ Defined in: [types.ts:123](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L123)
62
62
 
63
63
  http-cache-semantics 策略对象,包含 TTL 和缓存指令
64
64
 
@@ -72,7 +72,7 @@ http-cache-semantics 策略对象,包含 TTL 和缓存指令
72
72
 
73
73
  > **size**: `number`
74
74
 
75
- Defined in: [types.ts:49](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L49)
75
+ Defined in: [types.ts:131](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L131)
76
76
 
77
77
  Body 的字节长度,用于精确区分“空响应”与“未入内存的大响应”
78
78
 
@@ -86,7 +86,7 @@ Body 的字节长度,用于精确区分“空响应”与“未入内存的大
86
86
 
87
87
  > **status**: `number`
88
88
 
89
- Defined in: [types.ts:37](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L37)
89
+ Defined in: [types.ts:119](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L119)
90
90
 
91
91
  HTTP 状态码
92
92
 
@@ -100,7 +100,7 @@ HTTP 状态码
100
100
 
101
101
  > **timestamp**: `number`
102
102
 
103
- Defined in: [types.ts:47](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L47)
103
+ Defined in: [types.ts:129](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L129)
104
104
 
105
105
  缓存写入时的时间戳
106
106
 
@@ -114,7 +114,7 @@ Defined in: [types.ts:47](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
114
114
 
115
115
  > **url**: `string`
116
116
 
117
- Defined in: [types.ts:43](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L43)
117
+ Defined in: [types.ts:125](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L125)
118
118
 
119
119
  原始请求 URL
120
120
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: CacheMetadata
8
8
 
9
- Defined in: [types.ts:35](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L35)
9
+ Defined in: [types.ts:117](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L117)
10
10
 
11
11
  缓存元数据
12
12
 
@@ -23,7 +23,7 @@ Defined in: [types.ts:35](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
23
23
 
24
24
  > **headers**: `Record`\<`string`, `string`\>
25
25
 
26
- Defined in: [types.ts:39](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L39)
26
+ Defined in: [types.ts:121](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L121)
27
27
 
28
28
  响应头对象
29
29
 
@@ -33,7 +33,7 @@ Defined in: [types.ts:39](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
33
33
 
34
34
  > **method**: `string`
35
35
 
36
- Defined in: [types.ts:45](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L45)
36
+ Defined in: [types.ts:127](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L127)
37
37
 
38
38
  原始请求方法
39
39
 
@@ -43,7 +43,7 @@ Defined in: [types.ts:45](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
43
43
 
44
44
  > **policy**: `any`
45
45
 
46
- Defined in: [types.ts:41](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L41)
46
+ Defined in: [types.ts:123](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L123)
47
47
 
48
48
  http-cache-semantics 策略对象,包含 TTL 和缓存指令
49
49
 
@@ -53,7 +53,7 @@ http-cache-semantics 策略对象,包含 TTL 和缓存指令
53
53
 
54
54
  > **size**: `number`
55
55
 
56
- Defined in: [types.ts:49](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L49)
56
+ Defined in: [types.ts:131](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L131)
57
57
 
58
58
  Body 的字节长度,用于精确区分“空响应”与“未入内存的大响应”
59
59
 
@@ -63,7 +63,7 @@ Body 的字节长度,用于精确区分“空响应”与“未入内存的大
63
63
 
64
64
  > **status**: `number`
65
65
 
66
- Defined in: [types.ts:37](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L37)
66
+ Defined in: [types.ts:119](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L119)
67
67
 
68
68
  HTTP 状态码
69
69
 
@@ -73,7 +73,7 @@ HTTP 状态码
73
73
 
74
74
  > **timestamp**: `number`
75
75
 
76
- Defined in: [types.ts:47](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L47)
76
+ Defined in: [types.ts:129](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L129)
77
77
 
78
78
  缓存写入时的时间戳
79
79
 
@@ -83,6 +83,6 @@ Defined in: [types.ts:47](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
83
83
 
84
84
  > **url**: `string`
85
85
 
86
- Defined in: [types.ts:43](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L43)
86
+ Defined in: [types.ts:125](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L125)
87
87
 
88
88
  原始请求 URL
@@ -0,0 +1,80 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / CacheRule
6
+
7
+ # Interface: CacheRule
8
+
9
+ Defined in: [types.ts:35](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L35)
10
+
11
+ 精细化缓存匹配规则
12
+
13
+ 用于在 `methods` 过滤的基础上,进一步限定哪些具体的请求路径或参数需要被缓存。
14
+ 多个规则之间是 **OR (逻辑或)** 关系,即请求只需匹配其中一条规则即可。
15
+ 在单个规则对象内部,各字段之间是 **AND (逻辑与)** 关系。
16
+
17
+ ## Properties
18
+
19
+ ### body?
20
+
21
+ > `optional` **body**: `string` \| `RegExp` \| (`string` \| `RegExp`)[]
22
+
23
+ Defined in: [types.ts:75](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L75)
24
+
25
+ Body 内容匹配。
26
+ 仅当 Body 为文本或 JSON 时有效。
27
+ - 字符串: 支持 Glob 模式匹配。
28
+ - 正则表达式: 检查 Body 内容是否匹配。
29
+ - 数组: 支持传入多个模式。
30
+
31
+ ***
32
+
33
+ ### bodyType?
34
+
35
+ > `optional` **bodyType**: `"json"` \| `"text"` \| `"binary"`
36
+
37
+ Defined in: [types.ts:67](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L67)
38
+
39
+ 强制指定 Body 类型。
40
+ 如果不指定,则根据 `Content-Type` 自动判断。
41
+
42
+ ***
43
+
44
+ ### method?
45
+
46
+ > `optional` **method**: `string`
47
+
48
+ Defined in: [types.ts:40](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L40)
49
+
50
+ 匹配的方法 (如 "POST")。
51
+ 如果指定,则必须方法完全一致;如果不指定,则匹配所有 `methods` 中允许的方法。
52
+
53
+ ***
54
+
55
+ ### path?
56
+
57
+ > `optional` **path**: `string` \| `RegExp` \| (`string` \| `RegExp`)[]
58
+
59
+ Defined in: [types.ts:52](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L52)
60
+
61
+ 路径匹配。
62
+ - 字符串: 默认进行 Glob 模式匹配(支持 `!` 否定),若非 Glob 且非正则字符串则退化为前缀匹配。
63
+ - 正则表达式: 检查 `url.pathname` 是否匹配。
64
+ - 数组: 支持传入多个模式(含否定模式),只要其中一个匹配即可。
65
+
66
+ ***
67
+
68
+ ### query?
69
+
70
+ > `optional` **query**: `Record`\<`string`, `string` \| `boolean` \| `RegExp`\>
71
+
72
+ Defined in: [types.ts:62](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/types.ts#L62)
73
+
74
+ Query 参数匹配规则。
75
+ - 键名: 支持字符串、Glob 或正则。
76
+ - 值:
77
+ - 字符串: 支持 Glob 模式匹配。
78
+ - 正则表达式: 检查参数值是否匹配。
79
+ - `true`: 要求该参数必须存在于 URL 中。
80
+ - `false`: 要求该参数必须 **不** 存在于 URL 中。
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: FetchWithCacheContext
8
8
 
9
- Defined in: [core/fetchWithCache.ts:31](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L31)
9
+ Defined in: [core/fetchWithCache.ts:32](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L32)
10
10
 
11
11
  内部流水线上下文,合并了入参和计算出的关键状态
12
12
 
@@ -20,7 +20,7 @@ Defined in: [core/fetchWithCache.ts:31](https://github.com/isdk/proxy.js/blob/be
20
20
 
21
21
  > **activeCacheWrites**: `Map`\<`string`, `Promise`\<`void`\>\>
22
22
 
23
- Defined in: [core/fetchWithCache.ts:35](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L35)
23
+ Defined in: [core/fetchWithCache.ts:36](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L36)
24
24
 
25
25
  并发写入任务追踪器
26
26
  传入一个外部维护的 Map,用于在跨请求、跨实例时防止针对同一文件的并发重复下载。
@@ -36,7 +36,7 @@ Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
36
36
 
37
37
  > `optional` **backgroundUpdate**: `boolean`
38
38
 
39
- Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L17)
39
+ Defined in: [core/fetchWithCache.ts:18](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L18)
40
40
 
41
41
  是否启用后台异步更新 (SWR)
42
42
 
@@ -50,7 +50,7 @@ Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/be
50
50
 
51
51
  > **cache**: [`SmartCache`](../classes/SmartCache.md)
52
52
 
53
- Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L13)
53
+ Defined in: [core/fetchWithCache.ts:14](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L14)
54
54
 
55
55
  混合缓存实例
56
56
 
@@ -64,7 +64,7 @@ Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/be
64
64
 
65
65
  > **cacheKey**: `string`
66
66
 
67
- Defined in: [core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L34)
67
+ Defined in: [core/fetchWithCache.ts:35](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L35)
68
68
 
69
69
  ***
70
70
 
@@ -72,7 +72,7 @@ Defined in: [core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/be
72
72
 
73
73
  > **config**: [`SiteCacheConfig`](SiteCacheConfig.md)
74
74
 
75
- Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L15)
75
+ Defined in: [core/fetchWithCache.ts:16](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L16)
76
76
 
77
77
  站点级缓存配置
78
78
 
@@ -86,7 +86,7 @@ Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/be
86
86
 
87
87
  > **fetcher**: (`req`) => `Promise`\<`Response`\>
88
88
 
89
- Defined in: [core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L33)
89
+ Defined in: [core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L34)
90
90
 
91
91
  #### Parameters
92
92
 
@@ -102,13 +102,28 @@ Defined in: [core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/be
102
102
 
103
103
  ### generateKey()?
104
104
 
105
- > `optional` **generateKey**: (`req`, `config`) => `string`
105
+ > `optional` **generateKey**: (`req`, `config`) => `Promise`\<`string`\>
106
106
 
107
- Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L21)
107
+ Defined in: [core/fetchWithCache.ts:22](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L22)
108
108
 
109
109
  自定义缓存键生成函数
110
110
 
111
- 根据 Request 和配置生成唯一的缓存键
111
+ 根据 Request 对象和站点配置生成唯一的缓存指纹 (异步)
112
+
113
+ 该函数是缓存系统的核心组件,用于将复杂的 HTTP 请求对象转换为唯一的 SHA-256 字符串。
114
+ 它实现了高度可定制的提取逻辑,允许通过配置排除掉请求中不稳定的因素(如时间戳、Nonce 等)。
115
+
116
+ ### 生成指纹包含的要素:
117
+ 1. **Method**: 请求方法(统一转为大写)。
118
+ 2. **Host & Path**: 请求的域名和路径。
119
+ 3. **Query Params**: URL 查询参数,受 `config.query` 过滤影响。
120
+ 4. **Headers**: 请求头信息,受 `config.headers` 过滤影响。默认排除 `cookie` 头。
121
+ 5. **Cookies**: 特别提取的 Cookie 字段,受 `config.cookies` 过滤影响。
122
+ 6. **Request Body**:
123
+ - 对于 `POST`, `PUT`, `PATCH` 请求,会自动尝试读取 Body。
124
+ - **JSON 类型**: 如果 `Content-Type` 包含 `application/json`,则解析为对象并应用 `config.body` 过滤。
125
+ - **非 JSON/流类型**: 回退到对原始 Body 字节流进行 SHA-256 哈希计算。
126
+ - **安全性**: 使用 `req.clone()` 读取 Body,确保不影响后续真实的 Fetch 请求流消费。
112
127
 
113
128
  #### Parameters
114
129
 
@@ -116,13 +131,28 @@ Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/be
116
131
 
117
132
  `Request`
118
133
 
134
+ 原始 Web 标准 Request 对象。
135
+
119
136
  ##### config
120
137
 
121
138
  [`SiteCacheConfig`](SiteCacheConfig.md)
122
139
 
140
+ 站点级缓存配置,决定了哪些字段参与指纹计算。
141
+
123
142
  #### Returns
124
143
 
125
- `string`
144
+ `Promise`\<`string`\>
145
+
146
+ 返回一个 64 位十六进制的 SHA-256 哈希字符串作为缓存键。
147
+
148
+ #### Example
149
+
150
+ ```typescript
151
+ const cacheKey = await generateCacheKey(request, {
152
+ query: { exclude: ['timestamp'] },
153
+ body: { include: ['id', 'action'] }
154
+ });
155
+ ```
126
156
 
127
157
  #### Inherited from
128
158
 
@@ -134,7 +164,7 @@ Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/be
134
164
 
135
165
  > `optional` **onBackgroundUpdate**: (`promise`) => `void`
136
166
 
137
- Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L19)
167
+ Defined in: [core/fetchWithCache.ts:20](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L20)
138
168
 
139
169
  后台更新 Promise 触发时的回调
140
170
 
@@ -158,4 +188,4 @@ Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/be
158
188
 
159
189
  > **request**: `Request`
160
190
 
161
- Defined in: [core/fetchWithCache.ts:32](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L32)
191
+ Defined in: [core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/76fee3a101f98e5bf29599fe7ea02ab06479cf70/src/core/fetchWithCache.ts#L33)