@gravito/core 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -764,14 +764,19 @@ declare class Route {
764
764
  name(name: string): this;
765
765
  static get(path: string, handler: RouteHandler): Route;
766
766
  static get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
767
+ static get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
767
768
  static post(path: string, handler: RouteHandler): Route;
768
769
  static post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
770
+ static post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
769
771
  static put(path: string, handler: RouteHandler): Route;
770
772
  static put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
773
+ static put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
771
774
  static delete(path: string, handler: RouteHandler): Route;
772
775
  static delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
776
+ static delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
773
777
  static patch(path: string, handler: RouteHandler): Route;
774
778
  static patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
779
+ static patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
775
780
  static resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
776
781
  static prefix(path: string): RouteGroup;
777
782
  static middleware(...handlers: any[]): RouteGroup;
@@ -824,14 +829,19 @@ declare class RouteGroup {
824
829
  group(callback: (router: Router | RouteGroup) => void): void;
825
830
  get(path: string, handler: RouteHandler): Route;
826
831
  get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
832
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
827
833
  post(path: string, handler: RouteHandler): Route;
828
834
  post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
835
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
829
836
  put(path: string, handler: RouteHandler): Route;
830
837
  put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
838
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
831
839
  delete(path: string, handler: RouteHandler): Route;
832
840
  delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
841
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
833
842
  patch(path: string, handler: RouteHandler): Route;
834
843
  patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
844
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
835
845
  resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
836
846
  }
837
847
  /**
@@ -844,6 +854,7 @@ declare class RouteGroup {
844
854
  * - Domain-based routing: router.domain('api.app').group(...)
845
855
  * - Middleware chaining: router.middleware(auth).group(...)
846
856
  * - FormRequest validation: router.post('/users', StoreUserRequest, [UserController, 'store'])
857
+ * - Inline Middleware: router.get('/users', authMiddleware, [UserController, 'index'])
847
858
  */
848
859
  declare class Router {
849
860
  private core;
@@ -911,83 +922,34 @@ declare class Router {
911
922
  middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
912
923
  /**
913
924
  * Register a GET route.
914
- *
915
- * @param path - The URL path for the route.
916
- * @param handler - The handler function or controller method.
917
- * @returns The registered Route instance for chaining.
918
- *
919
- * @example
920
- * ```typescript
921
- * router.get('/users', [UserController, 'index']);
922
- * ```
923
925
  */
924
926
  get(path: string, handler: RouteHandler): Route;
925
- /**
926
- * Register a GET route with a FormRequest for validation.
927
- *
928
- * @param path - The URL path.
929
- * @param request - The FormRequest class for validation.
930
- * @param handler - The handler function or controller method.
931
- *
932
- * @example
933
- * ```typescript
934
- * router.get('/search', SearchRequest, [Controller, 'search']);
935
- * ```
936
- */
937
927
  get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
928
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
938
929
  /**
939
930
  * Register a POST route.
940
- *
941
- * @param path - The URL path.
942
- * @param handler - The handler function or controller method.
943
- * @returns The registered Route instance.
944
- *
945
- * @example
946
- * ```typescript
947
- * router.post('/users', [UserController, 'store']);
948
- * ```
949
931
  */
950
932
  post(path: string, handler: RouteHandler): Route;
951
- /**
952
- * Register a POST route with validation.
953
- *
954
- * @param path - The URL path.
955
- * @param request - The FormRequest class.
956
- * @param handler - The handler.
957
- *
958
- * @example
959
- * ```typescript
960
- * router.post('/users', StoreUserRequest, [UserController, 'store']);
961
- * ```
962
- */
963
933
  post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
934
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
964
935
  /**
965
936
  * Register a PUT route.
966
- *
967
- * @param path - The URL path.
968
- * @param handler - The handler function.
969
- * @returns The registered Route instance.
970
937
  */
971
938
  put(path: string, handler: RouteHandler): Route;
972
939
  put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
940
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
973
941
  /**
974
942
  * Register a DELETE route.
975
- *
976
- * @param path - The URL path.
977
- * @param handler - The handler function.
978
- * @returns The registered Route instance.
979
943
  */
980
944
  delete(path: string, handler: RouteHandler): Route;
981
945
  delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
946
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
982
947
  /**
983
948
  * Register a PATCH route.
984
- *
985
- * @param path - The URL path.
986
- * @param handler - The handler function.
987
- * @returns The registered Route instance.
988
949
  */
989
950
  patch(path: string, handler: RouteHandler): Route;
990
951
  patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
952
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
991
953
  /**
992
954
  * Register a resource route (Laravel-style).
993
955
  */
@@ -995,7 +957,7 @@ declare class Router {
995
957
  /**
996
958
  * Internal Request Registration
997
959
  */
998
- req(method: HttpMethod, path: string, requestOrHandler: FormRequestClass | RouteHandler, handler?: RouteHandler, options?: RouteOptions): Route;
960
+ req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
999
961
  /**
1000
962
  * Resolve Controller Instance and Method
1001
963
  */
@@ -1273,9 +1235,12 @@ declare class PlanetCore {
1273
1235
  * Wraps Photon's request object to implement GravitoRequest
1274
1236
  */
1275
1237
  declare class PhotonRequestWrapper implements GravitoRequest {
1276
- private photonCtx;
1277
- private _cachedJson;
1238
+ readonly photonCtx: Context;
1278
1239
  constructor(photonCtx: Context);
1240
+ /**
1241
+ * Create a proxied instance to delegate to Photon's request
1242
+ */
1243
+ static create(photonCtx: Context): PhotonRequestWrapper;
1279
1244
  get url(): string;
1280
1245
  get method(): string;
1281
1246
  get path(): string;
@@ -2001,6 +1966,632 @@ declare const getRuntimeAdapter: () => RuntimeAdapter;
2001
1966
  declare const getPasswordAdapter: () => RuntimePasswordAdapter;
2002
1967
  declare const createSqliteDatabase: (path: string) => Promise<RuntimeSqliteDatabase>;
2003
1968
 
1969
+ /**
1970
+ * @fileoverview Gravito Core Engine Types
1971
+ *
1972
+ * Minimal, high-performance types for the standalone engine.
1973
+ * These are intentionally simpler than the full framework types.
1974
+ *
1975
+ * @module @gravito/core/engine
1976
+ */
1977
+
1978
+ /**
1979
+ * FastContext - The pooled request context
1980
+ */
1981
+ interface FastContext$1 {
1982
+ /** Request accessor */
1983
+ readonly req: FastRequest;
1984
+ /** Response helpers */
1985
+ json<T>(data: T, status?: number): Response;
1986
+ text(text: string, status?: number): Response;
1987
+ html(html: string, status?: number): Response;
1988
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
1989
+ body(data: BodyInit | null, status?: number): Response;
1990
+ /** Header management */
1991
+ header(name: string, value: string): void;
1992
+ status(code: number): void;
1993
+ /** Internal reset for pooling */
1994
+ reset(request: Request, params?: Record<string, string>): this;
1995
+ }
1996
+ /**
1997
+ * FastRequest - Minimal request interface
1998
+ */
1999
+ interface FastRequest {
2000
+ /** Full URL */
2001
+ readonly url: string;
2002
+ /** HTTP method */
2003
+ readonly method: string;
2004
+ /** Path without query */
2005
+ readonly path: string;
2006
+ /** Get route parameter */
2007
+ param(name: string): string | undefined;
2008
+ /** Get all route parameters */
2009
+ params(): Record<string, string>;
2010
+ /** Get query parameter */
2011
+ query(name: string): string | undefined;
2012
+ /** Get all query parameters */
2013
+ queries(): Record<string, string | string[]>;
2014
+ /** Get header */
2015
+ header(name: string): string | undefined;
2016
+ /** Get all headers */
2017
+ headers(): Record<string, string>;
2018
+ /** Parse JSON body */
2019
+ json<T = unknown>(): Promise<T>;
2020
+ /** Parse text body */
2021
+ text(): Promise<string>;
2022
+ /** Parse form data */
2023
+ formData(): Promise<FormData>;
2024
+ /** Raw Request object */
2025
+ readonly raw: Request;
2026
+ }
2027
+ /**
2028
+ * Route handler function
2029
+ */
2030
+ type Handler = (ctx: FastContext$1) => Response | Promise<Response>;
2031
+ /**
2032
+ * Middleware function
2033
+ */
2034
+ type Middleware = (ctx: FastContext$1, next: () => Promise<Response | undefined>) => Response | undefined | Promise<Response | undefined>;
2035
+ /**
2036
+ * Error handler function
2037
+ */
2038
+ type ErrorHandler = (error: Error, ctx: FastContext$1) => Response | Promise<Response>;
2039
+ /**
2040
+ * Not found handler function
2041
+ */
2042
+ type NotFoundHandler = (ctx: FastContext$1) => Response | Promise<Response>;
2043
+ /**
2044
+ * Route match result from router
2045
+ */
2046
+ interface RouteMatch {
2047
+ /** Matched handler */
2048
+ handler: Handler | null;
2049
+ /** Extracted route parameters */
2050
+ params: Record<string, string>;
2051
+ /** Middleware to execute */
2052
+ middleware: Middleware[];
2053
+ }
2054
+ /**
2055
+ * Engine configuration options
2056
+ */
2057
+ interface EngineOptions {
2058
+ /** Context pool size (default: 256) */
2059
+ poolSize?: number;
2060
+ /** Enable route compilation optimization (default: true) */
2061
+ enableAOT?: boolean;
2062
+ /** Custom error handler */
2063
+ onError?: ErrorHandler;
2064
+ /** Custom 404 handler */
2065
+ onNotFound?: NotFoundHandler;
2066
+ }
2067
+
2068
+ /**
2069
+ * @fileoverview Gravito - High-Performance Web Engine for Bun
2070
+ *
2071
+ * The standalone engine optimized exclusively for Bun runtime.
2072
+ * 99% API-compatible with Hono, but faster through Bun-specific optimizations.
2073
+ *
2074
+ * Key optimizations:
2075
+ * 1. Object pooling for zero-allocation request handling
2076
+ * 2. AOT router with O(1) static route lookup
2077
+ * 3. Lazy parsing - only parse what's accessed
2078
+ * 4. Direct Bun.serve integration without wrapper layers
2079
+ *
2080
+ * @module @gravito/core/engine
2081
+ */
2082
+
2083
+ /**
2084
+ * Gravito - The High-Performance Web Engine
2085
+ *
2086
+ * @example
2087
+ * ```typescript
2088
+ * import { Gravito } from '@gravito/core/engine'
2089
+ *
2090
+ * const app = new Gravito()
2091
+ *
2092
+ * app.get('/', (c) => c.json({ message: 'Hello, World!' }))
2093
+ * app.get('/users/:id', (c) => {
2094
+ * const id = c.req.param('id')
2095
+ * return c.json({ id })
2096
+ * })
2097
+ *
2098
+ * export default app
2099
+ * ```
2100
+ */
2101
+ declare class Gravito {
2102
+ private router;
2103
+ private contextPool;
2104
+ private errorHandler?;
2105
+ private notFoundHandler?;
2106
+ private staticRoutes;
2107
+ private isPureStaticApp;
2108
+ /**
2109
+ * Create a new Gravito instance
2110
+ *
2111
+ * @param options - Engine configuration options
2112
+ */
2113
+ constructor(options?: EngineOptions);
2114
+ /**
2115
+ * Register a GET route
2116
+ *
2117
+ * @param path - Route path (e.g., '/users/:id')
2118
+ * @param handlers - Handler and optional middleware
2119
+ * @returns This instance for chaining
2120
+ */
2121
+ get(path: string, ...handlers: Handler[]): this;
2122
+ /**
2123
+ * Register a POST route
2124
+ */
2125
+ post(path: string, ...handlers: Handler[]): this;
2126
+ /**
2127
+ * Register a PUT route
2128
+ */
2129
+ put(path: string, ...handlers: Handler[]): this;
2130
+ /**
2131
+ * Register a DELETE route
2132
+ */
2133
+ delete(path: string, ...handlers: Handler[]): this;
2134
+ /**
2135
+ * Register a PATCH route
2136
+ */
2137
+ patch(path: string, ...handlers: Handler[]): this;
2138
+ /**
2139
+ * Register an OPTIONS route
2140
+ */
2141
+ options(path: string, ...handlers: Handler[]): this;
2142
+ /**
2143
+ * Register a HEAD route
2144
+ */
2145
+ head(path: string, ...handlers: Handler[]): this;
2146
+ /**
2147
+ * Register a route for all HTTP methods
2148
+ */
2149
+ all(path: string, ...handlers: Handler[]): this;
2150
+ /**
2151
+ * Register global or path-based middleware
2152
+ *
2153
+ * @example
2154
+ * ```typescript
2155
+ * // Global middleware
2156
+ * app.use(async (c, next) => {
2157
+ * console.log(`${c.req.method} ${c.req.path}`)
2158
+ * await next()
2159
+ * })
2160
+ *
2161
+ * // Path-based middleware
2162
+ * app.use('/api/*', async (c, next) => {
2163
+ * c.header('X-API-Version', '1.0')
2164
+ * await next()
2165
+ * })
2166
+ * ```
2167
+ */
2168
+ use(path: string, ...middleware: Middleware[]): this;
2169
+ use(...middleware: Middleware[]): this;
2170
+ /**
2171
+ * Mount a sub-application at a path prefix
2172
+ *
2173
+ * @example
2174
+ * ```typescript
2175
+ * const api = new Gravito()
2176
+ * api.get('/users', (c) => c.json({ users: [] }))
2177
+ *
2178
+ * const app = new Gravito()
2179
+ * app.route('/api', api)
2180
+ * // Now accessible at /api/users
2181
+ * ```
2182
+ */
2183
+ route(_path: string, _app: Gravito): this;
2184
+ /**
2185
+ * Set custom error handler
2186
+ *
2187
+ * @example
2188
+ * ```typescript
2189
+ * app.onError((err, c) => {
2190
+ * console.error(err)
2191
+ * return c.json({ error: err.message }, 500)
2192
+ * })
2193
+ * ```
2194
+ */
2195
+ onError(handler: ErrorHandler): this;
2196
+ /**
2197
+ * Set custom 404 handler
2198
+ *
2199
+ * @example
2200
+ * ```typescript
2201
+ * app.notFound((c) => {
2202
+ * return c.json({ error: 'Not Found' }, 404)
2203
+ * })
2204
+ * ```
2205
+ */
2206
+ notFound(handler: NotFoundHandler): this;
2207
+ /**
2208
+ * Handle an incoming request
2209
+ *
2210
+ * Optimized for minimal allocations and maximum throughput.
2211
+ * Uses sync/async dual-path strategy inspired by Hono.
2212
+ *
2213
+ * @param request - Incoming Request object
2214
+ * @returns Response object (sync or async)
2215
+ */
2216
+ fetch: (request: Request) => Response | Promise<Response>;
2217
+ /**
2218
+ * Handle routes with middleware (async path)
2219
+ */
2220
+ private handleWithMiddleware;
2221
+ /**
2222
+ * Handle dynamic routes (Radix Tree lookup)
2223
+ */
2224
+ private handleDynamicRoute;
2225
+ /**
2226
+ * Sync error handler (for ultra-fast path)
2227
+ */
2228
+ private handleErrorSync;
2229
+ /**
2230
+ * Sync 404 handler (for ultra-fast path)
2231
+ */
2232
+ private handleNotFoundSync;
2233
+ /**
2234
+ * Collect middleware for a specific path
2235
+ * (Simplified version - assumes we've already checked for pure static)
2236
+ */
2237
+ private collectMiddlewareForPath;
2238
+ /**
2239
+ * Compile routes for optimization
2240
+ * Called once during initialization and when routes change
2241
+ */
2242
+ private compileRoutes;
2243
+ /**
2244
+ * Add a route to the router
2245
+ */
2246
+ private addRoute;
2247
+ /**
2248
+ * Execute middleware chain followed by handler
2249
+ *
2250
+ * Implements the standard middleware pattern:
2251
+ * Each middleware can call next() to continue the chain.
2252
+ */
2253
+ private executeMiddleware;
2254
+ /**
2255
+ * Handle errors (Async version for dynamic/middleware paths)
2256
+ */
2257
+ private handleError;
2258
+ }
2259
+
2260
+ /**
2261
+ * @fileoverview AOT (Ahead-of-Time) Router
2262
+ *
2263
+ * Hybrid routing strategy:
2264
+ * - Static routes: O(1) Map lookup
2265
+ * - Dynamic routes: Optimized Radix Tree
2266
+ *
2267
+ * The key optimization is separating static from dynamic routes at registration time,
2268
+ * not at match time. This eliminates unnecessary tree traversal for static paths.
2269
+ *
2270
+ * @module @gravito/core/engine
2271
+ */
2272
+
2273
+ /**
2274
+ * AOT Router - Optimized for Bun
2275
+ *
2276
+ * Performance characteristics:
2277
+ * - Static routes: O(1) lookup via Map
2278
+ * - Dynamic routes: O(log n) via Radix Tree
2279
+ * - Middleware: O(m) where m = number of matching middleware
2280
+ */
2281
+ declare class AOTRouter {
2282
+ private staticRoutes;
2283
+ private dynamicRouter;
2284
+ private globalMiddleware;
2285
+ private pathMiddleware;
2286
+ /**
2287
+ * Register a route
2288
+ *
2289
+ * Automatically determines if route is static or dynamic.
2290
+ * Static routes are stored in a Map for O(1) lookup.
2291
+ * Dynamic routes use the Radix Tree.
2292
+ *
2293
+ * @param method - HTTP method
2294
+ * @param path - Route path
2295
+ * @param handler - Route handler
2296
+ * @param middleware - Route-specific middleware
2297
+ */
2298
+ add(method: HttpMethod, path: string, handler: Handler, middleware?: Middleware[]): void;
2299
+ /**
2300
+ * Add global middleware
2301
+ *
2302
+ * These run for every request, before route-specific middleware.
2303
+ *
2304
+ * @param middleware - Middleware functions
2305
+ */
2306
+ use(...middleware: Middleware[]): void;
2307
+ /**
2308
+ * Add path-based middleware
2309
+ *
2310
+ * Supports wildcard patterns like '/api/*'
2311
+ *
2312
+ * @param pattern - Path pattern
2313
+ * @param middleware - Middleware functions
2314
+ */
2315
+ usePattern(pattern: string, ...middleware: Middleware[]): void;
2316
+ /**
2317
+ * Match a request to a route
2318
+ *
2319
+ * Returns the handler, params, and all applicable middleware.
2320
+ *
2321
+ * @param method - HTTP method
2322
+ * @param path - Request path
2323
+ * @returns Route match or null if not found
2324
+ */
2325
+ match(method: string, path: string): RouteMatch;
2326
+ /**
2327
+ * Public wrapper for collectMiddleware (used by Gravito for optimization)
2328
+ */
2329
+ collectMiddlewarePublic(path: string, routeMiddleware: Middleware[]): Middleware[];
2330
+ /**
2331
+ * Collect all applicable middleware for a path
2332
+ *
2333
+ * Order: global -> pattern-based -> route-specific
2334
+ *
2335
+ * @param path - Request path
2336
+ * @param routeMiddleware - Route-specific middleware
2337
+ * @returns Combined middleware array
2338
+ */
2339
+ private collectMiddleware;
2340
+ /**
2341
+ * Check if a path is static (no parameters or wildcards)
2342
+ */
2343
+ private isStaticPath;
2344
+ /**
2345
+ * Match a pattern against a path
2346
+ *
2347
+ * Supports:
2348
+ * - Exact match: '/api/users'
2349
+ * - Wildcard suffix: '/api/*'
2350
+ *
2351
+ * @param pattern - Pattern to match
2352
+ * @param path - Path to test
2353
+ * @returns True if pattern matches
2354
+ */
2355
+ private matchPattern;
2356
+ /**
2357
+ * Find the original route key for a matched dynamic route
2358
+ *
2359
+ * This is needed to look up route-specific middleware.
2360
+ * It's a bit of a hack, but avoids storing duplicate data.
2361
+ *
2362
+ * @param method - HTTP method
2363
+ * @param path - Matched path
2364
+ * @returns Route key or null
2365
+ */
2366
+ private findDynamicRouteKey;
2367
+ /**
2368
+ * Get all registered routes (for debugging)
2369
+ */
2370
+ getRoutes(): Array<{
2371
+ method: string;
2372
+ path: string;
2373
+ type: 'static' | 'dynamic';
2374
+ }>;
2375
+ }
2376
+
2377
+ /**
2378
+ * @fileoverview FastContext - Pooled Request Context
2379
+ *
2380
+ * Minimal, high-performance context implementation designed for object pooling.
2381
+ * Lazy parsing strategy: only parse what's actually accessed.
2382
+ *
2383
+ * @module @gravito/core/engine
2384
+ */
2385
+
2386
+ /**
2387
+ * FastContext - Pooled request context
2388
+ *
2389
+ * Designed for minimal memory allocation and maximum reuse.
2390
+ * All response helpers create Response objects directly without intermediate wrappers.
2391
+ */
2392
+ declare class FastContext implements FastContext$1 {
2393
+ private _req;
2394
+ private _headers;
2395
+ /**
2396
+ * Reset context for pooling
2397
+ *
2398
+ * This is called when acquiring from the pool.
2399
+ * Must clear all state from previous request.
2400
+ */
2401
+ reset(request: Request, params?: Record<string, string>): this;
2402
+ get req(): FastRequest;
2403
+ json<T>(data: T, status?: number): Response;
2404
+ text(text: string, status?: number): Response;
2405
+ html(html: string, status?: number): Response;
2406
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
2407
+ body(data: BodyInit | null, status?: number): Response;
2408
+ header(name: string, value: string): void;
2409
+ status(_code: number): void;
2410
+ }
2411
+
2412
+ /**
2413
+ * @fileoverview MinimalContext - Ultra-lightweight Request Context
2414
+ *
2415
+ * Designed for zero-middleware static routes where pool overhead
2416
+ * exceeds the cost of creating a new object.
2417
+ *
2418
+ * Key difference from FastContext:
2419
+ * - No object pooling (direct instantiation is faster for simple cases)
2420
+ * - No Headers object reuse (creates inline)
2421
+ * - Minimal memory footprint
2422
+ *
2423
+ * @module @gravito/core/engine
2424
+ */
2425
+
2426
+ /**
2427
+ * MinimalContext - Optimized for simple, fast responses
2428
+ *
2429
+ * Use when:
2430
+ * - No middleware
2431
+ * - Static routes
2432
+ * - Simple JSON/text responses
2433
+ * - No custom headers needed
2434
+ */
2435
+ declare class MinimalContext implements FastContext$1 {
2436
+ private readonly _req;
2437
+ constructor(request: Request, params: Record<string, string>, path: string);
2438
+ get req(): FastRequest;
2439
+ json<T>(data: T, status?: number): Response;
2440
+ text(text: string, status?: number): Response;
2441
+ html(html: string, status?: number): Response;
2442
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
2443
+ body(data: BodyInit | null, status?: number): Response;
2444
+ header(_name: string, _value: string): void;
2445
+ status(_code: number): void;
2446
+ reset(_request: Request, _params?: Record<string, string>): this;
2447
+ }
2448
+
2449
+ /**
2450
+ * @fileoverview Lightweight Path Utilities
2451
+ *
2452
+ * High-performance path extraction without creating URL objects.
2453
+ * Performance critical - every optimization matters.
2454
+ *
2455
+ * @module @gravito/core/engine
2456
+ */
2457
+ /**
2458
+ * Extract pathname from URL string without creating URL object
2459
+ *
2460
+ * @param url - Full URL string (e.g., "http://localhost:3000/api/users?id=1")
2461
+ * @returns pathname (e.g., "/api/users")
2462
+ *
2463
+ * @example
2464
+ * ```typescript
2465
+ * extractPath("http://localhost:3000/api/users?id=1") // "/api/users"
2466
+ * extractPath("https://example.com/") // "/"
2467
+ * ```
2468
+ */
2469
+ declare function extractPath(url: string): string;
2470
+
2471
+ /**
2472
+ * @fileoverview Generic Object Pool Implementation
2473
+ *
2474
+ * High-performance object pooling to reduce GC pressure.
2475
+ * Implements "fixed pool + overflow fallback" strategy.
2476
+ *
2477
+ * @module @gravito/core/engine
2478
+ */
2479
+ /**
2480
+ * Generic object pool with fixed size and overflow handling
2481
+ *
2482
+ * @typeParam T - Type of objects to pool
2483
+ *
2484
+ * @example
2485
+ * ```typescript
2486
+ * const pool = new ObjectPool(
2487
+ * () => new MyObject(),
2488
+ * (obj) => obj.reset(),
2489
+ * 256
2490
+ * )
2491
+ *
2492
+ * const obj = pool.acquire()
2493
+ * try {
2494
+ * // Use object
2495
+ * } finally {
2496
+ * pool.release(obj)
2497
+ * }
2498
+ * ```
2499
+ */
2500
+ declare class ObjectPool<T> {
2501
+ private pool;
2502
+ private readonly factory;
2503
+ private readonly reset;
2504
+ private readonly maxSize;
2505
+ /**
2506
+ * Create a new object pool
2507
+ *
2508
+ * @param factory - Function to create new objects
2509
+ * @param reset - Function to reset objects before reuse
2510
+ * @param maxSize - Maximum pool size (default: 256)
2511
+ */
2512
+ constructor(factory: () => T, reset: (obj: T) => void, maxSize?: number);
2513
+ /**
2514
+ * Acquire an object from the pool
2515
+ *
2516
+ * If the pool is empty, creates a new object (overflow strategy).
2517
+ * This ensures the pool never blocks under high load.
2518
+ *
2519
+ * @returns Object from pool or newly created
2520
+ */
2521
+ acquire(): T;
2522
+ /**
2523
+ * Release an object back to the pool
2524
+ *
2525
+ * If the pool is full, the object is discarded (will be GC'd).
2526
+ * This prevents unbounded memory growth.
2527
+ *
2528
+ * @param obj - Object to release
2529
+ */
2530
+ release(obj: T): void;
2531
+ /**
2532
+ * Clear all objects from the pool
2533
+ *
2534
+ * Useful for testing or when you need to force a clean slate.
2535
+ */
2536
+ clear(): void;
2537
+ /**
2538
+ * Get current pool size
2539
+ */
2540
+ get size(): number;
2541
+ /**
2542
+ * Get maximum pool size
2543
+ */
2544
+ get capacity(): number;
2545
+ /**
2546
+ * Pre-warm the pool by creating objects in advance
2547
+ *
2548
+ * This can reduce latency for the first N requests.
2549
+ *
2550
+ * @param count - Number of objects to pre-create
2551
+ */
2552
+ prewarm(count: number): void;
2553
+ }
2554
+
2555
+ /**
2556
+ * @fileoverview Gravito Core Engine - Public API
2557
+ *
2558
+ * The High-Performance Web Engine for Bun
2559
+ *
2560
+ * @module @gravito/core/engine
2561
+ * @packageDocumentation
2562
+ *
2563
+ * @example
2564
+ * ```typescript
2565
+ * import { Gravito } from '@gravito/core/engine'
2566
+ *
2567
+ * const app = new Gravito()
2568
+ *
2569
+ * app.get('/', (c) => c.json({ message: 'Hello, World!' }))
2570
+ *
2571
+ * export default app
2572
+ * ```
2573
+ */
2574
+
2575
+ type index_AOTRouter = AOTRouter;
2576
+ declare const index_AOTRouter: typeof AOTRouter;
2577
+ type index_EngineOptions = EngineOptions;
2578
+ type index_ErrorHandler = ErrorHandler;
2579
+ type index_FastRequest = FastRequest;
2580
+ type index_Gravito = Gravito;
2581
+ declare const index_Gravito: typeof Gravito;
2582
+ type index_Handler = Handler;
2583
+ type index_Middleware = Middleware;
2584
+ type index_MinimalContext = MinimalContext;
2585
+ declare const index_MinimalContext: typeof MinimalContext;
2586
+ type index_NotFoundHandler = NotFoundHandler;
2587
+ type index_ObjectPool<T> = ObjectPool<T>;
2588
+ declare const index_ObjectPool: typeof ObjectPool;
2589
+ type index_RouteMatch = RouteMatch;
2590
+ declare const index_extractPath: typeof extractPath;
2591
+ declare namespace index {
2592
+ export { index_AOTRouter as AOTRouter, type index_EngineOptions as EngineOptions, type index_ErrorHandler as ErrorHandler, type FastContext$1 as FastContext, FastContext as FastContextImpl, type index_FastRequest as FastRequest, index_Gravito as Gravito, type index_Handler as Handler, type index_Middleware as Middleware, index_MinimalContext as MinimalContext, type index_NotFoundHandler as NotFoundHandler, index_ObjectPool as ObjectPool, type index_RouteMatch as RouteMatch, index_extractPath as extractPath };
2593
+ }
2594
+
2004
2595
  /**
2005
2596
  * @gravito/core
2006
2597
  *
@@ -2029,4 +2620,4 @@ declare const VERSION: string;
2029
2620
  */
2030
2621
  declare function defineConfig(config: GravitoConfig): GravitoConfig;
2031
2622
 
2032
- export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };
2623
+ export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, RouteGroup, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, index as engine, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };