@lytjs/runtime-edge 6.5.0 → 6.6.0

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 (2) hide show
  1. package/README.md +104 -104
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,104 +1,104 @@
1
- # @lytjs/runtime-edge
2
-
3
- LytJS 边缘运行时支持,为边缘计算环境提供完整的支持。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- pnpm add @lytjs/runtime-edge
9
- ```
10
-
11
- ## 快速开始
12
-
13
- ### 边缘路由器
14
-
15
- ```typescript
16
- import { createEdgeRouter } from '@lytjs/runtime-edge';
17
-
18
- const router = createEdgeRouter({
19
- basePath: '/api',
20
- });
21
-
22
- router.get('/users', (req, ctx) => {
23
- return new Response(JSON.stringify({ users: [] }), {
24
- status: 200,
25
- headers: { 'Content-Type': 'application/json' },
26
- });
27
- });
28
-
29
- export default {
30
- async fetch(request, env, ctx) {
31
- return router.handle(request, ctx);
32
- },
33
- };
34
- ```
35
-
36
- ### 边缘缓存
37
-
38
- ```typescript
39
- import { createEdgeCache } from '@lytjs/runtime-edge';
40
-
41
- const cache = createEdgeCache();
42
-
43
- // 设置缓存
44
- await cache.set('key', { data: 'value' }, { ttl: 60000 });
45
-
46
- // 获取缓存
47
- const value = await cache.get('key');
48
- ```
49
-
50
- ### 响应辅助工具
51
-
52
- ```typescript
53
- import { jsonResponse, textResponse, htmlResponse, redirectResponse } from '@lytjs/runtime-edge';
54
-
55
- // JSON 响应
56
- return jsonResponse({ success: true }, 200);
57
-
58
- // 文本响应
59
- return textResponse('Hello World', 200);
60
-
61
- // HTML 响应
62
- return htmlResponse('<html><body>Hello</body></html>', 200);
63
-
64
- // 重定向响应
65
- return redirectResponse('https://example.com', 302);
66
- ```
67
-
68
- ## 特性
69
-
70
- - 边缘函数支持
71
- - 边缘路由器
72
- - 内存缓存
73
- - 响应辅助工具
74
- - 零外部依赖
75
-
76
- ## API
77
-
78
- ### createEdgeRouter(options)
79
-
80
- 创建边缘路由器实例。
81
-
82
- ### createEdgeCache()
83
-
84
- 创建边缘缓存实例。
85
-
86
- ### jsonResponse(data, status)
87
-
88
- 创建 JSON 响应。
89
-
90
- ### textResponse(text, status)
91
-
92
- 创建文本响应。
93
-
94
- ### htmlResponse(html, status)
95
-
96
- 创建 HTML 响应。
97
-
98
- ### redirectResponse(url, status)
99
-
100
- 创建重定向响应。
101
-
102
- ## 许可证
103
-
104
- MIT
1
+ # @lytjs/runtime-edge
2
+
3
+ LytJS 边缘运行时支持,为边缘计算环境提供完整的支持。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @lytjs/runtime-edge
9
+ ```
10
+
11
+ ## 快速开始
12
+
13
+ ### 边缘路由器
14
+
15
+ ```typescript
16
+ import { createEdgeRouter } from '@lytjs/runtime-edge';
17
+
18
+ const router = createEdgeRouter({
19
+ basePath: '/api',
20
+ });
21
+
22
+ router.get('/users', (req, ctx) => {
23
+ return new Response(JSON.stringify({ users: [] }), {
24
+ status: 200,
25
+ headers: { 'Content-Type': 'application/json' },
26
+ });
27
+ });
28
+
29
+ export default {
30
+ async fetch(request, env, ctx) {
31
+ return router.handle(request, ctx);
32
+ },
33
+ };
34
+ ```
35
+
36
+ ### 边缘缓存
37
+
38
+ ```typescript
39
+ import { createEdgeCache } from '@lytjs/runtime-edge';
40
+
41
+ const cache = createEdgeCache();
42
+
43
+ // 设置缓存
44
+ await cache.set('key', { data: 'value' }, { ttl: 60000 });
45
+
46
+ // 获取缓存
47
+ const value = await cache.get('key');
48
+ ```
49
+
50
+ ### 响应辅助工具
51
+
52
+ ```typescript
53
+ import { jsonResponse, textResponse, htmlResponse, redirectResponse } from '@lytjs/runtime-edge';
54
+
55
+ // JSON 响应
56
+ return jsonResponse({ success: true }, 200);
57
+
58
+ // 文本响应
59
+ return textResponse('Hello World', 200);
60
+
61
+ // HTML 响应
62
+ return htmlResponse('<html><body>Hello</body></html>', 200);
63
+
64
+ // 重定向响应
65
+ return redirectResponse('https://example.com', 302);
66
+ ```
67
+
68
+ ## 特性
69
+
70
+ - 边缘函数支持
71
+ - 边缘路由器
72
+ - 内存缓存
73
+ - 响应辅助工具
74
+ - 零外部依赖
75
+
76
+ ## API
77
+
78
+ ### createEdgeRouter(options)
79
+
80
+ 创建边缘路由器实例。
81
+
82
+ ### createEdgeCache()
83
+
84
+ 创建边缘缓存实例。
85
+
86
+ ### jsonResponse(data, status)
87
+
88
+ 创建 JSON 响应。
89
+
90
+ ### textResponse(text, status)
91
+
92
+ 创建文本响应。
93
+
94
+ ### htmlResponse(html, status)
95
+
96
+ 创建 HTML 响应。
97
+
98
+ ### redirectResponse(url, status)
99
+
100
+ 创建重定向响应。
101
+
102
+ ## 许可证
103
+
104
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lytjs/runtime-edge",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "description": "LytJS edge runtime support for serverless and edge computing environments",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",