module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = require('../../../ssr-module-cache.js');
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		var threw = true;
/******/ 		try {
/******/ 			modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ 			threw = false;
/******/ 		} finally {
/******/ 			if(threw) delete installedModules[moduleId];
/******/ 		}
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 3);
/******/ })
/************************************************************************/
/******/ ({

/***/ 3:
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__("x+n+");


/***/ }),

/***/ "FTLX":
/***/ (function(module, exports) {

module.exports = require("@deepcase/hasura/cors-middleware");

/***/ }),

/***/ "K8Dv":
/***/ (function(module, exports) {

module.exports = require("@deepcase/hasura/api");

/***/ }),

/***/ "Xm2/":
/***/ (function(module, exports) {

module.exports = require("cors");

/***/ }),

/***/ "YvTO":
/***/ (function(module, exports) {

module.exports = require("apollo-boost");

/***/ }),

/***/ "r5oh":
/***/ (function(module, exports) {

module.exports = require("vm");

/***/ }),

/***/ "vv5f":
/***/ (function(module, exports) {

module.exports = require("@deepcase/hasura/client");

/***/ }),

/***/ "x+n+":
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "api", function() { return api; });
/* harmony import */ var cors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("Xm2/");
/* harmony import */ var cors__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(cors__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _deepcase_hasura_client__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("vv5f");
/* harmony import */ var _deepcase_hasura_client__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_deepcase_hasura_client__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _deepcase_hasura_cors_middleware__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("FTLX");
/* harmony import */ var _deepcase_hasura_cors_middleware__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_deepcase_hasura_cors_middleware__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _deepcase_hasura_api__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("K8Dv");
/* harmony import */ var _deepcase_hasura_api__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_deepcase_hasura_api__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var apollo_boost__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("YvTO");
/* harmony import */ var apollo_boost__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(apollo_boost__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var vm__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("r5oh");
/* harmony import */ var vm__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(vm__WEBPACK_IMPORTED_MODULE_5__);






const api = new _deepcase_hasura_api__WEBPACK_IMPORTED_MODULE_3__["HasuraApi"]({
  path: process.env.MIGRATIONS_HASURA_PATH,
  ssl: !!+process.env.MIGRATIONS_HASURA_SSL,
  secret: process.env.MIGRATIONS_HASURA_SECRET
});
const client = Object(_deepcase_hasura_client__WEBPACK_IMPORTED_MODULE_1__["generateApolloClient"])({
  path: `${process.env.MIGRATIONS_HASURA_PATH}/v1/graphql`,
  ssl: !!+process.env.MIGRATIONS_HASURA_SSL,
  secret: process.env.MIGRATIONS_HASURA_SECRET
});
const cors = cors__WEBPACK_IMPORTED_MODULE_0___default()({
  methods: ['GET', 'HEAD', 'POST']
});
/* harmony default export */ __webpack_exports__["default"] = (async (req, res) => {
  await Object(_deepcase_hasura_cors_middleware__WEBPACK_IMPORTED_MODULE_2__["corsMiddleware"])(req, res, cors);

  try {
    var _req$body;

    const event = req === null || req === void 0 ? void 0 : (_req$body = req.body) === null || _req$body === void 0 ? void 0 : _req$body.event;
    const operation = event === null || event === void 0 ? void 0 : event.op;

    if (operation === 'INSERT' || operation === 'UPDATE' || operation === 'DELETE') {
      var _event$data, _event$data2, _handleStringResult$d, _handleStringResult$d2, _handleStringResult$d3;

      const oldRow = event === null || event === void 0 ? void 0 : (_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.old;
      const newRow = event === null || event === void 0 ? void 0 : (_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : _event$data2.new;
      const typeId = operation === 'DELETE' ? oldRow.type_id : newRow.type_id;
      const handleStringResult = await client.query({
        query: apollo_boost__WEBPACK_IMPORTED_MODULE_4__["gql"]`query SELECT_STRING_HANDLE($typeId: bigint) { dc_dg_string(where: {
        link: {
          type_id: { _eq: 20 },
          to_id: { _eq: 16 },
          from_id: { _eq: $typeId }
        },
      }) {
        id
        value
      } }`,
        variables: {
          typeId
        }
      });
      const handleStringValue = handleStringResult === null || handleStringResult === void 0 ? void 0 : (_handleStringResult$d = handleStringResult.data) === null || _handleStringResult$d === void 0 ? void 0 : (_handleStringResult$d2 = _handleStringResult$d.dc_dg_string) === null || _handleStringResult$d2 === void 0 ? void 0 : (_handleStringResult$d3 = _handleStringResult$d2[0]) === null || _handleStringResult$d3 === void 0 ? void 0 : _handleStringResult$d3.value;

      try {
        vm__WEBPACK_IMPORTED_MODULE_5___default.a.runInNewContext(handleStringValue, {
          console,
          Error,
          oldRow,
          newRow
        });
      } catch (error) {
        console.log(error);
      }

      return res.status(500).json({
        error: 'notexplained'
      });
    }

    return res.status(500).json({
      error: 'operation can be only INSERT or UPDATE'
    });
  } catch (error) {
    return res.status(500).json({
      error: error.toString()
    });
  }
});

/***/ })

/******/ });