Skip to content

Commit

Permalink
refactor(hooks): export EMPTY_HOOK_RESULT just from /hooks path
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed May 9, 2024
1 parent 17935ad commit 74c0dc8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
14 changes: 11 additions & 3 deletions packages/next-safe-action/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ import type {
HookSafeActionFn,
HookSafeStateActionFn,
} from "./hooks.types";
import { EMPTY_HOOK_RESULT, isError } from "./utils";
import { isError } from "./utils";

/**
* Default value for `result` object returned by `useAction`, `useOptimisticAction` and `useStateAction` hooks.
*/
export const EMPTY_HOOK_RESULT = {
data: undefined,
fetchError: undefined,
serverError: undefined,
validationErrors: undefined,
} satisfies HookResult<any, any, any, any, any, any>;

const getActionStatus = <
ServerError,
Expand Down Expand Up @@ -318,6 +328,4 @@ export const useStateAction = <
};
};

export { EMPTY_HOOK_RESULT };

export type * from "./hooks.types";
2 changes: 1 addition & 1 deletion packages/next-safe-action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Schema } from "@typeschema/main";
import type { SafeActionClientOpts } from "./index.types";
import { createClientWithStrategy } from "./safe-action-client";

export { DEFAULT_SERVER_ERROR_MESSAGE, EMPTY_HOOK_RESULT as EMPTY_RESULT } from "./utils";
export { DEFAULT_SERVER_ERROR_MESSAGE } from "./utils";
export { flattenBindArgsValidationErrors, flattenValidationErrors, returnValidationErrors } from "./validation-errors";

export type * from "./index.types";
Expand Down
11 changes: 0 additions & 11 deletions packages/next-safe-action/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Infer, InferIn, Schema } from "@typeschema/main";
import type { HookResult } from "./hooks.types";

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

Expand All @@ -24,13 +23,3 @@ export type InferArray<BAS extends readonly Schema[]> = {
export type InferInArray<BAS extends readonly Schema[]> = {
[K in keyof BAS]: InferIn<BAS[K]>;
};

/**
* Default value for `result` object returned by `useAction`, `useOptimisticAction` and `useStateAction` hooks.
*/
export const EMPTY_HOOK_RESULT = {
data: undefined,
fetchError: undefined,
serverError: undefined,
validationErrors: undefined,
} satisfies HookResult<any, any, any, any, any, any>;
2 changes: 1 addition & 1 deletion packages/next-safe-action/src/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Schema } from "@typeschema/main";
import type { SafeActionClientOpts } from "./index.types";
import { createClientWithStrategy } from "./safe-action-client";

export { DEFAULT_SERVER_ERROR_MESSAGE, EMPTY_HOOK_RESULT as EMPTY_RESULT } from "./utils";
export { DEFAULT_SERVER_ERROR_MESSAGE } from "./utils";
export { flattenBindArgsValidationErrors, flattenValidationErrors, returnValidationErrors } from "./validation-errors";

export type * from "./index.types";
Expand Down

0 comments on commit 74c0dc8

Please sign in to comment.