From d13d5d5688052e366aa2e9169f50dfca376b32cf Mon Sep 17 00:00:00 2001 From: Taylor McIntyre Date: Fri, 21 May 2021 15:53:03 -0700 Subject: [PATCH] feat: add getTypeUrl method to generated code (#1463) * Add getTypeUrl method to static-module generated code * add tests for getTypeUrl method --- cli/pbjs.js | 4 +- cli/targets/static.js | 16 + scripts/gentests.js | 3 +- tests/data/comments.d.ts | 2 + tests/data/comments.js | 22 + tests/data/convert.d.ts | 1 + tests/data/convert.js | 11 + tests/data/mapbox/vector_tile.d.ts | 4 + tests/data/mapbox/vector_tile.js | 44 ++ tests/data/package.d.ts | 2 + tests/data/package.js | 22 + tests/data/rpc-es6.d.ts | 2 + tests/data/rpc-es6.js | 28 +- tests/data/rpc-reserved.d.ts | 2 + tests/data/rpc-reserved.js | 22 + tests/data/rpc.d.ts | 2 + tests/data/rpc.js | 22 + tests/data/test.d.ts | 57 +++ tests/data/test.js | 627 +++++++++++++++++++++++++++++ tests/data/type_url.js | 413 +++++++++++++++++++ tests/data/type_url.proto | 8 + tests/gen_type_url.js | 9 + 22 files changed, 1319 insertions(+), 4 deletions(-) create mode 100644 tests/data/type_url.js create mode 100644 tests/data/type_url.proto create mode 100644 tests/gen_type_url.js diff --git a/cli/pbjs.js b/cli/pbjs.js index 801f40144..8ae575008 100644 --- a/cli/pbjs.js +++ b/cli/pbjs.js @@ -41,7 +41,7 @@ exports.main = function main(args, callback) { "force-message": "strict-message" }, string: [ "target", "out", "path", "wrap", "dependency", "root", "lint" ], - boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "service", "es6", "sparse", "keep-case", "force-long", "force-number", "force-enum-string", "force-message", "null-defaults" ], + boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "typeurl", "beautify", "comments", "service", "es6", "sparse", "keep-case", "force-long", "force-number", "force-enum-string", "force-message", "null-defaults" ], default: { target: "json", create: true, @@ -50,6 +50,7 @@ exports.main = function main(args, callback) { verify: true, convert: true, delimited: true, + typeurl: true, beautify: true, comments: true, service: true, @@ -132,6 +133,7 @@ exports.main = function main(args, callback) { " --no-verify Does not generate verify functions.", " --no-convert Does not generate convert functions like from/toObject", " --no-delimited Does not generate delimited encode/decode functions.", + " --no-typeurl Does not generate getTypeUrl function.", " --no-beautify Does not beautify generated code.", " --no-comments Does not output any JSDoc comments.", " --no-service Does not output service classes.", diff --git a/cli/targets/static.js b/cli/targets/static.js index 5d3915fd1..3e983e00a 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -589,6 +589,22 @@ function buildType(ref, type) { --indent; push("};"); } + + if (config.typeurl) { + push(""); + pushComment([ + "Gets the default type url for " + type.name, + "@function getTypeUrl", + "@memberof " + exportName(type), + "@static", + "@returns {string} The default type url" + ]); + push(escapeName(type.name) + ".getTypeUrl = function getTypeUrl() {"); + ++indent; + push("return \"type.googleapis.com/" + exportName(type) + "\";"); + --indent; + push("};"); + } } function buildService(ref, service) { diff --git a/scripts/gentests.js b/scripts/gentests.js index 97812e0fc..42be12456 100644 --- a/scripts/gentests.js +++ b/scripts/gentests.js @@ -13,7 +13,8 @@ var fs = require("fs"), { file: "tests/data/rpc.proto", flags: [] }, { file: "tests/data/rpc-reserved.proto", flags: [] }, { file: "tests/data/test.proto", flags: [] }, - { file: "bench/data/bench.proto", flags: ["no-create", "no-verify", "no-delimited", "no-convert", "no-comments"], out: "bench/data/static_pbjs.js" } + { file: "tests/data/type_url.proto", flags: [] }, + { file: "bench/data/bench.proto", flags: ["no-create", "no-verify", "no-delimited", "no-convert", "no-verify", "no-typeurl", "no-comments"], out: "bench/data/static_pbjs.js" } ] .forEach(function({ file, flags, out }) { var basename = file.replace(/\.proto$/, ""); diff --git a/tests/data/comments.d.ts b/tests/data/comments.d.ts index 45ed81873..5f1d2883c 100644 --- a/tests/data/comments.d.ts +++ b/tests/data/comments.d.ts @@ -19,6 +19,7 @@ export class Test1 implements ITest1 { public static fromObject(object: { [k: string]: any }): Test1; public static toObject(message: Test1, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export interface ITest2 { @@ -35,6 +36,7 @@ export class Test2 implements ITest2 { public static fromObject(object: { [k: string]: any }): Test2; public static toObject(message: Test2, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export enum Test3 { diff --git a/tests/data/comments.js b/tests/data/comments.js index fa9c1750d..b405386db 100644 --- a/tests/data/comments.js +++ b/tests/data/comments.js @@ -241,6 +241,17 @@ $root.Test1 = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Test1 + * @function getTypeUrl + * @memberof Test1 + * @static + * @returns {string} The default type url + */ + Test1.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/Test1"; + }; + return Test1; })(); @@ -401,6 +412,17 @@ $root.Test2 = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Test2 + * @function getTypeUrl + * @memberof Test2 + * @static + * @returns {string} The default type url + */ + Test2.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/Test2"; + }; + return Test2; })(); diff --git a/tests/data/convert.d.ts b/tests/data/convert.d.ts index 5d5a59492..dd5ef3839 100644 --- a/tests/data/convert.d.ts +++ b/tests/data/convert.d.ts @@ -31,6 +31,7 @@ export class Message implements IMessage { public static fromObject(object: { [k: string]: any }): Message; public static toObject(message: Message, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export namespace Message { diff --git a/tests/data/convert.js b/tests/data/convert.js index 02ebe5e97..fd3a5aacb 100644 --- a/tests/data/convert.js +++ b/tests/data/convert.js @@ -562,6 +562,17 @@ $root.Message = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Message + * @function getTypeUrl + * @memberof Message + * @static + * @returns {string} The default type url + */ + Message.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/Message"; + }; + /** * SomeEnum enum. * @name Message.SomeEnum diff --git a/tests/data/mapbox/vector_tile.d.ts b/tests/data/mapbox/vector_tile.d.ts index d1adc23e7..5af943b20 100644 --- a/tests/data/mapbox/vector_tile.d.ts +++ b/tests/data/mapbox/vector_tile.d.ts @@ -17,6 +17,7 @@ export namespace vector_tile { public static fromObject(object: { [k: string]: any }): vector_tile.Tile; public static toObject(message: vector_tile.Tile, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace Tile { @@ -56,6 +57,7 @@ export namespace vector_tile { public static fromObject(object: { [k: string]: any }): vector_tile.Tile.Value; public static toObject(message: vector_tile.Tile.Value, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IFeature { @@ -80,6 +82,7 @@ export namespace vector_tile { public static fromObject(object: { [k: string]: any }): vector_tile.Tile.Feature; public static toObject(message: vector_tile.Tile.Feature, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ILayer { @@ -108,6 +111,7 @@ export namespace vector_tile { public static fromObject(object: { [k: string]: any }): vector_tile.Tile.Layer; public static toObject(message: vector_tile.Tile.Layer, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } } diff --git a/tests/data/mapbox/vector_tile.js b/tests/data/mapbox/vector_tile.js index ac2c1f7b7..001815d56 100644 --- a/tests/data/mapbox/vector_tile.js +++ b/tests/data/mapbox/vector_tile.js @@ -223,6 +223,17 @@ $root.vector_tile = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Tile + * @function getTypeUrl + * @memberof vector_tile.Tile + * @static + * @returns {string} The default type url + */ + Tile.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/vector_tile.Tile"; + }; + /** * GeomType enum. * @name vector_tile.Tile.GeomType @@ -600,6 +611,17 @@ $root.vector_tile = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Value + * @function getTypeUrl + * @memberof vector_tile.Tile.Value + * @static + * @returns {string} The default type url + */ + Value.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/vector_tile.Tile.Value"; + }; + return Value; })(); @@ -941,6 +963,17 @@ $root.vector_tile = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Feature + * @function getTypeUrl + * @memberof vector_tile.Tile.Feature + * @static + * @returns {string} The default type url + */ + Feature.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/vector_tile.Tile.Feature"; + }; + return Feature; })(); @@ -1299,6 +1332,17 @@ $root.vector_tile = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Layer + * @function getTypeUrl + * @memberof vector_tile.Tile.Layer + * @static + * @returns {string} The default type url + */ + Layer.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/vector_tile.Tile.Layer"; + }; + return Layer; })(); diff --git a/tests/data/package.d.ts b/tests/data/package.d.ts index 3ad494702..d18b917f8 100644 --- a/tests/data/package.d.ts +++ b/tests/data/package.d.ts @@ -47,6 +47,7 @@ export class Package implements IPackage { public static fromObject(object: { [k: string]: any }): Package; public static toObject(message: Package, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export namespace Package { @@ -69,5 +70,6 @@ export namespace Package { public static fromObject(object: { [k: string]: any }): Package.Repository; public static toObject(message: Package.Repository, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } diff --git a/tests/data/package.js b/tests/data/package.js index acdee24b2..3ec5e7da0 100644 --- a/tests/data/package.js +++ b/tests/data/package.js @@ -724,6 +724,17 @@ $root.Package = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Package + * @function getTypeUrl + * @memberof Package + * @static + * @returns {string} The default type url + */ + Package.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/Package"; + }; + Package.Repository = (function() { /** @@ -931,6 +942,17 @@ $root.Package = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Repository + * @function getTypeUrl + * @memberof Package.Repository + * @static + * @returns {string} The default type url + */ + Repository.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/Package.Repository"; + }; + return Repository; })(); diff --git a/tests/data/rpc-es6.d.ts b/tests/data/rpc-es6.d.ts index 47e4313b1..c327bbdd1 100644 --- a/tests/data/rpc-es6.d.ts +++ b/tests/data/rpc-es6.d.ts @@ -27,6 +27,7 @@ export class MyRequest implements IMyRequest { public static fromObject(object: { [k: string]: any }): MyRequest; public static toObject(message: MyRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export interface IMyResponse { @@ -45,4 +46,5 @@ export class MyResponse implements IMyResponse { public static fromObject(object: { [k: string]: any }): MyResponse; public static toObject(message: MyResponse, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } diff --git a/tests/data/rpc-es6.js b/tests/data/rpc-es6.js index be0e37c04..4799711fb 100644 --- a/tests/data/rpc-es6.js +++ b/tests/data/rpc-es6.js @@ -1,5 +1,7 @@ /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ -import * as $protobuf from "../../minimal"; +"use strict"; + +var $protobuf = require("../../minimal"); // Common aliases const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; @@ -259,6 +261,17 @@ export const MyRequest = $root.MyRequest = (() => { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MyRequest + * @function getTypeUrl + * @memberof MyRequest + * @static + * @returns {string} The default type url + */ + MyRequest.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/MyRequest"; + }; + return MyRequest; })(); @@ -446,7 +459,18 @@ export const MyResponse = $root.MyResponse = (() => { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MyResponse + * @function getTypeUrl + * @memberof MyResponse + * @static + * @returns {string} The default type url + */ + MyResponse.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/MyResponse"; + }; + return MyResponse; })(); -export { $root as default }; +module.exports = $root; diff --git a/tests/data/rpc-reserved.d.ts b/tests/data/rpc-reserved.d.ts index 770b92ccc..c8e9138bd 100644 --- a/tests/data/rpc-reserved.d.ts +++ b/tests/data/rpc-reserved.d.ts @@ -27,6 +27,7 @@ export class MyRequest implements IMyRequest { public static fromObject(object: { [k: string]: any }): MyRequest; public static toObject(message: MyRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export interface IMyResponse { @@ -45,4 +46,5 @@ export class MyResponse implements IMyResponse { public static fromObject(object: { [k: string]: any }): MyResponse; public static toObject(message: MyResponse, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } diff --git a/tests/data/rpc-reserved.js b/tests/data/rpc-reserved.js index ef555698c..15365c02b 100644 --- a/tests/data/rpc-reserved.js +++ b/tests/data/rpc-reserved.js @@ -261,6 +261,17 @@ $root.MyRequest = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MyRequest + * @function getTypeUrl + * @memberof MyRequest + * @static + * @returns {string} The default type url + */ + MyRequest.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/MyRequest"; + }; + return MyRequest; })(); @@ -448,6 +459,17 @@ $root.MyResponse = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MyResponse + * @function getTypeUrl + * @memberof MyResponse + * @static + * @returns {string} The default type url + */ + MyResponse.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/MyResponse"; + }; + return MyResponse; })(); diff --git a/tests/data/rpc.d.ts b/tests/data/rpc.d.ts index 47e4313b1..c327bbdd1 100644 --- a/tests/data/rpc.d.ts +++ b/tests/data/rpc.d.ts @@ -27,6 +27,7 @@ export class MyRequest implements IMyRequest { public static fromObject(object: { [k: string]: any }): MyRequest; public static toObject(message: MyRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } export interface IMyResponse { @@ -45,4 +46,5 @@ export class MyResponse implements IMyResponse { public static fromObject(object: { [k: string]: any }): MyResponse; public static toObject(message: MyResponse, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } diff --git a/tests/data/rpc.js b/tests/data/rpc.js index bc493aa4f..11c0a919b 100644 --- a/tests/data/rpc.js +++ b/tests/data/rpc.js @@ -261,6 +261,17 @@ $root.MyRequest = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MyRequest + * @function getTypeUrl + * @memberof MyRequest + * @static + * @returns {string} The default type url + */ + MyRequest.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/MyRequest"; + }; + return MyRequest; })(); @@ -448,6 +459,17 @@ $root.MyResponse = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MyResponse + * @function getTypeUrl + * @memberof MyResponse + * @static + * @returns {string} The default type url + */ + MyResponse.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/MyResponse"; + }; + return MyResponse; })(); diff --git a/tests/data/test.d.ts b/tests/data/test.d.ts index 832e104ba..f2b920406 100644 --- a/tests/data/test.d.ts +++ b/tests/data/test.d.ts @@ -17,6 +17,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Empty; public static toObject(message: jspb.test.Empty, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } enum OuterEnum { @@ -40,6 +41,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.EnumContainer; public static toObject(message: jspb.test.EnumContainer, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ISimple1 { @@ -62,6 +64,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Simple1; public static toObject(message: jspb.test.Simple1, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ISimple2 { @@ -82,6 +85,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Simple2; public static toObject(message: jspb.test.Simple2, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ISpecialCases { @@ -106,6 +110,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.SpecialCases; public static toObject(message: jspb.test.SpecialCases, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IOptionalFields { @@ -132,6 +137,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.OptionalFields; public static toObject(message: jspb.test.OptionalFields, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace OptionalFields { @@ -152,6 +158,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.OptionalFields.Nested; public static toObject(message: jspb.test.OptionalFields.Nested, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -181,6 +188,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.HasExtensions; public static toObject(message: jspb.test.HasExtensions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IComplex { @@ -207,6 +215,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Complex; public static toObject(message: jspb.test.Complex, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace Complex { @@ -227,6 +236,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Complex.Nested; public static toObject(message: jspb.test.Complex.Nested, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -244,6 +254,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.OuterMessage; public static toObject(message: jspb.test.OuterMessage, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace OuterMessage { @@ -264,6 +275,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.OuterMessage.Complex; public static toObject(message: jspb.test.OuterMessage.Complex, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -283,6 +295,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.IsExtension; public static toObject(message: jspb.test.IsExtension, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IIndirectExtension { @@ -299,6 +312,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.IndirectExtension; public static toObject(message: jspb.test.IndirectExtension, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IDefaultValues { @@ -327,6 +341,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.DefaultValues; public static toObject(message: jspb.test.DefaultValues, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace DefaultValues { @@ -367,6 +382,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.FloatingPointFields; public static toObject(message: jspb.test.FloatingPointFields, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestClone { @@ -394,6 +410,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestClone; public static toObject(message: jspb.test.TestClone, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ICloneExtension { @@ -412,6 +429,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.CloneExtension; public static toObject(message: jspb.test.CloneExtension, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestGroup { @@ -440,6 +458,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestGroup; public static toObject(message: jspb.test.TestGroup, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace TestGroup { @@ -462,6 +481,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestGroup.RepeatedGroup; public static toObject(message: jspb.test.TestGroup.RepeatedGroup, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IRequiredGroup { @@ -480,6 +500,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestGroup.RequiredGroup; public static toObject(message: jspb.test.TestGroup.RequiredGroup, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IOptionalGroup { @@ -498,6 +519,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestGroup.OptionalGroup; public static toObject(message: jspb.test.TestGroup.OptionalGroup, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -517,6 +539,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestGroup1; public static toObject(message: jspb.test.TestGroup1, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestReservedNames { @@ -536,6 +559,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestReservedNames; public static toObject(message: jspb.test.TestReservedNames, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestReservedNamesExtension { @@ -552,6 +576,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestReservedNamesExtension; public static toObject(message: jspb.test.TestReservedNamesExtension, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestMessageWithOneof { @@ -592,6 +617,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestMessageWithOneof; public static toObject(message: jspb.test.TestMessageWithOneof, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestEndsWithBytes { @@ -612,6 +638,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestEndsWithBytes; public static toObject(message: jspb.test.TestEndsWithBytes, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface ITestMapFieldsNoBinary { @@ -652,6 +679,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.TestMapFieldsNoBinary; public static toObject(message: jspb.test.TestMapFieldsNoBinary, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } enum MapValueEnumNoBinary { @@ -676,6 +704,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.MapValueMessageNoBinary; public static toObject(message: jspb.test.MapValueMessageNoBinary, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IDeeply { @@ -692,6 +721,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Deeply; public static toObject(message: jspb.test.Deeply, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace Deeply { @@ -710,6 +740,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Deeply.Nested; public static toObject(message: jspb.test.Deeply.Nested, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace Nested { @@ -730,6 +761,7 @@ export namespace jspb { public static fromObject(object: { [k: string]: any }): jspb.test.Deeply.Nested.Message; public static toObject(message: jspb.test.Deeply.Nested.Message, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } } @@ -756,6 +788,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.FileDescriptorSet; public static toObject(message: google.protobuf.FileDescriptorSet, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IFileDescriptorProto { @@ -796,6 +829,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.FileDescriptorProto; public static toObject(message: google.protobuf.FileDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IDescriptorProto { @@ -832,6 +866,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.DescriptorProto; public static toObject(message: google.protobuf.DescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace DescriptorProto { @@ -854,6 +889,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.DescriptorProto.ExtensionRange; public static toObject(message: google.protobuf.DescriptorProto.ExtensionRange, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IReservedRange { @@ -874,6 +910,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.DescriptorProto.ReservedRange; public static toObject(message: google.protobuf.DescriptorProto.ReservedRange, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -911,6 +948,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.FieldDescriptorProto; public static toObject(message: google.protobuf.FieldDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace FieldDescriptorProto { @@ -961,6 +999,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.OneofDescriptorProto; public static toObject(message: google.protobuf.OneofDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IEnumDescriptorProto { @@ -983,6 +1022,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.EnumDescriptorProto; public static toObject(message: google.protobuf.EnumDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IEnumValueDescriptorProto { @@ -1005,6 +1045,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.EnumValueDescriptorProto; public static toObject(message: google.protobuf.EnumValueDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IServiceDescriptorProto { @@ -1027,6 +1068,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.ServiceDescriptorProto; public static toObject(message: google.protobuf.ServiceDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IMethodDescriptorProto { @@ -1055,6 +1097,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.MethodDescriptorProto; public static toObject(message: google.protobuf.MethodDescriptorProto, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IFileOptions { @@ -1101,6 +1144,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.FileOptions; public static toObject(message: google.protobuf.FileOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace FileOptions { @@ -1136,6 +1180,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.MessageOptions; public static toObject(message: google.protobuf.MessageOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IFieldOptions { @@ -1166,6 +1211,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.FieldOptions; public static toObject(message: google.protobuf.FieldOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace FieldOptions { @@ -1199,6 +1245,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.OneofOptions; public static toObject(message: google.protobuf.OneofOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IEnumOptions { @@ -1222,6 +1269,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.EnumOptions; public static toObject(message: google.protobuf.EnumOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IEnumValueOptions { @@ -1242,6 +1290,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.EnumValueOptions; public static toObject(message: google.protobuf.EnumValueOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IServiceOptions { @@ -1262,6 +1311,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.ServiceOptions; public static toObject(message: google.protobuf.ServiceOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } interface IMethodOptions { @@ -1284,6 +1334,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.MethodOptions; public static toObject(message: google.protobuf.MethodOptions, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace MethodOptions { @@ -1323,6 +1374,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.UninterpretedOption; public static toObject(message: google.protobuf.UninterpretedOption, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace UninterpretedOption { @@ -1345,6 +1397,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.UninterpretedOption.NamePart; public static toObject(message: google.protobuf.UninterpretedOption.NamePart, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -1364,6 +1417,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.SourceCodeInfo; public static toObject(message: google.protobuf.SourceCodeInfo, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace SourceCodeInfo { @@ -1392,6 +1446,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.SourceCodeInfo.Location; public static toObject(message: google.protobuf.SourceCodeInfo.Location, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } @@ -1411,6 +1466,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.GeneratedCodeInfo; public static toObject(message: google.protobuf.GeneratedCodeInfo, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } namespace GeneratedCodeInfo { @@ -1437,6 +1493,7 @@ export namespace google { public static fromObject(object: { [k: string]: any }): google.protobuf.GeneratedCodeInfo.Annotation; public static toObject(message: google.protobuf.GeneratedCodeInfo.Annotation, options?: $protobuf.IConversionOptions): { [k: string]: any }; public toJSON(): { [k: string]: any }; + public static getTypeUrl(): string; } } } diff --git a/tests/data/test.js b/tests/data/test.js index dab3f5fb1..e0a794641 100644 --- a/tests/data/test.js +++ b/tests/data/test.js @@ -184,6 +184,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Empty + * @function getTypeUrl + * @memberof jspb.test.Empty + * @static + * @returns {string} The default type url + */ + Empty.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Empty"; + }; + return Empty; })(); @@ -398,6 +409,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for EnumContainer + * @function getTypeUrl + * @memberof jspb.test.EnumContainer + * @static + * @returns {string} The default type url + */ + EnumContainer.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.EnumContainer"; + }; + return EnumContainer; })(); @@ -647,6 +669,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Simple1 + * @function getTypeUrl + * @memberof jspb.test.Simple1 + * @static + * @returns {string} The default type url + */ + Simple1.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Simple1"; + }; + return Simple1; })(); @@ -873,6 +906,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Simple2 + * @function getTypeUrl + * @memberof jspb.test.Simple2 + * @static + * @returns {string} The default type url + */ + Simple2.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Simple2"; + }; + return Simple2; })(); @@ -1127,6 +1171,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for SpecialCases + * @function getTypeUrl + * @memberof jspb.test.SpecialCases + * @static + * @returns {string} The default type url + */ + SpecialCases.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.SpecialCases"; + }; + return SpecialCases; })(); @@ -1447,6 +1502,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for OptionalFields + * @function getTypeUrl + * @memberof jspb.test.OptionalFields + * @static + * @returns {string} The default type url + */ + OptionalFields.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.OptionalFields"; + }; + OptionalFields.Nested = (function() { /** @@ -1631,6 +1697,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Nested + * @function getTypeUrl + * @memberof jspb.test.OptionalFields.Nested + * @static + * @returns {string} The default type url + */ + Nested.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.OptionalFields.Nested"; + }; + return Nested; })(); @@ -2052,6 +2129,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for HasExtensions + * @function getTypeUrl + * @memberof jspb.test.HasExtensions + * @static + * @returns {string} The default type url + */ + HasExtensions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.HasExtensions"; + }; + return HasExtensions; })(); @@ -2372,6 +2460,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Complex + * @function getTypeUrl + * @memberof jspb.test.Complex + * @static + * @returns {string} The default type url + */ + Complex.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Complex"; + }; + Complex.Nested = (function() { /** @@ -2556,6 +2655,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Nested + * @function getTypeUrl + * @memberof jspb.test.Complex.Nested + * @static + * @returns {string} The default type url + */ + Nested.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Complex.Nested"; + }; + return Nested; })(); @@ -2719,6 +2829,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for OuterMessage + * @function getTypeUrl + * @memberof jspb.test.OuterMessage + * @static + * @returns {string} The default type url + */ + OuterMessage.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.OuterMessage"; + }; + OuterMessage.Complex = (function() { /** @@ -2903,6 +3024,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Complex + * @function getTypeUrl + * @memberof jspb.test.OuterMessage.Complex + * @static + * @returns {string} The default type url + */ + Complex.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.OuterMessage.Complex"; + }; + return Complex; })(); @@ -3093,6 +3225,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for IsExtension + * @function getTypeUrl + * @memberof jspb.test.IsExtension + * @static + * @returns {string} The default type url + */ + IsExtension.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.IsExtension"; + }; + return IsExtension; })(); @@ -3253,6 +3396,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for IndirectExtension + * @function getTypeUrl + * @memberof jspb.test.IndirectExtension + * @static + * @returns {string} The default type url + */ + IndirectExtension.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.IndirectExtension"; + }; + return IndirectExtension; })(); @@ -3591,6 +3745,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for DefaultValues + * @function getTypeUrl + * @memberof jspb.test.DefaultValues + * @static + * @returns {string} The default type url + */ + DefaultValues.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.DefaultValues"; + }; + /** * Enum enum. * @name jspb.test.DefaultValues.Enum @@ -3991,6 +4156,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for FloatingPointFields + * @function getTypeUrl + * @memberof jspb.test.FloatingPointFields + * @static + * @returns {string} The default type url + */ + FloatingPointFields.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.FloatingPointFields"; + }; + return FloatingPointFields; })(); @@ -4330,6 +4506,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestClone + * @function getTypeUrl + * @memberof jspb.test.TestClone + * @static + * @returns {string} The default type url + */ + TestClone.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestClone"; + }; + return TestClone; })(); @@ -4517,6 +4704,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for CloneExtension + * @function getTypeUrl + * @memberof jspb.test.CloneExtension + * @static + * @returns {string} The default type url + */ + CloneExtension.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.CloneExtension"; + }; + return CloneExtension; })(); @@ -4859,6 +5057,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestGroup + * @function getTypeUrl + * @memberof jspb.test.TestGroup + * @static + * @returns {string} The default type url + */ + TestGroup.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestGroup"; + }; + TestGroup.RepeatedGroup = (function() { /** @@ -5089,6 +5298,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for RepeatedGroup + * @function getTypeUrl + * @memberof jspb.test.TestGroup.RepeatedGroup + * @static + * @returns {string} The default type url + */ + RepeatedGroup.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestGroup.RepeatedGroup"; + }; + return RepeatedGroup; })(); @@ -5278,6 +5498,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for RequiredGroup + * @function getTypeUrl + * @memberof jspb.test.TestGroup.RequiredGroup + * @static + * @returns {string} The default type url + */ + RequiredGroup.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestGroup.RequiredGroup"; + }; + return RequiredGroup; })(); @@ -5467,6 +5698,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for OptionalGroup + * @function getTypeUrl + * @memberof jspb.test.TestGroup.OptionalGroup + * @static + * @returns {string} The default type url + */ + OptionalGroup.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestGroup.OptionalGroup"; + }; + return OptionalGroup; })(); @@ -5662,6 +5904,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestGroup1 + * @function getTypeUrl + * @memberof jspb.test.TestGroup1 + * @static + * @returns {string} The default type url + */ + TestGroup1.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestGroup1"; + }; + return TestGroup1; })(); @@ -5872,6 +6125,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestReservedNames + * @function getTypeUrl + * @memberof jspb.test.TestReservedNames + * @static + * @returns {string} The default type url + */ + TestReservedNames.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestReservedNames"; + }; + return TestReservedNames; })(); @@ -6032,6 +6296,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestReservedNamesExtension + * @function getTypeUrl + * @memberof jspb.test.TestReservedNamesExtension + * @static + * @returns {string} The default type url + */ + TestReservedNamesExtension.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestReservedNamesExtension"; + }; + return TestReservedNamesExtension; })(); @@ -6528,6 +6803,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestMessageWithOneof + * @function getTypeUrl + * @memberof jspb.test.TestMessageWithOneof + * @static + * @returns {string} The default type url + */ + TestMessageWithOneof.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestMessageWithOneof"; + }; + return TestMessageWithOneof; })(); @@ -6747,6 +7033,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestEndsWithBytes + * @function getTypeUrl + * @memberof jspb.test.TestEndsWithBytes + * @static + * @returns {string} The default type url + */ + TestEndsWithBytes.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestEndsWithBytes"; + }; + return TestEndsWithBytes; })(); @@ -7610,6 +7907,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for TestMapFieldsNoBinary + * @function getTypeUrl + * @memberof jspb.test.TestMapFieldsNoBinary + * @static + * @returns {string} The default type url + */ + TestMapFieldsNoBinary.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.TestMapFieldsNoBinary"; + }; + return TestMapFieldsNoBinary; })(); @@ -7813,6 +8121,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MapValueMessageNoBinary + * @function getTypeUrl + * @memberof jspb.test.MapValueMessageNoBinary + * @static + * @returns {string} The default type url + */ + MapValueMessageNoBinary.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.MapValueMessageNoBinary"; + }; + return MapValueMessageNoBinary; })(); @@ -7973,6 +8292,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Deeply + * @function getTypeUrl + * @memberof jspb.test.Deeply + * @static + * @returns {string} The default type url + */ + Deeply.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Deeply"; + }; + Deeply.Nested = (function() { /** @@ -8130,6 +8460,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Nested + * @function getTypeUrl + * @memberof jspb.test.Deeply.Nested + * @static + * @returns {string} The default type url + */ + Nested.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Deeply.Nested"; + }; + Nested.Message = (function() { /** @@ -8314,6 +8655,17 @@ $root.jspb = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Message + * @function getTypeUrl + * @memberof jspb.test.Deeply.Nested.Message + * @static + * @returns {string} The default type url + */ + Message.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/jspb.test.Deeply.Nested.Message"; + }; + return Message; })(); @@ -8552,6 +8904,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for FileDescriptorSet + * @function getTypeUrl + * @memberof google.protobuf.FileDescriptorSet + * @static + * @returns {string} The default type url + */ + FileDescriptorSet.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.FileDescriptorSet"; + }; + return FileDescriptorSet; })(); @@ -9136,6 +9499,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for FileDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.FileDescriptorProto + * @static + * @returns {string} The default type url + */ + FileDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.FileDescriptorProto"; + }; + return FileDescriptorProto; })(); @@ -9692,6 +10066,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for DescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.DescriptorProto + * @static + * @returns {string} The default type url + */ + DescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.DescriptorProto"; + }; + DescriptorProto.ExtensionRange = (function() { /** @@ -9899,6 +10284,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for ExtensionRange + * @function getTypeUrl + * @memberof google.protobuf.DescriptorProto.ExtensionRange + * @static + * @returns {string} The default type url + */ + ExtensionRange.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.DescriptorProto.ExtensionRange"; + }; + return ExtensionRange; })(); @@ -10109,6 +10505,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for ReservedRange + * @function getTypeUrl + * @memberof google.protobuf.DescriptorProto.ReservedRange + * @static + * @returns {string} The default type url + */ + ReservedRange.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.DescriptorProto.ReservedRange"; + }; + return ReservedRange; })(); @@ -10614,6 +11021,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for FieldDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.FieldDescriptorProto + * @static + * @returns {string} The default type url + */ + FieldDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.FieldDescriptorProto"; + }; + /** * Type enum. * @name google.protobuf.FieldDescriptorProto.Type @@ -10891,6 +11309,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for OneofDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.OneofDescriptorProto + * @static + * @returns {string} The default type url + */ + OneofDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.OneofDescriptorProto"; + }; + return OneofDescriptorProto; })(); @@ -11150,6 +11579,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for EnumDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.EnumDescriptorProto + * @static + * @returns {string} The default type url + */ + EnumDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.EnumDescriptorProto"; + }; + return EnumDescriptorProto; })(); @@ -11387,6 +11827,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for EnumValueDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.EnumValueDescriptorProto + * @static + * @returns {string} The default type url + */ + EnumValueDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.EnumValueDescriptorProto"; + }; + return EnumValueDescriptorProto; })(); @@ -11646,6 +12097,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for ServiceDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.ServiceDescriptorProto + * @static + * @returns {string} The default type url + */ + ServiceDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.ServiceDescriptorProto"; + }; + return ServiceDescriptorProto; })(); @@ -11949,6 +12411,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MethodDescriptorProto + * @function getTypeUrl + * @memberof google.protobuf.MethodDescriptorProto + * @static + * @returns {string} The default type url + */ + MethodDescriptorProto.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.MethodDescriptorProto"; + }; + return MethodDescriptorProto; })(); @@ -12485,6 +12958,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for FileOptions + * @function getTypeUrl + * @memberof google.protobuf.FileOptions + * @static + * @returns {string} The default type url + */ + FileOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.FileOptions"; + }; + /** * OptimizeMode enum. * @name google.protobuf.FileOptions.OptimizeMode @@ -12799,6 +13283,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MessageOptions + * @function getTypeUrl + * @memberof google.protobuf.MessageOptions + * @static + * @returns {string} The default type url + */ + MessageOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.MessageOptions"; + }; + return MessageOptions; })(); @@ -13177,6 +13672,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for FieldOptions + * @function getTypeUrl + * @memberof google.protobuf.FieldOptions + * @static + * @returns {string} The default type url + */ + FieldOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.FieldOptions"; + }; + /** * CType enum. * @name google.protobuf.FieldOptions.CType @@ -13417,6 +13923,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for OneofOptions + * @function getTypeUrl + * @memberof google.protobuf.OneofOptions + * @static + * @returns {string} The default type url + */ + OneofOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.OneofOptions"; + }; + return OneofOptions; })(); @@ -13693,6 +14210,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for EnumOptions + * @function getTypeUrl + * @memberof google.protobuf.EnumOptions + * @static + * @returns {string} The default type url + */ + EnumOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.EnumOptions"; + }; + return EnumOptions; })(); @@ -13924,6 +14452,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for EnumValueOptions + * @function getTypeUrl + * @memberof google.protobuf.EnumValueOptions + * @static + * @returns {string} The default type url + */ + EnumValueOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.EnumValueOptions"; + }; + return EnumValueOptions; })(); @@ -14155,6 +14694,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for ServiceOptions + * @function getTypeUrl + * @memberof google.protobuf.ServiceOptions + * @static + * @returns {string} The default type url + */ + ServiceOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.ServiceOptions"; + }; + return ServiceOptions; })(); @@ -14427,6 +14977,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for MethodOptions + * @function getTypeUrl + * @memberof google.protobuf.MethodOptions + * @static + * @returns {string} The default type url + */ + MethodOptions.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.MethodOptions"; + }; + /** * IdempotencyLevel enum. * @name google.protobuf.MethodOptions.IdempotencyLevel @@ -14822,6 +15383,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for UninterpretedOption + * @function getTypeUrl + * @memberof google.protobuf.UninterpretedOption + * @static + * @returns {string} The default type url + */ + UninterpretedOption.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.UninterpretedOption"; + }; + UninterpretedOption.NamePart = (function() { /** @@ -15029,6 +15601,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for NamePart + * @function getTypeUrl + * @memberof google.protobuf.UninterpretedOption.NamePart + * @static + * @returns {string} The default type url + */ + NamePart.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.UninterpretedOption.NamePart"; + }; + return NamePart; })(); @@ -15240,6 +15823,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for SourceCodeInfo + * @function getTypeUrl + * @memberof google.protobuf.SourceCodeInfo + * @static + * @returns {string} The default type url + */ + SourceCodeInfo.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.SourceCodeInfo"; + }; + SourceCodeInfo.Location = (function() { /** @@ -15579,6 +16173,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Location + * @function getTypeUrl + * @memberof google.protobuf.SourceCodeInfo.Location + * @static + * @returns {string} The default type url + */ + Location.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.SourceCodeInfo.Location"; + }; + return Location; })(); @@ -15790,6 +16395,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for GeneratedCodeInfo + * @function getTypeUrl + * @memberof google.protobuf.GeneratedCodeInfo + * @static + * @returns {string} The default type url + */ + GeneratedCodeInfo.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.GeneratedCodeInfo"; + }; + GeneratedCodeInfo.Annotation = (function() { /** @@ -16066,6 +16682,17 @@ $root.google = (function() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; + /** + * Gets the default type url for Annotation + * @function getTypeUrl + * @memberof google.protobuf.GeneratedCodeInfo.Annotation + * @static + * @returns {string} The default type url + */ + Annotation.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/google.protobuf.GeneratedCodeInfo.Annotation"; + }; + return Annotation; })(); diff --git a/tests/data/type_url.js b/tests/data/type_url.js new file mode 100644 index 000000000..901657966 --- /dev/null +++ b/tests/data/type_url.js @@ -0,0 +1,413 @@ +/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ +"use strict"; + +var $protobuf = require("../../minimal"); + +// Common aliases +var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +var $root = $protobuf.roots.test_type_url || ($protobuf.roots.test_type_url = {}); + +$root.TypeUrlTest = (function() { + + /** + * Properties of a TypeUrlTest. + * @exports ITypeUrlTest + * @interface ITypeUrlTest + * @property {TypeUrlTest.INested|null} [nested] TypeUrlTest nested + */ + + /** + * Constructs a new TypeUrlTest. + * @exports TypeUrlTest + * @classdesc Represents a TypeUrlTest. + * @implements ITypeUrlTest + * @constructor + * @param {ITypeUrlTest=} [properties] Properties to set + */ + function TypeUrlTest(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TypeUrlTest nested. + * @member {TypeUrlTest.INested|null|undefined} nested + * @memberof TypeUrlTest + * @instance + */ + TypeUrlTest.prototype.nested = null; + + /** + * Creates a new TypeUrlTest instance using the specified properties. + * @function create + * @memberof TypeUrlTest + * @static + * @param {ITypeUrlTest=} [properties] Properties to set + * @returns {TypeUrlTest} TypeUrlTest instance + */ + TypeUrlTest.create = function create(properties) { + return new TypeUrlTest(properties); + }; + + /** + * Encodes the specified TypeUrlTest message. Does not implicitly {@link TypeUrlTest.verify|verify} messages. + * @function encode + * @memberof TypeUrlTest + * @static + * @param {ITypeUrlTest} message TypeUrlTest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TypeUrlTest.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.nested != null && Object.hasOwnProperty.call(message, "nested")) + $root.TypeUrlTest.Nested.encode(message.nested, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified TypeUrlTest message, length delimited. Does not implicitly {@link TypeUrlTest.verify|verify} messages. + * @function encodeDelimited + * @memberof TypeUrlTest + * @static + * @param {ITypeUrlTest} message TypeUrlTest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TypeUrlTest.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TypeUrlTest message from the specified reader or buffer. + * @function decode + * @memberof TypeUrlTest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {TypeUrlTest} TypeUrlTest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TypeUrlTest.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.TypeUrlTest(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.nested = $root.TypeUrlTest.Nested.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TypeUrlTest message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof TypeUrlTest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {TypeUrlTest} TypeUrlTest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TypeUrlTest.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TypeUrlTest message. + * @function verify + * @memberof TypeUrlTest + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TypeUrlTest.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.nested != null && message.hasOwnProperty("nested")) { + var error = $root.TypeUrlTest.Nested.verify(message.nested); + if (error) + return "nested." + error; + } + return null; + }; + + /** + * Creates a TypeUrlTest message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof TypeUrlTest + * @static + * @param {Object.} object Plain object + * @returns {TypeUrlTest} TypeUrlTest + */ + TypeUrlTest.fromObject = function fromObject(object) { + if (object instanceof $root.TypeUrlTest) + return object; + var message = new $root.TypeUrlTest(); + if (object.nested != null) { + if (typeof object.nested !== "object") + throw TypeError(".TypeUrlTest.nested: object expected"); + message.nested = $root.TypeUrlTest.Nested.fromObject(object.nested); + } + return message; + }; + + /** + * Creates a plain object from a TypeUrlTest message. Also converts values to other types if specified. + * @function toObject + * @memberof TypeUrlTest + * @static + * @param {TypeUrlTest} message TypeUrlTest + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TypeUrlTest.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.nested = null; + if (message.nested != null && message.hasOwnProperty("nested")) + object.nested = $root.TypeUrlTest.Nested.toObject(message.nested, options); + return object; + }; + + /** + * Converts this TypeUrlTest to JSON. + * @function toJSON + * @memberof TypeUrlTest + * @instance + * @returns {Object.} JSON object + */ + TypeUrlTest.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for TypeUrlTest + * @function getTypeUrl + * @memberof TypeUrlTest + * @static + * @returns {string} The default type url + */ + TypeUrlTest.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/TypeUrlTest"; + }; + + TypeUrlTest.Nested = (function() { + + /** + * Properties of a Nested. + * @memberof TypeUrlTest + * @interface INested + * @property {string|null} [a] Nested a + */ + + /** + * Constructs a new Nested. + * @memberof TypeUrlTest + * @classdesc Represents a Nested. + * @implements INested + * @constructor + * @param {TypeUrlTest.INested=} [properties] Properties to set + */ + function Nested(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Nested a. + * @member {string} a + * @memberof TypeUrlTest.Nested + * @instance + */ + Nested.prototype.a = ""; + + /** + * Creates a new Nested instance using the specified properties. + * @function create + * @memberof TypeUrlTest.Nested + * @static + * @param {TypeUrlTest.INested=} [properties] Properties to set + * @returns {TypeUrlTest.Nested} Nested instance + */ + Nested.create = function create(properties) { + return new Nested(properties); + }; + + /** + * Encodes the specified Nested message. Does not implicitly {@link TypeUrlTest.Nested.verify|verify} messages. + * @function encode + * @memberof TypeUrlTest.Nested + * @static + * @param {TypeUrlTest.INested} message Nested message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Nested.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.a != null && Object.hasOwnProperty.call(message, "a")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.a); + return writer; + }; + + /** + * Encodes the specified Nested message, length delimited. Does not implicitly {@link TypeUrlTest.Nested.verify|verify} messages. + * @function encodeDelimited + * @memberof TypeUrlTest.Nested + * @static + * @param {TypeUrlTest.INested} message Nested message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Nested.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Nested message from the specified reader or buffer. + * @function decode + * @memberof TypeUrlTest.Nested + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {TypeUrlTest.Nested} Nested + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Nested.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.TypeUrlTest.Nested(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.a = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Nested message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof TypeUrlTest.Nested + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {TypeUrlTest.Nested} Nested + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Nested.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Nested message. + * @function verify + * @memberof TypeUrlTest.Nested + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Nested.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.a != null && message.hasOwnProperty("a")) + if (!$util.isString(message.a)) + return "a: string expected"; + return null; + }; + + /** + * Creates a Nested message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof TypeUrlTest.Nested + * @static + * @param {Object.} object Plain object + * @returns {TypeUrlTest.Nested} Nested + */ + Nested.fromObject = function fromObject(object) { + if (object instanceof $root.TypeUrlTest.Nested) + return object; + var message = new $root.TypeUrlTest.Nested(); + if (object.a != null) + message.a = String(object.a); + return message; + }; + + /** + * Creates a plain object from a Nested message. Also converts values to other types if specified. + * @function toObject + * @memberof TypeUrlTest.Nested + * @static + * @param {TypeUrlTest.Nested} message Nested + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Nested.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.a = ""; + if (message.a != null && message.hasOwnProperty("a")) + object.a = message.a; + return object; + }; + + /** + * Converts this Nested to JSON. + * @function toJSON + * @memberof TypeUrlTest.Nested + * @instance + * @returns {Object.} JSON object + */ + Nested.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for Nested + * @function getTypeUrl + * @memberof TypeUrlTest.Nested + * @static + * @returns {string} The default type url + */ + Nested.getTypeUrl = function getTypeUrl() { + return "type.googleapis.com/TypeUrlTest.Nested"; + }; + + return Nested; + })(); + + return TypeUrlTest; +})(); + +module.exports = $root; diff --git a/tests/data/type_url.proto b/tests/data/type_url.proto new file mode 100644 index 000000000..7255b69b7 --- /dev/null +++ b/tests/data/type_url.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +message TypeUrlTest { + message Nested { + string a = 1; + } + Nested nested = 1; +} diff --git a/tests/gen_type_url.js b/tests/gen_type_url.js new file mode 100644 index 000000000..da9bc3169 --- /dev/null +++ b/tests/gen_type_url.js @@ -0,0 +1,9 @@ +var tape = require("tape"); + +var TypeUrlTest = require("./data/type_url").TypeUrlTest; + +tape.test("getTypeUrl method", function(test) { + test.equal(TypeUrlTest.getTypeUrl(), "type.googleapis.com/TypeUrlTest", "should have a valid type url"); + test.equal(TypeUrlTest.Nested.getTypeUrl(), "type.googleapis.com/TypeUrlTest.Nested", "nested messages should have a valid type url"); + test.end(); +});