server-act 1.3.0 → 1.4.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/dist/index.d.mts CHANGED
@@ -7,8 +7,8 @@ type Prettify<T> = {
7
7
  [P in keyof T]: T[P];
8
8
  } & {};
9
9
  type SanitizeFunctionParam<T extends (param: any) => any> = T extends (param: infer P) => infer R ? Equals<P, undefined> extends true ? () => R : Equals<P, P | undefined> extends true ? (param?: P) => R : (param: P) => R : never;
10
- type InferParserType<T, TType extends "in" | "out"> = T extends z.ZodEffects<infer I, any, any> ? I[TType extends "in" ? "_input" : "_output"] : T extends z.ZodType ? T[TType extends "in" ? "_input" : "_output"] : never;
11
- type InferInputType<T, TType extends "in" | "out"> = T extends UnsetMarker ? undefined : InferParserType<T, TType>;
10
+ type InferParserType<T, TType extends "in" | "out", TUnwrapEffects extends true | false> = T extends z.ZodEffects<infer InnerType, infer Output, infer Input> ? TUnwrapEffects extends true ? InnerType[TType extends "in" ? "_input" : "_output"] : TType extends "in" ? Input : Output : T extends z.ZodType ? T[TType extends "in" ? "_input" : "_output"] : never;
11
+ type InferInputType<T, TType extends "in" | "out", TUnwrapEffects extends true | false = true> = T extends UnsetMarker ? undefined : InferParserType<T, TType, TUnwrapEffects>;
12
12
  type InferContextType<T> = T extends UnsetMarker ? undefined : T;
13
13
  interface ActionParams<TInput = unknown, TContext = unknown> {
14
14
  _input: TInput;
@@ -27,7 +27,7 @@ interface ActionBuilder<TParams extends ActionParams> {
27
27
  */
28
28
  input: <TParser extends z.ZodType>(input: ((params: {
29
29
  ctx: InferContextType<TParams["_context"]>;
30
- }) => TParser) | TParser) => Omit<ActionBuilder<{
30
+ }) => Promise<TParser> | TParser) | TParser) => Omit<ActionBuilder<{
31
31
  _input: TParser;
32
32
  _context: TParams["_context"];
33
33
  }>, "input">;
@@ -37,7 +37,7 @@ interface ActionBuilder<TParams extends ActionParams> {
37
37
  action: <TOutput>(action: (params: {
38
38
  ctx: InferContextType<TParams["_context"]>;
39
39
  input: InferInputType<TParams["_input"], "out">;
40
- }) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams["_input"], "in">) => Promise<TOutput>>;
40
+ }) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams["_input"], "in"> | InferInputType<TParams["_input"], "in", false>) => Promise<TOutput>>;
41
41
  /**
42
42
  * Create an action for React `useActionState`
43
43
  */
@@ -51,7 +51,7 @@ interface ActionBuilder<TParams extends ActionParams> {
51
51
  } | {
52
52
  input?: undefined;
53
53
  formErrors: z.ZodError<InferInputType<TParams["_input"], "in">>;
54
- })>) => Promise<TState>) => (prevState: TState | TPrevState, formData: FormData) => Promise<TState | TPrevState>;
54
+ })>) => Promise<TState>) => (prevState: TState | TPrevState, formData: InferInputType<TParams["_input"], "in"> | InferInputType<TParams["_input"], "in", false>) => Promise<TState | TPrevState>;
55
55
  }
56
56
  /**
57
57
  * Server action builder
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@ type Prettify<T> = {
7
7
  [P in keyof T]: T[P];
8
8
  } & {};
9
9
  type SanitizeFunctionParam<T extends (param: any) => any> = T extends (param: infer P) => infer R ? Equals<P, undefined> extends true ? () => R : Equals<P, P | undefined> extends true ? (param?: P) => R : (param: P) => R : never;
10
- type InferParserType<T, TType extends "in" | "out"> = T extends z.ZodEffects<infer I, any, any> ? I[TType extends "in" ? "_input" : "_output"] : T extends z.ZodType ? T[TType extends "in" ? "_input" : "_output"] : never;
11
- type InferInputType<T, TType extends "in" | "out"> = T extends UnsetMarker ? undefined : InferParserType<T, TType>;
10
+ type InferParserType<T, TType extends "in" | "out", TUnwrapEffects extends true | false> = T extends z.ZodEffects<infer InnerType, infer Output, infer Input> ? TUnwrapEffects extends true ? InnerType[TType extends "in" ? "_input" : "_output"] : TType extends "in" ? Input : Output : T extends z.ZodType ? T[TType extends "in" ? "_input" : "_output"] : never;
11
+ type InferInputType<T, TType extends "in" | "out", TUnwrapEffects extends true | false = true> = T extends UnsetMarker ? undefined : InferParserType<T, TType, TUnwrapEffects>;
12
12
  type InferContextType<T> = T extends UnsetMarker ? undefined : T;
13
13
  interface ActionParams<TInput = unknown, TContext = unknown> {
14
14
  _input: TInput;
@@ -27,7 +27,7 @@ interface ActionBuilder<TParams extends ActionParams> {
27
27
  */
28
28
  input: <TParser extends z.ZodType>(input: ((params: {
29
29
  ctx: InferContextType<TParams["_context"]>;
30
- }) => TParser) | TParser) => Omit<ActionBuilder<{
30
+ }) => Promise<TParser> | TParser) | TParser) => Omit<ActionBuilder<{
31
31
  _input: TParser;
32
32
  _context: TParams["_context"];
33
33
  }>, "input">;
@@ -37,7 +37,7 @@ interface ActionBuilder<TParams extends ActionParams> {
37
37
  action: <TOutput>(action: (params: {
38
38
  ctx: InferContextType<TParams["_context"]>;
39
39
  input: InferInputType<TParams["_input"], "out">;
40
- }) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams["_input"], "in">) => Promise<TOutput>>;
40
+ }) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams["_input"], "in"> | InferInputType<TParams["_input"], "in", false>) => Promise<TOutput>>;
41
41
  /**
42
42
  * Create an action for React `useActionState`
43
43
  */
@@ -51,7 +51,7 @@ interface ActionBuilder<TParams extends ActionParams> {
51
51
  } | {
52
52
  input?: undefined;
53
53
  formErrors: z.ZodError<InferInputType<TParams["_input"], "in">>;
54
- })>) => Promise<TState>) => (prevState: TState | TPrevState, formData: FormData) => Promise<TState | TPrevState>;
54
+ })>) => Promise<TState>) => (prevState: TState | TPrevState, formData: InferInputType<TParams["_input"], "in"> | InferInputType<TParams["_input"], "in", false>) => Promise<TState | TPrevState>;
55
55
  }
56
56
  /**
57
57
  * Server action builder
package/dist/index.js CHANGED
@@ -63,7 +63,7 @@ function createServerActionBuilder(initDef = {}) {
63
63
  return /*#__PURE__*/ _async_to_generator(function*(input) {
64
64
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
65
65
  if (_def.input) {
66
- const inputSchema = typeof _def.input === "function" ? _def.input({
66
+ const inputSchema = typeof _def.input === "function" ? yield _def.input({
67
67
  ctx
68
68
  }) : _def.input;
69
69
  const result = yield inputSchema.safeParseAsync(input);
@@ -83,10 +83,11 @@ function createServerActionBuilder(initDef = {}) {
83
83
  });
84
84
  },
85
85
  formAction: (action)=>{
86
+ // biome-ignore lint/suspicious/noExplicitAny: Intended
86
87
  return /*#__PURE__*/ _async_to_generator(function*(prevState, formData) {
87
88
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
88
89
  if (_def.input) {
89
- const inputSchema = typeof _def.input === "function" ? _def.input({
90
+ const inputSchema = typeof _def.input === "function" ? yield _def.input({
90
91
  ctx
91
92
  }) : _def.input;
92
93
  const result = yield inputSchema.safeParseAsync(formData);
package/dist/index.mjs CHANGED
@@ -61,7 +61,7 @@ function createServerActionBuilder(initDef = {}) {
61
61
  return /*#__PURE__*/ _async_to_generator(function*(input) {
62
62
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
63
63
  if (_def.input) {
64
- const inputSchema = typeof _def.input === "function" ? _def.input({
64
+ const inputSchema = typeof _def.input === "function" ? yield _def.input({
65
65
  ctx
66
66
  }) : _def.input;
67
67
  const result = yield inputSchema.safeParseAsync(input);
@@ -81,10 +81,11 @@ function createServerActionBuilder(initDef = {}) {
81
81
  });
82
82
  },
83
83
  formAction: (action)=>{
84
+ // biome-ignore lint/suspicious/noExplicitAny: Intended
84
85
  return /*#__PURE__*/ _async_to_generator(function*(prevState, formData) {
85
86
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
86
87
  if (_def.input) {
87
- const inputSchema = typeof _def.input === "function" ? _def.input({
88
+ const inputSchema = typeof _def.input === "function" ? yield _def.input({
88
89
  ctx
89
90
  }) : _def.input;
90
91
  const result = yield inputSchema.safeParseAsync(formData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "server-act",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "homepage": "https://github.com/chungweileong94/server-act#readme",
5
5
  "author": "chungweileong94",
6
6
  "license": "MIT",
@@ -44,8 +44,8 @@
44
44
  "action"
45
45
  ],
46
46
  "devDependencies": {
47
- "bunchee": "^5.1.2",
48
- "typescript": "^5.4.5",
47
+ "bunchee": "^5.6.0",
48
+ "typescript": "^5.6.3",
49
49
  "zod": "^3.22.2",
50
50
  "zod-form-data": "^2.0.2"
51
51
  },