mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-05 20:31:54 +00:00
fix(lint): resolve duplicate exports and consolidate utilities
- `src/lock-utils.mjs`: Removed duplicate definition of `mergeRelayList` (already re-exported). - `src/lock-publisher.mjs`: Removed duplicate definitions of `secureRandom`, `withTimeout`, and `MAX_RANDOM`. Now imports them from `src/lock-utils.mjs`. Removed unused `randomInt` import. - `src/lock-ops.mjs`: Removed duplicate import of `relayListLabel` and local definition of `withTimeout`. - `test/utils.test.mjs`, `test/utils-async.test.mjs`: Updated imports to point to `src/lock-utils.mjs` for moved utilities. Verified locally with `npm run lint` and `npm test`. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
54c524dd25
commit
7fdd2f7501
8 files changed
+6
-58
No files matched your search
+2
-14
@@ -1,4 +1,4 @@
|
||||
import { randomUUID, randomInt } from 'node:crypto';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { SimplePool } from 'nostr-tools/pool';
|
||||
import {
|
||||
getPublishTimeoutMs,
|
||||
@@ -6,20 +6,10 @@ import {
|
||||
getRelayFallbacks,
|
||||
getMinActiveRelayPool,
|
||||
} from './torch-config.mjs';
|
||||
import { mergeRelayList } from './lock-utils.mjs';
|
||||
import { mergeRelayList, secureRandom, withTimeout } from './lock-utils.mjs';
|
||||
import { defaultHealthManager, buildRelayHealthConfig } from './relay-health-manager.mjs';
|
||||
import { relayListLabel } from './utils.mjs';
|
||||
|
||||
function withTimeout(promise, timeoutMs, timeoutMessage) {
|
||||
let timeoutHandle;
|
||||
const timeoutPromise = new Promise((_, reject) => {
|
||||
timeoutHandle = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
|
||||
});
|
||||
return Promise.race([promise, timeoutPromise]).finally(() => {
|
||||
if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||
});
|
||||
}
|
||||
|
||||
const PUBLISH_ERROR_CODES = {
|
||||
TIMEOUT: 'publish_timeout',
|
||||
DNS: 'dns_resolution',
|
||||
@@ -111,8 +101,6 @@ function isTransientPublishCategory(category) {
|
||||
].includes(category);
|
||||
}
|
||||
|
||||
export { secureRandom };
|
||||
|
||||
function calculateBackoffDelayMs(attemptNumber, baseMs, capMs, randomFn = secureRandom) {
|
||||
const maxDelay = Math.min(capMs, baseMs * (2 ** Math.max(0, attemptNumber - 1)));
|
||||
return Math.floor(randomFn() * maxDelay);
|
||||
|
||||
+1
-5
@@ -3,7 +3,7 @@ import path from 'node:path';
|
||||
import { randomInt } from 'node:crypto';
|
||||
import { todayDateStr, getIsoWeekStr } from './utils.mjs';
|
||||
|
||||
export { relayListLabel } from './utils.mjs';
|
||||
export { relayListLabel, mergeRelayList } from './utils.mjs';
|
||||
|
||||
/**
|
||||
* Scans the local log directory to identify agents that have already completed their task
|
||||
@@ -69,10 +69,6 @@ export async function getCompletedAgents(cadence, logDir, deps) {
|
||||
return completed;
|
||||
}
|
||||
|
||||
export function mergeRelayList(primaryRelays, fallbackRelays) {
|
||||
return [...new Set([...primaryRelays, ...fallbackRelays])];
|
||||
}
|
||||
|
||||
const MAX_RANDOM = 281474976710655; // 2**48 - 1
|
||||
|
||||
export function secureRandom() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import WebSocket from 'ws';
|
||||
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools/pure';
|
||||
import { getNamespace, getRelays } from './torch-config.mjs';
|
||||
import { MS_PER_SECOND } from './constants.mjs';
|
||||
import { withTimeout } from './lock-utils.mjs';
|
||||
import { withTimeout } from './utils.mjs';
|
||||
|
||||
const PROBE_KIND = 27235;
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
- [x] Update `README.md` to include `scheduler:daily`, `scheduler:weekly`, and `lock:complete`.
|
||||
- [x] Update `TORCH.md` to include `scheduler:daily`, `scheduler:weekly`, and `lock:complete`.
|
||||
- [x] Verify updated commands run correctly (where applicable/safe).
|
||||
- Fixed syntax errors and circular dependencies in `src/lock-ops.mjs`, `src/lock-utils.mjs`, `src/lock-publisher.mjs`, and `src/relay-health.mjs` that were preventing commands from running.
|
||||
|
||||
## Blocked
|
||||
- None.
|
||||
Reference in new issue
Block a user