Skip to content

Commit

Permalink
CLI: Extend $Properties instead of implementing it, see #723
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 24, 2017
1 parent a1f23e0 commit 1b9db19
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 267 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,14 @@ var buffer = AwesomeMessage.encode(message).finish();
...
```

If you'd like to completely exclude long.js and/or node (Buffer) typings, there are two stubs available that can be referenced instead of the full type definitions:
**Note:** By default, the npm package ships with long.js including its typings and node typing as optional dependencies. However, where long.js and/or node Buffers are not required, there are two stubs available that can be referenced instead of the full type definitions:

```ts
/// <reference path="node_modules/protobufjs/stub-long.d.ts" />
/// <reference path="node_modules/protobufjs/stub-node.d.ts" />
/// <reference path="./node_modules/protobufjs/stub-long.d.ts" />
```

```ts
/// <reference path="./node_modules/protobufjs/stub-node.d.ts" />
```

Documentation
Expand Down
10 changes: 5 additions & 5 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ function toJsType(field) {
return "Uint8Array";
default:
if (field.resolvedType instanceof Enum)
return "number";
return field.resolvedType.fullName.substring(1); // reference the enum
if (field.resolvedType instanceof Type)
return field.resolvedType.fullName.substring(1) + "$Properties";
return field.resolvedType.fullName.substring(1) + "$Properties"; // reference the interface
return "*"; // should not happen
}
}
Expand Down Expand Up @@ -309,7 +309,7 @@ function buildType(ref, type) {
"Constructs a new " + type.name + ".",
type.comment ? "@classdesc " + type.comment : null,
"@exports " + fullName,
"@implements " + fullName + "$Properties",
"@extends " + fullName + "$Properties",
"@constructor",
"@param {" + fullName + "$Properties=} [" + (config.beautify ? "properties" : "p") + "] Properties to set"
]);
Expand All @@ -325,9 +325,9 @@ function buildType(ref, type) {
firstField = false;
}
if (field.repeated)
push(name(type.name) + ".prototype" + prop + " = $util.emptyArray;");
push(name(type.name) + ".prototype" + prop + " = $util.emptyArray;"); // overwritten in constructor
else if (field.map)
push(name(type.name) + ".prototype" + prop + " = $util.emptyObject;");
push(name(type.name) + ".prototype" + prop + " = $util.emptyObject;"); // overwritten in constructor
else if (field.long)
push(name(type.name) + ".prototype" + prop + " = $util.Long ? $util.Long.fromBits("
+ JSON.stringify(field.typeDefault.low) + ","
Expand Down
4 changes: 2 additions & 2 deletions tests/data/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $root.Test1 = (function() {
* a
* comment.
* @exports Test1
* @implements Test1$Properties
* @extends Test1$Properties
* @constructor
* @param {Test1$Properties=} [properties] Properties to set
*/
Expand Down Expand Up @@ -225,7 +225,7 @@ $root.Test2 = (function() {
/**
* Constructs a new Test2.
* @exports Test2
* @implements Test2$Properties
* @extends Test2$Properties
* @constructor
* @param {Test2$Properties=} [properties] Properties to set
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ $root.Message = (function() {
* @property {Array.<number|Long>} [uint64Repeated] Message uint64Repeated.
* @property {Uint8Array} [bytesVal] Message bytesVal.
* @property {Array.<Uint8Array>} [bytesRepeated] Message bytesRepeated.
* @property {number} [enumVal] Message enumVal.
* @property {Array.<number>} [enumRepeated] Message enumRepeated.
* @property {Message.SomeEnum} [enumVal] Message enumVal.
* @property {Array.<Message.SomeEnum>} [enumRepeated] Message enumRepeated.
* @property {Object.<string,number|Long>} [int64Map] Message int64Map.
*/

/**
* Constructs a new Message.
* @exports Message
* @implements Message$Properties
* @extends Message$Properties
* @constructor
* @param {Message$Properties=} [properties] Properties to set
*/
Expand Down
10 changes: 5 additions & 5 deletions tests/data/mapbox/vector_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ $root.vector_tile = (function() {
* Properties of a Tile.
* @typedef vector_tile.Tile$Properties
* @type Object
* @property {Array.<vector_tile.Tile.Layer>} [layers] Tile layers.
* @property {Array.<vector_tile.Tile.Layer$Properties>} [layers] Tile layers.
*/

/**
* Constructs a new Tile.
* @exports vector_tile.Tile
* @implements vector_tile.Tile$Properties
* @extends vector_tile.Tile$Properties
* @constructor
* @param {vector_tile.Tile$Properties=} [properties] Properties to set
*/
Expand Down Expand Up @@ -243,7 +243,7 @@ $root.vector_tile = (function() {
/**
* Constructs a new Value.
* @exports vector_tile.Tile.Value
* @implements vector_tile.Tile.Value$Properties
* @extends vector_tile.Tile.Value$Properties
* @constructor
* @param {vector_tile.Tile.Value$Properties=} [properties] Properties to set
*/
Expand Down Expand Up @@ -543,7 +543,7 @@ $root.vector_tile = (function() {
/**
* Constructs a new Feature.
* @exports vector_tile.Tile.Feature
* @implements vector_tile.Tile.Feature$Properties
* @extends vector_tile.Tile.Feature$Properties
* @constructor
* @param {vector_tile.Tile.Feature$Properties=} [properties] Properties to set
*/
Expand Down Expand Up @@ -848,7 +848,7 @@ $root.vector_tile = (function() {
/**
* Constructs a new Layer.
* @exports vector_tile.Tile.Layer
* @implements vector_tile.Tile.Layer$Properties
* @extends vector_tile.Tile.Layer$Properties
* @constructor
* @param {vector_tile.Tile.Layer$Properties=} [properties] Properties to set
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $root.Package = (function() {
* @property {string} [description] Package description.
* @property {string} [author] Package author.
* @property {string} [license] Package license.
* @property {Package.Repository} [repository] Package repository.
* @property {Package.Repository$Properties} [repository] Package repository.
* @property {string} [bugs] Package bugs.
* @property {string} [homepage] Package homepage.
* @property {Array.<string>} [keywords] Package keywords.
Expand All @@ -38,7 +38,7 @@ $root.Package = (function() {
/**
* Constructs a new Package.
* @exports Package
* @implements Package$Properties
* @extends Package$Properties
* @constructor
* @param {Package$Properties=} [properties] Properties to set
*/
Expand Down Expand Up @@ -587,7 +587,7 @@ $root.Package = (function() {
/**
* Constructs a new Repository.
* @exports Package.Repository
* @implements Package.Repository$Properties
* @extends Package.Repository$Properties
* @constructor
* @param {Package.Repository$Properties=} [properties] Properties to set
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/data/rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type MyRequest$Properties = {
path?: string;
};

export class MyRequest implements MyRequest$Properties {
export class MyRequest extends MyRequest$Properties {
constructor(properties?: MyRequest$Properties);
public static create(properties?: MyRequest$Properties): MyRequest;
public static encode(message: MyRequest$Properties, writer?: $protobuf.Writer): $protobuf.Writer;
Expand All @@ -32,7 +32,7 @@ type MyResponse$Properties = {
status?: number;
};

export class MyResponse implements MyResponse$Properties {
export class MyResponse extends MyResponse$Properties {
constructor(properties?: MyResponse$Properties);
public static create(properties?: MyResponse$Properties): MyResponse;
public static encode(message: MyResponse$Properties, writer?: $protobuf.Writer): $protobuf.Writer;
Expand Down
4 changes: 2 additions & 2 deletions tests/data/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $root.MyRequest = (function() {
/**
* Constructs a new MyRequest.
* @exports MyRequest
* @implements MyRequest$Properties
* @extends MyRequest$Properties
* @constructor
* @param {MyRequest$Properties=} [properties] Properties to set
*/
Expand Down Expand Up @@ -249,7 +249,7 @@ $root.MyResponse = (function() {
/**
* Constructs a new MyResponse.
* @exports MyResponse
* @implements MyResponse$Properties
* @extends MyResponse$Properties
* @constructor
* @param {MyResponse$Properties=} [properties] Properties to set
*/
Expand Down
Loading

0 comments on commit 1b9db19

Please sign in to comment.