1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-07-06 19:00:50 +00:00
This commit is contained in:
MatteZ02
2020-03-03 22:30:50 +02:00
parent edfcc6f474
commit 30022c7634
11800 changed files with 1984416 additions and 1 deletions

View File

@ -0,0 +1,31 @@
/**
* 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, ApiCallerSettings } from '../apiCaller';
import { APICallback, GRPCCall, SimpleCallbackFunction } from '../apitypes';
import { OngoingCall, OngoingCallPromise } from '../call';
import { GoogleError } from '../googleError';
/**
* Creates an API caller for regular unary methods.
*/
export declare class NormalApiCaller implements APICaller {
init(settings: ApiCallerSettings, callback?: APICallback): OngoingCallPromise | OngoingCall;
wrap(func: GRPCCall): GRPCCall;
call(apiCall: SimpleCallbackFunction, argument: {}, settings: {}, canceller: OngoingCallPromise): void;
fail(canceller: OngoingCallPromise, err: GoogleError): void;
result(canceller: OngoingCallPromise): import("../call").CancellablePromise<[import("../apitypes").ResponseType, {
[index: string]: string | number | {};
} | null | undefined, {} | import("..").Operation | null | undefined]>;
}

View File

@ -0,0 +1,43 @@
"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 });
const call_1 = require("../call");
/**
* Creates an API caller for regular unary methods.
*/
class NormalApiCaller {
init(settings, callback) {
if (callback) {
return new call_1.OngoingCall(callback);
}
return new call_1.OngoingCallPromise(settings.promise);
}
wrap(func) {
return func;
}
call(apiCall, argument, settings, canceller) {
canceller.call(apiCall, argument);
}
fail(canceller, err) {
canceller.callback(err);
}
result(canceller) {
return canceller.promise;
}
}
exports.NormalApiCaller = NormalApiCaller;
//# sourceMappingURL=normalApiCaller.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"normalApiCaller.js","sourceRoot":"","sources":["../../../src/normalCalls/normalApiCaller.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAIH,kCAAwD;AAGxD;;GAEG;AACH,MAAa,eAAe;IAC1B,IAAI,CACF,QAA2B,EAC3B,QAAsB;QAEtB,IAAI,QAAQ,EAAE;YACZ,OAAO,IAAI,kBAAW,CAAC,QAAQ,CAAC,CAAC;SAClC;QACD,OAAO,IAAI,yBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,CAAC,IAAc;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CACF,OAA+B,EAC/B,QAAY,EACZ,QAAY,EACZ,SAA6B;QAE7B,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACpC,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;AA/BD,0CA+BC"}

View File

@ -0,0 +1,31 @@
/**
* 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 { GRPCCall, GRPCCallOtherArgs, SimpleCallbackFunction } from '../apitypes';
import { RetryOptions } from '../gax';
/**
* Creates a function equivalent to func, but that retries on certain
* exceptions.
*
* @private
*
* @param {GRPCCall} func - A function.
* @param {RetryOptions} retry - Configures the exceptions upon which the
* function eshould retry, and the parameters to the exponential backoff retry
* algorithm.
* @param {GRPCCallOtherArgs} otherArgs - the additional arguments to be passed to func.
* @return {SimpleCallbackFunction} A function that will retry.
*/
export declare function retryable(func: GRPCCall, retry: RetryOptions, otherArgs: GRPCCallOtherArgs): SimpleCallbackFunction;

View File

@ -0,0 +1,132 @@
"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 });
const status_1 = require("../status");
const googleError_1 = require("../googleError");
const timeout_1 = require("./timeout");
/**
* Creates a function equivalent to func, but that retries on certain
* exceptions.
*
* @private
*
* @param {GRPCCall} func - A function.
* @param {RetryOptions} retry - Configures the exceptions upon which the
* function eshould retry, and the parameters to the exponential backoff retry
* algorithm.
* @param {GRPCCallOtherArgs} otherArgs - the additional arguments to be passed to func.
* @return {SimpleCallbackFunction} A function that will retry.
*/
function retryable(func, retry, otherArgs) {
const delayMult = retry.backoffSettings.retryDelayMultiplier;
const maxDelay = retry.backoffSettings.maxRetryDelayMillis;
const timeoutMult = retry.backoffSettings.rpcTimeoutMultiplier;
const maxTimeout = retry.backoffSettings.maxRpcTimeoutMillis;
let delay = retry.backoffSettings.initialRetryDelayMillis;
let timeout = retry.backoffSettings.initialRpcTimeoutMillis;
/**
* Equivalent to ``func``, but retries upon transient failure.
*
* Retrying is done through an exponential backoff algorithm configured
* by the options in ``retry``.
* @param {RequestType} argument The request object.
* @param {APICallback} callback The callback.
* @return {GRPCCall}
*/
return (argument, callback) => {
let canceller;
let timeoutId;
let now = new Date();
let deadline;
if (retry.backoffSettings.totalTimeoutMillis) {
deadline = now.getTime() + retry.backoffSettings.totalTimeoutMillis;
}
let retries = 0;
const maxRetries = retry.backoffSettings.maxRetries;
// TODO: define A/B testing values for retry behaviors.
/** Repeat the API call as long as necessary. */
function repeat() {
timeoutId = null;
if (deadline && now.getTime() >= deadline) {
const error = new googleError_1.GoogleError('Retry total timeout exceeded before any response was received');
error.code = status_1.Status.DEADLINE_EXCEEDED;
callback(error);
return;
}
if (retries && retries >= maxRetries) {
const error = new googleError_1.GoogleError('Exceeded maximum number of retries before any ' +
'response was received');
error.code = status_1.Status.DEADLINE_EXCEEDED;
callback(error);
return;
}
retries++;
const toCall = timeout_1.addTimeoutArg(func, timeout, otherArgs);
canceller = toCall(argument, (err, response, next, rawResponse) => {
if (!err) {
callback(null, response, next, rawResponse);
return;
}
canceller = null;
if (retry.retryCodes.indexOf(err.code) < 0) {
err.note =
'Exception occurred in retry method that was ' +
'not classified as transient';
callback(err);
}
else {
const toSleep = Math.random() * delay;
timeoutId = setTimeout(() => {
now = new Date();
delay = Math.min(delay * delayMult, maxDelay);
const timeoutCal = timeout && timeoutMult ? timeout * timeoutMult : 0;
const rpcTimeout = maxTimeout ? maxTimeout : 0;
const newDeadline = deadline ? deadline - now.getTime() : 0;
timeout = Math.min(timeoutCal, rpcTimeout, newDeadline);
repeat();
}, toSleep);
}
});
}
if (maxRetries && deadline) {
const error = new googleError_1.GoogleError('Cannot set both totalTimeoutMillis and maxRetries ' +
'in backoffSettings.');
error.code = status_1.Status.INVALID_ARGUMENT;
callback(error);
}
else {
repeat();
}
return {
cancel() {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (canceller) {
canceller.cancel();
}
else {
const error = new googleError_1.GoogleError('cancelled');
error.code = status_1.Status.CANCELLED;
callback(error);
}
},
};
};
}
exports.retryable = retryable;
//# sourceMappingURL=retries.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"retries.js","sourceRoot":"","sources":["../../../src/normalCalls/retries.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,sCAAiC;AAWjC,gDAA2C;AAE3C,uCAAwC;AAExC;;;;;;;;;;;;GAYG;AACH,SAAgB,SAAS,CACvB,IAAc,EACd,KAAmB,EACnB,SAA4B;IAE5B,MAAM,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,oBAAoB,CAAC;IAC7D,MAAM,QAAQ,GAAG,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC;IAC3D,MAAM,WAAW,GAAG,KAAK,CAAC,eAAe,CAAC,oBAAoB,CAAC;IAC/D,MAAM,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC;IAE7D,IAAI,KAAK,GAAG,KAAK,CAAC,eAAe,CAAC,uBAAuB,CAAC;IAC1D,IAAI,OAAO,GAAG,KAAK,CAAC,eAAe,CAAC,uBAAuB,CAAC;IAE5D;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAqB,EAAE,QAAqB,EAAE,EAAE;QACtD,IAAI,SAAgC,CAAC;QACrC,IAAI,SAA+C,CAAC;QACpD,IAAI,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,QAAgB,CAAC;QACrB,IAAI,KAAK,CAAC,eAAe,CAAC,kBAAkB,EAAE;YAC5C,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,eAAe,CAAC,kBAAkB,CAAC;SACrE;QACD,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,MAAM,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,UAAW,CAAC;QACrD,uDAAuD;QAEvD,gDAAgD;QAChD,SAAS,MAAM;YAC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/GD,8BA+GC"}

View File

@ -0,0 +1,32 @@
/**
* 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 { GRPCCall, GRPCCallOtherArgs, SimpleCallbackFunction } from '../apitypes';
/**
* Updates func so that it gets called with the timeout as its final arg.
*
* This converts a function, func, into another function with updated deadline.
*
* @private
*
* @param {GRPCCall} func - a function to be updated.
* @param {number} timeout - to be added to the original function as it final
* positional arg.
* @param {Object} otherArgs - the additional arguments to be passed to func.
* @param {Object=} abTests - the A/B testing key/value pairs.
* @return {function(Object, APICallback)}
* the function with other arguments and the timeout.
*/
export declare function addTimeoutArg(func: GRPCCall, timeout: number, otherArgs: GRPCCallOtherArgs, abTests?: {}): SimpleCallbackFunction;

View File

@ -0,0 +1,47 @@
"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 });
/**
* Updates func so that it gets called with the timeout as its final arg.
*
* This converts a function, func, into another function with updated deadline.
*
* @private
*
* @param {GRPCCall} func - a function to be updated.
* @param {number} timeout - to be added to the original function as it final
* positional arg.
* @param {Object} otherArgs - the additional arguments to be passed to func.
* @param {Object=} abTests - the A/B testing key/value pairs.
* @return {function(Object, APICallback)}
* the function with other arguments and the timeout.
*/
function addTimeoutArg(func, timeout, otherArgs, abTests) {
// TODO: this assumes the other arguments consist of metadata and options,
// which is specific to gRPC calls. Remove the hidden dependency on gRPC.
return (argument, callback) => {
const now = new Date();
const options = otherArgs.options || {};
options.deadline = new Date(now.getTime() + timeout);
const metadata = otherArgs.metadataBuilder
? otherArgs.metadataBuilder(abTests, otherArgs.headers || {})
: null;
return func(argument, metadata, options, callback);
};
}
exports.addTimeoutArg = addTimeoutArg;
//# sourceMappingURL=timeout.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../../src/normalCalls/timeout.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AASH;;;;;;;;;;;;;;GAcG;AACH,SAAgB,aAAa,CAC3B,IAAc,EACd,OAAe,EACf,SAA4B,EAC5B,OAAY;IAEZ,0EAA0E;IAC1E,yEAAyE;IACzE,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;QAC5B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;QACxC,OAAO,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QACrD,MAAM,QAAQ,GAAG,SAAS,CAAC,eAAe;YACxC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;YAC7D,CAAC,CAAC,IAAI,CAAC;QACT,OAAQ,IAAkB,CAAC,QAAQ,EAAE,QAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC,CAAC;AACJ,CAAC;AAjBD,sCAiBC"}