Skip to content

Commit

Permalink
Add dropOptions when serializing descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
PG Herveou authored Sep 11, 2020
1 parent 78c3e49 commit 09ed37d
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 44 deletions.
36 changes: 26 additions & 10 deletions dist/light/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/light/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/light/protobuf.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/minimal/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/minimal/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 28 additions & 11 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,9 @@ export interface IToJSONOptions {

/** Serializes comments. */
keepComments?: boolean;

/** Serializes options. */
dropOptions?: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pgherveou/protobufjs",
"version": "1.0.9",
"version": "1.0.10",
"versionScheme": "~",
"description": "Protocol Buffers for JavaScript (& TypeScript).",
"author": "Daniel Wirtz <[email protected]>",
Expand Down
4 changes: 3 additions & 1 deletion src/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ Enum.fromJSON = function fromJSON(name, json) {
*/
Enum.prototype.toJSON = function toJSON(toJSONOptions) {
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , this.options,
"options" , dropOptions ? undefined : this.options,
"values" , this.values,
"reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
"comment" , keepComments ? this.comment : undefined,
Expand Down
4 changes: 3 additions & 1 deletion src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,14 @@ Field.prototype.setOption = function setOption(name, value, ifNotSet) {
*/
Field.prototype.toJSON = function toJSON(toJSONOptions) {
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , dropOptions ? undefined : this.options,
"rule" , this.rule !== "optional" && this.rule || undefined,
"type" , this.type,
"id" , this.id,
"extend" , this.extend,
"options" , this.options,
"comment" , keepComments ? this.comment : undefined
]);
};
Expand Down
4 changes: 3 additions & 1 deletion src/mapfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ MapField.fromJSON = function fromJSON(name, json) {
*/
MapField.prototype.toJSON = function toJSON(toJSONOptions) {
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , dropOptions ? undefined : this.options,
"keyType" , this.keyType,
"type" , this.type,
"id" , this.id,
"extend" , this.extend,
"options" , this.options,
"comment" , keepComments ? this.comment : undefined
]);
};
Expand Down
4 changes: 3 additions & 1 deletion src/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ Method.fromJSON = function fromJSON(name, json) {
*/
Method.prototype.toJSON = function toJSON(toJSONOptions) {
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , dropOptions ? undefined : this.options,
"type" , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,
"requestType" , this.requestType,
"requestStream" , this.requestStream,
"responseType" , this.responseType,
"responseStream" , this.responseStream,
"options" , this.options,
"comment" , keepComments ? this.comment : undefined
]);
};
Expand Down
4 changes: 3 additions & 1 deletion src/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ Object.defineProperty(Namespace.prototype, "nestedArray", {
* @returns {INamespace} Namespace descriptor
*/
Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , this.options,
"options" , dropOptions ? undefined : this.options,
"nested" , arrayToJSON(this.nestedArray, toJSONOptions)
]);
};
Expand Down
4 changes: 3 additions & 1 deletion src/oneof.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ OneOf.fromJSON = function fromJSON(name, json) {
*/
OneOf.prototype.toJSON = function toJSON(toJSONOptions) {
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , this.options,
"options" , dropOptions ? undefined : this.options,
"oneof" , this.oneof,
"comment" , keepComments ? this.comment : undefined
]);
Expand Down
1 change: 1 addition & 0 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var base10Re = /^[1-9][0-9]*$/,
* Options modifying the behavior of JSON serialization.
* @interface IToJSONOptions
* @property {boolean} [keepComments=false] Serializes comments.
* @property {boolean} [dropOptions=false] Serializes options.
*/

/**
Expand Down
4 changes: 3 additions & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ Service.fromJSON = function fromJSON(name, json) {
Service.prototype.toJSON = function toJSON(toJSONOptions) {
var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
var dropOptions = toJSONOptions ? Boolean(toJSONOptions.dropOptions) : false;

return util.toObject([
"options" , inherited && inherited.options || undefined,
"options" , dropOptions ? undefined : this.options,
"methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
"nested" , inherited && inherited.nested || undefined,
"comment" , keepComments ? this.comment : undefined
Expand Down
Loading

0 comments on commit 09ed37d

Please sign in to comment.