@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,156 @@
1
+ import type { ConfigManager } from './ConfigManager';
2
+ import type { Container } from './Container';
3
+ import type { PlanetCore } from './PlanetCore';
4
+ /**
5
+ * ServiceProvider - The foundation for modular service registration.
6
+ *
7
+ * Service providers are the central place to configure your application.
8
+ * They bind services to the container and bootstrap application features.
9
+ *
10
+ * Lifecycle:
11
+ * 1. register() - Called during registration phase (sync or async)
12
+ * 2. boot() - Called after ALL providers have registered
13
+ *
14
+ * @since 1.0.0
15
+ * @example
16
+ * ```typescript
17
+ * class DatabaseServiceProvider extends ServiceProvider {
18
+ * register(container: Container) {
19
+ * container.singleton('db', () => new DatabaseManager());
20
+ * }
21
+ *
22
+ * boot(core: PlanetCore) {
23
+ * const db = core.container.make<DatabaseManager>('db');
24
+ * db.setDefaultConnection(core.config.get('database.default'));
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ export declare abstract class ServiceProvider {
30
+ /**
31
+ * Reference to the application core instance.
32
+ * Set during provider registration.
33
+ */
34
+ protected core?: PlanetCore;
35
+ /**
36
+ * Whether this provider should be deferred.
37
+ * Deferred providers are only registered when one of their
38
+ * provided services is actually requested from the container.
39
+ */
40
+ deferred: boolean;
41
+ /**
42
+ * Get the services provided by this provider.
43
+ * Used for deferred loading - provider is only loaded when
44
+ * one of these services is requested.
45
+ *
46
+ * @returns Array of service keys this provider offers
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * provides(): string[] {
51
+ * return ['db', 'db.connection'];
52
+ * }
53
+ * ```
54
+ */
55
+ provides(): string[];
56
+ /**
57
+ * Register bindings in the container.
58
+ *
59
+ * This method is called during the registration phase.
60
+ * **Warning**: Do not resolve services from other providers here,
61
+ * as they may not be registered yet.
62
+ *
63
+ * Supports both synchronous and asynchronous registration.
64
+ *
65
+ * @param container - The IoC container instance
66
+ */
67
+ abstract register(container: Container): void | Promise<void>;
68
+ /**
69
+ * Bootstrap any application services.
70
+ *
71
+ * This method is called after ALL providers have registered.
72
+ * You can safely resolve services from the container here.
73
+ *
74
+ * @param core - The PlanetCore application instance
75
+ */
76
+ boot?(core: PlanetCore): void | Promise<void>;
77
+ /**
78
+ * Set the core instance reference.
79
+ * Called internally by the application during registration.
80
+ *
81
+ * @internal
82
+ */
83
+ setCore(core: PlanetCore): void;
84
+ /**
85
+ * Merge configuration from a value into the application config.
86
+ *
87
+ * If the configuration key already exists and both the existing value and
88
+ * the new value are objects, they will be shallow-merged. Otherwise, the
89
+ * new value will overwrite the existing one.
90
+ *
91
+ * @param config - The ConfigManager instance.
92
+ * @param key - The configuration key to set (supports dot notation).
93
+ * @param value - The configuration value or object to merge.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * this.mergeConfig(config, 'database', {
98
+ * default: 'mysql',
99
+ * connections: { ... }
100
+ * });
101
+ * ```
102
+ */
103
+ protected mergeConfig(config: ConfigManager, key: string, value: unknown): void;
104
+ /**
105
+ * Merge configuration from an async loader.
106
+ * Useful for loading config from .ts files dynamically.
107
+ *
108
+ * @param config - The ConfigManager instance
109
+ * @param key - The configuration key
110
+ * @param loader - Async function that returns config value
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * await this.mergeConfigFrom(config, 'database', async () => {
115
+ * return (await import('./config/database')).default;
116
+ * });
117
+ * ```
118
+ */
119
+ protected mergeConfigFrom(config: ConfigManager, key: string, loader: () => Promise<unknown>): Promise<void>;
120
+ /**
121
+ * Paths that should be published by the CLI.
122
+ * Maps source paths to destination paths.
123
+ */
124
+ private static publishables;
125
+ /**
126
+ * Register paths to be published by the CLI.
127
+ *
128
+ * Used by CLI commands like `gravito vendor:publish` to copy configuration,
129
+ * views, or assets from the package to the application directory.
130
+ *
131
+ * @param paths - A record mapping source paths to destination paths.
132
+ * @param group - Optional group name for selective publishing (e.g., 'config', 'views').
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * this.publishes({
137
+ * './config/cache.ts': 'config/cache.ts',
138
+ * './views/errors': 'resources/views/errors'
139
+ * }, 'config');
140
+ * ```
141
+ */
142
+ protected publishes(paths: Record<string, string>, group?: string): void;
143
+ /**
144
+ * Get all publishable paths for a group.
145
+ *
146
+ * @param group - The group name (defaults to provider class name)
147
+ * @returns Map of source to destination paths
148
+ */
149
+ static getPublishables(group?: string): Map<string, string>;
150
+ /**
151
+ * Get all publish groups.
152
+ *
153
+ * @returns Array of group names
154
+ */
155
+ static getPublishGroups(): string[];
156
+ }
@@ -0,0 +1,27 @@
1
+ import { Gravito } from '../engine/Gravito';
2
+ import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, GravitoVariables, HttpMethod } from '../http/types';
3
+ import type { AdapterConfig, HttpAdapter, RouteDefinition } from './types';
4
+ /**
5
+ * GravitoEngineAdapter - Optimized adapter using the Standalone Gravito Engine
6
+ *
7
+ * This adapter is exclusively for Bun and provides the best performance
8
+ * by using the specialized Gravito engine with object pooling and AOT routing.
9
+ */
10
+ export declare class GravitoEngineAdapter<V extends GravitoVariables = GravitoVariables> implements HttpAdapter<V> {
11
+ readonly name = "gravito-engine";
12
+ readonly version = "1.0.0";
13
+ private engine;
14
+ constructor(config?: AdapterConfig);
15
+ get native(): Gravito;
16
+ route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
17
+ routes(routes: RouteDefinition[]): void;
18
+ use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
19
+ useGlobal(...middleware: GravitoMiddleware<V>[]): void;
20
+ mount(path: string, subAdapter: HttpAdapter<V>): void;
21
+ onError(handler: GravitoErrorHandler<V>): void;
22
+ onNotFound(handler: GravitoNotFoundHandler<V>): void;
23
+ fetch: (request: Request, _server?: unknown) => Response | Promise<Response>;
24
+ warmup(paths: string[]): Promise<void>;
25
+ createContext(_request: Request): GravitoContext<V>;
26
+ useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
27
+ }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @fileoverview Photon Adapter Implementation
3
+ *
4
+ * This adapter wraps Photon to implement the Gravito HttpAdapter interface.
5
+ * It serves as the default adapter and reference implementation for others.
6
+ *
7
+ * @module @gravito/core/adapters/photon
8
+ * @since 2.0.0
9
+ */
10
+ import type { Context, Handler, MiddlewareHandler, Photon } from '@gravito/photon';
11
+ import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, GravitoRequest, GravitoVariables, HttpMethod, ProxyOptions, StatusCode } from '../http/types';
12
+ import type { AdapterConfig, HttpAdapter, RouteDefinition } from './types';
13
+ /**
14
+ * Wraps Photon's request object to implement GravitoRequest
15
+ */
16
+ declare class PhotonRequestWrapper implements GravitoRequest {
17
+ photonCtx: Context;
18
+ /**
19
+ * Reset the wrapper for pooling
20
+ */
21
+ reset(photonCtx: Context): void;
22
+ /**
23
+ * Create a proxied instance to delegate to Photon's request
24
+ */
25
+ static create(photonCtx: Context): PhotonRequestWrapper;
26
+ /**
27
+ * Internal proxy wrapper
28
+ */
29
+ static wrap(instance: PhotonRequestWrapper): PhotonRequestWrapper;
30
+ get url(): string;
31
+ get method(): string;
32
+ get path(): string;
33
+ param(name: string): string | undefined;
34
+ params(): Record<string, string>;
35
+ query(name: string): string | undefined;
36
+ queries(): Record<string, string | string[]>;
37
+ header(name: string): string | undefined;
38
+ header(): Record<string, string>;
39
+ json<T = unknown>(): Promise<T>;
40
+ text(): Promise<string>;
41
+ formData(): Promise<FormData>;
42
+ arrayBuffer(): Promise<ArrayBuffer>;
43
+ parseBody<T = unknown>(): Promise<T>;
44
+ get raw(): Request;
45
+ valid<T = unknown>(target: string): T;
46
+ }
47
+ /**
48
+ * Wraps Photon's context to implement GravitoContext
49
+ */
50
+ declare class PhotonContextWrapper<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
51
+ private _req;
52
+ private photonCtx;
53
+ route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
54
+ /**
55
+ * Reset the wrapper for pooling
56
+ */
57
+ reset(photonCtx: Context): void;
58
+ /**
59
+ * Create a proxied instance to enable object destructuring of context variables
60
+ */
61
+ static create<V extends GravitoVariables = GravitoVariables>(photonCtx: Context): GravitoContext<V>;
62
+ /**
63
+ * Internal proxy wrapper
64
+ */
65
+ static wrap<V extends GravitoVariables = GravitoVariables>(instance: PhotonContextWrapper<V>): GravitoContext<V>;
66
+ get req(): GravitoRequest;
67
+ get params(): Record<string, string>;
68
+ get query(): Record<string, string | string[]>;
69
+ get data(): unknown;
70
+ set data(value: unknown);
71
+ back(status?: 301 | 302 | 303 | 307 | 308): Response;
72
+ json<T>(data: T, status?: number): Response;
73
+ text(text: string, status?: number): Response;
74
+ html(html: string, status?: number): Response;
75
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
76
+ body(data: BodyInit | null, status?: number): Response;
77
+ stream(stream: ReadableStream, status?: number): Response;
78
+ notFound(message?: string): Response;
79
+ forbidden(message?: string): Response;
80
+ unauthorized(message?: string): Response;
81
+ badRequest(message?: string): Response;
82
+ header(name: string): string | undefined;
83
+ header(name: string, value: string, options?: {
84
+ append?: boolean;
85
+ }): void;
86
+ status(code: StatusCode): void;
87
+ get<K extends keyof V>(key: K): V[K];
88
+ set<K extends keyof V>(key: K, value: V[K]): void;
89
+ get executionCtx(): ExecutionContext | undefined;
90
+ get env(): Record<string, unknown> | undefined;
91
+ get native(): Context;
92
+ forward(target: string, options?: ProxyOptions): Promise<Response>;
93
+ }
94
+ /**
95
+ * Convert a GravitoHandler to a Photon Handler
96
+ */
97
+ declare function toPhotonHandler<V extends GravitoVariables>(handler: GravitoHandler<V>): Handler;
98
+ /**
99
+ * Convert a GravitoMiddleware to a Photon MiddlewareHandler
100
+ */
101
+ declare function toPhotonMiddleware<V extends GravitoVariables>(middleware: GravitoMiddleware<V>): MiddlewareHandler;
102
+ /**
103
+ * Default HTTP adapter using the optimized Gravito Core Engine.
104
+ *
105
+ * This adapter provides a consistent interface that can be
106
+ * swapped out for other implementations without changing application code.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * import { GravitoAdapter } from '@gravito/core'
111
+ *
112
+ * const adapter = new GravitoAdapter()
113
+ *
114
+ * // Register routes
115
+ * adapter.route('get', '/hello', async (ctx) => {
116
+ * return ctx.json({ message: 'Hello, World!' })
117
+ * })
118
+ * ```
119
+ */
120
+ export declare class PhotonAdapter<V extends GravitoVariables = GravitoVariables> implements HttpAdapter<V> {
121
+ private config;
122
+ readonly name = "photon";
123
+ readonly version = "1.0.0";
124
+ private app;
125
+ constructor(config?: AdapterConfig, photonInstance?: unknown);
126
+ /**
127
+ * Get the underlying Photon app instance
128
+ */
129
+ get native(): Photon;
130
+ /**
131
+ * Set the underlying Photon app instance
132
+ * Used by PlanetCore during initialization
133
+ */
134
+ setNative(app: Photon): void;
135
+ route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
136
+ routes(routes: RouteDefinition[]): void;
137
+ use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
138
+ useGlobal(...middleware: GravitoMiddleware<V>[]): void;
139
+ useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
140
+ mount(path: string, subAdapter: HttpAdapter<V>): void;
141
+ onError(handler: GravitoErrorHandler<V>): void;
142
+ onNotFound(handler: GravitoNotFoundHandler<V>): void;
143
+ /**
144
+ * Predictive Route Warming (JIT Optimization)
145
+ */
146
+ warmup(paths: string[]): Promise<void>;
147
+ fetch: (request: Request, server?: unknown) => Response | Promise<Response>;
148
+ createContext(_request: Request): GravitoContext<V>;
149
+ init(): Promise<void>;
150
+ shutdown(): Promise<void>;
151
+ }
152
+ /**
153
+ * Create a new PhotonAdapter instance
154
+ */
155
+ export declare function createPhotonAdapter<V extends GravitoVariables = GravitoVariables>(config?: AdapterConfig): PhotonAdapter<V>;
156
+ export { PhotonContextWrapper, PhotonRequestWrapper, toPhotonHandler, toPhotonMiddleware };
157
+ /**
158
+ * Rebranded alias for PhotonAdapter.
159
+ * @category Rebranding
160
+ */
161
+ export declare const GravitoAdapter: typeof PhotonAdapter;
162
+ /**
163
+ * Rebranded alias for PhotonAdapter type.
164
+ * @category Rebranding
165
+ */
166
+ export type GravitoAdapter<V extends GravitoVariables = GravitoVariables> = PhotonAdapter<V>;
167
+ /**
168
+ * Rebranded alias for createPhotonAdapter.
169
+ * @category Rebranding
170
+ */
171
+ export declare const createGravitoAdapter: typeof createPhotonAdapter;
@@ -0,0 +1,45 @@
1
+ import type { ContentfulStatusCode, GravitoContext, GravitoVariables, ProxyOptions, StatusCode } from '../../http/types';
2
+ import { BunRequest } from './BunRequest';
3
+ /**
4
+ * Bun-optimized implementation of GravitoContext.
5
+ * @internal
6
+ */
7
+ export declare class BunContext<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
8
+ readonly env: Record<string, unknown>;
9
+ readonly req: BunRequest;
10
+ private _variables;
11
+ /**
12
+ * URL generator helper
13
+ */
14
+ route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
15
+ private _status;
16
+ private _headers;
17
+ private _executionCtx?;
18
+ res: Response | undefined;
19
+ readonly native: unknown;
20
+ constructor(request: Request, env?: Record<string, unknown>, executionCtx?: ExecutionContext);
21
+ /**
22
+ * Create a proxied instance to enable object destructuring of context variables
23
+ * This allows: async list({ userService }: Context)
24
+ */
25
+ static create<V extends GravitoVariables = GravitoVariables>(request: Request, env?: Record<string, unknown>, executionCtx?: ExecutionContext): GravitoContext<V>;
26
+ json<T>(data: T, status?: ContentfulStatusCode): Response;
27
+ text(text: string, status?: ContentfulStatusCode): Response;
28
+ html(html: string, status?: ContentfulStatusCode): Response;
29
+ redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
30
+ body(data: BodyInit | null, status?: StatusCode): Response;
31
+ stream(stream: ReadableStream, status?: ContentfulStatusCode): Response;
32
+ notFound(message?: string): Response;
33
+ forbidden(message?: string): Response;
34
+ unauthorized(message?: string): Response;
35
+ badRequest(message?: string): Response;
36
+ forward(target: string, options?: ProxyOptions): Promise<Response>;
37
+ header(name: string, value: string, options?: {
38
+ append?: boolean;
39
+ }): void;
40
+ header(name: string): string | undefined;
41
+ status(code: StatusCode): void;
42
+ get<K extends keyof V>(key: K): V[K];
43
+ set<K extends keyof V>(key: K, value: V[K]): void;
44
+ get executionCtx(): ExecutionContext | undefined;
45
+ }
@@ -0,0 +1,31 @@
1
+ import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, HttpMethod } from '../../http/types';
2
+ import type { HttpAdapter, RouteDefinition } from '../types';
3
+ /**
4
+ * Native Bun-optimized HTTP Adapter for Gravito.
5
+ * Uses Bun's standard Request/Response classes and efficient router.
6
+ * @public
7
+ */
8
+ export declare class BunNativeAdapter implements HttpAdapter {
9
+ readonly name = "bun-native";
10
+ readonly version = "0.0.1";
11
+ get native(): unknown;
12
+ private router;
13
+ private middlewares;
14
+ private errorHandler;
15
+ private notFoundHandler;
16
+ route(method: HttpMethod, path: string, ...handlers: (GravitoHandler | GravitoMiddleware)[]): void;
17
+ routes(routes: RouteDefinition[]): void;
18
+ use(path: string, ...middleware: GravitoMiddleware[]): void;
19
+ useGlobal(...middleware: GravitoMiddleware[]): void;
20
+ useScoped(scope: string, path: string, ...middleware: GravitoMiddleware[]): void;
21
+ mount(path: string, subAdapter: HttpAdapter): void;
22
+ createContext(request: Request): GravitoContext;
23
+ onError(handler: GravitoErrorHandler): void;
24
+ onNotFound(handler: GravitoNotFoundHandler): void;
25
+ /**
26
+ * Predictive Route Warming (JIT Optimization)
27
+ */
28
+ warmup(paths: string[]): Promise<void>;
29
+ fetch(request: Request, _server?: unknown): Promise<Response>;
30
+ private executeChain;
31
+ }
@@ -0,0 +1,31 @@
1
+ import type { GravitoRequest, ValidationTarget } from '../../http/types';
2
+ /**
3
+ * Bun-optimized implementation of GravitoRequest.
4
+ * @internal
5
+ */
6
+ export declare class BunRequest implements GravitoRequest {
7
+ readonly raw: Request;
8
+ private _url;
9
+ private _params;
10
+ private _query;
11
+ private _validated;
12
+ constructor(raw: Request, params?: Record<string, string>);
13
+ setParams(params: Record<string, string>): void;
14
+ get url(): string;
15
+ get method(): string;
16
+ get path(): string;
17
+ param(name: string): string | undefined;
18
+ params(): Record<string, string>;
19
+ query(name: string): string | undefined;
20
+ queries(): Record<string, string | string[]>;
21
+ header(name: string): string | undefined;
22
+ header(): Record<string, string>;
23
+ json<T = unknown>(): Promise<T>;
24
+ text(): Promise<string>;
25
+ formData(): Promise<FormData>;
26
+ arrayBuffer(): Promise<ArrayBuffer>;
27
+ parseBody<T = unknown>(): Promise<T>;
28
+ setValidated(target: ValidationTarget, data: unknown): void;
29
+ valid<T = unknown>(target: ValidationTarget): T;
30
+ private parseQuery;
31
+ }
@@ -0,0 +1,19 @@
1
+ import type { HttpMethod } from '../../http/types';
2
+ import { NodeType, type RouteHandler } from './types';
3
+ /**
4
+ * Node in the Radix Router tree.
5
+ * @internal
6
+ */
7
+ export declare class RadixNode {
8
+ segment: string;
9
+ type: NodeType;
10
+ children: Map<string, RadixNode>;
11
+ paramChild: RadixNode | null;
12
+ wildcardChild: RadixNode | null;
13
+ handlers: Map<HttpMethod, RouteHandler[]>;
14
+ paramName: string | null;
15
+ regex: RegExp | null;
16
+ constructor(segment?: string, type?: NodeType);
17
+ toJSON(): any;
18
+ static fromJSON(json: any): RadixNode;
19
+ }
@@ -0,0 +1,31 @@
1
+ import type { HttpMethod } from '../../http/types';
2
+ import { type RouteHandler, type RouteMatch } from './types';
3
+ /**
4
+ * High-performance Radix Tree Router for Bun
5
+ */
6
+ export declare class RadixRouter {
7
+ private root;
8
+ private globalConstraints;
9
+ /**
10
+ * Add a generic parameter constraint
11
+ */
12
+ where(param: string, regex: RegExp): void;
13
+ /**
14
+ * Register a route
15
+ */
16
+ add(method: HttpMethod, path: string, handlers: RouteHandler[]): void;
17
+ /**
18
+ * Match a request
19
+ */
20
+ match(method: string, path: string): RouteMatch | null;
21
+ private matchRecursive;
22
+ private splitPath;
23
+ /**
24
+ * Serialize the router to a JSON string
25
+ */
26
+ serialize(): string;
27
+ /**
28
+ * Restore a router from a serialized JSON string
29
+ */
30
+ static fromSerialized(json: string): RadixRouter;
31
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Route Handler type (simplified for internal use)
3
+ * In the full framework this will align with GravitoHandler
4
+ */
5
+ export type RouteHandler = Function;
6
+ /**
7
+ * Route Match Result
8
+ */
9
+ export interface RouteMatch {
10
+ handlers: RouteHandler[];
11
+ params: Record<string, string>;
12
+ }
13
+ /**
14
+ * Radix Node Type
15
+ */
16
+ export declare enum NodeType {
17
+ STATIC = 0,
18
+ PARAM = 1,
19
+ WILDCARD = 2
20
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @fileoverview Photon Type Extensions
3
+ *
4
+ * Type definitions for Photon framework extensions and internal properties.
5
+ * These types help maintain type safety when working with Photon's native APIs.
6
+ *
7
+ * @module @gravito/core/adapters/photon-types
8
+ * @since 2.0.0
9
+ */
10
+ import type { Context } from '@gravito/photon';
11
+ /**
12
+ * Extended Photon Request with additional properties
13
+ */
14
+ export interface PhotonRequestExtended {
15
+ /**
16
+ * Validate request data against a schema
17
+ * This is typically added by validation middleware
18
+ */
19
+ valid<T = unknown>(target: string): T;
20
+ /**
21
+ * Allow dynamic property access for middleware extensions
22
+ */
23
+ [key: string]: unknown;
24
+ }
25
+ /**
26
+ * Extended Photon Context with internal caching
27
+ */
28
+ export interface PhotonContextExtended extends Context {
29
+ /**
30
+ * Internal cache for parsed JSON body to avoid re-parsing
31
+ * @internal
32
+ */
33
+ _cachedJsonBody?: unknown;
34
+ /**
35
+ * Extended request object
36
+ */
37
+ req: Context['req'] & PhotonRequestExtended;
38
+ }
39
+ /**
40
+ * Extended Response with flash message support
41
+ * This is a partial interface since we're adding the method dynamically
42
+ */
43
+ export interface ResponseWithFlash {
44
+ /**
45
+ * Add flash message to session (for redirect responses)
46
+ * @param key - Flash message key
47
+ * @param value - Flash message value
48
+ * @returns The response for chaining
49
+ */
50
+ with(key: string, value: unknown): ResponseWithFlash;
51
+ [key: string]: unknown;
52
+ }
53
+ /**
54
+ * Session interface with flash message support
55
+ */
56
+ export interface SessionWithFlash {
57
+ /**
58
+ * Store a flash message in the session
59
+ */
60
+ flash(key: string, value: unknown): void;
61
+ /**
62
+ * Allow other session properties
63
+ */
64
+ [key: string]: unknown;
65
+ }
66
+ /**
67
+ * Type guard to check if context has cached JSON body
68
+ */
69
+ export declare function hasCachedJsonBody(ctx: Context): ctx is PhotonContextExtended;
70
+ /**
71
+ * Type guard to check if request has valid method
72
+ */
73
+ export declare function hasValidMethod(req: Context['req']): req is Context['req'] & PhotonRequestExtended;