Skip to content

Commit

Permalink
fix: mutation input typings
Browse files Browse the repository at this point in the history
  • Loading branch information
OrJDev committed Sep 28, 2024
1 parent ea7543f commit e4f7bc4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-eagles-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solid-mediakit/prpc': patch
---

fix: mutation input typings
1 change: 1 addition & 0 deletions examples/prpc/src/routes/builder-mutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Home: VoidComponent = () => {
}
},
}))

return (
<main class='flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#026d56] to-[#152a2c]'>
<p class='text-2xl text-white'>{helloMut.data ?? 'No Data yet...'}</p>
Expand Down
6 changes: 5 additions & 1 deletion packages/prpc/solid/src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export const mutation$ = <
mutationFn: async (input) => await tryAndWrap(props.mutationFn, input),
mutationKey: ['prpc.mutation', props.key],
...(opts?.() ?? {}),
})) as CreateMutationResult<Fn$Output<Fn, ZObj, Mw>>
})) as unknown as CreateMutationResult<
Fn$Output<Fn, ZObj, Mw>,
ZObj extends ZodSchema ? PRPCClientError<ZObj> : PRPCClientError,
Infer$PayLoad<ZObj>
>
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/prpc/solid/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export const query$ = <
input ? JSON.stringify(input()) : undefined,
],
...((opts?.() ?? {}) as any),
})) as CreateQueryResult<Fn$Output<Fn, ZObj, Mw>>
})) as unknown as CreateQueryResult<
Fn$Output<Fn, ZObj, Mw>,
ZObj extends ZodSchema ? PRPCClientError<ZObj> : PRPCClientError
>
}
return new Proxy(actualFn, {
get(target, prop) {
Expand Down
13 changes: 11 additions & 2 deletions packages/prpc/solid/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Accessor } from 'solid-js'
import { FCreateQueryOptions } from './query'
import { CreateMutationResult, CreateQueryResult } from '@tanstack/solid-query'
import { FCreateMutationOptions } from './mutation'
import { ZodSchema } from 'zod'
import { PRPCClientError } from './error'

export type EmptySchema = void | undefined

Expand Down Expand Up @@ -97,14 +99,21 @@ export type QueryBuilder<
? EmptySchema
: Accessor<Infer$PayLoad<ZObj>>,
opts?: FCreateQueryOptions<ZObj, Infer$PayLoad<ZObj>>,
): CreateQueryResult<Fn$Output<Fn, ZObj, Mws>>
): CreateQueryResult<
Fn$Output<Fn, ZObj, Mws>,
ZObj extends ZodSchema ? PRPCClientError<ZObj> : PRPCClientError
>
}
: {}) &
(BuilderType extends 'mutation'
? {
(
opts?: FCreateMutationOptions<ZObj, Infer$PayLoad<ZObj>>,
): CreateMutationResult<Fn$Output<Fn, ZObj, Mws>>
): CreateMutationResult<
Fn$Output<Fn, ZObj, Mws>,
ZObj extends ZodSchema ? PRPCClientError<ZObj> : PRPCClientError,
Infer$PayLoad<ZObj>
>
}
: {} & BuilderType extends void
? {
Expand Down

0 comments on commit e4f7bc4

Please sign in to comment.