grpc_tools_node_protoc_ts
Advanced tools
Comparing version 5.1.3 to 5.2.0
@@ -23,2 +23,3 @@ "use strict"; | ||
const fileNameToDescriptor = {}; | ||
codeGenResponse.setSupportedFeatures(plugin_pb_1.CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL); | ||
const isGrpcJs = ["generate_package_definition", "grpc_js"].indexOf(codeGenRequest.getParameter()) !== -1; | ||
@@ -25,0 +26,0 @@ codeGenRequest.getProtoFileList().forEach((protoFileDescriptor) => { |
@@ -43,2 +43,5 @@ "use strict"; | ||
} | ||
if (field.hasProto3Optional()) { | ||
return true; | ||
} | ||
if (field.hasOneofIndex()) { | ||
@@ -55,4 +58,13 @@ return true; | ||
const messageData = JSON.parse(MessageFormatter.defaultMessageType); | ||
const proto3OptionalFields = new Set(); | ||
descriptor.getFieldList().forEach((field) => { | ||
if (field.hasName() && field.hasProto3Optional()) { | ||
proto3OptionalFields.add(field.getName()); | ||
} | ||
}); | ||
messageData.messageName = descriptor.getName(); | ||
messageData.oneofDeclList = descriptor.getOneofDeclList(); | ||
messageData.oneofDeclList = descriptor.getOneofDeclList().filter((oneOfDecl) => { | ||
const name = oneOfDecl.getName(); | ||
return !(name && name.length > 1 && proto3OptionalFields.has(name.substring(1))); | ||
}); | ||
const messageOptions = descriptor.getOptions(); | ||
@@ -160,2 +172,5 @@ if (messageOptions !== undefined && messageOptions.getMapEntry()) { | ||
} | ||
else if (field.getProto3Optional()) { | ||
canBeUndefined = true; | ||
} | ||
else { | ||
@@ -183,2 +198,7 @@ if (Utility_1.Utility.isProto2(fileDescriptor)) { | ||
descriptor.getOneofDeclList().forEach((oneOfDecl, index) => { | ||
const name = oneOfDecl.getName(); | ||
if (name && name.length > 1 && proto3OptionalFields.has(name.substring(1))) { | ||
// Skip synthetic one-ofs for proto3 optional fields | ||
return; | ||
} | ||
messageData.formattedOneofListStr.push(OneofFormatter_1.OneofFormatter.format(oneOfDecl, oneofGroups[index] || [], nextIndent)); | ||
@@ -185,0 +205,0 @@ }); |
{ | ||
"name": "grpc_tools_node_protoc_ts", | ||
"version": "5.1.3", | ||
"version": "5.2.0", | ||
"description": "Generate d.ts definitions for generated js files from grpc_tools_node_protoc", | ||
@@ -31,3 +31,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"google-protobuf": "3.12.4", | ||
"google-protobuf": "3.15.8", | ||
"handlebars": "4.7.6", | ||
@@ -37,3 +37,3 @@ "handlebars-helpers": "0.10.0" | ||
"devDependencies": { | ||
"@types/google-protobuf": "3.7.2", | ||
"@types/google-protobuf": "3.7.4", | ||
"@types/node": "14.14.16", | ||
@@ -40,0 +40,0 @@ "tslint": "5.9.1", |
246
README.md
@@ -31,2 +31,5 @@ grpc_tools_node_protoc_ts | ||
## Breaking changes | ||
### v5.2.0 | ||
Add support for proto3 `optional`. `grpc-tools` version of `1.11.1` is `REQUIRED`. See: [Issue#88](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/88) and [PR#97](https://github.com/agreatfool/grpc_tools_node_protoc_ts/pull/97). | ||
### v5.1.0 | ||
@@ -87,3 +90,3 @@ Fix server implementation signature issue of `grpc_js` side. See: [Issue#79](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/79). | ||
### book.proto | ||
### examples/proto/book.proto | ||
```proto | ||
@@ -151,5 +154,35 @@ syntax = "proto3"; | ||
} | ||
message ExtMsgString { | ||
string extension = 1; | ||
} | ||
message ExtMsgList { | ||
repeated string extension = 1; | ||
} | ||
message ExtMsgByte { | ||
bytes extension = 1; | ||
} | ||
message ExtMsgByteList { | ||
repeated bytes extension = 1; | ||
} | ||
message ExtMsgMap { | ||
map<string, string> extension = 1; | ||
} | ||
message ExtMsgOneOf { | ||
oneof ext { | ||
string extension = 1; | ||
} | ||
} | ||
message OptTest { | ||
optional string name = 1; | ||
} | ||
``` | ||
### book_pb.d.ts | ||
### examples/grpcjs/proto/book_pb.d.ts | ||
```typescript | ||
@@ -167,10 +200,7 @@ // package: com.book | ||
setIsbn(value: number): Book; | ||
getTitle(): string; | ||
setTitle(value: string): Book; | ||
getAuthor(): string; | ||
setAuthor(value: string): Book; | ||
serializeBinary(): Uint8Array; | ||
@@ -198,3 +228,2 @@ toObject(includeInstance?: boolean): Book.AsObject; | ||
serializeBinary(): Uint8Array; | ||
@@ -220,3 +249,2 @@ toObject(includeInstance?: boolean): GetBookRequest.AsObject; | ||
serializeBinary(): Uint8Array; | ||
@@ -242,7 +270,5 @@ toObject(includeInstance?: boolean): GetBookViaAuthor.AsObject; | ||
getBooksMap(): jspb.Map<number, string>; | ||
clearBooksMap(): void; | ||
serializeBinary(): Uint8Array; | ||
@@ -269,13 +295,9 @@ toObject(includeInstance?: boolean): BookStore.AsObject; | ||
setNormal(value: string): SpecialCases; | ||
getDefault(): string; | ||
setDefault(value: string): SpecialCases; | ||
getFunction(): string; | ||
setFunction(value: string): SpecialCases; | ||
getVar(): string; | ||
setVar(value: string): SpecialCases; | ||
serializeBinary(): Uint8Array; | ||
@@ -307,3 +329,2 @@ toObject(includeInstance?: boolean): SpecialCases.AsObject; | ||
hasB1(): boolean; | ||
@@ -314,3 +335,2 @@ clearB1(): void; | ||
hasA2(): boolean; | ||
@@ -321,3 +341,2 @@ clearA2(): void; | ||
hasB2(): boolean; | ||
@@ -328,3 +347,2 @@ clearB2(): void; | ||
getSinglewordCase(): OneOfSample.SinglewordCase; | ||
@@ -353,7 +371,4 @@ getTwoWordsCase(): OneOfSample.TwoWordsCase; | ||
SINGLEWORD_NOT_SET = 0, | ||
A1 = 1, | ||
B1 = 2, | ||
A1 = 1, | ||
B1 = 2, | ||
} | ||
@@ -363,11 +378,172 @@ | ||
TWO_WORDS_NOT_SET = 0, | ||
A_2 = 3, | ||
A_2 = 3, | ||
B_2 = 4, | ||
} | ||
B_2 = 4, | ||
} | ||
export class ExtMsgString extends jspb.Message { | ||
getExtension$(): string; | ||
setExtension$(value: string): ExtMsgString; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ExtMsgString.AsObject; | ||
static toObject(includeInstance: boolean, msg: ExtMsgString): ExtMsgString.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ExtMsgString, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ExtMsgString; | ||
static deserializeBinaryFromReader(message: ExtMsgString, reader: jspb.BinaryReader): ExtMsgString; | ||
} | ||
export namespace ExtMsgString { | ||
export type AsObject = { | ||
extension: string, | ||
} | ||
} | ||
export class ExtMsgList extends jspb.Message { | ||
clearExtensionList(): void; | ||
getExtensionList(): Array<string>; | ||
setExtensionList(value: Array<string>): ExtMsgList; | ||
addExtension$(value: string, index?: number): string; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ExtMsgList.AsObject; | ||
static toObject(includeInstance: boolean, msg: ExtMsgList): ExtMsgList.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ExtMsgList, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ExtMsgList; | ||
static deserializeBinaryFromReader(message: ExtMsgList, reader: jspb.BinaryReader): ExtMsgList; | ||
} | ||
export namespace ExtMsgList { | ||
export type AsObject = { | ||
extensionList: Array<string>, | ||
} | ||
} | ||
export class ExtMsgByte extends jspb.Message { | ||
getExtension$(): Uint8Array | string; | ||
getExtension_asU8(): Uint8Array; | ||
getExtension_asB64(): string; | ||
setExtension$(value: Uint8Array | string): ExtMsgByte; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ExtMsgByte.AsObject; | ||
static toObject(includeInstance: boolean, msg: ExtMsgByte): ExtMsgByte.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ExtMsgByte, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ExtMsgByte; | ||
static deserializeBinaryFromReader(message: ExtMsgByte, reader: jspb.BinaryReader): ExtMsgByte; | ||
} | ||
export namespace ExtMsgByte { | ||
export type AsObject = { | ||
extension: Uint8Array | string, | ||
} | ||
} | ||
export class ExtMsgByteList extends jspb.Message { | ||
clearExtensionList(): void; | ||
getExtensionList(): Array<Uint8Array | string>; | ||
getExtensionList_asU8(): Array<Uint8Array>; | ||
getExtensionList_asB64(): Array<string>; | ||
setExtensionList(value: Array<Uint8Array | string>): ExtMsgByteList; | ||
addExtension$(value: Uint8Array | string, index?: number): Uint8Array | string; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ExtMsgByteList.AsObject; | ||
static toObject(includeInstance: boolean, msg: ExtMsgByteList): ExtMsgByteList.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ExtMsgByteList, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ExtMsgByteList; | ||
static deserializeBinaryFromReader(message: ExtMsgByteList, reader: jspb.BinaryReader): ExtMsgByteList; | ||
} | ||
export namespace ExtMsgByteList { | ||
export type AsObject = { | ||
extensionList: Array<Uint8Array | string>, | ||
} | ||
} | ||
export class ExtMsgMap extends jspb.Message { | ||
getExtensionMap(): jspb.Map<string, string>; | ||
clearExtensionMap(): void; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ExtMsgMap.AsObject; | ||
static toObject(includeInstance: boolean, msg: ExtMsgMap): ExtMsgMap.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ExtMsgMap, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ExtMsgMap; | ||
static deserializeBinaryFromReader(message: ExtMsgMap, reader: jspb.BinaryReader): ExtMsgMap; | ||
} | ||
export namespace ExtMsgMap { | ||
export type AsObject = { | ||
extensionMap: Array<[string, string]>, | ||
} | ||
} | ||
export class ExtMsgOneOf extends jspb.Message { | ||
hasExtension$(): boolean; | ||
clearExtension$(): void; | ||
getExtension$(): string; | ||
setExtension$(value: string): ExtMsgOneOf; | ||
getExtCase(): ExtMsgOneOf.ExtCase; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): ExtMsgOneOf.AsObject; | ||
static toObject(includeInstance: boolean, msg: ExtMsgOneOf): ExtMsgOneOf.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: ExtMsgOneOf, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): ExtMsgOneOf; | ||
static deserializeBinaryFromReader(message: ExtMsgOneOf, reader: jspb.BinaryReader): ExtMsgOneOf; | ||
} | ||
export namespace ExtMsgOneOf { | ||
export type AsObject = { | ||
extension: string, | ||
} | ||
export enum ExtCase { | ||
EXT_NOT_SET = 0, | ||
EXTENSION = 1, | ||
} | ||
} | ||
export class OptTest extends jspb.Message { | ||
hasName(): boolean; | ||
clearName(): void; | ||
getName(): string | undefined; | ||
setName(value: string): OptTest; | ||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): OptTest.AsObject; | ||
static toObject(includeInstance: boolean, msg: OptTest): OptTest.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: OptTest, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): OptTest; | ||
static deserializeBinaryFromReader(message: OptTest, reader: jspb.BinaryReader): OptTest; | ||
} | ||
export namespace OptTest { | ||
export type AsObject = { | ||
name?: string, | ||
} | ||
} | ||
export enum EnumSample { | ||
@@ -383,3 +559,3 @@ UNKNOWN = 0, | ||
### book_grpc_pb.d.ts | ||
### examples/grpcjs/proto/book_grpc_pb.d.ts | ||
```typescript | ||
@@ -392,3 +568,4 @@ // package: com.book | ||
import * as grpc from "grpc"; | ||
import * as grpc from "@grpc/grpc-js"; | ||
import {handleClientStreamingCall} from "@grpc/grpc-js/build/src/server-call"; | ||
import * as book_pb from "./book_pb"; | ||
@@ -442,6 +619,6 @@ | ||
export interface IBookServiceServer { | ||
export interface IBookServiceServer extends grpc.UntypedServiceImplementation { | ||
getBook: grpc.handleUnaryCall<book_pb.GetBookRequest, book_pb.Book>; | ||
getBooksViaAuthor: grpc.handleServerStreamingCall<book_pb.GetBookViaAuthor, book_pb.Book>; | ||
getGreatestBook: grpc.handleClientStreamingCall<book_pb.GetBookRequest, book_pb.Book>; | ||
getGreatestBook: handleClientStreamingCall<book_pb.GetBookRequest, book_pb.Book>; | ||
getBooks: grpc.handleBidiStreamingCall<book_pb.GetBookRequest, book_pb.Book>; | ||
@@ -466,3 +643,3 @@ } | ||
export class BookServiceClient extends grpc.Client implements IBookServiceClient { | ||
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); | ||
constructor(address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ClientOptions>); | ||
public getBook(request: book_pb.GetBookRequest, callback: (error: grpc.ServiceError | null, response: book_pb.Book) => void): grpc.ClientUnaryCall; | ||
@@ -483,2 +660,11 @@ public getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: book_pb.Book) => void): grpc.ClientUnaryCall; | ||
## Changes | ||
### 5.2.0 | ||
Add support for proto3 `optional`. `grpc-tools` version `1.11.1` is `RQUIRED`. See: [Issue#88](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/88) and [PR#97](https://github.com/agreatfool/grpc_tools_node_protoc_ts/pull/97). | ||
Some info: | ||
- google-protobuf changes: https://github.com/protocolbuffers/protobuf/blob/master/CHANGES.txt | ||
- google-protobuf releases: https://github.com/protocolbuffers/protobuf/releases | ||
- grpc-tools releases: https://github.com/grpc/grpc-node/releases | ||
### 5.1.3 | ||
@@ -485,0 +671,0 @@ Fix wrong publishing, 5.1.2 contains some temp compiled codes. See: [Issue#89](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/89). |
@@ -27,2 +27,4 @@ /** | ||
codeGenResponse.setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL); | ||
const isGrpcJs = ["generate_package_definition", "grpc_js"].indexOf(codeGenRequest.getParameter()) !== -1; | ||
@@ -29,0 +31,0 @@ |
@@ -93,2 +93,6 @@ import { | ||
if (field.hasProto3Optional()) { | ||
return true; | ||
} | ||
if (field.hasOneofIndex()) { | ||
@@ -114,4 +118,14 @@ return true; | ||
const proto3OptionalFields = new Set<string>(); | ||
descriptor.getFieldList().forEach((field) => { | ||
if (field.hasName() && field.hasProto3Optional()) { | ||
proto3OptionalFields.add(field.getName()); | ||
} | ||
}); | ||
messageData.messageName = descriptor.getName(); | ||
messageData.oneofDeclList = descriptor.getOneofDeclList(); | ||
messageData.oneofDeclList = descriptor.getOneofDeclList().filter((oneOfDecl) => { | ||
const name = oneOfDecl.getName(); | ||
return !(name && name.length > 1 && proto3OptionalFields.has(name.substring(1))); | ||
}); | ||
const messageOptions = descriptor.getOptions(); | ||
@@ -232,2 +246,4 @@ if (messageOptions !== undefined && messageOptions.getMapEntry()) { | ||
} | ||
} else if (field.getProto3Optional()) { | ||
canBeUndefined = true; | ||
} else { | ||
@@ -258,2 +274,7 @@ if (Utility.isProto2(fileDescriptor)) { | ||
descriptor.getOneofDeclList().forEach((oneOfDecl, index) => { | ||
const name = oneOfDecl.getName(); | ||
if (name && name.length > 1 && proto3OptionalFields.has(name.substring(1))) { | ||
// Skip synthetic one-ofs for proto3 optional fields | ||
return; | ||
} | ||
messageData.formattedOneofListStr.push(OneofFormatter.format(oneOfDecl, oneofGroups[index] || [], nextIndent)); | ||
@@ -260,0 +281,0 @@ }); |
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
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
382060
73
1841
896
+ Addedgoogle-protobuf@3.15.8(transitive)
- Removedgoogle-protobuf@3.12.4(transitive)
Updatedgoogle-protobuf@3.15.8