@databricks/sdk-pipelines 0.0.0-dev → 0.1.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,671 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {VERSION as AUTH_VERSION} from '@databricks/sdk-auth';
4
+ import type {Call} from '@databricks/sdk-core/api';
5
+ import {retryOn} from '@databricks/sdk-core/api';
6
+ import {createDefault} from '@databricks/sdk-core/clientinfo';
7
+ import type {Logger} from '@databricks/sdk-core/logger';
8
+ import {NoOpLogger} from '@databricks/sdk-core/logger';
9
+ import type {CallOptions} from '@databricks/sdk-options/call';
10
+ import type {ClientOptions} from '@databricks/sdk-options/client';
11
+ import type {HttpClient} from '@databricks/sdk-core/http';
12
+ import {newHttpClient} from './transport';
13
+ import {
14
+ buildHttpRequest,
15
+ executeCall,
16
+ executeHttpCall,
17
+ marshalRequest,
18
+ parseResponse,
19
+ } from './utils';
20
+ import pkgJson from '../../package.json' with {type: 'json'};
21
+ import type {
22
+ ApplyEnvironmentRequest,
23
+ ApplyEnvironmentRequest_Response,
24
+ ClonePipelineRequest,
25
+ ClonePipelineRequest_Response,
26
+ CreatePipelineRequest,
27
+ CreatePipelineRequest_Response,
28
+ DeletePipelineRequest,
29
+ DeletePipelineRequest_Response,
30
+ EditPipelineRequest,
31
+ EditPipelineRequest_Response,
32
+ GetPipelineRequest,
33
+ GetPipelineRequest_Response,
34
+ GetUpdateRequest,
35
+ GetUpdateRequest_Response,
36
+ ListPipelineEventsRequest,
37
+ ListPipelineEventsRequest_Response,
38
+ ListPipelinesRequest,
39
+ ListPipelinesRequest_Response,
40
+ ListUpdatesRequest,
41
+ ListUpdatesRequest_Response,
42
+ PipelineEvent,
43
+ PipelineStateInfo,
44
+ StartUpdateRequest,
45
+ StartUpdateRequest_Response,
46
+ StopPipelineRequest,
47
+ StopPipelineRequest_Response,
48
+ } from './model';
49
+ import {
50
+ PipelineState_PipelineState,
51
+ marshalApplyEnvironmentRequestSchema,
52
+ marshalClonePipelineRequestSchema,
53
+ marshalCreatePipelineRequestSchema,
54
+ marshalEditPipelineRequestSchema,
55
+ marshalStartUpdateRequestSchema,
56
+ marshalStopPipelineRequestSchema,
57
+ unmarshalApplyEnvironmentRequest_ResponseSchema,
58
+ unmarshalClonePipelineRequest_ResponseSchema,
59
+ unmarshalCreatePipelineRequest_ResponseSchema,
60
+ unmarshalDeletePipelineRequest_ResponseSchema,
61
+ unmarshalEditPipelineRequest_ResponseSchema,
62
+ unmarshalGetPipelineRequest_ResponseSchema,
63
+ unmarshalGetUpdateRequest_ResponseSchema,
64
+ unmarshalListPipelineEventsRequest_ResponseSchema,
65
+ unmarshalListPipelinesRequest_ResponseSchema,
66
+ unmarshalListUpdatesRequest_ResponseSchema,
67
+ unmarshalStartUpdateRequest_ResponseSchema,
68
+ unmarshalStopPipelineRequest_ResponseSchema,
69
+ } from './model';
70
+
71
+ // Package identity segment for this client to be used in the User-Agent header.
72
+ const PACKAGE_SEGMENT = {
73
+ key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
74
+ value: pkgJson.version,
75
+ };
76
+
77
+ class StillRunningError extends Error {}
78
+
79
+ export class PipelinesClient {
80
+ private readonly host: string;
81
+ // Workspace ID used to route workspace-level calls on unified hosts (SPOG).
82
+ // When set, workspace-level methods send X-Databricks-Org-Id on every
83
+ // request.
84
+ private readonly workspaceId: string | undefined;
85
+ private readonly httpClient: HttpClient;
86
+ private readonly logger: Logger;
87
+ // User-Agent header value. Composed once at construction from
88
+ // createDefault() merged with this package's identity and the active
89
+ // credential's name.
90
+ private readonly userAgent: string;
91
+
92
+ constructor(options: ClientOptions) {
93
+ if (options.host === undefined) {
94
+ throw new Error('Host is required.');
95
+ }
96
+ this.host = options.host.replace(/\/$/, '');
97
+ this.workspaceId = options.workspaceId;
98
+ this.logger = options.logger ?? new NoOpLogger();
99
+ const info = createDefault()
100
+ .with(PACKAGE_SEGMENT)
101
+ .with({key: 'sdk-js-auth', value: AUTH_VERSION})
102
+ .with({key: 'auth', value: options.credentials?.name() ?? 'default'});
103
+ this.userAgent = info.toString();
104
+ this.httpClient = newHttpClient(options);
105
+ }
106
+
107
+ /**
108
+ * *
109
+ * Applies the current pipeline environment onto the pipeline compute. The environment applied can be used by subsequent
110
+ * dev-mode updates.
111
+ */
112
+ async applyEnvironment(
113
+ req: ApplyEnvironmentRequest,
114
+ options?: CallOptions
115
+ ): Promise<ApplyEnvironmentRequest_Response> {
116
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/environment/apply`;
117
+ const body = marshalRequest(req, marshalApplyEnvironmentRequestSchema);
118
+ let resp: ApplyEnvironmentRequest_Response | undefined;
119
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
120
+ const headers = new Headers({'Content-Type': 'application/json'});
121
+ if (this.workspaceId !== undefined) {
122
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
123
+ }
124
+ headers.set('User-Agent', this.userAgent);
125
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
126
+ const respBody = await executeHttpCall({
127
+ request: httpReq,
128
+ httpClient: this.httpClient,
129
+ logger: this.logger,
130
+ });
131
+ resp = parseResponse(
132
+ respBody,
133
+ unmarshalApplyEnvironmentRequest_ResponseSchema
134
+ );
135
+ };
136
+ await executeCall(call, options);
137
+ if (resp === undefined) {
138
+ throw new Error('API call completed without a result.');
139
+ }
140
+ return resp;
141
+ }
142
+
143
+ /**
144
+ * Creates a new pipeline using Unity Catalog from a pipeline using Hive Metastore.
145
+ * This method returns the ID of the newly created clone.
146
+ * Additionally, this method starts an update for the newly created pipeline.
147
+ */
148
+ async clone(
149
+ req: ClonePipelineRequest,
150
+ options?: CallOptions
151
+ ): Promise<ClonePipelineRequest_Response> {
152
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/clone`;
153
+ const body = marshalRequest(req, marshalClonePipelineRequestSchema);
154
+ let resp: ClonePipelineRequest_Response | undefined;
155
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
156
+ const headers = new Headers({'Content-Type': 'application/json'});
157
+ if (this.workspaceId !== undefined) {
158
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
159
+ }
160
+ headers.set('User-Agent', this.userAgent);
161
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
162
+ const respBody = await executeHttpCall({
163
+ request: httpReq,
164
+ httpClient: this.httpClient,
165
+ logger: this.logger,
166
+ });
167
+ resp = parseResponse(
168
+ respBody,
169
+ unmarshalClonePipelineRequest_ResponseSchema
170
+ );
171
+ };
172
+ await executeCall(call, options);
173
+ if (resp === undefined) {
174
+ throw new Error('API call completed without a result.');
175
+ }
176
+ return resp;
177
+ }
178
+
179
+ /**
180
+ * Creates a new data processing pipeline based on the requested configuration. If successful, this method returns
181
+ * the ID of the new pipeline.
182
+ */
183
+ async create(
184
+ req: CreatePipelineRequest,
185
+ options?: CallOptions
186
+ ): Promise<CreatePipelineRequest_Response> {
187
+ const url = `${this.host}/api/2.0/pipelines`;
188
+ const body = marshalRequest(req, marshalCreatePipelineRequestSchema);
189
+ let resp: CreatePipelineRequest_Response | undefined;
190
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
191
+ const headers = new Headers({'Content-Type': 'application/json'});
192
+ if (this.workspaceId !== undefined) {
193
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
194
+ }
195
+ headers.set('User-Agent', this.userAgent);
196
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
197
+ const respBody = await executeHttpCall({
198
+ request: httpReq,
199
+ httpClient: this.httpClient,
200
+ logger: this.logger,
201
+ });
202
+ resp = parseResponse(
203
+ respBody,
204
+ unmarshalCreatePipelineRequest_ResponseSchema
205
+ );
206
+ };
207
+ await executeCall(call, options);
208
+ if (resp === undefined) {
209
+ throw new Error('API call completed without a result.');
210
+ }
211
+ return resp;
212
+ }
213
+
214
+ /**
215
+ * Deletes a pipeline. If the pipeline publishes to Unity Catalog, pipeline deletion will cascade to
216
+ * all pipeline tables. Please reach out to <Databricks> support for assistance to undo this action.
217
+ */
218
+ async delete(
219
+ req: DeletePipelineRequest,
220
+ options?: CallOptions
221
+ ): Promise<DeletePipelineRequest_Response> {
222
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}`;
223
+ const params = new URLSearchParams();
224
+ if (req.force !== undefined) {
225
+ params.append('force', String(req.force));
226
+ }
227
+ if (req.cascade !== undefined) {
228
+ params.append('cascade', String(req.cascade));
229
+ }
230
+ const query = params.toString();
231
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
232
+ let resp: DeletePipelineRequest_Response | undefined;
233
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
234
+ const headers = new Headers();
235
+ if (this.workspaceId !== undefined) {
236
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
237
+ }
238
+ headers.set('User-Agent', this.userAgent);
239
+ const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
240
+ const respBody = await executeHttpCall({
241
+ request: httpReq,
242
+ httpClient: this.httpClient,
243
+ logger: this.logger,
244
+ });
245
+ resp = parseResponse(
246
+ respBody,
247
+ unmarshalDeletePipelineRequest_ResponseSchema
248
+ );
249
+ };
250
+ await executeCall(call, options);
251
+ if (resp === undefined) {
252
+ throw new Error('API call completed without a result.');
253
+ }
254
+ return resp;
255
+ }
256
+
257
+ /** Updates a pipeline with the supplied configuration. */
258
+ async edit(
259
+ req: EditPipelineRequest,
260
+ options?: CallOptions
261
+ ): Promise<EditPipelineRequest_Response> {
262
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}`;
263
+ const body = marshalRequest(req, marshalEditPipelineRequestSchema);
264
+ let resp: EditPipelineRequest_Response | undefined;
265
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
266
+ const headers = new Headers({'Content-Type': 'application/json'});
267
+ if (this.workspaceId !== undefined) {
268
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
269
+ }
270
+ headers.set('User-Agent', this.userAgent);
271
+ const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
272
+ const respBody = await executeHttpCall({
273
+ request: httpReq,
274
+ httpClient: this.httpClient,
275
+ logger: this.logger,
276
+ });
277
+ resp = parseResponse(
278
+ respBody,
279
+ unmarshalEditPipelineRequest_ResponseSchema
280
+ );
281
+ };
282
+ await executeCall(call, options);
283
+ if (resp === undefined) {
284
+ throw new Error('API call completed without a result.');
285
+ }
286
+ return resp;
287
+ }
288
+
289
+ /** Retrieves events for a pipeline. */
290
+ async events(
291
+ req: ListPipelineEventsRequest,
292
+ options?: CallOptions
293
+ ): Promise<ListPipelineEventsRequest_Response> {
294
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/events`;
295
+ const params = new URLSearchParams();
296
+ if (req.pageToken !== undefined) {
297
+ params.append('page_token', req.pageToken);
298
+ }
299
+ if (req.maxResults !== undefined) {
300
+ params.append('max_results', String(req.maxResults));
301
+ }
302
+ if (req.orderBy !== undefined) {
303
+ params.append('order_by', String(req.orderBy));
304
+ }
305
+ if (req.filter !== undefined) {
306
+ params.append('filter', req.filter);
307
+ }
308
+ const query = params.toString();
309
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
310
+ let resp: ListPipelineEventsRequest_Response | undefined;
311
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
312
+ const headers = new Headers();
313
+ if (this.workspaceId !== undefined) {
314
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
315
+ }
316
+ headers.set('User-Agent', this.userAgent);
317
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
318
+ const respBody = await executeHttpCall({
319
+ request: httpReq,
320
+ httpClient: this.httpClient,
321
+ logger: this.logger,
322
+ });
323
+ resp = parseResponse(
324
+ respBody,
325
+ unmarshalListPipelineEventsRequest_ResponseSchema
326
+ );
327
+ };
328
+ await executeCall(call, options);
329
+ if (resp === undefined) {
330
+ throw new Error('API call completed without a result.');
331
+ }
332
+ return resp;
333
+ }
334
+
335
+ async *eventsIter(
336
+ req: ListPipelineEventsRequest,
337
+ options?: CallOptions
338
+ ): AsyncGenerator<PipelineEvent> {
339
+ const pageReq: ListPipelineEventsRequest = {...req};
340
+ for (;;) {
341
+ const resp = await this.events(pageReq, options);
342
+ for (const item of resp.events ?? []) {
343
+ yield item;
344
+ }
345
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
346
+ return;
347
+ }
348
+ pageReq.pageToken = resp.nextPageToken;
349
+ }
350
+ }
351
+
352
+ /** Get a pipeline. */
353
+ async get(
354
+ req: GetPipelineRequest,
355
+ options?: CallOptions
356
+ ): Promise<GetPipelineRequest_Response> {
357
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}`;
358
+ let resp: GetPipelineRequest_Response | undefined;
359
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
360
+ const headers = new Headers();
361
+ if (this.workspaceId !== undefined) {
362
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
363
+ }
364
+ headers.set('User-Agent', this.userAgent);
365
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
366
+ const respBody = await executeHttpCall({
367
+ request: httpReq,
368
+ httpClient: this.httpClient,
369
+ logger: this.logger,
370
+ });
371
+ resp = parseResponse(
372
+ respBody,
373
+ unmarshalGetPipelineRequest_ResponseSchema
374
+ );
375
+ };
376
+ await executeCall(call, options);
377
+ if (resp === undefined) {
378
+ throw new Error('API call completed without a result.');
379
+ }
380
+ return resp;
381
+ }
382
+
383
+ /** Gets an update from an active pipeline. */
384
+ async getUpdate(
385
+ req: GetUpdateRequest,
386
+ options?: CallOptions
387
+ ): Promise<GetUpdateRequest_Response> {
388
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/updates/${req.updateId ?? ''}`;
389
+ let resp: GetUpdateRequest_Response | undefined;
390
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
391
+ const headers = new Headers();
392
+ if (this.workspaceId !== undefined) {
393
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
394
+ }
395
+ headers.set('User-Agent', this.userAgent);
396
+ const httpReq = buildHttpRequest('GET', url, headers, callSignal);
397
+ const respBody = await executeHttpCall({
398
+ request: httpReq,
399
+ httpClient: this.httpClient,
400
+ logger: this.logger,
401
+ });
402
+ resp = parseResponse(respBody, unmarshalGetUpdateRequest_ResponseSchema);
403
+ };
404
+ await executeCall(call, options);
405
+ if (resp === undefined) {
406
+ throw new Error('API call completed without a result.');
407
+ }
408
+ return resp;
409
+ }
410
+
411
+ /** Lists pipelines defined in the Spark Declarative Pipelines system. */
412
+ async list(
413
+ req: ListPipelinesRequest,
414
+ options?: CallOptions
415
+ ): Promise<ListPipelinesRequest_Response> {
416
+ const url = `${this.host}/api/2.0/pipelines`;
417
+ const params = new URLSearchParams();
418
+ if (req.pageToken !== undefined) {
419
+ params.append('page_token', req.pageToken);
420
+ }
421
+ if (req.maxResults !== undefined) {
422
+ params.append('max_results', String(req.maxResults));
423
+ }
424
+ if (req.orderBy !== undefined) {
425
+ params.append('order_by', String(req.orderBy));
426
+ }
427
+ if (req.filter !== undefined) {
428
+ params.append('filter', req.filter);
429
+ }
430
+ const query = params.toString();
431
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
432
+ let resp: ListPipelinesRequest_Response | undefined;
433
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
434
+ const headers = new Headers();
435
+ if (this.workspaceId !== undefined) {
436
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
437
+ }
438
+ headers.set('User-Agent', this.userAgent);
439
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
440
+ const respBody = await executeHttpCall({
441
+ request: httpReq,
442
+ httpClient: this.httpClient,
443
+ logger: this.logger,
444
+ });
445
+ resp = parseResponse(
446
+ respBody,
447
+ unmarshalListPipelinesRequest_ResponseSchema
448
+ );
449
+ };
450
+ await executeCall(call, options);
451
+ if (resp === undefined) {
452
+ throw new Error('API call completed without a result.');
453
+ }
454
+ return resp;
455
+ }
456
+
457
+ async *listIter(
458
+ req: ListPipelinesRequest,
459
+ options?: CallOptions
460
+ ): AsyncGenerator<PipelineStateInfo> {
461
+ const pageReq: ListPipelinesRequest = {...req};
462
+ for (;;) {
463
+ const resp = await this.list(pageReq, options);
464
+ for (const item of resp.statuses ?? []) {
465
+ yield item;
466
+ }
467
+ if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
468
+ return;
469
+ }
470
+ pageReq.pageToken = resp.nextPageToken;
471
+ }
472
+ }
473
+
474
+ /** List updates for an active pipeline. */
475
+ async listUpdates(
476
+ req: ListUpdatesRequest,
477
+ options?: CallOptions
478
+ ): Promise<ListUpdatesRequest_Response> {
479
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/updates`;
480
+ const params = new URLSearchParams();
481
+ if (req.pageToken !== undefined) {
482
+ params.append('page_token', req.pageToken);
483
+ }
484
+ if (req.maxResults !== undefined) {
485
+ params.append('max_results', String(req.maxResults));
486
+ }
487
+ if (req.untilUpdateId !== undefined) {
488
+ params.append('until_update_id', req.untilUpdateId);
489
+ }
490
+ const query = params.toString();
491
+ const fullUrl = query !== '' ? `${url}?${query}` : url;
492
+ let resp: ListUpdatesRequest_Response | undefined;
493
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
494
+ const headers = new Headers();
495
+ if (this.workspaceId !== undefined) {
496
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
497
+ }
498
+ headers.set('User-Agent', this.userAgent);
499
+ const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
500
+ const respBody = await executeHttpCall({
501
+ request: httpReq,
502
+ httpClient: this.httpClient,
503
+ logger: this.logger,
504
+ });
505
+ resp = parseResponse(
506
+ respBody,
507
+ unmarshalListUpdatesRequest_ResponseSchema
508
+ );
509
+ };
510
+ await executeCall(call, options);
511
+ if (resp === undefined) {
512
+ throw new Error('API call completed without a result.');
513
+ }
514
+ return resp;
515
+ }
516
+
517
+ /** Starts a new update for the pipeline. If there is already an active update for the pipeline, the request will fail and the active update will remain running. */
518
+ async start(
519
+ req: StartUpdateRequest,
520
+ options?: CallOptions
521
+ ): Promise<StartUpdateRequest_Response> {
522
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/updates`;
523
+ const body = marshalRequest(req, marshalStartUpdateRequestSchema);
524
+ let resp: StartUpdateRequest_Response | undefined;
525
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
526
+ const headers = new Headers({'Content-Type': 'application/json'});
527
+ if (this.workspaceId !== undefined) {
528
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
529
+ }
530
+ headers.set('User-Agent', this.userAgent);
531
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
532
+ const respBody = await executeHttpCall({
533
+ request: httpReq,
534
+ httpClient: this.httpClient,
535
+ logger: this.logger,
536
+ });
537
+ resp = parseResponse(
538
+ respBody,
539
+ unmarshalStartUpdateRequest_ResponseSchema
540
+ );
541
+ };
542
+ await executeCall(call, options);
543
+ if (resp === undefined) {
544
+ throw new Error('API call completed without a result.');
545
+ }
546
+ return resp;
547
+ }
548
+
549
+ /** Stops the pipeline by canceling the active update. If there is no active update for the pipeline, this request is a no-op. */
550
+ async stop(
551
+ req: StopPipelineRequest,
552
+ options?: CallOptions
553
+ ): Promise<StopPipelineRequest_Response> {
554
+ const url = `${this.host}/api/2.0/pipelines/${req.pipelineId ?? ''}/stop`;
555
+ const body = marshalRequest(req, marshalStopPipelineRequestSchema);
556
+ let resp: StopPipelineRequest_Response | undefined;
557
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
558
+ const headers = new Headers({'Content-Type': 'application/json'});
559
+ if (this.workspaceId !== undefined) {
560
+ headers.set('X-Databricks-Org-Id', this.workspaceId);
561
+ }
562
+ headers.set('User-Agent', this.userAgent);
563
+ const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
564
+ const respBody = await executeHttpCall({
565
+ request: httpReq,
566
+ httpClient: this.httpClient,
567
+ logger: this.logger,
568
+ });
569
+ resp = parseResponse(
570
+ respBody,
571
+ unmarshalStopPipelineRequest_ResponseSchema
572
+ );
573
+ };
574
+ await executeCall(call, options);
575
+ if (resp === undefined) {
576
+ throw new Error('API call completed without a result.');
577
+ }
578
+ return resp;
579
+ }
580
+
581
+ async stopWaiter(
582
+ req: StopPipelineRequest,
583
+ options?: CallOptions
584
+ ): Promise<StopWaiter> {
585
+ await this.stop(req, options);
586
+ if (req.pipelineId === undefined) {
587
+ throw new Error(
588
+ 'request field pipelineId required for polling is missing'
589
+ );
590
+ }
591
+ return new StopWaiter(this, req.pipelineId);
592
+ }
593
+ }
594
+
595
+ export class StopWaiter {
596
+ constructor(
597
+ private readonly client: PipelinesClient,
598
+ readonly pipelineId: string
599
+ ) {}
600
+
601
+ /**
602
+ * Polls until the operation reaches a terminal state.
603
+ *
604
+ * Throws if a failure state is reached.
605
+ */
606
+ async wait(options?: CallOptions): Promise<GetPipelineRequest_Response> {
607
+ let result: GetPipelineRequest_Response | undefined;
608
+
609
+ const call: Call = async (callSignal?: AbortSignal): Promise<void> => {
610
+ const pollResp = await this.client.get(
611
+ {
612
+ pipelineId: this.pipelineId,
613
+ },
614
+ {...options, ...(callSignal !== undefined && {signal: callSignal})}
615
+ );
616
+
617
+ const status = pollResp.state;
618
+ if (status === undefined) {
619
+ throw new Error('response missing required status field');
620
+ }
621
+
622
+ switch (status) {
623
+ case PipelineState_PipelineState.IDLE:
624
+ result = pollResp;
625
+ return;
626
+ case PipelineState_PipelineState.FAILED: {
627
+ const msg = pollResp.cause ?? '(no message)';
628
+ throw new Error(`terminal state ${status}: ${msg}`);
629
+ }
630
+ default:
631
+ throw new StillRunningError();
632
+ }
633
+ };
634
+
635
+ const retryOptions: CallOptions = {
636
+ ...(options?.signal !== undefined && {signal: options.signal}),
637
+ retrier: () =>
638
+ retryOn({}, (err: Error) => {
639
+ return err instanceof StillRunningError;
640
+ }),
641
+ };
642
+ await executeCall(call, retryOptions);
643
+ if (result === undefined) {
644
+ throw new Error('API call completed without a result.');
645
+ }
646
+ return result;
647
+ }
648
+
649
+ /** Checks whether the operation has reached a terminal state. */
650
+ async done(options?: CallOptions): Promise<boolean> {
651
+ const pollResp = await this.client.get(
652
+ {
653
+ pipelineId: this.pipelineId,
654
+ },
655
+ options
656
+ );
657
+
658
+ const status = pollResp.state;
659
+ if (status === undefined) {
660
+ throw new Error('response missing required status field');
661
+ }
662
+
663
+ switch (status) {
664
+ case PipelineState_PipelineState.IDLE:
665
+ case PipelineState_PipelineState.FAILED:
666
+ return true;
667
+ default:
668
+ return false;
669
+ }
670
+ }
671
+ }