@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,4 +1,17 @@
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.makeJsonFormatProto2 = void 0;
4
17
  const field_wrapper_js_1 = require("./field-wrapper.js");
@@ -6,95 +19,84 @@ const assert_js_1 = require("./assert.js");
6
19
  const json_format_common_js_1 = require("./json-format-common.js");
7
20
  /* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
8
21
  function makeJsonFormatProto2() {
9
- return (0, json_format_common_js_1.makeJsonFormatCommon)(
10
- (writeEnum, writeScalar) => {
11
- return function writeField(field, value, options) {
12
- if (field.kind == "map") {
13
- const jsonObj = {};
14
- switch (field.V.kind) {
15
- case "scalar":
16
- for (const [entryKey, entryValue] of Object.entries(value)) {
17
- const val = writeScalar(field.V.T, entryValue, true);
18
- (0, assert_js_1.assert)(val !== undefined);
19
- jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
20
- }
21
- break;
22
- case "message":
23
- for (const [entryKey, entryValue] of Object.entries(value)) {
24
- // JSON standard allows only (double quoted) string as property key
25
- jsonObj[entryKey.toString()] = entryValue.toJson(options);
26
- }
27
- break;
28
- case "enum":
29
- const enumType = field.V.T;
30
- for (const [entryKey, entryValue] of Object.entries(value)) {
31
- (0, assert_js_1.assert)(
32
- entryValue === undefined || typeof entryValue == "number"
33
- );
34
- const val = writeEnum(
35
- enumType,
36
- entryValue,
37
- true,
38
- options.enumAsInteger
39
- );
40
- (0, assert_js_1.assert)(val !== undefined);
41
- jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
42
- }
43
- break;
44
- }
45
- return options.emitDefaultValues || Object.keys(jsonObj).length > 0
46
- ? jsonObj
47
- : undefined;
48
- } else if (field.repeated) {
49
- const jsonArr = [];
50
- switch (field.kind) {
51
- case "scalar":
52
- for (let i = 0; i < value.length; i++) {
53
- jsonArr.push(writeScalar(field.T, value[i], true));
54
- }
55
- break;
56
- case "enum":
57
- for (let i = 0; i < value.length; i++) {
58
- jsonArr.push(
59
- writeEnum(field.T, value[i], true, options.enumAsInteger)
60
- );
61
- }
62
- break;
63
- case "message":
64
- for (let i = 0; i < value.length; i++) {
65
- jsonArr.push(value[i].toJson(options));
66
- }
67
- break;
68
- }
69
- return options.emitDefaultValues || jsonArr.length > 0
70
- ? jsonArr
71
- : undefined;
72
- } else {
73
- // In contrast to proto3, we raise an error if a non-optional (proto2 required)
74
- // field is missing a value.
75
- if (value === undefined) {
76
- if (!field.oneof && !field.opt) {
77
- throw `required field not set`;
22
+ return (0, json_format_common_js_1.makeJsonFormatCommon)((writeEnum, writeScalar) => {
23
+ return function writeField(field, value, options) {
24
+ if (field.kind == "map") {
25
+ const jsonObj = {};
26
+ switch (field.V.kind) {
27
+ case "scalar":
28
+ for (const [entryKey, entryValue] of Object.entries(value)) {
29
+ const val = writeScalar(field.V.T, entryValue, true);
30
+ (0, assert_js_1.assert)(val !== undefined);
31
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
32
+ }
33
+ break;
34
+ case "message":
35
+ for (const [entryKey, entryValue] of Object.entries(value)) {
36
+ // JSON standard allows only (double quoted) string as property key
37
+ jsonObj[entryKey.toString()] = entryValue.toJson(options);
38
+ }
39
+ break;
40
+ case "enum":
41
+ const enumType = field.V.T;
42
+ for (const [entryKey, entryValue] of Object.entries(value)) {
43
+ (0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
44
+ const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
45
+ (0, assert_js_1.assert)(val !== undefined);
46
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
47
+ }
48
+ break;
49
+ }
50
+ return options.emitDefaultValues || Object.keys(jsonObj).length > 0
51
+ ? jsonObj
52
+ : undefined;
78
53
  }
79
- return undefined;
80
- }
81
- switch (field.kind) {
82
- case "scalar":
83
- // In contrast to proto3, we do not skip intrinsic default values.
84
- // Explicit default values are not special cased either.
85
- return writeScalar(field.T, value, true);
86
- case "enum":
87
- // In contrast to proto3, we do not skip intrinsic default values.
88
- // Explicit default values are not special cased either.
89
- return writeEnum(field.T, value, true, options.enumAsInteger);
90
- case "message":
91
- return (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(
92
- options
93
- );
94
- }
95
- }
96
- };
97
- }
98
- );
54
+ else if (field.repeated) {
55
+ const jsonArr = [];
56
+ switch (field.kind) {
57
+ case "scalar":
58
+ for (let i = 0; i < value.length; i++) {
59
+ jsonArr.push(writeScalar(field.T, value[i], true));
60
+ }
61
+ break;
62
+ case "enum":
63
+ for (let i = 0; i < value.length; i++) {
64
+ jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
65
+ }
66
+ break;
67
+ case "message":
68
+ for (let i = 0; i < value.length; i++) {
69
+ jsonArr.push(value[i].toJson(options));
70
+ }
71
+ break;
72
+ }
73
+ return options.emitDefaultValues || jsonArr.length > 0
74
+ ? jsonArr
75
+ : undefined;
76
+ }
77
+ else {
78
+ // In contrast to proto3, we raise an error if a non-optional (proto2 required)
79
+ // field is missing a value.
80
+ if (value === undefined) {
81
+ if (!field.oneof && !field.opt) {
82
+ throw `required field not set`;
83
+ }
84
+ return undefined;
85
+ }
86
+ switch (field.kind) {
87
+ case "scalar":
88
+ // In contrast to proto3, we do not skip intrinsic default values.
89
+ // Explicit default values are not special cased either.
90
+ return writeScalar(field.T, value, true);
91
+ case "enum":
92
+ // In contrast to proto3, we do not skip intrinsic default values.
93
+ // Explicit default values are not special cased either.
94
+ return writeEnum(field.T, value, true, options.enumAsInteger);
95
+ case "message":
96
+ return (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options);
97
+ }
98
+ }
99
+ };
100
+ });
99
101
  }
100
102
  exports.makeJsonFormatProto2 = makeJsonFormatProto2;
@@ -1,4 +1,17 @@
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.makeJsonFormatProto3 = void 0;
4
17
  const field_wrapper_js_1 = require("./field-wrapper.js");
@@ -6,98 +19,74 @@ const assert_js_1 = require("./assert.js");
6
19
  const json_format_common_js_1 = require("./json-format-common.js");
7
20
  /* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
8
21
  function makeJsonFormatProto3() {
9
- return (0, json_format_common_js_1.makeJsonFormatCommon)(
10
- (writeEnum, writeScalar) => {
11
- return function writeField(field, value, options) {
12
- if (field.kind == "map") {
13
- const jsonObj = {};
14
- switch (field.V.kind) {
15
- case "scalar":
16
- for (const [entryKey, entryValue] of Object.entries(value)) {
17
- const val = writeScalar(field.V.T, entryValue, true);
18
- (0, assert_js_1.assert)(val !== undefined);
19
- jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
20
- }
21
- break;
22
- case "message":
23
- for (const [entryKey, entryValue] of Object.entries(value)) {
24
- // JSON standard allows only (double quoted) string as property key
25
- jsonObj[entryKey.toString()] = entryValue.toJson(options);
26
- }
27
- break;
28
- case "enum":
29
- const enumType = field.V.T;
30
- for (const [entryKey, entryValue] of Object.entries(value)) {
31
- (0, assert_js_1.assert)(
32
- entryValue === undefined || typeof entryValue == "number"
33
- );
34
- const val = writeEnum(
35
- enumType,
36
- entryValue,
37
- true,
38
- options.enumAsInteger
39
- );
40
- (0, assert_js_1.assert)(val !== undefined);
41
- jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
42
- }
43
- break;
44
- }
45
- return options.emitDefaultValues || Object.keys(jsonObj).length > 0
46
- ? jsonObj
47
- : undefined;
48
- } else if (field.repeated) {
49
- const jsonArr = [];
50
- switch (field.kind) {
51
- case "scalar":
52
- for (let i = 0; i < value.length; i++) {
53
- jsonArr.push(writeScalar(field.T, value[i], true));
54
- }
55
- break;
56
- case "enum":
57
- for (let i = 0; i < value.length; i++) {
58
- jsonArr.push(
59
- writeEnum(field.T, value[i], true, options.enumAsInteger)
60
- );
61
- }
62
- break;
63
- case "message":
64
- for (let i = 0; i < value.length; i++) {
65
- jsonArr.push(
66
- (0, field_wrapper_js_1.wrapField)(field.T, value[i]).toJson(
67
- options
68
- )
69
- );
70
- }
71
- break;
72
- }
73
- return options.emitDefaultValues || jsonArr.length > 0
74
- ? jsonArr
75
- : undefined;
76
- } else {
77
- switch (field.kind) {
78
- case "scalar":
79
- return writeScalar(
80
- field.T,
81
- value,
82
- !!field.oneof || field.opt || options.emitDefaultValues
83
- );
84
- case "enum":
85
- return writeEnum(
86
- field.T,
87
- value,
88
- !!field.oneof || field.opt || options.emitDefaultValues,
89
- options.enumAsInteger
90
- );
91
- case "message":
92
- return value !== undefined
93
- ? (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(
94
- options
95
- )
96
- : undefined;
97
- }
98
- }
99
- };
100
- }
101
- );
22
+ return (0, json_format_common_js_1.makeJsonFormatCommon)((writeEnum, writeScalar) => {
23
+ return function writeField(field, value, options) {
24
+ if (field.kind == "map") {
25
+ const jsonObj = {};
26
+ switch (field.V.kind) {
27
+ case "scalar":
28
+ for (const [entryKey, entryValue] of Object.entries(value)) {
29
+ const val = writeScalar(field.V.T, entryValue, true);
30
+ (0, assert_js_1.assert)(val !== undefined);
31
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
32
+ }
33
+ break;
34
+ case "message":
35
+ for (const [entryKey, entryValue] of Object.entries(value)) {
36
+ // JSON standard allows only (double quoted) string as property key
37
+ jsonObj[entryKey.toString()] = entryValue.toJson(options);
38
+ }
39
+ break;
40
+ case "enum":
41
+ const enumType = field.V.T;
42
+ for (const [entryKey, entryValue] of Object.entries(value)) {
43
+ (0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
44
+ const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
45
+ (0, assert_js_1.assert)(val !== undefined);
46
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
47
+ }
48
+ break;
49
+ }
50
+ return options.emitDefaultValues || Object.keys(jsonObj).length > 0
51
+ ? jsonObj
52
+ : undefined;
53
+ }
54
+ else if (field.repeated) {
55
+ const jsonArr = [];
56
+ switch (field.kind) {
57
+ case "scalar":
58
+ for (let i = 0; i < value.length; i++) {
59
+ jsonArr.push(writeScalar(field.T, value[i], true));
60
+ }
61
+ break;
62
+ case "enum":
63
+ for (let i = 0; i < value.length; i++) {
64
+ jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
65
+ }
66
+ break;
67
+ case "message":
68
+ for (let i = 0; i < value.length; i++) {
69
+ jsonArr.push((0, field_wrapper_js_1.wrapField)(field.T, value[i]).toJson(options));
70
+ }
71
+ break;
72
+ }
73
+ return options.emitDefaultValues || jsonArr.length > 0
74
+ ? jsonArr
75
+ : undefined;
76
+ }
77
+ else {
78
+ switch (field.kind) {
79
+ case "scalar":
80
+ return writeScalar(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues);
81
+ case "enum":
82
+ return writeEnum(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues, options.enumAsInteger);
83
+ case "message":
84
+ return value !== undefined
85
+ ? (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options)
86
+ : undefined;
87
+ }
88
+ }
89
+ };
90
+ });
102
91
  }
103
92
  exports.makeJsonFormatProto3 = makeJsonFormatProto3;
@@ -1,4 +1,17 @@
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.makeMessageType = void 0;
4
17
  const message_js_1 = require("../message.js");
@@ -6,32 +19,31 @@ const message_js_1 = require("../message.js");
6
19
  * Create a new message type using the given runtime.
7
20
  */
8
21
  function makeMessageType(runtime, typeName, fields, opt) {
9
- const localName =
10
- opt?.localName ?? typeName.substring(typeName.lastIndexOf(".") + 1);
11
- const type = {
12
- [localName]: function (data) {
13
- runtime.util.initFields(this);
14
- runtime.util.initPartial(data, this);
15
- },
16
- }[localName];
17
- Object.setPrototypeOf(type.prototype, new message_js_1.Message());
18
- Object.assign(type, {
19
- runtime,
20
- typeName,
21
- fields: runtime.util.newFieldList(fields),
22
- fromBinary(bytes, options) {
23
- return new type().fromBinary(bytes, options);
24
- },
25
- fromJson(jsonValue, options) {
26
- return new type().fromJson(jsonValue, options);
27
- },
28
- fromJsonString(jsonString, options) {
29
- return new type().fromJsonString(jsonString, options);
30
- },
31
- equals(a, b) {
32
- return runtime.util.equals(type, a, b);
33
- },
34
- });
35
- return type;
22
+ const localName = opt?.localName ?? typeName.substring(typeName.lastIndexOf(".") + 1);
23
+ const type = {
24
+ [localName]: function (data) {
25
+ runtime.util.initFields(this);
26
+ runtime.util.initPartial(data, this);
27
+ },
28
+ }[localName];
29
+ Object.setPrototypeOf(type.prototype, new message_js_1.Message());
30
+ Object.assign(type, {
31
+ runtime,
32
+ typeName,
33
+ fields: runtime.util.newFieldList(fields),
34
+ fromBinary(bytes, options) {
35
+ return new type().fromBinary(bytes, options);
36
+ },
37
+ fromJson(jsonValue, options) {
38
+ return new type().fromJson(jsonValue, options);
39
+ },
40
+ fromJsonString(jsonString, options) {
41
+ return new type().fromJsonString(jsonString, options);
42
+ },
43
+ equals(a, b) {
44
+ return runtime.util.equals(type, a, b);
45
+ },
46
+ });
47
+ return type;
36
48
  }
37
49
  exports.makeMessageType = makeMessageType;
@@ -1,79 +1,88 @@
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.makeMethodName =
4
- exports.makeOneofName =
5
- exports.makeFieldName =
6
- exports.makeJsonName =
7
- void 0;
16
+ exports.makeMethodName = exports.makeOneofName = exports.makeFieldName = exports.makeJsonName = void 0;
8
17
  /**
9
18
  * Returns the JSON name for a protobuf field, exactly like protoc does.
10
19
  */
11
20
  function makeJsonName(protoName) {
12
- return protoCamelCase(protoName);
21
+ return protoCamelCase(protoName);
13
22
  }
14
23
  exports.makeJsonName = makeJsonName;
15
24
  /**
16
25
  * Returns the local name of a field, exactly like protoc-gen-es does.
17
26
  */
18
27
  function makeFieldName(protoName, inOneof) {
19
- const n = protoCamelCase(protoName);
20
- if (inOneof) {
21
- return n;
22
- }
23
- return rProp[n] ? n + escapeChar : n;
28
+ const n = protoCamelCase(protoName);
29
+ if (inOneof) {
30
+ return n;
31
+ }
32
+ return rProp[n] ? n + escapeChar : n;
24
33
  }
25
34
  exports.makeFieldName = makeFieldName;
26
35
  /**
27
36
  * Returns the local name of a oneof group, exactly like protoc-gen-es does.
28
37
  */
29
38
  function makeOneofName(protoName) {
30
- return makeFieldName(protoName, false);
39
+ return makeFieldName(protoName, false);
31
40
  }
32
41
  exports.makeOneofName = makeOneofName;
33
42
  /**
34
43
  * Returns the local name of a rpc, exactly like protoc-gen-es does.
35
44
  */
36
45
  function makeMethodName(protoName) {
37
- if (protoName.length == 0) {
38
- return protoName;
39
- }
40
- return protoName[0].toLowerCase() + protoName.substring(1);
46
+ if (protoName.length == 0) {
47
+ return protoName;
48
+ }
49
+ return protoName[0].toLowerCase() + protoName.substring(1);
41
50
  }
42
51
  exports.makeMethodName = makeMethodName;
43
52
  // Converts snake_case to protoCamelCase according to the convention
44
53
  // used by protoc to convert a field name to a JSON name.
45
54
  function protoCamelCase(snakeCase) {
46
- let capNext = false;
47
- const b = [];
48
- for (let i = 0; i < snakeCase.length; i++) {
49
- let c = snakeCase.charAt(i);
50
- switch (c) {
51
- case "_":
52
- capNext = true;
53
- break;
54
- case "0":
55
- case "1":
56
- case "2":
57
- case "3":
58
- case "4":
59
- case "5":
60
- case "6":
61
- case "7":
62
- case "8":
63
- case "9":
64
- b.push(c);
65
- capNext = false;
66
- break;
67
- default:
68
- if (capNext) {
69
- capNext = false;
70
- c = c.toUpperCase();
55
+ let capNext = false;
56
+ const b = [];
57
+ for (let i = 0; i < snakeCase.length; i++) {
58
+ let c = snakeCase.charAt(i);
59
+ switch (c) {
60
+ case "_":
61
+ capNext = true;
62
+ break;
63
+ case "0":
64
+ case "1":
65
+ case "2":
66
+ case "3":
67
+ case "4":
68
+ case "5":
69
+ case "6":
70
+ case "7":
71
+ case "8":
72
+ case "9":
73
+ b.push(c);
74
+ capNext = false;
75
+ break;
76
+ default:
77
+ if (capNext) {
78
+ capNext = false;
79
+ c = c.toUpperCase();
80
+ }
81
+ b.push(c);
82
+ break;
71
83
  }
72
- b.push(c);
73
- break;
74
84
  }
75
- }
76
- return b.join("");
85
+ return b.join("");
77
86
  }
78
87
  // escapeChar must be appended to a reserved name.
79
88
  // We choose '$' because it is invalid in proto identifiers.
@@ -81,21 +90,21 @@ const escapeChar = "$";
81
90
  // Names that cannot be used for object properties.
82
91
  // See buf_es/protoc-gen-es/internal/protoplugin/names.go
83
92
  const rProp = {
84
- // names reserved by JavaScript
85
- constructor: true,
86
- toString: true,
87
- toJSON: true,
88
- valueOf: true,
89
- // names reserved by the runtime
90
- getType: true,
91
- clone: true,
92
- equals: true,
93
- fromBinary: true,
94
- fromJson: true,
95
- fromJsonString: true,
96
- toBinary: true,
97
- toJson: true,
98
- toJsonString: true,
99
- // names reserved by the runtime for the future
100
- toObject: true,
93
+ // names reserved by JavaScript
94
+ constructor: true,
95
+ toString: true,
96
+ toJSON: true,
97
+ valueOf: true,
98
+ // names reserved by the runtime
99
+ getType: true,
100
+ clone: true,
101
+ equals: true,
102
+ fromBinary: true,
103
+ fromJson: true,
104
+ fromJsonString: true,
105
+ toBinary: true,
106
+ toJson: true,
107
+ toJsonString: true,
108
+ // names reserved by the runtime for the future
109
+ toObject: true,
101
110
  };
@@ -1,2 +1,15 @@
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 });