@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.
Files changed (138) hide show
  1. package/dist/cjs/binary-encoding.js +414 -409
  2. package/dist/cjs/binary-format.js +13 -0
  3. package/dist/cjs/descriptor-registry.js +420 -449
  4. package/dist/cjs/descriptor-set.js +429 -513
  5. package/dist/cjs/enum.js +13 -0
  6. package/dist/cjs/field-list.js +13 -0
  7. package/dist/cjs/field.js +43 -30
  8. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  9. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  10. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  11. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  12. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  13. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  14. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  15. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  16. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  17. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  18. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  19. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  20. package/dist/cjs/google/varint.js +166 -171
  21. package/dist/cjs/index.js +41 -122
  22. package/dist/cjs/json-format.js +13 -0
  23. package/dist/cjs/message-type.js +13 -0
  24. package/dist/cjs/message.js +89 -85
  25. package/dist/cjs/private/assert.js +33 -26
  26. package/dist/cjs/private/base64.js +93 -79
  27. package/dist/cjs/private/binary-format-common.js +208 -208
  28. package/dist/cjs/private/binary-format-proto2.js +88 -109
  29. package/dist/cjs/private/binary-format-proto3.js +70 -90
  30. package/dist/cjs/private/enum.js +77 -44
  31. package/dist/cjs/private/field-list.js +64 -50
  32. package/dist/cjs/private/field-wrapper.js +21 -10
  33. package/dist/cjs/private/field.js +35 -25
  34. package/dist/cjs/private/json-format-common.js +427 -440
  35. package/dist/cjs/private/json-format-proto2.js +91 -89
  36. package/dist/cjs/private/json-format-proto3.js +82 -93
  37. package/dist/cjs/private/message-type.js +39 -27
  38. package/dist/cjs/private/names.js +71 -62
  39. package/dist/cjs/private/options-map.js +13 -0
  40. package/dist/cjs/private/proto-runtime.js +25 -16
  41. package/dist/cjs/private/scalars.js +113 -103
  42. package/dist/cjs/private/util-common.js +193 -210
  43. package/dist/cjs/private/util.js +13 -0
  44. package/dist/cjs/proto-int64.js +123 -111
  45. package/dist/cjs/proto2.js +63 -63
  46. package/dist/cjs/proto3.js +74 -74
  47. package/dist/cjs/service-type.js +27 -17
  48. package/dist/cjs/type-registry.js +46 -31
  49. package/dist/esm/binary-encoding.js +414 -414
  50. package/dist/esm/binary-format.js +13 -0
  51. package/dist/esm/descriptor-registry.js +422 -458
  52. package/dist/esm/descriptor-set.js +430 -478
  53. package/dist/esm/enum.js +13 -0
  54. package/dist/esm/field-list.js +13 -0
  55. package/dist/esm/field.js +42 -29
  56. package/dist/esm/google/protobuf/any_pb.js +122 -140
  57. package/dist/esm/google/protobuf/api_pb.js +177 -197
  58. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  59. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  60. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  61. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  62. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  63. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  64. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  65. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  66. package/dist/esm/google/protobuf/type_pb.js +401 -421
  67. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  68. package/dist/esm/google/varint.js +165 -164
  69. package/dist/esm/index.js +14 -1
  70. package/dist/esm/json-format.js +13 -0
  71. package/dist/esm/message-type.js +13 -0
  72. package/dist/esm/message.js +89 -85
  73. package/dist/esm/private/assert.js +32 -21
  74. package/dist/esm/private/base64.js +92 -78
  75. package/dist/esm/private/binary-format-common.js +209 -207
  76. package/dist/esm/private/binary-format-proto2.js +89 -81
  77. package/dist/esm/private/binary-format-proto3.js +71 -67
  78. package/dist/esm/private/enum.js +75 -43
  79. package/dist/esm/private/field-list.js +64 -50
  80. package/dist/esm/private/field-wrapper.js +21 -10
  81. package/dist/esm/private/field.js +35 -22
  82. package/dist/esm/private/json-format-common.js +427 -435
  83. package/dist/esm/private/json-format-proto2.js +89 -81
  84. package/dist/esm/private/json-format-proto3.js +79 -80
  85. package/dist/esm/private/message-type.js +40 -28
  86. package/dist/esm/private/names.js +70 -57
  87. package/dist/esm/private/options-map.js +13 -0
  88. package/dist/esm/private/proto-runtime.js +26 -12
  89. package/dist/esm/private/scalars.js +112 -99
  90. package/dist/esm/private/util-common.js +193 -192
  91. package/dist/esm/private/util.js +13 -0
  92. package/dist/esm/proto-int64.js +123 -111
  93. package/dist/esm/proto2.js +63 -57
  94. package/dist/esm/proto3.js +74 -68
  95. package/dist/esm/service-type.js +25 -12
  96. package/dist/esm/type-registry.js +46 -31
  97. package/dist/types/binary-encoding.d.ts +398 -398
  98. package/dist/types/binary-format.d.ts +69 -91
  99. package/dist/types/descriptor-registry.d.ts +23 -29
  100. package/dist/types/descriptor-set.d.ts +107 -128
  101. package/dist/types/enum.d.ts +21 -21
  102. package/dist/types/field-list.d.ts +21 -21
  103. package/dist/types/field.d.ts +191 -231
  104. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  105. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  106. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  107. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  108. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  109. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  110. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  111. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  112. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  113. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  114. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  115. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  116. package/dist/types/google/varint.d.ts +6 -13
  117. package/dist/types/index.d.ts +4 -27
  118. package/dist/types/json-format.d.ts +70 -89
  119. package/dist/types/message-type.d.ts +37 -45
  120. package/dist/types/message.d.ts +62 -87
  121. package/dist/types/private/assert.d.ts +1 -4
  122. package/dist/types/private/binary-format-common.d.ts +6 -32
  123. package/dist/types/private/enum.d.ts +13 -11
  124. package/dist/types/private/field-list.d.ts +14 -21
  125. package/dist/types/private/field-wrapper.d.ts +4 -10
  126. package/dist/types/private/field.d.ts +12 -12
  127. package/dist/types/private/json-format-common.d.ts +5 -27
  128. package/dist/types/private/message-type.d.ts +12 -7
  129. package/dist/types/private/names.d.ts +1 -4
  130. package/dist/types/private/options-map.d.ts +1 -1
  131. package/dist/types/private/proto-runtime.d.ts +34 -42
  132. package/dist/types/private/scalars.d.ts +5 -12
  133. package/dist/types/private/util-common.d.ts +1 -4
  134. package/dist/types/private/util.d.ts +29 -41
  135. package/dist/types/proto-int64.d.ts +42 -42
  136. package/dist/types/service-type.d.ts +36 -56
  137. package/dist/types/type-registry.d.ts +13 -15
  138. 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
- return {
9
- ...(0, binary_format_common_js_1.makeBinaryFormatCommon)(),
10
- writeMessage(message, writer, options) {
11
- const type = message.getType();
12
- for (const field of type.fields.byNumber()) {
13
- let value, // this will be our field value, whether it is member of a oneof or regular field
14
- repeated = field.repeated,
15
- localName = field.localName;
16
- if (field.oneof) {
17
- const oneof = message[field.oneof.localName];
18
- if (oneof.case !== localName) {
19
- continue; // field is not selected, skip
20
- }
21
- value = oneof.value;
22
- } else {
23
- value = message[localName];
24
- }
25
- switch (field.kind) {
26
- case "scalar":
27
- case "enum":
28
- let scalarType =
29
- field.kind == "enum" ? field_js_1.ScalarType.INT32 : field.T;
30
- if (repeated) {
31
- if (field.packed) {
32
- (0, binary_format_common_js_1.writePacked)(
33
- writer,
34
- scalarType,
35
- field.no,
36
- value
37
- );
38
- } else {
39
- for (const item of value) {
40
- (0, binary_format_common_js_1.writeScalar)(
41
- writer,
42
- scalarType,
43
- field.no,
44
- item,
45
- true
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
- break;
82
- case "map":
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
- break;
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;
@@ -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
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any
13
- const t = enumObject[enumTypeSymbol];
14
- (0, assert_js_1.assert)(t, "missing enum type on enum object");
15
- return t; // eslint-disable-line @typescript-eslint/no-unsafe-return
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
- enumObject,
23
- typeName,
24
- values
25
- // We do not surface options at this time
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
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
31
- enumObject[enumTypeSymbol] = makeEnumType(typeName, values);
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
- typeName,
41
- values
42
- // We do not surface options at this time
43
- // opt?: {
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
- const names = Object.create(null);
48
- const numbers = Object.create(null);
49
- const normalValues = [];
50
- for (const value of values) {
51
- // We do not surface options at this time
52
- // const value: EnumValueInfo = {...v, options: v.options ?? emptyReadonlyObject};
53
- normalValues.push(value);
54
- names[value.name] = value;
55
- numbers[value.no] = value;
56
- }
57
- return {
58
- typeName,
59
- values: normalValues,
60
- // We do not surface options at this time
61
- // options: opt?.options ?? Object.create(null),
62
- findName(name) {
63
- return names[name];
64
- },
65
- findNumber(no) {
66
- return numbers[no];
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
- constructor(fields, normalizer) {
6
- this._fields = fields;
7
- this._normalizer = normalizer;
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
- return this.jsonNames[jsonName];
18
- }
19
- find(fieldNo) {
20
- if (!this.numbers) {
21
- const t = {};
22
- for (const f of this.list()) {
23
- t[f.no] = f;
24
- }
25
- this.numbers = t;
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
- return this.numbers[fieldNo];
28
- }
29
- list() {
30
- if (!this.all) {
31
- this.all = this._normalizer(this._fields);
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
- return this.all;
34
- }
35
- byNumber() {
36
- if (!this.numbersAsc) {
37
- this.numbersAsc = this.list()
38
- .concat()
39
- .sort((a, b) => a.no - b.no);
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
- return this.numbersAsc;
42
- }
43
- byMember() {
44
- if (!this.members) {
45
- this.members = [];
46
- const a = this.members;
47
- let o;
48
- for (const f of this.list()) {
49
- if (f.oneof) {
50
- if (f.oneof !== o) {
51
- o = f.oneof;
52
- a.push(o);
53
- }
54
- } else {
55
- a.push(f);
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
- if (value instanceof type) {
9
- return value;
10
- }
11
- if (type.fieldWrapper) {
12
- return type.fieldWrapper.wrapField(value);
13
- }
14
- throw new Error(
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
- return type.fieldWrapper ? type.fieldWrapper.unwrapField(value) : value;
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
- constructor(name) {
8
- this.kind = "oneof";
9
- this.repeated = false;
10
- this.packed = false;
11
- this.opt = false;
12
- this.default = undefined;
13
- this.fields = [];
14
- this.name = name;
15
- this.localName = (0, names_js_1.makeOneofName)(name);
16
- }
17
- addField(field) {
18
- (0, assert_js_1.assert)(
19
- field.oneof === this,
20
- `field ${field.name} not one of ${this.name}`
21
- );
22
- this.fields.push(field);
23
- }
24
- findField(localName) {
25
- if (!this._lookup) {
26
- this._lookup = Object.create(null);
27
- for (let i = 0; i < this.fields.length; i++) {
28
- this._lookup[this.fields[i].localName] = this.fields[i];
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;