server-act 1.2.1 → 1.3.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 +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +13 -3
- package/dist/index.mjs +13 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -18,17 +18,19 @@ interface ActionBuilder<TParams extends ActionParams> {
|
|
|
18
18
|
/**
|
|
19
19
|
* Middleware allows you to run code before the action, its return value will pass as context to the action.
|
|
20
20
|
*/
|
|
21
|
-
middleware: <TContext>(middleware: () => Promise<TContext> | TContext) => ActionBuilder<{
|
|
21
|
+
middleware: <TContext>(middleware: () => Promise<TContext> | TContext) => Omit<ActionBuilder<{
|
|
22
22
|
_input: TParams["_input"];
|
|
23
23
|
_context: TContext;
|
|
24
|
-
}>;
|
|
24
|
+
}>, "middleware">;
|
|
25
25
|
/**
|
|
26
26
|
* Input validation for the action.
|
|
27
27
|
*/
|
|
28
|
-
input: <TParser extends z.ZodType>(input:
|
|
28
|
+
input: <TParser extends z.ZodType>(input: ((params: {
|
|
29
|
+
ctx: InferContextType<TParams["_context"]>;
|
|
30
|
+
}) => TParser) | TParser) => Omit<ActionBuilder<{
|
|
29
31
|
_input: TParser;
|
|
30
32
|
_context: TParams["_context"];
|
|
31
|
-
}>;
|
|
33
|
+
}>, "input">;
|
|
32
34
|
/**
|
|
33
35
|
* Create an action.
|
|
34
36
|
*/
|
|
@@ -37,7 +39,7 @@ interface ActionBuilder<TParams extends ActionParams> {
|
|
|
37
39
|
input: InferInputType<TParams["_input"], "out">;
|
|
38
40
|
}) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams["_input"], "in">) => Promise<TOutput>>;
|
|
39
41
|
/**
|
|
40
|
-
* Create an action for React `
|
|
42
|
+
* Create an action for React `useActionState`
|
|
41
43
|
*/
|
|
42
44
|
formAction: <TState, TPrevState = undefined>(action: (params: Prettify<{
|
|
43
45
|
ctx: InferContextType<TParams["_context"]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,17 +18,19 @@ interface ActionBuilder<TParams extends ActionParams> {
|
|
|
18
18
|
/**
|
|
19
19
|
* Middleware allows you to run code before the action, its return value will pass as context to the action.
|
|
20
20
|
*/
|
|
21
|
-
middleware: <TContext>(middleware: () => Promise<TContext> | TContext) => ActionBuilder<{
|
|
21
|
+
middleware: <TContext>(middleware: () => Promise<TContext> | TContext) => Omit<ActionBuilder<{
|
|
22
22
|
_input: TParams["_input"];
|
|
23
23
|
_context: TContext;
|
|
24
|
-
}>;
|
|
24
|
+
}>, "middleware">;
|
|
25
25
|
/**
|
|
26
26
|
* Input validation for the action.
|
|
27
27
|
*/
|
|
28
|
-
input: <TParser extends z.ZodType>(input:
|
|
28
|
+
input: <TParser extends z.ZodType>(input: ((params: {
|
|
29
|
+
ctx: InferContextType<TParams["_context"]>;
|
|
30
|
+
}) => TParser) | TParser) => Omit<ActionBuilder<{
|
|
29
31
|
_input: TParser;
|
|
30
32
|
_context: TParams["_context"];
|
|
31
|
-
}>;
|
|
33
|
+
}>, "input">;
|
|
32
34
|
/**
|
|
33
35
|
* Create an action.
|
|
34
36
|
*/
|
|
@@ -37,7 +39,7 @@ interface ActionBuilder<TParams extends ActionParams> {
|
|
|
37
39
|
input: InferInputType<TParams["_input"], "out">;
|
|
38
40
|
}) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams["_input"], "in">) => Promise<TOutput>>;
|
|
39
41
|
/**
|
|
40
|
-
* Create an action for React `
|
|
42
|
+
* Create an action for React `useActionState`
|
|
41
43
|
*/
|
|
42
44
|
formAction: <TState, TPrevState = undefined>(action: (params: Prettify<{
|
|
43
45
|
ctx: InferContextType<TParams["_context"]>;
|
package/dist/index.js
CHANGED
|
@@ -63,15 +63,22 @@ 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
|
|
66
|
+
const inputSchema = typeof _def.input === "function" ? _def.input({
|
|
67
|
+
ctx
|
|
68
|
+
}) : _def.input;
|
|
69
|
+
const result = yield inputSchema.safeParseAsync(input);
|
|
67
70
|
if (!result.success) {
|
|
68
71
|
console.error("❌ Input validation error:", result.error.errors);
|
|
69
72
|
throw new Error("Input validation error");
|
|
70
73
|
}
|
|
74
|
+
return yield action({
|
|
75
|
+
ctx,
|
|
76
|
+
input: result.data
|
|
77
|
+
});
|
|
71
78
|
}
|
|
72
79
|
return yield action({
|
|
73
80
|
ctx,
|
|
74
|
-
input
|
|
81
|
+
input: undefined
|
|
75
82
|
});
|
|
76
83
|
});
|
|
77
84
|
},
|
|
@@ -79,7 +86,10 @@ function createServerActionBuilder(initDef = {}) {
|
|
|
79
86
|
return /*#__PURE__*/ _async_to_generator(function*(prevState, formData) {
|
|
80
87
|
const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
|
|
81
88
|
if (_def.input) {
|
|
82
|
-
const
|
|
89
|
+
const inputSchema = typeof _def.input === "function" ? _def.input({
|
|
90
|
+
ctx
|
|
91
|
+
}) : _def.input;
|
|
92
|
+
const result = yield inputSchema.safeParseAsync(formData);
|
|
83
93
|
if (!result.success) {
|
|
84
94
|
return yield action({
|
|
85
95
|
ctx,
|
package/dist/index.mjs
CHANGED
|
@@ -61,15 +61,22 @@ 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
|
|
64
|
+
const inputSchema = typeof _def.input === "function" ? _def.input({
|
|
65
|
+
ctx
|
|
66
|
+
}) : _def.input;
|
|
67
|
+
const result = yield inputSchema.safeParseAsync(input);
|
|
65
68
|
if (!result.success) {
|
|
66
69
|
console.error("❌ Input validation error:", result.error.errors);
|
|
67
70
|
throw new Error("Input validation error");
|
|
68
71
|
}
|
|
72
|
+
return yield action({
|
|
73
|
+
ctx,
|
|
74
|
+
input: result.data
|
|
75
|
+
});
|
|
69
76
|
}
|
|
70
77
|
return yield action({
|
|
71
78
|
ctx,
|
|
72
|
-
input
|
|
79
|
+
input: undefined
|
|
73
80
|
});
|
|
74
81
|
});
|
|
75
82
|
},
|
|
@@ -77,7 +84,10 @@ function createServerActionBuilder(initDef = {}) {
|
|
|
77
84
|
return /*#__PURE__*/ _async_to_generator(function*(prevState, formData) {
|
|
78
85
|
const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
|
|
79
86
|
if (_def.input) {
|
|
80
|
-
const
|
|
87
|
+
const inputSchema = typeof _def.input === "function" ? _def.input({
|
|
88
|
+
ctx
|
|
89
|
+
}) : _def.input;
|
|
90
|
+
const result = yield inputSchema.safeParseAsync(formData);
|
|
81
91
|
if (!result.success) {
|
|
82
92
|
return yield action({
|
|
83
93
|
ctx,
|