@bitcobblers/wod-wiki-engine 0.57.2213 → 0.58.2220
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.cjs +1 -1
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.mjs +1 -1
- package/dist/{chunk-RSRZKD7M.mjs → chunk-ZMTTEJUB.mjs} +325 -283
- package/dist/chunk-ZMTTEJUB.mjs.map +1 -0
- package/dist/index.cjs +323 -280
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.mjs +1 -1
- package/package.json +5 -5
- package/dist/chunk-RSRZKD7M.mjs.map +0 -1
|
@@ -858,13 +858,13 @@ function csvToTelemetryBundle(csv) {
|
|
|
858
858
|
}
|
|
859
859
|
|
|
860
860
|
// src/version.ts
|
|
861
|
-
var VERSION = "0.
|
|
862
|
-
var GIT_SHA = "
|
|
863
|
-
var BUILD_TIME = "2026-11-
|
|
861
|
+
var VERSION = "0.58.2220";
|
|
862
|
+
var GIT_SHA = "89b2e39";
|
|
863
|
+
var BUILD_TIME = "2026-11-14T03:19:12.696Z";
|
|
864
864
|
var SEMVER = {
|
|
865
|
-
version: "0.
|
|
866
|
-
gitSha: "
|
|
867
|
-
buildTime: "2026-11-
|
|
865
|
+
version: "0.58.2220",
|
|
866
|
+
gitSha: "89b2e39",
|
|
867
|
+
buildTime: "2026-11-14T03:19:12.696Z"
|
|
868
868
|
};
|
|
869
869
|
var SEED_SCHEMA = 9;
|
|
870
870
|
var SEED_REGISTERED_WIDGETS = KNOWN_SECTION_WIDGETS;
|
|
@@ -1560,10 +1560,26 @@ async function putChanged(store, values, keys) {
|
|
|
1560
1560
|
const changed = values.filter((value, i) => !equal(value, prior[i]));
|
|
1561
1561
|
if (changed.length) await store.putMany(changed);
|
|
1562
1562
|
}
|
|
1563
|
-
|
|
1563
|
+
var SEED_TX_STORES = [
|
|
1564
|
+
"notes",
|
|
1565
|
+
"block_revisions",
|
|
1566
|
+
"block_index",
|
|
1567
|
+
"block_efforts",
|
|
1568
|
+
"block_equipment",
|
|
1569
|
+
"page",
|
|
1570
|
+
"page_notes",
|
|
1571
|
+
"tags",
|
|
1572
|
+
"note_tags",
|
|
1573
|
+
"efforts",
|
|
1574
|
+
"equipment",
|
|
1575
|
+
"property_overrides",
|
|
1576
|
+
"meta",
|
|
1577
|
+
"sessions",
|
|
1578
|
+
"events"
|
|
1579
|
+
];
|
|
1580
|
+
async function prepareSeedChunkWrite(write) {
|
|
1564
1581
|
assertSeedManifest(write.manifest);
|
|
1565
1582
|
assertSeedRows(write.rows);
|
|
1566
|
-
const result = { totalNotes: 0, totalEfforts: 0, totalEquipment: 0, totalBlocks: 0, skippedUserOwned: 0, deleted: 0, addedNotes: 0, updatedNotes: 0 };
|
|
1567
1583
|
const ids = await Promise.all(write.rows.map((row) => seedNoteId(row.path)));
|
|
1568
1584
|
const pagesBySlug = /* @__PURE__ */ new Map();
|
|
1569
1585
|
const linkIds = /* @__PURE__ */ new Map();
|
|
@@ -1578,286 +1594,312 @@ async function applySeedChunk(storage, write) {
|
|
|
1578
1594
|
if (!tagIds.has(label)) tagIds.set(label, await seedNoteId(`tag:${label}`));
|
|
1579
1595
|
}
|
|
1580
1596
|
}
|
|
1581
|
-
return
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1597
|
+
return { write, ids, pagesBySlug, linkIds, tagIds };
|
|
1598
|
+
}
|
|
1599
|
+
async function applySeedChunks(storage, writes) {
|
|
1600
|
+
const empty = { totalNotes: 0, totalEfforts: 0, totalEquipment: 0, totalBlocks: 0, skippedUserOwned: 0, deleted: 0, addedNotes: 0, updatedNotes: 0 };
|
|
1601
|
+
if (!writes.length) return empty;
|
|
1602
|
+
const prepared = await Promise.all(writes.map(prepareSeedChunkWrite));
|
|
1603
|
+
return storage.transaction(SEED_TX_STORES, "readwrite", async (tx) => {
|
|
1604
|
+
const total = { ...empty };
|
|
1605
|
+
for (const item of prepared) {
|
|
1606
|
+
const part = await applyPreparedSeedChunkInTx(tx, item);
|
|
1607
|
+
total.totalNotes += part.totalNotes;
|
|
1608
|
+
total.totalEfforts += part.totalEfforts;
|
|
1609
|
+
total.totalEquipment += part.totalEquipment;
|
|
1610
|
+
total.totalBlocks += part.totalBlocks;
|
|
1611
|
+
total.skippedUserOwned += part.skippedUserOwned;
|
|
1612
|
+
total.deleted += part.deleted;
|
|
1613
|
+
total.addedNotes += part.addedNotes;
|
|
1614
|
+
total.updatedNotes += part.updatedNotes;
|
|
1615
|
+
}
|
|
1616
|
+
return total;
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
async function applySeedChunk(storage, write) {
|
|
1620
|
+
return applySeedChunks(storage, [write]);
|
|
1621
|
+
}
|
|
1622
|
+
async function applyPreparedSeedChunkInTx(tx, prepared) {
|
|
1623
|
+
const { write, ids, pagesBySlug, linkIds, tagIds } = prepared;
|
|
1624
|
+
const result = { totalNotes: 0, totalEfforts: 0, totalEquipment: 0, totalBlocks: 0, skippedUserOwned: 0, deleted: 0, addedNotes: 0, updatedNotes: 0 };
|
|
1625
|
+
const metaStore = tx.readwrite("meta");
|
|
1626
|
+
const userDeleted = /* @__PURE__ */ new Set();
|
|
1627
|
+
for (const row of await metaStore.getAll()) {
|
|
1628
|
+
const suppressed = userDeletedSeedNoteId(row?.key);
|
|
1629
|
+
if (suppressed !== void 0) userDeleted.add(suppressed);
|
|
1630
|
+
}
|
|
1631
|
+
const actualMeta = await metaStore.get(write.meta.key);
|
|
1632
|
+
if (!equal(actualMeta, write.expectedMeta)) throw new Error("Seed checkpoint changed during import");
|
|
1633
|
+
if (write.meta.schema !== SEED_SCHEMA || write.manifest.schema !== SEED_SCHEMA) throw new Error("Incompatible seed schema; recreate artifacts");
|
|
1634
|
+
const noteStore = tx.readwrite("notes");
|
|
1635
|
+
const priorIds = write.chunkId ? write.expectedMeta?.chunks[write.chunkId]?.noteIds ?? [] : [];
|
|
1636
|
+
const declared = new Set((write.chunkId ? write.meta.chunks[write.chunkId]?.noteIds : void 0) ?? ids);
|
|
1637
|
+
const goneIds = priorIds.filter((id) => !declared.has(id));
|
|
1638
|
+
const allIds = [.../* @__PURE__ */ new Set([...ids, ...goneIds])];
|
|
1639
|
+
const stored = await noteStore.getMany(allIds);
|
|
1640
|
+
const existingById = new Map(allIds.map((id, i) => [id, stored[i]]));
|
|
1641
|
+
const seedSource = write.meta.key.startsWith("seed:") ? write.meta.key.slice(5) : write.meta.key;
|
|
1642
|
+
const feedSourceId = feedIdOfMetaKey(write.meta.key);
|
|
1643
|
+
const incomingRank = seedPrecedenceRank(write.meta.key, write.meta.tier);
|
|
1644
|
+
const otherCheckpoints = [];
|
|
1645
|
+
for (const row of await metaStore.getAll()) {
|
|
1646
|
+
const meta = row;
|
|
1647
|
+
if (!meta || typeof meta.key !== "string" || !meta.key.startsWith("seed:") || meta.key === write.meta.key) continue;
|
|
1648
|
+
const noteIds = /* @__PURE__ */ new Set();
|
|
1649
|
+
for (const chunk of Object.values(meta.chunks ?? {})) {
|
|
1650
|
+
for (const noteId of chunk.noteIds ?? []) noteIds.add(noteId);
|
|
1651
|
+
}
|
|
1652
|
+
otherCheckpoints.push({
|
|
1653
|
+
key: meta.key,
|
|
1654
|
+
sourceId: meta.key.slice(5),
|
|
1655
|
+
rank: seedPrecedenceRank(meta.key, meta.tier),
|
|
1656
|
+
meta,
|
|
1657
|
+
noteIds
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
otherCheckpoints.sort((a, b) => b.rank - a.rank);
|
|
1661
|
+
const maxOtherRankForNote = (noteId) => {
|
|
1662
|
+
let max = -1;
|
|
1663
|
+
for (const cp of otherCheckpoints) {
|
|
1664
|
+
if (cp.noteIds.has(noteId) && cp.rank > max) max = cp.rank;
|
|
1587
1665
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1666
|
+
return max;
|
|
1667
|
+
};
|
|
1668
|
+
const ownedIds = allIds.filter((id) => {
|
|
1669
|
+
if (userDeleted.has(id)) return false;
|
|
1670
|
+
const note = existingById.get(id);
|
|
1671
|
+
if (!note) return declared.has(id);
|
|
1672
|
+
if (note.seedOrigin !== "seed") return false;
|
|
1673
|
+
const otherRank = maxOtherRankForNote(id);
|
|
1674
|
+
if (declared.has(id)) return incomingRank >= otherRank;
|
|
1675
|
+
return otherRank < 0 && note.seedChunkId === write.chunkId;
|
|
1676
|
+
});
|
|
1677
|
+
const owned = new Set(ownedIds);
|
|
1678
|
+
const revisionStore = tx.readwrite("block_revisions");
|
|
1679
|
+
const historyIds = ids.filter((id, i) => owned.has(id) && existingById.get(id)?.rawContent !== write.rows[i].content);
|
|
1680
|
+
const histories = await revisionStore.getAllFromIndexMany("by-note", historyIds);
|
|
1681
|
+
const history = new Map(historyIds.map((id, i) => [id, histories[i]]));
|
|
1682
|
+
const indexStore = tx.readwrite("block_index"), effortLinks = tx.readwrite("block_efforts"), equipmentLinks = tx.readwrite("block_equipment");
|
|
1683
|
+
const tagLinks = tx.readwrite("note_tags"), pageLinks = tx.readwrite("page_notes");
|
|
1684
|
+
const currentIndexes = await indexStore.getAllFromIndexMany("by-note", ownedIds);
|
|
1685
|
+
const currentEfforts = await effortLinks.getAllFromIndexMany("by-note", ownedIds);
|
|
1686
|
+
const currentEquipment = await equipmentLinks.getAllFromIndexMany("by-note", ownedIds);
|
|
1687
|
+
const currentTags = await tagLinks.getAllFromIndexMany("by-note", ownedIds);
|
|
1688
|
+
const currentPages = await pageLinks.getAllFromIndexMany("by-note", ownedIds);
|
|
1689
|
+
const slot = new Map(ownedIds.map((id, i) => [id, i]));
|
|
1690
|
+
const tagsStore = tx.readwrite("tags");
|
|
1691
|
+
const labels = [...tagIds.keys()];
|
|
1692
|
+
const matches = await tagsStore.getAllFromIndexMany("by-label", labels);
|
|
1693
|
+
const tagsByLabel = new Map(labels.map((label, i) => [label, matches[i][0]]));
|
|
1694
|
+
const changedTags = [], changedNotes = [], revisions = [], pages = [], pageNotes = [], noteTags = [];
|
|
1695
|
+
const blocks = [], blockEfforts = [], blockEquipment = [];
|
|
1696
|
+
const sessionStore = tx.readwrite("sessions"), eventStore = tx.readwrite("events");
|
|
1697
|
+
const telemetrySessionIds = write.rows.flatMap((row) => row.telemetry?.sessions.map((session) => session.id) ?? []);
|
|
1698
|
+
const storedTelemetrySessions = await sessionStore.getMany(telemetrySessionIds);
|
|
1699
|
+
const existingTelemetrySessions = new Map(telemetrySessionIds.map((sessionId, i) => [sessionId, storedTelemetrySessions[i]]));
|
|
1700
|
+
const sessions = [], events = [];
|
|
1701
|
+
for (const [i, row] of write.rows.entries()) {
|
|
1702
|
+
const id = ids[i], existing = existingById.get(id);
|
|
1703
|
+
if (!owned.has(id)) {
|
|
1704
|
+
if (existing && existing.seedOrigin !== "seed") result.skippedUserOwned++;
|
|
1705
|
+
continue;
|
|
1616
1706
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
const
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
const
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
const
|
|
1646
|
-
const
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
const
|
|
1650
|
-
const
|
|
1651
|
-
const
|
|
1652
|
-
const
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1707
|
+
if (!existing) result.addedNotes++;
|
|
1708
|
+
else if (existing.rawContent !== row.content) result.updatedNotes++;
|
|
1709
|
+
validateNoteBlocks(row.content, row.blocks, 1, { registeredWidgets: SEED_REGISTERED_WIDGETS });
|
|
1710
|
+
const sourceRevision = existing ? existing.sourceRevision + (existing.rawContent === row.content ? 0 : 1) : 1;
|
|
1711
|
+
let ordinal = 0;
|
|
1712
|
+
const retainedHistory = history.get(id) ?? [];
|
|
1713
|
+
const map = !existing ? retainedHistory.length ? reconcileNoteBlocks(row.content, { sourceRevision, registeredWidgets: SEED_REGISTERED_WIDGETS, createId: () => `seed:${id}:new${retainedHistory.length}:${ordinal++}` }) : structuredClone(row.blocks) : existing.rawContent === row.content ? structuredClone(existing.blocks) : refreshedBlocks(existing, row.content, sourceRevision);
|
|
1714
|
+
for (const block of Object.values(map)) {
|
|
1715
|
+
const saved = (history.get(id) ?? []).filter((r) => r.blockId === block.id).sort((a, b) => b.version - a.version)[0];
|
|
1716
|
+
const source = row.content.slice(block.from, block.to);
|
|
1717
|
+
if (existing?.rawContent === row.content) continue;
|
|
1718
|
+
const same = saved && saved.kind === block.kind && saved.rawContent === source && saved.dialect === block.dialect && saved.sport === block.sport;
|
|
1719
|
+
block.version = !existing ? 1 : same ? saved.version : (saved?.version ?? 0) + 1;
|
|
1720
|
+
if (!existing || !same) revisions.push({ noteId: id, blockId: block.id, version: block.version, kind: block.kind, rawContent: source, savedAt: write.meta.importedAt, ...block.dialect ? { dialect: block.dialect } : {}, ...block.sport ? { sport: block.sport } : {} });
|
|
1721
|
+
}
|
|
1722
|
+
validateNoteBlocks(row.content, map, sourceRevision, { registeredWidgets: SEED_REGISTERED_WIDGETS });
|
|
1723
|
+
const fm = readFrontmatterMeta(row.content);
|
|
1724
|
+
const title = typeof fm["title"] === "string" && fm["title"].trim() ? fm["title"].trim() : titleFromPath(row.path);
|
|
1725
|
+
const sourceId = write.chunkId ? seedNoteSourceId(row.path, row.content, write.chunkId) : void 0;
|
|
1726
|
+
if (!sourceId) throw new Error(`Unknown seed source family ${write.chunkId}`);
|
|
1727
|
+
const dateMatch = typeof fm["date"] === "string" ? fm["date"].match(/^(\d{4})-(\d{2})-(\d{2})$/) : null;
|
|
1728
|
+
let date;
|
|
1729
|
+
if (dateMatch) {
|
|
1730
|
+
const ts = Date.parse(`${fm["date"]}T12:00:00Z`);
|
|
1731
|
+
const real = Number.isFinite(ts) && new Date(ts).getUTCMonth() === Number(dateMatch[2]) - 1 && new Date(ts).getUTCDate() === Number(dateMatch[3]);
|
|
1732
|
+
if (!real) throw new Error(`invalid frontmatter date '${fm["date"]}' in '${row.path}' \u2014 expected a real calendar day (YYYY-MM-DD)`);
|
|
1733
|
+
date = ts;
|
|
1734
|
+
}
|
|
1735
|
+
const seedCommit = row.commit ?? write.manifest.commit;
|
|
1736
|
+
const note = { ...existing, id, title, rawContent: row.content, sourceRevision, blocks: map, createdAt: write.manifest.version, ...date === void 0 ? {} : { date }, type: write.chunkId === DASHBOARDS_CHUNK_ID ? "dashboard" : "note", sourceId, seedOrigin: "seed", seedVersion: write.manifest.version, seedChunkId: write.chunkId ?? void 0, feedOrigin: "feed", feedSourceId, sourcePath: row.path, ...seedCommit ? { seedCommit } : {} };
|
|
1737
|
+
if (date === void 0) delete note.date;
|
|
1738
|
+
if (!equal(note, existing)) changedNotes.push(note);
|
|
1739
|
+
const byRange = new Map(Object.values(map).map((b) => [`${b.from}:${b.to}`, b]));
|
|
1740
|
+
const compiledById = new Map(row.blockIndex.map((b) => [b.blockId, b]));
|
|
1741
|
+
const remap = /* @__PURE__ */ new Map();
|
|
1742
|
+
for (const compiled of row.blockIndex) {
|
|
1743
|
+
const block = byRange.get(`${compiled.from}:${compiled.to}`);
|
|
1744
|
+
if (!block || block.kind !== compiled.dataType) throw new Error("Orphan seed projection");
|
|
1745
|
+
remap.set(compiled.blockId, block.id);
|
|
1746
|
+
const projection = { ...compiled, id: `${id}:${block.id}`, noteId: id, blockId: block.id, blockVersion: block.version, sourceRevision, noteTitle: title, sourceId, sourcePath: row.path, rawContent: row.content.slice(block.from, block.to) };
|
|
1747
|
+
const prior = currentIndexes[slot.get(id)].find((b) => b.id === projection.id);
|
|
1748
|
+
if (!prior || prior.isStatic === true) blocks.push(projection);
|
|
1749
|
+
}
|
|
1750
|
+
const resolvedSessions = /* @__PURE__ */ new Map();
|
|
1751
|
+
const userRecordedSessions = /* @__PURE__ */ new Set();
|
|
1752
|
+
for (const compiled of row.telemetry?.sessions ?? []) {
|
|
1753
|
+
if (compiledById.get(compiled.blockId)?.dataType !== "wod") throw new Error("Orphan seed session pin");
|
|
1754
|
+
const prior = existingTelemetrySessions.get(compiled.id);
|
|
1755
|
+
if (prior && prior.noteId !== id) throw new Error(`Seed session ${compiled.id} belongs to another note`);
|
|
1756
|
+
if (prior?.origin) {
|
|
1757
|
+
userRecordedSessions.add(compiled.id);
|
|
1662
1758
|
continue;
|
|
1663
1759
|
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1695
|
-
if (!
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
}
|
|
1717
|
-
const blockId = prior?.blockId ?? remap.get(compiled.blockId);
|
|
1718
|
-
if (!blockId) throw new Error("Orphan seed session pin");
|
|
1719
|
-
const block = map[blockId];
|
|
1720
|
-
if (!prior && !block) throw new Error("Orphan seed session pin");
|
|
1721
|
-
const session = {
|
|
1722
|
-
...compiled,
|
|
1723
|
-
noteId: id,
|
|
1724
|
-
blockId,
|
|
1725
|
-
blockVersion: prior?.blockVersion ?? block.version,
|
|
1726
|
-
blockContentId: prior?.blockContentId ?? compiledById.get(compiled.blockId)?.blockContentId
|
|
1727
|
-
};
|
|
1728
|
-
sessions.push(session);
|
|
1729
|
-
resolvedSessions.set(session.id, session);
|
|
1760
|
+
const blockId = prior?.blockId ?? remap.get(compiled.blockId);
|
|
1761
|
+
if (!blockId) throw new Error("Orphan seed session pin");
|
|
1762
|
+
const block = map[blockId];
|
|
1763
|
+
if (!prior && !block) throw new Error("Orphan seed session pin");
|
|
1764
|
+
const session = {
|
|
1765
|
+
...compiled,
|
|
1766
|
+
noteId: id,
|
|
1767
|
+
blockId,
|
|
1768
|
+
blockVersion: prior?.blockVersion ?? block.version,
|
|
1769
|
+
blockContentId: prior?.blockContentId ?? compiledById.get(compiled.blockId)?.blockContentId
|
|
1770
|
+
};
|
|
1771
|
+
sessions.push(session);
|
|
1772
|
+
resolvedSessions.set(session.id, session);
|
|
1773
|
+
}
|
|
1774
|
+
for (const compiled of row.telemetry?.events ?? []) {
|
|
1775
|
+
if (userRecordedSessions.has(compiled.resultId)) continue;
|
|
1776
|
+
const session = resolvedSessions.get(compiled.resultId);
|
|
1777
|
+
if (!session) throw new Error("Orphan seed event result");
|
|
1778
|
+
events.push({
|
|
1779
|
+
...compiled,
|
|
1780
|
+
noteId: id,
|
|
1781
|
+
blockId: session.blockId,
|
|
1782
|
+
blockVersion: session.blockVersion,
|
|
1783
|
+
blockContentId: session.blockContentId
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
for (const compiled of row.blockEfforts) {
|
|
1787
|
+
const blockId = remap.get(compiled.blockId);
|
|
1788
|
+
if (!blockId || compiledById.get(compiled.blockId)?.dataType !== "wod") throw new Error("Orphan seed effort link");
|
|
1789
|
+
const link = { ...compiled, id: `${id}:${blockId}:${compiled.effortSlug}`, noteId: id, blockId, sourcePath: row.path };
|
|
1790
|
+
const prior = currentEfforts[slot.get(id)].find((b) => b.id === link.id);
|
|
1791
|
+
if (!prior || prior.isStatic === true) blockEfforts.push(prior ? { ...link, createdAt: prior.createdAt } : link);
|
|
1792
|
+
}
|
|
1793
|
+
for (const compiled of row.blockEquipment) {
|
|
1794
|
+
const blockId = remap.get(compiled.blockId);
|
|
1795
|
+
if (!blockId || compiledById.get(compiled.blockId)?.dataType !== "wod") throw new Error("Orphan seed equipment link");
|
|
1796
|
+
const link = { ...compiled, id: `${id}:${blockId}:${compiled.equipmentSlug}`, noteId: id, blockId, sourcePath: row.path };
|
|
1797
|
+
const prior = currentEquipment[slot.get(id)].find((b) => b.id === link.id);
|
|
1798
|
+
if (!prior || prior.isStatic === true) blockEquipment.push(prior ? { ...link, createdAt: prior.createdAt } : link);
|
|
1799
|
+
}
|
|
1800
|
+
const n = slot.get(id);
|
|
1801
|
+
const wantedTags = /* @__PURE__ */ new Set();
|
|
1802
|
+
for (const item of extractTypedTags(row.content)) {
|
|
1803
|
+
let tag = tagsByLabel.get(item.label);
|
|
1804
|
+
if (!tag) {
|
|
1805
|
+
tag = { id: tagIds.get(item.label), label: item.label, type: item.type, createdAt: write.meta.importedAt };
|
|
1806
|
+
changedTags.push(tag);
|
|
1807
|
+
tagsByLabel.set(item.label, tag);
|
|
1808
|
+
} else if (item.type && !tag.type) {
|
|
1809
|
+
tag = { ...tag, type: item.type };
|
|
1810
|
+
changedTags.push(tag);
|
|
1811
|
+
tagsByLabel.set(item.label, tag);
|
|
1730
1812
|
}
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1813
|
+
if (wantedTags.has(tag.id)) continue;
|
|
1814
|
+
wantedTags.add(tag.id);
|
|
1815
|
+
const link = currentTags[n].find((l) => l.tagId === tag.id);
|
|
1816
|
+
if (!link) noteTags.push({ id: `${id}:${tag.id}`, noteId: id, tagId: tag.id });
|
|
1817
|
+
}
|
|
1818
|
+
for (const link of currentTags[n]) if (!wantedTags.has(link.tagId)) await tagLinks.delete(link.id);
|
|
1819
|
+
const slug = fm["slug"];
|
|
1820
|
+
if (typeof slug === "string" && pagesBySlug.has(slug)) {
|
|
1821
|
+
const pageId = pagesBySlug.get(slug);
|
|
1822
|
+
pages.push({ id: pageId, slug, title: titleFromPath(row.path), createdAt: write.manifest.version });
|
|
1823
|
+
pageNotes.push({ id: linkIds.get(id), pageId, noteId: id, createdAt: write.manifest.version });
|
|
1824
|
+
}
|
|
1825
|
+
result.totalNotes++;
|
|
1826
|
+
result.totalBlocks += Object.keys(map).length;
|
|
1827
|
+
}
|
|
1828
|
+
const wantedBlocks = new Set(blocks.map((b) => b.id)), wantedEfforts = new Set(blockEfforts.map((b) => b.id)), wantedEquipment = new Set(blockEquipment.map((b) => b.id));
|
|
1829
|
+
for (const rows of currentIndexes) for (const row of rows) if (row.isStatic === true && !wantedBlocks.has(row.id)) await indexStore.delete(row.id);
|
|
1830
|
+
for (const rows of currentEfforts) for (const row of rows) if (row.isStatic === true && !wantedEfforts.has(row.id)) await effortLinks.delete(row.id);
|
|
1831
|
+
for (const rows of currentEquipment) for (const row of rows) if (row.isStatic === true && !wantedEquipment.has(row.id)) await equipmentLinks.delete(row.id);
|
|
1832
|
+
for (const id of goneIds) {
|
|
1833
|
+
if (!owned.has(id) || !existingById.get(id)) continue;
|
|
1834
|
+
const n = slot.get(id);
|
|
1835
|
+
await noteStore.delete(id);
|
|
1836
|
+
for (const link of currentTags[n]) await tagLinks.delete(link.id);
|
|
1837
|
+
for (const link of currentPages[n]) await pageLinks.delete(link.id);
|
|
1838
|
+
result.deleted++;
|
|
1839
|
+
}
|
|
1840
|
+
const recordSeedPropertyOverrides = async (kind, parse) => {
|
|
1841
|
+
let overrideStore;
|
|
1842
|
+
try {
|
|
1843
|
+
overrideStore = tx.readwrite("property_overrides");
|
|
1844
|
+
} catch {
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
const scopes = feedSourceId === "core" ? ["notebook/defaults"] : [
|
|
1848
|
+
`feed:${feedSourceId}`,
|
|
1849
|
+
...write.manifest.chunks.filter((c) => c.id.startsWith("notebook.")).map((c) => `notebook/${notebookSlugForChunkId(c.id)}`)
|
|
1850
|
+
];
|
|
1851
|
+
const wantedIds = /* @__PURE__ */ new Set();
|
|
1852
|
+
const toPut = [];
|
|
1853
|
+
for (const [idx, row] of write.rows.entries()) {
|
|
1854
|
+
const parsed = parse(row.content);
|
|
1855
|
+
if (!parsed) continue;
|
|
1856
|
+
for (const scope of scopes) {
|
|
1857
|
+
const ovId = makeScopedOverrideId(scope, kind, parsed.slug);
|
|
1858
|
+
wantedIds.add(ovId);
|
|
1859
|
+
toPut.push({
|
|
1860
|
+
id: ovId,
|
|
1861
|
+
notebookId: scope,
|
|
1862
|
+
kind,
|
|
1863
|
+
slug: parsed.slug,
|
|
1864
|
+
label: parsed.label,
|
|
1865
|
+
ownerNoteId: ids[idx],
|
|
1866
|
+
rawContent: row.content,
|
|
1867
|
+
payload: parsed,
|
|
1868
|
+
seedOrigin: "seed",
|
|
1869
|
+
feedSourceId,
|
|
1870
|
+
updatedAt: write.meta.importedAt
|
|
1741
1871
|
});
|
|
1742
1872
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1750
|
-
for (const compiled of row.blockEquipment) {
|
|
1751
|
-
const blockId = remap.get(compiled.blockId);
|
|
1752
|
-
if (!blockId || compiledById.get(compiled.blockId)?.dataType !== "wod") throw new Error("Orphan seed equipment link");
|
|
1753
|
-
const link = { ...compiled, id: `${id}:${blockId}:${compiled.equipmentSlug}`, noteId: id, blockId, sourcePath: row.path };
|
|
1754
|
-
const prior = currentEquipment[slot.get(id)].find((b) => b.id === link.id);
|
|
1755
|
-
if (!prior || prior.isStatic === true) blockEquipment.push(prior ? { ...link, createdAt: prior.createdAt } : link);
|
|
1756
|
-
}
|
|
1757
|
-
const n = slot.get(id);
|
|
1758
|
-
const wantedTags = /* @__PURE__ */ new Set();
|
|
1759
|
-
for (const item of extractTypedTags(row.content)) {
|
|
1760
|
-
let tag = tagsByLabel.get(item.label);
|
|
1761
|
-
if (!tag) {
|
|
1762
|
-
tag = { id: tagIds.get(item.label), label: item.label, type: item.type, createdAt: write.meta.importedAt };
|
|
1763
|
-
changedTags.push(tag);
|
|
1764
|
-
tagsByLabel.set(item.label, tag);
|
|
1765
|
-
} else if (item.type && !tag.type) {
|
|
1766
|
-
tag = { ...tag, type: item.type };
|
|
1767
|
-
changedTags.push(tag);
|
|
1768
|
-
tagsByLabel.set(item.label, tag);
|
|
1769
|
-
}
|
|
1770
|
-
if (wantedTags.has(tag.id)) continue;
|
|
1771
|
-
wantedTags.add(tag.id);
|
|
1772
|
-
const link = currentTags[n].find((l) => l.tagId === tag.id);
|
|
1773
|
-
if (!link) noteTags.push({ id: `${id}:${tag.id}`, noteId: id, tagId: tag.id });
|
|
1774
|
-
}
|
|
1775
|
-
for (const link of currentTags[n]) if (!wantedTags.has(link.tagId)) await tagLinks.delete(link.id);
|
|
1776
|
-
const slug = fm["slug"];
|
|
1777
|
-
if (typeof slug === "string" && pagesBySlug.has(slug)) {
|
|
1778
|
-
const pageId = pagesBySlug.get(slug);
|
|
1779
|
-
pages.push({ id: pageId, slug, title: titleFromPath(row.path), createdAt: write.manifest.version });
|
|
1780
|
-
pageNotes.push({ id: linkIds.get(id), pageId, noteId: id, createdAt: write.manifest.version });
|
|
1781
|
-
}
|
|
1782
|
-
result.totalNotes++;
|
|
1783
|
-
result.totalBlocks += Object.keys(map).length;
|
|
1784
|
-
}
|
|
1785
|
-
const wantedBlocks = new Set(blocks.map((b) => b.id)), wantedEfforts = new Set(blockEfforts.map((b) => b.id)), wantedEquipment = new Set(blockEquipment.map((b) => b.id));
|
|
1786
|
-
for (const rows of currentIndexes) for (const row of rows) if (row.isStatic === true && !wantedBlocks.has(row.id)) await indexStore.delete(row.id);
|
|
1787
|
-
for (const rows of currentEfforts) for (const row of rows) if (row.isStatic === true && !wantedEfforts.has(row.id)) await effortLinks.delete(row.id);
|
|
1788
|
-
for (const rows of currentEquipment) for (const row of rows) if (row.isStatic === true && !wantedEquipment.has(row.id)) await equipmentLinks.delete(row.id);
|
|
1789
|
-
for (const id of goneIds) {
|
|
1790
|
-
if (!owned.has(id) || !existingById.get(id)) continue;
|
|
1791
|
-
const n = slot.get(id);
|
|
1792
|
-
await noteStore.delete(id);
|
|
1793
|
-
for (const link of currentTags[n]) await tagLinks.delete(link.id);
|
|
1794
|
-
for (const link of currentPages[n]) await pageLinks.delete(link.id);
|
|
1795
|
-
result.deleted++;
|
|
1796
|
-
}
|
|
1797
|
-
const recordSeedPropertyOverrides = async (kind, parse) => {
|
|
1798
|
-
let overrideStore;
|
|
1799
|
-
try {
|
|
1800
|
-
overrideStore = tx.readwrite("property_overrides");
|
|
1801
|
-
} catch {
|
|
1802
|
-
return;
|
|
1803
|
-
}
|
|
1804
|
-
const scopes = feedSourceId === "core" ? ["notebook/defaults"] : [
|
|
1805
|
-
`feed:${feedSourceId}`,
|
|
1806
|
-
...write.manifest.chunks.filter((c) => c.id.startsWith("notebook.")).map((c) => `notebook/${notebookSlugForChunkId(c.id)}`)
|
|
1807
|
-
];
|
|
1808
|
-
const wantedIds = /* @__PURE__ */ new Set();
|
|
1809
|
-
const toPut = [];
|
|
1810
|
-
for (const [idx, row] of write.rows.entries()) {
|
|
1811
|
-
const parsed = parse(row.content);
|
|
1812
|
-
if (!parsed) continue;
|
|
1813
|
-
for (const scope of scopes) {
|
|
1814
|
-
const ovId = makeScopedOverrideId(scope, kind, parsed.slug);
|
|
1815
|
-
wantedIds.add(ovId);
|
|
1816
|
-
toPut.push({
|
|
1817
|
-
id: ovId,
|
|
1818
|
-
notebookId: scope,
|
|
1819
|
-
kind,
|
|
1820
|
-
slug: parsed.slug,
|
|
1821
|
-
label: parsed.label,
|
|
1822
|
-
ownerNoteId: ids[idx],
|
|
1823
|
-
rawContent: row.content,
|
|
1824
|
-
payload: parsed,
|
|
1825
|
-
seedOrigin: "seed",
|
|
1826
|
-
feedSourceId,
|
|
1827
|
-
updatedAt: write.meta.importedAt
|
|
1828
|
-
});
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
if (toPut.length > 0) await overrideStore.putMany(toPut);
|
|
1832
|
-
const existingAll = await overrideStore.getAll();
|
|
1833
|
-
for (const existingOv of existingAll) {
|
|
1834
|
-
if (existingOv.seedOrigin === "seed" && existingOv.feedSourceId === feedSourceId && existingOv.kind === kind && !wantedIds.has(existingOv.id)) {
|
|
1835
|
-
await overrideStore.delete(existingOv.id);
|
|
1836
|
-
}
|
|
1873
|
+
}
|
|
1874
|
+
if (toPut.length > 0) await overrideStore.putMany(toPut);
|
|
1875
|
+
const existingAll = await overrideStore.getAll();
|
|
1876
|
+
for (const existingOv of existingAll) {
|
|
1877
|
+
if (existingOv.seedOrigin === "seed" && existingOv.feedSourceId === feedSourceId && existingOv.kind === kind && !wantedIds.has(existingOv.id)) {
|
|
1878
|
+
await overrideStore.delete(existingOv.id);
|
|
1837
1879
|
}
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
if (write.chunkId === EFFORTS_CHUNK_ID) {
|
|
1883
|
+
result.totalEfforts = await applyDefinitionChunk(tx.readwrite("efforts"), noteStore, parseEffortFile, "efforts", seedSource, incomingRank, otherCheckpoints, priorIds, write.rows, ids, owned, existingById, allIds);
|
|
1884
|
+
await recordSeedPropertyOverrides("effort", parseEffortFile);
|
|
1885
|
+
}
|
|
1886
|
+
if (write.chunkId === EQUIPMENT_CHUNK_ID) {
|
|
1887
|
+
result.totalEquipment = await applyDefinitionChunk(tx.readwrite("equipment"), noteStore, parseEquipmentFile, "equipment", seedSource, incomingRank, otherCheckpoints, priorIds, write.rows, ids, owned, existingById, allIds);
|
|
1888
|
+
await recordSeedPropertyOverrides("equipment", parseEquipmentFile);
|
|
1889
|
+
}
|
|
1890
|
+
if (changedNotes.length) await noteStore.putMany(changedNotes);
|
|
1891
|
+
if (revisions.length) await revisionStore.putMany(revisions);
|
|
1892
|
+
await putChanged(indexStore, blocks, blocks.map((b) => b.id));
|
|
1893
|
+
await putChanged(effortLinks, blockEfforts, blockEfforts.map((b) => b.id));
|
|
1894
|
+
await putChanged(equipmentLinks, blockEquipment, blockEquipment.map((b) => b.id));
|
|
1895
|
+
await putChanged(sessionStore, sessions, sessions.map((session) => session.id));
|
|
1896
|
+
await putChanged(eventStore, events, events.map((event) => event.id));
|
|
1897
|
+
if (changedTags.length) await tagsStore.putMany([...new Map(changedTags.map((t) => [t.id, t])).values()]);
|
|
1898
|
+
if (noteTags.length) await tagLinks.putMany(noteTags);
|
|
1899
|
+
await putChanged(tx.readwrite("page"), pages, pages.map((p) => p.id));
|
|
1900
|
+
await putChanged(pageLinks, pageNotes, pageNotes.map((p) => p.id));
|
|
1901
|
+
await metaStore.put(write.meta);
|
|
1902
|
+
return result;
|
|
1861
1903
|
}
|
|
1862
1904
|
function owningFeed(claims, note) {
|
|
1863
1905
|
const byChunk = note.seedChunkId ? claims.filter((claim) => claim.chunkId === note.seedChunkId) : [];
|
|
@@ -4493,6 +4535,6 @@ function buildNoteProvenance(sourceNote, sourceNotebookId, clonedAt) {
|
|
|
4493
4535
|
};
|
|
4494
4536
|
}
|
|
4495
4537
|
|
|
4496
|
-
export { APP_ORIGIN, BUILD_TIME, CANVAS_CHUNK_ID, DASHBOARDS_CHUNK_ID, DirectoryHandleFeedTree, EFFORTS_CHUNK_ID, EQUIPMENT_CHUNK_ID, FeedTreeError, GIT_SHA, HttpFeedTree, MemoryFeedTree, NOTE_ID_FRONTMATTER_KEY, PUBLISHED_FEED_META_KEY, QR_SCRIPT_ID, SEED_BROADCAST_CHANNEL, SEED_NAMESPACE, SEED_REGISTERED_WIDGETS, SEED_SCHEMA, SEMVER, SESSION_CSV_HEADER, TELEMETRY_CSV_HEADER, VERSION, applySeedChunk, assertNotebookIndex, assertSeedManifest, assertSeedRow, assertSeedRows, backfillFeedProvenance, buildNoteProvenance, buildStatementTree, canvasRouteSlug, checkUnpublishedFeedChanges, cloneRemoteRecord, composeNoteMarkdown, createIRFile, createUserNotebookLanding, csvToEquipmentLabels, csvToSessionRows, csvToTelemetryBundle, decodeUtf8, effortToMarkdown, emptySeedMeta, encodeUtf8, equipmentToCsv, equipmentToMarkdown, exportPortableFilesFromStorage, extractNoteIdentity, extractTypedTags, feedIdOfMetaKey, getNoteNotebooks, getNotePublicationSummary, ingestPortableFilesIntoStorage, injectIdentityFrontmatter, isIRFile, listScopedPropertyOverrides, makeNotebookLinkId, makeScopedOverrideId, migrateNotebookVocabulary, normalizeFeedTreePath, notebookSlugForChunkId, parseCsvLine, parseFrontmatterDateMs, parseNoteMarkdown, prepareJournalSessionRun, previewRemoteNotebook, previewRemoteRecord, promoteNoteToNotebooks, promoteReferencedOverridesToNotebook, publishFeedFromStorage, qrInlineScript, readFrontmatterMeta, removeNoteFromNotebook, renderFeedLandingHtml, resolveScopedPropertyCatalog, resolveUpstreamProvenance, saveScopedPropertyOverride, seedMetaKey, seedNoteId, seedNoteSourceId, seedPrecedenceRank, seedSourceTier, sessionToCsv, setNoteNotebooks, setNotebookPublic, setSessionPublic, sha256HexAsync, splitCsvRecords, statementToNode, telemetryBundleToCsv };
|
|
4497
|
-
//# sourceMappingURL=chunk-
|
|
4498
|
-
//# sourceMappingURL=chunk-
|
|
4538
|
+
export { APP_ORIGIN, BUILD_TIME, CANVAS_CHUNK_ID, DASHBOARDS_CHUNK_ID, DirectoryHandleFeedTree, EFFORTS_CHUNK_ID, EQUIPMENT_CHUNK_ID, FeedTreeError, GIT_SHA, HttpFeedTree, MemoryFeedTree, NOTE_ID_FRONTMATTER_KEY, PUBLISHED_FEED_META_KEY, QR_SCRIPT_ID, SEED_BROADCAST_CHANNEL, SEED_NAMESPACE, SEED_REGISTERED_WIDGETS, SEED_SCHEMA, SEMVER, SESSION_CSV_HEADER, TELEMETRY_CSV_HEADER, VERSION, applySeedChunk, applySeedChunks, assertNotebookIndex, assertSeedManifest, assertSeedRow, assertSeedRows, backfillFeedProvenance, buildNoteProvenance, buildStatementTree, canvasRouteSlug, checkUnpublishedFeedChanges, cloneRemoteRecord, composeNoteMarkdown, createIRFile, createUserNotebookLanding, csvToEquipmentLabels, csvToSessionRows, csvToTelemetryBundle, decodeUtf8, effortToMarkdown, emptySeedMeta, encodeUtf8, equipmentToCsv, equipmentToMarkdown, exportPortableFilesFromStorage, extractNoteIdentity, extractTypedTags, feedIdOfMetaKey, getNoteNotebooks, getNotePublicationSummary, ingestPortableFilesIntoStorage, injectIdentityFrontmatter, isIRFile, listScopedPropertyOverrides, makeNotebookLinkId, makeScopedOverrideId, migrateNotebookVocabulary, normalizeFeedTreePath, notebookSlugForChunkId, parseCsvLine, parseFrontmatterDateMs, parseNoteMarkdown, prepareJournalSessionRun, previewRemoteNotebook, previewRemoteRecord, promoteNoteToNotebooks, promoteReferencedOverridesToNotebook, publishFeedFromStorage, qrInlineScript, readFrontmatterMeta, removeNoteFromNotebook, renderFeedLandingHtml, resolveScopedPropertyCatalog, resolveUpstreamProvenance, saveScopedPropertyOverride, seedMetaKey, seedNoteId, seedNoteSourceId, seedPrecedenceRank, seedSourceTier, sessionToCsv, setNoteNotebooks, setNotebookPublic, setSessionPublic, sha256HexAsync, splitCsvRecords, statementToNode, telemetryBundleToCsv };
|
|
4539
|
+
//# sourceMappingURL=chunk-ZMTTEJUB.mjs.map
|
|
4540
|
+
//# sourceMappingURL=chunk-ZMTTEJUB.mjs.map
|