@bufbuild/protobuf 0.0.3 → 0.0.4

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.
@@ -29,6 +29,7 @@ const field_mask_pb_js_1 = require("./google/protobuf/field_mask_pb.js");
29
29
  const struct_pb_js_1 = require("./google/protobuf/struct_pb.js");
30
30
  const enum_js_1 = require("./private/enum.js");
31
31
  const wrappers_pb_js_1 = require("./google/protobuf/wrappers_pb.js");
32
+ const descriptor_pb_js_1 = require("./google/protobuf/descriptor_pb.js");
32
33
  // well-known message types with specialized JSON representation
33
34
  const wkMessages = [
34
35
  any_pb_js_1.Any,
@@ -74,6 +75,18 @@ class DescriptorRegistry {
74
75
  }
75
76
  }
76
77
  }
78
+ /**
79
+ * Conveniently create a DescriptorRegistry from a FileDescriptorSet
80
+ * instance or a FileDescriptorSet in binary format.
81
+ */
82
+ static fromFileDescriptorSet(bytesOrSet) {
83
+ const set = bytesOrSet instanceof Uint8Array
84
+ ? descriptor_pb_js_1.FileDescriptorSet.fromBinary(bytesOrSet)
85
+ : new descriptor_pb_js_1.FileDescriptorSet(bytesOrSet);
86
+ const dr = new DescriptorRegistry();
87
+ dr.add(...set.file);
88
+ return dr;
89
+ }
77
90
  /**
78
91
  * May raise an error on invalid descriptors.
79
92
  */
@@ -26,6 +26,7 @@ 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";
29
30
  // well-known message types with specialized JSON representation
30
31
  const wkMessages = [
31
32
  Any,
@@ -71,6 +72,18 @@ export class DescriptorRegistry {
71
72
  }
72
73
  }
73
74
  }
75
+ /**
76
+ * Conveniently create a DescriptorRegistry from a FileDescriptorSet
77
+ * instance or a FileDescriptorSet in binary format.
78
+ */
79
+ static fromFileDescriptorSet(bytesOrSet) {
80
+ const set = bytesOrSet instanceof Uint8Array
81
+ ? FileDescriptorSet.fromBinary(bytesOrSet)
82
+ : new FileDescriptorSet(bytesOrSet);
83
+ const dr = new DescriptorRegistry();
84
+ dr.add(...set.file);
85
+ return dr;
86
+ }
74
87
  /**
75
88
  * May raise an error on invalid descriptors.
76
89
  */
@@ -4,6 +4,8 @@ import type { EnumType } from "./enum.js";
4
4
  import { DescriptorSet } from "./descriptor-set.js";
5
5
  import type { IEnumTypeRegistry, IMessageTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
6
6
  import type { ServiceType } from "./service-type.js";
7
+ import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
8
+ import type { PartialMessage } from "./message.js";
7
9
  /**
8
10
  * DescriptorRegistry is a type registry that dynamically creates types
9
11
  * from a set of google.protobuf.FileDescriptorProto.
@@ -17,6 +19,11 @@ export declare class DescriptorRegistry implements IMessageTypeRegistry, IEnumTy
17
19
  private readonly messages;
18
20
  private readonly services;
19
21
  constructor(descriptorSet?: DescriptorSet, replaceWkt?: boolean);
22
+ /**
23
+ * Conveniently create a DescriptorRegistry from a FileDescriptorSet
24
+ * instance or a FileDescriptorSet in binary format.
25
+ */
26
+ static fromFileDescriptorSet(bytesOrSet: Uint8Array | FileDescriptorSet | PartialMessage<FileDescriptorSet>): DescriptorRegistry;
20
27
  /**
21
28
  * May raise an error on invalid descriptors.
22
29
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
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": {
@@ -8,6 +8,7 @@
8
8
  "url": "https://github.com/bufbuild/protobuf-es.git",
9
9
  "directory": "packages/protobuf"
10
10
  },
11
+ "sideEffects": false,
11
12
  "scripts": {
12
13
  "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*",
13
14
  "build": "npm run build:cjs && npm run build:esm+types",