@gravito/ripple 4.0.1 → 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 (209) 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 -1
  4. package/dist/core/src/Application.d.ts +41 -0
  5. package/dist/core/src/HookManager.d.ts +33 -189
  6. package/dist/core/src/PlanetCore.d.ts +25 -1
  7. package/dist/core/src/Router.d.ts +32 -46
  8. package/dist/core/src/adapters/bun/BunContext.d.ts +6 -1
  9. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
  10. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  11. package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
  12. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  13. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  14. package/dist/core/src/binary/index.d.ts +5 -0
  15. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  16. package/dist/core/src/compat/crypto.d.ts +6 -0
  17. package/dist/core/src/engine/AOTRouter.d.ts +10 -0
  18. package/dist/core/src/engine/FastContext.d.ts +19 -1
  19. package/dist/core/src/engine/Gravito.d.ts +13 -18
  20. package/dist/core/src/engine/MinimalContext.d.ts +2 -0
  21. package/dist/core/src/engine/analyzer.d.ts +92 -6
  22. package/dist/core/src/engine/types.d.ts +3 -0
  23. package/dist/core/src/events/EventPriorityQueue.d.ts +18 -256
  24. package/dist/core/src/events/index.d.ts +12 -11
  25. package/dist/core/src/events/queue-core.d.ts +77 -0
  26. package/dist/core/src/events/task-executor.d.ts +51 -0
  27. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  28. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  29. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  30. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  31. package/dist/core/src/ffi/index.d.ts +10 -0
  32. package/dist/core/src/ffi/types.d.ts +135 -0
  33. package/dist/core/src/helpers/Str.d.ts +15 -0
  34. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  35. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  36. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  37. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  38. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  39. package/dist/core/src/hooks/types.d.ts +107 -0
  40. package/dist/core/src/http/CookieJar.d.ts +2 -2
  41. package/dist/core/src/http/types.d.ts +24 -3
  42. package/dist/core/src/index.d.ts +491 -14
  43. package/dist/core/src/observability/contracts.d.ts +137 -0
  44. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +2 -3
  45. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  46. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  47. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  48. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  49. package/dist/core/src/runtime/archive.d.ts +17 -0
  50. package/dist/core/src/runtime/compression.d.ts +21 -0
  51. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  52. package/dist/core/src/runtime/detection.d.ts +22 -0
  53. package/dist/core/src/runtime/escape.d.ts +34 -0
  54. package/dist/core/src/runtime/index.d.ts +44 -0
  55. package/dist/core/src/runtime/markdown.d.ts +44 -0
  56. package/dist/core/src/runtime/types.d.ts +436 -0
  57. package/dist/core/src/runtime-helpers.d.ts +67 -0
  58. package/dist/core/src/runtime.d.ts +10 -118
  59. package/dist/core/src/testing/HttpTester.d.ts +1 -0
  60. package/dist/core/src/transpiler-utils.d.ts +170 -0
  61. package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
  62. package/dist/index.js +1 -7502
  63. package/dist/index.js.map +3 -71
  64. package/package.json +6 -2
  65. package/dist/atlas/src/DB.d.ts +0 -348
  66. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  67. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  68. package/dist/atlas/src/config/index.d.ts +0 -7
  69. package/dist/atlas/src/config/loadConfig.d.ts +0 -41
  70. package/dist/atlas/src/connection/Connection.d.ts +0 -112
  71. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -180
  72. package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +0 -54
  73. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  74. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  75. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  76. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -79
  77. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -96
  78. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  79. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  80. package/dist/atlas/src/drivers/types.d.ts +0 -260
  81. package/dist/atlas/src/errors/index.d.ts +0 -45
  82. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  83. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  84. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  85. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  86. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  87. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  88. package/dist/atlas/src/index.d.ts +0 -79
  89. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  90. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  91. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  92. package/dist/atlas/src/migration/index.d.ts +0 -6
  93. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -33
  94. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  95. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  96. package/dist/atlas/src/observability/index.d.ts +0 -9
  97. package/dist/atlas/src/orm/Repository.d.ts +0 -247
  98. package/dist/atlas/src/orm/index.d.ts +0 -6
  99. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  100. package/dist/atlas/src/orm/model/Model.d.ts +0 -458
  101. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  102. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -150
  103. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  104. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -92
  105. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  106. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  107. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  108. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  109. package/dist/atlas/src/orm/model/decorators.d.ts +0 -138
  110. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  111. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  112. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  113. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  114. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -124
  115. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  116. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  117. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  118. package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +0 -98
  119. package/dist/atlas/src/pool/PoolHealthChecker.d.ts +0 -91
  120. package/dist/atlas/src/pool/PoolStrategy.d.ts +0 -129
  121. package/dist/atlas/src/pool/PoolWarmer.d.ts +0 -92
  122. package/dist/atlas/src/query/Expression.d.ts +0 -60
  123. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  124. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -643
  125. package/dist/atlas/src/query/RelationshipResolver.d.ts +0 -23
  126. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  127. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  128. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  129. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  130. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  131. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  132. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  133. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  134. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  135. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  136. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  137. package/dist/atlas/src/schema/MigrationGenerator.d.ts +0 -45
  138. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  139. package/dist/atlas/src/schema/SchemaDiff.d.ts +0 -73
  140. package/dist/atlas/src/schema/TypeGenerator.d.ts +0 -57
  141. package/dist/atlas/src/schema/TypeWriter.d.ts +0 -42
  142. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  143. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  144. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  145. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  146. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  147. package/dist/atlas/src/schema/index.d.ts +0 -8
  148. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  149. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  150. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  151. package/dist/atlas/src/seed/index.d.ts +0 -6
  152. package/dist/atlas/src/sharding/ShardingManager.d.ts +0 -59
  153. package/dist/atlas/src/types/index.d.ts +0 -1182
  154. package/dist/atlas/src/utils/CursorEncoding.d.ts +0 -63
  155. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  156. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -175
  157. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  158. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  159. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  160. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  161. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  162. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  163. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  164. package/dist/core/src/instrumentation/index.d.ts +0 -35
  165. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  166. package/dist/core/src/instrumentation/types.d.ts +0 -182
  167. package/dist/core/src/observability/Metrics.d.ts +0 -244
  168. package/dist/photon/src/index.d.ts +0 -89
  169. package/dist/photon/src/middleware/binary.d.ts +0 -31
  170. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  171. package/dist/photon/src/middleware/ratelimit-redis.d.ts +0 -50
  172. package/dist/photon/src/middleware/ratelimit.d.ts +0 -161
  173. package/dist/photon/src/openapi.d.ts +0 -19
  174. /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
  175. /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
  176. /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
  177. /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
  178. /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
  179. /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
  180. /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
  181. /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
  182. /package/dist/{ripple/src/engines → engines}/UWebSocketsEngine.d.ts +0 -0
  183. /package/dist/{ripple/src/engines → engines}/WsEngine.d.ts +0 -0
  184. /package/dist/{ripple/src/engines → engines}/index.d.ts +0 -0
  185. /package/dist/{ripple/src/errors → errors}/RippleError.d.ts +0 -0
  186. /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
  187. /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
  188. /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
  189. /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
  190. /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
  191. /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
  192. /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
  193. /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
  194. /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
  195. /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
  196. /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
  197. /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
  198. /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
  199. /package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +0 -0
  200. /package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +0 -0
  201. /package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +0 -0
  202. /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
  203. /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
  204. /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
  205. /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
  206. /package/dist/{ripple/src/types.d.ts → types.d.ts} +0 -0
  207. /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
  208. /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
  209. /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.
@@ -7,7 +7,7 @@ import { BunRequest } from './BunRequest';
7
7
  */
8
8
  export declare class BunContext<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
9
9
  readonly env: Record<string, unknown>;
10
- readonly req: BunRequest;
10
+ req: BunRequest;
11
11
  private _variables;
12
12
  private _requestScope;
13
13
  /**
@@ -40,6 +40,11 @@ export declare class BunContext<V extends GravitoVariables = GravitoVariables> i
40
40
  append?: boolean;
41
41
  }): void;
42
42
  header(name: string): string | undefined;
43
+ /**
44
+ * Reset context state for reuse in pooling scenarios
45
+ * @internal
46
+ */
47
+ reset(request: Request): void;
43
48
  status(code: StatusCode): void;
44
49
  get<K extends keyof V>(key: K): V[K];
45
50
  set<K extends keyof V>(key: K, value: V[K]): void;
@@ -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,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;
@@ -101,6 +101,16 @@ export declare class AOTRouter {
101
101
  * @returns Combined middleware array
102
102
  */
103
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>;
104
114
  /**
105
115
  * Check if a path is static (no parameters or wildcards)
106
116
  */
@@ -29,6 +29,7 @@ declare class FastRequestImpl implements FastRequest {
29
29
  private _cachedFormData;
30
30
  private _formDataParsed;
31
31
  private _cachedQueries;
32
+ private _cachedCookies;
32
33
  private _ctx;
33
34
  constructor(ctx: FastContext);
34
35
  /**
@@ -51,6 +52,7 @@ declare class FastRequestImpl implements FastRequest {
51
52
  queries(): Record<string, string | string[]>;
52
53
  header(name: string): string | undefined;
53
54
  headers(): Record<string, string>;
55
+ get cookies(): Record<string, string>;
54
56
  json<T = unknown>(): Promise<T>;
55
57
  text(): Promise<string>;
56
58
  formData(): Promise<FormData>;
@@ -87,9 +89,18 @@ export declare class FastContext implements IFastContext {
87
89
  json<T>(data: T, status?: number): Response;
88
90
  text(text: string, status?: number): Response;
89
91
  html(html: string, status?: number): Response;
92
+ /**
93
+ * Escape HTML using Bun's SIMD-accelerated native implementation
94
+ */
95
+ escape(html: string): string;
90
96
  redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
91
97
  body(data: BodyInit | null, status?: number): Response;
92
- 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;
93
104
  notFound(message?: string): Response;
94
105
  forbidden(message?: string): Response;
95
106
  unauthorized(message?: string): Response;
@@ -97,6 +108,13 @@ export declare class FastContext implements IFastContext {
97
108
  forward(target: string, _options?: any): Promise<Response>;
98
109
  header(name: string): string | undefined;
99
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
+ */
100
118
  status(_code: number): void;
101
119
  private _store;
102
120
  get<T>(key: string): T;
@@ -33,10 +33,6 @@ export declare class Gravito {
33
33
  constructor(options?: EngineOptions);
34
34
  /**
35
35
  * Register a GET route
36
- *
37
- * @param path - Route path (e.g., '/users/:id')
38
- * @param handlers - Handler and optional middleware
39
- * @returns This instance for chaining
40
36
  */
41
37
  get(path: string, ...handlers: Handler[]): this;
42
38
  /**
@@ -52,7 +48,7 @@ export declare class Gravito {
52
48
  */
53
49
  delete(path: string, ...handlers: Handler[]): this;
54
50
  /**
55
- * Register a PDF route
51
+ * Register a PATCH route
56
52
  */
57
53
  patch(path: string, ...handlers: Handler[]): this;
58
54
  /**
@@ -94,15 +90,22 @@ export declare class Gravito {
94
90
  */
95
91
  warmup(paths: string[]): Promise<void>;
96
92
  /**
97
- * 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.
98
97
  */
99
- 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;
100
103
  /**
101
- * Handle routes with middleware (async path)
104
+ * Handle an incoming request
102
105
  */
103
- private handleWithMiddleware;
106
+ fetch: (request: Request) => Promise<Response>;
104
107
  /**
105
- * Handle dynamic routes (Radix Tree lookup)
108
+ * Handle dynamic routes with Radix Tree
106
109
  */
107
110
  private handleDynamicRoute;
108
111
  /**
@@ -125,12 +128,4 @@ export declare class Gravito {
125
128
  * Add a route to the router
126
129
  */
127
130
  private addRoute;
128
- /**
129
- * Execute middleware chain followed by handler
130
- */
131
- private executeMiddleware;
132
- /**
133
- * Handle errors (Async version for dynamic/middleware paths)
134
- */
135
- private handleError;
136
131
  }
@@ -44,6 +44,7 @@ declare class MinimalRequest implements FastRequest {
44
44
  json<T = unknown>(): Promise<T>;
45
45
  text(): Promise<string>;
46
46
  formData(): Promise<FormData>;
47
+ get cookies(): Record<string, string>;
47
48
  get raw(): Request;
48
49
  }
49
50
  /**
@@ -75,6 +76,7 @@ export declare class MinimalContext implements IFastContext {
75
76
  unauthorized(message?: string): Response;
76
77
  badRequest(message?: string): Response;
77
78
  forward(target: string, _options?: any): Promise<Response>;
79
+ escape(html: string): string;
78
80
  get<T>(_key: string): T;
79
81
  set(_key: string, _value: any): void;
80
82
  /**
@@ -1,27 +1,113 @@
1
1
  /**
2
- * Handler Static Analyzer (Elysia-inspired)
2
+ * @fileoverview Handler 靜態分析器(Elysia-inspired,升級版)
3
3
  *
4
- * Analyzes handler functions to determine what request properties
5
- * they access, allowing for optimized code paths.
4
+ * 分析 handler 函式,偵測其存取了哪些請求屬性,
5
+ * 以選擇最優化的 Context 類型(minimal/fast/full)。
6
+ *
7
+ * ## 版本歷史
8
+ *
9
+ * ### v2(目前版本)- 使用 Bun.Transpiler
10
+ * - 精確度:~99%(AST 層級分析)
11
+ * - 正確處理假陽性:`const header = '...'` 不再誤判
12
+ * - 支援解構賦值:`const { header } = ctx.req`
13
+ * - 支援 Minified 代碼(transformSync 先標準化)
14
+ * - Fallback:若 Transpiler 失敗,退回字串匹配
15
+ *
16
+ * ### v1(原版本)- 字串匹配
17
+ * - 精確度:~85%
18
+ * - 假陽性:變數名稱包含目標字串會誤判
19
+ * - 假陰性:解構賦值無法偵測
20
+ * - Minified 代碼可能失效
21
+ *
22
+ * @module @gravito/core/engine/analyzer
23
+ * @since 3.0.0
6
24
  */
7
25
  /**
8
- * Represents the results of a static analysis performed on a handler function.
26
+ * Handler 靜態分析結果
27
+ *
28
+ * 記錄 handler 函式使用了哪些請求屬性,
29
+ * 用於選擇最優化的 Context 類型。
9
30
  *
10
31
  * @public
11
32
  * @since 3.0.0
12
33
  */
13
34
  export interface HandlerAnalysis {
35
+ /** 是否存取了 request headers */
14
36
  usesHeaders: boolean;
37
+ /** 是否存取了 query string 參數 */
15
38
  usesQuery: boolean;
39
+ /** 是否存取了 request body */
16
40
  usesBody: boolean;
41
+ /** 是否存取了 route 路徑參數 */
17
42
  usesParams: boolean;
43
+ /** 是否為非同步函式(含 async/await) */
18
44
  isAsync: boolean;
19
45
  }
20
46
  /**
21
- * Analyze a handler function to detect what it accesses
47
+ * 分析 handler 函式,偵測其使用了哪些請求屬性
48
+ *
49
+ * 使用 Bun.Transpiler 進行 AST 層級的精確分析(精確度 ~99%)。
50
+ * 若 Transpiler 不可用,自動 fallback 到字串匹配(精確度 ~85%)。
51
+ *
52
+ * ## 精確度提升說明
53
+ *
54
+ * **假陽性修復**(原本誤判,現在正確):
55
+ * ```typescript
56
+ * // 這個 handler 原本會誤判 usesHeaders = true
57
+ * // 因為字串 'header' 出現在變數名稱中
58
+ * function handler(ctx) {
59
+ * const header = 'Content-Type' // ← 變數名稱,不是 API 呼叫
60
+ * return ctx.json({ header })
61
+ * }
62
+ * // 現在:usesHeaders = false ✅
63
+ * ```
64
+ *
65
+ * **假陰性修復**(原本漏偵測,現在正確):
66
+ * ```typescript
67
+ * // 這個 handler 原本會漏偵測解構賦值
68
+ * function handler(ctx) {
69
+ * const { header, query } = ctx.req // ← 解構賦值
70
+ * return ctx.json({ header })
71
+ * }
72
+ * // 現在:usesHeaders = true, usesQuery = true ✅
73
+ * ```
74
+ *
75
+ * @param handler - 要分析的 handler 函式
76
+ * @returns HandlerAnalysis 分析結果
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const handler = async (ctx) => {
81
+ * const name = ctx.req.query('name')
82
+ * return ctx.json({ name })
83
+ * }
84
+ *
85
+ * const analysis = analyzeHandler(handler)
86
+ * // analysis.usesQuery === true
87
+ * // analysis.usesHeaders === false
88
+ * // analysis.isAsync === true
89
+ *
90
+ * const type = getOptimalContextType(analysis)
91
+ * // type === 'fast'
92
+ * ```
22
93
  */
23
94
  export declare function analyzeHandler(handler: Function): HandlerAnalysis;
24
95
  /**
25
- * Determine optimal context type based on analysis
96
+ * 根據分析結果決定最優化的 Context 類型
97
+ *
98
+ * Context 類型由輕到重:
99
+ * - `minimal`:僅支援路徑參數與靜態回應,零 overhead
100
+ * - `fast`:支援 headers 與 query,使用物件池
101
+ * - `full`:支援完整功能含 body 解析(async)
102
+ *
103
+ * 選擇邏輯(優先順序):
104
+ * 1. 若存取 headers → `fast`(header 設置需要完整支援)
105
+ * 2. 若不存取任何屬性 → `minimal`
106
+ * 3. 若僅存取 params → `minimal`(params 在 minimal 中也可用)
107
+ * 4. 若存取 body → `full`(async body 解析需要完整 context)
108
+ * 5. 其他 → `fast`
109
+ *
110
+ * @param analysis - HandlerAnalysis 分析結果
111
+ * @returns 最優化的 context 類型
26
112
  */
27
113
  export declare function getOptimalContextType(analysis: HandlerAnalysis): 'minimal' | 'fast' | 'full';
@@ -25,6 +25,7 @@ export interface FastContext {
25
25
  unauthorized(message?: string): Response;
26
26
  badRequest(message?: string): Response;
27
27
  forward(target: string, options?: any): Promise<Response>;
28
+ escape(html: string): string;
28
29
  /** Header management */
29
30
  header(name: string): string | undefined;
30
31
  header(name: string, value: string): void;
@@ -70,6 +71,8 @@ export interface FastRequest {
70
71
  header(name: string): string | undefined;
71
72
  /** Get all headers */
72
73
  headers(): Record<string, string>;
74
+ /** Get all cookies (Native Bun 1.39+ / Lazy Parsed) */
75
+ readonly cookies: Record<string, string>;
73
76
  /** Parse JSON body */
74
77
  json<T = unknown>(): Promise<T>;
75
78
  /** Parse text body */