Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TheEdoRan/next-safe-action
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.1.3
Choose a base ref
...
head repository: TheEdoRan/next-safe-action
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.2.0
Choose a head ref
  • 10 commits
  • 58 files changed
  • 1 contributor

Commits on Jul 2, 2024

  1. ci: add experimental channel

    TheEdoRan committed Jul 2, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    5b9ad94 View commit details
  2. ci(github): fix spacing in condition

    TheEdoRan committed Jul 2, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    0c1ddc5 View commit details
  3. ci: run workflows on experimental branch

    TheEdoRan committed Jul 2, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    6e92f78 View commit details

Commits on Jul 12, 2024

  1. chore: use pnpm 9.5.0

    TheEdoRan committed Jul 12, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    435dd1a View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    b6f0541 View commit details
  3. chore(website): add broken types section in troubleshooting page

    TheEdoRan committed Jul 12, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    b6bfef0 View commit details
  4. chore(website): add progressive enhancement section in `useStateActio…

    …n` page
    TheEdoRan committed Jul 12, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    579ab71 View commit details
  5. chore(website): fix optional result in getting started page

    TheEdoRan committed Jul 12, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    21f0355 View commit details
  6. chore(website): use npm2yarn plugin in troubleshooting page

    TheEdoRan committed Jul 12, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    TheEdoRan Edoardo Ranghieri
    Copy the full SHA
    e00829a View commit details

Commits on Jul 20, 2024

  1. feat: built-in support for multiple validation libraries (#202)

    Make use of built-in modular support for multiple validation libraries, instead of TypeSchema.
    TheEdoRan authored Jul 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    baff76b View commit details
Showing with 653 additions and 2,811 deletions.
  1. +2 −1 .github/workflows/cicd.yml
  2. +2 −2 apps/playground/package.json
  3. +2 −0 apps/playground/src/lib/safe-action.ts
  4. +1 −1 package.json
  5. +18 −15 packages/next-safe-action/package.json
  6. +5 −0 packages/next-safe-action/release.config.cjs
  7. +2 −0 packages/next-safe-action/src/__tests__/action-callbacks.test.ts
  8. +6 −1 packages/next-safe-action/src/__tests__/bind-args-validation-errors.test.ts
  9. +6 −1 packages/next-safe-action/src/__tests__/combined-validation-errors.test.ts
  10. +4 −1 packages/next-safe-action/src/__tests__/happy-path.test.ts
  11. +2 −0 packages/next-safe-action/src/__tests__/metadata.test.ts
  12. +3 −0 packages/next-safe-action/src/__tests__/middleware.test.ts
  13. +4 −0 packages/next-safe-action/src/__tests__/server-error.test.ts
  14. +0 −301 packages/next-safe-action/src/__tests__/typeschema/action-callbacks.test.ts
  15. +0 −251 packages/next-safe-action/src/__tests__/typeschema/bind-args-validation-errors.test.ts
  16. +0 −316 packages/next-safe-action/src/__tests__/typeschema/combined-validation-errors.test.ts
  17. +0 −158 packages/next-safe-action/src/__tests__/typeschema/happy-path.test.ts
  18. +0 −80 packages/next-safe-action/src/__tests__/typeschema/metadata.test.ts
  19. +0 −393 packages/next-safe-action/src/__tests__/typeschema/middleware.test.ts
  20. +0 −168 packages/next-safe-action/src/__tests__/typeschema/server-error.test.ts
  21. +0 −581 packages/next-safe-action/src/__tests__/typeschema/validation-errors.test.ts
  22. +7 −1 packages/next-safe-action/src/__tests__/validation-errors.test.ts
  23. +8 −19 packages/next-safe-action/src/action-builder.ts
  24. +74 −0 packages/next-safe-action/src/adapters/types.ts
  25. +29 −0 packages/next-safe-action/src/adapters/valibot.ts
  26. +38 −0 packages/next-safe-action/src/adapters/yup.ts
  27. +28 −0 packages/next-safe-action/src/adapters/zod.ts
  28. +1 −1 packages/next-safe-action/src/hooks-utils.ts
  29. +3 −1 packages/next-safe-action/src/hooks.ts
  30. +2 −2 packages/next-safe-action/src/hooks.types.ts
  31. +4 −4 packages/next-safe-action/src/index.ts
  32. +3 −2 packages/next-safe-action/src/index.types.ts
  33. +10 −10 packages/next-safe-action/src/safe-action-client.ts
  34. +1 −1 packages/next-safe-action/src/stateful-hooks.ts
  35. +0 −77 packages/next-safe-action/src/typeschema.ts
  36. +0 −39 packages/next-safe-action/src/utils.ts
  37. +7 −0 packages/next-safe-action/src/utils.types.ts
  38. +2 −4 packages/next-safe-action/src/validation-errors.ts
  39. +7 −2 packages/next-safe-action/src/validation-errors.types.ts
  40. +2 −1 packages/next-safe-action/tsup.config.ts
  41. +142 −212 pnpm-lock.yaml
  42. +25 −2 website/docs/execution/hooks/usestateaction.md
  43. +6 −21 website/docs/getting-started.md
  44. +1 −1 website/docs/recipes/additional-validation-errors.md
  45. +1 −1 website/docs/recipes/customize-validation-errors-format.md
  46. +1 −1 website/docs/recipes/extend-base-client.md
  47. +1 −1 website/docs/recipes/extend-previous-schema.md
  48. +1 −1 website/docs/recipes/form-actions.md
  49. +1 −1 website/docs/recipes/i18n.md
  50. +1 −1 website/docs/recipes/upload-files.md
  51. +43 −0 website/docs/recipes/validation-libraries-support.md
  52. +4 −0 website/docs/safe-action-client/initialization-options.md
  53. +2 −2 website/docs/safe-action-client/instance-methods.md
  54. +11 −3 website/docs/troubleshooting.md
  55. +2 −2 website/docs/types.md
  56. +1 −1 website/package.json
  57. +126 −126 website/pnpm-lock.yaml
  58. +1 −1 website/src/components/landing/features.tsx
3 changes: 2 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ on:
- main
- beta
- next
- experimental
- 4.x
pull_request:
paths:
@@ -33,7 +34,7 @@ jobs:
- run: pnpm run test:lib

CD:
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/next'|| github.ref == 'refs/heads/4.x' }}
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/next'|| github.ref == 'refs/heads/experimental' || github.ref == 'refs/heads/4.x' }}
runs-on: ubuntu-latest
needs: [CI]
steps:
4 changes: 2 additions & 2 deletions apps/playground/package.json
Original file line number Diff line number Diff line change
@@ -21,14 +21,14 @@
"zod-form-data": "^2.0.2"
},
"devDependencies": {
"@types/node": "^20.12.10",
"@types/node": "^20.14.11",
"@types/react": "^18.3.1",
"@types/react-dom": "18.3.0",
"autoprefixer": "10.4.19",
"eslint": "^8.57.0",
"eslint-config-next": "15.0.0-canary.25",
"postcss": "8.4.38",
"tailwindcss": "3.4.3",
"typescript": "^5.4.5"
"typescript": "^5.5.3"
}
}
2 changes: 2 additions & 0 deletions apps/playground/src/lib/safe-action.ts
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@ import {
DEFAULT_SERVER_ERROR_MESSAGE,
createSafeActionClient,
} from "next-safe-action";
import { zodAdapter } from "next-safe-action/adapters/zod";
import { z } from "zod";

export class ActionError extends Error {}

export const action = createSafeActionClient({
validationAdapter: zodAdapter(),
// You can provide a custom logging function, otherwise the lib will use `console.error`
// as the default logging system. If you want to disable server errors logging,
// just pass an empty Promise.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -38,5 +38,5 @@
"is-ci": "^3.0.1",
"turbo": "^1.13.4"
},
"packageManager": "pnpm@9.4.0+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903"
}
33 changes: 18 additions & 15 deletions packages/next-safe-action/package.json
Original file line number Diff line number Diff line change
@@ -11,23 +11,23 @@
],
"exports": {
".": "./dist/index.mjs",
"./typeschema": "./dist/typeschema.mjs",
"./hooks": "./dist/hooks.mjs",
"./stateful-hooks": "./dist/stateful-hooks.mjs"
"./stateful-hooks": "./dist/stateful-hooks.mjs",
"./adapters/*": "./dist/adapters/*.mjs"
},
"typesVersions": {
"*": {
".": [
"./dist/index.d.mts"
],
"typeschema": [
"./dist/typeschema.d.mts"
],
"hooks": [
"./dist/hooks.d.mts"
],
"stateful-hooks": [
"./dist/stateful-hooks.d.mts"
],
"adapters/*": [
"./dist/adapters/*.d.mts"
]
}
},
@@ -43,7 +43,7 @@
],
"scripts": {
"lint": "tsc && prettier --write . && eslint .",
"test": "node --import tsx --test ./src/__tests__/*.test.ts ./src/__tests__/typeschema/*.test.ts",
"test": "node --import tsx --test ./src/__tests__/*.test.ts",
"build": "tsup",
"deploy": "semantic-release"
},
@@ -67,10 +67,9 @@
},
"devDependencies": {
"@eslint/js": "^9.2.0",
"@types/node": "^20.12.10",
"@types/node": "^20.14.11",
"@types/react": "^18.3.1",
"@types/react-dom": "18.3.0",
"@typeschema/core": "^0.13.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-define-config": "^2.1.0",
@@ -82,26 +81,30 @@
"semantic-release": "^23.0.8",
"tsup": "^8.0.2",
"tsx": "^4.11.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0"
"typescript": "^5.5.3",
"typescript-eslint": "^7.8.0",
"valibot": "^0.36.0",
"yup": "^1.4.0",
"zod": "^3.23.6"
},
"peerDependencies": {
"next": ">= 14.0.0",
"react": ">= 18.2.0",
"react-dom": ">= 18.2.0",
"zod": ">= 3.0.0"
"valibot": ">= 0.36.0",
"zod": ">= 3.0.0",
"yup": ">= 1.0.0"
},
"peerDependenciesMeta": {
"zod": {
"optional": true
},
"valibot": {
"optional": true
}
},
"repository": {
"type": "git",
"url": "https://github.com/TheEdoRan/next-safe-action.git"
},
"dependencies": {
"@typeschema/main": "^0.13.10",
"@typeschema/zod": "^0.13.3"
}
}
5 changes: 5 additions & 0 deletions packages/next-safe-action/release.config.cjs
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ module.exports = {
channel: "next",
prerelease: true,
},
{
name: "experimental",
channel: "experimental",
prerelease: true,
},
{
name: "beta",
channel: "beta",
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@ import assert from "node:assert";
import { test } from "node:test";
import { z } from "zod";
import { DEFAULT_SERVER_ERROR_MESSAGE, createSafeActionClient, returnValidationErrors } from "..";
import { zodAdapter } from "../adapters/zod";

const ac = createSafeActionClient({
validationAdapter: zodAdapter(),
defineMetadataSchema() {
return z.object({
actionName: z.string(),
Original file line number Diff line number Diff line change
@@ -4,10 +4,13 @@ import assert from "node:assert";
import { test } from "node:test";
import { z } from "zod";
import { createSafeActionClient, flattenBindArgsValidationErrors, formatBindArgsValidationErrors } from "..";
import { zodAdapter } from "../adapters/zod";

// Default client tests.

const dac = createSafeActionClient();
const dac = createSafeActionClient({
validationAdapter: zodAdapter(),
});

test("action with invalid bind args input gives back an object with correct `bindArgsValidationErrors` (default formatted shape)", async () => {
const bindArgsSchemas: [age: z.ZodNumber, userId: z.ZodString, product: z.ZodObject<{ id: z.ZodString }>] = [
@@ -87,6 +90,7 @@ test("action with invalid bind args input gives back an object with correct `bin
// Formatted shape tests (same as default).

const foac = createSafeActionClient({
validationAdapter: zodAdapter(),
defaultValidationErrorsShape: "formatted",
});

@@ -168,6 +172,7 @@ test("action with invalid bind args input gives back an object with correct `bin
// Flattened shape tests.

const flac = createSafeActionClient({
validationAdapter: zodAdapter(),
defaultValidationErrorsShape: "flattened",
});

Original file line number Diff line number Diff line change
@@ -10,10 +10,13 @@ import {
formatBindArgsValidationErrors,
formatValidationErrors,
} from "..";
import { zodAdapter } from "../adapters/zod";

// Default client tests.

const dac = createSafeActionClient();
const dac = createSafeActionClient({
validationAdapter: zodAdapter(),
});

test("action with invalid bind args input and valid main input gives back an object with correct `bindArgsValidationErrors` (default formatted shape)", async () => {
const schema = z.object({
@@ -110,6 +113,7 @@ test("action with invalid bind args input and invalid main input gives back an o
// Formatted shape tests (same as default).

const foac = createSafeActionClient({
validationAdapter: zodAdapter(),
defaultValidationErrorsShape: "formatted",
});

@@ -209,6 +213,7 @@ test("action with invalid bind args input and valid main input gives back an obj
// Flattened shape tests.

const flac = createSafeActionClient({
validationAdapter: zodAdapter(),
defaultValidationErrorsShape: "flattened",
});

5 changes: 4 additions & 1 deletion packages/next-safe-action/src/__tests__/happy-path.test.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,11 @@ import assert from "node:assert";
import { test } from "node:test";
import { z } from "zod";
import { createSafeActionClient } from "..";
import { zodAdapter } from "../adapters/zod";

const ac = createSafeActionClient();
const ac = createSafeActionClient({
validationAdapter: zodAdapter(),
});

test("action with no input schema returns empty object", async () => {
const action = ac.action(async () => {
2 changes: 2 additions & 0 deletions packages/next-safe-action/src/__tests__/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@ import assert from "node:assert";
import { test } from "node:test";
import { z } from "zod";
import { DEFAULT_SERVER_ERROR_MESSAGE, createSafeActionClient } from "..";
import { zodAdapter } from "../adapters/zod";

const ac = createSafeActionClient({
validationAdapter: zodAdapter(),
handleServerErrorLog() {}, // disable server errors logging for these tests
defineMetadataSchema() {
return z.object({
3 changes: 3 additions & 0 deletions packages/next-safe-action/src/__tests__/middleware.test.ts
Original file line number Diff line number Diff line change
@@ -9,8 +9,10 @@ import {
formatValidationErrors,
returnValidationErrors,
} from "..";
import { zodAdapter } from "../adapters/zod";

const ac = createSafeActionClient({
validationAdapter: zodAdapter(),
handleServerErrorLog() {}, // disable server errors logging for these tests
handleReturnedServerError(e) {
return {
@@ -292,6 +294,7 @@ test("server validation errors in execution result from middleware are correct",
// Flattened validation errors shape.

const flac = createSafeActionClient({
validationAdapter: zodAdapter(),
handleServerErrorLog() {}, // disable server errors logging for these tests
defaultValidationErrorsShape: "flattened",
});
4 changes: 4 additions & 0 deletions packages/next-safe-action/src/__tests__/server-error.test.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import assert from "node:assert";
import { test } from "node:test";
import { DEFAULT_SERVER_ERROR_MESSAGE, createSafeActionClient } from "..";
import { zodAdapter } from "../adapters/zod";

class ActionError extends Error {
constructor(message: string) {
@@ -11,6 +12,7 @@ class ActionError extends Error {
}

const ac1 = createSafeActionClient({
validationAdapter: zodAdapter(),
handleServerErrorLog: () => {}, // disable server errors logging for these tests
handleReturnedServerError(e) {
if (e instanceof ActionError) {
@@ -93,6 +95,7 @@ test("known error occurred in middleware function is unmasked", async () => {

// Server error is an object with a 'message' property.
const ac2 = createSafeActionClient({
validationAdapter: zodAdapter(),
handleServerErrorLog: () => {}, // disable server errors logging for these tests
handleReturnedServerError(e) {
return {
@@ -138,6 +141,7 @@ test("error occurred in middleware function has the correct shape defined by `ha

// Rethrow all server errors.
const ac3 = createSafeActionClient({
validationAdapter: zodAdapter(),
handleServerErrorLog: () => {}, // disable server errors logging for these tests
handleReturnedServerError(e) {
throw e;
Loading