@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,18 +6,23 @@
|
|
|
6
6
|
|
|
7
7
|
# Function: extractData()
|
|
8
8
|
|
|
9
|
-
> **extractData**(`source`, `config?`): `Record`\<`string`, `string`[]\>
|
|
9
|
+
> **extractData**(`source`, `config?`, `defaultAllowed?`): `Record`\<`string`, `string`[]\>
|
|
10
10
|
|
|
11
|
-
Defined in: [utils/extractData.ts:
|
|
11
|
+
Defined in: [packages/proxy/src/utils/extractData.ts:40](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/utils/extractData.ts#L40)
|
|
12
12
|
|
|
13
13
|
从源对象中根据过滤配置提取数据并标准化。
|
|
14
14
|
|
|
15
15
|
此函数主要用于生成缓存指纹。它会:
|
|
16
|
-
1. 根据 `config` (include/exclude)
|
|
16
|
+
1. 根据 `config` (include/exclude) 过滤键,调用 `isAllowed` 判断每个键是否允许。
|
|
17
17
|
2. 对键进行排序以保证指纹的一致性。
|
|
18
18
|
3. 将所有键转换为小写。
|
|
19
19
|
4. 将值统一包装为数组并进行排序,消除数组项顺序差异。
|
|
20
20
|
|
|
21
|
+
**关于 `defaultAllowed` 参数**:
|
|
22
|
+
- 只有当没有配置 `include` 和 `exclude` 时,`defaultAllowed` 才会生效。
|
|
23
|
+
- 如果配置了 `include`(即使为空数组),`defaultAllowed` 也不会生效。
|
|
24
|
+
- 详见 `isAllowed` 函数的优先级逻辑。
|
|
25
|
+
|
|
21
26
|
## Parameters
|
|
22
27
|
|
|
23
28
|
### source
|
|
@@ -30,10 +35,34 @@ Defined in: [utils/extractData.ts:17](https://github.com/isdk/proxy.js/blob/bed3
|
|
|
30
35
|
|
|
31
36
|
[`KeyFilterConfig`](../interfaces/KeyFilterConfig.md)
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
过滤配置,支持 `include`(白名单)和 `exclude`(黑名单)
|
|
39
|
+
|
|
40
|
+
### defaultAllowed?
|
|
41
|
+
|
|
42
|
+
`boolean`
|
|
43
|
+
|
|
44
|
+
当没有配置时的默认值(默认 `false`,即不提取任何键)
|
|
34
45
|
|
|
35
46
|
## Returns
|
|
36
47
|
|
|
37
48
|
`Record`\<`string`, `string`[]\>
|
|
38
49
|
|
|
39
|
-
标准化后的数据 Map
|
|
50
|
+
标准化后的数据 Map,键为小写,值为排序后的字符串数组
|
|
51
|
+
|
|
52
|
+
## Example
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const headers = { 'Content-Type': 'application/json', 'X-Request-Id': '123' };
|
|
56
|
+
|
|
57
|
+
// 默认不提取任何键
|
|
58
|
+
extractData(headers); // {}
|
|
59
|
+
|
|
60
|
+
// 提取所有键
|
|
61
|
+
extractData(headers, undefined, true); // { 'content-type': ['application/json'], 'x-request-id': ['123'] }
|
|
62
|
+
|
|
63
|
+
// 白名单
|
|
64
|
+
extractData(headers, { include: ['content-type'] }); // { 'content-type': ['application/json'] }
|
|
65
|
+
|
|
66
|
+
// 黑名单(需要 include 或 defaultAllowed)
|
|
67
|
+
extractData(headers, { include: ['*'], exclude: ['x-request-id'] }, true); // { 'content-type': ['application/json'] }
|
|
68
|
+
```
|
|
@@ -8,17 +8,18 @@
|
|
|
8
8
|
|
|
9
9
|
> **fetchWithCache**(`request`, `fetcher`, `options`): `Promise`\<`Response`\>
|
|
10
10
|
|
|
11
|
-
Defined in: [core/fetchWithCache.ts:
|
|
11
|
+
Defined in: [packages/proxy/src/core/fetchWithCache.ts:234](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/fetchWithCache.ts#L234)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
核心协调函数:协调请求、缓存命中、并发控制和 SWR
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
流程如下:
|
|
16
|
+
1. 初始化上下文并生成缓存键。
|
|
17
|
+
2. 检查离线模式:若开启则强读取,未命中直接抛错。
|
|
18
|
+
3. 检查请求是否符合缓存规则 (isCacheable)。
|
|
19
|
+
4. 尝试读取缓存并判定状态 (HIT / STALE)。
|
|
20
|
+
5. 处理 SWR (后台更新)。
|
|
21
|
+
6. 处理请求合并 (Request Coalescing),防止缓存击穿。
|
|
22
|
+
7. 若缓存缺失,发起网络请求并流式写入。
|
|
22
23
|
|
|
23
24
|
## Parameters
|
|
24
25
|
|
|
@@ -26,14 +27,22 @@ Defined in: [core/fetchWithCache.ts:244](https://github.com/isdk/proxy.js/blob/b
|
|
|
26
27
|
|
|
27
28
|
`Request`
|
|
28
29
|
|
|
30
|
+
标准 Web Request 对象
|
|
31
|
+
|
|
29
32
|
### fetcher
|
|
30
33
|
|
|
31
34
|
(`req`) => `Promise`\<`Response`\>
|
|
32
35
|
|
|
36
|
+
底层发起真实请求的函数
|
|
37
|
+
|
|
33
38
|
### options
|
|
34
39
|
|
|
35
40
|
[`FetchWithCacheOptions`](../interfaces/FetchWithCacheOptions.md)
|
|
36
41
|
|
|
42
|
+
缓存协调配置项
|
|
43
|
+
|
|
37
44
|
## Returns
|
|
38
45
|
|
|
39
46
|
`Promise`\<`Response`\>
|
|
47
|
+
|
|
48
|
+
标准 Web Response 对象 (带 x-proxy-cache 标头)
|
|
@@ -6,11 +6,26 @@
|
|
|
6
6
|
|
|
7
7
|
# Function: generateCacheKey()
|
|
8
8
|
|
|
9
|
-
> **generateCacheKey**(`req`, `config`): `string
|
|
9
|
+
> **generateCacheKey**(`req`, `config`): `Promise`\<`string`\>
|
|
10
10
|
|
|
11
|
-
Defined in: [core/generateCacheKey.ts:
|
|
11
|
+
Defined in: [packages/proxy/src/core/generateCacheKey.ts:36](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/generateCacheKey.ts#L36)
|
|
12
12
|
|
|
13
|
-
根据 Request
|
|
13
|
+
根据 Request 对象和站点配置生成唯一的缓存指纹 (异步)
|
|
14
|
+
|
|
15
|
+
该函数是缓存系统的核心组件,用于将复杂的 HTTP 请求对象转换为唯一的 SHA-256 字符串。
|
|
16
|
+
它实现了高度可定制的提取逻辑,允许通过配置排除掉请求中不稳定的因素(如时间戳、Nonce 等)。
|
|
17
|
+
|
|
18
|
+
### 生成指纹包含的要素:
|
|
19
|
+
1. **Method**: 请求方法(统一转为大写)。
|
|
20
|
+
2. **Host & Path**: 请求的域名和路径。
|
|
21
|
+
3. **Query Params**: URL 查询参数,受 `config.query` 过滤影响。
|
|
22
|
+
4. **Headers**: 请求头信息,受 `config.headers` 过滤影响。默认排除 `cookie` 头。
|
|
23
|
+
5. **Cookies**: 特别提取的 Cookie 字段,受 `config.cookies` 过滤影响。
|
|
24
|
+
6. **Request Body**:
|
|
25
|
+
- 对于 `POST`, `PUT`, `PATCH` 请求,会自动尝试读取 Body。
|
|
26
|
+
- **JSON 类型**: 如果 `Content-Type` 包含 `application/json`,则解析为对象并应用 `config.body` 过滤。
|
|
27
|
+
- **非 JSON/流类型**: 回退到对原始 Body 字节流进行 SHA-256 哈希计算。
|
|
28
|
+
- **安全性**: 使用 `req.clone()` 读取 Body,确保不影响后续真实的 Fetch 请求流消费。
|
|
14
29
|
|
|
15
30
|
## Parameters
|
|
16
31
|
|
|
@@ -18,10 +33,25 @@ Defined in: [core/generateCacheKey.ts:8](https://github.com/isdk/proxy.js/blob/b
|
|
|
18
33
|
|
|
19
34
|
`Request`
|
|
20
35
|
|
|
36
|
+
原始 Web 标准 Request 对象。
|
|
37
|
+
|
|
21
38
|
### config
|
|
22
39
|
|
|
23
40
|
[`SiteCacheConfig`](../interfaces/SiteCacheConfig.md)
|
|
24
41
|
|
|
42
|
+
站点级缓存配置,决定了哪些字段参与指纹计算。
|
|
43
|
+
|
|
25
44
|
## Returns
|
|
26
45
|
|
|
27
|
-
`string
|
|
46
|
+
`Promise`\<`string`\>
|
|
47
|
+
|
|
48
|
+
返回一个 64 位十六进制的 SHA-256 哈希字符串作为缓存键。
|
|
49
|
+
|
|
50
|
+
## Example
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const cacheKey = await generateCacheKey(request, {
|
|
54
|
+
query: { exclude: ['timestamp'] },
|
|
55
|
+
body: { include: ['id', 'action'] }
|
|
56
|
+
});
|
|
57
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / getSiteConfig
|
|
6
|
+
|
|
7
|
+
# Function: getSiteConfig()
|
|
8
|
+
|
|
9
|
+
> **getSiteConfig**(`urlString`, `proxyConfig`): [`SiteCacheConfig`](../interfaces/SiteCacheConfig.md)
|
|
10
|
+
|
|
11
|
+
Defined in: [packages/proxy/src/utils/getSiteConfig.ts:17](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/utils/getSiteConfig.ts#L17)
|
|
12
|
+
|
|
13
|
+
根据 URL 获取对应的站点缓存配置
|
|
14
|
+
|
|
15
|
+
匹配逻辑:
|
|
16
|
+
1. 遍历 sites 中的所有 key。
|
|
17
|
+
2. 如果 key 是正则或 Glob 格式字符串,则对完整 URL 进行匹配。
|
|
18
|
+
3. 如果 key 是普通字符串,则作为 URL 前缀进行匹配。
|
|
19
|
+
4. 返回第一个匹配到的配置;若均未匹配,则返回 defaultConfig。
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### urlString
|
|
24
|
+
|
|
25
|
+
`string`
|
|
26
|
+
|
|
27
|
+
请求的完整 URL
|
|
28
|
+
|
|
29
|
+
### proxyConfig
|
|
30
|
+
|
|
31
|
+
[`ProxyConfig`](../interfaces/ProxyConfig.md)
|
|
32
|
+
|
|
33
|
+
全局代理配置
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
[`SiteCacheConfig`](../interfaces/SiteCacheConfig.md)
|
|
38
|
+
|
|
39
|
+
匹配到的站点配置
|
|
@@ -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:
|
|
11
|
+
Defined in: [packages/proxy/src/utils/isAllowed.ts:37](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/utils/isAllowed.ts#L37)
|
|
12
12
|
|
|
13
13
|
判断给定的键是否允许参与缓存指纹计算。
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
1.
|
|
17
|
-
2.
|
|
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,27 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / isCacheable
|
|
6
|
+
|
|
7
|
+
# Function: isCacheable()
|
|
8
|
+
|
|
9
|
+
> **isCacheable**(`request`, `config`): `Promise`\<`boolean`\>
|
|
10
|
+
|
|
11
|
+
Defined in: [packages/proxy/src/core/isCacheable.ts:56](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/isCacheable.ts#L56)
|
|
12
|
+
|
|
13
|
+
判断当前请求是否满足可缓存的基础条件
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### request
|
|
18
|
+
|
|
19
|
+
`Request`
|
|
20
|
+
|
|
21
|
+
### config
|
|
22
|
+
|
|
23
|
+
[`SiteCacheConfig`](../interfaces/SiteCacheConfig.md)
|
|
24
|
+
|
|
25
|
+
## Returns
|
|
26
|
+
|
|
27
|
+
`Promise`\<`boolean`\>
|
|
@@ -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: [packages/proxy/src/utils/matcher.ts:7](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/utils/matcher.ts:25](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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`
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / prefetch
|
|
6
|
+
|
|
7
|
+
# Function: prefetch()
|
|
8
|
+
|
|
9
|
+
> **prefetch**(`options`): `Promise`\<[`PrefetchResult`](../interfaces/PrefetchResult.md)\>
|
|
10
|
+
|
|
11
|
+
Defined in: [packages/proxy/src/core/prefetch.ts:55](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/core/prefetch.ts#L55)
|
|
12
|
+
|
|
13
|
+
预缓存函数
|
|
14
|
+
|
|
15
|
+
提前将指定的 URL 列表内容存入缓存,支持并发控制和进度回调。
|
|
16
|
+
复用了 `createCachedFetch` 的完整逻辑,自动支持:
|
|
17
|
+
- GET/POST/PUT/PATCH/DELETE 等所有方法
|
|
18
|
+
- POST body 过滤和缓存键生成
|
|
19
|
+
- 站点级配置
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### options
|
|
24
|
+
|
|
25
|
+
[`PrefetchOptions`](../interfaces/PrefetchOptions.md)
|
|
26
|
+
|
|
27
|
+
预缓存选项
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`Promise`\<[`PrefetchResult`](../interfaces/PrefetchResult.md)\>
|
|
32
|
+
|
|
33
|
+
预缓存结果,包含成功/失败数量和错误详情
|
package/docs/globals.md
CHANGED
|
@@ -6,19 +6,29 @@
|
|
|
6
6
|
|
|
7
7
|
## Classes
|
|
8
8
|
|
|
9
|
+
- [OfflineCacheMissError](classes/OfflineCacheMissError.md)
|
|
9
10
|
- [SmartCache](classes/SmartCache.md)
|
|
10
11
|
|
|
11
12
|
## Interfaces
|
|
12
13
|
|
|
14
|
+
- [BodyFilterConfig](interfaces/BodyFilterConfig.md)
|
|
13
15
|
- [CacheEntry](interfaces/CacheEntry.md)
|
|
14
16
|
- [CacheMetadata](interfaces/CacheMetadata.md)
|
|
17
|
+
- [CacheRule](interfaces/CacheRule.md)
|
|
15
18
|
- [FetchWithCacheContext](interfaces/FetchWithCacheContext.md)
|
|
16
19
|
- [FetchWithCacheOptions](interfaces/FetchWithCacheOptions.md)
|
|
17
20
|
- [KeyFilterConfig](interfaces/KeyFilterConfig.md)
|
|
21
|
+
- [PrefetchOptions](interfaces/PrefetchOptions.md)
|
|
22
|
+
- [PrefetchRequest](interfaces/PrefetchRequest.md)
|
|
23
|
+
- [PrefetchResult](interfaces/PrefetchResult.md)
|
|
18
24
|
- [ProxyConfig](interfaces/ProxyConfig.md)
|
|
19
25
|
- [SiteCacheConfig](interfaces/SiteCacheConfig.md)
|
|
20
26
|
- [SmartCacheOptions](interfaces/SmartCacheOptions.md)
|
|
21
27
|
|
|
28
|
+
## Variables
|
|
29
|
+
|
|
30
|
+
- [OfflineCacheMissErrorCode](variables/OfflineCacheMissErrorCode.md)
|
|
31
|
+
|
|
22
32
|
## Functions
|
|
23
33
|
|
|
24
34
|
- [createCachedFetch](functions/createCachedFetch.md)
|
|
@@ -26,4 +36,9 @@
|
|
|
26
36
|
- [extractData](functions/extractData.md)
|
|
27
37
|
- [fetchWithCache](functions/fetchWithCache.md)
|
|
28
38
|
- [generateCacheKey](functions/generateCacheKey.md)
|
|
39
|
+
- [getSiteConfig](functions/getSiteConfig.md)
|
|
29
40
|
- [isAllowed](functions/isAllowed.md)
|
|
41
|
+
- [isCacheable](functions/isCacheable.md)
|
|
42
|
+
- [isGlob](functions/isGlob.md)
|
|
43
|
+
- [isMatch](functions/isMatch.md)
|
|
44
|
+
- [prefetch](functions/prefetch.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: [packages/proxy/src/types.ts:13](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:10](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:18](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L18)
|
|
40
|
+
|
|
41
|
+
用于非 JSON (文本) Body 的提取正则表达式。
|
|
42
|
+
如果包含捕获组,则提取捕获组内容作为指纹;否则提取整个匹配部分。
|
|
43
|
+
|
|
44
|
+
***
|
|
45
|
+
|
|
46
|
+
### include?
|
|
47
|
+
|
|
48
|
+
> `optional` **include**: (`string` \| `RegExp`)[]
|
|
49
|
+
|
|
50
|
+
Defined in: [packages/proxy/src/types.ts:8](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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: [packages/proxy/src/types.ts:25](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L25)
|
|
65
|
+
|
|
66
|
+
用于正则匹配/提取 Body 时的最大长度限制,默认 1024 (1KB)
|
|
67
|
+
|
|
68
|
+
***
|
|
69
|
+
|
|
70
|
+
### sort?
|
|
71
|
+
|
|
72
|
+
> `optional` **sort**: `boolean`
|
|
73
|
+
|
|
74
|
+
Defined in: [packages/proxy/src/types.ts:23](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/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:
|
|
9
|
+
Defined in: [packages/proxy/src/types.ts:139](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L139)
|
|
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:
|
|
23
|
+
Defined in: [packages/proxy/src/types.ts:141](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L141)
|
|
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:
|
|
33
|
+
Defined in: [packages/proxy/src/types.ts:123](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L123)
|
|
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:
|
|
47
|
+
Defined in: [packages/proxy/src/types.ts:129](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L129)
|
|
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:
|
|
61
|
+
Defined in: [packages/proxy/src/types.ts:125](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L125)
|
|
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:
|
|
75
|
+
Defined in: [packages/proxy/src/types.ts:133](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L133)
|
|
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:
|
|
89
|
+
Defined in: [packages/proxy/src/types.ts:121](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L121)
|
|
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:
|
|
103
|
+
Defined in: [packages/proxy/src/types.ts:131](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L131)
|
|
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:
|
|
117
|
+
Defined in: [packages/proxy/src/types.ts:127](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L127)
|
|
118
118
|
|
|
119
119
|
原始请求 URL
|
|
120
120
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: CacheMetadata
|
|
8
8
|
|
|
9
|
-
Defined in: [types.ts:
|
|
9
|
+
Defined in: [packages/proxy/src/types.ts:119](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L119)
|
|
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:
|
|
26
|
+
Defined in: [packages/proxy/src/types.ts:123](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L123)
|
|
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:
|
|
36
|
+
Defined in: [packages/proxy/src/types.ts:129](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L129)
|
|
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:
|
|
46
|
+
Defined in: [packages/proxy/src/types.ts:125](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L125)
|
|
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:
|
|
56
|
+
Defined in: [packages/proxy/src/types.ts:133](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L133)
|
|
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:
|
|
66
|
+
Defined in: [packages/proxy/src/types.ts:121](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L121)
|
|
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:
|
|
76
|
+
Defined in: [packages/proxy/src/types.ts:131](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L131)
|
|
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:
|
|
86
|
+
Defined in: [packages/proxy/src/types.ts:127](https://github.com/isdk/proxy.js/blob/a1563efa4c3081261eb3af8a6404f1b704b33bf1/src/types.ts#L127)
|
|
87
87
|
|
|
88
88
|
原始请求 URL
|