refactor(all): uniformisation

This commit is contained in:
BlackAngelTV committed 2026-09-23 18:25:28 +02:00
1 parent ee538cb943
commit 50665c8edd
89 files changed
+10215 -10215

No files matched your search

+18 -18
View File
@@ -1,18 +1,18 @@
/** In-memory guard against duplicate actions within a time window (M13-T08). */
export function createCooldown(windowMs) {
const entries = new Map();
return {
/** Returns true when the key is free, and locks it for `windowMs`. */
acquire(key) {
const now = Date.now();
const expiresAt = entries.get(key);
if (expiresAt && expiresAt > now) return false;
entries.set(key, now + windowMs);
return true;
},
release(key) {
entries.delete(key);
},
};
}
/** In-memory guard against duplicate actions within a time window (M13-T08). */
export function createCooldown(windowMs) {
const entries = new Map();
return {
/** Returns true when the key is free, and locks it for `windowMs`. */
acquire(key) {
const now = Date.now();
const expiresAt = entries.get(key);
if (expiresAt && expiresAt > now) return false;
entries.set(key, now + windowMs);
return true;
},
release(key) {
entries.delete(key);
},
};
}
+19 -19
View File
@@ -1,19 +1,19 @@
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
/**
* Retries an async operation with exponential backoff (M13-T05).
* `shouldRetry` decides whether an error is transient.
*/
export async function withRetry(
operation,
{ retries = 2, baseDelayMs = 500, shouldRetry = () => true } = {},
) {
for (let attempt = 0; ; attempt += 1) {
try {
return await operation(attempt);
} catch (error) {
if (attempt >= retries || !shouldRetry(error)) throw error;
await sleep(baseDelayMs * 2 ** attempt);
}
}
}
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
/**
* Retries an async operation with exponential backoff (M13-T05).
* `shouldRetry` decides whether an error is transient.
*/
export async function withRetry(
operation,
{ retries = 2, baseDelayMs = 500, shouldRetry = () => true } = {},
) {
for (let attempt = 0; ; attempt += 1) {
try {
return await operation(attempt);
} catch (error) {
if (attempt >= retries || !shouldRetry(error)) throw error;
await sleep(baseDelayMs * 2 ** attempt);
}
}
}