@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,84 @@
1
+ /**
2
+ * @gravito/photon - High-performance web engine for the Gravito Galaxy Architecture.
3
+ *
4
+ * Photon serves as the foundational HTTP layer for Gravito, providing an ultra-fast,
5
+ * type-safe routing system based on Hono. It is designed to be the "light" that
6
+ * connects Satellites (domain plugins) and Orbits (infrastructure) within the ecosystem.
7
+ *
8
+ * Key features:
9
+ * - Zero-overhead routing and middleware.
10
+ * - Full TypeScript inference for request parameters and body.
11
+ * - Built-in support for HTMX and binary (CBOR) protocols.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { Photon } from '@gravito/photon'
16
+ *
17
+ * const app = new Photon()
18
+ *
19
+ * app.get('/welcome', (c) => c.text('Welcome to the Galaxy!'))
20
+ *
21
+ * export default app
22
+ * ```
23
+ * @packageDocumentation
24
+ */
25
+ export * from 'hono';
26
+ /**
27
+ * The primary application class for Photon.
28
+ *
29
+ * An alias for `Hono`, providing the core routing and middleware capabilities.
30
+ * Use this to define your API structure and mount domain-specific Satellites.
31
+ *
32
+ * @remarks
33
+ * Photon extends Hono's capabilities with Gravito-specific optimizations.
34
+ * It serves as the entry point for defining routes, applying middleware,
35
+ * and handling the request-response lifecycle.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const app = new Photon()
40
+ *
41
+ * // Basic routing
42
+ * app.get('/api/health', (c) => c.json({ status: 'ok' }))
43
+ *
44
+ * // Middleware integration
45
+ * app.use('/api/*', myMiddleware)
46
+ *
47
+ * // Mounting sub-routers
48
+ * app.route('/v1', v1Router)
49
+ * ```
50
+ * @public
51
+ */
52
+ export { Hono as Photon } from 'hono';
53
+ /**
54
+ * Binary-related middleware for Photon.
55
+ *
56
+ * Provides utilities for handling binary data formats like CBOR,
57
+ * optimizing payload size and serialization speed for high-performance APIs.
58
+ *
59
+ * @public
60
+ */
61
+ export * from './middleware/binary';
62
+ /**
63
+ * HTMX-related middleware for Photon.
64
+ *
65
+ * Enhances Photon with first-class support for HTMX, including
66
+ * automatic request detection and simplified header access for hypermedia-driven UIs.
67
+ *
68
+ * @public
69
+ */
70
+ export * from './middleware/htmx';
71
+ /**
72
+ * Rate limiting middleware for Photon.
73
+ *
74
+ * Provides built-in rate limiting with token bucket and sliding window strategies.
75
+ * Supports both memory-based and custom storage backends.
76
+ *
77
+ * @public
78
+ */
79
+ export * from './middleware/ratelimit';
80
+ /**
81
+ * OpenAPI utilities
82
+ * @public
83
+ */
84
+ export * from './openapi';
@@ -0,0 +1,31 @@
1
+ import type { MiddlewareHandler } from 'hono';
2
+ /**
3
+ * Binary Middleware for Photon.
4
+ *
5
+ * Automatically detects 'Accept: application/cbor' and encodes
6
+ * JSON responses using the CBOR binary format for high-performance communication.
7
+ *
8
+ * @remarks
9
+ * This middleware is essential for high-frequency API calls where payload size
10
+ * and serialization speed are critical. It leverages the `cborg` library for
11
+ * efficient binary encoding.
12
+ *
13
+ * @returns A Hono middleware handler that intercepts JSON responses.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Photon } from '@gravito/photon'
18
+ * import { binaryMiddleware } from '@gravito/photon/middleware/binary'
19
+ *
20
+ * const app = new Photon()
21
+ * app.use(binaryMiddleware())
22
+ *
23
+ * app.get('/api/data', (c) => c.json({ items: [1, 2, 3] }))
24
+ * ```
25
+ *
26
+ * @performance
27
+ * - CBOR encoding is ~2-3x faster than JSON.stringify for large objects.
28
+ * - Binary format reduces payload size by 20-40% on average.
29
+ * - Optimized to read body directly without clone(), saving ~30% overhead.
30
+ */
31
+ export declare const binaryMiddleware: () => MiddlewareHandler;
@@ -0,0 +1,39 @@
1
+ import type { MiddlewareHandler } from 'hono';
2
+ /**
3
+ * HTMX Middleware for Photon.
4
+ *
5
+ * Automatically detects HTMX requests and populates the context with
6
+ * HTMX-specific headers and state.
7
+ *
8
+ * @remarks
9
+ * This middleware enables hypermedia-driven UIs by providing first-class
10
+ * support for HTMX. It allows handlers to easily distinguish between
11
+ * full-page loads and partial updates.
12
+ *
13
+ * @returns A Hono middleware handler that populates HTMX context variables.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Photon } from '@gravito/photon'
18
+ * import { htmxMiddleware } from '@gravito/photon/middleware/htmx'
19
+ *
20
+ * const app = new Photon()
21
+ * app.use(htmxMiddleware())
22
+ *
23
+ * app.get('/search', async (c) => {
24
+ * // Check if request is from HTMX
25
+ * if (c.get('htmx')) {
26
+ * return c.html('<div>Search results...</div>')
27
+ * }
28
+ *
29
+ * return c.html('<html>...</html>')
30
+ * })
31
+ * ```
32
+ *
33
+ * @context_variables
34
+ * - `htmx`: Boolean indicating if the request is an HTMX request.
35
+ * - `htmx.boosted`: Boolean indicating if the request was boosted.
36
+ * - `htmx.target`: The ID of the target element.
37
+ * - `htmx.trigger`: The ID of the trigger element.
38
+ */
39
+ export declare const htmxMiddleware: () => MiddlewareHandler;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * @fileoverview Rate Limiting Middleware for Photon
3
+ *
4
+ * Provides token bucket and sliding window rate limiting strategies.
5
+ * Supports memory-based and Redis-based storage backends.
6
+ *
7
+ * @module @gravito/photon/middleware/ratelimit
8
+ * @since 1.0.0
9
+ */
10
+ import type { Context, MiddlewareHandler } from '@gravito/photon';
11
+ export interface RateLimitConfig {
12
+ /**
13
+ * Maximum number of requests allowed within the time window
14
+ * @default 100
15
+ */
16
+ maxRequests: number;
17
+ /**
18
+ * Time window in milliseconds
19
+ * @default 60000 (1 minute)
20
+ */
21
+ windowMs: number;
22
+ /**
23
+ * Strategy for rate limiting
24
+ * - 'token-bucket': Smooth rate limiting with token refill
25
+ * - 'sliding-window': Time-based window that slides continuously
26
+ * @default 'token-bucket'
27
+ */
28
+ strategy?: 'token-bucket' | 'sliding-window';
29
+ /**
30
+ * Custom key generator function
31
+ * @default (c) => c.req.header('x-forwarded-for') || c.req.header('x-real-ip') || 'unknown'
32
+ */
33
+ keyGenerator?: (c: Context) => string | Promise<string>;
34
+ /**
35
+ * Storage backend for rate limit state
36
+ * @default new MemoryStore()
37
+ */
38
+ store?: RateLimitStore;
39
+ /**
40
+ * Custom handler for rate-limited requests
41
+ * @default (c) => c.json({ error: 'Too Many Requests', retryAfter: <seconds> }, 429)
42
+ */
43
+ onRateLimitExceeded?: (c: Context, retryAfter: number) => Response | Promise<Response>;
44
+ /**
45
+ * Skip rate limiting for certain requests
46
+ * @default undefined
47
+ */
48
+ skip?: (c: Context) => boolean | Promise<boolean>;
49
+ /**
50
+ * Custom headers to include in responses
51
+ * @default true
52
+ */
53
+ standardHeaders?: boolean;
54
+ /**
55
+ * Include draft RateLimit headers (RateLimit-*)
56
+ * @default false
57
+ */
58
+ draftHeaders?: boolean;
59
+ }
60
+ export interface RateLimitStore {
61
+ /**
62
+ * Increment request count and return current state
63
+ */
64
+ increment(key: string): Promise<RateLimitState>;
65
+ /**
66
+ * Reset the rate limit for a key
67
+ */
68
+ reset(key: string): Promise<void>;
69
+ /**
70
+ * Get current state without incrementing
71
+ */
72
+ get(key: string): Promise<RateLimitState | null>;
73
+ }
74
+ export interface RateLimitState {
75
+ /**
76
+ * Number of requests made in current window
77
+ */
78
+ count: number;
79
+ /**
80
+ * Timestamp when the window expires (ms)
81
+ */
82
+ resetTime: number;
83
+ /**
84
+ * Remaining requests allowed
85
+ */
86
+ remaining: number;
87
+ }
88
+ export declare class MemoryStore implements RateLimitStore {
89
+ private config;
90
+ private store;
91
+ private cleanupInterval;
92
+ constructor(config: {
93
+ maxRequests: number;
94
+ windowMs: number;
95
+ }, cleanupIntervalMs?: number);
96
+ increment(key: string): Promise<RateLimitState>;
97
+ reset(key: string): Promise<void>;
98
+ get(key: string): Promise<RateLimitState | null>;
99
+ /**
100
+ * Cleanup resources
101
+ */
102
+ destroy(): void;
103
+ }
104
+ /**
105
+ * Create a rate limiting middleware
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * import { Photon } from '@gravito/photon'
110
+ * import { rateLimit } from '@gravito/photon/middleware'
111
+ *
112
+ * const app = new Photon()
113
+ *
114
+ * // Basic usage: 100 requests per minute
115
+ * app.use('*', rateLimit({ maxRequests: 100, windowMs: 60000 }))
116
+ *
117
+ * // Per-user rate limiting
118
+ * app.use('/api/*', rateLimit({
119
+ * maxRequests: 50,
120
+ * windowMs: 60000,
121
+ * keyGenerator: (c) => {
122
+ * const userId = c.get('userId')
123
+ * return userId || c.req.header('x-forwarded-for') || 'anonymous'
124
+ * }
125
+ * }))
126
+ * ```
127
+ */
128
+ export declare function rateLimit(config: RateLimitConfig): MiddlewareHandler;
129
+ /**
130
+ * Convenience factory: Create rate limiter with common presets
131
+ */
132
+ export declare const createRateLimiter: {
133
+ /**
134
+ * Strict: 10 requests per minute
135
+ */
136
+ strict: (overrides?: Partial<RateLimitConfig>) => MiddlewareHandler;
137
+ /**
138
+ * Moderate: 60 requests per minute
139
+ */
140
+ moderate: (overrides?: Partial<RateLimitConfig>) => MiddlewareHandler;
141
+ /**
142
+ * Lenient: 100 requests per minute
143
+ */
144
+ lenient: (overrides?: Partial<RateLimitConfig>) => MiddlewareHandler;
145
+ /**
146
+ * API: 1000 requests per hour
147
+ */
148
+ api: (overrides?: Partial<RateLimitConfig>) => MiddlewareHandler;
149
+ /**
150
+ * Auth: 5 attempts per 15 minutes (for login endpoints)
151
+ */
152
+ auth: (overrides?: Partial<RateLimitConfig>) => MiddlewareHandler;
153
+ };
154
+ /**
155
+ * Export convenience preset
156
+ */
157
+ export { createRateLimiter as rateLimiter };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file packages/photon/src/openapi.ts
3
+ * @module @gravito/photon/openapi
4
+ * @description OpenAPI (Swagger) integration for Photon
5
+ */
6
+ import type { RouteConfig } from '@hono/zod-openapi';
7
+ import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
8
+ import { z } from 'zod';
9
+ /**
10
+ * Photon Open API Class
11
+ * Extends OpenAPIHono to provide a seamless OpenAPI integration.
12
+ */
13
+ export declare class PhotonOpenAPI extends OpenAPIHono {
14
+ /**
15
+ * Helper to create a fully typed route definition.
16
+ */
17
+ static route(config: RouteConfig): RouteConfig;
18
+ }
19
+ export { createRoute, z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/echo",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Enterprise-grade webhook handling for Gravito. Secure receiving and reliable sending.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -19,10 +19,12 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "build": "bun run build.ts",
22
- "test": "bun test",
22
+ "test": "bun test --timeout=10000",
23
+ "test:unit": "bun test tests/unit",
24
+ "test:integration": "test $(find tests -name '*.integration.test.ts' 2>/dev/null | wc -l) -gt 0 && find tests -name '*.integration.test.ts' -print0 | xargs -0 bun test --timeout=10000 || echo 'No integration tests found'",
23
25
  "typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
24
- "test:coverage": "bun test --coverage --coverage-threshold=80",
25
- "test:ci": "bun test --coverage --coverage-threshold=80"
26
+ "test:coverage": "bun test --timeout=10000 --coverage --coverage-reporter=lcov --coverage-dir coverage && bun run --bun scripts/check-coverage.ts",
27
+ "test:ci": "bun test --timeout=10000 --coverage --coverage-reporter=lcov --coverage-dir coverage && bun run --bun scripts/check-coverage.ts"
26
28
  },
27
29
  "keywords": [
28
30
  "gravito",
@@ -50,4 +52,4 @@
50
52
  "publishConfig": {
51
53
  "access": "public"
52
54
  }
53
- }
55
+ }