UNPKG

@sanity/migrate

Version:

Tooling for running data migrations on Sanity.io projects

347 lines (346 loc) • 11.7 kB
function _assert_this_initialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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 _async_to_generator(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 _call_super(_this, derived, args) { derived = _get_prototype_of(derived); return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _construct(Parent, args, Class) { if (_is_native_reflect_construct()) { _construct = Reflect.construct; } else { _construct = function construct(Parent, args, Class) { var a = [ null ]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _set_prototype_of(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of(subClass, superClass); } function _is_native_function(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _possible_constructor_return(self, call) { if (call && (_type_of(call) === "object" || typeof call === "function")) { return call; } return _assert_this_initialized(self); } function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _wrap_native_super(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrap_native_super = function wrapNativeSuper(Class) { if (Class === null || !_is_native_function(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _get_prototype_of(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _set_prototype_of(Wrapper, Class); }; return _wrap_native_super(Class); } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); } catch (_) {} return (_is_native_reflect_construct = function() { return !!result; })(); } function _ts_generator(thisArg, body) { var f, y, t, _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty; return d(g, "next", { value: verb(0) }), d(g, "throw", { value: verb(1) }), d(g, "return", { value: verb(2) }), typeof Symbol === "function" && d(g, Symbol.iterator, { value: function() { return this; } }), g; function verb(n) { return function(v) { return step([ n, v ]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while(g && (g = 0, op[0] && (_ = 0)), _)try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [ op[0] & 2, t.value ]; switch(op[0]){ case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [ 0 ]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [ 6, e ]; y = 0; } finally{ f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } import { streamToAsyncIterator } from '../utils/streamToAsyncIterator.js'; export var HTTPError = /*#__PURE__*/ function(Error1) { "use strict"; _inherits(HTTPError, Error1); function HTTPError(statusCode, message) { _class_call_check(this, HTTPError); var _this; _this = _call_super(this, HTTPError, [ message ]), _define_property(_this, "statusCode", void 0); _this.name = 'HTTPError'; _this.statusCode = statusCode; return _this; } return HTTPError; }(_wrap_native_super(Error)); export function assert2xx(res) { return _async_to_generator(function() { var jsonResponse, message; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: if (!(res.status < 200 || res.status > 299)) return [ 3, 2 ]; return [ 4, res.json().catch(function() { return null; }) ]; case 1: jsonResponse = _state.sent(); if (jsonResponse === null || jsonResponse === void 0 ? void 0 : jsonResponse.error) { if (_type_of(jsonResponse.error) === 'object') { message = jsonResponse.error.description ? "".concat(jsonResponse.error.type || res.status, ": ").concat(jsonResponse.error.description) : "".concat(jsonResponse.error.type || res.status, ": ").concat(jsonResponse.message || 'Unknown error'); } else { message = "".concat(jsonResponse.error, ": ").concat(jsonResponse.message || ''); } } else { message = "HTTP Error ".concat(res.status, ": ").concat(res.statusText); } throw new HTTPError(res.status, message); case 2: return [ 2 ]; } }); })(); } export function fetchStream(_0) { return _async_to_generator(function(param) { var init, url, response; return _ts_generator(this, function(_state) { switch(_state.label){ case 0: init = param.init, url = param.url; return [ 4, fetch(url, init) ]; case 1: response = _state.sent(); return [ 4, assert2xx(response) ]; case 2: _state.sent(); if (response.body === null) throw new Error('No response received'); return [ 2, response.body ]; } }); }).apply(this, arguments); } export function fetchAsyncIterator(options) { return _async_to_generator(function() { return _ts_generator(this, function(_state) { switch(_state.label){ case 0: return [ 4, fetchStream(options) ]; case 1: return [ 2, streamToAsyncIterator.apply(void 0, [ _state.sent() ]) ]; } }); })(); }