@univerjs/network 0.6.7 → 0.6.8

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/facade.js ADDED
@@ -0,0 +1,85 @@
1
+ import { FBase as v, FUniver as p } from "@univerjs/core/facade";
2
+ import { HTTPService as S, WebSocketService as _ } from "@univerjs/network";
3
+ import { Inject as h, Injector as u } from "@univerjs/core";
4
+ var w = Object.getOwnPropertyDescriptor, l = (t, e, c, r) => {
5
+ for (var i = r > 1 ? void 0 : r ? w(e, c) : e, s = t.length - 1, o; s >= 0; s--)
6
+ (o = t[s]) && (i = o(i) || i);
7
+ return i;
8
+ }, a = (t, e) => (c, r) => e(c, r, t);
9
+ let n = class extends v {
10
+ constructor(t, e) {
11
+ super(), this._injector = t, this._httpService = e;
12
+ }
13
+ /**
14
+ * Send a GET request to the server.
15
+ * @param {string} url - The requested URL.
16
+ * @param {IRequestParams} [params] - Query parameters.
17
+ * @returns {Promise<HTTPResponse>} Network response.
18
+ */
19
+ get(t, e) {
20
+ return this._httpService.get(t, e);
21
+ }
22
+ /**
23
+ * Send a POST request to the server.
24
+ * @param {string} url - The requested URL.
25
+ * @param {IPostRequestParams} [params] - Query parameters.
26
+ * @returns {Promise<HTTPResponse>} Network response.
27
+ */
28
+ post(t, e) {
29
+ return this._httpService.post(t, e);
30
+ }
31
+ /**
32
+ * Send a PUT request to the server.
33
+ * @param {string} url - The requested URL
34
+ * @param {IPostRequestParams} [params] - Query parameters
35
+ * @returns {Promise<HTTPResponse>} Network response
36
+ */
37
+ put(t, e) {
38
+ return this._httpService.put(t, e);
39
+ }
40
+ /**
41
+ * Send DELETE request to the server.
42
+ * @param {string} url - The requested URL
43
+ * @param {IRequestParams} [params] - Query parameters
44
+ * @returns {Promise<HTTPResponse>} Network response
45
+ */
46
+ delete(t, e) {
47
+ return this._httpService.delete(t, e);
48
+ }
49
+ /**
50
+ * Send PATCH request to the server.
51
+ * @param {string} url - The requested URL
52
+ * @param {IPostRequestParams} [params] - Query parameters
53
+ * @returns {Promise<HTTPResponse>} Network response
54
+ */
55
+ patch(t, e) {
56
+ return this._httpService.patch(t, e);
57
+ }
58
+ /**
59
+ * Request for a stream of server-sent events. Instead of a single response, the server sends a stream of responses,
60
+ * Univer wraps the stream in an [`Observable`](https://rxjs.dev/guide/observable) which you can call `subscribe` on.
61
+ * @param {HTTPRequestMethod} method - HTTP request method
62
+ * @param {string} url - The requested URL
63
+ * @param {IPostRequestParams} [params] - params Query parameters
64
+ * @returns {Observable<HTTPEvent>} An observable that emits the network response.
65
+ */
66
+ getSSE(t, e, c) {
67
+ return this._httpService.getSSE(t, e, c);
68
+ }
69
+ };
70
+ n = l([
71
+ a(0, h(u)),
72
+ a(1, h(S))
73
+ ], n);
74
+ class f extends p {
75
+ getNetwork() {
76
+ return this._injector.createInstance(n);
77
+ }
78
+ createSocket(e) {
79
+ const r = this._injector.createInstance(_).createSocket(e);
80
+ if (!r)
81
+ throw new Error("[WebSocketService]: failed to create socket!");
82
+ return r;
83
+ }
84
+ }
85
+ p.extend(f);
package/lib/index.js ADDED
@@ -0,0 +1,586 @@
1
+ var Z = Object.defineProperty;
2
+ var P = (e, t, r) => t in e ? Z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var p = (e, t, r) => P(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { createIdentifier as V, Disposable as z, toDisposable as R, remove as J, ILogService as O, Inject as S, Injector as H, Plugin as C, Quantity as T, LookUp as ee, registerDependencies as re, mergeOverrideWithDependencies as te, DisposableCollection as ne } from "@univerjs/core";
5
+ import { of as q, firstValueFrom as se, Observable as m, catchError as oe, throwError as ie } from "rxjs";
6
+ import { concatMap as M, share as x, retry as ce } from "rxjs/operators";
7
+ const j = "application/json";
8
+ class I {
9
+ constructor(t) {
10
+ p(this, "_headers", /* @__PURE__ */ new Map());
11
+ typeof t == "string" ? this._handleHeadersString(t) : t instanceof Headers ? this._handleHeaders(t) : t && this._handleHeadersConstructorProps(t);
12
+ }
13
+ forEach(t) {
14
+ this._headers.forEach((r, n) => t(n, r));
15
+ }
16
+ has(t) {
17
+ return !!this._headers.has(t.toLowerCase());
18
+ }
19
+ get(t) {
20
+ const r = t.toLowerCase();
21
+ return this._headers.has(r) ? this._headers.get(r) : null;
22
+ }
23
+ set(t, r) {
24
+ this._setHeader(t, r);
25
+ }
26
+ toHeadersInit() {
27
+ var r, n;
28
+ const t = {};
29
+ return this._headers.forEach((s, o) => {
30
+ t[o] = s.join(",");
31
+ }), (r = t.accept) != null || (t.accept = "application/json, text/plain, */*"), (n = t["content-type"]) != null || (t["content-type"] = "application/json;charset=UTF-8"), t;
32
+ }
33
+ _setHeader(t, r) {
34
+ const n = t.toLowerCase();
35
+ this._headers.has(n) ? this._headers.get(n).push(r.toString()) : this._headers.set(n, [r.toString()]);
36
+ }
37
+ _handleHeadersString(t) {
38
+ t.split(`
39
+ `).forEach((r) => {
40
+ const [n, s] = r.split(":");
41
+ n && s && this._setHeader(n, s);
42
+ });
43
+ }
44
+ _handleHeadersConstructorProps(t) {
45
+ Object.entries(t).forEach(([r, n]) => this._setHeader(r, n));
46
+ }
47
+ _handleHeaders(t) {
48
+ t.forEach((r, n) => this._setHeader(n, r));
49
+ }
50
+ }
51
+ const K = V("network.http-implementation");
52
+ class B {
53
+ constructor(t) {
54
+ this.params = t;
55
+ }
56
+ toString() {
57
+ return this.params ? Object.keys(this.params).map((t) => {
58
+ const r = this.params[t];
59
+ return Array.isArray(r) ? r.map((n) => `${t}=${n}`).join("&") : `${t}=${r}`;
60
+ }).join("&") : "";
61
+ }
62
+ }
63
+ let ae = 0;
64
+ class G {
65
+ constructor(t, r, n) {
66
+ p(this, "uid", ae++);
67
+ this.method = t, this.url = r, this.requestParams = n;
68
+ }
69
+ get headers() {
70
+ return this.requestParams.headers;
71
+ }
72
+ get withCredentials() {
73
+ return this.requestParams.withCredentials;
74
+ }
75
+ get responseType() {
76
+ return this.requestParams.responseType;
77
+ }
78
+ getUrlWithParams() {
79
+ var r, n;
80
+ const t = (n = (r = this.requestParams) == null ? void 0 : r.params) == null ? void 0 : n.toString();
81
+ return t ? `${this.url}${this.url.includes("?") ? "&" : "?"}${t}` : this.url;
82
+ }
83
+ getBody() {
84
+ var n, s;
85
+ const t = (n = this.headers.get("Content-Type")) != null ? n : j, r = (s = this.requestParams) == null ? void 0 : s.body;
86
+ return t === j && r && typeof r == "object" ? JSON.stringify(r) : r ? `${r}` : null;
87
+ }
88
+ getHeadersInit() {
89
+ return this.headers.toHeadersInit();
90
+ }
91
+ }
92
+ var le = Object.getOwnPropertyDescriptor, he = (e, t, r, n) => {
93
+ for (var s = n > 1 ? void 0 : n ? le(t, r) : t, o = e.length - 1, i; o >= 0; o--)
94
+ (i = e[o]) && (s = i(s) || s);
95
+ return s;
96
+ }, de = (e, t) => (r, n) => t(r, n, e);
97
+ let b = class extends z {
98
+ constructor(t) {
99
+ super();
100
+ p(this, "_interceptors", []);
101
+ // eslint-disable-next-line ts/no-explicit-any
102
+ p(this, "_pipe");
103
+ this._http = t;
104
+ }
105
+ /**
106
+ * Register an HTTP interceptor.
107
+ *
108
+ * @param interceptor the http interceptor
109
+ * @returns a disposable handler to remove the interceptor
110
+ */
111
+ registerHTTPInterceptor(t) {
112
+ if (this._interceptors.indexOf(t) !== -1)
113
+ throw new Error("[HTTPService]: The interceptor has already been registered!");
114
+ return this._interceptors.push(t), this._interceptors = this._interceptors.sort((r, n) => {
115
+ var s, o;
116
+ return ((s = r.priority) != null ? s : 0) - ((o = n.priority) != null ? o : 0);
117
+ }), this._pipe = null, R(() => J(this._interceptors, t));
118
+ }
119
+ get(t, r) {
120
+ return this._request("GET", t, r);
121
+ }
122
+ post(t, r) {
123
+ return this._request("POST", t, r);
124
+ }
125
+ put(t, r) {
126
+ return this._request("PUT", t, r);
127
+ }
128
+ delete(t, r) {
129
+ return this._request("DELETE", t, r);
130
+ }
131
+ patch(t, r) {
132
+ return this._request("PATCH", t, r);
133
+ }
134
+ getSSE(t, r, n) {
135
+ var c, f;
136
+ const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
137
+ headers: s,
138
+ params: o,
139
+ withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
140
+ reportProgress: !0,
141
+ responseType: (f = n == null ? void 0 : n.responseType) != null ? f : "json",
142
+ body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
143
+ });
144
+ return q(i).pipe(M((a) => this._runInterceptorsAndImplementation(a)));
145
+ }
146
+ /** The HTTP request implementations */
147
+ async _request(t, r, n) {
148
+ var a, h;
149
+ const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
150
+ headers: s,
151
+ params: o,
152
+ withCredentials: (a = n == null ? void 0 : n.withCredentials) != null ? a : !1,
153
+ // default value for withCredentials is false by MDN
154
+ responseType: (h = n == null ? void 0 : n.responseType) != null ? h : "json",
155
+ body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
156
+ }), c = q(i).pipe(
157
+ M((l) => this._runInterceptorsAndImplementation(l))
158
+ );
159
+ return await se(c);
160
+ }
161
+ // eslint-disable-next-line ts/no-explicit-any
162
+ _runInterceptorsAndImplementation(t) {
163
+ return this._pipe || (this._pipe = this._interceptors.map((r) => r.interceptor).reduceRight(
164
+ (r, n) => pe(r, n),
165
+ (r, n) => n(r)
166
+ )), this._pipe(
167
+ t,
168
+ (r) => this._http.send(r)
169
+ /* final handler */
170
+ );
171
+ }
172
+ };
173
+ b = he([
174
+ de(0, K)
175
+ ], b);
176
+ function pe(e, t) {
177
+ return (r, n) => t(r, (s) => e(s, n));
178
+ }
179
+ const ue = 200, ge = 300;
180
+ var L = /* @__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))(L || {}), Y = /* @__PURE__ */ ((e) => (e[e.DownloadProgress = 0] = "DownloadProgress", e[e.Response = 1] = "Response", e))(Y || {});
181
+ class D {
182
+ constructor({
183
+ body: t,
184
+ headers: r,
185
+ status: n,
186
+ statusText: s
187
+ }) {
188
+ p(this, "type", 1);
189
+ p(this, "body");
190
+ p(this, "headers");
191
+ p(this, "status");
192
+ p(this, "statusText");
193
+ this.body = t, this.headers = r, this.status = n, this.statusText = s;
194
+ }
195
+ }
196
+ class ye {
197
+ constructor(t, r, n) {
198
+ p(this, "type", 0);
199
+ this.total = t, this.loaded = r, this.partialText = n;
200
+ }
201
+ }
202
+ class fe {
203
+ constructor(t, r, n) {
204
+ this.headers = t, this.status = r, this.statusText = n;
205
+ }
206
+ }
207
+ class v {
208
+ constructor({
209
+ request: t,
210
+ headers: r,
211
+ status: n,
212
+ statusText: s,
213
+ error: o
214
+ }) {
215
+ p(this, "request");
216
+ p(this, "headers");
217
+ p(this, "status");
218
+ p(this, "statusText");
219
+ p(this, "error");
220
+ this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
221
+ }
222
+ }
223
+ function Q(e) {
224
+ return {
225
+ method: e.method,
226
+ headers: e.getHeadersInit(),
227
+ body: e.getBody(),
228
+ credentials: e.withCredentials ? "include" : void 0
229
+ };
230
+ }
231
+ var we = Object.getOwnPropertyDescriptor, me = (e, t, r, n) => {
232
+ for (var s = n > 1 ? void 0 : n ? we(t, r) : t, o = e.length - 1, i; o >= 0; o--)
233
+ (i = e[o]) && (s = i(s) || s);
234
+ return s;
235
+ }, ve = (e, t) => (r, n) => t(r, n, e);
236
+ let N = class {
237
+ constructor(e) {
238
+ this._logService = e;
239
+ }
240
+ send(e) {
241
+ return new m((t) => {
242
+ const r = new AbortController();
243
+ return this._send(e, t, r).catch((n) => {
244
+ t.error(new v({
245
+ error: n,
246
+ request: e
247
+ }));
248
+ }), () => r.abort();
249
+ });
250
+ }
251
+ async _send(e, t, r) {
252
+ var a, h;
253
+ let n;
254
+ try {
255
+ const l = Q(e), w = e.getUrlWithParams(), d = fetch(w, {
256
+ signal: r.signal,
257
+ ...l
258
+ });
259
+ this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${w} with params ${l}`), n = await d;
260
+ } catch (l) {
261
+ const w = new v({
262
+ request: e,
263
+ error: l,
264
+ status: (a = l.status) != null ? a : 0,
265
+ statusText: (h = l.statusText) != null ? h : "Unknown Error",
266
+ headers: l.headers
267
+ });
268
+ this._logService.error("[FetchHTTPImplementation]: network error", w), t.error(w);
269
+ return;
270
+ }
271
+ const s = new I(n.headers), o = n.status, i = n.statusText;
272
+ let c = null;
273
+ if (n.body && (c = await this._readBody(e, n, t)), o >= L.Ok && o < L.MultipleChoices)
274
+ t.next(new D({
275
+ body: c,
276
+ headers: s,
277
+ status: o,
278
+ statusText: i
279
+ }));
280
+ else {
281
+ const l = new v({
282
+ request: e,
283
+ error: c,
284
+ status: o,
285
+ statusText: i,
286
+ headers: s
287
+ });
288
+ this._logService.error("[FetchHTTPImplementation]: network error", l), t.error(l);
289
+ }
290
+ t.complete();
291
+ }
292
+ async _readBody(e, t, r) {
293
+ var w, d;
294
+ const n = [], s = t.body.getReader(), o = t.headers.get("content-length");
295
+ let i = 0;
296
+ const c = (w = e.requestParams) == null ? void 0 : w.reportProgress, f = e.responseType;
297
+ let a, h;
298
+ for (; ; ) {
299
+ const { done: u, value: y } = await s.read();
300
+ if (u) break;
301
+ n.push(y), i += y.length, c && f === "text" && (a = (a != null ? a : "") + (h != null ? h : h = new TextDecoder()).decode(y, { stream: !0 }), r.next(new ye(
302
+ o ? Number.parseInt(o, 10) : void 0,
303
+ i,
304
+ a
305
+ )));
306
+ }
307
+ const l = _e(n, i);
308
+ try {
309
+ const u = (d = t.headers.get("content-type")) != null ? d : "";
310
+ return Re(e, l, u);
311
+ } catch (u) {
312
+ const y = new v({
313
+ request: e,
314
+ error: u,
315
+ status: t.status,
316
+ statusText: t.statusText,
317
+ headers: new I(t.headers)
318
+ });
319
+ return this._logService.error("[FetchHTTPImplementation]: network error", y), r.error(y), null;
320
+ }
321
+ }
322
+ };
323
+ N = me([
324
+ ve(0, O)
325
+ ], N);
326
+ function _e(e, t) {
327
+ const r = new Uint8Array(t);
328
+ let n = 0;
329
+ for (const s of e)
330
+ r.set(s, n), n += s.length;
331
+ return r;
332
+ }
333
+ const Ee = /^\)\]\}',?\n/;
334
+ function Re(e, t, r) {
335
+ switch (e.responseType) {
336
+ case "json":
337
+ const n = new TextDecoder().decode(t).replace(Ee, "");
338
+ return n === "" ? null : JSON.parse(n);
339
+ case "text":
340
+ return new TextDecoder().decode(t);
341
+ case "blob":
342
+ return new Blob([t], { type: r });
343
+ case "arraybuffer":
344
+ return t.buffer;
345
+ default:
346
+ throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
347
+ }
348
+ }
349
+ var Ie = Object.getOwnPropertyDescriptor, xe = (e, t, r, n) => {
350
+ for (var s = n > 1 ? void 0 : n ? Ie(t, r) : t, o = e.length - 1, i; o >= 0; o--)
351
+ (i = e[o]) && (s = i(s) || s);
352
+ return s;
353
+ }, be = (e, t) => (r, n) => t(r, n, e);
354
+ let U = class {
355
+ constructor(e) {
356
+ this._logService = e;
357
+ }
358
+ send(e) {
359
+ return new m((t) => {
360
+ const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e);
361
+ r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([a, h]) => r.setRequestHeader(a, h));
362
+ const o = () => {
363
+ const a = r.statusText || "OK", h = new I(r.getAllResponseHeaders());
364
+ return new fe(h, r.status, a);
365
+ }, i = () => {
366
+ const { headers: a, statusText: h, status: l } = o(), { responseType: w } = e;
367
+ let d = null, u = null;
368
+ l !== L.NoContent && (d = typeof r.response > "u" ? r.responseText : r.response);
369
+ let y = l >= ue && l < ge;
370
+ if (w === "json" && typeof d == "string") {
371
+ const g = d;
372
+ try {
373
+ d = d ? JSON.parse(d) : null;
374
+ } catch (_) {
375
+ y = !1, d = g, u = _;
376
+ }
377
+ }
378
+ if (y)
379
+ t.next(
380
+ new D({
381
+ body: d,
382
+ headers: a,
383
+ status: l,
384
+ statusText: h
385
+ })
386
+ );
387
+ else {
388
+ const g = new v({
389
+ request: e,
390
+ error: u,
391
+ headers: a,
392
+ status: l,
393
+ statusText: h
394
+ });
395
+ this._logService.error("[XHRHTTPImplementation]: network error", g), t.error(g);
396
+ }
397
+ }, c = (a) => {
398
+ const h = new v({
399
+ request: e,
400
+ error: a,
401
+ status: r.status || 0,
402
+ statusText: r.statusText || "Unknown Error",
403
+ headers: o().headers
404
+ });
405
+ this._logService.error("[XHRHTTPImplementation]: network error", h), t.error(h);
406
+ };
407
+ r.addEventListener("load", i), r.addEventListener("error", c), r.addEventListener("abort", c), r.addEventListener("timeout", c);
408
+ const f = e.getBody();
409
+ return r.send(f), this._logService.debug("[XHRHTTPImplementation]", `sending request to url ${n} with params ${s}`), () => {
410
+ r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", i), r.removeEventListener("error", c), r.removeEventListener("abort", c), r.removeEventListener("timeout", c);
411
+ };
412
+ });
413
+ }
414
+ };
415
+ U = xe([
416
+ be(0, O)
417
+ ], U);
418
+ var Le = Object.getOwnPropertyDescriptor, Ne = (e, t, r, n) => {
419
+ for (var s = n > 1 ? void 0 : n ? Le(t, r) : t, o = e.length - 1, i; o >= 0; o--)
420
+ (i = e[o]) && (s = i(s) || s);
421
+ return s;
422
+ }, W = (e, t) => (r, n) => t(r, n, e), F;
423
+ let X = (F = class extends C {
424
+ constructor(e = void 0, t, r) {
425
+ super(), this._config = e, this._logger = t, this._injector = r;
426
+ }
427
+ onStarting() {
428
+ var r, n, s;
429
+ if (this._injector.get(b, T.OPTIONAL, ee.SKIP_SELF) && !((r = this._config) != null && r.forceUseNewInstance)) {
430
+ this._logger.warn(
431
+ "[UniverNetworkPlugin]",
432
+ 'HTTPService is already registered in an ancestor interceptor. Skipping registration. If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.'
433
+ );
434
+ return;
435
+ }
436
+ const t = (n = this._config) != null && n.useFetchImpl ? N : typeof window < "u" ? U : N;
437
+ re(this._injector, te([
438
+ [b],
439
+ [K, { useClass: t }]
440
+ ], (s = this._config) == null ? void 0 : s.override));
441
+ }
442
+ }, p(F, "pluginName", "UNIVER_NETWORK_PLUGIN"), F);
443
+ X = Ne([
444
+ W(1, O),
445
+ W(2, S(H))
446
+ ], X);
447
+ const Me = V("univer.network.socket.service");
448
+ class je extends z {
449
+ createSocket(t) {
450
+ try {
451
+ const r = new WebSocket(t), n = new ne();
452
+ return {
453
+ URL: t,
454
+ close: (o, i) => {
455
+ r.close(o, i), n.dispose();
456
+ },
457
+ send: (o) => {
458
+ r.send(o);
459
+ },
460
+ open$: new m((o) => {
461
+ const i = (c) => o.next(c);
462
+ r.addEventListener("open", i), n.add(R(() => r.removeEventListener("open", i)));
463
+ }).pipe(x()),
464
+ close$: new m((o) => {
465
+ const i = (c) => o.next(c);
466
+ r.addEventListener("close", i), n.add(R(() => r.removeEventListener("close", i)));
467
+ }).pipe(x()),
468
+ error$: new m((o) => {
469
+ const i = (c) => o.next(c);
470
+ r.addEventListener("error", i), n.add(R(() => r.removeEventListener("error", i)));
471
+ }).pipe(x()),
472
+ message$: new m((o) => {
473
+ const i = (c) => o.next(c);
474
+ r.addEventListener("message", i), n.add(R(() => r.removeEventListener("message", i)));
475
+ }).pipe(x())
476
+ };
477
+ } catch (r) {
478
+ return console.error(r), null;
479
+ }
480
+ }
481
+ }
482
+ const ke = 3, Ae = 1e3, Be = (e) => {
483
+ var n, s;
484
+ const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n : ke, r = (s = e == null ? void 0 : e.delayInterval) != null ? s : Ae;
485
+ return (o, i) => i(o).pipe(ce({ delay: r, count: t }));
486
+ }, Ge = (e) => {
487
+ const t = [], r = /* @__PURE__ */ new Set(), n = () => {
488
+ var s;
489
+ for (; r.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && t.length > 0; ) {
490
+ const o = t.shift();
491
+ r.add(o), o();
492
+ }
493
+ };
494
+ return (s, o) => new m((i) => {
495
+ const c = () => o(s).subscribe({
496
+ next: (a) => i.next(a),
497
+ error: (a) => i.error(a),
498
+ complete: () => i.complete()
499
+ }), f = () => {
500
+ r.delete(c), J(t, c), n();
501
+ };
502
+ return t.push(c), n(), f;
503
+ });
504
+ }, We = (e) => {
505
+ const { errorStatusCodes: t, onAuthError: r } = e;
506
+ return (s, o) => o(s).pipe(
507
+ oe((i) => (i instanceof v && t.some((c) => c === i.status) && r(), ie(() => i)))
508
+ );
509
+ }, Fe = (e = 300) => {
510
+ let r = () => {
511
+ };
512
+ return (n) => new Promise((s) => {
513
+ r();
514
+ const o = setTimeout(() => {
515
+ s(!0);
516
+ }, e);
517
+ r = () => {
518
+ clearTimeout(o), s(!1);
519
+ };
520
+ });
521
+ }, Ue = () => (e, t) => t.map((r) => ({ config: r, result: e })), Xe = (e, t = {}) => {
522
+ const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Fe(300), distributeResult: i = Ue() } = t, c = [], f = (a) => a.map((h) => h.config);
523
+ return (a, h) => r(a) ? new m((l) => {
524
+ const w = n(a);
525
+ c.push({
526
+ next: (u) => l.next(u),
527
+ error: (u) => l.error(u),
528
+ config: w
529
+ });
530
+ const d = f(c);
531
+ o(a).then((u) => {
532
+ if (u) {
533
+ const y = [];
534
+ d.forEach((g) => {
535
+ const _ = c.findIndex((E) => E.config === g);
536
+ if (_ >= 0) {
537
+ const [E] = c.splice(_, 1);
538
+ y.push(E);
539
+ }
540
+ }), h(s(d, a)).subscribe({
541
+ next: (g) => {
542
+ if (g.type === Y.Response) {
543
+ const _ = g.body, E = i(_, d);
544
+ y.forEach((k) => {
545
+ const $ = E.find((A) => A.config === k.config);
546
+ if ($) {
547
+ const A = new D({
548
+ body: $.result,
549
+ headers: g.headers,
550
+ status: g.status,
551
+ statusText: g.statusText
552
+ });
553
+ k.next(A);
554
+ } else
555
+ k.error("batch error");
556
+ });
557
+ }
558
+ },
559
+ complete: () => l.complete(),
560
+ error: (g) => l.error(g)
561
+ });
562
+ }
563
+ });
564
+ }) : h(a);
565
+ };
566
+ export {
567
+ We as AuthInterceptorFactory,
568
+ N as FetchHTTPImplementation,
569
+ Y as HTTPEventType,
570
+ I as HTTPHeaders,
571
+ ye as HTTPProgress,
572
+ G as HTTPRequest,
573
+ D as HTTPResponse,
574
+ v as HTTPResponseError,
575
+ b as HTTPService,
576
+ L as HTTPStatusCode,
577
+ K as IHTTPImplementation,
578
+ Me as ISocketService,
579
+ Xe as MergeInterceptorFactory,
580
+ fe as ResponseHeader,
581
+ Be as RetryInterceptorFactory,
582
+ Ge as ThresholdInterceptorFactory,
583
+ X as UniverNetworkPlugin,
584
+ je as WebSocketService,
585
+ U as XHRHTTPImplementation
586
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/network",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "private": false,
5
5
  "author": "DreamNum <developer@univer.ai>",
6
6
  "license": "Apache-2.0",
@@ -52,14 +52,14 @@
52
52
  "rxjs": ">=7.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@univerjs/core": "0.6.7"
55
+ "@univerjs/core": "0.6.8"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.1",
59
59
  "typescript": "^5.8.2",
60
60
  "vite": "^6.2.3",
61
61
  "vitest": "^3.0.9",
62
- "@univerjs-infra/shared": "0.6.7"
62
+ "@univerjs-infra/shared": "0.6.8"
63
63
  },
64
64
  "scripts": {
65
65
  "test": "vitest run",