@devicechain/dashboards

中文文档
1.4.0发布于 2026/11/12Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 4935

DeviceChain dashboard runtime — the DashboardHub (telemetry subscription multiplexing over the client wire, plus the alarm, command and location channels) and the dashboard-definition, selector, slot, and binding-manifest types.

原始使用文档
文档目录10 节
  1. The hub
  2. The definition contract
  3. Layout
  4. Time range and density
  5. Slots
  6. Synthetic data
  7. Command status
  8. Upgrading from 0.21
  9. Compatibility
  10. License

@devicechain/dashboards

The DeviceChain dashboard runtime: the DashboardHub, which multiplexes live telemetry, alarms, commands and locations over the client wire, and the typed dashboard-definition contract that describes a board.

No React, no rendering. This is the layer under a widget set — the DeviceChain console and the standalone /dash viewer both sit on it, and so can yours. @devicechain/widgets is the React widget set built on this package.

npm install @devicechain/dashboards @devicechain/client graphql

@devicechain/client and graphql are peer dependencies. Peers rather than ordinary dependencies on purpose: the hub classifies stream errors with instanceof against the SDK's error type, and instanceof is false across two copies of the same package — a duplicate would turn "you may not view this device" into what reads like an outage.

The hub

One hub serves a whole board. Widgets subscribe to it; it does the deduplication.

import { DashboardHub, resolveWidgetDatasource } from '@devicechain/dashboards';

const hub = new DashboardHub({
  resolver,                 // how a selector becomes device tokens
  authorities: user.scopes, // what this viewer may do; drives hub.can(...)
});

// The hub holds no slot bindings: resolve a widget's `slot` selector through them
// first. A slot with no binding resolves to an explicit `unbound` selector, which the
// hub answers with no data; a raw `slot` selector is an error.
// It is undefined only for a widget that declares no datasource at all.
const datasource = resolveWidgetDatasource(widget.datasource, bindings);
const stop = datasource && hub.subscribeWidget(datasource, {
  next: (sample) => setLatest(sample),
});

// later
stop?.();
hub.disposeAll();

Ten widgets pointed at the same device open one upstream subscription, not ten. Each widget declares the measurement names it cares about (none means all), and the hub fans a single stream out to the subscribers that asked for each name.

Each channel has its own method, and each subscription returns its disposer:

methodwhat it carries
subscribeWidgetmeasurement samples for a datasource selector
subscribeMembersa fleet widget's members, then each member's samples tagged with its device
bucketMeasurementsthe time buckets (count, minimum, maximum, sum) a stat widget folds into one figure
subscribeAlarmslive alarm rows, plus acknowledgeAlarm / clearAlarm
subscribeCommandscommand rows and their delivery status, plus sendCommand
subscribeLocationsposition series for map widgets

The widget layer depends on the WidgetDataSource interface, not on the hub class, so a host can feed it from the hub, from SyntheticDataSource or from a recorded run (RecordedDataSource). subscribeMembers, bucketMeasurements and readMemberSeeds are optional on that interface: a source without them leaves the widgets that need them saying so instead of showing a number.

disposeAll() tears down every open channel — a host calls it when the board closes, which is what keeps a poll and a socket from outliving the page.

The definition contract

A dashboard is JSON. The server stores it opaquely; this package is what gives it a shape.

import { parseDashboardDefinition, serializeDefinition } from '@devicechain/dashboards';

const board = parseDashboardDefinition(json); // throws DashboardDefinitionError

A board saved by a newer release than this package is refused rather than read as the current format: the DashboardDefinitionError carries code: 'schemaTooNew' and the version it found in found. Test code, not instanceof, so the check still holds when an application ends up with two copies of the package.

Parsing is validating: a malformed board fails here, in your code, rather than half-rendering later. A board stored in an older format is converted as it is parsed, and the result carries a convertedFrom mark until it is saved again (withoutConversionMark drops it). isDirty compares a working copy against its saved original.

Layout

A board lays out on a grid of square cells. Each widget has a WidgetLayout: a Placement per breakpoint, with base required. A placement is either a grid footprint (GridPlacement, measured in cells) or a position relative to another widget (RelativePlacement). The column count follows the container, so the same board reads on a phone and on a wall display.

needexports
the placement a widget shows at a widthactiveBreakpoint, resolvePlacement
what a renderer draws for a container widtheffectiveLayout, layoutShape, liveColumns
pixel boxes for every widgetlayoutRects, gridRect, relativeRect, cellSizeAt
grid lengths and the widget framegridLengthPx, gutterPx, paddingPx, resolveFrame
placement against what each widget can showlintLayout, blockingLayoutFindings

The editor-model transforms are pure functions an authoring UI can wire to drag and resize: addWidget, moveWidget, resizeWidget, setWidgetPlacement, placeOnGrid, placeRelative, deleteWidget, setTitle, setCanvasGrid, setCanvasDensity and updateWidget, with gridPlacementToPx and pxToGridPlacement to convert between cells and pixels. Moving or resizing a grid widget pushes whatever it now covers out of its way. Grid widgets never overlap, so there is no stacking order to manage.

Time range and density

A board has a time range: TIME_RANGE_PRESETS (15 minutes to 7 days), initialTimeRange, pauseRange / resumeRange and rangeWindow manage it, and timeRangeLinkFromSearch reads the range, paused and from / to URL parameters (timeRangeFromSearch reads only range and paused, for a host that knows no fixed window). A fixed from-to window is an additive variant of the same state: absoluteRange builds it and TimeRangeState.absolute marks it, while paused, pausedAt and spanSeconds still describe the window as a frozen rolling range, so code that only knows rolling ranges keeps working. Its density (CANVAS_DENSITIES: compact, comfortable, wall) scales every text and spacing size by DENSITY_SCALE; a host may override the board's own value at view time.

Slots

A board can be written once and pointed at many entities. A widget's datasource may name a slot instead of a device, and the host supplies a binding for that slot at view time — effectiveBindings, resolveContextBindings, applySelection and resolveSlotCandidates are the machinery.

The hub holds no bindings. A slot is resolved to a concrete selector before it is subscribed — resolveWidgetDatasource(datasource, bindings), which the DashboardRenderer in @devicechain/widgets calls for every widget — so one hub serves a board for its whole life, and re-pointing a slot re-subscribes only the widgets bound to it. A slot with no binding resolves to { kind: 'unbound' }, which every channel treats as zero devices; it is never turned into an absent datasource, which the alarm channel reads as tenant-wide. A raw slot selector handed straight to the hub is an error.

Synthetic data

SyntheticDataSource implements the same interface as the hub and generates plausible measurements, so a board can be previewed, screenshotted or demonstrated with no instance behind it.

Command status

isTerminalCommandStatus and isCancellableCommandStatus are the two questions worth asking about a command, and they are different questions — a SENT command is still in flight but is no longer cancellable. The underlying sets are deliberately not exported: every surface asks the predicate, so a new status cannot be learned by some call sites and not others.

Upgrading from 0.21

0.22 replaces the layout model, so code written against 0.21 needs changes:

0.210.22
WidgetBoxPlacement (GridPlacement or RelativePlacement)
resolveWidgetBoxresolvePlacement
baseBoxbasePlacement
setWidgetBoxsetWidgetPlacement, or moveWidget / resizeWidget
gridBoxToPx / pxToGridBoxgridPlacementToPx / pxToGridPlacement
bringToFrontremoved: grid widgets cannot overlap, so there is no stacking order

These keep their names but change type:

  • WidgetLayout maps a breakpoint to a Placement, and Breakpoints maps a name to a BreakpointSpec.
  • CanvasGrid replaces gap and rowHeight with minCellSize, gutter and padding; GridGeometry replaces its column and row sizes with cell and gutter.
  • SYNTHETIC_GENERATORS is a list of generator ids ('sine', 'ramp', 'random-walk') instead of { value, label } pairs. Supply your own labels; the stored ids are unchanged.
  • parseDashboardDefinition refuses a definition whose grid widgets overlap. A definition in an older format is converted before that check.

Some unions gained members, which breaks an exhaustive switch over them: WidgetChannel has 'aggregate' (the stat card), OptionSpec has ListOptionSpec, and WidgetType, WidgetId and BuiltinWidgetId have the new built-in widgets.

The release's upgrade guide covers what changes for stored boards and for the other packages: If you build against the npm packages.

Compatibility

ESM only, built for bundler resolution (Vite, webpack, Rollup, esbuild). The emitted declarations use extensionless specifiers, which resolve under TypeScript's bundler module resolution and not under node16/nodenext.

License

Apache-2.0. See LICENSE.

版本与发布记录

@devicechain/dashboards 共发布 48 个版本,首次发布于 2026/09/02;过去 12 个月发布了 48 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.4.0latest2026/11/12今天
1.4.0-rc.2next2026/11/11今天
1.4.0-rc.12026/11/111 天前
1.3.02026/11/092 天前
1.3.0-rc.12026/11/092 天前
1.2.02026/11/083 天前

关于 @devicechain/dashboards 的常见问题

@devicechain/dashboards 是什么?

DeviceChain dashboard runtime — the DashboardHub (telemetry subscription multiplexing over the client wire, plus the alarm, command and location channels) and the dashboard-definition, selector, slot, and binding-manifest types.

如何安装 @devicechain/dashboards?

在项目目录运行 npm install @devicechain/dashboards,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:graphql(^16.0.0 || ^17.0.0)、@devicechain/client(1.4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@devicechain/dashboards 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devicechain/dashboards 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@devicechain/dashboards 可以商用吗?

@devicechain/dashboards 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@devicechain/dashboards 的下载量有多少?

根据 npm 官方下载统计,@devicechain/dashboards 在 2026/10/12 – 2026/11/10 这 30 天内被下载 4,935 次,日均约 165 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devicechain/dashboards 还在维护吗?

最新版本 1.4.0 发布于 2026/11/12(今天);至今共发布 48 个版本,其中过去 12 个月发布了 48 个;首次发布于 2026/09/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。