@bufbuild/protobuf 0.0.9 → 0.1.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.
- package/README.md +1 -1
- package/dist/cjs/create-registry-from-desc.js +10 -116
- package/dist/cjs/create-registry.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/empty_pb.js +0 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/varint.js +85 -37
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/private/binary-format-proto2.js +1 -1
- package/dist/cjs/private/json-format-common.js +6 -6
- package/dist/cjs/proto-int64.js +23 -40
- package/dist/esm/create-registry-from-desc.js +9 -114
- package/dist/esm/create-registry.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/empty_pb.js +0 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/varint.js +81 -34
- package/dist/esm/index.js +0 -3
- package/dist/esm/private/binary-format-proto2.js +1 -1
- package/dist/esm/private/json-format-common.js +6 -6
- package/dist/esm/proto-int64.js +24 -41
- package/dist/types/create-registry-from-desc.d.ts +0 -34
- package/dist/types/create-registry.d.ts +1 -1
- package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
- package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
- package/dist/types/google/varint.d.ts +21 -9
- package/dist/types/index.d.ts +0 -3
- package/dist/types/json-format.d.ts +1 -1
- package/dist/types/message.d.ts +3 -1
- package/dist/types/proto-int64.d.ts +14 -13
- package/package.json +5 -8
- package/dist/cjs/legacy-descriptor-registry.js +0 -468
- package/dist/cjs/legacy-descriptor-set.js +0 -453
- package/dist/cjs/legacy-type-registry.js +0 -104
- package/dist/esm/legacy-descriptor-registry.js +0 -464
- package/dist/esm/legacy-descriptor-set.js +0 -449
- package/dist/esm/legacy-type-registry.js +0 -100
- package/dist/types/legacy-descriptor-registry.d.ts +0 -45
- package/dist/types/legacy-descriptor-set.d.ts +0 -152
- package/dist/types/legacy-type-registry.d.ts +0 -44
|
@@ -135,7 +135,7 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
135
135
|
const methods = {};
|
|
136
136
|
for (const method of desc.methods) {
|
|
137
137
|
const I = this.findMessage(method.input.typeName);
|
|
138
|
-
const O = this.findMessage(method.
|
|
138
|
+
const O = this.findMessage(method.output.typeName);
|
|
139
139
|
assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
140
140
|
assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
141
141
|
const m = {
|
|
@@ -156,115 +156,6 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
156
156
|
},
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
/**
|
|
160
|
-
* DescriptorRegistry is a type registry that dynamically creates types
|
|
161
|
-
* from a set of google.protobuf.FileDescriptorProto.
|
|
162
|
-
*
|
|
163
|
-
* By default, all well-known types with a specialized JSON representation
|
|
164
|
-
* are replaced with their generated counterpart in this package.
|
|
165
|
-
*/
|
|
166
|
-
export class DescriptorRegistry {
|
|
167
|
-
constructor(descriptorSet, replaceWkt = true) {
|
|
168
|
-
this.enums = {};
|
|
169
|
-
this.messages = {};
|
|
170
|
-
this.services = {};
|
|
171
|
-
this.desc = descriptorSet;
|
|
172
|
-
if (replaceWkt) {
|
|
173
|
-
for (const mt of wkMessages) {
|
|
174
|
-
this.messages[mt.typeName] = mt;
|
|
175
|
-
}
|
|
176
|
-
for (const et of wkEnums) {
|
|
177
|
-
this.enums[et.typeName] = et;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
|
|
183
|
-
* or a FileDescriptorSet in binary format.
|
|
184
|
-
*/
|
|
185
|
-
static fromFileDescriptorSet(input) {
|
|
186
|
-
return new DescriptorRegistry(createDescriptorSet(input));
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* May raise an error on invalid descriptors.
|
|
190
|
-
*/
|
|
191
|
-
findEnum(typeName) {
|
|
192
|
-
const existing = this.enums[typeName];
|
|
193
|
-
if (existing) {
|
|
194
|
-
return existing;
|
|
195
|
-
}
|
|
196
|
-
const desc = this.desc.enums.get(typeName);
|
|
197
|
-
if (!desc) {
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
|
|
201
|
-
const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
|
|
202
|
-
no: u.number,
|
|
203
|
-
name: u.name,
|
|
204
|
-
localName: localName(u),
|
|
205
|
-
})), {});
|
|
206
|
-
this.enums[typeName] = type;
|
|
207
|
-
return type;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* May raise an error on invalid descriptors.
|
|
211
|
-
*/
|
|
212
|
-
findMessage(typeName) {
|
|
213
|
-
const existing = this.messages[typeName];
|
|
214
|
-
if (existing) {
|
|
215
|
-
return existing;
|
|
216
|
-
}
|
|
217
|
-
const desc = this.desc.messages.get(typeName);
|
|
218
|
-
if (!desc) {
|
|
219
|
-
return undefined;
|
|
220
|
-
}
|
|
221
|
-
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
|
|
222
|
-
const fields = [];
|
|
223
|
-
const type = runtime.makeMessageType(typeName, () => fields, {
|
|
224
|
-
localName: localName(desc),
|
|
225
|
-
});
|
|
226
|
-
this.messages[typeName] = type;
|
|
227
|
-
for (const field of desc.fields) {
|
|
228
|
-
const fieldInfo = makeFieldInfo(field, this);
|
|
229
|
-
fields.push(fieldInfo);
|
|
230
|
-
}
|
|
231
|
-
return type;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* May raise an error on invalid descriptors.
|
|
235
|
-
*/
|
|
236
|
-
findService(typeName) {
|
|
237
|
-
const existing = this.services[typeName];
|
|
238
|
-
if (existing) {
|
|
239
|
-
return existing;
|
|
240
|
-
}
|
|
241
|
-
const desc = this.desc.services.get(typeName);
|
|
242
|
-
if (!desc) {
|
|
243
|
-
return undefined;
|
|
244
|
-
}
|
|
245
|
-
const methods = {};
|
|
246
|
-
for (const method of desc.methods) {
|
|
247
|
-
const I = this.findMessage(method.input.typeName);
|
|
248
|
-
const O = this.findMessage(method.input.typeName);
|
|
249
|
-
assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
250
|
-
assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
251
|
-
const m = {
|
|
252
|
-
name: method.name,
|
|
253
|
-
localName: localName(method),
|
|
254
|
-
I,
|
|
255
|
-
O,
|
|
256
|
-
kind: method.methodKind,
|
|
257
|
-
idempotency: method.idempotency,
|
|
258
|
-
options: {},
|
|
259
|
-
};
|
|
260
|
-
methods[m.localName] = m;
|
|
261
|
-
}
|
|
262
|
-
return (this.services[typeName] = {
|
|
263
|
-
typeName: desc.typeName,
|
|
264
|
-
methods,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
159
|
function makeFieldInfo(desc, resolver) {
|
|
269
160
|
switch (desc.kind) {
|
|
270
161
|
case "map_field":
|
|
@@ -286,8 +177,9 @@ function makeFieldInfo(desc, resolver) {
|
|
|
286
177
|
function makeMapFieldInfo(field, resolver) {
|
|
287
178
|
const base = {
|
|
288
179
|
kind: "map",
|
|
289
|
-
name: field.name,
|
|
290
180
|
no: field.number,
|
|
181
|
+
name: field.name,
|
|
182
|
+
jsonName: field.jsonName,
|
|
291
183
|
K: field.mapKey,
|
|
292
184
|
};
|
|
293
185
|
if (field.mapValue.message) {
|
|
@@ -313,9 +205,10 @@ function makeMapFieldInfo(field, resolver) {
|
|
|
313
205
|
}
|
|
314
206
|
function makeScalarFieldInfo(field) {
|
|
315
207
|
const base = {
|
|
208
|
+
kind: "scalar",
|
|
316
209
|
no: field.number,
|
|
317
210
|
name: field.name,
|
|
318
|
-
|
|
211
|
+
jsonName: field.jsonName,
|
|
319
212
|
T: field.scalar,
|
|
320
213
|
};
|
|
321
214
|
if (field.repeated) {
|
|
@@ -333,9 +226,10 @@ function makeMessageFieldInfo(field, resolver) {
|
|
|
333
226
|
const messageType = resolver.findMessage(field.message.typeName);
|
|
334
227
|
assert(messageType, `message "${field.message.typeName}" for ${field.toString()} not found`);
|
|
335
228
|
const base = {
|
|
229
|
+
kind: "message",
|
|
336
230
|
no: field.number,
|
|
337
231
|
name: field.name,
|
|
338
|
-
|
|
232
|
+
jsonName: field.jsonName,
|
|
339
233
|
T: messageType,
|
|
340
234
|
};
|
|
341
235
|
if (field.repeated) {
|
|
@@ -353,9 +247,10 @@ function makeEnumFieldInfo(field, resolver) {
|
|
|
353
247
|
const enumType = resolver.findEnum(field.enum.typeName);
|
|
354
248
|
assert(enumType, `enum "${field.enum.typeName}" for ${field.toString()} not found`);
|
|
355
249
|
const base = {
|
|
250
|
+
kind: "enum",
|
|
356
251
|
no: field.number,
|
|
357
252
|
name: field.name,
|
|
358
|
-
|
|
253
|
+
jsonName: field.jsonName,
|
|
359
254
|
T: enumType,
|
|
360
255
|
};
|
|
361
256
|
if (field.repeated) {
|
|
@@ -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.
|
|
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], ["
|
|
1148
|
-
* "foo.(bar.baz).
|
|
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
|
*/
|
|
@@ -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.
|
|
14
|
+
// @generated by protoc-gen-es v0.1.1 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.
|
|
14
|
+
// @generated by protoc-gen-es v0.1.1 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 =
|
|
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
|
-
*
|
|
115
|
-
* [0]: minus sign?
|
|
116
|
-
* [1]: low bits
|
|
117
|
-
* [2]: high bits
|
|
114
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
118
115
|
*
|
|
119
|
-
*
|
|
116
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
120
117
|
*/
|
|
121
|
-
export function
|
|
118
|
+
export function int64FromString(dec) {
|
|
122
119
|
// Check for minus sign.
|
|
123
|
-
|
|
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
|
|
145
|
+
return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
150
|
-
*
|
|
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
|
-
*
|
|
172
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
153
173
|
*/
|
|
154
|
-
export function
|
|
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
|
-
|
|
158
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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 (
|
|
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";
|
|
@@ -34,7 +34,7 @@ export function makeBinaryFormatProto2() {
|
|
|
34
34
|
// In contrast to proto3, we raise an error if a non-optional (proto2 required)
|
|
35
35
|
// field is missing a value.
|
|
36
36
|
if (value === undefined && !field.oneof && !field.opt) {
|
|
37
|
-
throw new Error(`cannot encode field ${type.typeName}.${field.name} to
|
|
37
|
+
throw new Error(`cannot encode field ${type.typeName}.${field.name} to binary: required field not set`);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
switch (field.kind) {
|
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
}
|
package/dist/esm/proto-int64.js
CHANGED
|
@@ -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 {
|
|
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 (
|
|
73
|
-
|
|
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 (
|
|
79
|
-
|
|
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
|
|
85
|
-
|
|
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
|
-
|
|
93
|
-
return
|
|
95
|
+
assertInt64String(value);
|
|
96
|
+
return int64FromString(value);
|
|
94
97
|
},
|
|
95
98
|
uEnc(value) {
|
|
96
|
-
if (typeof value
|
|
97
|
-
|
|
98
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
99
|
-
}
|
|
99
|
+
if (typeof value != "string") {
|
|
100
|
+
value = value.toString();
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
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], ["
|
|
1337
|
-
* "foo.(bar.baz).
|
|
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
|
|
1493
|
+
* // Comment attached to moo.
|
|
1494
1494
|
* //
|
|
1495
|
-
* // Another line attached to
|
|
1496
|
-
* optional double
|
|
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
|
|
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
|
*/
|