protobufjs 6.11.2 → 7.1.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.
- package/README.md +7 -174
- package/dist/light/protobuf.js +77 -29
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +27 -10
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +163 -61
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +9 -7
- package/package.json +14 -33
- package/scripts/postinstall.js +0 -3
- package/src/converter.js +10 -4
- package/src/decoder.js +4 -3
- package/src/enum.js +24 -7
- package/src/field.js +6 -3
- package/src/namespace.js +3 -3
- package/src/parse.js +55 -16
- package/src/roots.js +1 -1
- package/src/tokenize.js +31 -16
- package/src/util/minimal.js +24 -7
- package/src/util.js +3 -0
- package/src/wrappers.js +2 -2
- package/tsconfig.json +2 -1
- package/CHANGELOG.md +0 -1019
- package/bin/pbjs +0 -6
- package/bin/pbts +0 -6
- package/cli/LICENSE +0 -33
- package/cli/README.md +0 -174
- package/cli/bin/pbjs +0 -6
- package/cli/bin/pbts +0 -6
- package/cli/index.d.ts +0 -3
- package/cli/index.js +0 -3
- package/cli/lib/tsd-jsdoc/LICENSE +0 -21
- package/cli/lib/tsd-jsdoc/README.md +0 -23
- package/cli/lib/tsd-jsdoc/plugin.js +0 -21
- package/cli/lib/tsd-jsdoc/publish.js +0 -705
- package/cli/lib/tsd-jsdoc.json +0 -18
- package/cli/node_modules/.package-lock.json +0 -256
- package/cli/node_modules/acorn/CHANGELOG.md +0 -620
- package/cli/node_modules/acorn/LICENSE +0 -21
- package/cli/node_modules/acorn/README.md +0 -269
- package/cli/node_modules/acorn/bin/acorn +0 -4
- package/cli/node_modules/acorn/dist/acorn.d.ts +0 -209
- package/cli/node_modules/acorn/dist/acorn.js +0 -5186
- package/cli/node_modules/acorn/dist/acorn.js.map +0 -1
- package/cli/node_modules/acorn/dist/acorn.mjs +0 -5155
- package/cli/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
- package/cli/node_modules/acorn/dist/acorn.mjs.map +0 -1
- package/cli/node_modules/acorn/dist/bin.js +0 -64
- package/cli/node_modules/acorn/package.json +0 -35
- package/cli/node_modules/acorn-jsx/LICENSE +0 -19
- package/cli/node_modules/acorn-jsx/README.md +0 -40
- package/cli/node_modules/acorn-jsx/index.js +0 -488
- package/cli/node_modules/acorn-jsx/package.json +0 -27
- package/cli/node_modules/acorn-jsx/xhtml.js +0 -255
- package/cli/node_modules/balanced-match/.npmignore +0 -5
- package/cli/node_modules/balanced-match/LICENSE.md +0 -21
- package/cli/node_modules/balanced-match/README.md +0 -91
- package/cli/node_modules/balanced-match/index.js +0 -59
- package/cli/node_modules/balanced-match/package.json +0 -49
- package/cli/node_modules/brace-expansion/LICENSE +0 -21
- package/cli/node_modules/brace-expansion/README.md +0 -129
- package/cli/node_modules/brace-expansion/index.js +0 -201
- package/cli/node_modules/brace-expansion/package.json +0 -47
- package/cli/node_modules/concat-map/.travis.yml +0 -4
- package/cli/node_modules/concat-map/LICENSE +0 -18
- package/cli/node_modules/concat-map/README.markdown +0 -62
- package/cli/node_modules/concat-map/example/map.js +0 -6
- package/cli/node_modules/concat-map/index.js +0 -13
- package/cli/node_modules/concat-map/package.json +0 -43
- package/cli/node_modules/concat-map/test/map.js +0 -39
- package/cli/node_modules/deep-is/.npmignore +0 -1
- package/cli/node_modules/deep-is/.travis.yml +0 -6
- package/cli/node_modules/deep-is/LICENSE +0 -22
- package/cli/node_modules/deep-is/README.markdown +0 -70
- package/cli/node_modules/deep-is/example/cmp.js +0 -11
- package/cli/node_modules/deep-is/index.js +0 -102
- package/cli/node_modules/deep-is/package.json +0 -61
- package/cli/node_modules/deep-is/test/NaN.js +0 -16
- package/cli/node_modules/deep-is/test/cmp.js +0 -23
- package/cli/node_modules/deep-is/test/neg-vs-pos-0.js +0 -15
- package/cli/node_modules/escodegen/LICENSE.BSD +0 -21
- package/cli/node_modules/escodegen/README.md +0 -84
- package/cli/node_modules/escodegen/bin/escodegen.js +0 -77
- package/cli/node_modules/escodegen/bin/esgenerate.js +0 -64
- package/cli/node_modules/escodegen/escodegen.js +0 -2647
- package/cli/node_modules/escodegen/package.json +0 -62
- package/cli/node_modules/eslint-visitor-keys/CHANGELOG.md +0 -25
- package/cli/node_modules/eslint-visitor-keys/LICENSE +0 -201
- package/cli/node_modules/eslint-visitor-keys/README.md +0 -98
- package/cli/node_modules/eslint-visitor-keys/lib/index.js +0 -81
- package/cli/node_modules/eslint-visitor-keys/lib/visitor-keys.json +0 -284
- package/cli/node_modules/eslint-visitor-keys/package.json +0 -40
- package/cli/node_modules/espree/CHANGELOG.md +0 -509
- package/cli/node_modules/espree/LICENSE +0 -25
- package/cli/node_modules/espree/README.md +0 -233
- package/cli/node_modules/espree/espree.js +0 -177
- package/cli/node_modules/espree/lib/ast-node-types.js +0 -96
- package/cli/node_modules/espree/lib/espree.js +0 -286
- package/cli/node_modules/espree/lib/features.js +0 -29
- package/cli/node_modules/espree/lib/options.js +0 -106
- package/cli/node_modules/espree/lib/token-translator.js +0 -263
- package/cli/node_modules/espree/lib/visitor-keys.js +0 -123
- package/cli/node_modules/espree/package.json +0 -64
- package/cli/node_modules/esprima/ChangeLog +0 -235
- package/cli/node_modules/esprima/LICENSE.BSD +0 -21
- package/cli/node_modules/esprima/README.md +0 -46
- package/cli/node_modules/esprima/bin/esparse.js +0 -139
- package/cli/node_modules/esprima/bin/esvalidate.js +0 -236
- package/cli/node_modules/esprima/dist/esprima.js +0 -6709
- package/cli/node_modules/esprima/package.json +0 -112
- package/cli/node_modules/estraverse/.jshintrc +0 -16
- package/cli/node_modules/estraverse/LICENSE.BSD +0 -19
- package/cli/node_modules/estraverse/README.md +0 -153
- package/cli/node_modules/estraverse/estraverse.js +0 -801
- package/cli/node_modules/estraverse/gulpfile.js +0 -70
- package/cli/node_modules/estraverse/package.json +0 -40
- package/cli/node_modules/esutils/LICENSE.BSD +0 -19
- package/cli/node_modules/esutils/README.md +0 -174
- package/cli/node_modules/esutils/lib/ast.js +0 -144
- package/cli/node_modules/esutils/lib/code.js +0 -135
- package/cli/node_modules/esutils/lib/keyword.js +0 -165
- package/cli/node_modules/esutils/lib/utils.js +0 -33
- package/cli/node_modules/esutils/package.json +0 -44
- package/cli/node_modules/fast-levenshtein/LICENSE.md +0 -25
- package/cli/node_modules/fast-levenshtein/README.md +0 -104
- package/cli/node_modules/fast-levenshtein/levenshtein.js +0 -136
- package/cli/node_modules/fast-levenshtein/package.json +0 -39
- package/cli/node_modules/fs.realpath/LICENSE +0 -43
- package/cli/node_modules/fs.realpath/README.md +0 -33
- package/cli/node_modules/fs.realpath/index.js +0 -66
- package/cli/node_modules/fs.realpath/old.js +0 -303
- package/cli/node_modules/fs.realpath/package.json +0 -26
- package/cli/node_modules/glob/LICENSE +0 -21
- package/cli/node_modules/glob/README.md +0 -375
- package/cli/node_modules/glob/changelog.md +0 -67
- package/cli/node_modules/glob/common.js +0 -240
- package/cli/node_modules/glob/glob.js +0 -790
- package/cli/node_modules/glob/package.json +0 -46
- package/cli/node_modules/glob/sync.js +0 -486
- package/cli/node_modules/inflight/LICENSE +0 -15
- package/cli/node_modules/inflight/README.md +0 -37
- package/cli/node_modules/inflight/inflight.js +0 -54
- package/cli/node_modules/inflight/package.json +0 -29
- package/cli/node_modules/inherits/LICENSE +0 -16
- package/cli/node_modules/inherits/README.md +0 -42
- package/cli/node_modules/inherits/inherits.js +0 -9
- package/cli/node_modules/inherits/inherits_browser.js +0 -27
- package/cli/node_modules/inherits/package.json +0 -29
- package/cli/node_modules/levn/LICENSE +0 -22
- package/cli/node_modules/levn/README.md +0 -196
- package/cli/node_modules/levn/lib/cast.js +0 -298
- package/cli/node_modules/levn/lib/coerce.js +0 -285
- package/cli/node_modules/levn/lib/index.js +0 -22
- package/cli/node_modules/levn/lib/parse-string.js +0 -113
- package/cli/node_modules/levn/lib/parse.js +0 -102
- package/cli/node_modules/levn/package.json +0 -47
- package/cli/node_modules/minimatch/LICENSE +0 -15
- package/cli/node_modules/minimatch/README.md +0 -209
- package/cli/node_modules/minimatch/minimatch.js +0 -923
- package/cli/node_modules/minimatch/package.json +0 -30
- package/cli/node_modules/once/LICENSE +0 -15
- package/cli/node_modules/once/README.md +0 -79
- package/cli/node_modules/once/once.js +0 -42
- package/cli/node_modules/once/package.json +0 -33
- package/cli/node_modules/optionator/CHANGELOG.md +0 -56
- package/cli/node_modules/optionator/LICENSE +0 -22
- package/cli/node_modules/optionator/README.md +0 -238
- package/cli/node_modules/optionator/lib/help.js +0 -260
- package/cli/node_modules/optionator/lib/index.js +0 -465
- package/cli/node_modules/optionator/lib/util.js +0 -54
- package/cli/node_modules/optionator/package.json +0 -44
- package/cli/node_modules/path-is-absolute/index.js +0 -20
- package/cli/node_modules/path-is-absolute/license +0 -21
- package/cli/node_modules/path-is-absolute/package.json +0 -43
- package/cli/node_modules/path-is-absolute/readme.md +0 -59
- package/cli/node_modules/prelude-ls/CHANGELOG.md +0 -99
- package/cli/node_modules/prelude-ls/LICENSE +0 -22
- package/cli/node_modules/prelude-ls/README.md +0 -15
- package/cli/node_modules/prelude-ls/lib/Func.js +0 -65
- package/cli/node_modules/prelude-ls/lib/List.js +0 -686
- package/cli/node_modules/prelude-ls/lib/Num.js +0 -130
- package/cli/node_modules/prelude-ls/lib/Obj.js +0 -154
- package/cli/node_modules/prelude-ls/lib/Str.js +0 -92
- package/cli/node_modules/prelude-ls/lib/index.js +0 -178
- package/cli/node_modules/prelude-ls/package.json +0 -52
- package/cli/node_modules/rimraf/CHANGELOG.md +0 -65
- package/cli/node_modules/rimraf/LICENSE +0 -15
- package/cli/node_modules/rimraf/README.md +0 -101
- package/cli/node_modules/rimraf/bin.js +0 -68
- package/cli/node_modules/rimraf/package.json +0 -32
- package/cli/node_modules/rimraf/rimraf.js +0 -360
- package/cli/node_modules/source-map/CHANGELOG.md +0 -301
- package/cli/node_modules/source-map/LICENSE +0 -28
- package/cli/node_modules/source-map/README.md +0 -742
- package/cli/node_modules/source-map/dist/source-map.debug.js +0 -3234
- package/cli/node_modules/source-map/dist/source-map.js +0 -3233
- package/cli/node_modules/source-map/dist/source-map.min.js +0 -2
- package/cli/node_modules/source-map/dist/source-map.min.js.map +0 -1
- package/cli/node_modules/source-map/lib/array-set.js +0 -121
- package/cli/node_modules/source-map/lib/base64-vlq.js +0 -140
- package/cli/node_modules/source-map/lib/base64.js +0 -67
- package/cli/node_modules/source-map/lib/binary-search.js +0 -111
- package/cli/node_modules/source-map/lib/mapping-list.js +0 -79
- package/cli/node_modules/source-map/lib/quick-sort.js +0 -114
- package/cli/node_modules/source-map/lib/source-map-consumer.js +0 -1145
- package/cli/node_modules/source-map/lib/source-map-generator.js +0 -425
- package/cli/node_modules/source-map/lib/source-node.js +0 -413
- package/cli/node_modules/source-map/lib/util.js +0 -488
- package/cli/node_modules/source-map/package.json +0 -73
- package/cli/node_modules/source-map/source-map.d.ts +0 -98
- package/cli/node_modules/source-map/source-map.js +0 -8
- package/cli/node_modules/tmp/CHANGELOG.md +0 -288
- package/cli/node_modules/tmp/LICENSE +0 -21
- package/cli/node_modules/tmp/README.md +0 -365
- package/cli/node_modules/tmp/lib/tmp.js +0 -780
- package/cli/node_modules/tmp/package.json +0 -58
- package/cli/node_modules/type-check/LICENSE +0 -22
- package/cli/node_modules/type-check/README.md +0 -210
- package/cli/node_modules/type-check/lib/check.js +0 -126
- package/cli/node_modules/type-check/lib/index.js +0 -16
- package/cli/node_modules/type-check/lib/parse-type.js +0 -196
- package/cli/node_modules/type-check/package.json +0 -40
- package/cli/node_modules/word-wrap/LICENSE +0 -21
- package/cli/node_modules/word-wrap/README.md +0 -182
- package/cli/node_modules/word-wrap/index.d.ts +0 -50
- package/cli/node_modules/word-wrap/index.js +0 -46
- package/cli/node_modules/word-wrap/package.json +0 -77
- package/cli/node_modules/wrappy/LICENSE +0 -15
- package/cli/node_modules/wrappy/README.md +0 -36
- package/cli/node_modules/wrappy/package.json +0 -29
- package/cli/node_modules/wrappy/wrappy.js +0 -33
- package/cli/package.json +0 -8
- package/cli/package.standalone.json +0 -32
- package/cli/pbjs.d.ts +0 -9
- package/cli/pbjs.js +0 -330
- package/cli/pbts.d.ts +0 -9
- package/cli/pbts.js +0 -197
- package/cli/targets/json-module.js +0 -38
- package/cli/targets/json.js +0 -8
- package/cli/targets/proto.js +0 -326
- package/cli/targets/proto2.js +0 -10
- package/cli/targets/proto3.js +0 -10
- package/cli/targets/static-module.js +0 -29
- package/cli/targets/static.js +0 -711
- package/cli/util.js +0 -183
- package/cli/wrappers/amd.js +0 -7
- package/cli/wrappers/closure.js +0 -7
- package/cli/wrappers/commonjs.js +0 -7
- package/cli/wrappers/default.js +0 -15
- package/cli/wrappers/es6.js +0 -5
- package/dist/README.md +0 -31
- package/dist/light/README.md +0 -31
- package/dist/minimal/README.md +0 -31
package/README.md
CHANGED
|
@@ -27,14 +27,6 @@ Contents
|
|
|
27
27
|
* [Using services](#using-services)
|
|
28
28
|
* [Usage with TypeScript](#usage-with-typescript)<br />
|
|
29
29
|
|
|
30
|
-
* [Command line](#command-line)<br />
|
|
31
|
-
How to use the command line utility.
|
|
32
|
-
|
|
33
|
-
* [pbjs for JavaScript](#pbjs-for-javascript)
|
|
34
|
-
* [pbts for TypeScript](#pbts-for-typescript)
|
|
35
|
-
* [Reflection vs. static code](#reflection-vs-static-code)
|
|
36
|
-
* [Command line API](#command-line-api)<br />
|
|
37
|
-
|
|
38
30
|
* [Additional documentation](#additional-documentation)<br />
|
|
39
31
|
A list of available documentation resources.
|
|
40
32
|
|
|
@@ -60,6 +52,12 @@ $> npm install protobufjs [--save --save-prefix=~]
|
|
|
60
52
|
var protobuf = require("protobufjs");
|
|
61
53
|
```
|
|
62
54
|
|
|
55
|
+
The command line utility lives in the protobufjs-cli package and must be installed separately:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
$> npm install protobufjs-cli [--save --save-prefix=~]
|
|
59
|
+
```
|
|
60
|
+
|
|
63
61
|
**Note** that this library's versioning scheme is not semver-compatible for historical reasons. For guaranteed backward compatibility, always depend on `~6.A.B` instead of `^6.A.B` (hence the `--save-prefix` above).
|
|
64
62
|
|
|
65
63
|
### Browsers
|
|
@@ -84,7 +82,7 @@ The library supports CommonJS and AMD loaders and also exports globally as `prot
|
|
|
84
82
|
|
|
85
83
|
Where bundle size is a factor, there are additional stripped-down versions of the [full library][dist-full] (~19kb gzipped) available that exclude certain functionality:
|
|
86
84
|
|
|
87
|
-
* When working with JSON descriptors (i.e. generated by [pbjs](#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:
|
|
85
|
+
* When working with JSON descriptors (i.e. generated by [pbjs](cli/README.md#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:
|
|
88
86
|
|
|
89
87
|
```js
|
|
90
88
|
var protobuf = require("protobufjs/light");
|
|
@@ -597,171 +595,6 @@ Other notes:
|
|
|
597
595
|
|
|
598
596
|
**ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/dcodeIO/protobuf.js/blob/master/examples/js-decorators.js) as well.
|
|
599
597
|
|
|
600
|
-
Command line
|
|
601
|
-
------------
|
|
602
|
-
|
|
603
|
-
**Note** that moving the CLI to [its own package](./cli) is a work in progress. At the moment, it's still part of the main package.
|
|
604
|
-
|
|
605
|
-
The command line interface (CLI) can be used to translate between file formats and to generate static code as well as TypeScript definitions.
|
|
606
|
-
|
|
607
|
-
### pbjs for JavaScript
|
|
608
|
-
|
|
609
|
-
```
|
|
610
|
-
Translates between file formats and generates static code.
|
|
611
|
-
|
|
612
|
-
-t, --target Specifies the target format. Also accepts a path to require a custom target.
|
|
613
|
-
|
|
614
|
-
json JSON representation
|
|
615
|
-
json-module JSON representation as a module
|
|
616
|
-
proto2 Protocol Buffers, Version 2
|
|
617
|
-
proto3 Protocol Buffers, Version 3
|
|
618
|
-
static Static code without reflection (non-functional on its own)
|
|
619
|
-
static-module Static code without reflection as a module
|
|
620
|
-
|
|
621
|
-
-p, --path Adds a directory to the include path.
|
|
622
|
-
|
|
623
|
-
-o, --out Saves to a file instead of writing to stdout.
|
|
624
|
-
|
|
625
|
-
--sparse Exports only those types referenced from a main file (experimental).
|
|
626
|
-
|
|
627
|
-
Module targets only:
|
|
628
|
-
|
|
629
|
-
-w, --wrap Specifies the wrapper to use. Also accepts a path to require a custom wrapper.
|
|
630
|
-
|
|
631
|
-
default Default wrapper supporting both CommonJS and AMD
|
|
632
|
-
commonjs CommonJS wrapper
|
|
633
|
-
amd AMD wrapper
|
|
634
|
-
es6 ES6 wrapper (implies --es6)
|
|
635
|
-
closure A closure adding to protobuf.roots where protobuf is a global
|
|
636
|
-
|
|
637
|
-
-r, --root Specifies an alternative protobuf.roots name.
|
|
638
|
-
|
|
639
|
-
-l, --lint Linter configuration. Defaults to protobuf.js-compatible rules:
|
|
640
|
-
|
|
641
|
-
eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins
|
|
642
|
-
|
|
643
|
-
--es6 Enables ES6 syntax (const/let instead of var)
|
|
644
|
-
|
|
645
|
-
Proto sources only:
|
|
646
|
-
|
|
647
|
-
--keep-case Keeps field casing instead of converting to camel case.
|
|
648
|
-
|
|
649
|
-
Static targets only:
|
|
650
|
-
|
|
651
|
-
--no-create Does not generate create functions used for reflection compatibility.
|
|
652
|
-
--no-encode Does not generate encode functions.
|
|
653
|
-
--no-decode Does not generate decode functions.
|
|
654
|
-
--no-verify Does not generate verify functions.
|
|
655
|
-
--no-convert Does not generate convert functions like from/toObject
|
|
656
|
-
--no-delimited Does not generate delimited encode/decode functions.
|
|
657
|
-
--no-beautify Does not beautify generated code.
|
|
658
|
-
--no-comments Does not output any JSDoc comments.
|
|
659
|
-
|
|
660
|
-
--force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.
|
|
661
|
-
--force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.
|
|
662
|
-
--force-message Enforces the use of message instances instead of plain objects.
|
|
663
|
-
|
|
664
|
-
usage: pbjs [options] file1.proto file2.json ... (or pipe) other | pbjs [options] -
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
For production environments it is recommended to bundle all your .proto files to a single .json file, which minimizes the number of network requests and avoids any parser overhead (hint: works with just the **light** library):
|
|
668
|
-
|
|
669
|
-
```
|
|
670
|
-
$> pbjs -t json file1.proto file2.proto > bundle.json
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
Now, either include this file in your final bundle:
|
|
674
|
-
|
|
675
|
-
```js
|
|
676
|
-
var root = protobuf.Root.fromJSON(require("./bundle.json"));
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
or load it the usual way:
|
|
680
|
-
|
|
681
|
-
```js
|
|
682
|
-
protobuf.load("bundle.json", function(err, root) {
|
|
683
|
-
...
|
|
684
|
-
});
|
|
685
|
-
```
|
|
686
|
-
|
|
687
|
-
Generated static code, on the other hand, works with just the **minimal** library. For example
|
|
688
|
-
|
|
689
|
-
```
|
|
690
|
-
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
|
|
691
|
-
```
|
|
692
|
-
|
|
693
|
-
will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`.
|
|
694
|
-
|
|
695
|
-
**ProTip!** Documenting your .proto files with `/** ... */`-blocks or (trailing) `/// ...` lines translates to generated static code.
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
### pbts for TypeScript
|
|
699
|
-
|
|
700
|
-
```
|
|
701
|
-
Generates TypeScript definitions from annotated JavaScript files.
|
|
702
|
-
|
|
703
|
-
-o, --out Saves to a file instead of writing to stdout.
|
|
704
|
-
|
|
705
|
-
-g, --global Name of the global object in browser environments, if any.
|
|
706
|
-
|
|
707
|
-
--no-comments Does not output any JSDoc comments.
|
|
708
|
-
|
|
709
|
-
Internal flags:
|
|
710
|
-
|
|
711
|
-
-n, --name Wraps everything in a module of the specified name.
|
|
712
|
-
|
|
713
|
-
-m, --main Whether building the main library without any imports.
|
|
714
|
-
|
|
715
|
-
usage: pbts [options] file1.js file2.js ... (or) other | pbts [options] -
|
|
716
|
-
```
|
|
717
|
-
|
|
718
|
-
Picking up on the example above, the following not only generates static code to a CommonJS module `compiled.js` but also its respective TypeScript definitions to `compiled.d.ts`:
|
|
719
|
-
|
|
720
|
-
```
|
|
721
|
-
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
|
|
722
|
-
$> pbts -o compiled.d.ts compiled.js
|
|
723
|
-
```
|
|
724
|
-
|
|
725
|
-
Additionally, TypeScript definitions of static modules are compatible with their reflection-based counterparts (i.e. as exported by JSON modules), as long as the following conditions are met:
|
|
726
|
-
|
|
727
|
-
1. Instead of using `new SomeMessage(...)`, always use `SomeMessage.create(...)` because reflection objects do not provide a constructor.
|
|
728
|
-
2. Types, services and enums must start with an uppercase letter to become available as properties of the reflected types as well (i.e. to be able to use `MyMessage.MyEnum` instead of `root.lookup("MyMessage.MyEnum")`).
|
|
729
|
-
|
|
730
|
-
For example, the following generates a JSON module `bundle.js` and a `bundle.d.ts`, but no static code:
|
|
731
|
-
|
|
732
|
-
```
|
|
733
|
-
$> pbjs -t json-module -w commonjs -o bundle.js file1.proto file2.proto
|
|
734
|
-
$> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts -
|
|
735
|
-
```
|
|
736
|
-
|
|
737
|
-
### Reflection vs. static code
|
|
738
|
-
|
|
739
|
-
While using .proto files directly requires the full library respectively pure reflection/JSON the light library, pretty much all code but the relatively short descriptors is shared.
|
|
740
|
-
|
|
741
|
-
Static code, on the other hand, requires just the minimal library, but generates additional source code without any reflection features. This also implies that there is a break-even point where statically generated code becomes larger than descriptor-based code once the amount of code generated exceeds the size of the full respectively light library.
|
|
742
|
-
|
|
743
|
-
There is no significant difference performance-wise as the code generated statically is pretty much the same as generated at runtime and both are largely interchangeable as seen in the previous section.
|
|
744
|
-
|
|
745
|
-
| Source | Library | Advantages | Tradeoffs
|
|
746
|
-
|--------|---------|------------|-----------
|
|
747
|
-
| .proto | full | Easily editable<br />Interoperability with other libraries<br />No compile step | Some parsing and possibly network overhead
|
|
748
|
-
| JSON | light | Easily editable<br />No parsing overhead<br />Single bundle (no network overhead) | protobuf.js specific<br />Has a compile step
|
|
749
|
-
| static | minimal | Works where `eval` access is restricted<br />Fully documented<br />Small footprint for small protos | Can be hard to edit<br />No reflection<br />Has a compile step
|
|
750
|
-
|
|
751
|
-
### Command line API
|
|
752
|
-
|
|
753
|
-
Both utilities can be used programmatically by providing command line arguments and a callback to their respective `main` functions:
|
|
754
|
-
|
|
755
|
-
```js
|
|
756
|
-
var pbjs = require("protobufjs/cli/pbjs"); // or require("protobufjs/cli").pbjs / .pbts
|
|
757
|
-
|
|
758
|
-
pbjs.main([ "--target", "json-module", "path/to/myproto.proto" ], function(err, output) {
|
|
759
|
-
if (err)
|
|
760
|
-
throw err;
|
|
761
|
-
// do something with output
|
|
762
|
-
});
|
|
763
|
-
```
|
|
764
|
-
|
|
765
598
|
Additional documentation
|
|
766
599
|
------------------------
|
|
767
600
|
|
package/dist/light/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v7.1.0 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled fri, 26 aug 2022 21:49:00 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -1134,8 +1134,14 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
1134
1134
|
if (field.resolvedType instanceof Enum) { gen
|
|
1135
1135
|
("switch(d%s){", prop);
|
|
1136
1136
|
for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
|
|
1137
|
-
|
|
1138
|
-
(
|
|
1137
|
+
// enum unknown values passthrough
|
|
1138
|
+
if (values[keys[i]] === field.typeDefault) { gen
|
|
1139
|
+
("default:")
|
|
1140
|
+
("if(typeof(d%s)===\"number\"){m%s=d%s;break}", prop, prop, prop);
|
|
1141
|
+
if (!field.repeated) gen // fallback to default value only for
|
|
1142
|
+
// arrays, to avoid leaving holes.
|
|
1143
|
+
("break"); // for non-repeated fields, just ignore
|
|
1144
|
+
}
|
|
1139
1145
|
gen
|
|
1140
1146
|
("case%j:", keys[i])
|
|
1141
1147
|
("case %i:", values[keys[i]])
|
|
@@ -1182,7 +1188,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
1182
1188
|
case "bytes": gen
|
|
1183
1189
|
("if(typeof d%s===\"string\")", prop)
|
|
1184
1190
|
("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
|
|
1185
|
-
("else if(d%s.length)", prop)
|
|
1191
|
+
("else if(d%s.length >= 0)", prop)
|
|
1186
1192
|
("m%s=d%s", prop, prop);
|
|
1187
1193
|
break;
|
|
1188
1194
|
case "string": gen
|
|
@@ -1267,7 +1273,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
|
|
|
1267
1273
|
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
1268
1274
|
if (field.resolvedType) {
|
|
1269
1275
|
if (field.resolvedType instanceof Enum) gen
|
|
1270
|
-
("d%s=o.enums===String?types[%i].values[m%s]:m%s", prop, fieldIndex, prop, prop);
|
|
1276
|
+
("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
|
|
1271
1277
|
else gen
|
|
1272
1278
|
("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
|
|
1273
1279
|
} else {
|
|
@@ -1439,7 +1445,7 @@ function decoder(mtype) {
|
|
|
1439
1445
|
var field = mtype._fieldsArray[i].resolve(),
|
|
1440
1446
|
type = field.resolvedType instanceof Enum ? "int32" : field.type,
|
|
1441
1447
|
ref = "m" + util.safeProp(field.name); gen
|
|
1442
|
-
("case %i:", field.id);
|
|
1448
|
+
("case %i: {", field.id);
|
|
1443
1449
|
|
|
1444
1450
|
// Map fields
|
|
1445
1451
|
if (field.map) { gen
|
|
@@ -1510,8 +1516,9 @@ function decoder(mtype) {
|
|
|
1510
1516
|
else gen
|
|
1511
1517
|
("%s=r.%s()", ref, type);
|
|
1512
1518
|
gen
|
|
1513
|
-
("break")
|
|
1514
|
-
|
|
1519
|
+
("break")
|
|
1520
|
+
("}");
|
|
1521
|
+
// Unknown fields
|
|
1515
1522
|
} gen
|
|
1516
1523
|
("default:")
|
|
1517
1524
|
("r.skipType(t&7)")
|
|
@@ -1656,8 +1663,9 @@ var Namespace = require(21),
|
|
|
1656
1663
|
* @param {Object.<string,*>} [options] Declared options
|
|
1657
1664
|
* @param {string} [comment] The comment for this enum
|
|
1658
1665
|
* @param {Object.<string,string>} [comments] The value comments for this enum
|
|
1666
|
+
* @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
|
|
1659
1667
|
*/
|
|
1660
|
-
function Enum(name, values, options, comment, comments) {
|
|
1668
|
+
function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
1661
1669
|
ReflectionObject.call(this, name, options);
|
|
1662
1670
|
|
|
1663
1671
|
if (values && typeof values !== "object")
|
|
@@ -1687,6 +1695,12 @@ function Enum(name, values, options, comment, comments) {
|
|
|
1687
1695
|
*/
|
|
1688
1696
|
this.comments = comments || {};
|
|
1689
1697
|
|
|
1698
|
+
/**
|
|
1699
|
+
* Values options, if any
|
|
1700
|
+
* @type {Object<string, Object<string, *>>|undefined}
|
|
1701
|
+
*/
|
|
1702
|
+
this.valuesOptions = valuesOptions;
|
|
1703
|
+
|
|
1690
1704
|
/**
|
|
1691
1705
|
* Reserved ranges, if any.
|
|
1692
1706
|
* @type {Array.<number[]|string>}
|
|
@@ -1731,11 +1745,12 @@ Enum.fromJSON = function fromJSON(name, json) {
|
|
|
1731
1745
|
Enum.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
1732
1746
|
var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
|
|
1733
1747
|
return util.toObject([
|
|
1734
|
-
"options"
|
|
1735
|
-
"
|
|
1736
|
-
"
|
|
1737
|
-
"
|
|
1738
|
-
"
|
|
1748
|
+
"options" , this.options,
|
|
1749
|
+
"valuesOptions" , this.valuesOptions,
|
|
1750
|
+
"values" , this.values,
|
|
1751
|
+
"reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
|
|
1752
|
+
"comment" , keepComments ? this.comment : undefined,
|
|
1753
|
+
"comments" , keepComments ? this.comments : undefined
|
|
1739
1754
|
]);
|
|
1740
1755
|
};
|
|
1741
1756
|
|
|
@@ -1744,11 +1759,12 @@ Enum.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
1744
1759
|
* @param {string} name Value name
|
|
1745
1760
|
* @param {number} id Value id
|
|
1746
1761
|
* @param {string} [comment] Comment, if any
|
|
1762
|
+
* @param {Object.<string, *>|undefined} [options] Options, if any
|
|
1747
1763
|
* @returns {Enum} `this`
|
|
1748
1764
|
* @throws {TypeError} If arguments are invalid
|
|
1749
1765
|
* @throws {Error} If there is already a value with this name or id
|
|
1750
1766
|
*/
|
|
1751
|
-
Enum.prototype.add = function add(name, id, comment) {
|
|
1767
|
+
Enum.prototype.add = function add(name, id, comment, options) {
|
|
1752
1768
|
// utilized by the parser but not by .fromJSON
|
|
1753
1769
|
|
|
1754
1770
|
if (!util.isString(name))
|
|
@@ -1773,6 +1789,12 @@ Enum.prototype.add = function add(name, id, comment) {
|
|
|
1773
1789
|
} else
|
|
1774
1790
|
this.valuesById[this.values[name] = id] = name;
|
|
1775
1791
|
|
|
1792
|
+
if (options) {
|
|
1793
|
+
if (this.valuesOptions === undefined)
|
|
1794
|
+
this.valuesOptions = {};
|
|
1795
|
+
this.valuesOptions[name] = options || null;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1776
1798
|
this.comments[name] = comment || null;
|
|
1777
1799
|
return this;
|
|
1778
1800
|
};
|
|
@@ -1796,6 +1818,8 @@ Enum.prototype.remove = function remove(name) {
|
|
|
1796
1818
|
delete this.valuesById[val];
|
|
1797
1819
|
delete this.values[name];
|
|
1798
1820
|
delete this.comments[name];
|
|
1821
|
+
if (this.valuesOptions)
|
|
1822
|
+
delete this.valuesOptions[name];
|
|
1799
1823
|
|
|
1800
1824
|
return this;
|
|
1801
1825
|
};
|
|
@@ -2091,6 +2115,9 @@ Field.prototype.resolve = function resolve() {
|
|
|
2091
2115
|
this.typeDefault = null;
|
|
2092
2116
|
else // instanceof Enum
|
|
2093
2117
|
this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
|
|
2118
|
+
} else if (this.options && this.options.proto3_optional) {
|
|
2119
|
+
// proto3 scalar value marked optional; should default to null
|
|
2120
|
+
this.typeDefault = null;
|
|
2094
2121
|
}
|
|
2095
2122
|
|
|
2096
2123
|
// use explicitly set default value if present
|
|
@@ -2777,7 +2804,8 @@ var ReflectionObject = require(22);
|
|
|
2777
2804
|
((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
|
|
2778
2805
|
|
|
2779
2806
|
var Field = require(15),
|
|
2780
|
-
util = require(33)
|
|
2807
|
+
util = require(33),
|
|
2808
|
+
OneOf = require(23);
|
|
2781
2809
|
|
|
2782
2810
|
var Type, // cyclic
|
|
2783
2811
|
Service,
|
|
@@ -2988,7 +3016,7 @@ Namespace.prototype.getEnum = function getEnum(name) {
|
|
|
2988
3016
|
*/
|
|
2989
3017
|
Namespace.prototype.add = function add(object) {
|
|
2990
3018
|
|
|
2991
|
-
if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))
|
|
3019
|
+
if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
|
|
2992
3020
|
throw TypeError("object must be a valid nested object");
|
|
2993
3021
|
|
|
2994
3022
|
if (!this.nested)
|
|
@@ -3203,7 +3231,7 @@ Namespace._configure = function(Type_, Service_, Enum_) {
|
|
|
3203
3231
|
Enum = Enum_;
|
|
3204
3232
|
};
|
|
3205
3233
|
|
|
3206
|
-
},{"15":15,"22":22,"33":33}],22:[function(require,module,exports){
|
|
3234
|
+
},{"15":15,"22":22,"23":23,"33":33}],22:[function(require,module,exports){
|
|
3207
3235
|
"use strict";
|
|
3208
3236
|
module.exports = ReflectionObject;
|
|
3209
3237
|
|
|
@@ -4491,7 +4519,7 @@ module.exports = {};
|
|
|
4491
4519
|
/**
|
|
4492
4520
|
* Named roots.
|
|
4493
4521
|
* This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
|
|
4494
|
-
* Can also be used manually to make roots available
|
|
4522
|
+
* Can also be used manually to make roots available across modules.
|
|
4495
4523
|
* @name roots
|
|
4496
4524
|
* @type {Object.<string,Root>}
|
|
4497
4525
|
* @example
|
|
@@ -5823,6 +5851,9 @@ util.decorateEnum = function decorateEnum(object) {
|
|
|
5823
5851
|
util.setProperty = function setProperty(dst, path, value) {
|
|
5824
5852
|
function setProp(dst, path, value) {
|
|
5825
5853
|
var part = path.shift();
|
|
5854
|
+
if (part === "__proto__") {
|
|
5855
|
+
return dst;
|
|
5856
|
+
}
|
|
5826
5857
|
if (path.length > 0) {
|
|
5827
5858
|
dst[part] = setProp(dst[part] || {}, path, value);
|
|
5828
5859
|
} else {
|
|
@@ -6340,13 +6371,30 @@ function newError(name) {
|
|
|
6340
6371
|
merge(this, properties);
|
|
6341
6372
|
}
|
|
6342
6373
|
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6374
|
+
CustomError.prototype = Object.create(Error.prototype, {
|
|
6375
|
+
constructor: {
|
|
6376
|
+
value: CustomError,
|
|
6377
|
+
writable: true,
|
|
6378
|
+
enumerable: false,
|
|
6379
|
+
configurable: true,
|
|
6380
|
+
},
|
|
6381
|
+
name: {
|
|
6382
|
+
get() { return name; },
|
|
6383
|
+
set: undefined,
|
|
6384
|
+
enumerable: false,
|
|
6385
|
+
// configurable: false would accurately preserve the behavior of
|
|
6386
|
+
// the original, but I'm guessing that was not intentional.
|
|
6387
|
+
// For an actual error subclass, this property would
|
|
6388
|
+
// be configurable.
|
|
6389
|
+
configurable: true,
|
|
6390
|
+
},
|
|
6391
|
+
toString: {
|
|
6392
|
+
value() { return this.name + ": " + this.message; },
|
|
6393
|
+
writable: true,
|
|
6394
|
+
enumerable: false,
|
|
6395
|
+
configurable: true,
|
|
6396
|
+
},
|
|
6397
|
+
});
|
|
6350
6398
|
|
|
6351
6399
|
return CustomError;
|
|
6352
6400
|
}
|
|
@@ -6710,7 +6758,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
6710
6758
|
if (type) {
|
|
6711
6759
|
// type_url does not accept leading "."
|
|
6712
6760
|
var type_url = object["@type"].charAt(0) === "." ?
|
|
6713
|
-
object["@type"].
|
|
6761
|
+
object["@type"].slice(1) : object["@type"];
|
|
6714
6762
|
// type_url prefix is optional, but path seperator is required
|
|
6715
6763
|
if (type_url.indexOf("/") === -1) {
|
|
6716
6764
|
type_url = "/" + type_url;
|
|
@@ -6748,7 +6796,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
6748
6796
|
if (!(message instanceof this.ctor) && message instanceof Message) {
|
|
6749
6797
|
var object = message.$type.toObject(message, options);
|
|
6750
6798
|
var messageName = message.$type.fullName[0] === "." ?
|
|
6751
|
-
message.$type.fullName.
|
|
6799
|
+
message.$type.fullName.slice(1) : message.$type.fullName;
|
|
6752
6800
|
// Default to type.googleapis.com prefix if no prefix is used
|
|
6753
6801
|
if (prefix === "") {
|
|
6754
6802
|
prefix = googleApi;
|