Skip to content

Commit 10143bb

Browse files
committed
refactor: set up built-in multi validation system
1 parent a148550 commit 10143bb

16 files changed

+69
-32
lines changed

packages/next-safe-action/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
"react-dom": ">= 18.2.0",
8888
"zod": ">= 3.0.0"
8989
},
90+
"peerDependenciesMeta": {
91+
"zod": {
92+
"optional": true
93+
}
94+
},
9095
"repository": {
9196
"type": "git",
9297
"url": "https://github.com/TheEdoRan/next-safe-action.git"

packages/next-safe-action/src/action-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
StateServerCodeFn,
1414
} from "./index.types";
1515
import { ActionMetadataError, DEFAULT_SERVER_ERROR_MESSAGE, isError, zodValidate } from "./utils";
16-
import type { Infer, InferArray, InferIn, InferInArray, Schema } from "./utils.types";
16+
import type { Infer, InferArray, InferIn, InferInArray, Schema } from "./validation-adapters";
1717
import { ActionValidationError, buildValidationErrors } from "./validation-errors";
1818
import type {
1919
BindArgsValidationErrors,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react";
22
import {} from "react/experimental";
33
import type {} from "zod";
44
import type { HookActionStatus, HookCallbacks, HookResult } from "./hooks.types";
5-
import type { InferIn, Schema } from "./utils.types";
5+
import type { InferIn, Schema } from "./validation-adapters";
66

77
export const getActionStatus = <
88
ServerError,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {} from "zod";
99
import { getActionShorthandStatusObject, getActionStatus, useActionCallbacks } from "./hooks-utils";
1010
import type { HookCallbacks, HookResult, HookSafeActionFn } from "./hooks.types";
1111
import { isError } from "./utils";
12-
import type { InferIn, Schema } from "./utils.types";
12+
import type { InferIn, Schema } from "./validation-adapters";
1313

1414
// HOOKS
1515

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { SafeActionResult } from "./index.types";
2-
import type { InferIn, MaybePromise, Prettify, Schema } from "./utils.types";
2+
import type { MaybePromise, Prettify } from "./utils.types";
3+
import type { InferIn, Schema } from "./validation-adapters";
34

45
/**
56
* Type of `result` object returned by `useAction`, `useOptimisticAction` and `useStateAction` hooks.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DVES, SafeActionClientOpts } from "./index.types";
22
import { SafeActionClient } from "./safe-action-client";
33
import { DEFAULT_SERVER_ERROR_MESSAGE } from "./utils";
4-
import type { Infer, Schema } from "./utils.types";
4+
import type { Infer, Schema } from "./validation-adapters";
55
import {
66
flattenBindArgsValidationErrors,
77
flattenValidationErrors,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { Infer, InferArray, InferIn, InferInArray, MaybePromise, Prettify, Schema } from "./utils.types";
1+
import type { MaybePromise, Prettify } from "./utils.types";
2+
import type { Infer, InferArray, InferIn, InferInArray, Schema } from "./validation-adapters";
23
import type { BindArgsValidationErrors, ValidationErrors } from "./validation-errors.types";
34

45
/**

packages/next-safe-action/src/safe-action-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
ServerCodeFn,
99
StateServerCodeFn,
1010
} from "./index.types";
11-
import type { Infer, Schema } from "./utils.types";
11+
import type { Infer, Schema } from "./validation-adapters";
1212
import type {
1313
BindArgsValidationErrors,
1414
FlattenedBindArgsValidationErrors,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {} from "react/experimental";
66
import type {} from "zod";
77
import { getActionShorthandStatusObject, getActionStatus, useActionCallbacks } from "./hooks-utils";
88
import type { HookCallbacks, HookSafeStateActionFn } from "./hooks.types";
9-
import type { InferIn, Schema } from "./utils.types";
9+
import type { InferIn, Schema } from "./validation-adapters";
1010
/**
1111
* Use the stateful action from a Client Component via hook. Used for actions defined with [`stateAction`](https://next-safe-action.dev/docs/safe-action-client/instance-methods#action--stateaction).
1212
* @param safeActionFn The action function

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Infer, Schema } from "./utils.types";
1+
import type { Infer, Schema } from "./validation-adapters";
22

33
export const DEFAULT_SERVER_ERROR_MESSAGE = "Something went wrong while executing the operation.";
44

0 commit comments

Comments
 (0)