Skip to content

Commit

Permalink
Chained Server Fn Syntax, ServerFn Middleware (TanStack#2513)
Browse files Browse the repository at this point in the history
* init

* Refactor createServerFn, add createServerMiddleware

* checkpoint

* checkpoint

* checkpoint

* update docs and examples to use new server function syntax

* fix: compilers, and update examples

* refactor: added merging of context and some type tests

* feat: createServerMiddleware context and input validation types

* checkpoint

* Server function middleware

* checkpoint

* checkpoint

* fix: return types from handlers, merging inputs etc

* checkpoint

* checkpoint

* checkpoint

* checkpoint

* feat: add types for client context and server context

* fix: merge server context

* checkpoint

* docs

* fix: better compilation of server functions

* fix: deferred example

* Html, Head, Body... be GONE!

* fix: API Routes

* checkpoint

* fix: support optional input types

* checkpoint

* fix lossy merge

* ci: fix build

* ci: fix start examples

* checkpoint

* feat: add client after context types

* test: add type tests

* checkpoint

* checkpoint

* Remove now-unnecessary data type headers

* checkpoint

* fix e2e test

* fix up merge conflicts

* ci: apply automated fixes

* fix: a few tests and a runtime bug

* chore: pnpm dedupe
except the search-validator-adapters example, everything else builds fine

* fix merge conflict

---------

Co-authored-by: chorobin <chrishorobin@hotmail.com>
Co-authored-by: Manuel Schiller <manuel.schiller@caligano.de>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>
  • Loading branch information
5 people authored and timoconnellaus committed Dec 4, 2024
1 parent 4c0fac5 commit d702cd8
Show file tree
Hide file tree
Showing 221 changed files with 6,995 additions and 2,612 deletions.
8 changes: 4 additions & 4 deletions docs/framework/react/api/router/retainSearchParamsFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ If `true` is passed in, all search params will be retained.
```tsx
import { z } from 'zod'
import { createRootRoute, retainSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const searchSchema = z.object({
rootValue: z.string().optional(),
})

export const Route = createRootRoute({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
middlewares: [retainSearchParams(['rootValue'])],
},
Expand All @@ -32,15 +32,15 @@ export const Route = createRootRoute({
```tsx
import { z } from 'zod'
import { createFileRoute, retainSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const searchSchema = z.object({
one: z.string().optional(),
two: z.string().optional(),
})

export const Route = createFileRoute('/hello')({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
middlewares: [retainSearchParams(true)],
},
Expand Down
12 changes: 6 additions & 6 deletions docs/framework/react/api/router/stripSearchParamsFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ title: Search middleware to strip search params
```tsx
import { z } from 'zod'
import { createFileRoute, stripSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const defaultValues = {
one: 'abc',
Expand All @@ -31,7 +31,7 @@ const searchSchema = z.object({
})

export const Route = createFileRoute('/hello')({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
// strip default values
middlewares: [stripSearchParams(defaultValues)],
Expand All @@ -42,15 +42,15 @@ export const Route = createFileRoute('/hello')({
```tsx
import { z } from 'zod'
import { createRootRoute, stripSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const searchSchema = z.object({
hello: z.string().default('world'),
requiredParam: z.string(),
})

export const Route = createRootRoute({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
// always remove `hello`
middlewares: [stripSearchParams(['hello'])],
Expand All @@ -61,15 +61,15 @@ export const Route = createRootRoute({
```tsx
import { z } from 'zod'
import { createFileRoute, stripSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const searchSchema = z.object({
one: z.string().default('abc'),
two: z.string().default('xyz'),
})

export const Route = createFileRoute('/hello')({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
// remove all search params
middlewares: [stripSearchParams(true)],
Expand Down
26 changes: 13 additions & 13 deletions docs/framework/react/guide/search-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ An adapter is provided for [Zod](https://zod.dev/) which will pipe through the c

```tsx
import { createFileRoute } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'
import { z } from 'zod'

const productSearchSchema = z.object({
Expand All @@ -215,7 +215,7 @@ const productSearchSchema = z.object({
})

export const Route = createFileRoute('/shop/products/')({
validateSearch: zodSearchValidator(productSearchSchema),
validateSearch: zodValidator(productSearchSchema),
})
```

Expand All @@ -229,7 +229,7 @@ However the use of `catch` here overrides the types and makes `page`, `filter` a

```tsx
import { createFileRoute } from '@tanstack/react-router'
import { fallback, zodSearchValidator } from '@tanstack/router-zod-adapter'
import { fallback, zodValidator } from '@tanstack/zod-adapter'
import { z } from 'zod'

const productSearchSchema = z.object({
Expand All @@ -241,7 +241,7 @@ const productSearchSchema = z.object({
})

export const Route = createFileRoute('/shop/products/')({
validateSearch: zodSearchValidator(productSearchSchema),
validateSearch: zodValidator(productSearchSchema),
})
```

Expand All @@ -259,7 +259,7 @@ const productSearchSchema = z.object({
})

export const Route = createFileRoute('/shop/products/')({
validateSearch: zodSearchValidator({
validateSearch: zodValidator({
schema: productSearchSchema,
input: 'output',
output: 'input',
Expand Down Expand Up @@ -538,14 +538,14 @@ The following example shows how to make sure that for **every** link that is bei
```tsx
import { z } from 'zod'
import { createFileRoute } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const searchSchema = z.object({
rootValue: z.string().optional(),
})

export const Route = createRootRoute({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
middlewares: [
({search, next}) => {
Expand All @@ -565,14 +565,14 @@ Since this specific use case is quite common, TanStack Router provides a generic
```tsx
import { z } from 'zod'
import { createFileRoute, retainSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const searchSchema = z.object({
rootValue: z.string().optional(),
})

export const Route = createRootRoute({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
middlewares: [retainSearchParams(['rootValue'])],
},
Expand All @@ -584,7 +584,7 @@ Another common use case is to strip out search params from links if their defaul
```tsx
import { z } from 'zod'
import { createFileRoute, stripSearchParams } from '@tanstack/react-router'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const defaultValues = {
one: 'abc',
Expand All @@ -597,7 +597,7 @@ const searchSchema = z.object({
})

export const Route = createFileRoute('/hello')({
validateSearch: zodSearchValidator(searchSchema),
validateSearch: zodValidator(searchSchema),
search: {
// strip default values
middlewares: [stripSearchParams(defaultValues)],
Expand All @@ -615,12 +615,12 @@ import {
stripSearchParams,
} from '@tanstack/react-router'
import { z } from 'zod'
import { zodSearchValidator } from '@tanstack/router-zod-adapter'
import { zodValidator } from '@tanstack/zod-adapter'

const defaultValues = ['foo', 'bar']

export const Route = createFileRoute('/search')({
validateSearch: zodSearchValidator(
validateSearch: zodValidator(
z.object({
retainMe: z.string().optional(),
arrayWithDefaults: z.string().array().default(defaultValues),
Expand Down
Loading

0 comments on commit d702cd8

Please sign in to comment.