@gvnrdao/dh-sdk 0.0.157 → 0.0.158
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.js +316 -85
- package/dist/index.mjs +316 -85
- package/package.json +7 -7
- package/browser/dist/397.browser.js +0 -2
- package/browser/dist/397.browser.js.LICENSE.txt +0 -1
- package/browser/dist/833.browser.js +0 -2
- package/browser/dist/833.browser.js.LICENSE.txt +0 -1
- package/browser/dist/browser.js +0 -14
- package/browser/dist/browser.js.LICENSE.txt +0 -90
- package/browser/dist/index.d.ts +0 -9
- package/browser/dist/index.d.ts.map +0 -1
- package/browser/dist/index.js +0 -24
- package/dist/index.d.mts +0 -4154
- package/dist/index.d.ts +0 -4154
package/dist/index.js
CHANGED
|
@@ -12745,47 +12745,45 @@ var init_deployment_addresses = __esm({
|
|
|
12745
12745
|
};
|
|
12746
12746
|
LOCALHOST_DEPLOYMENT = {
|
|
12747
12747
|
network: "localhost",
|
|
12748
|
-
chainId:
|
|
12749
|
-
timestamp: "2026-02-
|
|
12750
|
-
deployer: "",
|
|
12748
|
+
chainId: 1337,
|
|
12749
|
+
timestamp: "2026-02-09T10:20:16.663Z",
|
|
12750
|
+
deployer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
12751
12751
|
contracts: {
|
|
12752
|
-
UpgradeValidator: "
|
|
12752
|
+
UpgradeValidator: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
|
|
12753
12753
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
12754
12754
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
12755
|
-
PriceFeedConsumer: "
|
|
12756
|
-
UCDMintingRewards: "
|
|
12757
|
-
PositionManagerCoreModule: "
|
|
12758
|
-
TermManagerModule: "
|
|
12759
|
-
LoanOperationsManagerModule: "
|
|
12760
|
-
CollateralManagerModule: "
|
|
12761
|
-
LiquidationManagerModule: "
|
|
12762
|
-
CircuitBreakerModule: "
|
|
12763
|
-
CommunityManagerModule: "
|
|
12764
|
-
AdminModule: "
|
|
12765
|
-
PositionManagerViews: "
|
|
12766
|
-
PositionManager: "
|
|
12767
|
-
OperationAuthorizationRegistry: "
|
|
12768
|
-
PKPValidation: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
|
|
12755
|
+
PriceFeedConsumer: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
|
|
12756
|
+
UCDMintingRewards: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
|
|
12757
|
+
PositionManagerCoreModule: "0x9A676e781A523b5d0C0e43731313A708CB607508",
|
|
12758
|
+
TermManagerModule: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
12759
|
+
LoanOperationsManagerModule: "0x59b670e9fA9D0A427751Af201D676719a970857b",
|
|
12760
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
12761
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
12762
|
+
CircuitBreakerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
12763
|
+
CommunityManagerModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
12764
|
+
AdminModule: "0x67d269191c92Caf3cD7723F116c85e6E9bf55933",
|
|
12765
|
+
PositionManagerViews: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
|
|
12766
|
+
PositionManager: "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
|
|
12767
|
+
OperationAuthorizationRegistry: "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf"
|
|
12769
12768
|
}
|
|
12770
12769
|
};
|
|
12771
12770
|
LOCALHOST_CONTRACTS = {
|
|
12772
|
-
UpgradeValidator: "
|
|
12771
|
+
UpgradeValidator: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
|
|
12773
12772
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
12774
12773
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
12775
|
-
PriceFeedConsumer: "
|
|
12776
|
-
UCDMintingRewards: "
|
|
12777
|
-
PositionManagerCoreModule: "
|
|
12778
|
-
TermManagerModule: "
|
|
12779
|
-
LoanOperationsManagerModule: "
|
|
12780
|
-
CollateralManagerModule: "
|
|
12781
|
-
LiquidationManagerModule: "
|
|
12782
|
-
CircuitBreakerModule: "
|
|
12783
|
-
CommunityManagerModule: "
|
|
12784
|
-
AdminModule: "
|
|
12785
|
-
PositionManagerViews: "
|
|
12786
|
-
PositionManager: "
|
|
12787
|
-
OperationAuthorizationRegistry: "
|
|
12788
|
-
PKPValidation: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
|
|
12774
|
+
PriceFeedConsumer: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
|
|
12775
|
+
UCDMintingRewards: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
|
|
12776
|
+
PositionManagerCoreModule: "0x9A676e781A523b5d0C0e43731313A708CB607508",
|
|
12777
|
+
TermManagerModule: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
12778
|
+
LoanOperationsManagerModule: "0x59b670e9fA9D0A427751Af201D676719a970857b",
|
|
12779
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
12780
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
12781
|
+
CircuitBreakerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
12782
|
+
CommunityManagerModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
12783
|
+
AdminModule: "0x67d269191c92Caf3cD7723F116c85e6E9bf55933",
|
|
12784
|
+
PositionManagerViews: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
|
|
12785
|
+
PositionManager: "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
|
|
12786
|
+
OperationAuthorizationRegistry: "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf"
|
|
12789
12787
|
};
|
|
12790
12788
|
ALL_DEPLOYMENTS = {
|
|
12791
12789
|
sepolia: SEPOLIA_DEPLOYMENT,
|
|
@@ -13121,7 +13119,7 @@ __export(src_exports, {
|
|
|
13121
13119
|
ErrorCategory: () => ErrorCategory,
|
|
13122
13120
|
ErrorSeverity: () => ErrorSeverity,
|
|
13123
13121
|
EventHelpers: () => EventHelpers,
|
|
13124
|
-
LRUCache: () =>
|
|
13122
|
+
LRUCache: () => LRUCache,
|
|
13125
13123
|
LoanCreator: () => LoanCreator,
|
|
13126
13124
|
LoanQuery: () => LoanQuery,
|
|
13127
13125
|
LoanStatus: () => LoanStatus,
|
|
@@ -29632,7 +29630,8 @@ var PRICE_FEED_ABI = [
|
|
|
29632
29630
|
"function getLatestPrice() external view returns (int256)"
|
|
29633
29631
|
];
|
|
29634
29632
|
var TERM_MANAGER_ABI = [
|
|
29635
|
-
"function getAvailableTerms() external view returns (uint256[] memory termIds, uint256[] memory durationDays, uint256[] memory interestRateBps)"
|
|
29633
|
+
"function getAvailableTerms() external view returns (uint256[] memory termIds, uint256[] memory durationDays, uint256[] memory interestRateBps)",
|
|
29634
|
+
"function getValidTermsWithFees() external view returns (uint256[] terms, uint88[] originationFees, uint88[] extensionFees)"
|
|
29636
29635
|
];
|
|
29637
29636
|
var CIRCUIT_BREAKER_ABI = [
|
|
29638
29637
|
"function isPaused() external view returns (bool)"
|
|
@@ -29944,106 +29943,333 @@ function createContractManager(config) {
|
|
|
29944
29943
|
}
|
|
29945
29944
|
|
|
29946
29945
|
// src/modules/cache/cache-manager.module.ts
|
|
29947
|
-
var
|
|
29948
|
-
cache
|
|
29946
|
+
var LRUCache = class {
|
|
29947
|
+
cache;
|
|
29949
29948
|
maxSize;
|
|
29950
29949
|
ttlMs;
|
|
29951
|
-
|
|
29952
|
-
|
|
29953
|
-
|
|
29950
|
+
debug;
|
|
29951
|
+
name;
|
|
29952
|
+
// Statistics
|
|
29953
|
+
stats = {
|
|
29954
|
+
hits: 0,
|
|
29955
|
+
misses: 0,
|
|
29956
|
+
evictions: 0
|
|
29957
|
+
};
|
|
29958
|
+
constructor(config = {}) {
|
|
29959
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
29960
|
+
this.maxSize = config.maxSize || 1e3;
|
|
29961
|
+
this.ttlMs = config.ttlMs || 6e4;
|
|
29962
|
+
this.debug = config.debug || false;
|
|
29963
|
+
this.name = config.name || "Cache";
|
|
29964
|
+
if (this.debug) {
|
|
29965
|
+
console.log(
|
|
29966
|
+
`\u{1F4BE} [${this.name}] Initialized: maxSize=${this.maxSize}, ttl=${this.ttlMs}ms`
|
|
29967
|
+
);
|
|
29968
|
+
}
|
|
29954
29969
|
}
|
|
29955
29970
|
/**
|
|
29956
29971
|
* Get value from cache
|
|
29972
|
+
*
|
|
29973
|
+
* Returns null if:
|
|
29974
|
+
* - Key not found
|
|
29975
|
+
* - Entry has expired
|
|
29976
|
+
*
|
|
29977
|
+
* @param key - Cache key
|
|
29978
|
+
* @returns Cached value or null
|
|
29957
29979
|
*/
|
|
29958
29980
|
get(key2) {
|
|
29959
29981
|
const entry = this.cache.get(key2);
|
|
29960
29982
|
if (!entry) {
|
|
29961
|
-
|
|
29983
|
+
this.stats.misses++;
|
|
29984
|
+
if (this.debug) {
|
|
29985
|
+
console.log(`\u274C [${this.name}] Cache MISS: ${String(key2)}`);
|
|
29986
|
+
}
|
|
29987
|
+
return null;
|
|
29962
29988
|
}
|
|
29963
|
-
|
|
29964
|
-
if (now2 - entry.timestamp > entry.ttl) {
|
|
29989
|
+
if (this.isExpired(entry)) {
|
|
29965
29990
|
this.cache.delete(key2);
|
|
29966
|
-
|
|
29991
|
+
this.stats.misses++;
|
|
29992
|
+
if (this.debug) {
|
|
29993
|
+
const age = Date.now() - entry.timestamp;
|
|
29994
|
+
console.log(`\u23F0 [${this.name}] Cache EXPIRED: ${String(key2)} (age: ${age}ms)`);
|
|
29995
|
+
}
|
|
29996
|
+
return null;
|
|
29997
|
+
}
|
|
29998
|
+
entry.hits++;
|
|
29999
|
+
entry.lastAccessed = Date.now();
|
|
30000
|
+
this.cache.set(key2, entry);
|
|
30001
|
+
this.stats.hits++;
|
|
30002
|
+
if (this.debug) {
|
|
30003
|
+
const age = Date.now() - entry.timestamp;
|
|
30004
|
+
console.log(
|
|
30005
|
+
`\u2705 [${this.name}] Cache HIT: ${String(key2)} (age: ${age}ms, hits: ${entry.hits})`
|
|
30006
|
+
);
|
|
29967
30007
|
}
|
|
29968
30008
|
return entry.value;
|
|
29969
30009
|
}
|
|
30010
|
+
/**
|
|
30011
|
+
* Get value from cache with Result wrapper
|
|
30012
|
+
*
|
|
30013
|
+
* Useful when you want to distinguish between "not found" and "expired"
|
|
30014
|
+
*/
|
|
30015
|
+
getResult(key2) {
|
|
30016
|
+
const value = this.get(key2);
|
|
30017
|
+
if (value === null) {
|
|
30018
|
+
return failure(
|
|
30019
|
+
new SDKError({
|
|
30020
|
+
message: `Cache miss for key: ${String(key2)}`,
|
|
30021
|
+
category: "CACHE" /* CACHE */,
|
|
30022
|
+
severity: "LOW" /* LOW */,
|
|
30023
|
+
originalError: new Error("Cache miss")
|
|
30024
|
+
})
|
|
30025
|
+
);
|
|
30026
|
+
}
|
|
30027
|
+
return success(value);
|
|
30028
|
+
}
|
|
29970
30029
|
/**
|
|
29971
30030
|
* Set value in cache
|
|
30031
|
+
*
|
|
30032
|
+
* If cache is full, evicts the least recently used entry
|
|
30033
|
+
*
|
|
30034
|
+
* @param key - Cache key
|
|
30035
|
+
* @param value - Value to cache
|
|
30036
|
+
* @param ttl - Optional custom TTL for this entry (ms)
|
|
29972
30037
|
*/
|
|
29973
30038
|
set(key2, value, ttl) {
|
|
29974
30039
|
if (this.cache.size >= this.maxSize && !this.cache.has(key2)) {
|
|
29975
|
-
|
|
29976
|
-
if (firstKey) {
|
|
29977
|
-
this.cache.delete(firstKey);
|
|
29978
|
-
}
|
|
30040
|
+
this.evictLRU();
|
|
29979
30041
|
}
|
|
29980
|
-
|
|
30042
|
+
const entry = {
|
|
29981
30043
|
value,
|
|
29982
30044
|
timestamp: Date.now(),
|
|
29983
|
-
|
|
29984
|
-
|
|
30045
|
+
hits: 0,
|
|
30046
|
+
lastAccessed: Date.now()
|
|
30047
|
+
};
|
|
30048
|
+
this.cache.set(key2, entry);
|
|
30049
|
+
if (this.debug) {
|
|
30050
|
+
const effectiveTtl = ttl || this.ttlMs;
|
|
30051
|
+
console.log(
|
|
30052
|
+
`\u{1F4BE} [${this.name}] Cache SET: ${String(key2)} (ttl: ${effectiveTtl}ms, size: ${this.cache.size}/${this.maxSize})`
|
|
30053
|
+
);
|
|
30054
|
+
}
|
|
29985
30055
|
}
|
|
29986
30056
|
/**
|
|
29987
|
-
*
|
|
30057
|
+
* Set value in cache with Result wrapper
|
|
30058
|
+
*/
|
|
30059
|
+
setResult(key2, value, ttl) {
|
|
30060
|
+
try {
|
|
30061
|
+
this.set(key2, value, ttl);
|
|
30062
|
+
return success(void 0);
|
|
30063
|
+
} catch (error) {
|
|
30064
|
+
return failure(
|
|
30065
|
+
new SDKError({
|
|
30066
|
+
message: `Failed to set cache value for key: ${String(key2)}`,
|
|
30067
|
+
category: "CACHE" /* CACHE */,
|
|
30068
|
+
severity: "MEDIUM" /* MEDIUM */,
|
|
30069
|
+
originalError: error instanceof Error ? error : new Error(String(error))
|
|
30070
|
+
})
|
|
30071
|
+
);
|
|
30072
|
+
}
|
|
30073
|
+
}
|
|
30074
|
+
/**
|
|
30075
|
+
* Check if key exists in cache (without affecting stats)
|
|
29988
30076
|
*/
|
|
29989
30077
|
has(key2) {
|
|
29990
|
-
|
|
30078
|
+
const entry = this.cache.get(key2);
|
|
30079
|
+
return entry !== void 0 && !this.isExpired(entry);
|
|
29991
30080
|
}
|
|
29992
30081
|
/**
|
|
29993
|
-
* Delete key from cache
|
|
30082
|
+
* Delete specific key from cache
|
|
29994
30083
|
*/
|
|
29995
30084
|
delete(key2) {
|
|
29996
|
-
|
|
30085
|
+
const deleted = this.cache.delete(key2);
|
|
30086
|
+
if (deleted && this.debug) {
|
|
30087
|
+
console.log(`\u{1F5D1}\uFE0F [${this.name}] Cache DELETE: ${String(key2)}`);
|
|
30088
|
+
}
|
|
30089
|
+
return deleted;
|
|
29997
30090
|
}
|
|
29998
30091
|
/**
|
|
29999
|
-
* Clear
|
|
30092
|
+
* Clear entire cache
|
|
30000
30093
|
*/
|
|
30001
30094
|
clear() {
|
|
30095
|
+
const previousSize = this.cache.size;
|
|
30002
30096
|
this.cache.clear();
|
|
30097
|
+
this.stats = {
|
|
30098
|
+
hits: 0,
|
|
30099
|
+
misses: 0,
|
|
30100
|
+
evictions: 0
|
|
30101
|
+
};
|
|
30102
|
+
if (this.debug) {
|
|
30103
|
+
console.log(`\u{1F9F9} [${this.name}] Cache CLEARED: removed ${previousSize} entries`);
|
|
30104
|
+
}
|
|
30105
|
+
}
|
|
30106
|
+
/**
|
|
30107
|
+
* Get current cache size
|
|
30108
|
+
*/
|
|
30109
|
+
size() {
|
|
30110
|
+
return this.cache.size;
|
|
30003
30111
|
}
|
|
30004
30112
|
/**
|
|
30005
|
-
*
|
|
30113
|
+
* Get cache statistics
|
|
30114
|
+
*/
|
|
30115
|
+
getStats() {
|
|
30116
|
+
const entries = Array.from(this.cache.values());
|
|
30117
|
+
const timestamps = entries.map((e) => e.timestamp);
|
|
30118
|
+
const total = this.stats.hits + this.stats.misses;
|
|
30119
|
+
const hitRate = total === 0 ? 0 : this.stats.hits / total * 100;
|
|
30120
|
+
return {
|
|
30121
|
+
size: this.cache.size,
|
|
30122
|
+
hits: this.stats.hits,
|
|
30123
|
+
misses: this.stats.misses,
|
|
30124
|
+
evictions: this.stats.evictions,
|
|
30125
|
+
oldestEntry: timestamps.length > 0 ? Math.min(...timestamps) : 0,
|
|
30126
|
+
newestEntry: timestamps.length > 0 ? Math.max(...timestamps) : 0,
|
|
30127
|
+
hitRate
|
|
30128
|
+
};
|
|
30129
|
+
}
|
|
30130
|
+
/**
|
|
30131
|
+
* Get hit rate percentage
|
|
30132
|
+
*/
|
|
30133
|
+
getHitRate() {
|
|
30134
|
+
const total = this.stats.hits + this.stats.misses;
|
|
30135
|
+
return total === 0 ? 0 : this.stats.hits / total * 100;
|
|
30136
|
+
}
|
|
30137
|
+
/**
|
|
30138
|
+
* Get all cached keys (for debugging)
|
|
30139
|
+
*/
|
|
30140
|
+
getKeys() {
|
|
30141
|
+
return Array.from(this.cache.keys());
|
|
30142
|
+
}
|
|
30143
|
+
/**
|
|
30144
|
+
* Get all cached values (for debugging)
|
|
30145
|
+
*/
|
|
30146
|
+
getValues() {
|
|
30147
|
+
return Array.from(this.cache.values()).map((entry) => entry.value);
|
|
30148
|
+
}
|
|
30149
|
+
/**
|
|
30150
|
+
* Get all cache entries with metadata (for debugging)
|
|
30151
|
+
*/
|
|
30152
|
+
getEntries() {
|
|
30153
|
+
return Array.from(this.cache.entries()).map(([key2, entry]) => ({
|
|
30154
|
+
key: key2,
|
|
30155
|
+
value: entry.value,
|
|
30156
|
+
metadata: {
|
|
30157
|
+
timestamp: entry.timestamp,
|
|
30158
|
+
hits: entry.hits,
|
|
30159
|
+
lastAccessed: entry.lastAccessed
|
|
30160
|
+
}
|
|
30161
|
+
}));
|
|
30162
|
+
}
|
|
30163
|
+
/**
|
|
30164
|
+
* Clean up expired entries
|
|
30165
|
+
*
|
|
30166
|
+
* Useful for periodic maintenance
|
|
30167
|
+
*
|
|
30168
|
+
* @returns Number of entries cleaned
|
|
30006
30169
|
*/
|
|
30007
30170
|
cleanExpired() {
|
|
30008
30171
|
const now2 = Date.now();
|
|
30009
|
-
let
|
|
30172
|
+
let cleanedCount = 0;
|
|
30010
30173
|
for (const [key2, entry] of this.cache.entries()) {
|
|
30011
|
-
if (now2 - entry.timestamp >
|
|
30174
|
+
if (now2 - entry.timestamp > this.ttlMs) {
|
|
30012
30175
|
this.cache.delete(key2);
|
|
30013
|
-
|
|
30176
|
+
cleanedCount++;
|
|
30014
30177
|
}
|
|
30015
30178
|
}
|
|
30016
|
-
|
|
30179
|
+
if (cleanedCount > 0 && this.debug) {
|
|
30180
|
+
console.log(`\u{1F9F9} [${this.name}] Cleaned ${cleanedCount} expired entries`);
|
|
30181
|
+
}
|
|
30182
|
+
return cleanedCount;
|
|
30017
30183
|
}
|
|
30018
30184
|
/**
|
|
30019
|
-
*
|
|
30185
|
+
* Check if cache entry is expired
|
|
30020
30186
|
*/
|
|
30021
|
-
|
|
30022
|
-
return
|
|
30023
|
-
|
|
30024
|
-
|
|
30025
|
-
|
|
30026
|
-
|
|
30187
|
+
isExpired(entry) {
|
|
30188
|
+
return Date.now() - entry.timestamp > this.ttlMs;
|
|
30189
|
+
}
|
|
30190
|
+
/**
|
|
30191
|
+
* Evict least recently used entry
|
|
30192
|
+
*/
|
|
30193
|
+
evictLRU() {
|
|
30194
|
+
let oldestKey = null;
|
|
30195
|
+
let oldestAccess = Infinity;
|
|
30196
|
+
for (const [key2, entry] of this.cache.entries()) {
|
|
30197
|
+
if (entry.lastAccessed < oldestAccess) {
|
|
30198
|
+
oldestAccess = entry.lastAccessed;
|
|
30199
|
+
oldestKey = key2;
|
|
30200
|
+
}
|
|
30201
|
+
}
|
|
30202
|
+
if (oldestKey !== null) {
|
|
30203
|
+
this.cache.delete(oldestKey);
|
|
30204
|
+
this.stats.evictions++;
|
|
30205
|
+
if (this.debug) {
|
|
30206
|
+
const timeSinceAccess = Date.now() - oldestAccess;
|
|
30207
|
+
console.log(
|
|
30208
|
+
`\u267B\uFE0F [${this.name}] Cache EVICT (LRU): ${String(oldestKey)} (last accessed: ${timeSinceAccess}ms ago)`
|
|
30209
|
+
);
|
|
30210
|
+
}
|
|
30211
|
+
}
|
|
30212
|
+
}
|
|
30213
|
+
/**
|
|
30214
|
+
* Get or compute value
|
|
30215
|
+
*
|
|
30216
|
+
* If key exists in cache, returns cached value.
|
|
30217
|
+
* Otherwise, computes value using provided function and caches it.
|
|
30218
|
+
*
|
|
30219
|
+
* @param key - Cache key
|
|
30220
|
+
* @param compute - Function to compute value if not in cache
|
|
30221
|
+
* @param ttl - Optional custom TTL for this entry
|
|
30222
|
+
* @returns Cached or computed value
|
|
30223
|
+
*/
|
|
30224
|
+
async getOrCompute(key2, compute, ttl) {
|
|
30225
|
+
const cached = this.get(key2);
|
|
30226
|
+
if (cached !== null) {
|
|
30227
|
+
return cached;
|
|
30228
|
+
}
|
|
30229
|
+
const value = await compute();
|
|
30230
|
+
this.set(key2, value, ttl);
|
|
30231
|
+
return value;
|
|
30232
|
+
}
|
|
30233
|
+
/**
|
|
30234
|
+
* Get or compute value with Result wrapper
|
|
30235
|
+
*/
|
|
30236
|
+
async getOrComputeResult(key2, compute, ttl) {
|
|
30237
|
+
const cached = this.get(key2);
|
|
30238
|
+
if (cached !== null) {
|
|
30239
|
+
return success(cached);
|
|
30240
|
+
}
|
|
30241
|
+
const result = await compute();
|
|
30242
|
+
if (result.success) {
|
|
30243
|
+
this.set(key2, result.value, ttl);
|
|
30244
|
+
}
|
|
30245
|
+
return result;
|
|
30027
30246
|
}
|
|
30028
30247
|
};
|
|
30029
30248
|
var CacheManager = class {
|
|
30030
30249
|
caches = /* @__PURE__ */ new Map();
|
|
30031
|
-
|
|
30032
|
-
constructor(
|
|
30033
|
-
this.
|
|
30250
|
+
globalConfig;
|
|
30251
|
+
constructor(globalConfig = {}) {
|
|
30252
|
+
this.globalConfig = globalConfig;
|
|
30034
30253
|
}
|
|
30035
30254
|
/**
|
|
30036
|
-
*
|
|
30255
|
+
* Create or get a named cache
|
|
30256
|
+
*
|
|
30257
|
+
* @param name - Unique cache name
|
|
30258
|
+
* @param config - Optional cache-specific configuration
|
|
30259
|
+
* @returns LRU cache instance
|
|
30037
30260
|
*/
|
|
30038
30261
|
getCache(name, config) {
|
|
30039
|
-
|
|
30040
|
-
|
|
30262
|
+
const existingCache = this.caches.get(name);
|
|
30263
|
+
if (existingCache) {
|
|
30264
|
+
return existingCache;
|
|
30041
30265
|
}
|
|
30042
|
-
const
|
|
30266
|
+
const mergedConfig = {
|
|
30267
|
+
...this.globalConfig,
|
|
30268
|
+
...config,
|
|
30269
|
+
name
|
|
30270
|
+
};
|
|
30271
|
+
const cache = new LRUCache(mergedConfig);
|
|
30043
30272
|
this.caches.set(name, cache);
|
|
30044
|
-
if (this.debug) {
|
|
30045
|
-
console.log(`[CacheManager] Created cache: ${name}`, config);
|
|
30046
|
-
}
|
|
30047
30273
|
return cache;
|
|
30048
30274
|
}
|
|
30049
30275
|
/**
|
|
@@ -30058,11 +30284,11 @@ var CacheManager = class {
|
|
|
30058
30284
|
* Clean expired entries from all caches
|
|
30059
30285
|
*/
|
|
30060
30286
|
cleanAllExpired() {
|
|
30061
|
-
let
|
|
30287
|
+
let totalCleaned = 0;
|
|
30062
30288
|
for (const cache of this.caches.values()) {
|
|
30063
|
-
|
|
30289
|
+
totalCleaned += cache.cleanExpired();
|
|
30064
30290
|
}
|
|
30065
|
-
return
|
|
30291
|
+
return totalCleaned;
|
|
30066
30292
|
}
|
|
30067
30293
|
/**
|
|
30068
30294
|
* Get statistics for all caches
|
|
@@ -30075,11 +30301,16 @@ var CacheManager = class {
|
|
|
30075
30301
|
return stats;
|
|
30076
30302
|
}
|
|
30077
30303
|
/**
|
|
30078
|
-
*
|
|
30304
|
+
* Get list of all cache names
|
|
30079
30305
|
*/
|
|
30080
|
-
|
|
30081
|
-
this.
|
|
30082
|
-
|
|
30306
|
+
getCacheNames() {
|
|
30307
|
+
return Array.from(this.caches.keys());
|
|
30308
|
+
}
|
|
30309
|
+
/**
|
|
30310
|
+
* Delete a named cache
|
|
30311
|
+
*/
|
|
30312
|
+
deleteCache(name) {
|
|
30313
|
+
return this.caches.delete(name);
|
|
30083
30314
|
}
|
|
30084
30315
|
};
|
|
30085
30316
|
function createCacheManager(config) {
|