Skip to content

Commit cfcf5b2

Browse files
committed
fix type errors
1 parent 5e330ae commit cfcf5b2

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/lib/hooks/app/create-app-query.svelte.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export const createAppQuery = <T extends AppClient, K extends keyof T>(
4242
);
4343
const _args = $derived(typeof args === 'function' ? args() : args);
4444
const methodName = $derived(String(method));
45+
const enabled = $derived(
46+
appClient !== undefined && _options?.enabled !== false
47+
);
4548

4649
const queryOptions = $derived(
4750
createQueryOptions({
@@ -51,7 +54,7 @@ export const createAppQuery = <T extends AppClient, K extends keyof T>(
5154
methodName,
5255
...(_args ? [_args] : []),
5356
],
54-
enabled: appClient !== undefined && _options?.enabled !== false,
57+
enabled,
5558
queryFn: async () => {
5659
if (!appClient) {
5760
throw new Error('appClient is undefined');
@@ -88,7 +91,7 @@ export const createAppQuery = <T extends AppClient, K extends keyof T>(
8891

8992
usePolling(
9093
() => queryOptions.queryKey,
91-
() => queryOptions.enabled && (_options?.refetchInterval ?? false)
94+
() => enabled && (_options?.refetchInterval ?? false)
9295
);
9396

9497
return fromStore(createQuery(toStore(() => queryOptions)));

src/lib/hooks/app/create-data-query.svelte.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export const createDataQuery = <T extends DataClient, K extends keyof T>(
4242
);
4343
const _args = $derived(typeof args === 'function' ? args() : args);
4444
const methodName = $derived(String(method));
45+
const enabled = $derived(
46+
dataClient !== undefined && _options?.enabled !== false
47+
);
4548

4649
const queryOptions = $derived(
4750
createQueryOptions({
@@ -51,7 +54,7 @@ export const createDataQuery = <T extends DataClient, K extends keyof T>(
5154
methodName,
5255
...(_args ? [_args] : []),
5356
],
54-
enabled: dataClient !== undefined && _options?.enabled !== false,
57+
enabled,
5558
queryFn: async () => {
5659
if (!dataClient) {
5760
throw new Error('dataClient is undefined');
@@ -88,7 +91,7 @@ export const createDataQuery = <T extends DataClient, K extends keyof T>(
8891

8992
usePolling(
9093
() => queryOptions.queryKey,
91-
() => queryOptions.enabled && (_options?.refetchInterval ?? false)
94+
() => enabled && (_options?.refetchInterval ?? false)
9295
);
9396

9497
return fromStore(createQuery(toStore(() => queryOptions)));

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export const createResourceQuery = <T extends Resource, K extends keyof T>(
5252
const _args = $derived(typeof args === 'function' ? args() : args);
5353
const name = $derived(client.current?.name);
5454
const methodName = $derived(String(method));
55+
const enabled = $derived(
56+
client.current !== undefined &&
57+
_options?.enabled !== false &&
58+
enabledQueries.resourceQueries
59+
);
5560

5661
const queryOptions = $derived(
5762
createQueryOptions({
@@ -64,10 +69,7 @@ export const createResourceQuery = <T extends Resource, K extends keyof T>(
6469
methodName,
6570
...(_args ? [_args] : []),
6671
],
67-
enabled:
68-
client.current !== undefined &&
69-
_options?.enabled !== false &&
70-
enabledQueries.resourceQueries,
72+
enabled,
7173
retry: false,
7274
queryFn: async () => {
7375
const clientFunc = client.current?.[method];
@@ -101,7 +103,7 @@ export const createResourceQuery = <T extends Resource, K extends keyof T>(
101103

102104
usePolling(
103105
() => queryOptions.queryKey,
104-
() => queryOptions.enabled && (_options?.refetchInterval ?? false)
106+
() => enabled && (_options?.refetchInterval ?? false)
105107
);
106108

107109
return fromStore(createQuery(toStore(() => queryOptions)));

src/lib/hooks/create-robot-query.svelte.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export const createRobotQuery = <T extends RobotClient, K extends keyof T>(
5151
);
5252
const _args = $derived(typeof args === 'function' ? args() : args);
5353
const methodName = $derived(String(method));
54+
const enabled = $derived(
55+
client.current !== undefined &&
56+
_options?.enabled !== false &&
57+
enabledQueries.robotQueries
58+
);
5459

5560
const queryOptions = $derived(
5661
createQueryOptions({
@@ -62,10 +67,7 @@ export const createRobotQuery = <T extends RobotClient, K extends keyof T>(
6267
methodName,
6368
...(_args ? [_args] : []),
6469
],
65-
enabled:
66-
client.current !== undefined &&
67-
_options?.enabled !== false &&
68-
enabledQueries.robotQueries,
70+
enabled,
6971
retry: false,
7072
queryFn: async () => {
7173
const clientFunc = client.current?.[method];
@@ -99,7 +101,7 @@ export const createRobotQuery = <T extends RobotClient, K extends keyof T>(
99101

100102
usePolling(
101103
() => queryOptions.queryKey,
102-
() => _options?.refetchInterval ?? false
104+
() => enabled && (_options?.refetchInterval ?? false)
103105
);
104106

105107
return fromStore(createQuery(toStore(() => queryOptions)));

0 commit comments

Comments
 (0)