"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

var _Object$defineProperty2 = require("@babel/runtime-corejs2/core-js/object/define-property");

_Object$defineProperty2(exports, "__esModule", {
  value: true
});

exports["default"] = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-property"));

var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-properties"));

var _getOwnPropertyDescriptors = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors"));

require("core-js/modules/es6.array.for-each");

var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));

require("core-js/modules/es6.array.filter");

var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols"));

var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));

require("regenerator-runtime/runtime");

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));

var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));

function ownKeys(object, enumerableOnly) { var keys = (0, _keys["default"])(object); if (_getOwnPropertySymbols["default"]) { var symbols = (0, _getOwnPropertySymbols["default"])(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return (0, _getOwnPropertyDescriptor["default"])(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty3["default"])(target, key, source[key]); }); } else if (_getOwnPropertyDescriptors["default"]) { (0, _defineProperties["default"])(target, (0, _getOwnPropertyDescriptors["default"])(source)); } else { ownKeys(Object(source)).forEach(function (key) { (0, _defineProperty2["default"])(target, key, (0, _getOwnPropertyDescriptor["default"])(source, key)); }); } } return target; }

/**
 *
 */

/**
 * Remote reference to record information
 */
var RecordReference =
/*#__PURE__*/
function () {
  /**
   *
   */
  function RecordReference(conn, type, id) {
    (0, _classCallCheck2["default"])(this, RecordReference);
    (0, _defineProperty3["default"])(this, "type", void 0);
    (0, _defineProperty3["default"])(this, "id", void 0);
    (0, _defineProperty3["default"])(this, "_conn", void 0);
    (0, _defineProperty3["default"])(this, "delete", this.destroy);
    (0, _defineProperty3["default"])(this, "del", this.destroy);
    this._conn = conn;
    this.type = type;
    this.id = id;
  }
  /**
   * Retrieve record field information
   */


  (0, _createClass2["default"])(RecordReference, [{
    key: "retrieve",
    value: function retrieve(options) {
      var rec;
      return _regenerator["default"].async(function retrieve$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return _regenerator["default"].awrap(this._conn.retrieve(this.type, this.id, options));

            case 2:
              rec = _context.sent;
              return _context.abrupt("return", rec);

            case 4:
            case "end":
              return _context.stop();
          }
        }
      }, null, this);
    }
    /**
     * Update record field information
     */

  }, {
    key: "update",
    value: function update(record, options) {
      var record_;
      return _regenerator["default"].async(function update$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              record_ = _objectSpread({}, record, {
                Id: this.id
              });
              return _context2.abrupt("return", this._conn.update(this.type, record_, options));

            case 2:
            case "end":
              return _context2.stop();
          }
        }
      }, null, this);
    }
    /**
     * Delete record field
     */

  }, {
    key: "destroy",
    value: function destroy(options) {
      return this._conn.destroy(this.type, this.id, options);
    }
    /**
     * Synonym of Record#destroy()
     */

  }, {
    key: "blob",

    /**
     * Get blob field as stream
     *
     * @param {String} fieldName - Blob field name
     * @returns {stream.Stream}
     */
    value: function blob(fieldName) {
      var url = [this._conn._baseUrl(), 'sobjects', this.type, this.id, fieldName].join('/');
      return this._conn.request(url).stream();
    }
  }]);
  return RecordReference;
}();

exports["default"] =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