import { FieldList, FieldListSource } from "./field.js"; import { BinaryReadOptions, BinaryWriteOptions } from "./binary.js"; import { JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions } from "./json.js"; import { FieldWrapper } from "./field-wrapper.js"; export type Field = T extends Date | Uint8Array | bigint | boolean | string | number ? T : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> : T extends { case: string; value: any; } ? OneofSelectedMessage : T extends object ? Message : never; export type OneofSelectedMessage = { case: C; value: Field; }; export type Message = { [K in keyof T]?: Field; }; export type CompleteMessage = { [K in keyof T]-?: Field; }; export type AnyMessage = { [key: string]: any | undefined; }; /** * MessageType represents a protobuf message declaration. It provides: * - a constructor that produces an instance of the message * - metadata for reflection-based operations * - common functionality like serialization */ export interface MessageType = AnyMessage> { /** * The fully qualified name of the message. */ readonly typeName: string; /** * Field metadata. */ readonly fields: FieldList; /** * When used as a field, unwrap this message to a simple value. */ readonly fieldWrapper?: FieldWrapper; /** * Create a new empty instance of this message applying the partial message. */ create(partial?: Message): Message; /** * Create a new instance of this message with zero values for fields. */ createComplete(partial?: Message): CompleteMessage; /** * Create a deep copy. */ clone(a: T | undefined | null): T | undefined | null; /** * Parse from binary data, merging fields. * * Repeated fields are appended. Map entries are added, overwriting * existing keys. * * If a message field is already present, it will be merged with the * new data. */ fromBinary(bytes: Uint8Array | null | undefined, options?: Partial): T; /** * Parse a message from a JSON value. */ fromJson(jsonValue: JsonValue | null | undefined, options?: Partial): T; /** * Parse a message from a JSON string. */ fromJsonString(jsonString: string | null | undefined, options?: Partial): T; /** * Returns true if the given arguments have equal field values, recursively. * Will also return true if both messages are `undefined` or `null`. */ equals(a: T | undefined | null, b: T | undefined | null): boolean; /** * Serialize the message to binary data. */ toBinary(a: Message | undefined | null, options?: Partial): Uint8Array; /** * Serialize the message to a JSON value, a JavaScript value that can be * passed to JSON.stringify(). */ toJson(a: Message, options?: Partial): JsonValue; /** * Serialize the message to a JSON string. */ toJsonString(a: Message, options?: Partial): string; } export type MessageTypeParams> = Pick, "fieldWrapper" | "typeName"> & { /** * Fields contains the list of message fields. */ fields: FieldListSource; /** * `packedByDefault` specifies whether fields that do not specify `packed` * should be packed (proto3) or unpacked (proto2). */ packedByDefault: boolean; /** * `delimitedMessageEncoding` specifies whether fields are encoded without * delimited fields (proto3) or with (proto2 legacy). */ delimitedMessageEncoding?: boolean; }; /** * createMessageType creates a new message type. * * The argument `packedByDefault` specifies whether fields that do not specify * `packed` should be packed (proto3) or unpacked (proto2). */ export declare function createMessageType, E extends Partial> = Partial>>(params: MessageTypeParams, exts?: E): MessageType & E; export declare function compareMessages>(fields: FieldList, a: T | undefined | null, b: T | undefined | null): boolean; export declare function cloneMessage>(message: T | null | undefined, fields: FieldList): T | null; /** * createCompleteMessage recursively builds a message filled with zero values based on the given FieldList. */ export declare function createCompleteMessage>(fields: FieldList): CompleteMessage;