protobufjs 8.1.5-experimental → 8.2.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 (76) hide show
  1. package/README.md +219 -565
  2. package/dist/light/protobuf.js +1986 -1483
  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 +1122 -861
  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 +2089 -1513
  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/ext/README.md +81 -0
  15. package/ext/descriptor/README.md +3 -70
  16. package/ext/descriptor/index.d.ts +1 -191
  17. package/ext/descriptor/index.js +1 -1156
  18. package/ext/descriptor.d.ts +309 -0
  19. package/ext/descriptor.js +1236 -0
  20. package/ext/textformat.d.ts +30 -0
  21. package/ext/textformat.js +1249 -0
  22. package/google/protobuf/compiler/plugin.json +126 -0
  23. package/google/protobuf/compiler/plugin.proto +47 -0
  24. package/google/protobuf/descriptor.json +114 -10
  25. package/google/protobuf/descriptor.proto +35 -9
  26. package/index.d.ts +590 -476
  27. package/package.json +23 -38
  28. package/src/converter.js +60 -24
  29. package/src/decoder.js +122 -49
  30. package/src/encoder.js +10 -2
  31. package/src/enum.js +4 -1
  32. package/src/field.js +10 -7
  33. package/src/mapfield.js +1 -0
  34. package/src/message.js +7 -6
  35. package/src/method.js +4 -3
  36. package/src/namespace.js +23 -12
  37. package/src/object.js +24 -19
  38. package/src/oneof.js +2 -0
  39. package/src/parse.js +114 -46
  40. package/src/reader.js +145 -30
  41. package/src/reader_buffer.js +24 -3
  42. package/src/root.js +7 -4
  43. package/src/service.js +12 -6
  44. package/src/tokenize.js +6 -1
  45. package/src/type.js +48 -25
  46. package/src/types.js +1 -1
  47. package/src/util/aspromise.d.ts +13 -0
  48. package/src/util/aspromise.js +52 -0
  49. package/src/util/base64.d.ts +32 -0
  50. package/src/util/base64.js +146 -0
  51. package/src/util/codegen.d.ts +31 -0
  52. package/src/util/codegen.js +113 -0
  53. package/src/util/eventemitter.d.ts +45 -0
  54. package/src/util/eventemitter.js +84 -0
  55. package/src/util/fetch.d.ts +56 -0
  56. package/src/util/fetch.js +112 -0
  57. package/src/util/float.d.ts +83 -0
  58. package/src/util/float.js +335 -0
  59. package/src/util/fs.js +11 -0
  60. package/src/util/inquire.d.ts +10 -0
  61. package/src/util/inquire.js +38 -0
  62. package/src/util/minimal.js +67 -12
  63. package/src/util/path.d.ts +22 -0
  64. package/src/util/path.js +72 -0
  65. package/src/util/patterns.js +8 -0
  66. package/src/util/pool.d.ts +32 -0
  67. package/src/util/pool.js +48 -0
  68. package/src/util/utf8.d.ts +24 -0
  69. package/src/util/utf8.js +104 -0
  70. package/src/util.js +30 -13
  71. package/src/verifier.js +7 -4
  72. package/src/wrappers.js +4 -3
  73. package/src/writer.js +27 -4
  74. package/src/writer_buffer.js +12 -0
  75. package/tsconfig.json +2 -2
  76. package/ext/descriptor/test.js +0 -54
package/ext/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # protobuf.js Extensions
2
+
3
+ ## descriptor
4
+
5
+ Optional `google/protobuf/descriptor.proto` interoperability layer for reflected roots and objects.
6
+
7
+ ```js
8
+ import protobuf from "protobufjs";
9
+ import descriptor from "protobufjs/ext/descriptor.js";
10
+
11
+ // Convert an existing root to a FileDescriptorSet message.
12
+ const root = protobuf.Root.fromJSON(bundle);
13
+ const set = root.toDescriptor("proto2");
14
+
15
+ // Encode descriptor buffers.
16
+ const buffer = descriptor.FileDescriptorSet.encode(set).finish();
17
+
18
+ // Convert a FileDescriptorSet message or buffer back to a root.
19
+ const decodedRoot = protobuf.Root.fromDescriptor(buffer);
20
+ ```
21
+
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
+
24
+ Importing the extension adds `.fromDescriptor(descriptor[, syntaxOrEdition])` and `#toDescriptor([syntaxOrEdition])` methods to reflection objects and exports reflected descriptor types from `google.protobuf`. Descriptor inputs can be decoded messages, readers, or `Uint8Array`s for the corresponding descriptor message.
25
+
26
+ | Descriptor type | protobuf.js type | Remarks |
27
+ |-------------------------------|------------------|---------|
28
+ | **FileDescriptorSet** | Root | |
29
+ | FileDescriptorProto | | dependencies and source info are ignored on input and not emitted |
30
+ | FileOptions | | |
31
+ | FileOptionsOptimizeMode | | |
32
+ | SourceCodeInfo | | exported descriptor type; not mapped to reflection |
33
+ | SourceCodeInfoLocation | | |
34
+ | GeneratedCodeInfo | | exported descriptor type; not mapped to reflection |
35
+ | GeneratedCodeInfoAnnotation | | |
36
+ | **DescriptorProto** | Type | |
37
+ | MessageOptions | | |
38
+ | DescriptorProtoExtensionRange | | |
39
+ | DescriptorProtoReservedRange | | |
40
+ | **FieldDescriptorProto** | Field / MapField | map entries are reconstructed as map fields |
41
+ | FieldDescriptorProtoLabel | | |
42
+ | FieldDescriptorProtoType | | |
43
+ | FieldOptions | | |
44
+ | FieldOptionsCType | | |
45
+ | FieldOptionsJSType | | |
46
+ | **OneofDescriptorProto** | OneOf | |
47
+ | OneofOptions | | |
48
+ | **EnumDescriptorProto** | Enum | |
49
+ | EnumOptions | | |
50
+ | EnumValueDescriptorProto | | |
51
+ | EnumValueOptions | | |
52
+ | **ServiceDescriptorProto** | Service | |
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>`.
64
+
65
+ ## textformat
66
+
67
+ Optional text format support for reflected message types.
68
+
69
+ ```js
70
+ import protobuf from "protobufjs";
71
+ import "protobufjs/ext/textformat.js";
72
+
73
+ const root = protobuf.Root.fromJSON(bundle);
74
+ const MyType = root.lookupType("MyType");
75
+ const message = MyType.fromText("value: 1");
76
+ const text = MyType.toText(message);
77
+ ```
78
+
79
+ The extension patches `protobuf.Type` at runtime and requires reflection metadata. It works with `protobufjs/light.js` when schemas are loaded from JSON or otherwise provided as reflection objects. Static-only code using `protobufjs/minimal.js` is not supported.
80
+
81
+ Text output is produced from the message object passed to `toText`. Unknown fields can be printed with numeric field names by passing `{ unknowns: true }` to `toText`.
@@ -1,72 +1,5 @@
1
- protobufjs/ext/descriptor
2
- =========================
1
+ # protobufjs/ext/descriptor
3
2
 
4
- Experimental extension for interoperability with [descriptor.proto](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto) types.
3
+ This directory is kept as a backwards-compatible shim for `protobufjs/ext/descriptor` and may be removed in a future major release.
5
4
 
6
- Usage
7
- -----
8
-
9
- ```js
10
- var protobuf = require("protobufjs"), // requires the full library
11
- descriptor = require("protobufjs/ext/descriptor");
12
-
13
- var root = ...;
14
-
15
- // convert any existing root instance to the corresponding descriptor type
16
- var descriptorMsg = root.toDescriptor("proto2");
17
- // ^ returns a FileDescriptorSet message, see table below
18
-
19
- // encode to a descriptor buffer
20
- var buffer = descriptor.FileDescriptorSet.encode(descriptorMsg).finish();
21
-
22
- // decode from a descriptor buffer
23
- var decodedDescriptor = descriptor.FileDescriptorSet.decode(buffer);
24
-
25
- // convert any existing descriptor to a root instance
26
- root = protobuf.Root.fromDescriptor(decodedDescriptor);
27
- // ^ expects a FileDescriptorSet message or buffer, see table below
28
-
29
- // and start all over again
30
- ```
31
-
32
- API
33
- ---
34
-
35
- The extension adds `.fromDescriptor(descriptor[, syntax])` and `#toDescriptor([syntax])` methods to reflection objects and exports the `.google.protobuf` namespace of the internally used `Root` instance containing the following types present in descriptor.proto:
36
-
37
- | Descriptor type | protobuf.js type | Remarks
38
- |-------------------------------|------------------|---------
39
- | **FileDescriptorSet** | Root |
40
- | FileDescriptorProto | | dependencies are not supported
41
- | FileOptions | |
42
- | FileOptionsOptimizeMode | |
43
- | SourceCodeInfo | | not supported
44
- | SourceCodeInfoLocation | |
45
- | GeneratedCodeInfo | | not supported
46
- | GeneratedCodeInfoAnnotation | |
47
- | **DescriptorProto** | Type |
48
- | MessageOptions | |
49
- | DescriptorProtoExtensionRange | |
50
- | DescriptorProtoReservedRange | |
51
- | **FieldDescriptorProto** | Field |
52
- | FieldDescriptorProtoLabel | |
53
- | FieldDescriptorProtoType | |
54
- | FieldOptions | |
55
- | FieldOptionsCType | |
56
- | FieldOptionsJSType | |
57
- | **OneofDescriptorProto** | OneOf |
58
- | OneofOptions | |
59
- | **EnumDescriptorProto** | Enum |
60
- | EnumOptions | |
61
- | EnumValueDescriptorProto | |
62
- | EnumValueOptions | | not supported
63
- | **ServiceDescriptorProto** | Service |
64
- | ServiceOptions | |
65
- | **MethodDescriptorProto** | Method |
66
- | MethodOptions | |
67
- | UninterpretedOption | | not supported
68
- | UninterpretedOptionNamePart | |
69
-
70
- Note that not all features of descriptor.proto translate perfectly to a protobuf.js root instance. A root instance has only limited knowlege of packages or individual files for example, which is then compensated by guessing and generating fictional file names.
71
-
72
- When using TypeScript, the respective interface types can be used to reference specific message instances (i.e. `protobuf.Message<IDescriptorProto>`).
5
+ The descriptor extension documentation now lives in [../README.md](../README.md#descriptor).
@@ -1,191 +1 @@
1
- import * as $protobuf from "../..";
2
- export const FileDescriptorSet: $protobuf.Type;
3
-
4
- export const FileDescriptorProto: $protobuf.Type;
5
-
6
- export const DescriptorProto: $protobuf.Type & {
7
- ExtensionRange: $protobuf.Type,
8
- ReservedRange: $protobuf.Type
9
- };
10
-
11
- export const FieldDescriptorProto: $protobuf.Type & {
12
- Label: $protobuf.Enum,
13
- Type: $protobuf.Enum
14
- };
15
-
16
- export const OneofDescriptorProto: $protobuf.Type;
17
-
18
- export const EnumDescriptorProto: $protobuf.Type;
19
-
20
- export const ServiceDescriptorProto: $protobuf.Type;
21
-
22
- export const EnumValueDescriptorProto: $protobuf.Type;
23
-
24
- export const MethodDescriptorProto: $protobuf.Type;
25
-
26
- export const FileOptions: $protobuf.Type & {
27
- OptimizeMode: $protobuf.Enum
28
- };
29
-
30
- export const MessageOptions: $protobuf.Type;
31
-
32
- export const FieldOptions: $protobuf.Type & {
33
- CType: $protobuf.Enum,
34
- JSType: $protobuf.Enum
35
- };
36
-
37
- export const OneofOptions: $protobuf.Type;
38
-
39
- export const EnumOptions: $protobuf.Type;
40
-
41
- export const EnumValueOptions: $protobuf.Type;
42
-
43
- export const ServiceOptions: $protobuf.Type;
44
-
45
- export const MethodOptions: $protobuf.Type;
46
-
47
- export const UninterpretedOption: $protobuf.Type & {
48
- NamePart: $protobuf.Type
49
- };
50
-
51
- export const SourceCodeInfo: $protobuf.Type & {
52
- Location: $protobuf.Type
53
- };
54
-
55
- export const GeneratedCodeInfo: $protobuf.Type & {
56
- Annotation: $protobuf.Type
57
- };
58
-
59
- export interface IFileDescriptorSet {
60
- file: IFileDescriptorProto[];
61
- }
62
-
63
- export interface IFileDescriptorProto {
64
- name?: string;
65
- package?: string;
66
- dependency?: any;
67
- publicDependency?: any;
68
- weakDependency?: any;
69
- messageType?: IDescriptorProto[];
70
- enumType?: IEnumDescriptorProto[];
71
- service?: IServiceDescriptorProto[];
72
- extension?: IFieldDescriptorProto[];
73
- options?: IFileOptions;
74
- sourceCodeInfo?: any;
75
- syntax?: string;
76
- }
77
-
78
- export interface IFileOptions {
79
- javaPackage?: string;
80
- javaOuterClassname?: string;
81
- javaMultipleFiles?: boolean;
82
- javaGenerateEqualsAndHash?: boolean;
83
- javaStringCheckUtf8?: boolean;
84
- optimizeFor?: IFileOptionsOptimizeMode;
85
- goPackage?: string;
86
- ccGenericServices?: boolean;
87
- javaGenericServices?: boolean;
88
- pyGenericServices?: boolean;
89
- deprecated?: boolean;
90
- ccEnableArenas?: boolean;
91
- objcClassPrefix?: string;
92
- csharpNamespace?: string;
93
- }
94
-
95
- type IFileOptionsOptimizeMode = number;
96
-
97
- export interface IDescriptorProto {
98
- name?: string;
99
- field?: IFieldDescriptorProto[];
100
- extension?: IFieldDescriptorProto[];
101
- nestedType?: IDescriptorProto[];
102
- enumType?: IEnumDescriptorProto[];
103
- extensionRange?: IDescriptorProtoExtensionRange[];
104
- oneofDecl?: IOneofDescriptorProto[];
105
- options?: IMessageOptions;
106
- reservedRange?: IDescriptorProtoReservedRange[];
107
- reservedName?: string[];
108
- }
109
-
110
- export interface IMessageOptions {
111
- mapEntry?: boolean;
112
- }
113
-
114
- export interface IDescriptorProtoExtensionRange {
115
- start?: number;
116
- end?: number;
117
- }
118
-
119
- export interface IDescriptorProtoReservedRange {
120
- start?: number;
121
- end?: number;
122
- }
123
-
124
- export interface IFieldDescriptorProto {
125
- name?: string;
126
- number?: number;
127
- label?: IFieldDescriptorProtoLabel;
128
- type?: IFieldDescriptorProtoType;
129
- typeName?: string;
130
- extendee?: string;
131
- defaultValue?: string;
132
- oneofIndex?: number;
133
- jsonName?: any;
134
- options?: IFieldOptions;
135
- }
136
-
137
- type IFieldDescriptorProtoLabel = number;
138
-
139
- type IFieldDescriptorProtoType = number;
140
-
141
- export interface IFieldOptions {
142
- packed?: boolean;
143
- jstype?: IFieldOptionsJSType;
144
- }
145
-
146
- type IFieldOptionsJSType = number;
147
-
148
- export interface IEnumDescriptorProto {
149
- name?: string;
150
- value?: IEnumValueDescriptorProto[];
151
- options?: IEnumOptions;
152
- }
153
-
154
- export interface IEnumValueDescriptorProto {
155
- name?: string;
156
- number?: number;
157
- options?: any;
158
- }
159
-
160
- export interface IEnumOptions {
161
- allowAlias?: boolean;
162
- deprecated?: boolean;
163
- }
164
-
165
- export interface IOneofDescriptorProto {
166
- name?: string;
167
- options?: any;
168
- }
169
-
170
- export interface IServiceDescriptorProto {
171
- name?: string;
172
- method?: IMethodDescriptorProto[];
173
- options?: IServiceOptions;
174
- }
175
-
176
- export interface IServiceOptions {
177
- deprecated?: boolean;
178
- }
179
-
180
- export interface IMethodDescriptorProto {
181
- name?: string;
182
- inputType?: string;
183
- outputType?: string;
184
- options?: IMethodOptions;
185
- clientStreaming?: boolean;
186
- serverStreaming?: boolean;
187
- }
188
-
189
- export interface IMethodOptions {
190
- deprecated?: boolean;
191
- }
1
+ export * from "../descriptor";