google-gax
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -27,2 +27,3 @@ /** | ||
import { FallbackServiceError } from './googleError'; | ||
import { google } from '../protos/http'; | ||
export { FallbackServiceError }; | ||
@@ -52,2 +53,3 @@ export { PathTemplate } from './pathTemplate'; | ||
private static protoCache; | ||
httpRules?: Array<google.api.IHttpRule>; | ||
/** | ||
@@ -54,0 +56,0 @@ * In rare cases users might need to deallocate all memory consumed by loaded protos. |
@@ -80,2 +80,3 @@ "use strict"; | ||
this.grpcVersion = require('../../package.json').version; | ||
this.httpRules = options.httpRules; | ||
} | ||
@@ -248,4 +249,7 @@ /** | ||
options = Object.assign({ scopes: [] }, options); | ||
if (options.protoJson) { | ||
options = Object.assign(options, { fallback: 'rest' }); | ||
} | ||
const gaxGrpc = new GrpcClient(options); | ||
return new operationsClient_1.OperationsClientBuilder(gaxGrpc); | ||
return new operationsClient_1.OperationsClientBuilder(gaxGrpc, options.protoJson); | ||
} | ||
@@ -252,0 +256,0 @@ exports.lro = lro; |
@@ -24,5 +24,8 @@ /** | ||
import { ClientOptions } from '@grpc/grpc-js/build/src/client'; | ||
import { google } from '../protos/http'; | ||
export interface GrpcClientOptions extends GoogleAuthOptions { | ||
auth?: GoogleAuth; | ||
grpc?: GrpcModule; | ||
protoJson?: protobuf.Root; | ||
httpRules?: Array<google.api.IHttpRule>; | ||
} | ||
@@ -58,2 +61,3 @@ export interface MetadataValue { | ||
private static protoCache; | ||
httpRules?: Array<google.api.IHttpRule>; | ||
/** | ||
@@ -60,0 +64,0 @@ * Key for proto cache map. We are doing our best to make sure we respect |
@@ -315,3 +315,3 @@ /** | ||
*/ | ||
constructor(gaxGrpc: GrpcClient | FallbackGrpcClient); | ||
constructor(gaxGrpc: GrpcClient | FallbackGrpcClient, protoJson?: protobuf.Root); | ||
} |
@@ -23,3 +23,4 @@ "use strict"; | ||
const configData = require("./operations_client_config.json"); | ||
const protoJson = require("../protos/operations.json"); | ||
const operationProtoJson = require("../protos/operations.json"); | ||
const transcoding_1 = require("./transcoding"); | ||
exports.SERVICE_ADDRESS = 'longrunning.googleapis.com'; | ||
@@ -420,5 +421,8 @@ const version = require('../../package.json').version; | ||
*/ | ||
constructor(gaxGrpc) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const operationsProtos = gaxGrpc.loadProtoJSON(protoJson); | ||
constructor(gaxGrpc, protoJson) { | ||
if (protoJson && gaxGrpc.httpRules) { | ||
// overwrite the http rules if provide in service yaml. | ||
(0, transcoding_1.overrideHttpRules)(gaxGrpc.httpRules, protoJson); | ||
} | ||
const operationsProtos = protoJson !== null && protoJson !== void 0 ? protoJson : gaxGrpc.loadProtoJSON(operationProtoJson); | ||
/** | ||
@@ -435,3 +439,3 @@ * Build a new instance of {@link OperationsClient}. | ||
if (gaxGrpc.fallback) { | ||
opts.fallback = true; | ||
opts.fallback = gaxGrpc.fallback; | ||
} | ||
@@ -438,0 +442,0 @@ return new OperationsClient(gaxGrpc, operationsProtos, opts); |
@@ -57,2 +57,3 @@ /** | ||
}): TranscodedRequest | undefined; | ||
export declare function overrideHttpRules(httpRules: Array<google.api.IHttpRule>, protoJson: protobuf.Root): void; | ||
export {}; |
@@ -18,3 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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; | ||
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 util_1 = require("./util"); | ||
@@ -309,2 +309,41 @@ const httpOptionName = '(google.api.http)'; | ||
exports.transcode = transcode; | ||
// Override the protobuf json's the http rules. | ||
function overrideHttpRules(httpRules, protoJson) { | ||
for (const rule of httpRules) { | ||
if (!rule.selector) { | ||
continue; | ||
} | ||
const rpc = protoJson.lookup(rule.selector); | ||
// Not support override on non-exist RPC or a RPC without an annotation. | ||
// We could reconsider if we have the use case later. | ||
if (!rpc || !rpc.parsedOptions) { | ||
continue; | ||
} | ||
for (const item of rpc.parsedOptions) { | ||
if (!(httpOptionName in item)) { | ||
continue; | ||
} | ||
const httpOptions = item[httpOptionName]; | ||
for (const httpMethod in httpOptions) { | ||
if (httpMethod in rule) { | ||
if (httpMethod === 'additional_bindings') { | ||
continue; | ||
} | ||
httpOptions[httpMethod] = | ||
rule[httpMethod]; | ||
} | ||
if (rule.additional_bindings) { | ||
httpOptions['additional_bindings'] = !httpOptions['additional_bindings'] | ||
? [] | ||
: Array.isArray(httpOptions['additional_bindings']) | ||
? httpOptions['additional_bindings'] | ||
: [httpOptions['additional_bindings']]; | ||
// Make the additional_binding to be an array if it is not. | ||
httpOptions['additional_bindings'].push(...rule.additional_bindings); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
exports.overrideHttpRules = overrideHttpRules; | ||
//# sourceMappingURL=transcoding.js.map |
{ | ||
"name": "google-gax", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "Google API Extensions", | ||
@@ -5,0 +5,0 @@ "main": "build/src/index.js", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5793504
86645