@databricks/sdk-lakeview 0.0.0-dev → 0.1.0-dev.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.
@@ -0,0 +1,800 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import type {Call} from '@databricks/sdk-core/api';
5
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
6
+ import type {Logger} from '@databricks/sdk-core/logger';
7
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
8
+ import type {CallOptions} from '@databricks/sdk-options/call';
9
+ import type {ClientOptions} from '@databricks/sdk-options/client';
10
+ import type {HttpClient} from '@databricks/sdk-core/http';
11
+ import {newHttpClient} from './transport';
12
+ import {
13
+ buildHttpRequest,
14
+ executeCall,
15
+ executeHttpCall,
16
+ marshalRequest,
17
+ parseResponse,
18
+ } from './utils';
19
+ import pkgJson from '../../package.json' with {type: 'json'};
20
+ import type {
21
+ CreateDashboardRequest,
22
+ CreateScheduleRequest,
23
+ CreateSubscriptionRequest,
24
+ Dashboard,
25
+ DeleteScheduleRequest,
26
+ DeleteSubscriptionRequest,
27
+ GetDashboardRequest,
28
+ GetPublishedDashboardRequest,
29
+ GetPublishedDashboardTokenInfoRequest,
30
+ GetPublishedDashboardTokenInfoResponse,
31
+ GetScheduleRequest,
32
+ GetSubscriptionRequest,
33
+ ListDashboardsRequest,
34
+ ListDashboardsResponse,
35
+ ListSchedulesRequest,
36
+ ListSchedulesResponse,
37
+ ListSubscriptionsRequest,
38
+ ListSubscriptionsResponse,
39
+ MigrateDashboardRequest,
40
+ PublishDashboardRequest,
41
+ PublishedDashboard,
42
+ RevertDashboardRequest,
43
+ RevertDashboardResponse,
44
+ Schedule,
45
+ Subscription,
46
+ TrashDashboardRequest,
47
+ TrashDashboardResponse,
48
+ UnpublishDashboardRequest,
49
+ UnpublishDashboardResponse,
50
+ UpdateDashboardRequest,
51
+ UpdateScheduleRequest,
52
+ } from './model';
53
+ import {
54
+ marshalDashboardSchema,
55
+ marshalMigrateDashboardRequestSchema,
56
+ marshalPublishDashboardRequestSchema,
57
+ marshalRevertDashboardRequestSchema,
58
+ marshalScheduleSchema,
59
+ marshalSubscriptionSchema,
60
+ unmarshalDashboardSchema,
61
+ unmarshalGetPublishedDashboardTokenInfoResponseSchema,
62
+ unmarshalListDashboardsResponseSchema,
63
+ unmarshalListSchedulesResponseSchema,
64
+ unmarshalListSubscriptionsResponseSchema,
65
+ unmarshalPublishedDashboardSchema,
66
+ unmarshalRevertDashboardResponseSchema,
67
+ unmarshalScheduleSchema,
68
+ unmarshalSubscriptionSchema,
69
+ unmarshalTrashDashboardResponseSchema,
70
+ unmarshalUnpublishDashboardResponseSchema,
71
+ } from './model';
72
+
73
+ // Package identity segment for this client to be used in the User-Agent header.
74
+ const PACKAGE_SEGMENT = {
75
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
76
+ value: pkgJson.version,
77
+ };
78
+
79
+ export class LakeviewClient {
80
+ private readonly host: string;
81
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
82
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
83
+ // request.
84
+ private readonly workspaceId: string | undefined;
85
+ private readonly httpClient: HttpClient;
86
+ private readonly logger: Logger;
87
+ // User-Agent header value. Composed once at construction from
88
+ // createDefault() merged with this package's identity and the active
89
+ // credential's name.
90
+ private readonly userAgent: string;
91
+
92
+ constructor(options: ClientOptions) {
93
+ if (options.host === undefined) {
94
+ throw new Error('Host is required.');
95
+ }
96
+ this.host = options.host.replace(/\/$/, '');
97
+ this.workspaceId = options.workspaceId;
98
+ this.logger = options.logger ?? new NoOpLogger();
99
+ const info = createDefault()
100
+ .with(PACKAGE_SEGMENT)
101
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
102
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
103
+ this.userAgent = info.toString();
104
+ this.httpClient = newHttpClient(options);
105
+ }
106
+
107
+ /** Create a draft dashboard. */
108
+ async createDashboard(
109
+ req: CreateDashboardRequest,
110
+ options?: CallOptions
111
+ ): Promise<Dashboard> {
112
+ const url = `${this.host}/api/2.0/lakeview/dashboards`;
113
+ const params = new URLSearchParams();
114
+ if (req.datasetCatalog !== undefined) {
115
+ params.append('dataset_catalog', req.datasetCatalog);
116
+ }
117
+ if (req.datasetSchema !== undefined) {
118
+ params.append('dataset_schema', req.datasetSchema);
119
+ }
120
+ const query = params.toString();
121
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
122
+ const body = marshalRequest(req.dashboard, marshalDashboardSchema);
123
+ let resp: Dashboard | undefined;
124
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
125
+ const headers = new Headers({'Content-Type': 'application/json'});
126
+ if (this.workspaceId !== undefined) {
127
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
128
+ }
129
+ headers.set('User-Agent', this.userAgent);
130
+ const httpReq = buildHttpRequest(
131
+ 'POST',
132
+ fullUrl,
133
+ headers,
134
+ callSignal,
135
+ body
136
+ );
137
+ const respBody = await executeHttpCall({
138
+ request: httpReq,
139
+ httpClient: this.httpClient,
140
+ logger: this.logger,
141
+ });
142
+ resp = parseResponse(respBody, unmarshalDashboardSchema);
143
+ };
144
+ await executeCall(call, options);
145
+ if (resp === undefined) {
146
+ throw new Error('API call completed without a result.');
147
+ }
148
+ return resp;
149
+ }
150
+
151
+ /** Create dashboard schedule. */
152
+ async createSchedule(
153
+ req: CreateScheduleRequest,
154
+ options?: CallOptions
155
+ ): Promise<Schedule> {
156
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.schedule?.dashboardId ?? ''}/schedules`;
157
+ const body = marshalRequest(req.schedule, marshalScheduleSchema);
158
+ let resp: Schedule | undefined;
159
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
160
+ const headers = new Headers({'Content-Type': 'application/json'});
161
+ if (this.workspaceId !== undefined) {
162
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
163
+ }
164
+ headers.set('User-Agent', this.userAgent);
165
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
166
+ const respBody = await executeHttpCall({
167
+ request: httpReq,
168
+ httpClient: this.httpClient,
169
+ logger: this.logger,
170
+ });
171
+ resp = parseResponse(respBody, unmarshalScheduleSchema);
172
+ };
173
+ await executeCall(call, options);
174
+ if (resp === undefined) {
175
+ throw new Error('API call completed without a result.');
176
+ }
177
+ return resp;
178
+ }
179
+
180
+ /** Create schedule subscription. */
181
+ async createSubscription(
182
+ req: CreateSubscriptionRequest,
183
+ options?: CallOptions
184
+ ): Promise<Subscription> {
185
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.subscription?.dashboardId ?? ''}/schedules/${req.subscription?.scheduleId ?? ''}/subscriptions`;
186
+ const body = marshalRequest(req.subscription, marshalSubscriptionSchema);
187
+ let resp: Subscription | undefined;
188
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
189
+ const headers = new Headers({'Content-Type': 'application/json'});
190
+ if (this.workspaceId !== undefined) {
191
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
192
+ }
193
+ headers.set('User-Agent', this.userAgent);
194
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
195
+ const respBody = await executeHttpCall({
196
+ request: httpReq,
197
+ httpClient: this.httpClient,
198
+ logger: this.logger,
199
+ });
200
+ resp = parseResponse(respBody, unmarshalSubscriptionSchema);
201
+ };
202
+ await executeCall(call, options);
203
+ if (resp === undefined) {
204
+ throw new Error('API call completed without a result.');
205
+ }
206
+ return resp;
207
+ }
208
+
209
+ /** Delete dashboard schedule. */
210
+ async deleteSchedule(
211
+ req: DeleteScheduleRequest,
212
+ options?: CallOptions
213
+ ): Promise<void> {
214
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/schedules/${req.scheduleId ?? ''}`;
215
+ const params = new URLSearchParams();
216
+ if (req.etag !== undefined) {
217
+ params.append('etag', req.etag);
218
+ }
219
+ const query = params.toString();
220
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
221
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
222
+ const headers = new Headers();
223
+ if (this.workspaceId !== undefined) {
224
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
225
+ }
226
+ headers.set('User-Agent', this.userAgent);
227
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
228
+ await executeHttpCall({
229
+ request: httpReq,
230
+ httpClient: this.httpClient,
231
+ logger: this.logger,
232
+ });
233
+ };
234
+ await executeCall(call, options);
235
+ }
236
+
237
+ /** Delete schedule subscription. */
238
+ async deleteSubscription(
239
+ req: DeleteSubscriptionRequest,
240
+ options?: CallOptions
241
+ ): Promise<void> {
242
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/schedules/${req.scheduleId ?? ''}/subscriptions/${req.subscriptionId ?? ''}`;
243
+ const params = new URLSearchParams();
244
+ if (req.etag !== undefined) {
245
+ params.append('etag', req.etag);
246
+ }
247
+ const query = params.toString();
248
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
249
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
250
+ const headers = new Headers();
251
+ if (this.workspaceId !== undefined) {
252
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
253
+ }
254
+ headers.set('User-Agent', this.userAgent);
255
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
256
+ await executeHttpCall({
257
+ request: httpReq,
258
+ httpClient: this.httpClient,
259
+ logger: this.logger,
260
+ });
261
+ };
262
+ await executeCall(call, options);
263
+ }
264
+
265
+ /** Get a draft dashboard. */
266
+ async getDashboard(
267
+ req: GetDashboardRequest,
268
+ options?: CallOptions
269
+ ): Promise<Dashboard> {
270
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}`;
271
+ let resp: Dashboard | undefined;
272
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
273
+ const headers = new Headers();
274
+ if (this.workspaceId !== undefined) {
275
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
276
+ }
277
+ headers.set('User-Agent', this.userAgent);
278
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
279
+ const respBody = await executeHttpCall({
280
+ request: httpReq,
281
+ httpClient: this.httpClient,
282
+ logger: this.logger,
283
+ });
284
+ resp = parseResponse(respBody, unmarshalDashboardSchema);
285
+ };
286
+ await executeCall(call, options);
287
+ if (resp === undefined) {
288
+ throw new Error('API call completed without a result.');
289
+ }
290
+ return resp;
291
+ }
292
+
293
+ /** Get the current published dashboard. */
294
+ async getPublishedDashboard(
295
+ req: GetPublishedDashboardRequest,
296
+ options?: CallOptions
297
+ ): Promise<PublishedDashboard> {
298
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/published`;
299
+ let resp: PublishedDashboard | undefined;
300
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
301
+ const headers = new Headers();
302
+ if (this.workspaceId !== undefined) {
303
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
304
+ }
305
+ headers.set('User-Agent', this.userAgent);
306
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
307
+ const respBody = await executeHttpCall({
308
+ request: httpReq,
309
+ httpClient: this.httpClient,
310
+ logger: this.logger,
311
+ });
312
+ resp = parseResponse(respBody, unmarshalPublishedDashboardSchema);
313
+ };
314
+ await executeCall(call, options);
315
+ if (resp === undefined) {
316
+ throw new Error('API call completed without a result.');
317
+ }
318
+ return resp;
319
+ }
320
+
321
+ /** Get a required authorization details and scopes of a published dashboard to mint an OAuth token. */
322
+ async getPublishedDashboardTokenInfo(
323
+ req: GetPublishedDashboardTokenInfoRequest,
324
+ options?: CallOptions
325
+ ): Promise<GetPublishedDashboardTokenInfoResponse> {
326
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/published/tokeninfo`;
327
+ const params = new URLSearchParams();
328
+ if (req.externalValue !== undefined) {
329
+ params.append('external_value', req.externalValue);
330
+ }
331
+ if (req.externalViewerId !== undefined) {
332
+ params.append('external_viewer_id', req.externalViewerId);
333
+ }
334
+ const query = params.toString();
335
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
336
+ let resp: GetPublishedDashboardTokenInfoResponse | undefined;
337
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
338
+ const headers = new Headers();
339
+ if (this.workspaceId !== undefined) {
340
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
341
+ }
342
+ headers.set('User-Agent', this.userAgent);
343
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
344
+ const respBody = await executeHttpCall({
345
+ request: httpReq,
346
+ httpClient: this.httpClient,
347
+ logger: this.logger,
348
+ });
349
+ resp = parseResponse(
350
+ respBody,
351
+ unmarshalGetPublishedDashboardTokenInfoResponseSchema
352
+ );
353
+ };
354
+ await executeCall(call, options);
355
+ if (resp === undefined) {
356
+ throw new Error('API call completed without a result.');
357
+ }
358
+ return resp;
359
+ }
360
+
361
+ /** Get dashboard schedule. */
362
+ async getSchedule(
363
+ req: GetScheduleRequest,
364
+ options?: CallOptions
365
+ ): Promise<Schedule> {
366
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/schedules/${req.scheduleId ?? ''}`;
367
+ let resp: Schedule | undefined;
368
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
369
+ const headers = new Headers();
370
+ if (this.workspaceId !== undefined) {
371
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
372
+ }
373
+ headers.set('User-Agent', this.userAgent);
374
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
375
+ const respBody = await executeHttpCall({
376
+ request: httpReq,
377
+ httpClient: this.httpClient,
378
+ logger: this.logger,
379
+ });
380
+ resp = parseResponse(respBody, unmarshalScheduleSchema);
381
+ };
382
+ await executeCall(call, options);
383
+ if (resp === undefined) {
384
+ throw new Error('API call completed without a result.');
385
+ }
386
+ return resp;
387
+ }
388
+
389
+ /** Get schedule subscription. */
390
+ async getSubscription(
391
+ req: GetSubscriptionRequest,
392
+ options?: CallOptions
393
+ ): Promise<Subscription> {
394
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/schedules/${req.scheduleId ?? ''}/subscriptions/${req.subscriptionId ?? ''}`;
395
+ let resp: Subscription | undefined;
396
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
397
+ const headers = new Headers();
398
+ if (this.workspaceId !== undefined) {
399
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
400
+ }
401
+ headers.set('User-Agent', this.userAgent);
402
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
403
+ const respBody = await executeHttpCall({
404
+ request: httpReq,
405
+ httpClient: this.httpClient,
406
+ logger: this.logger,
407
+ });
408
+ resp = parseResponse(respBody, unmarshalSubscriptionSchema);
409
+ };
410
+ await executeCall(call, options);
411
+ if (resp === undefined) {
412
+ throw new Error('API call completed without a result.');
413
+ }
414
+ return resp;
415
+ }
416
+
417
+ /** List dashboards. */
418
+ async listDashboards(
419
+ req: ListDashboardsRequest,
420
+ options?: CallOptions
421
+ ): Promise<ListDashboardsResponse> {
422
+ const url = `${this.host}/api/2.0/lakeview/dashboards`;
423
+ const params = new URLSearchParams();
424
+ if (req.pageSize !== undefined) {
425
+ params.append('page_size', String(req.pageSize));
426
+ }
427
+ if (req.pageToken !== undefined) {
428
+ params.append('page_token', req.pageToken);
429
+ }
430
+ if (req.showTrashed !== undefined) {
431
+ params.append('show_trashed', String(req.showTrashed));
432
+ }
433
+ if (req.view !== undefined) {
434
+ params.append('view', req.view);
435
+ }
436
+ const query = params.toString();
437
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
438
+ let resp: ListDashboardsResponse | undefined;
439
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
440
+ const headers = new Headers();
441
+ if (this.workspaceId !== undefined) {
442
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
443
+ }
444
+ headers.set('User-Agent', this.userAgent);
445
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
446
+ const respBody = await executeHttpCall({
447
+ request: httpReq,
448
+ httpClient: this.httpClient,
449
+ logger: this.logger,
450
+ });
451
+ resp = parseResponse(respBody, unmarshalListDashboardsResponseSchema);
452
+ };
453
+ await executeCall(call, options);
454
+ if (resp === undefined) {
455
+ throw new Error('API call completed without a result.');
456
+ }
457
+ return resp;
458
+ }
459
+
460
+ async *listDashboardsIter(
461
+ req: ListDashboardsRequest,
462
+ options?: CallOptions
463
+ ): AsyncGenerator<Dashboard> {
464
+ const pageReq: ListDashboardsRequest = {...req};
465
+ for (;;) {
466
+ const resp = await this.listDashboards(pageReq, options);
467
+ for (const item of resp.dashboards ?? []) {
468
+ yield item;
469
+ }
470
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
471
+ return;
472
+ }
473
+ pageReq.pageToken = resp.nextPageToken;
474
+ }
475
+ }
476
+
477
+ /** List dashboard schedules. */
478
+ async listSchedules(
479
+ req: ListSchedulesRequest,
480
+ options?: CallOptions
481
+ ): Promise<ListSchedulesResponse> {
482
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/schedules`;
483
+ const params = new URLSearchParams();
484
+ if (req.pageSize !== undefined) {
485
+ params.append('page_size', String(req.pageSize));
486
+ }
487
+ if (req.pageToken !== undefined) {
488
+ params.append('page_token', req.pageToken);
489
+ }
490
+ const query = params.toString();
491
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
492
+ let resp: ListSchedulesResponse | undefined;
493
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
494
+ const headers = new Headers();
495
+ if (this.workspaceId !== undefined) {
496
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
497
+ }
498
+ headers.set('User-Agent', this.userAgent);
499
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
500
+ const respBody = await executeHttpCall({
501
+ request: httpReq,
502
+ httpClient: this.httpClient,
503
+ logger: this.logger,
504
+ });
505
+ resp = parseResponse(respBody, unmarshalListSchedulesResponseSchema);
506
+ };
507
+ await executeCall(call, options);
508
+ if (resp === undefined) {
509
+ throw new Error('API call completed without a result.');
510
+ }
511
+ return resp;
512
+ }
513
+
514
+ async *listSchedulesIter(
515
+ req: ListSchedulesRequest,
516
+ options?: CallOptions
517
+ ): AsyncGenerator<Schedule> {
518
+ const pageReq: ListSchedulesRequest = {...req};
519
+ for (;;) {
520
+ const resp = await this.listSchedules(pageReq, options);
521
+ for (const item of resp.schedules ?? []) {
522
+ yield item;
523
+ }
524
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
525
+ return;
526
+ }
527
+ pageReq.pageToken = resp.nextPageToken;
528
+ }
529
+ }
530
+
531
+ /** List schedule subscriptions. */
532
+ async listSubscriptions(
533
+ req: ListSubscriptionsRequest,
534
+ options?: CallOptions
535
+ ): Promise<ListSubscriptionsResponse> {
536
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/schedules/${req.scheduleId ?? ''}/subscriptions`;
537
+ const params = new URLSearchParams();
538
+ if (req.pageSize !== undefined) {
539
+ params.append('page_size', String(req.pageSize));
540
+ }
541
+ if (req.pageToken !== undefined) {
542
+ params.append('page_token', req.pageToken);
543
+ }
544
+ const query = params.toString();
545
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
546
+ let resp: ListSubscriptionsResponse | undefined;
547
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
548
+ const headers = new Headers();
549
+ if (this.workspaceId !== undefined) {
550
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
551
+ }
552
+ headers.set('User-Agent', this.userAgent);
553
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
554
+ const respBody = await executeHttpCall({
555
+ request: httpReq,
556
+ httpClient: this.httpClient,
557
+ logger: this.logger,
558
+ });
559
+ resp = parseResponse(respBody, unmarshalListSubscriptionsResponseSchema);
560
+ };
561
+ await executeCall(call, options);
562
+ if (resp === undefined) {
563
+ throw new Error('API call completed without a result.');
564
+ }
565
+ return resp;
566
+ }
567
+
568
+ async *listSubscriptionsIter(
569
+ req: ListSubscriptionsRequest,
570
+ options?: CallOptions
571
+ ): AsyncGenerator<Subscription> {
572
+ const pageReq: ListSubscriptionsRequest = {...req};
573
+ for (;;) {
574
+ const resp = await this.listSubscriptions(pageReq, options);
575
+ for (const item of resp.subscriptions ?? []) {
576
+ yield item;
577
+ }
578
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
579
+ return;
580
+ }
581
+ pageReq.pageToken = resp.nextPageToken;
582
+ }
583
+ }
584
+
585
+ /** Migrates a classic SQL dashboard to Lakeview. */
586
+ async migrateDashboard(
587
+ req: MigrateDashboardRequest,
588
+ options?: CallOptions
589
+ ): Promise<Dashboard> {
590
+ const url = `${this.host}/api/2.0/lakeview/dashboards/migrate`;
591
+ const body = marshalRequest(req, marshalMigrateDashboardRequestSchema);
592
+ let resp: Dashboard | undefined;
593
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
594
+ const headers = new Headers({'Content-Type': 'application/json'});
595
+ if (this.workspaceId !== undefined) {
596
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
597
+ }
598
+ headers.set('User-Agent', this.userAgent);
599
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
600
+ const respBody = await executeHttpCall({
601
+ request: httpReq,
602
+ httpClient: this.httpClient,
603
+ logger: this.logger,
604
+ });
605
+ resp = parseResponse(respBody, unmarshalDashboardSchema);
606
+ };
607
+ await executeCall(call, options);
608
+ if (resp === undefined) {
609
+ throw new Error('API call completed without a result.');
610
+ }
611
+ return resp;
612
+ }
613
+
614
+ /** Publish the current draft dashboard. */
615
+ async publishDashboard(
616
+ req: PublishDashboardRequest,
617
+ options?: CallOptions
618
+ ): Promise<PublishedDashboard> {
619
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/published`;
620
+ const body = marshalRequest(req, marshalPublishDashboardRequestSchema);
621
+ let resp: PublishedDashboard | undefined;
622
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
623
+ const headers = new Headers({'Content-Type': 'application/json'});
624
+ if (this.workspaceId !== undefined) {
625
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
626
+ }
627
+ headers.set('User-Agent', this.userAgent);
628
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
629
+ const respBody = await executeHttpCall({
630
+ request: httpReq,
631
+ httpClient: this.httpClient,
632
+ logger: this.logger,
633
+ });
634
+ resp = parseResponse(respBody, unmarshalPublishedDashboardSchema);
635
+ };
636
+ await executeCall(call, options);
637
+ if (resp === undefined) {
638
+ throw new Error('API call completed without a result.');
639
+ }
640
+ return resp;
641
+ }
642
+
643
+ /** Revert a dashboard's definition in draft mode to the last published version. */
644
+ async revertDashboard(
645
+ req: RevertDashboardRequest,
646
+ options?: CallOptions
647
+ ): Promise<RevertDashboardResponse> {
648
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/revert`;
649
+ const body = marshalRequest(req, marshalRevertDashboardRequestSchema);
650
+ let resp: RevertDashboardResponse | undefined;
651
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
652
+ const headers = new Headers({'Content-Type': 'application/json'});
653
+ if (this.workspaceId !== undefined) {
654
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
655
+ }
656
+ headers.set('User-Agent', this.userAgent);
657
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
658
+ const respBody = await executeHttpCall({
659
+ request: httpReq,
660
+ httpClient: this.httpClient,
661
+ logger: this.logger,
662
+ });
663
+ resp = parseResponse(respBody, unmarshalRevertDashboardResponseSchema);
664
+ };
665
+ await executeCall(call, options);
666
+ if (resp === undefined) {
667
+ throw new Error('API call completed without a result.');
668
+ }
669
+ return resp;
670
+ }
671
+
672
+ /** Trash a dashboard. */
673
+ async trashDashboard(
674
+ req: TrashDashboardRequest,
675
+ options?: CallOptions
676
+ ): Promise<TrashDashboardResponse> {
677
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}`;
678
+ let resp: TrashDashboardResponse | undefined;
679
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
680
+ const headers = new Headers();
681
+ if (this.workspaceId !== undefined) {
682
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
683
+ }
684
+ headers.set('User-Agent', this.userAgent);
685
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
686
+ const respBody = await executeHttpCall({
687
+ request: httpReq,
688
+ httpClient: this.httpClient,
689
+ logger: this.logger,
690
+ });
691
+ resp = parseResponse(respBody, unmarshalTrashDashboardResponseSchema);
692
+ };
693
+ await executeCall(call, options);
694
+ if (resp === undefined) {
695
+ throw new Error('API call completed without a result.');
696
+ }
697
+ return resp;
698
+ }
699
+
700
+ /** Unpublish the dashboard. */
701
+ async unpublishDashboard(
702
+ req: UnpublishDashboardRequest,
703
+ options?: CallOptions
704
+ ): Promise<UnpublishDashboardResponse> {
705
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboardId ?? ''}/published`;
706
+ let resp: UnpublishDashboardResponse | undefined;
707
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
708
+ const headers = new Headers();
709
+ if (this.workspaceId !== undefined) {
710
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
711
+ }
712
+ headers.set('User-Agent', this.userAgent);
713
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
714
+ const respBody = await executeHttpCall({
715
+ request: httpReq,
716
+ httpClient: this.httpClient,
717
+ logger: this.logger,
718
+ });
719
+ resp = parseResponse(respBody, unmarshalUnpublishDashboardResponseSchema);
720
+ };
721
+ await executeCall(call, options);
722
+ if (resp === undefined) {
723
+ throw new Error('API call completed without a result.');
724
+ }
725
+ return resp;
726
+ }
727
+
728
+ /** Update a draft dashboard. */
729
+ async updateDashboard(
730
+ req: UpdateDashboardRequest,
731
+ options?: CallOptions
732
+ ): Promise<Dashboard> {
733
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.dashboard?.dashboardId ?? ''}`;
734
+ const params = new URLSearchParams();
735
+ if (req.datasetCatalog !== undefined) {
736
+ params.append('dataset_catalog', req.datasetCatalog);
737
+ }
738
+ if (req.datasetSchema !== undefined) {
739
+ params.append('dataset_schema', req.datasetSchema);
740
+ }
741
+ const query = params.toString();
742
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
743
+ const body = marshalRequest(req.dashboard, marshalDashboardSchema);
744
+ let resp: Dashboard | undefined;
745
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
746
+ const headers = new Headers({'Content-Type': 'application/json'});
747
+ if (this.workspaceId !== undefined) {
748
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
749
+ }
750
+ headers.set('User-Agent', this.userAgent);
751
+ const httpReq = buildHttpRequest(
752
+ 'PATCH',
753
+ fullUrl,
754
+ headers,
755
+ callSignal,
756
+ body
757
+ );
758
+ const respBody = await executeHttpCall({
759
+ request: httpReq,
760
+ httpClient: this.httpClient,
761
+ logger: this.logger,
762
+ });
763
+ resp = parseResponse(respBody, unmarshalDashboardSchema);
764
+ };
765
+ await executeCall(call, options);
766
+ if (resp === undefined) {
767
+ throw new Error('API call completed without a result.');
768
+ }
769
+ return resp;
770
+ }
771
+
772
+ /** Update dashboard schedule. */
773
+ async updateSchedule(
774
+ req: UpdateScheduleRequest,
775
+ options?: CallOptions
776
+ ): Promise<Schedule> {
777
+ const url = `${this.host}/api/2.0/lakeview/dashboards/${req.schedule?.dashboardId ?? ''}/schedules/${req.schedule?.scheduleId ?? ''}`;
778
+ const body = marshalRequest(req.schedule, marshalScheduleSchema);
779
+ let resp: Schedule | undefined;
780
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
781
+ const headers = new Headers({'Content-Type': 'application/json'});
782
+ if (this.workspaceId !== undefined) {
783
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
784
+ }
785
+ headers.set('User-Agent', this.userAgent);
786
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
787
+ const respBody = await executeHttpCall({
788
+ request: httpReq,
789
+ httpClient: this.httpClient,
790
+ logger: this.logger,
791
+ });
792
+ resp = parseResponse(respBody, unmarshalScheduleSchema);
793
+ };
794
+ await executeCall(call, options);
795
+ if (resp === undefined) {
796
+ throw new Error('API call completed without a result.');
797
+ }
798
+ return resp;
799
+ }
800
+ }