protobufjs 6.11.3 → 7.0.0

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 (60) hide show
  1. package/README.md +7 -174
  2. package/dist/light/protobuf.js +40 -16
  3. package/dist/light/protobuf.js.map +1 -1
  4. package/dist/light/protobuf.min.js +3 -3
  5. package/dist/light/protobuf.min.js.map +1 -1
  6. package/dist/minimal/protobuf.js +27 -10
  7. package/dist/minimal/protobuf.js.map +1 -1
  8. package/dist/minimal/protobuf.min.js +3 -3
  9. package/dist/minimal/protobuf.min.js.map +1 -1
  10. package/dist/protobuf.js +109 -46
  11. package/dist/protobuf.js.map +1 -1
  12. package/dist/protobuf.min.js +3 -3
  13. package/dist/protobuf.min.js.map +1 -1
  14. package/index.d.ts +1 -4
  15. package/package.json +9 -28
  16. package/scripts/postinstall.js +0 -3
  17. package/src/converter.js +1 -1
  18. package/src/decoder.js +4 -3
  19. package/src/field.js +6 -3
  20. package/src/namespace.js +1 -2
  21. package/src/parse.js +38 -14
  22. package/src/roots.js +1 -1
  23. package/src/tokenize.js +31 -16
  24. package/src/util/minimal.js +24 -7
  25. package/src/wrappers.js +2 -2
  26. package/CHANGELOG.md +0 -1027
  27. package/bin/pbjs +0 -6
  28. package/bin/pbts +0 -6
  29. package/cli/LICENSE +0 -33
  30. package/cli/README.md +0 -174
  31. package/cli/bin/pbjs +0 -6
  32. package/cli/bin/pbts +0 -6
  33. package/cli/index.d.ts +0 -3
  34. package/cli/index.js +0 -3
  35. package/cli/lib/tsd-jsdoc/LICENSE +0 -21
  36. package/cli/lib/tsd-jsdoc/README.md +0 -23
  37. package/cli/lib/tsd-jsdoc/plugin.js +0 -21
  38. package/cli/lib/tsd-jsdoc/publish.js +0 -705
  39. package/cli/lib/tsd-jsdoc.json +0 -18
  40. package/cli/package.json +0 -8
  41. package/cli/package.standalone.json +0 -32
  42. package/cli/pbjs.d.ts +0 -9
  43. package/cli/pbjs.js +0 -330
  44. package/cli/pbts.d.ts +0 -9
  45. package/cli/pbts.js +0 -197
  46. package/cli/targets/json-module.js +0 -38
  47. package/cli/targets/json.js +0 -8
  48. package/cli/targets/proto.js +0 -326
  49. package/cli/targets/proto2.js +0 -10
  50. package/cli/targets/proto3.js +0 -10
  51. package/cli/targets/static-module.js +0 -29
  52. package/cli/targets/static.js +0 -711
  53. package/cli/util.js +0 -183
  54. package/cli/wrappers/amd.js +0 -7
  55. package/cli/wrappers/closure.js +0 -7
  56. package/cli/wrappers/commonjs.js +0 -7
  57. package/cli/wrappers/default.js +0 -15
  58. package/cli/wrappers/es6.js +0 -5
  59. package/package-lock.json +0 -7870
  60. package/scripts/changelog.js +0 -150
@@ -1,705 +0,0 @@
1
- "use strict";
2
-
3
- var fs = require("fs");
4
-
5
- // output stream
6
- var out = null;
7
-
8
- // documentation data
9
- var data = null;
10
-
11
- // already handled objects, by name
12
- var seen = {};
13
-
14
- // indentation level
15
- var indent = 0;
16
-
17
- // whether indent has been written for the current line yet
18
- var indentWritten = false;
19
-
20
- // provided options
21
- var options = {};
22
-
23
- // queued interfaces
24
- var queuedInterfaces = [];
25
-
26
- // whether writing the first line
27
- var firstLine = true;
28
-
29
- // JSDoc hook
30
- exports.publish = function publish(taffy, opts) {
31
- options = opts || {};
32
-
33
- // query overrides options
34
- if (options.query)
35
- Object.keys(options.query).forEach(function(key) {
36
- if (key !== "query")
37
- switch (options[key] = options.query[key]) {
38
- case "true":
39
- options[key] = true;
40
- break;
41
- case "false":
42
- options[key] = false;
43
- break;
44
- case "null":
45
- options[key] = null;
46
- break;
47
- }
48
- });
49
-
50
- // remove undocumented
51
- taffy({ undocumented: true }).remove();
52
- taffy({ ignore: true }).remove();
53
- taffy({ inherited: true }).remove();
54
-
55
- // remove private
56
- if (!options.private)
57
- taffy({ access: "private" }).remove();
58
-
59
- // setup output
60
- out = options.destination
61
- ? fs.createWriteStream(options.destination)
62
- : process.stdout;
63
-
64
- try {
65
- // setup environment
66
- data = taffy().get();
67
- indent = 0;
68
- indentWritten = false;
69
- firstLine = true;
70
-
71
- // wrap everything in a module if configured
72
- if (options.module) {
73
- writeln("export = ", options.module, ";");
74
- writeln();
75
- writeln("declare namespace ", options.module, " {");
76
- writeln();
77
- ++indent;
78
- }
79
-
80
- // handle all
81
- getChildrenOf(undefined).forEach(function(child) {
82
- handleElement(child, null);
83
- });
84
-
85
- // process queued
86
- while (queuedInterfaces.length) {
87
- var element = queuedInterfaces.shift();
88
- begin(element);
89
- writeInterface(element);
90
- writeln(";");
91
- }
92
-
93
- // end wrap
94
- if (options.module) {
95
- --indent;
96
- writeln("}");
97
- }
98
-
99
- // close file output
100
- if (out !== process.stdout)
101
- out.end();
102
-
103
- } finally {
104
- // gc environment objects
105
- out = data = null;
106
- seen = options = {};
107
- queuedInterfaces = [];
108
- }
109
- };
110
-
111
- //
112
- // Utility
113
- //
114
-
115
- // writes one or multiple strings
116
- function write() {
117
- var s = Array.prototype.slice.call(arguments).join("");
118
- if (!indentWritten) {
119
- for (var i = 0; i < indent; ++i)
120
- s = " " + s;
121
- indentWritten = true;
122
- }
123
- out.write(s);
124
- firstLine = false;
125
- }
126
-
127
- // writes zero or multiple strings, followed by a new line
128
- function writeln() {
129
- var s = Array.prototype.slice.call(arguments).join("");
130
- if (s.length)
131
- write(s, "\n");
132
- else if (!firstLine)
133
- out.write("\n");
134
- indentWritten = false;
135
- }
136
-
137
- var keepTags = [
138
- "param",
139
- "returns",
140
- "throws",
141
- "see"
142
- ];
143
-
144
- // parses a comment into text and tags
145
- function parseComment(comment) {
146
- var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n|\r/g); // property.description has just "\r" ?!
147
- var desc;
148
- var text = [];
149
- var tags = null;
150
- for (var i = 0; i < lines.length; ++i) {
151
- var match = /^@(\w+)\b/.exec(lines[i]);
152
- if (match) {
153
- if (!tags) {
154
- tags = [];
155
- desc = text;
156
- }
157
- text = [];
158
- tags.push({ name: match[1], text: text });
159
- lines[i] = lines[i].substring(match[1].length + 1).trim();
160
- }
161
- if (lines[i].length || text.length)
162
- text.push(lines[i]);
163
- }
164
- return {
165
- text: desc || text,
166
- tags: tags || []
167
- };
168
- }
169
-
170
- // writes a comment
171
- function writeComment(comment, otherwiseNewline) {
172
- if (!comment || options.comments === false) {
173
- if (otherwiseNewline)
174
- writeln();
175
- return;
176
- }
177
- if (typeof comment !== "object")
178
- comment = parseComment(comment);
179
- comment.tags = comment.tags.filter(function(tag) {
180
- return keepTags.indexOf(tag.name) > -1 && (tag.name !== "returns" || tag.text[0] !== "{undefined}");
181
- });
182
- writeln();
183
- if (!comment.tags.length && comment.text.length < 2) {
184
- writeln("/** " + comment.text[0] + " */");
185
- return;
186
- }
187
- writeln("/**");
188
- comment.text.forEach(function(line) {
189
- if (line.length)
190
- writeln(" * ", line);
191
- else
192
- writeln(" *");
193
- });
194
- comment.tags.forEach(function(tag) {
195
- var started = false;
196
- if (tag.text.length) {
197
- tag.text.forEach(function(line, i) {
198
- if (i > 0)
199
- write(" * ");
200
- else if (tag.name !== "throws")
201
- line = line.replace(/^\{[^\s]*} ?/, "");
202
- if (!line.length)
203
- return;
204
- if (!started) {
205
- write(" * @", tag.name, " ");
206
- started = true;
207
- }
208
- writeln(line);
209
- });
210
- }
211
- });
212
- writeln(" */");
213
- }
214
-
215
- // recursively replaces all occurencies of re's match
216
- function replaceRecursive(name, re, fn) {
217
- var found;
218
-
219
- function replacer() {
220
- found = true;
221
- return fn.apply(null, arguments);
222
- }
223
-
224
- do {
225
- found = false;
226
- name = name.replace(re, replacer);
227
- } while (found);
228
- return name;
229
- }
230
-
231
- // tests if an element is considered to be a class or class-like
232
- function isClassLike(element) {
233
- return isClass(element) || isInterface(element);
234
- }
235
-
236
- // tests if an element is considered to be a class
237
- function isClass(element) {
238
- return element && element.kind === "class";
239
- }
240
-
241
- // tests if an element is considered to be an interface
242
- function isInterface(element) {
243
- return element && (element.kind === "interface" || element.kind === "mixin");
244
- }
245
-
246
- // tests if an element is considered to be a namespace
247
- function isNamespace(element) {
248
- return element && (element.kind === "namespace" || element.kind === "module");
249
- }
250
-
251
- // gets all children of the specified parent
252
- function getChildrenOf(parent) {
253
- var memberof = parent ? parent.longname : undefined;
254
- return data.filter(function(element) {
255
- return element.memberof === memberof;
256
- });
257
- }
258
-
259
- // gets the literal type of an element
260
- function getTypeOf(element) {
261
- if (element.tsType)
262
- return element.tsType.replace(/\r?\n|\r/g, "\n");
263
- var name = "any";
264
- var type = element.type;
265
- if (type && type.names && type.names.length) {
266
- if (type.names.length === 1)
267
- name = element.type.names[0].trim();
268
- else
269
- name = "(" + element.type.names.join("|") + ")";
270
- } else
271
- return name;
272
-
273
- // Replace catchalls with any
274
- name = name.replace(/\*|\bmixed\b/g, "any");
275
-
276
- // Ensure upper case Object for map expressions below
277
- name = name.replace(/\bobject\b/g, "Object");
278
-
279
- // Correct Something.<Something> to Something<Something>
280
- name = replaceRecursive(name, /\b(?!Object|Array)([\w$]+)\.<([^>]*)>/gi, function($0, $1, $2) {
281
- return $1 + "<" + $2 + ">";
282
- });
283
-
284
- // Replace Array.<string> with string[]
285
- name = replaceRecursive(name, /\bArray\.?<([^>]*)>/gi, function($0, $1) {
286
- return $1 + "[]";
287
- });
288
-
289
- // Replace Object.<string,number> with { [k: string]: number }
290
- name = replaceRecursive(name, /\bObject\.?<([^,]*), *([^>]*)>/gi, function($0, $1, $2) {
291
- return "{ [k: " + $1 + "]: " + $2 + " }";
292
- });
293
-
294
- // Replace functions (there are no signatures) with Function
295
- name = name.replace(/\bfunction(?:\(\))?\b/g, "Function");
296
-
297
- // Convert plain Object back to just object
298
- name = name.replace(/\b(Object\b(?!\.))/g, function($0, $1) {
299
- return $1.toLowerCase();
300
- });
301
-
302
- return name;
303
- }
304
-
305
- // begins writing the definition of the specified element
306
- function begin(element, is_interface) {
307
- if (!seen[element.longname]) {
308
- if (isClass(element)) {
309
- var comment = parseComment(element.comment);
310
- var classdesc = comment.tags.find(function(tag) { return tag.name === "classdesc"; });
311
- if (classdesc) {
312
- comment.text = classdesc.text;
313
- comment.tags = [];
314
- }
315
- writeComment(comment, true);
316
- } else
317
- writeComment(element.comment, is_interface || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
318
- seen[element.longname] = element;
319
- } else
320
- writeln();
321
- // ????: something changed in JSDoc 3.6.0? so that @exports + @enum does
322
- // no longer yield a 'global' scope, but is some sort of unscoped module
323
- // element now. The additional condition added below works around this.
324
- if ((element.scope === "global" || element.isEnum && element.scope === undefined) && !options.module)
325
- write("export ");
326
- }
327
-
328
- // writes the function signature describing element
329
- function writeFunctionSignature(element, isConstructor, isTypeDef) {
330
- write("(");
331
-
332
- var params = {};
333
-
334
- // this type
335
- if (element.this)
336
- params["this"] = {
337
- type: element.this.replace(/^{|}$/g, ""),
338
- optional: false
339
- };
340
-
341
- // parameter types
342
- if (element.params)
343
- element.params.forEach(function(param) {
344
- var path = param.name.split(/\./g);
345
- if (path.length === 1)
346
- params[param.name] = {
347
- type: getTypeOf(param),
348
- variable: param.variable === true,
349
- optional: param.optional === true,
350
- defaultValue: param.defaultvalue // Not used yet (TODO)
351
- };
352
- else // Property syntax (TODO)
353
- params[path[0]].type = "{ [k: string]: any }";
354
- });
355
-
356
- var paramNames = Object.keys(params);
357
- paramNames.forEach(function(name, i) {
358
- var param = params[name];
359
- var type = param.type;
360
- if (param.variable) {
361
- name = "..." + name;
362
- type = param.type.charAt(0) === "(" ? "any[]" : param.type + "[]";
363
- }
364
- write(name, !param.variable && param.optional ? "?: " : ": ", type);
365
- if (i < paramNames.length - 1)
366
- write(", ");
367
- });
368
-
369
- write(")");
370
-
371
- // return type
372
- if (!isConstructor) {
373
- write(isTypeDef ? " => " : ": ");
374
- var typeName;
375
- if (element.returns && element.returns.length && (typeName = getTypeOf(element.returns[0])) !== "undefined")
376
- write(typeName);
377
- else
378
- write("void");
379
- }
380
- }
381
-
382
- // writes (a typedef as) an interface
383
- function writeInterface(element) {
384
- write("interface ", element.name);
385
- writeInterfaceBody(element);
386
- writeln();
387
- }
388
-
389
- function writeInterfaceBody(element) {
390
- writeln("{");
391
- ++indent;
392
- if (element.tsType)
393
- writeln(element.tsType.replace(/\r?\n|\r/g, "\n"));
394
- else if (element.properties && element.properties.length)
395
- element.properties.forEach(writeProperty);
396
- --indent;
397
- write("}");
398
- }
399
-
400
- function writeProperty(property, declare) {
401
- writeComment(property.description);
402
- if (declare)
403
- write("let ");
404
- write(property.name);
405
- if (property.optional)
406
- write("?");
407
- writeln(": ", getTypeOf(property), ";");
408
- }
409
-
410
- //
411
- // Handlers
412
- //
413
-
414
- // handles a single element of any understood type
415
- function handleElement(element, parent) {
416
- if (element.scope === "inner")
417
- return false;
418
-
419
- if (element.optional !== true && element.type && element.type.names && element.type.names.length) {
420
- for (var i = 0; i < element.type.names.length; i++) {
421
- if (element.type.names[i].toLowerCase() === "undefined") {
422
- // This element is actually optional. Set optional to true and
423
- // remove the 'undefined' type
424
- element.optional = true;
425
- element.type.names.splice(i, 1);
426
- i--;
427
- }
428
- }
429
- }
430
-
431
- if (seen[element.longname])
432
- return true;
433
- if (isClassLike(element))
434
- handleClass(element, parent);
435
- else switch (element.kind) {
436
- case "module":
437
- if (element.isEnum) {
438
- handleEnum(element, parent);
439
- break;
440
- }
441
- // eslint-disable-line no-fallthrough
442
- case "namespace":
443
- handleNamespace(element, parent);
444
- break;
445
- case "constant":
446
- case "member":
447
- handleMember(element, parent);
448
- break;
449
- case "function":
450
- handleFunction(element, parent);
451
- break;
452
- case "typedef":
453
- handleTypeDef(element, parent);
454
- break;
455
- case "package":
456
- break;
457
- }
458
- seen[element.longname] = element;
459
- return true;
460
- }
461
-
462
- // handles (just) a namespace
463
- function handleNamespace(element/*, parent*/) {
464
- var children = getChildrenOf(element);
465
- if (!children.length)
466
- return;
467
- var first = true;
468
- if (element.properties)
469
- element.properties.forEach(function(property) {
470
- if (!/^[$\w]+$/.test(property.name)) // incompatible in namespace
471
- return;
472
- if (first) {
473
- begin(element);
474
- writeln("namespace ", element.name, " {");
475
- ++indent;
476
- first = false;
477
- }
478
- writeProperty(property, true);
479
- });
480
- children.forEach(function(child) {
481
- if (child.scope === "inner" || seen[child.longname])
482
- return;
483
- if (first) {
484
- begin(element);
485
- writeln("namespace ", element.name, " {");
486
- ++indent;
487
- first = false;
488
- }
489
- handleElement(child, element);
490
- });
491
- if (!first) {
492
- --indent;
493
- writeln("}");
494
- }
495
- }
496
-
497
- // a filter function to remove any module references
498
- function notAModuleReference(ref) {
499
- return ref.indexOf("module:") === -1;
500
- }
501
-
502
- // handles a class or class-like
503
- function handleClass(element, parent) {
504
- var is_interface = isInterface(element);
505
- begin(element, is_interface);
506
- if (is_interface)
507
- write("interface ");
508
- else {
509
- if (element.virtual)
510
- write("abstract ");
511
- write("class ");
512
- }
513
- write(element.name);
514
- if (element.templates && element.templates.length)
515
- write("<", element.templates.join(", "), ">");
516
- write(" ");
517
-
518
- // extended classes
519
- if (element.augments) {
520
- var augments = element.augments.filter(notAModuleReference);
521
- if (augments.length)
522
- write("extends ", augments[0], " ");
523
- }
524
-
525
- // implemented interfaces
526
- var impls = [];
527
- if (element.implements)
528
- Array.prototype.push.apply(impls, element.implements);
529
- if (element.mixes)
530
- Array.prototype.push.apply(impls, element.mixes);
531
- impls = impls.filter(notAModuleReference);
532
- if (impls.length)
533
- write("implements ", impls.join(", "), " ");
534
-
535
- writeln("{");
536
- ++indent;
537
-
538
- if (element.tsType)
539
- writeln(element.tsType.replace(/\r?\n|\r/g, "\n"));
540
-
541
- // constructor
542
- if (!is_interface && !element.virtual)
543
- handleFunction(element, parent, true);
544
-
545
- // properties
546
- if (is_interface && element.properties)
547
- element.properties.forEach(function(property) {
548
- writeProperty(property);
549
- });
550
-
551
- // class-compatible members
552
- var incompatible = [];
553
- getChildrenOf(element).forEach(function(child) {
554
- if (isClassLike(child) || child.kind === "module" || child.kind === "typedef" || child.isEnum) {
555
- incompatible.push(child);
556
- return;
557
- }
558
- handleElement(child, element);
559
- });
560
-
561
- --indent;
562
- writeln("}");
563
-
564
- // class-incompatible members
565
- if (incompatible.length) {
566
- writeln();
567
- if (element.scope === "global" && !options.module)
568
- write("export ");
569
- writeln("namespace ", element.name, " {");
570
- ++indent;
571
- incompatible.forEach(function(child) {
572
- handleElement(child, element);
573
- });
574
- --indent;
575
- writeln("}");
576
- }
577
- }
578
-
579
- // handles an enum
580
- function handleEnum(element) {
581
- begin(element);
582
-
583
- var stringEnum = false;
584
- element.properties.forEach(function(property) {
585
- if (isNaN(property.defaultvalue)) {
586
- stringEnum = true;
587
- }
588
- });
589
- if (stringEnum) {
590
- writeln("type ", element.name, " =");
591
- ++indent;
592
- element.properties.forEach(function(property, i) {
593
- write(i === 0 ? "" : "| ", JSON.stringify(property.defaultvalue));
594
- });
595
- --indent;
596
- writeln(";");
597
- } else {
598
- writeln("enum ", element.name, " {");
599
- ++indent;
600
- element.properties.forEach(function(property, i) {
601
- write(property.name);
602
- if (property.defaultvalue !== undefined)
603
- write(" = ", JSON.stringify(property.defaultvalue));
604
- if (i < element.properties.length - 1)
605
- writeln(",");
606
- else
607
- writeln();
608
- });
609
- --indent;
610
- writeln("}");
611
- }
612
- }
613
-
614
- // handles a namespace or class member
615
- function handleMember(element, parent) {
616
- if (element.isEnum) {
617
- handleEnum(element);
618
- return;
619
- }
620
- begin(element);
621
-
622
- var inClass = isClassLike(parent);
623
- if (inClass) {
624
- write(element.access || "public", " ");
625
- if (element.scope === "static")
626
- write("static ");
627
- if (element.readonly)
628
- write("readonly ");
629
- } else
630
- write(element.kind === "constant" ? "const " : "let ");
631
-
632
- write(element.name);
633
- if (element.optional)
634
- write("?");
635
- write(": ");
636
-
637
- if (element.type && element.type.names && /^Object\b/i.test(element.type.names[0]) && element.properties) {
638
- writeln("{");
639
- ++indent;
640
- element.properties.forEach(function(property, i) {
641
- writeln(JSON.stringify(property.name), ": ", getTypeOf(property), i < element.properties.length - 1 ? "," : "");
642
- });
643
- --indent;
644
- writeln("};");
645
- } else
646
- writeln(getTypeOf(element), ";");
647
- }
648
-
649
- // handles a function or method
650
- function handleFunction(element, parent, isConstructor) {
651
- var insideClass = true;
652
- if (isConstructor) {
653
- writeComment(element.comment);
654
- write("constructor");
655
- } else {
656
- begin(element);
657
- insideClass = isClassLike(parent);
658
- if (insideClass) {
659
- write(element.access || "public", " ");
660
- if (element.scope === "static")
661
- write("static ");
662
- } else
663
- write("function ");
664
- write(element.name);
665
- if (element.templates && element.templates.length)
666
- write("<", element.templates.join(", "), ">");
667
- }
668
- writeFunctionSignature(element, isConstructor, false);
669
- writeln(";");
670
- if (!insideClass)
671
- handleNamespace(element);
672
- }
673
-
674
- // handles a type definition (not a real type)
675
- function handleTypeDef(element, parent) {
676
- if (isInterface(element)) {
677
- if (isClassLike(parent))
678
- queuedInterfaces.push(element);
679
- else {
680
- begin(element);
681
- writeInterface(element);
682
- }
683
- } else {
684
- writeComment(element.comment, true);
685
- write("type ", element.name);
686
- if (element.templates && element.templates.length)
687
- write("<", element.templates.join(", "), ">");
688
- write(" = ");
689
- if (element.tsType)
690
- write(element.tsType.replace(/\r?\n|\r/g, "\n"));
691
- else {
692
- var type = getTypeOf(element);
693
- if (element.type && element.type.names.length === 1 && element.type.names[0] === "function")
694
- writeFunctionSignature(element, false, true);
695
- else if (type === "object") {
696
- if (element.properties && element.properties.length)
697
- writeInterfaceBody(element);
698
- else
699
- write("{}");
700
- } else
701
- write(type);
702
- }
703
- writeln(";");
704
- }
705
- }