"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts function withMiddleware(client, plugins) { const originalExecute = client.execute.bind(client); const originalBatch = client.batch.bind(client); client.execute = async (stmt) => { let modifiedStmt = stmt; for (const plugin of plugins) { if (plugin.beforeExecute) { modifiedStmt = await plugin.beforeExecute(modifiedStmt, client); } } let executeChain = originalExecute; for (const plugin of plugins.slice().reverse()) { if (plugin.executeInterceptor) { const prevExecute = executeChain; executeChain = (query) => plugin.executeInterceptor(prevExecute, query, client); } } let result = await executeChain(modifiedStmt); for (const plugin of plugins) { if (plugin.afterExecute) { result = await plugin.afterExecute(result, modifiedStmt, client); } } return result; }; client.batch = async (stmts) => { let modifiedStmts = stmts; for (const plugin of plugins) { if (plugin.beforeBatch) { modifiedStmts = await plugin.beforeBatch(modifiedStmts, client); } } const results = await originalBatch(modifiedStmts); for (const plugin of plugins) { if (plugin.afterBatch) { await plugin.afterBatch(results, modifiedStmts, client); } } return results; }; return client; } function beforeExecute(handler) { return { beforeExecute: handler }; } function afterExecute(handler) { return { afterExecute: handler }; } function beforeBatch(handler) { return { beforeBatch: handler }; } function afterBatch(handler) { return { afterBatch: handler }; } function executeInterceptor(handler) { return { executeInterceptor: handler }; } exports.afterBatch = afterBatch; exports.afterExecute = afterExecute; exports.beforeBatch = beforeBatch; exports.beforeExecute = beforeExecute; exports.executeInterceptor = executeInterceptor; exports.withMiddleware = withMiddleware; //# sourceMappingURL=index.cjs.map