import { EnumType } from "./enum.js"; import { Message, MessageType } from "./message.js"; import { LongType, ScalarType } from "./scalar.js"; import { protoCamelCase } from "./names.js"; /** * FieldInfo describes a field of a protobuf message for runtime reflection. We * distinguish between the following kinds of fields: * * - "scalar": string, bool, float, int32, etc. The scalar type is "T". * - "enum": The field was declared with an enum type. The enum type is "T". * - "message": The field was declared with a message type. The message type is "T". * - "map": The field was declared with map. The key type is "K", the value type is "V". * * Every field always has the following properties: * * - "no": The field number of the protobuf field. * - "name": The original name of the protobuf field. * - "localName": The name of the field as used in generated code. * - "jsonName": The name for JSON serialization / deserialization. * - "opt": Whether the field is optional. * - "req": Whether the field is required (a legacy proto2 feature). * - "repeated": Whether the field is repeated. * - "packed": Whether the repeated field is packed. * * Additionally, fields may have the following properties: * * - "oneof": If the field is member of a oneof group. * - "default": Only proto2: An explicit default value. * - "delimited": Only proto2: Use the tag-delimited group encoding. */ export type FieldInfo = ScalarFieldInfo | EnumFieldInfo | MessageFieldInfo | MapFieldInfo; /** * ScalarFieldInfo represents a scalar field. * It includes rules for field presence, repetition, and packing. */ export type ScalarFieldInfo = fiRules; /** * EnumFieldInfo represents an enum field. * It includes rules for field presence, repetition, and packing. */ export type EnumFieldInfo = fiRules; /** * MessageFieldInfo represents a message field. * It includes rules for field presence, repetition, and packing. */ export type MessageFieldInfo = fiRules; /** * MapFieldInfo represents a map field with a scalar key type and * a scalar, enum, or message value type. * It includes rules for field presence, repetition, and packing. */ export type MapFieldInfo = fiRules; /** * MapValueInfo represents the value type of a map field. * The value can be a scalar, enum, or message type. */ export type MapValueInfo = { readonly kind: "scalar"; readonly T: ScalarType; } | { readonly kind: "enum"; readonly T: EnumType; } | { readonly kind: "message"; readonly T: MessageType | (() => MessageType); }; /** * Provides convenient access to field information of a message type. */ export declare class FieldList { private readonly _fields; private readonly _normalizer; private all?; private numbersAsc?; private jsonNames?; private numbers?; private members?; constructor(fields: FieldListSource, normalizer: (p: FieldListSource) => FieldInfo[]); /** * Find field information by field name or json_name. */ findJsonName(jsonName: string): FieldInfo | undefined; /** * Find field information by proto field number. */ find(fieldNo: number): FieldInfo | undefined; /** * Return field information in the order they appear in the source. */ list(): readonly FieldInfo[]; /** * Return field information ordered by field number ascending. */ byNumber(): readonly FieldInfo[]; /** * In order of appearance in the source, list fields and * oneof groups. */ byMember(): readonly (FieldInfo | OneofInfo)[]; } /** * Version of `FieldInfo` that allows the following properties * to be omitted: * * - "localName", "jsonName": can be omitted if equal to lowerCamelCase(name) * - "opt": Can be omitted if false. * - "repeated": Can be omitted if false. * - "packed": Can be omitted if equal to the standard packing of the field. */ export type PartialFieldInfo = fiPartialRules | fiPartialRules | fiPartialRules | fiPartialRules; export type FieldListSource = readonly PartialFieldInfo[] | readonly FieldInfo[] | (() => readonly PartialFieldInfo[]) | (() => readonly FieldInfo[]); export declare function newFieldList(fields: FieldListSource, packedByDefault: boolean): FieldList; /** * Returns true if the field is set. */ export declare function isFieldSet(field: FieldInfo, target: Record | null | undefined): boolean; /** * Returns the JSON name for a protobuf field, exactly like protoc does. */ export declare const fieldJsonName: typeof protoCamelCase; export declare function resolveMessageType>(t: fiMessage["T"]): MessageType; export declare class InternalOneofInfo implements OneofInfo { readonly kind = "oneof"; readonly name: string; readonly localName: string; readonly repeated = false; readonly packed = false; readonly opt = false; readonly req = false; readonly default: undefined; readonly fields: FieldInfo[]; private _lookup?; constructor(name: string); addField(field: FieldInfo): void; findField(localName: string): FieldInfo | undefined; } /** * Convert a collection of field info to an array of normalized FieldInfo. * * The argument `packedByDefault` specifies whether fields that do not specify * `packed` should be packed (proto3) or unpacked (proto2). */ export declare function normalizeFieldInfos(fieldInfos: FieldListSource, packedByDefault: boolean): FieldInfo[]; /** * Provides convenient access to field information of a oneof. */ export interface OneofInfo { readonly kind: "oneof"; readonly name: string; readonly localName: string; readonly repeated: false; readonly packed: false; readonly opt: false; readonly req: false; readonly default: undefined; readonly delimited?: undefined; readonly fields: readonly FieldInfo[]; /** * Return field information by local name. */ findField(localName: string): FieldInfo | undefined; } interface fiShared { /** * The field number of the .proto field. */ readonly no: number; /** * The original name of the .proto field. */ readonly name: string; /** * The name of the field as used in generated code. */ readonly localName: string; /** * The name for JSON serialization / deserialization. */ readonly jsonName: string; /** * The `oneof` group, if this field belongs to one. */ readonly oneof?: OneofInfo | undefined; } interface fiScalar extends fiShared { readonly kind: "scalar"; /** * Scalar type of the field. */ readonly T: ScalarType; /** * JavaScript representation of 64 bit integral types (int64, uint64, * sint64, fixed64, sfixed64). * * By default, this is LongType.BIGINT. Generated code will use the BigInt * primitive. * * With LongType.STRING, generated code will use the String primitive instead. * This can be specified per field with the option `[jstype = JS_STRING]`: * * ```protobuf * uint64 field_a = 1; // BigInt * uint64 field_b = 2 [jstype = JS_NORMAL]; // BigInt * uint64 field_b = 2 [jstype = JS_NUMBER]; // BigInt * uint64 field_b = 2 [jstype = JS_STRING]; // String * ``` * * This property is ignored for other scalar types. */ readonly L: LongType; /** * Is the field repeated? */ readonly repeated: boolean; /** * Is this repeated field packed? * BYTES and STRING can never be packed, since they are length-delimited. * Other types can be packed with the field option "packed". * For proto3, fields are packed by default. */ readonly packed: boolean; /** * Is the field optional? */ readonly opt: boolean; /** * Is the field required? A legacy proto2 feature. */ readonly req: boolean; /** * Only proto2: An explicit default value. */ readonly default: number | boolean | string | bigint | Uint8Array | undefined; /** * Serialize this message with the delimited format, also known as group * encoding, as opposed to the standard length prefix. * * Only valid for message fields. */ readonly delimited?: undefined; } interface fiMessage = any> extends fiShared { readonly kind: "message"; /** * Message handler for the field. */ readonly T: MessageType | (() => MessageType); /** * Is the field repeated? */ readonly repeated: boolean; /** * Is this repeated field packed? Never true for messages. */ readonly packed: false; /** * Is the field required? A legacy proto2 feature. */ readonly req: boolean; /** * An explicit default value (only proto2). Never set for messages. */ readonly default: undefined; /** * Serialize this message with the delimited format, also known as group * encoding, as opposed to the standard length prefix. * * Only valid for message fields. */ readonly delimited?: boolean; } interface fiEnum extends fiShared { readonly kind: "enum"; /** * Enum type information for the field. */ readonly T: EnumType; /** * Is the field repeated? */ readonly repeated: boolean; /** * Is this repeated field packed? * Repeated enums can be packed with the field option "packed". * For proto3, they are packed by default. */ readonly packed: boolean; /** * Is the field optional? */ readonly opt: boolean; /** * Is the field required? A legacy proto2 feature. */ readonly req: boolean; /** * Only proto2: An explicit default value. */ readonly default: number | undefined; /** * Serialize this message with the delimited format, also known as group * encoding, as opposed to the standard length prefix. * * Only valid for message fields. */ readonly delimited?: undefined; } interface fiMap extends fiShared { readonly kind: "map"; /** * Map key type. * * The key_type can be any integral or string type * (so, any scalar type except for floating point * types and bytes) */ readonly K: Exclude; /** * Map value type. Can be scalar, enum, or message. */ readonly V: MapValueInfo; /** * Is the field repeated? Never true for maps. */ readonly repeated: false; /** * Is this repeated field packed? Never true for maps. */ readonly packed: false; /** * An explicit default value (only proto2). Never set for maps. */ readonly default: undefined; /** * Serialize this message with the delimited format, also known as group * encoding, as opposed to the standard length prefix. * * Only valid for message fields. */ readonly delimited?: undefined; } type fiRules = Omit & ({ readonly repeated: false; readonly packed: false; readonly opt: false; readonly req: boolean; readonly oneof: undefined; } | { readonly repeated: false; readonly packed: false; readonly opt: true; readonly req: false; readonly oneof: undefined; } | { readonly repeated: boolean; readonly packed: boolean; readonly opt: false; readonly req: boolean; readonly oneof: undefined; } | { readonly repeated: false; readonly packed: false; readonly opt: false; readonly req: false; readonly oneof: OneofInfo; }); type fiPartialRules = Omit & ({ readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly req?: boolean; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt: true; readonly req?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } | { readonly jsonName?: string; readonly repeated?: boolean; readonly packed?: boolean; readonly opt?: false; readonly req?: boolean; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly req?: false; readonly oneof: string; default?: T["default"]; L?: LongType; delimited?: boolean; }); export {};