-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix get/set conflicting method names. (#272)
* Fix get/set conflicting method names. Update the typescript generator to add a suffix '$' to methods which conflict on the Message base class ('getExtension'/'setExtension'/'getJsPbMessageId'/'setJsPbMessageId'). This will keep the typescript definitions in sync with the generated JS code from the protoc compiler. Fixes #271. * Presence checks with conflicting namess * Fix clear method name. Co-authored-by: Marcus Longmuir <marcus.longmuir@improbable.io>
- Loading branch information
1 parent
fd6e3a0
commit 77d9ada
Showing
17 changed files
with
1,235 additions
and
6 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/generated-grpc-js-node/proto/examplecom/getter_name_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-js-node/proto/examplecom/getter_name_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 |
35 changes: 35 additions & 0 deletions
35
examples/generated-grpc-js-node/proto/examplecom/getter_name_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,35 @@ | ||
// package: examplecom | ||
// file: proto/examplecom/getter_name.proto | ||
|
||
import * as jspb from "google-protobuf"; | ||
|
||
export class GetterNameConflictMessage extends jspb.Message { | ||
hasExtension$(): boolean; | ||
clearExtension$(): void; | ||
getExtension$(): string | undefined; | ||
setExtension$(value: string): void; | ||
|
||
hasJsPbMessageId$(): boolean; | ||
clearJsPbMessageId$(): void; | ||
getJsPbMessageId$(): Uint8Array | string; | ||
getJsPbMessageId_asU8(): Uint8Array; | ||
getJsPbMessageId_asB64(): string; | ||
setJsPbMessageId$(value: Uint8Array | string): void; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): GetterNameConflictMessage.AsObject; | ||
static toObject(includeInstance: boolean, msg: GetterNameConflictMessage): GetterNameConflictMessage.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: GetterNameConflictMessage, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): GetterNameConflictMessage; | ||
static deserializeBinaryFromReader(message: GetterNameConflictMessage, reader: jspb.BinaryReader): GetterNameConflictMessage; | ||
} | ||
|
||
export namespace GetterNameConflictMessage { | ||
export type AsObject = { | ||
extension?: string, | ||
jsPbMessageId: Uint8Array | string, | ||
} | ||
} | ||
|
260 changes: 260 additions & 0 deletions
260
examples/generated-grpc-js-node/proto/examplecom/getter_name_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,260 @@ | ||
// source: proto/examplecom/getter_name.proto | ||
/** | ||
* @fileoverview | ||
* @enhanceable | ||
* @suppress {missingRequire} reports error on implicit type usages. | ||
* @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! | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
|
||
var jspb = require('google-protobuf'); | ||
var goog = jspb; | ||
var global = Function('return this')(); | ||
|
||
goog.exportSymbol('proto.examplecom.GetterNameConflictMessage', 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.GetterNameConflictMessage = function(opt_data) { | ||
jspb.Message.initialize(this, opt_data, 0, -1, null, null); | ||
}; | ||
goog.inherits(proto.examplecom.GetterNameConflictMessage, jspb.Message); | ||
if (goog.DEBUG && !COMPILED) { | ||
/** | ||
* @public | ||
* @override | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.displayName = 'proto.examplecom.GetterNameConflictMessage'; | ||
} | ||
|
||
|
||
|
||
if (jspb.Message.GENERATE_TO_OBJECT) { | ||
/** | ||
* Creates an object representation of this proto. | ||
* Field names that are reserved in JavaScript and will be renamed to pb_name. | ||
* Optional fields that are not set will be set to undefined. | ||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default. | ||
* For the list of reserved names please see: | ||
* net/proto2/compiler/js/internal/generator.cc#kKeyword. | ||
* @param {boolean=} opt_includeInstance Deprecated. whether to include the | ||
* JSPB instance for transitional soy proto support: | ||
* http://goto/soy-param-migration | ||
* @return {!Object} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.toObject = function(opt_includeInstance) { | ||
return proto.examplecom.GetterNameConflictMessage.toObject(opt_includeInstance, this); | ||
}; | ||
|
||
|
||
/** | ||
* Static version of the {@see toObject} method. | ||
* @param {boolean|undefined} includeInstance Deprecated. Whether to include | ||
* the JSPB instance for transitional soy proto support: | ||
* http://goto/soy-param-migration | ||
* @param {!proto.examplecom.GetterNameConflictMessage} msg The msg instance to transform. | ||
* @return {!Object} | ||
* @suppress {unusedLocalVariables} f is only used for nested messages | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.toObject = function(includeInstance, msg) { | ||
var f, obj = { | ||
extension: (f = jspb.Message.getField(msg, 1)) == null ? undefined : f, | ||
jsPbMessageId: msg.getJsPbMessageId_asB64() | ||
}; | ||
|
||
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.GetterNameConflictMessage} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.deserializeBinary = function(bytes) { | ||
var reader = new jspb.BinaryReader(bytes); | ||
var msg = new proto.examplecom.GetterNameConflictMessage; | ||
return proto.examplecom.GetterNameConflictMessage.deserializeBinaryFromReader(msg, reader); | ||
}; | ||
|
||
|
||
/** | ||
* Deserializes binary data (in protobuf wire format) from the | ||
* given reader into the given message object. | ||
* @param {!proto.examplecom.GetterNameConflictMessage} msg The message object to deserialize into. | ||
* @param {!jspb.BinaryReader} reader The BinaryReader to use. | ||
* @return {!proto.examplecom.GetterNameConflictMessage} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.deserializeBinaryFromReader = function(msg, reader) { | ||
while (reader.nextField()) { | ||
if (reader.isEndGroup()) { | ||
break; | ||
} | ||
var field = reader.getFieldNumber(); | ||
switch (field) { | ||
case 1: | ||
var value = /** @type {string} */ (reader.readString()); | ||
msg.setExtension$(value); | ||
break; | ||
case 2: | ||
var value = /** @type {!Uint8Array} */ (reader.readBytes()); | ||
msg.setJsPbMessageId$(value); | ||
break; | ||
default: | ||
reader.skipField(); | ||
break; | ||
} | ||
} | ||
return msg; | ||
}; | ||
|
||
|
||
/** | ||
* Serializes the message to binary data (in protobuf wire format). | ||
* @return {!Uint8Array} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.serializeBinary = function() { | ||
var writer = new jspb.BinaryWriter(); | ||
proto.examplecom.GetterNameConflictMessage.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.GetterNameConflictMessage} message | ||
* @param {!jspb.BinaryWriter} writer | ||
* @suppress {unusedLocalVariables} f is only used for nested messages | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.serializeBinaryToWriter = function(message, writer) { | ||
var f = undefined; | ||
f = /** @type {string} */ (jspb.Message.getField(message, 1)); | ||
if (f != null) { | ||
writer.writeString( | ||
1, | ||
f | ||
); | ||
} | ||
f = /** @type {!(string|Uint8Array)} */ (jspb.Message.getField(message, 2)); | ||
if (f != null) { | ||
writer.writeBytes( | ||
2, | ||
f | ||
); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* optional string extension = 1; | ||
* @return {string} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.getExtension$ = function() { | ||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); | ||
}; | ||
|
||
|
||
/** | ||
* @param {string} value | ||
* @return {!proto.examplecom.GetterNameConflictMessage} returns this | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.setExtension$ = function(value) { | ||
return jspb.Message.setField(this, 1, value); | ||
}; | ||
|
||
|
||
/** | ||
* Clears the field making it undefined. | ||
* @return {!proto.examplecom.GetterNameConflictMessage} returns this | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.clearExtension$ = function() { | ||
return jspb.Message.setField(this, 1, undefined); | ||
}; | ||
|
||
|
||
/** | ||
* Returns whether this field is set. | ||
* @return {boolean} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.hasExtension$ = function() { | ||
return jspb.Message.getField(this, 1) != null; | ||
}; | ||
|
||
|
||
/** | ||
* optional bytes js_pb_message_id = 2; | ||
* @return {!(string|Uint8Array)} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.getJsPbMessageId$ = function() { | ||
return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); | ||
}; | ||
|
||
|
||
/** | ||
* optional bytes js_pb_message_id = 2; | ||
* This is a type-conversion wrapper around `getJsPbMessageId$()` | ||
* @return {string} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.getJsPbMessageId_asB64 = function() { | ||
return /** @type {string} */ (jspb.Message.bytesAsB64( | ||
this.getJsPbMessageId$())); | ||
}; | ||
|
||
|
||
/** | ||
* optional bytes js_pb_message_id = 2; | ||
* Note that Uint8Array is not supported on all browsers. | ||
* @see http://caniuse.com/Uint8Array | ||
* This is a type-conversion wrapper around `getJsPbMessageId$()` | ||
* @return {!Uint8Array} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.getJsPbMessageId_asU8 = function() { | ||
return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( | ||
this.getJsPbMessageId$())); | ||
}; | ||
|
||
|
||
/** | ||
* @param {!(string|Uint8Array)} value | ||
* @return {!proto.examplecom.GetterNameConflictMessage} returns this | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.setJsPbMessageId$ = function(value) { | ||
return jspb.Message.setField(this, 2, value); | ||
}; | ||
|
||
|
||
/** | ||
* Clears the field making it undefined. | ||
* @return {!proto.examplecom.GetterNameConflictMessage} returns this | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.clearJsPbMessageId$ = function() { | ||
return jspb.Message.setField(this, 2, undefined); | ||
}; | ||
|
||
|
||
/** | ||
* Returns whether this field is set. | ||
* @return {boolean} | ||
*/ | ||
proto.examplecom.GetterNameConflictMessage.prototype.hasJsPbMessageId$ = function() { | ||
return jspb.Message.getField(this, 2) != null; | ||
}; | ||
|
||
|
||
goog.object.extend(exports, proto.examplecom); |
1 change: 1 addition & 0 deletions
1
examples/generated-grpc-node/proto/examplecom/getter_name_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/getter_name_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 |
35 changes: 35 additions & 0 deletions
35
examples/generated-grpc-node/proto/examplecom/getter_name_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,35 @@ | ||
// package: examplecom | ||
// file: proto/examplecom/getter_name.proto | ||
|
||
import * as jspb from "google-protobuf"; | ||
|
||
export class GetterNameConflictMessage extends jspb.Message { | ||
hasExtension$(): boolean; | ||
clearExtension$(): void; | ||
getExtension$(): string | undefined; | ||
setExtension$(value: string): void; | ||
|
||
hasJsPbMessageId$(): boolean; | ||
clearJsPbMessageId$(): void; | ||
getJsPbMessageId$(): Uint8Array | string; | ||
getJsPbMessageId_asU8(): Uint8Array; | ||
getJsPbMessageId_asB64(): string; | ||
setJsPbMessageId$(value: Uint8Array | string): void; | ||
|
||
serializeBinary(): Uint8Array; | ||
toObject(includeInstance?: boolean): GetterNameConflictMessage.AsObject; | ||
static toObject(includeInstance: boolean, msg: GetterNameConflictMessage): GetterNameConflictMessage.AsObject; | ||
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>}; | ||
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>}; | ||
static serializeBinaryToWriter(message: GetterNameConflictMessage, writer: jspb.BinaryWriter): void; | ||
static deserializeBinary(bytes: Uint8Array): GetterNameConflictMessage; | ||
static deserializeBinaryFromReader(message: GetterNameConflictMessage, reader: jspb.BinaryReader): GetterNameConflictMessage; | ||
} | ||
|
||
export namespace GetterNameConflictMessage { | ||
export type AsObject = { | ||
extension?: string, | ||
jsPbMessageId: Uint8Array | string, | ||
} | ||
} | ||
|
Oops, something went wrong.