@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
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google Inc. nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ //
30
+ // Code generated by the Protocol Buffer compiler is owned by the owner
31
+ // of the input file used when generating it. This code is not
32
+ // standalone and requires a support library to be linked with it. This
33
+ // support library is itself covered by the above license.
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.varint32read = exports.varint32write = exports.int64toString = exports.int64fromString = exports.varint64write = exports.varint64read = void 0;
36
+ /* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
37
+ /**
38
+ * Read a 64 bit varint as two JS numbers.
39
+ *
40
+ * Returns tuple:
41
+ * [0]: low bits
42
+ * [1]: high bits
43
+ *
44
+ * Copyright 2008 Google Inc. All rights reserved.
45
+ *
46
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
47
+ */
48
+ function varint64read() {
49
+ let lowBits = 0;
50
+ let highBits = 0;
51
+ for (let shift = 0; shift < 28; shift += 7) {
52
+ let b = this.buf[this.pos++];
53
+ lowBits |= (b & 0x7f) << shift;
54
+ if ((b & 0x80) == 0) {
55
+ this.assertBounds();
56
+ return [lowBits, highBits];
57
+ }
58
+ }
59
+ let middleByte = this.buf[this.pos++];
60
+ // last four bits of the first 32 bit number
61
+ lowBits |= (middleByte & 0x0f) << 28;
62
+ // 3 upper bits are part of the next 32 bit number
63
+ highBits = (middleByte & 0x70) >> 4;
64
+ if ((middleByte & 0x80) == 0) {
65
+ this.assertBounds();
66
+ return [lowBits, highBits];
67
+ }
68
+ for (let shift = 3; shift <= 31; shift += 7) {
69
+ let b = this.buf[this.pos++];
70
+ highBits |= (b & 0x7f) << shift;
71
+ if ((b & 0x80) == 0) {
72
+ this.assertBounds();
73
+ return [lowBits, highBits];
74
+ }
75
+ }
76
+ throw new Error("invalid varint");
77
+ }
78
+ exports.varint64read = varint64read;
79
+ /**
80
+ * Write a 64 bit varint, given as two JS numbers, to the given bytes array.
81
+ *
82
+ * Copyright 2008 Google Inc. All rights reserved.
83
+ *
84
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
85
+ */
86
+ function varint64write(lo, hi, bytes) {
87
+ for (let i = 0; i < 28; i = i + 7) {
88
+ const shift = lo >>> i;
89
+ const hasNext = !(shift >>> 7 == 0 && hi == 0);
90
+ const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
91
+ bytes.push(byte);
92
+ if (!hasNext) {
93
+ return;
94
+ }
95
+ }
96
+ const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4);
97
+ const hasMoreBits = !(hi >> 3 == 0);
98
+ bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff);
99
+ if (!hasMoreBits) {
100
+ return;
101
+ }
102
+ for (let i = 3; i < 31; i = i + 7) {
103
+ const shift = hi >>> i;
104
+ const hasNext = !(shift >>> 7 == 0);
105
+ const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
106
+ bytes.push(byte);
107
+ if (!hasNext) {
108
+ return;
109
+ }
110
+ }
111
+ bytes.push((hi >>> 31) & 0x01);
112
+ }
113
+ exports.varint64write = varint64write;
114
+ // constants for binary math
115
+ const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
116
+ /**
117
+ * Parse decimal string of 64 bit integer value as two JS numbers.
118
+ *
119
+ * Returns tuple:
120
+ * [0]: minus sign?
121
+ * [1]: low bits
122
+ * [2]: high bits
123
+ *
124
+ * Copyright 2008 Google Inc.
125
+ */
126
+ function int64fromString(dec) {
127
+ // Check for minus sign.
128
+ let minus = dec[0] == "-";
129
+ if (minus)
130
+ dec = dec.slice(1);
131
+ // Work 6 decimal digits at a time, acting like we're converting base 1e6
132
+ // digits to binary. This is safe to do with floating point math because
133
+ // Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
134
+ const base = 1e6;
135
+ let lowBits = 0;
136
+ let highBits = 0;
137
+ function add1e6digit(begin, end) {
138
+ // Note: Number('') is 0.
139
+ const digit1e6 = Number(dec.slice(begin, end));
140
+ highBits *= base;
141
+ lowBits = lowBits * base + digit1e6;
142
+ // Carry bits from lowBits to
143
+ if (lowBits >= TWO_PWR_32_DBL) {
144
+ highBits = highBits + ((lowBits / TWO_PWR_32_DBL) | 0);
145
+ lowBits = lowBits % TWO_PWR_32_DBL;
146
+ }
147
+ }
148
+ add1e6digit(-24, -18);
149
+ add1e6digit(-18, -12);
150
+ add1e6digit(-12, -6);
151
+ add1e6digit(-6);
152
+ return [minus, lowBits, highBits];
153
+ }
154
+ exports.int64fromString = int64fromString;
155
+ /**
156
+ * Format 64 bit integer value (as two JS numbers) to decimal string.
157
+ *
158
+ * Copyright 2008 Google Inc.
159
+ */
160
+ function int64toString(bitsLow, bitsHigh) {
161
+ // Skip the expensive conversion if the number is small enough to use the
162
+ // built-in conversions.
163
+ if (bitsHigh <= 0x1fffff) {
164
+ return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
165
+ }
166
+ // What this code is doing is essentially converting the input number from
167
+ // base-2 to base-1e7, which allows us to represent the 64-bit range with
168
+ // only 3 (very large) digits. Those digits are then trivial to convert to
169
+ // a base-10 string.
170
+ // The magic numbers used here are -
171
+ // 2^24 = 16777216 = (1,6777216) in base-1e7.
172
+ // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
173
+ // Split 32:32 representation into 16:24:24 representation so our
174
+ // intermediate digits don't overflow.
175
+ let low = bitsLow & 0xffffff;
176
+ let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
177
+ let high = (bitsHigh >> 16) & 0xffff;
178
+ // Assemble our three base-1e7 digits, ignoring carries. The maximum
179
+ // value in a digit at this step is representable as a 48-bit integer, which
180
+ // can be stored in a 64-bit floating point number.
181
+ let digitA = low + mid * 6777216 + high * 6710656;
182
+ let digitB = mid + high * 8147497;
183
+ let digitC = high * 2;
184
+ // Apply carries from A to B and from B to C.
185
+ let base = 10000000;
186
+ if (digitA >= base) {
187
+ digitB += Math.floor(digitA / base);
188
+ digitA %= base;
189
+ }
190
+ if (digitB >= base) {
191
+ digitC += Math.floor(digitB / base);
192
+ digitB %= base;
193
+ }
194
+ // Convert base-1e7 digits to base-10, with optional leading zeroes.
195
+ function decimalFrom1e7(digit1e7, needLeadingZeros) {
196
+ let partial = digit1e7 ? String(digit1e7) : "";
197
+ if (needLeadingZeros) {
198
+ return "0000000".slice(partial.length) + partial;
199
+ }
200
+ return partial;
201
+ }
202
+ return (decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
203
+ decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
204
+ // If the final 1e7 digit didn't need leading zeros, we would have
205
+ // returned via the trivial code path at the top.
206
+ decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
207
+ }
208
+ exports.int64toString = int64toString;
209
+ /**
210
+ * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
211
+ *
212
+ * Copyright 2008 Google Inc. All rights reserved.
213
+ *
214
+ * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
215
+ */
216
+ function varint32write(value, bytes) {
217
+ if (value >= 0) {
218
+ // write value as varint 32
219
+ while (value > 0x7f) {
220
+ bytes.push((value & 0x7f) | 0x80);
221
+ value = value >>> 7;
222
+ }
223
+ bytes.push(value);
224
+ }
225
+ else {
226
+ for (let i = 0; i < 9; i++) {
227
+ bytes.push((value & 127) | 128);
228
+ value = value >> 7;
229
+ }
230
+ bytes.push(1);
231
+ }
232
+ }
233
+ exports.varint32write = varint32write;
234
+ /**
235
+ * Read an unsigned 32 bit varint.
236
+ *
237
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
238
+ */
239
+ function varint32read() {
240
+ let b = this.buf[this.pos++];
241
+ let result = b & 0x7f;
242
+ if ((b & 0x80) == 0) {
243
+ this.assertBounds();
244
+ return result;
245
+ }
246
+ b = this.buf[this.pos++];
247
+ result |= (b & 0x7f) << 7;
248
+ if ((b & 0x80) == 0) {
249
+ this.assertBounds();
250
+ return result;
251
+ }
252
+ b = this.buf[this.pos++];
253
+ result |= (b & 0x7f) << 14;
254
+ if ((b & 0x80) == 0) {
255
+ this.assertBounds();
256
+ return result;
257
+ }
258
+ b = this.buf[this.pos++];
259
+ result |= (b & 0x7f) << 21;
260
+ if ((b & 0x80) == 0) {
261
+ this.assertBounds();
262
+ return result;
263
+ }
264
+ // Extract only last 4 bits
265
+ b = this.buf[this.pos++];
266
+ result |= (b & 0x0f) << 28;
267
+ for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++)
268
+ b = this.buf[this.pos++];
269
+ if ((b & 0x80) != 0)
270
+ throw new Error("invalid varint");
271
+ this.assertBounds();
272
+ // Result can have 32 bits, convert it to unsigned
273
+ return result >>> 0;
274
+ }
275
+ exports.varint32read = varint32read;