Skip to content

Commit

Permalink
fix: use # instead of private keyword (#5625)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name committed Apr 10, 2024
1 parent 75dd0b5 commit 619b253
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions packages/server/core/src/base/middlewares/customServer/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ export function createBaseHookContext(c: Context<ServerEnv>): HookContext {
}

class BaseHookRequest implements ModernRequest {
private req: HonoRequest;
#req: HonoRequest;

private c: Context;
#c: Context;

private headersData: Record<string, string | undefined> = {};
#headersData: Record<string, string | undefined> = {};

#headers: Record<string, string | undefined>;

constructor(c: Context) {
this.c = c;
this.req = c.req;
this.#c = c;
this.#req = c.req;

const rawHeaders = this.req.raw.headers;
const rawHeaders = this.#req.raw.headers;

rawHeaders.forEach((value, key) => {
this.headersData[key] = value;
this.#headersData[key] = value;
});

this.#headers = new Proxy(this.headersData, {
this.#headers = new Proxy(this.#headersData, {
get(target, p) {
return target[p as string];
},
Expand All @@ -53,7 +53,7 @@ class BaseHookRequest implements ModernRequest {

get url(): string {
// compat old middlwares,
return this.req.path;
return this.#req.path;
}

// TODO: remove next major version
Expand All @@ -62,7 +62,7 @@ class BaseHookRequest implements ModernRequest {
}

get host(): string {
return getHost(this.req.raw);
return getHost(this.#req.raw);
}

// TODO: remove next major version
Expand All @@ -71,7 +71,7 @@ class BaseHookRequest implements ModernRequest {
}

get pathname(): string {
return this.req.path;
return this.#req.path;
}

// TODO: remove next major version
Expand All @@ -80,7 +80,7 @@ class BaseHookRequest implements ModernRequest {
}

get query(): Record<string, any> {
return this.req.query();
return this.#req.query();
}

// TODO: remove next major version
Expand All @@ -101,14 +101,14 @@ class BaseHookRequest implements ModernRequest {
return {
// FIXME: ModernRequest Type Error
get: (key: string) => {
return getCookie(this.c, key) as string;
return getCookie(this.#c, key) as string;
},
};
}

get cookie(): string {
// FIXME: ModernRequest Type Error
return this.req.header('cookie') as string;
return this.#req.header('cookie') as string;
}

// TODO: remove next major version
Expand All @@ -125,14 +125,14 @@ class BaseHookResponse implements ModernResponse {
* */
private_overrided: boolean = false;

private c: Context;
#c: Context;

constructor(c: Context) {
this.c = c;
this.#c = c;
}

get(key: string) {
return this.c.res.headers.get(key) as
return this.#c.res.headers.get(key) as
| string
| number
| string[]
Expand All @@ -142,27 +142,27 @@ class BaseHookResponse implements ModernResponse {
set(key: string, value: string | number) {
// we should append, if the key is `set-cookie`
if (['set-cookie', 'Set-Cookie'].includes(key)) {
this.c.header(key, value.toString(), {
this.#c.header(key, value.toString(), {
append: true,
});
} else {
this.c.header(key, value.toString());
this.#c.header(key, value.toString());
}
}

status(code: number) {
this.c.status(code);
this.#c.status(code);
}

get cookies() {
const setCookie = (key: string, value: string) => {
this.c.header('set-cookie', `${key}=${value}`, {
this.#c.header('set-cookie', `${key}=${value}`, {
append: true,
});
};

const clearCookie = () => {
this.c.header('set-cookie', undefined);
this.#c.header('set-cookie', undefined);
};

return {
Expand All @@ -180,7 +180,7 @@ class BaseHookResponse implements ModernResponse {
}
| undefined,
) {
this.c.res = this.c.newResponse(body, options);
this.#c.res = this.#c.newResponse(body, options);
this.private_overrided = true;
}
}

0 comments on commit 619b253

Please sign in to comment.