import type { DescMessage, Message } from "@bufbuild/protobuf"; import type { GenMessage } from "@bufbuild/protobuf/codegenv2"; // Adapted from https://github.com/bufbuild/protobuf-es/blob/v2.5.2/packages/protobuf/src/types.ts#L90-L93 export type MessageInitShape = Desc extends GenMessage ? MessageInit : never; // Adapted from https://github.com/bufbuild/protobuf-es/blob/v2.5.2/packages/protobuf/src/types.ts#L189-L193 export type MessageInit = { [P in Exclude]: FieldInit; }; // Adapted from https://github.com/bufbuild/protobuf-es/blob/v2.5.2/packages/protobuf/src/types.ts#L196-L204 type FieldInit = F extends | Date | Uint8Array | bigint | boolean | string | number ? F : F extends (infer T)[] ? FieldInit[] : F extends readonly (infer T)[] ? readonly FieldInit[] : F extends Message ? MessageInit : F extends OneofMessage ? { case: C; value: MessageInit } : F extends MapWithMessage ? Record> : F; // Adapted from https://github.com/bufbuild/protobuf-es/blob/v2.5.2/packages/protobuf/src/types.ts#L210-L213 interface OneofMessage { case: K; value: M; } // Adapted from https://github.com/bufbuild/protobuf-es/blob/v2.5.2/packages/protobuf/src/types.ts#L206-L208 type MapWithMessage = Record;