react-form-action 1.0.1 → 1.1.0
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 +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ const i18nMiddleware = async () => {
|
|
|
50
50
|
const authAction = formAction
|
|
51
51
|
.use(i18nMiddleware)
|
|
52
52
|
.use(async ({ ctx: { t } }) =>
|
|
53
|
-
console.log("🎉 context enhanced by previous middlewares 🎉", t)
|
|
53
|
+
console.log("🎉 context enhanced by previous middlewares 🎉", t),
|
|
54
54
|
)
|
|
55
55
|
.error(({ error }) => {
|
|
56
56
|
if (error instanceof DbError) {
|
|
@@ -85,7 +85,7 @@ export const signUp = authAction
|
|
|
85
85
|
.refine((data) => data.password === data.confirm, {
|
|
86
86
|
message: "Passwords don't match",
|
|
87
87
|
path: ["confirm"],
|
|
88
|
-
})
|
|
88
|
+
}),
|
|
89
89
|
) // if using refinement, only one input call is permited, as schema with ZodEffects is not extendable.
|
|
90
90
|
.run(async ({ ctx: { t }, input: { email, password } }) => {
|
|
91
91
|
// 🎉 passwords match!
|
|
@@ -161,7 +161,7 @@ export const updateUser = createFormAction<
|
|
|
161
161
|
|
|
162
162
|
return failure({ message: "Failed to update user." });
|
|
163
163
|
}
|
|
164
|
-
}
|
|
164
|
+
},
|
|
165
165
|
);
|
|
166
166
|
```
|
|
167
167
|
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function S(e){function o(n){return{type:"success",data:n,error:null,validationError:null}}function a(n){return{type:"failure",data:null,error:n,validationError:null}}function d(n){return{type:"invalid",data:null,error:null,validationError:n}}return(n,f)=>e({success:o,failure:a,invalid:d})(n,f)}import{ZodFirstPartyTypeKind as C}from"zod";import{zfd as w}from"zod-form-data";var l=Symbol();function s(e,o=[],a){async function d(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 s(t,o,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,o)}else throw Error("Merging inputs works only for object schemas without effects.")},use(t){return s(e,[...o,t],a)},error(t){return s(e,o,t)},run:e===l?t=>S(({success:r,failure:i})=>async(u,m)=>{let x=await d(m);try{return r(await t({ctx:x}))}catch(c){if(a)return i(a({error:c,ctx:x}));throw c}}):e===l?void 0:t=>S(({success:r,failure:i,invalid:u})=>{let m=w.formData(e);return async(x,c)=>{let y=await d(c),p=m.safeParse(c);if(!p.success)return u(p.error.format());let h=p.data;try{return r(await t({input:h,ctx:y}))}catch(E){if(a)return i(a({error:E,ctx:y}));throw E}}})}}var b=s(l);export{S as createFormAction,b as formAction};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-action",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "State management helpers for the react form actions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsup",
|
|
16
16
|
"test": "vitest",
|
|
17
|
-
"typecheck": "vitest --typecheck"
|
|
17
|
+
"typecheck": "vitest --typecheck",
|
|
18
|
+
"format": "prettier . --write",
|
|
19
|
+
"format:check": "prettier . --check"
|
|
18
20
|
},
|
|
19
21
|
"exports": {
|
|
20
22
|
".": {
|
|
@@ -51,6 +53,7 @@
|
|
|
51
53
|
"@types/react": "^18.3.5",
|
|
52
54
|
"@types/react-dom": "^18.3.0",
|
|
53
55
|
"next": "^14.0.2",
|
|
56
|
+
"prettier": "^3.3.3",
|
|
54
57
|
"react-render-prop-type": "^0.1.0",
|
|
55
58
|
"tsup": "^7.2.0",
|
|
56
59
|
"typescript": "^5.2.2",
|