UNPKG

whatsapp-rust-bridge

Version:

A high-performance utilities for WhatsApp, powered by Rust and WebAssembly.

36 lines (35 loc) 1.94 kB
/** * Auto-assembled `proto` namespace, protobufjs-API-compatible. * * Walks every value exported by `./generated/whatsapp` (the ts-proto output), * splits the flat `Parent_Child_GrandChild` naming into a nested namespace tree, * and wraps each `MessageFns` into the `{ encode, decode, fromObject, create, * toObject }` surface that legacy Baileys-style consumers expect from * `WAProto.X.encode(obj).finish()` and friends. * * Why: there used to be a hand-maintained shim covering ~90 of the 1,352 * generated types. Bots that touched anything outside the manual list * type-checked against `WAProto/index.d.ts` but crashed at runtime. Generating * the runtime here from the same ts-proto output the bridge already builds * eliminates that drift entirely. * * Conventions matched: * - `encode(obj).finish()` returns `Uint8Array` (ts-proto's `BinaryWriter` * already exposes `.finish()`, so we reuse it directly). * - `decode(bytes)` returns the typed object with a no-op `toJSON` so * `JSON.stringify` round-trips cleanly without protobufjs's bytes→base64 * conversion (matches baileyrs' previous shim behavior). * - `fromObject(obj)` / `create(obj)` accept partial input and return the same * shape (no normalization — ts-proto's runtime accepts plain objects). * - Enums are flattened into the namespace as plain `{ NAME: value }` objects. * - Each top-level message is wrapped in a `Proxy` so unknown capitalized * sub-properties (`proto.Message.SomeUnreleasedThing.fromObject({...})`) * synthesize a passthrough at access time, preventing TypeError on bot code * that compiled against an updated `.d.ts` but runs against an older runtime. */ /** * Protobufjs-shaped namespace covering every type the bridge knows about. * Stable surface; safe to import as `proto` (or alias to `WAProto` for legacy * upstream-Baileys-style bot code). */ export declare const proto: Record<string, any>;