Socket
Socket
Sign inDemoInstall

google-gax

Package Overview
Dependencies
137
Maintainers
3
Versions
356
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.4 to 3.2.0

2

build/src/createApiCall.d.ts

@@ -38,2 +38,2 @@ /**

*/
export declare function createApiCall(func: Promise<GRPCCall> | GRPCCall, settings: CallSettings, descriptor?: Descriptor): GaxCall;
export declare function createApiCall(func: Promise<GRPCCall> | GRPCCall, settings: CallSettings, descriptor?: Descriptor, _fallback?: boolean | 'proto' | 'rest'): GaxCall;

@@ -44,3 +44,6 @@ "use strict";

*/
function createApiCall(func, settings, descriptor) {
function createApiCall(func, settings, descriptor,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_fallback // unused here, used in fallback.ts implementation
) {
// we want to be able to accept both promise resolving to a function and a

@@ -47,0 +50,0 @@ // function. Currently client librares are only calling this method with a

@@ -31,6 +31,9 @@ /**

export { routingHeader };
export { CallSettings, constructSettings, RetryOptions } from './gax';
export { CallSettings, constructSettings, RetryOptions, createDefaultBackoffSettings, } from './gax';
export declare const version: string;
export { BundleDescriptor, LongrunningDescriptor, PageDescriptor, StreamDescriptor, } from './descriptor';
export { StreamType } from './streamingCalls/streaming';
export { OperationsClient } from './operationsClient';
export { IamClient } from './iamService';
export { LocationsClient } from './locationService';
export declare const defaultToObjectOptions: {

@@ -137,3 +140,3 @@ keepCase: boolean;

*/
export declare function createApiCall(func: Promise<GRPCCall> | GRPCCall, settings: gax.CallSettings, descriptor?: Descriptor): GaxCall;
export declare function createApiCall(func: Promise<GRPCCall> | GRPCCall, settings: gax.CallSettings, descriptor?: Descriptor, fallback?: boolean | 'proto' | 'rest'): GaxCall;
export { protobuf };

@@ -140,0 +143,0 @@ export * as protobufMinimal from 'protobufjs/minimal';

@@ -18,3 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fallback = exports.protobufMinimal = exports.protobuf = exports.createApiCall = exports.lro = exports.GrpcClient = exports.defaultToObjectOptions = exports.StreamType = exports.StreamDescriptor = exports.PageDescriptor = exports.LongrunningDescriptor = exports.BundleDescriptor = exports.version = exports.RetryOptions = exports.constructSettings = exports.CallSettings = exports.routingHeader = exports.PathTemplate = void 0;
exports.fallback = exports.protobufMinimal = exports.protobuf = exports.createApiCall = exports.lro = exports.GrpcClient = exports.defaultToObjectOptions = exports.LocationsClient = exports.IamClient = exports.OperationsClient = exports.StreamType = exports.StreamDescriptor = exports.PageDescriptor = exports.LongrunningDescriptor = exports.BundleDescriptor = exports.version = exports.createDefaultBackoffSettings = exports.RetryOptions = exports.constructSettings = exports.CallSettings = exports.routingHeader = exports.PathTemplate = void 0;
const objectHash = require("object-hash");

@@ -42,2 +42,3 @@ const protobuf = require("protobufjs");

Object.defineProperty(exports, "RetryOptions", { enumerable: true, get: function () { return gax_1.RetryOptions; } });
Object.defineProperty(exports, "createDefaultBackoffSettings", { enumerable: true, get: function () { return gax_1.createDefaultBackoffSettings; } });
exports.version = require('../../package.json').version + '-fallback';

@@ -51,2 +52,8 @@ var descriptor_1 = require("./descriptor");

Object.defineProperty(exports, "StreamType", { enumerable: true, get: function () { return streaming_2.StreamType; } });
var operationsClient_2 = require("./operationsClient");
Object.defineProperty(exports, "OperationsClient", { enumerable: true, get: function () { return operationsClient_2.OperationsClient; } });
var iamService_1 = require("./iamService");
Object.defineProperty(exports, "IamClient", { enumerable: true, get: function () { return iamService_1.IamClient; } });
var locationService_1 = require("./locationService");
Object.defineProperty(exports, "LocationsClient", { enumerable: true, get: function () { return locationService_1.LocationsClient; } });
exports.defaultToObjectOptions = {

@@ -282,10 +289,18 @@ keepCase: false,

*/
function createApiCall(func, settings, descriptor) {
if (descriptor &&
function createApiCall(func, settings, descriptor, fallback) {
if ((!fallback || fallback === 'rest') &&
descriptor &&
'streaming' in descriptor &&
descriptor.type !== streaming_1.StreamType.SERVER_STREAMING) {
return () => {
throw new Error('The gRPC-fallback client library (e.g. browser version of the library) currently does not support client-streaming or bidi-stream calls.');
throw new Error('The REST transport currently does not support client-streaming or bidi-stream calls.');
};
}
if ((fallback === 'proto' || fallback === true) && // for legacy reasons, fallback === true means 'proto'
descriptor &&
'streaming' in descriptor) {
return () => {
throw new Error('The gRPC-fallback (proto over HTTP) transport currently does not support streaming calls.');
};
}
return (0, createApiCall_1.createApiCall)(func, settings, descriptor);

@@ -292,0 +307,0 @@ }

@@ -26,15 +26,3 @@ "use strict";

if (!(0, featureDetection_1.hasTextEncoder)() || !(0, featureDetection_1.hasTextDecoder)()) {
if ((0, featureDetection_1.isNodeJS)()) {
// Node.js 10 does not have global TextDecoder
// TODO(@alexander-fenster): remove this logic after Node.js 10 is EOL.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const util = require('util');
Object.assign(global, {
TextDecoder: util.TextDecoder,
TextEncoder: util.TextEncoder,
});
}
else {
require('fast-text-encoding');
}
require('fast-text-encoding');
}

@@ -41,0 +29,0 @@ function encodeRequest(rpc, protocol, servicePath, servicePort, request) {

@@ -40,2 +40,14 @@ "use strict";

// Using plain old promises instead.
let fetchParameters;
try {
fetchParameters = requestEncoder(rpc, protocol, servicePath, servicePort, request);
}
catch (err) {
// we could not encode parameters; pass error to the callback
// and return a no-op canceler object.
callback(err);
return {
cancel() { },
};
}
const cancelController = (0, featureDetection_1.hasAbortController)()

@@ -46,3 +58,2 @@ ? new AbortController()

let cancelRequested = false;
const fetchParameters = requestEncoder(rpc, protocol, servicePath, servicePort, request);
const url = fetchParameters.url;

@@ -49,0 +60,0 @@ const headers = fetchParameters.headers;

@@ -57,2 +57,15 @@ "use strict";

}
// fallback logic.
// related issue: https://github.com/googleapis/gax-nodejs/issues/1303
// google error mapping: https://cloud.google.com/apis/design/errors
// if input json doesn't have 'error' fields, wrap the whole object with 'error' field
if (!json['error']) {
json['error'] = {};
Object.keys(json)
.filter(key => key !== 'error')
.forEach(key => {
json['error'][key] = json[key];
delete json[key];
});
}
const decoder = new GoogleErrorDecoder();

@@ -71,3 +84,3 @@ const proto3Error = decoder.decodeHTTPError(json['error']);

// Keep consistency with gRPC statusDetails fields. gRPC details has been occupied before.
// Rename "detials" to "statusDetails".
// Rename "details" to "statusDetails".
if (error.details) {

@@ -74,0 +87,0 @@ try {

@@ -15,3 +15,2 @@ import * as gax from './gax';

private _providedCustomServicePath;
private _gaxGrpc;
private _protos;

@@ -18,0 +17,0 @@ private _defaults;

@@ -20,3 +20,2 @@ "use strict";

const warnings_1 = require("./warnings");
const grpc_1 = require("./grpc");
const createApiCall_1 = require("./createApiCall");

@@ -94,8 +93,6 @@ const routingHeader = require("./routingHeader");

}
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
this._gaxGrpc = new grpc_1.GrpcClient(opts);
// Save options to use in initialize() method.
this._opts = opts;
// Save the auth object to the client, for use by other methods.
this.auth = this._gaxGrpc.auth;
this.auth = gaxGrpc.auth;
// Set the default scopes in auth client if needed.

@@ -114,6 +111,6 @@ if (servicePath === staticMembers.servicePath) {

if (!opts.fallback) {
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`);
}
else if (opts.fallback === 'rest') {
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
clientHeader.push(`rest/${gaxGrpc.grpcVersion}`);
}

@@ -124,3 +121,3 @@ if (opts.libName && opts.libVersion) {

// Load the applicable protos.
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
this._protos = gaxGrpc.loadProtoJSON(jsonProtos);
// Some of the methods on this service return "paged" results,

@@ -133,3 +130,3 @@ // (e.g. 50 results at a time, with tokens to get subsequent

// Put together the default options sent with requests.
this._defaults = this._gaxGrpc.constructSettings('google.cloud.location.Locations', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
this._defaults = gaxGrpc.constructSettings('google.cloud.location.Locations', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
// Set up a dictionary of "inner API calls"; the core implementation

@@ -136,0 +133,0 @@ // of calling the API is handled in `google-gax`, with this code

@@ -124,2 +124,8 @@ "use strict";

return promisifyResponse();
}, (err) => {
if (callback) {
callback(err);
return;
}
return Promise.reject(err);
});

@@ -126,0 +132,0 @@ if (!callback) {

@@ -45,3 +45,3 @@ /**

export declare function flattenObject(request: JSONObject): JSONObject;
export declare function requestChangeCaseAndCleanup(request: JSONObject, caseChangeFunc: (key: string) => string): JSONObject;
export declare function requestChangeCaseAndCleanup(request: JSONObject, caseChangeFunc: (key: string) => string, fieldsToChange?: Set<string>): JSONObject;
export declare function isProto3OptionalField(field: Field): any;

@@ -48,0 +48,0 @@ export declare function isRequiredField(field: Field): boolean | undefined;

@@ -19,2 +19,3 @@ "use strict";

exports.overrideHttpRules = exports.transcode = exports.getFieldNameOnBehavior = exports.isRequiredField = exports.isProto3OptionalField = exports.requestChangeCaseAndCleanup = exports.flattenObject = exports.match = exports.applyPattern = exports.encodeWithoutSlashes = exports.encodeWithSlashes = exports.buildQueryStringComponents = exports.deleteField = exports.deepCopy = exports.getField = void 0;
const googleError_1 = require("./googleError");
const util_1 = require("./util");

@@ -138,7 +139,7 @@ const httpOptionName = '(google.api.http)';

const fieldValue = getField(request, field);
if (typeof fieldValue === 'undefined') {
if (fieldValue === undefined) {
return undefined;
}
const appliedPattern = applyPattern(pattern, fieldValue === null ? 'null' : fieldValue.toString());
if (typeof appliedPattern === 'undefined') {
if (appliedPattern === undefined) {
return undefined;

@@ -154,3 +155,3 @@ }

for (const key in request) {
if (typeof request[key] === 'undefined') {
if (request[key] === undefined) {
continue;

@@ -176,3 +177,3 @@ }

exports.flattenObject = flattenObject;
function requestChangeCaseAndCleanup(request, caseChangeFunc) {
function requestChangeCaseAndCleanup(request, caseChangeFunc, fieldsToChange) {
if (!request || typeof request !== 'object') {

@@ -187,9 +188,17 @@ return request;

}
const convertedField = caseChangeFunc(field);
let convertedField = caseChangeFunc(field);
// Here, we want to check if the fields in the proto match
// the fields we are changing; if not, we assume it's user
// input and revert back to its original form
if (fieldsToChange &&
(fieldsToChange === null || fieldsToChange === void 0 ? void 0 : fieldsToChange.size) !== 0 &&
!(fieldsToChange === null || fieldsToChange === void 0 ? void 0 : fieldsToChange.has(convertedField))) {
convertedField = field;
}
const value = request[field];
if (Array.isArray(value)) {
convertedRequest[convertedField] = value.map(v => requestChangeCaseAndCleanup(v, caseChangeFunc));
convertedRequest[convertedField] = value.map(v => requestChangeCaseAndCleanup(v, caseChangeFunc, fieldsToChange));
}
else {
convertedRequest[convertedField] = requestChangeCaseAndCleanup(value, caseChangeFunc);
convertedRequest[convertedField] = requestChangeCaseAndCleanup(value, caseChangeFunc, fieldsToChange);
}

@@ -225,2 +234,15 @@ }

exports.getFieldNameOnBehavior = getFieldNameOnBehavior;
// This function gets all the fields recursively
function getAllFieldNames(fields, fieldNames) {
var _a, _b;
if (fields) {
for (const field in fields) {
fieldNames.push(field);
if ((_b = (_a = fields === null || fields === void 0 ? void 0 : fields[field]) === null || _a === void 0 ? void 0 : _a.resolvedType) === null || _b === void 0 ? void 0 : _b.fields) {
getAllFieldNames(fields[field].resolvedType.fields, fieldNames);
}
}
}
return fieldNames;
}
function transcode(request, parsedOptions, requestFields) {

@@ -230,8 +252,13 @@ const { requiredFields, optionalFields } = getFieldNameOnBehavior(requestFields);

for (const requiredField of requiredFields) {
if (!(requiredField in request) || request[requiredField] === 'undefined') {
throw new Error(`Required field ${requiredField} is not present in the request.`);
if (!(requiredField in request) || request[requiredField] === undefined) {
throw new googleError_1.GoogleError(`Required field ${requiredField} is not present in the request.`);
}
}
// request is supposed to have keys in camelCase.
const snakeRequest = requestChangeCaseAndCleanup(request, util_1.camelToSnakeCase);
let fieldsToChange = undefined;
if (requestFields) {
fieldsToChange = getAllFieldNames(requestFields, []);
fieldsToChange = fieldsToChange === null || fieldsToChange === void 0 ? void 0 : fieldsToChange.map(x => (0, util_1.camelToSnakeCase)(x));
}
const snakeRequest = requestChangeCaseAndCleanup(request, util_1.camelToSnakeCase, new Set(fieldsToChange));
const httpRules = [];

@@ -258,3 +285,3 @@ for (const option of parsedOptions) {

const matchResult = match(snakeRequest, pathTemplate);
if (typeof matchResult === 'undefined') {
if (matchResult === undefined) {
continue;

@@ -272,3 +299,3 @@ }

if (optionalFields.has((0, util_1.toCamelCase)(key)) &&
(!(key in snakeRequest) || snakeRequest[key] === 'undefined')) {
(!(key in snakeRequest) || snakeRequest[key] === undefined)) {
delete data[key];

@@ -278,3 +305,4 @@ }

// HTTP endpoint expects camelCase but we have snake_case at this point
const camelCaseData = requestChangeCaseAndCleanup(data, util_1.toCamelCase);
fieldsToChange = fieldsToChange === null || fieldsToChange === void 0 ? void 0 : fieldsToChange.map(x => (0, util_1.toCamelCase)(x));
const camelCaseData = requestChangeCaseAndCleanup(data, util_1.toCamelCase, new Set(fieldsToChange));
return { httpMethod, url, queryString: '', data: camelCaseData };

@@ -290,3 +318,3 @@ }

data =
optionalFields.has(body) && snakeRequest[body] === 'undefined'
optionalFields.has(body) && snakeRequest[body] === undefined
? ''

@@ -300,3 +328,3 @@ : snakeRequest[body];

for (const key in queryStringObject) {
if (optionalFields.has(key) && request[key] === 'undefined') {
if (optionalFields.has(key) && request[key] === undefined) {
delete queryStringObject[key];

@@ -312,3 +340,4 @@ }

else {
camelCaseData = requestChangeCaseAndCleanup(data, util_1.toCamelCase);
fieldsToChange = fieldsToChange === null || fieldsToChange === void 0 ? void 0 : fieldsToChange.map(x => (0, util_1.toCamelCase)(x));
camelCaseData = requestChangeCaseAndCleanup(data, util_1.toCamelCase, new Set(fieldsToChange));
}

@@ -315,0 +344,0 @@ return { httpMethod, url, queryString, data: camelCaseData };

@@ -157,4 +157,5 @@ #!/usr/bin/env node

// is merged but not yet released.
if (!dts.match(/import \* as Long/)) {
dts = 'import * as Long from "long";\n' + dts;
dts = dts.replace('import * as Long from "long";', 'import Long = require("long");');
if (!dts.match(/import Long = require/)) {
dts = 'import Long = require("long");' + dts;
}

@@ -161,0 +162,0 @@ // 2. fix protobufjs import: we don't want the libraries to

{
"name": "google-gax",
"version": "3.1.4",
"version": "3.2.0",
"description": "Google API Extensions",

@@ -46,18 +46,6 @@ "main": "build/src/index.js",

"codecov": "^3.1.0",
"download": "^8.0.0",
"execa": "^5.0.0",
"file-loader": "^6.0.0",
"fs-extra": "^10.0.0",
"google-proto-files": "^3.0.0",
"gts": "^3.1.0",
"is-docker": "^3.0.0",
"json-loader": "^0.5.7",
"karma": "^6.0.0",
"karma-child-process": "^1.0.3",
"karma-chrome-launcher": "^3.0.0",
"karma-coverage": "^2.0.0",
"karma-mocha": "^2.0.0",
"karma-remap-coverage": "^0.1.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^5.0.0",
"linkinator": "^4.0.0",

@@ -71,10 +59,9 @@ "long": "^4.0.0",

"pumpify": "^2.0.0",
"puppeteer": "^15.0.0",
"rimraf": "^3.0.0",
"rimraf": "^3.0.2",
"sinon": "^14.0.0",
"stream-events": "^1.0.4",
"ts-loader": "^9.0.0",
"ts-loader": "^8.0.0",
"typescript": "^4.6.4",
"walkdir": "^0.4.0",
"webpack": "^5.0.0",
"webpack": "^4.0.0",
"webpack-cli": "^4.0.0"

@@ -98,7 +85,8 @@ },

"prepare": "npm run compile && node ./build/tools/prepublish.js && mkdirp build/protos && cp -r protos/* build/protos/",
"system-test": "c8 mocha build/test/system-test --timeout 600000",
"system-test": "c8 mocha build/test/system-test --timeout 600000 && npm run test-application",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"docs-test": "linkinator docs",
"predocs-test": "npm run docs",
"browser-test": "karma start",
"browser-test": "cd test/browser-test && npm run prefetch && npm install && npm test",
"test-application": "cd test/test-application && npm run prefetch && npm install && npm start",
"prelint": "cd samples; npm link ../; npm install",

@@ -105,0 +93,0 @@ "precompile": "gts clean",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc