feat(shared): appkit metric sync CLI#459
Draft
atilafassina wants to merge 1 commit into
Draft
Conversation
Contributor
|
5865783 to
b0ca822
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>
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.
Summary
PR4 of the metric-views decomposition: a focused
appkit metric 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.Design — reuse via dynamic import (not reimplementation)
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).Chain position
Fourth change in the metric-views decomposition, after #427 / #429 / #433. It is the second producer of
shared/appkit-types/metrics.metadata.json(the Vite typegen path is the other); PR2 — next in the merge order — runtime-consumes that bundle, so its closed-mode validation now reviews against two real producers rather than synthetic fixtures.Scope
9 files, +1943 / −0. Confined to
packages/appkit/src/type-generator/**(the metric-only export + tests) andpackages/shared/src/cli/commands/metric/**(+ the ambient decl and thecli/index.tsregistration). Noschemas/**,docs/static/schemas/, or dependency changes — themetric.json→metric-views.jsondoc-fix already landed in #433.Tests
syncMetricTypes— mock-fetcher unit tests (mixed SP/OBO fixtures, cache hit/miss,--no-cachere-describe).--no-cachepropagation.pnpm build && pnpm docs:build,pnpm check:fix && pnpm -r typecheck,pnpm test.This pull request and its description were written by Isaac.
This PR was created with GitHub MCP.