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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { resultColumns } from "derive-dashboards/core";
|
|
2
|
+
// src/drill-crumbs.ts
|
|
3
|
+
/** A field's label as a column of the tile would read it. */
|
|
4
|
+
function fieldLabel(o, member) {
|
|
5
|
+
return resultColumns(o.x.rt.options.model, {
|
|
6
|
+
...o.x.query,
|
|
7
|
+
dimensions: [{
|
|
8
|
+
id: "d1",
|
|
9
|
+
member
|
|
10
|
+
}]
|
|
11
|
+
}).find((c) => c.id === "d1")?.label ?? member;
|
|
12
|
+
}
|
|
13
|
+
/** One step as a breadcrumb: its fields and its values; a time point with its grain. */
|
|
14
|
+
function crumbOf(o, step) {
|
|
15
|
+
if ("bucket" in step) {
|
|
16
|
+
const { member, from, grain } = step.bucket;
|
|
17
|
+
return {
|
|
18
|
+
label: fieldLabel(o, member),
|
|
19
|
+
value: from,
|
|
20
|
+
kind: "time",
|
|
21
|
+
...grain === void 0 ? {} : { grain }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if ("other" in step) return {
|
|
25
|
+
label: step.other.members.map((m) => fieldLabel(o, m)).join(" · "),
|
|
26
|
+
value: null,
|
|
27
|
+
kind: "other"
|
|
28
|
+
};
|
|
29
|
+
if ("search" in step) return {
|
|
30
|
+
label: fieldLabel(o, step.search.member),
|
|
31
|
+
value: step.search.text,
|
|
32
|
+
kind: "search"
|
|
33
|
+
};
|
|
34
|
+
const [only] = step.group;
|
|
35
|
+
const value = step.group.length === 1 && only !== void 0 ? only.value : step.group.map((g) => String(g.value)).join(" · ");
|
|
36
|
+
return {
|
|
37
|
+
label: step.group.map((g) => fieldLabel(o, g.member)).join(" · "),
|
|
38
|
+
value,
|
|
39
|
+
kind: "group"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** One selection as a breadcrumb: its one step, its steps as parts, or a total. */
|
|
43
|
+
function selectionCrumb(o, selection) {
|
|
44
|
+
const previous = selection.previous === true ? { previous: true } : {};
|
|
45
|
+
const parts = selection.steps.map((step) => crumbOf(o, step));
|
|
46
|
+
const [only] = parts;
|
|
47
|
+
if (only === void 0) return {
|
|
48
|
+
label: "",
|
|
49
|
+
value: null,
|
|
50
|
+
kind: "total",
|
|
51
|
+
...previous
|
|
52
|
+
};
|
|
53
|
+
if (parts.length === 1) return {
|
|
54
|
+
...only,
|
|
55
|
+
...previous
|
|
56
|
+
};
|
|
57
|
+
const shown = parts.filter((p) => p.kind !== "search");
|
|
58
|
+
const [head] = shown;
|
|
59
|
+
if (shown.length === 1 && head !== void 0) return {
|
|
60
|
+
...head,
|
|
61
|
+
parts,
|
|
62
|
+
...previous
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
label: shown.map((p) => p.label).join(" · "),
|
|
66
|
+
value: null,
|
|
67
|
+
kind: "group",
|
|
68
|
+
parts,
|
|
69
|
+
...previous
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** The path as breadcrumbs, one per selection, in order. */
|
|
73
|
+
const crumbs = (o) => o.selections.map((s) => selectionCrumb(o, s));
|
|
74
|
+
/**
|
|
75
|
+
* What of a receipt a viewer who did not draw the link may read: a fixed list, so a field added
|
|
76
|
+
* to receipts later is held back until it is listed here. The filter (it states the drill's
|
|
77
|
+
* steps, an Other step's kept names among them) and the query's hash are never on it.
|
|
78
|
+
*/
|
|
79
|
+
const OPENER_RECEIPT = /* @__PURE__ */ new Set([
|
|
80
|
+
"provider",
|
|
81
|
+
"trust",
|
|
82
|
+
"sources",
|
|
83
|
+
"answeredBy",
|
|
84
|
+
"cache",
|
|
85
|
+
"range",
|
|
86
|
+
"calendar",
|
|
87
|
+
"dataThrough",
|
|
88
|
+
"computedAt",
|
|
89
|
+
"consistency",
|
|
90
|
+
"durationMs",
|
|
91
|
+
"rowsReturned",
|
|
92
|
+
"coverage",
|
|
93
|
+
"warnings"
|
|
94
|
+
]);
|
|
95
|
+
/** A value with every receipt in it cut to what the opener may read. */
|
|
96
|
+
function openerReceipts(value) {
|
|
97
|
+
if (Array.isArray(value)) return value.map((v) => openerReceipts(v));
|
|
98
|
+
if (typeof value !== "object" || value === null) return value;
|
|
99
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => {
|
|
100
|
+
if (k !== "receipt" || typeof v !== "object" || v === null) return [k, openerReceipts(v)];
|
|
101
|
+
return [k, Object.fromEntries(Object.entries(v).filter(([key]) => OPENER_RECEIPT.has(key)))];
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A drill's answer as a viewer who did not draw its link may read it: a receipt's filter states
|
|
106
|
+
* the drill's steps, and an Other step names the groups it leaves out, which may be groups this
|
|
107
|
+
* viewer's row rules hide. So for them each receipt carries only the fields listed as safe; the
|
|
108
|
+
* rows and counts are already theirs.
|
|
109
|
+
*/
|
|
110
|
+
function forOpener(answer, foreign) {
|
|
111
|
+
return foreign ? openerReceipts(answer) : answer;
|
|
112
|
+
}
|
|
113
|
+
export { crumbs, forOpener };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { openCursor, sealCursor } from "./cursor-seal.mjs";
|
|
2
|
+
import { drillRead, running } from "./drill-access.mjs";
|
|
3
|
+
import { fingerprint } from "./drill-identity.mjs";
|
|
4
|
+
import { itemId, keyHidden, linked } from "./drill-item-id.mjs";
|
|
5
|
+
import { mayLink, visibleTargets } from "./drill-targets.mjs";
|
|
6
|
+
import { bind } from "./execute.mjs";
|
|
7
|
+
import { canonical, isMark, recordColumns, resolveDimension } from "derive-dashboards/core";
|
|
8
|
+
import { EngineError, distinctQuery } from "derive-dashboards/core/engine";
|
|
9
|
+
/** A result cell as a value: a mark has none. */
|
|
10
|
+
const cellOf = (cell) => cell === void 0 || isMark(cell) ? null : cell;
|
|
11
|
+
/**
|
|
12
|
+
* The source and key a distinct value names, when its column is a join's own key to one row of
|
|
13
|
+
* another source the viewer may list: the value then links to that row's page.
|
|
14
|
+
*/
|
|
15
|
+
function joinedKey(o, field) {
|
|
16
|
+
const { model } = o.x.rt.options;
|
|
17
|
+
const { source } = o.x.query;
|
|
18
|
+
const dim = resolveDimension(model, source, field)?.dimension;
|
|
19
|
+
const column = dim !== void 0 && "column" in dim ? dim.column : void 0;
|
|
20
|
+
const join = Object.values(model.sources[source]?.joins ?? {}).find((j) => j.relationship !== "one_to_many" && j.on.length === 1 && j.on[0]?.[0] === column);
|
|
21
|
+
return join === void 0 ? join : keyOfTarget(model, join);
|
|
22
|
+
}
|
|
23
|
+
/** The join's target and its key, when the join reads exactly that one-column key and it is shown. */
|
|
24
|
+
function keyOfTarget(model, join) {
|
|
25
|
+
const name = join.on[0]?.[1];
|
|
26
|
+
const target = model.sources[join.to];
|
|
27
|
+
return name !== void 0 && target?.key.length === 1 && target.key[0] === name && !keyHidden(model, join.to) ? {
|
|
28
|
+
source: join.to,
|
|
29
|
+
name
|
|
30
|
+
} : void 0;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What a distinct list's cursor is bound to, as a records cursor is: the population and field,
|
|
34
|
+
* the lock and required filters it read under, and who asked (their access fingerprint), so a
|
|
35
|
+
* cursor never continues another viewer's list or one read under another policy.
|
|
36
|
+
*/
|
|
37
|
+
async function distinctAt(o, rows, field) {
|
|
38
|
+
const bound = bind(running(o.x, rows));
|
|
39
|
+
const by = await fingerprint(o.x.rt, o.scope.principal);
|
|
40
|
+
return {
|
|
41
|
+
principal: o.scope.principal,
|
|
42
|
+
on: {
|
|
43
|
+
distinct: rows,
|
|
44
|
+
field,
|
|
45
|
+
lock: bound.lock,
|
|
46
|
+
required: bound.required,
|
|
47
|
+
by
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** How far a distinct list has read, from its sealed cursor. */
|
|
52
|
+
async function distinctPage(o, rows, field, after) {
|
|
53
|
+
if (after === void 0) return 0;
|
|
54
|
+
const at = await distinctAt(o, rows, field);
|
|
55
|
+
const skip = Number(await openCursor(await o.x.rt.cursorKey, after, at));
|
|
56
|
+
if (!Number.isSafeInteger(skip) || skip < 0) throw new EngineError("CURSOR_INVALID", "The list's cursor is not one this view gave.");
|
|
57
|
+
return skip;
|
|
58
|
+
}
|
|
59
|
+
/** One distinct value as an item: a link to its own row when the field is a join's key. */
|
|
60
|
+
async function distinctItem(o, at, row) {
|
|
61
|
+
const value = cellOf(row[0]);
|
|
62
|
+
const values = {
|
|
63
|
+
[at.field]: value,
|
|
64
|
+
count: cellOf(row[1])
|
|
65
|
+
};
|
|
66
|
+
const { target } = at;
|
|
67
|
+
if (target === void 0) return {
|
|
68
|
+
source: at.source,
|
|
69
|
+
id: JSON.stringify(value),
|
|
70
|
+
values
|
|
71
|
+
};
|
|
72
|
+
const plain = typeof value === "object" ? null : value;
|
|
73
|
+
return linked(o, {
|
|
74
|
+
source: target.source,
|
|
75
|
+
id: await itemId(o, target.source, [plain], false),
|
|
76
|
+
key: { [target.name]: plain },
|
|
77
|
+
values
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The row each distinct value links to: only when the field is a join's key, the viewer may view
|
|
82
|
+
* that source and list its rows, and their own row rules let them see that row (one read for the page).
|
|
83
|
+
*/
|
|
84
|
+
async function linkedTargets(o, field, shown) {
|
|
85
|
+
const joined = joinedKey(o, field);
|
|
86
|
+
const target = joined !== void 0 && await mayLink(o, joined.source) ? joined : void 0;
|
|
87
|
+
const plain = shown.flatMap((row) => {
|
|
88
|
+
const v = cellOf(row[0]);
|
|
89
|
+
return typeof v === "object" || v === null ? [] : [v];
|
|
90
|
+
});
|
|
91
|
+
const visible = target === void 0 ? /* @__PURE__ */ new Set() : await visibleTargets(o, target, plain);
|
|
92
|
+
return (row) => visible.has(canonical(cellOf(row[0]))) ? target : void 0;
|
|
93
|
+
}
|
|
94
|
+
/** A distinct count's items, one page: its distinct values (never "not set"), each with its row count, a value linked to its own page when it is a join's key. */
|
|
95
|
+
async function distinctItems(o, rows, field, page) {
|
|
96
|
+
const { model } = o.x.rt.options;
|
|
97
|
+
const source = rows.source;
|
|
98
|
+
const take = page.limit ?? 50;
|
|
99
|
+
const skip = await distinctPage(o, rows, field, page.after);
|
|
100
|
+
const answer = await drillRead(o, distinctQuery(rows, field, {
|
|
101
|
+
skip,
|
|
102
|
+
take
|
|
103
|
+
}), [field]);
|
|
104
|
+
const [column] = recordColumns(model, source, [field]);
|
|
105
|
+
const columns = [...column === void 0 ? [] : [column], {
|
|
106
|
+
member: "count",
|
|
107
|
+
label: "Rows",
|
|
108
|
+
type: "int"
|
|
109
|
+
}];
|
|
110
|
+
const read = answer.rows.filter((row) => !row.some((c) => isMark(c)));
|
|
111
|
+
const shown = read.slice(skip, skip + take);
|
|
112
|
+
const targetOf = await linkedTargets(o, field, shown);
|
|
113
|
+
const items = await Promise.all(shown.map((row) => distinctItem(o, {
|
|
114
|
+
source,
|
|
115
|
+
field,
|
|
116
|
+
target: targetOf(row)
|
|
117
|
+
}, row)));
|
|
118
|
+
const next = read.length > skip + take ? await sealCursor(await o.x.rt.cursorKey, String(skip + take), await distinctAt(o, rows, field)) : void 0;
|
|
119
|
+
return {
|
|
120
|
+
by: "items",
|
|
121
|
+
source,
|
|
122
|
+
columns,
|
|
123
|
+
items,
|
|
124
|
+
value: field,
|
|
125
|
+
sort: "count",
|
|
126
|
+
...next === void 0 ? {} : { next },
|
|
127
|
+
...answer.status === "truncated" ? { truncated: true } : {}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export { distinctItems };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { pathDigest } from "./drill-identity.mjs";
|
|
2
|
+
import { sealSelection } from "./drill-seal.mjs";
|
|
3
|
+
import { resultColumns } from "derive-dashboards/core";
|
|
4
|
+
import { formulaParts, scopeSteps } from "derive-dashboards/core/engine";
|
|
5
|
+
// src/drill-explain.ts
|
|
6
|
+
/** A path of one sealed selection for a scope's steps, bound to this execution at the root. */
|
|
7
|
+
async function scopePath(o, selection) {
|
|
8
|
+
if (selection.steps.length === 0 && selection.previous !== true) return [];
|
|
9
|
+
const parent = await pathDigest([]);
|
|
10
|
+
return [await sealSelection(o.scope, {
|
|
11
|
+
...selection,
|
|
12
|
+
exec: o.pinned.id,
|
|
13
|
+
parent
|
|
14
|
+
})];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The drill that opens one part of a formula on its own, in its own scope: the same path for a
|
|
18
|
+
* part of the row, the whole tile for a total, the drill's time point for a bucket, the drill's
|
|
19
|
+
* steps in the period before for a previous value.
|
|
20
|
+
*/
|
|
21
|
+
async function operandState(o, entry, scope) {
|
|
22
|
+
const base = {
|
|
23
|
+
origin: o.scope.origin,
|
|
24
|
+
entry,
|
|
25
|
+
execution: o.execution,
|
|
26
|
+
view: { by: "breakdown" }
|
|
27
|
+
};
|
|
28
|
+
if (scope === "row") return {
|
|
29
|
+
...base,
|
|
30
|
+
path: o.path
|
|
31
|
+
};
|
|
32
|
+
const steps = scopeSteps(o.drill.steps, scope);
|
|
33
|
+
const previous = scope === "previous" ? { previous: true } : {};
|
|
34
|
+
return {
|
|
35
|
+
...base,
|
|
36
|
+
path: await scopePath(o, {
|
|
37
|
+
steps,
|
|
38
|
+
...previous
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A formula's parts (Rules, section 2): each line it reads in the scope it reads it, with its
|
|
44
|
+
* own value from the summary's reads (none read again), and the drill that opens it on its own.
|
|
45
|
+
*/
|
|
46
|
+
async function explanationView(o, summed, entry) {
|
|
47
|
+
const parts = formulaParts(o.x.query, entry);
|
|
48
|
+
const columns = resultColumns(o.x.rt.options.model, o.x.query);
|
|
49
|
+
return {
|
|
50
|
+
by: "explanation",
|
|
51
|
+
operands: await Promise.all(parts.map(async (p) => {
|
|
52
|
+
const value = summed.scoped[p.scope]?.get(p.entry) ?? null;
|
|
53
|
+
return {
|
|
54
|
+
entry: p.entry,
|
|
55
|
+
scope: p.scope,
|
|
56
|
+
label: columns.find((c) => c.id === p.entry)?.label ?? p.entry,
|
|
57
|
+
value,
|
|
58
|
+
state: await operandState(o, p.entry, p.scope),
|
|
59
|
+
can: { ok: true }
|
|
60
|
+
};
|
|
61
|
+
}))
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export { explanationView };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { sha256 } from "./cache.mjs";
|
|
2
|
+
import { mac } from "./cursor-seal.mjs";
|
|
3
|
+
import { canonical, principalTenant } from "derive-dashboards/core";
|
|
4
|
+
// src/drill-identity.ts
|
|
5
|
+
/**
|
|
6
|
+
* The fingerprint of a viewer's access: an HMAC under the server's key of who they are and
|
|
7
|
+
* what decides what they may see (tenant, id, roles, attributes, the person an agent acts for).
|
|
8
|
+
* Two requests with the same fingerprint see the same rows; it reveals nothing about either.
|
|
9
|
+
*/
|
|
10
|
+
async function fingerprint(rt, principal) {
|
|
11
|
+
return mac(await rt.macKey, canonical(accessOf(principal)));
|
|
12
|
+
}
|
|
13
|
+
/** What decides what a principal may see, in a stable shape. */
|
|
14
|
+
function accessOf(principal) {
|
|
15
|
+
const base = {
|
|
16
|
+
tenant: principalTenant(principal),
|
|
17
|
+
channel: principal.channel
|
|
18
|
+
};
|
|
19
|
+
return principal.channel === "user" ? {
|
|
20
|
+
...base,
|
|
21
|
+
...viewerAccess(principal.viewer)
|
|
22
|
+
} : base;
|
|
23
|
+
}
|
|
24
|
+
/** A signed-in viewer's part of their access: who they are, their roles and attributes. */
|
|
25
|
+
const viewerAccess = (viewer) => ({
|
|
26
|
+
id: viewer.id,
|
|
27
|
+
agent: viewer.agent?.for ?? null,
|
|
28
|
+
roles: [...viewer.roles ?? []].toSorted(),
|
|
29
|
+
attributes: viewer.attributes ?? {}
|
|
30
|
+
});
|
|
31
|
+
/** The tile's composed query as drawn, as a digest: a draft or a version that changed it is stale. */
|
|
32
|
+
const revisionOf = async (query) => (await sha256(canonical(query))).slice(0, 32);
|
|
33
|
+
/** A path's steps as a digest: what a selection drawn under them is bound to. */
|
|
34
|
+
const pathDigest = async (steps) => (await sha256(canonical(steps))).slice(0, 32);
|
|
35
|
+
export { fingerprint, pathDigest, revisionOf };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mac } from "./cursor-seal.mjs";
|
|
2
|
+
import { canonical, itemLink, principalTenant } from "derive-dashboards/core";
|
|
3
|
+
// src/drill-item-id.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether items of a source carry their key: not when the model hides it (`records.key: "hide"`),
|
|
6
|
+
* nor when a sensitive or hidden field reads one of its columns. A key never shows as a column.
|
|
7
|
+
*/
|
|
8
|
+
function keyHidden(model, source) {
|
|
9
|
+
const def = model.sources[source];
|
|
10
|
+
if (def === void 0 || def.records?.key === "hide") return true;
|
|
11
|
+
const kept = Object.entries(def.dimensions).filter(([name, d]) => !name.startsWith("dd_") && (d.sensitive === true || d.hidden === true)).map(([, d]) => d);
|
|
12
|
+
return def.key.some((column) => kept.some((d) => "column" in d && d.column === column));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An item's stable id: its key's value (its values as JSON, for a key of more than one column),
|
|
16
|
+
* or, when the key is hidden, an HMAC of it under the server's key, bound to the tenant: stable,
|
|
17
|
+
* opaque, and not reversible by enumerating keys.
|
|
18
|
+
*/
|
|
19
|
+
async function itemId(o, source, key, hide) {
|
|
20
|
+
if (hide) return mac(await o.x.rt.macKey, canonical({
|
|
21
|
+
tenant: principalTenant(o.scope.principal),
|
|
22
|
+
source,
|
|
23
|
+
key: [...key]
|
|
24
|
+
}));
|
|
25
|
+
return key.length === 1 ? String(key[0]) : JSON.stringify(key);
|
|
26
|
+
}
|
|
27
|
+
/** An item with its link from the server's `itemLinks`; a hidden key never builds one. */
|
|
28
|
+
function linked(o, item) {
|
|
29
|
+
const link = item.key === void 0 ? void 0 : itemLink(o.x.rt.options.itemLinks, item);
|
|
30
|
+
return link === void 0 ? item : {
|
|
31
|
+
...item,
|
|
32
|
+
link
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { itemId, keyHidden, linked };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { drillRead, readableColumns, running } from "./drill-access.mjs";
|
|
2
|
+
import { distinctItems } from "./drill-distinct.mjs";
|
|
3
|
+
import { fingerprint } from "./drill-identity.mjs";
|
|
4
|
+
import { itemId, keyHidden, linked } from "./drill-item-id.mjs";
|
|
5
|
+
import { lineValue } from "./drill-summary.mjs";
|
|
6
|
+
import { readPage } from "./records-read.mjs";
|
|
7
|
+
import { resolveDimension } from "derive-dashboards/core";
|
|
8
|
+
import { countQuery, flagCell, itemsShape, population, storedCell } from "derive-dashboards/core/engine";
|
|
9
|
+
// src/drill-items.ts
|
|
10
|
+
/** A column as Items show it: the line's value labelled, typed and formatted as the line, the flag as its numerator, a number with its model format. */
|
|
11
|
+
function columnOf(model, source, c, r) {
|
|
12
|
+
if (c.member === r.line.value && r.line.stored !== void 0 && r.column !== void 0) {
|
|
13
|
+
const unit = r.column.unit;
|
|
14
|
+
return {
|
|
15
|
+
member: c.member,
|
|
16
|
+
label: r.column.label,
|
|
17
|
+
type: r.column.type,
|
|
18
|
+
...unit === void 0 ? {} : { unit }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (c.member === r.line.numerator?.flag) return {
|
|
22
|
+
member: c.member,
|
|
23
|
+
label: r.line.numerator.label,
|
|
24
|
+
type: "boolean"
|
|
25
|
+
};
|
|
26
|
+
const format = resolveDimension(model, source, c.member)?.dimension.format;
|
|
27
|
+
return format === void 0 ? c : {
|
|
28
|
+
...c,
|
|
29
|
+
format
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** A page of records as items: each with its source, id, key (unless hidden), values and link. */
|
|
33
|
+
async function itemsOf(o, x, page, r) {
|
|
34
|
+
const by = await fingerprint(o.x.rt, o.scope.principal);
|
|
35
|
+
const read = await readPage(x, {
|
|
36
|
+
...page,
|
|
37
|
+
by
|
|
38
|
+
});
|
|
39
|
+
const { source } = x.query;
|
|
40
|
+
const { model } = x.rt.options;
|
|
41
|
+
const hide = keyHidden(model, source);
|
|
42
|
+
const names = model.sources[source]?.key ?? [];
|
|
43
|
+
const keys = read.keys ?? [];
|
|
44
|
+
const stored = r.line.stored;
|
|
45
|
+
const cell = (member, v) => {
|
|
46
|
+
if (member === r.line.numerator?.flag) return flagCell(v);
|
|
47
|
+
return member === r.line.value && stored !== void 0 ? storedCell(stored.numeric, v) : v;
|
|
48
|
+
};
|
|
49
|
+
const items = await Promise.all(read.rows.map(async (row, n) => {
|
|
50
|
+
const key = keys[n] ?? [];
|
|
51
|
+
const item = {
|
|
52
|
+
source,
|
|
53
|
+
id: await itemId(o, source, key, hide),
|
|
54
|
+
...hide ? {} : { key: Object.fromEntries(names.map((k, i) => [k, key[i] ?? null])) },
|
|
55
|
+
values: Object.fromEntries(read.columns.map((c, i) => [c.member, cell(c.member, row[i] ?? null)]))
|
|
56
|
+
};
|
|
57
|
+
return linked(o, item);
|
|
58
|
+
}));
|
|
59
|
+
return {
|
|
60
|
+
source,
|
|
61
|
+
columns: read.columns.map((c) => columnOf(model, source, c, r)),
|
|
62
|
+
items,
|
|
63
|
+
...read.next === void 0 ? {} : { next: read.next }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** A ratio's numerator: its label and flag, how many rows it counts, and whether the list shows only those. */
|
|
67
|
+
async function numeratorOf(o, set, line, only) {
|
|
68
|
+
const numerator = line.numerator;
|
|
69
|
+
if (numerator === void 0) return {};
|
|
70
|
+
const { model } = o.x.rt.options;
|
|
71
|
+
const counted = await drillRead(o, countQuery(population(model, set, o.drill, true)));
|
|
72
|
+
return { numerator: {
|
|
73
|
+
...numerator,
|
|
74
|
+
count: lineValue(counted, "m1"),
|
|
75
|
+
...only ? { only: true } : {},
|
|
76
|
+
...numerator.flag === void 0 ? { unmarked: true } : {}
|
|
77
|
+
} };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A page of a drill's Items, as its line's kind reads them (Rules, section 2): the rows of its
|
|
81
|
+
* population (a count's own rows, a sum's with the summed field, an average's or percentile's
|
|
82
|
+
* rows with a value sorted by it, a ratio's denominator rows, each marked when its numerator
|
|
83
|
+
* counts it, or only those), or a distinct count's values. Only columns the viewer may read
|
|
84
|
+
* are listed.
|
|
85
|
+
*/
|
|
86
|
+
async function drillItems(o, ask, page) {
|
|
87
|
+
const { model } = o.x.rt.options;
|
|
88
|
+
const { set, line } = ask;
|
|
89
|
+
const rows = population(model, set, o.drill, ask.only && line.numerator !== void 0);
|
|
90
|
+
if (line.semantics === "distinct" && line.value !== void 0) return distinctItems(o, rows, line.value, page);
|
|
91
|
+
const { title, badge, sorted, fixed, ...shape } = itemsShape(model, set, o.drill, line);
|
|
92
|
+
const columns = await readableColumns(o, set.source, shape.columns);
|
|
93
|
+
const after = page.after === void 0 ? {} : { after: page.after };
|
|
94
|
+
const read = {
|
|
95
|
+
limit: page.limit ?? 50,
|
|
96
|
+
shape: {
|
|
97
|
+
...shape,
|
|
98
|
+
columns
|
|
99
|
+
},
|
|
100
|
+
...after
|
|
101
|
+
};
|
|
102
|
+
const [listed, numerator] = await Promise.all([itemsOf(o, running(o.x, rows), read, {
|
|
103
|
+
line,
|
|
104
|
+
column: ask.column
|
|
105
|
+
}), page.after === void 0 ? numeratorOf(o, set, line, ask.only) : Promise.resolve({})]);
|
|
106
|
+
return {
|
|
107
|
+
...itemsView(listed, {
|
|
108
|
+
title,
|
|
109
|
+
badge,
|
|
110
|
+
sorted,
|
|
111
|
+
fixed
|
|
112
|
+
}, line),
|
|
113
|
+
...numerator
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** The Items view from a page: the title and badge only where their column is listed. */
|
|
117
|
+
function itemsView(listed, hints, line) {
|
|
118
|
+
const { title, badge, sorted, fixed } = hints;
|
|
119
|
+
const shown = (member) => member !== void 0 && listed.columns.some((c) => c.member === member);
|
|
120
|
+
return {
|
|
121
|
+
by: "items",
|
|
122
|
+
...listed,
|
|
123
|
+
...title !== void 0 && shown(title) ? { title } : {},
|
|
124
|
+
...badge !== void 0 && shown(badge.member) ? { badge } : {},
|
|
125
|
+
...line.value === void 0 ? {} : { value: line.value },
|
|
126
|
+
...sorted === void 0 ? {} : { sorted },
|
|
127
|
+
...fixed.length === 0 ? {} : { fixed },
|
|
128
|
+
...line.percentile === void 0 ? {} : { percentile: line.percentile },
|
|
129
|
+
sort: line.ranked === true ? "value" : "records"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export { drillItems };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { fingerprint, pathDigest, revisionOf } from "./drill-identity.mjs";
|
|
2
|
+
import { isRowRef, openExecution, openRow, openSelection, sealSelection } from "./drill-seal.mjs";
|
|
3
|
+
import { tileContext } from "./endpoints/dashboards.mjs";
|
|
4
|
+
import { freeExecution } from "./endpoints/query.mjs";
|
|
5
|
+
import { HttpError } from "./http.mjs";
|
|
6
|
+
import { tileExecution } from "./tiles.mjs";
|
|
7
|
+
import { DRILL_REASONS } from "derive-dashboards/core";
|
|
8
|
+
import { EngineError, keptPath } from "derive-dashboards/core/engine";
|
|
9
|
+
// src/drill-open.ts
|
|
10
|
+
/** The tile or query a drill starts from, composed as its answer was. */
|
|
11
|
+
async function originExecution(a, principal) {
|
|
12
|
+
const { origin } = a.state;
|
|
13
|
+
if (origin.kind === "query") return freeExecution(a.rt, principal, a.request, origin.query);
|
|
14
|
+
const document = origin.document;
|
|
15
|
+
const ctx = await tileContext(a.rt, {
|
|
16
|
+
dashboardId: origin.dashboardId,
|
|
17
|
+
picks: origin.picks,
|
|
18
|
+
...document !== void 0 && "draft" in document ? { draft: true } : {},
|
|
19
|
+
...document !== void 0 && "version" in document ? { at: document.version } : {},
|
|
20
|
+
principal,
|
|
21
|
+
request: a.request
|
|
22
|
+
});
|
|
23
|
+
return tileExecution(ctx, {
|
|
24
|
+
widgetId: origin.widgetId,
|
|
25
|
+
...origin.query === void 0 ? {} : { query: origin.query }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The execution as the answer was drawn: its pinned range and calendar, so the drill does not
|
|
30
|
+
* move; for a mark of the period before, that period's range. It reads the drill's model: the
|
|
31
|
+
* source's own fields and a drill's (`drillModel`).
|
|
32
|
+
*/
|
|
33
|
+
/** Whether a query's range is relative to now ("last 30 days"). */
|
|
34
|
+
const isRelative = (time) => time !== void 0 && "last" in time.range;
|
|
35
|
+
function pinnedTo(x, at, previous) {
|
|
36
|
+
const options = {
|
|
37
|
+
...x.rt.options,
|
|
38
|
+
model: x.rt.drillModel
|
|
39
|
+
};
|
|
40
|
+
const pinned = {
|
|
41
|
+
...x,
|
|
42
|
+
rt: {
|
|
43
|
+
...x.rt,
|
|
44
|
+
options,
|
|
45
|
+
cache: void 0
|
|
46
|
+
},
|
|
47
|
+
calendar: at.calendar
|
|
48
|
+
};
|
|
49
|
+
const time = x.query.time;
|
|
50
|
+
if (!previous && at.now !== void 0 && isRelative(time)) return {
|
|
51
|
+
...pinned,
|
|
52
|
+
now: new Date(at.now)
|
|
53
|
+
};
|
|
54
|
+
const range = previous ? at.compare : at.range;
|
|
55
|
+
if (time === void 0 || range === void 0) return pinned;
|
|
56
|
+
return {
|
|
57
|
+
...pinned,
|
|
58
|
+
query: {
|
|
59
|
+
...x.query,
|
|
60
|
+
time: {
|
|
61
|
+
dimension: time.dimension,
|
|
62
|
+
range,
|
|
63
|
+
...time.grain === void 0 ? {} : { grain: time.grain },
|
|
64
|
+
...previous || time.compare === void 0 ? {} : { compare: time.compare }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** A settled read's value, or its error thrown. */
|
|
70
|
+
function settled(result) {
|
|
71
|
+
if (result.status === "fulfilled") return result.value;
|
|
72
|
+
throw result.reason;
|
|
73
|
+
}
|
|
74
|
+
/** Refused unless a signed-in viewer drills a source the model lets drill. */
|
|
75
|
+
function checkDrillable(a, x) {
|
|
76
|
+
if (a.rt.options.model.sources[x.query.source]?.drill === false) throw new HttpError(403, "DRILL_DENIED", DRILL_REASONS.SOURCE_OFF);
|
|
77
|
+
}
|
|
78
|
+
const stale = () => new HttpError(409, "DRILL_STALE", "The dashboard changed since this drill was opened: open it again from the chart.");
|
|
79
|
+
const notThisView = () => new EngineError("SELECTION_INVALID", "This link's drill is out of date: open it again from the chart.");
|
|
80
|
+
/**
|
|
81
|
+
* Each step of the path opened: a sealed selection, or a row of a sealed answer (a click not yet
|
|
82
|
+
* normalized). Each must be drawn under this execution, after the very steps before it.
|
|
83
|
+
*/
|
|
84
|
+
async function openPath(scope, entries, exec) {
|
|
85
|
+
const opened = await Promise.all(entries.map((e) => isRowRef(e) ? openRow(scope, e) : openSelection(scope, e)));
|
|
86
|
+
const digests = await Promise.all(opened.map((_s, i) => pathDigest(opened.slice(0, i).flatMap((s) => s.steps))));
|
|
87
|
+
opened.forEach((s, i) => {
|
|
88
|
+
if (s.exec !== exec || s.parent !== digests[i]) throw notThisView();
|
|
89
|
+
});
|
|
90
|
+
return opened;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The path normalized and sealed again where it changed: each kept selection bound to the steps
|
|
94
|
+
* now before it, so the next request opens it as it stands.
|
|
95
|
+
*/
|
|
96
|
+
function resealed(scope, kept, entries) {
|
|
97
|
+
return Promise.all(kept.map(async (s, i) => {
|
|
98
|
+
const parent = await pathDigest(kept.slice(0, i).flatMap((k) => k.steps));
|
|
99
|
+
const entry = entries[i];
|
|
100
|
+
if (entry !== void 0 && !isRowRef(entry) && parent === s.parent) return entry;
|
|
101
|
+
return sealSelection(scope, {
|
|
102
|
+
...s,
|
|
103
|
+
parent
|
|
104
|
+
});
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A drill opened for the person asking: refused on a public link and on a source the model
|
|
109
|
+
* keeps from drilling; its origin composed under their access; its execution and path opened
|
|
110
|
+
* (each sealed for this tenant and origin, each step bound to the execution and the steps
|
|
111
|
+
* before it); its path normalized so it never fixes a field twice. A dashboard whose tile
|
|
112
|
+
* changed since the drill was drawn (another version, an edited draft) is DRILL_STALE. A link
|
|
113
|
+
* drawn by another viewer opens without anything they saw.
|
|
114
|
+
*/
|
|
115
|
+
async function openDrill(a) {
|
|
116
|
+
if (a.rt.options.drill === false) throw new HttpError(403, "DRILL_DENIED", "Drilling is off on this server (its drill option is false).");
|
|
117
|
+
const principal = a.principal;
|
|
118
|
+
if (principal?.channel !== "user") throw new HttpError(403, "DRILL_DENIED", "Drilling needs a signed-in viewer; a public link does not drill.");
|
|
119
|
+
const scope = {
|
|
120
|
+
rt: a.rt,
|
|
121
|
+
principal,
|
|
122
|
+
origin: a.state.origin
|
|
123
|
+
};
|
|
124
|
+
const [origin, execution, by] = await Promise.allSettled([
|
|
125
|
+
originExecution(a, principal),
|
|
126
|
+
openExecution(scope, a.state.execution),
|
|
127
|
+
fingerprint(a.rt, principal)
|
|
128
|
+
]);
|
|
129
|
+
const x = settled(origin);
|
|
130
|
+
checkDrillable(a, x);
|
|
131
|
+
const at = settled(execution);
|
|
132
|
+
if (at.revision !== void 0 && at.revision !== await revisionOf(x.query)) throw stale();
|
|
133
|
+
const all = await openPath(scope, a.state.path, at.id);
|
|
134
|
+
const foreign = at.by !== settled(by);
|
|
135
|
+
const mine = foreign ? all.map(({ clicked: _c, ...s }) => s) : all;
|
|
136
|
+
const indexes = keptPath(mine);
|
|
137
|
+
const kept = indexes.flatMap((i) => mine[i] ?? []);
|
|
138
|
+
const entries = indexes.flatMap((i) => a.state.path[i] ?? []);
|
|
139
|
+
return {
|
|
140
|
+
x: pinnedTo(x, at, kept.some((s) => s.previous === true)),
|
|
141
|
+
scope,
|
|
142
|
+
pinned: at,
|
|
143
|
+
execution: a.state.execution,
|
|
144
|
+
drill: {
|
|
145
|
+
steps: kept.flatMap((s) => s.steps),
|
|
146
|
+
...a.state.entry === void 0 ? {} : { measure: a.state.entry }
|
|
147
|
+
},
|
|
148
|
+
path: await resealed(scope, kept, entries),
|
|
149
|
+
selections: kept,
|
|
150
|
+
foreign,
|
|
151
|
+
omitted: false,
|
|
152
|
+
reads: /* @__PURE__ */ new Map()
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/** The drill cut back to its first `steps` selections, the rest left out: what a viewer with less access opens. */
|
|
156
|
+
function cutTo(o, steps) {
|
|
157
|
+
const kept = o.selections.slice(0, steps);
|
|
158
|
+
return {
|
|
159
|
+
...o,
|
|
160
|
+
drill: {
|
|
161
|
+
...o.drill,
|
|
162
|
+
steps: kept.flatMap((s) => s.steps)
|
|
163
|
+
},
|
|
164
|
+
selections: kept,
|
|
165
|
+
path: o.path.slice(0, steps),
|
|
166
|
+
omitted: true
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export { cutTo, openDrill };
|