@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.1

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 (127) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/binary-encoding.js +402 -410
  3. package/dist/cjs/descriptor-registry.js +407 -449
  4. package/dist/cjs/descriptor-set.js +416 -513
  5. package/dist/cjs/field.js +30 -30
  6. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  7. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  8. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  9. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  10. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  11. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  12. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  13. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  14. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  15. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  16. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  17. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  18. package/dist/cjs/index.js +24 -122
  19. package/dist/cjs/message.js +81 -89
  20. package/dist/cjs/private/assert.js +20 -26
  21. package/dist/cjs/private/base64.js +79 -78
  22. package/dist/cjs/private/binary-format-common.js +195 -208
  23. package/dist/cjs/private/binary-format-proto2.js +75 -109
  24. package/dist/cjs/private/binary-format-proto3.js +57 -90
  25. package/dist/cjs/private/enum.js +38 -43
  26. package/dist/cjs/private/field-list.js +51 -50
  27. package/dist/cjs/private/field-wrapper.js +8 -10
  28. package/dist/cjs/private/field.js +22 -25
  29. package/dist/cjs/private/goog-varint.js +275 -0
  30. package/dist/cjs/private/json-format-common.js +414 -440
  31. package/dist/cjs/private/json-format-proto2.js +78 -89
  32. package/dist/cjs/private/json-format-proto3.js +69 -93
  33. package/dist/cjs/private/message-type.js +26 -27
  34. package/dist/cjs/private/names.js +58 -62
  35. package/dist/cjs/private/proto-runtime.js +11 -16
  36. package/dist/cjs/private/scalars.js +100 -103
  37. package/dist/cjs/private/util-common.js +180 -210
  38. package/dist/cjs/proto-int64.js +111 -112
  39. package/dist/cjs/proto2.js +50 -63
  40. package/dist/cjs/proto3.js +61 -74
  41. package/dist/cjs/service-type.js +14 -17
  42. package/dist/cjs/type-registry.js +33 -31
  43. package/dist/esm/binary-encoding.js +401 -414
  44. package/dist/esm/descriptor-registry.js +409 -458
  45. package/dist/esm/descriptor-set.js +417 -478
  46. package/dist/esm/field.js +29 -29
  47. package/dist/esm/google/protobuf/any_pb.js +122 -140
  48. package/dist/esm/google/protobuf/api_pb.js +177 -197
  49. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  50. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  51. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  52. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  53. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  54. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  55. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  56. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  57. package/dist/esm/google/protobuf/type_pb.js +401 -421
  58. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  59. package/dist/esm/index.js +1 -1
  60. package/dist/esm/message.js +81 -89
  61. package/dist/esm/private/assert.js +19 -21
  62. package/dist/esm/private/base64.js +79 -78
  63. package/dist/esm/private/binary-format-common.js +196 -207
  64. package/dist/esm/private/binary-format-proto2.js +76 -81
  65. package/dist/esm/private/binary-format-proto3.js +58 -67
  66. package/dist/esm/private/enum.js +38 -43
  67. package/dist/esm/private/field-list.js +51 -50
  68. package/dist/esm/private/field-wrapper.js +8 -10
  69. package/dist/esm/private/field.js +22 -22
  70. package/dist/esm/private/goog-varint.js +266 -0
  71. package/dist/esm/private/json-format-common.js +414 -435
  72. package/dist/esm/private/json-format-proto2.js +76 -81
  73. package/dist/esm/private/json-format-proto3.js +66 -80
  74. package/dist/esm/private/message-type.js +27 -28
  75. package/dist/esm/private/names.js +57 -57
  76. package/dist/esm/private/proto-runtime.js +11 -11
  77. package/dist/esm/private/scalars.js +99 -99
  78. package/dist/esm/private/util-common.js +180 -192
  79. package/dist/esm/proto-int64.js +111 -112
  80. package/dist/esm/proto2.js +50 -57
  81. package/dist/esm/proto3.js +61 -68
  82. package/dist/esm/service-type.js +12 -12
  83. package/dist/esm/type-registry.js +33 -31
  84. package/dist/types/binary-encoding.d.ts +398 -398
  85. package/dist/types/binary-format.d.ts +69 -91
  86. package/dist/types/descriptor-registry.d.ts +23 -29
  87. package/dist/types/descriptor-set.d.ts +107 -128
  88. package/dist/types/enum.d.ts +21 -21
  89. package/dist/types/field-list.d.ts +21 -21
  90. package/dist/types/field.d.ts +191 -231
  91. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  92. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  93. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  94. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  95. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  96. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  97. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  98. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  99. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  100. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  101. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  102. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  103. package/dist/types/index.d.ts +4 -27
  104. package/dist/types/json-format.d.ts +70 -89
  105. package/dist/types/message-type.d.ts +38 -46
  106. package/dist/types/message.d.ts +73 -99
  107. package/dist/types/private/assert.d.ts +1 -4
  108. package/dist/types/private/binary-format-common.d.ts +6 -32
  109. package/dist/types/private/enum.d.ts +4 -11
  110. package/dist/types/private/field-list.d.ts +14 -21
  111. package/dist/types/private/field-wrapper.d.ts +5 -11
  112. package/dist/types/private/field.d.ts +12 -12
  113. package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
  114. package/dist/types/private/json-format-common.d.ts +5 -27
  115. package/dist/types/private/message-type.d.ts +3 -8
  116. package/dist/types/private/names.d.ts +1 -4
  117. package/dist/types/private/options-map.d.ts +1 -1
  118. package/dist/types/private/proto-runtime.d.ts +29 -42
  119. package/dist/types/private/scalars.d.ts +5 -12
  120. package/dist/types/private/util-common.d.ts +1 -4
  121. package/dist/types/private/util.d.ts +29 -41
  122. package/dist/types/proto-int64.d.ts +42 -42
  123. package/dist/types/service-type.d.ts +37 -57
  124. package/dist/types/type-registry.d.ts +13 -15
  125. package/package.json +2 -2
  126. package/dist/cjs/google/varint.js +0 -280
  127. package/dist/esm/google/varint.js +0 -265
@@ -6,95 +6,84 @@ const assert_js_1 = require("./assert.js");
6
6
  const json_format_common_js_1 = require("./json-format-common.js");
7
7
  /* 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
8
  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`;
9
+ return (0, json_format_common_js_1.makeJsonFormatCommon)((writeEnum, writeScalar) => {
10
+ return function writeField(field, value, options) {
11
+ if (field.kind == "map") {
12
+ const jsonObj = {};
13
+ switch (field.V.kind) {
14
+ case "scalar":
15
+ for (const [entryKey, entryValue] of Object.entries(value)) {
16
+ const val = writeScalar(field.V.T, entryValue, true);
17
+ (0, assert_js_1.assert)(val !== undefined);
18
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
19
+ }
20
+ break;
21
+ case "message":
22
+ for (const [entryKey, entryValue] of Object.entries(value)) {
23
+ // JSON standard allows only (double quoted) string as property key
24
+ jsonObj[entryKey.toString()] = entryValue.toJson(options);
25
+ }
26
+ break;
27
+ case "enum":
28
+ const enumType = field.V.T;
29
+ for (const [entryKey, entryValue] of Object.entries(value)) {
30
+ (0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
31
+ const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
32
+ (0, assert_js_1.assert)(val !== undefined);
33
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
34
+ }
35
+ break;
36
+ }
37
+ return options.emitDefaultValues || Object.keys(jsonObj).length > 0
38
+ ? jsonObj
39
+ : undefined;
78
40
  }
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
- );
41
+ else if (field.repeated) {
42
+ const jsonArr = [];
43
+ switch (field.kind) {
44
+ case "scalar":
45
+ for (let i = 0; i < value.length; i++) {
46
+ jsonArr.push(writeScalar(field.T, value[i], true));
47
+ }
48
+ break;
49
+ case "enum":
50
+ for (let i = 0; i < value.length; i++) {
51
+ jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
52
+ }
53
+ break;
54
+ case "message":
55
+ for (let i = 0; i < value.length; i++) {
56
+ jsonArr.push(value[i].toJson(options));
57
+ }
58
+ break;
59
+ }
60
+ return options.emitDefaultValues || jsonArr.length > 0
61
+ ? jsonArr
62
+ : undefined;
63
+ }
64
+ else {
65
+ // In contrast to proto3, we raise an error if a non-optional (proto2 required)
66
+ // field is missing a value.
67
+ if (value === undefined) {
68
+ if (!field.oneof && !field.opt) {
69
+ throw `required field not set`;
70
+ }
71
+ return undefined;
72
+ }
73
+ switch (field.kind) {
74
+ case "scalar":
75
+ // In contrast to proto3, we do not skip intrinsic default values.
76
+ // Explicit default values are not special cased either.
77
+ return writeScalar(field.T, value, true);
78
+ case "enum":
79
+ // In contrast to proto3, we do not skip intrinsic default values.
80
+ // Explicit default values are not special cased either.
81
+ return writeEnum(field.T, value, true, options.enumAsInteger);
82
+ case "message":
83
+ return (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options);
84
+ }
85
+ }
86
+ };
87
+ });
99
88
  }
100
89
  exports.makeJsonFormatProto2 = makeJsonFormatProto2;
@@ -6,98 +6,74 @@ const assert_js_1 = require("./assert.js");
6
6
  const json_format_common_js_1 = require("./json-format-common.js");
7
7
  /* 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
8
  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
- );
9
+ return (0, json_format_common_js_1.makeJsonFormatCommon)((writeEnum, writeScalar) => {
10
+ return function writeField(field, value, options) {
11
+ if (field.kind == "map") {
12
+ const jsonObj = {};
13
+ switch (field.V.kind) {
14
+ case "scalar":
15
+ for (const [entryKey, entryValue] of Object.entries(value)) {
16
+ const val = writeScalar(field.V.T, entryValue, true);
17
+ (0, assert_js_1.assert)(val !== undefined);
18
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
19
+ }
20
+ break;
21
+ case "message":
22
+ for (const [entryKey, entryValue] of Object.entries(value)) {
23
+ // JSON standard allows only (double quoted) string as property key
24
+ jsonObj[entryKey.toString()] = entryValue.toJson(options);
25
+ }
26
+ break;
27
+ case "enum":
28
+ const enumType = field.V.T;
29
+ for (const [entryKey, entryValue] of Object.entries(value)) {
30
+ (0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
31
+ const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
32
+ (0, assert_js_1.assert)(val !== undefined);
33
+ jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
34
+ }
35
+ break;
36
+ }
37
+ return options.emitDefaultValues || Object.keys(jsonObj).length > 0
38
+ ? jsonObj
39
+ : undefined;
40
+ }
41
+ else if (field.repeated) {
42
+ const jsonArr = [];
43
+ switch (field.kind) {
44
+ case "scalar":
45
+ for (let i = 0; i < value.length; i++) {
46
+ jsonArr.push(writeScalar(field.T, value[i], true));
47
+ }
48
+ break;
49
+ case "enum":
50
+ for (let i = 0; i < value.length; i++) {
51
+ jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
52
+ }
53
+ break;
54
+ case "message":
55
+ for (let i = 0; i < value.length; i++) {
56
+ jsonArr.push((0, field_wrapper_js_1.wrapField)(field.T, value[i]).toJson(options));
57
+ }
58
+ break;
59
+ }
60
+ return options.emitDefaultValues || jsonArr.length > 0
61
+ ? jsonArr
62
+ : undefined;
63
+ }
64
+ else {
65
+ switch (field.kind) {
66
+ case "scalar":
67
+ return writeScalar(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues);
68
+ case "enum":
69
+ return writeEnum(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues, options.enumAsInteger);
70
+ case "message":
71
+ return value !== undefined
72
+ ? (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options)
73
+ : undefined;
74
+ }
75
+ }
76
+ };
77
+ });
102
78
  }
103
79
  exports.makeJsonFormatProto3 = makeJsonFormatProto3;
@@ -6,32 +6,31 @@ const message_js_1 = require("../message.js");
6
6
  * Create a new message type using the given runtime.
7
7
  */
8
8
  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;
9
+ const localName = opt?.localName ?? typeName.substring(typeName.lastIndexOf(".") + 1);
10
+ const type = {
11
+ [localName]: function (data) {
12
+ runtime.util.initFields(this);
13
+ runtime.util.initPartial(data, this);
14
+ },
15
+ }[localName];
16
+ Object.setPrototypeOf(type.prototype, new message_js_1.Message());
17
+ Object.assign(type, {
18
+ runtime,
19
+ typeName,
20
+ fields: runtime.util.newFieldList(fields),
21
+ fromBinary(bytes, options) {
22
+ return new type().fromBinary(bytes, options);
23
+ },
24
+ fromJson(jsonValue, options) {
25
+ return new type().fromJson(jsonValue, options);
26
+ },
27
+ fromJsonString(jsonString, options) {
28
+ return new type().fromJsonString(jsonString, options);
29
+ },
30
+ equals(a, b) {
31
+ return runtime.util.equals(type, a, b);
32
+ },
33
+ });
34
+ return type;
36
35
  }
37
36
  exports.makeMessageType = makeMessageType;
@@ -1,79 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeMethodName =
4
- exports.makeOneofName =
5
- exports.makeFieldName =
6
- exports.makeJsonName =
7
- void 0;
3
+ exports.makeMethodName = exports.makeOneofName = exports.makeFieldName = exports.makeJsonName = void 0;
8
4
  /**
9
5
  * Returns the JSON name for a protobuf field, exactly like protoc does.
10
6
  */
11
7
  function makeJsonName(protoName) {
12
- return protoCamelCase(protoName);
8
+ return protoCamelCase(protoName);
13
9
  }
14
10
  exports.makeJsonName = makeJsonName;
15
11
  /**
16
12
  * Returns the local name of a field, exactly like protoc-gen-es does.
17
13
  */
18
14
  function makeFieldName(protoName, inOneof) {
19
- const n = protoCamelCase(protoName);
20
- if (inOneof) {
21
- return n;
22
- }
23
- return rProp[n] ? n + escapeChar : n;
15
+ const n = protoCamelCase(protoName);
16
+ if (inOneof) {
17
+ return n;
18
+ }
19
+ return rProp[n] ? n + escapeChar : n;
24
20
  }
25
21
  exports.makeFieldName = makeFieldName;
26
22
  /**
27
23
  * Returns the local name of a oneof group, exactly like protoc-gen-es does.
28
24
  */
29
25
  function makeOneofName(protoName) {
30
- return makeFieldName(protoName, false);
26
+ return makeFieldName(protoName, false);
31
27
  }
32
28
  exports.makeOneofName = makeOneofName;
33
29
  /**
34
30
  * Returns the local name of a rpc, exactly like protoc-gen-es does.
35
31
  */
36
32
  function makeMethodName(protoName) {
37
- if (protoName.length == 0) {
38
- return protoName;
39
- }
40
- return protoName[0].toLowerCase() + protoName.substring(1);
33
+ if (protoName.length == 0) {
34
+ return protoName;
35
+ }
36
+ return protoName[0].toLowerCase() + protoName.substring(1);
41
37
  }
42
38
  exports.makeMethodName = makeMethodName;
43
39
  // Converts snake_case to protoCamelCase according to the convention
44
40
  // used by protoc to convert a field name to a JSON name.
45
41
  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();
42
+ let capNext = false;
43
+ const b = [];
44
+ for (let i = 0; i < snakeCase.length; i++) {
45
+ let c = snakeCase.charAt(i);
46
+ switch (c) {
47
+ case "_":
48
+ capNext = true;
49
+ break;
50
+ case "0":
51
+ case "1":
52
+ case "2":
53
+ case "3":
54
+ case "4":
55
+ case "5":
56
+ case "6":
57
+ case "7":
58
+ case "8":
59
+ case "9":
60
+ b.push(c);
61
+ capNext = false;
62
+ break;
63
+ default:
64
+ if (capNext) {
65
+ capNext = false;
66
+ c = c.toUpperCase();
67
+ }
68
+ b.push(c);
69
+ break;
71
70
  }
72
- b.push(c);
73
- break;
74
71
  }
75
- }
76
- return b.join("");
72
+ return b.join("");
77
73
  }
78
74
  // escapeChar must be appended to a reserved name.
79
75
  // We choose '$' because it is invalid in proto identifiers.
@@ -81,21 +77,21 @@ const escapeChar = "$";
81
77
  // Names that cannot be used for object properties.
82
78
  // See buf_es/protoc-gen-es/internal/protoplugin/names.go
83
79
  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,
80
+ // names reserved by JavaScript
81
+ constructor: true,
82
+ toString: true,
83
+ toJSON: true,
84
+ valueOf: true,
85
+ // names reserved by the runtime
86
+ getType: true,
87
+ clone: true,
88
+ equals: true,
89
+ fromBinary: true,
90
+ fromJson: true,
91
+ fromJsonString: true,
92
+ toBinary: true,
93
+ toJson: true,
94
+ toJsonString: true,
95
+ // names reserved by the runtime for the future
96
+ toObject: true,
101
97
  };
@@ -4,21 +4,16 @@ exports.makeProtoRuntime = void 0;
4
4
  const enum_js_1 = require("./enum.js");
5
5
  const message_type_js_1 = require("./message-type.js");
6
6
  function makeProtoRuntime(syntax, json, bin, util) {
7
- return {
8
- syntax,
9
- json,
10
- bin,
11
- util,
12
- makeMessageType(typeName, fields, opt) {
13
- return (0, message_type_js_1.makeMessageType)(
14
- this,
15
- typeName,
16
- fields,
17
- opt
18
- );
19
- },
20
- makeEnumType: enum_js_1.makeEnumType,
21
- getEnumType: enum_js_1.getEnumType,
22
- };
7
+ return {
8
+ syntax,
9
+ json,
10
+ bin,
11
+ util,
12
+ makeMessageType(typeName, fields, opt) {
13
+ return (0, message_type_js_1.makeMessageType)(this, typeName, fields, opt);
14
+ },
15
+ makeEnumType: enum_js_1.makeEnumType,
16
+ getEnumType: enum_js_1.getEnumType,
17
+ };
23
18
  }
24
19
  exports.makeProtoRuntime = makeProtoRuntime;