@gravito/echo 3.0.0 → 3.0.1

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 (81) hide show
  1. package/dist/core/src/Application.d.ts +189 -0
  2. package/dist/core/src/ConfigManager.d.ts +26 -0
  3. package/dist/core/src/Container.d.ts +44 -0
  4. package/dist/core/src/ErrorHandler.d.ts +63 -0
  5. package/dist/core/src/Event.d.ts +5 -0
  6. package/dist/core/src/EventManager.d.ts +123 -0
  7. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  8. package/dist/core/src/GravitoServer.d.ts +28 -0
  9. package/dist/core/src/HookManager.d.ts +82 -0
  10. package/dist/core/src/Listener.d.ts +4 -0
  11. package/dist/core/src/Logger.d.ts +20 -0
  12. package/dist/core/src/PlanetCore.d.ts +244 -0
  13. package/dist/core/src/Route.d.ts +36 -0
  14. package/dist/core/src/Router.d.ts +250 -0
  15. package/dist/core/src/ServiceProvider.d.ts +150 -0
  16. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +26 -0
  17. package/dist/core/src/adapters/PhotonAdapter.d.ts +170 -0
  18. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  19. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +30 -0
  20. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  21. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  22. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  23. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  24. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  25. package/dist/core/src/adapters/types.d.ts +196 -0
  26. package/dist/core/src/engine/AOTRouter.d.ts +134 -0
  27. package/dist/core/src/engine/FastContext.d.ts +98 -0
  28. package/dist/core/src/engine/Gravito.d.ts +137 -0
  29. package/dist/core/src/engine/MinimalContext.d.ts +77 -0
  30. package/dist/core/src/engine/analyzer.d.ts +27 -0
  31. package/dist/core/src/engine/constants.d.ts +23 -0
  32. package/dist/core/src/engine/index.d.ts +26 -0
  33. package/dist/core/src/engine/path.d.ts +26 -0
  34. package/dist/core/src/engine/pool.d.ts +83 -0
  35. package/dist/core/src/engine/types.d.ts +138 -0
  36. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  37. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  38. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  39. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  40. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  41. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  42. package/dist/core/src/exceptions/index.d.ts +6 -0
  43. package/dist/core/src/helpers/Arr.d.ts +19 -0
  44. package/dist/core/src/helpers/Str.d.ts +23 -0
  45. package/dist/core/src/helpers/data.d.ts +25 -0
  46. package/dist/core/src/helpers/errors.d.ts +34 -0
  47. package/dist/core/src/helpers/response.d.ts +41 -0
  48. package/dist/core/src/helpers.d.ts +338 -0
  49. package/dist/core/src/http/CookieJar.d.ts +51 -0
  50. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  51. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  52. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  53. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  54. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  55. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  56. package/dist/core/src/http/types.d.ts +334 -0
  57. package/dist/core/src/index.d.ts +66 -0
  58. package/dist/core/src/runtime.d.ts +119 -0
  59. package/dist/core/src/security/Encrypter.d.ts +33 -0
  60. package/dist/core/src/security/Hasher.d.ts +29 -0
  61. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  62. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  63. package/dist/core/src/testing/index.d.ts +2 -0
  64. package/dist/core/src/types/events.d.ts +94 -0
  65. package/dist/echo/src/OrbitEcho.d.ts +60 -0
  66. package/dist/echo/src/index.d.ts +48 -0
  67. package/dist/echo/src/providers/GenericProvider.d.ts +34 -0
  68. package/dist/echo/src/providers/GitHubProvider.d.ts +26 -0
  69. package/dist/echo/src/providers/StripeProvider.d.ts +30 -0
  70. package/dist/echo/src/providers/index.d.ts +3 -0
  71. package/dist/echo/src/receive/SignatureValidator.d.ts +34 -0
  72. package/dist/echo/src/receive/WebhookReceiver.d.ts +67 -0
  73. package/dist/echo/src/receive/index.d.ts +2 -0
  74. package/dist/echo/src/send/WebhookDispatcher.d.ts +54 -0
  75. package/dist/echo/src/send/index.d.ts +1 -0
  76. package/dist/echo/src/types.d.ts +164 -0
  77. package/dist/index.js +6 -2
  78. package/dist/index.js.map +3 -3
  79. package/dist/photon/src/index.d.ts +20 -0
  80. package/dist/photon/src/middleware/binary.d.ts +34 -0
  81. package/package.json +1 -1
@@ -0,0 +1,244 @@
1
+ /**
2
+ * @fileoverview PlanetCore - The Heart of Gravito Framework
3
+ *
4
+ * The micro-kernel that orchestrates the entire Galaxy Architecture.
5
+ * Manages HTTP routing, middleware, error handling, and orbit integration.
6
+ *
7
+ * @module @gravito/core
8
+ * @since 1.0.0
9
+ */
10
+ import { type HttpAdapter } from './adapters/types';
11
+ import { ConfigManager } from './ConfigManager';
12
+ import { Container } from './Container';
13
+ import { EventManager } from './EventManager';
14
+ import { type RegisterGlobalErrorHandlersOptions } from './GlobalErrorHandlers';
15
+ import { HookManager } from './HookManager';
16
+ import type { fail } from './helpers/response';
17
+ import type { ContentfulStatusCode, GravitoContext } from './http/types';
18
+ import { type Logger } from './Logger';
19
+ import type { ServiceProvider } from './ServiceProvider';
20
+ /**
21
+ * CacheService interface for orbit-injected cache
22
+ * Orbits implementing cache should conform to this interface
23
+ */
24
+ export interface CacheService {
25
+ get<T = unknown>(key: string): Promise<T | null>;
26
+ set(key: string, value: unknown, ttl?: number): Promise<void>;
27
+ delete(key: string): Promise<void>;
28
+ clear(): Promise<void>;
29
+ remember<T>(key: string, ttl: number, callback: () => Promise<T>): Promise<T>;
30
+ }
31
+ /**
32
+ * Interface for View Rendering Service
33
+ * @public
34
+ */
35
+ export interface ViewService {
36
+ render(view: string, data?: Record<string, unknown>, options?: Record<string, unknown>): string;
37
+ }
38
+ /**
39
+ * Context passed to error handlers
40
+ * @public
41
+ */
42
+ export type ErrorHandlerContext = {
43
+ core: PlanetCore;
44
+ c: GravitoContext;
45
+ error: unknown;
46
+ isProduction: boolean;
47
+ accept: string;
48
+ wantsHtml: boolean;
49
+ status: ContentfulStatusCode;
50
+ payload: ReturnType<typeof fail>;
51
+ logLevel?: 'error' | 'warn' | 'info' | 'none';
52
+ logMessage?: string;
53
+ html?: {
54
+ templates: string[];
55
+ data: Record<string, unknown>;
56
+ };
57
+ };
58
+ /**
59
+ * Interface for Gravito Orbit (Plugin/Module)
60
+ * @public
61
+ */
62
+ export interface GravitoOrbit {
63
+ install(core: PlanetCore): void | Promise<void>;
64
+ }
65
+ /**
66
+ * Configuration for booting PlanetCore
67
+ * @public
68
+ */
69
+ export type GravitoConfig = {
70
+ logger?: Logger;
71
+ config?: Record<string, unknown>;
72
+ orbits?: (new () => GravitoOrbit)[] | GravitoOrbit[];
73
+ /**
74
+ * HTTP Adapter to use. Defaults to PhotonAdapter.
75
+ * @since 2.0.0
76
+ */
77
+ adapter?: HttpAdapter;
78
+ /**
79
+ * Dependency Injection Container. If provided, PlanetCore will use this
80
+ * container instead of creating a new one. This allows sharing a container
81
+ * between Application and PlanetCore.
82
+ * @since 2.0.0
83
+ */
84
+ container?: Container;
85
+ };
86
+ import { Router } from './Router';
87
+ import { Encrypter } from './security/Encrypter';
88
+ import { BunHasher } from './security/Hasher';
89
+ /**
90
+ * PlanetCore - The Heart of Gravito Framework
91
+ *
92
+ * The micro-kernel that orchestrates the entire Galaxy Architecture.
93
+ * Manages HTTP routing, middleware, error handling, and orbit integration.
94
+ * @public
95
+ */
96
+ export declare class PlanetCore {
97
+ /**
98
+ * The HTTP adapter used by this core instance.
99
+ * @since 2.0.0
100
+ */
101
+ private _adapter;
102
+ /**
103
+ * Access the underlying Photon app instance.
104
+ * @deprecated Use adapter methods for new code. This property is kept for backward compatibility.
105
+ */
106
+ get app(): unknown;
107
+ /**
108
+ * Get the HTTP adapter instance.
109
+ * @since 2.0.0
110
+ */
111
+ get adapter(): HttpAdapter;
112
+ logger: Logger;
113
+ config: ConfigManager;
114
+ hooks: HookManager;
115
+ events: EventManager;
116
+ router: Router;
117
+ container: Container;
118
+ /** @deprecated Use core.container instead */
119
+ services: Map<string, unknown>;
120
+ encrypter?: Encrypter;
121
+ hasher: BunHasher;
122
+ private providers;
123
+ private deferredProviders;
124
+ private bootedProviders;
125
+ /**
126
+ * Register a service provider.
127
+ *
128
+ * @param provider - The ServiceProvider instance to register.
129
+ * @returns The PlanetCore instance for chaining.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * core.register(new DatabaseServiceProvider());
134
+ * ```
135
+ */
136
+ register(provider: ServiceProvider): this;
137
+ /**
138
+ * Bootstrap the application by registering and booting providers.
139
+ *
140
+ * This method must be called before the application starts handling requests.
141
+ * It calls `register()` on all providers first, then `boot()` on all providers.
142
+ *
143
+ * Supports async register() methods.
144
+ *
145
+ * @returns Promise that resolves when bootstrapping is complete.
146
+ */
147
+ bootstrap(): Promise<void>;
148
+ /**
149
+ * Setup deferred provider resolution.
150
+ * Wraps container.make to auto-register deferred providers on first request.
151
+ *
152
+ * @internal
153
+ */
154
+ private setupDeferredProviderResolution;
155
+ /**
156
+ * Register a deferred provider on-demand.
157
+ *
158
+ * @internal
159
+ */
160
+ private registerDeferredProvider;
161
+ /**
162
+ * Boot a single provider if not already booted.
163
+ *
164
+ * @internal
165
+ */
166
+ private bootProvider;
167
+ constructor(options?: {
168
+ logger?: Logger;
169
+ config?: Record<string, unknown>;
170
+ adapter?: HttpAdapter;
171
+ container?: Container;
172
+ });
173
+ /**
174
+ * Programmatically register an infrastructure module (Orbit).
175
+ * @since 2.0.0
176
+ *
177
+ * @param orbit - The orbit class or instance to register.
178
+ * @returns The PlanetCore instance for chaining.
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * await core.orbit(OrbitCache);
183
+ * ```
184
+ */
185
+ orbit(orbit: GravitoOrbit | (new () => GravitoOrbit)): Promise<this>;
186
+ /**
187
+ * Programmatically register a feature module (Satellite).
188
+ * Alias for register() with provider support.
189
+ * @since 2.0.0
190
+ *
191
+ * @param satellite - The provider or setup function.
192
+ * @returns The PlanetCore instance for chaining.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * await core.use(new AuthProvider());
197
+ * ```
198
+ */
199
+ use(satellite: ServiceProvider | ((core: PlanetCore) => void | Promise<void>)): Promise<this>;
200
+ registerGlobalErrorHandlers(options?: Omit<RegisterGlobalErrorHandlersOptions, 'core'>): () => void;
201
+ /**
202
+ * Predictive Route Warming (JIT Optimization)
203
+ *
204
+ * @param paths List of paths to warm up
205
+ */
206
+ warmup(paths: string[]): Promise<void>;
207
+ /**
208
+ * Boot the application with a configuration object (IoC style default entry)
209
+ *
210
+ * @param config - The Gravito configuration object.
211
+ * @returns A Promise resolving to the booted PlanetCore instance.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const core = await PlanetCore.boot(config);
216
+ * ```
217
+ */
218
+ static boot(config: GravitoConfig): Promise<PlanetCore>;
219
+ /**
220
+ * Mount an Orbit (a PlanetCore instance or native app) to a path.
221
+ *
222
+ * @param path - The URL path to mount the orbit at.
223
+ * @param orbitApp - The application instance (PlanetCore, HttpAdapter, or native app).
224
+ */
225
+ mountOrbit(path: string, orbitApp: unknown): void;
226
+ /**
227
+ * Start the core (Liftoff).
228
+ *
229
+ * Returns a config object for `Bun.serve`.
230
+ *
231
+ * @param port - Optional port number (defaults to config or 3000).
232
+ * @returns An object compatible with Bun.serve({ ... }).
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * export default core.liftoff(3000);
237
+ * ```
238
+ */
239
+ liftoff(port?: number): {
240
+ port: number;
241
+ fetch: (request: Request, server?: unknown) => Response | Promise<Response>;
242
+ core: PlanetCore;
243
+ };
244
+ }
@@ -0,0 +1,36 @@
1
+ import type { GravitoMiddleware } from './http/types';
2
+ import type { ControllerClass, FormRequestClass, ResourceOptions, RouteHandler, RouteOptions, Router } from './Router';
3
+ /**
4
+ * Route definition helper.
5
+ * Represents a registered route and allows method chaining for middleware/names.
6
+ * @public
7
+ */
8
+ export declare class Route {
9
+ private router;
10
+ private method;
11
+ private path;
12
+ private options;
13
+ constructor(router: Router, method: string, path: string, options: RouteOptions);
14
+ /**
15
+ * Name the route
16
+ */
17
+ name(name: string): this;
18
+ static get(path: string, handler: RouteHandler): Route;
19
+ static get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
20
+ static get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
21
+ static post(path: string, handler: RouteHandler): Route;
22
+ static post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
23
+ static post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
24
+ static put(path: string, handler: RouteHandler): Route;
25
+ static put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
26
+ static put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
27
+ static delete(path: string, handler: RouteHandler): Route;
28
+ static delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
29
+ static delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
30
+ static patch(path: string, handler: RouteHandler): Route;
31
+ static patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
32
+ static patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
33
+ static resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
34
+ static prefix(path: string): import("@gravito/core").RouteGroup;
35
+ static middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): import("@gravito/core").RouteGroup;
36
+ }
@@ -0,0 +1,250 @@
1
+ import type { GravitoHandler, GravitoMiddleware, HttpMethod, ProxyOptions } from './http/types';
2
+ import type { PlanetCore } from './PlanetCore';
3
+ import { Route } from './Route';
4
+ /**
5
+ * Type for Controller Class Constructor
6
+ * @public
7
+ */
8
+ export type ControllerClass = new (core: PlanetCore) => Record<string, unknown>;
9
+ /**
10
+ * Handler can be a function or [Class, 'methodName']
11
+ * @public
12
+ */
13
+ export type RouteHandler = GravitoHandler | [ControllerClass, string];
14
+ /**
15
+ * Interface for FormRequest classes (from @gravito/impulse).
16
+ * Used for duck-typing detection without hard dependency.
17
+ */
18
+ export interface FormRequestLike {
19
+ schema: unknown;
20
+ source?: string;
21
+ /**
22
+ * Validate the request context.
23
+ * @param ctx - The request context
24
+ */
25
+ validate?(ctx: unknown): Promise<{
26
+ success: boolean;
27
+ data?: unknown;
28
+ error?: unknown;
29
+ }>;
30
+ }
31
+ /**
32
+ * Type for FormRequest class constructor
33
+ * @public
34
+ */
35
+ export type FormRequestClass = new () => FormRequestLike;
36
+ /**
37
+ * Symbol to mark FormRequest classes for fast identification.
38
+ * FormRequest classes from @gravito/impulse should set this symbol.
39
+ */
40
+ /**
41
+ * Symbol to mark FormRequest classes for fast identification.
42
+ * FormRequest classes from @gravito/impulse should set this symbol.
43
+ * @public
44
+ */
45
+ export declare const FORM_REQUEST_SYMBOL: unique symbol;
46
+ /**
47
+ * Options for route definitions
48
+ * @public
49
+ */
50
+ export interface RouteOptions {
51
+ /** Route prefix path */
52
+ prefix?: string;
53
+ /** Domain/Hostname constraint */
54
+ domain?: string;
55
+ /** Middleware stack for the route */
56
+ middleware?: GravitoMiddleware[];
57
+ }
58
+ /**
59
+ * RouteGroup
60
+ * Helper class for chained route configuration (prefix, domain, etc.)
61
+ */
62
+ /**
63
+ * RouteGroup
64
+ * Helper class for chained route configuration (prefix, domain, etc.)
65
+ * @public
66
+ */
67
+ export declare class RouteGroup {
68
+ private router;
69
+ private options;
70
+ constructor(router: Router, options: RouteOptions);
71
+ /**
72
+ * Add a prefix to the current group
73
+ */
74
+ prefix(path: string): RouteGroup;
75
+ /**
76
+ * Add middleware to the current group.
77
+ * Accepts individual handlers or arrays of handlers.
78
+ */
79
+ middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
80
+ /**
81
+ * Define routes within this group
82
+ */
83
+ group(callback: (router: Router | RouteGroup) => void): void;
84
+ get(path: string, handler: RouteHandler): Route;
85
+ get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
86
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
87
+ post(path: string, handler: RouteHandler): Route;
88
+ post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
89
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
90
+ put(path: string, handler: RouteHandler): Route;
91
+ put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
92
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
93
+ delete(path: string, handler: RouteHandler): Route;
94
+ delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
95
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
96
+ patch(path: string, handler: RouteHandler): Route;
97
+ patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
98
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
99
+ resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
100
+ /**
101
+ * Register a route that forwards requests to another URL (Gateway Proxy).
102
+ * @param method - HTTP method or 'all'
103
+ * @param path - Local route path
104
+ * @param target - Remote URL or base URL to forward to
105
+ * @param options - Optional proxy options
106
+ */
107
+ forward(method: HttpMethod | HttpMethod[] | 'all', path: string, target: string, options?: ProxyOptions): void;
108
+ }
109
+ /**
110
+ * Gravito Router
111
+ *
112
+ * Provides a Laravel-like fluent API for defining routes.
113
+ * Supports:
114
+ * - Controller-based routing: router.get('/', [HomeController, 'index'])
115
+ * - Route groups with prefixes: router.prefix('/api').group(...)
116
+ * - Domain-based routing: router.domain('api.app').group(...)
117
+ * - Middleware chaining: router.middleware(auth).group(...)
118
+ * - FormRequest validation: router.post('/users', StoreUserRequest, [UserController, 'store'])
119
+ * - Inline Middleware: router.get('/users', authMiddleware, [UserController, 'index'])
120
+ */
121
+ export declare class Router {
122
+ private core;
123
+ routes: Array<{
124
+ method: string;
125
+ path: string;
126
+ domain?: string;
127
+ }>;
128
+ private controllers;
129
+ private namedRoutes;
130
+ private bindings;
131
+ /**
132
+ * Compile all registered routes into a flat array for caching or manifest generation.
133
+ * Optimized: O(n) complexity using Set for lookups instead of O(n²) with Array.some()
134
+ */
135
+ compile(): {
136
+ method: string;
137
+ path: string;
138
+ name?: string;
139
+ domain?: string | undefined;
140
+ }[];
141
+ /**
142
+ * Register a named route
143
+ */
144
+ registerName(name: string, method: string, path: string, options?: RouteOptions): void;
145
+ /**
146
+ * Generate a URL from a named route.
147
+ */
148
+ url(name: string, params?: Record<string, string | number>, query?: Record<string, string | number | boolean | null | undefined>): string;
149
+ /**
150
+ * Export named routes as a serializable manifest (for caching).
151
+ */
152
+ exportNamedRoutes(): Record<string, {
153
+ method: string;
154
+ path: string;
155
+ domain?: string;
156
+ }>;
157
+ /**
158
+ * Load named routes from a manifest (for caching).
159
+ */
160
+ loadNamedRoutes(manifest: Record<string, {
161
+ method: string;
162
+ path: string;
163
+ domain?: string;
164
+ }>): void;
165
+ /**
166
+ * Register a route model binding.
167
+ */
168
+ bind(param: string, resolver: (id: string) => Promise<unknown>): void;
169
+ /**
170
+ * Register a route model binding for a Model class.
171
+ */
172
+ model(param: string, modelClass: unknown): void;
173
+ constructor(core: PlanetCore);
174
+ /**
175
+ * Start a route group with a prefix
176
+ */
177
+ prefix(path: string): RouteGroup;
178
+ /**
179
+ * Start a route group with a domain constraint
180
+ */
181
+ domain(host: string): RouteGroup;
182
+ /**
183
+ * Start a route group with middleware.
184
+ * Accepts individual handlers or arrays of handlers.
185
+ */
186
+ middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
187
+ /**
188
+ * Register a GET route.
189
+ */
190
+ get(path: string, handler: RouteHandler): Route;
191
+ get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
192
+ get(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
193
+ /**
194
+ * Register a POST route.
195
+ */
196
+ post(path: string, handler: RouteHandler): Route;
197
+ post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
198
+ post(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
199
+ /**
200
+ * Register a PUT route.
201
+ */
202
+ put(path: string, handler: RouteHandler): Route;
203
+ put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
204
+ put(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
205
+ /**
206
+ * Register a DELETE route.
207
+ */
208
+ delete(path: string, handler: RouteHandler): Route;
209
+ delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
210
+ delete(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
211
+ /**
212
+ * Register a PATCH route.
213
+ */
214
+ patch(path: string, handler: RouteHandler): Route;
215
+ patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
216
+ patch(path: string, middleware: GravitoMiddleware | GravitoMiddleware[], handler: RouteHandler): Route;
217
+ /**
218
+ * Register a route that forwards requests to another URL (Gateway Proxy).
219
+ * @param method - HTTP method or 'all'
220
+ * @param path - Local route path
221
+ * @param target - Remote URL or base URL to forward to
222
+ * @param options - Optional proxy options
223
+ */
224
+ forward(method: HttpMethod | HttpMethod[] | 'all', path: string, target: string, options?: ProxyOptions): void;
225
+ /**
226
+ * Register a resource route (Laravel-style).
227
+ */
228
+ resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
229
+ /**
230
+ * Internal Request Registration
231
+ */
232
+ req(method: HttpMethod, path: string, requestOrHandlerOrMiddleware: FormRequestClass | RouteHandler | GravitoMiddleware | GravitoMiddleware[], handler?: RouteHandler, options?: RouteOptions): Route;
233
+ /**
234
+ * Resolve Controller Instance and Method
235
+ */
236
+ private resolveControllerHandler;
237
+ }
238
+ /**
239
+ * Standard RESTful resource action names.
240
+ * @public
241
+ */
242
+ export type ResourceAction = 'index' | 'create' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
243
+ /**
244
+ * Options for resource route registration.
245
+ * @public
246
+ */
247
+ export interface ResourceOptions {
248
+ only?: ResourceAction[];
249
+ except?: ResourceAction[];
250
+ }
@@ -0,0 +1,150 @@
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 file into the application config.
86
+ *
87
+ * @param config - The ConfigManager instance
88
+ * @param key - The configuration key to set
89
+ * @param value - The configuration value or object
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * this.mergeConfig(config, 'database', {
94
+ * default: 'mysql',
95
+ * connections: { ... }
96
+ * });
97
+ * ```
98
+ */
99
+ protected mergeConfig(config: ConfigManager, key: string, value: unknown): void;
100
+ /**
101
+ * Merge configuration from an async loader.
102
+ * Useful for loading config from .ts files dynamically.
103
+ *
104
+ * @param config - The ConfigManager instance
105
+ * @param key - The configuration key
106
+ * @param loader - Async function that returns config value
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * await this.mergeConfigFrom(config, 'database', async () => {
111
+ * return (await import('./config/database')).default;
112
+ * });
113
+ * ```
114
+ */
115
+ protected mergeConfigFrom(config: ConfigManager, key: string, loader: () => Promise<unknown>): Promise<void>;
116
+ /**
117
+ * Paths that should be published by the CLI.
118
+ * Maps source paths to destination paths.
119
+ */
120
+ private static publishables;
121
+ /**
122
+ * Register paths to be published.
123
+ * Used by CLI commands like `gravito vendor:publish`.
124
+ *
125
+ * @param paths - Map of source to destination paths
126
+ * @param group - Optional group name for selective publishing
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * this.publishes({
131
+ * './config/cache.ts': 'config/cache.ts',
132
+ * './views/errors': 'resources/views/errors'
133
+ * }, 'config');
134
+ * ```
135
+ */
136
+ protected publishes(paths: Record<string, string>, group?: string): void;
137
+ /**
138
+ * Get all publishable paths for a group.
139
+ *
140
+ * @param group - The group name (defaults to provider class name)
141
+ * @returns Map of source to destination paths
142
+ */
143
+ static getPublishables(group?: string): Map<string, string>;
144
+ /**
145
+ * Get all publish groups.
146
+ *
147
+ * @returns Array of group names
148
+ */
149
+ static getPublishGroups(): string[];
150
+ }