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

Commit 5c4e065

Browse files
committed
chore: update pocketbase to ^0.11.1, use getFullList w/o batchSize, RecordService type, and sort imports
1 parent 7ea7a8a commit 5c4e065

File tree

11 files changed

+59
-55
lines changed

11 files changed

+59
-55
lines changed

.changeset/quick-mayflies-do.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+
chore: update pocketbase to ^0.11.1, use getFullList w/o batchSize, RecordService type, and sort imports

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"@tanstack/svelte-query": "^4.22.2",
2121
"immer": "^9.0.19",
22-
"pocketbase": "^0.10.0",
22+
"pocketbase": "^0.11.1",
2323
"svelte": "^3.54.0"
2424
},
2525
"devDependencies": {
@@ -74,7 +74,8 @@
7474
"realtime"
7575
],
7676
"files": [
77-
"dist"
77+
"dist",
78+
"CHANGELOG.md"
7879
],
7980
"exports": {
8081
".": "./dist/index.js"

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export * from './query-key-factory';
21
export * from './queries/collection';
32
export * from './queries/infinite-collection';
43
export * from './queries/record';
54
export * from './queries/user';
5+
export * from './query-key-factory';
66
export * from './types';

src/lib/internal/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type Client from 'pocketbase';
2-
import type { Record } from 'pocketbase';
1+
import type { Record, RecordService } from 'pocketbase';
32

43
/**
54
* Meant for internal use, simply returns the expanded record if there is an expand query param.
@@ -10,7 +9,7 @@ import type { Record } from 'pocketbase';
109
* @returns The expanded record.
1110
*/
1211
export const realtimeStoreExpand = async <T extends Pick<Record, 'id'>>(
13-
collection: ReturnType<Client['collection']>,
12+
collection: RecordService,
1413
record: T,
1514
expand: string | undefined = undefined
1615
): Promise<T> =>

src/lib/queries/collection.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import {
22
createQuery,
3-
type QueryClient,
43
useQueryClient,
54
type CreateQueryResult,
65
type FetchQueryOptions,
6+
type QueryClient,
77
type QueryKey
88
} from '@tanstack/svelte-query';
99

10-
import { setAutoFreeze, produce, type Draft } from 'immer';
10+
import { produce, setAutoFreeze, type Draft } from 'immer';
1111

12-
import type Client from 'pocketbase';
1312
import type {
13+
ClientResponseError,
1414
Record,
1515
RecordListQueryParams,
16-
RecordSubscription,
17-
ClientResponseError
16+
RecordService,
17+
RecordSubscription
1818
} from 'pocketbase';
1919

20-
import { collectionKeys } from '../query-key-factory';
2120
import { realtimeStoreExpand } from '../internal';
22-
import type { CollectionStoreOptions, CollectionQueryPrefetchOptions } from '../types';
21+
import { collectionKeys } from '../query-key-factory';
22+
import type { CollectionQueryPrefetchOptions, CollectionStoreOptions } from '../types';
2323

2424
setAutoFreeze(false);
2525

@@ -30,7 +30,7 @@ const collectionStoreCallback = async <
3030
queryClient: QueryClient,
3131
queryKey: TQueryKey,
3232
subscription: RecordSubscription<T>,
33-
collection: ReturnType<Client['collection']>,
33+
collection: RecordService,
3434
queryParams: RecordListQueryParams | undefined = undefined,
3535
sortFunction?: (a: T, b: T) => number,
3636
filterFunction?: (value: T, index: number, array: T[]) => boolean,
@@ -106,9 +106,9 @@ const collectionStoreCallback = async <
106106
export const createCollectionQueryInitialData = async <
107107
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>
108108
>(
109-
collection: ReturnType<Client['collection']>,
109+
collection: RecordService,
110110
{ queryParams = undefined }: { queryParams?: RecordListQueryParams }
111-
): Promise<Array<T>> => [...(await collection.getFullList<T>(undefined, queryParams))];
111+
): Promise<Array<T>> => [...(await collection.getFullList<T>(queryParams))];
112112

113113
/**
114114
* Meant for SSR use, allows for prefetching queries on the server so that data is already available in the cache, and no initial fetch occurs client-side. See [TanStack's documentation](https://tanstack.com/query/v4/docs/svelte/ssr#using-prefetchquery) and this project's README.md for some examples.
@@ -124,7 +124,7 @@ export const createCollectionQueryPrefetch = <
124124
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
125125
TQueryKey extends QueryKey = QueryKey
126126
>(
127-
collection: ReturnType<Client['collection']>,
127+
collection: RecordService,
128128
{
129129
staleTime = Infinity,
130130
queryParams = undefined,
@@ -168,7 +168,7 @@ export const createCollectionQuery = <
168168
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
169169
TQueryKey extends QueryKey = QueryKey
170170
>(
171-
collection: ReturnType<Client['collection']>,
171+
collection: RecordService,
172172
{
173173
staleTime = Infinity,
174174
refetchOnReconnect = 'always',

src/lib/queries/infinite-collection.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import type Client from 'pocketbase';
2-
import {
3-
ListResult,
4-
type Record,
5-
type RecordSubscription,
6-
type RecordListQueryParams,
7-
type ClientResponseError
8-
} from 'pocketbase';
91
import {
102
createInfiniteQuery,
113
useQueryClient,
4+
type CreateInfiniteQueryResult,
125
type FetchQueryOptions,
13-
type QueryKey,
146
type InfiniteData,
15-
type CreateInfiniteQueryResult,
16-
type QueryClient
7+
type QueryClient,
8+
type QueryKey
179
} from '@tanstack/svelte-query';
10+
import {
11+
ListResult,
12+
type ClientResponseError,
13+
type Record,
14+
type RecordListQueryParams,
15+
type RecordService,
16+
type RecordSubscription
17+
} from 'pocketbase';
1818

19-
import { setAutoFreeze, produce, type Draft } from 'immer';
19+
import { produce, setAutoFreeze, type Draft } from 'immer';
2020

2121
import { realtimeStoreExpand } from '../internal';
2222
import { collectionKeys } from '../query-key-factory';
@@ -31,7 +31,7 @@ const infiniteCollectionStoreCallback = async <
3131
queryClient: QueryClient,
3232
queryKey: TQueryKey,
3333
subscription: RecordSubscription<T>,
34-
collection: ReturnType<Client['collection']>,
34+
collection: RecordService,
3535
perPage: number,
3636
queryParams: RecordListQueryParams | undefined = undefined,
3737
sortFunction?: (a: T, b: T) => number,
@@ -237,7 +237,7 @@ const infiniteCollectionStoreCallback = async <
237237
export const infiniteCollectionQueryInitialData = async <
238238
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>
239239
>(
240-
collection: ReturnType<Client['collection']>,
240+
collection: RecordService,
241241
{
242242
page = 1,
243243
perPage = 20,
@@ -262,7 +262,7 @@ export const infiniteCollectionQueryPrefetch = <
262262
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
263263
TQueryKey extends QueryKey = QueryKey
264264
>(
265-
collection: ReturnType<Client['collection']>,
265+
collection: RecordService,
266266
{
267267
staleTime = Infinity,
268268
page = 1,
@@ -314,7 +314,7 @@ export const createInfiniteCollectionQuery = <
314314
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
315315
TQueryKey extends QueryKey = QueryKey
316316
>(
317-
collection: ReturnType<Client['collection']>,
317+
collection: RecordService,
318318
{
319319
staleTime = Infinity,
320320
refetchOnReconnect = 'always',

src/lib/queries/record.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import {
22
createQuery,
3-
type QueryClient,
43
useQueryClient,
54
type CreateQueryResult,
65
type FetchQueryOptions,
6+
type QueryClient,
77
type QueryKey
88
} from '@tanstack/svelte-query';
99

10-
import type Client from 'pocketbase';
1110
import type {
1211
ClientResponseError,
1312
Record,
1413
RecordQueryParams,
14+
RecordService,
1515
RecordSubscription
1616
} from 'pocketbase';
1717

18-
import { collectionKeys } from '../query-key-factory';
1918
import { realtimeStoreExpand } from '../internal';
19+
import { collectionKeys } from '../query-key-factory';
2020
import type { QueryPrefetchOptions, RecordStoreOptions } from '../types';
2121

2222
const createRecordQueryCallback = async <
@@ -26,7 +26,7 @@ const createRecordQueryCallback = async <
2626
queryClient: QueryClient,
2727
queryKey: TQueryKey,
2828
subscription: RecordSubscription<T>,
29-
collection: ReturnType<Client['collection']>,
29+
collection: RecordService,
3030
queryParams: RecordQueryParams | undefined = undefined
3131
) => {
3232
let data = queryClient.getQueryData<T | null>(queryKey);
@@ -69,7 +69,7 @@ const createRecordQueryCallback = async <
6969
export const createRecordQueryInitialData = <
7070
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>
7171
>(
72-
collection: ReturnType<Client['collection']>,
72+
collection: RecordService,
7373
id: string,
7474
{ queryParams = undefined }: { queryParams?: RecordQueryParams }
7575
): Promise<T> => collection.getOne<T>(id, queryParams);
@@ -89,7 +89,7 @@ export const createRecordQueryPrefetch = <
8989
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
9090
TQueryKey extends QueryKey = QueryKey
9191
>(
92-
collection: ReturnType<Client['collection']>,
92+
collection: RecordService,
9393
id: string,
9494
{
9595
staleTime = Infinity,
@@ -132,7 +132,7 @@ export const createRecordQuery = <
132132
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
133133
TQueryKey extends QueryKey = QueryKey
134134
>(
135-
collection: ReturnType<Client['collection']>,
135+
collection: RecordService,
136136
id: string,
137137
{
138138
staleTime = Infinity,

src/lib/queries/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type Client from 'pocketbase';
22
import type { BaseAuthStore, Record } from 'pocketbase';
33
import { readable, type Readable } from 'svelte/store';
44

5-
import { type KnownUser, type UnknownUser, isRecord } from '../types';
5+
import { isRecord, type KnownUser, type UnknownUser } from '../types';
66

77
/**
88
* Svelte store wrapper around the authenticated Pocketbase user that updates in realtime.

src/lib/query-key-factory.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { RecordListQueryParams } from 'pocketbase';
2-
import type Client from 'pocketbase';
1+
import type { RecordListQueryParams, RecordService } from 'pocketbase';
32

43
/**
54
* A collection key factory to generate query keys for TanStack Query based on the parameters given to a Pocketbase `get[...]` function.
@@ -14,7 +13,7 @@ export const collectionKeys = ({
1413
id = '*',
1514
...queryParams
1615
}: {
17-
collection: ReturnType<Client['collection']>;
16+
collection: RecordService;
1817
id?: string;
1918
} & RecordListQueryParams) => {
2019
return [

0 commit comments

Comments
 (0)