Compare commits

..

8 Commits

Author SHA1 Message Date
Robert Soriano
977a9e1465 release v0.1.24 2022-06-05 17:05:34 -07:00
Robert Soriano
2620379e02 feat: allow changing of src dir 2022-06-05 17:05:13 -07:00
Robert Soriano
e4f42d5322 Merge pull request #10 from nicolesmileyface/feat/support-src-dir
use nuxt srcDir instead of rootDir
2022-06-05 17:02:41 -07:00
Cole Hollant
ad28a9124e use nuxt srcDir instead of rootDir 2022-06-05 11:55:25 -04:00
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
4 changed files with 18 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.1.21",
"version": "0.1.24",
"packageManager": "pnpm@7.1.1",
"license": "MIT",
"main": "./dist/module.cjs",
@@ -37,6 +37,7 @@
"@trpc/server": "^9.23.2",
"@vueuse/core": "^8.5.0",
"@vueuse/nuxt": "^8.5.0",
"dedent": "^0.7.0",
"defu": "^6.0.0",
"h3": "^0.7.8",
"pathe": "^0.3.0",

8
pnpm-lock.yaml generated
View File

@@ -13,6 +13,7 @@ importers:
'@vueuse/core': ^8.5.0
'@vueuse/nuxt': ^8.5.0
bumpp: ^7.1.1
dedent: ^0.7.0
defu: ^6.0.0
eslint: ^8.14.0
h3: ^0.7.8
@@ -30,6 +31,7 @@ importers:
'@trpc/server': 9.23.4
'@vueuse/core': 8.5.0
'@vueuse/nuxt': 8.5.0
dedent: 0.7.0
defu: 6.0.0
h3: 0.7.8
pathe: 0.3.0
@@ -2077,6 +2079,10 @@ packages:
engines: {node: '>=0.10'}
dev: true
/dedent/0.7.0:
resolution: {integrity: sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA==}
dev: false
/deep-extend/0.6.0:
resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==}
engines: {node: '>=4.0.0'}
@@ -3794,7 +3800,7 @@ packages:
dev: true
/is-module/1.0.0:
resolution: {integrity: sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=}
resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==}
dev: true
/is-negative-zero/2.0.2:

View File

@@ -1,6 +1,8 @@
import { fileURLToPath } from 'url'
import { join, resolve } from 'pathe'
import { defu } from 'defu'
// @ts-expect-error: No types
import dedent from 'dedent'
import { addPlugin, addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit'
@@ -23,7 +25,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.build.transpile.push(runtimeDir, '#build/trpc-handler')
const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
const trpcOptionsPath = join(nuxt.options.rootDir, 'server/trpc')
const trpcOptionsPath = join(nuxt.options.srcDir, 'server/trpc')
// Add vueuse
nuxt.options.modules.push('@vueuse/nuxt')
@@ -53,7 +55,7 @@ export default defineNuxtModule<ModuleOptions>({
filename: 'trpc-handler.ts',
write: true,
getContents() {
return `
return dedent`
import { createTRPCHandler } from 'trpc-nuxt/api'
import * as functions from '${trpcOptionsPath}'

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)
}