From f551a24e75785ffc23faacc6c98376532323e40f Mon Sep 17 00:00:00 2001 From: Nikhil Verma Date: Thu, 21 Mar 2024 19:28:53 +0530 Subject: [PATCH] Add support for BoolValue --- examples/basic/basic.proto | 2 ++ examples/basic/protocol/basic.ts | 1 + package.json | 2 +- src/services.ts | 3 +++ src/utils.ts | 3 ++- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/basic/basic.proto b/examples/basic/basic.proto index 3480134..dc1bca3 100644 --- a/examples/basic/basic.proto +++ b/examples/basic/basic.proto @@ -38,6 +38,7 @@ import "google/protobuf/empty.proto"; import "google/protobuf/descriptor.proto"; import "google/protobuf/struct.proto"; import "google/protobuf/any.proto"; +import "google/protobuf/wrappers.proto"; package basic; @@ -83,6 +84,7 @@ message OptionalFields { repeated Nested a_repeated_message = 4; repeated string a_repeated_string = 5; optional google.protobuf.Any anyValue = 13; + optional google.protobuf.BoolValue boolValue = 14; } message HasExtensions { diff --git a/examples/basic/protocol/basic.ts b/examples/basic/protocol/basic.ts index a242ad1..8bed154 100644 --- a/examples/basic/protocol/basic.ts +++ b/examples/basic/protocol/basic.ts @@ -48,6 +48,7 @@ export interface OptionalFields { aRepeatedMessage?: OptionalFields_Nested[]; aRepeatedString?: string[]; anyValue?: unknown; + boolValue?: boolean; } export interface HasExtensions { diff --git a/package.json b/package.json index 7cdf54d..3bb928c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ollion/protobufjs-typescript-gen", - "version": "2.0.6", + "version": "2.0.7", "main": "dist/index.js", "author": "Nikhil Verma ", "license": "MIT", diff --git a/src/services.ts b/src/services.ts index 472f8c9..0b61e40 100644 --- a/src/services.ts +++ b/src/services.ts @@ -69,6 +69,9 @@ function getServiceTypeInfo( case '.google.protobuf.ListValue': return { code: 'any[]', import: null }; + case '.google.protobuf.BoolValue': + return { code: 'boolean', import: null }; + case '.google.protobuf.Struct': return { code: 'Record', import: null }; diff --git a/src/utils.ts b/src/utils.ts index 08b74ec..0936927 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -25,7 +25,7 @@ export function getCommentBlock(object: ReflectionObject) { export function getImport( object: ReflectionObject, targetObject: ReflectionObject | null, - options: ProtoGenOptions + options: ProtoGenOptions, ) { if (!targetObject) { return null; @@ -126,6 +126,7 @@ export function fieldToTypescriptType(field: FieldBase, options: ProtoGenOptions break; case 'bool': + case 'google.protobuf.BoolValue': type = 'boolean'; break;