Compare commits

..

7 Commits

Author SHA1 Message Date
wobsoriano
0bb648bb08 chore: release v0.3.7 2022-12-21 09:15:38 -08:00
wobsoriano
ca2344ad86 add prepublish script 2022-12-21 09:12:53 -08:00
wobsoriano
004e655194 more cleanup 2022-12-20 20:14:58 -08:00
wobsoriano
fca82a027e chore: release v0.3.6 2022-12-20 20:13:53 -08:00
wobsoriano
7995e892db feat: replace ohmyfetch with ofetch 2022-12-20 20:13:48 -08:00
wobsoriano
8168a46985 chore: release v0.3.5 2022-12-20 01:37:21 -08:00
wobsoriano
2a23f4303d import composables from #app to #imports 2022-12-20 01:37:12 -08:00
8 changed files with 19 additions and 18 deletions

View File

@@ -1,10 +1,8 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.3.4",
"version": "0.3.7",
"license": "MIT",
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
@@ -16,6 +14,8 @@
"import": "./dist/runtime/api.mjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist",
"*.d.ts"
@@ -29,7 +29,8 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"release": "bumpp --commit --push --tag && npm publish",
"prepare": "nuxi prepare playground"
"prepare": "nuxi prepare playground",
"prepublishOnly": "pnpm build"
},
"peerDependencies": {
"@trpc/client": "<10.0.0",
@@ -42,6 +43,7 @@
"dedent": "^0.7.0",
"defu": "^6.1.1",
"h3": "^1.0.2",
"ofetch": "^1.0.0",
"ohash": "^1.0.0",
"pathe": "^1.0.0",
"ufo": "^1.0.1"

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useClient, useClientHeaders, useAsyncQuery } from '#imports'
import { useAsyncQuery, useClient, useClientHeaders } from '#imports'
const client = useClient()
const headers = useClientHeaders()
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useRoute, useAsyncQuery } from '#imports'
import { useAsyncQuery, useRoute } from '#imports'
const route = useRoute()
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
</script>

View File

@@ -29,7 +29,6 @@ export const router = trpc.router<Context>()
.mutation('addTodo', {
input: TodoShape,
async resolve(req) {
console.log(req.input)
return await $fetch<Todo>(`${baseURL}/todos`, {
method: 'POST',
body: req.input,
@@ -43,7 +42,7 @@ export async function createContext(event: H3Event) {
// This is just an example of something you'd might want to do in your ctx fn
// const x = useCookies(event)
console.log(event.req.headers)
console.log(event.node.req.headers)
return {

3
pnpm-lock.yaml generated
View File

@@ -16,6 +16,7 @@ importers:
eslint: ^8.25.0
h3: ^1.0.2
nuxt: 3.0.0
ofetch: ^1.0.0
ohash: ^1.0.0
pathe: ^1.0.0
ufo: ^1.0.1
@@ -27,6 +28,7 @@ importers:
dedent: 0.7.0
defu: 6.1.1
h3: 1.0.2
ofetch: 1.0.0
ohash: 1.0.0
pathe: 1.0.0
ufo: 1.0.1
@@ -4505,7 +4507,6 @@ packages:
destr: 1.2.2
node-fetch-native: 1.0.1
ufo: 1.0.1
dev: true
/ohash/1.0.0:
resolution: {integrity: sha512-kxSyzq6tt+6EE/xCnD1XaFhCCjUNUaz3X30rJp6mnjGLXAAvuPFqohMdv0aScWzajR45C29HyBaXZ8jXBwnh9A==}

View File

@@ -26,12 +26,12 @@ export default defineNuxtModule<ModuleOptions>({
async setup(options, nuxt) {
const logger = useLogger(metaName)
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
nuxt.options.build.transpile.push(runtimeDir)
const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
const trpcOptionsPath = join(nuxt.options.srcDir, 'server/trpc')
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
nuxt.options.build.transpile.push(runtimeDir, handlerPath)
// Final resolved configuration
const finalConfig = nuxt.options.runtimeConfig.public.trpc = defu(nuxt.options.runtimeConfig.public.trpc, {
baseURL: options.baseURL,
@@ -49,8 +49,8 @@ export default defineNuxtModule<ModuleOptions>({
write: true,
getContents() {
return dedent`
import { createTRPCHandler } from ${JSON.stringify(join(runtimeDir, 'api'))}
import * as functions from '${trpcOptionsPath}'
import { createTRPCHandler } from ${JSON.stringify(join(runtimeDir, 'api'))};
import * as functions from ${JSON.stringify(trpcOptionsPath)};
export default createTRPCHandler({
...functions,
@@ -77,4 +77,3 @@ export default defineNuxtModule<ModuleOptions>({
}
},
})

View File

@@ -9,7 +9,7 @@ import type { ProcedureRecord, inferHandlerInput, inferProcedureInput, inferProc
import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client'
import { objectHash } from 'ohash'
import type { Ref } from 'vue'
import { useAsyncData, useNuxtApp, useState } from '#app'
import { useAsyncData, useNuxtApp, useState } from '#imports'
import type { router } from '~/server/trpc'
type MaybeRef<T> = T | Ref<T>

View File

@@ -1,8 +1,8 @@
import * as trpc from '@trpc/client'
import { unref } from 'vue'
import { FetchError } from 'ohmyfetch'
import { FetchError } from 'ofetch'
import { useClientHeaders } from './client'
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app'
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#imports'
import type { router } from '~/server/trpc'
declare type AppRouter = typeof router