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.9.4
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.9.5
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 21, 2024

  1. chore: update dependencies

    TheEdoRan committed Oct 21, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    knqyf263 Teppei Fukuda
    Copy the full SHA
    ea4687b View commit details
  2. refactor: clean up some logic

    TheEdoRan committed Oct 21, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    knqyf263 Teppei Fukuda
    Copy the full SHA
    f8519cc View commit details
Showing with 50 additions and 42 deletions.
  1. +2 −2 package.json
  2. +4 −8 packages/next-safe-action/src/action-builder.ts
  3. +11 −0 packages/next-safe-action/src/utils.ts
  4. +33 −32 pnpm-lock.yaml
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"cz-conventional-changelog": "^3.3.0",
"husky": "^9.0.11",
"is-ci": "^3.0.1",
"turbo": "^2.1.1"
"turbo": "^2.2.2"
},
"packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
"packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
}
12 changes: 4 additions & 8 deletions packages/next-safe-action/src/action-builder.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import type {
ServerCodeFn,
StateServerCodeFn,
} from "./index.types";
import { DEFAULT_SERVER_ERROR_MESSAGE, isError } from "./utils";
import { DEFAULT_SERVER_ERROR_MESSAGE, isError, winningBoolean } from "./utils";
import type { MaybePromise } from "./utils.types";
import {
ActionMetadataValidationError,
@@ -327,13 +327,9 @@ export function actionBuilder<
const actionResult: SafeActionResult<ServerError, IS, BAS, CVE, CBAVE, Data> = {};

if (typeof middlewareResult.validationErrors !== "undefined") {
// Throw validation errors if either `throwValidationErrors` property at the action or instance level is `true`.
// If `throwValidationErrors` property at the action is `false`, do not throw validation errors, since it
// has a higher priority than the instance one.
if (
(utils?.throwValidationErrors || args.throwValidationErrors) &&
utils?.throwValidationErrors !== false
) {
// `utils.throwValidationErrors` has higher priority since it's set at the action level.
// It overrides the client setting, if set.
if (winningBoolean(args.throwValidationErrors, utils?.throwValidationErrors)) {
throw new ActionValidationError(middlewareResult.validationErrors as CVE);
} else {
actionResult.validationErrors = middlewareResult.validationErrors as CVE;
11 changes: 11 additions & 0 deletions packages/next-safe-action/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export const DEFAULT_SERVER_ERROR_MESSAGE = "Something went wrong while executing the operation.";

/**
* Checks if passed argument is an instance of Error.
*/
export const isError = (error: unknown): error is Error => error instanceof Error;

/**
* Checks what the winning boolean value is from a series of values, from lowest to highest priority.
* `null` and `undefined` values are skipped.
*/
export const winningBoolean = (...args: (boolean | undefined | null)[]) => {
return args.reduce((acc, v) => (typeof v === "boolean" ? v : acc), false) as boolean;
};
65 changes: 33 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.