@ureq/business 0.0.3 → 0.0.4

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 +35 -21
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -14,38 +14,52 @@ pnpm add @ureq/business
14
14
 
15
15
  ## 功能
16
16
 
17
- ### HashService
17
+ ### LibHashService
18
18
 
19
- 提供请求哈希生成功能,用于请求去重和缓存键生成。
19
+ 提供请求哈希生成功能,基于 `@ureq/lib-hash`。
20
20
 
21
21
  ```typescript
22
- import { DefaultHashService } from '@ureq/business';
22
+ import { LibHashService } from '@ureq/business';
23
+
24
+ const hashService = new LibHashService();
23
25
 
24
- const hashService = new DefaultHashService();
26
+ // 生成字符串哈希
27
+ const hash = hashService.generateHash('some-string');
25
28
 
26
29
  // 生成请求哈希
27
- const hash = hashService.generateRequestHash(
30
+ const requestHash = hashService.generateRequestHash(
28
31
  'GET',
29
32
  '/api/users',
30
33
  null,
31
34
  { params: { page: 1 } }
32
35
  );
33
-
34
- // 生成字符串哈希
35
- const strHash = hashService.hashString('some-string');
36
36
  ```
37
37
 
38
- ### CacheStore
38
+ ### LibCacheStore
39
39
 
40
- 提供缓存存储的接口定义。
40
+ 提供缓存存储功能,基于 `@ureq/lib-cache-store`。
41
41
 
42
42
  ```typescript
43
- interface CacheStore {
44
- get<T>(key: string): Promise<T | null>;
45
- set<T>(key: string, value: T, ttl: number): Promise<void>;
46
- delete(key: string): Promise<void>;
47
- clear(): Promise<void>;
48
- }
43
+ import { LibCacheStore } from '@ureq/business';
44
+ import { MemoryStore } from '@ureq/lib-cache-store';
45
+
46
+ const memoryStore = new MemoryStore();
47
+ const cacheStore = new LibCacheStore(memoryStore);
48
+
49
+ // 存储数据
50
+ await cacheStore.set('key', { data: 'value' }, 60000);
51
+
52
+ // 获取数据
53
+ const data = await cacheStore.get('key');
54
+
55
+ // 检查是否存在
56
+ const exists = await cacheStore.has('key');
57
+
58
+ // 删除数据
59
+ await cacheStore.delete('key');
60
+
61
+ // 清空缓存
62
+ await cacheStore.clear();
49
63
  ```
50
64
 
51
65
  ## 接口
@@ -54,14 +68,13 @@ interface CacheStore {
54
68
 
55
69
  ```typescript
56
70
  interface HashService {
71
+ generateHash(input: string): string;
57
72
  generateRequestHash(
58
73
  method: string,
59
74
  url: string,
60
75
  data?: any,
61
- options?: RequestOptions
76
+ options?: Record<string, any>
62
77
  ): string;
63
-
64
- hashString(str: string): string;
65
78
  }
66
79
  ```
67
80
 
@@ -69,10 +82,11 @@ interface HashService {
69
82
 
70
83
  ```typescript
71
84
  interface CacheStore {
72
- get<T>(key: string): Promise<T | null>;
73
- set<T>(key: string, value: T, ttl: number): Promise<void>;
85
+ get<T>(key: string): Promise<T | undefined>;
86
+ set<T>(key: string, value: T, ttl?: number): Promise<void>;
74
87
  delete(key: string): Promise<void>;
75
88
  clear(): Promise<void>;
89
+ has(key: string): Promise<boolean>;
76
90
  }
77
91
  ```
78
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ureq/business",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Universal request library business logic",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -19,8 +19,8 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@ureq/lib-hash": "0.0.3",
23
- "@ureq/lib-cache-store": "0.0.3"
22
+ "@ureq/lib-cache-store": "0.0.4",
23
+ "@ureq/lib-hash": "0.0.4"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "^8.3.6",
@@ -29,6 +29,6 @@
29
29
  "scripts": {
30
30
  "build": "tsup --config tsup.config.ts",
31
31
  "dev": "tsup --config tsup.config.ts --watch",
32
- "test": "vitest"
32
+ "test": "vitest --run"
33
33
  }
34
34
  }