react-form-action 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,9 @@ export const signIn = authAction
|
|
|
70
70
|
return t("verificationEmail.success");
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
import { formAction } from "react-fomr-action";
|
|
74
|
+
|
|
75
|
+
export const signUp = formAction
|
|
74
76
|
.input(
|
|
75
77
|
z
|
|
76
78
|
.object({
|
|
@@ -88,7 +90,7 @@ export const signUp = authAction
|
|
|
88
90
|
|
|
89
91
|
await db.signUp({ email, password });
|
|
90
92
|
|
|
91
|
-
return
|
|
93
|
+
return "We've sent you an email!";
|
|
92
94
|
});
|
|
93
95
|
```
|
|
94
96
|
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function y(e){function a
|
|
1
|
+
function y(e){function o(a){return{type:"success",data:a,error:null,validationError:null}}function n(a){return{type:"failure",data:null,error:a,validationError:null}}function s(a){return{type:"invalid",data:null,error:null,validationError:a}}return(a,S)=>e({success:o,failure:n,invalid:s})(a,S)}import{ZodFirstPartyTypeKind as C}from"zod";import{zfd as w}from"zod-form-data";var l=Symbol();function d(e,o=[],n){async function s(t){let r={formData:t};for(let i of o){let u=await i({ctx:r});r={...r,...u}}return r}return{input(t){if(e===l)return d(t,o,n);if(e._def.effect)throw new Error("Previous input is not augmentable because it contains an effect.");if(t._def.effect)throw new Error("Your input contains effect which prevents merging it with the previous inputs.");if(e._def.typeName===C.ZodObject){let r=e.merge(t);return d(r,o)}else throw Error("Merging inputs works only for object schemas without effects.")},use(t){return d(e,[...o,t],n)},error(t){return d(e,o,t)},run:e===l?t=>y(({success:r,failure:i})=>async(u,x)=>{let p=await s(x);try{return r(await t({ctx:p}))}catch(c){if(n)return i(n({error:c,ctx:p}));throw c}}):e===l?void 0:t=>y(({success:r,failure:i,invalid:u})=>{let x=w.formData(e);return async(p,c)=>{let f=await s(c),m=x.safeParse(c);if(!m.success)return u(m.error.flatten());let h=m.data;try{return r(await t({input:h,ctx:f}))}catch(E){if(n)return i(n({error:E,ctx:f}));throw E}}})}}var b=d(l);export{y as createFormAction,b as formAction};
|