@ureq/business 0.0.2 → 0.0.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.md ADDED
@@ -0,0 +1,129 @@
1
+ # @ureq/business
2
+
3
+ 业务抽象层,提供 Hash 和 Cache 服务的接口定义和默认实现。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @ureq/business
9
+ # 或
10
+ pnpm add @ureq/business
11
+ ```
12
+
13
+ > 注意:通常作为 `@ureq/core` 的依赖自动安装,无需单独安装
14
+
15
+ ## 功能
16
+
17
+ ### HashService
18
+
19
+ 提供请求哈希生成功能,用于请求去重和缓存键生成。
20
+
21
+ ```typescript
22
+ import { DefaultHashService } from '@ureq/business';
23
+
24
+ const hashService = new DefaultHashService();
25
+
26
+ // 生成请求哈希
27
+ const hash = hashService.generateRequestHash(
28
+ 'GET',
29
+ '/api/users',
30
+ null,
31
+ { params: { page: 1 } }
32
+ );
33
+
34
+ // 生成字符串哈希
35
+ const strHash = hashService.hashString('some-string');
36
+ ```
37
+
38
+ ### CacheStore
39
+
40
+ 提供缓存存储的接口定义。
41
+
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
+ }
49
+ ```
50
+
51
+ ## 接口
52
+
53
+ ### HashService
54
+
55
+ ```typescript
56
+ interface HashService {
57
+ generateRequestHash(
58
+ method: string,
59
+ url: string,
60
+ data?: any,
61
+ options?: RequestOptions
62
+ ): string;
63
+
64
+ hashString(str: string): string;
65
+ }
66
+ ```
67
+
68
+ ### CacheStore
69
+
70
+ ```typescript
71
+ interface CacheStore {
72
+ get<T>(key: string): Promise<T | null>;
73
+ set<T>(key: string, value: T, ttl: number): Promise<void>;
74
+ delete(key: string): Promise<void>;
75
+ clear(): Promise<void>;
76
+ }
77
+ ```
78
+
79
+ ## 自定义实现
80
+
81
+ ### 自定义 HashService
82
+
83
+ ```typescript
84
+ import { HashService } from '@ureq/business';
85
+
86
+ class MyHashService implements HashService {
87
+ generateRequestHash(method: string, url: string, data?: any, options?: any): string {
88
+ // 自定义哈希生成逻辑
89
+ return `${method}:${url}`;
90
+ }
91
+
92
+ hashString(str: string): string {
93
+ // 自定义字符串哈希
94
+ return btoa(str);
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### 自定义 CacheStore
100
+
101
+ ```typescript
102
+ import { CacheStore } from '@ureq/business';
103
+
104
+ class MyCache implements CacheStore {
105
+ async get<T>(key: string): Promise<T | null> {
106
+ // 实现获取逻辑
107
+ }
108
+
109
+ async set<T>(key: string, value: T, ttl: number): Promise<void> {
110
+ // 实现存储逻辑
111
+ }
112
+
113
+ async delete(key: string): Promise<void> {
114
+ // 实现删除逻辑
115
+ }
116
+
117
+ async clear(): Promise<void> {
118
+ // 实现清空逻辑
119
+ }
120
+ }
121
+ ```
122
+
123
+ ## 文档
124
+
125
+ 查看完整文档:[https://sunny-117.github.io/ureq](https://sunny-117.github.io/ureq)
126
+
127
+ ## License
128
+
129
+ MIT
package/dist/index.js CHANGED
@@ -1,2 +1,96 @@
1
- 'use strict';var libHash=require('@ureq/lib-hash'),libCacheStore=require('@ureq/lib-cache-store');var i=class{generateHash(e){let r=0;for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);r=(r<<5)-r+s,r=r&r;}return r.toString(36)}generateRequestHash(e,r,t,s){let c=[e.toUpperCase(),r,t?JSON.stringify(t):"",s?JSON.stringify(s):""];return this.generateHash(c.join("|"))}};var o=class{constructor(){this.cache=new Map;}get(e){let r=this.cache.get(e);if(r){if(r.expires&&Date.now()>r.expires){this.cache.delete(e);return}return r.value}}set(e,r,t){let s=t?Date.now()+t:void 0;this.cache.set(e,{value:r,expires:s});}delete(e){this.cache.delete(e);}clear(){this.cache.clear();}has(e){let r=this.cache.get(e);return r?r.expires&&Date.now()>r.expires?(this.cache.delete(e),false):true:false}};var a=class{generateHash(e){return libHash.generateHash(e)}generateRequestHash(e,r,t,s){return libHash.generateRequestHash(e,r,t,s)}};var g=class{constructor(e){this.store=e||new libCacheStore.MemoryStore;}async get(e){return this.store.get(e)}async set(e,r,t){return this.store.set(e,r,t)}async delete(e){return this.store.delete(e)}async clear(){return this.store.clear()}async has(e){return this.store.has(e)}};exports.DefaultHashService=i;exports.LibCacheStore=g;exports.LibHashService=a;exports.MemoryCacheStore=o;//# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ var libHash = require('@ureq/lib-hash');
4
+ var libCacheStore = require('@ureq/lib-cache-store');
5
+
6
+ // src/interfaces/hash.ts
7
+ var DefaultHashService = class {
8
+ generateHash(input) {
9
+ let hash = 0;
10
+ for (let i = 0; i < input.length; i++) {
11
+ const char = input.charCodeAt(i);
12
+ hash = (hash << 5) - hash + char;
13
+ hash = hash & hash;
14
+ }
15
+ return hash.toString(36);
16
+ }
17
+ generateRequestHash(method, url, data, options) {
18
+ const parts = [
19
+ method.toUpperCase(),
20
+ url,
21
+ data ? JSON.stringify(data) : "",
22
+ options ? JSON.stringify(options) : ""
23
+ ];
24
+ return this.generateHash(parts.join("|"));
25
+ }
26
+ };
27
+
28
+ // src/interfaces/cache.ts
29
+ var MemoryCacheStore = class {
30
+ constructor() {
31
+ this.cache = /* @__PURE__ */ new Map();
32
+ }
33
+ get(key) {
34
+ const item = this.cache.get(key);
35
+ if (!item) return void 0;
36
+ if (item.expires && Date.now() > item.expires) {
37
+ this.cache.delete(key);
38
+ return void 0;
39
+ }
40
+ return item.value;
41
+ }
42
+ set(key, value, ttl) {
43
+ const expires = ttl ? Date.now() + ttl : void 0;
44
+ this.cache.set(key, { value, expires });
45
+ }
46
+ delete(key) {
47
+ this.cache.delete(key);
48
+ }
49
+ clear() {
50
+ this.cache.clear();
51
+ }
52
+ has(key) {
53
+ const item = this.cache.get(key);
54
+ if (!item) return false;
55
+ if (item.expires && Date.now() > item.expires) {
56
+ this.cache.delete(key);
57
+ return false;
58
+ }
59
+ return true;
60
+ }
61
+ };
62
+ var LibHashService = class {
63
+ generateHash(input) {
64
+ return libHash.generateHash(input);
65
+ }
66
+ generateRequestHash(method, url, data, options) {
67
+ return libHash.generateRequestHash(method, url, data, options);
68
+ }
69
+ };
70
+ var LibCacheStore = class {
71
+ constructor(store) {
72
+ this.store = store || new libCacheStore.MemoryStore();
73
+ }
74
+ async get(key) {
75
+ return this.store.get(key);
76
+ }
77
+ async set(key, value, ttl) {
78
+ return this.store.set(key, value, ttl);
79
+ }
80
+ async delete(key) {
81
+ return this.store.delete(key);
82
+ }
83
+ async clear() {
84
+ return this.store.clear();
85
+ }
86
+ async has(key) {
87
+ return this.store.has(key);
88
+ }
89
+ };
90
+
91
+ exports.DefaultHashService = DefaultHashService;
92
+ exports.LibCacheStore = LibCacheStore;
93
+ exports.LibHashService = LibHashService;
94
+ exports.MemoryCacheStore = MemoryCacheStore;
95
+ //# sourceMappingURL=index.js.map
2
96
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interfaces/hash.ts","../src/interfaces/cache.ts","../src/services/hash.ts","../src/services/cache.ts"],"names":["DefaultHashService","input","hash","i","char","method","url","data","options","parts","MemoryCacheStore","key","item","value","ttl","expires","LibHashService","generateHash","generateRequestHash","LibCacheStore","store","MemoryStore"],"mappings":"kGAuBO,IAAMA,CAAN,CAAA,KAAgD,CACrD,YAAA,CAAaC,EAAuB,CAClC,IAAIC,CAAO,CAAA,CAAA,CACX,IAASC,IAAAA,CAAAA,CAAI,CAAGA,CAAAA,CAAAA,CAAIF,EAAM,MAAQE,CAAAA,CAAAA,EAAAA,CAAK,CACrC,IAAMC,CAAOH,CAAAA,CAAAA,CAAM,UAAWE,CAAAA,CAAC,EAC/BD,CAASA,CAAAA,CAAAA,CAAAA,EAAQ,CAAKA,EAAAA,CAAAA,CAAQE,CAC9BF,CAAAA,CAAAA,CAAOA,CAAOA,CAAAA,EAChB,C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ifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","import { generateHash, generateRequestHash } from '@ureq/lib-hash';\nimport { HashService } from '../interfaces/hash.js';\n\n/**\n * Hash service implementation using @ureq/lib-hash\n */\nexport class LibHashService implements HashService {\n generateHash(input: string): string {\n return generateHash(input);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n return generateRequestHash(method, url, data, options);\n }\n}\n","import { MemoryStore } from '@ureq/lib-cache-store';\nimport { CacheStore } from '../interfaces/cache.js';\n\n/**\n * Cache store implementation using @ureq/lib-cache-store\n */\nexport class LibCacheStore implements CacheStore {\n private store: MemoryStore;\n\n constructor(store?: MemoryStore) {\n this.store = store || new MemoryStore();\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n return this.store.get<T>(key);\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n return this.store.set(key, value, ttl);\n }\n\n async delete(key: string): Promise<void> {\n return this.store.delete(key);\n }\n\n async clear(): Promise<void> {\n return this.store.clear();\n }\n\n async has(key: string): Promise<boolean> {\n return this.store.has(key);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/interfaces/hash.ts","../src/interfaces/cache.ts","../src/services/hash.ts","../src/services/cache.ts"],"names":["generateHash","generateRequestHash","MemoryStore"],"mappings":";;;;;;AAuBO,IAAM,qBAAN,MAAgD;AAAA,EACrD,aAAa,KAAuB,EAAA;AAClC,IAAA,IAAI,IAAO,GAAA,CAAA;AACX,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,CAAM,QAAQ,CAAK,EAAA,EAAA;AACrC,MAAM,MAAA,IAAA,GAAO,KAAM,CAAA,UAAA,CAAW,CAAC,CAAA;AAC/B,MAAS,IAAA,GAAA,CAAA,IAAA,IAAQ,KAAK,IAAQ,GAAA,IAAA;AAC9B,MAAA,IAAA,GAAO,IAAO,GAAA,IAAA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;AAAA;AAC9B,EAEA,MAAM,KAAuB,GAAA;AAC3B,IAAO,OAAA,IAAA,CAAK,MAAM,KAAM,EAAA;AAAA;AAC1B,EAEA,MAAM,IAAI,GAA+B,EAAA;AACvC,IAAO,OAAA,IAAA,CAAK,KAAM,CAAA,GAAA,CAAI,GAAG,CAAA;AAAA;AAE7B","file":"index.js","sourcesContent":["/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","import { generateHash, generateRequestHash } from '@ureq/lib-hash';\nimport { HashService } from '../interfaces/hash.js';\n\n/**\n * Hash service implementation using @ureq/lib-hash\n */\nexport class LibHashService implements HashService {\n generateHash(input: string): string {\n return generateHash(input);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n return generateRequestHash(method, url, data, options);\n }\n}\n","import { MemoryStore } from '@ureq/lib-cache-store';\nimport { CacheStore } from '../interfaces/cache.js';\n\n/**\n * Cache store implementation using @ureq/lib-cache-store\n */\nexport class LibCacheStore implements CacheStore {\n private store: MemoryStore;\n\n constructor(store?: MemoryStore) {\n this.store = store || new MemoryStore();\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n return this.store.get<T>(key);\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n return this.store.set(key, value, ttl);\n }\n\n async delete(key: string): Promise<void> {\n return this.store.delete(key);\n }\n\n async clear(): Promise<void> {\n return this.store.clear();\n }\n\n async has(key: string): Promise<boolean> {\n return this.store.has(key);\n }\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,91 @@
1
- import {generateHash,generateRequestHash}from'@ureq/lib-hash';import {MemoryStore}from'@ureq/lib-cache-store';var i=class{generateHash(e){let r=0;for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);r=(r<<5)-r+s,r=r&r;}return r.toString(36)}generateRequestHash(e,r,t,s){let c=[e.toUpperCase(),r,t?JSON.stringify(t):"",s?JSON.stringify(s):""];return this.generateHash(c.join("|"))}};var o=class{constructor(){this.cache=new Map;}get(e){let r=this.cache.get(e);if(r){if(r.expires&&Date.now()>r.expires){this.cache.delete(e);return}return r.value}}set(e,r,t){let s=t?Date.now()+t:void 0;this.cache.set(e,{value:r,expires:s});}delete(e){this.cache.delete(e);}clear(){this.cache.clear();}has(e){let r=this.cache.get(e);return r?r.expires&&Date.now()>r.expires?(this.cache.delete(e),false):true:false}};var a=class{generateHash(e){return generateHash(e)}generateRequestHash(e,r,t,s){return generateRequestHash(e,r,t,s)}};var g=class{constructor(e){this.store=e||new MemoryStore;}async get(e){return this.store.get(e)}async set(e,r,t){return this.store.set(e,r,t)}async delete(e){return this.store.delete(e)}async clear(){return this.store.clear()}async has(e){return this.store.has(e)}};export{i as DefaultHashService,g as LibCacheStore,a as LibHashService,o as MemoryCacheStore};//# sourceMappingURL=index.mjs.map
1
+ import { generateHash, generateRequestHash } from '@ureq/lib-hash';
2
+ import { MemoryStore } from '@ureq/lib-cache-store';
3
+
4
+ // src/interfaces/hash.ts
5
+ var DefaultHashService = class {
6
+ generateHash(input) {
7
+ let hash = 0;
8
+ for (let i = 0; i < input.length; i++) {
9
+ const char = input.charCodeAt(i);
10
+ hash = (hash << 5) - hash + char;
11
+ hash = hash & hash;
12
+ }
13
+ return hash.toString(36);
14
+ }
15
+ generateRequestHash(method, url, data, options) {
16
+ const parts = [
17
+ method.toUpperCase(),
18
+ url,
19
+ data ? JSON.stringify(data) : "",
20
+ options ? JSON.stringify(options) : ""
21
+ ];
22
+ return this.generateHash(parts.join("|"));
23
+ }
24
+ };
25
+
26
+ // src/interfaces/cache.ts
27
+ var MemoryCacheStore = class {
28
+ constructor() {
29
+ this.cache = /* @__PURE__ */ new Map();
30
+ }
31
+ get(key) {
32
+ const item = this.cache.get(key);
33
+ if (!item) return void 0;
34
+ if (item.expires && Date.now() > item.expires) {
35
+ this.cache.delete(key);
36
+ return void 0;
37
+ }
38
+ return item.value;
39
+ }
40
+ set(key, value, ttl) {
41
+ const expires = ttl ? Date.now() + ttl : void 0;
42
+ this.cache.set(key, { value, expires });
43
+ }
44
+ delete(key) {
45
+ this.cache.delete(key);
46
+ }
47
+ clear() {
48
+ this.cache.clear();
49
+ }
50
+ has(key) {
51
+ const item = this.cache.get(key);
52
+ if (!item) return false;
53
+ if (item.expires && Date.now() > item.expires) {
54
+ this.cache.delete(key);
55
+ return false;
56
+ }
57
+ return true;
58
+ }
59
+ };
60
+ var LibHashService = class {
61
+ generateHash(input) {
62
+ return generateHash(input);
63
+ }
64
+ generateRequestHash(method, url, data, options) {
65
+ return generateRequestHash(method, url, data, options);
66
+ }
67
+ };
68
+ var LibCacheStore = class {
69
+ constructor(store) {
70
+ this.store = store || new MemoryStore();
71
+ }
72
+ async get(key) {
73
+ return this.store.get(key);
74
+ }
75
+ async set(key, value, ttl) {
76
+ return this.store.set(key, value, ttl);
77
+ }
78
+ async delete(key) {
79
+ return this.store.delete(key);
80
+ }
81
+ async clear() {
82
+ return this.store.clear();
83
+ }
84
+ async has(key) {
85
+ return this.store.has(key);
86
+ }
87
+ };
88
+
89
+ export { DefaultHashService, LibCacheStore, LibHashService, MemoryCacheStore };
90
+ //# sourceMappingURL=index.mjs.map
2
91
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interfaces/hash.ts","../src/interfaces/cache.ts","../src/services/hash.ts","../src/services/cache.ts"],"names":["DefaultHashService","input","hash","i","char","method","url","data","options","parts","MemoryCacheStore","key","item","value","ttl","expires","LibHashService","generateHash","generateRequestHash","LibCacheStore","store","MemoryStore"],"mappings":"8GAuBO,IAAMA,CAAN,CAAA,KAAgD,CACrD,YAAA,CAAaC,EAAuB,CAClC,IAAIC,CAAO,CAAA,CAAA,CACX,IAASC,IAAAA,CAAAA,CAAI,CAAGA,CAAAA,CAAAA,CAAIF,EAAM,MAAQE,CAAAA,CAAAA,EAAAA,CAAK,CACrC,IAAMC,CAAOH,CAAA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KAAM,EAC1B,CAEA,MAAM,GAAA,CAAIA,CAA+B,CAAA,CACvC,OAAO,IAAK,CAAA,KAAA,CAAM,GAAIA,CAAAA,CAAG,CAC3B,CACF","file":"index.mjs","sourcesContent":["/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","import { generateHash, generateRequestHash } from '@ureq/lib-hash';\nimport { HashService } from '../interfaces/hash.js';\n\n/**\n * Hash service implementation using @ureq/lib-hash\n */\nexport class LibHashService implements HashService {\n generateHash(input: string): string {\n return generateHash(input);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n return generateRequestHash(method, url, data, options);\n }\n}\n","import { MemoryStore } from '@ureq/lib-cache-store';\nimport { CacheStore } from '../interfaces/cache.js';\n\n/**\n * Cache store implementation using @ureq/lib-cache-store\n */\nexport class LibCacheStore implements CacheStore {\n private store: MemoryStore;\n\n constructor(store?: MemoryStore) {\n this.store = store || new MemoryStore();\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n return this.store.get<T>(key);\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n return this.store.set(key, value, ttl);\n }\n\n async delete(key: string): Promise<void> {\n return this.store.delete(key);\n }\n\n async clear(): Promise<void> {\n return this.store.clear();\n }\n\n async has(key: string): Promise<boolean> {\n return this.store.has(key);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/interfaces/hash.ts","../src/interfaces/cache.ts","../src/services/hash.ts","../src/services/cache.ts"],"names":[],"mappings":";;;;AAuBO,IAAM,qBAAN,MAAgD;AAAA,EACrD,aAAa,KAAuB,EAAA;AAClC,IAAA,IAAI,IAAO,GAAA,CAAA;AACX,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,CAAM,QAAQ,CAAK,EAAA,EAAA;AACrC,MAAM,MAAA,IAAA,GAAO,KAAM,CAAA,UA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,OAAO,GAAG,CAAA;AAAA;AACvC,EAEA,MAAM,OAAO,GAA4B,EAAA;AACvC,IAAO,OAAA,IAAA,CAAK,KAAM,CAAA,MAAA,CAAO,GAAG,CAAA;AAAA;AAC9B,EAEA,MAAM,KAAuB,GAAA;AAC3B,IAAO,OAAA,IAAA,CAAK,MAAM,KAAM,EAAA;AAAA;AAC1B,EAEA,MAAM,IAAI,GAA+B,EAAA;AACvC,IAAO,OAAA,IAAA,CAAK,KAAM,CAAA,GAAA,CAAI,GAAG,CAAA;AAAA;AAE7B","file":"index.mjs","sourcesContent":["/**\n * Hash service interface for generating request identifiers\n */\nexport interface HashService {\n /**\n * Generate a hash from a string input\n */\n generateHash(input: string): string;\n \n /**\n * Generate a hash for a request based on method, URL, data, and options\n */\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string;\n}\n\n/**\n * Default hash service implementation using simple hash algorithm\n */\nexport class DefaultHashService implements HashService {\n generateHash(input: string): string {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return hash.toString(36);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n const parts = [\n method.toUpperCase(),\n url,\n data ? JSON.stringify(data) : '',\n options ? JSON.stringify(options) : ''\n ];\n return this.generateHash(parts.join('|'));\n }\n}\n","/**\n * Cache store interface for storing and retrieving cached data\n */\nexport interface CacheStore {\n /**\n * Get a value from the cache\n */\n get<T>(key: string): Promise<T | undefined> | T | undefined;\n \n /**\n * Set a value in the cache with optional TTL\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void> | void;\n \n /**\n * Delete a value from the cache\n */\n delete(key: string): Promise<void> | void;\n \n /**\n * Clear all values from the cache\n */\n clear(): Promise<void> | void;\n \n /**\n * Check if a key exists in the cache\n */\n has(key: string): Promise<boolean> | boolean;\n}\n\n/**\n * Simple in-memory cache store implementation\n */\nexport class MemoryCacheStore implements CacheStore {\n private cache = new Map<string, { value: any; expires?: number }>();\n\n get<T>(key: string): T | undefined {\n const item = this.cache.get(key);\n if (!item) return undefined;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n \n return item.value;\n }\n\n set<T>(key: string, value: T, ttl?: number): void {\n const expires = ttl ? Date.now() + ttl : undefined;\n this.cache.set(key, { value, expires });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n has(key: string): boolean {\n const item = this.cache.get(key);\n if (!item) return false;\n \n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return false;\n }\n \n return true;\n }\n}\n","import { generateHash, generateRequestHash } from '@ureq/lib-hash';\nimport { HashService } from '../interfaces/hash.js';\n\n/**\n * Hash service implementation using @ureq/lib-hash\n */\nexport class LibHashService implements HashService {\n generateHash(input: string): string {\n return generateHash(input);\n }\n\n generateRequestHash(\n method: string,\n url: string,\n data?: any,\n options?: Record<string, any>\n ): string {\n return generateRequestHash(method, url, data, options);\n }\n}\n","import { MemoryStore } from '@ureq/lib-cache-store';\nimport { CacheStore } from '../interfaces/cache.js';\n\n/**\n * Cache store implementation using @ureq/lib-cache-store\n */\nexport class LibCacheStore implements CacheStore {\n private store: MemoryStore;\n\n constructor(store?: MemoryStore) {\n this.store = store || new MemoryStore();\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n return this.store.get<T>(key);\n }\n\n async set<T>(key: string, value: T, ttl?: number): Promise<void> {\n return this.store.set(key, value, ttl);\n }\n\n async delete(key: string): Promise<void> {\n return this.store.delete(key);\n }\n\n async clear(): Promise<void> {\n return this.store.clear();\n }\n\n async has(key: string): Promise<boolean> {\n return this.store.has(key);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ureq/business",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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.2",
23
- "@ureq/lib-cache-store": "0.0.2"
22
+ "@ureq/lib-hash": "0.0.3",
23
+ "@ureq/lib-cache-store": "0.0.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "^8.3.6",