text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.ensureDocumentIdAndType = ensureDocumentIdAndType;
  exports.removeDraftPrefix = removeDraftPrefix;
  
  var _draftUtils = require("part:@sanity/base/util/draft-utils");
  
  var _document = _interopRequireDefault(require("part:@sanity/base/datastore/document"));
  
  var _uuid = require("@sanity/uuid");
  
  var _operators = require("rxjs/operators");
  
  var _PaneResolutionError = require("../../utils/PaneResolutionError");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  
  function removeDraftPrefix(documentId) {
    var publishedId = (0, _draftUtils.getPublishedId)(documentId);
  
    if (publishedId !== documentId) {
      console.warn('Removed unexpected draft id in document link: All links to documents should have the ' + '`drafts.`-prefix removed and something appears to have made an intent link to `%s`', documentId);
    }
  
    return publishedId;
  }
  
  function ensureDocumentIdAndType(_x, _x2) {
    return _ensureDocumentIdAndType.apply(this, arguments);
  }
  
  function _ensureDocumentIdAndType() {
    _ensureDocumentIdAndType = _asyncToGenerator(function* (id, type) {
      if (id && type) return {
        id,
        type
      };
      if (!id && type) return {
        id: (0, _uuid.uuid)(),
        type
      };
  
      if (id && !type) {
        var resolvedType = yield _document.default.resolveTypeForDocument(id).pipe((0, _operators.first)()).toPromise();
        return {
          id,
          type: resolvedType
        };
      }
  
      throw new _PaneResolutionError.PaneResolutionError({
        message: 'Neither document `id` or `type` was provided when trying to resolve intent.'
      });
    });
    return _ensureDocumentIdAndType.apply(this, arguments);
  }