import type { TwinStream } from '../twin-fetch.js'; /** A command or reply document as the pack's codec gives it: the pack decides how BSON's types appear in it. */ export type MongoDocument = Record; /** BSON, as the pack supplies it (the `bson` library, installed by the pack's package.json). The kernel frames * documents and never reads inside one but for a command's `$db`. */ export type MongoCodec = { serialize(document: MongoDocument): Uint8Array; deserialize(bytes: Uint8Array): MongoDocument; }; /** What a pack's stream reads of the `bson` library its generated fetch's `loadBson` resolves from the pack: the codec, * extended JSON, and the number kinds a reply names. The kernel declares the shape and imports nothing of it. */ export type BsonLibrary = { serialize(document: MongoDocument): Uint8Array; deserialize(bytes: Uint8Array, options?: { promoteValues?: boolean; promoteLongs?: boolean; bsonRegExp?: boolean; }): MongoDocument; EJSON: { serialize(value: unknown, options?: { relaxed?: boolean; }): MongoDocument; deserialize(value: unknown, options?: { relaxed?: boolean; }): MongoDocument; }; Double: new (value: number) => unknown; Int32: new (value: number) => unknown; Long: { fromNumber(value: number): unknown; }; }; /** What the sender's message said beside its command: whether it will take more than one reply to it (OP_MSG's exhaustAllowed). */ export type MongoAsked = { exhaustAllowed: boolean; }; declare const TIMED: unique symbol; /** * An answer the wire sends LATER, or goes on sending: the vendor's protocol does this in real time (an awaitable * `hello` is held for the sender's maxAwaitTimeMS, and one sent with exhaustAllowed is answered again every such * interval, each reply marked moreToCome). The pack says WHAT and WHEN as data and holds no clock: the same request * gets the same answer every time. The wire does the holding and the repeating on the wall clock, and the delay is * never read back into state (architecture, "The MongoDB wire"). */ export type MongoTimedReply = { readonly [TIMED]: true; reply: MongoDocument; afterMs: number; everyMs?: number; }; /** * `reply` after `afterMs` (0: at once); with `everyMs`, again each `everyMs` until the peer closes, where the sender * allowed more than one reply. The two differ in the vendor's own answers: a hello naming the server's current * topology is first answered after the wait, one naming another process at once, and both then repeat at the wait. */ export declare const timedReply: (reply: MongoDocument, afterMs: number, everyMs?: number) => MongoTimedReply; export type MongoStreamOptions = { codec: MongoCodec; /** A connection opened: what the pack keeps for it (its sessions, an open transaction); never the tree. */ open(peer: string): Session; /** Answer ONE command document sent to `database`. A document sequence (an insert's `documents`, an update's * `updates`) arrives as that field holding the array. The answer is the reply document, `ok: 1` or the vendor's * error document; a command the pack does not serve is the pack's to answer as the vendor answers an unknown one. */ command(session: Session, database: string, command: MongoDocument, asked: MongoAsked): Promise; /** The connection went away: abort what it left open. */ close?(session: Session): void; /** Told why a connection is ended by this stream and not by its peer: the pack threw answering a command, or a * message was one this wire does not serve. Ending the connection is all the wire can say to the client, so the * reason is said here; unset, it is written to the process's error output. A stream that ends connections in * silence leaves its operator with a client that hangs and nothing to read. */ ended?(reason: string, peer: string): void; /** The largest message accepted; the vendor's server names 48,000,000 in its hello (`maxMessageSizeBytes`). */ maxMessageSizeBytes?: number; }; export declare const MongoOp: { readonly REPLY: 1; readonly QUERY: 2004; readonly MSG: 2013; }; /** OP_MSG's flag bits. */ export declare const MongoMsgFlag: { readonly CHECKSUM_PRESENT: number; readonly MORE_TO_COME: number; readonly EXHAUST_ALLOWED: number; }; /** An OP_MSG message carrying one document as its body section. */ export declare function encodeMsg(codec: MongoCodec, document: MongoDocument, requestId: number, responseTo: number, flags?: number): Uint8Array; /** The command of an OP_MSG message: its body section, with each document sequence as the field it names. */ export declare function decodeMsg(codec: MongoCodec, message: Uint8Array): { flags: number; document: MongoDocument; }; /** MongoDB's wire, served: each command document answered by the pack, in arrival order, on one connection. */ export declare function createMongoStream(options: MongoStreamOptions): TwinStream; /** The bytes of a C string, for a client's OP_QUERY. */ export declare const cstring: (text: string) => Uint8Array; export {};