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