@gravito/core 1.0.0-beta.6
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.
- package/LICENSE +21 -0
- package/README.md +180 -0
- package/README.zh-TW.md +24 -0
- package/dist/compat.cjs +18 -0
- package/dist/compat.d.cts +313 -0
- package/dist/compat.d.ts +313 -0
- package/dist/compat.js +0 -0
- package/dist/index.cjs +4794 -0
- package/dist/index.d.cts +2031 -0
- package/dist/index.d.ts +2031 -0
- package/dist/index.js +4688 -0
- package/package.json +67 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2031 @@
|
|
|
1
|
+
import { Variables as GravitoVariables, HttpMethod, Handler as GravitoHandler, MiddlewareHandler as GravitoMiddleware, GravitoErrorHandler, GravitoNotFoundHandler, Context as GravitoContext, ContentfulStatusCode, GravitoRequest, StatusCode } from './compat.cjs';
|
|
2
|
+
export { Next as GravitoNext, ValidationTarget } from './compat.cjs';
|
|
3
|
+
import { Photon, Context } from '@gravito/photon';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview HTTP Adapter Interface for Gravito Framework
|
|
7
|
+
*
|
|
8
|
+
* This module defines the contract that all HTTP adapters must implement.
|
|
9
|
+
* By programming to this interface, Gravito can swap out the underlying
|
|
10
|
+
* HTTP engine without changing application code.
|
|
11
|
+
*
|
|
12
|
+
* @module @gravito/core/adapters
|
|
13
|
+
* @since 2.0.0
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for HTTP adapters
|
|
18
|
+
*/
|
|
19
|
+
interface AdapterConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Base path prefix for all routes
|
|
22
|
+
* @default ''
|
|
23
|
+
*/
|
|
24
|
+
basePath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to enable strict routing (trailing slashes matter)
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
strictRouting?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Custom options passed to the underlying HTTP engine
|
|
32
|
+
*/
|
|
33
|
+
engineOptions?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Route definition structure
|
|
37
|
+
*/
|
|
38
|
+
interface RouteDefinition {
|
|
39
|
+
method: HttpMethod;
|
|
40
|
+
path: string;
|
|
41
|
+
handlers: (GravitoHandler | GravitoMiddleware)[];
|
|
42
|
+
name?: string;
|
|
43
|
+
middleware?: GravitoMiddleware[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* HttpAdapter - The core interface for HTTP engine abstraction
|
|
47
|
+
*
|
|
48
|
+
* Any HTTP engine (Photon, Express, Fastify, custom Bun implementation)
|
|
49
|
+
* must implement this interface to be usable with Gravito.
|
|
50
|
+
*
|
|
51
|
+
* @typeParam V - Context variables type
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Using the default Photon adapter
|
|
56
|
+
* import { PhotonAdapter } from '@gravito/core/adapters'
|
|
57
|
+
*
|
|
58
|
+
* const core = new PlanetCore({
|
|
59
|
+
* adapter: new PhotonAdapter()
|
|
60
|
+
* })
|
|
61
|
+
*
|
|
62
|
+
* // Using a custom adapter
|
|
63
|
+
* import { BunNativeAdapter } from '@gravito/adapter-bun'
|
|
64
|
+
*
|
|
65
|
+
* const core = new PlanetCore({
|
|
66
|
+
* adapter: new BunNativeAdapter()
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
interface HttpAdapter<V extends GravitoVariables = GravitoVariables> {
|
|
71
|
+
/**
|
|
72
|
+
* Adapter name for identification
|
|
73
|
+
* @example 'photon', 'bun-native', 'express'
|
|
74
|
+
*/
|
|
75
|
+
readonly name: string;
|
|
76
|
+
/**
|
|
77
|
+
* Adapter version
|
|
78
|
+
*/
|
|
79
|
+
readonly version: string;
|
|
80
|
+
/**
|
|
81
|
+
* Access the underlying native HTTP engine instance.
|
|
82
|
+
*
|
|
83
|
+
* ⚠️ WARNING: Using this ties your code to a specific adapter.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // For Photon adapter
|
|
88
|
+
* const photonApp = adapter.native as Photon
|
|
89
|
+
*
|
|
90
|
+
* // For custom Bun adapter
|
|
91
|
+
* const bunApp = adapter.native as BunApp
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
readonly native: unknown;
|
|
95
|
+
/**
|
|
96
|
+
* Register a route with the adapter
|
|
97
|
+
*
|
|
98
|
+
* @param method - HTTP method
|
|
99
|
+
* @param path - Route path (may include parameters like ':id')
|
|
100
|
+
* @param handlers - One or more handlers for this route (handlers or middleware)
|
|
101
|
+
*/
|
|
102
|
+
route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Register multiple routes at once
|
|
105
|
+
*
|
|
106
|
+
* @param routes - Array of route definitions
|
|
107
|
+
*/
|
|
108
|
+
routes(routes: RouteDefinition[]): void;
|
|
109
|
+
/**
|
|
110
|
+
* Register a middleware for a path
|
|
111
|
+
*
|
|
112
|
+
* @param path - Path pattern to match
|
|
113
|
+
* @param middleware - One or more middleware functions
|
|
114
|
+
*/
|
|
115
|
+
use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
116
|
+
/**
|
|
117
|
+
* Register a global middleware (applied to all routes)
|
|
118
|
+
*
|
|
119
|
+
* @param middleware - Middleware function
|
|
120
|
+
*/
|
|
121
|
+
useGlobal(...middleware: GravitoMiddleware<V>[]): void;
|
|
122
|
+
/**
|
|
123
|
+
* Mount a sub-adapter at a path
|
|
124
|
+
*
|
|
125
|
+
* @param path - Mount path
|
|
126
|
+
* @param subAdapter - The adapter to mount
|
|
127
|
+
*/
|
|
128
|
+
mount(path: string, subAdapter: HttpAdapter<V>): void;
|
|
129
|
+
/**
|
|
130
|
+
* Set the error handler
|
|
131
|
+
*
|
|
132
|
+
* @param handler - Error handler function
|
|
133
|
+
*/
|
|
134
|
+
onError(handler: GravitoErrorHandler<V>): void;
|
|
135
|
+
/**
|
|
136
|
+
* Set the not-found handler
|
|
137
|
+
*
|
|
138
|
+
* @param handler - Not-found handler function
|
|
139
|
+
*/
|
|
140
|
+
onNotFound(handler: GravitoNotFoundHandler<V>): void;
|
|
141
|
+
/**
|
|
142
|
+
* The main fetch handler for serving requests.
|
|
143
|
+
*
|
|
144
|
+
* This is compatible with `Bun.serve()`, Cloudflare Workers,
|
|
145
|
+
* and other fetch-based runtimes.
|
|
146
|
+
*
|
|
147
|
+
* @param request - Incoming HTTP request
|
|
148
|
+
* @param server - Optional server context (Bun.Server, etc.)
|
|
149
|
+
* @returns HTTP response
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // With Bun.serve
|
|
154
|
+
* Bun.serve({
|
|
155
|
+
* port: 3000,
|
|
156
|
+
* fetch: adapter.fetch
|
|
157
|
+
* })
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
fetch(request: Request, server?: unknown): Response | Promise<Response>;
|
|
161
|
+
/**
|
|
162
|
+
* Initialize the adapter
|
|
163
|
+
*
|
|
164
|
+
* Called during PlanetCore.boot()
|
|
165
|
+
*/
|
|
166
|
+
init?(): void | Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Cleanup resources
|
|
169
|
+
*
|
|
170
|
+
* Called during graceful shutdown
|
|
171
|
+
*/
|
|
172
|
+
shutdown?(): void | Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Create a GravitoContext from a raw request.
|
|
175
|
+
*
|
|
176
|
+
* This is used internally for testing and advanced scenarios.
|
|
177
|
+
*
|
|
178
|
+
* @param request - Raw HTTP request
|
|
179
|
+
* @returns Gravito context
|
|
180
|
+
*/
|
|
181
|
+
createContext(request: Request): GravitoContext<V>;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Factory function type for creating adapters
|
|
185
|
+
*/
|
|
186
|
+
type AdapterFactory<V extends GravitoVariables = GravitoVariables> = (config?: AdapterConfig) => HttpAdapter<V>;
|
|
187
|
+
/**
|
|
188
|
+
* Check if a value is an HttpAdapter
|
|
189
|
+
*/
|
|
190
|
+
declare function isHttpAdapter(value: unknown): value is HttpAdapter;
|
|
191
|
+
|
|
192
|
+
declare class ConfigManager {
|
|
193
|
+
private config;
|
|
194
|
+
constructor(initialConfig?: Record<string, unknown>);
|
|
195
|
+
/**
|
|
196
|
+
* Load all environment variables from the active runtime.
|
|
197
|
+
*/
|
|
198
|
+
private loadEnv;
|
|
199
|
+
/**
|
|
200
|
+
* Get a configuration value (generic return type supported).
|
|
201
|
+
* Supports dot notation for deep access (e.g. 'app.name').
|
|
202
|
+
*/
|
|
203
|
+
get<T = unknown>(key: string, defaultValue?: T): T;
|
|
204
|
+
/**
|
|
205
|
+
* Set a configuration value.
|
|
206
|
+
*/
|
|
207
|
+
set(key: string, value: unknown): void;
|
|
208
|
+
/**
|
|
209
|
+
* Check whether a key exists.
|
|
210
|
+
*/
|
|
211
|
+
has(key: string): boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Factory type for creating service instances
|
|
216
|
+
*/
|
|
217
|
+
type Factory<T> = (container: Container) => T;
|
|
218
|
+
declare class Container {
|
|
219
|
+
private bindings;
|
|
220
|
+
private instances;
|
|
221
|
+
/**
|
|
222
|
+
* Bind a service to the container.
|
|
223
|
+
* New instance will be created on each resolution.
|
|
224
|
+
*/
|
|
225
|
+
bind<T>(key: string, factory: Factory<T>): void;
|
|
226
|
+
/**
|
|
227
|
+
* Bind a shared service to the container (Singleton).
|
|
228
|
+
* Same instance will be returned on each resolution.
|
|
229
|
+
*/
|
|
230
|
+
singleton<T>(key: string, factory: Factory<T>): void;
|
|
231
|
+
/**
|
|
232
|
+
* Register an existing instance as shared service.
|
|
233
|
+
*/
|
|
234
|
+
instance<T>(key: string, instance: T): void;
|
|
235
|
+
/**
|
|
236
|
+
* Resolve a service from the container.
|
|
237
|
+
*/
|
|
238
|
+
make<T>(key: string): T;
|
|
239
|
+
/**
|
|
240
|
+
* Check if a service is bound.
|
|
241
|
+
*/
|
|
242
|
+
has(key: string): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Flush all instances and bindings.
|
|
245
|
+
*/
|
|
246
|
+
flush(): void;
|
|
247
|
+
/**
|
|
248
|
+
* Forget a specific instance (but keep binding)
|
|
249
|
+
*/
|
|
250
|
+
forget(key: string): void;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Event system type definitions.
|
|
255
|
+
*/
|
|
256
|
+
/**
|
|
257
|
+
* Listener interface.
|
|
258
|
+
*
|
|
259
|
+
* All event listeners must implement this interface.
|
|
260
|
+
*/
|
|
261
|
+
interface Listener<TEvent extends Event = Event> {
|
|
262
|
+
/**
|
|
263
|
+
* Handle an event.
|
|
264
|
+
* @param event - Event instance
|
|
265
|
+
*/
|
|
266
|
+
handle(event: TEvent): Promise<void> | void;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Marker interface for listeners that should be queued.
|
|
270
|
+
*
|
|
271
|
+
* Listeners implementing this interface can be dispatched asynchronously via a queue.
|
|
272
|
+
*/
|
|
273
|
+
interface ShouldQueue {
|
|
274
|
+
/**
|
|
275
|
+
* Queue name (optional).
|
|
276
|
+
*/
|
|
277
|
+
queue?: string;
|
|
278
|
+
/**
|
|
279
|
+
* Connection name (optional).
|
|
280
|
+
*/
|
|
281
|
+
connection?: string;
|
|
282
|
+
/**
|
|
283
|
+
* Delay before execution (seconds).
|
|
284
|
+
*/
|
|
285
|
+
delay?: number;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Marker interface for events that should be broadcast.
|
|
289
|
+
*
|
|
290
|
+
* Events implementing this interface can be automatically broadcast to clients.
|
|
291
|
+
*/
|
|
292
|
+
interface ShouldBroadcast {
|
|
293
|
+
/**
|
|
294
|
+
* Define the broadcast channel.
|
|
295
|
+
* @returns Channel name or channel object
|
|
296
|
+
*/
|
|
297
|
+
broadcastOn(): string | Channel;
|
|
298
|
+
/**
|
|
299
|
+
* Define broadcast payload (optional).
|
|
300
|
+
* If omitted, public event properties will be used.
|
|
301
|
+
* @returns Broadcast payload
|
|
302
|
+
*/
|
|
303
|
+
broadcastWith?(): Record<string, unknown>;
|
|
304
|
+
/**
|
|
305
|
+
* Define the broadcast event name (optional).
|
|
306
|
+
* If omitted, the event class name will be used.
|
|
307
|
+
* @returns Event name
|
|
308
|
+
*/
|
|
309
|
+
broadcastAs?(): string;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Channel interface.
|
|
313
|
+
*/
|
|
314
|
+
interface Channel {
|
|
315
|
+
/**
|
|
316
|
+
* Channel name.
|
|
317
|
+
*/
|
|
318
|
+
name: string;
|
|
319
|
+
/**
|
|
320
|
+
* Channel type.
|
|
321
|
+
*/
|
|
322
|
+
type: 'public' | 'private' | 'presence';
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Base event class.
|
|
326
|
+
*
|
|
327
|
+
* All events should extend this class.
|
|
328
|
+
*/
|
|
329
|
+
declare abstract class Event {
|
|
330
|
+
/**
|
|
331
|
+
* Whether this event should be broadcast.
|
|
332
|
+
*/
|
|
333
|
+
shouldBroadcast(): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Get broadcast channel.
|
|
336
|
+
*/
|
|
337
|
+
getBroadcastChannel(): string | Channel | null;
|
|
338
|
+
/**
|
|
339
|
+
* Get broadcast payload.
|
|
340
|
+
*/
|
|
341
|
+
getBroadcastData(): Record<string, unknown>;
|
|
342
|
+
/**
|
|
343
|
+
* Get broadcast event name.
|
|
344
|
+
*/
|
|
345
|
+
getBroadcastEventName(): string;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Listener registration metadata.
|
|
350
|
+
*/
|
|
351
|
+
interface ListenerRegistration<TEvent extends Event = Event> {
|
|
352
|
+
listener: Listener<TEvent> | (new () => Listener<TEvent>);
|
|
353
|
+
queue?: string;
|
|
354
|
+
connection?: string;
|
|
355
|
+
delay?: number;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Event manager.
|
|
359
|
+
*
|
|
360
|
+
* Provides type-safe event dispatching and listener registration.
|
|
361
|
+
* Supports both synchronous listeners and asynchronous (queued) listeners.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```typescript
|
|
365
|
+
* class UserRegistered extends Event {
|
|
366
|
+
* constructor(public user: User) {
|
|
367
|
+
* super()
|
|
368
|
+
* }
|
|
369
|
+
* }
|
|
370
|
+
*
|
|
371
|
+
* class SendWelcomeEmail implements Listener<UserRegistered> {
|
|
372
|
+
* async handle(event: UserRegistered): Promise<void> {
|
|
373
|
+
* // send welcome email
|
|
374
|
+
* }
|
|
375
|
+
* }
|
|
376
|
+
*
|
|
377
|
+
* // Register listener
|
|
378
|
+
* core.events.listen(UserRegistered, SendWelcomeEmail)
|
|
379
|
+
*
|
|
380
|
+
* // Dispatch event
|
|
381
|
+
* await core.events.dispatch(new UserRegistered(user))
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
declare class EventManager {
|
|
385
|
+
private core;
|
|
386
|
+
/**
|
|
387
|
+
* Listener registry.
|
|
388
|
+
* Key: event class or event name
|
|
389
|
+
* Value: listener registrations
|
|
390
|
+
*/
|
|
391
|
+
private listeners;
|
|
392
|
+
/**
|
|
393
|
+
* Broadcast manager (optional, injected by `orbit-broadcasting`).
|
|
394
|
+
*/
|
|
395
|
+
private broadcastManager;
|
|
396
|
+
/**
|
|
397
|
+
* Queue manager (optional, injected by `orbit-queue`).
|
|
398
|
+
*/
|
|
399
|
+
private queueManager;
|
|
400
|
+
constructor(core: PlanetCore);
|
|
401
|
+
/**
|
|
402
|
+
* Register the broadcast manager (called by `orbit-broadcasting`).
|
|
403
|
+
*/
|
|
404
|
+
setBroadcastManager(manager: EventManager['broadcastManager']): void;
|
|
405
|
+
/**
|
|
406
|
+
* Register the queue manager (called by `orbit-queue`).
|
|
407
|
+
*/
|
|
408
|
+
setQueueManager(manager: EventManager['queueManager']): void;
|
|
409
|
+
/**
|
|
410
|
+
* Register an event listener.
|
|
411
|
+
*
|
|
412
|
+
* @param event - Event class or event name
|
|
413
|
+
* @param listener - Listener instance or listener class
|
|
414
|
+
* @param options - Optional queue options
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* // Synchronous listener
|
|
419
|
+
* core.events.listen(UserRegistered, SendWelcomeEmail)
|
|
420
|
+
*
|
|
421
|
+
* // Queued listener (async)
|
|
422
|
+
* core.events.listen(UserRegistered, SendWelcomeEmail, {
|
|
423
|
+
* queue: 'emails',
|
|
424
|
+
* delay: 60
|
|
425
|
+
* })
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
listen<TEvent extends Event>(event: string | (new (...args: unknown[]) => TEvent), listener: Listener<TEvent> | (new () => Listener<TEvent>), options?: {
|
|
429
|
+
queue?: string;
|
|
430
|
+
connection?: string;
|
|
431
|
+
delay?: number;
|
|
432
|
+
}): void;
|
|
433
|
+
/**
|
|
434
|
+
* Remove an event listener.
|
|
435
|
+
*
|
|
436
|
+
* @param event - Event class or event name
|
|
437
|
+
* @param listener - Listener to remove
|
|
438
|
+
*/
|
|
439
|
+
unlisten<TEvent extends Event>(event: string | (new (...args: unknown[]) => TEvent), listener: Listener<TEvent> | (new () => Listener<TEvent>)): void;
|
|
440
|
+
/**
|
|
441
|
+
* Dispatch an event.
|
|
442
|
+
*
|
|
443
|
+
* Runs all registered listeners. If a listener implements `ShouldQueue` or
|
|
444
|
+
* has queue options, the listener will be pushed to the queue for async execution.
|
|
445
|
+
*
|
|
446
|
+
* @param event - Event instance
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* await core.events.dispatch(new UserRegistered(user))
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
dispatch<TEvent extends Event>(event: TEvent): Promise<void>;
|
|
454
|
+
/**
|
|
455
|
+
* Serialize an event (for queueing).
|
|
456
|
+
*/
|
|
457
|
+
private serializeEvent;
|
|
458
|
+
/**
|
|
459
|
+
* Get all registered listeners.
|
|
460
|
+
*/
|
|
461
|
+
getListeners(event?: string | (new () => Event)): ListenerRegistration[];
|
|
462
|
+
/**
|
|
463
|
+
* Clear all listeners.
|
|
464
|
+
*/
|
|
465
|
+
clear(): void;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Standard logger interface.
|
|
470
|
+
*
|
|
471
|
+
* PSR-3 inspired API for easy swapping (e.g., Winston, Pino).
|
|
472
|
+
*/
|
|
473
|
+
interface Logger {
|
|
474
|
+
debug(message: string, ...args: unknown[]): void;
|
|
475
|
+
info(message: string, ...args: unknown[]): void;
|
|
476
|
+
warn(message: string, ...args: unknown[]): void;
|
|
477
|
+
error(message: string, ...args: unknown[]): void;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Default console logger implementation.
|
|
481
|
+
*/
|
|
482
|
+
declare class ConsoleLogger implements Logger {
|
|
483
|
+
debug(message: string, ...args: unknown[]): void;
|
|
484
|
+
info(message: string, ...args: unknown[]): void;
|
|
485
|
+
warn(message: string, ...args: unknown[]): void;
|
|
486
|
+
error(message: string, ...args: unknown[]): void;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
type GlobalProcessErrorKind = 'unhandledRejection' | 'uncaughtException';
|
|
490
|
+
type GlobalProcessErrorHandlerContext = {
|
|
491
|
+
core?: PlanetCore;
|
|
492
|
+
kind: GlobalProcessErrorKind;
|
|
493
|
+
error: unknown;
|
|
494
|
+
isProduction: boolean;
|
|
495
|
+
timestamp: number;
|
|
496
|
+
logLevel?: 'error' | 'warn' | 'info' | 'none';
|
|
497
|
+
logMessage?: string;
|
|
498
|
+
exit?: boolean;
|
|
499
|
+
exitCode?: number;
|
|
500
|
+
gracePeriodMs?: number;
|
|
501
|
+
};
|
|
502
|
+
type GlobalErrorHandlersMode = 'log' | 'exit' | 'exitInProduction';
|
|
503
|
+
type RegisterGlobalErrorHandlersOptions = {
|
|
504
|
+
core?: PlanetCore;
|
|
505
|
+
logger?: Logger;
|
|
506
|
+
mode?: GlobalErrorHandlersMode;
|
|
507
|
+
exitCode?: number;
|
|
508
|
+
gracePeriodMs?: number;
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Register process-level error handlers (`unhandledRejection` / `uncaughtException`).
|
|
512
|
+
*
|
|
513
|
+
* - `mode: "log"`: only log/report
|
|
514
|
+
* - `mode: "exit"`: report then `process.exit(exitCode)`
|
|
515
|
+
* - `mode: "exitInProduction"`: exit only when `NODE_ENV=production` (default)
|
|
516
|
+
*/
|
|
517
|
+
declare function registerGlobalErrorHandlers(options?: RegisterGlobalErrorHandlersOptions): () => void;
|
|
518
|
+
|
|
519
|
+
type FilterCallback<T = unknown> = (value: T, ...args: unknown[]) => Promise<T> | T;
|
|
520
|
+
type ActionCallback<TArgs = unknown> = (args: TArgs) => Promise<void> | void;
|
|
521
|
+
declare class HookManager {
|
|
522
|
+
private filters;
|
|
523
|
+
private actions;
|
|
524
|
+
/**
|
|
525
|
+
* Register a filter hook.
|
|
526
|
+
*
|
|
527
|
+
* Filters are used to transform a value (input/output).
|
|
528
|
+
*
|
|
529
|
+
* @template T - The type of value being filtered.
|
|
530
|
+
* @param hook - The name of the hook.
|
|
531
|
+
* @param callback - The callback function to execute.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* core.hooks.addFilter('content', async (content: string) => {
|
|
536
|
+
* return content.toUpperCase();
|
|
537
|
+
* });
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
addFilter<T = unknown>(hook: string, callback: FilterCallback<T>): void;
|
|
541
|
+
/**
|
|
542
|
+
* Apply all registered filters sequentially.
|
|
543
|
+
*
|
|
544
|
+
* Each callback receives the previous callback's return value.
|
|
545
|
+
*
|
|
546
|
+
* @template T - The type of value being filtered.
|
|
547
|
+
* @param hook - The name of the hook.
|
|
548
|
+
* @param initialValue - The initial value to filter.
|
|
549
|
+
* @param args - Additional arguments to pass to the callbacks.
|
|
550
|
+
* @returns The final filtered value.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```typescript
|
|
554
|
+
* const content = await core.hooks.applyFilters('content', 'hello world');
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
applyFilters<T = unknown>(hook: string, initialValue: T, ...args: unknown[]): Promise<T>;
|
|
558
|
+
/**
|
|
559
|
+
* Register an action hook.
|
|
560
|
+
*
|
|
561
|
+
* Actions are for side effects (no return value).
|
|
562
|
+
*
|
|
563
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
564
|
+
* @param hook - The name of the hook.
|
|
565
|
+
* @param callback - The callback function to execute.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* core.hooks.addAction('user_registered', async (user: User) => {
|
|
570
|
+
* await sendWelcomeEmail(user);
|
|
571
|
+
* });
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>): void;
|
|
575
|
+
/**
|
|
576
|
+
* Run all registered actions sequentially.
|
|
577
|
+
*
|
|
578
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
579
|
+
* @param hook - The name of the hook.
|
|
580
|
+
* @param args - The arguments to pass to the callbacks.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```typescript
|
|
584
|
+
* await core.hooks.doAction('user_registered', user);
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
doAction<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
type ApiSuccess<T> = {
|
|
591
|
+
success: true;
|
|
592
|
+
data: T;
|
|
593
|
+
};
|
|
594
|
+
type ApiFailure = {
|
|
595
|
+
success: false;
|
|
596
|
+
error: {
|
|
597
|
+
message: string;
|
|
598
|
+
code?: string;
|
|
599
|
+
details?: unknown;
|
|
600
|
+
};
|
|
601
|
+
};
|
|
602
|
+
declare function ok<T>(data: T): ApiSuccess<T>;
|
|
603
|
+
declare function fail(message: string, code?: string, details?: unknown): ApiFailure;
|
|
604
|
+
declare function jsonSuccess<T>(c: GravitoContext, data: T, status?: ContentfulStatusCode): Response;
|
|
605
|
+
declare function jsonFail(c: GravitoContext, message: string, status?: ContentfulStatusCode, code?: string, details?: unknown): Response;
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* ServiceProvider - The foundation for modular service registration.
|
|
609
|
+
*
|
|
610
|
+
* Service providers are the central place to configure your application.
|
|
611
|
+
* They bind services to the container and bootstrap application features.
|
|
612
|
+
*
|
|
613
|
+
* Lifecycle:
|
|
614
|
+
* 1. register() - Called during registration phase (sync or async)
|
|
615
|
+
* 2. boot() - Called after ALL providers have registered
|
|
616
|
+
*
|
|
617
|
+
* @since 1.0.0
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* class DatabaseServiceProvider extends ServiceProvider {
|
|
621
|
+
* register(container: Container) {
|
|
622
|
+
* container.singleton('db', () => new DatabaseManager());
|
|
623
|
+
* }
|
|
624
|
+
*
|
|
625
|
+
* boot(core: PlanetCore) {
|
|
626
|
+
* const db = core.container.make<DatabaseManager>('db');
|
|
627
|
+
* db.setDefaultConnection(core.config.get('database.default'));
|
|
628
|
+
* }
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
declare abstract class ServiceProvider {
|
|
633
|
+
/**
|
|
634
|
+
* Reference to the application core instance.
|
|
635
|
+
* Set during provider registration.
|
|
636
|
+
*/
|
|
637
|
+
protected core?: PlanetCore;
|
|
638
|
+
/**
|
|
639
|
+
* Whether this provider should be deferred.
|
|
640
|
+
* Deferred providers are only registered when one of their
|
|
641
|
+
* provided services is actually requested from the container.
|
|
642
|
+
*/
|
|
643
|
+
deferred: boolean;
|
|
644
|
+
/**
|
|
645
|
+
* Get the services provided by this provider.
|
|
646
|
+
* Used for deferred loading - provider is only loaded when
|
|
647
|
+
* one of these services is requested.
|
|
648
|
+
*
|
|
649
|
+
* @returns Array of service keys this provider offers
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* provides(): string[] {
|
|
654
|
+
* return ['db', 'db.connection'];
|
|
655
|
+
* }
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
provides(): string[];
|
|
659
|
+
/**
|
|
660
|
+
* Register bindings in the container.
|
|
661
|
+
*
|
|
662
|
+
* This method is called during the registration phase.
|
|
663
|
+
* **Warning**: Do not resolve services from other providers here,
|
|
664
|
+
* as they may not be registered yet.
|
|
665
|
+
*
|
|
666
|
+
* Supports both synchronous and asynchronous registration.
|
|
667
|
+
*
|
|
668
|
+
* @param container - The IoC container instance
|
|
669
|
+
*/
|
|
670
|
+
abstract register(container: Container): void | Promise<void>;
|
|
671
|
+
/**
|
|
672
|
+
* Bootstrap any application services.
|
|
673
|
+
*
|
|
674
|
+
* This method is called after ALL providers have registered.
|
|
675
|
+
* You can safely resolve services from the container here.
|
|
676
|
+
*
|
|
677
|
+
* @param core - The PlanetCore application instance
|
|
678
|
+
*/
|
|
679
|
+
boot?(core: PlanetCore): void | Promise<void>;
|
|
680
|
+
/**
|
|
681
|
+
* Set the core instance reference.
|
|
682
|
+
* Called internally by the application during registration.
|
|
683
|
+
*
|
|
684
|
+
* @internal
|
|
685
|
+
*/
|
|
686
|
+
setCore(core: PlanetCore): void;
|
|
687
|
+
/**
|
|
688
|
+
* Merge configuration from a file into the application config.
|
|
689
|
+
*
|
|
690
|
+
* @param config - The ConfigManager instance
|
|
691
|
+
* @param key - The configuration key to set
|
|
692
|
+
* @param value - The configuration value or object
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* this.mergeConfig(config, 'database', {
|
|
697
|
+
* default: 'mysql',
|
|
698
|
+
* connections: { ... }
|
|
699
|
+
* });
|
|
700
|
+
* ```
|
|
701
|
+
*/
|
|
702
|
+
protected mergeConfig(config: ConfigManager, key: string, value: unknown): void;
|
|
703
|
+
/**
|
|
704
|
+
* Merge configuration from an async loader.
|
|
705
|
+
* Useful for loading config from .ts files dynamically.
|
|
706
|
+
*
|
|
707
|
+
* @param config - The ConfigManager instance
|
|
708
|
+
* @param key - The configuration key
|
|
709
|
+
* @param loader - Async function that returns config value
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```typescript
|
|
713
|
+
* await this.mergeConfigFrom(config, 'database', async () => {
|
|
714
|
+
* return (await import('./config/database')).default;
|
|
715
|
+
* });
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
protected mergeConfigFrom(config: ConfigManager, key: string, loader: () => Promise<unknown>): Promise<void>;
|
|
719
|
+
/**
|
|
720
|
+
* Paths that should be published by the CLI.
|
|
721
|
+
* Maps source paths to destination paths.
|
|
722
|
+
*/
|
|
723
|
+
private static publishables;
|
|
724
|
+
/**
|
|
725
|
+
* Register paths to be published.
|
|
726
|
+
* Used by CLI commands like `gravito vendor:publish`.
|
|
727
|
+
*
|
|
728
|
+
* @param paths - Map of source to destination paths
|
|
729
|
+
* @param group - Optional group name for selective publishing
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```typescript
|
|
733
|
+
* this.publishes({
|
|
734
|
+
* './config/cache.ts': 'config/cache.ts',
|
|
735
|
+
* './views/errors': 'resources/views/errors'
|
|
736
|
+
* }, 'config');
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
protected publishes(paths: Record<string, string>, group?: string): void;
|
|
740
|
+
/**
|
|
741
|
+
* Get all publishable paths for a group.
|
|
742
|
+
*
|
|
743
|
+
* @param group - The group name (defaults to provider class name)
|
|
744
|
+
* @returns Map of source to destination paths
|
|
745
|
+
*/
|
|
746
|
+
static getPublishables(group?: string): Map<string, string>;
|
|
747
|
+
/**
|
|
748
|
+
* Get all publish groups.
|
|
749
|
+
*
|
|
750
|
+
* @returns Array of group names
|
|
751
|
+
*/
|
|
752
|
+
static getPublishGroups(): string[];
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
declare class Route {
|
|
756
|
+
private router;
|
|
757
|
+
private method;
|
|
758
|
+
private path;
|
|
759
|
+
private options;
|
|
760
|
+
constructor(router: Router, method: string, path: string, options: RouteOptions);
|
|
761
|
+
/**
|
|
762
|
+
* Name the route
|
|
763
|
+
*/
|
|
764
|
+
name(name: string): this;
|
|
765
|
+
static get(path: string, handler: RouteHandler): Route;
|
|
766
|
+
static get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
767
|
+
static post(path: string, handler: RouteHandler): Route;
|
|
768
|
+
static post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
769
|
+
static put(path: string, handler: RouteHandler): Route;
|
|
770
|
+
static put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
771
|
+
static delete(path: string, handler: RouteHandler): Route;
|
|
772
|
+
static delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
773
|
+
static patch(path: string, handler: RouteHandler): Route;
|
|
774
|
+
static patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
775
|
+
static resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
|
|
776
|
+
static prefix(path: string): RouteGroup;
|
|
777
|
+
static middleware(...handlers: any[]): RouteGroup;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
type ControllerClass = new (core: PlanetCore) => Record<string, unknown>;
|
|
781
|
+
type RouteHandler = GravitoHandler | [ControllerClass, string];
|
|
782
|
+
/**
|
|
783
|
+
* Interface for FormRequest classes (from @gravito/impulse).
|
|
784
|
+
* Used for duck-typing detection without hard dependency.
|
|
785
|
+
*/
|
|
786
|
+
interface FormRequestLike {
|
|
787
|
+
schema: unknown;
|
|
788
|
+
source?: string;
|
|
789
|
+
validate?(ctx: unknown): Promise<{
|
|
790
|
+
success: boolean;
|
|
791
|
+
data?: unknown;
|
|
792
|
+
error?: unknown;
|
|
793
|
+
}>;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Type for FormRequest class constructor
|
|
797
|
+
*/
|
|
798
|
+
type FormRequestClass = new () => FormRequestLike;
|
|
799
|
+
interface RouteOptions {
|
|
800
|
+
prefix?: string;
|
|
801
|
+
domain?: string;
|
|
802
|
+
middleware?: GravitoMiddleware[];
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* RouteGroup
|
|
806
|
+
* Helper class for chained route configuration (prefix, domain, etc.)
|
|
807
|
+
*/
|
|
808
|
+
declare class RouteGroup {
|
|
809
|
+
private router;
|
|
810
|
+
private options;
|
|
811
|
+
constructor(router: Router, options: RouteOptions);
|
|
812
|
+
/**
|
|
813
|
+
* Add a prefix to the current group
|
|
814
|
+
*/
|
|
815
|
+
prefix(path: string): RouteGroup;
|
|
816
|
+
/**
|
|
817
|
+
* Add middleware to the current group.
|
|
818
|
+
* Accepts individual handlers or arrays of handlers.
|
|
819
|
+
*/
|
|
820
|
+
middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
|
|
821
|
+
/**
|
|
822
|
+
* Define routes within this group
|
|
823
|
+
*/
|
|
824
|
+
group(callback: (router: Router | RouteGroup) => void): void;
|
|
825
|
+
get(path: string, handler: RouteHandler): Route;
|
|
826
|
+
get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
827
|
+
post(path: string, handler: RouteHandler): Route;
|
|
828
|
+
post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
829
|
+
put(path: string, handler: RouteHandler): Route;
|
|
830
|
+
put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
831
|
+
delete(path: string, handler: RouteHandler): Route;
|
|
832
|
+
delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
833
|
+
patch(path: string, handler: RouteHandler): Route;
|
|
834
|
+
patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
835
|
+
resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Gravito Router
|
|
839
|
+
*
|
|
840
|
+
* Provides a Laravel-like fluent API for defining routes.
|
|
841
|
+
* Supports:
|
|
842
|
+
* - Controller-based routing: router.get('/', [HomeController, 'index'])
|
|
843
|
+
* - Route groups with prefixes: router.prefix('/api').group(...)
|
|
844
|
+
* - Domain-based routing: router.domain('api.app').group(...)
|
|
845
|
+
* - Middleware chaining: router.middleware(auth).group(...)
|
|
846
|
+
* - FormRequest validation: router.post('/users', StoreUserRequest, [UserController, 'store'])
|
|
847
|
+
*/
|
|
848
|
+
declare class Router {
|
|
849
|
+
private core;
|
|
850
|
+
routes: Array<{
|
|
851
|
+
method: string;
|
|
852
|
+
path: string;
|
|
853
|
+
}>;
|
|
854
|
+
private controllers;
|
|
855
|
+
private namedRoutes;
|
|
856
|
+
private bindings;
|
|
857
|
+
/**
|
|
858
|
+
* Compile all registered routes into a flat array for caching or manifest generation.
|
|
859
|
+
*/
|
|
860
|
+
compile(): {
|
|
861
|
+
method: string;
|
|
862
|
+
path: string;
|
|
863
|
+
name?: string;
|
|
864
|
+
domain?: string | undefined;
|
|
865
|
+
}[];
|
|
866
|
+
/**
|
|
867
|
+
* Register a named route
|
|
868
|
+
*/
|
|
869
|
+
registerName(name: string, method: string, path: string, options?: RouteOptions): void;
|
|
870
|
+
/**
|
|
871
|
+
* Generate a URL from a named route.
|
|
872
|
+
*/
|
|
873
|
+
url(name: string, params?: Record<string, string | number>, query?: Record<string, string | number | boolean | null | undefined>): string;
|
|
874
|
+
/**
|
|
875
|
+
* Export named routes as a serializable manifest (for caching).
|
|
876
|
+
*/
|
|
877
|
+
exportNamedRoutes(): Record<string, {
|
|
878
|
+
method: string;
|
|
879
|
+
path: string;
|
|
880
|
+
domain?: string;
|
|
881
|
+
}>;
|
|
882
|
+
/**
|
|
883
|
+
* Load named routes from a manifest (for caching).
|
|
884
|
+
*/
|
|
885
|
+
loadNamedRoutes(manifest: Record<string, {
|
|
886
|
+
method: string;
|
|
887
|
+
path: string;
|
|
888
|
+
domain?: string;
|
|
889
|
+
}>): void;
|
|
890
|
+
/**
|
|
891
|
+
* Register a route model binding.
|
|
892
|
+
*/
|
|
893
|
+
bind(param: string, resolver: (id: string) => Promise<unknown>): void;
|
|
894
|
+
/**
|
|
895
|
+
* Register a route model binding for a Model class.
|
|
896
|
+
*/
|
|
897
|
+
model(param: string, modelClass: unknown): void;
|
|
898
|
+
constructor(core: PlanetCore);
|
|
899
|
+
/**
|
|
900
|
+
* Start a route group with a prefix
|
|
901
|
+
*/
|
|
902
|
+
prefix(path: string): RouteGroup;
|
|
903
|
+
/**
|
|
904
|
+
* Start a route group with a domain constraint
|
|
905
|
+
*/
|
|
906
|
+
domain(host: string): RouteGroup;
|
|
907
|
+
/**
|
|
908
|
+
* Start a route group with middleware.
|
|
909
|
+
* Accepts individual handlers or arrays of handlers.
|
|
910
|
+
*/
|
|
911
|
+
middleware(...handlers: (GravitoMiddleware | GravitoMiddleware[])[]): RouteGroup;
|
|
912
|
+
/**
|
|
913
|
+
* Register a GET route.
|
|
914
|
+
*
|
|
915
|
+
* @param path - The URL path for the route.
|
|
916
|
+
* @param handler - The handler function or controller method.
|
|
917
|
+
* @returns The registered Route instance for chaining.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```typescript
|
|
921
|
+
* router.get('/users', [UserController, 'index']);
|
|
922
|
+
* ```
|
|
923
|
+
*/
|
|
924
|
+
get(path: string, handler: RouteHandler): Route;
|
|
925
|
+
/**
|
|
926
|
+
* Register a GET route with a FormRequest for validation.
|
|
927
|
+
*
|
|
928
|
+
* @param path - The URL path.
|
|
929
|
+
* @param request - The FormRequest class for validation.
|
|
930
|
+
* @param handler - The handler function or controller method.
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```typescript
|
|
934
|
+
* router.get('/search', SearchRequest, [Controller, 'search']);
|
|
935
|
+
* ```
|
|
936
|
+
*/
|
|
937
|
+
get(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
938
|
+
/**
|
|
939
|
+
* Register a POST route.
|
|
940
|
+
*
|
|
941
|
+
* @param path - The URL path.
|
|
942
|
+
* @param handler - The handler function or controller method.
|
|
943
|
+
* @returns The registered Route instance.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```typescript
|
|
947
|
+
* router.post('/users', [UserController, 'store']);
|
|
948
|
+
* ```
|
|
949
|
+
*/
|
|
950
|
+
post(path: string, handler: RouteHandler): Route;
|
|
951
|
+
/**
|
|
952
|
+
* Register a POST route with validation.
|
|
953
|
+
*
|
|
954
|
+
* @param path - The URL path.
|
|
955
|
+
* @param request - The FormRequest class.
|
|
956
|
+
* @param handler - The handler.
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* ```typescript
|
|
960
|
+
* router.post('/users', StoreUserRequest, [UserController, 'store']);
|
|
961
|
+
* ```
|
|
962
|
+
*/
|
|
963
|
+
post(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
964
|
+
/**
|
|
965
|
+
* Register a PUT route.
|
|
966
|
+
*
|
|
967
|
+
* @param path - The URL path.
|
|
968
|
+
* @param handler - The handler function.
|
|
969
|
+
* @returns The registered Route instance.
|
|
970
|
+
*/
|
|
971
|
+
put(path: string, handler: RouteHandler): Route;
|
|
972
|
+
put(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
973
|
+
/**
|
|
974
|
+
* Register a DELETE route.
|
|
975
|
+
*
|
|
976
|
+
* @param path - The URL path.
|
|
977
|
+
* @param handler - The handler function.
|
|
978
|
+
* @returns The registered Route instance.
|
|
979
|
+
*/
|
|
980
|
+
delete(path: string, handler: RouteHandler): Route;
|
|
981
|
+
delete(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
982
|
+
/**
|
|
983
|
+
* Register a PATCH route.
|
|
984
|
+
*
|
|
985
|
+
* @param path - The URL path.
|
|
986
|
+
* @param handler - The handler function.
|
|
987
|
+
* @returns The registered Route instance.
|
|
988
|
+
*/
|
|
989
|
+
patch(path: string, handler: RouteHandler): Route;
|
|
990
|
+
patch(path: string, request: FormRequestClass, handler: RouteHandler): Route;
|
|
991
|
+
/**
|
|
992
|
+
* Register a resource route (Laravel-style).
|
|
993
|
+
*/
|
|
994
|
+
resource(name: string, controller: ControllerClass, options?: ResourceOptions): void;
|
|
995
|
+
/**
|
|
996
|
+
* Internal Request Registration
|
|
997
|
+
*/
|
|
998
|
+
req(method: HttpMethod, path: string, requestOrHandler: FormRequestClass | RouteHandler, handler?: RouteHandler, options?: RouteOptions): Route;
|
|
999
|
+
/**
|
|
1000
|
+
* Resolve Controller Instance and Method
|
|
1001
|
+
*/
|
|
1002
|
+
private resolveControllerHandler;
|
|
1003
|
+
}
|
|
1004
|
+
type ResourceAction = 'index' | 'create' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
|
|
1005
|
+
interface ResourceOptions {
|
|
1006
|
+
only?: ResourceAction[];
|
|
1007
|
+
except?: ResourceAction[];
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
interface EncrypterOptions {
|
|
1011
|
+
key: string;
|
|
1012
|
+
cipher?: string;
|
|
1013
|
+
}
|
|
1014
|
+
declare class Encrypter {
|
|
1015
|
+
private algorithm;
|
|
1016
|
+
private key;
|
|
1017
|
+
constructor(options: EncrypterOptions);
|
|
1018
|
+
/**
|
|
1019
|
+
* Encrypt a value
|
|
1020
|
+
*/
|
|
1021
|
+
encrypt(value: unknown, serialize?: boolean): string;
|
|
1022
|
+
/**
|
|
1023
|
+
* Decrypt a value
|
|
1024
|
+
*/
|
|
1025
|
+
decrypt(payload: string, deserialize?: boolean): unknown;
|
|
1026
|
+
private hash;
|
|
1027
|
+
private validPayload;
|
|
1028
|
+
private validMac;
|
|
1029
|
+
/**
|
|
1030
|
+
* Generate a new key
|
|
1031
|
+
*/
|
|
1032
|
+
static generateKey(cipher?: string): string;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Hashing interface
|
|
1037
|
+
*/
|
|
1038
|
+
interface Hasher {
|
|
1039
|
+
/**
|
|
1040
|
+
* Hash the given value
|
|
1041
|
+
*/
|
|
1042
|
+
make(value: string, options?: Record<string, unknown>): Promise<string>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Check the given plain value against a hash
|
|
1045
|
+
*/
|
|
1046
|
+
check(value: string, hashedValue: string): Promise<boolean>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Check if the given hash has been hashed using the given options
|
|
1049
|
+
*/
|
|
1050
|
+
needsRehash(hashedValue: string, options?: Record<string, unknown>): boolean;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Bun Hasher
|
|
1054
|
+
* Uses Bun's native password hashing (bcrypt by default)
|
|
1055
|
+
*/
|
|
1056
|
+
declare class BunHasher implements Hasher {
|
|
1057
|
+
make(value: string, options?: {
|
|
1058
|
+
algorithm?: 'bcrypt' | 'argon2id';
|
|
1059
|
+
cost?: number;
|
|
1060
|
+
}): Promise<string>;
|
|
1061
|
+
check(value: string, hashedValue: string): Promise<boolean>;
|
|
1062
|
+
needsRehash(_hashedValue: string, _options?: Record<string, unknown>): boolean;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* @fileoverview PlanetCore - The Heart of Gravito Framework
|
|
1067
|
+
*
|
|
1068
|
+
* The micro-kernel that orchestrates the entire Galaxy Architecture.
|
|
1069
|
+
* Manages HTTP routing, middleware, error handling, and orbit integration.
|
|
1070
|
+
*
|
|
1071
|
+
* @module @gravito/core
|
|
1072
|
+
* @since 1.0.0
|
|
1073
|
+
*/
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* CacheService interface for orbit-injected cache
|
|
1077
|
+
* Orbits implementing cache should conform to this interface
|
|
1078
|
+
*/
|
|
1079
|
+
interface CacheService {
|
|
1080
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
1081
|
+
set(key: string, value: unknown, ttl?: number): Promise<void>;
|
|
1082
|
+
delete(key: string): Promise<void>;
|
|
1083
|
+
clear(): Promise<void>;
|
|
1084
|
+
remember<T>(key: string, ttl: number, callback: () => Promise<T>): Promise<T>;
|
|
1085
|
+
}
|
|
1086
|
+
interface ViewService {
|
|
1087
|
+
render(view: string, data?: Record<string, unknown>, options?: Record<string, unknown>): string;
|
|
1088
|
+
}
|
|
1089
|
+
type ErrorHandlerContext = {
|
|
1090
|
+
core: PlanetCore;
|
|
1091
|
+
c: GravitoContext;
|
|
1092
|
+
error: unknown;
|
|
1093
|
+
isProduction: boolean;
|
|
1094
|
+
accept: string;
|
|
1095
|
+
wantsHtml: boolean;
|
|
1096
|
+
status: ContentfulStatusCode;
|
|
1097
|
+
payload: ReturnType<typeof fail>;
|
|
1098
|
+
logLevel?: 'error' | 'warn' | 'info' | 'none';
|
|
1099
|
+
logMessage?: string;
|
|
1100
|
+
html?: {
|
|
1101
|
+
templates: string[];
|
|
1102
|
+
data: Record<string, unknown>;
|
|
1103
|
+
};
|
|
1104
|
+
};
|
|
1105
|
+
interface GravitoOrbit {
|
|
1106
|
+
install(core: PlanetCore): void | Promise<void>;
|
|
1107
|
+
}
|
|
1108
|
+
type GravitoConfig = {
|
|
1109
|
+
logger?: Logger;
|
|
1110
|
+
config?: Record<string, unknown>;
|
|
1111
|
+
orbits?: (new () => GravitoOrbit)[] | GravitoOrbit[];
|
|
1112
|
+
/**
|
|
1113
|
+
* HTTP Adapter to use. Defaults to PhotonAdapter.
|
|
1114
|
+
* @since 2.0.0
|
|
1115
|
+
*/
|
|
1116
|
+
adapter?: HttpAdapter;
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
declare class PlanetCore {
|
|
1120
|
+
/**
|
|
1121
|
+
* The HTTP adapter used by this core instance.
|
|
1122
|
+
* @since 2.0.0
|
|
1123
|
+
*/
|
|
1124
|
+
private _adapter;
|
|
1125
|
+
/**
|
|
1126
|
+
* Access the underlying Photon app instance.
|
|
1127
|
+
* @deprecated Use adapter methods for new code. This property is kept for backward compatibility.
|
|
1128
|
+
*/
|
|
1129
|
+
get app(): unknown;
|
|
1130
|
+
/**
|
|
1131
|
+
* Get the HTTP adapter instance.
|
|
1132
|
+
* @since 2.0.0
|
|
1133
|
+
*/
|
|
1134
|
+
get adapter(): HttpAdapter;
|
|
1135
|
+
logger: Logger;
|
|
1136
|
+
config: ConfigManager;
|
|
1137
|
+
hooks: HookManager;
|
|
1138
|
+
events: EventManager;
|
|
1139
|
+
router: Router;
|
|
1140
|
+
container: Container;
|
|
1141
|
+
/** @deprecated Use core.container instead */
|
|
1142
|
+
services: Map<string, unknown>;
|
|
1143
|
+
encrypter?: Encrypter;
|
|
1144
|
+
hasher: BunHasher;
|
|
1145
|
+
private providers;
|
|
1146
|
+
private deferredProviders;
|
|
1147
|
+
private bootedProviders;
|
|
1148
|
+
/**
|
|
1149
|
+
* Register a service provider.
|
|
1150
|
+
*
|
|
1151
|
+
* @param provider - The ServiceProvider instance to register.
|
|
1152
|
+
* @returns The PlanetCore instance for chaining.
|
|
1153
|
+
*
|
|
1154
|
+
* @example
|
|
1155
|
+
* ```typescript
|
|
1156
|
+
* core.register(new DatabaseServiceProvider());
|
|
1157
|
+
* ```
|
|
1158
|
+
*/
|
|
1159
|
+
register(provider: ServiceProvider): this;
|
|
1160
|
+
/**
|
|
1161
|
+
* Bootstrap the application by registering and booting providers.
|
|
1162
|
+
*
|
|
1163
|
+
* This method must be called before the application starts handling requests.
|
|
1164
|
+
* It calls `register()` on all providers first, then `boot()` on all providers.
|
|
1165
|
+
*
|
|
1166
|
+
* Supports async register() methods.
|
|
1167
|
+
*
|
|
1168
|
+
* @returns Promise that resolves when bootstrapping is complete.
|
|
1169
|
+
*/
|
|
1170
|
+
bootstrap(): Promise<void>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Setup deferred provider resolution.
|
|
1173
|
+
* Wraps container.make to auto-register deferred providers on first request.
|
|
1174
|
+
*
|
|
1175
|
+
* @internal
|
|
1176
|
+
*/
|
|
1177
|
+
private setupDeferredProviderResolution;
|
|
1178
|
+
/**
|
|
1179
|
+
* Register a deferred provider on-demand.
|
|
1180
|
+
*
|
|
1181
|
+
* @internal
|
|
1182
|
+
*/
|
|
1183
|
+
private registerDeferredProvider;
|
|
1184
|
+
/**
|
|
1185
|
+
* Boot a single provider if not already booted.
|
|
1186
|
+
*
|
|
1187
|
+
* @internal
|
|
1188
|
+
*/
|
|
1189
|
+
private bootProvider;
|
|
1190
|
+
constructor(options?: {
|
|
1191
|
+
logger?: Logger;
|
|
1192
|
+
config?: Record<string, unknown>;
|
|
1193
|
+
adapter?: HttpAdapter;
|
|
1194
|
+
});
|
|
1195
|
+
/**
|
|
1196
|
+
* Programmatically register an infrastructure module (Orbit).
|
|
1197
|
+
* @since 2.0.0
|
|
1198
|
+
*
|
|
1199
|
+
* @param orbit - The orbit class or instance to register.
|
|
1200
|
+
* @returns The PlanetCore instance for chaining.
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```typescript
|
|
1204
|
+
* await core.orbit(OrbitCache);
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
orbit(orbit: GravitoOrbit | (new () => GravitoOrbit)): Promise<this>;
|
|
1208
|
+
/**
|
|
1209
|
+
* Programmatically register a feature module (Satellite).
|
|
1210
|
+
* Alias for register() with provider support.
|
|
1211
|
+
* @since 2.0.0
|
|
1212
|
+
*
|
|
1213
|
+
* @param satellite - The provider or setup function.
|
|
1214
|
+
* @returns The PlanetCore instance for chaining.
|
|
1215
|
+
*
|
|
1216
|
+
* @example
|
|
1217
|
+
* ```typescript
|
|
1218
|
+
* await core.use(new AuthProvider());
|
|
1219
|
+
* ```
|
|
1220
|
+
*/
|
|
1221
|
+
use(satellite: ServiceProvider | ((core: PlanetCore) => void | Promise<void>)): Promise<this>;
|
|
1222
|
+
registerGlobalErrorHandlers(options?: Omit<RegisterGlobalErrorHandlersOptions, 'core'>): () => void;
|
|
1223
|
+
/**
|
|
1224
|
+
* Boot the application with a configuration object (IoC style default entry)
|
|
1225
|
+
*
|
|
1226
|
+
* @param config - The Gravito configuration object.
|
|
1227
|
+
* @returns A Promise resolving to the booted PlanetCore instance.
|
|
1228
|
+
*
|
|
1229
|
+
* @example
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* const core = await PlanetCore.boot(config);
|
|
1232
|
+
* ```
|
|
1233
|
+
*/
|
|
1234
|
+
static boot(config: GravitoConfig): Promise<PlanetCore>;
|
|
1235
|
+
/**
|
|
1236
|
+
* Mount an Orbit (a Photon app) to a path.
|
|
1237
|
+
*
|
|
1238
|
+
* @param path - The URL path to mount the orbit at.
|
|
1239
|
+
* @param orbitApp - The Photon application instance.
|
|
1240
|
+
*/
|
|
1241
|
+
mountOrbit(path: string, orbitApp: unknown): void;
|
|
1242
|
+
/**
|
|
1243
|
+
* Start the core (Liftoff).
|
|
1244
|
+
*
|
|
1245
|
+
* Returns a config object for `Bun.serve`.
|
|
1246
|
+
*
|
|
1247
|
+
* @param port - Optional port number (defaults to config or 3000).
|
|
1248
|
+
* @returns An object compatible with Bun.serve({ ... }).
|
|
1249
|
+
*
|
|
1250
|
+
* @example
|
|
1251
|
+
* ```typescript
|
|
1252
|
+
* export default core.liftoff(3000);
|
|
1253
|
+
* ```
|
|
1254
|
+
*/
|
|
1255
|
+
liftoff(port?: number): {
|
|
1256
|
+
port: number;
|
|
1257
|
+
fetch: (request: Request, server?: unknown) => Response | Promise<Response>;
|
|
1258
|
+
core: PlanetCore;
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* @fileoverview Photon Adapter Implementation
|
|
1264
|
+
*
|
|
1265
|
+
* This adapter wraps Photon to implement the Gravito HttpAdapter interface.
|
|
1266
|
+
* It serves as the default adapter and reference implementation for others.
|
|
1267
|
+
*
|
|
1268
|
+
* @module @gravito/core/adapters/photon
|
|
1269
|
+
* @since 2.0.0
|
|
1270
|
+
*/
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Wraps Photon's request object to implement GravitoRequest
|
|
1274
|
+
*/
|
|
1275
|
+
declare class PhotonRequestWrapper implements GravitoRequest {
|
|
1276
|
+
private photonCtx;
|
|
1277
|
+
constructor(photonCtx: Context);
|
|
1278
|
+
get url(): string;
|
|
1279
|
+
get method(): string;
|
|
1280
|
+
get path(): string;
|
|
1281
|
+
param(name: string): string | undefined;
|
|
1282
|
+
params(): Record<string, string>;
|
|
1283
|
+
query(name: string): string | undefined;
|
|
1284
|
+
queries(): Record<string, string | string[]>;
|
|
1285
|
+
header(name: string): string | undefined;
|
|
1286
|
+
header(): Record<string, string>;
|
|
1287
|
+
json<T = unknown>(): Promise<T>;
|
|
1288
|
+
text(): Promise<string>;
|
|
1289
|
+
formData(): Promise<FormData>;
|
|
1290
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1291
|
+
parseBody<T = unknown>(): Promise<T>;
|
|
1292
|
+
get raw(): Request;
|
|
1293
|
+
valid<T = unknown>(target: string): T;
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Wraps Photon's context to implement GravitoContext
|
|
1297
|
+
*/
|
|
1298
|
+
declare class PhotonContextWrapper<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
|
|
1299
|
+
private photonCtx;
|
|
1300
|
+
private _req;
|
|
1301
|
+
constructor(photonCtx: Context);
|
|
1302
|
+
/**
|
|
1303
|
+
* Create a proxied instance to enable object destructuring of context variables
|
|
1304
|
+
* This allows: async list({ userService }: Context)
|
|
1305
|
+
*/
|
|
1306
|
+
static create<V extends GravitoVariables = GravitoVariables>(photonCtx: Context): GravitoContext<V>;
|
|
1307
|
+
get req(): GravitoRequest;
|
|
1308
|
+
json<T>(data: T, status?: number): Response;
|
|
1309
|
+
text(text: string, status?: number): Response;
|
|
1310
|
+
html(html: string, status?: number): Response;
|
|
1311
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
1312
|
+
body(data: BodyInit | null, status?: number): Response;
|
|
1313
|
+
stream(stream: ReadableStream, status?: number): Response;
|
|
1314
|
+
notFound(message?: string): Response;
|
|
1315
|
+
forbidden(message?: string): Response;
|
|
1316
|
+
unauthorized(message?: string): Response;
|
|
1317
|
+
badRequest(message?: string): Response;
|
|
1318
|
+
header(name: string): string | undefined;
|
|
1319
|
+
header(name: string, value: string, options?: {
|
|
1320
|
+
append?: boolean;
|
|
1321
|
+
}): void;
|
|
1322
|
+
status(code: StatusCode): void;
|
|
1323
|
+
get<K extends keyof V>(key: K): V[K];
|
|
1324
|
+
set<K extends keyof V>(key: K, value: V[K]): void;
|
|
1325
|
+
get executionCtx(): ExecutionContext | undefined;
|
|
1326
|
+
get env(): Record<string, unknown> | undefined;
|
|
1327
|
+
get native(): Context;
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Default HTTP adapter using the optimized Gravito Core Engine.
|
|
1331
|
+
*
|
|
1332
|
+
* This adapter provides a consistent interface that can be
|
|
1333
|
+
* swapped out for other implementations without changing application code.
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```typescript
|
|
1337
|
+
* import { GravitoAdapter } from '@gravito/core'
|
|
1338
|
+
*
|
|
1339
|
+
* const adapter = new GravitoAdapter()
|
|
1340
|
+
*
|
|
1341
|
+
* // Register routes
|
|
1342
|
+
* adapter.route('get', '/hello', async (ctx) => {
|
|
1343
|
+
* return ctx.json({ message: 'Hello, World!' })
|
|
1344
|
+
* })
|
|
1345
|
+
* ```
|
|
1346
|
+
*/
|
|
1347
|
+
declare class PhotonAdapter<V extends GravitoVariables = GravitoVariables> implements HttpAdapter<V> {
|
|
1348
|
+
private config;
|
|
1349
|
+
readonly name = "photon";
|
|
1350
|
+
readonly version = "1.0.0";
|
|
1351
|
+
private app;
|
|
1352
|
+
constructor(config?: AdapterConfig, photonInstance?: unknown);
|
|
1353
|
+
/**
|
|
1354
|
+
* Get the underlying Photon app instance
|
|
1355
|
+
*/
|
|
1356
|
+
get native(): Photon;
|
|
1357
|
+
/**
|
|
1358
|
+
* Set the underlying Photon app instance
|
|
1359
|
+
* Used by PlanetCore during initialization
|
|
1360
|
+
*/
|
|
1361
|
+
setNative(app: Photon): void;
|
|
1362
|
+
route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
|
|
1363
|
+
routes(routes: RouteDefinition[]): void;
|
|
1364
|
+
use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
1365
|
+
useGlobal(...middleware: GravitoMiddleware<V>[]): void;
|
|
1366
|
+
mount(path: string, subAdapter: HttpAdapter<V>): void;
|
|
1367
|
+
onError(handler: GravitoErrorHandler<V>): void;
|
|
1368
|
+
onNotFound(handler: GravitoNotFoundHandler<V>): void;
|
|
1369
|
+
fetch: (request: Request, server?: unknown) => Response | Promise<Response>;
|
|
1370
|
+
createContext(_request: Request): GravitoContext<V>;
|
|
1371
|
+
init(): Promise<void>;
|
|
1372
|
+
shutdown(): Promise<void>;
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Create a new PhotonAdapter instance
|
|
1376
|
+
*/
|
|
1377
|
+
declare function createPhotonAdapter<V extends GravitoVariables = GravitoVariables>(config?: AdapterConfig): PhotonAdapter<V>;
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Rebranded alias for PhotonAdapter.
|
|
1381
|
+
* @category Rebranding
|
|
1382
|
+
*/
|
|
1383
|
+
declare const GravitoAdapter: typeof PhotonAdapter;
|
|
1384
|
+
type GravitoAdapter<V extends GravitoVariables = GravitoVariables> = PhotonAdapter<V>;
|
|
1385
|
+
/**
|
|
1386
|
+
* Rebranded alias for createPhotonAdapter.
|
|
1387
|
+
* @category Rebranding
|
|
1388
|
+
*/
|
|
1389
|
+
declare const createGravitoAdapter: typeof createPhotonAdapter;
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* @fileoverview Application - Enterprise Application Container
|
|
1393
|
+
*
|
|
1394
|
+
* A high-level application class that orchestrates the entire framework.
|
|
1395
|
+
* Provides a centralized entry point for enterprise applications with
|
|
1396
|
+
* auto-discovery of providers, config loading, and lifecycle management.
|
|
1397
|
+
*
|
|
1398
|
+
* @module @gravito/core
|
|
1399
|
+
* @since 2.0.0
|
|
1400
|
+
*/
|
|
1401
|
+
|
|
1402
|
+
interface ApplicationConfig {
|
|
1403
|
+
/**
|
|
1404
|
+
* Base path of the application
|
|
1405
|
+
*/
|
|
1406
|
+
basePath: string;
|
|
1407
|
+
/**
|
|
1408
|
+
* Path to the config directory (relative to basePath)
|
|
1409
|
+
* @default 'config'
|
|
1410
|
+
*/
|
|
1411
|
+
configPath?: string;
|
|
1412
|
+
/**
|
|
1413
|
+
* Path to the providers directory (relative to basePath)
|
|
1414
|
+
* @default 'src/Providers'
|
|
1415
|
+
*/
|
|
1416
|
+
providersPath?: string;
|
|
1417
|
+
/**
|
|
1418
|
+
* Environment (development, production, testing)
|
|
1419
|
+
*/
|
|
1420
|
+
env?: 'development' | 'production' | 'testing';
|
|
1421
|
+
/**
|
|
1422
|
+
* Logger instance
|
|
1423
|
+
*/
|
|
1424
|
+
logger?: Logger;
|
|
1425
|
+
/**
|
|
1426
|
+
* Initial configuration values
|
|
1427
|
+
*/
|
|
1428
|
+
config?: Record<string, unknown>;
|
|
1429
|
+
/**
|
|
1430
|
+
* Service providers to register
|
|
1431
|
+
*/
|
|
1432
|
+
providers?: ServiceProvider[];
|
|
1433
|
+
/**
|
|
1434
|
+
* Whether to auto-discover providers from providersPath
|
|
1435
|
+
* @default true
|
|
1436
|
+
*/
|
|
1437
|
+
autoDiscoverProviders?: boolean;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Application - Enterprise-grade application container.
|
|
1441
|
+
*
|
|
1442
|
+
* Provides a higher-level abstraction over PlanetCore for building
|
|
1443
|
+
* enterprise applications with convention-over-configuration patterns.
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```typescript
|
|
1447
|
+
* // Create application
|
|
1448
|
+
* const app = new Application({
|
|
1449
|
+
* basePath: import.meta.dir,
|
|
1450
|
+
* env: process.env.NODE_ENV as 'development' | 'production',
|
|
1451
|
+
* });
|
|
1452
|
+
*
|
|
1453
|
+
* // Boot the application
|
|
1454
|
+
* await app.boot();
|
|
1455
|
+
*
|
|
1456
|
+
* // Access core
|
|
1457
|
+
* export default app.core.liftoff();
|
|
1458
|
+
* ```
|
|
1459
|
+
*/
|
|
1460
|
+
declare class Application {
|
|
1461
|
+
/**
|
|
1462
|
+
* The underlying PlanetCore instance.
|
|
1463
|
+
*/
|
|
1464
|
+
readonly core: PlanetCore;
|
|
1465
|
+
/**
|
|
1466
|
+
* The IoC container.
|
|
1467
|
+
*/
|
|
1468
|
+
readonly container: Container;
|
|
1469
|
+
/**
|
|
1470
|
+
* The configuration manager.
|
|
1471
|
+
*/
|
|
1472
|
+
readonly config: ConfigManager;
|
|
1473
|
+
/**
|
|
1474
|
+
* The event manager.
|
|
1475
|
+
*/
|
|
1476
|
+
readonly events: EventManager;
|
|
1477
|
+
/**
|
|
1478
|
+
* The logger instance.
|
|
1479
|
+
*/
|
|
1480
|
+
readonly logger: Logger;
|
|
1481
|
+
/**
|
|
1482
|
+
* Application base path.
|
|
1483
|
+
*/
|
|
1484
|
+
readonly basePath: string;
|
|
1485
|
+
/**
|
|
1486
|
+
* Environment mode.
|
|
1487
|
+
*/
|
|
1488
|
+
readonly env: 'development' | 'production' | 'testing';
|
|
1489
|
+
/**
|
|
1490
|
+
* Configuration options.
|
|
1491
|
+
*/
|
|
1492
|
+
private readonly options;
|
|
1493
|
+
/**
|
|
1494
|
+
* Whether the application has been booted.
|
|
1495
|
+
*/
|
|
1496
|
+
private booted;
|
|
1497
|
+
constructor(options: ApplicationConfig);
|
|
1498
|
+
/**
|
|
1499
|
+
* Boot the application.
|
|
1500
|
+
*
|
|
1501
|
+
* This will:
|
|
1502
|
+
* 1. Load configuration files
|
|
1503
|
+
* 2. Auto-discover providers (if enabled)
|
|
1504
|
+
* 3. Register all providers
|
|
1505
|
+
* 4. Bootstrap the core
|
|
1506
|
+
*
|
|
1507
|
+
* @returns Promise that resolves when boot is complete
|
|
1508
|
+
*/
|
|
1509
|
+
boot(): Promise<this>;
|
|
1510
|
+
/**
|
|
1511
|
+
* Load configuration files from the config directory.
|
|
1512
|
+
*
|
|
1513
|
+
* @internal
|
|
1514
|
+
*/
|
|
1515
|
+
private loadConfiguration;
|
|
1516
|
+
/**
|
|
1517
|
+
* Discover and register providers from the providers directory.
|
|
1518
|
+
*
|
|
1519
|
+
* @internal
|
|
1520
|
+
*/
|
|
1521
|
+
private discoverProviders;
|
|
1522
|
+
/**
|
|
1523
|
+
* Get a service from the container.
|
|
1524
|
+
*
|
|
1525
|
+
* @param key - The service key
|
|
1526
|
+
* @returns The resolved service
|
|
1527
|
+
*/
|
|
1528
|
+
make<T>(key: string): T;
|
|
1529
|
+
/**
|
|
1530
|
+
* Check if a service is bound.
|
|
1531
|
+
*
|
|
1532
|
+
* @param key - The service key
|
|
1533
|
+
* @returns True if bound
|
|
1534
|
+
*/
|
|
1535
|
+
has(key: string): boolean;
|
|
1536
|
+
/**
|
|
1537
|
+
* Get a configuration value.
|
|
1538
|
+
*
|
|
1539
|
+
* @param key - The config key (supports dot notation)
|
|
1540
|
+
* @param defaultValue - Default value if not found
|
|
1541
|
+
* @returns The config value
|
|
1542
|
+
*/
|
|
1543
|
+
getConfig<T>(key: string, defaultValue?: T): T;
|
|
1544
|
+
/**
|
|
1545
|
+
* Create application path helper.
|
|
1546
|
+
*
|
|
1547
|
+
* @param segments - Path segments relative to base path
|
|
1548
|
+
* @returns Absolute path
|
|
1549
|
+
*/
|
|
1550
|
+
path(...segments: string[]): string;
|
|
1551
|
+
/**
|
|
1552
|
+
* Get the config path.
|
|
1553
|
+
*
|
|
1554
|
+
* @param segments - Additional path segments
|
|
1555
|
+
* @returns Absolute path to config directory
|
|
1556
|
+
*/
|
|
1557
|
+
configPath(...segments: string[]): string;
|
|
1558
|
+
/**
|
|
1559
|
+
* Check if running in production.
|
|
1560
|
+
*/
|
|
1561
|
+
isProduction(): boolean;
|
|
1562
|
+
/**
|
|
1563
|
+
* Check if running in development.
|
|
1564
|
+
*/
|
|
1565
|
+
isDevelopment(): boolean;
|
|
1566
|
+
/**
|
|
1567
|
+
* Check if running in testing.
|
|
1568
|
+
*/
|
|
1569
|
+
isTesting(): boolean;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
interface ExceptionOptions {
|
|
1573
|
+
message?: string;
|
|
1574
|
+
cause?: unknown;
|
|
1575
|
+
i18nKey?: string;
|
|
1576
|
+
i18nParams?: Record<string, string | number>;
|
|
1577
|
+
}
|
|
1578
|
+
declare abstract class GravitoException extends Error {
|
|
1579
|
+
readonly status: ContentfulStatusCode;
|
|
1580
|
+
readonly code: string;
|
|
1581
|
+
readonly i18nKey?: string;
|
|
1582
|
+
readonly i18nParams?: Record<string, string | number>;
|
|
1583
|
+
constructor(status: number, code: string, options?: ExceptionOptions);
|
|
1584
|
+
getLocalizedMessage(t: (key: string, params?: Record<string, string | number>) => string): string;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
declare class AuthenticationException extends GravitoException {
|
|
1588
|
+
constructor(message?: string);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
declare class AuthorizationException extends GravitoException {
|
|
1592
|
+
constructor(message?: string);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
declare class HttpException extends GravitoException {
|
|
1596
|
+
constructor(status: ContentfulStatusCode, options?: ExceptionOptions);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
declare class ModelNotFoundException extends GravitoException {
|
|
1600
|
+
readonly model: string;
|
|
1601
|
+
readonly id?: string | number;
|
|
1602
|
+
constructor(model: string, id?: string | number);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
interface ValidationError {
|
|
1606
|
+
field: string;
|
|
1607
|
+
message: string;
|
|
1608
|
+
code?: string;
|
|
1609
|
+
}
|
|
1610
|
+
declare class ValidationException extends GravitoException {
|
|
1611
|
+
readonly errors: ValidationError[];
|
|
1612
|
+
redirectTo?: string;
|
|
1613
|
+
input?: unknown;
|
|
1614
|
+
constructor(errors: ValidationError[], message?: string);
|
|
1615
|
+
withRedirect(url: string): this;
|
|
1616
|
+
withInput(input: unknown): this;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
interface GravitoManifest {
|
|
1620
|
+
name: string;
|
|
1621
|
+
version?: string;
|
|
1622
|
+
modules: string[];
|
|
1623
|
+
config?: GravitoConfig;
|
|
1624
|
+
}
|
|
1625
|
+
type ModuleResolver = () => Promise<any>;
|
|
1626
|
+
/**
|
|
1627
|
+
* Gravito 核心啟動引擎 (已解耦)
|
|
1628
|
+
*/
|
|
1629
|
+
declare class GravitoServer {
|
|
1630
|
+
/**
|
|
1631
|
+
* 一鍵建立並組裝伺服器
|
|
1632
|
+
* @param manifest 站點描述清單
|
|
1633
|
+
* @param resolvers 模組解析器字典
|
|
1634
|
+
* @param baseOrbits 基礎軌道模組 (例如 OrbitMonolith)
|
|
1635
|
+
*/
|
|
1636
|
+
static create(manifest: GravitoManifest, resolvers: Record<string, ModuleResolver>, baseOrbits?: any[]): Promise<PlanetCore>;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
type PathSegment = string | number;
|
|
1640
|
+
type DataPath = string | readonly PathSegment[];
|
|
1641
|
+
declare function dataGet<TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault): unknown | TDefault;
|
|
1642
|
+
declare function dataHas(target: unknown, path: DataPath | null | undefined): boolean;
|
|
1643
|
+
declare function dataSet(target: unknown, path: DataPath, setValue: unknown, overwrite?: boolean): unknown;
|
|
1644
|
+
|
|
1645
|
+
declare const Arr: {
|
|
1646
|
+
readonly get: <TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault) => unknown | TDefault;
|
|
1647
|
+
readonly has: (target: unknown, path: DataPath | null | undefined) => boolean;
|
|
1648
|
+
readonly set: (target: unknown, path: DataPath, value: unknown, overwrite?: boolean) => unknown;
|
|
1649
|
+
readonly wrap: <T>(value: T | T[] | null | undefined) => T[];
|
|
1650
|
+
readonly first: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
|
|
1651
|
+
readonly last: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
|
|
1652
|
+
readonly only: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
|
|
1653
|
+
readonly except: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
|
|
1654
|
+
readonly flatten: (items: unknown[], depth?: number) => unknown[];
|
|
1655
|
+
readonly pluck: <TItem extends Record<string, unknown>>(items: readonly TItem[], valuePath: DataPath, keyPath?: DataPath) => unknown[] | Record<string, unknown>;
|
|
1656
|
+
readonly where: <T>(items: readonly T[], callback: (value: T, index: number) => boolean) => T[];
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
interface ErrorBag {
|
|
1660
|
+
has(field: string): boolean;
|
|
1661
|
+
first(field?: string): string | undefined;
|
|
1662
|
+
get(field: string): string[];
|
|
1663
|
+
all(): Record<string, string[]>;
|
|
1664
|
+
any(): boolean;
|
|
1665
|
+
count(): number;
|
|
1666
|
+
}
|
|
1667
|
+
declare function createErrorBag(errors: Record<string, string[]>): ErrorBag;
|
|
1668
|
+
declare function errors(c: GravitoContext): ErrorBag;
|
|
1669
|
+
declare function old(c: GravitoContext, field: string, defaultValue?: unknown): unknown;
|
|
1670
|
+
|
|
1671
|
+
type StartsEndsNeedle = string | readonly string[];
|
|
1672
|
+
declare const Str: {
|
|
1673
|
+
readonly lower: (value: string) => string;
|
|
1674
|
+
readonly upper: (value: string) => string;
|
|
1675
|
+
readonly startsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
1676
|
+
readonly endsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
1677
|
+
readonly contains: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
1678
|
+
readonly snake: (value: string) => string;
|
|
1679
|
+
readonly kebab: (value: string) => string;
|
|
1680
|
+
readonly studly: (value: string) => string;
|
|
1681
|
+
readonly camel: (value: string) => string;
|
|
1682
|
+
readonly title: (value: string) => string;
|
|
1683
|
+
readonly limit: (value: string, limit: number, end?: string) => string;
|
|
1684
|
+
readonly slug: (value: string, separator?: string) => string;
|
|
1685
|
+
readonly uuid: () => string;
|
|
1686
|
+
readonly random: (length?: number) => string;
|
|
1687
|
+
};
|
|
1688
|
+
|
|
1689
|
+
declare class DumpDieError extends Error {
|
|
1690
|
+
readonly values: unknown[];
|
|
1691
|
+
name: string;
|
|
1692
|
+
constructor(values: unknown[]);
|
|
1693
|
+
}
|
|
1694
|
+
type DumpOptions = {
|
|
1695
|
+
depth?: number | null;
|
|
1696
|
+
colors?: boolean;
|
|
1697
|
+
};
|
|
1698
|
+
declare function dump(...values: unknown[]): void;
|
|
1699
|
+
declare function dd(...values: unknown[]): never;
|
|
1700
|
+
declare function tap<T>(value: T, callback: (value: T) => unknown): T;
|
|
1701
|
+
declare function value<TArgs extends readonly unknown[], TResult>(value: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
|
1702
|
+
declare function value<TResult>(value: TResult): TResult;
|
|
1703
|
+
declare function value<TArgs extends readonly unknown[], TResult>(valueOrFactory: TResult | ((...args: TArgs) => TResult), ...args: TArgs): TResult;
|
|
1704
|
+
declare function blank(value: unknown): boolean;
|
|
1705
|
+
declare function filled(value: unknown): boolean;
|
|
1706
|
+
declare function throwIf(condition: unknown, error?: Error | string | (() => Error)): void;
|
|
1707
|
+
declare function throwUnless(condition: unknown, error?: Error | string | (() => Error)): void;
|
|
1708
|
+
declare function env<TDefault = string | undefined>(key: string, defaultValue?: TDefault): string | TDefault;
|
|
1709
|
+
declare function setApp(core: PlanetCore | null): void;
|
|
1710
|
+
declare function hasApp(): boolean;
|
|
1711
|
+
declare function app(): PlanetCore;
|
|
1712
|
+
declare function config<T = unknown>(key: string): T;
|
|
1713
|
+
declare function config<T>(key: string, defaultValue: T): T;
|
|
1714
|
+
declare function logger(): Logger;
|
|
1715
|
+
declare function router(): Router;
|
|
1716
|
+
declare function abort(status: ContentfulStatusCode, message?: string): never;
|
|
1717
|
+
declare function abortIf(condition: unknown, status: ContentfulStatusCode, message?: string): void;
|
|
1718
|
+
declare function abortUnless(condition: unknown, status: ContentfulStatusCode, message?: string): void;
|
|
1719
|
+
|
|
1720
|
+
interface CookieOptions {
|
|
1721
|
+
path?: string;
|
|
1722
|
+
domain?: string;
|
|
1723
|
+
secure?: boolean;
|
|
1724
|
+
httpOnly?: boolean;
|
|
1725
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
1726
|
+
maxAge?: number;
|
|
1727
|
+
expires?: Date;
|
|
1728
|
+
encrypt?: boolean;
|
|
1729
|
+
}
|
|
1730
|
+
declare class CookieJar {
|
|
1731
|
+
private encrypter?;
|
|
1732
|
+
private queued;
|
|
1733
|
+
constructor(encrypter?: Encrypter | undefined);
|
|
1734
|
+
/**
|
|
1735
|
+
* Queue a cookie to be sent with the response
|
|
1736
|
+
*/
|
|
1737
|
+
queue(name: string, value: string, minutes?: number, options?: CookieOptions): void;
|
|
1738
|
+
/**
|
|
1739
|
+
* Make a cookie that lasts "forever" (5 years)
|
|
1740
|
+
*/
|
|
1741
|
+
forever(name: string, value: string, options?: CookieOptions): void;
|
|
1742
|
+
/**
|
|
1743
|
+
* Expire a cookie
|
|
1744
|
+
*/
|
|
1745
|
+
forget(name: string, options?: CookieOptions): void;
|
|
1746
|
+
/**
|
|
1747
|
+
* Serialize a cookie to a Set-Cookie header value
|
|
1748
|
+
*/
|
|
1749
|
+
private serializeCookie;
|
|
1750
|
+
/**
|
|
1751
|
+
* Attach queued cookies to the context
|
|
1752
|
+
*/
|
|
1753
|
+
attach(c: GravitoContext): void;
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
type BodySizeLimitOptions = {
|
|
1757
|
+
methods?: string[];
|
|
1758
|
+
requireContentLength?: boolean;
|
|
1759
|
+
};
|
|
1760
|
+
declare function bodySizeLimit(maxBytes: number, options?: BodySizeLimitOptions): GravitoMiddleware;
|
|
1761
|
+
|
|
1762
|
+
type CorsOrigin = string | string[] | ((origin: string | undefined) => string | false);
|
|
1763
|
+
type CorsOptions = {
|
|
1764
|
+
origin?: CorsOrigin;
|
|
1765
|
+
methods?: string[];
|
|
1766
|
+
allowedHeaders?: string[];
|
|
1767
|
+
exposedHeaders?: string[];
|
|
1768
|
+
credentials?: boolean;
|
|
1769
|
+
maxAge?: number;
|
|
1770
|
+
optionsSuccessStatus?: number;
|
|
1771
|
+
};
|
|
1772
|
+
declare function cors(options?: CorsOptions): GravitoMiddleware;
|
|
1773
|
+
|
|
1774
|
+
type CsrfOptions = {
|
|
1775
|
+
cookieName?: string;
|
|
1776
|
+
headerName?: string;
|
|
1777
|
+
formFieldName?: string;
|
|
1778
|
+
cookie?: CookieOptions;
|
|
1779
|
+
safeMethods?: string[];
|
|
1780
|
+
};
|
|
1781
|
+
declare function getCsrfToken(c: GravitoContext, options?: CsrfOptions): string;
|
|
1782
|
+
declare function csrfProtection(options?: CsrfOptions): GravitoMiddleware;
|
|
1783
|
+
|
|
1784
|
+
type HeaderTokenGateOptions = {
|
|
1785
|
+
headerName?: string;
|
|
1786
|
+
token?: string | ((c: GravitoContext) => string | undefined);
|
|
1787
|
+
};
|
|
1788
|
+
type RequireHeaderTokenOptions = HeaderTokenGateOptions & {
|
|
1789
|
+
status?: number;
|
|
1790
|
+
message?: string;
|
|
1791
|
+
};
|
|
1792
|
+
declare function createHeaderGate(options?: HeaderTokenGateOptions): (c: GravitoContext) => Promise<boolean>;
|
|
1793
|
+
declare function requireHeaderToken(options?: RequireHeaderTokenOptions): GravitoMiddleware;
|
|
1794
|
+
|
|
1795
|
+
type HstsOptions = {
|
|
1796
|
+
maxAge: number;
|
|
1797
|
+
includeSubDomains?: boolean;
|
|
1798
|
+
preload?: boolean;
|
|
1799
|
+
};
|
|
1800
|
+
type SecurityHeadersOptions = {
|
|
1801
|
+
contentSecurityPolicy?: string | false | ((c: GravitoContext) => string | false);
|
|
1802
|
+
frameOptions?: string | false;
|
|
1803
|
+
referrerPolicy?: string | false;
|
|
1804
|
+
noSniff?: boolean;
|
|
1805
|
+
hsts?: HstsOptions | false;
|
|
1806
|
+
permissionsPolicy?: string | false;
|
|
1807
|
+
crossOriginOpenerPolicy?: string | false;
|
|
1808
|
+
crossOriginResourcePolicy?: string | false;
|
|
1809
|
+
};
|
|
1810
|
+
declare function securityHeaders(options?: SecurityHeadersOptions): GravitoMiddleware;
|
|
1811
|
+
|
|
1812
|
+
declare class ThrottleRequests {
|
|
1813
|
+
private core;
|
|
1814
|
+
constructor(core: PlanetCore);
|
|
1815
|
+
/**
|
|
1816
|
+
* Create the middleware
|
|
1817
|
+
* @param maxAttempts - Max requests allowed
|
|
1818
|
+
* @param decaySeconds - Time window in seconds
|
|
1819
|
+
*/
|
|
1820
|
+
handle(maxAttempts?: number, decaySeconds?: number): GravitoMiddleware;
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
/**
|
|
1824
|
+
* TestResponse wraps a standard Fetch Response and provides fluent assertion methods
|
|
1825
|
+
* inspired by Laravel's TestResponse.
|
|
1826
|
+
*/
|
|
1827
|
+
declare class TestResponse {
|
|
1828
|
+
readonly response: Response;
|
|
1829
|
+
private _jsonData;
|
|
1830
|
+
private _textData;
|
|
1831
|
+
constructor(response: Response);
|
|
1832
|
+
/**
|
|
1833
|
+
* Assert the response status code
|
|
1834
|
+
*/
|
|
1835
|
+
assertStatus(status: number): this;
|
|
1836
|
+
/**
|
|
1837
|
+
* Assert that the response has a 200 status code
|
|
1838
|
+
*/
|
|
1839
|
+
assertOk(): this;
|
|
1840
|
+
/**
|
|
1841
|
+
* Assert that the response has a 201 status code
|
|
1842
|
+
*/
|
|
1843
|
+
assertCreated(): this;
|
|
1844
|
+
/**
|
|
1845
|
+
* Assert that the response has a 404 status code
|
|
1846
|
+
*/
|
|
1847
|
+
assertNotFound(): this;
|
|
1848
|
+
/**
|
|
1849
|
+
* Assert that the response has a 403 status code
|
|
1850
|
+
*/
|
|
1851
|
+
assertForbidden(): this;
|
|
1852
|
+
/**
|
|
1853
|
+
* Assert that the response has a 401 status code
|
|
1854
|
+
*/
|
|
1855
|
+
assertUnauthorized(): this;
|
|
1856
|
+
/**
|
|
1857
|
+
* Assert the response is a redirect
|
|
1858
|
+
*/
|
|
1859
|
+
assertRedirect(uri?: string): this;
|
|
1860
|
+
/**
|
|
1861
|
+
* Assert that the response contains the given JSON data.
|
|
1862
|
+
*/
|
|
1863
|
+
assertJson(data: any): Promise<this>;
|
|
1864
|
+
/**
|
|
1865
|
+
* Assert that the response contains exactly the given JSON data.
|
|
1866
|
+
*/
|
|
1867
|
+
assertExactJson(data: any): Promise<this>;
|
|
1868
|
+
/**
|
|
1869
|
+
* Assert the structure of the JSON response.
|
|
1870
|
+
*/
|
|
1871
|
+
assertJsonStructure(structure: any): Promise<this>;
|
|
1872
|
+
/**
|
|
1873
|
+
* Assert that the response contains the given string.
|
|
1874
|
+
*/
|
|
1875
|
+
assertSee(value: string): Promise<this>;
|
|
1876
|
+
/**
|
|
1877
|
+
* Assert that the response does not contain the given string.
|
|
1878
|
+
*/
|
|
1879
|
+
assertDontSee(value: string): Promise<this>;
|
|
1880
|
+
/**
|
|
1881
|
+
* Assert a header exists and matches value
|
|
1882
|
+
*/
|
|
1883
|
+
assertHeader(header: string, value: string): this;
|
|
1884
|
+
/**
|
|
1885
|
+
* Assert a header does not exist
|
|
1886
|
+
*/
|
|
1887
|
+
assertHeaderMissing(header: string): this;
|
|
1888
|
+
/**
|
|
1889
|
+
* Get the JSON content
|
|
1890
|
+
*/
|
|
1891
|
+
getJson(): Promise<any>;
|
|
1892
|
+
/**
|
|
1893
|
+
* Get the text content
|
|
1894
|
+
*/
|
|
1895
|
+
getText(): Promise<string>;
|
|
1896
|
+
/**
|
|
1897
|
+
* Alias for getText for standard expectations if needed
|
|
1898
|
+
*/
|
|
1899
|
+
get body(): Promise<string>;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
/**
|
|
1903
|
+
* HttpTester provides a way to simulate HTTP requests against a PlanetCore instance
|
|
1904
|
+
* and returns a TestResponse for assertions.
|
|
1905
|
+
*/
|
|
1906
|
+
declare class HttpTester {
|
|
1907
|
+
private core;
|
|
1908
|
+
constructor(core: PlanetCore);
|
|
1909
|
+
/**
|
|
1910
|
+
* Make a GET request
|
|
1911
|
+
*/
|
|
1912
|
+
get(uri: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
1913
|
+
/**
|
|
1914
|
+
* Make a POST request
|
|
1915
|
+
*/
|
|
1916
|
+
post(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
1917
|
+
/**
|
|
1918
|
+
* Make a PUT request
|
|
1919
|
+
*/
|
|
1920
|
+
put(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
1921
|
+
/**
|
|
1922
|
+
* Make a PATCH request
|
|
1923
|
+
*/
|
|
1924
|
+
patch(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
1925
|
+
/**
|
|
1926
|
+
* Make a DELETE request
|
|
1927
|
+
*/
|
|
1928
|
+
delete(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
1929
|
+
/**
|
|
1930
|
+
* Core call method
|
|
1931
|
+
*/
|
|
1932
|
+
private call;
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Helper to create an HttpTester for a PlanetCore instance
|
|
1936
|
+
*/
|
|
1937
|
+
declare function createHttpTester(core: PlanetCore): HttpTester;
|
|
1938
|
+
|
|
1939
|
+
type RuntimeKind = 'bun' | 'node' | 'deno' | 'unknown';
|
|
1940
|
+
interface RuntimeSpawnOptions {
|
|
1941
|
+
cwd?: string;
|
|
1942
|
+
env?: Record<string, string | undefined>;
|
|
1943
|
+
stdin?: 'pipe' | 'inherit' | 'ignore';
|
|
1944
|
+
stdout?: 'pipe' | 'inherit' | 'ignore';
|
|
1945
|
+
stderr?: 'pipe' | 'inherit' | 'ignore';
|
|
1946
|
+
}
|
|
1947
|
+
interface RuntimeProcess {
|
|
1948
|
+
exited: Promise<number>;
|
|
1949
|
+
stdout?: ReadableStream<Uint8Array> | null;
|
|
1950
|
+
stderr?: ReadableStream<Uint8Array> | null;
|
|
1951
|
+
kill?: (signal?: string | number) => void;
|
|
1952
|
+
}
|
|
1953
|
+
interface RuntimeFileStat {
|
|
1954
|
+
size: number;
|
|
1955
|
+
}
|
|
1956
|
+
interface RuntimeServeConfig {
|
|
1957
|
+
port?: number;
|
|
1958
|
+
fetch: (req: Request, server?: unknown) => Response | Promise<Response>;
|
|
1959
|
+
websocket?: unknown;
|
|
1960
|
+
}
|
|
1961
|
+
interface RuntimeServer {
|
|
1962
|
+
stop?: () => void;
|
|
1963
|
+
}
|
|
1964
|
+
interface RuntimeAdapter {
|
|
1965
|
+
kind: RuntimeKind;
|
|
1966
|
+
spawn(command: string[], options?: RuntimeSpawnOptions): RuntimeProcess;
|
|
1967
|
+
writeFile(path: string, data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<void>;
|
|
1968
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
1969
|
+
readFileAsBlob(path: string): Promise<Blob>;
|
|
1970
|
+
exists(path: string): Promise<boolean>;
|
|
1971
|
+
stat(path: string): Promise<RuntimeFileStat>;
|
|
1972
|
+
deleteFile(path: string): Promise<void>;
|
|
1973
|
+
serve(config: RuntimeServeConfig): RuntimeServer;
|
|
1974
|
+
}
|
|
1975
|
+
interface RuntimePasswordAdapter {
|
|
1976
|
+
hash(value: string, options: {
|
|
1977
|
+
algorithm: 'bcrypt';
|
|
1978
|
+
cost?: number;
|
|
1979
|
+
} | {
|
|
1980
|
+
algorithm: 'argon2id';
|
|
1981
|
+
memoryCost?: number;
|
|
1982
|
+
timeCost?: number;
|
|
1983
|
+
parallelism?: number;
|
|
1984
|
+
}): Promise<string>;
|
|
1985
|
+
verify(value: string, hashed: string): Promise<boolean>;
|
|
1986
|
+
}
|
|
1987
|
+
interface RuntimeSqliteStatement {
|
|
1988
|
+
run(params?: Record<string, unknown>): void;
|
|
1989
|
+
get(params?: Record<string, unknown>): unknown;
|
|
1990
|
+
all(params?: Record<string, unknown>): unknown[];
|
|
1991
|
+
}
|
|
1992
|
+
interface RuntimeSqliteDatabase {
|
|
1993
|
+
run(sql: string): void;
|
|
1994
|
+
prepare(sql: string): RuntimeSqliteStatement;
|
|
1995
|
+
query(sql: string): RuntimeSqliteStatement;
|
|
1996
|
+
close(): void;
|
|
1997
|
+
}
|
|
1998
|
+
declare const getRuntimeEnv: () => Record<string, string | undefined>;
|
|
1999
|
+
declare const getRuntimeAdapter: () => RuntimeAdapter;
|
|
2000
|
+
declare const getPasswordAdapter: () => RuntimePasswordAdapter;
|
|
2001
|
+
declare const createSqliteDatabase: (path: string) => Promise<RuntimeSqliteDatabase>;
|
|
2002
|
+
|
|
2003
|
+
/**
|
|
2004
|
+
* @gravito/core
|
|
2005
|
+
*
|
|
2006
|
+
* The core micro-kernel for the Galaxy Architecture.
|
|
2007
|
+
*
|
|
2008
|
+
* @packageDocumentation
|
|
2009
|
+
*/
|
|
2010
|
+
|
|
2011
|
+
declare const VERSION: string;
|
|
2012
|
+
|
|
2013
|
+
/**
|
|
2014
|
+
* Configure your Gravito application
|
|
2015
|
+
*
|
|
2016
|
+
* @example
|
|
2017
|
+
* ```typescript
|
|
2018
|
+
* const config = defineConfig({
|
|
2019
|
+
* config: {
|
|
2020
|
+
* APP_NAME: 'My App',
|
|
2021
|
+
* PORT: 3000,
|
|
2022
|
+
* },
|
|
2023
|
+
* orbits: [], // Add your orbits here
|
|
2024
|
+
* })
|
|
2025
|
+
*
|
|
2026
|
+
* const core = await PlanetCore.boot(config)
|
|
2027
|
+
* ```
|
|
2028
|
+
*/
|
|
2029
|
+
declare function defineConfig(config: GravitoConfig): GravitoConfig;
|
|
2030
|
+
|
|
2031
|
+
export { type ActionCallback, type AdapterConfig, type AdapterFactory, type ApiFailure, type ApiSuccess, Application, type ApplicationConfig, Arr, AuthenticationException, AuthorizationException, type BodySizeLimitOptions, type CacheService, type Channel, ConfigManager, ConsoleLogger, Container, ContentfulStatusCode, type ControllerClass, CookieJar, type CookieOptions, type CorsOptions, type CorsOrigin, type CsrfOptions, type DataPath, DumpDieError, type DumpOptions, Encrypter, type EncrypterOptions, type ErrorBag, type ErrorHandlerContext, Event, EventManager, type ExceptionOptions, type Factory, type FilterCallback, type FormRequestClass, type FormRequestLike, type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, GravitoAdapter, type GravitoConfig, GravitoContext, GravitoErrorHandler, GravitoException, GravitoHandler, type GravitoManifest, GravitoMiddleware, GravitoNotFoundHandler, type GravitoOrbit, GravitoRequest, GravitoServer, GravitoVariables, type HeaderTokenGateOptions, HookManager, type HstsOptions, type HttpAdapter, HttpException, HttpMethod, HttpTester, type Listener, type Logger, ModelNotFoundException, type PathSegment, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, PlanetCore, type RegisterGlobalErrorHandlersOptions, type RequireHeaderTokenOptions, Route, type RouteDefinition, type RouteHandler, type RouteOptions, Router, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, type SecurityHeadersOptions, ServiceProvider, type ShouldBroadcast, type ShouldQueue, StatusCode, Str, TestResponse, ThrottleRequests, VERSION, type ValidationError, ValidationException, type ViewService, abort, abortIf, abortUnless, app, blank, bodySizeLimit, config, cors, createErrorBag, createGravitoAdapter, createHeaderGate, createHttpTester, createPhotonAdapter, createSqliteDatabase, csrfProtection, dataGet, dataHas, dataSet, dd, defineConfig, dump, env, errors, fail, filled, getCsrfToken, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, hasApp, isHttpAdapter, jsonFail, jsonSuccess, logger, ok, old, registerGlobalErrorHandlers, requireHeaderToken, router, securityHeaders, setApp, tap, throwIf, throwUnless, value };
|