fix(lint): resolve duplicate identifiers and missing exports

- Removed duplicate `relayListLabel` import in `src/lock-ops.mjs`.
- Removed duplicate `mergeRelayList` declaration in `src/lock-publisher.mjs`.
- Moved `withTimeout` implementation to `src/lock-utils.mjs` and ensured it is exported.
- Updated `test/utils.test.mjs` and `test/utils-async.test.mjs` to import from `src/lock-utils.mjs` where appropriate.
- Added `randomInt` import in `src/lock-publisher.mjs` to fix `no-undef`.
- Verified with `npm run lint` and `npm test`.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-20 21:58:00 +00:00
1 parent 8b019b1a84
commit 141b317764
5 files changed
+23 -24

No files matched your search

+1 -15
View File
@@ -8,7 +8,7 @@ import {
KIND_APP_DATA,
MS_PER_SECOND,
} from './constants.mjs';
import { nowUnix, relayListLabel } from './utils.mjs';
import { nowUnix } from './utils.mjs';
import { defaultHealthManager, buildRelayHealthConfig, RelayHealthManager } from './relay-health-manager.mjs';
import { publishLock, LockPublisher } from './lock-publisher.mjs';
import {
@@ -61,20 +61,6 @@ function filterActiveLocks(locks) {
return locks.filter((lock) => !lock.expiresAt || lock.expiresAt > now);
}
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);
});
}
function mergeRelayList(primaryRelays, fallbackRelays) {
return [...new Set([...primaryRelays, ...fallbackRelays])];
}
/**
* Queries relays for active lock events matching the criteria.
* Uses a tiered approach: tries primary relays first, then falls back to others if needed.
+2 -6
View File
@@ -1,4 +1,4 @@
import { randomUUID } from 'node:crypto';
import { randomUUID, randomInt } from 'node:crypto';
import { SimplePool } from 'nostr-tools/pool';
import {
getPublishTimeoutMs,
@@ -6,7 +6,7 @@ import {
getRelayFallbacks,
getMinActiveRelayPool,
} from './torch-config.mjs';
import { mergeRelayList } from './utils.mjs';
import { mergeRelayList } from './lock-utils.mjs';
import { defaultHealthManager, buildRelayHealthConfig } from './relay-health-manager.mjs';
import { relayListLabel } from './utils.mjs';
@@ -20,10 +20,6 @@ function withTimeout(promise, timeoutMs, timeoutMessage) {
});
}
function mergeRelayList(primaryRelays, fallbackRelays) {
return [...new Set([...primaryRelays, ...fallbackRelays])];
}
const PUBLISH_ERROR_CODES = {
TIMEOUT: 'publish_timeout',
DNS: 'dns_resolution',
+18 -2
View File
@@ -14,6 +14,24 @@ export { relayListLabel } from './utils.mjs';
* @param {Object} deps - Dependency injection for testing
* @returns {Promise<Set<string>>} - Set of agent names that have completed their task
*/
/**
* Promisified timeout wrapper.
*
* @param {Promise} promise - The promise to wrap.
* @param {number} timeoutMs - Timeout in milliseconds.
* @param {string} timeoutMessage - Error message on timeout.
* @returns {Promise} - The result of the promise or a timeout error.
*/
export 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);
});
}
export async function getCompletedAgents(cadence, logDir, deps) {
const { readdir = fs.readdir, getDateStr = todayDateStr, getIsoWeek = getIsoWeekStr } = deps;
const completed = new Set();
@@ -51,8 +69,6 @@ export async function getCompletedAgents(cadence, logDir, deps) {
return completed;
}
export { withTimeout };
export function mergeRelayList(primaryRelays, fallbackRelays) {
return [...new Set([...primaryRelays, ...fallbackRelays])];
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { withTimeout } from '../src/utils.mjs';
import { withTimeout } from '../src/lock-utils.mjs';
describe('Async Utilities', () => {
describe('withTimeout', () => {
+1
View File
@@ -3,6 +3,7 @@ import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { getIsoWeekStr, todayDateStr, nowUnix, ensureDir, detectPlatform, relayListLabel } from '../src/utils.mjs';
import { mergeRelayList } from '../src/lock-utils.mjs';
describe('Date Utilities', () => {
describe('todayDateStr', () => {