@bitcobblers/wod-wiki-engine 0.6.32 → 0.7.37

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
@@ -65,13 +65,66 @@ function getRegisteredLanguagePacks() {
65
65
  }
66
66
 
67
67
  // src/store.ts
68
- function inMemoryFactStore(facts, noteTags = {}) {
68
+ function factRowsToEventRows(facts) {
69
+ return facts.map((f, i) => {
70
+ const metricKey = f.metricKey ?? f.type;
71
+ return {
72
+ id: `fact:${f.resultId}:${metricKey}:${i}`,
73
+ resultId: f.resultId,
74
+ noteId: f.noteId,
75
+ blockContentId: f.blockContentId,
76
+ pageId: f.pageId,
77
+ origin: f.origin,
78
+ timestamp: f.timestamp,
79
+ grain: f.grain === "event" ? "event" : "summary",
80
+ outputType: "analytics",
81
+ effortSlug: f.effortSlug,
82
+ metrics: [{
83
+ type: metricKey,
84
+ value: f.value,
85
+ ...f.unit ? { unit: f.unit } : {},
86
+ metadata: {
87
+ canonicalKey: metricKey,
88
+ ...f.effortSlug ? { effortSlug: f.effortSlug } : {},
89
+ ...f.discipline ? { effortDiscipline: f.discipline } : {},
90
+ ...f.intensityTier ? { effortIntensityTier: f.intensityTier } : {}
91
+ }
92
+ }],
93
+ segmentId: f.segmentId,
94
+ segmentVersion: f.segmentVersion
95
+ };
96
+ });
97
+ }
98
+ function inMemoryEventStore(events) {
99
+ const rows = [...events];
69
100
  return {
70
- getFactsByMetric: async (metricKey) => facts.filter((f) => f.metricKey === metricKey || f.type === metricKey),
71
- getFactsByTimeRange: async (start, end) => facts.filter((f) => f.timestamp >= start && f.timestamp <= end),
72
- getNoteTagLabels: async (noteId) => [...noteTags[noteId] ?? []]
101
+ getEventsByTimeRange: async (start, end) => rows.filter((r) => r.timestamp >= start && r.timestamp <= end),
102
+ getEventsByResult: async (resultId) => rows.filter((r) => r.resultId === resultId),
103
+ getEventsForNote: async (noteId) => rows.filter((r) => r.noteId === noteId),
104
+ getEventsByContent: async (blockContentId) => rows.filter((r) => r.blockContentId === blockContentId),
105
+ scanAll: async () => rows,
106
+ appendEvents: async (appended) => {
107
+ rows.push(...appended);
108
+ },
109
+ finalizeSummaries: async (resultId, finals) => {
110
+ for (let i = rows.length - 1; i >= 0; i--) {
111
+ const row = rows[i];
112
+ if (row.resultId === resultId && row.grain === "summary" && row.origin !== "user") rows.splice(i, 1);
113
+ }
114
+ rows.push(...finals);
115
+ },
116
+ deleteEvents: async (ids) => {
117
+ const doomed = new Set(ids);
118
+ for (let i = rows.length - 1; i >= 0; i--) {
119
+ if (doomed.has(rows[i].id)) rows.splice(i, 1);
120
+ }
121
+ }
73
122
  };
74
123
  }
124
+ function inMemoryEventStoreFromFacts(facts) {
125
+ return inMemoryEventStore(factRowsToEventRows(facts));
126
+ }
127
+ var inMemoryFactStore = inMemoryEventStoreFromFacts;
75
128
  function createIRFile(kind, data, optionsOrSource, generatedAt) {
76
129
  let source = "wod:headless";
77
130
  let genAt = Date.now();
@@ -258,7 +311,7 @@ function factsFromExecutionLog(log, resultId = "stdin-result-1") {
258
311
  segmentId: s.sourceBlockKey || "stdin-seg-1",
259
312
  segmentVersion: 1,
260
313
  resultId,
261
- grain: s.outputType === "analytics" ? "summary" : "segment",
314
+ grain: s.outputType === "analytics" ? "summary" : "event",
262
315
  type: mType,
263
316
  value: Number.isNaN(numVal) ? 0 : numVal,
264
317
  unit: m.unit,
@@ -284,11 +337,24 @@ function extractPayload(rawJson) {
284
337
  }
285
338
  }
286
339
  function buildStoresFromData(data) {
287
- const factStore = {
288
- getFactsByMetric: async (key) => data.facts.filter((f) => f.metricKey === key || f.type === key),
289
- getFactsByTimeRange: async (start, end) => data.facts.filter((f) => f.timestamp >= start && f.timestamp <= end),
290
- getNoteTagLabels: async (noteId) => [...data.noteTags[noteId] ?? []]
291
- };
340
+ const identity = (r) => ({
341
+ noteId: r.noteId,
342
+ resultId: r.id,
343
+ segmentId: r.segmentId,
344
+ segmentVersion: r.segmentVersion,
345
+ blockContentId: r.blockContentId,
346
+ origin: r.origin,
347
+ pageId: r.pageId,
348
+ workoutTimestamp: r.createdAt
349
+ });
350
+ const events = [
351
+ ...factRowsToEventRows(data.facts),
352
+ ...data.results.flatMap((r) => {
353
+ const logs = r.data.logs ?? [];
354
+ return [...wodWikiWql.toEventRows(logs, identity(r)), ...wodWikiWql.toSummaryEventRows(logs, identity(r))];
355
+ })
356
+ ];
357
+ const eventStore = inMemoryEventStore(events);
292
358
  const noteStore = {
293
359
  getAllNotes: async () => [...data.notes],
294
360
  getNoteIdsForTag: async (tag) => {
@@ -297,20 +363,16 @@ function buildStoresFromData(data) {
297
363
  if (tags.includes(tag)) matching.add(noteId);
298
364
  }
299
365
  return matching;
300
- }
366
+ },
367
+ getNoteTagLabels: async (noteId) => [...data.noteTags[noteId] ?? []]
301
368
  };
302
369
  const blockStore = {
303
370
  getAllBlocks: async () => [...data.blocks]
304
371
  };
305
- const resultStore = {
306
- getResultsByContentId: async (contentId) => data.results.filter((r) => r.blockContentId === contentId),
307
- getResultById: async (resultId) => data.results.find((r) => r.id === resultId),
308
- getResultsForNote: async (noteId) => data.results.filter((r) => r.noteId === noteId)
309
- };
310
372
  const effortStore = {
311
373
  getAllEfforts: async () => [...data.efforts]
312
374
  };
313
- return { factStore, noteStore, blockStore, resultStore, effortStore };
375
+ return { eventStore, noteStore, blockStore, effortStore };
314
376
  }
315
377
  function loadQueryData(options) {
316
378
  const data = {
@@ -396,13 +458,11 @@ async function runQueryCli(wqlString, options = {}) {
396
458
  if (parsed.error) {
397
459
  throw new WqlSyntaxError(wqlString, parsed.error);
398
460
  }
399
- const data = loadQueryData(options);
400
- const stores = buildStoresFromData(data);
461
+ const stores = buildStoresFromData(loadQueryData(options));
401
462
  const service = new wodWikiWql.QueryService(
402
- stores.factStore,
463
+ stores.eventStore,
403
464
  stores.noteStore,
404
465
  stores.blockStore,
405
- stores.resultStore,
406
466
  stores.effortStore
407
467
  );
408
468
  if (wodWikiWql.isFindQuery(parsed)) {
@@ -598,20 +658,17 @@ function formatQueryOutput(ir, format, pretty = true) {
598
658
  if (kind === "rows-result") {
599
659
  const data2 = ir.data;
600
660
  if (format === "csv") {
601
- const header = "resultId,started,ended,duration,completed,outputType,statementId,metrics";
661
+ const header = "resultId,timestamp,outputType,eventId,metrics";
602
662
  const rows = [];
603
663
  for (const run of data2.runs) {
604
- for (const log of run.logs) {
664
+ for (const event of run.events) {
605
665
  rows.push(
606
666
  [
607
- run.result.id,
608
- run.result.createdAt,
609
- run.result.createdAt + (run.result.data.duration ?? 0),
610
- run.result.data.duration ?? 0,
611
- run.result.data.completed ? "true" : "false",
612
- log.outputType ?? "segment",
613
- log.id ?? 0,
614
- escapeCsvField(log.metrics.map(formatMetric).join("; "))
667
+ run.resultId,
668
+ run.timestamp,
669
+ event.outputType,
670
+ event.id,
671
+ escapeCsvField(event.metrics.map(formatMetric).join("; "))
615
672
  ].join(",")
616
673
  );
617
674
  }
@@ -623,16 +680,15 @@ function formatQueryOutput(ir, format, pretty = true) {
623
680
  if (data2.error) lines2.push(`Error: ${data2.error}`);
624
681
  lines2.push("\u2500".repeat(80));
625
682
  lines2.push(
626
- ["Result ID".padEnd(20), "Date".padEnd(24), "Duration".padEnd(12), "Logs"].join(" | ")
683
+ ["Result ID".padEnd(20), "Date".padEnd(24), "Events"].join(" | ")
627
684
  );
628
685
  lines2.push("\u2500".repeat(80));
629
686
  for (const run of data2.runs) {
630
687
  lines2.push(
631
688
  [
632
- run.result.id.padEnd(20),
633
- formatDate(run.result.createdAt).padEnd(24),
634
- `${run.result.data.duration ?? 0}ms`.padEnd(12),
635
- String(run.logs.length)
689
+ run.resultId.padEnd(20),
690
+ formatDate(run.timestamp).padEnd(24),
691
+ String(run.events.length)
636
692
  ].join(" | ")
637
693
  );
638
694
  }
@@ -984,13 +1040,13 @@ async function cliMain(argv = process.argv.slice(2), io = {}) {
984
1040
  }
985
1041
 
986
1042
  // src/version.ts
987
- var VERSION2 = "0.6.32";
988
- var GIT_SHA = "bc13c0f";
989
- var BUILD_TIME = "2026-08-21T20:12:50.453Z";
1043
+ var VERSION2 = "0.7.37";
1044
+ var GIT_SHA = "713c593";
1045
+ var BUILD_TIME = "2026-08-25T00:18:25.714Z";
990
1046
  var SEMVER = {
991
- version: "0.6.32",
992
- gitSha: "bc13c0f",
993
- buildTime: "2026-08-21T20:12:50.453Z"
1047
+ version: "0.7.37",
1048
+ gitSha: "713c593",
1049
+ buildTime: "2026-08-25T00:18:25.714Z"
994
1050
  };
995
1051
 
996
1052
  Object.defineProperty(exports, "ABSENT", {
@@ -1837,10 +1893,13 @@ exports.buildWorkoutResults = buildWorkoutResults;
1837
1893
  exports.cliMain = cliMain;
1838
1894
  exports.createIRFile = createIRFile;
1839
1895
  exports.defineLanguagePack = defineLanguagePack;
1896
+ exports.factRowsToEventRows = factRowsToEventRows;
1840
1897
  exports.formatExecutionOutput = formatExecutionOutput;
1841
1898
  exports.formatParseOutput = formatParseOutput;
1842
1899
  exports.formatQueryOutput = formatQueryOutput;
1843
1900
  exports.getRegisteredLanguagePacks = getRegisteredLanguagePacks;
1901
+ exports.inMemoryEventStore = inMemoryEventStore;
1902
+ exports.inMemoryEventStoreFromFacts = inMemoryEventStoreFromFacts;
1844
1903
  exports.inMemoryFactStore = inMemoryFactStore;
1845
1904
  exports.isIRFile = isIRFile;
1846
1905
  exports.listLanguagePacks = listLanguagePacks;