@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2
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.js +414 -409
- package/dist/cjs/binary-format.js +13 -0
- package/dist/cjs/descriptor-registry.js +420 -449
- package/dist/cjs/descriptor-set.js +429 -513
- package/dist/cjs/enum.js +13 -0
- package/dist/cjs/field-list.js +13 -0
- package/dist/cjs/field.js +43 -30
- package/dist/cjs/google/protobuf/any_pb.js +122 -140
- package/dist/cjs/google/protobuf/api_pb.js +177 -224
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
- package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
- package/dist/cjs/google/protobuf/duration_pb.js +72 -88
- package/dist/cjs/google/protobuf/empty_pb.js +17 -17
- package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
- package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
- package/dist/cjs/google/protobuf/struct_pb.js +144 -181
- package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
- package/dist/cjs/google/protobuf/type_pb.js +406 -462
- package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
- package/dist/cjs/google/varint.js +166 -171
- package/dist/cjs/index.js +41 -122
- package/dist/cjs/json-format.js +13 -0
- package/dist/cjs/message-type.js +13 -0
- package/dist/cjs/message.js +89 -85
- package/dist/cjs/private/assert.js +33 -26
- package/dist/cjs/private/base64.js +93 -79
- package/dist/cjs/private/binary-format-common.js +208 -208
- package/dist/cjs/private/binary-format-proto2.js +88 -109
- package/dist/cjs/private/binary-format-proto3.js +70 -90
- package/dist/cjs/private/enum.js +77 -44
- package/dist/cjs/private/field-list.js +64 -50
- package/dist/cjs/private/field-wrapper.js +21 -10
- package/dist/cjs/private/field.js +35 -25
- package/dist/cjs/private/json-format-common.js +427 -440
- package/dist/cjs/private/json-format-proto2.js +91 -89
- package/dist/cjs/private/json-format-proto3.js +82 -93
- package/dist/cjs/private/message-type.js +39 -27
- package/dist/cjs/private/names.js +71 -62
- package/dist/cjs/private/options-map.js +13 -0
- package/dist/cjs/private/proto-runtime.js +25 -16
- package/dist/cjs/private/scalars.js +113 -103
- package/dist/cjs/private/util-common.js +193 -210
- package/dist/cjs/private/util.js +13 -0
- package/dist/cjs/proto-int64.js +123 -111
- package/dist/cjs/proto2.js +63 -63
- package/dist/cjs/proto3.js +74 -74
- package/dist/cjs/service-type.js +27 -17
- package/dist/cjs/type-registry.js +46 -31
- package/dist/esm/binary-encoding.js +414 -414
- package/dist/esm/binary-format.js +13 -0
- package/dist/esm/descriptor-registry.js +422 -458
- package/dist/esm/descriptor-set.js +430 -478
- package/dist/esm/enum.js +13 -0
- package/dist/esm/field-list.js +13 -0
- package/dist/esm/field.js +42 -29
- package/dist/esm/google/protobuf/any_pb.js +122 -140
- package/dist/esm/google/protobuf/api_pb.js +177 -197
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
- package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
- package/dist/esm/google/protobuf/duration_pb.js +72 -88
- package/dist/esm/google/protobuf/empty_pb.js +17 -17
- package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
- package/dist/esm/google/protobuf/source_context_pb.js +25 -25
- package/dist/esm/google/protobuf/struct_pb.js +143 -180
- package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
- package/dist/esm/google/protobuf/type_pb.js +401 -421
- package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
- package/dist/esm/google/varint.js +165 -164
- package/dist/esm/index.js +14 -1
- package/dist/esm/json-format.js +13 -0
- package/dist/esm/message-type.js +13 -0
- package/dist/esm/message.js +89 -85
- package/dist/esm/private/assert.js +32 -21
- package/dist/esm/private/base64.js +92 -78
- package/dist/esm/private/binary-format-common.js +209 -207
- package/dist/esm/private/binary-format-proto2.js +89 -81
- package/dist/esm/private/binary-format-proto3.js +71 -67
- package/dist/esm/private/enum.js +75 -43
- package/dist/esm/private/field-list.js +64 -50
- package/dist/esm/private/field-wrapper.js +21 -10
- package/dist/esm/private/field.js +35 -22
- package/dist/esm/private/json-format-common.js +427 -435
- package/dist/esm/private/json-format-proto2.js +89 -81
- package/dist/esm/private/json-format-proto3.js +79 -80
- package/dist/esm/private/message-type.js +40 -28
- package/dist/esm/private/names.js +70 -57
- package/dist/esm/private/options-map.js +13 -0
- package/dist/esm/private/proto-runtime.js +26 -12
- package/dist/esm/private/scalars.js +112 -99
- package/dist/esm/private/util-common.js +193 -192
- package/dist/esm/private/util.js +13 -0
- package/dist/esm/proto-int64.js +123 -111
- package/dist/esm/proto2.js +63 -57
- package/dist/esm/proto3.js +74 -68
- package/dist/esm/service-type.js +25 -12
- package/dist/esm/type-registry.js +46 -31
- package/dist/types/binary-encoding.d.ts +398 -398
- package/dist/types/binary-format.d.ts +69 -91
- package/dist/types/descriptor-registry.d.ts +23 -29
- package/dist/types/descriptor-set.d.ts +107 -128
- package/dist/types/enum.d.ts +21 -21
- package/dist/types/field-list.d.ts +21 -21
- package/dist/types/field.d.ts +191 -231
- package/dist/types/google/protobuf/any_pb.d.ts +56 -77
- package/dist/types/google/protobuf/api_pb.d.ts +144 -187
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
- package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
- package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
- package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
- package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
- package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
- package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
- package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
- package/dist/types/google/protobuf/type_pb.d.ts +355 -422
- package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
- package/dist/types/google/varint.d.ts +6 -13
- package/dist/types/index.d.ts +4 -27
- package/dist/types/json-format.d.ts +70 -89
- package/dist/types/message-type.d.ts +37 -45
- package/dist/types/message.d.ts +62 -87
- package/dist/types/private/assert.d.ts +1 -4
- package/dist/types/private/binary-format-common.d.ts +6 -32
- package/dist/types/private/enum.d.ts +13 -11
- package/dist/types/private/field-list.d.ts +14 -21
- package/dist/types/private/field-wrapper.d.ts +4 -10
- package/dist/types/private/field.d.ts +12 -12
- package/dist/types/private/json-format-common.d.ts +5 -27
- package/dist/types/private/message-type.d.ts +12 -7
- package/dist/types/private/names.d.ts +1 -4
- package/dist/types/private/options-map.d.ts +1 -1
- package/dist/types/private/proto-runtime.d.ts +34 -42
- package/dist/types/private/scalars.d.ts +5 -12
- package/dist/types/private/util-common.d.ts +1 -4
- package/dist/types/private/util.d.ts +29 -41
- package/dist/types/proto-int64.d.ts +42 -42
- package/dist/types/service-type.d.ts +36 -56
- package/dist/types/type-registry.d.ts +13 -15
- package/package.json +2 -3
|
@@ -1,102 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 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.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.makeBinaryFormatProto3 = void 0;
|
|
4
17
|
const field_js_1 = require("../field.js");
|
|
5
18
|
const binary_format_common_js_1 = require("./binary-format-common.js");
|
|
6
19
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
|
|
7
20
|
function makeBinaryFormatProto3() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
21
|
+
return {
|
|
22
|
+
...(0, binary_format_common_js_1.makeBinaryFormatCommon)(),
|
|
23
|
+
writeMessage(message, writer, options) {
|
|
24
|
+
const type = message.getType();
|
|
25
|
+
for (const field of type.fields.byNumber()) {
|
|
26
|
+
let value, // this will be our field value, whether it is member of a oneof or regular field
|
|
27
|
+
repeated = field.repeated, localName = field.localName;
|
|
28
|
+
if (field.oneof) {
|
|
29
|
+
const oneof = message[field.oneof.localName];
|
|
30
|
+
if (oneof.case !== localName) {
|
|
31
|
+
continue; // field is not selected, skip
|
|
32
|
+
}
|
|
33
|
+
value = oneof.value;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
value = message[localName];
|
|
37
|
+
}
|
|
38
|
+
switch (field.kind) {
|
|
39
|
+
case "scalar":
|
|
40
|
+
case "enum":
|
|
41
|
+
let scalarType = field.kind == "enum" ? field_js_1.ScalarType.INT32 : field.T;
|
|
42
|
+
if (repeated) {
|
|
43
|
+
if (field.packed) {
|
|
44
|
+
(0, binary_format_common_js_1.writePacked)(writer, scalarType, field.no, value);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
for (const item of value) {
|
|
48
|
+
(0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, item, true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (value !== undefined) {
|
|
54
|
+
(0, binary_format_common_js_1.writeScalar)(writer, scalarType, field.no, value, !!field.oneof || field.opt);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case "message":
|
|
59
|
+
if (repeated) {
|
|
60
|
+
for (const item of value) {
|
|
61
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, item);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, value);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case "map":
|
|
69
|
+
for (const [key, val] of Object.entries(value)) {
|
|
70
|
+
(0, binary_format_common_js_1.writeMapEntry)(writer, options, field, key, val);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
47
73
|
}
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
if (value !== undefined) {
|
|
51
|
-
(0, binary_format_common_js_1.writeScalar)(
|
|
52
|
-
writer,
|
|
53
|
-
scalarType,
|
|
54
|
-
field.no,
|
|
55
|
-
value,
|
|
56
|
-
!!field.oneof || field.opt
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
case "message":
|
|
62
|
-
if (repeated) {
|
|
63
|
-
for (const item of value) {
|
|
64
|
-
(0, binary_format_common_js_1.writeMessageField)(
|
|
65
|
-
writer,
|
|
66
|
-
options,
|
|
67
|
-
field.T,
|
|
68
|
-
field.no,
|
|
69
|
-
item
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
(0, binary_format_common_js_1.writeMessageField)(
|
|
74
|
-
writer,
|
|
75
|
-
options,
|
|
76
|
-
field.T,
|
|
77
|
-
field.no,
|
|
78
|
-
value
|
|
79
|
-
);
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (const [key, val] of Object.entries(value)) {
|
|
84
|
-
(0, binary_format_common_js_1.writeMapEntry)(
|
|
85
|
-
writer,
|
|
86
|
-
options,
|
|
87
|
-
field,
|
|
88
|
-
key,
|
|
89
|
-
val
|
|
90
|
-
);
|
|
75
|
+
if (options.writeUnknownFields) {
|
|
76
|
+
this.writeUnknownFields(message, writer);
|
|
91
77
|
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (options.writeUnknownFields) {
|
|
96
|
-
this.writeUnknownFields(message, writer);
|
|
97
|
-
}
|
|
98
|
-
return writer;
|
|
99
|
-
},
|
|
100
|
-
};
|
|
78
|
+
return writer;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
101
81
|
}
|
|
102
82
|
exports.makeBinaryFormatProto3 = makeBinaryFormatProto3;
|
package/dist/cjs/private/enum.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 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.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeEnumType = exports.setEnumType = exports.getEnumType = void 0;
|
|
16
|
+
exports.makeEnum = exports.makeEnumType = exports.setEnumType = exports.getEnumType = void 0;
|
|
4
17
|
const assert_js_1 = require("./assert.js");
|
|
5
18
|
const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
|
|
6
19
|
/**
|
|
@@ -9,26 +22,23 @@ const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
|
|
|
9
22
|
* enum, it raises an error.
|
|
10
23
|
*/
|
|
11
24
|
function getEnumType(enumObject) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any
|
|
26
|
+
const t = enumObject[enumTypeSymbol];
|
|
27
|
+
(0, assert_js_1.assert)(t, "missing enum type on enum object");
|
|
28
|
+
return t; // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
16
29
|
}
|
|
17
30
|
exports.getEnumType = getEnumType;
|
|
18
31
|
/**
|
|
19
32
|
* Sets reflection information on a generated enum.
|
|
20
33
|
*/
|
|
21
|
-
function setEnumType(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// opt?: {
|
|
27
|
-
// options?: { readonly [extensionName: string]: JsonValue };
|
|
28
|
-
// },
|
|
34
|
+
function setEnumType(enumObject, typeName, values
|
|
35
|
+
// We do not surface options at this time
|
|
36
|
+
// opt?: {
|
|
37
|
+
// options?: { readonly [extensionName: string]: JsonValue };
|
|
38
|
+
// },
|
|
29
39
|
) {
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
41
|
+
enumObject[enumTypeSymbol] = makeEnumType(typeName, values);
|
|
32
42
|
}
|
|
33
43
|
exports.setEnumType = setEnumType;
|
|
34
44
|
// We do not surface options at this time
|
|
@@ -36,35 +46,58 @@ exports.setEnumType = setEnumType;
|
|
|
36
46
|
/**
|
|
37
47
|
* Create a new EnumType with the given values.
|
|
38
48
|
*/
|
|
39
|
-
function makeEnumType(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// options?: { readonly [extensionName: string]: JsonValue };
|
|
45
|
-
// },
|
|
49
|
+
function makeEnumType(typeName, values
|
|
50
|
+
// We do not surface options at this time
|
|
51
|
+
// opt?: {
|
|
52
|
+
// options?: { readonly [extensionName: string]: JsonValue };
|
|
53
|
+
// },
|
|
46
54
|
) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
const names = Object.create(null);
|
|
56
|
+
const numbers = Object.create(null);
|
|
57
|
+
const normalValues = [];
|
|
58
|
+
for (const value of values) {
|
|
59
|
+
// We do not surface options at this time
|
|
60
|
+
// const value: EnumValueInfo = {...v, options: v.options ?? emptyReadonlyObject};
|
|
61
|
+
normalValues.push(value);
|
|
62
|
+
names[value.name] = value;
|
|
63
|
+
numbers[value.no] = value;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
typeName,
|
|
67
|
+
values: normalValues,
|
|
68
|
+
// We do not surface options at this time
|
|
69
|
+
// options: opt?.options ?? Object.create(null),
|
|
70
|
+
findName(name) {
|
|
71
|
+
return names[name];
|
|
72
|
+
},
|
|
73
|
+
findNumber(no) {
|
|
74
|
+
return numbers[no];
|
|
75
|
+
},
|
|
76
|
+
};
|
|
69
77
|
}
|
|
70
78
|
exports.makeEnumType = makeEnumType;
|
|
79
|
+
/**
|
|
80
|
+
* Create a new enum object with the given values.
|
|
81
|
+
*/
|
|
82
|
+
function makeEnum(typeName, values, opt) {
|
|
83
|
+
const enumObject = {};
|
|
84
|
+
for (const value of values) {
|
|
85
|
+
const name = makeEnumValueName(value, opt?.sharedPrefix);
|
|
86
|
+
enumObject[name] = value.no;
|
|
87
|
+
enumObject[value.no] = name;
|
|
88
|
+
}
|
|
89
|
+
setEnumType(enumObject, typeName, values);
|
|
90
|
+
return enumObject;
|
|
91
|
+
}
|
|
92
|
+
exports.makeEnum = makeEnum;
|
|
93
|
+
// Construct a local name for an enum value.
|
|
94
|
+
// This logic matches the Go function with the same name in private/protoplugin/names.go
|
|
95
|
+
function makeEnumValueName(value, sharedPrefix) {
|
|
96
|
+
if (sharedPrefix === undefined) {
|
|
97
|
+
return value.name;
|
|
98
|
+
}
|
|
99
|
+
if (!value.name.startsWith(sharedPrefix)) {
|
|
100
|
+
return value.name;
|
|
101
|
+
}
|
|
102
|
+
return value.name.substring(sharedPrefix.length);
|
|
103
|
+
}
|
|
@@ -1,62 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 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.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.InternalFieldList = void 0;
|
|
4
17
|
class InternalFieldList {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
findJsonName(jsonName) {
|
|
10
|
-
if (!this.jsonNames) {
|
|
11
|
-
const t = {};
|
|
12
|
-
for (const f of this.list()) {
|
|
13
|
-
t[f.jsonName] = t[f.name] = f;
|
|
14
|
-
}
|
|
15
|
-
this.jsonNames = t;
|
|
18
|
+
constructor(fields, normalizer) {
|
|
19
|
+
this._fields = fields;
|
|
20
|
+
this._normalizer = normalizer;
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
findJsonName(jsonName) {
|
|
23
|
+
if (!this.jsonNames) {
|
|
24
|
+
const t = {};
|
|
25
|
+
for (const f of this.list()) {
|
|
26
|
+
t[f.jsonName] = t[f.name] = f;
|
|
27
|
+
}
|
|
28
|
+
this.jsonNames = t;
|
|
29
|
+
}
|
|
30
|
+
return this.jsonNames[jsonName];
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
find(fieldNo) {
|
|
33
|
+
if (!this.numbers) {
|
|
34
|
+
const t = {};
|
|
35
|
+
for (const f of this.list()) {
|
|
36
|
+
t[f.no] = f;
|
|
37
|
+
}
|
|
38
|
+
this.numbers = t;
|
|
39
|
+
}
|
|
40
|
+
return this.numbers[fieldNo];
|
|
32
41
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
list() {
|
|
43
|
+
if (!this.all) {
|
|
44
|
+
this.all = this._normalizer(this._fields);
|
|
45
|
+
}
|
|
46
|
+
return this.all;
|
|
47
|
+
}
|
|
48
|
+
byNumber() {
|
|
49
|
+
if (!this.numbersAsc) {
|
|
50
|
+
this.numbersAsc = this.list()
|
|
51
|
+
.concat()
|
|
52
|
+
.sort((a, b) => a.no - b.no);
|
|
53
|
+
}
|
|
54
|
+
return this.numbersAsc;
|
|
40
55
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
byMember() {
|
|
57
|
+
if (!this.members) {
|
|
58
|
+
this.members = [];
|
|
59
|
+
const a = this.members;
|
|
60
|
+
let o;
|
|
61
|
+
for (const f of this.list()) {
|
|
62
|
+
if (f.oneof) {
|
|
63
|
+
if (f.oneof !== o) {
|
|
64
|
+
o = f.oneof;
|
|
65
|
+
a.push(o);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
a.push(f);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
|
-
|
|
73
|
+
return this.members;
|
|
58
74
|
}
|
|
59
|
-
return this.members;
|
|
60
|
-
}
|
|
61
75
|
}
|
|
62
76
|
exports.InternalFieldList = InternalFieldList;
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 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.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.unwrapField = exports.wrapField = void 0;
|
|
4
17
|
/**
|
|
5
18
|
* Wrap field values whose message type has a wrapper.
|
|
6
19
|
*/
|
|
7
20
|
function wrapField(type, value) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`cannot unwrap field value, ${type.typeName} does not define a field wrapper`
|
|
16
|
-
);
|
|
21
|
+
if (value instanceof type) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (type.fieldWrapper) {
|
|
25
|
+
return type.fieldWrapper.wrapField(value);
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`cannot unwrap field value, ${type.typeName} does not define a field wrapper`);
|
|
17
28
|
}
|
|
18
29
|
exports.wrapField = wrapField;
|
|
19
30
|
/**
|
|
20
31
|
* Unwrap field values whose message type has a wrapper.
|
|
21
32
|
*/
|
|
22
33
|
function unwrapField(type, value) {
|
|
23
|
-
|
|
34
|
+
return type.fieldWrapper ? type.fieldWrapper.unwrapField(value) : value;
|
|
24
35
|
}
|
|
25
36
|
exports.unwrapField = unwrapField;
|
|
@@ -1,34 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 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.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.InternalOneofInfo = void 0;
|
|
4
17
|
const names_js_1 = require("./names.js");
|
|
5
18
|
const assert_js_1 = require("./assert.js");
|
|
6
19
|
class InternalOneofInfo {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this._lookup[
|
|
29
|
-
}
|
|
20
|
+
constructor(name) {
|
|
21
|
+
this.kind = "oneof";
|
|
22
|
+
this.repeated = false;
|
|
23
|
+
this.packed = false;
|
|
24
|
+
this.opt = false;
|
|
25
|
+
this.default = undefined;
|
|
26
|
+
this.fields = [];
|
|
27
|
+
this.name = name;
|
|
28
|
+
this.localName = (0, names_js_1.makeOneofName)(name);
|
|
29
|
+
}
|
|
30
|
+
addField(field) {
|
|
31
|
+
(0, assert_js_1.assert)(field.oneof === this, `field ${field.name} not one of ${this.name}`);
|
|
32
|
+
this.fields.push(field);
|
|
33
|
+
}
|
|
34
|
+
findField(localName) {
|
|
35
|
+
if (!this._lookup) {
|
|
36
|
+
this._lookup = Object.create(null);
|
|
37
|
+
for (let i = 0; i < this.fields.length; i++) {
|
|
38
|
+
this._lookup[this.fields[i].localName] = this.fields[i];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return this._lookup[localName];
|
|
30
42
|
}
|
|
31
|
-
return this._lookup[localName];
|
|
32
|
-
}
|
|
33
43
|
}
|
|
34
44
|
exports.InternalOneofInfo = InternalOneofInfo;
|