@databricks/sdk-warehouses 0.34.0 → 0.35.0

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/dist/v1/client.js CHANGED
@@ -1,734 +1,556 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
- import { VERSION as AUTH_VERSION } from '@databricks/sdk-auth';
3
- import { createDefault } from '@databricks/sdk-core/clientinfo';
4
- import { NoOpLogger } from '@databricks/sdk-core/logger';
5
- import { resolveClientConfig } from './transport';
6
- import { buildHttpRequest, executeCall, executeHttpCall, marshalRequest, parseResponse, executeWait, StillRunningError, } from './utils';
7
- import pkgJson from '../../package.json' with { type: 'json' };
8
- import { EndpointState, marshalCreateWarehouseRequestSchema, marshalDefaultWarehouseOverrideSchema, marshalEditWarehouseRequestSchema, marshalSetWorkspaceWarehouseConfigRequestSchema, marshalStartRequestSchema, marshalStopRequestSchema, unmarshalCreateWarehouseResponseSchema, unmarshalDefaultWarehouseOverrideSchema, unmarshalDeleteWarehouseResponseSchema, unmarshalEditWarehouseResponseSchema, unmarshalGetWarehouseResponseSchema, unmarshalGetWorkspaceWarehouseConfigResponseSchema, unmarshalListDefaultWarehouseOverridesResponseSchema, unmarshalListWarehousesResponseSchema, unmarshalSetWorkspaceWarehouseConfigResponseSchema, unmarshalStartResponseSchema, unmarshalStopResponseSchema, } from './model';
9
- // Package identity segment for this client to be used in the User-Agent header.
1
+ import { resolveClientConfig } from "./transport.js";
2
+ import { StillRunningError, buildHttpRequest, executeCall, executeHttpCall, executeWait, marshalRequest, parseResponse } from "./utils.js";
3
+ import { name, version } from "../package.js";
4
+ import { EndpointState, marshalCreateWarehouseRequestSchema, marshalDefaultWarehouseOverrideSchema, marshalEditWarehouseRequestSchema, marshalSetWorkspaceWarehouseConfigRequestSchema, marshalStartRequestSchema, marshalStopRequestSchema, unmarshalCreateWarehouseResponseSchema, unmarshalDefaultWarehouseOverrideSchema, unmarshalDeleteWarehouseResponseSchema, unmarshalEditWarehouseResponseSchema, unmarshalGetWarehouseResponseSchema, unmarshalGetWorkspaceWarehouseConfigResponseSchema, unmarshalListDefaultWarehouseOverridesResponseSchema, unmarshalListWarehousesResponseSchema, unmarshalSetWorkspaceWarehouseConfigResponseSchema, unmarshalStartResponseSchema, unmarshalStopResponseSchema } from "./model.js";
5
+ import { VERSION } from "@databricks/sdk-auth";
6
+ import { createDefault } from "@databricks/sdk-core/clientinfo";
7
+ import { NoOpLogger } from "@databricks/sdk-core/logger";
8
+
9
+ //#region src/v1/client.ts
10
10
  const PACKAGE_SEGMENT = {
11
- key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
12
- value: pkgJson.version,
11
+ key: "sdk-js-" + name.replace(/^@[^/]+\/sdk-/, ""),
12
+ value: version
13
13
  };
14
- export class WarehousesClient {
15
- options;
16
- logger;
17
- // User-Agent header value. Composed once at construction from
18
- // createDefault() merged with this package's identity and the active
19
- // credential's name.
20
- userAgent;
21
- // Memoized configuration. The profile is resolved once, lazily, on the first
22
- // request, then reused; host, workspaceId/accountId, and credentials are
23
- // filled from it when not set explicitly on the options.
24
- config;
25
- constructor(options) {
26
- this.options = options;
27
- this.logger = options.logger ?? new NoOpLogger();
28
- const info = createDefault()
29
- .with(PACKAGE_SEGMENT)
30
- .with({ key: 'sdk-js-auth', value: AUTH_VERSION })
31
- .with({ key: 'auth', value: options.credentials?.name() ?? 'default' });
32
- this.userAgent = info.toString();
33
- }
34
- resolveConfig() {
35
- this.config ??= resolveClientConfig(this.options);
36
- return this.config;
37
- }
38
- /**
39
- * Creates a new default warehouse override for a user.
40
- * Users can create their own override. Admins can create overrides for any user.
41
- */
42
- async createDefaultWarehouseOverride(req, options) {
43
- const { host, workspaceId, httpClient } = await this.resolveConfig();
44
- const url = `${host}/api/warehouses/v1/default-warehouse-overrides`;
45
- const params = new URLSearchParams();
46
- if (req.defaultWarehouseOverrideId !== undefined) {
47
- params.append('default_warehouse_override_id', req.defaultWarehouseOverrideId);
48
- }
49
- const query = params.toString();
50
- const fullUrl = query !== '' ? `${url}?${query}` : url;
51
- const body = marshalRequest(req.defaultWarehouseOverride, marshalDefaultWarehouseOverrideSchema);
52
- let resp;
53
- const call = async (callSignal) => {
54
- const headers = new Headers({ 'Content-Type': 'application/json' });
55
- if (workspaceId !== undefined) {
56
- headers.set('X-Databricks-Workspace-Id', workspaceId);
57
- }
58
- headers.set('User-Agent', this.userAgent);
59
- const httpReq = buildHttpRequest('POST', fullUrl, headers, callSignal, body);
60
- const respBody = await executeHttpCall({
61
- request: httpReq,
62
- httpClient,
63
- logger: this.logger,
64
- });
65
- resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
66
- };
67
- await executeCall(call, options);
68
- if (resp === undefined) {
69
- throw new Error('operation completed without a result.');
70
- }
71
- return resp;
72
- }
73
- /** Creates a new SQL warehouse. */
74
- async createWarehouseBase(req, options) {
75
- const { host, workspaceId, httpClient } = await this.resolveConfig();
76
- const url = `${host}/api/2.0/sql/warehouses`;
77
- const body = marshalRequest(req, marshalCreateWarehouseRequestSchema);
78
- let resp;
79
- const call = async (callSignal) => {
80
- const headers = new Headers({ 'Content-Type': 'application/json' });
81
- if (workspaceId !== undefined) {
82
- headers.set('X-Databricks-Workspace-Id', workspaceId);
83
- }
84
- headers.set('User-Agent', this.userAgent);
85
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
86
- const respBody = await executeHttpCall({
87
- request: httpReq,
88
- httpClient,
89
- logger: this.logger,
90
- });
91
- resp = parseResponse(respBody, unmarshalCreateWarehouseResponseSchema);
92
- };
93
- await executeCall(call, options);
94
- if (resp === undefined) {
95
- throw new Error('operation completed without a result.');
96
- }
97
- return resp;
98
- }
99
- /** Creates a new SQL warehouse. */
100
- async createWarehouse(req, options) {
101
- const resp = await this.createWarehouseBase(req, options);
102
- if (resp.id === undefined) {
103
- throw new Error('response field id required for polling is missing');
104
- }
105
- return new CreateWarehouseWaiter(this, resp.id);
106
- }
107
- /**
108
- * Deletes the default warehouse override for a user.
109
- * Users can delete their own override. Admins can delete overrides for any user.
110
- * After deletion, the workspace default warehouse will be used.
111
- */
112
- async deleteDefaultWarehouseOverride(req, options) {
113
- const { host, workspaceId, httpClient } = await this.resolveConfig();
114
- const url = `${host}/api/warehouses/v1/${req.name ?? ''}`;
115
- const call = async (callSignal) => {
116
- const headers = new Headers();
117
- if (workspaceId !== undefined) {
118
- headers.set('X-Databricks-Workspace-Id', workspaceId);
119
- }
120
- headers.set('User-Agent', this.userAgent);
121
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
122
- await executeHttpCall({
123
- request: httpReq,
124
- httpClient,
125
- logger: this.logger,
126
- });
127
- };
128
- await executeCall(call, options);
129
- }
130
- /** Deletes a SQL warehouse. */
131
- async deleteWarehouse(req, options) {
132
- const { host, workspaceId, httpClient } = await this.resolveConfig();
133
- const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ''}`;
134
- let resp;
135
- const call = async (callSignal) => {
136
- const headers = new Headers();
137
- if (workspaceId !== undefined) {
138
- headers.set('X-Databricks-Workspace-Id', workspaceId);
139
- }
140
- headers.set('User-Agent', this.userAgent);
141
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
142
- const respBody = await executeHttpCall({
143
- request: httpReq,
144
- httpClient,
145
- logger: this.logger,
146
- });
147
- resp = parseResponse(respBody, unmarshalDeleteWarehouseResponseSchema);
148
- };
149
- await executeCall(call, options);
150
- if (resp === undefined) {
151
- throw new Error('operation completed without a result.');
152
- }
153
- return resp;
154
- }
155
- /** Updates the configuration for a SQL warehouse. */
156
- async editWarehouseBase(req, options) {
157
- const { host, workspaceId, httpClient } = await this.resolveConfig();
158
- const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ''}/edit`;
159
- const body = marshalRequest(req, marshalEditWarehouseRequestSchema);
160
- let resp;
161
- const call = async (callSignal) => {
162
- const headers = new Headers({ 'Content-Type': 'application/json' });
163
- if (workspaceId !== undefined) {
164
- headers.set('X-Databricks-Workspace-Id', workspaceId);
165
- }
166
- headers.set('User-Agent', this.userAgent);
167
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
168
- const respBody = await executeHttpCall({
169
- request: httpReq,
170
- httpClient,
171
- logger: this.logger,
172
- });
173
- resp = parseResponse(respBody, unmarshalEditWarehouseResponseSchema);
174
- };
175
- await executeCall(call, options);
176
- if (resp === undefined) {
177
- throw new Error('operation completed without a result.');
178
- }
179
- return resp;
180
- }
181
- /** Updates the configuration for a SQL warehouse. */
182
- async editWarehouse(req, options) {
183
- await this.editWarehouseBase(req, options);
184
- if (req.id === undefined) {
185
- throw new Error('request field id required for polling is missing');
186
- }
187
- return new EditWarehouseWaiter(this, req.id);
188
- }
189
- /**
190
- * Returns the default warehouse override for a user.
191
- * Users can fetch their own override. Admins can fetch overrides for any user.
192
- * If no override exists, the UI will fallback to the workspace default warehouse.
193
- */
194
- async getDefaultWarehouseOverride(req, options) {
195
- const { host, workspaceId, httpClient } = await this.resolveConfig();
196
- const url = `${host}/api/warehouses/v1/${req.name ?? ''}`;
197
- let resp;
198
- const call = async (callSignal) => {
199
- const headers = new Headers();
200
- if (workspaceId !== undefined) {
201
- headers.set('X-Databricks-Workspace-Id', workspaceId);
202
- }
203
- headers.set('User-Agent', this.userAgent);
204
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
205
- const respBody = await executeHttpCall({
206
- request: httpReq,
207
- httpClient,
208
- logger: this.logger,
209
- });
210
- resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
211
- };
212
- await executeCall(call, options);
213
- if (resp === undefined) {
214
- throw new Error('operation completed without a result.');
215
- }
216
- return resp;
217
- }
218
- /** Gets the information for a single SQL warehouse. */
219
- async getWarehouse(req, options) {
220
- const { host, workspaceId, httpClient } = await this.resolveConfig();
221
- const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ''}`;
222
- let resp;
223
- const call = async (callSignal) => {
224
- const headers = new Headers();
225
- if (workspaceId !== undefined) {
226
- headers.set('X-Databricks-Workspace-Id', workspaceId);
227
- }
228
- headers.set('User-Agent', this.userAgent);
229
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
230
- const respBody = await executeHttpCall({
231
- request: httpReq,
232
- httpClient,
233
- logger: this.logger,
234
- });
235
- resp = parseResponse(respBody, unmarshalGetWarehouseResponseSchema);
236
- };
237
- await executeCall(call, options);
238
- if (resp === undefined) {
239
- throw new Error('operation completed without a result.');
240
- }
241
- return resp;
242
- }
243
- /** Gets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
244
- async getWorkspaceWarehouseConfig(_req, options) {
245
- const { host, workspaceId, httpClient } = await this.resolveConfig();
246
- const url = `${host}/api/2.0/sql/config/warehouses`;
247
- let resp;
248
- const call = async (callSignal) => {
249
- const headers = new Headers();
250
- if (workspaceId !== undefined) {
251
- headers.set('X-Databricks-Workspace-Id', workspaceId);
252
- }
253
- headers.set('User-Agent', this.userAgent);
254
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
255
- const respBody = await executeHttpCall({
256
- request: httpReq,
257
- httpClient,
258
- logger: this.logger,
259
- });
260
- resp = parseResponse(respBody, unmarshalGetWorkspaceWarehouseConfigResponseSchema);
261
- };
262
- await executeCall(call, options);
263
- if (resp === undefined) {
264
- throw new Error('operation completed without a result.');
265
- }
266
- return resp;
267
- }
268
- /**
269
- * Lists all default warehouse overrides in the workspace.
270
- * Only workspace administrators can list all overrides.
271
- */
272
- async listDefaultWarehouseOverrides(req, options) {
273
- const { host, workspaceId, httpClient } = await this.resolveConfig();
274
- const url = `${host}/api/warehouses/v1/default-warehouse-overrides`;
275
- const params = new URLSearchParams();
276
- if (req.pageSize !== undefined) {
277
- params.append('page_size', String(req.pageSize));
278
- }
279
- if (req.pageToken !== undefined) {
280
- params.append('page_token', req.pageToken);
281
- }
282
- const query = params.toString();
283
- const fullUrl = query !== '' ? `${url}?${query}` : url;
284
- let resp;
285
- const call = async (callSignal) => {
286
- const headers = new Headers();
287
- if (workspaceId !== undefined) {
288
- headers.set('X-Databricks-Workspace-Id', workspaceId);
289
- }
290
- headers.set('User-Agent', this.userAgent);
291
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
292
- const respBody = await executeHttpCall({
293
- request: httpReq,
294
- httpClient,
295
- logger: this.logger,
296
- });
297
- resp = parseResponse(respBody, unmarshalListDefaultWarehouseOverridesResponseSchema);
298
- };
299
- await executeCall(call, options);
300
- if (resp === undefined) {
301
- throw new Error('operation completed without a result.');
302
- }
303
- return resp;
304
- }
305
- async *listDefaultWarehouseOverridesIter(req, options) {
306
- const pageReq = { ...req };
307
- for (;;) {
308
- const resp = await this.listDefaultWarehouseOverrides(pageReq, options);
309
- for (const item of resp.defaultWarehouseOverrides ?? []) {
310
- yield item;
311
- }
312
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
313
- return;
314
- }
315
- pageReq.pageToken = resp.nextPageToken;
316
- }
317
- }
318
- /** Lists all SQL warehouses that a user has access to. */
319
- async listWarehouses(req, options) {
320
- const { host, workspaceId, httpClient } = await this.resolveConfig();
321
- const url = `${host}/api/2.0/sql/warehouses`;
322
- const params = new URLSearchParams();
323
- if (req.runAsUserId !== undefined) {
324
- params.append('run_as_user_id', String(req.runAsUserId));
325
- }
326
- if (req.pageSize !== undefined) {
327
- params.append('page_size', String(req.pageSize));
328
- }
329
- if (req.pageToken !== undefined) {
330
- params.append('page_token', req.pageToken);
331
- }
332
- const query = params.toString();
333
- const fullUrl = query !== '' ? `${url}?${query}` : url;
334
- let resp;
335
- const call = async (callSignal) => {
336
- const headers = new Headers();
337
- if (workspaceId !== undefined) {
338
- headers.set('X-Databricks-Workspace-Id', workspaceId);
339
- }
340
- headers.set('User-Agent', this.userAgent);
341
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
342
- const respBody = await executeHttpCall({
343
- request: httpReq,
344
- httpClient,
345
- logger: this.logger,
346
- });
347
- resp = parseResponse(respBody, unmarshalListWarehousesResponseSchema);
348
- };
349
- await executeCall(call, options);
350
- if (resp === undefined) {
351
- throw new Error('operation completed without a result.');
352
- }
353
- return resp;
354
- }
355
- async *listWarehousesIter(req, options) {
356
- const pageReq = { ...req };
357
- for (;;) {
358
- const resp = await this.listWarehouses(pageReq, options);
359
- for (const item of resp.warehouses ?? []) {
360
- yield item;
361
- }
362
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
363
- return;
364
- }
365
- pageReq.pageToken = resp.nextPageToken;
366
- }
367
- }
368
- /** Sets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
369
- async setWorkspaceWarehouseConfig(req, options) {
370
- const { host, workspaceId, httpClient } = await this.resolveConfig();
371
- const url = `${host}/api/2.0/sql/config/warehouses`;
372
- const body = marshalRequest(req, marshalSetWorkspaceWarehouseConfigRequestSchema);
373
- let resp;
374
- const call = async (callSignal) => {
375
- const headers = new Headers({ 'Content-Type': 'application/json' });
376
- if (workspaceId !== undefined) {
377
- headers.set('X-Databricks-Workspace-Id', workspaceId);
378
- }
379
- headers.set('User-Agent', this.userAgent);
380
- const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
381
- const respBody = await executeHttpCall({
382
- request: httpReq,
383
- httpClient,
384
- logger: this.logger,
385
- });
386
- resp = parseResponse(respBody, unmarshalSetWorkspaceWarehouseConfigResponseSchema);
387
- };
388
- await executeCall(call, options);
389
- if (resp === undefined) {
390
- throw new Error('operation completed without a result.');
391
- }
392
- return resp;
393
- }
394
- /** Starts a SQL warehouse. */
395
- async startWarehouseBase(req, options) {
396
- const { host, workspaceId, httpClient } = await this.resolveConfig();
397
- const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ''}/start`;
398
- const body = marshalRequest(req, marshalStartRequestSchema);
399
- let resp;
400
- const call = async (callSignal) => {
401
- const headers = new Headers({ 'Content-Type': 'application/json' });
402
- if (workspaceId !== undefined) {
403
- headers.set('X-Databricks-Workspace-Id', workspaceId);
404
- }
405
- headers.set('User-Agent', this.userAgent);
406
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
407
- const respBody = await executeHttpCall({
408
- request: httpReq,
409
- httpClient,
410
- logger: this.logger,
411
- });
412
- resp = parseResponse(respBody, unmarshalStartResponseSchema);
413
- };
414
- await executeCall(call, options);
415
- if (resp === undefined) {
416
- throw new Error('operation completed without a result.');
417
- }
418
- return resp;
419
- }
420
- /** Starts a SQL warehouse. */
421
- async startWarehouse(req, options) {
422
- await this.startWarehouseBase(req, options);
423
- if (req.id === undefined) {
424
- throw new Error('request field id required for polling is missing');
425
- }
426
- return new StartWarehouseWaiter(this, req.id);
427
- }
428
- /** Stops a SQL warehouse. */
429
- async stopWarehouseBase(req, options) {
430
- const { host, workspaceId, httpClient } = await this.resolveConfig();
431
- const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ''}/stop`;
432
- const body = marshalRequest(req, marshalStopRequestSchema);
433
- let resp;
434
- const call = async (callSignal) => {
435
- const headers = new Headers({ 'Content-Type': 'application/json' });
436
- if (workspaceId !== undefined) {
437
- headers.set('X-Databricks-Workspace-Id', workspaceId);
438
- }
439
- headers.set('User-Agent', this.userAgent);
440
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
441
- const respBody = await executeHttpCall({
442
- request: httpReq,
443
- httpClient,
444
- logger: this.logger,
445
- });
446
- resp = parseResponse(respBody, unmarshalStopResponseSchema);
447
- };
448
- await executeCall(call, options);
449
- if (resp === undefined) {
450
- throw new Error('operation completed without a result.');
451
- }
452
- return resp;
453
- }
454
- /** Stops a SQL warehouse. */
455
- async stopWarehouse(req, options) {
456
- await this.stopWarehouseBase(req, options);
457
- if (req.id === undefined) {
458
- throw new Error('request field id required for polling is missing');
459
- }
460
- return new StopWarehouseWaiter(this, req.id);
461
- }
462
- /**
463
- * Updates an existing default warehouse override for a user.
464
- * Users can update their own override. Admins can update overrides for any user.
465
- */
466
- async updateDefaultWarehouseOverride(req, options) {
467
- const { host, workspaceId, httpClient } = await this.resolveConfig();
468
- const url = `${host}/api/warehouses/v1/${req.defaultWarehouseOverride?.name ?? ''}`;
469
- const params = new URLSearchParams();
470
- if (req.updateMask !== undefined) {
471
- params.append('update_mask', req.updateMask.toString());
472
- }
473
- if (req.allowMissing !== undefined) {
474
- params.append('allow_missing', String(req.allowMissing));
475
- }
476
- const query = params.toString();
477
- const fullUrl = query !== '' ? `${url}?${query}` : url;
478
- const body = marshalRequest(req.defaultWarehouseOverride, marshalDefaultWarehouseOverrideSchema);
479
- let resp;
480
- const call = async (callSignal) => {
481
- const headers = new Headers({ 'Content-Type': 'application/json' });
482
- if (workspaceId !== undefined) {
483
- headers.set('X-Databricks-Workspace-Id', workspaceId);
484
- }
485
- headers.set('User-Agent', this.userAgent);
486
- const httpReq = buildHttpRequest('PATCH', fullUrl, headers, callSignal, body);
487
- const respBody = await executeHttpCall({
488
- request: httpReq,
489
- httpClient,
490
- logger: this.logger,
491
- });
492
- resp = parseResponse(respBody, unmarshalDefaultWarehouseOverrideSchema);
493
- };
494
- await executeCall(call, options);
495
- if (resp === undefined) {
496
- throw new Error('operation completed without a result.');
497
- }
498
- return resp;
499
- }
500
- }
501
- export class CreateWarehouseWaiter {
502
- client;
503
- id;
504
- constructor(client, id) {
505
- this.client = client;
506
- this.id = id;
507
- }
508
- /**
509
- * Polls until the operation reaches a terminal state.
510
- *
511
- * Throws if a failure state is reached.
512
- */
513
- async wait(options) {
514
- let result;
515
- const call = async (callSignal) => {
516
- const pollResp = await this.client.getWarehouse({
517
- id: this.id,
518
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
519
- const status = pollResp.state;
520
- if (status === undefined) {
521
- throw new Error('response missing required status field');
522
- }
523
- switch (status) {
524
- case EndpointState.RUNNING:
525
- result = pollResp;
526
- return;
527
- case EndpointState.STOPPED:
528
- case EndpointState.DELETED: {
529
- const msg = pollResp.health?.summary ?? '(no message)';
530
- throw new Error(`terminal state ${status}: ${msg}`);
531
- }
532
- default:
533
- throw new StillRunningError();
534
- }
535
- };
536
- await executeWait(call, options);
537
- if (result === undefined) {
538
- throw new Error('operation completed without a result.');
539
- }
540
- return result;
541
- }
542
- /** Checks whether the operation has reached a terminal state. */
543
- async done(options) {
544
- const pollResp = await this.client.getWarehouse({
545
- id: this.id,
546
- }, options);
547
- const status = pollResp.state;
548
- if (status === undefined) {
549
- throw new Error('response missing required status field');
550
- }
551
- switch (status) {
552
- case EndpointState.RUNNING:
553
- case EndpointState.STOPPED:
554
- case EndpointState.DELETED:
555
- return true;
556
- default:
557
- return false;
558
- }
559
- }
560
- }
561
- export class EditWarehouseWaiter {
562
- client;
563
- id;
564
- constructor(client, id) {
565
- this.client = client;
566
- this.id = id;
567
- }
568
- /**
569
- * Polls until the operation reaches a terminal state.
570
- *
571
- * Throws if a failure state is reached.
572
- */
573
- async wait(options) {
574
- let result;
575
- const call = async (callSignal) => {
576
- const pollResp = await this.client.getWarehouse({
577
- id: this.id,
578
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
579
- const status = pollResp.state;
580
- if (status === undefined) {
581
- throw new Error('response missing required status field');
582
- }
583
- switch (status) {
584
- case EndpointState.RUNNING:
585
- result = pollResp;
586
- return;
587
- case EndpointState.STOPPED:
588
- case EndpointState.DELETED: {
589
- const msg = pollResp.health?.summary ?? '(no message)';
590
- throw new Error(`terminal state ${status}: ${msg}`);
591
- }
592
- default:
593
- throw new StillRunningError();
594
- }
595
- };
596
- await executeWait(call, options);
597
- if (result === undefined) {
598
- throw new Error('operation completed without a result.');
599
- }
600
- return result;
601
- }
602
- /** Checks whether the operation has reached a terminal state. */
603
- async done(options) {
604
- const pollResp = await this.client.getWarehouse({
605
- id: this.id,
606
- }, options);
607
- const status = pollResp.state;
608
- if (status === undefined) {
609
- throw new Error('response missing required status field');
610
- }
611
- switch (status) {
612
- case EndpointState.RUNNING:
613
- case EndpointState.STOPPED:
614
- case EndpointState.DELETED:
615
- return true;
616
- default:
617
- return false;
618
- }
619
- }
620
- }
621
- export class StartWarehouseWaiter {
622
- client;
623
- id;
624
- constructor(client, id) {
625
- this.client = client;
626
- this.id = id;
627
- }
628
- /**
629
- * Polls until the operation reaches a terminal state.
630
- *
631
- * Throws if a failure state is reached.
632
- */
633
- async wait(options) {
634
- let result;
635
- const call = async (callSignal) => {
636
- const pollResp = await this.client.getWarehouse({
637
- id: this.id,
638
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
639
- const status = pollResp.state;
640
- if (status === undefined) {
641
- throw new Error('response missing required status field');
642
- }
643
- switch (status) {
644
- case EndpointState.RUNNING:
645
- result = pollResp;
646
- return;
647
- case EndpointState.STOPPED:
648
- case EndpointState.DELETED: {
649
- const msg = pollResp.health?.summary ?? '(no message)';
650
- throw new Error(`terminal state ${status}: ${msg}`);
651
- }
652
- default:
653
- throw new StillRunningError();
654
- }
655
- };
656
- await executeWait(call, options);
657
- if (result === undefined) {
658
- throw new Error('operation completed without a result.');
659
- }
660
- return result;
661
- }
662
- /** Checks whether the operation has reached a terminal state. */
663
- async done(options) {
664
- const pollResp = await this.client.getWarehouse({
665
- id: this.id,
666
- }, options);
667
- const status = pollResp.state;
668
- if (status === undefined) {
669
- throw new Error('response missing required status field');
670
- }
671
- switch (status) {
672
- case EndpointState.RUNNING:
673
- case EndpointState.STOPPED:
674
- case EndpointState.DELETED:
675
- return true;
676
- default:
677
- return false;
678
- }
679
- }
680
- }
681
- export class StopWarehouseWaiter {
682
- client;
683
- id;
684
- constructor(client, id) {
685
- this.client = client;
686
- this.id = id;
687
- }
688
- /**
689
- * Polls until the operation reaches a terminal state.
690
- *
691
- * Throws if a failure state is reached.
692
- */
693
- async wait(options) {
694
- let result;
695
- const call = async (callSignal) => {
696
- const pollResp = await this.client.getWarehouse({
697
- id: this.id,
698
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
699
- const status = pollResp.state;
700
- if (status === undefined) {
701
- throw new Error('response missing required status field');
702
- }
703
- switch (status) {
704
- case EndpointState.STOPPED:
705
- result = pollResp;
706
- return;
707
- default:
708
- throw new StillRunningError();
709
- }
710
- };
711
- await executeWait(call, options);
712
- if (result === undefined) {
713
- throw new Error('operation completed without a result.');
714
- }
715
- return result;
716
- }
717
- /** Checks whether the operation has reached a terminal state. */
718
- async done(options) {
719
- const pollResp = await this.client.getWarehouse({
720
- id: this.id,
721
- }, options);
722
- const status = pollResp.state;
723
- if (status === undefined) {
724
- throw new Error('response missing required status field');
725
- }
726
- switch (status) {
727
- case EndpointState.STOPPED:
728
- return true;
729
- default:
730
- return false;
731
- }
732
- }
733
- }
14
+ var WarehousesClient = class {
15
+ options;
16
+ logger;
17
+ userAgent;
18
+ config;
19
+ constructor(options) {
20
+ this.options = options;
21
+ this.logger = options.logger ?? new NoOpLogger();
22
+ this.userAgent = createDefault().with(PACKAGE_SEGMENT).with({
23
+ key: "sdk-js-auth",
24
+ value: VERSION
25
+ }).with({
26
+ key: "auth",
27
+ value: options.credentials?.name() ?? "default"
28
+ }).toString();
29
+ }
30
+ resolveConfig() {
31
+ this.config ??= resolveClientConfig(this.options);
32
+ return this.config;
33
+ }
34
+ /**
35
+ * Creates a new default warehouse override for a user.
36
+ * Users can create their own override. Admins can create overrides for any user.
37
+ */
38
+ async createDefaultWarehouseOverride(req, options) {
39
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
40
+ const url = `${host}/api/warehouses/v1/default-warehouse-overrides`;
41
+ const params = new URLSearchParams();
42
+ if (req.defaultWarehouseOverrideId !== void 0) params.append("default_warehouse_override_id", req.defaultWarehouseOverrideId);
43
+ const query = params.toString();
44
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
45
+ const body = marshalRequest(req.defaultWarehouseOverride, marshalDefaultWarehouseOverrideSchema);
46
+ let resp;
47
+ const call = async (callSignal) => {
48
+ const headers = new Headers({ "Content-Type": "application/json" });
49
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
50
+ headers.set("User-Agent", this.userAgent);
51
+ resp = parseResponse(await executeHttpCall({
52
+ request: buildHttpRequest("POST", fullUrl, headers, callSignal, body),
53
+ httpClient,
54
+ logger: this.logger
55
+ }), unmarshalDefaultWarehouseOverrideSchema);
56
+ };
57
+ await executeCall(call, options);
58
+ if (resp === void 0) throw new Error("operation completed without a result.");
59
+ return resp;
60
+ }
61
+ /** Creates a new SQL warehouse. */
62
+ async createWarehouseBase(req, options) {
63
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
64
+ const url = `${host}/api/2.0/sql/warehouses`;
65
+ const body = marshalRequest(req, marshalCreateWarehouseRequestSchema);
66
+ let resp;
67
+ const call = async (callSignal) => {
68
+ const headers = new Headers({ "Content-Type": "application/json" });
69
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
70
+ headers.set("User-Agent", this.userAgent);
71
+ resp = parseResponse(await executeHttpCall({
72
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
73
+ httpClient,
74
+ logger: this.logger
75
+ }), unmarshalCreateWarehouseResponseSchema);
76
+ };
77
+ await executeCall(call, options);
78
+ if (resp === void 0) throw new Error("operation completed without a result.");
79
+ return resp;
80
+ }
81
+ /** Creates a new SQL warehouse. */
82
+ async createWarehouse(req, options) {
83
+ const resp = await this.createWarehouseBase(req, options);
84
+ if (resp.id === void 0) throw new Error("response field id required for polling is missing");
85
+ return new CreateWarehouseWaiter(this, resp.id);
86
+ }
87
+ /**
88
+ * Deletes the default warehouse override for a user.
89
+ * Users can delete their own override. Admins can delete overrides for any user.
90
+ * After deletion, the workspace default warehouse will be used.
91
+ */
92
+ async deleteDefaultWarehouseOverride(req, options) {
93
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
94
+ const url = `${host}/api/warehouses/v1/${req.name ?? ""}`;
95
+ const call = async (callSignal) => {
96
+ const headers = new Headers();
97
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
98
+ headers.set("User-Agent", this.userAgent);
99
+ await executeHttpCall({
100
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
101
+ httpClient,
102
+ logger: this.logger
103
+ });
104
+ };
105
+ await executeCall(call, options);
106
+ }
107
+ /** Deletes a SQL warehouse. */
108
+ async deleteWarehouse(req, options) {
109
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
110
+ const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ""}`;
111
+ let resp;
112
+ const call = async (callSignal) => {
113
+ const headers = new Headers();
114
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
115
+ headers.set("User-Agent", this.userAgent);
116
+ resp = parseResponse(await executeHttpCall({
117
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
118
+ httpClient,
119
+ logger: this.logger
120
+ }), unmarshalDeleteWarehouseResponseSchema);
121
+ };
122
+ await executeCall(call, options);
123
+ if (resp === void 0) throw new Error("operation completed without a result.");
124
+ return resp;
125
+ }
126
+ /** Updates the configuration for a SQL warehouse. */
127
+ async editWarehouseBase(req, options) {
128
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
129
+ const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ""}/edit`;
130
+ const body = marshalRequest(req, marshalEditWarehouseRequestSchema);
131
+ let resp;
132
+ const call = async (callSignal) => {
133
+ const headers = new Headers({ "Content-Type": "application/json" });
134
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
135
+ headers.set("User-Agent", this.userAgent);
136
+ resp = parseResponse(await executeHttpCall({
137
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
138
+ httpClient,
139
+ logger: this.logger
140
+ }), unmarshalEditWarehouseResponseSchema);
141
+ };
142
+ await executeCall(call, options);
143
+ if (resp === void 0) throw new Error("operation completed without a result.");
144
+ return resp;
145
+ }
146
+ /** Updates the configuration for a SQL warehouse. */
147
+ async editWarehouse(req, options) {
148
+ await this.editWarehouseBase(req, options);
149
+ if (req.id === void 0) throw new Error("request field id required for polling is missing");
150
+ return new EditWarehouseWaiter(this, req.id);
151
+ }
152
+ /**
153
+ * Returns the default warehouse override for a user.
154
+ * Users can fetch their own override. Admins can fetch overrides for any user.
155
+ * If no override exists, the UI will fallback to the workspace default warehouse.
156
+ */
157
+ async getDefaultWarehouseOverride(req, options) {
158
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
159
+ const url = `${host}/api/warehouses/v1/${req.name ?? ""}`;
160
+ let resp;
161
+ const call = async (callSignal) => {
162
+ const headers = new Headers();
163
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
164
+ headers.set("User-Agent", this.userAgent);
165
+ resp = parseResponse(await executeHttpCall({
166
+ request: buildHttpRequest("GET", url, headers, callSignal),
167
+ httpClient,
168
+ logger: this.logger
169
+ }), unmarshalDefaultWarehouseOverrideSchema);
170
+ };
171
+ await executeCall(call, options);
172
+ if (resp === void 0) throw new Error("operation completed without a result.");
173
+ return resp;
174
+ }
175
+ /** Gets the information for a single SQL warehouse. */
176
+ async getWarehouse(req, options) {
177
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
178
+ const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ""}`;
179
+ let resp;
180
+ const call = async (callSignal) => {
181
+ const headers = new Headers();
182
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
183
+ headers.set("User-Agent", this.userAgent);
184
+ resp = parseResponse(await executeHttpCall({
185
+ request: buildHttpRequest("GET", url, headers, callSignal),
186
+ httpClient,
187
+ logger: this.logger
188
+ }), unmarshalGetWarehouseResponseSchema);
189
+ };
190
+ await executeCall(call, options);
191
+ if (resp === void 0) throw new Error("operation completed without a result.");
192
+ return resp;
193
+ }
194
+ /** Gets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
195
+ async getWorkspaceWarehouseConfig(_req, options) {
196
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
197
+ const url = `${host}/api/2.0/sql/config/warehouses`;
198
+ let resp;
199
+ const call = async (callSignal) => {
200
+ const headers = new Headers();
201
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
202
+ headers.set("User-Agent", this.userAgent);
203
+ resp = parseResponse(await executeHttpCall({
204
+ request: buildHttpRequest("GET", url, headers, callSignal),
205
+ httpClient,
206
+ logger: this.logger
207
+ }), unmarshalGetWorkspaceWarehouseConfigResponseSchema);
208
+ };
209
+ await executeCall(call, options);
210
+ if (resp === void 0) throw new Error("operation completed without a result.");
211
+ return resp;
212
+ }
213
+ /**
214
+ * Lists all default warehouse overrides in the workspace.
215
+ * Only workspace administrators can list all overrides.
216
+ */
217
+ async listDefaultWarehouseOverrides(req, options) {
218
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
219
+ const url = `${host}/api/warehouses/v1/default-warehouse-overrides`;
220
+ const params = new URLSearchParams();
221
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
222
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
223
+ const query = params.toString();
224
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
225
+ let resp;
226
+ const call = async (callSignal) => {
227
+ const headers = new Headers();
228
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
229
+ headers.set("User-Agent", this.userAgent);
230
+ resp = parseResponse(await executeHttpCall({
231
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
232
+ httpClient,
233
+ logger: this.logger
234
+ }), unmarshalListDefaultWarehouseOverridesResponseSchema);
235
+ };
236
+ await executeCall(call, options);
237
+ if (resp === void 0) throw new Error("operation completed without a result.");
238
+ return resp;
239
+ }
240
+ async *listDefaultWarehouseOverridesIter(req, options) {
241
+ const pageReq = { ...req };
242
+ for (;;) {
243
+ const resp = await this.listDefaultWarehouseOverrides(pageReq, options);
244
+ for (const item of resp.defaultWarehouseOverrides ?? []) yield item;
245
+ if (resp.nextPageToken === void 0 || resp.nextPageToken === "") return;
246
+ pageReq.pageToken = resp.nextPageToken;
247
+ }
248
+ }
249
+ /** Lists all SQL warehouses that a user has access to. */
250
+ async listWarehouses(req, options) {
251
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
252
+ const url = `${host}/api/2.0/sql/warehouses`;
253
+ const params = new URLSearchParams();
254
+ if (req.runAsUserId !== void 0) params.append("run_as_user_id", String(req.runAsUserId));
255
+ if (req.pageSize !== void 0) params.append("page_size", String(req.pageSize));
256
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
257
+ const query = params.toString();
258
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
259
+ let resp;
260
+ const call = async (callSignal) => {
261
+ const headers = new Headers();
262
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
263
+ headers.set("User-Agent", this.userAgent);
264
+ resp = parseResponse(await executeHttpCall({
265
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
266
+ httpClient,
267
+ logger: this.logger
268
+ }), unmarshalListWarehousesResponseSchema);
269
+ };
270
+ await executeCall(call, options);
271
+ if (resp === void 0) throw new Error("operation completed without a result.");
272
+ return resp;
273
+ }
274
+ async *listWarehousesIter(req, options) {
275
+ const pageReq = { ...req };
276
+ for (;;) {
277
+ const resp = await this.listWarehouses(pageReq, options);
278
+ for (const item of resp.warehouses ?? []) yield item;
279
+ if (resp.nextPageToken === void 0 || resp.nextPageToken === "") return;
280
+ pageReq.pageToken = resp.nextPageToken;
281
+ }
282
+ }
283
+ /** Sets the workspace level configuration that is shared by all SQL warehouses in a workspace. */
284
+ async setWorkspaceWarehouseConfig(req, options) {
285
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
286
+ const url = `${host}/api/2.0/sql/config/warehouses`;
287
+ const body = marshalRequest(req, marshalSetWorkspaceWarehouseConfigRequestSchema);
288
+ let resp;
289
+ const call = async (callSignal) => {
290
+ const headers = new Headers({ "Content-Type": "application/json" });
291
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
292
+ headers.set("User-Agent", this.userAgent);
293
+ resp = parseResponse(await executeHttpCall({
294
+ request: buildHttpRequest("PUT", url, headers, callSignal, body),
295
+ httpClient,
296
+ logger: this.logger
297
+ }), unmarshalSetWorkspaceWarehouseConfigResponseSchema);
298
+ };
299
+ await executeCall(call, options);
300
+ if (resp === void 0) throw new Error("operation completed without a result.");
301
+ return resp;
302
+ }
303
+ /** Starts a SQL warehouse. */
304
+ async startWarehouseBase(req, options) {
305
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
306
+ const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ""}/start`;
307
+ const body = marshalRequest(req, marshalStartRequestSchema);
308
+ let resp;
309
+ const call = async (callSignal) => {
310
+ const headers = new Headers({ "Content-Type": "application/json" });
311
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
312
+ headers.set("User-Agent", this.userAgent);
313
+ resp = parseResponse(await executeHttpCall({
314
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
315
+ httpClient,
316
+ logger: this.logger
317
+ }), unmarshalStartResponseSchema);
318
+ };
319
+ await executeCall(call, options);
320
+ if (resp === void 0) throw new Error("operation completed without a result.");
321
+ return resp;
322
+ }
323
+ /** Starts a SQL warehouse. */
324
+ async startWarehouse(req, options) {
325
+ await this.startWarehouseBase(req, options);
326
+ if (req.id === void 0) throw new Error("request field id required for polling is missing");
327
+ return new StartWarehouseWaiter(this, req.id);
328
+ }
329
+ /** Stops a SQL warehouse. */
330
+ async stopWarehouseBase(req, options) {
331
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
332
+ const url = `${host}/api/2.0/sql/warehouses/${req.id ?? ""}/stop`;
333
+ const body = marshalRequest(req, marshalStopRequestSchema);
334
+ let resp;
335
+ const call = async (callSignal) => {
336
+ const headers = new Headers({ "Content-Type": "application/json" });
337
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
338
+ headers.set("User-Agent", this.userAgent);
339
+ resp = parseResponse(await executeHttpCall({
340
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
341
+ httpClient,
342
+ logger: this.logger
343
+ }), unmarshalStopResponseSchema);
344
+ };
345
+ await executeCall(call, options);
346
+ if (resp === void 0) throw new Error("operation completed without a result.");
347
+ return resp;
348
+ }
349
+ /** Stops a SQL warehouse. */
350
+ async stopWarehouse(req, options) {
351
+ await this.stopWarehouseBase(req, options);
352
+ if (req.id === void 0) throw new Error("request field id required for polling is missing");
353
+ return new StopWarehouseWaiter(this, req.id);
354
+ }
355
+ /**
356
+ * Updates an existing default warehouse override for a user.
357
+ * Users can update their own override. Admins can update overrides for any user.
358
+ */
359
+ async updateDefaultWarehouseOverride(req, options) {
360
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
361
+ const url = `${host}/api/warehouses/v1/${req.defaultWarehouseOverride?.name ?? ""}`;
362
+ const params = new URLSearchParams();
363
+ if (req.updateMask !== void 0) params.append("update_mask", req.updateMask.toString());
364
+ if (req.allowMissing !== void 0) params.append("allow_missing", String(req.allowMissing));
365
+ const query = params.toString();
366
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
367
+ const body = marshalRequest(req.defaultWarehouseOverride, marshalDefaultWarehouseOverrideSchema);
368
+ let resp;
369
+ const call = async (callSignal) => {
370
+ const headers = new Headers({ "Content-Type": "application/json" });
371
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
372
+ headers.set("User-Agent", this.userAgent);
373
+ resp = parseResponse(await executeHttpCall({
374
+ request: buildHttpRequest("PATCH", fullUrl, headers, callSignal, body),
375
+ httpClient,
376
+ logger: this.logger
377
+ }), unmarshalDefaultWarehouseOverrideSchema);
378
+ };
379
+ await executeCall(call, options);
380
+ if (resp === void 0) throw new Error("operation completed without a result.");
381
+ return resp;
382
+ }
383
+ };
384
+ var CreateWarehouseWaiter = class {
385
+ constructor(client, id) {
386
+ this.client = client;
387
+ this.id = id;
388
+ }
389
+ /**
390
+ * Polls until the operation reaches a terminal state.
391
+ *
392
+ * Throws if a failure state is reached.
393
+ */
394
+ async wait(options) {
395
+ let result;
396
+ const call = async (callSignal) => {
397
+ const pollResp = await this.client.getWarehouse({ id: this.id }, callSignal !== void 0 ? { signal: callSignal } : void 0);
398
+ const status = pollResp.state;
399
+ if (status === void 0) throw new Error("response missing required status field");
400
+ switch (status) {
401
+ case EndpointState.RUNNING:
402
+ result = pollResp;
403
+ return;
404
+ case EndpointState.STOPPED:
405
+ case EndpointState.DELETED: {
406
+ const msg = pollResp.health?.summary ?? "(no message)";
407
+ throw new Error(`terminal state ${status}: ${msg}`);
408
+ }
409
+ default: throw new StillRunningError();
410
+ }
411
+ };
412
+ await executeWait(call, options);
413
+ if (result === void 0) throw new Error("operation completed without a result.");
414
+ return result;
415
+ }
416
+ /** Checks whether the operation has reached a terminal state. */
417
+ async done(options) {
418
+ const status = (await this.client.getWarehouse({ id: this.id }, options)).state;
419
+ if (status === void 0) throw new Error("response missing required status field");
420
+ switch (status) {
421
+ case EndpointState.RUNNING:
422
+ case EndpointState.STOPPED:
423
+ case EndpointState.DELETED: return true;
424
+ default: return false;
425
+ }
426
+ }
427
+ };
428
+ var EditWarehouseWaiter = class {
429
+ constructor(client, id) {
430
+ this.client = client;
431
+ this.id = id;
432
+ }
433
+ /**
434
+ * Polls until the operation reaches a terminal state.
435
+ *
436
+ * Throws if a failure state is reached.
437
+ */
438
+ async wait(options) {
439
+ let result;
440
+ const call = async (callSignal) => {
441
+ const pollResp = await this.client.getWarehouse({ id: this.id }, callSignal !== void 0 ? { signal: callSignal } : void 0);
442
+ const status = pollResp.state;
443
+ if (status === void 0) throw new Error("response missing required status field");
444
+ switch (status) {
445
+ case EndpointState.RUNNING:
446
+ result = pollResp;
447
+ return;
448
+ case EndpointState.STOPPED:
449
+ case EndpointState.DELETED: {
450
+ const msg = pollResp.health?.summary ?? "(no message)";
451
+ throw new Error(`terminal state ${status}: ${msg}`);
452
+ }
453
+ default: throw new StillRunningError();
454
+ }
455
+ };
456
+ await executeWait(call, options);
457
+ if (result === void 0) throw new Error("operation completed without a result.");
458
+ return result;
459
+ }
460
+ /** Checks whether the operation has reached a terminal state. */
461
+ async done(options) {
462
+ const status = (await this.client.getWarehouse({ id: this.id }, options)).state;
463
+ if (status === void 0) throw new Error("response missing required status field");
464
+ switch (status) {
465
+ case EndpointState.RUNNING:
466
+ case EndpointState.STOPPED:
467
+ case EndpointState.DELETED: return true;
468
+ default: return false;
469
+ }
470
+ }
471
+ };
472
+ var StartWarehouseWaiter = class {
473
+ constructor(client, id) {
474
+ this.client = client;
475
+ this.id = id;
476
+ }
477
+ /**
478
+ * Polls until the operation reaches a terminal state.
479
+ *
480
+ * Throws if a failure state is reached.
481
+ */
482
+ async wait(options) {
483
+ let result;
484
+ const call = async (callSignal) => {
485
+ const pollResp = await this.client.getWarehouse({ id: this.id }, callSignal !== void 0 ? { signal: callSignal } : void 0);
486
+ const status = pollResp.state;
487
+ if (status === void 0) throw new Error("response missing required status field");
488
+ switch (status) {
489
+ case EndpointState.RUNNING:
490
+ result = pollResp;
491
+ return;
492
+ case EndpointState.STOPPED:
493
+ case EndpointState.DELETED: {
494
+ const msg = pollResp.health?.summary ?? "(no message)";
495
+ throw new Error(`terminal state ${status}: ${msg}`);
496
+ }
497
+ default: throw new StillRunningError();
498
+ }
499
+ };
500
+ await executeWait(call, options);
501
+ if (result === void 0) throw new Error("operation completed without a result.");
502
+ return result;
503
+ }
504
+ /** Checks whether the operation has reached a terminal state. */
505
+ async done(options) {
506
+ const status = (await this.client.getWarehouse({ id: this.id }, options)).state;
507
+ if (status === void 0) throw new Error("response missing required status field");
508
+ switch (status) {
509
+ case EndpointState.RUNNING:
510
+ case EndpointState.STOPPED:
511
+ case EndpointState.DELETED: return true;
512
+ default: return false;
513
+ }
514
+ }
515
+ };
516
+ var StopWarehouseWaiter = class {
517
+ constructor(client, id) {
518
+ this.client = client;
519
+ this.id = id;
520
+ }
521
+ /**
522
+ * Polls until the operation reaches a terminal state.
523
+ *
524
+ * Throws if a failure state is reached.
525
+ */
526
+ async wait(options) {
527
+ let result;
528
+ const call = async (callSignal) => {
529
+ const pollResp = await this.client.getWarehouse({ id: this.id }, callSignal !== void 0 ? { signal: callSignal } : void 0);
530
+ const status = pollResp.state;
531
+ if (status === void 0) throw new Error("response missing required status field");
532
+ switch (status) {
533
+ case EndpointState.STOPPED:
534
+ result = pollResp;
535
+ return;
536
+ default: throw new StillRunningError();
537
+ }
538
+ };
539
+ await executeWait(call, options);
540
+ if (result === void 0) throw new Error("operation completed without a result.");
541
+ return result;
542
+ }
543
+ /** Checks whether the operation has reached a terminal state. */
544
+ async done(options) {
545
+ const status = (await this.client.getWarehouse({ id: this.id }, options)).state;
546
+ if (status === void 0) throw new Error("response missing required status field");
547
+ switch (status) {
548
+ case EndpointState.STOPPED: return true;
549
+ default: return false;
550
+ }
551
+ }
552
+ };
553
+
554
+ //#endregion
555
+ export { CreateWarehouseWaiter, EditWarehouseWaiter, StartWarehouseWaiter, StopWarehouseWaiter, WarehousesClient };
734
556
  //# sourceMappingURL=client.js.map