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 CHANGED
@@ -70,7 +70,9 @@ export const signIn = authAction
70
70
  return t("verificationEmail.success");
71
71
  });
72
72
 
73
- export const signUp = authAction
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 t("signUp.success");
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(n){return{type:"success",data:n,error:null,validationError:null}}function o(n){return{type:"failure",data:null,error:n,validationError:null}}function d(n){return{type:"invalid",data:null,error:null,validationError:n}}return(n,S)=>e({success:a,failure:o,invalid:d})(n,S)}import{ZodFirstPartyTypeKind as C}from"zod";import{zfd as w}from"zod-form-data";var l=Symbol();function s(e,a=[],o){async function d(t){let r={formData:t};for(let i of a){let u=await i({ctx:r});r={...r,...u}}return r}return{input(t){if(e===l)return s(t,a);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 s(r,a)}else throw Error("Merging inputs works only for object schemas without effects.")},use(t){return s(e,[...a,t])},error(t){return s(e,a,t)},run:e===l?t=>y(({success:r,failure:i})=>async(u,p)=>{let x=await d(p);try{return r(await t({ctx:x}))}catch(c){if(o)return i(o({error:c,ctx:x}));throw c}}):e===l?void 0:t=>y(({success:r,failure:i,invalid:u})=>{let p=w.formData(e);return async(x,c)=>{let f=await d(c),m=p.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(o)return i(o({error:E,ctx:f}));throw E}}})}}var b=s(l);export{y as createFormAction,b as formAction};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-form-action",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "State management helpers for the react form actions.",
5
5
  "repository": {
6
6
  "type": "git",