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

Commit

Permalink
chore: update pocketbase to ^0.11.1, use getFullList w/o batchSize, R…
Browse files Browse the repository at this point in the history
…ecordService type, and sort imports
  • Loading branch information
goknsh committed Feb 28, 2023
1 parent 7ea7a8a commit 5c4e065
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-mayflies-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-query-pocketbase': patch
---

chore: update pocketbase to ^0.11.1, use getFullList w/o batchSize, RecordService type, and sort imports
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@tanstack/svelte-query": "^4.22.2",
"immer": "^9.0.19",
"pocketbase": "^0.10.0",
"pocketbase": "^0.11.1",
"svelte": "^3.54.0"
},
"devDependencies": {
Expand Down Expand Up @@ -74,7 +74,8 @@
"realtime"
],
"files": [
"dist"
"dist",
"CHANGELOG.md"
],
"exports": {
".": "./dist/index.js"
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './query-key-factory';
export * from './queries/collection';
export * from './queries/infinite-collection';
export * from './queries/record';
export * from './queries/user';
export * from './query-key-factory';
export * from './types';
5 changes: 2 additions & 3 deletions src/lib/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type Client from 'pocketbase';
import type { Record } from 'pocketbase';
import type { Record, RecordService } from 'pocketbase';

/**
* Meant for internal use, simply returns the expanded record if there is an expand query param.
Expand All @@ -10,7 +9,7 @@ import type { Record } from 'pocketbase';
* @returns The expanded record.
*/
export const realtimeStoreExpand = async <T extends Pick<Record, 'id'>>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
record: T,
expand: string | undefined = undefined
): Promise<T> =>
Expand Down
24 changes: 12 additions & 12 deletions src/lib/queries/collection.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import {
createQuery,
type QueryClient,
useQueryClient,
type CreateQueryResult,
type FetchQueryOptions,
type QueryClient,
type QueryKey
} from '@tanstack/svelte-query';

import { setAutoFreeze, produce, type Draft } from 'immer';
import { produce, setAutoFreeze, type Draft } from 'immer';

import type Client from 'pocketbase';
import type {
ClientResponseError,
Record,
RecordListQueryParams,
RecordSubscription,
ClientResponseError
RecordService,
RecordSubscription
} from 'pocketbase';

import { collectionKeys } from '../query-key-factory';
import { realtimeStoreExpand } from '../internal';
import type { CollectionStoreOptions, CollectionQueryPrefetchOptions } from '../types';
import { collectionKeys } from '../query-key-factory';
import type { CollectionQueryPrefetchOptions, CollectionStoreOptions } from '../types';

setAutoFreeze(false);

Expand All @@ -30,7 +30,7 @@ const collectionStoreCallback = async <
queryClient: QueryClient,
queryKey: TQueryKey,
subscription: RecordSubscription<T>,
collection: ReturnType<Client['collection']>,
collection: RecordService,
queryParams: RecordListQueryParams | undefined = undefined,
sortFunction?: (a: T, b: T) => number,
filterFunction?: (value: T, index: number, array: T[]) => boolean,
Expand Down Expand Up @@ -106,9 +106,9 @@ const collectionStoreCallback = async <
export const createCollectionQueryInitialData = async <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
{ queryParams = undefined }: { queryParams?: RecordListQueryParams }
): Promise<Array<T>> => [...(await collection.getFullList<T>(undefined, queryParams))];
): Promise<Array<T>> => [...(await collection.getFullList<T>(queryParams))];

/**
* 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.
Expand All @@ -124,7 +124,7 @@ export const createCollectionQueryPrefetch = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
TQueryKey extends QueryKey = QueryKey
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
{
staleTime = Infinity,
queryParams = undefined,
Expand Down Expand Up @@ -168,7 +168,7 @@ export const createCollectionQuery = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
TQueryKey extends QueryKey = QueryKey
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
{
staleTime = Infinity,
refetchOnReconnect = 'always',
Expand Down
32 changes: 16 additions & 16 deletions src/lib/queries/infinite-collection.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type Client from 'pocketbase';
import {
ListResult,
type Record,
type RecordSubscription,
type RecordListQueryParams,
type ClientResponseError
} from 'pocketbase';
import {
createInfiniteQuery,
useQueryClient,
type CreateInfiniteQueryResult,
type FetchQueryOptions,
type QueryKey,
type InfiniteData,
type CreateInfiniteQueryResult,
type QueryClient
type QueryClient,
type QueryKey
} from '@tanstack/svelte-query';
import {
ListResult,
type ClientResponseError,
type Record,
type RecordListQueryParams,
type RecordService,
type RecordSubscription
} from 'pocketbase';

import { setAutoFreeze, produce, type Draft } from 'immer';
import { produce, setAutoFreeze, type Draft } from 'immer';

import { realtimeStoreExpand } from '../internal';
import { collectionKeys } from '../query-key-factory';
Expand All @@ -31,7 +31,7 @@ const infiniteCollectionStoreCallback = async <
queryClient: QueryClient,
queryKey: TQueryKey,
subscription: RecordSubscription<T>,
collection: ReturnType<Client['collection']>,
collection: RecordService,
perPage: number,
queryParams: RecordListQueryParams | undefined = undefined,
sortFunction?: (a: T, b: T) => number,
Expand Down Expand Up @@ -237,7 +237,7 @@ const infiniteCollectionStoreCallback = async <
export const infiniteCollectionQueryInitialData = async <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
{
page = 1,
perPage = 20,
Expand All @@ -262,7 +262,7 @@ export const infiniteCollectionQueryPrefetch = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
TQueryKey extends QueryKey = QueryKey
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
{
staleTime = Infinity,
page = 1,
Expand Down Expand Up @@ -314,7 +314,7 @@ export const createInfiniteCollectionQuery = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
TQueryKey extends QueryKey = QueryKey
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
{
staleTime = Infinity,
refetchOnReconnect = 'always',
Expand Down
14 changes: 7 additions & 7 deletions src/lib/queries/record.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {
createQuery,
type QueryClient,
useQueryClient,
type CreateQueryResult,
type FetchQueryOptions,
type QueryClient,
type QueryKey
} from '@tanstack/svelte-query';

import type Client from 'pocketbase';
import type {
ClientResponseError,
Record,
RecordQueryParams,
RecordService,
RecordSubscription
} from 'pocketbase';

import { collectionKeys } from '../query-key-factory';
import { realtimeStoreExpand } from '../internal';
import { collectionKeys } from '../query-key-factory';
import type { QueryPrefetchOptions, RecordStoreOptions } from '../types';

const createRecordQueryCallback = async <
Expand All @@ -26,7 +26,7 @@ const createRecordQueryCallback = async <
queryClient: QueryClient,
queryKey: TQueryKey,
subscription: RecordSubscription<T>,
collection: ReturnType<Client['collection']>,
collection: RecordService,
queryParams: RecordQueryParams | undefined = undefined
) => {
let data = queryClient.getQueryData<T | null>(queryKey);
Expand Down Expand Up @@ -69,7 +69,7 @@ const createRecordQueryCallback = async <
export const createRecordQueryInitialData = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
id: string,
{ queryParams = undefined }: { queryParams?: RecordQueryParams }
): Promise<T> => collection.getOne<T>(id, queryParams);
Expand All @@ -89,7 +89,7 @@ export const createRecordQueryPrefetch = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
TQueryKey extends QueryKey = QueryKey
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
id: string,
{
staleTime = Infinity,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const createRecordQuery = <
T extends Pick<Record, 'id' | 'updated'> = Pick<Record, 'id' | 'updated'>,
TQueryKey extends QueryKey = QueryKey
>(
collection: ReturnType<Client['collection']>,
collection: RecordService,
id: string,
{
staleTime = Infinity,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/queries/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type Client from 'pocketbase';
import type { BaseAuthStore, Record } from 'pocketbase';
import { readable, type Readable } from 'svelte/store';

import { type KnownUser, type UnknownUser, isRecord } from '../types';
import { isRecord, type KnownUser, type UnknownUser } from '../types';

/**
* Svelte store wrapper around the authenticated Pocketbase user that updates in realtime.
Expand Down
5 changes: 2 additions & 3 deletions src/lib/query-key-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { RecordListQueryParams } from 'pocketbase';
import type Client from 'pocketbase';
import type { RecordListQueryParams, RecordService } from 'pocketbase';

/**
* A collection key factory to generate query keys for TanStack Query based on the parameters given to a Pocketbase `get[...]` function.
Expand All @@ -14,7 +13,7 @@ export const collectionKeys = ({
id = '*',
...queryParams
}: {
collection: ReturnType<Client['collection']>;
collection: RecordService;
id?: string;
} & RecordListQueryParams) => {
return [
Expand Down
12 changes: 6 additions & 6 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type {
CreateInfiniteQueryOptions,
CreateQueryOptions,
FetchQueryOptions,
QueryKey
} from '@tanstack/svelte-query';
import type {
Admin,
Record,
RecordListQueryParams,
RecordQueryParams,
RecordSubscription
} from 'pocketbase';
import type {
CreateInfiniteQueryOptions,
CreateQueryOptions,
FetchQueryOptions,
QueryKey
} from '@tanstack/svelte-query';

/**
* A known user, used in the `userStore`.
Expand Down

0 comments on commit 5c4e065

Please sign in to comment.