ton-provider-system 0.1.1 → 0.1.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/dist/index.cjs +52 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -1
- package/dist/index.d.ts +59 -1
- package/dist/index.js +52 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1898,10 +1898,20 @@ var _ProviderManager = class _ProviderManager {
|
|
|
1898
1898
|
this.rateLimiter = createRateLimiterManager(this.options.logger);
|
|
1899
1899
|
for (const provider of this.registry.getAllProviders()) {
|
|
1900
1900
|
const config2 = getRateLimitForType(provider.type);
|
|
1901
|
+
const minDelayMs = Math.ceil(1e3 / provider.rps * 1.1);
|
|
1902
|
+
let burstSize;
|
|
1903
|
+
if (provider.rps <= 3) {
|
|
1904
|
+
burstSize = 1;
|
|
1905
|
+
} else if (provider.rps <= 5) {
|
|
1906
|
+
burstSize = 2;
|
|
1907
|
+
} else {
|
|
1908
|
+
burstSize = Math.max(3, Math.ceil(provider.rps * 1.5));
|
|
1909
|
+
}
|
|
1901
1910
|
this.rateLimiter.setConfig(provider.id, {
|
|
1902
1911
|
...config2,
|
|
1903
1912
|
rps: provider.rps,
|
|
1904
|
-
minDelayMs
|
|
1913
|
+
minDelayMs,
|
|
1914
|
+
burstSize
|
|
1905
1915
|
});
|
|
1906
1916
|
}
|
|
1907
1917
|
this.healthChecker = createHealthChecker(
|
|
@@ -2307,6 +2317,17 @@ var NodeAdapter = class {
|
|
|
2307
2317
|
* Get TonClient instance
|
|
2308
2318
|
*
|
|
2309
2319
|
* Creates a new client if endpoint changed, otherwise returns cached.
|
|
2320
|
+
*
|
|
2321
|
+
* NOTE: Direct TonClient calls bypass rate limiting. For rate-limited operations,
|
|
2322
|
+
* use adapter methods (getAddressState, runGetMethod, etc.) or wrap your calls
|
|
2323
|
+
* with rate limit token acquisition.
|
|
2324
|
+
*
|
|
2325
|
+
* Example with rate limiting:
|
|
2326
|
+
* ```typescript
|
|
2327
|
+
* const endpoint = await adapter.manager.getEndpointWithRateLimit();
|
|
2328
|
+
* // Make your TonClient call
|
|
2329
|
+
* adapter.manager.reportSuccess(); // or reportError() on failure
|
|
2330
|
+
* ```
|
|
2310
2331
|
*/
|
|
2311
2332
|
async getClient() {
|
|
2312
2333
|
const endpoint = await this.manager.getEndpoint();
|
|
@@ -2332,6 +2353,19 @@ var NodeAdapter = class {
|
|
|
2332
2353
|
this.logger.debug(`Created TonClient for ${network}`, { endpoint });
|
|
2333
2354
|
return client;
|
|
2334
2355
|
}
|
|
2356
|
+
/**
|
|
2357
|
+
* Get TonClient with rate limiting applied
|
|
2358
|
+
*
|
|
2359
|
+
* Acquires a rate limit token before returning the client.
|
|
2360
|
+
* Use this when you need to ensure rate limiting is respected.
|
|
2361
|
+
*
|
|
2362
|
+
* Note: This only acquires ONE token. For multiple operations,
|
|
2363
|
+
* you should acquire tokens before each operation or use adapter methods.
|
|
2364
|
+
*/
|
|
2365
|
+
async getClientWithRateLimit(timeoutMs) {
|
|
2366
|
+
await this.manager.getEndpointWithRateLimit(timeoutMs);
|
|
2367
|
+
return this.getClient();
|
|
2368
|
+
}
|
|
2335
2369
|
/**
|
|
2336
2370
|
* Reset client cache (forces new client creation)
|
|
2337
2371
|
*/
|
|
@@ -2517,6 +2551,22 @@ async function getTonClient(manager) {
|
|
|
2517
2551
|
const adapter = new NodeAdapter(manager);
|
|
2518
2552
|
return adapter.getClient();
|
|
2519
2553
|
}
|
|
2554
|
+
async function getTonClientWithRateLimit(manager) {
|
|
2555
|
+
const adapter = new NodeAdapter(manager);
|
|
2556
|
+
const client = await adapter.getClient();
|
|
2557
|
+
const withRateLimit = async (fn) => {
|
|
2558
|
+
await manager.getEndpointWithRateLimit();
|
|
2559
|
+
try {
|
|
2560
|
+
const result = await fn();
|
|
2561
|
+
manager.reportSuccess();
|
|
2562
|
+
return result;
|
|
2563
|
+
} catch (error) {
|
|
2564
|
+
manager.reportError(error);
|
|
2565
|
+
throw error;
|
|
2566
|
+
}
|
|
2567
|
+
};
|
|
2568
|
+
return { client, withRateLimit };
|
|
2569
|
+
}
|
|
2520
2570
|
async function getTonClientForNetwork(network, configPath) {
|
|
2521
2571
|
const manager = ProviderManager.getInstance({ configPath });
|
|
2522
2572
|
if (!manager.isInitialized() || manager.getNetwork() !== network) {
|
|
@@ -2855,6 +2905,7 @@ exports.getProvidersForNetwork = getProvidersForNetwork;
|
|
|
2855
2905
|
exports.getRateLimitForType = getRateLimitForType;
|
|
2856
2906
|
exports.getTonClient = getTonClient;
|
|
2857
2907
|
exports.getTonClientForNetwork = getTonClientForNetwork;
|
|
2908
|
+
exports.getTonClientWithRateLimit = getTonClientWithRateLimit;
|
|
2858
2909
|
exports.isApiVersion = isApiVersion;
|
|
2859
2910
|
exports.isChainstackUrl = isChainstackUrl;
|
|
2860
2911
|
exports.isNetwork = isNetwork;
|