server-act 1.3.1 → 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 +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +3 -3
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
|
|
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;
|
|
@@ -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:
|
|
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
|
|
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;
|
|
@@ -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:
|
|
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
|
@@ -83,6 +83,7 @@ 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) {
|
package/dist/index.mjs
CHANGED
|
@@ -81,6 +81,7 @@ 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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "server-act",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
48
|
-
"typescript": "^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
|
},
|