text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = resolveRefType;
  
  var _rxjs = require("rxjs");
  
  var _operators = require("rxjs/operators");
  
  var _versionedClient = require("../../client/versionedClient");
  
  var CACHE = Object.create(null); // todo: use a LRU cache instead (e.g. hashlru or quick-lru)
  
  function resolveRefTypeName(reference) {
    if (!(reference._ref in CACHE)) {
      CACHE[reference._ref] = _versionedClient.versionedClient.fetch('*[_id == $id][0]._type', {
        id: reference._ref
      });
    }
  
    return (0, _rxjs.from)(CACHE[reference._ref]);
  }
  
  function resolveRefType(value, type) {
    return resolveRefTypeName(value).pipe((0, _operators.map)(refTypeName => type.to.find(toType => toType.name === refTypeName)));
  }