@bufbuild/protobuf 0.0.3 → 0.0.6

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 (53) hide show
  1. package/dist/cjs/descriptor-registry.js +13 -0
  2. package/dist/cjs/google/protobuf/any_pb.js +7 -6
  3. package/dist/cjs/google/protobuf/api_pb.js +19 -18
  4. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +23 -22
  5. package/dist/cjs/google/protobuf/descriptor_pb.js +149 -148
  6. package/dist/cjs/google/protobuf/duration_pb.js +13 -11
  7. package/dist/cjs/google/protobuf/empty_pb.js +7 -6
  8. package/dist/cjs/google/protobuf/field_mask_pb.js +8 -7
  9. package/dist/cjs/google/protobuf/source_context_pb.js +7 -6
  10. package/dist/cjs/google/protobuf/struct_pb.js +25 -21
  11. package/dist/cjs/google/protobuf/timestamp_pb.js +12 -10
  12. package/dist/cjs/google/protobuf/type_pb.js +37 -33
  13. package/dist/cjs/google/protobuf/wrappers_pb.js +69 -66
  14. package/dist/cjs/index.js +40 -4
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/type-registry.js +58 -13
  17. package/dist/esm/descriptor-registry.js +13 -0
  18. package/dist/esm/google/protobuf/any_pb.js +2 -1
  19. package/dist/esm/google/protobuf/api_pb.js +2 -1
  20. package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -1
  21. package/dist/esm/google/protobuf/descriptor_pb.js +2 -1
  22. package/dist/esm/google/protobuf/duration_pb.js +3 -1
  23. package/dist/esm/google/protobuf/empty_pb.js +2 -1
  24. package/dist/esm/google/protobuf/field_mask_pb.js +2 -1
  25. package/dist/esm/google/protobuf/source_context_pb.js +2 -1
  26. package/dist/esm/google/protobuf/struct_pb.js +5 -1
  27. package/dist/esm/google/protobuf/timestamp_pb.js +3 -1
  28. package/dist/esm/google/protobuf/type_pb.js +5 -1
  29. package/dist/esm/google/protobuf/wrappers_pb.js +4 -1
  30. package/dist/esm/index.js +25 -4
  31. package/dist/esm/type-registry.js +58 -13
  32. package/dist/types/descriptor-registry.d.ts +7 -0
  33. package/dist/types/google/protobuf/any_pb.d.ts +6 -2
  34. package/dist/types/google/protobuf/api_pb.d.ts +5 -2
  35. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +5 -2
  36. package/dist/types/google/protobuf/descriptor_pb.d.ts +5 -2
  37. package/dist/types/google/protobuf/duration_pb.d.ts +5 -2
  38. package/dist/types/google/protobuf/empty_pb.d.ts +5 -2
  39. package/dist/types/google/protobuf/field_mask_pb.d.ts +5 -2
  40. package/dist/types/google/protobuf/source_context_pb.d.ts +5 -2
  41. package/dist/types/google/protobuf/struct_pb.d.ts +5 -2
  42. package/dist/types/google/protobuf/timestamp_pb.d.ts +5 -2
  43. package/dist/types/google/protobuf/type_pb.d.ts +5 -2
  44. package/dist/types/google/protobuf/wrappers_pb.d.ts +5 -2
  45. package/dist/types/index.d.ts +31 -2
  46. package/dist/types/type-registry.d.ts +35 -2
  47. package/package.json +4 -3
  48. package/dist/cjs/index-runtime.js +0 -42
  49. package/dist/cjs/index-wkt.js +0 -42
  50. package/dist/esm/index-runtime.js +0 -25
  51. package/dist/esm/index-wkt.js +0 -26
  52. package/dist/types/index-runtime.d.ts +0 -19
  53. package/dist/types/index-wkt.d.ts +0 -12
@@ -11,7 +11,8 @@
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-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
15
16
  /**
16
17
  * `FieldMask` represents a set of symbolic field paths, for example:
17
18
  *
@@ -11,7 +11,8 @@
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-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
15
16
  /**
16
17
  * `SourceContext` represents information about the source of a
17
18
  * protobuf element, like the file in which it is defined.
@@ -11,7 +11,11 @@
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-runtime.js";
14
+ // @generated by protoc-gen-es v0.0.6 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
+ // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
+ /* eslint-disable */
17
+ import { proto3 } from "../../proto3.js";
18
+ import { Message } from "../../message.js";
15
19
  /**
16
20
  * `NullValue` is a singleton enumeration to represent the null value for the
17
21
  * `Value` type union.
@@ -11,7 +11,9 @@
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-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { protoInt64 } from "../../proto-int64.js";
16
+ import { proto3 } from "../../proto3.js";
15
17
  /**
16
18
  * A Timestamp represents a point in time independent of any time zone or local
17
19
  * calendar, encoded as a count of seconds and fractions of seconds at
@@ -11,7 +11,11 @@
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-runtime.js";
14
+ // @generated by protoc-gen-es v0.0.6 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
+ // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
+ /* eslint-disable */
17
+ import { proto3 } from "../../proto3.js";
18
+ import { Message } from "../../message.js";
15
19
  import { SourceContext } from "./source_context_pb.js";
16
20
  import { Any } from "./any_pb.js";
17
21
  /**
@@ -11,7 +11,10 @@
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-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
16
+ import { ScalarType } from "../../field.js";
17
+ import { protoInt64 } from "../../proto-int64.js";
15
18
  /**
16
19
  * Wrapper message for `double`.
17
20
  *
package/dist/esm/index.js CHANGED
@@ -11,7 +11,28 @@
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
- // 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";
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";
@@ -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,9 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions } from "../../json-format.js";
4
+ import type { MessageType } from "../../message-type.js";
5
+ import type { FieldList } from "../../field-list.js";
6
+ import type { BinaryReadOptions } from "../../binary-format.js";
3
7
  /**
4
8
  * `Any` contains an arbitrary serialized protocol buffer message along with a
5
9
  * URL that describes the type of the serialized message.
@@ -1,7 +1,10 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
3
  import { Option, Syntax } from "./type_pb.js";
4
4
  import { SourceContext } from "./source_context_pb.js";
5
+ import type { FieldList } from "../../field-list.js";
6
+ import type { BinaryReadOptions } from "../../binary-format.js";
7
+ import type { JsonReadOptions, JsonValue } from "../../json-format.js";
5
8
  /**
6
9
  * Api is a light-weight descriptor for an API Interface.
7
10
  *
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../../index-runtime.js";
2
- import { Message } from "../../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../../message.js";
2
+ import { Message } from "../../../message.js";
3
+ import type { FieldList } from "../../../field-list.js";
4
+ import type { BinaryReadOptions } from "../../../binary-format.js";
5
+ import type { JsonReadOptions, JsonValue } from "../../../json-format.js";
3
6
  import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor_pb.js";
4
7
  /**
5
8
  * The version number of protocol compiler.
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { FieldList } from "../../field-list.js";
4
+ import type { BinaryReadOptions } from "../../binary-format.js";
5
+ import type { JsonReadOptions, JsonValue } from "../../json-format.js";
3
6
  /**
4
7
  * The protocol compiler can output a FileDescriptorSet containing the .proto
5
8
  * files it parses.
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions } from "../../json-format.js";
4
+ import type { FieldList } from "../../field-list.js";
5
+ import type { BinaryReadOptions } from "../../binary-format.js";
3
6
  /**
4
7
  * A Duration represents a signed, fixed-length span of time represented
5
8
  * as a count of seconds and fractions of seconds at nanosecond
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { FieldList } from "../../field-list.js";
4
+ import type { BinaryReadOptions } from "../../binary-format.js";
5
+ import type { JsonReadOptions, JsonValue } from "../../json-format.js";
3
6
  /**
4
7
  * A generic empty message that you can re-use to avoid defining duplicated
5
8
  * empty messages in your APIs. A typical example is to use it as the request
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions } from "../../json-format.js";
4
+ import type { FieldList } from "../../field-list.js";
5
+ import type { BinaryReadOptions } from "../../binary-format.js";
3
6
  /**
4
7
  * `FieldMask` represents a set of symbolic field paths, for example:
5
8
  *
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { FieldList } from "../../field-list.js";
4
+ import type { BinaryReadOptions } from "../../binary-format.js";
5
+ import type { JsonReadOptions, JsonValue } from "../../json-format.js";
3
6
  /**
4
7
  * `SourceContext` represents information about the source of a
5
8
  * protobuf element, like the file in which it is defined.
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions } from "../../json-format.js";
4
+ import type { FieldList } from "../../field-list.js";
5
+ import type { BinaryReadOptions } from "../../binary-format.js";
3
6
  /**
4
7
  * `NullValue` is a singleton enumeration to represent the null value for the
5
8
  * `Value` type union.
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions } from "../../json-format.js";
4
+ import type { FieldList } from "../../field-list.js";
5
+ import type { BinaryReadOptions } from "../../binary-format.js";
3
6
  /**
4
7
  * A Timestamp represents a point in time independent of any time zone or local
5
8
  * calendar, encoded as a count of seconds and fractions of seconds at
@@ -1,6 +1,9 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
3
  import { SourceContext } from "./source_context_pb.js";
4
+ import type { FieldList } from "../../field-list.js";
5
+ import type { BinaryReadOptions } from "../../binary-format.js";
6
+ import type { JsonReadOptions, JsonValue } from "../../json-format.js";
4
7
  import { Any } from "./any_pb.js";
5
8
  /**
6
9
  * The syntax in which a protocol buffer element is defined.
@@ -1,5 +1,8 @@
1
- import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, JsonWriteOptions, PartialMessage, PlainMessage } from "../../index-runtime.js";
2
- import { Message } from "../../index-runtime.js";
1
+ import type { PartialMessage, PlainMessage } from "../../message.js";
2
+ import { Message } from "../../message.js";
3
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions } from "../../json-format.js";
4
+ import type { FieldList } from "../../field-list.js";
5
+ import type { BinaryReadOptions } from "../../binary-format.js";
3
6
  /**
4
7
  * Wrapper message for `double`.
5
8
  *
@@ -1,2 +1,31 @@
1
- export * from "./index-runtime.js";
2
- export * from "./index-wkt.js";
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";
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
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,10 +8,11 @@
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",
14
- "build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs",
15
+ "build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
15
16
  "build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
16
17
  },
17
18
  "type": "module",
@@ -22,7 +23,7 @@
22
23
  "default": "./dist/esm/index.js"
23
24
  },
24
25
  "devDependencies": {
25
- "typescript": "^4.6.4"
26
+ "typescript": "^4.7.3"
26
27
  },
27
28
  "files": [
28
29
  "dist/**/"
@@ -1,42 +0,0 @@
1
- "use strict";
2
- // Copyright 2021-2022 Buf Technologies, Inc.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.DescriptorSet = exports.DescriptorRegistry = exports.TypeRegistry = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.protoBase64 = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
17
- var proto3_js_1 = require("./proto3.js");
18
- Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
19
- var proto2_js_1 = require("./proto2.js");
20
- Object.defineProperty(exports, "proto2", { enumerable: true, get: function () { return proto2_js_1.proto2; } });
21
- var proto_int64_js_1 = require("./proto-int64.js");
22
- Object.defineProperty(exports, "protoInt64", { enumerable: true, get: function () { return proto_int64_js_1.protoInt64; } });
23
- var proto_base64_js_1 = require("./proto-base64.js");
24
- Object.defineProperty(exports, "protoBase64", { enumerable: true, get: function () { return proto_base64_js_1.protoBase64; } });
25
- var message_js_1 = require("./message.js");
26
- Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_js_1.Message; } });
27
- var field_js_1 = require("./field.js");
28
- Object.defineProperty(exports, "ScalarType", { enumerable: true, get: function () { return field_js_1.ScalarType; } });
29
- var service_type_js_1 = require("./service-type.js");
30
- Object.defineProperty(exports, "MethodKind", { enumerable: true, get: function () { return service_type_js_1.MethodKind; } });
31
- Object.defineProperty(exports, "MethodIdempotency", { enumerable: true, get: function () { return service_type_js_1.MethodIdempotency; } });
32
- var type_registry_js_1 = require("./type-registry.js");
33
- Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return type_registry_js_1.TypeRegistry; } });
34
- var descriptor_registry_js_1 = require("./descriptor-registry.js");
35
- Object.defineProperty(exports, "DescriptorRegistry", { enumerable: true, get: function () { return descriptor_registry_js_1.DescriptorRegistry; } });
36
- var descriptor_set_js_1 = require("./descriptor-set.js");
37
- Object.defineProperty(exports, "DescriptorSet", { enumerable: true, get: function () { return descriptor_set_js_1.DescriptorSet; } });
38
- var binary_encoding_js_1 = require("./binary-encoding.js");
39
- Object.defineProperty(exports, "WireType", { enumerable: true, get: function () { return binary_encoding_js_1.WireType; } });
40
- Object.defineProperty(exports, "BinaryWriter", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryWriter; } });
41
- Object.defineProperty(exports, "BinaryReader", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryReader; } });
42
- var json_format_js_1 = require("./json-format.js");
@@ -1,42 +0,0 @@
1
- "use strict";
2
- // Copyright 2021-2022 Buf Technologies, Inc.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- var desc = Object.getOwnPropertyDescriptor(m, k);
18
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
- desc = { enumerable: true, get: function() { return m[k]; } };
20
- }
21
- Object.defineProperty(o, k2, desc);
22
- }) : (function(o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- }));
26
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- // ideally, we would export these types with sub-path exports:
31
- __exportStar(require("./google/protobuf/compiler/plugin_pb.js"), exports);
32
- __exportStar(require("./google/protobuf/api_pb.js"), exports);
33
- __exportStar(require("./google/protobuf/any_pb.js"), exports);
34
- __exportStar(require("./google/protobuf/descriptor_pb.js"), exports);
35
- __exportStar(require("./google/protobuf/duration_pb.js"), exports);
36
- __exportStar(require("./google/protobuf/empty_pb.js"), exports);
37
- __exportStar(require("./google/protobuf/field_mask_pb.js"), exports);
38
- __exportStar(require("./google/protobuf/source_context_pb.js"), exports);
39
- __exportStar(require("./google/protobuf/struct_pb.js"), exports);
40
- __exportStar(require("./google/protobuf/timestamp_pb.js"), exports);
41
- __exportStar(require("./google/protobuf/type_pb.js"), exports);
42
- __exportStar(require("./google/protobuf/wrappers_pb.js"), exports);
@@ -1,25 +0,0 @@
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";