@databricks/sdk-postgres 0.1.0-dev.3 → 0.1.0-dev.5

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