@bufbuild/protobuf 1.3.0 → 1.3.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 (119) hide show
  1. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  2. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  3. package/dist/cjs/private/json-format-common.js +2 -1
  4. package/dist/cjs/private/util-common.js +37 -8
  5. package/dist/esm/binary-encoding.d.ts +421 -0
  6. package/dist/esm/binary-format.d.ts +87 -0
  7. package/dist/esm/codegen-info.d.ts +23 -0
  8. package/dist/esm/create-descriptor-set.d.ts +16 -0
  9. package/dist/esm/create-registry-from-desc.d.ts +15 -0
  10. package/dist/esm/create-registry.d.ts +8 -0
  11. package/dist/esm/descriptor-set.d.ts +606 -0
  12. package/dist/esm/enum.d.ts +35 -0
  13. package/dist/esm/field-list.d.ts +27 -0
  14. package/dist/esm/field.d.ts +255 -0
  15. package/dist/esm/google/protobuf/any_pb.d.ts +156 -0
  16. package/dist/esm/google/protobuf/api_pb.d.ts +256 -0
  17. package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +236 -0
  18. package/dist/esm/google/protobuf/descriptor_pb.d.ts +1851 -0
  19. package/dist/esm/google/protobuf/duration_pb.d.ts +100 -0
  20. package/dist/esm/google/protobuf/empty_pb.d.ts +28 -0
  21. package/dist/esm/google/protobuf/field_mask_pb.d.ts +227 -0
  22. package/dist/esm/google/protobuf/source_context_pb.d.ts +29 -0
  23. package/dist/esm/google/protobuf/struct_pb.d.ts +158 -0
  24. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  25. package/dist/esm/google/protobuf/timestamp_pb.d.ts +132 -0
  26. package/dist/esm/google/protobuf/type_pb.d.ts +437 -0
  27. package/dist/esm/google/protobuf/type_pb.js +1 -1
  28. package/dist/esm/google/protobuf/wrappers_pb.d.ts +267 -0
  29. package/dist/esm/google/varint.d.ts +70 -0
  30. package/dist/esm/index.d.ts +38 -0
  31. package/dist/esm/json-format.d.ts +110 -0
  32. package/dist/esm/message-type.d.ts +51 -0
  33. package/dist/esm/message.d.ts +130 -0
  34. package/dist/esm/private/assert.d.ts +16 -0
  35. package/dist/esm/private/binary-format-common.d.ts +13 -0
  36. package/dist/esm/private/binary-format-proto2.d.ts +2 -0
  37. package/dist/esm/private/binary-format-proto3.d.ts +2 -0
  38. package/dist/esm/private/enum.d.ts +27 -0
  39. package/dist/esm/private/field-list.d.ts +18 -0
  40. package/dist/esm/private/field-wrapper.d.ts +25 -0
  41. package/dist/esm/private/field.d.ts +15 -0
  42. package/dist/esm/private/json-format-common.d.ts +9 -0
  43. package/dist/esm/private/json-format-common.js +2 -1
  44. package/dist/esm/private/json-format-proto2.d.ts +2 -0
  45. package/dist/esm/private/json-format-proto3.d.ts +2 -0
  46. package/dist/esm/private/message-type.d.ts +18 -0
  47. package/dist/esm/private/names.d.ts +43 -0
  48. package/dist/esm/private/options-map.d.ts +7 -0
  49. package/dist/esm/private/proto-runtime.d.ts +47 -0
  50. package/dist/esm/private/reify-wkt.d.ts +100 -0
  51. package/dist/esm/private/scalars.d.ts +27 -0
  52. package/dist/esm/private/util-common.d.ts +2 -0
  53. package/dist/esm/private/util-common.js +37 -8
  54. package/dist/esm/private/util.d.ts +38 -0
  55. package/dist/esm/proto-base64.d.ts +18 -0
  56. package/dist/esm/proto-delimited.d.ts +54 -0
  57. package/dist/esm/proto-double.d.ts +5 -0
  58. package/dist/esm/proto-int64.d.ts +95 -0
  59. package/dist/esm/proto2.d.ts +4 -0
  60. package/dist/esm/proto3.d.ts +4 -0
  61. package/dist/esm/service-type.d.ts +96 -0
  62. package/dist/esm/to-plain-message.d.ts +9 -0
  63. package/dist/esm/type-registry.d.ts +30 -0
  64. package/package.json +14 -9
  65. /package/dist/{types → cjs}/binary-encoding.d.ts +0 -0
  66. /package/dist/{types → cjs}/binary-format.d.ts +0 -0
  67. /package/dist/{types → cjs}/codegen-info.d.ts +0 -0
  68. /package/dist/{types → cjs}/create-descriptor-set.d.ts +0 -0
  69. /package/dist/{types → cjs}/create-registry-from-desc.d.ts +0 -0
  70. /package/dist/{types → cjs}/create-registry.d.ts +0 -0
  71. /package/dist/{types → cjs}/descriptor-set.d.ts +0 -0
  72. /package/dist/{types → cjs}/enum.d.ts +0 -0
  73. /package/dist/{types → cjs}/field-list.d.ts +0 -0
  74. /package/dist/{types → cjs}/field.d.ts +0 -0
  75. /package/dist/{types → cjs}/google/protobuf/any_pb.d.ts +0 -0
  76. /package/dist/{types → cjs}/google/protobuf/api_pb.d.ts +0 -0
  77. /package/dist/{types → cjs}/google/protobuf/compiler/plugin_pb.d.ts +0 -0
  78. /package/dist/{types → cjs}/google/protobuf/descriptor_pb.d.ts +0 -0
  79. /package/dist/{types → cjs}/google/protobuf/duration_pb.d.ts +0 -0
  80. /package/dist/{types → cjs}/google/protobuf/empty_pb.d.ts +0 -0
  81. /package/dist/{types → cjs}/google/protobuf/field_mask_pb.d.ts +0 -0
  82. /package/dist/{types → cjs}/google/protobuf/source_context_pb.d.ts +0 -0
  83. /package/dist/{types → cjs}/google/protobuf/struct_pb.d.ts +0 -0
  84. /package/dist/{types → cjs}/google/protobuf/timestamp_pb.d.ts +0 -0
  85. /package/dist/{types → cjs}/google/protobuf/type_pb.d.ts +0 -0
  86. /package/dist/{types → cjs}/google/protobuf/wrappers_pb.d.ts +0 -0
  87. /package/dist/{types → cjs}/google/varint.d.ts +0 -0
  88. /package/dist/{types → cjs}/index.d.ts +0 -0
  89. /package/dist/{types → cjs}/json-format.d.ts +0 -0
  90. /package/dist/{types → cjs}/message-type.d.ts +0 -0
  91. /package/dist/{types → cjs}/message.d.ts +0 -0
  92. /package/dist/{types → cjs}/private/assert.d.ts +0 -0
  93. /package/dist/{types → cjs}/private/binary-format-common.d.ts +0 -0
  94. /package/dist/{types → cjs}/private/binary-format-proto2.d.ts +0 -0
  95. /package/dist/{types → cjs}/private/binary-format-proto3.d.ts +0 -0
  96. /package/dist/{types → cjs}/private/enum.d.ts +0 -0
  97. /package/dist/{types → cjs}/private/field-list.d.ts +0 -0
  98. /package/dist/{types → cjs}/private/field-wrapper.d.ts +0 -0
  99. /package/dist/{types → cjs}/private/field.d.ts +0 -0
  100. /package/dist/{types → cjs}/private/json-format-common.d.ts +0 -0
  101. /package/dist/{types → cjs}/private/json-format-proto2.d.ts +0 -0
  102. /package/dist/{types → cjs}/private/json-format-proto3.d.ts +0 -0
  103. /package/dist/{types → cjs}/private/message-type.d.ts +0 -0
  104. /package/dist/{types → cjs}/private/names.d.ts +0 -0
  105. /package/dist/{types → cjs}/private/options-map.d.ts +0 -0
  106. /package/dist/{types → cjs}/private/proto-runtime.d.ts +0 -0
  107. /package/dist/{types → cjs}/private/reify-wkt.d.ts +0 -0
  108. /package/dist/{types → cjs}/private/scalars.d.ts +0 -0
  109. /package/dist/{types → cjs}/private/util-common.d.ts +0 -0
  110. /package/dist/{types → cjs}/private/util.d.ts +0 -0
  111. /package/dist/{types → cjs}/proto-base64.d.ts +0 -0
  112. /package/dist/{types → cjs}/proto-delimited.d.ts +0 -0
  113. /package/dist/{types → cjs}/proto-double.d.ts +0 -0
  114. /package/dist/{types → cjs}/proto-int64.d.ts +0 -0
  115. /package/dist/{types → cjs}/proto2.d.ts +0 -0
  116. /package/dist/{types → cjs}/proto3.d.ts +0 -0
  117. /package/dist/{types → cjs}/service-type.d.ts +0 -0
  118. /package/dist/{types → cjs}/to-plain-message.d.ts +0 -0
  119. /package/dist/{types → cjs}/type-registry.d.ts +0 -0
@@ -0,0 +1,13 @@
1
+ import type { IBinaryWriter } from "../binary-encoding.js";
2
+ import type { BinaryWriteOptions } from "../binary-format.js";
3
+ import type { BinaryFormat } from "../binary-format.js";
4
+ import { ScalarType } from "../field.js";
5
+ import type { FieldInfo } from "../field.js";
6
+ import type { MessageType } from "../message-type.js";
7
+ export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">;
8
+ export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
9
+ kind: "map";
10
+ }, key: any, value: any): void;
11
+ export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, type: MessageType, fieldNo: number, value: any): void;
12
+ export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
13
+ export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
@@ -0,0 +1,2 @@
1
+ import type { BinaryFormat } from "../binary-format.js";
2
+ export declare function makeBinaryFormatProto2(): BinaryFormat;
@@ -0,0 +1,2 @@
1
+ import type { BinaryFormat } from "../binary-format.js";
2
+ export declare function makeBinaryFormatProto3(): BinaryFormat;
@@ -0,0 +1,27 @@
1
+ import type { EnumType, EnumValueInfo } from "../enum.js";
2
+ /**
3
+ * Represents a generated enum.
4
+ */
5
+ export interface EnumObject {
6
+ [key: number]: string;
7
+ [k: string]: number | string;
8
+ }
9
+ /**
10
+ * Get reflection information from a generated enum.
11
+ * If this function is called on something other than a generated
12
+ * enum, it raises an error.
13
+ */
14
+ export declare function getEnumType(enumObject: EnumObject): EnumType;
15
+ /**
16
+ * Sets reflection information on a generated enum.
17
+ */
18
+ export declare function setEnumType(enumObject: EnumObject, typeName: string, values: Omit<EnumValueInfo, "localName">[], opt?: {}): void;
19
+ /**
20
+ * Create a new EnumType with the given values.
21
+ */
22
+ export declare function makeEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[], _opt?: {}): EnumType;
23
+ /**
24
+ * Create a new enum object with the given values.
25
+ * Sets reflection information.
26
+ */
27
+ export declare function makeEnum(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[], opt?: {}): EnumObject;
@@ -0,0 +1,18 @@
1
+ import type { FieldInfo, OneofInfo, PartialFieldInfo } from "../field.js";
2
+ import type { FieldList } from "../field-list.js";
3
+ export type FieldListSource = readonly PartialFieldInfo[] | readonly FieldInfo[] | (() => readonly PartialFieldInfo[]) | (() => readonly FieldInfo[]);
4
+ export declare class InternalFieldList implements FieldList {
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)[];
18
+ }
@@ -0,0 +1,25 @@
1
+ import { Message } from "../message.js";
2
+ import type { MessageType } from "../message-type.js";
3
+ import type { DescField } from "../descriptor-set.js";
4
+ import { ScalarType } from "../field.js";
5
+ /**
6
+ * A field wrapper unwraps a message to a primitive value that is more
7
+ * ergonomic for use as a message field.
8
+ *
9
+ * Note that this feature exists for google/protobuf/wrappers.proto
10
+ * and cannot be used to arbitrarily modify types in generated code.
11
+ */
12
+ export interface FieldWrapper<T extends Message<T> = any, U = any> {
13
+ wrapField(value: U): T;
14
+ unwrapField(value: T): U;
15
+ }
16
+ /**
17
+ * Wrap a primitive message field value in its corresponding wrapper
18
+ * message. This function is idempotent.
19
+ */
20
+ export declare function wrapField<T extends Message<T>>(type: MessageType<T>, value: any): T;
21
+ /**
22
+ * If the given field uses one of the well-known wrapper types, return
23
+ * the primitive type it wraps.
24
+ */
25
+ export declare function getUnwrappedFieldType(field: DescField): ScalarType | undefined;
@@ -0,0 +1,15 @@
1
+ import type { FieldInfo, OneofInfo } from "../field.js";
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;
15
+ }
@@ -0,0 +1,9 @@
1
+ import type { JsonFormat, JsonValue, JsonWriteOptions } from "../json-format.js";
2
+ import { ScalarType } from "../field.js";
3
+ import type { FieldInfo } from "../field.js";
4
+ import type { EnumType } from "../enum.js";
5
+ type JsonFormatWriteFieldFn = (field: FieldInfo, value: any, options: JsonWriteOptions) => JsonValue | undefined;
6
+ export declare function makeJsonFormatCommon(makeWriteField: (writeEnumFn: typeof writeEnum, writeScalarFn: typeof writeScalar) => JsonFormatWriteFieldFn): JsonFormat;
7
+ declare function writeEnum(type: EnumType, value: number | undefined, emitIntrinsicDefault: boolean, enumAsInteger: boolean): JsonValue | undefined;
8
+ declare function writeScalar(type: ScalarType, value: any, emitIntrinsicDefault: boolean): JsonValue | undefined;
9
+ export {};
@@ -256,7 +256,7 @@ function debugJsonValue(json) {
256
256
  case "string":
257
257
  return json.length > 100 ? "string" : `"${json.split('"').join('\\"')}"`;
258
258
  default:
259
- return json.toString();
259
+ return String(json);
260
260
  }
261
261
  }
262
262
  // May throw an error. If the error message is non-blank, it should be shown.
@@ -386,6 +386,7 @@ function readEnum(type, json, ignoreUnknownFields) {
386
386
  break;
387
387
  case "string":
388
388
  const value = type.findName(json);
389
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
389
390
  if (value || ignoreUnknownFields) {
390
391
  return value === null || value === void 0 ? void 0 : value.no;
391
392
  }
@@ -0,0 +1,2 @@
1
+ import type { JsonFormat } from "../json-format.js";
2
+ export declare function makeJsonFormatProto2(): JsonFormat;
@@ -0,0 +1,2 @@
1
+ import type { JsonFormat } from "../json-format.js";
2
+ export declare function makeJsonFormatProto3(): JsonFormat;
@@ -0,0 +1,18 @@
1
+ import { Message } from "../message.js";
2
+ import type { AnyMessage } from "../message.js";
3
+ import type { FieldListSource } from "./field-list.js";
4
+ import type { MessageType } from "../message-type.js";
5
+ import type { ProtoRuntime } from "./proto-runtime.js";
6
+ /**
7
+ * Create a new message type using the given runtime.
8
+ */
9
+ export declare function makeMessageType<T extends Message<T> = AnyMessage>(runtime: ProtoRuntime, typeName: string, fields: FieldListSource, opt?: {
10
+ /**
11
+ * localName is the "name" property of the constructed function.
12
+ * It is useful in stack traces, debuggers and test frameworks,
13
+ * but has no other implications.
14
+ *
15
+ * If omitted, the last part of the typeName is used.
16
+ */
17
+ localName?: string;
18
+ }): MessageType<T>;
@@ -0,0 +1,43 @@
1
+ import type { DescEnum, DescEnumValue, DescField, DescMessage, DescService } from "../descriptor-set.js";
2
+ import type { DescMethod, DescOneof } from "../descriptor-set.js";
3
+ /**
4
+ * Returns the name of a protobuf element in generated code.
5
+ *
6
+ * Field names - including oneofs - are converted to lowerCamelCase. For
7
+ * messages, enumerations and services, the package name is stripped from
8
+ * the type name. For nested messages and enumerations, the names are joined
9
+ * with an underscore. For methods, the first character is made lowercase.
10
+ */
11
+ export declare function localName(desc: DescEnum | DescEnumValue | DescMessage | DescOneof | DescField | DescService | DescMethod): string;
12
+ /**
13
+ * Returns the name of a field in generated code.
14
+ */
15
+ export declare function localFieldName(protoName: string, inOneof: boolean): string;
16
+ /**
17
+ * Returns the name of a oneof group in generated code.
18
+ */
19
+ export declare function localOneofName(protoName: string): string;
20
+ /**
21
+ * Returns the JSON name for a protobuf field, exactly like protoc does.
22
+ */
23
+ export declare const fieldJsonName: typeof protoCamelCase;
24
+ /**
25
+ * Finds a prefix shared by enum values, for example `MY_ENUM_` for
26
+ * `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`.
27
+ */
28
+ export declare function findEnumSharedPrefix(enumName: string, valueNames: string[]): string | undefined;
29
+ /**
30
+ * Converts snake_case to protoCamelCase according to the convention
31
+ * used by protoc to convert a field name to a JSON name.
32
+ */
33
+ declare function protoCamelCase(snakeCase: string): string;
34
+ /**
35
+ * Names that cannot be used for object properties because they are reserved
36
+ * by built-in JavaScript properties.
37
+ */
38
+ export declare const safeObjectProperty: (name: string) => string;
39
+ /**
40
+ * Names that can be used for identifiers or class properties
41
+ */
42
+ export declare const safeIdentifier: (name: string) => string;
43
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { JsonValue } from "../json-format";
2
+ /**
3
+ *
4
+ */
5
+ export type OptionsMap = {
6
+ readonly [extensionName: string]: JsonValue;
7
+ };
@@ -0,0 +1,47 @@
1
+ import type { JsonFormat } from "../json-format.js";
2
+ import type { BinaryFormat } from "../binary-format.js";
3
+ import type { AnyMessage } from "../message.js";
4
+ import type { Message } from "../message.js";
5
+ import type { EnumType, EnumValueInfo } from "../enum.js";
6
+ import type { MessageType } from "../message-type.js";
7
+ import type { FieldListSource } from "./field-list.js";
8
+ import type { EnumObject } from "./enum.js";
9
+ import type { Util } from "./util.js";
10
+ /**
11
+ * A facade that provides serialization and other internal functionality.
12
+ */
13
+ export interface ProtoRuntime {
14
+ readonly syntax: string;
15
+ readonly json: JsonFormat;
16
+ readonly bin: BinaryFormat;
17
+ readonly util: Util;
18
+ /**
19
+ * Create a message type at runtime, without generating code.
20
+ */
21
+ makeMessageType<T extends Message<T> = AnyMessage>(typeName: string, fields: FieldListSource, opt?: {
22
+ localName?: string;
23
+ }): MessageType<T>;
24
+ /**
25
+ * Create an enum object at runtime, without generating code.
26
+ *
27
+ * The object conforms to TypeScript enums, and comes with
28
+ * mapping from name to value, and from value to name.
29
+ *
30
+ * The type name and other reflection information is accessible
31
+ * via getEnumType().
32
+ */
33
+ makeEnum(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[], opt?: {}): EnumObject;
34
+ /**
35
+ * Create an enum type at runtime, without generating code.
36
+ * Note that this only creates the reflection information, not an
37
+ * actual enum object.
38
+ */
39
+ makeEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[], opt?: {}): EnumType;
40
+ /**
41
+ * Get reflection information - the EnumType - from an enum object.
42
+ * If this function is called on something other than a generated
43
+ * enum, or an enum constructed with makeEnum(), it raises an error.
44
+ */
45
+ getEnumType(enumObject: EnumObject): EnumType;
46
+ }
47
+ export declare function makeProtoRuntime(syntax: string, json: JsonFormat, bin: BinaryFormat, util: Util): ProtoRuntime;
@@ -0,0 +1,100 @@
1
+ import type { DescField, DescMessage, DescOneof } from "../descriptor-set.js";
2
+ type DescWkt = {
3
+ typeName: "google.protobuf.Any";
4
+ typeUrl: DescField;
5
+ value: DescField;
6
+ } | {
7
+ typeName: "google.protobuf.Timestamp";
8
+ seconds: DescField;
9
+ nanos: DescField;
10
+ } | {
11
+ typeName: "google.protobuf.Duration";
12
+ seconds: DescField;
13
+ nanos: DescField;
14
+ } | {
15
+ typeName: "google.protobuf.Struct";
16
+ fields: DescField & {
17
+ fieldKind: "map";
18
+ };
19
+ } | {
20
+ typeName: "google.protobuf.Value";
21
+ kind: DescOneof;
22
+ nullValue: DescField & {
23
+ fieldKind: "enum";
24
+ };
25
+ numberValue: DescField;
26
+ stringValue: DescField;
27
+ boolValue: DescField;
28
+ structValue: DescField & {
29
+ fieldKind: "message";
30
+ };
31
+ listValue: DescField & {
32
+ fieldKind: "message";
33
+ };
34
+ } | {
35
+ typeName: "google.protobuf.ListValue";
36
+ values: DescField & {
37
+ fieldKind: "message";
38
+ };
39
+ } | {
40
+ typeName: "google.protobuf.FieldMask";
41
+ paths: DescField;
42
+ } | {
43
+ typeName: "google.protobuf.DoubleValue";
44
+ value: DescField & {
45
+ fieldKind: "scalar";
46
+ };
47
+ } | {
48
+ typeName: "google.protobuf.FloatValue";
49
+ value: DescField & {
50
+ fieldKind: "scalar";
51
+ };
52
+ } | {
53
+ typeName: "google.protobuf.Int64Value";
54
+ value: DescField & {
55
+ fieldKind: "scalar";
56
+ };
57
+ } | {
58
+ typeName: "google.protobuf.UInt64Value";
59
+ value: DescField & {
60
+ fieldKind: "scalar";
61
+ };
62
+ } | {
63
+ typeName: "google.protobuf.Int32Value";
64
+ value: DescField & {
65
+ fieldKind: "scalar";
66
+ };
67
+ } | {
68
+ typeName: "google.protobuf.UInt32Value";
69
+ value: DescField & {
70
+ fieldKind: "scalar";
71
+ };
72
+ } | {
73
+ typeName: "google.protobuf.BoolValue";
74
+ value: DescField & {
75
+ fieldKind: "scalar";
76
+ };
77
+ } | {
78
+ typeName: "google.protobuf.StringValue";
79
+ value: DescField & {
80
+ fieldKind: "scalar";
81
+ };
82
+ } | {
83
+ typeName: "google.protobuf.BytesValue";
84
+ value: DescField & {
85
+ fieldKind: "scalar";
86
+ };
87
+ };
88
+ /**
89
+ * Reifies a given DescMessage into a more concrete object representing its
90
+ * respective well-known type. The returned object will contain properties
91
+ * representing the WKT's defined fields.
92
+ *
93
+ * Useful during code generation when immediate access to a particular field
94
+ * is needed without having to search the object's typename and DescField list.
95
+ *
96
+ * Returns undefined if the WKT cannot be completely constructed via the
97
+ * DescMessage.
98
+ */
99
+ export declare function reifyWkt(message: DescMessage): DescWkt | undefined;
100
+ export {};
@@ -0,0 +1,27 @@
1
+ import { ScalarType } from "../field.js";
2
+ import type { IBinaryWriter } from "../binary-encoding.js";
3
+ import { WireType } from "../binary-encoding.js";
4
+ /**
5
+ * Returns true if both scalar values are equal.
6
+ */
7
+ export declare function scalarEquals(type: ScalarType, a: string | boolean | number | bigint | Uint8Array | undefined, b: string | boolean | number | bigint | Uint8Array | undefined): boolean;
8
+ /**
9
+ * Returns the default value for the given scalar type, following
10
+ * proto3 semantics.
11
+ */
12
+ export declare function scalarDefaultValue(type: ScalarType): any;
13
+ /**
14
+ * Get information for writing a scalar value.
15
+ *
16
+ * Returns tuple:
17
+ * [0]: appropriate WireType
18
+ * [1]: name of the appropriate method of IBinaryWriter
19
+ * [2]: whether the given value is a default value for proto3 semantics
20
+ *
21
+ * If argument `value` is omitted, [2] is always false.
22
+ */
23
+ export declare function scalarTypeInfo(type: ScalarType, value?: any): [
24
+ WireType,
25
+ Exclude<keyof IBinaryWriter, "tag" | "raw" | "fork" | "join" | "finish">,
26
+ boolean
27
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Util } from "./util.js";
2
+ export declare function makeUtilCommon(): Omit<Util, "newFieldList" | "initFields">;
@@ -42,17 +42,35 @@ export function makeUtilCommon() {
42
42
  !(val instanceof sourceField.T)) {
43
43
  val = new sourceField.T(val);
44
44
  }
45
+ else if (sourceField &&
46
+ sourceField.kind === "scalar" &&
47
+ sourceField.T === ScalarType.BYTES) {
48
+ val = toU8Arr(val);
49
+ }
45
50
  t[localName] = { case: sk, value: val };
46
51
  break;
47
52
  case "scalar":
48
53
  case "enum":
49
- t[localName] = s[localName];
54
+ let copy = s[localName];
55
+ if (member.T === ScalarType.BYTES) {
56
+ copy = member.repeated
57
+ ? copy.map(toU8Arr)
58
+ : toU8Arr(copy);
59
+ }
60
+ t[localName] = copy;
50
61
  break;
51
62
  case "map":
52
63
  switch (member.V.kind) {
53
64
  case "scalar":
54
65
  case "enum":
55
- Object.assign(t[localName], s[localName]);
66
+ if (member.V.T === ScalarType.BYTES) {
67
+ for (const [k, v] of Object.entries(s[localName])) {
68
+ t[localName][k] = toU8Arr(v);
69
+ }
70
+ }
71
+ else {
72
+ Object.assign(t[localName], s[localName]);
73
+ }
56
74
  break;
57
75
  case "message":
58
76
  const messageType = member.V.T;
@@ -76,7 +94,14 @@ export function makeUtilCommon() {
76
94
  else if (s[localName] !== undefined) {
77
95
  const val = s[localName];
78
96
  if (mt.fieldWrapper) {
79
- t[localName] = val;
97
+ if (
98
+ // We can't use BytesValue.typeName as that will create a circular import
99
+ mt.typeName === "google.protobuf.BytesValue") {
100
+ t[localName] = toU8Arr(val);
101
+ }
102
+ else {
103
+ t[localName] = val;
104
+ }
80
105
  }
81
106
  else {
82
107
  t[localName] = val instanceof mt ? val : new mt(val);
@@ -158,22 +183,22 @@ export function makeUtilCommon() {
158
183
  const source = message[member.localName];
159
184
  let copy;
160
185
  if (member.repeated) {
161
- copy = source.map((e) => cloneSingularField(member, e));
186
+ copy = source.map(cloneSingularField);
162
187
  }
163
188
  else if (member.kind == "map") {
164
189
  copy = any[member.localName];
165
190
  for (const [key, v] of Object.entries(source)) {
166
- copy[key] = cloneSingularField(member.V, v);
191
+ copy[key] = cloneSingularField(v);
167
192
  }
168
193
  }
169
194
  else if (member.kind == "oneof") {
170
195
  const f = member.findField(source.case);
171
196
  copy = f
172
- ? { case: source.case, value: cloneSingularField(f, source.value) }
197
+ ? { case: source.case, value: cloneSingularField(source.value) }
173
198
  : { case: undefined };
174
199
  }
175
200
  else {
176
- copy = cloneSingularField(member, source);
201
+ copy = cloneSingularField(source);
177
202
  }
178
203
  any[member.localName] = copy;
179
204
  }
@@ -182,7 +207,7 @@ export function makeUtilCommon() {
182
207
  };
183
208
  }
184
209
  // clone a single field value - i.e. the element type of repeated fields, the value type of maps
185
- function cloneSingularField(field, value) {
210
+ function cloneSingularField(value) {
186
211
  if (value === undefined) {
187
212
  return value;
188
213
  }
@@ -196,3 +221,7 @@ function cloneSingularField(field, value) {
196
221
  }
197
222
  return value;
198
223
  }
224
+ // converts any ArrayLike<number> to Uint8Array if necessary.
225
+ function toU8Arr(input) {
226
+ return input instanceof Uint8Array ? input : new Uint8Array(input);
227
+ }
@@ -0,0 +1,38 @@
1
+ import type { FieldListSource } from "./field-list.js";
2
+ import type { FieldList } from "../field-list.js";
3
+ import type { EnumObject } from "./enum.js";
4
+ import type { Message, PartialMessage, PlainMessage } from "../message.js";
5
+ import type { MessageType } from "../message-type.js";
6
+ import type { EnumValueInfo } from "../enum.js";
7
+ /**
8
+ * Provides utilities used by generated code.
9
+ * All methods are internal and are not safe to use, they may break with a
10
+ * future release.
11
+ */
12
+ export interface Util {
13
+ /**
14
+ * Create a field list
15
+ */
16
+ newFieldList(fields: FieldListSource): FieldList;
17
+ /**
18
+ * Sets reflection information on a generated enum.
19
+ */
20
+ setEnumType(enumObject: EnumObject, typeName: string, values: Omit<EnumValueInfo, "localName">[], opt?: {}): void;
21
+ /**
22
+ * Set default field values on the target message.
23
+ */
24
+ initFields(target: Message): void;
25
+ /**
26
+ * Set specified field values on the target message, recursively.
27
+ */
28
+ initPartial<T extends Message<T>>(source: PartialMessage<T> | undefined, target: T): void;
29
+ /**
30
+ * Compares two messages of the same type recursively.
31
+ * Will also return true if both messages are `undefined` or `null`.
32
+ */
33
+ equals<T extends Message<T>>(type: MessageType<T>, a: T | PlainMessage<T> | undefined | null, b: T | PlainMessage<T> | undefined | null): boolean;
34
+ /**
35
+ * Create a deep copy.
36
+ */
37
+ clone<T extends Message<T>>(message: T): T;
38
+ }
@@ -0,0 +1,18 @@
1
+ export declare const protoBase64: {
2
+ /**
3
+ * Decodes a base64 string to a byte array.
4
+ *
5
+ * - ignores white-space, including line breaks and tabs
6
+ * - allows inner padding (can decode concatenated base64 strings)
7
+ * - does not require padding
8
+ * - understands base64url encoding:
9
+ * "-" instead of "+",
10
+ * "_" instead of "/",
11
+ * no padding
12
+ */
13
+ readonly dec: (base64Str: string) => Uint8Array;
14
+ /**
15
+ * Encode a byte array to a base64 string.
16
+ */
17
+ readonly enc: (bytes: Uint8Array) => string;
18
+ };
@@ -0,0 +1,54 @@
1
+ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";
2
+ import type { Message } from "./message.js";
3
+ import type { MessageType } from "./message-type.js";
4
+ /**
5
+ * protoDelimited provides functions to serialize and parse size-delimited
6
+ * messages.
7
+ *
8
+ * A size-delimited message is a varint size in bytes, followed by exactly
9
+ * that many bytes of a message serialized with the binary format.
10
+ *
11
+ * This size-delimited format is compatible with other implementations.
12
+ * For details, see https://github.com/protocolbuffers/protobuf/issues/10229
13
+ */
14
+ export declare const protoDelimited: {
15
+ /**
16
+ * Serialize a message, prefixing it with its size.
17
+ */
18
+ enc(message: Message, options?: BinaryWriteOptions): Uint8Array;
19
+ /**
20
+ * Parse a size-delimited message, ignoring extra bytes.
21
+ */
22
+ dec<T extends Message<T>>(type: MessageType<T>, bytes: Uint8Array, options?: BinaryReadOptions): T;
23
+ /**
24
+ * Parse a stream of size-delimited messages.
25
+ */
26
+ decStream<T_1 extends Message<T_1>>(type: MessageType<T_1>, iterable: AsyncIterable<Uint8Array>): AsyncGenerator<T_1, void, unknown>;
27
+ /**
28
+ * Decodes the size from the given size-delimited message, which may be
29
+ * incomplete.
30
+ *
31
+ * Returns an object with the following properties:
32
+ * - size: The size of the delimited message in bytes
33
+ * - offset: The offset in the given byte array where the message starts
34
+ * - eof: true
35
+ *
36
+ * If the size-delimited data does not include all bytes of the varint size,
37
+ * the following object is returned:
38
+ * - size: null
39
+ * - offset: null
40
+ * - eof: false
41
+ *
42
+ * This function can be used to implement parsing of size-delimited messages
43
+ * from a stream.
44
+ */
45
+ peekSize(data: Uint8Array): {
46
+ readonly eof: false;
47
+ readonly size: number;
48
+ readonly offset: number;
49
+ } | {
50
+ readonly eof: true;
51
+ readonly size: null;
52
+ readonly offset: null;
53
+ };
54
+ };
@@ -0,0 +1,5 @@
1
+ export declare const protoDouble: {
2
+ readonly NaN: number;
3
+ readonly POSITIVE_INFINITY: number;
4
+ readonly NEGATIVE_INFINITY: number;
5
+ };