dev testing
This commit is contained in:
40
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningApiCaller.d.ts
generated
vendored
Normal file
40
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningApiCaller.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { APICaller } from '../apiCaller';
|
||||
import { APICallback, GRPCCall, SimpleCallbackFunction } from '../apitypes';
|
||||
import { OngoingCall, OngoingCallPromise } from '../call';
|
||||
import { CallOptions } from '../gax';
|
||||
import { GoogleError } from '../googleError';
|
||||
import { LongRunningDescriptor } from './longRunningDescriptor';
|
||||
export declare class LongrunningApiCaller implements APICaller {
|
||||
longrunningDescriptor: LongRunningDescriptor;
|
||||
/**
|
||||
* Creates an API caller that performs polling on a long running operation.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {LongRunningDescriptor} longrunningDescriptor - Holds the
|
||||
* decoders used for unpacking responses and the operationsClient
|
||||
* used for polling the operation.
|
||||
*/
|
||||
constructor(longrunningDescriptor: LongRunningDescriptor);
|
||||
init(callback?: APICallback): OngoingCallPromise | OngoingCall;
|
||||
wrap(func: GRPCCall): GRPCCall;
|
||||
call(apiCall: SimpleCallbackFunction, argument: {}, settings: CallOptions, canceller: OngoingCallPromise): void;
|
||||
private _wrapOperation;
|
||||
fail(canceller: OngoingCallPromise, err: GoogleError): void;
|
||||
result(canceller: OngoingCallPromise): import("../call").CancellablePromise<import("../apitypes").ResultTuple>;
|
||||
}
|
||||
72
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningApiCaller.js
generated
vendored
Normal file
72
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningApiCaller.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LongrunningApiCaller = void 0;
|
||||
const call_1 = require("../call");
|
||||
const gax_1 = require("../gax");
|
||||
const longrunning_1 = require("./longrunning");
|
||||
class LongrunningApiCaller {
|
||||
/**
|
||||
* Creates an API caller that performs polling on a long running operation.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @param {LongRunningDescriptor} longrunningDescriptor - Holds the
|
||||
* decoders used for unpacking responses and the operationsClient
|
||||
* used for polling the operation.
|
||||
*/
|
||||
constructor(longrunningDescriptor) {
|
||||
this.longrunningDescriptor = longrunningDescriptor;
|
||||
}
|
||||
init(callback) {
|
||||
if (callback) {
|
||||
return new call_1.OngoingCall(callback);
|
||||
}
|
||||
return new call_1.OngoingCallPromise();
|
||||
}
|
||||
wrap(func) {
|
||||
return func;
|
||||
}
|
||||
call(apiCall, argument, settings, canceller) {
|
||||
canceller.call((argument, callback) => {
|
||||
return this._wrapOperation(apiCall, settings, argument, callback);
|
||||
}, argument);
|
||||
}
|
||||
_wrapOperation(apiCall, settings, argument, callback) {
|
||||
let backoffSettings = settings.longrunning;
|
||||
if (!backoffSettings) {
|
||||
backoffSettings = (0, gax_1.createDefaultBackoffSettings)();
|
||||
}
|
||||
const longrunningDescriptor = this.longrunningDescriptor;
|
||||
return apiCall(argument, (err, rawResponse) => {
|
||||
if (err) {
|
||||
callback(err, null, null, rawResponse);
|
||||
return;
|
||||
}
|
||||
const operation = new longrunning_1.Operation(rawResponse, longrunningDescriptor, backoffSettings, settings);
|
||||
callback(null, operation, rawResponse);
|
||||
});
|
||||
}
|
||||
fail(canceller, err) {
|
||||
canceller.callback(err);
|
||||
}
|
||||
result(canceller) {
|
||||
return canceller.promise;
|
||||
}
|
||||
}
|
||||
exports.LongrunningApiCaller = LongrunningApiCaller;
|
||||
//# sourceMappingURL=longRunningApiCaller.js.map
|
||||
1
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningApiCaller.js.map
generated
vendored
Normal file
1
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningApiCaller.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"longRunningApiCaller.js","sourceRoot":"","sources":["../../../src/longRunningCalls/longRunningApiCaller.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,kCAAwD;AACxD,gCAIgB;AAGhB,+CAAwC;AAIxC,MAAa,oBAAoB;IAE/B;;;;;;;;OAQG;IACH,YAAY,qBAA4C;QACtD,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACrD,CAAC;IAED,IAAI,CAAC,QAAsB;QACzB,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,IAAI,kBAAW,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,yBAAkB,EAAE,CAAC;IAClC,CAAC;IAED,IAAI,CAAC,IAAc;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CACF,OAA+B,EAC/B,QAAY,EACZ,QAAqB,EACrB,SAA6B;QAE7B,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;YACpC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACpE,CAAC,EAAE,QAAQ,CAAC,CAAC;IACf,CAAC;IAEO,cAAc,CACpB,OAA+B,EAC/B,QAAqB,EACrB,QAAY,EACZ,QAAqB;QAErB,IAAI,eAAe,GAAgC,QAAQ,CAAC,WAAW,CAAC;QACxE,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,IAAA,kCAA4B,GAAE,CAAC;QACnD,CAAC;QAED,MAAM,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAC;QACzD,OAAO,OAAO,CACZ,QAAQ,EACR,CAAC,GAAuB,EAAE,WAAkC,EAAE,EAAE;YAC9D,IAAI,GAAG,EAAE,CAAC;gBACR,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,WAAwB,CAAC,CAAC;gBACpD,OAAO;YACT,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,uBAAS,CAC7B,WAA2D,EAC3D,qBAAqB,EACrB,eAAgB,EAChB,QAAQ,CACT,CAAC;YAEF,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;QACzC,CAAC,CACF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,SAA6B,EAAE,GAAgB;QAClD,SAAS,CAAC,QAAS,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,SAA6B;QAClC,OAAO,SAAS,CAAC,OAAO,CAAC;IAC3B,CAAC;CACF;AA5ED,oDA4EC"}
|
||||
35
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningDescriptor.d.ts
generated
vendored
Normal file
35
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningDescriptor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import * as protobuf from 'protobufjs';
|
||||
import { Descriptor } from '../descriptor';
|
||||
import { OperationsClient } from '../operationsClient';
|
||||
import { LongrunningApiCaller } from './longRunningApiCaller';
|
||||
/**
|
||||
* A callback to upack a google.protobuf.Any message.
|
||||
*/
|
||||
export interface AnyDecoder {
|
||||
(reader: protobuf.Reader | Uint8Array, length?: number): protobuf.Message<{}>;
|
||||
}
|
||||
/**
|
||||
* A descriptor for long-running operations.
|
||||
*/
|
||||
export declare class LongRunningDescriptor implements Descriptor {
|
||||
operationsClient: OperationsClient;
|
||||
responseDecoder: AnyDecoder;
|
||||
metadataDecoder: AnyDecoder;
|
||||
constructor(operationsClient: OperationsClient, responseDecoder: AnyDecoder, metadataDecoder: AnyDecoder);
|
||||
getApiCaller(): LongrunningApiCaller;
|
||||
}
|
||||
34
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningDescriptor.js
generated
vendored
Normal file
34
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningDescriptor.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LongRunningDescriptor = void 0;
|
||||
const longRunningApiCaller_1 = require("./longRunningApiCaller");
|
||||
/**
|
||||
* A descriptor for long-running operations.
|
||||
*/
|
||||
class LongRunningDescriptor {
|
||||
constructor(operationsClient, responseDecoder, metadataDecoder) {
|
||||
this.operationsClient = operationsClient;
|
||||
this.responseDecoder = responseDecoder;
|
||||
this.metadataDecoder = metadataDecoder;
|
||||
}
|
||||
getApiCaller() {
|
||||
return new longRunningApiCaller_1.LongrunningApiCaller(this);
|
||||
}
|
||||
}
|
||||
exports.LongRunningDescriptor = LongRunningDescriptor;
|
||||
//# sourceMappingURL=longRunningDescriptor.js.map
|
||||
1
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningDescriptor.js.map
generated
vendored
Normal file
1
functions/node_modules/google-gax/build/src/longRunningCalls/longRunningDescriptor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"longRunningDescriptor.js","sourceRoot":"","sources":["../../../src/longRunningCalls/longRunningDescriptor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAKH,iEAA4D;AAS5D;;GAEG;AACH,MAAa,qBAAqB;IAKhC,YACE,gBAAkC,EAClC,eAA2B,EAC3B,eAA2B;QAE3B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,2CAAoB,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF;AAlBD,sDAkBC"}
|
||||
132
functions/node_modules/google-gax/build/src/longRunningCalls/longrunning.d.ts
generated
vendored
Normal file
132
functions/node_modules/google-gax/build/src/longRunningCalls/longrunning.d.ts
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { EventEmitter } from 'events';
|
||||
import { ResultTuple } from '../apitypes';
|
||||
import { CancellablePromise } from '../call';
|
||||
import { BackoffSettings, CallOptions } from '../gax';
|
||||
import { GoogleError } from '../googleError';
|
||||
import { Metadata } from '../grpc';
|
||||
import { LongRunningDescriptor } from './longRunningDescriptor';
|
||||
import * as operationProtos from '../../protos/operations';
|
||||
/**
|
||||
* @callback GetOperationCallback
|
||||
* @param {?Error} error
|
||||
* @param {?Object} result
|
||||
* @param {?Object} metadata
|
||||
* @param {?google.longrunning.Operation} rawResponse
|
||||
*/
|
||||
export interface GetOperationCallback {
|
||||
(err?: Error | null, result?: {}, metadata?: {}, rawResponse?: LROOperation): void;
|
||||
}
|
||||
type LROOperation = operationProtos.google.longrunning.Operation;
|
||||
export declare class Operation extends EventEmitter {
|
||||
completeListeners: number;
|
||||
hasActiveListeners: boolean;
|
||||
latestResponse: LROOperation;
|
||||
longrunningDescriptor: LongRunningDescriptor;
|
||||
result: {} | null;
|
||||
metadata: Metadata | null;
|
||||
backoffSettings: BackoffSettings;
|
||||
_callOptions?: CallOptions;
|
||||
currentCallPromise_?: CancellablePromise<ResultTuple>;
|
||||
name?: string;
|
||||
done?: boolean;
|
||||
error?: GoogleError;
|
||||
response?: {};
|
||||
/**
|
||||
* Wrapper for a google.longrunnung.Operation.
|
||||
*
|
||||
* @constructor
|
||||
*
|
||||
* @param {google.longrunning.Operation} grpcOp - The operation to be wrapped.
|
||||
* @param {LongRunningDescriptor} longrunningDescriptor - This defines the
|
||||
* operations service client and unpacking mechanisms for the operation.
|
||||
* @param {BackoffSettings} backoffSettings - The backoff settings used in
|
||||
* in polling the operation.
|
||||
* @param {CallOptions} callOptions - CallOptions used in making get operation
|
||||
* requests.
|
||||
*/
|
||||
constructor(grpcOp: LROOperation, longrunningDescriptor: LongRunningDescriptor, backoffSettings: BackoffSettings, callOptions?: CallOptions);
|
||||
/**
|
||||
* Begin listening for events on the operation. This method keeps track of how
|
||||
* many "complete" listeners are registered and removed, making sure polling
|
||||
* is handled automatically.
|
||||
*
|
||||
* As long as there is one active "complete" listener, the connection is open.
|
||||
* When there are no more listeners, the polling stops.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_listenForEvents(): void;
|
||||
/**
|
||||
* Cancels current polling api call and cancels the operation.
|
||||
*
|
||||
* @return {Promise} the promise of the OperationsClient#cancelOperation api
|
||||
* request.
|
||||
*/
|
||||
cancel(): Promise<operationProtos.google.protobuf.Empty>;
|
||||
/**
|
||||
* Get the updated status of the operation. If the Operation has previously
|
||||
* completed, this will use the status of the cached completed operation.
|
||||
*
|
||||
* - callback(err): Operation failed
|
||||
* - callback(null, result, metadata, rawResponse): Operation complete
|
||||
* - callback(null, null, metadata, rawResponse): Operation incomplete
|
||||
*
|
||||
* @param {getOperationCallback} callback - Callback to handle the polled
|
||||
* operation result and metadata.
|
||||
* @return {Promise|undefined} - This returns a promise if a callback is not specified.
|
||||
* The promise resolves to an array where the first element is the unpacked
|
||||
* result, the second element is the metadata, and the third element is the
|
||||
* raw response of the api call. The promise rejects if the operation returns
|
||||
* an error.
|
||||
*/
|
||||
getOperation(): Promise<{}>;
|
||||
getOperation(callback: GetOperationCallback): void;
|
||||
_unpackResponse(op: LROOperation, callback?: GetOperationCallback): void;
|
||||
/**
|
||||
* Poll `getOperation` to check the operation's status. This runs a loop to
|
||||
* ping using the backoff strategy specified at initialization.
|
||||
*
|
||||
* Note: This method is automatically called once a "complete" event handler
|
||||
* is registered on the operation.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
startPolling_(): void;
|
||||
/**
|
||||
* Wraps the `complete` and `error` events in a Promise.
|
||||
*
|
||||
* @return {promise} - Promise that resolves on operation completion and rejects
|
||||
* on operation error.
|
||||
*/
|
||||
promise(): Promise<unknown>;
|
||||
}
|
||||
/**
|
||||
* Method used to create Operation objects.
|
||||
*
|
||||
* @constructor
|
||||
*
|
||||
* @param {google.longrunning.Operation} op - The operation to be wrapped.
|
||||
* @param {LongRunningDescriptor} longrunningDescriptor - This defines the
|
||||
* operations service client and unpacking mechanisms for the operation.
|
||||
* @param {BackoffSettings} backoffSettings - The backoff settings used in
|
||||
* in polling the operation.
|
||||
* @param {CallOptions=} callOptions - CallOptions used in making get operation
|
||||
* requests.
|
||||
*/
|
||||
export declare function operation(op: LROOperation, longrunningDescriptor: LongRunningDescriptor, backoffSettings: BackoffSettings, callOptions?: CallOptions): Operation;
|
||||
export {};
|
||||
280
functions/node_modules/google-gax/build/src/longRunningCalls/longrunning.js
generated
vendored
Normal file
280
functions/node_modules/google-gax/build/src/longRunningCalls/longrunning.js
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Operation = void 0;
|
||||
exports.operation = operation;
|
||||
const events_1 = require("events");
|
||||
const status_1 = require("../status");
|
||||
const googleError_1 = require("../googleError");
|
||||
const operationProtos = require("../../protos/operations");
|
||||
class Operation extends events_1.EventEmitter {
|
||||
/**
|
||||
* Wrapper for a google.longrunnung.Operation.
|
||||
*
|
||||
* @constructor
|
||||
*
|
||||
* @param {google.longrunning.Operation} grpcOp - The operation to be wrapped.
|
||||
* @param {LongRunningDescriptor} longrunningDescriptor - This defines the
|
||||
* operations service client and unpacking mechanisms for the operation.
|
||||
* @param {BackoffSettings} backoffSettings - The backoff settings used in
|
||||
* in polling the operation.
|
||||
* @param {CallOptions} callOptions - CallOptions used in making get operation
|
||||
* requests.
|
||||
*/
|
||||
constructor(grpcOp, longrunningDescriptor, backoffSettings, callOptions) {
|
||||
super();
|
||||
this.completeListeners = 0;
|
||||
this.hasActiveListeners = false;
|
||||
this.latestResponse = grpcOp;
|
||||
this.name = this.latestResponse.name;
|
||||
this.done = this.latestResponse.done;
|
||||
this.error = this.latestResponse.error;
|
||||
this.longrunningDescriptor = longrunningDescriptor;
|
||||
this.result = null;
|
||||
this.metadata = null;
|
||||
this.backoffSettings = backoffSettings;
|
||||
this._unpackResponse(grpcOp);
|
||||
this._listenForEvents();
|
||||
this._callOptions = callOptions;
|
||||
}
|
||||
/**
|
||||
* Begin listening for events on the operation. This method keeps track of how
|
||||
* many "complete" listeners are registered and removed, making sure polling
|
||||
* is handled automatically.
|
||||
*
|
||||
* As long as there is one active "complete" listener, the connection is open.
|
||||
* When there are no more listeners, the polling stops.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_listenForEvents() {
|
||||
this.on('newListener', event => {
|
||||
if (event === 'complete') {
|
||||
this.completeListeners++;
|
||||
if (!this.hasActiveListeners) {
|
||||
this.hasActiveListeners = true;
|
||||
this.startPolling_();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.on('removeListener', event => {
|
||||
if (event === 'complete' && --this.completeListeners === 0) {
|
||||
this.hasActiveListeners = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Cancels current polling api call and cancels the operation.
|
||||
*
|
||||
* @return {Promise} the promise of the OperationsClient#cancelOperation api
|
||||
* request.
|
||||
*/
|
||||
cancel() {
|
||||
if (this.currentCallPromise_) {
|
||||
this.currentCallPromise_.cancel();
|
||||
}
|
||||
const operationsClient = this.longrunningDescriptor.operationsClient;
|
||||
const cancelRequest = new operationProtos.google.longrunning.CancelOperationRequest();
|
||||
cancelRequest.name = this.latestResponse.name;
|
||||
return operationsClient.cancelOperation(cancelRequest);
|
||||
}
|
||||
getOperation(callback) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const self = this;
|
||||
const operationsClient = this.longrunningDescriptor.operationsClient;
|
||||
function promisifyResponse() {
|
||||
if (!callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (self.latestResponse.error) {
|
||||
const error = new googleError_1.GoogleError(self.latestResponse.error.message);
|
||||
error.code = self.latestResponse.error.code;
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve([self.result, self.metadata, self.latestResponse]);
|
||||
}
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.latestResponse.done) {
|
||||
this._unpackResponse(this.latestResponse, callback);
|
||||
return promisifyResponse();
|
||||
}
|
||||
const request = new operationProtos.google.longrunning.GetOperationRequest();
|
||||
request.name = this.latestResponse.name;
|
||||
this.currentCallPromise_ = operationsClient.getOperationInternal(request, this._callOptions);
|
||||
const noCallbackPromise = this.currentCallPromise_.then(responses => {
|
||||
self.latestResponse = responses[0];
|
||||
self._unpackResponse(responses[0], callback);
|
||||
return promisifyResponse();
|
||||
}, (err) => {
|
||||
if (callback) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
return Promise.reject(err);
|
||||
});
|
||||
if (!callback) {
|
||||
return noCallbackPromise;
|
||||
}
|
||||
}
|
||||
_unpackResponse(op, callback) {
|
||||
const responseDecoder = this.longrunningDescriptor.responseDecoder;
|
||||
const metadataDecoder = this.longrunningDescriptor.metadataDecoder;
|
||||
let response;
|
||||
let metadata;
|
||||
if (op.done) {
|
||||
if (op.result === 'error') {
|
||||
const error = new googleError_1.GoogleError(op.error.message);
|
||||
error.code = op.error.code;
|
||||
this.error = error;
|
||||
if (callback) {
|
||||
callback(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (responseDecoder && op.response) {
|
||||
this.response = op.response;
|
||||
response = responseDecoder(op.response.value);
|
||||
this.result = response;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
if (metadataDecoder && op.metadata) {
|
||||
metadata = metadataDecoder(op.metadata.value);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
if (callback) {
|
||||
callback(null, response, metadata, op);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Poll `getOperation` to check the operation's status. This runs a loop to
|
||||
* ping using the backoff strategy specified at initialization.
|
||||
*
|
||||
* Note: This method is automatically called once a "complete" event handler
|
||||
* is registered on the operation.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
startPolling_() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const self = this;
|
||||
let now = new Date();
|
||||
const delayMult = this.backoffSettings.retryDelayMultiplier;
|
||||
const maxDelay = this.backoffSettings.maxRetryDelayMillis;
|
||||
let delay = this.backoffSettings.initialRetryDelayMillis;
|
||||
let deadline = Infinity;
|
||||
if (this.backoffSettings.totalTimeoutMillis) {
|
||||
deadline = now.getTime() + this.backoffSettings.totalTimeoutMillis;
|
||||
}
|
||||
let previousMetadataBytes;
|
||||
if (this.latestResponse.metadata) {
|
||||
previousMetadataBytes = this.latestResponse.metadata.value;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function emit(event, ...args) {
|
||||
self.emit(event, ...args);
|
||||
}
|
||||
// Helper function to replace nodejs buffer's equals()
|
||||
function arrayEquals(a, b) {
|
||||
if (a.byteLength !== b.byteLength) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.byteLength; ++i) {
|
||||
if (a[i] !== b[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function retry() {
|
||||
if (!self.hasActiveListeners) {
|
||||
return;
|
||||
}
|
||||
if (now.getTime() >= deadline) {
|
||||
const error = new googleError_1.GoogleError('Total timeout exceeded before any response was received');
|
||||
error.code = status_1.Status.DEADLINE_EXCEEDED;
|
||||
setImmediate(emit, 'error', error);
|
||||
return;
|
||||
}
|
||||
self.getOperation((err, result, metadata, rawResponse) => {
|
||||
if (err) {
|
||||
setImmediate(emit, 'error', err);
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
if (rawResponse.metadata &&
|
||||
(!previousMetadataBytes ||
|
||||
(rawResponse &&
|
||||
!arrayEquals(rawResponse.metadata.value, previousMetadataBytes)))) {
|
||||
setImmediate(emit, 'progress', metadata, rawResponse);
|
||||
previousMetadataBytes = rawResponse.metadata.value;
|
||||
}
|
||||
// special case: some APIs fail to set either result or error
|
||||
// but set done = true (e.g. speech with silent file).
|
||||
// Some APIs just use this for the normal completion
|
||||
// (e.g. nodejs-contact-center-insights), so let's just return
|
||||
// an empty response in this case.
|
||||
if (rawResponse.done) {
|
||||
setImmediate(emit, 'complete', {}, metadata, rawResponse);
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
now = new Date();
|
||||
delay = Math.min(delay * delayMult, maxDelay);
|
||||
retry();
|
||||
}, delay);
|
||||
return;
|
||||
}
|
||||
setImmediate(emit, 'complete', result, metadata, rawResponse);
|
||||
});
|
||||
}
|
||||
retry();
|
||||
}
|
||||
/**
|
||||
* Wraps the `complete` and `error` events in a Promise.
|
||||
*
|
||||
* @return {promise} - Promise that resolves on operation completion and rejects
|
||||
* on operation error.
|
||||
*/
|
||||
promise() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.on('error', reject).on('complete', (result, metadata, rawResponse) => {
|
||||
resolve([result, metadata, rawResponse]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Operation = Operation;
|
||||
/**
|
||||
* Method used to create Operation objects.
|
||||
*
|
||||
* @constructor
|
||||
*
|
||||
* @param {google.longrunning.Operation} op - The operation to be wrapped.
|
||||
* @param {LongRunningDescriptor} longrunningDescriptor - This defines the
|
||||
* operations service client and unpacking mechanisms for the operation.
|
||||
* @param {BackoffSettings} backoffSettings - The backoff settings used in
|
||||
* in polling the operation.
|
||||
* @param {CallOptions=} callOptions - CallOptions used in making get operation
|
||||
* requests.
|
||||
*/
|
||||
function operation(op, longrunningDescriptor, backoffSettings, callOptions) {
|
||||
return new Operation(op, longrunningDescriptor, backoffSettings, callOptions);
|
||||
}
|
||||
//# sourceMappingURL=longrunning.js.map
|
||||
1
functions/node_modules/google-gax/build/src/longRunningCalls/longrunning.js.map
generated
vendored
Normal file
1
functions/node_modules/google-gax/build/src/longRunningCalls/longrunning.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user