@@ -20,24 +20,24 @@ import {
20
20
import type { ValidationErrors } from "./validation-errors.types" ;
21
21
22
22
class SafeActionClient < const ServerError , const Ctx = null > {
23
- private readonly handleServerErrorLog : NonNullable <
23
+ readonly # handleServerErrorLog: NonNullable <
24
24
SafeActionClientOpts < ServerError > [ "handleServerErrorLog" ]
25
25
> ;
26
- private readonly handleReturnedServerError : NonNullable <
26
+ readonly # handleReturnedServerError: NonNullable <
27
27
SafeActionClientOpts < ServerError > [ "handleReturnedServerError" ]
28
28
> ;
29
29
30
- private middlewareFns : MiddlewareFn < ServerError , any , any , any > [ ] ;
31
- private _metadata : ActionMetadata = { } ;
30
+ # middlewareFns: MiddlewareFn < ServerError , any , any , any > [ ] ;
31
+ #metadata : ActionMetadata = { } ;
32
32
33
33
constructor (
34
34
opts : { middlewareFns : MiddlewareFn < ServerError , any , any , any > [ ] } & Required <
35
35
SafeActionClientOpts < ServerError >
36
36
>
37
37
) {
38
- this . middlewareFns = opts . middlewareFns ;
39
- this . handleServerErrorLog = opts . handleServerErrorLog ;
40
- this . handleReturnedServerError = opts . handleReturnedServerError ;
38
+ this . # middlewareFns = opts . middlewareFns ;
39
+ this . # handleServerErrorLog = opts . handleServerErrorLog ;
40
+ this . # handleReturnedServerError = opts . handleReturnedServerError ;
41
41
}
42
42
43
43
/**
@@ -47,9 +47,9 @@ class SafeActionClient<const ServerError, const Ctx = null> {
47
47
*/
48
48
public clone ( ) {
49
49
return new SafeActionClient < ServerError , Ctx > ( {
50
- handleReturnedServerError : this . handleReturnedServerError ,
51
- handleServerErrorLog : this . handleServerErrorLog ,
52
- middlewareFns : [ ...this . middlewareFns ] , // copy the middleware stack so we don't mutate it
50
+ handleReturnedServerError : this . # handleReturnedServerError,
51
+ handleServerErrorLog : this . # handleServerErrorLog,
52
+ middlewareFns : [ ...this . # middlewareFns] , // copy the middleware stack so we don't mutate it
53
53
} ) ;
54
54
}
55
55
@@ -61,12 +61,12 @@ class SafeActionClient<const ServerError, const Ctx = null> {
61
61
public use < const ClientInput , const NextCtx > (
62
62
middlewareFn : MiddlewareFn < ServerError , ClientInput , Ctx , NextCtx >
63
63
) {
64
- this . middlewareFns . push ( middlewareFn ) ;
64
+ this . # middlewareFns. push ( middlewareFn ) ;
65
65
66
66
return new SafeActionClient < ServerError , NextCtx > ( {
67
- middlewareFns : this . middlewareFns ,
68
- handleReturnedServerError : this . handleReturnedServerError ,
69
- handleServerErrorLog : this . handleServerErrorLog ,
67
+ middlewareFns : this . # middlewareFns,
68
+ handleReturnedServerError : this . # handleReturnedServerError,
69
+ handleServerErrorLog : this . # handleServerErrorLog,
70
70
} ) ;
71
71
}
72
72
@@ -76,7 +76,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
76
76
* @returns {Function } Define a new action
77
77
*/
78
78
public metadata ( data : ActionMetadata ) {
79
- this . _metadata = data ;
79
+ this . #metadata = data ;
80
80
81
81
return {
82
82
schema : this . schema . bind ( this ) ,
@@ -107,7 +107,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
107
107
108
108
// Execute the middleware stack.
109
109
const executeMiddlewareChain = async ( idx = 0 ) => {
110
- const currentFn = classThis . middlewareFns [ idx ] ;
110
+ const currentFn = classThis . # middlewareFns[ idx ] ;
111
111
112
112
middlewareResult . ctx = prevCtx ;
113
113
@@ -116,7 +116,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
116
116
await currentFn ( {
117
117
clientInput, // pass raw client input
118
118
ctx : prevCtx ,
119
- metadata : classThis . _metadata ,
119
+ metadata : classThis . #metadata ,
120
120
next : async ( { ctx } ) => {
121
121
prevCtx = ctx ;
122
122
await executeMiddlewareChain ( idx + 1 ) ;
@@ -134,7 +134,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
134
134
const data =
135
135
( await serverCodeFn ( parsedInput . data , {
136
136
ctx : prevCtx ,
137
- metadata : classThis . _metadata ,
137
+ metadata : classThis . #metadata ,
138
138
} ) ) ?? null ;
139
139
middlewareResult . success = true ;
140
140
middlewareResult . data = data ;
@@ -159,10 +159,10 @@ class SafeActionClient<const ServerError, const Ctx = null> {
159
159
// the default message.
160
160
const error = isError ( e ) ? e : new Error ( DEFAULT_SERVER_ERROR_MESSAGE ) ;
161
161
162
- await Promise . resolve ( classThis . handleServerErrorLog ( error ) ) ;
162
+ await Promise . resolve ( classThis . # handleServerErrorLog( error ) ) ;
163
163
164
164
middlewareResult . serverError = await Promise . resolve (
165
- classThis . handleReturnedServerError ( error )
165
+ classThis . # handleReturnedServerError( error )
166
166
) ;
167
167
}
168
168
} ;
0 commit comments