@univerjs/network 0.1.0-beta.2 → 0.1.0-beta.3
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.txt → LICENSE} +0 -2
- package/lib/cjs/index.js +2 -422
- package/lib/es/index.js +193 -354
- package/lib/umd/index.js +2 -422
- package/package.json +25 -22
package/lib/es/index.js
CHANGED
|
@@ -1,68 +1,49 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this._setHeader(name, value);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
if (headers) {
|
|
24
|
-
Object.keys(headers).forEach(([name, value]) => {
|
|
25
|
-
this._setHeader(name, value);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var I = (e, t, n) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var a = (e, t, n) => (I(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
+
import { Disposable as b, toDisposable as d, remove as F, DisposableCollection as M } from "@univerjs/core";
|
|
5
|
+
import { of as O, firstValueFrom as k, Observable as y } from "rxjs";
|
|
6
|
+
import { concatMap as j, share as f } from "rxjs/operators";
|
|
7
|
+
import { createIdentifier as _ } from "@wendellhu/redi";
|
|
8
|
+
const g = "application/json";
|
|
9
|
+
class L {
|
|
10
|
+
constructor(t) {
|
|
11
|
+
a(this, "_headers", /* @__PURE__ */ new Map());
|
|
12
|
+
typeof t == "string" ? t.split(`
|
|
13
|
+
`).forEach((n) => {
|
|
14
|
+
const [r, s] = n.split(":");
|
|
15
|
+
r && s && this._setHeader(r, s);
|
|
16
|
+
}) : t && Object.keys(t).forEach(([n, r]) => {
|
|
17
|
+
this._setHeader(n, r);
|
|
18
|
+
});
|
|
29
19
|
}
|
|
30
|
-
forEach(
|
|
31
|
-
this._headers.forEach((
|
|
20
|
+
forEach(t) {
|
|
21
|
+
this._headers.forEach((n, r) => t(r, n));
|
|
32
22
|
}
|
|
33
|
-
has(
|
|
34
|
-
return !!this._headers.has(
|
|
23
|
+
has(t) {
|
|
24
|
+
return !!this._headers.has(t.toLowerCase());
|
|
35
25
|
}
|
|
36
|
-
get(
|
|
37
|
-
const
|
|
38
|
-
return this._headers.has(
|
|
26
|
+
get(t) {
|
|
27
|
+
const n = t.toLowerCase();
|
|
28
|
+
return this._headers.has(n) ? this._headers.get(n) : null;
|
|
39
29
|
}
|
|
40
|
-
_setHeader(
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
this._headers.get(lowerCase).push(value.toString());
|
|
44
|
-
} else {
|
|
45
|
-
this._headers.set(lowerCase, [value.toString()]);
|
|
46
|
-
}
|
|
30
|
+
_setHeader(t, n) {
|
|
31
|
+
const r = t.toLowerCase();
|
|
32
|
+
this._headers.has(r) ? this._headers.get(r).push(n.toString()) : this._headers.set(r, [n.toString()]);
|
|
47
33
|
}
|
|
48
34
|
}
|
|
49
|
-
const
|
|
50
|
-
class
|
|
51
|
-
constructor(
|
|
52
|
-
this.params =
|
|
35
|
+
const $ = _("univer-pro.network.http-implementation");
|
|
36
|
+
class D {
|
|
37
|
+
constructor(t) {
|
|
38
|
+
this.params = t;
|
|
53
39
|
}
|
|
54
40
|
toString() {
|
|
55
|
-
|
|
56
|
-
return "";
|
|
57
|
-
}
|
|
58
|
-
return Object.keys(this.params).map((key) => `${key}=${this.params[key]}`).join("&");
|
|
41
|
+
return this.params ? Object.keys(this.params).map((t) => `${t}=${this.params[t]}`).join("&") : "";
|
|
59
42
|
}
|
|
60
43
|
}
|
|
61
|
-
class
|
|
62
|
-
constructor(
|
|
63
|
-
this.method =
|
|
64
|
-
this.url = url;
|
|
65
|
-
this.requestParams = requestParams;
|
|
44
|
+
class B {
|
|
45
|
+
constructor(t, n, r) {
|
|
46
|
+
this.method = t, this.url = n, this.requestParams = r;
|
|
66
47
|
}
|
|
67
48
|
get headers() {
|
|
68
49
|
return this.requestParams.headers;
|
|
@@ -74,350 +55,208 @@ class HTTPRequest {
|
|
|
74
55
|
return this.requestParams.responseType;
|
|
75
56
|
}
|
|
76
57
|
getUrlWithParams() {
|
|
77
|
-
var
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
return this.url;
|
|
81
|
-
}
|
|
82
|
-
return `${this.url}${this.url.includes("?") ? "&" : "?"}${params}`;
|
|
58
|
+
var n, r;
|
|
59
|
+
const t = (r = (n = this.requestParams) == null ? void 0 : n.params) == null ? void 0 : r.toString();
|
|
60
|
+
return t ? `${this.url}${this.url.includes("?") ? "&" : "?"}${t}` : this.url;
|
|
83
61
|
}
|
|
84
62
|
getBody() {
|
|
85
|
-
var
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
if (contentType === ApplicationJSONType && body && typeof body === "object") {
|
|
89
|
-
return JSON.stringify(body);
|
|
90
|
-
}
|
|
91
|
-
return body ? `${body}` : null;
|
|
63
|
+
var r;
|
|
64
|
+
const t = this.headers.get("Content-Type") ?? g, n = (r = this.requestParams) == null ? void 0 : r.body;
|
|
65
|
+
return t === g && n && typeof n == "object" ? JSON.stringify(n) : n ? `${n}` : null;
|
|
92
66
|
}
|
|
93
67
|
}
|
|
94
|
-
class
|
|
68
|
+
class q {
|
|
95
69
|
constructor({
|
|
96
|
-
body,
|
|
97
|
-
headers,
|
|
98
|
-
status,
|
|
99
|
-
statusText
|
|
70
|
+
body: t,
|
|
71
|
+
headers: n,
|
|
72
|
+
status: r,
|
|
73
|
+
statusText: s
|
|
100
74
|
}) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.body =
|
|
106
|
-
this.headers = headers;
|
|
107
|
-
this.status = status;
|
|
108
|
-
this.statusText = statusText;
|
|
75
|
+
a(this, "body");
|
|
76
|
+
a(this, "headers");
|
|
77
|
+
a(this, "status");
|
|
78
|
+
a(this, "statusText");
|
|
79
|
+
this.body = t, this.headers = n, this.status = r, this.statusText = s;
|
|
109
80
|
}
|
|
110
81
|
}
|
|
111
|
-
class
|
|
82
|
+
class R {
|
|
112
83
|
constructor({
|
|
113
|
-
headers,
|
|
114
|
-
status,
|
|
115
|
-
statusText,
|
|
116
|
-
error
|
|
84
|
+
headers: t,
|
|
85
|
+
status: n,
|
|
86
|
+
statusText: r,
|
|
87
|
+
error: s
|
|
117
88
|
}) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.headers =
|
|
123
|
-
this.status = status;
|
|
124
|
-
this.statusText = statusText;
|
|
125
|
-
this.error = error;
|
|
89
|
+
a(this, "headers");
|
|
90
|
+
a(this, "status");
|
|
91
|
+
a(this, "statusText");
|
|
92
|
+
a(this, "error");
|
|
93
|
+
this.headers = t, this.status = n, this.statusText = r, this.error = s;
|
|
126
94
|
}
|
|
127
95
|
}
|
|
128
|
-
class
|
|
129
|
-
constructor(
|
|
130
|
-
this.headers =
|
|
131
|
-
this.status = status;
|
|
132
|
-
this.statusText = statusText;
|
|
96
|
+
class G {
|
|
97
|
+
constructor(t, n, r) {
|
|
98
|
+
this.headers = t, this.status = n, this.statusText = r;
|
|
133
99
|
}
|
|
134
100
|
}
|
|
135
|
-
var
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (kind && result)
|
|
143
|
-
__defProp2(target, key, result);
|
|
144
|
-
return result;
|
|
145
|
-
};
|
|
146
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
147
|
-
let HTTPService = class extends Disposable {
|
|
148
|
-
constructor(_http) {
|
|
101
|
+
var V = Object.defineProperty, W = Object.getOwnPropertyDescriptor, J = (e, t, n, r) => {
|
|
102
|
+
for (var s = r > 1 ? void 0 : r ? W(t, n) : t, o = e.length - 1, i; o >= 0; o--)
|
|
103
|
+
(i = e[o]) && (s = (r ? i(t, n, s) : i(s)) || s);
|
|
104
|
+
return r && s && V(t, n, s), s;
|
|
105
|
+
}, z = (e, t) => (n, r) => t(n, r, e);
|
|
106
|
+
let E = class extends b {
|
|
107
|
+
constructor(t) {
|
|
149
108
|
super();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this._http = _http;
|
|
109
|
+
a(this, "_interceptors", []);
|
|
110
|
+
a(this, "_pipe");
|
|
111
|
+
this._http = t;
|
|
154
112
|
}
|
|
155
|
-
registerHTTPInterceptor(
|
|
156
|
-
if (this._interceptors.indexOf(
|
|
113
|
+
registerHTTPInterceptor(t) {
|
|
114
|
+
if (this._interceptors.indexOf(t) !== -1)
|
|
157
115
|
throw new Error("[HTTPService]: The interceptor has already been registered!");
|
|
158
|
-
|
|
159
|
-
this._interceptors.push(interceptor);
|
|
160
|
-
this._interceptors = this._interceptors.sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
|
|
161
|
-
this._pipe = null;
|
|
162
|
-
return toDisposable(() => remove(this._interceptors, interceptor));
|
|
116
|
+
return this._interceptors.push(t), this._interceptors = this._interceptors.sort((n, r) => (n.priority ?? 0) - (r.priority ?? 0)), this._pipe = null, d(() => F(this._interceptors, t));
|
|
163
117
|
}
|
|
164
|
-
get(
|
|
165
|
-
return this._request("GET",
|
|
118
|
+
get(t, n) {
|
|
119
|
+
return this._request("GET", t, n);
|
|
166
120
|
}
|
|
167
|
-
post(
|
|
168
|
-
return this._request("POST",
|
|
121
|
+
post(t, n) {
|
|
122
|
+
return this._request("POST", t, n);
|
|
169
123
|
}
|
|
170
|
-
put(
|
|
171
|
-
return this._request("PUT",
|
|
124
|
+
put(t, n) {
|
|
125
|
+
return this._request("PUT", t, n);
|
|
172
126
|
}
|
|
173
|
-
delete(
|
|
174
|
-
return this._request("DELETE",
|
|
127
|
+
delete(t, n) {
|
|
128
|
+
return this._request("DELETE", t, n);
|
|
175
129
|
}
|
|
176
130
|
/** The HTTP request implementations */
|
|
177
|
-
async _request(
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
params,
|
|
183
|
-
withCredentials: (options == null ? void 0 : options.withCredentials) ?? false,
|
|
131
|
+
async _request(t, n, r) {
|
|
132
|
+
const s = new L(r == null ? void 0 : r.headers), o = new D(r == null ? void 0 : r.params), i = new B(t, n, {
|
|
133
|
+
headers: s,
|
|
134
|
+
params: o,
|
|
135
|
+
withCredentials: (r == null ? void 0 : r.withCredentials) ?? !1,
|
|
184
136
|
// default value for withCredentials is false by MDN
|
|
185
|
-
responseType: (
|
|
186
|
-
body:
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return result;
|
|
194
|
-
}
|
|
195
|
-
throw new Error(`${result.error}`);
|
|
137
|
+
responseType: (r == null ? void 0 : r.responseType) ?? "json",
|
|
138
|
+
body: r == null ? void 0 : r.body
|
|
139
|
+
}), l = O(i).pipe(
|
|
140
|
+
j((p) => this._runInterceptorsAndImplementation(p))
|
|
141
|
+
), c = await k(l);
|
|
142
|
+
if (c instanceof q)
|
|
143
|
+
return c;
|
|
144
|
+
throw new Error(`${c.error}`);
|
|
196
145
|
}
|
|
197
|
-
_runInterceptorsAndImplementation(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return this._pipe(
|
|
205
|
-
request,
|
|
206
|
-
(requestToNext) => this._http.send(requestToNext)
|
|
146
|
+
_runInterceptorsAndImplementation(t) {
|
|
147
|
+
return this._pipe || (this._pipe = this._interceptors.map((n) => n.interceptor).reduceRight(
|
|
148
|
+
(n, r) => X(n, r),
|
|
149
|
+
(n, r) => r(n)
|
|
150
|
+
)), this._pipe(
|
|
151
|
+
t,
|
|
152
|
+
(n) => this._http.send(n)
|
|
207
153
|
/* final handler */
|
|
208
154
|
);
|
|
209
155
|
}
|
|
210
156
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
],
|
|
214
|
-
function
|
|
215
|
-
return (
|
|
157
|
+
E = J([
|
|
158
|
+
z(0, $)
|
|
159
|
+
], E);
|
|
160
|
+
function X(e, t) {
|
|
161
|
+
return (n, r) => t(n, (s) => e(s, r));
|
|
216
162
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
HTTPStatusCode2[HTTPStatusCode2["MultipleChoices"] = 300] = "MultipleChoices";
|
|
235
|
-
HTTPStatusCode2[HTTPStatusCode2["MovedPermanently"] = 301] = "MovedPermanently";
|
|
236
|
-
HTTPStatusCode2[HTTPStatusCode2["Found"] = 302] = "Found";
|
|
237
|
-
HTTPStatusCode2[HTTPStatusCode2["SeeOther"] = 303] = "SeeOther";
|
|
238
|
-
HTTPStatusCode2[HTTPStatusCode2["NotModified"] = 304] = "NotModified";
|
|
239
|
-
HTTPStatusCode2[HTTPStatusCode2["UseProxy"] = 305] = "UseProxy";
|
|
240
|
-
HTTPStatusCode2[HTTPStatusCode2["Unused"] = 306] = "Unused";
|
|
241
|
-
HTTPStatusCode2[HTTPStatusCode2["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
242
|
-
HTTPStatusCode2[HTTPStatusCode2["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
243
|
-
HTTPStatusCode2[HTTPStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
244
|
-
HTTPStatusCode2[HTTPStatusCode2["Unauthorized"] = 401] = "Unauthorized";
|
|
245
|
-
HTTPStatusCode2[HTTPStatusCode2["PaymentRequired"] = 402] = "PaymentRequired";
|
|
246
|
-
HTTPStatusCode2[HTTPStatusCode2["Forbidden"] = 403] = "Forbidden";
|
|
247
|
-
HTTPStatusCode2[HTTPStatusCode2["NotFound"] = 404] = "NotFound";
|
|
248
|
-
HTTPStatusCode2[HTTPStatusCode2["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
249
|
-
HTTPStatusCode2[HTTPStatusCode2["NotAcceptable"] = 406] = "NotAcceptable";
|
|
250
|
-
HTTPStatusCode2[HTTPStatusCode2["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
251
|
-
HTTPStatusCode2[HTTPStatusCode2["RequestTimeout"] = 408] = "RequestTimeout";
|
|
252
|
-
HTTPStatusCode2[HTTPStatusCode2["Conflict"] = 409] = "Conflict";
|
|
253
|
-
HTTPStatusCode2[HTTPStatusCode2["Gone"] = 410] = "Gone";
|
|
254
|
-
HTTPStatusCode2[HTTPStatusCode2["LengthRequired"] = 411] = "LengthRequired";
|
|
255
|
-
HTTPStatusCode2[HTTPStatusCode2["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
256
|
-
HTTPStatusCode2[HTTPStatusCode2["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
257
|
-
HTTPStatusCode2[HTTPStatusCode2["UriTooLong"] = 414] = "UriTooLong";
|
|
258
|
-
HTTPStatusCode2[HTTPStatusCode2["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
259
|
-
HTTPStatusCode2[HTTPStatusCode2["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
260
|
-
HTTPStatusCode2[HTTPStatusCode2["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
261
|
-
HTTPStatusCode2[HTTPStatusCode2["ImATeapot"] = 418] = "ImATeapot";
|
|
262
|
-
HTTPStatusCode2[HTTPStatusCode2["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
263
|
-
HTTPStatusCode2[HTTPStatusCode2["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
264
|
-
HTTPStatusCode2[HTTPStatusCode2["Locked"] = 423] = "Locked";
|
|
265
|
-
HTTPStatusCode2[HTTPStatusCode2["FailedDependency"] = 424] = "FailedDependency";
|
|
266
|
-
HTTPStatusCode2[HTTPStatusCode2["TooEarly"] = 425] = "TooEarly";
|
|
267
|
-
HTTPStatusCode2[HTTPStatusCode2["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
268
|
-
HTTPStatusCode2[HTTPStatusCode2["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
269
|
-
HTTPStatusCode2[HTTPStatusCode2["TooManyRequests"] = 429] = "TooManyRequests";
|
|
270
|
-
HTTPStatusCode2[HTTPStatusCode2["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
271
|
-
HTTPStatusCode2[HTTPStatusCode2["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
272
|
-
HTTPStatusCode2[HTTPStatusCode2["InternalServerError"] = 500] = "InternalServerError";
|
|
273
|
-
HTTPStatusCode2[HTTPStatusCode2["NotImplemented"] = 501] = "NotImplemented";
|
|
274
|
-
HTTPStatusCode2[HTTPStatusCode2["BadGateway"] = 502] = "BadGateway";
|
|
275
|
-
HTTPStatusCode2[HTTPStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
276
|
-
HTTPStatusCode2[HTTPStatusCode2["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
277
|
-
HTTPStatusCode2[HTTPStatusCode2["HttpVersionNotSupported"] = 505] = "HttpVersionNotSupported";
|
|
278
|
-
HTTPStatusCode2[HTTPStatusCode2["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
279
|
-
HTTPStatusCode2[HTTPStatusCode2["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
280
|
-
HTTPStatusCode2[HTTPStatusCode2["LoopDetected"] = 508] = "LoopDetected";
|
|
281
|
-
HTTPStatusCode2[HTTPStatusCode2["NotExtended"] = 510] = "NotExtended";
|
|
282
|
-
HTTPStatusCode2[HTTPStatusCode2["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
283
|
-
return HTTPStatusCode2;
|
|
284
|
-
})(HTTPStatusCode || {});
|
|
285
|
-
class XHRHTTPImplementation {
|
|
286
|
-
send(request) {
|
|
287
|
-
return new Observable((observer) => {
|
|
288
|
-
const xhr = new XMLHttpRequest();
|
|
289
|
-
xhr.open(request.method, request.getUrlWithParams());
|
|
290
|
-
if (request.withCredentials) {
|
|
291
|
-
xhr.withCredentials = true;
|
|
292
|
-
}
|
|
293
|
-
request.headers.forEach((key, value) => xhr.setRequestHeader(key, value.join(",")));
|
|
294
|
-
if (!request.headers.has("Accept")) {
|
|
295
|
-
xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
|
|
296
|
-
}
|
|
297
|
-
if (!request.headers.has("Content-Type")) {
|
|
298
|
-
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
299
|
-
}
|
|
300
|
-
const buildResponseHeader = () => {
|
|
301
|
-
const statusText = xhr.statusText || "OK";
|
|
302
|
-
const headers = new HTTPHeaders(xhr.getAllResponseHeaders());
|
|
303
|
-
return new ResponseHeader(headers, xhr.status, statusText);
|
|
304
|
-
};
|
|
305
|
-
const onLoadHandler = () => {
|
|
306
|
-
const { headers, statusText, status } = buildResponseHeader();
|
|
307
|
-
const { responseType } = request;
|
|
308
|
-
let body2 = null;
|
|
309
|
-
let error = null;
|
|
310
|
-
if (status !== HTTPStatusCode.NoContent) {
|
|
311
|
-
body2 = typeof xhr.response === "undefined" ? xhr.responseText : xhr.response;
|
|
312
|
-
}
|
|
313
|
-
let success = status >= SuccessStatusCodeLowerBound && status < ErrorStatusCodeLowerBound;
|
|
314
|
-
if (responseType === "json" && typeof body2 === "string") {
|
|
315
|
-
const originalBody = body2;
|
|
163
|
+
const K = 200, Q = 300;
|
|
164
|
+
var x = /* @__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))(x || {});
|
|
165
|
+
class H {
|
|
166
|
+
send(t) {
|
|
167
|
+
return new y((n) => {
|
|
168
|
+
const r = new XMLHttpRequest();
|
|
169
|
+
r.open(t.method, t.getUrlWithParams()), t.withCredentials && (r.withCredentials = !0), t.headers.forEach((c, p) => r.setRequestHeader(c, p.join(","))), t.headers.has("Accept") || r.setRequestHeader("Accept", "application/json, text/plain, */*"), t.headers.has("Content-Type") || r.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
170
|
+
const s = () => {
|
|
171
|
+
const c = r.statusText || "OK", p = new L(r.getAllResponseHeaders());
|
|
172
|
+
return new G(p, r.status, c);
|
|
173
|
+
}, o = () => {
|
|
174
|
+
const { headers: c, statusText: p, status: m } = s(), { responseType: N } = t;
|
|
175
|
+
let h = null, v = null;
|
|
176
|
+
m !== x.NoContent && (h = typeof r.response > "u" ? r.responseText : r.response);
|
|
177
|
+
let w = m >= K && m < Q;
|
|
178
|
+
if (N === "json" && typeof h == "string") {
|
|
179
|
+
const u = h;
|
|
316
180
|
try {
|
|
317
|
-
|
|
318
|
-
} catch (
|
|
319
|
-
|
|
320
|
-
body2 = originalBody;
|
|
321
|
-
error = e;
|
|
181
|
+
h = h ? JSON.parse(h) : null;
|
|
182
|
+
} catch (A) {
|
|
183
|
+
w = !1, h = u, v = A;
|
|
322
184
|
}
|
|
323
185
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const res = new HTTPResponseError({
|
|
346
|
-
error,
|
|
347
|
-
status: xhr.status || 0,
|
|
348
|
-
statusText: xhr.statusText || "Unknown Error",
|
|
349
|
-
headers: buildResponseHeader().headers
|
|
186
|
+
w ? n.next(
|
|
187
|
+
new q({
|
|
188
|
+
body: h,
|
|
189
|
+
headers: c,
|
|
190
|
+
status: m,
|
|
191
|
+
statusText: p
|
|
192
|
+
})
|
|
193
|
+
) : n.next(
|
|
194
|
+
new R({
|
|
195
|
+
error: v,
|
|
196
|
+
headers: c,
|
|
197
|
+
status: m,
|
|
198
|
+
statusText: p
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
}, i = (c) => {
|
|
202
|
+
const p = new R({
|
|
203
|
+
error: c,
|
|
204
|
+
status: r.status || 0,
|
|
205
|
+
statusText: r.statusText || "Unknown Error",
|
|
206
|
+
headers: s().headers
|
|
350
207
|
});
|
|
351
|
-
|
|
208
|
+
n.next(p);
|
|
352
209
|
};
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const body = request.getBody();
|
|
358
|
-
xhr.send(body);
|
|
359
|
-
return () => {
|
|
360
|
-
if (xhr.readyState !== xhr.DONE) {
|
|
361
|
-
xhr.abort();
|
|
362
|
-
}
|
|
363
|
-
xhr.removeEventListener("load", onLoadHandler);
|
|
364
|
-
xhr.removeEventListener("error", onErrorHandler);
|
|
365
|
-
xhr.removeEventListener("abort", onErrorHandler);
|
|
366
|
-
xhr.removeEventListener("timeout", onErrorHandler);
|
|
210
|
+
r.addEventListener("load", o), r.addEventListener("error", i), r.addEventListener("abort", i), r.addEventListener("timeout", i);
|
|
211
|
+
const l = t.getBody();
|
|
212
|
+
return r.send(l), () => {
|
|
213
|
+
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", o), r.removeEventListener("error", i), r.removeEventListener("abort", i), r.removeEventListener("timeout", i);
|
|
367
214
|
};
|
|
368
215
|
});
|
|
369
216
|
}
|
|
370
217
|
}
|
|
371
|
-
const
|
|
372
|
-
class
|
|
373
|
-
createSocket(
|
|
218
|
+
const T = _("univer.socket");
|
|
219
|
+
class ee extends b {
|
|
220
|
+
createSocket(t) {
|
|
374
221
|
try {
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
connection.close(code, reason);
|
|
381
|
-
disposables.dispose();
|
|
222
|
+
const n = new WebSocket(t), r = new M();
|
|
223
|
+
return {
|
|
224
|
+
URL: t,
|
|
225
|
+
close: (o, i) => {
|
|
226
|
+
n.close(o, i), r.dispose();
|
|
382
227
|
},
|
|
383
|
-
send: (
|
|
384
|
-
|
|
228
|
+
send: (o) => {
|
|
229
|
+
n.send(o);
|
|
385
230
|
},
|
|
386
|
-
open$: new
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const callback = (event) => subscriber.next(event);
|
|
403
|
-
connection.addEventListener("message", callback);
|
|
404
|
-
disposables.add(toDisposable(() => connection.removeEventListener("message", callback)));
|
|
405
|
-
}).pipe(share())
|
|
231
|
+
open$: new y((o) => {
|
|
232
|
+
const i = (l) => o.next(l);
|
|
233
|
+
n.addEventListener("open", i), r.add(d(() => n.removeEventListener("open", i)));
|
|
234
|
+
}).pipe(f()),
|
|
235
|
+
close$: new y((o) => {
|
|
236
|
+
const i = (l) => o.next(l);
|
|
237
|
+
n.addEventListener("close", i), r.add(d(() => n.removeEventListener("close", i)));
|
|
238
|
+
}).pipe(f()),
|
|
239
|
+
error$: new y((o) => {
|
|
240
|
+
const i = (l) => o.next(l);
|
|
241
|
+
n.addEventListener("error", i), r.add(d(() => n.removeEventListener("error", i)));
|
|
242
|
+
}).pipe(f()),
|
|
243
|
+
message$: new y((o) => {
|
|
244
|
+
const i = (l) => o.next(l);
|
|
245
|
+
n.addEventListener("message", i), r.add(d(() => n.removeEventListener("message", i)));
|
|
246
|
+
}).pipe(f())
|
|
406
247
|
};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
console.error(e);
|
|
410
|
-
return null;
|
|
248
|
+
} catch (n) {
|
|
249
|
+
return console.error(n), null;
|
|
411
250
|
}
|
|
412
251
|
}
|
|
413
252
|
}
|
|
414
253
|
export {
|
|
415
|
-
HTTPHeaders,
|
|
416
|
-
HTTPRequest,
|
|
417
|
-
HTTPResponse,
|
|
418
|
-
HTTPService,
|
|
419
|
-
IHTTPImplementation,
|
|
420
|
-
ISocketService,
|
|
421
|
-
WebSocketService,
|
|
422
|
-
XHRHTTPImplementation
|
|
254
|
+
L as HTTPHeaders,
|
|
255
|
+
B as HTTPRequest,
|
|
256
|
+
q as HTTPResponse,
|
|
257
|
+
E as HTTPService,
|
|
258
|
+
$ as IHTTPImplementation,
|
|
259
|
+
T as ISocketService,
|
|
260
|
+
ee as WebSocketService,
|
|
261
|
+
H as XHRHTTPImplementation
|
|
423
262
|
};
|