Tags: axiomhq/mpl
Tags
feat: host-supplied system parameters in editor + playground (#53) * feat: thread host-supplied system params into the editor + playground The CodeMirror diagnostics and completions sources previously called `compile()` with an empty system-params map, so any host-injected reference like `$__interval` surfaced as an `UndefinedParam` error in the editor and crashed the playground preview. This commit plumbs system-param registrations end-to-end. Rust (wasm bridge) - New `src/wasm/system_params.rs` decodes a `[{ name, type, optional? }]` array from JS, mapping the source-level type spellings (`Dataset`, `Duration`, `Regex`, `string`, `int`, `float`, `bool`) to both `query::ParamType` (diagnostics path) and `ParamItem` (completions path). Unknown spellings are silently dropped so a malformed host registration cannot break the editor. - `diagnostics(query, system_params)` and `completions(query, cursor, system_params)` now thread the decoded params into `compile()` and `compute_completions_with_params()` respectively. Inline `param` declarations still win on name collision. TS package (@axiomhq/mpl-codemirror) - New `mplSystemParams` facet (`Facet<MplSystemParam[]>`) combines multiple providers via `values.flat()` and defaults to `[]`, so every pre-existing consumer is byte-identical without registering anything. - `mplLintSource`, both completion sources, and `mplHover` read the facet and forward it to the wasm bridge. Hover merges system params into the inline-declaration map without overwriting collisions. - Exports added: `mplSystemParams`, `MplSystemParam`, `MplParamType`, plus `mplLintSource` for testability. - `tsconfig.json` path alias maps `@axiomhq/mpl` to the workspace artifact at `packages/mpl/mpl_lang.d.ts`, matching what vite already does at runtime; otherwise tsc resolves to the stale npm-registry copy and fails on the new third argument. Playground - `SYSTEM_PARAMS` in `editor.ts` is the single source of truth: each entry carries name, type, and value. `SYSTEM_PARAM_FACET` strips the value for the language-server registration; `substituteSystemParams` replaces param references with the concrete value before the query reaches the interpreter, which has no binding step of its own. - `main.ts` substitutes on every editor change before `interpreter.run`, so the live preview works for queries containing `$__interval`. - `playground/tsconfig.json` mirrors the mpl-codemirror path alias. Tests - 13 new Rust tests across `system_params`, diagnostics, and completions covering the decode path, type-mismatch behaviour, name collisions, and missing-prefix diagnostics. - 18 new TS tests covering the facet defaulting/composition, the hover merge, the lint source's arg forwarding (with a spy on the wasm bridge), and the playground substitution + end-to-end interpretation. - Total: 489 Rust + 65 mpl-codemirror + 46 playground = 600 tests pass. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Heinz N. Gies <heinz@licenser.net> * feat(playground): render scalar tiles for whole-window aggregates Queries like `align using avg` (no time clause) collapse each series to a single datapoint. The previous renderer drew a 120px-tall uPlot with a synthetic 1-hour x-axis and a single dot in the middle — technically correct, visually wasteful, and harder to read than just the number. When every series in a step has exactly one timestamp, render a row of rounded value tiles instead: a coloured accent chip (palette-matched to the series), the formatted value, and the series name underneath. Tiles wrap horizontally so multi-series scalars stay on one row at typical widths. - `isScalarEntry(entry)` detects the trigger condition. Mixed-shape steps and empty/no-data series fall through to the existing chart and empty paths. - `formatScalar(v)` keeps the tile width bounded: integers render bare, fractional values to two decimals, very large/small magnitudes in scientific notation, and NaN/Infinity pass through verbatim. - 9 new tests pin both helpers' contracts so regressions either hide multi-point series behind a tile (false positive) or waste a chart on a single dot (false negative) become visible immediately. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Heinz N. Gies <heinz@licenser.net> * fix(playground): distribute scalar tiles evenly across the row Flex + flex-wrap left-aligned the tiles, leaving an empty gutter on the right of the last row \u2014 ugly when one or two tiles ended up stranded next to whitespace. Switch to a CSS grid with `repeat(auto-fit, minmax(120px, 1fr))`: every tile in a row gets an equal share of the available width, rows only wrap when the next tile would shrink below the minimum. Dropped the per-tile max-width and tightened min-width to 0 so the grid cell controls sizing and the label ellipsis still works. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Heinz N. Gies <heinz@licenser.net> * fix(playground): align rate + group by works at window-cadence Reported by the user: this query crashed the playground preview with "No valid points at column 1 for Sum": `dev.metrics`:http_requests_total | filter path == #/.../ | filter code == #/[123]../ | align to $__interval using prom::rate | group by method, path, code using sum Two pre-existing bugs in the playground interpreter chained together to produce the failure. 1) `align using rate` used a leading window `[t, t + W)`. With source samples spaced ~W apart (a 1-minute counter sampled every minute), each bucket contained 0 or 1 samples, so every step produced NaN after the first off-by-one boundary case. Switched to a Prometheus- style trailing window with a 2*W lookback, dividing the total increase by the actual sample span (not the lookback) so the rate stays correct regardless of the lookback width. First column is NaN because there is no prior sample to compare against — same semantics Prometheus emits for the leading edge of a range query. 2) `aggregate_columns` bailed the whole step when any column had only NaN values across the input series. Real query engines render missing data as gaps; the playground used to error out. Now sum, avg, min, and max emit NaN at an all-NaN column, and count emits 0 (a literal count of non-NaN samples). The existing `align_rate` test asserted the old leading-window behaviour at column 0. Updated to match the trailing semantics: col 0 is NaN, a later column carries the rate. Tests - 3 new Rust unit tests pin the corrected rate window at window cadence, the sum tolerance for all-NaN columns, and the count=0 behaviour for the same case. - 1 new playground integration test reproduces the user's exact query end-to-end against the rebuilt WASM, asserting every step succeeds and the final grouped series carries finite values. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Heinz N. Gies <heinz@licenser.net> * 0.5.3 Bump patch version across Cargo + npm manifests. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Heinz N. Gies <heinz@licenser.net> --------- Signed-off-by: Heinz N. Gies <heinz@licenser.net> Co-authored-by: Claude <noreply@anthropic.com>
enhance: allow align, bucket to omit time (#48) * enhance: allow align, bucket to omit time Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> * add adr Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> * playground: add whole window align/bucket Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> * playground: adjust range for single point series chart Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> * rabbithole: skip duplicated declaration check for system param Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> * chore: update mplc Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> * rel 0.5.1 Signed-off-by: Seoyoung Lee <seoyoung@axiom.co> --------- Signed-off-by: Seoyoung Lee <seoyoung@axiom.co>
PreviousNext