@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,24 +1,33 @@
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.makeProtoRuntime = void 0;
4
17
  const enum_js_1 = require("./enum.js");
5
18
  const message_type_js_1 = require("./message-type.js");
6
19
  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
- };
20
+ return {
21
+ syntax,
22
+ json,
23
+ bin,
24
+ util,
25
+ makeMessageType(typeName, fields, opt) {
26
+ return (0, message_type_js_1.makeMessageType)(this, typeName, fields, opt);
27
+ },
28
+ makeEnum: enum_js_1.makeEnum,
29
+ makeEnumType: enum_js_1.makeEnumType,
30
+ getEnumType: enum_js_1.getEnumType,
31
+ };
23
32
  }
24
33
  exports.makeProtoRuntime = makeProtoRuntime;
@@ -1,9 +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.scalarTypeInfo =
4
- exports.scalarDefaultValue =
5
- exports.scalarEquals =
6
- void 0;
16
+ exports.scalarTypeInfo = exports.scalarDefaultValue = exports.scalarEquals = void 0;
7
17
  const field_js_1 = require("../field.js");
8
18
  const binary_encoding_js_1 = require("../binary-encoding.js");
9
19
  const proto_int64_js_1 = require("../proto-int64.js");
@@ -12,39 +22,39 @@ const proto_int64_js_1 = require("../proto-int64.js");
12
22
  * Returns true if both scalar values are equal.
13
23
  */
14
24
  function scalarEquals(type, a, b) {
15
- if (a === b) {
16
- // This correctly matches equal values except BYTES and (possibly) 64-bit integers.
17
- return true;
18
- }
19
- // Special case BYTES - we need to compare each byte individually
20
- if (type == field_js_1.ScalarType.BYTES) {
21
- if (!(a instanceof Uint8Array) || !(b instanceof Uint8Array)) {
22
- return false;
25
+ if (a === b) {
26
+ // This correctly matches equal values except BYTES and (possibly) 64-bit integers.
27
+ return true;
23
28
  }
24
- if (a.length !== b.length) {
25
- return false;
29
+ // Special case BYTES - we need to compare each byte individually
30
+ if (type == field_js_1.ScalarType.BYTES) {
31
+ if (!(a instanceof Uint8Array) || !(b instanceof Uint8Array)) {
32
+ return false;
33
+ }
34
+ if (a.length !== b.length) {
35
+ return false;
36
+ }
37
+ for (let i = 0; i < a.length; i++) {
38
+ if (a[i] !== b[i]) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
26
43
  }
27
- for (let i = 0; i < a.length; i++) {
28
- if (a[i] !== b[i]) {
29
- return false;
30
- }
44
+ // Special case 64-bit integers - we support number, string and bigint representation.
45
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
46
+ switch (type) {
47
+ case field_js_1.ScalarType.UINT64:
48
+ case field_js_1.ScalarType.FIXED64:
49
+ case field_js_1.ScalarType.INT64:
50
+ case field_js_1.ScalarType.SFIXED64:
51
+ case field_js_1.ScalarType.SINT64:
52
+ // Loose comparison will match between 0n, 0 and "0".
53
+ return a == b;
31
54
  }
32
- return true;
33
- }
34
- // Special case 64-bit integers - we support number, string and bigint representation.
35
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
36
- switch (type) {
37
- case field_js_1.ScalarType.UINT64:
38
- case field_js_1.ScalarType.FIXED64:
39
- case field_js_1.ScalarType.INT64:
40
- case field_js_1.ScalarType.SFIXED64:
41
- case field_js_1.ScalarType.SINT64:
42
- // Loose comparison will match between 0n, 0 and "0".
43
- return a == b;
44
- }
45
- // Anything that hasn't been caught by strict comparison or special cased
46
- // BYTES and 64-bit integers is not equal.
47
- return false;
55
+ // Anything that hasn't been caught by strict comparison or special cased
56
+ // BYTES and 64-bit integers is not equal.
57
+ return false;
48
58
  }
49
59
  exports.scalarEquals = scalarEquals;
50
60
  /**
@@ -52,27 +62,27 @@ exports.scalarEquals = scalarEquals;
52
62
  * proto3 semantics.
53
63
  */
54
64
  function scalarDefaultValue(type) {
55
- switch (type) {
56
- case field_js_1.ScalarType.BOOL:
57
- return false;
58
- case field_js_1.ScalarType.UINT64:
59
- case field_js_1.ScalarType.FIXED64:
60
- case field_js_1.ScalarType.INT64:
61
- case field_js_1.ScalarType.SFIXED64:
62
- case field_js_1.ScalarType.SINT64:
63
- return proto_int64_js_1.protoInt64.zero;
64
- case field_js_1.ScalarType.DOUBLE:
65
- case field_js_1.ScalarType.FLOAT:
66
- return 0.0;
67
- case field_js_1.ScalarType.BYTES:
68
- return new Uint8Array(0);
69
- case field_js_1.ScalarType.STRING:
70
- return "";
71
- default:
72
- // Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
73
- // We do not use individual cases to save a few bytes code size.
74
- return 0;
75
- }
65
+ switch (type) {
66
+ case field_js_1.ScalarType.BOOL:
67
+ return false;
68
+ case field_js_1.ScalarType.UINT64:
69
+ case field_js_1.ScalarType.FIXED64:
70
+ case field_js_1.ScalarType.INT64:
71
+ case field_js_1.ScalarType.SFIXED64:
72
+ case field_js_1.ScalarType.SINT64:
73
+ return proto_int64_js_1.protoInt64.zero;
74
+ case field_js_1.ScalarType.DOUBLE:
75
+ case field_js_1.ScalarType.FLOAT:
76
+ return 0.0;
77
+ case field_js_1.ScalarType.BYTES:
78
+ return new Uint8Array(0);
79
+ case field_js_1.ScalarType.STRING:
80
+ return "";
81
+ default:
82
+ // Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
83
+ // We do not use individual cases to save a few bytes code size.
84
+ return 0;
85
+ }
76
86
  }
77
87
  exports.scalarDefaultValue = scalarDefaultValue;
78
88
  /**
@@ -86,53 +96,53 @@ exports.scalarDefaultValue = scalarDefaultValue;
86
96
  * If argument `value` is omitted, [2] is always false.
87
97
  */
88
98
  function scalarTypeInfo(type, value) {
89
- const isUndefined = value === undefined;
90
- let wireType = binary_encoding_js_1.WireType.Varint;
91
- let isIntrinsicDefault = value === 0;
92
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- INT32, UINT32, SINT32 are covered by the defaults
93
- switch (type) {
94
- case field_js_1.ScalarType.STRING:
95
- isIntrinsicDefault = isUndefined || !value.length;
96
- wireType = binary_encoding_js_1.WireType.LengthDelimited;
97
- break;
98
- case field_js_1.ScalarType.BOOL:
99
- isIntrinsicDefault = value === false;
100
- break;
101
- case field_js_1.ScalarType.DOUBLE:
102
- wireType = binary_encoding_js_1.WireType.Bit64;
103
- break;
104
- case field_js_1.ScalarType.FLOAT:
105
- wireType = binary_encoding_js_1.WireType.Bit32;
106
- break;
107
- case field_js_1.ScalarType.INT64:
108
- isIntrinsicDefault = isUndefined || value == 0;
109
- break;
110
- case field_js_1.ScalarType.UINT64:
111
- isIntrinsicDefault = isUndefined || value == 0;
112
- break;
113
- case field_js_1.ScalarType.FIXED64:
114
- isIntrinsicDefault = isUndefined || value == 0;
115
- wireType = binary_encoding_js_1.WireType.Bit64;
116
- break;
117
- case field_js_1.ScalarType.BYTES:
118
- isIntrinsicDefault = isUndefined || !value.byteLength;
119
- wireType = binary_encoding_js_1.WireType.LengthDelimited;
120
- break;
121
- case field_js_1.ScalarType.FIXED32:
122
- wireType = binary_encoding_js_1.WireType.Bit32;
123
- break;
124
- case field_js_1.ScalarType.SFIXED32:
125
- wireType = binary_encoding_js_1.WireType.Bit32;
126
- break;
127
- case field_js_1.ScalarType.SFIXED64:
128
- isIntrinsicDefault = isUndefined || value == 0;
129
- wireType = binary_encoding_js_1.WireType.Bit64;
130
- break;
131
- case field_js_1.ScalarType.SINT64:
132
- isIntrinsicDefault = isUndefined || value == 0;
133
- break;
134
- }
135
- const method = field_js_1.ScalarType[type].toLowerCase();
136
- return [wireType, method, isUndefined || isIntrinsicDefault];
99
+ const isUndefined = value === undefined;
100
+ let wireType = binary_encoding_js_1.WireType.Varint;
101
+ let isIntrinsicDefault = value === 0;
102
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- INT32, UINT32, SINT32 are covered by the defaults
103
+ switch (type) {
104
+ case field_js_1.ScalarType.STRING:
105
+ isIntrinsicDefault = isUndefined || !value.length;
106
+ wireType = binary_encoding_js_1.WireType.LengthDelimited;
107
+ break;
108
+ case field_js_1.ScalarType.BOOL:
109
+ isIntrinsicDefault = value === false;
110
+ break;
111
+ case field_js_1.ScalarType.DOUBLE:
112
+ wireType = binary_encoding_js_1.WireType.Bit64;
113
+ break;
114
+ case field_js_1.ScalarType.FLOAT:
115
+ wireType = binary_encoding_js_1.WireType.Bit32;
116
+ break;
117
+ case field_js_1.ScalarType.INT64:
118
+ isIntrinsicDefault = isUndefined || value == 0;
119
+ break;
120
+ case field_js_1.ScalarType.UINT64:
121
+ isIntrinsicDefault = isUndefined || value == 0;
122
+ break;
123
+ case field_js_1.ScalarType.FIXED64:
124
+ isIntrinsicDefault = isUndefined || value == 0;
125
+ wireType = binary_encoding_js_1.WireType.Bit64;
126
+ break;
127
+ case field_js_1.ScalarType.BYTES:
128
+ isIntrinsicDefault = isUndefined || !value.byteLength;
129
+ wireType = binary_encoding_js_1.WireType.LengthDelimited;
130
+ break;
131
+ case field_js_1.ScalarType.FIXED32:
132
+ wireType = binary_encoding_js_1.WireType.Bit32;
133
+ break;
134
+ case field_js_1.ScalarType.SFIXED32:
135
+ wireType = binary_encoding_js_1.WireType.Bit32;
136
+ break;
137
+ case field_js_1.ScalarType.SFIXED64:
138
+ isIntrinsicDefault = isUndefined || value == 0;
139
+ wireType = binary_encoding_js_1.WireType.Bit64;
140
+ break;
141
+ case field_js_1.ScalarType.SINT64:
142
+ isIntrinsicDefault = isUndefined || value == 0;
143
+ break;
144
+ }
145
+ const method = field_js_1.ScalarType[type].toLowerCase();
146
+ return [wireType, method, isUndefined || isIntrinsicDefault];
137
147
  }
138
148
  exports.scalarTypeInfo = scalarTypeInfo;