derive-dashboards 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +90 -2
- package/dist/adapter/sql-adapter.mjs +80 -0
- package/dist/adapter/statement.mjs +140 -0
- package/dist/authorize.mjs +55 -0
- package/dist/body.mjs +164 -0
- package/dist/bounded.mjs +31 -0
- package/dist/cache.d.mts +21 -0
- package/dist/cache.mjs +138 -0
- package/dist/checks.mjs +98 -0
- package/dist/cli/bin.d.mts +1 -0
- package/dist/cli/bin.mjs +13 -0
- package/dist/cli/check.mjs +52 -0
- package/dist/cli/cli.d.mts +5 -0
- package/dist/cli/cli.mjs +144 -0
- package/dist/cli/config.d.mts +21 -0
- package/dist/cli/config.mjs +14 -0
- package/dist/cli/conformance.mjs +34 -0
- package/dist/cli/import/build.mjs +118 -0
- package/dist/cli/import/catalog.mjs +42 -0
- package/dist/cli/import/cube-schema.mjs +51 -0
- package/dist/cli/import/cube-sql.mjs +52 -0
- package/dist/cli/import/cube.mjs +172 -0
- package/dist/cli/import/dbt-metrics.mjs +76 -0
- package/dist/cli/import/dbt-schema.mjs +82 -0
- package/dist/cli/import/dbt.mjs +154 -0
- package/dist/cli/import/draft.mjs +46 -0
- package/dist/cli/import/index.mjs +71 -0
- package/dist/cli/import/storage.mjs +92 -0
- package/dist/cli/import/tenancy.mjs +76 -0
- package/dist/cli/index.d.mts +6 -0
- package/dist/cli/index.mjs +5 -0
- package/dist/cli/init.mjs +72 -0
- package/dist/cli/io.d.mts +6 -0
- package/dist/cli/load.mjs +18 -0
- package/dist/cli/propose.d.mts +13 -0
- package/dist/cli/propose.mjs +215 -0
- package/dist/cli/render.d.mts +14 -0
- package/dist/cli/render.mjs +106 -0
- package/dist/core/conformance/cases.d.mts +12 -0
- package/dist/core/conformance/cases.mjs +82 -0
- package/dist/core/conformance/check.d.mts +33 -0
- package/dist/core/conformance/check.mjs +81 -0
- package/dist/core/conformance/dataset-model.mjs +306 -0
- package/dist/core/conformance/dataset-rows.mjs +246 -0
- package/dist/core/conformance/dataset.d.mts +381 -0
- package/dist/core/conformance/dataset.mjs +58 -0
- package/dist/core/conformance/index.d.mts +10 -0
- package/dist/core/conformance/index.mjs +9 -0
- package/dist/core/conformance/memory/aggregate.mjs +76 -0
- package/dist/core/conformance/memory/rows.d.mts +10 -0
- package/dist/core/conformance/memory/rows.mjs +98 -0
- package/dist/core/conformance/memory/source.d.mts +4 -0
- package/dist/core/conformance/memory/source.mjs +129 -0
- package/dist/core/conformance/queries.mjs +108 -0
- package/dist/core/conformance/records-cases.mjs +68 -0
- package/dist/core/document/diff.d.mts +68 -0
- package/dist/core/document/diff.mjs +155 -0
- package/dist/core/document/layout.d.mts +51 -0
- package/dist/core/document/layout.mjs +228 -0
- package/dist/core/document/outcome.d.mts +10 -0
- package/dist/core/document/outcome.mjs +14 -0
- package/dist/core/document/reduce.d.mts +16 -0
- package/dist/core/document/reduce.mjs +191 -0
- package/dist/core/document/replay.d.mts +28 -0
- package/dist/core/document/replay.mjs +38 -0
- package/dist/core/document/stacked.d.mts +14 -0
- package/dist/core/document/stacked.mjs +70 -0
- package/dist/core/document/tabs.mjs +70 -0
- package/dist/core/document/types.d.mts +138 -0
- package/dist/core/document/types.mjs +16 -0
- package/dist/core/document/upgrade.d.mts +25 -0
- package/dist/core/document/upgrade.mjs +49 -0
- package/dist/core/document/view.d.mts +30 -0
- package/dist/core/document/view.mjs +50 -0
- package/dist/core/engine/access.mjs +113 -0
- package/dist/core/engine/assert.d.mts +21 -0
- package/dist/core/engine/assert.mjs +132 -0
- package/dist/core/engine/bucket.mjs +52 -0
- package/dist/core/engine/build.mjs +71 -0
- package/dist/core/engine/checks.mjs +29 -0
- package/dist/core/engine/context.mjs +46 -0
- package/dist/core/engine/cursor.mjs +30 -0
- package/dist/core/engine/custom/ask.mjs +13 -0
- package/dist/core/engine/custom/cells.mjs +80 -0
- package/dist/core/engine/custom/fields.mjs +130 -0
- package/dist/core/engine/custom/level.mjs +136 -0
- package/dist/core/engine/custom/measures.mjs +146 -0
- package/dist/core/engine/custom/query.mjs +37 -0
- package/dist/core/engine/custom/reader.d.mts +7 -0
- package/dist/core/engine/custom/reader.mjs +67 -0
- package/dist/core/engine/custom/records.mjs +51 -0
- package/dist/core/engine/custom/request.d.mts +283 -0
- package/dist/core/engine/custom/seen.mjs +79 -0
- package/dist/core/engine/custom/where.mjs +34 -0
- package/dist/core/engine/dialect.d.mts +54 -0
- package/dist/core/engine/filter.mjs +129 -0
- package/dist/core/engine/index.d.mts +16 -0
- package/dist/core/engine/index.mjs +9 -0
- package/dist/core/engine/leaf.mjs +141 -0
- package/dist/core/engine/levels.mjs +175 -0
- package/dist/core/engine/measure.mjs +81 -0
- package/dist/core/engine/members.mjs +149 -0
- package/dist/core/engine/nan.mjs +9 -0
- package/dist/core/engine/native.mjs +59 -0
- package/dist/core/engine/numbers.mjs +191 -0
- package/dist/core/engine/other.mjs +45 -0
- package/dist/core/engine/plan.d.mts +54 -0
- package/dist/core/engine/postgres.d.mts +6 -0
- package/dist/core/engine/postgres.mjs +136 -0
- package/dist/core/engine/prepare.mjs +133 -0
- package/dist/core/engine/rank-sets.mjs +119 -0
- package/dist/core/engine/rank.mjs +149 -0
- package/dist/core/engine/read.mjs +74 -0
- package/dist/core/engine/reader.d.mts +128 -0
- package/dist/core/engine/reader.mjs +18 -0
- package/dist/core/engine/record-layout.d.mts +10 -0
- package/dist/core/engine/record-layout.mjs +37 -0
- package/dist/core/engine/records.d.mts +14 -0
- package/dist/core/engine/records.mjs +51 -0
- package/dist/core/engine/refs.mjs +58 -0
- package/dist/core/engine/run.d.mts +3 -0
- package/dist/core/engine/run.mjs +102 -0
- package/dist/core/engine/segmented.d.mts +11 -0
- package/dist/core/engine/segmented.mjs +80 -0
- package/dist/core/engine/series.mjs +95 -0
- package/dist/core/engine/shape.d.mts +12 -0
- package/dist/core/engine/shape.mjs +92 -0
- package/dist/core/engine/sql-marked.mjs +77 -0
- package/dist/core/engine/sql-pass.mjs +24 -0
- package/dist/core/engine/sql-reader.d.mts +10 -0
- package/dist/core/engine/sql-reader.mjs +51 -0
- package/dist/core/engine/sql-reads.mjs +28 -0
- package/dist/core/engine/sql-records.mjs +100 -0
- package/dist/core/engine/sql-split.mjs +158 -0
- package/dist/core/engine/sql.d.mts +8 -0
- package/dist/core/engine/sql.mjs +33 -0
- package/dist/core/engine/statement.mjs +78 -0
- package/dist/core/engine/time.mjs +52 -0
- package/dist/core/engine/two-step.mjs +104 -0
- package/dist/core/engine/types.d.mts +55 -0
- package/dist/core/engine/version.d.mts +7 -0
- package/dist/core/engine/version.mjs +9 -0
- package/dist/core/error/codes.d.mts +154 -0
- package/dist/core/error/codes.mjs +127 -0
- package/dist/core/error/refusal.d.mts +8 -0
- package/dist/core/error/refusal.mjs +11 -0
- package/dist/core/exact/decimal.d.mts +22 -0
- package/dist/core/exact/decimal.mjs +51 -0
- package/dist/core/exact/sum.d.mts +17 -0
- package/dist/core/exact/sum.mjs +31 -0
- package/dist/core/index.d.mts +56 -0
- package/dist/core/index.mjs +45 -0
- package/dist/core/model/catalog/check.d.mts +10 -0
- package/dist/core/model/catalog/check.mjs +141 -0
- package/dist/core/model/catalog/columns.mjs +34 -0
- package/dist/core/model/catalog/queries.d.mts +12 -0
- package/dist/core/model/catalog/queries.mjs +50 -0
- package/dist/core/model/defaults.d.mts +3 -0
- package/dist/core/model/defaults.mjs +24 -0
- package/dist/core/model/define.d.mts +32 -0
- package/dist/core/model/define.mjs +21 -0
- package/dist/core/model/member.d.mts +26 -0
- package/dist/core/model/member.mjs +58 -0
- package/dist/core/model/storage.mjs +28 -0
- package/dist/core/model/types.d.mts +270 -0
- package/dist/core/model/types.mjs +9 -0
- package/dist/core/model/validate/expr.d.mts +10 -0
- package/dist/core/model/validate/expr.mjs +56 -0
- package/dist/core/model/validate/filter.mjs +28 -0
- package/dist/core/model/validate/index.d.mts +10 -0
- package/dist/core/model/validate/index.mjs +36 -0
- package/dist/core/model/validate/issues.mjs +17 -0
- package/dist/core/model/validate/members.mjs +98 -0
- package/dist/core/model/validate/policy.mjs +76 -0
- package/dist/core/model/validate/source.mjs +143 -0
- package/dist/core/model/validate/via.d.mts +4 -0
- package/dist/core/model/validate/via.mjs +47 -0
- package/dist/core/oracle/data.d.mts +37 -0
- package/dist/core/oracle/data.mjs +30 -0
- package/dist/core/oracle/evaluate.d.mts +23 -0
- package/dist/core/oracle/evaluate.mjs +117 -0
- package/dist/core/oracle/expr.mjs +74 -0
- package/dist/core/oracle/facts.mjs +72 -0
- package/dist/core/oracle/filter.d.mts +6 -0
- package/dist/core/oracle/filter.mjs +25 -0
- package/dist/core/oracle/groups.mjs +33 -0
- package/dist/core/oracle/index.d.mts +4 -0
- package/dist/core/oracle/index.mjs +3 -0
- package/dist/core/oracle/levels.mjs +46 -0
- package/dist/core/oracle/logic.mjs +38 -0
- package/dist/core/oracle/measure.mjs +85 -0
- package/dist/core/oracle/members.mjs +80 -0
- package/dist/core/oracle/request.mjs +38 -0
- package/dist/core/oracle/segmented.d.mts +7 -0
- package/dist/core/oracle/segmented.mjs +35 -0
- package/dist/core/oracle/split.mjs +84 -0
- package/dist/core/oracle/time-axis.mjs +37 -0
- package/dist/core/oracle/time-value.mjs +28 -0
- package/dist/core/oracle/tree.mjs +24 -0
- package/dist/core/oracle/values.mjs +41 -0
- package/dist/core/oracle/visibility.mjs +49 -0
- package/dist/core/policy/bind.d.mts +25 -0
- package/dist/core/policy/bind.mjs +64 -0
- package/dist/core/policy/match.d.mts +16 -0
- package/dist/core/policy/match.mjs +44 -0
- package/dist/core/query/alias.mjs +14 -0
- package/dist/core/query/closure.d.mts +17 -0
- package/dist/core/query/closure.mjs +131 -0
- package/dist/core/query/compose-tile.d.mts +50 -0
- package/dist/core/query/compose-tile.mjs +140 -0
- package/dist/core/query/compose.d.mts +105 -0
- package/dist/core/query/compose.mjs +12 -0
- package/dist/core/query/derived-rules.mjs +56 -0
- package/dist/core/query/effective.d.mts +32 -0
- package/dist/core/query/effective.mjs +22 -0
- package/dist/core/query/filter.d.mts +99 -0
- package/dist/core/query/filter.mjs +79 -0
- package/dist/core/query/formulas.d.mts +17 -0
- package/dist/core/query/formulas.mjs +52 -0
- package/dist/core/query/picks.d.mts +10 -0
- package/dist/core/query/picks.mjs +25 -0
- package/dist/core/query/segments.d.mts +6 -0
- package/dist/core/query/segments.mjs +182 -0
- package/dist/core/query/to-wire.d.mts +21 -0
- package/dist/core/query/to-wire.mjs +124 -0
- package/dist/core/query/types.d.mts +238 -0
- package/dist/core/result/calc.mjs +95 -0
- package/dist/core/result/columns.d.mts +13 -0
- package/dist/core/result/columns.mjs +118 -0
- package/dist/core/result/marks.d.mts +20 -0
- package/dist/core/result/marks.mjs +35 -0
- package/dist/core/result/number.mjs +78 -0
- package/dist/core/result/order.d.mts +2 -0
- package/dist/core/result/order.mjs +57 -0
- package/dist/core/result/types.d.mts +66 -0
- package/dist/core/result/zero.mjs +18 -0
- package/dist/core/schema/answers.d.mts +2071 -0
- package/dist/core/schema/answers.mjs +217 -0
- package/dist/core/schema/commands.d.mts +273 -0
- package/dist/core/schema/commands.mjs +129 -0
- package/dist/core/schema/custom.d.mts +13 -0
- package/dist/core/schema/custom.mjs +250 -0
- package/dist/core/schema/document.d.mts +149 -0
- package/dist/core/schema/document.mjs +216 -0
- package/dist/core/schema/editing.mjs +166 -0
- package/dist/core/schema/index.d.mts +9 -0
- package/dist/core/schema/index.mjs +9 -0
- package/dist/core/schema/issue.mjs +18 -0
- package/dist/core/schema/query.d.mts +92 -0
- package/dist/core/schema/query.mjs +174 -0
- package/dist/core/schema/tools.d.mts +17 -0
- package/dist/core/schema/tools.mjs +62 -0
- package/dist/core/schema/view.d.mts +47 -0
- package/dist/core/schema/view.mjs +71 -0
- package/dist/core/store/ddl.d.mts +38 -0
- package/dist/core/store/ddl.mjs +79 -0
- package/dist/core/store/schema.d.mts +315 -0
- package/dist/core/store/schema.mjs +181 -0
- package/dist/core/time/bucket.d.mts +25 -0
- package/dist/core/time/bucket.mjs +103 -0
- package/dist/core/time/compare.d.mts +30 -0
- package/dist/core/time/compare.mjs +73 -0
- package/dist/core/time/index.d.mts +7 -0
- package/dist/core/time/instant.d.mts +14 -0
- package/dist/core/time/instant.mjs +58 -0
- package/dist/core/time/range.d.mts +21 -0
- package/dist/core/time/range.mjs +41 -0
- package/dist/core/time/stored.d.mts +10 -0
- package/dist/core/time/stored.mjs +29 -0
- package/dist/core/time/temporal.d.mts +14 -0
- package/dist/core/time/temporal.mjs +27 -0
- package/dist/core/time/zone.d.mts +27 -0
- package/dist/core/time/zone.mjs +55 -0
- package/dist/core/types/api.d.mts +327 -0
- package/dist/core/types/api.mjs +9 -0
- package/dist/core/types/infer.d.mts +91 -0
- package/dist/core/types/options.d.mts +94 -0
- package/dist/core/types/plugin.d.mts +82 -0
- package/dist/core/types/plugin.mjs +12 -0
- package/dist/core/types/primitives.d.mts +26 -0
- package/dist/core/types/provider.d.mts +74 -0
- package/dist/core/types/source.d.mts +73 -0
- package/dist/core/types/store.d.mts +327 -0
- package/dist/core/types/viewer.d.mts +74 -0
- package/dist/core/types/viewer.mjs +6 -0
- package/dist/core/value/canonical.d.mts +5 -0
- package/dist/core/value/canonical.mjs +10 -0
- package/dist/core/value/casefold-data.mjs +3 -0
- package/dist/core/value/casefold.d.mts +8 -0
- package/dist/core/value/casefold.mjs +36 -0
- package/dist/core/value/compare.d.mts +3 -0
- package/dist/core/value/compare.mjs +18 -0
- package/dist/custom-source.d.mts +21 -0
- package/dist/custom-source.mjs +30 -0
- package/dist/dashboard-id.mjs +31 -0
- package/dist/dashboards.mjs +84 -0
- package/dist/editing.mjs +114 -0
- package/dist/endpoints/access.mjs +44 -0
- package/dist/endpoints/dashboards.mjs +109 -0
- package/dist/endpoints/drafts.mjs +138 -0
- package/dist/endpoints/index.d.mts +453 -0
- package/dist/endpoints/index.mjs +39 -0
- package/dist/endpoints/meta.mjs +123 -0
- package/dist/endpoints/query.mjs +72 -0
- package/dist/endpoints/read.mjs +79 -0
- package/dist/endpoints/review.mjs +91 -0
- package/dist/endpoints/values.mjs +58 -0
- package/dist/endpoints/versions.mjs +103 -0
- package/dist/execute.d.mts +10 -0
- package/dist/execute.mjs +152 -0
- package/dist/handler.mjs +189 -0
- package/dist/http.d.mts +16 -0
- package/dist/http.mjs +67 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.mjs +115 -0
- package/dist/introspect.mjs +180 -0
- package/dist/mcp/api.d.mts +10 -0
- package/dist/mcp/api.mjs +34 -0
- package/dist/mcp/format.d.mts +10 -0
- package/dist/mcp/format.mjs +59 -0
- package/dist/mcp/index.d.mts +61 -0
- package/dist/mcp/index.mjs +88 -0
- package/dist/mcp/query.d.mts +6 -0
- package/dist/mcp/query.mjs +123 -0
- package/dist/mcp/resolve.mjs +67 -0
- package/dist/node-postgres.d.mts +33 -0
- package/dist/node-postgres.mjs +59 -0
- package/dist/owner.mjs +34 -0
- package/dist/postgres-connection.d.mts +33 -0
- package/dist/postgres-connection.mjs +84 -0
- package/dist/postgres-store.d.mts +38 -0
- package/dist/postgres-store.mjs +60 -0
- package/dist/principal.mjs +28 -0
- package/dist/react/CancelRestore.mjs +21 -0
- package/dist/react/Canvas.mjs +97 -0
- package/dist/react/Cell.mjs +106 -0
- package/dist/react/ConfirmButton.mjs +31 -0
- package/dist/react/Dashboard.d.mts +27 -0
- package/dist/react/Dashboard.mjs +80 -0
- package/dist/react/DashboardList.d.mts +12 -0
- package/dist/react/DashboardList.mjs +155 -0
- package/dist/react/Discard.mjs +99 -0
- package/dist/react/EditBar.d.mts +16 -0
- package/dist/react/EditBar.mjs +141 -0
- package/dist/react/Editing.mjs +124 -0
- package/dist/react/FilterBar.d.mts +9 -0
- package/dist/react/FilterBar.mjs +119 -0
- package/dist/react/Grid.mjs +133 -0
- package/dist/react/Header.mjs +107 -0
- package/dist/react/History.d.mts +30 -0
- package/dist/react/History.mjs +202 -0
- package/dist/react/Notice.d.mts +8 -0
- package/dist/react/Notice.mjs +51 -0
- package/dist/react/Overlaps.mjs +54 -0
- package/dist/react/Panel.d.mts +16 -0
- package/dist/react/Panel.mjs +93 -0
- package/dist/react/Parts.mjs +98 -0
- package/dist/react/Records.d.mts +12 -0
- package/dist/react/Records.mjs +97 -0
- package/dist/react/ReviewPanel.d.mts +15 -0
- package/dist/react/ReviewPanel.mjs +200 -0
- package/dist/react/Spaces.mjs +108 -0
- package/dist/react/Tile.d.mts +20 -0
- package/dist/react/Tile.mjs +123 -0
- package/dist/react/arrange-steps.mjs +108 -0
- package/dist/react/arrange.mjs +135 -0
- package/dist/react/board.d.mts +16 -0
- package/dist/react/board.mjs +156 -0
- package/dist/react/builder/Calcs.mjs +87 -0
- package/dist/react/builder/Filters.mjs +165 -0
- package/dist/react/builder/Groups.mjs +189 -0
- package/dist/react/builder/Picker.mjs +154 -0
- package/dist/react/builder/Preview.d.mts +6 -0
- package/dist/react/builder/Preview.mjs +102 -0
- package/dist/react/builder/Sections.mjs +85 -0
- package/dist/react/builder/Time.mjs +119 -0
- package/dist/react/builder/WidgetBuilder.d.mts +23 -0
- package/dist/react/builder/WidgetBuilder.mjs +202 -0
- package/dist/react/builder/base.d.mts +19 -0
- package/dist/react/builder/base.mjs +111 -0
- package/dist/react/builder/calc.d.mts +5 -0
- package/dist/react/builder/calc.mjs +110 -0
- package/dist/react/builder/labels.d.mts +1 -0
- package/dist/react/builder/labels.mjs +55 -0
- package/dist/react/builder/options.mjs +55 -0
- package/dist/react/builder/state.d.mts +12 -0
- package/dist/react/builder/state.mjs +201 -0
- package/dist/react/builder/useBuilder.d.mts +46 -0
- package/dist/react/builder/useBuilder.mjs +60 -0
- package/dist/react/builder/usePreview.mjs +56 -0
- package/dist/react/client.d.mts +93 -0
- package/dist/react/client.mjs +107 -0
- package/dist/react/context.d.mts +32 -0
- package/dist/react/context.mjs +44 -0
- package/dist/react/debounce.mjs +19 -0
- package/dist/react/draft.d.mts +55 -0
- package/dist/react/draft.mjs +230 -0
- package/dist/react/english.d.mts +3 -0
- package/dist/react/english.mjs +149 -0
- package/dist/react/errors.d.mts +12 -0
- package/dist/react/errors.mjs +13 -0
- package/dist/react/format.d.mts +25 -0
- package/dist/react/format.mjs +153 -0
- package/dist/react/index.d.mts +27 -0
- package/dist/react/index.mjs +25 -0
- package/dist/react/marks.d.mts +11 -0
- package/dist/react/marks.mjs +62 -0
- package/dist/react/messages.d.mts +159 -0
- package/dist/react/place.mjs +21 -0
- package/dist/react/read.d.mts +15 -0
- package/dist/react/read.mjs +54 -0
- package/dist/react/renderers/index.d.mts +19 -0
- package/dist/react/renderers/index.mjs +85 -0
- package/dist/react/review-words.d.mts +79 -0
- package/dist/react/review-words.mjs +132 -0
- package/dist/react/review.d.mts +26 -0
- package/dist/react/review.mjs +110 -0
- package/dist/react/scope.mjs +9 -0
- package/dist/react/stable.mjs +39 -0
- package/dist/react/theme.css +1337 -0
- package/dist/react/tile-keys.d.mts +20 -0
- package/dist/react/tile-keys.mjs +21 -0
- package/dist/react/tile-store.mjs +99 -0
- package/dist/react/useBoard.d.mts +80 -0
- package/dist/react/useBoard.mjs +53 -0
- package/dist/react/useDashboard.d.mts +51 -0
- package/dist/react/useDashboard.mjs +56 -0
- package/dist/react/useTiles.d.mts +20 -0
- package/dist/react/useTiles.mjs +133 -0
- package/dist/react/view.mjs +52 -0
- package/dist/reading.mjs +43 -0
- package/dist/recharts/charts.d.mts +10 -0
- package/dist/recharts/charts.mjs +121 -0
- package/dist/recharts/index.d.mts +3 -0
- package/dist/recharts/index.mjs +3 -0
- package/dist/recharts/series.d.mts +22 -0
- package/dist/recharts/series.mjs +64 -0
- package/dist/request-rows.mjs +21 -0
- package/dist/request.mjs +20 -0
- package/dist/storage.d.mts +3 -0
- package/dist/storage.mjs +54 -0
- package/dist/store/apply.mjs +102 -0
- package/dist/store/commands.mjs +74 -0
- package/dist/store/conflicts.mjs +79 -0
- package/dist/store/create-tables.d.mts +29 -0
- package/dist/store/create-tables.mjs +91 -0
- package/dist/store/discard.mjs +60 -0
- package/dist/store/drafts.mjs +132 -0
- package/dist/store/editor.mjs +22 -0
- package/dist/store/log.mjs +22 -0
- package/dist/store/publish.mjs +177 -0
- package/dist/store/publisher.mjs +16 -0
- package/dist/store/reader.mjs +139 -0
- package/dist/store/review.mjs +177 -0
- package/dist/store/rows.mjs +205 -0
- package/dist/store/tenant.mjs +23 -0
- package/dist/store/undo.mjs +49 -0
- package/dist/store/unpublished.mjs +47 -0
- package/dist/store/versions.mjs +93 -0
- package/dist/store/writer.mjs +19 -0
- package/dist/testing/adapter-suite.d.mts +12 -0
- package/dist/testing/adapter-suite.mjs +281 -0
- package/dist/testing/index.d.mts +2 -0
- package/dist/testing/index.mjs +1 -0
- package/dist/tile-doc.mjs +44 -0
- package/dist/tiles.mjs +102 -0
- package/package.json +125 -3
- package/src/adapter/sql-adapter.ts +95 -0
- package/src/adapter/statement.ts +185 -0
- package/src/authorize.ts +73 -0
- package/src/body.ts +169 -0
- package/src/bounded.ts +43 -0
- package/src/cache.ts +192 -0
- package/src/checks.ts +170 -0
- package/src/custom-source.ts +59 -0
- package/src/dashboard-id.ts +36 -0
- package/src/dashboards.ts +132 -0
- package/src/editing.ts +148 -0
- package/src/endpoints/access.ts +41 -0
- package/src/endpoints/dashboards.ts +92 -0
- package/src/endpoints/drafts.ts +138 -0
- package/src/endpoints/index.ts +21 -0
- package/src/endpoints/meta.ts +137 -0
- package/src/endpoints/query.ts +86 -0
- package/src/endpoints/read.ts +92 -0
- package/src/endpoints/review.ts +89 -0
- package/src/endpoints/values.ts +62 -0
- package/src/endpoints/versions.ts +104 -0
- package/src/execute.ts +207 -0
- package/src/handler.ts +232 -0
- package/src/http.ts +66 -0
- package/src/index.ts +163 -0
- package/src/introspect.ts +205 -0
- package/src/mcp/api.ts +59 -0
- package/src/mcp/format.ts +67 -0
- package/src/mcp/index.ts +151 -0
- package/src/mcp/query.ts +153 -0
- package/src/mcp/resolve.ts +114 -0
- package/src/node-postgres.ts +81 -0
- package/src/owner.ts +36 -0
- package/src/postgres-connection.ts +143 -0
- package/src/postgres-store.ts +82 -0
- package/src/principal.ts +39 -0
- package/src/reading.ts +56 -0
- package/src/request-rows.ts +23 -0
- package/src/request.ts +22 -0
- package/src/storage.ts +63 -0
- package/src/store/apply.ts +129 -0
- package/src/store/commands.ts +75 -0
- package/src/store/conflicts.ts +98 -0
- package/src/store/create-tables.ts +104 -0
- package/src/store/discard.ts +42 -0
- package/src/store/drafts.ts +133 -0
- package/src/store/editor.ts +28 -0
- package/src/store/log.ts +28 -0
- package/src/store/publish.ts +199 -0
- package/src/store/publisher.ts +21 -0
- package/src/store/reader.ts +139 -0
- package/src/store/review.ts +239 -0
- package/src/store/rows.ts +250 -0
- package/src/store/tenant.ts +28 -0
- package/src/store/undo.ts +56 -0
- package/src/store/unpublished.ts +33 -0
- package/src/store/versions.ts +106 -0
- package/src/store/writer.ts +19 -0
- package/src/testing/adapter-suite.ts +239 -0
- package/src/testing/index.ts +2 -0
- package/src/tile-doc.ts +46 -0
- package/src/tiles.ts +120 -0
package/dist/cache.mjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { entriesIn, memoryStorage } from "./storage.mjs";
|
|
2
|
+
import { bindPolicy, canonical, namedPolicy, policyBinding, principalTenant, queryClosure, viaJoins } from "derive-dashboards/core";
|
|
3
|
+
import { ENGINE_VERSION } from "derive-dashboards/core/engine";
|
|
4
|
+
// src/cache.ts
|
|
5
|
+
async function sha256(text) {
|
|
6
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
7
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8
|
+
}
|
|
9
|
+
/** The parents a source's rows are visible through, all the way up. */
|
|
10
|
+
function viaParents(model, source, seen) {
|
|
11
|
+
const def = model.sources[source];
|
|
12
|
+
if (seen.has(source) || def === void 0) return;
|
|
13
|
+
seen.add(source);
|
|
14
|
+
for (const join of viaJoins(def)) {
|
|
15
|
+
const to = def.joins?.[join]?.to;
|
|
16
|
+
if (to !== void 0) viaParents(model, to, seen);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Every source an answer can depend on: what the query reads, what its lock and required filters are on, and their via parents. */
|
|
20
|
+
function manifest(model, query, on) {
|
|
21
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22
|
+
for (const source of [...queryClosure(model, query).sources, ...on]) viaParents(model, source, seen);
|
|
23
|
+
return [...seen].toSorted();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The bound row policy of each source the answer reads (its manifest: the query's sources, the
|
|
27
|
+
* lock's, and every parent they are visible through): two viewers share an entry when those
|
|
28
|
+
* bind alike, whatever the policies of sources it does not read.
|
|
29
|
+
*/
|
|
30
|
+
function boundPolicies(model, principal, sources) {
|
|
31
|
+
return Object.fromEntries(sources.flatMap((name) => {
|
|
32
|
+
const def = model.sources[name];
|
|
33
|
+
if (def === void 0) return [];
|
|
34
|
+
const policy = policyBinding(def);
|
|
35
|
+
if (typeof policy === "object" && "via" in policy) return [[name, "via"]];
|
|
36
|
+
const rules = typeof policy === "string" ? namedPolicy(model, policy) : policy;
|
|
37
|
+
return [[name, bindPolicy(rules, principal)]];
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const epochKey = (tenant, source) => `dd:epoch:${canonical(tenant)}:${source}`;
|
|
41
|
+
const marked = (value, cache) => ({
|
|
42
|
+
...value,
|
|
43
|
+
receipt: {
|
|
44
|
+
...value.receipt,
|
|
45
|
+
cache,
|
|
46
|
+
answeredBy: cache === "miss" ? "base" : "cache"
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Answers keyed by everything that decides them. Each source's epoch is in the key, so a write
|
|
51
|
+
* invalidates by bumping the epochs of the sources it changed; old entries are never read again
|
|
52
|
+
* and expire on their own.
|
|
53
|
+
*/
|
|
54
|
+
var ResultCache = class {
|
|
55
|
+
#options;
|
|
56
|
+
#ttl;
|
|
57
|
+
#stale;
|
|
58
|
+
#storage;
|
|
59
|
+
#entries;
|
|
60
|
+
#inFlight = /* @__PURE__ */ new Map();
|
|
61
|
+
#modelHash;
|
|
62
|
+
constructor(options, cache) {
|
|
63
|
+
this.#options = options;
|
|
64
|
+
this.#ttl = cache.ttl ?? 60;
|
|
65
|
+
this.#stale = cache.staleTtl ?? 0;
|
|
66
|
+
this.#storage = options.secondaryStorage ?? memoryStorage();
|
|
67
|
+
this.#entries = entriesIn(options.secondaryStorage);
|
|
68
|
+
this.#modelHash = sha256(canonical(options.model));
|
|
69
|
+
}
|
|
70
|
+
async #keyOf(k) {
|
|
71
|
+
const tenant = principalTenant(k.principal);
|
|
72
|
+
const epochs = await Promise.all(k.sources.map(async (s) => await this.#storage.get(epochKey(tenant, s)) ?? "0"));
|
|
73
|
+
const relative = k.query.time !== void 0 && "last" in k.query.time.range;
|
|
74
|
+
const parts = {
|
|
75
|
+
v: ENGINE_VERSION,
|
|
76
|
+
model: await this.#modelHash,
|
|
77
|
+
tenant,
|
|
78
|
+
policy: boundPolicies(this.#options.model, k.principal, k.sources),
|
|
79
|
+
query: k.query,
|
|
80
|
+
lock: k.lock,
|
|
81
|
+
required: k.required,
|
|
82
|
+
calendar: k.calendar,
|
|
83
|
+
maxRows: k.maxRows,
|
|
84
|
+
...relative ? { now: k.now } : {},
|
|
85
|
+
epochs: Object.fromEntries(k.sources.map((s, i) => [s, epochs[i]]))
|
|
86
|
+
};
|
|
87
|
+
return `dd:result:${await sha256(canonical(parts))}`;
|
|
88
|
+
}
|
|
89
|
+
/** Computes once per key at a time, stores the answer, and hands every waiter the same one. */
|
|
90
|
+
#refresh(key, compute) {
|
|
91
|
+
const running = this.#inFlight.get(key);
|
|
92
|
+
if (running !== void 0) return running;
|
|
93
|
+
const task = (async () => {
|
|
94
|
+
try {
|
|
95
|
+
const value = await compute();
|
|
96
|
+
await this.#entries.set(key, {
|
|
97
|
+
at: Date.now(),
|
|
98
|
+
value
|
|
99
|
+
}, this.#ttl + this.#stale);
|
|
100
|
+
return value;
|
|
101
|
+
} finally {
|
|
102
|
+
this.#inFlight.delete(key);
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
this.#inFlight.set(key, task);
|
|
106
|
+
return task;
|
|
107
|
+
}
|
|
108
|
+
/** A stale answer's refresh runs where the host runs background work, and never fails a request. */
|
|
109
|
+
#background(task) {
|
|
110
|
+
const quiet = task.catch(() => null);
|
|
111
|
+
this.#options.advanced?.backgroundTasks?.handler(quiet);
|
|
112
|
+
}
|
|
113
|
+
async answer(k, compute) {
|
|
114
|
+
const key = await this.#keyOf(k);
|
|
115
|
+
const entry = await this.#entries.get(key);
|
|
116
|
+
if (entry !== null) {
|
|
117
|
+
const age = (Date.now() - entry.at) / 1e3;
|
|
118
|
+
if (age < this.#ttl) return marked(entry.value, "hit");
|
|
119
|
+
if (age < this.#ttl + this.#stale) {
|
|
120
|
+
this.#background(this.#refresh(key, compute));
|
|
121
|
+
return marked(entry.value, "stale");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return marked(await this.#refresh(key, compute), "miss");
|
|
125
|
+
}
|
|
126
|
+
async invalidate(tenant, sources) {
|
|
127
|
+
const names = sources ?? Object.keys(this.#options.model.sources);
|
|
128
|
+
await Promise.all(names.map(async (s) => {
|
|
129
|
+
const current = Number(await this.#storage.get(epochKey(tenant, s)) ?? "0");
|
|
130
|
+
await this.#storage.set(epochKey(tenant, s), String(current + 1));
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/** The result cache, or undefined when the host did not ask for one. */
|
|
135
|
+
function createCache(options) {
|
|
136
|
+
return options.cache === void 0 ? void 0 : new ResultCache(options, options.cache);
|
|
137
|
+
}
|
|
138
|
+
export { createCache, manifest, sha256 };
|
package/dist/checks.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { authorizeFree } from "./authorize.mjs";
|
|
2
|
+
import { editorOf, storeFor, storedId } from "./editing.mjs";
|
|
3
|
+
import { HttpError } from "./http.mjs";
|
|
4
|
+
import { dashboardResource } from "./owner.mjs";
|
|
5
|
+
import { QueryReferenceError, lockChanged, parseMemberId, resolveDimension, toWire } from "derive-dashboards/core";
|
|
6
|
+
// src/checks.ts
|
|
7
|
+
/** A stored query as the engine reads it; one that names a missing formula part is refused. */
|
|
8
|
+
function wireOf(query) {
|
|
9
|
+
try {
|
|
10
|
+
return toWire(query).wire;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error instanceof QueryReferenceError) throw new HttpError(400, "QUERY_REFERENCE", error.message);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Every query a batch adds or changes, each named query of a new widget included, must resolve against the model and be one the
|
|
18
|
+
* editor may read: nobody builds a widget over data they cannot see. A lock needs `manage`.
|
|
19
|
+
*/
|
|
20
|
+
async function checkCommands(rt, viewer, dashboard, commands) {
|
|
21
|
+
const queries = commands.flatMap((c) => c.type === "widget.setQuery" ? [c.query] : c.type === "widget.add" ? Object.values(c.widget.queries) : []);
|
|
22
|
+
for (const query of queries) await authorizeFree(rt.options, viewer, wireOf(query));
|
|
23
|
+
await checkFilters(rt, viewer, commands.flatMap((c) => c.type === "control.add" ? [c.control] : []));
|
|
24
|
+
if (commands.some((c) => c.type === "lock.set" || c.type === "lock.remove")) {
|
|
25
|
+
if (!await rt.options.access.can(viewer, "manage", dashboard)) throw new HttpError(403, "FORBIDDEN", "Changing a dashboard's lock needs manage.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Every filter a batch adds narrows a field the model has and the editor may read: a filter on
|
|
30
|
+
* a field that does not exist would never apply, and one on a hidden field would show its values.
|
|
31
|
+
*/
|
|
32
|
+
async function checkFilters(rt, viewer, controls) {
|
|
33
|
+
const members = controls.flatMap((c) => c.kind === "filter" ? [c.member] : []);
|
|
34
|
+
for (const member of members) {
|
|
35
|
+
const ref = parseMemberId(member);
|
|
36
|
+
if (!(ref !== void 0 && resolveDimension(rt.options.model, ref.source, member) !== void 0)) throw new HttpError(400, "QUERY_REFERENCE", `A filter names "${member}", which is not a field of the model.`);
|
|
37
|
+
if (!await rt.options.access.can(viewer, "view", {
|
|
38
|
+
kind: "member",
|
|
39
|
+
id: member
|
|
40
|
+
})) throw new HttpError(403, "FORBIDDEN", `A filter on "${member}" needs view on it.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Widgets brought back whole (a put-back on review): every query in them must be one the editor may read. */
|
|
44
|
+
async function checkWidgets(rt, viewer, dashboard, widgets) {
|
|
45
|
+
await checkCommands(rt, viewer, dashboard, widgets.map((widget, i) => ({
|
|
46
|
+
commandId: String(i),
|
|
47
|
+
type: "widget.add",
|
|
48
|
+
tab: "",
|
|
49
|
+
id: String(i),
|
|
50
|
+
widget,
|
|
51
|
+
at: {
|
|
52
|
+
x: 0,
|
|
53
|
+
y: 0,
|
|
54
|
+
w: 1,
|
|
55
|
+
h: 1
|
|
56
|
+
}
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A whole document an editor brings back, as a restore does: every query in it must be one they
|
|
61
|
+
* may read, and if its lock differs from the current one, they need `manage`, exactly as if
|
|
62
|
+
* they had made those changes by hand.
|
|
63
|
+
*/
|
|
64
|
+
async function checkDocument(rt, viewer, dashboard, docs) {
|
|
65
|
+
const { restored: doc, current } = docs;
|
|
66
|
+
const queries = Object.values(doc.widgets).flatMap((w) => Object.values(w.queries));
|
|
67
|
+
for (const query of queries) await authorizeFree(rt.options, viewer, wireOf(query));
|
|
68
|
+
await checkFilters(rt, viewer, doc.controls);
|
|
69
|
+
if (current !== void 0 && lockChanged(current, doc)) {
|
|
70
|
+
if (!await rt.options.access.can(viewer, "manage", dashboard)) throw new HttpError(403, "FORBIDDEN", "That version has a different lock; restoring it needs manage.");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* An earlier published version of a dashboard: the one rule for reading one, whether to
|
|
75
|
+
* preview it, run its tiles or copy it. It needs `edit`, and `manage` when its lock differs
|
|
76
|
+
* from the current one, so it never shows more than the person could see by restoring it.
|
|
77
|
+
*/
|
|
78
|
+
async function versionDoc(rt, request, user, ref) {
|
|
79
|
+
const resource = await dashboardResource(rt.options, request, user, ref.dashboardId);
|
|
80
|
+
if (!await rt.options.access.can(user.viewer, "edit", resource)) throw new HttpError(403, "FORBIDDEN", "Reading an earlier version needs edit.");
|
|
81
|
+
const id = await storedId(rt, request, user, ref.dashboardId);
|
|
82
|
+
const store = storeFor(rt, request);
|
|
83
|
+
const { tenant } = editorOf(user);
|
|
84
|
+
const old = id === null ? null : await store.getVersion({
|
|
85
|
+
tenant,
|
|
86
|
+
id,
|
|
87
|
+
version: ref.version
|
|
88
|
+
});
|
|
89
|
+
if (id === null) throw new HttpError(404, "NOT_FOUND", `"${ref.dashboardId}" has no published versions.`);
|
|
90
|
+
if (old === null) throw new HttpError(404, "NOT_FOUND", `There is no version ${String(ref.version)} of "${ref.dashboardId}".`);
|
|
91
|
+
const current = await store.get({
|
|
92
|
+
tenant,
|
|
93
|
+
ref: { id }
|
|
94
|
+
});
|
|
95
|
+
if (current !== null && lockChanged(current.doc, old.doc) && !await rt.options.access.can(user.viewer, "manage", resource)) throw new HttpError(403, "FORBIDDEN", "That version has a different lock; seeing it needs manage.");
|
|
96
|
+
return old;
|
|
97
|
+
}
|
|
98
|
+
export { checkCommands, checkDocument, checkWidgets, versionDoc };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli/bin.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { run } from "./cli.mjs";
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
process.exitCode = await run(process.argv.slice(2), {
|
|
5
|
+
cwd: process.cwd(),
|
|
6
|
+
out: (line) => {
|
|
7
|
+
process.stdout.write(`${line}\n`);
|
|
8
|
+
},
|
|
9
|
+
err: (line) => {
|
|
10
|
+
process.stderr.write(`${line}\n`);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { checkCatalog, describeQueries, validateModel } from "derive-dashboards/core";
|
|
2
|
+
// src/check.ts
|
|
3
|
+
const introspects = (c) => "introspect" in c;
|
|
4
|
+
/**
|
|
5
|
+
* What a connection of the config is: one `check` reads the catalog of, or a custom source it
|
|
6
|
+
* leaves to `--conformance`. Anything else (a raw pool, a function) is refused by name.
|
|
7
|
+
*/
|
|
8
|
+
function connectionOf(id, found) {
|
|
9
|
+
if (introspects(found)) return found;
|
|
10
|
+
if ("kind" in found && found.kind === "custom") return void 0;
|
|
11
|
+
throw new Error(`The config's connection "${id}" is neither a connection (nodePostgres(pool).connection, postgresConnection(...)) nor a customSource(...).`);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The model's sources by the connection they read, each as a model of its own: every source
|
|
15
|
+
* reads the one `connection` when the config gives that; with `connections`, each its own.
|
|
16
|
+
*/
|
|
17
|
+
function byConnection(config, model) {
|
|
18
|
+
return [...new Set(Object.values(model.sources).map((s) => s.in))].map((id) => {
|
|
19
|
+
const found = config.connections?.[id] ?? config.connection;
|
|
20
|
+
if (found === void 0) throw new Error(`The config has no connection "${id}".`);
|
|
21
|
+
const sources = Object.entries(model.sources).filter(([, s]) => s.in === id);
|
|
22
|
+
return {
|
|
23
|
+
sources: sources.map(([name]) => name),
|
|
24
|
+
model: {
|
|
25
|
+
...model,
|
|
26
|
+
sources: Object.fromEntries(sources)
|
|
27
|
+
},
|
|
28
|
+
connection: connectionOf(id, found)
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** One connection's sources against its database: a source's own sql described, then checked like a table. */
|
|
33
|
+
async function partIssues(part) {
|
|
34
|
+
if (part.connection === void 0) return [];
|
|
35
|
+
const described = await describeQueries(part.model, part.connection, await part.connection.introspect());
|
|
36
|
+
return [...described.issues, ...checkCatalog(part.model, described.schema)];
|
|
37
|
+
}
|
|
38
|
+
const describeIssue = (i) => ` ${i.code} ${i.path.join(".")}: ${i.message}`;
|
|
39
|
+
/**
|
|
40
|
+
* Proves a model against the config's databases and prints every problem: the exit code is 0
|
|
41
|
+
* when it matches, 1 when it does not.
|
|
42
|
+
*/
|
|
43
|
+
async function checkModel(config, model, io) {
|
|
44
|
+
const parts = byConnection(config, model);
|
|
45
|
+
for (const part of parts) if (part.connection === void 0) io.out(`${part.sources.join(", ")}: read through a custom source; check it with --conformance.`);
|
|
46
|
+
const checked = await Promise.all(parts.map((part) => partIssues(part)));
|
|
47
|
+
const issues = [...validateModel(model), ...checked.flat()];
|
|
48
|
+
for (const issue of issues) io.err(describeIssue(issue));
|
|
49
|
+
io.out(issues.length === 0 ? "The model matches the database." : `${issues.length} problems.`);
|
|
50
|
+
return issues.length === 0 ? 0 : 1;
|
|
51
|
+
}
|
|
52
|
+
export { checkModel, describeIssue, introspects };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CliConfig } from "./config.mjs";
|
|
2
|
+
import { Io } from "./io.mjs";
|
|
3
|
+
/** Runs one command; the exit code is 0 on success, 1 when a check finds problems, 2 on a usage or setup error. */
|
|
4
|
+
export declare function run(argv: readonly string[], io: Io, given?: CliConfig): Promise<number>;
|
|
5
|
+
export type { Io };
|
package/dist/cli/cli.mjs
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { checkModel } from "./check.mjs";
|
|
2
|
+
import { loadConfig } from "./config.mjs";
|
|
3
|
+
import { checkHost } from "./conformance.mjs";
|
|
4
|
+
import { init, writeNew } from "./init.mjs";
|
|
5
|
+
import { renderDrizzle, renderKysely, renderSql, renderStatements } from "./render.mjs";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
|
+
import { parseArgs } from "node:util";
|
|
9
|
+
import { createTables, schemaDiff } from "derive-dashboards";
|
|
10
|
+
// src/cli.ts
|
|
11
|
+
const USAGE = `Usage: derive-dashboards <command> [options]
|
|
12
|
+
|
|
13
|
+
init [--tenant org=org_id] [--out dashboards.model.ts] [--force]
|
|
14
|
+
Propose a model from the database's tables and foreign keys.
|
|
15
|
+
init --from dbt|cube <path> [--tenant org=org_id] [--out file] [--force]
|
|
16
|
+
Import a model from dbt's semantic layer (target/semantic_manifest.json, or the project
|
|
17
|
+
folder) or Cube's YAML data model (a file or folder); exact storage from the config's
|
|
18
|
+
connection when there is one, then checked against it.
|
|
19
|
+
check
|
|
20
|
+
Prove the config's model against the database: tables, columns, keys, types.
|
|
21
|
+
check --conformance <module>
|
|
22
|
+
Run the conformance kit against a custom data layer: the module exports \`source\`
|
|
23
|
+
(customSource({ answer, records })) and \`load(dataset)\`, which fills its store.
|
|
24
|
+
create-tables
|
|
25
|
+
Make the library's own tables (dd_*) in the config's database; safe to run again.
|
|
26
|
+
generate --orm drizzle|sql|kysely [--dialect postgres|sqlite] --out <file>
|
|
27
|
+
Write the library's tables for your own tool (drizzle-kit, SQL files).
|
|
28
|
+
generate --orm sql --diff --out <file>
|
|
29
|
+
Write only what the config's database lacks: new tables, columns, keys, indexes.
|
|
30
|
+
|
|
31
|
+
--config <file> defaults to derive-dashboards.config.ts
|
|
32
|
+
-h, --help this text`;
|
|
33
|
+
/** The schema file for a host's own tool. */
|
|
34
|
+
function generated(orm, dialect) {
|
|
35
|
+
if (orm === "drizzle") return renderDrizzle(dialect);
|
|
36
|
+
if (orm === "sql") return renderSql(dialect);
|
|
37
|
+
if (orm === "kysely") return renderKysely();
|
|
38
|
+
throw new Error("generate needs --orm drizzle, sql or kysely.");
|
|
39
|
+
}
|
|
40
|
+
function need(value, what) {
|
|
41
|
+
if (value === void 0) throw new Error(`The config has no ${what}. Add \`${what}\` to defineConfig in derive-dashboards.config.ts${what === "model" ? " (`derive-dashboards init` writes one)" : ""}.`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
const COMMANDS = {
|
|
45
|
+
init,
|
|
46
|
+
check(config, flags, io) {
|
|
47
|
+
if (flags.conformance !== void 0) return checkHost(io, flags.conformance);
|
|
48
|
+
return checkModel(config, need(config.model, "model"), io);
|
|
49
|
+
},
|
|
50
|
+
async "create-tables"(config, _flags, io) {
|
|
51
|
+
await createTables(need(config.database, "database"));
|
|
52
|
+
io.out("The dd_ tables are there.");
|
|
53
|
+
return 0;
|
|
54
|
+
},
|
|
55
|
+
async generate(config, flags, io) {
|
|
56
|
+
if (flags.diff === true) {
|
|
57
|
+
if (flags.orm !== "sql") throw new Error("--diff writes SQL: use it with --orm sql.");
|
|
58
|
+
const diff = await schemaDiff(need(config.database, "database"));
|
|
59
|
+
const statements = [
|
|
60
|
+
...diff.tables,
|
|
61
|
+
...diff.columns,
|
|
62
|
+
...diff.indexes
|
|
63
|
+
];
|
|
64
|
+
await writeNew(io, need(flags.out, "--out"), renderStatements(statements), true);
|
|
65
|
+
io.out(diff.tables.length + diff.columns.length === 0 ? "The database has every table and column; only keys and indexes (IF NOT EXISTS) are written." : `Wrote ${diff.tables.length} tables and ${diff.columns.length} columns to add.`);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
const dialect = flags.dialect ?? "postgres";
|
|
69
|
+
if (dialect !== "postgres" && dialect !== "sqlite") throw new Error("--dialect is postgres or sqlite.");
|
|
70
|
+
await writeNew(io, need(flags.out, "--out"), generated(flags.orm, dialect), true);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The config a command reads: none for generating files or checking a custom source; for an
|
|
76
|
+
* import, the config when there is one (its connection gives exact storage), else none.
|
|
77
|
+
*/
|
|
78
|
+
function configFor(command, flags, cwd) {
|
|
79
|
+
if (command === "generate" && flags.diff !== true || flags.conformance !== void 0) return Promise.resolve({});
|
|
80
|
+
if (command === "init" && flags.from !== void 0 && !existsSync(resolve(cwd, flags.config ?? "derive-dashboards.config.ts"))) return Promise.resolve({});
|
|
81
|
+
return loadConfig(cwd, flags.config);
|
|
82
|
+
}
|
|
83
|
+
const OPTIONS = {
|
|
84
|
+
config: { type: "string" },
|
|
85
|
+
tenant: {
|
|
86
|
+
type: "string",
|
|
87
|
+
multiple: true
|
|
88
|
+
},
|
|
89
|
+
out: { type: "string" },
|
|
90
|
+
force: { type: "boolean" },
|
|
91
|
+
from: { type: "string" },
|
|
92
|
+
orm: { type: "string" },
|
|
93
|
+
dialect: { type: "string" },
|
|
94
|
+
diff: { type: "boolean" },
|
|
95
|
+
conformance: { type: "string" },
|
|
96
|
+
help: {
|
|
97
|
+
type: "boolean",
|
|
98
|
+
short: "h"
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/** The command line, or an exit code: help prints the usage (0), a flag it does not know says so (2). */
|
|
102
|
+
function parsedArgs(argv, io) {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = parseArgs({
|
|
105
|
+
args: [...argv],
|
|
106
|
+
allowPositionals: true,
|
|
107
|
+
options: OPTIONS
|
|
108
|
+
});
|
|
109
|
+
if (parsed.values.help === true || parsed.positionals[0] === "help" || argv.length === 0) {
|
|
110
|
+
(argv.length === 0 ? io.err : io.out)(USAGE);
|
|
111
|
+
return argv.length === 0 ? 2 : 0;
|
|
112
|
+
}
|
|
113
|
+
return parsed;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
io.err(`${error instanceof Error ? error.message : String(error)}\n\n${USAGE}`);
|
|
116
|
+
return 2;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Runs one command; the exit code is 0 on success, 1 when a check finds problems, 2 on a usage or setup error. */
|
|
120
|
+
async function run(argv, io, given) {
|
|
121
|
+
const parsed = parsedArgs(argv, io);
|
|
122
|
+
if (typeof parsed === "number") return parsed;
|
|
123
|
+
const { positionals } = parsed;
|
|
124
|
+
const values = {
|
|
125
|
+
...parsed.values,
|
|
126
|
+
args: positionals.slice(1)
|
|
127
|
+
};
|
|
128
|
+
const command = COMMANDS[positionals[0] ?? ""];
|
|
129
|
+
if (command === void 0) {
|
|
130
|
+
io.err(`Unknown command "${positionals[0]}".\n\n${USAGE}`);
|
|
131
|
+
return 2;
|
|
132
|
+
}
|
|
133
|
+
let config = {};
|
|
134
|
+
try {
|
|
135
|
+
config = given ?? await configFor(positionals[0], values, io.cwd);
|
|
136
|
+
return await command(config, values, io);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
io.err(error instanceof Error ? error.message : String(error));
|
|
139
|
+
return 2;
|
|
140
|
+
} finally {
|
|
141
|
+
await config.close?.();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export { run };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DashAdapter, IntrospectingConnection, Model } from "derive-dashboards/core";
|
|
2
|
+
import { CustomSource } from "derive-dashboards/core/engine";
|
|
3
|
+
/**
|
|
4
|
+
* What the CLI reads from `derive-dashboards.config.ts`: the connection `init` and `check`
|
|
5
|
+
* introspect, the store `create-tables` makes tables in, and the model `check` proves.
|
|
6
|
+
*/
|
|
7
|
+
export type CliConfig = {
|
|
8
|
+
/** The database every source of the model reads, when there is one. */
|
|
9
|
+
connection?: IntrospectingConnection;
|
|
10
|
+
/**
|
|
11
|
+
* Each connection by the id sources name in `in`, when the model reads more than one. A
|
|
12
|
+
* custom source (one that cannot be introspected) is skipped by `check`; `check
|
|
13
|
+
* --conformance` checks it.
|
|
14
|
+
*/
|
|
15
|
+
connections?: Readonly<Record<string, IntrospectingConnection | CustomSource>>;
|
|
16
|
+
database?: DashAdapter;
|
|
17
|
+
model?: Model;
|
|
18
|
+
/** Closes connections when a command is done. */
|
|
19
|
+
close?: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export declare function defineConfig(config: CliConfig): CliConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { loadModule } from "./load.mjs";
|
|
2
|
+
// src/config.ts
|
|
3
|
+
function defineConfig(config) {
|
|
4
|
+
return config;
|
|
5
|
+
}
|
|
6
|
+
const isConfig = (value) => typeof value === "object" && value !== null;
|
|
7
|
+
/** Loads the config module; its default export is the config. */
|
|
8
|
+
async function loadConfig(cwd, path = "derive-dashboards.config.ts") {
|
|
9
|
+
const module = await loadModule(cwd, path, "Make one that default-exports defineConfig({ ... }); see docs/cli.md.");
|
|
10
|
+
const config = isConfig(module) && "default" in module ? module.default : void 0;
|
|
11
|
+
if (!isConfig(config)) throw new Error(`${path} must export its config as the default export.`);
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
export { defineConfig, loadConfig };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { loadModule } from "./load.mjs";
|
|
2
|
+
import { checkConformance } from "derive-dashboards/core/conformance";
|
|
3
|
+
// src/conformance.ts
|
|
4
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
5
|
+
/** A module's host: its default export, or its own `source` and `load` exports. */
|
|
6
|
+
function hostOf(module, path) {
|
|
7
|
+
const candidate = isObject(module) && isObject(module.default) ? module.default : module;
|
|
8
|
+
const source = isObject(candidate) ? candidate.source : void 0;
|
|
9
|
+
const load = isObject(candidate) ? candidate.load : void 0;
|
|
10
|
+
if (!(isObject(source) && source.kind === "custom" && typeof source.answer === "function") || load !== void 0 && typeof load !== "function") throw new Error(`${path} must export \`source\` (a customSource({ answer, records })) and, to fill your store with the kit's dataset first, \`load(dataset)\`.`);
|
|
11
|
+
return candidate;
|
|
12
|
+
}
|
|
13
|
+
/** One mismatch: the case, then what the oracle and the host answered. */
|
|
14
|
+
function describe(m) {
|
|
15
|
+
return [
|
|
16
|
+
` ${m.name}`,
|
|
17
|
+
` expected ${JSON.stringify(m.expected)}`,
|
|
18
|
+
` got ${JSON.stringify(m.got)}`
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs the conformance kit against the host module at `path`: its custom source answers every
|
|
23
|
+
* case, compared with the oracle. 0 when every case matches, 1 when one does not.
|
|
24
|
+
*/
|
|
25
|
+
async function checkHost(io, path) {
|
|
26
|
+
const module = await loadModule(io.cwd, path, "Give a module that exports the custom source to check.");
|
|
27
|
+
const report = await checkConformance(hostOf(module, path));
|
|
28
|
+
for (const line of report.mismatches.slice(0, 20).flatMap((m) => describe(m))) io.err(line);
|
|
29
|
+
const more = report.mismatches.length - 20;
|
|
30
|
+
if (more > 0) io.err(` ... and ${more} more.`);
|
|
31
|
+
io.out(report.mismatches.length === 0 ? `The custom source keeps the contract: ${report.passed} of ${report.cases} cases match the oracle.` : `${report.mismatches.length} of ${report.cases} cases differ from the oracle.`);
|
|
32
|
+
return report.mismatches.length === 0 ? 0 : 1;
|
|
33
|
+
}
|
|
34
|
+
export { checkHost };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { labelsOf } from "./draft.mjs";
|
|
2
|
+
import { dimensionOf, numericOf } from "./storage.mjs";
|
|
3
|
+
import { tieToTenant } from "./tenancy.mjs";
|
|
4
|
+
// src/import/build.ts
|
|
5
|
+
/** The table a draft reads in the database: by name and schema, or its own sql as described. */
|
|
6
|
+
function tableOf(schema, d) {
|
|
7
|
+
if ("sql" in d.relation) return schema.tables.find((t) => t.name === `sql:${d.name}`);
|
|
8
|
+
const { table, schema: within } = d.relation;
|
|
9
|
+
return schema.tables.find((t) => t.name === table && (within === void 0 || t.schema === void 0 || t.schema === within));
|
|
10
|
+
}
|
|
11
|
+
function measureOf(catalog, source, m) {
|
|
12
|
+
const meta = labelsOf(m);
|
|
13
|
+
switch (m.agg) {
|
|
14
|
+
case "count": return m.distinct === void 0 ? {
|
|
15
|
+
kind: "count",
|
|
16
|
+
merge: "sum",
|
|
17
|
+
...meta
|
|
18
|
+
} : {
|
|
19
|
+
kind: "count",
|
|
20
|
+
distinct: m.distinct,
|
|
21
|
+
merge: "none",
|
|
22
|
+
...meta
|
|
23
|
+
};
|
|
24
|
+
case "ratio": return {
|
|
25
|
+
kind: "ratio",
|
|
26
|
+
numerator: m.numerator,
|
|
27
|
+
denominator: m.denominator,
|
|
28
|
+
merge: "none",
|
|
29
|
+
...meta
|
|
30
|
+
};
|
|
31
|
+
case "percentile": return {
|
|
32
|
+
kind: "percentile",
|
|
33
|
+
of: m.of,
|
|
34
|
+
p: m.p,
|
|
35
|
+
merge: "none",
|
|
36
|
+
...meta
|
|
37
|
+
};
|
|
38
|
+
case "avg": return {
|
|
39
|
+
kind: "avg",
|
|
40
|
+
of: m.of,
|
|
41
|
+
numeric: numericOf(catalog, source, m.of),
|
|
42
|
+
merge: "none",
|
|
43
|
+
...meta
|
|
44
|
+
};
|
|
45
|
+
case "sum":
|
|
46
|
+
case "min":
|
|
47
|
+
case "max": return {
|
|
48
|
+
kind: m.agg,
|
|
49
|
+
of: m.of,
|
|
50
|
+
numeric: numericOf(catalog, source, m.of),
|
|
51
|
+
merge: m.agg,
|
|
52
|
+
...meta
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Guesses made for want of a connection, one note per source. */
|
|
57
|
+
function unsureNote(source, unsure) {
|
|
58
|
+
if (unsure.length === 0) return [];
|
|
59
|
+
return [`${source}: with no connection in the config the import cannot see how its columns are stored, so ${[...new Set(unsure)].join(", ")}. Confirm, or run init with a connection for exact storage.`];
|
|
60
|
+
}
|
|
61
|
+
function sourceOf(d, catalog, names) {
|
|
62
|
+
const measures = {};
|
|
63
|
+
for (const m of d.measures) measures[m.name] = measureOf(catalog, d.name, m);
|
|
64
|
+
const dimensions = {};
|
|
65
|
+
for (const dim of d.dimensions) dimensions[dim.name] = dimensionOf(catalog, d.name, dim);
|
|
66
|
+
const times = Object.keys(dimensions).filter((n) => dimensions[n]?.kind === "time");
|
|
67
|
+
const time = d.time !== void 0 && times.includes(d.time) ? d.time : times[0];
|
|
68
|
+
const joins = d.joins.filter((j) => names.has(j.to));
|
|
69
|
+
for (const j of d.joins) if (!names.has(j.to)) catalog.notes.push(`Not imported: the join ${d.name}.${j.name}, to ${j.to}, which is not imported.`);
|
|
70
|
+
return {
|
|
71
|
+
...d.relation,
|
|
72
|
+
in: "main",
|
|
73
|
+
key: d.key,
|
|
74
|
+
...time === void 0 ? {} : { time },
|
|
75
|
+
...joins.length === 0 ? {} : { joins: Object.fromEntries(joins.map((j) => [j.name, {
|
|
76
|
+
to: j.to,
|
|
77
|
+
on: j.on,
|
|
78
|
+
relationship: j.relationship
|
|
79
|
+
}])) },
|
|
80
|
+
measures,
|
|
81
|
+
dimensions
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The model an import describes, with exact storage from the database when the config has a
|
|
86
|
+
* connection (`schema`), and tied to the tenant by `--tenant` as `init` ties tables.
|
|
87
|
+
*/
|
|
88
|
+
function buildModel(imported, schema, tenant) {
|
|
89
|
+
const notes = [...imported.notes];
|
|
90
|
+
const names = new Set(imported.sources.map((s) => s.name));
|
|
91
|
+
const sources = {};
|
|
92
|
+
const columns = /* @__PURE__ */ new Map();
|
|
93
|
+
for (const d of imported.sources) {
|
|
94
|
+
const table = schema === void 0 ? void 0 : tableOf(schema, d);
|
|
95
|
+
if (schema !== void 0 && table === void 0) notes.push(`${d.name}: the database has no ${"sql" in d.relation ? "result for its sql" : `table ${d.relation.table}`}.`);
|
|
96
|
+
const catalog = {
|
|
97
|
+
table,
|
|
98
|
+
unsure: [],
|
|
99
|
+
notes
|
|
100
|
+
};
|
|
101
|
+
sources[d.name] = sourceOf(d, catalog, names);
|
|
102
|
+
notes.push(...unsureNote(d.name, catalog.unsure));
|
|
103
|
+
columns.set(d.name, table === void 0 ? void 0 : new Set(table.columns.map((c) => c.name)));
|
|
104
|
+
}
|
|
105
|
+
const tied = tieToTenant(sources, columns, tenant, notes);
|
|
106
|
+
return {
|
|
107
|
+
model: Object.keys(tenant).length === 0 ? {
|
|
108
|
+
version: 1,
|
|
109
|
+
sources: tied
|
|
110
|
+
} : {
|
|
111
|
+
version: 1,
|
|
112
|
+
tenant: { keys: Object.keys(tenant) },
|
|
113
|
+
sources: tied
|
|
114
|
+
},
|
|
115
|
+
notes
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export { buildModel };
|