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 | /**
|
17 | * Google API Extensions
|
18 | */
|
19 | import { BundleOptions } from './bundlingCalls/bundleExecutor';
|
20 | /**
|
21 | * Encapsulates the overridable settings for a particular API call.
|
22 | *
|
23 | * ``CallOptions`` is an optional arg for all GAX API calls. It is used to
|
24 | * configure the settings of a specific API call.
|
25 | *
|
26 | * When provided, its values override the GAX service defaults for that
|
27 | * particular call.
|
28 | *
|
29 | * Typically the API clients will accept this as the second to the last
|
30 | * argument. See the examples below.
|
31 | * @typedef {Object} CallOptions
|
32 | * @property {number=} timeout - The client-side timeout for API calls.
|
33 | * @property {RetryOptions=} retry - determines whether and how to retry
|
34 | * on transient errors. When set to null, the call will not retry.
|
35 | * @property {boolean=} autoPaginate - If set to false and the call is
|
36 | * configured for paged iteration, page unrolling is not performed, instead
|
37 | * the callback will be called with the response object.
|
38 | * @property {Object=} pageToken - If set and the call is configured for
|
39 | * paged iteration, paged iteration is not performed and requested with this
|
40 | * pageToken.
|
41 | * @property {number} maxResults - If set and the call is configured for
|
42 | * paged iteration, the call will stop when the number of response elements
|
43 | * reaches to the specified size. By default, it will unroll the page to
|
44 | * the end of the list.
|
45 | * @property {boolean=} isBundling - If set to false and the call is configured
|
46 | * for bundling, bundling is not performed.
|
47 | * @property {BackoffSettings=} longrunning - BackoffSettings used for polling.
|
48 | * @example
|
49 | * // suppress bundling for bundled method.
|
50 | * api.bundlingMethod(
|
51 | * param, {optParam: aValue, isBundling: false}, function(err, response) {
|
52 | * // handle response.
|
53 | * });
|
54 | * @example
|
55 | * // suppress streaming for page-streaming method.
|
56 | * api.pageStreamingMethod(
|
57 | * param, {optParam: aValue, autoPaginate: false}, function(err, page) {
|
58 | * // not returning a stream, but callback is called with the paged response.
|
59 | * });
|
60 | */
|
61 | /**
|
62 | * Per-call configurable settings for retrying upon transient failure.
|
63 | * @typedef {Object} RetryOptions
|
64 | * @property {String[]} retryCodes
|
65 | * @property {BackoffSettings} backoffSettings
|
66 | */
|
67 | export declare class RetryOptions {
|
68 | retryCodes: number[];
|
69 | backoffSettings: BackoffSettings;
|
70 | constructor(retryCodes: number[], backoffSettings: BackoffSettings);
|
71 | }
|
72 | export interface RetryRequestOptions {
|
73 | objectMode?: boolean;
|
74 | request?: any;
|
75 | retries?: number;
|
76 | noResponseRetries?: number;
|
77 | currentRetryAttempt?: number;
|
78 | shouldRetryFn?: () => boolean;
|
79 | }
|
80 | /**
|
81 | * Parameters to the exponential backoff algorithm for retrying.
|
82 | * @typedef {Object} BackoffSettings
|
83 | * @property {number} initialRetryDelayMillis - the initial delay time,
|
84 | * in milliseconds, between the completion of the first failed request and the
|
85 | * initiation of the first retrying request.
|
86 | * @property {number} retryDelayMultiplier - the multiplier by which to
|
87 | * increase the delay time between the completion of failed requests, and the
|
88 | * initiation of the subsequent retrying request.
|
89 | * @property {number} maxRetryDelayMillis - the maximum delay time, in
|
90 | * milliseconds, between requests. When this value is reached,
|
91 | * ``retryDelayMultiplier`` will no longer be used to increase delay time.
|
92 | * @property {number} initialRpcTimeoutMillis - the initial timeout parameter
|
93 | * to the request.
|
94 | * @propetry {number} rpcTimeoutMultiplier - the multiplier by which to
|
95 | * increase the timeout parameter between failed requests.
|
96 | * @property {number} maxRpcTimeoutMillis - the maximum timeout parameter, in
|
97 | * milliseconds, for a request. When this value is reached,
|
98 | * ``rpcTimeoutMultiplier`` will no longer be used to increase the timeout.
|
99 | * @property {number} totalTimeoutMillis - the total time, in milliseconds,
|
100 | * starting from when the initial request is sent, after which an error will
|
101 | * be returned, regardless of the retrying attempts made meanwhile.
|
102 | */
|
103 | export interface BackoffSettings {
|
104 | maxRetries?: number;
|
105 | initialRetryDelayMillis: number;
|
106 | retryDelayMultiplier: number;
|
107 | maxRetryDelayMillis: number;
|
108 | initialRpcTimeoutMillis?: number | null;
|
109 | maxRpcTimeoutMillis?: number | null;
|
110 | totalTimeoutMillis?: number | null;
|
111 | rpcTimeoutMultiplier?: number | null;
|
112 | }
|
113 | export interface CallOptions {
|
114 | timeout?: number;
|
115 | retry?: Partial<RetryOptions> | null;
|
116 | autoPaginate?: boolean;
|
117 | pageToken?: string;
|
118 | pageSize?: number;
|
119 | maxResults?: number;
|
120 | maxRetries?: number;
|
121 | otherArgs?: {
|
122 | [index: string]: any;
|
123 | };
|
124 | bundleOptions?: BundleOptions | null;
|
125 | isBundling?: boolean;
|
126 | longrunning?: BackoffSettings;
|
127 | apiName?: string;
|
128 | retryRequestOptions?: RetryRequestOptions;
|
129 | }
|
130 | export declare class CallSettings {
|
131 | timeout: number;
|
132 | retry?: RetryOptions | null;
|
133 | autoPaginate?: boolean;
|
134 | pageToken?: string;
|
135 | pageSize?: number;
|
136 | maxResults?: number;
|
137 | otherArgs: {
|
138 | [index: string]: any;
|
139 | };
|
140 | bundleOptions?: BundleOptions | null;
|
141 | isBundling: boolean;
|
142 | longrunning?: BackoffSettings;
|
143 | apiName?: string;
|
144 | retryRequestOptions?: RetryRequestOptions;
|
145 | /**
|
146 | * @param {Object} settings - An object containing parameters of this settings.
|
147 | * @param {number} settings.timeout - The client-side timeout for API calls.
|
148 | * This parameter is ignored for retrying calls.
|
149 | * @param {RetryOptions} settings.retry - The configuration for retrying upon
|
150 | * transient error. If set to null, this call will not retry.
|
151 | * @param {boolean} settings.autoPaginate - If there is no `pageDescriptor`,
|
152 | * this attrbute has no meaning. Otherwise, determines whether a page
|
153 | * streamed response should make the page structure transparent to the user by
|
154 | * flattening the repeated field in the returned generator.
|
155 | * @param {number} settings.pageToken - If there is no `pageDescriptor`,
|
156 | * this attribute has no meaning. Otherwise, determines the page token used
|
157 | * in the page streaming request.
|
158 | * @param {Object} settings.otherArgs - Additional arguments to be passed to
|
159 | * the API calls.
|
160 | *
|
161 | * @constructor
|
162 | */
|
163 | constructor(settings?: CallOptions);
|
164 | /**
|
165 | * Returns a new CallSettings merged from this and a CallOptions object.
|
166 | *
|
167 | * @param {CallOptions} options - an instance whose values override
|
168 | * those in this object. If null, ``merge`` returns a copy of this
|
169 | * object
|
170 | * {CallSettings} The merged CallSettings instance.
|
171 | */
|
172 | merge(options?: CallOptions | null): CallSettings;
|
173 | }
|
174 | /**
|
175 | * Per-call configurable settings for retrying upon transient failure.
|
176 | *
|
177 | * @param {number[]} retryCodes - a list of Google API canonical error codes
|
178 | * upon which a retry should be attempted.
|
179 | * @param {BackoffSettings} backoffSettings - configures the retry
|
180 | * exponential backoff algorithm.
|
181 | * @return {RetryOptions} A new RetryOptions object.
|
182 | *
|
183 | */
|
184 | export declare function createRetryOptions(retryCodes: number[], backoffSettings: BackoffSettings): RetryOptions;
|
185 | /**
|
186 | * Parameters to the exponential backoff algorithm for retrying.
|
187 | *
|
188 | * @param {number} initialRetryDelayMillis - the initial delay time,
|
189 | * in milliseconds, between the completion of the first failed request and the
|
190 | * initiation of the first retrying request.
|
191 | * @param {number} retryDelayMultiplier - the multiplier by which to
|
192 | * increase the delay time between the completion of failed requests, and the
|
193 | * initiation of the subsequent retrying request.
|
194 | * @param {number} maxRetryDelayMillis - the maximum delay time, in
|
195 | * milliseconds, between requests. When this value is reached,
|
196 | * ``retryDelayMultiplier`` will no longer be used to increase delay time.
|
197 | * @param {number} initialRpcTimeoutMillis - the initial timeout parameter
|
198 | * to the request.
|
199 | * @param {number} rpcTimeoutMultiplier - the multiplier by which to
|
200 | * increase the timeout parameter between failed requests.
|
201 | * @param {number} maxRpcTimeoutMillis - the maximum timeout parameter, in
|
202 | * milliseconds, for a request. When this value is reached,
|
203 | * ``rpcTimeoutMultiplier`` will no longer be used to increase the timeout.
|
204 | * @param {number} totalTimeoutMillis - the total time, in milliseconds,
|
205 | * starting from when the initial request is sent, after which an error will
|
206 | * be returned, regardless of the retrying attempts made meanwhile.
|
207 | * @return {BackoffSettings} a new settings.
|
208 | *
|
209 | */
|
210 | export declare function createBackoffSettings(initialRetryDelayMillis: number, retryDelayMultiplier: number, maxRetryDelayMillis: number, initialRpcTimeoutMillis: number | null, rpcTimeoutMultiplier: number | null, maxRpcTimeoutMillis: number | null, totalTimeoutMillis: number | null): BackoffSettings;
|
211 | export declare function createDefaultBackoffSettings(): BackoffSettings;
|
212 | /**
|
213 | * Parameters to the exponential backoff algorithm for retrying.
|
214 | * This function is unsupported, and intended for internal use only.
|
215 | *
|
216 | * @param {number} initialRetryDelayMillis - the initial delay time,
|
217 | * in milliseconds, between the completion of the first failed request and the
|
218 | * initiation of the first retrying request.
|
219 | * @param {number} retryDelayMultiplier - the multiplier by which to
|
220 | * increase the delay time between the completion of failed requests, and the
|
221 | * initiation of the subsequent retrying request.
|
222 | * @param {number} maxRetryDelayMillis - the maximum delay time, in
|
223 | * milliseconds, between requests. When this value is reached,
|
224 | * ``retryDelayMultiplier`` will no longer be used to increase delay time.
|
225 | * @param {number} initialRpcTimeoutMillis - the initial timeout parameter
|
226 | * to the request.
|
227 | * @param {number} rpcTimeoutMultiplier - the multiplier by which to
|
228 | * increase the timeout parameter between failed requests.
|
229 | * @param {number} maxRpcTimeoutMillis - the maximum timeout parameter, in
|
230 | * milliseconds, for a request. When this value is reached,
|
231 | * ``rpcTimeoutMultiplier`` will no longer be used to increase the timeout.
|
232 | * @param {number} maxRetries - the maximum number of retrying attempts that
|
233 | * will be made. If reached, an error will be returned.
|
234 | * @return {BackoffSettings} a new settings.
|
235 | *
|
236 | */
|
237 | export declare function createMaxRetriesBackoffSettings(initialRetryDelayMillis: number, retryDelayMultiplier: number, maxRetryDelayMillis: number, initialRpcTimeoutMillis: number, rpcTimeoutMultiplier: number, maxRpcTimeoutMillis: number, maxRetries: number): BackoffSettings;
|
238 | /**
|
239 | * Creates a new {@link BundleOptions}.
|
240 | *
|
241 | * @private
|
242 | * @param {Object} options - An object to hold optional parameters. See
|
243 | * properties for the content of options.
|
244 | * @return {BundleOptions} - A new options.
|
245 | */
|
246 | export declare function createBundleOptions(options: BundlingConfig): BundleOptions;
|
247 | export interface ServiceConfig {
|
248 | retry_codes?: {
|
249 | [index: string]: string[];
|
250 | };
|
251 | retry_params?: {
|
252 | [index: string]: RetryParamsConfig;
|
253 | };
|
254 | methods: {
|
255 | [index: string]: MethodConfig | null;
|
256 | };
|
257 | }
|
258 | export interface RetryParamsConfig {
|
259 | initial_retry_delay_millis: number;
|
260 | retry_delay_multiplier: number;
|
261 | max_retry_delay_millis: number;
|
262 | initial_rpc_timeout_millis: number;
|
263 | rpc_timeout_multiplier: number;
|
264 | max_rpc_timeout_millis: number;
|
265 | total_timeout_millis: number;
|
266 | }
|
267 | export interface MethodConfig {
|
268 | retry_codes_name?: string;
|
269 | retry_params_name?: string;
|
270 | bundling?: BundlingConfig | null;
|
271 | timeout_millis?: number;
|
272 | }
|
273 | export interface BundlingConfig {
|
274 | element_count_threshold: number;
|
275 | element_count_limit: number;
|
276 | request_byte_threshold?: number;
|
277 | request_byte_limit?: number;
|
278 | delay_threshold_millis?: number;
|
279 | }
|
280 | export interface ClientConfig {
|
281 | interfaces?: {
|
282 | [index: string]: ServiceConfig;
|
283 | };
|
284 | }
|
285 | /**
|
286 | * Constructs a dictionary mapping method names to {@link CallSettings}.
|
287 | *
|
288 | * The `clientConfig` parameter is parsed from a client configuration JSON
|
289 | * file of the form:
|
290 | *
|
291 | * {
|
292 | * "interfaces": {
|
293 | * "google.fake.v1.ServiceName": {
|
294 | * "retry_codes": {
|
295 | * "idempotent": ["UNAVAILABLE", "DEADLINE_EXCEEDED"],
|
296 | * "non_idempotent": []
|
297 | * },
|
298 | * "retry_params": {
|
299 | * "default": {
|
300 | * "initial_retry_delay_millis": 100,
|
301 | * "retry_delay_multiplier": 1.2,
|
302 | * "max_retry_delay_millis": 1000,
|
303 | * "initial_rpc_timeout_millis": 2000,
|
304 | * "rpc_timeout_multiplier": 1.5,
|
305 | * "max_rpc_timeout_millis": 30000,
|
306 | * "total_timeout_millis": 45000
|
307 | * }
|
308 | * },
|
309 | * "methods": {
|
310 | * "CreateFoo": {
|
311 | * "retry_codes_name": "idempotent",
|
312 | * "retry_params_name": "default"
|
313 | * },
|
314 | * "Publish": {
|
315 | * "retry_codes_name": "non_idempotent",
|
316 | * "retry_params_name": "default",
|
317 | * "bundling": {
|
318 | * "element_count_threshold": 40,
|
319 | * "element_count_limit": 200,
|
320 | * "request_byte_threshold": 90000,
|
321 | * "request_byte_limit": 100000,
|
322 | * "delay_threshold_millis": 100
|
323 | * }
|
324 | * }
|
325 | * }
|
326 | * }
|
327 | * }
|
328 | * }
|
329 | *
|
330 | * @param {String} serviceName - The fully-qualified name of this
|
331 | * service, used as a key into the client config file (in the
|
332 | * example above, this value should be 'google.fake.v1.ServiceName').
|
333 | * @param {Object} clientConfig - A dictionary parsed from the
|
334 | * standard API client config file.
|
335 | * @param {Object} configOverrides - A dictionary in the same structure of
|
336 | * client_config to override the settings.
|
337 | * @param {Object.<string, string[]>} retryNames - A dictionary mapping the strings
|
338 | * referring to response status codes to objects representing
|
339 | * those codes.
|
340 | * @param {Object} otherArgs - the non-request arguments to be passed to the API
|
341 | * calls.
|
342 | * @return {Object} A mapping from method name to CallSettings, or null if the
|
343 | * service is not found in the config.
|
344 | */
|
345 | export declare function constructSettings(serviceName: string, clientConfig: ClientConfig, configOverrides: ClientConfig, retryNames: {}, otherArgs?: {}): any;
|