@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/api.js ADDED
@@ -0,0 +1,334 @@
1
+ export class MetabaseApiError extends Error {
2
+ status;
3
+ constructor(message, status) {
4
+ super(message);
5
+ this.status = status;
6
+ this.name = 'MetabaseApiError';
7
+ }
8
+ }
9
+ /**
10
+ * Minimal client for the Metabase HTTP API, enough to complete the setup wizard and register the
11
+ * databases Metabase reports on. Metabase has no declarative provisioning in the open source
12
+ * edition (the config file is an enterprise feature), so this is the only way to automate it.
13
+ *
14
+ * Two ways to authenticate, because the two environments differ in what they can hold:
15
+ *
16
+ * - An admin account, which also completes the setup wizard. Used against a local Metabase, where
17
+ * the CLI creates that account itself and knows the password.
18
+ * - An `apiKey`, created by hand in Metabase (Admin > Settings > Authentication > API keys) and kept
19
+ * in 1Password. Used against a server, where nothing may hold a human's password and where the
20
+ * first account was made by a person.
21
+ */
22
+ export class MetabaseApi {
23
+ baseUrl;
24
+ session;
25
+ apiKey;
26
+ constructor(baseUrl, options = {}) {
27
+ this.baseUrl = baseUrl;
28
+ this.apiKey = options.apiKey;
29
+ }
30
+ /**
31
+ * Metabase hands out a setup token until the wizard completed, which is also the only way to
32
+ * create the very first user. Absent means someone already set this instance up.
33
+ */
34
+ async getSetupToken() {
35
+ const properties = await this.request('GET', '/api/session/properties');
36
+ return properties['setup-token'] ?? undefined;
37
+ }
38
+ /**
39
+ * Complete the setup wizard on a fresh instance and keep the session it returns.
40
+ */
41
+ async setup(token, admin) {
42
+ const result = await this.request('POST', '/api/setup', {
43
+ token,
44
+ user: {
45
+ first_name: admin.firstName,
46
+ last_name: admin.lastName,
47
+ email: admin.email,
48
+ password: admin.password,
49
+ site_name: 'Stamhoofd',
50
+ },
51
+ prefs: {
52
+ site_name: 'Stamhoofd',
53
+ site_locale: 'en',
54
+ allow_tracking: false,
55
+ },
56
+ });
57
+ this.session = result.id;
58
+ }
59
+ async login(admin) {
60
+ const result = await this.request('POST', '/api/session', {
61
+ username: admin.email,
62
+ password: admin.password,
63
+ });
64
+ this.session = result.id;
65
+ }
66
+ /**
67
+ * Set the wizard up when the instance is fresh, log in when it is not. Returns whether this
68
+ * call is what created the admin account.
69
+ */
70
+ async authenticate(admin) {
71
+ const token = await this.getSetupToken();
72
+ if (token !== undefined) {
73
+ await this.setup(token, admin);
74
+ return { created: true };
75
+ }
76
+ await this.login(admin);
77
+ return { created: false };
78
+ }
79
+ /** Who the current credentials belong to. */
80
+ async currentUser() {
81
+ return await this.request('GET', '/api/user/current');
82
+ }
83
+ /**
84
+ * Check that the api key is accepted and belongs to an admin, before anything is written.
85
+ *
86
+ * A key is created by hand and can be revoked or downgraded there, so without this a stale one
87
+ * surfaces as a 401 somewhere halfway through writing the report.
88
+ */
89
+ async verifyApiKey() {
90
+ if (this.apiKey === undefined) {
91
+ throw new Error('No api key was configured on this client');
92
+ }
93
+ let user;
94
+ try {
95
+ user = await this.currentUser();
96
+ }
97
+ catch (error) {
98
+ if (error instanceof MetabaseApiError && (error.status === 401 || error.status === 403)) {
99
+ throw new Error(`${this.baseUrl} rejected the api key. Create a new one under Admin > Settings > Authentication > API keys and update it in 1Password.`, { cause: error });
100
+ }
101
+ throw error;
102
+ }
103
+ if (!user.is_superuser) {
104
+ throw new Error(`The api key of ${this.baseUrl} belongs to ${user.email}, which is not an admin. Writing questions and dashboards needs a key in the Administrators group.`);
105
+ }
106
+ return user;
107
+ }
108
+ async listDatabases() {
109
+ const result = await this.request('GET', '/api/database');
110
+ return Array.isArray(result) ? result : result.data;
111
+ }
112
+ async findDatabaseByName(name) {
113
+ return (await this.listDatabases()).find(database => database.name === name);
114
+ }
115
+ /**
116
+ * The registered database to write questions against, which has to be there already.
117
+ *
118
+ * Deliberately not created here: on a server the data source holds credentials of its own and
119
+ * connects over SSL, so it is added once by hand and this only ever looks it up.
120
+ */
121
+ async requireDatabaseByName(name) {
122
+ const match = await this.findDatabaseByName(name);
123
+ if (!match) {
124
+ const known = (await this.listDatabases()).map(database => database.name);
125
+ throw new Error(`${this.baseUrl} has no data source named "${name}"${known.length > 0 ? `, only: ${known.join(', ')}` : ''}. Add it under Admin > Databases first.`);
126
+ }
127
+ return match;
128
+ }
129
+ /**
130
+ * Register `input` as a MySQL database unless a database with the same name is already
131
+ * registered. An existing one is left untouched, so changes made in the UI survive.
132
+ */
133
+ async ensureDatabase(input) {
134
+ const match = await this.findDatabaseByName(input.name);
135
+ if (match) {
136
+ return { id: match.id, created: false };
137
+ }
138
+ const created = await this.request('POST', '/api/database', {
139
+ name: input.name,
140
+ engine: 'mysql',
141
+ details: {
142
+ host: input.host,
143
+ port: input.port,
144
+ dbname: input.database,
145
+ user: input.user,
146
+ password: input.password,
147
+ ssl: false,
148
+ },
149
+ });
150
+ return { id: created.id, created: true };
151
+ }
152
+ /**
153
+ * Make Metabase re-read the tables of a database. It caches the schema it found when the data
154
+ * source was registered and only refreshes on its own schedule, so a database that was still
155
+ * empty at that moment keeps showing no tables long after the migrations created them.
156
+ */
157
+ async syncDatabaseSchema(id) {
158
+ await this.request('POST', `/api/database/${id}/sync_schema`);
159
+ }
160
+ /**
161
+ * Hide tables from the query builder and the data reference. Used for the schema-history table,
162
+ * which is part of the database but has nothing to report on.
163
+ *
164
+ * Metabase discovers tables in a background sync, so a table that was only just created may not
165
+ * be known yet; this waits a bounded time for it and otherwise leaves it for the next run rather
166
+ * than holding up the command.
167
+ */
168
+ async hideTables(databaseId, names, options = {}) {
169
+ const deadline = Date.now() + (options.timeoutMs ?? 30_000);
170
+ const hidden = [];
171
+ for (;;) {
172
+ const metadata = await this.request('GET', `/api/database/${databaseId}/metadata?include_hidden=true`);
173
+ const tables = (metadata.tables ?? []).filter(table => names.includes(table.name));
174
+ for (const table of tables.filter(table => table.visibility_type !== 'hidden')) {
175
+ await this.request('PUT', `/api/table/${table.id}`, { visibility_type: 'hidden' });
176
+ hidden.push(table.name);
177
+ }
178
+ if (tables.length === names.length || Date.now() >= deadline) {
179
+ return hidden;
180
+ }
181
+ await new Promise(resolve => setTimeout(resolve, 2_000));
182
+ }
183
+ }
184
+ /**
185
+ * Drop Metabase's demo database. Instances started before the image was told to skip it already
186
+ * have one, and it is only noise next to the platform statistics. Identified by the flag rather
187
+ * than by name, which is the only thing Metabase guarantees about it.
188
+ */
189
+ async removeSampleDatabase() {
190
+ const sample = (await this.listDatabases()).find(database => database.is_sample === true);
191
+ if (!sample) {
192
+ return { removed: false };
193
+ }
194
+ await this.request('DELETE', `/api/database/${sample.id}`);
195
+ return { removed: true };
196
+ }
197
+ async listCollections() {
198
+ const collections = await this.request('GET', '/api/collection');
199
+ return collections.filter(collection => collection.archived !== true);
200
+ }
201
+ /**
202
+ * The collection the report lives in, created if it is not there yet. Everything the CLI writes
203
+ * goes in one collection so it stays apart from whatever the client builds themselves.
204
+ */
205
+ async ensureCollection(name) {
206
+ const match = (await this.listCollections()).find(collection => collection.name === name);
207
+ if (match) {
208
+ return { id: match.id, created: false };
209
+ }
210
+ const created = await this.request('POST', '/api/collection', { name, parent_id: null });
211
+ return { id: created.id, created: true };
212
+ }
213
+ /**
214
+ * Rename a collection, keeping its id and everything in it. Used to bring a collection this
215
+ * wrote under an earlier name along rather than leaving it beside a new one.
216
+ */
217
+ async renameCollection(id, name) {
218
+ await this.request('PUT', `/api/collection/${id}`, { name });
219
+ }
220
+ async listCards(collectionId) {
221
+ const items = await this.request('GET', `/api/collection/${collectionId}/items?models=card`);
222
+ return (items.data ?? []).map(item => ({ id: item.id, name: item.name }));
223
+ }
224
+ async listDashboards(collectionId) {
225
+ const items = await this.request('GET', `/api/collection/${collectionId}/items?models=dashboard`);
226
+ return (items.data ?? []).map(item => ({ id: item.id, name: item.name }));
227
+ }
228
+ /**
229
+ * Write a native question. Updating an existing card rather than replacing it keeps its id, and
230
+ * with it every dashboard that points at it and every link the client saved.
231
+ */
232
+ async saveCard(input, existingId) {
233
+ const body = {
234
+ name: input.name,
235
+ description: input.description ?? null,
236
+ display: input.display,
237
+ visualization_settings: input.visualizationSettings,
238
+ collection_id: input.collectionId,
239
+ dataset_query: {
240
+ type: 'native',
241
+ database: input.databaseId,
242
+ native: { query: input.query, 'template-tags': input.templateTags },
243
+ },
244
+ };
245
+ if (existingId !== undefined) {
246
+ await this.request('PUT', `/api/card/${existingId}`, body);
247
+ return existingId;
248
+ }
249
+ return (await this.request('POST', '/api/card', body)).id;
250
+ }
251
+ /**
252
+ * Run a saved question and return the values of its first column. Used to read the values a
253
+ * filter offers straight out of the database Metabase is already connected to, so the CLI needs
254
+ * no database connection of its own.
255
+ */
256
+ async runCardValues(cardId) {
257
+ const result = await this.request('POST', `/api/card/${cardId}/query`);
258
+ return (result.data?.rows ?? [])
259
+ .map(row => row[0])
260
+ .filter((value) => typeof value === 'string' && value.length > 0);
261
+ }
262
+ async createDashboard(name, description, collectionId) {
263
+ const created = await this.request('POST', '/api/dashboard', {
264
+ name,
265
+ description: description ?? null,
266
+ collection_id: collectionId,
267
+ });
268
+ return created.id;
269
+ }
270
+ /** The tabs and cards a dashboard already has, so writing it again can keep their ids. */
271
+ async getDashboardLayout(id) {
272
+ const dashboard = await this.request('GET', `/api/dashboard/${id}`);
273
+ return {
274
+ tabs: dashboard.tabs ?? [],
275
+ cards: (dashboard.dashcards ?? []).map(dashcard => ({ id: dashcard.id, cardId: dashcard.card_id, tabId: dashcard.dashboard_tab_id })),
276
+ };
277
+ }
278
+ /**
279
+ * Lay out a dashboard: its tabs, its filters and which card sits where. Metabase replaces the
280
+ * whole set of tabs and cards with what is sent, so this is also what removes a card the report
281
+ * no longer has.
282
+ */
283
+ async updateDashboard(id, body) {
284
+ await this.request('PUT', `/api/dashboard/${id}`, {
285
+ name: body.name,
286
+ description: body.description ?? null,
287
+ parameters: body.parameters,
288
+ tabs: body.tabs,
289
+ dashcards: body.dashcards,
290
+ // A position is what pins an item to the top of its collection; null leaves it unpinned.
291
+ collection_position: body.collectionPosition ?? null,
292
+ });
293
+ }
294
+ /**
295
+ * Bookmark the dashboard, so it shows up under "Bookmarks" in the sidebar.
296
+ *
297
+ * A bookmark belongs to one account — the one the CLI signs in as — so this does nothing for
298
+ * anyone else who opens Metabase. Bookmarking twice is an error, hence the check first.
299
+ */
300
+ async bookmarkDashboard(id) {
301
+ const bookmarks = await this.request('GET', '/api/bookmark');
302
+ if (bookmarks.some(bookmark => bookmark.type === 'dashboard' && bookmark.item_id === id)) {
303
+ return { created: false };
304
+ }
305
+ await this.request('POST', `/api/bookmark/dashboard/${id}`);
306
+ return { created: true };
307
+ }
308
+ /** Move a question to the trash. */
309
+ async archiveCard(id) {
310
+ await this.request('PUT', `/api/card/${id}`, { archived: true });
311
+ }
312
+ /** Move a dashboard to the trash. Used to clear away the one-dashboard-per-page layout. */
313
+ async archiveDashboard(id) {
314
+ await this.request('PUT', `/api/dashboard/${id}`, { archived: true });
315
+ }
316
+ async request(method, path, body) {
317
+ const response = await fetch(`${this.baseUrl}${path}`, {
318
+ method,
319
+ headers: {
320
+ 'Content-Type': 'application/json',
321
+ ...(this.apiKey ? { 'x-api-key': this.apiKey } : {}),
322
+ ...(this.session ? { 'X-Metabase-Session': this.session } : {}),
323
+ },
324
+ body: body === undefined ? undefined : JSON.stringify(body),
325
+ signal: AbortSignal.timeout(60_000),
326
+ });
327
+ const text = await response.text();
328
+ if (!response.ok) {
329
+ throw new MetabaseApiError(`${method} ${path} failed with status ${response.status}: ${text.slice(0, 200)}`, response.status);
330
+ }
331
+ return (text.length === 0 ? undefined : JSON.parse(text));
332
+ }
333
+ }
334
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AA+DA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACD;IAAtC,YAAY,OAAe,EAAW,MAAc;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,WAAM,GAAN,MAAM,CAAQ;QAEhD,IAAI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EAAE,EAAE;YACnD,MAAM;YACN,OAAO,EAAE;gBACL,cAAc,EAAE,kBAAkB;gBAClC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAClE;YACD,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC3D,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;SACtC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,gBAAgB,CAAC,GAAG,MAAM,IAAI,IAAI,uBAAuB,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClI,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAM,CAAC;IACnE,CAAC;CACJ"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What the report is called inside Metabase. Shared by every caller so a dashboard written locally
3
+ * and one written to a server end up under the same names, and running either again updates in
4
+ * place instead of adding a second copy.
5
+ */
6
+ /**
7
+ * The name a platform statistics database is registered under in Metabase. One Metabase can serve
8
+ * several environments, so the environment has to be visible in the name.
9
+ */
10
+ export declare function metabaseDataSourceName(env: string): string;
11
+ /**
12
+ * The collection the ledenstatistieken dashboards live in.
13
+ *
14
+ * One collection, whichever platform it counts. A local Metabase holds several environments' data
15
+ * sources but shows one report: writing the report of an environment points the questions in here at
16
+ * its data source, so the collection always holds the platform that was written last. A server holds
17
+ * one platform and never sees the difference.
18
+ */
19
+ export declare const metabaseReportCollectionName = "Statistieken";
20
+ /**
21
+ * The dashboard a tab lands on unless it names one of its own: one tab per page of the client's own
22
+ * report.
23
+ */
24
+ export declare const metabaseReportDashboardName = "Ledenstatistieken";
25
+ /**
26
+ * Whether a name is the one the collection carried while there was one per environment
27
+ * (`Ledenstatistieken (keeo)`). Recognised so that collection can be renamed into the one written
28
+ * now instead of being left beside it.
29
+ */
30
+ export declare function isLegacyReportCollectionName(name: string): boolean;
31
+ /**
32
+ * Tables of the statistics database that are infrastructure rather than data. They are hidden in
33
+ * Metabase so they stay out of the query builder and the data reference.
34
+ */
35
+ export declare const metabaseHiddenTables: string[];
36
+ //# sourceMappingURL=naming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1D;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,iBAAiB,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,2BAA2B,sBAAa,CAAC;AAItD;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElE;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAiB,CAAC"}
package/dist/naming.js ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * What the report is called inside Metabase. Shared by every caller so a dashboard written locally
3
+ * and one written to a server end up under the same names, and running either again updates in
4
+ * place instead of adding a second copy.
5
+ */
6
+ /**
7
+ * The name a platform statistics database is registered under in Metabase. One Metabase can serve
8
+ * several environments, so the environment has to be visible in the name.
9
+ */
10
+ export function metabaseDataSourceName(env) {
11
+ return `Platform statistics (${env})`;
12
+ }
13
+ const reportName = 'Ledenstatistieken';
14
+ /**
15
+ * The collection the ledenstatistieken dashboards live in.
16
+ *
17
+ * One collection, whichever platform it counts. A local Metabase holds several environments' data
18
+ * sources but shows one report: writing the report of an environment points the questions in here at
19
+ * its data source, so the collection always holds the platform that was written last. A server holds
20
+ * one platform and never sees the difference.
21
+ */
22
+ export const metabaseReportCollectionName = 'Statistieken';
23
+ /**
24
+ * The dashboard a tab lands on unless it names one of its own: one tab per page of the client's own
25
+ * report.
26
+ */
27
+ export const metabaseReportDashboardName = reportName;
28
+ const legacyReportCollectionPattern = new RegExp(`^${reportName} \\([^()]+\\)$`);
29
+ /**
30
+ * Whether a name is the one the collection carried while there was one per environment
31
+ * (`Ledenstatistieken (keeo)`). Recognised so that collection can be renamed into the one written
32
+ * now instead of being left beside it.
33
+ */
34
+ export function isLegacyReportCollectionName(name) {
35
+ return legacyReportCollectionPattern.test(name);
36
+ }
37
+ /**
38
+ * Tables of the statistics database that are infrastructure rather than data. They are hidden in
39
+ * Metabase so they stay out of the query builder and the data reference.
40
+ */
41
+ export const metabaseHiddenTables = ['migrations'];
42
+ //# sourceMappingURL=naming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming.js","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAW;IAC9C,OAAO,wBAAwB,GAAG,GAAG,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC;AAEtD,MAAM,6BAA6B,GAAG,IAAI,MAAM,CAAC,IAAI,UAAU,gBAAgB,CAAC,CAAC;AAEjF;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAAY;IACrD,OAAO,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The report the client's own tool produces, expressed as queries on the statistics database.
3
+ *
4
+ * The definitions are plain `.sql` files, read and checked for shape without ever being run: the
5
+ * schema they query belongs to the statistics syncer, which this package does not depend on. Turning
6
+ * them into Metabase questions is `sync-report.ts` — nothing here knows Metabase exists.
7
+ *
8
+ * A file holds one tab of the report and its cards, mirroring a page of the client's own report:
9
+ *
10
+ * -- @tab nationaal
11
+ * -- title: Nationaal
12
+ *
13
+ * -- @card totaal-leden
14
+ * -- title: Totaal leden
15
+ * -- display: scalar
16
+ * -- @include facts
17
+ * SELECT COUNT(DISTINCT member_id) AS `Totaal leden` FROM facts
18
+ *
19
+ * `@include <name>` is replaced by `includes/<name>.sql`, which is how every card counts members the
20
+ * same way, and a fragment may include another. `{{name}}` marks a query parameter, the same syntax
21
+ * Metabase uses, and `[[...]]` around a clause drops it when that parameter is empty. A parameter
22
+ * several values can be chosen for is written `IN ({{name}})`, since Metabase replaces it with all of
23
+ * them, comma separated.
24
+ *
25
+ * The same report is written for every platform, which do not all count the same thing the same way.
26
+ * Where they differ, the environment says which variant a card gets: `includes/<env>/<name>.sql`
27
+ * replaces the fragment of that name, and a setting written `-- description@<env>:` replaces the
28
+ * unqualified one. Neither is visible to a card, which keeps saying `@include gtp`.
29
+ */
30
+ export type ReportCard = {
31
+ key: string;
32
+ title: string;
33
+ /** How Metabase should draw it: scalar, bar, line, pie, table, combo, gauge, row, map. */
34
+ display: string;
35
+ /** For a map, the columns holding the coordinates of each point. */
36
+ latitude?: string;
37
+ longitude?: string;
38
+ /** Width on the dashboard: full, two-thirds, half, third, quarter or sixth of a row. */
39
+ size: ReportCardSize;
40
+ /**
41
+ * How tall the card is drawn, in rows of the dashboard grid -- the unit the layout counts in.
42
+ * Absent takes the height its display asks for, which is what nearly every card does; a chart
43
+ * that has to be read closely says its own.
44
+ */
45
+ height?: number;
46
+ /**
47
+ * How many rows of cards this one stands across. `1` unless it says otherwise: a card spanning
48
+ * two stands beside the two cards stacked next to it and is as tall as both of those rows
49
+ * together, which is how the netwerk map keeps the height of the chart and the pie beside it.
50
+ */
51
+ span: number;
52
+ description?: string;
53
+ /** Columns to group by, for the chart displays. */
54
+ dimensions: string[];
55
+ /** Columns to plot, for the chart displays. */
56
+ metrics: string[];
57
+ /**
58
+ * The headers a table has to be exported under, in order. Named here because a card that is
59
+ * downloaded rather than read on screen has an agreed structure to keep: Metabase writes the
60
+ * header of an export from the column's title, and a title it was not given is whatever it makes
61
+ * of the alias.
62
+ */
63
+ columns: string[];
64
+ /** How bars are stacked: absent, `stacked` or `normalized`. */
65
+ stacked?: 'stacked' | 'normalized';
66
+ /**
67
+ * The boundaries the figure is read in, lowest first: `0, 35, 55, 75, 95, 115, 135` makes six
68
+ * ranges. A gauge draws them as its arc and a number is colored by the one it falls in, which is
69
+ * how the two cards of one figure say the same thing. The outer two are where the arc starts and
70
+ * stops rather than a figure anything is measured against, since the figure itself has no ends.
71
+ * Absent leaves a gauge to Metabase, which splits the arc in three, and a number uncolored.
72
+ */
73
+ segments: number[];
74
+ /**
75
+ * Which end of those ranges is the good one, and therefore which of them is green: `high` unless
76
+ * the card says otherwise. The omkaderingscijfer is the one that reads the other way round --
77
+ * the fewer leden a leider has to look after, the better.
78
+ */
79
+ best: ReportCardBest;
80
+ /**
81
+ * How the labels along the x-axis are drawn. Absent lets the chart decide, which drops them
82
+ * entirely when too many do not fit -- an eenheid or tak chart needs a rotation to keep them.
83
+ */
84
+ xLabels?: ReportCardXLabels;
85
+ /** Parameters the query takes, read from the `{{...}}` in the sql. */
86
+ parameters: string[];
87
+ sql: string;
88
+ };
89
+ export type ReportTab = {
90
+ key: string;
91
+ title: string;
92
+ description?: string;
93
+ /**
94
+ * The dashboard this tab belongs to. Absent puts it on the report's own dashboard, beside the
95
+ * pages it mirrors. A tab that is not part of the client's report names one of its own, which is
96
+ * written as a separate dashboard in the same collection.
97
+ */
98
+ dashboard?: string;
99
+ /**
100
+ * The filters that drive this tab. Declared rather than taken from the cards: the shared query
101
+ * fragments offer both filters to every card, so a tab that only wants one has to say so.
102
+ *
103
+ * Metabase shows filters above the whole dashboard rather than per tab, so every filter named by
104
+ * any tab is visible everywhere; this is what decides which cards it actually reaches.
105
+ */
106
+ filters: string[];
107
+ /** Cards that only feed the filter dropdowns. They live in the collection but on no tab. */
108
+ hidden: boolean;
109
+ cards: ReportCard[];
110
+ };
111
+ export declare const reportCardSizes: readonly ["full", "two-thirds", "half", "third", "quarter", "sixth"];
112
+ export type ReportCardSize = typeof reportCardSizes[number];
113
+ export declare const reportCardXLabels: readonly ["show", "hide", "compact", "rotate-45", "rotate-90"];
114
+ export type ReportCardXLabels = typeof reportCardXLabels[number];
115
+ export declare const reportCardBest: readonly ["low", "high"];
116
+ export type ReportCardBest = typeof reportCardBest[number];
117
+ /** The order the tabs are written in: the pages of the client's report first, then what is not one. */
118
+ export declare const reportTabOrder: string[];
119
+ export declare function getReportDirectory(): string;
120
+ /**
121
+ * The report as one environment counts it.
122
+ *
123
+ * Not every figure is counted the same everywhere -- the GTP index weighs takken for keeo and ages
124
+ * for ravot -- and a statistics database holds one platform, so which variant a card gets is decided
125
+ * here rather than in the queries. `env` is the same name the data source carries.
126
+ */
127
+ export declare function loadReport(env: string, directory?: string): Promise<ReportTab[]>;
128
+ /**
129
+ * Splits a file into its `@tab` header and `@card` sections. Everything that is not a directive
130
+ * stays as it is, so a card's sql keeps the comments written above it.
131
+ */
132
+ export declare function parseTab(contents: string, file: string, includes: Map<string, string>, env?: string): ReportTab;
133
+ /** The `{{name}}` parameters a query uses, in the order they first appear. */
134
+ export declare function parameterNames(sql: string): string[];
135
+ /**
136
+ * The sql as it runs outside Metabase: parameters resolved and the `[[...]]` clauses around them
137
+ * kept or dropped. Used by the tests to run a card against a real database, since Metabase is the
138
+ * only thing that understands this syntax.
139
+ */
140
+ export declare function resolveSql(sql: string, values?: Record<string, string | null>): string;
141
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAM,MAAM,UAAU,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wFAAwF;IACxF,IAAI,EAAE,cAAc,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;OAKG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,+DAA+D;IAC/D,OAAO,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,IAAI,EAAE,cAAc,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,sEAAsE;IACtE,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;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