import type { GenEnum, GenExtension, GenMessage } from "./codegenv1/types.js"; import type { DescEnum, DescExtension, DescMessage, DescMethod } from "./descriptors.js"; import type { OneofADT } from "./reflect/guard.js"; import type { WireType } from "./wire/index.js"; import type { JsonValue } from "./json-value.js"; /** * The type `Message` contains the properties shared by all messages. */ export type Message = { /** * The fully qualified Protobuf type-name of the message. */ readonly $typeName: TypeName; /** * Unknown fields and extensions stored on the message. */ $unknown?: UnknownField[]; }; /** * Extract the message type from a message descriptor. */ export type MessageShape = Desc extends GenMessage ? RuntimeShape : Message; /** * Extract the message JSON type from a message descriptor. */ export type MessageJsonType = Desc extends GenMessage ? JsonType : JsonValue; /** * Extract the init type from a message descriptor. * The init type is accepted by the function create(). */ export type MessageInitShape = Desc extends GenMessage ? MessageInit : Record; /** * Extract the enum type of from an enum descriptor. */ export type EnumShape = Desc extends GenEnum ? RuntimeShape : number; /** * Extract the enum JSON type from a enum descriptor. */ export type EnumJsonType = Desc extends GenEnum ? JsonType : string | null; /** * Extract the value type from an extension descriptor. */ export type ExtensionValueShape = Desc extends GenExtension ? RuntimeShape : unknown; /** * Extract the type of the extended message from an extension descriptor. */ export type Extendee = Desc extends GenExtension ? Extendee : Message; /** * Unknown fields are fields that were not recognized during parsing, or * extension. */ export type UnknownField = { readonly no: number; readonly wireType: WireType; readonly data: Uint8Array; }; /** * Describes a streaming RPC declaration. */ export type DescMethodStreaming = DescMethodClientStreaming | DescMethodServerStreaming | DescMethodBiDiStreaming; /** * Describes a unary RPC declaration. */ export type DescMethodUnary = DescMethodTyped<"unary", I, O>; /** * Describes a server streaming RPC declaration. */ export type DescMethodServerStreaming = DescMethodTyped<"server_streaming", I, O>; /** * Describes a client streaming RPC declaration. */ export type DescMethodClientStreaming = DescMethodTyped<"client_streaming", I, O>; /** * Describes a bidi streaming RPC declaration. */ export type DescMethodBiDiStreaming = DescMethodTyped<"bidi_streaming", I, O>; /** * The init type for a message, which makes all fields optional. * The init type is accepted by the function create(). */ type MessageInit = T | { [P in keyof T as P extends "$unknown" ? never : P]?: P extends "$typeName" ? never : FieldInit; }; type FieldInit = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array ? Array> : F extends ReadonlyArray ? ReadonlyArray> : F extends Message ? MessageInit : F extends OneofSelectedMessage ? { case: C; value: MessageInit; } : F extends OneofADT ? F : F extends MapWithMessage ? { [key: string | number]: MessageInit; } : F; type MapWithMessage = { [key: string | number]: V; }; type OneofSelectedMessage = { case: K; value: M; }; type DescMethodTyped = Omit & { /** * One of the four available method types. */ readonly methodKind: K; /** * The message type for requests. */ readonly input: I; /** * The message type for responses. */ readonly output: O; }; export {};