"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const Response_1 = require("../../../../../wrap/Response");
const _ids_1 = require("../../../../_ids");
class Fetch0 extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['url', 'opt', 'body'],
            fo: ['res'],
            i: [],
            o: [],
        }, {
            input: {
                body: {
                    ref: true,
                },
            },
            output: {
                res: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_FETCH_0);
    }
    async f({ url, opt, body }, done) {
        const { api: { http: { fetch }, }, } = this.__system;
        opt.body = await body.raw();
        let response;
        try {
            response = await fetch(url, opt);
        }
        catch (err) {
            if (err.message === 'Failed to fetch') {
                done(undefined, 'failed to fetch');
                return;
            }
            done(undefined, 'malformed');
            return;
        }
        const res = (0, Response_1.wrapResponse)(response, this.__system);
        done({ res });
    }
}
exports.default = Fetch0;
//# sourceMappingURL=index.js.map