@@ -19,16 +19,19 @@ export class SafeActionClient<
19
19
ODVES extends DVES | undefined , // override default validation errors shape
20
20
MetadataSchema extends StandardSchemaV1 | undefined = undefined ,
21
21
MD = InferOutputOrDefault < MetadataSchema , undefined > , // metadata type (inferred from metadata schema)
22
+ MDProvided extends boolean = MetadataSchema extends undefined ? true : false ,
22
23
Ctx extends object = { } ,
23
24
ISF extends ( ( ) => Promise < StandardSchemaV1 > ) | undefined = undefined , // input schema function
24
25
IS extends StandardSchemaV1 | undefined = ISF extends Function ? Awaited < ReturnType < ISF > > : undefined , // input schema
25
26
OS extends StandardSchemaV1 | undefined = undefined , // output schema
26
27
const BAS extends readonly StandardSchemaV1 [ ] = [ ] ,
27
28
CVE = undefined ,
28
29
> {
29
- readonly #args: SafeActionClientArgs < ServerError , ODVES , MetadataSchema , MD , Ctx , ISF , IS , OS , BAS , CVE > ;
30
+ readonly #args: SafeActionClientArgs < ServerError , ODVES , MetadataSchema , MD , MDProvided , Ctx , ISF , IS , OS , BAS , CVE > ;
30
31
31
- constructor ( args : SafeActionClientArgs < ServerError , ODVES , MetadataSchema , MD , Ctx , ISF , IS , OS , BAS , CVE > ) {
32
+ constructor (
33
+ args : SafeActionClientArgs < ServerError , ODVES , MetadataSchema , MD , MDProvided , Ctx , ISF , IS , OS , BAS , CVE >
34
+ ) {
32
35
this . #args = args ;
33
36
}
34
37
@@ -56,6 +59,7 @@ export class SafeActionClient<
56
59
return new SafeActionClient ( {
57
60
...this . #args,
58
61
metadata : data ,
62
+ metadataProvided : true ,
59
63
} ) ;
60
64
}
61
65
@@ -141,6 +145,9 @@ export class SafeActionClient<
141
145
* {@link https://next-safe-action.dev/docs/define-actions/instance-methods#action--stateaction See docs for more information}
142
146
*/
143
147
action < Data extends InferOutputOrDefault < OS , any > > (
148
+ this : MDProvided extends true
149
+ ? SafeActionClient < ServerError , ODVES , MetadataSchema , MD , MDProvided , Ctx , ISF , IS , OS , BAS , CVE >
150
+ : never ,
144
151
serverCodeFn : ServerCodeFn < MD , Ctx , IS , BAS , Data > ,
145
152
utils ?: SafeActionUtils < ServerError , MD , Ctx , IS , BAS , CVE , Data >
146
153
) {
@@ -156,6 +163,9 @@ export class SafeActionClient<
156
163
* {@link https://next-safe-action.dev/docs/define-actions/instance-methods#action--stateaction See docs for more information}
157
164
*/
158
165
stateAction < Data extends InferOutputOrDefault < OS , any > > (
166
+ this : MDProvided extends true
167
+ ? SafeActionClient < ServerError , ODVES , MetadataSchema , MD , MDProvided , Ctx , ISF , IS , OS , BAS , CVE >
168
+ : never ,
159
169
serverCodeFn : StateServerCodeFn < ServerError , MD , Ctx , IS , BAS , CVE , Data > ,
160
170
utils ?: SafeActionUtils < ServerError , MD , Ctx , IS , BAS , CVE , Data >
161
171
) {
0 commit comments