@pisell/pisellos 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +360 -0
- package/dist/effects/index.d.ts +17 -0
- package/dist/effects/index.js +162 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +17 -0
- package/dist/modules/Account/index.d.ts +21 -0
- package/dist/modules/Account/index.js +212 -0
- package/dist/modules/Account/types.d.ts +41 -0
- package/dist/modules/Account/types.js +19 -0
- package/dist/modules/BaseModule.d.ts +11 -0
- package/dist/modules/BaseModule.js +27 -0
- package/dist/modules/Cart/index.d.ts +33 -0
- package/dist/modules/Cart/index.js +242 -0
- package/dist/modules/Cart/types.d.ts +35 -0
- package/dist/modules/Cart/types.js +19 -0
- package/dist/modules/Date/index.d.ts +17 -0
- package/dist/modules/Date/index.js +133 -0
- package/dist/modules/Date/types.d.ts +32 -0
- package/dist/modules/Date/types.js +17 -0
- package/dist/modules/Guests/index.d.ts +17 -0
- package/dist/modules/Guests/index.js +259 -0
- package/dist/modules/Guests/types.d.ts +43 -0
- package/dist/modules/Guests/types.js +23 -0
- package/dist/modules/Order/index.d.ts +17 -0
- package/dist/modules/Order/index.js +228 -0
- package/dist/modules/Order/types.d.ts +57 -0
- package/dist/modules/Order/types.js +29 -0
- package/dist/modules/Payment/index.d.ts +18 -0
- package/dist/modules/Payment/index.js +243 -0
- package/dist/modules/Payment/types.d.ts +49 -0
- package/dist/modules/Payment/types.js +31 -0
- package/dist/modules/Product/index.d.ts +39 -0
- package/dist/modules/Product/index.js +118 -0
- package/dist/modules/Product/types.d.ts +387 -0
- package/dist/modules/Product/types.js +1 -0
- package/dist/modules/ProductList/index.d.ts +16 -0
- package/dist/modules/ProductList/index.js +158 -0
- package/dist/modules/ProductList/types.d.ts +9 -0
- package/dist/modules/ProductList/types.js +5 -0
- package/dist/modules/Resource/index.d.ts +15 -0
- package/dist/modules/Resource/index.js +219 -0
- package/dist/modules/Resource/types.d.ts +44 -0
- package/dist/modules/Resource/types.js +22 -0
- package/dist/modules/index.d.ts +3 -0
- package/dist/modules/index.js +3 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/request.d.ts +127 -0
- package/dist/plugins/request.js +592 -0
- package/dist/plugins/window.d.ts +115 -0
- package/dist/plugins/window.js +328 -0
- package/dist/solution/BookingByStep/index.d.ts +12 -0
- package/dist/solution/BookingByStep/index.js +77 -0
- package/dist/solution/BookingByStep/types.d.ts +27 -0
- package/dist/solution/BookingByStep/types.js +10 -0
- package/dist/solution/BuyTickets/index.d.ts +26 -0
- package/dist/solution/BuyTickets/index.js +339 -0
- package/dist/solution/BuyTickets/types.d.ts +24 -0
- package/dist/solution/BuyTickets/types.js +19 -0
- package/dist/solution/PlaceOrder/index.d.ts +0 -0
- package/dist/solution/PlaceOrder/index.js +54 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +1 -0
- package/dist/store/createStore.d.ts +3 -0
- package/dist/store/createStore.js +43 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/index.js +1 -0
- package/lib/core/index.d.ts +30 -0
- package/lib/core/index.js +212 -0
- package/lib/effects/index.d.ts +17 -0
- package/lib/effects/index.js +78 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +51 -0
- package/lib/modules/Account/index.d.ts +21 -0
- package/lib/modules/Account/index.js +93 -0
- package/lib/modules/Account/types.d.ts +41 -0
- package/lib/modules/Account/types.js +35 -0
- package/lib/modules/BaseModule.d.ts +11 -0
- package/lib/modules/BaseModule.js +40 -0
- package/lib/modules/Cart/index.d.ts +33 -0
- package/lib/modules/Cart/index.js +104 -0
- package/lib/modules/Cart/types.d.ts +35 -0
- package/lib/modules/Cart/types.js +35 -0
- package/lib/modules/Date/index.d.ts +17 -0
- package/lib/modules/Date/index.js +75 -0
- package/lib/modules/Date/types.d.ts +32 -0
- package/lib/modules/Date/types.js +33 -0
- package/lib/modules/Guests/index.d.ts +17 -0
- package/lib/modules/Guests/index.js +95 -0
- package/lib/modules/Guests/types.d.ts +43 -0
- package/lib/modules/Guests/types.js +35 -0
- package/lib/modules/Order/index.d.ts +17 -0
- package/lib/modules/Order/index.js +95 -0
- package/lib/modules/Order/types.d.ts +57 -0
- package/lib/modules/Order/types.js +35 -0
- package/lib/modules/Payment/index.d.ts +18 -0
- package/lib/modules/Payment/index.js +103 -0
- package/lib/modules/Payment/types.d.ts +49 -0
- package/lib/modules/Payment/types.js +35 -0
- package/lib/modules/Product/index.d.ts +39 -0
- package/lib/modules/Product/index.js +87 -0
- package/lib/modules/Product/types.d.ts +387 -0
- package/lib/modules/Product/types.js +17 -0
- package/lib/modules/ProductList/index.d.ts +16 -0
- package/lib/modules/ProductList/index.js +71 -0
- package/lib/modules/ProductList/types.d.ts +9 -0
- package/lib/modules/ProductList/types.js +33 -0
- package/lib/modules/Resource/index.d.ts +15 -0
- package/lib/modules/Resource/index.js +91 -0
- package/lib/modules/Resource/types.d.ts +44 -0
- package/lib/modules/Resource/types.js +34 -0
- package/lib/modules/index.d.ts +3 -0
- package/lib/modules/index.js +27 -0
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +25 -0
- package/lib/plugins/request.d.ts +127 -0
- package/lib/plugins/request.js +297 -0
- package/lib/plugins/window.d.ts +115 -0
- package/lib/plugins/window.js +252 -0
- package/lib/solution/BookingByStep/index.d.ts +12 -0
- package/lib/solution/BookingByStep/index.js +53 -0
- package/lib/solution/BookingByStep/types.d.ts +27 -0
- package/lib/solution/BookingByStep/types.js +38 -0
- package/lib/solution/BuyTickets/index.d.ts +26 -0
- package/lib/solution/BuyTickets/index.js +122 -0
- package/lib/solution/BuyTickets/types.d.ts +24 -0
- package/lib/solution/BuyTickets/types.js +40 -0
- package/lib/solution/PlaceOrder/index.d.ts +0 -0
- package/lib/solution/PlaceOrder/index.js +0 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +23 -0
- package/lib/store/createStore.d.ts +3 -0
- package/lib/store/createStore.js +46 -0
- package/lib/types/index.d.ts +85 -0
- package/lib/types/index.js +17 -0
- package/package.json +65 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
7
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
+
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); } }
|
|
11
|
+
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); }); }; }
|
|
12
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
+
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
18
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
19
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
20
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(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, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
22
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } 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) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
23
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
24
|
+
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
|
|
25
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
26
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
28
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
29
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
30
|
+
/**
|
|
31
|
+
* RequestPlugin 接口定义
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 请求配置
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 响应接口
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 请求错误
|
|
44
|
+
*/
|
|
45
|
+
export var RequestError = /*#__PURE__*/function (_Error) {
|
|
46
|
+
_inherits(RequestError, _Error);
|
|
47
|
+
var _super = _createSuper(RequestError);
|
|
48
|
+
function RequestError(message, config, request, response) {
|
|
49
|
+
var _this;
|
|
50
|
+
_classCallCheck(this, RequestError);
|
|
51
|
+
_this = _super.call(this, message);
|
|
52
|
+
_defineProperty(_assertThisInitialized(_this), "response", void 0);
|
|
53
|
+
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "config", void 0);
|
|
55
|
+
_this.name = 'RequestError';
|
|
56
|
+
_this.config = config;
|
|
57
|
+
_this.request = request;
|
|
58
|
+
_this.response = response;
|
|
59
|
+
return _this;
|
|
60
|
+
}
|
|
61
|
+
return _createClass(RequestError);
|
|
62
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* RequestPlugin 实现
|
|
66
|
+
*/
|
|
67
|
+
var RequestPluginImpl = /*#__PURE__*/function () {
|
|
68
|
+
function RequestPluginImpl() {
|
|
69
|
+
_classCallCheck(this, RequestPluginImpl);
|
|
70
|
+
_defineProperty(this, "name", 'request');
|
|
71
|
+
_defineProperty(this, "version", '1.0.0');
|
|
72
|
+
_defineProperty(this, "core", null);
|
|
73
|
+
/**
|
|
74
|
+
* 默认请求选项
|
|
75
|
+
*/
|
|
76
|
+
_defineProperty(this, "defaultOptions", {
|
|
77
|
+
method: 'GET',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json'
|
|
80
|
+
},
|
|
81
|
+
timeout: 30000,
|
|
82
|
+
responseType: 'json'
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* 全局拦截器
|
|
86
|
+
*/
|
|
87
|
+
_defineProperty(this, "interceptors", {
|
|
88
|
+
request: [],
|
|
89
|
+
response: [],
|
|
90
|
+
error: []
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
_createClass(RequestPluginImpl, [{
|
|
94
|
+
key: "initialize",
|
|
95
|
+
value:
|
|
96
|
+
// 初始化方法
|
|
97
|
+
function initialize() {
|
|
98
|
+
this.core = globalThis.pisellOS;
|
|
99
|
+
console.log('[RequestPlugin] 初始化完成');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 销毁方法
|
|
103
|
+
}, {
|
|
104
|
+
key: "destroy",
|
|
105
|
+
value: function destroy() {
|
|
106
|
+
console.log('[RequestPlugin] 已销毁');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 添加请求拦截器
|
|
111
|
+
*/
|
|
112
|
+
}, {
|
|
113
|
+
key: "addRequestInterceptor",
|
|
114
|
+
value: function addRequestInterceptor(interceptor) {
|
|
115
|
+
this.interceptors.request.push(interceptor);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 添加响应拦截器
|
|
120
|
+
*/
|
|
121
|
+
}, {
|
|
122
|
+
key: "addResponseInterceptor",
|
|
123
|
+
value: function addResponseInterceptor(interceptor) {
|
|
124
|
+
this.interceptors.response.push(interceptor);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 添加错误拦截器
|
|
129
|
+
*/
|
|
130
|
+
}, {
|
|
131
|
+
key: "addErrorInterceptor",
|
|
132
|
+
value: function addErrorInterceptor(interceptor) {
|
|
133
|
+
this.interceptors.error.push(interceptor);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* GET 请求
|
|
138
|
+
*/
|
|
139
|
+
}, {
|
|
140
|
+
key: "get",
|
|
141
|
+
value: function get(url) {
|
|
142
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
143
|
+
return this.request(_objectSpread(_objectSpread({}, options), {}, {
|
|
144
|
+
url: url,
|
|
145
|
+
method: 'GET'
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* POST 请求
|
|
151
|
+
*/
|
|
152
|
+
}, {
|
|
153
|
+
key: "post",
|
|
154
|
+
value: function post(url, data) {
|
|
155
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
156
|
+
return this.request(_objectSpread(_objectSpread({}, options), {}, {
|
|
157
|
+
url: url,
|
|
158
|
+
method: 'POST',
|
|
159
|
+
data: data
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* PUT 请求
|
|
165
|
+
*/
|
|
166
|
+
}, {
|
|
167
|
+
key: "put",
|
|
168
|
+
value: function put(url, data) {
|
|
169
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
170
|
+
return this.request(_objectSpread(_objectSpread({}, options), {}, {
|
|
171
|
+
url: url,
|
|
172
|
+
method: 'PUT',
|
|
173
|
+
data: data
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* DELETE 请求
|
|
179
|
+
*/
|
|
180
|
+
}, {
|
|
181
|
+
key: "delete",
|
|
182
|
+
value: function _delete(url) {
|
|
183
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
184
|
+
return this.request(_objectSpread(_objectSpread({}, options), {}, {
|
|
185
|
+
url: url,
|
|
186
|
+
method: 'DELETE'
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 通用请求方法
|
|
192
|
+
*/
|
|
193
|
+
}, {
|
|
194
|
+
key: "request",
|
|
195
|
+
value: (function () {
|
|
196
|
+
var _request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
197
|
+
var config, windowPlugin, _iterator, _step, _interceptor, _requestError2, _processedError2, _iterator5, _step5, _errorInterceptor2, _response, processedResponse, _iterator2, _step2, interceptor, requestError, processedError, _iterator3, _step3, errorInterceptor, _requestError, _processedError, _iterator4, _step4, _errorInterceptor;
|
|
198
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
199
|
+
while (1) switch (_context.prev = _context.next) {
|
|
200
|
+
case 0:
|
|
201
|
+
// 合并默认选项
|
|
202
|
+
config = _objectSpread(_objectSpread(_objectSpread({}, this.defaultOptions), options), {}, {
|
|
203
|
+
headers: _objectSpread(_objectSpread({}, this.defaultOptions.headers), options.headers)
|
|
204
|
+
});
|
|
205
|
+
if (!config.headers['authorization'] && this.core) {
|
|
206
|
+
windowPlugin = this.core.getPlugin('window');
|
|
207
|
+
if (windowPlugin) {
|
|
208
|
+
config.headers['authorization'] = windowPlugin.localStorage.getItem('token') || '';
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 应用请求拦截器
|
|
213
|
+
_iterator = _createForOfIteratorHelper(this.interceptors.request);
|
|
214
|
+
_context.prev = 3;
|
|
215
|
+
_iterator.s();
|
|
216
|
+
case 5:
|
|
217
|
+
if ((_step = _iterator.n()).done) {
|
|
218
|
+
_context.next = 43;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
_interceptor = _step.value;
|
|
222
|
+
_context.prev = 7;
|
|
223
|
+
_context.next = 10;
|
|
224
|
+
return Promise.resolve(_interceptor(config));
|
|
225
|
+
case 10:
|
|
226
|
+
config = _context.sent;
|
|
227
|
+
_context.next = 41;
|
|
228
|
+
break;
|
|
229
|
+
case 13:
|
|
230
|
+
_context.prev = 13;
|
|
231
|
+
_context.t0 = _context["catch"](7);
|
|
232
|
+
_requestError2 = _context.t0 instanceof RequestError ? _context.t0 : new RequestError(_context.t0 instanceof Error ? _context.t0.message : '请求拦截器错误', config); // 应用错误拦截器
|
|
233
|
+
_processedError2 = _requestError2;
|
|
234
|
+
_iterator5 = _createForOfIteratorHelper(this.interceptors.error);
|
|
235
|
+
_context.prev = 18;
|
|
236
|
+
_iterator5.s();
|
|
237
|
+
case 20:
|
|
238
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
239
|
+
_context.next = 32;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
_errorInterceptor2 = _step5.value;
|
|
243
|
+
_context.prev = 22;
|
|
244
|
+
_context.next = 25;
|
|
245
|
+
return Promise.resolve(_errorInterceptor2(_processedError2));
|
|
246
|
+
case 25:
|
|
247
|
+
_processedError2 = _context.sent;
|
|
248
|
+
_context.next = 30;
|
|
249
|
+
break;
|
|
250
|
+
case 28:
|
|
251
|
+
_context.prev = 28;
|
|
252
|
+
_context.t1 = _context["catch"](22);
|
|
253
|
+
case 30:
|
|
254
|
+
_context.next = 20;
|
|
255
|
+
break;
|
|
256
|
+
case 32:
|
|
257
|
+
_context.next = 37;
|
|
258
|
+
break;
|
|
259
|
+
case 34:
|
|
260
|
+
_context.prev = 34;
|
|
261
|
+
_context.t2 = _context["catch"](18);
|
|
262
|
+
_iterator5.e(_context.t2);
|
|
263
|
+
case 37:
|
|
264
|
+
_context.prev = 37;
|
|
265
|
+
_iterator5.f();
|
|
266
|
+
return _context.finish(37);
|
|
267
|
+
case 40:
|
|
268
|
+
throw _processedError2;
|
|
269
|
+
case 41:
|
|
270
|
+
_context.next = 5;
|
|
271
|
+
break;
|
|
272
|
+
case 43:
|
|
273
|
+
_context.next = 48;
|
|
274
|
+
break;
|
|
275
|
+
case 45:
|
|
276
|
+
_context.prev = 45;
|
|
277
|
+
_context.t3 = _context["catch"](3);
|
|
278
|
+
_iterator.e(_context.t3);
|
|
279
|
+
case 48:
|
|
280
|
+
_context.prev = 48;
|
|
281
|
+
_iterator.f();
|
|
282
|
+
return _context.finish(48);
|
|
283
|
+
case 51:
|
|
284
|
+
_context.prev = 51;
|
|
285
|
+
_context.next = 54;
|
|
286
|
+
return this.performRequest(config);
|
|
287
|
+
case 54:
|
|
288
|
+
_response = _context.sent;
|
|
289
|
+
// 应用响应拦截器
|
|
290
|
+
processedResponse = _response;
|
|
291
|
+
_iterator2 = _createForOfIteratorHelper(this.interceptors.response);
|
|
292
|
+
_context.prev = 57;
|
|
293
|
+
_iterator2.s();
|
|
294
|
+
case 59:
|
|
295
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
296
|
+
_context.next = 97;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
interceptor = _step2.value;
|
|
300
|
+
_context.prev = 61;
|
|
301
|
+
_context.next = 64;
|
|
302
|
+
return Promise.resolve(interceptor(processedResponse));
|
|
303
|
+
case 64:
|
|
304
|
+
processedResponse = _context.sent;
|
|
305
|
+
_context.next = 95;
|
|
306
|
+
break;
|
|
307
|
+
case 67:
|
|
308
|
+
_context.prev = 67;
|
|
309
|
+
_context.t4 = _context["catch"](61);
|
|
310
|
+
requestError = _context.t4 instanceof RequestError ? _context.t4 : new RequestError(_context.t4 instanceof Error ? _context.t4.message : '响应拦截器错误', config, null, _response); // 应用错误拦截器
|
|
311
|
+
processedError = requestError;
|
|
312
|
+
_iterator3 = _createForOfIteratorHelper(this.interceptors.error);
|
|
313
|
+
_context.prev = 72;
|
|
314
|
+
_iterator3.s();
|
|
315
|
+
case 74:
|
|
316
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
317
|
+
_context.next = 86;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
errorInterceptor = _step3.value;
|
|
321
|
+
_context.prev = 76;
|
|
322
|
+
_context.next = 79;
|
|
323
|
+
return Promise.resolve(errorInterceptor(processedError));
|
|
324
|
+
case 79:
|
|
325
|
+
processedError = _context.sent;
|
|
326
|
+
_context.next = 84;
|
|
327
|
+
break;
|
|
328
|
+
case 82:
|
|
329
|
+
_context.prev = 82;
|
|
330
|
+
_context.t5 = _context["catch"](76);
|
|
331
|
+
case 84:
|
|
332
|
+
_context.next = 74;
|
|
333
|
+
break;
|
|
334
|
+
case 86:
|
|
335
|
+
_context.next = 91;
|
|
336
|
+
break;
|
|
337
|
+
case 88:
|
|
338
|
+
_context.prev = 88;
|
|
339
|
+
_context.t6 = _context["catch"](72);
|
|
340
|
+
_iterator3.e(_context.t6);
|
|
341
|
+
case 91:
|
|
342
|
+
_context.prev = 91;
|
|
343
|
+
_iterator3.f();
|
|
344
|
+
return _context.finish(91);
|
|
345
|
+
case 94:
|
|
346
|
+
throw processedError;
|
|
347
|
+
case 95:
|
|
348
|
+
_context.next = 59;
|
|
349
|
+
break;
|
|
350
|
+
case 97:
|
|
351
|
+
_context.next = 102;
|
|
352
|
+
break;
|
|
353
|
+
case 99:
|
|
354
|
+
_context.prev = 99;
|
|
355
|
+
_context.t7 = _context["catch"](57);
|
|
356
|
+
_iterator2.e(_context.t7);
|
|
357
|
+
case 102:
|
|
358
|
+
_context.prev = 102;
|
|
359
|
+
_iterator2.f();
|
|
360
|
+
return _context.finish(102);
|
|
361
|
+
case 105:
|
|
362
|
+
return _context.abrupt("return", processedResponse.data);
|
|
363
|
+
case 108:
|
|
364
|
+
_context.prev = 108;
|
|
365
|
+
_context.t8 = _context["catch"](51);
|
|
366
|
+
_requestError = _context.t8 instanceof RequestError ? _context.t8 : new RequestError(_context.t8 instanceof Error ? _context.t8.message : '请求错误', config); // 应用错误拦截器
|
|
367
|
+
_processedError = _requestError;
|
|
368
|
+
_iterator4 = _createForOfIteratorHelper(this.interceptors.error);
|
|
369
|
+
_context.prev = 113;
|
|
370
|
+
_iterator4.s();
|
|
371
|
+
case 115:
|
|
372
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
373
|
+
_context.next = 127;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
_errorInterceptor = _step4.value;
|
|
377
|
+
_context.prev = 117;
|
|
378
|
+
_context.next = 120;
|
|
379
|
+
return Promise.resolve(_errorInterceptor(_processedError));
|
|
380
|
+
case 120:
|
|
381
|
+
_processedError = _context.sent;
|
|
382
|
+
_context.next = 125;
|
|
383
|
+
break;
|
|
384
|
+
case 123:
|
|
385
|
+
_context.prev = 123;
|
|
386
|
+
_context.t9 = _context["catch"](117);
|
|
387
|
+
case 125:
|
|
388
|
+
_context.next = 115;
|
|
389
|
+
break;
|
|
390
|
+
case 127:
|
|
391
|
+
_context.next = 132;
|
|
392
|
+
break;
|
|
393
|
+
case 129:
|
|
394
|
+
_context.prev = 129;
|
|
395
|
+
_context.t10 = _context["catch"](113);
|
|
396
|
+
_iterator4.e(_context.t10);
|
|
397
|
+
case 132:
|
|
398
|
+
_context.prev = 132;
|
|
399
|
+
_iterator4.f();
|
|
400
|
+
return _context.finish(132);
|
|
401
|
+
case 135:
|
|
402
|
+
throw _processedError;
|
|
403
|
+
case 136:
|
|
404
|
+
case "end":
|
|
405
|
+
return _context.stop();
|
|
406
|
+
}
|
|
407
|
+
}, _callee, this, [[3, 45, 48, 51], [7, 13], [18, 34, 37, 40], [22, 28], [51, 108], [57, 99, 102, 105], [61, 67], [72, 88, 91, 94], [76, 82], [113, 129, 132, 135], [117, 123]]);
|
|
408
|
+
}));
|
|
409
|
+
function request(_x) {
|
|
410
|
+
return _request.apply(this, arguments);
|
|
411
|
+
}
|
|
412
|
+
return request;
|
|
413
|
+
}()
|
|
414
|
+
/**
|
|
415
|
+
* 执行实际的请求
|
|
416
|
+
* 这里实现了一个基于 fetch API 的请求
|
|
417
|
+
*/
|
|
418
|
+
)
|
|
419
|
+
}, {
|
|
420
|
+
key: "performRequest",
|
|
421
|
+
value: (function () {
|
|
422
|
+
var _performRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
|
|
423
|
+
var url, method, headers, data, params, timeout, responseType, withCredentials, fullUrl, queryString, fetchOptions, timeoutId, timeoutPromise, fetchPromise, _response2, responseHeaders, responseData, result;
|
|
424
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
425
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
426
|
+
case 0:
|
|
427
|
+
url = config.url, method = config.method, headers = config.headers, data = config.data, params = config.params, timeout = config.timeout, responseType = config.responseType, withCredentials = config.withCredentials;
|
|
428
|
+
if (url) {
|
|
429
|
+
_context2.next = 3;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
throw new RequestError('URL不能为空', config);
|
|
433
|
+
case 3:
|
|
434
|
+
// 处理 URL 参数
|
|
435
|
+
fullUrl = url;
|
|
436
|
+
if (params && Object.keys(params).length > 0) {
|
|
437
|
+
queryString = Object.entries(params).map(function (_ref) {
|
|
438
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
439
|
+
key = _ref2[0],
|
|
440
|
+
value = _ref2[1];
|
|
441
|
+
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
|
|
442
|
+
}).join('&');
|
|
443
|
+
fullUrl += (url.includes('?') ? '&' : '?') + queryString;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// 准备请求选项
|
|
447
|
+
fetchOptions = {
|
|
448
|
+
method: method,
|
|
449
|
+
headers: _objectSpread({}, headers),
|
|
450
|
+
credentials: withCredentials ? 'include' : 'same-origin'
|
|
451
|
+
}; // 处理请求体
|
|
452
|
+
if (data !== undefined && method !== 'GET' && method !== 'HEAD') {
|
|
453
|
+
if (data instanceof FormData) {
|
|
454
|
+
fetchOptions.body = data;
|
|
455
|
+
// 当使用 FormData 时,删除 Content-Type,让浏览器自动设置
|
|
456
|
+
delete fetchOptions.headers['Content-Type'];
|
|
457
|
+
} else if (_typeof(data) === 'object') {
|
|
458
|
+
fetchOptions.body = JSON.stringify(data);
|
|
459
|
+
} else {
|
|
460
|
+
fetchOptions.body = data;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// 处理超时
|
|
465
|
+
timeoutPromise = new Promise(function (_, reject) {
|
|
466
|
+
if (timeout) {
|
|
467
|
+
timeoutId = setTimeout(function () {
|
|
468
|
+
reject(new RequestError("\u8BF7\u6C42\u8D85\u65F6: ".concat(timeout, "ms"), config));
|
|
469
|
+
}, timeout);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
_context2.prev = 8;
|
|
473
|
+
// 发起请求,并竞争超时
|
|
474
|
+
fetchPromise = typeof fetch !== 'undefined' ? fetch(fullUrl, fetchOptions) : Promise.reject(new RequestError('当前环境不支持 fetch API', config));
|
|
475
|
+
_context2.next = 12;
|
|
476
|
+
return Promise.race([fetchPromise, timeoutPromise]);
|
|
477
|
+
case 12:
|
|
478
|
+
_response2 = _context2.sent;
|
|
479
|
+
// 解析响应头
|
|
480
|
+
responseHeaders = {};
|
|
481
|
+
_response2.headers.forEach(function (value, key) {
|
|
482
|
+
responseHeaders[key] = value;
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// 解析响应内容
|
|
486
|
+
if (!(responseType === 'json')) {
|
|
487
|
+
_context2.next = 29;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
_context2.prev = 16;
|
|
491
|
+
_context2.next = 19;
|
|
492
|
+
return _response2.json();
|
|
493
|
+
case 19:
|
|
494
|
+
responseData = _context2.sent;
|
|
495
|
+
_context2.next = 27;
|
|
496
|
+
break;
|
|
497
|
+
case 22:
|
|
498
|
+
_context2.prev = 22;
|
|
499
|
+
_context2.t0 = _context2["catch"](16);
|
|
500
|
+
_context2.next = 26;
|
|
501
|
+
return _response2.text();
|
|
502
|
+
case 26:
|
|
503
|
+
responseData = _context2.sent;
|
|
504
|
+
case 27:
|
|
505
|
+
_context2.next = 58;
|
|
506
|
+
break;
|
|
507
|
+
case 29:
|
|
508
|
+
if (!(responseType === 'text')) {
|
|
509
|
+
_context2.next = 35;
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
_context2.next = 32;
|
|
513
|
+
return _response2.text();
|
|
514
|
+
case 32:
|
|
515
|
+
responseData = _context2.sent;
|
|
516
|
+
_context2.next = 58;
|
|
517
|
+
break;
|
|
518
|
+
case 35:
|
|
519
|
+
if (!(responseType === 'arraybuffer')) {
|
|
520
|
+
_context2.next = 41;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
_context2.next = 38;
|
|
524
|
+
return _response2.arrayBuffer();
|
|
525
|
+
case 38:
|
|
526
|
+
responseData = _context2.sent;
|
|
527
|
+
_context2.next = 58;
|
|
528
|
+
break;
|
|
529
|
+
case 41:
|
|
530
|
+
if (!(responseType === 'blob')) {
|
|
531
|
+
_context2.next = 47;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
_context2.next = 44;
|
|
535
|
+
return _response2.blob();
|
|
536
|
+
case 44:
|
|
537
|
+
responseData = _context2.sent;
|
|
538
|
+
_context2.next = 58;
|
|
539
|
+
break;
|
|
540
|
+
case 47:
|
|
541
|
+
_context2.prev = 47;
|
|
542
|
+
_context2.next = 50;
|
|
543
|
+
return _response2.json();
|
|
544
|
+
case 50:
|
|
545
|
+
responseData = _context2.sent;
|
|
546
|
+
_context2.next = 58;
|
|
547
|
+
break;
|
|
548
|
+
case 53:
|
|
549
|
+
_context2.prev = 53;
|
|
550
|
+
_context2.t1 = _context2["catch"](47);
|
|
551
|
+
_context2.next = 57;
|
|
552
|
+
return _response2.text();
|
|
553
|
+
case 57:
|
|
554
|
+
responseData = _context2.sent;
|
|
555
|
+
case 58:
|
|
556
|
+
// 构建响应对象
|
|
557
|
+
result = {
|
|
558
|
+
data: responseData,
|
|
559
|
+
status: _response2.status,
|
|
560
|
+
statusText: _response2.statusText,
|
|
561
|
+
headers: responseHeaders,
|
|
562
|
+
config: config
|
|
563
|
+
}; // 处理非成功状态码
|
|
564
|
+
if (_response2.ok) {
|
|
565
|
+
_context2.next = 61;
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
throw new RequestError("\u8BF7\u6C42\u5931\u8D25\uFF0C\u72B6\u6001\u7801: ".concat(_response2.status), config, fetchOptions, result);
|
|
569
|
+
case 61:
|
|
570
|
+
return _context2.abrupt("return", result);
|
|
571
|
+
case 62:
|
|
572
|
+
_context2.prev = 62;
|
|
573
|
+
// 清除超时计时器
|
|
574
|
+
if (timeoutId) {
|
|
575
|
+
clearTimeout(timeoutId);
|
|
576
|
+
}
|
|
577
|
+
return _context2.finish(62);
|
|
578
|
+
case 65:
|
|
579
|
+
case "end":
|
|
580
|
+
return _context2.stop();
|
|
581
|
+
}
|
|
582
|
+
}, _callee2, null, [[8,, 62, 65], [16, 22], [47, 53]]);
|
|
583
|
+
}));
|
|
584
|
+
function performRequest(_x2) {
|
|
585
|
+
return _performRequest.apply(this, arguments);
|
|
586
|
+
}
|
|
587
|
+
return performRequest;
|
|
588
|
+
}())
|
|
589
|
+
}]);
|
|
590
|
+
return RequestPluginImpl;
|
|
591
|
+
}();
|
|
592
|
+
export default new RequestPluginImpl();
|