@bufbuild/protobuf 1.7.2 → 1.9.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/dist/cjs/binary-encoding.d.ts +2 -2
- package/dist/cjs/codegen-info.d.ts +6 -1
- package/dist/cjs/codegen-info.js +4 -3
- package/dist/cjs/create-descriptor-set.js +45 -33
- package/dist/cjs/create-registry-from-desc.js +60 -110
- package/dist/cjs/descriptor-set.d.ts +13 -9
- package/dist/cjs/field.d.ts +25 -51
- package/dist/cjs/field.js +0 -66
- package/dist/cjs/google/protobuf/compiler/plugin_pb.d.ts +18 -0
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +2 -0
- package/dist/cjs/google/protobuf/descriptor_pb.d.ts +33 -33
- package/dist/cjs/google/protobuf/descriptor_pb.js +23 -10
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/protobuf/wrappers_pb.js +19 -19
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/is-message.d.ts +22 -0
- package/dist/cjs/is-message.js +52 -0
- package/dist/cjs/json-format.d.ts +1 -2
- package/dist/cjs/message.d.ts +1 -0
- package/dist/cjs/message.js +1 -0
- package/dist/cjs/private/binary-format.d.ts +7 -0
- package/dist/cjs/private/{binary-format-common.js → binary-format.js} +150 -53
- package/dist/cjs/private/extensions.js +1 -1
- package/dist/cjs/private/feature-set.js +1 -1
- package/dist/cjs/private/field-normalize.d.ts +9 -0
- package/dist/cjs/private/field-normalize.js +69 -0
- package/dist/cjs/private/field-wrapper.d.ts +1 -1
- package/dist/cjs/private/field-wrapper.js +12 -12
- package/dist/cjs/private/field.d.ts +1 -0
- package/dist/cjs/private/field.js +1 -0
- package/dist/cjs/private/json-format.d.ts +2 -0
- package/dist/cjs/private/{json-format-common.js → json-format.js} +261 -170
- package/dist/cjs/private/names.js +3 -3
- package/dist/cjs/private/proto-runtime.d.ts +1 -1
- package/dist/cjs/private/proto-runtime.js +8 -4
- package/dist/cjs/private/reflect.d.ts +9 -0
- package/dist/cjs/private/reflect.js +79 -0
- package/dist/cjs/private/reify-wkt.js +11 -11
- package/dist/cjs/private/scalars.d.ts +9 -18
- package/dist/cjs/private/scalars.js +36 -80
- package/dist/cjs/private/text-format.d.ts +1 -1
- package/dist/cjs/private/text-format.js +17 -17
- package/dist/cjs/private/util-common.js +20 -14
- package/dist/cjs/proto-delimited.js +2 -3
- package/dist/cjs/proto2.js +29 -68
- package/dist/cjs/proto3.js +30 -77
- package/dist/cjs/scalar.d.ts +53 -0
- package/dist/cjs/scalar.js +81 -0
- package/dist/cjs/to-plain-message.js +3 -4
- package/dist/esm/binary-encoding.d.ts +2 -2
- package/dist/esm/codegen-info.d.ts +6 -1
- package/dist/esm/codegen-info.js +6 -5
- package/dist/esm/create-descriptor-set.js +22 -10
- package/dist/esm/create-registry-from-desc.js +62 -111
- package/dist/esm/descriptor-set.d.ts +13 -9
- package/dist/esm/descriptor-set.js +1 -1
- package/dist/esm/field.d.ts +25 -51
- package/dist/esm/field.js +1 -65
- package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +18 -0
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -0
- package/dist/esm/google/protobuf/descriptor_pb.d.ts +33 -33
- package/dist/esm/google/protobuf/descriptor_pb.js +23 -10
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/is-message.d.ts +22 -0
- package/dist/esm/is-message.js +48 -0
- package/dist/esm/json-format.d.ts +1 -2
- package/dist/esm/json-format.js +1 -1
- package/dist/esm/message.d.ts +1 -0
- package/dist/esm/message.js +1 -0
- package/dist/esm/private/binary-format.d.ts +7 -0
- package/dist/esm/private/{binary-format-common.js → binary-format.js} +126 -25
- package/dist/esm/private/extensions.js +2 -2
- package/dist/esm/private/feature-set.js +1 -1
- package/dist/esm/private/field-normalize.d.ts +9 -0
- package/dist/esm/private/field-normalize.js +65 -0
- package/dist/esm/private/field-wrapper.d.ts +1 -1
- package/dist/esm/private/field-wrapper.js +3 -2
- package/dist/esm/private/field.d.ts +1 -0
- package/dist/esm/private/field.js +1 -0
- package/dist/esm/private/json-format.d.ts +2 -0
- package/dist/esm/private/{json-format-common.js → json-format.js} +228 -136
- package/dist/esm/private/names.js +3 -3
- package/dist/esm/private/proto-runtime.d.ts +1 -1
- package/dist/esm/private/proto-runtime.js +8 -4
- package/dist/esm/private/reflect.d.ts +9 -0
- package/dist/esm/private/reflect.js +74 -0
- package/dist/esm/private/reify-wkt.js +1 -1
- package/dist/esm/private/scalars.d.ts +9 -18
- package/dist/esm/private/scalars.js +15 -59
- package/dist/esm/private/text-format.d.ts +1 -1
- package/dist/esm/private/text-format.js +1 -1
- package/dist/esm/private/util-common.js +13 -6
- package/dist/esm/proto-delimited.js +2 -3
- package/dist/esm/proto2.js +29 -68
- package/dist/esm/proto3.js +31 -78
- package/dist/esm/scalar.d.ts +53 -0
- package/dist/esm/scalar.js +78 -0
- package/dist/esm/to-plain-message.js +3 -2
- package/package.json +4 -10
- package/dist/cjs/private/binary-format-common.d.ts +0 -13
- package/dist/cjs/private/binary-format-proto2.d.ts +0 -2
- package/dist/cjs/private/binary-format-proto2.js +0 -91
- package/dist/cjs/private/binary-format-proto3.d.ts +0 -2
- package/dist/cjs/private/binary-format-proto3.js +0 -83
- package/dist/cjs/private/json-format-common.d.ts +0 -9
- package/dist/cjs/private/json-format-proto2.d.ts +0 -2
- package/dist/cjs/private/json-format-proto2.js +0 -103
- package/dist/cjs/private/json-format-proto3.d.ts +0 -2
- package/dist/cjs/private/json-format-proto3.js +0 -94
- package/dist/esm/private/binary-format-common.d.ts +0 -13
- package/dist/esm/private/binary-format-proto2.d.ts +0 -2
- package/dist/esm/private/binary-format-proto2.js +0 -87
- package/dist/esm/private/binary-format-proto3.d.ts +0 -2
- package/dist/esm/private/binary-format-proto3.js +0 -79
- package/dist/esm/private/json-format-common.d.ts +0 -9
- package/dist/esm/private/json-format-proto2.d.ts +0 -2
- package/dist/esm/private/json-format-proto2.js +0 -99
- package/dist/esm/private/json-format-proto3.d.ts +0 -2
- package/dist/esm/private/json-format-proto3.js +0 -90
- package/dist/proxy/index.d.ts +0 -1
- package/dist/proxy/index.js +0 -1
package/dist/cjs/proto2.js
CHANGED
|
@@ -15,78 +15,39 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.proto2 = void 0;
|
|
17
17
|
const proto_runtime_js_1 = require("./private/proto-runtime.js");
|
|
18
|
-
const binary_format_proto2_js_1 = require("./private/binary-format-proto2.js");
|
|
19
|
-
const util_common_js_1 = require("./private/util-common.js");
|
|
20
18
|
const field_list_js_1 = require("./private/field-list.js");
|
|
21
|
-
const
|
|
22
|
-
const names_js_1 = require("./private/names.js");
|
|
23
|
-
const json_format_proto2_js_1 = require("./private/json-format-proto2.js");
|
|
24
|
-
const field_js_2 = require("./field.js");
|
|
19
|
+
const field_normalize_js_1 = require("./private/field-normalize.js");
|
|
25
20
|
/**
|
|
26
21
|
* Provides functionality for messages defined with the proto2 syntax.
|
|
27
22
|
*/
|
|
28
|
-
exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
switch (member.kind) {
|
|
39
|
-
case "oneof":
|
|
40
|
-
t[name] = { case: undefined };
|
|
41
|
-
break;
|
|
42
|
-
case "map":
|
|
43
|
-
t[name] = {};
|
|
44
|
-
break;
|
|
45
|
-
case "scalar":
|
|
46
|
-
case "enum":
|
|
47
|
-
case "message":
|
|
48
|
-
// In contrast to proto3, enum and scalar fields have no intrinsic default value,
|
|
49
|
-
// only an optional explicit default value.
|
|
50
|
-
// Unlike proto3 intrinsic default values, proto2 explicit default values are not
|
|
51
|
-
// set on construction, because they are not omitted on the wire. If we did set
|
|
52
|
-
// default values on construction, a deserialize-serialize round-trip would add
|
|
53
|
-
// fields to a message.
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
23
|
+
exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (fields) => {
|
|
24
|
+
return new field_list_js_1.InternalFieldList(fields, (source) => (0, field_normalize_js_1.normalizeFieldInfos)(source, false));
|
|
25
|
+
},
|
|
26
|
+
// TODO merge with proto3 and initExtensionField, also see initPartial, equals, clone
|
|
27
|
+
(target) => {
|
|
28
|
+
for (const member of target.getType().fields.byMember()) {
|
|
29
|
+
const name = member.localName, t = target;
|
|
30
|
+
if (member.repeated) {
|
|
31
|
+
t[name] = [];
|
|
32
|
+
continue;
|
|
56
33
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
34
|
+
switch (member.kind) {
|
|
35
|
+
case "oneof":
|
|
36
|
+
t[name] = { case: undefined };
|
|
37
|
+
break;
|
|
38
|
+
case "map":
|
|
39
|
+
t[name] = {};
|
|
40
|
+
break;
|
|
41
|
+
case "scalar":
|
|
42
|
+
case "enum":
|
|
43
|
+
case "message":
|
|
44
|
+
// In contrast to proto3, enum and scalar fields have no intrinsic default value,
|
|
45
|
+
// only an optional explicit default value.
|
|
46
|
+
// Unlike proto3 intrinsic default values, proto2 explicit default values are not
|
|
47
|
+
// set on construction, because they are not omitted on the wire. If we did set
|
|
48
|
+
// default values on construction, a deserialize-serialize round-trip would add
|
|
49
|
+
// fields to a message.
|
|
50
|
+
break;
|
|
72
51
|
}
|
|
73
|
-
// We do not surface options at this time
|
|
74
|
-
// f.options = field.options ?? emptyReadonlyObject;
|
|
75
|
-
if (field.oneof !== undefined) {
|
|
76
|
-
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
|
|
77
|
-
if (!o || o.name != ooname) {
|
|
78
|
-
o = new field_js_1.InternalOneofInfo(ooname);
|
|
79
|
-
}
|
|
80
|
-
f.oneof = o;
|
|
81
|
-
o.addField(f);
|
|
82
|
-
}
|
|
83
|
-
// proto2 specific:
|
|
84
|
-
if (field.kind == "message") {
|
|
85
|
-
f.delimited = (_d = field.delimited) !== null && _d !== void 0 ? _d : false;
|
|
86
|
-
}
|
|
87
|
-
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
88
|
-
f.packed = (_e = field.packed) !== null && _e !== void 0 ? _e : false;
|
|
89
|
-
r.push(f);
|
|
90
52
|
}
|
|
91
|
-
|
|
92
|
-
}
|
|
53
|
+
});
|
package/dist/cjs/proto3.js
CHANGED
|
@@ -15,89 +15,42 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.proto3 = void 0;
|
|
17
17
|
const proto_runtime_js_1 = require("./private/proto-runtime.js");
|
|
18
|
-
const binary_format_proto3_js_1 = require("./private/binary-format-proto3.js");
|
|
19
|
-
const json_format_proto3_js_1 = require("./private/json-format-proto3.js");
|
|
20
|
-
const util_common_js_1 = require("./private/util-common.js");
|
|
21
18
|
const field_list_js_1 = require("./private/field-list.js");
|
|
22
19
|
const scalars_js_1 = require("./private/scalars.js");
|
|
23
|
-
const
|
|
24
|
-
const field_js_2 = require("./private/field.js");
|
|
25
|
-
const names_js_1 = require("./private/names.js");
|
|
20
|
+
const field_normalize_js_1 = require("./private/field-normalize.js");
|
|
26
21
|
/**
|
|
27
22
|
* Provides functionality for messages defined with the proto3 syntax.
|
|
28
23
|
*/
|
|
29
|
-
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const name = member.localName, t = target;
|
|
38
|
-
if (member.repeated) {
|
|
39
|
-
t[name] = [];
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
switch (member.kind) {
|
|
43
|
-
case "oneof":
|
|
44
|
-
t[name] = { case: undefined };
|
|
45
|
-
break;
|
|
46
|
-
case "enum":
|
|
47
|
-
t[name] = 0;
|
|
48
|
-
break;
|
|
49
|
-
case "map":
|
|
50
|
-
t[name] = {};
|
|
51
|
-
break;
|
|
52
|
-
case "scalar":
|
|
53
|
-
t[name] = (0, scalars_js_1.scalarDefaultValue)(member.T, member.L); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
54
|
-
break;
|
|
55
|
-
case "message":
|
|
56
|
-
// message fields are always optional in proto3
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
24
|
+
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (fields) => {
|
|
25
|
+
return new field_list_js_1.InternalFieldList(fields, (source) => (0, field_normalize_js_1.normalizeFieldInfos)(source, true));
|
|
26
|
+
},
|
|
27
|
+
// TODO merge with proto2 and initExtensionField, also see initPartial, equals, clone
|
|
28
|
+
(target) => {
|
|
29
|
+
for (const member of target.getType().fields.byMember()) {
|
|
30
|
+
if (member.opt) {
|
|
31
|
+
continue;
|
|
59
32
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const r = [];
|
|
65
|
-
let o;
|
|
66
|
-
for (const field of typeof fieldInfos == "function"
|
|
67
|
-
? fieldInfos()
|
|
68
|
-
: fieldInfos) {
|
|
69
|
-
const f = field;
|
|
70
|
-
f.localName = (0, names_js_1.localFieldName)(field.name, field.oneof !== undefined);
|
|
71
|
-
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : (0, names_js_1.fieldJsonName)(field.name);
|
|
72
|
-
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
73
|
-
if (field.kind == "scalar") {
|
|
74
|
-
f.L = (_c = field.L) !== null && _c !== void 0 ? _c : field_js_1.LongType.BIGINT;
|
|
33
|
+
const name = member.localName, t = target;
|
|
34
|
+
if (member.repeated) {
|
|
35
|
+
t[name] = [];
|
|
36
|
+
continue;
|
|
75
37
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
38
|
+
switch (member.kind) {
|
|
39
|
+
case "oneof":
|
|
40
|
+
t[name] = { case: undefined };
|
|
41
|
+
break;
|
|
42
|
+
case "enum":
|
|
43
|
+
t[name] = 0;
|
|
44
|
+
break;
|
|
45
|
+
case "map":
|
|
46
|
+
t[name] = {};
|
|
47
|
+
break;
|
|
48
|
+
case "scalar":
|
|
49
|
+
t[name] = (0, scalars_js_1.scalarZeroValue)(member.T, member.L);
|
|
50
|
+
break;
|
|
51
|
+
case "message":
|
|
52
|
+
// message fields are always optional in proto3
|
|
53
|
+
break;
|
|
85
54
|
}
|
|
86
|
-
// proto3 specific:
|
|
87
|
-
if (field.kind == "message") {
|
|
88
|
-
f.delimited = false;
|
|
89
|
-
}
|
|
90
|
-
// From the proto3 language guide:
|
|
91
|
-
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
92
|
-
// This information is incomplete - according to the conformance tests, BOOL
|
|
93
|
-
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
94
|
-
// are not packed by default, which makes sense because they are length-delimited.
|
|
95
|
-
f.packed =
|
|
96
|
-
(_d = field.packed) !== null && _d !== void 0 ? _d : (field.kind == "enum" ||
|
|
97
|
-
(field.kind == "scalar" &&
|
|
98
|
-
field.T != field_js_1.ScalarType.BYTES &&
|
|
99
|
-
field.T != field_js_1.ScalarType.STRING));
|
|
100
|
-
r.push(f);
|
|
101
55
|
}
|
|
102
|
-
|
|
103
|
-
}
|
|
56
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scalar value types. This is a subset of field types declared by protobuf
|
|
3
|
+
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
4
|
+
* are omitted, but the numerical values are identical.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ScalarType {
|
|
7
|
+
DOUBLE = 1,
|
|
8
|
+
FLOAT = 2,
|
|
9
|
+
INT64 = 3,
|
|
10
|
+
UINT64 = 4,
|
|
11
|
+
INT32 = 5,
|
|
12
|
+
FIXED64 = 6,
|
|
13
|
+
FIXED32 = 7,
|
|
14
|
+
BOOL = 8,
|
|
15
|
+
STRING = 9,
|
|
16
|
+
BYTES = 12,
|
|
17
|
+
UINT32 = 13,
|
|
18
|
+
SFIXED32 = 15,
|
|
19
|
+
SFIXED64 = 16,
|
|
20
|
+
SINT32 = 17,// Uses ZigZag encoding.
|
|
21
|
+
SINT64 = 18
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* JavaScript representation of fields with 64 bit integral types (int64, uint64,
|
|
25
|
+
* sint64, fixed64, sfixed64).
|
|
26
|
+
*
|
|
27
|
+
* This is a subset of google.protobuf.FieldOptions.JSType, which defines JS_NORMAL,
|
|
28
|
+
* JS_STRING, and JS_NUMBER. Protobuf-ES uses BigInt by default, but will use
|
|
29
|
+
* String if `[jstype = JS_STRING]` is specified.
|
|
30
|
+
*
|
|
31
|
+
* ```protobuf
|
|
32
|
+
* uint64 field_a = 1; // BigInt
|
|
33
|
+
* uint64 field_b = 2 [jstype = JS_NORMAL]; // BigInt
|
|
34
|
+
* uint64 field_b = 2 [jstype = JS_NUMBER]; // BigInt
|
|
35
|
+
* uint64 field_b = 2 [jstype = JS_STRING]; // String
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare enum LongType {
|
|
39
|
+
/**
|
|
40
|
+
* Use JavaScript BigInt.
|
|
41
|
+
*/
|
|
42
|
+
BIGINT = 0,
|
|
43
|
+
/**
|
|
44
|
+
* Use JavaScript String.
|
|
45
|
+
*
|
|
46
|
+
* Field option `[jstype = JS_STRING]`.
|
|
47
|
+
*/
|
|
48
|
+
STRING = 1
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* ScalarValue maps from a scalar field type to a TypeScript value type.
|
|
52
|
+
*/
|
|
53
|
+
export type ScalarValue<T = ScalarType, L extends LongType = LongType.STRING | LongType.BIGINT> = T extends ScalarType.STRING ? string : T extends ScalarType.INT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.SINT32 ? number : T extends ScalarType.FIXED32 ? number : T extends ScalarType.SFIXED32 ? number : T extends ScalarType.FLOAT ? number : T extends ScalarType.DOUBLE ? number : T extends ScalarType.INT64 ? (L extends LongType.STRING ? string : bigint) : T extends ScalarType.SINT64 ? (L extends LongType.STRING ? string : bigint) : T extends ScalarType.SFIXED64 ? (L extends LongType.STRING ? string : bigint) : T extends ScalarType.UINT64 ? (L extends LongType.STRING ? string : bigint) : T extends ScalarType.FIXED64 ? (L extends LongType.STRING ? string : bigint) : T extends ScalarType.BOOL ? boolean : T extends ScalarType.BYTES ? Uint8Array : never;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2024 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.LongType = exports.ScalarType = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* Scalar value types. This is a subset of field types declared by protobuf
|
|
19
|
+
* enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
|
|
20
|
+
* are omitted, but the numerical values are identical.
|
|
21
|
+
*/
|
|
22
|
+
var ScalarType;
|
|
23
|
+
(function (ScalarType) {
|
|
24
|
+
// 0 is reserved for errors.
|
|
25
|
+
// Order is weird for historical reasons.
|
|
26
|
+
ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
|
|
27
|
+
ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
|
|
28
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
|
29
|
+
// negative values are likely.
|
|
30
|
+
ScalarType[ScalarType["INT64"] = 3] = "INT64";
|
|
31
|
+
ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
|
|
32
|
+
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
|
33
|
+
// negative values are likely.
|
|
34
|
+
ScalarType[ScalarType["INT32"] = 5] = "INT32";
|
|
35
|
+
ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
|
|
36
|
+
ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
|
|
37
|
+
ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
|
|
38
|
+
ScalarType[ScalarType["STRING"] = 9] = "STRING";
|
|
39
|
+
// Tag-delimited aggregate.
|
|
40
|
+
// Group type is deprecated and not supported in proto3. However, Proto3
|
|
41
|
+
// implementations should still be able to parse the group wire format and
|
|
42
|
+
// treat group fields as unknown fields.
|
|
43
|
+
// TYPE_GROUP = 10,
|
|
44
|
+
// TYPE_MESSAGE = 11, // Length-delimited aggregate.
|
|
45
|
+
// New in version 2.
|
|
46
|
+
ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
|
|
47
|
+
ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
|
|
48
|
+
// TYPE_ENUM = 14,
|
|
49
|
+
ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
|
|
50
|
+
ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
|
|
51
|
+
ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
|
|
52
|
+
ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
|
|
53
|
+
})(ScalarType || (exports.ScalarType = ScalarType = {}));
|
|
54
|
+
/**
|
|
55
|
+
* JavaScript representation of fields with 64 bit integral types (int64, uint64,
|
|
56
|
+
* sint64, fixed64, sfixed64).
|
|
57
|
+
*
|
|
58
|
+
* This is a subset of google.protobuf.FieldOptions.JSType, which defines JS_NORMAL,
|
|
59
|
+
* JS_STRING, and JS_NUMBER. Protobuf-ES uses BigInt by default, but will use
|
|
60
|
+
* String if `[jstype = JS_STRING]` is specified.
|
|
61
|
+
*
|
|
62
|
+
* ```protobuf
|
|
63
|
+
* uint64 field_a = 1; // BigInt
|
|
64
|
+
* uint64 field_b = 2 [jstype = JS_NORMAL]; // BigInt
|
|
65
|
+
* uint64 field_b = 2 [jstype = JS_NUMBER]; // BigInt
|
|
66
|
+
* uint64 field_b = 2 [jstype = JS_STRING]; // String
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
var LongType;
|
|
70
|
+
(function (LongType) {
|
|
71
|
+
/**
|
|
72
|
+
* Use JavaScript BigInt.
|
|
73
|
+
*/
|
|
74
|
+
LongType[LongType["BIGINT"] = 0] = "BIGINT";
|
|
75
|
+
/**
|
|
76
|
+
* Use JavaScript String.
|
|
77
|
+
*
|
|
78
|
+
* Field option `[jstype = JS_STRING]`.
|
|
79
|
+
*/
|
|
80
|
+
LongType[LongType["STRING"] = 1] = "STRING";
|
|
81
|
+
})(LongType || (exports.LongType = LongType = {}));
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.toPlainMessage = void 0;
|
|
17
|
-
|
|
18
|
-
const message_js_1 = require("./message.js");
|
|
17
|
+
const is_message_js_1 = require("./is-message.js");
|
|
19
18
|
/**
|
|
20
19
|
* toPlainMessage returns a new object by stripping
|
|
21
20
|
* all methods from a message, leaving only fields and
|
|
@@ -26,7 +25,7 @@ const message_js_1 = require("./message.js");
|
|
|
26
25
|
* returned as-is.
|
|
27
26
|
*/
|
|
28
27
|
function toPlainMessage(message) {
|
|
29
|
-
if (!(
|
|
28
|
+
if (!(0, is_message_js_1.isMessage)(message)) {
|
|
30
29
|
return message;
|
|
31
30
|
}
|
|
32
31
|
const type = message.getType();
|
|
@@ -61,7 +60,7 @@ function toPlainValue(value) {
|
|
|
61
60
|
if (value === undefined) {
|
|
62
61
|
return value;
|
|
63
62
|
}
|
|
64
|
-
if (
|
|
63
|
+
if ((0, is_message_js_1.isMessage)(value)) {
|
|
65
64
|
return toPlainMessage(value);
|
|
66
65
|
}
|
|
67
66
|
if (value instanceof Uint8Array) {
|
|
@@ -63,11 +63,11 @@ export interface IBinaryReader {
|
|
|
63
63
|
*/
|
|
64
64
|
skip(wireType: WireType): Uint8Array;
|
|
65
65
|
/**
|
|
66
|
-
* Read a `
|
|
66
|
+
* Read a `uint32` field, an unsigned 32 bit varint.
|
|
67
67
|
*/
|
|
68
68
|
uint32(): number;
|
|
69
69
|
/**
|
|
70
|
-
* Read a `
|
|
70
|
+
* Read a `int32` field, a signed 32 bit varint.
|
|
71
71
|
*/
|
|
72
72
|
int32(): number;
|
|
73
73
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { reifyWkt } from "./private/reify-wkt.js";
|
|
2
2
|
import type { DescEnum, DescEnumValue, DescField, DescExtension, DescMessage, DescMethod, DescOneof, DescService } from "./descriptor-set.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ScalarValue } from "./scalar.js";
|
|
4
|
+
import { LongType, ScalarType } from "./scalar.js";
|
|
4
5
|
interface CodegenInfo {
|
|
5
6
|
/**
|
|
6
7
|
* Name of the runtime library NPM package.
|
|
@@ -10,7 +11,11 @@ interface CodegenInfo {
|
|
|
10
11
|
readonly symbols: Record<RuntimeSymbolName, RuntimeSymbolInfo>;
|
|
11
12
|
readonly getUnwrappedFieldType: (field: DescField | DescExtension) => ScalarType | undefined;
|
|
12
13
|
readonly wktSourceFiles: readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated please use scalarZeroValue instead
|
|
16
|
+
*/
|
|
13
17
|
readonly scalarDefaultValue: (type: ScalarType, longType: LongType) => any;
|
|
18
|
+
readonly scalarZeroValue: <T extends ScalarType, L extends LongType>(type: T, longType: L) => ScalarValue<T, L>;
|
|
14
19
|
/**
|
|
15
20
|
* @deprecated please use reifyWkt from @bufbuild/protoplugin/ecmascript instead
|
|
16
21
|
*/
|
package/dist/esm/codegen-info.js
CHANGED
|
@@ -13,16 +13,17 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { localName, safeIdentifier, safeObjectProperty, } from "./private/names.js";
|
|
15
15
|
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
16
|
-
import {
|
|
16
|
+
import { scalarZeroValue } from "./private/scalars.js";
|
|
17
17
|
import { reifyWkt } from "./private/reify-wkt.js";
|
|
18
|
-
import { LongType, ScalarType } from "./
|
|
18
|
+
import { LongType, ScalarType } from "./scalar.js";
|
|
19
19
|
const packageName = "@bufbuild/protobuf";
|
|
20
20
|
export const codegenInfo = {
|
|
21
21
|
packageName: "@bufbuild/protobuf",
|
|
22
22
|
localName,
|
|
23
23
|
reifyWkt,
|
|
24
24
|
getUnwrappedFieldType,
|
|
25
|
-
scalarDefaultValue,
|
|
25
|
+
scalarDefaultValue: scalarZeroValue,
|
|
26
|
+
scalarZeroValue,
|
|
26
27
|
safeIdentifier,
|
|
27
28
|
safeObjectProperty,
|
|
28
29
|
// prettier-ignore
|
|
@@ -43,8 +44,8 @@ export const codegenInfo = {
|
|
|
43
44
|
JsonObject: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
44
45
|
protoDouble: { typeOnly: false, privateImportPath: "./proto-double.js", publicImportPath: packageName },
|
|
45
46
|
protoInt64: { typeOnly: false, privateImportPath: "./proto-int64.js", publicImportPath: packageName },
|
|
46
|
-
ScalarType: { typeOnly: false, privateImportPath: "./
|
|
47
|
-
LongType: { typeOnly: false, privateImportPath: "./
|
|
47
|
+
ScalarType: { typeOnly: false, privateImportPath: "./scalar.js", publicImportPath: packageName },
|
|
48
|
+
LongType: { typeOnly: false, privateImportPath: "./scalar.js", publicImportPath: packageName },
|
|
48
49
|
MethodKind: { typeOnly: false, privateImportPath: "./service-type.js", publicImportPath: packageName },
|
|
49
50
|
MethodIdempotency: { typeOnly: false, privateImportPath: "./service-type.js", publicImportPath: packageName },
|
|
50
51
|
IMessageTypeRegistry: { typeOnly: true, privateImportPath: "./type-registry.js", publicImportPath: packageName },
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { Edition, FeatureSet_RepeatedFieldEncoding, FeatureSetDefaults, FieldDescriptorProto_Label, FieldDescriptorProto_Type, FieldOptions_JSType, FileDescriptorProto, FileDescriptorSet, MethodDescriptorProto, MethodOptions_IdempotencyLevel, ServiceDescriptorProto, SourceCodeInfo, } from "./google/protobuf/descriptor_pb.js";
|
|
15
15
|
import { assert } from "./private/assert.js";
|
|
16
|
-
import { LongType, ScalarType } from "./field.js";
|
|
17
16
|
import { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
18
17
|
import { fieldJsonName, findEnumSharedPrefix } from "./private/names.js";
|
|
19
18
|
import { parseTextFormatEnumValue, parseTextFormatScalarValue, } from "./private/text-format.js";
|
|
20
19
|
import { createFeatureResolver } from "./private/feature-set.js";
|
|
20
|
+
import { LongType, ScalarType } from "./scalar.js";
|
|
21
|
+
import { isMessage } from "./is-message.js";
|
|
21
22
|
/**
|
|
22
23
|
* Create a DescriptorSet, a convenient interface for working with a set of
|
|
23
24
|
* google.protobuf.FileDescriptorProto.
|
|
@@ -27,38 +28,39 @@ import { createFeatureResolver } from "./private/feature-set.js";
|
|
|
27
28
|
* files in topological order.
|
|
28
29
|
*/
|
|
29
30
|
export function createDescriptorSet(input, options) {
|
|
31
|
+
var _a;
|
|
30
32
|
const cart = {
|
|
33
|
+
files: [],
|
|
31
34
|
enums: new Map(),
|
|
32
35
|
messages: new Map(),
|
|
33
36
|
services: new Map(),
|
|
34
37
|
extensions: new Map(),
|
|
35
38
|
mapEntries: new Map(),
|
|
36
39
|
};
|
|
37
|
-
const fileDescriptors = input
|
|
40
|
+
const fileDescriptors = isMessage(input, FileDescriptorSet)
|
|
38
41
|
? input.file
|
|
39
42
|
: input instanceof Uint8Array
|
|
40
43
|
? FileDescriptorSet.fromBinary(input).file
|
|
41
44
|
: input;
|
|
42
45
|
const resolverByEdition = new Map();
|
|
43
|
-
const
|
|
44
|
-
var _a;
|
|
46
|
+
for (const proto of fileDescriptors) {
|
|
45
47
|
const edition = (_a = proto.edition) !== null && _a !== void 0 ? _a : parseFileSyntax(proto.syntax, proto.edition).edition;
|
|
46
48
|
let resolveFeatures = resolverByEdition.get(edition);
|
|
47
49
|
if (resolveFeatures === undefined) {
|
|
48
50
|
resolveFeatures = createFeatureResolver(edition, options === null || options === void 0 ? void 0 : options.featureSetDefaults, options === null || options === void 0 ? void 0 : options.serializationOptions);
|
|
49
51
|
resolverByEdition.set(edition, resolveFeatures);
|
|
50
52
|
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return
|
|
53
|
+
addFile(proto, cart, resolveFeatures);
|
|
54
|
+
}
|
|
55
|
+
return cart;
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
56
58
|
* Create a descriptor for a file.
|
|
57
59
|
*/
|
|
58
|
-
function
|
|
60
|
+
function addFile(proto, cart, resolveFeatures) {
|
|
59
61
|
var _a, _b;
|
|
60
62
|
assert(proto.name, `invalid FileDescriptorProto: missing name`);
|
|
61
|
-
const file = Object.assign(Object.assign({ kind: "file", proto, deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false }, parseFileSyntax(proto.syntax, proto.edition)), { name: proto.name.replace(/\.proto/, ""), enums: [], messages: [], extensions: [], services: [], toString() {
|
|
63
|
+
const file = Object.assign(Object.assign({ kind: "file", proto, deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false }, parseFileSyntax(proto.syntax, proto.edition)), { name: proto.name.replace(/\.proto/, ""), dependencies: findFileDependencies(proto, cart), enums: [], messages: [], extensions: [], services: [], toString() {
|
|
62
64
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
63
65
|
return `file ${this.proto.name}`;
|
|
64
66
|
},
|
|
@@ -95,7 +97,7 @@ function newFile(proto, cart, resolveFeatures) {
|
|
|
95
97
|
addExtensions(message, cart, resolveFeatures);
|
|
96
98
|
}
|
|
97
99
|
cart.mapEntries.clear(); // map entries are local to the file, we can safely discard
|
|
98
|
-
|
|
100
|
+
cart.files.push(file);
|
|
99
101
|
}
|
|
100
102
|
/**
|
|
101
103
|
* Create descriptors for extensions, and add them to the message / file,
|
|
@@ -571,6 +573,16 @@ function parseFileSyntax(syntax, edition) {
|
|
|
571
573
|
edition: e,
|
|
572
574
|
};
|
|
573
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* Resolve dependencies of FileDescriptorProto to DescFile.
|
|
578
|
+
*/
|
|
579
|
+
function findFileDependencies(proto, cart) {
|
|
580
|
+
return proto.dependency.map((wantName) => {
|
|
581
|
+
const dep = cart.files.find((f) => f.proto.name === wantName);
|
|
582
|
+
assert(dep);
|
|
583
|
+
return dep;
|
|
584
|
+
});
|
|
585
|
+
}
|
|
574
586
|
/**
|
|
575
587
|
* Create a fully qualified name for a protobuf type or extension field.
|
|
576
588
|
*
|