@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/lib/es/index.js CHANGED
@@ -1,68 +1,49 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import { Disposable, toDisposable, remove, DisposableCollection } from "@univerjs/core";
8
- import { of, firstValueFrom, Observable } from "rxjs";
9
- import { concatMap, share } from "rxjs/operators";
10
- import { createIdentifier } from "@wendellhu/redi";
11
- const ApplicationJSONType = "application/json";
12
- class HTTPHeaders {
13
- constructor(headers) {
14
- __publicField(this, "_headers", /* @__PURE__ */ new Map());
15
- if (typeof headers === "string") {
16
- headers.split("\n").forEach((header) => {
17
- const [name, value] = header.split(":");
18
- if (name && value) {
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(callback) {
31
- this._headers.forEach((v, key) => callback(key, v));
20
+ forEach(t) {
21
+ this._headers.forEach((n, r) => t(r, n));
32
22
  }
33
- has(key) {
34
- return !!this._headers.has(key.toLowerCase());
23
+ has(t) {
24
+ return !!this._headers.has(t.toLowerCase());
35
25
  }
36
- get(key) {
37
- const k = key.toLowerCase();
38
- return this._headers.has(k) ? this._headers.get(k) : null;
26
+ get(t) {
27
+ const n = t.toLowerCase();
28
+ return this._headers.has(n) ? this._headers.get(n) : null;
39
29
  }
40
- _setHeader(name, value) {
41
- const lowerCase = name.toLowerCase();
42
- if (this._headers.has(lowerCase)) {
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 IHTTPImplementation = createIdentifier("univer-pro.network.http-implementation");
50
- class HTTPParams {
51
- constructor(params) {
52
- this.params = params;
35
+ const $ = _("univer-pro.network.http-implementation");
36
+ class D {
37
+ constructor(t) {
38
+ this.params = t;
53
39
  }
54
40
  toString() {
55
- if (!this.params) {
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 HTTPRequest {
62
- constructor(method, url, requestParams) {
63
- this.method = 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 _a, _b;
78
- const params = (_b = (_a = this.requestParams) == null ? void 0 : _a.params) == null ? void 0 : _b.toString();
79
- if (!params) {
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 _a;
86
- const contentType = this.headers.get("Content-Type") ?? ApplicationJSONType;
87
- const body = (_a = this.requestParams) == null ? void 0 : _a.body;
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 HTTPResponse {
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
- __publicField(this, "body");
102
- __publicField(this, "headers");
103
- __publicField(this, "status");
104
- __publicField(this, "statusText");
105
- this.body = 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 HTTPResponseError {
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
- __publicField(this, "headers");
119
- __publicField(this, "status");
120
- __publicField(this, "statusText");
121
- __publicField(this, "error");
122
- this.headers = 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 ResponseHeader {
129
- constructor(headers, status, statusText) {
130
- this.headers = 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 __defProp2 = Object.defineProperty;
136
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
137
- var __decorateClass = (decorators, target, key, kind) => {
138
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
139
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
140
- if (decorator = decorators[i])
141
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
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
- __publicField(this, "_interceptors", []);
151
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
- __publicField(this, "_pipe");
153
- this._http = _http;
109
+ a(this, "_interceptors", []);
110
+ a(this, "_pipe");
111
+ this._http = t;
154
112
  }
155
- registerHTTPInterceptor(interceptor) {
156
- if (this._interceptors.indexOf(interceptor) !== -1) {
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(url, options) {
165
- return this._request("GET", url, options);
118
+ get(t, n) {
119
+ return this._request("GET", t, n);
166
120
  }
167
- post(url, options) {
168
- return this._request("POST", url, options);
121
+ post(t, n) {
122
+ return this._request("POST", t, n);
169
123
  }
170
- put(url, options) {
171
- return this._request("PUT", url, options);
124
+ put(t, n) {
125
+ return this._request("PUT", t, n);
172
126
  }
173
- delete(url, options) {
174
- return this._request("DELETE", url, options);
127
+ delete(t, n) {
128
+ return this._request("DELETE", t, n);
175
129
  }
176
130
  /** The HTTP request implementations */
177
- async _request(method, url, options) {
178
- const headers = new HTTPHeaders(options == null ? void 0 : options.headers);
179
- const params = new HTTPParams(options == null ? void 0 : options.params);
180
- const request = new HTTPRequest(method, url, {
181
- headers,
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: (options == null ? void 0 : options.responseType) ?? "json",
186
- body: options == null ? void 0 : options.body
187
- });
188
- const events$ = of(request).pipe(
189
- concatMap((request2) => this._runInterceptorsAndImplementation(request2))
190
- );
191
- const result = await firstValueFrom(events$);
192
- if (result instanceof HTTPResponse) {
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(request) {
198
- if (!this._pipe) {
199
- this._pipe = this._interceptors.map((handler) => handler.interceptor).reduceRight(
200
- (nextHandlerFunction, interceptorFunction) => chainInterceptorFn(nextHandlerFunction, interceptorFunction),
201
- (requestFromPrevInterceptor, finalHandler) => finalHandler(requestFromPrevInterceptor)
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
- HTTPService = __decorateClass([
212
- __decorateParam(0, IHTTPImplementation)
213
- ], HTTPService);
214
- function chainInterceptorFn(afterInterceptorChain, currentInterceptorFn) {
215
- return (prevRequest, nextHandlerFn) => currentInterceptorFn(prevRequest, (nextRequest) => afterInterceptorChain(nextRequest, nextHandlerFn));
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 SuccessStatusCodeLowerBound = 200;
218
- const ErrorStatusCodeLowerBound = 300;
219
- var HTTPStatusCode = /* @__PURE__ */ ((HTTPStatusCode2) => {
220
- HTTPStatusCode2[HTTPStatusCode2["Continue"] = 100] = "Continue";
221
- HTTPStatusCode2[HTTPStatusCode2["SwitchingProtocols"] = 101] = "SwitchingProtocols";
222
- HTTPStatusCode2[HTTPStatusCode2["Processing"] = 102] = "Processing";
223
- HTTPStatusCode2[HTTPStatusCode2["EarlyHints"] = 103] = "EarlyHints";
224
- HTTPStatusCode2[HTTPStatusCode2["Ok"] = 200] = "Ok";
225
- HTTPStatusCode2[HTTPStatusCode2["Created"] = 201] = "Created";
226
- HTTPStatusCode2[HTTPStatusCode2["Accepted"] = 202] = "Accepted";
227
- HTTPStatusCode2[HTTPStatusCode2["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
228
- HTTPStatusCode2[HTTPStatusCode2["NoContent"] = 204] = "NoContent";
229
- HTTPStatusCode2[HTTPStatusCode2["ResetContent"] = 205] = "ResetContent";
230
- HTTPStatusCode2[HTTPStatusCode2["PartialContent"] = 206] = "PartialContent";
231
- HTTPStatusCode2[HTTPStatusCode2["MultiStatus"] = 207] = "MultiStatus";
232
- HTTPStatusCode2[HTTPStatusCode2["AlreadyReported"] = 208] = "AlreadyReported";
233
- HTTPStatusCode2[HTTPStatusCode2["ImUsed"] = 226] = "ImUsed";
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
- body2 = body2 ? JSON.parse(body2) : null;
318
- } catch (e) {
319
- success = false;
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
- if (success) {
325
- observer.next(
326
- new HTTPResponse({
327
- body: body2,
328
- headers,
329
- status,
330
- statusText
331
- })
332
- );
333
- } else {
334
- observer.next(
335
- new HTTPResponseError({
336
- error,
337
- headers,
338
- status,
339
- statusText
340
- })
341
- );
342
- }
343
- };
344
- const onErrorHandler = (error) => {
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
- observer.next(res);
208
+ n.next(p);
352
209
  };
353
- xhr.addEventListener("load", onLoadHandler);
354
- xhr.addEventListener("error", onErrorHandler);
355
- xhr.addEventListener("abort", onErrorHandler);
356
- xhr.addEventListener("timeout", onErrorHandler);
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 ISocketService = createIdentifier("univer.socket");
372
- class WebSocketService extends Disposable {
373
- createSocket(URL) {
218
+ const T = _("univer.socket");
219
+ class ee extends b {
220
+ createSocket(t) {
374
221
  try {
375
- const connection = new WebSocket(URL);
376
- const disposables = new DisposableCollection();
377
- const webSocket = {
378
- URL,
379
- close: (code, reason) => {
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: (data) => {
384
- connection.send(data);
228
+ send: (o) => {
229
+ n.send(o);
385
230
  },
386
- open$: new Observable((subscriber) => {
387
- const callback = (event) => subscriber.next(event);
388
- connection.addEventListener("open", callback);
389
- disposables.add(toDisposable(() => connection.removeEventListener("open", callback)));
390
- }).pipe(share()),
391
- close$: new Observable((subscriber) => {
392
- const callback = (event) => subscriber.next(event);
393
- connection.addEventListener("close", callback);
394
- disposables.add(toDisposable(() => connection.removeEventListener("close", callback)));
395
- }).pipe(share()),
396
- error$: new Observable((subscriber) => {
397
- const callback = (event) => subscriber.next(event);
398
- connection.addEventListener("error", callback);
399
- disposables.add(toDisposable(() => connection.removeEventListener("error", callback)));
400
- }).pipe(share()),
401
- message$: new Observable((subscriber) => {
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
- return webSocket;
408
- } catch (e) {
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
  };