@zyzgroup/core-web 0.0.83 → 0.0.84

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.
@@ -11175,65 +11175,57 @@ async function Qh(n, t = "SHA-256") {
11175
11175
  }
11176
11176
  class Tl {
11177
11177
  instance;
11178
- interceptors;
11179
- requestCanceler;
11178
+ // Alter defaults after instance has been created
11179
+ // axios.defaults.baseURL = "";
11180
+ // axios.defaults.timeout = 30000;
11181
+ // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
11182
+ // axios.defaults.headers.post.Accept = 'application/json';
11183
+ // axios.defaults.responseType = 'json'; // json | stream
11184
+ // .then(function (response) {response.data.pipe(fs.createWriteStream('xxx.jpg'))});
11180
11185
  constructor(t) {
11181
- this.instance = Zh.create(t), this.interceptors = t?.interceptors, this.requestCanceler = new tc(), this.instance.interceptors.request.use(
11182
- (e) => (this.requestCanceler.pendingRequest(e), e),
11183
- (e) => (this.requestCanceler.cancelRequest(e.config), e)
11184
- ), this.instance.interceptors.request.use(
11185
- this.interceptors?.requestInterceptor,
11186
- this.interceptors?.requestInterceptorCatch
11186
+ this.instance = Zh.create(t);
11187
+ const e = new tc();
11188
+ this.instance.interceptors.request.use(
11189
+ (s) => (e.pendingRequest(s), s),
11190
+ (s) => (e.cancelRequest(s.config), s)
11191
+ ), t?.interceptor && (this.instance.interceptors.request.use(
11192
+ t.interceptor.request,
11193
+ t.interceptor.requestError
11187
11194
  ), this.instance.interceptors.response.use(
11188
- this.interceptors?.responseInterceptor,
11189
- this.interceptors?.responseInterceptorCatch
11190
- ), this.instance.interceptors.response.use(
11191
- (e) => new Promise((s, i) => {
11192
- this.requestCanceler.confirmRequest(e.config), e.status === 200 ? s(e.data) : i(e.data);
11193
- }),
11194
- async (e) => {
11195
- const { code: s = "", config: i } = e;
11196
- return !i || !i.retry || !i.retryStatus?.includes(s) || (i.retryCounted = i.retryCounted ?? 0, i.retryCounted >= i.retry) ? Promise.reject(e) : (i.retryCounted++, await new Promise((r) => {
11197
- setTimeout(() => {
11198
- r(void 0);
11199
- }, i.retryDelay);
11200
- }), await this.request(i));
11195
+ t.interceptor.response,
11196
+ t.interceptor.responseError
11197
+ )), this.instance.interceptors.response.use(
11198
+ async (s) => (await e.confirmRequest(s.config), s.data),
11199
+ async (s) => {
11200
+ const { code: i = "", config: r } = s;
11201
+ return !r || !r.retry || (r.retryCounted = r.retryCounted || 0, r.retryCounted >= r.retry) ? Promise.reject(s) : (r.retryCounted++, await new Promise((a) => {
11202
+ setTimeout(a, r.retryDelay);
11203
+ }), await this.request(r));
11201
11204
  }
11202
11205
  );
11203
11206
  }
11204
- /** 发出请求 */
11205
- request(t) {
11206
- return new Promise((e, s) => {
11207
- try {
11208
- t.interceptors?.requestInterceptor && (t = t.interceptors?.requestInterceptor(t)), this.instance.request(t).then((i) => {
11209
- t.interceptors?.responseInterceptor && (i = t.interceptors.responseInterceptor(i)), e(i);
11210
- }).catch((i) => {
11211
- t.interceptors?.responseInterceptorCatch && (i = t.interceptors?.responseInterceptorCatch(i)), s(i);
11212
- });
11213
- } catch (i) {
11214
- t.interceptors?.requestInterceptorCatch && t.interceptors.requestInterceptorCatch(i);
11215
- }
11216
- });
11207
+ async request(t) {
11208
+ return await this.instance.request(t);
11217
11209
  }
11218
- get(t, e) {
11210
+ async get(t, e) {
11219
11211
  return this.request({ ...e, method: "get", url: t });
11220
11212
  }
11221
- delete(t, e) {
11213
+ async delete(t, e) {
11222
11214
  return this.request({ ...e, method: "delete", url: t });
11223
11215
  }
11224
- head(t, e) {
11216
+ async head(t, e) {
11225
11217
  return this.request({ ...e, method: "head", url: t });
11226
11218
  }
11227
- options(t, e) {
11219
+ async options(t, e) {
11228
11220
  return this.request({ ...e, method: "options", url: t });
11229
11221
  }
11230
- post(t, e, s) {
11222
+ async post(t, e, s) {
11231
11223
  return this.request({ ...s, method: "post", url: t, data: e });
11232
11224
  }
11233
- put(t, e, s) {
11225
+ async put(t, e, s) {
11234
11226
  return this.request({ ...s, method: "put", url: t, data: e });
11235
11227
  }
11236
- patch(t, e, s) {
11228
+ async patch(t, e, s) {
11237
11229
  return this.request({ ...s, method: "patch", url: t, data: e });
11238
11230
  }
11239
11231
  getUri(t) {
@@ -11245,6 +11237,10 @@ class tc {
11245
11237
  constructor() {
11246
11238
  this.pendingRequestMap = /* @__PURE__ */ new Map();
11247
11239
  }
11240
+ async getRequestId(t) {
11241
+ const { url: e, method: s, params: i, data: r } = t;
11242
+ return await Qh({ url: e, method: s, params: i, data: r });
11243
+ }
11248
11244
  async pendingRequest(t) {
11249
11245
  const e = await this.getRequestId(t);
11250
11246
  if (this.pendingRequestMap.has(e))
@@ -11267,14 +11263,11 @@ class tc {
11267
11263
  this.pendingRequestMap.has(e) && (this.pendingRequestMap.get(e)?.abort(), this.pendingRequestMap.delete(e));
11268
11264
  }
11269
11265
  async cancelAllRequest() {
11270
- for (const t of this.pendingRequestMap.values())
11271
- t.abort();
11266
+ const t = this.pendingRequestMap.values();
11267
+ for (const e of t)
11268
+ e.abort();
11272
11269
  this.pendingRequestMap.clear();
11273
11270
  }
11274
- async getRequestId(t) {
11275
- const { url: e, method: s, params: i, data: r } = t;
11276
- return await Qh({ url: e, method: s, params: i, data: r });
11277
- }
11278
11271
  }
11279
11272
  function Pl(n, t, e, s, i) {
11280
11273
  const r = t / e;