@stamhoofd/metabase 2.148.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.
Files changed (46) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +136 -0
  3. package/dist/api.d.ts +217 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +334 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/naming.d.ts +36 -0
  8. package/dist/naming.d.ts.map +1 -0
  9. package/dist/naming.js +42 -0
  10. package/dist/naming.js.map +1 -0
  11. package/dist/report.d.ts +141 -0
  12. package/dist/report.d.ts.map +1 -0
  13. package/dist/report.js +297 -0
  14. package/dist/report.js.map +1 -0
  15. package/dist/sync-report.d.ts +212 -0
  16. package/dist/sync-report.d.ts.map +1 -0
  17. package/dist/sync-report.js +653 -0
  18. package/dist/sync-report.js.map +1 -0
  19. package/package.json +33 -0
  20. package/report/eenheden.sql +459 -0
  21. package/report/filters.sql +65 -0
  22. package/report/includes/aangesloten.sql +23 -0
  23. package/report/includes/aansluiting.sql +26 -0
  24. package/report/includes/facts-alle-jaren.sql +53 -0
  25. package/report/includes/facts.sql +102 -0
  26. package/report/includes/gtp.sql +49 -0
  27. package/report/includes/ingeschreven-voor.sql +27 -0
  28. package/report/includes/jaren.sql +20 -0
  29. package/report/includes/keeo/tak-categorie.sql +30 -0
  30. package/report/includes/leden-per-jaar.sql +29 -0
  31. package/report/includes/leden.sql +39 -0
  32. package/report/includes/omkaderingscijfer.sql +17 -0
  33. package/report/includes/postcode-coordinaten.sql +8 -0
  34. package/report/includes/ravot/gtp.sql +32 -0
  35. package/report/includes/ravot/omkaderingscijfer.sql +25 -0
  36. package/report/includes/ravot/tak-categorie.sql +28 -0
  37. package/report/includes/ravot/type-deelnemers.sql +22 -0
  38. package/report/includes/tak-categorie.sql +18 -0
  39. package/report/includes/takken.sql +20 -0
  40. package/report/includes/tarief.sql +14 -0
  41. package/report/includes/type-deelnemers.sql +14 -0
  42. package/report/includes/uldk.sql +23 -0
  43. package/report/jeugdbewegingen.sql +221 -0
  44. package/report/nationaal.sql +229 -0
  45. package/report/netwerk.sql +70 -0
  46. package/report/varia.sql +35 -0
package/dist/report.js ADDED
@@ -0,0 +1,297 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ export const reportCardSizes = ['full', 'two-thirds', 'half', 'third', 'quarter', 'sixth'];
5
+ export const reportCardXLabels = ['show', 'hide', 'compact', 'rotate-45', 'rotate-90'];
6
+ export const reportCardBest = ['low', 'high'];
7
+ /** The order the tabs are written in: the pages of the client's report first, then what is not one. */
8
+ export const reportTabOrder = ['nationaal', 'eenheden', 'netwerk', 'varia', 'jeugdbewegingen', 'filters'];
9
+ export function getReportDirectory() {
10
+ return path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'report');
11
+ }
12
+ /**
13
+ * The report as one environment counts it.
14
+ *
15
+ * Not every figure is counted the same everywhere -- the GTP index weighs takken for keeo and ages
16
+ * for ravot -- and a statistics database holds one platform, so which variant a card gets is decided
17
+ * here rather than in the queries. `env` is the same name the data source carries.
18
+ */
19
+ export async function loadReport(env, directory = getReportDirectory()) {
20
+ const includes = await loadIncludes(path.join(directory, 'includes'), env);
21
+ const files = (await fs.readdir(directory)).filter(file => file.endsWith('.sql')).sort();
22
+ const tabs = await Promise.all(files.map(async (file) => {
23
+ return parseTab(await fs.readFile(path.join(directory, file), 'utf-8'), file, includes, env);
24
+ }));
25
+ return tabs.sort((a, b) => orderOf(a.key) - orderOf(b.key));
26
+ }
27
+ function orderOf(key) {
28
+ const index = reportTabOrder.indexOf(key);
29
+ return index === -1 ? reportTabOrder.length : index;
30
+ }
31
+ /**
32
+ * The shared fragments, with the ones this environment counts differently laid over them:
33
+ * `includes/<env>/gtp.sql` is what `@include gtp` expands to there, while every other environment
34
+ * keeps `includes/gtp.sql`. A card therefore never says which platform it is written for.
35
+ *
36
+ * An override of a name no fragment carries is a mistake rather than a fragment only one environment
37
+ * has: nothing includes it, so a misspelled file would change nothing and say nothing.
38
+ */
39
+ async function loadIncludes(directory, env) {
40
+ const includes = await readIncludes(directory);
41
+ for (const [name, sql] of await readIncludes(path.join(directory, env))) {
42
+ if (!includes.has(name)) {
43
+ throw new Error(`includes/${env}/${name}.sql overrides "${name}", which has no includes/${name}.sql`);
44
+ }
45
+ includes.set(name, sql);
46
+ }
47
+ return includes;
48
+ }
49
+ /** The `.sql` files of a directory by name. An environment that overrides nothing has no directory. */
50
+ async function readIncludes(directory) {
51
+ let entries;
52
+ try {
53
+ entries = await fs.readdir(directory);
54
+ }
55
+ catch (error) {
56
+ if (error.code === 'ENOENT') {
57
+ return new Map();
58
+ }
59
+ throw error;
60
+ }
61
+ const includes = new Map();
62
+ for (const file of entries.filter(entry => entry.endsWith('.sql'))) {
63
+ includes.set(path.basename(file, '.sql'), (await fs.readFile(path.join(directory, file), 'utf-8')).trim());
64
+ }
65
+ return includes;
66
+ }
67
+ /**
68
+ * Splits a file into its `@tab` header and `@card` sections. Everything that is not a directive
69
+ * stays as it is, so a card's sql keeps the comments written above it.
70
+ */
71
+ export function parseTab(contents, file, includes, env) {
72
+ const sections = splitSections(contents, file, env);
73
+ const header = sections.find(section => section.kind === 'tab');
74
+ if (!header) {
75
+ throw new Error(`${file} has no "-- @tab <key>" header`);
76
+ }
77
+ const cards = sections.filter(section => section.kind === 'card').map(section => parseCard(section, file, includes));
78
+ if (cards.length === 0) {
79
+ throw new Error(`${file} declares no cards`);
80
+ }
81
+ // A question is stored under its title, so two cards sharing one on the same tab would end up as
82
+ // the same question: whichever is written last decides what both show.
83
+ const duplicate = cards.find((card, index) => cards.findIndex(other => other.title === card.title) !== index);
84
+ if (duplicate) {
85
+ throw new Error(`${file}: two cards are titled "${duplicate.title}", which would store them as one question`);
86
+ }
87
+ const filters = splitList(header.attributes.get('filters'));
88
+ const offered = new Set(cards.flatMap(card => card.parameters));
89
+ const unused = filters.filter(filter => !offered.has(filter));
90
+ if (unused.length > 0) {
91
+ throw new Error(`${file}: filter "${unused[0]}" is declared but no card uses {{${unused[0]}}}`);
92
+ }
93
+ return {
94
+ key: header.key,
95
+ title: required(header.attributes, 'title', file, header.key),
96
+ description: header.attributes.get('description'),
97
+ dashboard: header.attributes.get('dashboard'),
98
+ filters,
99
+ hidden: header.attributes.get('hidden') === 'true',
100
+ cards,
101
+ };
102
+ }
103
+ /**
104
+ * Every setting a tab or card understands. A line shaped like one below the query is a setting that
105
+ * slipped down rather than a comment, and would otherwise be dropped without a word: writing a
106
+ * comment above `-- size:` is enough to make the whole block below it stop counting.
107
+ */
108
+ const knownAttributes = new Set(['title', 'display', 'size', 'description', 'dimensions', 'metrics', 'columns', 'stacked', 'segments', 'best', 'xlabels', 'height', 'span', 'latitude', 'longitude', 'filters', 'hidden', 'dashboard']);
109
+ function splitSections(contents, file, env) {
110
+ const sections = [];
111
+ let current;
112
+ for (const line of contents.split('\n')) {
113
+ const directive = /^--[ \t]*@(tab|card)[ \t]+(\S+)[ \t]*$/.exec(line);
114
+ if (directive) {
115
+ current = { kind: directive[1], key: directive[2], attributes: new Map(), qualified: new Set(), body: '' };
116
+ sections.push(current);
117
+ continue;
118
+ }
119
+ if (!current) {
120
+ continue;
121
+ }
122
+ // An attribute only counts while the body has not started; further comments belong to the sql.
123
+ // The value keeps its leading spaces here and is trimmed below: matching them separately
124
+ // would let the two quantifiers split the same run of spaces in several ways.
125
+ const attribute = /^--[ \t]*([a-z]+)(?:@([a-z0-9-]+))?:(.*)$/.exec(line);
126
+ if (attribute) {
127
+ if (current.body.trim().length === 0) {
128
+ setAttribute(current, attribute[1], attribute[2], attribute[3].trim(), env);
129
+ continue;
130
+ }
131
+ if (knownAttributes.has(attribute[1])) {
132
+ throw new Error(`${file}: "${current.key}" has "${attribute[1]}:" below the query, where it is read as a comment instead of a setting. Move it above the first comment and @include.`);
133
+ }
134
+ }
135
+ current.body += line + '\n';
136
+ }
137
+ return sections;
138
+ }
139
+ /**
140
+ * A setting written `-- description@ravot:` only holds in that environment, and beats the unqualified
141
+ * one wherever it does, whichever of the two is written first. It is how a card says a figure that is
142
+ * not counted the same everywhere in the words of the platform reading it, without becoming two cards.
143
+ */
144
+ function setAttribute(section, name, qualifier, value, env) {
145
+ if (qualifier === undefined) {
146
+ if (!section.qualified.has(name)) {
147
+ section.attributes.set(name, value);
148
+ }
149
+ return;
150
+ }
151
+ if (qualifier !== env) {
152
+ return;
153
+ }
154
+ section.qualified.add(name);
155
+ section.attributes.set(name, value);
156
+ }
157
+ function parseCard(section, file, includes) {
158
+ const size = section.attributes.get('size') ?? 'half';
159
+ if (!reportCardSizes.includes(size)) {
160
+ throw new Error(`${file}: card "${section.key}" has size "${size}", expected one of ${reportCardSizes.join(', ')}`);
161
+ }
162
+ const stacked = section.attributes.get('stacked');
163
+ if (stacked !== undefined && stacked !== 'stacked' && stacked !== 'normalized') {
164
+ throw new Error(`${file}: card "${section.key}" has stacked "${stacked}", expected stacked or normalized`);
165
+ }
166
+ const xLabels = section.attributes.get('xlabels');
167
+ if (xLabels !== undefined && !reportCardXLabels.includes(xLabels)) {
168
+ throw new Error(`${file}: card "${section.key}" has xlabels "${xLabels}", expected one of ${reportCardXLabels.join(', ')}`);
169
+ }
170
+ const display = required(section.attributes, 'display', file, section.key);
171
+ const latitude = section.attributes.get('latitude');
172
+ const longitude = section.attributes.get('longitude');
173
+ if (display === 'map' && (latitude === undefined || longitude === undefined)) {
174
+ throw new Error(`${file}: card "${section.key}" is a map but names no latitude and longitude columns`);
175
+ }
176
+ const { segments, best } = parseRanges(section, file, display);
177
+ const height = parseCount(section, file, 'height');
178
+ const span = parseCount(section, file, 'span') ?? 1;
179
+ // A spanning card is as tall as the rows it stands across, so a height of its own would be read
180
+ // by neither: the layout hands it the one it computes.
181
+ if (height !== undefined && span > 1) {
182
+ throw new Error(`${file}: card "${section.key}" spans ${span} rows and names a height, which the rows it spans decide`);
183
+ }
184
+ const sql = expandIncludes(section.body, includes, file, section.key).trim();
185
+ return {
186
+ key: section.key,
187
+ title: required(section.attributes, 'title', file, section.key),
188
+ display,
189
+ latitude,
190
+ longitude,
191
+ size: size,
192
+ height,
193
+ span,
194
+ description: section.attributes.get('description'),
195
+ dimensions: splitList(section.attributes.get('dimensions')),
196
+ metrics: splitList(section.attributes.get('metrics')),
197
+ columns: splitList(section.attributes.get('columns')),
198
+ stacked,
199
+ segments,
200
+ best,
201
+ xLabels: xLabels,
202
+ parameters: parameterNames(sql),
203
+ sql,
204
+ };
205
+ }
206
+ /** A setting counted in whole cards or rows, which is only a size while it is a positive number. */
207
+ function parseCount(section, file, name) {
208
+ const written = section.attributes.get(name);
209
+ if (written === undefined) {
210
+ return undefined;
211
+ }
212
+ const count = Number(written);
213
+ if (!Number.isInteger(count) || count < 1) {
214
+ throw new Error(`${file}: card "${section.key}" has ${name} "${written}", expected a whole number of rows`);
215
+ }
216
+ return count;
217
+ }
218
+ /** The displays that read a figure against ranges: a gauge draws them, a number is colored by them. */
219
+ const rangedDisplays = ['gauge', 'scalar'];
220
+ /**
221
+ * How a figure is divided into ranges and which way they are read, both of which every other display
222
+ * would silently drop. The boundaries rise, because a range that ends before it starts is drawn
223
+ * nowhere on the arc, and there are at least three of them so the ranges say something the figure
224
+ * does not say on its own.
225
+ */
226
+ function parseRanges(section, file, display) {
227
+ const written = section.attributes.get('segments');
228
+ const best = section.attributes.get('best') ?? 'high';
229
+ for (const name of ['segments', 'best']) {
230
+ if (section.attributes.has(name) && !rangedDisplays.includes(display)) {
231
+ throw new Error(`${file}: card "${section.key}" names ${name}, which only a gauge or a number reads`);
232
+ }
233
+ }
234
+ if (!reportCardBest.includes(best)) {
235
+ throw new Error(`${file}: card "${section.key}" has best "${best}", expected one of ${reportCardBest.join(', ')}`);
236
+ }
237
+ // Which end is the good one only decides how the ranges are colored, so on its own it colors
238
+ // nothing: a number without ranges keeps its own color, and the ones a gauge falls back to are
239
+ // drawn in Metabase's.
240
+ if (section.attributes.has('best') && written === undefined) {
241
+ throw new Error(`${file}: card "${section.key}" says its best is "${best}" but names no segments to color`);
242
+ }
243
+ if (written === undefined) {
244
+ return { segments: [], best: best };
245
+ }
246
+ const segments = splitList(written).map(entry => Number(entry));
247
+ if (segments.length < 3) {
248
+ throw new Error(`${file}: card "${section.key}" has segments "${written}", expected at least three boundaries`);
249
+ }
250
+ if (segments.some((boundary, index) => !Number.isFinite(boundary) || (index > 0 && boundary <= segments[index - 1]))) {
251
+ throw new Error(`${file}: card "${section.key}" has segments "${written}", expected rising numbers`);
252
+ }
253
+ return { segments, best: best };
254
+ }
255
+ /** A fragment may include another, which is how the two grains of `facts` share their filters. */
256
+ function expandIncludes(body, includes, file, card, chain = []) {
257
+ return body.replaceAll(/^([ \t]*)--[ \t]*@include[ \t]+(\S+)[ \t]*$/gm, (_match, indent, name) => {
258
+ const include = includes.get(name);
259
+ if (include === undefined) {
260
+ throw new Error(`${file}: card "${card}" includes "${name}", which has no report/includes/${name}.sql`);
261
+ }
262
+ if (chain.includes(name)) {
263
+ throw new Error(`${file}: card "${card}" includes "${name}" from within itself: ${[...chain, name].join(' -> ')}`);
264
+ }
265
+ return expandIncludes(include, includes, file, card, [...chain, name])
266
+ .split('\n').map(line => indent + line).join('\n');
267
+ });
268
+ }
269
+ /** The `{{name}}` parameters a query uses, in the order they first appear. */
270
+ export function parameterNames(sql) {
271
+ return [...new Set([...sql.matchAll(/\{\{\s*([a-z_]+)\s*\}\}/g)].map(match => match[1]))];
272
+ }
273
+ function splitList(value) {
274
+ return value === undefined ? [] : value.split(',').map(entry => entry.trim()).filter(entry => entry.length > 0);
275
+ }
276
+ function required(attributes, name, file, key) {
277
+ const value = attributes.get(name);
278
+ if (value === undefined || value.length === 0) {
279
+ throw new Error(`${file}: "${key}" has no ${name}`);
280
+ }
281
+ return value;
282
+ }
283
+ /**
284
+ * The sql as it runs outside Metabase: parameters resolved and the `[[...]]` clauses around them
285
+ * kept or dropped. Used by the tests to run a card against a real database, since Metabase is the
286
+ * only thing that understands this syntax.
287
+ */
288
+ export function resolveSql(sql, values = {}) {
289
+ const optional = sql.replaceAll(/\[\[([\s\S]*?)\]\]/g, (_match, clause) => {
290
+ return parameterNames(clause).every(name => values[name] !== undefined && values[name] !== null) ? clause : '';
291
+ });
292
+ return optional.replaceAll(/\{\{\s*([a-z_]+)\s*\}\}/g, (_match, name) => {
293
+ const value = values[name];
294
+ return value === undefined || value === null ? 'NULL' : `'${value.replaceAll("'", "''")}'`;
295
+ });
296
+ }
297
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAmHpC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAU,CAAC;AAGpG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AAGhG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,CAAU,CAAC;AAGvD,uGAAuG;AACvG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC;AAE1G,MAAM,UAAU,kBAAkB;IAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACnF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,SAAS,GAAG,kB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AM,KAAK,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,MAAM,GAAG,YAAY,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,SAAwC,EAAE;IAC9E,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAc,EAAE,EAAE;QAC9E,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACnH,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,UAAU,CAAC,0BAA0B,EAAE,CAAC,MAAM,EAAE,IAAY,EAAE,EAAE;QAC5E,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;IAC/F,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,212 @@
1
+ import type { MetabaseApi } from './api.js';
2
+ import type { ReportCard, ReportCardBest, ReportTab } from './report.js';
3
+ /**
4
+ * Turns the report definition of `report.ts` into one Metabase dashboard, with a tab per page of the
5
+ * client's report.
6
+ *
7
+ * This file only knows how to say the queries in Metabase's vocabulary: which display, which columns
8
+ * on which axis, and which filter drives which card.
9
+ *
10
+ * Everything here is written by name and updated in place, so running it twice changes nothing and
11
+ * running it after an edit only moves what actually changed.
12
+ */
13
+ /**
14
+ * The filters shown above the dashboards. `valuesFrom` names the card in the hidden `filters`
15
+ * dashboard that fills the dropdown, and `column` the column to read the values from.
16
+ *
17
+ * `keepOrder` says the order of that card matters. Metabase sorts a dropdown fed by a question
18
+ * alphabetically whatever the question's ORDER BY says, so the scoutsjaren would run oldest first.
19
+ * Those filters get the values written out as a fixed list instead, which Metabase leaves alone —
20
+ * at the cost of being a snapshot, so a new scoutsjaar appears once the report is written again.
21
+ * Unit names read fine alphabetically and stay on the live question.
22
+ *
23
+ * `multiple` is whether several values can be picked at once. Metabase writes those out comma
24
+ * separated, so a query takes such a filter as `IN ({{name}})` and one without as `= {{name}}`. It
25
+ * is said here for every filter rather than only where it is on, because a filter that drives a
26
+ * variable is single-select unless told otherwise, and a second value would land beside the `=` of
27
+ * the others as sql they cannot parse.
28
+ *
29
+ * `start` is what a filter is set to when a dashboard is opened. Only one filter has any: the others
30
+ * count every member while nothing is chosen, and a value to start from would show whoever does not
31
+ * read the filter bar a slice of the platform. "Ingeschreven voor" is the other way round -- empty
32
+ * counts the wachtlijsten and the activiteiten along with the leden -- so it opens on the
33
+ * leeftijdsgroepen, which is what the ledenstatistieken are read as.
34
+ */
35
+ export type ReportFilter = {
36
+ name: string;
37
+ title: string;
38
+ valuesFrom: string;
39
+ column: string;
40
+ keepOrder: boolean;
41
+ multiple: boolean;
42
+ start?: string[];
43
+ };
44
+ export declare const reportFilters: readonly ReportFilter[];
45
+ /**
46
+ * What a question is called in the collection.
47
+ *
48
+ * Qualified with its tab because a title is not unique — the report shows "Aantal leden per postcode"
49
+ * on two pages, as the client's own does — and questions are matched by name to be updated in place.
50
+ * Two of them sharing a name means one silently overwrites the other. The dashboard still shows the
51
+ * plain title: that comes from the card's own `card.title` setting.
52
+ */
53
+ export declare function cardName(card: ReportCard, tab: ReportTab): string;
54
+ /**
55
+ * Places the cards left to right in the order the report lists them, wrapping to a new row when the
56
+ * next one no longer fits.
57
+ *
58
+ * A row is as tall as its tallest card and every card in it is drawn that tall, so the row ends on
59
+ * one line. The cards of a row are two readings of one thing -- the geslachten as a pie beside the
60
+ * geslachten over the years -- and one of them stopping halfway leaves a hole under it that the row
61
+ * below cannot fill.
62
+ *
63
+ * A card that spans rows keeps its columns in the rows below it, which the cards after it wrap
64
+ * around, and ends up as tall as those rows together: the netwerk map stands beside the chart and
65
+ * the pie stacked next to it. It does not decide how tall those rows are -- the cards stacked beside
66
+ * it do, which is what makes it end exactly where they do.
67
+ */
68
+ export declare function layoutCards(cards: ReportCard[]): {
69
+ card: ReportCard;
70
+ row: number;
71
+ col: number;
72
+ sizeX: number;
73
+ sizeY: number;
74
+ }[];
75
+ /**
76
+ * Metabase identifies a template tag by a uuid that has to stay the same between runs, otherwise
77
+ * every filter connection is rebuilt on each push. Derived from the card and parameter name so it is
78
+ * stable without having to be stored anywhere.
79
+ */
80
+ export declare function templateTagId(cardKey: string, parameter: string): string;
81
+ export declare function buildTemplateTags(card: ReportCard): Record<string, unknown>;
82
+ /**
83
+ * What Metabase actually draws. A map needs a coordinate per postal code, and those are loaded
84
+ * separately from anything Stamhoofd holds; while `postal_codes` is empty the card is a bar chart of
85
+ * the same figures rather than an empty map.
86
+ */
87
+ export declare function effectiveDisplay(card: ReportCard, hasCoordinates: boolean): string;
88
+ /**
89
+ * The color of each range, mixed along that scale rather than picked per range: the ranges of a
90
+ * figure are read against each other, so what a color says has to be where it sits between the worst
91
+ * and the best -- whether a card splits the figure in three or in six.
92
+ *
93
+ * A figure that is better the lower it is runs the scale the other way, which is the whole of the
94
+ * difference between the two figures of the page: green is always the end an eenheid is doing well at.
95
+ */
96
+ export declare function segmentColors(count: number, best: ReportCardBest): string[];
97
+ /**
98
+ * The colors the values of a column are drawn in, wherever a card splits on it.
99
+ *
100
+ * Kept by the column rather than by the card because the same split stands on several pages -- the
101
+ * geslachten are a pie on two of them and the bars of a third -- and someone reading two pages side
102
+ * by side reads the colors before the legend. A value the palette does not name keeps whichever
103
+ * color Metabase gives it.
104
+ */
105
+ export declare const columnPalettes: Map<string, Record<string, string>>;
106
+ /**
107
+ * The colors a chart falls back to, per platform: the ones the platform shows itself in everywhere
108
+ * else. A chart takes them for the series nothing else has colored -- a column palette colors first,
109
+ * and a card that says its own colors keeps them -- which is what makes these the default rather
110
+ * than the colors. A platform the report is not written for keeps Metabase's own palette.
111
+ *
112
+ * Said per card because the setting that colors every chart of an instance at once,
113
+ * `application-colors`, is a paid feature. An instance serves one platform anyway.
114
+ */
115
+ export declare const environmentColors: Map<string, string[]>;
116
+ /**
117
+ * The platform's colors, and after them the same ones lightened and darkened.
118
+ *
119
+ * A chart with more series than the platform has colors has to get them from somewhere: repeating
120
+ * one draws two takken as if they were one, and stopping after three leaves the rest of the legend in
121
+ * Metabase's palette, which reads as a chart drawn in two sets of colors. Shades of the three stay
122
+ * the platform's own.
123
+ */
124
+ export declare function chartColors(colors: string[], count?: number): string[];
125
+ export declare function buildVisualizationSettings(card: ReportCard, hasCoordinates?: boolean, env?: string): Record<string, unknown>;
126
+ /**
127
+ * The filters shown above the dashboard: every one that any tab asks for.
128
+ *
129
+ * Metabase puts filters above the whole dashboard rather than on a tab, so a filter named by one tab
130
+ * is visible on all of them. Which cards it actually reaches is decided per tab in `buildDashcards`,
131
+ * so the Eenheid filter cannot quietly turn the national figures into one unit's.
132
+ */
133
+ export declare function buildParameters(tabs: ReportTab[], filterCardIds: Map<string, number>, orderedValues?: Map<string, string[]>): Record<string, unknown>[];
134
+ /**
135
+ * The tabs, in the order the report lists them. A tab that is already there keeps its id so links
136
+ * into it survive; a new one gets a negative id, which is how Metabase is told to create it.
137
+ */
138
+ export declare function buildTabs(tabs: ReportTab[], existing: Map<string, number>): {
139
+ id: number;
140
+ name: string;
141
+ position: number;
142
+ }[];
143
+ /**
144
+ * Where each card of the report sits on the dashboard.
145
+ *
146
+ * `existing` holds the placed cards the dashboard already has, keyed by tab and card, so a card that
147
+ * is still there keeps the id it was placed under. Metabase addresses a card on a dashboard by that
148
+ * id: giving out new ones on every run leaves anyone with the dashboard open asking for placements
149
+ * that no longer exist, and every card on their screen answers 404 until they load the page again.
150
+ */
151
+ /** How a placed card is recognised between two runs: the same card on the same tab. */
152
+ export declare function dashcardKey(tabId: number | null | undefined, cardId: number | null): string;
153
+ export declare function buildDashcards(tabs: ReportTab[], cardIds: Map<string, number>, parameters: Record<string, unknown>[], tabIds: Map<string, number>, existing?: Map<string, number>): Record<string, unknown>[];
154
+ export type ReportSyncDashboard = {
155
+ name: string;
156
+ id: number;
157
+ /** The titles of the tabs it holds, in the order the report lists them. */
158
+ tabs: string[];
159
+ bookmarked: boolean;
160
+ };
161
+ export type ReportSyncResult = {
162
+ collection: string;
163
+ collectionId: number;
164
+ createdCollection: boolean;
165
+ /** The name the collection carried before this run renamed it, when it still had one. */
166
+ renamedCollection: string | undefined;
167
+ dashboards: ReportSyncDashboard[];
168
+ cards: number;
169
+ /** Map cards drawn as a bar chart because no postal code coordinates are loaded yet. */
170
+ mapsWithoutCoordinates: string[];
171
+ };
172
+ /**
173
+ * Where the first dashboard is pinned in its collection; the ones after it follow. Pinned because
174
+ * the dashboards are the only things in there worth opening directly -- everything else in the
175
+ * collection is a question one of them draws.
176
+ */
177
+ export declare const reportCollectionPosition = 1;
178
+ /**
179
+ * The dashboards to write and the tabs each of them holds, in the order the report lists them. A tab
180
+ * lands on the report's own dashboard unless it names one, which is what gives a tab that mirrors no
181
+ * page of the client's report -- the aanlevering to the department -- a dashboard of its own.
182
+ */
183
+ export declare function groupByDashboard(tabs: ReportTab[], dashboardName: string): {
184
+ name: string;
185
+ tabs: ReportTab[];
186
+ }[];
187
+ /**
188
+ * Write the whole report to Metabase: a dashboard with a tab per page, and one per tab that asked for
189
+ * its own. Cards first, because a dashboard can only point at cards that exist, and the filter
190
+ * dropdowns point at cards too.
191
+ *
192
+ * `env` is the platform being written, the same name the report was loaded for. It says which colors
193
+ * a chart falls back to; without it they are Metabase's.
194
+ */
195
+ export declare function syncReport(api: MetabaseApi, databaseId: number, tabs: ReportTab[], collection: string, dashboardName: string, hasCoordinates?: boolean, env?: string): Promise<ReportSyncResult>;
196
+ /**
197
+ * The collection to rename into the one written now: the one this wrote while collections were named
198
+ * per environment. Renaming keeps its id, and with it every question, dashboard, link and bookmark
199
+ * that points into it, where writing a new collection would leave all of that behind.
200
+ *
201
+ * Only when exactly one is left, which is every instance that serves one platform. A development
202
+ * machine that served several has no single right answer, so it gets a new collection and can throw
203
+ * the old ones away itself.
204
+ */
205
+ export declare function collectionToRename(collections: {
206
+ id: number;
207
+ name: string;
208
+ }[], name: string): {
209
+ id: number;
210
+ name: string;
211
+ } | undefined;
212
+ //# sourceMappingURL=sync-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-report.d.ts","sourceRoot":"","sources":["../src/sync-report.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEzE;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,YAAY,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,YAAY,EAKhD,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,GAAG,MAAM,CAEjE;AAkDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAA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