import { IncomingMessage, Server, ServerResponse } from "node:http"; import type { _JetPath_paths, v } from "./functions.js"; import { type CookieOptions, SchemaBuilder } from "./classes.js"; import type { BunFile } from "bun"; import type Stream from "node:stream"; export type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never; export interface JetContext; params?: Record; query?: Record; } = { body: {}; params: {}; query: {}; }, JetPluginTypes extends Record[] = []> { /** * an object you can set values to per request */ state: Record; /** * an object you can set values to per request */ plugins: UnionToIntersection & Record; /** * get body params after /? */ /** * get query params after /? */ /** * get route params in /:thing */ params: Record; /** * websocket socket event class */ connection: jet_socket; /** * reply the request */ request: Request; /** * API status */ code: number; /** * send a stream * @param stream - The stream or file path to send * @param folder - The folder to save the stream to * @param ContentType - The content type of the stream * * PLEASE PROVIDE A VALID FOLDER PATH FOR SECURITY REASONS */ sendStream(stream: Stream | string | BunFile, config?: { folder?: string; ContentType?: string; }): void | never; /** * send a file for download * @param stream - The file path to send * @param folder - The folder to save the stream to * @param ContentType - The content type of the stream * * PLEASE PROVIDE A VALID FOLDER PATH FOR SECURITY REASONS */ download(stream: string | BunFile, config?: { folder?: string; ContentType?: string; }): void; /** * send a direct response * *Only for deno and bun */ sendResponse(response?: Response): void; /** * reply the request */ send(data: unknown, statusCode?: number, ContentType?: string): void; /** * redirect the request */ redirect(url: string): void; /** * get request header values */ get(field: string): string | undefined; /** * set request header values */ set(field: string, value: string): void; /** * Parses the request body */ getCookie(name: string): string | undefined; getCookies(): Record; setCookie(name: string, value: string, options: CookieOptions): void; clearCookie(name: string, options: CookieOptions): void; parse(options?: { maxBodySize?: number; contentType?: string; }): Promise; parseQuery(): Record; /** * Upgrade the request to a WebSocket connection */ upgrade(): void | never; /** * get original request */ path: string; payload?: string; _2?: Record; _3?: any; _4?: boolean | undefined; _5?: JetRoute | undefined; _6?: Response | false; } export type JetPluginExecutorInitParams = { runtime: { node: boolean; bun: boolean; deno: boolean; }; server: Server; routesObject: typeof _JetPath_paths; JetPath_app: (req: Request) => Response; }; export type contentType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json"; export type methods = "GET" | "POST" | "OPTIONS" | "DELETE" | "HEAD" | "PUT" | "CONNECT" | "TRACE" | "PATCH"; export type allowedMethods = methods[]; export interface BunClusterOptions { enabled?: boolean; workers?: number | "auto"; silent?: boolean; } export type jetOptions = { /** * edge grabber helps capture defined API functions in an edge environment * and avoids fs system scanning. * @example * ```ts * edgeGrabber: [ * GET_api_users, * POST_api_users, * Middleware_api_users, * ] * ``` */ edgeGrabber?: JetRoute[] & JetMiddleware[]; /** * upgrade the request to a WebSocket connection */ upgrade?: boolean; /** * source of the app */ source?: string; /** * global headers */ globalHeaders?: Record; /** * strict mode */ strictMode?: "ON" | "OFF" | "WARN"; /** * generated routes file path * putting the file on the frontend folder will make it accessible * during build time * @default generates nothing */ generatedRoutesFilePath?: string; runtimes?: { bun?: { reusePort?: boolean; }; deno?: {}; node?: {}; aws_lambda?: {}; cloudflare_worker?: {}; }; /** * keep alive timeout */ keepAliveTimeout?: number; /** * api documentation options */ apiDoc?: { display?: "UI" | "HTTP" | false; environments?: Record; name?: string; info?: string; color?: string; logo?: string; path?: string; password?: string; username?: string; }; /** * credentials options */ credentials?: { cert: string; key: string; }; /** * port */ port?: number; /** * cors options */ cors?: { allowMethods?: allowedMethods; secureContext?: { "Cross-Origin-Opener-Policy": "same-origin" | "unsafe-none" | "same-origin-allow-popups"; "Cross-Origin-Embedder-Policy": "require-corp" | "unsafe-none"; }; allowHeaders?: string[]; exposeHeaders?: string[]; keepHeadersOnError?: boolean; maxAge?: string; credentials?: boolean; privateNetworkAccess?: any; origin?: string[]; } | boolean; /** * Bun cluster options for multi-core utilization * Uses SO_REUSEPORT for load balancing (Linux only) */ cluster?: BunClusterOptions; }; export type HTTPBody> = { [x in keyof Obj]: { err?: string; type?: "string" | "number" | "file" | "object" | "boolean" | "array" | "date"; arrayType?: "string" | "number" | "file" | "object" | "boolean" | "array" | "date"; RegExp?: RegExp; inputAccept?: string; inputType?: "date" | "email" | "file" | "password" | "number" | "time" | "tel" | "datetime" | "url"; inputDefaultValue?: string | number | boolean; required?: boolean; validator?: (value: any) => boolean | string; objectSchema?: HTTPBody>; }; }; export type Middleware; params?: Record; query?: Record; } = { body: {}; params: {}; query: {}; }, JetPluginTypes extends Record[] = []> = (ctx: JetContext) => void | Promise | ((ctx: JetContext, error: unknown) => void | Promise) | Promise<((ctx: JetContext, error: unknown) => void | Promise) | undefined> | undefined; export type JetMiddleware; params?: Record; query?: Record; } = { body: {}; params: {}; query: {}; }, JetPluginTypes extends Record[] = []> = Middleware | Middleware[]; export type JetRoute; params?: Record; query?: Record; response?: Record; } = { body: {}; params: {}; query: {}; response: {}; title: ""; description: ""; method: ""; path: ""; jet_middleware: []; }, JetPluginTypes extends Record[] = []> = { (ctx: JetContext): Promise | void; body?: HTTPBody>; headers?: Record; title?: string; description?: string; method?: string; path?: string; jet_middleware?: Middleware[]; params?: HTTPBody>; query?: HTTPBody>; response?: HTTPBody>; }; interface jet_socket { addEventListener(event: "message" | "close" | "drain" | "open", listener: (socket: WebSocket, ...params: any[]) => void): void; } export type JetFile = { fileName: string; content: Uint8Array; mimeType: string; }; export type SchemaType = "string" | "number" | "boolean" | "array" | "object" | "date" | "file"; export interface ValidationOptions { err?: string; RegExp?: RegExp; validator?: (value: any) => boolean | string; inputDefaultValue?: any; required?: boolean; } export interface FileOptions { inputAccept?: string; inputMultiple?: boolean; err?: string; } export interface ArrayOptions extends ValidationOptions { arrayType?: SchemaType | "object"; objectSchema?: HTTPBody; } export interface ObjectOptions extends ValidationOptions { objectSchema?: HTTPBody; } export type SchemaDefinition = { type: SchemaType; } & ValidationOptions & ArrayOptions & ObjectOptions; export type compilerType; params?: Record; query?: Record; response?: Record; }, JetPluginTypes extends Record[] = []> = { /** * Sets the API body validation and documentation body for the endpoint */ body: (schemaFn: (t: typeof v) => Partial>, SchemaBuilder>>) => compilerType; /** * Sets the API body validation and documentation body for the endpoint */ response: (schemaFn: (t: typeof v) => Partial>, SchemaBuilder>>) => compilerType; /** * Sets the API documentation query for the endpoint */ query: (schemaFn: (t: typeof v) => Partial>, SchemaBuilder>>) => compilerType; /** * Sets the API documentation title for the endpoint */ title: (title: string) => compilerType; /** * Sets the API documentation description for the endpoint */ description: (description: string) => compilerType; }; export {};