"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PutRoute = void 0;
function _express() {
  const data = require("@teambit/express");
  _express = function () {
    return data;
  };
  return data;
}
function _objectList() {
  const data = require("@teambit/legacy/dist/scope/objects/object-list");
  _objectList = function () {
    return data;
  };
  return data;
}
function _legacy() {
  const data = require("@teambit/legacy.scope-api");
  _legacy = function () {
    return data;
  };
  return data;
}
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
class PutRoute {
  constructor(scope, postPutSlot) {
    this.scope = scope;
    this.postPutSlot = postPutSlot;
    _defineProperty(this, "method", 'post');
    _defineProperty(this, "route", '/scope/put');
    _defineProperty(this, "verb", _express().Verb.WRITE);
    _defineProperty(this, "middlewares", [async (req, res) => {
      req.setTimeout(this.scope.config.httpTimeOut);
      const pushOptionsStr = req.headers['push-options'];
      if (!pushOptionsStr) throw new Error('http is missing the push-options header');
      const pushOptions = JSON.parse(pushOptionsStr);
      const objectList = await _objectList().ObjectList.fromTar(req);
      const ids = await (0, _legacy().put)({
        path: this.scope.path,
        objectList
      }, pushOptions);
      await Promise.all(ids.map(id => {
        return this.scope.resolveComponentId(id);
      }));
      res.json(ids);
    }]);
  }
}
exports.PutRoute = PutRoute;

//# sourceMappingURL=put.route.js.map