@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 +214 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +172 -10
- package/dist/index.d.ts +172 -10
- package/dist/index.mjs +206 -21
- package/dist/index.mjs.map +1 -1
- package/dist/testing.cjs +576 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +735 -0
- package/dist/testing.d.ts +735 -0
- package/dist/testing.mjs +569 -0
- package/dist/testing.mjs.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feed identity — the source-side vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* A **feed** is one published directory the app subscribes to and syncs as a
|
|
5
|
+
* unit (the glossary's *Feed*). The word "seed" no longer names a source:
|
|
6
|
+
* a registered source is a feed, its id is a feed id, and the artifact it
|
|
7
|
+
* serves is a **Seed** (see `SeedManifest` in the engine's seed contract).
|
|
8
|
+
*
|
|
9
|
+
* A registered feed has ONE id — the registry id, `FeedSource.id` — and
|
|
10
|
+
* that id is also the note's `feedSourceId` and the suffix of the import
|
|
11
|
+
* checkpoint key (`seed:<id>`, whose `seed:` prefix is a persisted wire
|
|
12
|
+
* format, not a source name).
|
|
13
|
+
*/
|
|
14
|
+
/** A feed identifier — the id of one registered feed source. */
|
|
15
|
+
type FeedId = string;
|
|
16
|
+
/**
|
|
17
|
+
* How a record came to be: delivered by a feed (`'feed'`), or authored and
|
|
18
|
+
* owned by the user (`'user'`). The feed-side twin of the artifact-side
|
|
19
|
+
* `seedOrigin` (`'seed' | 'user'`) — the two agree on every imported note.
|
|
20
|
+
*/
|
|
21
|
+
type FeedOrigin = 'feed' | 'user';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Canonical ownership vocabulary for metric visibility decisions.
|
|
25
|
+
* Ordered from lowest to highest ownership precedence.
|
|
26
|
+
*/
|
|
27
|
+
type MetricOwnershipLayer = 'parser' | 'dialect' | 'user-plan' | 'runtime' | 'user-entry';
|
|
28
|
+
/**
|
|
29
|
+
* Origin of a metric - where it was created and its current state.
|
|
30
|
+
*
|
|
31
|
+
* Source origins:
|
|
32
|
+
* - 'parser': Created by the parser from source text
|
|
33
|
+
* - 'compiler': Synthesized by a compiler strategy
|
|
34
|
+
* - 'dialect': Synthesized by a dialect policy before runtime
|
|
35
|
+
* - 'runtime': Generated during execution (e.g., elapsed time)
|
|
36
|
+
* - 'user': Collected from user input (e.g., actual reps completed)
|
|
37
|
+
*
|
|
38
|
+
* Value states:
|
|
39
|
+
* - 'collected': Value has been collected and populated
|
|
40
|
+
* - 'hinted': Value is a hint or suggestion not strictly enforced
|
|
41
|
+
* - 'tracked': Value is actively being tracked during execution
|
|
42
|
+
* - 'analyzed': Value is derived from analysis
|
|
43
|
+
* - 'analyzed-estimated': Value is derived from estimation
|
|
44
|
+
* - 'execution': Generated by runtime execution
|
|
45
|
+
* - 'user-plan': Planned override set by user before execution
|
|
46
|
+
*/
|
|
47
|
+
type MetricAction = 'suppress';
|
|
48
|
+
type MetricOrigin = 'parser' | 'compiler' | 'dialect' | 'runtime' | 'user' | 'collected' | 'hinted' | 'tracked' | 'analyzed' | 'analyzed-estimated' | 'execution' | 'user-plan' | 'diagnostic';
|
|
49
|
+
interface IMetric {
|
|
50
|
+
readonly image?: string;
|
|
51
|
+
readonly value?: unknown;
|
|
52
|
+
/**
|
|
53
|
+
* The metric type. Use a `MetricType` enum value for standard types, or any
|
|
54
|
+
* string for custom derived metrics produced by enrichment processes
|
|
55
|
+
* (e.g. `'speed'`, `'pace'`, `'rep-rate'`, `'power'`).
|
|
56
|
+
*/
|
|
57
|
+
readonly type: MetricType | string;
|
|
58
|
+
/** Backward-compatible alias for type */
|
|
59
|
+
readonly metricType?: MetricType | string;
|
|
60
|
+
readonly origin: MetricOrigin;
|
|
61
|
+
readonly unit?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Visibility instruction. The only live value is `'suppress'`, which hides
|
|
64
|
+
* all metrics of this type from display (resolved by the ownership ledger).
|
|
65
|
+
* Most metrics carry no action (undefined = passive).
|
|
66
|
+
*/
|
|
67
|
+
readonly action?: MetricAction;
|
|
68
|
+
/**
|
|
69
|
+
* Block key that created/owns this metric.
|
|
70
|
+
* Present for runtime and user-collected metrics.
|
|
71
|
+
*/
|
|
72
|
+
readonly sourceBlockKey?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Timestamp when this metric was created/recorded.
|
|
75
|
+
* Present for runtime and user-collected metrics.
|
|
76
|
+
*/
|
|
77
|
+
readonly timestamp?: Date;
|
|
78
|
+
/**
|
|
79
|
+
* Processor-attached structured payload. Summary processors (e.g. TIS) hang
|
|
80
|
+
* derivation metadata (effortSlug, effortDiscipline, effortIntensityTier,
|
|
81
|
+
* component scores) on the projection value metric; fact normalization reads
|
|
82
|
+
* it back out. Pure data — survives the stored-logs round-trip.
|
|
83
|
+
*/
|
|
84
|
+
readonly metadata?: Record<string, unknown>;
|
|
85
|
+
/** Optional explicit ownership layer for legacy compatibility */
|
|
86
|
+
readonly ownershipLayer?: MetricOwnershipLayer;
|
|
87
|
+
/** Optional human-readable name or label */
|
|
88
|
+
readonly name?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Optional icon (emoji/glyph) for hint metrics. Hints without an icon are
|
|
91
|
+
* data-only — they never render in display surfaces; a hint WITH an icon
|
|
92
|
+
* renders as the icon alone, with the hint text on hover.
|
|
93
|
+
*/
|
|
94
|
+
readonly icon?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Metric type enumeration.
|
|
98
|
+
*
|
|
99
|
+
* Time-related terms follow the glossary in docs/architecture/time-terminology.md:
|
|
100
|
+
* - **Duration** (Parser) — planned target from the script (e.g., "5:00" -> 300 000 ms)
|
|
101
|
+
* - **Time / Spans** (Block) — the raw TimeSpan[] start/stop recordings a block tracks
|
|
102
|
+
* - **TimeStamp** (Runtime) — system Date.now() when a message is logged
|
|
103
|
+
* - **Elapsed** (Runtime) — Σ(end - start) of each span segment (active time, excludes pauses)
|
|
104
|
+
* - **Total** (Runtime) — lastEnd - firstStart (wall-clock bracket, includes pauses)
|
|
105
|
+
*/
|
|
106
|
+
declare enum MetricType {
|
|
107
|
+
/**
|
|
108
|
+
* **Duration** (Core) — parser-defined planned target.
|
|
109
|
+
*
|
|
110
|
+
* A metric defined by the CodeStatement during parsing (e.g., "5:00" -> 300 000 ms).
|
|
111
|
+
* It can be a time (duration) or a placeholder to be resolved.
|
|
112
|
+
* Owned by the parser — the runtime reads it but never computes it.
|
|
113
|
+
*/
|
|
114
|
+
Duration = "duration",
|
|
115
|
+
/**
|
|
116
|
+
* **Spans** (Core) — raw start/stop TimeSpan[] recordings.
|
|
117
|
+
*
|
|
118
|
+
* Source-of-truth data recorded using the runtime clock.
|
|
119
|
+
* Each span represents a continuous period of active (unpaused) execution.
|
|
120
|
+
* These can be recorded at runtime or back-filled during analytics.
|
|
121
|
+
*/
|
|
122
|
+
Spans = "spans",
|
|
123
|
+
/**
|
|
124
|
+
* **SystemTime** (Core) — real system time (Date.now()) when a message is logged.
|
|
125
|
+
*
|
|
126
|
+
* Ground-truth wall-clock reference (timestamp) associated with system time metrics.
|
|
127
|
+
* Independent of the runtime clock.
|
|
128
|
+
*/
|
|
129
|
+
SystemTime = "system-time",
|
|
130
|
+
/** Live timer state written into block memory by the count-up/count-down timer behaviors. */
|
|
131
|
+
Time = "time",
|
|
132
|
+
/** Active elapsed time — Σ(end - start) of active spans; derived during analytics. */
|
|
133
|
+
Elapsed = "elapsed",
|
|
134
|
+
/** Total wall-clock bracket (lastEnd - firstStart) for a block; derived during analytics. */
|
|
135
|
+
Total = "total",
|
|
136
|
+
Rep = "rep",
|
|
137
|
+
Effort = "effort",
|
|
138
|
+
/**
|
|
139
|
+
* **Equipment** (Core) — ordered deduplicated canonical equipment slugs for a
|
|
140
|
+
* statement (e.g. `["dumbbell"]` from `10 Dumbbell Snatch`). One metric per
|
|
141
|
+
* statement; `metadata.refs` carries structured ReferenceRef entries,
|
|
142
|
+
* `metadata.source` the authored label, `metadata.diagnostics` any
|
|
143
|
+
* unknown/ambiguous/malformed reference findings.
|
|
144
|
+
*/
|
|
145
|
+
Equipment = "equipment",
|
|
146
|
+
Distance = "distance",
|
|
147
|
+
Rounds = "rounds",
|
|
148
|
+
CurrentRound = "current-round",
|
|
149
|
+
Action = "action",
|
|
150
|
+
Increment = "increment",
|
|
151
|
+
Group = "group",
|
|
152
|
+
Text = "text",
|
|
153
|
+
Resistance = "resistance",
|
|
154
|
+
Sound = "sound",
|
|
155
|
+
System = "system",
|
|
156
|
+
Label = "label",
|
|
157
|
+
Lap = "lap",
|
|
158
|
+
Metric = "metric",
|
|
159
|
+
/**
|
|
160
|
+
* **Hint** (Core) — a semantic marker emitted by a dialect or the parser.
|
|
161
|
+
*
|
|
162
|
+
* Dot-namespaced string markers (e.g. `workout.amrap`, `behavior.required_timer`)
|
|
163
|
+
* that strategies and the label composer query to drive compilation decisions.
|
|
164
|
+
* Hints are metrics so they flow through the single ownership channel, but they
|
|
165
|
+
* are excluded from display resolution and from runtime block fragments.
|
|
166
|
+
*/
|
|
167
|
+
Hint = "hint",
|
|
168
|
+
/** Generic custom metric bucket for parser-owned property metrics. */
|
|
169
|
+
Custom = "custom",
|
|
170
|
+
Volume = "volume",
|
|
171
|
+
Intensity = "intensity",
|
|
172
|
+
/** Climb grade label carried by an observation (e.g. `V8`, `5.12a`) —
|
|
173
|
+
* user-authored grade metrics promote to the analytics `grade` dim. */
|
|
174
|
+
Grade = "grade",
|
|
175
|
+
Load = "load",
|
|
176
|
+
Work = "work",
|
|
177
|
+
/** Per-set Reps in Reserve (real-time, strength) */
|
|
178
|
+
RIR = "rir",
|
|
179
|
+
/** Post-session subjective effort rating (0–10) */
|
|
180
|
+
SessionRPE = "session-rpe",
|
|
181
|
+
/** Session RPE x total minutes */
|
|
182
|
+
SessionLoad = "session-load",
|
|
183
|
+
/** Normalized MET ((Activity METs ÷ METmax) x 100) */
|
|
184
|
+
METScore = "met-score",
|
|
185
|
+
/** Training Intensity Score (composite) */
|
|
186
|
+
TIS = "tis",
|
|
187
|
+
/** Runtime-layer calculated metric emitted from declarative formulas */
|
|
188
|
+
Calculated = "calculated",
|
|
189
|
+
/** Skipped-Dependency Diagnostic emitted by the Metric Shake-Out Queue */
|
|
190
|
+
Diagnostic = "diagnostic",
|
|
191
|
+
/**
|
|
192
|
+
* **Choice** (Parser) — a pipe-separated OR expression.
|
|
193
|
+
*
|
|
194
|
+
* Emitted by Fusion when a pipe separates two homogeneous alternatives
|
|
195
|
+
* (same MetricType on both sides). Carries `alternatives: IMetric[]`.
|
|
196
|
+
* Resolved in the Pre-Run Wizard before the JIT compiles: the chosen
|
|
197
|
+
* alternative is written at origin `user-plan` into the Statement's
|
|
198
|
+
* MetricContainer, shadowing this group via ownership-layer precedence.
|
|
199
|
+
* Never reaches compiled Blocks or display output once resolved.
|
|
200
|
+
*/
|
|
201
|
+
Choice = "choice"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Output statement types indicating what kind of result this represents.
|
|
206
|
+
*
|
|
207
|
+
* - 'segment': A timed portion of execution (e.g., a round, an effort interval)
|
|
208
|
+
* - 'milestone': A notable event during execution (e.g., halfway point, personal record)
|
|
209
|
+
* - 'system': Debug/diagnostic output from lifecycle events
|
|
210
|
+
* - 'event': Tracks external stimuli or internal triggers
|
|
211
|
+
* - 'group': Identified segment with children
|
|
212
|
+
* - 'load': Initial script state
|
|
213
|
+
* - 'compiler': Behavior configuration and setup
|
|
214
|
+
* - 'analytics': Output generated by the analytics engine
|
|
215
|
+
*/
|
|
216
|
+
type OutputStatementType = 'segment' | 'milestone' | 'completion' | 'metric' | 'system' | 'event' | 'group' | 'load' | 'compiler' | 'analytics';
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Plain-data snapshot of a runtime OutputStatement safe for JSON / IndexedDB
|
|
220
|
+
* round-trips. Class methods and non-serialisable fields (Set, Map,
|
|
221
|
+
* MetricContainer instances) are intentionally excluded.
|
|
222
|
+
*
|
|
223
|
+
* The live->stored converter `toStoredOutputStatement` lives in `@bitcobblers/wod-wiki-lang`
|
|
224
|
+
* because it requires the hint evaluation protocol.
|
|
225
|
+
*/
|
|
226
|
+
interface StoredOutputStatement {
|
|
227
|
+
readonly id?: number;
|
|
228
|
+
readonly line?: number;
|
|
229
|
+
readonly text?: string;
|
|
230
|
+
readonly dialect?: string;
|
|
231
|
+
readonly outputType?: OutputStatementType;
|
|
232
|
+
readonly timeSpan?: {
|
|
233
|
+
started: number;
|
|
234
|
+
ended?: number;
|
|
235
|
+
};
|
|
236
|
+
/** Flat IMetric array — MetricContainer class not needed after serialisation. */
|
|
237
|
+
readonly metrics: IMetric[] | {
|
|
238
|
+
name?: string;
|
|
239
|
+
type?: string;
|
|
240
|
+
value?: unknown;
|
|
241
|
+
unit?: string;
|
|
242
|
+
origin?: string;
|
|
243
|
+
}[];
|
|
244
|
+
/** Plain string array — Set<string> does not survive JSON serialisation. */
|
|
245
|
+
readonly hints?: string[];
|
|
246
|
+
readonly sourceBlockKey?: string;
|
|
247
|
+
readonly stackLevel?: number;
|
|
248
|
+
readonly parent?: number;
|
|
249
|
+
readonly sourceStatementId?: number;
|
|
250
|
+
readonly completionReason?: string;
|
|
251
|
+
readonly timestamp?: number;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Tags — named bundles a script can reference.
|
|
256
|
+
*
|
|
257
|
+
* A script line points at a tag instead of repeating what the tag means:
|
|
258
|
+
*
|
|
259
|
+
* ```text
|
|
260
|
+
* 5 reps @ 100 kg #heavy
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* A tag contributes three kinds of thing to the statements that reference
|
|
264
|
+
* it:
|
|
265
|
+
*
|
|
266
|
+
* - a **metric** — a typed value with a unit (the meaning of the line),
|
|
267
|
+
* - a **tag** — another tag, so a tag can build on a tag,
|
|
268
|
+
* - a **function** — a named calculation the tag activates where it applies.
|
|
269
|
+
*
|
|
270
|
+
* The model lives in core because both the parser (which resolves
|
|
271
|
+
* `#slug` references) and the runtime (which runs the functions a tag
|
|
272
|
+
* carries) need it, and neither should know how tags are stored.
|
|
273
|
+
*/
|
|
274
|
+
/** A metric a tag contributes: a typed value with an optional unit. */
|
|
275
|
+
interface TagMetricContribution {
|
|
276
|
+
readonly kind: 'metric';
|
|
277
|
+
/** The metric type, e.g. `sound` or `rpe`. */
|
|
278
|
+
readonly type: string;
|
|
279
|
+
/** The metric's value. */
|
|
280
|
+
readonly value: string | number | boolean | null;
|
|
281
|
+
/** The unit the value is expressed in, when it has one. */
|
|
282
|
+
readonly unit?: string;
|
|
283
|
+
}
|
|
284
|
+
/** Another tag this tag applies. */
|
|
285
|
+
interface TagTagContribution {
|
|
286
|
+
readonly kind: 'tag';
|
|
287
|
+
/** The slug of the applied tag. */
|
|
288
|
+
readonly slug: string;
|
|
289
|
+
}
|
|
290
|
+
/** A named function this tag carries. */
|
|
291
|
+
interface TagFunctionContribution {
|
|
292
|
+
readonly kind: 'function';
|
|
293
|
+
/**
|
|
294
|
+
* The function's name — the id of the calculation it refers to. The
|
|
295
|
+
* calculation's own scope decides the grain it runs at: `segment` per
|
|
296
|
+
* record, `workout` at the end of the workout.
|
|
297
|
+
*/
|
|
298
|
+
readonly name: string;
|
|
299
|
+
}
|
|
300
|
+
/** What a tag contributes. */
|
|
301
|
+
type TagContribution = TagMetricContribution | TagTagContribution | TagFunctionContribution;
|
|
302
|
+
|
|
303
|
+
type NoteBlockKind = 'wod' | 'query' | 'widget' | 'embed';
|
|
304
|
+
interface NoteBlock {
|
|
305
|
+
id: string;
|
|
306
|
+
kind: NoteBlockKind;
|
|
307
|
+
version: number;
|
|
308
|
+
sourceRevision: number;
|
|
309
|
+
from: number;
|
|
310
|
+
to: number;
|
|
311
|
+
dialect?: 'time' | 'log';
|
|
312
|
+
sport?: string;
|
|
313
|
+
}
|
|
314
|
+
interface BlockRevision {
|
|
315
|
+
noteId: string;
|
|
316
|
+
blockId: string;
|
|
317
|
+
version: number;
|
|
318
|
+
kind: NoteBlockKind;
|
|
319
|
+
rawContent: string;
|
|
320
|
+
savedAt: number;
|
|
321
|
+
dialect?: 'time' | 'log';
|
|
322
|
+
sport?: string;
|
|
323
|
+
}
|
|
324
|
+
type NoteKind = 'journal' | 'playground' | 'dashboard' | 'page' | 'note' | (string & {});
|
|
325
|
+
interface NoteProvenance {
|
|
326
|
+
/** Canonical UUID of the original Note at the time of cloning/execution. */
|
|
327
|
+
sourceNoteId: string;
|
|
328
|
+
/** Upstream seed/manifest version or source revision captured when cloned. */
|
|
329
|
+
sourceVersion?: number;
|
|
330
|
+
/** Git commit hash of the upstream publication when available. */
|
|
331
|
+
sourceCommit?: string;
|
|
332
|
+
/** Registered Feed id that delivered the upstream Note. */
|
|
333
|
+
feedSourceId?: FeedId;
|
|
334
|
+
/** Source Notebook id ('notebook/<slug>') for scoped override inheritance. */
|
|
335
|
+
sourceNotebookId?: string;
|
|
336
|
+
/** Original corpus path fallback if the upstream Note is later removed. */
|
|
337
|
+
sourcePath?: string;
|
|
338
|
+
/** Epoch-ms timestamp when the clone was created. */
|
|
339
|
+
clonedAt: number;
|
|
340
|
+
}
|
|
341
|
+
interface Note {
|
|
342
|
+
id: string;
|
|
343
|
+
title: string;
|
|
344
|
+
rawContent: string;
|
|
345
|
+
sourceRevision: number;
|
|
346
|
+
blocks: Record<string, NoteBlock>;
|
|
347
|
+
date?: number;
|
|
348
|
+
createdAt: number;
|
|
349
|
+
type?: NoteKind;
|
|
350
|
+
sourceId?: string;
|
|
351
|
+
/** Canonical notebook identifier ('notebook/{slug}', e.g. 'notebook/journal', 'notebook/playground', 'notebook/guides'). */
|
|
352
|
+
notebookId?: string;
|
|
353
|
+
/** Many-to-many Notebook memberships linked to this Note (kept in sync with `notebook_links`). */
|
|
354
|
+
notebookIds?: string[];
|
|
355
|
+
/** Structured lineage back to an upstream read-only Note when cloned into the Journal or a user Notebook. */
|
|
356
|
+
provenance?: NoteProvenance;
|
|
357
|
+
tags?: string[];
|
|
358
|
+
/** Artifact provenance — which published bundle this note came from.
|
|
359
|
+
* Persisted field names; the artifact they describe is a **Seed**. */
|
|
360
|
+
seedOrigin?: 'seed' | 'user';
|
|
361
|
+
seedVersion?: number;
|
|
362
|
+
seedChunkId?: string;
|
|
363
|
+
/** Feed provenance — 'feed' for a note a feed delivered, 'user' for one the
|
|
364
|
+
* user owns. The two agree: a feed-delivered note is seed-delivered, and
|
|
365
|
+
* vice versa. */
|
|
366
|
+
feedOrigin?: FeedOrigin;
|
|
367
|
+
/** The registered feed that delivered this note (the feed's own id).
|
|
368
|
+
* Read from here alone — never from the seed stamps. */
|
|
369
|
+
feedSourceId?: FeedId;
|
|
370
|
+
/** Authored corpus path used for deterministic identity and routing. */
|
|
371
|
+
sourcePath?: string;
|
|
372
|
+
/** Git commit hash in which this note was published or changed. */
|
|
373
|
+
seedCommit?: string;
|
|
374
|
+
/** Whether a user-owned notebook landing note (`notebook/{slug}`) publishes its member notes to the outbound Feed. */
|
|
375
|
+
public?: boolean;
|
|
376
|
+
}
|
|
377
|
+
interface Page {
|
|
378
|
+
id: string;
|
|
379
|
+
date?: string;
|
|
380
|
+
slug?: string;
|
|
381
|
+
title?: string;
|
|
382
|
+
createdAt: number;
|
|
383
|
+
}
|
|
384
|
+
interface PageNote {
|
|
385
|
+
id: string;
|
|
386
|
+
pageId: string;
|
|
387
|
+
noteId: string;
|
|
388
|
+
position?: number;
|
|
389
|
+
createdAt: number;
|
|
390
|
+
}
|
|
391
|
+
type TagType = 'playground' | 'qualification' | 'notebook' | 'general' | (string & {});
|
|
392
|
+
/**
|
|
393
|
+
* A tag: a named bundle a script can reference with `#slug`.
|
|
394
|
+
*
|
|
395
|
+
* Keeping the contributions on the tag means the meaning lives in one place
|
|
396
|
+
* instead of being repeated on every line that wants the tag.
|
|
397
|
+
*/
|
|
398
|
+
interface Tag {
|
|
399
|
+
id: string;
|
|
400
|
+
label: string;
|
|
401
|
+
type?: TagType;
|
|
402
|
+
/**
|
|
403
|
+
* What this tag contributes when referenced from script content: metrics,
|
|
404
|
+
* other tags, and functions.
|
|
405
|
+
*/
|
|
406
|
+
contributions?: TagContribution[];
|
|
407
|
+
createdAt: number;
|
|
408
|
+
}
|
|
409
|
+
interface NoteTag {
|
|
410
|
+
id: string;
|
|
411
|
+
noteId: string;
|
|
412
|
+
tagId: string;
|
|
413
|
+
}
|
|
414
|
+
interface BlockIndexRow {
|
|
415
|
+
/** Current occurrence key `${noteId}:${blockId}`. */
|
|
416
|
+
id: string;
|
|
417
|
+
noteId: string;
|
|
418
|
+
blockId: string;
|
|
419
|
+
blockVersion: number;
|
|
420
|
+
sourceRevision: number;
|
|
421
|
+
from: number;
|
|
422
|
+
to: number;
|
|
423
|
+
position?: number;
|
|
424
|
+
dataType: NoteBlock['kind'];
|
|
425
|
+
blockContentId?: string;
|
|
426
|
+
rawContent: string;
|
|
427
|
+
noteTitle: string;
|
|
428
|
+
createdAt: number;
|
|
429
|
+
isStatic?: boolean;
|
|
430
|
+
sourceId?: string;
|
|
431
|
+
sourcePath?: string;
|
|
432
|
+
routeId?: string;
|
|
433
|
+
notebookId?: string;
|
|
434
|
+
}
|
|
435
|
+
type ResultOrigin = 'journal' | 'playground' | 'user';
|
|
436
|
+
interface Session {
|
|
437
|
+
id: string;
|
|
438
|
+
noteId: string;
|
|
439
|
+
blockId: string;
|
|
440
|
+
blockVersion: number;
|
|
441
|
+
blockContentId?: string;
|
|
442
|
+
origin?: ResultOrigin;
|
|
443
|
+
pageId?: string;
|
|
444
|
+
/** Born in-progress at run start, completed when finalization commits. */
|
|
445
|
+
status?: 'in-progress' | 'completed';
|
|
446
|
+
/** When workout started */
|
|
447
|
+
startTime: number;
|
|
448
|
+
/** When workout ended */
|
|
449
|
+
endTime: number;
|
|
450
|
+
/** Total elapsed time (ms) */
|
|
451
|
+
duration: number;
|
|
452
|
+
/** Rounds completed (for rounds-based workouts) */
|
|
453
|
+
roundsCompleted?: number;
|
|
454
|
+
/** Total rounds (for rounds-based workouts) */
|
|
455
|
+
totalRounds?: number;
|
|
456
|
+
/** Reps completed (for rep-based workouts) */
|
|
457
|
+
repsCompleted?: number;
|
|
458
|
+
/** Whether workout was completed or stopped early */
|
|
459
|
+
completed: boolean;
|
|
460
|
+
createdAt: number;
|
|
461
|
+
/** Whether this Session's telemetry is published when its parent Note belongs to a public Notebook. */
|
|
462
|
+
public?: boolean;
|
|
463
|
+
/** Many-to-many Notebook memberships this Session is attached/promoted to. */
|
|
464
|
+
notebookIds?: string[];
|
|
465
|
+
}
|
|
466
|
+
type NotebookLinkTargetKind = 'note' | 'session';
|
|
467
|
+
interface NotebookLink {
|
|
468
|
+
/** Deterministic key `${notebookId}:${targetKind}:${targetId}`. */
|
|
469
|
+
id: string;
|
|
470
|
+
notebookId: string;
|
|
471
|
+
targetKind: NotebookLinkTargetKind;
|
|
472
|
+
targetId: string;
|
|
473
|
+
/** Owning Note UUID (`targetId` when `targetKind === 'note'`, `session.noteId` when `'session'`). */
|
|
474
|
+
noteId: string;
|
|
475
|
+
createdAt: number;
|
|
476
|
+
}
|
|
477
|
+
type OverridePropertyKind = 'effort' | 'equipment' | 'tag' | 'tag-type';
|
|
478
|
+
interface ScopedPropertyOverride {
|
|
479
|
+
/** Composite key `${notebookId}:${kind}:${slug}`. */
|
|
480
|
+
id: string;
|
|
481
|
+
notebookId: string;
|
|
482
|
+
kind: OverridePropertyKind;
|
|
483
|
+
slug: string;
|
|
484
|
+
label: string;
|
|
485
|
+
ownerNoteId: string;
|
|
486
|
+
rawContent: string;
|
|
487
|
+
/** Parsed entity payload (`IEffort`, `IEquipment`, `Tag`, or `TagTypeRecord`). */
|
|
488
|
+
payload?: Record<string, unknown>;
|
|
489
|
+
seedOrigin?: 'seed' | 'user';
|
|
490
|
+
feedSourceId?: FeedId;
|
|
491
|
+
updatedAt: number;
|
|
492
|
+
}
|
|
493
|
+
/** Store-row kind: 'event' = raw statement row, 'summary' = folded row.
|
|
494
|
+
* Authorship lives on `origin` (engine-authored summaries are finalize-owned;
|
|
495
|
+
* user-authored summaries — wellness — are reconcile-owned). Ticket 005. */
|
|
496
|
+
type EventGrain = 'event' | 'summary';
|
|
497
|
+
interface EventRecord {
|
|
498
|
+
/**
|
|
499
|
+
* Event rows: `${resultId}:${seq}` — immutable, append-only.
|
|
500
|
+
* Summary rows: `${resultId}:summary:${metricKey}[:k=v…]` — deterministic
|
|
501
|
+
* content key; re-finalize overwrites cleanly (ticket 002).
|
|
502
|
+
* Wellness rows: `wellness:${noteId}:${key}` — reconcile-owned upserts.
|
|
503
|
+
*/
|
|
504
|
+
id: string;
|
|
505
|
+
resultId: string;
|
|
506
|
+
noteId: string;
|
|
507
|
+
/** Content-stable cross-workout join key (promoted, ticket 003 amendment). */
|
|
508
|
+
blockContentId?: string;
|
|
509
|
+
pageId?: string;
|
|
510
|
+
origin?: ResultOrigin;
|
|
511
|
+
/** Canonical time — when the workout happened, never when derived. */
|
|
512
|
+
timestamp: number;
|
|
513
|
+
grain: EventGrain;
|
|
514
|
+
effortSlug?: string;
|
|
515
|
+
/** Open vocabulary — see KNOWN_OUTPUT_TYPES. */
|
|
516
|
+
outputType: string;
|
|
517
|
+
/** Typed metric array; EXACTLY ONE entry when grain:'summary'. Summary
|
|
518
|
+
* fold identity (canonicalKey, groupTags, effort metadata) lives in
|
|
519
|
+
* metrics[0].metadata — shape-uniform with events. */
|
|
520
|
+
metrics: StoredOutputStatement['metrics'];
|
|
521
|
+
timeSpan?: {
|
|
522
|
+
started: number;
|
|
523
|
+
ended?: number;
|
|
524
|
+
};
|
|
525
|
+
sourceBlockKey?: string;
|
|
526
|
+
sourceStatementId?: number;
|
|
527
|
+
line?: number;
|
|
528
|
+
text?: string;
|
|
529
|
+
dialect?: string;
|
|
530
|
+
stackLevel?: number;
|
|
531
|
+
completionReason?: string;
|
|
532
|
+
blockId?: string;
|
|
533
|
+
blockVersion?: number;
|
|
534
|
+
/** Per-metric temporal anchors (ticket 12) — parallel to `metrics` when
|
|
535
|
+
* the producing statement carries its own instants/dates:
|
|
536
|
+
* 'instant' = recorded occurrence instant; 'civil-date' = recorded civil
|
|
537
|
+
* date (date-only wellness), never a fabricated midnight. The row
|
|
538
|
+
* timestamp remains the V16 fetch anchor until the by-metricDate index
|
|
539
|
+
* (ticket 14); it must not relocate a metric whose own date differs. */
|
|
540
|
+
metricTemporal?: MetricTemporal[];
|
|
541
|
+
/** Ticket 14: civil-date keys (d:YYYY-MM-DD) of every metricTemporal with
|
|
542
|
+
* temporalKind 'civil-date' — the multiEntry `by-metric-date` index
|
|
543
|
+
* source. Kept distinct from the instant index on purpose: a date-only
|
|
544
|
+
* observation is never a midnight instant. */
|
|
545
|
+
metricDateKeys?: string[];
|
|
546
|
+
/** Ticket 14 provenance: how this row represents the underlying
|
|
547
|
+
* observations — directly recorded, calculated, or a substitute summary. */
|
|
548
|
+
representationKind?: 'direct' | 'calculated' | 'substitute_summary';
|
|
549
|
+
/** Ticket 14: the temporal/production scope a substitute summary covers. */
|
|
550
|
+
summaryCoverage?: SummaryCoverage;
|
|
551
|
+
/** Ticket 14: retained reducer statistics for substitution proofs. */
|
|
552
|
+
reducerStats?: ReducerStats;
|
|
553
|
+
}
|
|
554
|
+
/** Scope descriptor of a substitute summary's coverage (ticket 14). */
|
|
555
|
+
interface SummaryCoverage {
|
|
556
|
+
scope: 'workout' | 'effort' | 'partition';
|
|
557
|
+
effortSlug?: string;
|
|
558
|
+
/** Partition identity (group-tag pairs, key-sorted). */
|
|
559
|
+
groupTags?: Record<string, string>;
|
|
560
|
+
}
|
|
561
|
+
/** Retained statistics for substitution proofs (ticket 16 consumes).
|
|
562
|
+
* `observedCount` is the true represented observation count — never
|
|
563
|
+
* invented for legacy rows that lack it (undefined = insufficient
|
|
564
|
+
* evidence, not 1). */
|
|
565
|
+
interface ReducerStats {
|
|
566
|
+
observedCount?: number;
|
|
567
|
+
sum?: number;
|
|
568
|
+
min?: number;
|
|
569
|
+
max?: number;
|
|
570
|
+
}
|
|
571
|
+
interface MetricTemporal {
|
|
572
|
+
temporalKind: 'instant' | 'civil-date';
|
|
573
|
+
/** Occurrence instant (ms epoch) when temporalKind === 'instant'. */
|
|
574
|
+
instant?: number;
|
|
575
|
+
/** Civil YYYY-MM-DD when temporalKind === 'civil-date'. */
|
|
576
|
+
civilDate?: string;
|
|
577
|
+
}
|
|
578
|
+
interface BlockEffort {
|
|
579
|
+
id: string;
|
|
580
|
+
noteId: string;
|
|
581
|
+
blockId: string;
|
|
582
|
+
blockContentId?: string;
|
|
583
|
+
effortSlug: string;
|
|
584
|
+
isStatic?: boolean;
|
|
585
|
+
sourcePath?: string;
|
|
586
|
+
createdAt: number;
|
|
587
|
+
}
|
|
588
|
+
/** Containment link block → canonical equipment, mirroring BlockEffort. */
|
|
589
|
+
interface BlockEquipment {
|
|
590
|
+
id: string;
|
|
591
|
+
noteId: string;
|
|
592
|
+
blockId: string;
|
|
593
|
+
blockContentId?: string;
|
|
594
|
+
equipmentSlug: string;
|
|
595
|
+
isStatic?: boolean;
|
|
596
|
+
sourcePath?: string;
|
|
597
|
+
createdAt: number;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** Fixed epoch (2024-01-01T00:00:00Z) for every derived timestamp. */
|
|
601
|
+
declare const TEST_EPOCH: 1704067200000;
|
|
602
|
+
interface TestNoteInput {
|
|
603
|
+
id?: string;
|
|
604
|
+
title?: string;
|
|
605
|
+
rawContent: string;
|
|
606
|
+
type?: Note['type'];
|
|
607
|
+
date?: number;
|
|
608
|
+
createdAt?: number;
|
|
609
|
+
sourceRevision?: number;
|
|
610
|
+
seedOrigin?: 'seed' | 'user';
|
|
611
|
+
feedOrigin?: FeedOrigin;
|
|
612
|
+
sourceId?: string;
|
|
613
|
+
sourcePath?: string;
|
|
614
|
+
feedSourceId?: string;
|
|
615
|
+
priorBlocks?: Record<string, NoteBlock>;
|
|
616
|
+
notebookId?: string;
|
|
617
|
+
notebookIds?: string[];
|
|
618
|
+
tags?: string[];
|
|
619
|
+
provenance?: NoteProvenance;
|
|
620
|
+
}
|
|
621
|
+
interface BuiltTestNote {
|
|
622
|
+
note: Note;
|
|
623
|
+
revisions: BlockRevision[];
|
|
624
|
+
blockIndex: BlockIndexRow[];
|
|
625
|
+
blockEfforts: BlockEffort[];
|
|
626
|
+
blockEquipment: BlockEquipment[];
|
|
627
|
+
tags: Tag[];
|
|
628
|
+
noteTags: NoteTag[];
|
|
629
|
+
notebookLinks: NotebookLink[];
|
|
630
|
+
}
|
|
631
|
+
/** Clear the process-global property vocabulary (test isolation helper). */
|
|
632
|
+
declare function resetTestingVocabulary(): void;
|
|
633
|
+
/**
|
|
634
|
+
* Build a full Note aggregate: the Note itself, its block revision history,
|
|
635
|
+
* WQL block-index projections, effort/equipment containment rows, tag rows
|
|
636
|
+
* and notebook membership links.
|
|
637
|
+
*
|
|
638
|
+
* Block occurrence ids are deterministic (`blk-0`, `blk-1`, … in document
|
|
639
|
+
* order) and `BlockIndexRow.blockContentId` carries the real content
|
|
640
|
+
* fingerprint for wod blocks, so sessions can pin by content.
|
|
641
|
+
*/
|
|
642
|
+
declare function buildTestNote(input: TestNoteInput): BuiltTestNote;
|
|
643
|
+
interface TestPropertyNoteInput {
|
|
644
|
+
id?: string;
|
|
645
|
+
kind: OverridePropertyKind;
|
|
646
|
+
slug: string;
|
|
647
|
+
label: string;
|
|
648
|
+
notebookId?: string;
|
|
649
|
+
aliases?: string[];
|
|
650
|
+
metrics?: Record<string, string | number>;
|
|
651
|
+
summaries?: Record<string, string | number>;
|
|
652
|
+
baseAttributes?: Record<string, unknown>;
|
|
653
|
+
body?: string;
|
|
654
|
+
seedOrigin?: 'seed' | 'user';
|
|
655
|
+
feedSourceId?: string;
|
|
656
|
+
asOverride?: boolean;
|
|
657
|
+
}
|
|
658
|
+
interface BuiltPropertyNote {
|
|
659
|
+
note: Note;
|
|
660
|
+
override?: ScopedPropertyOverride;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Build a Property Note (effort | equipment | tag | tag-type) with valid
|
|
664
|
+
* YAML frontmatter — `parseEffortFile` / `parseEquipmentFile` /
|
|
665
|
+
* `documentToTag` can consume the result unchanged. When `asOverride` is set
|
|
666
|
+
* (or a notebook scope other than `notebook/defaults` is given) the matching
|
|
667
|
+
* `ScopedPropertyOverride` row is emitted alongside the Note.
|
|
668
|
+
*
|
|
669
|
+
* Effort/equipment slugs register into the mention vocabulary so later
|
|
670
|
+
* `buildTestNote` calls link containing blocks automatically.
|
|
671
|
+
*/
|
|
672
|
+
declare function buildPropertyNote(input: TestPropertyNoteInput): BuiltPropertyNote;
|
|
673
|
+
interface TestSessionInput {
|
|
674
|
+
id?: string;
|
|
675
|
+
noteId: string;
|
|
676
|
+
blockId?: string;
|
|
677
|
+
blockVersion?: number;
|
|
678
|
+
startedAt?: number;
|
|
679
|
+
completedAt?: number;
|
|
680
|
+
durationMs?: number;
|
|
681
|
+
origin?: ResultOrigin;
|
|
682
|
+
isPublic?: boolean;
|
|
683
|
+
notebookIds?: string[];
|
|
684
|
+
events?: Array<Partial<EventRecord> & {
|
|
685
|
+
id?: string;
|
|
686
|
+
}>;
|
|
687
|
+
}
|
|
688
|
+
interface BuiltTestSession {
|
|
689
|
+
session: Session;
|
|
690
|
+
events: EventRecord[];
|
|
691
|
+
notebookLinks: NotebookLink[];
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Build a Session execution log plus its EventRecord rows, pinned to
|
|
695
|
+
* `noteId`/`blockId`/`blockVersion`. Without an explicit block pin the first
|
|
696
|
+
* wod occurrence (`blk-0`) of a `buildTestNote` note is assumed. Session ids
|
|
697
|
+
* default to `session-${noteId}:1`; pass explicit ids when authoring several
|
|
698
|
+
* sessions against one note outside a `buildDomainWorld` sequence.
|
|
699
|
+
*/
|
|
700
|
+
declare function buildTestSession(input: TestSessionInput): BuiltTestSession;
|
|
701
|
+
interface DomainWorldInput {
|
|
702
|
+
notes?: TestNoteInput[];
|
|
703
|
+
propertyNotes?: TestPropertyNoteInput[];
|
|
704
|
+
sessions?: TestSessionInput[];
|
|
705
|
+
pages?: Page[];
|
|
706
|
+
pageNotes?: PageNote[];
|
|
707
|
+
}
|
|
708
|
+
interface DomainWorld {
|
|
709
|
+
notes: Note[];
|
|
710
|
+
revisions: BlockRevision[];
|
|
711
|
+
blockIndex: BlockIndexRow[];
|
|
712
|
+
blockEfforts: BlockEffort[];
|
|
713
|
+
blockEquipment: BlockEquipment[];
|
|
714
|
+
tags: Tag[];
|
|
715
|
+
noteTags: NoteTag[];
|
|
716
|
+
notebooks: Note[];
|
|
717
|
+
notebookLinks: NotebookLink[];
|
|
718
|
+
propertyOverrides: ScopedPropertyOverride[];
|
|
719
|
+
pages: Page[];
|
|
720
|
+
pageNotes: PageNote[];
|
|
721
|
+
sessions: Session[];
|
|
722
|
+
events: EventRecord[];
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Aggregate a complete deterministic domain snapshot: Notes, Property Notes
|
|
726
|
+
* with their Scoped Property Overrides, notebook landing notes for every
|
|
727
|
+
* referenced notebook, NotebookLinks, pages, sessions and events.
|
|
728
|
+
*
|
|
729
|
+
* Property notes are built FIRST so effort/equipment mentions in note
|
|
730
|
+
* content resolve against their vocabulary; sessions then pin to the first
|
|
731
|
+
* wod block of their note (real block id, version and content fingerprint).
|
|
732
|
+
*/
|
|
733
|
+
declare function buildDomainWorld(input?: DomainWorldInput): DomainWorld;
|
|
734
|
+
|
|
735
|
+
export { type BuiltPropertyNote, type BuiltTestNote, type BuiltTestSession, type DomainWorld, type DomainWorldInput, TEST_EPOCH, type TestNoteInput, type TestPropertyNoteInput, type TestSessionInput, buildDomainWorld, buildPropertyNote, buildTestNote, buildTestSession, resetTestingVocabulary };
|