@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.1

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 (127) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/binary-encoding.js +402 -410
  3. package/dist/cjs/descriptor-registry.js +407 -449
  4. package/dist/cjs/descriptor-set.js +416 -513
  5. package/dist/cjs/field.js +30 -30
  6. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  7. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  8. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  9. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  10. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  11. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  12. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  13. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  14. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  15. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  16. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  17. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  18. package/dist/cjs/index.js +24 -122
  19. package/dist/cjs/message.js +81 -89
  20. package/dist/cjs/private/assert.js +20 -26
  21. package/dist/cjs/private/base64.js +79 -78
  22. package/dist/cjs/private/binary-format-common.js +195 -208
  23. package/dist/cjs/private/binary-format-proto2.js +75 -109
  24. package/dist/cjs/private/binary-format-proto3.js +57 -90
  25. package/dist/cjs/private/enum.js +38 -43
  26. package/dist/cjs/private/field-list.js +51 -50
  27. package/dist/cjs/private/field-wrapper.js +8 -10
  28. package/dist/cjs/private/field.js +22 -25
  29. package/dist/cjs/private/goog-varint.js +275 -0
  30. package/dist/cjs/private/json-format-common.js +414 -440
  31. package/dist/cjs/private/json-format-proto2.js +78 -89
  32. package/dist/cjs/private/json-format-proto3.js +69 -93
  33. package/dist/cjs/private/message-type.js +26 -27
  34. package/dist/cjs/private/names.js +58 -62
  35. package/dist/cjs/private/proto-runtime.js +11 -16
  36. package/dist/cjs/private/scalars.js +100 -103
  37. package/dist/cjs/private/util-common.js +180 -210
  38. package/dist/cjs/proto-int64.js +111 -112
  39. package/dist/cjs/proto2.js +50 -63
  40. package/dist/cjs/proto3.js +61 -74
  41. package/dist/cjs/service-type.js +14 -17
  42. package/dist/cjs/type-registry.js +33 -31
  43. package/dist/esm/binary-encoding.js +401 -414
  44. package/dist/esm/descriptor-registry.js +409 -458
  45. package/dist/esm/descriptor-set.js +417 -478
  46. package/dist/esm/field.js +29 -29
  47. package/dist/esm/google/protobuf/any_pb.js +122 -140
  48. package/dist/esm/google/protobuf/api_pb.js +177 -197
  49. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  50. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  51. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  52. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  53. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  54. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  55. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  56. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  57. package/dist/esm/google/protobuf/type_pb.js +401 -421
  58. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  59. package/dist/esm/index.js +1 -1
  60. package/dist/esm/message.js +81 -89
  61. package/dist/esm/private/assert.js +19 -21
  62. package/dist/esm/private/base64.js +79 -78
  63. package/dist/esm/private/binary-format-common.js +196 -207
  64. package/dist/esm/private/binary-format-proto2.js +76 -81
  65. package/dist/esm/private/binary-format-proto3.js +58 -67
  66. package/dist/esm/private/enum.js +38 -43
  67. package/dist/esm/private/field-list.js +51 -50
  68. package/dist/esm/private/field-wrapper.js +8 -10
  69. package/dist/esm/private/field.js +22 -22
  70. package/dist/esm/private/goog-varint.js +266 -0
  71. package/dist/esm/private/json-format-common.js +414 -435
  72. package/dist/esm/private/json-format-proto2.js +76 -81
  73. package/dist/esm/private/json-format-proto3.js +66 -80
  74. package/dist/esm/private/message-type.js +27 -28
  75. package/dist/esm/private/names.js +57 -57
  76. package/dist/esm/private/proto-runtime.js +11 -11
  77. package/dist/esm/private/scalars.js +99 -99
  78. package/dist/esm/private/util-common.js +180 -192
  79. package/dist/esm/proto-int64.js +111 -112
  80. package/dist/esm/proto2.js +50 -57
  81. package/dist/esm/proto3.js +61 -68
  82. package/dist/esm/service-type.js +12 -12
  83. package/dist/esm/type-registry.js +33 -31
  84. package/dist/types/binary-encoding.d.ts +398 -398
  85. package/dist/types/binary-format.d.ts +69 -91
  86. package/dist/types/descriptor-registry.d.ts +23 -29
  87. package/dist/types/descriptor-set.d.ts +107 -128
  88. package/dist/types/enum.d.ts +21 -21
  89. package/dist/types/field-list.d.ts +21 -21
  90. package/dist/types/field.d.ts +191 -231
  91. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  92. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  93. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  94. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  95. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  96. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  97. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  98. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  99. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  100. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  101. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  102. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  103. package/dist/types/index.d.ts +4 -27
  104. package/dist/types/json-format.d.ts +70 -89
  105. package/dist/types/message-type.d.ts +38 -46
  106. package/dist/types/message.d.ts +73 -99
  107. package/dist/types/private/assert.d.ts +1 -4
  108. package/dist/types/private/binary-format-common.d.ts +6 -32
  109. package/dist/types/private/enum.d.ts +4 -11
  110. package/dist/types/private/field-list.d.ts +14 -21
  111. package/dist/types/private/field-wrapper.d.ts +5 -11
  112. package/dist/types/private/field.d.ts +12 -12
  113. package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
  114. package/dist/types/private/json-format-common.d.ts +5 -27
  115. package/dist/types/private/message-type.d.ts +3 -8
  116. package/dist/types/private/names.d.ts +1 -4
  117. package/dist/types/private/options-map.d.ts +1 -1
  118. package/dist/types/private/proto-runtime.d.ts +29 -42
  119. package/dist/types/private/scalars.d.ts +5 -12
  120. package/dist/types/private/util-common.d.ts +1 -4
  121. package/dist/types/private/util.d.ts +29 -41
  122. package/dist/types/proto-int64.d.ts +42 -42
  123. package/dist/types/service-type.d.ts +37 -57
  124. package/dist/types/type-registry.d.ts +13 -15
  125. package/package.json +2 -2
  126. package/dist/cjs/google/varint.js +0 -280
  127. package/dist/esm/google/varint.js +0 -265
@@ -8,102 +8,89 @@ import type { IMessageTypeRegistry } from "./type-registry";
8
8
  * based, or delegate to speed optimized generated code.
9
9
  */
10
10
  export interface JsonFormat {
11
- /**
12
- * Provide options for parsing JSON data.
13
- */
14
- makeReadOptions(
15
- options?: Partial<JsonReadOptions>
16
- ): Readonly<JsonReadOptions>;
17
- /**
18
- * Provide options for serializing to JSON.
19
- */
20
- makeWriteOptions(
21
- options?: Partial<JsonWriteStringOptions>
22
- ): Readonly<JsonWriteStringOptions>;
23
- /**
24
- * Parse a message from JSON.
25
- */
26
- readMessage<T extends Message<T>>(
27
- type: MessageType<T>,
28
- jsonValue: JsonValue,
29
- options: JsonReadOptions,
30
- message?: T
31
- ): T;
32
- /**
33
- * Serialize a message to JSON.
34
- */
35
- writeMessage(message: Message, options: JsonWriteOptions): JsonValue;
36
- /**
37
- * Parse a single scalar value from JSON.
38
- * This method may throw an error, but it may have a blank error message.
39
- * Callers are expected to provide context.
40
- */
41
- readScalar(type: ScalarType, json: JsonValue): any;
42
- /**
43
- * Serialize a single scalar value to JSON.
44
- */
45
- writeScalar(
46
- type: ScalarType,
47
- value: any,
48
- emitDefaultValues: boolean
49
- ): JsonValue | undefined;
50
- /**
51
- * Returns a short string representation of a JSON value, suitable for error messages.
52
- */
53
- debug(json: JsonValue): string;
11
+ /**
12
+ * Provide options for parsing JSON data.
13
+ */
14
+ makeReadOptions(options?: Partial<JsonReadOptions>): Readonly<JsonReadOptions>;
15
+ /**
16
+ * Provide options for serializing to JSON.
17
+ */
18
+ makeWriteOptions(options?: Partial<JsonWriteStringOptions>): Readonly<JsonWriteStringOptions>;
19
+ /**
20
+ * Parse a message from JSON.
21
+ */
22
+ readMessage<T extends Message>(type: MessageType<T>, jsonValue: JsonValue, options: JsonReadOptions, message?: T): T;
23
+ /**
24
+ * Serialize a message to JSON.
25
+ */
26
+ writeMessage(message: Message, options: JsonWriteOptions): JsonValue;
27
+ /**
28
+ * Parse a single scalar value from JSON.
29
+ * This method may throw an error, but it may have a blank error message.
30
+ * Callers are expected to provide context.
31
+ */
32
+ readScalar(type: ScalarType, json: JsonValue): any;
33
+ /**
34
+ * Serialize a single scalar value to JSON.
35
+ */
36
+ writeScalar(type: ScalarType, value: any, emitDefaultValues: boolean): JsonValue | undefined;
37
+ /**
38
+ * Returns a short string representation of a JSON value, suitable for error messages.
39
+ */
40
+ debug(json: JsonValue): string;
54
41
  }
55
42
  /**
56
43
  * Options for parsing JSON data.
57
44
  */
58
45
  export interface JsonReadOptions {
59
- /**
60
- * Ignore unknown fields: Proto3 JSON parser should reject unknown fields
61
- * by default. This option ignores unknown fields in parsing, as well as
62
- * unrecognized enum string representations.
63
- */
64
- ignoreUnknownFields: boolean;
65
- /**
66
- * This option is required to read `google.protobuf.Any`
67
- * from JSON format.
68
- */
69
- typeRegistry?: IMessageTypeRegistry;
46
+ /**
47
+ * Ignore unknown fields: Proto3 JSON parser should reject unknown fields
48
+ * by default. This option ignores unknown fields in parsing, as well as
49
+ * unrecognized enum string representations.
50
+ */
51
+ ignoreUnknownFields: boolean;
52
+ /**
53
+ * This option is required to read `google.protobuf.Any`
54
+ * from JSON format.
55
+ */
56
+ typeRegistry?: IMessageTypeRegistry;
70
57
  }
71
58
  /**
72
59
  * Options for serializing to JSON.
73
60
  */
74
61
  export interface JsonWriteOptions {
75
- /**
76
- * Emit fields with default values: Fields with default values are omitted
77
- * by default in proto3 JSON output. This option overrides this behavior
78
- * and outputs fields with their default values.
79
- */
80
- emitDefaultValues: boolean;
81
- /**
82
- * Emit enum values as integers instead of strings: The name of an enum
83
- * value is used by default in JSON output. An option may be provided to
84
- * use the numeric value of the enum value instead.
85
- */
86
- enumAsInteger: boolean;
87
- /**
88
- * Use proto field name instead of lowerCamelCase name: By default proto3
89
- * JSON printer should convert the field name to lowerCamelCase and use
90
- * that as the JSON name. An implementation may provide an option to use
91
- * proto field name as the JSON name instead. Proto3 JSON parsers are
92
- * required to accept both the converted lowerCamelCase name and the proto
93
- * field name.
94
- */
95
- useProtoFieldName: boolean;
96
- /**
97
- * This option is required to write `google.protobuf.Any`
98
- * to JSON format.
99
- */
100
- typeRegistry?: IMessageTypeRegistry;
62
+ /**
63
+ * Emit fields with default values: Fields with default values are omitted
64
+ * by default in proto3 JSON output. This option overrides this behavior
65
+ * and outputs fields with their default values.
66
+ */
67
+ emitDefaultValues: boolean;
68
+ /**
69
+ * Emit enum values as integers instead of strings: The name of an enum
70
+ * value is used by default in JSON output. An option may be provided to
71
+ * use the numeric value of the enum value instead.
72
+ */
73
+ enumAsInteger: boolean;
74
+ /**
75
+ * Use proto field name instead of lowerCamelCase name: By default proto3
76
+ * JSON printer should convert the field name to lowerCamelCase and use
77
+ * that as the JSON name. An implementation may provide an option to use
78
+ * proto field name as the JSON name instead. Proto3 JSON parsers are
79
+ * required to accept both the converted lowerCamelCase name and the proto
80
+ * field name.
81
+ */
82
+ useProtoFieldName: boolean;
83
+ /**
84
+ * This option is required to write `google.protobuf.Any`
85
+ * to JSON format.
86
+ */
87
+ typeRegistry?: IMessageTypeRegistry;
101
88
  }
102
89
  /**
103
90
  * Options for serializing to JSON.
104
91
  */
105
92
  export interface JsonWriteStringOptions extends JsonWriteOptions {
106
- prettySpaces: number;
93
+ prettySpaces: number;
107
94
  }
108
95
  /**
109
96
  * Represents any possible JSON value:
@@ -114,16 +101,10 @@ export interface JsonWriteStringOptions extends JsonWriteOptions {
114
101
  * - object (with any JSON value as property)
115
102
  * - array (with any JSON value as element)
116
103
  */
117
- export declare type JsonValue =
118
- | number
119
- | string
120
- | boolean
121
- | null
122
- | JsonObject
123
- | JsonValue[];
104
+ export declare type JsonValue = number | string | boolean | null | JsonObject | JsonValue[];
124
105
  /**
125
106
  * Represents a JSON object.
126
107
  */
127
108
  export declare type JsonObject = {
128
- [k: string]: JsonValue;
109
+ [k: string]: JsonValue;
129
110
  };
@@ -2,12 +2,7 @@ import type { FieldList } from "./field-list.js";
2
2
  import type { ProtoRuntime } from "./private/proto-runtime.js";
3
3
  import type { JsonReadOptions, JsonValue } from "./json-format.js";
4
4
  import type { BinaryReadOptions } from "./binary-format.js";
5
- import type {
6
- AnyMessage,
7
- Message,
8
- PartialMessage,
9
- PlainMessage,
10
- } from "./message.js";
5
+ import type { DynamicMessage, Message, PartialMessage, PlainMessage } from "./message.js";
11
6
  import type { FieldWrapper } from "./private/field-wrapper.js";
12
7
  /**
13
8
  * MessageType represents a protobuf message. It provides:
@@ -15,44 +10,41 @@ import type { FieldWrapper } from "./private/field-wrapper.js";
15
10
  * - metadata for reflection-based operations
16
11
  * - common functionality like serialization
17
12
  */
18
- export interface MessageType<T extends Message<T> = AnyMessage> {
19
- /**
20
- * Create a new instance of this type.
21
- */
22
- new (data?: PartialMessage<T>): T;
23
- /**
24
- * The fully qualified name of the message.
25
- */
26
- readonly typeName: string;
27
- /**
28
- * Field metadata.
29
- */
30
- readonly fields: FieldList;
31
- /**
32
- * Provides serialization and other functionality.
33
- */
34
- readonly runtime: ProtoRuntime;
35
- /**
36
- * When used as a field, unwrap this message to a simple value.
37
- */
38
- readonly fieldWrapper?: FieldWrapper<T>;
39
- /**
40
- * Parse serialized binary data.
41
- */
42
- fromBinary(data: Uint8Array, options?: Partial<BinaryReadOptions>): T;
43
- /**
44
- * Parse a JSON object.
45
- */
46
- fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): T;
47
- /**
48
- * Parse a JSON string.
49
- */
50
- fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): T;
51
- /**
52
- * Returns true if the given arguments have equal field values, recursively.
53
- */
54
- equals(
55
- a: T | PlainMessage<T> | undefined,
56
- b: T | PlainMessage<T> | undefined
57
- ): boolean;
13
+ export interface MessageType<T extends Message = DynamicMessage> {
14
+ /**
15
+ * Create a new instance of this type.
16
+ */
17
+ new (data?: PartialMessage<T>): T;
18
+ /**
19
+ * The fully qualified name of the message.
20
+ */
21
+ readonly typeName: string;
22
+ /**
23
+ * Field metadata.
24
+ */
25
+ readonly fields: FieldList;
26
+ /**
27
+ * Provides serialization and other functionality.
28
+ */
29
+ readonly runtime: ProtoRuntime;
30
+ /**
31
+ * When used as a field, unwrap this message to a simple value.
32
+ */
33
+ readonly fieldWrapper?: FieldWrapper<T>;
34
+ /**
35
+ * Parse serialized binary data.
36
+ */
37
+ fromBinary(data: Uint8Array, options?: Partial<BinaryReadOptions>): T;
38
+ /**
39
+ * Parse a JSON object.
40
+ */
41
+ fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): T;
42
+ /**
43
+ * Parse a JSON string.
44
+ */
45
+ fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): T;
46
+ /**
47
+ * Returns true if the given arguments have equal field values, recursively.
48
+ */
49
+ equals(a: T | PlainMessage<T> | undefined, b: T | PlainMessage<T> | undefined): boolean;
58
50
  }
@@ -1,79 +1,66 @@
1
1
  import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";
2
- import type {
3
- JsonReadOptions,
4
- JsonValue,
5
- JsonWriteOptions,
6
- JsonWriteStringOptions,
7
- } from "./json-format.js";
2
+ import type { JsonReadOptions, JsonValue, JsonWriteOptions, JsonWriteStringOptions } from "./json-format.js";
8
3
  import type { MessageType } from "./message-type.js";
9
4
  /**
10
- * AnyMessage is an interface implemented by all messages. If you need to
11
- * handle messages of unknown type, this interface provides a convenient
12
- * index signature to access fields with message["fieldname"].
13
- */
14
- export interface AnyMessage extends Message<AnyMessage> {
15
- [k: string]: any;
16
- }
17
- /**
18
- * Message is the base class of every message, generated, or created at
19
- * runtime.
5
+ * Every message - generated or created at runtime - is an instance of this
6
+ * class.
20
7
  *
21
- * It is _not_ safe to extend this class. If you want to create a message at
22
- * run time, use proto3.makeMessageType().
8
+ * It is unsafe to extend this class. If you want to create a message at run
9
+ * time, use proto3.makeMessageType().
23
10
  */
24
- export declare class Message<T extends Message<T> = AnyMessage> {
25
- /**
26
- * Compare with a message of the same type.
27
- */
28
- equals(other: T | PlainMessage<T> | undefined): boolean;
29
- /**
30
- * Create a deep copy.
31
- */
32
- clone(): T;
33
- /**
34
- * Parse from binary data, merging fields.
35
- *
36
- * Repeated fields are appended. Map entries are added, overwriting
37
- * existing keys.
38
- *
39
- * If a message field is already present, it will be merged with the
40
- * new data.
41
- */
42
- fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): this;
43
- /**
44
- * Parse a message from a JSON value.
45
- */
46
- fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): this;
47
- /**
48
- * Parse a message from a JSON string.
49
- */
50
- fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): this;
51
- /**
52
- * Serialize the message to binary data.
53
- */
54
- toBinary(options?: Partial<BinaryWriteOptions>): Uint8Array;
55
- /**
56
- * Serialize the message to a JSON value, a JavaScript value that can be
57
- * passed to JSON.stringify().
58
- */
59
- toJson(options?: Partial<JsonWriteOptions>): JsonValue;
60
- /**
61
- * Serialize the message to a JSON string.
62
- */
63
- toJsonString(options?: Partial<JsonWriteStringOptions>): string;
64
- /**
65
- * Retrieve the MessageType of this message - a singleton that represents
66
- * the protobuf message declaration and provides metadata for reflection-
67
- * based operations.
68
- */
69
- getType(): MessageType<T>;
11
+ export declare class Message<T extends Message = DynamicMessage> {
12
+ /**
13
+ * Compare with a message of the same type.
14
+ */
15
+ equals(other: T | PlainMessage<T> | undefined): boolean;
16
+ /**
17
+ * Create a deep copy.
18
+ */
19
+ clone(): T;
20
+ /**
21
+ * Parse from binary data, merging fields.
22
+ *
23
+ * Repeated fields are appended. Map entries are added, overwriting
24
+ * existing keys.
25
+ *
26
+ * If a message field is already present, it will be merged with the
27
+ * new data.
28
+ */
29
+ fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): this;
30
+ /**
31
+ * Parse a message from a JSON value.
32
+ */
33
+ fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): this;
34
+ /**
35
+ * Parse a message from a JSON string.
36
+ */
37
+ fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): this;
38
+ /**
39
+ * Serialize the message to binary data.
40
+ */
41
+ toBinary(options?: Partial<BinaryWriteOptions>): Uint8Array;
42
+ /**
43
+ * Serialize the message to a JSON value, a JavaScript value that can be
44
+ * passed to JSON.stringify().
45
+ */
46
+ toJson(options?: Partial<JsonWriteOptions>): JsonValue;
47
+ /**
48
+ * Serialize the message to a JSON string.
49
+ */
50
+ toJsonString(options?: Partial<JsonWriteStringOptions>): string;
51
+ /**
52
+ * Retrieve the MessageType of this message - a singleton that represents
53
+ * the protobuf message declaration and provides metadata for reflection-
54
+ * based operations.
55
+ */
56
+ getType(): MessageType<T>;
70
57
  }
71
58
  /**
72
59
  * PlainMessage<T> strips all methods from a message, leaving only fields
73
60
  * and oneof groups.
74
61
  */
75
62
  export declare type PlainMessage<T extends Message> = {
76
- [P in keyof T as T[P] extends Function ? never : P]: T[P];
63
+ [P in keyof T as T[P] extends Function ? never : P]: T[P];
77
64
  };
78
65
  /**
79
66
  * PartialMessage<T> constructs a type from a message. The resulting type
@@ -84,41 +71,28 @@ export declare type PlainMessage<T extends Message> = {
84
71
  * and respects `oneof` groups.
85
72
  */
86
73
  export declare type PartialMessage<T extends Message> = {
87
- [P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
74
+ [P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
88
75
  };
89
- declare type PartialField<F> = F extends
90
- | Date
91
- | Uint8Array
92
- | bigint
93
- | boolean
94
- | string
95
- | number
96
- ? F
97
- : F extends Array<infer U>
98
- ? Array<PartialField<U>>
99
- : F extends ReadonlyArray<infer U>
100
- ? ReadonlyArray<PartialField<U>>
101
- : F extends OneofSelectedMessage<infer C, infer V>
102
- ? {
103
- case: C;
104
- value: PartialMessage<V>;
105
- }
106
- : F extends {
107
- case: string | undefined;
108
- value?: unknown;
109
- }
110
- ? F
111
- : F extends Message
112
- ? PartialMessage<F>
113
- : F extends {
114
- [key: string | number]: Message<infer U>;
115
- }
116
- ? {
117
- [key: string | number]: PartialMessage<U>;
118
- }
119
- : F;
76
+ declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends OneofSelectedMessage<infer C, infer V> ? {
77
+ case: C;
78
+ value: PartialMessage<V>;
79
+ } : F extends {
80
+ case: string | undefined;
81
+ value?: unknown;
82
+ } ? F : F extends Message ? PartialMessage<F> : F extends {
83
+ [key: string | number]: Message<infer U>;
84
+ } ? {
85
+ [key: string | number]: PartialMessage<U>;
86
+ } : F;
120
87
  declare type OneofSelectedMessage<K extends string, M extends Message> = {
121
- case: K;
122
- value: M;
88
+ case: K;
89
+ value: M;
90
+ };
91
+ /**
92
+ * DynamicMessage exposes the fields of the message with an index signature,
93
+ * which means that fields can be accessed with message["fieldname"].
94
+ */
95
+ export declare type DynamicMessage = Message & {
96
+ [k: string]: any;
123
97
  };
124
98
  export {};
@@ -1,10 +1,7 @@
1
1
  /**
2
2
  * Assert that condition is truthy or throw error (with message)
3
3
  */
4
- export declare function assert(
5
- condition: unknown,
6
- msg?: string
7
- ): asserts condition;
4
+ export declare function assert(condition: unknown, msg?: string): asserts condition;
8
5
  /**
9
6
  * Assert a valid signed protobuf 32-bit integer.
10
7
  */
@@ -3,36 +3,10 @@ import type { BinaryWriteOptions } from "../binary-format.js";
3
3
  import type { BinaryFormat } from "../binary-format.js";
4
4
  import { FieldInfo, ScalarType } from "../field.js";
5
5
  import type { MessageType } from "../message-type.js";
6
- export declare function makeBinaryFormatCommon(): Omit<
7
- BinaryFormat,
8
- "writeMessage"
9
- >;
10
- export declare function writeMapEntry(
11
- writer: IBinaryWriter,
12
- options: BinaryWriteOptions,
13
- field: FieldInfo & {
6
+ export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">;
7
+ export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
14
8
  kind: "map";
15
- },
16
- key: any,
17
- value: any
18
- ): void;
19
- export declare function writeMessageField(
20
- writer: IBinaryWriter,
21
- options: BinaryWriteOptions,
22
- type: MessageType,
23
- fieldNo: number,
24
- value: any
25
- ): void;
26
- export declare function writeScalar(
27
- writer: IBinaryWriter,
28
- type: ScalarType,
29
- fieldNo: number,
30
- value: any,
31
- emitIntrinsicDefault: boolean
32
- ): void;
33
- export declare function writePacked(
34
- writer: IBinaryWriter,
35
- type: ScalarType,
36
- fieldNo: number,
37
- value: any[]
38
- ): void;
9
+ }, key: any, value: any): void;
10
+ export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, type: MessageType, fieldNo: number, value: any): void;
11
+ export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
12
+ export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
@@ -3,8 +3,8 @@ import type { EnumType, EnumValueInfo } from "../enum.js";
3
3
  * Represents a generated enum.
4
4
  */
5
5
  export interface EnumObject {
6
- [key: number]: string;
7
- [k: string]: number | string;
6
+ [key: number]: string;
7
+ [k: string]: number | string;
8
8
  }
9
9
  /**
10
10
  * Get reflection information from a generated enum.
@@ -15,15 +15,8 @@ export declare function getEnumType(enumObject: EnumObject): EnumType;
15
15
  /**
16
16
  * Sets reflection information on a generated enum.
17
17
  */
18
- export declare function setEnumType(
19
- enumObject: EnumObject,
20
- typeName: string,
21
- values: EnumValueInfo[]
22
- ): void;
18
+ export declare function setEnumType(enumObject: EnumObject, typeName: string, values: EnumValueInfo[]): void;
23
19
  /**
24
20
  * Create a new EnumType with the given values.
25
21
  */
26
- export declare function makeEnumType(
27
- typeName: string,
28
- values: EnumValueInfo[]
29
- ): EnumType;
22
+ export declare function makeEnumType(typeName: string, values: EnumValueInfo[]): EnumType;
@@ -1,25 +1,18 @@
1
1
  import type { FieldInfo, OneofInfo, PartialFieldInfo } from "../field.js";
2
2
  import type { FieldList } from "../field-list.js";
3
- export declare type FieldListSource =
4
- | readonly PartialFieldInfo[]
5
- | readonly FieldInfo[]
6
- | (() => readonly PartialFieldInfo[])
7
- | (() => readonly FieldInfo[]);
3
+ export declare type FieldListSource = readonly PartialFieldInfo[] | readonly FieldInfo[] | (() => readonly PartialFieldInfo[]) | (() => readonly FieldInfo[]);
8
4
  export declare class InternalFieldList implements FieldList {
9
- private readonly _fields;
10
- private readonly _normalizer;
11
- private all?;
12
- private numbersAsc?;
13
- private jsonNames?;
14
- private numbers?;
15
- private members?;
16
- constructor(
17
- fields: FieldListSource,
18
- normalizer: (p: FieldListSource) => FieldInfo[]
19
- );
20
- findJsonName(jsonName: string): FieldInfo | undefined;
21
- find(fieldNo: number): FieldInfo | undefined;
22
- list(): readonly FieldInfo[];
23
- byNumber(): readonly FieldInfo[];
24
- byMember(): readonly (FieldInfo | OneofInfo)[];
5
+ private readonly _fields;
6
+ private readonly _normalizer;
7
+ private all?;
8
+ private numbersAsc?;
9
+ private jsonNames?;
10
+ private numbers?;
11
+ private members?;
12
+ constructor(fields: FieldListSource, normalizer: (p: FieldListSource) => FieldInfo[]);
13
+ findJsonName(jsonName: string): FieldInfo | undefined;
14
+ find(fieldNo: number): FieldInfo | undefined;
15
+ list(): readonly FieldInfo[];
16
+ byNumber(): readonly FieldInfo[];
17
+ byMember(): readonly (FieldInfo | OneofInfo)[];
25
18
  }
@@ -7,21 +7,15 @@ import type { MessageType } from "../message-type.js";
7
7
  * Note that this feature exists for google/protobuf/{wrappers,struct}.proto
8
8
  * and cannot be used to arbitrarily modify types in generated code.
9
9
  */
10
- export interface FieldWrapper<T extends Message<T> = any, U = any> {
11
- wrapField(value: U): T;
12
- unwrapField(value: T): U;
10
+ export interface FieldWrapper<T extends Message = any, U = any> {
11
+ wrapField(value: U): T;
12
+ unwrapField(value: T): U;
13
13
  }
14
14
  /**
15
15
  * Wrap field values whose message type has a wrapper.
16
16
  */
17
- export declare function wrapField<T extends Message<T>>(
18
- type: MessageType<T>,
19
- value: any
20
- ): T;
17
+ export declare function wrapField<T extends Message>(type: MessageType<T>, value: any): T;
21
18
  /**
22
19
  * Unwrap field values whose message type has a wrapper.
23
20
  */
24
- export declare function unwrapField<T extends Message<T>>(
25
- type: MessageType<T>,
26
- value: T
27
- ): any;
21
+ export declare function unwrapField<T extends Message>(type: MessageType<T>, value: T): any;
@@ -1,15 +1,15 @@
1
1
  import type { FieldInfo, OneofInfo } from "../field.js";
2
2
  export declare class InternalOneofInfo implements OneofInfo {
3
- readonly kind = "oneof";
4
- readonly name: string;
5
- readonly localName: string;
6
- readonly repeated = false;
7
- readonly packed = false;
8
- readonly opt = false;
9
- readonly default: undefined;
10
- readonly fields: FieldInfo[];
11
- private _lookup?;
12
- constructor(name: string);
13
- addField(field: FieldInfo): void;
14
- findField(localName: string): FieldInfo | undefined;
3
+ readonly kind = "oneof";
4
+ readonly name: string;
5
+ readonly localName: string;
6
+ readonly repeated = false;
7
+ readonly packed = false;
8
+ readonly opt = false;
9
+ readonly default: undefined;
10
+ readonly fields: FieldInfo[];
11
+ private _lookup?;
12
+ constructor(name: string);
13
+ addField(field: FieldInfo): void;
14
+ findField(localName: string): FieldInfo | undefined;
15
15
  }