addDatasetEntry function exported ✓ 100.0%
Last updated: 2026-02-24T21:07:57.500Z
Metrics
LOC: 42
Complexity: 6
Params: 3
Coverage: 100.0% (12/12 lines, 2x executed)
Signature
addDatasetEntry(
entry: Omit<DatasetEntry, "id" | "createdAt">,
): : Promise<DatasetEntry | null>
Summary
Adds a single entry to the dataset. Deduplicates by normalised signals — if an identical signals string already exists with the same type, the entry is updated in place.
Source Code
export async function addDatasetEntry(
entry: Omit<DatasetEntry, "id" | "createdAt">,
): Promise<DatasetEntry | null> {
const normalized = normalise(entry.signals);
if (!normalized) {
log.warn(
"addDatasetEntry: signals está vazio após normalização — ignorando",
);
return null;
}
const existing = await getDatasetEntries();
const dupIdx = existing.findIndex(
(e) => e.signals === normalized && e.type === entry.type,
);
const newEntry: DatasetEntry =
dupIdx >= 0
? {
...existing[dupIdx],
source: entry.source,
difficulty: entry.difficulty,
createdAt: Date.now(),
}
: {
id: generateId(),
signals: normalized,
type: entry.type,
source: entry.source,
difficulty: entry.difficulty,
createdAt: Date.now(),
};
const updated =
dupIdx >= 0
? existing.map((e, i) => (i === dupIdx ? newEntry : e))
: [...existing, newEntry];
await chrome.storage.local.set({ [RUNTIME_DATASET_KEY]: updated });
return newEntry;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| normalise | calls |
| getDatasetEntries | calls |
| generateId | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handle | uses |
| handle | uses |
| LearnedEntry | uses |
| makeEntry | uses |
| getContextHtml | uses |