@surfaces-ui/components 0.0.0-stage → 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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +48 -2
- package/dist/appComponents.d.ts +86 -0
- package/dist/appComponents.js +555 -0
- package/dist/appComponents.js.map +1 -0
- package/dist/chart/BulletGraph.d.ts +44 -0
- package/dist/chart/BulletGraph.js +40 -0
- package/dist/chart/BulletGraph.js.map +1 -0
- package/dist/chart/Chart.d.ts +177 -0
- package/dist/chart/Chart.js +279 -0
- package/dist/chart/Chart.js.map +1 -0
- package/dist/chart/Sparkline.d.ts +35 -0
- package/dist/chart/Sparkline.js +37 -0
- package/dist/chart/Sparkline.js.map +1 -0
- package/dist/chart/advice.d.ts +28 -0
- package/dist/chart/advice.js +39 -0
- package/dist/chart/advice.js.map +1 -0
- package/dist/chart/option.d.ts +90 -0
- package/dist/chart/option.js +252 -0
- package/dist/chart/option.js.map +1 -0
- package/dist/controls/Combobox.d.ts +39 -0
- package/dist/controls/Combobox.js +75 -0
- package/dist/controls/Combobox.js.map +1 -0
- package/dist/controls/ConfirmDialog.d.ts +35 -0
- package/dist/controls/ConfirmDialog.js +84 -0
- package/dist/controls/ConfirmDialog.js.map +1 -0
- package/dist/controls/ItemControls.d.ts +115 -0
- package/dist/controls/ItemControls.js +109 -0
- package/dist/controls/ItemControls.js.map +1 -0
- package/dist/controls/Popover.d.ts +31 -0
- package/dist/controls/Popover.js +114 -0
- package/dist/controls/Popover.js.map +1 -0
- package/dist/controls/ResizeHandle.d.ts +48 -0
- package/dist/controls/ResizeHandle.js +91 -0
- package/dist/controls/ResizeHandle.js.map +1 -0
- package/dist/controls/SegmentedControl.d.ts +27 -0
- package/dist/controls/SegmentedControl.js +17 -0
- package/dist/controls/SegmentedControl.js.map +1 -0
- package/dist/controls/StatusBadge.d.ts +17 -0
- package/dist/controls/StatusBadge.js +10 -0
- package/dist/controls/StatusBadge.js.map +1 -0
- package/dist/controls/context.d.ts +17 -0
- package/dist/controls/context.js +2 -0
- package/dist/controls/context.js.map +1 -0
- package/dist/controls/placement.d.ts +43 -0
- package/dist/controls/placement.js +19 -0
- package/dist/controls/placement.js.map +1 -0
- package/dist/controls/resize.d.ts +23 -0
- package/dist/controls/resize.js +49 -0
- package/dist/controls/resize.js.map +1 -0
- package/dist/data/DataSourceProvider.d.ts +11 -0
- package/dist/data/DataSourceProvider.js +21 -0
- package/dist/data/DataSourceProvider.js.map +1 -0
- package/dist/data/export.d.ts +33 -0
- package/dist/data/export.js +77 -0
- package/dist/data/export.js.map +1 -0
- package/dist/data/format.d.ts +44 -0
- package/dist/data/format.js +127 -0
- package/dist/data/format.js.map +1 -0
- package/dist/data/messages.d.ts +13 -0
- package/dist/data/messages.js +2 -0
- package/dist/data/messages.js.map +1 -0
- package/dist/data/useRowWindow.d.ts +70 -0
- package/dist/data/useRowWindow.js +175 -0
- package/dist/data/useRowWindow.js.map +1 -0
- package/dist/discovery/AskData.d.ts +22 -0
- package/dist/discovery/AskData.js +48 -0
- package/dist/discovery/AskData.js.map +1 -0
- package/dist/discovery/ContextBuilder.d.ts +49 -0
- package/dist/discovery/ContextBuilder.js +167 -0
- package/dist/discovery/ContextBuilder.js.map +1 -0
- package/dist/discovery/DataSearch.d.ts +27 -0
- package/dist/discovery/DataSearch.js +73 -0
- package/dist/discovery/DataSearch.js.map +1 -0
- package/dist/discovery/ObjectDetail.d.ts +38 -0
- package/dist/discovery/ObjectDetail.js +129 -0
- package/dist/discovery/ObjectDetail.js.map +1 -0
- package/dist/discovery/RelationshipGraph.d.ts +19 -0
- package/dist/discovery/RelationshipGraph.js +64 -0
- package/dist/discovery/RelationshipGraph.js.map +1 -0
- package/dist/discovery/shared.d.ts +38 -0
- package/dist/discovery/shared.js +64 -0
- package/dist/discovery/shared.js.map +1 -0
- package/dist/editor/SqlEditor.d.ts +41 -0
- package/dist/editor/SqlEditor.js +181 -0
- package/dist/editor/SqlEditor.js.map +1 -0
- package/dist/explore/Explorer.d.ts +110 -0
- package/dist/explore/Explorer.js +471 -0
- package/dist/explore/Explorer.js.map +1 -0
- package/dist/explore/ModelLineage.d.ts +22 -0
- package/dist/explore/ModelLineage.js +70 -0
- package/dist/explore/ModelLineage.js.map +1 -0
- package/dist/explore/ReportBuilder.d.ts +39 -0
- package/dist/explore/ReportBuilder.js +98 -0
- package/dist/explore/ReportBuilder.js.map +1 -0
- package/dist/explore/SemanticModelEditor.d.ts +60 -0
- package/dist/explore/SemanticModelEditor.js +220 -0
- package/dist/explore/SemanticModelEditor.js.map +1 -0
- package/dist/explore/SemanticRows.d.ts +42 -0
- package/dist/explore/SemanticRows.js +117 -0
- package/dist/explore/SemanticRows.js.map +1 -0
- package/dist/explore/SemanticsProvider.d.ts +31 -0
- package/dist/explore/SemanticsProvider.js +72 -0
- package/dist/explore/SemanticsProvider.js.map +1 -0
- package/dist/explore/model.d.ts +151 -0
- package/dist/explore/model.js +344 -0
- package/dist/explore/model.js.map +1 -0
- package/dist/explore/report.d.ts +60 -0
- package/dist/explore/report.js +92 -0
- package/dist/explore/report.js.map +1 -0
- package/dist/explore/semantic-proposal.d.ts +44 -0
- package/dist/explore/semantic-proposal.js +67 -0
- package/dist/explore/semantic-proposal.js.map +1 -0
- package/dist/explore/semantic.d.ts +44 -0
- package/dist/explore/semantic.js +154 -0
- package/dist/explore/semantic.js.map +1 -0
- package/dist/files/FileBrowser.d.ts +42 -0
- package/dist/files/FileBrowser.js +314 -0
- package/dist/files/FileBrowser.js.map +1 -0
- package/dist/files/files.d.ts +65 -0
- package/dist/files/files.js +165 -0
- package/dist/files/files.js.map +1 -0
- package/dist/filter/FilterBar.d.ts +49 -0
- package/dist/filter/FilterBar.js +153 -0
- package/dist/filter/FilterBar.js.map +1 -0
- package/dist/filter/QueryFilters.d.ts +25 -0
- package/dist/filter/QueryFilters.js +58 -0
- package/dist/filter/QueryFilters.js.map +1 -0
- package/dist/form/Form.d.ts +76 -0
- package/dist/form/Form.js +131 -0
- package/dist/form/Form.js.map +1 -0
- package/dist/graph/NodeGraph.d.ts +30 -0
- package/dist/graph/NodeGraph.js +86 -0
- package/dist/graph/NodeGraph.js.map +1 -0
- package/dist/graph/model.d.ts +68 -0
- package/dist/graph/model.js +122 -0
- package/dist/graph/model.js.map +1 -0
- package/dist/grid/DataGrid.d.ts +98 -0
- package/dist/grid/DataGrid.js +399 -0
- package/dist/grid/DataGrid.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/locale/SurfacesText.d.ts +17 -0
- package/dist/locale/SurfacesText.js +17 -0
- package/dist/locale/SurfacesText.js.map +1 -0
- package/dist/locale/locale.d.ts +305 -0
- package/dist/locale/locale.js +359 -0
- package/dist/locale/locale.js.map +1 -0
- package/dist/menu/ContextMenu.d.ts +31 -0
- package/dist/menu/ContextMenu.js +95 -0
- package/dist/menu/ContextMenu.js.map +1 -0
- package/dist/metric/Metric.d.ts +33 -0
- package/dist/metric/Metric.js +63 -0
- package/dist/metric/Metric.js.map +1 -0
- package/dist/metric/useMeasure.d.ts +23 -0
- package/dist/metric/useMeasure.js +43 -0
- package/dist/metric/useMeasure.js.map +1 -0
- package/dist/model/ModelDiagram.d.ts +142 -0
- package/dist/model/ModelDiagram.js +699 -0
- package/dist/model/ModelDiagram.js.map +1 -0
- package/dist/panzoom/usePanZoom.d.ts +117 -0
- package/dist/panzoom/usePanZoom.js +313 -0
- package/dist/panzoom/usePanZoom.js.map +1 -0
- package/dist/pipeline/DatasetReview.d.ts +48 -0
- package/dist/pipeline/DatasetReview.js +157 -0
- package/dist/pipeline/DatasetReview.js.map +1 -0
- package/dist/pipeline/IngestWizard.d.ts +51 -0
- package/dist/pipeline/IngestWizard.js +79 -0
- package/dist/pipeline/IngestWizard.js.map +1 -0
- package/dist/pipeline/Pipeline.d.ts +171 -0
- package/dist/pipeline/Pipeline.js +203 -0
- package/dist/pipeline/Pipeline.js.map +1 -0
- package/dist/pipeline/PipelineView.d.ts +63 -0
- package/dist/pipeline/PipelineView.js +239 -0
- package/dist/pipeline/PipelineView.js.map +1 -0
- package/dist/pivot/PivotTable.d.ts +94 -0
- package/dist/pivot/PivotTable.js +171 -0
- package/dist/pivot/PivotTable.js.map +1 -0
- package/dist/plan/QueryPlan.d.ts +29 -0
- package/dist/plan/QueryPlan.js +79 -0
- package/dist/plan/QueryPlan.js.map +1 -0
- package/dist/result/QueryResult.d.ts +51 -0
- package/dist/result/QueryResult.js +255 -0
- package/dist/result/QueryResult.js.map +1 -0
- package/dist/review/ActionReceipt.d.ts +52 -0
- package/dist/review/ActionReceipt.js +32 -0
- package/dist/review/ActionReceipt.js.map +1 -0
- package/dist/review/PiiReview.d.ts +37 -0
- package/dist/review/PiiReview.js +29 -0
- package/dist/review/PiiReview.js.map +1 -0
- package/dist/review/PlanReview.d.ts +42 -0
- package/dist/review/PlanReview.js +37 -0
- package/dist/review/PlanReview.js.map +1 -0
- package/dist/review/StepFlow.d.ts +25 -0
- package/dist/review/StepFlow.js +21 -0
- package/dist/review/StepFlow.js.map +1 -0
- package/dist/review/pii.d.ts +21 -0
- package/dist/review/pii.js +67 -0
- package/dist/review/pii.js.map +1 -0
- package/dist/rows/RowList.d.ts +41 -0
- package/dist/rows/RowList.js +71 -0
- package/dist/rows/RowList.js.map +1 -0
- package/dist/schema/ObjectBrowser.d.ts +78 -0
- package/dist/schema/ObjectBrowser.js +467 -0
- package/dist/schema/ObjectBrowser.js.map +1 -0
- package/dist/schema/ObjectInfo.d.ts +25 -0
- package/dist/schema/ObjectInfo.js +69 -0
- package/dist/schema/ObjectInfo.js.map +1 -0
- package/dist/schema/SchemaExplorer.d.ts +32 -0
- package/dist/schema/SchemaExplorer.js +175 -0
- package/dist/schema/SchemaExplorer.js.map +1 -0
- package/dist/schema/refs.d.ts +32 -0
- package/dist/schema/refs.js +65 -0
- package/dist/schema/refs.js.map +1 -0
- package/dist/site/Site.d.ts +191 -0
- package/dist/site/Site.js +138 -0
- package/dist/site/Site.js.map +1 -0
- package/dist/source/ConnectionBuilder.d.ts +54 -0
- package/dist/source/ConnectionBuilder.js +115 -0
- package/dist/source/ConnectionBuilder.js.map +1 -0
- package/dist/source/SourceList.d.ts +17 -0
- package/dist/source/SourceList.js +71 -0
- package/dist/source/SourceList.js.map +1 -0
- package/dist/styles.css +9882 -0
- package/dist/styles.layer.css +9886 -0
- package/dist/table/DataTable.d.ts +72 -0
- package/dist/table/DataTable.js +68 -0
- package/dist/table/DataTable.js.map +1 -0
- package/dist/table/Pagination.d.ts +20 -0
- package/dist/table/Pagination.js +16 -0
- package/dist/table/Pagination.js.map +1 -0
- package/dist/table/SelectionBar.d.ts +43 -0
- package/dist/table/SelectionBar.js +18 -0
- package/dist/table/SelectionBar.js.map +1 -0
- package/dist/text/Markdown.d.ts +71 -0
- package/dist/text/Markdown.js +187 -0
- package/dist/text/Markdown.js.map +1 -0
- package/dist/text/highlight.d.ts +23 -0
- package/dist/text/highlight.js +196 -0
- package/dist/text/highlight.js.map +1 -0
- package/dist/theme/ThemePicker.d.ts +16 -0
- package/dist/theme/ThemePicker.js +49 -0
- package/dist/theme/ThemePicker.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +43 -0
- package/dist/theme/ThemeProvider.js +107 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/workspace/NavBar.d.ts +23 -0
- package/dist/workspace/NavBar.js +171 -0
- package/dist/workspace/NavBar.js.map +1 -0
- package/dist/workspace/SideNav.d.ts +61 -0
- package/dist/workspace/SideNav.js +149 -0
- package/dist/workspace/SideNav.js.map +1 -0
- package/dist/workspace/Workspace.d.ts +50 -0
- package/dist/workspace/Workspace.js +243 -0
- package/dist/workspace/Workspace.js.map +1 -0
- package/dist/workspace/icons.d.ts +34 -0
- package/dist/workspace/icons.js +37 -0
- package/dist/workspace/icons.js.map +1 -0
- package/dist/workspace/layout.d.ts +74 -0
- package/dist/workspace/layout.js +276 -0
- package/dist/work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C,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAChI,CAAC","sourcesContent":["import type { FilterSpec } from \"@surfaces-ui/data\";\nimport { type ExploreChartSettings, type ExploreState, type Pill, normalizeExplore } from \"./model.js\";\n\n/** One view on a report: what is on its shelves, drawn from the report's pills and filters. */\nexport interface ReportTile {\n id: string;\n /** Shown above the tile. Left out, the shelves are read out: \"Refund rate by Category\". */\n title?: string;\n rows: string[];\n split?: string;\n values: string[];\n view?: \"chart\" | \"table\";\n /** How its chart is drawn: type, axes swapped, each measure's own type and scale. */\n chart?: ExploreChartSettings;\n /** How many of the report's three columns it takes. Defaults to 1; headline numbers take the row. */\n span?: 1 | 2 | 3;\n}\n\n/**\n * A report: pills defined once, filters shared by every view, and the views\n * themselves as tiles. This is the whole of a dashboard as plain JSON, so\n * it can be saved, reviewed, sent to an agent and written by one.\n */\nexport interface ReportState {\n title?: string;\n /** The report's fields. Every tile and the builder use these, so a metric means the same thing everywhere on it. */\n fields: Pill[];\n /** Filters every tile follows. */\n filters: FilterSpec[];\n tiles: ReportTile[];\n /** What is on the builder's shelves: the tile being made, or the one being changed. */\n draft?: Pick<ReportTile, \"rows\" | \"split\" | \"values\" | \"view\" | \"chart\">;\n /** The tile the draft will replace, when one is being changed. */\n editing?: string;\n}\n\nexport const emptyReport: ReportState = { fields: [], filters: [], tiles: [] };\nexport const MAX_TILES = 24;\n\n/** A tile's shelves as an explorer state over the report's pills and filters. */\nexport function tileState(report: ReportState, tile: Pick<ReportTile, \"rows\" | \"split\" | \"values\" | \"view\" | \"chart\">): ExploreState {\n return normalizeExplore({ fields: report.fields, rows: tile.rows, ...(tile.split ? { split: tile.split } : {}), values: tile.values, filters: report.filters, ...(tile.view ? { view: tile.view } : {}), ...(tile.chart ? { chart: tile.chart } : {}) });\n}\n\n/** The builder's own state: the draft over the report's pills and filters. */\nexport function draftState(report: ReportState): ExploreState {\n // Not normalised here: a draft can name pills that are generated only once the columns are known.\n const draft = report.draft ?? { rows: [], values: [] };\n return { fields: report.fields, rows: draft.rows, ...(draft.split ? { split: draft.split } : {}), values: draft.values, filters: report.filters, ...(draft.view ? { view: draft.view } : {}), ...(draft.chart ? { chart: draft.chart } : {}) };\n}\n\n/** The report after the builder changed: its pills and filters are the report's, the shelves are the draft. */\nexport function withDraft(report: ReportState, state: ExploreState): ReportState {\n return { ...report, fields: state.fields, filters: state.filters, draft: { rows: state.rows, ...(state.split ? { split: state.split } : {}), values: state.values, ...(state.view ? { view: state.view } : {}), ...(state.chart ? { chart: state.chart } : {}) } };\n}\n\nconst nextId = (tiles: ReportTile[]) => {\n for (let n = tiles.length + 1; ; n++) if (!tiles.some((t) => t.id === `tile-${n}`)) return `tile-${n}`;\n};\n\n/**\n * Keeps the draft as a tile: a new one at the end, or in place of the tile\n * being changed. A draft with nothing to measure is not kept. The shelves\n * are left as they are, so the next tile starts from this one.\n */\nexport function keepDraft(report: ReportState, title?: string): ReportState {\n const draft = report.draft;\n const state = draft ? tileState(report, draft) : undefined;\n if (!draft || !state || state.values.length === 0) return report;\n const shelves = { rows: state.rows, ...(state.split ? { split: state.split } : {}), values: state.values, ...(draft.view ? { view: draft.view } : {}), chart: state.chart };\n if (report.editing && report.tiles.some((t) => t.id === report.editing)) {\n return { ...report, tiles: report.tiles.map((t) => (t.id === report.editing ? { ...t, ...shelves, ...(shelves.split ? {} : { split: undefined }), ...(title !== undefined ? { title: title || undefined } : {}) } : t)), editing: undefined };\n }\n if (report.tiles.length >= MAX_TILES) return report;\n // Headline numbers read best across the top of the row.\n const span = state.rows.length === 0 ? 3 : 1;\n const { chart, ...rest } = shelves;\n return { ...report, tiles: [...report.tiles, { id: nextId(report.tiles), ...(title ? { title } : {}), ...rest, ...(chart ? { chart } : {}), span }] };\n}\n\n/** Opens a tile in the builder, to change it. */\nexport function editTile(report: ReportState, id: string): ReportState {\n const tile = report.tiles.find((t) => t.id === id);\n if (!tile) return report;\n return { ...report, editing: id, draft: { rows: tile.rows, ...(tile.split ? { split: tile.split } : {}), values: tile.values, ...(tile.view ? { view: tile.view } : {}), ...(tile.chart ? { chart: tile.chart } : {}) } };\n}\n\nexport function removeTile(report: ReportState, id: string): ReportState {\n return { ...report, tiles: report.tiles.filter((t) => t.id !== id), ...(report.editing === id ? { editing: undefined } : {}) };\n}\n\n/** Moves a tile one place earlier (-1) or later (1). At an end, nothing changes. */\nexport function moveTile(report: ReportState, id: string, by: -1 | 1): ReportState {\n const from = report.tiles.findIndex((t) => t.id === id);\n const to = from + by;\n if (from < 0 || to < 0 || to >= report.tiles.length) return report;\n const tiles = [...report.tiles];\n [tiles[from], tiles[to]] = [tiles[to]!, tiles[from]!];\n return { ...report, tiles };\n}\n\nexport function setTile(report: ReportState, id: string, change: Partial<Pick<ReportTile, \"title\" | \"span\" | \"view\">>): ReportState {\n return { ...report, tiles: report.tiles.map((t) => (t.id === id ? { ...t, ...change } : t)) };\n}\n\n/**\n * A report with nothing that cannot be drawn: tiles that name pills that are\n * gone lose them, a tile left with nothing to measure is dropped, and ids\n * are made unlike each other. Whatever its source (a saved page, an agent),\n * a report goes through this before it is shown.\n */\nexport function normalizeReport(report: ReportState): ReportState {\n // Before the pills exist (they are generated once the columns are known) there is nothing to check tiles against.\n if (report.fields.length === 0) return report;\n const seen = new Set<string>();\n const tiles: ReportTile[] = [];\n for (const tile of report.tiles.slice(0, MAX_TILES)) {\n const state = tileState(report, tile);\n if (state.values.length === 0) continue;\n let id = tile.id || nextId(tiles);\n if (seen.has(id)) id = nextId(tiles);\n seen.add(id);\n const span = tile.span === 2 || tile.span === 3 ? tile.span : 1;\n tiles.push({ id, ...(tile.title ? { title: tile.title } : {}), rows: state.rows, ...(state.split ? { split: state.split } : {}), values: state.values, ...(tile.view ? { view: tile.view } : {}), ...(state.chart ? { chart: state.chart } : {}), span });\n }\n return { ...report, tiles, ...(report.editing && !tiles.some((t) => t.id === report.editing) ? { editing: undefined } : {}) };\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type SemanticModel } from "@surfaces-ui/proto";
|
|
2
|
+
import type { Pill } from "./model.js";
|
|
3
|
+
import type { JoinKind } from "../model/ModelDiagram.js";
|
|
4
|
+
/** A join as an agent writes it: two tables and the columns that match. */
|
|
5
|
+
export interface ProposedJoin {
|
|
6
|
+
left: string;
|
|
7
|
+
right: string;
|
|
8
|
+
keys: {
|
|
9
|
+
leftColumn: string;
|
|
10
|
+
rightColumn: string;
|
|
11
|
+
}[];
|
|
12
|
+
/** Which rows it keeps, read from left to right. Left out, "left": every row of the left table, the one nearer the first, so adding detail never drops a row. */
|
|
13
|
+
type?: JoinKind;
|
|
14
|
+
}
|
|
15
|
+
/** What one row is and where the rows come from, as proposed. Any part left out stays as it is. */
|
|
16
|
+
export interface ProposedRows {
|
|
17
|
+
grain?: string;
|
|
18
|
+
primaryKey?: string[];
|
|
19
|
+
/** The tables, the first being the one whose rows the model's rows are. With them the query is generated, unless `sql` is given too. */
|
|
20
|
+
tables?: string[];
|
|
21
|
+
joins?: ProposedJoin[];
|
|
22
|
+
/** A query written out, in place of tables and joins. */
|
|
23
|
+
sql?: string;
|
|
24
|
+
/** A dataset a pipeline builds, in place of tables, joins and a query: the model reads its table, and its grain and key should be the dataset's, which the pipeline checks. */
|
|
25
|
+
dataset?: {
|
|
26
|
+
pipeline: string;
|
|
27
|
+
dataset: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A change to a semantic model in the plain form an agent writes and a
|
|
32
|
+
* person's edits come back in: fields to add or put in place (as pills),
|
|
33
|
+
* names to take out, and the rows. The same shape proposes a new model,
|
|
34
|
+
* starting from an empty one.
|
|
35
|
+
*/
|
|
36
|
+
export interface SemanticProposal {
|
|
37
|
+
add?: Pill[];
|
|
38
|
+
remove?: string[];
|
|
39
|
+
rows?: ProposedRows;
|
|
40
|
+
}
|
|
41
|
+
/** The model with a proposal applied, every field and join it adds marked as `by`'s. Nothing is saved. */
|
|
42
|
+
export declare function applyProposal(model: SemanticModel, proposal: SemanticProposal, by: string): SemanticModel;
|
|
43
|
+
/** A draft as the proposal that would make it from `model`: what a person left in or changed, in the form the agent wrote. */
|
|
44
|
+
export declare function proposalFrom(model: SemanticModel, draft: SemanticModel): SemanticProposal;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { clone, create } from "@bufbuild/protobuf";
|
|
2
|
+
import { SemanticDatasetSchema, SemanticJoinSchema, SemanticModelSchema } from "@surfaces-ui/proto";
|
|
3
|
+
import { modelChanges, pillsFromModel, setModelField } from "./semantic.js";
|
|
4
|
+
import { joinKindOf, joinTypeOf, semanticSql } from "./SemanticRows.js";
|
|
5
|
+
import { datasetSql } from "@surfaces-ui/data";
|
|
6
|
+
/** The model with a proposal applied, every field and join it adds marked as `by`'s. Nothing is saved. */
|
|
7
|
+
export function applyProposal(model, proposal, by) {
|
|
8
|
+
let next = model;
|
|
9
|
+
for (const name of proposal.remove ?? [])
|
|
10
|
+
next = setModelField(next, name, undefined, by);
|
|
11
|
+
for (const pill of proposal.add ?? [])
|
|
12
|
+
next = setModelField(next, pill.id, pill, pill.by || by);
|
|
13
|
+
const rows = proposal.rows;
|
|
14
|
+
if (!rows)
|
|
15
|
+
return next;
|
|
16
|
+
next = clone(SemanticModelSchema, next);
|
|
17
|
+
if (rows.grain !== undefined)
|
|
18
|
+
next.grain = rows.grain;
|
|
19
|
+
if (rows.primaryKey !== undefined)
|
|
20
|
+
next.primaryKey = [...rows.primaryKey];
|
|
21
|
+
if (rows.tables !== undefined || rows.joins !== undefined) {
|
|
22
|
+
next.tables = [...(rows.tables ?? next.tables)];
|
|
23
|
+
next.joins = (rows.joins ?? []).map((j) => create(SemanticJoinSchema, { left: j.left, right: j.right, keys: j.keys, type: joinTypeOf(j.type ?? "left"), definedBy: by }));
|
|
24
|
+
// Until the editor has read the columns and can name each one, the query is the plain form.
|
|
25
|
+
next.sql = semanticSql({ tables: next.tables, joins: next.joins.map((j) => ({ left: j.left, right: j.right, keys: j.keys, type: joinKindOf(j.type) })) }).sql;
|
|
26
|
+
}
|
|
27
|
+
if (rows.sql !== undefined) {
|
|
28
|
+
next.sql = rows.sql;
|
|
29
|
+
if (rows.tables === undefined)
|
|
30
|
+
(next.tables = []), (next.joins = []);
|
|
31
|
+
}
|
|
32
|
+
if (rows.dataset) {
|
|
33
|
+
next.dataset = create(SemanticDatasetSchema, { pipelineId: rows.dataset.pipeline, dataset: rows.dataset.dataset });
|
|
34
|
+
next.sql = datasetSql(rows.dataset.dataset);
|
|
35
|
+
next.tables = [];
|
|
36
|
+
next.joins = [];
|
|
37
|
+
}
|
|
38
|
+
else if (rows.sql !== undefined || rows.tables !== undefined)
|
|
39
|
+
next.dataset = undefined;
|
|
40
|
+
return next;
|
|
41
|
+
}
|
|
42
|
+
/** A draft as the proposal that would make it from `model`: what a person left in or changed, in the form the agent wrote. */
|
|
43
|
+
export function proposalFrom(model, draft) {
|
|
44
|
+
const changes = modelChanges(model, draft);
|
|
45
|
+
const after = new Map(pillsFromModel(draft).map((p) => [p.id, p]));
|
|
46
|
+
const out = {
|
|
47
|
+
add: [...changes].filter(([name, kind]) => kind !== "removed" && after.has(name)).map(([name]) => after.get(name)),
|
|
48
|
+
remove: [...changes].filter(([, kind]) => kind === "removed").map(([name]) => name),
|
|
49
|
+
};
|
|
50
|
+
const rows = {};
|
|
51
|
+
if (changes.has("(grain)"))
|
|
52
|
+
rows.grain = draft.grain;
|
|
53
|
+
if (changes.has("(primaryKey)"))
|
|
54
|
+
rows.primaryKey = draft.primaryKey;
|
|
55
|
+
if (changes.has("(joins)")) {
|
|
56
|
+
rows.tables = draft.tables;
|
|
57
|
+
rows.joins = draft.joins.map((j) => ({ left: j.left, right: j.right, keys: j.keys.map((k) => ({ leftColumn: k.leftColumn, rightColumn: k.rightColumn })), type: joinKindOf(j.type) }));
|
|
58
|
+
}
|
|
59
|
+
if (draft.dataset && changes.has("(dataset)"))
|
|
60
|
+
rows.dataset = { pipeline: draft.dataset.pipelineId, dataset: draft.dataset.dataset };
|
|
61
|
+
else if (changes.has("(sql)") && draft.tables.length === 0)
|
|
62
|
+
rows.sql = draft.sql;
|
|
63
|
+
if (Object.keys(rows).length > 0)
|
|
64
|
+
out.rows = rows;
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=semantic-proposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-proposal.js","sourceRoot":"","sources":["../../src/explore/semantic-proposal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAsB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAExH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAoC/C,0GAA0G;AAC1G,MAAM,UAAU,aAAa,CAAC,KAAoB,EAAE,QAA0B,EAAE,EAAU;IACxF,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,MAAM,IAAI,EAAE;QAAE,IAAI,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IAC1F,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,GAAG,IAAI,EAAE;QAAE,IAAI,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAChG,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,C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CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACzL,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAAE,IAAI,CAAC,OAAO,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;SAChI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACjF,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAClD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { clone, create } from \"@bufbuild/protobuf\";\nimport { SemanticDatasetSchema, SemanticJoinSchema, type SemanticModel, SemanticModelSchema } from \"@surfaces-ui/proto\";\nimport type { Pill } from \"./model.js\";\nimport { modelChanges, pillsFromModel, setModelField } from \"./semantic.js\";\nimport type { JoinKind } from \"../model/ModelDiagram.js\";\nimport { joinKindOf, joinTypeOf, semanticSql } from \"./SemanticRows.js\";\nimport { datasetSql } from \"@surfaces-ui/data\";\n\n/** A join as an agent writes it: two tables and the columns that match. */\nexport interface ProposedJoin {\n left: string;\n right: string;\n keys: { leftColumn: string; rightColumn: string }[];\n /** Which rows it keeps, read from left to right. Left out, \"left\": every row of the left table, the one nearer the first, so adding detail never drops a row. */\n type?: JoinKind;\n}\n\n/** What one row is and where the rows come from, as proposed. Any part left out stays as it is. */\nexport interface ProposedRows {\n grain?: string;\n primaryKey?: string[];\n /** The tables, the first being the one whose rows the model's rows are. With them the query is generated, unless `sql` is given too. */\n tables?: string[];\n joins?: ProposedJoin[];\n /** A query written out, in place of tables and joins. */\n sql?: string;\n /** A dataset a pipeline builds, in place of tables, joins and a query: the model reads its table, and its grain and key should be the dataset's, which the pipeline checks. */\n dataset?: { pipeline: string; dataset: string };\n}\n\n/**\n * A change to a semantic model in the plain form an agent writes and a\n * person's edits come back in: fields to add or put in place (as pills),\n * names to take out, and the rows. The same shape proposes a new model,\n * starting from an empty one.\n */\nexport interface SemanticProposal {\n add?: Pill[];\n remove?: string[];\n rows?: ProposedRows;\n}\n\n/** The model with a proposal applied, every field and join it adds marked as `by`'s. Nothing is saved. */\nexport function applyProposal(model: SemanticModel, proposal: SemanticProposal, by: string): SemanticModel {\n let next = model;\n for (const name of proposal.remove ?? []) next = setModelField(next, name, undefined, by);\n for (const pill of proposal.add ?? []) next = setModelField(next, pill.id, pill, pill.by || by);\n const rows = proposal.rows;\n if (!rows) return next;\n next = clone(SemanticModelSchema, next);\n if (rows.grain !== undefined) next.grain = rows.grain;\n if (rows.primaryKey !== undefined) next.primaryKey = [...rows.primaryKey];\n if (rows.tables !== undefined || rows.joins !== undefined) {\n next.tables = [...(rows.tables ?? next.tables)];\n next.joins = (rows.joins ?? []).map((j) => create(SemanticJoinSchema, { left: j.left, right: j.right, keys: j.keys, type: joinTypeOf(j.type ?? \"left\"), definedBy: by }));\n // Until the editor has read the columns and can name each one, the query is the plain form.\n next.sql = semanticSql({ tables: next.tables, joins: next.joins.map((j) => ({ left: j.left, right: j.right, keys: j.keys, type: joinKindOf(j.type) })) }).sql;\n }\n if (rows.sql !== undefined) {\n next.sql = rows.sql;\n if (rows.tables === undefined) (next.tables = []), (next.joins = []);\n }\n if (rows.dataset) {\n next.dataset = create(SemanticDatasetSchema, { pipelineId: rows.dataset.pipeline, dataset: rows.dataset.dataset });\n next.sql = datasetSql(rows.dataset.dataset);\n next.tables = [];\n next.joins = [];\n } else if (rows.sql !== undefined || rows.tables !== undefined) next.dataset = undefined;\n return next;\n}\n\n/** A draft as the proposal that would make it from `model`: what a person left in or changed, in the form the agent wrote. */\nexport function proposalFrom(model: SemanticModel, draft: SemanticModel): SemanticProposal {\n const changes = modelChanges(model, draft);\n const after = new Map(pillsFromModel(draft).map((p) => [p.id, p]));\n const out: SemanticProposal = {\n add: [...changes].filter(([name, kind]) => kind !== \"removed\" && after.has(name)).map(([name]) => after.get(name)!),\n remove: [...changes].filter(([, kind]) => kind === \"removed\").map(([name]) => name),\n };\n const rows: ProposedRows = {};\n if (changes.has(\"(grain)\")) rows.grain = draft.grain;\n if (changes.has(\"(primaryKey)\")) rows.primaryKey = draft.primaryKey;\n if (changes.has(\"(joins)\")) {\n rows.tables = draft.tables;\n rows.joins = draft.joins.map((j) => ({ left: j.left, right: j.right, keys: j.keys.map((k) => ({ leftColumn: k.leftColumn, rightColumn: k.rightColumn })), type: joinKindOf(j.type) }));\n }\n if (draft.dataset && changes.has(\"(dataset)\")) rows.dataset = { pipeline: draft.dataset.pipelineId, dataset: draft.dataset.dataset };\n else if (changes.has(\"(sql)\") && draft.tables.length === 0) rows.sql = draft.sql;\n if (Object.keys(rows).length > 0) out.rows = rows;\n return out;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type MessageInitShape } from "@bufbuild/protobuf";
|
|
2
|
+
import { type Dimension, type Measure, type Metric, type SemanticModel, SemanticModelSchema } from "@surfaces-ui/proto";
|
|
3
|
+
import type { Field } from "apache-arrow";
|
|
4
|
+
import { type Pill } from "./model.js";
|
|
5
|
+
/** What a model calls itself on a pill: "the Sales lines model". */
|
|
6
|
+
export declare const modelByline: (model: Pick<SemanticModel, "name" | "label">) => string;
|
|
7
|
+
/**
|
|
8
|
+
* A semantic model's fields as pills: dimensions are attributes, measures
|
|
9
|
+
* are metrics, metrics are calculations. Each says it comes from the model
|
|
10
|
+
* (`model`) and who defined it (`by`).
|
|
11
|
+
*/
|
|
12
|
+
export declare function pillsFromModel(model: SemanticModel): Pill[];
|
|
13
|
+
/** The model's pills first, then pills generated for the columns the model leaves out. */
|
|
14
|
+
export declare function pillsWithModel(model: SemanticModel, columns: Pick<Field, "name" | "type">[]): Pill[];
|
|
15
|
+
/** Whether two pills define the same thing, whatever they are called and whoever made them. */
|
|
16
|
+
export declare function sameDefinition(a: Pill, b: Pill): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The fields after the model changed: a pill the model now defines the same
|
|
19
|
+
* way becomes the model's, a pill that came from the model follows it, and
|
|
20
|
+
* a model field not shown yet is added. A pill a person or an agent changed
|
|
21
|
+
* since it came from the model is kept as they left it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mergeModelPills(fields: Pill[], model: SemanticModel): Pill[];
|
|
24
|
+
/** Whether a pill is worth offering to the model: it is not the model's own, or it was changed since. */
|
|
25
|
+
export declare const canPromote: (pill: Pill, model: SemanticModel | undefined) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The model with a pill added to it, or put in place of the field of the
|
|
28
|
+
* same name. A calculation brings the metrics it uses that the model does
|
|
29
|
+
* not have yet. `by` is recorded as who defined what is added.
|
|
30
|
+
*/
|
|
31
|
+
export declare function promotePill(model: SemanticModel, pill: Pill, all: Pill[], by: string): SemanticModel;
|
|
32
|
+
/** The model's field of that name, whichever kind it is. */
|
|
33
|
+
export declare function fieldNamed(model: SemanticModel, name: string): Dimension | Measure | Metric | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The model with the field called `name` changed to `pill`, in the same
|
|
36
|
+
* place, or removed when `pill` is undefined, or added at the end of its
|
|
37
|
+
* kind when there is none. A rename follows into the metrics that use it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function setModelField(model: SemanticModel, name: string, pill: Pill | undefined, definedBy: string): SemanticModel;
|
|
40
|
+
export type FieldChange = "added" | "changed" | "removed";
|
|
41
|
+
/** What a draft changes against the saved model, by field name. Who defined a field does not count as a change. */
|
|
42
|
+
export declare function modelChanges(saved: SemanticModel, draft: SemanticModel): Map<string, FieldChange>;
|
|
43
|
+
/** A model to start from for a query, with nothing defined yet: a person or an agent adds the fields. */
|
|
44
|
+
export declare function emptyModel(init: MessageInitShape<typeof SemanticModelSchema>): SemanticModel;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { clone, create } from "@bufbuild/protobuf";
|
|
2
|
+
import { aggregateFunctionOf, aggregateWord, measureNames, parseMeasureExpression } from "@surfaces-ui/data";
|
|
3
|
+
import { DimensionKind, SemanticModelSchema } from "@surfaces-ui/proto";
|
|
4
|
+
import { pillsFromFields } from "./model.js";
|
|
5
|
+
const FORMATS = ["number", "compact", "currency", "percent"];
|
|
6
|
+
const format = (value) => (FORMATS.includes(value) ? value : undefined);
|
|
7
|
+
/** What a model calls itself on a pill: "the Sales lines model". */
|
|
8
|
+
export const modelByline = (model) => `the ${model.label || model.name} model`;
|
|
9
|
+
/**
|
|
10
|
+
* A semantic model's fields as pills: dimensions are attributes, measures
|
|
11
|
+
* are metrics, metrics are calculations. Each says it comes from the model
|
|
12
|
+
* (`model`) and who defined it (`by`).
|
|
13
|
+
*/
|
|
14
|
+
export function pillsFromModel(model) {
|
|
15
|
+
const by = (definedBy) => definedBy || modelByline(model);
|
|
16
|
+
const pills = [];
|
|
17
|
+
for (const d of model.dimensions) {
|
|
18
|
+
const time = d.kind === DimensionKind.TIME;
|
|
19
|
+
pills.push({ id: d.name, kind: "attribute", label: d.label || d.name, column: d.column, ...(time ? { grain: (d.grain || "month") } : {}), ...(d.description ? { description: d.description } : {}), by: by(d.definedBy), model: model.name });
|
|
20
|
+
}
|
|
21
|
+
for (const m of model.measures) {
|
|
22
|
+
const aggregate = aggregateWord(m.aggregate);
|
|
23
|
+
if (!aggregate)
|
|
24
|
+
continue;
|
|
25
|
+
pills.push({ id: m.name, kind: "metric", label: m.label || m.name, ...(m.column ? { column: m.column } : {}), aggregate, ...(format(m.format) ? { format: format(m.format) } : {}), ...(m.description ? { description: m.description } : {}), by: by(m.definedBy), model: model.name });
|
|
26
|
+
}
|
|
27
|
+
for (const m of model.metrics) {
|
|
28
|
+
pills.push({ id: m.name, kind: "derived", label: m.label || m.name, expression: m.expression, ...(format(m.format) ? { format: format(m.format) } : {}), ...(m.description ? { description: m.description } : {}), by: by(m.definedBy), model: model.name });
|
|
29
|
+
}
|
|
30
|
+
return pills;
|
|
31
|
+
}
|
|
32
|
+
/** The model's pills first, then pills generated for the columns the model leaves out. */
|
|
33
|
+
export function pillsWithModel(model, columns) {
|
|
34
|
+
const fromModel = pillsFromModel(model);
|
|
35
|
+
const used = new Set(fromModel.flatMap((p) => (p.column ? [p.column] : [])));
|
|
36
|
+
const ids = new Set(fromModel.map((p) => p.id));
|
|
37
|
+
const counts = fromModel.some((p) => p.kind === "metric" && p.aggregate === "count" && !p.column);
|
|
38
|
+
const generated = pillsFromFields(columns.filter((c) => !used.has(c.name))).filter((p) => !ids.has(p.id) && !(counts && p.aggregate === "count" && !p.column));
|
|
39
|
+
return [...fromModel, ...generated];
|
|
40
|
+
}
|
|
41
|
+
/** Whether two pills define the same thing, whatever they are called and whoever made them. */
|
|
42
|
+
export function sameDefinition(a, b) {
|
|
43
|
+
return a.id === b.id && a.kind === b.kind && (a.column ?? "") === (b.column ?? "") && (a.aggregate ?? "") === (b.aggregate ?? "") && (a.grain ?? "") === (b.grain ?? "") && (a.expression ?? "").replace(/\s+/g, "") === (b.expression ?? "").replace(/\s+/g, "") && (a.format ?? "") === (b.format ?? "") && a.label === b.label && (a.description ?? "") === (b.description ?? "");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The fields after the model changed: a pill the model now defines the same
|
|
47
|
+
* way becomes the model's, a pill that came from the model follows it, and
|
|
48
|
+
* a model field not shown yet is added. A pill a person or an agent changed
|
|
49
|
+
* since it came from the model is kept as they left it.
|
|
50
|
+
*/
|
|
51
|
+
export function mergeModelPills(fields, model) {
|
|
52
|
+
const fromModel = pillsFromModel(model);
|
|
53
|
+
const byId = new Map(fromModel.map((p) => [p.id, p]));
|
|
54
|
+
const out = fields.flatMap((p) => {
|
|
55
|
+
const defined = byId.get(p.id);
|
|
56
|
+
if (!defined)
|
|
57
|
+
return p.model === model.name ? [] : [p];
|
|
58
|
+
return p.model === model.name || sameDefinition(p, defined) ? [defined] : [p];
|
|
59
|
+
});
|
|
60
|
+
const have = new Set(out.map((p) => p.id));
|
|
61
|
+
return [...fromModel.filter((p) => !have.has(p.id)), ...out];
|
|
62
|
+
}
|
|
63
|
+
/** Whether a pill is worth offering to the model: it is not the model's own, or it was changed since. */
|
|
64
|
+
export const canPromote = (pill, model) => !!model && pill.model !== model.name;
|
|
65
|
+
/**
|
|
66
|
+
* The model with a pill added to it, or put in place of the field of the
|
|
67
|
+
* same name. A calculation brings the metrics it uses that the model does
|
|
68
|
+
* not have yet. `by` is recorded as who defined what is added.
|
|
69
|
+
*/
|
|
70
|
+
export function promotePill(model, pill, all, by) {
|
|
71
|
+
const next = create(SemanticModelSchema, model);
|
|
72
|
+
const bring = [pill];
|
|
73
|
+
if (pill.kind === "derived") {
|
|
74
|
+
let names = [];
|
|
75
|
+
try {
|
|
76
|
+
names = measureNames(parseMeasureExpression(pill.expression ?? ""));
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
names = [];
|
|
80
|
+
}
|
|
81
|
+
for (const name of names) {
|
|
82
|
+
const used = all.find((p) => p.id === name && p.kind === "metric");
|
|
83
|
+
if (used && !next.measures.some((m) => m.name === name))
|
|
84
|
+
bring.unshift(used);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
let out = next;
|
|
88
|
+
for (const p of bring)
|
|
89
|
+
out = setModelField(out, p.id, p, p === pill || p.model !== model.name ? by : (fieldNamed(model, p.id)?.definedBy ?? ""));
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
/** The model's field of that name, whichever kind it is. */
|
|
93
|
+
export function fieldNamed(model, name) {
|
|
94
|
+
return model.dimensions.find((d) => d.name === name) ?? model.measures.find((m) => m.name === name) ?? model.metrics.find((m) => m.name === name);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The model with the field called `name` changed to `pill`, in the same
|
|
98
|
+
* place, or removed when `pill` is undefined, or added at the end of its
|
|
99
|
+
* kind when there is none. A rename follows into the metrics that use it.
|
|
100
|
+
*/
|
|
101
|
+
export function setModelField(model, name, pill, definedBy) {
|
|
102
|
+
const next = clone(SemanticModelSchema, model);
|
|
103
|
+
const common = pill && { name: pill.id, label: pill.label, description: pill.description ?? "", definedBy };
|
|
104
|
+
const dimension = pill?.kind === "attribute" ? { $typeName: "surfaces.v1.Dimension", ...common, column: pill.column ?? "", kind: pill.grain ? DimensionKind.TIME : DimensionKind.CATEGORY, grain: pill.grain ?? "" } : undefined;
|
|
105
|
+
const measure = pill?.kind === "metric" ? { $typeName: "surfaces.v1.Measure", ...common, column: pill.column ?? "", aggregate: aggregateFunctionOf(pill.aggregate ?? ""), format: pill.format ?? "" } : undefined;
|
|
106
|
+
const metric = pill?.kind === "derived" ? { $typeName: "surfaces.v1.Metric", ...common, expression: pill.expression ?? "", format: pill.format ?? "" } : undefined;
|
|
107
|
+
const place = (list, field) => {
|
|
108
|
+
const at = list.findIndex((f) => f.name === name);
|
|
109
|
+
if (at < 0)
|
|
110
|
+
return field ? [...list, field] : list;
|
|
111
|
+
return field ? list.map((f, i) => (i === at ? field : f)) : list.filter((_, i) => i !== at);
|
|
112
|
+
};
|
|
113
|
+
next.dimensions = place(next.dimensions, dimension);
|
|
114
|
+
next.measures = place(next.measures, measure);
|
|
115
|
+
next.metrics = place(next.metrics, metric);
|
|
116
|
+
if (pill && pill.id !== name) {
|
|
117
|
+
const word = new RegExp(`\\b${name}\\b`, "g");
|
|
118
|
+
next.metrics = next.metrics.map((m) => ({ ...m, expression: m.expression.replace(word, pill.id) }));
|
|
119
|
+
}
|
|
120
|
+
return next;
|
|
121
|
+
}
|
|
122
|
+
/** What a draft changes against the saved model, by field name. Who defined a field does not count as a change. */
|
|
123
|
+
export function modelChanges(saved, draft) {
|
|
124
|
+
const before = new Map(pillsFromModel(saved).map((p) => [p.id, p]));
|
|
125
|
+
const after = new Map(pillsFromModel(draft).map((p) => [p.id, p]));
|
|
126
|
+
const out = new Map();
|
|
127
|
+
for (const [name, pill] of after) {
|
|
128
|
+
const was = before.get(name);
|
|
129
|
+
if (!was)
|
|
130
|
+
out.set(name, "added");
|
|
131
|
+
else if (!sameDefinition(was, pill))
|
|
132
|
+
out.set(name, "changed");
|
|
133
|
+
}
|
|
134
|
+
for (const name of before.keys())
|
|
135
|
+
if (!after.has(name))
|
|
136
|
+
out.set(name, "removed");
|
|
137
|
+
for (const key of ["name", "label", "description", "sql", "grain"])
|
|
138
|
+
if (saved[key] !== draft[key])
|
|
139
|
+
out.set(`(${key})`, "changed");
|
|
140
|
+
if (saved.primaryKey.join("|") !== draft.primaryKey.join("|"))
|
|
141
|
+
out.set("(primaryKey)", "changed");
|
|
142
|
+
const rows = (m) => JSON.stringify([m.tables, m.joins.map((j) => [j.left, j.right, j.keys.map((k) => [k.leftColumn, k.rightColumn]), j.definedBy, j.type || 1])]);
|
|
143
|
+
if (rows(saved) !== rows(draft))
|
|
144
|
+
out.set("(joins)", "changed");
|
|
145
|
+
const from = (m) => (m.dataset ? `${m.dataset.pipelineId}/${m.dataset.dataset}` : "");
|
|
146
|
+
if (from(saved) !== from(draft))
|
|
147
|
+
out.set("(dataset)", "changed");
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/** A model to start from for a query, with nothing defined yet: a person or an agent adds the fields. */
|
|
151
|
+
export function emptyModel(init) {
|
|
152
|
+
return create(SemanticModelSchema, init);
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=semantic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../src/explore/semantic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,OAAO,EAAkB,aAAa,E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CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC/D,MAAM,IAAI,GAAG,CAAC,CAAgB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrG,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACjE,OAAO,GAAG,CAAC;AACb,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,UAAU,CAAC,IAAkD;IAC3E,OAAO,MAAM,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { type MessageInitShape, clone, create } from \"@bufbuild/protobuf\";\nimport { aggregateFunctionOf, aggregateWord, measureNames, parseMeasureExpression } from \"@surfaces-ui/data\";\nimport { type Dimension, DimensionKind, type Measure, type Metric, type SemanticModel, SemanticModelSchema } from \"@surfaces-ui/proto\";\nimport type { Field } from \"apache-arrow\";\nimport type { ChartGrain } from \"../chart/Chart.js\";\nimport { type Pill, type PillFormat, pillsFromFields } from \"./model.js\";\n\nconst FORMATS: PillFormat[] = [\"number\", \"compact\", \"currency\", \"percent\"];\nconst format = (value: string): PillFormat | undefined => (FORMATS.includes(value as PillFormat) ? (value as PillFormat) : undefined);\n\n/** What a model calls itself on a pill: \"the Sales lines model\". */\nexport const modelByline = (model: Pick<SemanticModel, \"name\" | \"label\">) => `the ${model.label || model.name} model`;\n\n/**\n * A semantic model's fields as pills: dimensions are attributes, measures\n * are metrics, metrics are calculations. Each says it comes from the model\n * (`model`) and who defined it (`by`).\n */\nexport function pillsFromModel(model: SemanticModel): Pill[] {\n const by = (definedBy: string) => definedBy || modelByline(model);\n const pills: Pill[] = [];\n for (const d of model.dimensions) {\n const time = d.kind === DimensionKind.TIME;\n pills.push({ id: d.name, kind: \"attribute\", label: d.label || d.name, column: d.column, ...(time ? { grain: (d.grain || \"month\") as ChartGrain } : {}), ...(d.description ? { description: d.description } : {}), by: by(d.definedBy), model: model.name });\n }\n for (const m of model.measures) {\n const aggregate = aggregateWord(m.aggregate);\n if (!aggregate) continue;\n pills.push({ id: m.name, kind: \"metric\", label: m.label || m.name, ...(m.column ? { column: m.column } : {}), aggregate, ...(format(m.format) ? { format: format(m.format) } : {}), ...(m.description ? { description: m.description } : {}), by: by(m.definedBy), model: model.name });\n }\n for (const m of model.metrics) {\n pills.push({ id: m.name, kind: \"derived\", label: m.label || m.name, expression: m.expression, ...(format(m.format) ? { format: format(m.format) } : {}), ...(m.description ? { description: m.description } : {}), by: by(m.definedBy), model: model.name });\n }\n return pills;\n}\n\n/** The model's pills first, then pills generated for the columns the model leaves out. */\nexport function pillsWithModel(model: SemanticModel, columns: Pick<Field, \"name\" | \"type\">[]): Pill[] {\n const fromModel = pillsFromModel(model);\n const used = new Set(fromModel.flatMap((p) => (p.column ? [p.column] : [])));\n const ids = new Set(fromModel.map((p) => p.id));\n const counts = fromModel.some((p) => p.kind === \"metric\" && p.aggregate === \"count\" && !p.column);\n const generated = pillsFromFields(columns.filter((c) => !used.has(c.name))).filter((p) => !ids.has(p.id) && !(counts && p.aggregate === \"count\" && !p.column));\n return [...fromModel, ...generated];\n}\n\n/** Whether two pills define the same thing, whatever they are called and whoever made them. */\nexport function sameDefinition(a: Pill, b: Pill): boolean {\n return a.id === b.id && a.kind === b.kind && (a.column ?? \"\") === (b.column ?? \"\") && (a.aggregate ?? \"\") === (b.aggregate ?? \"\") && (a.grain ?? \"\") === (b.grain ?? \"\") && (a.expression ?? \"\").replace(/\\s+/g, \"\") === (b.expression ?? \"\").replace(/\\s+/g, \"\") && (a.format ?? \"\") === (b.format ?? \"\") && a.label === b.label && (a.description ?? \"\") === (b.description ?? \"\");\n}\n\n/**\n * The fields after the model changed: a pill the model now defines the same\n * way becomes the model's, a pill that came from the model follows it, and\n * a model field not shown yet is added. A pill a person or an agent changed\n * since it came from the model is kept as they left it.\n */\nexport function mergeModelPills(fields: Pill[], model: SemanticModel): Pill[] {\n const fromModel = pillsFromModel(model);\n const byId = new Map(fromModel.map((p) => [p.id, p]));\n const out = fields.flatMap((p) => {\n const defined = byId.get(p.id);\n if (!defined) return p.model === model.name ? [] : [p];\n return p.model === model.name || sameDefinition(p, defined) ? [defined] : [p];\n });\n const have = new Set(out.map((p) => p.id));\n return [...fromModel.filter((p) => !have.has(p.id)), ...out];\n}\n\n/** Whether a pill is worth offering to the model: it is not the model's own, or it was changed since. */\nexport const canPromote = (pill: Pill, model: SemanticModel | undefined) => !!model && pill.model !== model.name;\n\n/**\n * The model with a pill added to it, or put in place of the field of the\n * same name. A calculation brings the metrics it uses that the model does\n * not have yet. `by` is recorded as who defined what is added.\n */\nexport function promotePill(model: SemanticModel, pill: Pill, all: Pill[], by: string): SemanticModel {\n const next = create(SemanticModelSchema, model);\n const bring = [pill];\n if (pill.kind === \"derived\") {\n let names: string[] = [];\n try {\n names = measureNames(parseMeasureExpression(pill.expression ?? \"\"));\n } catch {\n names = [];\n }\n for (const name of names) {\n const used = all.find((p) => p.id === name && p.kind === \"metric\");\n if (used && !next.measures.some((m) => m.name === name)) bring.unshift(used);\n }\n }\n let out = next;\n for (const p of bring) out = setModelField(out, p.id, p, p === pill || p.model !== model.name ? by : (fieldNamed(model, p.id)?.definedBy ?? \"\"));\n return out;\n}\n\n/** The model's field of that name, whichever kind it is. */\nexport function fieldNamed(model: SemanticModel, name: string): Dimension | Measure | Metric | undefined {\n return model.dimensions.find((d) => d.name === name) ?? model.measures.find((m) => m.name === name) ?? model.metrics.find((m) => m.name === name);\n}\n\n/**\n * The model with the field called `name` changed to `pill`, in the same\n * place, or removed when `pill` is undefined, or added at the end of its\n * kind when there is none. A rename follows into the metrics that use it.\n */\nexport function setModelField(model: SemanticModel, name: string, pill: Pill | undefined, definedBy: string): SemanticModel {\n const next = clone(SemanticModelSchema, model);\n const common = pill && { name: pill.id, label: pill.label, description: pill.description ?? \"\", definedBy };\n const dimension: Dimension | undefined = pill?.kind === \"attribute\" ? { $typeName: \"surfaces.v1.Dimension\", ...common!, column: pill.column ?? \"\", kind: pill.grain ? DimensionKind.TIME : DimensionKind.CATEGORY, grain: pill.grain ?? \"\" } : undefined;\n const measure: Measure | undefined = pill?.kind === \"metric\" ? { $typeName: \"surfaces.v1.Measure\", ...common!, column: pill.column ?? \"\", aggregate: aggregateFunctionOf(pill.aggregate ?? \"\"), format: pill.format ?? \"\" } : undefined;\n const metric: Metric | undefined = pill?.kind === \"derived\" ? { $typeName: \"surfaces.v1.Metric\", ...common!, expression: pill.expression ?? \"\", format: pill.format ?? \"\" } : undefined;\n const place = <T extends { name: string }>(list: T[], field: T | undefined): T[] => {\n const at = list.findIndex((f) => f.name === name);\n if (at < 0) return field ? [...list, field] : list;\n return field ? list.map((f, i) => (i === at ? field : f)) : list.filter((_, i) => i !== at);\n };\n next.dimensions = place(next.dimensions, dimension);\n next.measures = place(next.measures, measure);\n next.metrics = place(next.metrics, metric);\n if (pill && pill.id !== name) {\n const word = new RegExp(`\\\\b${name}\\\\b`, \"g\");\n next.metrics = next.metrics.map((m) => ({ ...m, expression: m.expression.replace(word, pill.id) }));\n }\n return next;\n}\n\nexport type FieldChange = \"added\" | \"changed\" | \"removed\";\n\n/** What a draft changes against the saved model, by field name. Who defined a field does not count as a change. */\nexport function modelChanges(saved: SemanticModel, draft: SemanticModel): Map<string, FieldChange> {\n const before = new Map(pillsFromModel(saved).map((p) => [p.id, p]));\n const after = new Map(pillsFromModel(draft).map((p) => [p.id, p]));\n const out = new Map<string, FieldChange>();\n for (const [name, pill] of after) {\n const was = before.get(name);\n if (!was) out.set(name, \"added\");\n else if (!sameDefinition(was, pill)) out.set(name, \"changed\");\n }\n for (const name of before.keys()) if (!after.has(name)) out.set(name, \"removed\");\n for (const key of [\"name\", \"label\", \"description\", \"sql\", \"grain\"] as const) if (saved[key] !== draft[key]) out.set(`(${key})`, \"changed\");\n if (saved.primaryKey.join(\"|\") !== draft.primaryKey.join(\"|\")) out.set(\"(primaryKey)\", \"changed\");\n const rows = (m: SemanticModel) => JSON.stringify([m.tables, m.joins.map((j) => [j.left, j.right, j.keys.map((k) => [k.leftColumn, k.rightColumn]), j.definedBy, j.type || 1])]);\n if (rows(saved) !== rows(draft)) out.set(\"(joins)\", \"changed\");\n const from = (m: SemanticModel) => (m.dataset ? `${m.dataset.pipelineId}/${m.dataset.dataset}` : \"\");\n if (from(saved) !== from(draft)) out.set(\"(dataset)\", \"changed\");\n return out;\n}\n\n/** A model to start from for a query, with nothing defined yet: a person or an agent adds the fields. */\nexport function emptyModel(init: MessageInitShape<typeof SemanticModelSchema>): SemanticModel {\n return create(SemanticModelSchema, init);\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DataSource } from "@surfaces-ui/data";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { OnContext } from "../controls/context.js";
|
|
4
|
+
import { type DataRef } from "../schema/refs.js";
|
|
5
|
+
import { type FileItem, type FilePlace } from "./files.js";
|
|
6
|
+
export interface FileBrowserProps {
|
|
7
|
+
/** List this source's storage, through the backend (`DataSource.listFiles`). */
|
|
8
|
+
sourceId?: string;
|
|
9
|
+
/** Name shown for the source's storage. Defaults to the source id. */
|
|
10
|
+
sourceLabel?: string;
|
|
11
|
+
dataSource?: DataSource;
|
|
12
|
+
/** Other places to list: a consumer's own store, or folders opened elsewhere. */
|
|
13
|
+
places?: FilePlace[];
|
|
14
|
+
/** Offer "Open a folder on this computer". The folder is read by the browser and nothing is uploaded. */
|
|
15
|
+
local?: boolean;
|
|
16
|
+
/** Told when a person opens a local folder, so a host can keep it. */
|
|
17
|
+
onPlaceAdded?(place: FilePlace): void;
|
|
18
|
+
onSelect?(item: FileItem, place: FilePlace): void;
|
|
19
|
+
/** Enter or a double click on a file: open it, load it, preview it. The host decides. */
|
|
20
|
+
onOpen?(item: FileItem, place: FilePlace): void;
|
|
21
|
+
/** Hand files and folders to something else (a chat): the selection, or the one row. Names only. */
|
|
22
|
+
onAttach?(refs: DataRef[], items: FileItem[]): void;
|
|
23
|
+
/** What `onAttach` is called in the menu. Defaults to "Add to chat". */
|
|
24
|
+
attachLabel?: string;
|
|
25
|
+
/** Told what a person does here (a folder opened from their computer, a file opened, files handed on), by name only, for an agent's context. */
|
|
26
|
+
onContext?: OnContext;
|
|
27
|
+
/** Buttons at the end of a file's row. */
|
|
28
|
+
renderActions?(item: FileItem, place: FilePlace): ReactNode;
|
|
29
|
+
/** Height of the whole browser in px. Defaults to 420. */
|
|
30
|
+
height?: number;
|
|
31
|
+
/** Accessible name of the tree. */
|
|
32
|
+
label?: string;
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A tree of folders and files: a source's storage (the places it is allowed
|
|
37
|
+
* to read), folders a person opens from their own computer, or both. Files
|
|
38
|
+
* show their size, date and what they can be read as, and which configured
|
|
39
|
+
* table reads them. Several can be selected and handed to a chat or dragged
|
|
40
|
+
* onto one, as names: the browser never reads what a file holds.
|
|
41
|
+
*/
|
|
42
|
+
export declare function FileBrowser(props: FileBrowserProps): import("react").JSX.Element;
|