@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2

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 (138) hide show
  1. package/dist/cjs/binary-encoding.js +414 -409
  2. package/dist/cjs/binary-format.js +13 -0
  3. package/dist/cjs/descriptor-registry.js +420 -449
  4. package/dist/cjs/descriptor-set.js +429 -513
  5. package/dist/cjs/enum.js +13 -0
  6. package/dist/cjs/field-list.js +13 -0
  7. package/dist/cjs/field.js +43 -30
  8. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  9. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  10. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  11. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  12. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  13. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  14. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  15. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  16. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  17. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  18. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  19. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  20. package/dist/cjs/google/varint.js +166 -171
  21. package/dist/cjs/index.js +41 -122
  22. package/dist/cjs/json-format.js +13 -0
  23. package/dist/cjs/message-type.js +13 -0
  24. package/dist/cjs/message.js +89 -85
  25. package/dist/cjs/private/assert.js +33 -26
  26. package/dist/cjs/private/base64.js +93 -79
  27. package/dist/cjs/private/binary-format-common.js +208 -208
  28. package/dist/cjs/private/binary-format-proto2.js +88 -109
  29. package/dist/cjs/private/binary-format-proto3.js +70 -90
  30. package/dist/cjs/private/enum.js +77 -44
  31. package/dist/cjs/private/field-list.js +64 -50
  32. package/dist/cjs/private/field-wrapper.js +21 -10
  33. package/dist/cjs/private/field.js +35 -25
  34. package/dist/cjs/private/json-format-common.js +427 -440
  35. package/dist/cjs/private/json-format-proto2.js +91 -89
  36. package/dist/cjs/private/json-format-proto3.js +82 -93
  37. package/dist/cjs/private/message-type.js +39 -27
  38. package/dist/cjs/private/names.js +71 -62
  39. package/dist/cjs/private/options-map.js +13 -0
  40. package/dist/cjs/private/proto-runtime.js +25 -16
  41. package/dist/cjs/private/scalars.js +113 -103
  42. package/dist/cjs/private/util-common.js +193 -210
  43. package/dist/cjs/private/util.js +13 -0
  44. package/dist/cjs/proto-int64.js +123 -111
  45. package/dist/cjs/proto2.js +63 -63
  46. package/dist/cjs/proto3.js +74 -74
  47. package/dist/cjs/service-type.js +27 -17
  48. package/dist/cjs/type-registry.js +46 -31
  49. package/dist/esm/binary-encoding.js +414 -414
  50. package/dist/esm/binary-format.js +13 -0
  51. package/dist/esm/descriptor-registry.js +422 -458
  52. package/dist/esm/descriptor-set.js +430 -478
  53. package/dist/esm/enum.js +13 -0
  54. package/dist/esm/field-list.js +13 -0
  55. package/dist/esm/field.js +42 -29
  56. package/dist/esm/google/protobuf/any_pb.js +122 -140
  57. package/dist/esm/google/protobuf/api_pb.js +177 -197
  58. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  59. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  60. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  61. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  62. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  63. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  64. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  65. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  66. package/dist/esm/google/protobuf/type_pb.js +401 -421
  67. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  68. package/dist/esm/google/varint.js +165 -164
  69. package/dist/esm/index.js +14 -1
  70. package/dist/esm/json-format.js +13 -0
  71. package/dist/esm/message-type.js +13 -0
  72. package/dist/esm/message.js +89 -85
  73. package/dist/esm/private/assert.js +32 -21
  74. package/dist/esm/private/base64.js +92 -78
  75. package/dist/esm/private/binary-format-common.js +209 -207
  76. package/dist/esm/private/binary-format-proto2.js +89 -81
  77. package/dist/esm/private/binary-format-proto3.js +71 -67
  78. package/dist/esm/private/enum.js +75 -43
  79. package/dist/esm/private/field-list.js +64 -50
  80. package/dist/esm/private/field-wrapper.js +21 -10
  81. package/dist/esm/private/field.js +35 -22
  82. package/dist/esm/private/json-format-common.js +427 -435
  83. package/dist/esm/private/json-format-proto2.js +89 -81
  84. package/dist/esm/private/json-format-proto3.js +79 -80
  85. package/dist/esm/private/message-type.js +40 -28
  86. package/dist/esm/private/names.js +70 -57
  87. package/dist/esm/private/options-map.js +13 -0
  88. package/dist/esm/private/proto-runtime.js +26 -12
  89. package/dist/esm/private/scalars.js +112 -99
  90. package/dist/esm/private/util-common.js +193 -192
  91. package/dist/esm/private/util.js +13 -0
  92. package/dist/esm/proto-int64.js +123 -111
  93. package/dist/esm/proto2.js +63 -57
  94. package/dist/esm/proto3.js +74 -68
  95. package/dist/esm/service-type.js +25 -12
  96. package/dist/esm/type-registry.js +46 -31
  97. package/dist/types/binary-encoding.d.ts +398 -398
  98. package/dist/types/binary-format.d.ts +69 -91
  99. package/dist/types/descriptor-registry.d.ts +23 -29
  100. package/dist/types/descriptor-set.d.ts +107 -128
  101. package/dist/types/enum.d.ts +21 -21
  102. package/dist/types/field-list.d.ts +21 -21
  103. package/dist/types/field.d.ts +191 -231
  104. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  105. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  106. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  107. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  108. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  109. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  110. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  111. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  112. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  113. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  114. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  115. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  116. package/dist/types/google/varint.d.ts +6 -13
  117. package/dist/types/index.d.ts +4 -27
  118. package/dist/types/json-format.d.ts +70 -89
  119. package/dist/types/message-type.d.ts +37 -45
  120. package/dist/types/message.d.ts +62 -87
  121. package/dist/types/private/assert.d.ts +1 -4
  122. package/dist/types/private/binary-format-common.d.ts +6 -32
  123. package/dist/types/private/enum.d.ts +13 -11
  124. package/dist/types/private/field-list.d.ts +14 -21
  125. package/dist/types/private/field-wrapper.d.ts +4 -10
  126. package/dist/types/private/field.d.ts +12 -12
  127. package/dist/types/private/json-format-common.d.ts +5 -27
  128. package/dist/types/private/message-type.d.ts +12 -7
  129. package/dist/types/private/names.d.ts +1 -4
  130. package/dist/types/private/options-map.d.ts +1 -1
  131. package/dist/types/private/proto-runtime.d.ts +34 -42
  132. package/dist/types/private/scalars.d.ts +5 -12
  133. package/dist/types/private/util-common.d.ts +1 -4
  134. package/dist/types/private/util.d.ts +29 -41
  135. package/dist/types/proto-int64.d.ts +42 -42
  136. package/dist/types/service-type.d.ts +36 -56
  137. package/dist/types/type-registry.d.ts +13 -15
  138. package/package.json +2 -3
@@ -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<T>>(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 { AnyMessage, 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:
@@ -16,43 +11,40 @@ import type { FieldWrapper } from "./private/field-wrapper.js";
16
11
  * - common functionality like serialization
17
12
  */
18
13
  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;
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,10 +1,5 @@
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
5
  * AnyMessage is an interface implemented by all messages. If you need to
@@ -12,7 +7,7 @@ import type { MessageType } from "./message-type.js";
12
7
  * index signature to access fields with message["fieldname"].
13
8
  */
14
9
  export interface AnyMessage extends Message<AnyMessage> {
15
- [k: string]: any;
10
+ [k: string]: any;
16
11
  }
17
12
  /**
18
13
  * Message is the base class of every message, generated, or created at
@@ -22,58 +17,58 @@ export interface AnyMessage extends Message<AnyMessage> {
22
17
  * run time, use proto3.makeMessageType().
23
18
  */
24
19
  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>;
20
+ /**
21
+ * Compare with a message of the same type.
22
+ */
23
+ equals(other: T | PlainMessage<T> | undefined): boolean;
24
+ /**
25
+ * Create a deep copy.
26
+ */
27
+ clone(): T;
28
+ /**
29
+ * Parse from binary data, merging fields.
30
+ *
31
+ * Repeated fields are appended. Map entries are added, overwriting
32
+ * existing keys.
33
+ *
34
+ * If a message field is already present, it will be merged with the
35
+ * new data.
36
+ */
37
+ fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): this;
38
+ /**
39
+ * Parse a message from a JSON value.
40
+ */
41
+ fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): this;
42
+ /**
43
+ * Parse a message from a JSON string.
44
+ */
45
+ fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): this;
46
+ /**
47
+ * Serialize the message to binary data.
48
+ */
49
+ toBinary(options?: Partial<BinaryWriteOptions>): Uint8Array;
50
+ /**
51
+ * Serialize the message to a JSON value, a JavaScript value that can be
52
+ * passed to JSON.stringify().
53
+ */
54
+ toJson(options?: Partial<JsonWriteOptions>): JsonValue;
55
+ /**
56
+ * Serialize the message to a JSON string.
57
+ */
58
+ toJsonString(options?: Partial<JsonWriteStringOptions>): string;
59
+ /**
60
+ * Retrieve the MessageType of this message - a singleton that represents
61
+ * the protobuf message declaration and provides metadata for reflection-
62
+ * based operations.
63
+ */
64
+ getType(): MessageType<T>;
70
65
  }
71
66
  /**
72
67
  * PlainMessage<T> strips all methods from a message, leaving only fields
73
68
  * and oneof groups.
74
69
  */
75
70
  export declare type PlainMessage<T extends Message> = {
76
- [P in keyof T as T[P] extends Function ? never : P]: T[P];
71
+ [P in keyof T as T[P] extends Function ? never : P]: T[P];
77
72
  };
78
73
  /**
79
74
  * PartialMessage<T> constructs a type from a message. The resulting type
@@ -84,41 +79,21 @@ export declare type PlainMessage<T extends Message> = {
84
79
  * and respects `oneof` groups.
85
80
  */
86
81
  export declare type PartialMessage<T extends Message> = {
87
- [P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
82
+ [P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
88
83
  };
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;
84
+ 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> ? {
85
+ case: C;
86
+ value: PartialMessage<V>;
87
+ } : F extends {
88
+ case: string | undefined;
89
+ value?: unknown;
90
+ } ? F : F extends Message ? PartialMessage<F> : F extends {
91
+ [key: string | number]: Message<infer U>;
92
+ } ? {
93
+ [key: string | number]: PartialMessage<U>;
94
+ } : F;
120
95
  declare type OneofSelectedMessage<K extends string, M extends Message> = {
121
- case: K;
122
- value: M;
96
+ case: K;
97
+ value: M;
123
98
  };
124
99
  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,17 @@ 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;
23
+ /**
24
+ * Create a new enum object with the given values.
25
+ */
26
+ export declare function makeEnum(typeName: string, values: EnumValueInfo[], opt?: {
27
+ /**
28
+ * MY_ENUM_ for `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`, or blank string
29
+ */
30
+ sharedPrefix?: string;
31
+ }): EnumObject;
@@ -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
  }
@@ -8,20 +8,14 @@ import type { MessageType } from "../message-type.js";
8
8
  * and cannot be used to arbitrarily modify types in generated code.
9
9
  */
10
10
  export interface FieldWrapper<T extends Message<T> = any, U = any> {
11
- wrapField(value: U): T;
12
- unwrapField(value: T): U;
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<T>>(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<T>>(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
  }