@bufbuild/protobuf 0.0.2-alpha.3 → 0.0.5

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 (57) hide show
  1. package/README.md +5 -2
  2. package/dist/cjs/descriptor-registry.js +13 -0
  3. package/dist/cjs/google/protobuf/any_pb.js +6 -6
  4. package/dist/cjs/google/protobuf/api_pb.js +18 -18
  5. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +22 -22
  6. package/dist/cjs/google/protobuf/descriptor_pb.js +148 -148
  7. package/dist/cjs/google/protobuf/duration_pb.js +11 -11
  8. package/dist/cjs/google/protobuf/empty_pb.js +6 -6
  9. package/dist/cjs/google/protobuf/field_mask_pb.js +7 -7
  10. package/dist/cjs/google/protobuf/source_context_pb.js +6 -6
  11. package/dist/cjs/google/protobuf/struct_pb.js +21 -21
  12. package/dist/cjs/google/protobuf/timestamp_pb.js +10 -10
  13. package/dist/cjs/google/protobuf/type_pb.js +33 -33
  14. package/dist/cjs/google/protobuf/wrappers_pb.js +66 -66
  15. package/dist/cjs/index-runtime.js +42 -0
  16. package/dist/cjs/index-wkt.js +42 -0
  17. package/dist/cjs/index.js +4 -40
  18. package/dist/cjs/package.json +1 -0
  19. package/dist/cjs/private/util-common.js +1 -1
  20. package/dist/cjs/type-registry.js +58 -13
  21. package/dist/esm/descriptor-registry.js +13 -0
  22. package/dist/esm/google/protobuf/any_pb.js +1 -1
  23. package/dist/esm/google/protobuf/api_pb.js +1 -1
  24. package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
  25. package/dist/esm/google/protobuf/descriptor_pb.js +1 -1
  26. package/dist/esm/google/protobuf/duration_pb.js +1 -1
  27. package/dist/esm/google/protobuf/empty_pb.js +1 -1
  28. package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
  29. package/dist/esm/google/protobuf/source_context_pb.js +1 -1
  30. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  31. package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
  32. package/dist/esm/google/protobuf/type_pb.js +1 -1
  33. package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
  34. package/dist/esm/index-runtime.js +25 -0
  35. package/dist/esm/index-wkt.js +26 -0
  36. package/dist/esm/index.js +4 -25
  37. package/dist/esm/private/util-common.js +1 -1
  38. package/dist/esm/type-registry.js +58 -13
  39. package/dist/types/descriptor-registry.d.ts +7 -0
  40. package/dist/types/google/protobuf/any_pb.d.ts +2 -2
  41. package/dist/types/google/protobuf/api_pb.d.ts +2 -2
  42. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +2 -2
  43. package/dist/types/google/protobuf/descriptor_pb.d.ts +2 -2
  44. package/dist/types/google/protobuf/duration_pb.d.ts +2 -2
  45. package/dist/types/google/protobuf/empty_pb.d.ts +2 -2
  46. package/dist/types/google/protobuf/field_mask_pb.d.ts +2 -2
  47. package/dist/types/google/protobuf/source_context_pb.d.ts +2 -2
  48. package/dist/types/google/protobuf/struct_pb.d.ts +2 -2
  49. package/dist/types/google/protobuf/timestamp_pb.d.ts +2 -2
  50. package/dist/types/google/protobuf/type_pb.d.ts +2 -2
  51. package/dist/types/google/protobuf/wrappers_pb.d.ts +2 -2
  52. package/dist/types/index-runtime.d.ts +19 -0
  53. package/dist/types/index-wkt.d.ts +12 -0
  54. package/dist/types/index.d.ts +2 -31
  55. package/dist/types/message.d.ts +1 -3
  56. package/dist/types/type-registry.d.ts +35 -2
  57. package/package.json +4 -3
@@ -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
  */
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  /**
16
16
  * `Any` contains an arbitrary serialized protocol buffer message along with a
17
17
  * URL that describes the type of the serialized message.
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  import { Option, Syntax } from "./type_pb.js";
16
16
  import { SourceContext } from "./source_context_pb.js";
17
17
  /**
@@ -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
- import { Message, proto2 } from "../../../index.js";
14
+ import { Message, proto2 } from "../../../index-runtime.js";
15
15
  import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor_pb.js";
16
16
  /**
17
17
  * The version number of protocol compiler.
@@ -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
- import { Message, proto2 } from "../../index.js";
14
+ import { Message, proto2 } from "../../index-runtime.js";
15
15
  /**
16
16
  * The protocol compiler can output a FileDescriptorSet containing the .proto
17
17
  * files it parses.
@@ -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
- import { Message, proto3, protoInt64 } from "../../index.js";
14
+ import { Message, proto3, protoInt64 } from "../../index-runtime.js";
15
15
  /**
16
16
  * A Duration represents a signed, fixed-length span of time represented
17
17
  * as a count of seconds and fractions of seconds at nanosecond
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  /**
16
16
  * A generic empty message that you can re-use to avoid defining duplicated
17
17
  * empty messages in your APIs. A typical example is to use it as the request
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  /**
16
16
  * `FieldMask` represents a set of symbolic field paths, for example:
17
17
  *
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  /**
16
16
  * `SourceContext` represents information about the source of a
17
17
  * protobuf element, like the file in which it is defined.
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  /**
16
16
  * `NullValue` is a singleton enumeration to represent the null value for the
17
17
  * `Value` type union.
@@ -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
- import { Message, proto3, protoInt64 } from "../../index.js";
14
+ import { Message, proto3, protoInt64 } from "../../index-runtime.js";
15
15
  /**
16
16
  * A Timestamp represents a point in time independent of any time zone or local
17
17
  * calendar, encoded as a count of seconds and fractions of seconds at
@@ -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
- import { Message, proto3 } from "../../index.js";
14
+ import { Message, proto3 } from "../../index-runtime.js";
15
15
  import { SourceContext } from "./source_context_pb.js";
16
16
  import { Any } from "./any_pb.js";
17
17
  /**
@@ -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
- import { Message, ScalarType, proto3, protoInt64 } from "../../index.js";
14
+ import { Message, ScalarType, proto3, protoInt64 } from "../../index-runtime.js";
15
15
  /**
16
16
  * Wrapper message for `double`.
17
17
  *
@@ -0,0 +1,25 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ export { proto3 } from "./proto3.js";
15
+ export { proto2 } from "./proto2.js";
16
+ export { protoInt64 } from "./proto-int64.js";
17
+ export { protoBase64 } from "./proto-base64.js";
18
+ export { Message, } from "./message.js";
19
+ export { ScalarType } from "./field.js";
20
+ 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
+ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
25
+ export {} from "./json-format.js";
@@ -0,0 +1,26 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // ideally, we would export these types with sub-path exports:
15
+ export * from "./google/protobuf/compiler/plugin_pb.js";
16
+ export * from "./google/protobuf/api_pb.js";
17
+ export * from "./google/protobuf/any_pb.js";
18
+ export * from "./google/protobuf/descriptor_pb.js";
19
+ export * from "./google/protobuf/duration_pb.js";
20
+ export * from "./google/protobuf/empty_pb.js";
21
+ export * from "./google/protobuf/field_mask_pb.js";
22
+ export * from "./google/protobuf/source_context_pb.js";
23
+ export * from "./google/protobuf/struct_pb.js";
24
+ export * from "./google/protobuf/timestamp_pb.js";
25
+ export * from "./google/protobuf/type_pb.js";
26
+ export * from "./google/protobuf/wrappers_pb.js";
package/dist/esm/index.js CHANGED
@@ -11,28 +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
- export { proto3 } from "./proto3.js";
15
- export { proto2 } from "./proto2.js";
16
- export { protoInt64 } from "./proto-int64.js";
17
- export { protoBase64 } from "./proto-base64.js";
18
- export { Message, } from "./message.js";
19
- export { ScalarType } from "./field.js";
20
- 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
- export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
25
- export {} from "./json-format.js";
26
- // ideally, we would export these types with sub-path exports:
27
- export * from "./google/protobuf/compiler/plugin_pb.js";
28
- export * from "./google/protobuf/api_pb.js";
29
- export * from "./google/protobuf/any_pb.js";
30
- export * from "./google/protobuf/descriptor_pb.js";
31
- export * from "./google/protobuf/duration_pb.js";
32
- export * from "./google/protobuf/empty_pb.js";
33
- export * from "./google/protobuf/field_mask_pb.js";
34
- export * from "./google/protobuf/source_context_pb.js";
35
- export * from "./google/protobuf/struct_pb.js";
36
- export * from "./google/protobuf/timestamp_pb.js";
37
- export * from "./google/protobuf/type_pb.js";
38
- export * from "./google/protobuf/wrappers_pb.js";
14
+ // To avoid circular imports when the wkt import from ./index.js, we
15
+ // use a separate ./index-runtime.js
16
+ export * from "./index-runtime.js";
17
+ export * from "./index-wkt.js";
@@ -78,7 +78,7 @@ export function makeUtilCommon() {
78
78
  t[localName] = val;
79
79
  }
80
80
  else {
81
- t[localName] = val instanceof mt ? mt : new mt(val);
81
+ t[localName] = val instanceof mt ? val : new mt(val);
82
82
  }
83
83
  }
84
84
  break;
@@ -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
- * TypeRegistry is a basic type registry
15
+ * TypeRegistry is a simple registry for all message, enum, or service types.
16
16
  */
17
17
  export class TypeRegistry {
18
18
  constructor() {
@@ -20,34 +20,79 @@ export class TypeRegistry {
20
20
  this.enums = {};
21
21
  this.services = {};
22
22
  }
23
+ /**
24
+ * Find a message type by its protobuf type name.
25
+ */
23
26
  findMessage(typeName) {
24
27
  return this.messages[typeName];
25
28
  }
29
+ /**
30
+ * Find an enum type by its protobuf type name.
31
+ */
26
32
  findEnum(typeName) {
27
33
  return this.enums[typeName];
28
34
  }
35
+ /**
36
+ * Find a service type by its protobuf type name.
37
+ */
29
38
  findService(typeName) {
30
39
  return this.services[typeName];
31
40
  }
41
+ /**
42
+ * Create a new TypeRegistry from the given types.
43
+ */
44
+ static from(...types) {
45
+ const registry = new TypeRegistry();
46
+ for (const type of types) {
47
+ registry.add(type);
48
+ }
49
+ return registry;
50
+ }
51
+ /**
52
+ * @deprecated use TypeRegistry.from()
53
+ */
54
+ static fromIterable(types) {
55
+ return TypeRegistry.from(...types);
56
+ }
57
+ /**
58
+ * @deprecated use TypeRegistry.from()
59
+ */
60
+ static fromTypes(...types) {
61
+ return TypeRegistry.from(...types);
62
+ }
63
+ /**
64
+ * Add a type to the registry. For messages, the types used in message
65
+ * fields are added recursively. For services, the message types used
66
+ * for requests and responses are added recursively.
67
+ */
32
68
  add(type) {
33
69
  if ("fields" in type) {
34
- this.messages[type.typeName] = type;
70
+ if (!this.findMessage(type.typeName)) {
71
+ this.messages[type.typeName] = type;
72
+ for (const field of type.fields.list()) {
73
+ if (field.kind == "message") {
74
+ this.add(field.T);
75
+ }
76
+ else if (field.kind == "map" && field.V.kind == "message") {
77
+ this.add(field.V.T);
78
+ }
79
+ else if (field.kind == "enum") {
80
+ this.add(field.T);
81
+ }
82
+ }
83
+ }
35
84
  }
36
85
  else if ("methods" in type) {
37
- this.services[type.typeName] = type;
86
+ if (!this.findService(type.typeName)) {
87
+ this.services[type.typeName] = type;
88
+ for (const method of Object.values(type.methods)) {
89
+ this.add(method.I);
90
+ this.add(method.O);
91
+ }
92
+ }
38
93
  }
39
94
  else {
40
95
  this.enums[type.typeName] = type;
41
96
  }
42
97
  }
43
- static fromIterable(types) {
44
- const r = new TypeRegistry();
45
- for (const t of types) {
46
- r.add(t);
47
- }
48
- return r;
49
- }
50
- static fromTypes(...types) {
51
- return TypeRegistry.fromIterable(types);
52
- }
53
98
  }
@@ -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
  */
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * `Any` contains an arbitrary serialized protocol buffer message along with a
5
5
  * URL that describes the type of the serialized message.
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  import { Option, Syntax } from "./type_pb.js";
4
4
  import { SourceContext } from "./source_context_pb.js";
5
5
  /**
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../../index.js";
2
- import { Message } from "../../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../../index-runtime.js";
2
+ import { Message } from "../../../index-runtime.js";
3
3
  import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor_pb.js";
4
4
  /**
5
5
  * The version number of protocol compiler.
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * The protocol compiler can output a FileDescriptorSet containing the .proto
5
5
  * files it parses.
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * A Duration represents a signed, fixed-length span of time represented
5
5
  * as a count of seconds and fractions of seconds at nanosecond
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * A generic empty message that you can re-use to avoid defining duplicated
5
5
  * empty messages in your APIs. A typical example is to use it as the request
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * `FieldMask` represents a set of symbolic field paths, for example:
5
5
  *
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * `SourceContext` represents information about the source of a
5
5
  * protobuf element, like the file in which it is defined.
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * `NullValue` is a singleton enumeration to represent the null value for the
5
5
  * `Value` type union.
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * A Timestamp represents a point in time independent of any time zone or local
5
5
  * calendar, encoded as a count of seconds and fractions of seconds at
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  import { SourceContext } from "./source_context_pb.js";
4
4
  import { Any } from "./any_pb.js";
5
5
  /**
@@ -1,5 +1,5 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index.js";
2
- import { Message } from "../../index.js";
1
+ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
+ import { Message } from "../../index-runtime.js";
3
3
  /**
4
4
  * Wrapper message for `double`.
5
5
  *
@@ -0,0 +1,19 @@
1
+ export { proto3 } from "./proto3.js";
2
+ export { proto2 } from "./proto2.js";
3
+ export { protoInt64 } from "./proto-int64.js";
4
+ export { protoBase64 } from "./proto-base64.js";
5
+ export { Message, AnyMessage, PartialMessage, PlainMessage, } from "./message.js";
6
+ export type { FieldInfo } from "./field.js";
7
+ export type { FieldList } from "./field-list.js";
8
+ export { ScalarType } from "./field.js";
9
+ export type { MessageType } from "./message-type.js";
10
+ export type { EnumType, EnumValueInfo } from "./enum.js";
11
+ export type { ServiceType, MethodInfo, MethodInfoUnary, MethodInfoServerStreaming, MethodInfoClientStreaming, MethodInfoBiDiStreaming, } from "./service-type.js";
12
+ export { MethodKind, MethodIdempotency } from "./service-type.js";
13
+ export { TypeRegistry, IMessageTypeRegistry } from "./type-registry.js";
14
+ export { DescriptorRegistry } from "./descriptor-registry.js";
15
+ export { DescriptorSet } from "./descriptor-set.js";
16
+ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
17
+ export type { IBinaryReader, IBinaryWriter } from "./binary-encoding.js";
18
+ export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./binary-format.js";
19
+ export { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
@@ -0,0 +1,12 @@
1
+ export * from "./google/protobuf/compiler/plugin_pb.js";
2
+ export * from "./google/protobuf/api_pb.js";
3
+ export * from "./google/protobuf/any_pb.js";
4
+ export * from "./google/protobuf/descriptor_pb.js";
5
+ export * from "./google/protobuf/duration_pb.js";
6
+ export * from "./google/protobuf/empty_pb.js";
7
+ export * from "./google/protobuf/field_mask_pb.js";
8
+ export * from "./google/protobuf/source_context_pb.js";
9
+ export * from "./google/protobuf/struct_pb.js";
10
+ export * from "./google/protobuf/timestamp_pb.js";
11
+ export * from "./google/protobuf/type_pb.js";
12
+ export * from "./google/protobuf/wrappers_pb.js";
@@ -1,31 +1,2 @@
1
- export { proto3 } from "./proto3.js";
2
- export { proto2 } from "./proto2.js";
3
- export { protoInt64 } from "./proto-int64.js";
4
- export { protoBase64 } from "./proto-base64.js";
5
- export { Message, AnyMessage, PartialMessage, PlainMessage, } from "./message.js";
6
- export type { FieldInfo } from "./field.js";
7
- export type { FieldList } from "./field-list.js";
8
- export { ScalarType } from "./field.js";
9
- export type { MessageType } from "./message-type.js";
10
- export type { EnumType, EnumValueInfo } from "./enum.js";
11
- export type { ServiceType, MethodInfo, MethodInfoUnary, MethodInfoServerStreaming, MethodInfoClientStreaming, MethodInfoBiDiStreaming, } from "./service-type.js";
12
- export { MethodKind, MethodIdempotency } from "./service-type.js";
13
- export { TypeRegistry, IMessageTypeRegistry } from "./type-registry.js";
14
- export { DescriptorRegistry } from "./descriptor-registry.js";
15
- export { DescriptorSet } from "./descriptor-set.js";
16
- export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
17
- export type { IBinaryReader, IBinaryWriter } from "./binary-encoding.js";
18
- export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./binary-format.js";
19
- export { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
20
- export * from "./google/protobuf/compiler/plugin_pb.js";
21
- export * from "./google/protobuf/api_pb.js";
22
- export * from "./google/protobuf/any_pb.js";
23
- export * from "./google/protobuf/descriptor_pb.js";
24
- export * from "./google/protobuf/duration_pb.js";
25
- export * from "./google/protobuf/empty_pb.js";
26
- export * from "./google/protobuf/field_mask_pb.js";
27
- export * from "./google/protobuf/source_context_pb.js";
28
- export * from "./google/protobuf/struct_pb.js";
29
- export * from "./google/protobuf/timestamp_pb.js";
30
- export * from "./google/protobuf/type_pb.js";
31
- export * from "./google/protobuf/wrappers_pb.js";
1
+ export * from "./index-runtime.js";
2
+ export * from "./index-wkt.js";
@@ -67,9 +67,7 @@ export declare class Message<T extends Message<T> = AnyMessage> {
67
67
  * PlainMessage<T> strips all methods from a message, leaving only fields
68
68
  * and oneof groups.
69
69
  */
70
- export declare type PlainMessage<T extends Message> = {
71
- [P in keyof T as T[P] extends Function ? never : P]: T[P];
72
- };
70
+ export declare type PlainMessage<T extends Message> = Omit<T, keyof Message>;
73
71
  /**
74
72
  * PartialMessage<T> constructs a type from a message. The resulting type
75
73
  * only contains the protobuf field members of the message, and all of them
@@ -5,31 +5,64 @@ import type { ServiceType } from "./service-type.js";
5
5
  * IMessageTypeRegistry provides look-up for message types.
6
6
  */
7
7
  export interface IMessageTypeRegistry {
8
+ /**
9
+ * Find a message type by its protobuf type name.
10
+ */
8
11
  findMessage(typeName: string): MessageType | undefined;
9
12
  }
10
13
  /**
11
14
  * IEnumTypeRegistry provides look-up for enum types.
12
15
  */
13
16
  export interface IEnumTypeRegistry {
17
+ /**
18
+ * Find an enum type by its protobuf type name.
19
+ */
14
20
  findEnum(typeName: string): EnumType | undefined;
15
21
  }
16
22
  /**
17
23
  * IServiceTypeRegistry provides look-up for service types.
18
24
  */
19
25
  export interface IServiceTypeRegistry {
26
+ /**
27
+ * Find a service type by its protobuf type name.
28
+ */
20
29
  findService(typeName: string): ServiceType | undefined;
21
30
  }
22
31
  /**
23
- * TypeRegistry is a basic type registry
32
+ * TypeRegistry is a simple registry for all message, enum, or service types.
24
33
  */
25
34
  export declare class TypeRegistry implements IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry {
26
35
  private readonly messages;
27
36
  private readonly enums;
28
37
  private readonly services;
38
+ /**
39
+ * Find a message type by its protobuf type name.
40
+ */
29
41
  findMessage(typeName: string): MessageType | undefined;
42
+ /**
43
+ * Find an enum type by its protobuf type name.
44
+ */
30
45
  findEnum(typeName: string): EnumType | undefined;
46
+ /**
47
+ * Find a service type by its protobuf type name.
48
+ */
31
49
  findService(typeName: string): ServiceType | undefined;
32
- private add;
50
+ /**
51
+ * Create a new TypeRegistry from the given types.
52
+ */
53
+ static from(...types: Array<MessageType | EnumType | ServiceType>): TypeRegistry;
54
+ /**
55
+ * @deprecated use TypeRegistry.from()
56
+ */
33
57
  static fromIterable(types: Iterable<MessageType>): TypeRegistry;
58
+ /**
59
+ * @deprecated use TypeRegistry.from()
60
+ */
34
61
  static fromTypes(...types: MessageType[]): TypeRegistry;
62
+ /**
63
+ * Add a type to the registry. For messages, the types used in message
64
+ * fields are added recursively. For services, the message types used
65
+ * for requests and responses are added recursively.
66
+ */
67
+ add(type: MessageType | EnumType | ServiceType): void;
35
68
  }