@univerjs/network 0.8.2 → 0.8.3-nightly.202506271607
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 +169 -163
- package/lib/index.js +169 -163
- package/lib/types/controllers/config.schema.d.ts +22 -0
- package/lib/types/index.d.ts +10 -9
- package/lib/types/plugin.d.ts +4 -20
- package/lib/umd/index.js +2 -2
- package/package.json +4 -4
- package/LICENSE +0 -176
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (e, t, r) =>
|
|
4
|
-
import { createIdentifier as
|
|
5
|
-
import { of as
|
|
6
|
-
import { concatMap as
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
return Array.isArray(e) ? e.some((t) => t.includes(
|
|
1
|
+
var P = Object.defineProperty;
|
|
2
|
+
var S = (e, t, r) => t in e ? P(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var u = (e, t, r) => S(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { createIdentifier as J, Disposable as K, toDisposable as R, remove as z, ILogService as $, Inject as H, Injector as C, IConfigService as T, Plugin as ee, merge as re, Quantity as te, LookUp as ne, registerDependencies as se, mergeOverrideWithDependencies as oe, DisposableCollection as ie } from "@univerjs/core";
|
|
5
|
+
import { of as M, firstValueFrom as ce, Observable as m, catchError as ae, throwError as le } from "rxjs";
|
|
6
|
+
import { concatMap as B, retry as he, share as b } from "rxjs/operators";
|
|
7
|
+
const pe = "network.config", G = {}, O = "application/json";
|
|
8
|
+
function de(e) {
|
|
9
|
+
return Array.isArray(e) ? e.some((t) => t.includes(O)) : e.includes(O);
|
|
10
10
|
}
|
|
11
11
|
class I {
|
|
12
12
|
constructor(t) {
|
|
@@ -51,8 +51,8 @@ class I {
|
|
|
51
51
|
t.forEach((r, n) => this._setHeader(n, r));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const
|
|
55
|
-
class
|
|
54
|
+
const Y = J("network.http-implementation");
|
|
55
|
+
class W {
|
|
56
56
|
constructor(t) {
|
|
57
57
|
this.params = t;
|
|
58
58
|
}
|
|
@@ -63,10 +63,10 @@ class B {
|
|
|
63
63
|
}).join("&") : "";
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
let
|
|
67
|
-
class
|
|
66
|
+
let ue = 0;
|
|
67
|
+
class X {
|
|
68
68
|
constructor(t, r, n) {
|
|
69
|
-
u(this, "uid",
|
|
69
|
+
u(this, "uid", ue++);
|
|
70
70
|
this.method = t, this.url = r, this.requestParams = n;
|
|
71
71
|
}
|
|
72
72
|
get headers() {
|
|
@@ -85,20 +85,20 @@ class G {
|
|
|
85
85
|
}
|
|
86
86
|
getBody() {
|
|
87
87
|
var n, s;
|
|
88
|
-
const t = (n = this.headers.get("Content-Type")) != null ? n :
|
|
89
|
-
return r instanceof FormData ? r :
|
|
88
|
+
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 : de(t) && r && typeof r == "object" ? JSON.stringify(r) : r ? `${r}` : null;
|
|
90
90
|
}
|
|
91
91
|
getHeadersInit() {
|
|
92
92
|
var r;
|
|
93
93
|
return this.headers.toHeadersInit((r = this.requestParams) == null ? void 0 : r.body);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var
|
|
97
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
96
|
+
var ge = Object.getOwnPropertyDescriptor, fe = (e, t, r, n) => {
|
|
97
|
+
for (var s = n > 1 ? void 0 : n ? ge(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
98
98
|
(i = e[o]) && (s = i(s) || s);
|
|
99
99
|
return s;
|
|
100
|
-
},
|
|
101
|
-
let x = class extends
|
|
100
|
+
}, ye = (e, t) => (r, n) => t(r, n, e);
|
|
101
|
+
let x = class extends K {
|
|
102
102
|
constructor(t) {
|
|
103
103
|
super();
|
|
104
104
|
u(this, "_interceptors", []);
|
|
@@ -145,17 +145,17 @@ let x = class extends J {
|
|
|
145
145
|
*/
|
|
146
146
|
async request(t, r, n) {
|
|
147
147
|
var l, h;
|
|
148
|
-
const s = new I(n == null ? void 0 : n.headers), o = new
|
|
148
|
+
const s = new I(n == null ? void 0 : n.headers), o = new W(n == null ? void 0 : n.params), i = new X(t, r, {
|
|
149
149
|
headers: s,
|
|
150
150
|
params: o,
|
|
151
151
|
withCredentials: (l = n == null ? void 0 : n.withCredentials) != null ? l : !1,
|
|
152
152
|
// default value for withCredentials is false by MDN
|
|
153
153
|
responseType: (h = n == null ? void 0 : n.responseType) != null ? h : "json",
|
|
154
154
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
155
|
-
}), c =
|
|
156
|
-
|
|
155
|
+
}), c = M(i).pipe(
|
|
156
|
+
B((a) => this._runInterceptorsAndImplementation(a))
|
|
157
157
|
);
|
|
158
|
-
return await
|
|
158
|
+
return await ce(c);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Send an HTTP request. It returns an observable that emits HTTP events. For example, it can be used to
|
|
@@ -180,7 +180,7 @@ let x = class extends J {
|
|
|
180
180
|
*/
|
|
181
181
|
getSSE(t, r, n) {
|
|
182
182
|
var c, d;
|
|
183
|
-
const s = new I(n == null ? void 0 : n.headers), o = new
|
|
183
|
+
const s = new I(n == null ? void 0 : n.headers), o = new W(n == null ? void 0 : n.params), i = new X(t, r, {
|
|
184
184
|
headers: s,
|
|
185
185
|
params: o,
|
|
186
186
|
withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
|
|
@@ -188,12 +188,12 @@ let x = class extends J {
|
|
|
188
188
|
responseType: (d = n == null ? void 0 : n.responseType) != null ? d : "json",
|
|
189
189
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
190
190
|
});
|
|
191
|
-
return
|
|
191
|
+
return M(i).pipe(B((l) => this._runInterceptorsAndImplementation(l)));
|
|
192
192
|
}
|
|
193
193
|
// eslint-disable-next-line ts/no-explicit-any
|
|
194
194
|
_runInterceptorsAndImplementation(t) {
|
|
195
195
|
return this._pipe || (this._pipe = this._interceptors.map((r) => r.interceptor).reduceRight(
|
|
196
|
-
(r, n) =>
|
|
196
|
+
(r, n) => we(r, n),
|
|
197
197
|
(r, n) => n(r)
|
|
198
198
|
)), this._pipe(
|
|
199
199
|
t,
|
|
@@ -202,15 +202,15 @@ let x = class extends J {
|
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
|
-
x =
|
|
206
|
-
|
|
205
|
+
x = fe([
|
|
206
|
+
ye(0, Y)
|
|
207
207
|
], x);
|
|
208
|
-
function
|
|
208
|
+
function we(e, t) {
|
|
209
209
|
return (r, n) => t(r, (s) => e(s, n));
|
|
210
210
|
}
|
|
211
|
-
const
|
|
212
|
-
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 || {}),
|
|
213
|
-
class
|
|
211
|
+
const me = 200, ve = 300;
|
|
212
|
+
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 || {}), Q = /* @__PURE__ */ ((e) => (e[e.DownloadProgress = 0] = "DownloadProgress", e[e.Response = 1] = "Response", e))(Q || {});
|
|
213
|
+
class q {
|
|
214
214
|
constructor({
|
|
215
215
|
body: t,
|
|
216
216
|
headers: r,
|
|
@@ -225,13 +225,13 @@ class $ {
|
|
|
225
225
|
this.body = t, this.headers = r, this.status = n, this.statusText = s;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
class
|
|
228
|
+
class _e {
|
|
229
229
|
constructor(t, r, n) {
|
|
230
230
|
u(this, "type", 0);
|
|
231
231
|
this.total = t, this.loaded = r, this.partialText = n;
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
class
|
|
234
|
+
class Ee {
|
|
235
235
|
constructor(t, r, n) {
|
|
236
236
|
this.headers = t, this.status = r, this.statusText = n;
|
|
237
237
|
}
|
|
@@ -252,7 +252,7 @@ class v {
|
|
|
252
252
|
this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function Z(e) {
|
|
256
256
|
return {
|
|
257
257
|
method: e.method,
|
|
258
258
|
headers: e.getHeadersInit(),
|
|
@@ -260,11 +260,11 @@ function Q(e) {
|
|
|
260
260
|
credentials: e.withCredentials ? "include" : void 0
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
|
-
var
|
|
264
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
263
|
+
var Re = Object.getOwnPropertyDescriptor, Ie = (e, t, r, n) => {
|
|
264
|
+
for (var s = n > 1 ? void 0 : n ? Re(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
265
265
|
(i = e[o]) && (s = i(s) || s);
|
|
266
266
|
return s;
|
|
267
|
-
},
|
|
267
|
+
}, be = (e, t) => (r, n) => t(r, n, e);
|
|
268
268
|
let N = class {
|
|
269
269
|
constructor(e) {
|
|
270
270
|
this._logService = e;
|
|
@@ -284,7 +284,7 @@ let N = class {
|
|
|
284
284
|
var l, h;
|
|
285
285
|
let n;
|
|
286
286
|
try {
|
|
287
|
-
const a =
|
|
287
|
+
const a = Z(e), g = e.getUrlWithParams(), p = fetch(g, {
|
|
288
288
|
signal: r.signal,
|
|
289
289
|
...a
|
|
290
290
|
});
|
|
@@ -303,7 +303,7 @@ let N = class {
|
|
|
303
303
|
const s = new I(n.headers), o = n.status, i = n.statusText;
|
|
304
304
|
let c = null;
|
|
305
305
|
if (n.body && (c = await this._readBody(e, n, t)), o >= L.Ok && o < L.MultipleChoices)
|
|
306
|
-
t.next(new
|
|
306
|
+
t.next(new q({
|
|
307
307
|
body: c,
|
|
308
308
|
headers: s,
|
|
309
309
|
status: o,
|
|
@@ -330,16 +330,16 @@ let N = class {
|
|
|
330
330
|
for (; ; ) {
|
|
331
331
|
const { done: f, value: y } = await s.read();
|
|
332
332
|
if (f) break;
|
|
333
|
-
n.push(y), i += y.length, c && d === "text" && (l = (l != null ? l : "") + (h != null ? h : h = new TextDecoder()).decode(y, { stream: !0 }), r.next(new
|
|
333
|
+
n.push(y), i += y.length, c && d === "text" && (l = (l != null ? l : "") + (h != null ? h : h = new TextDecoder()).decode(y, { stream: !0 }), r.next(new _e(
|
|
334
334
|
o ? Number.parseInt(o, 10) : void 0,
|
|
335
335
|
i,
|
|
336
336
|
l
|
|
337
337
|
)));
|
|
338
338
|
}
|
|
339
|
-
const a =
|
|
339
|
+
const a = xe(n, i);
|
|
340
340
|
try {
|
|
341
341
|
const f = (p = t.headers.get("content-type")) != null ? p : "";
|
|
342
|
-
return
|
|
342
|
+
return Ne(e, a, f);
|
|
343
343
|
} catch (f) {
|
|
344
344
|
const y = new v({
|
|
345
345
|
request: e,
|
|
@@ -352,21 +352,21 @@ let N = class {
|
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
|
-
N =
|
|
356
|
-
|
|
355
|
+
N = Ie([
|
|
356
|
+
be(0, $)
|
|
357
357
|
], N);
|
|
358
|
-
function
|
|
358
|
+
function xe(e, t) {
|
|
359
359
|
const r = new Uint8Array(t);
|
|
360
360
|
let n = 0;
|
|
361
361
|
for (const s of e)
|
|
362
362
|
r.set(s, n), n += s.length;
|
|
363
363
|
return r;
|
|
364
364
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
365
|
+
const Le = /^\)\]\}',?\n/;
|
|
366
|
+
function Ne(e, t, r) {
|
|
367
367
|
switch (e.responseType) {
|
|
368
368
|
case "json":
|
|
369
|
-
const n = new TextDecoder().decode(t).replace(
|
|
369
|
+
const n = new TextDecoder().decode(t).replace(Le, "");
|
|
370
370
|
return n === "" ? null : JSON.parse(n);
|
|
371
371
|
case "text":
|
|
372
372
|
return new TextDecoder().decode(t);
|
|
@@ -378,38 +378,38 @@ function Ie(e, t, r) {
|
|
|
378
378
|
throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
var
|
|
382
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
381
|
+
var Ae = Object.getOwnPropertyDescriptor, Fe = (e, t, r, n) => {
|
|
382
|
+
for (var s = n > 1 ? void 0 : n ? Ae(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
383
383
|
(i = e[o]) && (s = i(s) || s);
|
|
384
384
|
return s;
|
|
385
|
-
},
|
|
386
|
-
let
|
|
385
|
+
}, ke = (e, t) => (r, n) => t(r, n, e);
|
|
386
|
+
let D = class {
|
|
387
387
|
constructor(e) {
|
|
388
388
|
this._logService = e;
|
|
389
389
|
}
|
|
390
390
|
send(e) {
|
|
391
391
|
return new m((t) => {
|
|
392
|
-
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s =
|
|
392
|
+
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Z(e), { responseType: o } = e;
|
|
393
393
|
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([h, a]) => r.setRequestHeader(h, a));
|
|
394
394
|
const i = () => {
|
|
395
395
|
const h = r.statusText || "OK", a = new I(r.getAllResponseHeaders());
|
|
396
|
-
return new
|
|
396
|
+
return new Ee(a, r.status, h);
|
|
397
397
|
}, c = () => {
|
|
398
398
|
const { headers: h, statusText: a, status: g } = i();
|
|
399
399
|
let p = null, f = null;
|
|
400
400
|
g !== L.NoContent && (p = typeof r.response > "u" ? r.responseText : r.response);
|
|
401
|
-
let y = g >=
|
|
401
|
+
let y = g >= me && g < ve;
|
|
402
402
|
if (o === "json" && typeof p == "string") {
|
|
403
403
|
const w = p;
|
|
404
404
|
try {
|
|
405
405
|
p = p ? JSON.parse(p) : null;
|
|
406
|
-
} catch (
|
|
407
|
-
y = !1, p = w, f =
|
|
406
|
+
} catch (_) {
|
|
407
|
+
y = !1, p = w, f = _;
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
if (o === "blob" && !(p instanceof Blob) && (y = !1, f = new Error("Response is not a Blob object")), y)
|
|
411
411
|
t.next(
|
|
412
|
-
new
|
|
412
|
+
new q({
|
|
413
413
|
body: p,
|
|
414
414
|
headers: h,
|
|
415
415
|
status: g,
|
|
@@ -444,101 +444,51 @@ let O = class {
|
|
|
444
444
|
});
|
|
445
445
|
}
|
|
446
446
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
],
|
|
450
|
-
var
|
|
451
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
447
|
+
D = Fe([
|
|
448
|
+
ke(0, $)
|
|
449
|
+
], D);
|
|
450
|
+
var Ue = Object.getOwnPropertyDescriptor, Oe = (e, t, r, n) => {
|
|
451
|
+
for (var s = n > 1 ? void 0 : n ? Ue(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
452
452
|
(i = e[o]) && (s = i(s) || s);
|
|
453
453
|
return s;
|
|
454
|
-
},
|
|
455
|
-
let
|
|
456
|
-
constructor(e =
|
|
457
|
-
super(), this._config = e, this._logger = t, this._injector = r;
|
|
454
|
+
}, k = (e, t) => (r, n) => t(r, n, e), U;
|
|
455
|
+
let V = (U = class extends ee {
|
|
456
|
+
constructor(e = G, t, r, n) {
|
|
457
|
+
super(), this._config = e, this._logger = t, this._injector = r, this._configService = n;
|
|
458
|
+
const { ...s } = re(
|
|
459
|
+
{},
|
|
460
|
+
G,
|
|
461
|
+
this._config
|
|
462
|
+
);
|
|
463
|
+
this._configService.setConfig(pe, s);
|
|
458
464
|
}
|
|
459
465
|
onStarting() {
|
|
460
466
|
var r, n, s;
|
|
461
|
-
if (this._injector.get(x,
|
|
467
|
+
if (this._injector.get(x, te.OPTIONAL, ne.SKIP_SELF) && !((r = this._config) != null && r.forceUseNewInstance)) {
|
|
462
468
|
this._logger.warn(
|
|
463
469
|
"[UniverNetworkPlugin]",
|
|
464
470
|
'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.'
|
|
465
471
|
);
|
|
466
472
|
return;
|
|
467
473
|
}
|
|
468
|
-
const t = (n = this._config) != null && n.useFetchImpl ? N : typeof window < "u" ?
|
|
469
|
-
|
|
474
|
+
const t = (n = this._config) != null && n.useFetchImpl ? N : typeof window < "u" ? D : N;
|
|
475
|
+
se(this._injector, oe([
|
|
470
476
|
[x],
|
|
471
|
-
[
|
|
477
|
+
[Y, { useClass: t }]
|
|
472
478
|
], (s = this._config) == null ? void 0 : s.override));
|
|
473
479
|
}
|
|
474
|
-
}, u(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
createSocket(t) {
|
|
482
|
-
try {
|
|
483
|
-
const r = new WebSocket(t), n = new ne();
|
|
484
|
-
return {
|
|
485
|
-
URL: t,
|
|
486
|
-
close: (o, i) => {
|
|
487
|
-
r.close(o, i), n.dispose();
|
|
488
|
-
},
|
|
489
|
-
send: (o) => {
|
|
490
|
-
r.send(o);
|
|
491
|
-
},
|
|
492
|
-
open$: new m((o) => {
|
|
493
|
-
const i = (c) => o.next(c);
|
|
494
|
-
r.addEventListener("open", i), n.add(R(() => r.removeEventListener("open", i)));
|
|
495
|
-
}).pipe(b()),
|
|
496
|
-
close$: new m((o) => {
|
|
497
|
-
const i = (c) => o.next(c);
|
|
498
|
-
r.addEventListener("close", i), n.add(R(() => r.removeEventListener("close", i)));
|
|
499
|
-
}).pipe(b()),
|
|
500
|
-
error$: new m((o) => {
|
|
501
|
-
const i = (c) => o.next(c);
|
|
502
|
-
r.addEventListener("error", i), n.add(R(() => r.removeEventListener("error", i)));
|
|
503
|
-
}).pipe(b()),
|
|
504
|
-
message$: new m((o) => {
|
|
505
|
-
const i = (c) => o.next(c);
|
|
506
|
-
r.addEventListener("message", i), n.add(R(() => r.removeEventListener("message", i)));
|
|
507
|
-
}).pipe(b())
|
|
508
|
-
};
|
|
509
|
-
} catch (r) {
|
|
510
|
-
return console.error(r), null;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
515
|
-
var n, s;
|
|
516
|
-
const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n : Fe, r = (s = e == null ? void 0 : e.delayInterval) != null ? s : ke;
|
|
517
|
-
return (o, i) => i(o).pipe(ce({ delay: r, count: t }));
|
|
518
|
-
}, We = (e) => {
|
|
519
|
-
const t = [], r = /* @__PURE__ */ new Set(), n = () => {
|
|
520
|
-
var s;
|
|
521
|
-
for (; r.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && t.length > 0; ) {
|
|
522
|
-
const o = t.shift();
|
|
523
|
-
r.add(o), o();
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
return (s, o) => new m((i) => {
|
|
527
|
-
const c = () => o(s).subscribe({
|
|
528
|
-
next: (l) => i.next(l),
|
|
529
|
-
error: (l) => i.error(l),
|
|
530
|
-
complete: () => i.complete()
|
|
531
|
-
}), d = () => {
|
|
532
|
-
r.delete(c), z(t, c), n();
|
|
533
|
-
};
|
|
534
|
-
return t.push(c), n(), d;
|
|
535
|
-
});
|
|
536
|
-
}, Xe = (e) => {
|
|
480
|
+
}, u(U, "pluginName", "UNIVER_NETWORK_PLUGIN"), U);
|
|
481
|
+
V = Oe([
|
|
482
|
+
k(1, $),
|
|
483
|
+
k(2, H(C)),
|
|
484
|
+
k(3, T)
|
|
485
|
+
], V);
|
|
486
|
+
const Xe = (e) => {
|
|
537
487
|
const { errorStatusCodes: t, onAuthError: r } = e;
|
|
538
488
|
return (s, o) => o(s).pipe(
|
|
539
|
-
|
|
489
|
+
ae((i) => (i instanceof v && t.some((c) => c === i.status) && r(), le(() => i)))
|
|
540
490
|
);
|
|
541
|
-
},
|
|
491
|
+
}, De = (e = 300) => {
|
|
542
492
|
let r = () => {
|
|
543
493
|
};
|
|
544
494
|
return (n) => new Promise((s) => {
|
|
@@ -550,8 +500,8 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
550
500
|
clearTimeout(o), s(!1);
|
|
551
501
|
};
|
|
552
502
|
});
|
|
553
|
-
},
|
|
554
|
-
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o =
|
|
503
|
+
}, $e = () => (e, t) => t.map((r) => ({ config: r, result: e })), Ve = (e, t = {}) => {
|
|
504
|
+
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = De(300), distributeResult: i = $e() } = t, c = [], d = (l) => l.map((h) => h.config);
|
|
555
505
|
return (l, h) => r(l) ? new m((a) => {
|
|
556
506
|
const g = n(l);
|
|
557
507
|
c.push({
|
|
@@ -564,20 +514,20 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
564
514
|
if (f) {
|
|
565
515
|
const y = [];
|
|
566
516
|
p.forEach((w) => {
|
|
567
|
-
const
|
|
568
|
-
if (
|
|
569
|
-
const [
|
|
570
|
-
y.push(
|
|
517
|
+
const _ = c.findIndex((E) => E.config === w);
|
|
518
|
+
if (_ >= 0) {
|
|
519
|
+
const [E] = c.splice(_, 1);
|
|
520
|
+
y.push(E);
|
|
571
521
|
}
|
|
572
522
|
}), h(s(p, l)).subscribe({
|
|
573
523
|
next: (w) => {
|
|
574
|
-
if (w.type ===
|
|
575
|
-
const
|
|
524
|
+
if (w.type === Q.Response) {
|
|
525
|
+
const _ = w.body, E = i(_, p);
|
|
576
526
|
y.forEach((A) => {
|
|
577
|
-
const
|
|
578
|
-
if (
|
|
579
|
-
const F = new
|
|
580
|
-
body:
|
|
527
|
+
const j = E.find((F) => F.config === A.config);
|
|
528
|
+
if (j) {
|
|
529
|
+
const F = new q({
|
|
530
|
+
body: j.result,
|
|
581
531
|
headers: w.headers,
|
|
582
532
|
status: w.status,
|
|
583
533
|
statusText: w.statusText
|
|
@@ -594,25 +544,81 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
594
544
|
}
|
|
595
545
|
});
|
|
596
546
|
}) : h(l);
|
|
597
|
-
}
|
|
547
|
+
}, qe = 3, je = 1e3, Je = (e) => {
|
|
548
|
+
var n, s;
|
|
549
|
+
const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n : qe, r = (s = e == null ? void 0 : e.delayInterval) != null ? s : je;
|
|
550
|
+
return (o, i) => i(o).pipe(he({ delay: r, count: t }));
|
|
551
|
+
}, Ke = (e) => {
|
|
552
|
+
const t = [], r = /* @__PURE__ */ new Set(), n = () => {
|
|
553
|
+
var s;
|
|
554
|
+
for (; r.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && t.length > 0; ) {
|
|
555
|
+
const o = t.shift();
|
|
556
|
+
r.add(o), o();
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
return (s, o) => new m((i) => {
|
|
560
|
+
const c = () => o(s).subscribe({
|
|
561
|
+
next: (l) => i.next(l),
|
|
562
|
+
error: (l) => i.error(l),
|
|
563
|
+
complete: () => i.complete()
|
|
564
|
+
}), d = () => {
|
|
565
|
+
r.delete(c), z(t, c), n();
|
|
566
|
+
};
|
|
567
|
+
return t.push(c), n(), d;
|
|
568
|
+
});
|
|
569
|
+
}, ze = J("univer.network.socket.service");
|
|
570
|
+
class Ye extends K {
|
|
571
|
+
createSocket(t) {
|
|
572
|
+
try {
|
|
573
|
+
const r = new WebSocket(t), n = new ie();
|
|
574
|
+
return {
|
|
575
|
+
URL: t,
|
|
576
|
+
close: (o, i) => {
|
|
577
|
+
r.close(o, i), n.dispose();
|
|
578
|
+
},
|
|
579
|
+
send: (o) => {
|
|
580
|
+
r.send(o);
|
|
581
|
+
},
|
|
582
|
+
open$: new m((o) => {
|
|
583
|
+
const i = (c) => o.next(c);
|
|
584
|
+
r.addEventListener("open", i), n.add(R(() => r.removeEventListener("open", i)));
|
|
585
|
+
}).pipe(b()),
|
|
586
|
+
close$: new m((o) => {
|
|
587
|
+
const i = (c) => o.next(c);
|
|
588
|
+
r.addEventListener("close", i), n.add(R(() => r.removeEventListener("close", i)));
|
|
589
|
+
}).pipe(b()),
|
|
590
|
+
error$: new m((o) => {
|
|
591
|
+
const i = (c) => o.next(c);
|
|
592
|
+
r.addEventListener("error", i), n.add(R(() => r.removeEventListener("error", i)));
|
|
593
|
+
}).pipe(b()),
|
|
594
|
+
message$: new m((o) => {
|
|
595
|
+
const i = (c) => o.next(c);
|
|
596
|
+
r.addEventListener("message", i), n.add(R(() => r.removeEventListener("message", i)));
|
|
597
|
+
}).pipe(b())
|
|
598
|
+
};
|
|
599
|
+
} catch (r) {
|
|
600
|
+
return console.error(r), null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
598
604
|
export {
|
|
599
605
|
Xe as AuthInterceptorFactory,
|
|
600
606
|
N as FetchHTTPImplementation,
|
|
601
|
-
|
|
607
|
+
Q as HTTPEventType,
|
|
602
608
|
I as HTTPHeaders,
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
609
|
+
_e as HTTPProgress,
|
|
610
|
+
X as HTTPRequest,
|
|
611
|
+
q as HTTPResponse,
|
|
606
612
|
v as HTTPResponseError,
|
|
607
613
|
x as HTTPService,
|
|
608
614
|
L as HTTPStatusCode,
|
|
609
|
-
|
|
610
|
-
|
|
615
|
+
Y as IHTTPImplementation,
|
|
616
|
+
ze as ISocketService,
|
|
611
617
|
Ve as MergeInterceptorFactory,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
+
Ee as ResponseHeader,
|
|
619
|
+
Je as RetryInterceptorFactory,
|
|
620
|
+
Ke as ThresholdInterceptorFactory,
|
|
621
|
+
V as UniverNetworkPlugin,
|
|
622
|
+
Ye as WebSocketService,
|
|
623
|
+
D as XHRHTTPImplementation
|
|
618
624
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DependencyOverride } from '@univerjs/core';
|
|
2
|
+
export declare const NETWORK_PLUGIN_CONFIG_KEY = "network.config";
|
|
3
|
+
export declare const configSymbol: unique symbol;
|
|
4
|
+
export interface IUniverNetworkConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Use fetch instead of XMLHttpRequest. By default, Univer will use fetch on Node.js and XMLHttpRequest in browser.
|
|
7
|
+
*/
|
|
8
|
+
useFetchImpl?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Build in dependencies that can be overridden:
|
|
11
|
+
*
|
|
12
|
+
* - {@link HTTPService}
|
|
13
|
+
* - {@link IHTTPImplementation}
|
|
14
|
+
*/
|
|
15
|
+
override?: DependencyOverride;
|
|
16
|
+
/**
|
|
17
|
+
* Force to use a new instance of {@link HTTPService} and {@link IHTTPImplementation} even if
|
|
18
|
+
* an ancestor injector already has them registered.
|
|
19
|
+
*/
|
|
20
|
+
forceUseNewInstance?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const defaultPluginConfig: IUniverNetworkConfig;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,19 +13,20 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export type { IUniverNetworkConfig } from './controllers/config.schema';
|
|
17
|
+
export { UniverNetworkPlugin } from './plugin';
|
|
17
18
|
export { HTTPHeaders } from './services/http/headers';
|
|
19
|
+
export { type HTTPResponseType, HTTPStatusCode } from './services/http/http';
|
|
18
20
|
export { HTTPService } from './services/http/http.service';
|
|
19
|
-
export {
|
|
21
|
+
export type { IPostRequestParams, IRequestParams } from './services/http/http.service';
|
|
20
22
|
export { FetchHTTPImplementation } from './services/http/implementations/fetch';
|
|
23
|
+
export { IHTTPImplementation } from './services/http/implementations/implementation';
|
|
21
24
|
export { XHRHTTPImplementation } from './services/http/implementations/xhr';
|
|
22
|
-
export { HTTPRequest, type HTTPRequestMethod } from './services/http/request';
|
|
23
|
-
export { type HTTPResponseType, HTTPStatusCode } from './services/http/http';
|
|
24
|
-
export { type HTTPEvent, HTTPEventType, HTTPProgress, HTTPResponse, type HTTPResponseBody, HTTPResponseError, ResponseHeader, } from './services/http/response';
|
|
25
|
-
export { type ISocket, ISocketService, type SocketBodyType, WebSocketService, } from './services/web-socket/web-socket.service';
|
|
26
|
-
export type { IPostRequestParams, IRequestParams } from './services/http/http.service';
|
|
27
25
|
export type { HTTPHandlerFn, HTTPInterceptorFn, HTTPInterceptorFnFactory } from './services/http/interceptor';
|
|
28
|
-
export { type IRetryInterceptorFactoryParams, RetryInterceptorFactory } from './services/http/interceptors/retry-interceptor';
|
|
29
|
-
export { ThresholdInterceptorFactory } from './services/http/interceptors/threshold-interceptor';
|
|
30
26
|
export { AuthInterceptorFactory, type IAuthInterceptorParams } from './services/http/interceptors/auth-interceptor';
|
|
31
27
|
export { MergeInterceptorFactory } from './services/http/interceptors/merge-interceptor';
|
|
28
|
+
export { type IRetryInterceptorFactoryParams, RetryInterceptorFactory } from './services/http/interceptors/retry-interceptor';
|
|
29
|
+
export { ThresholdInterceptorFactory } from './services/http/interceptors/threshold-interceptor';
|
|
30
|
+
export { HTTPRequest, type HTTPRequestMethod } from './services/http/request';
|
|
31
|
+
export { type HTTPEvent, HTTPEventType, HTTPProgress, HTTPResponse, type HTTPResponseBody, HTTPResponseError, ResponseHeader, } from './services/http/response';
|
|
32
|
+
export { type ISocket, ISocketService, type SocketBodyType, WebSocketService, } from './services/web-socket/web-socket.service';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Use fetch instead of XMLHttpRequest. By default, Univer will use fetch on Node.js and XMLHttpRequest in browser.
|
|
5
|
-
*/
|
|
6
|
-
useFetchImpl?: boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Build in dependencies that can be overridden:
|
|
9
|
-
*
|
|
10
|
-
* - {@link HTTPService}
|
|
11
|
-
* - {@link IHTTPImplementation}
|
|
12
|
-
*/
|
|
13
|
-
override?: DependencyOverride;
|
|
14
|
-
/**
|
|
15
|
-
* Force to use a new instance of {@link HTTPService} and {@link IHTTPImplementation} even if
|
|
16
|
-
* an ancestor injector already has them registered.
|
|
17
|
-
*/
|
|
18
|
-
forceUseNewInstance?: boolean;
|
|
19
|
-
}
|
|
1
|
+
import { IUniverNetworkConfig } from './controllers/config.schema';
|
|
2
|
+
import { IConfigService, ILogService, Injector, Plugin } from '@univerjs/core';
|
|
20
3
|
/**
|
|
21
4
|
* This plugin add network services to the Univer instance.
|
|
22
5
|
*/
|
|
@@ -24,7 +7,8 @@ export declare class UniverNetworkPlugin extends Plugin {
|
|
|
24
7
|
private readonly _config;
|
|
25
8
|
private readonly _logger;
|
|
26
9
|
protected readonly _injector: Injector;
|
|
10
|
+
private readonly _configService;
|
|
27
11
|
static pluginName: string;
|
|
28
|
-
constructor(_config: Partial<
|
|
12
|
+
constructor(_config: Partial<IUniverNetworkConfig> | undefined, _logger: ILogService, _injector: Injector, _configService: IConfigService);
|
|
29
13
|
onStarting(): void;
|
|
30
14
|
}
|