@gravito/core 1.0.0-beta.6 → 1.1.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/README.md +2 -0
- package/dist/compat.d.cts +1 -0
- package/dist/compat.d.ts +1 -0
- package/dist/engine/index.cjs +1173 -0
- package/dist/engine/index.d.cts +612 -0
- package/dist/engine/index.d.ts +612 -0
- package/dist/engine/index.js +1141 -0
- package/dist/index.cjs +953 -8
- package/dist/index.d.cts +632 -1
- package/dist/index.d.ts +632 -1
- package/dist/index.js +957 -8
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -2000,6 +2000,637 @@ declare const getRuntimeAdapter: () => RuntimeAdapter;
|
|
|
2000
2000
|
declare const getPasswordAdapter: () => RuntimePasswordAdapter;
|
|
2001
2001
|
declare const createSqliteDatabase: (path: string) => Promise<RuntimeSqliteDatabase>;
|
|
2002
2002
|
|
|
2003
|
+
/**
|
|
2004
|
+
* @fileoverview Gravito Core Engine Types
|
|
2005
|
+
*
|
|
2006
|
+
* Minimal, high-performance types for the standalone engine.
|
|
2007
|
+
* These are intentionally simpler than the full framework types.
|
|
2008
|
+
*
|
|
2009
|
+
* @module @gravito/core/engine
|
|
2010
|
+
*/
|
|
2011
|
+
|
|
2012
|
+
/**
|
|
2013
|
+
* FastContext - The pooled request context
|
|
2014
|
+
*/
|
|
2015
|
+
interface FastContext$1 {
|
|
2016
|
+
/** Request accessor */
|
|
2017
|
+
readonly req: FastRequest;
|
|
2018
|
+
/** Response helpers */
|
|
2019
|
+
json<T>(data: T, status?: number): Response;
|
|
2020
|
+
text(text: string, status?: number): Response;
|
|
2021
|
+
html(html: string, status?: number): Response;
|
|
2022
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
2023
|
+
body(data: BodyInit | null, status?: number): Response;
|
|
2024
|
+
/** Header management */
|
|
2025
|
+
header(name: string, value: string): void;
|
|
2026
|
+
status(code: number): void;
|
|
2027
|
+
/** Internal reset for pooling */
|
|
2028
|
+
reset(request: Request, params?: Record<string, string>): this;
|
|
2029
|
+
}
|
|
2030
|
+
/**
|
|
2031
|
+
* FastRequest - Minimal request interface
|
|
2032
|
+
*/
|
|
2033
|
+
interface FastRequest {
|
|
2034
|
+
/** Full URL */
|
|
2035
|
+
readonly url: string;
|
|
2036
|
+
/** HTTP method */
|
|
2037
|
+
readonly method: string;
|
|
2038
|
+
/** Path without query */
|
|
2039
|
+
readonly path: string;
|
|
2040
|
+
/** Get route parameter */
|
|
2041
|
+
param(name: string): string | undefined;
|
|
2042
|
+
/** Get all route parameters */
|
|
2043
|
+
params(): Record<string, string>;
|
|
2044
|
+
/** Get query parameter */
|
|
2045
|
+
query(name: string): string | undefined;
|
|
2046
|
+
/** Get all query parameters */
|
|
2047
|
+
queries(): Record<string, string | string[]>;
|
|
2048
|
+
/** Get header */
|
|
2049
|
+
header(name: string): string | undefined;
|
|
2050
|
+
/** Get all headers */
|
|
2051
|
+
headers(): Record<string, string>;
|
|
2052
|
+
/** Parse JSON body */
|
|
2053
|
+
json<T = unknown>(): Promise<T>;
|
|
2054
|
+
/** Parse text body */
|
|
2055
|
+
text(): Promise<string>;
|
|
2056
|
+
/** Parse form data */
|
|
2057
|
+
formData(): Promise<FormData>;
|
|
2058
|
+
/** Raw Request object */
|
|
2059
|
+
readonly raw: Request;
|
|
2060
|
+
}
|
|
2061
|
+
/**
|
|
2062
|
+
* Route handler function
|
|
2063
|
+
*/
|
|
2064
|
+
type Handler = (ctx: FastContext$1) => Response | Promise<Response>;
|
|
2065
|
+
/**
|
|
2066
|
+
* Middleware function
|
|
2067
|
+
*/
|
|
2068
|
+
type Middleware = (ctx: FastContext$1, next: () => Promise<void>) => void | Promise<void>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Error handler function
|
|
2071
|
+
*/
|
|
2072
|
+
type ErrorHandler = (error: Error, ctx: FastContext$1) => Response | Promise<Response>;
|
|
2073
|
+
/**
|
|
2074
|
+
* Not found handler function
|
|
2075
|
+
*/
|
|
2076
|
+
type NotFoundHandler = (ctx: FastContext$1) => Response | Promise<Response>;
|
|
2077
|
+
/**
|
|
2078
|
+
* Route match result from router
|
|
2079
|
+
*/
|
|
2080
|
+
interface RouteMatch {
|
|
2081
|
+
/** Matched handler */
|
|
2082
|
+
handler: Handler | null;
|
|
2083
|
+
/** Extracted route parameters */
|
|
2084
|
+
params: Record<string, string>;
|
|
2085
|
+
/** Middleware to execute */
|
|
2086
|
+
middleware: Middleware[];
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Engine configuration options
|
|
2090
|
+
*/
|
|
2091
|
+
interface EngineOptions {
|
|
2092
|
+
/** Context pool size (default: 256) */
|
|
2093
|
+
poolSize?: number;
|
|
2094
|
+
/** Enable route compilation optimization (default: true) */
|
|
2095
|
+
enableAOT?: boolean;
|
|
2096
|
+
/** Custom error handler */
|
|
2097
|
+
onError?: ErrorHandler;
|
|
2098
|
+
/** Custom 404 handler */
|
|
2099
|
+
onNotFound?: NotFoundHandler;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
/**
|
|
2103
|
+
* @fileoverview Gravito - High-Performance Web Engine for Bun
|
|
2104
|
+
*
|
|
2105
|
+
* The standalone engine optimized exclusively for Bun runtime.
|
|
2106
|
+
* 99% API-compatible with Hono, but faster through Bun-specific optimizations.
|
|
2107
|
+
*
|
|
2108
|
+
* Key optimizations:
|
|
2109
|
+
* 1. Object pooling for zero-allocation request handling
|
|
2110
|
+
* 2. AOT router with O(1) static route lookup
|
|
2111
|
+
* 3. Lazy parsing - only parse what's accessed
|
|
2112
|
+
* 4. Direct Bun.serve integration without wrapper layers
|
|
2113
|
+
*
|
|
2114
|
+
* @module @gravito/core/engine
|
|
2115
|
+
*/
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Gravito - The High-Performance Web Engine
|
|
2119
|
+
*
|
|
2120
|
+
* @example
|
|
2121
|
+
* ```typescript
|
|
2122
|
+
* import { Gravito } from '@gravito/core/engine'
|
|
2123
|
+
*
|
|
2124
|
+
* const app = new Gravito()
|
|
2125
|
+
*
|
|
2126
|
+
* app.get('/', (c) => c.json({ message: 'Hello, World!' }))
|
|
2127
|
+
* app.get('/users/:id', (c) => {
|
|
2128
|
+
* const id = c.req.param('id')
|
|
2129
|
+
* return c.json({ id })
|
|
2130
|
+
* })
|
|
2131
|
+
*
|
|
2132
|
+
* export default app
|
|
2133
|
+
* ```
|
|
2134
|
+
*/
|
|
2135
|
+
declare class Gravito {
|
|
2136
|
+
private router;
|
|
2137
|
+
private contextPool;
|
|
2138
|
+
private errorHandler?;
|
|
2139
|
+
private notFoundHandler?;
|
|
2140
|
+
private staticRoutes;
|
|
2141
|
+
private isPureStaticApp;
|
|
2142
|
+
/**
|
|
2143
|
+
* Create a new Gravito instance
|
|
2144
|
+
*
|
|
2145
|
+
* @param options - Engine configuration options
|
|
2146
|
+
*/
|
|
2147
|
+
constructor(options?: EngineOptions);
|
|
2148
|
+
/**
|
|
2149
|
+
* Register a GET route
|
|
2150
|
+
*
|
|
2151
|
+
* @param path - Route path (e.g., '/users/:id')
|
|
2152
|
+
* @param handlers - Handler and optional middleware
|
|
2153
|
+
* @returns This instance for chaining
|
|
2154
|
+
*/
|
|
2155
|
+
get(path: string, ...handlers: Handler[]): this;
|
|
2156
|
+
/**
|
|
2157
|
+
* Register a POST route
|
|
2158
|
+
*/
|
|
2159
|
+
post(path: string, ...handlers: Handler[]): this;
|
|
2160
|
+
/**
|
|
2161
|
+
* Register a PUT route
|
|
2162
|
+
*/
|
|
2163
|
+
put(path: string, ...handlers: Handler[]): this;
|
|
2164
|
+
/**
|
|
2165
|
+
* Register a DELETE route
|
|
2166
|
+
*/
|
|
2167
|
+
delete(path: string, ...handlers: Handler[]): this;
|
|
2168
|
+
/**
|
|
2169
|
+
* Register a PATCH route
|
|
2170
|
+
*/
|
|
2171
|
+
patch(path: string, ...handlers: Handler[]): this;
|
|
2172
|
+
/**
|
|
2173
|
+
* Register an OPTIONS route
|
|
2174
|
+
*/
|
|
2175
|
+
options(path: string, ...handlers: Handler[]): this;
|
|
2176
|
+
/**
|
|
2177
|
+
* Register a HEAD route
|
|
2178
|
+
*/
|
|
2179
|
+
head(path: string, ...handlers: Handler[]): this;
|
|
2180
|
+
/**
|
|
2181
|
+
* Register a route for all HTTP methods
|
|
2182
|
+
*/
|
|
2183
|
+
all(path: string, ...handlers: Handler[]): this;
|
|
2184
|
+
/**
|
|
2185
|
+
* Register global or path-based middleware
|
|
2186
|
+
*
|
|
2187
|
+
* @example
|
|
2188
|
+
* ```typescript
|
|
2189
|
+
* // Global middleware
|
|
2190
|
+
* app.use(async (c, next) => {
|
|
2191
|
+
* console.log(`${c.req.method} ${c.req.path}`)
|
|
2192
|
+
* await next()
|
|
2193
|
+
* })
|
|
2194
|
+
*
|
|
2195
|
+
* // Path-based middleware
|
|
2196
|
+
* app.use('/api/*', async (c, next) => {
|
|
2197
|
+
* c.header('X-API-Version', '1.0')
|
|
2198
|
+
* await next()
|
|
2199
|
+
* })
|
|
2200
|
+
* ```
|
|
2201
|
+
*/
|
|
2202
|
+
use(path: string, ...middleware: Middleware[]): this;
|
|
2203
|
+
use(...middleware: Middleware[]): this;
|
|
2204
|
+
/**
|
|
2205
|
+
* Mount a sub-application at a path prefix
|
|
2206
|
+
*
|
|
2207
|
+
* @example
|
|
2208
|
+
* ```typescript
|
|
2209
|
+
* const api = new Gravito()
|
|
2210
|
+
* api.get('/users', (c) => c.json({ users: [] }))
|
|
2211
|
+
*
|
|
2212
|
+
* const app = new Gravito()
|
|
2213
|
+
* app.route('/api', api)
|
|
2214
|
+
* // Now accessible at /api/users
|
|
2215
|
+
* ```
|
|
2216
|
+
*/
|
|
2217
|
+
route(path: string, app: Gravito): this;
|
|
2218
|
+
/**
|
|
2219
|
+
* Set custom error handler
|
|
2220
|
+
*
|
|
2221
|
+
* @example
|
|
2222
|
+
* ```typescript
|
|
2223
|
+
* app.onError((err, c) => {
|
|
2224
|
+
* console.error(err)
|
|
2225
|
+
* return c.json({ error: err.message }, 500)
|
|
2226
|
+
* })
|
|
2227
|
+
* ```
|
|
2228
|
+
*/
|
|
2229
|
+
onError(handler: ErrorHandler): this;
|
|
2230
|
+
/**
|
|
2231
|
+
* Set custom 404 handler
|
|
2232
|
+
*
|
|
2233
|
+
* @example
|
|
2234
|
+
* ```typescript
|
|
2235
|
+
* app.notFound((c) => {
|
|
2236
|
+
* return c.json({ error: 'Not Found' }, 404)
|
|
2237
|
+
* })
|
|
2238
|
+
* ```
|
|
2239
|
+
*/
|
|
2240
|
+
notFound(handler: NotFoundHandler): this;
|
|
2241
|
+
/**
|
|
2242
|
+
* Handle an incoming request
|
|
2243
|
+
*
|
|
2244
|
+
* Optimized for minimal allocations and maximum throughput.
|
|
2245
|
+
* Uses sync/async dual-path strategy inspired by Hono.
|
|
2246
|
+
*
|
|
2247
|
+
* @param request - Incoming Request object
|
|
2248
|
+
* @returns Response object (sync or async)
|
|
2249
|
+
*/
|
|
2250
|
+
fetch: (request: Request) => Response | Promise<Response>;
|
|
2251
|
+
/**
|
|
2252
|
+
* Handle routes with middleware (async path)
|
|
2253
|
+
*/
|
|
2254
|
+
private handleWithMiddleware;
|
|
2255
|
+
/**
|
|
2256
|
+
* Handle dynamic routes (Radix Tree lookup)
|
|
2257
|
+
*/
|
|
2258
|
+
private handleDynamicRoute;
|
|
2259
|
+
/**
|
|
2260
|
+
* Sync error handler (for ultra-fast path)
|
|
2261
|
+
*/
|
|
2262
|
+
private handleErrorSync;
|
|
2263
|
+
/**
|
|
2264
|
+
* Sync 404 handler (for ultra-fast path)
|
|
2265
|
+
*/
|
|
2266
|
+
private handleNotFoundSync;
|
|
2267
|
+
/**
|
|
2268
|
+
* Collect middleware for a specific path
|
|
2269
|
+
* (Simplified version - assumes we've already checked for pure static)
|
|
2270
|
+
*/
|
|
2271
|
+
private collectMiddlewareForPath;
|
|
2272
|
+
/**
|
|
2273
|
+
* Compile routes for optimization
|
|
2274
|
+
* Called once during initialization and when routes change
|
|
2275
|
+
*/
|
|
2276
|
+
private compileRoutes;
|
|
2277
|
+
/**
|
|
2278
|
+
* Add a route to the router
|
|
2279
|
+
*/
|
|
2280
|
+
private addRoute;
|
|
2281
|
+
/**
|
|
2282
|
+
* Execute middleware chain followed by handler
|
|
2283
|
+
*
|
|
2284
|
+
* Implements the standard middleware pattern:
|
|
2285
|
+
* Each middleware can call next() to continue the chain.
|
|
2286
|
+
*/
|
|
2287
|
+
private executeMiddleware;
|
|
2288
|
+
/**
|
|
2289
|
+
* Handle 404 Not Found (Async version for dynamic/middleware paths)
|
|
2290
|
+
*/
|
|
2291
|
+
private handleNotFound;
|
|
2292
|
+
/**
|
|
2293
|
+
* Handle errors (Async version for dynamic/middleware paths)
|
|
2294
|
+
*/
|
|
2295
|
+
private handleError;
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
/**
|
|
2299
|
+
* @fileoverview AOT (Ahead-of-Time) Router
|
|
2300
|
+
*
|
|
2301
|
+
* Hybrid routing strategy:
|
|
2302
|
+
* - Static routes: O(1) Map lookup
|
|
2303
|
+
* - Dynamic routes: Optimized Radix Tree
|
|
2304
|
+
*
|
|
2305
|
+
* The key optimization is separating static from dynamic routes at registration time,
|
|
2306
|
+
* not at match time. This eliminates unnecessary tree traversal for static paths.
|
|
2307
|
+
*
|
|
2308
|
+
* @module @gravito/core/engine
|
|
2309
|
+
*/
|
|
2310
|
+
|
|
2311
|
+
/**
|
|
2312
|
+
* AOT Router - Optimized for Bun
|
|
2313
|
+
*
|
|
2314
|
+
* Performance characteristics:
|
|
2315
|
+
* - Static routes: O(1) lookup via Map
|
|
2316
|
+
* - Dynamic routes: O(log n) via Radix Tree
|
|
2317
|
+
* - Middleware: O(m) where m = number of matching middleware
|
|
2318
|
+
*/
|
|
2319
|
+
declare class AOTRouter {
|
|
2320
|
+
private staticRoutes;
|
|
2321
|
+
private dynamicRouter;
|
|
2322
|
+
private globalMiddleware;
|
|
2323
|
+
private pathMiddleware;
|
|
2324
|
+
/**
|
|
2325
|
+
* Register a route
|
|
2326
|
+
*
|
|
2327
|
+
* Automatically determines if route is static or dynamic.
|
|
2328
|
+
* Static routes are stored in a Map for O(1) lookup.
|
|
2329
|
+
* Dynamic routes use the Radix Tree.
|
|
2330
|
+
*
|
|
2331
|
+
* @param method - HTTP method
|
|
2332
|
+
* @param path - Route path
|
|
2333
|
+
* @param handler - Route handler
|
|
2334
|
+
* @param middleware - Route-specific middleware
|
|
2335
|
+
*/
|
|
2336
|
+
add(method: HttpMethod, path: string, handler: Handler, middleware?: Middleware[]): void;
|
|
2337
|
+
/**
|
|
2338
|
+
* Add global middleware
|
|
2339
|
+
*
|
|
2340
|
+
* These run for every request, before route-specific middleware.
|
|
2341
|
+
*
|
|
2342
|
+
* @param middleware - Middleware functions
|
|
2343
|
+
*/
|
|
2344
|
+
use(...middleware: Middleware[]): void;
|
|
2345
|
+
/**
|
|
2346
|
+
* Add path-based middleware
|
|
2347
|
+
*
|
|
2348
|
+
* Supports wildcard patterns like '/api/*'
|
|
2349
|
+
*
|
|
2350
|
+
* @param pattern - Path pattern
|
|
2351
|
+
* @param middleware - Middleware functions
|
|
2352
|
+
*/
|
|
2353
|
+
usePattern(pattern: string, ...middleware: Middleware[]): void;
|
|
2354
|
+
/**
|
|
2355
|
+
* Match a request to a route
|
|
2356
|
+
*
|
|
2357
|
+
* Returns the handler, params, and all applicable middleware.
|
|
2358
|
+
*
|
|
2359
|
+
* @param method - HTTP method
|
|
2360
|
+
* @param path - Request path
|
|
2361
|
+
* @returns Route match or null if not found
|
|
2362
|
+
*/
|
|
2363
|
+
match(method: string, path: string): RouteMatch;
|
|
2364
|
+
/**
|
|
2365
|
+
* Public wrapper for collectMiddleware (used by Gravito for optimization)
|
|
2366
|
+
*/
|
|
2367
|
+
collectMiddlewarePublic(path: string, routeMiddleware: Middleware[]): Middleware[];
|
|
2368
|
+
/**
|
|
2369
|
+
* Collect all applicable middleware for a path
|
|
2370
|
+
*
|
|
2371
|
+
* Order: global -> pattern-based -> route-specific
|
|
2372
|
+
*
|
|
2373
|
+
* @param path - Request path
|
|
2374
|
+
* @param routeMiddleware - Route-specific middleware
|
|
2375
|
+
* @returns Combined middleware array
|
|
2376
|
+
*/
|
|
2377
|
+
private collectMiddleware;
|
|
2378
|
+
/**
|
|
2379
|
+
* Check if a path is static (no parameters or wildcards)
|
|
2380
|
+
*/
|
|
2381
|
+
private isStaticPath;
|
|
2382
|
+
/**
|
|
2383
|
+
* Match a pattern against a path
|
|
2384
|
+
*
|
|
2385
|
+
* Supports:
|
|
2386
|
+
* - Exact match: '/api/users'
|
|
2387
|
+
* - Wildcard suffix: '/api/*'
|
|
2388
|
+
*
|
|
2389
|
+
* @param pattern - Pattern to match
|
|
2390
|
+
* @param path - Path to test
|
|
2391
|
+
* @returns True if pattern matches
|
|
2392
|
+
*/
|
|
2393
|
+
private matchPattern;
|
|
2394
|
+
/**
|
|
2395
|
+
* Find the original route key for a matched dynamic route
|
|
2396
|
+
*
|
|
2397
|
+
* This is needed to look up route-specific middleware.
|
|
2398
|
+
* It's a bit of a hack, but avoids storing duplicate data.
|
|
2399
|
+
*
|
|
2400
|
+
* @param method - HTTP method
|
|
2401
|
+
* @param path - Matched path
|
|
2402
|
+
* @returns Route key or null
|
|
2403
|
+
*/
|
|
2404
|
+
private findDynamicRouteKey;
|
|
2405
|
+
/**
|
|
2406
|
+
* Get all registered routes (for debugging)
|
|
2407
|
+
*/
|
|
2408
|
+
getRoutes(): Array<{
|
|
2409
|
+
method: string;
|
|
2410
|
+
path: string;
|
|
2411
|
+
type: 'static' | 'dynamic';
|
|
2412
|
+
}>;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
/**
|
|
2416
|
+
* @fileoverview FastContext - Pooled Request Context
|
|
2417
|
+
*
|
|
2418
|
+
* Minimal, high-performance context implementation designed for object pooling.
|
|
2419
|
+
* Lazy parsing strategy: only parse what's actually accessed.
|
|
2420
|
+
*
|
|
2421
|
+
* @module @gravito/core/engine
|
|
2422
|
+
*/
|
|
2423
|
+
|
|
2424
|
+
/**
|
|
2425
|
+
* FastContext - Pooled request context
|
|
2426
|
+
*
|
|
2427
|
+
* Designed for minimal memory allocation and maximum reuse.
|
|
2428
|
+
* All response helpers create Response objects directly without intermediate wrappers.
|
|
2429
|
+
*/
|
|
2430
|
+
declare class FastContext implements FastContext$1 {
|
|
2431
|
+
private _req;
|
|
2432
|
+
private _statusCode;
|
|
2433
|
+
private _headers;
|
|
2434
|
+
/**
|
|
2435
|
+
* Reset context for pooling
|
|
2436
|
+
*
|
|
2437
|
+
* This is called when acquiring from the pool.
|
|
2438
|
+
* Must clear all state from previous request.
|
|
2439
|
+
*/
|
|
2440
|
+
reset(request: Request, params?: Record<string, string>): this;
|
|
2441
|
+
get req(): FastRequest;
|
|
2442
|
+
json<T>(data: T, status?: number): Response;
|
|
2443
|
+
text(text: string, status?: number): Response;
|
|
2444
|
+
html(html: string, status?: number): Response;
|
|
2445
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
2446
|
+
body(data: BodyInit | null, status?: number): Response;
|
|
2447
|
+
header(name: string, value: string): void;
|
|
2448
|
+
status(code: number): void;
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
/**
|
|
2452
|
+
* @fileoverview MinimalContext - Ultra-lightweight Request Context
|
|
2453
|
+
*
|
|
2454
|
+
* Designed for zero-middleware static routes where pool overhead
|
|
2455
|
+
* exceeds the cost of creating a new object.
|
|
2456
|
+
*
|
|
2457
|
+
* Key difference from FastContext:
|
|
2458
|
+
* - No object pooling (direct instantiation is faster for simple cases)
|
|
2459
|
+
* - No Headers object reuse (creates inline)
|
|
2460
|
+
* - Minimal memory footprint
|
|
2461
|
+
*
|
|
2462
|
+
* @module @gravito/core/engine
|
|
2463
|
+
*/
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* MinimalContext - Optimized for simple, fast responses
|
|
2467
|
+
*
|
|
2468
|
+
* Use when:
|
|
2469
|
+
* - No middleware
|
|
2470
|
+
* - Static routes
|
|
2471
|
+
* - Simple JSON/text responses
|
|
2472
|
+
* - No custom headers needed
|
|
2473
|
+
*/
|
|
2474
|
+
declare class MinimalContext implements FastContext$1 {
|
|
2475
|
+
private readonly _req;
|
|
2476
|
+
constructor(request: Request, params: Record<string, string>, path: string);
|
|
2477
|
+
get req(): FastRequest;
|
|
2478
|
+
json<T>(data: T, status?: number): Response;
|
|
2479
|
+
text(text: string, status?: number): Response;
|
|
2480
|
+
html(html: string, status?: number): Response;
|
|
2481
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
2482
|
+
body(data: BodyInit | null, status?: number): Response;
|
|
2483
|
+
header(_name: string, _value: string): void;
|
|
2484
|
+
status(_code: number): void;
|
|
2485
|
+
reset(_request: Request, _params?: Record<string, string>): this;
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
/**
|
|
2489
|
+
* @fileoverview Lightweight Path Utilities
|
|
2490
|
+
*
|
|
2491
|
+
* High-performance path extraction without creating URL objects.
|
|
2492
|
+
* Performance critical - every optimization matters.
|
|
2493
|
+
*
|
|
2494
|
+
* @module @gravito/core/engine
|
|
2495
|
+
*/
|
|
2496
|
+
/**
|
|
2497
|
+
* Extract pathname from URL string without creating URL object
|
|
2498
|
+
*
|
|
2499
|
+
* @param url - Full URL string (e.g., "http://localhost:3000/api/users?id=1")
|
|
2500
|
+
* @returns pathname (e.g., "/api/users")
|
|
2501
|
+
*
|
|
2502
|
+
* @example
|
|
2503
|
+
* ```typescript
|
|
2504
|
+
* extractPath("http://localhost:3000/api/users?id=1") // "/api/users"
|
|
2505
|
+
* extractPath("https://example.com/") // "/"
|
|
2506
|
+
* ```
|
|
2507
|
+
*/
|
|
2508
|
+
declare function extractPath(url: string): string;
|
|
2509
|
+
|
|
2510
|
+
/**
|
|
2511
|
+
* @fileoverview Generic Object Pool Implementation
|
|
2512
|
+
*
|
|
2513
|
+
* High-performance object pooling to reduce GC pressure.
|
|
2514
|
+
* Implements "fixed pool + overflow fallback" strategy.
|
|
2515
|
+
*
|
|
2516
|
+
* @module @gravito/core/engine
|
|
2517
|
+
*/
|
|
2518
|
+
/**
|
|
2519
|
+
* Generic object pool with fixed size and overflow handling
|
|
2520
|
+
*
|
|
2521
|
+
* @typeParam T - Type of objects to pool
|
|
2522
|
+
*
|
|
2523
|
+
* @example
|
|
2524
|
+
* ```typescript
|
|
2525
|
+
* const pool = new ObjectPool(
|
|
2526
|
+
* () => new MyObject(),
|
|
2527
|
+
* (obj) => obj.reset(),
|
|
2528
|
+
* 256
|
|
2529
|
+
* )
|
|
2530
|
+
*
|
|
2531
|
+
* const obj = pool.acquire()
|
|
2532
|
+
* try {
|
|
2533
|
+
* // Use object
|
|
2534
|
+
* } finally {
|
|
2535
|
+
* pool.release(obj)
|
|
2536
|
+
* }
|
|
2537
|
+
* ```
|
|
2538
|
+
*/
|
|
2539
|
+
declare class ObjectPool<T> {
|
|
2540
|
+
private pool;
|
|
2541
|
+
private readonly factory;
|
|
2542
|
+
private readonly reset;
|
|
2543
|
+
private readonly maxSize;
|
|
2544
|
+
/**
|
|
2545
|
+
* Create a new object pool
|
|
2546
|
+
*
|
|
2547
|
+
* @param factory - Function to create new objects
|
|
2548
|
+
* @param reset - Function to reset objects before reuse
|
|
2549
|
+
* @param maxSize - Maximum pool size (default: 256)
|
|
2550
|
+
*/
|
|
2551
|
+
constructor(factory: () => T, reset: (obj: T) => void, maxSize?: number);
|
|
2552
|
+
/**
|
|
2553
|
+
* Acquire an object from the pool
|
|
2554
|
+
*
|
|
2555
|
+
* If the pool is empty, creates a new object (overflow strategy).
|
|
2556
|
+
* This ensures the pool never blocks under high load.
|
|
2557
|
+
*
|
|
2558
|
+
* @returns Object from pool or newly created
|
|
2559
|
+
*/
|
|
2560
|
+
acquire(): T;
|
|
2561
|
+
/**
|
|
2562
|
+
* Release an object back to the pool
|
|
2563
|
+
*
|
|
2564
|
+
* If the pool is full, the object is discarded (will be GC'd).
|
|
2565
|
+
* This prevents unbounded memory growth.
|
|
2566
|
+
*
|
|
2567
|
+
* @param obj - Object to release
|
|
2568
|
+
*/
|
|
2569
|
+
release(obj: T): void;
|
|
2570
|
+
/**
|
|
2571
|
+
* Clear all objects from the pool
|
|
2572
|
+
*
|
|
2573
|
+
* Useful for testing or when you need to force a clean slate.
|
|
2574
|
+
*/
|
|
2575
|
+
clear(): void;
|
|
2576
|
+
/**
|
|
2577
|
+
* Get current pool size
|
|
2578
|
+
*/
|
|
2579
|
+
get size(): number;
|
|
2580
|
+
/**
|
|
2581
|
+
* Get maximum pool size
|
|
2582
|
+
*/
|
|
2583
|
+
get capacity(): number;
|
|
2584
|
+
/**
|
|
2585
|
+
* Pre-warm the pool by creating objects in advance
|
|
2586
|
+
*
|
|
2587
|
+
* This can reduce latency for the first N requests.
|
|
2588
|
+
*
|
|
2589
|
+
* @param count - Number of objects to pre-create
|
|
2590
|
+
*/
|
|
2591
|
+
prewarm(count: number): void;
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
/**
|
|
2595
|
+
* @fileoverview Gravito Core Engine - Public API
|
|
2596
|
+
*
|
|
2597
|
+
* The High-Performance Web Engine for Bun
|
|
2598
|
+
*
|
|
2599
|
+
* @module @gravito/core/engine
|
|
2600
|
+
* @packageDocumentation
|
|
2601
|
+
*
|
|
2602
|
+
* @example
|
|
2603
|
+
* ```typescript
|
|
2604
|
+
* import { Gravito } from '@gravito/core/engine'
|
|
2605
|
+
*
|
|
2606
|
+
* const app = new Gravito()
|
|
2607
|
+
*
|
|
2608
|
+
* app.get('/', (c) => c.json({ message: 'Hello, World!' }))
|
|
2609
|
+
*
|
|
2610
|
+
* export default app
|
|
2611
|
+
* ```
|
|
2612
|
+
*/
|
|
2613
|
+
|
|
2614
|
+
type index_AOTRouter = AOTRouter;
|
|
2615
|
+
declare const index_AOTRouter: typeof AOTRouter;
|
|
2616
|
+
type index_EngineOptions = EngineOptions;
|
|
2617
|
+
type index_ErrorHandler = ErrorHandler;
|
|
2618
|
+
type index_FastRequest = FastRequest;
|
|
2619
|
+
type index_Gravito = Gravito;
|
|
2620
|
+
declare const index_Gravito: typeof Gravito;
|
|
2621
|
+
type index_Handler = Handler;
|
|
2622
|
+
type index_Middleware = Middleware;
|
|
2623
|
+
type index_MinimalContext = MinimalContext;
|
|
2624
|
+
declare const index_MinimalContext: typeof MinimalContext;
|
|
2625
|
+
type index_NotFoundHandler = NotFoundHandler;
|
|
2626
|
+
type index_ObjectPool<T> = ObjectPool<T>;
|
|
2627
|
+
declare const index_ObjectPool: typeof ObjectPool;
|
|
2628
|
+
type index_RouteMatch = RouteMatch;
|
|
2629
|
+
declare const index_extractPath: typeof extractPath;
|
|
2630
|
+
declare namespace index {
|
|
2631
|
+
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 };
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2003
2634
|
/**
|
|
2004
2635
|
* @gravito/core
|
|
2005
2636
|
*
|
|
@@ -2028,4 +2659,4 @@ declare const VERSION: string;
|
|
|
2028
2659
|
*/
|
|
2029
2660
|
declare function defineConfig(config: GravitoConfig): GravitoConfig;
|
|
2030
2661
|
|
|
2031
|
-
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 };
|
|
2662
|
+
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, 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 };
|