doover-js 0.3.0 → 0.4.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/react/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { useAgentConnections, agentConnectionsQueryKey, } from "./useAgentConnec
|
|
|
6
6
|
export { useChannelSubscription, } from "./useChannelSubscription";
|
|
7
7
|
export type { ChannelSubscriptionHandlers } from "./useChannelSubscription";
|
|
8
8
|
export { useChannelAggregate, channelAggregateQueryKey, } from "./useChannelAggregate";
|
|
9
|
+
export type { UseChannelAggregateResult } from "./useChannelAggregate";
|
|
9
10
|
export { useAgentChannel } from "./useAgentChannel";
|
|
10
11
|
export { useSendMessage } from "./useSendMessage";
|
|
11
12
|
export { useUpdateAggregate } from "./useUpdateAggregate";
|
|
@@ -4,4 +4,4 @@ import type { Aggregate } from "../types/common";
|
|
|
4
4
|
* and channel name as separate arguments — the most common shape at call
|
|
5
5
|
* sites where the identifier isn't already a `ChannelIdentifier`.
|
|
6
6
|
*/
|
|
7
|
-
export declare function useAgentChannel<TData
|
|
7
|
+
export declare function useAgentChannel<TData = Aggregate["data"]>(agentId: string | undefined, channelName: string): import("./useChannelAggregate").UseChannelAggregateResult<TData>;
|
|
@@ -2,12 +2,32 @@ import { type UseQueryResult } from "@tanstack/react-query";
|
|
|
2
2
|
import type { Aggregate } from "../types/common";
|
|
3
3
|
import type { ChannelIdentifier } from "../types/viewer";
|
|
4
4
|
export declare function channelAggregateQueryKey(agentId: string | undefined, channelName: string | undefined): readonly ["doover", "agent", string | undefined, "channel", string | undefined];
|
|
5
|
+
/**
|
|
6
|
+
* Shape returned by `useChannelAggregate`. Shadows the react-query
|
|
7
|
+
* `data` field with the unwrapped aggregate payload (`TData`) so the
|
|
8
|
+
* common call-site pattern — `const { data } = useChannelAggregate(…)` —
|
|
9
|
+
* just works without a secondary `.data` access or cast. The
|
|
10
|
+
* `attachments` and `last_updated` slots are hoisted alongside for the
|
|
11
|
+
* same reason; everything else (isLoading, isError, refetch, status,
|
|
12
|
+
* …) passes through from react-query unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export interface UseChannelAggregateResult<TData> extends Omit<UseQueryResult<Aggregate<TData> | undefined>, "data"> {
|
|
15
|
+
/** The aggregate payload. `undefined` until the first fetch lands. */
|
|
16
|
+
data: TData | undefined;
|
|
17
|
+
/** Attachments (files/blobs) on the aggregate. */
|
|
18
|
+
attachments: Aggregate["attachments"] | undefined;
|
|
19
|
+
/** Server timestamp (epoch seconds) of the last aggregate update. */
|
|
20
|
+
last_updated: number | null | undefined;
|
|
21
|
+
}
|
|
5
22
|
/**
|
|
6
23
|
* Fetch a channel's aggregate and keep it live via the gateway. Incoming
|
|
7
24
|
* `channelSync` and `aggregateUpdate` events patch the react-query cache
|
|
8
25
|
* under `channelAggregateQueryKey(agentId, channelName)`.
|
|
9
26
|
*
|
|
10
27
|
* Typed on `TData` — the shape of `aggregate.data`. Defaults to the generic
|
|
11
|
-
* `Record<string, JSONValue>` used by `Aggregate`.
|
|
28
|
+
* `Record<string, JSONValue>` used by `Aggregate`. No `extends` constraint
|
|
29
|
+
* on the generic: typed aggregate interfaces (e.g. `{ enabled: boolean }`)
|
|
30
|
+
* don't have the implicit index signature that `Aggregate["data"]` carries
|
|
31
|
+
* and enforcing compatibility there just forces `as` casts at call sites.
|
|
12
32
|
*/
|
|
13
|
-
export declare function useChannelAggregate<TData
|
|
33
|
+
export declare function useChannelAggregate<TData = Aggregate["data"]>(identifier: ChannelIdentifier): UseChannelAggregateResult<TData>;
|
|
@@ -15,7 +15,10 @@ function channelAggregateQueryKey(agentId, channelName) {
|
|
|
15
15
|
* under `channelAggregateQueryKey(agentId, channelName)`.
|
|
16
16
|
*
|
|
17
17
|
* Typed on `TData` — the shape of `aggregate.data`. Defaults to the generic
|
|
18
|
-
* `Record<string, JSONValue>` used by `Aggregate`.
|
|
18
|
+
* `Record<string, JSONValue>` used by `Aggregate`. No `extends` constraint
|
|
19
|
+
* on the generic: typed aggregate interfaces (e.g. `{ enabled: boolean }`)
|
|
20
|
+
* don't have the implicit index signature that `Aggregate["data"]` carries
|
|
21
|
+
* and enforcing compatibility there just forces `as` casts at call sites.
|
|
19
22
|
*/
|
|
20
23
|
function useChannelAggregate(identifier) {
|
|
21
24
|
const client = (0, context_1.useDooverClient)();
|
|
@@ -29,10 +32,18 @@ function useChannelAggregate(identifier) {
|
|
|
29
32
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
33
|
[queryClient, agentId, channelName]);
|
|
31
34
|
(0, useChannelSubscription_1.useChannelSubscription)(identifier, { onAggregate });
|
|
32
|
-
|
|
35
|
+
const query = (0, react_query_1.useQuery)({
|
|
33
36
|
queryKey: key,
|
|
34
37
|
enabled: !!agentId && !!channelName,
|
|
35
38
|
staleTime: Infinity,
|
|
36
39
|
queryFn: () => client.viewer.getAggregate(identifier),
|
|
37
40
|
});
|
|
41
|
+
const aggregate = query.data;
|
|
42
|
+
const { data: _ignored, ...rest } = query;
|
|
43
|
+
return {
|
|
44
|
+
...rest,
|
|
45
|
+
data: aggregate?.data,
|
|
46
|
+
attachments: aggregate?.attachments,
|
|
47
|
+
last_updated: aggregate?.last_updated,
|
|
48
|
+
};
|
|
38
49
|
}
|
package/dist/test/react.test.js
CHANGED
|
@@ -131,7 +131,8 @@ function wrapper(client) {
|
|
|
131
131
|
wrapper: Wrapper,
|
|
132
132
|
});
|
|
133
133
|
await (0, react_1.waitFor)(() => (0, chai_1.expect)(result.current.isSuccess).to.equal(true));
|
|
134
|
-
(0, chai_1.expect)(result.current.data
|
|
134
|
+
(0, chai_1.expect)(result.current.data).to.deep.equal({ x: 1 });
|
|
135
|
+
(0, chai_1.expect)(result.current.attachments).to.deep.equal([]);
|
|
135
136
|
// Drive a live aggregate update.
|
|
136
137
|
await (0, react_1.act)(async () => {
|
|
137
138
|
const ws = helpers_1.MockWebSocket.instances[0];
|
|
@@ -154,7 +155,7 @@ function wrapper(client) {
|
|
|
154
155
|
},
|
|
155
156
|
});
|
|
156
157
|
});
|
|
157
|
-
await (0, react_1.waitFor)(() => (0, chai_1.expect)(result.current.data
|
|
158
|
+
await (0, react_1.waitFor)(() => (0, chai_1.expect)(result.current.data).to.deep.equal({ x: 2 }));
|
|
158
159
|
});
|
|
159
160
|
(0, mocha_1.it)("useSendMessage posts via MessagesApi", async () => {
|
|
160
161
|
const fetchMock = (0, helpers_1.createFetchMock)((url) => {
|