Skip to content

Commit c317ea7

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/vite-6.3.6
2 parents 58c849f + 6b6951c commit c317ea7

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

.changeset/cold-beans-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@viamrobotics/svelte-sdk': patch
3+
---
4+
5+
Export streamQueryKey factory to help with query management

.changeset/polite-candies-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@viamrobotics/svelte-sdk': patch
3+
---
4+
5+
Fix create-resource-stream params"

src/lib/hooks/create-resource-stream.svelte.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,27 @@ export type StreamItemType<T> = T extends (
2222
interface QueryOptions {
2323
// enabled defaults to true if unspecified
2424
enabled?: boolean;
25+
// refetchMode defaults to 'reset' if unspecified
2526
refetchMode?: 'append' | 'reset' | 'replace';
26-
maxChunks?: number;
2727
}
2828

2929
type QueryResult<U> = QueryObserverResult<U[], Error>;
3030

31+
export const streamQueryKey = (
32+
partID: string,
33+
name: string | undefined,
34+
methodName: string,
35+
args?: QueryOptions | unknown
36+
) => [
37+
'viam-svelte-sdk',
38+
'partID',
39+
partID,
40+
'resource',
41+
name,
42+
methodName,
43+
...(args ? [args] : []),
44+
];
45+
3146
export const createResourceStream = <T extends Resource, K extends keyof T>(
3247
client: { current: T | undefined },
3348
method: K,
@@ -54,15 +69,9 @@ export const createResourceStream = <T extends Resource, K extends keyof T>(
5469
const _args = $derived(typeof args === 'function' ? args() : args);
5570
const name = $derived(client.current?.name);
5671
const methodName = $derived(String(method));
57-
const queryKey = $derived([
58-
'viam-svelte-sdk',
59-
'partID',
60-
(client.current as T & { partID: string })?.partID,
61-
'resource',
62-
name,
63-
methodName,
64-
...(_args ? [_args] : []),
65-
]);
72+
const refetchMode = $derived(_options?.refetchMode ?? 'reset');
73+
const partID = $derived((client.current as T & { partID: string })?.partID);
74+
const queryKey = $derived(streamQueryKey(partID, name, methodName, _args));
6675

6776
function processStream() {
6877
const clientFunc = client.current?.[method];
@@ -97,7 +106,7 @@ export const createResourceStream = <T extends Resource, K extends keyof T>(
97106
enabled: client.current !== undefined && _options?.enabled !== false,
98107
queryFn: streamedQuery<StreamItemType<T[K]>>({
99108
streamFn: processStream,
100-
..._options,
109+
refetchMode,
101110
}),
102111
})
103112
);

src/lib/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export { createRobotMutation } from './hooks/create-robot-mutation.svelte';
1616
export { createResourceClient } from './hooks/create-resource-client.svelte';
1717
export { createResourceQuery } from './hooks/create-resource-query.svelte';
1818
export { createResourceMutation } from './hooks/create-resource-mutation.svelte';
19-
export { createResourceStream } from './hooks/create-resource-stream.svelte';
19+
export {
20+
createResourceStream,
21+
streamQueryKey,
22+
} from './hooks/create-resource-stream.svelte';
2023
export { createStreamClient } from './hooks/create-stream-client.svelte';
2124

2225
export { useMachineStatus } from './hooks/machine-status.svelte';

0 commit comments

Comments
 (0)