metabase-cli 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +291 -0
- package/dist/index.d.mts +408 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +735 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +675 -0
- package/dist/index.mjs.map +1 -0
- package/dist/metabase.js +1710 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
interface Profile {
|
|
2
|
+
name: string;
|
|
3
|
+
domain: string;
|
|
4
|
+
auth: SessionAuth | ApiKeyAuth;
|
|
5
|
+
user?: CachedUser;
|
|
6
|
+
defaultDb?: number;
|
|
7
|
+
}
|
|
8
|
+
interface SessionAuth {
|
|
9
|
+
method: "session";
|
|
10
|
+
email: string;
|
|
11
|
+
password: string;
|
|
12
|
+
sessionToken?: string;
|
|
13
|
+
}
|
|
14
|
+
interface ApiKeyAuth {
|
|
15
|
+
method: "api-key";
|
|
16
|
+
apiKey: string;
|
|
17
|
+
}
|
|
18
|
+
interface CachedUser {
|
|
19
|
+
id: number;
|
|
20
|
+
email: string;
|
|
21
|
+
first_name: string;
|
|
22
|
+
last_name: string;
|
|
23
|
+
is_superuser: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface Config {
|
|
26
|
+
activeProfile: string;
|
|
27
|
+
profiles: Record<string, Profile>;
|
|
28
|
+
}
|
|
29
|
+
interface SessionResponse {
|
|
30
|
+
id: string;
|
|
31
|
+
}
|
|
32
|
+
interface User {
|
|
33
|
+
id: number;
|
|
34
|
+
email: string;
|
|
35
|
+
first_name: string;
|
|
36
|
+
last_name: string;
|
|
37
|
+
is_superuser: boolean;
|
|
38
|
+
common_name: string;
|
|
39
|
+
locale: string | null;
|
|
40
|
+
is_active: boolean;
|
|
41
|
+
date_joined: string;
|
|
42
|
+
last_login: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
interface Database {
|
|
46
|
+
id: number;
|
|
47
|
+
name: string;
|
|
48
|
+
engine: string;
|
|
49
|
+
is_sample: boolean;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
interface Table {
|
|
53
|
+
id: number;
|
|
54
|
+
name: string;
|
|
55
|
+
display_name: string;
|
|
56
|
+
db_id: number;
|
|
57
|
+
schema: string;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
interface Field {
|
|
61
|
+
id: number;
|
|
62
|
+
name: string;
|
|
63
|
+
display_name: string;
|
|
64
|
+
table_id: number;
|
|
65
|
+
base_type: string;
|
|
66
|
+
semantic_type: string | null;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
interface Card {
|
|
70
|
+
id: number;
|
|
71
|
+
name: string;
|
|
72
|
+
description: string | null;
|
|
73
|
+
display: string;
|
|
74
|
+
collection_id: number | null;
|
|
75
|
+
creator_id: number;
|
|
76
|
+
dataset_query: DatasetQuery;
|
|
77
|
+
visualization_settings: Record<string, unknown>;
|
|
78
|
+
archived: boolean;
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
}
|
|
81
|
+
interface Dashboard {
|
|
82
|
+
id: number;
|
|
83
|
+
name: string;
|
|
84
|
+
description: string | null;
|
|
85
|
+
collection_id: number | null;
|
|
86
|
+
creator_id: number;
|
|
87
|
+
dashcards: DashCard[];
|
|
88
|
+
parameters: Parameter[];
|
|
89
|
+
archived: boolean;
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
interface DashCard {
|
|
93
|
+
id: number;
|
|
94
|
+
card_id: number | null;
|
|
95
|
+
card: Card | null;
|
|
96
|
+
row: number;
|
|
97
|
+
col: number;
|
|
98
|
+
size_x: number;
|
|
99
|
+
size_y: number;
|
|
100
|
+
parameter_mappings: unknown[];
|
|
101
|
+
visualization_settings: Record<string, unknown>;
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
}
|
|
104
|
+
interface Parameter {
|
|
105
|
+
id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
type: string;
|
|
108
|
+
slug: string;
|
|
109
|
+
default?: unknown;
|
|
110
|
+
[key: string]: unknown;
|
|
111
|
+
}
|
|
112
|
+
interface Collection {
|
|
113
|
+
id: number | "root";
|
|
114
|
+
name: string;
|
|
115
|
+
description: string | null;
|
|
116
|
+
parent_id: number | null;
|
|
117
|
+
archived: boolean;
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
interface Snippet {
|
|
121
|
+
id: number;
|
|
122
|
+
name: string;
|
|
123
|
+
description: string | null;
|
|
124
|
+
content: string;
|
|
125
|
+
creator_id: number;
|
|
126
|
+
archived: boolean;
|
|
127
|
+
collection_id: number | null;
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}
|
|
130
|
+
interface DatasetQuery {
|
|
131
|
+
type: "native" | "query";
|
|
132
|
+
database: number;
|
|
133
|
+
native?: {
|
|
134
|
+
query: string;
|
|
135
|
+
"template-tags"?: Record<string, unknown>;
|
|
136
|
+
};
|
|
137
|
+
query?: Record<string, unknown>;
|
|
138
|
+
}
|
|
139
|
+
interface DatasetResponse {
|
|
140
|
+
data: {
|
|
141
|
+
rows: unknown[][];
|
|
142
|
+
cols: DatasetColumn[];
|
|
143
|
+
results_metadata?: {
|
|
144
|
+
columns: DatasetColumn[];
|
|
145
|
+
};
|
|
146
|
+
native_form?: {
|
|
147
|
+
query: string;
|
|
148
|
+
};
|
|
149
|
+
rows_truncated?: number;
|
|
150
|
+
};
|
|
151
|
+
row_count: number;
|
|
152
|
+
status: string;
|
|
153
|
+
[key: string]: unknown;
|
|
154
|
+
}
|
|
155
|
+
interface DatasetColumn {
|
|
156
|
+
name: string;
|
|
157
|
+
display_name: string;
|
|
158
|
+
base_type: string;
|
|
159
|
+
semantic_type?: string | null;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
}
|
|
162
|
+
interface SearchResult {
|
|
163
|
+
id: number;
|
|
164
|
+
name: string;
|
|
165
|
+
model: string;
|
|
166
|
+
description: string | null;
|
|
167
|
+
collection_id: number | null;
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
}
|
|
170
|
+
interface PaginatedResponse<T> {
|
|
171
|
+
data: T[];
|
|
172
|
+
total: number;
|
|
173
|
+
limit: number;
|
|
174
|
+
offset: number;
|
|
175
|
+
}
|
|
176
|
+
type OutputFormat = "table" | "json" | "csv" | "tsv";
|
|
177
|
+
|
|
178
|
+
declare class MetabaseClient {
|
|
179
|
+
private domain;
|
|
180
|
+
private sessionToken?;
|
|
181
|
+
private apiKey?;
|
|
182
|
+
private profile;
|
|
183
|
+
constructor(profile: Profile);
|
|
184
|
+
private getHeaders;
|
|
185
|
+
private request;
|
|
186
|
+
get<T>(path: string, params?: Record<string, string>): Promise<T>;
|
|
187
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
188
|
+
put<T>(path: string, body?: unknown): Promise<T>;
|
|
189
|
+
delete<T>(path: string): Promise<T>;
|
|
190
|
+
requestFormExport(path: string, fields: Record<string, string>): Promise<Response>;
|
|
191
|
+
requestRaw(method: string, path: string, body?: unknown): Promise<Response>;
|
|
192
|
+
login(): Promise<SessionResponse>;
|
|
193
|
+
logout(): Promise<void>;
|
|
194
|
+
ensureAuthenticated(): Promise<void>;
|
|
195
|
+
getProfile(): Profile;
|
|
196
|
+
getUserId(): number | null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare class SafetyGuard {
|
|
200
|
+
private client;
|
|
201
|
+
private unsafe;
|
|
202
|
+
constructor(client: MetabaseClient, unsafe?: boolean);
|
|
203
|
+
checkOwnership(entityType: string, entityId: number): Promise<{
|
|
204
|
+
owned: boolean;
|
|
205
|
+
creatorId: number;
|
|
206
|
+
}>;
|
|
207
|
+
guard<T>(entityType: string, entityId: number, action: string, fn: () => Promise<T>): Promise<T>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare function loadConfig(): Config;
|
|
211
|
+
declare function saveConfig(config: Config): void;
|
|
212
|
+
declare function getActiveProfile(): Profile | null;
|
|
213
|
+
declare function setActiveProfile(name: string): void;
|
|
214
|
+
declare function addProfile(profile: Profile): void;
|
|
215
|
+
declare function removeProfile(name: string): void;
|
|
216
|
+
declare function updateProfile(name: string, updates: Partial<Profile>): void;
|
|
217
|
+
declare function listProfiles(): {
|
|
218
|
+
profiles: Profile[];
|
|
219
|
+
active: string;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
declare class SessionApi {
|
|
223
|
+
private client;
|
|
224
|
+
constructor(client: MetabaseClient);
|
|
225
|
+
getCurrentUser(): Promise<User>;
|
|
226
|
+
getSessionProperties(): Promise<Record<string, unknown>>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare class DatasetApi {
|
|
230
|
+
private client;
|
|
231
|
+
constructor(client: MetabaseClient);
|
|
232
|
+
query(datasetQuery: DatasetQuery): Promise<DatasetResponse>;
|
|
233
|
+
queryNative(database: number, sql: string, templateTags?: Record<string, unknown>): Promise<DatasetResponse>;
|
|
234
|
+
export(datasetQuery: DatasetQuery, format: "csv" | "json" | "xlsx"): Promise<string>;
|
|
235
|
+
exportBinary(datasetQuery: DatasetQuery, format: "csv" | "json" | "xlsx"): Promise<Buffer>;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
interface CreateCardParams {
|
|
239
|
+
name: string;
|
|
240
|
+
dataset_query: DatasetQuery;
|
|
241
|
+
display: string;
|
|
242
|
+
description?: string;
|
|
243
|
+
collection_id?: number;
|
|
244
|
+
visualization_settings?: Record<string, unknown>;
|
|
245
|
+
parameters?: unknown[];
|
|
246
|
+
}
|
|
247
|
+
interface UpdateCardParams {
|
|
248
|
+
name?: string;
|
|
249
|
+
description?: string;
|
|
250
|
+
parameters?: unknown[];
|
|
251
|
+
collection_id?: number;
|
|
252
|
+
dataset_query?: DatasetQuery;
|
|
253
|
+
display?: string;
|
|
254
|
+
visualization_settings?: Record<string, unknown>;
|
|
255
|
+
archived?: boolean;
|
|
256
|
+
}
|
|
257
|
+
declare class CardApi {
|
|
258
|
+
private client;
|
|
259
|
+
constructor(client: MetabaseClient);
|
|
260
|
+
list(params?: Record<string, string>): Promise<Card[]>;
|
|
261
|
+
get(id: number): Promise<Card>;
|
|
262
|
+
create(params: CreateCardParams): Promise<Card>;
|
|
263
|
+
update(id: number, params: UpdateCardParams): Promise<Card>;
|
|
264
|
+
delete(id: number): Promise<void>;
|
|
265
|
+
copy(id: number, overrides?: Partial<CreateCardParams>): Promise<Card>;
|
|
266
|
+
query(id: number, parameters?: unknown[]): Promise<DatasetResponse>;
|
|
267
|
+
queryExport(id: number, format: "csv" | "json" | "xlsx", parameters?: unknown[]): Promise<string>;
|
|
268
|
+
queryExportBinary(id: number, format: "csv" | "json" | "xlsx", parameters?: unknown[]): Promise<Buffer>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface CreateDashboardParams {
|
|
272
|
+
name: string;
|
|
273
|
+
description?: string;
|
|
274
|
+
collection_id?: number;
|
|
275
|
+
parameters?: unknown[];
|
|
276
|
+
}
|
|
277
|
+
interface UpdateDashboardParams {
|
|
278
|
+
name?: string;
|
|
279
|
+
description?: string;
|
|
280
|
+
collection_id?: number;
|
|
281
|
+
parameters?: unknown[];
|
|
282
|
+
dashcards?: unknown[];
|
|
283
|
+
archived?: boolean;
|
|
284
|
+
}
|
|
285
|
+
declare class DashboardApi {
|
|
286
|
+
private client;
|
|
287
|
+
constructor(client: MetabaseClient);
|
|
288
|
+
list(params?: Record<string, string>): Promise<Dashboard[]>;
|
|
289
|
+
get(id: number): Promise<Dashboard>;
|
|
290
|
+
create(params: CreateDashboardParams): Promise<Dashboard>;
|
|
291
|
+
update(id: number, params: UpdateDashboardParams): Promise<Dashboard>;
|
|
292
|
+
delete(id: number): Promise<void>;
|
|
293
|
+
copy(id: number, overrides?: Partial<CreateDashboardParams>): Promise<Dashboard>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
interface CreateCollectionParams {
|
|
297
|
+
name: string;
|
|
298
|
+
description?: string;
|
|
299
|
+
parent_id?: number;
|
|
300
|
+
}
|
|
301
|
+
interface UpdateCollectionParams {
|
|
302
|
+
name?: string;
|
|
303
|
+
description?: string;
|
|
304
|
+
parent_id?: number;
|
|
305
|
+
archived?: boolean;
|
|
306
|
+
}
|
|
307
|
+
interface CollectionItem {
|
|
308
|
+
id: number;
|
|
309
|
+
name: string;
|
|
310
|
+
model: string;
|
|
311
|
+
description: string | null;
|
|
312
|
+
[key: string]: unknown;
|
|
313
|
+
}
|
|
314
|
+
declare class CollectionApi {
|
|
315
|
+
private client;
|
|
316
|
+
constructor(client: MetabaseClient);
|
|
317
|
+
list(): Promise<Collection[]>;
|
|
318
|
+
tree(): Promise<Collection[]>;
|
|
319
|
+
get(id: number | "root"): Promise<Collection>;
|
|
320
|
+
items(id: number | "root", params?: Record<string, string>): Promise<{
|
|
321
|
+
data: CollectionItem[];
|
|
322
|
+
total: number;
|
|
323
|
+
}>;
|
|
324
|
+
create(params: CreateCollectionParams): Promise<Collection>;
|
|
325
|
+
update(id: number, params: UpdateCollectionParams): Promise<Collection>;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
declare class DatabaseApi {
|
|
329
|
+
private client;
|
|
330
|
+
constructor(client: MetabaseClient);
|
|
331
|
+
list(): Promise<{
|
|
332
|
+
data: Database[];
|
|
333
|
+
}>;
|
|
334
|
+
get(id: number): Promise<Database>;
|
|
335
|
+
metadata(id: number): Promise<Database & {
|
|
336
|
+
tables: Table[];
|
|
337
|
+
}>;
|
|
338
|
+
schemas(id: number): Promise<string[]>;
|
|
339
|
+
tablesInSchema(id: number, schema: string): Promise<Table[]>;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
declare class TableApi {
|
|
343
|
+
private client;
|
|
344
|
+
constructor(client: MetabaseClient);
|
|
345
|
+
get(id: number): Promise<Table>;
|
|
346
|
+
queryMetadata(id: number): Promise<Table & {
|
|
347
|
+
fields: Field[];
|
|
348
|
+
}>;
|
|
349
|
+
foreignKeys(id: number): Promise<unknown[]>;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
declare class FieldApi {
|
|
353
|
+
private client;
|
|
354
|
+
constructor(client: MetabaseClient);
|
|
355
|
+
get(id: number): Promise<Field>;
|
|
356
|
+
values(id: number): Promise<{
|
|
357
|
+
values: unknown[][];
|
|
358
|
+
}>;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface CreateSnippetParams {
|
|
362
|
+
name: string;
|
|
363
|
+
content: string;
|
|
364
|
+
description?: string;
|
|
365
|
+
collection_id?: number;
|
|
366
|
+
}
|
|
367
|
+
interface UpdateSnippetParams {
|
|
368
|
+
name?: string;
|
|
369
|
+
content?: string;
|
|
370
|
+
description?: string;
|
|
371
|
+
collection_id?: number;
|
|
372
|
+
archived?: boolean;
|
|
373
|
+
}
|
|
374
|
+
declare class SnippetApi {
|
|
375
|
+
private client;
|
|
376
|
+
constructor(client: MetabaseClient);
|
|
377
|
+
list(params?: Record<string, string>): Promise<Snippet[]>;
|
|
378
|
+
get(id: number): Promise<Snippet>;
|
|
379
|
+
create(params: CreateSnippetParams): Promise<Snippet>;
|
|
380
|
+
update(id: number, params: UpdateSnippetParams): Promise<Snippet>;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
declare class SearchApi {
|
|
384
|
+
private client;
|
|
385
|
+
constructor(client: MetabaseClient);
|
|
386
|
+
search(query: string, params?: {
|
|
387
|
+
models?: string[];
|
|
388
|
+
limit?: number;
|
|
389
|
+
offset?: number;
|
|
390
|
+
}): Promise<PaginatedResponse<SearchResult>>;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
declare class UserApi {
|
|
394
|
+
private client;
|
|
395
|
+
constructor(client: MetabaseClient);
|
|
396
|
+
list(params?: Record<string, string>): Promise<PaginatedResponse<User>>;
|
|
397
|
+
get(id: number): Promise<User>;
|
|
398
|
+
current(): Promise<User>;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
declare function formatDatasetResponse(dataset: DatasetResponse, format?: OutputFormat, columns?: string[]): string;
|
|
402
|
+
declare function formatJson(data: unknown): string;
|
|
403
|
+
declare function formatEntityTable(items: Record<string, unknown>[], columns: {
|
|
404
|
+
key: string;
|
|
405
|
+
header: string;
|
|
406
|
+
}[]): string;
|
|
407
|
+
|
|
408
|
+
export { type ApiKeyAuth, type CachedUser, type Card, CardApi, type Collection, CollectionApi, type Config, type DashCard, type Dashboard, DashboardApi, type Database, DatabaseApi, DatasetApi, type DatasetColumn, type DatasetQuery, type DatasetResponse, type Field, FieldApi, MetabaseClient, type OutputFormat, type PaginatedResponse, type Parameter, type Profile, SafetyGuard, SearchApi, type SearchResult, SessionApi, type SessionAuth, type SessionResponse, type Snippet, SnippetApi, type Table, TableApi, type User, UserApi, addProfile, formatDatasetResponse, formatEntityTable, formatJson, getActiveProfile, listProfiles, loadConfig, removeProfile, saveConfig, setActiveProfile, updateProfile };
|