@univerjs/network 0.1.0-beta.2 → 0.1.0-beta.4

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 _, 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 L } from "@wendellhu/redi";
8
+ const R = "application/json";
9
+ class q {
10
+ constructor(t) {
11
+ a(this, "_headers", /* @__PURE__ */ new Map());
12
+ typeof t == "string" ? t.split(`
13
+ `).forEach((n) => {
14
+ const [r, i] = n.split(":");
15
+ r && i && this._setHeader(r, i);
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 $ = L("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,212 @@ 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, i;
64
+ const t = (r = this.headers.get("Content-Type")) != null ? r : R, n = (i = this.requestParams) == null ? void 0 : i.body;
65
+ return t === R && n && typeof n == "object" ? JSON.stringify(n) : n ? `${n}` : null;
92
66
  }
93
67
  }
94
- class HTTPResponse {
68
+ class x {
95
69
  constructor({
96
- body,
97
- headers,
98
- status,
99
- statusText
70
+ body: t,
71
+ headers: n,
72
+ status: r,
73
+ statusText: i
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 = i;
109
80
  }
110
81
  }
111
- class HTTPResponseError {
82
+ class E {
112
83
  constructor({
113
- headers,
114
- status,
115
- statusText,
116
- error
84
+ headers: t,
85
+ status: n,
86
+ statusText: r,
87
+ error: i
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 = i;
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 i = r > 1 ? void 0 : r ? W(t, n) : t, o = e.length - 1, s; o >= 0; o--)
103
+ (s = e[o]) && (i = (r ? s(t, n, i) : s(i)) || i);
104
+ return r && i && V(t, n, i), i;
105
+ }, z = (e, t) => (n, r) => t(n, r, e);
106
+ let b = class extends _ {
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) => {
117
+ var i, o;
118
+ return ((i = n.priority) != null ? i : 0) - ((o = r.priority) != null ? o : 0);
119
+ }), this._pipe = null, d(() => F(this._interceptors, t));
163
120
  }
164
- get(url, options) {
165
- return this._request("GET", url, options);
121
+ get(t, n) {
122
+ return this._request("GET", t, n);
166
123
  }
167
- post(url, options) {
168
- return this._request("POST", url, options);
124
+ post(t, n) {
125
+ return this._request("POST", t, n);
169
126
  }
170
- put(url, options) {
171
- return this._request("PUT", url, options);
127
+ put(t, n) {
128
+ return this._request("PUT", t, n);
172
129
  }
173
- delete(url, options) {
174
- return this._request("DELETE", url, options);
130
+ delete(t, n) {
131
+ return this._request("DELETE", t, n);
175
132
  }
176
133
  /** 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,
134
+ async _request(t, n, r) {
135
+ var p, h;
136
+ const i = new q(r == null ? void 0 : r.headers), o = new D(r == null ? void 0 : r.params), s = new B(t, n, {
137
+ headers: i,
138
+ params: o,
139
+ withCredentials: (p = r == null ? void 0 : r.withCredentials) != null ? p : !1,
184
140
  // 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}`);
141
+ responseType: (h = r == null ? void 0 : r.responseType) != null ? h : "json",
142
+ body: r == null ? void 0 : r.body
143
+ }), l = O(s).pipe(
144
+ j((v) => this._runInterceptorsAndImplementation(v))
145
+ ), c = await k(l);
146
+ if (c instanceof x)
147
+ return c;
148
+ throw new Error(`${c.error}`);
196
149
  }
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)
150
+ _runInterceptorsAndImplementation(t) {
151
+ return this._pipe || (this._pipe = this._interceptors.map((n) => n.interceptor).reduceRight(
152
+ (n, r) => X(n, r),
153
+ (n, r) => r(n)
154
+ )), this._pipe(
155
+ t,
156
+ (n) => this._http.send(n)
207
157
  /* final handler */
208
158
  );
209
159
  }
210
160
  };
211
- HTTPService = __decorateClass([
212
- __decorateParam(0, IHTTPImplementation)
213
- ], HTTPService);
214
- function chainInterceptorFn(afterInterceptorChain, currentInterceptorFn) {
215
- return (prevRequest, nextHandlerFn) => currentInterceptorFn(prevRequest, (nextRequest) => afterInterceptorChain(nextRequest, nextHandlerFn));
161
+ b = J([
162
+ z(0, $)
163
+ ], b);
164
+ function X(e, t) {
165
+ return (n, r) => t(n, (i) => e(i, r));
216
166
  }
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;
167
+ const K = 200, Q = 300;
168
+ var N = /* @__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))(N || {});
169
+ class H {
170
+ send(t) {
171
+ return new y((n) => {
172
+ const r = new XMLHttpRequest();
173
+ 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");
174
+ const i = () => {
175
+ const c = r.statusText || "OK", p = new q(r.getAllResponseHeaders());
176
+ return new G(p, r.status, c);
177
+ }, o = () => {
178
+ const { headers: c, statusText: p, status: h } = i(), { responseType: v } = t;
179
+ let m = null, w = null;
180
+ h !== N.NoContent && (m = typeof r.response > "u" ? r.responseText : r.response);
181
+ let g = h >= K && h < Q;
182
+ if (v === "json" && typeof m == "string") {
183
+ const u = m;
316
184
  try {
317
- body2 = body2 ? JSON.parse(body2) : null;
318
- } catch (e) {
319
- success = false;
320
- body2 = originalBody;
321
- error = e;
185
+ m = m ? JSON.parse(m) : null;
186
+ } catch (A) {
187
+ g = !1, m = u, w = A;
322
188
  }
323
189
  }
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
190
+ g ? n.next(
191
+ new x({
192
+ body: m,
193
+ headers: c,
194
+ status: h,
195
+ statusText: p
196
+ })
197
+ ) : n.next(
198
+ new E({
199
+ error: w,
200
+ headers: c,
201
+ status: h,
202
+ statusText: p
203
+ })
204
+ );
205
+ }, s = (c) => {
206
+ const p = new E({
207
+ error: c,
208
+ status: r.status || 0,
209
+ statusText: r.statusText || "Unknown Error",
210
+ headers: i().headers
350
211
  });
351
- observer.next(res);
212
+ n.next(p);
352
213
  };
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);
214
+ r.addEventListener("load", o), r.addEventListener("error", s), r.addEventListener("abort", s), r.addEventListener("timeout", s);
215
+ const l = t.getBody();
216
+ return r.send(l), () => {
217
+ r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", o), r.removeEventListener("error", s), r.removeEventListener("abort", s), r.removeEventListener("timeout", s);
367
218
  };
368
219
  });
369
220
  }
370
221
  }
371
- const ISocketService = createIdentifier("univer.socket");
372
- class WebSocketService extends Disposable {
373
- createSocket(URL) {
222
+ const T = L("univer.socket");
223
+ class ee extends _ {
224
+ createSocket(t) {
374
225
  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();
226
+ const n = new WebSocket(t), r = new M();
227
+ return {
228
+ URL: t,
229
+ close: (o, s) => {
230
+ n.close(o, s), r.dispose();
382
231
  },
383
- send: (data) => {
384
- connection.send(data);
232
+ send: (o) => {
233
+ n.send(o);
385
234
  },
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())
235
+ open$: new y((o) => {
236
+ const s = (l) => o.next(l);
237
+ n.addEventListener("open", s), r.add(d(() => n.removeEventListener("open", s)));
238
+ }).pipe(f()),
239
+ close$: new y((o) => {
240
+ const s = (l) => o.next(l);
241
+ n.addEventListener("close", s), r.add(d(() => n.removeEventListener("close", s)));
242
+ }).pipe(f()),
243
+ error$: new y((o) => {
244
+ const s = (l) => o.next(l);
245
+ n.addEventListener("error", s), r.add(d(() => n.removeEventListener("error", s)));
246
+ }).pipe(f()),
247
+ message$: new y((o) => {
248
+ const s = (l) => o.next(l);
249
+ n.addEventListener("message", s), r.add(d(() => n.removeEventListener("message", s)));
250
+ }).pipe(f())
406
251
  };
407
- return webSocket;
408
- } catch (e) {
409
- console.error(e);
410
- return null;
252
+ } catch (n) {
253
+ return console.error(n), null;
411
254
  }
412
255
  }
413
256
  }
414
257
  export {
415
- HTTPHeaders,
416
- HTTPRequest,
417
- HTTPResponse,
418
- HTTPService,
419
- IHTTPImplementation,
420
- ISocketService,
421
- WebSocketService,
422
- XHRHTTPImplementation
258
+ q as HTTPHeaders,
259
+ B as HTTPRequest,
260
+ x as HTTPResponse,
261
+ b as HTTPService,
262
+ $ as IHTTPImplementation,
263
+ T as ISocketService,
264
+ ee as WebSocketService,
265
+ H as XHRHTTPImplementation
423
266
  };