@bufbuild/protobuf 0.1.1 → 0.2.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.
@@ -440,24 +440,24 @@ function newField(proto, file, parent, oneof, cart) {
440
440
  const mapEntry = cart.mapEntries.get(trimLeadingDot(proto.typeName));
441
441
  if (mapEntry !== undefined) {
442
442
  (0, assert_js_1.assert)(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
443
- return Object.assign(Object.assign(Object.assign({}, common), { kind: "map_field", repeated: false }), getMapFieldTypes(mapEntry));
443
+ return Object.assign(Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "map", repeated: false }), getMapFieldTypes(mapEntry));
444
444
  }
445
445
  const message = cart.messages.get(trimLeadingDot(proto.typeName));
446
446
  (0, assert_js_1.assert)(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
447
- return Object.assign(Object.assign({}, common), { kind: "message_field", repeated,
447
+ return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "message", repeated,
448
448
  message });
449
449
  }
450
450
  case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM: {
451
451
  (0, assert_js_1.assert)(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
452
452
  const e = cart.enums.get(trimLeadingDot(proto.typeName));
453
453
  (0, assert_js_1.assert)(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
454
- return Object.assign(Object.assign({}, common), { kind: "enum_field", getDefaultValue,
454
+ return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "enum", getDefaultValue,
455
455
  repeated, enum: e });
456
456
  }
457
457
  default: {
458
458
  const scalar = fieldTypeToScalarType[proto.type];
459
459
  (0, assert_js_1.assert)(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
460
- return Object.assign(Object.assign({}, common), { kind: "scalar_field", getDefaultValue,
460
+ return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "scalar", getDefaultValue,
461
461
  repeated,
462
462
  scalar });
463
463
  }
@@ -472,7 +472,7 @@ function newExtension(proto, file, parent, cart) {
472
472
  undefined, cart);
473
473
  const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
474
474
  (0, assert_js_1.assert)(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
475
- return Object.assign(Object.assign({}, field), { typeName: makeTypeName(proto, parent, file), parent,
475
+ return Object.assign(Object.assign({}, field), { kind: "extension", typeName: makeTypeName(proto, parent, file), parent,
476
476
  file,
477
477
  extendee,
478
478
  toString() {
@@ -541,18 +541,18 @@ function getMapFieldTypes(mapEntry) {
541
541
  mapKey !== field_js_1.ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${(_b = keyField.proto.type) !== null && _b !== void 0 ? _b : -1}`);
542
542
  const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
543
543
  (0, assert_js_1.assert)(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
544
- switch (valueField.kind) {
545
- case "scalar_field":
544
+ switch (valueField.fieldKind) {
545
+ case "scalar":
546
546
  return {
547
547
  mapKey,
548
548
  mapValue: Object.assign(Object.assign({}, valueField), { kind: "scalar" }),
549
549
  };
550
- case "message_field":
550
+ case "message":
551
551
  return {
552
552
  mapKey,
553
553
  mapValue: Object.assign(Object.assign({}, valueField), { kind: "message" }),
554
554
  };
555
- case "enum_field":
555
+ case "enum":
556
556
  return {
557
557
  mapKey,
558
558
  mapValue: Object.assign(Object.assign({}, valueField), { kind: "enum" }),
@@ -711,23 +711,23 @@ function declarationString() {
711
711
  if (this.optional) {
712
712
  parts.push("optional");
713
713
  }
714
- const file = "extendee" in this ? this.file : this.parent.file;
714
+ const file = this.kind === "extension" ? this.file : this.parent.file;
715
715
  if (file.syntax == "proto2" &&
716
716
  this.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED) {
717
717
  parts.push("required");
718
718
  }
719
719
  let type;
720
- switch (this.kind) {
721
- case "scalar_field":
720
+ switch (this.fieldKind) {
721
+ case "scalar":
722
722
  type = field_js_1.ScalarType[this.scalar].toLowerCase();
723
723
  break;
724
- case "enum_field":
724
+ case "enum":
725
725
  type = this.enum.typeName;
726
726
  break;
727
- case "message_field":
727
+ case "message":
728
728
  type = this.message.typeName;
729
729
  break;
730
- case "map_field": {
730
+ case "map": {
731
731
  const k = field_js_1.ScalarType[this.mapKey].toLowerCase();
732
732
  let v;
733
733
  switch (this.mapValue.kind) {
@@ -777,13 +777,13 @@ function getDefaultValue() {
777
777
  if (d === undefined) {
778
778
  return undefined;
779
779
  }
780
- switch (this.kind) {
781
- case "enum_field": {
780
+ switch (this.fieldKind) {
781
+ case "enum": {
782
782
  const enumValue = this.enum.values.find((v) => v.name === d);
783
783
  (0, assert_js_1.assert)(enumValue, `cannot parse ${this.toString()} default value: ${d}`);
784
784
  return enumValue.number;
785
785
  }
786
- case "scalar_field":
786
+ case "scalar":
787
787
  switch (this.scalar) {
788
788
  case field_js_1.ScalarType.STRING:
789
789
  return d;
@@ -161,17 +161,17 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
161
161
  }
162
162
  exports.createRegistryFromDescriptors = createRegistryFromDescriptors;
163
163
  function makeFieldInfo(desc, resolver) {
164
- switch (desc.kind) {
165
- case "map_field":
164
+ switch (desc.fieldKind) {
165
+ case "map":
166
166
  return makeMapFieldInfo(desc, resolver);
167
- case "message_field":
167
+ case "message":
168
168
  return makeMessageFieldInfo(desc, resolver);
169
- case "enum_field": {
169
+ case "enum": {
170
170
  const fi = makeEnumFieldInfo(desc, resolver);
171
171
  fi.default = desc.getDefaultValue();
172
172
  return fi;
173
173
  }
174
- case "scalar_field": {
174
+ case "scalar": {
175
175
  const fi = makeScalarFieldInfo(desc);
176
176
  fi.default = desc.getDefaultValue();
177
177
  return fi;
@@ -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.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.2.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.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.2.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");
@@ -40,7 +40,7 @@ exports.unwrapField = unwrapField;
40
40
  * the base type it wraps.
41
41
  */
42
42
  function getUnwrappedFieldType(field) {
43
- if (field.kind !== "message_field") {
43
+ if (field.fieldKind !== "message") {
44
44
  return undefined;
45
45
  }
46
46
  if (field.repeated) {
@@ -24,10 +24,7 @@ exports.findEnumSharedPrefix = exports.fieldJsonName = exports.localOneofName =
24
24
  */
25
25
  function localName(desc) {
26
26
  switch (desc.kind) {
27
- case "enum_field":
28
- case "message_field":
29
- case "map_field":
30
- case "scalar_field":
27
+ case "field":
31
28
  return localFieldName(desc.name, desc.oneof !== undefined);
32
29
  case "oneof":
33
30
  return localOneofName(desc.name);
@@ -436,24 +436,24 @@ function newField(proto, file, parent, oneof, cart) {
436
436
  const mapEntry = cart.mapEntries.get(trimLeadingDot(proto.typeName));
437
437
  if (mapEntry !== undefined) {
438
438
  assert(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
439
- return Object.assign(Object.assign(Object.assign({}, common), { kind: "map_field", repeated: false }), getMapFieldTypes(mapEntry));
439
+ return Object.assign(Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "map", repeated: false }), getMapFieldTypes(mapEntry));
440
440
  }
441
441
  const message = cart.messages.get(trimLeadingDot(proto.typeName));
442
442
  assert(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
443
- return Object.assign(Object.assign({}, common), { kind: "message_field", repeated,
443
+ return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "message", repeated,
444
444
  message });
445
445
  }
446
446
  case FieldDescriptorProto_Type.ENUM: {
447
447
  assert(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
448
448
  const e = cart.enums.get(trimLeadingDot(proto.typeName));
449
449
  assert(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
450
- return Object.assign(Object.assign({}, common), { kind: "enum_field", getDefaultValue,
450
+ return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "enum", getDefaultValue,
451
451
  repeated, enum: e });
452
452
  }
453
453
  default: {
454
454
  const scalar = fieldTypeToScalarType[proto.type];
455
455
  assert(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
456
- return Object.assign(Object.assign({}, common), { kind: "scalar_field", getDefaultValue,
456
+ return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "scalar", getDefaultValue,
457
457
  repeated,
458
458
  scalar });
459
459
  }
@@ -468,7 +468,7 @@ function newExtension(proto, file, parent, cart) {
468
468
  undefined, cart);
469
469
  const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
470
470
  assert(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
471
- return Object.assign(Object.assign({}, field), { typeName: makeTypeName(proto, parent, file), parent,
471
+ return Object.assign(Object.assign({}, field), { kind: "extension", typeName: makeTypeName(proto, parent, file), parent,
472
472
  file,
473
473
  extendee,
474
474
  toString() {
@@ -537,18 +537,18 @@ function getMapFieldTypes(mapEntry) {
537
537
  mapKey !== ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${(_b = keyField.proto.type) !== null && _b !== void 0 ? _b : -1}`);
538
538
  const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
539
539
  assert(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
540
- switch (valueField.kind) {
541
- case "scalar_field":
540
+ switch (valueField.fieldKind) {
541
+ case "scalar":
542
542
  return {
543
543
  mapKey,
544
544
  mapValue: Object.assign(Object.assign({}, valueField), { kind: "scalar" }),
545
545
  };
546
- case "message_field":
546
+ case "message":
547
547
  return {
548
548
  mapKey,
549
549
  mapValue: Object.assign(Object.assign({}, valueField), { kind: "message" }),
550
550
  };
551
- case "enum_field":
551
+ case "enum":
552
552
  return {
553
553
  mapKey,
554
554
  mapValue: Object.assign(Object.assign({}, valueField), { kind: "enum" }),
@@ -706,23 +706,23 @@ function declarationString() {
706
706
  if (this.optional) {
707
707
  parts.push("optional");
708
708
  }
709
- const file = "extendee" in this ? this.file : this.parent.file;
709
+ const file = this.kind === "extension" ? this.file : this.parent.file;
710
710
  if (file.syntax == "proto2" &&
711
711
  this.proto.label === FieldDescriptorProto_Label.REQUIRED) {
712
712
  parts.push("required");
713
713
  }
714
714
  let type;
715
- switch (this.kind) {
716
- case "scalar_field":
715
+ switch (this.fieldKind) {
716
+ case "scalar":
717
717
  type = ScalarType[this.scalar].toLowerCase();
718
718
  break;
719
- case "enum_field":
719
+ case "enum":
720
720
  type = this.enum.typeName;
721
721
  break;
722
- case "message_field":
722
+ case "message":
723
723
  type = this.message.typeName;
724
724
  break;
725
- case "map_field": {
725
+ case "map": {
726
726
  const k = ScalarType[this.mapKey].toLowerCase();
727
727
  let v;
728
728
  switch (this.mapValue.kind) {
@@ -772,13 +772,13 @@ function getDefaultValue() {
772
772
  if (d === undefined) {
773
773
  return undefined;
774
774
  }
775
- switch (this.kind) {
776
- case "enum_field": {
775
+ switch (this.fieldKind) {
776
+ case "enum": {
777
777
  const enumValue = this.enum.values.find((v) => v.name === d);
778
778
  assert(enumValue, `cannot parse ${this.toString()} default value: ${d}`);
779
779
  return enumValue.number;
780
780
  }
781
- case "scalar_field":
781
+ case "scalar":
782
782
  switch (this.scalar) {
783
783
  case ScalarType.STRING:
784
784
  return d;
@@ -157,17 +157,17 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
157
157
  };
158
158
  }
159
159
  function makeFieldInfo(desc, resolver) {
160
- switch (desc.kind) {
161
- case "map_field":
160
+ switch (desc.fieldKind) {
161
+ case "map":
162
162
  return makeMapFieldInfo(desc, resolver);
163
- case "message_field":
163
+ case "message":
164
164
  return makeMessageFieldInfo(desc, resolver);
165
- case "enum_field": {
165
+ case "enum": {
166
166
  const fi = makeEnumFieldInfo(desc, resolver);
167
167
  fi.default = desc.getDefaultValue();
168
168
  return fi;
169
169
  }
170
- case "scalar_field": {
170
+ case "scalar": {
171
171
  const fi = makeScalarFieldInfo(desc);
172
172
  fi.default = desc.getDefaultValue();
173
173
  return fi;
@@ -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.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.2.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.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v0.2.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";
@@ -35,7 +35,7 @@ export function unwrapField(type, value) {
35
35
  * the base type it wraps.
36
36
  */
37
37
  export function getUnwrappedFieldType(field) {
38
- if (field.kind !== "message_field") {
38
+ if (field.fieldKind !== "message") {
39
39
  return undefined;
40
40
  }
41
41
  if (field.repeated) {
@@ -21,10 +21,7 @@
21
21
  */
22
22
  export function localName(desc) {
23
23
  switch (desc.kind) {
24
- case "enum_field":
25
- case "message_field":
26
- case "map_field":
27
- case "scalar_field":
24
+ case "field":
28
25
  return localFieldName(desc.name, desc.oneof !== undefined);
29
26
  case "oneof":
30
27
  return localOneofName(desc.name);
@@ -8,6 +8,10 @@ import type { MethodIdempotency, MethodKind } from "./service-type.js";
8
8
  * When protobuf sources are compiled, each file is parsed into a
9
9
  * google.protobuf.FileDescriptorProto. Those messages describe all parts
10
10
  * of the source file that are required to generate code for them.
11
+ *
12
+ * DescriptorSet resolves references between the descriptors, hides
13
+ * implementation details like synthetic map entry messages, and provides
14
+ * simple access to comments.
11
15
  */
12
16
  export interface DescriptorSet {
13
17
  /**
@@ -34,6 +38,10 @@ export interface DescriptorSet {
34
38
  */
35
39
  readonly extensions: ReadonlyMap<string, DescExtension>;
36
40
  }
41
+ /**
42
+ * A union of all descriptors, discriminated by a `kind` property.
43
+ */
44
+ export declare type AnyDesc = DescFile | DescEnum | DescEnumValue | DescMessage | DescField | DescExtension | DescOneof | DescService | DescMethod;
37
45
  /**
38
46
  * Describes a protobuf source file.
39
47
  */
@@ -232,6 +240,7 @@ export interface DescMessage {
232
240
  * Describes a field declaration in a protobuf source file.
233
241
  */
234
242
  export declare type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
243
+ kind: "field";
235
244
  /**
236
245
  * The message this field is declared on.
237
246
  */
@@ -241,6 +250,7 @@ export declare type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMe
241
250
  * Describes an extension in a protobuf source file.
242
251
  */
243
252
  export declare type DescExtension = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
253
+ kind: "extension";
244
254
  /**
245
255
  * The fully qualified name of the extension.
246
256
  */
@@ -311,7 +321,7 @@ interface DescFieldCommon {
311
321
  toString(): string;
312
322
  }
313
323
  interface DescFieldScalar {
314
- readonly kind: "scalar_field";
324
+ readonly fieldKind: "scalar";
315
325
  /**
316
326
  * Is the field repeated?
317
327
  */
@@ -343,7 +353,7 @@ interface DescFieldScalar {
343
353
  getDefaultValue(): number | boolean | string | bigint | Uint8Array | undefined;
344
354
  }
345
355
  interface DescFieldMessage {
346
- readonly kind: "message_field";
356
+ readonly fieldKind: "message";
347
357
  /**
348
358
  * Is the field repeated?
349
359
  */
@@ -370,7 +380,7 @@ interface DescFieldMessage {
370
380
  readonly mapValue: undefined;
371
381
  }
372
382
  interface DescFieldEnum {
373
- readonly kind: "enum_field";
383
+ readonly fieldKind: "enum";
374
384
  /**
375
385
  * Is the field repeated?
376
386
  */
@@ -402,7 +412,7 @@ interface DescFieldEnum {
402
412
  getDefaultValue(): number | boolean | string | bigint | Uint8Array | undefined;
403
413
  }
404
414
  interface DescFieldMap {
405
- readonly kind: "map_field";
415
+ readonly fieldKind: "map";
406
416
  /**
407
417
  * Is the field repeated?
408
418
  */
@@ -15,7 +15,7 @@ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
15
15
  export type { IBinaryReader, IBinaryWriter } from "./binary-encoding.js";
16
16
  export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./binary-format.js";
17
17
  export { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
18
- export { DescriptorSet, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
18
+ export { DescriptorSet, AnyDesc, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
19
19
  export { createDescriptorSet } from "./create-descriptor-set.js";
20
20
  export { IMessageTypeRegistry } from "./type-registry.js";
21
21
  export { createRegistry } from "./create-registry.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.1.1",
3
+ "version": "0.2.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": {