Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / google-gax / build / src / longrunning.d.ts
1 /// <reference types="node" />
2 import { EventEmitter } from 'events';
3 import { APICall, APICallback, CancellablePromise, NormalApiCaller, PromiseCanceller } from './apiCallable';
4 import { BackoffSettings, CallOptions } from './gax';
5 import { GoogleError } from './GoogleError';
6 import { Metadata } from './grpc';
7 import { OperationsClient } from './operationsClient';
8 /**
9  * A callback to upack a google.protobuf.Any message.
10  * @callback anyDecoder
11  * @param {google.protobuf.Any} message - The message to unpacked.
12  * @return {Object} - The unpacked message.
13  */
14 export interface AnyDecoder {
15     (message: {}): Metadata;
16 }
17 /**
18  * @callback GetOperationCallback
19  * @param {?Error} error
20  * @param {?Object} result
21  * @param {?Object} metadata
22  * @param {?google.longrunning.Operation} rawResponse
23  */
24 export interface GetOperationCallback {
25     (err?: Error | null, result?: {}, metadata?: {}, rawResponse?: Operation): void;
26 }
27 export declare class LongrunningDescriptor {
28     operationsClient: OperationsClient;
29     responseDecoder: AnyDecoder;
30     metadataDecoder: AnyDecoder;
31     /**
32      * Describes the structure of a page-streaming call.
33      *
34      * @property {OperationsClient} operationsClient
35      * @property {anyDecoder} responseDecoder
36      * @property {anyDecoder} metadataDecoder
37      *
38      * @param {OperationsClient} operationsClient - The client used to poll or
39      *   cancel an operation.
40      * @param {anyDecoder=} responseDecoder - The decoder to unpack
41      *   the response message.
42      * @param {anyDecoder=} metadataDecoder - The decoder to unpack
43      *   the metadata message.
44      *
45      * @constructor
46      */
47     constructor(operationsClient: OperationsClient, responseDecoder: AnyDecoder, metadataDecoder: AnyDecoder);
48     apiCaller(): LongrunningApiCaller;
49 }
50 export declare class LongrunningApiCaller extends NormalApiCaller {
51     longrunningDescriptor: LongrunningDescriptor;
52     /**
53      * Creates an API caller that performs polling on a long running operation.
54      *
55      * @private
56      * @constructor
57      * @param {LongrunningDescriptor} longrunningDescriptor - Holds the
58      * decoders used for unpacking responses and the operationsClient
59      * used for polling the operation.
60      */
61     constructor(longrunningDescriptor: LongrunningDescriptor);
62     call(apiCall: APICall, argument: {}, settings: CallOptions, canceller: PromiseCanceller): void;
63     _wrapOperation(apiCall: APICall, settings: CallOptions, argument: {}, callback: APICallback): any;
64 }
65 export declare class Operation extends EventEmitter {
66     completeListeners: number;
67     hasActiveListeners: boolean;
68     latestResponse: Operation;
69     longrunningDescriptor: LongrunningDescriptor;
70     result: {} | null;
71     metadata: Metadata | null;
72     backoffSettings: BackoffSettings;
73     _callOptions?: CallOptions;
74     currentCallPromise_?: CancellablePromise;
75     name?: string;
76     done?: boolean;
77     error?: GoogleError;
78     response?: {
79         value: {};
80     };
81     /**
82      * Wrapper for a google.longrunnung.Operation.
83      *
84      * @constructor
85      *
86      * @param {google.longrunning.Operation} grpcOp - The operation to be wrapped.
87      * @param {LongrunningDescriptor} longrunningDescriptor - This defines the
88      * operations service client and unpacking mechanisms for the operation.
89      * @param {BackoffSettings} backoffSettings - The backoff settings used in
90      * in polling the operation.
91      * @param {CallOptions=} callOptions - CallOptions used in making get operation
92      * requests.
93      */
94     constructor(grpcOp: Operation, longrunningDescriptor: LongrunningDescriptor, backoffSettings: BackoffSettings, callOptions?: CallOptions);
95     /**
96      * Begin listening for events on the operation. This method keeps track of how
97      * many "complete" listeners are registered and removed, making sure polling
98      * is handled automatically.
99      *
100      * As long as there is one active "complete" listener, the connection is open.
101      * When there are no more listeners, the polling stops.
102      *
103      * @private
104      */
105     _listenForEvents(): void;
106     /**
107      * Cancels current polling api call and cancels the operation.
108      *
109      * @return {Promise} the promise of the OperationsClient#cancelOperation api
110      * request.
111      */
112     cancel(): any;
113     /**
114      * Get the updated status of the operation. If the Operation has previously
115      * completed, this will use the status of the cached completed operation.
116      *
117      *   - callback(err): Operation failed
118      *   - callback(null, result, metadata, rawResponse): Operation complete
119      *   - callback(null, null, metadata, rawResponse): Operation incomplete
120      *
121      * @param {getOperationCallback} callback - Callback to handle the polled
122      * operation result and metadata.
123      * @return {Promise|undefined} - This returns a promise if a callback is not specified.
124      * The promise resolves to an array where the first element is the unpacked
125      * result, the second element is the metadata, and the third element is the
126      * raw response of the api call. The promise rejects if the operation returns
127      * an error.
128      */
129     getOperation(): Promise<{}>;
130     getOperation(callback: GetOperationCallback): void;
131     _unpackResponse(op: Operation, callback?: GetOperationCallback): void;
132     /**
133      * Poll `getOperation` to check the operation's status. This runs a loop to
134      * ping using the backoff strategy specified at initialization.
135      *
136      * Note: This method is automatically called once a "complete" event handler
137      * is registered on the operation.
138      *
139      * @private
140      */
141     startPolling_(): void;
142     /**
143      * Wraps the `complete` and `error` events in a Promise.
144      *
145      * @return {promise} - Promise that resolves on operation completion and rejects
146      * on operation error.
147      */
148     promise(): Promise<{}>;
149 }
150 /**
151  * Method used to create Operation objects.
152  *
153  * @constructor
154  *
155  * @param {google.longrunning.Operation} op - The operation to be wrapped.
156  * @param {LongrunningDescriptor} longrunningDescriptor - This defines the
157  * operations service client and unpacking mechanisms for the operation.
158  * @param {BackoffSettings} backoffSettings - The backoff settings used in
159  * in polling the operation.
160  * @param {CallOptions=} callOptions - CallOptions used in making get operation
161  * requests.
162  */
163 export declare function operation(op: Operation, longrunningDescriptor: LongrunningDescriptor, backoffSettings: BackoffSettings, callOptions?: CallOptions): Operation;