@gravito/echo 3.0.1 → 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 (173) 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 +43 -17
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/Container.d.ts +78 -14
  83. package/dist/core/src/HookManager.d.ts +422 -8
  84. package/dist/core/src/PlanetCore.d.ts +52 -7
  85. package/dist/core/src/Router.d.ts +41 -7
  86. package/dist/core/src/ServiceProvider.d.ts +14 -8
  87. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
  88. package/dist/core/src/adapters/PhotonAdapter.d.ts +1 -0
  89. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
  90. package/dist/core/src/adapters/types.d.ts +39 -0
  91. package/dist/core/src/engine/AOTRouter.d.ts +1 -11
  92. package/dist/core/src/engine/FastContext.d.ts +4 -2
  93. package/dist/core/src/engine/Gravito.d.ts +1 -1
  94. package/dist/core/src/engine/MinimalContext.d.ts +4 -2
  95. package/dist/core/src/engine/types.d.ts +6 -1
  96. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  97. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  98. package/dist/core/src/events/EventBackend.d.ts +11 -0
  99. package/dist/core/src/events/EventOptions.d.ts +109 -0
  100. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  101. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  102. package/dist/core/src/events/index.d.ts +14 -0
  103. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  104. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  105. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  106. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  107. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  108. package/dist/core/src/events/observability/index.d.ts +20 -0
  109. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  110. package/dist/core/src/events/types.d.ts +75 -0
  111. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  112. package/dist/core/src/exceptions/index.d.ts +1 -0
  113. package/dist/core/src/http/cookie.d.ts +29 -0
  114. package/dist/core/src/http/types.d.ts +21 -0
  115. package/dist/core/src/index.d.ts +13 -3
  116. package/dist/core/src/instrumentation/index.d.ts +35 -0
  117. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  118. package/dist/core/src/instrumentation/types.d.ts +182 -0
  119. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  120. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  121. package/dist/core/src/reliability/index.d.ts +6 -0
  122. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  123. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  124. package/dist/echo/src/OrbitEcho.d.ts +71 -16
  125. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  126. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  127. package/dist/echo/src/dlq/index.d.ts +2 -0
  128. package/dist/echo/src/index.d.ts +31 -15
  129. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  130. package/dist/echo/src/middleware/index.d.ts +8 -0
  131. package/dist/echo/src/observability/index.d.ts +3 -0
  132. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  133. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  134. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  135. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  136. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  137. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  138. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  139. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  140. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  141. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  142. package/dist/echo/src/providers/GenericProvider.d.ts +37 -18
  143. package/dist/echo/src/providers/GitHubProvider.d.ts +21 -12
  144. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  145. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  146. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  147. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  148. package/dist/echo/src/providers/StripeProvider.d.ts +20 -12
  149. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  150. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  151. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  152. package/dist/echo/src/providers/index.d.ts +14 -3
  153. package/dist/echo/src/receive/SignatureValidator.d.ts +33 -0
  154. package/dist/echo/src/receive/WebhookReceiver.d.ts +139 -21
  155. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  156. package/dist/echo/src/replay/index.d.ts +1 -0
  157. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  158. package/dist/echo/src/resilience/index.d.ts +10 -0
  159. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  160. package/dist/echo/src/rotation/index.d.ts +10 -0
  161. package/dist/echo/src/send/WebhookDispatcher.d.ts +159 -15
  162. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  163. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  164. package/dist/echo/src/storage/index.d.ts +2 -0
  165. package/dist/echo/src/types.d.ts +656 -64
  166. package/dist/index.js +1327 -189
  167. package/dist/index.js.map +28 -10
  168. package/dist/photon/src/index.d.ts +69 -5
  169. package/dist/photon/src/middleware/binary.d.ts +12 -15
  170. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  171. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  172. package/dist/photon/src/openapi.d.ts +19 -0
  173. 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[];
@@ -115,15 +115,21 @@ export declare class Application {
115
115
  private booted;
116
116
  constructor(options: ApplicationConfig);
117
117
  /**
118
- * Boot the application.
118
+ * Boot the application and its dependencies.
119
119
  *
120
- * This will:
121
- * 1. Load configuration files
122
- * 2. Auto-discover providers (if enabled)
123
- * 3. Register all providers
124
- * 4. Bootstrap the core
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
125
  *
126
- * @returns Promise that resolves when boot is complete
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
+ * ```
127
133
  */
128
134
  boot(): Promise<this>;
129
135
  /**
@@ -139,10 +145,19 @@ export declare class Application {
139
145
  */
140
146
  private discoverProviders;
141
147
  /**
142
- * Get a service from the container.
148
+ * Resolve a service instance from the IoC container.
143
149
  *
144
- * @param key - The service key
145
- * @returns The resolved service
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
+ * ```
146
161
  */
147
162
  make<T>(key: string): T;
148
163
  /**
@@ -153,18 +168,29 @@ export declare class Application {
153
168
  */
154
169
  has(key: string): boolean;
155
170
  /**
156
- * Get a configuration value.
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.
157
177
  *
158
- * @param key - The config key (supports dot notation)
159
- * @param defaultValue - Default value if not found
160
- * @returns The config value
178
+ * @example
179
+ * ```typescript
180
+ * const port = app.getConfig<number>('app.port', 3000);
181
+ * ```
161
182
  */
162
183
  getConfig<T>(key: string, defaultValue?: T): T;
163
184
  /**
164
- * Create application path helper.
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.
165
189
  *
166
- * @param segments - Path segments relative to base path
167
- * @returns Absolute path
190
+ * @example
191
+ * ```typescript
192
+ * const storagePath = app.path('storage', 'logs');
193
+ * ```
168
194
  */
169
195
  path(...segments: string[]): string;
170
196
  /**
@@ -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
+ }
@@ -2,7 +2,26 @@
2
2
  * Factory type for creating service instances
3
3
  */
4
4
  export type Factory<T> = (container: Container) => T;
5
- export type BindingKey = string | symbol;
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;
6
25
  /**
7
26
  * Container - Simple Dependency Injection Container.
8
27
  * Manages service bindings and singleton instances.
@@ -11,34 +30,79 @@ export type BindingKey = string | symbol;
11
30
  export declare class Container {
12
31
  private bindings;
13
32
  private instances;
33
+ private resolutionStack;
14
34
  /**
15
35
  * Bind a service to the container.
16
- * New instance will be created on each resolution.
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
+ * ```
17
48
  */
18
- bind<T>(key: BindingKey, factory: Factory<T>): void;
49
+ bind<T>(key: ServiceKey, factory: Factory<T>): void;
19
50
  /**
20
51
  * Bind a shared service to the container (Singleton).
21
- * Same instance will be returned on each resolution.
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
+ * ```
22
64
  */
23
- singleton<T>(key: BindingKey, factory: Factory<T>): void;
65
+ singleton<T>(key: ServiceKey, factory: Factory<T>): void;
24
66
  /**
25
- * Register an existing instance as shared service.
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.
26
71
  */
27
- instance<T>(key: BindingKey, instance: T): void;
72
+ instance<T>(key: ServiceKey, instance: T): void;
28
73
  /**
29
- * Resolve a service from the container.
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
+ * ```
30
87
  */
31
- make<T>(key: BindingKey): T;
88
+ make<K extends keyof ServiceMap>(key: K): ServiceMap[K];
89
+ make<T>(key: ServiceKey): T;
32
90
  /**
33
- * Check if a service is bound.
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.
34
95
  */
35
- has(key: BindingKey): boolean;
96
+ has(key: ServiceKey): boolean;
36
97
  /**
37
- * Flush all instances and bindings.
98
+ * Flush all instances and bindings from the container.
99
+ * Resets the container to an empty state.
38
100
  */
39
101
  flush(): void;
40
102
  /**
41
- * Forget a specific instance (but keep binding)
103
+ * Forget a specific instance while keeping its binding.
104
+ *
105
+ * @param key - The service key to forget.
42
106
  */
43
- forget(key: BindingKey): void;
107
+ forget(key: ServiceKey): void;
44
108
  }