@bufbuild/protobuf 0.0.10 → 0.1.0

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 (38) hide show
  1. package/dist/cjs/create-registry-from-desc.js +2 -112
  2. package/dist/cjs/create-registry.js +1 -1
  3. package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
  4. package/dist/cjs/google/protobuf/empty_pb.js +0 -1
  5. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  6. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  7. package/dist/cjs/google/varint.js +85 -37
  8. package/dist/cjs/index.js +1 -7
  9. package/dist/cjs/private/json-format-common.js +6 -6
  10. package/dist/cjs/proto-int64.js +23 -40
  11. package/dist/esm/create-registry-from-desc.js +1 -110
  12. package/dist/esm/create-registry.js +1 -1
  13. package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
  14. package/dist/esm/google/protobuf/empty_pb.js +0 -1
  15. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  16. package/dist/esm/google/protobuf/type_pb.js +1 -1
  17. package/dist/esm/google/varint.js +81 -34
  18. package/dist/esm/index.js +0 -3
  19. package/dist/esm/private/json-format-common.js +6 -6
  20. package/dist/esm/proto-int64.js +24 -41
  21. package/dist/types/create-registry-from-desc.d.ts +0 -34
  22. package/dist/types/create-registry.d.ts +1 -1
  23. package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
  24. package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
  25. package/dist/types/google/varint.d.ts +21 -9
  26. package/dist/types/index.d.ts +0 -3
  27. package/dist/types/message.d.ts +3 -1
  28. package/dist/types/proto-int64.d.ts +14 -13
  29. package/package.json +5 -9
  30. package/dist/cjs/legacy-descriptor-registry.js +0 -468
  31. package/dist/cjs/legacy-descriptor-set.js +0 -453
  32. package/dist/cjs/legacy-type-registry.js +0 -104
  33. package/dist/esm/legacy-descriptor-registry.js +0 -464
  34. package/dist/esm/legacy-descriptor-set.js +0 -449
  35. package/dist/esm/legacy-type-registry.js +0 -100
  36. package/dist/types/legacy-descriptor-registry.d.ts +0 -45
  37. package/dist/types/legacy-descriptor-set.d.ts +0 -152
  38. package/dist/types/legacy-type-registry.d.ts +0 -44
@@ -12,7 +12,7 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  /**
15
- * Create a new registry from the given types. Note that
15
+ * Create a new registry from the given types.
16
16
  */
17
17
  export function createRegistry(...types) {
18
18
  const messages = {};
@@ -1144,8 +1144,8 @@ UninterpretedOption.fields = proto2.util.newFieldList(() => [
1144
1144
  * The name of the uninterpreted option. Each string represents a segment in
1145
1145
  * a dot-separated name. is_extension is true iff a segment represents an
1146
1146
  * extension (denoted with parentheses in options specs in .proto files).
1147
- * E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
1148
- * "foo.(bar.baz).qux".
1147
+ * E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
1148
+ * "foo.(bar.baz).moo".
1149
1149
  *
1150
1150
  * @generated from message google.protobuf.UninterpretedOption.NamePart
1151
1151
  */
@@ -22,7 +22,6 @@ import { proto3 } from "../../proto3.js";
22
22
  * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
23
23
  * }
24
24
  *
25
- * The JSON representation for `Empty` is empty JSON object `{}`.
26
25
  *
27
26
  * @generated from message google.protobuf.Empty
28
27
  */
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v0.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -11,7 +11,7 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- // @generated by protoc-gen-es v0.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -107,22 +107,20 @@ export function varint64write(lo, hi, bytes) {
107
107
  bytes.push((hi >>> 31) & 0x01);
108
108
  }
109
109
  // constants for binary math
110
- const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
110
+ const TWO_PWR_32_DBL = 0x100000000;
111
111
  /**
112
112
  * Parse decimal string of 64 bit integer value as two JS numbers.
113
113
  *
114
- * Returns tuple:
115
- * [0]: minus sign?
116
- * [1]: low bits
117
- * [2]: high bits
114
+ * Copyright 2008 Google Inc. All rights reserved.
118
115
  *
119
- * Copyright 2008 Google Inc.
116
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
120
117
  */
121
- export function int64fromString(dec) {
118
+ export function int64FromString(dec) {
122
119
  // Check for minus sign.
123
- let minus = dec[0] == "-";
124
- if (minus)
120
+ const minus = dec[0] === "-";
121
+ if (minus) {
125
122
  dec = dec.slice(1);
123
+ }
126
124
  // Work 6 decimal digits at a time, acting like we're converting base 1e6
127
125
  // digits to binary. This is safe to do with floating point math because
128
126
  // Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
@@ -144,18 +142,45 @@ export function int64fromString(dec) {
144
142
  add1e6digit(-18, -12);
145
143
  add1e6digit(-12, -6);
146
144
  add1e6digit(-6);
147
- return [minus, lowBits, highBits];
145
+ return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
148
146
  }
149
147
  /**
150
- * Format 64 bit integer value (as two JS numbers) to decimal string.
148
+ * Losslessly converts a 64-bit signed integer in 32:32 split representation
149
+ * into a decimal string.
150
+ *
151
+ * Copyright 2008 Google Inc. All rights reserved.
152
+ *
153
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
154
+ */
155
+ export function int64ToString(lo, hi) {
156
+ let bits = newBits(lo, hi);
157
+ // If we're treating the input as a signed value and the high bit is set, do
158
+ // a manual two's complement conversion before the decimal conversion.
159
+ const negative = (bits.hi & 0x80000000);
160
+ if (negative) {
161
+ bits = negate(bits.lo, bits.hi);
162
+ }
163
+ const result = uInt64ToString(bits.lo, bits.hi);
164
+ return negative ? "-" + result : result;
165
+ }
166
+ /**
167
+ * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
168
+ * into a decimal string.
169
+ *
170
+ * Copyright 2008 Google Inc. All rights reserved.
151
171
  *
152
- * Copyright 2008 Google Inc.
172
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
153
173
  */
154
- export function int64toString(bitsLow, bitsHigh) {
174
+ export function uInt64ToString(lo, hi) {
175
+ ({ lo, hi } = toUnsigned(lo, hi));
155
176
  // Skip the expensive conversion if the number is small enough to use the
156
177
  // built-in conversions.
157
- if (bitsHigh <= 0x1fffff) {
158
- return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
178
+ // Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
179
+ // highBits <= 0x1FFFFF can be safely expressed with a double and retain
180
+ // integer precision.
181
+ // Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
182
+ if (hi <= 0x1FFFFF) {
183
+ return String(TWO_PWR_32_DBL * hi + lo);
159
184
  }
160
185
  // What this code is doing is essentially converting the input number from
161
186
  // base-2 to base-1e7, which allows us to represent the 64-bit range with
@@ -166,17 +191,17 @@ export function int64toString(bitsLow, bitsHigh) {
166
191
  // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
167
192
  // Split 32:32 representation into 16:24:24 representation so our
168
193
  // intermediate digits don't overflow.
169
- let low = bitsLow & 0xffffff;
170
- let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
171
- let high = (bitsHigh >> 16) & 0xffff;
194
+ const low = lo & 0xFFFFFF;
195
+ const mid = ((lo >>> 24) | (hi << 8)) & 0xFFFFFF;
196
+ const high = (hi >> 16) & 0xFFFF;
172
197
  // Assemble our three base-1e7 digits, ignoring carries. The maximum
173
198
  // value in a digit at this step is representable as a 48-bit integer, which
174
199
  // can be stored in a 64-bit floating point number.
175
- let digitA = low + mid * 6777216 + high * 6710656;
176
- let digitB = mid + high * 8147497;
177
- let digitC = high * 2;
200
+ let digitA = low + (mid * 6777216) + (high * 6710656);
201
+ let digitB = mid + (high * 8147497);
202
+ let digitC = (high * 2);
178
203
  // Apply carries from A to B and from B to C.
179
- let base = 10000000;
204
+ const base = 10000000;
180
205
  if (digitA >= base) {
181
206
  digitB += Math.floor(digitA / base);
182
207
  digitA %= base;
@@ -185,20 +210,42 @@ export function int64toString(bitsLow, bitsHigh) {
185
210
  digitC += Math.floor(digitB / base);
186
211
  digitB %= base;
187
212
  }
188
- // Convert base-1e7 digits to base-10, with optional leading zeroes.
189
- function decimalFrom1e7(digit1e7, needLeadingZeros) {
190
- let partial = digit1e7 ? String(digit1e7) : "";
191
- if (needLeadingZeros) {
192
- return "0000000".slice(partial.length) + partial;
193
- }
194
- return partial;
213
+ // If digitC is 0, then we should have returned in the trivial code path
214
+ // at the top for non-safe integers. Given this, we can assume both digitB
215
+ // and digitA need leading zeros.
216
+ return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) +
217
+ decimalFrom1e7WithLeadingZeros(digitA);
218
+ }
219
+ function toUnsigned(lo, hi) {
220
+ return { lo: lo >>> 0, hi: hi >>> 0 };
221
+ }
222
+ function newBits(lo, hi) {
223
+ return { lo: lo | 0, hi: hi | 0 };
224
+ }
225
+ /**
226
+ * Returns two's compliment negation of input.
227
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
228
+ */
229
+ function negate(lowBits, highBits) {
230
+ highBits = ~highBits;
231
+ if (lowBits) {
232
+ lowBits = ~lowBits + 1;
233
+ }
234
+ else {
235
+ // If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
236
+ // adding 1 to that, results in 0x100000000, which leaves
237
+ // the low bits 0x0 and simply adds one to the high bits.
238
+ highBits += 1;
195
239
  }
196
- return (decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
197
- decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
198
- // If the final 1e7 digit didn't need leading zeros, we would have
199
- // returned via the trivial code path at the top.
200
- decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
240
+ return newBits(lowBits, highBits);
201
241
  }
242
+ /**
243
+ * Returns decimal representation of digit1e7 with leading zeros.
244
+ */
245
+ const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
246
+ const partial = String(digit1e7);
247
+ return "0000000".slice(partial.length) + partial;
248
+ };
202
249
  /**
203
250
  * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
204
251
  *
package/dist/esm/index.js CHANGED
@@ -26,9 +26,6 @@ export { createDescriptorSet } from "./create-descriptor-set.js";
26
26
  export {} from "./type-registry.js";
27
27
  export { createRegistry } from "./create-registry.js";
28
28
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
29
- export { LegacyDescriptorRegistry } from "./legacy-descriptor-registry.js";
30
- export { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
31
- export { TypeRegistry } from "./legacy-type-registry.js";
32
29
  // ideally, we would export these types with sub-path exports:
33
30
  export * from "./google/protobuf/compiler/plugin_pb.js";
34
31
  export * from "./google/protobuf/api_pb.js";
@@ -73,12 +73,12 @@ export function makeJsonFormatCommon(makeWriteField) {
73
73
  continue;
74
74
  }
75
75
  if (!Array.isArray(jsonValue)) {
76
- throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`);
76
+ throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`);
77
77
  }
78
78
  const targetArray = target[localName];
79
79
  for (const jsonItem of jsonValue) {
80
80
  if (jsonItem === null) {
81
- throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonItem)}"`);
81
+ throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`);
82
82
  }
83
83
  let val;
84
84
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- "map" is invalid for repeated fields
@@ -96,7 +96,7 @@ export function makeJsonFormatCommon(makeWriteField) {
96
96
  val = readScalar(field.T, jsonItem);
97
97
  }
98
98
  catch (e) {
99
- let m = `cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonItem)}"`;
99
+ let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`;
100
100
  if (e instanceof Error && e.message.length > 0) {
101
101
  m += `: ${e.message}`;
102
102
  }
@@ -134,7 +134,7 @@ export function makeJsonFormatCommon(makeWriteField) {
134
134
  val = readScalar(field.V.T, jsonMapValue);
135
135
  }
136
136
  catch (e) {
137
- let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
137
+ let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
138
138
  if (e instanceof Error && e.message.length > 0) {
139
139
  m += `: ${e.message}`;
140
140
  }
@@ -152,7 +152,7 @@ export function makeJsonFormatCommon(makeWriteField) {
152
152
  : jsonMapKey).toString()] = val;
153
153
  }
154
154
  catch (e) {
155
- let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
155
+ let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
156
156
  if (e instanceof Error && e.message.length > 0) {
157
157
  m += `: ${e.message}`;
158
158
  }
@@ -187,7 +187,7 @@ export function makeJsonFormatCommon(makeWriteField) {
187
187
  target[localName] = readScalar(field.T, jsonValue);
188
188
  }
189
189
  catch (e) {
190
- let m = `cannot decode field ${type.typeName}.${field.name} from JSON: "${this.debug(jsonValue)}"`;
190
+ let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
191
191
  if (e instanceof Error && e.message.length > 0) {
192
192
  m += `: ${e.message}`;
193
193
  }
@@ -11,7 +11,8 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { int64fromString, int64toString } from "./google/varint.js";
14
+ import { assert } from "./private/assert.js";
15
+ import { int64FromString, int64ToString, uInt64ToString, } from "./google/varint.js";
15
16
  function makeInt64Support() {
16
17
  const dv = new DataView(new ArrayBuffer(8));
17
18
  // note that Safari 14 implements BigInt, but not the DataView methods
@@ -19,7 +20,10 @@ function makeInt64Support() {
19
20
  typeof dv.getBigInt64 === "function" &&
20
21
  typeof dv.getBigUint64 === "function" &&
21
22
  typeof dv.setBigInt64 === "function" &&
22
- typeof dv.setBigUint64 === "function";
23
+ typeof dv.setBigUint64 === "function" &&
24
+ (typeof process != "object" ||
25
+ typeof process.env != "object" ||
26
+ process.env.BUF_BIGINT_DISABLE !== "1");
23
27
  if (ok) {
24
28
  const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");
25
29
  return {
@@ -65,65 +69,44 @@ function makeInt64Support() {
65
69
  },
66
70
  };
67
71
  }
72
+ const assertInt64String = (value) => assert(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
73
+ const assertUInt64String = (value) => assert(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
68
74
  return {
69
75
  zero: "0",
70
76
  supported: false,
71
77
  parse(value) {
72
- if (!/^-?[0-9]+$/.test(value)) {
73
- throw new Error(`int64 invalid: ${value}`);
78
+ if (typeof value != "string") {
79
+ value = value.toString();
74
80
  }
81
+ assertInt64String(value);
75
82
  return value;
76
83
  },
77
84
  uParse(value) {
78
- if (!/^-?[0-9]+$/.test(value)) {
79
- throw new Error(`uint64 invalid: ${value}`);
85
+ if (typeof value != "string") {
86
+ value = value.toString();
80
87
  }
88
+ assertUInt64String(value);
81
89
  return value;
82
90
  },
83
91
  enc(value) {
84
- if (typeof value == "string") {
85
- if (!/^-?[0-9]+$/.test(value)) {
86
- throw new Error(`int64 invalid: ${value}`);
87
- }
88
- }
89
- else {
90
- value = value.toString(10);
92
+ if (typeof value != "string") {
93
+ value = value.toString();
91
94
  }
92
- const [, lo, hi] = int64fromString(value);
93
- return { lo, hi };
95
+ assertInt64String(value);
96
+ return int64FromString(value);
94
97
  },
95
98
  uEnc(value) {
96
- if (typeof value == "string") {
97
- if (!/^-?[0-9]+$/.test(value)) {
98
- throw new Error(`uint64 invalid: ${value}`);
99
- }
99
+ if (typeof value != "string") {
100
+ value = value.toString();
100
101
  }
101
- else {
102
- value = value.toString(10);
103
- }
104
- const [minus, lo, hi] = int64fromString(value);
105
- if (minus) {
106
- throw new Error(`uint64 invalid: ${value}`);
107
- }
108
- return { lo, hi };
102
+ assertUInt64String(value);
103
+ return int64FromString(value);
109
104
  },
110
105
  dec(lo, hi) {
111
- const minus = (hi & 0x80000000) !== 0;
112
- if (minus) {
113
- // negate
114
- hi = ~hi;
115
- if (lo) {
116
- lo = ~lo + 1;
117
- }
118
- else {
119
- hi += 1;
120
- }
121
- return ("-" + int64toString(lo, hi));
122
- }
123
- return int64toString(lo, hi);
106
+ return int64ToString(lo, hi);
124
107
  },
125
108
  uDec(lo, hi) {
126
- return int64toString(lo, hi);
109
+ return uInt64ToString(lo, hi);
127
110
  },
128
111
  };
129
112
  }
@@ -1,7 +1,4 @@
1
- import type { MessageType } from "./message-type.js";
2
- import type { EnumType } from "./enum.js";
3
1
  import type { IEnumTypeRegistry, IMessageTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
4
- import type { ServiceType } from "./service-type.js";
5
2
  import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
6
3
  import type { DescriptorSet } from "./descriptor-set.js";
7
4
  /**
@@ -16,34 +13,3 @@ import type { DescriptorSet } from "./descriptor-set.js";
16
13
  * are replaced with their generated counterpart in this package.
17
14
  */
18
15
  export declare function createRegistryFromDescriptors(input: DescriptorSet | FileDescriptorSet | Uint8Array, replaceWkt?: boolean): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry;
19
- /**
20
- * DescriptorRegistry is a type registry that dynamically creates types
21
- * from a set of google.protobuf.FileDescriptorProto.
22
- *
23
- * By default, all well-known types with a specialized JSON representation
24
- * are replaced with their generated counterpart in this package.
25
- */
26
- export declare class DescriptorRegistry implements IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry {
27
- private readonly desc;
28
- private readonly enums;
29
- private readonly messages;
30
- private readonly services;
31
- constructor(descriptorSet: DescriptorSet, replaceWkt?: boolean);
32
- /**
33
- * Conveniently create a DescriptorRegistry from a FileDescriptorSet,
34
- * or a FileDescriptorSet in binary format.
35
- */
36
- static fromFileDescriptorSet(input: FileDescriptorSet | Uint8Array): DescriptorRegistry;
37
- /**
38
- * May raise an error on invalid descriptors.
39
- */
40
- findEnum(typeName: string): EnumType | undefined;
41
- /**
42
- * May raise an error on invalid descriptors.
43
- */
44
- findMessage(typeName: string): MessageType | undefined;
45
- /**
46
- * May raise an error on invalid descriptors.
47
- */
48
- findService(typeName: string): ServiceType | undefined;
49
- }
@@ -3,6 +3,6 @@ import type { EnumType } from "./enum.js";
3
3
  import type { ServiceType } from "./service-type.js";
4
4
  import type { IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
5
5
  /**
6
- * Create a new registry from the given types. Note that
6
+ * Create a new registry from the given types.
7
7
  */
8
8
  export declare function createRegistry(...types: Array<MessageType | EnumType | ServiceType>): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry;
@@ -1333,8 +1333,8 @@ export declare class UninterpretedOption extends Message<UninterpretedOption> {
1333
1333
  * The name of the uninterpreted option. Each string represents a segment in
1334
1334
  * a dot-separated name. is_extension is true iff a segment represents an
1335
1335
  * extension (denoted with parentheses in options specs in .proto files).
1336
- * E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
1337
- * "foo.(bar.baz).qux".
1336
+ * E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
1337
+ * "foo.(bar.baz).moo".
1338
1338
  *
1339
1339
  * @generated from message google.protobuf.UninterpretedOption.NamePart
1340
1340
  */
@@ -1490,13 +1490,13 @@ export declare class SourceCodeInfo_Location extends Message<SourceCodeInfo_Loca
1490
1490
  * // Comment attached to baz.
1491
1491
  * // Another line attached to baz.
1492
1492
  *
1493
- * // Comment attached to qux.
1493
+ * // Comment attached to moo.
1494
1494
  * //
1495
- * // Another line attached to qux.
1496
- * optional double qux = 4;
1495
+ * // Another line attached to moo.
1496
+ * optional double moo = 4;
1497
1497
  *
1498
1498
  * // Detached comment for corge. This is not leading or trailing comments
1499
- * // to qux or corge because there are blank lines separating it from
1499
+ * // to moo or corge because there are blank lines separating it from
1500
1500
  * // both.
1501
1501
  *
1502
1502
  * // Detached comment for corge paragraph 2.
@@ -12,7 +12,6 @@ import type { JsonReadOptions, JsonValue } from "../../json-format.js";
12
12
  * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
13
13
  * }
14
14
  *
15
- * The JSON representation for `Empty` is empty JSON object `{}`.
16
15
  *
17
16
  * @generated from message google.protobuf.Empty
18
17
  */
@@ -21,20 +21,32 @@ export declare function varint64write(lo: number, hi: number, bytes: number[]):
21
21
  /**
22
22
  * Parse decimal string of 64 bit integer value as two JS numbers.
23
23
  *
24
- * Returns tuple:
25
- * [0]: minus sign?
26
- * [1]: low bits
27
- * [2]: high bits
24
+ * Copyright 2008 Google Inc. All rights reserved.
25
+ *
26
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
27
+ */
28
+ export declare function int64FromString(dec: string): {
29
+ lo: number;
30
+ hi: number;
31
+ };
32
+ /**
33
+ * Losslessly converts a 64-bit signed integer in 32:32 split representation
34
+ * into a decimal string.
35
+ *
36
+ * Copyright 2008 Google Inc. All rights reserved.
28
37
  *
29
- * Copyright 2008 Google Inc.
38
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
30
39
  */
31
- export declare function int64fromString(dec: string): [boolean, number, number];
40
+ export declare function int64ToString(lo: number, hi: number): string;
32
41
  /**
33
- * Format 64 bit integer value (as two JS numbers) to decimal string.
42
+ * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
43
+ * into a decimal string.
44
+ *
45
+ * Copyright 2008 Google Inc. All rights reserved.
34
46
  *
35
- * Copyright 2008 Google Inc.
47
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
36
48
  */
37
- export declare function int64toString(bitsLow: number, bitsHigh: number): string;
49
+ export declare function uInt64ToString(lo: number, hi: number): string;
38
50
  /**
39
51
  * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
40
52
  *
@@ -20,9 +20,6 @@ export { createDescriptorSet } from "./create-descriptor-set.js";
20
20
  export { IMessageTypeRegistry } from "./type-registry.js";
21
21
  export { createRegistry } from "./create-registry.js";
22
22
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
23
- export { LegacyDescriptorRegistry } from "./legacy-descriptor-registry.js";
24
- export { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
25
- export { TypeRegistry } from "./legacy-type-registry.js";
26
23
  export * from "./google/protobuf/compiler/plugin_pb.js";
27
24
  export * from "./google/protobuf/api_pb.js";
28
25
  export * from "./google/protobuf/any_pb.js";
@@ -67,7 +67,9 @@ export declare class Message<T extends Message<T> = AnyMessage> {
67
67
  * PlainMessage<T> strips all methods from a message, leaving only fields
68
68
  * and oneof groups.
69
69
  */
70
- export declare type PlainMessage<T extends Message> = Omit<T, keyof Message>;
70
+ export declare type PlainMessage<T extends Message> = {
71
+ [P in keyof T as T[P] extends Function ? never : P]: T[P];
72
+ };
71
73
  /**
72
74
  * PartialMessage<T> constructs a type from a message. The resulting type
73
75
  * only contains the protobuf field members of the message, and all of them
@@ -29,22 +29,23 @@
29
29
  * ```
30
30
  *
31
31
  * If you need to manipulate 64-bit integral values that are outside the
32
- * range of safe representation as Number, you can work with the two's
33
- * complement directly. The following example negates a field value:
32
+ * range of safe representation as a JavaScript Number, we recommend you
33
+ * use a third party library, for example the npm package "long":
34
34
  *
35
35
  * ```ts
36
- * let t = protoInt64.enc(message.int64Field);
37
- * t.hi = ~t.hi;
38
- * if (t.lo) {
39
- * t.lo = ~t.lo + 1;
40
- * } else {
41
- * t.hi += 1;
42
- * }
43
- * message.int64Field = protoInt64.dec(t.lo, t.hi);
44
- * ```
36
+ * // convert the field value to a Long
37
+ * const bits = protoInt64.enc(message.int64Field);
38
+ * const longValue = Long.fromBits(bits.lo, bits.hi);
39
+ *
40
+ * // perform arithmetic
41
+ * const longResult = longValue.subtract(1);
45
42
  *
46
- * There are several 3rd party libraries that provide arithmetic operations
47
- * on a two's complement, for example the npm package "long".
43
+ * // set the result in the field
44
+ * message.int64Field = protoInt64.dec(longResult.low, longResult.high);
45
+ *
46
+ * // Assuming int64Field contains 9223372036854775807:
47
+ * console.log(message.int64Field); // 9223372036854775806
48
+ * ```
48
49
  */
49
50
  interface Int64Support {
50
51
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "repository": {
@@ -12,19 +12,15 @@
12
12
  "scripts": {
13
13
  "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*",
14
14
  "build": "npm run build:cjs && npm run build:esm+types",
15
- "build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
16
- "build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
15
+ "build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
16
+ "build:esm+types": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
17
17
  },
18
- "main": "./dist/esm/index.js",
18
+ "main": "./dist/cjs/index.js",
19
19
  "type": "module",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "exports": {
22
22
  "import": "./dist/esm/index.js",
23
- "require": "./dist/cjs/index.js",
24
- "default": "./dist/esm/index.js"
25
- },
26
- "devDependencies": {
27
- "typescript": "^4.7.4"
23
+ "require": "./dist/cjs/index.js"
28
24
  },
29
25
  "files": [
30
26
  "dist/**/"