@univerjs/network 0.4.2 → 0.5.0-alpha.0

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/lib/es/index.js CHANGED
@@ -1,69 +1,67 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { createIdentifier, Disposable, toDisposable, remove, Inject, Injector, Plugin, registerDependencies, mergeOverrideWithDependencies, DisposableCollection } from "@univerjs/core";
6
- import { of, firstValueFrom, Observable, catchError, throwError } from "rxjs";
7
- import { concatMap, share, retry } from "rxjs/operators";
8
- const ApplicationJSONType = "application/json", _HTTPHeaders = class _HTTPHeaders {
9
- constructor(headers) {
10
- __publicField(this, "_headers", /* @__PURE__ */ new Map());
11
- typeof headers == "string" ? this._handleHeadersString(headers) : headers instanceof Headers ? this._handleHeaders(headers) : headers && this._handleHeadersConstructorProps(headers);
12
- }
13
- forEach(callback) {
14
- this._headers.forEach((v, key) => callback(key, v));
15
- }
16
- has(key) {
17
- return !!this._headers.has(key.toLowerCase());
18
- }
19
- get(key) {
20
- const k = key.toLowerCase();
21
- return this._headers.has(k) ? this._headers.get(k) : null;
22
- }
23
- set(key, value) {
24
- this._setHeader(key, value);
1
+ var z = Object.defineProperty;
2
+ var J = (e, r, n) => r in e ? z(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
3
+ var u = (e, r, n) => J(e, typeof r != "symbol" ? r + "" : r, n);
4
+ import { createIdentifier as B, Disposable as G, toDisposable as R, remove as V, Inject as K, Injector as Y, Plugin as Q, registerDependencies as Z, mergeOverrideWithDependencies as P, DisposableCollection as S } from "@univerjs/core";
5
+ import { of as D, firstValueFrom as H, Observable as w, catchError as C, throwError as T } from "rxjs";
6
+ import { concatMap as O, share as b, retry as ee } from "rxjs/operators";
7
+ const k = "application/json";
8
+ class v {
9
+ constructor(r) {
10
+ u(this, "_headers", /* @__PURE__ */ new Map());
11
+ typeof r == "string" ? this._handleHeadersString(r) : r instanceof Headers ? this._handleHeaders(r) : r && this._handleHeadersConstructorProps(r);
12
+ }
13
+ forEach(r) {
14
+ this._headers.forEach((n, t) => r(t, n));
15
+ }
16
+ has(r) {
17
+ return !!this._headers.has(r.toLowerCase());
18
+ }
19
+ get(r) {
20
+ const n = r.toLowerCase();
21
+ return this._headers.has(n) ? this._headers.get(n) : null;
22
+ }
23
+ set(r, n) {
24
+ this._setHeader(r, n);
25
25
  }
26
26
  toHeadersInit() {
27
- var _a3, _b;
28
- const headers = {};
29
- return this._headers.forEach((values, key) => {
30
- headers[key] = values.join(",");
31
- }), (_a3 = headers.accept) != null || (headers.accept = "application/json, text/plain, */*"), (_b = headers["content-type"]) != null || (headers["content-type"] = "application/json;charset=UTF-8"), headers;
32
- }
33
- _setHeader(name, value) {
34
- const lowerCase = name.toLowerCase();
35
- this._headers.has(lowerCase) ? this._headers.get(lowerCase).push(value.toString()) : this._headers.set(lowerCase, [value.toString()]);
36
- }
37
- _handleHeadersString(headers) {
38
- headers.split(`
39
- `).forEach((header) => {
40
- const [name, value] = header.split(":");
41
- name && value && this._setHeader(name, value);
27
+ var n, t;
28
+ const r = {};
29
+ return this._headers.forEach((s, i) => {
30
+ r[i] = s.join(",");
31
+ }), (n = r.accept) != null || (r.accept = "application/json, text/plain, */*"), (t = r["content-type"]) != null || (r["content-type"] = "application/json;charset=UTF-8"), r;
32
+ }
33
+ _setHeader(r, n) {
34
+ const t = r.toLowerCase();
35
+ this._headers.has(t) ? this._headers.get(t).push(n.toString()) : this._headers.set(t, [n.toString()]);
36
+ }
37
+ _handleHeadersString(r) {
38
+ r.split(`
39
+ `).forEach((n) => {
40
+ const [t, s] = n.split(":");
41
+ t && s && this._setHeader(t, s);
42
42
  });
43
43
  }
44
- _handleHeadersConstructorProps(headers) {
45
- Object.entries(headers).forEach(([name, value]) => this._setHeader(name, value));
44
+ _handleHeadersConstructorProps(r) {
45
+ Object.entries(r).forEach(([n, t]) => this._setHeader(n, t));
46
46
  }
47
- _handleHeaders(headers) {
48
- headers.forEach((value, name) => this._setHeader(name, value));
47
+ _handleHeaders(r) {
48
+ r.forEach((n, t) => this._setHeader(t, n));
49
49
  }
50
- };
51
- __name(_HTTPHeaders, "HTTPHeaders");
52
- let HTTPHeaders = _HTTPHeaders;
53
- const IHTTPImplementation = createIdentifier("network.http-implementation"), _HTTPParams = class _HTTPParams {
54
- constructor(params) {
55
- this.params = params;
50
+ }
51
+ const W = B("network.http-implementation");
52
+ class M {
53
+ constructor(r) {
54
+ this.params = r;
56
55
  }
57
56
  toString() {
58
- return this.params ? Object.keys(this.params).map((key) => `${key}=${this.params[key]}`).join("&") : "";
57
+ return this.params ? Object.keys(this.params).map((r) => `${r}=${this.params[r]}`).join("&") : "";
59
58
  }
60
- };
61
- __name(_HTTPParams, "HTTPParams");
62
- let HTTPParams = _HTTPParams, HTTPRequestUID = 0;
63
- const _HTTPRequest = class _HTTPRequest {
64
- constructor(method, url, requestParams) {
65
- __publicField(this, "uid", HTTPRequestUID++);
66
- this.method = method, this.url = url, this.requestParams = requestParams;
59
+ }
60
+ let re = 0;
61
+ class j {
62
+ constructor(r, n, t) {
63
+ u(this, "uid", re++);
64
+ this.method = r, this.url = n, this.requestParams = t;
67
65
  }
68
66
  get headers() {
69
67
  return this.requestParams.headers;
@@ -75,33 +73,31 @@ const _HTTPRequest = class _HTTPRequest {
75
73
  return this.requestParams.responseType;
76
74
  }
77
75
  getUrlWithParams() {
78
- var _a3, _b;
79
- const params = (_b = (_a3 = this.requestParams) == null ? void 0 : _a3.params) == null ? void 0 : _b.toString();
80
- return params ? `${this.url}${this.url.includes("?") ? "&" : "?"}${params}` : this.url;
76
+ var n, t;
77
+ const r = (t = (n = this.requestParams) == null ? void 0 : n.params) == null ? void 0 : t.toString();
78
+ return r ? `${this.url}${this.url.includes("?") ? "&" : "?"}${r}` : this.url;
81
79
  }
82
80
  getBody() {
83
- var _a3, _b;
84
- const contentType = (_a3 = this.headers.get("Content-Type")) != null ? _a3 : ApplicationJSONType, body = (_b = this.requestParams) == null ? void 0 : _b.body;
85
- return contentType === ApplicationJSONType && body && typeof body == "object" ? JSON.stringify(body) : body ? `${body}` : null;
81
+ var t, s;
82
+ const r = (t = this.headers.get("Content-Type")) != null ? t : k, n = (s = this.requestParams) == null ? void 0 : s.body;
83
+ return r === k && n && typeof n == "object" ? JSON.stringify(n) : n ? `${n}` : null;
86
84
  }
87
85
  getHeadersInit() {
88
86
  return this.headers.toHeadersInit();
89
87
  }
90
- };
91
- __name(_HTTPRequest, "HTTPRequest");
92
- let HTTPRequest = _HTTPRequest;
93
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
94
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
95
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
96
- return kind && result && __defProp$1(target, key, result), result;
97
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
98
- let HTTPService = (_a = class extends Disposable {
99
- constructor(_http) {
88
+ }
89
+ var te = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, se = (e, r, n, t) => {
90
+ for (var s = t > 1 ? void 0 : t ? ne(r, n) : r, i = e.length - 1, o; i >= 0; i--)
91
+ (o = e[i]) && (s = (t ? o(r, n, s) : o(s)) || s);
92
+ return t && s && te(r, n, s), s;
93
+ }, oe = (e, r) => (n, t) => r(n, t, e);
94
+ let F = class extends G {
95
+ constructor(r) {
100
96
  super();
101
- __publicField(this, "_interceptors", []);
97
+ u(this, "_interceptors", []);
102
98
  // eslint-disable-next-line ts/no-explicit-any
103
- __publicField(this, "_pipe");
104
- this._http = _http;
99
+ u(this, "_pipe");
100
+ this._http = r;
105
101
  }
106
102
  /**
107
103
  * Register an HTTP interceptor.
@@ -109,446 +105,430 @@ let HTTPService = (_a = class extends Disposable {
109
105
  * @param interceptor the http interceptor
110
106
  * @returns a disposable handler to remove the interceptor
111
107
  */
112
- registerHTTPInterceptor(interceptor) {
113
- if (this._interceptors.indexOf(interceptor) !== -1)
108
+ registerHTTPInterceptor(r) {
109
+ if (this._interceptors.indexOf(r) !== -1)
114
110
  throw new Error("[HTTPService]: The interceptor has already been registered!");
115
- return this._interceptors.push(interceptor), this._interceptors = this._interceptors.sort((a, b) => {
116
- var _a3, _b;
117
- return ((_a3 = a.priority) != null ? _a3 : 0) - ((_b = b.priority) != null ? _b : 0);
118
- }), this._pipe = null, toDisposable(() => remove(this._interceptors, interceptor));
111
+ return this._interceptors.push(r), this._interceptors = this._interceptors.sort((n, t) => {
112
+ var s, i;
113
+ return ((s = n.priority) != null ? s : 0) - ((i = t.priority) != null ? i : 0);
114
+ }), this._pipe = null, R(() => V(this._interceptors, r));
119
115
  }
120
- get(url, params) {
121
- return this._request("GET", url, params);
116
+ get(r, n) {
117
+ return this._request("GET", r, n);
122
118
  }
123
- post(url, params) {
124
- return this._request("POST", url, params);
119
+ post(r, n) {
120
+ return this._request("POST", r, n);
125
121
  }
126
- put(url, params) {
127
- return this._request("PUT", url, params);
122
+ put(r, n) {
123
+ return this._request("PUT", r, n);
128
124
  }
129
- delete(url, params) {
130
- return this._request("DELETE", url, params);
125
+ delete(r, n) {
126
+ return this._request("DELETE", r, n);
131
127
  }
132
- patch(url, options) {
133
- return this._request("PATCH", url, options);
128
+ patch(r, n) {
129
+ return this._request("PATCH", r, n);
134
130
  }
135
- getSSE(method, url, options) {
136
- var _a3, _b;
137
- const headers = new HTTPHeaders(options == null ? void 0 : options.headers), params = new HTTPParams(options == null ? void 0 : options.params), request = new HTTPRequest(method, url, {
138
- headers,
139
- params,
140
- withCredentials: (_a3 = options == null ? void 0 : options.withCredentials) != null ? _a3 : !1,
131
+ getSSE(r, n, t) {
132
+ var c, l;
133
+ const s = new v(t == null ? void 0 : t.headers), i = new M(t == null ? void 0 : t.params), o = new j(r, n, {
134
+ headers: s,
135
+ params: i,
136
+ withCredentials: (c = t == null ? void 0 : t.withCredentials) != null ? c : !1,
141
137
  reportProgress: !0,
142
- responseType: (_b = options == null ? void 0 : options.responseType) != null ? _b : "json",
143
- body: ["GET", "DELETE"].includes(method) || options == null ? void 0 : options.body
138
+ responseType: (l = t == null ? void 0 : t.responseType) != null ? l : "json",
139
+ body: ["GET", "DELETE"].includes(r) || t == null ? void 0 : t.body
144
140
  });
145
- return of(request).pipe(concatMap((request2) => this._runInterceptorsAndImplementation(request2)));
141
+ return D(o).pipe(O((a) => this._runInterceptorsAndImplementation(a)));
146
142
  }
147
143
  /** The HTTP request implementations */
148
- async _request(method, url, options) {
149
- var _a3, _b;
150
- const headers = new HTTPHeaders(options == null ? void 0 : options.headers), params = new HTTPParams(options == null ? void 0 : options.params), request = new HTTPRequest(method, url, {
151
- headers,
152
- params,
153
- withCredentials: (_a3 = options == null ? void 0 : options.withCredentials) != null ? _a3 : !1,
144
+ async _request(r, n, t) {
145
+ var a, h;
146
+ const s = new v(t == null ? void 0 : t.headers), i = new M(t == null ? void 0 : t.params), o = new j(r, n, {
147
+ headers: s,
148
+ params: i,
149
+ withCredentials: (a = t == null ? void 0 : t.withCredentials) != null ? a : !1,
154
150
  // default value for withCredentials is false by MDN
155
- responseType: (_b = options == null ? void 0 : options.responseType) != null ? _b : "json",
156
- body: ["GET", "DELETE"].includes(method) || options == null ? void 0 : options.body
157
- }), events$ = of(request).pipe(
158
- concatMap((request2) => this._runInterceptorsAndImplementation(request2))
151
+ responseType: (h = t == null ? void 0 : t.responseType) != null ? h : "json",
152
+ body: ["GET", "DELETE"].includes(r) || t == null ? void 0 : t.body
153
+ }), c = D(o).pipe(
154
+ O((m) => this._runInterceptorsAndImplementation(m))
159
155
  );
160
- return await firstValueFrom(events$);
156
+ return await H(c);
161
157
  }
162
158
  // eslint-disable-next-line ts/no-explicit-any
163
- _runInterceptorsAndImplementation(request) {
164
- return this._pipe || (this._pipe = this._interceptors.map((handler) => handler.interceptor).reduceRight(
165
- (nextHandlerFunction, interceptorFunction) => chainInterceptorFn(nextHandlerFunction, interceptorFunction),
166
- (requestFromPrevInterceptor, finalHandler) => finalHandler(requestFromPrevInterceptor)
159
+ _runInterceptorsAndImplementation(r) {
160
+ return this._pipe || (this._pipe = this._interceptors.map((n) => n.interceptor).reduceRight(
161
+ (n, t) => ie(n, t),
162
+ (n, t) => t(n)
167
163
  )), this._pipe(
168
- request,
169
- (requestToNext) => this._http.send(requestToNext)
164
+ r,
165
+ (n) => this._http.send(n)
170
166
  /* final handler */
171
167
  );
172
168
  }
173
- }, __name(_a, "HTTPService"), _a);
174
- HTTPService = __decorateClass$1([
175
- __decorateParam$1(0, IHTTPImplementation)
176
- ], HTTPService);
177
- function chainInterceptorFn(afterInterceptorChain, currentInterceptorFn) {
178
- return (prevRequest, nextHandlerFn) => currentInterceptorFn(prevRequest, (nextRequest) => afterInterceptorChain(nextRequest, nextHandlerFn));
169
+ };
170
+ F = se([
171
+ oe(0, W)
172
+ ], F);
173
+ function ie(e, r) {
174
+ return (n, t) => r(n, (s) => e(s, t));
179
175
  }
180
- __name(chainInterceptorFn, "chainInterceptorFn");
181
- const SuccessStatusCodeLowerBound = 200, ErrorStatusCodeLowerBound = 300;
182
- var HTTPStatusCode = /* @__PURE__ */ ((HTTPStatusCode2) => (HTTPStatusCode2[HTTPStatusCode2.Continue = 100] = "Continue", HTTPStatusCode2[HTTPStatusCode2.SwitchingProtocols = 101] = "SwitchingProtocols", HTTPStatusCode2[HTTPStatusCode2.Processing = 102] = "Processing", HTTPStatusCode2[HTTPStatusCode2.EarlyHints = 103] = "EarlyHints", HTTPStatusCode2[HTTPStatusCode2.Ok = 200] = "Ok", HTTPStatusCode2[HTTPStatusCode2.Created = 201] = "Created", HTTPStatusCode2[HTTPStatusCode2.Accepted = 202] = "Accepted", HTTPStatusCode2[HTTPStatusCode2.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", HTTPStatusCode2[HTTPStatusCode2.NoContent = 204] = "NoContent", HTTPStatusCode2[HTTPStatusCode2.ResetContent = 205] = "ResetContent", HTTPStatusCode2[HTTPStatusCode2.PartialContent = 206] = "PartialContent", HTTPStatusCode2[HTTPStatusCode2.MultiStatus = 207] = "MultiStatus", HTTPStatusCode2[HTTPStatusCode2.AlreadyReported = 208] = "AlreadyReported", HTTPStatusCode2[HTTPStatusCode2.ImUsed = 226] = "ImUsed", HTTPStatusCode2[HTTPStatusCode2.MultipleChoices = 300] = "MultipleChoices", HTTPStatusCode2[HTTPStatusCode2.MovedPermanently = 301] = "MovedPermanently", HTTPStatusCode2[HTTPStatusCode2.Found = 302] = "Found", HTTPStatusCode2[HTTPStatusCode2.SeeOther = 303] = "SeeOther", HTTPStatusCode2[HTTPStatusCode2.NotModified = 304] = "NotModified", HTTPStatusCode2[HTTPStatusCode2.UseProxy = 305] = "UseProxy", HTTPStatusCode2[HTTPStatusCode2.Unused = 306] = "Unused", HTTPStatusCode2[HTTPStatusCode2.TemporaryRedirect = 307] = "TemporaryRedirect", HTTPStatusCode2[HTTPStatusCode2.PermanentRedirect = 308] = "PermanentRedirect", HTTPStatusCode2[HTTPStatusCode2.BadRequest = 400] = "BadRequest", HTTPStatusCode2[HTTPStatusCode2.Unauthorized = 401] = "Unauthorized", HTTPStatusCode2[HTTPStatusCode2.PaymentRequired = 402] = "PaymentRequired", HTTPStatusCode2[HTTPStatusCode2.Forbidden = 403] = "Forbidden", HTTPStatusCode2[HTTPStatusCode2.NotFound = 404] = "NotFound", HTTPStatusCode2[HTTPStatusCode2.MethodNotAllowed = 405] = "MethodNotAllowed", HTTPStatusCode2[HTTPStatusCode2.NotAcceptable = 406] = "NotAcceptable", HTTPStatusCode2[HTTPStatusCode2.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", HTTPStatusCode2[HTTPStatusCode2.RequestTimeout = 408] = "RequestTimeout", HTTPStatusCode2[HTTPStatusCode2.Conflict = 409] = "Conflict", HTTPStatusCode2[HTTPStatusCode2.Gone = 410] = "Gone", HTTPStatusCode2[HTTPStatusCode2.LengthRequired = 411] = "LengthRequired", HTTPStatusCode2[HTTPStatusCode2.PreconditionFailed = 412] = "PreconditionFailed", HTTPStatusCode2[HTTPStatusCode2.PayloadTooLarge = 413] = "PayloadTooLarge", HTTPStatusCode2[HTTPStatusCode2.UriTooLong = 414] = "UriTooLong", HTTPStatusCode2[HTTPStatusCode2.UnsupportedMediaType = 415] = "UnsupportedMediaType", HTTPStatusCode2[HTTPStatusCode2.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", HTTPStatusCode2[HTTPStatusCode2.ExpectationFailed = 417] = "ExpectationFailed", HTTPStatusCode2[HTTPStatusCode2.ImATeapot = 418] = "ImATeapot", HTTPStatusCode2[HTTPStatusCode2.MisdirectedRequest = 421] = "MisdirectedRequest", HTTPStatusCode2[HTTPStatusCode2.UnprocessableEntity = 422] = "UnprocessableEntity", HTTPStatusCode2[HTTPStatusCode2.Locked = 423] = "Locked", HTTPStatusCode2[HTTPStatusCode2.FailedDependency = 424] = "FailedDependency", HTTPStatusCode2[HTTPStatusCode2.TooEarly = 425] = "TooEarly", HTTPStatusCode2[HTTPStatusCode2.UpgradeRequired = 426] = "UpgradeRequired", HTTPStatusCode2[HTTPStatusCode2.PreconditionRequired = 428] = "PreconditionRequired", HTTPStatusCode2[HTTPStatusCode2.TooManyRequests = 429] = "TooManyRequests", HTTPStatusCode2[HTTPStatusCode2.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", HTTPStatusCode2[HTTPStatusCode2.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", HTTPStatusCode2[HTTPStatusCode2.InternalServerError = 500] = "InternalServerError", HTTPStatusCode2[HTTPStatusCode2.NotImplemented = 501] = "NotImplemented", HTTPStatusCode2[HTTPStatusCode2.BadGateway = 502] = "BadGateway", HTTPStatusCode2[HTTPStatusCode2.ServiceUnavailable = 503] = "ServiceUnavailable", HTTPStatusCode2[HTTPStatusCode2.GatewayTimeout = 504] = "GatewayTimeout", HTTPStatusCode2[HTTPStatusCode2.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", HTTPStatusCode2[HTTPStatusCode2.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", HTTPStatusCode2[HTTPStatusCode2.InsufficientStorage = 507] = "InsufficientStorage", HTTPStatusCode2[HTTPStatusCode2.LoopDetected = 508] = "LoopDetected", HTTPStatusCode2[HTTPStatusCode2.NotExtended = 510] = "NotExtended", HTTPStatusCode2[HTTPStatusCode2.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", HTTPStatusCode2))(HTTPStatusCode || {}), HTTPEventType = /* @__PURE__ */ ((HTTPEventType2) => (HTTPEventType2[HTTPEventType2.DownloadProgress = 0] = "DownloadProgress", HTTPEventType2[HTTPEventType2.Response = 1] = "Response", HTTPEventType2))(HTTPEventType || {});
183
- const _HTTPResponse = class _HTTPResponse {
176
+ const ce = 200, ae = 300;
177
+ var I = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(I || {}), X = /* @__PURE__ */ ((e) => (e[e.DownloadProgress = 0] = "DownloadProgress", e[e.Response = 1] = "Response", e))(X || {});
178
+ class U {
184
179
  constructor({
185
- body,
186
- headers,
187
- status,
188
- statusText
180
+ body: r,
181
+ headers: n,
182
+ status: t,
183
+ statusText: s
189
184
  }) {
190
- __publicField(this, "type", 1);
191
- __publicField(this, "body");
192
- __publicField(this, "headers");
193
- __publicField(this, "status");
194
- __publicField(this, "statusText");
195
- this.body = body, this.headers = headers, this.status = status, this.statusText = statusText;
185
+ u(this, "type", 1);
186
+ u(this, "body");
187
+ u(this, "headers");
188
+ u(this, "status");
189
+ u(this, "statusText");
190
+ this.body = r, this.headers = n, this.status = t, this.statusText = s;
196
191
  }
197
- };
198
- __name(_HTTPResponse, "HTTPResponse");
199
- let HTTPResponse = _HTTPResponse;
200
- const _HTTPProgress = class _HTTPProgress {
201
- constructor(total, loaded, partialText) {
202
- __publicField(this, "type", 0);
203
- this.total = total, this.loaded = loaded, this.partialText = partialText;
192
+ }
193
+ class le {
194
+ constructor(r, n, t) {
195
+ u(this, "type", 0);
196
+ this.total = r, this.loaded = n, this.partialText = t;
204
197
  }
205
- };
206
- __name(_HTTPProgress, "HTTPProgress");
207
- let HTTPProgress = _HTTPProgress;
208
- const _ResponseHeader = class _ResponseHeader {
209
- constructor(headers, status, statusText) {
210
- this.headers = headers, this.status = status, this.statusText = statusText;
198
+ }
199
+ class he {
200
+ constructor(r, n, t) {
201
+ this.headers = r, this.status = n, this.statusText = t;
211
202
  }
212
- };
213
- __name(_ResponseHeader, "ResponseHeader");
214
- let ResponseHeader = _ResponseHeader;
215
- const _HTTPResponseError = class _HTTPResponseError {
203
+ }
204
+ class _ {
216
205
  constructor({
217
- headers,
218
- status,
219
- statusText,
220
- error
206
+ headers: r,
207
+ status: n,
208
+ statusText: t,
209
+ error: s
221
210
  }) {
222
- __publicField(this, "headers");
223
- __publicField(this, "status");
224
- __publicField(this, "statusText");
225
- __publicField(this, "error");
226
- this.headers = headers, this.status = status, this.statusText = statusText, this.error = error;
211
+ u(this, "headers");
212
+ u(this, "status");
213
+ u(this, "statusText");
214
+ u(this, "error");
215
+ this.headers = r, this.status = n, this.statusText = t, this.error = s;
227
216
  }
228
- };
229
- __name(_HTTPResponseError, "HTTPResponseError");
230
- let HTTPResponseError = _HTTPResponseError;
231
- const _XHRHTTPImplementation = class _XHRHTTPImplementation {
232
- send(request) {
233
- return new Observable((observer) => {
234
- const xhr = new XMLHttpRequest();
235
- xhr.open(request.method, request.getUrlWithParams()), request.withCredentials && (xhr.withCredentials = !0), request.headers.forEach((key, value) => xhr.setRequestHeader(key, value.join(","))), request.headers.has("Accept") || xhr.setRequestHeader("Accept", "application/json, text/plain, */*"), request.headers.has("Content-Type") || xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
236
- const buildResponseHeader = /* @__PURE__ */ __name(() => {
237
- const statusText = xhr.statusText || "OK", headers = new HTTPHeaders(xhr.getAllResponseHeaders());
238
- return new ResponseHeader(headers, xhr.status, statusText);
239
- }, "buildResponseHeader"), onLoadHandler = /* @__PURE__ */ __name(() => {
240
- const { headers, statusText, status } = buildResponseHeader(), { responseType } = request;
241
- let body2 = null, error = null;
242
- status !== HTTPStatusCode.NoContent && (body2 = typeof xhr.response > "u" ? xhr.responseText : xhr.response);
243
- let success = status >= SuccessStatusCodeLowerBound && status < ErrorStatusCodeLowerBound;
244
- if (responseType === "json" && typeof body2 == "string") {
245
- const originalBody = body2;
217
+ }
218
+ class de {
219
+ send(r) {
220
+ return new w((n) => {
221
+ const t = new XMLHttpRequest();
222
+ t.open(r.method, r.getUrlWithParams()), r.withCredentials && (t.withCredentials = !0), r.headers.forEach((l, a) => t.setRequestHeader(l, a.join(","))), r.headers.has("Accept") || t.setRequestHeader("Accept", "application/json, text/plain, */*"), r.headers.has("Content-Type") || t.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
223
+ const s = () => {
224
+ const l = t.statusText || "OK", a = new v(t.getAllResponseHeaders());
225
+ return new he(a, t.status, l);
226
+ }, i = () => {
227
+ const { headers: l, statusText: a, status: h } = s(), { responseType: m } = r;
228
+ let d = null, f = null;
229
+ h !== I.NoContent && (d = typeof t.response > "u" ? t.responseText : t.response);
230
+ let y = h >= ce && h < ae;
231
+ if (m === "json" && typeof d == "string") {
232
+ const g = d;
246
233
  try {
247
- body2 = body2 ? JSON.parse(body2) : null;
248
- } catch (e) {
249
- success = !1, body2 = originalBody, error = e;
234
+ d = d ? JSON.parse(d) : null;
235
+ } catch (p) {
236
+ y = !1, d = g, f = p;
250
237
  }
251
238
  }
252
- success ? observer.next(
253
- new HTTPResponse({
254
- body: body2,
255
- headers,
256
- status,
257
- statusText
239
+ y ? n.next(
240
+ new U({
241
+ body: d,
242
+ headers: l,
243
+ status: h,
244
+ statusText: a
258
245
  })
259
- ) : observer.error(
260
- new HTTPResponseError({
261
- error,
262
- headers,
263
- status,
264
- statusText
246
+ ) : n.error(
247
+ new _({
248
+ error: f,
249
+ headers: l,
250
+ status: h,
251
+ statusText: a
265
252
  })
266
253
  );
267
- }, "onLoadHandler"), onErrorHandler = /* @__PURE__ */ __name((error) => {
268
- const res = new HTTPResponseError({
269
- error,
270
- status: xhr.status || 0,
271
- statusText: xhr.statusText || "Unknown Error",
272
- headers: buildResponseHeader().headers
254
+ }, o = (l) => {
255
+ const a = new _({
256
+ error: l,
257
+ status: t.status || 0,
258
+ statusText: t.statusText || "Unknown Error",
259
+ headers: s().headers
273
260
  });
274
- observer.error(res);
275
- }, "onErrorHandler");
276
- xhr.addEventListener("load", onLoadHandler), xhr.addEventListener("error", onErrorHandler), xhr.addEventListener("abort", onErrorHandler), xhr.addEventListener("timeout", onErrorHandler);
277
- const body = request.getBody();
278
- return xhr.send(body), () => {
279
- xhr.readyState !== xhr.DONE && xhr.abort(), xhr.removeEventListener("load", onLoadHandler), xhr.removeEventListener("error", onErrorHandler), xhr.removeEventListener("abort", onErrorHandler), xhr.removeEventListener("timeout", onErrorHandler);
261
+ n.error(a);
262
+ };
263
+ t.addEventListener("load", i), t.addEventListener("error", o), t.addEventListener("abort", o), t.addEventListener("timeout", o);
264
+ const c = r.getBody();
265
+ return t.send(c), () => {
266
+ t.readyState !== t.DONE && t.abort(), t.removeEventListener("load", i), t.removeEventListener("error", o), t.removeEventListener("abort", o), t.removeEventListener("timeout", o);
280
267
  };
281
268
  });
282
269
  }
283
- };
284
- __name(_XHRHTTPImplementation, "XHRHTTPImplementation");
285
- let XHRHTTPImplementation = _XHRHTTPImplementation;
286
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
287
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
288
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
289
- return kind && result && __defProp2(target, key, result), result;
290
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a2;
291
- let UniverNetworkPlugin = (_a2 = class extends Plugin {
292
- constructor(_config = void 0, _injector) {
293
- super(), this._config = _config, this._injector = _injector;
270
+ }
271
+ var pe = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, me = (e, r, n, t) => {
272
+ for (var s = t > 1 ? void 0 : t ? ue(r, n) : r, i = e.length - 1, o; i >= 0; i--)
273
+ (o = e[i]) && (s = (t ? o(r, n, s) : o(s)) || s);
274
+ return t && s && pe(r, n, s), s;
275
+ }, ye = (e, r) => (n, t) => r(n, t, e), N;
276
+ let $ = (N = class extends Q {
277
+ constructor(e = void 0, r) {
278
+ super(), this._config = e, this._injector = r;
294
279
  }
295
280
  onStarting() {
296
- var _a3;
297
- registerDependencies(this._injector, mergeOverrideWithDependencies([
298
- [HTTPService],
299
- [IHTTPImplementation, { useClass: XHRHTTPImplementation }]
300
- ], (_a3 = this._config) == null ? void 0 : _a3.override));
301
- }
302
- }, __name(_a2, "UniverNetworkPlugin"), __publicField(_a2, "pluginName", "UNIVER_NETWORK_PLUGIN"), _a2);
303
- UniverNetworkPlugin = __decorateClass([
304
- __decorateParam(1, Inject(Injector))
305
- ], UniverNetworkPlugin);
306
- const _FetchHTTPImplementation = class _FetchHTTPImplementation {
307
- send(request) {
308
- return new Observable((subscriber) => {
309
- const abortController = new AbortController();
310
- return this._send(request, subscriber, abortController).then(() => {
311
- }, (error) => {
312
- subscriber.error(new HTTPResponseError({
313
- error
281
+ var e;
282
+ Z(this._injector, P([
283
+ [F],
284
+ [W, { useClass: de }]
285
+ ], (e = this._config) == null ? void 0 : e.override));
286
+ }
287
+ }, u(N, "pluginName", "UNIVER_NETWORK_PLUGIN"), N);
288
+ $ = me([
289
+ ye(1, K(Y))
290
+ ], $);
291
+ class Ae {
292
+ send(r) {
293
+ return new w((n) => {
294
+ const t = new AbortController();
295
+ return this._send(r, n, t).then(() => {
296
+ }, (s) => {
297
+ n.error(new _({
298
+ error: s
314
299
  }));
315
- }), () => abortController.abort();
300
+ }), () => t.abort();
316
301
  });
317
302
  }
318
- async _send(request, subscriber, abortController) {
319
- var _a3, _b;
320
- let response;
303
+ async _send(r, n, t) {
304
+ var h, m;
305
+ let s;
321
306
  try {
322
- const fetchParams = this._parseFetchParamsFromRequest(request);
323
- response = await fetch(request.getUrlWithParams(), {
324
- signal: abortController.signal,
325
- ...fetchParams
307
+ const d = this._parseFetchParamsFromRequest(r);
308
+ s = await fetch(r.getUrlWithParams(), {
309
+ signal: t.signal,
310
+ ...d
326
311
  });
327
- } catch (error) {
328
- subscriber.error(new HTTPResponseError({
329
- error,
330
- status: (_a3 = error.status) != null ? _a3 : 0,
331
- statusText: (_b = error.statusText) != null ? _b : "Unknown Error",
332
- headers: error.headers
312
+ } catch (d) {
313
+ n.error(new _({
314
+ error: d,
315
+ status: (h = d.status) != null ? h : 0,
316
+ statusText: (m = d.statusText) != null ? m : "Unknown Error",
317
+ headers: d.headers
333
318
  }));
334
319
  return;
335
320
  }
336
- const responseHeaders = new HTTPHeaders(response.headers), status = response.status, statusText = response.statusText;
337
- let body = null;
338
- response.body && (body = await this._readBody(request, response, subscriber)), status >= HTTPStatusCode.Ok && status < HTTPStatusCode.MultipleChoices ? subscriber.next(new HTTPResponse({
339
- body,
340
- headers: responseHeaders,
341
- status,
342
- statusText
343
- })) : subscriber.error(new HTTPResponseError({
344
- error: body,
345
- status,
346
- statusText,
347
- headers: responseHeaders
348
- })), subscriber.complete();
349
- }
350
- async _readBody(request, response, subscriber) {
351
- var _a3, _b;
352
- const chunks = [], reader = response.body.getReader(), contentLength = response.headers.get("content-length");
353
- let receivedLength = 0;
354
- const reportProgress = (_a3 = request.requestParams) == null ? void 0 : _a3.reportProgress, responseType = request.responseType;
355
- let partialText, decoder;
321
+ const i = new v(s.headers), o = s.status, c = s.statusText;
322
+ let l = null;
323
+ s.body && (l = await this._readBody(r, s, n)), o >= I.Ok && o < I.MultipleChoices ? n.next(new U({
324
+ body: l,
325
+ headers: i,
326
+ status: o,
327
+ statusText: c
328
+ })) : n.error(new _({
329
+ error: l,
330
+ status: o,
331
+ statusText: c,
332
+ headers: i
333
+ })), n.complete();
334
+ }
335
+ async _readBody(r, n, t) {
336
+ var f, y;
337
+ const s = [], i = n.body.getReader(), o = n.headers.get("content-length");
338
+ let c = 0;
339
+ const l = (f = r.requestParams) == null ? void 0 : f.reportProgress, a = r.responseType;
340
+ let h, m;
356
341
  for (; ; ) {
357
- const { done, value } = await reader.read();
358
- if (done) break;
359
- chunks.push(value), receivedLength += value.length, reportProgress && responseType === "text" && (partialText = (partialText != null ? partialText : "") + (decoder != null ? decoder : decoder = new TextDecoder()).decode(value, { stream: !0 }), subscriber.next(new HTTPProgress(
360
- contentLength ? Number.parseInt(contentLength, 10) : void 0,
361
- receivedLength,
362
- partialText
342
+ const { done: g, value: p } = await i.read();
343
+ if (g) break;
344
+ s.push(p), c += p.length, l && a === "text" && (h = (h != null ? h : "") + (m != null ? m : m = new TextDecoder()).decode(p, { stream: !0 }), t.next(new le(
345
+ o ? Number.parseInt(o, 10) : void 0,
346
+ c,
347
+ h
363
348
  )));
364
349
  }
365
- const all = mergeChunks(chunks, receivedLength);
350
+ const d = fe(s, c);
366
351
  try {
367
- const contentType = (_b = response.headers.get("content-type")) != null ? _b : "";
368
- return deserialize(request, all, contentType);
369
- } catch (error) {
370
- return subscriber.error(new HTTPResponseError({
371
- error,
372
- status: response.status,
373
- statusText: response.statusText,
374
- headers: new HTTPHeaders(response.headers)
352
+ const g = (y = n.headers.get("content-type")) != null ? y : "";
353
+ return we(r, d, g);
354
+ } catch (g) {
355
+ return t.error(new _({
356
+ error: g,
357
+ status: n.status,
358
+ statusText: n.statusText,
359
+ headers: new v(n.headers)
375
360
  })), null;
376
361
  }
377
362
  }
378
- _parseFetchParamsFromRequest(request) {
363
+ _parseFetchParamsFromRequest(r) {
379
364
  return {
380
- method: request.method,
381
- headers: request.getHeadersInit(),
382
- body: request.getBody(),
383
- credentials: request.withCredentials ? "include" : void 0
365
+ method: r.method,
366
+ headers: r.getHeadersInit(),
367
+ body: r.getBody(),
368
+ credentials: r.withCredentials ? "include" : void 0
384
369
  };
385
370
  }
386
- };
387
- __name(_FetchHTTPImplementation, "FetchHTTPImplementation");
388
- let FetchHTTPImplementation = _FetchHTTPImplementation;
389
- function mergeChunks(chunks, totalLength) {
390
- const all = new Uint8Array(totalLength);
391
- let position = 0;
392
- for (const chunk of chunks)
393
- all.set(chunk, position), position += chunk.length;
394
- return all;
395
371
  }
396
- __name(mergeChunks, "mergeChunks");
397
- const XSSI_PREFIX = /^\)\]\}',?\n/;
398
- function deserialize(request, bin, contentType) {
399
- switch (request.responseType) {
372
+ function fe(e, r) {
373
+ const n = new Uint8Array(r);
374
+ let t = 0;
375
+ for (const s of e)
376
+ n.set(s, t), t += s.length;
377
+ return n;
378
+ }
379
+ const ge = /^\)\]\}',?\n/;
380
+ function we(e, r, n) {
381
+ switch (e.responseType) {
400
382
  case "json":
401
- const text = new TextDecoder().decode(bin).replace(XSSI_PREFIX, "");
402
- return text === "" ? null : JSON.parse(text);
383
+ const t = new TextDecoder().decode(r).replace(ge, "");
384
+ return t === "" ? null : JSON.parse(t);
403
385
  case "text":
404
- return new TextDecoder().decode(bin);
386
+ return new TextDecoder().decode(r);
405
387
  case "blob":
406
- return new Blob([bin], { type: contentType });
388
+ return new Blob([r], { type: n });
407
389
  case "arraybuffer":
408
- return bin.buffer;
390
+ return r.buffer;
409
391
  default:
410
- throw new Error(`[FetchHTTPImplementation]: unknown response type: ${request.responseType}.`);
392
+ throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
411
393
  }
412
394
  }
413
- __name(deserialize, "deserialize");
414
- const ISocketService = createIdentifier("univer.socket"), _WebSocketService = class _WebSocketService extends Disposable {
415
- createSocket(URL) {
395
+ const Ne = B("univer.socket");
396
+ class Fe extends G {
397
+ createSocket(r) {
416
398
  try {
417
- const connection = new WebSocket(URL), disposables = new DisposableCollection();
399
+ const n = new WebSocket(r), t = new S();
418
400
  return {
419
- URL,
420
- close: /* @__PURE__ */ __name((code, reason) => {
421
- connection.close(code, reason), disposables.dispose();
422
- }, "close"),
423
- send: /* @__PURE__ */ __name((data) => {
424
- connection.send(data);
425
- }, "send"),
426
- open$: new Observable((subscriber) => {
427
- const callback = /* @__PURE__ */ __name((event) => subscriber.next(event), "callback");
428
- connection.addEventListener("open", callback), disposables.add(toDisposable(() => connection.removeEventListener("open", callback)));
429
- }).pipe(share()),
430
- close$: new Observable((subscriber) => {
431
- const callback = /* @__PURE__ */ __name((event) => subscriber.next(event), "callback");
432
- connection.addEventListener("close", callback), disposables.add(toDisposable(() => connection.removeEventListener("close", callback)));
433
- }).pipe(share()),
434
- error$: new Observable((subscriber) => {
435
- const callback = /* @__PURE__ */ __name((event) => subscriber.next(event), "callback");
436
- connection.addEventListener("error", callback), disposables.add(toDisposable(() => connection.removeEventListener("error", callback)));
437
- }).pipe(share()),
438
- message$: new Observable((subscriber) => {
439
- const callback = /* @__PURE__ */ __name((event) => subscriber.next(event), "callback");
440
- connection.addEventListener("message", callback), disposables.add(toDisposable(() => connection.removeEventListener("message", callback)));
441
- }).pipe(share())
401
+ URL: r,
402
+ close: (i, o) => {
403
+ n.close(i, o), t.dispose();
404
+ },
405
+ send: (i) => {
406
+ n.send(i);
407
+ },
408
+ open$: new w((i) => {
409
+ const o = (c) => i.next(c);
410
+ n.addEventListener("open", o), t.add(R(() => n.removeEventListener("open", o)));
411
+ }).pipe(b()),
412
+ close$: new w((i) => {
413
+ const o = (c) => i.next(c);
414
+ n.addEventListener("close", o), t.add(R(() => n.removeEventListener("close", o)));
415
+ }).pipe(b()),
416
+ error$: new w((i) => {
417
+ const o = (c) => i.next(c);
418
+ n.addEventListener("error", o), t.add(R(() => n.removeEventListener("error", o)));
419
+ }).pipe(b()),
420
+ message$: new w((i) => {
421
+ const o = (c) => i.next(c);
422
+ n.addEventListener("message", o), t.add(R(() => n.removeEventListener("message", o)));
423
+ }).pipe(b())
442
424
  };
443
- } catch (e) {
444
- return console.error(e), null;
425
+ } catch (n) {
426
+ return console.error(n), null;
445
427
  }
446
428
  }
447
- };
448
- __name(_WebSocketService, "WebSocketService");
449
- let WebSocketService = _WebSocketService;
450
- const DEFAULT_MAX_RETRY_ATTEMPTS = 3, DELAY_INTERVAL = 1e3, RetryInterceptorFactory = /* @__PURE__ */ __name((params) => {
451
- var _a3, _b;
452
- const maxRetryAttempts = (_a3 = params == null ? void 0 : params.maxRetryAttempts) != null ? _a3 : DEFAULT_MAX_RETRY_ATTEMPTS, delayInterval = (_b = params == null ? void 0 : params.delayInterval) != null ? _b : DELAY_INTERVAL;
453
- return (request, next) => next(request).pipe(retry({ delay: delayInterval, count: maxRetryAttempts }));
454
- }, "RetryInterceptorFactory"), ThresholdInterceptorFactory = /* @__PURE__ */ __name((params) => {
455
- const handlers = [], ongoingHandlers = /* @__PURE__ */ new Set(), tick = /* @__PURE__ */ __name(() => {
456
- var _a3;
457
- for (; ongoingHandlers.size < ((_a3 = params == null ? void 0 : params.maxParallel) != null ? _a3 : 1) && handlers.length > 0; ) {
458
- const handler = handlers.shift();
459
- ongoingHandlers.add(handler), handler();
429
+ }
430
+ const _e = 3, Ee = 1e3, Ue = (e) => {
431
+ var t, s;
432
+ const r = (t = e == null ? void 0 : e.maxRetryAttempts) != null ? t : _e, n = (s = e == null ? void 0 : e.delayInterval) != null ? s : Ee;
433
+ return (i, o) => o(i).pipe(ee({ delay: n, count: r }));
434
+ }, qe = (e) => {
435
+ const r = [], n = /* @__PURE__ */ new Set(), t = () => {
436
+ var s;
437
+ for (; n.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && r.length > 0; ) {
438
+ const i = r.shift();
439
+ n.add(i), i();
460
440
  }
461
- }, "tick");
462
- return (request, next) => new Observable((observer) => {
463
- const handler = /* @__PURE__ */ __name(() => next(request).subscribe({
464
- next: /* @__PURE__ */ __name((event) => observer.next(event), "next"),
465
- error: /* @__PURE__ */ __name((err) => observer.error(err), "error"),
466
- complete: /* @__PURE__ */ __name(() => observer.complete(), "complete")
467
- }), "handler"), teardown = /* @__PURE__ */ __name(() => {
468
- ongoingHandlers.delete(handler), remove(handlers, handler), tick();
469
- }, "teardown");
470
- return handlers.push(handler), tick(), teardown;
441
+ };
442
+ return (s, i) => new w((o) => {
443
+ const c = () => i(s).subscribe({
444
+ next: (a) => o.next(a),
445
+ error: (a) => o.error(a),
446
+ complete: () => o.complete()
447
+ }), l = () => {
448
+ n.delete(c), V(r, c), t();
449
+ };
450
+ return r.push(c), t(), l;
471
451
  });
472
- }, "ThresholdInterceptorFactory"), AuthInterceptorFactory = /* @__PURE__ */ __name((params) => {
473
- const { errorStatusCodes, onAuthError } = params;
474
- return /* @__PURE__ */ __name((request, next) => next(request).pipe(
475
- catchError((error) => (error instanceof HTTPResponseError && errorStatusCodes.some((c) => c === error.status) && onAuthError(), throwError(() => error)))
476
- ), "authInterceptor");
477
- }, "AuthInterceptorFactory"), createDefaultFetchCheck = /* @__PURE__ */ __name((time = 300) => {
478
- let cancel = /* @__PURE__ */ __name(() => {
479
- }, "noop");
480
- return (_currentConfig) => new Promise((res) => {
481
- cancel();
482
- const t = setTimeout(() => {
483
- res(!0);
484
- }, time);
485
- cancel = /* @__PURE__ */ __name(() => {
486
- clearTimeout(t), res(!1);
487
- }, "cancel");
452
+ }, De = (e) => {
453
+ const { errorStatusCodes: r, onAuthError: n } = e;
454
+ return (s, i) => i(s).pipe(
455
+ C((o) => (o instanceof _ && r.some((c) => c === o.status) && n(), T(() => o)))
456
+ );
457
+ }, Re = (e = 300) => {
458
+ let n = () => {
459
+ };
460
+ return (t) => new Promise((s) => {
461
+ n();
462
+ const i = setTimeout(() => {
463
+ s(!0);
464
+ }, e);
465
+ n = () => {
466
+ clearTimeout(i), s(!1);
467
+ };
488
468
  });
489
- }, "createDefaultFetchCheck"), createDistributeResult = /* @__PURE__ */ __name(() => (result, list) => list.map((config) => ({ config, result })), "createDistributeResult"), MergeInterceptorFactory = /* @__PURE__ */ __name((config, options = {}) => {
490
- const { isMatch, getParamsFromRequest, mergeParamsToRequest } = config, { fetchCheck = createDefaultFetchCheck(300), distributeResult = createDistributeResult() } = options, hookList = [], getPlainList = /* @__PURE__ */ __name((_list) => _list.map((item) => item.config), "getPlainList");
491
- return (requestConfig, next) => isMatch(requestConfig) ? new Observable((observer) => {
492
- const params = getParamsFromRequest(requestConfig);
493
- hookList.push({
494
- next: /* @__PURE__ */ __name((v) => observer.next(v), "next"),
495
- error: /* @__PURE__ */ __name((error) => observer.error(error), "error"),
496
- config: params
469
+ }, ve = () => (e, r) => r.map((n) => ({ config: n, result: e })), Oe = (e, r = {}) => {
470
+ const { isMatch: n, getParamsFromRequest: t, mergeParamsToRequest: s } = e, { fetchCheck: i = Re(300), distributeResult: o = ve() } = r, c = [], l = (a) => a.map((h) => h.config);
471
+ return (a, h) => n(a) ? new w((m) => {
472
+ const d = t(a);
473
+ c.push({
474
+ next: (y) => m.next(y),
475
+ error: (y) => m.error(y),
476
+ config: d
497
477
  });
498
- const list = getPlainList(hookList);
499
- fetchCheck(requestConfig).then((isFetch) => {
500
- if (isFetch) {
501
- const currentHookList = [];
502
- list.forEach((config2) => {
503
- const index = hookList.findIndex((item) => item.config === config2);
504
- if (index >= 0) {
505
- const [hook] = hookList.splice(index, 1);
506
- currentHookList.push(hook);
478
+ const f = l(c);
479
+ i(a).then((y) => {
480
+ if (y) {
481
+ const g = [];
482
+ f.forEach((p) => {
483
+ const x = c.findIndex((E) => E.config === p);
484
+ if (x >= 0) {
485
+ const [E] = c.splice(x, 1);
486
+ g.push(E);
507
487
  }
508
- }), next(mergeParamsToRequest(list, requestConfig)).subscribe({
509
- next: /* @__PURE__ */ __name((e) => {
510
- if (e.type === HTTPEventType.Response) {
511
- const body = e.body, configList = distributeResult(body, list);
512
- currentHookList.forEach((hookItem) => {
513
- const res = configList.find((item) => item.config === hookItem.config);
514
- if (res) {
515
- const response = new HTTPResponse({
516
- body: res.result,
517
- headers: e.headers,
518
- status: e.status,
519
- statusText: e.statusText
488
+ }), h(s(f, a)).subscribe({
489
+ next: (p) => {
490
+ if (p.type === X.Response) {
491
+ const x = p.body, E = o(x, f);
492
+ g.forEach((L) => {
493
+ const q = E.find((A) => A.config === L.config);
494
+ if (q) {
495
+ const A = new U({
496
+ body: q.result,
497
+ headers: p.headers,
498
+ status: p.status,
499
+ statusText: p.statusText
520
500
  });
521
- hookItem.next(response);
501
+ L.next(A);
522
502
  } else
523
- hookItem.error("batch error");
503
+ L.error("batch error");
524
504
  });
525
505
  }
526
- }, "next"),
527
- complete: /* @__PURE__ */ __name(() => observer.complete(), "complete"),
528
- error: /* @__PURE__ */ __name((e) => observer.error(e), "error")
506
+ },
507
+ complete: () => m.complete(),
508
+ error: (p) => m.error(p)
529
509
  });
530
510
  }
531
511
  });
532
- }) : next(requestConfig);
533
- }, "MergeInterceptorFactory");
512
+ }) : h(a);
513
+ };
534
514
  export {
535
- AuthInterceptorFactory,
536
- FetchHTTPImplementation,
537
- HTTPEventType,
538
- HTTPHeaders,
539
- HTTPProgress,
540
- HTTPRequest,
541
- HTTPResponse,
542
- HTTPResponseError,
543
- HTTPService,
544
- HTTPStatusCode,
545
- IHTTPImplementation,
546
- ISocketService,
547
- MergeInterceptorFactory,
548
- ResponseHeader,
549
- RetryInterceptorFactory,
550
- ThresholdInterceptorFactory,
551
- UniverNetworkPlugin,
552
- WebSocketService,
553
- XHRHTTPImplementation
515
+ De as AuthInterceptorFactory,
516
+ Ae as FetchHTTPImplementation,
517
+ X as HTTPEventType,
518
+ v as HTTPHeaders,
519
+ le as HTTPProgress,
520
+ j as HTTPRequest,
521
+ U as HTTPResponse,
522
+ _ as HTTPResponseError,
523
+ F as HTTPService,
524
+ I as HTTPStatusCode,
525
+ W as IHTTPImplementation,
526
+ Ne as ISocketService,
527
+ Oe as MergeInterceptorFactory,
528
+ he as ResponseHeader,
529
+ Ue as RetryInterceptorFactory,
530
+ qe as ThresholdInterceptorFactory,
531
+ $ as UniverNetworkPlugin,
532
+ Fe as WebSocketService,
533
+ de as XHRHTTPImplementation
554
534
  };