Compare commits

...

6 Commits

Author SHA1 Message Date
Robert Soriano
9c8509f79c release v0.1.23 2022-05-27 08:53:18 -07:00
Robert Soriano
2ce29137ce fix: unimported composable 2022-05-27 08:41:14 -07:00
Robert Soriano
e9c5307e23 release v0.1.22 2022-05-27 01:10:10 -07:00
Robert Soriano
bbdabf544c fix: type inference bug with vueuse 2022-05-27 01:10:06 -07:00
Robert Soriano
aed10ac5b8 release v0.1.21 2022-05-27 00:56:58 -07:00
Robert Soriano
4b2c714658 fix: remove module export 2022-05-27 00:56:53 -07:00
2 changed files with 6 additions and 23 deletions

View File

@@ -1,11 +1,10 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.1.20",
"version": "0.1.23",
"packageManager": "pnpm@7.1.1",
"license": "MIT",
"main": "./dist/module.cjs",
"module": "./dist/module.mjs",
"types": "./dist/types.d.ts",
"exports": {
"./package.json": "./package.json",

View File

@@ -8,11 +8,13 @@ import type {
import type { ProcedureRecord, inferHandlerInput, inferProcedureInput, inferProcedureOutput } from '@trpc/server'
import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client'
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 type { router } from '~/server/trpc'
type MaybeRef<T> = T | Ref<T>
type AppRouter = typeof router
export type inferProcedures<
@@ -29,13 +31,6 @@ export type TError = TRPCClientErrorLike<AppRouter>
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<
TPath extends keyof TQueryValues & string,
TOutput extends TQueryValues[TPath]['output'] = TQueryValues[TPath]['output'],
@@ -68,22 +63,11 @@ export async function useAsyncQuery<
} as any
}
/**
* tRPC Client.
*
* @see https://trpc.io/docs/vanilla
*/
export function useClient(): TRPCClient<AppRouter> {
const { $client } = useNuxtApp()
return $client
}
/**
* Additional header properties to pass to tRPC client.
*
* @see https://github.com/trpc/trpc/discussions/1686
* @param initialValue
*/
export function useClientHeaders(initialValue?: MaybeRef<Record<string, any>>) {
return useStorage('trpc-nuxt-header', initialValue || {})
export function useClientHeaders(initialValue: MaybeRef<Record<string, any>> = {}): Ref<Record<string, any>> {
return useStorage('trpc-nuxt-header', initialValue)
}