function _putAttachment() {
  _putAttachment = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(_ref3) {
    var _this5 = this;

    var id,
        data,
        _ref3$type,
        type,
        skipIfSame,
        blobBuffer,
        _args2 = arguments;

    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            id = _ref3.id, data = _ref3.data, _ref3$type = _ref3.type, type = _ref3$type === void 0 ? 'text/plain' : _ref3$type;
            skipIfSame = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : false;
            ensureSchemaSupportsAttachments(this);

            if (shouldEncrypt(this)) {
              data = this.collection._crypter._encryptValue(data);
            }

            blobBuffer = blobBufferUtil.createBlobBuffer(data, type);
            this._atomicQueue = this._atomicQueue.then( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
              var currentMeta, newHash;
              return _regenerator["default"].wrap(function _callee$(_context) {
                while (1) {
                  switch (_context.prev = _context.next) {
                    case 0:
                      if (!(skipIfSame && _this5._data._attachments && _this5._data._attachments[id])) {
                        _context.next = 7;
                        break;
                      }

                      currentMeta = _this5._data._attachments[id];
                      _context.next = 4;
                      return (0, _pouchDb.pouchAttachmentBinaryHash)(data);

                    case 4:
                      newHash = _context.sent;

                      if (!(currentMeta.content_type === type && currentMeta.digest === newHash)) {
                        _context.next = 7;
                        break;
                      }

                      return _context.abrupt("return", _this5.getAttachment(id));

                    case 7:
                      return _context.abrupt("return", _this5.collection.pouch.putAttachment(_this5.primary, id, _this5._data._rev, blobBuffer, type).then(function () {
                        return _this5.collection.pouch.get(_this5.primary);
                      }).then(function (docData) {
                        var attachmentData = docData._attachments[id];
                        var attachment = fromPouchDocument(id, attachmentData, _this5);
                        _this5._data._rev = docData._rev;
                        _this5._data._attachments = docData._attachments;
                        return resyncRxDocument(_this5).then(function () {
                          return attachment;
                        });
                      }));

                    case 8:
                    case "end":
                      return _context.stop();
                  }
                }
              }, _callee);
            })));
            return _context2.abrupt("return", this._atomicQueue);

          case 7:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, this);
  }));
  return _putAttachment.apply(this, arguments);
}
/**
 * get an attachment of the document by its id
 */
get an attachment of the document by its id
get an attachment of the document by its id
function _putAttachment() {
  _putAttachment = (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee2(_ref3) {
    var _this5 = this;
    var id,
        data,
        _ref3$type,
        type,
        skipIfSame,
        blobBuffer,
        _args2 = arguments;
    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            id = _ref3.id, data = _ref3.data, _ref3$type = _ref3.type, type = _ref3$type === void 0 ? 'text/plain' : _ref3$type;
            skipIfSame = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : false;
            ensureSchemaSupportsAttachments(this);
            if (shouldEncrypt(this)) {
              data = this.collection._crypter._encryptValue(data);
            }
            blobBuffer = blobBufferUtil.createBlobBuffer(data, type);
            this._atomicQueue = this._atomicQueue.then( (0, _asyncToGenerator2["default"])( _regenerator["default"].mark(function _callee() {
              var currentMeta, newHash;
              return _regenerator["default"].wrap(function _callee$(_context) {
                while (1) {
                  switch (_context.prev = _context.next) {
                    case 0:
                      if (!(skipIfSame && _this5._data._attachments && _this5._data._attachments[id])) {
                        _context.next = 7;
                        break;
                      }
                      currentMeta = _this5._data._attachments[id];
                      _context.next = 4;
                      return (0, _pouchDb.pouchAttachmentBinaryHash)(data);
                    case 4:
                      newHash = _context.sent;
                      if (!(currentMeta.content_type === type && currentMeta.digest === newHash)) {
                        _context.next = 7;
                        break;
                      }
                      return _context.abrupt("return", _this5.getAttachment(id));
                    case 7:
                      return _context.abrupt("return", _this5.collection.pouch.putAttachment(_this5.primary, id, _this5._data._rev, blobBuffer, type).then(function () {
                        return _this5.collection.pouch.get(_this5.primary);
                      }).then(function (docData) {
                        var attachmentData = docData._attachments[id];
                        var attachment = fromPouchDocument(id, attachmentData, _this5);
                        _this5._data._rev = docData._rev;
                        _this5._data._attachments = docData._attachments;
                        return resyncRxDocument(_this5).then(function () {
                          return attachment;
                        });
                      }));
                    case 8:
                    case "end":
                      return _context.stop();
                  }
                }
              }, _callee);
            })));
            return _context2.abrupt("return", this._atomicQueue);
          case 7:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, this);
  }));
  return _putAttachment.apply(this, arguments);
}
function _putAttachment ( ) { _putAttachment = ( 0 , _asyncToGenerator2 [ "default" ] ) ( _regenerator [ "default" ] . mark ( function _callee2 ( _ref3 ) { var _this5 = this ; var id , data , _ref3$type , type , skipIfSame , blobBuffer , _args2 = arguments ; return _regenerator [ "default" ] . wrap ( function _callee2$ ( _context2 ) { while ( 1 ) { switch ( _context2 . prev = _context2 . next ) { case 0 : id = _ref3 . id , data = _ref3 . data , _ref3$type = _ref3 . type , type = _ref3$type === void 0 ? 'text/plain' : _ref3$type ; skipIfSame = _args2 . length > 1 && _args2 [ 1 ] !== undefined ? _args2 [ 1 ] : false ; ensureSchemaSupportsAttachments ( this ) ; if ( shouldEncrypt ( this ) ) { data = this . collection . _crypter . _encryptValue ( data ) ; } blobBuffer = blobBufferUtil . createBlobBuffer ( data , type ) ; this . _atomicQueue = this . _atomicQueue . then ( ( 0 , _asyncToGenerator2 [ "default" ] ) ( _regenerator [ "default" ] . mark ( function _callee ( ) { var currentMeta , newHash ; return _regenerator [ "default" ] . wrap ( function _callee$ ( _context ) { while ( 1 ) { switch ( _context . prev = _context . next ) { case 0 : if ( ! ( skipIfSame && _this5 . _data . _attachments && _this5 . _data . _attachments [ id ] ) ) { _context . next = 7 ; break ; } currentMeta = _this5 . _data . _attachments [ id ] ; _context . next = 4 ; return ( 0 , _pouchDb . pouchAttachmentBinaryHash ) ( data ) ; case 4 : newHash = _context . sent ; if ( ! ( currentMeta . content_type === type && currentMeta . digest === newHash ) ) { _context . next = 7 ; break ; } return _context . abrupt ( "return" , _this5 . getAttachment ( id ) ) ; case 7 : return _context . abrupt ( "return" , _this5 . collection . pouch . putAttachment ( _this5 . primary , id , _this5 . _data . _rev , blobBuffer , type ) . then ( function ( ) { return _this5 . collection . pouch . get ( _this5 . primary ) ; } ) . then ( function ( docData ) { var attachmentData = docData . _attachments [ id ] ; var attachment = fromPouchDocument ( id , attachmentData , _this5 ) ; _this5 . _data . _rev = docData . _rev ; _this5 . _data . _attachments = docData . _attachments ; return resyncRxDocument ( _this5 ) . then ( function ( ) { return attachment ; } ) ; } ) ) ; case 8 : case "end" : return _context . stop ( ) ; } } } , _callee ) ; } ) ) ) ; return _context2 . abrupt ( "return" , this . _atomicQueue ) ; case 7 : case "end" : return _context2 . stop ( ) ; } } } , _callee2 , this ) ; } ) ) ; return _putAttachment . apply ( this , arguments ) ; }
get an attachment of the document by its id
get an attachment of the document by its id
/*#__PURE__*/ /*#__PURE__*/ /*#__PURE__*/