@gravito/echo 3.0.0 → 3.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.
Files changed (221) hide show
  1. package/README.md +211 -0
  2. package/dist/atlas/src/DB.d.ts +301 -0
  3. package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
  4. package/dist/atlas/src/config/defineConfig.d.ts +14 -0
  5. package/dist/atlas/src/config/index.d.ts +7 -0
  6. package/dist/atlas/src/config/loadConfig.d.ts +48 -0
  7. package/dist/atlas/src/connection/Connection.d.ts +108 -0
  8. package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
  9. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
  10. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
  11. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
  12. package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
  13. package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
  14. package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
  15. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
  16. package/dist/atlas/src/drivers/types.d.ts +260 -0
  17. package/dist/atlas/src/errors/index.d.ts +45 -0
  18. package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
  19. package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
  20. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
  21. package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
  22. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
  23. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
  24. package/dist/atlas/src/index.d.ts +67 -0
  25. package/dist/atlas/src/migration/Migration.d.ts +64 -0
  26. package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
  27. package/dist/atlas/src/migration/Migrator.d.ts +110 -0
  28. package/dist/atlas/src/migration/index.d.ts +6 -0
  29. package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
  30. package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
  31. package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
  32. package/dist/atlas/src/observability/index.d.ts +9 -0
  33. package/dist/atlas/src/orm/index.d.ts +5 -0
  34. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
  35. package/dist/atlas/src/orm/model/Model.d.ts +449 -0
  36. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
  37. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
  38. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
  39. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
  40. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
  41. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
  42. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
  43. package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
  44. package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
  45. package/dist/atlas/src/orm/model/errors.d.ts +52 -0
  46. package/dist/atlas/src/orm/model/index.d.ts +10 -0
  47. package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
  48. package/dist/atlas/src/orm/model/types.d.ts +12 -0
  49. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
  50. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
  51. package/dist/atlas/src/orm/schema/index.d.ts +6 -0
  52. package/dist/atlas/src/orm/schema/types.d.ts +85 -0
  53. package/dist/atlas/src/query/Expression.d.ts +60 -0
  54. package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
  55. package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
  56. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
  57. package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
  58. package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
  59. package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
  60. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
  61. package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
  62. package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
  63. package/dist/atlas/src/query/clauses/index.d.ts +11 -0
  64. package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
  65. package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
  66. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
  67. package/dist/atlas/src/schema/Schema.d.ts +131 -0
  68. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
  69. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
  70. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
  71. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
  72. package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
  73. package/dist/atlas/src/schema/index.d.ts +8 -0
  74. package/dist/atlas/src/seed/Factory.d.ts +90 -0
  75. package/dist/atlas/src/seed/Seeder.d.ts +28 -0
  76. package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
  77. package/dist/atlas/src/seed/index.d.ts +6 -0
  78. package/dist/atlas/src/types/index.d.ts +1100 -0
  79. package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
  80. package/dist/core/src/Application.d.ts +215 -0
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/ConfigManager.d.ts +26 -0
  83. package/dist/core/src/Container.d.ts +108 -0
  84. package/dist/core/src/ErrorHandler.d.ts +63 -0
  85. package/dist/core/src/Event.d.ts +5 -0
  86. package/dist/core/src/EventManager.d.ts +123 -0
  87. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  88. package/dist/core/src/GravitoServer.d.ts +28 -0
  89. package/dist/core/src/HookManager.d.ts +496 -0
  90. package/dist/core/src/Listener.d.ts +4 -0
  91. package/dist/core/src/Logger.d.ts +20 -0
  92. package/dist/core/src/PlanetCore.d.ts +289 -0
  93. package/dist/core/src/Route.d.ts +36 -0
  94. package/dist/core/src/Router.d.ts +284 -0
  95. package/dist/core/src/ServiceProvider.d.ts +156 -0
  96. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
  97. package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
  98. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  99. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
  100. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  101. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  102. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  103. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  104. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  105. package/dist/core/src/adapters/types.d.ts +235 -0
  106. package/dist/core/src/engine/AOTRouter.d.ts +124 -0
  107. package/dist/core/src/engine/FastContext.d.ts +100 -0
  108. package/dist/core/src/engine/Gravito.d.ts +137 -0
  109. package/dist/core/src/engine/MinimalContext.d.ts +79 -0
  110. package/dist/core/src/engine/analyzer.d.ts +27 -0
  111. package/dist/core/src/engine/constants.d.ts +23 -0
  112. package/dist/core/src/engine/index.d.ts +26 -0
  113. package/dist/core/src/engine/path.d.ts +26 -0
  114. package/dist/core/src/engine/pool.d.ts +83 -0
  115. package/dist/core/src/engine/types.d.ts +143 -0
  116. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  117. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  118. package/dist/core/src/events/EventBackend.d.ts +11 -0
  119. package/dist/core/src/events/EventOptions.d.ts +109 -0
  120. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  121. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  122. package/dist/core/src/events/index.d.ts +14 -0
  123. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  124. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  125. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  126. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  127. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  128. package/dist/core/src/events/observability/index.d.ts +20 -0
  129. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  130. package/dist/core/src/events/types.d.ts +75 -0
  131. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  132. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  133. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  134. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  135. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  136. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  137. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  138. package/dist/core/src/exceptions/index.d.ts +7 -0
  139. package/dist/core/src/helpers/Arr.d.ts +19 -0
  140. package/dist/core/src/helpers/Str.d.ts +23 -0
  141. package/dist/core/src/helpers/data.d.ts +25 -0
  142. package/dist/core/src/helpers/errors.d.ts +34 -0
  143. package/dist/core/src/helpers/response.d.ts +41 -0
  144. package/dist/core/src/helpers.d.ts +338 -0
  145. package/dist/core/src/http/CookieJar.d.ts +51 -0
  146. package/dist/core/src/http/cookie.d.ts +29 -0
  147. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  148. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  149. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  150. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  151. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  152. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  153. package/dist/core/src/http/types.d.ts +355 -0
  154. package/dist/core/src/index.d.ts +76 -0
  155. package/dist/core/src/instrumentation/index.d.ts +35 -0
  156. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  157. package/dist/core/src/instrumentation/types.d.ts +182 -0
  158. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  159. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  160. package/dist/core/src/reliability/index.d.ts +6 -0
  161. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  162. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  163. package/dist/core/src/runtime.d.ts +119 -0
  164. package/dist/core/src/security/Encrypter.d.ts +33 -0
  165. package/dist/core/src/security/Hasher.d.ts +29 -0
  166. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  167. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  168. package/dist/core/src/testing/index.d.ts +2 -0
  169. package/dist/core/src/types/events.d.ts +94 -0
  170. package/dist/echo/src/OrbitEcho.d.ts +115 -0
  171. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  172. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  173. package/dist/echo/src/dlq/index.d.ts +2 -0
  174. package/dist/echo/src/index.d.ts +64 -0
  175. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  176. package/dist/echo/src/middleware/index.d.ts +8 -0
  177. package/dist/echo/src/observability/index.d.ts +3 -0
  178. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  179. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  180. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  181. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  182. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  183. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  184. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  185. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  186. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  187. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  188. package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
  189. package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
  190. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  191. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  192. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  193. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  194. package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
  195. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  196. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  197. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  198. package/dist/echo/src/providers/index.d.ts +14 -0
  199. package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
  200. package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
  201. package/dist/echo/src/receive/index.d.ts +2 -0
  202. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  203. package/dist/echo/src/replay/index.d.ts +1 -0
  204. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  205. package/dist/echo/src/resilience/index.d.ts +10 -0
  206. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  207. package/dist/echo/src/rotation/index.d.ts +10 -0
  208. package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
  209. package/dist/echo/src/send/index.d.ts +1 -0
  210. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  211. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  212. package/dist/echo/src/storage/index.d.ts +2 -0
  213. package/dist/echo/src/types.d.ts +756 -0
  214. package/dist/index.js +1332 -190
  215. package/dist/index.js.map +28 -10
  216. package/dist/photon/src/index.d.ts +84 -0
  217. package/dist/photon/src/middleware/binary.d.ts +31 -0
  218. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  219. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  220. package/dist/photon/src/openapi.d.ts +19 -0
  221. package/package.json +7 -5
@@ -0,0 +1,235 @@
1
+ /**
2
+ * @fileoverview HTTP Adapter Interface for Gravito Framework
3
+ *
4
+ * This module defines the contract that all HTTP adapters must implement.
5
+ * By programming to this interface, Gravito can swap out the underlying
6
+ * HTTP engine without changing application code.
7
+ *
8
+ * @module @gravito/core/adapters
9
+ * @since 2.0.0
10
+ */
11
+ import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, GravitoVariables, HttpMethod } from '../http/types';
12
+ /**
13
+ * Configuration options for HTTP adapters
14
+ */
15
+ export interface AdapterConfig {
16
+ /**
17
+ * Base path prefix for all routes
18
+ * @default ''
19
+ */
20
+ basePath?: string;
21
+ /**
22
+ * Whether to enable strict routing (trailing slashes matter)
23
+ * @default false
24
+ */
25
+ strictRouting?: boolean;
26
+ /**
27
+ * Custom options passed to the underlying HTTP engine
28
+ */
29
+ engineOptions?: Record<string, unknown>;
30
+ }
31
+ /**
32
+ * Route definition structure
33
+ */
34
+ export interface RouteDefinition {
35
+ method: HttpMethod;
36
+ path: string;
37
+ handlers: (GravitoHandler | GravitoMiddleware)[];
38
+ name?: string;
39
+ middleware?: GravitoMiddleware[];
40
+ }
41
+ /**
42
+ * HttpAdapter - The core interface for HTTP engine abstraction
43
+ *
44
+ * Any HTTP engine (Photon, Express, Fastify, custom Bun implementation)
45
+ * must implement this interface to be usable with Gravito.
46
+ *
47
+ * @typeParam V - Context variables type
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Using the default Photon adapter
52
+ * import { PhotonAdapter } from '@gravito/core/adapters'
53
+ *
54
+ * const core = new PlanetCore({
55
+ * adapter: new PhotonAdapter()
56
+ * })
57
+ *
58
+ * // Using a custom adapter
59
+ * import { BunNativeAdapter } from '@gravito/adapter-bun'
60
+ *
61
+ * const core = new PlanetCore({
62
+ * adapter: new BunNativeAdapter()
63
+ * })
64
+ * ```
65
+ */
66
+ export interface HttpAdapter<V extends GravitoVariables = GravitoVariables> {
67
+ /**
68
+ * Adapter name for identification
69
+ * @example 'photon', 'bun-native', 'express'
70
+ */
71
+ readonly name: string;
72
+ /**
73
+ * Adapter version
74
+ */
75
+ readonly version: string;
76
+ /**
77
+ * Access the underlying native HTTP engine instance.
78
+ *
79
+ * ⚠️ WARNING: Using this ties your code to a specific adapter.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // For Photon adapter
84
+ * const photonApp = adapter.native as Photon
85
+ *
86
+ * // For custom Bun adapter
87
+ * const bunApp = adapter.native as BunApp
88
+ * ```
89
+ */
90
+ readonly native: unknown;
91
+ /**
92
+ * Register a route with the adapter
93
+ *
94
+ * @param method - HTTP method
95
+ * @param path - Route path (may include parameters like ':id')
96
+ * @param handlers - One or more handlers for this route (handlers or middleware)
97
+ */
98
+ route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
99
+ /**
100
+ * Register multiple routes at once
101
+ *
102
+ * @param routes - Array of route definitions
103
+ */
104
+ routes(routes: RouteDefinition[]): void;
105
+ /**
106
+ * Register a middleware for a path
107
+ *
108
+ * @param path - Path pattern to match
109
+ * @param middleware - One or more middleware functions
110
+ */
111
+ use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
112
+ /**
113
+ * Register a global middleware (applied to all routes)
114
+ *
115
+ * @param middleware - Middleware function
116
+ */
117
+ useGlobal(...middleware: GravitoMiddleware<V>[]): void;
118
+ /**
119
+ * Register a scoped middleware for Orbit-level isolation
120
+ *
121
+ * Unlike regular `use()`, this method enforces stricter scoping rules:
122
+ * - REJECTS '*' wildcard paths (prevents global middleware in Orbits)
123
+ * - ENFORCES that all middleware paths must include the scope prefix
124
+ * - Throws error if attempting to register global middleware within an Orbit scope
125
+ *
126
+ * This is designed to prevent accidental middleware cross-contamination
127
+ * when multiple Orbits are mounted to a single PlanetCore instance.
128
+ *
129
+ * @param scope - The scope/path prefix (e.g., '/api', '/blog')
130
+ * @param path - Path pattern to match (cannot be '*')
131
+ * @param middleware - One or more middleware functions
132
+ * @throws {Error} If path is '*' when in Orbit scope
133
+ * @since 2.3.0
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // Correct: Scoped to specific path
138
+ * adapter.useScoped('/api', '/users/*', authMiddleware)
139
+ *
140
+ * // Error: Cannot use wildcard in Orbit scope
141
+ * adapter.useScoped('/api', '*', loggerMiddleware)
142
+ * ```
143
+ */
144
+ useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
145
+ /**
146
+ * Mount a sub-adapter at a path
147
+ *
148
+ * @param path - Mount path
149
+ * @param subAdapter - The adapter to mount
150
+ */
151
+ mount(path: string, subAdapter: HttpAdapter<V>): void;
152
+ /**
153
+ * Set the error handler
154
+ *
155
+ * @param handler - Error handler function
156
+ */
157
+ onError(handler: GravitoErrorHandler<V>): void;
158
+ /**
159
+ * Set the not-found handler
160
+ *
161
+ * @param handler - Not-found handler function
162
+ */
163
+ onNotFound(handler: GravitoNotFoundHandler<V>): void;
164
+ /**
165
+ * The main fetch handler for serving requests.
166
+ *
167
+ * This is compatible with `Bun.serve()`, Cloudflare Workers,
168
+ * and other fetch-based runtimes.
169
+ *
170
+ * @param request - Incoming HTTP request
171
+ * @param server - Optional server context (Bun.Server, etc.)
172
+ * @returns HTTP response
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * // With Bun.serve
177
+ * Bun.serve({
178
+ * port: 3000,
179
+ * fetch: adapter.fetch
180
+ * })
181
+ * ```
182
+ */
183
+ fetch(request: Request, server?: unknown): Response | Promise<Response>;
184
+ /**
185
+ * Predictive Route Warming (JIT Optimization)
186
+ *
187
+ * Simulates requests to specified routes to trigger JIT compilation (FTL)
188
+ * before real traffic arrives.
189
+ *
190
+ * @param paths List of paths to warm up (e.g. ['/api/users', '/health'])
191
+ * @since 2.1.0
192
+ */
193
+ warmup?(paths: string[]): Promise<void>;
194
+ /**
195
+ * WebSocket Handler for Bun.serve
196
+ *
197
+ * @since 2.2.0
198
+ */
199
+ websocket?: {
200
+ open?(ws: unknown): void | Promise<void>;
201
+ message?(ws: unknown, message: string | Buffer | Uint8Array): void | Promise<void>;
202
+ close?(ws: unknown, code: number, message: string): void | Promise<void>;
203
+ drain?(ws: unknown): void | Promise<void>;
204
+ [key: string]: unknown;
205
+ };
206
+ /**
207
+ * Initialize the adapter
208
+ *
209
+ * Called during PlanetCore.boot()
210
+ */
211
+ init?(): void | Promise<void>;
212
+ /**
213
+ * Cleanup resources
214
+ *
215
+ * Called during graceful shutdown
216
+ */
217
+ shutdown?(): void | Promise<void>;
218
+ /**
219
+ * Create a GravitoContext from a raw request.
220
+ *
221
+ * This is used internally for testing and advanced scenarios.
222
+ *
223
+ * @param request - Raw HTTP request
224
+ * @returns Gravito context
225
+ */
226
+ createContext(request: Request): GravitoContext<V>;
227
+ }
228
+ /**
229
+ * Factory function type for creating adapters
230
+ */
231
+ export type AdapterFactory<V extends GravitoVariables = GravitoVariables> = (config?: AdapterConfig) => HttpAdapter<V>;
232
+ /**
233
+ * Check if a value is an HttpAdapter
234
+ */
235
+ export declare function isHttpAdapter(value: unknown): value is HttpAdapter;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @fileoverview AOT (Ahead-of-Time) Router
3
+ *
4
+ * Hybrid routing strategy:
5
+ * - Static routes: O(1) Map lookup
6
+ * - Dynamic routes: Optimized Radix Tree
7
+ *
8
+ * The key optimization is separating static from dynamic routes at registration time,
9
+ * not at match time. This eliminates unnecessary tree traversal for static paths.
10
+ *
11
+ * @module @gravito/core/engine
12
+ */
13
+ import type { HttpMethod } from '../http/types';
14
+ import type { Handler, Middleware, RouteMatch, RouteMetadata } from './types';
15
+ /**
16
+ * Route definition for re-playing routes (mounting)
17
+ */
18
+ interface RouteDefinition {
19
+ method: HttpMethod;
20
+ path: string;
21
+ handler: Handler;
22
+ middleware: Middleware[];
23
+ }
24
+ /**
25
+ * AOT Router - Optimized for Bun
26
+ */
27
+ export declare class AOTRouter {
28
+ /** @internal */
29
+ readonly staticRoutes: Map<string, RouteMetadata>;
30
+ private dynamicRouter;
31
+ /** @internal */
32
+ readonly routeDefinitions: RouteDefinition[];
33
+ /** @internal */
34
+ readonly globalMiddleware: Middleware[];
35
+ /** @internal */
36
+ readonly pathMiddleware: Map<string, Middleware[]>;
37
+ private dynamicRoutePatterns;
38
+ private middlewareCache;
39
+ private cacheMaxSize;
40
+ private version;
41
+ /**
42
+ * Register a route
43
+ *
44
+ * Automatically determines if route is static or dynamic.
45
+ * Static routes are stored in a Map for O(1) lookup.
46
+ * Dynamic routes use the Radix Tree.
47
+ *
48
+ * @param method - HTTP method
49
+ * @param path - Route path
50
+ * @param handler - Route handler
51
+ * @param middleware - Route-specific middleware
52
+ */
53
+ add(method: HttpMethod, path: string, handler: Handler, middleware?: Middleware[]): void;
54
+ /**
55
+ * Mount another router at a prefix
56
+ */
57
+ mount(prefix: string, other: AOTRouter): void;
58
+ /**
59
+ * Add global middleware
60
+ *
61
+ * These run for every request, before route-specific middleware.
62
+ *
63
+ * @param middleware - Middleware functions
64
+ */
65
+ use(...middleware: Middleware[]): void;
66
+ /**
67
+ * Add path-based middleware
68
+ *
69
+ * Supports wildcard patterns like '/api/*'
70
+ *
71
+ * @param pattern - Path pattern
72
+ * @param middleware - Middleware functions
73
+ */
74
+ usePattern(pattern: string, ...middleware: Middleware[]): void;
75
+ /**
76
+ * Match a request to a route
77
+ *
78
+ * Returns the handler, params, and all applicable middleware.
79
+ *
80
+ * @param method - HTTP method
81
+ * @param path - Request path
82
+ * @returns Route match or null if not found
83
+ */
84
+ match(method: string, path: string): RouteMatch;
85
+ /**
86
+ * Public wrapper for collectMiddleware (used by Gravito for optimization)
87
+ */
88
+ collectMiddlewarePublic(path: string, routeMiddleware: Middleware[]): Middleware[];
89
+ /**
90
+ * Collect all applicable middleware for a path
91
+ *
92
+ * Order: global -> pattern-based -> route-specific
93
+ *
94
+ * @param path - Request path
95
+ * @param routeMiddleware - Route-specific middleware
96
+ * @returns Combined middleware array
97
+ */
98
+ private collectMiddleware;
99
+ /**
100
+ * Check if a path is static (no parameters or wildcards)
101
+ */
102
+ private isStaticPath;
103
+ /**
104
+ * Match a pattern against a path
105
+ *
106
+ * Supports:
107
+ * - Exact match: '/api/users'
108
+ * - Wildcard suffix: '/api/*'
109
+ *
110
+ * @param pattern - Pattern to match
111
+ * @param path - Path to test
112
+ * @returns True if pattern matches
113
+ */
114
+ private matchPattern;
115
+ /**
116
+ * Get all registered routes (for debugging)
117
+ */
118
+ getRoutes(): Array<{
119
+ method: string;
120
+ path: string;
121
+ type: 'static' | 'dynamic';
122
+ }>;
123
+ }
124
+ export {};
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @fileoverview FastContext - Pooled Request Context
3
+ *
4
+ * Minimal, high-performance context implementation designed for object pooling.
5
+ * Lazy parsing strategy: only parse what's actually accessed.
6
+ *
7
+ * @module @gravito/core/engine
8
+ */
9
+ import type { FastRequest, FastContext as IFastContext } from './types';
10
+ /**
11
+ * Lazy-parsed request wrapper
12
+ *
13
+ * Delays parsing of query params, headers, and body until accessed.
14
+ * This is a key optimization for requests that don't need all data.
15
+ */
16
+ declare class FastRequestImpl implements FastRequest {
17
+ private _request;
18
+ private _params;
19
+ private _path;
20
+ private _routePattern?;
21
+ private _url;
22
+ private _query;
23
+ private _headers;
24
+ private _cachedJson;
25
+ private _jsonParsed;
26
+ private _ctx;
27
+ constructor(ctx: FastContext);
28
+ /**
29
+ * Initialize for new request
30
+ */
31
+ init(request: Request, params?: Record<string, string>, path?: string, routePattern?: string): this;
32
+ /**
33
+ * Reset for pooling
34
+ */
35
+ reset(): void;
36
+ private checkReleased;
37
+ get url(): string;
38
+ get method(): string;
39
+ get path(): string;
40
+ get routePattern(): string | undefined;
41
+ param(name: string): string | undefined;
42
+ params(): Record<string, string>;
43
+ private getUrl;
44
+ query(name: string): string | undefined;
45
+ queries(): Record<string, string | string[]>;
46
+ header(name: string): string | undefined;
47
+ headers(): Record<string, string>;
48
+ json<T = unknown>(): Promise<T>;
49
+ text(): Promise<string>;
50
+ formData(): Promise<FormData>;
51
+ get raw(): Request;
52
+ }
53
+ /**
54
+ * FastContext - Pooled request context
55
+ *
56
+ * Designed for minimal memory allocation and maximum reuse.
57
+ * All response helpers create Response objects directly without intermediate wrappers.
58
+ */
59
+ export declare class FastContext implements IFastContext {
60
+ readonly req: FastRequestImpl;
61
+ private _headers;
62
+ _isReleased: boolean;
63
+ /**
64
+ * Initialize context for a new request
65
+ *
66
+ * This is called when acquiring from the pool.
67
+ */
68
+ init(request: Request, params?: Record<string, string>, path?: string, routePattern?: string): this;
69
+ /**
70
+ * Reset context for pooling (Cleanup)
71
+ *
72
+ * This is called when releasing back to the pool.
73
+ * Implements "Deep-Reset Protocol" and "Release Guard".
74
+ */
75
+ reset(): void;
76
+ /**
77
+ * Check if context is released
78
+ */
79
+ private checkReleased;
80
+ json<T>(data: T, status?: number): Response;
81
+ text(text: string, status?: number): Response;
82
+ html(html: string, status?: number): Response;
83
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
84
+ body(data: BodyInit | null, status?: number): Response;
85
+ stream(stream: ReadableStream, status?: number): Response;
86
+ notFound(message?: string): Response;
87
+ forbidden(message?: string): Response;
88
+ unauthorized(message?: string): Response;
89
+ badRequest(message?: string): Response;
90
+ forward(target: string, _options?: any): Promise<Response>;
91
+ header(name: string): string | undefined;
92
+ header(name: string, value: string): void;
93
+ status(_code: number): void;
94
+ private _store;
95
+ get<T>(key: string): T;
96
+ set(key: string, value: any): void;
97
+ route: (name: string, params?: any, query?: any) => string;
98
+ get native(): this;
99
+ }
100
+ export {};
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @fileoverview Gravito - High-Performance Web Engine for Bun
3
+ *
4
+ * The standalone engine optimized exclusively for Bun runtime.
5
+ * 99% API-compatible with Hono, but faster through Bun-specific optimizations.
6
+ *
7
+ * Key optimizations:
8
+ * 1. Object pooling for zero-allocation request handling
9
+ * 2. AOT router with O(1) static route lookup
10
+ * 3. Lazy parsing - only parse what's accessed
11
+ * 4. Direct Bun.serve integration without wrapper layers
12
+ *
13
+ * @module @gravito/core/engine
14
+ */
15
+ import type { EngineOptions, ErrorHandler, Handler, Middleware, NotFoundHandler, RouteMetadata } from './types';
16
+ /**
17
+ * Gravito - The High-Performance Web Engine
18
+ */
19
+ export declare class Gravito {
20
+ private router;
21
+ private contextPool;
22
+ private errorHandler?;
23
+ private notFoundHandler?;
24
+ /** @internal */
25
+ staticRoutes: Map<string, RouteMetadata>;
26
+ private isPureStaticApp;
27
+ private compiledDynamicRoutes;
28
+ private middlewareVersion;
29
+ /**
30
+ * Create a new Gravito instance
31
+ *
32
+ * @param options - Engine configuration options
33
+ */
34
+ constructor(options?: EngineOptions);
35
+ /**
36
+ * Register a GET route
37
+ *
38
+ * @param path - Route path (e.g., '/users/:id')
39
+ * @param handlers - Handler and optional middleware
40
+ * @returns This instance for chaining
41
+ */
42
+ get(path: string, ...handlers: Handler[]): this;
43
+ /**
44
+ * Register a POST route
45
+ */
46
+ post(path: string, ...handlers: Handler[]): this;
47
+ /**
48
+ * Register a PUT route
49
+ */
50
+ put(path: string, ...handlers: Handler[]): this;
51
+ /**
52
+ * Register a DELETE route
53
+ */
54
+ delete(path: string, ...handlers: Handler[]): this;
55
+ /**
56
+ * Register a PDF route
57
+ */
58
+ patch(path: string, ...handlers: Handler[]): this;
59
+ /**
60
+ * Register an OPTIONS route
61
+ */
62
+ options(path: string, ...handlers: Handler[]): this;
63
+ /**
64
+ * Register a HEAD route
65
+ */
66
+ head(path: string, ...handlers: Handler[]): this;
67
+ /**
68
+ * Register a route for all HTTP methods
69
+ */
70
+ all(path: string, ...handlers: Handler[]): this;
71
+ /**
72
+ * Register global or path-based middleware
73
+ */
74
+ use(path: string, ...middleware: Middleware[]): this;
75
+ use(...middleware: Middleware[]): this;
76
+ /**
77
+ * Mount a sub-application at a path prefix
78
+ */
79
+ route(path: string, app: Gravito): this;
80
+ /**
81
+ * Set custom error handler
82
+ */
83
+ onError(handler: ErrorHandler): this;
84
+ /**
85
+ * Set custom 404 handler
86
+ */
87
+ notFound(handler: NotFoundHandler): this;
88
+ /**
89
+ * Predictive Route Warming (JIT Optimization)
90
+ *
91
+ * Simulates requests to specified routes to trigger JIT compilation (FTL)
92
+ * before real traffic arrives.
93
+ *
94
+ * @param paths List of paths to warm up (e.g. ['/api/users', '/health'])
95
+ */
96
+ warmup(paths: string[]): Promise<void>;
97
+ /**
98
+ * Handle an incoming request
99
+ */
100
+ fetch: (request: Request) => Promise<Response>;
101
+ /**
102
+ * Handle routes with middleware (async path)
103
+ */
104
+ private handleWithMiddleware;
105
+ /**
106
+ * Handle dynamic routes (Radix Tree lookup)
107
+ */
108
+ private handleDynamicRoute;
109
+ /**
110
+ * Sync error handler (for ultra-fast path)
111
+ */
112
+ private handleErrorSync;
113
+ /**
114
+ * Sync 404 handler (for ultra-fast path)
115
+ */
116
+ private handleNotFoundSync;
117
+ /**
118
+ * Collect middleware for a specific path
119
+ */
120
+ private collectMiddlewareForPath;
121
+ /**
122
+ * Compile routes for optimization
123
+ */
124
+ private compileRoutes;
125
+ /**
126
+ * Add a route to the router
127
+ */
128
+ private addRoute;
129
+ /**
130
+ * Execute middleware chain followed by handler
131
+ */
132
+ private executeMiddleware;
133
+ /**
134
+ * Handle errors (Async version for dynamic/middleware paths)
135
+ */
136
+ private handleError;
137
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview MinimalContext - Ultra-lightweight Request Context
3
+ *
4
+ * Designed for zero-middleware static routes where pool overhead
5
+ * exceeds the cost of creating a new object.
6
+ *
7
+ * Key difference from FastContext:
8
+ * - No object pooling (direct instantiation is faster for simple cases)
9
+ * - No Headers object reuse (creates inline)
10
+ * - Minimal memory footprint
11
+ *
12
+ * @module @gravito/core/engine
13
+ */
14
+ import type { FastRequest, FastContext as IFastContext } from './types';
15
+ /**
16
+ * Minimal request wrapper
17
+ */
18
+ declare class MinimalRequest implements FastRequest {
19
+ private readonly _request;
20
+ private readonly _params;
21
+ private readonly _path;
22
+ private readonly _routePattern?;
23
+ private _searchParams;
24
+ constructor(_request: Request, _params: Record<string, string>, _path: string, _routePattern?: string | undefined);
25
+ get url(): string;
26
+ get method(): string;
27
+ get path(): string;
28
+ get routePattern(): string | undefined;
29
+ param(name: string): string | undefined;
30
+ params(): Record<string, string>;
31
+ /**
32
+ * Lazy-initialize searchParams, only parse once
33
+ */
34
+ private getSearchParams;
35
+ query(name: string): string | undefined;
36
+ queries(): Record<string, string | string[]>;
37
+ header(name: string): string | undefined;
38
+ headers(): Record<string, string>;
39
+ json<T = unknown>(): Promise<T>;
40
+ text(): Promise<string>;
41
+ formData(): Promise<FormData>;
42
+ get raw(): Request;
43
+ }
44
+ /**
45
+ * MinimalContext - Optimized for simple, fast responses
46
+ *
47
+ * Use when:
48
+ * - No middleware
49
+ * - Static routes
50
+ * - Simple JSON/text responses
51
+ * - No custom headers needed
52
+ */
53
+ export declare class MinimalContext implements IFastContext {
54
+ readonly req: MinimalRequest;
55
+ private _resHeaders;
56
+ constructor(request: Request, params: Record<string, string>, path: string, routePattern?: string);
57
+ private getHeaders;
58
+ json<T>(data: T, status?: number): Response;
59
+ text(text: string, status?: number): Response;
60
+ html(html: string, status?: number): Response;
61
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
62
+ body(data: BodyInit | null, status?: number): Response;
63
+ header(name: string): string | undefined;
64
+ header(name: string, value: string): void;
65
+ status(_code: number): void;
66
+ stream(stream: ReadableStream, status?: number): Response;
67
+ notFound(message?: string): Response;
68
+ forbidden(message?: string): Response;
69
+ unauthorized(message?: string): Response;
70
+ badRequest(message?: string): Response;
71
+ forward(target: string, _options?: any): Promise<Response>;
72
+ get<T>(_key: string): T;
73
+ set(_key: string, _value: any): void;
74
+ route: (name: string, params?: any, query?: any) => string;
75
+ get native(): this;
76
+ init(_request: Request, _params?: Record<string, string>, _path?: string): this;
77
+ reset(): void;
78
+ }
79
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Handler Static Analyzer (Elysia-inspired)
3
+ *
4
+ * Analyzes handler functions to determine what request properties
5
+ * they access, allowing for optimized code paths.
6
+ */
7
+ /**
8
+ * Represents the results of a static analysis performed on a handler function.
9
+ *
10
+ * @public
11
+ * @since 3.0.0
12
+ */
13
+ export interface HandlerAnalysis {
14
+ usesHeaders: boolean;
15
+ usesQuery: boolean;
16
+ usesBody: boolean;
17
+ usesParams: boolean;
18
+ isAsync: boolean;
19
+ }
20
+ /**
21
+ * Analyze a handler function to detect what it accesses
22
+ */
23
+ export declare function analyzeHandler(handler: Function): HandlerAnalysis;
24
+ /**
25
+ * Determine optimal context type based on analysis
26
+ */
27
+ export declare function getOptimalContextType(analysis: HandlerAnalysis): 'minimal' | 'fast' | 'full';