@bufbuild/protobuf 0.0.8 → 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 (70) hide show
  1. package/README.md +34 -4
  2. package/dist/cjs/codegen-info.js +60 -0
  3. package/dist/cjs/create-descriptor-set.js +952 -0
  4. package/dist/cjs/create-registry-from-desc.js +270 -0
  5. package/dist/cjs/create-registry.js +75 -0
  6. package/dist/cjs/descriptor-set.js +0 -436
  7. package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
  8. package/dist/cjs/google/protobuf/empty_pb.js +0 -1
  9. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  10. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  11. package/dist/cjs/google/varint.js +85 -37
  12. package/dist/cjs/index.js +11 -7
  13. package/dist/cjs/private/enum.js +22 -31
  14. package/dist/cjs/private/field-wrapper.js +30 -1
  15. package/dist/cjs/private/field.js +1 -1
  16. package/dist/cjs/private/json-format-common.js +6 -6
  17. package/dist/cjs/private/names.js +168 -29
  18. package/dist/cjs/proto-int64.js +23 -40
  19. package/dist/cjs/proto2.js +2 -2
  20. package/dist/cjs/proto3.js +2 -2
  21. package/dist/cjs/type-registry.js +0 -87
  22. package/dist/esm/codegen-info.js +57 -0
  23. package/dist/esm/create-descriptor-set.js +947 -0
  24. package/dist/esm/create-registry-from-desc.js +266 -0
  25. package/dist/esm/create-registry.js +71 -0
  26. package/dist/esm/descriptor-set.js +1 -434
  27. package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
  28. package/dist/esm/google/protobuf/empty_pb.js +0 -1
  29. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  30. package/dist/esm/google/protobuf/type_pb.js +1 -1
  31. package/dist/esm/google/varint.js +81 -34
  32. package/dist/esm/index.js +6 -3
  33. package/dist/esm/private/enum.js +22 -31
  34. package/dist/esm/private/field-wrapper.js +28 -0
  35. package/dist/esm/private/field.js +2 -2
  36. package/dist/esm/private/json-format-common.js +6 -6
  37. package/dist/esm/private/names.js +163 -24
  38. package/dist/esm/proto-int64.js +24 -41
  39. package/dist/esm/proto2.js +3 -3
  40. package/dist/esm/proto3.js +3 -3
  41. package/dist/esm/type-registry.js +1 -85
  42. package/dist/types/codegen-info.d.ts +19 -0
  43. package/dist/types/create-descriptor-set.d.ts +16 -0
  44. package/dist/types/create-registry-from-desc.d.ts +15 -0
  45. package/dist/types/create-registry.d.ts +8 -0
  46. package/dist/types/descriptor-set.d.ts +554 -108
  47. package/dist/types/enum.d.ts +9 -5
  48. package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
  49. package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
  50. package/dist/types/google/varint.d.ts +21 -9
  51. package/dist/types/index.d.ts +6 -3
  52. package/dist/types/message.d.ts +3 -1
  53. package/dist/types/private/enum.d.ts +4 -8
  54. package/dist/types/private/field-wrapper.d.ts +7 -0
  55. package/dist/types/private/message-type.d.ts +1 -4
  56. package/dist/types/private/names.d.ts +26 -8
  57. package/dist/types/private/proto-runtime.d.ts +2 -2
  58. package/dist/types/private/util.d.ts +1 -6
  59. package/dist/types/proto-int64.d.ts +14 -13
  60. package/dist/types/type-registry.d.ts +0 -38
  61. package/package.json +6 -10
  62. package/dist/cjs/descriptor-registry.js +0 -460
  63. package/dist/esm/descriptor-registry.js +0 -456
  64. package/dist/protobuf.cjs +0 -2
  65. package/dist/protobuf.cjs.map +0 -1
  66. package/dist/protobuf.esm.js +0 -2
  67. package/dist/protobuf.esm.js.map +0 -1
  68. package/dist/protobuf.modern.js +0 -2
  69. package/dist/protobuf.modern.js.map +0 -1
  70. package/dist/types/descriptor-registry.d.ts +0 -43
@@ -13,439 +13,3 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.DescriptorSet = void 0;
17
- const descriptor_pb_js_1 = require("./google/protobuf/descriptor_pb.js");
18
- const assert_js_1 = require("./private/assert.js");
19
- const field_js_1 = require("./field.js");
20
- const service_type_js_1 = require("./service-type.js");
21
- /**
22
- * DescriptorSet wraps a set of google.protobuf.FileDescriptorProto,
23
- * asserting basic expectations and providing hierarchical information.
24
- *
25
- * Note that all types are kept by their fully qualified type name
26
- * with a leading dot.
27
- */
28
- class DescriptorSet {
29
- constructor() {
30
- this.enums = {};
31
- this.messages = {};
32
- this.services = {};
33
- }
34
- /**
35
- * May raise an error on invalid descriptors.
36
- */
37
- add(...files) {
38
- for (const file of files) {
39
- newFile(file, this);
40
- }
41
- }
42
- listEnums() {
43
- return Object.values(this.enums).filter(isDefined);
44
- }
45
- listMessages() {
46
- return Object.values(this.messages).filter(isDefined);
47
- }
48
- listServices() {
49
- return Object.values(this.services).filter(isDefined);
50
- }
51
- }
52
- exports.DescriptorSet = DescriptorSet;
53
- function isDefined(v) {
54
- return v !== undefined;
55
- }
56
- const fieldTypeToScalarType = {
57
- [descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE]: field_js_1.ScalarType.DOUBLE,
58
- [descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT]: field_js_1.ScalarType.FLOAT,
59
- [descriptor_pb_js_1.FieldDescriptorProto_Type.INT64]: field_js_1.ScalarType.INT64,
60
- [descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64]: field_js_1.ScalarType.UINT64,
61
- [descriptor_pb_js_1.FieldDescriptorProto_Type.INT32]: field_js_1.ScalarType.INT32,
62
- [descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64]: field_js_1.ScalarType.FIXED64,
63
- [descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32]: field_js_1.ScalarType.FIXED32,
64
- [descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL]: field_js_1.ScalarType.BOOL,
65
- [descriptor_pb_js_1.FieldDescriptorProto_Type.STRING]: field_js_1.ScalarType.STRING,
66
- [descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP]: undefined,
67
- [descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE]: undefined,
68
- [descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES]: field_js_1.ScalarType.BYTES,
69
- [descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32]: field_js_1.ScalarType.UINT32,
70
- [descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM]: undefined,
71
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32]: field_js_1.ScalarType.SFIXED32,
72
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64]: field_js_1.ScalarType.SFIXED64,
73
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32]: field_js_1.ScalarType.SINT32,
74
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64]: field_js_1.ScalarType.SINT64,
75
- };
76
- function newFile(proto, ds) {
77
- (0, assert_js_1.assert)(proto.name, `missing file descriptor name`);
78
- if (proto.syntax !== undefined && proto.syntax !== "proto3") {
79
- throw new Error(`invalid descriptor: unsupported syntax: ${proto.syntax}`);
80
- }
81
- const file = {
82
- proto,
83
- syntax: proto.syntax === "proto3" ? "proto3" : "proto2",
84
- name: proto.name.endsWith(".proto")
85
- ? proto.name.substring(-".proto".length)
86
- : proto.name,
87
- toString() {
88
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
89
- return `file ${this.proto.name}`;
90
- },
91
- };
92
- for (const messageType of proto.messageType) {
93
- newMessage(messageType, undefined, file, ds);
94
- }
95
- for (const enumType of proto.enumType) {
96
- newEnum(enumType, undefined, file, ds);
97
- }
98
- for (const extension of proto.extension) {
99
- newExtension(extension, undefined, file, ds);
100
- }
101
- for (const service of proto.service) {
102
- newService(service, file, ds);
103
- }
104
- return file;
105
- }
106
- function newEnum(proto, parent, file, us) {
107
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing enum descriptor name`);
108
- let protoTypeName;
109
- if (parent) {
110
- protoTypeName = `${parent.protoTypeName}.${proto.name}`;
111
- }
112
- else if (file.proto.package !== undefined) {
113
- protoTypeName = `.${file.proto.package}.${proto.name}`;
114
- }
115
- else {
116
- protoTypeName = `.${proto.name}`;
117
- }
118
- const values = [];
119
- const enumT = {
120
- proto,
121
- file,
122
- parent,
123
- name: proto.name,
124
- protoTypeName,
125
- typeName: protoTypeName.startsWith(".")
126
- ? protoTypeName.substring(1)
127
- : protoTypeName,
128
- values,
129
- toString() {
130
- return `enum ${this.typeName}`;
131
- },
132
- };
133
- us.enums[enumT.protoTypeName] = enumT;
134
- for (const value of proto.value) {
135
- values.push(newEnumValue(value, enumT));
136
- }
137
- return enumT;
138
- }
139
- function newEnumValue(proto, parent) {
140
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing enum value descriptor name`);
141
- (0, assert_js_1.assert)(proto.number !== undefined, `invalid descriptor: missing enum value descriptor number`);
142
- return {
143
- proto,
144
- name: proto.name,
145
- number: proto.number,
146
- parent,
147
- toString() {
148
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
149
- return `enum value ${this.parent.typeName}.${this.proto.name}`;
150
- },
151
- };
152
- }
153
- function newMessage(proto, parent, file, us) {
154
- var _a;
155
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing name`);
156
- const nestedMessages = [];
157
- const fields = [];
158
- const oneofs = [];
159
- const nestedEnums = [];
160
- const nestedExtensions = [];
161
- let protoTypeName;
162
- if (parent) {
163
- protoTypeName = `${parent.protoTypeName}.${proto.name}`;
164
- }
165
- else if (file.proto.package !== undefined) {
166
- protoTypeName = `.${file.proto.package}.${proto.name}`;
167
- }
168
- else {
169
- protoTypeName = `.${proto.name}`;
170
- }
171
- const message = {
172
- proto,
173
- file,
174
- parent,
175
- name: proto.name,
176
- typeName: protoTypeName.startsWith(".")
177
- ? protoTypeName.substring(1)
178
- : protoTypeName,
179
- protoTypeName,
180
- fields,
181
- oneofs,
182
- nestedEnums,
183
- nestedMessages,
184
- nestedExtensions,
185
- toString() {
186
- return `message ${this.typeName}`;
187
- },
188
- };
189
- us.messages[message.protoTypeName] = message;
190
- for (const nestedType of proto.nestedType) {
191
- nestedMessages.push(newMessage(nestedType, message, file, us));
192
- }
193
- for (const oneofDecl of proto.oneofDecl) {
194
- oneofs.push(newOneof(oneofDecl, message, file));
195
- }
196
- for (const field of proto.field) {
197
- let oneof = undefined;
198
- if (field.oneofIndex !== undefined) {
199
- oneof = oneofs[field.oneofIndex];
200
- (0, assert_js_1.assert)(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${(_a = field.number) !== null && _a !== void 0 ? _a : -1} not found`);
201
- }
202
- fields.push(newField(field, message, oneof));
203
- }
204
- for (const enumType of proto.enumType) {
205
- nestedEnums.push(newEnum(enumType, message, file, us));
206
- }
207
- for (const extension of proto.extension) {
208
- nestedExtensions.push(newExtension(extension, message, file, us));
209
- }
210
- return message;
211
- }
212
- function newField(proto, parent, oneof) {
213
- var _a;
214
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing name`);
215
- (0, assert_js_1.assert)(proto.number, `invalid descriptor: missing number`);
216
- (0, assert_js_1.assert)(proto.type, `invalid descriptor: missing type`);
217
- let optional = false;
218
- let packed = ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.packed) === true;
219
- switch (parent.file.syntax) {
220
- case "proto2":
221
- optional =
222
- oneof === undefined &&
223
- proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.OPTIONAL;
224
- break;
225
- case "proto3":
226
- optional = proto.proto3Optional === true;
227
- switch (proto.type) {
228
- case descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE:
229
- case descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT:
230
- case descriptor_pb_js_1.FieldDescriptorProto_Type.INT64:
231
- case descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64:
232
- case descriptor_pb_js_1.FieldDescriptorProto_Type.INT32:
233
- case descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64:
234
- case descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32:
235
- case descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32:
236
- case descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32:
237
- case descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64:
238
- case descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32:
239
- case descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64:
240
- case descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL:
241
- case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM:
242
- // From the proto3 language guide:
243
- // > In proto3, repeated fields of scalar numeric types are packed by default.
244
- // This information is incomplete - according to the conformance tests, BOOL
245
- // and ENUM are packed by default as well. This means only STRING and BYTES
246
- // are not packed by default, which makes sense because they are length-delimited.
247
- packed = true;
248
- break;
249
- case descriptor_pb_js_1.FieldDescriptorProto_Type.STRING:
250
- case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP:
251
- case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
252
- case descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES:
253
- (0, assert_js_1.assert)(!packed, `invalid descriptor: ${descriptor_pb_js_1.FieldDescriptorProto_Type[proto.type]} cannot be packed`);
254
- break;
255
- }
256
- break;
257
- }
258
- const field = {
259
- proto,
260
- name: proto.name,
261
- number: proto.number,
262
- type: proto.type,
263
- parent,
264
- oneof: proto.proto3Optional === true ? undefined : oneof,
265
- optional,
266
- packed,
267
- toString() {
268
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
269
- return `field ${parent.typeName}.${proto.name}`;
270
- },
271
- resolve(us) {
272
- return resolveField(this, us);
273
- },
274
- };
275
- if (oneof) {
276
- oneof.fields.push(field);
277
- }
278
- return field;
279
- }
280
- function resolveField(u, us) {
281
- var _a;
282
- const repeated = u.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REPEATED;
283
- switch (u.type) {
284
- case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
285
- case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP: {
286
- (0, assert_js_1.assert)(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${descriptor_pb_js_1.FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
287
- const refMessage = us.messages[u.proto.typeName];
288
- (0, assert_js_1.assert)(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
289
- if (((_a = refMessage.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry) !== undefined) {
290
- return Object.assign(Object.assign({}, u), { repeated: false, scalarType: undefined, message: undefined, enum: undefined, map: resolveMap(refMessage, us) });
291
- }
292
- return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: refMessage, enum: undefined, map: undefined });
293
- }
294
- case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM: {
295
- (0, assert_js_1.assert)(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${descriptor_pb_js_1.FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
296
- const refEnum = us.enums[u.proto.typeName];
297
- (0, assert_js_1.assert)(refEnum, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
298
- return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: undefined, enum: refEnum, map: undefined });
299
- }
300
- default: {
301
- const scalarType = fieldTypeToScalarType[u.type];
302
- (0, assert_js_1.assert)(scalarType, `invalid descriptor: unable to convert google.protobuf.FieldDescriptorProto.Type ${descriptor_pb_js_1.FieldDescriptorProto_Type[u.type]} to ScalarType`);
303
- return Object.assign(Object.assign({}, u), { repeated,
304
- scalarType, message: undefined, enum: undefined, map: undefined });
305
- }
306
- }
307
- }
308
- function resolveMap(mapEntry, us) {
309
- var _a;
310
- (0, assert_js_1.assert)((_a = mapEntry.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
311
- (0, assert_js_1.assert)(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
312
- const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
313
- (0, assert_js_1.assert)(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
314
- const keyField = resolveField(uKeyField, us);
315
- (0, assert_js_1.assert)(keyField.scalarType !== undefined &&
316
- keyField.scalarType !== field_js_1.ScalarType.BYTES &&
317
- keyField.scalarType !== field_js_1.ScalarType.FLOAT &&
318
- keyField.scalarType !== field_js_1.ScalarType.DOUBLE, `invalid descriptor: map entry ${mapEntry.toString()} has unexpected key type ${descriptor_pb_js_1.FieldDescriptorProto_Type[keyField.type]}`);
319
- const uValueField = mapEntry.fields.find((f) => f.proto.number === 2);
320
- (0, assert_js_1.assert)(uValueField, `invalid descriptor: map entry ${mapEntry.toString()} is missing value field`);
321
- const valueField = resolveField(uValueField, us);
322
- if (valueField.scalarType !== undefined) {
323
- return {
324
- key: keyField.scalarType,
325
- value: {
326
- scalarType: valueField.scalarType,
327
- enum: undefined,
328
- message: undefined,
329
- },
330
- };
331
- }
332
- if (valueField.enum !== undefined) {
333
- return {
334
- key: keyField.scalarType,
335
- value: { scalar: undefined, enum: valueField.enum, message: undefined },
336
- };
337
- }
338
- if (valueField.message !== undefined) {
339
- return {
340
- key: keyField.scalarType,
341
- value: {
342
- scalar: undefined,
343
- enum: undefined,
344
- message: valueField.message,
345
- },
346
- };
347
- }
348
- throw new Error(`invalid descriptor: map entry ${mapEntry.toString()} has unexpected value type ${descriptor_pb_js_1.FieldDescriptorProto_Type[keyField.type]}`);
349
- }
350
- function newOneof(proto, parent, file) {
351
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing oneof descriptor name`);
352
- return {
353
- proto,
354
- parent,
355
- file,
356
- fields: [],
357
- name: proto.name,
358
- toString() {
359
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
360
- return `oneof ${parent.typeName}.${proto.name}`;
361
- },
362
- };
363
- }
364
- function newExtension(proto, parent, file, us // eslint-disable-line @typescript-eslint/no-unused-vars
365
- ) {
366
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing field descriptor name`);
367
- return {
368
- proto,
369
- file,
370
- parent,
371
- };
372
- }
373
- function newService(proto, file, us) {
374
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing service descriptor name`);
375
- let protoTypeName;
376
- if (file.proto.package !== undefined) {
377
- protoTypeName = `.${file.proto.package}.${proto.name}`;
378
- }
379
- else {
380
- protoTypeName = `.${proto.name}`;
381
- }
382
- const methods = [];
383
- const service = {
384
- proto,
385
- file,
386
- typeName: protoTypeName.startsWith(".")
387
- ? protoTypeName.substring(1)
388
- : protoTypeName,
389
- protoTypeName,
390
- methods,
391
- toString() {
392
- return `service ${this.typeName}`;
393
- },
394
- };
395
- for (const method of proto.method) {
396
- methods.push(newMethod(method, service));
397
- }
398
- us.services[service.protoTypeName] = service;
399
- return service;
400
- }
401
- function newMethod(proto, parent) {
402
- var _a;
403
- (0, assert_js_1.assert)(proto.name, `invalid descriptor: missing method descriptor name`);
404
- (0, assert_js_1.assert)(proto.inputType, `invalid descriptor: missing method input type`);
405
- (0, assert_js_1.assert)(proto.outputType, `invalid descriptor: missing method output type`);
406
- let kind;
407
- if (proto.clientStreaming === true && proto.serverStreaming === true) {
408
- kind = service_type_js_1.MethodKind.BiDiStreaming;
409
- }
410
- else if (proto.clientStreaming === true) {
411
- kind = service_type_js_1.MethodKind.ClientStreaming;
412
- }
413
- else if (proto.serverStreaming === true) {
414
- kind = service_type_js_1.MethodKind.ServerStreaming;
415
- }
416
- else {
417
- kind = service_type_js_1.MethodKind.Unary;
418
- }
419
- let idempotency;
420
- switch ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.idempotencyLevel) {
421
- case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENT:
422
- idempotency = service_type_js_1.MethodIdempotency.Idempotent;
423
- break;
424
- case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
425
- idempotency = service_type_js_1.MethodIdempotency.NoSideEffects;
426
- break;
427
- case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
428
- case undefined:
429
- idempotency = undefined;
430
- break;
431
- }
432
- const inputTypeName = proto.inputType.startsWith(".")
433
- ? proto.inputType.substring(1)
434
- : proto.inputType;
435
- const outputTypeName = proto.outputType.startsWith(".")
436
- ? proto.outputType.substring(1)
437
- : proto.outputType;
438
- return {
439
- proto,
440
- parent,
441
- name: proto.name,
442
- kind,
443
- idempotency,
444
- inputTypeName,
445
- outputTypeName,
446
- toString() {
447
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
448
- return `rpc ${this.parent.typeName}.${proto.name}`;
449
- },
450
- };
451
- }
@@ -1169,8 +1169,8 @@ UninterpretedOption.fields = proto2_js_1.proto2.util.newFieldList(() => [
1169
1169
  * The name of the uninterpreted option. Each string represents a segment in
1170
1170
  * a dot-separated name. is_extension is true iff a segment represents an
1171
1171
  * extension (denoted with parentheses in options specs in .proto files).
1172
- * E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
1173
- * "foo.(bar.baz).qux".
1172
+ * E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
1173
+ * "foo.(bar.baz).moo".
1174
1174
  *
1175
1175
  * @generated from message google.protobuf.UninterpretedOption.NamePart
1176
1176
  */
@@ -25,7 +25,6 @@ const proto3_js_1 = require("../../proto3.js");
25
25
  * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
26
26
  * }
27
27
  *
28
- * The JSON representation for `Empty` is empty JSON object `{}`.
29
28
  *
30
29
  * @generated from message google.protobuf.Empty
31
30
  */
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
17
- // @generated by protoc-gen-es v0.0.8 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
17
- // @generated by protoc-gen-es v0.0.8 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.1.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -32,7 +32,7 @@
32
32
  // standalone and requires a support library to be linked with it. This
33
33
  // support library is itself covered by the above license.
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.varint32read = exports.varint32write = exports.int64toString = exports.int64fromString = exports.varint64write = exports.varint64read = void 0;
35
+ exports.varint32read = exports.varint32write = exports.uInt64ToString = exports.int64ToString = exports.int64FromString = exports.varint64write = exports.varint64read = void 0;
36
36
  /* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
37
37
  /**
38
38
  * Read a 64 bit varint as two JS numbers.
@@ -112,22 +112,20 @@ function varint64write(lo, hi, bytes) {
112
112
  }
113
113
  exports.varint64write = varint64write;
114
114
  // constants for binary math
115
- const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
115
+ const TWO_PWR_32_DBL = 0x100000000;
116
116
  /**
117
117
  * Parse decimal string of 64 bit integer value as two JS numbers.
118
118
  *
119
- * Returns tuple:
120
- * [0]: minus sign?
121
- * [1]: low bits
122
- * [2]: high bits
119
+ * Copyright 2008 Google Inc. All rights reserved.
123
120
  *
124
- * Copyright 2008 Google Inc.
121
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
125
122
  */
126
- function int64fromString(dec) {
123
+ function int64FromString(dec) {
127
124
  // Check for minus sign.
128
- let minus = dec[0] == "-";
129
- if (minus)
125
+ const minus = dec[0] === "-";
126
+ if (minus) {
130
127
  dec = dec.slice(1);
128
+ }
131
129
  // Work 6 decimal digits at a time, acting like we're converting base 1e6
132
130
  // digits to binary. This is safe to do with floating point math because
133
131
  // Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
@@ -149,19 +147,47 @@ function int64fromString(dec) {
149
147
  add1e6digit(-18, -12);
150
148
  add1e6digit(-12, -6);
151
149
  add1e6digit(-6);
152
- return [minus, lowBits, highBits];
150
+ return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
153
151
  }
154
- exports.int64fromString = int64fromString;
152
+ exports.int64FromString = int64FromString;
155
153
  /**
156
- * Format 64 bit integer value (as two JS numbers) to decimal string.
154
+ * Losslessly converts a 64-bit signed integer in 32:32 split representation
155
+ * into a decimal string.
156
+ *
157
+ * Copyright 2008 Google Inc. All rights reserved.
158
+ *
159
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
160
+ */
161
+ function int64ToString(lo, hi) {
162
+ let bits = newBits(lo, hi);
163
+ // If we're treating the input as a signed value and the high bit is set, do
164
+ // a manual two's complement conversion before the decimal conversion.
165
+ const negative = (bits.hi & 0x80000000);
166
+ if (negative) {
167
+ bits = negate(bits.lo, bits.hi);
168
+ }
169
+ const result = uInt64ToString(bits.lo, bits.hi);
170
+ return negative ? "-" + result : result;
171
+ }
172
+ exports.int64ToString = int64ToString;
173
+ /**
174
+ * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
175
+ * into a decimal string.
176
+ *
177
+ * Copyright 2008 Google Inc. All rights reserved.
157
178
  *
158
- * Copyright 2008 Google Inc.
179
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
159
180
  */
160
- function int64toString(bitsLow, bitsHigh) {
181
+ function uInt64ToString(lo, hi) {
182
+ ({ lo, hi } = toUnsigned(lo, hi));
161
183
  // Skip the expensive conversion if the number is small enough to use the
162
184
  // built-in conversions.
163
- if (bitsHigh <= 0x1fffff) {
164
- return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
185
+ // Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
186
+ // highBits <= 0x1FFFFF can be safely expressed with a double and retain
187
+ // integer precision.
188
+ // Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
189
+ if (hi <= 0x1FFFFF) {
190
+ return String(TWO_PWR_32_DBL * hi + lo);
165
191
  }
166
192
  // What this code is doing is essentially converting the input number from
167
193
  // base-2 to base-1e7, which allows us to represent the 64-bit range with
@@ -172,17 +198,17 @@ function int64toString(bitsLow, bitsHigh) {
172
198
  // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
173
199
  // Split 32:32 representation into 16:24:24 representation so our
174
200
  // 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;
201
+ const low = lo & 0xFFFFFF;
202
+ const mid = ((lo >>> 24) | (hi << 8)) & 0xFFFFFF;
203
+ const high = (hi >> 16) & 0xFFFF;
178
204
  // Assemble our three base-1e7 digits, ignoring carries. The maximum
179
205
  // value in a digit at this step is representable as a 48-bit integer, which
180
206
  // 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;
207
+ let digitA = low + (mid * 6777216) + (high * 6710656);
208
+ let digitB = mid + (high * 8147497);
209
+ let digitC = (high * 2);
184
210
  // Apply carries from A to B and from B to C.
185
- let base = 10000000;
211
+ const base = 10000000;
186
212
  if (digitA >= base) {
187
213
  digitB += Math.floor(digitA / base);
188
214
  digitA %= base;
@@ -191,21 +217,43 @@ function int64toString(bitsLow, bitsHigh) {
191
217
  digitC += Math.floor(digitB / base);
192
218
  digitB %= base;
193
219
  }
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;
220
+ // If digitC is 0, then we should have returned in the trivial code path
221
+ // at the top for non-safe integers. Given this, we can assume both digitB
222
+ // and digitA need leading zeros.
223
+ return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) +
224
+ decimalFrom1e7WithLeadingZeros(digitA);
225
+ }
226
+ exports.uInt64ToString = uInt64ToString;
227
+ function toUnsigned(lo, hi) {
228
+ return { lo: lo >>> 0, hi: hi >>> 0 };
229
+ }
230
+ function newBits(lo, hi) {
231
+ return { lo: lo | 0, hi: hi | 0 };
232
+ }
233
+ /**
234
+ * Returns two's compliment negation of input.
235
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
236
+ */
237
+ function negate(lowBits, highBits) {
238
+ highBits = ~highBits;
239
+ if (lowBits) {
240
+ lowBits = ~lowBits + 1;
241
+ }
242
+ else {
243
+ // If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
244
+ // adding 1 to that, results in 0x100000000, which leaves
245
+ // the low bits 0x0 and simply adds one to the high bits.
246
+ highBits += 1;
201
247
  }
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));
248
+ return newBits(lowBits, highBits);
207
249
  }
208
- exports.int64toString = int64toString;
250
+ /**
251
+ * Returns decimal representation of digit1e7 with leading zeros.
252
+ */
253
+ const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
254
+ const partial = String(digit1e7);
255
+ return "0000000".slice(partial.length) + partial;
256
+ };
209
257
  /**
210
258
  * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
211
259
  *