@gravito/ripple 4.0.0 → 4.0.3

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 (225) hide show
  1. package/README.md +26 -10
  2. package/dist/{ripple/src/OrbitRipple.d.ts → OrbitRipple.d.ts} +1 -0
  3. package/dist/{ripple/src/RippleServer.d.ts → RippleServer.d.ts} +32 -2
  4. package/dist/core/src/Application.d.ts +41 -0
  5. package/dist/core/src/ConfigManager.d.ts +39 -0
  6. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/core/src/Container.d.ts +45 -0
  9. package/dist/core/src/ErrorHandler.d.ts +3 -0
  10. package/dist/core/src/HookManager.d.ts +104 -165
  11. package/dist/core/src/PlanetCore.d.ts +114 -1
  12. package/dist/core/src/RequestContext.d.ts +97 -0
  13. package/dist/core/src/Router.d.ts +32 -46
  14. package/dist/core/src/ServiceProvider.d.ts +22 -0
  15. package/dist/core/src/adapters/bun/BunContext.d.ts +10 -1
  16. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
  17. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  18. package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
  19. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  20. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  21. package/dist/core/src/binary/index.d.ts +5 -0
  22. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  23. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  24. package/dist/core/src/compat/crypto.d.ts +6 -0
  25. package/dist/core/src/engine/AOTRouter.d.ts +16 -1
  26. package/dist/core/src/engine/FastContext.d.ts +42 -1
  27. package/dist/core/src/engine/Gravito.d.ts +13 -19
  28. package/dist/core/src/engine/MinimalContext.d.ts +23 -0
  29. package/dist/core/src/engine/analyzer.d.ts +92 -6
  30. package/dist/core/src/engine/types.d.ts +6 -0
  31. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  32. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  33. package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
  34. package/dist/core/src/events/EventBackend.d.ts +2 -1
  35. package/dist/core/src/events/EventOptions.d.ts +99 -4
  36. package/dist/core/src/events/EventPriorityQueue.d.ts +36 -175
  37. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  38. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  39. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  40. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  41. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  42. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  43. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  44. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  45. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  46. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  47. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  48. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  49. package/dist/core/src/events/index.d.ts +18 -6
  50. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
  51. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  52. package/dist/core/src/events/observability/index.d.ts +4 -0
  53. package/dist/core/src/events/queue-core.d.ts +77 -0
  54. package/dist/core/src/events/task-executor.d.ts +51 -0
  55. package/dist/core/src/events/types.d.ts +59 -0
  56. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  57. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  58. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  59. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  60. package/dist/core/src/ffi/index.d.ts +10 -0
  61. package/dist/core/src/ffi/types.d.ts +135 -0
  62. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  63. package/dist/core/src/helpers/Str.d.ts +15 -0
  64. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  65. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  66. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  67. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  68. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  69. package/dist/core/src/hooks/types.d.ts +107 -0
  70. package/dist/core/src/http/CookieJar.d.ts +2 -2
  71. package/dist/core/src/http/types.d.ts +43 -3
  72. package/dist/core/src/index.d.ts +504 -15
  73. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  74. package/dist/core/src/observability/contracts.d.ts +137 -0
  75. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +36 -3
  76. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  77. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  78. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  79. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  80. package/dist/core/src/runtime/archive.d.ts +17 -0
  81. package/dist/core/src/runtime/compression.d.ts +21 -0
  82. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  83. package/dist/core/src/runtime/detection.d.ts +22 -0
  84. package/dist/core/src/runtime/escape.d.ts +34 -0
  85. package/dist/core/src/runtime/index.d.ts +44 -0
  86. package/dist/core/src/runtime/markdown.d.ts +44 -0
  87. package/dist/core/src/runtime/types.d.ts +436 -0
  88. package/dist/core/src/runtime-helpers.d.ts +67 -0
  89. package/dist/core/src/runtime.d.ts +10 -118
  90. package/dist/core/src/testing/HttpTester.d.ts +1 -0
  91. package/dist/core/src/transpiler-utils.d.ts +170 -0
  92. package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
  93. package/dist/engines/UWebSocketsEngine.d.ts +97 -0
  94. package/dist/engines/WsEngine.d.ts +69 -0
  95. package/dist/{ripple/src/engines → engines}/index.d.ts +4 -0
  96. package/dist/index.js +1 -7139
  97. package/dist/index.js.map +3 -69
  98. package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +1 -1
  99. package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +1 -1
  100. package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +6 -3
  101. package/dist/{ripple/src/types.d.ts → types.d.ts} +11 -0
  102. package/package.json +7 -2
  103. package/dist/atlas/src/DB.d.ts +0 -301
  104. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  105. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  106. package/dist/atlas/src/config/index.d.ts +0 -7
  107. package/dist/atlas/src/config/loadConfig.d.ts +0 -48
  108. package/dist/atlas/src/connection/Connection.d.ts +0 -108
  109. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -111
  110. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  111. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  112. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  113. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -66
  114. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -83
  115. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  116. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  117. package/dist/atlas/src/drivers/types.d.ts +0 -260
  118. package/dist/atlas/src/errors/index.d.ts +0 -45
  119. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  120. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  121. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  122. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  123. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  124. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  125. package/dist/atlas/src/index.d.ts +0 -67
  126. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  127. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  128. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  129. package/dist/atlas/src/migration/index.d.ts +0 -6
  130. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -11
  131. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  132. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  133. package/dist/atlas/src/observability/index.d.ts +0 -9
  134. package/dist/atlas/src/orm/index.d.ts +0 -5
  135. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  136. package/dist/atlas/src/orm/model/Model.d.ts +0 -449
  137. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  138. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -136
  139. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  140. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -87
  141. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  142. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  143. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  144. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  145. package/dist/atlas/src/orm/model/decorators.d.ts +0 -109
  146. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  147. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  148. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  149. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  150. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -123
  151. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  152. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  153. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  154. package/dist/atlas/src/query/Expression.d.ts +0 -60
  155. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  156. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -573
  157. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  158. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  159. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  160. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  161. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  162. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  163. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  164. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  165. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  166. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  167. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  168. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  169. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  170. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  171. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  172. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  173. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  174. package/dist/atlas/src/schema/index.d.ts +0 -8
  175. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  176. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  177. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  178. package/dist/atlas/src/seed/index.d.ts +0 -6
  179. package/dist/atlas/src/types/index.d.ts +0 -1100
  180. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  181. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -171
  182. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  183. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  184. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  185. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  186. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  187. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  188. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  189. package/dist/core/src/instrumentation/index.d.ts +0 -35
  190. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  191. package/dist/core/src/instrumentation/types.d.ts +0 -182
  192. package/dist/photon/src/index.d.ts +0 -84
  193. package/dist/photon/src/middleware/binary.d.ts +0 -31
  194. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  195. package/dist/photon/src/middleware/ratelimit.d.ts +0 -157
  196. package/dist/photon/src/openapi.d.ts +0 -19
  197. /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
  198. /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
  199. /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
  200. /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
  201. /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
  202. /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
  203. /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
  204. /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
  205. /package/dist/{ripple/src/errors → errors}/RippleError.d.ts +0 -0
  206. /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
  207. /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
  208. /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
  209. /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
  210. /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
  211. /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
  212. /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
  213. /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
  214. /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
  215. /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
  216. /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
  217. /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
  218. /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
  219. /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
  220. /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
  221. /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
  222. /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
  223. /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
  224. /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
  225. /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
@@ -55,6 +55,33 @@ export interface RouteOptions {
55
55
  /** Middleware stack for the route */
56
56
  middleware?: GravitoMiddleware[];
57
57
  }
58
+ /**
59
+ * Common routing handler argument definition
60
+ * @public
61
+ */
62
+ export type RouteDefinitionArg = FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[];
63
+ /**
64
+ * Interface merging for HTTP routing methods to establish overloads
65
+ * without duplicate bodies.
66
+ * @public
67
+ */
68
+ export interface RoutingMethods {
69
+ get(path: string, handler: RouteHandler): Route;
70
+ get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
71
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
72
+ post(path: string, handler: RouteHandler): Route;
73
+ post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
74
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
75
+ put(path: string, handler: RouteHandler): Route;
76
+ put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
77
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
78
+ delete(path: string, handler: RouteHandler): Route;
79
+ delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
80
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
81
+ patch(path: string, handler: RouteHandler): Route;
82
+ patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
83
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
84
+ }
58
85
  /**
59
86
  * RouteGroup
60
87
  * Helper class for chained route configuration (prefix, domain, etc.)
@@ -64,6 +91,8 @@ export interface RouteOptions {
64
91
  * Helper class for chained route configuration (prefix, domain, etc.)
65
92
  * @public
66
93
  */
94
+ export interface RouteGroup extends RoutingMethods {
95
+ }
67
96
  export declare class RouteGroup {
68
97
  private router;
69
98
  private options;
@@ -81,21 +110,6 @@ export declare class RouteGroup {
81
110
  * Define routes within this group
82
111
  */
83
112
  group(callback: (router: Router | RouteGroup) => void): void;
84
- get(path: string, handler: RouteHandler): Route;
85
- get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
86
- get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
87
- post(path: string, handler: RouteHandler): Route;
88
- post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
89
- post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
90
- put(path: string, handler: RouteHandler): Route;
91
- put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
92
- put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
93
- delete(path: string, handler: RouteHandler): Route;
94
- delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
95
- delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
96
- patch(path: string, handler: RouteHandler): Route;
97
- patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
98
- patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
99
113
  resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
100
114
  /**
101
115
  * Register a route that forwards requests to another URL (Gateway Proxy).
@@ -118,6 +132,8 @@ export declare class RouteGroup {
118
132
  * - FormRequest validation: router.post('/users', StoreUserRequest, [UserController, 'store'])
119
133
  * - Inline Middleware: router.get('/users', authMiddleware, [UserController, 'index'])
120
134
  */
135
+ export interface Router extends RoutingMethods {
136
+ }
121
137
  export declare class Router {
122
138
  private core;
123
139
  routes: Array<{
@@ -210,36 +226,6 @@ export declare class Router {
210
226
  * Accepts individual handlers or arrays of handlers.
211
227
  */
212
228
  middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
213
- /**
214
- * Register a GET route.
215
- */
216
- get(path: string, handler: RouteHandler): Route;
217
- get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
218
- get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
219
- /**
220
- * Register a POST route.
221
- */
222
- post(path: string, handler: RouteHandler): Route;
223
- post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
224
- post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
225
- /**
226
- * Register a PUT route.
227
- */
228
- put(path: string, handler: RouteHandler): Route;
229
- put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
230
- put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
231
- /**
232
- * Register a DELETE route.
233
- */
234
- delete(path: string, handler: RouteHandler): Route;
235
- delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
236
- delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
237
- /**
238
- * Register a PATCH route.
239
- */
240
- patch(path: string, handler: RouteHandler): Route;
241
- patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
242
- patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
243
229
  /**
244
230
  * Register a route that forwards requests to another URL (Gateway Proxy).
245
231
  * @param method - HTTP method or 'all'
@@ -267,7 +253,7 @@ export declare class Router {
267
253
  /**
268
254
  * Internal Request Registration
269
255
  */
270
- req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
256
+ req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: RouteDefinitionArg, handler?: RouteHandler, options?: RouteOptions): Route;
271
257
  }
272
258
  /**
273
259
  * Standard RESTful resource action names.
@@ -74,6 +74,28 @@ export declare abstract class ServiceProvider {
74
74
  * @param core - The PlanetCore application instance
75
75
  */
76
76
  boot?(core: PlanetCore): void | Promise<void>;
77
+ /**
78
+ * Called when the application is ready to accept requests.
79
+ *
80
+ * This method is called after ALL providers have booted.
81
+ * Use this for final initialization before the server starts accepting traffic.
82
+ *
83
+ * @param core - The PlanetCore application instance
84
+ * @since 2.2.0
85
+ */
86
+ onReady?(core: PlanetCore): void | Promise<void>;
87
+ /**
88
+ * Called when the application is shutting down.
89
+ *
90
+ * This method is called during graceful shutdown.
91
+ * Use this to clean up resources, close connections, etc.
92
+ *
93
+ * Providers are called in reverse order (LIFO).
94
+ *
95
+ * @param core - The PlanetCore application instance
96
+ * @since 2.2.0
97
+ */
98
+ onShutdown?(core: PlanetCore): void | Promise<void>;
77
99
  /**
78
100
  * Set the core instance reference.
79
101
  * Called internally by the application during registration.
@@ -1,3 +1,4 @@
1
+ import { RequestScopeManager } from '../../Container/RequestScopeManager';
1
2
  import type { ContentfulStatusCode, GravitoContext, GravitoVariables, ProxyOptions, StatusCode } from '../../http/types';
2
3
  import { BunRequest } from './BunRequest';
3
4
  /**
@@ -6,8 +7,9 @@ import { BunRequest } from './BunRequest';
6
7
  */
7
8
  export declare class BunContext<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
8
9
  readonly env: Record<string, unknown>;
9
- readonly req: BunRequest;
10
+ req: BunRequest;
10
11
  private _variables;
12
+ private _requestScope;
11
13
  /**
12
14
  * URL generator helper
13
15
  */
@@ -38,8 +40,15 @@ export declare class BunContext<V extends GravitoVariables = GravitoVariables> i
38
40
  append?: boolean;
39
41
  }): void;
40
42
  header(name: string): string | undefined;
43
+ /**
44
+ * Reset context state for reuse in pooling scenarios
45
+ * @internal
46
+ */
47
+ reset(request: Request): void;
41
48
  status(code: StatusCode): void;
42
49
  get<K extends keyof V>(key: K): V[K];
43
50
  set<K extends keyof V>(key: K, value: V[K]): void;
44
51
  get executionCtx(): ExecutionContext | undefined;
52
+ requestScope(): RequestScopeManager;
53
+ scoped<T>(key: string | symbol, factory: () => T): T;
45
54
  }
@@ -1,5 +1,6 @@
1
1
  import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, HttpMethod } from '../../http/types';
2
2
  import type { HttpAdapter, RouteDefinition } from '../types';
3
+ import type { WebSocketRouteHandlers } from './BunWebSocketHandler';
3
4
  /**
4
5
  * Native Bun-optimized HTTP Adapter for Gravito.
5
6
  * Uses Bun's standard Request/Response classes and efficient router.
@@ -13,15 +14,49 @@ export declare class BunNativeAdapter implements HttpAdapter {
13
14
  private middlewares;
14
15
  private errorHandler;
15
16
  private notFoundHandler;
17
+ private contextPool;
18
+ private readonly maxPoolSize;
19
+ private middlewareChainCache;
20
+ private wsHandler;
16
21
  route(method: HttpMethod, path: string, ...handlers: (GravitoHandler | GravitoMiddleware)[]): void;
17
22
  routes(routes: RouteDefinition[]): void;
18
23
  use(path: string, ...middleware: GravitoMiddleware[]): void;
19
24
  useGlobal(...middleware: GravitoMiddleware[]): void;
20
25
  useScoped(scope: string, path: string, ...middleware: GravitoMiddleware[]): void;
26
+ /**
27
+ * P1 Fix: Accurate path pattern matching for middleware
28
+ * Handles wildcards: *, /api/*, /api
29
+ */
30
+ private matchesPath;
31
+ /**
32
+ * P2 optimization: Pre-compile middleware chain for a path
33
+ */
34
+ private getCompiledMiddlewareChain;
35
+ /**
36
+ * P0 Fix: Context object pooling to prevent state pollution
37
+ */
38
+ private acquireContext;
39
+ /**
40
+ * P0 Fix: Release context back to pool
41
+ */
42
+ private releaseContext;
21
43
  mount(path: string, subAdapter: HttpAdapter): void;
22
44
  createContext(request: Request): GravitoContext;
23
45
  onError(handler: GravitoErrorHandler): void;
24
46
  onNotFound(handler: GravitoNotFoundHandler): void;
47
+ /**
48
+ * 註冊 WebSocket 路由
49
+ */
50
+ registerWebSocketRoute(path: string, handlers: WebSocketRouteHandlers): void;
51
+ /**
52
+ * 取得 WebSocket handler(供 Bun.serve 使用)
53
+ */
54
+ get websocket(): {
55
+ open?: (ws: unknown) => void | Promise<void>;
56
+ message?: (ws: unknown, data: string | Buffer | Uint8Array) => void | Promise<void>;
57
+ close?: (ws: unknown, code: number, reason: string) => void | Promise<void>;
58
+ drain?: (ws: unknown) => void | Promise<void>;
59
+ } | undefined;
25
60
  /**
26
61
  * Predictive Route Warming (JIT Optimization)
27
62
  */
@@ -0,0 +1,48 @@
1
+ /**
2
+ * WebSocket 路由管理器
3
+ *
4
+ * 負責註冊和分發 WebSocket 事件到相應的路由處理器
5
+ */
6
+ export interface WebSocketRouteHandlers {
7
+ open?: (ws: unknown) => void | Promise<void>;
8
+ message?: (ws: unknown, data: string | Buffer | Uint8Array) => void | Promise<void>;
9
+ close?: (ws: unknown, code: number, reason: string) => void | Promise<void>;
10
+ drain?: (ws: unknown) => void | Promise<void>;
11
+ }
12
+ export declare class BunWebSocketHandler {
13
+ private routes;
14
+ /**
15
+ * 註冊 WebSocket 路由
16
+ */
17
+ register(path: string, handlers: WebSocketRouteHandlers): void;
18
+ /**
19
+ * 檢查是否有該路由
20
+ * 支援精確匹配和 wildcard 匹配
21
+ */
22
+ hasRoute(path: string): boolean;
23
+ /**
24
+ * 檢查是否有任何已註冊的路由
25
+ */
26
+ hasAnyRoute(): boolean;
27
+ /**
28
+ * 將 handlers 轉換為 Bun.serve websocket config
29
+ */
30
+ toHandler(): {
31
+ open?: (ws: unknown) => void | Promise<void>;
32
+ message?: (ws: unknown, data: string | Buffer | Uint8Array) => void | Promise<void>;
33
+ close?: (ws: unknown, code: number, reason: string) => void | Promise<void>;
34
+ drain?: (ws: unknown) => void | Promise<void>;
35
+ };
36
+ /**
37
+ * 尋找符合路徑的 handler
38
+ * 優先精確匹配,再 wildcard 匹配
39
+ */
40
+ private findHandler;
41
+ /**
42
+ * 路徑匹配邏輯
43
+ * 支援:
44
+ * - 精確匹配:/chat
45
+ * - Wildcard:/api/*, /api*
46
+ */
47
+ private matchesPath;
48
+ }
@@ -6,6 +6,7 @@ import { type RouteHandler, type RouteMatch } from './types';
6
6
  export declare class RadixRouter {
7
7
  private root;
8
8
  private globalConstraints;
9
+ private routeCache;
9
10
  /**
10
11
  * Add a generic parameter constraint
11
12
  */
@@ -0,0 +1,7 @@
1
+ export * from './BunContext';
2
+ export * from './BunNativeAdapter';
3
+ export * from './BunRequest';
4
+ export * from './BunWebSocketHandler';
5
+ export * from './RadixNode';
6
+ export * from './RadixRouter';
7
+ export * from './types';
@@ -0,0 +1,105 @@
1
+ /**
2
+ * BinaryUtils - 統一的二進制轉換工具類
3
+ *
4
+ * 支援 Bun 原生 API 優化,並提供 Node.js 回退路徑。
5
+ * 設計為 isomorphic,可在 Bun 和 Node.js 環境中運行。
6
+ * @public
7
+ */
8
+ /**
9
+ * BinaryUtils - 提供統一的二進制轉換、編碼、壓縮工具
10
+ * 所有方法均為靜態方法,可直接呼叫
11
+ * @public
12
+ */
13
+ export declare class BinaryUtils {
14
+ /**
15
+ * 將各種資料類型轉換為 Uint8Array
16
+ * @param data - 輸入資料(Blob、Buffer、string、ArrayBuffer 或 Uint8Array)
17
+ * @returns Uint8Array
18
+ * @public
19
+ */
20
+ static toUint8Array(data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
21
+ /**
22
+ * 將各種資料類型轉換為 ArrayBuffer
23
+ * @param data - 輸入資料
24
+ * @returns ArrayBuffer
25
+ * @public
26
+ */
27
+ static toArrayBuffer(data: Blob | Buffer | string | Uint8Array | ArrayBuffer): Promise<ArrayBuffer>;
28
+ /**
29
+ * 將 Uint8Array 編碼為 Base64 字串
30
+ * 在 Bun 環境中使用原生 toBase64(),否則使用 Buffer
31
+ * @param data - 輸入的 Uint8Array
32
+ * @returns Base64 字串
33
+ * @public
34
+ */
35
+ static toBase64(data: Uint8Array): string;
36
+ /**
37
+ * 將 Base64 字串解碼為 Uint8Array
38
+ * @param base64 - Base64 字串
39
+ * @returns Uint8Array
40
+ * @public
41
+ */
42
+ static fromBase64(base64: string): Uint8Array;
43
+ /**
44
+ * 將 Uint8Array 編碼為 Base64URL 字串(URL 安全,無填充)
45
+ * @param data - 輸入的 Uint8Array
46
+ * @returns Base64URL 字串
47
+ * @public
48
+ */
49
+ static toBase64Url(data: Uint8Array): string;
50
+ /**
51
+ * 將 Base64URL 字串解碼為 Uint8Array
52
+ * @param base64url - Base64URL 字串
53
+ * @returns Uint8Array
54
+ * @public
55
+ */
56
+ static fromBase64Url(base64url: string): Uint8Array;
57
+ /**
58
+ * 將 Uint8Array 編碼為十六進制字串
59
+ * 在 Bun 環境中使用原生 toHex(),否則使用 Buffer
60
+ * @param data - 輸入的 Uint8Array
61
+ * @returns 十六進制字串(小寫)
62
+ * @public
63
+ */
64
+ static toHex(data: Uint8Array): string;
65
+ /**
66
+ * 將十六進制字串解碼為 Uint8Array
67
+ * @param hex - 十六進制字串
68
+ * @returns Uint8Array
69
+ * @throws {TypeError} 如果輸入不是有效的十六進制字串
70
+ * @public
71
+ */
72
+ static fromHex(hex: string): Uint8Array;
73
+ /**
74
+ * 使用 gzip 壓縮資料
75
+ * 在 Bun 環境中使用原生 Bun.gzipSync(),在 Node.js 中使用 zlib
76
+ * @param data - 輸入資料
77
+ * @param level - 壓縮等級(0-9),預設為 6
78
+ * @returns 壓縮後的 Uint8Array
79
+ * @public
80
+ */
81
+ static gzip(data: Uint8Array, level?: number): Promise<Uint8Array>;
82
+ /**
83
+ * 解壓縮 gzip 資料
84
+ * 在 Bun 環境中使用原生 Bun.gunzipSync(),在 Node.js 中使用 zlib
85
+ * @param data - gzip 壓縮的 Uint8Array
86
+ * @returns 解壓縮後的 Uint8Array
87
+ * @public
88
+ */
89
+ static gunzip(data: Uint8Array): Promise<Uint8Array>;
90
+ /**
91
+ * 將 ReadableStream<Uint8Array> 讀取為 Uint8Array
92
+ * 在 Bun 環境中使用原生 Bun.readableStreamToBytes(),否則手動讀取 chunks
93
+ * @param stream - 輸入的 ReadableStream
94
+ * @returns Uint8Array
95
+ * @public
96
+ */
97
+ static readableStreamToBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;
98
+ /**
99
+ * 將 ReadableStream<Uint8Array> 讀取為 ArrayBuffer
100
+ * @param stream - 輸入的 ReadableStream
101
+ * @returns ArrayBuffer
102
+ * @public
103
+ */
104
+ static readableStreamToArrayBuffer(stream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>;
105
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Binary utilities module for @gravito/core
3
+ * @packageDocumentation
4
+ */
5
+ export { BinaryUtils } from './BinaryUtils';
@@ -0,0 +1,6 @@
1
+ import type { CommandKernel } from '../CommandKernel';
2
+ import type { QueueDashboard } from '../observability/QueueDashboard';
3
+ /**
4
+ * Register queue management commands with CommandKernel
5
+ */
6
+ export declare function registerQueueCommands(kernel: CommandKernel, dashboard: QueueDashboard): void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Universal AsyncLocalStorage wrapper.
3
+ * Automatically switches between node:async_hooks and a browser mock.
4
+ */
5
+ export declare const AsyncLocalStorage: {
6
+ new <_T>(): any;
7
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Universal Crypto wrapper.
3
+ * Automatically switches between node:crypto and globalThis.crypto.
4
+ */
5
+ export declare const randomUUID: () => string;
6
+ export declare const randomBytes: (size: number) => any;
@@ -37,7 +37,12 @@ export declare class AOTRouter {
37
37
  private dynamicRoutePatterns;
38
38
  private middlewareCache;
39
39
  private cacheMaxSize;
40
- private version;
40
+ private _version;
41
+ /**
42
+ * Get the current version for cache invalidation
43
+ * Incremented whenever middleware or routes are modified
44
+ */
45
+ get version(): number;
41
46
  /**
42
47
  * Register a route
43
48
  *
@@ -96,6 +101,16 @@ export declare class AOTRouter {
96
101
  * @returns Combined middleware array
97
102
  */
98
103
  private collectMiddleware;
104
+ /**
105
+ * Get all static routes optimized for Bun's native router.
106
+ *
107
+ * Unlike basic offloading, this version supports routes with middleware
108
+ * by pre-compiling the middleware chain into a single native handler.
109
+ *
110
+ * @param onMatch - Factory to wrap handler and middleware into a Bun-compatible function
111
+ * @returns Record of path -> Handler (Bun-compatible)
112
+ */
113
+ getNativeRoutes(onMatch: (handler: Handler, middleware: Middleware[], path: string) => (req: Request) => Response | Promise<Response>): Record<string, any>;
99
114
  /**
100
115
  * Check if a path is static (no parameters or wildcards)
101
116
  */
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module @gravito/core/engine
8
8
  */
9
+ import { RequestScopeManager } from '../Container/RequestScopeManager';
9
10
  import type { FastRequest, FastContext as IFastContext } from './types';
10
11
  /**
11
12
  * Lazy-parsed request wrapper
@@ -23,6 +24,12 @@ declare class FastRequestImpl implements FastRequest {
23
24
  private _headers;
24
25
  private _cachedJson;
25
26
  private _jsonParsed;
27
+ private _cachedText;
28
+ private _textParsed;
29
+ private _cachedFormData;
30
+ private _formDataParsed;
31
+ private _cachedQueries;
32
+ private _cachedCookies;
26
33
  private _ctx;
27
34
  constructor(ctx: FastContext);
28
35
  /**
@@ -45,6 +52,7 @@ declare class FastRequestImpl implements FastRequest {
45
52
  queries(): Record<string, string | string[]>;
46
53
  header(name: string): string | undefined;
47
54
  headers(): Record<string, string>;
55
+ get cookies(): Record<string, string>;
48
56
  json<T = unknown>(): Promise<T>;
49
57
  text(): Promise<string>;
50
58
  formData(): Promise<FormData>;
@@ -60,6 +68,7 @@ export declare class FastContext implements IFastContext {
60
68
  readonly req: FastRequestImpl;
61
69
  private _headers;
62
70
  _isReleased: boolean;
71
+ private _requestScope;
63
72
  /**
64
73
  * Initialize context for a new request
65
74
  *
@@ -80,9 +89,18 @@ export declare class FastContext implements IFastContext {
80
89
  json<T>(data: T, status?: number): Response;
81
90
  text(text: string, status?: number): Response;
82
91
  html(html: string, status?: number): Response;
92
+ /**
93
+ * Escape HTML using Bun's SIMD-accelerated native implementation
94
+ */
95
+ escape(html: string): string;
83
96
  redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
84
97
  body(data: BodyInit | null, status?: number): Response;
85
- stream(stream: ReadableStream, status?: number): Response;
98
+ /**
99
+ * Send high-performance binary response (e.g. CBOR, Protobuf)
100
+ * Utilizing Bun's native ArrayBufferSink for zero-allocation construction.
101
+ */
102
+ binary(data: Uint8Array | ArrayBuffer, status?: number): Response;
103
+ stream(stream: any, status?: number): Response;
86
104
  notFound(message?: string): Response;
87
105
  forbidden(message?: string): Response;
88
106
  unauthorized(message?: string): Response;
@@ -90,10 +108,33 @@ export declare class FastContext implements IFastContext {
90
108
  forward(target: string, _options?: any): Promise<Response>;
91
109
  header(name: string): string | undefined;
92
110
  header(name: string, value: string): void;
111
+ /**
112
+ * Status code setter (no-op)
113
+ *
114
+ * Note: Since all response helpers accept a `status` parameter,
115
+ * this method is not actively used. Status should be set directly
116
+ * in the response helper call (e.g., `ctx.json({}, 201)`).
117
+ */
93
118
  status(_code: number): void;
94
119
  private _store;
95
120
  get<T>(key: string): T;
96
121
  set(key: string, value: any): void;
122
+ /**
123
+ * Get the request-scoped service manager for this request.
124
+ *
125
+ * @returns The RequestScopeManager for this request.
126
+ * @throws Error if called before init() or after reset().
127
+ */
128
+ requestScope(): RequestScopeManager;
129
+ /**
130
+ * Resolve a request-scoped service (convenience method).
131
+ *
132
+ * @template T - The service type.
133
+ * @param key - The service key for caching.
134
+ * @param factory - Factory function to create the service.
135
+ * @returns The cached or newly created service instance.
136
+ */
137
+ scoped<T>(key: string | symbol, factory: () => T): T;
97
138
  route: (name: string, params?: any, query?: any) => string;
98
139
  get native(): this;
99
140
  }
@@ -25,7 +25,6 @@ export declare class Gravito {
25
25
  staticRoutes: Map<string, RouteMetadata>;
26
26
  private isPureStaticApp;
27
27
  private compiledDynamicRoutes;
28
- private middlewareVersion;
29
28
  /**
30
29
  * Create a new Gravito instance
31
30
  *
@@ -34,10 +33,6 @@ export declare class Gravito {
34
33
  constructor(options?: EngineOptions);
35
34
  /**
36
35
  * 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
36
  */
42
37
  get(path: string, ...handlers: Handler[]): this;
43
38
  /**
@@ -53,7 +48,7 @@ export declare class Gravito {
53
48
  */
54
49
  delete(path: string, ...handlers: Handler[]): this;
55
50
  /**
56
- * Register a PDF route
51
+ * Register a PATCH route
57
52
  */
58
53
  patch(path: string, ...handlers: Handler[]): this;
59
54
  /**
@@ -95,15 +90,22 @@ export declare class Gravito {
95
90
  */
96
91
  warmup(paths: string[]): Promise<void>;
97
92
  /**
98
- * Handle an incoming request
93
+ * Generate Native Bun.serve Configuration
94
+ *
95
+ * Offloads static routes to Bun's SIMD-accelerated native router.
96
+ * Supports pre-compiled middleware chains for zero runtime lookup.
99
97
  */
100
- fetch: (request: Request) => Promise<Response>;
98
+ serveConfig(baseConfig?: Record<string, unknown>): Record<string, unknown>;
99
+ /**
100
+ * Optimize TLS Configuration for Bun 1.39+
101
+ */
102
+ private optimizeTLS;
101
103
  /**
102
- * Handle routes with middleware (async path)
104
+ * Handle an incoming request
103
105
  */
104
- private handleWithMiddleware;
106
+ fetch: (request: Request) => Promise<Response>;
105
107
  /**
106
- * Handle dynamic routes (Radix Tree lookup)
108
+ * Handle dynamic routes with Radix Tree
107
109
  */
108
110
  private handleDynamicRoute;
109
111
  /**
@@ -126,12 +128,4 @@ export declare class Gravito {
126
128
  * Add a route to the router
127
129
  */
128
130
  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
131
  }