@databricks/sdk-workspaces 0.0.0-dev → 0.1.0-dev.2

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,34 @@
1
+ import type { HttpClient, HttpRequest } from '@databricks/sdk-core/http';
2
+ import type { Logger } from '@databricks/sdk-core/logger';
3
+ import type { CallOptions } from '@databricks/sdk-options/call';
4
+ import type { LroOptions } from '@databricks/sdk-options/lro';
5
+ import type { z } from 'zod';
6
+ export interface HttpCallOptions {
7
+ readonly request: HttpRequest;
8
+ readonly httpClient: HttpClient;
9
+ readonly logger: Logger;
10
+ }
11
+ /**
12
+ * Translates public CallOptions to the internal Options shape accepted by
13
+ * execute(). Even though the shapes match today, this isolates the public
14
+ * API from the executor's internal type so they can diverge.
15
+ */
16
+ export declare function executeCall(call: (signal?: AbortSignal) => Promise<void>, options?: CallOptions): Promise<void>;
17
+ /**
18
+ * Sentinel thrown by a polling call to signal that the operation has not
19
+ * yet reached a terminal state. {@link executeWait} treats this error as
20
+ * retriable; any other error aborts the wait.
21
+ */
22
+ export declare class StillRunningError extends Error {
23
+ }
24
+ /**
25
+ * Polls until the call returns without throwing {@link StillRunningError}.
26
+ * Abort and overall-deadline behavior come from the supplied LroOptions.
27
+ */
28
+ export declare function executeWait(call: (signal?: AbortSignal) => Promise<void>, options?: LroOptions): Promise<void>;
29
+ export declare function executeHttpCall(opts: HttpCallOptions): Promise<Uint8Array>;
30
+ export declare function buildHttpRequest(method: string, url: string, headers: Headers, signal?: AbortSignal, body?: string | ReadableStream<Uint8Array>): HttpRequest;
31
+ export declare function parseResponse<T>(body: Uint8Array, schema: z.ZodType<T>): T;
32
+ export declare function marshalRequest(data: unknown, schema: z.ZodType): string;
33
+ export declare function flattenQueryParams(prefix: string, value: unknown, params: URLSearchParams): void;
34
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/v1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U,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAI1E;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,CAEvE;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,eAAe,GACtB,IAAI,CAuBN"}
@@ -0,0 +1,131 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+ import { execute, retryOn } from '@databricks/sdk-core/ops';
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
+ /**
25
+ * Sentinel thrown by a polling call to signal that the operation has not
26
+ * yet reached a terminal state. {@link executeWait} treats this error as
27
+ * retriable; any other error aborts the wait.
28
+ */
29
+ export class StillRunningError extends Error {
30
+ }
31
+ /**
32
+ * Polls until the call returns without throwing {@link StillRunningError}.
33
+ * Abort and overall-deadline behavior come from the supplied LroOptions.
34
+ */
35
+ export async function executeWait(call, options) {
36
+ const opts = {
37
+ ...(options?.timeout !== undefined && { timeout: options.timeout }),
38
+ retrier: () => retryOn({}, (err) => err instanceof StillRunningError),
39
+ };
40
+ return execute(options?.signal, call, opts);
41
+ }
42
+ async function readAll(body) {
43
+ if (body === null) {
44
+ return new Uint8Array(0);
45
+ }
46
+ const reader = body.getReader();
47
+ const chunks = [];
48
+ for (;;) {
49
+ const { done, value } = await reader.read();
50
+ if (done) {
51
+ break;
52
+ }
53
+ chunks.push(value);
54
+ }
55
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
56
+ const result = new Uint8Array(totalLength);
57
+ let offset = 0;
58
+ for (const chunk of chunks) {
59
+ result.set(chunk, offset);
60
+ offset += chunk.length;
61
+ }
62
+ return result;
63
+ }
64
+ export async function executeHttpCall(opts) {
65
+ opts.logger.debug('HTTP request', {
66
+ method: opts.request.method,
67
+ url: opts.request.url,
68
+ });
69
+ let resp;
70
+ try {
71
+ resp = await opts.httpClient.send(opts.request);
72
+ }
73
+ catch (e) {
74
+ opts.logger.debug('HTTP request failed');
75
+ throw e;
76
+ }
77
+ const body = await readAll(resp.body);
78
+ opts.logger.debug('HTTP response', {
79
+ statusCode: resp.statusCode,
80
+ body: new TextDecoder().decode(body),
81
+ });
82
+ const apiErr = ApiError.fromHttpError(resp.statusCode, resp.headers, body);
83
+ if (apiErr !== undefined) {
84
+ throw apiErr;
85
+ }
86
+ return body;
87
+ }
88
+ export function buildHttpRequest(method, url, headers, signal, body) {
89
+ const req = { url, method, headers };
90
+ if (body !== undefined) {
91
+ req.body = body;
92
+ }
93
+ if (signal !== undefined) {
94
+ req.signal = signal;
95
+ }
96
+ return req;
97
+ }
98
+ export function parseResponse(body, schema) {
99
+ const text = new TextDecoder().decode(body);
100
+ const parsed = jsonBigint.parse(text);
101
+ return schema.parse(parsed);
102
+ }
103
+ export function marshalRequest(data, schema) {
104
+ return jsonBigint.stringify(schema.parse(data));
105
+ }
106
+ export function flattenQueryParams(prefix, value, params) {
107
+ if (value === null || value === undefined) {
108
+ return;
109
+ }
110
+ if (Array.isArray(value)) {
111
+ // arrays of objects are not yet supported
112
+ for (const item of value) {
113
+ params.append(prefix, String(item));
114
+ }
115
+ }
116
+ else if (typeof value === 'object') {
117
+ for (const [key, val] of Object.entries(value)) {
118
+ flattenQueryParams(`${prefix}.${key}`, val, params);
119
+ }
120
+ }
121
+ else if (typeof value === 'string' ||
122
+ typeof value === 'number' ||
123
+ typeof value === 'boolean' ||
124
+ typeof value === 'bigint') {
125
+ params.append(prefix, String(value));
126
+ }
127
+ else {
128
+ throw new Error(`Unsupported query parameter type: ${typeof value}`);
129
+ }
130
+ }
131
+ //# 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,EAAE,OAAO,EAAC,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,+BAA+B,CAAC;AASvD,OAAO,OAAO,MAAM,aAAa,CAAC;AAGlC,0EAA0E;AAC1E,6EAA6E;AAC7E,gEAAgE;AAChE,MAAM,UAAU,GAAG,OAAO,CAAC,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC,CAAC;AAQpD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAA6C,EAC7C,OAAqB;IAErB,MAAM,IAAI,GAAY;QACpB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,SAAS,IAAI,EAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAC,CAAC;QACjE,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,SAAS,IAAI;YACxC,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC;QACF,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,SAAS,IAAI,EAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAC,CAAC;KAClE,CAAC;IACF,OAAO,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9C,CA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AAI,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.2",
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.3 <1.0.0",
32
+ "@databricks/sdk-core": ">=0.1.0-dev.4 <1.0.0",
33
+ "@databricks/sdk-options": ">=0.1.0-dev.3 <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,405 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
5
+ import type {Logger} from '@databricks/sdk-core/logger';
6
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
7
+ import type {CallOptions} from '@databricks/sdk-options/call';
8
+ import type {ClientOptions} from '@databricks/sdk-options/client';
9
+ import type {LroOptions} from '@databricks/sdk-options/lro';
10
+ import type {HttpClient} from '@databricks/sdk-core/http';
11
+ import {newHttpClient} from './transport';
12
+ import {
13
+ buildHttpRequest,
14
+ executeCall,
15
+ executeHttpCall,
16
+ marshalRequest,
17
+ parseResponse,
18
+ executeWait,
19
+ StillRunningError,
20
+ } from './utils';
21
+ import pkgJson from '../../package.json' with {type: 'json'};
22
+ import {z} from 'zod';
23
+ import type {
24
+ CreateWorkspaceRequest,
25
+ DeleteWorkspaceRequest,
26
+ GetWorkspaceRequest,
27
+ ListWorkspacesRequest,
28
+ ListWorkspacesResponse,
29
+ UpdateWorkspaceRequest,
30
+ Workspace,
31
+ } from './model';
32
+ import {
33
+ WorkspaceStatus,
34
+ marshalCreateWorkspaceRequestSchema,
35
+ marshalWorkspaceSchema,
36
+ unmarshalWorkspaceSchema,
37
+ } from './model';
38
+
39
+ // Package identity segment for this client to be used in the User-Agent header.
40
+ const PACKAGE_SEGMENT = {
41
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
42
+ value: pkgJson.version,
43
+ };
44
+
45
+ export class WorkspacesClient {
46
+ private readonly host: string;
47
+ // Fallback for endpoints whose path contains {account_id}. If the request
48
+ // already carries an accountId, that value wins.
49
+ private readonly accountId: string | undefined;
50
+ private readonly httpClient: HttpClient;
51
+ private readonly logger: Logger;
52
+ // User-Agent header value. Composed once at construction from
53
+ // createDefault() merged with this package's identity and the active
54
+ // credential's name.
55
+ private readonly userAgent: string;
56
+
57
+ constructor(options: ClientOptions) {
58
+ if (options.host === undefined) {
59
+ throw new Error('Host is required.');
60
+ }
61
+ this.host = options.host.replace(/\/$/, '');
62
+ this.accountId = options.accountId;
63
+ this.logger = options.logger ?? new NoOpLogger();
64
+ const info = createDefault()
65
+ .with(PACKAGE_SEGMENT)
66
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
67
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
68
+ this.userAgent = info.toString();
69
+ this.httpClient = newHttpClient(options);
70
+ }
71
+
72
+ /**
73
+ * 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.
74
+ *
75
+ * 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.
76
+ *
77
+ * 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.
78
+ *
79
+ * 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).
80
+ *
81
+ * 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.
82
+ *
83
+ * 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.
84
+ */
85
+ private async createWorkspacePublic(
86
+ req: CreateWorkspaceRequest,
87
+ options?: CallOptions
88
+ ): Promise<Workspace> {
89
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces`;
90
+ const body = marshalRequest(req, marshalCreateWorkspaceRequestSchema);
91
+ let resp: Workspace | undefined;
92
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
93
+ const headers = new Headers({'Content-Type': 'application/json'});
94
+ headers.set('User-Agent', this.userAgent);
95
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
96
+ const respBody = await executeHttpCall({
97
+ request: httpReq,
98
+ httpClient: this.httpClient,
99
+ logger: this.logger,
100
+ });
101
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
102
+ };
103
+ await executeCall(call, options);
104
+ if (resp === undefined) {
105
+ throw new Error('operation completed without a result.');
106
+ }
107
+ return resp;
108
+ }
109
+
110
+ async createWorkspacePublicWaiter(
111
+ req: CreateWorkspaceRequest,
112
+ options?: CallOptions
113
+ ): Promise<CreateWorkspacePublicWaiter> {
114
+ const resp = await this.createWorkspacePublic(req, options);
115
+ if (resp.workspaceId === undefined) {
116
+ throw new Error(
117
+ 'response field workspaceId required for polling is missing'
118
+ );
119
+ }
120
+ return new CreateWorkspacePublicWaiter(this, resp.workspaceId);
121
+ }
122
+
123
+ /** Deletes a <Databricks> workspace, both specified by ID. */
124
+ async deleteWorkspacePublic(
125
+ req: DeleteWorkspaceRequest,
126
+ options?: CallOptions
127
+ ): Promise<Workspace> {
128
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}`;
129
+ let resp: Workspace | undefined;
130
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
131
+ const headers = new Headers();
132
+ headers.set('User-Agent', this.userAgent);
133
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
134
+ const respBody = await executeHttpCall({
135
+ request: httpReq,
136
+ httpClient: this.httpClient,
137
+ logger: this.logger,
138
+ });
139
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
140
+ };
141
+ await executeCall(call, options);
142
+ if (resp === undefined) {
143
+ throw new Error('operation completed without a result.');
144
+ }
145
+ return resp;
146
+ }
147
+
148
+ /**
149
+ * 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`.
150
+ * 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).
151
+ */
152
+ async getWorkspacePublic(
153
+ req: GetWorkspaceRequest,
154
+ options?: CallOptions
155
+ ): Promise<Workspace> {
156
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces/${String(req.workspaceId ?? '')}`;
157
+ let resp: Workspace | undefined;
158
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
159
+ const headers = new Headers();
160
+ headers.set('User-Agent', this.userAgent);
161
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
162
+ const respBody = await executeHttpCall({
163
+ request: httpReq,
164
+ httpClient: this.httpClient,
165
+ logger: this.logger,
166
+ });
167
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
168
+ };
169
+ await executeCall(call, options);
170
+ if (resp === undefined) {
171
+ throw new Error('operation completed without a result.');
172
+ }
173
+ return resp;
174
+ }
175
+
176
+ /** Lists <Databricks> workspaces for an account. */
177
+ async listWorkspacesPublic(
178
+ req: ListWorkspacesRequest,
179
+ options?: CallOptions
180
+ ): Promise<ListWorkspacesResponse> {
181
+ const url = `${this.host}/api/2.0/accounts/${req.accountId ?? this.accountId ?? ''}/workspaces`;
182
+ let resp: ListWorkspacesResponse | undefined;
183
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
184
+ const headers = new Headers();
185
+ headers.set('User-Agent', this.userAgent);
186
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
187
+ const respBody = await executeHttpCall({
188
+ request: httpReq,
189
+ httpClient: this.httpClient,
190
+ logger: this.logger,
191
+ });
192
+ resp = {
193
+ workspaces: parseResponse(
194
+ respBody,
195
+ z.array(z.lazy(() => unmarshalWorkspaceSchema))
196
+ ),
197
+ };
198
+ };
199
+ await executeCall(call, options);
200
+ if (resp === undefined) {
201
+ throw new Error('operation completed without a result.');
202
+ }
203
+ return resp;
204
+ }
205
+
206
+ /** Updates a workspace. */
207
+ private async updateWorkspacePublic(
208
+ req: UpdateWorkspaceRequest,
209
+ options?: CallOptions
210
+ ): Promise<Workspace> {
211
+ const url = `${this.host}/api/2.0/accounts/${req.customerFacingWorkspace?.accountId ?? this.accountId ?? ''}/workspaces/${String(req.customerFacingWorkspace?.workspaceId ?? '')}`;
212
+ const params = new URLSearchParams();
213
+ if (req.updateMask !== undefined) {
214
+ params.append('update_mask', req.updateMask.toString());
215
+ }
216
+ const query = params.toString();
217
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
218
+ const body = marshalRequest(
219
+ req.customerFacingWorkspace,
220
+ marshalWorkspaceSchema
221
+ );
222
+ let resp: Workspace | undefined;
223
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
224
+ const headers = new Headers({'Content-Type': 'application/json'});
225
+ headers.set('User-Agent', this.userAgent);
226
+ const httpReq = buildHttpRequest(
227
+ 'PATCH',
228
+ fullUrl,
229
+ headers,
230
+ callSignal,
231
+ body
232
+ );
233
+ const respBody = await executeHttpCall({
234
+ request: httpReq,
235
+ httpClient: this.httpClient,
236
+ logger: this.logger,
237
+ });
238
+ resp = parseResponse(respBody, unmarshalWorkspaceSchema);
239
+ };
240
+ await executeCall(call, options);
241
+ if (resp === undefined) {
242
+ throw new Error('operation completed without a result.');
243
+ }
244
+ return resp;
245
+ }
246
+
247
+ async updateWorkspacePublicWaiter(
248
+ req: UpdateWorkspaceRequest,
249
+ options?: CallOptions
250
+ ): Promise<UpdateWorkspacePublicWaiter> {
251
+ const resp = await this.updateWorkspacePublic(req, options);
252
+ if (resp.workspaceId === undefined) {
253
+ throw new Error(
254
+ 'response field workspaceId required for polling is missing'
255
+ );
256
+ }
257
+ return new UpdateWorkspacePublicWaiter(this, resp.workspaceId);
258
+ }
259
+ }
260
+
261
+ export class CreateWorkspacePublicWaiter {
262
+ constructor(
263
+ private readonly client: WorkspacesClient,
264
+ readonly workspaceId: bigint
265
+ ) {}
266
+
267
+ /**
268
+ * Polls until the operation reaches a terminal state.
269
+ *
270
+ * Throws if a failure state is reached.
271
+ */
272
+ async wait(options?: LroOptions): Promise<Workspace> {
273
+ let result: Workspace | undefined;
274
+
275
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
276
+ const pollResp = await this.client.getWorkspacePublic(
277
+ {
278
+ workspaceId: this.workspaceId,
279
+ },
280
+ callSignal !== undefined ? {signal: callSignal} : undefined
281
+ );
282
+
283
+ const status = pollResp.workspaceStatus;
284
+ if (status === undefined) {
285
+ throw new Error('response missing required status field');
286
+ }
287
+
288
+ switch (status) {
289
+ case WorkspaceStatus.RUNNING:
290
+ result = pollResp;
291
+ return;
292
+ case WorkspaceStatus.BANNED:
293
+ case WorkspaceStatus.FAILED: {
294
+ const msg = pollResp.workspaceStatusMessage ?? '(no message)';
295
+ throw new Error(`terminal state ${status}: ${msg}`);
296
+ }
297
+ default:
298
+ throw new StillRunningError();
299
+ }
300
+ };
301
+
302
+ await executeWait(call, options);
303
+ if (result === undefined) {
304
+ throw new Error('operation completed without a result.');
305
+ }
306
+ return result;
307
+ }
308
+
309
+ /** Checks whether the operation has reached a terminal state. */
310
+ async done(options?: CallOptions): Promise<boolean> {
311
+ const pollResp = await this.client.getWorkspacePublic(
312
+ {
313
+ workspaceId: this.workspaceId,
314
+ },
315
+ options
316
+ );
317
+
318
+ const status = pollResp.workspaceStatus;
319
+ if (status === undefined) {
320
+ throw new Error('response missing required status field');
321
+ }
322
+
323
+ switch (status) {
324
+ case WorkspaceStatus.RUNNING:
325
+ case WorkspaceStatus.BANNED:
326
+ case WorkspaceStatus.FAILED:
327
+ return true;
328
+ default:
329
+ return false;
330
+ }
331
+ }
332
+ }
333
+
334
+ export class UpdateWorkspacePublicWaiter {
335
+ constructor(
336
+ private readonly client: WorkspacesClient,
337
+ readonly workspaceId: bigint
338
+ ) {}
339
+
340
+ /**
341
+ * Polls until the operation reaches a terminal state.
342
+ *
343
+ * Throws if a failure state is reached.
344
+ */
345
+ async wait(options?: LroOptions): Promise<Workspace> {
346
+ let result: Workspace | undefined;
347
+
348
+ const call = async (callSignal?: AbortSignal): Promise<void> => {
349
+ const pollResp = await this.client.getWorkspacePublic(
350
+ {
351
+ workspaceId: this.workspaceId,
352
+ },
353
+ callSignal !== undefined ? {signal: callSignal} : undefined
354
+ );
355
+
356
+ const status = pollResp.workspaceStatus;
357
+ if (status === undefined) {
358
+ throw new Error('response missing required status field');
359
+ }
360
+
361
+ switch (status) {
362
+ case WorkspaceStatus.RUNNING:
363
+ result = pollResp;
364
+ return;
365
+ case WorkspaceStatus.BANNED:
366
+ case WorkspaceStatus.FAILED: {
367
+ const msg = pollResp.workspaceStatusMessage ?? '(no message)';
368
+ throw new Error(`terminal state ${status}: ${msg}`);
369
+ }
370
+ default:
371
+ throw new StillRunningError();
372
+ }
373
+ };
374
+
375
+ await executeWait(call, options);
376
+ if (result === undefined) {
377
+ throw new Error('operation completed without a result.');
378
+ }
379
+ return result;
380
+ }
381
+
382
+ /** Checks whether the operation has reached a terminal state. */
383
+ async done(options?: CallOptions): Promise<boolean> {
384
+ const pollResp = await this.client.getWorkspacePublic(
385
+ {
386
+ workspaceId: this.workspaceId,
387
+ },
388
+ options
389
+ );
390
+
391
+ const status = pollResp.workspaceStatus;
392
+ if (status === undefined) {
393
+ throw new Error('response missing required status field');
394
+ }
395
+
396
+ switch (status) {
397
+ case WorkspaceStatus.RUNNING:
398
+ case WorkspaceStatus.BANNED:
399
+ case WorkspaceStatus.FAILED:
400
+ return true;
401
+ default:
402
+ return false;
403
+ }
404
+ }
405
+ }
@@ -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';