@bitcobblers/wod-wiki-engine 0.59.2236 → 0.59.2238

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/index.cjs CHANGED
@@ -940,13 +940,13 @@ function csvToTelemetryBundle(csv) {
940
940
  }
941
941
 
942
942
  // src/version.ts
943
- var VERSION = "0.59.2236";
944
- var GIT_SHA = "7b4743b";
945
- var BUILD_TIME = "2026-11-16T04:52:27.639Z";
943
+ var VERSION = "0.59.2238";
944
+ var GIT_SHA = "9029981";
945
+ var BUILD_TIME = "2026-11-16T16:02:29.109Z";
946
946
  var SEMVER = {
947
- version: "0.59.2236",
948
- gitSha: "7b4743b",
949
- buildTime: "2026-11-16T04:52:27.639Z"
947
+ version: "0.59.2238",
948
+ gitSha: "9029981",
949
+ buildTime: "2026-11-16T16:02:29.109Z"
950
950
  };
951
951
  var SEED_SCHEMA = 9;
952
952
  var SEED_REGISTERED_WIDGETS = wodWikiCore.KNOWN_SECTION_WIDGETS;
@@ -1837,7 +1837,7 @@ async function applyPreparedSeedChunkInTx(tx, prepared) {
1837
1837
  if (compiledById.get(compiled.blockId)?.dataType !== "wod") throw new Error("Orphan seed session pin");
1838
1838
  const prior = existingTelemetrySessions.get(compiled.id);
1839
1839
  if (prior && prior.noteId !== id) throw new Error(`Seed session ${compiled.id} belongs to another note`);
1840
- if (prior?.origin) {
1840
+ if (prior && (prior.origin || !prior.id.startsWith("seed:"))) {
1841
1841
  userRecordedSessions.add(compiled.id);
1842
1842
  continue;
1843
1843
  }
@@ -3189,10 +3189,26 @@ async function collectPublicStorageState(storage, options = {}) {
3189
3189
  storedCheckpoint
3190
3190
  };
3191
3191
  }
3192
+ async function recordPublishedFeedCheckpoint(storage, report) {
3193
+ const chunkShas = {};
3194
+ for (const c of report.manifest.chunks) chunkShas[c.id] = c.sha256;
3195
+ const cp = {
3196
+ key: PUBLISHED_FEED_META_KEY,
3197
+ version: report.manifest.version,
3198
+ builtAt: report.manifest.builtAt,
3199
+ manifestSha256: report.manifestSha256,
3200
+ chunkShas
3201
+ };
3202
+ await storage.transaction(["meta"], "readwrite", async (tx) => {
3203
+ await tx.readwrite("meta").put(cp);
3204
+ });
3205
+ }
3192
3206
  async function publishFeedFromStorage(storage, tree, options = {}) {
3207
+ options.signal?.throwIfAborted();
3193
3208
  const t0 = Date.now();
3194
3209
  const layout = options.layout ?? "feed";
3195
3210
  const state = await collectPublicStorageState(storage, options);
3211
+ options.signal?.throwIfAborted();
3196
3212
  if (state.notebooks.size === 0) {
3197
3213
  throw new Error("No public notebooks found to publish. Mark at least one user-owned notebook as Public first.");
3198
3214
  }
@@ -3480,28 +3496,19 @@ ${group.description ?? ""}
3480
3496
  const manifestBytes = encodeUtf8(JSON.stringify(manifest, null, 2) + "\n");
3481
3497
  const manifestSha256 = await sha256HexAsync(manifestBytes);
3482
3498
  await tree.write(`${artifactPrefix}manifest.json`, manifestBytes);
3483
- const shouldCheckpoint = options.recordCheckpoint ?? (layout === "feed" && !options.notebookSlug);
3484
- if (shouldCheckpoint) {
3485
- const chunkShas = {};
3486
- for (const c of manifestChunks) chunkShas[c.id] = c.sha256;
3487
- const cp = {
3488
- key: PUBLISHED_FEED_META_KEY,
3489
- version: nextVersion,
3490
- builtAt,
3491
- manifestSha256,
3492
- chunkShas
3493
- };
3494
- await storage.transaction(["meta"], "readwrite", async (tx) => {
3495
- await tx.readwrite("meta").put(cp);
3496
- });
3497
- }
3498
- return {
3499
+ const report = {
3499
3500
  manifest,
3500
3501
  notebooks: sortedSlugs,
3501
3502
  totalNotes,
3502
3503
  totalPublicSessions,
3503
3504
  manifestSha256
3504
3505
  };
3506
+ const shouldCheckpoint = options.recordCheckpoint ?? (layout === "feed" && !options.notebookSlug);
3507
+ if (shouldCheckpoint) {
3508
+ options.signal?.throwIfAborted();
3509
+ await recordPublishedFeedCheckpoint(storage, report);
3510
+ }
3511
+ return report;
3505
3512
  }
3506
3513
  async function checkUnpublishedFeedChanges(storage, currentTree, options = {}) {
3507
3514
  const state = await collectPublicStorageState(storage, options);
@@ -4322,6 +4329,208 @@ async function ingestPortableFilesIntoStorage(storage, files, options = {}) {
4322
4329
  errors
4323
4330
  };
4324
4331
  }
4332
+ var FEED_SUBSCRIPTIONS_META_KEY = "feed:subscriptions";
4333
+ async function removeSeedSourceContent(storage, meta) {
4334
+ return await storage.transaction(
4335
+ [
4336
+ "notes",
4337
+ "attachments",
4338
+ "tags",
4339
+ "note_tags",
4340
+ "block_index",
4341
+ "block_efforts",
4342
+ "block_equipment",
4343
+ "page_notes",
4344
+ "efforts",
4345
+ "equipment",
4346
+ "property_overrides",
4347
+ "meta"
4348
+ ],
4349
+ "readwrite",
4350
+ async (tx) => {
4351
+ const targetIds = /* @__PURE__ */ new Set();
4352
+ const legacyChunks = [];
4353
+ for (const [chunkId, chunk] of Object.entries(meta.chunks)) {
4354
+ if (chunk.noteIds?.length) {
4355
+ for (const id of chunk.noteIds) targetIds.add(id);
4356
+ } else {
4357
+ legacyChunks.push(chunkId);
4358
+ }
4359
+ }
4360
+ if (legacyChunks.length) {
4361
+ for (const note of await tx.readwrite("notes").getAll()) {
4362
+ if (note.seedOrigin === "seed" && note.seedChunkId && legacyChunks.includes(note.seedChunkId)) {
4363
+ targetIds.add(note.id);
4364
+ }
4365
+ }
4366
+ }
4367
+ const metaStore = tx.readwrite("meta");
4368
+ const otherCheckpoints = [];
4369
+ for (const row of await metaStore.getAll()) {
4370
+ const other = row;
4371
+ if (!other || typeof other.key !== "string" || !other.key.startsWith("seed:") || other.key === meta.key) {
4372
+ continue;
4373
+ }
4374
+ const noteIds = /* @__PURE__ */ new Set();
4375
+ for (const chunk of Object.values(other.chunks ?? {})) {
4376
+ for (const id of chunk.noteIds ?? []) noteIds.add(id);
4377
+ }
4378
+ otherCheckpoints.push({
4379
+ key: other.key,
4380
+ sourceId: other.key.slice(5),
4381
+ rank: seedPrecedenceRank(other.key, other.tier),
4382
+ meta: other,
4383
+ noteIds
4384
+ });
4385
+ }
4386
+ otherCheckpoints.sort((a, b) => b.rank - a.rank);
4387
+ const isClaimedByOther = (noteId) => otherCheckpoints.some((cp) => cp.noteIds.has(noteId));
4388
+ const removedSourceId = meta.key.startsWith("seed:") ? meta.key.slice(5) : meta.key;
4389
+ const notes = tx.readwrite("notes");
4390
+ const noteTags = tx.readwrite("note_tags");
4391
+ let deleted = 0;
4392
+ const removedPaths = /* @__PURE__ */ new Set();
4393
+ const touchedTagIds = /* @__PURE__ */ new Set();
4394
+ for (const id of targetIds) {
4395
+ if (isClaimedByOther(id)) continue;
4396
+ const note = await notes.get(id);
4397
+ if (!note || note.seedOrigin !== "seed") continue;
4398
+ if (note.seedChunkId && !meta.chunks[note.seedChunkId]) continue;
4399
+ if (note.sourcePath) removedPaths.add(note.sourcePath);
4400
+ await notes.delete(id);
4401
+ const attachments = tx.readwrite("attachments");
4402
+ for (const attachment of await attachments.getAllFromIndex("by-note", id)) {
4403
+ await attachments.delete(attachment.id);
4404
+ }
4405
+ for (const link of await noteTags.getAllFromIndex("by-note", id)) {
4406
+ touchedTagIds.add(link.tagId);
4407
+ await noteTags.delete(link.id);
4408
+ }
4409
+ const blockIndex = tx.readwrite("block_index");
4410
+ for (const row of await blockIndex.getAllFromIndex("by-note", id)) await blockIndex.delete(row.id);
4411
+ const blockEfforts = tx.readwrite("block_efforts");
4412
+ for (const row of await blockEfforts.getAllFromIndex("by-note", id)) await blockEfforts.delete(row.id);
4413
+ const blockEquipment = tx.readwrite("block_equipment");
4414
+ for (const row of await blockEquipment.getAllFromIndex("by-note", id)) await blockEquipment.delete(row.id);
4415
+ const pageNotes = tx.readwrite("page_notes");
4416
+ for (const link of await pageNotes.getAllFromIndex("by-note", id)) await pageNotes.delete(link.id);
4417
+ deleted++;
4418
+ }
4419
+ if (touchedTagIds.size > 0) {
4420
+ const tagsStore = tx.readwrite("tags");
4421
+ for (const tagId of touchedTagIds) {
4422
+ const remainingLinks = await noteTags.countFromIndex("by-tag", tagId);
4423
+ if (remainingLinks > 0) continue;
4424
+ const tag = await tagsStore.get(tagId);
4425
+ if (!tag) continue;
4426
+ if (tag.contributions && tag.contributions.length > 0) continue;
4427
+ const refNote = await notes.get(`t/${tag.type ?? "tag"}/${tag.label}`);
4428
+ if (refNote) continue;
4429
+ await tagsStore.delete(tagId);
4430
+ }
4431
+ }
4432
+ const defFamilies = [
4433
+ { storeName: "efforts", familyPathPrefix: "markdown/efforts/", parse: wodWikiLang.parseEffortFile },
4434
+ { storeName: "equipment", familyPathPrefix: "markdown/equipment/", parse: wodWikiLang.parseEquipmentFile }
4435
+ ];
4436
+ for (const { storeName, familyPathPrefix, parse } of defFamilies) {
4437
+ const store = tx.readwrite(storeName);
4438
+ for (const row of await store.getAll()) {
4439
+ if (row.registrySource !== "bundled") continue;
4440
+ const owned = row.sourceId === removedSourceId || row.ownerNoteId !== void 0 && targetIds.has(row.ownerNoteId) && (!row.sourceId || row.sourceId === storeName) || row.sourcePath !== void 0 && row.sourcePath.startsWith(familyPathPrefix) && removedPaths.has(row.sourcePath);
4441
+ if (!owned) continue;
4442
+ let restored = false;
4443
+ for (const cp of otherCheckpoints) {
4444
+ const candidateIds = cp.meta.chunks?.[storeName]?.noteIds ?? [];
4445
+ for (const candidateId of candidateIds) {
4446
+ const candidateNote = await notes.get(candidateId);
4447
+ if (!candidateNote || candidateNote.seedOrigin !== "seed") continue;
4448
+ const parsed = parse(candidateNote.rawContent);
4449
+ if (parsed && parsed.slug === row.slug) {
4450
+ await store.put({
4451
+ ...parsed,
4452
+ registrySource: "bundled",
4453
+ ownerNoteId: candidateNote.id,
4454
+ sourceId: cp.sourceId,
4455
+ feedSourceId: cp.sourceId,
4456
+ sourcePath: candidateNote.sourcePath ?? ""
4457
+ });
4458
+ restored = true;
4459
+ break;
4460
+ }
4461
+ }
4462
+ if (restored) break;
4463
+ }
4464
+ if (!restored) await store.delete(row.slug);
4465
+ }
4466
+ }
4467
+ try {
4468
+ const overrideStore = tx.readwrite("property_overrides");
4469
+ for (const ov of await overrideStore.getAll()) {
4470
+ if (ov.seedOrigin === "seed" && ov.feedSourceId === removedSourceId) {
4471
+ await overrideStore.delete(ov.id);
4472
+ }
4473
+ }
4474
+ } catch {
4475
+ }
4476
+ await metaStore.delete(meta.key);
4477
+ return deleted;
4478
+ }
4479
+ );
4480
+ }
4481
+ async function readFeedSubscriptionsMap(storage) {
4482
+ const row = await storage.readonly("meta").get(FEED_SUBSCRIPTIONS_META_KEY);
4483
+ return { ...row?.entries ?? {} };
4484
+ }
4485
+ async function writeFeedSubscriptionEntry(storage, sourceId, entry) {
4486
+ await storage.transaction(["meta"], "readwrite", async (tx) => {
4487
+ const metaStore = tx.readwrite("meta");
4488
+ const existing = await metaStore.get(FEED_SUBSCRIPTIONS_META_KEY);
4489
+ const entries = { ...existing?.entries ?? {}, [sourceId]: entry };
4490
+ await metaStore.put({ key: FEED_SUBSCRIPTIONS_META_KEY, entries });
4491
+ });
4492
+ }
4493
+ async function listFeedSubscriptionsHeadless(storage) {
4494
+ return readFeedSubscriptionsMap(storage);
4495
+ }
4496
+ async function subscribeFeedSourceHeadless(storage, sourceId, options) {
4497
+ const notebookIds = options?.notebookIds && options.notebookIds.length > 0 ? options.notebookIds : null;
4498
+ await writeFeedSubscriptionEntry(storage, sourceId, {
4499
+ subscribed: true,
4500
+ notebookIds,
4501
+ hidden: false,
4502
+ ...options?.url ? { url: options.url } : {},
4503
+ ...options?.name ? { name: options.name } : {},
4504
+ updatedAt: Date.now()
4505
+ });
4506
+ return { sourceId, subscribed: true, notebookIds };
4507
+ }
4508
+ async function unsubscribeFeedSourceHeadless(storage, sourceId) {
4509
+ if (sourceId === "core") {
4510
+ throw new Error("Core feed cannot be unsubscribed.");
4511
+ }
4512
+ const meta = await storage.readonly("meta").get(seedMetaKey(sourceId));
4513
+ const deletedNotes = meta ? await removeSeedSourceContent(storage, meta) : 0;
4514
+ await writeFeedSubscriptionEntry(storage, sourceId, {
4515
+ subscribed: false,
4516
+ hidden: false,
4517
+ updatedAt: Date.now()
4518
+ });
4519
+ return { sourceId, unsubscribed: true, deletedNotes };
4520
+ }
4521
+ async function deleteFeedSourceHeadless(storage, sourceId) {
4522
+ if (sourceId === "core") {
4523
+ throw new Error("Core feed cannot be deleted.");
4524
+ }
4525
+ const meta = await storage.readonly("meta").get(seedMetaKey(sourceId));
4526
+ const deletedNotes = meta ? await removeSeedSourceContent(storage, meta) : 0;
4527
+ await writeFeedSubscriptionEntry(storage, sourceId, {
4528
+ subscribed: false,
4529
+ hidden: true,
4530
+ updatedAt: Date.now()
4531
+ });
4532
+ return { sourceId, deleted: true, deletedNotes };
4533
+ }
4325
4534
  function mintUuid() {
4326
4535
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
4327
4536
  return crypto.randomUUID();
@@ -5720,6 +5929,7 @@ exports.DASHBOARDS_CHUNK_ID = DASHBOARDS_CHUNK_ID;
5720
5929
  exports.DirectoryHandleFeedTree = DirectoryHandleFeedTree;
5721
5930
  exports.EFFORTS_CHUNK_ID = EFFORTS_CHUNK_ID;
5722
5931
  exports.EQUIPMENT_CHUNK_ID = EQUIPMENT_CHUNK_ID;
5932
+ exports.FEED_SUBSCRIPTIONS_META_KEY = FEED_SUBSCRIPTIONS_META_KEY;
5723
5933
  exports.FeedTreeError = FeedTreeError;
5724
5934
  exports.GIT_SHA = GIT_SHA;
5725
5935
  exports.HttpFeedTree = HttpFeedTree;
@@ -5755,6 +5965,7 @@ exports.csvToSessionRows = csvToSessionRows;
5755
5965
  exports.csvToTelemetryBundle = csvToTelemetryBundle;
5756
5966
  exports.decodeUtf8 = decodeUtf8;
5757
5967
  exports.defineLanguagePack = defineLanguagePack;
5968
+ exports.deleteFeedSourceHeadless = deleteFeedSourceHeadless;
5758
5969
  exports.effortToMarkdown = effortToMarkdown;
5759
5970
  exports.emptySeedMeta = emptySeedMeta;
5760
5971
  exports.encodeUtf8 = encodeUtf8;
@@ -5771,6 +5982,7 @@ exports.inMemoryEventStore = inMemoryEventStore;
5771
5982
  exports.ingestPortableFilesIntoStorage = ingestPortableFilesIntoStorage;
5772
5983
  exports.injectIdentityFrontmatter = injectIdentityFrontmatter;
5773
5984
  exports.isIRFile = isIRFile;
5985
+ exports.listFeedSubscriptionsHeadless = listFeedSubscriptionsHeadless;
5774
5986
  exports.listLanguagePacks = listLanguagePacks;
5775
5987
  exports.listScopedPropertyOverrides = listScopedPropertyOverrides;
5776
5988
  exports.makeNotebookLinkId = makeNotebookLinkId;
@@ -5789,8 +6001,10 @@ exports.promoteReferencedOverridesToNotebook = promoteReferencedOverridesToNoteb
5789
6001
  exports.publishFeedFromStorage = publishFeedFromStorage;
5790
6002
  exports.qrInlineScript = qrInlineScript;
5791
6003
  exports.readFrontmatterMeta = readFrontmatterMeta;
6004
+ exports.recordPublishedFeedCheckpoint = recordPublishedFeedCheckpoint;
5792
6005
  exports.registerLanguagePack = registerLanguagePack;
5793
6006
  exports.removeNoteFromNotebook = removeNoteFromNotebook;
6007
+ exports.removeSeedSourceContent = removeSeedSourceContent;
5794
6008
  exports.renderFeedLandingHtml = renderFeedLandingHtml;
5795
6009
  exports.resolveScopedPropertyCatalog = resolveScopedPropertyCatalog;
5796
6010
  exports.resolveUpstreamProvenance = resolveUpstreamProvenance;
@@ -5807,8 +6021,10 @@ exports.setSessionPublic = setSessionPublic;
5807
6021
  exports.sha256HexAsync = sha256HexAsync;
5808
6022
  exports.splitCsvRecords = splitCsvRecords;
5809
6023
  exports.statementToNode = statementToNode;
6024
+ exports.subscribeFeedSourceHeadless = subscribeFeedSourceHeadless;
5810
6025
  exports.telemetryBundleToCsv = telemetryBundleToCsv;
5811
6026
  exports.unregisterLanguagePack = unregisterLanguagePack;
6027
+ exports.unsubscribeFeedSourceHeadless = unsubscribeFeedSourceHeadless;
5812
6028
  Object.keys(wodWikiCore).forEach(function (k) {
5813
6029
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5814
6030
  enumerable: true,