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

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