@finos/legend-cube-builder

中文文档
0.0.14发布于 2026/11/12Apache-2.0TypeScriptES Module近 30 天下载 2695

Legend Cube builder: the canvas UI and the Legend engine adapter of the Legend Cube query builder

原始使用文档
文档目录5 节
  1. Layout
  2. Public API
  3. Sources
  4. Samples and examples
  5. Documentation

@finos/legend-cube-builder

The UI and the Legend engine adapter of Legend Cube, a canvas-based visual query builder. The domain model lives in the host-free @finos/legend-cube.

It holds the page (the canvas, the palette, the side-panel editors, the source picker and the results grid), its MobX stores, the engine port with its v1/ adapter, and the bundled model catalog. Legend Analytics hosts the page at /analytics/, and Legend Studio opens it from an ingest definition's editor (see hosting).

Status: work in progress, version 0.0.x. This version has relational tables (from a model or a direct connection to H2 or DuckDB), the access points of deployed data products and the data sets of deployed ingest definitions (both beta), Join, Sort, Group, Pivot (on the databases that run it), Filter, Restrict, Rename, Distinct, Drop, Limit, Slice, Concat, Compare Column Values (Difference), window functions (Apply Window Functions), computed columns (Extend Columns, whose expressions the engine checks) and rows kept by a Pure condition (Filter by Expression, which the engine checks too), with one model, one runtime and one database, data product project or producer deployment per query. A cube is kept only through Export and Import of its spec, marked "(dev)", until the Cube store exists. A pasted model is kept in the cube. The results grid works server-side by default: a header's sort and each drill-down level run on the engine, from the run on screen; local mode groups, pivots and filters the run's rows in the browser. The grid exports the whole query as CSV through the engine and the rows shown as Excel, lists the latest runs with their SQL, and formats number columns (a number, an ISO currency or a percent). Nothing links to the page yet, there is no redo, and Cube sends no telemetry.

Layout

FolderHolds
src/components/the page, CubeEditor, and its parts: canvas/, palette/, editors/, source-picker/, grid/, show-pure/, spec-transfer/
src/stores/the MobX state of the page, its parts and the node editor; editors/ (node drafts); LocalModelCatalog and fixtures/ (the bundled model); CubeHost
src/graph-manager/the engine port (CubeEngine.ts), the connection explorer, data product catalog and ingest catalog ports, and their builders
src/graph-manager/protocol/pure/v1/the engine adapter, V1_LegendCubeEngine: the lambda serializer, the result and relation-type readers, the error mapping
src/__lib__/labels, help text, the command config and test ids
src/__test-utils__/the fake engine and the helpers of the tests
style/the stylesheet, built to lib/index.css

It depends on @finos/legend-cube, legend-graph, legend-application, legend-art, legend-lego, legend-shared, and the depot, lakehouse and storage clients, never on an application package (legend-application-*) or on legend-query-builder.

The V1 rule: V1_* protocol code lives under src/graph-manager/protocol/pure/v1/. The one product file outside it that names V1_* is the seam src/graph-manager/protocol/pure/CubeEngineBuilder.ts: buildCubeEngine is the only product code that makes a V1_LegendCubeEngine, so hosts never name a V1_* symbol. The repo's enforce-module-import-hierarchy lint rule forbids imports between stores/ or components/ and v1/, both ways. The engine-backed tests in src/__tests__/ are an exception: they need both the adapter and stores/.

Public API

src/index.ts exports:

  • CubeEditor, the page, and CubeHost, what a host gives it; CubeEntrySource, a source a link asks the page to start with (initialSource), and formatCubeAccessPointEntryId with its CubeAccessPointEntry, which write a data product access point's link id (hosting.md);
  • the engine port, everything in CubeEngine.ts (CubeEngine, CubeEngineError, CubeEngineErrorKind, CubeResult, CubeModelOutline, …), with buildCubeEngine and CubeEngineConfig;
  • the connection explorer port, everything in CubeConnectionExplorer.ts, with buildCubeConnectionExplorer;
  • data products: everything in CubeDataProduct.ts (the model kind, its runtime path, the environment types, the warehouse rule) and CubeDataProductCatalog.ts (the catalog port and its classes), with buildCubeDataProductCatalog, buildCubeLakehouseEnvironment, CubeLakehouseServices, CubeLakehouseEnvironment and getCubeRememberedWarehouse;
  • ingest data sets: everything in CubeIngest.ts (the model kind, its runtime path, the saved settings) and CubeIngestCatalog.ts (the catalog port and its classes), with buildCubeIngestCatalog;
  • published projects: everything in CubeProject.ts (the pointer model and its checks) and CubeProjectCatalog.ts (the catalog port), with buildCubeProjectCatalog;
  • LocalModelCatalog and BUNDLED_MODELS;
  • LEGEND_CUBE_COMMAND_CONFIG and LEGEND_CUBE_COMMAND_KEY, the page's shortcuts;
  • LEGEND_CUBE_TEST_ID;
  • helpers that 0.0.2 published and nothing outside the package uses yet: getRuntimesForDatabase, createTextModel, BundledModel, and the bundled model's CUBE_NORTHWIND_MODEL, CUBE_NORTHWIND_DATABASE and CUBE_NORTHWIND_RUNTIME.

The node-type registries (drafts, editors, help text and icons) are internal: there is no plugin API for node types yet.

Sources

A cube reads one kind of source: relational tables (from a model, or from a database through a direct connection), the access points of deployed data products, or the data sets of deployed ingest definitions (both beta; PLAN §6.7, §6.8). The "Add a source" dialog has a tab per way to find a source, each implementing CubeSourcePickerTab (src/stores/source-picker/): Model, Database connection, Data product and Ingest. A host offers the last three by giving the page a connectionExplorer, a dataProductCatalog and an ingestCatalog (see hosting).

A new kind of source needs, in the core, a SourceDefinition (node, codec, emitter and its query rules) and, in the builder, a tab, a Source panel editor, help text and an icon, and its branch in the engine's implementation, which builds the model each call runs on from the cube's saved model kind (src/graph-manager/CubeDirectConnection.ts, CubeDataProduct.ts and CubeIngest.ts are the examples).

Tables of a published project's Databases come through the Project Database tab (PLAN §6.3), which extends the Sample Data tab: the cube saves the engine's pointer to the project at a released version, and the host's projectCatalog lists projects, versions and outlines from its depot.

Samples and examples

The Sample Data tab bundles three datasets: Northwind (without Cube's test tables) and two made-up, seeded samples, Sports and Trades (src/stores/fixtures/), each an in-memory H2 database filled by its setup SQL. The Examples dialog (the header's Examples button) opens one of seven example cubes over them (src/stores/CubeExamples.ts) in place of the cube, then runs it, or starts a new cube on a dataset (PLAN §6.9). An example is built in code, so a new one needs no saved spec; add it to CUBE_EXAMPLES, and the engine test CubeExamples.engine-roundtrip-test.ts opens, types and runs it.

Documentation

版本与发布记录

@finos/legend-cube-builder 共发布 14 个版本,首次发布于 2026/10/08;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.0.14latest2026/11/122 天前
0.0.132026/11/113 天前
0.0.122026/11/104 天前
0.0.112026/11/095 天前
0.0.102026/11/0212 天前
0.0.92026/10/2619 天前

关于 @finos/legend-cube-builder 的常见问题

@finos/legend-cube-builder 是什么?

Legend Cube builder: the canvas UI and the Legend engine adapter of the Legend Cube query builder

如何安装 @finos/legend-cube-builder?

在项目目录运行 npm install @finos/legend-cube-builder,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@finos/legend-cube-builder 支持 TypeScript 吗?

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

@finos/legend-cube-builder 支持 ESM 还是 CommonJS?

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

@finos/legend-cube-builder 可以商用吗?

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

@finos/legend-cube-builder 的下载量有多少?

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

@finos/legend-cube-builder 还在维护吗?

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