@univerjs/network 0.16.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +157 -154
- package/lib/index.js +157 -154
- package/lib/types/index.d.ts +1 -1
- package/lib/types/plugin.d.ts +3 -1
- package/lib/types/services/http/__testing__/http-testing-utils.d.ts +4 -4
- package/lib/types/services/http/__testing__/http.service.spec.d.ts +16 -0
- package/lib/types/services/http/interceptors/merge-interceptor.d.ts +2 -2
- package/lib/umd/index.js +2 -2
- package/package.json +3 -3
- /package/lib/types/{controllers/config.schema.d.ts → config/config.d.ts} +0 -0
package/lib/es/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { createIdentifier as
|
|
5
|
-
import { of as M, firstValueFrom as
|
|
6
|
-
import { concatMap as B, retry as
|
|
7
|
-
const
|
|
8
|
-
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var H = (e, t, r) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var p = (e, t, r) => H(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { createIdentifier as K, Disposable as z, toDisposable as I, remove as Y, ILogService as $, Inject as C, Injector as T, IConfigService as ee, Plugin as re, merge as te, Quantity as ne, LookUp as se, registerDependencies as oe, mergeOverrideWithDependencies as ie, DisposableCollection as ce } from "@univerjs/core";
|
|
5
|
+
import { of as M, firstValueFrom as ae, Observable as m, catchError as le, throwError as he } from "rxjs";
|
|
6
|
+
import { concatMap as B, retry as pe, share as x } from "rxjs/operators";
|
|
7
|
+
const de = "@univerjs/network", ue = "0.17.0", G = {
|
|
8
|
+
name: de,
|
|
9
|
+
version: ue
|
|
10
|
+
}, ge = "network.config", W = {}, O = "application/json";
|
|
11
|
+
function fe(e) {
|
|
9
12
|
return Array.isArray(e) ? e.some((t) => t.includes(O)) : e.includes(O);
|
|
10
13
|
}
|
|
11
|
-
class
|
|
14
|
+
class b {
|
|
12
15
|
constructor(t) {
|
|
13
|
-
|
|
16
|
+
p(this, "_headers", /* @__PURE__ */ new Map());
|
|
14
17
|
typeof t == "string" ? this._handleHeadersString(t) : t instanceof Headers ? this._handleHeaders(t) : t && this._handleHeadersConstructorProps(t);
|
|
15
18
|
}
|
|
16
19
|
forEach(t) {
|
|
@@ -51,8 +54,8 @@ class I {
|
|
|
51
54
|
t.forEach((r, n) => this._setHeader(n, r));
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
const
|
|
55
|
-
class
|
|
57
|
+
const Q = K("network.http-implementation");
|
|
58
|
+
class X {
|
|
56
59
|
constructor(t) {
|
|
57
60
|
this.params = t;
|
|
58
61
|
}
|
|
@@ -63,10 +66,10 @@ class W {
|
|
|
63
66
|
}).join("&") : "";
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
let
|
|
67
|
-
class
|
|
69
|
+
let ye = 0;
|
|
70
|
+
class V {
|
|
68
71
|
constructor(t, r, n) {
|
|
69
|
-
|
|
72
|
+
p(this, "uid", ye++);
|
|
70
73
|
this.method = t, this.url = r, this.requestParams = n;
|
|
71
74
|
}
|
|
72
75
|
get headers() {
|
|
@@ -86,24 +89,24 @@ class X {
|
|
|
86
89
|
getBody() {
|
|
87
90
|
var n, s;
|
|
88
91
|
const t = (n = this.headers.get("Content-Type")) != null ? n : O, r = (s = this.requestParams) == null ? void 0 : s.body;
|
|
89
|
-
return r instanceof FormData ? r :
|
|
92
|
+
return r instanceof FormData ? r : fe(t) && r && typeof r == "object" ? JSON.stringify(r) : r ? `${r}` : null;
|
|
90
93
|
}
|
|
91
94
|
getHeadersInit() {
|
|
92
95
|
var r;
|
|
93
96
|
return this.headers.toHeadersInit((r = this.requestParams) == null ? void 0 : r.body);
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
|
-
var
|
|
97
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
99
|
+
var we = Object.getOwnPropertyDescriptor, me = (e, t, r, n) => {
|
|
100
|
+
for (var s = n > 1 ? void 0 : n ? we(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
98
101
|
(i = e[o]) && (s = i(s) || s);
|
|
99
102
|
return s;
|
|
100
|
-
},
|
|
101
|
-
let
|
|
103
|
+
}, ve = (e, t) => (r, n) => t(r, n, e);
|
|
104
|
+
let L = class extends z {
|
|
102
105
|
constructor(t) {
|
|
103
106
|
super();
|
|
104
|
-
|
|
107
|
+
p(this, "_interceptors", []);
|
|
105
108
|
// eslint-disable-next-line ts/no-explicit-any
|
|
106
|
-
|
|
109
|
+
p(this, "_pipe");
|
|
107
110
|
this._http = t;
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
@@ -118,7 +121,7 @@ let x = class extends K {
|
|
|
118
121
|
return this._interceptors.push(t), this._interceptors = this._interceptors.sort((r, n) => {
|
|
119
122
|
var s, o;
|
|
120
123
|
return ((s = r.priority) != null ? s : 0) - ((o = n.priority) != null ? o : 0);
|
|
121
|
-
}), this._pipe = null,
|
|
124
|
+
}), this._pipe = null, I(() => Y(this._interceptors, t));
|
|
122
125
|
}
|
|
123
126
|
get(t, r) {
|
|
124
127
|
return this.request("GET", t, r);
|
|
@@ -145,7 +148,7 @@ let x = class extends K {
|
|
|
145
148
|
*/
|
|
146
149
|
async request(t, r, n) {
|
|
147
150
|
var l, h;
|
|
148
|
-
const s = new
|
|
151
|
+
const s = new b(n == null ? void 0 : n.headers), o = new X(n == null ? void 0 : n.params), i = new V(t, r, {
|
|
149
152
|
headers: s,
|
|
150
153
|
params: o,
|
|
151
154
|
withCredentials: (l = n == null ? void 0 : n.withCredentials) != null ? l : !1,
|
|
@@ -155,7 +158,7 @@ let x = class extends K {
|
|
|
155
158
|
}), c = M(i).pipe(
|
|
156
159
|
B((a) => this._runInterceptorsAndImplementation(a))
|
|
157
160
|
);
|
|
158
|
-
return await
|
|
161
|
+
return await ae(c);
|
|
159
162
|
}
|
|
160
163
|
/**
|
|
161
164
|
* Send an HTTP request. It returns an observable that emits HTTP events. For example, it can be used to
|
|
@@ -179,13 +182,13 @@ let x = class extends K {
|
|
|
179
182
|
* @returns An observable of the HTTP event.
|
|
180
183
|
*/
|
|
181
184
|
getSSE(t, r, n) {
|
|
182
|
-
var c,
|
|
183
|
-
const s = new
|
|
185
|
+
var c, u;
|
|
186
|
+
const s = new b(n == null ? void 0 : n.headers), o = new X(n == null ? void 0 : n.params), i = new V(t, r, {
|
|
184
187
|
headers: s,
|
|
185
188
|
params: o,
|
|
186
189
|
withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
|
|
187
190
|
reportProgress: !0,
|
|
188
|
-
responseType: (
|
|
191
|
+
responseType: (u = n == null ? void 0 : n.responseType) != null ? u : "json",
|
|
189
192
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
190
193
|
});
|
|
191
194
|
return M(i).pipe(B((l) => this._runInterceptorsAndImplementation(l)));
|
|
@@ -193,7 +196,7 @@ let x = class extends K {
|
|
|
193
196
|
// eslint-disable-next-line ts/no-explicit-any
|
|
194
197
|
_runInterceptorsAndImplementation(t) {
|
|
195
198
|
return this._pipe || (this._pipe = this._interceptors.map((r) => r.interceptor).reduceRight(
|
|
196
|
-
(r, n) =>
|
|
199
|
+
(r, n) => _e(r, n),
|
|
197
200
|
(r, n) => n(r)
|
|
198
201
|
)), this._pipe(
|
|
199
202
|
t,
|
|
@@ -202,14 +205,14 @@ let x = class extends K {
|
|
|
202
205
|
);
|
|
203
206
|
}
|
|
204
207
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
],
|
|
208
|
-
function
|
|
208
|
+
L = me([
|
|
209
|
+
ve(0, Q)
|
|
210
|
+
], L);
|
|
211
|
+
function _e(e, t) {
|
|
209
212
|
return (r, n) => t(r, (s) => e(s, n));
|
|
210
213
|
}
|
|
211
|
-
const
|
|
212
|
-
var
|
|
214
|
+
const Ee = 200, Re = 300;
|
|
215
|
+
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 || {}), Z = /* @__PURE__ */ ((e) => (e[e.DownloadProgress = 0] = "DownloadProgress", e[e.Response = 1] = "Response", e))(Z || {});
|
|
213
216
|
class q {
|
|
214
217
|
constructor({
|
|
215
218
|
body: t,
|
|
@@ -217,21 +220,21 @@ class q {
|
|
|
217
220
|
status: n,
|
|
218
221
|
statusText: s
|
|
219
222
|
}) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
p(this, "type", 1);
|
|
224
|
+
p(this, "body");
|
|
225
|
+
p(this, "headers");
|
|
226
|
+
p(this, "status");
|
|
227
|
+
p(this, "statusText");
|
|
225
228
|
this.body = t, this.headers = r, this.status = n, this.statusText = s;
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
|
-
class
|
|
231
|
+
class Ie {
|
|
229
232
|
constructor(t, r, n) {
|
|
230
|
-
|
|
233
|
+
p(this, "type", 0);
|
|
231
234
|
this.total = t, this.loaded = r, this.partialText = n;
|
|
232
235
|
}
|
|
233
236
|
}
|
|
234
|
-
class
|
|
237
|
+
class be {
|
|
235
238
|
constructor(t, r, n) {
|
|
236
239
|
this.headers = t, this.status = r, this.statusText = n;
|
|
237
240
|
}
|
|
@@ -244,15 +247,15 @@ class v {
|
|
|
244
247
|
statusText: s,
|
|
245
248
|
error: o
|
|
246
249
|
}) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
p(this, "request");
|
|
251
|
+
p(this, "headers");
|
|
252
|
+
p(this, "status");
|
|
253
|
+
p(this, "statusText");
|
|
254
|
+
p(this, "error");
|
|
252
255
|
this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
|
|
253
256
|
}
|
|
254
257
|
}
|
|
255
|
-
function
|
|
258
|
+
function P(e) {
|
|
256
259
|
return {
|
|
257
260
|
method: e.method,
|
|
258
261
|
headers: e.getHeadersInit(),
|
|
@@ -260,12 +263,12 @@ function Z(e) {
|
|
|
260
263
|
credentials: e.withCredentials ? "include" : void 0
|
|
261
264
|
};
|
|
262
265
|
}
|
|
263
|
-
var
|
|
264
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
266
|
+
var xe = Object.getOwnPropertyDescriptor, Le = (e, t, r, n) => {
|
|
267
|
+
for (var s = n > 1 ? void 0 : n ? xe(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
265
268
|
(i = e[o]) && (s = i(s) || s);
|
|
266
269
|
return s;
|
|
267
|
-
},
|
|
268
|
-
let
|
|
270
|
+
}, Ne = (e, t) => (r, n) => t(r, n, e);
|
|
271
|
+
let k = class {
|
|
269
272
|
constructor(e) {
|
|
270
273
|
this._logService = e;
|
|
271
274
|
}
|
|
@@ -284,11 +287,11 @@ let N = class {
|
|
|
284
287
|
var l, h;
|
|
285
288
|
let n;
|
|
286
289
|
try {
|
|
287
|
-
const a =
|
|
290
|
+
const a = P(e), g = e.getUrlWithParams(), d = fetch(g, {
|
|
288
291
|
signal: r.signal,
|
|
289
292
|
...a
|
|
290
293
|
});
|
|
291
|
-
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${g} with params ${a}`), n = await
|
|
294
|
+
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${g} with params ${a}`), n = await d;
|
|
292
295
|
} catch (a) {
|
|
293
296
|
const g = new v({
|
|
294
297
|
request: e,
|
|
@@ -300,9 +303,9 @@ let N = class {
|
|
|
300
303
|
this._logService.error("[FetchHTTPImplementation]: network error", g), t.error(g);
|
|
301
304
|
return;
|
|
302
305
|
}
|
|
303
|
-
const s = new
|
|
306
|
+
const s = new b(n.headers), o = n.status, i = n.statusText;
|
|
304
307
|
let c = null;
|
|
305
|
-
if (n.body && (c = await this._readBody(e, n, t)), o >=
|
|
308
|
+
if (n.body && (c = await this._readBody(e, n, t)), o >= N.Ok && o < N.MultipleChoices)
|
|
306
309
|
t.next(new q({
|
|
307
310
|
body: c,
|
|
308
311
|
headers: s,
|
|
@@ -322,51 +325,51 @@ let N = class {
|
|
|
322
325
|
t.complete();
|
|
323
326
|
}
|
|
324
327
|
async _readBody(e, t, r) {
|
|
325
|
-
var g,
|
|
328
|
+
var g, d;
|
|
326
329
|
const n = [], s = t.body.getReader(), o = t.headers.get("content-length");
|
|
327
330
|
let i = 0;
|
|
328
|
-
const c = (g = e.requestParams) == null ? void 0 : g.reportProgress,
|
|
331
|
+
const c = (g = e.requestParams) == null ? void 0 : g.reportProgress, u = e.responseType;
|
|
329
332
|
let l, h;
|
|
330
333
|
for (; ; ) {
|
|
331
334
|
const { done: f, value: y } = await s.read();
|
|
332
335
|
if (f) break;
|
|
333
|
-
n.push(y), i += y.length, c &&
|
|
336
|
+
n.push(y), i += y.length, c && u === "text" && (l = (l != null ? l : "") + (h != null ? h : h = new TextDecoder()).decode(y, { stream: !0 }), r.next(new Ie(
|
|
334
337
|
o ? Number.parseInt(o, 10) : void 0,
|
|
335
338
|
i,
|
|
336
339
|
l
|
|
337
340
|
)));
|
|
338
341
|
}
|
|
339
|
-
const a =
|
|
342
|
+
const a = ke(n, i);
|
|
340
343
|
try {
|
|
341
|
-
const f = (
|
|
342
|
-
return
|
|
344
|
+
const f = (d = t.headers.get("content-type")) != null ? d : "";
|
|
345
|
+
return Fe(e, a, f);
|
|
343
346
|
} catch (f) {
|
|
344
347
|
const y = new v({
|
|
345
348
|
request: e,
|
|
346
349
|
error: f,
|
|
347
350
|
status: t.status,
|
|
348
351
|
statusText: t.statusText,
|
|
349
|
-
headers: new
|
|
352
|
+
headers: new b(t.headers)
|
|
350
353
|
});
|
|
351
354
|
return this._logService.error("[FetchHTTPImplementation]: network error", y), r.error(y), null;
|
|
352
355
|
}
|
|
353
356
|
}
|
|
354
357
|
};
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
],
|
|
358
|
-
function
|
|
358
|
+
k = Le([
|
|
359
|
+
Ne(0, $)
|
|
360
|
+
], k);
|
|
361
|
+
function ke(e, t) {
|
|
359
362
|
const r = new Uint8Array(t);
|
|
360
363
|
let n = 0;
|
|
361
364
|
for (const s of e)
|
|
362
365
|
r.set(s, n), n += s.length;
|
|
363
366
|
return r;
|
|
364
367
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
368
|
+
const Ae = /^\)\]\}',?\n/;
|
|
369
|
+
function Fe(e, t, r) {
|
|
367
370
|
switch (e.responseType) {
|
|
368
371
|
case "json":
|
|
369
|
-
const n = new TextDecoder().decode(t).replace(
|
|
372
|
+
const n = new TextDecoder().decode(t).replace(Ae, "");
|
|
370
373
|
return n === "" ? null : JSON.parse(n);
|
|
371
374
|
case "text":
|
|
372
375
|
return new TextDecoder().decode(t);
|
|
@@ -378,39 +381,39 @@ function Ne(e, t, r) {
|
|
|
378
381
|
throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
|
|
379
382
|
}
|
|
380
383
|
}
|
|
381
|
-
var
|
|
382
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
384
|
+
var Ue = Object.getOwnPropertyDescriptor, Oe = (e, t, r, n) => {
|
|
385
|
+
for (var s = n > 1 ? void 0 : n ? Ue(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
383
386
|
(i = e[o]) && (s = i(s) || s);
|
|
384
387
|
return s;
|
|
385
|
-
},
|
|
388
|
+
}, De = (e, t) => (r, n) => t(r, n, e);
|
|
386
389
|
let D = class {
|
|
387
390
|
constructor(e) {
|
|
388
391
|
this._logService = e;
|
|
389
392
|
}
|
|
390
393
|
send(e) {
|
|
391
394
|
return new m((t) => {
|
|
392
|
-
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s =
|
|
395
|
+
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = P(e), { responseType: o } = e;
|
|
393
396
|
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([h, a]) => r.setRequestHeader(h, a));
|
|
394
397
|
const i = () => {
|
|
395
|
-
const h = r.statusText || "OK", a = new
|
|
396
|
-
return new
|
|
398
|
+
const h = r.statusText || "OK", a = new b(r.getAllResponseHeaders());
|
|
399
|
+
return new be(a, r.status, h);
|
|
397
400
|
}, c = () => {
|
|
398
401
|
const { headers: h, statusText: a, status: g } = i();
|
|
399
|
-
let
|
|
400
|
-
g !==
|
|
401
|
-
let y = g >=
|
|
402
|
-
if (o === "json" && typeof
|
|
403
|
-
const w =
|
|
402
|
+
let d = null, f = null;
|
|
403
|
+
g !== N.NoContent && (d = typeof r.response > "u" ? r.responseText : r.response);
|
|
404
|
+
let y = g >= Ee && g < Re;
|
|
405
|
+
if (o === "json" && typeof d == "string") {
|
|
406
|
+
const w = d;
|
|
404
407
|
try {
|
|
405
|
-
|
|
408
|
+
d = d ? JSON.parse(d) : null;
|
|
406
409
|
} catch (_) {
|
|
407
|
-
y = !1,
|
|
410
|
+
y = !1, d = w, f = _;
|
|
408
411
|
}
|
|
409
412
|
}
|
|
410
|
-
if (o === "blob" && !(
|
|
413
|
+
if (o === "blob" && !(d instanceof Blob) && (y = !1, f = new Error("Response is not a Blob object")), y)
|
|
411
414
|
t.next(
|
|
412
415
|
new q({
|
|
413
|
-
body:
|
|
416
|
+
body: d,
|
|
414
417
|
headers: h,
|
|
415
418
|
status: g,
|
|
416
419
|
statusText: a
|
|
@@ -426,7 +429,7 @@ let D = class {
|
|
|
426
429
|
});
|
|
427
430
|
this._logService.error("[XHRHTTPImplementation]: network error", w), t.error(w);
|
|
428
431
|
}
|
|
429
|
-
},
|
|
432
|
+
}, u = (h) => {
|
|
430
433
|
const a = new v({
|
|
431
434
|
request: e,
|
|
432
435
|
error: h,
|
|
@@ -436,59 +439,59 @@ let D = class {
|
|
|
436
439
|
});
|
|
437
440
|
this._logService.error("[XHRHTTPImplementation]: network error", a), t.error(a);
|
|
438
441
|
};
|
|
439
|
-
r.responseType = o || "", r.addEventListener("load", c), r.addEventListener("error",
|
|
442
|
+
r.responseType = o || "", r.addEventListener("load", c), r.addEventListener("error", u), r.addEventListener("abort", u), r.addEventListener("timeout", u);
|
|
440
443
|
const l = e.getBody();
|
|
441
444
|
return r.send(l), this._logService.debug("[XHRHTTPImplementation]", `sending request to url ${n} with params ${s}`), () => {
|
|
442
|
-
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", c), r.removeEventListener("error",
|
|
445
|
+
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", c), r.removeEventListener("error", u), r.removeEventListener("abort", u), r.removeEventListener("timeout", u);
|
|
443
446
|
};
|
|
444
447
|
});
|
|
445
448
|
}
|
|
446
449
|
};
|
|
447
|
-
D =
|
|
448
|
-
|
|
450
|
+
D = Oe([
|
|
451
|
+
De(0, $)
|
|
449
452
|
], D);
|
|
450
|
-
var
|
|
451
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
453
|
+
var $e = Object.getOwnPropertyDescriptor, qe = (e, t, r, n) => {
|
|
454
|
+
for (var s = n > 1 ? void 0 : n ? $e(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
452
455
|
(i = e[o]) && (s = i(s) || s);
|
|
453
456
|
return s;
|
|
454
|
-
},
|
|
455
|
-
let
|
|
456
|
-
constructor(e =
|
|
457
|
+
}, U = (e, t) => (r, n) => t(r, n, e), R;
|
|
458
|
+
let J = (R = class extends re {
|
|
459
|
+
constructor(e = W, t, r, n) {
|
|
457
460
|
super(), this._config = e, this._logger = t, this._injector = r, this._configService = n;
|
|
458
|
-
const { ...s } =
|
|
461
|
+
const { ...s } = te(
|
|
459
462
|
{},
|
|
460
|
-
|
|
463
|
+
W,
|
|
461
464
|
this._config
|
|
462
465
|
);
|
|
463
|
-
this._configService.setConfig(
|
|
466
|
+
this._configService.setConfig(ge, s);
|
|
464
467
|
}
|
|
465
468
|
onStarting() {
|
|
466
469
|
var r, n, s;
|
|
467
|
-
if (this._injector.get(
|
|
470
|
+
if (this._injector.get(L, ne.OPTIONAL, se.SKIP_SELF) && !((r = this._config) != null && r.forceUseNewInstance)) {
|
|
468
471
|
this._logger.warn(
|
|
469
472
|
"[UniverNetworkPlugin]",
|
|
470
473
|
'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.'
|
|
471
474
|
);
|
|
472
475
|
return;
|
|
473
476
|
}
|
|
474
|
-
const t = (n = this._config) != null && n.useFetchImpl ?
|
|
475
|
-
|
|
476
|
-
[
|
|
477
|
-
[
|
|
477
|
+
const t = (n = this._config) != null && n.useFetchImpl ? k : typeof window < "u" ? D : k;
|
|
478
|
+
oe(this._injector, ie([
|
|
479
|
+
[L],
|
|
480
|
+
[Q, { useClass: t }]
|
|
478
481
|
], (s = this._config) == null ? void 0 : s.override));
|
|
479
482
|
}
|
|
480
|
-
},
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
],
|
|
486
|
-
const
|
|
483
|
+
}, p(R, "pluginName", "UNIVER_NETWORK_PLUGIN"), p(R, "packageName", G.name), p(R, "version", G.version), R);
|
|
484
|
+
J = qe([
|
|
485
|
+
U(1, $),
|
|
486
|
+
U(2, C(T)),
|
|
487
|
+
U(3, ee)
|
|
488
|
+
], J);
|
|
489
|
+
const Ke = (e) => {
|
|
487
490
|
const { errorStatusCodes: t, onAuthError: r } = e;
|
|
488
491
|
return (s, o) => o(s).pipe(
|
|
489
|
-
|
|
492
|
+
le((i) => (i instanceof v && t.some((c) => c === i.status) && r(), he(() => i)))
|
|
490
493
|
);
|
|
491
|
-
},
|
|
494
|
+
}, je = (e = 300) => {
|
|
492
495
|
let r = () => {
|
|
493
496
|
};
|
|
494
497
|
return (n) => new Promise((s) => {
|
|
@@ -500,8 +503,8 @@ const Xe = (e) => {
|
|
|
500
503
|
clearTimeout(o), s(!1);
|
|
501
504
|
};
|
|
502
505
|
});
|
|
503
|
-
},
|
|
504
|
-
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o =
|
|
506
|
+
}, Me = () => (e, t) => t.map((r) => ({ config: r, result: e })), ze = (e, t = {}) => {
|
|
507
|
+
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = je(300), distributeResult: i = Me() } = t, c = [], u = (l) => l.map((h) => h.config);
|
|
505
508
|
return (l, h) => r(l) ? new m((a) => {
|
|
506
509
|
const g = n(l);
|
|
507
510
|
c.push({
|
|
@@ -509,20 +512,20 @@ const Xe = (e) => {
|
|
|
509
512
|
error: (f) => a.error(f),
|
|
510
513
|
config: g
|
|
511
514
|
});
|
|
512
|
-
const
|
|
515
|
+
const d = u(c);
|
|
513
516
|
o(l).then((f) => {
|
|
514
517
|
if (f) {
|
|
515
518
|
const y = [];
|
|
516
|
-
|
|
519
|
+
d.forEach((w) => {
|
|
517
520
|
const _ = c.findIndex((E) => E.config === w);
|
|
518
521
|
if (_ >= 0) {
|
|
519
522
|
const [E] = c.splice(_, 1);
|
|
520
523
|
y.push(E);
|
|
521
524
|
}
|
|
522
|
-
}), h(s(
|
|
525
|
+
}), h(s(d, l)).subscribe({
|
|
523
526
|
next: (w) => {
|
|
524
|
-
if (w.type ===
|
|
525
|
-
const _ = w.body, E = i(_,
|
|
527
|
+
if (w.type === Z.Response) {
|
|
528
|
+
const _ = w.body, E = i(_, d);
|
|
526
529
|
y.forEach((A) => {
|
|
527
530
|
const j = E.find((F) => F.config === A.config);
|
|
528
531
|
if (j) {
|
|
@@ -544,11 +547,11 @@ const Xe = (e) => {
|
|
|
544
547
|
}
|
|
545
548
|
});
|
|
546
549
|
}) : h(l);
|
|
547
|
-
},
|
|
550
|
+
}, Be = 3, Ge = 1e3, Ye = (e) => {
|
|
548
551
|
var n, s;
|
|
549
|
-
const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n :
|
|
550
|
-
return (o, i) => i(o).pipe(
|
|
551
|
-
},
|
|
552
|
+
const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n : Be, r = (s = e == null ? void 0 : e.delayInterval) != null ? s : Ge;
|
|
553
|
+
return (o, i) => i(o).pipe(pe({ delay: r, count: t }));
|
|
554
|
+
}, Qe = (e) => {
|
|
552
555
|
const t = [], r = /* @__PURE__ */ new Set(), n = () => {
|
|
553
556
|
var s;
|
|
554
557
|
for (; r.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && t.length > 0; ) {
|
|
@@ -561,16 +564,16 @@ const Xe = (e) => {
|
|
|
561
564
|
next: (l) => i.next(l),
|
|
562
565
|
error: (l) => i.error(l),
|
|
563
566
|
complete: () => i.complete()
|
|
564
|
-
}),
|
|
565
|
-
r.delete(c),
|
|
567
|
+
}), u = () => {
|
|
568
|
+
r.delete(c), Y(t, c), n();
|
|
566
569
|
};
|
|
567
|
-
return t.push(c), n(),
|
|
570
|
+
return t.push(c), n(), u;
|
|
568
571
|
});
|
|
569
|
-
},
|
|
570
|
-
class
|
|
572
|
+
}, Ze = K("univer.network.socket.service");
|
|
573
|
+
class Pe extends z {
|
|
571
574
|
createSocket(t) {
|
|
572
575
|
try {
|
|
573
|
-
const r = new WebSocket(t), n = new
|
|
576
|
+
const r = new WebSocket(t), n = new ce();
|
|
574
577
|
return {
|
|
575
578
|
URL: t,
|
|
576
579
|
close: (o, i) => {
|
|
@@ -581,20 +584,20 @@ class Ye extends K {
|
|
|
581
584
|
},
|
|
582
585
|
open$: new m((o) => {
|
|
583
586
|
const i = (c) => o.next(c);
|
|
584
|
-
r.addEventListener("open", i), n.add(
|
|
585
|
-
}).pipe(
|
|
587
|
+
r.addEventListener("open", i), n.add(I(() => r.removeEventListener("open", i)));
|
|
588
|
+
}).pipe(x()),
|
|
586
589
|
close$: new m((o) => {
|
|
587
590
|
const i = (c) => o.next(c);
|
|
588
|
-
r.addEventListener("close", i), n.add(
|
|
589
|
-
}).pipe(
|
|
591
|
+
r.addEventListener("close", i), n.add(I(() => r.removeEventListener("close", i)));
|
|
592
|
+
}).pipe(x()),
|
|
590
593
|
error$: new m((o) => {
|
|
591
594
|
const i = (c) => o.next(c);
|
|
592
|
-
r.addEventListener("error", i), n.add(
|
|
593
|
-
}).pipe(
|
|
595
|
+
r.addEventListener("error", i), n.add(I(() => r.removeEventListener("error", i)));
|
|
596
|
+
}).pipe(x()),
|
|
594
597
|
message$: new m((o) => {
|
|
595
598
|
const i = (c) => o.next(c);
|
|
596
|
-
r.addEventListener("message", i), n.add(
|
|
597
|
-
}).pipe(
|
|
599
|
+
r.addEventListener("message", i), n.add(I(() => r.removeEventListener("message", i)));
|
|
600
|
+
}).pipe(x())
|
|
598
601
|
};
|
|
599
602
|
} catch (r) {
|
|
600
603
|
return console.error(r), null;
|
|
@@ -602,23 +605,23 @@ class Ye extends K {
|
|
|
602
605
|
}
|
|
603
606
|
}
|
|
604
607
|
export {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
608
|
+
Ke as AuthInterceptorFactory,
|
|
609
|
+
k as FetchHTTPImplementation,
|
|
610
|
+
Z as HTTPEventType,
|
|
611
|
+
b as HTTPHeaders,
|
|
612
|
+
Ie as HTTPProgress,
|
|
613
|
+
V as HTTPRequest,
|
|
611
614
|
q as HTTPResponse,
|
|
612
615
|
v as HTTPResponseError,
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
616
|
+
L as HTTPService,
|
|
617
|
+
N as HTTPStatusCode,
|
|
618
|
+
Q as IHTTPImplementation,
|
|
619
|
+
Ze as ISocketService,
|
|
620
|
+
ze as MergeInterceptorFactory,
|
|
621
|
+
be as ResponseHeader,
|
|
622
|
+
Ye as RetryInterceptorFactory,
|
|
623
|
+
Qe as ThresholdInterceptorFactory,
|
|
624
|
+
J as UniverNetworkPlugin,
|
|
625
|
+
Pe as WebSocketService,
|
|
623
626
|
D as XHRHTTPImplementation
|
|
624
627
|
};
|