protobufjs 8.5.0 → 8.6.1
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 +46 -57
- package/dist/light/protobuf.js +159 -121
- 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 +26 -69
- 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 +174 -122
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/README.md +38 -49
- package/ext/descriptor.d.ts +8 -7
- package/ext/descriptor.generated.d.ts +16 -8
- package/ext/descriptor.js +170 -104
- package/ext/protojson.LICENSE +201 -0
- package/ext/protojson.d.ts +20 -0
- package/ext/protojson.generated.d.ts +49 -0
- package/ext/protojson.js +925 -0
- package/ext/textformat.d.ts +2 -2
- package/ext/textformat.generated.d.ts +22 -0
- package/ext/textformat.js +40 -19
- package/index.d.ts +35 -17
- package/package.json +2 -6
- package/src/converter.js +3 -3
- package/src/decoder.js +2 -2
- package/src/encoder.js +1 -1
- package/src/field.js +49 -7
- package/src/mapfield.js +16 -7
- package/src/parse.js +15 -1
- package/src/service.js +5 -7
- package/src/type.js +12 -3
- package/src/util/minimal.js +1 -4
- package/src/util.js +23 -0
- package/src/verifier.js +2 -2
- package/scripts/postinstall.js +0 -32
- package/src/util/inquire.d.ts +0 -10
- package/src/util/inquire.js +0 -38
package/ext/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## descriptor
|
|
4
4
|
|
|
5
|
-
Optional `
|
|
5
|
+
Optional `descriptor.proto` support for converting reflected protobuf.js roots and objects to and from descriptor messages.
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
import protobuf from "protobufjs";
|
|
9
9
|
import descriptor from "protobufjs/ext/descriptor.js";
|
|
10
10
|
|
|
11
11
|
// Convert an existing root to a FileDescriptorSet message.
|
|
12
|
-
const root =
|
|
12
|
+
const root = ...;
|
|
13
13
|
const set = root.toDescriptor("proto2");
|
|
14
14
|
|
|
15
15
|
// Encode descriptor buffers.
|
|
@@ -21,61 +21,50 @@ const decodedRoot = protobuf.Root.fromDescriptor(buffer);
|
|
|
21
21
|
|
|
22
22
|
The extension requires reflection metadata and also works with `protobufjs/light.js` when schemas are loaded from JSON or otherwise provided as reflection objects.
|
|
23
23
|
|
|
24
|
-
Importing the extension adds `.fromDescriptor(descriptor[,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
| ServiceOptions | | |
|
|
54
|
-
| **MethodDescriptorProto** | Method | |
|
|
55
|
-
| MethodOptions | | |
|
|
56
|
-
| FeatureSet | | exported descriptor type; used by edition-aware options |
|
|
57
|
-
| FeatureSetDefaults | | exported descriptor type |
|
|
58
|
-
| UninterpretedOption | | exported descriptor type; options are not interpreted |
|
|
59
|
-
| UninterpretedOptionNamePart | | |
|
|
60
|
-
|
|
61
|
-
Not all `descriptor.proto` features translate perfectly to a protobuf.js root. A root has only limited knowledge of packages and individual files, for example, which is compensated by guessing and generating file names.
|
|
62
|
-
|
|
63
|
-
The exported TypeScript interfaces can be used to reference specific descriptor message instances, for example `protobuf.Message<IDescriptorProto>`.
|
|
24
|
+
Importing the extension adds `.fromDescriptor(descriptor[, editionOrContext])` and `#toDescriptor([syntaxOrEdition])` methods to reflection objects and exports the bundled descriptor types from `google.protobuf`. Descriptor inputs can be decoded messages, readers, or buffers of the corresponding descriptor messages. Direct object descriptor imports accept either an edition string or a descriptor context with `edition`, `features` and `keepCase`.
|
|
25
|
+
|
|
26
|
+
The conversion covers descriptor messages that correspond to protobuf.js reflection objects: files and file sets, messages, fields and map fields, oneofs, enums, services and methods. Descriptor-only metadata such as source locations, generated-code annotations and uninterpreted options remains available through the exported descriptor message types, but is not mapped onto reflection objects. File names are inferred when generating descriptors because roots do not retain exact file/package boundaries.
|
|
27
|
+
|
|
28
|
+
## protojson
|
|
29
|
+
|
|
30
|
+
Optional ProtoJSON support for reflected message types.
|
|
31
|
+
|
|
32
|
+
> [!NOTE]
|
|
33
|
+
> Specialized code generation for the `pbjs` static-module target is a potential future extension. If you need this for high-throughput JSON transcoding or REST fallbacks in production, consider getting in touch and supporting the codegen and conformance work.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import protobuf from "protobufjs";
|
|
37
|
+
import protojson from "protobufjs/ext/protojson.js";
|
|
38
|
+
|
|
39
|
+
const root = ...;
|
|
40
|
+
const MyType = root.lookupType("MyType");
|
|
41
|
+
const message = protojson.fromJson(MyType, { value: 1 });
|
|
42
|
+
const json = protojson.toJson(MyType, message);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
const messageFromString = protojson.fromJsonString(MyType, '{"value":1}');
|
|
47
|
+
const jsonString = protojson.toJsonString(MyType, messageFromString);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Importing the extension has no prototype side effects. Calling `protojson.install()` installs `fromJson`, `fromJsonString`, `toJson` and `toJsonString` convenience methods on `protobuf.Type.prototype`. It works with `protobufjs/light.js` when schemas are loaded from JSON or otherwise provided as reflection objects.
|
|
51
|
+
|
|
52
|
+
Unknown fields can be ignored while parsing by passing `{ ignoreUnknownFields: true }` to `fromJson` or `fromJsonString`.
|
|
64
53
|
|
|
65
54
|
## textformat
|
|
66
55
|
|
|
67
|
-
Optional
|
|
56
|
+
Optional Text Format support for reflected message types.
|
|
68
57
|
|
|
69
58
|
```js
|
|
70
59
|
import protobuf from "protobufjs";
|
|
71
|
-
import "protobufjs/ext/textformat.js";
|
|
60
|
+
import textformat from "protobufjs/ext/textformat.js";
|
|
72
61
|
|
|
73
|
-
const root =
|
|
62
|
+
const root = ...;
|
|
74
63
|
const MyType = root.lookupType("MyType");
|
|
75
|
-
const message =
|
|
76
|
-
const text =
|
|
64
|
+
const message = textformat.fromText(MyType, "value: 1");
|
|
65
|
+
const text = textformat.toText(MyType, message);
|
|
77
66
|
```
|
|
78
67
|
|
|
79
|
-
|
|
68
|
+
Importing the extension has no prototype side effects. Calling `textformat.install()` installs `fromText` and `toText` convenience methods on `protobuf.Type.prototype`. It works with `protobufjs/light.js` when schemas are loaded from JSON or otherwise provided as reflection objects.
|
|
80
69
|
|
|
81
|
-
|
|
70
|
+
Unknown fields can be printed with numeric field names by passing `{ unknowns: true }` to `toText`.
|
package/ext/descriptor.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as $protobuf from "..";
|
|
2
2
|
import {
|
|
3
3
|
IDescriptorProto,
|
|
4
|
+
IDescriptorContext,
|
|
4
5
|
IEnumDescriptorProto,
|
|
5
6
|
IFieldDescriptorProto,
|
|
6
7
|
IFileDescriptorSet,
|
|
@@ -16,7 +17,7 @@ type DescriptorInput<T> = T | $protobuf.Reader | Uint8Array;
|
|
|
16
17
|
declare module ".." {
|
|
17
18
|
namespace Root {
|
|
18
19
|
/** Creates a root from a descriptor set. */
|
|
19
|
-
function fromDescriptor(descriptor: DescriptorInput<IFileDescriptorSet
|
|
20
|
+
function fromDescriptor(descriptor: DescriptorInput<IFileDescriptorSet>, options?: { keepCase?: boolean }): $protobuf.Root;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
interface Root {
|
|
@@ -26,7 +27,7 @@ declare module ".." {
|
|
|
26
27
|
|
|
27
28
|
namespace Type {
|
|
28
29
|
/** Creates a type from a descriptor. */
|
|
29
|
-
function fromDescriptor(descriptor: DescriptorInput<IDescriptorProto>,
|
|
30
|
+
function fromDescriptor(descriptor: DescriptorInput<IDescriptorProto>, editionOrContext?: string | IDescriptorContext): $protobuf.Type;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
interface Type {
|
|
@@ -36,7 +37,7 @@ declare module ".." {
|
|
|
36
37
|
|
|
37
38
|
namespace Field {
|
|
38
39
|
/** Creates a field from a descriptor. */
|
|
39
|
-
function fromDescriptor(descriptor: DescriptorInput<IFieldDescriptorProto>,
|
|
40
|
+
function fromDescriptor(descriptor: DescriptorInput<IFieldDescriptorProto>, editionOrContext?: string | IDescriptorContext): $protobuf.Field;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
interface Field {
|
|
@@ -46,7 +47,7 @@ declare module ".." {
|
|
|
46
47
|
|
|
47
48
|
namespace Enum {
|
|
48
49
|
/** Creates an enum from a descriptor. */
|
|
49
|
-
function fromDescriptor(descriptor: DescriptorInput<IEnumDescriptorProto>,
|
|
50
|
+
function fromDescriptor(descriptor: DescriptorInput<IEnumDescriptorProto>, editionOrContext?: string | IDescriptorContext): $protobuf.Enum;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
interface Enum {
|
|
@@ -56,7 +57,7 @@ declare module ".." {
|
|
|
56
57
|
|
|
57
58
|
namespace OneOf {
|
|
58
59
|
/** Creates a oneof from a descriptor. */
|
|
59
|
-
function fromDescriptor(descriptor: DescriptorInput<IOneofDescriptorProto
|
|
60
|
+
function fromDescriptor(descriptor: DescriptorInput<IOneofDescriptorProto>, editionOrContext?: string | IDescriptorContext): $protobuf.OneOf;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
interface OneOf {
|
|
@@ -66,7 +67,7 @@ declare module ".." {
|
|
|
66
67
|
|
|
67
68
|
namespace Service {
|
|
68
69
|
/** Creates a service from a descriptor. */
|
|
69
|
-
function fromDescriptor(descriptor: DescriptorInput<IServiceDescriptorProto>,
|
|
70
|
+
function fromDescriptor(descriptor: DescriptorInput<IServiceDescriptorProto>, editionOrContext?: string | IDescriptorContext): $protobuf.Service;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
interface Service {
|
|
@@ -76,7 +77,7 @@ declare module ".." {
|
|
|
76
77
|
|
|
77
78
|
namespace Method {
|
|
78
79
|
/** Creates a method from a descriptor. */
|
|
79
|
-
function fromDescriptor(descriptor: DescriptorInput<IMethodDescriptorProto
|
|
80
|
+
function fromDescriptor(descriptor: DescriptorInput<IMethodDescriptorProto>, editionOrContext?: string | IDescriptorContext): $protobuf.Method;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
interface Method {
|
|
@@ -170,6 +170,19 @@ export interface IFileOptions {
|
|
|
170
170
|
/** Values of he FileOptions.OptimizeMode enum. */
|
|
171
171
|
export type IFileOptionsOptimizeMode = number;
|
|
172
172
|
|
|
173
|
+
/** Descriptor context. */
|
|
174
|
+
export interface IDescriptorContext {
|
|
175
|
+
|
|
176
|
+
/** Syntax or edition to use for direct object descriptor imports */
|
|
177
|
+
edition?: string;
|
|
178
|
+
|
|
179
|
+
/** File-level features to apply for direct object descriptor imports */
|
|
180
|
+
features?: IFeatureSet;
|
|
181
|
+
|
|
182
|
+
/** Uses proto field names as reflected field names */
|
|
183
|
+
keepCase?: boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
173
186
|
/** Properties of a DescriptorProto message. */
|
|
174
187
|
export interface IDescriptorProto {
|
|
175
188
|
|
|
@@ -258,8 +271,8 @@ export interface IFieldDescriptorProto {
|
|
|
258
271
|
/** Oneof index if part of a oneof */
|
|
259
272
|
oneofIndex?: number;
|
|
260
273
|
|
|
261
|
-
/**
|
|
262
|
-
jsonName?:
|
|
274
|
+
/** JSON name (lowerCamelCase) */
|
|
275
|
+
jsonName?: string;
|
|
263
276
|
|
|
264
277
|
/** Field options */
|
|
265
278
|
options?: IFieldOptions;
|
|
@@ -398,12 +411,7 @@ export interface IMethodDescriptorProto {
|
|
|
398
411
|
serverStreaming?: boolean;
|
|
399
412
|
}
|
|
400
413
|
|
|
401
|
-
/**
|
|
402
|
-
* Properties of a MethodOptions message.
|
|
403
|
-
*
|
|
404
|
-
* Warning: this is not safe to use with editions protos, since it discards relevant file context.
|
|
405
|
-
*
|
|
406
|
-
*/
|
|
414
|
+
/** Properties of a MethodOptions message. */
|
|
407
415
|
export interface IMethodOptions {
|
|
408
416
|
deprecated?: boolean;
|
|
409
417
|
}
|