UNPKG

16.3 kBTypeScriptView Raw
1/**
2 * Copyright 2020 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/// <reference types="node" />
17import { GoogleAuth, OAuth2Client } from 'google-auth-library';
18import { ProjectIdCallback } from 'google-auth-library/build/src/auth/googleauth';
19import { ClientOptions, Callback } from './clientInterface';
20import { ResultTuple } from './apitypes';
21import { PageDescriptor } from './descriptor';
22import * as gax from './gax';
23import { GrpcClient } from './grpc';
24import { GrpcClient as FallbackGrpcClient } from './fallback';
25import * as protos from '../protos/operations';
26import { Transform } from 'stream';
27import { CancellablePromise } from './call';
28export declare const SERVICE_ADDRESS = "longrunning.googleapis.com";
29/**
30 * The scopes needed to make gRPC calls to all of the methods defined in
31 * this service.
32 */
33export declare const ALL_SCOPES: string[];
34/**
35 * Manages long-running operations with an API service.
36 *
37 * When an API method normally takes long time to complete, it can be designed
38 * to return {@link Operation} to the client, and the client can use this
39 * interface to receive the real response asynchronously by polling the
40 * operation resource, or pass the operation resource to another API (such as
41 * Google Cloud Pub/Sub API) to receive the response. Any API service that
42 * returns long-running operations should implement the `Operations` interface
43 * so developers can have a consistent client experience.
44 *
45 * This will be created through a builder function which can be obtained by the
46 * module. See the following example of how to initialize the module and how to
47 * access to the builder.
48 * @see {@link operationsClient}
49 *
50 * @class
51 */
52export declare class OperationsClient {
53 auth?: GoogleAuth | OAuth2Client;
54 innerApiCalls: {
55 [name: string]: Function;
56 };
57 descriptor: {
58 [method: string]: PageDescriptor;
59 };
60 operationsStub: Promise<{
61 [method: string]: Function;
62 }>;
63 constructor(gaxGrpc: GrpcClient | FallbackGrpcClient, operationsProtos: any, options: ClientOptions);
64 /** Closes this operations client. */
65 close(): void;
66 /**
67 * Get the project ID used by this class.
68 * @param {function(Error, string)} callback - the callback to be called with
69 * the current project Id.
70 */
71 getProjectId(): Promise<string>;
72 getProjectId(callback: ProjectIdCallback): void;
73 getOperationInternal(request: protos.google.longrunning.GetOperationRequest, options?: gax.CallOptions, callback?: Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>): CancellablePromise<ResultTuple>;
74 /**
75 * Gets the latest state of a long-running operation. Clients can use this
76 * method to poll the operation result at intervals as recommended by the API
77 * service.
78 *
79 * @param {Object} request - The request object that will be sent.
80 * @param {string} request.name - The name of the operation resource.
81 * @param {Object=} options
82 * Optional parameters. You can override the default settings for this call,
83 * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
84 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
85 * details.
86 * @param {function(?Error, ?Object)=} callback
87 * The function which will be called with the result of the API call.
88 *
89 * The second parameter to the callback is an object representing
90 * [google.longrunning.Operation]{@link
91 * external:"google.longrunning.Operation"}.
92 * @return {Promise} - The promise which resolves to an array.
93 * The first element of the array is an object representing
94 * [google.longrunning.Operation]{@link
95 * external:"google.longrunning.Operation"}. The promise has a method named
96 * "cancel" which cancels the ongoing API call.
97 *
98 * @example
99 *
100 * const client = longrunning.operationsClient();
101 * const name = '';
102 * const [response] = await client.getOperation({name});
103 * // doThingsWith(response)
104 */
105 getOperation(request: protos.google.longrunning.GetOperationRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>): Promise<[protos.google.longrunning.Operation]>;
106 /**
107 * Lists operations that match the specified filter in the request. If the
108 * server doesn't support this method, it returns `UNIMPLEMENTED`.
109 *
110 * NOTE: the `name` binding below allows API services to override the binding
111 * to use different resource name schemes.
112 *
113 * @param {Object} request - The request object that will be sent.
114 * @param {string} request.name - The name of the operation collection.
115 * @param {string} request.filter - The standard list filter.
116 * @param {number=} request.pageSize
117 * The maximum number of resources contained in the underlying API
118 * response. If page streaming is performed per-resource, this
119 * parameter does not affect the return value. If page streaming is
120 * performed per-page, this determines the maximum number of
121 * resources in a page.
122 * @param {Object=} options
123 * Optional parameters. You can override the default settings for this call,
124 * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
125 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
126 * details.
127 * @param {function(?Error, ?Array, ?Object, ?Object)=} callback
128 * The function which will be called with the result of the API call.
129 *
130 * The second parameter to the callback is Array of
131 * [google.longrunning.Operation]{@link
132 * external:"google.longrunning.Operation"}.
133 *
134 * When autoPaginate: false is specified through options, it contains the
135 * result in a single response. If the response indicates the next page
136 * exists, the third parameter is set to be used for the next request object.
137 * The fourth parameter keeps the raw response object of an object
138 * representing [google.longrunning.ListOperationsResponse]{@link
139 * external:"google.longrunning.ListOperationsResponse"}.
140 * @return {Promise} - The promise which resolves to an array.
141 * The first element of the array is Array of
142 * [google.longrunning.Operation]{@link
143 * external:"google.longrunning.Operation"}.
144 *
145 * When autoPaginate: false is specified through options, the array has
146 * three elements. The first element is Array of
147 * [google.longrunning.Operation]{@link
148 * external:"google.longrunning.Operation"} in a single response. The second
149 * element is the next request object if the response indicates the next page
150 * exists, or null. The third element is an object representing
151 * [google.longrunning.ListOperationsResponse]{@link
152 * external:"google.longrunning.ListOperationsResponse"}.
153 *
154 * The promise has a method named "cancel" which cancels the ongoing API
155 * call.
156 *
157 * @example
158 *
159 * const client = longrunning.operationsClient();
160 * const request = {
161 * name: '',
162 * filter: ''
163 * };
164 * // Iterate over all elements.
165 * const [resources] = await client.listOperations(request);
166 * for (const resource of resources) {
167 * console.log(resources);
168 * }
169 *
170 * // Or obtain the paged response.
171 * const options = {autoPaginate: false};
172 * let nextRequest = request;
173 * while(nextRequest) {
174 * const response = await client.listOperations(nextRequest, options);
175 * const resources = response[0];
176 * nextRequest = response[1];
177 * const rawResponse = response[2];
178 * for (const resource of resources) {
179 * // doThingsWith(resource);
180 * }
181 * };
182 */
183 listOperations(request: protos.google.longrunning.ListOperationsRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.longrunning.ListOperationsResponse, protos.google.longrunning.ListOperationsRequest, {} | null | undefined>, callback?: Callback<protos.google.longrunning.ListOperationsResponse, protos.google.longrunning.ListOperationsRequest, {} | null | undefined>): Promise<protos.google.longrunning.ListOperationsResponse>;
184 /**
185 * Equivalent to {@link listOperations}, but returns a NodeJS Stream object.
186 *
187 * This fetches the paged responses for {@link listOperations} continuously
188 * and invokes the callback registered for 'data' event for each element in
189 * the responses.
190 *
191 * The returned object has 'end' method when no more elements are required.
192 *
193 * autoPaginate option will be ignored.
194 *
195 * @see {@link https://nodejs.org/api/stream.html}
196 *
197 * @param {Object} request - The request object that will be sent.
198 * @param {string} request.name - The name of the operation collection.
199 * @param {string} request.filter - The standard list filter.
200 * @param {number=} request.pageSize -
201 * The maximum number of resources contained in the underlying API
202 * response. If page streaming is performed per-resource, this
203 * parameter does not affect the return value. If page streaming is
204 * performed per-page, this determines the maximum number of
205 * resources in a page.
206 * @param {Object=} options
207 * Optional parameters. You can override the default settings for this call,
208 * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
209 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
210 * details.
211 * @return {Stream} - An object stream which emits an object representing [google.longrunning.Operation]{@link external:"google.longrunning.Operation"} on 'data' event.
212 *
213 * @example
214 *
215 * const client = longrunning.operationsClient();
216 * const request = {
217 * name: '',
218 * filter: ''
219 * };
220 * client.listOperationsStream(request)
221 * .on('data', element => {
222 * // doThingsWith(element)
223 * })
224 * .on('error', err => {
225 * console.error(err);
226 * });
227 */
228 listOperationsStream(request: protos.google.longrunning.ListOperationsRequest, options?: gax.CallOptions): Transform;
229 /**
230 * Equivalent to {@link listOperations}, but returns an iterable object.
231 *
232 * for-await-of syntax is used with the iterable to recursively get response element on-demand.
233 *
234 * @param {Object} request - The request object that will be sent.
235 * @param {string} request.name - The name of the operation collection.
236 * @param {string} request.filter - The standard list filter.
237 * @param {number=} request.pageSize -
238 * The maximum number of resources contained in the underlying API
239 * response. If page streaming is performed per-resource, this
240 * parameter does not affect the return value. If page streaming is
241 * performed per-page, this determines the maximum number of
242 * resources in a page.
243 * @param {Object=} options
244 * Optional parameters. You can override the default settings for this call,
245 * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
246 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
247 * details.
248 * @returns {Object}
249 * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
250 */
251 listOperationsAsync(request: protos.google.longrunning.ListOperationsRequest, options?: gax.CallOptions): AsyncIterable<protos.google.longrunning.ListOperationsResponse>;
252 /**
253 * Starts asynchronous cancellation on a long-running operation. The server
254 * makes a best effort to cancel the operation, but success is not
255 * guaranteed. If the server doesn't support this method, it returns
256 * `google.rpc.Code.UNIMPLEMENTED`. Clients can use
257 * {@link Operations.GetOperation} or
258 * other methods to check whether the cancellation succeeded or whether the
259 * operation completed despite cancellation. On successful cancellation,
260 * the operation is not deleted; instead, it becomes an operation with
261 * an {@link Operation.error} value with a {@link google.rpc.Status.code} of
262 * 1, corresponding to `Code.CANCELLED`.
263 *
264 * @param {Object} request - The request object that will be sent.
265 * @param {string} request.name - The name of the operation resource to be cancelled.
266 * @param {Object=} options
267 * Optional parameters. You can override the default settings for this call,
268 * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
269 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
270 * details.
271 * @param {function(?Error)=} callback
272 * The function which will be called with the result of the API call.
273 * @return {Promise} - The promise which resolves when API call finishes.
274 * The promise has a method named "cancel" which cancels the ongoing API
275 * call.
276 *
277 * @example
278 *
279 * const client = longrunning.operationsClient();
280 * await client.cancelOperation({name: ''});
281 */
282 cancelOperation(request: protos.google.longrunning.CancelOperationRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.CancelOperationRequest, {} | undefined | null>, callback?: Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>): Promise<protos.google.protobuf.Empty>;
283 /**
284 * Deletes a long-running operation. This method indicates that the client is
285 * no longer interested in the operation result. It does not cancel the
286 * operation. If the server doesn't support this method, it returns
287 * `google.rpc.Code.UNIMPLEMENTED`.
288 *
289 * @param {Object} request - The request object that will be sent.
290 * @param {string} request.name - The name of the operation resource to be deleted.
291 * @param {Object=} options
292 * Optional parameters. You can override the default settings for this call,
293 * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
294 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
295 * details.
296 * @param {function(?Error)=} callback
297 * The function which will be called with the result of the API call.
298 * @return {Promise} - The promise which resolves when API call finishes.
299 * The promise has a method named "cancel" which cancels the ongoing API
300 * call.
301 *
302 * @example
303 *
304 * const client = longrunning.operationsClient();
305 * await client.deleteOperation({name: ''});
306 */
307 deleteOperation(request: protos.google.longrunning.DeleteOperationRequest, optionsOrCallback?: gax.CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>): Promise<protos.google.protobuf.Empty>;
308}
309export declare class OperationsClientBuilder {
310 operationsClient: (opts: ClientOptions) => OperationsClient;
311 /**
312 * Builds a new Operations Client
313 * @param gaxGrpc {GrpcClient}
314 */
315 constructor(gaxGrpc: GrpcClient | FallbackGrpcClient);
316}