derive-dashboards 0.1.0 → 0.1.1
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 +4 -3
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- 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/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/members.mjs +1 -1
- 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 +31 -0
- package/dist/core/error/codes.mjs +28 -1
- package/dist/core/index.d.mts +9 -5
- package/dist/core/index.mjs +5 -3
- 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 +16 -3
- package/dist/core/model/types.d.mts +8 -6
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- 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/segments.d.mts +12 -2
- package/dist/core/query/segments.mjs +3 -1
- package/dist/core/result/columns.mjs +17 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2108 -128
- package/dist/core/schema/answers.mjs +10 -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 +4 -2
- package/dist/core/schema/index.mjs +4 -2
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +1 -1
- 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 +15 -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/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 +2 -2
- package/dist/endpoints/dashboards.mjs +11 -3
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +233 -2
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +15 -17
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +27 -3
- 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 +7 -3
- 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/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +51 -23
- package/dist/react/DashboardList.mjs +30 -2
- package/dist/react/Discard.mjs +7 -2
- package/dist/react/Grid.mjs +12 -5
- package/dist/react/Header.mjs +9 -0
- package/dist/react/Parts.mjs +6 -2
- 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/Tile.d.mts +1 -1
- package/dist/react/Tile.mjs +54 -30
- package/dist/react/builder/state.d.mts +1 -1
- package/dist/react/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +15 -1
- package/dist/react/context.mjs +19 -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 +98 -0
- package/dist/react/drill/words.mjs +77 -0
- package/dist/react/english.mjs +9 -1
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +34 -12
- package/dist/react/index.d.mts +27 -4
- package/dist/react/index.mjs +10 -3
- package/dist/react/messages.d.mts +14 -1
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +54 -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 +37 -0
- package/dist/react/series.mjs +95 -0
- package/dist/react/theme.css +1823 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +5 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +1 -0
- package/dist/react/useDashboard.mjs +2 -1
- package/dist/react/useTiles.mjs +50 -15
- 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/charts.d.mts +0 -1
- package/dist/recharts/charts.mjs +128 -34
- package/dist/recharts/index.d.mts +2 -2
- package/dist/recharts/index.mjs +2 -2
- package/dist/recharts/marks.mjs +83 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/records-read.mjs +44 -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 +8 -10
- 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
|
@@ -33,6 +33,226 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
33
33
|
version: number;
|
|
34
34
|
requestId: string;
|
|
35
35
|
}, import("derive-dashboards/core").Published, "POST">;
|
|
36
|
+
drill: import("derive-dashboards/core").DashEndpoint<"/dashboards/drill", {
|
|
37
|
+
state: {
|
|
38
|
+
origin: {
|
|
39
|
+
kind: "dashboard";
|
|
40
|
+
dashboardId: string;
|
|
41
|
+
widgetId: string;
|
|
42
|
+
picks: Record<string, string | number | boolean | {
|
|
43
|
+
op: "set" | "equals" | "in" | "contains" | "startsWith" | "gt" | "gte" | "lt" | "lte" | "between" | "notEquals" | "notIn" | "notContains" | "notSet";
|
|
44
|
+
values: readonly (string | number | boolean | null)[];
|
|
45
|
+
} | {
|
|
46
|
+
last: number;
|
|
47
|
+
unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
48
|
+
includeCurrent: boolean;
|
|
49
|
+
} | {
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
} | null>;
|
|
53
|
+
query?: string;
|
|
54
|
+
document?: {
|
|
55
|
+
version: number;
|
|
56
|
+
} | {
|
|
57
|
+
draft: true;
|
|
58
|
+
};
|
|
59
|
+
} | {
|
|
60
|
+
kind: "query";
|
|
61
|
+
query: {
|
|
62
|
+
kind: "aggregate";
|
|
63
|
+
source: string;
|
|
64
|
+
measures: readonly {
|
|
65
|
+
id: `m${number}`;
|
|
66
|
+
measure: string;
|
|
67
|
+
filter?: import("derive-dashboards/core").WireFilter;
|
|
68
|
+
label?: string;
|
|
69
|
+
}[];
|
|
70
|
+
dimensions?: readonly {
|
|
71
|
+
id: `d${number}`;
|
|
72
|
+
member: string;
|
|
73
|
+
limit?: number;
|
|
74
|
+
other?: boolean;
|
|
75
|
+
rankBy?: {
|
|
76
|
+
by: `m${number}` | `c${number}`;
|
|
77
|
+
dir: "asc" | "desc";
|
|
78
|
+
};
|
|
79
|
+
}[];
|
|
80
|
+
time?: {
|
|
81
|
+
dimension: string;
|
|
82
|
+
range: {
|
|
83
|
+
last: number;
|
|
84
|
+
unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
85
|
+
includeCurrent: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
from: string;
|
|
88
|
+
to: string;
|
|
89
|
+
};
|
|
90
|
+
grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
91
|
+
compare?: "previous_period" | "previous_year";
|
|
92
|
+
};
|
|
93
|
+
filters?: import("derive-dashboards/core").WireFilter;
|
|
94
|
+
calc?: readonly {
|
|
95
|
+
id: `c${number}`;
|
|
96
|
+
formula: import("derive-dashboards/core").FormulaNode;
|
|
97
|
+
format?: "number" | "percent" | "currency" | "duration";
|
|
98
|
+
label?: string;
|
|
99
|
+
}[];
|
|
100
|
+
order?: readonly {
|
|
101
|
+
by: `m${number}` | `c${number}` | `d${number}`;
|
|
102
|
+
dir: "asc" | "desc";
|
|
103
|
+
}[];
|
|
104
|
+
limit?: number;
|
|
105
|
+
other?: boolean;
|
|
106
|
+
total?: boolean;
|
|
107
|
+
fill?: "zero" | "none";
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
execution: string;
|
|
111
|
+
path: readonly string[];
|
|
112
|
+
view: {
|
|
113
|
+
by: "breakdown";
|
|
114
|
+
member?: string;
|
|
115
|
+
search?: string;
|
|
116
|
+
} | {
|
|
117
|
+
by: "trend";
|
|
118
|
+
grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
119
|
+
} | {
|
|
120
|
+
by: "items";
|
|
121
|
+
numerator?: true;
|
|
122
|
+
} | {
|
|
123
|
+
by: "explanation";
|
|
124
|
+
};
|
|
125
|
+
entry?: string;
|
|
126
|
+
views?: readonly ({
|
|
127
|
+
by: "breakdown";
|
|
128
|
+
member?: string;
|
|
129
|
+
search?: string;
|
|
130
|
+
} | {
|
|
131
|
+
by: "trend";
|
|
132
|
+
grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
133
|
+
} | {
|
|
134
|
+
by: "items";
|
|
135
|
+
numerator?: true;
|
|
136
|
+
} | {
|
|
137
|
+
by: "explanation";
|
|
138
|
+
})[];
|
|
139
|
+
};
|
|
140
|
+
page?: {
|
|
141
|
+
after?: string;
|
|
142
|
+
limit?: number;
|
|
143
|
+
};
|
|
144
|
+
summary?: false;
|
|
145
|
+
}, import("derive-dashboards/core").DrillAnswer, "POST">;
|
|
146
|
+
queryDrill: import("derive-dashboards/core").DashEndpoint<"/query/drill", {
|
|
147
|
+
state: {
|
|
148
|
+
origin: {
|
|
149
|
+
kind: "dashboard";
|
|
150
|
+
dashboardId: string;
|
|
151
|
+
widgetId: string;
|
|
152
|
+
picks: Record<string, string | number | boolean | {
|
|
153
|
+
op: "set" | "equals" | "in" | "contains" | "startsWith" | "gt" | "gte" | "lt" | "lte" | "between" | "notEquals" | "notIn" | "notContains" | "notSet";
|
|
154
|
+
values: readonly (string | number | boolean | null)[];
|
|
155
|
+
} | {
|
|
156
|
+
last: number;
|
|
157
|
+
unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
158
|
+
includeCurrent: boolean;
|
|
159
|
+
} | {
|
|
160
|
+
from: string;
|
|
161
|
+
to: string;
|
|
162
|
+
} | null>;
|
|
163
|
+
query?: string;
|
|
164
|
+
document?: {
|
|
165
|
+
version: number;
|
|
166
|
+
} | {
|
|
167
|
+
draft: true;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
kind: "query";
|
|
171
|
+
query: {
|
|
172
|
+
kind: "aggregate";
|
|
173
|
+
source: string;
|
|
174
|
+
measures: readonly {
|
|
175
|
+
id: `m${number}`;
|
|
176
|
+
measure: string;
|
|
177
|
+
filter?: import("derive-dashboards/core").WireFilter;
|
|
178
|
+
label?: string;
|
|
179
|
+
}[];
|
|
180
|
+
dimensions?: readonly {
|
|
181
|
+
id: `d${number}`;
|
|
182
|
+
member: string;
|
|
183
|
+
limit?: number;
|
|
184
|
+
other?: boolean;
|
|
185
|
+
rankBy?: {
|
|
186
|
+
by: `m${number}` | `c${number}`;
|
|
187
|
+
dir: "asc" | "desc";
|
|
188
|
+
};
|
|
189
|
+
}[];
|
|
190
|
+
time?: {
|
|
191
|
+
dimension: string;
|
|
192
|
+
range: {
|
|
193
|
+
last: number;
|
|
194
|
+
unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
195
|
+
includeCurrent: boolean;
|
|
196
|
+
} | {
|
|
197
|
+
from: string;
|
|
198
|
+
to: string;
|
|
199
|
+
};
|
|
200
|
+
grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
201
|
+
compare?: "previous_period" | "previous_year";
|
|
202
|
+
};
|
|
203
|
+
filters?: import("derive-dashboards/core").WireFilter;
|
|
204
|
+
calc?: readonly {
|
|
205
|
+
id: `c${number}`;
|
|
206
|
+
formula: import("derive-dashboards/core").FormulaNode;
|
|
207
|
+
format?: "number" | "percent" | "currency" | "duration";
|
|
208
|
+
label?: string;
|
|
209
|
+
}[];
|
|
210
|
+
order?: readonly {
|
|
211
|
+
by: `m${number}` | `c${number}` | `d${number}`;
|
|
212
|
+
dir: "asc" | "desc";
|
|
213
|
+
}[];
|
|
214
|
+
limit?: number;
|
|
215
|
+
other?: boolean;
|
|
216
|
+
total?: boolean;
|
|
217
|
+
fill?: "zero" | "none";
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
execution: string;
|
|
221
|
+
path: readonly string[];
|
|
222
|
+
view: {
|
|
223
|
+
by: "breakdown";
|
|
224
|
+
member?: string;
|
|
225
|
+
search?: string;
|
|
226
|
+
} | {
|
|
227
|
+
by: "trend";
|
|
228
|
+
grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
229
|
+
} | {
|
|
230
|
+
by: "items";
|
|
231
|
+
numerator?: true;
|
|
232
|
+
} | {
|
|
233
|
+
by: "explanation";
|
|
234
|
+
};
|
|
235
|
+
entry?: string;
|
|
236
|
+
views?: readonly ({
|
|
237
|
+
by: "breakdown";
|
|
238
|
+
member?: string;
|
|
239
|
+
search?: string;
|
|
240
|
+
} | {
|
|
241
|
+
by: "trend";
|
|
242
|
+
grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
243
|
+
} | {
|
|
244
|
+
by: "items";
|
|
245
|
+
numerator?: true;
|
|
246
|
+
} | {
|
|
247
|
+
by: "explanation";
|
|
248
|
+
})[];
|
|
249
|
+
};
|
|
250
|
+
page?: {
|
|
251
|
+
after?: string;
|
|
252
|
+
limit?: number;
|
|
253
|
+
};
|
|
254
|
+
summary?: false;
|
|
255
|
+
}, import("derive-dashboards/core").DrillAnswer, "POST">;
|
|
36
256
|
queryRun: import("derive-dashboards/core").DashEndpoint<"/query/run", {
|
|
37
257
|
query: {
|
|
38
258
|
kind: "aggregate";
|
|
@@ -82,7 +302,18 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
82
302
|
total?: boolean;
|
|
83
303
|
fill?: "zero" | "none";
|
|
84
304
|
};
|
|
85
|
-
}, Answered, "
|
|
305
|
+
}, Omit<Answered, "cuts"> | {
|
|
306
|
+
drill: import("derive-dashboards/core").AnswerDrill;
|
|
307
|
+
compare?: {
|
|
308
|
+
rows: import("derive-dashboards/core").ResultRows;
|
|
309
|
+
range: import("derive-dashboards/core").ResolvedRange;
|
|
310
|
+
};
|
|
311
|
+
rows: import("derive-dashboards/core").ResultRows;
|
|
312
|
+
columns: readonly import("derive-dashboards/core").ResultColumn[];
|
|
313
|
+
status: "complete" | "truncated";
|
|
314
|
+
receipt: import("derive-dashboards/core").Receipt;
|
|
315
|
+
unreadable?: true;
|
|
316
|
+
}, "POST">;
|
|
86
317
|
queryBatch: import("derive-dashboards/core").DashEndpoint<"/query/batch", {
|
|
87
318
|
queries: {
|
|
88
319
|
kind: "aggregate";
|
|
@@ -141,7 +372,7 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
141
372
|
} | {
|
|
142
373
|
i: number;
|
|
143
374
|
ok: true;
|
|
144
|
-
result: Answered
|
|
375
|
+
result: Omit<Answered, "cuts">;
|
|
145
376
|
}, any, any>, "POST">;
|
|
146
377
|
queryRecords: import("derive-dashboards/core").DashEndpoint<"/query/records", {
|
|
147
378
|
query: {
|
package/dist/endpoints/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dashboardEndpoints } from "./dashboards.mjs";
|
|
2
2
|
import { draftEndpoints } from "./drafts.mjs";
|
|
3
|
+
import { drillEndpoints } from "./drill.mjs";
|
|
3
4
|
import { metaEndpoints } from "./meta.mjs";
|
|
4
5
|
import { queryEndpoints } from "./query.mjs";
|
|
5
6
|
import { readEndpoints } from "./read.mjs";
|
|
@@ -17,7 +18,10 @@ function coreEndpoints(rt) {
|
|
|
17
18
|
...draftEndpoints(rt),
|
|
18
19
|
...reviewEndpoints(rt)
|
|
19
20
|
};
|
|
20
|
-
const query =
|
|
21
|
+
const query = {
|
|
22
|
+
...queryEndpoints(rt),
|
|
23
|
+
...drillEndpoints(rt)
|
|
24
|
+
};
|
|
21
25
|
const history = versionEndpoints(rt);
|
|
22
26
|
const names = [
|
|
23
27
|
meta,
|
package/dist/endpoints/query.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { authorizeFree } from "../authorize.mjs";
|
|
2
2
|
import { bodies, parseWith } from "../body.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { issueDrill } from "../drill-seal.mjs";
|
|
4
|
+
import { execute, wire } from "../execute.mjs";
|
|
5
|
+
import { executeRecords } from "../records-read.mjs";
|
|
4
6
|
import { calendarOf, nowOf, userOf } from "../request.mjs";
|
|
5
7
|
import { concurrencyOf, streamLines } from "../tiles.mjs";
|
|
6
8
|
import { createDashEndpoint, queryClosure, recordDimensions } from "derive-dashboards/core";
|
|
@@ -24,6 +26,26 @@ async function freeExecution(rt, principal, request, query) {
|
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
28
|
}
|
|
29
|
+
/** A free query's answer, with what a click on each of its rows drills into. */
|
|
30
|
+
async function runFree(rt, principal, request, query) {
|
|
31
|
+
const x = await freeExecution(rt, principal, request, query);
|
|
32
|
+
const answer = await execute(x);
|
|
33
|
+
const drill = await issueDrill({
|
|
34
|
+
rt,
|
|
35
|
+
principal: x.principal,
|
|
36
|
+
origin: {
|
|
37
|
+
kind: "query",
|
|
38
|
+
query
|
|
39
|
+
}
|
|
40
|
+
}, answer, {
|
|
41
|
+
query,
|
|
42
|
+
now: x.now
|
|
43
|
+
});
|
|
44
|
+
return drill === void 0 ? wire(answer) : {
|
|
45
|
+
...wire(answer),
|
|
46
|
+
drill
|
|
47
|
+
};
|
|
48
|
+
}
|
|
27
49
|
/** Free queries: the widget builder's preview, an agent's question. A different grant from viewing a dashboard. */
|
|
28
50
|
function queryEndpoints(rt) {
|
|
29
51
|
return {
|
|
@@ -31,14 +53,14 @@ function queryEndpoints(rt) {
|
|
|
31
53
|
method: "POST",
|
|
32
54
|
access: { kind: "signed_in" },
|
|
33
55
|
parse: (input) => parseWith(bodies.query, input, "QUERY_INVALID"),
|
|
34
|
-
handler:
|
|
56
|
+
handler: ({ body, principal, request }) => runFree(rt, principal, request, body.query)
|
|
35
57
|
}),
|
|
36
58
|
queryBatch: createDashEndpoint("/query/batch", {
|
|
37
59
|
method: "POST",
|
|
38
60
|
access: { kind: "signed_in" },
|
|
39
61
|
respond: "ndjson",
|
|
40
62
|
parse: (input) => parseWith(bodies.queryBatch, input, "QUERY_INVALID"),
|
|
41
|
-
handler: ({ body, principal, request }) => streamLines(body.queries.map((q) => async () => execute(await freeExecution(rt, principal, request, q))), concurrencyOf(rt))
|
|
63
|
+
handler: ({ body, principal, request }) => streamLines(body.queries.map((q) => async () => wire(await execute(await freeExecution(rt, principal, request, q)))), concurrencyOf(rt))
|
|
42
64
|
}),
|
|
43
65
|
queryRecords: createDashEndpoint("/query/records", {
|
|
44
66
|
method: "POST",
|
|
@@ -69,4 +91,4 @@ function queryEndpoints(rt) {
|
|
|
69
91
|
})
|
|
70
92
|
};
|
|
71
93
|
}
|
|
72
|
-
export { queryEndpoints };
|
|
94
|
+
export { freeExecution, queryEndpoints };
|
package/dist/execute.d.mts
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
import "./reading.mjs";
|
|
1
2
|
import { Cache } from "./cache.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { cursorKey, macKey } from "./cursor-seal.mjs";
|
|
4
|
+
import { Cuts, DashOptions, Model, Principal, Result, WireQuery } from "derive-dashboards/core";
|
|
5
|
+
import "derive-dashboards/core/engine";
|
|
3
6
|
/** The runtime's state for one handler: its options and its result cache. */
|
|
4
7
|
export type Runtime = {
|
|
5
8
|
options: DashOptions;
|
|
6
9
|
cache: Cache | undefined;
|
|
10
|
+
/** Seals records cursors and a drill's parts (`cursor-seal`). */
|
|
11
|
+
cursorKey: ReturnType<typeof cursorKey>;
|
|
12
|
+
/** Signs what must be stable and unreadable: a hidden item id, a viewer's access fingerprint. */
|
|
13
|
+
macKey: ReturnType<typeof macKey>;
|
|
14
|
+
/** The model a drill reads (`drillModel`), built once. */
|
|
15
|
+
drillModel: Model;
|
|
16
|
+
/** Whether the missing-`secret` warning was given, so it is given once. */
|
|
17
|
+
warned: {
|
|
18
|
+
secret: boolean;
|
|
19
|
+
};
|
|
7
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* An answer as the server keeps it: with what each dimension's own limit kept (`cuts`), which a
|
|
23
|
+
* drill reads its Other from. `cuts` never leaves the server (`wire`).
|
|
24
|
+
*/
|
|
8
25
|
export type Answered = Result & {
|
|
9
26
|
unreadable?: true;
|
|
27
|
+
cuts?: Cuts;
|
|
10
28
|
};
|
package/dist/execute.mjs
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { checkSensitive } from "./authorize.mjs";
|
|
2
|
-
import { manifest
|
|
2
|
+
import { manifest } from "./cache.mjs";
|
|
3
|
+
import { macHex } from "./cursor-seal.mjs";
|
|
3
4
|
import { adapterFor } from "./dashboards.mjs";
|
|
4
5
|
import { withReader } from "./reading.mjs";
|
|
5
6
|
import { logQuery } from "./store/log.mjs";
|
|
6
|
-
import { canonical, isBound, markedRows,
|
|
7
|
-
import { EngineError, readQuery
|
|
7
|
+
import { canonical, isBound, markedRows, resultColumns } from "derive-dashboards/core";
|
|
8
|
+
import { EngineError, readQuery } from "derive-dashboards/core/engine";
|
|
8
9
|
// src/execute.ts
|
|
9
|
-
|
|
10
|
+
/** An answer as a client reads it: without what only the server reads. */
|
|
11
|
+
function wire(answer) {
|
|
12
|
+
const { cuts: _cuts, ...rest } = answer;
|
|
13
|
+
return rest;
|
|
14
|
+
}
|
|
10
15
|
function boundEntries(entries, what) {
|
|
11
16
|
return entries.map((entry) => {
|
|
12
17
|
if (!isBound(entry.filter)) throw new EngineError("FILTER_UNBOUND", `A ${what} that uses a viewer value or a variable is not supported yet.`);
|
|
@@ -46,7 +51,7 @@ function bind(x) {
|
|
|
46
51
|
now: x.now,
|
|
47
52
|
calendar: x.calendar,
|
|
48
53
|
maxRows,
|
|
49
|
-
quantumSeconds: options.cache?.quantum ??
|
|
54
|
+
quantumSeconds: options.cache?.quantum ?? 60
|
|
50
55
|
},
|
|
51
56
|
lock,
|
|
52
57
|
required,
|
|
@@ -65,6 +70,7 @@ async function compute(x, bound) {
|
|
|
65
70
|
const started = performance.now();
|
|
66
71
|
const computedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
67
72
|
const { value, consistency, custom } = await reading(x, bound.maxRows, (reader) => readQuery(bound.input, reader));
|
|
73
|
+
const cuts = value.cuts === void 0 ? {} : { cuts: value.cuts };
|
|
68
74
|
const { truncated, unreadable, compare, ...levels } = value.answer;
|
|
69
75
|
const warnings = truncated === true ? [{
|
|
70
76
|
code: "ROW_CAP",
|
|
@@ -80,8 +86,9 @@ async function compute(x, bound) {
|
|
|
80
86
|
} },
|
|
81
87
|
status: truncated === true ? "truncated" : "complete",
|
|
82
88
|
...unreadable === true ? { unreadable } : {},
|
|
89
|
+
...cuts,
|
|
83
90
|
receipt: {
|
|
84
|
-
queryHash: await
|
|
91
|
+
queryHash: await macHex(await x.rt.macKey, canonical({
|
|
85
92
|
query: x.query,
|
|
86
93
|
lock: bound.lock,
|
|
87
94
|
required: bound.required
|
|
@@ -126,7 +133,7 @@ function answered(x) {
|
|
|
126
133
|
const bound = bind(x);
|
|
127
134
|
const { cache, options } = x.rt;
|
|
128
135
|
if (cache === void 0) return compute(x, bound);
|
|
129
|
-
const quantum = (options.cache?.quantum ??
|
|
136
|
+
const quantum = (options.cache?.quantum ?? 60) * 1e3;
|
|
130
137
|
const on = [...bound.lock, ...bound.required].map((e) => e.on);
|
|
131
138
|
const key = {
|
|
132
139
|
principal: x.principal,
|
|
@@ -140,13 +147,4 @@ function answered(x) {
|
|
|
140
147
|
};
|
|
141
148
|
return cache.answer(key, () => compute(x, bound));
|
|
142
149
|
}
|
|
143
|
-
|
|
144
|
-
async function executeRecords(x, page) {
|
|
145
|
-
const bound = bind(x);
|
|
146
|
-
const { value } = await reading(x, page.limit, (reader) => readRecords(bound.input, page, reader));
|
|
147
|
-
return {
|
|
148
|
-
...value,
|
|
149
|
-
columns: recordColumns(x.rt.options.model, x.query.source, value.columns)
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
export { execute, executeRecords };
|
|
150
|
+
export { bind, execute, reading, wire };
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { PostgresConnectionOptions, RunSql, postgresConnection } from "./postgre
|
|
|
6
6
|
import { PostgresStoreOptions, RunRows, postgresStore } from "./postgres-store.mjs";
|
|
7
7
|
import { memoryStorage } from "./storage.mjs";
|
|
8
8
|
import { SchemaDiff, SchemaMismatchError, createTables, schemaDiff } from "./store/create-tables.mjs";
|
|
9
|
-
import { Awaitable, Dash, DashOptions, UniqueIds, ViewerFor } from "derive-dashboards/core";
|
|
9
|
+
import { Awaitable, Dash, DashOptions, ItemLinksFor, UniqueIds, ViewerFor } from "derive-dashboards/core";
|
|
10
10
|
/** What `deriveDashboards` returns: `api` calls every endpoint; `$Infer.Endpoints` types a client. */
|
|
11
11
|
export type DashServer<O extends DashOptions> = Dash<O, ReturnType<typeof coreEndpoints>>;
|
|
12
12
|
/**
|
|
@@ -20,5 +20,7 @@ export declare function deriveDashboards<const O extends DashOptions>(options: O
|
|
|
20
20
|
plugins?: UniqueIds<O["plugins"]>;
|
|
21
21
|
/** Typed from the model: with tenant keys, the viewer must carry a value for each. */
|
|
22
22
|
viewer: (request: Request) => Awaitable<ViewerFor<O["model"]> | null>;
|
|
23
|
+
/** Typed from the model: a template per source, and no source the model lacks. */
|
|
24
|
+
itemLinks?: ItemLinksFor<O["model"], O["itemLinks"]>;
|
|
23
25
|
}): DashServer<O>;
|
|
24
26
|
export { type CustomSourceOptions, HttpError, type PgPool, type PgQueryable, type PostgresConnectionOptions, type PostgresStoreOptions, type RunRows, type RunSql, type SchemaDiff, SchemaMismatchError, createTables, customSource, memoryStorage, nodePostgres, postgresConnection, postgresStore, schemaDiff };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createCache } from "./cache.mjs";
|
|
2
|
+
import { cursorKey, macKey } from "./cursor-seal.mjs";
|
|
3
|
+
import { warnSecretAtStart } from "./drill-secret.mjs";
|
|
2
4
|
import { coreEndpoints } from "./endpoints/index.mjs";
|
|
3
5
|
import { createHandler, serverCall } from "./handler.mjs";
|
|
4
6
|
import { HttpError } from "./http.mjs";
|
|
@@ -9,7 +11,8 @@ import { postgresConnection } from "./postgres-connection.mjs";
|
|
|
9
11
|
import { postgresStore } from "./postgres-store.mjs";
|
|
10
12
|
import { memoryStorage } from "./storage.mjs";
|
|
11
13
|
import { SchemaMismatchError, createTables, schemaDiff } from "./store/create-tables.mjs";
|
|
12
|
-
import { BASE_ERROR_CODES, defineModel } from "derive-dashboards/core";
|
|
14
|
+
import { BASE_ERROR_CODES, defineModel, linkTemplateIssues } from "derive-dashboards/core";
|
|
15
|
+
import { drillModel } from "derive-dashboards/core/engine";
|
|
13
16
|
import { loadDocument } from "derive-dashboards/core/schema";
|
|
14
17
|
// src/index.ts
|
|
15
18
|
/**
|
|
@@ -54,6 +57,24 @@ function checkPluginIds(options, taken) {
|
|
|
54
57
|
function isStream(output) {
|
|
55
58
|
return typeof output === "object" && output !== null && typeof Reflect.get(output, Symbol.asyncIterator) === "function";
|
|
56
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Each `itemLinks` template names a source of the model and only parts its items have: `{id}`,
|
|
62
|
+
* or `{key.<column>}` for a column of the source's key. A misspelled source or column would
|
|
63
|
+
* otherwise only show as links that never appear: refuse to start.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Each `itemLinks` template names a source of the model and is one core's link filler reads:
|
|
67
|
+
* it starts with "/" or a scheme, and names only {id} and {key.<column>} of that source's key. A
|
|
68
|
+
* misspelling would otherwise only show as links that never appear: refuse to start.
|
|
69
|
+
*/
|
|
70
|
+
function checkItemLinks(options) {
|
|
71
|
+
for (const [source, template] of Object.entries(options.itemLinks ?? {})) {
|
|
72
|
+
const def = options.model.sources[source];
|
|
73
|
+
if (def === void 0) throw new Error(`itemLinks names "${source}", which is not a source of the model.`);
|
|
74
|
+
const [problem] = linkTemplateIssues(template, def.key);
|
|
75
|
+
if (problem !== void 0) throw new Error(`itemLinks.${source} ${problem}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
57
78
|
/** One endpoint by path; a streamed answer is read to its end and comes back as its lines. */
|
|
58
79
|
async function callPath(byPath, path, input) {
|
|
59
80
|
const call = byPath.get(path);
|
|
@@ -74,14 +95,20 @@ async function callPath(byPath, path, input) {
|
|
|
74
95
|
function deriveDashboards(options) {
|
|
75
96
|
defineModel(options.model);
|
|
76
97
|
checkConnections(options);
|
|
98
|
+
checkItemLinks(options);
|
|
77
99
|
const checked = {
|
|
78
100
|
...options,
|
|
79
101
|
dashboards: checkedDashboards(options)
|
|
80
102
|
};
|
|
81
103
|
const rt = {
|
|
82
104
|
options: checked,
|
|
83
|
-
cache: createCache(checked)
|
|
105
|
+
cache: createCache(checked),
|
|
106
|
+
cursorKey: cursorKey(options.secret),
|
|
107
|
+
macKey: macKey(options.secret),
|
|
108
|
+
drillModel: drillModel(checked.model),
|
|
109
|
+
warned: { secret: false }
|
|
84
110
|
};
|
|
111
|
+
warnSecretAtStart(rt);
|
|
85
112
|
const library = coreEndpoints(rt);
|
|
86
113
|
checkPluginIds(options, ["cache", ...Object.keys(library)]);
|
|
87
114
|
const plugins = options.plugins ?? [];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ok, table } from "./format.mjs";
|
|
2
|
+
import { itemLink } from "derive-dashboards/core";
|
|
3
|
+
// src/mcp/drill.ts
|
|
4
|
+
/** A value as text: a plain value as itself, an exact number by its digits. */
|
|
5
|
+
const text = (cell) => typeof cell === "object" && cell !== null ? cell.v : String(cell);
|
|
6
|
+
/** One breadcrumb in words: Other only for an Other step, "not set" for a group with no value. */
|
|
7
|
+
function crumbText(p) {
|
|
8
|
+
if (p.parts !== void 0) return p.parts.map((q) => crumbText(q)).join(", ");
|
|
9
|
+
if (p.kind === "other") return `${p.label}: Other`;
|
|
10
|
+
if (p.kind === "search") return `${p.label} contains "${text(p.value ?? "")}"`;
|
|
11
|
+
if (p.kind === "total") return "Total";
|
|
12
|
+
return `${p.label}: ${p.value === null ? "not set" : text(p.value)}`;
|
|
13
|
+
}
|
|
14
|
+
/** What the answer is about, in one line: how many rows, behind which path. */
|
|
15
|
+
function heading(answer, shown) {
|
|
16
|
+
const where = answer.path.map((p) => crumbText(p)).join(" › ");
|
|
17
|
+
return `${text(answer.summary?.itemCount ?? shown)} rows behind ${where === "" ? "the tile" : where}`;
|
|
18
|
+
}
|
|
19
|
+
/** The drill's answer, asked as the agent's person: of a dashboard's tile, or of a free query. */
|
|
20
|
+
function ask(c, drill, page) {
|
|
21
|
+
const body = {
|
|
22
|
+
state: {
|
|
23
|
+
...drill,
|
|
24
|
+
view: { by: "items" }
|
|
25
|
+
},
|
|
26
|
+
page: {
|
|
27
|
+
limit: page.limit ?? 50,
|
|
28
|
+
...page.after === void 0 ? {} : { after: page.after }
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return drill.origin.kind === "dashboard" ? c.dashboards.api.drill({
|
|
32
|
+
body,
|
|
33
|
+
viewer: c.viewer
|
|
34
|
+
}) : c.dashboards.api.queryDrill({
|
|
35
|
+
body,
|
|
36
|
+
viewer: c.viewer
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The rows behind one mark, for an agent: the same drill a person opens, with the same checks,
|
|
41
|
+
* as a table of its items, each with its link in the host's app when `itemLinks` gives one.
|
|
42
|
+
*/
|
|
43
|
+
async function drillRows(c, drill, page) {
|
|
44
|
+
const answer = await ask(c, drill, page);
|
|
45
|
+
const view = answer.view.by === "items" ? answer.view : void 0;
|
|
46
|
+
const items = (view?.items ?? []).map((item) => ({
|
|
47
|
+
...item,
|
|
48
|
+
link: item.link ?? itemLink(c.itemLinks, item)
|
|
49
|
+
}));
|
|
50
|
+
const columns = view?.columns ?? [];
|
|
51
|
+
const labels = [...columns.map((col) => col.label), "Link"];
|
|
52
|
+
const rows = items.map((item) => [...columns.map((col) => item.values[col.member] ?? null), item.link ?? ""]);
|
|
53
|
+
return ok(`${heading(answer, items.length)}\n\n${table(labels, rows)}`, {
|
|
54
|
+
...answer,
|
|
55
|
+
view: {
|
|
56
|
+
...view,
|
|
57
|
+
items
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export { drillRows };
|
package/dist/mcp/format.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpError } from "../http.mjs";
|
|
2
|
+
import { EngineError } from "derive-dashboards/core/engine";
|
|
2
3
|
// src/mcp/format.ts
|
|
3
4
|
/** The most rows a table shows the model; the rest are counted, and all are in the structured answer. */
|
|
4
5
|
const SHOWN = 30;
|
|
@@ -40,9 +41,32 @@ const ok = (text, data) => ({
|
|
|
40
41
|
}],
|
|
41
42
|
...data === void 0 ? {} : { structuredContent: { result: data } }
|
|
42
43
|
});
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* A refusal the model can act on: the code, the reason, each problem with the input, and a hint.
|
|
46
|
+
* An engine refusal keeps its code; anything else goes to `onError` and the model reads only
|
|
47
|
+
* INTERNAL, never a database's own message, which can name columns or echo stored values.
|
|
48
|
+
*/
|
|
49
|
+
function refused(error, hint, onError = (e) => {
|
|
50
|
+
console.error(e);
|
|
51
|
+
}) {
|
|
52
|
+
if (error instanceof EngineError) return {
|
|
53
|
+
content: [{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: `${error.code}: ${error.message}`
|
|
56
|
+
}],
|
|
57
|
+
isError: true
|
|
58
|
+
};
|
|
59
|
+
if (!(error instanceof HttpError)) {
|
|
60
|
+
onError(error);
|
|
61
|
+
return {
|
|
62
|
+
content: [{
|
|
63
|
+
type: "text",
|
|
64
|
+
text: "INTERNAL: Something went wrong answering this. It was logged."
|
|
65
|
+
}],
|
|
66
|
+
isError: true
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (error.cause !== void 0) onError(error.cause);
|
|
46
70
|
const issues = (error.issues ?? []).map((i) => `- ${i.path.join(".") || "input"}: ${i.message}`);
|
|
47
71
|
return {
|
|
48
72
|
content: [{
|
package/dist/mcp/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiServer } from "./api.mjs";
|
|
2
2
|
import { ToolResult } from "./format.mjs";
|
|
3
|
-
import { Viewer } from "derive-dashboards/core";
|
|
3
|
+
import { ItemLinks, Viewer, ViewerFor } from "derive-dashboards/core";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
/** MCP's tool annotations: what a client may assume about a tool before it runs it. */
|
|
6
6
|
export type ToolAnnotations = {
|
|
@@ -29,6 +29,10 @@ export type DashboardToolsOptions = {
|
|
|
29
29
|
api?: boolean;
|
|
30
30
|
/** The link to a dashboard in your app, given with every dashboard the agent opens. */
|
|
31
31
|
linkFor?: (dashboardId: string) => string;
|
|
32
|
+
/** Where each source's items open in your app; by default the server's own `itemLinks`. */
|
|
33
|
+
itemLinks?: ItemLinks;
|
|
34
|
+
/** Where an unexpected error goes (its message never reaches the model); the console without one. */
|
|
35
|
+
onError?: (error: unknown) => void;
|
|
32
36
|
};
|
|
33
37
|
/** The two tools, as plain data: `name`, `description`, `inputSchema` (Zod), `annotations`, `run(input, viewer)`. */
|
|
34
38
|
export declare function dashboardTools(dashboards: ApiServer, options?: DashboardToolsOptions): DashboardTool[];
|
|
@@ -51,11 +55,18 @@ export type McpServerLike = {
|
|
|
51
55
|
annotations?: ToolAnnotations;
|
|
52
56
|
}, callback: (input: Record<string, unknown>, extra: McpCallExtra) => Promise<ToolResult>): unknown;
|
|
53
57
|
};
|
|
58
|
+
/** The model a dashboards server was made with, when its type says; else any. */
|
|
59
|
+
type ModelOf<S> = S extends {
|
|
60
|
+
options: {
|
|
61
|
+
model: infer M;
|
|
62
|
+
};
|
|
63
|
+
} ? M : unknown;
|
|
54
64
|
/**
|
|
55
65
|
* Adds the two tools to an MCP server you already run. `viewer` reads the person from the
|
|
56
|
-
* call (`extra.authInfo` from your MCP auth); none refuses the call.
|
|
66
|
+
* call (`extra.authInfo` from your MCP auth); none refuses the call. It is typed from the
|
|
67
|
+
* server's model, as `deriveDashboards`'s own `viewer` is: with tenant keys, each is required.
|
|
57
68
|
*/
|
|
58
|
-
export declare function addDashboardTools(server: McpServerLike, dashboards:
|
|
59
|
-
viewer: (extra: McpCallExtra) =>
|
|
69
|
+
export declare function addDashboardTools<S extends ApiServer>(server: McpServerLike, dashboards: S, options: DashboardToolsOptions & {
|
|
70
|
+
viewer: (extra: McpCallExtra) => ViewerFor<ModelOf<S>> | null | Promise<ViewerFor<ModelOf<S>> | null>;
|
|
60
71
|
}): void;
|
|
61
72
|
export type { ToolResult };
|