@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.
Files changed (36) hide show
  1. package/README.cn.md +249 -9
  2. package/README.md +249 -7
  3. package/dist/index.d.mts +374 -41
  4. package/dist/index.d.ts +374 -41
  5. package/dist/index.js +1 -1
  6. package/dist/index.mjs +1 -1
  7. package/docs/README.md +249 -7
  8. package/docs/classes/OfflineCacheMissError.md +426 -0
  9. package/docs/classes/SmartCache.md +81 -13
  10. package/docs/functions/createCachedFetch.md +1 -1
  11. package/docs/functions/createFetchWithCache.md +1 -1
  12. package/docs/functions/extractData.md +34 -5
  13. package/docs/functions/fetchWithCache.md +18 -9
  14. package/docs/functions/generateCacheKey.md +34 -4
  15. package/docs/functions/getSiteConfig.md +39 -0
  16. package/docs/functions/isAllowed.md +35 -8
  17. package/docs/functions/isCacheable.md +27 -0
  18. package/docs/functions/isGlob.md +23 -0
  19. package/docs/functions/isMatch.md +44 -0
  20. package/docs/functions/prefetch.md +33 -0
  21. package/docs/globals.md +15 -0
  22. package/docs/interfaces/BodyFilterConfig.md +77 -0
  23. package/docs/interfaces/CacheEntry.md +9 -9
  24. package/docs/interfaces/CacheMetadata.md +8 -8
  25. package/docs/interfaces/CacheRule.md +80 -0
  26. package/docs/interfaces/FetchWithCacheContext.md +44 -16
  27. package/docs/interfaces/FetchWithCacheOptions.md +40 -12
  28. package/docs/interfaces/KeyFilterConfig.md +11 -7
  29. package/docs/interfaces/PrefetchOptions.md +107 -0
  30. package/docs/interfaces/PrefetchRequest.md +31 -0
  31. package/docs/interfaces/PrefetchResult.md +47 -0
  32. package/docs/interfaces/ProxyConfig.md +4 -4
  33. package/docs/interfaces/SiteCacheConfig.md +56 -11
  34. package/docs/interfaces/SmartCacheOptions.md +32 -6
  35. package/docs/variables/OfflineCacheMissErrorCode.md +18 -0
  36. package/package.json +5 -3
@@ -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: [packages/proxy/src/types.ts:35](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:75](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:67](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L67)
38
+
39
+ 强制指定 Body 类型。
40
+ 如果不指定,则根据 `Content-Type` 自动判断。
41
+
42
+ ***
43
+
44
+ ### method?
45
+
46
+ > `optional` **method**: `string`
47
+
48
+ Defined in: [packages/proxy/src/types.ts:40](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:52](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:62](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L62)
73
+
74
+ Query 参数匹配规则。
75
+ - 键名: 支持字符串、Glob 或正则。
76
+ - 值:
77
+ - 字符串: 支持 Glob 模式匹配。
78
+ - 正则表达式: 检查参数值是否匹配。
79
+ - `true`: 要求该参数必须存在于 URL 中。
80
+ - `false`: 要求该参数必须 **不** 存在于 URL 中。
@@ -6,9 +6,9 @@
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: [packages/proxy/src/core/fetchWithCache.ts:31](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L31)
10
10
 
11
- 内部流水线上下文,合并了入参和计算出的关键状态
11
+ 内部流水线上下文
12
12
 
13
13
  ## Extends
14
14
 
@@ -20,11 +20,9 @@ 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: [packages/proxy/src/core/fetchWithCache.ts:35](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L35)
24
24
 
25
25
  并发写入任务追踪器
26
- 传入一个外部维护的 Map,用于在跨请求、跨实例时防止针对同一文件的并发重复下载。
27
- Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
28
26
 
29
27
  #### Overrides
30
28
 
@@ -36,7 +34,7 @@ Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
36
34
 
37
35
  > `optional` **backgroundUpdate**: `boolean`
38
36
 
39
- Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L17)
37
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L19)
40
38
 
41
39
  是否启用后台异步更新 (SWR)
42
40
 
@@ -50,7 +48,7 @@ Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/be
50
48
 
51
49
  > **cache**: [`SmartCache`](../classes/SmartCache.md)
52
50
 
53
- Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L13)
51
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L15)
54
52
 
55
53
  混合缓存实例
56
54
 
@@ -64,7 +62,7 @@ Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/be
64
62
 
65
63
  > **cacheKey**: `string`
66
64
 
67
- Defined in: [core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L34)
65
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L34)
68
66
 
69
67
  ***
70
68
 
@@ -72,7 +70,7 @@ Defined in: [core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/be
72
70
 
73
71
  > **config**: [`SiteCacheConfig`](SiteCacheConfig.md)
74
72
 
75
- Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L15)
73
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L17)
76
74
 
77
75
  站点级缓存配置
78
76
 
@@ -86,7 +84,7 @@ Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/be
86
84
 
87
85
  > **fetcher**: (`req`) => `Promise`\<`Response`\>
88
86
 
89
- Defined in: [core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L33)
87
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L33)
90
88
 
91
89
  #### Parameters
92
90
 
@@ -102,13 +100,28 @@ Defined in: [core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/be
102
100
 
103
101
  ### generateKey()?
104
102
 
105
- > `optional` **generateKey**: (`req`, `config`) => `string`
103
+ > `optional` **generateKey**: (`req`, `config`) => `Promise`\<`string`\>
106
104
 
107
- Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L21)
105
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:23](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L23)
108
106
 
109
107
  自定义缓存键生成函数
110
108
 
111
- 根据 Request 和配置生成唯一的缓存键
109
+ 根据 Request 对象和站点配置生成唯一的缓存指纹 (异步)
110
+
111
+ 该函数是缓存系统的核心组件,用于将复杂的 HTTP 请求对象转换为唯一的 SHA-256 字符串。
112
+ 它实现了高度可定制的提取逻辑,允许通过配置排除掉请求中不稳定的因素(如时间戳、Nonce 等)。
113
+
114
+ ### 生成指纹包含的要素:
115
+ 1. **Method**: 请求方法(统一转为大写)。
116
+ 2. **Host & Path**: 请求的域名和路径。
117
+ 3. **Query Params**: URL 查询参数,受 `config.query` 过滤影响。
118
+ 4. **Headers**: 请求头信息,受 `config.headers` 过滤影响。默认排除 `cookie` 头。
119
+ 5. **Cookies**: 特别提取的 Cookie 字段,受 `config.cookies` 过滤影响。
120
+ 6. **Request Body**:
121
+ - 对于 `POST`, `PUT`, `PATCH` 请求,会自动尝试读取 Body。
122
+ - **JSON 类型**: 如果 `Content-Type` 包含 `application/json`,则解析为对象并应用 `config.body` 过滤。
123
+ - **非 JSON/流类型**: 回退到对原始 Body 字节流进行 SHA-256 哈希计算。
124
+ - **安全性**: 使用 `req.clone()` 读取 Body,确保不影响后续真实的 Fetch 请求流消费。
112
125
 
113
126
  #### Parameters
114
127
 
@@ -116,13 +129,28 @@ Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/be
116
129
 
117
130
  `Request`
118
131
 
132
+ 原始 Web 标准 Request 对象。
133
+
119
134
  ##### config
120
135
 
121
136
  [`SiteCacheConfig`](SiteCacheConfig.md)
122
137
 
138
+ 站点级缓存配置,决定了哪些字段参与指纹计算。
139
+
123
140
  #### Returns
124
141
 
125
- `string`
142
+ `Promise`\<`string`\>
143
+
144
+ 返回一个 64 位十六进制的 SHA-256 哈希字符串作为缓存键。
145
+
146
+ #### Example
147
+
148
+ ```typescript
149
+ const cacheKey = await generateCacheKey(request, {
150
+ query: { exclude: ['timestamp'] },
151
+ body: { include: ['id', 'action'] }
152
+ });
153
+ ```
126
154
 
127
155
  #### Inherited from
128
156
 
@@ -134,7 +162,7 @@ Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/be
134
162
 
135
163
  > `optional` **onBackgroundUpdate**: (`promise`) => `void`
136
164
 
137
- Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L19)
165
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L21)
138
166
 
139
167
  后台更新 Promise 触发时的回调
140
168
 
@@ -158,4 +186,4 @@ Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/be
158
186
 
159
187
  > **request**: `Request`
160
188
 
161
- Defined in: [core/fetchWithCache.ts:32](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L32)
189
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:32](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L32)
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: FetchWithCacheOptions
8
8
 
9
- Defined in: [core/fetchWithCache.ts:11](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L11)
9
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L13)
10
10
 
11
11
  fetchWithCache 选项
12
12
 
@@ -20,11 +20,9 @@ fetchWithCache 选项
20
20
 
21
21
  > `optional` **activeCacheWrites**: `Map`\<`string`, `Promise`\<`void`\>\>
22
22
 
23
- Defined in: [core/fetchWithCache.ts:27](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L27)
23
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:27](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L27)
24
24
 
25
25
  并发写入任务追踪器
26
- 传入一个外部维护的 Map,用于在跨请求、跨实例时防止针对同一文件的并发重复下载。
27
- Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
28
26
 
29
27
  ***
30
28
 
@@ -32,7 +30,7 @@ Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
32
30
 
33
31
  > `optional` **backgroundUpdate**: `boolean`
34
32
 
35
- Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L17)
33
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L19)
36
34
 
37
35
  是否启用后台异步更新 (SWR)
38
36
 
@@ -42,7 +40,7 @@ Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/be
42
40
 
43
41
  > **cache**: [`SmartCache`](../classes/SmartCache.md)
44
42
 
45
- Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L13)
43
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L15)
46
44
 
47
45
  混合缓存实例
48
46
 
@@ -52,7 +50,7 @@ Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/be
52
50
 
53
51
  > **config**: [`SiteCacheConfig`](SiteCacheConfig.md)
54
52
 
55
- Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L15)
53
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L17)
56
54
 
57
55
  站点级缓存配置
58
56
 
@@ -60,13 +58,28 @@ Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/be
60
58
 
61
59
  ### generateKey()?
62
60
 
63
- > `optional` **generateKey**: (`req`, `config`) => `string`
61
+ > `optional` **generateKey**: (`req`, `config`) => `Promise`\<`string`\>
64
62
 
65
- Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L21)
63
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:23](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L23)
66
64
 
67
65
  自定义缓存键生成函数
68
66
 
69
- 根据 Request 和配置生成唯一的缓存键
67
+ 根据 Request 对象和站点配置生成唯一的缓存指纹 (异步)
68
+
69
+ 该函数是缓存系统的核心组件,用于将复杂的 HTTP 请求对象转换为唯一的 SHA-256 字符串。
70
+ 它实现了高度可定制的提取逻辑,允许通过配置排除掉请求中不稳定的因素(如时间戳、Nonce 等)。
71
+
72
+ ### 生成指纹包含的要素:
73
+ 1. **Method**: 请求方法(统一转为大写)。
74
+ 2. **Host & Path**: 请求的域名和路径。
75
+ 3. **Query Params**: URL 查询参数,受 `config.query` 过滤影响。
76
+ 4. **Headers**: 请求头信息,受 `config.headers` 过滤影响。默认排除 `cookie` 头。
77
+ 5. **Cookies**: 特别提取的 Cookie 字段,受 `config.cookies` 过滤影响。
78
+ 6. **Request Body**:
79
+ - 对于 `POST`, `PUT`, `PATCH` 请求,会自动尝试读取 Body。
80
+ - **JSON 类型**: 如果 `Content-Type` 包含 `application/json`,则解析为对象并应用 `config.body` 过滤。
81
+ - **非 JSON/流类型**: 回退到对原始 Body 字节流进行 SHA-256 哈希计算。
82
+ - **安全性**: 使用 `req.clone()` 读取 Body,确保不影响后续真实的 Fetch 请求流消费。
70
83
 
71
84
  #### Parameters
72
85
 
@@ -74,13 +87,28 @@ Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/be
74
87
 
75
88
  `Request`
76
89
 
90
+ 原始 Web 标准 Request 对象。
91
+
77
92
  ##### config
78
93
 
79
94
  [`SiteCacheConfig`](SiteCacheConfig.md)
80
95
 
96
+ 站点级缓存配置,决定了哪些字段参与指纹计算。
97
+
81
98
  #### Returns
82
99
 
83
- `string`
100
+ `Promise`\<`string`\>
101
+
102
+ 返回一个 64 位十六进制的 SHA-256 哈希字符串作为缓存键。
103
+
104
+ #### Example
105
+
106
+ ```typescript
107
+ const cacheKey = await generateCacheKey(request, {
108
+ query: { exclude: ['timestamp'] },
109
+ body: { include: ['id', 'action'] }
110
+ });
111
+ ```
84
112
 
85
113
  ***
86
114
 
@@ -88,7 +116,7 @@ Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/be
88
116
 
89
117
  > `optional` **onBackgroundUpdate**: (`promise`) => `void`
90
118
 
91
- Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L19)
119
+ Defined in: [packages/proxy/src/core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L21)
92
120
 
93
121
  后台更新 Promise 触发时的回调
94
122
 
@@ -6,28 +6,32 @@
6
6
 
7
7
  # Interface: KeyFilterConfig
8
8
 
9
- Defined in: [types.ts:6](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L6)
9
+ Defined in: [packages/proxy/src/types.ts:6](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L6)
10
10
 
11
11
  缓存键过滤配置
12
12
 
13
13
  用于定义在生成缓存指纹时,哪些字段应该被包含或排除。
14
14
 
15
+ ## Extended by
16
+
17
+ - [`BodyFilterConfig`](BodyFilterConfig.md)
18
+
15
19
  ## Properties
16
20
 
17
21
  ### exclude?
18
22
 
19
- > `optional` **exclude**: `string`[]
23
+ > `optional` **exclude**: (`string` \| `RegExp`)[]
20
24
 
21
- Defined in: [types.ts:10](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L10)
25
+ Defined in: [packages/proxy/src/types.ts:10](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L10)
22
26
 
23
- 排除(黑名单):用于排除像 `timestamp`、`nonce` 等干扰缓存命中的动态字段
27
+ 排除(黑名单):用于排除像 `timestamp`、`nonce` 等干扰缓存命中的动态字段。支持字符串、Glob 模式或正则表达式。
24
28
 
25
29
  ***
26
30
 
27
31
  ### include?
28
32
 
29
- > `optional` **include**: `string`[]
33
+ > `optional` **include**: (`string` \| `RegExp`)[]
30
34
 
31
- Defined in: [types.ts:8](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L8)
35
+ Defined in: [packages/proxy/src/types.ts:8](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L8)
32
36
 
33
- 仅包含(白名单):如果设置,只有这些字段会参与 Key 的计算
37
+ 仅包含(白名单):如果设置,只有这些字段会参与 Key 的计算。支持字符串、Glob 模式或正则表达式。
@@ -0,0 +1,107 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / PrefetchOptions
6
+
7
+ # Interface: PrefetchOptions
8
+
9
+ Defined in: [packages/proxy/src/core/prefetch.ts:17](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L17)
10
+
11
+ ## Properties
12
+
13
+ ### cache
14
+
15
+ > **cache**: [`SmartCache`](../classes/SmartCache.md)
16
+
17
+ Defined in: [packages/proxy/src/core/prefetch.ts:23](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L23)
18
+
19
+ SmartCache 实例
20
+
21
+ ***
22
+
23
+ ### concurrency?
24
+
25
+ > `optional` **concurrency**: `number`
26
+
27
+ Defined in: [packages/proxy/src/core/prefetch.ts:27](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L27)
28
+
29
+ 并发数,默认 3
30
+
31
+ ***
32
+
33
+ ### config
34
+
35
+ > **config**: [`ProxyConfig`](ProxyConfig.md)
36
+
37
+ Defined in: [packages/proxy/src/core/prefetch.ts:21](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L21)
38
+
39
+ 完整的代理配置
40
+
41
+ ***
42
+
43
+ ### fetcher()?
44
+
45
+ > `optional` **fetcher**: (`req`) => `Promise`\<`Response`\>
46
+
47
+ Defined in: [packages/proxy/src/core/prefetch.ts:25](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L25)
48
+
49
+ 自定义 fetcher,默认使用 globalThis.fetch
50
+
51
+ #### Parameters
52
+
53
+ ##### req
54
+
55
+ `Request`
56
+
57
+ #### Returns
58
+
59
+ `Promise`\<`Response`\>
60
+
61
+ ***
62
+
63
+ ### onProgress()?
64
+
65
+ > `optional` **onProgress**: (`completed`, `total`, `url`) => `void`
66
+
67
+ Defined in: [packages/proxy/src/core/prefetch.ts:29](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L29)
68
+
69
+ 进度回调 (completed, total, url)
70
+
71
+ #### Parameters
72
+
73
+ ##### completed
74
+
75
+ `number`
76
+
77
+ ##### total
78
+
79
+ `number`
80
+
81
+ ##### url
82
+
83
+ `string`
84
+
85
+ #### Returns
86
+
87
+ `void`
88
+
89
+ ***
90
+
91
+ ### signal?
92
+
93
+ > `optional` **signal**: `AbortSignal`
94
+
95
+ Defined in: [packages/proxy/src/core/prefetch.ts:31](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L31)
96
+
97
+ 取消信号
98
+
99
+ ***
100
+
101
+ ### urls
102
+
103
+ > **urls**: [`PrefetchRequest`](PrefetchRequest.md)[]
104
+
105
+ Defined in: [packages/proxy/src/core/prefetch.ts:19](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L19)
106
+
107
+ 要预缓存的 URL 列表及其请求选项
@@ -0,0 +1,31 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / PrefetchRequest
6
+
7
+ # Interface: PrefetchRequest
8
+
9
+ Defined in: [packages/proxy/src/core/prefetch.ts:10](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L10)
10
+
11
+ 预缓存请求选项
12
+
13
+ ## Properties
14
+
15
+ ### request?
16
+
17
+ > `optional` **request**: `RequestInit`
18
+
19
+ Defined in: [packages/proxy/src/core/prefetch.ts:14](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L14)
20
+
21
+ 可选的请求配置(method, headers, body 等)
22
+
23
+ ***
24
+
25
+ ### url
26
+
27
+ > **url**: `string`
28
+
29
+ Defined in: [packages/proxy/src/core/prefetch.ts:12](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L12)
30
+
31
+ 请求 URL
@@ -0,0 +1,47 @@
1
+ [**@isdk/proxy**](../README.md)
2
+
3
+ ***
4
+
5
+ [@isdk/proxy](../globals.md) / PrefetchResult
6
+
7
+ # Interface: PrefetchResult
8
+
9
+ Defined in: [packages/proxy/src/core/prefetch.ts:34](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L34)
10
+
11
+ ## Properties
12
+
13
+ ### errors?
14
+
15
+ > `optional` **errors**: `object`[]
16
+
17
+ Defined in: [packages/proxy/src/core/prefetch.ts:40](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L40)
18
+
19
+ 失败详情
20
+
21
+ #### error
22
+
23
+ > **error**: `Error`
24
+
25
+ #### url
26
+
27
+ > **url**: `string`
28
+
29
+ ***
30
+
31
+ ### failed
32
+
33
+ > **failed**: `number`
34
+
35
+ Defined in: [packages/proxy/src/core/prefetch.ts:38](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L38)
36
+
37
+ 失败数量
38
+
39
+ ***
40
+
41
+ ### succeeded
42
+
43
+ > **succeeded**: `number`
44
+
45
+ Defined in: [packages/proxy/src/core/prefetch.ts:36](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L36)
46
+
47
+ 成功数量
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Interface: ProxyConfig
8
8
 
9
- Defined in: [types.ts:63](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L63)
9
+ Defined in: [packages/proxy/src/types.ts:147](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L147)
10
10
 
11
11
  代理拦截器全局配置
12
12
 
@@ -16,7 +16,7 @@ Defined in: [types.ts:63](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
16
16
 
17
17
  > **default**: [`SiteCacheConfig`](SiteCacheConfig.md)
18
18
 
19
- Defined in: [types.ts:65](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L65)
19
+ Defined in: [packages/proxy/src/types.ts:149](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L149)
20
20
 
21
21
  默认缓存配置,当请求的域名未在 sites 中匹配时使用
22
22
 
@@ -26,7 +26,7 @@ Defined in: [types.ts:65](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
26
26
 
27
27
  > **sites**: `Record`\<`string`, [`SiteCacheConfig`](SiteCacheConfig.md)\>
28
28
 
29
- Defined in: [types.ts:67](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L67)
29
+ Defined in: [packages/proxy/src/types.ts:151](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L151)
30
30
 
31
31
  针对特定域名的精细化缓存配置
32
32
 
@@ -36,6 +36,6 @@ Defined in: [types.ts:67](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe
36
36
 
37
37
  > `optional` **storagePath**: `string`
38
38
 
39
- Defined in: [types.ts:69](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L69)
39
+ Defined in: [packages/proxy/src/types.ts:153](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L153)
40
40
 
41
41
  磁盘缓存(cacache)的物理存储路径,可选,默认为系统临时目录