protobufjs 6.8.4 → 6.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +2 -2
  3. package/cli/node_modules/os-tmpdir/index.js +25 -0
  4. package/cli/node_modules/os-tmpdir/license +21 -0
  5. package/cli/node_modules/os-tmpdir/readme.md +32 -0
  6. package/cli/node_modules/tmp/LICENSE +21 -0
  7. package/cli/node_modules/tmp/README.md +314 -0
  8. package/cli/node_modules/tmp/lib/tmp.js +611 -0
  9. package/cli/pbjs.d.ts +1 -1
  10. package/cli/pbjs.js +11 -1
  11. package/cli/pbts.d.ts +1 -1
  12. package/cli/pbts.js +36 -7
  13. package/cli/targets/proto.js +1 -1
  14. package/cli/targets/static.js +3 -6
  15. package/dist/light/protobuf.js +143 -64
  16. package/dist/light/protobuf.js.map +1 -1
  17. package/dist/light/protobuf.min.js +3 -3
  18. package/dist/light/protobuf.min.js.map +1 -1
  19. package/dist/minimal/protobuf.js +23 -14
  20. package/dist/minimal/protobuf.js.map +1 -1
  21. package/dist/minimal/protobuf.min.js +3 -3
  22. package/dist/minimal/protobuf.min.js.map +1 -1
  23. package/dist/protobuf.js +268 -90
  24. package/dist/protobuf.js.map +1 -1
  25. package/dist/protobuf.min.js +3 -3
  26. package/dist/protobuf.min.js.map +1 -1
  27. package/ext/descriptor/index.d.ts +0 -1
  28. package/ext/descriptor/index.js +3 -0
  29. package/index.d.ts +57 -16
  30. package/package-lock.json +4579 -3191
  31. package/package.json +122 -125
  32. package/src/common.js +22 -1
  33. package/src/converter.js +9 -3
  34. package/src/enum.js +17 -5
  35. package/src/field.js +17 -4
  36. package/src/index-light.js +2 -2
  37. package/src/index-minimal.js +1 -1
  38. package/src/mapfield.js +9 -5
  39. package/src/message.js +1 -1
  40. package/src/method.js +14 -4
  41. package/src/namespace.js +14 -10
  42. package/src/object.js +1 -0
  43. package/src/oneof.js +14 -4
  44. package/src/parse.js +11 -3
  45. package/src/reader.js +2 -4
  46. package/src/root.js +3 -2
  47. package/src/service.js +8 -4
  48. package/src/tokenize.js +92 -22
  49. package/src/type.js +10 -5
  50. package/src/util/minimal.js +11 -2
  51. package/google/protobuf/field_mask.json +0 -21
  52. package/google/protobuf/field_mask.proto +0 -7
package/package.json CHANGED
@@ -1,125 +1,122 @@
1
- {
2
- "name": "protobufjs",
3
- "version": "6.8.4",
4
- "versionScheme": "~",
5
- "description": "Protocol Buffers for JavaScript (& TypeScript).",
6
- "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
7
- "license": "BSD-3-Clause",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/dcodeIO/protobuf.js.git"
11
- },
12
- "bugs": "https://github.com/dcodeIO/protobuf.js/issues",
13
- "homepage": "http://dcode.io/protobuf.js",
14
- "keywords": [
15
- "protobuf",
16
- "protocol-buffers",
17
- "serialization",
18
- "typescript"
19
- ],
20
- "main": "index.js",
21
- "types": "index.d.ts",
22
- "bin": {
23
- "pbjs": "bin/pbjs",
24
- "pbts": "bin/pbts"
25
- },
26
- "scripts": {
27
- "bench": "node bench",
28
- "build": "gulp --gulpfile scripts/gulpfile.js",
29
- "changelog": "node scripts/changelog -w",
30
- "coverage": "istanbul --config=config/istanbul.json cover node_modules/tape/bin/tape tests/*.js tests/node/*.js",
31
- "coverage-ci": "npm run coverage && codeclimate-test-reporter < coverage/lcov.info",
32
- "docs": "jsdoc -c config/jsdoc.json -R README.md --verbose --pedantic",
33
- "lint": "eslint **/*.js -c config/eslint.json && tslint **/*.d.ts -e **/node_modules/** -t stylish -c config/tslint.json",
34
- "pages": "node scripts/pages",
35
- "prepublish": "node scripts/prepublish",
36
- "postinstall": "node scripts/postinstall",
37
- "prof": "node bench/prof",
38
- "test": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js | tap-spec",
39
- "test-types": "tsc tests/comp_typescript.ts --lib es2015 --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc tests/data/test.js.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
40
- "types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js && npm run test-types",
41
- "make": "npm run test && npm run types && npm run build && npm run lint",
42
- "release": "npm run make && npm run changelog"
43
- },
44
- "dependencies": {
45
- "@protobufjs/aspromise": "^1.1.2",
46
- "@protobufjs/base64": "^1.1.2",
47
- "@protobufjs/codegen": "^2.0.4",
48
- "@protobufjs/eventemitter": "^1.1.0",
49
- "@protobufjs/fetch": "^1.1.0",
50
- "@protobufjs/float": "^1.0.2",
51
- "@protobufjs/inquire": "^1.1.0",
52
- "@protobufjs/path": "^1.1.2",
53
- "@protobufjs/pool": "^1.1.0",
54
- "@protobufjs/utf8": "^1.1.0",
55
- "@types/long": "^3.0.32",
56
- "@types/node": "^8.5.5",
57
- "long": "^3.2.0"
58
- },
59
- "devDependencies": {
60
- "benchmark": "^2.1.4",
61
- "browserify": "^14.5.0",
62
- "browserify-wrap": "^1.0.2",
63
- "bundle-collapser": "^1.3.0",
64
- "chalk": "^1.1.3",
65
- "codeclimate-test-reporter": "^0.5.0",
66
- "escodegen": "^1.9.0",
67
- "eslint": "^3.19.0",
68
- "espree": "^3.5.2",
69
- "estraverse": "^4.2.0",
70
- "gh-pages": "^0.12.0",
71
- "git-raw-commits": "^1.3.0",
72
- "git-semver-tags": "^1.2.3",
73
- "glob": "^7.1.2",
74
- "google-protobuf": "^3.5.0",
75
- "gulp": "^3.9.1",
76
- "gulp-header": "^1.8.9",
77
- "gulp-if": "^2.0.1",
78
- "gulp-sourcemaps": "^2.6.3",
79
- "gulp-uglify": "^2.1.2",
80
- "istanbul": "^0.4.5",
81
- "jaguarjs-jsdoc": "github:dcodeIO/jaguarjs-jsdoc",
82
- "jsdoc": "^3.5.5",
83
- "minimist": "^1.2.0",
84
- "reflect-metadata": "^0.1.10",
85
- "semver": "^5.4.1",
86
- "tap-spec": "^4.1.1",
87
- "tape": "^4.8.0",
88
- "tmp": "0.0.33",
89
- "tslint": "^5.8.0",
90
- "typescript": "^2.6.2",
91
- "uglify-js": "^2.8.29",
92
- "vinyl-buffer": "^1.0.1",
93
- "vinyl-fs": "^2.4.4",
94
- "vinyl-source-stream": "^1.1.2"
95
- },
96
- "cliDependencies": [
97
- "semver",
98
- "chalk",
99
- "glob",
100
- "jsdoc",
101
- "minimist",
102
- "tmp",
103
- "uglify-js",
104
- "espree",
105
- "escodegen",
106
- "estraverse"
107
- ],
108
- "files": [
109
- "index.js",
110
- "index.d.ts",
111
- "light.d.ts",
112
- "light.js",
113
- "minimal.d.ts",
114
- "minimal.js",
115
- "package-lock.json",
116
- "tsconfig.json",
117
- "scripts/postinstall.js",
118
- "bin/**",
119
- "cli/**",
120
- "dist/**",
121
- "ext/**",
122
- "google/**",
123
- "src/**"
124
- ]
125
- }
1
+ {
2
+ "name": "protobufjs",
3
+ "version": "6.8.8",
4
+ "versionScheme": "~",
5
+ "description": "Protocol Buffers for JavaScript (& TypeScript).",
6
+ "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
7
+ "license": "BSD-3-Clause",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/dcodeIO/protobuf.js.git"
11
+ },
12
+ "bugs": "https://github.com/dcodeIO/protobuf.js/issues",
13
+ "homepage": "http://dcode.io/protobuf.js",
14
+ "keywords": [
15
+ "protobuf",
16
+ "protocol-buffers",
17
+ "serialization",
18
+ "typescript"
19
+ ],
20
+ "main": "index.js",
21
+ "types": "index.d.ts",
22
+ "bin": {
23
+ "pbjs": "bin/pbjs",
24
+ "pbts": "bin/pbts"
25
+ },
26
+ "scripts": {
27
+ "bench": "node bench",
28
+ "build": "gulp --gulpfile scripts/gulpfile.js",
29
+ "changelog": "node scripts/changelog -w",
30
+ "coverage": "istanbul --config=config/istanbul.json cover node_modules/tape/bin/tape tests/*.js tests/node/*.js",
31
+ "docs": "jsdoc -c config/jsdoc.json -R README.md --verbose --pedantic",
32
+ "lint": "eslint **/*.js -c config/eslint.json && tslint **/*.d.ts -e **/node_modules/** -t stylish -c config/tslint.json",
33
+ "pages": "node scripts/pages",
34
+ "prepublish": "node scripts/prepublish",
35
+ "postinstall": "node scripts/postinstall",
36
+ "prof": "node bench/prof",
37
+ "test": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
38
+ "test-types": "tsc tests/comp_typescript.ts --lib es2015 --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc tests/data/test.js.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/rpc.ts --lib es2015 --noEmit --strictNullChecks",
39
+ "types": "node bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js && npm run test-types",
40
+ "make": "npm run test && npm run types && npm run build && npm run lint",
41
+ "release": "npm run make && npm run changelog"
42
+ },
43
+ "dependencies": {
44
+ "@protobufjs/aspromise": "^1.1.2",
45
+ "@protobufjs/base64": "^1.1.2",
46
+ "@protobufjs/codegen": "^2.0.4",
47
+ "@protobufjs/eventemitter": "^1.1.0",
48
+ "@protobufjs/fetch": "^1.1.0",
49
+ "@protobufjs/float": "^1.0.2",
50
+ "@protobufjs/inquire": "^1.1.0",
51
+ "@protobufjs/path": "^1.1.2",
52
+ "@protobufjs/pool": "^1.1.0",
53
+ "@protobufjs/utf8": "^1.1.0",
54
+ "@types/long": "^4.0.0",
55
+ "@types/node": "^10.1.0",
56
+ "long": "^4.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "benchmark": "^2.1.4",
60
+ "browserify": "^16.2.2",
61
+ "browserify-wrap": "^1.0.2",
62
+ "bundle-collapser": "^1.3.0",
63
+ "chalk": "^2.4.1",
64
+ "escodegen": "^1.9.1",
65
+ "eslint": "^4.19.1",
66
+ "espree": "^3.5.4",
67
+ "estraverse": "^4.2.0",
68
+ "gh-pages": "^1.1.0",
69
+ "git-raw-commits": "^1.3.6",
70
+ "git-semver-tags": "^1.3.6",
71
+ "glob": "^7.1.2",
72
+ "google-protobuf": "^3.5.0",
73
+ "gulp": "^4.0.0",
74
+ "gulp-header": "^2.0.5",
75
+ "gulp-if": "^2.0.1",
76
+ "gulp-sourcemaps": "^2.6.4",
77
+ "gulp-uglify": "^3.0.0",
78
+ "istanbul": "^0.4.5",
79
+ "jaguarjs-jsdoc": "github:dcodeIO/jaguarjs-jsdoc",
80
+ "jsdoc": "^3.5.5",
81
+ "minimist": "^1.2.0",
82
+ "reflect-metadata": "^0.1.12",
83
+ "semver": "^5.5.0",
84
+ "tape": "^4.9.0",
85
+ "tmp": "0.0.33",
86
+ "tslint": "^5.10.0",
87
+ "typescript": "^2.8.3",
88
+ "uglify-js": "^3.3.25",
89
+ "vinyl-buffer": "^1.0.1",
90
+ "vinyl-fs": "^3.0.3",
91
+ "vinyl-source-stream": "^2.0.0"
92
+ },
93
+ "cliDependencies": [
94
+ "semver",
95
+ "chalk",
96
+ "glob",
97
+ "jsdoc",
98
+ "minimist",
99
+ "tmp",
100
+ "uglify-js",
101
+ "espree",
102
+ "escodegen",
103
+ "estraverse"
104
+ ],
105
+ "files": [
106
+ "index.js",
107
+ "index.d.ts",
108
+ "light.d.ts",
109
+ "light.js",
110
+ "minimal.d.ts",
111
+ "minimal.js",
112
+ "package-lock.json",
113
+ "tsconfig.json",
114
+ "scripts/postinstall.js",
115
+ "bin/**",
116
+ "cli/**",
117
+ "dist/**",
118
+ "ext/**",
119
+ "google/**",
120
+ "src/**"
121
+ ]
122
+ }
package/src/common.js CHANGED
@@ -12,6 +12,7 @@ var commonRe = /\/|\./;
12
12
  * @property {INamespace} google/protobuf/any.proto Any
13
13
  * @property {INamespace} google/protobuf/duration.proto Duration
14
14
  * @property {INamespace} google/protobuf/empty.proto Empty
15
+ * @property {INamespace} google/protobuf/field_mask.proto FieldMask
15
16
  * @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
16
17
  * @property {INamespace} google/protobuf/timestamp.proto Timestamp
17
18
  * @property {INamespace} google/protobuf/wrappers.proto Wrappers
@@ -33,7 +34,6 @@ function common(name, json) {
33
34
  // Not provided because of limited use (feel free to discuss or to provide yourself):
34
35
  //
35
36
  // google/protobuf/descriptor.proto
36
- // google/protobuf/field_mask.proto
37
37
  // google/protobuf/source_context.proto
38
38
  // google/protobuf/type.proto
39
39
  //
@@ -359,6 +359,26 @@ common("wrappers", {
359
359
  }
360
360
  });
361
361
 
362
+ common("field_mask", {
363
+
364
+ /**
365
+ * Properties of a google.protobuf.FieldMask message.
366
+ * @interface IDoubleValue
367
+ * @type {Object}
368
+ * @property {number} [value]
369
+ * @memberof common
370
+ */
371
+ FieldMask: {
372
+ fields: {
373
+ paths: {
374
+ rule: "repeated",
375
+ type: "string",
376
+ id: 1
377
+ }
378
+ }
379
+ }
380
+ });
381
+
362
382
  /**
363
383
  * Gets the root definition of the specified common proto file.
364
384
  *
@@ -366,6 +386,7 @@ common("wrappers", {
366
386
  * - google/protobuf/any.proto
367
387
  * - google/protobuf/duration.proto
368
388
  * - google/protobuf/empty.proto
389
+ * - google/protobuf/field_mask.proto
369
390
  * - google/protobuf/struct.proto
370
391
  * - google/protobuf/timestamp.proto
371
392
  * - google/protobuf/wrappers.proto
package/src/converter.js CHANGED
@@ -244,9 +244,15 @@ converter.toObject = function toObject(mtype) {
244
244
  ("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
245
245
  ("}else")
246
246
  ("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
247
- else if (field.bytes) gen
248
- ("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");
249
- else gen
247
+ else if (field.bytes) {
248
+ var arrayDefault = "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]";
249
+ gen
250
+ ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
251
+ ("else{")
252
+ ("d%s=%s", prop, arrayDefault)
253
+ ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
254
+ ("}");
255
+ } else gen
250
256
  ("d%s=%j", prop, field.typeDefault); // also messages (=null)
251
257
  } gen
252
258
  ("}");
package/src/enum.js CHANGED
@@ -16,8 +16,10 @@ var Namespace = require("./namespace"),
16
16
  * @param {string} name Unique name within its namespace
17
17
  * @param {Object.<string,number>} [values] Enum values as an object, by name
18
18
  * @param {Object.<string,*>} [options] Declared options
19
+ * @param {string} [comment] The comment for this enum
20
+ * @param {Object.<string,string>} [comments] The value comments for this enum
19
21
  */
20
- function Enum(name, values, options) {
22
+ function Enum(name, values, options, comment, comments) {
21
23
  ReflectionObject.call(this, name, options);
22
24
 
23
25
  if (values && typeof values !== "object")
@@ -35,11 +37,17 @@ function Enum(name, values, options) {
35
37
  */
36
38
  this.values = Object.create(this.valuesById); // toJSON, marker
37
39
 
40
+ /**
41
+ * Enum comment text.
42
+ * @type {string|null}
43
+ */
44
+ this.comment = comment;
45
+
38
46
  /**
39
47
  * Value comment texts, if any.
40
48
  * @type {Object.<string,string>}
41
49
  */
42
- this.comments = {};
50
+ this.comments = comments || {};
43
51
 
44
52
  /**
45
53
  * Reserved ranges, if any.
@@ -72,20 +80,24 @@ function Enum(name, values, options) {
72
80
  * @throws {TypeError} If arguments are invalid
73
81
  */
74
82
  Enum.fromJSON = function fromJSON(name, json) {
75
- var enm = new Enum(name, json.values, json.options);
83
+ var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
76
84
  enm.reserved = json.reserved;
77
85
  return enm;
78
86
  };
79
87
 
80
88
  /**
81
89
  * Converts this enum to an enum descriptor.
90
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
82
91
  * @returns {IEnum} Enum descriptor
83
92
  */
84
- Enum.prototype.toJSON = function toJSON() {
93
+ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
94
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
85
95
  return util.toObject([
86
96
  "options" , this.options,
87
97
  "values" , this.values,
88
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined
98
+ "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
99
+ "comment" , keepComments ? this.comment : undefined,
100
+ "comments" , keepComments ? this.comments : undefined
89
101
  ]);
90
102
  };
91
103
 
package/src/field.js CHANGED
@@ -35,7 +35,7 @@ var ruleRe = /^required|optional|repeated$/;
35
35
  * @throws {TypeError} If arguments are invalid
36
36
  */
37
37
  Field.fromJSON = function fromJSON(name, json) {
38
- return new Field(name, json.id, json.type, json.rule, json.extend, json.options);
38
+ return new Field(name, json.id, json.type, json.rule, json.extend, json.options, json.comment);
39
39
  };
40
40
 
41
41
  /**
@@ -50,13 +50,16 @@ Field.fromJSON = function fromJSON(name, json) {
50
50
  * @param {string|Object.<string,*>} [rule="optional"] Field rule
51
51
  * @param {string|Object.<string,*>} [extend] Extended type if different from parent
52
52
  * @param {Object.<string,*>} [options] Declared options
53
+ * @param {string} [comment] Comment associated with this field
53
54
  */
54
- function Field(name, id, type, rule, extend, options) {
55
+ function Field(name, id, type, rule, extend, options, comment) {
55
56
 
56
57
  if (util.isObject(rule)) {
58
+ comment = extend;
57
59
  options = rule;
58
60
  rule = extend = undefined;
59
61
  } else if (util.isObject(extend)) {
62
+ comment = options;
60
63
  options = extend;
61
64
  extend = undefined;
62
65
  }
@@ -183,6 +186,12 @@ function Field(name, id, type, rule, extend, options) {
183
186
  * @private
184
187
  */
185
188
  this._packed = null;
189
+
190
+ /**
191
+ * Comment for this field.
192
+ * @type {string|null}
193
+ */
194
+ this.comment = comment;
186
195
  }
187
196
 
188
197
  /**
@@ -227,15 +236,18 @@ Field.prototype.setOption = function setOption(name, value, ifNotSet) {
227
236
 
228
237
  /**
229
238
  * Converts this field to a field descriptor.
239
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
230
240
  * @returns {IField} Field descriptor
231
241
  */
232
- Field.prototype.toJSON = function toJSON() {
242
+ Field.prototype.toJSON = function toJSON(toJSONOptions) {
243
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
233
244
  return util.toObject([
234
245
  "rule" , this.rule !== "optional" && this.rule || undefined,
235
246
  "type" , this.type,
236
247
  "id" , this.id,
237
248
  "extend" , this.extend,
238
- "options" , this.options
249
+ "options" , this.options,
250
+ "comment" , keepComments ? this.comment : undefined
239
251
  ]);
240
252
  };
241
253
 
@@ -353,6 +365,7 @@ Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
353
365
  */
354
366
  // like Field.d but without a default value
355
367
 
368
+ // Sets up cyclic dependencies (called in index-light)
356
369
  Field._configure = function configure(Type_) {
357
370
  Type = Type_;
358
371
  };
@@ -97,8 +97,8 @@ protobuf.wrappers = require("./wrappers");
97
97
  protobuf.types = require("./types");
98
98
  protobuf.util = require("./util");
99
99
 
100
- // Configure reflection
100
+ // Set up possibly cyclic reflection dependencies
101
101
  protobuf.ReflectionObject._configure(protobuf.Root);
102
- protobuf.Namespace._configure(protobuf.Type, protobuf.Service);
102
+ protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
103
103
  protobuf.Root._configure(protobuf.Type);
104
104
  protobuf.Field._configure(protobuf.Type);
@@ -31,6 +31,6 @@ function configure() {
31
31
  protobuf.util._configure();
32
32
  }
33
33
 
34
- // Configure serialization
34
+ // Set up buffer utility according to the environment
35
35
  protobuf.Writer._configure(protobuf.BufferWriter);
36
36
  configure();
package/src/mapfield.js CHANGED
@@ -18,9 +18,10 @@ var types = require("./types"),
18
18
  * @param {string} keyType Key type
19
19
  * @param {string} type Value type
20
20
  * @param {Object.<string,*>} [options] Declared options
21
+ * @param {string} [comment] Comment associated with this field
21
22
  */
22
- function MapField(name, id, keyType, type, options) {
23
- Field.call(this, name, id, type, options);
23
+ function MapField(name, id, keyType, type, options, comment) {
24
+ Field.call(this, name, id, type, undefined, undefined, options, comment);
24
25
 
25
26
  /* istanbul ignore if */
26
27
  if (!util.isString(keyType))
@@ -64,20 +65,23 @@ function MapField(name, id, keyType, type, options) {
64
65
  * @throws {TypeError} If arguments are invalid
65
66
  */
66
67
  MapField.fromJSON = function fromJSON(name, json) {
67
- return new MapField(name, json.id, json.keyType, json.type, json.options);
68
+ return new MapField(name, json.id, json.keyType, json.type, json.options, json.comment);
68
69
  };
69
70
 
70
71
  /**
71
72
  * Converts this map field to a map field descriptor.
73
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
72
74
  * @returns {IMapField} Map field descriptor
73
75
  */
74
- MapField.prototype.toJSON = function toJSON() {
76
+ MapField.prototype.toJSON = function toJSON(toJSONOptions) {
77
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
75
78
  return util.toObject([
76
79
  "keyType" , this.keyType,
77
80
  "type" , this.type,
78
81
  "id" , this.id,
79
82
  "extend" , this.extend,
80
- "options" , this.options
83
+ "options" , this.options,
84
+ "comment" , keepComments ? this.comment : undefined
81
85
  ]);
82
86
  };
83
87
 
package/src/message.js CHANGED
@@ -8,7 +8,7 @@ var util = require("./util/minimal");
8
8
  * @classdesc Abstract runtime message.
9
9
  * @constructor
10
10
  * @param {Properties<T>} [properties] Properties to set
11
- * @template T extends object
11
+ * @template T extends object = object
12
12
  */
13
13
  function Message(properties) {
14
14
  // not used internally
package/src/method.js CHANGED
@@ -19,8 +19,9 @@ var util = require("./util");
19
19
  * @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
20
20
  * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
21
21
  * @param {Object.<string,*>} [options] Declared options
22
+ * @param {string} [comment] The comment for this method
22
23
  */
23
- function Method(name, type, requestType, responseType, requestStream, responseStream, options) {
24
+ function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment) {
24
25
 
25
26
  /* istanbul ignore next */
26
27
  if (util.isObject(requestStream)) {
@@ -86,6 +87,12 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
86
87
  * @type {Type|null}
87
88
  */
88
89
  this.resolvedResponseType = null;
90
+
91
+ /**
92
+ * Comment for this method
93
+ * @type {string|null}
94
+ */
95
+ this.comment = comment;
89
96
  }
90
97
 
91
98
  /**
@@ -107,21 +114,24 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
107
114
  * @throws {TypeError} If arguments are invalid
108
115
  */
109
116
  Method.fromJSON = function fromJSON(name, json) {
110
- return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options);
117
+ return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options, json.comment);
111
118
  };
112
119
 
113
120
  /**
114
121
  * Converts this method to a method descriptor.
122
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
115
123
  * @returns {IMethod} Method descriptor
116
124
  */
117
- Method.prototype.toJSON = function toJSON() {
125
+ Method.prototype.toJSON = function toJSON(toJSONOptions) {
126
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
118
127
  return util.toObject([
119
128
  "type" , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,
120
129
  "requestType" , this.requestType,
121
130
  "requestStream" , this.requestStream,
122
131
  "responseType" , this.responseType,
123
132
  "responseStream" , this.responseStream,
124
- "options" , this.options
133
+ "options" , this.options,
134
+ "comment" , keepComments ? this.comment : undefined
125
135
  ]);
126
136
  };
127
137
 
package/src/namespace.js CHANGED
@@ -5,12 +5,12 @@ module.exports = Namespace;
5
5
  var ReflectionObject = require("./object");
6
6
  ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
7
7
 
8
- var Enum = require("./enum"),
9
- Field = require("./field"),
8
+ var Field = require("./field"),
10
9
  util = require("./util");
11
10
 
12
11
  var Type, // cyclic
13
- Service; // "
12
+ Service,
13
+ Enum;
14
14
 
15
15
  /**
16
16
  * Constructs a new namespace instance.
@@ -39,14 +39,15 @@ Namespace.fromJSON = function fromJSON(name, json) {
39
39
  * Converts an array of reflection objects to JSON.
40
40
  * @memberof Namespace
41
41
  * @param {ReflectionObject[]} array Object array
42
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
42
43
  * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty
43
44
  */
44
- function arrayToJSON(array) {
45
+ function arrayToJSON(array, toJSONOptions) {
45
46
  if (!(array && array.length))
46
47
  return undefined;
47
48
  var obj = {};
48
49
  for (var i = 0; i < array.length; ++i)
49
- obj[array[i].name] = array[i].toJSON();
50
+ obj[array[i].name] = array[i].toJSON(toJSONOptions);
50
51
  return obj;
51
52
  }
52
53
 
@@ -147,12 +148,13 @@ Object.defineProperty(Namespace.prototype, "nestedArray", {
147
148
 
148
149
  /**
149
150
  * Converts this namespace to a namespace descriptor.
151
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
150
152
  * @returns {INamespace} Namespace descriptor
151
153
  */
152
- Namespace.prototype.toJSON = function toJSON() {
154
+ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
153
155
  return util.toObject([
154
156
  "options" , this.options,
155
- "nested" , arrayToJSON(this.nestedArray)
157
+ "nested" , arrayToJSON(this.nestedArray, toJSONOptions)
156
158
  ]);
157
159
  };
158
160
 
@@ -203,7 +205,7 @@ Namespace.prototype.get = function get(name) {
203
205
  Namespace.prototype.getEnum = function getEnum(name) {
204
206
  if (this.nested && this.nested[name] instanceof Enum)
205
207
  return this.nested[name].values;
206
- throw Error("no such enum");
208
+ throw Error("no such enum: " + name);
207
209
  };
208
210
 
209
211
  /**
@@ -377,7 +379,7 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
377
379
  Namespace.prototype.lookupType = function lookupType(path) {
378
380
  var found = this.lookup(path, [ Type ]);
379
381
  if (!found)
380
- throw Error("no such type");
382
+ throw Error("no such type: " + path);
381
383
  return found;
382
384
  };
383
385
 
@@ -423,7 +425,9 @@ Namespace.prototype.lookupService = function lookupService(path) {
423
425
  return found;
424
426
  };
425
427
 
426
- Namespace._configure = function(Type_, Service_) {
428
+ // Sets up cyclic dependencies (called in index-light)
429
+ Namespace._configure = function(Type_, Service_, Enum_) {
427
430
  Type = Type_;
428
431
  Service = Service_;
432
+ Enum = Enum_;
429
433
  };