@bitcobblers/wod-wiki-engine 0.63.2270 → 0.63.2272

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 CHANGED
@@ -1988,12 +1988,33 @@ function buildQueryServiceStoresFromStorage(storage, options = {}) {
1988
1988
  const rawEventStore = {
1989
1989
  getEventsByTimeRange: async (start, end) => storage.readonly("events").getAllFromIndex("by-timestamp", asRange(start, end)),
1990
1990
  getEventsByMetricDates: async (dates) => {
1991
+ if (dates.length === 0) return [];
1991
1992
  const store = storage.readonly("events");
1992
1993
  const byId = /* @__PURE__ */ new Map();
1993
- for (const date of dates) {
1994
- for (const row of await store.getAllFromIndex("by-metric-date", date)) {
1994
+ if (dates.length === 1) {
1995
+ for (const row of await store.getAllFromIndex("by-metric-date", dates[0])) {
1995
1996
  byId.set(row.id, row);
1996
1997
  }
1998
+ return Array.from(byId.values());
1999
+ }
2000
+ let minDate = dates[0];
2001
+ let maxDate = dates[0];
2002
+ const wanted = /* @__PURE__ */ new Set();
2003
+ for (const date of dates) {
2004
+ wanted.add(date);
2005
+ if (date < minDate) minDate = date;
2006
+ if (date > maxDate) maxDate = date;
2007
+ }
2008
+ const rows = await store.getAllFromIndex(
2009
+ "by-metric-date",
2010
+ asRange(minDate, maxDate)
2011
+ );
2012
+ for (const row of rows) {
2013
+ if (byId.has(row.id)) continue;
2014
+ if (Array.isArray(row.metricDateKeys) && row.metricDateKeys.length > 0) {
2015
+ if (!row.metricDateKeys.some((k) => wanted.has(k))) continue;
2016
+ }
2017
+ byId.set(row.id, row);
1997
2018
  }
1998
2019
  return Array.from(byId.values());
1999
2020
  },
@@ -2148,6 +2169,40 @@ function buildQueryServiceStoresFromStorage(storage, options = {}) {
2148
2169
  const bundles = /* @__PURE__ */ new Map();
2149
2170
  const uniqueIds = [...new Set(noteIds)];
2150
2171
  if (uniqueIds.length === 0) return bundles;
2172
+ if (storage.queryDomain) {
2173
+ const CHUNK_SIZE = 100;
2174
+ let usedDomain = true;
2175
+ let matchedRows = 0;
2176
+ for (let offset = 0; offset < uniqueIds.length; offset += CHUNK_SIZE) {
2177
+ const chunk = uniqueIds.slice(offset, offset + CHUNK_SIZE);
2178
+ const result = await storage.queryDomain({
2179
+ plan: "detail",
2180
+ selection: [{ field: "id", values: chunk }]
2181
+ });
2182
+ if (!result || result.plan !== "detail") {
2183
+ usedDomain = false;
2184
+ bundles.clear();
2185
+ break;
2186
+ }
2187
+ matchedRows += result.rows.length;
2188
+ for (const row of result.rows) {
2189
+ bundles.set(row.note.id, {
2190
+ tags: row.tags.map((t) => ({ label: t.label, ...t.type ? { type: t.type } : {} })),
2191
+ links: [...row.links],
2192
+ pages: [...row.pages]
2193
+ });
2194
+ }
2195
+ }
2196
+ if (usedDomain && matchedRows > 0) {
2197
+ for (const id of uniqueIds) {
2198
+ if (!bundles.has(id)) {
2199
+ bundles.set(id, { tags: [], links: [], pages: [] });
2200
+ }
2201
+ }
2202
+ return bundles;
2203
+ }
2204
+ bundles.clear();
2205
+ }
2151
2206
  return storage.transaction(["page_notes", "note_tags", "tags", "page"], "readonly", async (tx) => {
2152
2207
  const [pageLinkGroups, tagLinkGroups] = await Promise.all([
2153
2208
  tx.readonly("page_notes").getAllFromIndexMany("by-note", uniqueIds),
@@ -4366,7 +4421,7 @@ async function ingestPortableFilesIntoStorage(storage, files, options = {}) {
4366
4421
  }
4367
4422
 
4368
4423
  // src/version.ts
4369
- var VERSION = "0.63.2270";
4424
+ var VERSION = "0.63.2272";
4370
4425
 
4371
4426
  // src/feed/qr.ts
4372
4427
  var APP_ORIGIN = "https://wod.wiki";
@@ -6198,20 +6253,27 @@ async function deleteUserNotebook(storage, notebookIdOrSlug) {
6198
6253
  );
6199
6254
  let touchedMembers = 0;
6200
6255
  const noteWriter = tx.readwrite("notes");
6256
+ const legacyColonTag = `notebook:${slug}`;
6257
+ const legacySlashTag = `notebook/${slug}`;
6201
6258
  for (const note of allNotes) {
6202
6259
  if (wodWikiCore.isNotebookLanding(note)) continue;
6203
6260
  const hasSingle = note.notebookId === nbId;
6204
6261
  const hasMulti = (note.notebookIds ?? []).includes(nbId);
6205
6262
  const hasLink = linkedNoteIds.has(note.id);
6206
- if (!hasSingle && !hasMulti && !hasLink) continue;
6263
+ const hasLegacyTag = (note.tags ?? []).some(
6264
+ (t) => t === legacyColonTag || t === legacySlashTag
6265
+ );
6266
+ if (!hasSingle && !hasMulti && !hasLink && !hasLegacyTag) continue;
6207
6267
  const baseIds = note.notebookIds !== void 0 ? note.notebookIds : note.notebookId ? [note.notebookId] : [];
6208
6268
  const remaining = baseIds.map((id) => wodWikiCore.toNotebookId(id)).filter((id) => id !== nbId);
6209
6269
  const primaryUser = remaining.find(
6210
6270
  (id) => id !== "notebook/journal" && id !== "notebook/playground"
6211
6271
  );
6272
+ const nextTags = hasLegacyTag ? (note.tags ?? []).filter((t) => t !== legacyColonTag && t !== legacySlashTag) : note.tags;
6212
6273
  const { notebookId: _droppedSingle, notebookIds: _droppedMulti, ...rest } = note;
6213
6274
  await noteWriter.put({
6214
6275
  ...rest,
6276
+ ...nextTags !== void 0 ? { tags: nextTags } : {},
6215
6277
  notebookIds: remaining,
6216
6278
  ...primaryUser ? { notebookId: primaryUser } : {}
6217
6279
  });