Skip to content

Commit f36392a

Browse files
authoredApr 7, 2024··
fix: exported class expression ts error 4094 (#96)
1 parent 04c080d commit f36392a

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed
 

‎packages/next-safe-action/src/index.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ import {
2020
import type { ValidationErrors } from "./validation-errors.types";
2121

2222
class SafeActionClient<const ServerError, const Ctx = null> {
23-
private readonly handleServerErrorLog: NonNullable<
23+
readonly #handleServerErrorLog: NonNullable<
2424
SafeActionClientOpts<ServerError>["handleServerErrorLog"]
2525
>;
26-
private readonly handleReturnedServerError: NonNullable<
26+
readonly #handleReturnedServerError: NonNullable<
2727
SafeActionClientOpts<ServerError>["handleReturnedServerError"]
2828
>;
2929

30-
private middlewareFns: MiddlewareFn<ServerError, any, any, any>[];
31-
private _metadata: ActionMetadata = {};
30+
#middlewareFns: MiddlewareFn<ServerError, any, any, any>[];
31+
#metadata: ActionMetadata = {};
3232

3333
constructor(
3434
opts: { middlewareFns: MiddlewareFn<ServerError, any, any, any>[] } & Required<
3535
SafeActionClientOpts<ServerError>
3636
>
3737
) {
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;
4141
}
4242

4343
/**
@@ -47,9 +47,9 @@ class SafeActionClient<const ServerError, const Ctx = null> {
4747
*/
4848
public clone() {
4949
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
5353
});
5454
}
5555

@@ -61,12 +61,12 @@ class SafeActionClient<const ServerError, const Ctx = null> {
6161
public use<const ClientInput, const NextCtx>(
6262
middlewareFn: MiddlewareFn<ServerError, ClientInput, Ctx, NextCtx>
6363
) {
64-
this.middlewareFns.push(middlewareFn);
64+
this.#middlewareFns.push(middlewareFn);
6565

6666
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,
7070
});
7171
}
7272

@@ -76,7 +76,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
7676
* @returns {Function} Define a new action
7777
*/
7878
public metadata(data: ActionMetadata) {
79-
this._metadata = data;
79+
this.#metadata = data;
8080

8181
return {
8282
schema: this.schema.bind(this),
@@ -107,7 +107,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
107107

108108
// Execute the middleware stack.
109109
const executeMiddlewareChain = async (idx = 0) => {
110-
const currentFn = classThis.middlewareFns[idx];
110+
const currentFn = classThis.#middlewareFns[idx];
111111

112112
middlewareResult.ctx = prevCtx;
113113

@@ -116,7 +116,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
116116
await currentFn({
117117
clientInput, // pass raw client input
118118
ctx: prevCtx,
119-
metadata: classThis._metadata,
119+
metadata: classThis.#metadata,
120120
next: async ({ ctx }) => {
121121
prevCtx = ctx;
122122
await executeMiddlewareChain(idx + 1);
@@ -134,7 +134,7 @@ class SafeActionClient<const ServerError, const Ctx = null> {
134134
const data =
135135
(await serverCodeFn(parsedInput.data, {
136136
ctx: prevCtx,
137-
metadata: classThis._metadata,
137+
metadata: classThis.#metadata,
138138
})) ?? null;
139139
middlewareResult.success = true;
140140
middlewareResult.data = data;
@@ -159,10 +159,10 @@ class SafeActionClient<const ServerError, const Ctx = null> {
159159
// the default message.
160160
const error = isError(e) ? e : new Error(DEFAULT_SERVER_ERROR_MESSAGE);
161161

162-
await Promise.resolve(classThis.handleServerErrorLog(error));
162+
await Promise.resolve(classThis.#handleServerErrorLog(error));
163163

164164
middlewareResult.serverError = await Promise.resolve(
165-
classThis.handleReturnedServerError(error)
165+
classThis.#handleReturnedServerError(error)
166166
);
167167
}
168168
};

0 commit comments

Comments
 (0)
Please sign in to comment.