@univerjs/network 0.8.0 → 0.8.1-nightly.202506131607
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 +171 -143
- package/lib/index.js +171 -143
- package/lib/types/services/http/http.service.d.ts +34 -8
- package/lib/umd/index.js +2 -2
- package/package.json +3 -3
- package/LICENSE +0 -176
package/lib/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var Z = Object.defineProperty;
|
|
2
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
|
|
3
|
+
var u = (e, t, r) => P(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { createIdentifier as V, Disposable as J, toDisposable as R, remove as z, ILogService as D, 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
|
|
6
|
-
import { concatMap as
|
|
5
|
+
import { of as j, firstValueFrom as se, Observable as m, catchError as oe, throwError as ie } from "rxjs";
|
|
6
|
+
import { concatMap as M, share as b, retry as ce } from "rxjs/operators";
|
|
7
7
|
const U = "application/json";
|
|
8
8
|
function ae(e) {
|
|
9
9
|
return Array.isArray(e) ? e.some((t) => t.includes(U)) : e.includes(U);
|
|
10
10
|
}
|
|
11
11
|
class I {
|
|
12
12
|
constructor(t) {
|
|
13
|
-
|
|
13
|
+
u(this, "_headers", /* @__PURE__ */ new Map());
|
|
14
14
|
typeof t == "string" ? this._handleHeadersString(t) : t instanceof Headers ? this._handleHeaders(t) : t && this._handleHeadersConstructorProps(t);
|
|
15
15
|
}
|
|
16
16
|
forEach(t) {
|
|
@@ -66,7 +66,7 @@ class B {
|
|
|
66
66
|
let le = 0;
|
|
67
67
|
class G {
|
|
68
68
|
constructor(t, r, n) {
|
|
69
|
-
|
|
69
|
+
u(this, "uid", le++);
|
|
70
70
|
this.method = t, this.url = r, this.requestParams = n;
|
|
71
71
|
}
|
|
72
72
|
get headers() {
|
|
@@ -93,17 +93,17 @@ class G {
|
|
|
93
93
|
return this.headers.toHeadersInit((r = this.requestParams) == null ? void 0 : r.body);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var he = Object.getOwnPropertyDescriptor,
|
|
96
|
+
var he = Object.getOwnPropertyDescriptor, pe = (e, t, r, n) => {
|
|
97
97
|
for (var s = n > 1 ? void 0 : n ? he(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
|
-
},
|
|
100
|
+
}, de = (e, t) => (r, n) => t(r, n, e);
|
|
101
101
|
let x = class extends J {
|
|
102
102
|
constructor(t) {
|
|
103
103
|
super();
|
|
104
|
-
|
|
104
|
+
u(this, "_interceptors", []);
|
|
105
105
|
// eslint-disable-next-line ts/no-explicit-any
|
|
106
|
-
|
|
106
|
+
u(this, "_pipe");
|
|
107
107
|
this._http = t;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
@@ -121,46 +121,74 @@ let x = class extends J {
|
|
|
121
121
|
}), this._pipe = null, R(() => z(this._interceptors, t));
|
|
122
122
|
}
|
|
123
123
|
get(t, r) {
|
|
124
|
-
return this.
|
|
124
|
+
return this.request("GET", t, r);
|
|
125
125
|
}
|
|
126
126
|
post(t, r) {
|
|
127
|
-
return this.
|
|
127
|
+
return this.request("POST", t, r);
|
|
128
128
|
}
|
|
129
129
|
put(t, r) {
|
|
130
|
-
return this.
|
|
130
|
+
return this.request("PUT", t, r);
|
|
131
131
|
}
|
|
132
132
|
delete(t, r) {
|
|
133
|
-
return this.
|
|
133
|
+
return this.request("DELETE", t, r);
|
|
134
134
|
}
|
|
135
135
|
patch(t, r) {
|
|
136
|
-
return this.
|
|
136
|
+
return this.request("PATCH", t, r);
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
/**
|
|
139
|
+
* The HTTP request implementations. Normally you should use the `get`, `post`, `put`, `delete`,
|
|
140
|
+
* `patch` methods instead.
|
|
141
|
+
* @param method HTTP request method, e.g. GET, POST, PUT, DELETE, etc.
|
|
142
|
+
* @param url The URL to send the request to.
|
|
143
|
+
* @param options Optional parameters for the request.
|
|
144
|
+
* @returns A promise that resolves to the HTTP response.
|
|
145
|
+
*/
|
|
146
|
+
async request(t, r, n) {
|
|
147
|
+
var l, h;
|
|
140
148
|
const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
|
|
141
149
|
headers: s,
|
|
142
150
|
params: o,
|
|
143
|
-
withCredentials: (
|
|
144
|
-
|
|
145
|
-
responseType: (
|
|
151
|
+
withCredentials: (l = n == null ? void 0 : n.withCredentials) != null ? l : !1,
|
|
152
|
+
// default value for withCredentials is false by MDN
|
|
153
|
+
responseType: (h = n == null ? void 0 : n.responseType) != null ? h : "json",
|
|
146
154
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
147
|
-
})
|
|
148
|
-
|
|
155
|
+
}), c = j(i).pipe(
|
|
156
|
+
M((a) => this._runInterceptorsAndImplementation(a))
|
|
157
|
+
);
|
|
158
|
+
return await se(c);
|
|
149
159
|
}
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Send an HTTP request. It returns an observable that emits HTTP events. For example, it can be used to
|
|
162
|
+
* send Server-Sent Events (SSE) requests.
|
|
163
|
+
* @deprecated Please use `stream` method instead.
|
|
164
|
+
* @param method HTTP request method, e.g. GET, POST, PUT, DELETE, etc.
|
|
165
|
+
* @param url The URL to send the request to.
|
|
166
|
+
* @param _params Optional parameters for the request.
|
|
167
|
+
* @returns An observable of the HTTP event.
|
|
168
|
+
*/
|
|
169
|
+
stream(t, r, n) {
|
|
170
|
+
return this.getSSE(t, r, n);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Send a Server-Sent Events (SSE) request. It returns an observable that emits HTTP events. It is the observable
|
|
174
|
+
* pair of the `request` method.
|
|
175
|
+
* @deprecated Please use `stream` method instead.
|
|
176
|
+
* @param method HTTP request method, e.g. GET, POST, PUT, DELETE, etc.
|
|
177
|
+
* @param url The URL to send the request to.
|
|
178
|
+
* @param _params Optional parameters for the request.
|
|
179
|
+
* @returns An observable of the HTTP event.
|
|
180
|
+
*/
|
|
181
|
+
getSSE(t, r, n) {
|
|
182
|
+
var c, d;
|
|
153
183
|
const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
|
|
154
184
|
headers: s,
|
|
155
185
|
params: o,
|
|
156
|
-
withCredentials: (
|
|
157
|
-
|
|
158
|
-
responseType: (
|
|
186
|
+
withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
|
|
187
|
+
reportProgress: !0,
|
|
188
|
+
responseType: (d = n == null ? void 0 : n.responseType) != null ? d : "json",
|
|
159
189
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
);
|
|
163
|
-
return await se(c);
|
|
190
|
+
});
|
|
191
|
+
return j(i).pipe(M((l) => this._runInterceptorsAndImplementation(l)));
|
|
164
192
|
}
|
|
165
193
|
// eslint-disable-next-line ts/no-explicit-any
|
|
166
194
|
_runInterceptorsAndImplementation(t) {
|
|
@@ -174,8 +202,8 @@ let x = class extends J {
|
|
|
174
202
|
);
|
|
175
203
|
}
|
|
176
204
|
};
|
|
177
|
-
x =
|
|
178
|
-
|
|
205
|
+
x = pe([
|
|
206
|
+
de(0, K)
|
|
179
207
|
], x);
|
|
180
208
|
function ue(e, t) {
|
|
181
209
|
return (r, n) => t(r, (s) => e(s, n));
|
|
@@ -189,17 +217,17 @@ class $ {
|
|
|
189
217
|
status: n,
|
|
190
218
|
statusText: s
|
|
191
219
|
}) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
220
|
+
u(this, "type", 1);
|
|
221
|
+
u(this, "body");
|
|
222
|
+
u(this, "headers");
|
|
223
|
+
u(this, "status");
|
|
224
|
+
u(this, "statusText");
|
|
197
225
|
this.body = t, this.headers = r, this.status = n, this.statusText = s;
|
|
198
226
|
}
|
|
199
227
|
}
|
|
200
228
|
class ye {
|
|
201
229
|
constructor(t, r, n) {
|
|
202
|
-
|
|
230
|
+
u(this, "type", 0);
|
|
203
231
|
this.total = t, this.loaded = r, this.partialText = n;
|
|
204
232
|
}
|
|
205
233
|
}
|
|
@@ -216,11 +244,11 @@ class v {
|
|
|
216
244
|
statusText: s,
|
|
217
245
|
error: o
|
|
218
246
|
}) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
247
|
+
u(this, "request");
|
|
248
|
+
u(this, "headers");
|
|
249
|
+
u(this, "status");
|
|
250
|
+
u(this, "statusText");
|
|
251
|
+
u(this, "error");
|
|
224
252
|
this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
|
|
225
253
|
}
|
|
226
254
|
}
|
|
@@ -236,7 +264,7 @@ var me = Object.getOwnPropertyDescriptor, ve = (e, t, r, n) => {
|
|
|
236
264
|
for (var s = n > 1 ? void 0 : n ? me(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
237
265
|
(i = e[o]) && (s = i(s) || s);
|
|
238
266
|
return s;
|
|
239
|
-
},
|
|
267
|
+
}, Ee = (e, t) => (r, n) => t(r, n, e);
|
|
240
268
|
let N = class {
|
|
241
269
|
constructor(e) {
|
|
242
270
|
this._logService = e;
|
|
@@ -253,23 +281,23 @@ let N = class {
|
|
|
253
281
|
});
|
|
254
282
|
}
|
|
255
283
|
async _send(e, t, r) {
|
|
256
|
-
var
|
|
284
|
+
var l, h;
|
|
257
285
|
let n;
|
|
258
286
|
try {
|
|
259
|
-
const
|
|
287
|
+
const a = Q(e), g = e.getUrlWithParams(), p = fetch(g, {
|
|
260
288
|
signal: r.signal,
|
|
261
|
-
...
|
|
289
|
+
...a
|
|
262
290
|
});
|
|
263
|
-
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${
|
|
264
|
-
} catch (
|
|
265
|
-
const
|
|
291
|
+
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${g} with params ${a}`), n = await p;
|
|
292
|
+
} catch (a) {
|
|
293
|
+
const g = new v({
|
|
266
294
|
request: e,
|
|
267
|
-
error:
|
|
268
|
-
status: (
|
|
269
|
-
statusText: (h =
|
|
270
|
-
headers:
|
|
295
|
+
error: a,
|
|
296
|
+
status: (l = a.status) != null ? l : 0,
|
|
297
|
+
statusText: (h = a.statusText) != null ? h : "Unknown Error",
|
|
298
|
+
headers: a.headers
|
|
271
299
|
});
|
|
272
|
-
this._logService.error("[FetchHTTPImplementation]: network error",
|
|
300
|
+
this._logService.error("[FetchHTTPImplementation]: network error", g), t.error(g);
|
|
273
301
|
return;
|
|
274
302
|
}
|
|
275
303
|
const s = new I(n.headers), o = n.status, i = n.statusText;
|
|
@@ -282,52 +310,52 @@ let N = class {
|
|
|
282
310
|
statusText: i
|
|
283
311
|
}));
|
|
284
312
|
else {
|
|
285
|
-
const
|
|
313
|
+
const a = new v({
|
|
286
314
|
request: e,
|
|
287
315
|
error: c,
|
|
288
316
|
status: o,
|
|
289
317
|
statusText: i,
|
|
290
318
|
headers: s
|
|
291
319
|
});
|
|
292
|
-
this._logService.error("[FetchHTTPImplementation]: network error",
|
|
320
|
+
this._logService.error("[FetchHTTPImplementation]: network error", a), t.error(a);
|
|
293
321
|
}
|
|
294
322
|
t.complete();
|
|
295
323
|
}
|
|
296
324
|
async _readBody(e, t, r) {
|
|
297
|
-
var
|
|
325
|
+
var g, p;
|
|
298
326
|
const n = [], s = t.body.getReader(), o = t.headers.get("content-length");
|
|
299
327
|
let i = 0;
|
|
300
|
-
const c = (
|
|
301
|
-
let
|
|
328
|
+
const c = (g = e.requestParams) == null ? void 0 : g.reportProgress, d = e.responseType;
|
|
329
|
+
let l, h;
|
|
302
330
|
for (; ; ) {
|
|
303
|
-
const { done:
|
|
304
|
-
if (
|
|
305
|
-
n.push(
|
|
331
|
+
const { done: f, value: y } = await s.read();
|
|
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 ye(
|
|
306
334
|
o ? Number.parseInt(o, 10) : void 0,
|
|
307
335
|
i,
|
|
308
|
-
|
|
336
|
+
l
|
|
309
337
|
)));
|
|
310
338
|
}
|
|
311
|
-
const
|
|
339
|
+
const a = _e(n, i);
|
|
312
340
|
try {
|
|
313
|
-
const
|
|
314
|
-
return Ie(e,
|
|
315
|
-
} catch (
|
|
316
|
-
const
|
|
341
|
+
const f = (p = t.headers.get("content-type")) != null ? p : "";
|
|
342
|
+
return Ie(e, a, f);
|
|
343
|
+
} catch (f) {
|
|
344
|
+
const y = new v({
|
|
317
345
|
request: e,
|
|
318
|
-
error:
|
|
346
|
+
error: f,
|
|
319
347
|
status: t.status,
|
|
320
348
|
statusText: t.statusText,
|
|
321
349
|
headers: new I(t.headers)
|
|
322
350
|
});
|
|
323
|
-
return this._logService.error("[FetchHTTPImplementation]: network error",
|
|
351
|
+
return this._logService.error("[FetchHTTPImplementation]: network error", y), r.error(y), null;
|
|
324
352
|
}
|
|
325
353
|
}
|
|
326
354
|
};
|
|
327
355
|
N = ve([
|
|
328
|
-
|
|
356
|
+
Ee(0, D)
|
|
329
357
|
], N);
|
|
330
|
-
function
|
|
358
|
+
function _e(e, t) {
|
|
331
359
|
const r = new Uint8Array(t);
|
|
332
360
|
let n = 0;
|
|
333
361
|
for (const s of e)
|
|
@@ -361,57 +389,57 @@ let O = class {
|
|
|
361
389
|
}
|
|
362
390
|
send(e) {
|
|
363
391
|
return new m((t) => {
|
|
364
|
-
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e);
|
|
365
|
-
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
return new we(
|
|
369
|
-
},
|
|
370
|
-
const { headers:
|
|
371
|
-
let
|
|
372
|
-
|
|
373
|
-
let
|
|
374
|
-
if (
|
|
375
|
-
const
|
|
392
|
+
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e), { responseType: o } = e;
|
|
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
|
+
const i = () => {
|
|
395
|
+
const h = r.statusText || "OK", a = new I(r.getAllResponseHeaders());
|
|
396
|
+
return new we(a, r.status, h);
|
|
397
|
+
}, c = () => {
|
|
398
|
+
const { headers: h, statusText: a, status: g } = i();
|
|
399
|
+
let p = null, f = null;
|
|
400
|
+
g !== L.NoContent && (p = typeof r.response > "u" ? r.responseText : r.response);
|
|
401
|
+
let y = g >= ge && g < fe;
|
|
402
|
+
if (o === "json" && typeof p == "string") {
|
|
403
|
+
const w = p;
|
|
376
404
|
try {
|
|
377
|
-
|
|
378
|
-
} catch (
|
|
379
|
-
|
|
405
|
+
p = p ? JSON.parse(p) : null;
|
|
406
|
+
} catch (E) {
|
|
407
|
+
y = !1, p = w, f = E;
|
|
380
408
|
}
|
|
381
409
|
}
|
|
382
|
-
if (f)
|
|
410
|
+
if (o === "blob" && !(p instanceof Blob) && (y = !1, f = new Error("Response is not a Blob object")), y)
|
|
383
411
|
t.next(
|
|
384
412
|
new $({
|
|
385
|
-
body:
|
|
386
|
-
headers:
|
|
387
|
-
status:
|
|
388
|
-
statusText:
|
|
413
|
+
body: p,
|
|
414
|
+
headers: h,
|
|
415
|
+
status: g,
|
|
416
|
+
statusText: a
|
|
389
417
|
})
|
|
390
418
|
);
|
|
391
419
|
else {
|
|
392
|
-
const
|
|
420
|
+
const w = new v({
|
|
393
421
|
request: e,
|
|
394
|
-
error:
|
|
395
|
-
headers:
|
|
396
|
-
status:
|
|
397
|
-
statusText:
|
|
422
|
+
error: f,
|
|
423
|
+
headers: h,
|
|
424
|
+
status: g,
|
|
425
|
+
statusText: a
|
|
398
426
|
});
|
|
399
|
-
this._logService.error("[XHRHTTPImplementation]: network error",
|
|
427
|
+
this._logService.error("[XHRHTTPImplementation]: network error", w), t.error(w);
|
|
400
428
|
}
|
|
401
|
-
},
|
|
402
|
-
const
|
|
429
|
+
}, d = (h) => {
|
|
430
|
+
const a = new v({
|
|
403
431
|
request: e,
|
|
404
|
-
error:
|
|
432
|
+
error: h,
|
|
405
433
|
status: r.status || 0,
|
|
406
434
|
statusText: r.statusText || "Unknown Error",
|
|
407
|
-
headers:
|
|
435
|
+
headers: i().headers
|
|
408
436
|
});
|
|
409
|
-
this._logService.error("[XHRHTTPImplementation]: network error",
|
|
437
|
+
this._logService.error("[XHRHTTPImplementation]: network error", a), t.error(a);
|
|
410
438
|
};
|
|
411
|
-
r.addEventListener("load",
|
|
412
|
-
const
|
|
413
|
-
return r.send(
|
|
414
|
-
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load",
|
|
439
|
+
r.responseType = o || "", r.addEventListener("load", c), r.addEventListener("error", d), r.addEventListener("abort", d), r.addEventListener("timeout", d);
|
|
440
|
+
const l = e.getBody();
|
|
441
|
+
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", d), r.removeEventListener("abort", d), r.removeEventListener("timeout", d);
|
|
415
443
|
};
|
|
416
444
|
});
|
|
417
445
|
}
|
|
@@ -443,12 +471,12 @@ let X = (k = class extends C {
|
|
|
443
471
|
[K, { useClass: t }]
|
|
444
472
|
], (s = this._config) == null ? void 0 : s.override));
|
|
445
473
|
}
|
|
446
|
-
},
|
|
474
|
+
}, u(k, "pluginName", "UNIVER_NETWORK_PLUGIN"), k);
|
|
447
475
|
X = Ae([
|
|
448
476
|
W(1, D),
|
|
449
477
|
W(2, S(H))
|
|
450
478
|
], X);
|
|
451
|
-
const
|
|
479
|
+
const Me = V("univer.network.socket.service");
|
|
452
480
|
class Be extends J {
|
|
453
481
|
createSocket(t) {
|
|
454
482
|
try {
|
|
@@ -497,13 +525,13 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
497
525
|
};
|
|
498
526
|
return (s, o) => new m((i) => {
|
|
499
527
|
const c = () => o(s).subscribe({
|
|
500
|
-
next: (
|
|
501
|
-
error: (
|
|
528
|
+
next: (l) => i.next(l),
|
|
529
|
+
error: (l) => i.error(l),
|
|
502
530
|
complete: () => i.complete()
|
|
503
|
-
}),
|
|
531
|
+
}), d = () => {
|
|
504
532
|
r.delete(c), z(t, c), n();
|
|
505
533
|
};
|
|
506
|
-
return t.push(c), n(),
|
|
534
|
+
return t.push(c), n(), d;
|
|
507
535
|
});
|
|
508
536
|
}, Xe = (e) => {
|
|
509
537
|
const { errorStatusCodes: t, onAuthError: r } = e;
|
|
@@ -523,36 +551,36 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
523
551
|
};
|
|
524
552
|
});
|
|
525
553
|
}, Oe = () => (e, t) => t.map((r) => ({ config: r, result: e })), Ve = (e, t = {}) => {
|
|
526
|
-
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Ue(300), distributeResult: i = Oe() } = t, c = [],
|
|
527
|
-
return (
|
|
528
|
-
const
|
|
554
|
+
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Ue(300), distributeResult: i = Oe() } = t, c = [], d = (l) => l.map((h) => h.config);
|
|
555
|
+
return (l, h) => r(l) ? new m((a) => {
|
|
556
|
+
const g = n(l);
|
|
529
557
|
c.push({
|
|
530
|
-
next: (
|
|
531
|
-
error: (
|
|
532
|
-
config:
|
|
558
|
+
next: (f) => a.next(f),
|
|
559
|
+
error: (f) => a.error(f),
|
|
560
|
+
config: g
|
|
533
561
|
});
|
|
534
|
-
const
|
|
535
|
-
o(
|
|
536
|
-
if (
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
if (
|
|
541
|
-
const [
|
|
542
|
-
|
|
562
|
+
const p = d(c);
|
|
563
|
+
o(l).then((f) => {
|
|
564
|
+
if (f) {
|
|
565
|
+
const y = [];
|
|
566
|
+
p.forEach((w) => {
|
|
567
|
+
const E = c.findIndex((_) => _.config === w);
|
|
568
|
+
if (E >= 0) {
|
|
569
|
+
const [_] = c.splice(E, 1);
|
|
570
|
+
y.push(_);
|
|
543
571
|
}
|
|
544
|
-
}), h(s(
|
|
545
|
-
next: (
|
|
546
|
-
if (
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
const q =
|
|
572
|
+
}), h(s(p, l)).subscribe({
|
|
573
|
+
next: (w) => {
|
|
574
|
+
if (w.type === Y.Response) {
|
|
575
|
+
const E = w.body, _ = i(E, p);
|
|
576
|
+
y.forEach((A) => {
|
|
577
|
+
const q = _.find((F) => F.config === A.config);
|
|
550
578
|
if (q) {
|
|
551
579
|
const F = new $({
|
|
552
580
|
body: q.result,
|
|
553
|
-
headers:
|
|
554
|
-
status:
|
|
555
|
-
statusText:
|
|
581
|
+
headers: w.headers,
|
|
582
|
+
status: w.status,
|
|
583
|
+
statusText: w.statusText
|
|
556
584
|
});
|
|
557
585
|
A.next(F);
|
|
558
586
|
} else
|
|
@@ -560,12 +588,12 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
560
588
|
});
|
|
561
589
|
}
|
|
562
590
|
},
|
|
563
|
-
complete: () =>
|
|
564
|
-
error: (
|
|
591
|
+
complete: () => a.complete(),
|
|
592
|
+
error: (w) => a.error(w)
|
|
565
593
|
});
|
|
566
594
|
}
|
|
567
595
|
});
|
|
568
|
-
}) : h(
|
|
596
|
+
}) : h(l);
|
|
569
597
|
};
|
|
570
598
|
export {
|
|
571
599
|
Xe as AuthInterceptorFactory,
|
|
@@ -579,7 +607,7 @@ export {
|
|
|
579
607
|
x as HTTPService,
|
|
580
608
|
L as HTTPStatusCode,
|
|
581
609
|
K as IHTTPImplementation,
|
|
582
|
-
|
|
610
|
+
Me as ISocketService,
|
|
583
611
|
Ve as MergeInterceptorFactory,
|
|
584
612
|
we as ResponseHeader,
|
|
585
613
|
Ge as RetryInterceptorFactory,
|
|
@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { HTTPResponseType } from './http';
|
|
4
4
|
import { HTTPInterceptorFn } from './interceptor';
|
|
5
5
|
import { HTTPRequestMethod } from './request';
|
|
6
|
-
import { HTTPEvent } from './response';
|
|
6
|
+
import { HTTPEvent, HTTPResponse } from './response';
|
|
7
7
|
import { IHTTPImplementation } from './implementations/implementation';
|
|
8
8
|
export interface IRequestParams {
|
|
9
9
|
/** Query params. These params would be append to the url before the request is sent. */
|
|
@@ -56,13 +56,39 @@ export declare class HTTPService extends Disposable {
|
|
|
56
56
|
* @returns a disposable handler to remove the interceptor
|
|
57
57
|
*/
|
|
58
58
|
registerHTTPInterceptor(interceptor: IHTTPInterceptor): IDisposable;
|
|
59
|
-
get<T>(url: string, params?: IRequestParams): Promise<
|
|
60
|
-
post<T>(url: string, params?: IPostRequestParams): Promise<
|
|
61
|
-
put<T>(url: string, params?: IPostRequestParams): Promise<
|
|
62
|
-
delete<T>(url: string, params?: IRequestParams): Promise<
|
|
63
|
-
patch<T>(url: string, params?: IPostRequestParams): Promise<
|
|
59
|
+
get<T>(url: string, params?: IRequestParams): Promise<HTTPResponse<T>>;
|
|
60
|
+
post<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>;
|
|
61
|
+
put<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>;
|
|
62
|
+
delete<T>(url: string, params?: IRequestParams): Promise<HTTPResponse<T>>;
|
|
63
|
+
patch<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>;
|
|
64
|
+
/**
|
|
65
|
+
* The HTTP request implementations. Normally you should use the `get`, `post`, `put`, `delete`,
|
|
66
|
+
* `patch` methods instead.
|
|
67
|
+
* @param method HTTP request method, e.g. GET, POST, PUT, DELETE, etc.
|
|
68
|
+
* @param url The URL to send the request to.
|
|
69
|
+
* @param options Optional parameters for the request.
|
|
70
|
+
* @returns A promise that resolves to the HTTP response.
|
|
71
|
+
*/
|
|
72
|
+
request<T>(method: HTTPRequestMethod, url: string, options?: IRequestParams): Promise<HTTPResponse<T>>;
|
|
73
|
+
/**
|
|
74
|
+
* Send an HTTP request. It returns an observable that emits HTTP events. For example, it can be used to
|
|
75
|
+
* send Server-Sent Events (SSE) requests.
|
|
76
|
+
* @deprecated Please use `stream` method instead.
|
|
77
|
+
* @param method HTTP request method, e.g. GET, POST, PUT, DELETE, etc.
|
|
78
|
+
* @param url The URL to send the request to.
|
|
79
|
+
* @param _params Optional parameters for the request.
|
|
80
|
+
* @returns An observable of the HTTP event.
|
|
81
|
+
*/
|
|
82
|
+
stream<T>(method: HTTPRequestMethod, url: string, _params?: IRequestParams): Observable<HTTPEvent<T>>;
|
|
83
|
+
/**
|
|
84
|
+
* Send a Server-Sent Events (SSE) request. It returns an observable that emits HTTP events. It is the observable
|
|
85
|
+
* pair of the `request` method.
|
|
86
|
+
* @deprecated Please use `stream` method instead.
|
|
87
|
+
* @param method HTTP request method, e.g. GET, POST, PUT, DELETE, etc.
|
|
88
|
+
* @param url The URL to send the request to.
|
|
89
|
+
* @param _params Optional parameters for the request.
|
|
90
|
+
* @returns An observable of the HTTP event.
|
|
91
|
+
*/
|
|
64
92
|
getSSE<T>(method: HTTPRequestMethod, url: string, _params?: IPostRequestParams): Observable<HTTPEvent<T>>;
|
|
65
|
-
/** The HTTP request implementations */
|
|
66
|
-
private _request;
|
|
67
93
|
private _runInterceptorsAndImplementation;
|
|
68
94
|
}
|