Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 55f6b76

Browse files
committed
fix: fix generic type for all stores
1 parent 04c45fd commit 55f6b76

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

.changeset/eleven-mugs-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-query-pocketbase': patch
3+
---
4+
5+
fix: fix generic type for all stores

.changeset/pre.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"mode": "pre",
3-
"tag": "beta",
4-
"initialVersions": {
5-
"svelte-query-pocketbase": "0.0.0"
6-
},
7-
"changesets": []
2+
"mode": "pre",
3+
"tag": "beta",
4+
"initialVersions": {
5+
"svelte-query-pocketbase": "0.0.0"
6+
},
7+
"changesets": []
88
}

src/lib/queries/collection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { collectionKeys } from '../query-key-factory';
1818
import { realtimeStoreExpand } from '../internal';
1919
import type { CollectionStoreOptions, QueryPrefetchOptions } from '../types';
2020

21-
const collectionStoreCallback = async <T extends Record = Record>(
21+
const collectionStoreCallback = async <T extends Pick<Record, 'id'> = Pick<Record, 'id'>>(
2222
list: T[],
2323
subscription: RecordSubscription<T>,
2424
collection: ReturnType<Client['collection']>,
@@ -46,13 +46,13 @@ const collectionStoreCallback = async <T extends Record = Record>(
4646
}
4747
};
4848

49-
export const createCollectionQueryInitialData = <T extends Record = Record>(
49+
export const createCollectionQueryInitialData = <T extends Pick<Record, 'id'> = Pick<Record, 'id'>>(
5050
collection: ReturnType<Client['collection']>,
5151
{ queryParams = undefined }: { queryParams?: RecordListQueryParams }
5252
): Promise<Array<T>> => collection.getFullList<T>(undefined, queryParams);
5353

5454
export const createCollectionQueryPrefetch = <
55-
T extends Record = Record,
55+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>,
5656
TQueryKey extends QueryKey = QueryKey
5757
>(
5858
collection: ReturnType<Client['collection']>,
@@ -92,7 +92,7 @@ export const createCollectionQueryPrefetch = <
9292
* @param [options.disableRealtime] Only performs the initial fetch and does not subscribe to anything. This has an effect only when provided client-side.
9393
*/
9494
export const createCollectionQuery = <
95-
T extends Record = Record,
95+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>,
9696
TQueryKey extends QueryKey = QueryKey
9797
>(
9898
collection: ReturnType<Client['collection']>,

src/lib/queries/infinite-collection.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ const infiniteCollectionStoreCallback = async <T extends Pick<Record, 'id'>>(
121121
return { data, invalidatePages };
122122
};
123123

124-
export const infiniteCollectionQueryInitialData = <T extends Record = Record>(
124+
export const infiniteCollectionQueryInitialData = <
125+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>
126+
>(
125127
collection: ReturnType<Client['collection']>,
126128
{
127129
page = 1,
@@ -131,7 +133,7 @@ export const infiniteCollectionQueryInitialData = <T extends Record = Record>(
131133
): Promise<ListResult<T>> => collection.getList<T>(page, perPage, queryParams);
132134

133135
export const infiniteCollectionQueryPrefetch = <
134-
T extends Record = Record,
136+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>,
135137
TQueryKey extends QueryKey = QueryKey
136138
>(
137139
collection: ReturnType<Client['collection']>,
@@ -159,7 +161,7 @@ export const infiniteCollectionQueryPrefetch = <
159161
});
160162

161163
export const createInfiniteCollectionQuery = <
162-
T extends Record = Record,
164+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>,
163165
TQueryKey extends QueryKey = QueryKey
164166
>(
165167
collection: ReturnType<Client['collection']>,

src/lib/queries/record.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { collectionKeys } from '../query-key-factory';
1818
import { realtimeStoreExpand } from '../internal';
1919
import type { QueryPrefetchOptions, RecordStoreOptions } from '../types';
2020

21-
const createRecordQueryCallback = async <T extends Record = Record>(
21+
const createRecordQueryCallback = async <T extends Pick<Record, 'id'> = Pick<Record, 'id'>>(
2222
item: T | null,
2323
subscription: RecordSubscription<T>,
2424
collection: ReturnType<Client['collection']>,
@@ -36,14 +36,14 @@ const createRecordQueryCallback = async <T extends Record = Record>(
3636
}
3737
};
3838

39-
export const createRecordQueryInitialData = <T extends Record = Record>(
39+
export const createRecordQueryInitialData = <T extends Pick<Record, 'id'> = Pick<Record, 'id'>>(
4040
collection: ReturnType<Client['collection']>,
4141
id: string,
4242
{ queryParams = undefined }: { queryParams?: RecordQueryParams }
4343
): Promise<T> => collection.getOne<T>(id, queryParams);
4444

4545
export const createRecordQueryPrefetch = <
46-
T extends Record = Record,
46+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>,
4747
TQueryKey extends QueryKey = QueryKey
4848
>(
4949
collection: ReturnType<Client['collection']>,
@@ -78,7 +78,10 @@ export const createRecordQueryPrefetch = <
7878
* @param [options.initial] If provided, skips initial data fetching and uses the provided value instead. Useful if you want to perform initial fetch during SSR and initialize a realtime subscription client-side.
7979
* @param [options.disableRealtime] Only performs the initial fetch and does not subscribe to anything. This has an effect only when provided client-side.
8080
*/
81-
export const createRecordQuery = <T extends Record = Record, TQueryKey extends QueryKey = QueryKey>(
81+
export const createRecordQuery = <
82+
T extends Pick<Record, 'id'> = Pick<Record, 'id'>,
83+
TQueryKey extends QueryKey = QueryKey
84+
>(
8285
collection: ReturnType<Client['collection']>,
8386
id: string,
8487
{

0 commit comments

Comments
 (0)