@bitcobblers/wod-wiki-engine 0.53.2203 → 0.54.2205

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.
@@ -0,0 +1,360 @@
1
+ import { NoteBlock, BlockIndexRow, BlockEffort, BlockEquipment, Session, EventRecord, Note, PublicationVisibilitySummary, ResultOrigin, BlockRevision, NoteProvenance, AnalyticsDataPoint, StoredOutputStatement, WorkoutResults, ICodeStatement } from '@bitcobblers/wod-wiki-core';
2
+ import { IStorage } from '@bitcobblers/wod-wiki-storage';
3
+ import { IEffort, IScript } from '@bitcobblers/wod-wiki-lang';
4
+
5
+ /**
6
+ * FeedTree — universal path-addressed byte tree port and runtime-agnostic adapters.
7
+ *
8
+ * Unifies:
9
+ * - MemoryFeedTree: in-memory tests, server snapshot staging, dirty diffs
10
+ * - HttpFeedTree: read-only fetch over GitHub Pages, custom peer URLs, and `wod server /feed/`
11
+ * - DirectoryHandleFeedTree: browser File System Access folder export/import
12
+ */
13
+ type FeedPath = string;
14
+ type FeedTreeErrorCode = 'not-found' | 'unsupported' | 'read-only' | 'checksum' | 'layout' | 'permission';
15
+ declare class FeedTreeError extends Error {
16
+ readonly code: FeedTreeErrorCode;
17
+ constructor(code: FeedTreeErrorCode, message: string);
18
+ }
19
+ interface FeedFileStat {
20
+ bytes: number;
21
+ sha256?: string;
22
+ }
23
+ interface FeedTreeReader {
24
+ read(path: FeedPath): Promise<Uint8Array>;
25
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
26
+ list?(prefix?: string): Promise<FeedPath[]>;
27
+ }
28
+ interface FeedTreeWriter {
29
+ write(path: FeedPath, bytes: Uint8Array): Promise<void>;
30
+ delete(path: FeedPath): Promise<void>;
31
+ }
32
+ interface FeedTree extends FeedTreeReader, FeedTreeWriter {
33
+ }
34
+ declare function encodeUtf8(text: string): Uint8Array;
35
+ declare function decodeUtf8(bytes: Uint8Array): string;
36
+ declare function normalizeFeedTreePath(rawPath: string): FeedPath;
37
+ declare function sha256HexAsync(input: Uint8Array | string): Promise<string>;
38
+ declare class MemoryFeedTree implements FeedTree {
39
+ private readonly store;
40
+ constructor(initial?: Readonly<Record<string, string | Uint8Array>>);
41
+ read(path: FeedPath): Promise<Uint8Array>;
42
+ readText(path: FeedPath): Promise<string>;
43
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
44
+ write(path: FeedPath, bytes: Uint8Array): Promise<void>;
45
+ writeText(path: FeedPath, text: string): Promise<void>;
46
+ delete(path: FeedPath): Promise<void>;
47
+ list(prefix?: string): Promise<FeedPath[]>;
48
+ entries(): Array<[FeedPath, Uint8Array]>;
49
+ }
50
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
51
+ declare class HttpFeedTree implements FeedTreeReader {
52
+ private readonly baseUrl;
53
+ private readonly fetchImpl;
54
+ constructor(baseUrl: string, fetchImpl?: FetchLike);
55
+ read(path: FeedPath): Promise<Uint8Array>;
56
+ readJson<T = unknown>(path: FeedPath): Promise<T>;
57
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
58
+ }
59
+ /** Structural subset of the Web File System Access API so non-DOM builds need no ambient DOM types. */
60
+ interface FileSystemWritableLike {
61
+ write(data: Uint8Array): Promise<void>;
62
+ close(): Promise<void>;
63
+ }
64
+ interface FileSystemFileHandleLike {
65
+ readonly kind: 'file';
66
+ readonly name: string;
67
+ getFile(): Promise<{
68
+ arrayBuffer(): Promise<ArrayBuffer>;
69
+ size: number;
70
+ }>;
71
+ createWritable(): Promise<FileSystemWritableLike>;
72
+ }
73
+ interface FileSystemDirectoryHandleLike {
74
+ readonly kind: 'directory';
75
+ readonly name: string;
76
+ getDirectoryHandle(name: string, options?: {
77
+ create?: boolean;
78
+ }): Promise<FileSystemDirectoryHandleLike>;
79
+ getFileHandle(name: string, options?: {
80
+ create?: boolean;
81
+ }): Promise<FileSystemFileHandleLike>;
82
+ removeEntry(name: string, options?: {
83
+ recursive?: boolean;
84
+ }): Promise<void>;
85
+ }
86
+ declare class DirectoryHandleFeedTree implements FeedTree {
87
+ private readonly root;
88
+ constructor(root: FileSystemDirectoryHandleLike);
89
+ private resolveDir;
90
+ read(path: FeedPath): Promise<Uint8Array>;
91
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
92
+ write(path: FeedPath, bytes: Uint8Array): Promise<void>;
93
+ delete(path: FeedPath): Promise<void>;
94
+ }
95
+
96
+ declare const SEED_SCHEMA = 9;
97
+ declare const SEED_REGISTERED_WIDGETS: readonly string[];
98
+ declare const SEED_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";
99
+ /** Source and all current derived rows commit as one chunk. */
100
+ interface SeedRow {
101
+ path: string;
102
+ content: string;
103
+ blocks: Record<string, NoteBlock>;
104
+ blockIndex: BlockIndexRow[];
105
+ blockEfforts: BlockEffort[];
106
+ blockEquipment: BlockEquipment[];
107
+ telemetry?: {
108
+ sessions: Session[];
109
+ events: EventRecord[];
110
+ };
111
+ commit?: string;
112
+ uuid?: string;
113
+ version?: number;
114
+ }
115
+ interface SeedRecordRef {
116
+ uuid: string;
117
+ path: string;
118
+ recordPath: string;
119
+ commit: string;
120
+ version: number;
121
+ sha256: string;
122
+ title?: string;
123
+ date?: number;
124
+ }
125
+ interface NotebookIndexSummary {
126
+ notebookId: string;
127
+ label: string;
128
+ category?: string;
129
+ description?: string;
130
+ indexPath: string;
131
+ version: number;
132
+ commit: string;
133
+ updatedAt?: string;
134
+ builtAt: string;
135
+ sha256: string;
136
+ bytes: number;
137
+ count: number;
138
+ }
139
+ interface NotebookIndex extends NotebookIndexSummary {
140
+ records: SeedRecordRef[];
141
+ }
142
+ type ChunkKind = 'notes';
143
+ interface ManifestChunk {
144
+ id: string;
145
+ path: string;
146
+ sha256: string;
147
+ bytes: number;
148
+ count: number;
149
+ kind?: ChunkKind;
150
+ records?: SeedRecordRef[];
151
+ }
152
+ interface SeedManifest {
153
+ name?: string;
154
+ description?: string;
155
+ repositoryUrl?: string;
156
+ schema: number;
157
+ version: number;
158
+ versionLabel?: string;
159
+ commit?: string;
160
+ dirty?: boolean;
161
+ builtAt: string;
162
+ chunks: ManifestChunk[];
163
+ notebooks?: NotebookIndexSummary[];
164
+ }
165
+ type SeedPrecedenceTier = 'core' | 'community' | 'imported' | 'user';
166
+ declare function seedSourceTier(sourceIdOrMetaKey?: string | null, explicitTier?: SeedPrecedenceTier): SeedPrecedenceTier;
167
+ declare function seedPrecedenceRank(sourceIdOrMetaKey?: string | null, explicitTier?: SeedPrecedenceTier): number;
168
+ interface SeedMetaRecord {
169
+ key: string;
170
+ schema: number;
171
+ seedVersion: number;
172
+ builtAt: string;
173
+ importedAt: number;
174
+ chunks: Record<string, {
175
+ sha256: string;
176
+ version?: number;
177
+ builtAt?: string;
178
+ importedAt?: number;
179
+ noteIds?: string[];
180
+ }>;
181
+ claim?: {
182
+ owner: string;
183
+ at: number;
184
+ } | null;
185
+ tier?: SeedPrecedenceTier;
186
+ }
187
+ declare const SEED_BROADCAST_CHANNEL = "wodwiki.seed";
188
+ declare const EFFORTS_CHUNK_ID = "efforts";
189
+ declare const EQUIPMENT_CHUNK_ID = "equipment";
190
+ declare const CANVAS_CHUNK_ID = "canvas";
191
+ declare const DASHBOARDS_CHUNK_ID = "dashboards";
192
+ declare function seedMetaKey(sourceId: string): string;
193
+ /**
194
+ * The feed identifier a checkpoint key names — the key's source id. The
195
+ * checkpoint key keeps its seed spelling (`seed:<id>`, a persisted wire
196
+ * format) and the broadcast channel keeps its own, so a feed's checkpoint
197
+ * IS the checkpoint its id writes.
198
+ */
199
+ declare function feedIdOfMetaKey(metaKey: string): string;
200
+ declare function emptySeedMeta(key: string): SeedMetaRecord;
201
+ /** The notebook slug a notebook chunk id names — `notebook.<slug>`; the
202
+ * `_root` landing (a file directly under `markdown/notebooks/`) names no
203
+ * notebook. */
204
+ declare function notebookSlugForChunkId(chunkId: string): string | undefined;
205
+ declare function canvasRouteSlug(content: string): string | null;
206
+ declare function seedNoteSourceId(path: string, content: string, chunkId: string): string | undefined;
207
+
208
+ /**
209
+ * VaultIngestor & PublicationManager — transactional Note/Telemetry ingestion,
210
+ * zero-import remote preview, single-Note cloning, and Publication Visibility
211
+ * controls over IStorage.
212
+ */
213
+
214
+ declare function getNotePublicationSummary(storage: IStorage, noteId: string): Promise<PublicationVisibilitySummary>;
215
+ declare function setNotebookPublic(storage: IStorage, notebookIdOrSlug: string, isPublic: boolean): Promise<Note>;
216
+ declare function setSessionPublic(storage: IStorage, sessionId: string, isPublic: boolean): Promise<Session>;
217
+ declare function previewRemoteNotebook(reader: FeedTreeReader, indexPath: string): Promise<NotebookIndex>;
218
+ declare function previewRemoteRecord(reader: FeedTreeReader, recordPath: string): Promise<SeedRow>;
219
+ declare function cloneRemoteRecord(storage: IStorage, reader: FeedTreeReader, input: {
220
+ feedId: string;
221
+ record: SeedRecordRef;
222
+ targetNotebookId: string;
223
+ includePublicTelemetry?: boolean;
224
+ }): Promise<Note>;
225
+ interface PortableFileEntry {
226
+ path: string;
227
+ content: string;
228
+ }
229
+ interface PortabilityImportReport {
230
+ notesImported: number;
231
+ revisionsImported: number;
232
+ sessionsImported: number;
233
+ eventsImported: number;
234
+ errors: string[];
235
+ }
236
+ declare function exportPortableFilesFromStorage(storage: IStorage, options?: {
237
+ noteIds?: readonly string[];
238
+ telemetryFormat?: 'jsonl' | 'csv' | 'both';
239
+ }): Promise<PortableFileEntry[]>;
240
+ declare function ingestPortableFilesIntoStorage(storage: IStorage, files: readonly PortableFileEntry[], options?: {
241
+ defaultNotebookId?: string;
242
+ now?: number;
243
+ }): Promise<PortabilityImportReport>;
244
+
245
+ /**
246
+ * JournalSessionIntake — Deep module owning read-only workout cloning into
247
+ * `notebook/journal`, atomic Session pinning, and upstream Note provenance
248
+ * resolution.
249
+ *
250
+ * When a workout is started on ANY read-only Note (`seedOrigin === 'seed'`,
251
+ * `feedOrigin === 'feed'`, `notebook/defaults`, `notebook/guides`, or a
252
+ * subscribed Feed Notebook), this module atomically:
253
+ * 1. Clones the full Note (Markdown prose, frontmatter, all workout & widget
254
+ * blocks, and immutable `BlockRevision`s) into `notebook/journal`,
255
+ * 2. Places the cloned Note onto the requested calendar `Page` (`YYYY-MM-DD`),
256
+ * 3. Records structured `NoteProvenance` (`sourceNoteId`, `sourceVersion`,
257
+ * `sourceCommit`, `feedSourceId`, `sourceNotebookId`, `sourcePath`),
258
+ * 4. Pins the new `Session` to the corresponding block occurrence on the
259
+ * Journal clone — leaving the read-only upstream Note untouched.
260
+ */
261
+
262
+ interface PrepareJournalSessionRunInput {
263
+ noteId: string;
264
+ blockId?: string;
265
+ sessionId?: string;
266
+ journalDate?: string;
267
+ startedAt?: number;
268
+ origin?: ResultOrigin;
269
+ }
270
+ interface PreparedJournalSessionRun {
271
+ note: Note;
272
+ revision: BlockRevision;
273
+ session: Session;
274
+ clonedFromReadOnly: boolean;
275
+ upstreamNoteId?: string;
276
+ }
277
+ interface ResolvedUpstreamProvenance {
278
+ exists: boolean;
279
+ sourceNoteId: string;
280
+ title?: string;
281
+ sourceVersion?: number;
282
+ currentUpstreamVersion?: number;
283
+ sourceCommit?: string;
284
+ feedSourceId?: string;
285
+ sourceNotebookId?: string;
286
+ sourcePath?: string;
287
+ }
288
+ declare function prepareJournalSessionRun(storage: IStorage, input: PrepareJournalSessionRunInput): Promise<PreparedJournalSessionRun>;
289
+ /**
290
+ * Resolve a cloned Note's upstream provenance against current storage.
291
+ * Returns `exists: true` while the original Note remains in storage (so UI can
292
+ * link directly to it), and `exists: false` with preserved metadata if the
293
+ * upstream Feed was later unsubscribed or removed.
294
+ */
295
+ declare function resolveUpstreamProvenance(storage: IStorage, note: Pick<Note, 'provenance' | 'sourceId'>): Promise<ResolvedUpstreamProvenance | null>;
296
+ declare function buildNoteProvenance(sourceNote: Pick<Note, 'id' | 'seedVersion' | 'sourceRevision' | 'seedCommit' | 'feedSourceId' | 'sourcePath'>, sourceNotebookId: string | undefined, clonedAt: number): NoteProvenance;
297
+
298
+ /**
299
+ * Pure JSON Intermediate Representation (IR) Schemas & Envelope
300
+ *
301
+ * Implements wayfinder #955 and research asset `docs/research/json-ir-schemas-2026-08-17.md`.
302
+ * Freezes the existing result vocabulary (QueryResult, RowsQueryResult, FindQueryResult,
303
+ * StoredOutputStatement, AnalyticsDataPoint, WorkoutResult, StatementNode) in a
304
+ * versioned envelope safe for JSON round-trips.
305
+ */
306
+
307
+ type IrKind = 'fact-set' | 'result-set' | 'note-set' | 'corpus' | 'query-result' | 'find-result' | 'rows-result' | 'pipeline-result' | 'parse-tree' | 'execution-log';
308
+ /**
309
+ * Universal JSON envelope for all headless IR fixtures and output artifacts.
310
+ */
311
+ interface WodWikiIRFile<T> {
312
+ $schema: 'https://wod-wiki.dev/ir/v1.json';
313
+ kind: IrKind;
314
+ generatedAt: number;
315
+ source: string;
316
+ data: T;
317
+ }
318
+ declare function createIRFile<T>(kind: IrKind, data: T, optionsOrSource?: string | {
319
+ source?: string;
320
+ generatedAt?: number;
321
+ }, generatedAt?: number): WodWikiIRFile<T>;
322
+ declare function isIRFile<T = unknown>(obj: unknown): obj is WodWikiIRFile<T>;
323
+ interface MetricNode {
324
+ type: string;
325
+ image?: string;
326
+ value?: unknown;
327
+ origin?: string;
328
+ }
329
+ interface StatementNode {
330
+ id: number;
331
+ type: 'statement' | 'duration' | 'rounds' | 'rest' | 'segment' | 'root';
332
+ raw: string;
333
+ from: number;
334
+ to: number;
335
+ metrics: MetricNode[];
336
+ hints?: string[];
337
+ children?: StatementNode[];
338
+ }
339
+ declare function statementToNode(stmt: ICodeStatement, idMap: Map<number, ICodeStatement>): StatementNode;
340
+ /** Builds a StatementNode tree from a parsed WhiteboardScript. */
341
+ declare function buildStatementTree(script: IScript): StatementNode;
342
+ interface ExecutionLog {
343
+ results: WorkoutResults;
344
+ logs: StoredOutputStatement[];
345
+ statements?: StoredOutputStatement[];
346
+ blockKey?: string;
347
+ sourceScript?: string;
348
+ }
349
+ interface CorpusIRData {
350
+ notes?: Note[];
351
+ revisions?: BlockRevision[];
352
+ blocks?: BlockIndexRow[];
353
+ results?: Session[];
354
+ facts?: AnalyticsDataPoint[];
355
+ efforts?: IEffort[];
356
+ logs?: StoredOutputStatement[];
357
+ tags?: Record<string, string[]>;
358
+ }
359
+
360
+ export { isIRFile as $, SEED_REGISTERED_WIDGETS as A, SEED_SCHEMA as B, CANVAS_CHUNK_ID as C, DASHBOARDS_CHUNK_ID as D, EFFORTS_CHUNK_ID as E, type FeedTree as F, type SeedRecordRef as G, HttpFeedTree as H, type IrKind as I, buildNoteProvenance as J, buildStatementTree as K, canvasRouteSlug as L, type ManifestChunk as M, type NotebookIndex as N, cloneRemoteRecord as O, type PortableFileEntry as P, createIRFile as Q, type ResolvedUpstreamProvenance as R, type StatementNode as S, decodeUtf8 as T, emptySeedMeta as U, encodeUtf8 as V, type WodWikiIRFile as W, exportPortableFilesFromStorage as X, feedIdOfMetaKey as Y, getNotePublicationSummary as Z, ingestPortableFilesIntoStorage as _, type SeedRow as a, normalizeFeedTreePath as a0, notebookSlugForChunkId as a1, prepareJournalSessionRun as a2, previewRemoteNotebook as a3, previewRemoteRecord as a4, resolveUpstreamProvenance as a5, seedMetaKey as a6, seedNoteSourceId as a7, seedPrecedenceRank as a8, seedSourceTier as a9, setNotebookPublic as aa, setSessionPublic as ab, sha256HexAsync as ac, statementToNode as ad, type SeedManifest as b, type SeedMetaRecord as c, type FeedTreeReader as d, type ChunkKind as e, type CorpusIRData as f, DirectoryHandleFeedTree as g, EQUIPMENT_CHUNK_ID as h, type ExecutionLog as i, type FeedFileStat as j, type FeedPath as k, FeedTreeError as l, type FeedTreeErrorCode as m, type FeedTreeWriter as n, type FetchLike as o, type FileSystemDirectoryHandleLike as p, type FileSystemFileHandleLike as q, type FileSystemWritableLike as r, MemoryFeedTree as s, type MetricNode as t, type NotebookIndexSummary as u, type PortabilityImportReport as v, type PrepareJournalSessionRunInput as w, type PreparedJournalSessionRun as x, SEED_BROADCAST_CHANNEL as y, SEED_NAMESPACE as z };