mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-02-02 13:17:55 +01:00
feat: add helper types
This commit is contained in:
@@ -78,6 +78,12 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
`
|
`
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
addTemplate({
|
||||||
|
filename: 'trpc-helpers.ts',
|
||||||
|
write: true,
|
||||||
|
src: join(runtimeDir, 'helpers.d.ts'),
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
71
src/runtime/helpers.d.ts
vendored
Normal file
71
src/runtime/helpers.d.ts
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import type { inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server'
|
||||||
|
// @ts-expect-error: Resolved by Nuxt
|
||||||
|
import type { router } from '~/server/trpc'
|
||||||
|
|
||||||
|
type AppRouter = typeof router
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum containing all api query paths
|
||||||
|
*/
|
||||||
|
export type TQuery = keyof AppRouter['_def']['queries']
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum containing all api mutation paths
|
||||||
|
*/
|
||||||
|
export type TMutation = keyof AppRouter['_def']['mutations']
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum containing all api subscription paths
|
||||||
|
*/
|
||||||
|
export type TSubscription = keyof AppRouter['_def']['subscriptions']
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the output of a query resolver
|
||||||
|
* @example type HelloOutput = InferQueryOutput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferQueryOutput<TRouteKey extends TQuery> = inferProcedureOutput<
|
||||||
|
AppRouter['_def']['queries'][TRouteKey]
|
||||||
|
>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the input of a query resolver
|
||||||
|
* @example type HelloInput = InferQueryInput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferQueryInput<TRouteKey extends TQuery> = inferProcedureInput<
|
||||||
|
AppRouter['_def']['queries'][TRouteKey]
|
||||||
|
>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the output of a mutation resolver
|
||||||
|
* @example type HelloOutput = InferMutationOutput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferMutationOutput<TRouteKey extends TMutation> =
|
||||||
|
inferProcedureOutput<AppRouter['_def']['mutations'][TRouteKey]>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the input of a mutation resolver
|
||||||
|
* @example type HelloInput = InferMutationInput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferMutationInput<TRouteKey extends TMutation> =
|
||||||
|
inferProcedureInput<AppRouter['_def']['mutations'][TRouteKey]>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the output of a subscription resolver
|
||||||
|
* @example type HelloOutput = InferSubscriptionOutput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferSubscriptionOutput<TRouteKey extends TSubscription> =
|
||||||
|
inferProcedureOutput<AppRouter['_def']['subscriptions'][TRouteKey]>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the asynchronous output of a subscription resolver
|
||||||
|
* @example type HelloAsyncOutput = InferAsyncSubscriptionOutput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferAsyncSubscriptionOutput<TRouteKey extends TSubscription> =
|
||||||
|
inferSubscriptionOutput<AppRouter, TRouteKey>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method to infer the input of a subscription resolver
|
||||||
|
* @example type HelloInput = InferSubscriptionInput<'hello'>
|
||||||
|
*/
|
||||||
|
export type InferSubscriptionInput<TRouteKey extends TSubscription> =
|
||||||
|
inferProcedureInput<AppRouter['_def']['subscriptions'][TRouteKey]>
|
||||||
Reference in New Issue
Block a user