@bufbuild/protobuf 1.4.2 → 1.5.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/dist/cjs/binary-encoding.d.ts +3 -4
- package/dist/cjs/binary-encoding.js +3 -4
- package/dist/cjs/binary-format.d.ts +10 -1
- package/dist/cjs/create-descriptor-set.d.ts +19 -5
- package/dist/cjs/create-descriptor-set.js +157 -223
- package/dist/cjs/create-registry-from-desc.js +1 -0
- package/dist/cjs/descriptor-set.d.ts +47 -5
- package/dist/cjs/field.d.ts +36 -2
- package/dist/cjs/google/protobuf/any_pb.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/private/binary-format-common.d.ts +3 -2
- package/dist/cjs/private/binary-format-common.js +36 -15
- package/dist/cjs/private/binary-format-proto2.js +2 -2
- package/dist/cjs/private/binary-format-proto3.js +2 -2
- package/dist/cjs/private/feature-set.d.ts +21 -0
- package/dist/cjs/private/feature-set.js +107 -0
- package/dist/cjs/private/text-format.d.ts +4 -0
- package/dist/cjs/private/text-format.js +189 -0
- package/dist/cjs/proto-delimited.js +3 -2
- package/dist/cjs/proto2.js +7 -3
- package/dist/cjs/proto3.js +14 -10
- package/dist/esm/binary-encoding.d.ts +3 -4
- package/dist/esm/binary-encoding.js +3 -4
- package/dist/esm/binary-format.d.ts +10 -1
- package/dist/esm/create-descriptor-set.d.ts +19 -5
- package/dist/esm/create-descriptor-set.js +157 -222
- package/dist/esm/create-registry-from-desc.js +2 -1
- package/dist/esm/descriptor-set.d.ts +47 -5
- package/dist/esm/field.d.ts +36 -2
- package/dist/esm/google/protobuf/any_pb.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/private/binary-format-common.d.ts +3 -2
- package/dist/esm/private/binary-format-common.js +36 -15
- package/dist/esm/private/binary-format-proto2.js +2 -2
- package/dist/esm/private/binary-format-proto3.js +2 -2
- package/dist/esm/private/feature-set.d.ts +21 -0
- package/dist/esm/private/feature-set.js +103 -0
- package/dist/esm/private/text-format.d.ts +4 -0
- package/dist/esm/private/text-format.js +184 -0
- package/dist/esm/proto-delimited.js +3 -2
- package/dist/esm/proto2.js +7 -3
- package/dist/esm/proto3.js +14 -10
- package/package.json +11 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { DescriptorProto, EnumDescriptorProto, EnumValueDescriptorProto, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, OneofDescriptorProto, ServiceDescriptorProto } from "./google/protobuf/descriptor_pb.js";
|
|
2
|
-
import type {
|
|
1
|
+
import type { DescriptorProto, Edition, EnumDescriptorProto, EnumValueDescriptorProto, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, OneofDescriptorProto, ServiceDescriptorProto } from "./google/protobuf/descriptor_pb.js";
|
|
2
|
+
import type { LongType, ScalarType } from "./field.js";
|
|
3
3
|
import type { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
4
|
+
import type { MergedFeatureSet } from "./private/feature-set.js";
|
|
4
5
|
/**
|
|
5
6
|
* DescriptorSet provides a convenient interface for working with a set
|
|
6
7
|
* of google.protobuf.FileDescriptorProto.
|
|
@@ -50,7 +51,12 @@ export interface DescFile {
|
|
|
50
51
|
/**
|
|
51
52
|
* The syntax specified in the protobuf source.
|
|
52
53
|
*/
|
|
53
|
-
readonly syntax: "proto3" | "proto2";
|
|
54
|
+
readonly syntax: "proto3" | "proto2" | "editions";
|
|
55
|
+
/**
|
|
56
|
+
* The edition of the protobuf file. Will be EDITION_PROTO2 for syntax="proto2",
|
|
57
|
+
* EDITION_PROTO3 for syntax="proto3";
|
|
58
|
+
*/
|
|
59
|
+
readonly edition: Exclude<Edition, Edition.EDITION_1_TEST_ONLY | Edition.EDITION_2_TEST_ONLY | Edition.EDITION_99997_TEST_ONLY | Edition.EDITION_99998_TEST_ONLY | Edition.EDITION_99999_TEST_ONLY>;
|
|
54
60
|
/**
|
|
55
61
|
* The name of the file, excluding the .proto suffix.
|
|
56
62
|
* For a protobuf file `foo/bar.proto`, this is `foo/bar`.
|
|
@@ -91,6 +97,10 @@ export interface DescFile {
|
|
|
91
97
|
* Get comments on the package element in the protobuf source.
|
|
92
98
|
*/
|
|
93
99
|
getPackageComments(): DescComments;
|
|
100
|
+
/**
|
|
101
|
+
* Get the edition features for this protobuf element.
|
|
102
|
+
*/
|
|
103
|
+
getFeatures(): MergedFeatureSet;
|
|
94
104
|
toString(): string;
|
|
95
105
|
}
|
|
96
106
|
/**
|
|
@@ -135,6 +145,10 @@ export interface DescEnum {
|
|
|
135
145
|
* Get comments on the element in the protobuf source.
|
|
136
146
|
*/
|
|
137
147
|
getComments(): DescComments;
|
|
148
|
+
/**
|
|
149
|
+
* Get the edition features for this protobuf element.
|
|
150
|
+
*/
|
|
151
|
+
getFeatures(): MergedFeatureSet;
|
|
138
152
|
toString(): string;
|
|
139
153
|
}
|
|
140
154
|
/**
|
|
@@ -171,6 +185,10 @@ export interface DescEnumValue {
|
|
|
171
185
|
* Get comments on the element in the protobuf source.
|
|
172
186
|
*/
|
|
173
187
|
getComments(): DescComments;
|
|
188
|
+
/**
|
|
189
|
+
* Get the edition features for this protobuf element.
|
|
190
|
+
*/
|
|
191
|
+
getFeatures(): MergedFeatureSet;
|
|
174
192
|
toString(): string;
|
|
175
193
|
}
|
|
176
194
|
/**
|
|
@@ -234,6 +252,10 @@ export interface DescMessage {
|
|
|
234
252
|
* Get comments on the element in the protobuf source.
|
|
235
253
|
*/
|
|
236
254
|
getComments(): DescComments;
|
|
255
|
+
/**
|
|
256
|
+
* Get the edition features for this protobuf element.
|
|
257
|
+
*/
|
|
258
|
+
getFeatures(): MergedFeatureSet;
|
|
237
259
|
toString(): string;
|
|
238
260
|
}
|
|
239
261
|
/**
|
|
@@ -290,10 +312,14 @@ interface DescFieldCommon {
|
|
|
290
312
|
*/
|
|
291
313
|
readonly packed: boolean;
|
|
292
314
|
/**
|
|
293
|
-
* Is this field packed by default? Only valid for enum fields, and
|
|
294
|
-
* scalar fields except BYTES and STRING.
|
|
315
|
+
* Is this field packed by default? Only valid for repeated enum fields, and
|
|
316
|
+
* for repeated scalar fields except BYTES and STRING.
|
|
317
|
+
*
|
|
295
318
|
* In proto3 syntax, fields are packed by default. In proto2 syntax, fields
|
|
296
319
|
* are unpacked by default.
|
|
320
|
+
*
|
|
321
|
+
* With editions, the default is whatever the edition specifies as a default.
|
|
322
|
+
* In edition 2023, fields are packed by default.
|
|
297
323
|
*/
|
|
298
324
|
readonly packedByDefault: boolean;
|
|
299
325
|
/**
|
|
@@ -318,6 +344,10 @@ interface DescFieldCommon {
|
|
|
318
344
|
* protobuf source.
|
|
319
345
|
*/
|
|
320
346
|
declarationString(): string;
|
|
347
|
+
/**
|
|
348
|
+
* Get the edition features for this protobuf element.
|
|
349
|
+
*/
|
|
350
|
+
getFeatures(): MergedFeatureSet;
|
|
321
351
|
toString(): string;
|
|
322
352
|
}
|
|
323
353
|
interface DescFieldScalar {
|
|
@@ -534,6 +564,10 @@ export interface DescOneof {
|
|
|
534
564
|
* Get comments on the element in the protobuf source.
|
|
535
565
|
*/
|
|
536
566
|
getComments(): DescComments;
|
|
567
|
+
/**
|
|
568
|
+
* Get the edition features for this protobuf element.
|
|
569
|
+
*/
|
|
570
|
+
getFeatures(): MergedFeatureSet;
|
|
537
571
|
toString(): string;
|
|
538
572
|
}
|
|
539
573
|
/**
|
|
@@ -569,6 +603,10 @@ export interface DescService {
|
|
|
569
603
|
* Get comments on the element in the protobuf source.
|
|
570
604
|
*/
|
|
571
605
|
getComments(): DescComments;
|
|
606
|
+
/**
|
|
607
|
+
* Get the edition features for this protobuf element.
|
|
608
|
+
*/
|
|
609
|
+
getFeatures(): MergedFeatureSet;
|
|
572
610
|
toString(): string;
|
|
573
611
|
}
|
|
574
612
|
/**
|
|
@@ -612,6 +650,10 @@ export interface DescMethod {
|
|
|
612
650
|
* Get comments on the element in the protobuf source.
|
|
613
651
|
*/
|
|
614
652
|
getComments(): DescComments;
|
|
653
|
+
/**
|
|
654
|
+
* Get the edition features for this protobuf element.
|
|
655
|
+
*/
|
|
656
|
+
getFeatures(): MergedFeatureSet;
|
|
615
657
|
toString(): string;
|
|
616
658
|
}
|
|
617
659
|
/**
|
package/dist/cjs/field.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { MessageType } from "./message-type.js";
|
|
|
23
23
|
*
|
|
24
24
|
* - "oneof": If the field is member of a oneof group.
|
|
25
25
|
* - "default": Only proto2: An explicit default value.
|
|
26
|
+
* - "delimited": Only proto2: Use the tag-delimited group encoding.
|
|
26
27
|
*/
|
|
27
28
|
export type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>;
|
|
28
29
|
/**
|
|
@@ -46,6 +47,7 @@ export interface OneofInfo {
|
|
|
46
47
|
readonly packed: false;
|
|
47
48
|
readonly opt: false;
|
|
48
49
|
readonly default: undefined;
|
|
50
|
+
readonly delimited?: undefined;
|
|
49
51
|
readonly fields: readonly FieldInfo[];
|
|
50
52
|
/**
|
|
51
53
|
* Return field information by local name.
|
|
@@ -119,6 +121,13 @@ interface fiScalar extends fiShared {
|
|
|
119
121
|
* Only proto2: An explicit default value.
|
|
120
122
|
*/
|
|
121
123
|
readonly default: number | boolean | string | bigint | Uint8Array | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Serialize this message with the delimited format, also known as group
|
|
126
|
+
* encoding, as opposed to the standard length prefix.
|
|
127
|
+
*
|
|
128
|
+
* Only valid for message fields.
|
|
129
|
+
*/
|
|
130
|
+
readonly delimited?: undefined;
|
|
122
131
|
}
|
|
123
132
|
interface fiMessage extends fiShared {
|
|
124
133
|
readonly kind: "message";
|
|
@@ -138,6 +147,13 @@ interface fiMessage extends fiShared {
|
|
|
138
147
|
* An explicit default value (only proto2). Never set for messages.
|
|
139
148
|
*/
|
|
140
149
|
readonly default: undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Serialize this message with the delimited format, also known as group
|
|
152
|
+
* encoding, as opposed to the standard length prefix.
|
|
153
|
+
*
|
|
154
|
+
* Only valid for message fields.
|
|
155
|
+
*/
|
|
156
|
+
readonly delimited?: boolean;
|
|
141
157
|
}
|
|
142
158
|
interface fiEnum extends fiShared {
|
|
143
159
|
readonly kind: "enum";
|
|
@@ -163,6 +179,13 @@ interface fiEnum extends fiShared {
|
|
|
163
179
|
* Only proto2: An explicit default value.
|
|
164
180
|
*/
|
|
165
181
|
readonly default: number | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Serialize this message with the delimited format, also known as group
|
|
184
|
+
* encoding, as opposed to the standard length prefix.
|
|
185
|
+
*
|
|
186
|
+
* Only valid for message fields.
|
|
187
|
+
*/
|
|
188
|
+
readonly delimited?: undefined;
|
|
166
189
|
}
|
|
167
190
|
interface fiMap extends fiShared {
|
|
168
191
|
readonly kind: "map";
|
|
@@ -199,6 +222,13 @@ interface fiMap extends fiShared {
|
|
|
199
222
|
* An explicit default value (only proto2). Never set for maps.
|
|
200
223
|
*/
|
|
201
224
|
readonly default: undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Serialize this message with the delimited format, also known as group
|
|
227
|
+
* encoding, as opposed to the standard length prefix.
|
|
228
|
+
*
|
|
229
|
+
* Only valid for message fields.
|
|
230
|
+
*/
|
|
231
|
+
readonly delimited?: undefined;
|
|
202
232
|
}
|
|
203
233
|
type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({
|
|
204
234
|
readonly repeated: false;
|
|
@@ -221,7 +251,7 @@ type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> &
|
|
|
221
251
|
readonly opt: false;
|
|
222
252
|
readonly oneof: OneofInfo;
|
|
223
253
|
});
|
|
224
|
-
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L"> & ({
|
|
254
|
+
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L" | "delimited"> & ({
|
|
225
255
|
readonly jsonName?: string;
|
|
226
256
|
readonly repeated?: false;
|
|
227
257
|
readonly packed?: false;
|
|
@@ -229,6 +259,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
229
259
|
readonly oneof?: undefined;
|
|
230
260
|
default?: T["default"];
|
|
231
261
|
L?: LongType;
|
|
262
|
+
delimited?: boolean;
|
|
232
263
|
} | {
|
|
233
264
|
readonly jsonName?: string;
|
|
234
265
|
readonly repeated?: false;
|
|
@@ -237,6 +268,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
237
268
|
readonly oneof?: undefined;
|
|
238
269
|
default?: T["default"];
|
|
239
270
|
L?: LongType;
|
|
271
|
+
delimited?: boolean;
|
|
240
272
|
} | {
|
|
241
273
|
readonly jsonName?: string;
|
|
242
274
|
readonly repeated?: boolean;
|
|
@@ -245,6 +277,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
245
277
|
readonly oneof?: undefined;
|
|
246
278
|
default?: T["default"];
|
|
247
279
|
L?: LongType;
|
|
280
|
+
delimited?: boolean;
|
|
248
281
|
} | {
|
|
249
282
|
readonly jsonName?: string;
|
|
250
283
|
readonly repeated?: false;
|
|
@@ -253,6 +286,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
253
286
|
readonly oneof: string;
|
|
254
287
|
default?: T["default"];
|
|
255
288
|
L?: LongType;
|
|
289
|
+
delimited?: boolean;
|
|
256
290
|
});
|
|
257
291
|
/**
|
|
258
292
|
* Scalar value types. This is a subset of field types declared by protobuf
|
|
@@ -273,7 +307,7 @@ export declare enum ScalarType {
|
|
|
273
307
|
UINT32 = 13,
|
|
274
308
|
SFIXED32 = 15,
|
|
275
309
|
SFIXED64 = 16,
|
|
276
|
-
SINT32 = 17
|
|
310
|
+
SINT32 = 17,// Uses ZigZag encoding.
|
|
277
311
|
SINT64 = 18
|
|
278
312
|
}
|
|
279
313
|
/**
|
|
@@ -240,7 +240,7 @@ class Any extends message_js_1.Message {
|
|
|
240
240
|
throw new Error(`invalid type url: ${url}`);
|
|
241
241
|
}
|
|
242
242
|
const slash = url.lastIndexOf("/");
|
|
243
|
-
const name = slash
|
|
243
|
+
const name = slash >= 0 ? url.substring(slash + 1) : url;
|
|
244
244
|
if (!name.length) {
|
|
245
245
|
throw new Error(`invalid type url: ${url}`);
|
|
246
246
|
}
|
|
@@ -21,7 +21,7 @@ exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annota
|
|
|
21
21
|
// The messages in this file describe the definitions found in .proto files.
|
|
22
22
|
// A valid .proto file can be translated directly to a FileDescriptorProto
|
|
23
23
|
// without any other information (e.g. without reading its imports).
|
|
24
|
-
// @generated by protoc-gen-es v1.
|
|
24
|
+
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
25
25
|
// @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
|
|
26
26
|
/* eslint-disable */
|
|
27
27
|
const proto2_js_1 = require("../../proto2.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v1.
|
|
17
|
+
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v1.
|
|
17
|
+
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -2,12 +2,13 @@ import type { IBinaryReader, IBinaryWriter } from "../binary-encoding.js";
|
|
|
2
2
|
import type { BinaryFormat, BinaryWriteOptions } from "../binary-format.js";
|
|
3
3
|
import type { FieldInfo } from "../field.js";
|
|
4
4
|
import { ScalarType } from "../field.js";
|
|
5
|
-
import type { MessageType } from "../message-type.js";
|
|
6
5
|
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">;
|
|
7
6
|
export declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): any;
|
|
8
7
|
export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
9
8
|
kind: "map";
|
|
10
9
|
}, key: any, value: any): void;
|
|
11
|
-
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions,
|
|
10
|
+
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
11
|
+
kind: "message";
|
|
12
|
+
}, value: any): void;
|
|
12
13
|
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
|
|
13
14
|
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
|
|
@@ -65,11 +65,19 @@ function makeBinaryFormatCommon() {
|
|
|
65
65
|
}
|
|
66
66
|
m[unknownFieldsSymbol].push({ no, wireType, data });
|
|
67
67
|
},
|
|
68
|
-
readMessage(message, reader,
|
|
68
|
+
readMessage(message, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
69
69
|
const type = message.getType();
|
|
70
|
-
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
71
|
+
const end = delimitedMessageEncoding
|
|
72
|
+
? reader.len
|
|
73
|
+
: reader.pos + lengthOrEndTagFieldNo;
|
|
74
|
+
let fieldNo, wireType;
|
|
71
75
|
while (reader.pos < end) {
|
|
72
|
-
|
|
76
|
+
[fieldNo, wireType] = reader.tag();
|
|
77
|
+
if (wireType == binary_encoding_js_1.WireType.EndGroup) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
const field = type.fields.find(fieldNo);
|
|
73
81
|
if (!field) {
|
|
74
82
|
const data = reader.skip(wireType);
|
|
75
83
|
if (options.readUnknownFields) {
|
|
@@ -117,14 +125,14 @@ function makeBinaryFormatCommon() {
|
|
|
117
125
|
const messageType = field.T;
|
|
118
126
|
if (repeated) {
|
|
119
127
|
// safe to assume presence of array, oneof cannot contain repeated values
|
|
120
|
-
target[localName].push(readMessageField(reader, new messageType(), options));
|
|
128
|
+
target[localName].push(readMessageField(reader, new messageType(), options, field));
|
|
121
129
|
}
|
|
122
130
|
else {
|
|
123
131
|
if (target[localName] instanceof message_js_1.Message) {
|
|
124
|
-
readMessageField(reader, target[localName], options);
|
|
132
|
+
readMessageField(reader, target[localName], options, field);
|
|
125
133
|
}
|
|
126
134
|
else {
|
|
127
|
-
target[localName] = readMessageField(reader, new messageType(), options);
|
|
135
|
+
target[localName] = readMessageField(reader, new messageType(), options, field);
|
|
128
136
|
if (messageType.fieldWrapper &&
|
|
129
137
|
!field.oneof &&
|
|
130
138
|
!field.repeated) {
|
|
@@ -140,15 +148,21 @@ function makeBinaryFormatCommon() {
|
|
|
140
148
|
break;
|
|
141
149
|
}
|
|
142
150
|
}
|
|
151
|
+
if (delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
152
|
+
(wireType != binary_encoding_js_1.WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo)) {
|
|
153
|
+
throw new Error(`invalid end group tag`);
|
|
154
|
+
}
|
|
143
155
|
},
|
|
144
156
|
};
|
|
145
157
|
}
|
|
146
158
|
exports.makeBinaryFormatCommon = makeBinaryFormatCommon;
|
|
147
159
|
// Read a message, avoiding MessageType.fromBinary() to re-use the
|
|
148
160
|
// BinaryReadOptions and the IBinaryReader.
|
|
149
|
-
function readMessageField(reader, message, options) {
|
|
161
|
+
function readMessageField(reader, message, options, field) {
|
|
150
162
|
const format = message.getType().runtime.bin;
|
|
151
|
-
|
|
163
|
+
const delimited = field === null || field === void 0 ? void 0 : field.delimited;
|
|
164
|
+
format.readMessage(message, reader, delimited ? field === null || field === void 0 ? void 0 : field.no : reader.uint32(), // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
165
|
+
options, delimited);
|
|
152
166
|
return message;
|
|
153
167
|
}
|
|
154
168
|
// Read a map field, expecting key field = 1, value field = 2
|
|
@@ -170,7 +184,7 @@ function readMapEntry(field, reader, options) {
|
|
|
170
184
|
val = reader.int32();
|
|
171
185
|
break;
|
|
172
186
|
case "message":
|
|
173
|
-
val = readMessageField(reader, new field.V.T(), options);
|
|
187
|
+
val = readMessageField(reader, new field.V.T(), options, undefined);
|
|
174
188
|
break;
|
|
175
189
|
}
|
|
176
190
|
break;
|
|
@@ -274,18 +288,25 @@ function writeMapEntry(writer, options, field, key, value) {
|
|
|
274
288
|
writeScalar(writer, field_js_1.ScalarType.INT32, 2, value, true);
|
|
275
289
|
break;
|
|
276
290
|
case "message":
|
|
277
|
-
|
|
291
|
+
writer.tag(2, binary_encoding_js_1.WireType.LengthDelimited).bytes(value.toBinary(options));
|
|
278
292
|
break;
|
|
279
293
|
}
|
|
280
294
|
writer.join();
|
|
281
295
|
}
|
|
282
296
|
exports.writeMapEntry = writeMapEntry;
|
|
283
|
-
function writeMessageField(writer, options,
|
|
297
|
+
function writeMessageField(writer, options, field, value) {
|
|
284
298
|
if (value !== undefined) {
|
|
285
|
-
const message = (0, field_wrapper_js_1.wrapField)(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
299
|
+
const message = (0, field_wrapper_js_1.wrapField)(field.T, value);
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
301
|
+
if (field === null || field === void 0 ? void 0 : field.delimited)
|
|
302
|
+
writer
|
|
303
|
+
.tag(field.no, binary_encoding_js_1.WireType.StartGroup)
|
|
304
|
+
.raw(message.toBinary(options))
|
|
305
|
+
.tag(field.no, binary_encoding_js_1.WireType.EndGroup);
|
|
306
|
+
else
|
|
307
|
+
writer
|
|
308
|
+
.tag(field.no, binary_encoding_js_1.WireType.LengthDelimited)
|
|
309
|
+
.bytes(message.toBinary(options));
|
|
289
310
|
}
|
|
290
311
|
}
|
|
291
312
|
exports.writeMessageField = writeMessageField;
|
|
@@ -65,11 +65,11 @@ function makeBinaryFormatProto2() {
|
|
|
65
65
|
case "message":
|
|
66
66
|
if (repeated) {
|
|
67
67
|
for (const item of value) {
|
|
68
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
68
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
72
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value);
|
|
73
73
|
}
|
|
74
74
|
break;
|
|
75
75
|
case "map":
|
|
@@ -56,11 +56,11 @@ function makeBinaryFormatProto3() {
|
|
|
56
56
|
case "message":
|
|
57
57
|
if (repeated) {
|
|
58
58
|
for (const item of value) {
|
|
59
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
59
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
63
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value);
|
|
64
64
|
}
|
|
65
65
|
break;
|
|
66
66
|
case "map":
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Edition, FeatureSet, FeatureSetDefaults } from "../google/protobuf/descriptor_pb.js";
|
|
2
|
+
/**
|
|
3
|
+
* Static edition feature defaults supported by @bufbuild/protobuf.
|
|
4
|
+
*/
|
|
5
|
+
export declare const featureSetDefaults: FeatureSetDefaults;
|
|
6
|
+
/**
|
|
7
|
+
* A merged google.protobuf.FeaturesSet, with all fields guaranteed to be set.
|
|
8
|
+
*/
|
|
9
|
+
export type MergedFeatureSet = FeatureSet & Required<FeatureSet>;
|
|
10
|
+
/**
|
|
11
|
+
* A function that resolves features for the given edition.
|
|
12
|
+
*
|
|
13
|
+
* If no feature set is provided, the default feature set for the edition is
|
|
14
|
+
* returned. If features are provided, they are merged into the edition default
|
|
15
|
+
* features.
|
|
16
|
+
*/
|
|
17
|
+
export type FeatureResolverFn = (edition: Edition, a?: FeatureSet, b?: FeatureSet) => MergedFeatureSet;
|
|
18
|
+
/**
|
|
19
|
+
* Create an edition feature resolver with the given feature set defaults.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createFeatureResolver(compiledFeatureSetDefaults: FeatureSetDefaults): FeatureResolverFn;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.createFeatureResolver = exports.featureSetDefaults = void 0;
|
|
17
|
+
const descriptor_pb_js_1 = require("../google/protobuf/descriptor_pb.js");
|
|
18
|
+
const proto_base64_js_1 = require("../proto-base64.js");
|
|
19
|
+
/**
|
|
20
|
+
* Static edition feature defaults supported by @bufbuild/protobuf.
|
|
21
|
+
*/
|
|
22
|
+
exports.featureSetDefaults = descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec(
|
|
23
|
+
/*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/));
|
|
24
|
+
/**
|
|
25
|
+
* Create an edition feature resolver with the given feature set defaults.
|
|
26
|
+
*/
|
|
27
|
+
function createFeatureResolver(compiledFeatureSetDefaults) {
|
|
28
|
+
const min = compiledFeatureSetDefaults.minimumEdition;
|
|
29
|
+
const max = compiledFeatureSetDefaults.maximumEdition;
|
|
30
|
+
if (min === undefined ||
|
|
31
|
+
max === undefined ||
|
|
32
|
+
compiledFeatureSetDefaults.defaults.some((d) => d.edition === undefined)) {
|
|
33
|
+
throw new Error("Invalid FeatureSetDefaults");
|
|
34
|
+
}
|
|
35
|
+
const defaultsBinByEdition = new Map();
|
|
36
|
+
return (edition, ...rest) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
let defaultsBin = defaultsBinByEdition.get(edition);
|
|
39
|
+
if (defaultsBin === undefined) {
|
|
40
|
+
if (edition < min) {
|
|
41
|
+
throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is earlier than the minimum supported edition ${descriptor_pb_js_1.Edition[min]}`);
|
|
42
|
+
}
|
|
43
|
+
if (max < edition) {
|
|
44
|
+
throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is later than the maximum supported edition ${descriptor_pb_js_1.Edition[max]}`);
|
|
45
|
+
}
|
|
46
|
+
let highestMatch = undefined;
|
|
47
|
+
for (const c of compiledFeatureSetDefaults.defaults) {
|
|
48
|
+
const e = (_a = c.edition) !== null && _a !== void 0 ? _a : 0;
|
|
49
|
+
if (e > edition) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (highestMatch !== undefined && highestMatch.e > e) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
highestMatch = {
|
|
56
|
+
e,
|
|
57
|
+
f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (highestMatch === undefined) {
|
|
61
|
+
throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
|
|
62
|
+
}
|
|
63
|
+
defaultsBin = highestMatch.f.toBinary();
|
|
64
|
+
defaultsBinByEdition.set(edition, defaultsBin);
|
|
65
|
+
}
|
|
66
|
+
const f = descriptor_pb_js_1.FeatureSet.fromBinary(defaultsBin);
|
|
67
|
+
for (const c of rest) {
|
|
68
|
+
if (c !== undefined) {
|
|
69
|
+
f.fromBinary(c.toBinary());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!validateMergedFeatures(f)) {
|
|
73
|
+
throw new Error(`Invalid FeatureSet for edition ${descriptor_pb_js_1.Edition[edition]}`);
|
|
74
|
+
}
|
|
75
|
+
return f;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.createFeatureResolver = createFeatureResolver;
|
|
79
|
+
// When protoc generates google.protobuf.FeatureSetDefaults, it ensures that
|
|
80
|
+
// fields are not repeated or required, do not use oneof, and have a default
|
|
81
|
+
// value.
|
|
82
|
+
//
|
|
83
|
+
// When features for an element are resolved, features of the element and its
|
|
84
|
+
// parents are merged into the default FeatureSet for the edition. Because unset
|
|
85
|
+
// fields in the FeatureSet of an element do not unset the default FeatureSet
|
|
86
|
+
// values, a resolved FeatureSet is guaranteed to have all fields set. This is
|
|
87
|
+
// also the case for extensions to FeatureSet that a user might provide, and for
|
|
88
|
+
// features from the future.
|
|
89
|
+
//
|
|
90
|
+
// We cannot exhaustively validate correctness of FeatureSetDefaults at runtime
|
|
91
|
+
// without knowing the schema: If no value for a feature is provided, we do not
|
|
92
|
+
// know that it exists at all.
|
|
93
|
+
//
|
|
94
|
+
// As a sanity check, we validate that all fields known to our version of
|
|
95
|
+
// FeatureSet are set.
|
|
96
|
+
function validateMergedFeatures(featureSet) {
|
|
97
|
+
for (const fi of descriptor_pb_js_1.FeatureSet.fields.list()) {
|
|
98
|
+
const v = featureSet[fi.localName];
|
|
99
|
+
if (v === undefined) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (fi.kind == "enum" && v === 0) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DescEnum } from "../descriptor-set.js";
|
|
2
|
+
import { ScalarType } from "../field.js";
|
|
3
|
+
export declare function parseTextFormatEnumValue(descEnum: DescEnum, value: string): number;
|
|
4
|
+
export declare function parseTextFormatScalarValue(type: ScalarType, value: string): number | boolean | string | bigint | Uint8Array;
|