mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-21 07:21:43 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bb648bb08 | ||
|
|
ca2344ad86 | ||
|
|
004e655194 | ||
|
|
fca82a027e | ||
|
|
7995e892db |
10
package.json
10
package.json
@@ -1,10 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "trpc-nuxt",
|
"name": "trpc-nuxt",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.3.5",
|
"version": "0.3.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/module.cjs",
|
|
||||||
"types": "./dist/types.d.ts",
|
|
||||||
"exports": {
|
"exports": {
|
||||||
"./package.json": "./package.json",
|
"./package.json": "./package.json",
|
||||||
".": {
|
".": {
|
||||||
@@ -16,6 +14,8 @@
|
|||||||
"import": "./dist/runtime/api.mjs"
|
"import": "./dist/runtime/api.mjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"main": "./dist/module.cjs",
|
||||||
|
"types": "./dist/types.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"*.d.ts"
|
"*.d.ts"
|
||||||
@@ -29,7 +29,8 @@
|
|||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"lint:fix": "eslint . --fix",
|
"lint:fix": "eslint . --fix",
|
||||||
"release": "bumpp --commit --push --tag && npm publish",
|
"release": "bumpp --commit --push --tag && npm publish",
|
||||||
"prepare": "nuxi prepare playground"
|
"prepare": "nuxi prepare playground",
|
||||||
|
"prepublishOnly": "pnpm build"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@trpc/client": "<10.0.0",
|
"@trpc/client": "<10.0.0",
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
"dedent": "^0.7.0",
|
"dedent": "^0.7.0",
|
||||||
"defu": "^6.1.1",
|
"defu": "^6.1.1",
|
||||||
"h3": "^1.0.2",
|
"h3": "^1.0.2",
|
||||||
|
"ofetch": "^1.0.0",
|
||||||
"ohash": "^1.0.0",
|
"ohash": "^1.0.0",
|
||||||
"pathe": "^1.0.0",
|
"pathe": "^1.0.0",
|
||||||
"ufo": "^1.0.1"
|
"ufo": "^1.0.1"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useClient, useClientHeaders, useAsyncQuery } from '#imports'
|
import { useAsyncQuery, useClient, useClientHeaders } from '#imports'
|
||||||
const client = useClient()
|
const client = useClient()
|
||||||
const headers = useClientHeaders()
|
const headers = useClientHeaders()
|
||||||
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
|
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRoute, useAsyncQuery } from '#imports'
|
import { useAsyncQuery, useRoute } from '#imports'
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
|
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ export const router = trpc.router<Context>()
|
|||||||
.mutation('addTodo', {
|
.mutation('addTodo', {
|
||||||
input: TodoShape,
|
input: TodoShape,
|
||||||
async resolve(req) {
|
async resolve(req) {
|
||||||
console.log(req.input)
|
|
||||||
return await $fetch<Todo>(`${baseURL}/todos`, {
|
return await $fetch<Todo>(`${baseURL}/todos`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: req.input,
|
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
|
// This is just an example of something you'd might want to do in your ctx fn
|
||||||
// const x = useCookies(event)
|
// const x = useCookies(event)
|
||||||
console.log(event.req.headers)
|
console.log(event.node.req.headers)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
|
|||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -16,6 +16,7 @@ importers:
|
|||||||
eslint: ^8.25.0
|
eslint: ^8.25.0
|
||||||
h3: ^1.0.2
|
h3: ^1.0.2
|
||||||
nuxt: 3.0.0
|
nuxt: 3.0.0
|
||||||
|
ofetch: ^1.0.0
|
||||||
ohash: ^1.0.0
|
ohash: ^1.0.0
|
||||||
pathe: ^1.0.0
|
pathe: ^1.0.0
|
||||||
ufo: ^1.0.1
|
ufo: ^1.0.1
|
||||||
@@ -27,6 +28,7 @@ importers:
|
|||||||
dedent: 0.7.0
|
dedent: 0.7.0
|
||||||
defu: 6.1.1
|
defu: 6.1.1
|
||||||
h3: 1.0.2
|
h3: 1.0.2
|
||||||
|
ofetch: 1.0.0
|
||||||
ohash: 1.0.0
|
ohash: 1.0.0
|
||||||
pathe: 1.0.0
|
pathe: 1.0.0
|
||||||
ufo: 1.0.1
|
ufo: 1.0.1
|
||||||
@@ -4505,7 +4507,6 @@ packages:
|
|||||||
destr: 1.2.2
|
destr: 1.2.2
|
||||||
node-fetch-native: 1.0.1
|
node-fetch-native: 1.0.1
|
||||||
ufo: 1.0.1
|
ufo: 1.0.1
|
||||||
dev: true
|
|
||||||
|
|
||||||
/ohash/1.0.0:
|
/ohash/1.0.0:
|
||||||
resolution: {integrity: sha512-kxSyzq6tt+6EE/xCnD1XaFhCCjUNUaz3X30rJp6mnjGLXAAvuPFqohMdv0aScWzajR45C29HyBaXZ8jXBwnh9A==}
|
resolution: {integrity: sha512-kxSyzq6tt+6EE/xCnD1XaFhCCjUNUaz3X30rJp6mnjGLXAAvuPFqohMdv0aScWzajR45C29HyBaXZ8jXBwnh9A==}
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
async setup(options, nuxt) {
|
async setup(options, nuxt) {
|
||||||
const logger = useLogger(metaName)
|
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 handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
|
||||||
const trpcOptionsPath = join(nuxt.options.srcDir, 'server/trpc')
|
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
|
// Final resolved configuration
|
||||||
const finalConfig = nuxt.options.runtimeConfig.public.trpc = defu(nuxt.options.runtimeConfig.public.trpc, {
|
const finalConfig = nuxt.options.runtimeConfig.public.trpc = defu(nuxt.options.runtimeConfig.public.trpc, {
|
||||||
baseURL: options.baseURL,
|
baseURL: options.baseURL,
|
||||||
@@ -49,8 +49,8 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
write: true,
|
write: true,
|
||||||
getContents() {
|
getContents() {
|
||||||
return dedent`
|
return dedent`
|
||||||
import { createTRPCHandler } from ${JSON.stringify(join(runtimeDir, 'api'))}
|
import { createTRPCHandler } from ${JSON.stringify(join(runtimeDir, 'api'))};
|
||||||
import * as functions from '${trpcOptionsPath}'
|
import * as functions from ${JSON.stringify(trpcOptionsPath)};
|
||||||
|
|
||||||
export default createTRPCHandler({
|
export default createTRPCHandler({
|
||||||
...functions,
|
...functions,
|
||||||
@@ -77,4 +77,3 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as trpc from '@trpc/client'
|
import * as trpc from '@trpc/client'
|
||||||
import { unref } from 'vue'
|
import { unref } from 'vue'
|
||||||
import { FetchError } from 'ohmyfetch'
|
import { FetchError } from 'ofetch'
|
||||||
import { useClientHeaders } from './client'
|
import { useClientHeaders } from './client'
|
||||||
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#imports'
|
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#imports'
|
||||||
import type { router } from '~/server/trpc'
|
import type { router } from '~/server/trpc'
|
||||||
|
|||||||
Reference in New Issue
Block a user