react-form-action 1.0.1 → 1.1.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
@@ -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.d.mts CHANGED
@@ -30,7 +30,7 @@ type FormActionBuilder<Schema extends ZodTypeAny | EmptyInput, Err = Error, Cont
30
30
  * @param action async function to execute. It will receive parsed formData as input, when the builder was initialized with a schema.
31
31
  * @returns runnable server action exportable from a module.
32
32
  */
33
- run: Schema extends ZodTypeAny ? <Data>(action: SchemaAction<Data, Context, Schema>) => (state: FormState<Data, Err, z.inferFlattenedErrors<Schema>>, payload: FormData) => Promise<Flatten<InvalidState<z.inferFlattenedErrors<Schema>> | FailureState<Err> | SuccessState<Data>>> : <Data>(action: Action<Data, Context>) => (state: FormState<Data, Err>, payload: FormData) => Promise<Flatten<FailureState<Err> | SuccessState<Data>>>;
33
+ run: Schema extends ZodTypeAny ? <Data>(action: SchemaAction<Data, Context, Schema>) => (state: FormState<Data, Err, z.inferFormattedError<Schema>>, payload: FormData) => Promise<Flatten<InvalidState<z.inferFormattedError<Schema>> | FailureState<Err> | SuccessState<Data>>> : <Data>(action: Action<Data, Context>) => (state: FormState<Data, Err>, payload: FormData) => Promise<Flatten<FailureState<Err> | SuccessState<Data>>>;
34
34
  /**
35
35
  * A chainable context enhancing helper.
36
36
  * @param middleware A function which receives the current context, and returns an object which will be added to the context.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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 d(a){return{type:"invalid",data:null,error:null,validationError:a}}return(a,S)=>e({success:o,failure:n,invalid:d})(a,S)}import{ZodFirstPartyTypeKind as C}from"zod";import{zfd as w}from"zod-form-data";var l=Symbol();function s(e,o=[],n){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,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 s(r,o)}else throw Error("Merging inputs works only for object schemas without effects.")},use(t){return s(e,[...o,t],n)},error(t){return s(e,o,t)},run:e===l?t=>y(({success:r,failure:i})=>async(u,x)=>{let m=await d(x);try{return r(await t({ctx:m}))}catch(c){if(n)return i(n({error:c,ctx:m}));throw c}}):e===l?void 0:t=>y(({success:r,failure:i,invalid:u})=>{let x=w.formData(e);return async(m,c)=>{let f=await d(c),p=x.safeParse(c);if(!p.success)return u(p.error.flatten());let h=p.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=s(l);export{y as createFormAction,b as formAction};
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 s(n){return{type:"invalid",data:null,error:null,validationError:n}}return(n,f)=>e({success:o,failure:a,invalid:s})(n,f)}import{ZodFirstPartyTypeKind as C}from"zod";import{zfd as w}from"zod-form-data";var l=Symbol();function d(e,o=[],a){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,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 d(r,o)}else throw Error("Merging inputs works only for object schemas without effects.")},use(t){return d(e,[...o,t],a)},error(t){return d(e,o,t)},run:e===l?t=>S(({success:r,failure:i})=>async(u,m)=>{let x=await s(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 s(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=d(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.1",
3
+ "version": "1.1.1",
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",