runtipi/patches/next-safe-action@3.4.0.patch
2023-10-12 22:26:34 +02:00

113 lines
3.5 KiB
Diff

diff --git a/dist/hook.mjs b/dist/hook.mjs
index 4f2ea0f6818194b906590f2467f788e66d3524d9..fcec224f19be119a922734e8a6fb7d1916921d8a 100644
--- a/dist/hook.mjs
+++ b/dist/hook.mjs
@@ -7,7 +7,7 @@ import {
useEffect,
useRef,
useState,
- useTransition
+ useTransition,
} from "react";
// src/utils.ts
@@ -17,8 +17,12 @@ var isNextNotFoundError = (e) => isError(e) && e.message === "NEXT_NOT_FOUND";
// src/hook.ts
var getActionStatus = (res) => {
- const hasSucceded = typeof res.data !== "undefined";
- const hasErrored = typeof res.validationError !== "undefined" || typeof res.serverError !== "undefined" || typeof res.fetchError !== "undefined";
+ const hasSucceded = typeof res?.data !== "undefined";
+ const hasErrored =
+ typeof res === "undefined" ||
+ typeof res.validationError !== "undefined" ||
+ typeof res.serverError !== "undefined" ||
+ typeof res.fetchError !== "undefined";
const hasExecuted = hasSucceded || hasErrored;
return { hasExecuted, hasSucceded, hasErrored };
};
@@ -49,12 +53,15 @@ var useAction = (clientCaller, cb) => {
onExecute(input2);
}
return startTransition(() => {
- return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
- if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- throw e;
- }
- setRes({ fetchError: e });
- });
+ return executor
+ .current(input2)
+ .then((res2) => setRes(res2))
+ .catch((e) => {
+ if (isNextRedirectError(e) || isNextNotFoundError(e)) {
+ throw e;
+ }
+ setRes({ fetchError: e });
+ });
});
}, []);
const reset = useCallback(() => {
@@ -68,17 +75,20 @@ var useAction = (clientCaller, cb) => {
reset,
hasExecuted,
hasSucceded,
- hasErrored
+ hasErrored,
};
};
var useOptimisticAction = (clientCaller, initialOptData, cb) => {
const [res, setRes] = useState({});
const [input, setInput] = useState();
- const [optState, syncState] = experimental_useOptimistic({ ...initialOptData, ...res.data, __isExecuting__: false }, (state, newState) => ({
- ...state,
- ...newState,
- __isExecuting__: true
- }));
+ const [optState, syncState] = experimental_useOptimistic(
+ { ...initialOptData, ...res.data, __isExecuting__: false },
+ (state, newState) => ({
+ ...state,
+ ...newState,
+ __isExecuting__: true,
+ })
+ );
const executor = useRef(clientCaller);
const onExecuteRef = useRef(cb?.onExecute);
const { hasExecuted, hasSucceded, hasErrored } = getActionStatus(res);
@@ -90,12 +100,15 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
if (onExecute) {
onExecute(input2);
}
- return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
- if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- throw e;
- }
- setRes({ fetchError: e });
- });
+ return executor
+ .current(input2)
+ .then((res2) => setRes(res2))
+ .catch((e) => {
+ if (isNextRedirectError(e) || isNextNotFoundError(e)) {
+ throw e;
+ }
+ setRes({ fetchError: e });
+ });
},
[syncState]
);
@@ -113,11 +126,8 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
reset,
hasExecuted,
hasSucceded,
- hasErrored
+ hasErrored,
};
};
-export {
- useAction,
- useOptimisticAction
-};
+export { useAction, useOptimisticAction };
//# sourceMappingURL=hook.mjs.map