@rtkelly-labs/design-system 0.16.0-dev.0.37dedac → 0.17.0
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/CHANGELOG.md +18 -0
- package/dist/components/AlertList.js +246 -0
- package/dist/components/AlertList.js.map +1 -0
- package/dist/components/FilterBar.js +215 -0
- package/dist/components/FilterBar.js.map +1 -0
- package/dist/components/FreshnessIndicator.js +50 -0
- package/dist/components/FreshnessIndicator.js.map +1 -0
- package/dist/components/IdChip.js +58 -0
- package/dist/components/IdChip.js.map +1 -0
- package/dist/components/IncidentTimeline.js +122 -0
- package/dist/components/IncidentTimeline.js.map +1 -0
- package/dist/components/LatencyHeatmap.js +382 -0
- package/dist/components/LatencyHeatmap.js.map +1 -0
- package/dist/components/LatencyHistogram.js +282 -0
- package/dist/components/LatencyHistogram.js.map +1 -0
- package/dist/components/LogViewer.js +393 -0
- package/dist/components/LogViewer.js.map +1 -0
- package/dist/components/ServiceMap.js +404 -0
- package/dist/components/ServiceMap.js.map +1 -0
- package/dist/components/SeverityBadge.js +15 -0
- package/dist/components/SeverityBadge.js.map +1 -0
- package/dist/components/TimeRange.js +89 -0
- package/dist/components/TimeRange.js.map +1 -0
- package/dist/components/TimeSeriesChart.js +507 -0
- package/dist/components/TimeSeriesChart.js.map +1 -0
- package/dist/components/TraceViewer.js +159 -0
- package/dist/components/TraceViewer.js.map +1 -0
- package/dist/components/TraceWaterfall.js +226 -0
- package/dist/components/TraceWaterfall.js.map +1 -0
- package/dist/components/saas/ObservabilityConsole.js +220 -0
- package/dist/components/saas/ObservabilityConsole.js.map +1 -0
- package/dist/components/saas/observabilityData.js +250 -0
- package/dist/components/saas/observabilityData.js.map +1 -0
- package/dist/hooks/useMeasuredWidth.js +22 -0
- package/dist/hooks/useMeasuredWidth.js.map +1 -0
- package/dist/hooks/useTraceClock.js +17 -0
- package/dist/hooks/useTraceClock.js.map +1 -0
- package/dist/hooks/useTraceReplay.js +75 -0
- package/dist/hooks/useTraceReplay.js.map +1 -0
- package/dist/index.d.ts +1562 -1
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/filters.js +130 -0
- package/dist/lib/filters.js.map +1 -0
- package/dist/lib/ids.js +9 -0
- package/dist/lib/ids.js.map +1 -0
- package/dist/lib/latency.js +228 -0
- package/dist/lib/latency.js.map +1 -0
- package/dist/lib/logs.js +78 -0
- package/dist/lib/logs.js.map +1 -0
- package/dist/lib/serviceGraph.js +243 -0
- package/dist/lib/serviceGraph.js.map +1 -0
- package/dist/lib/severity.js +23 -0
- package/dist/lib/severity.js.map +1 -0
- package/dist/lib/timeRange.js +94 -0
- package/dist/lib/timeRange.js.map +1 -0
- package/dist/lib/timeSeries.js +285 -0
- package/dist/lib/timeSeries.js.map +1 -0
- package/dist/lib/trace.js +251 -0
- package/dist/lib/trace.js.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ import { cn } from "./lib/recipe.js";
|
|
|
15
15
|
export { Slugger, childrenToText, slugify } from "./lib/slug.js";
|
|
16
16
|
export { useCopyToClipboard } from "./hooks/useCopyToClipboard.js";
|
|
17
17
|
export { useActiveHeading } from "./hooks/useActiveHeading.js";
|
|
18
|
+
export { useTraceClock } from "./hooks/useTraceClock.js";
|
|
19
|
+
export { useTraceReplay } from "./hooks/useTraceReplay.js";
|
|
18
20
|
export { Button } from "./components/Button.js";
|
|
19
21
|
export { Card } from "./components/Card.js";
|
|
20
22
|
export { Badge } from "./components/Badge.js";
|
|
@@ -83,6 +85,28 @@ export { BarChart, ResponsiveChartContainer } from "./components/BarChart.js";
|
|
|
83
85
|
export { Sparkline } from "./components/Sparkline.js";
|
|
84
86
|
export { ChartTooltip, useChartTooltip } from "./components/ChartTooltip.js";
|
|
85
87
|
export { BulletChart } from "./components/BulletChart.js";
|
|
88
|
+
export { buildTrace, formatTraceDuration, matchTraceSpan, parseOtlpTrace, parseTraceDocument, replayTrace, visibleTraceSpans } from "./lib/trace.js";
|
|
89
|
+
export { TraceWaterfall, describeTraceSpan } from "./components/TraceWaterfall.js";
|
|
90
|
+
export { TraceViewer } from "./components/TraceViewer.js";
|
|
91
|
+
export { TIME_RANGE_PRESETS, bucketTimes, clampToRange, formatClock, formatDay, formatRange, formatRangeDuration, formatTimeTick, formatTimestamp, normaliseRange, presetRange, timeTicks } from "./lib/timeRange.js";
|
|
92
|
+
export { TimeRangePicker, TimeRangeProvider, useTimeCursor, useTimeRange } from "./components/TimeRange.js";
|
|
93
|
+
export { SEVERITY_ACCENTS, severityAccent } from "./lib/severity.js";
|
|
94
|
+
export { SeverityBadge } from "./components/SeverityBadge.js";
|
|
95
|
+
export { TIME_SERIES_VARIANTS, TimeSeriesChart } from "./components/TimeSeriesChart.js";
|
|
96
|
+
export { bucketIndex, bucketPercentile, formatCount, formatLatencyRange, formatRequests, formatShare, heatmapCells, histogram, intensityLevel, intensityThresholds, latencyBuckets, latencyExtent, latencyRowPosition, linearBuckets, logTicks, percentile, percentiles, shareAbove } from "./lib/latency.js";
|
|
97
|
+
export { LATENCY_HISTOGRAM_VARIANTS, LatencyHistogram } from "./components/LatencyHistogram.js";
|
|
98
|
+
export { LATENCY_HEATMAP_VARIANTS, LatencyHeatmap } from "./components/LatencyHeatmap.js";
|
|
99
|
+
export { LOG_SEVERITIES, describeLogEntry, filterLogEntries, highlightLogText, inLogRange, matchLogEntry, nearestLogIndex, sortLogEntries } from "./lib/logs.js";
|
|
100
|
+
export { LogViewer } from "./components/LogViewer.js";
|
|
101
|
+
export { FILTER_OPERATORS, FILTER_OPERATOR_LABELS, FREE_TEXT_KEY, describeFilter, formatFilter, lookupField, matchFilters, parseFilter, sameFilter, tryParseFilter } from "./lib/filters.js";
|
|
102
|
+
export { FilterBar } from "./components/FilterBar.js";
|
|
103
|
+
export { formatServiceCount, formatServiceErrorRate, layoutServiceGraph, serviceEdgeMidpoint, serviceEdgePath, serviceGraph } from "./lib/serviceGraph.js";
|
|
104
|
+
export { ServiceMap } from "./components/ServiceMap.js";
|
|
105
|
+
export { ALERT_STATE_ORDER, AlertList, formatAlertDuration, sortAlerts } from "./components/AlertList.js";
|
|
106
|
+
export { IncidentTimeline, summariseIncident } from "./components/IncidentTimeline.js";
|
|
107
|
+
export { FreshnessIndicator, formatAge } from "./components/FreshnessIndicator.js";
|
|
108
|
+
export { truncateId } from "./lib/ids.js";
|
|
109
|
+
export { IdChip } from "./components/IdChip.js";
|
|
86
110
|
export { Slide } from "./components/slides/Slide.js";
|
|
87
111
|
export { SLIDE_DECK_HOTKEYS, SlideDeck } from "./components/slides/SlideDeck.js";
|
|
88
112
|
export { BlogPost } from "./components/blog/BlogPost.js";
|
|
@@ -93,6 +117,7 @@ export { ColophonCard } from "./components/ColophonCard.js";
|
|
|
93
117
|
export { DEFAULT_EXPERIMENTS, ExperimentsView } from "./components/experiments/ExperimentsView.js";
|
|
94
118
|
export { DesignSandbox } from "./components/experiments/DesignSandbox.js";
|
|
95
119
|
export { DEFAULT_DEPLOY_LOG, DEFAULT_PRICING_TIERS, SaasLandingPage } from "./components/saas/SaasLandingPage.js";
|
|
120
|
+
export { OBSERVABILITY_INCIDENT_WINDOW, ObservabilityConsole } from "./components/saas/ObservabilityConsole.js";
|
|
96
121
|
export { ActivityGrid, AnchorHeading, BeforeAfter, Breadcrumbs, ChangeSummary, CodeBlock, CodeBlockAttachment, CodeTab, CodeTabs, Decision, DocPager, DocsHeader, DocsLayout, DocsLink, DocsLinkProvider, DocsSidebar, DrawingSheet, Event, FigureFrame, FileChangeTree, FlowDiagram, GanttChart, IndexedSection, Line, MetricStrip, Node, Option, Path, Prose, Slope, Step, Steps, SwatchCompare, TableOfContents, Term, TermGrid, Terminal, Timeline, TokenTable, TreeDiagram, UptimeStrip, collectHeadings, createAnchorHeading, mdxComponents, useDocsLinkComponent } from "./components/docs/index.js";
|
|
97
122
|
export {
|
|
98
123
|
ANSI_SLOTS,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// @rtkelly-labs/design-system main entrypoint\n\nexport * from './tokens';\n\n// The theme ladder — the single source for level names, level colours, and the\n// contrast arithmetic that gates them.\nexport * from './theme/levels';\nexport {\n MEDIA,\n CSS_MEDIUM,\n MEDIA_DEFINITIONS,\n isMedium,\n} from './theme/media';\nexport type {\n Medium,\n MediumDefinition,\n TypeStep,\n TypeStepName,\n Motion,\n} from './theme/media';\nexport * from './theme/contrast';\nexport { ANSI_SLOTS, SLOTS, ansiScheme } from './theme/ansi';\nexport type { AnsiSlot, AnsiScheme, AnsiChrome } from './theme/ansi';\n\n// Semantic theming — prefer these over the raw palette in `tokens`.\nexport * from './lib/theme';\nexport * from './theme/recommended';\n// Only `cn` is public. `recipe`'s type comes from the library that implements\n// it, so exporting it would put that library back into the published .d.ts and\n// make replacing it a breaking change. Components import it directly.\nexport { cn } from './lib/recipe';\nexport type { ClassInput } from './lib/recipe';\nexport * from './lib/slug';\n\n// Hooks\nexport * from './hooks/useCopyToClipboard';\nexport * from './hooks/useActiveHeading';\n\n// Primitives & Callouts\nexport * from './components/Button';\nexport * from './components/Card';\nexport * from './components/Badge';\n// The report frame — the page a generated report is built in. Separate from\n// the docs components because a report is written by a tool and read once,\n// where a docs page is written by a person and read often: the frame owns the\n// measure, the header strip and the print behaviour, and everything inside it\n// is ordinary composition.\nexport * from './components/ReportDocument';\n\n// The colour-instead-of-role rules, and the scanner over them. Published\n// because a tool generating markup against this system should be able to hold\n// itself to the same rule the system holds itself to — the report generator\n// lints at budget zero with exactly these.\nexport { TOKEN_RULES, scanRules, scanTokenRules } from './lib/tokenRules';\nexport type { Finding, TokenRule } from './lib/tokenRules';\nexport * from './components/Avatar';\nexport * from './components/PageTitle';\nexport * from './components/PageHeader';\nexport * from './components/Tag';\nexport * from './components/Pagination';\n// The tablist. There is exactly one in this tree: `CodeTabs` renders through\n// it rather than hand-rolling a second keyboard model — see #240, and #163 for\n// why it is first-party rather than a wrapper over Base UI.\nexport * from './components/Tabs';\nexport * from './components/SectionContainer';\nexport * from './components/Divider';\nexport * from './components/AsciiDivider';\nexport * from './components/ThemeProvider';\n// Server-safe: a root layout calls `getThemeInitScript`, and that layout is a\n// server component under the Next App Router. See the module's header.\nexport * from './components/themeInitScript';\nexport * from './components/BracketText';\nexport * from './components/NoteBlock';\nexport * from './components/TLDR';\n// Named rather than `export *`: `Input.tsx` also exports the field recipe\n// `Select` draws its trigger with, and a recipe's type is `tailwind-variants`'.\nexport { Input, TextArea } from './components/Input';\nexport type { InputProps, TextAreaProps } from './components/Input';\n// One of a fixed set (#164): the same field as `Input`, with a listbox this\n// system paints instead of the operating system's, and `native` for the\n// platform picker when that is the better phone experience.\nexport * from './components/Select';\n// The booleans, added together: one capability in two presentations,\n// composing the same Field as the text controls above.\nexport * from './components/Checkbox';\nexport * from './components/Switch';\n// The groups (#239): `Fieldset` and `Legend` are the set's label, description\n// and error on the same Field contract, and `RadioGroup` / `Radio` are the\n// choose-one control built on that frame rather than beside it.\nexport * from './components/Fieldset';\nexport * from './components/RadioGroup';\n// The form-level half of validation (issue 50): the field errors above,\n// gathered at the top of the form as links that move focus to each field.\nexport * from './components/ErrorSummary';\nexport * from './components/Swatch';\nexport * from './components/StatCard';\nexport * from './components/Table';\nexport * from './components/DataTable';\nexport * from './components/Modal';\nexport * from './components/AlertDialog';\nexport * from './components/Drawer';\n\n// The application layout (#247): sidebar, topbar and main as five composable\n// pieces, with the sidebar off-canvas in a `Drawer` below desktop width.\nexport * from './components/AppShell';\n\n// System feedback — the three states an application has besides \"loaded\".\n// One vocabulary on purpose: the same motion tokens, the same reduced-motion\n// rule, the same muted surface, so a loading card and an empty table read as\n// the same system rather than as two consumers' guesses.\nexport * from './components/Spinner';\nexport * from './components/Skeleton';\nexport * from './components/Progress';\nexport * from './components/EmptyState';\n// The page-level states (#251) — 404, 500, maintenance, offline, unauthorized\n// — as `EmptyState` in a page frame, not a component family of their own.\nexport * from './components/StatusPage';\n\n// The floating set (#166): anchored to a trigger, positioned by the same\n// engine, dismissed by the same stack as the dialogs above. `Tooltip` labels,\n// `Popover` shows content, `Menu` offers actions.\nexport * from './components/Tooltip';\nexport * from './components/Popover';\nexport * from './components/Menu';\n\n// Site chrome (issue 246): the banner, the navigation in its two widths, and\n// the footer — layouts and landmarks that hold no items of their own. The\n// link adapter is the package's one, shared with the docs chrome: a router's\n// `Link` and its current-route test are injected once and reach both.\nexport {\n LinkProvider,\n SiteLink,\n isExternalHref,\n useIsCurrentHref,\n useLinkComponent,\n} from './components/LinkProvider';\nexport type {\n LinkComponentProps,\n LinkProviderProps,\n SiteLinkProps,\n} from './components/LinkProvider';\nexport * from './components/SiteHeader';\nexport * from './components/SiteNav';\nexport * from './components/MobileNav';\nexport * from './components/SiteFooter';\n\n// Marketing sections (issue 248): the parts a landing page is composed from.\n// Layouts that hold no copy — `SaasLandingPage` below is one composition of\n// them, and the `SaaS/LandingPage` stories build two more.\nexport * from './components/marketing/Hero';\nexport * from './components/marketing/FeatureGrid';\nexport * from './components/marketing/PricingGrid';\nexport * from './components/marketing/CTASection';\n\n// Transient notifications. Not an overlay: a toast shares neither the\n// positioning nor the dismissal model of Tooltip/Popover/Menu — it is a queue,\n// a live region and a lifetime (#243).\nexport * from './components/Toast';\n\nexport * from './components/NerdIcon';\nexport * from './components/SocialIcon';\nexport * from './components/Glyph';\n\n// Terminal & Monospace Telemetry Primitives\nexport * from './components/AsciiGauge';\nexport * from './components/TelemetryGauge';\nexport * from './components/TickerTape';\n\n// Chart Primitives & Trend Visualizers\nexport * from './components/BarChart';\nexport * from './components/Sparkline';\nexport * from './components/ChartTooltip';\nexport * from './components/BulletChart';\n\n// Slides & Presentation Deck Engine\nexport * from './components/slides/Slide';\nexport * from './components/slides/SlideDeck';\n\n// Blog & Editorial Post Foundations\nexport * from './components/blog/BlogPost';\nexport * from './components/blog/LoremIpsumPost';\nexport * from './components/MetadataGrid';\nexport * from './components/TrackCard';\nexport * from './components/ColophonCard';\n\n// Experiments Page & Design System Sandbox\nexport * from './components/experiments/ExperimentsView';\nexport * from './components/experiments/DesignSandbox';\n\n// SaaS Landing Pages\nexport * from './components/saas/SaasLandingPage';\n\n// Documentation Portal Chrome & MDX Rendering\nexport * from './components/docs';\n"],"mappings":";AAEA,cAAc;AAId,cAAc;AACd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,cAAc;AACd,SAAS,YAAY,OAAO,kBAAkB;AAI9C,cAAc;AACd,cAAc;AAId,SAAS,UAAU;AAEnB,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAMd,cAAc;AAMd,SAAS,aAAa,WAAW,sBAAsB;AAEvD,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,SAAS,OAAO,gBAAgB;AAKhC,cAAc;AAGd,cAAc;AACd,cAAc;AAId,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,cAAc;AAMd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AAMd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// @rtkelly-labs/design-system main entrypoint\n\nexport * from './tokens';\n\n// The theme ladder — the single source for level names, level colours, and the\n// contrast arithmetic that gates them.\nexport * from './theme/levels';\nexport {\n MEDIA,\n CSS_MEDIUM,\n MEDIA_DEFINITIONS,\n isMedium,\n} from './theme/media';\nexport type {\n Medium,\n MediumDefinition,\n TypeStep,\n TypeStepName,\n Motion,\n} from './theme/media';\nexport * from './theme/contrast';\nexport { ANSI_SLOTS, SLOTS, ansiScheme } from './theme/ansi';\nexport type { AnsiSlot, AnsiScheme, AnsiChrome } from './theme/ansi';\n\n// Semantic theming — prefer these over the raw palette in `tokens`.\nexport * from './lib/theme';\nexport * from './theme/recommended';\n// Only `cn` is public. `recipe`'s type comes from the library that implements\n// it, so exporting it would put that library back into the published .d.ts and\n// make replacing it a breaking change. Components import it directly.\nexport { cn } from './lib/recipe';\nexport type { ClassInput } from './lib/recipe';\nexport * from './lib/slug';\n\n// Hooks\nexport * from './hooks/useCopyToClipboard';\nexport * from './hooks/useActiveHeading';\nexport * from './hooks/useTraceClock';\nexport * from './hooks/useTraceReplay';\n\n// Primitives & Callouts\nexport * from './components/Button';\nexport * from './components/Card';\nexport * from './components/Badge';\n// The report frame — the page a generated report is built in. Separate from\n// the docs components because a report is written by a tool and read once,\n// where a docs page is written by a person and read often: the frame owns the\n// measure, the header strip and the print behaviour, and everything inside it\n// is ordinary composition.\nexport * from './components/ReportDocument';\n\n// The colour-instead-of-role rules, and the scanner over them. Published\n// because a tool generating markup against this system should be able to hold\n// itself to the same rule the system holds itself to — the report generator\n// lints at budget zero with exactly these.\nexport { TOKEN_RULES, scanRules, scanTokenRules } from './lib/tokenRules';\nexport type { Finding, TokenRule } from './lib/tokenRules';\nexport * from './components/Avatar';\nexport * from './components/PageTitle';\nexport * from './components/PageHeader';\nexport * from './components/Tag';\nexport * from './components/Pagination';\n// The tablist. There is exactly one in this tree: `CodeTabs` renders through\n// it rather than hand-rolling a second keyboard model — see #240, and #163 for\n// why it is first-party rather than a wrapper over Base UI.\nexport * from './components/Tabs';\nexport * from './components/SectionContainer';\nexport * from './components/Divider';\nexport * from './components/AsciiDivider';\nexport * from './components/ThemeProvider';\n// Server-safe: a root layout calls `getThemeInitScript`, and that layout is a\n// server component under the Next App Router. See the module's header.\nexport * from './components/themeInitScript';\nexport * from './components/BracketText';\nexport * from './components/NoteBlock';\nexport * from './components/TLDR';\n// Named rather than `export *`: `Input.tsx` also exports the field recipe\n// `Select` draws its trigger with, and a recipe's type is `tailwind-variants`'.\nexport { Input, TextArea } from './components/Input';\nexport type { InputProps, TextAreaProps } from './components/Input';\n// One of a fixed set (#164): the same field as `Input`, with a listbox this\n// system paints instead of the operating system's, and `native` for the\n// platform picker when that is the better phone experience.\nexport * from './components/Select';\n// The booleans, added together: one capability in two presentations,\n// composing the same Field as the text controls above.\nexport * from './components/Checkbox';\nexport * from './components/Switch';\n// The groups (#239): `Fieldset` and `Legend` are the set's label, description\n// and error on the same Field contract, and `RadioGroup` / `Radio` are the\n// choose-one control built on that frame rather than beside it.\nexport * from './components/Fieldset';\nexport * from './components/RadioGroup';\n// The form-level half of validation (issue 50): the field errors above,\n// gathered at the top of the form as links that move focus to each field.\nexport * from './components/ErrorSummary';\nexport * from './components/Swatch';\nexport * from './components/StatCard';\nexport * from './components/Table';\nexport * from './components/DataTable';\nexport * from './components/Modal';\nexport * from './components/AlertDialog';\nexport * from './components/Drawer';\n\n// The application layout (#247): sidebar, topbar and main as five composable\n// pieces, with the sidebar off-canvas in a `Drawer` below desktop width.\nexport * from './components/AppShell';\n\n// System feedback — the three states an application has besides \"loaded\".\n// One vocabulary on purpose: the same motion tokens, the same reduced-motion\n// rule, the same muted surface, so a loading card and an empty table read as\n// the same system rather than as two consumers' guesses.\nexport * from './components/Spinner';\nexport * from './components/Skeleton';\nexport * from './components/Progress';\nexport * from './components/EmptyState';\n// The page-level states (#251) — 404, 500, maintenance, offline, unauthorized\n// — as `EmptyState` in a page frame, not a component family of their own.\nexport * from './components/StatusPage';\n\n// The floating set (#166): anchored to a trigger, positioned by the same\n// engine, dismissed by the same stack as the dialogs above. `Tooltip` labels,\n// `Popover` shows content, `Menu` offers actions.\nexport * from './components/Tooltip';\nexport * from './components/Popover';\nexport * from './components/Menu';\n\n// Site chrome (issue 246): the banner, the navigation in its two widths, and\n// the footer — layouts and landmarks that hold no items of their own. The\n// link adapter is the package's one, shared with the docs chrome: a router's\n// `Link` and its current-route test are injected once and reach both.\nexport {\n LinkProvider,\n SiteLink,\n isExternalHref,\n useIsCurrentHref,\n useLinkComponent,\n} from './components/LinkProvider';\nexport type {\n LinkComponentProps,\n LinkProviderProps,\n SiteLinkProps,\n} from './components/LinkProvider';\nexport * from './components/SiteHeader';\nexport * from './components/SiteNav';\nexport * from './components/MobileNav';\nexport * from './components/SiteFooter';\n\n// Marketing sections (issue 248): the parts a landing page is composed from.\n// Layouts that hold no copy — `SaasLandingPage` below is one composition of\n// them, and the `SaaS/LandingPage` stories build two more.\nexport * from './components/marketing/Hero';\nexport * from './components/marketing/FeatureGrid';\nexport * from './components/marketing/PricingGrid';\nexport * from './components/marketing/CTASection';\n\n// Transient notifications. Not an overlay: a toast shares neither the\n// positioning nor the dismissal model of Tooltip/Popover/Menu — it is a queue,\n// a live region and a lifetime (#243).\nexport * from './components/Toast';\n\nexport * from './components/NerdIcon';\nexport * from './components/SocialIcon';\nexport * from './components/Glyph';\n\n// Terminal & Monospace Telemetry Primitives\nexport * from './components/AsciiGauge';\nexport * from './components/TelemetryGauge';\nexport * from './components/TickerTape';\n\n// Chart Primitives & Trend Visualizers\nexport * from './components/BarChart';\nexport * from './components/Sparkline';\nexport * from './components/ChartTooltip';\nexport * from './components/BulletChart';\n// Traces: one React-free model (`lib/trace`) — layout, critical path, OTLP\n// parsing — drawn by the waterfall and the viewer around it.\nexport * from './lib/trace';\nexport * from './components/TraceWaterfall';\nexport * from './components/TraceViewer';\n// Observability (#407): one time window and hover cursor that every view on a\n// page shares, and the views that follow it. Each works standalone too.\nexport * from './lib/timeRange';\nexport * from './components/TimeRange';\nexport * from './lib/severity';\nexport * from './components/SeverityBadge';\nexport * from './components/TimeSeriesChart';\nexport * from './lib/latency';\nexport * from './components/LatencyHistogram';\nexport * from './components/LatencyHeatmap';\nexport * from './lib/logs';\nexport * from './components/LogViewer';\nexport * from './lib/filters';\nexport * from './components/FilterBar';\nexport * from './lib/serviceGraph';\nexport * from './components/ServiceMap';\nexport * from './components/AlertList';\nexport * from './components/IncidentTimeline';\nexport * from './components/FreshnessIndicator';\nexport * from './lib/ids';\nexport * from './components/IdChip';\n\n// Slides & Presentation Deck Engine\nexport * from './components/slides/Slide';\nexport * from './components/slides/SlideDeck';\n\n// Blog & Editorial Post Foundations\nexport * from './components/blog/BlogPost';\nexport * from './components/blog/LoremIpsumPost';\nexport * from './components/MetadataGrid';\nexport * from './components/TrackCard';\nexport * from './components/ColophonCard';\n\n// Experiments Page & Design System Sandbox\nexport * from './components/experiments/ExperimentsView';\nexport * from './components/experiments/DesignSandbox';\n\n// SaaS Landing Pages\nexport * from './components/saas/SaasLandingPage';\nexport * from './components/saas/ObservabilityConsole';\n\n// Documentation Portal Chrome & MDX Rendering\nexport * from './components/docs';\n"],"mappings":";AAEA,cAAc;AAId,cAAc;AACd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,cAAc;AACd,SAAS,YAAY,OAAO,kBAAkB;AAI9C,cAAc;AACd,cAAc;AAId,SAAS,UAAU;AAEnB,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAMd,cAAc;AAMd,SAAS,aAAa,WAAW,sBAAsB;AAEvD,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,SAAS,OAAO,gBAAgB;AAKhC,cAAc;AAGd,cAAc;AACd,cAAc;AAId,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,cAAc;AAMd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AAMd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AAGd,cAAc;","names":[]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/lib/filters.ts
|
|
2
|
+
var FREE_TEXT_KEY = "*";
|
|
3
|
+
var FILTER_OPERATORS = ["!=", "!~", "=", "~"];
|
|
4
|
+
var FILTER_OPERATOR_LABELS = {
|
|
5
|
+
"=": "equals",
|
|
6
|
+
"!=": "does not equal",
|
|
7
|
+
"~": "contains",
|
|
8
|
+
"!~": "does not contain"
|
|
9
|
+
};
|
|
10
|
+
var WHOLE_QUOTED = /^"((?:[^"\\]|\\.)*)"$/;
|
|
11
|
+
function unquote(text) {
|
|
12
|
+
const match = WHOLE_QUOTED.exec(text);
|
|
13
|
+
return match ? match[1].replace(/\\(.)/g, "$1") : text;
|
|
14
|
+
}
|
|
15
|
+
function quote(text) {
|
|
16
|
+
return `"${text.replace(/(["\\])/g, "\\$1")}"`;
|
|
17
|
+
}
|
|
18
|
+
function findOperator(text) {
|
|
19
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
20
|
+
const char = text[index];
|
|
21
|
+
if (char === '"') return null;
|
|
22
|
+
if (char === "!" && (text[index + 1] === "=" || text[index + 1] === "~")) {
|
|
23
|
+
return { index, operator: `!${text[index + 1]}` };
|
|
24
|
+
}
|
|
25
|
+
if (char === "=" || char === "~") return { index, operator: char };
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function tryParseFilter(text) {
|
|
30
|
+
const trimmed = text.trim();
|
|
31
|
+
if (!trimmed) return null;
|
|
32
|
+
if (WHOLE_QUOTED.test(trimmed)) {
|
|
33
|
+
return { ok: true, filter: { key: FREE_TEXT_KEY, operator: "~", value: unquote(trimmed) } };
|
|
34
|
+
}
|
|
35
|
+
const found = findOperator(trimmed);
|
|
36
|
+
if (!found) return { ok: true, filter: { key: FREE_TEXT_KEY, operator: "~", value: trimmed } };
|
|
37
|
+
const key = trimmed.slice(0, found.index).trim();
|
|
38
|
+
const rawValue = trimmed.slice(found.index + found.operator.length).trim();
|
|
39
|
+
if (!key) return { ok: false, error: `Add a field name before ${found.operator}, as in service${found.operator}checkout.` };
|
|
40
|
+
if (/[\s!]/.test(key)) return { ok: false, error: `\u201C${key}\u201D is not a field name. Field names have no spaces; put text in quotes to search for it.` };
|
|
41
|
+
const value = unquote(rawValue);
|
|
42
|
+
if (!rawValue || !value && !WHOLE_QUOTED.test(rawValue)) {
|
|
43
|
+
return { ok: false, error: `Add a value after ${key}${found.operator}.` };
|
|
44
|
+
}
|
|
45
|
+
return { ok: true, filter: { key, operator: found.operator, value } };
|
|
46
|
+
}
|
|
47
|
+
function parseFilter(text) {
|
|
48
|
+
const result = tryParseFilter(text);
|
|
49
|
+
return result?.ok ? result.filter : null;
|
|
50
|
+
}
|
|
51
|
+
function freeTextNeedsQuotes(value) {
|
|
52
|
+
return value === "" || value !== value.trim() || value.startsWith('"') || /[=~]/.test(value);
|
|
53
|
+
}
|
|
54
|
+
function valueNeedsQuotes(value) {
|
|
55
|
+
return value === "" || value !== value.trim() || value.startsWith('"');
|
|
56
|
+
}
|
|
57
|
+
function formatFilter(filter) {
|
|
58
|
+
if (filter.key === FREE_TEXT_KEY && filter.operator === "~") {
|
|
59
|
+
return freeTextNeedsQuotes(filter.value) ? quote(filter.value) : filter.value;
|
|
60
|
+
}
|
|
61
|
+
const value = valueNeedsQuotes(filter.value) ? quote(filter.value) : filter.value;
|
|
62
|
+
return `${filter.key}${filter.operator}${value}`;
|
|
63
|
+
}
|
|
64
|
+
function describeFilter(filter) {
|
|
65
|
+
if (filter.key === FREE_TEXT_KEY && filter.operator === "~") return `\u201C${filter.value}\u201D`;
|
|
66
|
+
return `${filter.key} ${filter.operator} ${filter.value}`;
|
|
67
|
+
}
|
|
68
|
+
function sameFilter(a, b) {
|
|
69
|
+
return a.key === b.key && a.operator === b.operator && a.value === b.value;
|
|
70
|
+
}
|
|
71
|
+
function isRecord(value) {
|
|
72
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
73
|
+
}
|
|
74
|
+
function lookupField(record, key) {
|
|
75
|
+
if (Object.prototype.hasOwnProperty.call(record, key)) return record[key];
|
|
76
|
+
const parts = key.split(".");
|
|
77
|
+
for (let cut = 1; cut < parts.length; cut += 1) {
|
|
78
|
+
const head = parts.slice(0, cut).join(".");
|
|
79
|
+
const next = Object.prototype.hasOwnProperty.call(record, head) ? record[head] : void 0;
|
|
80
|
+
if (isRecord(next)) {
|
|
81
|
+
const found = lookupField(next, parts.slice(cut).join("."));
|
|
82
|
+
if (found !== void 0) return found;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function scalars(value) {
|
|
88
|
+
if (value === null || value === void 0) return [];
|
|
89
|
+
if (Array.isArray(value)) return value.flatMap(scalars);
|
|
90
|
+
if (typeof value === "string") return [value];
|
|
91
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return [String(value)];
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
function everyScalar(value) {
|
|
95
|
+
if (isRecord(value)) return Object.values(value).flatMap(everyScalar);
|
|
96
|
+
if (Array.isArray(value)) return value.flatMap(everyScalar);
|
|
97
|
+
return scalars(value);
|
|
98
|
+
}
|
|
99
|
+
function matchOne(candidates, filter) {
|
|
100
|
+
const needle = filter.value.toLowerCase();
|
|
101
|
+
switch (filter.operator) {
|
|
102
|
+
case "=":
|
|
103
|
+
return candidates.some((candidate) => candidate === filter.value);
|
|
104
|
+
case "!=":
|
|
105
|
+
return !candidates.some((candidate) => candidate === filter.value);
|
|
106
|
+
case "~":
|
|
107
|
+
return candidates.some((candidate) => candidate.toLowerCase().includes(needle));
|
|
108
|
+
case "!~":
|
|
109
|
+
return !candidates.some((candidate) => candidate.toLowerCase().includes(needle));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function matchFilters(record, filters) {
|
|
113
|
+
return filters.every((filter) => {
|
|
114
|
+
const candidates = filter.key === FREE_TEXT_KEY ? everyScalar(record) : scalars(lookupField(record, filter.key));
|
|
115
|
+
return matchOne(candidates, filter);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
FILTER_OPERATORS,
|
|
120
|
+
FILTER_OPERATOR_LABELS,
|
|
121
|
+
FREE_TEXT_KEY,
|
|
122
|
+
describeFilter,
|
|
123
|
+
formatFilter,
|
|
124
|
+
lookupField,
|
|
125
|
+
matchFilters,
|
|
126
|
+
parseFilter,
|
|
127
|
+
sameFilter,
|
|
128
|
+
tryParseFilter
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/filters.ts"],"sourcesContent":["/**\n * Filter expressions for log, span and event lists — `service=checkout`,\n * `status != 500`, `msg~timeout` — parsed, formatted and matched as data.\n *\n * Pure: no React, no clock. `FilterBar` is the editor; this module is what a\n * page uses to apply the result to its records.\n */\n\n/** `=` equals, `!=` does not equal, `~` contains, `!~` does not contain. */\nexport type FilterOperator = '=' | '!=' | '~' | '!~';\n\n/**\n * One condition. Free text — a search across every value — is\n * `{ key: '*', operator: '~', value }`.\n */\nexport interface Filter {\n /** The field name; dots address nested values. `*` means any field. */\n key: string;\n operator: FilterOperator;\n value: string;\n}\n\n/** The key a free-text filter carries. */\nexport const FREE_TEXT_KEY = '*';\n\n/** What `tryParseFilter` returns for non-empty text: a filter, or why there is none. */\nexport type FilterParseResult = { ok: true; filter: Filter } | { ok: false; error: string };\n\n/** Every operator, longest first so `!=` is never read as `!` then `=`. */\nexport const FILTER_OPERATORS: readonly FilterOperator[] = ['!=', '!~', '=', '~'];\n\n/** A word for each operator, for an accessible name or a hint. */\nexport const FILTER_OPERATOR_LABELS: Record<FilterOperator, string> = {\n '=': 'equals',\n '!=': 'does not equal',\n '~': 'contains',\n '!~': 'does not contain',\n};\n\nconst WHOLE_QUOTED = /^\"((?:[^\"\\\\]|\\\\.)*)\"$/;\n\nfunction unquote(text: string): string {\n const match = WHOLE_QUOTED.exec(text);\n return match ? match[1]!.replace(/\\\\(.)/g, '$1') : text;\n}\n\nfunction quote(text: string): string {\n return `\"${text.replace(/([\"\\\\])/g, '\\\\$1')}\"`;\n}\n\n/** The first operator in `text` and where it starts, or null. */\nfunction findOperator(text: string): { index: number; operator: FilterOperator } | null {\n for (let index = 0; index < text.length; index += 1) {\n const char = text[index];\n // A quote before any operator means the text is not `key op value`.\n if (char === '\"') return null;\n if (char === '!' && (text[index + 1] === '=' || text[index + 1] === '~')) {\n return { index, operator: `!${text[index + 1]}` as FilterOperator };\n }\n if (char === '=' || char === '~') return { index, operator: char };\n }\n return null;\n}\n\n/**\n * Parse one expression, saying why when it cannot be one. Returns null for\n * empty or whitespace-only text.\n *\n * - `key op value`, whitespace around the operator ignored: `status != 500`.\n * - A value in double quotes keeps its spaces and may hold `\"` as `\\\"`:\n * `route=\"/v1/orders\"`.\n * - Text with no operator, or text wholly in quotes, is free text.\n * - An operator with nothing before it, or nothing after it, is an error.\n */\nexport function tryParseFilter(text: string): FilterParseResult | null {\n const trimmed = text.trim();\n if (!trimmed) return null;\n if (WHOLE_QUOTED.test(trimmed)) {\n return { ok: true, filter: { key: FREE_TEXT_KEY, operator: '~', value: unquote(trimmed) } };\n }\n const found = findOperator(trimmed);\n if (!found) return { ok: true, filter: { key: FREE_TEXT_KEY, operator: '~', value: trimmed } };\n const key = trimmed.slice(0, found.index).trim();\n const rawValue = trimmed.slice(found.index + found.operator.length).trim();\n if (!key) return { ok: false, error: `Add a field name before ${found.operator}, as in service${found.operator}checkout.` };\n if (/[\\s!]/.test(key)) return { ok: false, error: `“${key}” is not a field name. Field names have no spaces; put text in quotes to search for it.` };\n const value = unquote(rawValue);\n if (!rawValue || (!value && !WHOLE_QUOTED.test(rawValue))) {\n return { ok: false, error: `Add a value after ${key}${found.operator}.` };\n }\n return { ok: true, filter: { key, operator: found.operator, value } };\n}\n\n/**\n * Parse one expression into a filter: `service=checkout`, `status != 500`,\n * `msg~timeout`, `route=\"/v1/orders\"`; plain text becomes free text. Null for\n * empty text and for text that is not a valid expression — `tryParseFilter`\n * says why.\n */\nexport function parseFilter(text: string): Filter | null {\n const result = tryParseFilter(text);\n return result?.ok ? result.filter : null;\n}\n\n/** Whether a free-text value must be quoted to survive a round trip. */\nfunction freeTextNeedsQuotes(value: string): boolean {\n return value === '' || value !== value.trim() || value.startsWith('\"') || /[=~]/.test(value);\n}\n\nfunction valueNeedsQuotes(value: string): boolean {\n return value === '' || value !== value.trim() || value.startsWith('\"');\n}\n\n/**\n * The expression a filter was written as — `service=checkout`, or the bare\n * text for free text. `parseFilter(formatFilter(f))` gives `f` back.\n */\nexport function formatFilter(filter: Filter): string {\n if (filter.key === FREE_TEXT_KEY && filter.operator === '~') {\n return freeTextNeedsQuotes(filter.value) ? quote(filter.value) : filter.value;\n }\n const value = valueNeedsQuotes(filter.value) ? quote(filter.value) : filter.value;\n return `${filter.key}${filter.operator}${value}`;\n}\n\n/**\n * A filter as a reader sees it: `service = checkout`, or `“timeout”` for\n * free text. Used for chip text and accessible names.\n */\nexport function describeFilter(filter: Filter): string {\n if (filter.key === FREE_TEXT_KEY && filter.operator === '~') return `“${filter.value}”`;\n return `${filter.key} ${filter.operator} ${filter.value}`;\n}\n\n/** Whether two filters say the same thing. */\nexport function sameFilter(a: Filter, b: Filter): boolean {\n return a.key === b.key && a.operator === b.operator && a.value === b.value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * The value at `key`: the flat key first (`record['attributes.http.route']`),\n * then the dotted path (`record.attributes.http.route`). A segment may itself\n * contain dots, so each remainder is tried flat before descending.\n */\nexport function lookupField(record: Record<string, unknown>, key: string): unknown {\n if (Object.prototype.hasOwnProperty.call(record, key)) return record[key];\n const parts = key.split('.');\n for (let cut = 1; cut < parts.length; cut += 1) {\n const head = parts.slice(0, cut).join('.');\n const next = Object.prototype.hasOwnProperty.call(record, head) ? record[head] : undefined;\n if (isRecord(next)) {\n const found = lookupField(next, parts.slice(cut).join('.'));\n if (found !== undefined) return found;\n }\n }\n return undefined;\n}\n\n/** The comparable strings a value holds: itself, or each element of an array. */\nfunction scalars(value: unknown): string[] {\n if (value === null || value === undefined) return [];\n if (Array.isArray(value)) return value.flatMap(scalars);\n if (typeof value === 'string') return [value];\n if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return [String(value)];\n return [];\n}\n\n/** Every string, number and boolean anywhere inside a value. */\nfunction everyScalar(value: unknown): string[] {\n if (isRecord(value)) return Object.values(value).flatMap(everyScalar);\n if (Array.isArray(value)) return value.flatMap(everyScalar);\n return scalars(value);\n}\n\nfunction matchOne(candidates: string[], filter: Filter): boolean {\n const needle = filter.value.toLowerCase();\n switch (filter.operator) {\n case '=':\n return candidates.some((candidate) => candidate === filter.value);\n case '!=':\n return !candidates.some((candidate) => candidate === filter.value);\n case '~':\n return candidates.some((candidate) => candidate.toLowerCase().includes(needle));\n case '!~':\n return !candidates.some((candidate) => candidate.toLowerCase().includes(needle));\n }\n}\n\n/**\n * Whether a record satisfies every filter (AND; no filters matches all).\n *\n * - `=` and `!=` compare exactly; `~` and `!~` are case-insensitive substring tests.\n * - Numbers and booleans compare by their string form, so `status=500` works.\n * - An array matches `=`/`~` when any element does; `!=`/`!~` when none does.\n * - A missing field never equals or contains anything, so it passes `!=` and `!~`.\n * - Key `*` searches every string, number and boolean in the record, nested included.\n */\nexport function matchFilters(record: Record<string, unknown>, filters: readonly Filter[]): boolean {\n return filters.every((filter) => {\n const candidates = filter.key === FREE_TEXT_KEY ? everyScalar(record) : scalars(lookupField(record, filter.key));\n return matchOne(candidates, filter);\n });\n}\n"],"mappings":";AAuBO,IAAM,gBAAgB;AAMtB,IAAM,mBAA8C,CAAC,MAAM,MAAM,KAAK,GAAG;AAGzE,IAAM,yBAAyD;AAAA,EACpE,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR;AAEA,IAAM,eAAe;AAErB,SAAS,QAAQ,MAAsB;AACrC,QAAM,QAAQ,aAAa,KAAK,IAAI;AACpC,SAAO,QAAQ,MAAM,CAAC,EAAG,QAAQ,UAAU,IAAI,IAAI;AACrD;AAEA,SAAS,MAAM,MAAsB;AACnC,SAAO,IAAI,KAAK,QAAQ,YAAY,MAAM,CAAC;AAC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AAW,KAAK,CAAC,cAAc,UAAU,YAAY,EAAE,SAAS,MAAM,CAAC;AAAA,IAChF,KAAK;AACH,aAAO,CAAC,WAAW,KAAK,CAAC,cAAc,UAAU,YAAY,EAAE,SAAS,MAAM,CAAC;AAAA,EACnF;AACF;AAWO,SAAS,aAAa,QAAiC,SAAqC;AACjG,SAAO,QAAQ,MAAM,CAAC,WAAW;AAC/B,UAAM,aAAa,OAAO,QAAQ,gBAAgB,YAAY,MAAM,IAAI,QAAQ,YAAY,QAAQ,OAAO,GAAG,CAAC;AAC/G,WAAO,SAAS,YAAY,MAAM;AAAA,EACpC,CAAC;AACH;","names":[]}
|
package/dist/lib/ids.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/ids.ts"],"sourcesContent":["/** The visible part of an id: its first `count` characters and `…`, or all of it. */\nexport function truncateId(value: string, count = 8): string {\n if (count <= 0 || value.length <= count) return value;\n return `${value.slice(0, count)}…`;\n}\n"],"mappings":";AACO,SAAS,WAAW,OAAe,QAAQ,GAAW;AAC3D,MAAI,SAAS,KAAK,MAAM,UAAU,MAAO,QAAO;AAChD,SAAO,GAAG,MAAM,MAAM,GAAG,KAAK,CAAC;AACjC;","names":[]}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// src/lib/latency.ts
|
|
2
|
+
import { formatTraceDuration } from "./trace.js";
|
|
3
|
+
var finite = (value) => typeof value === "number" && Number.isFinite(value);
|
|
4
|
+
function roundSig(value, direction) {
|
|
5
|
+
if (value <= 0) return value;
|
|
6
|
+
const magnitude = 10 ** (Math.floor(Math.log10(value)) - 1);
|
|
7
|
+
const scaled = value / magnitude;
|
|
8
|
+
const rounded = direction === "floor" ? Math.floor(scaled + 1e-9) : direction === "ceil" ? Math.ceil(scaled - 1e-9) : Math.round(scaled);
|
|
9
|
+
return Number((rounded * magnitude).toPrecision(12));
|
|
10
|
+
}
|
|
11
|
+
function latencyBuckets(min, max, count) {
|
|
12
|
+
const n = Math.max(1, Math.floor(finite(count) ? count : 1));
|
|
13
|
+
let hi = finite(max) && max > 0 ? max : 1e3;
|
|
14
|
+
let lo = finite(min) && min > 0 ? min : hi / 1e3;
|
|
15
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
16
|
+
if (hi / lo < 1.0001) {
|
|
17
|
+
lo /= Math.sqrt(10);
|
|
18
|
+
hi *= Math.sqrt(10);
|
|
19
|
+
}
|
|
20
|
+
const ratio = Math.log(hi / lo) / n;
|
|
21
|
+
const raw = Array.from({ length: n + 1 }, (_, index) => index === n ? hi : lo * Math.exp(ratio * index));
|
|
22
|
+
const nice = raw.map((edge, index) => roundSig(edge, index === 0 ? "floor" : index === n ? "ceil" : "round"));
|
|
23
|
+
return nice.every((edge, index) => index === 0 || edge > nice[index - 1]) ? nice : raw;
|
|
24
|
+
}
|
|
25
|
+
function linearBuckets(min, max, count) {
|
|
26
|
+
const n = Math.max(1, Math.floor(finite(count) ? count : 1));
|
|
27
|
+
let lo = finite(min) ? min : 0;
|
|
28
|
+
let hi = finite(max) ? max : lo + 1;
|
|
29
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
30
|
+
if (hi === lo) hi = lo + 1;
|
|
31
|
+
return Array.from({ length: n + 1 }, (_, index) => lo + (hi - lo) * index / n);
|
|
32
|
+
}
|
|
33
|
+
function bucketIndex(value, edges) {
|
|
34
|
+
const last = edges.length - 2;
|
|
35
|
+
if (last < 0) return -1;
|
|
36
|
+
if (value < edges[1]) return 0;
|
|
37
|
+
if (value >= edges[last]) return last;
|
|
38
|
+
let lo = 0;
|
|
39
|
+
let hi = last;
|
|
40
|
+
while (lo < hi) {
|
|
41
|
+
const mid = lo + hi + 1 >> 1;
|
|
42
|
+
if (edges[mid] <= value) lo = mid;
|
|
43
|
+
else hi = mid - 1;
|
|
44
|
+
}
|
|
45
|
+
return lo;
|
|
46
|
+
}
|
|
47
|
+
function histogram(samples, edges) {
|
|
48
|
+
const buckets = [];
|
|
49
|
+
for (let index = 0; index < edges.length - 1; index += 1) buckets.push({ from: edges[index], to: edges[index + 1], count: 0 });
|
|
50
|
+
if (!buckets.length) return buckets;
|
|
51
|
+
for (const sample of samples) {
|
|
52
|
+
if (!finite(sample)) continue;
|
|
53
|
+
buckets[bucketIndex(sample, edges)].count += 1;
|
|
54
|
+
}
|
|
55
|
+
return buckets;
|
|
56
|
+
}
|
|
57
|
+
function sorted(samples) {
|
|
58
|
+
return samples.filter(finite).sort((a, b) => a - b);
|
|
59
|
+
}
|
|
60
|
+
function interpolate(ordered, p) {
|
|
61
|
+
if (!ordered.length || !finite(p)) return Number.NaN;
|
|
62
|
+
const rank = Math.max(0, Math.min(100, p)) / 100 * (ordered.length - 1);
|
|
63
|
+
const below = Math.floor(rank);
|
|
64
|
+
const above = Math.min(ordered.length - 1, below + 1);
|
|
65
|
+
return ordered[below] + (ordered[above] - ordered[below]) * (rank - below);
|
|
66
|
+
}
|
|
67
|
+
function percentile(samples, p) {
|
|
68
|
+
return interpolate(sorted(samples), p);
|
|
69
|
+
}
|
|
70
|
+
function percentiles(samples, ps = [50, 90, 99]) {
|
|
71
|
+
const ordered = sorted(samples);
|
|
72
|
+
return ps.map((p) => interpolate(ordered, p));
|
|
73
|
+
}
|
|
74
|
+
function bucketPercentile(buckets, p) {
|
|
75
|
+
const total = buckets.reduce((sum, bucket) => sum + Math.max(0, bucket.count), 0);
|
|
76
|
+
if (!total || !finite(p)) return Number.NaN;
|
|
77
|
+
const target = Math.max(0, Math.min(100, p)) / 100 * total;
|
|
78
|
+
let seen = 0;
|
|
79
|
+
for (const bucket of buckets) {
|
|
80
|
+
const count = Math.max(0, bucket.count);
|
|
81
|
+
if (count && seen + count >= target) {
|
|
82
|
+
const t = (target - seen) / count;
|
|
83
|
+
return bucket.from > 0 && bucket.to > 0 ? bucket.from * (bucket.to / bucket.from) ** t : bucket.from + (bucket.to - bucket.from) * t;
|
|
84
|
+
}
|
|
85
|
+
seen += count;
|
|
86
|
+
}
|
|
87
|
+
return buckets[buckets.length - 1].to;
|
|
88
|
+
}
|
|
89
|
+
function shareAbove(samples, threshold) {
|
|
90
|
+
let total = 0;
|
|
91
|
+
let over = 0;
|
|
92
|
+
for (const sample of samples) {
|
|
93
|
+
if (!finite(sample)) continue;
|
|
94
|
+
total += 1;
|
|
95
|
+
if (sample > threshold) over += 1;
|
|
96
|
+
}
|
|
97
|
+
return total ? over / total : 0;
|
|
98
|
+
}
|
|
99
|
+
function latencyExtent(values) {
|
|
100
|
+
let min = Number.POSITIVE_INFINITY;
|
|
101
|
+
let max = Number.NEGATIVE_INFINITY;
|
|
102
|
+
for (const value of values) {
|
|
103
|
+
if (!finite(value) || value <= 0) continue;
|
|
104
|
+
if (value < min) min = value;
|
|
105
|
+
if (value > max) max = value;
|
|
106
|
+
}
|
|
107
|
+
return max >= min ? { min, max } : null;
|
|
108
|
+
}
|
|
109
|
+
function logTicks(min, max, target = 6) {
|
|
110
|
+
if (!finite(min) || !finite(max) || min <= 0 || max <= min) return [];
|
|
111
|
+
const steps = [[1, 2, 5], [1, 5], [1], [1]];
|
|
112
|
+
for (let pass = 0; pass < steps.length; pass += 1) {
|
|
113
|
+
const ticks = [];
|
|
114
|
+
const decadeStep = pass === 3 ? 2 : 1;
|
|
115
|
+
for (let decade = Math.floor(Math.log10(min)); decade <= Math.ceil(Math.log10(max)); decade += decadeStep) {
|
|
116
|
+
for (const mantissa of steps[pass]) {
|
|
117
|
+
const tick = Number((mantissa * 10 ** decade).toPrecision(12));
|
|
118
|
+
if (tick >= min * (1 - 1e-9) && tick <= max * (1 + 1e-9)) ticks.push(tick);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (ticks.length <= target || pass === steps.length - 1) return ticks;
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
function heatmapCells(points, timeBuckets, latencyEdges) {
|
|
126
|
+
const columns = timeBuckets.length;
|
|
127
|
+
const rows = Math.max(0, latencyEdges.length - 1);
|
|
128
|
+
const cells = [];
|
|
129
|
+
for (let column = 0; column < columns; column += 1) {
|
|
130
|
+
for (let row = 0; row < rows; row += 1) {
|
|
131
|
+
cells.push({ column, row, timeRange: timeBuckets[column], latencyRange: { from: latencyEdges[row], to: latencyEdges[row + 1] }, count: 0 });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let max = 0;
|
|
135
|
+
let total = 0;
|
|
136
|
+
if (!columns || !rows) return { cells, columns, rows, max, total };
|
|
137
|
+
const first = timeBuckets[0].from;
|
|
138
|
+
const end = timeBuckets[columns - 1].to;
|
|
139
|
+
for (const point of points) {
|
|
140
|
+
if (!point || !finite(point.time) || !finite(point.value)) continue;
|
|
141
|
+
if (point.time < first || point.time > end) continue;
|
|
142
|
+
let lo = 0;
|
|
143
|
+
let hi = columns - 1;
|
|
144
|
+
while (lo < hi) {
|
|
145
|
+
const mid = lo + hi + 1 >> 1;
|
|
146
|
+
if (timeBuckets[mid].from <= point.time) lo = mid;
|
|
147
|
+
else hi = mid - 1;
|
|
148
|
+
}
|
|
149
|
+
const cell = cells[lo * rows + bucketIndex(point.value, latencyEdges)];
|
|
150
|
+
cell.count += 1;
|
|
151
|
+
total += 1;
|
|
152
|
+
if (cell.count > max) max = cell.count;
|
|
153
|
+
}
|
|
154
|
+
return { cells, columns, rows, max, total };
|
|
155
|
+
}
|
|
156
|
+
function intensityThresholds(counts, levels = 6, scale = "sqrt") {
|
|
157
|
+
const n = Math.max(1, Math.floor(levels));
|
|
158
|
+
const nonzero = counts.filter((count) => finite(count) && count > 0).sort((a, b) => a - b);
|
|
159
|
+
if (!nonzero.length) return [];
|
|
160
|
+
const max = nonzero[nonzero.length - 1];
|
|
161
|
+
if (scale === "quantile") {
|
|
162
|
+
return Array.from({ length: n }, (_, index) => nonzero[Math.min(nonzero.length - 1, Math.floor(index / n * nonzero.length))]);
|
|
163
|
+
}
|
|
164
|
+
const lower = (fraction) => {
|
|
165
|
+
if (scale === "linear") return max * fraction;
|
|
166
|
+
if (scale === "log") return (1 + max) ** fraction - 1;
|
|
167
|
+
return max * fraction * fraction;
|
|
168
|
+
};
|
|
169
|
+
return Array.from({ length: n }, (_, index) => Math.max(1, Math.floor(lower(index / n) + 1e-9) + 1));
|
|
170
|
+
}
|
|
171
|
+
function intensityLevel(count, thresholds) {
|
|
172
|
+
if (!finite(count) || count <= 0 || !thresholds.length) return 0;
|
|
173
|
+
let level = 0;
|
|
174
|
+
for (const threshold of thresholds) if (count >= threshold) level += 1;
|
|
175
|
+
return Math.max(1, level);
|
|
176
|
+
}
|
|
177
|
+
function latencyRowPosition(value, edges) {
|
|
178
|
+
const index = bucketIndex(value, edges);
|
|
179
|
+
if (index < 0 || !finite(value)) return Number.NaN;
|
|
180
|
+
const from = edges[index];
|
|
181
|
+
const to = edges[index + 1];
|
|
182
|
+
const fraction = from > 0 && value > 0 ? Math.log(value / from) / Math.log(to / from) : (value - from) / (to - from);
|
|
183
|
+
return Math.max(0, Math.min(edges.length - 1, index + Math.max(0, Math.min(1, fraction))));
|
|
184
|
+
}
|
|
185
|
+
function formatCount(value) {
|
|
186
|
+
if (!finite(value)) return "\u2014";
|
|
187
|
+
const [whole, fraction] = String(Math.round(value * 100) / 100).split(".");
|
|
188
|
+
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
189
|
+
return fraction ? `${grouped}.${fraction}` : grouped;
|
|
190
|
+
}
|
|
191
|
+
function formatShare(share) {
|
|
192
|
+
if (!finite(share)) return "\u2014";
|
|
193
|
+
const percent = share * 100;
|
|
194
|
+
if (percent === 0 || percent === 100) return `${percent}%`;
|
|
195
|
+
if (percent < 0.1) return `${percent.toFixed(2)}%`;
|
|
196
|
+
return `${percent.toFixed(1).replace(/\.0$/, "")}%`;
|
|
197
|
+
}
|
|
198
|
+
function formatLatencyRange(from, to, format = formatTraceDuration) {
|
|
199
|
+
const a = format(from);
|
|
200
|
+
const b = format(to);
|
|
201
|
+
const unitA = /^[\d.]+([a-zµ]+)$/.exec(a)?.[1];
|
|
202
|
+
const unitB = /^[\d.]+([a-zµ]+)$/.exec(b)?.[1];
|
|
203
|
+
return unitA && unitA === unitB ? `${a.slice(0, -unitA.length)}\u2013${b}` : `${a}\u2013${b}`;
|
|
204
|
+
}
|
|
205
|
+
function formatRequests(count) {
|
|
206
|
+
return `${formatCount(count)} ${count === 1 ? "request" : "requests"}`;
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
bucketIndex,
|
|
210
|
+
bucketPercentile,
|
|
211
|
+
formatCount,
|
|
212
|
+
formatLatencyRange,
|
|
213
|
+
formatRequests,
|
|
214
|
+
formatShare,
|
|
215
|
+
heatmapCells,
|
|
216
|
+
histogram,
|
|
217
|
+
intensityLevel,
|
|
218
|
+
intensityThresholds,
|
|
219
|
+
latencyBuckets,
|
|
220
|
+
latencyExtent,
|
|
221
|
+
latencyRowPosition,
|
|
222
|
+
linearBuckets,
|
|
223
|
+
logTicks,
|
|
224
|
+
percentile,
|
|
225
|
+
percentiles,
|
|
226
|
+
shareAbove
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=latency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/latency.ts"],"sourcesContent":["/**\n * Latency distributions: bucket edges that suit them, histograms, percentiles,\n * and the time × latency grid a heatmap draws.\n *\n * ## Why log-spaced buckets\n *\n * Request latency spans orders of magnitude — a cache hit at 2ms and a cold\n * path at 2s on the same endpoint. Equal-width buckets put the whole fast mode\n * in the first bar and spend the rest on the tail; equal *ratio* buckets give\n * every decade the same resolution, which is what a reader comparing 20ms with\n * 200ms wants.\n *\n * ## Percentiles interpolate\n *\n * `percentile` is the linear-interpolation estimate (NumPy's default, R type\n * 7): sort, take the fractional rank `p/100 × (n − 1)`, and interpolate between\n * its neighbours. It never returns a value outside the samples and agrees with\n * nearest-rank at the ends.\n *\n * Everything here is pure: no clock, no randomness.\n */\n\nimport type { TimeRange } from './timeRange';\nimport { formatTraceDuration } from './trace';\n\n/** One histogram bar: samples in `[from, to)` (the last bucket also includes `to`). */\nexport interface LatencyBucket {\n /** Lower edge, in milliseconds. */\n from: number;\n /** Upper edge, in milliseconds. */\n to: number;\n /** Samples in the bucket. */\n count: number;\n}\n\n/** A point in a latency-over-time series. */\nexport interface LatencyPoint {\n /** When the request happened, epoch milliseconds. */\n time: number;\n /** How long it took, in milliseconds. */\n value: number;\n}\n\n/** One cell of a latency heatmap. */\nexport interface LatencyCell {\n /** Time bucket index, 0 at the left. */\n column: number;\n /** Latency bucket index, 0 at the fastest. */\n row: number;\n /** The cell's time window. */\n timeRange: TimeRange;\n /** The cell's latency window, in milliseconds. */\n latencyRange: { from: number; to: number };\n /** Points in the cell. */\n count: number;\n}\n\n/** The cells of a heatmap, column-major (`cells[column * rows + row]`), and their totals. */\nexport interface LatencyGrid {\n cells: LatencyCell[];\n columns: number;\n rows: number;\n /** The busiest cell's count; 0 for an empty grid. */\n max: number;\n /** Points placed in the grid (inside the time buckets). */\n total: number;\n}\n\nconst finite = (value: number) => typeof value === 'number' && Number.isFinite(value);\n\n/** Round to two significant figures, down or up. */\nfunction roundSig(value: number, direction: 'floor' | 'ceil' | 'round'): number {\n if (value <= 0) return value;\n const magnitude = 10 ** (Math.floor(Math.log10(value)) - 1);\n const scaled = value / magnitude;\n // A little tolerance, so 120.00000001 does not round up to 130.\n const rounded = direction === 'floor' ? Math.floor(scaled + 1e-9) : direction === 'ceil' ? Math.ceil(scaled - 1e-9) : Math.round(scaled);\n return Number((rounded * magnitude).toPrecision(12));\n}\n\n/**\n * `count + 1` log-spaced bucket edges from `min` to `max`, in milliseconds.\n * Edges are rounded to two significant figures (so labels read `120–180ms`)\n * unless rounding would merge two of them. A non-positive `min` is lifted to\n * `max / 1000`; an empty span is widened to a decade.\n */\nexport function latencyBuckets(min: number, max: number, count: number): number[] {\n const n = Math.max(1, Math.floor(finite(count) ? count : 1));\n let hi = finite(max) && max > 0 ? max : 1000;\n let lo = finite(min) && min > 0 ? min : hi / 1000;\n if (lo > hi) [lo, hi] = [hi, lo];\n if (hi / lo < 1.0001) { lo /= Math.sqrt(10); hi *= Math.sqrt(10); }\n const ratio = Math.log(hi / lo) / n;\n const raw = Array.from({ length: n + 1 }, (_, index) => (index === n ? hi : lo * Math.exp(ratio * index)));\n const nice = raw.map((edge, index) => roundSig(edge, index === 0 ? 'floor' : index === n ? 'ceil' : 'round'));\n return nice.every((edge, index) => index === 0 || edge > nice[index - 1]!) ? nice : raw;\n}\n\n/** `count + 1` evenly spaced edges from `min` to `max`. */\nexport function linearBuckets(min: number, max: number, count: number): number[] {\n const n = Math.max(1, Math.floor(finite(count) ? count : 1));\n let lo = finite(min) ? min : 0;\n let hi = finite(max) ? max : lo + 1;\n if (lo > hi) [lo, hi] = [hi, lo];\n if (hi === lo) hi = lo + 1;\n return Array.from({ length: n + 1 }, (_, index) => lo + ((hi - lo) * index) / n);\n}\n\n/** The index of the bucket `value` falls in, clamped to the ends. -1 when there are no buckets. */\nexport function bucketIndex(value: number, edges: readonly number[]): number {\n const last = edges.length - 2;\n if (last < 0) return -1;\n if (value < edges[1]!) return 0;\n if (value >= edges[last]!) return last;\n let lo = 0;\n let hi = last;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (edges[mid]! <= value) lo = mid;\n else hi = mid - 1;\n }\n return lo;\n}\n\n/**\n * Count `samples` into the buckets `edges` describe. Values below the first\n * edge land in the first bucket and above the last in the last, so the counts\n * always sum to the finite samples; non-finite samples are skipped.\n */\nexport function histogram(samples: readonly number[], edges: readonly number[]): LatencyBucket[] {\n const buckets: LatencyBucket[] = [];\n for (let index = 0; index < edges.length - 1; index += 1) buckets.push({ from: edges[index]!, to: edges[index + 1]!, count: 0 });\n if (!buckets.length) return buckets;\n for (const sample of samples) {\n if (!finite(sample)) continue;\n buckets[bucketIndex(sample, edges)]!.count += 1;\n }\n return buckets;\n}\n\n/** Finite samples, sorted ascending. */\nfunction sorted(samples: readonly number[]): number[] {\n return samples.filter(finite).sort((a, b) => a - b);\n}\n\nfunction interpolate(ordered: readonly number[], p: number): number {\n if (!ordered.length || !finite(p)) return Number.NaN;\n const rank = (Math.max(0, Math.min(100, p)) / 100) * (ordered.length - 1);\n const below = Math.floor(rank);\n const above = Math.min(ordered.length - 1, below + 1);\n return ordered[below]! + (ordered[above]! - ordered[below]!) * (rank - below);\n}\n\n/**\n * The `p`th percentile (0–100) of `samples`, by linear interpolation between\n * closest ranks. Non-finite samples are ignored; `NaN` when none remain or `p`\n * is not a number.\n */\nexport function percentile(samples: readonly number[], p: number): number {\n return interpolate(sorted(samples), p);\n}\n\n/** Several percentiles at once, sorting once. Same method as `percentile`. */\nexport function percentiles(samples: readonly number[], ps: readonly number[] = [50, 90, 99]): number[] {\n const ordered = sorted(samples);\n return ps.map((p) => interpolate(ordered, p));\n}\n\n/**\n * The `p`th percentile estimated from pre-bucketed counts — for when only a\n * histogram is available. Interpolates linearly inside the bucket the rank\n * falls in (geometrically when both edges are positive, matching log buckets).\n */\nexport function bucketPercentile(buckets: readonly LatencyBucket[], p: number): number {\n const total = buckets.reduce((sum, bucket) => sum + Math.max(0, bucket.count), 0);\n if (!total || !finite(p)) return Number.NaN;\n const target = (Math.max(0, Math.min(100, p)) / 100) * total;\n let seen = 0;\n for (const bucket of buckets) {\n const count = Math.max(0, bucket.count);\n if (count && seen + count >= target) {\n const t = (target - seen) / count;\n return bucket.from > 0 && bucket.to > 0 ? bucket.from * (bucket.to / bucket.from) ** t : bucket.from + (bucket.to - bucket.from) * t;\n }\n seen += count;\n }\n return buckets[buckets.length - 1]!.to;\n}\n\n/** The share (0–1) of finite samples strictly above `threshold`; 0 when there are none. */\nexport function shareAbove(samples: readonly number[], threshold: number): number {\n let total = 0;\n let over = 0;\n for (const sample of samples) {\n if (!finite(sample)) continue;\n total += 1;\n if (sample > threshold) over += 1;\n }\n return total ? over / total : 0;\n}\n\n/** The smallest and largest finite, positive value; null when there is none. */\nexport function latencyExtent(values: Iterable<number>): { min: number; max: number } | null {\n let min = Number.POSITIVE_INFINITY;\n let max = Number.NEGATIVE_INFINITY;\n for (const value of values) {\n if (!finite(value) || value <= 0) continue;\n if (value < min) min = value;\n if (value > max) max = value;\n }\n return max >= min ? { min, max } : null;\n}\n\n/**\n * Ticks for a log axis: 1, 2 and 5 of each decade inside `[min, max]`, thinned\n * to 1 and 5, then to decades, until there are at most `target`.\n */\nexport function logTicks(min: number, max: number, target = 6): number[] {\n if (!finite(min) || !finite(max) || min <= 0 || max <= min) return [];\n const steps = [[1, 2, 5], [1, 5], [1], [1]];\n for (let pass = 0; pass < steps.length; pass += 1) {\n const ticks: number[] = [];\n const decadeStep = pass === 3 ? 2 : 1;\n for (let decade = Math.floor(Math.log10(min)); decade <= Math.ceil(Math.log10(max)); decade += decadeStep) {\n for (const mantissa of steps[pass]!) {\n const tick = Number((mantissa * 10 ** decade).toPrecision(12));\n if (tick >= min * (1 - 1e-9) && tick <= max * (1 + 1e-9)) ticks.push(tick);\n }\n }\n if (ticks.length <= target || pass === steps.length - 1) return ticks;\n }\n return [];\n}\n\n/**\n * Place `points` on a time × latency grid. A point outside every time bucket\n * is dropped (it is outside the window); one outside the latency edges is\n * clamped into the first or last row. Cells are dense — an empty cell is there\n * with `count: 0` — and column-major: `cells[column * rows + row]`.\n */\nexport function heatmapCells(points: readonly LatencyPoint[], timeBuckets: readonly TimeRange[], latencyEdges: readonly number[]): LatencyGrid {\n const columns = timeBuckets.length;\n const rows = Math.max(0, latencyEdges.length - 1);\n const cells: LatencyCell[] = [];\n for (let column = 0; column < columns; column += 1) {\n for (let row = 0; row < rows; row += 1) {\n cells.push({ column, row, timeRange: timeBuckets[column]!, latencyRange: { from: latencyEdges[row]!, to: latencyEdges[row + 1]! }, count: 0 });\n }\n }\n let max = 0;\n let total = 0;\n if (!columns || !rows) return { cells, columns, rows, max, total };\n const first = timeBuckets[0]!.from;\n const end = timeBuckets[columns - 1]!.to;\n for (const point of points) {\n if (!point || !finite(point.time) || !finite(point.value)) continue;\n if (point.time < first || point.time > end) continue;\n let lo = 0;\n let hi = columns - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (timeBuckets[mid]!.from <= point.time) lo = mid;\n else hi = mid - 1;\n }\n const cell = cells[lo * rows + bucketIndex(point.value, latencyEdges)]!;\n cell.count += 1;\n total += 1;\n if (cell.count > max) max = cell.count;\n }\n return { cells, columns, rows, max, total };\n}\n\n/** How a cell's count maps to an intensity step. */\nexport type IntensityScale = 'sqrt' | 'linear' | 'log' | 'quantile';\n\n/**\n * The smallest count in each of `levels` intensity steps — what a legend\n * prints, and what `intensityLevel` reads. Ascending; two steps can share a\n * threshold when counts are small, and the lower one is then never used.\n *\n * - `sqrt` (the heatmap default): latency counts are skewed, and a linear\n * scale would leave the slow mode of a bimodal service invisible.\n * - `linear`: equal count ranges per step.\n * - `log`: equal ratios per step, on `log(1 + count)`.\n * - `quantile`: each step holds about the same number of non-empty cells.\n */\nexport function intensityThresholds(counts: readonly number[], levels = 6, scale: IntensityScale = 'sqrt'): number[] {\n const n = Math.max(1, Math.floor(levels));\n const nonzero = counts.filter((count) => finite(count) && count > 0).sort((a, b) => a - b);\n if (!nonzero.length) return [];\n const max = nonzero[nonzero.length - 1]!;\n if (scale === 'quantile') {\n return Array.from({ length: n }, (_, index) => nonzero[Math.min(nonzero.length - 1, Math.floor((index / n) * nonzero.length))]!);\n }\n const lower = (fraction: number) => {\n if (scale === 'linear') return max * fraction;\n if (scale === 'log') return (1 + max) ** fraction - 1;\n return max * fraction * fraction;\n };\n // The smallest whole count strictly past the step's lower bound.\n return Array.from({ length: n }, (_, index) => Math.max(1, Math.floor(lower(index / n) + 1e-9) + 1));\n}\n\n/** The intensity step (0 for empty, else 1…thresholds.length) a count falls in. */\nexport function intensityLevel(count: number, thresholds: readonly number[]): number {\n if (!finite(count) || count <= 0 || !thresholds.length) return 0;\n let level = 0;\n for (const threshold of thresholds) if (count >= threshold) level += 1;\n return Math.max(1, level);\n}\n\n/**\n * Where a latency sits on log-spaced edges, as a fractional row: 0 at the\n * first edge, `edges.length - 1` at the last, interpolated geometrically\n * inside a bucket and clamped to the ends.\n */\nexport function latencyRowPosition(value: number, edges: readonly number[]): number {\n const index = bucketIndex(value, edges);\n if (index < 0 || !finite(value)) return Number.NaN;\n const from = edges[index]!;\n const to = edges[index + 1]!;\n const fraction = from > 0 && value > 0 ? Math.log(value / from) / Math.log(to / from) : (value - from) / (to - from);\n return Math.max(0, Math.min(edges.length - 1, index + Math.max(0, Math.min(1, fraction))));\n}\n\n/** `1,234` — grouped by hand, so a server render and a browser agree. */\nexport function formatCount(value: number): string {\n if (!finite(value)) return '—';\n const [whole, fraction] = String(Math.round(value * 100) / 100).split('.');\n const grouped = whole!.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\n return fraction ? `${grouped}.${fraction}` : grouped;\n}\n\n/** `3.2%`, `0.04%`, `100%` for a 0–1 share. */\nexport function formatShare(share: number): string {\n if (!finite(share)) return '—';\n const percent = share * 100;\n if (percent === 0 || percent === 100) return `${percent}%`;\n if (percent < 0.1) return `${percent.toFixed(2)}%`;\n return `${percent.toFixed(1).replace(/\\.0$/, '')}%`;\n}\n\n/**\n * `120–180ms`, `850ms–1.2s`: a latency window, with the unit said once when\n * both ends share it. `format` defaults to `formatTraceDuration`.\n */\nexport function formatLatencyRange(from: number, to: number, format: (ms: number) => string = formatTraceDuration): string {\n const a = format(from);\n const b = format(to);\n const unitA = /^[\\d.]+([a-zµ]+)$/.exec(a)?.[1];\n const unitB = /^[\\d.]+([a-zµ]+)$/.exec(b)?.[1];\n return unitA && unitA === unitB ? `${a.slice(0, -unitA.length)}–${b}` : `${a}–${b}`;\n}\n\n/** `1 request`, `342 requests`. */\nexport function formatRequests(count: number): string {\n return `${formatCount(count)} ${count === 1 ? 'request' : 'requests'}`;\n}\n"],"mappings":";AAuBA,SAAS,2BAA2B;AA6CpC,IAAM,SAAS,CAAC,UAAkB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAGpF,SAAS,SAAS,OA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IAAI,YAAY,UAAU;AACtE;","names":[]}
|
package/dist/lib/logs.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/lib/logs.ts
|
|
2
|
+
import { formatTimestamp } from "./timeRange.js";
|
|
3
|
+
var LOG_SEVERITIES = ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
4
|
+
function matchLogEntry(entry, query) {
|
|
5
|
+
const needle = query.trim().toLowerCase();
|
|
6
|
+
if (!needle) return true;
|
|
7
|
+
if (entry.message.toLowerCase().includes(needle)) return true;
|
|
8
|
+
if (entry.service?.toLowerCase().includes(needle)) return true;
|
|
9
|
+
if (entry.traceId?.toLowerCase().includes(needle) || entry.spanId?.toLowerCase().includes(needle)) return true;
|
|
10
|
+
if (!entry.fields) return false;
|
|
11
|
+
return Object.entries(entry.fields).some(
|
|
12
|
+
([key, value]) => `${key}=${String(value)}`.toLowerCase().includes(needle)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
function inLogRange(time, range) {
|
|
16
|
+
const from = Math.min(range.from, range.to);
|
|
17
|
+
const to = Math.max(range.from, range.to);
|
|
18
|
+
return time >= from && time <= to;
|
|
19
|
+
}
|
|
20
|
+
function filterLogEntries(entries, filter = {}) {
|
|
21
|
+
const { query, severities, range } = filter;
|
|
22
|
+
const allowed = severities ? new Set(severities) : null;
|
|
23
|
+
return entries.filter(
|
|
24
|
+
(entry) => (!allowed || allowed.has(entry.severity)) && (!range || inLogRange(entry.time, range)) && (!query || matchLogEntry(entry, query))
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function sortLogEntries(entries, order = "asc") {
|
|
28
|
+
const sign = order === "desc" ? -1 : 1;
|
|
29
|
+
return entries.map((entry, index) => ({ entry, index })).sort((a, b) => (a.entry.time - b.entry.time) * sign || a.index - b.index).map(({ entry }) => entry);
|
|
30
|
+
}
|
|
31
|
+
function highlightLogText(text, query) {
|
|
32
|
+
const needle = query?.trim().toLowerCase();
|
|
33
|
+
if (!needle) return [{ text, match: false }];
|
|
34
|
+
const haystack = text.toLowerCase();
|
|
35
|
+
const parts = [];
|
|
36
|
+
let at = 0;
|
|
37
|
+
for (let hit = haystack.indexOf(needle); hit !== -1; hit = haystack.indexOf(needle, at)) {
|
|
38
|
+
if (hit > at) parts.push({ text: text.slice(at, hit), match: false });
|
|
39
|
+
parts.push({ text: text.slice(hit, hit + needle.length), match: true });
|
|
40
|
+
at = hit + needle.length;
|
|
41
|
+
}
|
|
42
|
+
if (at < text.length) parts.push({ text: text.slice(at), match: false });
|
|
43
|
+
return parts.length ? parts : [{ text, match: false }];
|
|
44
|
+
}
|
|
45
|
+
function nearestLogIndex(entries, time) {
|
|
46
|
+
if (time == null || !Number.isFinite(time) || !entries.length) return null;
|
|
47
|
+
const first = entries[0].time;
|
|
48
|
+
const last = entries[entries.length - 1].time;
|
|
49
|
+
const desc = first > last;
|
|
50
|
+
const lo = Math.min(first, last);
|
|
51
|
+
const hi = Math.max(first, last);
|
|
52
|
+
if (time < lo || time > hi) return null;
|
|
53
|
+
let low = 0;
|
|
54
|
+
let high = entries.length - 1;
|
|
55
|
+
while (low < high) {
|
|
56
|
+
const mid = low + high >> 1;
|
|
57
|
+
const past = desc ? entries[mid].time <= time : entries[mid].time >= time;
|
|
58
|
+
if (past) high = mid;
|
|
59
|
+
else low = mid + 1;
|
|
60
|
+
}
|
|
61
|
+
const prev = low - 1;
|
|
62
|
+
if (prev >= 0 && Math.abs(entries[prev].time - time) <= Math.abs(entries[low].time - time)) return prev;
|
|
63
|
+
return low;
|
|
64
|
+
}
|
|
65
|
+
function describeLogEntry(entry) {
|
|
66
|
+
return [`${formatTimestamp(entry.time, "millisecond")} UTC`, entry.severity.toUpperCase(), entry.service, entry.message].filter(Boolean).join(", ");
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
LOG_SEVERITIES,
|
|
70
|
+
describeLogEntry,
|
|
71
|
+
filterLogEntries,
|
|
72
|
+
highlightLogText,
|
|
73
|
+
inLogRange,
|
|
74
|
+
matchLogEntry,
|
|
75
|
+
nearestLogIndex,
|
|
76
|
+
sortLogEntries
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=logs.js.map
|