@bufbuild/protobuf 1.3.1 → 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.
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/esm/binary-encoding.d.ts +421 -0
- package/dist/esm/binary-format.d.ts +87 -0
- package/dist/esm/codegen-info.d.ts +23 -0
- package/dist/esm/create-descriptor-set.d.ts +16 -0
- package/dist/esm/create-registry-from-desc.d.ts +15 -0
- package/dist/esm/create-registry.d.ts +8 -0
- package/dist/esm/descriptor-set.d.ts +606 -0
- package/dist/esm/enum.d.ts +35 -0
- package/dist/esm/field-list.d.ts +27 -0
- package/dist/esm/field.d.ts +255 -0
- package/dist/esm/google/protobuf/any_pb.d.ts +156 -0
- package/dist/esm/google/protobuf/api_pb.d.ts +256 -0
- package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +236 -0
- package/dist/esm/google/protobuf/descriptor_pb.d.ts +1851 -0
- package/dist/esm/google/protobuf/duration_pb.d.ts +100 -0
- package/dist/esm/google/protobuf/empty_pb.d.ts +28 -0
- package/dist/esm/google/protobuf/field_mask_pb.d.ts +227 -0
- package/dist/esm/google/protobuf/source_context_pb.d.ts +29 -0
- package/dist/esm/google/protobuf/struct_pb.d.ts +158 -0
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/timestamp_pb.d.ts +132 -0
- package/dist/esm/google/protobuf/type_pb.d.ts +437 -0
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/protobuf/wrappers_pb.d.ts +267 -0
- package/dist/esm/google/varint.d.ts +70 -0
- package/dist/esm/index.d.ts +38 -0
- package/dist/esm/json-format.d.ts +110 -0
- package/dist/esm/message-type.d.ts +51 -0
- package/dist/esm/message.d.ts +130 -0
- package/dist/esm/private/assert.d.ts +16 -0
- package/dist/esm/private/binary-format-common.d.ts +13 -0
- package/dist/esm/private/binary-format-proto2.d.ts +2 -0
- package/dist/esm/private/binary-format-proto3.d.ts +2 -0
- package/dist/esm/private/enum.d.ts +27 -0
- package/dist/esm/private/field-list.d.ts +18 -0
- package/dist/esm/private/field-wrapper.d.ts +25 -0
- package/dist/esm/private/field.d.ts +15 -0
- package/dist/esm/private/json-format-common.d.ts +9 -0
- package/dist/esm/private/json-format-proto2.d.ts +2 -0
- package/dist/esm/private/json-format-proto3.d.ts +2 -0
- package/dist/esm/private/message-type.d.ts +18 -0
- package/dist/esm/private/names.d.ts +43 -0
- package/dist/esm/private/options-map.d.ts +7 -0
- package/dist/esm/private/proto-runtime.d.ts +47 -0
- package/dist/esm/private/reify-wkt.d.ts +100 -0
- package/dist/esm/private/scalars.d.ts +27 -0
- package/dist/esm/private/util-common.d.ts +2 -0
- package/dist/esm/private/util.d.ts +38 -0
- package/dist/esm/proto-base64.d.ts +18 -0
- package/dist/esm/proto-delimited.d.ts +54 -0
- package/dist/esm/proto-double.d.ts +5 -0
- package/dist/esm/proto-int64.d.ts +95 -0
- package/dist/esm/proto2.d.ts +4 -0
- package/dist/esm/proto3.d.ts +4 -0
- package/dist/esm/service-type.d.ts +96 -0
- package/dist/esm/to-plain-message.d.ts +9 -0
- package/dist/esm/type-registry.d.ts +30 -0
- package/package.json +14 -9
- /package/dist/{types → cjs}/binary-encoding.d.ts +0 -0
- /package/dist/{types → cjs}/binary-format.d.ts +0 -0
- /package/dist/{types → cjs}/codegen-info.d.ts +0 -0
- /package/dist/{types → cjs}/create-descriptor-set.d.ts +0 -0
- /package/dist/{types → cjs}/create-registry-from-desc.d.ts +0 -0
- /package/dist/{types → cjs}/create-registry.d.ts +0 -0
- /package/dist/{types → cjs}/descriptor-set.d.ts +0 -0
- /package/dist/{types → cjs}/enum.d.ts +0 -0
- /package/dist/{types → cjs}/field-list.d.ts +0 -0
- /package/dist/{types → cjs}/field.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/any_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/api_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/compiler/plugin_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/descriptor_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/duration_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/empty_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/field_mask_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/source_context_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/struct_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/timestamp_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/type_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/protobuf/wrappers_pb.d.ts +0 -0
- /package/dist/{types → cjs}/google/varint.d.ts +0 -0
- /package/dist/{types → cjs}/index.d.ts +0 -0
- /package/dist/{types → cjs}/json-format.d.ts +0 -0
- /package/dist/{types → cjs}/message-type.d.ts +0 -0
- /package/dist/{types → cjs}/message.d.ts +0 -0
- /package/dist/{types → cjs}/private/assert.d.ts +0 -0
- /package/dist/{types → cjs}/private/binary-format-common.d.ts +0 -0
- /package/dist/{types → cjs}/private/binary-format-proto2.d.ts +0 -0
- /package/dist/{types → cjs}/private/binary-format-proto3.d.ts +0 -0
- /package/dist/{types → cjs}/private/enum.d.ts +0 -0
- /package/dist/{types → cjs}/private/field-list.d.ts +0 -0
- /package/dist/{types → cjs}/private/field-wrapper.d.ts +0 -0
- /package/dist/{types → cjs}/private/field.d.ts +0 -0
- /package/dist/{types → cjs}/private/json-format-common.d.ts +0 -0
- /package/dist/{types → cjs}/private/json-format-proto2.d.ts +0 -0
- /package/dist/{types → cjs}/private/json-format-proto3.d.ts +0 -0
- /package/dist/{types → cjs}/private/message-type.d.ts +0 -0
- /package/dist/{types → cjs}/private/names.d.ts +0 -0
- /package/dist/{types → cjs}/private/options-map.d.ts +0 -0
- /package/dist/{types → cjs}/private/proto-runtime.d.ts +0 -0
- /package/dist/{types → cjs}/private/reify-wkt.d.ts +0 -0
- /package/dist/{types → cjs}/private/scalars.d.ts +0 -0
- /package/dist/{types → cjs}/private/util-common.d.ts +0 -0
- /package/dist/{types → cjs}/private/util.d.ts +0 -0
- /package/dist/{types → cjs}/proto-base64.d.ts +0 -0
- /package/dist/{types → cjs}/proto-delimited.d.ts +0 -0
- /package/dist/{types → cjs}/proto-double.d.ts +0 -0
- /package/dist/{types → cjs}/proto-int64.d.ts +0 -0
- /package/dist/{types → cjs}/proto2.d.ts +0 -0
- /package/dist/{types → cjs}/proto3.d.ts +0 -0
- /package/dist/{types → cjs}/service-type.d.ts +0 -0
- /package/dist/{types → cjs}/to-plain-message.d.ts +0 -0
- /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,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 {};
|
|
@@ -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,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,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,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use the `bigint` primitive to represent 64-bit integral types. If bigint
|
|
3
|
+
* is unavailable, we fall back to a string representation, which means that
|
|
4
|
+
* all values typed as `bigint` will actually be strings.
|
|
5
|
+
*
|
|
6
|
+
* If your code is intended to run in an environment where bigint may be
|
|
7
|
+
* unavailable, it must handle both the bigint and the string representation.
|
|
8
|
+
* For presenting values, this is straight-forward with implicit or explicit
|
|
9
|
+
* conversion to string:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* let el = document.createElement("span");
|
|
13
|
+
* el.innerText = message.int64Field; // assuming a protobuf int64 field
|
|
14
|
+
*
|
|
15
|
+
* console.log(`int64: ${message.int64Field}`);
|
|
16
|
+
*
|
|
17
|
+
* let str: string = message.int64Field.toString();
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* If you need to manipulate 64-bit integral values and are sure the values
|
|
21
|
+
* can be safely represented as an IEEE-754 double precision number, you can
|
|
22
|
+
* convert to a JavaScript Number:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* console.log(message.int64Field.toString())
|
|
26
|
+
* let num = Number(message.int64Field);
|
|
27
|
+
* num = num + 1;
|
|
28
|
+
* message.int64Field = protoInt64.parse(num);
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* If you need to manipulate 64-bit integral values that are outside the
|
|
32
|
+
* range of safe representation as a JavaScript Number, we recommend you
|
|
33
|
+
* use a third party library, for example the npm package "long":
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* // convert the field value to a Long
|
|
37
|
+
* const bits = protoInt64.enc(message.int64Field);
|
|
38
|
+
* const longValue = Long.fromBits(bits.lo, bits.hi);
|
|
39
|
+
*
|
|
40
|
+
* // perform arithmetic
|
|
41
|
+
* const longResult = longValue.subtract(1);
|
|
42
|
+
*
|
|
43
|
+
* // set the result in the field
|
|
44
|
+
* message.int64Field = protoInt64.dec(longResult.low, longResult.high);
|
|
45
|
+
*
|
|
46
|
+
* // Assuming int64Field contains 9223372036854775807:
|
|
47
|
+
* console.log(message.int64Field); // 9223372036854775806
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
interface Int64Support {
|
|
51
|
+
/**
|
|
52
|
+
* 0n if bigint is available, "0" if unavailable.
|
|
53
|
+
*/
|
|
54
|
+
readonly zero: bigint;
|
|
55
|
+
/**
|
|
56
|
+
* Is bigint available?
|
|
57
|
+
*/
|
|
58
|
+
readonly supported: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Parse a signed 64-bit integer.
|
|
61
|
+
* Returns a bigint if available, a string otherwise.
|
|
62
|
+
*/
|
|
63
|
+
parse(value: string | number | bigint): bigint;
|
|
64
|
+
/**
|
|
65
|
+
* Parse an unsigned 64-bit integer.
|
|
66
|
+
* Returns a bigint if available, a string otherwise.
|
|
67
|
+
*/
|
|
68
|
+
uParse(value: string | number | bigint): bigint;
|
|
69
|
+
/**
|
|
70
|
+
* Convert a signed 64-bit integral value to a two's complement.
|
|
71
|
+
*/
|
|
72
|
+
enc(value: string | number | bigint): {
|
|
73
|
+
lo: number;
|
|
74
|
+
hi: number;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Convert an unsigned 64-bit integral value to a two's complement.
|
|
78
|
+
*/
|
|
79
|
+
uEnc(value: string | number | bigint): {
|
|
80
|
+
lo: number;
|
|
81
|
+
hi: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Convert a two's complement to a signed 64-bit integral value.
|
|
85
|
+
* Returns a bigint if available, a string otherwise.
|
|
86
|
+
*/
|
|
87
|
+
dec(lo: number, hi: number): bigint;
|
|
88
|
+
/**
|
|
89
|
+
* Convert a two's complement to an unsigned 64-bit integral value.
|
|
90
|
+
* Returns a bigint if available, a string otherwise.
|
|
91
|
+
*/
|
|
92
|
+
uDec(lo: number, hi: number): bigint;
|
|
93
|
+
}
|
|
94
|
+
export declare const protoInt64: Int64Support;
|
|
95
|
+
export {};
|