Comparing version
@@ -496,5 +496,8 @@ "use strict"; | ||
const nameMatches = methodDesc.name.startsWith('Batch'); | ||
const inputTypeDesc = fileDesc.messageType.find(m => `.${fileDesc.package}.${m.name}` === methodDesc.inputType); | ||
const outputTypeDesc = fileDesc.messageType.find(m => `.${fileDesc.package}.${m.name}` === methodDesc.outputType); | ||
if (nameMatches && inputTypeDesc && outputTypeDesc) { | ||
const inputType = typeMap.get(methodDesc.inputType.substring(1)); // drop the `.` prefix | ||
const outputType = typeMap.get(methodDesc.outputType.substring(1)); | ||
if (nameMatches && inputType && outputType) { | ||
// TODO: This might be enums? | ||
const inputTypeDesc = inputType[2]; | ||
const outputTypeDesc = outputType[2]; | ||
if (hasSingleRepeatedField(inputTypeDesc) && hasSingleRepeatedField(outputTypeDesc)) { | ||
@@ -501,0 +504,0 @@ const singleMethodName = methodDesc.name.replace('Batch', 'Get'); |
@@ -189,4 +189,4 @@ "use strict"; | ||
// So given a fullName like FooMessage_InnerMessage, proto will see that as package.name.FooMessage.InnerMessage | ||
function saveMapping(fullName) { | ||
typeMap.set(file.package + '.' + fullName.replace(/_/g, '.'), [moduleName, fullName]); | ||
function saveMapping(fullName, desc) { | ||
typeMap.set(file.package + '.' + fullName.replace(/_/g, '.'), [moduleName, fullName, desc]); | ||
} | ||
@@ -256,3 +256,3 @@ main_1.visit(file, saveMapping, saveMapping); | ||
exports.messageToTypeName = messageToTypeName; | ||
/** Breaks `.some_proto_namespace.Some.Message` into `['some_proto_namespace', 'Some_Message']. */ | ||
/** Breaks `.some_proto_namespace.Some.Message` into `['some_proto_namespace', 'Some_Message', Descriptor]. */ | ||
function toModuleAndType(typeMap, protoType) { | ||
@@ -259,0 +259,0 @@ return typeMap.get(protoType.substring(1)) || utils_1.fail(`No type found for ${protoType}`); |
{ | ||
"name": "ts-proto", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/plugin.js", |
@@ -642,5 +642,8 @@ import { | ||
const nameMatches = methodDesc.name.startsWith('Batch'); | ||
const inputTypeDesc = fileDesc.messageType.find(m => `.${fileDesc.package}.${m.name}` === methodDesc.inputType); | ||
const outputTypeDesc = fileDesc.messageType.find(m => `.${fileDesc.package}.${m.name}` === methodDesc.outputType); | ||
if (nameMatches && inputTypeDesc && outputTypeDesc) { | ||
const inputType = typeMap.get(methodDesc.inputType.substring(1)); // drop the `.` prefix | ||
const outputType = typeMap.get(methodDesc.outputType.substring(1)); | ||
if (nameMatches && inputType && outputType) { | ||
// TODO: This might be enums? | ||
const inputTypeDesc = inputType[2] as DescriptorProto; | ||
const outputTypeDesc= outputType[2] as DescriptorProto; | ||
if (hasSingleRepeatedField(inputTypeDesc) && hasSingleRepeatedField(outputTypeDesc)) { | ||
@@ -647,0 +650,0 @@ const singleMethodName = methodDesc.name.replace('Batch', 'Get'); |
@@ -8,2 +8,3 @@ import { google } from '../build/pbjs'; | ||
import CodeGeneratorRequest = google.protobuf.compiler.CodeGeneratorRequest; | ||
import EnumDescriptorProto = google.protobuf.EnumDescriptorProto; | ||
import DescriptorProto = google.protobuf.DescriptorProto; | ||
@@ -185,7 +186,7 @@ | ||
/** A map of proto type name, e.g. `foo.Message.Inner`, to module/class name, e.g. `foo`, `Message_Inner`. */ | ||
export type TypeMap = Map<string, [string, string]>; | ||
export type TypeMap = Map<string, [string, string, DescriptorProto | EnumDescriptorProto]>; | ||
/** Scans all of the proto files in `request` and builds a map of proto typeName -> TS module/name. */ | ||
export function createTypeMap(request: CodeGeneratorRequest): TypeMap { | ||
const typeMap = new Map<string, [string, string]>(); | ||
const typeMap: TypeMap = new Map(); | ||
for (const file of request.protoFile) { | ||
@@ -195,4 +196,4 @@ // We assume a file.name of google/protobuf/wrappers.proto --> a module path of google/protobuf/wrapper.ts | ||
// So given a fullName like FooMessage_InnerMessage, proto will see that as package.name.FooMessage.InnerMessage | ||
function saveMapping(fullName: string): void { | ||
typeMap.set(file.package + '.' + fullName.replace(/_/g, '.'), [moduleName, fullName]); | ||
function saveMapping(fullName: string, desc: DescriptorProto | EnumDescriptorProto): void { | ||
typeMap.set(file.package + '.' + fullName.replace(/_/g, '.'), [moduleName, fullName, desc]); | ||
} | ||
@@ -264,4 +265,4 @@ visit(file, saveMapping, saveMapping); | ||
/** Breaks `.some_proto_namespace.Some.Message` into `['some_proto_namespace', 'Some_Message']. */ | ||
function toModuleAndType(typeMap: TypeMap, protoType: string): [string, string] { | ||
/** Breaks `.some_proto_namespace.Some.Message` into `['some_proto_namespace', 'Some_Message', Descriptor]. */ | ||
function toModuleAndType(typeMap: TypeMap, protoType: string): [string, string, DescriptorProto | EnumDescriptorProto] { | ||
return typeMap.get(protoType.substring(1)) || fail(`No type found for ${protoType}`); | ||
@@ -268,0 +269,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
824208
0.05%11789
0.06%97
2.11%