saveFieldDetectionCacheForUrl function infrastructure exported ✓ 100.0%
Last updated: 2026-02-24T21:07:57.500Z
Metrics
LOC: 45
Complexity: 9
Params: 3
Coverage: 100.0% (12/12 lines, 5x executed)
Signature
saveFieldDetectionCacheForUrl(
url: string,
fields: DetectedFieldSummary[],
): : Promise<FieldDetectionCacheEntry>
Summary
Saves detected fields for a URL in the cache. Deduplicates by URL and origin+path. Evicts oldest entries beyond the limit.
Tags
#@param url - Full page URL#@param fields - Array of detected field summaries#@returns The saved cache entry
Source Code
export async function saveFieldDetectionCacheForUrl(
url: string,
fields: DetectedFieldSummary[],
): Promise<FieldDetectionCacheEntry> {
const now = Date.now();
let parsed: URL | null = null;
try {
parsed = new URL(url);
} catch {
// keep null and fallback to plain values
}
const entry: FieldDetectionCacheEntry = {
url,
origin: parsed?.origin ?? "",
hostname: parsed?.hostname ?? "",
path: parsed?.pathname ?? "",
count: fields.length,
fields,
updatedAt: now,
};
await updateStorageAtomically(
STORAGE_KEYS.FIELD_CACHE,
[] as FieldDetectionCacheEntry[],
(existing) => {
const filtered = existing.filter(
(item) =>
item.url !== url &&
!(
entry.origin &&
entry.path &&
item.origin === entry.origin &&
item.path === entry.path
),
);
filtered.push(entry);
return filtered
.sort((a, b) => b.updatedAt - a.updatedAt)
.slice(0, MAX_FIELD_CACHE_ENTRIES);
},
);
return entry;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| updateStorageAtomically | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handle | uses |