jetpath
Version:
A performance-first cross-runtime API framework without the boilerplate
117 lines (116 loc) • 5.5 kB
TypeScript
import { type IncomingMessage } from 'node:http';
import type { allowedMethods, compilerType, FileOptions, HTTPBody, JetMiddleware, 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?: unknown;
origin?: string[];
}): void;
export declare const JetSocketInstance: JetSocket;
export declare const _JetPath_paths: Record<methods, Record<string, JetRoute>>;
export declare const _JetPath_paths_trie: Record<methods, Trie>;
export declare const _jet_middleware: Record<string, ((ctx: Context, err?: unknown) => void | Promise<void>) | ((ctx: Context, err?: unknown) => void | Promise<void>)[]>;
export declare const ctxPool: Context[];
export declare let runtime: Record<'bun' | 'deno' | 'node' | 'edge' | 'cloudflare_worker' | 'aws_lambda', boolean>;
export declare function abstractPluginCreator(ctx: Context): Record<string, () => void>;
export declare const isNode: boolean;
export declare const server: (plugs: JetPlugin[], options: jetOptions) => {
listen: any;
edge: boolean;
};
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 getHandlersEdge(modules: JetRoute[] & JetMiddleware[]): Promise<void>;
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) => Promise<void> | void) | ((ctx: any) => 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', connectionLinks: {
local: string;
external: string;
}, generatedRoutesFilePath?: string): Promise<void>;
export declare function getLocalIP(): any;
export declare const fs: () => {
opendir: typeof import("fs/promises").opendir;
readdir: typeof import("fs/promises").readdir;
readFile: typeof import("fs/promises").readFile;
writeFile: typeof import("fs/promises").writeFile;
dirname: (path: string) => string;
join: (...paths: string[]) => string;
resolve: (...paths: string[]) => string;
sep: "\\" | "/";
cwd: () => string;
createReadStream: typeof import("fs").createReadStream;
realpathSync: typeof import("fs").realpathSync;
createServer: typeof import("http").createServer;
networkInterfaces: typeof import("os").networkInterfaces;
execFile: typeof import("child_process").execFile;
mkdirSync: typeof import("fs").mkdirSync;
pathToFileURL: typeof import("url").pathToFileURL;
};