Skip to content

Commit

Permalink
Add build files for fastify types
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Oct 1, 2024
1 parent f4692c0 commit 0ff1140
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/build/framework/fastify/framework.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
import type { FastifyRequest as OriginalFastifyRequest, FastifyReply, FastifyPluginCallback } from "fastify";
import { FastifyRequest as OriginalFastifyRequest, FastifyReply, FastifyPluginCallback } from "./types";
import type { HTTPMethod } from "../../types";
import { BaseRequest } from "../request";
import { BaseResponse } from "../response";
Expand Down
2 changes: 1 addition & 1 deletion lib/build/framework/fastify/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class FastifyResponse extends response_1.BaseResponse {
);
let oldHeaders = this.response.getHeader(constants_1.COOKIE_HEADER);
if (oldHeaders === undefined) oldHeaders = [];
else if (!(oldHeaders instanceof Array)) oldHeaders = [oldHeaders];
else if (!(oldHeaders instanceof Array)) oldHeaders = [oldHeaders.toString()];
this.response.removeHeader(constants_1.COOKIE_HEADER);
this.response.header(constants_1.COOKIE_HEADER, [
...oldHeaders.filter((h) => !h.startsWith(key + "=")),
Expand Down
20 changes: 3 additions & 17 deletions lib/build/framework/fastify/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
// @ts-nocheck
/// <reference types="node" />
export type { SessionRequest } from "./framework";
export declare const plugin: import("fastify").FastifyPluginCallback<
Record<never, never>,
import("fastify").RawServerDefault
>;
export declare const plugin: import("./types").FastifyPluginCallback;
export declare const errorHandler: () => (
err: any,
req: import("fastify").FastifyRequest<
import("fastify/types/route").RouteGenericInterface,
import("fastify").RawServerDefault,
import("http").IncomingMessage
>,
res: import("fastify").FastifyReply<
import("fastify").RawServerDefault,
import("http").IncomingMessage,
import("http").ServerResponse<import("http").IncomingMessage>,
import("fastify/types/route").RouteGenericInterface,
unknown
>
req: import("./types").FastifyRequest,
res: import("./types").FastifyReply
) => Promise<void>;
export declare const wrapRequest: (unwrapped: any) => import("..").BaseRequest;
export declare const wrapResponse: (unwrapped: any) => import("..").BaseResponse;
25 changes: 25 additions & 0 deletions lib/build/framework/fastify/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-nocheck
/**
* Define fastify types based on the parts that are used in the codebase.
*/
export interface FastifyRequest {
body: any;
query: Record<string, string | string[] | undefined>;
headers: Record<string, string | string[] | undefined>;
method: string;
url: string;
}
export interface FastifyReply {
sent: boolean;
statusCode: number;
getHeaders(): Record<string, number | string | string[] | undefined>;
send(payload?: any): FastifyReply;
header(key: any, value: any): FastifyReply;
removeHeader(key: any): FastifyReply;
getHeader(key: any): number | string | string[] | undefined;
type(contentType: string): FastifyReply;
}
export interface FastifyInstance {
addHook(name: string, hook: (req: FastifyRequest, reply: FastifyReply) => void): FastifyInstance;
}
export declare type FastifyPluginCallback = (instance: FastifyInstance, opts: any, done: (err?: Error) => void) => void;
5 changes: 5 additions & 0 deletions lib/build/framework/fastify/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
/**
* Define fastify types based on the parts that are used in the codebase.
*/
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 1 addition & 1 deletion lib/build/recipe/session/framework/fastify.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck
import { VerifySessionOptions } from "..";
import { SessionRequest } from "../../../framework/fastify/framework";
import { FastifyReply, FastifyRequest as OriginalFastifyRequest } from "fastify";
import { FastifyReply, FastifyRequest as OriginalFastifyRequest } from "../../../framework/fastify/types";
export declare function verifySession<TRequest extends OriginalFastifyRequest = OriginalFastifyRequest>(
options?: VerifySessionOptions
): (req: SessionRequest<TRequest>, res: FastifyReply) => Promise<void>;

0 comments on commit 0ff1140

Please sign in to comment.