diff --git a/packages/next-safe-action/src/action-builder.ts b/packages/next-safe-action/src/action-builder.ts index 3cf2fb7f..22397b29 100644 --- a/packages/next-safe-action/src/action-builder.ts +++ b/packages/next-safe-action/src/action-builder.ts @@ -12,16 +12,8 @@ import type { ServerCodeFn, StateServerCodeFn, } from "./index.types"; -import type { InferArray, InferInArray } from "./utils"; -import { - ActionMetadataError, - DEFAULT_SERVER_ERROR_MESSAGE, - isError, - zodValidate, - type Infer, - type InferIn, - type Schema, -} from "./utils"; +import { ActionMetadataError, DEFAULT_SERVER_ERROR_MESSAGE, isError, zodValidate } from "./utils"; +import type { Infer, InferArray, InferIn, InferInArray, Schema } from "./utils.types"; import { ActionValidationError, buildValidationErrors } from "./validation-errors"; import type { BindArgsValidationErrors, diff --git a/packages/next-safe-action/src/hooks-utils.ts b/packages/next-safe-action/src/hooks-utils.ts index f4cc90bd..0212f97a 100644 --- a/packages/next-safe-action/src/hooks-utils.ts +++ b/packages/next-safe-action/src/hooks-utils.ts @@ -2,7 +2,7 @@ import * as React from "react"; import {} from "react/experimental"; import type {} from "zod"; import type { HookActionStatus, HookCallbacks, HookResult } from "./hooks.types"; -import type { InferIn, Schema } from "./utils"; +import type { InferIn, Schema } from "./utils.types"; export const getActionStatus = < ServerError, diff --git a/packages/next-safe-action/src/hooks.ts b/packages/next-safe-action/src/hooks.ts index cc335b72..a531588b 100644 --- a/packages/next-safe-action/src/hooks.ts +++ b/packages/next-safe-action/src/hooks.ts @@ -8,8 +8,8 @@ import {} from "react/experimental"; import type {} from "zod"; import { getActionShorthandStatusObject, getActionStatus, useActionCallbacks } from "./hooks-utils"; import type { HookCallbacks, HookResult, HookSafeActionFn } from "./hooks.types"; -import type { InferIn, Schema } from "./utils"; import { isError } from "./utils"; +import type { InferIn, Schema } from "./utils.types"; // HOOKS diff --git a/packages/next-safe-action/src/hooks.types.ts b/packages/next-safe-action/src/hooks.types.ts index 025a0acb..111c4728 100644 --- a/packages/next-safe-action/src/hooks.types.ts +++ b/packages/next-safe-action/src/hooks.types.ts @@ -1,5 +1,5 @@ import type { SafeActionResult } from "./index.types"; -import type { InferIn, MaybePromise, Prettify, Schema } from "./utils"; +import type { InferIn, MaybePromise, Prettify, Schema } from "./utils.types"; /** * Type of `result` object returned by `useAction`, `useOptimisticAction` and `useStateAction` hooks. diff --git a/packages/next-safe-action/src/index.ts b/packages/next-safe-action/src/index.ts index 2ffde669..a8d7c492 100644 --- a/packages/next-safe-action/src/index.ts +++ b/packages/next-safe-action/src/index.ts @@ -1,7 +1,7 @@ import type { DVES, SafeActionClientOpts } from "./index.types"; import { SafeActionClient } from "./safe-action-client"; -import type { Infer, Schema } from "./utils"; import { DEFAULT_SERVER_ERROR_MESSAGE } from "./utils"; +import type { Infer, Schema } from "./utils.types"; import { flattenBindArgsValidationErrors, flattenValidationErrors, diff --git a/packages/next-safe-action/src/index.types.ts b/packages/next-safe-action/src/index.types.ts index 0bd37fde..d1197bec 100644 --- a/packages/next-safe-action/src/index.types.ts +++ b/packages/next-safe-action/src/index.types.ts @@ -1,4 +1,4 @@ -import type { Infer, InferArray, InferIn, InferInArray, MaybePromise, Prettify, Schema } from "./utils"; +import type { Infer, InferArray, InferIn, InferInArray, MaybePromise, Prettify, Schema } from "./utils.types"; import type { BindArgsValidationErrors, ValidationErrors } from "./validation-errors.types"; /** diff --git a/packages/next-safe-action/src/safe-action-client.ts b/packages/next-safe-action/src/safe-action-client.ts index 528e9280..ec7f1ccd 100644 --- a/packages/next-safe-action/src/safe-action-client.ts +++ b/packages/next-safe-action/src/safe-action-client.ts @@ -8,7 +8,7 @@ import type { ServerCodeFn, StateServerCodeFn, } from "./index.types"; -import type { Infer, Schema } from "./utils"; +import type { Infer, Schema } from "./utils.types"; import type { BindArgsValidationErrors, FlattenedBindArgsValidationErrors, diff --git a/packages/next-safe-action/src/stateful-hooks.ts b/packages/next-safe-action/src/stateful-hooks.ts index 5375e350..360460f5 100644 --- a/packages/next-safe-action/src/stateful-hooks.ts +++ b/packages/next-safe-action/src/stateful-hooks.ts @@ -6,7 +6,7 @@ import {} from "react/experimental"; import type {} from "zod"; import { getActionShorthandStatusObject, getActionStatus, useActionCallbacks } from "./hooks-utils"; import type { HookCallbacks, HookSafeStateActionFn } from "./hooks.types"; -import type { InferIn, Schema } from "./utils"; +import type { InferIn, Schema } from "./utils.types"; /** * 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). * @param safeActionFn The action function diff --git a/packages/next-safe-action/src/utils.ts b/packages/next-safe-action/src/utils.ts index 67283664..df2f6713 100644 --- a/packages/next-safe-action/src/utils.ts +++ b/packages/next-safe-action/src/utils.ts @@ -1,38 +1,9 @@ -import type { z } from "zod"; +import type { Infer, Schema } from "./utils.types"; export const DEFAULT_SERVER_ERROR_MESSAGE = "Something went wrong while executing the operation."; export const isError = (error: unknown): error is Error => error instanceof Error; -// UTIL TYPES - -// Takes an object type and makes it more readable. -export type Prettify = { - [K in keyof T]: T[K]; -} & {}; - -// Returns type or promise of type. -export type MaybePromise = Promise | T; - -// Schema type. -export type Schema = z.ZodType; - -// Infers output schema type. -export type Infer = z.infer; - -// Infers input schema type. -export type InferIn = z.input; - -// Infers output schema type in array of schemas. -export type InferArray = { - [K in keyof BAS]: Infer; -}; - -// Infers input schema type in array of schemas. -export type InferInArray = { - [K in keyof BAS]: InferIn; -}; - // Validate with Zod. export async function zodValidate(s: S, data: unknown) { const result = await s.safeParseAsync(data); diff --git a/packages/next-safe-action/src/utils.types.ts b/packages/next-safe-action/src/utils.types.ts new file mode 100644 index 00000000..1a95eaf2 --- /dev/null +++ b/packages/next-safe-action/src/utils.types.ts @@ -0,0 +1,28 @@ +import type { z } from "zod"; + +// Takes an object type and makes it more readable. +export type Prettify = { + [K in keyof T]: T[K]; +} & {}; + +// Returns type or promise of type. +export type MaybePromise = Promise | T; + +// Schema type. +export type Schema = z.ZodType; + +// Infers output schema type. +export type Infer = z.infer; + +// Infers input schema type. +export type InferIn = z.input; + +// Infers output schema type in array of schemas. +export type InferArray = { + [K in keyof BAS]: Infer; +}; + +// Infers input schema type in array of schemas. +export type InferInArray = { + [K in keyof BAS]: InferIn; +}; diff --git a/packages/next-safe-action/src/validation-errors.ts b/packages/next-safe-action/src/validation-errors.ts index 01a866e6..afdec433 100644 --- a/packages/next-safe-action/src/validation-errors.ts +++ b/packages/next-safe-action/src/validation-errors.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */ -import type { Schema } from "./utils"; +import type { Schema } from "./utils.types"; import type { FlattenedBindArgsValidationErrors, FlattenedValidationErrors, diff --git a/packages/next-safe-action/src/validation-errors.types.ts b/packages/next-safe-action/src/validation-errors.types.ts index 7fa8dbc1..e84d354a 100644 --- a/packages/next-safe-action/src/validation-errors.types.ts +++ b/packages/next-safe-action/src/validation-errors.types.ts @@ -1,4 +1,4 @@ -import type { Infer, Prettify, Schema } from "./utils"; +import type { Infer, Prettify, Schema } from "./utils.types"; export type ValidationIssue = { message: string;