/**
 * Socket message recorder middleware.
 *
 * Creates a middleware that records socket messages passing through
 * the socket manager. Follows the existing middleware pattern used
 * for authentication.
 */
/**
 * Creates a socket recording middleware.
 *
 * This middleware records all socket messages before passing them to the next
 * handler. It captures the method name from context, request parameters, and peer ID.
 *
 * The actual data cleaning is handled by RecordingManager.recordSocket(),
 * which uses a switch statement to decide what to record for each method.
 *
 * @param recorder - The RecordingManager instance
 * @returns A GenericMiddleware that records socket messages
 *
 * @example
 * ```typescript
 * const recordingMiddleware = createSocketRecordingMiddleware(recorder);
 * // Add to middleware array in socket-manager.ts alongside authMiddleware
 * ```
 */
export function createSocketRecordingMiddleware(recorder) {
    return async (params, ctx, peer, next) => {
        // Record the socket message if recording is enabled
        if (recorder.isEnabled()) {
            // Extract peer ID from various possible sources
            const peerId = peer?.id ?? peer?.peerId ?? ctx?.peerId;
            // Get method name from context (provided by TracedSocket)
            const method = ctx?.method ?? "unknown";
            recorder.recordSocket({
                method,
                request: params,
                peerId,
            });
        }
        // Continue to the next handler
        return await next();
    };
}
//# sourceMappingURL=socket-recorder.js.map