"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.INTERNAL_DRIVER_SYMBOL = void 0;
exports.flattenInternalDriver = flattenInternalDriver;
exports.mergeDrivers = mergeDrivers;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/**
 * Symbol for accessing driver methods which are internal
 * (we don't want to expose them to WSR consumers)
 */
var INTERNAL_DRIVER_SYMBOL = exports.INTERNAL_DRIVER_SYMBOL = Symbol('internal-driver');

/**
 * Merge driver 2 into driver 1
 *
 * It should take care of merging Internal methods into the target'shidden internal driver
 * (which sits under the [INTERNAL_DRIVER] property). Currently not supported.
 */
function mergeDrivers(target, source) {
  // TODO: merge driver2's internal methods into driver1's internal methods.
  // TODO: make this a reduce that accepts a list of drivers.
  if (target[INTERNAL_DRIVER_SYMBOL]) {
    throw new Error('mergeDrivers(): Merging into a driver with INTERNAL_DRIVER methods, is currently not supported yet.');
  }
  return _objectSpread(_objectSpread({}, target), source);
}

/**
 * Flatten driver by spreading all internal methods,
 * and removing the INTERNAL_DRIVER property.
 * Does not mutate the given driver.
 */
function flattenInternalDriver(driver) {
  if (driver[INTERNAL_DRIVER_SYMBOL]) {
    var driverCopy = _objectSpread({}, driver);
    var driverInternalMethods = driver[INTERNAL_DRIVER_SYMBOL];
    delete driverCopy[INTERNAL_DRIVER_SYMBOL];
    return _objectSpread(_objectSpread({}, driverCopy), driverInternalMethods);
  } else {
    return driver;
  }
}
//# sourceMappingURL=private-drivers.js.map