@bufbuild/protobuf 0.0.8 → 0.0.9

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 (61) 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 +376 -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/struct_pb.js +1 -1
  8. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  9. package/dist/cjs/index.js +17 -7
  10. package/dist/cjs/{descriptor-registry.js → legacy-descriptor-registry.js} +18 -10
  11. package/dist/cjs/legacy-descriptor-set.js +453 -0
  12. package/dist/cjs/legacy-type-registry.js +104 -0
  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/names.js +168 -29
  17. package/dist/cjs/proto2.js +2 -2
  18. package/dist/cjs/proto3.js +2 -2
  19. package/dist/cjs/type-registry.js +0 -87
  20. package/dist/esm/codegen-info.js +57 -0
  21. package/dist/esm/create-descriptor-set.js +947 -0
  22. package/dist/esm/create-registry-from-desc.js +371 -0
  23. package/dist/esm/create-registry.js +71 -0
  24. package/dist/esm/descriptor-set.js +1 -434
  25. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  26. package/dist/esm/google/protobuf/type_pb.js +1 -1
  27. package/dist/esm/index.js +9 -3
  28. package/dist/esm/{descriptor-registry.js → legacy-descriptor-registry.js} +16 -8
  29. package/dist/esm/legacy-descriptor-set.js +449 -0
  30. package/dist/esm/legacy-type-registry.js +100 -0
  31. package/dist/esm/private/enum.js +22 -31
  32. package/dist/esm/private/field-wrapper.js +28 -0
  33. package/dist/esm/private/field.js +2 -2
  34. package/dist/esm/private/names.js +163 -24
  35. package/dist/esm/proto2.js +3 -3
  36. package/dist/esm/proto3.js +3 -3
  37. package/dist/esm/type-registry.js +1 -85
  38. package/dist/types/codegen-info.d.ts +19 -0
  39. package/dist/types/create-descriptor-set.d.ts +16 -0
  40. package/dist/types/create-registry-from-desc.d.ts +49 -0
  41. package/dist/types/create-registry.d.ts +8 -0
  42. package/dist/types/descriptor-set.d.ts +554 -108
  43. package/dist/types/enum.d.ts +9 -5
  44. package/dist/types/index.d.ts +9 -3
  45. package/dist/types/{descriptor-registry.d.ts → legacy-descriptor-registry.d.ts} +8 -6
  46. package/dist/types/legacy-descriptor-set.d.ts +152 -0
  47. package/dist/types/legacy-type-registry.d.ts +44 -0
  48. package/dist/types/private/enum.d.ts +4 -8
  49. package/dist/types/private/field-wrapper.d.ts +7 -0
  50. package/dist/types/private/message-type.d.ts +1 -4
  51. package/dist/types/private/names.d.ts +26 -8
  52. package/dist/types/private/proto-runtime.d.ts +2 -2
  53. package/dist/types/private/util.d.ts +1 -6
  54. package/dist/types/type-registry.d.ts +0 -38
  55. package/package.json +2 -2
  56. package/dist/protobuf.cjs +0 -2
  57. package/dist/protobuf.cjs.map +0 -1
  58. package/dist/protobuf.esm.js +0 -2
  59. package/dist/protobuf.esm.js.map +0 -1
  60. package/dist/protobuf.modern.js +0 -2
  61. package/dist/protobuf.modern.js.map +0 -1
@@ -11,437 +11,4 @@
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 { FieldDescriptorProto_Label, FieldDescriptorProto_Type, MethodOptions_IdempotencyLevel, } from "./google/protobuf/descriptor_pb.js";
15
- import { assert } from "./private/assert.js";
16
- import { ScalarType } from "./field.js";
17
- import { MethodIdempotency, MethodKind } from "./service-type.js";
18
- /**
19
- * DescriptorSet wraps a set of google.protobuf.FileDescriptorProto,
20
- * asserting basic expectations and providing hierarchical information.
21
- *
22
- * Note that all types are kept by their fully qualified type name
23
- * with a leading dot.
24
- */
25
- export class DescriptorSet {
26
- constructor() {
27
- this.enums = {};
28
- this.messages = {};
29
- this.services = {};
30
- }
31
- /**
32
- * May raise an error on invalid descriptors.
33
- */
34
- add(...files) {
35
- for (const file of files) {
36
- newFile(file, this);
37
- }
38
- }
39
- listEnums() {
40
- return Object.values(this.enums).filter(isDefined);
41
- }
42
- listMessages() {
43
- return Object.values(this.messages).filter(isDefined);
44
- }
45
- listServices() {
46
- return Object.values(this.services).filter(isDefined);
47
- }
48
- }
49
- function isDefined(v) {
50
- return v !== undefined;
51
- }
52
- const fieldTypeToScalarType = {
53
- [FieldDescriptorProto_Type.DOUBLE]: ScalarType.DOUBLE,
54
- [FieldDescriptorProto_Type.FLOAT]: ScalarType.FLOAT,
55
- [FieldDescriptorProto_Type.INT64]: ScalarType.INT64,
56
- [FieldDescriptorProto_Type.UINT64]: ScalarType.UINT64,
57
- [FieldDescriptorProto_Type.INT32]: ScalarType.INT32,
58
- [FieldDescriptorProto_Type.FIXED64]: ScalarType.FIXED64,
59
- [FieldDescriptorProto_Type.FIXED32]: ScalarType.FIXED32,
60
- [FieldDescriptorProto_Type.BOOL]: ScalarType.BOOL,
61
- [FieldDescriptorProto_Type.STRING]: ScalarType.STRING,
62
- [FieldDescriptorProto_Type.GROUP]: undefined,
63
- [FieldDescriptorProto_Type.MESSAGE]: undefined,
64
- [FieldDescriptorProto_Type.BYTES]: ScalarType.BYTES,
65
- [FieldDescriptorProto_Type.UINT32]: ScalarType.UINT32,
66
- [FieldDescriptorProto_Type.ENUM]: undefined,
67
- [FieldDescriptorProto_Type.SFIXED32]: ScalarType.SFIXED32,
68
- [FieldDescriptorProto_Type.SFIXED64]: ScalarType.SFIXED64,
69
- [FieldDescriptorProto_Type.SINT32]: ScalarType.SINT32,
70
- [FieldDescriptorProto_Type.SINT64]: ScalarType.SINT64,
71
- };
72
- function newFile(proto, ds) {
73
- assert(proto.name, `missing file descriptor name`);
74
- if (proto.syntax !== undefined && proto.syntax !== "proto3") {
75
- throw new Error(`invalid descriptor: unsupported syntax: ${proto.syntax}`);
76
- }
77
- const file = {
78
- proto,
79
- syntax: proto.syntax === "proto3" ? "proto3" : "proto2",
80
- name: proto.name.endsWith(".proto")
81
- ? proto.name.substring(-".proto".length)
82
- : proto.name,
83
- toString() {
84
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
85
- return `file ${this.proto.name}`;
86
- },
87
- };
88
- for (const messageType of proto.messageType) {
89
- newMessage(messageType, undefined, file, ds);
90
- }
91
- for (const enumType of proto.enumType) {
92
- newEnum(enumType, undefined, file, ds);
93
- }
94
- for (const extension of proto.extension) {
95
- newExtension(extension, undefined, file, ds);
96
- }
97
- for (const service of proto.service) {
98
- newService(service, file, ds);
99
- }
100
- return file;
101
- }
102
- function newEnum(proto, parent, file, us) {
103
- assert(proto.name, `invalid descriptor: missing enum descriptor name`);
104
- let protoTypeName;
105
- if (parent) {
106
- protoTypeName = `${parent.protoTypeName}.${proto.name}`;
107
- }
108
- else if (file.proto.package !== undefined) {
109
- protoTypeName = `.${file.proto.package}.${proto.name}`;
110
- }
111
- else {
112
- protoTypeName = `.${proto.name}`;
113
- }
114
- const values = [];
115
- const enumT = {
116
- proto,
117
- file,
118
- parent,
119
- name: proto.name,
120
- protoTypeName,
121
- typeName: protoTypeName.startsWith(".")
122
- ? protoTypeName.substring(1)
123
- : protoTypeName,
124
- values,
125
- toString() {
126
- return `enum ${this.typeName}`;
127
- },
128
- };
129
- us.enums[enumT.protoTypeName] = enumT;
130
- for (const value of proto.value) {
131
- values.push(newEnumValue(value, enumT));
132
- }
133
- return enumT;
134
- }
135
- function newEnumValue(proto, parent) {
136
- assert(proto.name, `invalid descriptor: missing enum value descriptor name`);
137
- assert(proto.number !== undefined, `invalid descriptor: missing enum value descriptor number`);
138
- return {
139
- proto,
140
- name: proto.name,
141
- number: proto.number,
142
- parent,
143
- toString() {
144
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
145
- return `enum value ${this.parent.typeName}.${this.proto.name}`;
146
- },
147
- };
148
- }
149
- function newMessage(proto, parent, file, us) {
150
- var _a;
151
- assert(proto.name, `invalid descriptor: missing name`);
152
- const nestedMessages = [];
153
- const fields = [];
154
- const oneofs = [];
155
- const nestedEnums = [];
156
- const nestedExtensions = [];
157
- let protoTypeName;
158
- if (parent) {
159
- protoTypeName = `${parent.protoTypeName}.${proto.name}`;
160
- }
161
- else if (file.proto.package !== undefined) {
162
- protoTypeName = `.${file.proto.package}.${proto.name}`;
163
- }
164
- else {
165
- protoTypeName = `.${proto.name}`;
166
- }
167
- const message = {
168
- proto,
169
- file,
170
- parent,
171
- name: proto.name,
172
- typeName: protoTypeName.startsWith(".")
173
- ? protoTypeName.substring(1)
174
- : protoTypeName,
175
- protoTypeName,
176
- fields,
177
- oneofs,
178
- nestedEnums,
179
- nestedMessages,
180
- nestedExtensions,
181
- toString() {
182
- return `message ${this.typeName}`;
183
- },
184
- };
185
- us.messages[message.protoTypeName] = message;
186
- for (const nestedType of proto.nestedType) {
187
- nestedMessages.push(newMessage(nestedType, message, file, us));
188
- }
189
- for (const oneofDecl of proto.oneofDecl) {
190
- oneofs.push(newOneof(oneofDecl, message, file));
191
- }
192
- for (const field of proto.field) {
193
- let oneof = undefined;
194
- if (field.oneofIndex !== undefined) {
195
- oneof = oneofs[field.oneofIndex];
196
- assert(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${(_a = field.number) !== null && _a !== void 0 ? _a : -1} not found`);
197
- }
198
- fields.push(newField(field, message, oneof));
199
- }
200
- for (const enumType of proto.enumType) {
201
- nestedEnums.push(newEnum(enumType, message, file, us));
202
- }
203
- for (const extension of proto.extension) {
204
- nestedExtensions.push(newExtension(extension, message, file, us));
205
- }
206
- return message;
207
- }
208
- function newField(proto, parent, oneof) {
209
- var _a;
210
- assert(proto.name, `invalid descriptor: missing name`);
211
- assert(proto.number, `invalid descriptor: missing number`);
212
- assert(proto.type, `invalid descriptor: missing type`);
213
- let optional = false;
214
- let packed = ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.packed) === true;
215
- switch (parent.file.syntax) {
216
- case "proto2":
217
- optional =
218
- oneof === undefined &&
219
- proto.label === FieldDescriptorProto_Label.OPTIONAL;
220
- break;
221
- case "proto3":
222
- optional = proto.proto3Optional === true;
223
- switch (proto.type) {
224
- case FieldDescriptorProto_Type.DOUBLE:
225
- case FieldDescriptorProto_Type.FLOAT:
226
- case FieldDescriptorProto_Type.INT64:
227
- case FieldDescriptorProto_Type.UINT64:
228
- case FieldDescriptorProto_Type.INT32:
229
- case FieldDescriptorProto_Type.FIXED64:
230
- case FieldDescriptorProto_Type.FIXED32:
231
- case FieldDescriptorProto_Type.UINT32:
232
- case FieldDescriptorProto_Type.SFIXED32:
233
- case FieldDescriptorProto_Type.SFIXED64:
234
- case FieldDescriptorProto_Type.SINT32:
235
- case FieldDescriptorProto_Type.SINT64:
236
- case FieldDescriptorProto_Type.BOOL:
237
- case FieldDescriptorProto_Type.ENUM:
238
- // From the proto3 language guide:
239
- // > In proto3, repeated fields of scalar numeric types are packed by default.
240
- // This information is incomplete - according to the conformance tests, BOOL
241
- // and ENUM are packed by default as well. This means only STRING and BYTES
242
- // are not packed by default, which makes sense because they are length-delimited.
243
- packed = true;
244
- break;
245
- case FieldDescriptorProto_Type.STRING:
246
- case FieldDescriptorProto_Type.GROUP:
247
- case FieldDescriptorProto_Type.MESSAGE:
248
- case FieldDescriptorProto_Type.BYTES:
249
- assert(!packed, `invalid descriptor: ${FieldDescriptorProto_Type[proto.type]} cannot be packed`);
250
- break;
251
- }
252
- break;
253
- }
254
- const field = {
255
- proto,
256
- name: proto.name,
257
- number: proto.number,
258
- type: proto.type,
259
- parent,
260
- oneof: proto.proto3Optional === true ? undefined : oneof,
261
- optional,
262
- packed,
263
- toString() {
264
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
265
- return `field ${parent.typeName}.${proto.name}`;
266
- },
267
- resolve(us) {
268
- return resolveField(this, us);
269
- },
270
- };
271
- if (oneof) {
272
- oneof.fields.push(field);
273
- }
274
- return field;
275
- }
276
- function resolveField(u, us) {
277
- var _a;
278
- const repeated = u.proto.label === FieldDescriptorProto_Label.REPEATED;
279
- switch (u.type) {
280
- case FieldDescriptorProto_Type.MESSAGE:
281
- case FieldDescriptorProto_Type.GROUP: {
282
- assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
283
- const refMessage = us.messages[u.proto.typeName];
284
- assert(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
285
- if (((_a = refMessage.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry) !== undefined) {
286
- return Object.assign(Object.assign({}, u), { repeated: false, scalarType: undefined, message: undefined, enum: undefined, map: resolveMap(refMessage, us) });
287
- }
288
- return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: refMessage, enum: undefined, map: undefined });
289
- }
290
- case FieldDescriptorProto_Type.ENUM: {
291
- assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
292
- const refEnum = us.enums[u.proto.typeName];
293
- assert(refEnum, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
294
- return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: undefined, enum: refEnum, map: undefined });
295
- }
296
- default: {
297
- const scalarType = fieldTypeToScalarType[u.type];
298
- assert(scalarType, `invalid descriptor: unable to convert google.protobuf.FieldDescriptorProto.Type ${FieldDescriptorProto_Type[u.type]} to ScalarType`);
299
- return Object.assign(Object.assign({}, u), { repeated,
300
- scalarType, message: undefined, enum: undefined, map: undefined });
301
- }
302
- }
303
- }
304
- function resolveMap(mapEntry, us) {
305
- var _a;
306
- assert((_a = mapEntry.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
307
- assert(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
308
- const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
309
- assert(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
310
- const keyField = resolveField(uKeyField, us);
311
- assert(keyField.scalarType !== undefined &&
312
- keyField.scalarType !== ScalarType.BYTES &&
313
- keyField.scalarType !== ScalarType.FLOAT &&
314
- keyField.scalarType !== ScalarType.DOUBLE, `invalid descriptor: map entry ${mapEntry.toString()} has unexpected key type ${FieldDescriptorProto_Type[keyField.type]}`);
315
- const uValueField = mapEntry.fields.find((f) => f.proto.number === 2);
316
- assert(uValueField, `invalid descriptor: map entry ${mapEntry.toString()} is missing value field`);
317
- const valueField = resolveField(uValueField, us);
318
- if (valueField.scalarType !== undefined) {
319
- return {
320
- key: keyField.scalarType,
321
- value: {
322
- scalarType: valueField.scalarType,
323
- enum: undefined,
324
- message: undefined,
325
- },
326
- };
327
- }
328
- if (valueField.enum !== undefined) {
329
- return {
330
- key: keyField.scalarType,
331
- value: { scalar: undefined, enum: valueField.enum, message: undefined },
332
- };
333
- }
334
- if (valueField.message !== undefined) {
335
- return {
336
- key: keyField.scalarType,
337
- value: {
338
- scalar: undefined,
339
- enum: undefined,
340
- message: valueField.message,
341
- },
342
- };
343
- }
344
- throw new Error(`invalid descriptor: map entry ${mapEntry.toString()} has unexpected value type ${FieldDescriptorProto_Type[keyField.type]}`);
345
- }
346
- function newOneof(proto, parent, file) {
347
- assert(proto.name, `invalid descriptor: missing oneof descriptor name`);
348
- return {
349
- proto,
350
- parent,
351
- file,
352
- fields: [],
353
- name: proto.name,
354
- toString() {
355
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
356
- return `oneof ${parent.typeName}.${proto.name}`;
357
- },
358
- };
359
- }
360
- function newExtension(proto, parent, file, us // eslint-disable-line @typescript-eslint/no-unused-vars
361
- ) {
362
- assert(proto.name, `invalid descriptor: missing field descriptor name`);
363
- return {
364
- proto,
365
- file,
366
- parent,
367
- };
368
- }
369
- function newService(proto, file, us) {
370
- assert(proto.name, `invalid descriptor: missing service descriptor name`);
371
- let protoTypeName;
372
- if (file.proto.package !== undefined) {
373
- protoTypeName = `.${file.proto.package}.${proto.name}`;
374
- }
375
- else {
376
- protoTypeName = `.${proto.name}`;
377
- }
378
- const methods = [];
379
- const service = {
380
- proto,
381
- file,
382
- typeName: protoTypeName.startsWith(".")
383
- ? protoTypeName.substring(1)
384
- : protoTypeName,
385
- protoTypeName,
386
- methods,
387
- toString() {
388
- return `service ${this.typeName}`;
389
- },
390
- };
391
- for (const method of proto.method) {
392
- methods.push(newMethod(method, service));
393
- }
394
- us.services[service.protoTypeName] = service;
395
- return service;
396
- }
397
- function newMethod(proto, parent) {
398
- var _a;
399
- assert(proto.name, `invalid descriptor: missing method descriptor name`);
400
- assert(proto.inputType, `invalid descriptor: missing method input type`);
401
- assert(proto.outputType, `invalid descriptor: missing method output type`);
402
- let kind;
403
- if (proto.clientStreaming === true && proto.serverStreaming === true) {
404
- kind = MethodKind.BiDiStreaming;
405
- }
406
- else if (proto.clientStreaming === true) {
407
- kind = MethodKind.ClientStreaming;
408
- }
409
- else if (proto.serverStreaming === true) {
410
- kind = MethodKind.ServerStreaming;
411
- }
412
- else {
413
- kind = MethodKind.Unary;
414
- }
415
- let idempotency;
416
- switch ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.idempotencyLevel) {
417
- case MethodOptions_IdempotencyLevel.IDEMPOTENT:
418
- idempotency = MethodIdempotency.Idempotent;
419
- break;
420
- case MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
421
- idempotency = MethodIdempotency.NoSideEffects;
422
- break;
423
- case MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
424
- case undefined:
425
- idempotency = undefined;
426
- break;
427
- }
428
- const inputTypeName = proto.inputType.startsWith(".")
429
- ? proto.inputType.substring(1)
430
- : proto.inputType;
431
- const outputTypeName = proto.outputType.startsWith(".")
432
- ? proto.outputType.substring(1)
433
- : proto.outputType;
434
- return {
435
- proto,
436
- parent,
437
- name: proto.name,
438
- kind,
439
- idempotency,
440
- inputTypeName,
441
- outputTypeName,
442
- toString() {
443
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
444
- return `rpc ${this.parent.typeName}.${proto.name}`;
445
- },
446
- };
447
- }
14
+ export {};
@@ -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.8 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.0.9 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.8 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.0.9 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";
package/dist/esm/index.js CHANGED
@@ -15,14 +15,20 @@ export { proto3 } from "./proto3.js";
15
15
  export { proto2 } from "./proto2.js";
16
16
  export { protoInt64 } from "./proto-int64.js";
17
17
  export { protoBase64 } from "./proto-base64.js";
18
+ export { codegenInfo } from "./codegen-info.js";
18
19
  export { Message, } from "./message.js";
19
20
  export { ScalarType } from "./field.js";
20
21
  export { MethodKind, MethodIdempotency } from "./service-type.js";
21
- export { TypeRegistry } from "./type-registry.js";
22
- export { DescriptorRegistry } from "./descriptor-registry.js";
23
- export { DescriptorSet } from "./descriptor-set.js";
24
22
  export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
25
23
  export {} from "./json-format.js";
24
+ export {} from "./descriptor-set.js";
25
+ export { createDescriptorSet } from "./create-descriptor-set.js";
26
+ export {} from "./type-registry.js";
27
+ export { createRegistry } from "./create-registry.js";
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";
26
32
  // ideally, we would export these types with sub-path exports:
27
33
  export * from "./google/protobuf/compiler/plugin_pb.js";
28
34
  export * from "./google/protobuf/api_pb.js";
@@ -11,13 +11,13 @@
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 { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
14
15
  import { assert } from "./private/assert.js";
15
16
  import { proto3 } from "./proto3.js";
16
17
  import { proto2 } from "./proto2.js";
17
18
  import { ScalarType } from "./field.js";
18
- import { DescriptorSet } from "./descriptor-set.js";
19
+ import { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
19
20
  import { protoInt64 } from "./proto-int64.js";
20
- import { makeMethodName } from "./private/names.js";
21
21
  import { Timestamp } from "./google/protobuf/timestamp_pb.js";
22
22
  import { Duration } from "./google/protobuf/duration_pb.js";
23
23
  import { Any } from "./google/protobuf/any_pb.js";
@@ -26,7 +26,6 @@ import { FieldMask } from "./google/protobuf/field_mask_pb.js";
26
26
  import { ListValue, NullValue, Struct, Value, } from "./google/protobuf/struct_pb.js";
27
27
  import { getEnumType } from "./private/enum.js";
28
28
  import { BoolValue, BytesValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, UInt32Value, UInt64Value, } from "./google/protobuf/wrappers_pb.js";
29
- import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
30
29
  // well-known message types with specialized JSON representation
31
30
  const wkMessages = [
32
31
  Any,
@@ -51,18 +50,20 @@ const wkMessages = [
51
50
  // well-known enum types with specialized JSON representation
52
51
  const wkEnums = [getEnumType(NullValue)];
53
52
  /**
54
- * DescriptorRegistry is a type registry that dynamically creates types
53
+ * LegacyDescriptorRegistry is a type registry that dynamically creates types
55
54
  * from a set of google.protobuf.FileDescriptorProto.
56
55
  *
57
56
  * By default, all well-known types with a specialized JSON representation
58
57
  * are replaced with their generated counterpart in this package.
58
+ *
59
+ * @deprecated
59
60
  */
60
- export class DescriptorRegistry {
61
+ export class LegacyDescriptorRegistry {
61
62
  constructor(descriptorSet, replaceWkt = true) {
62
63
  this.enums = {};
63
64
  this.messages = {};
64
65
  this.services = {};
65
- this.ds = descriptorSet !== null && descriptorSet !== void 0 ? descriptorSet : new DescriptorSet();
66
+ this.ds = descriptorSet !== null && descriptorSet !== void 0 ? descriptorSet : new LegacyDescriptorSet();
66
67
  if (replaceWkt) {
67
68
  for (const mt of wkMessages) {
68
69
  this.messages["." + mt.typeName] = mt;
@@ -80,7 +81,7 @@ export class DescriptorRegistry {
80
81
  const set = bytesOrSet instanceof Uint8Array
81
82
  ? FileDescriptorSet.fromBinary(bytesOrSet)
82
83
  : new FileDescriptorSet(bytesOrSet);
83
- const dr = new DescriptorRegistry();
84
+ const dr = new LegacyDescriptorRegistry();
84
85
  dr.add(...set.file);
85
86
  return dr;
86
87
  }
@@ -107,6 +108,7 @@ export class DescriptorRegistry {
107
108
  const type = runtime.makeEnumType(typeName, raw.values.map((u) => ({
108
109
  no: u.number,
109
110
  name: u.name,
111
+ localName: u.name,
110
112
  })), {});
111
113
  this.enums[protoTypeName] = type;
112
114
  return type;
@@ -157,7 +159,7 @@ export class DescriptorRegistry {
157
159
  assert(ot, `output message "${u.outputTypeName}" for ${u.toString()} not found`);
158
160
  const m = {
159
161
  name: u.name,
160
- localName: makeMethodName(u.name),
162
+ localName: localMethodName(u.name),
161
163
  I: it,
162
164
  O: ot,
163
165
  kind: u.kind,
@@ -172,6 +174,12 @@ export class DescriptorRegistry {
172
174
  });
173
175
  }
174
176
  }
177
+ function localMethodName(protoName) {
178
+ if (protoName.length == 0) {
179
+ return protoName;
180
+ }
181
+ return protoName[0].toLowerCase() + protoName.substring(1);
182
+ }
175
183
  function makeTypeLocalName(type) {
176
184
  var _a;
177
185
  const typeName = type.typeName;