@cclr/service 0.1.17
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/LICENSE +19 -0
- package/README.md +11 -0
- package/lib/cjs/index.js +662 -0
- package/lib/esm/index.js +659 -0
- package/lib/type/index.d.ts +60 -0
- package/package.json +36 -0
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import { logger } from '@cclr/logger';
|
|
2
|
+
|
|
3
|
+
function _assertThisInitialized(e) {
|
|
4
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
5
|
+
return e;
|
|
6
|
+
}
|
|
7
|
+
function _callSuper(t, o, e) {
|
|
8
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
9
|
+
}
|
|
10
|
+
function _classCallCheck(a, n) {
|
|
11
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
12
|
+
}
|
|
13
|
+
function _defineProperties(e, r) {
|
|
14
|
+
for (var t = 0; t < r.length; t++) {
|
|
15
|
+
var o = r[t];
|
|
16
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _createClass(e, r, t) {
|
|
20
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
21
|
+
writable: false
|
|
22
|
+
}), e;
|
|
23
|
+
}
|
|
24
|
+
function _defineProperty(e, r, t) {
|
|
25
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
26
|
+
value: t,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
}) : e[r] = t, e;
|
|
31
|
+
}
|
|
32
|
+
function _getPrototypeOf(t) {
|
|
33
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
34
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
35
|
+
}, _getPrototypeOf(t);
|
|
36
|
+
}
|
|
37
|
+
function _inherits(t, e) {
|
|
38
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
39
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
40
|
+
constructor: {
|
|
41
|
+
value: t,
|
|
42
|
+
writable: true,
|
|
43
|
+
configurable: true
|
|
44
|
+
}
|
|
45
|
+
}), Object.defineProperty(t, "prototype", {
|
|
46
|
+
writable: false
|
|
47
|
+
}), e && _setPrototypeOf(t, e);
|
|
48
|
+
}
|
|
49
|
+
function _isNativeReflectConstruct() {
|
|
50
|
+
try {
|
|
51
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
52
|
+
} catch (t) {}
|
|
53
|
+
return (_isNativeReflectConstruct = function () {
|
|
54
|
+
return !!t;
|
|
55
|
+
})();
|
|
56
|
+
}
|
|
57
|
+
function ownKeys(e, r) {
|
|
58
|
+
var t = Object.keys(e);
|
|
59
|
+
if (Object.getOwnPropertySymbols) {
|
|
60
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
61
|
+
r && (o = o.filter(function (r) {
|
|
62
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
63
|
+
})), t.push.apply(t, o);
|
|
64
|
+
}
|
|
65
|
+
return t;
|
|
66
|
+
}
|
|
67
|
+
function _objectSpread2(e) {
|
|
68
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
69
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
70
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
71
|
+
_defineProperty(e, r, t[r]);
|
|
72
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
73
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return e;
|
|
77
|
+
}
|
|
78
|
+
function _possibleConstructorReturn(t, e) {
|
|
79
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
80
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
81
|
+
return _assertThisInitialized(t);
|
|
82
|
+
}
|
|
83
|
+
function _setPrototypeOf(t, e) {
|
|
84
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
85
|
+
return t.__proto__ = e, t;
|
|
86
|
+
}, _setPrototypeOf(t, e);
|
|
87
|
+
}
|
|
88
|
+
function _toPrimitive(t, r) {
|
|
89
|
+
if ("object" != typeof t || !t) return t;
|
|
90
|
+
var e = t[Symbol.toPrimitive];
|
|
91
|
+
if (void 0 !== e) {
|
|
92
|
+
var i = e.call(t, r);
|
|
93
|
+
if ("object" != typeof i) return i;
|
|
94
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
95
|
+
}
|
|
96
|
+
return ("string" === r ? String : Number)(t);
|
|
97
|
+
}
|
|
98
|
+
function _toPropertyKey(t) {
|
|
99
|
+
var i = _toPrimitive(t, "string");
|
|
100
|
+
return "symbol" == typeof i ? i : i + "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var n = function n(_n, t, r) {
|
|
104
|
+
if (r) for (var e = _n.length - 1; e >= 0; e--) t(_n[e], e, _n);else for (var o = 0; o < _n.length; o++) t(_n[o], o, _n);
|
|
105
|
+
};
|
|
106
|
+
Function.prototype.call.bind(Object.prototype.hasOwnProperty);
|
|
107
|
+
var e = Function.prototype.call.bind(Object.prototype.toString),
|
|
108
|
+
o = {
|
|
109
|
+
boolean: "boolean",
|
|
110
|
+
undefined: "undefined",
|
|
111
|
+
number: "number",
|
|
112
|
+
string: "string",
|
|
113
|
+
symbol: "symbol",
|
|
114
|
+
null: "null",
|
|
115
|
+
"[object Object]": "object",
|
|
116
|
+
"[object Function]": "function",
|
|
117
|
+
"[object RegExp]": "regexp",
|
|
118
|
+
"[object Array]": "array",
|
|
119
|
+
"[object Date]": "date",
|
|
120
|
+
"[object Error]": "error",
|
|
121
|
+
"[object Blob]": "blob",
|
|
122
|
+
"[object File]": "file",
|
|
123
|
+
"[object ArrayBuffer]": "arrayBuffer"
|
|
124
|
+
};
|
|
125
|
+
function u(n) {
|
|
126
|
+
return o[typeof n] || o[e(n)] || (n ? "object" : "null");
|
|
127
|
+
}
|
|
128
|
+
function c(n) {
|
|
129
|
+
return "string" === u(n);
|
|
130
|
+
}
|
|
131
|
+
function b(n) {
|
|
132
|
+
return null === n;
|
|
133
|
+
}
|
|
134
|
+
function y$1(n) {
|
|
135
|
+
return void 0 === n;
|
|
136
|
+
}
|
|
137
|
+
function s$1(n) {
|
|
138
|
+
return b(n) || y$1(n);
|
|
139
|
+
}
|
|
140
|
+
function A$1(n, t) {
|
|
141
|
+
(null == t || t > n.length) && (t = n.length);
|
|
142
|
+
for (var r = 0, e = Array(t); r < t; r++) e[r] = n[r];
|
|
143
|
+
return e;
|
|
144
|
+
}
|
|
145
|
+
function E(n) {
|
|
146
|
+
if (Array.isArray(n)) return n;
|
|
147
|
+
}
|
|
148
|
+
function S$1() {
|
|
149
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
150
|
+
}
|
|
151
|
+
function x(n) {
|
|
152
|
+
return E(n) || function (n) {
|
|
153
|
+
if ("undefined" != typeof Symbol && null != n[Symbol.iterator] || null != n["@@iterator"]) return Array.from(n);
|
|
154
|
+
}(n) || k$1(n) || S$1();
|
|
155
|
+
}
|
|
156
|
+
function k$1(n, t) {
|
|
157
|
+
if (n) {
|
|
158
|
+
if ("string" == typeof n) return A$1(n, t);
|
|
159
|
+
var r = {}.toString.call(n).slice(8, -1);
|
|
160
|
+
return "Object" === r && n.constructor && (r = n.constructor.name), "Map" === r || "Set" === r ? Array.from(n) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? A$1(n, t) : void 0;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
var _F = function F(n, t) {
|
|
164
|
+
var r = x(t),
|
|
165
|
+
e = r[0],
|
|
166
|
+
o = r.slice(1);
|
|
167
|
+
return n = n[e], o.length && n ? _F(n, o) : n;
|
|
168
|
+
},
|
|
169
|
+
I$1 = function I(n, t, r) {
|
|
170
|
+
var e = _F(n || {}, t.split("."));
|
|
171
|
+
return y$1(e) || b(e) ? r : e;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function f(t, r) {
|
|
175
|
+
(null == r || r > t.length) && (r = t.length);
|
|
176
|
+
for (var n = 0, e = Array(r); n < r; n++) e[n] = t[n];
|
|
177
|
+
return e;
|
|
178
|
+
}
|
|
179
|
+
function s(t, r, n) {
|
|
180
|
+
return r && function (t, r) {
|
|
181
|
+
for (var n = 0; n < r.length; n++) {
|
|
182
|
+
var e = r[n];
|
|
183
|
+
e.enumerable = e.enumerable || false, e.configurable = true, "value" in e && (e.writable = true), Object.defineProperty(t, m(e.key), e);
|
|
184
|
+
}
|
|
185
|
+
}(t.prototype, r), Object.defineProperty(t, "prototype", {
|
|
186
|
+
writable: false
|
|
187
|
+
}), t;
|
|
188
|
+
}
|
|
189
|
+
function p(t, r, n) {
|
|
190
|
+
return (r = m(r)) in t ? Object.defineProperty(t, r, {
|
|
191
|
+
value: n,
|
|
192
|
+
enumerable: true,
|
|
193
|
+
configurable: true,
|
|
194
|
+
writable: true
|
|
195
|
+
}) : t[r] = n, t;
|
|
196
|
+
}
|
|
197
|
+
function h(t, r) {
|
|
198
|
+
var n = Object.keys(t);
|
|
199
|
+
if (Object.getOwnPropertySymbols) {
|
|
200
|
+
var e = Object.getOwnPropertySymbols(t);
|
|
201
|
+
r && (e = e.filter(function (r) {
|
|
202
|
+
return Object.getOwnPropertyDescriptor(t, r).enumerable;
|
|
203
|
+
})), n.push.apply(n, e);
|
|
204
|
+
}
|
|
205
|
+
return n;
|
|
206
|
+
}
|
|
207
|
+
function y(t) {
|
|
208
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
209
|
+
var n = null != arguments[r] ? arguments[r] : {};
|
|
210
|
+
r % 2 ? h(Object(n), true).forEach(function (r) {
|
|
211
|
+
p(t, r, n[r]);
|
|
212
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(n)) : h(Object(n)).forEach(function (r) {
|
|
213
|
+
Object.defineProperty(t, r, Object.getOwnPropertyDescriptor(n, r));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return t;
|
|
217
|
+
}
|
|
218
|
+
function v(t, r) {
|
|
219
|
+
return v = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, r) {
|
|
220
|
+
return t.__proto__ = r, t;
|
|
221
|
+
}, v(t, r);
|
|
222
|
+
}
|
|
223
|
+
function d(t, r) {
|
|
224
|
+
return function (t) {
|
|
225
|
+
if (Array.isArray(t)) return t;
|
|
226
|
+
}(t) || function (t, r) {
|
|
227
|
+
var n = null == t ? null : "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
|
|
228
|
+
if (null != n) {
|
|
229
|
+
var e,
|
|
230
|
+
o,
|
|
231
|
+
i,
|
|
232
|
+
u,
|
|
233
|
+
a = [],
|
|
234
|
+
l = true,
|
|
235
|
+
c = false;
|
|
236
|
+
try {
|
|
237
|
+
if (i = (n = n.call(t)).next, 0 === r) ;else for (; !(l = (e = i.call(n)).done) && (a.push(e.value), a.length !== r); l = !0);
|
|
238
|
+
} catch (t) {
|
|
239
|
+
c = true, o = t;
|
|
240
|
+
} finally {
|
|
241
|
+
try {
|
|
242
|
+
if (!l && null != n.return && (u = n.return(), Object(u) !== u)) return;
|
|
243
|
+
} finally {
|
|
244
|
+
if (c) throw o;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return a;
|
|
248
|
+
}
|
|
249
|
+
}(t, r) || g(t, r) || function () {
|
|
250
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
251
|
+
}();
|
|
252
|
+
}
|
|
253
|
+
function m(t) {
|
|
254
|
+
var r = function (t, r) {
|
|
255
|
+
if ("object" != typeof t || !t) return t;
|
|
256
|
+
var n = t[Symbol.toPrimitive];
|
|
257
|
+
if (void 0 !== n) {
|
|
258
|
+
var e = n.call(t, r);
|
|
259
|
+
if ("object" != typeof e) return e;
|
|
260
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
261
|
+
}
|
|
262
|
+
return (String )(t);
|
|
263
|
+
}(t, "string");
|
|
264
|
+
return "symbol" == typeof r ? r : r + "";
|
|
265
|
+
}
|
|
266
|
+
function g(t, r) {
|
|
267
|
+
if (t) {
|
|
268
|
+
if ("string" == typeof t) return f(t, r);
|
|
269
|
+
var n = {}.toString.call(t).slice(8, -1);
|
|
270
|
+
return "Object" === n && t.constructor && (n = t.constructor.name), "Map" === n || "Set" === n ? Array.from(t) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? f(t, r) : void 0;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function O() {
|
|
274
|
+
O = function O(t, r) {
|
|
275
|
+
return new n(t, void 0, r);
|
|
276
|
+
};
|
|
277
|
+
var t = RegExp.prototype,
|
|
278
|
+
r = new WeakMap();
|
|
279
|
+
function n(t, e, o) {
|
|
280
|
+
var i = RegExp(t, e);
|
|
281
|
+
return r.set(i, o || r.get(t)), v(i, n.prototype);
|
|
282
|
+
}
|
|
283
|
+
function e(t, n) {
|
|
284
|
+
var e = r.get(n);
|
|
285
|
+
return Object.keys(e).reduce(function (r, n) {
|
|
286
|
+
var o = e[n];
|
|
287
|
+
if ("number" == typeof o) r[n] = t[o];else {
|
|
288
|
+
for (var i = 0; void 0 === t[o[i]] && i + 1 < o.length;) i++;
|
|
289
|
+
r[n] = t[o[i]];
|
|
290
|
+
}
|
|
291
|
+
return r;
|
|
292
|
+
}, Object.create(null));
|
|
293
|
+
}
|
|
294
|
+
return function (t, r) {
|
|
295
|
+
if ("function" != typeof r && null !== r) throw new TypeError("Super expression must either be null or a function");
|
|
296
|
+
t.prototype = Object.create(r && r.prototype, {
|
|
297
|
+
constructor: {
|
|
298
|
+
value: t,
|
|
299
|
+
writable: true,
|
|
300
|
+
configurable: true
|
|
301
|
+
}
|
|
302
|
+
}), Object.defineProperty(t, "prototype", {
|
|
303
|
+
writable: false
|
|
304
|
+
}), r && v(t, r);
|
|
305
|
+
}(n, RegExp), n.prototype.exec = function (r) {
|
|
306
|
+
var n = t.exec.call(this, r);
|
|
307
|
+
if (n) {
|
|
308
|
+
n.groups = e(n, this);
|
|
309
|
+
var o = n.indices;
|
|
310
|
+
o && (o.groups = e(o, this));
|
|
311
|
+
}
|
|
312
|
+
return n;
|
|
313
|
+
}, n.prototype[Symbol.replace] = function (n, o) {
|
|
314
|
+
if ("string" == typeof o) {
|
|
315
|
+
var i = r.get(this);
|
|
316
|
+
return t[Symbol.replace].call(this, n, o.replace(/\$<([^>]+)>/g, function (t, r) {
|
|
317
|
+
var n = i[r];
|
|
318
|
+
return "$" + (Array.isArray(n) ? n.join("$") : n);
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
if ("function" == typeof o) {
|
|
322
|
+
var u = this;
|
|
323
|
+
return t[Symbol.replace].call(this, n, function () {
|
|
324
|
+
var t = arguments;
|
|
325
|
+
return "object" != typeof t[t.length - 1] && (t = [].slice.call(t)).push(e(t, u)), o.apply(this, t);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return t[Symbol.replace].call(this, n, o);
|
|
329
|
+
}, O.apply(this, arguments);
|
|
330
|
+
}
|
|
331
|
+
var j = function () {
|
|
332
|
+
return s(function t() {
|
|
333
|
+
!function (t, r) {
|
|
334
|
+
if (!(t instanceof r)) throw new TypeError("Cannot call a class as a function");
|
|
335
|
+
}(this, t), p(this, "handler", []);
|
|
336
|
+
}, [{
|
|
337
|
+
key: "use",
|
|
338
|
+
value: function value(t, r) {
|
|
339
|
+
return this.handler.push({
|
|
340
|
+
fulfilled: t,
|
|
341
|
+
rejected: r
|
|
342
|
+
}), this.handler.length - 1;
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
key: "eject",
|
|
346
|
+
value: function value(t) {
|
|
347
|
+
this.handler[t] && (this.handler[t] = null);
|
|
348
|
+
}
|
|
349
|
+
}, {
|
|
350
|
+
key: "clear",
|
|
351
|
+
value: function value() {
|
|
352
|
+
this.handler = [];
|
|
353
|
+
}
|
|
354
|
+
}, {
|
|
355
|
+
key: "forEach",
|
|
356
|
+
value: function value(t) {
|
|
357
|
+
var n$1 = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
|
|
358
|
+
n(this.handler, function (r) {
|
|
359
|
+
r && t(r);
|
|
360
|
+
}, n$1);
|
|
361
|
+
}
|
|
362
|
+
}, {
|
|
363
|
+
key: "run",
|
|
364
|
+
value: function value(t) {
|
|
365
|
+
var r = arguments;
|
|
366
|
+
return new Promise(function (n, e) {
|
|
367
|
+
var o = r.length > 1 && void 0 !== r[1] && r[1],
|
|
368
|
+
i = Promise.resolve(t());
|
|
369
|
+
return this.forEach(function (t) {
|
|
370
|
+
i = i.then(t.fulfilled, t.rejected);
|
|
371
|
+
}, o), n(i);
|
|
372
|
+
}.bind(this));
|
|
373
|
+
}
|
|
374
|
+
}]);
|
|
375
|
+
}(),
|
|
376
|
+
w = new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?", "(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?", "(?<pathname>[^?#]*)", "(?:\\?(?<query>[^#]*))?", "(?:#(?<hash>.*))?"].join(""));
|
|
377
|
+
O(/\?([^#]*)/, {
|
|
378
|
+
query: 1
|
|
379
|
+
});
|
|
380
|
+
var S = O(/#(.*)/, {
|
|
381
|
+
hash: 1
|
|
382
|
+
}),
|
|
383
|
+
A = O(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/, {
|
|
384
|
+
pathname: 1
|
|
385
|
+
}),
|
|
386
|
+
k = function k(t) {
|
|
387
|
+
var r = t.protocol,
|
|
388
|
+
n = t.auth,
|
|
389
|
+
e = t.host,
|
|
390
|
+
o = t.hostname,
|
|
391
|
+
i = t.port,
|
|
392
|
+
u = t.pathname,
|
|
393
|
+
a = t.query,
|
|
394
|
+
l = t.search,
|
|
395
|
+
c = t.hash,
|
|
396
|
+
f = r ? "".concat(r, "//") : "",
|
|
397
|
+
s = n ? "".concat(n, "@") : "",
|
|
398
|
+
p = e || "".concat(o || "").concat(i ? ":".concat(i) : ""),
|
|
399
|
+
h = a ? "?".concat(a) : l || "",
|
|
400
|
+
y = c ? "#".concat(c) : "";
|
|
401
|
+
return "".concat(f).concat(s).concat(p).concat(u).concat(h).concat(y);
|
|
402
|
+
},
|
|
403
|
+
I = function I(t) {
|
|
404
|
+
if (!t) return "";
|
|
405
|
+
var r = t.split("?")[1];
|
|
406
|
+
return r ? r.replace(S, "") : "";
|
|
407
|
+
},
|
|
408
|
+
q = function q(t) {
|
|
409
|
+
if (!t) return {};
|
|
410
|
+
var r = I(t);
|
|
411
|
+
return r ? r.split("&").reduce(function (t, r) {
|
|
412
|
+
var n = r.indexOf("="),
|
|
413
|
+
e = (-1 !== n ? [r.substring(0, n), r.substring(n + 1)] : [r]).map(function (t) {
|
|
414
|
+
return decodeURIComponent(t.replace("+", " "));
|
|
415
|
+
});
|
|
416
|
+
return t[e[0]] = e[1], t;
|
|
417
|
+
}, {}) : {};
|
|
418
|
+
};
|
|
419
|
+
function R(t) {
|
|
420
|
+
var r = t.match(w),
|
|
421
|
+
n = I$1(r, "groups", {}),
|
|
422
|
+
o = n.protocol,
|
|
423
|
+
i = n.auth,
|
|
424
|
+
u = n.host,
|
|
425
|
+
a = n.pathname,
|
|
426
|
+
l = n.query,
|
|
427
|
+
c = n.hash,
|
|
428
|
+
f = null,
|
|
429
|
+
s = null;
|
|
430
|
+
if (u) {
|
|
431
|
+
var p = d(u.split(":"), 2);
|
|
432
|
+
f = p[0], s = p[1] || null;
|
|
433
|
+
}
|
|
434
|
+
return {
|
|
435
|
+
href: t,
|
|
436
|
+
protocol: o || null,
|
|
437
|
+
slashes: t.includes("//") || null,
|
|
438
|
+
auth: i ? i.slice(0, -1) : null,
|
|
439
|
+
host: u || null,
|
|
440
|
+
hostname: f || null,
|
|
441
|
+
port: s || null,
|
|
442
|
+
pathname: a || null,
|
|
443
|
+
search: l ? "?".concat(l) : null,
|
|
444
|
+
query: l || null,
|
|
445
|
+
hash: c || null
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
var D = function D(t) {
|
|
449
|
+
var r = [];
|
|
450
|
+
for (var n in t) {
|
|
451
|
+
var e = t[n];
|
|
452
|
+
s$1(e) ? r.push(encodeURIComponent(n) + "=") : r.push(encodeURIComponent(n) + "=" + encodeURIComponent(e));
|
|
453
|
+
}
|
|
454
|
+
return r.join("&");
|
|
455
|
+
},
|
|
456
|
+
C = ["queryObj"],
|
|
457
|
+
U = function U(t, r) {
|
|
458
|
+
var n = r.queryObj,
|
|
459
|
+
e = function (t, r) {
|
|
460
|
+
if (null == t) return {};
|
|
461
|
+
var n,
|
|
462
|
+
e,
|
|
463
|
+
o = function (t, r) {
|
|
464
|
+
if (null == t) return {};
|
|
465
|
+
var n = {};
|
|
466
|
+
for (var e in t) if ({}.hasOwnProperty.call(t, e)) {
|
|
467
|
+
if (-1 !== r.indexOf(e)) continue;
|
|
468
|
+
n[e] = t[e];
|
|
469
|
+
}
|
|
470
|
+
return n;
|
|
471
|
+
}(t, r);
|
|
472
|
+
if (Object.getOwnPropertySymbols) {
|
|
473
|
+
var i = Object.getOwnPropertySymbols(t);
|
|
474
|
+
for (e = 0; e < i.length; e++) n = i[e], -1 === r.indexOf(n) && {}.propertyIsEnumerable.call(t, n) && (o[n] = t[n]);
|
|
475
|
+
}
|
|
476
|
+
return o;
|
|
477
|
+
}(r, C),
|
|
478
|
+
o = y(y({}, R(t)), e),
|
|
479
|
+
i = y(y({}, q(o.search || "")), n);
|
|
480
|
+
return k(y(y({}, o), {}, {
|
|
481
|
+
search: "",
|
|
482
|
+
query: D(i)
|
|
483
|
+
}));
|
|
484
|
+
};
|
|
485
|
+
function z(t) {
|
|
486
|
+
var r,
|
|
487
|
+
n = t.match(A);
|
|
488
|
+
if (n) return (null === (r = n.groups) || void 0 === r ? void 0 : r.pathname) || "";
|
|
489
|
+
}
|
|
490
|
+
var M = {
|
|
491
|
+
parseUrl: R,
|
|
492
|
+
getPathArr: function getPathArr(t) {
|
|
493
|
+
var r = z(t);
|
|
494
|
+
if (!y$1(r)) return r.split("/").filter(Boolean);
|
|
495
|
+
},
|
|
496
|
+
getPathStr: z,
|
|
497
|
+
getQuery: I,
|
|
498
|
+
getQueryObj: q,
|
|
499
|
+
toQueryString: D,
|
|
500
|
+
change: U,
|
|
501
|
+
addQuery: function addQuery(t, r) {
|
|
502
|
+
return U(t, {
|
|
503
|
+
queryObj: r
|
|
504
|
+
});
|
|
505
|
+
},
|
|
506
|
+
combine: k
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* fetch 适配器
|
|
511
|
+
* @param options
|
|
512
|
+
* @returns
|
|
513
|
+
*/
|
|
514
|
+
var adaptRequestFetch = function adaptRequestFetch(options) {
|
|
515
|
+
var baseURL = options.baseURL,
|
|
516
|
+
headers = options.headers,
|
|
517
|
+
method = options.method,
|
|
518
|
+
data = options.data,
|
|
519
|
+
params = options.params;
|
|
520
|
+
var newUrlObj = M.parseUrl(baseURL);
|
|
521
|
+
newUrlObj.query = M.toQueryString(params || {});
|
|
522
|
+
var isGet = method === 'get';
|
|
523
|
+
var newRes = {
|
|
524
|
+
config: options
|
|
525
|
+
};
|
|
526
|
+
return fetch(M.combine(newUrlObj), {
|
|
527
|
+
method: method,
|
|
528
|
+
headers: headers,
|
|
529
|
+
body: !isGet && data ? JSON.stringify(data) : undefined
|
|
530
|
+
}).then(function (response) {
|
|
531
|
+
if (!response.ok) return Promise.reject(response);
|
|
532
|
+
newRes.status = response.status;
|
|
533
|
+
newRes.statusText = response.statusText;
|
|
534
|
+
newRes.config = options;
|
|
535
|
+
newRes.response = response;
|
|
536
|
+
return response.text();
|
|
537
|
+
}).then(function (text) {
|
|
538
|
+
newRes.data = text;
|
|
539
|
+
return newRes;
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
var defaultConfig = {
|
|
544
|
+
baseURL: '',
|
|
545
|
+
method: 'get',
|
|
546
|
+
headers: {
|
|
547
|
+
'Content-Type': 'application/json'
|
|
548
|
+
},
|
|
549
|
+
adapter: adaptRequestFetch
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
var Axios = /*#__PURE__*/function () {
|
|
553
|
+
function Axios() {
|
|
554
|
+
var defaultRequestConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultConfig;
|
|
555
|
+
_classCallCheck(this, Axios);
|
|
556
|
+
_defineProperty(this, "defaultRequestConfig", void 0);
|
|
557
|
+
/**
|
|
558
|
+
* 拦截器 中间件
|
|
559
|
+
*/
|
|
560
|
+
_defineProperty(this, "interceptors", {
|
|
561
|
+
request: new j(),
|
|
562
|
+
response: new j()
|
|
563
|
+
});
|
|
564
|
+
this.defaultRequestConfig = defaultRequestConfig;
|
|
565
|
+
}
|
|
566
|
+
return _createClass(Axios, [{
|
|
567
|
+
key: "request",
|
|
568
|
+
value: function request(options) {
|
|
569
|
+
return new Promise(function ($return, $error) {
|
|
570
|
+
var _this, newConfig, res, newRes;
|
|
571
|
+
_this = this;
|
|
572
|
+
return Promise.resolve(this.interceptors.request.run(function () {
|
|
573
|
+
return _objectSpread2(_objectSpread2({}, _this.defaultRequestConfig), options);
|
|
574
|
+
}, true)).then(function ($await_1) {
|
|
575
|
+
try {
|
|
576
|
+
newConfig = $await_1;
|
|
577
|
+
return Promise.resolve(newConfig.adapter(newConfig)).then(function ($await_2) {
|
|
578
|
+
try {
|
|
579
|
+
res = $await_2;
|
|
580
|
+
return Promise.resolve(this.interceptors.response.run(function () {
|
|
581
|
+
return res;
|
|
582
|
+
})).then(function ($await_3) {
|
|
583
|
+
try {
|
|
584
|
+
newRes = $await_3;
|
|
585
|
+
return $return(newRes.data);
|
|
586
|
+
} catch ($boundEx) {
|
|
587
|
+
return $error($boundEx);
|
|
588
|
+
}
|
|
589
|
+
}, $error);
|
|
590
|
+
} catch ($boundEx) {
|
|
591
|
+
return $error($boundEx);
|
|
592
|
+
}
|
|
593
|
+
}.bind(this), $error);
|
|
594
|
+
} catch ($boundEx) {
|
|
595
|
+
return $error($boundEx);
|
|
596
|
+
}
|
|
597
|
+
}.bind(this), $error);
|
|
598
|
+
}.bind(this));
|
|
599
|
+
}
|
|
600
|
+
}, {
|
|
601
|
+
key: "get",
|
|
602
|
+
value: function get(url, params, headers) {
|
|
603
|
+
var newParams = _objectSpread2(_objectSpread2({}, M.getQueryObj(url)), params);
|
|
604
|
+
return this.request({
|
|
605
|
+
method: 'get',
|
|
606
|
+
baseURL: url,
|
|
607
|
+
params: newParams,
|
|
608
|
+
headers: _objectSpread2({
|
|
609
|
+
'Content-Type': 'application/json'
|
|
610
|
+
}, headers)
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}, {
|
|
614
|
+
key: "post",
|
|
615
|
+
value: function post(url, data, headers) {
|
|
616
|
+
return this.request({
|
|
617
|
+
baseURL: url,
|
|
618
|
+
method: 'post',
|
|
619
|
+
data: data,
|
|
620
|
+
headers: _objectSpread2({
|
|
621
|
+
'Content-Type': 'application/json'
|
|
622
|
+
}, headers)
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
}]);
|
|
626
|
+
}();
|
|
627
|
+
|
|
628
|
+
var ServiceBase = /*#__PURE__*/function (_Axios) {
|
|
629
|
+
function ServiceBase() {
|
|
630
|
+
var _this;
|
|
631
|
+
_classCallCheck(this, ServiceBase);
|
|
632
|
+
_this = _callSuper(this, ServiceBase);
|
|
633
|
+
_this.interceptors.response.use(function (config) {
|
|
634
|
+
var data = config.data;
|
|
635
|
+
if (c(data)) {
|
|
636
|
+
try {
|
|
637
|
+
config.data = JSON.parse(data);
|
|
638
|
+
} catch (_error) {
|
|
639
|
+
logger.warn('response data is not json', data);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return config;
|
|
643
|
+
});
|
|
644
|
+
return _this;
|
|
645
|
+
}
|
|
646
|
+
_inherits(ServiceBase, _Axios);
|
|
647
|
+
return _createClass(ServiceBase, null, [{
|
|
648
|
+
key: "create",
|
|
649
|
+
value: function create() {
|
|
650
|
+
if (!ServiceBase.service) {
|
|
651
|
+
ServiceBase.service = new ServiceBase();
|
|
652
|
+
}
|
|
653
|
+
return ServiceBase.service;
|
|
654
|
+
}
|
|
655
|
+
}]);
|
|
656
|
+
}(Axios);
|
|
657
|
+
_defineProperty(ServiceBase, "service", void 0);
|
|
658
|
+
|
|
659
|
+
export { Axios, ServiceBase };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { TPlainObject } from '@cclr/lang';
|
|
2
|
+
import { Interceptor } from '@cclr/utils';
|
|
3
|
+
|
|
4
|
+
type Method = 'get' | 'delete' | 'head' | 'post' | 'put' | 'patch' | 'options';
|
|
5
|
+
type TAxiosConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* 请求地址,只包含query前面部分
|
|
8
|
+
* - http://www.***.com/aa/bb
|
|
9
|
+
*/
|
|
10
|
+
baseURL: string;
|
|
11
|
+
/** 请求方法 */
|
|
12
|
+
method: Method;
|
|
13
|
+
/** get 请求的参数 */
|
|
14
|
+
params?: TPlainObject;
|
|
15
|
+
/** post请求的body */
|
|
16
|
+
data?: TPlainObject;
|
|
17
|
+
/** 请求头 */
|
|
18
|
+
headers: TPlainObject;
|
|
19
|
+
/** 适配器 */
|
|
20
|
+
adapter: <T>(options: TAxiosConfig) => Promise<TAxiosResponse<T>>;
|
|
21
|
+
};
|
|
22
|
+
interface TAxiosResponse<TData = any> {
|
|
23
|
+
/** 返回的数据 */
|
|
24
|
+
data: TData;
|
|
25
|
+
/** 状态码 */
|
|
26
|
+
status: number;
|
|
27
|
+
/** 状态描述 */
|
|
28
|
+
statusText: string;
|
|
29
|
+
/** 相应头 */
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
/** 请求配置 */
|
|
32
|
+
config: TAxiosConfig;
|
|
33
|
+
/** 响应体 */
|
|
34
|
+
response: Response;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare class Axios {
|
|
38
|
+
private defaultRequestConfig;
|
|
39
|
+
constructor(defaultRequestConfig?: TAxiosConfig);
|
|
40
|
+
/**
|
|
41
|
+
* 拦截器 中间件
|
|
42
|
+
*/
|
|
43
|
+
interceptors: {
|
|
44
|
+
request: Interceptor<TAxiosConfig>;
|
|
45
|
+
response: Interceptor<TAxiosResponse<any>>;
|
|
46
|
+
};
|
|
47
|
+
request<T>(options: Partial<TAxiosConfig>): Promise<any>;
|
|
48
|
+
get<T>(url: string, params: TPlainObject, headers?: TPlainObject): Promise<any>;
|
|
49
|
+
post<T>(url: string, data: TPlainObject, headers: TPlainObject): Promise<any>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 定义一个抽象类 */
|
|
53
|
+
|
|
54
|
+
declare class ServiceBase extends Axios {
|
|
55
|
+
constructor();
|
|
56
|
+
static service: ServiceBase;
|
|
57
|
+
static create(): ServiceBase;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Axios, ServiceBase };
|