protobufjs 6.11.1 → 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.
- package/README.md +7 -174
- package/dist/light/protobuf.js +40 -16
- 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 +109 -46
- 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 +1 -1
- package/package.json +11 -30
- package/scripts/postinstall.js +0 -3
- package/src/converter.js +1 -1
- package/src/decoder.js +4 -3
- package/src/field.js +3 -0
- package/src/namespace.js +1 -2
- package/src/parse.js +38 -14
- 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/CHANGELOG.md +0 -1014
- 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/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 v6.
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v6.10.2 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled fri, 08 jul 2022 16:17:13 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -1182,7 +1182,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
1182
1182
|
case "bytes": gen
|
|
1183
1183
|
("if(typeof d%s===\"string\")", prop)
|
|
1184
1184
|
("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)
|
|
1185
|
+
("else if(d%s.length >= 0)", prop)
|
|
1186
1186
|
("m%s=d%s", prop, prop);
|
|
1187
1187
|
break;
|
|
1188
1188
|
case "string": gen
|
|
@@ -1439,7 +1439,7 @@ function decoder(mtype) {
|
|
|
1439
1439
|
var field = mtype._fieldsArray[i].resolve(),
|
|
1440
1440
|
type = field.resolvedType instanceof Enum ? "int32" : field.type,
|
|
1441
1441
|
ref = "m" + util.safeProp(field.name); gen
|
|
1442
|
-
("case %i:", field.id);
|
|
1442
|
+
("case %i: {", field.id);
|
|
1443
1443
|
|
|
1444
1444
|
// Map fields
|
|
1445
1445
|
if (field.map) { gen
|
|
@@ -1510,8 +1510,9 @@ function decoder(mtype) {
|
|
|
1510
1510
|
else gen
|
|
1511
1511
|
("%s=r.%s()", ref, type);
|
|
1512
1512
|
gen
|
|
1513
|
-
("break")
|
|
1514
|
-
|
|
1513
|
+
("break")
|
|
1514
|
+
("}");
|
|
1515
|
+
// Unknown fields
|
|
1515
1516
|
} gen
|
|
1516
1517
|
("default:")
|
|
1517
1518
|
("r.skipType(t&7)")
|
|
@@ -2091,6 +2092,9 @@ Field.prototype.resolve = function resolve() {
|
|
|
2091
2092
|
this.typeDefault = null;
|
|
2092
2093
|
else // instanceof Enum
|
|
2093
2094
|
this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
|
|
2095
|
+
} else if (this.options && this.options.proto3_optional) {
|
|
2096
|
+
// proto3 scalar value marked optional; should default to null
|
|
2097
|
+
this.typeDefault = null;
|
|
2094
2098
|
}
|
|
2095
2099
|
|
|
2096
2100
|
// use explicitly set default value if present
|
|
@@ -4491,7 +4495,7 @@ module.exports = {};
|
|
|
4491
4495
|
/**
|
|
4492
4496
|
* Named roots.
|
|
4493
4497
|
* This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
|
|
4494
|
-
* Can also be used manually to make roots available
|
|
4498
|
+
* Can also be used manually to make roots available across modules.
|
|
4495
4499
|
* @name roots
|
|
4496
4500
|
* @type {Object.<string,Root>}
|
|
4497
4501
|
* @example
|
|
@@ -5823,6 +5827,9 @@ util.decorateEnum = function decorateEnum(object) {
|
|
|
5823
5827
|
util.setProperty = function setProperty(dst, path, value) {
|
|
5824
5828
|
function setProp(dst, path, value) {
|
|
5825
5829
|
var part = path.shift();
|
|
5830
|
+
if (part === "__proto__") {
|
|
5831
|
+
return dst;
|
|
5832
|
+
}
|
|
5826
5833
|
if (path.length > 0) {
|
|
5827
5834
|
dst[part] = setProp(dst[part] || {}, path, value);
|
|
5828
5835
|
} else {
|
|
@@ -6340,13 +6347,30 @@ function newError(name) {
|
|
|
6340
6347
|
merge(this, properties);
|
|
6341
6348
|
}
|
|
6342
6349
|
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
+
CustomError.prototype = Object.create(Error.prototype, {
|
|
6351
|
+
constructor: {
|
|
6352
|
+
value: CustomError,
|
|
6353
|
+
writable: true,
|
|
6354
|
+
enumerable: false,
|
|
6355
|
+
configurable: true,
|
|
6356
|
+
},
|
|
6357
|
+
name: {
|
|
6358
|
+
get() { return name; },
|
|
6359
|
+
set: undefined,
|
|
6360
|
+
enumerable: false,
|
|
6361
|
+
// configurable: false would accurately preserve the behavior of
|
|
6362
|
+
// the original, but I'm guessing that was not intentional.
|
|
6363
|
+
// For an actual error subclass, this property would
|
|
6364
|
+
// be configurable.
|
|
6365
|
+
configurable: true,
|
|
6366
|
+
},
|
|
6367
|
+
toString: {
|
|
6368
|
+
value() { return this.name + ": " + this.message; },
|
|
6369
|
+
writable: true,
|
|
6370
|
+
enumerable: false,
|
|
6371
|
+
configurable: true,
|
|
6372
|
+
},
|
|
6373
|
+
});
|
|
6350
6374
|
|
|
6351
6375
|
return CustomError;
|
|
6352
6376
|
}
|
|
@@ -6710,7 +6734,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
6710
6734
|
if (type) {
|
|
6711
6735
|
// type_url does not accept leading "."
|
|
6712
6736
|
var type_url = object["@type"].charAt(0) === "." ?
|
|
6713
|
-
object["@type"].
|
|
6737
|
+
object["@type"].slice(1) : object["@type"];
|
|
6714
6738
|
// type_url prefix is optional, but path seperator is required
|
|
6715
6739
|
if (type_url.indexOf("/") === -1) {
|
|
6716
6740
|
type_url = "/" + type_url;
|
|
@@ -6748,7 +6772,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
6748
6772
|
if (!(message instanceof this.ctor) && message instanceof Message) {
|
|
6749
6773
|
var object = message.$type.toObject(message, options);
|
|
6750
6774
|
var messageName = message.$type.fullName[0] === "." ?
|
|
6751
|
-
message.$type.fullName.
|
|
6775
|
+
message.$type.fullName.slice(1) : message.$type.fullName;
|
|
6752
6776
|
// Default to type.googleapis.com prefix if no prefix is used
|
|
6753
6777
|
if (prefix === "") {
|
|
6754
6778
|
prefix = googleApi;
|