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
package/dist/recharts/series.mjs
CHANGED
|
@@ -1,64 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { isMark } from "derive-dashboards/core";
|
|
3
|
-
// src/series.ts
|
|
4
|
-
const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
|
|
5
|
-
/** The series key a dimension's Other draws as. */
|
|
6
|
-
const OTHER_KEY = "other";
|
|
7
|
-
const isAll = (cell) => isMark(cell) && cell.mark === "all";
|
|
8
|
-
/**
|
|
9
|
-
* Chart data from an answer. The first non-value column is the x axis (the time bucket when
|
|
10
|
-
* there is one). With a second key column, the first value is split into one series per
|
|
11
|
-
* value of it, and Other in that column is one more series; otherwise every value column is
|
|
12
|
-
* its own series. Other on the x axis is one more point; totals are not drawn.
|
|
13
|
-
*/
|
|
14
|
-
function toSeries(answer, format = {}) {
|
|
15
|
-
const keyCount = answer.columns.filter((c) => !isValue(c)).length;
|
|
16
|
-
const all = answer.columns.slice(keyCount);
|
|
17
|
-
const calcs = all.filter((c) => c.id.startsWith("c"));
|
|
18
|
-
const values = calcs.length > 0 ? calcs : all;
|
|
19
|
-
const rows = answer.rows.filter((row) => !row.some((cell) => isAll(cell)));
|
|
20
|
-
const keyText = (cell, column) => cell === null || cell === "" ? (format.messages ?? ENGLISH).empty : formatCell(cell, column, format);
|
|
21
|
-
const xOf = (row) => keyText(row[0] ?? null, answer.columns[0]);
|
|
22
|
-
if (keyCount < 2) {
|
|
23
|
-
const series = values.map((column) => ({
|
|
24
|
-
key: column.id,
|
|
25
|
-
label: column.label,
|
|
26
|
-
column
|
|
27
|
-
}));
|
|
28
|
-
return {
|
|
29
|
-
points: rows.map((row) => ({
|
|
30
|
-
x: keyCount === 0 ? "" : xOf(row),
|
|
31
|
-
...Object.fromEntries(values.map((c) => [c.id, plotValue(row[answer.columns.indexOf(c)] ?? null)]))
|
|
32
|
-
})),
|
|
33
|
-
series,
|
|
34
|
-
split: false
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const first = values[0];
|
|
38
|
-
if (first === void 0) return {
|
|
39
|
-
points: [],
|
|
40
|
-
series: [],
|
|
41
|
-
split: true
|
|
42
|
-
};
|
|
43
|
-
const byX = /* @__PURE__ */ new Map();
|
|
44
|
-
const names = /* @__PURE__ */ new Map();
|
|
45
|
-
for (const row of rows) {
|
|
46
|
-
const split = row[1] ?? null;
|
|
47
|
-
const key = isMark(split) ? split.mark : `s${JSON.stringify(split)}`;
|
|
48
|
-
names.set(key, keyText(split, answer.columns[1]));
|
|
49
|
-
const point = byX.get(xOf(row)) ?? { x: xOf(row) };
|
|
50
|
-
point[key] = plotValue(row[keyCount] ?? null);
|
|
51
|
-
byX.set(xOf(row), point);
|
|
52
|
-
}
|
|
53
|
-
const series = [...names].map(([key, label]) => ({
|
|
54
|
-
key,
|
|
55
|
-
label,
|
|
56
|
-
column: first
|
|
57
|
-
})).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
|
|
58
|
-
return {
|
|
59
|
-
points: [...byX.values()],
|
|
60
|
-
series,
|
|
61
|
-
split: true
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export { OTHER_KEY, toSeries };
|
|
1
|
+
export { OTHER_KEY, rowAt, toSeries } from "derive-dashboards/react";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { openCursor, sealCursor } from "./cursor-seal.mjs";
|
|
2
|
+
import { bind, reading } from "./execute.mjs";
|
|
3
|
+
import { recordColumns } from "derive-dashboards/core";
|
|
4
|
+
import { readRecords } from "derive-dashboards/core/engine";
|
|
5
|
+
// src/records-read.ts
|
|
6
|
+
/**
|
|
7
|
+
* A page of rows, its cursor sealed to the viewer's tenant and to everything that decides which
|
|
8
|
+
* rows come next: the query (a drill's filters in it), the columns and order read, the lock and
|
|
9
|
+
* required filters, and who asks (`by`), so a cursor never continues another population.
|
|
10
|
+
*/
|
|
11
|
+
async function readPage(x, page) {
|
|
12
|
+
const bound = bind(x);
|
|
13
|
+
const key = await x.rt.cursorKey;
|
|
14
|
+
const on = {
|
|
15
|
+
query: x.query,
|
|
16
|
+
shape: page.shape ?? null,
|
|
17
|
+
lock: bound.lock,
|
|
18
|
+
required: bound.required,
|
|
19
|
+
by: page.by ?? null
|
|
20
|
+
};
|
|
21
|
+
const at = {
|
|
22
|
+
principal: x.principal,
|
|
23
|
+
on
|
|
24
|
+
};
|
|
25
|
+
const after = page.after === void 0 ? {} : { after: await openCursor(key, page.after, at) };
|
|
26
|
+
const shape = page.shape === void 0 ? {} : { shape: page.shape };
|
|
27
|
+
const { value } = await reading(x, page.limit, (reader) => readRecords(bound.input, {
|
|
28
|
+
limit: page.limit,
|
|
29
|
+
...after,
|
|
30
|
+
...shape
|
|
31
|
+
}, reader));
|
|
32
|
+
const next = value.next === void 0 ? {} : { next: await sealCursor(key, value.next, at) };
|
|
33
|
+
return {
|
|
34
|
+
...value,
|
|
35
|
+
...next,
|
|
36
|
+
columns: recordColumns(x.rt.options.model, x.query.source, value.columns)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** A page of the rows behind a query, under the same access, filters and range as its answer. */
|
|
40
|
+
async function executeRecords(x, page) {
|
|
41
|
+
const { keys: _keys, ...records } = await readPage(x, page);
|
|
42
|
+
return records;
|
|
43
|
+
}
|
|
44
|
+
export { executeRecords, readPage };
|
package/dist/store/apply.mjs
CHANGED
|
@@ -23,7 +23,7 @@ async function newCommands(tx, draftId, commands) {
|
|
|
23
23
|
value: commands.map((c) => c.commandId)
|
|
24
24
|
}]
|
|
25
25
|
});
|
|
26
|
-
const digests = new Map(seen.map((r) => [String(r
|
|
26
|
+
const digests = new Map(seen.map((r) => [String(r.command_id), String(r.digest)]));
|
|
27
27
|
const fresh = [];
|
|
28
28
|
const acknowledged = [];
|
|
29
29
|
for (const command of commands) {
|
|
@@ -48,7 +48,7 @@ function summed(row, current, fresh) {
|
|
|
48
48
|
return {
|
|
49
49
|
steps: current.steps + 1,
|
|
50
50
|
named: [...named].toSorted(),
|
|
51
|
-
next_seq: Number(row
|
|
51
|
+
next_seq: Number(row.next_seq) + fresh.length
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -59,7 +59,7 @@ function summed(row, current, fresh) {
|
|
|
59
59
|
function applyDraft(db, a) {
|
|
60
60
|
return inTransaction(db, async (tx) => {
|
|
61
61
|
const { row } = await openDraft(tx, a);
|
|
62
|
-
const { fresh, acknowledged } = await newCommands(tx, row
|
|
62
|
+
const { fresh, acknowledged } = await newCommands(tx, row.id, a.commands);
|
|
63
63
|
const current = draftOf(row);
|
|
64
64
|
if (fresh.length === 0) return {
|
|
65
65
|
draft: current,
|
|
@@ -70,7 +70,7 @@ function applyDraft(db, a) {
|
|
|
70
70
|
if (!outcome.ok) throw new HttpError(400, "EDIT_REFUSED", outcome.issue.message, { issues: [outcome.issue] });
|
|
71
71
|
const revision = current.revision + 1;
|
|
72
72
|
const at = now();
|
|
73
|
-
const first = Number(row
|
|
73
|
+
const first = Number(row.next_seq);
|
|
74
74
|
const set = {
|
|
75
75
|
spec: outcome.doc,
|
|
76
76
|
revision,
|
|
@@ -85,7 +85,7 @@ function applyDraft(db, a) {
|
|
|
85
85
|
digest: await digestOf(c)
|
|
86
86
|
})));
|
|
87
87
|
await writeCommands(tx, {
|
|
88
|
-
draftId: row
|
|
88
|
+
draftId: row.id,
|
|
89
89
|
commands: added,
|
|
90
90
|
first,
|
|
91
91
|
at
|
package/dist/store/commands.mjs
CHANGED
|
@@ -13,10 +13,10 @@ async function keptCommands(tx, draftId) {
|
|
|
13
13
|
direction: "asc"
|
|
14
14
|
}]
|
|
15
15
|
})).map((r) => ({
|
|
16
|
-
commandId: String(r
|
|
17
|
-
body: r
|
|
18
|
-
revision: Number(r
|
|
19
|
-
digest: String(r
|
|
16
|
+
commandId: String(r.command_id),
|
|
17
|
+
body: r.body,
|
|
18
|
+
revision: Number(r.revision),
|
|
19
|
+
digest: String(r.digest)
|
|
20
20
|
}));
|
|
21
21
|
}
|
|
22
22
|
/** A draft's commands as rows, numbered from `first`; written in one statement where the store can. */
|
package/dist/store/discard.mjs
CHANGED
|
@@ -12,7 +12,7 @@ function discardDraft(db, a) {
|
|
|
12
12
|
table: "dd_dashboard_draft_command",
|
|
13
13
|
where: [{
|
|
14
14
|
field: "draft_id",
|
|
15
|
-
value: row
|
|
15
|
+
value: row.id
|
|
16
16
|
}]
|
|
17
17
|
});
|
|
18
18
|
const others = await tx.count({
|
|
@@ -20,7 +20,7 @@ function discardDraft(db, a) {
|
|
|
20
20
|
where: [
|
|
21
21
|
{
|
|
22
22
|
field: "dashboard_id",
|
|
23
|
-
value: dashboard
|
|
23
|
+
value: dashboard.id
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
field: "state",
|
|
@@ -29,26 +29,26 @@ function discardDraft(db, a) {
|
|
|
29
29
|
{
|
|
30
30
|
field: "id",
|
|
31
31
|
op: "ne",
|
|
32
|
-
value: row
|
|
32
|
+
value: row.id
|
|
33
33
|
}
|
|
34
34
|
]
|
|
35
35
|
});
|
|
36
|
-
if (dashboard
|
|
36
|
+
if (dashboard.current_version === null && others === 0) {
|
|
37
37
|
await tx.deleteMany({
|
|
38
38
|
table: "dd_dashboard_draft",
|
|
39
39
|
where: [{
|
|
40
40
|
field: "dashboard_id",
|
|
41
|
-
value: dashboard
|
|
41
|
+
value: dashboard.id
|
|
42
42
|
}]
|
|
43
43
|
});
|
|
44
44
|
await tx.deleteMany({
|
|
45
45
|
table: "dd_dashboard",
|
|
46
46
|
where: [{
|
|
47
47
|
field: "id",
|
|
48
|
-
value: dashboard
|
|
48
|
+
value: dashboard.id
|
|
49
49
|
}]
|
|
50
50
|
});
|
|
51
|
-
return { removed: dashboard
|
|
51
|
+
return { removed: dashboard.default_of === null };
|
|
52
52
|
}
|
|
53
53
|
await advanceDraft(tx, row, {
|
|
54
54
|
state: "closed",
|
package/dist/store/drafts.mjs
CHANGED
|
@@ -34,7 +34,7 @@ async function madeBefore(db, a) {
|
|
|
34
34
|
}
|
|
35
35
|
]
|
|
36
36
|
});
|
|
37
|
-
if (made !== null && made
|
|
37
|
+
if (made !== null && made.request_digest !== await docDigest(a.target.create)) throw new HttpError(409, "REQUEST_REUSED", `The request id "${requestId}" already made "${String(made.title)}". Send a new one for another dashboard.`);
|
|
38
38
|
return made;
|
|
39
39
|
}
|
|
40
40
|
/** The dashboard row a draft edits, made for a built-in or a new dashboard the first time. */
|
|
@@ -75,9 +75,9 @@ async function targetRow(db, a) {
|
|
|
75
75
|
function startDraft(db, a) {
|
|
76
76
|
return inTransaction(db, async (tx) => {
|
|
77
77
|
const { row, base } = await targetRow(tx, a);
|
|
78
|
-
const id = String(row
|
|
78
|
+
const id = String(row.id);
|
|
79
79
|
const existing = await draftRow(tx, id, a.author);
|
|
80
|
-
if (existing?.
|
|
80
|
+
if (existing?.state === "open") return draftOf(existing);
|
|
81
81
|
const head = await headDoc(tx, row);
|
|
82
82
|
const doc = head.doc ?? base;
|
|
83
83
|
if (doc === void 0) throw new HttpError(404, "NOT_FOUND", `The dashboard "${id}" has no document to edit.`);
|
|
@@ -110,12 +110,12 @@ function startDraft(db, a) {
|
|
|
110
110
|
});
|
|
111
111
|
return draftOf(data);
|
|
112
112
|
}
|
|
113
|
-
const generation = Number(existing
|
|
113
|
+
const generation = Number(existing.generation) + 1;
|
|
114
114
|
await tx.updateMany({
|
|
115
115
|
table: "dd_dashboard_draft",
|
|
116
116
|
where: [{
|
|
117
117
|
field: "id",
|
|
118
|
-
value: existing
|
|
118
|
+
value: existing.id
|
|
119
119
|
}],
|
|
120
120
|
set: {
|
|
121
121
|
...fresh,
|
package/dist/store/editor.mjs
CHANGED
|
@@ -10,7 +10,7 @@ function draftMethods(db) {
|
|
|
10
10
|
return {
|
|
11
11
|
getDraft: async (a) => {
|
|
12
12
|
const row = await dashboardRow(db, a.tenant, { id: a.id }) === null ? null : await draftRow(db, a.id, a.author);
|
|
13
|
-
return row === null || row
|
|
13
|
+
return row === null || row.state !== "open" ? null : draftOf(row);
|
|
14
14
|
},
|
|
15
15
|
startDraft: (a) => startDraft(db, a),
|
|
16
16
|
applyDraft: (a) => applyDraft(db, a),
|
package/dist/store/publish.mjs
CHANGED
|
@@ -13,11 +13,11 @@ import { replay } from "derive-dashboards/core";
|
|
|
13
13
|
async function publishedDoc(tx, draft, dashboard, expected) {
|
|
14
14
|
const head = await headDoc(tx, dashboard);
|
|
15
15
|
expectHead(head.version, expected);
|
|
16
|
-
if (head.version === Number(draft
|
|
16
|
+
if (head.version === Number(draft.base_version) || head.doc === void 0) return {
|
|
17
17
|
doc: draftDoc(draft),
|
|
18
18
|
head: head.version
|
|
19
19
|
};
|
|
20
|
-
const merged = replay(head.doc, await keptCommands(tx, draft
|
|
20
|
+
const merged = replay(head.doc, await keptCommands(tx, draft.id));
|
|
21
21
|
const refused = merged.outcomes.flatMap((o) => o.applied ? [] : [o.issue]);
|
|
22
22
|
const [issue] = refused;
|
|
23
23
|
if (issue !== void 0) throw new HttpError(409, "REPLAY_REFUSED", `${String(refused.length)} of your changes no longer apply to version ${String(head.version)}: ${issue.message}`, { issues: refused });
|
|
@@ -109,10 +109,10 @@ async function answeredBefore(tx, a, rows) {
|
|
|
109
109
|
const done = await earlier(tx, a.id, a.requestId, a.author);
|
|
110
110
|
const { draft, dashboard } = rows;
|
|
111
111
|
if (done !== null) {
|
|
112
|
-
if (draft?.
|
|
113
|
-
return Number(done
|
|
112
|
+
if (draft?.state === "open") throw new HttpError(409, "REQUEST_REUSED", `The request id "${a.requestId}" already published version ${String(done.n)}. Send a new one for this publish.`);
|
|
113
|
+
return Number(done.n);
|
|
114
114
|
}
|
|
115
|
-
return draft?.
|
|
115
|
+
return draft?.state === "closed" && draft.closed_by === a.requestId && dashboard.current_version !== null ? Number(dashboard.current_version) : null;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Publishes the author's open draft as the dashboard's next version, in one transaction, and
|
|
@@ -131,11 +131,11 @@ function publish(db, a) {
|
|
|
131
131
|
dashboardId: a.id,
|
|
132
132
|
version: before
|
|
133
133
|
};
|
|
134
|
-
if (draft?.
|
|
134
|
+
if (draft?.state !== "open") throw draftClosed();
|
|
135
135
|
const row = draft;
|
|
136
136
|
expectRevision(row, a.expectedRevision);
|
|
137
|
-
const current = dashboard
|
|
138
|
-
if (Number(row
|
|
137
|
+
const current = dashboard.current_version;
|
|
138
|
+
if (Number(row.revision) === 0 && current !== null) {
|
|
139
139
|
await advanceDraft(tx, row, {
|
|
140
140
|
state: "closed",
|
|
141
141
|
closed_by: a.requestId,
|
|
@@ -150,17 +150,17 @@ function publish(db, a) {
|
|
|
150
150
|
const n = head + 1;
|
|
151
151
|
await insertVersion(tx, {
|
|
152
152
|
...a,
|
|
153
|
-
dashboardId: dashboard
|
|
153
|
+
dashboardId: dashboard.id,
|
|
154
154
|
n,
|
|
155
155
|
doc,
|
|
156
|
-
basedOn: Number(row
|
|
156
|
+
basedOn: Number(row.base_version)
|
|
157
157
|
});
|
|
158
|
-
await advanceHead(tx, dashboard
|
|
158
|
+
await advanceHead(tx, dashboard.id, head, doc);
|
|
159
159
|
await tx.deleteMany({
|
|
160
160
|
table: "dd_dashboard_draft_command",
|
|
161
161
|
where: [{
|
|
162
162
|
field: "draft_id",
|
|
163
|
-
value: row
|
|
163
|
+
value: row.id
|
|
164
164
|
}]
|
|
165
165
|
});
|
|
166
166
|
await advanceDraft(tx, row, {
|
package/dist/store/reader.mjs
CHANGED
|
@@ -3,30 +3,30 @@ import { sameTenant, tenantHash, tenantOf } from "./tenant.mjs";
|
|
|
3
3
|
// src/store/reader.ts
|
|
4
4
|
const text = (value) => typeof value === "string" ? value : void 0;
|
|
5
5
|
function summaryOf(row) {
|
|
6
|
-
const id = String(row
|
|
6
|
+
const id = String(row.id);
|
|
7
7
|
const optional = (key, value) => {
|
|
8
8
|
const t = text(value);
|
|
9
9
|
return t === void 0 ? {} : { [key]: t };
|
|
10
10
|
};
|
|
11
11
|
return {
|
|
12
12
|
id,
|
|
13
|
-
...optional("key", row
|
|
14
|
-
...optional("defaultOf", row
|
|
15
|
-
tenant: tenantOf(row
|
|
16
|
-
title: String(row
|
|
17
|
-
...optional("description", row
|
|
18
|
-
ownerId: String(row
|
|
19
|
-
ownerKind: row
|
|
20
|
-
currentVersion: Number(row
|
|
21
|
-
token: `${id}@${String(row
|
|
22
|
-
...optional("archivedAt", row
|
|
13
|
+
...optional("key", row.key),
|
|
14
|
+
...optional("defaultOf", row.default_of),
|
|
15
|
+
tenant: tenantOf(row.tenant),
|
|
16
|
+
title: String(row.title),
|
|
17
|
+
...optional("description", row.description),
|
|
18
|
+
ownerId: String(row.owner_id),
|
|
19
|
+
ownerKind: row.owner_kind === "agent" ? "agent" : "user",
|
|
20
|
+
currentVersion: Number(row.current_version),
|
|
21
|
+
token: `${id}@${String(row.current_version)}`,
|
|
22
|
+
...optional("archivedAt", row.archived_at)
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
/** A dashboard with its document at its current version. */
|
|
26
26
|
function headOf(row, spec) {
|
|
27
27
|
return {
|
|
28
28
|
...summaryOf(row),
|
|
29
|
-
doc: documentOf(spec, `dashboard "${String(row
|
|
29
|
+
doc: documentOf(spec, `dashboard "${String(row.id)}"`)
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -98,7 +98,7 @@ var StoreReader = class {
|
|
|
98
98
|
offset
|
|
99
99
|
});
|
|
100
100
|
return {
|
|
101
|
-
items: rows.slice(0, limit).filter((row) => sameTenant(row
|
|
101
|
+
items: rows.slice(0, limit).filter((row) => sameTenant(row.tenant, tenant)).map((row) => summaryOf(row)),
|
|
102
102
|
...rows.length > limit ? { next: String(offset + limit) } : {}
|
|
103
103
|
};
|
|
104
104
|
}
|
|
@@ -112,26 +112,45 @@ var StoreReader = class {
|
|
|
112
112
|
return {
|
|
113
113
|
dashboardId: owner.id,
|
|
114
114
|
version,
|
|
115
|
-
doc: documentOf(row
|
|
116
|
-
author: { id: String(row
|
|
117
|
-
createdAt: String(row
|
|
115
|
+
doc: documentOf(row.spec, `version ${version} of "${owner.id}"`),
|
|
116
|
+
author: { id: String(row.author_id) },
|
|
117
|
+
createdAt: String(row.created_at)
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
121
|
/** A stored dashboard row as viewers see it, its current version read: none until its first publish. */
|
|
122
122
|
async function storedHead(adapter, row, tenant) {
|
|
123
|
-
if (row === null || !sameTenant(row
|
|
124
|
-
if (row
|
|
125
|
-
return headOf(row,
|
|
123
|
+
if (row === null || !sameTenant(row.tenant, tenant)) return null;
|
|
124
|
+
if (row.current_version === null) return null;
|
|
125
|
+
return headOf(row, await versionSpec(adapter, String(row.id), Number(row.current_version)));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Published versions never change, so each store keeps the documents it read, by dashboard and
|
|
129
|
+
* version, for the requests after (a tile, a filter's values): at most 500, the oldest first out.
|
|
130
|
+
* The row read beside it still decides the tenant and which version is current.
|
|
131
|
+
*/
|
|
132
|
+
const specs = /* @__PURE__ */ new WeakMap();
|
|
133
|
+
const MOST_SPECS = 500;
|
|
134
|
+
function versionSpec(adapter, dashboardId, n) {
|
|
135
|
+
const kept = specs.get(adapter) ?? /* @__PURE__ */ new Map();
|
|
136
|
+
specs.set(adapter, kept);
|
|
137
|
+
const key = `${dashboardId}\u0000${String(n)}`;
|
|
138
|
+
const found = kept.get(key);
|
|
139
|
+
if (found !== void 0) return found;
|
|
140
|
+
const read = adapter.findOne({
|
|
126
141
|
table: "dd_dashboard_version",
|
|
127
142
|
where: [{
|
|
128
143
|
field: "dashboard_id",
|
|
129
|
-
value:
|
|
144
|
+
value: dashboardId
|
|
130
145
|
}, {
|
|
131
146
|
field: "n",
|
|
132
|
-
value:
|
|
147
|
+
value: n
|
|
133
148
|
}]
|
|
134
|
-
}))?.
|
|
149
|
+
}).then((version) => version?.spec);
|
|
150
|
+
read.catch(() => kept.delete(key));
|
|
151
|
+
kept.set(key, read);
|
|
152
|
+
if (kept.size > MOST_SPECS) kept.delete(kept.keys().next().value ?? key);
|
|
153
|
+
return read;
|
|
135
154
|
}
|
|
136
155
|
function createReader(adapter) {
|
|
137
156
|
return new StoreReader(adapter);
|
package/dist/store/review.mjs
CHANGED
|
@@ -20,7 +20,7 @@ async function publisher(tx, dashboardId, n) {
|
|
|
20
20
|
const author = v === null ? void 0 : authorIn(v, "author");
|
|
21
21
|
return v === null ? null : {
|
|
22
22
|
...author === void 0 ? {} : { author },
|
|
23
|
-
at: String(v
|
|
23
|
+
at: String(v.created_at)
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -31,21 +31,21 @@ async function publisher(tx, dashboardId, n) {
|
|
|
31
31
|
async function stillBoth(tx, row, head) {
|
|
32
32
|
const origin = originDoc(row);
|
|
33
33
|
if (origin === void 0 || head === void 0) return [];
|
|
34
|
-
const kept = await keptCommands(tx, row
|
|
34
|
+
const kept = await keptCommands(tx, row.id);
|
|
35
35
|
return overlapsOf(kept, replay(head, kept), diffDocs(origin, head), head);
|
|
36
36
|
}
|
|
37
37
|
/** What publishing this draft row now would do, on the dashboard's current version. */
|
|
38
38
|
async function previewOf(tx, row, dashboard) {
|
|
39
39
|
const doc = draftDoc(row);
|
|
40
40
|
const base = baseDoc(row);
|
|
41
|
-
const baseVersion = Number(row
|
|
42
|
-
const revision = Number(row
|
|
41
|
+
const baseVersion = Number(row.base_version);
|
|
42
|
+
const revision = Number(row.revision);
|
|
43
43
|
const head = await headDoc(tx, dashboard);
|
|
44
44
|
const named = namedOf(row);
|
|
45
45
|
if (head.version === baseVersion || head.doc === void 0) {
|
|
46
46
|
const changes = markShifted(diffDocs(head.doc ?? base, doc), named);
|
|
47
47
|
const both = await stillBoth(tx, row, head.doc);
|
|
48
|
-
const by = both.length === 0 ? null : await publisher(tx, dashboard
|
|
48
|
+
const by = both.length === 0 ? null : await publisher(tx, dashboard.id, head.version);
|
|
49
49
|
return {
|
|
50
50
|
head: head.version,
|
|
51
51
|
revision,
|
|
@@ -58,10 +58,10 @@ async function previewOf(tx, row, dashboard) {
|
|
|
58
58
|
...by === null ? {} : { publishedBy: by }
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const kept = await keptCommands(tx, row
|
|
61
|
+
const kept = await keptCommands(tx, row.id);
|
|
62
62
|
const merged = replay(head.doc, kept);
|
|
63
63
|
const since = diffDocs(base, head.doc);
|
|
64
|
-
const by = await publisher(tx, dashboard
|
|
64
|
+
const by = await publisher(tx, dashboard.id, head.version);
|
|
65
65
|
return {
|
|
66
66
|
head: head.version,
|
|
67
67
|
revision,
|
|
@@ -84,12 +84,12 @@ function draftDocument(db, a) {
|
|
|
84
84
|
return inTransaction(db, async (tx) => {
|
|
85
85
|
const dashboard = await dashboardRow(tx, a.tenant, { id: a.id });
|
|
86
86
|
const row = dashboard === null ? null : await draftRow(tx, a.id, a.author);
|
|
87
|
-
if (dashboard === null || row === null || row
|
|
87
|
+
if (dashboard === null || row === null || row.state !== "open") return null;
|
|
88
88
|
const doc = draftDoc(row);
|
|
89
89
|
if (a.as === "draft") return doc;
|
|
90
90
|
const head = await headDoc(tx, dashboard);
|
|
91
|
-
if (head.version === Number(row
|
|
92
|
-
return replay(head.doc, await keptCommands(tx, row
|
|
91
|
+
if (head.version === Number(row.base_version) || head.doc === void 0) return doc;
|
|
92
|
+
return replay(head.doc, await keptCommands(tx, row.id)).doc;
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
/** What publishing the author's draft would do now, without writing anything. */
|
|
@@ -147,11 +147,11 @@ function rebase(db, a) {
|
|
|
147
147
|
expectRevision(row, a.expectedRevision);
|
|
148
148
|
const head = await headDoc(tx, dashboard);
|
|
149
149
|
expectHead(head.version, a.head);
|
|
150
|
-
const kept = await keptCommands(tx, row
|
|
150
|
+
const kept = await keptCommands(tx, row.id);
|
|
151
151
|
const onto = head.doc;
|
|
152
152
|
if (onto === void 0) throw new HttpError(400, "EDIT_REFUSED", "Nothing has been published yet, so there is nothing to move the draft onto.");
|
|
153
153
|
refuseUnknownDrops(a.drop, kept);
|
|
154
|
-
const first = Math.min(Number(row
|
|
154
|
+
const first = Math.min(Number(row.revision) + 1, ...kept.map((k) => k.revision));
|
|
155
155
|
const next = [...await Promise.all(a.restore.map((w) => putBack(row, onto, w, first))), ...kept.filter((k) => !a.drop.includes(k.commandId))];
|
|
156
156
|
const outcome = reduceAll(onto, next.map((k) => k.body));
|
|
157
157
|
if (!outcome.ok) throw new HttpError(409, "REPLAY_REFUSED", outcome.issue.message, { issues: [outcome.issue] });
|
|
@@ -159,15 +159,15 @@ function rebase(db, a) {
|
|
|
159
159
|
spec: outcome.doc,
|
|
160
160
|
base_spec: onto,
|
|
161
161
|
base_version: head.version,
|
|
162
|
-
origin_version: row
|
|
163
|
-
origin_spec: row
|
|
164
|
-
revision: Number(row
|
|
162
|
+
origin_version: row.origin_version ?? Number(row.base_version),
|
|
163
|
+
origin_spec: row.origin_spec ?? row.base_spec,
|
|
164
|
+
revision: Number(row.revision) + 1,
|
|
165
165
|
...keptColumns(next),
|
|
166
166
|
next_seq: next.length,
|
|
167
167
|
updated_at: now()
|
|
168
168
|
};
|
|
169
169
|
await advanceDraft(tx, row, set);
|
|
170
|
-
await rewriteCommands(tx, row
|
|
170
|
+
await rewriteCommands(tx, row.id, next);
|
|
171
171
|
return draftOf({
|
|
172
172
|
...row,
|
|
173
173
|
...set
|
package/dist/store/rows.mjs
CHANGED
|
@@ -35,11 +35,11 @@ async function dashboardRow(db, tenant, by) {
|
|
|
35
35
|
}
|
|
36
36
|
]
|
|
37
37
|
});
|
|
38
|
-
return row !== null && sameTenant(row
|
|
38
|
+
return row !== null && sameTenant(row.tenant, tenant) ? row : null;
|
|
39
39
|
}
|
|
40
40
|
/** A dashboard's document at its current version; a built-in or new one has none yet. */
|
|
41
41
|
async function headDoc(db, row) {
|
|
42
|
-
const version = row
|
|
42
|
+
const version = row.current_version === null ? 0 : Number(row.current_version);
|
|
43
43
|
if (version === 0) return { version };
|
|
44
44
|
return {
|
|
45
45
|
version,
|
|
@@ -47,12 +47,12 @@ async function headDoc(db, row) {
|
|
|
47
47
|
table: "dd_dashboard_version",
|
|
48
48
|
where: [{
|
|
49
49
|
field: "dashboard_id",
|
|
50
|
-
value: row
|
|
50
|
+
value: row.id
|
|
51
51
|
}, {
|
|
52
52
|
field: "n",
|
|
53
53
|
value: version
|
|
54
54
|
}]
|
|
55
|
-
}))?.
|
|
55
|
+
}))?.spec, `dashboard "${String(row.id)}"`)
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
/** A document's hash, by its canonical JSON. */
|
|
@@ -95,9 +95,9 @@ function draftAuthorId(author) {
|
|
|
95
95
|
}
|
|
96
96
|
/** The id an author is known by, from the id their draft row is kept under. */
|
|
97
97
|
function authorIdOf(row) {
|
|
98
|
-
const key = String(row
|
|
99
|
-
const person = row
|
|
100
|
-
if (row
|
|
98
|
+
const key = String(row.author_id);
|
|
99
|
+
const person = row.for_id;
|
|
100
|
+
if (row.author_kind !== "agent" || typeof person !== "string") return key;
|
|
101
101
|
return key.slice(`${String(person.length)}:${person}:`.length);
|
|
102
102
|
}
|
|
103
103
|
/** The author's draft row of a dashboard, open or closed; null when there has never been one. */
|
|
@@ -121,11 +121,11 @@ function draftRow(db, dashboardId, author) {
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
/** The document a draft holds now. */
|
|
124
|
-
const draftDoc = (row) => documentOf(row
|
|
124
|
+
const draftDoc = (row) => documentOf(row.spec, `the draft of "${String(row.dashboard_id)}"`);
|
|
125
125
|
/** The document a draft started from: the draft is this with its commands applied. */
|
|
126
|
-
const baseDoc = (row) => documentOf(row
|
|
126
|
+
const baseDoc = (row) => documentOf(row.base_spec, `the start of the draft of "${String(row.dashboard_id)}"`);
|
|
127
127
|
/** The document a draft first started from, once review moved it onto a newer version; else none. */
|
|
128
|
-
const originDoc = (row) => row
|
|
128
|
+
const originDoc = (row) => row.origin_spec === null || row.origin_spec === void 0 ? void 0 : documentOf(row.origin_spec, `the first start of the draft of "${String(row.dashboard_id)}"`);
|
|
129
129
|
/** Who a draft row names in a column pair, if anyone. */
|
|
130
130
|
function authorIn(row, prefix) {
|
|
131
131
|
const id = row[`${prefix}_id`];
|
|
@@ -136,19 +136,19 @@ function authorIn(row, prefix) {
|
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
/** The widgets a draft row says its commands name. */
|
|
139
|
-
const namedOf = (row) => new Set(Array.isArray(row
|
|
139
|
+
const namedOf = (row) => new Set(Array.isArray(row.named) ? row.named.map(String) : []);
|
|
140
140
|
/** A draft row as the client reads it: its document, changes and undo steps, from the row alone. */
|
|
141
141
|
function draftOf(row) {
|
|
142
142
|
const doc = draftDoc(row);
|
|
143
143
|
return {
|
|
144
|
-
dashboardId: String(row
|
|
144
|
+
dashboardId: String(row.dashboard_id),
|
|
145
145
|
authorId: authorIdOf(row),
|
|
146
|
-
generation: Number(row
|
|
147
|
-
revision: Number(row
|
|
148
|
-
baseVersion: Number(row
|
|
146
|
+
generation: Number(row.generation),
|
|
147
|
+
revision: Number(row.revision),
|
|
148
|
+
baseVersion: Number(row.base_version),
|
|
149
149
|
doc,
|
|
150
150
|
changes: markShifted(diffDocs(baseDoc(row), doc), namedOf(row)),
|
|
151
|
-
steps: Number(row
|
|
151
|
+
steps: Number(row.steps)
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
/** The refusal for an edit made against another revision of the draft: the one wording of it. */
|
|
@@ -159,7 +159,7 @@ const draftClosed = () => new HttpError(409, "DRAFT_CLOSED", "There is no open d
|
|
|
159
159
|
async function openDraft(db, a) {
|
|
160
160
|
const dashboard = await dashboardRow(db, a.tenant, { id: a.id });
|
|
161
161
|
const row = dashboard === null ? null : await draftRow(db, a.id, a.author);
|
|
162
|
-
if (dashboard === null || row === null || row
|
|
162
|
+
if (dashboard === null || row === null || row.state !== "open") throw draftClosed();
|
|
163
163
|
return {
|
|
164
164
|
row,
|
|
165
165
|
dashboard
|
|
@@ -167,7 +167,7 @@ async function openDraft(db, a) {
|
|
|
167
167
|
}
|
|
168
168
|
/** Refuses an edit made against another revision of the draft than the current one. */
|
|
169
169
|
function expectRevision(row, expected) {
|
|
170
|
-
expectDraftRevision(Number(row
|
|
170
|
+
expectDraftRevision(Number(row.revision), expected);
|
|
171
171
|
}
|
|
172
172
|
/** Refuses an edit made against another revision than `current`, with the one message for it. */
|
|
173
173
|
function expectDraftRevision(current, expected) {
|
|
@@ -194,10 +194,10 @@ async function advanceDraft(tx, row, set) {
|
|
|
194
194
|
table: "dd_dashboard_draft",
|
|
195
195
|
where: [{
|
|
196
196
|
field: "id",
|
|
197
|
-
value: row
|
|
197
|
+
value: row.id
|
|
198
198
|
}, {
|
|
199
199
|
field: "revision",
|
|
200
|
-
value: row
|
|
200
|
+
value: row.revision
|
|
201
201
|
}],
|
|
202
202
|
set
|
|
203
203
|
}) !== 1) throw draftConflict();
|