importDatasetEntries function exported ✓ 100.0%
Last updated: 2026-02-24T21:07:57.500Z
Metrics
LOC: 37
Complexity: 9
Params: 3
Coverage: 100.0% (15/15 lines, 1x executed)
Signature
importDatasetEntries(
entries: Array<
Omit<DatasetEntry, "id" | "createdAt"> & { id?: string; createdAt?: number }
>,
): : Promise<number>
Summary
Bulk-import entries (e.g. from JSON file). Deduplicates by signals+type. Returns the number of newly added entries.
Source Code
export async function importDatasetEntries(
entries: Array<
Omit<DatasetEntry, "id" | "createdAt"> & { id?: string; createdAt?: number }
>,
): Promise<number> {
const existing = await getDatasetEntries();
const existingKeys = new Set(existing.map((e) => `${e.signals}::${e.type}`));
let added = 0;
const toAdd: DatasetEntry[] = [];
for (const raw of entries) {
const normalized = normalise(raw.signals);
if (!normalized) continue;
const key = `${normalized}::${raw.type}`;
if (existingKeys.has(key)) continue;
toAdd.push({
id: raw.id ?? generateId(),
signals: normalized,
type: raw.type,
source: raw.source ?? "imported",
difficulty: raw.difficulty ?? "easy",
createdAt: raw.createdAt ?? Date.now(),
});
existingKeys.add(key);
added++;
}
if (added > 0) {
await chrome.storage.local.set({
[RUNTIME_DATASET_KEY]: [...existing, ...toAdd],
});
}
return added;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getDatasetEntries | calls |
| normalise | calls |
| generateId | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handle | uses |