@databricks/sdk-uc-metastores 0.1.0-dev.3 → 0.1.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/v1/client.ts DELETED
@@ -1,800 +0,0 @@
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
- AccountsCreateMetastoreAssignmentResponse,
22
- AccountsCreateMetastoreRequest,
23
- AccountsCreateMetastoreResponse,
24
- AccountsDeleteMetastoreAssignmentRequest,
25
- AccountsDeleteMetastoreAssignmentResponse,
26
- AccountsDeleteMetastoreRequest,
27
- AccountsDeleteMetastoreResponse,
28
- AccountsGetMetastoreAssignmentRequest,
29
- AccountsGetMetastoreAssignmentResponse,
30
- AccountsGetMetastoreRequest,
31
- AccountsGetMetastoreResponse,
32
- AccountsListMetastoresRequest,
33
- AccountsListMetastoresResponse,
34
- AccountsListWorkspaceIdsForMetastoreRequest,
35
- AccountsListWorkspaceIdsForMetastoreResponse,
36
- AccountsUpdateMetastoreAssignmentRequest,
37
- AccountsUpdateMetastoreAssignmentResponse,
38
- AccountsUpdateMetastoreRequest,
39
- AccountsUpdateMetastoreResponse,
40
- CreateMetastoreAssignmentRequest,
41
- CreateMetastoreAssignmentResponse,
42
- CreateMetastoreRequest,
43
- DeleteMetastoreAssignmentRequest,
44
- DeleteMetastoreAssignmentResponse,
45
- DeleteMetastoreRequest,
46
- DeleteMetastoreResponse,
47
- GetCurrentMetastoreAssignmentRequest,
48
- GetMetastoreRequest,
49
- GetMetastoreSummaryRequest,
50
- GetMetastoreSummaryResponse,
51
- ListMetastoresRequest,
52
- ListMetastoresResponse,
53
- MetastoreAssignment,
54
- MetastoreInfo,
55
- UpdateMetastoreAssignmentRequest,
56
- UpdateMetastoreAssignmentResponse,
57
- UpdateMetastoreRequest,
58
- } from './model';
59
- import {
60
- marshalAccountsCreateMetastoreAssignmentRequestSchema,
61
- marshalAccountsCreateMetastoreRequestSchema,
62
- marshalAccountsUpdateMetastoreAssignmentRequestSchema,
63
- marshalAccountsUpdateMetastoreRequestSchema,
64
- marshalCreateMetastoreAssignmentRequestSchema,
65
- marshalCreateMetastoreRequestSchema,
66
- marshalUpdateMetastoreAssignmentRequestSchema,
67
- marshalUpdateMetastoreRequestSchema,
68
- unmarshalAccountsCreateMetastoreAssignmentResponseSchema,
69
- unmarshalAccountsCreateMetastoreResponseSchema,
70
- unmarshalAccountsDeleteMetastoreAssignmentResponseSchema,
71
- unmarshalAccountsDeleteMetastoreResponseSchema,
72
- unmarshalAccountsGetMetastoreAssignmentResponseSchema,
73
- unmarshalAccountsGetMetastoreResponseSchema,
74
- unmarshalAccountsListMetastoresResponseSchema,
75
- unmarshalAccountsListWorkspaceIdsForMetastoreResponseSchema,
76
- unmarshalAccountsUpdateMetastoreAssignmentResponseSchema,
77
- unmarshalAccountsUpdateMetastoreResponseSchema,
78
- unmarshalCreateMetastoreAssignmentResponseSchema,
79
- unmarshalDeleteMetastoreAssignmentResponseSchema,
80
- unmarshalDeleteMetastoreResponseSchema,
81
- unmarshalGetMetastoreSummaryResponseSchema,
82
- unmarshalListMetastoresResponseSchema,
83
- unmarshalMetastoreAssignmentSchema,
84
- unmarshalMetastoreInfoSchema,
85
- unmarshalUpdateMetastoreAssignmentResponseSchema,
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<AccountsCreateMetastoreResponse> {
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: AccountsCreateMetastoreResponse | 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
- unmarshalAccountsCreateMetastoreResponseSchema
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<AccountsCreateMetastoreAssignmentResponse> {
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: AccountsCreateMetastoreAssignmentResponse | 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
- unmarshalAccountsCreateMetastoreAssignmentResponseSchema
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<AccountsDeleteMetastoreResponse> {
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: AccountsDeleteMetastoreResponse | 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
- unmarshalAccountsDeleteMetastoreResponseSchema
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<AccountsDeleteMetastoreAssignmentResponse> {
229
- const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}/metastores/${req.metastoreId ?? ''}`;
230
- let resp: AccountsDeleteMetastoreAssignmentResponse | 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
- unmarshalAccountsDeleteMetastoreAssignmentResponseSchema
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<AccountsGetMetastoreResponse> {
257
- const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores/${req.metastoreId ?? ''}`;
258
- let resp: AccountsGetMetastoreResponse | 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
- unmarshalAccountsGetMetastoreResponseSchema
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<AccountsGetMetastoreAssignmentResponse> {
290
- const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}/metastore`;
291
- let resp: AccountsGetMetastoreAssignmentResponse | 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
- unmarshalAccountsGetMetastoreAssignmentResponseSchema
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<AccountsListMetastoresResponse> {
318
- const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores`;
319
- let resp: AccountsListMetastoresResponse | 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
- unmarshalAccountsListMetastoresResponseSchema
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<AccountsListWorkspaceIdsForMetastoreResponse> {
346
- const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/metastores/${req.metastoreId ?? ''}/workspaces`;
347
- let resp: AccountsListWorkspaceIdsForMetastoreResponse | 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
- unmarshalAccountsListWorkspaceIdsForMetastoreResponseSchema
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<AccountsUpdateMetastoreResponse> {
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: AccountsUpdateMetastoreResponse | 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
- unmarshalAccountsUpdateMetastoreResponseSchema
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<AccountsUpdateMetastoreAssignmentResponse> {
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: AccountsUpdateMetastoreAssignmentResponse | 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
- unmarshalAccountsUpdateMetastoreAssignmentResponseSchema
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<CreateMetastoreAssignmentResponse> {
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: CreateMetastoreAssignmentResponse | 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
- unmarshalCreateMetastoreAssignmentResponseSchema
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<DeleteMetastoreResponse> {
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: DeleteMetastoreResponse | 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(respBody, unmarshalDeleteMetastoreResponseSchema);
532
- };
533
- await executeCall(call, options);
534
- if (resp === undefined) {
535
- throw new Error('operation completed without a result.');
536
- }
537
- return resp;
538
- }
539
-
540
- /** Deletes a metastore assignment. The caller must be an account administrator. */
541
- async deleteMetastoreAssignment(
542
- req: DeleteMetastoreAssignmentRequest,
543
- options?: CallOptions
544
- ): Promise<DeleteMetastoreAssignmentResponse> {
545
- const url = `${this.host}/api/2.1/unity-catalog/workspaces/${String(req.workspaceId ?? '')}/metastore`;
546
- const params = new URLSearchParams();
547
- if (req.metastoreId !== undefined) {
548
- params.append('metastore_id', req.metastoreId);
549
- }
550
- const query = params.toString();
551
- const fullUrl = query !== '' ? `${url}?${query}` : url;
552
- let resp: DeleteMetastoreAssignmentResponse | undefined;
553
- const call = async (callSignal?: AbortSignal): Promise<void> => {
554
- const headers = new Headers();
555
- if (this.workspaceId !== undefined) {
556
- headers.set('X-Databricks-Org-Id', this.workspaceId);
557
- }
558
- headers.set('User-Agent', this.userAgent);
559
- const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
560
- const respBody = await executeHttpCall({
561
- request: httpReq,
562
- httpClient: this.httpClient,
563
- logger: this.logger,
564
- });
565
- resp = parseResponse(
566
- respBody,
567
- unmarshalDeleteMetastoreAssignmentResponseSchema
568
- );
569
- };
570
- await executeCall(call, options);
571
- if (resp === undefined) {
572
- throw new Error('operation completed without a result.');
573
- }
574
- return resp;
575
- }
576
-
577
- /** Gets the metastore assignment for the workspace being accessed. */
578
- async getCurrentMetastoreAssignment(
579
- _req: GetCurrentMetastoreAssignmentRequest,
580
- options?: CallOptions
581
- ): Promise<MetastoreAssignment> {
582
- const url = `${this.host}/api/2.1/unity-catalog/current-metastore-assignment`;
583
- let resp: MetastoreAssignment | undefined;
584
- const call = async (callSignal?: AbortSignal): Promise<void> => {
585
- const headers = new Headers();
586
- if (this.workspaceId !== undefined) {
587
- headers.set('X-Databricks-Org-Id', this.workspaceId);
588
- }
589
- headers.set('User-Agent', this.userAgent);
590
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
591
- const respBody = await executeHttpCall({
592
- request: httpReq,
593
- httpClient: this.httpClient,
594
- logger: this.logger,
595
- });
596
- resp = parseResponse(respBody, unmarshalMetastoreAssignmentSchema);
597
- };
598
- await executeCall(call, options);
599
- if (resp === undefined) {
600
- throw new Error('operation completed without a result.');
601
- }
602
- return resp;
603
- }
604
-
605
- /** Gets a metastore that matches the supplied ID. The caller must be a metastore admin to retrieve this info. */
606
- async getMetastore(
607
- req: GetMetastoreRequest,
608
- options?: CallOptions
609
- ): Promise<MetastoreInfo> {
610
- const url = `${this.host}/api/2.1/unity-catalog/metastores/${req.id ?? ''}`;
611
- let resp: MetastoreInfo | undefined;
612
- const call = async (callSignal?: AbortSignal): Promise<void> => {
613
- const headers = new Headers();
614
- if (this.workspaceId !== undefined) {
615
- headers.set('X-Databricks-Org-Id', this.workspaceId);
616
- }
617
- headers.set('User-Agent', this.userAgent);
618
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
619
- const respBody = await executeHttpCall({
620
- request: httpReq,
621
- httpClient: this.httpClient,
622
- logger: this.logger,
623
- });
624
- resp = parseResponse(respBody, unmarshalMetastoreInfoSchema);
625
- };
626
- await executeCall(call, options);
627
- if (resp === undefined) {
628
- throw new Error('operation completed without a result.');
629
- }
630
- return resp;
631
- }
632
-
633
- /**
634
- * Gets information about a metastore.
635
- * This summary includes the storage credential, the cloud vendor, the cloud region, and the global metastore ID.
636
- */
637
- async getMetastoreSummary(
638
- _req: GetMetastoreSummaryRequest,
639
- options?: CallOptions
640
- ): Promise<GetMetastoreSummaryResponse> {
641
- const url = `${this.host}/api/2.1/unity-catalog/metastore_summary`;
642
- let resp: GetMetastoreSummaryResponse | undefined;
643
- const call = async (callSignal?: AbortSignal): Promise<void> => {
644
- const headers = new Headers();
645
- if (this.workspaceId !== undefined) {
646
- headers.set('X-Databricks-Org-Id', this.workspaceId);
647
- }
648
- headers.set('User-Agent', this.userAgent);
649
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
650
- const respBody = await executeHttpCall({
651
- request: httpReq,
652
- httpClient: this.httpClient,
653
- logger: this.logger,
654
- });
655
- resp = parseResponse(
656
- respBody,
657
- unmarshalGetMetastoreSummaryResponseSchema
658
- );
659
- };
660
- await executeCall(call, options);
661
- if (resp === undefined) {
662
- throw new Error('operation completed without a result.');
663
- }
664
- return resp;
665
- }
666
-
667
- /**
668
- * Gets an array of the available metastores (as __MetastoreInfo__ objects). The caller must be an admin to retrieve this info.
669
- * There is no guarantee of a specific ordering of the elements in the array.
670
- *
671
- * NOTE: we recommend using max_results=0 to use the paginated version of this API. Unpaginated calls will be deprecated soon.
672
- *
673
- * PAGINATION BEHAVIOR: When using pagination (max_results >= 0), a page may contain zero results while still providing a next_page_token.
674
- * Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
675
- */
676
- async listMetastores(
677
- req: ListMetastoresRequest,
678
- options?: CallOptions
679
- ): Promise<ListMetastoresResponse> {
680
- const url = `${this.host}/api/2.1/unity-catalog/metastores`;
681
- const params = new URLSearchParams();
682
- if (req.maxResults !== undefined) {
683
- params.append('max_results', String(req.maxResults));
684
- }
685
- if (req.pageToken !== undefined) {
686
- params.append('page_token', req.pageToken);
687
- }
688
- const query = params.toString();
689
- const fullUrl = query !== '' ? `${url}?${query}` : url;
690
- let resp: ListMetastoresResponse | undefined;
691
- const call = async (callSignal?: AbortSignal): Promise<void> => {
692
- const headers = new Headers();
693
- if (this.workspaceId !== undefined) {
694
- headers.set('X-Databricks-Org-Id', this.workspaceId);
695
- }
696
- headers.set('User-Agent', this.userAgent);
697
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
698
- const respBody = await executeHttpCall({
699
- request: httpReq,
700
- httpClient: this.httpClient,
701
- logger: this.logger,
702
- });
703
- resp = parseResponse(respBody, unmarshalListMetastoresResponseSchema);
704
- };
705
- await executeCall(call, options);
706
- if (resp === undefined) {
707
- throw new Error('operation completed without a result.');
708
- }
709
- return resp;
710
- }
711
-
712
- async *listMetastoresIter(
713
- req: ListMetastoresRequest,
714
- options?: CallOptions
715
- ): AsyncGenerator<MetastoreInfo> {
716
- const pageReq: ListMetastoresRequest = {...req};
717
- for (;;) {
718
- const resp = await this.listMetastores(pageReq, options);
719
- for (const item of resp.metastores ?? []) {
720
- yield item;
721
- }
722
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
723
- return;
724
- }
725
- pageReq.pageToken = resp.nextPageToken;
726
- }
727
- }
728
-
729
- /**
730
- * Updates information for a specific metastore. The caller must be a metastore admin.
731
- * If the __owner__ field is set to the empty string (**""**), the ownership is updated
732
- * to the System User.
733
- */
734
- async updateMetastore(
735
- req: UpdateMetastoreRequest,
736
- options?: CallOptions
737
- ): Promise<MetastoreInfo> {
738
- const url = `${this.host}/api/2.1/unity-catalog/metastores/${req.id ?? ''}`;
739
- const body = marshalRequest(req, marshalUpdateMetastoreRequestSchema);
740
- let resp: MetastoreInfo | undefined;
741
- const call = async (callSignal?: AbortSignal): Promise<void> => {
742
- const headers = new Headers({'Content-Type': 'application/json'});
743
- if (this.workspaceId !== undefined) {
744
- headers.set('X-Databricks-Org-Id', this.workspaceId);
745
- }
746
- headers.set('User-Agent', this.userAgent);
747
- const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
748
- const respBody = await executeHttpCall({
749
- request: httpReq,
750
- httpClient: this.httpClient,
751
- logger: this.logger,
752
- });
753
- resp = parseResponse(respBody, unmarshalMetastoreInfoSchema);
754
- };
755
- await executeCall(call, options);
756
- if (resp === undefined) {
757
- throw new Error('operation completed without a result.');
758
- }
759
- return resp;
760
- }
761
-
762
- /**
763
- * Updates a metastore assignment. This operation can be used to update __metastore_id__ or __default_catalog_name__
764
- * for a specified Workspace, if the Workspace is already assigned a metastore.
765
- * The caller must be an account admin to update __metastore_id__; otherwise, the caller can be a Workspace admin.
766
- */
767
- async updateMetastoreAssignment(
768
- req: UpdateMetastoreAssignmentRequest,
769
- options?: CallOptions
770
- ): Promise<UpdateMetastoreAssignmentResponse> {
771
- const url = `${this.host}/api/2.1/unity-catalog/workspaces/${String(req.workspaceId ?? '')}/metastore`;
772
- const body = marshalRequest(
773
- req,
774
- marshalUpdateMetastoreAssignmentRequestSchema
775
- );
776
- let resp: UpdateMetastoreAssignmentResponse | undefined;
777
- const call = async (callSignal?: AbortSignal): Promise<void> => {
778
- const headers = new Headers({'Content-Type': 'application/json'});
779
- if (this.workspaceId !== undefined) {
780
- headers.set('X-Databricks-Org-Id', this.workspaceId);
781
- }
782
- headers.set('User-Agent', this.userAgent);
783
- const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
784
- const respBody = await executeHttpCall({
785
- request: httpReq,
786
- httpClient: this.httpClient,
787
- logger: this.logger,
788
- });
789
- resp = parseResponse(
790
- respBody,
791
- unmarshalUpdateMetastoreAssignmentResponseSchema
792
- );
793
- };
794
- await executeCall(call, options);
795
- if (resp === undefined) {
796
- throw new Error('operation completed without a result.');
797
- }
798
- return resp;
799
- }
800
- }