@databricks/sdk-warehouses 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,990 @@
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 {retryOn} from '@databricks/sdk-core/api';
6
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
7
+ import type {Logger} from '@databricks/sdk-core/logger';
8
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
9
+ import type {CallOptions} from '@databricks/sdk-options/call';
10
+ import type {ClientOptions} from '@databricks/sdk-options/client';
11
+ import type {HttpClient} from '@databricks/sdk-core/http';
12
+ import {newHttpClient} from './transport';
13
+ import {
14
+ buildHttpRequest,
15
+ executeCall,
16
+ executeHttpCall,
17
+ marshalRequest,
18
+ parseResponse,
19
+ } from './utils';
20
+ import pkgJson from '../../package.json' with {type: 'json'};
21
+ import type {
22
+ CreateDefaultWarehouseOverrideRequest,
23
+ CreateWarehouseRequest,
24
+ CreateWarehouseRequest_Response,
25
+ DefaultWarehouseOverride,
26
+ DeleteDefaultWarehouseOverrideRequest,
27
+ DeleteWarehouseRequest,
28
+ DeleteWarehouseRequest_Response,
29
+ EditWarehouseRequest,
30
+ EditWarehouseRequest_Response,
31
+ EndpointInfo,
32
+ GetDefaultWarehouseOverrideRequest,
33
+ GetWarehouseRequest,
34
+ GetWarehouseRequest_Response,
35
+ GetWorkspaceWarehouseConfigRequest,
36
+ GetWorkspaceWarehouseConfigRequest_Response,
37
+ ListDefaultWarehouseOverridesRequest,
38
+ ListDefaultWarehouseOverridesResponse,
39
+ ListWarehousesRequest,
40
+ ListWarehousesRequest_Response,
41
+ SetWorkspaceWarehouseConfigRequest,
42
+ SetWorkspaceWarehouseConfigRequest_Response,
43
+ StartRequest,
44
+ StartRequest_Response,
45
+ StopRequest,
46
+ StopRequest_Response,
47
+ UpdateDefaultWarehouseOverrideRequest,
48
+ } from './model';
49
+ import {
50
+ EndpointState,
51
+ marshalCreateWarehouseRequestSchema,
52
+ marshalDefaultWarehouseOverrideSchema,
53
+ marshalEditWarehouseRequestSchema,
54
+ marshalSetWorkspaceWarehouseConfigRequestSchema,
55
+ marshalStartRequestSchema,
56
+ marshalStopRequestSchema,
57
+ unmarshalCreateWarehouseRequest_ResponseSchema,
58
+ unmarshalDefaultWarehouseOverrideSchema,
59
+ unmarshalDeleteWarehouseRequest_ResponseSchema,
60
+ unmarshalEditWarehouseRequest_ResponseSchema,
61
+ unmarshalGetWarehouseRequest_ResponseSchema,
62
+ unmarshalGetWorkspaceWarehouseConfigRequest_ResponseSchema,
63
+ unmarshalListDefaultWarehouseOverridesResponseSchema,
64
+ unmarshalListWarehousesRequest_ResponseSchema,
65
+ unmarshalSetWorkspaceWarehouseConfigRequest_ResponseSchema,
66
+ unmarshalStartRequest_ResponseSchema,
67
+ unmarshalStopRequest_ResponseSchema,
68
+ } from './model';
69
+
70
+ // Package identity segment for this client to be used in the User-Agent header.
71
+ const PACKAGE_SEGMENT = {
72
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
73
+ value: pkgJson.version,
74
+ };
75
+
76
+ class StillRunningError extends Error {}
77
+
78
+ export class WarehousesClient {
79
+ private readonly host: string;
80
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
81
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
82
+ // request.
83
+ private readonly workspaceId: string | undefined;
84
+ private readonly httpClient: HttpClient;
85
+ private readonly logger: Logger;
86
+ // User-Agent header value. Composed once at construction from
87
+ // createDefault() merged with this package's identity and the active
88
+ // credential's name.
89
+ private readonly userAgent: string;
90
+
91
+ constructor(options: ClientOptions) {
92
+ if (options.host === undefined) {
93
+ throw new Error('Host is required.');
94
+ }
95
+ this.host = options.host.replace(/\/$/, '');
96
+ this.workspaceId = options.workspaceId;
97
+ this.logger = options.logger ?? new NoOpLogger();
98
+ const info = createDefault()
99
+ .with(PACKAGE_SEGMENT)
100
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
101
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
102
+ this.userAgent = info.toString();
103
+ this.httpClient = newHttpClient(options);
104
+ }
105
+
106
+ /**
107
+ * Creates a new default warehouse override for a user.
108
+ * Users can create their own override. Admins can create overrides for any user.
109
+ */
110
+ async createDefaultWarehouseOverride(
111
+ req: CreateDefaultWarehouseOverrideRequest,
112
+ options?: CallOptions
113
+ ): Promise<DefaultWarehouseOverride> {
114
+ const url = `${this.host}/api/warehouses/v1/default-warehouse-overrides`;
115
+ const params = new URLSearchParams();
116
+ if (req.defaultWarehouseOverrideId !== undefined) {
117
+ params.append(
118
+ 'default_warehouse_override_id',
119
+ req.defaultWarehouseOverrideId
120
+ );
121
+ }
122
+ const query = params.toString();
123
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
124
+ const body = marshalRequest(
125
+ req.defaultWarehouseOverride,
126
+ marshalDefaultWarehouseOverrideSchema
127
+ );
128
+ let resp: DefaultWarehouseOverride | undefined;
129
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
130
+ const headers = new Headers({'Content-Type': 'application/json'});
131
+ if (this.workspaceId !== undefined) {
132
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
133
+ }
134
+ headers.set('User-Agent', this.userAgent);
135
+ const httpReq = buildHttpRequest(
136
+ 'POST',
137
+ fullUrl,
138
+ headers,
139
+ callSignal,
140
+ body
141
+ );
142
+ const respBody = await executeHttpCall({
143
+ request: httpReq,
144
+ httpClient: this.httpClient,
145
+ logger: this.logger,
146
+ });
147
+ resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
148
+ };
149
+ await executeCall(call, options);
150
+ if (resp === undefined) {
151
+ throw new Error('API call completed without a result.');
152
+ }
153
+ return resp;
154
+ }
155
+
156
+ /** Creates a new SQL warehouse. */
157
+ async createWarehouse(
158
+ req: CreateWarehouseRequest,
159
+ options?: CallOptions
160
+ ): Promise<CreateWarehouseRequest_Response> {
161
+ const url = `${this.host}/api/2.0/sql/warehouses`;
162
+ const body = marshalRequest(req, marshalCreateWarehouseRequestSchema);
163
+ let resp: CreateWarehouseRequest_Response | undefined;
164
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
165
+ const headers = new Headers({'Content-Type': 'application/json'});
166
+ if (this.workspaceId !== undefined) {
167
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
168
+ }
169
+ headers.set('User-Agent', this.userAgent);
170
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
171
+ const respBody = await executeHttpCall({
172
+ request: httpReq,
173
+ httpClient: this.httpClient,
174
+ logger: this.logger,
175
+ });
176
+ resp = parseResponse(
177
+ respBody,
178
+ unmarshalCreateWarehouseRequest_ResponseSchema
179
+ );
180
+ };
181
+ await executeCall(call, options);
182
+ if (resp === undefined) {
183
+ throw new Error('API call completed without a result.');
184
+ }
185
+ return resp;
186
+ }
187
+
188
+ async createWarehouseWaiter(
189
+ req: CreateWarehouseRequest,
190
+ options?: CallOptions
191
+ ): Promise<CreateWarehouseWaiter> {
192
+ const resp = await this.createWarehouse(req, options);
193
+ if (resp.id === undefined) {
194
+ throw new Error('response field id required for polling is missing');
195
+ }
196
+ return new CreateWarehouseWaiter(this, resp.id);
197
+ }
198
+
199
+ /**
200
+ * Deletes the default warehouse override for a user.
201
+ * Users can delete their own override. Admins can delete overrides for any user.
202
+ * After deletion, the workspace default warehouse will be used.
203
+ */
204
+ async deleteDefaultWarehouseOverride(
205
+ req: DeleteDefaultWarehouseOverrideRequest,
206
+ options?: CallOptions
207
+ ): Promise<void> {
208
+ const url = `${this.host}/api/warehouses/v1/${req.name ?? ''}`;
209
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
210
+ const headers = new Headers();
211
+ if (this.workspaceId !== undefined) {
212
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
213
+ }
214
+ headers.set('User-Agent', this.userAgent);
215
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
216
+ await executeHttpCall({
217
+ request: httpReq,
218
+ httpClient: this.httpClient,
219
+ logger: this.logger,
220
+ });
221
+ };
222
+ await executeCall(call, options);
223
+ }
224
+
225
+ /** Deletes a SQL warehouse. */
226
+ async deleteWarehouse(
227
+ req: DeleteWarehouseRequest,
228
+ options?: CallOptions
229
+ ): Promise<DeleteWarehouseRequest_Response> {
230
+ const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}`;
231
+ let resp: DeleteWarehouseRequest_Response | undefined;
232
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
233
+ const headers = new Headers();
234
+ if (this.workspaceId !== undefined) {
235
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
236
+ }
237
+ headers.set('User-Agent', this.userAgent);
238
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
239
+ const respBody = await executeHttpCall({
240
+ request: httpReq,
241
+ httpClient: this.httpClient,
242
+ logger: this.logger,
243
+ });
244
+ resp = parseResponse(
245
+ respBody,
246
+ unmarshalDeleteWarehouseRequest_ResponseSchema
247
+ );
248
+ };
249
+ await executeCall(call, options);
250
+ if (resp === undefined) {
251
+ throw new Error('API call completed without a result.');
252
+ }
253
+ return resp;
254
+ }
255
+
256
+ /** Updates the configuration for a SQL warehouse. */
257
+ async editWarehouse(
258
+ req: EditWarehouseRequest,
259
+ options?: CallOptions
260
+ ): Promise<EditWarehouseRequest_Response> {
261
+ const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}/edit`;
262
+ const body = marshalRequest(req, marshalEditWarehouseRequestSchema);
263
+ let resp: EditWarehouseRequest_Response | undefined;
264
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
265
+ const headers = new Headers({'Content-Type': 'application/json'});
266
+ if (this.workspaceId !== undefined) {
267
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
268
+ }
269
+ headers.set('User-Agent', this.userAgent);
270
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
271
+ const respBody = await executeHttpCall({
272
+ request: httpReq,
273
+ httpClient: this.httpClient,
274
+ logger: this.logger,
275
+ });
276
+ resp = parseResponse(
277
+ respBody,
278
+ unmarshalEditWarehouseRequest_ResponseSchema
279
+ );
280
+ };
281
+ await executeCall(call, options);
282
+ if (resp === undefined) {
283
+ throw new Error('API call completed without a result.');
284
+ }
285
+ return resp;
286
+ }
287
+
288
+ async editWarehouseWaiter(
289
+ req: EditWarehouseRequest,
290
+ options?: CallOptions
291
+ ): Promise<EditWarehouseWaiter> {
292
+ await this.editWarehouse(req, options);
293
+ if (req.id === undefined) {
294
+ throw new Error('request field id required for polling is missing');
295
+ }
296
+ return new EditWarehouseWaiter(this, req.id);
297
+ }
298
+
299
+ /**
300
+ * Returns the default warehouse override for a user.
301
+ * Users can fetch their own override. Admins can fetch overrides for any user.
302
+ * If no override exists, the UI will fallback to the workspace default warehouse.
303
+ */
304
+ async getDefaultWarehouseOverride(
305
+ req: GetDefaultWarehouseOverrideRequest,
306
+ options?: CallOptions
307
+ ): Promise<DefaultWarehouseOverride> {
308
+ const url = `${this.host}/api/warehouses/v1/${req.name ?? ''}`;
309
+ let resp: DefaultWarehouseOverride | undefined;
310
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
311
+ const headers = new Headers();
312
+ if (this.workspaceId !== undefined) {
313
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
314
+ }
315
+ headers.set('User-Agent', this.userAgent);
316
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
317
+ const respBody = await executeHttpCall({
318
+ request: httpReq,
319
+ httpClient: this.httpClient,
320
+ logger: this.logger,
321
+ });
322
+ resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
323
+ };
324
+ await executeCall(call, options);
325
+ if (resp === undefined) {
326
+ throw new Error('API call completed without a result.');
327
+ }
328
+ return resp;
329
+ }
330
+
331
+ /** Gets the information for a single SQL warehouse. */
332
+ async getWarehouse(
333
+ req: GetWarehouseRequest,
334
+ options?: CallOptions
335
+ ): Promise<GetWarehouseRequest_Response> {
336
+ const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}`;
337
+ let resp: GetWarehouseRequest_Response | undefined;
338
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
339
+ const headers = new Headers();
340
+ if (this.workspaceId !== undefined) {
341
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
342
+ }
343
+ headers.set('User-Agent', this.userAgent);
344
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
345
+ const respBody = await executeHttpCall({
346
+ request: httpReq,
347
+ httpClient: this.httpClient,
348
+ logger: this.logger,
349
+ });
350
+ resp = parseResponse(
351
+ respBody,
352
+ unmarshalGetWarehouseRequest_ResponseSchema
353
+ );
354
+ };
355
+ await executeCall(call, options);
356
+ if (resp === undefined) {
357
+ throw new Error('API call completed without a result.');
358
+ }
359
+ return resp;
360
+ }
361
+
362
+ /** Gets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
363
+ async getWorkspaceWarehouseConfig(
364
+ _req: GetWorkspaceWarehouseConfigRequest,
365
+ options?: CallOptions
366
+ ): Promise<GetWorkspaceWarehouseConfigRequest_Response> {
367
+ const url = `${this.host}/api/2.0/sql/config/warehouses`;
368
+ let resp: GetWorkspaceWarehouseConfigRequest_Response | undefined;
369
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
370
+ const headers = new Headers();
371
+ if (this.workspaceId !== undefined) {
372
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
373
+ }
374
+ headers.set('User-Agent', this.userAgent);
375
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
376
+ const respBody = await executeHttpCall({
377
+ request: httpReq,
378
+ httpClient: this.httpClient,
379
+ logger: this.logger,
380
+ });
381
+ resp = parseResponse(
382
+ respBody,
383
+ unmarshalGetWorkspaceWarehouseConfigRequest_ResponseSchema
384
+ );
385
+ };
386
+ await executeCall(call, options);
387
+ if (resp === undefined) {
388
+ throw new Error('API call completed without a result.');
389
+ }
390
+ return resp;
391
+ }
392
+
393
+ /**
394
+ * Lists all default warehouse overrides in the workspace.
395
+ * Only workspace administrators can list all overrides.
396
+ */
397
+ async listDefaultWarehouseOverrides(
398
+ req: ListDefaultWarehouseOverridesRequest,
399
+ options?: CallOptions
400
+ ): Promise<ListDefaultWarehouseOverridesResponse> {
401
+ const url = `${this.host}/api/warehouses/v1/default-warehouse-overrides`;
402
+ const params = new URLSearchParams();
403
+ if (req.pageSize !== undefined) {
404
+ params.append('page_size', String(req.pageSize));
405
+ }
406
+ if (req.pageToken !== undefined) {
407
+ params.append('page_token', req.pageToken);
408
+ }
409
+ const query = params.toString();
410
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
411
+ let resp: ListDefaultWarehouseOverridesResponse | undefined;
412
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
413
+ const headers = new Headers();
414
+ if (this.workspaceId !== undefined) {
415
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
416
+ }
417
+ headers.set('User-Agent', this.userAgent);
418
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
419
+ const respBody = await executeHttpCall({
420
+ request: httpReq,
421
+ httpClient: this.httpClient,
422
+ logger: this.logger,
423
+ });
424
+ resp = parseResponse(
425
+ respBody,
426
+ unmarshalListDefaultWarehouseOverridesResponseSchema
427
+ );
428
+ };
429
+ await executeCall(call, options);
430
+ if (resp === undefined) {
431
+ throw new Error('API call completed without a result.');
432
+ }
433
+ return resp;
434
+ }
435
+
436
+ async *listDefaultWarehouseOverridesIter(
437
+ req: ListDefaultWarehouseOverridesRequest,
438
+ options?: CallOptions
439
+ ): AsyncGenerator<DefaultWarehouseOverride> {
440
+ const pageReq: ListDefaultWarehouseOverridesRequest = {...req};
441
+ for (;;) {
442
+ const resp = await this.listDefaultWarehouseOverrides(pageReq, options);
443
+ for (const item of resp.defaultWarehouseOverrides ?? []) {
444
+ yield item;
445
+ }
446
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
447
+ return;
448
+ }
449
+ pageReq.pageToken = resp.nextPageToken;
450
+ }
451
+ }
452
+
453
+ /** Lists all SQL warehouses that a user has access to. */
454
+ async listWarehouses(
455
+ req: ListWarehousesRequest,
456
+ options?: CallOptions
457
+ ): Promise<ListWarehousesRequest_Response> {
458
+ const url = `${this.host}/api/2.0/sql/warehouses`;
459
+ const params = new URLSearchParams();
460
+ if (req.runAsUserId !== undefined) {
461
+ params.append('run_as_user_id', String(req.runAsUserId));
462
+ }
463
+ if (req.pageSize !== undefined) {
464
+ params.append('page_size', String(req.pageSize));
465
+ }
466
+ if (req.pageToken !== undefined) {
467
+ params.append('page_token', req.pageToken);
468
+ }
469
+ const query = params.toString();
470
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
471
+ let resp: ListWarehousesRequest_Response | undefined;
472
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
473
+ const headers = new Headers();
474
+ if (this.workspaceId !== undefined) {
475
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
476
+ }
477
+ headers.set('User-Agent', this.userAgent);
478
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
479
+ const respBody = await executeHttpCall({
480
+ request: httpReq,
481
+ httpClient: this.httpClient,
482
+ logger: this.logger,
483
+ });
484
+ resp = parseResponse(
485
+ respBody,
486
+ unmarshalListWarehousesRequest_ResponseSchema
487
+ );
488
+ };
489
+ await executeCall(call, options);
490
+ if (resp === undefined) {
491
+ throw new Error('API call completed without a result.');
492
+ }
493
+ return resp;
494
+ }
495
+
496
+ async *listWarehousesIter(
497
+ req: ListWarehousesRequest,
498
+ options?: CallOptions
499
+ ): AsyncGenerator<EndpointInfo> {
500
+ const pageReq: ListWarehousesRequest = {...req};
501
+ for (;;) {
502
+ const resp = await this.listWarehouses(pageReq, options);
503
+ for (const item of resp.warehouses ?? []) {
504
+ yield item;
505
+ }
506
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
507
+ return;
508
+ }
509
+ pageReq.pageToken = resp.nextPageToken;
510
+ }
511
+ }
512
+
513
+ /** Sets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
514
+ async setWorkspaceWarehouseConfig(
515
+ req: SetWorkspaceWarehouseConfigRequest,
516
+ options?: CallOptions
517
+ ): Promise<SetWorkspaceWarehouseConfigRequest_Response> {
518
+ const url = `${this.host}/api/2.0/sql/config/warehouses`;
519
+ const body = marshalRequest(
520
+ req,
521
+ marshalSetWorkspaceWarehouseConfigRequestSchema
522
+ );
523
+ let resp: SetWorkspaceWarehouseConfigRequest_Response | undefined;
524
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
525
+ const headers = new Headers({'Content-Type': 'application/json'});
526
+ if (this.workspaceId !== undefined) {
527
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
528
+ }
529
+ headers.set('User-Agent', this.userAgent);
530
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
531
+ const respBody = await executeHttpCall({
532
+ request: httpReq,
533
+ httpClient: this.httpClient,
534
+ logger: this.logger,
535
+ });
536
+ resp = parseResponse(
537
+ respBody,
538
+ unmarshalSetWorkspaceWarehouseConfigRequest_ResponseSchema
539
+ );
540
+ };
541
+ await executeCall(call, options);
542
+ if (resp === undefined) {
543
+ throw new Error('API call completed without a result.');
544
+ }
545
+ return resp;
546
+ }
547
+
548
+ /** Starts a SQL warehouse. */
549
+ async startWarehouse(
550
+ req: StartRequest,
551
+ options?: CallOptions
552
+ ): Promise<StartRequest_Response> {
553
+ const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}/start`;
554
+ const body = marshalRequest(req, marshalStartRequestSchema);
555
+ let resp: StartRequest_Response | undefined;
556
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
557
+ const headers = new Headers({'Content-Type': 'application/json'});
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('POST', url, headers, callSignal, body);
563
+ const respBody = await executeHttpCall({
564
+ request: httpReq,
565
+ httpClient: this.httpClient,
566
+ logger: this.logger,
567
+ });
568
+ resp = parseResponse(respBody, unmarshalStartRequest_ResponseSchema);
569
+ };
570
+ await executeCall(call, options);
571
+ if (resp === undefined) {
572
+ throw new Error('API call completed without a result.');
573
+ }
574
+ return resp;
575
+ }
576
+
577
+ async startWarehouseWaiter(
578
+ req: StartRequest,
579
+ options?: CallOptions
580
+ ): Promise<StartWarehouseWaiter> {
581
+ await this.startWarehouse(req, options);
582
+ if (req.id === undefined) {
583
+ throw new Error('request field id required for polling is missing');
584
+ }
585
+ return new StartWarehouseWaiter(this, req.id);
586
+ }
587
+
588
+ /** Stops a SQL warehouse. */
589
+ async stopWarehouse(
590
+ req: StopRequest,
591
+ options?: CallOptions
592
+ ): Promise<StopRequest_Response> {
593
+ const url = `${this.host}/api/2.0/sql/warehouses/${req.id ?? ''}/stop`;
594
+ const body = marshalRequest(req, marshalStopRequestSchema);
595
+ let resp: StopRequest_Response | undefined;
596
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
597
+ const headers = new Headers({'Content-Type': 'application/json'});
598
+ if (this.workspaceId !== undefined) {
599
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
600
+ }
601
+ headers.set('User-Agent', this.userAgent);
602
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
603
+ const respBody = await executeHttpCall({
604
+ request: httpReq,
605
+ httpClient: this.httpClient,
606
+ logger: this.logger,
607
+ });
608
+ resp = parseResponse(respBody, unmarshalStopRequest_ResponseSchema);
609
+ };
610
+ await executeCall(call, options);
611
+ if (resp === undefined) {
612
+ throw new Error('API call completed without a result.');
613
+ }
614
+ return resp;
615
+ }
616
+
617
+ async stopWarehouseWaiter(
618
+ req: StopRequest,
619
+ options?: CallOptions
620
+ ): Promise<StopWarehouseWaiter> {
621
+ await this.stopWarehouse(req, options);
622
+ if (req.id === undefined) {
623
+ throw new Error('request field id required for polling is missing');
624
+ }
625
+ return new StopWarehouseWaiter(this, req.id);
626
+ }
627
+
628
+ /**
629
+ * Updates an existing default warehouse override for a user.
630
+ * Users can update their own override. Admins can update overrides for any user.
631
+ */
632
+ async updateDefaultWarehouseOverride(
633
+ req: UpdateDefaultWarehouseOverrideRequest,
634
+ options?: CallOptions
635
+ ): Promise<DefaultWarehouseOverride> {
636
+ const url = `${this.host}/api/warehouses/v1/${req.defaultWarehouseOverride?.name ?? ''}`;
637
+ const params = new URLSearchParams();
638
+ if (req.updateMask !== undefined) {
639
+ params.append('update_mask', req.updateMask.toString());
640
+ }
641
+ if (req.allowMissing !== undefined) {
642
+ params.append('allow_missing', String(req.allowMissing));
643
+ }
644
+ const query = params.toString();
645
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
646
+ const body = marshalRequest(
647
+ req.defaultWarehouseOverride,
648
+ marshalDefaultWarehouseOverrideSchema
649
+ );
650
+ let resp: DefaultWarehouseOverride | undefined;
651
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
652
+ const headers = new Headers({'Content-Type': 'application/json'});
653
+ if (this.workspaceId !== undefined) {
654
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
655
+ }
656
+ headers.set('User-Agent', this.userAgent);
657
+ const httpReq = buildHttpRequest(
658
+ 'PATCH',
659
+ fullUrl,
660
+ headers,
661
+ callSignal,
662
+ body
663
+ );
664
+ const respBody = await executeHttpCall({
665
+ request: httpReq,
666
+ httpClient: this.httpClient,
667
+ logger: this.logger,
668
+ });
669
+ resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
670
+ };
671
+ await executeCall(call, options);
672
+ if (resp === undefined) {
673
+ throw new Error('API call completed without a result.');
674
+ }
675
+ return resp;
676
+ }
677
+ }
678
+
679
+ export class CreateWarehouseWaiter {
680
+ constructor(
681
+ private readonly client: WarehousesClient,
682
+ readonly id: string
683
+ ) {}
684
+
685
+ /**
686
+ * Polls until the operation reaches a terminal state.
687
+ *
688
+ * Throws if a failure state is reached.
689
+ */
690
+ async wait(options?: CallOptions): Promise<GetWarehouseRequest_Response> {
691
+ let result: GetWarehouseRequest_Response | undefined;
692
+
693
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
694
+ const pollResp = await this.client.getWarehouse(
695
+ {
696
+ id: this.id,
697
+ },
698
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
699
+ );
700
+
701
+ const status = pollResp.state;
702
+ if (status === undefined) {
703
+ throw new Error('response missing required status field');
704
+ }
705
+
706
+ switch (status) {
707
+ case EndpointState.RUNNING:
708
+ result = pollResp;
709
+ return;
710
+ case EndpointState.STOPPED:
711
+ case EndpointState.DELETED: {
712
+ const msg = pollResp.health?.summary ?? '(no message)';
713
+ throw new Error(`terminal state ${status}: ${msg}`);
714
+ }
715
+ default:
716
+ throw new StillRunningError();
717
+ }
718
+ };
719
+
720
+ const retryOptions: CallOptions = {
721
+ ...(options?.signal !== undefined && {signal: options.signal}),
722
+ retrier: () =>
723
+ retryOn({}, (err: Error) => {
724
+ return err instanceof StillRunningError;
725
+ }),
726
+ };
727
+ await executeCall(call, retryOptions);
728
+ if (result === undefined) {
729
+ throw new Error('API call completed without a result.');
730
+ }
731
+ return result;
732
+ }
733
+
734
+ /** Checks whether the operation has reached a terminal state. */
735
+ async done(options?: CallOptions): Promise<boolean> {
736
+ const pollResp = await this.client.getWarehouse(
737
+ {
738
+ id: this.id,
739
+ },
740
+ options
741
+ );
742
+
743
+ const status = pollResp.state;
744
+ if (status === undefined) {
745
+ throw new Error('response missing required status field');
746
+ }
747
+
748
+ switch (status) {
749
+ case EndpointState.RUNNING:
750
+ case EndpointState.STOPPED:
751
+ case EndpointState.DELETED:
752
+ return true;
753
+ default:
754
+ return false;
755
+ }
756
+ }
757
+ }
758
+
759
+ export class EditWarehouseWaiter {
760
+ constructor(
761
+ private readonly client: WarehousesClient,
762
+ readonly id: string
763
+ ) {}
764
+
765
+ /**
766
+ * Polls until the operation reaches a terminal state.
767
+ *
768
+ * Throws if a failure state is reached.
769
+ */
770
+ async wait(options?: CallOptions): Promise<GetWarehouseRequest_Response> {
771
+ let result: GetWarehouseRequest_Response | undefined;
772
+
773
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
774
+ const pollResp = await this.client.getWarehouse(
775
+ {
776
+ id: this.id,
777
+ },
778
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
779
+ );
780
+
781
+ const status = pollResp.state;
782
+ if (status === undefined) {
783
+ throw new Error('response missing required status field');
784
+ }
785
+
786
+ switch (status) {
787
+ case EndpointState.RUNNING:
788
+ result = pollResp;
789
+ return;
790
+ case EndpointState.STOPPED:
791
+ case EndpointState.DELETED: {
792
+ const msg = pollResp.health?.summary ?? '(no message)';
793
+ throw new Error(`terminal state ${status}: ${msg}`);
794
+ }
795
+ default:
796
+ throw new StillRunningError();
797
+ }
798
+ };
799
+
800
+ const retryOptions: CallOptions = {
801
+ ...(options?.signal !== undefined && {signal: options.signal}),
802
+ retrier: () =>
803
+ retryOn({}, (err: Error) => {
804
+ return err instanceof StillRunningError;
805
+ }),
806
+ };
807
+ await executeCall(call, retryOptions);
808
+ if (result === undefined) {
809
+ throw new Error('API call completed without a result.');
810
+ }
811
+ return result;
812
+ }
813
+
814
+ /** Checks whether the operation has reached a terminal state. */
815
+ async done(options?: CallOptions): Promise<boolean> {
816
+ const pollResp = await this.client.getWarehouse(
817
+ {
818
+ id: this.id,
819
+ },
820
+ options
821
+ );
822
+
823
+ const status = pollResp.state;
824
+ if (status === undefined) {
825
+ throw new Error('response missing required status field');
826
+ }
827
+
828
+ switch (status) {
829
+ case EndpointState.RUNNING:
830
+ case EndpointState.STOPPED:
831
+ case EndpointState.DELETED:
832
+ return true;
833
+ default:
834
+ return false;
835
+ }
836
+ }
837
+ }
838
+
839
+ export class StartWarehouseWaiter {
840
+ constructor(
841
+ private readonly client: WarehousesClient,
842
+ readonly id: string
843
+ ) {}
844
+
845
+ /**
846
+ * Polls until the operation reaches a terminal state.
847
+ *
848
+ * Throws if a failure state is reached.
849
+ */
850
+ async wait(options?: CallOptions): Promise<GetWarehouseRequest_Response> {
851
+ let result: GetWarehouseRequest_Response | undefined;
852
+
853
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
854
+ const pollResp = await this.client.getWarehouse(
855
+ {
856
+ id: this.id,
857
+ },
858
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
859
+ );
860
+
861
+ const status = pollResp.state;
862
+ if (status === undefined) {
863
+ throw new Error('response missing required status field');
864
+ }
865
+
866
+ switch (status) {
867
+ case EndpointState.RUNNING:
868
+ result = pollResp;
869
+ return;
870
+ case EndpointState.STOPPED:
871
+ case EndpointState.DELETED: {
872
+ const msg = pollResp.health?.summary ?? '(no message)';
873
+ throw new Error(`terminal state ${status}: ${msg}`);
874
+ }
875
+ default:
876
+ throw new StillRunningError();
877
+ }
878
+ };
879
+
880
+ const retryOptions: CallOptions = {
881
+ ...(options?.signal !== undefined && {signal: options.signal}),
882
+ retrier: () =>
883
+ retryOn({}, (err: Error) => {
884
+ return err instanceof StillRunningError;
885
+ }),
886
+ };
887
+ await executeCall(call, retryOptions);
888
+ if (result === undefined) {
889
+ throw new Error('API call completed without a result.');
890
+ }
891
+ return result;
892
+ }
893
+
894
+ /** Checks whether the operation has reached a terminal state. */
895
+ async done(options?: CallOptions): Promise<boolean> {
896
+ const pollResp = await this.client.getWarehouse(
897
+ {
898
+ id: this.id,
899
+ },
900
+ options
901
+ );
902
+
903
+ const status = pollResp.state;
904
+ if (status === undefined) {
905
+ throw new Error('response missing required status field');
906
+ }
907
+
908
+ switch (status) {
909
+ case EndpointState.RUNNING:
910
+ case EndpointState.STOPPED:
911
+ case EndpointState.DELETED:
912
+ return true;
913
+ default:
914
+ return false;
915
+ }
916
+ }
917
+ }
918
+
919
+ export class StopWarehouseWaiter {
920
+ constructor(
921
+ private readonly client: WarehousesClient,
922
+ readonly id: string
923
+ ) {}
924
+
925
+ /**
926
+ * Polls until the operation reaches a terminal state.
927
+ *
928
+ * Throws if a failure state is reached.
929
+ */
930
+ async wait(options?: CallOptions): Promise<GetWarehouseRequest_Response> {
931
+ let result: GetWarehouseRequest_Response | undefined;
932
+
933
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
934
+ const pollResp = await this.client.getWarehouse(
935
+ {
936
+ id: this.id,
937
+ },
938
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
939
+ );
940
+
941
+ const status = pollResp.state;
942
+ if (status === undefined) {
943
+ throw new Error('response missing required status field');
944
+ }
945
+
946
+ switch (status) {
947
+ case EndpointState.STOPPED:
948
+ result = pollResp;
949
+ return;
950
+ default:
951
+ throw new StillRunningError();
952
+ }
953
+ };
954
+
955
+ const retryOptions: CallOptions = {
956
+ ...(options?.signal !== undefined && {signal: options.signal}),
957
+ retrier: () =>
958
+ retryOn({}, (err: Error) => {
959
+ return err instanceof StillRunningError;
960
+ }),
961
+ };
962
+ await executeCall(call, retryOptions);
963
+ if (result === undefined) {
964
+ throw new Error('API call completed without a result.');
965
+ }
966
+ return result;
967
+ }
968
+
969
+ /** Checks whether the operation has reached a terminal state. */
970
+ async done(options?: CallOptions): Promise<boolean> {
971
+ const pollResp = await this.client.getWarehouse(
972
+ {
973
+ id: this.id,
974
+ },
975
+ options
976
+ );
977
+
978
+ const status = pollResp.state;
979
+ if (status === undefined) {
980
+ throw new Error('response missing required status field');
981
+ }
982
+
983
+ switch (status) {
984
+ case EndpointState.STOPPED:
985
+ return true;
986
+ default:
987
+ return false;
988
+ }
989
+ }
990
+ }