google-gax
Advanced tools
Comparing version 3.3.1 to 3.3.2-pre
@@ -40,3 +40,3 @@ "use strict"; | ||
} | ||
const transcoded = (0, transcoding_1.transcode)(json, rpc.parsedOptions, rpc.resolvedRequestType.fields); | ||
const transcoded = (0, transcoding_1.transcode)(json, rpc.parsedOptions, rpc.resolvedRequestType); | ||
if (!transcoded) { | ||
@@ -43,0 +43,0 @@ throw new Error(`Cannot build HTTP request for ${JSON.stringify(json)}, method: ${rpc.name}`); |
@@ -17,3 +17,3 @@ /** | ||
import { JSONObject, JSONValue } from 'proto3-json-serializer'; | ||
import { Field } from 'protobufjs'; | ||
import { Field, Type } from 'protobufjs'; | ||
import { google } from '../protos/http'; | ||
@@ -49,12 +49,8 @@ export interface TranscodedRequest { | ||
export declare function isRequiredField(field: Field): boolean | undefined; | ||
export declare function getFieldNameOnBehavior(fields: { | ||
[k: string]: Field; | ||
} | undefined): { | ||
export declare function getFieldNameOnBehavior(requestType?: Type): { | ||
requiredFields: Set<string>; | ||
optionalFields: Set<string>; | ||
}; | ||
export declare function transcode(request: JSONObject, parsedOptions: ParsedOptionsType, requestFields?: { | ||
[k: string]: Field; | ||
}): TranscodedRequest | undefined; | ||
export declare function transcode(request: JSONObject, parsedOptions: ParsedOptionsType, requestType?: Type | null): TranscodedRequest | undefined; | ||
export declare function overrideHttpRules(httpRules: Array<google.api.IHttpRule>, protoJson: protobuf.Root): void; | ||
export {}; |
@@ -214,11 +214,12 @@ "use strict"; | ||
exports.isRequiredField = isRequiredField; | ||
function getFieldNameOnBehavior(fields) { | ||
function getFieldNameOnBehavior(requestType) { | ||
var _a; | ||
const requiredFields = new Set(); | ||
const optionalFields = new Set(); | ||
for (const fieldName in fields) { | ||
const field = fields[fieldName]; | ||
if (isRequiredField(field)) { | ||
for (const fieldName in (_a = requestType === null || requestType === void 0 ? void 0 : requestType.fields) !== null && _a !== void 0 ? _a : []) { | ||
const field = requestType === null || requestType === void 0 ? void 0 : requestType.fields[fieldName]; | ||
if (field && isRequiredField(field)) { | ||
requiredFields.add(fieldName); | ||
} | ||
if (isProto3OptionalField(field)) { | ||
if (field && isProto3OptionalField(field)) { | ||
optionalFields.add(fieldName); | ||
@@ -230,10 +231,27 @@ } | ||
exports.getFieldNameOnBehavior = getFieldNameOnBehavior; | ||
// Get fully qualified protobuf type name | ||
function getFullyQualifiedTypeName(type) { | ||
const parts = []; | ||
while (type && type.name) { | ||
parts.unshift(type.name); | ||
type = type.parent; | ||
} | ||
return parts.join('.'); | ||
} | ||
// This function gets all the fields recursively | ||
function getAllFieldNames(fields, fieldNames) { | ||
var _a, _b; | ||
if (fields) { | ||
for (const field in fields) { | ||
function getAllFieldNames(type, fieldNames, visited) { | ||
var _a, _b, _c; | ||
if (!type) { | ||
return fieldNames; | ||
} | ||
const name = getFullyQualifiedTypeName(type); | ||
if (visited.has(name)) { | ||
return fieldNames; | ||
} | ||
visited.add(name); | ||
if ('fields' in type && type.fields) { | ||
for (const field in type.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); | ||
if ((_c = (_b = (_a = type.fields) === null || _a === void 0 ? void 0 : _a[field]) === null || _b === void 0 ? void 0 : _b.resolvedType) === null || _c === void 0 ? void 0 : _c.fields) { | ||
getAllFieldNames(type.fields[field].resolvedType, fieldNames, visited); | ||
} | ||
@@ -244,4 +262,4 @@ } | ||
} | ||
function transcode(request, parsedOptions, requestFields) { | ||
const { requiredFields, optionalFields } = getFieldNameOnBehavior(requestFields); | ||
function transcode(request, parsedOptions, requestType) { | ||
const { requiredFields, optionalFields } = getFieldNameOnBehavior(requestType !== null && requestType !== void 0 ? requestType : undefined); | ||
// all fields annotated as REQUIRED MUST be emitted in the body. | ||
@@ -255,4 +273,4 @@ for (const requiredField of requiredFields) { | ||
let fieldsToChange = undefined; | ||
if (requestFields) { | ||
fieldsToChange = getAllFieldNames(requestFields, []); | ||
if (requestType === null || requestType === void 0 ? void 0 : requestType.fields) { | ||
fieldsToChange = getAllFieldNames(requestType, [], new Set()); | ||
fieldsToChange = fieldsToChange === null || fieldsToChange === void 0 ? void 0 : fieldsToChange.map(x => (0, util_1.camelToSnakeCase)(x)); | ||
@@ -259,0 +277,0 @@ } |
{ | ||
"name": "google-gax", | ||
"version": "3.3.1", | ||
"version": "3.3.2-pre", | ||
"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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
86874
5739975
275
1