@bitcobblers/wod-wiki-core 0.51.2196 → 0.53.2203

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
@@ -1064,7 +1064,17 @@ function isWorkoutSectionType(type) {
1064
1064
  }
1065
1065
 
1066
1066
  // src/types/notebook.ts
1067
- var DEFAULT_NOTEBOOK_SLUGS = ["journal", "playground", "defaults", "guides"];
1067
+ var DEFAULT_NOTEBOOK_SLUGS = ["journal", "playground", "defaults", "custom", "guides"];
1068
+ var READONLY_SYSTEM_NOTEBOOK_SLUGS = ["defaults", "guides", "efforts", "equipment", "dashboards"];
1069
+ var NON_PUBLISHABLE_NOTEBOOK_SLUGS = ["journal", "playground", "defaults", "custom", "guides", "efforts", "equipment", "dashboards"];
1070
+ var READONLY_SET = new Set(READONLY_SYSTEM_NOTEBOOK_SLUGS);
1071
+ var NON_PUBLISHABLE_SET = new Set(NON_PUBLISHABLE_NOTEBOOK_SLUGS);
1072
+ function isSystemReadOnlyNotebook(slugOrId) {
1073
+ return READONLY_SET.has(notebookSlugFromId(slugOrId));
1074
+ }
1075
+ function isNonPublishableNotebook(slugOrId) {
1076
+ return NON_PUBLISHABLE_SET.has(notebookSlugFromId(slugOrId));
1077
+ }
1068
1078
  function notebookSlugFromId(slugOrId) {
1069
1079
  const trimmed = slugOrId.trim();
1070
1080
  if (trimmed.startsWith("notebook/")) return trimmed.slice("notebook/".length);
@@ -1074,7 +1084,9 @@ function notebookSlugFromId(slugOrId) {
1074
1084
  function toNotebookId(slugOrId) {
1075
1085
  return `notebook/${notebookSlugFromId(slugOrId)}`;
1076
1086
  }
1077
- function isNoteEditable(note, notebookOrigin) {
1087
+ function isNoteEditable(note, notebookOrigin, resolvedNotebookId) {
1088
+ const targetNb = resolvedNotebookId ?? note.notebookId ?? void 0;
1089
+ if (targetNb && isSystemReadOnlyNotebook(targetNb)) return false;
1078
1090
  if (notebookOrigin) return notebookOrigin !== "feed";
1079
1091
  return note.seedOrigin !== "seed" && note.feedOrigin !== "feed";
1080
1092
  }
@@ -1083,33 +1095,51 @@ var BUILTIN_NOTEBOOKS = [
1083
1095
  slug: "journal",
1084
1096
  notebookId: "notebook/journal",
1085
1097
  name: "Journal",
1086
- description: "Dated training log and scheduled workouts.",
1087
- icon: "\u{1F4C5}",
1088
- href: "/journal"
1098
+ description: "Private training log tracking all created notes and sessions across journal and playground.",
1099
+ icon: "J",
1100
+ href: "/journal",
1101
+ readOnly: false,
1102
+ publishable: false
1089
1103
  },
1090
1104
  {
1091
1105
  slug: "playground",
1092
1106
  notebookId: "notebook/playground",
1093
1107
  name: "Playground",
1094
1108
  description: "Scratchpad workouts and timer experiments.",
1095
- icon: "\u{1F9EA}",
1096
- href: "/playgrounds"
1109
+ icon: "P",
1110
+ href: "/playgrounds",
1111
+ readOnly: false,
1112
+ publishable: false
1097
1113
  },
1098
1114
  {
1099
1115
  slug: "defaults",
1100
1116
  notebookId: "notebook/defaults",
1101
1117
  name: "Defaults",
1102
- description: "Starter notes \u2014 clone any of them into your own notebooks.",
1103
- icon: "\u{1F4DD}",
1104
- href: "/notebook/defaults"
1118
+ description: "Read-only base primitives: Tags, Efforts, Equipment, and shared dynamic properties.",
1119
+ icon: "D",
1120
+ href: "/notebook/defaults",
1121
+ readOnly: true,
1122
+ publishable: false
1123
+ },
1124
+ {
1125
+ slug: "custom",
1126
+ notebookId: "notebook/custom",
1127
+ name: "Custom",
1128
+ description: "User overrides and custom Tags, Efforts, Equipment, and starter workouts.",
1129
+ icon: "C",
1130
+ href: "/notebook/custom",
1131
+ readOnly: false,
1132
+ publishable: false
1105
1133
  },
1106
1134
  {
1107
1135
  slug: "guides",
1108
1136
  notebookId: "notebook/guides",
1109
1137
  name: "Guides",
1110
- description: "Built-in Whiteboard Language and WQL guides.",
1111
- icon: "\u{1F4D6}",
1138
+ description: "Pre-subscribed read-only Whiteboard Language and WQL guides.",
1139
+ icon: "G",
1112
1140
  href: "/notebook/guides",
1141
+ readOnly: true,
1142
+ publishable: false,
1113
1143
  feedEntryId: "core",
1114
1144
  seedChunkId: "canvas"
1115
1145
  },
@@ -1604,7 +1634,7 @@ function parseMetaLines(lines) {
1604
1634
  }
1605
1635
  if (items.length > 0) {
1606
1636
  meta[key] = items;
1607
- } else if (key === "metrics" || key === "summaries" || key === "widgets") {
1637
+ } else if (key === "metrics" || key === "summaries" || key === "widgets" || key === "baseAttributes") {
1608
1638
  while (i + 1 < lines.length) {
1609
1639
  const childLine = lines[i + 1];
1610
1640
  if (/^\s*(?:#.*)?$/.test(childLine)) {
@@ -1614,7 +1644,8 @@ function parseMetaLines(lines) {
1614
1644
  const childMatch = childLine.match(/^\s{2,}([A-Za-z][\w.-]*)\s*:(.*)$/);
1615
1645
  if (!childMatch) break;
1616
1646
  i++;
1617
- const childKey = `${key}.${childMatch[1]}`;
1647
+ const childName = childMatch[1];
1648
+ const childKey = key === "baseAttributes" ? childName === "met" || childName === "disciplineFactor" ? `metrics.${childName}` : childName : `${key}.${childName}`;
1618
1649
  const childRaw = childMatch[2].trim();
1619
1650
  if (childRaw === "") {
1620
1651
  const childItems = [];
@@ -1739,15 +1770,169 @@ function parseFrontmatterProps(lines) {
1739
1770
  }
1740
1771
 
1741
1772
  // src/version.ts
1742
- var VERSION = "0.51.2196";
1743
- var GIT_SHA = "817bc28";
1744
- var BUILD_TIME = "2026-11-05T23:36:56.914Z";
1773
+ var VERSION = "0.53.2203";
1774
+ var GIT_SHA = "522974d";
1775
+ var BUILD_TIME = "2026-11-11T22:34:03.328Z";
1745
1776
  var SEMVER = {
1746
- version: "0.51.2196",
1747
- gitSha: "817bc28",
1748
- buildTime: "2026-11-05T23:36:56.914Z"
1777
+ version: "0.53.2203",
1778
+ gitSha: "522974d",
1779
+ buildTime: "2026-11-11T22:34:03.328Z"
1749
1780
  };
1750
1781
 
1782
+ // src/portability/note-jsonl.ts
1783
+ function isObject(value) {
1784
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1785
+ }
1786
+ function isString(value) {
1787
+ return typeof value === "string" && value.length > 0;
1788
+ }
1789
+ function isFiniteNumber(value) {
1790
+ return typeof value === "number" && Number.isFinite(value);
1791
+ }
1792
+ function isPositiveInteger(value) {
1793
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
1794
+ }
1795
+ function hasValidOrigin(value) {
1796
+ return value === void 0 || value === "journal" || value === "playground" || value === "user";
1797
+ }
1798
+ function validNote(value) {
1799
+ return isString(value.id) && typeof value.title === "string" && isFiniteNumber(value.createdAt) && isFiniteNumber(value.updatedAt) && isFiniteNumber(value.targetDate) && typeof value.rawContent === "string" && (value.sourceRevision === void 0 || isPositiveInteger(value.sourceRevision)) && (value.blocks === void 0 || isObject(value.blocks)) && (value.tags === void 0 || Array.isArray(value.tags) && value.tags.every((tag) => typeof tag === "string")) && (value.type === void 0 || typeof value.type === "string") && (value.sourceId === void 0 || typeof value.sourceId === "string");
1800
+ }
1801
+ function validSession(value) {
1802
+ return isString(value.id) && isString(value.noteId) && isString(value.blockId) && isPositiveInteger(value.blockVersion) && isString(value.blockContentId) && hasValidOrigin(value.origin) && (value.status === void 0 || value.status === "in-progress" || value.status === "completed") && (value.public === void 0 || typeof value.public === "boolean") && isFiniteNumber(value.startTime) && isFiniteNumber(value.endTime) && isFiniteNumber(value.duration) && typeof value.completed === "boolean" && isFiniteNumber(value.createdAt);
1803
+ }
1804
+ function validParseRecord(value) {
1805
+ return isString(value.id) && isString(value.noteId) && (value.blockId === void 0 || isString(value.blockId)) && (value.blockVersion === void 0 || isPositiveInteger(value.blockVersion)) && (value.stage === "parse" || value.stage === "load") && (value.status === "ok" || value.status === "warning" || value.status === "error") && isFiniteNumber(value.timestamp) && (value.diagnostics === void 0 || Array.isArray(value.diagnostics) && value.diagnostics.every((d) => typeof d === "string")) && (value.metrics === void 0 || isObject(value.metrics));
1806
+ }
1807
+ function validEvent(value) {
1808
+ return isString(value.id) && isString(value.resultId) && isString(value.noteId) && isString(value.blockId) && isPositiveInteger(value.blockVersion) && isString(value.blockContentId) && hasValidOrigin(value.origin) && isFiniteNumber(value.timestamp) && (value.grain === "event" || value.grain === "summary") && typeof value.outputType === "string" && Array.isArray(value.metrics) && value.metrics.every((metric) => isObject(metric) && typeof metric.type === "string") && (value.grain !== "summary" || value.metrics.length === 1) && (value.representationKind === void 0 || value.representationKind === "direct" || value.representationKind === "calculated" || value.representationKind === "substitute_summary");
1809
+ }
1810
+ function validRevision(value) {
1811
+ return isString(value.noteId) && isString(value.blockId) && isPositiveInteger(value.version) && ["wod", "query", "widget", "embed"].includes(String(value.blockKind)) && typeof value.rawContent === "string" && isFiniteNumber(value.savedAt) && (value.dialect === void 0 || value.dialect === "time" || value.dialect === "log") && (value.sport === void 0 || typeof value.sport === "string");
1812
+ }
1813
+ function revisionToJsonl(revision) {
1814
+ const { kind: blockKind, ...identity } = revision;
1815
+ return { kind: "revision", blockKind, ...identity };
1816
+ }
1817
+ function serializeNoteBundleToJsonl(bundle) {
1818
+ const records = [
1819
+ ...bundle.note ? [{ kind: "note", ...bundle.note }] : [],
1820
+ ...(bundle.revisions ?? []).map(revisionToJsonl),
1821
+ ...(bundle.parses ?? []).map((parse) => ({ kind: "parse", ...parse })),
1822
+ ...bundle.sessions.map((session) => ({ kind: "session", ...session })),
1823
+ ...bundle.events.map((event) => ({ kind: "event", ...event }))
1824
+ ];
1825
+ return records.map((record) => JSON.stringify(record)).join("\n");
1826
+ }
1827
+ async function* streamNoteBundleToJsonlLines(bundles) {
1828
+ for await (const bundle of bundles) {
1829
+ if (bundle.note) yield JSON.stringify({ kind: "note", ...bundle.note });
1830
+ for (const revision of bundle.revisions ?? []) yield JSON.stringify(revisionToJsonl(revision));
1831
+ for (const parse of bundle.parses ?? []) yield JSON.stringify({ kind: "parse", ...parse });
1832
+ for (const session of bundle.sessions) yield JSON.stringify({ kind: "session", ...session });
1833
+ for (const event of bundle.events) yield JSON.stringify({ kind: "event", ...event });
1834
+ }
1835
+ }
1836
+ function parseNoteBundleFromJsonl(jsonlText) {
1837
+ const bundles = /* @__PURE__ */ new Map();
1838
+ const errors = [];
1839
+ const lines = jsonlText.split(/\r?\n/);
1840
+ const bundleFor = (noteId) => {
1841
+ const existing = bundles.get(noteId);
1842
+ if (existing) return existing;
1843
+ const created = { sessions: [], events: [] };
1844
+ bundles.set(noteId, created);
1845
+ return created;
1846
+ };
1847
+ for (const [index, line] of lines.entries()) {
1848
+ if (!line.trim()) continue;
1849
+ const lineNumber = index + 1;
1850
+ try {
1851
+ const parsed = JSON.parse(line);
1852
+ if (!isObject(parsed) || typeof parsed.kind !== "string") {
1853
+ errors.push(`Line ${lineNumber}: missing record kind`);
1854
+ continue;
1855
+ }
1856
+ const { kind, ...value } = parsed;
1857
+ if (kind === "note") {
1858
+ if (!validNote(value)) {
1859
+ errors.push(`Line ${lineNumber}: invalid note record`);
1860
+ continue;
1861
+ }
1862
+ const note = value;
1863
+ const bundle = bundleFor(note.id);
1864
+ if (bundle.note) {
1865
+ errors.push(`Line ${lineNumber}: duplicate note ${note.id}`);
1866
+ continue;
1867
+ }
1868
+ bundle.note = note;
1869
+ } else if (kind === "revision") {
1870
+ if (!validRevision(value)) {
1871
+ errors.push(`Line ${lineNumber}: invalid revision record`);
1872
+ continue;
1873
+ }
1874
+ const { blockKind, ...identity } = value;
1875
+ const revision = { ...identity, kind: blockKind };
1876
+ (bundleFor(revision.noteId).revisions ??= []).push(revision);
1877
+ } else if (kind === "session") {
1878
+ if (!validSession(value)) {
1879
+ errors.push(`Line ${lineNumber}: invalid session record`);
1880
+ continue;
1881
+ }
1882
+ const session = value;
1883
+ bundleFor(session.noteId).sessions.push(session);
1884
+ } else if (kind === "event") {
1885
+ if (!validEvent(value)) {
1886
+ errors.push(`Line ${lineNumber}: invalid event record`);
1887
+ continue;
1888
+ }
1889
+ const event = value;
1890
+ bundleFor(event.noteId).events.push(event);
1891
+ } else if (kind === "parse") {
1892
+ if (!validParseRecord(value)) {
1893
+ errors.push(`Line ${lineNumber}: invalid parse/load record`);
1894
+ continue;
1895
+ }
1896
+ const parseRec = value;
1897
+ (bundleFor(parseRec.noteId).parses ??= []).push(parseRec);
1898
+ } else {
1899
+ errors.push(`Line ${lineNumber}: unknown record kind ${kind}`);
1900
+ }
1901
+ } catch (error) {
1902
+ errors.push(`Line ${lineNumber}: ${error instanceof Error ? error.message : String(error)}`);
1903
+ }
1904
+ }
1905
+ for (const bundle of bundles.values()) {
1906
+ const sessionIds = new Set(bundle.sessions.map((session) => session.id));
1907
+ for (const event of bundle.events) {
1908
+ if (!sessionIds.has(event.resultId)) {
1909
+ errors.push(`Event ${event.id}: no session ${event.resultId} for note ${event.noteId}`);
1910
+ }
1911
+ }
1912
+ }
1913
+ return { bundles: [...bundles.values()], errors };
1914
+ }
1915
+
1916
+ // src/publication.ts
1917
+ function isPublishableNotebookLanding(note) {
1918
+ return note.id.startsWith("notebook/") && note.notebookId === note.id && !isNonPublishableNotebook(note.id) && note.feedOrigin !== "feed" && note.seedOrigin !== "seed";
1919
+ }
1920
+ function derivePublicationVisibility(input) {
1921
+ const notebookPublic = input.notebookPublic === true;
1922
+ const publicSessions = Math.max(0, Math.trunc(input.publicSessions));
1923
+ const totalSessions = Math.max(publicSessions, Math.trunc(input.totalSessions));
1924
+ const visibility = !notebookPublic ? "Private" : publicSessions > 0 ? "Published Note + Data" : "Published Note";
1925
+ return {
1926
+ visibility,
1927
+ notebookPublic,
1928
+ publicSessions,
1929
+ totalSessions,
1930
+ ...input.notebookId ? { notebookId: input.notebookId } : {},
1931
+ ...input.notebookIds ? { notebookIds: input.notebookIds } : {},
1932
+ ...input.publicNotebookIds ? { publicNotebookIds: input.publicNotebookIds } : {}
1933
+ };
1934
+ }
1935
+
1751
1936
  exports.BUILD_TIME = BUILD_TIME;
1752
1937
  exports.BUILTIN_NOTEBOOKS = BUILTIN_NOTEBOOKS;
1753
1938
  exports.BlockKey = BlockKey;
@@ -1762,10 +1947,12 @@ exports.METRIC_OWNERSHIP_LAYER_CHAIN = METRIC_OWNERSHIP_LAYER_CHAIN;
1762
1947
  exports.Metric = Metric;
1763
1948
  exports.MetricContainer = MetricContainer;
1764
1949
  exports.MetricType = MetricType;
1950
+ exports.NON_PUBLISHABLE_NOTEBOOK_SLUGS = NON_PUBLISHABLE_NOTEBOOK_SLUGS;
1765
1951
  exports.NOTEBOOK_TAG_PREFIX = NOTEBOOK_TAG_PREFIX;
1766
1952
  exports.OutputStatement = OutputStatement;
1767
1953
  exports.OwnershipResolver = OwnershipResolver;
1768
1954
  exports.ParsedCodeStatement = ParsedCodeStatement;
1955
+ exports.READONLY_SYSTEM_NOTEBOOK_SLUGS = READONLY_SYSTEM_NOTEBOOK_SLUGS;
1769
1956
  exports.REFERENCE_METADATA_KEY = REFERENCE_METADATA_KEY;
1770
1957
  exports.SEMVER = SEMVER;
1771
1958
  exports.SYSTEM_DEFAULT_OUTPUT_UNIT = SYSTEM_DEFAULT_OUTPUT_UNIT;
@@ -1782,6 +1969,7 @@ exports.comparePlacements = comparePlacements;
1782
1969
  exports.convertViaCatalog = convertViaCatalog;
1783
1970
  exports.createMetricOwnershipLedger = createMetricOwnershipLedger;
1784
1971
  exports.createTagIndex = createTagIndex;
1972
+ exports.derivePublicationVisibility = derivePublicationVisibility;
1785
1973
  exports.detectScriptBlocks = detectScriptBlocks;
1786
1974
  exports.dimensionKeyOf = dimensionKeyOf;
1787
1975
  exports.extractBlockContent = extractBlockContent;
@@ -1797,8 +1985,11 @@ exports.getMetricOwnershipLayer = getMetricOwnershipLayer;
1797
1985
  exports.getReferenceMetadata = getReferenceMetadata;
1798
1986
  exports.getScalar = getScalar;
1799
1987
  exports.getTagReference = getTagReference;
1988
+ exports.isNonPublishableNotebook = isNonPublishableNotebook;
1800
1989
  exports.isNoteEditable = isNoteEditable;
1801
1990
  exports.isNotebookTag = isNotebookTag;
1991
+ exports.isPublishableNotebookLanding = isPublishableNotebookLanding;
1992
+ exports.isSystemReadOnlyNotebook = isSystemReadOnlyNotebook;
1802
1993
  exports.isWorkoutSectionType = isWorkoutSectionType;
1803
1994
  exports.lookupUnit = lookupUnit;
1804
1995
  exports.mapNoteBlockChanges = mapNoteBlockChanges;
@@ -1814,6 +2005,7 @@ exports.parseFrontmatter = parseFrontmatter;
1814
2005
  exports.parseFrontmatterBody = parseFrontmatterBody;
1815
2006
  exports.parseFrontmatterCategories = parseFrontmatterCategories;
1816
2007
  exports.parseFrontmatterProps = parseFrontmatterProps;
2008
+ exports.parseNoteBundleFromJsonl = parseNoteBundleFromJsonl;
1817
2009
  exports.patchFrontmatterProperty = patchFrontmatterProperty;
1818
2010
  exports.projectPlacements = projectPlacements;
1819
2011
  exports.reconcileNoteBlocks = reconcileNoteBlocks;
@@ -1821,6 +2013,8 @@ exports.resolveLayer = resolveLayer;
1821
2013
  exports.resolvePlacements = resolvePlacements;
1822
2014
  exports.runAffordance = runAffordance;
1823
2015
  exports.serializeFrontmatter = serializeFrontmatter;
2016
+ exports.serializeNoteBundleToJsonl = serializeNoteBundleToJsonl;
2017
+ exports.streamNoteBundleToJsonlLines = streamNoteBundleToJsonlLines;
1824
2018
  exports.stripFrontmatter = stripFrontmatter;
1825
2019
  exports.systemDefaultUnit = systemDefaultUnit;
1826
2020
  exports.toNotebookId = toNotebookId;