@databricks/sdk-uc-metastores 0.0.0-dev → 0.1.0-dev.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.
@@ -0,0 +1,806 @@
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 {createDefault} from '@databricks/sdk-core/clientinfo';
5
+ import type {Logger} from '@databricks/sdk-core/logger';
6
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
7
+ import type {CallOptions} from '@databricks/sdk-options/call';
8
+ import type {ClientOptions} from '@databricks/sdk-options/client';
9
+ import type {HttpClient} from '@databricks/sdk-core/http';
10
+ import {newHttpClient} from './transport';
11
+ import {
12
+ buildHttpRequest,
13
+ executeCall,
14
+ executeHttpCall,
15
+ marshalRequest,
16
+ parseResponse,
17
+ } from './utils';
18
+ import pkgJson from '../../package.json' with {type: 'json'};
19
+ import type {
20
+ AccountsCreateMetastoreAssignmentRequest,
21
+ AccountsCreateMetastoreAssignmentRequest_Response,
22
+ AccountsCreateMetastoreRequest,
23
+ AccountsCreateMetastoreRequest_Response,
24
+ AccountsDeleteMetastoreAssignmentRequest,
25
+ AccountsDeleteMetastoreAssignmentRequest_Response,
26
+ AccountsDeleteMetastoreRequest,
27
+ AccountsDeleteMetastoreRequest_Response,
28
+ AccountsGetMetastoreAssignmentRequest,
29
+ AccountsGetMetastoreAssignmentRequest_Response,
30
+ AccountsGetMetastoreRequest,
31
+ AccountsGetMetastoreRequest_Response,
32
+ AccountsListMetastoresRequest,
33
+ AccountsListMetastoresRequest_Response,
34
+ AccountsListWorkspaceIdsForMetastoreRequest,
35
+ AccountsListWorkspaceIdsForMetastoreRequest_Response,
36
+ AccountsUpdateMetastoreAssignmentRequest,
37
+ AccountsUpdateMetastoreAssignmentRequest_Response,
38
+ AccountsUpdateMetastoreRequest,
39
+ AccountsUpdateMetastoreRequest_Response,
40
+ CreateMetastoreAssignmentRequest,
41
+ CreateMetastoreAssignmentRequest_Response,
42
+ CreateMetastoreRequest,
43
+ DeleteMetastoreAssignmentRequest,
44
+ DeleteMetastoreAssignmentRequest_Response,
45
+ DeleteMetastoreRequest,
46
+ DeleteMetastoreRequest_Response,
47
+ GetCurrentMetastoreAssignmentRequest,
48
+ GetMetastoreRequest,
49
+ GetMetastoreSummaryRequest,
50
+ GetMetastoreSummaryRequest_Response,
51
+ ListMetastoresRequest,
52
+ ListMetastoresRequest_Response,
53
+ MetastoreAssignment,
54
+ MetastoreInfo,
55
+ UpdateMetastoreAssignmentRequest,
56
+ UpdateMetastoreAssignmentRequest_Response,
57
+ UpdateMetastoreRequest,
58
+ } from './model';
59
+ import {
60
+ marshalAccountsCreateMetastoreAssignmentRequestSchema,
61
+ marshalAccountsCreateMetastoreRequestSchema,
62
+ marshalAccountsUpdateMetastoreAssignmentRequestSchema,
63
+ marshalAccountsUpdateMetastoreRequestSchema,
64
+ marshalCreateMetastoreAssignmentRequestSchema,
65
+ marshalCreateMetastoreRequestSchema,
66
+ marshalUpdateMetastoreAssignmentRequestSchema,
67
+ marshalUpdateMetastoreRequestSchema,
68
+ unmarshalAccountsCreateMetastoreAssignmentRequest_ResponseSchema,
69
+ unmarshalAccountsCreateMetastoreRequest_ResponseSchema,
70
+ unmarshalAccountsDeleteMetastoreAssignmentRequest_ResponseSchema,
71
+ unmarshalAccountsDeleteMetastoreRequest_ResponseSchema,
72
+ unmarshalAccountsGetMetastoreAssignmentRequest_ResponseSchema,
73
+ unmarshalAccountsGetMetastoreRequest_ResponseSchema,
74
+ unmarshalAccountsListMetastoresRequest_ResponseSchema,
75
+ unmarshalAccountsListWorkspaceIdsForMetastoreRequest_ResponseSchema,
76
+ unmarshalAccountsUpdateMetastoreAssignmentRequest_ResponseSchema,
77
+ unmarshalAccountsUpdateMetastoreRequest_ResponseSchema,
78
+ unmarshalCreateMetastoreAssignmentRequest_ResponseSchema,
79
+ unmarshalDeleteMetastoreAssignmentRequest_ResponseSchema,
80
+ unmarshalDeleteMetastoreRequest_ResponseSchema,
81
+ unmarshalGetMetastoreSummaryRequest_ResponseSchema,
82
+ unmarshalListMetastoresRequest_ResponseSchema,
83
+ unmarshalMetastoreAssignmentSchema,
84
+ unmarshalMetastoreInfoSchema,
85
+ unmarshalUpdateMetastoreAssignmentRequest_ResponseSchema,
86
+ } from './model';
87
+
88
+ // Package identity segment for this client to be used in the User-Agent header.
89
+ const PACKAGE_SEGMENT = {
90
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
91
+ value: pkgJson.version,
92
+ };
93
+
94
+ export class MetastoresClient {
95
+ private readonly host: string;
96
+ // Fallback for endpoints whose path contains {account_id}. If the request
97
+ // already carries an accountId, that value wins.
98
+ private readonly accountId: string | undefined;
99
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
100
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
101
+ // request.
102
+ private readonly workspaceId: string | undefined;
103
+ private readonly httpClient: HttpClient;
104
+ private readonly logger: Logger;
105
+ // User-Agent header value. Composed once at construction from
106
+ // createDefault() merged with this package's identity and the active
107
+ // credential's name.
108
+ private readonly userAgent: string;
109
+
110
+ constructor(options: ClientOptions) {
111
+ if (options.host === undefined) {
112
+ throw new Error('Host is required.');
113
+ }
114
+ this.host = options.host.replace(/\/$/, '');
115
+ this.accountId = options.accountId;
116
+ this.workspaceId = options.workspaceId;
117
+ this.logger = options.logger ?? new NoOpLogger();
118
+ const info = createDefault()
119
+ .with(PACKAGE_SEGMENT)
120
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
121
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
122
+ this.userAgent = info.toString();
123
+ this.httpClient = newHttpClient(options);
124
+ }
125
+
126
+ /** Creates a Unity Catalog metastore. */
127
+ async createAccountsMetastore(
128
+ req: AccountsCreateMetastoreRequest,
129
+ options?: CallOptions
130
+ ): Promise<AccountsCreateMetastoreRequest_Response> {
131
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores`;
132
+ const body = marshalRequest(
133
+ req,
134
+ marshalAccountsCreateMetastoreRequestSchema
135
+ );
136
+ let resp: AccountsCreateMetastoreRequest_Response | undefined;
137
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
138
+ const headers = new Headers({'Content-Type': 'application/json'});
139
+ headers.set('User-Agent', this.userAgent);
140
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
141
+ const respBody = await executeHttpCall({
142
+ request: httpReq,
143
+ httpClient: this.httpClient,
144
+ logger: this.logger,
145
+ });
146
+ resp = parseResponse(
147
+ respBody,
148
+ unmarshalAccountsCreateMetastoreRequest_ResponseSchema
149
+ );
150
+ };
151
+ await executeCall(call, options);
152
+ if (resp === undefined) {
153
+ throw new Error('operation completed without a result.');
154
+ }
155
+ return resp;
156
+ }
157
+
158
+ /** Creates an assignment to a metastore for a workspace */
159
+ async createAccountsMetastoreAssignment(
160
+ req: AccountsCreateMetastoreAssignmentRequest,
161
+ options?: CallOptions
162
+ ): Promise<AccountsCreateMetastoreAssignmentRequest_Response> {
163
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}/metastores/${req.metastoreId ?? ''}`;
164
+ const body = marshalRequest(
165
+ req,
166
+ marshalAccountsCreateMetastoreAssignmentRequestSchema
167
+ );
168
+ let resp: AccountsCreateMetastoreAssignmentRequest_Response | undefined;
169
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
170
+ const headers = new Headers({'Content-Type': 'application/json'});
171
+ headers.set('User-Agent', this.userAgent);
172
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
173
+ const respBody = await executeHttpCall({
174
+ request: httpReq,
175
+ httpClient: this.httpClient,
176
+ logger: this.logger,
177
+ });
178
+ resp = parseResponse(
179
+ respBody,
180
+ unmarshalAccountsCreateMetastoreAssignmentRequest_ResponseSchema
181
+ );
182
+ };
183
+ await executeCall(call, options);
184
+ if (resp === undefined) {
185
+ throw new Error('operation completed without a result.');
186
+ }
187
+ return resp;
188
+ }
189
+
190
+ /** Deletes a Unity Catalog metastore for an account, both specified by ID. */
191
+ async deleteAccountsMetastore(
192
+ req: AccountsDeleteMetastoreRequest,
193
+ options?: CallOptions
194
+ ): Promise<AccountsDeleteMetastoreRequest_Response> {
195
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores/${req.metastoreId ?? ''}`;
196
+ const params = new URLSearchParams();
197
+ if (req.force !== undefined) {
198
+ params.append('force', String(req.force));
199
+ }
200
+ const query = params.toString();
201
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
202
+ let resp: AccountsDeleteMetastoreRequest_Response | undefined;
203
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
204
+ const headers = new Headers();
205
+ headers.set('User-Agent', this.userAgent);
206
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
207
+ const respBody = await executeHttpCall({
208
+ request: httpReq,
209
+ httpClient: this.httpClient,
210
+ logger: this.logger,
211
+ });
212
+ resp = parseResponse(
213
+ respBody,
214
+ unmarshalAccountsDeleteMetastoreRequest_ResponseSchema
215
+ );
216
+ };
217
+ await executeCall(call, options);
218
+ if (resp === undefined) {
219
+ throw new Error('operation completed without a result.');
220
+ }
221
+ return resp;
222
+ }
223
+
224
+ /** Deletes a metastore assignment to a workspace, leaving the workspace with no metastore. */
225
+ async deleteAccountsMetastoreAssignment(
226
+ req: AccountsDeleteMetastoreAssignmentRequest,
227
+ options?: CallOptions
228
+ ): Promise<AccountsDeleteMetastoreAssignmentRequest_Response> {
229
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}/metastores/${req.metastoreId ?? ''}`;
230
+ let resp: AccountsDeleteMetastoreAssignmentRequest_Response | undefined;
231
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
232
+ const headers = new Headers();
233
+ headers.set('User-Agent', this.userAgent);
234
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
235
+ const respBody = await executeHttpCall({
236
+ request: httpReq,
237
+ httpClient: this.httpClient,
238
+ logger: this.logger,
239
+ });
240
+ resp = parseResponse(
241
+ respBody,
242
+ unmarshalAccountsDeleteMetastoreAssignmentRequest_ResponseSchema
243
+ );
244
+ };
245
+ await executeCall(call, options);
246
+ if (resp === undefined) {
247
+ throw new Error('operation completed without a result.');
248
+ }
249
+ return resp;
250
+ }
251
+
252
+ /** Gets a Unity Catalog metastore from an account, both specified by ID. */
253
+ async getAccountsMetastore(
254
+ req: AccountsGetMetastoreRequest,
255
+ options?: CallOptions
256
+ ): Promise<AccountsGetMetastoreRequest_Response> {
257
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores/${req.metastoreId ?? ''}`;
258
+ let resp: AccountsGetMetastoreRequest_Response | undefined;
259
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
260
+ const headers = new Headers();
261
+ headers.set('User-Agent', this.userAgent);
262
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
263
+ const respBody = await executeHttpCall({
264
+ request: httpReq,
265
+ httpClient: this.httpClient,
266
+ logger: this.logger,
267
+ });
268
+ resp = parseResponse(
269
+ respBody,
270
+ unmarshalAccountsGetMetastoreRequest_ResponseSchema
271
+ );
272
+ };
273
+ await executeCall(call, options);
274
+ if (resp === undefined) {
275
+ throw new Error('operation completed without a result.');
276
+ }
277
+ return resp;
278
+ }
279
+
280
+ /**
281
+ * Gets the metastore assignment, if any, for the workspace specified by ID.
282
+ * If the workspace is assigned a metastore, the mapping will be returned.
283
+ * If no metastore is assigned to the workspace, the assignment will not be
284
+ * found and a 404 returned.
285
+ */
286
+ async getMetastoreAssignment(
287
+ req: AccountsGetMetastoreAssignmentRequest,
288
+ options?: CallOptions
289
+ ): Promise<AccountsGetMetastoreAssignmentRequest_Response> {
290
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}/metastore`;
291
+ let resp: AccountsGetMetastoreAssignmentRequest_Response | undefined;
292
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
293
+ const headers = new Headers();
294
+ headers.set('User-Agent', this.userAgent);
295
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
296
+ const respBody = await executeHttpCall({
297
+ request: httpReq,
298
+ httpClient: this.httpClient,
299
+ logger: this.logger,
300
+ });
301
+ resp = parseResponse(
302
+ respBody,
303
+ unmarshalAccountsGetMetastoreAssignmentRequest_ResponseSchema
304
+ );
305
+ };
306
+ await executeCall(call, options);
307
+ if (resp === undefined) {
308
+ throw new Error('operation completed without a result.');
309
+ }
310
+ return resp;
311
+ }
312
+
313
+ /** Gets all Unity Catalog metastores associated with an account specified by ID. */
314
+ async listAccountsMetastores(
315
+ req: AccountsListMetastoresRequest,
316
+ options?: CallOptions
317
+ ): Promise<AccountsListMetastoresRequest_Response> {
318
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores`;
319
+ let resp: AccountsListMetastoresRequest_Response | undefined;
320
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
321
+ const headers = new Headers();
322
+ headers.set('User-Agent', this.userAgent);
323
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
324
+ const respBody = await executeHttpCall({
325
+ request: httpReq,
326
+ httpClient: this.httpClient,
327
+ logger: this.logger,
328
+ });
329
+ resp = parseResponse(
330
+ respBody,
331
+ unmarshalAccountsListMetastoresRequest_ResponseSchema
332
+ );
333
+ };
334
+ await executeCall(call, options);
335
+ if (resp === undefined) {
336
+ throw new Error('operation completed without a result.');
337
+ }
338
+ return resp;
339
+ }
340
+
341
+ /** Gets a list of all <Databricks> workspace IDs that have been assigned to given metastore. */
342
+ async listMetastoreAssignments(
343
+ req: AccountsListWorkspaceIdsForMetastoreRequest,
344
+ options?: CallOptions
345
+ ): Promise<AccountsListWorkspaceIdsForMetastoreRequest_Response> {
346
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores/${req.metastoreId ?? ''}/workspaces`;
347
+ let resp: AccountsListWorkspaceIdsForMetastoreRequest_Response | undefined;
348
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
349
+ const headers = new Headers();
350
+ headers.set('User-Agent', this.userAgent);
351
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
352
+ const respBody = await executeHttpCall({
353
+ request: httpReq,
354
+ httpClient: this.httpClient,
355
+ logger: this.logger,
356
+ });
357
+ resp = parseResponse(
358
+ respBody,
359
+ unmarshalAccountsListWorkspaceIdsForMetastoreRequest_ResponseSchema
360
+ );
361
+ };
362
+ await executeCall(call, options);
363
+ if (resp === undefined) {
364
+ throw new Error('operation completed without a result.');
365
+ }
366
+ return resp;
367
+ }
368
+
369
+ /** Updates an existing Unity Catalog metastore. */
370
+ async updateAccountsMetastore(
371
+ req: AccountsUpdateMetastoreRequest,
372
+ options?: CallOptions
373
+ ): Promise<AccountsUpdateMetastoreRequest_Response> {
374
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores/${req.metastoreId ?? ''}`;
375
+ const body = marshalRequest(
376
+ req,
377
+ marshalAccountsUpdateMetastoreRequestSchema
378
+ );
379
+ let resp: AccountsUpdateMetastoreRequest_Response | undefined;
380
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
381
+ const headers = new Headers({'Content-Type': 'application/json'});
382
+ headers.set('User-Agent', this.userAgent);
383
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
384
+ const respBody = await executeHttpCall({
385
+ request: httpReq,
386
+ httpClient: this.httpClient,
387
+ logger: this.logger,
388
+ });
389
+ resp = parseResponse(
390
+ respBody,
391
+ unmarshalAccountsUpdateMetastoreRequest_ResponseSchema
392
+ );
393
+ };
394
+ await executeCall(call, options);
395
+ if (resp === undefined) {
396
+ throw new Error('operation completed without a result.');
397
+ }
398
+ return resp;
399
+ }
400
+
401
+ /** Updates an assignment to a metastore for a workspace. Currently, only the default catalog may be updated. */
402
+ async updateAccountsMetastoreAssignment(
403
+ req: AccountsUpdateMetastoreAssignmentRequest,
404
+ options?: CallOptions
405
+ ): Promise<AccountsUpdateMetastoreAssignmentRequest_Response> {
406
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}/metastores/${req.metastoreId ?? ''}`;
407
+ const body = marshalRequest(
408
+ req,
409
+ marshalAccountsUpdateMetastoreAssignmentRequestSchema
410
+ );
411
+ let resp: AccountsUpdateMetastoreAssignmentRequest_Response | undefined;
412
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
413
+ const headers = new Headers({'Content-Type': 'application/json'});
414
+ headers.set('User-Agent', this.userAgent);
415
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
416
+ const respBody = await executeHttpCall({
417
+ request: httpReq,
418
+ httpClient: this.httpClient,
419
+ logger: this.logger,
420
+ });
421
+ resp = parseResponse(
422
+ respBody,
423
+ unmarshalAccountsUpdateMetastoreAssignmentRequest_ResponseSchema
424
+ );
425
+ };
426
+ await executeCall(call, options);
427
+ if (resp === undefined) {
428
+ throw new Error('operation completed without a result.');
429
+ }
430
+ return resp;
431
+ }
432
+
433
+ /**
434
+ * Creates a new metastore based on a provided name and optional storage root path.
435
+ * By default (if the __owner__ field is not set), the owner of the new metastore is the user calling
436
+ * the __createMetastore__ API. If the __owner__ field is set to the empty string (**""**), the ownership is
437
+ * assigned to the System User instead.
438
+ */
439
+ async createMetastore(
440
+ req: CreateMetastoreRequest,
441
+ options?: CallOptions
442
+ ): Promise<MetastoreInfo> {
443
+ const url = `${this.host}/api/2.1/unity-catalog/metastores`;
444
+ const body = marshalRequest(req, marshalCreateMetastoreRequestSchema);
445
+ let resp: MetastoreInfo | undefined;
446
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
447
+ const headers = new Headers({'Content-Type': 'application/json'});
448
+ if (this.workspaceId !== undefined) {
449
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
450
+ }
451
+ headers.set('User-Agent', this.userAgent);
452
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
453
+ const respBody = await executeHttpCall({
454
+ request: httpReq,
455
+ httpClient: this.httpClient,
456
+ logger: this.logger,
457
+ });
458
+ resp = parseResponse(respBody, unmarshalMetastoreInfoSchema);
459
+ };
460
+ await executeCall(call, options);
461
+ if (resp === undefined) {
462
+ throw new Error('operation completed without a result.');
463
+ }
464
+ return resp;
465
+ }
466
+
467
+ /**
468
+ * Creates a new metastore assignment.
469
+ * If an assignment for the same __workspace_id__ exists, it will be overwritten by the new __metastore_id__ and
470
+ * __default_catalog_name__. The caller must be an account admin.
471
+ */
472
+ async createMetastoreAssignment(
473
+ req: CreateMetastoreAssignmentRequest,
474
+ options?: CallOptions
475
+ ): Promise<CreateMetastoreAssignmentRequest_Response> {
476
+ const url = `${this.host}/api/2.1/unity-catalog/workspaces/${String(req.workspaceId ?? '')}/metastore`;
477
+ const body = marshalRequest(
478
+ req,
479
+ marshalCreateMetastoreAssignmentRequestSchema
480
+ );
481
+ let resp: CreateMetastoreAssignmentRequest_Response | undefined;
482
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
483
+ const headers = new Headers({'Content-Type': 'application/json'});
484
+ if (this.workspaceId !== undefined) {
485
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
486
+ }
487
+ headers.set('User-Agent', this.userAgent);
488
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
489
+ const respBody = await executeHttpCall({
490
+ request: httpReq,
491
+ httpClient: this.httpClient,
492
+ logger: this.logger,
493
+ });
494
+ resp = parseResponse(
495
+ respBody,
496
+ unmarshalCreateMetastoreAssignmentRequest_ResponseSchema
497
+ );
498
+ };
499
+ await executeCall(call, options);
500
+ if (resp === undefined) {
501
+ throw new Error('operation completed without a result.');
502
+ }
503
+ return resp;
504
+ }
505
+
506
+ /** Deletes a metastore. The caller must be a metastore admin. */
507
+ async deleteMetastore(
508
+ req: DeleteMetastoreRequest,
509
+ options?: CallOptions
510
+ ): Promise<DeleteMetastoreRequest_Response> {
511
+ const url = `${this.host}/api/2.1/unity-catalog/metastores/${req.id ?? ''}`;
512
+ const params = new URLSearchParams();
513
+ if (req.force !== undefined) {
514
+ params.append('force', String(req.force));
515
+ }
516
+ const query = params.toString();
517
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
518
+ let resp: DeleteMetastoreRequest_Response | undefined;
519
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
520
+ const headers = new Headers();
521
+ if (this.workspaceId !== undefined) {
522
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
523
+ }
524
+ headers.set('User-Agent', this.userAgent);
525
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
526
+ const respBody = await executeHttpCall({
527
+ request: httpReq,
528
+ httpClient: this.httpClient,
529
+ logger: this.logger,
530
+ });
531
+ resp = parseResponse(
532
+ respBody,
533
+ unmarshalDeleteMetastoreRequest_ResponseSchema
534
+ );
535
+ };
536
+ await executeCall(call, options);
537
+ if (resp === undefined) {
538
+ throw new Error('operation completed without a result.');
539
+ }
540
+ return resp;
541
+ }
542
+
543
+ /** Deletes a metastore assignment. The caller must be an account administrator. */
544
+ async deleteMetastoreAssignment(
545
+ req: DeleteMetastoreAssignmentRequest,
546
+ options?: CallOptions
547
+ ): Promise<DeleteMetastoreAssignmentRequest_Response> {
548
+ const url = `${this.host}/api/2.1/unity-catalog/workspaces/${String(req.workspaceId ?? '')}/metastore`;
549
+ const params = new URLSearchParams();
550
+ if (req.metastoreId !== undefined) {
551
+ params.append('metastore_id', req.metastoreId);
552
+ }
553
+ const query = params.toString();
554
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
555
+ let resp: DeleteMetastoreAssignmentRequest_Response | undefined;
556
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
557
+ const headers = new Headers();
558
+ if (this.workspaceId !== undefined) {
559
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
560
+ }
561
+ headers.set('User-Agent', this.userAgent);
562
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
563
+ const respBody = await executeHttpCall({
564
+ request: httpReq,
565
+ httpClient: this.httpClient,
566
+ logger: this.logger,
567
+ });
568
+ resp = parseResponse(
569
+ respBody,
570
+ unmarshalDeleteMetastoreAssignmentRequest_ResponseSchema
571
+ );
572
+ };
573
+ await executeCall(call, options);
574
+ if (resp === undefined) {
575
+ throw new Error('operation completed without a result.');
576
+ }
577
+ return resp;
578
+ }
579
+
580
+ /** Gets the metastore assignment for the workspace being accessed. */
581
+ async getCurrentMetastoreAssignment(
582
+ _req: GetCurrentMetastoreAssignmentRequest,
583
+ options?: CallOptions
584
+ ): Promise<MetastoreAssignment> {
585
+ const url = `${this.host}/api/2.1/unity-catalog/current-metastore-assignment`;
586
+ let resp: MetastoreAssignment | undefined;
587
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
588
+ const headers = new Headers();
589
+ if (this.workspaceId !== undefined) {
590
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
591
+ }
592
+ headers.set('User-Agent', this.userAgent);
593
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
594
+ const respBody = await executeHttpCall({
595
+ request: httpReq,
596
+ httpClient: this.httpClient,
597
+ logger: this.logger,
598
+ });
599
+ resp = parseResponse(respBody, unmarshalMetastoreAssignmentSchema);
600
+ };
601
+ await executeCall(call, options);
602
+ if (resp === undefined) {
603
+ throw new Error('operation completed without a result.');
604
+ }
605
+ return resp;
606
+ }
607
+
608
+ /** Gets a metastore that matches the supplied ID. The caller must be a metastore admin to retrieve this info. */
609
+ async getMetastore(
610
+ req: GetMetastoreRequest,
611
+ options?: CallOptions
612
+ ): Promise<MetastoreInfo> {
613
+ const url = `${this.host}/api/2.1/unity-catalog/metastores/${req.id ?? ''}`;
614
+ let resp: MetastoreInfo | undefined;
615
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
616
+ const headers = new Headers();
617
+ if (this.workspaceId !== undefined) {
618
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
619
+ }
620
+ headers.set('User-Agent', this.userAgent);
621
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
622
+ const respBody = await executeHttpCall({
623
+ request: httpReq,
624
+ httpClient: this.httpClient,
625
+ logger: this.logger,
626
+ });
627
+ resp = parseResponse(respBody, unmarshalMetastoreInfoSchema);
628
+ };
629
+ await executeCall(call, options);
630
+ if (resp === undefined) {
631
+ throw new Error('operation completed without a result.');
632
+ }
633
+ return resp;
634
+ }
635
+
636
+ /**
637
+ * Gets information about a metastore.
638
+ * This summary includes the storage credential, the cloud vendor, the cloud region, and the global metastore ID.
639
+ */
640
+ async getMetastoreSummary(
641
+ _req: GetMetastoreSummaryRequest,
642
+ options?: CallOptions
643
+ ): Promise<GetMetastoreSummaryRequest_Response> {
644
+ const url = `${this.host}/api/2.1/unity-catalog/metastore_summary`;
645
+ let resp: GetMetastoreSummaryRequest_Response | undefined;
646
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
647
+ const headers = new Headers();
648
+ if (this.workspaceId !== undefined) {
649
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
650
+ }
651
+ headers.set('User-Agent', this.userAgent);
652
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
653
+ const respBody = await executeHttpCall({
654
+ request: httpReq,
655
+ httpClient: this.httpClient,
656
+ logger: this.logger,
657
+ });
658
+ resp = parseResponse(
659
+ respBody,
660
+ unmarshalGetMetastoreSummaryRequest_ResponseSchema
661
+ );
662
+ };
663
+ await executeCall(call, options);
664
+ if (resp === undefined) {
665
+ throw new Error('operation completed without a result.');
666
+ }
667
+ return resp;
668
+ }
669
+
670
+ /**
671
+ * Gets an array of the available metastores (as __MetastoreInfo__ objects). The caller must be an admin to retrieve this info.
672
+ * There is no guarantee of a specific ordering of the elements in the array.
673
+ *
674
+ * NOTE: we recommend using max_results=0 to use the paginated version of this API. Unpaginated calls will be deprecated soon.
675
+ *
676
+ * PAGINATION BEHAVIOR: When using pagination (max_results >= 0), a page may contain zero results while still providing a next_page_token.
677
+ * Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
678
+ */
679
+ async listMetastores(
680
+ req: ListMetastoresRequest,
681
+ options?: CallOptions
682
+ ): Promise<ListMetastoresRequest_Response> {
683
+ const url = `${this.host}/api/2.1/unity-catalog/metastores`;
684
+ const params = new URLSearchParams();
685
+ if (req.maxResults !== undefined) {
686
+ params.append('max_results', String(req.maxResults));
687
+ }
688
+ if (req.pageToken !== undefined) {
689
+ params.append('page_token', req.pageToken);
690
+ }
691
+ const query = params.toString();
692
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
693
+ let resp: ListMetastoresRequest_Response | undefined;
694
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
695
+ const headers = new Headers();
696
+ if (this.workspaceId !== undefined) {
697
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
698
+ }
699
+ headers.set('User-Agent', this.userAgent);
700
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
701
+ const respBody = await executeHttpCall({
702
+ request: httpReq,
703
+ httpClient: this.httpClient,
704
+ logger: this.logger,
705
+ });
706
+ resp = parseResponse(
707
+ respBody,
708
+ unmarshalListMetastoresRequest_ResponseSchema
709
+ );
710
+ };
711
+ await executeCall(call, options);
712
+ if (resp === undefined) {
713
+ throw new Error('operation completed without a result.');
714
+ }
715
+ return resp;
716
+ }
717
+
718
+ async *listMetastoresIter(
719
+ req: ListMetastoresRequest,
720
+ options?: CallOptions
721
+ ): AsyncGenerator<MetastoreInfo> {
722
+ const pageReq: ListMetastoresRequest = {...req};
723
+ for (;;) {
724
+ const resp = await this.listMetastores(pageReq, options);
725
+ for (const item of resp.metastores ?? []) {
726
+ yield item;
727
+ }
728
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
729
+ return;
730
+ }
731
+ pageReq.pageToken = resp.nextPageToken;
732
+ }
733
+ }
734
+
735
+ /**
736
+ * Updates information for a specific metastore. The caller must be a metastore admin.
737
+ * If the __owner__ field is set to the empty string (**""**), the ownership is updated
738
+ * to the System User.
739
+ */
740
+ async updateMetastore(
741
+ req: UpdateMetastoreRequest,
742
+ options?: CallOptions
743
+ ): Promise<MetastoreInfo> {
744
+ const url = `${this.host}/api/2.1/unity-catalog/metastores/${req.id ?? ''}`;
745
+ const body = marshalRequest(req, marshalUpdateMetastoreRequestSchema);
746
+ let resp: MetastoreInfo | undefined;
747
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
748
+ const headers = new Headers({'Content-Type': 'application/json'});
749
+ if (this.workspaceId !== undefined) {
750
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
751
+ }
752
+ headers.set('User-Agent', this.userAgent);
753
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
754
+ const respBody = await executeHttpCall({
755
+ request: httpReq,
756
+ httpClient: this.httpClient,
757
+ logger: this.logger,
758
+ });
759
+ resp = parseResponse(respBody, unmarshalMetastoreInfoSchema);
760
+ };
761
+ await executeCall(call, options);
762
+ if (resp === undefined) {
763
+ throw new Error('operation completed without a result.');
764
+ }
765
+ return resp;
766
+ }
767
+
768
+ /**
769
+ * Updates a metastore assignment. This operation can be used to update __metastore_id__ or __default_catalog_name__
770
+ * for a specified Workspace, if the Workspace is already assigned a metastore.
771
+ * The caller must be an account admin to update __metastore_id__; otherwise, the caller can be a Workspace admin.
772
+ */
773
+ async updateMetastoreAssignment(
774
+ req: UpdateMetastoreAssignmentRequest,
775
+ options?: CallOptions
776
+ ): Promise<UpdateMetastoreAssignmentRequest_Response> {
777
+ const url = `${this.host}/api/2.1/unity-catalog/workspaces/${String(req.workspaceId ?? '')}/metastore`;
778
+ const body = marshalRequest(
779
+ req,
780
+ marshalUpdateMetastoreAssignmentRequestSchema
781
+ );
782
+ let resp: UpdateMetastoreAssignmentRequest_Response | undefined;
783
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
784
+ const headers = new Headers({'Content-Type': 'application/json'});
785
+ if (this.workspaceId !== undefined) {
786
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
787
+ }
788
+ headers.set('User-Agent', this.userAgent);
789
+ const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
790
+ const respBody = await executeHttpCall({
791
+ request: httpReq,
792
+ httpClient: this.httpClient,
793
+ logger: this.logger,
794
+ });
795
+ resp = parseResponse(
796
+ respBody,
797
+ unmarshalUpdateMetastoreAssignmentRequest_ResponseSchema
798
+ );
799
+ };
800
+ await executeCall(call, options);
801
+ if (resp === undefined) {
802
+ throw new Error('operation completed without a result.');
803
+ }
804
+ return resp;
805
+ }
806
+ }