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