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,210 @@
|
|
|
1
|
+
import { DrillReason } from "../error/codes.mjs";
|
|
2
|
+
import { Noun, NumberFormat, Tone } from "../model/hints.mjs";
|
|
3
|
+
import { ItemsOrder } from "../query/drill/items.mjs";
|
|
4
|
+
import { DrillCan, DrillField, DrillSemantics, DrillState } from "../query/drill/types.mjs";
|
|
5
|
+
import { Cell, Grain, ResolvedRange } from "../query/types.mjs";
|
|
6
|
+
import { Receipt, RecordColumn, Result, ResultColumn } from "../result/types.mjs";
|
|
7
|
+
import { Primitive } from "./primitives.mjs";
|
|
8
|
+
/** Rows of an answer that do not open, each with why (a code a host can translate, and its text). */
|
|
9
|
+
export type ClosedRow = {
|
|
10
|
+
row: number;
|
|
11
|
+
code: DrillReason;
|
|
12
|
+
reason: string;
|
|
13
|
+
};
|
|
14
|
+
/** One answer as a drill reads it: sealed once, so a click names one of its rows. */
|
|
15
|
+
export type SealedAnswer = {
|
|
16
|
+
/** The answer's rows as drawn (their groups, buckets and the kept sets of Other), sealed. */
|
|
17
|
+
answer: string;
|
|
18
|
+
/** The rows that do not open, with why; every other row opens. */
|
|
19
|
+
closed?: ClosedRow[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* What an answer gives a client to drill with: the execution it ran under (its range, calendar
|
|
23
|
+
* and version, sealed), and the answer itself sealed once (`SealedAnswer`). A click sends back
|
|
24
|
+
* the answer and a row's place (`drillFrom` writes it); the server reads the row's selection
|
|
25
|
+
* from it and answers with the path normalized to one sealed selection per step.
|
|
26
|
+
*/
|
|
27
|
+
export type AnswerDrill = SealedAnswer & {
|
|
28
|
+
execution: string;
|
|
29
|
+
/** The comparison period's rows (`compare.rows`), when there is one. */
|
|
30
|
+
previous?: SealedAnswer;
|
|
31
|
+
/** Why some rows do not open (`code` for a client to word it, `reason` in English). */
|
|
32
|
+
code?: DrillReason;
|
|
33
|
+
reason?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A drill request: the drill, and for Items the page asked for. `summary: false` says the
|
|
37
|
+
* client already has this path's summary (another view, the next page), so it is not read again.
|
|
38
|
+
*/
|
|
39
|
+
export type DrillBody = {
|
|
40
|
+
state: DrillState;
|
|
41
|
+
page?: {
|
|
42
|
+
after?: string;
|
|
43
|
+
limit?: number;
|
|
44
|
+
};
|
|
45
|
+
summary?: false;
|
|
46
|
+
};
|
|
47
|
+
/** Whether a drill can show each view, and why not. */
|
|
48
|
+
export type DrillAbilities = {
|
|
49
|
+
breakdown: DrillCan;
|
|
50
|
+
trend: DrillCan;
|
|
51
|
+
items: DrillCan;
|
|
52
|
+
explanation: DrillCan;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The numbers a drill keeps apart: its line's value now (`value`), its value when the chart
|
|
56
|
+
* was drawn (`clicked`, only for the viewer who drew it), how many rows are behind it
|
|
57
|
+
* (`itemCount`), what those rows are, and its share of the step before when its line adds up
|
|
58
|
+
* and no row can be negative.
|
|
59
|
+
*/
|
|
60
|
+
export type DrillSummary = {
|
|
61
|
+
value: Cell;
|
|
62
|
+
clicked?: Cell;
|
|
63
|
+
itemCount?: Cell;
|
|
64
|
+
/**
|
|
65
|
+
* For a line that counts only rows whose field is set (an average, a sum): the rows behind
|
|
66
|
+
* the mark whether or not it is set, so "396 tasks with hours (57 without)" can be said.
|
|
67
|
+
*/
|
|
68
|
+
rows?: Cell;
|
|
69
|
+
/** The field those rows have set, by its label ("Hours"). */
|
|
70
|
+
operand?: string;
|
|
71
|
+
semantics: DrillSemantics;
|
|
72
|
+
/** The line counts rows (a count, not a sum that may equal one): its value is its rows. */
|
|
73
|
+
counted?: true;
|
|
74
|
+
/** `parent`: of the step before; `tile`: of the whole chart. */
|
|
75
|
+
share?: {
|
|
76
|
+
value: number;
|
|
77
|
+
of: "parent" | "tile";
|
|
78
|
+
};
|
|
79
|
+
can: DrillAbilities;
|
|
80
|
+
/** The fields Breakdown may group by at this step, first the one it opens on. */
|
|
81
|
+
offered: DrillField[];
|
|
82
|
+
receipt: Receipt;
|
|
83
|
+
/** The line's column: its label, type and unit, to format the value. */
|
|
84
|
+
column?: ResultColumn;
|
|
85
|
+
/** What one row of the source is called, to say how many there are. */
|
|
86
|
+
noun?: Noun;
|
|
87
|
+
/** The window read: the tile's range, or the period before for a mark of it (`previous`). */
|
|
88
|
+
range?: ResolvedRange;
|
|
89
|
+
previous?: true;
|
|
90
|
+
/**
|
|
91
|
+
* The link was drawn by another viewer: nothing it saw travels (no clicked value), and the
|
|
92
|
+
* counts are of the rows this viewer can see.
|
|
93
|
+
*/
|
|
94
|
+
foreign?: true;
|
|
95
|
+
/** Part of the link was left out: a step this viewer may not open. Never how many rows. */
|
|
96
|
+
omitted?: true;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* One selection of the path as a breadcrumb reads it: its fields and its values. A total (the
|
|
100
|
+
* whole tile, a row's or a column's) is `total`, with no label of its own. A selection of more
|
|
101
|
+
* than one step (a segment and its Other) lists each in `parts`.
|
|
102
|
+
*/
|
|
103
|
+
export type DrillCrumb = {
|
|
104
|
+
label: string;
|
|
105
|
+
value: Cell;
|
|
106
|
+
kind?: "group" | "time" | "other" | "total" | "search";
|
|
107
|
+
/** A time step's grain, to name it as the chart does ("Week of Nov 9"). */
|
|
108
|
+
grain?: Grain;
|
|
109
|
+
parts?: DrillCrumb[];
|
|
110
|
+
/** A mark of the period before. */
|
|
111
|
+
previous?: true;
|
|
112
|
+
};
|
|
113
|
+
/** One row behind a drill: its source, an opaque stable id, its key (unless the model hides it) and its values by member. */
|
|
114
|
+
export type DrillItem = {
|
|
115
|
+
source: string;
|
|
116
|
+
id: string;
|
|
117
|
+
key?: Record<string, Primitive>;
|
|
118
|
+
values: Record<string, Cell>;
|
|
119
|
+
/** Where it opens in the host's app, from the server's `itemLinks`. */
|
|
120
|
+
link?: string;
|
|
121
|
+
};
|
|
122
|
+
/** A Breakdown or Over time: an answer, sealed once for its clicks, and the fields offered. */
|
|
123
|
+
export type DrillGroupedView = {
|
|
124
|
+
by: "breakdown" | "trend";
|
|
125
|
+
answer: Result & {
|
|
126
|
+
unreadable?: true;
|
|
127
|
+
};
|
|
128
|
+
drill: SealedAnswer;
|
|
129
|
+
offered: DrillField[];
|
|
130
|
+
member?: string;
|
|
131
|
+
grain?: Grain;
|
|
132
|
+
/** Over time: the range it draws, and the grains it may be drawn at. */
|
|
133
|
+
range?: ResolvedRange;
|
|
134
|
+
grains?: Grain[];
|
|
135
|
+
/** A Breakdown of the change: each group now (the line), before (`c1`) and its change (`c2`). */
|
|
136
|
+
change?: true;
|
|
137
|
+
/** The field has more values than a Breakdown draws: a search narrows them. */
|
|
138
|
+
searchable?: true;
|
|
139
|
+
search?: string;
|
|
140
|
+
/** A Breakdown of a line that does not add up ranks its groups by their rows (`m<n>`). */
|
|
141
|
+
rankedBy?: string;
|
|
142
|
+
};
|
|
143
|
+
/** A record column as Items show it: with its number format when the model gives one. */
|
|
144
|
+
export type ItemColumn = RecordColumn & {
|
|
145
|
+
format?: NumberFormat;
|
|
146
|
+
unit?: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* A page of Items: the columns each item has, labelled and typed; the items; the page after;
|
|
150
|
+
* the field each item shows as its value (a sum's, an average's) and how they are sorted.
|
|
151
|
+
*/
|
|
152
|
+
export type DrillItemsView = {
|
|
153
|
+
by: "items";
|
|
154
|
+
source: string;
|
|
155
|
+
columns: ItemColumn[];
|
|
156
|
+
items: DrillItem[];
|
|
157
|
+
next?: string;
|
|
158
|
+
value?: string;
|
|
159
|
+
sort: "records" | "value" | "count";
|
|
160
|
+
/** The records order, when `sort` is `records`: "newest first", "by priority". */
|
|
161
|
+
sorted?: ItemsOrder;
|
|
162
|
+
/** The fields the path fixes: the same on every item, so a list does not repeat them. */
|
|
163
|
+
fixed?: string[];
|
|
164
|
+
/** The field that names each item in a list. */
|
|
165
|
+
title?: string;
|
|
166
|
+
/** The field shown as each item's badge, and the tone of each of its values. */
|
|
167
|
+
badge?: {
|
|
168
|
+
member: string;
|
|
169
|
+
tones?: Readonly<Record<string, Tone>>;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* A ratio's numerator: its label, how many of the rows it counts, the field that marks each row
|
|
173
|
+
* it counts, and whether the list shows only those (`only`). Without `flag`, rows carry no
|
|
174
|
+
* mark, and `unmarked` is set (its reason is `DRILL_REASONS.RATIO_UNMARKED`).
|
|
175
|
+
*/
|
|
176
|
+
numerator?: {
|
|
177
|
+
label: string;
|
|
178
|
+
count?: Cell;
|
|
179
|
+
flag?: string;
|
|
180
|
+
only?: true;
|
|
181
|
+
unmarked?: true;
|
|
182
|
+
};
|
|
183
|
+
/** A percentile's fraction (90 for p90), for the marker row. */
|
|
184
|
+
percentile?: number;
|
|
185
|
+
/** A list cut at the row cap: more values exist than it can page through. */
|
|
186
|
+
truncated?: true;
|
|
187
|
+
};
|
|
188
|
+
/** One part of a formula, in its own scope: its value, and its own drill when it has one. */
|
|
189
|
+
export type DrillOperand = {
|
|
190
|
+
entry: string;
|
|
191
|
+
scope: "row" | "total" | "bucket" | "previous";
|
|
192
|
+
label: string;
|
|
193
|
+
value: Cell;
|
|
194
|
+
/** The drill that opens this part on its own, already sealed; absent when it cannot open. */
|
|
195
|
+
state?: DrillState;
|
|
196
|
+
can: DrillCan;
|
|
197
|
+
};
|
|
198
|
+
/** A formula's parts: each operand with its own scope and value, each drillable on its own. */
|
|
199
|
+
export type DrillExplanationView = {
|
|
200
|
+
by: "explanation";
|
|
201
|
+
operands: DrillOperand[];
|
|
202
|
+
};
|
|
203
|
+
/** A drill's answer: its summary, its path as breadcrumbs, its state normalized, and its view. */
|
|
204
|
+
export type DrillAnswer = {
|
|
205
|
+
/** Absent when the request said it already has it (`summary: false`). */
|
|
206
|
+
summary?: DrillSummary;
|
|
207
|
+
path: DrillCrumb[];
|
|
208
|
+
state: DrillState;
|
|
209
|
+
view: DrillGroupedView | DrillItemsView | DrillExplanationView;
|
|
210
|
+
};
|
|
@@ -2,6 +2,7 @@ import { Doc } from "../document/types.mjs";
|
|
|
2
2
|
import { CustomSource } from "../engine/custom/request.mjs";
|
|
3
3
|
import { Model } from "../model/types.mjs";
|
|
4
4
|
import { CompositionPolicy } from "../query/compose.mjs";
|
|
5
|
+
import { ItemLinks } from "../query/drill/links.mjs";
|
|
5
6
|
import { DashPlugin } from "./plugin.mjs";
|
|
6
7
|
import { Awaitable, ConnectionId, IanaZone, WeekStart } from "./primitives.mjs";
|
|
7
8
|
import { QueryConnection } from "./source.mjs";
|
|
@@ -42,6 +43,14 @@ export type DashOptions = {
|
|
|
42
43
|
*/
|
|
43
44
|
connections: Record<ConnectionId, QueryConnection | CustomSource | ((request: Request) => QueryConnection | CustomSource)>;
|
|
44
45
|
viewer: (request: Request) => Awaitable<Viewer | null>;
|
|
46
|
+
/**
|
|
47
|
+
* The key for everything the server seals or signs: records and Items cursors, a drill's
|
|
48
|
+
* execution, its sealed answers and selections, and hidden item ids. Optional: without it,
|
|
49
|
+
* each process makes its own key, so a drill link or cursor opens only on the process that
|
|
50
|
+
* gave it and stops working after a restart. Set one shared secret in production, and
|
|
51
|
+
* whenever several instances serve the same app; the server warns at startup without one.
|
|
52
|
+
*/
|
|
53
|
+
secret?: string;
|
|
45
54
|
/** `can` is required. Access is never open by default. */
|
|
46
55
|
access: {
|
|
47
56
|
can: CanFn;
|
|
@@ -91,4 +100,16 @@ export type DashOptions = {
|
|
|
91
100
|
now?: () => Date;
|
|
92
101
|
compose?: CompositionPolicy;
|
|
93
102
|
trustedOrigins?: readonly string[];
|
|
103
|
+
/**
|
|
104
|
+
* Where each source's items open in your app, `{ order: "/orders/{id}" }`: the links an agent's
|
|
105
|
+
* drill answers carry (`dashboards_query` rows). The React UI takes the same map as a prop.
|
|
106
|
+
*/
|
|
107
|
+
itemLinks?: ItemLinks;
|
|
108
|
+
/**
|
|
109
|
+
* Drill-in: answers carry what a click drills, and the drill endpoints answer. On by default;
|
|
110
|
+
* `false` turns it off for the whole server: answers carry nothing to drill, the drill
|
|
111
|
+
* endpoints refuse (`DRILL_DENIED`, naming this option) and the React UI shows no drill and no
|
|
112
|
+
* Rows. A source or field with `drill: false` in the model is kept out on its own.
|
|
113
|
+
*/
|
|
114
|
+
drill?: boolean;
|
|
94
115
|
};
|
|
@@ -47,6 +47,11 @@ export type Resource = {
|
|
|
47
47
|
kind: "member";
|
|
48
48
|
id: string;
|
|
49
49
|
} |
|
|
50
|
+
/** The rows of a source as items: a drill's list. Ask yes for anyone who may view the source to keep it on. */
|
|
51
|
+
{
|
|
52
|
+
kind: "records";
|
|
53
|
+
source: string;
|
|
54
|
+
} |
|
|
50
55
|
/** The viewer's tenant as a whole, asked to create a dashboard; in an app of one tenant, the app. */
|
|
51
56
|
{
|
|
52
57
|
kind: "tenant";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Principal } from "derive-dashboards/core";
|
|
2
|
+
/** The AES key WebCrypto gives, under any runtime's types. */
|
|
3
|
+
type SealKey = Awaited<ReturnType<typeof crypto.subtle.importKey>>;
|
|
4
|
+
/** The key that seals: from `options.secret`, or one made for this process. */
|
|
5
|
+
export declare function cursorKey(secret: string | undefined): Promise<SealKey>;
|
|
6
|
+
/** The key that signs (HMAC-SHA-256): from `options.secret` for its own use, or one for this process. */
|
|
7
|
+
export declare function macKey(secret: string | undefined): Promise<SealKey>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { canonical, principalTenant } from "derive-dashboards/core";
|
|
2
|
+
import { EngineError } from "derive-dashboards/core/engine";
|
|
3
|
+
// src/cursor-seal.ts
|
|
4
|
+
/** 32 bytes from the secret for one use, or random ones for this process when there is none. */
|
|
5
|
+
async function keyBytes(secret, use) {
|
|
6
|
+
if (secret === void 0) return crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32));
|
|
7
|
+
const text = use === "" ? secret : `${use}\u0000${secret}`;
|
|
8
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)));
|
|
9
|
+
}
|
|
10
|
+
/** The key that seals: from `options.secret`, or one made for this process. */
|
|
11
|
+
async function cursorKey(secret) {
|
|
12
|
+
const raw = await keyBytes(secret, "");
|
|
13
|
+
return crypto.subtle.importKey("raw", raw, "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
14
|
+
}
|
|
15
|
+
/** The key that signs (HMAC-SHA-256): from `options.secret` for its own use, or one for this process. */
|
|
16
|
+
async function macKey(secret) {
|
|
17
|
+
const raw = await keyBytes(secret, "derive-dashboards mac");
|
|
18
|
+
return crypto.subtle.importKey("raw", raw, {
|
|
19
|
+
name: "HMAC",
|
|
20
|
+
hash: "SHA-256"
|
|
21
|
+
}, false, ["sign"]);
|
|
22
|
+
}
|
|
23
|
+
const base64url = (bytes) => btoa(Array.from(bytes, (b) => String.fromCodePoint(b)).join("")).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
|
|
24
|
+
const fromBase64url = (text) => Uint8Array.from(atob(text.replaceAll("-", "+").replaceAll("_", "/")), (c) => c.codePointAt(0) ?? 0);
|
|
25
|
+
/** A text's HMAC under the key, as 22 URL-safe characters (128 bits): stable, and not reversible without the key. */
|
|
26
|
+
/**
|
|
27
|
+
* A keyed digest in hex: what a receipt names its query by. Keyed, so a person who can guess the
|
|
28
|
+
* query's hidden parts (an Other step's kept names) cannot test a guess against it offline.
|
|
29
|
+
*/
|
|
30
|
+
async function macHex(key, text) {
|
|
31
|
+
const signed = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(text));
|
|
32
|
+
return Array.from(new Uint8Array(signed), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
33
|
+
}
|
|
34
|
+
async function mac(key, text) {
|
|
35
|
+
const signed = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(text));
|
|
36
|
+
return base64url(new Uint8Array(signed).slice(0, 16));
|
|
37
|
+
}
|
|
38
|
+
const boundTo = (b) => new TextEncoder().encode(canonical({
|
|
39
|
+
purpose: b.purpose,
|
|
40
|
+
tenant: principalTenant(b.principal),
|
|
41
|
+
on: b.on
|
|
42
|
+
}));
|
|
43
|
+
/** Sealed texts are padded to a whole number of blocks: a token's length says little of what is in it. */
|
|
44
|
+
const PAD_BLOCK = 256;
|
|
45
|
+
const PAD_MARK = "\0";
|
|
46
|
+
function padded(text) {
|
|
47
|
+
const bytes = new TextEncoder().encode(`${text}${PAD_MARK}`);
|
|
48
|
+
const size = Math.ceil(bytes.length / PAD_BLOCK) * PAD_BLOCK;
|
|
49
|
+
const out = new Uint8Array(size).fill(32);
|
|
50
|
+
out.set(bytes);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The text a padded one holds: everything before its last pad mark. */
|
|
54
|
+
function unpadded(text) {
|
|
55
|
+
const at = text.lastIndexOf(PAD_MARK);
|
|
56
|
+
return at === -1 ? text : text.slice(0, at);
|
|
57
|
+
}
|
|
58
|
+
/** A text sealed for one purpose, tenant and subject. */
|
|
59
|
+
async function seal(key, text, binding) {
|
|
60
|
+
const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
|
|
61
|
+
const sealed = await crypto.subtle.encrypt({
|
|
62
|
+
name: "AES-GCM",
|
|
63
|
+
iv,
|
|
64
|
+
additionalData: boundTo(binding)
|
|
65
|
+
}, key, padded(text));
|
|
66
|
+
return `${base64url(iv)}.${base64url(new Uint8Array(sealed))}`;
|
|
67
|
+
}
|
|
68
|
+
/** A sealed text opened, or undefined when it is not one sealed for this purpose, tenant and subject. */
|
|
69
|
+
async function unseal(key, sealed, binding) {
|
|
70
|
+
try {
|
|
71
|
+
const [iv = "", body = ""] = sealed.split(".");
|
|
72
|
+
const opened = await crypto.subtle.decrypt({
|
|
73
|
+
name: "AES-GCM",
|
|
74
|
+
iv: fromBase64url(iv),
|
|
75
|
+
additionalData: boundTo(binding)
|
|
76
|
+
}, key, fromBase64url(body));
|
|
77
|
+
return unpadded(new TextDecoder().decode(opened));
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function sealCursor(key, cursor, at) {
|
|
83
|
+
return seal(key, cursor, {
|
|
84
|
+
purpose: "cursor",
|
|
85
|
+
principal: at.principal,
|
|
86
|
+
on: at.on
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function openCursor(key, sealed, at) {
|
|
90
|
+
const opened = await unseal(key, sealed, {
|
|
91
|
+
purpose: "cursor",
|
|
92
|
+
principal: at.principal,
|
|
93
|
+
on: at.on
|
|
94
|
+
});
|
|
95
|
+
if (opened !== void 0) return opened;
|
|
96
|
+
throw new EngineError("CURSOR_INVALID", "The records cursor is not one this view gave, or it has expired: start again from the first page.");
|
|
97
|
+
}
|
|
98
|
+
export { base64url, cursorKey, mac, macHex, macKey, openCursor, seal, sealCursor, unseal };
|
package/dist/dashboard-id.mjs
CHANGED
|
@@ -19,7 +19,7 @@ const builtInId = (key) => `${BUILT_IN}${key}`;
|
|
|
19
19
|
*/
|
|
20
20
|
function expectServedAs(row, ref, id) {
|
|
21
21
|
if (row === null || "key" in ref) return;
|
|
22
|
-
if (row
|
|
22
|
+
if (row.default_of !== null && row.default_of !== void 0) throw new HttpError(404, "NOT_FOUND", `There is no dashboard "${id}".`);
|
|
23
23
|
}
|
|
24
24
|
/** An answer that names a dashboard, naming it by the id the client used. */
|
|
25
25
|
function servedAs(answer, id) {
|
package/dist/dashboards.mjs
CHANGED
|
@@ -30,6 +30,8 @@ function adapterFor(options, request) {
|
|
|
30
30
|
const { database } = options;
|
|
31
31
|
return typeof database === "function" ? database(request) : database;
|
|
32
32
|
}
|
|
33
|
+
/** A description the list carries only when there is one to show. */
|
|
34
|
+
const described = (description) => description === void 0 || description.trim() === "" ? {} : { description };
|
|
33
35
|
async function listDashboards(options, request, principal) {
|
|
34
36
|
const adapter = adapterFor(options, request);
|
|
35
37
|
const stored = adapter === void 0 ? [] : await allStored(adapter, principalTenant(principal));
|
|
@@ -37,11 +39,13 @@ async function listDashboards(options, request, principal) {
|
|
|
37
39
|
const defaults = (options.dashboards ?? []).filter((d) => !customized.has(d.key)).map((d) => ({
|
|
38
40
|
id: builtInId(d.key),
|
|
39
41
|
title: d.document.meta.title,
|
|
42
|
+
...described(d.document.meta.description),
|
|
40
43
|
version: 0
|
|
41
44
|
}));
|
|
42
45
|
return [...stored.map((d) => ({
|
|
43
46
|
id: d.defaultOf === void 0 ? d.id : builtInId(d.defaultOf),
|
|
44
47
|
title: d.title,
|
|
48
|
+
...described(d.description),
|
|
45
49
|
version: d.currentVersion,
|
|
46
50
|
...d.defaultOf === void 0 ? { owner: {
|
|
47
51
|
id: d.ownerId,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { execute } from "./execute.mjs";
|
|
2
|
+
import { HttpError } from "./http.mjs";
|
|
3
|
+
import { queryClosure } from "derive-dashboards/core";
|
|
4
|
+
import { drillOwner, stepMembers } from "derive-dashboards/core/engine";
|
|
5
|
+
// src/drill-access.ts
|
|
6
|
+
/** Which fields this viewer may see in a drill: never a sensitive one (Rules, section 6). */
|
|
7
|
+
const readableFor = (_x) => (_member, def) => def.sensitive !== true;
|
|
8
|
+
/** The clock the engine resolves ranges by, so a drill's window matches the tile's. */
|
|
9
|
+
const clockOf = (x) => ({
|
|
10
|
+
now: x.now,
|
|
11
|
+
calendar: x.calendar,
|
|
12
|
+
quantumSeconds: x.rt.options.cache?.quantum ?? 60
|
|
13
|
+
});
|
|
14
|
+
/** The same execution, running another query. */
|
|
15
|
+
const running = (x, query) => ({
|
|
16
|
+
...x,
|
|
17
|
+
query
|
|
18
|
+
});
|
|
19
|
+
/** The members a tile showed, which its drill reads freely: its groups, its time when it draws by it, its measures. */
|
|
20
|
+
function disclosed(o) {
|
|
21
|
+
if (o.scope.origin.kind === "query") return /* @__PURE__ */ new Set();
|
|
22
|
+
const q = o.x.query;
|
|
23
|
+
return /* @__PURE__ */ new Set([
|
|
24
|
+
...(q.dimensions ?? []).map((d) => d.member),
|
|
25
|
+
...q.time?.grain === void 0 ? [] : [q.time.dimension],
|
|
26
|
+
...q.measures.map((m) => m.measure)
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
/** Whether the viewer may read a member on its own: `view` on it, asked once per request. */
|
|
30
|
+
function mayRead(o, member) {
|
|
31
|
+
if (disclosed(o).has(member)) return Promise.resolve(true);
|
|
32
|
+
const asked = o.reads.get(member);
|
|
33
|
+
if (asked !== void 0) return asked;
|
|
34
|
+
const { principal } = o.scope;
|
|
35
|
+
const answer = principal.channel === "user" ? Promise.resolve(o.x.rt.options.access.can(principal.viewer, "view", {
|
|
36
|
+
kind: "member",
|
|
37
|
+
id: member
|
|
38
|
+
})) : Promise.resolve(false);
|
|
39
|
+
o.reads.set(member, answer);
|
|
40
|
+
return answer;
|
|
41
|
+
}
|
|
42
|
+
/** The host's members a query reads, as the host names them. */
|
|
43
|
+
function membersOf(o, query) {
|
|
44
|
+
const closure = queryClosure(o.x.rt.options.model, query);
|
|
45
|
+
return new Set(closure.members.flatMap((m) => drillOwner(m) ?? []));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The members a drill's query reads that its tile's own query did not, with the members the
|
|
49
|
+
* drill uses on purpose (its steps, the field it breaks down or draws by, the columns it lists)
|
|
50
|
+
* even when the tile filtered on them: a filter is not a field the tile showed.
|
|
51
|
+
*/
|
|
52
|
+
function addedMembers(o, query, used) {
|
|
53
|
+
const tile = membersOf(o, o.x.query);
|
|
54
|
+
const steps = o.drill.steps.flatMap((s) => stepMembers(s));
|
|
55
|
+
const read = [...membersOf(o, query)].filter((m) => !tile.has(m));
|
|
56
|
+
return [.../* @__PURE__ */ new Set([
|
|
57
|
+
...read,
|
|
58
|
+
...steps,
|
|
59
|
+
...used
|
|
60
|
+
])];
|
|
61
|
+
}
|
|
62
|
+
/** The first member a drill's query adds that this viewer may not read, if any. */
|
|
63
|
+
async function refusedMember(o, query, used = []) {
|
|
64
|
+
const members = addedMembers(o, query, used);
|
|
65
|
+
const answers = await Promise.all(members.map((m) => mayRead(o, m)));
|
|
66
|
+
return members.find((_m, i) => answers[i] !== true);
|
|
67
|
+
}
|
|
68
|
+
/** Refused unless the viewer may read every member the drill adds to what the tile showed. */
|
|
69
|
+
async function authorize(o, query, used = []) {
|
|
70
|
+
const refused = await refusedMember(o, query, used);
|
|
71
|
+
if (refused !== void 0) throw new HttpError(403, "FORBIDDEN", `You cannot read the member "${refused}".`);
|
|
72
|
+
}
|
|
73
|
+
/** A drill's query, authorized for this viewer and run under the drill's execution. */
|
|
74
|
+
async function drillRead(o, query, used = []) {
|
|
75
|
+
await authorize(o, query, used);
|
|
76
|
+
return execute(running(o.x, query));
|
|
77
|
+
}
|
|
78
|
+
/** The columns of a records read this viewer may see: each a member the tile showed or one they may read. */
|
|
79
|
+
async function readableColumns(o, source, names) {
|
|
80
|
+
const answers = await Promise.all(names.map((n) => mayRead(o, `${source}.${n}`)));
|
|
81
|
+
return names.filter((_n, i) => answers[i] === true);
|
|
82
|
+
}
|
|
83
|
+
/** Whether this viewer may see a source's rows as items: `view` on its records. */
|
|
84
|
+
function mayList(o, source) {
|
|
85
|
+
const { principal } = o.scope;
|
|
86
|
+
if (principal.channel !== "user") return Promise.resolve(false);
|
|
87
|
+
const can = o.x.rt.options.access.can;
|
|
88
|
+
return Promise.resolve(can(principal.viewer, "view", {
|
|
89
|
+
kind: "records",
|
|
90
|
+
source
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
export { clockOf, drillRead, mayList, mayRead, readableColumns, readableFor, running };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { formatExact, isMark, parseExact } from "derive-dashboards/core";
|
|
2
|
+
// src/drill-change.ts
|
|
3
|
+
/** A cell's number as whole units of 10^-scale, or undefined for anything else. */
|
|
4
|
+
function units(cell, scale) {
|
|
5
|
+
if (typeof cell === "number") return Number.isFinite(cell) ? parseExact(plainText(cell), scale) : void 0;
|
|
6
|
+
if (typeof cell === "object" && cell !== null && "v" in cell) return parseExact(cell.v, scale);
|
|
7
|
+
}
|
|
8
|
+
/** A float's shortest decimal text, written out where JavaScript would use an exponent (1e-7). */
|
|
9
|
+
const plainText = (n) => {
|
|
10
|
+
const text = String(n);
|
|
11
|
+
return /e/iu.test(text) ? n.toFixed(Math.min(decimalsOf(text), 100)) : text;
|
|
12
|
+
};
|
|
13
|
+
/** The decimal places a number's text holds, an exponent's included ("1e-7" has 7, "1.25e-3" has 5). */
|
|
14
|
+
function decimalsOf(text) {
|
|
15
|
+
const [mantissa = "", exponent = "0"] = text.toLowerCase().split("e");
|
|
16
|
+
const places = mantissa.includes(".") ? mantissa.split(".")[1]?.length ?? 0 : 0;
|
|
17
|
+
return Math.max(0, places - Number(exponent));
|
|
18
|
+
}
|
|
19
|
+
/** The places a set of cells needs to be added exactly: the most any of them has. */
|
|
20
|
+
const placesOf = (cells) => Math.max(0, ...cells.map((c) => {
|
|
21
|
+
return decimalsOf(typeof c === "object" && c !== null && "v" in c ? c.v : typeof c === "number" ? String(c) : "");
|
|
22
|
+
}));
|
|
23
|
+
/** A sum of units at a scale as a cell like the inputs: a number, or exact text. */
|
|
24
|
+
function cellAt(value, scale, exact) {
|
|
25
|
+
if (!exact) return Number(value) / 10 ** scale;
|
|
26
|
+
return {
|
|
27
|
+
t: scale === 0 ? "int" : "decimal",
|
|
28
|
+
v: formatExact(value, scale)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const isOther = (row) => row.some((c) => isMark(c) && c.mark === "other");
|
|
32
|
+
const isAll = (row) => row.some((c) => isMark(c) && c.mark === "all");
|
|
33
|
+
/**
|
|
34
|
+
* A Breakdown of the change with Other's own change filled in: its value before is the
|
|
35
|
+
* period's total before less the kept groups' before, exactly, so the listed changes add up to
|
|
36
|
+
* the whole change. Its change and the size of its change follow. Left as it is when a value
|
|
37
|
+
* is missing or not a number (a line that does not add up has no total to subtract from).
|
|
38
|
+
*/
|
|
39
|
+
function otherChange(answer) {
|
|
40
|
+
const at = (id) => answer.columns.findIndex((c) => c.id === id);
|
|
41
|
+
const places = {
|
|
42
|
+
before: at("c1"),
|
|
43
|
+
change: at("c2"),
|
|
44
|
+
size: at("c3")
|
|
45
|
+
};
|
|
46
|
+
const total = answer.rows.find((r) => isAll(r));
|
|
47
|
+
const other = answer.rows.findIndex((r) => isOther(r));
|
|
48
|
+
const now = answer.columns.findIndex((c) => c.id.startsWith("m"));
|
|
49
|
+
if (places.before < 0 || total === void 0 || other < 0 || now < 0) return answer;
|
|
50
|
+
const kept = answer.rows.filter((r) => !isAll(r) && !isOther(r));
|
|
51
|
+
const row = answer.rows[other] ?? [];
|
|
52
|
+
const filled = fillOther(row, [
|
|
53
|
+
total[places.before],
|
|
54
|
+
row[now],
|
|
55
|
+
...kept.map((r) => r[places.before])
|
|
56
|
+
], places);
|
|
57
|
+
return filled === null ? answer : {
|
|
58
|
+
...answer,
|
|
59
|
+
rows: answer.rows.map((r, i) => i === other ? filled : r)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Other's row with its value before, change and size of change, from the exact cells; null when one is not a number. */
|
|
63
|
+
function fillOther(row, cells, places) {
|
|
64
|
+
const scale = placesOf(cells);
|
|
65
|
+
const read = cells.map((c) => units(c, scale));
|
|
66
|
+
if (read.some((u) => u === void 0)) return null;
|
|
67
|
+
const [whole = 0n, mine = 0n, ...others] = read.map((u) => u ?? 0n);
|
|
68
|
+
const was = whole - others.reduce((a, b) => a + b, 0n);
|
|
69
|
+
const exact = cells.some((c) => typeof c === "object" && c !== null);
|
|
70
|
+
const filled = [...row];
|
|
71
|
+
filled[places.before] = cellAt(was, scale, exact);
|
|
72
|
+
if (places.change >= 0) filled[places.change] = cellAt(mine - was, scale, exact);
|
|
73
|
+
if (places.size >= 0) filled[places.size] = cellAt(mine >= was ? mine - was : was - mine, scale, exact);
|
|
74
|
+
return filled;
|
|
75
|
+
}
|
|
76
|
+
export { otherChange };
|