UNPKG

jetpath

Version:

Jetpath - A fast, seamless and minimalist framework for Node, Deno and Bun.js. Embrace the speed and elegance of the next-gen server-side experience.

95 lines (94 loc) 4.41 kB
import { type IncomingMessage } from "node:http"; import type { allowedMethods, compilerType, FileOptions, HTTPBody, jetOptions, JetRoute, methods, ValidationOptions } from "./types.js"; import { ArraySchema, BooleanSchema, Context, DateSchema, FileSchema, JetPlugin, JetSocket, NumberSchema, ObjectSchema, SchemaBuilder, StringSchema, Trie } from "./classes.js"; export declare function corsMiddleware(options: { exposeHeaders?: string[]; allowMethods?: allowedMethods; allowHeaders?: string[]; keepHeadersOnError?: boolean; maxAge?: string; credentials?: boolean; secureContext?: { "Cross-Origin-Opener-Policy": "same-origin" | "unsafe-none" | "same-origin-allow-popups"; "Cross-Origin-Embedder-Policy": "require-corp" | "unsafe-none"; }; privateNetworkAccess?: any; origin?: string[]; }): void; export declare const JetSocketInstance: JetSocket; export declare let _JetPath_paths: Record<methods, Record<string, JetRoute>>; export declare let _JetPath_paths_trie: Record<methods, Trie>; export declare const _jet_middleware: Record<string, (ctx: Context, err?: unknown) => void | Promise<void>>; export declare const ctxPool: Context[]; export declare let runtime: Record<"bun" | "deno" | "node" | "edge", boolean>; export declare function abstractPluginCreator(ctx: Context): Record<string, Function>; export declare const isNode: boolean; export declare const server: (plugs: JetPlugin[], options: jetOptions) => { listen: any; edge: boolean; } | void; export declare const getCtx: (req: IncomingMessage | Request, res: any, path: string, route: JetRoute, params?: Record<string, any>) => Context; export declare function getHandlers(source: string, print: boolean, errorsCount?: { file: string; error: string; }[] | undefined, again?: boolean): Promise<{ file: string; error: string; }[] | undefined>; export declare function validator<T extends Record<string, any>>(schema: HTTPBody<T> | undefined, data: any): T; export declare const compileUI: (UI: string, options: jetOptions, api: string) => string; export declare const compileAPI: (options: jetOptions) => [number, string]; /** * Assigns middleware functions to routes while ensuring that each route gets exactly one middleware function. * A middleware function can be shared across multiple routes. * * @param _JetPath_paths - An object mapping HTTP methods to route-handler maps. * @param _jet_middleware - An object mapping route paths to an array of middleware functions. */ export declare function assignMiddleware(_JetPath_paths: { [method: string]: { [route: string]: any; }; }, _jet_middleware: { [route: string]: (ctx: any, next: () => Promise<void>) => Promise<void> | void; }): void; export declare function parseFormData(rawBody: Uint8Array, contentType: string, options?: { maxBodySize?: number; }): { [x: string]: string | string[] | { fileName: string; content: Uint8Array; mimeType: string; size: number; }; }; export declare function parseUrlEncoded(bodyText: string): Record<string, string | string[]>; /** * Reads the request/stream and returns a Promise that resolves to the parsed body. */ export declare function parseRequest(req: any, options?: { maxBodySize?: number; contentType?: string; }): Promise<Record<string, any>>; export declare const v: { string: (options?: ValidationOptions) => StringSchema; number: (options?: ValidationOptions) => NumberSchema; boolean: () => BooleanSchema; array: (itemType?: SchemaBuilder) => ArraySchema; object: (shape?: Record<string, SchemaBuilder>) => ObjectSchema; date: () => DateSchema; file: (options?: FileOptions) => FileSchema; }; /** * Configures the endpoint with API documentation and validation * @param endpoint - The endpoint function to configure * @returns The current compiler object */ export declare function use<JetData extends { body?: Record<string, any>; params?: Record<string, any>; query?: Record<string, any>; response?: Record<string, any>; }, JetPluginTypes extends Record<string, unknown>[] = []>(endpoint: JetRoute<JetData, JetPluginTypes>): compilerType<JetData, JetPluginTypes>; export declare function codeGen(ROUTES_DIR: string, mode: "ON" | "WARN", generatedRoutesFilePath?: string): Promise<void>; export declare function getLocalIP(): any;