@gvnrdao/dh-sdk 0.0.161 → 0.0.162
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/browser/dist/browser.js +5 -5
- package/dist/index.js +86 -316
- package/dist/index.mjs +86 -316
- package/package.json +5 -5
- package/browser/dist/browser/index.d.ts +0 -8
- package/browser/dist/browser/index.d.ts.map +0 -1
- package/browser/dist/browser/index.js +0 -24
- package/browser/dist/dist/index.d.ts +0 -3
- package/browser/dist/dist/index.d.ts.map +0 -1
- package/browser/dist/dist/index.js +0 -40174
package/dist/index.js
CHANGED
|
@@ -12745,45 +12745,47 @@ 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: 31337,
|
|
12749
|
+
timestamp: "2026-02-16T15:23:50.854Z",
|
|
12750
|
+
deployer: "",
|
|
12751
12751
|
contracts: {
|
|
12752
|
-
UpgradeValidator: "
|
|
12752
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
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: "
|
|
12755
|
+
PriceFeedConsumer: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
12756
|
+
UCDMintingRewards: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
12757
|
+
PositionManagerCoreModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
12758
|
+
TermManagerModule: "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
|
|
12759
|
+
LoanOperationsManagerModule: "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
|
|
12760
|
+
CollateralManagerModule: "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
|
|
12761
|
+
LiquidationManagerModule: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
|
|
12762
|
+
CircuitBreakerModule: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
|
|
12763
|
+
CommunityManagerModule: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
|
|
12764
|
+
AdminModule: "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
|
|
12765
|
+
PositionManagerViews: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
12766
|
+
PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
|
|
12767
|
+
OperationAuthorizationRegistry: "0x9d4454B023096f34B160D6B654540c56A1F81688",
|
|
12768
|
+
PKPValidation: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
|
|
12768
12769
|
}
|
|
12769
12770
|
};
|
|
12770
12771
|
LOCALHOST_CONTRACTS = {
|
|
12771
|
-
UpgradeValidator: "
|
|
12772
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
12772
12773
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
12773
12774
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
12774
|
-
PriceFeedConsumer: "
|
|
12775
|
-
UCDMintingRewards: "
|
|
12776
|
-
PositionManagerCoreModule: "
|
|
12777
|
-
TermManagerModule: "
|
|
12778
|
-
LoanOperationsManagerModule: "
|
|
12779
|
-
CollateralManagerModule: "
|
|
12780
|
-
LiquidationManagerModule: "
|
|
12781
|
-
CircuitBreakerModule: "
|
|
12782
|
-
CommunityManagerModule: "
|
|
12783
|
-
AdminModule: "
|
|
12784
|
-
PositionManagerViews: "
|
|
12785
|
-
PositionManager: "
|
|
12786
|
-
OperationAuthorizationRegistry: "
|
|
12775
|
+
PriceFeedConsumer: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
12776
|
+
UCDMintingRewards: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
12777
|
+
PositionManagerCoreModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
12778
|
+
TermManagerModule: "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
|
|
12779
|
+
LoanOperationsManagerModule: "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
|
|
12780
|
+
CollateralManagerModule: "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
|
|
12781
|
+
LiquidationManagerModule: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
|
|
12782
|
+
CircuitBreakerModule: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
|
|
12783
|
+
CommunityManagerModule: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
|
|
12784
|
+
AdminModule: "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
|
|
12785
|
+
PositionManagerViews: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
12786
|
+
PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
|
|
12787
|
+
OperationAuthorizationRegistry: "0x9d4454B023096f34B160D6B654540c56A1F81688",
|
|
12788
|
+
PKPValidation: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
|
|
12787
12789
|
};
|
|
12788
12790
|
ALL_DEPLOYMENTS = {
|
|
12789
12791
|
sepolia: SEPOLIA_DEPLOYMENT,
|
|
@@ -12929,7 +12931,7 @@ function getSepoliaConfig() {
|
|
|
12929
12931
|
operationAuthorizationRegistry: SEPOLIA_CONTRACTS.OperationAuthorizationRegistry || ""
|
|
12930
12932
|
},
|
|
12931
12933
|
subgraphs: {
|
|
12932
|
-
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/v0.6.
|
|
12934
|
+
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/v0.6.19"
|
|
12933
12935
|
},
|
|
12934
12936
|
// litNetwork: "datil-test",
|
|
12935
12937
|
debug: true
|
|
@@ -13039,7 +13041,7 @@ function getLocalhostConfig() {
|
|
|
13039
13041
|
)
|
|
13040
13042
|
},
|
|
13041
13043
|
subgraphs: {
|
|
13042
|
-
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/v0.6.
|
|
13044
|
+
diamondHandsUrl: "https://api.studio.thegraph.com/query/65258/diamond-hands/v0.6.19"
|
|
13043
13045
|
},
|
|
13044
13046
|
litNetwork: "datil",
|
|
13045
13047
|
debug: true
|
|
@@ -13119,7 +13121,7 @@ __export(src_exports, {
|
|
|
13119
13121
|
ErrorCategory: () => ErrorCategory,
|
|
13120
13122
|
ErrorSeverity: () => ErrorSeverity,
|
|
13121
13123
|
EventHelpers: () => EventHelpers,
|
|
13122
|
-
LRUCache: () =>
|
|
13124
|
+
LRUCache: () => Cache,
|
|
13123
13125
|
LoanCreator: () => LoanCreator,
|
|
13124
13126
|
LoanQuery: () => LoanQuery,
|
|
13125
13127
|
LoanStatus: () => LoanStatus,
|
|
@@ -29943,333 +29945,106 @@ function createContractManager(config) {
|
|
|
29943
29945
|
}
|
|
29944
29946
|
|
|
29945
29947
|
// src/modules/cache/cache-manager.module.ts
|
|
29946
|
-
var
|
|
29947
|
-
cache;
|
|
29948
|
+
var Cache = class {
|
|
29949
|
+
cache = /* @__PURE__ */ new Map();
|
|
29948
29950
|
maxSize;
|
|
29949
29951
|
ttlMs;
|
|
29950
|
-
|
|
29951
|
-
|
|
29952
|
-
|
|
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
|
-
}
|
|
29952
|
+
constructor(config) {
|
|
29953
|
+
this.maxSize = config.maxSize;
|
|
29954
|
+
this.ttlMs = config.ttlMs;
|
|
29969
29955
|
}
|
|
29970
29956
|
/**
|
|
29971
29957
|
* 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
|
|
29979
29958
|
*/
|
|
29980
29959
|
get(key2) {
|
|
29981
29960
|
const entry = this.cache.get(key2);
|
|
29982
29961
|
if (!entry) {
|
|
29983
|
-
|
|
29984
|
-
if (this.debug) {
|
|
29985
|
-
console.log(`\u274C [${this.name}] Cache MISS: ${String(key2)}`);
|
|
29986
|
-
}
|
|
29987
|
-
return null;
|
|
29962
|
+
return void 0;
|
|
29988
29963
|
}
|
|
29989
|
-
|
|
29964
|
+
const now2 = Date.now();
|
|
29965
|
+
if (now2 - entry.timestamp > entry.ttl) {
|
|
29990
29966
|
this.cache.delete(key2);
|
|
29991
|
-
|
|
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
|
+
return void 0;
|
|
30007
29968
|
}
|
|
30008
29969
|
return entry.value;
|
|
30009
29970
|
}
|
|
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
|
-
}
|
|
30029
29971
|
/**
|
|
30030
29972
|
* 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)
|
|
30037
29973
|
*/
|
|
30038
29974
|
set(key2, value, ttl) {
|
|
30039
29975
|
if (this.cache.size >= this.maxSize && !this.cache.has(key2)) {
|
|
30040
|
-
this.
|
|
29976
|
+
const firstKey = this.cache.keys().next().value;
|
|
29977
|
+
if (firstKey) {
|
|
29978
|
+
this.cache.delete(firstKey);
|
|
29979
|
+
}
|
|
30041
29980
|
}
|
|
30042
|
-
|
|
29981
|
+
this.cache.set(key2, {
|
|
30043
29982
|
value,
|
|
30044
29983
|
timestamp: Date.now(),
|
|
30045
|
-
|
|
30046
|
-
|
|
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
|
-
}
|
|
30055
|
-
}
|
|
30056
|
-
/**
|
|
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
|
-
}
|
|
29984
|
+
ttl: ttl || this.ttlMs
|
|
29985
|
+
});
|
|
30073
29986
|
}
|
|
30074
29987
|
/**
|
|
30075
|
-
* Check if key exists in cache
|
|
29988
|
+
* Check if key exists in cache
|
|
30076
29989
|
*/
|
|
30077
29990
|
has(key2) {
|
|
30078
|
-
|
|
30079
|
-
return entry !== void 0 && !this.isExpired(entry);
|
|
29991
|
+
return this.get(key2) !== void 0;
|
|
30080
29992
|
}
|
|
30081
29993
|
/**
|
|
30082
|
-
* Delete
|
|
29994
|
+
* Delete key from cache
|
|
30083
29995
|
*/
|
|
30084
29996
|
delete(key2) {
|
|
30085
|
-
|
|
30086
|
-
if (deleted && this.debug) {
|
|
30087
|
-
console.log(`\u{1F5D1}\uFE0F [${this.name}] Cache DELETE: ${String(key2)}`);
|
|
30088
|
-
}
|
|
30089
|
-
return deleted;
|
|
29997
|
+
return this.cache.delete(key2);
|
|
30090
29998
|
}
|
|
30091
29999
|
/**
|
|
30092
|
-
* Clear
|
|
30000
|
+
* Clear all cache entries
|
|
30093
30001
|
*/
|
|
30094
30002
|
clear() {
|
|
30095
|
-
const previousSize = this.cache.size;
|
|
30096
30003
|
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;
|
|
30111
30004
|
}
|
|
30112
30005
|
/**
|
|
30113
|
-
*
|
|
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
|
+
* Clean expired entries
|
|
30169
30007
|
*/
|
|
30170
30008
|
cleanExpired() {
|
|
30171
30009
|
const now2 = Date.now();
|
|
30172
|
-
let
|
|
30010
|
+
let cleaned = 0;
|
|
30173
30011
|
for (const [key2, entry] of this.cache.entries()) {
|
|
30174
|
-
if (now2 - entry.timestamp >
|
|
30012
|
+
if (now2 - entry.timestamp > entry.ttl) {
|
|
30175
30013
|
this.cache.delete(key2);
|
|
30176
|
-
|
|
30014
|
+
cleaned++;
|
|
30177
30015
|
}
|
|
30178
30016
|
}
|
|
30179
|
-
|
|
30180
|
-
console.log(`\u{1F9F9} [${this.name}] Cleaned ${cleanedCount} expired entries`);
|
|
30181
|
-
}
|
|
30182
|
-
return cleanedCount;
|
|
30183
|
-
}
|
|
30184
|
-
/**
|
|
30185
|
-
* Check if cache entry is expired
|
|
30186
|
-
*/
|
|
30187
|
-
isExpired(entry) {
|
|
30188
|
-
return Date.now() - entry.timestamp > this.ttlMs;
|
|
30017
|
+
return cleaned;
|
|
30189
30018
|
}
|
|
30190
30019
|
/**
|
|
30191
|
-
*
|
|
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
|
|
30020
|
+
* Get cache statistics
|
|
30235
30021
|
*/
|
|
30236
|
-
|
|
30237
|
-
|
|
30238
|
-
|
|
30239
|
-
|
|
30240
|
-
|
|
30241
|
-
|
|
30242
|
-
if (result.success) {
|
|
30243
|
-
this.set(key2, result.value, ttl);
|
|
30244
|
-
}
|
|
30245
|
-
return result;
|
|
30022
|
+
getStats() {
|
|
30023
|
+
return {
|
|
30024
|
+
size: this.cache.size,
|
|
30025
|
+
maxSize: this.maxSize,
|
|
30026
|
+
ttlMs: this.ttlMs
|
|
30027
|
+
};
|
|
30246
30028
|
}
|
|
30247
30029
|
};
|
|
30248
30030
|
var CacheManager = class {
|
|
30249
30031
|
caches = /* @__PURE__ */ new Map();
|
|
30250
|
-
|
|
30251
|
-
constructor(
|
|
30252
|
-
this.
|
|
30032
|
+
debug;
|
|
30033
|
+
constructor(config = {}) {
|
|
30034
|
+
this.debug = config.debug || false;
|
|
30253
30035
|
}
|
|
30254
30036
|
/**
|
|
30255
|
-
*
|
|
30256
|
-
*
|
|
30257
|
-
* @param name - Unique cache name
|
|
30258
|
-
* @param config - Optional cache-specific configuration
|
|
30259
|
-
* @returns LRU cache instance
|
|
30037
|
+
* Get or create a cache instance
|
|
30260
30038
|
*/
|
|
30261
30039
|
getCache(name, config) {
|
|
30262
|
-
|
|
30263
|
-
|
|
30264
|
-
return existingCache;
|
|
30040
|
+
if (this.caches.has(name)) {
|
|
30041
|
+
return this.caches.get(name);
|
|
30265
30042
|
}
|
|
30266
|
-
const
|
|
30267
|
-
...this.globalConfig,
|
|
30268
|
-
...config,
|
|
30269
|
-
name
|
|
30270
|
-
};
|
|
30271
|
-
const cache = new LRUCache(mergedConfig);
|
|
30043
|
+
const cache = new Cache(config);
|
|
30272
30044
|
this.caches.set(name, cache);
|
|
30045
|
+
if (this.debug) {
|
|
30046
|
+
console.log(`[CacheManager] Created cache: ${name}`, config);
|
|
30047
|
+
}
|
|
30273
30048
|
return cache;
|
|
30274
30049
|
}
|
|
30275
30050
|
/**
|
|
@@ -30284,11 +30059,11 @@ var CacheManager = class {
|
|
|
30284
30059
|
* Clean expired entries from all caches
|
|
30285
30060
|
*/
|
|
30286
30061
|
cleanAllExpired() {
|
|
30287
|
-
let
|
|
30062
|
+
let total = 0;
|
|
30288
30063
|
for (const cache of this.caches.values()) {
|
|
30289
|
-
|
|
30064
|
+
total += cache.cleanExpired();
|
|
30290
30065
|
}
|
|
30291
|
-
return
|
|
30066
|
+
return total;
|
|
30292
30067
|
}
|
|
30293
30068
|
/**
|
|
30294
30069
|
* Get statistics for all caches
|
|
@@ -30301,16 +30076,11 @@ var CacheManager = class {
|
|
|
30301
30076
|
return stats;
|
|
30302
30077
|
}
|
|
30303
30078
|
/**
|
|
30304
|
-
*
|
|
30079
|
+
* Destroy cache manager
|
|
30305
30080
|
*/
|
|
30306
|
-
|
|
30307
|
-
|
|
30308
|
-
|
|
30309
|
-
/**
|
|
30310
|
-
* Delete a named cache
|
|
30311
|
-
*/
|
|
30312
|
-
deleteCache(name) {
|
|
30313
|
-
return this.caches.delete(name);
|
|
30081
|
+
destroy() {
|
|
30082
|
+
this.clearAll();
|
|
30083
|
+
this.caches.clear();
|
|
30314
30084
|
}
|
|
30315
30085
|
};
|
|
30316
30086
|
function createCacheManager(config) {
|