Compare commits

...

13 Commits

Author SHA1 Message Date
25e09b2e30 Update example and playground dependencies 2023-08-31 14:11:23 +02:00
0612716187 Update dependencies 2023-08-31 13:56:19 +02:00
wobsoriano
55712e3027 chore(release): v0.10.12 2023-08-23 14:18:33 -07:00
wobsoriano
0fec55a3ae refactor: explicitly copy headers to custom fetcher 2023-08-23 14:18:12 -07:00
wobsoriano
8f9e398ae2 fix: expect ofetch missing error response type 2023-08-23 14:12:29 -07:00
wobsoriano
092e3495fd build(deps): bump ofetch to 1.3.2 2023-08-23 13:44:22 -07:00
wobsoriano
230422bb16 docs: fix incorrect syntax 2023-08-23 12:49:09 -07:00
wobsoriano
057c8f8d3a docs: fix missing title 2023-08-23 12:48:32 -07:00
wobsoriano
9808375f31 docs: add response caching page 2023-08-23 12:46:22 -07:00
wobsoriano
8e893a2e30 chore(release): v0.10.11 2023-08-22 10:52:53 -07:00
wobsoriano
f74273190f bump local deps 2023-08-22 10:52:41 -07:00
wobsoriano
283400d41a chore(deps): bump ohash to 1.1.3 2023-08-22 10:51:54 -07:00
wobsoriano
5221dc0515 chore(deps): bump ofetch to 1.2.0 2023-08-22 10:51:29 -07:00
10 changed files with 2554 additions and 901 deletions

View File

@@ -1,6 +1,48 @@
# Changelog # Changelog
## v0.10.12
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.11...v0.10.12)
### 🩹 Fixes
- Expect ofetch missing error response type ([8f9e398](https://github.com/wobsoriano/trpc-nuxt/commit/8f9e398))
### 💅 Refactors
- Explicitly copy headers to custom fetcher ([0fec55a](https://github.com/wobsoriano/trpc-nuxt/commit/0fec55a))
### 📖 Documentation
- Add response caching page ([9808375](https://github.com/wobsoriano/trpc-nuxt/commit/9808375))
- Fix missing title ([057c8f8](https://github.com/wobsoriano/trpc-nuxt/commit/057c8f8))
- Fix incorrect syntax ([230422b](https://github.com/wobsoriano/trpc-nuxt/commit/230422b))
### 📦 Build
- **deps:** Bump ofetch to 1.3.2 ([092e349](https://github.com/wobsoriano/trpc-nuxt/commit/092e349))
### ❤️ Contributors
- Wobsoriano ([@wobsoriano](http://github.com/wobsoriano))
## v0.10.11
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.10...v0.10.11)
### 🩹 Fixes
- Add missing useLazyQuery type ([299ae55](https://github.com/wobsoriano/trpc-nuxt/commit/299ae55))
### 📖 Documentation
- Bump @nuxt-themes/docus to 1.14.6 ([f7eeb10](https://github.com/wobsoriano/trpc-nuxt/commit/f7eeb10))
### ❤️ Contributors
- Wobsoriano ([@wobsoriano](http://github.com/wobsoriano))
## v0.10.10 ## v0.10.10
[compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.9...v0.10.10) [compare changes](https://github.com/wobsoriano/trpc-nuxt/compare/v0.10.9...v0.10.10)

View File

@@ -0,0 +1,51 @@
---
title: Response Caching
---
## Response Caching
Your server responses must [satisfy some criteria](https://vercel.com/docs/concepts/functions/serverless-functions/edge-caching) in order for them to be cached (i.e. by Vercel's Edge Network). Please refer to [this section of the tRPC.io documentation](https://trpc.io/docs/caching) for more information.
The `createNuxtApiHandler` function conveniently allows you to specify a `responseMeta` function.
```ts [server/api/trpc/[trpc].ts]
import { createNuxtApiHandler } from 'trpc-nuxt'
import { appRouter } from '~/server/trpc/routers'
export default createNuxtApiHandler({
router: appRouter,
/**
* @link https://trpc.io/docs/caching#api-response-caching
*/
responseMeta(opts) {
// cache request for 1 day + revalidate once every second
const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
return {
headers: {
'cache-control': `s-maxage=1, stale-while-revalidate=${ONE_DAY_IN_SECONDS}`,
},
};
},
})
```
You can also take advantage of Nitro's [Cache API](https://nitro.unjs.io/guide/cache#cache-api) if doing server-side calls:
```ts
import { appRouter } from '@/server/trpc/routers'
const caller = appRouter.createCaller({})
export default cachedEventHandler(async (event) => {
const { name } = getQuery(event)
const greeting = await caller.greeting({ name })
return {
greeting
}
}, {
swr: true, maxAge: 10
})
```

View File

@@ -2,21 +2,21 @@
"name": "nuxt-app", "name": "nuxt-app",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "nuxt build", "build": "nuxi build",
"dev": "nuxt dev", "dev": "nuxi dev",
"generate": "nuxt generate", "generate": "nuxi generate",
"preview": "nuxt preview", "preview": "nuxi preview",
"postinstall": "nuxt prepare" "postinstall": "nuxi prepare"
}, },
"devDependencies": { "devDependencies": {
"@nuxt/devtools": "latest", "@nuxt/devtools": "latest",
"@types/node": "^20.4.2", "@types/node": "20.5.7",
"nuxt": "^3.6.5" "nuxt": "^3.7.0"
}, },
"dependencies": { "dependencies": {
"@trpc/client": "^10.35.0", "@trpc/client": "^10.38.1",
"@trpc/server": "^10.35.0", "@trpc/server": "^10.38.1",
"trpc-nuxt": "workspace:*", "trpc-nuxt": "workspace:*",
"zod": "^3.21.4" "zod": "^3.22.2"
} }
} }

View File

@@ -3,7 +3,7 @@
"description": "End-to-end typesafe APIs in Nuxt applications.", "description": "End-to-end typesafe APIs in Nuxt applications.",
"type": "module", "type": "module",
"packageManager": "pnpm@8.6.9", "packageManager": "pnpm@8.6.9",
"version": "0.10.10", "version": "0.10.12",
"license": "MIT", "license": "MIT",
"sideEffects": false, "sideEffects": false,
"exports": { "exports": {
@@ -35,23 +35,23 @@
"update-deps": "taze -w && pnpm i" "update-deps": "taze -w && pnpm i"
}, },
"peerDependencies": { "peerDependencies": {
"@trpc/client": "^10.26.0", "@trpc/client": "^10.38.1",
"@trpc/server": "^10.26.0" "@trpc/server": "^10.38.1"
}, },
"dependencies": { "dependencies": {
"h3": "^1.8.0", "h3": "^1.8.1",
"ofetch": "^1.1.1", "ofetch": "^1.3.3",
"ohash": "^1.1.2" "ohash": "^1.1.3"
}, },
"devDependencies": { "devDependencies": {
"@nuxt/eslint-config": "^0.1.1", "@nuxt/eslint-config": "^0.2.0",
"@trpc/client": "^10.37.1", "@trpc/client": "^10.38.1",
"@trpc/server": "^10.37.1", "@trpc/server": "^10.38.1",
"changelogen": "^0.5.4", "changelogen": "^0.5.5",
"eslint": "^8.45.0", "eslint": "^8.48.0",
"taze": "^0.11.2", "taze": "^0.11.2",
"tsup": "7.2.0", "tsup": "7.2.0",
"typescript": "^5.1.6" "typescript": "^5.2.2"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
@@ -74,9 +74,9 @@
], ],
"pnpm": { "pnpm": {
"overrides": { "overrides": {
"nuxt": "3.6.5", "nuxt": "3.7.0",
"@trpc/client": "10.37.1", "@trpc/client": "10.38.1",
"@trpc/server": "10.37.1" "@trpc/server": "10.38.1"
} }
} }
} }

View File

@@ -2,21 +2,21 @@
"name": "playground", "name": "playground",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "nuxt build", "build": "nuxi build",
"dev": "nuxt dev", "dev": "nuxi dev",
"generate": "nuxt generate", "generate": "nuxi generate",
"preview": "nuxt preview", "preview": "nuxi preview",
"postinstall": "nuxt prepare" "postinstall": "nuxi prepare"
}, },
"dependencies": { "dependencies": {
"@trpc/client": "^10.37.1", "@trpc/client": "10.38.1",
"@trpc/server": "^10.37.1", "@trpc/server": "10.38.1",
"superjson": "^1.13.1", "superjson": "^1.13.1",
"trpc-nuxt": "workspace:*", "trpc-nuxt": "workspace:*",
"zod": "^3.21.4" "zod": "^3.22.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.4.2", "@types/node": "20.5.7",
"nuxt": "3.6.5" "nuxt": "3.7.0"
} }
} }

View File

@@ -1,6 +1,6 @@
import { createNuxtApiHandler } from 'trpc-nuxt' import { createNuxtApiHandler } from 'trpc-nuxt'
import { appRouter } from '@/server/trpc/routers' import { appRouter } from '../../trpc/routers'
import { createContext } from '@/server/trpc/context' import { createContext } from '../../trpc/context'
export default createNuxtApiHandler({ export default createNuxtApiHandler({
router: appRouter, router: appRouter,

View File

@@ -1,5 +1,6 @@
import { z } from 'zod' import { z } from 'zod'
import { publicProcedure, router } from '../trpc' import { publicProcedure, router } from '../trpc'
import { $fetch } from 'ofetch'
const baseURL = 'https://jsonplaceholder.typicode.com' const baseURL = 'https://jsonplaceholder.typicode.com'

View File

@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}

3281
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -14,6 +14,7 @@ function customFetch(input: RequestInfo | URL, init?: RequestInit & { method: 'G
}) })
.then(response => ({ .then(response => ({
...response, ...response,
headers: response.headers,
json: () => Promise.resolve(response._data) json: () => Promise.resolve(response._data)
})) }))
} }