Skip to content

Commit 9238190

Browse files
authoredMar 11, 2024··
refactor: upgrade TypeSchema to v0.13 (#81)
This commit upgrades TypeSchema from v0.12 to v0.13. v0.13 is a major refactor of the library, which switched to a modular design. From now on, next-safe-action will use @typeschema/main to just include the common adapter logic without actually bundling adapters. This keeps the bundle size small, while allowing users to choose the specific validation libraries (and adapters) they want to use.
1 parent da5284e commit 9238190

File tree

7 files changed

+155
-99
lines changed

7 files changed

+155
-99
lines changed
 

‎package-lock.json

+137-75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/example-app/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
"license": "MIT",
1212
"author": "Edoardo Ranghieri",
1313
"dependencies": {
14-
"lucide-react": "^0.354.0",
1514
"@hookform/resolvers": "^3.3.4",
15+
"@typeschema/valibot": "^0.13.4",
16+
"@typeschema/zod": "^0.13.3",
17+
"lucide-react": "^0.354.0",
1618
"next": "14.1.3",
1719
"next-safe-action": "file:../next-safe-action",
1820
"react": "18.2.0",
1921
"react-dom": "18.2.0",
20-
"valibot": "^0.30.0",
2122
"react-hook-form": "^7.51.0",
23+
"valibot": "^0.30.0",
2224
"zod": "^3.22.4",
2325
"zod-form-data": "^2.0.2"
2426
},

‎packages/next-safe-action/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"devDependencies": {
5454
"@types/node": "^20.11.25",
5555
"@types/react": "^18.2.64",
56+
"@typeschema/zod": "^0.13.3",
5657
"@typescript-eslint/eslint-plugin": "^7.1.1",
5758
"@typescript-eslint/parser": "^7.1.1",
5859
"eslint": "^8.57.0",
@@ -73,6 +74,6 @@
7374
"url": "https://github.com/TheEdoRan/next-safe-action.git"
7475
},
7576
"dependencies": {
76-
"@decs/typeschema": "^0.12.2"
77+
"@typeschema/main": "^0.13.7"
7778
}
7879
}

‎packages/next-safe-action/src/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import type { InferIn, Schema } from "@decs/typeschema";
3+
import type { InferIn, Schema } from "@typeschema/main";
44
import { isNotFoundError } from "next/dist/client/components/not-found.js";
55
import { isRedirectError } from "next/dist/client/components/redirect.js";
66
import * as React from "react";

‎packages/next-safe-action/src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Infer, InferIn, Schema } from "@decs/typeschema";
2-
import { wrap } from "@decs/typeschema";
1+
import type { Infer, InferIn, Schema } from "@typeschema/main";
2+
import { validate } from "@typeschema/main";
33
import { isNotFoundError } from "next/dist/client/components/not-found.js";
44
import { isRedirectError } from "next/dist/client/components/redirect.js";
55
import type { ErrorList, Extend, MaybePromise, SchemaErrors } from "./utils";
@@ -84,10 +84,10 @@ export const createSafeActionClient = <Context, MiddlewareData>(
8484
// all the invalid fields provided.
8585
return async (clientInput) => {
8686
try {
87-
const parsedInput = await wrap(schema).validate(clientInput);
87+
const parsedInput = await validate(schema, clientInput);
8888

8989
// If schema validation fails.
90-
if ("issues" in parsedInput) {
90+
if (!parsedInput.success) {
9191
return {
9292
validationErrors: buildValidationErrors<S>(parsedInput.issues),
9393
};

‎packages/next-safe-action/src/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { Schema, ValidationIssue } from "@decs/typeschema";
1+
import type { ValidationIssue } from "@typeschema/core";
2+
import type { Schema } from "@typeschema/main";
23
import type { ValidationErrors } from ".";
34

45
export const isError = (error: unknown): error is Error => error instanceof Error;

‎website/docs/getting-started.md

+5-15
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,27 @@ This is the documentation for the current version of the library (7.x.x).
1010
:::
1111

1212
:::info Requirements
13-
- v4: Next.js >= 13.4.2, v5: Next.js >= 14.0.0
13+
- Next.js >= 14.0.0
1414
- TypeScript >= 5.0.0
15-
- pre-v6: Zod >= 3.0.0, from v6: a validation library supported by [TypeSchema](https://typeschema.com/#coverage)
15+
- a validation library supported by [TypeSchema](https://typeschema.com/#coverage)
1616
:::
1717

1818
**next-safe-action** provides a typesafe Server Actions implementation for Next.js App Router.
1919

2020
## Validation libraries support
2121

22-
We will use Zod as our validation library in this documentation, but since version 6 of next-safe-action, you can use your validation library of choice, or even multiple and custom ones at the same time, thanks to the **TypeSchema** library. You can find supported libraries [here](https://typeschema.com/#coverage).
22+
We will use Zod as our validation library in this documentation, but since version 6 of next-safe-action, you can use your validation library of choice, or even multiple and custom ones at the same time, thanks to the **TypeSchema** library. Note that we also need to install the related TypeSchema adapter for our validation library of choice. You can find supported libraries and related adapters [here](https://typeschema.com/#coverage).
2323

2424
## Installation
2525

26-
For Next.js >= 14, use the following command:
26+
For Next.js >= 14, assuming you want to use Zod as your validation library, use the following command:
2727

2828
```bash npm2yarn
29-
npm i next-safe-action
30-
```
31-
32-
For Next.js 13, use the following command:
33-
34-
```bash npm2yarn
35-
npm i next-safe-action@v4 zod
29+
npm i next-safe-action zod @typeschema/zod
3630
```
3731

3832
## Usage
3933

40-
:::note
41-
If you're still using Next.js 13 with next-safe-action v4, you need to enable `serverActions` flag under the `experimental` object in next.config.js file. Find out more [here](/docs/migrations/v4-to-v5).
42-
:::
43-
4434
### 1. Instantiate a new client
4535

4636
You can create a new client with the following code:

0 commit comments

Comments
 (0)