chore: CLI typegen for Metric Views#459
Open
atilafassina wants to merge 5 commits into
Open
Conversation
Contributor
|
b0ca822 to
bef7429
Compare
Adds an appkit mv sync command that fetches Unity Catalog metric-view schemas and emits metric.d.ts plus metrics.metadata.json outside the Vite dev loop (CI, non-Vite builds, manual refresh). The command lives in shared and reaches appkit's sync core via dynamic import of the type-generator entry with an ambient declaration and a graceful appkit-absent fallback, so shared keeps no static appkit dependency. A new appkit syncMetricViewsTypes export reuses the existing metric writers, adaptive describe fetcher and persistent cache helpers, so the emitted bundle matches the Vite plugin output. Config is validated against metricSourceSchema before sync, an absent default file exits zero for dormancy while error modes exit non-zero with distinct messages, and interactive and non-interactive flows mirror plugin create. Flags are --warehouse-id, --metric-views-json-path, --output-dir and --no-cache. Fourth change in the metric-views decomposition after #427, #429 and #433. Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
…Path "format" describes what the helper does — render a Zod issue path as a CLI string — without the "humanize" framing it borrowed from the plugin-manifest validator's humanizePath. Update its caller, tests, and doc comments to match. Also trim redundant comments in the type-generator .d.ts shim and align the syncMetricViewsTypes doc with the appkit source. Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
`appkit mv sync` runs in describe-now mode, where a not-ready (cold or starting) warehouse can return no schema for a metric view WITHOUT a hard DESCRIBE failure: the appkit export writes permissive (degraded) types and reports them via `schemas[].degraded` with an empty `failures` list. The CLI only inspected `failures`, so this path fell through to the success message and exited 0 with no signal, silently shipping permissive `unknown` types. Add a degraded-schema check after the failures gate: name the affected views, tell the user to rerun once the warehouse is available, and exit 0 — a not-ready warehouse is transient, not a hard failure (genuine DESCRIBE failures still exit non-zero, unchanged). Also align the ambient `@databricks/appkit/type-generator` shim's `SyncMetricViewsTypesResult` with the real export by adding `fatalErrors` (always empty for the CLI's describe-now mode; declared to keep the cross-package contract honest). Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
Rename the generated metric-view artifacts for naming consistency with the `metric-views.json` source config (and to fix the metric/metrics singular-vs- plural split): - METRIC_TYPES_FILE: metric.d.ts -> metric-views.d.ts - METRIC_METADATA_FILE: metrics.metadata.json -> metric-views.metadata.json Touches the constants, the dev/Vite generate path, the ambient type-generator shim, the shared `mv sync` CLI, and all test assertions across appkit + shared. The Metric Views feature is pre-release (not shipped), so no migration is needed. Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new appkit mv sync CLI surface (in packages/shared) that can generate Metric View type artifacts outside the Vite dev loop, backed by a new/expanded syncMetricViewsTypes export in @databricks/appkit/type-generator and a refactor to reuse the same unified metric sync pipeline from both the CLI and generateFromEntryPoint.
Changes:
- Add
appkit mv synccommand with interactive/non-interactive flows, schema validation, dormancy behavior, and cache controls. - Introduce/extend
syncMetricViewsTypesin the appkit type-generator and refactorgenerateFromEntryPointto delegate Metric View emission to it. - Standardize Metric View artifact filenames to
metric-views.d.tsandmetric-views.metadata.json, updating tests accordingly.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/cli/index.ts | Wires the new mv parent command into the shared CLI. |
| packages/shared/src/cli/commands/type-generator.d.ts | Extends the ambient optional @databricks/appkit/type-generator declaration with syncMetricViewsTypes + metric artifact constants. |
| packages/shared/src/cli/commands/metric-views/index.ts | Adds the mv parent command and attaches the sync subcommand. |
| packages/shared/src/cli/commands/metric-views/validate-metric-views-source.ts | Adds Zod-based validation and CLI-friendly formatting for metric-views.json. |
| packages/shared/src/cli/commands/metric-views/validate-metric-views-source.test.ts | Unit tests for metric source validation + formatting. |
| packages/shared/src/cli/commands/metric-views/sync/sync.ts | Implements appkit mv sync (path resolution, dormancy, dynamic import, error taxonomy, interactive prompts). |
| packages/shared/src/cli/commands/metric-views/sync/sync.test.ts | Tests CLI behavior (flag vs interactive, error taxonomy, cache flag propagation). |
| packages/appkit/tsdown.config.ts | Ensures ./type-generator is built as its own entry so dynamic-import consumers see required exports. |
| packages/appkit/src/type-generator/index.ts | Refactors metric emission to a unified syncMetricViewsTypes pipeline and updates exported metric artifact constants. |
| packages/appkit/src/type-generator/mv-registry/render-types.ts | Updates comments to reflect the new artifact filename. |
| packages/appkit/src/type-generator/tests/vite-plugin.test.ts | Updates expected default/custom Metric View artifact filenames. |
| packages/appkit/src/type-generator/tests/index.test.ts | Updates expected Metric View artifact filenames in type-generator tests. |
| packages/appkit/src/type-generator/tests/mv-registry.test.ts | Updates metadata bundle naming references in tests. |
| packages/appkit/src/type-generator/tests/sync-metric-views-types.test.ts | Adds focused unit tests for the new syncMetricViewsTypes export, including cache behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+230
to
+232
| onProgress?.succeed(`Generated metric types: ${metricOutFile}`); | ||
| console.log(`Generated metric types: ${metricOutFile}`); | ||
| console.log(`Generated metric metadata: ${metricMetadataOutFile}`); |
Comment on lines
+271
to
+274
| const cancelled = (): never => { | ||
| cancel("Cancelled."); | ||
| process.exit(1); | ||
| }; |
Comment on lines
762
to
+772
| @@ -710,4 +769,4 @@ export const METRIC_TYPES_FILE = "metric.d.ts"; | |||
| * `registerMetricsMetadata()`, so the React hook returns per-metric `metadata` | |||
| * without a second network round-trip. | |||
| */ | |||
| export const METRIC_METADATA_FILE = "metrics.metadata.json"; | |||
| export const METRIC_METADATA_FILE = "metric-views.metadata.json"; | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
appkit mv syncCLI that runs the metric-view schema-fetch + type-emission outside the Vite dev loop — for CI, non-Vite builds, and manual refresh after pulling a teammate'smetric-views.json.Note
Dormant feature, still not user facing.
Design
The CLI lives in
sharedand reaches appkit's metric-sync core via dynamicimport("@databricks/appkit/type-generator")— the same patterngenerate-typesuses — backed by an ambient declaration and a graceful appkit-absent fallback, sosharedkeeps no static dependency onappkit.A new appkit
syncMetricTypesexport runsreadMetricConfig → resolveMetricConfig → syncMetrics → write metric.d.ts + metrics.metadata.json, reusing the existing metric writers, the adaptive DESCRIBE fetcher, and the post-#433 persistent cache helpers (loadCache/saveCache/metricCacheHash). Because it is the same code path, the emitted bundle is structurally identical to the Vite plugin output. It deliberately does not generate query types or route throughgenerateFromEntryPoint.Behaviour
metricSourceSchema(post-chore: Metric Views typegen #433 UC FQN grammar) before any sync, with issues formatted aspath: message.config/queries/metric-views.jsonexits 0 (dormancy invariant); explicit-missing-path / JSON-parse / schema-validation / missing-FQN / unreachable-warehouse / auth each exit non-zero with a distinct message.@clack/promptsflow (mirrorsplugin create); any flag → non-interactive (detected viagetOptionValueSource() === "cli").--warehouse-id(+DATABRICKS_WAREHOUSE_IDfallback),--metric-views-json-path,--output-dir,--no-cache(→cache: false: ignore + overwrite the metric cache).