"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendFailResultToDevtools = exports.sendEmptyResultToDevtools = exports.defaultUpwardMiddleware = exports.defaultDownwardMiddleware = void 0;
/**
 * 默认下行中间件，发送至 devtools
 */
const defaultDownwardMiddleware = async ({ msg, sendToDevtools }, next) => {
    await next();
    return sendToDevtools(msg);
};
exports.defaultDownwardMiddleware = defaultDownwardMiddleware;
/**
 * 默认上行中间件，发送至 app
 */
const defaultUpwardMiddleware = async ({ msg, sendToApp }, next) => {
    await next();
    return sendToApp(msg);
};
exports.defaultUpwardMiddleware = defaultUpwardMiddleware;
/**
 * 发送空包至 devtools
 */
const sendEmptyResultToDevtools = async ({ msg, sendToDevtools }) => {
    const req = msg;
    return sendToDevtools({
        id: req.id,
        method: req.method,
        result: {},
    });
};
exports.sendEmptyResultToDevtools = sendEmptyResultToDevtools;
/**
 * 发送失败回包至 devtools
 */
const sendFailResultToDevtools = async ({ msg, sendToDevtools }) => {
    const req = msg;
    return sendToDevtools({
        id: req.id,
        method: req.method,
        error: {
            code: -32601 /* ProtocolNotFound */,
            message: `'${req.method}' wasn't found`,
        },
    });
};
exports.sendFailResultToDevtools = sendFailResultToDevtools;
