@civet/common 1.2.0 → 2.0.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/dist/FetchProvider.d.ts +1 -0
- package/dist/SSEReceiver.d.ts +5 -5
- package/dist/main.js +39 -31
- package/package.json +3 -3
package/dist/FetchProvider.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare class FetchProvider<Item = unknown, ResponseType extends Item | Item[] =
|
|
|
16
16
|
private options;
|
|
17
17
|
constructor(options?: FetchProviderOptions<Item, MetaType, ResponseType>);
|
|
18
18
|
handleGet(url: string, query: Query, options: Options | undefined, meta: MetaType, abortSignal: AbortSignalProxy): Promise<ResponseType>;
|
|
19
|
+
normalizeResource(resource: string): string;
|
|
19
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>;
|
|
20
21
|
}
|
|
21
22
|
declare const FetchProviderWithPlugins: import('@civet/core').DataProviderImplementationWithPlugin<typeof FetchProvider, unknown, {
|
package/dist/SSEReceiver.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { GenericDataProvider, ResourceContextValue } from '@civet/core';
|
|
1
|
+
import { GenericDataProvider, Notifier, ResourceContextValue } from '@civet/core';
|
|
2
2
|
import { EventReceiver } from '@civet/events';
|
|
3
3
|
export type SSEReceiverOptions<Resource extends ResourceContextValue<GenericDataProvider>, EventType = MessageEvent> = {
|
|
4
|
-
getEvents?: (resource: Resource, type: string, event: MessageEvent) => Promise<EventType[]> | EventType[];
|
|
4
|
+
getEvents?: (resource: Resource | undefined, type: string, event: MessageEvent) => Promise<EventType[]> | EventType[];
|
|
5
5
|
};
|
|
6
6
|
export type SSEOptions<Resource extends ResourceContextValue<GenericDataProvider>, EventType = MessageEvent> = {
|
|
7
7
|
events?: string[];
|
|
8
|
-
getEvents?: (resource: Resource, type: string, event: MessageEvent) => Promise<EventType[]> | EventType[];
|
|
8
|
+
getEvents?: (resource: Resource | undefined, type: string, event: MessageEvent) => Promise<EventType[]> | EventType[];
|
|
9
9
|
};
|
|
10
|
-
export default class SSEReceiver<Resource extends ResourceContextValue<GenericDataProvider>, EventType = MessageEvent, Options extends SSEOptions<Resource, EventType> = SSEOptions<Resource, EventType>> extends EventReceiver<
|
|
10
|
+
export default class SSEReceiver<Resource extends ResourceContextValue<GenericDataProvider>, EventType = MessageEvent, Options extends SSEOptions<Resource, EventType> = SSEOptions<Resource, EventType>> extends EventReceiver<EventType, Resource, Options> {
|
|
11
11
|
readonly eventSource: EventSource;
|
|
12
12
|
private options;
|
|
13
13
|
constructor(eventSource: EventSource, options?: SSEReceiverOptions<Resource, EventType>);
|
|
14
|
-
handleSubscribe(
|
|
14
|
+
handleSubscribe(resourceNotifier: Notifier<[Resource | undefined]>, options: Options | undefined, handler: (events: EventType[]) => void): () => void;
|
|
15
15
|
}
|
|
16
16
|
export type SSEReceiverType = InstanceType<typeof SSEReceiver>;
|
package/dist/main.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
import { DataProvider as d, Meta as
|
|
2
|
-
import { eventPlugin as p, EventReceiver as
|
|
3
|
-
class
|
|
1
|
+
import { DataProvider as d, Meta as l } from "@civet/core";
|
|
2
|
+
import { eventPlugin as p, EventReceiver as v } from "@civet/events";
|
|
3
|
+
class f extends d {
|
|
4
4
|
options;
|
|
5
|
-
constructor(
|
|
6
|
-
super(), this.options =
|
|
5
|
+
constructor(r = {}) {
|
|
6
|
+
super(), this.options = r;
|
|
7
7
|
}
|
|
8
|
-
handleGet(
|
|
9
|
-
return this.request(
|
|
8
|
+
handleGet(r, s, t, e, u) {
|
|
9
|
+
return this.request(r, s, t, e, u);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
normalizeResource(r) {
|
|
12
|
+
return new URL(r, this.options.baseURL).toString();
|
|
13
|
+
}
|
|
14
|
+
async request(r, s, t, e, u) {
|
|
15
|
+
e = e instanceof l ? e : new l(e);
|
|
13
16
|
const i = new AbortController();
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
await this.options.modifyRequest?.(
|
|
17
|
-
const o = await fetch(
|
|
18
|
-
...
|
|
17
|
+
u?.listen(i.abort.bind(i));
|
|
18
|
+
const a = new URL(r), c = new Headers(s?.headers), n = { ...s, headers: c };
|
|
19
|
+
await this.options.modifyRequest?.(a, n, e);
|
|
20
|
+
const o = await fetch(a.toString(), {
|
|
21
|
+
...n,
|
|
19
22
|
signal: AbortSignal.any(
|
|
20
|
-
[
|
|
23
|
+
[n.signal, i.signal].filter((g) => g != null)
|
|
21
24
|
)
|
|
22
25
|
});
|
|
23
26
|
if (!o.ok) {
|
|
24
27
|
if (t?.handleError)
|
|
25
28
|
return t.handleError(
|
|
26
|
-
s,
|
|
27
29
|
a,
|
|
30
|
+
n,
|
|
28
31
|
o,
|
|
29
32
|
e
|
|
30
33
|
);
|
|
31
34
|
if (this.options.handleError)
|
|
32
35
|
return this.options.handleError(
|
|
33
|
-
s,
|
|
34
36
|
a,
|
|
37
|
+
n,
|
|
35
38
|
o,
|
|
36
39
|
e
|
|
37
40
|
);
|
|
@@ -39,15 +42,15 @@ class v extends d {
|
|
|
39
42
|
}
|
|
40
43
|
if (t?.getResponse)
|
|
41
44
|
return t.getResponse(
|
|
42
|
-
s,
|
|
43
45
|
a,
|
|
46
|
+
n,
|
|
44
47
|
o,
|
|
45
48
|
e
|
|
46
49
|
);
|
|
47
50
|
if (this.options.getResponse)
|
|
48
51
|
return this.options.getResponse(
|
|
49
|
-
s,
|
|
50
52
|
a,
|
|
53
|
+
n,
|
|
51
54
|
o,
|
|
52
55
|
e
|
|
53
56
|
);
|
|
@@ -59,25 +62,30 @@ class v extends d {
|
|
|
59
62
|
throw new Error("unprocessable response");
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
|
-
const
|
|
63
|
-
class R extends
|
|
65
|
+
const w = p(f);
|
|
66
|
+
class R extends v {
|
|
64
67
|
eventSource;
|
|
65
68
|
options;
|
|
66
|
-
constructor(
|
|
67
|
-
super(), this.eventSource =
|
|
69
|
+
constructor(r, s = {}) {
|
|
70
|
+
super(), this.eventSource = r, this.options = s;
|
|
68
71
|
}
|
|
69
|
-
handleSubscribe(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
handleSubscribe(r, s, t) {
|
|
73
|
+
let e;
|
|
74
|
+
const u = r.subscribe(
|
|
75
|
+
(c) => {
|
|
76
|
+
e = c;
|
|
77
|
+
}
|
|
78
|
+
), i = new AbortController();
|
|
79
|
+
return i.signal.addEventListener("abort", u), (s?.events?.length ? s.events : ["message"]).forEach((c) => {
|
|
72
80
|
this.eventSource.addEventListener(
|
|
73
|
-
|
|
74
|
-
async (
|
|
75
|
-
{ signal:
|
|
81
|
+
c,
|
|
82
|
+
async (n) => s?.getEvents ? t(await s.getEvents(e, c, n)) : this.options.getEvents ? t(await this.options.getEvents(e, c, n)) : t([n]),
|
|
83
|
+
{ signal: i.signal }
|
|
76
84
|
);
|
|
77
|
-
}),
|
|
85
|
+
}), i.abort.bind(i);
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
export {
|
|
81
|
-
|
|
89
|
+
w as FetchProvider,
|
|
82
90
|
R as SSEReceiver
|
|
83
91
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civet/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Civet",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Burmeister"
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"react-dom": ">=18.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@civet/core": "^6.
|
|
55
|
-
"@civet/events": "^
|
|
54
|
+
"@civet/core": "^6.1.1",
|
|
55
|
+
"@civet/events": "^4.0.1",
|
|
56
56
|
"@eslint/js": "^9.35.0",
|
|
57
57
|
"@types/react": "^19.1.12",
|
|
58
58
|
"@types/react-dom": "^19.1.9",
|