@civet/common 2.1.0 → 2.1.1
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/dist/FetchProvider.d.ts +1 -1
- package/dist/main.js +23 -23
- package/package.json +1 -1
package/dist/FetchProvider.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export type FetchOptions<Item = unknown, MetaType extends Meta = Meta, ResponseT
|
|
|
15
15
|
declare class FetchProvider<Item = unknown, ResponseType extends Item | Item[] = Item | Item[], Query extends RequestInit | undefined = RequestInit | undefined, MetaType extends Meta = Meta, Options extends FetchOptions<Item, MetaType, ResponseType> = FetchOptions<Item, MetaType, ResponseType>> extends DataProvider<Item, Query, Options, MetaType, ResponseType> {
|
|
16
16
|
private options;
|
|
17
17
|
constructor(options?: FetchProviderOptions<Item, MetaType, ResponseType>);
|
|
18
|
-
handleGet(url: string, query: Query, options: Options | undefined, meta: MetaType, abortSignal: AbortSignalProxy): Promise<ResponseType>;
|
|
19
18
|
normalizeResource(resource: string): string;
|
|
19
|
+
handleGet(url: string, query: Query, options: Options | undefined, meta: MetaType, abortSignal: AbortSignalProxy): Promise<ResponseType>;
|
|
20
20
|
request<ResponseTypeI extends ResponseType = ResponseType, QueryI extends Query = Query, OptionsI extends Options = Options, MetaTypeI extends MetaType = MetaType>(url: string, query: QueryI, options?: OptionsI | undefined, meta?: MetaTypeI, abortSignal?: AbortSignalProxy): Promise<ResponseTypeI>;
|
|
21
21
|
}
|
|
22
22
|
declare const FetchProviderWithPlugins: import('@civet/core').DataProviderImplementationWithPlugin<typeof FetchProvider, unknown, {
|
package/dist/main.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { DataProvider as d, Meta as l } from "@civet/core";
|
|
2
|
-
import { eventPlugin as
|
|
2
|
+
import { eventPlugin as p, EventReceiver as f } from "@civet/events";
|
|
3
3
|
class v extends d {
|
|
4
4
|
options;
|
|
5
|
-
constructor(
|
|
6
|
-
super(), this.options =
|
|
5
|
+
constructor(r = {}) {
|
|
6
|
+
super(), this.options = r;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
return
|
|
8
|
+
normalizeResource(r) {
|
|
9
|
+
return new URL(r, this.options.baseURL).toString();
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
return
|
|
11
|
+
handleGet(r, n, t, e, u) {
|
|
12
|
+
return this.request(r, n, t, e, u);
|
|
13
13
|
}
|
|
14
|
-
async request(
|
|
14
|
+
async request(r, n, t, e, u) {
|
|
15
15
|
e = e instanceof l ? e : new l(e);
|
|
16
16
|
const a = new AbortController();
|
|
17
17
|
u?.listen(a.abort.bind(a));
|
|
18
|
-
const
|
|
19
|
-
await this.options.modifyRequest?.(
|
|
20
|
-
const i = await fetch(
|
|
18
|
+
const s = new URL(r, this.options.baseURL), c = new Headers(n?.headers), o = { ...n, headers: c };
|
|
19
|
+
await this.options.modifyRequest?.(s, o, e);
|
|
20
|
+
const i = await fetch(s.toString(), {
|
|
21
21
|
...o,
|
|
22
22
|
signal: AbortSignal.any(
|
|
23
23
|
[o.signal, a.signal].filter((g) => g != null)
|
|
@@ -26,14 +26,14 @@ class v extends d {
|
|
|
26
26
|
if (!i.ok) {
|
|
27
27
|
if (t?.handleError)
|
|
28
28
|
return t.handleError(
|
|
29
|
-
|
|
29
|
+
s,
|
|
30
30
|
o,
|
|
31
31
|
i,
|
|
32
32
|
e
|
|
33
33
|
);
|
|
34
34
|
if (this.options.handleError)
|
|
35
35
|
return this.options.handleError(
|
|
36
|
-
|
|
36
|
+
s,
|
|
37
37
|
o,
|
|
38
38
|
i,
|
|
39
39
|
e
|
|
@@ -42,14 +42,14 @@ class v extends d {
|
|
|
42
42
|
}
|
|
43
43
|
if (t?.getResponse)
|
|
44
44
|
return t.getResponse(
|
|
45
|
-
|
|
45
|
+
s,
|
|
46
46
|
o,
|
|
47
47
|
i,
|
|
48
48
|
e
|
|
49
49
|
);
|
|
50
50
|
if (this.options.getResponse)
|
|
51
51
|
return this.options.getResponse(
|
|
52
|
-
|
|
52
|
+
s,
|
|
53
53
|
o,
|
|
54
54
|
i,
|
|
55
55
|
e
|
|
@@ -62,23 +62,23 @@ class v extends d {
|
|
|
62
62
|
throw new Error("unprocessable response");
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
const w =
|
|
66
|
-
class R extends
|
|
65
|
+
const w = p(v);
|
|
66
|
+
class R extends f {
|
|
67
67
|
eventSource;
|
|
68
68
|
options;
|
|
69
|
-
constructor(
|
|
70
|
-
super(), this.eventSource =
|
|
69
|
+
constructor(r, n = {}) {
|
|
70
|
+
super(), this.eventSource = r, this.options = n;
|
|
71
71
|
}
|
|
72
|
-
handleSubscribe(
|
|
72
|
+
handleSubscribe(r, n, t) {
|
|
73
73
|
let e;
|
|
74
|
-
const u =
|
|
74
|
+
const u = r.subscribe(
|
|
75
75
|
(c) => {
|
|
76
76
|
e = c;
|
|
77
77
|
}
|
|
78
78
|
), a = new AbortController();
|
|
79
79
|
a.signal.addEventListener("abort", u);
|
|
80
|
-
let
|
|
81
|
-
return n?.events ?
|
|
80
|
+
let s = [];
|
|
81
|
+
return n?.events ? s = n.events : this.options.events && (s = this.options.events), s.length === 0 && (s = ["message"]), s.forEach((c) => {
|
|
82
82
|
this.eventSource.addEventListener(
|
|
83
83
|
c,
|
|
84
84
|
async (o) => n?.getEvents ? t(await n.getEvents(e, c, o)) : this.options.getEvents ? t(await this.options.getEvents(e, c, o)) : t([o]),
|