/** * Capnweb RPC client for postgres.do * * This module provides a capnweb-enabled PostgreSQL client with: * - Magic map support for N+1 query elimination * - Promise pipelining for batched operations * - RPC transport with automatic batching * * @example * ```typescript * import { createClient } from 'postgres.do/rpc' * * const db = createClient('postgres.do/my-database') * * // Magic map - N+1 solved in single round trip * const usersWithOrders = await db.query('SELECT * FROM users') * .map(users => Promise.all( * users.map(u => db.query('SELECT * FROM orders WHERE user_id = $1', [u.id])) * )) * * // Promise pipelining - chain without await * const user = db.query('SELECT * FROM users WHERE id = $1', [id]) * const posts = user.map(u => db.query('SELECT * FROM posts WHERE author = $1', [u.id])) * const comments = posts.map(p => db.query('SELECT * FROM comments WHERE post_id = ANY($1)', [p.map(x => x.id)])) * const result = await comments // Single round trip! * ``` * * @module postgres.do/rpc */ // Client exports export { RpcClient, createClient, type RpcClientConfig, type TransactionOptions, type TransactionClient, } from './client' // RpcPromise exports export { RpcPromise, createRpcPromise, createRowsPromise, batchExecute, magicMap, type RpcExecutionContext, type BatchResult, type MapFn, type RpcQueryResult, } from './rpc-promise' // Re-export transport export { RpcTransport, createRpcTransport, type RpcTransportConfig } from '../transport/rpc' // Default export export { createClient as default } from './client' // ============================================================================ // Shared RPC Types (for use by both client and server) // ============================================================================ /** * Shared RPC types for the capnweb contract * * These types are the single source of truth for the RPC protocol. * Import these in @dotdo/postgres to ensure type-safe RPC communication. * * @example Server-side usage in @dotdo/postgres: * ```typescript * import type { * RpcQueryResult, * RpcBatchQuery, * RpcBatchResult, * RpcTransactionOptions, * IPostgresRpcApi, * } from 'postgres.do/rpc' * ``` */ export { // Base types type RpcRow, type RpcField, // Query types type RpcQueryResult as SharedRpcQueryResult, type RpcBatchQuery, type RpcBatchResult, // Transaction types type RpcIsolationLevel, type RpcTransactionOptions, type RpcTransactionState, // Error types type RpcError, // Wire protocol types RpcMessageType, type RpcQueryRequest, type RpcBatchRequest, type RpcBatchTransactionRequest, type RpcAuthRequest, type RpcPingRequest, type RpcQueryResultMessage, type RpcBatchResultMessage, type RpcErrorMessage, type RpcAuthResultMessage, type RpcPongMessage, type RpcRequestMessage, type RpcResponseMessage, type RpcMessage, // Server API interfaces type IPostgresRpcApi, type ITransactionRpcApi, } from './shared-types'