@ureq/business 0.0.1
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/dist/index.d.mts +82 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +34 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { MemoryStore } from '@ureq/lib-cache-store';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hash service interface for generating request identifiers
|
|
5
|
+
*/
|
|
6
|
+
interface HashService {
|
|
7
|
+
/**
|
|
8
|
+
* Generate a hash from a string input
|
|
9
|
+
*/
|
|
10
|
+
generateHash(input: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a hash for a request based on method, URL, data, and options
|
|
13
|
+
*/
|
|
14
|
+
generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Default hash service implementation using simple hash algorithm
|
|
18
|
+
*/
|
|
19
|
+
declare class DefaultHashService implements HashService {
|
|
20
|
+
generateHash(input: string): string;
|
|
21
|
+
generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Cache store interface for storing and retrieving cached data
|
|
26
|
+
*/
|
|
27
|
+
interface CacheStore {
|
|
28
|
+
/**
|
|
29
|
+
* Get a value from the cache
|
|
30
|
+
*/
|
|
31
|
+
get<T>(key: string): Promise<T | undefined> | T | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Set a value in the cache with optional TTL
|
|
34
|
+
*/
|
|
35
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void> | void;
|
|
36
|
+
/**
|
|
37
|
+
* Delete a value from the cache
|
|
38
|
+
*/
|
|
39
|
+
delete(key: string): Promise<void> | void;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all values from the cache
|
|
42
|
+
*/
|
|
43
|
+
clear(): Promise<void> | void;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a key exists in the cache
|
|
46
|
+
*/
|
|
47
|
+
has(key: string): Promise<boolean> | boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Simple in-memory cache store implementation
|
|
51
|
+
*/
|
|
52
|
+
declare class MemoryCacheStore implements CacheStore {
|
|
53
|
+
private cache;
|
|
54
|
+
get<T>(key: string): T | undefined;
|
|
55
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
56
|
+
delete(key: string): void;
|
|
57
|
+
clear(): void;
|
|
58
|
+
has(key: string): boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Hash service implementation using @ureq/lib-hash
|
|
63
|
+
*/
|
|
64
|
+
declare class LibHashService implements HashService {
|
|
65
|
+
generateHash(input: string): string;
|
|
66
|
+
generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Cache store implementation using @ureq/lib-cache-store
|
|
71
|
+
*/
|
|
72
|
+
declare class LibCacheStore implements CacheStore {
|
|
73
|
+
private store;
|
|
74
|
+
constructor(store?: MemoryStore);
|
|
75
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
76
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
77
|
+
delete(key: string): Promise<void>;
|
|
78
|
+
clear(): Promise<void>;
|
|
79
|
+
has(key: string): Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { type CacheStore, DefaultHashService, type HashService, LibCacheStore, LibHashService, MemoryCacheStore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { MemoryStore } from '@ureq/lib-cache-store';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hash service interface for generating request identifiers
|
|
5
|
+
*/
|
|
6
|
+
interface HashService {
|
|
7
|
+
/**
|
|
8
|
+
* Generate a hash from a string input
|
|
9
|
+
*/
|
|
10
|
+
generateHash(input: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a hash for a request based on method, URL, data, and options
|
|
13
|
+
*/
|
|
14
|
+
generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Default hash service implementation using simple hash algorithm
|
|
18
|
+
*/
|
|
19
|
+
declare class DefaultHashService implements HashService {
|
|
20
|
+
generateHash(input: string): string;
|
|
21
|
+
generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Cache store interface for storing and retrieving cached data
|
|
26
|
+
*/
|
|
27
|
+
interface CacheStore {
|
|
28
|
+
/**
|
|
29
|
+
* Get a value from the cache
|
|
30
|
+
*/
|
|
31
|
+
get<T>(key: string): Promise<T | undefined> | T | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Set a value in the cache with optional TTL
|
|
34
|
+
*/
|
|
35
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void> | void;
|
|
36
|
+
/**
|
|
37
|
+
* Delete a value from the cache
|
|
38
|
+
*/
|
|
39
|
+
delete(key: string): Promise<void> | void;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all values from the cache
|
|
42
|
+
*/
|
|
43
|
+
clear(): Promise<void> | void;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a key exists in the cache
|
|
46
|
+
*/
|
|
47
|
+
has(key: string): Promise<boolean> | boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Simple in-memory cache store implementation
|
|
51
|
+
*/
|
|
52
|
+
declare class MemoryCacheStore implements CacheStore {
|
|
53
|
+
private cache;
|
|
54
|
+
get<T>(key: string): T | undefined;
|
|
55
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
56
|
+
delete(key: string): void;
|
|
57
|
+
clear(): void;
|
|
58
|
+
has(key: string): boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Hash service implementation using @ureq/lib-hash
|
|
63
|
+
*/
|
|
64
|
+
declare class LibHashService implements HashService {
|
|
65
|
+
generateHash(input: string): string;
|
|
66
|
+
generateRequestHash(method: string, url: string, data?: any, options?: Record<string, any>): string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Cache store implementation using @ureq/lib-cache-store
|
|
71
|
+
*/
|
|
72
|
+
declare class LibCacheStore implements CacheStore {
|
|
73
|
+
private store;
|
|
74
|
+
constructor(store?: MemoryStore);
|
|
75
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
76
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
77
|
+
delete(key: string): Promise<void>;
|
|
78
|
+
clear(): Promise<void>;
|
|
79
|
+
has(key: string): Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { type CacheStore, DefaultHashService, type HashService, LibCacheStore, LibHashService, MemoryCacheStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,CACA,OAAOA,CAAAA,CAAK,QAAS,CAAA,EAAE,CACzB,CAEA,mBACEG,CAAAA,CAAAA,CACAC,EACAC,CACAC,CAAAA,CAAAA,CACQ,CACR,IAAMC,CAAQ,CAAA,CACZJ,CAAO,CAAA,WAAA,GACPC,CACAC,CAAAA,CAAAA,CAAO,IAAK,CAAA,SAAA,CAAUA,CAAI,CAAA,CA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,EACd,KAGF,EAAA,IAAA,CAPW,KAQpB,CACF,EClEaK,IAAAA,CAAAA,CAAN,KAA4C,CACjD,YAAaf,CAAAA,CAAAA,CAAuB,CAClC,OAAOgB,oBAAAA,CAAahB,CAAK,CAC3B,CAEA,mBAAA,CACEI,CACAC,CAAAA,CAAAA,CACAC,EACAC,CACQ,CAAA,CACR,OAAOU,2BAAAA,CAAoBb,EAAQC,CAAKC,CAAAA,CAAAA,CAAMC,CAAO,CACvD,CACF,ECbO,IAAMW,CAAN,CAAA,KAA0C,CAG/C,WAAYC,CAAAA,CAAAA,CAAqB,CAC/B,IAAA,CAAK,KAAQA,CAAAA,CAAAA,EAAS,IAAIC,0BAC5B,CAEA,MAAM,GAAA,CAAOV,CAAqC,CAAA,CAChD,OAAO,IAAA,CAAK,KAAM,CAAA,GAAA,CAAOA,CAAG,CAC9B,CAEA,MAAM,GAAA,CAAOA,EAAaE,CAAUC,CAAAA,CAAAA,CAA6B,CAC/D,OAAO,KAAK,KAAM,CAAA,GAAA,CAAIH,CAAKE,CAAAA,CAAAA,CAAOC,CAAG,CACvC,CAEA,MAAM,OAAOH,CAA4B,CAAA,CACvC,OAAO,IAAA,CAAK,KAAM,CAAA,MAAA,CAAOA,CAAG,CAC9B,CAEA,MAAM,KAAA,EAAuB,CAC3B,OAAO,IAAK,CAAA,KAAA,CAAM,KAAM,EAC1B,CAEA,MAAM,GAAA,CAAIA,CAA+B,CAAA,CACvC,OAAO,IAAK,CAAA,KAAA,CAAM,GAAIA,CAAAA,CAAG,CAC3B,CACF","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
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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,CAAAA,CAAAA,CAAM,UAAWE,CAAAA,CAAC,EAC/BD,CAASA,CAAAA,CAAAA,CAAAA,EAAQ,CAAKA,EAAAA,CAAAA,CAAQE,CAC9BF,CAAAA,CAAAA,CAAOA,CAAOA,CAAAA,EAChB,CACA,OAAOA,CAAAA,CAAK,QAAS,CAAA,EAAE,CACzB,CAEA,mBACEG,CAAAA,CAAAA,CACAC,EACAC,CACAC,CAAAA,CAAAA,CACQ,CACR,IAAMC,CAAQ,CAAA,CACZJ,CAAO,CAAA,WAAA,GACPC,CACAC,CAAAA,CAAAA,CAAO,IAAK,CAAA,SAAA,CAAUA,CAAI,CAAA,CAAI,EAC9BC,CAAAA,CAAAA,CAAU,KAAK,SAAUA,CAAAA,CAAO,CAAI,CAAA,EACtC,EACA,OAAO,IAAA,CAAK,YAAaC,CAAAA,CAAAA,CAAM,KAAK,GAAG,CAAC,CAC1C,CACF,ECfO,IAAMC,CAAN,CAAA,KAA6C,CAA7C,WACL,EAAA,CAAA,IAAA,CAAQ,KAAQ,CAAA,IAAI,IAEpB,CA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AKC,CAAAA,CAAAA,CAAMC,CAAO,CACvD,CACF,ECbO,IAAMW,CAAN,CAAA,KAA0C,CAG/C,WAAYC,CAAAA,CAAAA,CAAqB,CAC/B,IAAA,CAAK,KAAQA,CAAAA,CAAAA,EAAS,IAAIC,YAC5B,CAEA,MAAM,GAAA,CAAOV,CAAqC,CAAA,CAChD,OAAO,IAAA,CAAK,KAAM,CAAA,GAAA,CAAOA,CAAG,CAC9B,CAEA,MAAM,GAAA,CAAOA,EAAaE,CAAUC,CAAAA,CAAAA,CAA6B,CAC/D,OAAO,KAAK,KAAM,CAAA,GAAA,CAAIH,CAAKE,CAAAA,CAAAA,CAAOC,CAAG,CACvC,CAEA,MAAM,OAAOH,CAA4B,CAAA,CACvC,OAAO,IAAA,CAAK,KAAM,CAAA,MAAA,CAAOA,CAAG,CAC9B,CAEA,MAAM,KAAA,EAAuB,CAC3B,OAAO,IAAK,CAAA,KAAA,CAAM,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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ureq/business",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Universal request library business logic",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ureq/lib-cache-store": "0.0.1",
|
|
23
|
+
"@ureq/lib-hash": "0.0.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"tsup": "^8.3.6",
|
|
27
|
+
"typescript": "^5.7.3"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup --config tsup.config.ts",
|
|
31
|
+
"dev": "tsup --config tsup.config.ts --watch",
|
|
32
|
+
"test": "vitest"
|
|
33
|
+
}
|
|
34
|
+
}
|