diff --git a/src/descriptor.ts b/src/descriptor.ts index 3153c11..2d8d849 100644 --- a/src/descriptor.ts +++ b/src/descriptor.ts @@ -618,76 +618,6 @@ function createMessageSignature( return ts.factory.createTypeLiteralNode(fieldSignatures); } -function createPrimitiveMessageSignature( - rootDescriptor: descriptor.FileDescriptorProto, - messageDescriptor: descriptor.DescriptorProto, -) { - const fieldSignatures = []; - - const wrapMessageType = ( - fieldType: ts.TypeReferenceNode, - ): ts.TypeReferenceNode => { - const type = ts.factory.createTypeQueryNode( - ts.factory.createQualifiedName( - ts.factory.createQualifiedName(fieldType.typeName, "prototype"), - "toObject", - ), - ); - return ts.factory.createTypeReferenceNode("ReturnType", [type]); - }; - - for (const fieldDescriptor of messageDescriptor.field) { - let fieldType: ts.TypeNode = field.getType(fieldDescriptor, rootDescriptor); - - if (field.isMap(fieldDescriptor)) { - const [keyDescriptor, valueDescriptor] = type.getMapDescriptor( - fieldDescriptor.type_name, - )!.field; - - let valueType = field.getType(valueDescriptor, rootDescriptor); - - if (field.isMessage(valueDescriptor)) { - valueType = wrapMessageType(valueType); - } - - fieldType = ts.factory.createTypeLiteralNode([ - ts.factory.createIndexSignature( - undefined, - [ - ts.factory.createParameterDeclaration( - undefined, - undefined, - "key", - undefined, - field.getType(keyDescriptor, rootDescriptor), - ), - ], - valueType as ts.TypeNode, - ), - ]); - } else if (field.isMessage(fieldDescriptor)) { - fieldType = wrapMessageType(fieldType as ts.TypeReferenceNode); - } - - fieldSignatures.push( - ts.factory.createPropertySignature( - undefined, - getFieldName(fieldDescriptor), - ( - field.isOptional(rootDescriptor, fieldDescriptor) || - field.isMessage(fieldDescriptor) || - field.isRequiredWithoutExplicitDefault(rootDescriptor, fieldDescriptor) - ) - ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) - : undefined, - field.wrapRepeatedType(fieldType as ts.TypeNode, fieldDescriptor), - ), - ); - } - - return ts.factory.createTypeLiteralNode(fieldSignatures); -} - function getPivot(descriptor: descriptor.DescriptorProto) { const kDefaultPivot = 500; let max_field_number = 0;