@databricks/sdk-pipelines 0.33.0 → 0.35.0

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/dist/v2/client.js CHANGED
@@ -1,502 +1,377 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
- import { VERSION as AUTH_VERSION } from '@databricks/sdk-auth';
3
- import { createDefault } from '@databricks/sdk-core/clientinfo';
4
- import { NoOpLogger } from '@databricks/sdk-core/logger';
5
- import { resolveClientConfig } from './transport';
6
- import { buildHttpRequest, executeCall, executeHttpCall, marshalRequest, parseResponse, flattenQueryParams, executeWait, StillRunningError, } from './utils';
7
- import pkgJson from '../../package.json' with { type: 'json' };
8
- import { PipelineState_PipelineState, marshalApplyEnvironmentRequestSchema, marshalClonePipelineRequestSchema, marshalCreatePipelineRequestSchema, marshalEditPipelineRequestSchema, marshalStartUpdateRequestSchema, marshalStopPipelineRequestSchema, unmarshalApplyEnvironmentResponseSchema, unmarshalClonePipelineResponseSchema, unmarshalCreatePipelineResponseSchema, unmarshalDeletePipelineResponseSchema, unmarshalEditPipelineResponseSchema, unmarshalGetPipelineResponseSchema, unmarshalGetUpdateResponseSchema, unmarshalListPipelineEventsResponseSchema, unmarshalListPipelinesResponseSchema, unmarshalListUpdatesResponseSchema, unmarshalStartUpdateResponseSchema, unmarshalStopPipelineResponseSchema, } from './model';
9
- // Package identity segment for this client to be used in the User-Agent header.
1
+ import { resolveClientConfig } from "./transport.js";
2
+ import { StillRunningError, buildHttpRequest, executeCall, executeHttpCall, executeWait, flattenQueryParams, marshalRequest, parseResponse } from "./utils.js";
3
+ import { name, version } from "../package.js";
4
+ import { PipelineState_PipelineState, marshalApplyEnvironmentRequestSchema, marshalClonePipelineRequestSchema, marshalCreatePipelineRequestSchema, marshalEditPipelineRequestSchema, marshalStartUpdateRequestSchema, marshalStopPipelineRequestSchema, unmarshalApplyEnvironmentResponseSchema, unmarshalClonePipelineResponseSchema, unmarshalCreatePipelineResponseSchema, unmarshalDeletePipelineResponseSchema, unmarshalEditPipelineResponseSchema, unmarshalGetPipelineResponseSchema, unmarshalGetUpdateResponseSchema, unmarshalListPipelineEventsResponseSchema, unmarshalListPipelinesResponseSchema, unmarshalListUpdatesResponseSchema, unmarshalStartUpdateResponseSchema, unmarshalStopPipelineResponseSchema } from "./model.js";
5
+ import { VERSION } from "@databricks/sdk-auth";
6
+ import { createDefault } from "@databricks/sdk-core/clientinfo";
7
+ import { NoOpLogger } from "@databricks/sdk-core/logger";
8
+
9
+ //#region src/v2/client.ts
10
10
  const PACKAGE_SEGMENT = {
11
- key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
12
- value: pkgJson.version,
11
+ key: "sdk-js-" + name.replace(/^@[^/]+\/sdk-/, ""),
12
+ value: version
13
13
  };
14
- export class PipelinesClient {
15
- options;
16
- logger;
17
- // User-Agent header value. Composed once at construction from
18
- // createDefault() merged with this package's identity and the active
19
- // credential's name.
20
- userAgent;
21
- // Memoized configuration. The profile is resolved once, lazily, on the first
22
- // request, then reused; host, workspaceId/accountId, and credentials are
23
- // filled from it when not set explicitly on the options.
24
- config;
25
- constructor(options) {
26
- this.options = options;
27
- this.logger = options.logger ?? new NoOpLogger();
28
- const info = createDefault()
29
- .with(PACKAGE_SEGMENT)
30
- .with({ key: 'sdk-js-auth', value: AUTH_VERSION })
31
- .with({ key: 'auth', value: options.credentials?.name() ?? 'default' });
32
- this.userAgent = info.toString();
33
- }
34
- resolveConfig() {
35
- this.config ??= resolveClientConfig(this.options);
36
- return this.config;
37
- }
38
- /**
39
- * *
40
- * Applies the current pipeline environment onto the pipeline compute. The environment applied can be used by subsequent
41
- * dev-mode updates.
42
- */
43
- async applyEnvironment(req, options) {
44
- const { host, workspaceId, httpClient } = await this.resolveConfig();
45
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/environment/apply`;
46
- const body = marshalRequest(req, marshalApplyEnvironmentRequestSchema);
47
- let resp;
48
- const call = async (callSignal) => {
49
- const headers = new Headers({ 'Content-Type': 'application/json' });
50
- if (workspaceId !== undefined) {
51
- headers.set('X-Databricks-Workspace-Id', workspaceId);
52
- }
53
- headers.set('User-Agent', this.userAgent);
54
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
55
- const respBody = await executeHttpCall({
56
- request: httpReq,
57
- httpClient,
58
- logger: this.logger,
59
- });
60
- resp = parseResponse(respBody, unmarshalApplyEnvironmentResponseSchema);
61
- };
62
- await executeCall(call, options);
63
- if (resp === undefined) {
64
- throw new Error('operation completed without a result.');
65
- }
66
- return resp;
67
- }
68
- /**
69
- * Creates a new pipeline using Unity Catalog from a pipeline using Hive Metastore.
70
- * This method returns the ID of the newly created clone.
71
- * Additionally, this method starts an update for the newly created pipeline.
72
- */
73
- async clone(req, options) {
74
- const { host, workspaceId, httpClient } = await this.resolveConfig();
75
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/clone`;
76
- const body = marshalRequest(req, marshalClonePipelineRequestSchema);
77
- let resp;
78
- const call = async (callSignal) => {
79
- const headers = new Headers({ 'Content-Type': 'application/json' });
80
- if (workspaceId !== undefined) {
81
- headers.set('X-Databricks-Workspace-Id', workspaceId);
82
- }
83
- headers.set('User-Agent', this.userAgent);
84
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
85
- const respBody = await executeHttpCall({
86
- request: httpReq,
87
- httpClient,
88
- logger: this.logger,
89
- });
90
- resp = parseResponse(respBody, unmarshalClonePipelineResponseSchema);
91
- };
92
- await executeCall(call, options);
93
- if (resp === undefined) {
94
- throw new Error('operation completed without a result.');
95
- }
96
- return resp;
97
- }
98
- /**
99
- * Creates a new data processing pipeline based on the requested configuration. If successful, this method returns
100
- * the ID of the new pipeline.
101
- */
102
- async create(req, options) {
103
- const { host, workspaceId, httpClient } = await this.resolveConfig();
104
- const url = `${host}/api/2.0/pipelines`;
105
- const body = marshalRequest(req, marshalCreatePipelineRequestSchema);
106
- let resp;
107
- const call = async (callSignal) => {
108
- const headers = new Headers({ 'Content-Type': 'application/json' });
109
- if (workspaceId !== undefined) {
110
- headers.set('X-Databricks-Workspace-Id', workspaceId);
111
- }
112
- headers.set('User-Agent', this.userAgent);
113
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
114
- const respBody = await executeHttpCall({
115
- request: httpReq,
116
- httpClient,
117
- logger: this.logger,
118
- });
119
- resp = parseResponse(respBody, unmarshalCreatePipelineResponseSchema);
120
- };
121
- await executeCall(call, options);
122
- if (resp === undefined) {
123
- throw new Error('operation completed without a result.');
124
- }
125
- return resp;
126
- }
127
- /**
128
- * Deletes a pipeline. If the pipeline publishes to Unity Catalog, pipeline deletion will cascade to
129
- * all pipeline tables. Please reach out to <Databricks> support for assistance to undo this action.
130
- */
131
- async delete(req, options) {
132
- const { host, workspaceId, httpClient } = await this.resolveConfig();
133
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}`;
134
- const params = new URLSearchParams();
135
- if (req.force !== undefined) {
136
- params.append('force', String(req.force));
137
- }
138
- if (req.cascade !== undefined) {
139
- params.append('cascade', String(req.cascade));
140
- }
141
- const query = params.toString();
142
- const fullUrl = query !== '' ? `${url}?${query}` : url;
143
- let resp;
144
- const call = async (callSignal) => {
145
- const headers = new Headers();
146
- if (workspaceId !== undefined) {
147
- headers.set('X-Databricks-Workspace-Id', workspaceId);
148
- }
149
- headers.set('User-Agent', this.userAgent);
150
- const httpReq = buildHttpRequest('DELETE', fullUrl, headers, callSignal);
151
- const respBody = await executeHttpCall({
152
- request: httpReq,
153
- httpClient,
154
- logger: this.logger,
155
- });
156
- resp = parseResponse(respBody, unmarshalDeletePipelineResponseSchema);
157
- };
158
- await executeCall(call, options);
159
- if (resp === undefined) {
160
- throw new Error('operation completed without a result.');
161
- }
162
- return resp;
163
- }
164
- /** Updates a pipeline with the supplied configuration. */
165
- async edit(req, options) {
166
- const { host, workspaceId, httpClient } = await this.resolveConfig();
167
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}`;
168
- const body = marshalRequest(req, marshalEditPipelineRequestSchema);
169
- let resp;
170
- const call = async (callSignal) => {
171
- const headers = new Headers({ 'Content-Type': 'application/json' });
172
- if (workspaceId !== undefined) {
173
- headers.set('X-Databricks-Workspace-Id', workspaceId);
174
- }
175
- headers.set('User-Agent', this.userAgent);
176
- const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
177
- const respBody = await executeHttpCall({
178
- request: httpReq,
179
- httpClient,
180
- logger: this.logger,
181
- });
182
- resp = parseResponse(respBody, unmarshalEditPipelineResponseSchema);
183
- };
184
- await executeCall(call, options);
185
- if (resp === undefined) {
186
- throw new Error('operation completed without a result.');
187
- }
188
- return resp;
189
- }
190
- /** Retrieves events for a pipeline. */
191
- async events(req, options) {
192
- const { host, workspaceId, httpClient } = await this.resolveConfig();
193
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/events`;
194
- const params = new URLSearchParams();
195
- if (req.pageToken !== undefined) {
196
- params.append('page_token', req.pageToken);
197
- }
198
- if (req.maxResults !== undefined) {
199
- params.append('max_results', String(req.maxResults));
200
- }
201
- if (req.orderBy !== undefined) {
202
- flattenQueryParams('order_by', req.orderBy, params);
203
- }
204
- if (req.filter !== undefined) {
205
- params.append('filter', req.filter);
206
- }
207
- const query = params.toString();
208
- const fullUrl = query !== '' ? `${url}?${query}` : url;
209
- let resp;
210
- const call = async (callSignal) => {
211
- const headers = new Headers();
212
- if (workspaceId !== undefined) {
213
- headers.set('X-Databricks-Workspace-Id', workspaceId);
214
- }
215
- headers.set('User-Agent', this.userAgent);
216
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
217
- const respBody = await executeHttpCall({
218
- request: httpReq,
219
- httpClient,
220
- logger: this.logger,
221
- });
222
- resp = parseResponse(respBody, unmarshalListPipelineEventsResponseSchema);
223
- };
224
- await executeCall(call, options);
225
- if (resp === undefined) {
226
- throw new Error('operation completed without a result.');
227
- }
228
- return resp;
229
- }
230
- async *eventsIter(req, options) {
231
- const pageReq = { ...req };
232
- for (;;) {
233
- const resp = await this.events(pageReq, options);
234
- for (const item of resp.events ?? []) {
235
- yield item;
236
- }
237
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
238
- return;
239
- }
240
- pageReq.pageToken = resp.nextPageToken;
241
- }
242
- }
243
- /** Get a pipeline. */
244
- async get(req, options) {
245
- const { host, workspaceId, httpClient } = await this.resolveConfig();
246
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}`;
247
- let resp;
248
- const call = async (callSignal) => {
249
- const headers = new Headers();
250
- if (workspaceId !== undefined) {
251
- headers.set('X-Databricks-Workspace-Id', workspaceId);
252
- }
253
- headers.set('User-Agent', this.userAgent);
254
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
255
- const respBody = await executeHttpCall({
256
- request: httpReq,
257
- httpClient,
258
- logger: this.logger,
259
- });
260
- resp = parseResponse(respBody, unmarshalGetPipelineResponseSchema);
261
- };
262
- await executeCall(call, options);
263
- if (resp === undefined) {
264
- throw new Error('operation completed without a result.');
265
- }
266
- return resp;
267
- }
268
- /** Gets an update from an active pipeline. */
269
- async getUpdate(req, options) {
270
- const { host, workspaceId, httpClient } = await this.resolveConfig();
271
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/updates/${req.updateId ?? ''}`;
272
- let resp;
273
- const call = async (callSignal) => {
274
- const headers = new Headers();
275
- if (workspaceId !== undefined) {
276
- headers.set('X-Databricks-Workspace-Id', workspaceId);
277
- }
278
- headers.set('User-Agent', this.userAgent);
279
- const httpReq = buildHttpRequest('GET', url, headers, callSignal);
280
- const respBody = await executeHttpCall({
281
- request: httpReq,
282
- httpClient,
283
- logger: this.logger,
284
- });
285
- resp = parseResponse(respBody, unmarshalGetUpdateResponseSchema);
286
- };
287
- await executeCall(call, options);
288
- if (resp === undefined) {
289
- throw new Error('operation completed without a result.');
290
- }
291
- return resp;
292
- }
293
- /** Lists pipelines defined in the Spark Declarative Pipelines system. */
294
- async list(req, options) {
295
- const { host, workspaceId, httpClient } = await this.resolveConfig();
296
- const url = `${host}/api/2.0/pipelines`;
297
- const params = new URLSearchParams();
298
- if (req.pageToken !== undefined) {
299
- params.append('page_token', req.pageToken);
300
- }
301
- if (req.maxResults !== undefined) {
302
- params.append('max_results', String(req.maxResults));
303
- }
304
- if (req.orderBy !== undefined) {
305
- flattenQueryParams('order_by', req.orderBy, params);
306
- }
307
- if (req.filter !== undefined) {
308
- params.append('filter', req.filter);
309
- }
310
- const query = params.toString();
311
- const fullUrl = query !== '' ? `${url}?${query}` : url;
312
- let resp;
313
- const call = async (callSignal) => {
314
- const headers = new Headers();
315
- if (workspaceId !== undefined) {
316
- headers.set('X-Databricks-Workspace-Id', workspaceId);
317
- }
318
- headers.set('User-Agent', this.userAgent);
319
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
320
- const respBody = await executeHttpCall({
321
- request: httpReq,
322
- httpClient,
323
- logger: this.logger,
324
- });
325
- resp = parseResponse(respBody, unmarshalListPipelinesResponseSchema);
326
- };
327
- await executeCall(call, options);
328
- if (resp === undefined) {
329
- throw new Error('operation completed without a result.');
330
- }
331
- return resp;
332
- }
333
- async *listIter(req, options) {
334
- const pageReq = { ...req };
335
- for (;;) {
336
- const resp = await this.list(pageReq, options);
337
- for (const item of resp.statuses ?? []) {
338
- yield item;
339
- }
340
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
341
- return;
342
- }
343
- pageReq.pageToken = resp.nextPageToken;
344
- }
345
- }
346
- /** List updates for an active pipeline. */
347
- async listUpdates(req, options) {
348
- const { host, workspaceId, httpClient } = await this.resolveConfig();
349
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/updates`;
350
- const params = new URLSearchParams();
351
- if (req.pageToken !== undefined) {
352
- params.append('page_token', req.pageToken);
353
- }
354
- if (req.maxResults !== undefined) {
355
- params.append('max_results', String(req.maxResults));
356
- }
357
- if (req.untilUpdateId !== undefined) {
358
- params.append('until_update_id', req.untilUpdateId);
359
- }
360
- const query = params.toString();
361
- const fullUrl = query !== '' ? `${url}?${query}` : url;
362
- let resp;
363
- const call = async (callSignal) => {
364
- const headers = new Headers();
365
- if (workspaceId !== undefined) {
366
- headers.set('X-Databricks-Workspace-Id', workspaceId);
367
- }
368
- headers.set('User-Agent', this.userAgent);
369
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
370
- const respBody = await executeHttpCall({
371
- request: httpReq,
372
- httpClient,
373
- logger: this.logger,
374
- });
375
- resp = parseResponse(respBody, unmarshalListUpdatesResponseSchema);
376
- };
377
- await executeCall(call, options);
378
- if (resp === undefined) {
379
- throw new Error('operation completed without a result.');
380
- }
381
- return resp;
382
- }
383
- /** 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. */
384
- async start(req, options) {
385
- const { host, workspaceId, httpClient } = await this.resolveConfig();
386
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/updates`;
387
- const body = marshalRequest(req, marshalStartUpdateRequestSchema);
388
- let resp;
389
- const call = async (callSignal) => {
390
- const headers = new Headers({ 'Content-Type': 'application/json' });
391
- if (workspaceId !== undefined) {
392
- headers.set('X-Databricks-Workspace-Id', workspaceId);
393
- }
394
- headers.set('User-Agent', this.userAgent);
395
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
396
- const respBody = await executeHttpCall({
397
- request: httpReq,
398
- httpClient,
399
- logger: this.logger,
400
- });
401
- resp = parseResponse(respBody, unmarshalStartUpdateResponseSchema);
402
- };
403
- await executeCall(call, options);
404
- if (resp === undefined) {
405
- throw new Error('operation completed without a result.');
406
- }
407
- return resp;
408
- }
409
- /** Stops the pipeline by canceling the active update. If there is no active update for the pipeline, this request is a no-op. */
410
- async stopBase(req, options) {
411
- const { host, workspaceId, httpClient } = await this.resolveConfig();
412
- const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ''}/stop`;
413
- const body = marshalRequest(req, marshalStopPipelineRequestSchema);
414
- let resp;
415
- const call = async (callSignal) => {
416
- const headers = new Headers({ 'Content-Type': 'application/json' });
417
- if (workspaceId !== undefined) {
418
- headers.set('X-Databricks-Workspace-Id', workspaceId);
419
- }
420
- headers.set('User-Agent', this.userAgent);
421
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
422
- const respBody = await executeHttpCall({
423
- request: httpReq,
424
- httpClient,
425
- logger: this.logger,
426
- });
427
- resp = parseResponse(respBody, unmarshalStopPipelineResponseSchema);
428
- };
429
- await executeCall(call, options);
430
- if (resp === undefined) {
431
- throw new Error('operation completed without a result.');
432
- }
433
- return resp;
434
- }
435
- /** Stops the pipeline by canceling the active update. If there is no active update for the pipeline, this request is a no-op. */
436
- async stop(req, options) {
437
- await this.stopBase(req, options);
438
- if (req.pipelineId === undefined) {
439
- throw new Error('request field pipelineId required for polling is missing');
440
- }
441
- return new StopWaiter(this, req.pipelineId);
442
- }
443
- }
444
- export class StopWaiter {
445
- client;
446
- pipelineId;
447
- constructor(client, pipelineId) {
448
- this.client = client;
449
- this.pipelineId = pipelineId;
450
- }
451
- /**
452
- * Polls until the operation reaches a terminal state.
453
- *
454
- * Throws if a failure state is reached.
455
- */
456
- async wait(options) {
457
- let result;
458
- const call = async (callSignal) => {
459
- const pollResp = await this.client.get({
460
- pipelineId: this.pipelineId,
461
- }, callSignal !== undefined ? { signal: callSignal } : undefined);
462
- const status = pollResp.state;
463
- if (status === undefined) {
464
- throw new Error('response missing required status field');
465
- }
466
- switch (status) {
467
- case PipelineState_PipelineState.IDLE:
468
- result = pollResp;
469
- return;
470
- case PipelineState_PipelineState.FAILED: {
471
- const msg = pollResp.cause ?? '(no message)';
472
- throw new Error(`terminal state ${status}: ${msg}`);
473
- }
474
- default:
475
- throw new StillRunningError();
476
- }
477
- };
478
- await executeWait(call, options);
479
- if (result === undefined) {
480
- throw new Error('operation completed without a result.');
481
- }
482
- return result;
483
- }
484
- /** Checks whether the operation has reached a terminal state. */
485
- async done(options) {
486
- const pollResp = await this.client.get({
487
- pipelineId: this.pipelineId,
488
- }, options);
489
- const status = pollResp.state;
490
- if (status === undefined) {
491
- throw new Error('response missing required status field');
492
- }
493
- switch (status) {
494
- case PipelineState_PipelineState.IDLE:
495
- case PipelineState_PipelineState.FAILED:
496
- return true;
497
- default:
498
- return false;
499
- }
500
- }
501
- }
14
+ var PipelinesClient = class {
15
+ options;
16
+ logger;
17
+ userAgent;
18
+ config;
19
+ constructor(options) {
20
+ this.options = options;
21
+ this.logger = options.logger ?? new NoOpLogger();
22
+ this.userAgent = createDefault().with(PACKAGE_SEGMENT).with({
23
+ key: "sdk-js-auth",
24
+ value: VERSION
25
+ }).with({
26
+ key: "auth",
27
+ value: options.credentials?.name() ?? "default"
28
+ }).toString();
29
+ }
30
+ resolveConfig() {
31
+ this.config ??= resolveClientConfig(this.options);
32
+ return this.config;
33
+ }
34
+ /**
35
+ * *
36
+ * Applies the current pipeline environment onto the pipeline compute. The environment applied can be used by subsequent
37
+ * dev-mode updates.
38
+ */
39
+ async applyEnvironment(req, options) {
40
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
41
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/environment/apply`;
42
+ const body = marshalRequest(req, marshalApplyEnvironmentRequestSchema);
43
+ let resp;
44
+ const call = async (callSignal) => {
45
+ const headers = new Headers({ "Content-Type": "application/json" });
46
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
47
+ headers.set("User-Agent", this.userAgent);
48
+ resp = parseResponse(await executeHttpCall({
49
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
50
+ httpClient,
51
+ logger: this.logger
52
+ }), unmarshalApplyEnvironmentResponseSchema);
53
+ };
54
+ await executeCall(call, options);
55
+ if (resp === void 0) throw new Error("operation completed without a result.");
56
+ return resp;
57
+ }
58
+ /**
59
+ * Creates a new pipeline using Unity Catalog from a pipeline using Hive Metastore.
60
+ * This method returns the ID of the newly created clone.
61
+ * Additionally, this method starts an update for the newly created pipeline.
62
+ */
63
+ async clone(req, options) {
64
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
65
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/clone`;
66
+ const body = marshalRequest(req, marshalClonePipelineRequestSchema);
67
+ let resp;
68
+ const call = async (callSignal) => {
69
+ const headers = new Headers({ "Content-Type": "application/json" });
70
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
71
+ headers.set("User-Agent", this.userAgent);
72
+ resp = parseResponse(await executeHttpCall({
73
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
74
+ httpClient,
75
+ logger: this.logger
76
+ }), unmarshalClonePipelineResponseSchema);
77
+ };
78
+ await executeCall(call, options);
79
+ if (resp === void 0) throw new Error("operation completed without a result.");
80
+ return resp;
81
+ }
82
+ /**
83
+ * Creates a new data processing pipeline based on the requested configuration. If successful, this method returns
84
+ * the ID of the new pipeline.
85
+ */
86
+ async create(req, options) {
87
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
88
+ const url = `${host}/api/2.0/pipelines`;
89
+ const body = marshalRequest(req, marshalCreatePipelineRequestSchema);
90
+ let resp;
91
+ const call = async (callSignal) => {
92
+ const headers = new Headers({ "Content-Type": "application/json" });
93
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
94
+ headers.set("User-Agent", this.userAgent);
95
+ resp = parseResponse(await executeHttpCall({
96
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
97
+ httpClient,
98
+ logger: this.logger
99
+ }), unmarshalCreatePipelineResponseSchema);
100
+ };
101
+ await executeCall(call, options);
102
+ if (resp === void 0) throw new Error("operation completed without a result.");
103
+ return resp;
104
+ }
105
+ /**
106
+ * Deletes a pipeline. If the pipeline publishes to Unity Catalog, pipeline deletion will cascade to
107
+ * all pipeline tables. Please reach out to <Databricks> support for assistance to undo this action.
108
+ */
109
+ async delete(req, options) {
110
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
111
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}`;
112
+ const params = new URLSearchParams();
113
+ if (req.force !== void 0) params.append("force", String(req.force));
114
+ if (req.cascade !== void 0) params.append("cascade", String(req.cascade));
115
+ const query = params.toString();
116
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
117
+ let resp;
118
+ const call = async (callSignal) => {
119
+ const headers = new Headers();
120
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
121
+ headers.set("User-Agent", this.userAgent);
122
+ resp = parseResponse(await executeHttpCall({
123
+ request: buildHttpRequest("DELETE", fullUrl, headers, callSignal),
124
+ httpClient,
125
+ logger: this.logger
126
+ }), unmarshalDeletePipelineResponseSchema);
127
+ };
128
+ await executeCall(call, options);
129
+ if (resp === void 0) throw new Error("operation completed without a result.");
130
+ return resp;
131
+ }
132
+ /** Updates a pipeline with the supplied configuration. */
133
+ async edit(req, options) {
134
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
135
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}`;
136
+ const body = marshalRequest(req, marshalEditPipelineRequestSchema);
137
+ let resp;
138
+ const call = async (callSignal) => {
139
+ const headers = new Headers({ "Content-Type": "application/json" });
140
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
141
+ headers.set("User-Agent", this.userAgent);
142
+ resp = parseResponse(await executeHttpCall({
143
+ request: buildHttpRequest("PUT", url, headers, callSignal, body),
144
+ httpClient,
145
+ logger: this.logger
146
+ }), unmarshalEditPipelineResponseSchema);
147
+ };
148
+ await executeCall(call, options);
149
+ if (resp === void 0) throw new Error("operation completed without a result.");
150
+ return resp;
151
+ }
152
+ /** Retrieves events for a pipeline. */
153
+ async events(req, options) {
154
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
155
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/events`;
156
+ const params = new URLSearchParams();
157
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
158
+ if (req.maxResults !== void 0) params.append("max_results", String(req.maxResults));
159
+ if (req.orderBy !== void 0) flattenQueryParams("order_by", req.orderBy, params);
160
+ if (req.filter !== void 0) params.append("filter", req.filter);
161
+ const query = params.toString();
162
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
163
+ let resp;
164
+ const call = async (callSignal) => {
165
+ const headers = new Headers();
166
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
167
+ headers.set("User-Agent", this.userAgent);
168
+ resp = parseResponse(await executeHttpCall({
169
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
170
+ httpClient,
171
+ logger: this.logger
172
+ }), unmarshalListPipelineEventsResponseSchema);
173
+ };
174
+ await executeCall(call, options);
175
+ if (resp === void 0) throw new Error("operation completed without a result.");
176
+ return resp;
177
+ }
178
+ async *eventsIter(req, options) {
179
+ const pageReq = { ...req };
180
+ for (;;) {
181
+ const resp = await this.events(pageReq, options);
182
+ for (const item of resp.events ?? []) yield item;
183
+ if (resp.nextPageToken === void 0 || resp.nextPageToken === "") return;
184
+ pageReq.pageToken = resp.nextPageToken;
185
+ }
186
+ }
187
+ /** Get a pipeline. */
188
+ async get(req, options) {
189
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
190
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}`;
191
+ let resp;
192
+ const call = async (callSignal) => {
193
+ const headers = new Headers();
194
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
195
+ headers.set("User-Agent", this.userAgent);
196
+ resp = parseResponse(await executeHttpCall({
197
+ request: buildHttpRequest("GET", url, headers, callSignal),
198
+ httpClient,
199
+ logger: this.logger
200
+ }), unmarshalGetPipelineResponseSchema);
201
+ };
202
+ await executeCall(call, options);
203
+ if (resp === void 0) throw new Error("operation completed without a result.");
204
+ return resp;
205
+ }
206
+ /** Gets an update from an active pipeline. */
207
+ async getUpdate(req, options) {
208
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
209
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/updates/${req.updateId ?? ""}`;
210
+ let resp;
211
+ const call = async (callSignal) => {
212
+ const headers = new Headers();
213
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
214
+ headers.set("User-Agent", this.userAgent);
215
+ resp = parseResponse(await executeHttpCall({
216
+ request: buildHttpRequest("GET", url, headers, callSignal),
217
+ httpClient,
218
+ logger: this.logger
219
+ }), unmarshalGetUpdateResponseSchema);
220
+ };
221
+ await executeCall(call, options);
222
+ if (resp === void 0) throw new Error("operation completed without a result.");
223
+ return resp;
224
+ }
225
+ /** Lists pipelines defined in the Spark Declarative Pipelines system. */
226
+ async list(req, options) {
227
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
228
+ const url = `${host}/api/2.0/pipelines`;
229
+ const params = new URLSearchParams();
230
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
231
+ if (req.maxResults !== void 0) params.append("max_results", String(req.maxResults));
232
+ if (req.orderBy !== void 0) flattenQueryParams("order_by", req.orderBy, params);
233
+ if (req.filter !== void 0) params.append("filter", req.filter);
234
+ const query = params.toString();
235
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
236
+ let resp;
237
+ const call = async (callSignal) => {
238
+ const headers = new Headers();
239
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
240
+ headers.set("User-Agent", this.userAgent);
241
+ resp = parseResponse(await executeHttpCall({
242
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
243
+ httpClient,
244
+ logger: this.logger
245
+ }), unmarshalListPipelinesResponseSchema);
246
+ };
247
+ await executeCall(call, options);
248
+ if (resp === void 0) throw new Error("operation completed without a result.");
249
+ return resp;
250
+ }
251
+ async *listIter(req, options) {
252
+ const pageReq = { ...req };
253
+ for (;;) {
254
+ const resp = await this.list(pageReq, options);
255
+ for (const item of resp.statuses ?? []) yield item;
256
+ if (resp.nextPageToken === void 0 || resp.nextPageToken === "") return;
257
+ pageReq.pageToken = resp.nextPageToken;
258
+ }
259
+ }
260
+ /** List updates for an active pipeline. */
261
+ async listUpdates(req, options) {
262
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
263
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/updates`;
264
+ const params = new URLSearchParams();
265
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
266
+ if (req.maxResults !== void 0) params.append("max_results", String(req.maxResults));
267
+ if (req.untilUpdateId !== void 0) params.append("until_update_id", req.untilUpdateId);
268
+ const query = params.toString();
269
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
270
+ let resp;
271
+ const call = async (callSignal) => {
272
+ const headers = new Headers();
273
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
274
+ headers.set("User-Agent", this.userAgent);
275
+ resp = parseResponse(await executeHttpCall({
276
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
277
+ httpClient,
278
+ logger: this.logger
279
+ }), unmarshalListUpdatesResponseSchema);
280
+ };
281
+ await executeCall(call, options);
282
+ if (resp === void 0) throw new Error("operation completed without a result.");
283
+ return resp;
284
+ }
285
+ /** 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. */
286
+ async start(req, options) {
287
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
288
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/updates`;
289
+ const body = marshalRequest(req, marshalStartUpdateRequestSchema);
290
+ let resp;
291
+ const call = async (callSignal) => {
292
+ const headers = new Headers({ "Content-Type": "application/json" });
293
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
294
+ headers.set("User-Agent", this.userAgent);
295
+ resp = parseResponse(await executeHttpCall({
296
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
297
+ httpClient,
298
+ logger: this.logger
299
+ }), unmarshalStartUpdateResponseSchema);
300
+ };
301
+ await executeCall(call, options);
302
+ if (resp === void 0) throw new Error("operation completed without a result.");
303
+ return resp;
304
+ }
305
+ /** Stops the pipeline by canceling the active update. If there is no active update for the pipeline, this request is a no-op. */
306
+ async stopBase(req, options) {
307
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
308
+ const url = `${host}/api/2.0/pipelines/${req.pipelineId ?? ""}/stop`;
309
+ const body = marshalRequest(req, marshalStopPipelineRequestSchema);
310
+ let resp;
311
+ const call = async (callSignal) => {
312
+ const headers = new Headers({ "Content-Type": "application/json" });
313
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
314
+ headers.set("User-Agent", this.userAgent);
315
+ resp = parseResponse(await executeHttpCall({
316
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
317
+ httpClient,
318
+ logger: this.logger
319
+ }), unmarshalStopPipelineResponseSchema);
320
+ };
321
+ await executeCall(call, options);
322
+ if (resp === void 0) throw new Error("operation completed without a result.");
323
+ return resp;
324
+ }
325
+ /** Stops the pipeline by canceling the active update. If there is no active update for the pipeline, this request is a no-op. */
326
+ async stop(req, options) {
327
+ await this.stopBase(req, options);
328
+ if (req.pipelineId === void 0) throw new Error("request field pipelineId required for polling is missing");
329
+ return new StopWaiter(this, req.pipelineId);
330
+ }
331
+ };
332
+ var StopWaiter = class {
333
+ constructor(client, pipelineId) {
334
+ this.client = client;
335
+ this.pipelineId = pipelineId;
336
+ }
337
+ /**
338
+ * Polls until the operation reaches a terminal state.
339
+ *
340
+ * Throws if a failure state is reached.
341
+ */
342
+ async wait(options) {
343
+ let result;
344
+ const call = async (callSignal) => {
345
+ const pollResp = await this.client.get({ pipelineId: this.pipelineId }, callSignal !== void 0 ? { signal: callSignal } : void 0);
346
+ const status = pollResp.state;
347
+ if (status === void 0) throw new Error("response missing required status field");
348
+ switch (status) {
349
+ case PipelineState_PipelineState.IDLE:
350
+ result = pollResp;
351
+ return;
352
+ case PipelineState_PipelineState.FAILED: {
353
+ const msg = pollResp.cause ?? "(no message)";
354
+ throw new Error(`terminal state ${status}: ${msg}`);
355
+ }
356
+ default: throw new StillRunningError();
357
+ }
358
+ };
359
+ await executeWait(call, options);
360
+ if (result === void 0) throw new Error("operation completed without a result.");
361
+ return result;
362
+ }
363
+ /** Checks whether the operation has reached a terminal state. */
364
+ async done(options) {
365
+ const status = (await this.client.get({ pipelineId: this.pipelineId }, options)).state;
366
+ if (status === void 0) throw new Error("response missing required status field");
367
+ switch (status) {
368
+ case PipelineState_PipelineState.IDLE:
369
+ case PipelineState_PipelineState.FAILED: return true;
370
+ default: return false;
371
+ }
372
+ }
373
+ };
374
+
375
+ //#endregion
376
+ export { PipelinesClient, StopWaiter };
502
377
  //# sourceMappingURL=client.js.map