Archipelago — open-source initial import

This commit is contained in:
Archipelago
2026-08-12 10:55:50 +00:00
commit b67e1527a2
2068 changed files with 472303 additions and 0 deletions
@@ -0,0 +1,29 @@
const inflight = new Map<string, Promise<Response>>()
export function useDeduplicatedFetch() {
async function dedupFetch(url: string, options?: RequestInit): Promise<Response> {
// Generate a cache key from URL + body
const bodyStr = options?.body ? String(options.body) : ''
const key = `${options?.method ?? 'GET'}:${url}:${bodyStr}`
const existing = inflight.get(key)
if (existing) return existing.then(r => r.clone())
const controller = new AbortController()
const mergedOptions = { ...options, signal: controller.signal }
const promise = fetch(url, mergedOptions).finally(() => {
inflight.delete(key)
})
inflight.set(key, promise)
return promise
}
function cancelAll() {
inflight.clear()
}
return { dedupFetch, cancelAll }
}