@databricks/sdk-workspaces 0.1.0-dev.3 → 0.1.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/v1/client.ts DELETED
@@ -1,405 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
- import {createDefault} from '@databricks/sdk-core/clientinfo';
5
- import type {Logger} from '@databricks/sdk-core/logger';
6
- import {NoOpLogger} from '@databricks/sdk-core/logger';
7
- import type {CallOptions} from '@databricks/sdk-options/call';
8
- import type {ClientOptions} from '@databricks/sdk-options/client';
9
- import type {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
- }
package/src/v1/index.ts DELETED
@@ -1,36 +0,0 @@
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';