Compare commits

..

12 Commits

Author SHA1 Message Date
Robert Soriano
fd9b86fb18 release v0.3.1 2022-10-21 12:27:16 -07:00
Robert Soriano
5fab0e54b0 update local deps 2022-10-21 12:24:18 -07:00
Robert Soriano
7d2f464699 Merge pull request #34 from mahdiboomeri/chore
chore: bump nuxt to RC 12
2022-10-21 08:10:53 -07:00
Mahdi Boomeri
fdb9c2b474 refactor: playground nuxt.config 2022-10-21 17:00:22 +03:30
Mahdi Boomeri
4ed504e1e9 fix: h3 CompatibilityEvent 2022-10-21 16:56:09 +03:30
Mahdi Boomeri
92747711c6 chore: bump other deps 2022-10-21 16:53:53 +03:30
Mahdi Boomeri
3646e8cdfe chore: nump nuxt 2022-10-21 16:43:22 +03:30
Robert Soriano
09e8ab536a feat: replace useBody with readBody 2022-10-01 09:15:36 -07:00
Robert Soriano
f7dadd482d Update README.md 2022-09-29 10:20:05 -07:00
Robert Soriano
7b69cff1ed Merge pull request #30 from cawa-93/patch-1
docs: Fix `baseURL` in code sample
2022-09-27 10:18:15 -07:00
Alex Kozack
f2d7763fa4 docs: Fix baseURL in code sample 2022-09-27 10:41:38 +03:00
Robert Soriano
20f5a08cbd update readme 2022-09-24 08:26:36 -07:00
7 changed files with 995 additions and 1002 deletions

View File

@@ -15,8 +15,6 @@ End-to-end typesafe APIs with [tRPC.io](https://trpc.io/) in Nuxt applications.
</figure>
</p>
**⚠️ Currently works on Node v16 until [this issue](https://github.com/trpc/trpc/issues/2420) gets fixed.**
## Install
```bash
@@ -30,7 +28,7 @@ import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
modules: ['trpc-nuxt'],
trpc: {
baseURL: 'http://localhost:3000', // defaults to http://localhost:3000
baseURL: '', // Set empty string (default) to make requests by relative address
endpoint: '/trpc', // defaults to /trpc
},
typescript: {
@@ -122,14 +120,14 @@ trpc-nuxt accepts the following options exposed under `~/server/trpc/index.ts`:
```ts
import * as trpc from '@trpc/server'
import type { inferAsyncReturnType } from '@trpc/server'
import type { CompatibilityEvent } from 'h3'
import type { H3Event } from 'h3'
import type { OnErrorPayload } from 'trpc-nuxt/api'
export const router = trpc.router<inferAsyncReturnType<typeof createContext>>()
// Optional
// https://trpc.io/docs/context
export const createContext = (event: CompatibilityEvent) => {
export const createContext = (event: H3Event) => {
// ...
return {
/** context data */
@@ -161,7 +159,7 @@ export const onError = (payload: OnErrorPayload<typeof router>) => {
- [Error Formatting](/recipes/error-formatting.md)
- [Inference Helpers](/recipes/inference-helpers.md)
Learn more about tRPC.io [here](https://trpc.io/docs).
Learn more about tRPC.io [here](https://trpc.io/docs/v9).
## Recommended IDE Setup

View File

@@ -1,7 +1,7 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.3.0",
"version": "0.3.1",
"packageManager": "pnpm@7.5.0",
"license": "MIT",
"main": "./dist/module.cjs",
@@ -32,27 +32,27 @@
"prepare": "nuxi prepare playground"
},
"dependencies": {
"@nuxt/kit": "3.0.0-rc.11",
"@trpc/client": "^9.27.2",
"@trpc/server": "^9.27.2",
"@nuxt/kit": "3.0.0-rc.12",
"@trpc/client": "^9.27.4",
"@trpc/server": "^9.27.4",
"dedent": "^0.7.0",
"defu": "^6.0.0",
"h3": "^0.7.21",
"defu": "^6.1.0",
"h3": "^0.8.5",
"ohash": "^0.1.5",
"pathe": "^0.3.0",
"ufo": "^0.8.5"
"pathe": "^0.3.9",
"ufo": "^0.8.6"
},
"devDependencies": {
"@antfu/eslint-config": "^0.23.1",
"@antfu/ni": "^0.16.2",
"@nuxt/module-builder": "^0.1.7",
"@nuxt/module-builder": "^0.2.0",
"@types/dedent": "^0.7.0",
"bumpp": "^7.2.0",
"eslint": "^8.14.0",
"nuxt": "3.0.0-rc.11",
"eslint": "^8.25.0",
"nuxt": "3.0.0-rc.12",
"pnpm": "^7.5.0",
"trpc-nuxt": "workspace:*",
"zod": "^3.16.0"
"zod": "^3.19.1"
},
"eslintConfig": {
"extends": "@antfu",

View File

@@ -1,4 +1,3 @@
import { defineNuxtConfig } from 'nuxt'
import Module from '../src/module'
// https://v3.nuxtjs.org/api/configuration/nuxt.config

View File

@@ -1,7 +1,7 @@
import * as trpc from '@trpc/server'
import type { inferAsyncReturnType } from '@trpc/server'
import { z } from 'zod'
import type { CompatibilityEvent } from 'h3'
import type { H3Event } from 'h3'
const baseURL = 'https://jsonplaceholder.typicode.com'
@@ -37,7 +37,7 @@ export const router = trpc.router<Context>()
},
})
export async function createContext(event: CompatibilityEvent) {
export async function createContext(event: H3Event) {
// Create your context based on the request object
// Will be available as `ctx` in all your resolvers

1944
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,11 +7,11 @@ The `createContext`-function is called for each incoming request so here you can
```ts
// ~/server/trpc/index.ts
import type { inferAsyncReturnType } from '@trpc/server'
import type { CompatibilityEvent } from 'h3'
import type { H3Event } from 'h3'
import { decodeAndVerifyJwtToken } from '~/somewhere/in/your/app/utils'
// The app's context - is generated for each incoming request
export async function createContext({ req }: CompatibilityEvent) {
export async function createContext({ req }: H3Event) {
// Create your context based on the request object
// Will be available as `ctx` in all your resolvers

View File

@@ -8,13 +8,13 @@ import type {
inferRouterError,
} from '@trpc/server'
import { createURL } from 'ufo'
import type { CompatibilityEvent } from 'h3'
import { defineEventHandler, isMethod, useBody } from 'h3'
import type { H3Event } from 'h3'
import { defineEventHandler, isMethod, readBody } from 'h3'
import type { TRPCResponse } from '@trpc/server/dist/declarations/src/rpc'
type MaybePromise<T> = T | Promise<T>
export type CreateContextFn<TRouter extends AnyRouter> = (event: CompatibilityEvent) => MaybePromise<inferRouterContext<TRouter>>
export type CreateContextFn<TRouter extends AnyRouter> = (event: H3Event) => MaybePromise<inferRouterContext<TRouter>>
export interface ResponseMetaFnPayload<TRouter extends AnyRouter> {
data: TRPCResponse<unknown, inferRouterError<TRouter>>[]
@@ -30,7 +30,7 @@ export interface OnErrorPayload<TRouter extends AnyRouter> {
error: TRPCError
type: ProcedureType | 'unknown'
path: string | undefined
req: CompatibilityEvent['req']
req: H3Event['req']
input: unknown
ctx: undefined | inferRouterContext<TRouter>
}
@@ -63,7 +63,7 @@ export function createTRPCHandler<Router extends AnyRouter>({
req: {
method: req.method!,
headers: req.headers,
body: isMethod(event, 'GET') ? null : await useBody(event),
body: isMethod(event, 'GET') ? null : await readBody(event),
query: $url.searchParams,
},
path: $url.pathname.substring(endpoint.length + 1),