@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,9 @@
1
+ /**
2
+ * Calculate Levenshtein distance between two strings
3
+ * Used for "Did you mean?" suggestions
4
+ */
5
+ export declare function levenshtein(a: string, b: string): number;
6
+ /**
7
+ * Find similar strings from a list
8
+ */
9
+ export declare function findSimilar(target: string, candidates: string[], maxDistance?: number, maxResults?: number): string[];
@@ -0,0 +1,215 @@
1
+ /**
2
+ * @fileoverview Application - Enterprise Application Container
3
+ *
4
+ * A high-level application class that orchestrates the entire framework.
5
+ * Provides a centralized entry point for enterprise applications with
6
+ * auto-discovery of providers, config loading, and lifecycle management.
7
+ *
8
+ * @module @gravito/core
9
+ * @since 2.0.0
10
+ */
11
+ import { ConfigManager } from './ConfigManager';
12
+ import { Container } from './Container';
13
+ import type { EventManager } from './EventManager';
14
+ import type { Logger } from './Logger';
15
+ import { PlanetCore } from './PlanetCore';
16
+ import type { ServiceProvider } from './ServiceProvider';
17
+ /**
18
+ * Application Config options for the Application class.
19
+ * @public
20
+ */
21
+ export interface ApplicationConfig {
22
+ /**
23
+ * Base path of the application
24
+ */
25
+ basePath: string;
26
+ /**
27
+ * Path to the config directory (relative to basePath)
28
+ * @default 'config'
29
+ */
30
+ configPath?: string;
31
+ /**
32
+ * Path to the providers directory (relative to basePath)
33
+ * @default 'src/Providers'
34
+ */
35
+ providersPath?: string;
36
+ /**
37
+ * Environment (development, production, testing)
38
+ */
39
+ env?: 'development' | 'production' | 'testing';
40
+ /**
41
+ * Logger instance
42
+ */
43
+ logger?: Logger;
44
+ /**
45
+ * Initial configuration values
46
+ */
47
+ config?: Record<string, unknown>;
48
+ /**
49
+ * Service providers to register
50
+ */
51
+ providers?: ServiceProvider[];
52
+ /**
53
+ * Whether to auto-discover providers from providersPath
54
+ * @default true
55
+ */
56
+ autoDiscoverProviders?: boolean;
57
+ }
58
+ /**
59
+ * Application - Enterprise-grade application container.
60
+ *
61
+ * Provides a higher-level abstraction over PlanetCore for building
62
+ * enterprise applications with convention-over-configuration patterns.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Create application
67
+ * const app = new Application({
68
+ * basePath: import.meta.dir,
69
+ * env: process.env.NODE_ENV as 'development' | 'production',
70
+ * });
71
+ *
72
+ * // Boot the application
73
+ * await app.boot();
74
+ *
75
+ * // Access core
76
+ * export default app.core.liftoff();
77
+ * ```
78
+ */
79
+ export declare class Application {
80
+ /**
81
+ * The underlying PlanetCore instance.
82
+ */
83
+ readonly core: PlanetCore;
84
+ /**
85
+ * The IoC container.
86
+ */
87
+ readonly container: Container;
88
+ /**
89
+ * The configuration manager.
90
+ */
91
+ readonly config: ConfigManager;
92
+ /**
93
+ * The event manager.
94
+ */
95
+ readonly events: EventManager;
96
+ /**
97
+ * The logger instance.
98
+ */
99
+ readonly logger: Logger;
100
+ /**
101
+ * Application base path.
102
+ */
103
+ readonly basePath: string;
104
+ /**
105
+ * Environment mode.
106
+ */
107
+ readonly env: 'development' | 'production' | 'testing';
108
+ /**
109
+ * Configuration options.
110
+ */
111
+ private readonly options;
112
+ /**
113
+ * Whether the application has been booted.
114
+ */
115
+ private booted;
116
+ constructor(options: ApplicationConfig);
117
+ /**
118
+ * Boot the application and its dependencies.
119
+ *
120
+ * This method orchestrates the full application lifecycle:
121
+ * 1. Configuration: Loads all config files from the config directory.
122
+ * 2. Discovery: Auto-discovers ServiceProviders from the providers directory.
123
+ * 3. Registration: Registers all discovered and explicit providers.
124
+ * 4. Bootstrapping: Triggers the PlanetCore bootstrap sequence.
125
+ *
126
+ * @returns Promise that resolves to the application instance for chaining.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const app = new Application({ basePath: import.meta.dir });
131
+ * await app.boot();
132
+ * ```
133
+ */
134
+ boot(): Promise<this>;
135
+ /**
136
+ * Load configuration files from the config directory.
137
+ *
138
+ * @internal
139
+ */
140
+ private loadConfiguration;
141
+ /**
142
+ * Discover and register providers from the providers directory.
143
+ *
144
+ * @internal
145
+ */
146
+ private discoverProviders;
147
+ /**
148
+ * Resolve a service instance from the IoC container.
149
+ *
150
+ * This is a convenience wrapper around `container.make()`.
151
+ *
152
+ * @template T - The expected type of the service.
153
+ * @param key - The unique identifier or class name of the service.
154
+ * @returns The resolved service instance.
155
+ * @throws Error if the service is not bound in the container.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const db = app.make<Database>('db');
160
+ * ```
161
+ */
162
+ make<T>(key: string): T;
163
+ /**
164
+ * Check if a service is bound.
165
+ *
166
+ * @param key - The service key
167
+ * @returns True if bound
168
+ */
169
+ has(key: string): boolean;
170
+ /**
171
+ * Retrieve a configuration value using dot notation.
172
+ *
173
+ * @template T - The expected type of the configuration value.
174
+ * @param key - The configuration key (e.g., 'app.name', 'database.connections.mysql').
175
+ * @param defaultValue - Optional value to return if the key is not found.
176
+ * @returns The configuration value or the default value.
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const port = app.getConfig<number>('app.port', 3000);
181
+ * ```
182
+ */
183
+ getConfig<T>(key: string, defaultValue?: T): T;
184
+ /**
185
+ * Resolve an absolute path relative to the application base path.
186
+ *
187
+ * @param segments - Path segments to join with the base path.
188
+ * @returns The absolute path string.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const storagePath = app.path('storage', 'logs');
193
+ * ```
194
+ */
195
+ path(...segments: string[]): string;
196
+ /**
197
+ * Get the config path.
198
+ *
199
+ * @param segments - Additional path segments
200
+ * @returns Absolute path to config directory
201
+ */
202
+ configPath(...segments: string[]): string;
203
+ /**
204
+ * Check if running in production.
205
+ */
206
+ isProduction(): boolean;
207
+ /**
208
+ * Check if running in development.
209
+ */
210
+ isDevelopment(): boolean;
211
+ /**
212
+ * Check if running in testing.
213
+ */
214
+ isTesting(): boolean;
215
+ }
@@ -0,0 +1,33 @@
1
+ import type { Container } from './Container';
2
+ /**
3
+ * CommandHandler type for custom CLI commands.
4
+ */
5
+ export type CommandHandler = (args: string[], container: Container) => Promise<void> | void;
6
+ /**
7
+ * CommandKernel - Structured CLI Command handling.
8
+ *
9
+ * Manages registration and execution of custom CLI commands that can
10
+ * reuse the application container and providers.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const kernel = new CommandKernel(container);
15
+ * kernel.register('greet', (args) => console.log('Hello', args[0]));
16
+ * await kernel.handle(['greet', 'Universe']);
17
+ * ```
18
+ */
19
+ export declare class CommandKernel {
20
+ private container;
21
+ private commands;
22
+ constructor(container: Container);
23
+ /**
24
+ * Register a new command handler.
25
+ */
26
+ register(name: string, handler: CommandHandler): void;
27
+ /**
28
+ * Handle an incoming CLI command.
29
+ *
30
+ * @param argv - Array of command line arguments (e.g. process.argv.slice(2))
31
+ */
32
+ handle(argv: string[]): Promise<void>;
33
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * ConfigManager - Central configuration store.
3
+ * Supports loading from environment variables and initial objects.
4
+ * @public
5
+ */
6
+ export declare class ConfigManager {
7
+ private config;
8
+ constructor(initialConfig?: Record<string, unknown>);
9
+ /**
10
+ * Load all environment variables from the active runtime.
11
+ */
12
+ private loadEnv;
13
+ /**
14
+ * Get a configuration value (generic return type supported).
15
+ * Supports dot notation for deep access (e.g. 'app.name').
16
+ */
17
+ get<T = unknown>(key: string, defaultValue?: T): T;
18
+ /**
19
+ * Set a configuration value.
20
+ */
21
+ set(key: string, value: unknown): void;
22
+ /**
23
+ * Check whether a key exists.
24
+ */
25
+ has(key: string): boolean;
26
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Factory type for creating service instances
3
+ */
4
+ export type Factory<T> = (container: Container) => T;
5
+ /**
6
+ * ServiceMap interface for type-safe IoC resolution.
7
+ *
8
+ * Extend this interface via module augmentation to get type inference:
9
+ * @example
10
+ * ```typescript
11
+ * declare module '@gravito/core' {
12
+ * interface ServiceMap {
13
+ * logger: Logger
14
+ * db: DatabaseConnection
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export type ServiceMap = {};
20
+ /**
21
+ * ServiceKey represents the allowed keys for service resolution.
22
+ * Includes keys from ServiceMap, generic strings, or symbols.
23
+ */
24
+ export type ServiceKey = keyof ServiceMap | (string & {}) | symbol;
25
+ /**
26
+ * Container - Simple Dependency Injection Container.
27
+ * Manages service bindings and singleton instances.
28
+ * @public
29
+ */
30
+ export declare class Container {
31
+ private bindings;
32
+ private instances;
33
+ private resolutionStack;
34
+ /**
35
+ * Bind a service to the container.
36
+ *
37
+ * A new instance will be created by the factory function every time the
38
+ * service is resolved from the container.
39
+ *
40
+ * @template T - The type of the service being bound.
41
+ * @param key - The unique identifier for the service.
42
+ * @param factory - The factory function that creates the service instance.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * container.bind('logger', (c) => new ConsoleLogger());
47
+ * ```
48
+ */
49
+ bind<T>(key: ServiceKey, factory: Factory<T>): void;
50
+ /**
51
+ * Bind a shared service to the container (Singleton).
52
+ *
53
+ * The factory function will be called only once, and the same instance
54
+ * will be returned on every subsequent resolution.
55
+ *
56
+ * @template T - The type of the service being bound.
57
+ * @param key - The unique identifier for the service.
58
+ * @param factory - The factory function that creates the service instance.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * container.singleton('db', (c) => new DatabaseConnection());
63
+ * ```
64
+ */
65
+ singleton<T>(key: ServiceKey, factory: Factory<T>): void;
66
+ /**
67
+ * Register an existing instance as a shared service.
68
+ *
69
+ * @param key - The unique identifier for the service.
70
+ * @param instance - The instance to register.
71
+ */
72
+ instance<T>(key: ServiceKey, instance: T): void;
73
+ /**
74
+ * Resolve a service instance from the container.
75
+ *
76
+ * Automatically handles singleton caching and factory execution.
77
+ *
78
+ * @template T - The expected type of the service.
79
+ * @param key - The unique identifier for the service.
80
+ * @returns The resolved service instance.
81
+ * @throws Error if the service key is not found in the container.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const logger = container.make<Logger>('logger');
86
+ * ```
87
+ */
88
+ make<K extends keyof ServiceMap>(key: K): ServiceMap[K];
89
+ make<T>(key: ServiceKey): T;
90
+ /**
91
+ * Check if a service is bound or has an instance in the container.
92
+ *
93
+ * @param key - The service key to check.
94
+ * @returns True if the service exists.
95
+ */
96
+ has(key: ServiceKey): boolean;
97
+ /**
98
+ * Flush all instances and bindings from the container.
99
+ * Resets the container to an empty state.
100
+ */
101
+ flush(): void;
102
+ /**
103
+ * Forget a specific instance while keeping its binding.
104
+ *
105
+ * @param key - The service key to forget.
106
+ */
107
+ forget(key: ServiceKey): void;
108
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @fileoverview ErrorHandler - Centralized Error Handling for Gravito Framework
3
+ *
4
+ * Extracted from PlanetCore to follow Single Responsibility Principle.
5
+ * Handles HTTP errors, validation errors, and error rendering.
6
+ *
7
+ * @module @gravito/core
8
+ * @since 1.3.0
9
+ */
10
+ import type { HookManager } from './HookManager';
11
+ import type { GravitoContext } from './http/types';
12
+ import type { Logger } from './Logger';
13
+ /**
14
+ * HTTP Status Code to Error Code mapping
15
+ */
16
+ export declare function codeFromStatus(status: number): string;
17
+ /**
18
+ * HTTP Status Code to Message mapping
19
+ */
20
+ export declare function messageFromStatus(status: number): string;
21
+ /**
22
+ * Dependencies injected into ErrorHandler
23
+ * @public
24
+ */
25
+ export interface ErrorHandlerDeps {
26
+ logger: Logger;
27
+ hooks: HookManager;
28
+ getCore: () => unknown;
29
+ }
30
+ /**
31
+ * ErrorHandler - Centralized error handling logic
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const handler = new ErrorHandler({ logger, hooks, getCore: () => core })
36
+ * adapter.onError(handler.handleError.bind(handler))
37
+ * adapter.onNotFound(handler.handleNotFound.bind(handler))
38
+ * ```
39
+ */
40
+ export declare class ErrorHandler {
41
+ private deps;
42
+ constructor(deps: ErrorHandlerDeps);
43
+ /**
44
+ * Handle application errors
45
+ */
46
+ handleError(err: unknown, c: GravitoContext): Promise<Response>;
47
+ /**
48
+ * Handle 404 Not Found errors
49
+ */
50
+ handleNotFound(c: GravitoContext): Promise<Response>;
51
+ /**
52
+ * Handle validation error redirect for HTML requests
53
+ */
54
+ private handleValidationRedirect;
55
+ /**
56
+ * Log error based on context settings
57
+ */
58
+ private logError;
59
+ /**
60
+ * Render error response (HTML or JSON)
61
+ */
62
+ private renderErrorResponse;
63
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Event base class and related types.
3
+ */
4
+ export type { Channel, ShouldBroadcast } from './types/events';
5
+ export { Event } from './types/events';
@@ -0,0 +1,123 @@
1
+ import { Event } from './Event';
2
+ import type { Listener } from './Listener';
3
+ import type { PlanetCore } from './PlanetCore';
4
+ /**
5
+ * Listener registration metadata.
6
+ */
7
+ interface ListenerRegistration<TEvent extends Event = Event> {
8
+ listener: Listener<TEvent> | (new () => Listener<TEvent>);
9
+ queue?: string;
10
+ connection?: string;
11
+ delay?: number;
12
+ }
13
+ /**
14
+ * Event manager.
15
+ *
16
+ * Provides type-safe event dispatching and listener registration.
17
+ * Supports both synchronous listeners and asynchronous (queued) listeners.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * class UserRegistered extends Event {
22
+ * constructor(public user: User) {
23
+ * super()
24
+ * }
25
+ * }
26
+ *
27
+ * class SendWelcomeEmail implements Listener<UserRegistered> {
28
+ * async handle(event: UserRegistered): Promise<void> {
29
+ * // send welcome email
30
+ * }
31
+ * }
32
+ *
33
+ * // Register listener
34
+ * core.events.listen(UserRegistered, SendWelcomeEmail)
35
+ *
36
+ * // Dispatch event
37
+ * await core.events.dispatch(new UserRegistered(user))
38
+ * ```
39
+ */
40
+ export declare class EventManager {
41
+ private core;
42
+ /**
43
+ * Listener registry.
44
+ * Key: event class or event name
45
+ * Value: listener registrations
46
+ */
47
+ private listeners;
48
+ /**
49
+ * Broadcast manager (optional, injected by `orbit-broadcasting`).
50
+ */
51
+ private broadcastManager;
52
+ /**
53
+ * Queue manager (optional, injected by `orbit-queue`).
54
+ */
55
+ private queueManager;
56
+ constructor(core: PlanetCore);
57
+ /**
58
+ * Register the broadcast manager (called by `orbit-broadcasting`).
59
+ */
60
+ setBroadcastManager(manager: EventManager['broadcastManager']): void;
61
+ /**
62
+ * Register the queue manager (called by `orbit-queue`).
63
+ */
64
+ setQueueManager(manager: EventManager['queueManager']): void;
65
+ /**
66
+ * Register an event listener.
67
+ *
68
+ * @param event - Event class or event name
69
+ * @param listener - Listener instance or listener class
70
+ * @param options - Optional queue options
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * // Synchronous listener
75
+ * core.events.listen(UserRegistered, SendWelcomeEmail)
76
+ *
77
+ * // Queued listener (async)
78
+ * core.events.listen(UserRegistered, SendWelcomeEmail, {
79
+ * queue: 'emails',
80
+ * delay: 60
81
+ * })
82
+ * ```
83
+ */
84
+ listen<TEvent extends Event>(event: string | (new (...args: unknown[]) => TEvent), listener: Listener<TEvent> | (new () => Listener<TEvent>), options?: {
85
+ queue?: string;
86
+ connection?: string;
87
+ delay?: number;
88
+ }): void;
89
+ /**
90
+ * Remove an event listener.
91
+ *
92
+ * @param event - Event class or event name
93
+ * @param listener - Listener to remove
94
+ */
95
+ unlisten<TEvent extends Event>(event: string | (new (...args: unknown[]) => TEvent), listener: Listener<TEvent> | (new () => Listener<TEvent>)): void;
96
+ /**
97
+ * Dispatch an event.
98
+ *
99
+ * Runs all registered listeners. If a listener implements `ShouldQueue` or
100
+ * has queue options, the listener will be pushed to the queue for async execution.
101
+ *
102
+ * @param event - Event instance
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * await core.events.dispatch(new UserRegistered(user))
107
+ * ```
108
+ */
109
+ dispatch<TEvent extends Event>(event: TEvent): Promise<void>;
110
+ /**
111
+ * Serialize an event (for queueing).
112
+ */
113
+ private serializeEvent;
114
+ /**
115
+ * Get all registered listeners.
116
+ */
117
+ getListeners(event?: string | (new () => Event)): ListenerRegistration[];
118
+ /**
119
+ * Clear all listeners.
120
+ */
121
+ clear(): void;
122
+ }
123
+ export {};
@@ -0,0 +1,47 @@
1
+ import type { Logger } from './Logger';
2
+ import type { PlanetCore } from './PlanetCore';
3
+ /**
4
+ * Type of process-level error
5
+ * @public
6
+ */
7
+ export type GlobalProcessErrorKind = 'unhandledRejection' | 'uncaughtException';
8
+ /**
9
+ * Context payload for global error handler filters/actions
10
+ * @public
11
+ */
12
+ export type GlobalProcessErrorHandlerContext = {
13
+ core?: PlanetCore;
14
+ kind: GlobalProcessErrorKind;
15
+ error: unknown;
16
+ isProduction: boolean;
17
+ timestamp: number;
18
+ logLevel?: 'error' | 'warn' | 'info' | 'none';
19
+ logMessage?: string;
20
+ exit?: boolean;
21
+ exitCode?: number;
22
+ gracePeriodMs?: number;
23
+ };
24
+ /**
25
+ * Error handling strategy
26
+ * @public
27
+ */
28
+ export type GlobalErrorHandlersMode = 'log' | 'exit' | 'exitInProduction';
29
+ /**
30
+ * Options for registering global handlers
31
+ * @public
32
+ */
33
+ export type RegisterGlobalErrorHandlersOptions = {
34
+ core?: PlanetCore;
35
+ logger?: Logger;
36
+ mode?: GlobalErrorHandlersMode;
37
+ exitCode?: number;
38
+ gracePeriodMs?: number;
39
+ };
40
+ /**
41
+ * Register process-level error handlers (`unhandledRejection` / `uncaughtException`).
42
+ *
43
+ * - `mode: "log"`: only log/report
44
+ * - `mode: "exit"`: report then `process.exit(exitCode)`
45
+ * - `mode: "exitInProduction"`: exit only when `NODE_ENV=production` (default)
46
+ */
47
+ export declare function registerGlobalErrorHandlers(options?: RegisterGlobalErrorHandlersOptions): () => void;
@@ -0,0 +1,28 @@
1
+ import { type GravitoConfig, PlanetCore } from './PlanetCore';
2
+ /**
3
+ * Manifest describing a Gravito application structure.
4
+ * @public
5
+ */
6
+ export interface GravitoManifest {
7
+ name: string;
8
+ version?: string;
9
+ modules: string[];
10
+ config?: GravitoConfig;
11
+ }
12
+ /**
13
+ * Function type for asynchronous module resolution.
14
+ * @public
15
+ */
16
+ export type ModuleResolver = () => Promise<any>;
17
+ /**
18
+ * Gravito 核心啟動引擎 (已解耦)
19
+ */
20
+ export declare class GravitoServer {
21
+ /**
22
+ * 一鍵建立並組裝伺服器
23
+ * @param manifest 站點描述清單
24
+ * @param resolvers 模組解析器字典
25
+ * @param baseOrbits 基礎軌道模組 (例如 OrbitMonolith)
26
+ */
27
+ static create(manifest: GravitoManifest, resolvers: Record<string, ModuleResolver>, baseOrbits?: any[]): Promise<PlanetCore>;
28
+ }