derive-dashboards 0.1.0 → 0.2.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/README.md +8 -5
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/add.mjs +130 -0
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/cli.mjs +14 -12
- package/dist/cli/config.mjs +12 -1
- package/dist/cli/doctor.mjs +147 -0
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- package/dist/cli/init.mjs +3 -2
- package/dist/cli/json.mjs +21 -0
- package/dist/cli/layers.mjs +33 -0
- package/dist/core/conformance/cases.d.mts +3 -0
- package/dist/core/conformance/cases.mjs +20 -4
- package/dist/core/conformance/check.mjs +6 -3
- package/dist/core/conformance/drill-cases.mjs +120 -0
- package/dist/core/document/layout.mjs +1 -1
- package/dist/core/document/view-layout.d.mts +14 -0
- package/dist/core/document/view-layout.mjs +157 -0
- package/dist/core/document/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/filter.mjs +2 -2
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/leaf.mjs +9 -4
- package/dist/core/engine/members.mjs +2 -2
- package/dist/core/engine/postgres.mjs +1 -1
- package/dist/core/engine/record-layout.d.mts +11 -0
- package/dist/core/engine/record-layout.mjs +7 -7
- package/dist/core/engine/records.d.mts +3 -2
- package/dist/core/engine/records.mjs +2 -1
- package/dist/core/engine/segmented.mjs +5 -2
- package/dist/core/engine/sql-records.mjs +2 -1
- package/dist/core/engine/statement.mjs +37 -3
- package/dist/core/engine/types.d.mts +3 -0
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +33 -1
- package/dist/core/error/codes.mjs +30 -2
- package/dist/core/index.d.mts +13 -7
- package/dist/core/index.mjs +9 -5
- package/dist/core/model/catalog/check.mjs +1 -1
- package/dist/core/model/hints.d.mts +36 -0
- package/dist/core/model/member.d.mts +4 -2
- package/dist/core/model/member.mjs +19 -3
- package/dist/core/model/types.d.mts +21 -19
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/members.mjs +7 -4
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- package/dist/core/policy/bind-query.d.mts +12 -0
- package/dist/core/policy/bind-query.mjs +53 -0
- package/dist/core/query/alias.mjs +7 -1
- package/dist/core/query/drill/compose.d.mts +22 -0
- package/dist/core/query/drill/compose.mjs +85 -0
- package/dist/core/query/drill/fields.d.mts +21 -0
- package/dist/core/query/drill/fields.mjs +91 -0
- package/dist/core/query/drill/internal.d.mts +11 -0
- package/dist/core/query/drill/items.d.mts +29 -0
- package/dist/core/query/drill/items.mjs +98 -0
- package/dist/core/query/drill/line.d.mts +31 -0
- package/dist/core/query/drill/line.mjs +183 -0
- package/dist/core/query/drill/links.d.mts +33 -0
- package/dist/core/query/drill/links.mjs +31 -0
- package/dist/core/query/drill/operand.mjs +7 -0
- package/dist/core/query/drill/scopes.d.mts +22 -0
- package/dist/core/query/drill/scopes.mjs +58 -0
- package/dist/core/query/drill/selection.d.mts +37 -0
- package/dist/core/query/drill/selection.mjs +144 -0
- package/dist/core/query/drill/steps.d.mts +14 -0
- package/dist/core/query/drill/steps.mjs +35 -0
- package/dist/core/query/drill/synthetic-expr.mjs +85 -0
- package/dist/core/query/drill/synthetic.d.mts +22 -0
- package/dist/core/query/drill/synthetic.mjs +165 -0
- package/dist/core/query/drill/time.d.mts +11 -0
- package/dist/core/query/drill/time.mjs +71 -0
- package/dist/core/query/drill/types.d.mts +155 -0
- package/dist/core/query/drill/types.mjs +4 -0
- package/dist/core/query/drill/views.d.mts +62 -0
- package/dist/core/query/drill/views.mjs +257 -0
- package/dist/core/query/filter.d.mts +6 -0
- package/dist/core/query/picks.d.mts +8 -2
- package/dist/core/query/picks.mjs +11 -4
- package/dist/core/query/segments.d.mts +12 -2
- package/dist/core/query/segments.mjs +5 -2
- package/dist/core/result/columns.mjs +20 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/aliases.d.mts +7 -0
- package/dist/core/schema/aliases.mjs +77 -0
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2109 -128
- package/dist/core/schema/answers.mjs +11 -113
- package/dist/core/schema/commands.d.mts +2 -2
- package/dist/core/schema/document.d.mts +1 -1
- package/dist/core/schema/drill-answers.mjs +179 -0
- package/dist/core/schema/drill.d.mts +260 -0
- package/dist/core/schema/drill.mjs +107 -0
- package/dist/core/schema/index.d.mts +6 -3
- package/dist/core/schema/index.mjs +6 -3
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +82 -1
- package/dist/core/schema/query.mjs +9 -5
- package/dist/core/schema/tools.mjs +1 -1
- package/dist/core/schema/view.d.mts +0 -35
- package/dist/core/schema/view.mjs +19 -24
- package/dist/core/store/schema.d.mts +5 -0
- package/dist/core/store/schema.mjs +10 -0
- package/dist/core/types/api.d.mts +21 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +210 -0
- package/dist/core/types/options.d.mts +21 -0
- package/dist/core/types/viewer.d.mts +5 -0
- package/dist/cursor-seal.d.mts +8 -0
- package/dist/cursor-seal.mjs +98 -0
- package/dist/dashboard-id.mjs +1 -1
- package/dist/dashboards.mjs +4 -0
- package/dist/drill-access.mjs +93 -0
- package/dist/drill-change.mjs +76 -0
- package/dist/drill-crumbs.mjs +113 -0
- package/dist/drill-distinct.mjs +130 -0
- package/dist/drill-explain.mjs +64 -0
- package/dist/drill-identity.mjs +35 -0
- package/dist/drill-item-id.mjs +35 -0
- package/dist/drill-items.mjs +132 -0
- package/dist/drill-open.mjs +169 -0
- package/dist/drill-seal.mjs +170 -0
- package/dist/drill-secret.mjs +14 -0
- package/dist/drill-share.mjs +53 -0
- package/dist/drill-summary.mjs +158 -0
- package/dist/drill-targets.mjs +53 -0
- package/dist/drill-totals.mjs +8 -0
- package/dist/drill-views.mjs +175 -0
- package/dist/drill.mjs +157 -0
- package/dist/editing.mjs +3 -3
- package/dist/endpoints/dashboards.mjs +28 -5
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +245 -4
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/meta.mjs +10 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +34 -27
- package/dist/handler.mjs +5 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/llms.txt +22 -0
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +69 -11
- package/dist/mcp/index.d.mts +15 -4
- package/dist/mcp/index.mjs +13 -7
- package/dist/mcp/query.d.mts +7 -2
- package/dist/mcp/query.mjs +40 -6
- package/dist/node-postgres.d.mts +8 -4
- package/dist/node-postgres.mjs +29 -6
- package/dist/owner.mjs +3 -3
- package/dist/postgres-connection.d.mts +8 -2
- package/dist/postgres-connection.mjs +2 -1
- package/dist/postgres-store.mjs +1 -0
- package/dist/react/Canvas.mjs +28 -5
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +62 -22
- package/dist/react/DashboardList.mjs +52 -24
- package/dist/react/DashboardListRow.mjs +49 -0
- package/dist/react/Discard.mjs +12 -4
- package/dist/react/Editing.mjs +19 -5
- package/dist/react/FilterBar.d.mts +7 -9
- package/dist/react/Grid.mjs +19 -24
- package/dist/react/Header.mjs +10 -1
- package/dist/react/History.mjs +5 -0
- package/dist/react/Parts.mjs +6 -2
- package/dist/react/ReadFailed.mjs +23 -0
- package/dist/react/ReviewPanel.mjs +13 -2
- package/dist/react/RowBody.d.mts +19 -0
- package/dist/react/RowBody.mjs +55 -0
- package/dist/react/Spaces.mjs +15 -1
- package/dist/react/Tile.d.mts +3 -1
- package/dist/react/Tile.mjs +84 -32
- package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/react/arrange-steps.mjs +16 -13
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/Calcs.mjs +35 -11
- package/dist/react/builder/FilterEditor.mjs +196 -0
- package/dist/react/builder/Filters.mjs +172 -116
- package/dist/react/builder/Formula.mjs +82 -0
- package/dist/react/builder/Groups.mjs +1 -0
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/builder/RangeEditor.mjs +184 -0
- package/dist/react/builder/Sections.mjs +41 -6
- package/dist/react/builder/Time.mjs +138 -60
- package/dist/react/builder/Values.mjs +85 -0
- package/dist/react/builder/WidgetBuilder.mjs +50 -49
- package/dist/react/builder/base.d.mts +5 -0
- package/dist/react/builder/base.mjs +33 -8
- package/dist/react/builder/calc.mjs +15 -1
- package/dist/react/builder/escape.d.mts +1 -0
- package/dist/react/builder/escape.mjs +62 -0
- package/dist/react/builder/filter-tree.d.mts +9 -0
- package/dist/react/builder/filter-tree.mjs +186 -0
- package/dist/react/builder/formula-parse.d.mts +18 -0
- package/dist/react/builder/formula-parse.mjs +136 -0
- package/dist/react/builder/labels.d.mts +1 -1
- package/dist/react/builder/state.d.mts +2 -1
- package/dist/react/builder/state.mjs +23 -37
- package/dist/react/builder/useBuilder.d.mts +12 -1
- package/dist/react/builder/useBuilder.mjs +6 -3
- package/dist/react/builder/words.d.mts +59 -0
- package/dist/react/builder/words.mjs +73 -0
- package/dist/react/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +28 -1
- package/dist/react/context.mjs +25 -4
- package/dist/react/drill/Bars.mjs +179 -0
- package/dist/react/drill/Controls.mjs +173 -0
- package/dist/react/drill/DashboardTile.d.mts +18 -0
- package/dist/react/drill/DashboardTile.mjs +107 -0
- package/dist/react/drill/DrillPanel.d.mts +31 -0
- package/dist/react/drill/DrillPanel.mjs +104 -0
- package/dist/react/drill/DrillTabs.mjs +52 -0
- package/dist/react/drill/Header.mjs +131 -0
- package/dist/react/drill/Items.d.mts +22 -0
- package/dist/react/drill/Items.mjs +164 -0
- package/dist/react/drill/ItemsFoot.mjs +60 -0
- package/dist/react/drill/Notes.mjs +58 -0
- package/dist/react/drill/PanelBody.mjs +74 -0
- package/dist/react/drill/PanelStates.mjs +37 -0
- package/dist/react/drill/board.d.mts +18 -0
- package/dist/react/drill/board.mjs +91 -0
- package/dist/react/drill/counts.mjs +14 -0
- package/dist/react/drill/host.mjs +26 -0
- package/dist/react/drill/item-parts.d.mts +5 -0
- package/dist/react/drill/item-parts.mjs +76 -0
- package/dist/react/drill/item-type.d.mts +26 -0
- package/dist/react/drill/item-type.mjs +7 -0
- package/dist/react/drill/lazy.d.mts +6 -0
- package/dist/react/drill/lazy.mjs +17 -0
- package/dist/react/drill/pages.mjs +48 -0
- package/dist/react/drill/panel-focus.mjs +51 -0
- package/dist/react/drill/props.d.mts +25 -0
- package/dist/react/drill/props.mjs +72 -0
- package/dist/react/drill/state.d.mts +18 -0
- package/dist/react/drill/state.mjs +68 -0
- package/dist/react/drill/useDrill.d.mts +46 -0
- package/dist/react/drill/useDrill.mjs +194 -0
- package/dist/react/drill/words.d.mts +101 -0
- package/dist/react/drill/words.mjs +79 -0
- package/dist/react/english.mjs +29 -6
- package/dist/react/filters/bar.d.mts +12 -0
- package/dist/react/filters/bar.mjs +135 -0
- package/dist/react/filters/calendar.mjs +193 -0
- package/dist/react/filters/chip.mjs +174 -0
- package/dist/react/filters/context.d.mts +22 -0
- package/dist/react/filters/context.mjs +78 -0
- package/dist/react/filters/dates.mjs +89 -0
- package/dist/react/filters/days.d.mts +36 -0
- package/dist/react/filters/days.mjs +87 -0
- package/dist/react/filters/field-step.mjs +81 -0
- package/dist/react/filters/hooks.d.mts +34 -0
- package/dist/react/filters/hooks.mjs +94 -0
- package/dist/react/filters/listbox.mjs +131 -0
- package/dist/react/filters/logic.d.mts +59 -0
- package/dist/react/filters/logic.mjs +109 -0
- package/dist/react/filters/menu-search.mjs +211 -0
- package/dist/react/filters/menu.mjs +85 -0
- package/dist/react/filters/number.mjs +127 -0
- package/dist/react/filters/numbers.d.mts +47 -0
- package/dist/react/filters/numbers.mjs +151 -0
- package/dist/react/filters/operator.mjs +104 -0
- package/dist/react/filters/phone.mjs +104 -0
- package/dist/react/filters/popover.d.mts +19 -0
- package/dist/react/filters/popover.mjs +153 -0
- package/dist/react/filters/rules.d.mts +8 -0
- package/dist/react/filters/rules.mjs +55 -0
- package/dist/react/filters/sheet.mjs +196 -0
- package/dist/react/filters/state.mjs +132 -0
- package/dist/react/filters/suggest.d.mts +47 -0
- package/dist/react/filters/suggest.mjs +97 -0
- package/dist/react/filters/values.mjs +166 -0
- package/dist/react/filters/words.d.mts +81 -0
- package/dist/react/filters/words.mjs +73 -0
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +45 -16
- package/dist/react/index.d.mts +34 -5
- package/dist/react/index.mjs +15 -4
- package/dist/react/messages.d.mts +47 -2
- package/dist/react/place.mjs +7 -3
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +116 -14
- package/dist/react/renderers/list.d.mts +22 -0
- package/dist/react/renderers/list.mjs +118 -0
- package/dist/react/review-words.mjs +1 -1
- package/dist/react/review.mjs +2 -2
- package/dist/react/scope.mjs +2 -7
- package/dist/react/series.d.mts +54 -0
- package/dist/react/series.mjs +191 -0
- package/dist/react/theme.css +2734 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +7 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +4 -0
- package/dist/react/useDashboard.mjs +8 -1
- package/dist/react/useTiles.mjs +50 -15
- package/dist/react/view-grid.mjs +16 -0
- package/dist/react/view.d.mts +9 -0
- package/dist/react/view.mjs +22 -10
- package/dist/reading.d.mts +2 -0
- package/dist/reading.mjs +9 -1
- package/dist/recharts/axes.mjs +28 -0
- package/dist/recharts/axis.mjs +84 -0
- package/dist/recharts/bar.d.mts +7 -0
- package/dist/recharts/bar.mjs +140 -0
- package/dist/recharts/charts.d.mts +4 -6
- package/dist/recharts/charts.mjs +2 -114
- package/dist/recharts/index.d.mts +5 -3
- package/dist/recharts/index.mjs +6 -3
- package/dist/recharts/line.d.mts +2 -0
- package/dist/recharts/line.mjs +111 -0
- package/dist/recharts/marks.mjs +112 -0
- package/dist/recharts/parts.mjs +88 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/recharts/table.mjs +71 -0
- package/dist/records-read.mjs +44 -0
- package/dist/registry/filter-bar.json +26 -0
- package/dist/skills/derive-dashboards/SKILL.md +69 -0
- package/dist/store/apply.mjs +5 -5
- package/dist/store/commands.mjs +4 -4
- package/dist/store/discard.mjs +7 -7
- package/dist/store/drafts.mjs +5 -5
- package/dist/store/editor.mjs +1 -1
- package/dist/store/publish.mjs +12 -12
- package/dist/store/reader.mjs +41 -22
- package/dist/store/review.mjs +16 -16
- package/dist/store/rows.mjs +20 -20
- package/dist/store/undo.mjs +3 -3
- package/dist/store/unpublished.mjs +4 -4
- package/dist/store/versions.mjs +14 -14
- package/dist/testing/adapter-suite.mjs +4 -4
- package/dist/tiles.mjs +37 -3
- package/package.json +12 -10
- package/dist/react/FilterBar.mjs +0 -119
- package/dist/react/Records.d.mts +0 -12
- package/dist/react/Records.mjs +0 -97
- package/src/adapter/sql-adapter.ts +0 -95
- package/src/adapter/statement.ts +0 -185
- package/src/authorize.ts +0 -73
- package/src/body.ts +0 -169
- package/src/bounded.ts +0 -43
- package/src/cache.ts +0 -192
- package/src/checks.ts +0 -170
- package/src/custom-source.ts +0 -59
- package/src/dashboard-id.ts +0 -36
- package/src/dashboards.ts +0 -132
- package/src/editing.ts +0 -148
- package/src/endpoints/access.ts +0 -41
- package/src/endpoints/dashboards.ts +0 -92
- package/src/endpoints/drafts.ts +0 -138
- package/src/endpoints/index.ts +0 -21
- package/src/endpoints/meta.ts +0 -137
- package/src/endpoints/query.ts +0 -86
- package/src/endpoints/read.ts +0 -92
- package/src/endpoints/review.ts +0 -89
- package/src/endpoints/values.ts +0 -62
- package/src/endpoints/versions.ts +0 -104
- package/src/execute.ts +0 -207
- package/src/handler.ts +0 -232
- package/src/http.ts +0 -66
- package/src/index.ts +0 -163
- package/src/introspect.ts +0 -205
- package/src/mcp/api.ts +0 -59
- package/src/mcp/format.ts +0 -67
- package/src/mcp/index.ts +0 -151
- package/src/mcp/query.ts +0 -153
- package/src/mcp/resolve.ts +0 -114
- package/src/node-postgres.ts +0 -81
- package/src/owner.ts +0 -36
- package/src/postgres-connection.ts +0 -143
- package/src/postgres-store.ts +0 -82
- package/src/principal.ts +0 -39
- package/src/reading.ts +0 -56
- package/src/request-rows.ts +0 -23
- package/src/request.ts +0 -22
- package/src/storage.ts +0 -63
- package/src/store/apply.ts +0 -129
- package/src/store/commands.ts +0 -75
- package/src/store/conflicts.ts +0 -98
- package/src/store/create-tables.ts +0 -104
- package/src/store/discard.ts +0 -42
- package/src/store/drafts.ts +0 -133
- package/src/store/editor.ts +0 -28
- package/src/store/log.ts +0 -28
- package/src/store/publish.ts +0 -199
- package/src/store/publisher.ts +0 -21
- package/src/store/reader.ts +0 -139
- package/src/store/review.ts +0 -239
- package/src/store/rows.ts +0 -250
- package/src/store/tenant.ts +0 -28
- package/src/store/undo.ts +0 -56
- package/src/store/unpublished.ts +0 -33
- package/src/store/versions.ts +0 -106
- package/src/store/writer.ts +0 -19
- package/src/testing/adapter-suite.ts +0 -239
- package/src/testing/index.ts +0 -2
- package/src/tile-doc.ts +0 -46
- package/src/tiles.ts +0 -120
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Op, ViewerRef, WireFilter } from "../query/filter.mjs";
|
|
2
2
|
import { Column, ConnectionId, DimensionName, IanaZone, JoinName, MeasureName, PolicyName, Primitive, SourceName, TenantKey } from "../types/primitives.mjs";
|
|
3
3
|
import { Channel } from "../types/viewer.mjs";
|
|
4
|
+
import { DimensionHints, Noun, RecordsHint } from "./hints.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* The semantic model: plain data, owned by the host as code. Tenancy and row access are part
|
|
6
7
|
* of it, and both are opt-in: with tenant keys, no source can be queried outside its tenant.
|
|
@@ -125,11 +126,8 @@ export type SourceDef = SourceRelation & {
|
|
|
125
126
|
acknowledgeOpenPolicy?: true;
|
|
126
127
|
/** Always applied, for example `removed_at` is not set. Shown in the receipt. */
|
|
127
128
|
where?: WireFilter;
|
|
128
|
-
records?:
|
|
129
|
-
|
|
130
|
-
columns: readonly DimensionName[];
|
|
131
|
-
link?: string;
|
|
132
|
-
};
|
|
129
|
+
records?: RecordsHint;
|
|
130
|
+
noun?: Noun;
|
|
133
131
|
joins?: Record<JoinName, JoinDef>;
|
|
134
132
|
measures: Record<MeasureName, MeasureDef>;
|
|
135
133
|
dimensions: Record<DimensionName, DimensionDef>;
|
|
@@ -137,6 +135,10 @@ export type SourceDef = SourceRelation & {
|
|
|
137
135
|
limits?: {
|
|
138
136
|
maxWindowDays?: number;
|
|
139
137
|
};
|
|
138
|
+
/** Drill-in: Breakdown's field order (`prefer`), or `false` never to drill into this source. */
|
|
139
|
+
drill?: false | {
|
|
140
|
+
prefer: readonly string[];
|
|
141
|
+
};
|
|
140
142
|
};
|
|
141
143
|
export type MemberMeta = {
|
|
142
144
|
label?: string;
|
|
@@ -155,6 +157,15 @@ export type Numeric = "float" | {
|
|
|
155
157
|
scale: number;
|
|
156
158
|
stored: "decimal" | "minor_units";
|
|
157
159
|
};
|
|
160
|
+
/** What every measure over a column may add: rows it reads, a duration format, a partition. */
|
|
161
|
+
type OverColumn = {
|
|
162
|
+
of: Column | Expr;
|
|
163
|
+
where?: WireFilter;
|
|
164
|
+
/** `duration`: the values are seconds, shown as "3.7 days", "2 h". */
|
|
165
|
+
format?: "duration";
|
|
166
|
+
/** Reserved for snapshot measures (the last value per partition). Refused by the model check until computed. */
|
|
167
|
+
partitionBy?: DimensionName;
|
|
168
|
+
};
|
|
158
169
|
/** One aggregate per measure, so each has one result type and one merge rule. */
|
|
159
170
|
export type MeasureDef = MemberMeta & {
|
|
160
171
|
/** How partial results combine. `none` means they cannot be combined. */
|
|
@@ -163,26 +174,17 @@ export type MeasureDef = MemberMeta & {
|
|
|
163
174
|
kind: "count";
|
|
164
175
|
distinct?: Column;
|
|
165
176
|
where?: WireFilter;
|
|
166
|
-
} | {
|
|
177
|
+
} | ({
|
|
167
178
|
kind: "sum" | "min" | "max";
|
|
168
|
-
of: Column | Expr;
|
|
169
179
|
numeric: Numeric;
|
|
170
|
-
where?: WireFilter;
|
|
171
180
|
unit?: Unit;
|
|
172
|
-
|
|
173
|
-
} | {
|
|
181
|
+
} & OverColumn) | ({
|
|
174
182
|
kind: "avg";
|
|
175
|
-
of: Column | Expr;
|
|
176
183
|
numeric: Numeric;
|
|
177
|
-
|
|
178
|
-
partitionBy?: DimensionName;
|
|
179
|
-
} | {
|
|
184
|
+
} & OverColumn) | ({
|
|
180
185
|
kind: "percentile";
|
|
181
|
-
of: Column | Expr;
|
|
182
186
|
p: 50 | 75 | 90 | 95 | 99;
|
|
183
|
-
|
|
184
|
-
partitionBy?: DimensionName;
|
|
185
|
-
} | {
|
|
187
|
+
} & OverColumn) | {
|
|
186
188
|
kind: "ratio";
|
|
187
189
|
numerator: MeasureName;
|
|
188
190
|
denominator: MeasureName;
|
|
@@ -201,7 +203,7 @@ export type TimeStorage = "timestamptz" | "date" | "epoch_ms" | "epoch_s" | {
|
|
|
201
203
|
fractionDigits: number;
|
|
202
204
|
};
|
|
203
205
|
} | "text_parseable";
|
|
204
|
-
export type DimensionDef = MemberMeta & ({
|
|
206
|
+
export type DimensionDef = MemberMeta & DimensionHints & ({
|
|
205
207
|
kind: "string";
|
|
206
208
|
column: Column;
|
|
207
209
|
values?: readonly string[] | "lookup";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { parseMemberId } from "../member.mjs";
|
|
2
|
+
import { when } from "./issues.mjs";
|
|
3
|
+
// src/model/validate/drill.ts
|
|
4
|
+
/** Whether a `drill.prefer` entry names a dimension, `join.dimension`, or a join. */
|
|
5
|
+
function names(source, entry) {
|
|
6
|
+
const ref = parseMemberId(`source.${entry}`);
|
|
7
|
+
if (ref === void 0) return false;
|
|
8
|
+
if (ref.join !== void 0) return source.joins?.[ref.join] !== void 0;
|
|
9
|
+
return source.dimensions[ref.name] !== void 0 || source.joins?.[ref.name] !== void 0;
|
|
10
|
+
}
|
|
11
|
+
/** A dimension's hints fit it: a format on a number, tones for values it declares. */
|
|
12
|
+
function dimensionHintIssues(def, path) {
|
|
13
|
+
const declared = def.kind === "string" && Array.isArray(def.values) ? def.values : [];
|
|
14
|
+
const tones = Object.keys(def.tones ?? {});
|
|
15
|
+
return [
|
|
16
|
+
...when(def.buckets !== void 0 && (def.kind !== "number" || def.buckets.length === 0 || def.buckets.some((e, i) => i > 0 && e <= (def.buckets?.[i - 1] ?? e))), "HINT_INVALID", [...path, "buckets"], "Bucket edges sit on a number dimension and go up, one after another."),
|
|
17
|
+
...when(def.format !== void 0 && def.kind !== "number", "HINT_INVALID", [...path, "format"], "A number format sits on a number dimension."),
|
|
18
|
+
...tones.flatMap((value) => when(!declared.includes(value), "HINT_INVALID", [
|
|
19
|
+
...path,
|
|
20
|
+
"tones",
|
|
21
|
+
value
|
|
22
|
+
], `"${value}" is not one of the dimension's declared values.`))
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
/** The keys a `records` hint may have; `link` was removed (routes live in `itemLinks`). */
|
|
26
|
+
const RECORDS_KEYS = Object.freeze({
|
|
27
|
+
order: true,
|
|
28
|
+
columns: true,
|
|
29
|
+
title: true,
|
|
30
|
+
key: true
|
|
31
|
+
});
|
|
32
|
+
/** A `records` hint has only its own keys, a `key` of "expose" or "hide", and a title a list may show. */
|
|
33
|
+
function recordsIssues(source, path) {
|
|
34
|
+
const records = source.records;
|
|
35
|
+
if (records === void 0) return [];
|
|
36
|
+
const at = [...path, "records"];
|
|
37
|
+
const title = source.records?.title;
|
|
38
|
+
const titled = title === void 0 ? void 0 : source.dimensions[title];
|
|
39
|
+
const key = source.records?.key;
|
|
40
|
+
return [
|
|
41
|
+
...Object.keys(records).flatMap((k) => when(!Object.hasOwn(RECORDS_KEYS, k), "MODEL_SHAPE", [...at, k], k === "link" ? "records.link was removed: pass itemLinks to deriveDashboards and the React UI instead." : `records has no "${k}": it takes order, columns, title and key.`)),
|
|
42
|
+
...when(key !== void 0 && key !== "expose" && key !== "hide", "HINT_INVALID", [...at, "key"], `records.key is "expose" or "hide", not ${JSON.stringify(key)}.`),
|
|
43
|
+
...when(titled !== void 0 && (titled.sensitive === true || titled.hidden === true), "HINT_INVALID", [...at, "title"], "A records title is never a sensitive or hidden field: it shows on every item.")
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/** Each drill and records hint resolves: preferred fields, the records title, tones and formats. */
|
|
47
|
+
function drillIssues(source, path) {
|
|
48
|
+
const prefer = source.drill === false ? [] : source.drill?.prefer ?? [];
|
|
49
|
+
const title = source.records?.title;
|
|
50
|
+
return [
|
|
51
|
+
...recordsIssues(source, path),
|
|
52
|
+
...prefer.flatMap((entry, i) => when(!names(source, entry), "DRILL_PREFER_UNKNOWN", [
|
|
53
|
+
...path,
|
|
54
|
+
"drill",
|
|
55
|
+
"prefer",
|
|
56
|
+
i
|
|
57
|
+
], `"${entry}" is not a dimension, a join or a join's dimension of this source.`)),
|
|
58
|
+
...when(title !== void 0 && source.dimensions[title] === void 0, "HINT_INVALID", [
|
|
59
|
+
...path,
|
|
60
|
+
"records",
|
|
61
|
+
"title"
|
|
62
|
+
], `There is no dimension named "${title ?? ""}".`),
|
|
63
|
+
...Object.entries(source.dimensions).flatMap(([name, def]) => dimensionHintIssues(def, [
|
|
64
|
+
...path,
|
|
65
|
+
"dimensions",
|
|
66
|
+
name
|
|
67
|
+
]))
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
export { drillIssues };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { nameIssues, when } from "./issues.mjs";
|
|
2
2
|
import { rowPolicyIssues } from "./policy.mjs";
|
|
3
|
+
import { shapeIssues } from "./shape.mjs";
|
|
3
4
|
import { sourceIssues } from "./source.mjs";
|
|
4
5
|
import { viaCycleIssues } from "./via.mjs";
|
|
5
6
|
// src/model/validate/index.ts
|
|
@@ -11,6 +12,8 @@ import { viaCycleIssues } from "./via.mjs";
|
|
|
11
12
|
* job of the `check` command.
|
|
12
13
|
*/
|
|
13
14
|
function validateModel(model) {
|
|
15
|
+
const shaped = shapeIssues(model);
|
|
16
|
+
if (shaped.length > 0) return [...headerIssues(model), ...shaped];
|
|
14
17
|
const sources = Object.entries(model.sources ?? {});
|
|
15
18
|
return [
|
|
16
19
|
...headerIssues(model),
|
|
@@ -64,10 +64,13 @@ function numericIssues(numeric, path) {
|
|
|
64
64
|
const ok = Number.isInteger(numeric.scale) && numeric.scale >= 0 && numeric.scale <= 38;
|
|
65
65
|
return when(!ok, "NUMERIC_SCALE", [...path, "scale"], "The scale must be a whole number, 0 to 38.");
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
/**
|
|
68
|
+
* A snapshot measure (`partitionBy`) is refused until the engines compute its meaning, the last
|
|
69
|
+
* value per partition in a bucket: accepting it now would answer an ordinary aggregate where the
|
|
70
|
+
* model's author asked for a snapshot.
|
|
71
|
+
*/
|
|
72
|
+
function partitionIssues(_source, measure, path) {
|
|
73
|
+
return when(measure.partitionBy !== void 0, "PARTITION_UNSUPPORTED", path, "Snapshot measures (partitionBy) are not computed yet: remove it, or model the snapshot as a source of last rows.");
|
|
71
74
|
}
|
|
72
75
|
function percentileIssues(measure, path) {
|
|
73
76
|
const bad = measure.kind === "percentile" && measure.merge !== "none";
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { issue } from "./issues.mjs";
|
|
2
|
+
// src/model/validate/shape.ts
|
|
3
|
+
const MEASURE_KINDS = [
|
|
4
|
+
"count",
|
|
5
|
+
"sum",
|
|
6
|
+
"min",
|
|
7
|
+
"max",
|
|
8
|
+
"avg",
|
|
9
|
+
"percentile",
|
|
10
|
+
"ratio"
|
|
11
|
+
];
|
|
12
|
+
const MERGES = [
|
|
13
|
+
"sum",
|
|
14
|
+
"min",
|
|
15
|
+
"max",
|
|
16
|
+
"none"
|
|
17
|
+
];
|
|
18
|
+
const PERCENTILES = [
|
|
19
|
+
50,
|
|
20
|
+
75,
|
|
21
|
+
90,
|
|
22
|
+
95,
|
|
23
|
+
99
|
|
24
|
+
];
|
|
25
|
+
const DIMENSION_KINDS = [
|
|
26
|
+
"string",
|
|
27
|
+
"number",
|
|
28
|
+
"boolean",
|
|
29
|
+
"time",
|
|
30
|
+
"ref",
|
|
31
|
+
"bucket",
|
|
32
|
+
"expr"
|
|
33
|
+
];
|
|
34
|
+
const STORAGES = [
|
|
35
|
+
"timestamptz",
|
|
36
|
+
"date",
|
|
37
|
+
"epoch_ms",
|
|
38
|
+
"epoch_s",
|
|
39
|
+
"text_parseable"
|
|
40
|
+
];
|
|
41
|
+
const isObject = (v) => typeof v === "object" && v !== null;
|
|
42
|
+
const known = (list, value) => list.includes(value);
|
|
43
|
+
const shape = (path, message) => issue("MODEL_SHAPE", path, message);
|
|
44
|
+
const oneOf = (list) => list.map((v) => JSON.stringify(v)).join(", ");
|
|
45
|
+
/** Fields a kind needs, each named when missing. */
|
|
46
|
+
function needs(m, fields, path) {
|
|
47
|
+
return fields.flatMap((f) => m[f] === void 0 ? [shape([...path, f], `A ${String(m["kind"])} needs "${f}".`)] : []);
|
|
48
|
+
}
|
|
49
|
+
function measureShape(m, path) {
|
|
50
|
+
if (!isObject(m)) return [shape(path, "A measure is an object.")];
|
|
51
|
+
if (!known(MEASURE_KINDS, m["kind"])) return [shape([...path, "kind"], `"${String(m["kind"])}" is not a measure kind: ${oneOf(MEASURE_KINDS)}.`)];
|
|
52
|
+
if (m["kind"] === "ratio") return needs(m, ["numerator", "denominator"], path);
|
|
53
|
+
const merge = known(MERGES, m["merge"]) ? [] : [shape([...path, "merge"], `"${String(m["merge"])}" is not a merge: ${oneOf(MERGES)}.`)];
|
|
54
|
+
if (m["kind"] === "count") return merge;
|
|
55
|
+
const fields = m["kind"] === "percentile" ? ["of", "p"] : ["of", "numeric"];
|
|
56
|
+
const p = m["kind"] === "percentile" && m["p"] !== void 0 && !known(PERCENTILES, m["p"]) ? [shape([...path, "p"], `A percentile is one of ${oneOf(PERCENTILES)}.`)] : [];
|
|
57
|
+
return [
|
|
58
|
+
...merge,
|
|
59
|
+
...needs(m, fields, path),
|
|
60
|
+
...p
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
function storageShape(storage, path) {
|
|
64
|
+
if (typeof storage === "string" && known(STORAGES, storage)) return [];
|
|
65
|
+
if (isObject(storage) && ("timestamp" in storage || "iso_utc_fixed" in storage)) return [];
|
|
66
|
+
return [shape(path, `${JSON.stringify(storage)} is not a time storage: ${oneOf(STORAGES)}, { timestamp: { zone, ... } } or { iso_utc_fixed: { ... } }.`)];
|
|
67
|
+
}
|
|
68
|
+
const DIMENSION_NEEDS = {
|
|
69
|
+
string: ["column"],
|
|
70
|
+
number: ["column"],
|
|
71
|
+
boolean: ["column"],
|
|
72
|
+
time: ["column", "storage"],
|
|
73
|
+
ref: ["join", "label"],
|
|
74
|
+
bucket: [
|
|
75
|
+
"of",
|
|
76
|
+
"edges",
|
|
77
|
+
"labels"
|
|
78
|
+
],
|
|
79
|
+
expr: ["expr", "type"]
|
|
80
|
+
};
|
|
81
|
+
function dimensionShape(d, path) {
|
|
82
|
+
if (!isObject(d)) return [shape(path, "A dimension is an object.")];
|
|
83
|
+
const kind = d["kind"];
|
|
84
|
+
if (typeof kind !== "string" || !known(DIMENSION_KINDS, kind)) return [shape([...path, "kind"], `"${String(kind)}" is not a dimension kind: ${oneOf(DIMENSION_KINDS)}.`)];
|
|
85
|
+
const missing = needs(d, DIMENSION_NEEDS[kind] ?? [], path);
|
|
86
|
+
if (missing.length > 0) return missing;
|
|
87
|
+
if (kind === "time") return storageShape(d["storage"], [...path, "storage"]);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
/** Every member of every source whose shape is wrong, before any check reads it. */
|
|
91
|
+
function shapeIssues(model) {
|
|
92
|
+
const sources = model.sources;
|
|
93
|
+
if (!isObject(sources)) return [shape(["sources"], "A model's sources are an object, by name.")];
|
|
94
|
+
return Object.entries(sources).flatMap(([name, source]) => {
|
|
95
|
+
const path = ["sources", name];
|
|
96
|
+
if (!isObject(source)) return [shape(path, "A source is an object.")];
|
|
97
|
+
const measures = isObject(source["measures"]) ? source["measures"] : {};
|
|
98
|
+
const dimensions = isObject(source["dimensions"]) ? source["dimensions"] : {};
|
|
99
|
+
return [
|
|
100
|
+
...needs({
|
|
101
|
+
kind: "source",
|
|
102
|
+
...source
|
|
103
|
+
}, [
|
|
104
|
+
"in",
|
|
105
|
+
"key",
|
|
106
|
+
"measures",
|
|
107
|
+
"dimensions"
|
|
108
|
+
], path),
|
|
109
|
+
...Object.entries(measures).flatMap(([m, def]) => measureShape(def, [
|
|
110
|
+
...path,
|
|
111
|
+
"measures",
|
|
112
|
+
m
|
|
113
|
+
])),
|
|
114
|
+
...Object.entries(dimensions).flatMap(([d, def]) => dimensionShape(def, [
|
|
115
|
+
...path,
|
|
116
|
+
"dimensions",
|
|
117
|
+
d
|
|
118
|
+
])),
|
|
119
|
+
...hintShape(source, path)
|
|
120
|
+
];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Each entry of `records.order` is a field and a direction: `["createdAt", "desc"]`. */
|
|
124
|
+
function orderShape(order, path) {
|
|
125
|
+
if (!Array.isArray(order)) return [];
|
|
126
|
+
return order.flatMap((entry, i) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && (entry[1] === "asc" || entry[1] === "desc") ? [] : [shape([...path, i], "Each order entry is a field and a direction: [\"createdAt\", \"desc\"].")]);
|
|
127
|
+
}
|
|
128
|
+
/** A source's `records` (its lists) and `noun` (its two words), shaped so later checks can read them. */
|
|
129
|
+
function hintShape(source, path) {
|
|
130
|
+
const records = source["records"];
|
|
131
|
+
const noun = source["noun"];
|
|
132
|
+
const list = (key) => isObject(records) && records[key] !== void 0 && !Array.isArray(records[key]) ? [shape([
|
|
133
|
+
...path,
|
|
134
|
+
"records",
|
|
135
|
+
key
|
|
136
|
+
], `records.${key} is a list.`)] : [];
|
|
137
|
+
const words = isObject(noun) && typeof noun["one"] === "string" && typeof noun["other"] === "string";
|
|
138
|
+
return [
|
|
139
|
+
...records === void 0 || isObject(records) ? [] : [shape([...path, "records"], "records is an object: { title, columns, order, key }.")],
|
|
140
|
+
...list("columns"),
|
|
141
|
+
...list("order"),
|
|
142
|
+
...orderShape(isObject(records) ? records["order"] : void 0, [
|
|
143
|
+
...path,
|
|
144
|
+
"records",
|
|
145
|
+
"order"
|
|
146
|
+
]),
|
|
147
|
+
...noun === void 0 || words ? [] : [shape([...path, "noun"], "noun is { one: \"order\", other: \"orders\" }.")]
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
export { shapeIssues };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tenantKeys } from "../defaults.mjs";
|
|
2
|
+
import { drillIssues } from "./drill.mjs";
|
|
2
3
|
import { modelFilterIssues } from "./filter.mjs";
|
|
3
4
|
import { issue, nameIssues, when } from "./issues.mjs";
|
|
4
5
|
import { dimensionIssues, measureIssues } from "./members.mjs";
|
|
@@ -18,7 +19,8 @@ function sourceIssues(model, name, source) {
|
|
|
18
19
|
...filterIssues(model, name, source, path),
|
|
19
20
|
...memberIssues(model, name, source, path),
|
|
20
21
|
...timeIssues(source, [...path, "time"]),
|
|
21
|
-
...recordIssues(source, [...path, "records"])
|
|
22
|
+
...recordIssues(source, [...path, "records"]),
|
|
23
|
+
...drillIssues(source, path)
|
|
22
24
|
];
|
|
23
25
|
}
|
|
24
26
|
/** One SELECT, optionally behind WITH; a trailing semicolon is allowed, none inside. */
|
|
@@ -122,7 +124,7 @@ function recordIssues(source, path) {
|
|
|
122
124
|
const def = source.dimensions?.[column];
|
|
123
125
|
return when(def?.sensitive === true || def?.hidden === true, "RECORD_COLUMN_SENSITIVE", at, `"${column}" is ${def?.sensitive === true ? "sensitive" : "hidden"}, so the records cannot show or be ordered by it: they are shown to everyone who sees the tile.`);
|
|
124
126
|
};
|
|
125
|
-
return [...records.columns.flatMap((column, i) => [...unknown(column, [
|
|
127
|
+
return [...(records.columns ?? []).flatMap((column, i) => [...unknown(column, [
|
|
126
128
|
...path,
|
|
127
129
|
"columns",
|
|
128
130
|
i
|
|
@@ -130,7 +132,7 @@ function recordIssues(source, path) {
|
|
|
130
132
|
...path,
|
|
131
133
|
"columns",
|
|
132
134
|
i
|
|
133
|
-
])]), ...records.order.flatMap(([column], i) => [...unknown(column, [
|
|
135
|
+
])]), ...(records.order ?? []).flatMap(([column], i) => [...unknown(column, [
|
|
134
136
|
...path,
|
|
135
137
|
"order",
|
|
136
138
|
i
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WireFilter } from "../query/filter.mjs";
|
|
2
|
+
import { WireQuery } from "../query/types.mjs";
|
|
3
|
+
import { Principal } from "../types/viewer.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* The filter with every viewer reference (`{ viewer: "id" }`) replaced by the signed-in viewer's
|
|
6
|
+
* values, as a row policy binds them. When a value is missing (a public link, a viewer without
|
|
7
|
+
* that attribute), the whole filter matches no rows: a missing value never makes a negated leaf
|
|
8
|
+
* true. Variables are left as they are.
|
|
9
|
+
*/
|
|
10
|
+
export declare function bindViewer(filter: WireFilter, principal: Principal): WireFilter;
|
|
11
|
+
/** The query with the viewer bound in its filters and in each measure's own filter. */
|
|
12
|
+
export declare function bindQueryViewer(query: WireQuery, principal: Principal): WireQuery;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { viewerValues } from "./bind.mjs";
|
|
2
|
+
// src/policy/bind-query.ts
|
|
3
|
+
/** No rows: what a filter is when a viewer value it needs is missing. */
|
|
4
|
+
const NOTHING = { any: [] };
|
|
5
|
+
var Missing = class extends Error {};
|
|
6
|
+
function walk(filter, viewer) {
|
|
7
|
+
if ("all" in filter) return { all: filter.all.map((f) => walk(f, viewer)) };
|
|
8
|
+
if ("any" in filter) return { any: filter.any.map((f) => walk(f, viewer)) };
|
|
9
|
+
if ("not" in filter) return { not: walk(filter.not, viewer) };
|
|
10
|
+
if ("some" in filter) return { some: {
|
|
11
|
+
...filter.some,
|
|
12
|
+
where: walk(filter.some.where, viewer)
|
|
13
|
+
} };
|
|
14
|
+
if ("none" in filter) return { none: {
|
|
15
|
+
...filter.none,
|
|
16
|
+
where: walk(filter.none.where, viewer)
|
|
17
|
+
} };
|
|
18
|
+
if (!("viewer" in filter)) return filter;
|
|
19
|
+
const values = viewer === void 0 ? [] : viewerValues(viewer, filter.viewer);
|
|
20
|
+
if (values.length === 0) throw new Missing();
|
|
21
|
+
return {
|
|
22
|
+
member: filter.member,
|
|
23
|
+
op: filter.op,
|
|
24
|
+
values
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The filter with every viewer reference (`{ viewer: "id" }`) replaced by the signed-in viewer's
|
|
29
|
+
* values, as a row policy binds them. When a value is missing (a public link, a viewer without
|
|
30
|
+
* that attribute), the whole filter matches no rows: a missing value never makes a negated leaf
|
|
31
|
+
* true. Variables are left as they are.
|
|
32
|
+
*/
|
|
33
|
+
function bindViewer(filter, principal) {
|
|
34
|
+
const viewer = principal.channel === "user" ? principal.viewer : void 0;
|
|
35
|
+
try {
|
|
36
|
+
return walk(filter, viewer);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof Missing) return NOTHING;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The query with the viewer bound in its filters and in each measure's own filter. */
|
|
43
|
+
function bindQueryViewer(query, principal) {
|
|
44
|
+
return {
|
|
45
|
+
...query,
|
|
46
|
+
...query.filters === void 0 ? {} : { filters: bindViewer(query.filters, principal) },
|
|
47
|
+
measures: query.measures.map((m) => m.filter === void 0 ? m : {
|
|
48
|
+
...m,
|
|
49
|
+
filter: bindViewer(m.filter, principal)
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { bindQueryViewer, bindViewer };
|
|
@@ -11,4 +11,10 @@ function aliasPart(alias) {
|
|
|
11
11
|
index
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
/** A line's alias (`m1`, `c2`) read from text, as a drill names the line clicked; undefined for anything else. */
|
|
15
|
+
function lineAlias(text) {
|
|
16
|
+
if (!/^[mc][1-9]\d*$/u.test(text)) return void 0;
|
|
17
|
+
const n = Number(text.slice(1));
|
|
18
|
+
return text.startsWith("m") ? `m${n}` : `c${n}`;
|
|
19
|
+
}
|
|
20
|
+
export { aliasPart, lineAlias };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Model } from "../../model/types.mjs";
|
|
2
|
+
import { WireQuery } from "../types.mjs";
|
|
3
|
+
import { Readable } from "./fields.mjs";
|
|
4
|
+
import { DrillClock } from "./time.mjs";
|
|
5
|
+
import { Drill } from "./types.mjs";
|
|
6
|
+
export type DrillInput = {
|
|
7
|
+
model: Model;
|
|
8
|
+
/** The tile's query as composed: its filters, picks and range already in it. */
|
|
9
|
+
query: WireQuery;
|
|
10
|
+
drill: Drill;
|
|
11
|
+
readable: Readable;
|
|
12
|
+
clock: DrillClock;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The rows behind a drill, as a query with no grouping: the tile's own query (its filters,
|
|
16
|
+
* picks, range and measures) with each step's values ANDed on as filters and its time windows
|
|
17
|
+
* narrowing the range. The lock, required filters, tenancy and row rules travel apart, as for
|
|
18
|
+
* the tile. A calc that reads around its row (a total, a bucket, the period before) is left
|
|
19
|
+
* out: on rows with no grouping it would read the wrong scope. The server evaluates it from
|
|
20
|
+
* each scope's own read (`drillScopes`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function composeDrill(input: DrillInput): WireQuery;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { EngineError } from "../../error/refusal.mjs";
|
|
2
|
+
import { drillableMembers } from "./fields.mjs";
|
|
3
|
+
import { aroundCalcs } from "./scopes.mjs";
|
|
4
|
+
import { stepMembers } from "./steps.mjs";
|
|
5
|
+
import { drilledTime } from "./time.mjs";
|
|
6
|
+
import "./types.mjs";
|
|
7
|
+
// src/query/drill/compose.ts
|
|
8
|
+
const refuse = (message) => {
|
|
9
|
+
throw new EngineError("SELECTION_INVALID", message);
|
|
10
|
+
};
|
|
11
|
+
/** One field at one value; no value is the rows where it is not set. */
|
|
12
|
+
function equalsLeaf(member, value) {
|
|
13
|
+
return value === null ? {
|
|
14
|
+
member,
|
|
15
|
+
op: "notSet",
|
|
16
|
+
values: []
|
|
17
|
+
} : {
|
|
18
|
+
member,
|
|
19
|
+
op: "equals",
|
|
20
|
+
values: [value]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** The rows in none of the kept groups. */
|
|
24
|
+
function otherFilter(other) {
|
|
25
|
+
return { not: { any: other.kept.map((tuple) => {
|
|
26
|
+
if (tuple.length !== other.members.length) refuse("A kept group has one value per field.");
|
|
27
|
+
return { all: other.members.map((member, i) => equalsLeaf(member, tuple[i] ?? null)) };
|
|
28
|
+
}) } };
|
|
29
|
+
}
|
|
30
|
+
/** Every field the tile groups by, and every field of its source a drill may step on. */
|
|
31
|
+
function allowedMembers(input) {
|
|
32
|
+
const grouped = (input.query.dimensions ?? []).map((d) => d.member);
|
|
33
|
+
return /* @__PURE__ */ new Set([...grouped, ...drillableMembers(input.model, input.query.source, input.readable)]);
|
|
34
|
+
}
|
|
35
|
+
/** The filter one step adds; a field the tile neither groups by nor can be broken down by is refused. */
|
|
36
|
+
function stepFilter(step, allowed) {
|
|
37
|
+
if ("bucket" in step) return void 0;
|
|
38
|
+
const members = stepMembers(step);
|
|
39
|
+
if (members.length === 0) refuse("A step names at least one field.");
|
|
40
|
+
const bad = members.find((m) => !allowed.has(m));
|
|
41
|
+
if (bad !== void 0) refuse(`"${bad}" is not a field this tile can be drilled by.`);
|
|
42
|
+
if ("group" in step) return { all: step.group.map((g) => equalsLeaf(g.member, g.value)) };
|
|
43
|
+
if ("search" in step) return {
|
|
44
|
+
member: step.search.member,
|
|
45
|
+
op: "contains",
|
|
46
|
+
values: [step.search.text]
|
|
47
|
+
};
|
|
48
|
+
return otherFilter(step.other);
|
|
49
|
+
}
|
|
50
|
+
/** The line a drill reads: `m1` and the like; one line's tile needs none named. */
|
|
51
|
+
function checkLine(query, drill) {
|
|
52
|
+
const calc = query.calc ?? [];
|
|
53
|
+
const known = [...query.measures.map((m) => m.id), ...calc.map((c) => c.id)];
|
|
54
|
+
if (drill.measure === void 0 && query.measures.length + calc.length > 1) refuse("This tile has more than one line: name the one clicked (measure).");
|
|
55
|
+
if (drill.measure !== void 0 && !known.includes(drill.measure)) refuse(`The tile has no line "${drill.measure}" to drill.`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The rows behind a drill, as a query with no grouping: the tile's own query (its filters,
|
|
59
|
+
* picks, range and measures) with each step's values ANDed on as filters and its time windows
|
|
60
|
+
* narrowing the range. The lock, required filters, tenancy and row rules travel apart, as for
|
|
61
|
+
* the tile. A calc that reads around its row (a total, a bucket, the period before) is left
|
|
62
|
+
* out: on rows with no grouping it would read the wrong scope. The server evaluates it from
|
|
63
|
+
* each scope's own read (`drillScopes`).
|
|
64
|
+
*/
|
|
65
|
+
function composeDrill(input) {
|
|
66
|
+
const { query, drill } = input;
|
|
67
|
+
if (drill.steps.length > 8) refuse(`A path is at most 8 steps.`);
|
|
68
|
+
const allowed = allowedMembers(input);
|
|
69
|
+
const added = drill.steps.flatMap((step) => stepFilter(step, allowed) ?? []);
|
|
70
|
+
const parts = [...query.filters === void 0 ? [] : [query.filters], ...added];
|
|
71
|
+
const [only, ...more] = parts;
|
|
72
|
+
const around = aroundCalcs(query);
|
|
73
|
+
const calc = (query.calc ?? []).filter((c) => !around.has(c.id));
|
|
74
|
+
checkLine(query, drill);
|
|
75
|
+
const time = drilledTime(input.model, query, drill.steps, input.clock);
|
|
76
|
+
return {
|
|
77
|
+
kind: query.kind,
|
|
78
|
+
source: query.source,
|
|
79
|
+
measures: query.measures,
|
|
80
|
+
...calc.length === 0 ? {} : { calc },
|
|
81
|
+
...only === void 0 ? {} : { filters: more.length === 0 ? only : { all: parts } },
|
|
82
|
+
...time === void 0 ? {} : { time }
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export { composeDrill };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DimensionDef, Model } from "../../model/types.mjs";
|
|
2
|
+
import { WireFilter } from "../filter.mjs";
|
|
3
|
+
import { WireQuery } from "../types.mjs";
|
|
4
|
+
/** Which members a viewer may see in a drill; the server's answer for sensitive members. */
|
|
5
|
+
export type Readable = (member: string, def: DimensionDef) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The fields Breakdown offers at a step: every drill field but those the path fixes or the line's
|
|
8
|
+
* measure fixes. A field the tile groups by is offered where the path does not fix it (its total,
|
|
9
|
+
* a number tile's root), so a total breaks down by the tile's own groups. Under Other, the field Other was cut on comes first:
|
|
10
|
+
* breaking it down again shows the long tail.
|
|
11
|
+
*/
|
|
12
|
+
export declare function offeredMembers(model: Model, query: WireQuery, path: {
|
|
13
|
+
fixed: readonly string[];
|
|
14
|
+
other: readonly string[];
|
|
15
|
+
where?: WireFilter | undefined;
|
|
16
|
+
}, readable: Readable): string[];
|
|
17
|
+
/**
|
|
18
|
+
* The time field Over time uses: the tile's own, else the source's default, else its first. A
|
|
19
|
+
* field the tile does not group by must be one a drill may read; else there is none.
|
|
20
|
+
*/
|
|
21
|
+
export declare function trendDimension(model: Model, query: WireQuery): string | undefined;
|