@databricks/sdk-postgres 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,3455 @@
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
+ Branch,
24
+ BranchOperationMetadata,
25
+ Catalog,
26
+ CatalogOperationMetadata,
27
+ CreateBranchRequest,
28
+ CreateCatalogRequest,
29
+ CreateDatabaseRequest,
30
+ CreateEndpointRequest,
31
+ CreateProjectRequest,
32
+ CreateRoleRequest,
33
+ CreateSyncedTableRequest,
34
+ Database,
35
+ DatabaseCredential,
36
+ DatabaseOperationMetadata,
37
+ DeleteBranchRequest,
38
+ DeleteCatalogRequest,
39
+ DeleteDatabaseRequest,
40
+ DeleteEndpointRequest,
41
+ DeleteProjectRequest,
42
+ DeleteRoleRequest,
43
+ DeleteSyncedTableRequest,
44
+ Endpoint,
45
+ EndpointOperationMetadata,
46
+ GenerateDatabaseCredentialRequest,
47
+ GetBranchRequest,
48
+ GetCatalogRequest,
49
+ GetDatabaseRequest,
50
+ GetEndpointRequest,
51
+ GetOperationRequest,
52
+ GetProjectRequest,
53
+ GetRoleRequest,
54
+ GetSyncedTableRequest,
55
+ ListBranchesRequest,
56
+ ListBranchesResponse,
57
+ ListDatabasesRequest,
58
+ ListDatabasesResponse,
59
+ ListEndpointsRequest,
60
+ ListEndpointsResponse,
61
+ ListProjectsRequest,
62
+ ListProjectsResponse,
63
+ ListRolesRequest,
64
+ ListRolesResponse,
65
+ Operation,
66
+ Project,
67
+ ProjectOperationMetadata,
68
+ Role,
69
+ RoleOperationMetadata,
70
+ SyncedTable,
71
+ SyncedTableOperationMetadata,
72
+ UndeleteBranchRequest,
73
+ UndeleteProjectRequest,
74
+ UpdateBranchRequest,
75
+ UpdateDatabaseRequest,
76
+ UpdateEndpointRequest,
77
+ UpdateProjectRequest,
78
+ UpdateRoleRequest,
79
+ } from './model';
80
+ import {
81
+ marshalBranchSchema,
82
+ marshalCatalogSchema,
83
+ marshalDatabaseSchema,
84
+ marshalEndpointSchema,
85
+ marshalGenerateDatabaseCredentialRequestSchema,
86
+ marshalProjectSchema,
87
+ marshalRoleSchema,
88
+ marshalSyncedTableSchema,
89
+ marshalUndeleteBranchRequestSchema,
90
+ marshalUndeleteProjectRequestSchema,
91
+ unmarshalBranchOperationMetadataSchema,
92
+ unmarshalBranchSchema,
93
+ unmarshalCatalogOperationMetadataSchema,
94
+ unmarshalCatalogSchema,
95
+ unmarshalDatabaseCredentialSchema,
96
+ unmarshalDatabaseOperationMetadataSchema,
97
+ unmarshalDatabaseSchema,
98
+ unmarshalEndpointOperationMetadataSchema,
99
+ unmarshalEndpointSchema,
100
+ unmarshalListBranchesResponseSchema,
101
+ unmarshalListDatabasesResponseSchema,
102
+ unmarshalListEndpointsResponseSchema,
103
+ unmarshalListProjectsResponseSchema,
104
+ unmarshalListRolesResponseSchema,
105
+ unmarshalOperationSchema,
106
+ unmarshalProjectOperationMetadataSchema,
107
+ unmarshalProjectSchema,
108
+ unmarshalRoleOperationMetadataSchema,
109
+ unmarshalRoleSchema,
110
+ unmarshalSyncedTableOperationMetadataSchema,
111
+ unmarshalSyncedTableSchema,
112
+ } from './model';
113
+
114
+ // Package identity segment for this client to be used in the User-Agent header.
115
+ const PACKAGE_SEGMENT = {
116
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
117
+ value: pkgJson.version,
118
+ };
119
+
120
+ export class Client {
121
+ private readonly host: string;
122
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
123
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
124
+ // request.
125
+ private readonly workspaceId: string | undefined;
126
+ private readonly httpClient: HttpClient;
127
+ private readonly logger: Logger;
128
+ // User-Agent header value. Composed once at construction from
129
+ // createDefault() merged with this package's identity and the active
130
+ // credential's name.
131
+ private readonly userAgent: string;
132
+
133
+ constructor(options: ClientOptions) {
134
+ if (options.host === undefined) {
135
+ throw new Error('Host is required.');
136
+ }
137
+ this.host = options.host.replace(/\/$/, '');
138
+ this.workspaceId = options.workspaceId;
139
+ this.logger = options.logger ?? new NoOpLogger();
140
+ let info = createDefault().with(PACKAGE_SEGMENT);
141
+ if (options.credentials !== undefined) {
142
+ info = info
143
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
144
+ .with({key: 'auth', value: options.credentials.name()});
145
+ }
146
+ this.userAgent = info.toString();
147
+ this.httpClient = newHttpClient(options);
148
+ }
149
+
150
+ /** Creates a new database branch in the project. */
151
+ async createBranch(
152
+ req: CreateBranchRequest,
153
+ options?: CallOptions
154
+ ): Promise<Operation> {
155
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/branches`;
156
+ const params = new URLSearchParams();
157
+ if (req.branchId !== undefined) {
158
+ params.append('branch_id', req.branchId);
159
+ }
160
+ if (req.replaceExisting !== undefined) {
161
+ params.append('replace_existing', String(req.replaceExisting));
162
+ }
163
+ const query = params.toString();
164
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
165
+ const body = marshalRequest(req.branch, marshalBranchSchema);
166
+ let resp: Operation | undefined;
167
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
168
+ const headers = new Headers({'Content-Type': 'application/json'});
169
+ if (this.workspaceId !== undefined) {
170
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
171
+ }
172
+ headers.set('User-Agent', this.userAgent);
173
+ const httpReq = buildHttpRequest(
174
+ 'POST',
175
+ fullUrl,
176
+ headers,
177
+ callSignal,
178
+ body
179
+ );
180
+ const respBody = await executeHttpCall({
181
+ request: httpReq,
182
+ httpClient: this.httpClient,
183
+ logger: this.logger,
184
+ });
185
+ resp = parseResponse(respBody, unmarshalOperationSchema);
186
+ };
187
+ await executeCall(call, options);
188
+ if (resp === undefined) {
189
+ throw new Error('API call completed without a result.');
190
+ }
191
+ return resp;
192
+ }
193
+
194
+ async createBranchOperation(
195
+ req: CreateBranchRequest,
196
+ options?: CallOptions
197
+ ): Promise<CreateBranchOperation> {
198
+ const op = await this.createBranch(req, options);
199
+ return new CreateBranchOperation(this, op);
200
+ }
201
+
202
+ /** Register a Postgres database in the Unity Catalog. */
203
+ async createCatalog(
204
+ req: CreateCatalogRequest,
205
+ options?: CallOptions
206
+ ): Promise<Operation> {
207
+ const url = `${this.host}/api/2.0/postgres/catalogs`;
208
+ const params = new URLSearchParams();
209
+ if (req.catalogId !== undefined) {
210
+ params.append('catalog_id', req.catalogId);
211
+ }
212
+ const query = params.toString();
213
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
214
+ const body = marshalRequest(req.catalog, marshalCatalogSchema);
215
+ let resp: Operation | undefined;
216
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
217
+ const headers = new Headers({'Content-Type': 'application/json'});
218
+ if (this.workspaceId !== undefined) {
219
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
220
+ }
221
+ headers.set('User-Agent', this.userAgent);
222
+ const httpReq = buildHttpRequest(
223
+ 'POST',
224
+ fullUrl,
225
+ headers,
226
+ callSignal,
227
+ body
228
+ );
229
+ const respBody = await executeHttpCall({
230
+ request: httpReq,
231
+ httpClient: this.httpClient,
232
+ logger: this.logger,
233
+ });
234
+ resp = parseResponse(respBody, unmarshalOperationSchema);
235
+ };
236
+ await executeCall(call, options);
237
+ if (resp === undefined) {
238
+ throw new Error('API call completed without a result.');
239
+ }
240
+ return resp;
241
+ }
242
+
243
+ async createCatalogOperation(
244
+ req: CreateCatalogRequest,
245
+ options?: CallOptions
246
+ ): Promise<CreateCatalogOperation> {
247
+ const op = await this.createCatalog(req, options);
248
+ return new CreateCatalogOperation(this, op);
249
+ }
250
+
251
+ /**
252
+ * Create a Database.
253
+ *
254
+ * Creates a database in the specified branch. A branch can have multiple databases.
255
+ */
256
+ async createDatabase(
257
+ req: CreateDatabaseRequest,
258
+ options?: CallOptions
259
+ ): Promise<Operation> {
260
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/databases`;
261
+ const params = new URLSearchParams();
262
+ if (req.databaseId !== undefined) {
263
+ params.append('database_id', req.databaseId);
264
+ }
265
+ const query = params.toString();
266
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
267
+ const body = marshalRequest(req.database, marshalDatabaseSchema);
268
+ let resp: Operation | undefined;
269
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
270
+ const headers = new Headers({'Content-Type': 'application/json'});
271
+ if (this.workspaceId !== undefined) {
272
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
273
+ }
274
+ headers.set('User-Agent', this.userAgent);
275
+ const httpReq = buildHttpRequest(
276
+ 'POST',
277
+ fullUrl,
278
+ headers,
279
+ callSignal,
280
+ body
281
+ );
282
+ const respBody = await executeHttpCall({
283
+ request: httpReq,
284
+ httpClient: this.httpClient,
285
+ logger: this.logger,
286
+ });
287
+ resp = parseResponse(respBody, unmarshalOperationSchema);
288
+ };
289
+ await executeCall(call, options);
290
+ if (resp === undefined) {
291
+ throw new Error('API call completed without a result.');
292
+ }
293
+ return resp;
294
+ }
295
+
296
+ async createDatabaseOperation(
297
+ req: CreateDatabaseRequest,
298
+ options?: CallOptions
299
+ ): Promise<CreateDatabaseOperation> {
300
+ const op = await this.createDatabase(req, options);
301
+ return new CreateDatabaseOperation(this, op);
302
+ }
303
+
304
+ /** Creates a new compute endpoint in the branch. */
305
+ async createEndpoint(
306
+ req: CreateEndpointRequest,
307
+ options?: CallOptions
308
+ ): Promise<Operation> {
309
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/endpoints`;
310
+ const params = new URLSearchParams();
311
+ if (req.endpointId !== undefined) {
312
+ params.append('endpoint_id', req.endpointId);
313
+ }
314
+ if (req.replaceExisting !== undefined) {
315
+ params.append('replace_existing', String(req.replaceExisting));
316
+ }
317
+ const query = params.toString();
318
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
319
+ const body = marshalRequest(req.endpoint, marshalEndpointSchema);
320
+ let resp: Operation | undefined;
321
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
322
+ const headers = new Headers({'Content-Type': 'application/json'});
323
+ if (this.workspaceId !== undefined) {
324
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
325
+ }
326
+ headers.set('User-Agent', this.userAgent);
327
+ const httpReq = buildHttpRequest(
328
+ 'POST',
329
+ fullUrl,
330
+ headers,
331
+ callSignal,
332
+ body
333
+ );
334
+ const respBody = await executeHttpCall({
335
+ request: httpReq,
336
+ httpClient: this.httpClient,
337
+ logger: this.logger,
338
+ });
339
+ resp = parseResponse(respBody, unmarshalOperationSchema);
340
+ };
341
+ await executeCall(call, options);
342
+ if (resp === undefined) {
343
+ throw new Error('API call completed without a result.');
344
+ }
345
+ return resp;
346
+ }
347
+
348
+ async createEndpointOperation(
349
+ req: CreateEndpointRequest,
350
+ options?: CallOptions
351
+ ): Promise<CreateEndpointOperation> {
352
+ const op = await this.createEndpoint(req, options);
353
+ return new CreateEndpointOperation(this, op);
354
+ }
355
+
356
+ /** Creates a new Lakebase Autoscaling Postgres database project, which contains branches and compute endpoints. */
357
+ async createProject(
358
+ req: CreateProjectRequest,
359
+ options?: CallOptions
360
+ ): Promise<Operation> {
361
+ const url = `${this.host}/api/2.0/postgres/projects`;
362
+ const params = new URLSearchParams();
363
+ if (req.projectId !== undefined) {
364
+ params.append('project_id', req.projectId);
365
+ }
366
+ const query = params.toString();
367
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
368
+ const body = marshalRequest(req.project, marshalProjectSchema);
369
+ let resp: Operation | undefined;
370
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
371
+ const headers = new Headers({'Content-Type': 'application/json'});
372
+ if (this.workspaceId !== undefined) {
373
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
374
+ }
375
+ headers.set('User-Agent', this.userAgent);
376
+ const httpReq = buildHttpRequest(
377
+ 'POST',
378
+ fullUrl,
379
+ headers,
380
+ callSignal,
381
+ body
382
+ );
383
+ const respBody = await executeHttpCall({
384
+ request: httpReq,
385
+ httpClient: this.httpClient,
386
+ logger: this.logger,
387
+ });
388
+ resp = parseResponse(respBody, unmarshalOperationSchema);
389
+ };
390
+ await executeCall(call, options);
391
+ if (resp === undefined) {
392
+ throw new Error('API call completed without a result.');
393
+ }
394
+ return resp;
395
+ }
396
+
397
+ async createProjectOperation(
398
+ req: CreateProjectRequest,
399
+ options?: CallOptions
400
+ ): Promise<CreateProjectOperation> {
401
+ const op = await this.createProject(req, options);
402
+ return new CreateProjectOperation(this, op);
403
+ }
404
+
405
+ /** Creates a new Postgres role in the branch. */
406
+ async createRole(
407
+ req: CreateRoleRequest,
408
+ options?: CallOptions
409
+ ): Promise<Operation> {
410
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/roles`;
411
+ const params = new URLSearchParams();
412
+ if (req.roleId !== undefined) {
413
+ params.append('role_id', req.roleId);
414
+ }
415
+ const query = params.toString();
416
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
417
+ const body = marshalRequest(req.role, marshalRoleSchema);
418
+ let resp: Operation | undefined;
419
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
420
+ const headers = new Headers({'Content-Type': 'application/json'});
421
+ if (this.workspaceId !== undefined) {
422
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
423
+ }
424
+ headers.set('User-Agent', this.userAgent);
425
+ const httpReq = buildHttpRequest(
426
+ 'POST',
427
+ fullUrl,
428
+ headers,
429
+ callSignal,
430
+ body
431
+ );
432
+ const respBody = await executeHttpCall({
433
+ request: httpReq,
434
+ httpClient: this.httpClient,
435
+ logger: this.logger,
436
+ });
437
+ resp = parseResponse(respBody, unmarshalOperationSchema);
438
+ };
439
+ await executeCall(call, options);
440
+ if (resp === undefined) {
441
+ throw new Error('API call completed without a result.');
442
+ }
443
+ return resp;
444
+ }
445
+
446
+ async createRoleOperation(
447
+ req: CreateRoleRequest,
448
+ options?: CallOptions
449
+ ): Promise<CreateRoleOperation> {
450
+ const op = await this.createRole(req, options);
451
+ return new CreateRoleOperation(this, op);
452
+ }
453
+
454
+ /** Create a Synced Table. */
455
+ async createSyncedTable(
456
+ req: CreateSyncedTableRequest,
457
+ options?: CallOptions
458
+ ): Promise<Operation> {
459
+ const url = `${this.host}/api/2.0/postgres/synced_tables`;
460
+ const params = new URLSearchParams();
461
+ if (req.syncedTableId !== undefined) {
462
+ params.append('synced_table_id', req.syncedTableId);
463
+ }
464
+ const query = params.toString();
465
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
466
+ const body = marshalRequest(req.syncedTable, marshalSyncedTableSchema);
467
+ let resp: Operation | undefined;
468
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
469
+ const headers = new Headers({'Content-Type': 'application/json'});
470
+ if (this.workspaceId !== undefined) {
471
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
472
+ }
473
+ headers.set('User-Agent', this.userAgent);
474
+ const httpReq = buildHttpRequest(
475
+ 'POST',
476
+ fullUrl,
477
+ headers,
478
+ callSignal,
479
+ body
480
+ );
481
+ const respBody = await executeHttpCall({
482
+ request: httpReq,
483
+ httpClient: this.httpClient,
484
+ logger: this.logger,
485
+ });
486
+ resp = parseResponse(respBody, unmarshalOperationSchema);
487
+ };
488
+ await executeCall(call, options);
489
+ if (resp === undefined) {
490
+ throw new Error('API call completed without a result.');
491
+ }
492
+ return resp;
493
+ }
494
+
495
+ async createSyncedTableOperation(
496
+ req: CreateSyncedTableRequest,
497
+ options?: CallOptions
498
+ ): Promise<CreateSyncedTableOperation> {
499
+ const op = await this.createSyncedTable(req, options);
500
+ return new CreateSyncedTableOperation(this, op);
501
+ }
502
+
503
+ /** Deletes the specified database branch. */
504
+ async deleteBranch(
505
+ req: DeleteBranchRequest,
506
+ options?: CallOptions
507
+ ): Promise<Operation> {
508
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
509
+ const params = new URLSearchParams();
510
+ if (req.purge !== undefined) {
511
+ params.append('purge', String(req.purge));
512
+ }
513
+ const query = params.toString();
514
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
515
+ let resp: Operation | undefined;
516
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
517
+ const headers = new Headers();
518
+ if (this.workspaceId !== undefined) {
519
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
520
+ }
521
+ headers.set('User-Agent', this.userAgent);
522
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
523
+ const respBody = await executeHttpCall({
524
+ request: httpReq,
525
+ httpClient: this.httpClient,
526
+ logger: this.logger,
527
+ });
528
+ resp = parseResponse(respBody, unmarshalOperationSchema);
529
+ };
530
+ await executeCall(call, options);
531
+ if (resp === undefined) {
532
+ throw new Error('API call completed without a result.');
533
+ }
534
+ return resp;
535
+ }
536
+
537
+ async deleteBranchOperation(
538
+ req: DeleteBranchRequest,
539
+ options?: CallOptions
540
+ ): Promise<DeleteBranchOperation> {
541
+ const op = await this.deleteBranch(req, options);
542
+ return new DeleteBranchOperation(this, op);
543
+ }
544
+
545
+ /** Delete a Database Catalog. */
546
+ async deleteCatalog(
547
+ req: DeleteCatalogRequest,
548
+ options?: CallOptions
549
+ ): Promise<Operation> {
550
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
551
+ let resp: Operation | undefined;
552
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
553
+ const headers = new Headers();
554
+ if (this.workspaceId !== undefined) {
555
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
556
+ }
557
+ headers.set('User-Agent', this.userAgent);
558
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
559
+ const respBody = await executeHttpCall({
560
+ request: httpReq,
561
+ httpClient: this.httpClient,
562
+ logger: this.logger,
563
+ });
564
+ resp = parseResponse(respBody, unmarshalOperationSchema);
565
+ };
566
+ await executeCall(call, options);
567
+ if (resp === undefined) {
568
+ throw new Error('API call completed without a result.');
569
+ }
570
+ return resp;
571
+ }
572
+
573
+ async deleteCatalogOperation(
574
+ req: DeleteCatalogRequest,
575
+ options?: CallOptions
576
+ ): Promise<DeleteCatalogOperation> {
577
+ const op = await this.deleteCatalog(req, options);
578
+ return new DeleteCatalogOperation(this, op);
579
+ }
580
+
581
+ /** Delete a Database. */
582
+ async deleteDatabase(
583
+ req: DeleteDatabaseRequest,
584
+ options?: CallOptions
585
+ ): Promise<Operation> {
586
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
587
+ let resp: Operation | undefined;
588
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
589
+ const headers = new Headers();
590
+ if (this.workspaceId !== undefined) {
591
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
592
+ }
593
+ headers.set('User-Agent', this.userAgent);
594
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
595
+ const respBody = await executeHttpCall({
596
+ request: httpReq,
597
+ httpClient: this.httpClient,
598
+ logger: this.logger,
599
+ });
600
+ resp = parseResponse(respBody, unmarshalOperationSchema);
601
+ };
602
+ await executeCall(call, options);
603
+ if (resp === undefined) {
604
+ throw new Error('API call completed without a result.');
605
+ }
606
+ return resp;
607
+ }
608
+
609
+ async deleteDatabaseOperation(
610
+ req: DeleteDatabaseRequest,
611
+ options?: CallOptions
612
+ ): Promise<DeleteDatabaseOperation> {
613
+ const op = await this.deleteDatabase(req, options);
614
+ return new DeleteDatabaseOperation(this, op);
615
+ }
616
+
617
+ /** Deletes the specified compute endpoint. */
618
+ async deleteEndpoint(
619
+ req: DeleteEndpointRequest,
620
+ options?: CallOptions
621
+ ): Promise<Operation> {
622
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
623
+ let resp: Operation | undefined;
624
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
625
+ const headers = new Headers();
626
+ if (this.workspaceId !== undefined) {
627
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
628
+ }
629
+ headers.set('User-Agent', this.userAgent);
630
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
631
+ const respBody = await executeHttpCall({
632
+ request: httpReq,
633
+ httpClient: this.httpClient,
634
+ logger: this.logger,
635
+ });
636
+ resp = parseResponse(respBody, unmarshalOperationSchema);
637
+ };
638
+ await executeCall(call, options);
639
+ if (resp === undefined) {
640
+ throw new Error('API call completed without a result.');
641
+ }
642
+ return resp;
643
+ }
644
+
645
+ async deleteEndpointOperation(
646
+ req: DeleteEndpointRequest,
647
+ options?: CallOptions
648
+ ): Promise<DeleteEndpointOperation> {
649
+ const op = await this.deleteEndpoint(req, options);
650
+ return new DeleteEndpointOperation(this, op);
651
+ }
652
+
653
+ /** Deletes the specified database project. */
654
+ async deleteProject(
655
+ req: DeleteProjectRequest,
656
+ options?: CallOptions
657
+ ): Promise<Operation> {
658
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
659
+ const params = new URLSearchParams();
660
+ if (req.purge !== undefined) {
661
+ params.append('purge', String(req.purge));
662
+ }
663
+ const query = params.toString();
664
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
665
+ let resp: Operation | undefined;
666
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
667
+ const headers = new Headers();
668
+ if (this.workspaceId !== undefined) {
669
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
670
+ }
671
+ headers.set('User-Agent', this.userAgent);
672
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
673
+ const respBody = await executeHttpCall({
674
+ request: httpReq,
675
+ httpClient: this.httpClient,
676
+ logger: this.logger,
677
+ });
678
+ resp = parseResponse(respBody, unmarshalOperationSchema);
679
+ };
680
+ await executeCall(call, options);
681
+ if (resp === undefined) {
682
+ throw new Error('API call completed without a result.');
683
+ }
684
+ return resp;
685
+ }
686
+
687
+ async deleteProjectOperation(
688
+ req: DeleteProjectRequest,
689
+ options?: CallOptions
690
+ ): Promise<DeleteProjectOperation> {
691
+ const op = await this.deleteProject(req, options);
692
+ return new DeleteProjectOperation(this, op);
693
+ }
694
+
695
+ /** Deletes the specified Postgres role. */
696
+ async deleteRole(
697
+ req: DeleteRoleRequest,
698
+ options?: CallOptions
699
+ ): Promise<Operation> {
700
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
701
+ const params = new URLSearchParams();
702
+ if (req.reassignOwnedTo !== undefined) {
703
+ params.append('reassign_owned_to', req.reassignOwnedTo);
704
+ }
705
+ const query = params.toString();
706
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
707
+ let resp: Operation | undefined;
708
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
709
+ const headers = new Headers();
710
+ if (this.workspaceId !== undefined) {
711
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
712
+ }
713
+ headers.set('User-Agent', this.userAgent);
714
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
715
+ const respBody = await executeHttpCall({
716
+ request: httpReq,
717
+ httpClient: this.httpClient,
718
+ logger: this.logger,
719
+ });
720
+ resp = parseResponse(respBody, unmarshalOperationSchema);
721
+ };
722
+ await executeCall(call, options);
723
+ if (resp === undefined) {
724
+ throw new Error('API call completed without a result.');
725
+ }
726
+ return resp;
727
+ }
728
+
729
+ async deleteRoleOperation(
730
+ req: DeleteRoleRequest,
731
+ options?: CallOptions
732
+ ): Promise<DeleteRoleOperation> {
733
+ const op = await this.deleteRole(req, options);
734
+ return new DeleteRoleOperation(this, op);
735
+ }
736
+
737
+ /** Delete a Synced Table. */
738
+ async deleteSyncedTable(
739
+ req: DeleteSyncedTableRequest,
740
+ options?: CallOptions
741
+ ): Promise<Operation> {
742
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
743
+ let resp: Operation | undefined;
744
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
745
+ const headers = new Headers();
746
+ if (this.workspaceId !== undefined) {
747
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
748
+ }
749
+ headers.set('User-Agent', this.userAgent);
750
+ const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
751
+ const respBody = await executeHttpCall({
752
+ request: httpReq,
753
+ httpClient: this.httpClient,
754
+ logger: this.logger,
755
+ });
756
+ resp = parseResponse(respBody, unmarshalOperationSchema);
757
+ };
758
+ await executeCall(call, options);
759
+ if (resp === undefined) {
760
+ throw new Error('API call completed without a result.');
761
+ }
762
+ return resp;
763
+ }
764
+
765
+ async deleteSyncedTableOperation(
766
+ req: DeleteSyncedTableRequest,
767
+ options?: CallOptions
768
+ ): Promise<DeleteSyncedTableOperation> {
769
+ const op = await this.deleteSyncedTable(req, options);
770
+ return new DeleteSyncedTableOperation(this, op);
771
+ }
772
+
773
+ /** Generate OAuth credentials for a Postgres database. */
774
+ async generateDatabaseCredential(
775
+ req: GenerateDatabaseCredentialRequest,
776
+ options?: CallOptions
777
+ ): Promise<DatabaseCredential> {
778
+ const url = `${this.host}/api/2.0/postgres/credentials`;
779
+ const body = marshalRequest(
780
+ req,
781
+ marshalGenerateDatabaseCredentialRequestSchema
782
+ );
783
+ let resp: DatabaseCredential | undefined;
784
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
785
+ const headers = new Headers({'Content-Type': 'application/json'});
786
+ if (this.workspaceId !== undefined) {
787
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
788
+ }
789
+ headers.set('User-Agent', this.userAgent);
790
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
791
+ const respBody = await executeHttpCall({
792
+ request: httpReq,
793
+ httpClient: this.httpClient,
794
+ logger: this.logger,
795
+ });
796
+ resp = parseResponse(respBody, unmarshalDatabaseCredentialSchema);
797
+ };
798
+ await executeCall(call, options);
799
+ if (resp === undefined) {
800
+ throw new Error('API call completed without a result.');
801
+ }
802
+ return resp;
803
+ }
804
+
805
+ /** Retrieves information about the specified database branch. */
806
+ async getBranch(
807
+ req: GetBranchRequest,
808
+ options?: CallOptions
809
+ ): Promise<Branch> {
810
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
811
+ let resp: Branch | undefined;
812
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
813
+ const headers = new Headers();
814
+ if (this.workspaceId !== undefined) {
815
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
816
+ }
817
+ headers.set('User-Agent', this.userAgent);
818
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
819
+ const respBody = await executeHttpCall({
820
+ request: httpReq,
821
+ httpClient: this.httpClient,
822
+ logger: this.logger,
823
+ });
824
+ resp = parseResponse(respBody, unmarshalBranchSchema);
825
+ };
826
+ await executeCall(call, options);
827
+ if (resp === undefined) {
828
+ throw new Error('API call completed without a result.');
829
+ }
830
+ return resp;
831
+ }
832
+
833
+ /** Get a Database Catalog. */
834
+ async getCatalog(
835
+ req: GetCatalogRequest,
836
+ options?: CallOptions
837
+ ): Promise<Catalog> {
838
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
839
+ let resp: Catalog | undefined;
840
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
841
+ const headers = new Headers();
842
+ if (this.workspaceId !== undefined) {
843
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
844
+ }
845
+ headers.set('User-Agent', this.userAgent);
846
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
847
+ const respBody = await executeHttpCall({
848
+ request: httpReq,
849
+ httpClient: this.httpClient,
850
+ logger: this.logger,
851
+ });
852
+ resp = parseResponse(respBody, unmarshalCatalogSchema);
853
+ };
854
+ await executeCall(call, options);
855
+ if (resp === undefined) {
856
+ throw new Error('API call completed without a result.');
857
+ }
858
+ return resp;
859
+ }
860
+
861
+ /** Get a Database. */
862
+ async getDatabase(
863
+ req: GetDatabaseRequest,
864
+ options?: CallOptions
865
+ ): Promise<Database> {
866
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
867
+ let resp: Database | undefined;
868
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
869
+ const headers = new Headers();
870
+ if (this.workspaceId !== undefined) {
871
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
872
+ }
873
+ headers.set('User-Agent', this.userAgent);
874
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
875
+ const respBody = await executeHttpCall({
876
+ request: httpReq,
877
+ httpClient: this.httpClient,
878
+ logger: this.logger,
879
+ });
880
+ resp = parseResponse(respBody, unmarshalDatabaseSchema);
881
+ };
882
+ await executeCall(call, options);
883
+ if (resp === undefined) {
884
+ throw new Error('API call completed without a result.');
885
+ }
886
+ return resp;
887
+ }
888
+
889
+ /** Retrieves information about the specified compute endpoint, including its connection details and operational state. */
890
+ async getEndpoint(
891
+ req: GetEndpointRequest,
892
+ options?: CallOptions
893
+ ): Promise<Endpoint> {
894
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
895
+ let resp: Endpoint | undefined;
896
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
897
+ const headers = new Headers();
898
+ if (this.workspaceId !== undefined) {
899
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
900
+ }
901
+ headers.set('User-Agent', this.userAgent);
902
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
903
+ const respBody = await executeHttpCall({
904
+ request: httpReq,
905
+ httpClient: this.httpClient,
906
+ logger: this.logger,
907
+ });
908
+ resp = parseResponse(respBody, unmarshalEndpointSchema);
909
+ };
910
+ await executeCall(call, options);
911
+ if (resp === undefined) {
912
+ throw new Error('API call completed without a result.');
913
+ }
914
+ return resp;
915
+ }
916
+
917
+ /** Retrieves the status of a long-running operation. */
918
+ async getOperation(
919
+ req: GetOperationRequest,
920
+ options?: CallOptions
921
+ ): Promise<Operation> {
922
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
923
+ let resp: Operation | undefined;
924
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
925
+ const headers = new Headers();
926
+ if (this.workspaceId !== undefined) {
927
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
928
+ }
929
+ headers.set('User-Agent', this.userAgent);
930
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
931
+ const respBody = await executeHttpCall({
932
+ request: httpReq,
933
+ httpClient: this.httpClient,
934
+ logger: this.logger,
935
+ });
936
+ resp = parseResponse(respBody, unmarshalOperationSchema);
937
+ };
938
+ await executeCall(call, options);
939
+ if (resp === undefined) {
940
+ throw new Error('API call completed without a result.');
941
+ }
942
+ return resp;
943
+ }
944
+
945
+ /** Retrieves information about the specified database project. */
946
+ async getProject(
947
+ req: GetProjectRequest,
948
+ options?: CallOptions
949
+ ): Promise<Project> {
950
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
951
+ let resp: Project | undefined;
952
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
953
+ const headers = new Headers();
954
+ if (this.workspaceId !== undefined) {
955
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
956
+ }
957
+ headers.set('User-Agent', this.userAgent);
958
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
959
+ const respBody = await executeHttpCall({
960
+ request: httpReq,
961
+ httpClient: this.httpClient,
962
+ logger: this.logger,
963
+ });
964
+ resp = parseResponse(respBody, unmarshalProjectSchema);
965
+ };
966
+ await executeCall(call, options);
967
+ if (resp === undefined) {
968
+ throw new Error('API call completed without a result.');
969
+ }
970
+ return resp;
971
+ }
972
+
973
+ /** Retrieves information about the specified Postgres role, including its authentication method and permissions. */
974
+ async getRole(req: GetRoleRequest, options?: CallOptions): Promise<Role> {
975
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
976
+ let resp: Role | undefined;
977
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
978
+ const headers = new Headers();
979
+ if (this.workspaceId !== undefined) {
980
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
981
+ }
982
+ headers.set('User-Agent', this.userAgent);
983
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
984
+ const respBody = await executeHttpCall({
985
+ request: httpReq,
986
+ httpClient: this.httpClient,
987
+ logger: this.logger,
988
+ });
989
+ resp = parseResponse(respBody, unmarshalRoleSchema);
990
+ };
991
+ await executeCall(call, options);
992
+ if (resp === undefined) {
993
+ throw new Error('API call completed without a result.');
994
+ }
995
+ return resp;
996
+ }
997
+
998
+ /** Get a Synced Table. */
999
+ async getSyncedTable(
1000
+ req: GetSyncedTableRequest,
1001
+ options?: CallOptions
1002
+ ): Promise<SyncedTable> {
1003
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}`;
1004
+ let resp: SyncedTable | undefined;
1005
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1006
+ const headers = new Headers();
1007
+ if (this.workspaceId !== undefined) {
1008
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1009
+ }
1010
+ headers.set('User-Agent', this.userAgent);
1011
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
1012
+ const respBody = await executeHttpCall({
1013
+ request: httpReq,
1014
+ httpClient: this.httpClient,
1015
+ logger: this.logger,
1016
+ });
1017
+ resp = parseResponse(respBody, unmarshalSyncedTableSchema);
1018
+ };
1019
+ await executeCall(call, options);
1020
+ if (resp === undefined) {
1021
+ throw new Error('API call completed without a result.');
1022
+ }
1023
+ return resp;
1024
+ }
1025
+
1026
+ /** Returns a paginated list of database branches in the project. */
1027
+ async listBranches(
1028
+ req: ListBranchesRequest,
1029
+ options?: CallOptions
1030
+ ): Promise<ListBranchesResponse> {
1031
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/branches`;
1032
+ const params = new URLSearchParams();
1033
+ if (req.pageToken !== undefined) {
1034
+ params.append('page_token', req.pageToken);
1035
+ }
1036
+ if (req.pageSize !== undefined) {
1037
+ params.append('page_size', String(req.pageSize));
1038
+ }
1039
+ if (req.showDeleted !== undefined) {
1040
+ params.append('show_deleted', String(req.showDeleted));
1041
+ }
1042
+ const query = params.toString();
1043
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1044
+ let resp: ListBranchesResponse | undefined;
1045
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1046
+ const headers = new Headers();
1047
+ if (this.workspaceId !== undefined) {
1048
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1049
+ }
1050
+ headers.set('User-Agent', this.userAgent);
1051
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
1052
+ const respBody = await executeHttpCall({
1053
+ request: httpReq,
1054
+ httpClient: this.httpClient,
1055
+ logger: this.logger,
1056
+ });
1057
+ resp = parseResponse(respBody, unmarshalListBranchesResponseSchema);
1058
+ };
1059
+ await executeCall(call, options);
1060
+ if (resp === undefined) {
1061
+ throw new Error('API call completed without a result.');
1062
+ }
1063
+ return resp;
1064
+ }
1065
+
1066
+ async *listBranchesIter(
1067
+ req: ListBranchesRequest,
1068
+ options?: CallOptions
1069
+ ): AsyncGenerator<Branch> {
1070
+ const pageReq: ListBranchesRequest = {...req};
1071
+ for (;;) {
1072
+ const resp = await this.listBranches(pageReq, options);
1073
+ for (const item of resp.branches ?? []) {
1074
+ yield item;
1075
+ }
1076
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
1077
+ return;
1078
+ }
1079
+ pageReq.pageToken = resp.nextPageToken;
1080
+ }
1081
+ }
1082
+
1083
+ /** List Databases. */
1084
+ async listDatabases(
1085
+ req: ListDatabasesRequest,
1086
+ options?: CallOptions
1087
+ ): Promise<ListDatabasesResponse> {
1088
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/databases`;
1089
+ const params = new URLSearchParams();
1090
+ if (req.pageToken !== undefined) {
1091
+ params.append('page_token', req.pageToken);
1092
+ }
1093
+ if (req.pageSize !== undefined) {
1094
+ params.append('page_size', String(req.pageSize));
1095
+ }
1096
+ const query = params.toString();
1097
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1098
+ let resp: ListDatabasesResponse | undefined;
1099
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1100
+ const headers = new Headers();
1101
+ if (this.workspaceId !== undefined) {
1102
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1103
+ }
1104
+ headers.set('User-Agent', this.userAgent);
1105
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
1106
+ const respBody = await executeHttpCall({
1107
+ request: httpReq,
1108
+ httpClient: this.httpClient,
1109
+ logger: this.logger,
1110
+ });
1111
+ resp = parseResponse(respBody, unmarshalListDatabasesResponseSchema);
1112
+ };
1113
+ await executeCall(call, options);
1114
+ if (resp === undefined) {
1115
+ throw new Error('API call completed without a result.');
1116
+ }
1117
+ return resp;
1118
+ }
1119
+
1120
+ async *listDatabasesIter(
1121
+ req: ListDatabasesRequest,
1122
+ options?: CallOptions
1123
+ ): AsyncGenerator<Database> {
1124
+ const pageReq: ListDatabasesRequest = {...req};
1125
+ for (;;) {
1126
+ const resp = await this.listDatabases(pageReq, options);
1127
+ for (const item of resp.databases ?? []) {
1128
+ yield item;
1129
+ }
1130
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
1131
+ return;
1132
+ }
1133
+ pageReq.pageToken = resp.nextPageToken;
1134
+ }
1135
+ }
1136
+
1137
+ /** Returns a paginated list of compute endpoints in the branch. */
1138
+ async listEndpoints(
1139
+ req: ListEndpointsRequest,
1140
+ options?: CallOptions
1141
+ ): Promise<ListEndpointsResponse> {
1142
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/endpoints`;
1143
+ const params = new URLSearchParams();
1144
+ if (req.pageToken !== undefined) {
1145
+ params.append('page_token', req.pageToken);
1146
+ }
1147
+ if (req.pageSize !== undefined) {
1148
+ params.append('page_size', String(req.pageSize));
1149
+ }
1150
+ const query = params.toString();
1151
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1152
+ let resp: ListEndpointsResponse | undefined;
1153
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1154
+ const headers = new Headers();
1155
+ if (this.workspaceId !== undefined) {
1156
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1157
+ }
1158
+ headers.set('User-Agent', this.userAgent);
1159
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
1160
+ const respBody = await executeHttpCall({
1161
+ request: httpReq,
1162
+ httpClient: this.httpClient,
1163
+ logger: this.logger,
1164
+ });
1165
+ resp = parseResponse(respBody, unmarshalListEndpointsResponseSchema);
1166
+ };
1167
+ await executeCall(call, options);
1168
+ if (resp === undefined) {
1169
+ throw new Error('API call completed without a result.');
1170
+ }
1171
+ return resp;
1172
+ }
1173
+
1174
+ async *listEndpointsIter(
1175
+ req: ListEndpointsRequest,
1176
+ options?: CallOptions
1177
+ ): AsyncGenerator<Endpoint> {
1178
+ const pageReq: ListEndpointsRequest = {...req};
1179
+ for (;;) {
1180
+ const resp = await this.listEndpoints(pageReq, options);
1181
+ for (const item of resp.endpoints ?? []) {
1182
+ yield item;
1183
+ }
1184
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
1185
+ return;
1186
+ }
1187
+ pageReq.pageToken = resp.nextPageToken;
1188
+ }
1189
+ }
1190
+
1191
+ /** Returns a paginated list of database projects in the workspace that the user has permission to access. */
1192
+ async listProjects(
1193
+ req: ListProjectsRequest,
1194
+ options?: CallOptions
1195
+ ): Promise<ListProjectsResponse> {
1196
+ const url = `${this.host}/api/2.0/postgres/projects`;
1197
+ const params = new URLSearchParams();
1198
+ if (req.pageToken !== undefined) {
1199
+ params.append('page_token', req.pageToken);
1200
+ }
1201
+ if (req.pageSize !== undefined) {
1202
+ params.append('page_size', String(req.pageSize));
1203
+ }
1204
+ if (req.showDeleted !== undefined) {
1205
+ params.append('show_deleted', String(req.showDeleted));
1206
+ }
1207
+ const query = params.toString();
1208
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1209
+ let resp: ListProjectsResponse | undefined;
1210
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1211
+ const headers = new Headers();
1212
+ if (this.workspaceId !== undefined) {
1213
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1214
+ }
1215
+ headers.set('User-Agent', this.userAgent);
1216
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
1217
+ const respBody = await executeHttpCall({
1218
+ request: httpReq,
1219
+ httpClient: this.httpClient,
1220
+ logger: this.logger,
1221
+ });
1222
+ resp = parseResponse(respBody, unmarshalListProjectsResponseSchema);
1223
+ };
1224
+ await executeCall(call, options);
1225
+ if (resp === undefined) {
1226
+ throw new Error('API call completed without a result.');
1227
+ }
1228
+ return resp;
1229
+ }
1230
+
1231
+ async *listProjectsIter(
1232
+ req: ListProjectsRequest,
1233
+ options?: CallOptions
1234
+ ): AsyncGenerator<Project> {
1235
+ const pageReq: ListProjectsRequest = {...req};
1236
+ for (;;) {
1237
+ const resp = await this.listProjects(pageReq, options);
1238
+ for (const item of resp.projects ?? []) {
1239
+ yield item;
1240
+ }
1241
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
1242
+ return;
1243
+ }
1244
+ pageReq.pageToken = resp.nextPageToken;
1245
+ }
1246
+ }
1247
+
1248
+ /** Returns a paginated list of Postgres roles in the branch. */
1249
+ async listRoles(
1250
+ req: ListRolesRequest,
1251
+ options?: CallOptions
1252
+ ): Promise<ListRolesResponse> {
1253
+ const url = `${this.host}/api/2.0/postgres/${req.parent ?? ''}/roles`;
1254
+ const params = new URLSearchParams();
1255
+ if (req.pageToken !== undefined) {
1256
+ params.append('page_token', req.pageToken);
1257
+ }
1258
+ if (req.pageSize !== undefined) {
1259
+ params.append('page_size', String(req.pageSize));
1260
+ }
1261
+ const query = params.toString();
1262
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1263
+ let resp: ListRolesResponse | undefined;
1264
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1265
+ const headers = new Headers();
1266
+ if (this.workspaceId !== undefined) {
1267
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1268
+ }
1269
+ headers.set('User-Agent', this.userAgent);
1270
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
1271
+ const respBody = await executeHttpCall({
1272
+ request: httpReq,
1273
+ httpClient: this.httpClient,
1274
+ logger: this.logger,
1275
+ });
1276
+ resp = parseResponse(respBody, unmarshalListRolesResponseSchema);
1277
+ };
1278
+ await executeCall(call, options);
1279
+ if (resp === undefined) {
1280
+ throw new Error('API call completed without a result.');
1281
+ }
1282
+ return resp;
1283
+ }
1284
+
1285
+ async *listRolesIter(
1286
+ req: ListRolesRequest,
1287
+ options?: CallOptions
1288
+ ): AsyncGenerator<Role> {
1289
+ const pageReq: ListRolesRequest = {...req};
1290
+ for (;;) {
1291
+ const resp = await this.listRoles(pageReq, options);
1292
+ for (const item of resp.roles ?? []) {
1293
+ yield item;
1294
+ }
1295
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
1296
+ return;
1297
+ }
1298
+ pageReq.pageToken = resp.nextPageToken;
1299
+ }
1300
+ }
1301
+
1302
+ /** Undeletes the specified database branch. */
1303
+ async undeleteBranch(
1304
+ req: UndeleteBranchRequest,
1305
+ options?: CallOptions
1306
+ ): Promise<Operation> {
1307
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}/undelete`;
1308
+ const body = marshalRequest(req, marshalUndeleteBranchRequestSchema);
1309
+ let resp: Operation | undefined;
1310
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1311
+ const headers = new Headers({'Content-Type': 'application/json'});
1312
+ if (this.workspaceId !== undefined) {
1313
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1314
+ }
1315
+ headers.set('User-Agent', this.userAgent);
1316
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
1317
+ const respBody = await executeHttpCall({
1318
+ request: httpReq,
1319
+ httpClient: this.httpClient,
1320
+ logger: this.logger,
1321
+ });
1322
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1323
+ };
1324
+ await executeCall(call, options);
1325
+ if (resp === undefined) {
1326
+ throw new Error('API call completed without a result.');
1327
+ }
1328
+ return resp;
1329
+ }
1330
+
1331
+ async undeleteBranchOperation(
1332
+ req: UndeleteBranchRequest,
1333
+ options?: CallOptions
1334
+ ): Promise<UndeleteBranchOperation> {
1335
+ const op = await this.undeleteBranch(req, options);
1336
+ return new UndeleteBranchOperation(this, op);
1337
+ }
1338
+
1339
+ /** Undeletes a soft-deleted project. */
1340
+ async undeleteProject(
1341
+ req: UndeleteProjectRequest,
1342
+ options?: CallOptions
1343
+ ): Promise<Operation> {
1344
+ const url = `${this.host}/api/2.0/postgres/${req.name ?? ''}/undelete`;
1345
+ const body = marshalRequest(req, marshalUndeleteProjectRequestSchema);
1346
+ let resp: Operation | undefined;
1347
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1348
+ const headers = new Headers({'Content-Type': 'application/json'});
1349
+ if (this.workspaceId !== undefined) {
1350
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1351
+ }
1352
+ headers.set('User-Agent', this.userAgent);
1353
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
1354
+ const respBody = await executeHttpCall({
1355
+ request: httpReq,
1356
+ httpClient: this.httpClient,
1357
+ logger: this.logger,
1358
+ });
1359
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1360
+ };
1361
+ await executeCall(call, options);
1362
+ if (resp === undefined) {
1363
+ throw new Error('API call completed without a result.');
1364
+ }
1365
+ return resp;
1366
+ }
1367
+
1368
+ async undeleteProjectOperation(
1369
+ req: UndeleteProjectRequest,
1370
+ options?: CallOptions
1371
+ ): Promise<UndeleteProjectOperation> {
1372
+ const op = await this.undeleteProject(req, options);
1373
+ return new UndeleteProjectOperation(this, op);
1374
+ }
1375
+
1376
+ /** Updates the specified database branch. You can set this branch as the project's default branch, or protect/unprotect it. */
1377
+ async updateBranch(
1378
+ req: UpdateBranchRequest,
1379
+ options?: CallOptions
1380
+ ): Promise<Operation> {
1381
+ const url = `${this.host}/api/2.0/postgres/${req.branch?.name ?? ''}`;
1382
+ const params = new URLSearchParams();
1383
+ if (req.updateMask !== undefined) {
1384
+ params.append('update_mask', req.updateMask.toString());
1385
+ }
1386
+ const query = params.toString();
1387
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1388
+ const body = marshalRequest(req.branch, marshalBranchSchema);
1389
+ let resp: Operation | undefined;
1390
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1391
+ const headers = new Headers({'Content-Type': 'application/json'});
1392
+ if (this.workspaceId !== undefined) {
1393
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1394
+ }
1395
+ headers.set('User-Agent', this.userAgent);
1396
+ const httpReq = buildHttpRequest(
1397
+ 'PATCH',
1398
+ fullUrl,
1399
+ headers,
1400
+ callSignal,
1401
+ body
1402
+ );
1403
+ const respBody = await executeHttpCall({
1404
+ request: httpReq,
1405
+ httpClient: this.httpClient,
1406
+ logger: this.logger,
1407
+ });
1408
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1409
+ };
1410
+ await executeCall(call, options);
1411
+ if (resp === undefined) {
1412
+ throw new Error('API call completed without a result.');
1413
+ }
1414
+ return resp;
1415
+ }
1416
+
1417
+ async updateBranchOperation(
1418
+ req: UpdateBranchRequest,
1419
+ options?: CallOptions
1420
+ ): Promise<UpdateBranchOperation> {
1421
+ const op = await this.updateBranch(req, options);
1422
+ return new UpdateBranchOperation(this, op);
1423
+ }
1424
+
1425
+ /** Update a Database. */
1426
+ async updateDatabase(
1427
+ req: UpdateDatabaseRequest,
1428
+ options?: CallOptions
1429
+ ): Promise<Operation> {
1430
+ const url = `${this.host}/api/2.0/postgres/${req.database?.name ?? ''}`;
1431
+ const params = new URLSearchParams();
1432
+ if (req.updateMask !== undefined) {
1433
+ params.append('update_mask', req.updateMask.toString());
1434
+ }
1435
+ const query = params.toString();
1436
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1437
+ const body = marshalRequest(req.database, marshalDatabaseSchema);
1438
+ let resp: Operation | undefined;
1439
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1440
+ const headers = new Headers({'Content-Type': 'application/json'});
1441
+ if (this.workspaceId !== undefined) {
1442
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1443
+ }
1444
+ headers.set('User-Agent', this.userAgent);
1445
+ const httpReq = buildHttpRequest(
1446
+ 'PATCH',
1447
+ fullUrl,
1448
+ headers,
1449
+ callSignal,
1450
+ body
1451
+ );
1452
+ const respBody = await executeHttpCall({
1453
+ request: httpReq,
1454
+ httpClient: this.httpClient,
1455
+ logger: this.logger,
1456
+ });
1457
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1458
+ };
1459
+ await executeCall(call, options);
1460
+ if (resp === undefined) {
1461
+ throw new Error('API call completed without a result.');
1462
+ }
1463
+ return resp;
1464
+ }
1465
+
1466
+ async updateDatabaseOperation(
1467
+ req: UpdateDatabaseRequest,
1468
+ options?: CallOptions
1469
+ ): Promise<UpdateDatabaseOperation> {
1470
+ const op = await this.updateDatabase(req, options);
1471
+ return new UpdateDatabaseOperation(this, op);
1472
+ }
1473
+
1474
+ /** Updates the specified compute endpoint. You can update autoscaling limits, suspend timeout, or enable/disable the compute endpoint. */
1475
+ async updateEndpoint(
1476
+ req: UpdateEndpointRequest,
1477
+ options?: CallOptions
1478
+ ): Promise<Operation> {
1479
+ const url = `${this.host}/api/2.0/postgres/${req.endpoint?.name ?? ''}`;
1480
+ const params = new URLSearchParams();
1481
+ if (req.updateMask !== undefined) {
1482
+ params.append('update_mask', req.updateMask.toString());
1483
+ }
1484
+ const query = params.toString();
1485
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1486
+ const body = marshalRequest(req.endpoint, marshalEndpointSchema);
1487
+ let resp: Operation | undefined;
1488
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1489
+ const headers = new Headers({'Content-Type': 'application/json'});
1490
+ if (this.workspaceId !== undefined) {
1491
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1492
+ }
1493
+ headers.set('User-Agent', this.userAgent);
1494
+ const httpReq = buildHttpRequest(
1495
+ 'PATCH',
1496
+ fullUrl,
1497
+ headers,
1498
+ callSignal,
1499
+ body
1500
+ );
1501
+ const respBody = await executeHttpCall({
1502
+ request: httpReq,
1503
+ httpClient: this.httpClient,
1504
+ logger: this.logger,
1505
+ });
1506
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1507
+ };
1508
+ await executeCall(call, options);
1509
+ if (resp === undefined) {
1510
+ throw new Error('API call completed without a result.');
1511
+ }
1512
+ return resp;
1513
+ }
1514
+
1515
+ async updateEndpointOperation(
1516
+ req: UpdateEndpointRequest,
1517
+ options?: CallOptions
1518
+ ): Promise<UpdateEndpointOperation> {
1519
+ const op = await this.updateEndpoint(req, options);
1520
+ return new UpdateEndpointOperation(this, op);
1521
+ }
1522
+
1523
+ /** Updates the specified database project. */
1524
+ async updateProject(
1525
+ req: UpdateProjectRequest,
1526
+ options?: CallOptions
1527
+ ): Promise<Operation> {
1528
+ const url = `${this.host}/api/2.0/postgres/${req.project?.name ?? ''}`;
1529
+ const params = new URLSearchParams();
1530
+ if (req.updateMask !== undefined) {
1531
+ params.append('update_mask', req.updateMask.toString());
1532
+ }
1533
+ const query = params.toString();
1534
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1535
+ const body = marshalRequest(req.project, marshalProjectSchema);
1536
+ let resp: Operation | undefined;
1537
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1538
+ const headers = new Headers({'Content-Type': 'application/json'});
1539
+ if (this.workspaceId !== undefined) {
1540
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1541
+ }
1542
+ headers.set('User-Agent', this.userAgent);
1543
+ const httpReq = buildHttpRequest(
1544
+ 'PATCH',
1545
+ fullUrl,
1546
+ headers,
1547
+ callSignal,
1548
+ body
1549
+ );
1550
+ const respBody = await executeHttpCall({
1551
+ request: httpReq,
1552
+ httpClient: this.httpClient,
1553
+ logger: this.logger,
1554
+ });
1555
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1556
+ };
1557
+ await executeCall(call, options);
1558
+ if (resp === undefined) {
1559
+ throw new Error('API call completed without a result.');
1560
+ }
1561
+ return resp;
1562
+ }
1563
+
1564
+ async updateProjectOperation(
1565
+ req: UpdateProjectRequest,
1566
+ options?: CallOptions
1567
+ ): Promise<UpdateProjectOperation> {
1568
+ const op = await this.updateProject(req, options);
1569
+ return new UpdateProjectOperation(this, op);
1570
+ }
1571
+
1572
+ /** Update a role for a branch. */
1573
+ async updateRole(
1574
+ req: UpdateRoleRequest,
1575
+ options?: CallOptions
1576
+ ): Promise<Operation> {
1577
+ const url = `${this.host}/api/2.0/postgres/${req.role?.name ?? ''}`;
1578
+ const params = new URLSearchParams();
1579
+ if (req.updateMask !== undefined) {
1580
+ params.append('update_mask', req.updateMask.toString());
1581
+ }
1582
+ const query = params.toString();
1583
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
1584
+ const body = marshalRequest(req.role, marshalRoleSchema);
1585
+ let resp: Operation | undefined;
1586
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1587
+ const headers = new Headers({'Content-Type': 'application/json'});
1588
+ if (this.workspaceId !== undefined) {
1589
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
1590
+ }
1591
+ headers.set('User-Agent', this.userAgent);
1592
+ const httpReq = buildHttpRequest(
1593
+ 'PATCH',
1594
+ fullUrl,
1595
+ headers,
1596
+ callSignal,
1597
+ body
1598
+ );
1599
+ const respBody = await executeHttpCall({
1600
+ request: httpReq,
1601
+ httpClient: this.httpClient,
1602
+ logger: this.logger,
1603
+ });
1604
+ resp = parseResponse(respBody, unmarshalOperationSchema);
1605
+ };
1606
+ await executeCall(call, options);
1607
+ if (resp === undefined) {
1608
+ throw new Error('API call completed without a result.');
1609
+ }
1610
+ return resp;
1611
+ }
1612
+
1613
+ async updateRoleOperation(
1614
+ req: UpdateRoleRequest,
1615
+ options?: CallOptions
1616
+ ): Promise<UpdateRoleOperation> {
1617
+ const op = await this.updateRole(req, options);
1618
+ return new UpdateRoleOperation(this, op);
1619
+ }
1620
+ }
1621
+
1622
+ export class CreateBranchOperation {
1623
+ constructor(
1624
+ private readonly client: Client,
1625
+ private operation: Operation
1626
+ ) {}
1627
+
1628
+ /** Returns the server-assigned name of the long-running operation. */
1629
+ name(): Promise<string | undefined> {
1630
+ return Promise.resolve(this.operation.name);
1631
+ }
1632
+
1633
+ /** Returns metadata associated with the long-running operation. */
1634
+ metadata(): Promise<BranchOperationMetadata | undefined> {
1635
+ if (this.operation.metadata === undefined) {
1636
+ return Promise.resolve(undefined);
1637
+ }
1638
+ return Promise.resolve(
1639
+ z
1640
+ .lazy(() => unmarshalBranchOperationMetadataSchema)
1641
+ .parse(this.operation.metadata)
1642
+ );
1643
+ }
1644
+
1645
+ /**
1646
+ * Polls the operation until it completes.
1647
+ *
1648
+ * Throws if the operation failed.
1649
+ */
1650
+ async wait(options?: CallOptions): Promise<Branch> {
1651
+ const errStillRunning = new Error('operation still in progress');
1652
+ let result: Branch | undefined;
1653
+
1654
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1655
+ const op = await this.client.getOperation(
1656
+ {
1657
+ name: this.operation.name,
1658
+ },
1659
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
1660
+ );
1661
+ this.operation = op;
1662
+ if (op.done === undefined) {
1663
+ throw new Error('operation is missing the done field');
1664
+ }
1665
+ if (!op.done) {
1666
+ throw errStillRunning;
1667
+ }
1668
+
1669
+ if (op.result?.$case === 'error') {
1670
+ const err = op.result.error;
1671
+ const msg =
1672
+ err.message !== undefined && err.message !== ''
1673
+ ? err.message
1674
+ : 'unknown error';
1675
+ const errorMsg =
1676
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
1677
+ throw new Error(`operation failed: ${errorMsg}`, {
1678
+ cause: err,
1679
+ });
1680
+ }
1681
+
1682
+ if (op.result?.$case !== 'response') {
1683
+ throw new Error('operation completed without a response');
1684
+ }
1685
+
1686
+ result = z.lazy(() => unmarshalBranchSchema).parse(op.result.response);
1687
+ };
1688
+
1689
+ const retryOptions: CallOptions = {
1690
+ ...(options?.signal !== undefined && {signal: options.signal}),
1691
+ retrier: () =>
1692
+ retryOn({}, (err: Error) => {
1693
+ return err.message.includes('operation still in progress');
1694
+ }),
1695
+ };
1696
+ await executeCall(call, retryOptions);
1697
+ if (result === undefined) {
1698
+ throw new Error('API call completed without a result.');
1699
+ }
1700
+ return result;
1701
+ }
1702
+
1703
+ /** Checks whether the operation has completed */
1704
+ async done(options?: CallOptions): Promise<boolean | undefined> {
1705
+ const op = await this.client.getOperation(
1706
+ {name: this.operation.name},
1707
+ options
1708
+ );
1709
+ this.operation = op;
1710
+ return op.done;
1711
+ }
1712
+ }
1713
+
1714
+ export class CreateCatalogOperation {
1715
+ constructor(
1716
+ private readonly client: Client,
1717
+ private operation: Operation
1718
+ ) {}
1719
+
1720
+ /** Returns the server-assigned name of the long-running operation. */
1721
+ name(): Promise<string | undefined> {
1722
+ return Promise.resolve(this.operation.name);
1723
+ }
1724
+
1725
+ /** Returns metadata associated with the long-running operation. */
1726
+ metadata(): Promise<CatalogOperationMetadata | undefined> {
1727
+ if (this.operation.metadata === undefined) {
1728
+ return Promise.resolve(undefined);
1729
+ }
1730
+ return Promise.resolve(
1731
+ z
1732
+ .lazy(() => unmarshalCatalogOperationMetadataSchema)
1733
+ .parse(this.operation.metadata)
1734
+ );
1735
+ }
1736
+
1737
+ /**
1738
+ * Polls the operation until it completes.
1739
+ *
1740
+ * Throws if the operation failed.
1741
+ */
1742
+ async wait(options?: CallOptions): Promise<Catalog> {
1743
+ const errStillRunning = new Error('operation still in progress');
1744
+ let result: Catalog | undefined;
1745
+
1746
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1747
+ const op = await this.client.getOperation(
1748
+ {
1749
+ name: this.operation.name,
1750
+ },
1751
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
1752
+ );
1753
+ this.operation = op;
1754
+ if (op.done === undefined) {
1755
+ throw new Error('operation is missing the done field');
1756
+ }
1757
+ if (!op.done) {
1758
+ throw errStillRunning;
1759
+ }
1760
+
1761
+ if (op.result?.$case === 'error') {
1762
+ const err = op.result.error;
1763
+ const msg =
1764
+ err.message !== undefined && err.message !== ''
1765
+ ? err.message
1766
+ : 'unknown error';
1767
+ const errorMsg =
1768
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
1769
+ throw new Error(`operation failed: ${errorMsg}`, {
1770
+ cause: err,
1771
+ });
1772
+ }
1773
+
1774
+ if (op.result?.$case !== 'response') {
1775
+ throw new Error('operation completed without a response');
1776
+ }
1777
+
1778
+ result = z.lazy(() => unmarshalCatalogSchema).parse(op.result.response);
1779
+ };
1780
+
1781
+ const retryOptions: CallOptions = {
1782
+ ...(options?.signal !== undefined && {signal: options.signal}),
1783
+ retrier: () =>
1784
+ retryOn({}, (err: Error) => {
1785
+ return err.message.includes('operation still in progress');
1786
+ }),
1787
+ };
1788
+ await executeCall(call, retryOptions);
1789
+ if (result === undefined) {
1790
+ throw new Error('API call completed without a result.');
1791
+ }
1792
+ return result;
1793
+ }
1794
+
1795
+ /** Checks whether the operation has completed */
1796
+ async done(options?: CallOptions): Promise<boolean | undefined> {
1797
+ const op = await this.client.getOperation(
1798
+ {name: this.operation.name},
1799
+ options
1800
+ );
1801
+ this.operation = op;
1802
+ return op.done;
1803
+ }
1804
+ }
1805
+
1806
+ export class CreateDatabaseOperation {
1807
+ constructor(
1808
+ private readonly client: Client,
1809
+ private operation: Operation
1810
+ ) {}
1811
+
1812
+ /** Returns the server-assigned name of the long-running operation. */
1813
+ name(): Promise<string | undefined> {
1814
+ return Promise.resolve(this.operation.name);
1815
+ }
1816
+
1817
+ /** Returns metadata associated with the long-running operation. */
1818
+ metadata(): Promise<DatabaseOperationMetadata | undefined> {
1819
+ if (this.operation.metadata === undefined) {
1820
+ return Promise.resolve(undefined);
1821
+ }
1822
+ return Promise.resolve(
1823
+ z
1824
+ .lazy(() => unmarshalDatabaseOperationMetadataSchema)
1825
+ .parse(this.operation.metadata)
1826
+ );
1827
+ }
1828
+
1829
+ /**
1830
+ * Polls the operation until it completes.
1831
+ *
1832
+ * Throws if the operation failed.
1833
+ */
1834
+ async wait(options?: CallOptions): Promise<Database> {
1835
+ const errStillRunning = new Error('operation still in progress');
1836
+ let result: Database | undefined;
1837
+
1838
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1839
+ const op = await this.client.getOperation(
1840
+ {
1841
+ name: this.operation.name,
1842
+ },
1843
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
1844
+ );
1845
+ this.operation = op;
1846
+ if (op.done === undefined) {
1847
+ throw new Error('operation is missing the done field');
1848
+ }
1849
+ if (!op.done) {
1850
+ throw errStillRunning;
1851
+ }
1852
+
1853
+ if (op.result?.$case === 'error') {
1854
+ const err = op.result.error;
1855
+ const msg =
1856
+ err.message !== undefined && err.message !== ''
1857
+ ? err.message
1858
+ : 'unknown error';
1859
+ const errorMsg =
1860
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
1861
+ throw new Error(`operation failed: ${errorMsg}`, {
1862
+ cause: err,
1863
+ });
1864
+ }
1865
+
1866
+ if (op.result?.$case !== 'response') {
1867
+ throw new Error('operation completed without a response');
1868
+ }
1869
+
1870
+ result = z.lazy(() => unmarshalDatabaseSchema).parse(op.result.response);
1871
+ };
1872
+
1873
+ const retryOptions: CallOptions = {
1874
+ ...(options?.signal !== undefined && {signal: options.signal}),
1875
+ retrier: () =>
1876
+ retryOn({}, (err: Error) => {
1877
+ return err.message.includes('operation still in progress');
1878
+ }),
1879
+ };
1880
+ await executeCall(call, retryOptions);
1881
+ if (result === undefined) {
1882
+ throw new Error('API call completed without a result.');
1883
+ }
1884
+ return result;
1885
+ }
1886
+
1887
+ /** Checks whether the operation has completed */
1888
+ async done(options?: CallOptions): Promise<boolean | undefined> {
1889
+ const op = await this.client.getOperation(
1890
+ {name: this.operation.name},
1891
+ options
1892
+ );
1893
+ this.operation = op;
1894
+ return op.done;
1895
+ }
1896
+ }
1897
+
1898
+ export class CreateEndpointOperation {
1899
+ constructor(
1900
+ private readonly client: Client,
1901
+ private operation: Operation
1902
+ ) {}
1903
+
1904
+ /** Returns the server-assigned name of the long-running operation. */
1905
+ name(): Promise<string | undefined> {
1906
+ return Promise.resolve(this.operation.name);
1907
+ }
1908
+
1909
+ /** Returns metadata associated with the long-running operation. */
1910
+ metadata(): Promise<EndpointOperationMetadata | undefined> {
1911
+ if (this.operation.metadata === undefined) {
1912
+ return Promise.resolve(undefined);
1913
+ }
1914
+ return Promise.resolve(
1915
+ z
1916
+ .lazy(() => unmarshalEndpointOperationMetadataSchema)
1917
+ .parse(this.operation.metadata)
1918
+ );
1919
+ }
1920
+
1921
+ /**
1922
+ * Polls the operation until it completes.
1923
+ *
1924
+ * Throws if the operation failed.
1925
+ */
1926
+ async wait(options?: CallOptions): Promise<Endpoint> {
1927
+ const errStillRunning = new Error('operation still in progress');
1928
+ let result: Endpoint | undefined;
1929
+
1930
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
1931
+ const op = await this.client.getOperation(
1932
+ {
1933
+ name: this.operation.name,
1934
+ },
1935
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
1936
+ );
1937
+ this.operation = op;
1938
+ if (op.done === undefined) {
1939
+ throw new Error('operation is missing the done field');
1940
+ }
1941
+ if (!op.done) {
1942
+ throw errStillRunning;
1943
+ }
1944
+
1945
+ if (op.result?.$case === 'error') {
1946
+ const err = op.result.error;
1947
+ const msg =
1948
+ err.message !== undefined && err.message !== ''
1949
+ ? err.message
1950
+ : 'unknown error';
1951
+ const errorMsg =
1952
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
1953
+ throw new Error(`operation failed: ${errorMsg}`, {
1954
+ cause: err,
1955
+ });
1956
+ }
1957
+
1958
+ if (op.result?.$case !== 'response') {
1959
+ throw new Error('operation completed without a response');
1960
+ }
1961
+
1962
+ result = z.lazy(() => unmarshalEndpointSchema).parse(op.result.response);
1963
+ };
1964
+
1965
+ const retryOptions: CallOptions = {
1966
+ ...(options?.signal !== undefined && {signal: options.signal}),
1967
+ retrier: () =>
1968
+ retryOn({}, (err: Error) => {
1969
+ return err.message.includes('operation still in progress');
1970
+ }),
1971
+ };
1972
+ await executeCall(call, retryOptions);
1973
+ if (result === undefined) {
1974
+ throw new Error('API call completed without a result.');
1975
+ }
1976
+ return result;
1977
+ }
1978
+
1979
+ /** Checks whether the operation has completed */
1980
+ async done(options?: CallOptions): Promise<boolean | undefined> {
1981
+ const op = await this.client.getOperation(
1982
+ {name: this.operation.name},
1983
+ options
1984
+ );
1985
+ this.operation = op;
1986
+ return op.done;
1987
+ }
1988
+ }
1989
+
1990
+ export class CreateProjectOperation {
1991
+ constructor(
1992
+ private readonly client: Client,
1993
+ private operation: Operation
1994
+ ) {}
1995
+
1996
+ /** Returns the server-assigned name of the long-running operation. */
1997
+ name(): Promise<string | undefined> {
1998
+ return Promise.resolve(this.operation.name);
1999
+ }
2000
+
2001
+ /** Returns metadata associated with the long-running operation. */
2002
+ metadata(): Promise<ProjectOperationMetadata | undefined> {
2003
+ if (this.operation.metadata === undefined) {
2004
+ return Promise.resolve(undefined);
2005
+ }
2006
+ return Promise.resolve(
2007
+ z
2008
+ .lazy(() => unmarshalProjectOperationMetadataSchema)
2009
+ .parse(this.operation.metadata)
2010
+ );
2011
+ }
2012
+
2013
+ /**
2014
+ * Polls the operation until it completes.
2015
+ *
2016
+ * Throws if the operation failed.
2017
+ */
2018
+ async wait(options?: CallOptions): Promise<Project> {
2019
+ const errStillRunning = new Error('operation still in progress');
2020
+ let result: Project | undefined;
2021
+
2022
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2023
+ const op = await this.client.getOperation(
2024
+ {
2025
+ name: this.operation.name,
2026
+ },
2027
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2028
+ );
2029
+ this.operation = op;
2030
+ if (op.done === undefined) {
2031
+ throw new Error('operation is missing the done field');
2032
+ }
2033
+ if (!op.done) {
2034
+ throw errStillRunning;
2035
+ }
2036
+
2037
+ if (op.result?.$case === 'error') {
2038
+ const err = op.result.error;
2039
+ const msg =
2040
+ err.message !== undefined && err.message !== ''
2041
+ ? err.message
2042
+ : 'unknown error';
2043
+ const errorMsg =
2044
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2045
+ throw new Error(`operation failed: ${errorMsg}`, {
2046
+ cause: err,
2047
+ });
2048
+ }
2049
+
2050
+ if (op.result?.$case !== 'response') {
2051
+ throw new Error('operation completed without a response');
2052
+ }
2053
+
2054
+ result = z.lazy(() => unmarshalProjectSchema).parse(op.result.response);
2055
+ };
2056
+
2057
+ const retryOptions: CallOptions = {
2058
+ ...(options?.signal !== undefined && {signal: options.signal}),
2059
+ retrier: () =>
2060
+ retryOn({}, (err: Error) => {
2061
+ return err.message.includes('operation still in progress');
2062
+ }),
2063
+ };
2064
+ await executeCall(call, retryOptions);
2065
+ if (result === undefined) {
2066
+ throw new Error('API call completed without a result.');
2067
+ }
2068
+ return result;
2069
+ }
2070
+
2071
+ /** Checks whether the operation has completed */
2072
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2073
+ const op = await this.client.getOperation(
2074
+ {name: this.operation.name},
2075
+ options
2076
+ );
2077
+ this.operation = op;
2078
+ return op.done;
2079
+ }
2080
+ }
2081
+
2082
+ export class CreateRoleOperation {
2083
+ constructor(
2084
+ private readonly client: Client,
2085
+ private operation: Operation
2086
+ ) {}
2087
+
2088
+ /** Returns the server-assigned name of the long-running operation. */
2089
+ name(): Promise<string | undefined> {
2090
+ return Promise.resolve(this.operation.name);
2091
+ }
2092
+
2093
+ /** Returns metadata associated with the long-running operation. */
2094
+ metadata(): Promise<RoleOperationMetadata | undefined> {
2095
+ if (this.operation.metadata === undefined) {
2096
+ return Promise.resolve(undefined);
2097
+ }
2098
+ return Promise.resolve(
2099
+ z
2100
+ .lazy(() => unmarshalRoleOperationMetadataSchema)
2101
+ .parse(this.operation.metadata)
2102
+ );
2103
+ }
2104
+
2105
+ /**
2106
+ * Polls the operation until it completes.
2107
+ *
2108
+ * Throws if the operation failed.
2109
+ */
2110
+ async wait(options?: CallOptions): Promise<Role> {
2111
+ const errStillRunning = new Error('operation still in progress');
2112
+ let result: Role | undefined;
2113
+
2114
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2115
+ const op = await this.client.getOperation(
2116
+ {
2117
+ name: this.operation.name,
2118
+ },
2119
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2120
+ );
2121
+ this.operation = op;
2122
+ if (op.done === undefined) {
2123
+ throw new Error('operation is missing the done field');
2124
+ }
2125
+ if (!op.done) {
2126
+ throw errStillRunning;
2127
+ }
2128
+
2129
+ if (op.result?.$case === 'error') {
2130
+ const err = op.result.error;
2131
+ const msg =
2132
+ err.message !== undefined && err.message !== ''
2133
+ ? err.message
2134
+ : 'unknown error';
2135
+ const errorMsg =
2136
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2137
+ throw new Error(`operation failed: ${errorMsg}`, {
2138
+ cause: err,
2139
+ });
2140
+ }
2141
+
2142
+ if (op.result?.$case !== 'response') {
2143
+ throw new Error('operation completed without a response');
2144
+ }
2145
+
2146
+ result = z.lazy(() => unmarshalRoleSchema).parse(op.result.response);
2147
+ };
2148
+
2149
+ const retryOptions: CallOptions = {
2150
+ ...(options?.signal !== undefined && {signal: options.signal}),
2151
+ retrier: () =>
2152
+ retryOn({}, (err: Error) => {
2153
+ return err.message.includes('operation still in progress');
2154
+ }),
2155
+ };
2156
+ await executeCall(call, retryOptions);
2157
+ if (result === undefined) {
2158
+ throw new Error('API call completed without a result.');
2159
+ }
2160
+ return result;
2161
+ }
2162
+
2163
+ /** Checks whether the operation has completed */
2164
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2165
+ const op = await this.client.getOperation(
2166
+ {name: this.operation.name},
2167
+ options
2168
+ );
2169
+ this.operation = op;
2170
+ return op.done;
2171
+ }
2172
+ }
2173
+
2174
+ export class CreateSyncedTableOperation {
2175
+ constructor(
2176
+ private readonly client: Client,
2177
+ private operation: Operation
2178
+ ) {}
2179
+
2180
+ /** Returns the server-assigned name of the long-running operation. */
2181
+ name(): Promise<string | undefined> {
2182
+ return Promise.resolve(this.operation.name);
2183
+ }
2184
+
2185
+ /** Returns metadata associated with the long-running operation. */
2186
+ metadata(): Promise<SyncedTableOperationMetadata | undefined> {
2187
+ if (this.operation.metadata === undefined) {
2188
+ return Promise.resolve(undefined);
2189
+ }
2190
+ return Promise.resolve(
2191
+ z
2192
+ .lazy(() => unmarshalSyncedTableOperationMetadataSchema)
2193
+ .parse(this.operation.metadata)
2194
+ );
2195
+ }
2196
+
2197
+ /**
2198
+ * Polls the operation until it completes.
2199
+ *
2200
+ * Throws if the operation failed.
2201
+ */
2202
+ async wait(options?: CallOptions): Promise<SyncedTable> {
2203
+ const errStillRunning = new Error('operation still in progress');
2204
+ let result: SyncedTable | undefined;
2205
+
2206
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2207
+ const op = await this.client.getOperation(
2208
+ {
2209
+ name: this.operation.name,
2210
+ },
2211
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2212
+ );
2213
+ this.operation = op;
2214
+ if (op.done === undefined) {
2215
+ throw new Error('operation is missing the done field');
2216
+ }
2217
+ if (!op.done) {
2218
+ throw errStillRunning;
2219
+ }
2220
+
2221
+ if (op.result?.$case === 'error') {
2222
+ const err = op.result.error;
2223
+ const msg =
2224
+ err.message !== undefined && err.message !== ''
2225
+ ? err.message
2226
+ : 'unknown error';
2227
+ const errorMsg =
2228
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2229
+ throw new Error(`operation failed: ${errorMsg}`, {
2230
+ cause: err,
2231
+ });
2232
+ }
2233
+
2234
+ if (op.result?.$case !== 'response') {
2235
+ throw new Error('operation completed without a response');
2236
+ }
2237
+
2238
+ result = z
2239
+ .lazy(() => unmarshalSyncedTableSchema)
2240
+ .parse(op.result.response);
2241
+ };
2242
+
2243
+ const retryOptions: CallOptions = {
2244
+ ...(options?.signal !== undefined && {signal: options.signal}),
2245
+ retrier: () =>
2246
+ retryOn({}, (err: Error) => {
2247
+ return err.message.includes('operation still in progress');
2248
+ }),
2249
+ };
2250
+ await executeCall(call, retryOptions);
2251
+ if (result === undefined) {
2252
+ throw new Error('API call completed without a result.');
2253
+ }
2254
+ return result;
2255
+ }
2256
+
2257
+ /** Checks whether the operation has completed */
2258
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2259
+ const op = await this.client.getOperation(
2260
+ {name: this.operation.name},
2261
+ options
2262
+ );
2263
+ this.operation = op;
2264
+ return op.done;
2265
+ }
2266
+ }
2267
+
2268
+ export class DeleteBranchOperation {
2269
+ constructor(
2270
+ private readonly client: Client,
2271
+ private operation: Operation
2272
+ ) {}
2273
+
2274
+ /** Returns the server-assigned name of the long-running operation. */
2275
+ name(): Promise<string | undefined> {
2276
+ return Promise.resolve(this.operation.name);
2277
+ }
2278
+
2279
+ /** Returns metadata associated with the long-running operation. */
2280
+ metadata(): Promise<BranchOperationMetadata | undefined> {
2281
+ if (this.operation.metadata === undefined) {
2282
+ return Promise.resolve(undefined);
2283
+ }
2284
+ return Promise.resolve(
2285
+ z
2286
+ .lazy(() => unmarshalBranchOperationMetadataSchema)
2287
+ .parse(this.operation.metadata)
2288
+ );
2289
+ }
2290
+
2291
+ /**
2292
+ * Polls the operation until it completes.
2293
+ *
2294
+ * Throws if the operation failed.
2295
+ */
2296
+ async wait(options?: CallOptions): Promise<void> {
2297
+ const errStillRunning = new Error('operation still in progress');
2298
+
2299
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2300
+ const op = await this.client.getOperation(
2301
+ {
2302
+ name: this.operation.name,
2303
+ },
2304
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2305
+ );
2306
+ this.operation = op;
2307
+ if (op.done === undefined) {
2308
+ throw new Error('operation is missing the done field');
2309
+ }
2310
+ if (!op.done) {
2311
+ throw errStillRunning;
2312
+ }
2313
+
2314
+ if (op.result?.$case === 'error') {
2315
+ const err = op.result.error;
2316
+ const msg =
2317
+ err.message !== undefined && err.message !== ''
2318
+ ? err.message
2319
+ : 'unknown error';
2320
+ const errorMsg =
2321
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2322
+ throw new Error(`operation failed: ${errorMsg}`, {
2323
+ cause: err,
2324
+ });
2325
+ }
2326
+ };
2327
+
2328
+ const retryOptions: CallOptions = {
2329
+ ...(options?.signal !== undefined && {signal: options.signal}),
2330
+ retrier: () =>
2331
+ retryOn({}, (err: Error) => {
2332
+ return err.message.includes('operation still in progress');
2333
+ }),
2334
+ };
2335
+ await executeCall(call, retryOptions);
2336
+ }
2337
+
2338
+ /** Checks whether the operation has completed */
2339
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2340
+ const op = await this.client.getOperation(
2341
+ {name: this.operation.name},
2342
+ options
2343
+ );
2344
+ this.operation = op;
2345
+ return op.done;
2346
+ }
2347
+ }
2348
+
2349
+ export class DeleteCatalogOperation {
2350
+ constructor(
2351
+ private readonly client: Client,
2352
+ private operation: Operation
2353
+ ) {}
2354
+
2355
+ /** Returns the server-assigned name of the long-running operation. */
2356
+ name(): Promise<string | undefined> {
2357
+ return Promise.resolve(this.operation.name);
2358
+ }
2359
+
2360
+ /** Returns metadata associated with the long-running operation. */
2361
+ metadata(): Promise<CatalogOperationMetadata | undefined> {
2362
+ if (this.operation.metadata === undefined) {
2363
+ return Promise.resolve(undefined);
2364
+ }
2365
+ return Promise.resolve(
2366
+ z
2367
+ .lazy(() => unmarshalCatalogOperationMetadataSchema)
2368
+ .parse(this.operation.metadata)
2369
+ );
2370
+ }
2371
+
2372
+ /**
2373
+ * Polls the operation until it completes.
2374
+ *
2375
+ * Throws if the operation failed.
2376
+ */
2377
+ async wait(options?: CallOptions): Promise<void> {
2378
+ const errStillRunning = new Error('operation still in progress');
2379
+
2380
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2381
+ const op = await this.client.getOperation(
2382
+ {
2383
+ name: this.operation.name,
2384
+ },
2385
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2386
+ );
2387
+ this.operation = op;
2388
+ if (op.done === undefined) {
2389
+ throw new Error('operation is missing the done field');
2390
+ }
2391
+ if (!op.done) {
2392
+ throw errStillRunning;
2393
+ }
2394
+
2395
+ if (op.result?.$case === 'error') {
2396
+ const err = op.result.error;
2397
+ const msg =
2398
+ err.message !== undefined && err.message !== ''
2399
+ ? err.message
2400
+ : 'unknown error';
2401
+ const errorMsg =
2402
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2403
+ throw new Error(`operation failed: ${errorMsg}`, {
2404
+ cause: err,
2405
+ });
2406
+ }
2407
+ };
2408
+
2409
+ const retryOptions: CallOptions = {
2410
+ ...(options?.signal !== undefined && {signal: options.signal}),
2411
+ retrier: () =>
2412
+ retryOn({}, (err: Error) => {
2413
+ return err.message.includes('operation still in progress');
2414
+ }),
2415
+ };
2416
+ await executeCall(call, retryOptions);
2417
+ }
2418
+
2419
+ /** Checks whether the operation has completed */
2420
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2421
+ const op = await this.client.getOperation(
2422
+ {name: this.operation.name},
2423
+ options
2424
+ );
2425
+ this.operation = op;
2426
+ return op.done;
2427
+ }
2428
+ }
2429
+
2430
+ export class DeleteDatabaseOperation {
2431
+ constructor(
2432
+ private readonly client: Client,
2433
+ private operation: Operation
2434
+ ) {}
2435
+
2436
+ /** Returns the server-assigned name of the long-running operation. */
2437
+ name(): Promise<string | undefined> {
2438
+ return Promise.resolve(this.operation.name);
2439
+ }
2440
+
2441
+ /** Returns metadata associated with the long-running operation. */
2442
+ metadata(): Promise<DatabaseOperationMetadata | undefined> {
2443
+ if (this.operation.metadata === undefined) {
2444
+ return Promise.resolve(undefined);
2445
+ }
2446
+ return Promise.resolve(
2447
+ z
2448
+ .lazy(() => unmarshalDatabaseOperationMetadataSchema)
2449
+ .parse(this.operation.metadata)
2450
+ );
2451
+ }
2452
+
2453
+ /**
2454
+ * Polls the operation until it completes.
2455
+ *
2456
+ * Throws if the operation failed.
2457
+ */
2458
+ async wait(options?: CallOptions): Promise<void> {
2459
+ const errStillRunning = new Error('operation still in progress');
2460
+
2461
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2462
+ const op = await this.client.getOperation(
2463
+ {
2464
+ name: this.operation.name,
2465
+ },
2466
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2467
+ );
2468
+ this.operation = op;
2469
+ if (op.done === undefined) {
2470
+ throw new Error('operation is missing the done field');
2471
+ }
2472
+ if (!op.done) {
2473
+ throw errStillRunning;
2474
+ }
2475
+
2476
+ if (op.result?.$case === 'error') {
2477
+ const err = op.result.error;
2478
+ const msg =
2479
+ err.message !== undefined && err.message !== ''
2480
+ ? err.message
2481
+ : 'unknown error';
2482
+ const errorMsg =
2483
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2484
+ throw new Error(`operation failed: ${errorMsg}`, {
2485
+ cause: err,
2486
+ });
2487
+ }
2488
+ };
2489
+
2490
+ const retryOptions: CallOptions = {
2491
+ ...(options?.signal !== undefined && {signal: options.signal}),
2492
+ retrier: () =>
2493
+ retryOn({}, (err: Error) => {
2494
+ return err.message.includes('operation still in progress');
2495
+ }),
2496
+ };
2497
+ await executeCall(call, retryOptions);
2498
+ }
2499
+
2500
+ /** Checks whether the operation has completed */
2501
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2502
+ const op = await this.client.getOperation(
2503
+ {name: this.operation.name},
2504
+ options
2505
+ );
2506
+ this.operation = op;
2507
+ return op.done;
2508
+ }
2509
+ }
2510
+
2511
+ export class DeleteEndpointOperation {
2512
+ constructor(
2513
+ private readonly client: Client,
2514
+ private operation: Operation
2515
+ ) {}
2516
+
2517
+ /** Returns the server-assigned name of the long-running operation. */
2518
+ name(): Promise<string | undefined> {
2519
+ return Promise.resolve(this.operation.name);
2520
+ }
2521
+
2522
+ /** Returns metadata associated with the long-running operation. */
2523
+ metadata(): Promise<EndpointOperationMetadata | undefined> {
2524
+ if (this.operation.metadata === undefined) {
2525
+ return Promise.resolve(undefined);
2526
+ }
2527
+ return Promise.resolve(
2528
+ z
2529
+ .lazy(() => unmarshalEndpointOperationMetadataSchema)
2530
+ .parse(this.operation.metadata)
2531
+ );
2532
+ }
2533
+
2534
+ /**
2535
+ * Polls the operation until it completes.
2536
+ *
2537
+ * Throws if the operation failed.
2538
+ */
2539
+ async wait(options?: CallOptions): Promise<void> {
2540
+ const errStillRunning = new Error('operation still in progress');
2541
+
2542
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2543
+ const op = await this.client.getOperation(
2544
+ {
2545
+ name: this.operation.name,
2546
+ },
2547
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2548
+ );
2549
+ this.operation = op;
2550
+ if (op.done === undefined) {
2551
+ throw new Error('operation is missing the done field');
2552
+ }
2553
+ if (!op.done) {
2554
+ throw errStillRunning;
2555
+ }
2556
+
2557
+ if (op.result?.$case === 'error') {
2558
+ const err = op.result.error;
2559
+ const msg =
2560
+ err.message !== undefined && err.message !== ''
2561
+ ? err.message
2562
+ : 'unknown error';
2563
+ const errorMsg =
2564
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2565
+ throw new Error(`operation failed: ${errorMsg}`, {
2566
+ cause: err,
2567
+ });
2568
+ }
2569
+ };
2570
+
2571
+ const retryOptions: CallOptions = {
2572
+ ...(options?.signal !== undefined && {signal: options.signal}),
2573
+ retrier: () =>
2574
+ retryOn({}, (err: Error) => {
2575
+ return err.message.includes('operation still in progress');
2576
+ }),
2577
+ };
2578
+ await executeCall(call, retryOptions);
2579
+ }
2580
+
2581
+ /** Checks whether the operation has completed */
2582
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2583
+ const op = await this.client.getOperation(
2584
+ {name: this.operation.name},
2585
+ options
2586
+ );
2587
+ this.operation = op;
2588
+ return op.done;
2589
+ }
2590
+ }
2591
+
2592
+ export class DeleteProjectOperation {
2593
+ constructor(
2594
+ private readonly client: Client,
2595
+ private operation: Operation
2596
+ ) {}
2597
+
2598
+ /** Returns the server-assigned name of the long-running operation. */
2599
+ name(): Promise<string | undefined> {
2600
+ return Promise.resolve(this.operation.name);
2601
+ }
2602
+
2603
+ /** Returns metadata associated with the long-running operation. */
2604
+ metadata(): Promise<ProjectOperationMetadata | undefined> {
2605
+ if (this.operation.metadata === undefined) {
2606
+ return Promise.resolve(undefined);
2607
+ }
2608
+ return Promise.resolve(
2609
+ z
2610
+ .lazy(() => unmarshalProjectOperationMetadataSchema)
2611
+ .parse(this.operation.metadata)
2612
+ );
2613
+ }
2614
+
2615
+ /**
2616
+ * Polls the operation until it completes.
2617
+ *
2618
+ * Throws if the operation failed.
2619
+ */
2620
+ async wait(options?: CallOptions): Promise<void> {
2621
+ const errStillRunning = new Error('operation still in progress');
2622
+
2623
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2624
+ const op = await this.client.getOperation(
2625
+ {
2626
+ name: this.operation.name,
2627
+ },
2628
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2629
+ );
2630
+ this.operation = op;
2631
+ if (op.done === undefined) {
2632
+ throw new Error('operation is missing the done field');
2633
+ }
2634
+ if (!op.done) {
2635
+ throw errStillRunning;
2636
+ }
2637
+
2638
+ if (op.result?.$case === 'error') {
2639
+ const err = op.result.error;
2640
+ const msg =
2641
+ err.message !== undefined && err.message !== ''
2642
+ ? err.message
2643
+ : 'unknown error';
2644
+ const errorMsg =
2645
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2646
+ throw new Error(`operation failed: ${errorMsg}`, {
2647
+ cause: err,
2648
+ });
2649
+ }
2650
+ };
2651
+
2652
+ const retryOptions: CallOptions = {
2653
+ ...(options?.signal !== undefined && {signal: options.signal}),
2654
+ retrier: () =>
2655
+ retryOn({}, (err: Error) => {
2656
+ return err.message.includes('operation still in progress');
2657
+ }),
2658
+ };
2659
+ await executeCall(call, retryOptions);
2660
+ }
2661
+
2662
+ /** Checks whether the operation has completed */
2663
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2664
+ const op = await this.client.getOperation(
2665
+ {name: this.operation.name},
2666
+ options
2667
+ );
2668
+ this.operation = op;
2669
+ return op.done;
2670
+ }
2671
+ }
2672
+
2673
+ export class DeleteRoleOperation {
2674
+ constructor(
2675
+ private readonly client: Client,
2676
+ private operation: Operation
2677
+ ) {}
2678
+
2679
+ /** Returns the server-assigned name of the long-running operation. */
2680
+ name(): Promise<string | undefined> {
2681
+ return Promise.resolve(this.operation.name);
2682
+ }
2683
+
2684
+ /** Returns metadata associated with the long-running operation. */
2685
+ metadata(): Promise<RoleOperationMetadata | undefined> {
2686
+ if (this.operation.metadata === undefined) {
2687
+ return Promise.resolve(undefined);
2688
+ }
2689
+ return Promise.resolve(
2690
+ z
2691
+ .lazy(() => unmarshalRoleOperationMetadataSchema)
2692
+ .parse(this.operation.metadata)
2693
+ );
2694
+ }
2695
+
2696
+ /**
2697
+ * Polls the operation until it completes.
2698
+ *
2699
+ * Throws if the operation failed.
2700
+ */
2701
+ async wait(options?: CallOptions): Promise<void> {
2702
+ const errStillRunning = new Error('operation still in progress');
2703
+
2704
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2705
+ const op = await this.client.getOperation(
2706
+ {
2707
+ name: this.operation.name,
2708
+ },
2709
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2710
+ );
2711
+ this.operation = op;
2712
+ if (op.done === undefined) {
2713
+ throw new Error('operation is missing the done field');
2714
+ }
2715
+ if (!op.done) {
2716
+ throw errStillRunning;
2717
+ }
2718
+
2719
+ if (op.result?.$case === 'error') {
2720
+ const err = op.result.error;
2721
+ const msg =
2722
+ err.message !== undefined && err.message !== ''
2723
+ ? err.message
2724
+ : 'unknown error';
2725
+ const errorMsg =
2726
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2727
+ throw new Error(`operation failed: ${errorMsg}`, {
2728
+ cause: err,
2729
+ });
2730
+ }
2731
+ };
2732
+
2733
+ const retryOptions: CallOptions = {
2734
+ ...(options?.signal !== undefined && {signal: options.signal}),
2735
+ retrier: () =>
2736
+ retryOn({}, (err: Error) => {
2737
+ return err.message.includes('operation still in progress');
2738
+ }),
2739
+ };
2740
+ await executeCall(call, retryOptions);
2741
+ }
2742
+
2743
+ /** Checks whether the operation has completed */
2744
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2745
+ const op = await this.client.getOperation(
2746
+ {name: this.operation.name},
2747
+ options
2748
+ );
2749
+ this.operation = op;
2750
+ return op.done;
2751
+ }
2752
+ }
2753
+
2754
+ export class DeleteSyncedTableOperation {
2755
+ constructor(
2756
+ private readonly client: Client,
2757
+ private operation: Operation
2758
+ ) {}
2759
+
2760
+ /** Returns the server-assigned name of the long-running operation. */
2761
+ name(): Promise<string | undefined> {
2762
+ return Promise.resolve(this.operation.name);
2763
+ }
2764
+
2765
+ /** Returns metadata associated with the long-running operation. */
2766
+ metadata(): Promise<SyncedTableOperationMetadata | undefined> {
2767
+ if (this.operation.metadata === undefined) {
2768
+ return Promise.resolve(undefined);
2769
+ }
2770
+ return Promise.resolve(
2771
+ z
2772
+ .lazy(() => unmarshalSyncedTableOperationMetadataSchema)
2773
+ .parse(this.operation.metadata)
2774
+ );
2775
+ }
2776
+
2777
+ /**
2778
+ * Polls the operation until it completes.
2779
+ *
2780
+ * Throws if the operation failed.
2781
+ */
2782
+ async wait(options?: CallOptions): Promise<void> {
2783
+ const errStillRunning = new Error('operation still in progress');
2784
+
2785
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2786
+ const op = await this.client.getOperation(
2787
+ {
2788
+ name: this.operation.name,
2789
+ },
2790
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2791
+ );
2792
+ this.operation = op;
2793
+ if (op.done === undefined) {
2794
+ throw new Error('operation is missing the done field');
2795
+ }
2796
+ if (!op.done) {
2797
+ throw errStillRunning;
2798
+ }
2799
+
2800
+ if (op.result?.$case === 'error') {
2801
+ const err = op.result.error;
2802
+ const msg =
2803
+ err.message !== undefined && err.message !== ''
2804
+ ? err.message
2805
+ : 'unknown error';
2806
+ const errorMsg =
2807
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2808
+ throw new Error(`operation failed: ${errorMsg}`, {
2809
+ cause: err,
2810
+ });
2811
+ }
2812
+ };
2813
+
2814
+ const retryOptions: CallOptions = {
2815
+ ...(options?.signal !== undefined && {signal: options.signal}),
2816
+ retrier: () =>
2817
+ retryOn({}, (err: Error) => {
2818
+ return err.message.includes('operation still in progress');
2819
+ }),
2820
+ };
2821
+ await executeCall(call, retryOptions);
2822
+ }
2823
+
2824
+ /** Checks whether the operation has completed */
2825
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2826
+ const op = await this.client.getOperation(
2827
+ {name: this.operation.name},
2828
+ options
2829
+ );
2830
+ this.operation = op;
2831
+ return op.done;
2832
+ }
2833
+ }
2834
+
2835
+ export class UndeleteBranchOperation {
2836
+ constructor(
2837
+ private readonly client: Client,
2838
+ private operation: Operation
2839
+ ) {}
2840
+
2841
+ /** Returns the server-assigned name of the long-running operation. */
2842
+ name(): Promise<string | undefined> {
2843
+ return Promise.resolve(this.operation.name);
2844
+ }
2845
+
2846
+ /** Returns metadata associated with the long-running operation. */
2847
+ metadata(): Promise<BranchOperationMetadata | undefined> {
2848
+ if (this.operation.metadata === undefined) {
2849
+ return Promise.resolve(undefined);
2850
+ }
2851
+ return Promise.resolve(
2852
+ z
2853
+ .lazy(() => unmarshalBranchOperationMetadataSchema)
2854
+ .parse(this.operation.metadata)
2855
+ );
2856
+ }
2857
+
2858
+ /**
2859
+ * Polls the operation until it completes.
2860
+ *
2861
+ * Throws if the operation failed.
2862
+ */
2863
+ async wait(options?: CallOptions): Promise<void> {
2864
+ const errStillRunning = new Error('operation still in progress');
2865
+
2866
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2867
+ const op = await this.client.getOperation(
2868
+ {
2869
+ name: this.operation.name,
2870
+ },
2871
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2872
+ );
2873
+ this.operation = op;
2874
+ if (op.done === undefined) {
2875
+ throw new Error('operation is missing the done field');
2876
+ }
2877
+ if (!op.done) {
2878
+ throw errStillRunning;
2879
+ }
2880
+
2881
+ if (op.result?.$case === 'error') {
2882
+ const err = op.result.error;
2883
+ const msg =
2884
+ err.message !== undefined && err.message !== ''
2885
+ ? err.message
2886
+ : 'unknown error';
2887
+ const errorMsg =
2888
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2889
+ throw new Error(`operation failed: ${errorMsg}`, {
2890
+ cause: err,
2891
+ });
2892
+ }
2893
+ };
2894
+
2895
+ const retryOptions: CallOptions = {
2896
+ ...(options?.signal !== undefined && {signal: options.signal}),
2897
+ retrier: () =>
2898
+ retryOn({}, (err: Error) => {
2899
+ return err.message.includes('operation still in progress');
2900
+ }),
2901
+ };
2902
+ await executeCall(call, retryOptions);
2903
+ }
2904
+
2905
+ /** Checks whether the operation has completed */
2906
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2907
+ const op = await this.client.getOperation(
2908
+ {name: this.operation.name},
2909
+ options
2910
+ );
2911
+ this.operation = op;
2912
+ return op.done;
2913
+ }
2914
+ }
2915
+
2916
+ export class UndeleteProjectOperation {
2917
+ constructor(
2918
+ private readonly client: Client,
2919
+ private operation: Operation
2920
+ ) {}
2921
+
2922
+ /** Returns the server-assigned name of the long-running operation. */
2923
+ name(): Promise<string | undefined> {
2924
+ return Promise.resolve(this.operation.name);
2925
+ }
2926
+
2927
+ /** Returns metadata associated with the long-running operation. */
2928
+ metadata(): Promise<ProjectOperationMetadata | undefined> {
2929
+ if (this.operation.metadata === undefined) {
2930
+ return Promise.resolve(undefined);
2931
+ }
2932
+ return Promise.resolve(
2933
+ z
2934
+ .lazy(() => unmarshalProjectOperationMetadataSchema)
2935
+ .parse(this.operation.metadata)
2936
+ );
2937
+ }
2938
+
2939
+ /**
2940
+ * Polls the operation until it completes.
2941
+ *
2942
+ * Throws if the operation failed.
2943
+ */
2944
+ async wait(options?: CallOptions): Promise<void> {
2945
+ const errStillRunning = new Error('operation still in progress');
2946
+
2947
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
2948
+ const op = await this.client.getOperation(
2949
+ {
2950
+ name: this.operation.name,
2951
+ },
2952
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
2953
+ );
2954
+ this.operation = op;
2955
+ if (op.done === undefined) {
2956
+ throw new Error('operation is missing the done field');
2957
+ }
2958
+ if (!op.done) {
2959
+ throw errStillRunning;
2960
+ }
2961
+
2962
+ if (op.result?.$case === 'error') {
2963
+ const err = op.result.error;
2964
+ const msg =
2965
+ err.message !== undefined && err.message !== ''
2966
+ ? err.message
2967
+ : 'unknown error';
2968
+ const errorMsg =
2969
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
2970
+ throw new Error(`operation failed: ${errorMsg}`, {
2971
+ cause: err,
2972
+ });
2973
+ }
2974
+ };
2975
+
2976
+ const retryOptions: CallOptions = {
2977
+ ...(options?.signal !== undefined && {signal: options.signal}),
2978
+ retrier: () =>
2979
+ retryOn({}, (err: Error) => {
2980
+ return err.message.includes('operation still in progress');
2981
+ }),
2982
+ };
2983
+ await executeCall(call, retryOptions);
2984
+ }
2985
+
2986
+ /** Checks whether the operation has completed */
2987
+ async done(options?: CallOptions): Promise<boolean | undefined> {
2988
+ const op = await this.client.getOperation(
2989
+ {name: this.operation.name},
2990
+ options
2991
+ );
2992
+ this.operation = op;
2993
+ return op.done;
2994
+ }
2995
+ }
2996
+
2997
+ export class UpdateBranchOperation {
2998
+ constructor(
2999
+ private readonly client: Client,
3000
+ private operation: Operation
3001
+ ) {}
3002
+
3003
+ /** Returns the server-assigned name of the long-running operation. */
3004
+ name(): Promise<string | undefined> {
3005
+ return Promise.resolve(this.operation.name);
3006
+ }
3007
+
3008
+ /** Returns metadata associated with the long-running operation. */
3009
+ metadata(): Promise<BranchOperationMetadata | undefined> {
3010
+ if (this.operation.metadata === undefined) {
3011
+ return Promise.resolve(undefined);
3012
+ }
3013
+ return Promise.resolve(
3014
+ z
3015
+ .lazy(() => unmarshalBranchOperationMetadataSchema)
3016
+ .parse(this.operation.metadata)
3017
+ );
3018
+ }
3019
+
3020
+ /**
3021
+ * Polls the operation until it completes.
3022
+ *
3023
+ * Throws if the operation failed.
3024
+ */
3025
+ async wait(options?: CallOptions): Promise<Branch> {
3026
+ const errStillRunning = new Error('operation still in progress');
3027
+ let result: Branch | undefined;
3028
+
3029
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
3030
+ const op = await this.client.getOperation(
3031
+ {
3032
+ name: this.operation.name,
3033
+ },
3034
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
3035
+ );
3036
+ this.operation = op;
3037
+ if (op.done === undefined) {
3038
+ throw new Error('operation is missing the done field');
3039
+ }
3040
+ if (!op.done) {
3041
+ throw errStillRunning;
3042
+ }
3043
+
3044
+ if (op.result?.$case === 'error') {
3045
+ const err = op.result.error;
3046
+ const msg =
3047
+ err.message !== undefined && err.message !== ''
3048
+ ? err.message
3049
+ : 'unknown error';
3050
+ const errorMsg =
3051
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
3052
+ throw new Error(`operation failed: ${errorMsg}`, {
3053
+ cause: err,
3054
+ });
3055
+ }
3056
+
3057
+ if (op.result?.$case !== 'response') {
3058
+ throw new Error('operation completed without a response');
3059
+ }
3060
+
3061
+ result = z.lazy(() => unmarshalBranchSchema).parse(op.result.response);
3062
+ };
3063
+
3064
+ const retryOptions: CallOptions = {
3065
+ ...(options?.signal !== undefined && {signal: options.signal}),
3066
+ retrier: () =>
3067
+ retryOn({}, (err: Error) => {
3068
+ return err.message.includes('operation still in progress');
3069
+ }),
3070
+ };
3071
+ await executeCall(call, retryOptions);
3072
+ if (result === undefined) {
3073
+ throw new Error('API call completed without a result.');
3074
+ }
3075
+ return result;
3076
+ }
3077
+
3078
+ /** Checks whether the operation has completed */
3079
+ async done(options?: CallOptions): Promise<boolean | undefined> {
3080
+ const op = await this.client.getOperation(
3081
+ {name: this.operation.name},
3082
+ options
3083
+ );
3084
+ this.operation = op;
3085
+ return op.done;
3086
+ }
3087
+ }
3088
+
3089
+ export class UpdateDatabaseOperation {
3090
+ constructor(
3091
+ private readonly client: Client,
3092
+ private operation: Operation
3093
+ ) {}
3094
+
3095
+ /** Returns the server-assigned name of the long-running operation. */
3096
+ name(): Promise<string | undefined> {
3097
+ return Promise.resolve(this.operation.name);
3098
+ }
3099
+
3100
+ /** Returns metadata associated with the long-running operation. */
3101
+ metadata(): Promise<DatabaseOperationMetadata | undefined> {
3102
+ if (this.operation.metadata === undefined) {
3103
+ return Promise.resolve(undefined);
3104
+ }
3105
+ return Promise.resolve(
3106
+ z
3107
+ .lazy(() => unmarshalDatabaseOperationMetadataSchema)
3108
+ .parse(this.operation.metadata)
3109
+ );
3110
+ }
3111
+
3112
+ /**
3113
+ * Polls the operation until it completes.
3114
+ *
3115
+ * Throws if the operation failed.
3116
+ */
3117
+ async wait(options?: CallOptions): Promise<Database> {
3118
+ const errStillRunning = new Error('operation still in progress');
3119
+ let result: Database | undefined;
3120
+
3121
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
3122
+ const op = await this.client.getOperation(
3123
+ {
3124
+ name: this.operation.name,
3125
+ },
3126
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
3127
+ );
3128
+ this.operation = op;
3129
+ if (op.done === undefined) {
3130
+ throw new Error('operation is missing the done field');
3131
+ }
3132
+ if (!op.done) {
3133
+ throw errStillRunning;
3134
+ }
3135
+
3136
+ if (op.result?.$case === 'error') {
3137
+ const err = op.result.error;
3138
+ const msg =
3139
+ err.message !== undefined && err.message !== ''
3140
+ ? err.message
3141
+ : 'unknown error';
3142
+ const errorMsg =
3143
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
3144
+ throw new Error(`operation failed: ${errorMsg}`, {
3145
+ cause: err,
3146
+ });
3147
+ }
3148
+
3149
+ if (op.result?.$case !== 'response') {
3150
+ throw new Error('operation completed without a response');
3151
+ }
3152
+
3153
+ result = z.lazy(() => unmarshalDatabaseSchema).parse(op.result.response);
3154
+ };
3155
+
3156
+ const retryOptions: CallOptions = {
3157
+ ...(options?.signal !== undefined && {signal: options.signal}),
3158
+ retrier: () =>
3159
+ retryOn({}, (err: Error) => {
3160
+ return err.message.includes('operation still in progress');
3161
+ }),
3162
+ };
3163
+ await executeCall(call, retryOptions);
3164
+ if (result === undefined) {
3165
+ throw new Error('API call completed without a result.');
3166
+ }
3167
+ return result;
3168
+ }
3169
+
3170
+ /** Checks whether the operation has completed */
3171
+ async done(options?: CallOptions): Promise<boolean | undefined> {
3172
+ const op = await this.client.getOperation(
3173
+ {name: this.operation.name},
3174
+ options
3175
+ );
3176
+ this.operation = op;
3177
+ return op.done;
3178
+ }
3179
+ }
3180
+
3181
+ export class UpdateEndpointOperation {
3182
+ constructor(
3183
+ private readonly client: Client,
3184
+ private operation: Operation
3185
+ ) {}
3186
+
3187
+ /** Returns the server-assigned name of the long-running operation. */
3188
+ name(): Promise<string | undefined> {
3189
+ return Promise.resolve(this.operation.name);
3190
+ }
3191
+
3192
+ /** Returns metadata associated with the long-running operation. */
3193
+ metadata(): Promise<EndpointOperationMetadata | undefined> {
3194
+ if (this.operation.metadata === undefined) {
3195
+ return Promise.resolve(undefined);
3196
+ }
3197
+ return Promise.resolve(
3198
+ z
3199
+ .lazy(() => unmarshalEndpointOperationMetadataSchema)
3200
+ .parse(this.operation.metadata)
3201
+ );
3202
+ }
3203
+
3204
+ /**
3205
+ * Polls the operation until it completes.
3206
+ *
3207
+ * Throws if the operation failed.
3208
+ */
3209
+ async wait(options?: CallOptions): Promise<Endpoint> {
3210
+ const errStillRunning = new Error('operation still in progress');
3211
+ let result: Endpoint | undefined;
3212
+
3213
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
3214
+ const op = await this.client.getOperation(
3215
+ {
3216
+ name: this.operation.name,
3217
+ },
3218
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
3219
+ );
3220
+ this.operation = op;
3221
+ if (op.done === undefined) {
3222
+ throw new Error('operation is missing the done field');
3223
+ }
3224
+ if (!op.done) {
3225
+ throw errStillRunning;
3226
+ }
3227
+
3228
+ if (op.result?.$case === 'error') {
3229
+ const err = op.result.error;
3230
+ const msg =
3231
+ err.message !== undefined && err.message !== ''
3232
+ ? err.message
3233
+ : 'unknown error';
3234
+ const errorMsg =
3235
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
3236
+ throw new Error(`operation failed: ${errorMsg}`, {
3237
+ cause: err,
3238
+ });
3239
+ }
3240
+
3241
+ if (op.result?.$case !== 'response') {
3242
+ throw new Error('operation completed without a response');
3243
+ }
3244
+
3245
+ result = z.lazy(() => unmarshalEndpointSchema).parse(op.result.response);
3246
+ };
3247
+
3248
+ const retryOptions: CallOptions = {
3249
+ ...(options?.signal !== undefined && {signal: options.signal}),
3250
+ retrier: () =>
3251
+ retryOn({}, (err: Error) => {
3252
+ return err.message.includes('operation still in progress');
3253
+ }),
3254
+ };
3255
+ await executeCall(call, retryOptions);
3256
+ if (result === undefined) {
3257
+ throw new Error('API call completed without a result.');
3258
+ }
3259
+ return result;
3260
+ }
3261
+
3262
+ /** Checks whether the operation has completed */
3263
+ async done(options?: CallOptions): Promise<boolean | undefined> {
3264
+ const op = await this.client.getOperation(
3265
+ {name: this.operation.name},
3266
+ options
3267
+ );
3268
+ this.operation = op;
3269
+ return op.done;
3270
+ }
3271
+ }
3272
+
3273
+ export class UpdateProjectOperation {
3274
+ constructor(
3275
+ private readonly client: Client,
3276
+ private operation: Operation
3277
+ ) {}
3278
+
3279
+ /** Returns the server-assigned name of the long-running operation. */
3280
+ name(): Promise<string | undefined> {
3281
+ return Promise.resolve(this.operation.name);
3282
+ }
3283
+
3284
+ /** Returns metadata associated with the long-running operation. */
3285
+ metadata(): Promise<ProjectOperationMetadata | undefined> {
3286
+ if (this.operation.metadata === undefined) {
3287
+ return Promise.resolve(undefined);
3288
+ }
3289
+ return Promise.resolve(
3290
+ z
3291
+ .lazy(() => unmarshalProjectOperationMetadataSchema)
3292
+ .parse(this.operation.metadata)
3293
+ );
3294
+ }
3295
+
3296
+ /**
3297
+ * Polls the operation until it completes.
3298
+ *
3299
+ * Throws if the operation failed.
3300
+ */
3301
+ async wait(options?: CallOptions): Promise<Project> {
3302
+ const errStillRunning = new Error('operation still in progress');
3303
+ let result: Project | undefined;
3304
+
3305
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
3306
+ const op = await this.client.getOperation(
3307
+ {
3308
+ name: this.operation.name,
3309
+ },
3310
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
3311
+ );
3312
+ this.operation = op;
3313
+ if (op.done === undefined) {
3314
+ throw new Error('operation is missing the done field');
3315
+ }
3316
+ if (!op.done) {
3317
+ throw errStillRunning;
3318
+ }
3319
+
3320
+ if (op.result?.$case === 'error') {
3321
+ const err = op.result.error;
3322
+ const msg =
3323
+ err.message !== undefined && err.message !== ''
3324
+ ? err.message
3325
+ : 'unknown error';
3326
+ const errorMsg =
3327
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
3328
+ throw new Error(`operation failed: ${errorMsg}`, {
3329
+ cause: err,
3330
+ });
3331
+ }
3332
+
3333
+ if (op.result?.$case !== 'response') {
3334
+ throw new Error('operation completed without a response');
3335
+ }
3336
+
3337
+ result = z.lazy(() => unmarshalProjectSchema).parse(op.result.response);
3338
+ };
3339
+
3340
+ const retryOptions: CallOptions = {
3341
+ ...(options?.signal !== undefined && {signal: options.signal}),
3342
+ retrier: () =>
3343
+ retryOn({}, (err: Error) => {
3344
+ return err.message.includes('operation still in progress');
3345
+ }),
3346
+ };
3347
+ await executeCall(call, retryOptions);
3348
+ if (result === undefined) {
3349
+ throw new Error('API call completed without a result.');
3350
+ }
3351
+ return result;
3352
+ }
3353
+
3354
+ /** Checks whether the operation has completed */
3355
+ async done(options?: CallOptions): Promise<boolean | undefined> {
3356
+ const op = await this.client.getOperation(
3357
+ {name: this.operation.name},
3358
+ options
3359
+ );
3360
+ this.operation = op;
3361
+ return op.done;
3362
+ }
3363
+ }
3364
+
3365
+ export class UpdateRoleOperation {
3366
+ constructor(
3367
+ private readonly client: Client,
3368
+ private operation: Operation
3369
+ ) {}
3370
+
3371
+ /** Returns the server-assigned name of the long-running operation. */
3372
+ name(): Promise<string | undefined> {
3373
+ return Promise.resolve(this.operation.name);
3374
+ }
3375
+
3376
+ /** Returns metadata associated with the long-running operation. */
3377
+ metadata(): Promise<RoleOperationMetadata | undefined> {
3378
+ if (this.operation.metadata === undefined) {
3379
+ return Promise.resolve(undefined);
3380
+ }
3381
+ return Promise.resolve(
3382
+ z
3383
+ .lazy(() => unmarshalRoleOperationMetadataSchema)
3384
+ .parse(this.operation.metadata)
3385
+ );
3386
+ }
3387
+
3388
+ /**
3389
+ * Polls the operation until it completes.
3390
+ *
3391
+ * Throws if the operation failed.
3392
+ */
3393
+ async wait(options?: CallOptions): Promise<Role> {
3394
+ const errStillRunning = new Error('operation still in progress');
3395
+ let result: Role | undefined;
3396
+
3397
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
3398
+ const op = await this.client.getOperation(
3399
+ {
3400
+ name: this.operation.name,
3401
+ },
3402
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
3403
+ );
3404
+ this.operation = op;
3405
+ if (op.done === undefined) {
3406
+ throw new Error('operation is missing the done field');
3407
+ }
3408
+ if (!op.done) {
3409
+ throw errStillRunning;
3410
+ }
3411
+
3412
+ if (op.result?.$case === 'error') {
3413
+ const err = op.result.error;
3414
+ const msg =
3415
+ err.message !== undefined && err.message !== ''
3416
+ ? err.message
3417
+ : 'unknown error';
3418
+ const errorMsg =
3419
+ err.errorCode !== undefined ? `[${err.errorCode}] ${msg}` : msg;
3420
+ throw new Error(`operation failed: ${errorMsg}`, {
3421
+ cause: err,
3422
+ });
3423
+ }
3424
+
3425
+ if (op.result?.$case !== 'response') {
3426
+ throw new Error('operation completed without a response');
3427
+ }
3428
+
3429
+ result = z.lazy(() => unmarshalRoleSchema).parse(op.result.response);
3430
+ };
3431
+
3432
+ const retryOptions: CallOptions = {
3433
+ ...(options?.signal !== undefined && {signal: options.signal}),
3434
+ retrier: () =>
3435
+ retryOn({}, (err: Error) => {
3436
+ return err.message.includes('operation still in progress');
3437
+ }),
3438
+ };
3439
+ await executeCall(call, retryOptions);
3440
+ if (result === undefined) {
3441
+ throw new Error('API call completed without a result.');
3442
+ }
3443
+ return result;
3444
+ }
3445
+
3446
+ /** Checks whether the operation has completed */
3447
+ async done(options?: CallOptions): Promise<boolean | undefined> {
3448
+ const op = await this.client.getOperation(
3449
+ {name: this.operation.name},
3450
+ options
3451
+ );
3452
+ this.operation = op;
3453
+ return op.done;
3454
+ }
3455
+ }