-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for generating grpc-node service types (#193)
* Run protoc twice, with and without service=true * Use service=grpc-web instead of service=true * Extract common code from service/grpcweb.ts * Add support for service=grpc-node option * Update yarn.lock * Add additional grpcnode.ts tests * Tests ready for review * Warn when using deprecated service=true parameter
- Loading branch information
1 parent
7a65c0d
commit 005b479
Showing
165 changed files
with
27,794 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/generated-grpc-node/proto/examplecom/annotations_grpc_pb.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// GENERATED CODE -- NO SERVICES IN PROTO |
1 change: 1 addition & 0 deletions
1
examples/generated-grpc-node/proto/examplecom/annotations_grpc_pb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// GENERATED CODE -- NO SERVICES IN PROTO |
41 changes: 41 additions & 0 deletions
41
examples/generated-grpc-node/proto/examplecom/annotations_pb.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// package: examplecom | ||
// file: proto/examplecom/annotations.proto | ||
|
||
import * as jspb from "google-protobuf"; | ||
|
||
export class AnnotatedMessage extends jspb.Message { | ||
getMyunit64(): string; | ||
setMyunit64(value: string): void; | ||
|
||
getMyint64(): string; | ||
setMyint64(value: string): void; | ||
|
||
getMyfixed64(): string; | ||
setMyfixed64(value: string): void; | ||
|
||
getMysint64(): string; | ||
setMysint64(value: string): void; | ||
|
||
getMysfixed64(): string; | ||
setMysfixed64(value: string): void; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): AnnotatedMessage.AsObject; | ||
static toObject(includeInstance: boolean, msg: AnnotatedMessage): AnnotatedMessage.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: AnnotatedMessage, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): AnnotatedMessage; | ||
static deserializeBinaryFromReader(message: AnnotatedMessage, reader: jspb.BinaryReader): AnnotatedMessage; | ||
} | ||
|
||
export namespace AnnotatedMessage { | ||
export type AsObject = { | ||
myunit64: string, | ||
myint64: string, | ||
myfixed64: string, | ||
mysint64: string, | ||
mysfixed64: string, | ||
} | ||
} | ||
|
265 changes: 265 additions & 0 deletions
265
examples/generated-grpc-node/proto/examplecom/annotations_pb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
/** | ||
* @fileoverview | ||
* @enhanceable | ||
* @suppress {messageConventions} JS Compiler reports an error if a variable or | ||
* field starts with 'MSG_' and isn't a translatable message. | ||
* @public | ||
*/ | ||
// GENERATED CODE -- DO NOT EDIT! | ||
|
||
var jspb = require('google-protobuf'); | ||
var goog = jspb; | ||
var global = Function('return this')(); | ||
|
||
goog.exportSymbol('proto.examplecom.AnnotatedMessage', null, global); | ||
|
||
/** | ||
* Generated by JsPbCodeGenerator. | ||
* @param {Array=} opt_data Optional initial data array, typically from a | ||
* server response, or constructed directly in Javascript. The array is used | ||
* in place and becomes part of the constructed object. It is not cloned. | ||
* If no data is provided, the constructed object will be empty, but still | ||
* valid. | ||
* @extends {jspb.Message} | ||
* @constructor | ||
*/ | ||
proto.examplecom.AnnotatedMessage = function(opt_data) { | ||
jspb.Message.initialize(this, opt_data, 0, -1, null, null); | ||
}; | ||
goog.inherits(proto.examplecom.AnnotatedMessage, jspb.Message); | ||
if (goog.DEBUG && !COMPILED) { | ||
proto.examplecom.AnnotatedMessage.displayName = 'proto.examplecom.AnnotatedMessage'; | ||
} | ||
|
||
|
||
if (jspb.Message.GENERATE_TO_OBJECT) { | ||
/** | ||
* Creates an object representation of this proto suitable for use in Soy templates. | ||
* Field names that are reserved in JavaScript and will be renamed to pb_name. | ||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default. | ||
* For the list of reserved names please see: | ||
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. | ||
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance | ||
* for transitional soy proto support: http://goto/soy-param-migration | ||
* @return {!Object} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.toObject = function(opt_includeInstance) { | ||
return proto.examplecom.AnnotatedMessage.toObject(opt_includeInstance, this); | ||
}; | ||
|
||
|
||
/** | ||
* Static version of the {@see toObject} method. | ||
* @param {boolean|undefined} includeInstance Whether to include the JSPB | ||
* instance for transitional soy proto support: | ||
* http://goto/soy-param-migration | ||
* @param {!proto.examplecom.AnnotatedMessage} msg The msg instance to transform. | ||
* @return {!Object} | ||
* @suppress {unusedLocalVariables} f is only used for nested messages | ||
*/ | ||
proto.examplecom.AnnotatedMessage.toObject = function(includeInstance, msg) { | ||
var f, obj = { | ||
myunit64: jspb.Message.getFieldWithDefault(msg, 1, "0"), | ||
myint64: jspb.Message.getFieldWithDefault(msg, 2, "0"), | ||
myfixed64: jspb.Message.getFieldWithDefault(msg, 3, "0"), | ||
mysint64: jspb.Message.getFieldWithDefault(msg, 4, "0"), | ||
mysfixed64: jspb.Message.getFieldWithDefault(msg, 5, "0") | ||
}; | ||
|
||
if (includeInstance) { | ||
obj.$jspbMessageInstance = msg; | ||
} | ||
return obj; | ||
}; | ||
} | ||
|
||
|
||
/** | ||
* Deserializes binary data (in protobuf wire format). | ||
* @param {jspb.ByteSource} bytes The bytes to deserialize. | ||
* @return {!proto.examplecom.AnnotatedMessage} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.deserializeBinary = function(bytes) { | ||
var reader = new jspb.BinaryReader(bytes); | ||
var msg = new proto.examplecom.AnnotatedMessage; | ||
return proto.examplecom.AnnotatedMessage.deserializeBinaryFromReader(msg, reader); | ||
}; | ||
|
||
|
||
/** | ||
* Deserializes binary data (in protobuf wire format) from the | ||
* given reader into the given message object. | ||
* @param {!proto.examplecom.AnnotatedMessage} msg The message object to deserialize into. | ||
* @param {!jspb.BinaryReader} reader The BinaryReader to use. | ||
* @return {!proto.examplecom.AnnotatedMessage} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.deserializeBinaryFromReader = function(msg, reader) { | ||
while (reader.nextField()) { | ||
if (reader.isEndGroup()) { | ||
break; | ||
} | ||
var field = reader.getFieldNumber(); | ||
switch (field) { | ||
case 1: | ||
var value = /** @type {string} */ (reader.readUint64String()); | ||
msg.setMyunit64(value); | ||
break; | ||
case 2: | ||
var value = /** @type {string} */ (reader.readInt64String()); | ||
msg.setMyint64(value); | ||
break; | ||
case 3: | ||
var value = /** @type {string} */ (reader.readFixed64String()); | ||
msg.setMyfixed64(value); | ||
break; | ||
case 4: | ||
var value = /** @type {string} */ (reader.readSint64String()); | ||
msg.setMysint64(value); | ||
break; | ||
case 5: | ||
var value = /** @type {string} */ (reader.readSfixed64String()); | ||
msg.setMysfixed64(value); | ||
break; | ||
default: | ||
reader.skipField(); | ||
break; | ||
} | ||
} | ||
return msg; | ||
}; | ||
|
||
|
||
/** | ||
* Serializes the message to binary data (in protobuf wire format). | ||
* @return {!Uint8Array} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.serializeBinary = function() { | ||
var writer = new jspb.BinaryWriter(); | ||
proto.examplecom.AnnotatedMessage.serializeBinaryToWriter(this, writer); | ||
return writer.getResultBuffer(); | ||
}; | ||
|
||
|
||
/** | ||
* Serializes the given message to binary data (in protobuf wire | ||
* format), writing to the given BinaryWriter. | ||
* @param {!proto.examplecom.AnnotatedMessage} message | ||
* @param {!jspb.BinaryWriter} writer | ||
* @suppress {unusedLocalVariables} f is only used for nested messages | ||
*/ | ||
proto.examplecom.AnnotatedMessage.serializeBinaryToWriter = function(message, writer) { | ||
var f = undefined; | ||
f = message.getMyunit64(); | ||
if (parseInt(f, 10) !== 0) { | ||
writer.writeUint64String( | ||
1, | ||
f | ||
); | ||
} | ||
f = message.getMyint64(); | ||
if (parseInt(f, 10) !== 0) { | ||
writer.writeInt64String( | ||
2, | ||
f | ||
); | ||
} | ||
f = message.getMyfixed64(); | ||
if (parseInt(f, 10) !== 0) { | ||
writer.writeFixed64String( | ||
3, | ||
f | ||
); | ||
} | ||
f = message.getMysint64(); | ||
if (parseInt(f, 10) !== 0) { | ||
writer.writeSint64String( | ||
4, | ||
f | ||
); | ||
} | ||
f = message.getMysfixed64(); | ||
if (parseInt(f, 10) !== 0) { | ||
writer.writeSfixed64String( | ||
5, | ||
f | ||
); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* optional uint64 myUnit64 = 1; | ||
* @return {string} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.getMyunit64 = function() { | ||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "0")); | ||
}; | ||
|
||
|
||
/** @param {string} value */ | ||
proto.examplecom.AnnotatedMessage.prototype.setMyunit64 = function(value) { | ||
jspb.Message.setProto3StringIntField(this, 1, value); | ||
}; | ||
|
||
|
||
/** | ||
* optional int64 myInt64 = 2; | ||
* @return {string} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.getMyint64 = function() { | ||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "0")); | ||
}; | ||
|
||
|
||
/** @param {string} value */ | ||
proto.examplecom.AnnotatedMessage.prototype.setMyint64 = function(value) { | ||
jspb.Message.setProto3StringIntField(this, 2, value); | ||
}; | ||
|
||
|
||
/** | ||
* optional fixed64 myFixed64 = 3; | ||
* @return {string} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.getMyfixed64 = function() { | ||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "0")); | ||
}; | ||
|
||
|
||
/** @param {string} value */ | ||
proto.examplecom.AnnotatedMessage.prototype.setMyfixed64 = function(value) { | ||
jspb.Message.setProto3StringIntField(this, 3, value); | ||
}; | ||
|
||
|
||
/** | ||
* optional sint64 mySint64 = 4; | ||
* @return {string} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.getMysint64 = function() { | ||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "0")); | ||
}; | ||
|
||
|
||
/** @param {string} value */ | ||
proto.examplecom.AnnotatedMessage.prototype.setMysint64 = function(value) { | ||
jspb.Message.setProto3StringIntField(this, 4, value); | ||
}; | ||
|
||
|
||
/** | ||
* optional sfixed64 mySfixed64 = 5; | ||
* @return {string} | ||
*/ | ||
proto.examplecom.AnnotatedMessage.prototype.getMysfixed64 = function() { | ||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, "0")); | ||
}; | ||
|
||
|
||
/** @param {string} value */ | ||
proto.examplecom.AnnotatedMessage.prototype.setMysfixed64 = function(value) { | ||
jspb.Message.setProto3StringIntField(this, 5, value); | ||
}; | ||
|
||
|
||
goog.object.extend(exports, proto.examplecom); |
1 change: 1 addition & 0 deletions
1
examples/generated-grpc-node/proto/examplecom/casing_grpc_pb.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// GENERATED CODE -- NO SERVICES IN PROTO |
1 change: 1 addition & 0 deletions
1
examples/generated-grpc-node/proto/examplecom/casing_grpc_pb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// GENERATED CODE -- NO SERVICES IN PROTO |
Oops, something went wrong.