@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/cjs/index.js +2 -2
- package/lib/es/index.js +414 -434
- package/lib/umd/index.js +2 -2
- package/package.json +11 -10
package/lib/es/index.js
CHANGED
|
@@ -1,69 +1,67 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
typeof
|
|
12
|
-
}
|
|
13
|
-
forEach(
|
|
14
|
-
this._headers.forEach((
|
|
15
|
-
}
|
|
16
|
-
has(
|
|
17
|
-
return !!this._headers.has(
|
|
18
|
-
}
|
|
19
|
-
get(
|
|
20
|
-
const
|
|
21
|
-
return this._headers.has(
|
|
22
|
-
}
|
|
23
|
-
set(
|
|
24
|
-
this._setHeader(
|
|
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
|
|
28
|
-
const
|
|
29
|
-
return this._headers.forEach((
|
|
30
|
-
|
|
31
|
-
}), (
|
|
32
|
-
}
|
|
33
|
-
_setHeader(
|
|
34
|
-
const
|
|
35
|
-
this._headers.has(
|
|
36
|
-
}
|
|
37
|
-
_handleHeadersString(
|
|
38
|
-
|
|
39
|
-
`).forEach((
|
|
40
|
-
const [
|
|
41
|
-
|
|
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(
|
|
45
|
-
Object.entries(
|
|
44
|
+
_handleHeadersConstructorProps(r) {
|
|
45
|
+
Object.entries(r).forEach(([n, t]) => this._setHeader(n, t));
|
|
46
46
|
}
|
|
47
|
-
_handleHeaders(
|
|
48
|
-
|
|
47
|
+
_handleHeaders(r) {
|
|
48
|
+
r.forEach((n, t) => this._setHeader(t, n));
|
|
49
49
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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((
|
|
57
|
+
return this.params ? Object.keys(this.params).map((r) => `${r}=${this.params[r]}`).join("&") : "";
|
|
59
58
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
79
|
-
const
|
|
80
|
-
return
|
|
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
|
|
84
|
-
const
|
|
85
|
-
return
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
97
|
+
u(this, "_interceptors", []);
|
|
102
98
|
// eslint-disable-next-line ts/no-explicit-any
|
|
103
|
-
|
|
104
|
-
this._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(
|
|
113
|
-
if (this._interceptors.indexOf(
|
|
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(
|
|
116
|
-
var
|
|
117
|
-
return ((
|
|
118
|
-
}), this._pipe = null,
|
|
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(
|
|
121
|
-
return this._request("GET",
|
|
116
|
+
get(r, n) {
|
|
117
|
+
return this._request("GET", r, n);
|
|
122
118
|
}
|
|
123
|
-
post(
|
|
124
|
-
return this._request("POST",
|
|
119
|
+
post(r, n) {
|
|
120
|
+
return this._request("POST", r, n);
|
|
125
121
|
}
|
|
126
|
-
put(
|
|
127
|
-
return this._request("PUT",
|
|
122
|
+
put(r, n) {
|
|
123
|
+
return this._request("PUT", r, n);
|
|
128
124
|
}
|
|
129
|
-
delete(
|
|
130
|
-
return this._request("DELETE",
|
|
125
|
+
delete(r, n) {
|
|
126
|
+
return this._request("DELETE", r, n);
|
|
131
127
|
}
|
|
132
|
-
patch(
|
|
133
|
-
return this._request("PATCH",
|
|
128
|
+
patch(r, n) {
|
|
129
|
+
return this._request("PATCH", r, n);
|
|
134
130
|
}
|
|
135
|
-
getSSE(
|
|
136
|
-
var
|
|
137
|
-
const
|
|
138
|
-
headers,
|
|
139
|
-
params,
|
|
140
|
-
withCredentials: (
|
|
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: (
|
|
143
|
-
body: ["GET", "DELETE"].includes(
|
|
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
|
|
141
|
+
return D(o).pipe(O((a) => this._runInterceptorsAndImplementation(a)));
|
|
146
142
|
}
|
|
147
143
|
/** The HTTP request implementations */
|
|
148
|
-
async _request(
|
|
149
|
-
var
|
|
150
|
-
const
|
|
151
|
-
headers,
|
|
152
|
-
params,
|
|
153
|
-
withCredentials: (
|
|
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: (
|
|
156
|
-
body: ["GET", "DELETE"].includes(
|
|
157
|
-
}),
|
|
158
|
-
|
|
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
|
|
156
|
+
return await H(c);
|
|
161
157
|
}
|
|
162
158
|
// eslint-disable-next-line ts/no-explicit-any
|
|
163
|
-
_runInterceptorsAndImplementation(
|
|
164
|
-
return this._pipe || (this._pipe = this._interceptors.map((
|
|
165
|
-
(
|
|
166
|
-
(
|
|
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
|
-
|
|
169
|
-
(
|
|
164
|
+
r,
|
|
165
|
+
(n) => this._http.send(n)
|
|
170
166
|
/* final handler */
|
|
171
167
|
);
|
|
172
168
|
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
],
|
|
177
|
-
function
|
|
178
|
-
return (
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.body =
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.headers =
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
let
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
248
|
-
} catch (
|
|
249
|
-
|
|
234
|
+
d = d ? JSON.parse(d) : null;
|
|
235
|
+
} catch (p) {
|
|
236
|
+
y = !1, d = g, f = p;
|
|
250
237
|
}
|
|
251
238
|
}
|
|
252
|
-
|
|
253
|
-
new
|
|
254
|
-
body:
|
|
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
|
-
) :
|
|
260
|
-
new
|
|
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
|
-
},
|
|
268
|
-
const
|
|
269
|
-
error,
|
|
270
|
-
status:
|
|
271
|
-
statusText:
|
|
272
|
-
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
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
return
|
|
279
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
|
297
|
-
|
|
298
|
-
[
|
|
299
|
-
[
|
|
300
|
-
], (
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
],
|
|
306
|
-
|
|
307
|
-
send(
|
|
308
|
-
return new
|
|
309
|
-
const
|
|
310
|
-
return this._send(
|
|
311
|
-
}, (
|
|
312
|
-
|
|
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
|
-
}), () =>
|
|
300
|
+
}), () => t.abort();
|
|
316
301
|
});
|
|
317
302
|
}
|
|
318
|
-
async _send(
|
|
319
|
-
var
|
|
320
|
-
let
|
|
303
|
+
async _send(r, n, t) {
|
|
304
|
+
var h, m;
|
|
305
|
+
let s;
|
|
321
306
|
try {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
signal:
|
|
325
|
-
...
|
|
307
|
+
const d = this._parseFetchParamsFromRequest(r);
|
|
308
|
+
s = await fetch(r.getUrlWithParams(), {
|
|
309
|
+
signal: t.signal,
|
|
310
|
+
...d
|
|
326
311
|
});
|
|
327
|
-
} catch (
|
|
328
|
-
|
|
329
|
-
error,
|
|
330
|
-
status: (
|
|
331
|
-
statusText: (
|
|
332
|
-
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
|
|
337
|
-
let
|
|
338
|
-
|
|
339
|
-
body,
|
|
340
|
-
headers:
|
|
341
|
-
status,
|
|
342
|
-
statusText
|
|
343
|
-
})) :
|
|
344
|
-
error:
|
|
345
|
-
status,
|
|
346
|
-
statusText,
|
|
347
|
-
headers:
|
|
348
|
-
})),
|
|
349
|
-
}
|
|
350
|
-
async _readBody(
|
|
351
|
-
var
|
|
352
|
-
const
|
|
353
|
-
let
|
|
354
|
-
const
|
|
355
|
-
let
|
|
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
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
|
350
|
+
const d = fe(s, c);
|
|
366
351
|
try {
|
|
367
|
-
const
|
|
368
|
-
return
|
|
369
|
-
} catch (
|
|
370
|
-
return
|
|
371
|
-
error,
|
|
372
|
-
status:
|
|
373
|
-
statusText:
|
|
374
|
-
headers: new
|
|
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(
|
|
363
|
+
_parseFetchParamsFromRequest(r) {
|
|
379
364
|
return {
|
|
380
|
-
method:
|
|
381
|
-
headers:
|
|
382
|
-
body:
|
|
383
|
-
credentials:
|
|
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
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
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
|
|
402
|
-
return
|
|
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(
|
|
386
|
+
return new TextDecoder().decode(r);
|
|
405
387
|
case "blob":
|
|
406
|
-
return new Blob([
|
|
388
|
+
return new Blob([r], { type: n });
|
|
407
389
|
case "arraybuffer":
|
|
408
|
-
return
|
|
390
|
+
return r.buffer;
|
|
409
391
|
default:
|
|
410
|
-
throw new Error(`[FetchHTTPImplementation]: unknown response type: ${
|
|
392
|
+
throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
|
|
411
393
|
}
|
|
412
394
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
createSocket(
|
|
395
|
+
const Ne = B("univer.socket");
|
|
396
|
+
class Fe extends G {
|
|
397
|
+
createSocket(r) {
|
|
416
398
|
try {
|
|
417
|
-
const
|
|
399
|
+
const n = new WebSocket(r), t = new S();
|
|
418
400
|
return {
|
|
419
|
-
URL,
|
|
420
|
-
close:
|
|
421
|
-
|
|
422
|
-
},
|
|
423
|
-
send:
|
|
424
|
-
|
|
425
|
-
},
|
|
426
|
-
open$: new
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
}).pipe(
|
|
430
|
-
close$: new
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
}).pipe(
|
|
434
|
-
error$: new
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
}).pipe(
|
|
438
|
-
message$: new
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
}).pipe(
|
|
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 (
|
|
444
|
-
return console.error(
|
|
425
|
+
} catch (n) {
|
|
426
|
+
return console.error(n), null;
|
|
445
427
|
}
|
|
446
428
|
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
-
}
|
|
462
|
-
return (
|
|
463
|
-
const
|
|
464
|
-
next:
|
|
465
|
-
error:
|
|
466
|
-
complete:
|
|
467
|
-
}),
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
return
|
|
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
|
-
},
|
|
473
|
-
const { errorStatusCodes, onAuthError } =
|
|
474
|
-
return
|
|
475
|
-
|
|
476
|
-
)
|
|
477
|
-
},
|
|
478
|
-
let
|
|
479
|
-
}
|
|
480
|
-
return (
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
},
|
|
485
|
-
|
|
486
|
-
clearTimeout(
|
|
487
|
-
}
|
|
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
|
-
},
|
|
490
|
-
const { isMatch, getParamsFromRequest, mergeParamsToRequest } =
|
|
491
|
-
return (
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
next:
|
|
495
|
-
error:
|
|
496
|
-
config:
|
|
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
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
const
|
|
504
|
-
if (
|
|
505
|
-
const [
|
|
506
|
-
|
|
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
|
-
}),
|
|
509
|
-
next:
|
|
510
|
-
if (
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
if (
|
|
515
|
-
const
|
|
516
|
-
body:
|
|
517
|
-
headers:
|
|
518
|
-
status:
|
|
519
|
-
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
|
-
|
|
501
|
+
L.next(A);
|
|
522
502
|
} else
|
|
523
|
-
|
|
503
|
+
L.error("batch error");
|
|
524
504
|
});
|
|
525
505
|
}
|
|
526
|
-
},
|
|
527
|
-
complete:
|
|
528
|
-
error:
|
|
506
|
+
},
|
|
507
|
+
complete: () => m.complete(),
|
|
508
|
+
error: (p) => m.error(p)
|
|
529
509
|
});
|
|
530
510
|
}
|
|
531
511
|
});
|
|
532
|
-
}) :
|
|
533
|
-
}
|
|
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
|
};
|