Skip to content

Commit

Permalink
Handle for falsy client-side inputs (#38)
Browse files Browse the repository at this point in the history
* fix: handle for falsy client-side inputs

[Comment from #34 for reference](#34 (comment))

* bump version
  • Loading branch information
vishalbalaji authored May 14, 2024
1 parent bcc57a7 commit 0d2f244
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trpc-svelte-query-adapter",
"version": "2.3.0",
"version": "2.3.1",
"description": "A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.",
"keywords": [
"trpc",
Expand Down
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ type CreateQueryProcedure<TInput, TOutput, TError> = {
[ProcedureNames.query]: <TData = TOutput>(input: TInput, opts?: CreateTRPCQueryOptions<TOutput, TError, TData> & TRPCQueryOpts)
=> CreateQueryResult<TData, TError>,
[ProcedureNames.serverQuery]: <TData = TOutput>(input: TInput, opts?: CreateTRPCServerQueryOptions<TOutput, TError, TData> & TRPCQueryOpts)
=> Promise<(input?: TInput | ((old: TInput) => TInput)) => CreateQueryResult<TData, TError>>,
=> Promise<(...args: [TInput | ((old: TInput) => TInput)] | []) => CreateQueryResult<TData, TError>>,
// [ProcedureNames.serverQuery]: <TData = TOutput>(input: TInput, opts?: CreateTRPCServerQueryOptions<TOutput, TError, TData> & TRPCQueryOpts)
// => Promise<(input: TInput | never) => CreateQueryResult<TData, TError>>,
} & {}

type CreateTRPCInfiniteQueryOptions<TOutput, TError, TData> = Omit<CreateInfiniteQueryOptions<TOutput, TError, TData>, 'queryKey' | 'queryFn'>;
Expand All @@ -225,7 +227,7 @@ type CreateInfiniteQueryProcedure<TInput, TOutput, TError> = (TInput extends { c
[ProcedureNames.infiniteQuery]: <TData = TOutput>(input: Omit<TInput, 'cursor'>, opts?: CreateTRPCInfiniteQueryOptions<TOutput, TError, TData> & InfiniteQueryOpts<TInput> & TRPCQueryOpts)
=> CreateInfiniteQueryResult<InfiniteData<TData>, TError>,
[ProcedureNames.serverInfiniteQuery]: <TData = TOutput>(input: Omit<TInput, 'cursor'>, opts?: CreateTRPCServerInfiniteQueryOptions<TOutput, TError, TData> & InfiniteQueryOpts<TInput> & TRPCQueryOpts)
=> Promise<(input?: TInput | ((old: TInput) => TInput)) => CreateInfiniteQueryResult<InfiniteData<TData>, TError>>,
=> Promise<(...args: [TInput | ((old: TInput) => TInput)] | []) => CreateInfiniteQueryResult<InfiniteData<TData>, TError>>,
}
: {}) & {}

Expand Down Expand Up @@ -458,10 +460,11 @@ const procedures: Record<PropertyKey,
await queryClient.prefetchQuery(query);
}

return (newInput?: any) => {
return (...args: any[]) => {
let newQuery = query;

if (newInput) {
if (args.length > 0) {
const newInput = args[0];
let i = newInput;
if (typeof newInput === 'function') i = newInput(input);
newQuery = {
Expand Down Expand Up @@ -517,10 +520,11 @@ const procedures: Record<PropertyKey,
await queryClient.prefetchInfiniteQuery(query as any);
}

return (newInput?: any) => {
return (...args: any[]) => {
let newQuery = query;

if (newInput) {
if (args.length > 0) {
const newInput = args[0];
let i = newInput;
if (typeof newInput === 'function') i = newInput(input);
newQuery = {
Expand Down Expand Up @@ -713,5 +717,3 @@ export function svelteQueryWrapper<TRouter extends AnyRouter>({
},
});
}


0 comments on commit 0d2f244

Please sign in to comment.