mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-26 01:40:31 +01:00
update readme
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { dirname, join } from 'pathe'
|
||||
|
||||
import { addServerHandler, defineNuxtModule } from '@nuxt/kit'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
@@ -28,6 +29,7 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
{ name: 'useTrpcQuery', from: clientPath },
|
||||
{ name: 'useLazyTrpcQuery', from: clientPath },
|
||||
{ name: 'useTrpcMutation', from: clientPath },
|
||||
{ name: 'useClient', from: clientPath },
|
||||
)
|
||||
})
|
||||
|
||||
@@ -45,13 +47,15 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
const {
|
||||
useTrpcQuery,
|
||||
useLazyTrpcQuery,
|
||||
useTrpcMutation
|
||||
useTrpcMutation,
|
||||
useClient
|
||||
} = createTRPCComposables<typeof router>(client)
|
||||
|
||||
export {
|
||||
useTrpcQuery,
|
||||
useLazyTrpcQuery,
|
||||
useTrpcMutation
|
||||
useTrpcMutation,
|
||||
useClient
|
||||
}
|
||||
`)
|
||||
|
||||
@@ -67,3 +71,4 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
`)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ export function createTRPCComposables<
|
||||
ProcedureInput = inferProcedureInput<Router['_def']['queries'][TRouteKey]>,
|
||||
ProcedureOutput = inferProcedureOutput<Router['_def']['queries'][TRouteKey]>,
|
||||
>(
|
||||
args_0: TRouteKey,
|
||||
args_1: ProcedureInput
|
||||
path: TRouteKey,
|
||||
input: ProcedureInput
|
||||
) => AsyncData<
|
||||
PickFrom<
|
||||
ProcedureOutput,
|
||||
@@ -32,8 +32,8 @@ export function createTRPCComposables<
|
||||
ProcedureInput = inferProcedureInput<Router['_def']['queries'][TRouteKey]>,
|
||||
ProcedureOutput = inferProcedureOutput<Router['_def']['queries'][TRouteKey]>,
|
||||
>(
|
||||
args_0: TRouteKey,
|
||||
args_1: ProcedureInput
|
||||
path: TRouteKey,
|
||||
input: ProcedureInput
|
||||
) => AsyncData<
|
||||
PickFrom<
|
||||
ProcedureOutput,
|
||||
@@ -50,8 +50,8 @@ export function createTRPCComposables<
|
||||
Router['_def']['mutations'][TRouteKey]
|
||||
>,
|
||||
>(
|
||||
args_0: TRouteKey,
|
||||
args_1: ProcedureInput
|
||||
path: TRouteKey,
|
||||
input: ProcedureInput
|
||||
) => AsyncData<
|
||||
PickFrom<
|
||||
ProcedureOutput,
|
||||
@@ -59,6 +59,7 @@ export function createTRPCComposables<
|
||||
>,
|
||||
true | Error
|
||||
>
|
||||
useClient: () => Client
|
||||
}
|
||||
|
||||
export function createTRPCComposables(client: any) {
|
||||
@@ -74,9 +75,12 @@ export function createTRPCComposables(client: any) {
|
||||
return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.mutation(...args))
|
||||
}
|
||||
|
||||
const useClient = () => client
|
||||
|
||||
return {
|
||||
useTrpcQuery,
|
||||
useLazyTrpcQuery,
|
||||
useTrpcMutation,
|
||||
useClient,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user