@databricks/sdk-workspaces 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,113 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+ import { execute } from '@databricks/sdk-core/api';
3
+ import { ApiError } from '@databricks/sdk-core/apierror';
4
+ import JSONBig from 'json-bigint';
5
+ // JSON codec that preserves int64 precision. On the way in, large integer
6
+ // literals come back as bigint instead of being rounded to JS Number. On the
7
+ // way out, bigint values are emitted as raw JSON number digits.
8
+ const jsonBigint = JSONBig({ useNativeBigInt: true });
9
+ /**
10
+ * Translates public CallOptions to the internal Options shape accepted by
11
+ * execute(). Even though the shapes match today, this isolates the public
12
+ * API from the executor's internal type so they can diverge.
13
+ */
14
+ export async function executeCall(call, options) {
15
+ const opts = {
16
+ ...(options?.retrier !== undefined && { retrier: options.retrier }),
17
+ ...(options?.rateLimiter !== undefined && {
18
+ rateLimiter: options.rateLimiter,
19
+ }),
20
+ ...(options?.timeout !== undefined && { timeout: options.timeout }),
21
+ };
22
+ return execute(options?.signal, call, opts);
23
+ }
24
+ async function readAll(body) {
25
+ if (body === null) {
26
+ return new Uint8Array(0);
27
+ }
28
+ const reader = body.getReader();
29
+ const chunks = [];
30
+ for (;;) {
31
+ const { done, value } = await reader.read();
32
+ if (done) {
33
+ break;
34
+ }
35
+ chunks.push(value);
36
+ }
37
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
38
+ const result = new Uint8Array(totalLength);
39
+ let offset = 0;
40
+ for (const chunk of chunks) {
41
+ result.set(chunk, offset);
42
+ offset += chunk.length;
43
+ }
44
+ return result;
45
+ }
46
+ export async function executeHttpCall(opts) {
47
+ opts.logger.debug('HTTP request', {
48
+ method: opts.request.method,
49
+ url: opts.request.url,
50
+ });
51
+ let resp;
52
+ try {
53
+ resp = await opts.httpClient.send(opts.request);
54
+ }
55
+ catch (e) {
56
+ opts.logger.debug('HTTP request failed');
57
+ throw e;
58
+ }
59
+ const body = await readAll(resp.body);
60
+ opts.logger.debug('HTTP response', {
61
+ statusCode: resp.statusCode,
62
+ body: new TextDecoder().decode(body),
63
+ });
64
+ const apiErr = ApiError.fromHttpError(resp.statusCode, resp.headers, body);
65
+ if (apiErr !== undefined) {
66
+ throw apiErr;
67
+ }
68
+ return body;
69
+ }
70
+ export function buildHttpRequest(method, url, headers, signal, body) {
71
+ const req = { url, method, headers };
72
+ if (body !== undefined) {
73
+ req.body = body;
74
+ }
75
+ if (signal !== undefined) {
76
+ req.signal = signal;
77
+ }
78
+ return req;
79
+ }
80
+ export function parseResponse(body, schema) {
81
+ const text = new TextDecoder().decode(body);
82
+ const parsed = jsonBigint.parse(text);
83
+ return schema.parse(parsed);
84
+ }
85
+ export function marshalRequest(data, schema) {
86
+ return jsonBigint.stringify(schema.parse(data));
87
+ }
88
+ export function flattenQueryParams(prefix, value, params) {
89
+ if (value === null || value === undefined) {
90
+ return;
91
+ }
92
+ if (Array.isArray(value)) {
93
+ // arrays of objects are not yet supported
94
+ for (const item of value) {
95
+ params.append(prefix, String(item));
96
+ }
97
+ }
98
+ else if (typeof value === 'object') {
99
+ for (const [key, val] of Object.entries(value)) {
100
+ flattenQueryParams(`${prefix}.${key}`, val, params);
101
+ }
102
+ }
103
+ else if (typeof value === 'string' ||
104
+ typeof value === 'number' ||
105
+ typeof value === 'boolean' ||
106
+ typeof value === 'bigint') {
107
+ params.append(prefix, String(value));
108
+ }
109
+ else {
110
+ throw new Error(`Unsupported query parameter type: ${typeof value}`);
111
+ }
112
+ }
113
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/v1/utils.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAG/E,OAAO,EAAC,OAAO,EAAC,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,+BAA+B,CAA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AM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;YAC1E,kBAAkB,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;SAAM,IACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ,EACzB,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,41 @@
1
1
  {
2
2
  "name": "@databricks/sdk-workspaces",
3
- "version": "0.0.0-dev",
4
- "description": "Bootstrap placeholder; real contents in a later release.",
5
- "main": "index.js",
6
- "license": "Apache-2.0"
3
+ "version": "0.1.0-dev.1",
4
+ "description": "",
5
+ "type": "module",
6
+ "exports": {
7
+ "./v1": {
8
+ "types": "./dist/v1/index.d.ts",
9
+ "import": "./dist/v1/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "src",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc -b",
19
+ "lint": "eslint src --ext .ts",
20
+ "lint:fix": "eslint src --ext .ts --fix",
21
+ "format": "prettier --write \"src/**/*.ts\"",
22
+ "format:check": "prettier --check \"src/**/*.ts\"",
23
+ "typecheck": "tsc --noEmit",
24
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
25
+ "test": "echo 'no tests'",
26
+ "test:browser": "echo 'no tests'"
27
+ },
28
+ "author": "Databricks",
29
+ "license": "Apache-2.0",
30
+ "dependencies": {
31
+ "@databricks/sdk-auth": ">=0.1.0-dev.2 <1.0.0",
32
+ "@databricks/sdk-core": ">=0.1.0-dev.3 <1.0.0",
33
+ "@databricks/sdk-options": ">=0.1.0-dev.2 <1.0.0",
34
+ "@js-temporal/polyfill": "^0.5.0",
35
+ "json-bigint": "^1.0.0",
36
+ "zod": "^4.3.6"
37
+ },
38
+ "engines": {
39
+ "node": ">=22.0.0"
40
+ }
7
41
  }
@@ -0,0 +1,420 @@
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 {z} from 'zod';
22
+ import type {
23
+ CreateWorkspaceRequest,
24
+ DeleteWorkspaceRequest,
25
+ GetWorkspaceRequest,
26
+ ListWorkspacesRequest,
27
+ ListWorkspacesResponse,
28
+ UpdateWorkspaceRequest,
29
+ Workspace,
30
+ } from './model';
31
+ import {
32
+ WorkspaceStatus,
33
+ marshalCreateWorkspaceRequestSchema,
34
+ marshalWorkspaceSchema,
35
+ unmarshalWorkspaceSchema,
36
+ } from './model';
37
+
38
+ // Package identity segment for this client to be used in the User-Agent header.
39
+ const PACKAGE_SEGMENT = {
40
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
41
+ value: pkgJson.version,
42
+ };
43
+
44
+ class StillRunningError extends Error {}
45
+
46
+ export class WorkspacesClient {
47
+ private readonly host: string;
48
+ // Fallback for endpoints whose path contains {account_id}. If the request
49
+ // already carries an accountId, that value wins.
50
+ private readonly accountId: string | undefined;
51
+ private readonly httpClient: HttpClient;
52
+ private readonly logger: Logger;
53
+ // User-Agent header value. Composed once at construction from
54
+ // createDefault() merged with this package's identity and the active
55
+ // credential's name.
56
+ private readonly userAgent: string;
57
+
58
+ constructor(options: ClientOptions) {
59
+ if (options.host === undefined) {
60
+ throw new Error('Host is required.');
61
+ }
62
+ this.host = options.host.replace(/\/$/, '');
63
+ this.accountId = options.accountId;
64
+ this.logger = options.logger ?? new NoOpLogger();
65
+ const info = createDefault()
66
+ .with(PACKAGE_SEGMENT)
67
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
68
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
69
+ this.userAgent = info.toString();
70
+ this.httpClient = newHttpClient(options);
71
+ }
72
+
73
+ /**
74
+ * Creates a new workspace using a credential configuration and a storage configuration, an optional network configuration (if using a customer-managed VPC), an optional managed services key configuration (if using customer-managed keys for managed services), and an optional storage key configuration (if using customer-managed keys for storage). The key configurations used for managed services and storage encryption can be the same or different.
75
+ *
76
+ * Important: This operation is asynchronous. A response with HTTP status code 200 means the request has been accepted and is in progress, but does not mean that the workspace deployed successfully and is running. The initial workspace status is typically PROVISIONING. Use the workspace ID (workspace_id) field in the response to identify the new workspace and make repeated GET requests with the workspace ID and check its status. The workspace becomes available when the status changes to RUNNING.
77
+ *
78
+ * You can share one customer-managed VPC with multiple workspaces in a single account. It is not required to create a new VPC for each workspace. However, you cannot reuse subnets or Security Groups between workspaces. If you plan to share one VPC with multiple workspaces, make sure you size your VPC and subnets accordingly. Because a Databricks Account API network configuration encapsulates this information, you cannot reuse a Databricks Account API network configuration across workspaces.
79
+ *
80
+ * For information about how to create a new workspace with this API including error handling, see [Create a new workspace using the Account API](http://docs.databricks.com/administration-guide/account-api/new-workspace.html).
81
+ *
82
+ * Important: Customer-managed VPCs, PrivateLink, and customer-managed keys are supported on a limited set of deployment and subscription types. If you have questions about availability, contact your <Databricks> representative.
83
+ *
84
+ * This operation is available only if your account is on the E2 version of the platform or on a select custom plan that allows multiple workspaces per account.
85
+ */
86
+ async createWorkspacePublic(
87
+ req: CreateWorkspaceRequest,
88
+ options?: CallOptions
89
+ ): Promise<Workspace> {
90
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces`;
91
+ const body = marshalRequest(req, marshalCreateWorkspaceRequestSchema);
92
+ let resp: Workspace | undefined;
93
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
94
+ const headers = new Headers({'Content-Type': 'application/json'});
95
+ headers.set('User-Agent', this.userAgent);
96
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
97
+ const respBody = await executeHttpCall({
98
+ request: httpReq,
99
+ httpClient: this.httpClient,
100
+ logger: this.logger,
101
+ });
102
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
103
+ };
104
+ await executeCall(call, options);
105
+ if (resp === undefined) {
106
+ throw new Error('API call completed without a result.');
107
+ }
108
+ return resp;
109
+ }
110
+
111
+ async createWorkspacePublicWaiter(
112
+ req: CreateWorkspaceRequest,
113
+ options?: CallOptions
114
+ ): Promise<CreateWorkspacePublicWaiter> {
115
+ const resp = await this.createWorkspacePublic(req, options);
116
+ if (resp.workspaceId === undefined) {
117
+ throw new Error(
118
+ 'response field workspaceId required for polling is missing'
119
+ );
120
+ }
121
+ return new CreateWorkspacePublicWaiter(this, resp.workspaceId);
122
+ }
123
+
124
+ /** Deletes a <Databricks> workspace, both specified by ID. */
125
+ async deleteWorkspacePublic(
126
+ req: DeleteWorkspaceRequest,
127
+ options?: CallOptions
128
+ ): Promise<Workspace> {
129
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}`;
130
+ let resp: Workspace | undefined;
131
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
132
+ const headers = new Headers();
133
+ headers.set('User-Agent', this.userAgent);
134
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
135
+ const respBody = await executeHttpCall({
136
+ request: httpReq,
137
+ httpClient: this.httpClient,
138
+ logger: this.logger,
139
+ });
140
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
141
+ };
142
+ await executeCall(call, options);
143
+ if (resp === undefined) {
144
+ throw new Error('API call completed without a result.');
145
+ }
146
+ return resp;
147
+ }
148
+
149
+ /**
150
+ * Gets information including status for a <Databricks> workspace, specified by ID. In the response, the `workspace_status` field indicates the current status. After initial workspace creation (which is asynchronous), make repeated `GET` requests with the workspace ID and check its status. The workspace becomes available when the status changes to `RUNNING`.
151
+ * For information about how to create a new workspace with this API **including error handling**, see [Create a new workspace using the Account API](http://docs.databricks.com/administration-guide/account-api/new-workspace.html).
152
+ */
153
+ async getWorkspacePublic(
154
+ req: GetWorkspaceRequest,
155
+ options?: CallOptions
156
+ ): Promise<Workspace> {
157
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}`;
158
+ let resp: Workspace | undefined;
159
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
160
+ const headers = new Headers();
161
+ headers.set('User-Agent', this.userAgent);
162
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
163
+ const respBody = await executeHttpCall({
164
+ request: httpReq,
165
+ httpClient: this.httpClient,
166
+ logger: this.logger,
167
+ });
168
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
169
+ };
170
+ await executeCall(call, options);
171
+ if (resp === undefined) {
172
+ throw new Error('API call completed without a result.');
173
+ }
174
+ return resp;
175
+ }
176
+
177
+ /** Lists <Databricks> workspaces for an account. */
178
+ async listWorkspacesPublic(
179
+ req: ListWorkspacesRequest,
180
+ options?: CallOptions
181
+ ): Promise<ListWorkspacesResponse> {
182
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces`;
183
+ let resp: ListWorkspacesResponse | undefined;
184
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
185
+ const headers = new Headers();
186
+ headers.set('User-Agent', this.userAgent);
187
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
188
+ const respBody = await executeHttpCall({
189
+ request: httpReq,
190
+ httpClient: this.httpClient,
191
+ logger: this.logger,
192
+ });
193
+ resp = {
194
+ workspaces: parseResponse(
195
+ respBody,
196
+ z.array(z.lazy(() => unmarshalWorkspaceSchema))
197
+ ),
198
+ };
199
+ };
200
+ await executeCall(call, options);
201
+ if (resp === undefined) {
202
+ throw new Error('API call completed without a result.');
203
+ }
204
+ return resp;
205
+ }
206
+
207
+ /** Updates a workspace. */
208
+ async updateWorkspacePublic(
209
+ req: UpdateWorkspaceRequest,
210
+ options?: CallOptions
211
+ ): Promise<Workspace> {
212
+ const url = `${this.host}/api/2.0/accounts/${req.customerFacingWorkspace?.accountId ?? this.accountId ?? ''}/workspaces/${String(req.customerFacingWorkspace?.workspaceId ?? '')}`;
213
+ const params = new URLSearchParams();
214
+ if (req.updateMask !== undefined) {
215
+ params.append('update_mask', req.updateMask.toString());
216
+ }
217
+ const query = params.toString();
218
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
219
+ const body = marshalRequest(
220
+ req.customerFacingWorkspace,
221
+ marshalWorkspaceSchema
222
+ );
223
+ let resp: Workspace | undefined;
224
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
225
+ const headers = new Headers({'Content-Type': 'application/json'});
226
+ headers.set('User-Agent', this.userAgent);
227
+ const httpReq = buildHttpRequest(
228
+ 'PATCH',
229
+ fullUrl,
230
+ headers,
231
+ callSignal,
232
+ body
233
+ );
234
+ const respBody = await executeHttpCall({
235
+ request: httpReq,
236
+ httpClient: this.httpClient,
237
+ logger: this.logger,
238
+ });
239
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
240
+ };
241
+ await executeCall(call, options);
242
+ if (resp === undefined) {
243
+ throw new Error('API call completed without a result.');
244
+ }
245
+ return resp;
246
+ }
247
+
248
+ async updateWorkspacePublicWaiter(
249
+ req: UpdateWorkspaceRequest,
250
+ options?: CallOptions
251
+ ): Promise<UpdateWorkspacePublicWaiter> {
252
+ const resp = await this.updateWorkspacePublic(req, options);
253
+ if (resp.workspaceId === undefined) {
254
+ throw new Error(
255
+ 'response field workspaceId required for polling is missing'
256
+ );
257
+ }
258
+ return new UpdateWorkspacePublicWaiter(this, resp.workspaceId);
259
+ }
260
+ }
261
+
262
+ export class CreateWorkspacePublicWaiter {
263
+ constructor(
264
+ private readonly client: WorkspacesClient,
265
+ readonly workspaceId: bigint
266
+ ) {}
267
+
268
+ /**
269
+ * Polls until the operation reaches a terminal state.
270
+ *
271
+ * Throws if a failure state is reached.
272
+ */
273
+ async wait(options?: CallOptions): Promise<Workspace> {
274
+ let result: Workspace | undefined;
275
+
276
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
277
+ const pollResp = await this.client.getWorkspacePublic(
278
+ {
279
+ workspaceId: this.workspaceId,
280
+ },
281
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
282
+ );
283
+
284
+ const status = pollResp.workspaceStatus;
285
+ if (status === undefined) {
286
+ throw new Error('response missing required status field');
287
+ }
288
+
289
+ switch (status) {
290
+ case WorkspaceStatus.RUNNING:
291
+ result = pollResp;
292
+ return;
293
+ case WorkspaceStatus.BANNED:
294
+ case WorkspaceStatus.FAILED: {
295
+ const msg = pollResp.workspaceStatusMessage ?? '(no message)';
296
+ throw new Error(`terminal state ${status}: ${msg}`);
297
+ }
298
+ default:
299
+ throw new StillRunningError();
300
+ }
301
+ };
302
+
303
+ const retryOptions: CallOptions = {
304
+ ...(options?.signal !== undefined && {signal: options.signal}),
305
+ retrier: () =>
306
+ retryOn({}, (err: Error) => {
307
+ return err instanceof StillRunningError;
308
+ }),
309
+ };
310
+ await executeCall(call, retryOptions);
311
+ if (result === undefined) {
312
+ throw new Error('API call completed without a result.');
313
+ }
314
+ return result;
315
+ }
316
+
317
+ /** Checks whether the operation has reached a terminal state. */
318
+ async done(options?: CallOptions): Promise<boolean> {
319
+ const pollResp = await this.client.getWorkspacePublic(
320
+ {
321
+ workspaceId: this.workspaceId,
322
+ },
323
+ options
324
+ );
325
+
326
+ const status = pollResp.workspaceStatus;
327
+ if (status === undefined) {
328
+ throw new Error('response missing required status field');
329
+ }
330
+
331
+ switch (status) {
332
+ case WorkspaceStatus.RUNNING:
333
+ case WorkspaceStatus.BANNED:
334
+ case WorkspaceStatus.FAILED:
335
+ return true;
336
+ default:
337
+ return false;
338
+ }
339
+ }
340
+ }
341
+
342
+ export class UpdateWorkspacePublicWaiter {
343
+ constructor(
344
+ private readonly client: WorkspacesClient,
345
+ readonly workspaceId: bigint
346
+ ) {}
347
+
348
+ /**
349
+ * Polls until the operation reaches a terminal state.
350
+ *
351
+ * Throws if a failure state is reached.
352
+ */
353
+ async wait(options?: CallOptions): Promise<Workspace> {
354
+ let result: Workspace | undefined;
355
+
356
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
357
+ const pollResp = await this.client.getWorkspacePublic(
358
+ {
359
+ workspaceId: this.workspaceId,
360
+ },
361
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
362
+ );
363
+
364
+ const status = pollResp.workspaceStatus;
365
+ if (status === undefined) {
366
+ throw new Error('response missing required status field');
367
+ }
368
+
369
+ switch (status) {
370
+ case WorkspaceStatus.RUNNING:
371
+ result = pollResp;
372
+ return;
373
+ case WorkspaceStatus.BANNED:
374
+ case WorkspaceStatus.FAILED: {
375
+ const msg = pollResp.workspaceStatusMessage ?? '(no message)';
376
+ throw new Error(`terminal state ${status}: ${msg}`);
377
+ }
378
+ default:
379
+ throw new StillRunningError();
380
+ }
381
+ };
382
+
383
+ const retryOptions: CallOptions = {
384
+ ...(options?.signal !== undefined && {signal: options.signal}),
385
+ retrier: () =>
386
+ retryOn({}, (err: Error) => {
387
+ return err instanceof StillRunningError;
388
+ }),
389
+ };
390
+ await executeCall(call, retryOptions);
391
+ if (result === undefined) {
392
+ throw new Error('API call completed without a result.');
393
+ }
394
+ return result;
395
+ }
396
+
397
+ /** Checks whether the operation has reached a terminal state. */
398
+ async done(options?: CallOptions): Promise<boolean> {
399
+ const pollResp = await this.client.getWorkspacePublic(
400
+ {
401
+ workspaceId: this.workspaceId,
402
+ },
403
+ options
404
+ );
405
+
406
+ const status = pollResp.workspaceStatus;
407
+ if (status === undefined) {
408
+ throw new Error('response missing required status field');
409
+ }
410
+
411
+ switch (status) {
412
+ case WorkspaceStatus.RUNNING:
413
+ case WorkspaceStatus.BANNED:
414
+ case WorkspaceStatus.FAILED:
415
+ return true;
416
+ default:
417
+ return false;
418
+ }
419
+ }
420
+ }
@@ -0,0 +1,36 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ export {
4
+ WorkspacesClient,
5
+ CreateWorkspacePublicWaiter,
6
+ UpdateWorkspacePublicWaiter,
7
+ } from './client';
8
+
9
+ export {
10
+ ComputeMode,
11
+ GkeConnectivityType,
12
+ PricingTier,
13
+ StorageMode,
14
+ WorkspaceStatus,
15
+ } from './model';
16
+
17
+ export type {
18
+ AzureWorkspaceInfo,
19
+ CloudResourceContainer,
20
+ CreateWorkspaceRequest,
21
+ CreateWorkspaceRequest_CustomTagsEntry,
22
+ DeleteWorkspaceRequest,
23
+ GcpCloudResourceContainer,
24
+ GcpCommonNetworkConfig,
25
+ GcpManagedNetworkConfig,
26
+ GetWorkspaceRequest,
27
+ GkeConfig,
28
+ ListWorkspacesRequest,
29
+ ListWorkspacesResponse,
30
+ UpdateWorkspaceRequest,
31
+ Workspace,
32
+ Workspace_CustomTagsEntry,
33
+ WorkspaceNetwork,
34
+ } from './model';
35
+
36
+ export {workspaceFieldMask} from './model';