mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-25 17:30:33 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9c5307e23 | ||
|
|
bbdabf544c | ||
|
|
aed10ac5b8 | ||
|
|
4b2c714658 | ||
|
|
43e9fefdbd | ||
|
|
dabda23976 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "trpc-nuxt",
|
"name": "trpc-nuxt",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.1.19",
|
"version": "0.1.22",
|
||||||
"packageManager": "pnpm@7.1.1",
|
"packageManager": "pnpm@7.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/module.cjs",
|
"main": "./dist/module.cjs",
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import type {
|
|||||||
import type { ProcedureRecord, inferHandlerInput, inferProcedureInput, inferProcedureOutput } from '@trpc/server'
|
import type { ProcedureRecord, inferHandlerInput, inferProcedureInput, inferProcedureOutput } from '@trpc/server'
|
||||||
import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client'
|
import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client'
|
||||||
import { objectHash } from 'ohash'
|
import { objectHash } from 'ohash'
|
||||||
import type { MaybeRef } from '@vueuse/core'
|
import type { Ref } from 'vue'
|
||||||
import { useStorage } from '@vueuse/core'
|
|
||||||
import { useAsyncData, useNuxtApp, useState } from '#app'
|
import { useAsyncData, useNuxtApp, useState } from '#app'
|
||||||
import type { router } from '~/server/trpc'
|
import type { router } from '~/server/trpc'
|
||||||
|
|
||||||
|
type MaybeRef<T> = T | Ref<T>
|
||||||
|
|
||||||
type AppRouter = typeof router
|
type AppRouter = typeof router
|
||||||
|
|
||||||
export type inferProcedures<
|
export type inferProcedures<
|
||||||
@@ -29,13 +30,6 @@ export type TError = TRPCClientErrorLike<AppRouter>
|
|||||||
|
|
||||||
export type TQueryValues = inferProcedures<AppRouter['_def']['queries']>
|
export type TQueryValues = inferProcedures<AppRouter['_def']['queries']>
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional header properties to pass to tRPC client.
|
|
||||||
*
|
|
||||||
* @see https://trpc.io/docs/vanilla
|
|
||||||
* @param pathAndInput tRPC client path and input.
|
|
||||||
* @param options Options to pass to useAsyncData.
|
|
||||||
*/
|
|
||||||
export async function useAsyncQuery<
|
export async function useAsyncQuery<
|
||||||
TPath extends keyof TQueryValues & string,
|
TPath extends keyof TQueryValues & string,
|
||||||
TOutput extends TQueryValues[TPath]['output'] = TQueryValues[TPath]['output'],
|
TOutput extends TQueryValues[TPath]['output'] = TQueryValues[TPath]['output'],
|
||||||
@@ -68,22 +62,11 @@ export async function useAsyncQuery<
|
|||||||
} as any
|
} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* tRPC Client.
|
|
||||||
*
|
|
||||||
* @see https://trpc.io/docs/vanilla
|
|
||||||
*/
|
|
||||||
export function useClient(): TRPCClient<AppRouter> {
|
export function useClient(): TRPCClient<AppRouter> {
|
||||||
const { $client } = useNuxtApp()
|
const { $client } = useNuxtApp()
|
||||||
return $client
|
return $client
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export function useClientHeaders(initialValue: MaybeRef<Record<string, any>> = {}): Ref<Record<string, any>> {
|
||||||
* Additional header properties to pass to tRPC client.
|
return useStorage('trpc-nuxt-header', initialValue)
|
||||||
*
|
|
||||||
* @see https://github.com/trpc/trpc/discussions/1686
|
|
||||||
* @param initialValue
|
|
||||||
*/
|
|
||||||
export function useClientHeaders(initialValue?: MaybeRef<Record<string, any>>) {
|
|
||||||
return useStorage('trpc-nuxt-header', initialValue || {})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user