@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,74 +1,78 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
import { ScalarType } from "../field.js";
|
|
2
|
-
import {
|
|
3
|
-
makeBinaryFormatCommon,
|
|
4
|
-
writeMapEntry,
|
|
5
|
-
writeMessageField,
|
|
6
|
-
writePacked,
|
|
7
|
-
writeScalar,
|
|
8
|
-
} from "./binary-format-common.js";
|
|
15
|
+
import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
|
|
9
16
|
/* 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 */
|
|
10
17
|
export function makeBinaryFormatProto3() {
|
|
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
|
-
|
|
18
|
+
return {
|
|
19
|
+
...makeBinaryFormatCommon(),
|
|
20
|
+
writeMessage(message, writer, options) {
|
|
21
|
+
const type = message.getType();
|
|
22
|
+
for (const field of type.fields.byNumber()) {
|
|
23
|
+
let value, // this will be our field value, whether it is member of a oneof or regular field
|
|
24
|
+
repeated = field.repeated, localName = field.localName;
|
|
25
|
+
if (field.oneof) {
|
|
26
|
+
const oneof = message[field.oneof.localName];
|
|
27
|
+
if (oneof.case !== localName) {
|
|
28
|
+
continue; // field is not selected, skip
|
|
29
|
+
}
|
|
30
|
+
value = oneof.value;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
value = message[localName];
|
|
34
|
+
}
|
|
35
|
+
switch (field.kind) {
|
|
36
|
+
case "scalar":
|
|
37
|
+
case "enum":
|
|
38
|
+
let scalarType = field.kind == "enum" ? ScalarType.INT32 : field.T;
|
|
39
|
+
if (repeated) {
|
|
40
|
+
if (field.packed) {
|
|
41
|
+
writePacked(writer, scalarType, field.no, value);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
for (const item of value) {
|
|
45
|
+
writeScalar(writer, scalarType, field.no, item, true);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (value !== undefined) {
|
|
51
|
+
writeScalar(writer, scalarType, field.no, value, !!field.oneof || field.opt);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case "message":
|
|
56
|
+
if (repeated) {
|
|
57
|
+
for (const item of value) {
|
|
58
|
+
writeMessageField(writer, options, field.T, field.no, item);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
writeMessageField(writer, options, field.T, field.no, value);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case "map":
|
|
66
|
+
for (const [key, val] of Object.entries(value)) {
|
|
67
|
+
writeMapEntry(writer, options, field, key, val);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
38
70
|
}
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
if (value !== undefined) {
|
|
42
|
-
writeScalar(
|
|
43
|
-
writer,
|
|
44
|
-
scalarType,
|
|
45
|
-
field.no,
|
|
46
|
-
value,
|
|
47
|
-
!!field.oneof || field.opt
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
case "message":
|
|
53
|
-
if (repeated) {
|
|
54
|
-
for (const item of value) {
|
|
55
|
-
writeMessageField(writer, options, field.T, field.no, item);
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
writeMessageField(writer, options, field.T, field.no, value);
|
|
59
71
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (const [key, val] of Object.entries(value)) {
|
|
63
|
-
writeMapEntry(writer, options, field, key, val);
|
|
72
|
+
if (options.writeUnknownFields) {
|
|
73
|
+
this.writeUnknownFields(message, writer);
|
|
64
74
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (options.writeUnknownFields) {
|
|
69
|
-
this.writeUnknownFields(message, writer);
|
|
70
|
-
}
|
|
71
|
-
return writer;
|
|
72
|
-
},
|
|
73
|
-
};
|
|
75
|
+
return writer;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
74
78
|
}
|
package/dist/esm/private/enum.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
import { assert } from "./assert.js";
|
|
2
15
|
const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
|
|
3
16
|
/**
|
|
@@ -6,59 +19,78 @@ const enumTypeSymbol = Symbol("@bufbuild/protobuf/enum-type");
|
|
|
6
19
|
* enum, it raises an error.
|
|
7
20
|
*/
|
|
8
21
|
export function getEnumType(enumObject) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any
|
|
23
|
+
const t = enumObject[enumTypeSymbol];
|
|
24
|
+
assert(t, "missing enum type on enum object");
|
|
25
|
+
return t; // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
28
|
* Sets reflection information on a generated enum.
|
|
16
29
|
*/
|
|
17
|
-
export function setEnumType(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// opt?: {
|
|
23
|
-
// options?: { readonly [extensionName: string]: JsonValue };
|
|
24
|
-
// },
|
|
30
|
+
export function setEnumType(enumObject, typeName, values
|
|
31
|
+
// We do not surface options at this time
|
|
32
|
+
// opt?: {
|
|
33
|
+
// options?: { readonly [extensionName: string]: JsonValue };
|
|
34
|
+
// },
|
|
25
35
|
) {
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
37
|
+
enumObject[enumTypeSymbol] = makeEnumType(typeName, values);
|
|
28
38
|
}
|
|
29
39
|
// We do not surface options at this time
|
|
30
40
|
// export type PartialEnumValue = Omit<EnumValueInfo, 'options'> & Partial<Pick<EnumValueInfo, "options">>;
|
|
31
41
|
/**
|
|
32
42
|
* Create a new EnumType with the given values.
|
|
33
43
|
*/
|
|
34
|
-
export function makeEnumType(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// options?: { readonly [extensionName: string]: JsonValue };
|
|
40
|
-
// },
|
|
44
|
+
export function makeEnumType(typeName, values
|
|
45
|
+
// We do not surface options at this time
|
|
46
|
+
// opt?: {
|
|
47
|
+
// options?: { readonly [extensionName: string]: JsonValue };
|
|
48
|
+
// },
|
|
41
49
|
) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const names = Object.create(null);
|
|
51
|
+
const numbers = Object.create(null);
|
|
52
|
+
const normalValues = [];
|
|
53
|
+
for (const value of values) {
|
|
54
|
+
// We do not surface options at this time
|
|
55
|
+
// const value: EnumValueInfo = {...v, options: v.options ?? emptyReadonlyObject};
|
|
56
|
+
normalValues.push(value);
|
|
57
|
+
names[value.name] = value;
|
|
58
|
+
numbers[value.no] = value;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
typeName,
|
|
62
|
+
values: normalValues,
|
|
63
|
+
// We do not surface options at this time
|
|
64
|
+
// options: opt?.options ?? Object.create(null),
|
|
65
|
+
findName(name) {
|
|
66
|
+
return names[name];
|
|
67
|
+
},
|
|
68
|
+
findNumber(no) {
|
|
69
|
+
return numbers[no];
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a new enum object with the given values.
|
|
75
|
+
*/
|
|
76
|
+
export function makeEnum(typeName, values, opt) {
|
|
77
|
+
const enumObject = {};
|
|
78
|
+
for (const value of values) {
|
|
79
|
+
const name = makeEnumValueName(value, opt?.sharedPrefix);
|
|
80
|
+
enumObject[name] = value.no;
|
|
81
|
+
enumObject[value.no] = name;
|
|
82
|
+
}
|
|
83
|
+
setEnumType(enumObject, typeName, values);
|
|
84
|
+
return enumObject;
|
|
85
|
+
}
|
|
86
|
+
// Construct a local name for an enum value.
|
|
87
|
+
// This logic matches the Go function with the same name in private/protoplugin/names.go
|
|
88
|
+
function makeEnumValueName(value, sharedPrefix) {
|
|
89
|
+
if (sharedPrefix === undefined) {
|
|
90
|
+
return value.name;
|
|
91
|
+
}
|
|
92
|
+
if (!value.name.startsWith(sharedPrefix)) {
|
|
93
|
+
return value.name;
|
|
94
|
+
}
|
|
95
|
+
return value.name.substring(sharedPrefix.length);
|
|
64
96
|
}
|
|
@@ -1,58 +1,72 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
export class InternalFieldList {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
findJsonName(jsonName) {
|
|
7
|
-
if (!this.jsonNames) {
|
|
8
|
-
const t = {};
|
|
9
|
-
for (const f of this.list()) {
|
|
10
|
-
t[f.jsonName] = t[f.name] = f;
|
|
11
|
-
}
|
|
12
|
-
this.jsonNames = t;
|
|
15
|
+
constructor(fields, normalizer) {
|
|
16
|
+
this._fields = fields;
|
|
17
|
+
this._normalizer = normalizer;
|
|
13
18
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
findJsonName(jsonName) {
|
|
20
|
+
if (!this.jsonNames) {
|
|
21
|
+
const t = {};
|
|
22
|
+
for (const f of this.list()) {
|
|
23
|
+
t[f.jsonName] = t[f.name] = f;
|
|
24
|
+
}
|
|
25
|
+
this.jsonNames = t;
|
|
26
|
+
}
|
|
27
|
+
return this.jsonNames[jsonName];
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
find(fieldNo) {
|
|
30
|
+
if (!this.numbers) {
|
|
31
|
+
const t = {};
|
|
32
|
+
for (const f of this.list()) {
|
|
33
|
+
t[f.no] = f;
|
|
34
|
+
}
|
|
35
|
+
this.numbers = t;
|
|
36
|
+
}
|
|
37
|
+
return this.numbers[fieldNo];
|
|
29
38
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
list() {
|
|
40
|
+
if (!this.all) {
|
|
41
|
+
this.all = this._normalizer(this._fields);
|
|
42
|
+
}
|
|
43
|
+
return this.all;
|
|
44
|
+
}
|
|
45
|
+
byNumber() {
|
|
46
|
+
if (!this.numbersAsc) {
|
|
47
|
+
this.numbersAsc = this.list()
|
|
48
|
+
.concat()
|
|
49
|
+
.sort((a, b) => a.no - b.no);
|
|
50
|
+
}
|
|
51
|
+
return this.numbersAsc;
|
|
37
52
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
byMember() {
|
|
54
|
+
if (!this.members) {
|
|
55
|
+
this.members = [];
|
|
56
|
+
const a = this.members;
|
|
57
|
+
let o;
|
|
58
|
+
for (const f of this.list()) {
|
|
59
|
+
if (f.oneof) {
|
|
60
|
+
if (f.oneof !== o) {
|
|
61
|
+
o = f.oneof;
|
|
62
|
+
a.push(o);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
a.push(f);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
53
69
|
}
|
|
54
|
-
|
|
70
|
+
return this.members;
|
|
55
71
|
}
|
|
56
|
-
return this.members;
|
|
57
|
-
}
|
|
58
72
|
}
|
|
@@ -1,20 +1,31 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
/**
|
|
2
15
|
* Wrap field values whose message type has a wrapper.
|
|
3
16
|
*/
|
|
4
17
|
export function wrapField(type, value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`cannot unwrap field value, ${type.typeName} does not define a field wrapper`
|
|
13
|
-
);
|
|
18
|
+
if (value instanceof type) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
if (type.fieldWrapper) {
|
|
22
|
+
return type.fieldWrapper.wrapField(value);
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`cannot unwrap field value, ${type.typeName} does not define a field wrapper`);
|
|
14
25
|
}
|
|
15
26
|
/**
|
|
16
27
|
* Unwrap field values whose message type has a wrapper.
|
|
17
28
|
*/
|
|
18
29
|
export function unwrapField(type, value) {
|
|
19
|
-
|
|
30
|
+
return type.fieldWrapper ? type.fieldWrapper.unwrapField(value) : value;
|
|
20
31
|
}
|
|
@@ -1,27 +1,40 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
import { makeOneofName } from "./names.js";
|
|
2
15
|
import { assert } from "./assert.js";
|
|
3
16
|
export class InternalOneofInfo {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
constructor(name) {
|
|
18
|
+
this.kind = "oneof";
|
|
19
|
+
this.repeated = false;
|
|
20
|
+
this.packed = false;
|
|
21
|
+
this.opt = false;
|
|
22
|
+
this.default = undefined;
|
|
23
|
+
this.fields = [];
|
|
24
|
+
this.name = name;
|
|
25
|
+
this.localName = makeOneofName(name);
|
|
26
|
+
}
|
|
27
|
+
addField(field) {
|
|
28
|
+
assert(field.oneof === this, `field ${field.name} not one of ${this.name}`);
|
|
29
|
+
this.fields.push(field);
|
|
30
|
+
}
|
|
31
|
+
findField(localName) {
|
|
32
|
+
if (!this._lookup) {
|
|
33
|
+
this._lookup = Object.create(null);
|
|
34
|
+
for (let i = 0; i < this.fields.length; i++) {
|
|
35
|
+
this._lookup[this.fields[i].localName] = this.fields[i];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return this._lookup[localName];
|
|
24
39
|
}
|
|
25
|
-
return this._lookup[localName];
|
|
26
|
-
}
|
|
27
40
|
}
|