@gravito/echo 2.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.
- package/dist/core/src/Application.d.ts +189 -0
- package/dist/core/src/ConfigManager.d.ts +26 -0
- package/dist/core/src/Container.d.ts +44 -0
- package/dist/core/src/ErrorHandler.d.ts +63 -0
- package/dist/core/src/Event.d.ts +5 -0
- package/dist/core/src/EventManager.d.ts +123 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
- package/dist/core/src/GravitoServer.d.ts +28 -0
- package/dist/core/src/HookManager.d.ts +82 -0
- package/dist/core/src/Listener.d.ts +4 -0
- package/dist/core/src/Logger.d.ts +20 -0
- package/dist/core/src/PlanetCore.d.ts +244 -0
- package/dist/core/src/Route.d.ts +36 -0
- package/dist/core/src/Router.d.ts +250 -0
- package/dist/core/src/ServiceProvider.d.ts +150 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +26 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +170 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +30 -0
- package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
- package/dist/core/src/adapters/bun/types.d.ts +20 -0
- package/dist/core/src/adapters/photon-types.d.ts +73 -0
- package/dist/core/src/adapters/types.d.ts +196 -0
- package/dist/core/src/engine/AOTRouter.d.ts +134 -0
- package/dist/core/src/engine/FastContext.d.ts +98 -0
- package/dist/core/src/engine/Gravito.d.ts +137 -0
- package/dist/core/src/engine/MinimalContext.d.ts +77 -0
- package/dist/core/src/engine/analyzer.d.ts +27 -0
- package/dist/core/src/engine/constants.d.ts +23 -0
- package/dist/core/src/engine/index.d.ts +26 -0
- package/dist/core/src/engine/path.d.ts +26 -0
- package/dist/core/src/engine/pool.d.ts +83 -0
- package/dist/core/src/engine/types.d.ts +138 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
- package/dist/core/src/exceptions/HttpException.d.ts +9 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
- package/dist/core/src/exceptions/index.d.ts +6 -0
- package/dist/core/src/helpers/Arr.d.ts +19 -0
- package/dist/core/src/helpers/Str.d.ts +23 -0
- package/dist/core/src/helpers/data.d.ts +25 -0
- package/dist/core/src/helpers/errors.d.ts +34 -0
- package/dist/core/src/helpers/response.d.ts +41 -0
- package/dist/core/src/helpers.d.ts +338 -0
- package/dist/core/src/http/CookieJar.d.ts +51 -0
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
- package/dist/core/src/http/middleware/Cors.d.ts +24 -0
- package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
- package/dist/core/src/http/types.d.ts +334 -0
- package/dist/core/src/index.d.ts +66 -0
- package/dist/core/src/runtime.d.ts +119 -0
- package/dist/core/src/security/Encrypter.d.ts +33 -0
- package/dist/core/src/security/Hasher.d.ts +29 -0
- package/dist/core/src/testing/HttpTester.d.ts +39 -0
- package/dist/core/src/testing/TestResponse.d.ts +78 -0
- package/dist/core/src/testing/index.d.ts +2 -0
- package/dist/core/src/types/events.d.ts +94 -0
- package/dist/echo/src/OrbitEcho.d.ts +60 -0
- package/dist/echo/src/index.d.ts +48 -0
- package/dist/echo/src/providers/GenericProvider.d.ts +34 -0
- package/dist/echo/src/providers/GitHubProvider.d.ts +26 -0
- package/dist/echo/src/providers/StripeProvider.d.ts +30 -0
- package/dist/echo/src/providers/index.d.ts +3 -0
- package/dist/echo/src/receive/SignatureValidator.d.ts +34 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +67 -0
- package/dist/echo/src/receive/index.d.ts +2 -0
- package/dist/echo/src/send/WebhookDispatcher.d.ts +54 -0
- package/dist/echo/src/send/index.d.ts +1 -0
- package/dist/echo/src/types.d.ts +164 -0
- package/dist/index.js +6 -2
- package/dist/index.js.map +3 -3
- package/dist/photon/src/index.d.ts +20 -0
- package/dist/photon/src/middleware/binary.d.ts +34 -0
- package/package.json +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Application - Enterprise Application Container
|
|
3
|
+
*
|
|
4
|
+
* A high-level application class that orchestrates the entire framework.
|
|
5
|
+
* Provides a centralized entry point for enterprise applications with
|
|
6
|
+
* auto-discovery of providers, config loading, and lifecycle management.
|
|
7
|
+
*
|
|
8
|
+
* @module @gravito/core
|
|
9
|
+
* @since 2.0.0
|
|
10
|
+
*/
|
|
11
|
+
import { ConfigManager } from './ConfigManager';
|
|
12
|
+
import { Container } from './Container';
|
|
13
|
+
import type { EventManager } from './EventManager';
|
|
14
|
+
import type { Logger } from './Logger';
|
|
15
|
+
import { PlanetCore } from './PlanetCore';
|
|
16
|
+
import type { ServiceProvider } from './ServiceProvider';
|
|
17
|
+
/**
|
|
18
|
+
* Application Config options for the Application class.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface ApplicationConfig {
|
|
22
|
+
/**
|
|
23
|
+
* Base path of the application
|
|
24
|
+
*/
|
|
25
|
+
basePath: string;
|
|
26
|
+
/**
|
|
27
|
+
* Path to the config directory (relative to basePath)
|
|
28
|
+
* @default 'config'
|
|
29
|
+
*/
|
|
30
|
+
configPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Path to the providers directory (relative to basePath)
|
|
33
|
+
* @default 'src/Providers'
|
|
34
|
+
*/
|
|
35
|
+
providersPath?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Environment (development, production, testing)
|
|
38
|
+
*/
|
|
39
|
+
env?: 'development' | 'production' | 'testing';
|
|
40
|
+
/**
|
|
41
|
+
* Logger instance
|
|
42
|
+
*/
|
|
43
|
+
logger?: Logger;
|
|
44
|
+
/**
|
|
45
|
+
* Initial configuration values
|
|
46
|
+
*/
|
|
47
|
+
config?: Record<string, unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Service providers to register
|
|
50
|
+
*/
|
|
51
|
+
providers?: ServiceProvider[];
|
|
52
|
+
/**
|
|
53
|
+
* Whether to auto-discover providers from providersPath
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
autoDiscoverProviders?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Application - Enterprise-grade application container.
|
|
60
|
+
*
|
|
61
|
+
* Provides a higher-level abstraction over PlanetCore for building
|
|
62
|
+
* enterprise applications with convention-over-configuration patterns.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Create application
|
|
67
|
+
* const app = new Application({
|
|
68
|
+
* basePath: import.meta.dir,
|
|
69
|
+
* env: process.env.NODE_ENV as 'development' | 'production',
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Boot the application
|
|
73
|
+
* await app.boot();
|
|
74
|
+
*
|
|
75
|
+
* // Access core
|
|
76
|
+
* export default app.core.liftoff();
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare class Application {
|
|
80
|
+
/**
|
|
81
|
+
* The underlying PlanetCore instance.
|
|
82
|
+
*/
|
|
83
|
+
readonly core: PlanetCore;
|
|
84
|
+
/**
|
|
85
|
+
* The IoC container.
|
|
86
|
+
*/
|
|
87
|
+
readonly container: Container;
|
|
88
|
+
/**
|
|
89
|
+
* The configuration manager.
|
|
90
|
+
*/
|
|
91
|
+
readonly config: ConfigManager;
|
|
92
|
+
/**
|
|
93
|
+
* The event manager.
|
|
94
|
+
*/
|
|
95
|
+
readonly events: EventManager;
|
|
96
|
+
/**
|
|
97
|
+
* The logger instance.
|
|
98
|
+
*/
|
|
99
|
+
readonly logger: Logger;
|
|
100
|
+
/**
|
|
101
|
+
* Application base path.
|
|
102
|
+
*/
|
|
103
|
+
readonly basePath: string;
|
|
104
|
+
/**
|
|
105
|
+
* Environment mode.
|
|
106
|
+
*/
|
|
107
|
+
readonly env: 'development' | 'production' | 'testing';
|
|
108
|
+
/**
|
|
109
|
+
* Configuration options.
|
|
110
|
+
*/
|
|
111
|
+
private readonly options;
|
|
112
|
+
/**
|
|
113
|
+
* Whether the application has been booted.
|
|
114
|
+
*/
|
|
115
|
+
private booted;
|
|
116
|
+
constructor(options: ApplicationConfig);
|
|
117
|
+
/**
|
|
118
|
+
* Boot the application.
|
|
119
|
+
*
|
|
120
|
+
* This will:
|
|
121
|
+
* 1. Load configuration files
|
|
122
|
+
* 2. Auto-discover providers (if enabled)
|
|
123
|
+
* 3. Register all providers
|
|
124
|
+
* 4. Bootstrap the core
|
|
125
|
+
*
|
|
126
|
+
* @returns Promise that resolves when boot is complete
|
|
127
|
+
*/
|
|
128
|
+
boot(): Promise<this>;
|
|
129
|
+
/**
|
|
130
|
+
* Load configuration files from the config directory.
|
|
131
|
+
*
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
private loadConfiguration;
|
|
135
|
+
/**
|
|
136
|
+
* Discover and register providers from the providers directory.
|
|
137
|
+
*
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
private discoverProviders;
|
|
141
|
+
/**
|
|
142
|
+
* Get a service from the container.
|
|
143
|
+
*
|
|
144
|
+
* @param key - The service key
|
|
145
|
+
* @returns The resolved service
|
|
146
|
+
*/
|
|
147
|
+
make<T>(key: string): T;
|
|
148
|
+
/**
|
|
149
|
+
* Check if a service is bound.
|
|
150
|
+
*
|
|
151
|
+
* @param key - The service key
|
|
152
|
+
* @returns True if bound
|
|
153
|
+
*/
|
|
154
|
+
has(key: string): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Get a configuration value.
|
|
157
|
+
*
|
|
158
|
+
* @param key - The config key (supports dot notation)
|
|
159
|
+
* @param defaultValue - Default value if not found
|
|
160
|
+
* @returns The config value
|
|
161
|
+
*/
|
|
162
|
+
getConfig<T>(key: string, defaultValue?: T): T;
|
|
163
|
+
/**
|
|
164
|
+
* Create application path helper.
|
|
165
|
+
*
|
|
166
|
+
* @param segments - Path segments relative to base path
|
|
167
|
+
* @returns Absolute path
|
|
168
|
+
*/
|
|
169
|
+
path(...segments: string[]): string;
|
|
170
|
+
/**
|
|
171
|
+
* Get the config path.
|
|
172
|
+
*
|
|
173
|
+
* @param segments - Additional path segments
|
|
174
|
+
* @returns Absolute path to config directory
|
|
175
|
+
*/
|
|
176
|
+
configPath(...segments: string[]): string;
|
|
177
|
+
/**
|
|
178
|
+
* Check if running in production.
|
|
179
|
+
*/
|
|
180
|
+
isProduction(): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Check if running in development.
|
|
183
|
+
*/
|
|
184
|
+
isDevelopment(): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Check if running in testing.
|
|
187
|
+
*/
|
|
188
|
+
isTesting(): boolean;
|
|
189
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConfigManager - Central configuration store.
|
|
3
|
+
* Supports loading from environment variables and initial objects.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConfigManager {
|
|
7
|
+
private config;
|
|
8
|
+
constructor(initialConfig?: Record<string, unknown>);
|
|
9
|
+
/**
|
|
10
|
+
* Load all environment variables from the active runtime.
|
|
11
|
+
*/
|
|
12
|
+
private loadEnv;
|
|
13
|
+
/**
|
|
14
|
+
* Get a configuration value (generic return type supported).
|
|
15
|
+
* Supports dot notation for deep access (e.g. 'app.name').
|
|
16
|
+
*/
|
|
17
|
+
get<T = unknown>(key: string, defaultValue?: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Set a configuration value.
|
|
20
|
+
*/
|
|
21
|
+
set(key: string, value: unknown): void;
|
|
22
|
+
/**
|
|
23
|
+
* Check whether a key exists.
|
|
24
|
+
*/
|
|
25
|
+
has(key: string): boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory type for creating service instances
|
|
3
|
+
*/
|
|
4
|
+
export type Factory<T> = (container: Container) => T;
|
|
5
|
+
export type BindingKey = string | symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Container - Simple Dependency Injection Container.
|
|
8
|
+
* Manages service bindings and singleton instances.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare class Container {
|
|
12
|
+
private bindings;
|
|
13
|
+
private instances;
|
|
14
|
+
/**
|
|
15
|
+
* Bind a service to the container.
|
|
16
|
+
* New instance will be created on each resolution.
|
|
17
|
+
*/
|
|
18
|
+
bind<T>(key: BindingKey, factory: Factory<T>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Bind a shared service to the container (Singleton).
|
|
21
|
+
* Same instance will be returned on each resolution.
|
|
22
|
+
*/
|
|
23
|
+
singleton<T>(key: BindingKey, factory: Factory<T>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Register an existing instance as shared service.
|
|
26
|
+
*/
|
|
27
|
+
instance<T>(key: BindingKey, instance: T): void;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve a service from the container.
|
|
30
|
+
*/
|
|
31
|
+
make<T>(key: BindingKey): T;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a service is bound.
|
|
34
|
+
*/
|
|
35
|
+
has(key: BindingKey): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Flush all instances and bindings.
|
|
38
|
+
*/
|
|
39
|
+
flush(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Forget a specific instance (but keep binding)
|
|
42
|
+
*/
|
|
43
|
+
forget(key: BindingKey): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ErrorHandler - Centralized Error Handling for Gravito Framework
|
|
3
|
+
*
|
|
4
|
+
* Extracted from PlanetCore to follow Single Responsibility Principle.
|
|
5
|
+
* Handles HTTP errors, validation errors, and error rendering.
|
|
6
|
+
*
|
|
7
|
+
* @module @gravito/core
|
|
8
|
+
* @since 1.3.0
|
|
9
|
+
*/
|
|
10
|
+
import type { HookManager } from './HookManager';
|
|
11
|
+
import type { GravitoContext } from './http/types';
|
|
12
|
+
import type { Logger } from './Logger';
|
|
13
|
+
/**
|
|
14
|
+
* HTTP Status Code to Error Code mapping
|
|
15
|
+
*/
|
|
16
|
+
export declare function codeFromStatus(status: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* HTTP Status Code to Message mapping
|
|
19
|
+
*/
|
|
20
|
+
export declare function messageFromStatus(status: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Dependencies injected into ErrorHandler
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface ErrorHandlerDeps {
|
|
26
|
+
logger: Logger;
|
|
27
|
+
hooks: HookManager;
|
|
28
|
+
getCore: () => unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* ErrorHandler - Centralized error handling logic
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const handler = new ErrorHandler({ logger, hooks, getCore: () => core })
|
|
36
|
+
* adapter.onError(handler.handleError.bind(handler))
|
|
37
|
+
* adapter.onNotFound(handler.handleNotFound.bind(handler))
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class ErrorHandler {
|
|
41
|
+
private deps;
|
|
42
|
+
constructor(deps: ErrorHandlerDeps);
|
|
43
|
+
/**
|
|
44
|
+
* Handle application errors
|
|
45
|
+
*/
|
|
46
|
+
handleError(err: unknown, c: GravitoContext): Promise<Response>;
|
|
47
|
+
/**
|
|
48
|
+
* Handle 404 Not Found errors
|
|
49
|
+
*/
|
|
50
|
+
handleNotFound(c: GravitoContext): Promise<Response>;
|
|
51
|
+
/**
|
|
52
|
+
* Handle validation error redirect for HTML requests
|
|
53
|
+
*/
|
|
54
|
+
private handleValidationRedirect;
|
|
55
|
+
/**
|
|
56
|
+
* Log error based on context settings
|
|
57
|
+
*/
|
|
58
|
+
private logError;
|
|
59
|
+
/**
|
|
60
|
+
* Render error response (HTML or JSON)
|
|
61
|
+
*/
|
|
62
|
+
private renderErrorResponse;
|
|
63
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Event } from './Event';
|
|
2
|
+
import type { Listener } from './Listener';
|
|
3
|
+
import type { PlanetCore } from './PlanetCore';
|
|
4
|
+
/**
|
|
5
|
+
* Listener registration metadata.
|
|
6
|
+
*/
|
|
7
|
+
interface ListenerRegistration<TEvent extends Event = Event> {
|
|
8
|
+
listener: Listener<TEvent> | (new () => Listener<TEvent>);
|
|
9
|
+
queue?: string;
|
|
10
|
+
connection?: string;
|
|
11
|
+
delay?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Event manager.
|
|
15
|
+
*
|
|
16
|
+
* Provides type-safe event dispatching and listener registration.
|
|
17
|
+
* Supports both synchronous listeners and asynchronous (queued) listeners.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class UserRegistered extends Event {
|
|
22
|
+
* constructor(public user: User) {
|
|
23
|
+
* super()
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* class SendWelcomeEmail implements Listener<UserRegistered> {
|
|
28
|
+
* async handle(event: UserRegistered): Promise<void> {
|
|
29
|
+
* // send welcome email
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Register listener
|
|
34
|
+
* core.events.listen(UserRegistered, SendWelcomeEmail)
|
|
35
|
+
*
|
|
36
|
+
* // Dispatch event
|
|
37
|
+
* await core.events.dispatch(new UserRegistered(user))
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class EventManager {
|
|
41
|
+
private core;
|
|
42
|
+
/**
|
|
43
|
+
* Listener registry.
|
|
44
|
+
* Key: event class or event name
|
|
45
|
+
* Value: listener registrations
|
|
46
|
+
*/
|
|
47
|
+
private listeners;
|
|
48
|
+
/**
|
|
49
|
+
* Broadcast manager (optional, injected by `orbit-broadcasting`).
|
|
50
|
+
*/
|
|
51
|
+
private broadcastManager;
|
|
52
|
+
/**
|
|
53
|
+
* Queue manager (optional, injected by `orbit-queue`).
|
|
54
|
+
*/
|
|
55
|
+
private queueManager;
|
|
56
|
+
constructor(core: PlanetCore);
|
|
57
|
+
/**
|
|
58
|
+
* Register the broadcast manager (called by `orbit-broadcasting`).
|
|
59
|
+
*/
|
|
60
|
+
setBroadcastManager(manager: EventManager['broadcastManager']): void;
|
|
61
|
+
/**
|
|
62
|
+
* Register the queue manager (called by `orbit-queue`).
|
|
63
|
+
*/
|
|
64
|
+
setQueueManager(manager: EventManager['queueManager']): void;
|
|
65
|
+
/**
|
|
66
|
+
* Register an event listener.
|
|
67
|
+
*
|
|
68
|
+
* @param event - Event class or event name
|
|
69
|
+
* @param listener - Listener instance or listener class
|
|
70
|
+
* @param options - Optional queue options
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Synchronous listener
|
|
75
|
+
* core.events.listen(UserRegistered, SendWelcomeEmail)
|
|
76
|
+
*
|
|
77
|
+
* // Queued listener (async)
|
|
78
|
+
* core.events.listen(UserRegistered, SendWelcomeEmail, {
|
|
79
|
+
* queue: 'emails',
|
|
80
|
+
* delay: 60
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
listen<TEvent extends Event>(event: string | (new (...args: unknown[]) => TEvent), listener: Listener<TEvent> | (new () => Listener<TEvent>), options?: {
|
|
85
|
+
queue?: string;
|
|
86
|
+
connection?: string;
|
|
87
|
+
delay?: number;
|
|
88
|
+
}): void;
|
|
89
|
+
/**
|
|
90
|
+
* Remove an event listener.
|
|
91
|
+
*
|
|
92
|
+
* @param event - Event class or event name
|
|
93
|
+
* @param listener - Listener to remove
|
|
94
|
+
*/
|
|
95
|
+
unlisten<TEvent extends Event>(event: string | (new (...args: unknown[]) => TEvent), listener: Listener<TEvent> | (new () => Listener<TEvent>)): void;
|
|
96
|
+
/**
|
|
97
|
+
* Dispatch an event.
|
|
98
|
+
*
|
|
99
|
+
* Runs all registered listeners. If a listener implements `ShouldQueue` or
|
|
100
|
+
* has queue options, the listener will be pushed to the queue for async execution.
|
|
101
|
+
*
|
|
102
|
+
* @param event - Event instance
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* await core.events.dispatch(new UserRegistered(user))
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
dispatch<TEvent extends Event>(event: TEvent): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Serialize an event (for queueing).
|
|
112
|
+
*/
|
|
113
|
+
private serializeEvent;
|
|
114
|
+
/**
|
|
115
|
+
* Get all registered listeners.
|
|
116
|
+
*/
|
|
117
|
+
getListeners(event?: string | (new () => Event)): ListenerRegistration[];
|
|
118
|
+
/**
|
|
119
|
+
* Clear all listeners.
|
|
120
|
+
*/
|
|
121
|
+
clear(): void;
|
|
122
|
+
}
|
|
123
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Logger } from './Logger';
|
|
2
|
+
import type { PlanetCore } from './PlanetCore';
|
|
3
|
+
/**
|
|
4
|
+
* Type of process-level error
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type GlobalProcessErrorKind = 'unhandledRejection' | 'uncaughtException';
|
|
8
|
+
/**
|
|
9
|
+
* Context payload for global error handler filters/actions
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type GlobalProcessErrorHandlerContext = {
|
|
13
|
+
core?: PlanetCore;
|
|
14
|
+
kind: GlobalProcessErrorKind;
|
|
15
|
+
error: unknown;
|
|
16
|
+
isProduction: boolean;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
logLevel?: 'error' | 'warn' | 'info' | 'none';
|
|
19
|
+
logMessage?: string;
|
|
20
|
+
exit?: boolean;
|
|
21
|
+
exitCode?: number;
|
|
22
|
+
gracePeriodMs?: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Error handling strategy
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export type GlobalErrorHandlersMode = 'log' | 'exit' | 'exitInProduction';
|
|
29
|
+
/**
|
|
30
|
+
* Options for registering global handlers
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export type RegisterGlobalErrorHandlersOptions = {
|
|
34
|
+
core?: PlanetCore;
|
|
35
|
+
logger?: Logger;
|
|
36
|
+
mode?: GlobalErrorHandlersMode;
|
|
37
|
+
exitCode?: number;
|
|
38
|
+
gracePeriodMs?: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Register process-level error handlers (`unhandledRejection` / `uncaughtException`).
|
|
42
|
+
*
|
|
43
|
+
* - `mode: "log"`: only log/report
|
|
44
|
+
* - `mode: "exit"`: report then `process.exit(exitCode)`
|
|
45
|
+
* - `mode: "exitInProduction"`: exit only when `NODE_ENV=production` (default)
|
|
46
|
+
*/
|
|
47
|
+
export declare function registerGlobalErrorHandlers(options?: RegisterGlobalErrorHandlersOptions): () => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type GravitoConfig, PlanetCore } from './PlanetCore';
|
|
2
|
+
/**
|
|
3
|
+
* Manifest describing a Gravito application structure.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface GravitoManifest {
|
|
7
|
+
name: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
modules: string[];
|
|
10
|
+
config?: GravitoConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Function type for asynchronous module resolution.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type ModuleResolver = () => Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Gravito 核心啟動引擎 (已解耦)
|
|
19
|
+
*/
|
|
20
|
+
export declare class GravitoServer {
|
|
21
|
+
/**
|
|
22
|
+
* 一鍵建立並組裝伺服器
|
|
23
|
+
* @param manifest 站點描述清單
|
|
24
|
+
* @param resolvers 模組解析器字典
|
|
25
|
+
* @param baseOrbits 基礎軌道模組 (例如 OrbitMonolith)
|
|
26
|
+
*/
|
|
27
|
+
static create(manifest: GravitoManifest, resolvers: Record<string, ModuleResolver>, baseOrbits?: any[]): Promise<PlanetCore>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback function for filters (transforms values).
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export type FilterCallback<T = unknown> = (value: T, ...args: unknown[]) => Promise<T> | T;
|
|
6
|
+
/**
|
|
7
|
+
* Callback function for actions (side effects).
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type ActionCallback<TArgs = unknown> = (args: TArgs) => Promise<void> | void;
|
|
11
|
+
/**
|
|
12
|
+
* Manager for WordPress-style hooks (actions and filters).
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare class HookManager {
|
|
16
|
+
private filters;
|
|
17
|
+
private actions;
|
|
18
|
+
/**
|
|
19
|
+
* Register a filter hook.
|
|
20
|
+
*
|
|
21
|
+
* Filters are used to transform a value (input/output).
|
|
22
|
+
*
|
|
23
|
+
* @template T - The type of value being filtered.
|
|
24
|
+
* @param hook - The name of the hook.
|
|
25
|
+
* @param callback - The callback function to execute.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* core.hooks.addFilter('content', async (content: string) => {
|
|
30
|
+
* return content.toUpperCase();
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
addFilter<T = unknown>(hook: string, callback: FilterCallback<T>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Apply all registered filters sequentially.
|
|
37
|
+
*
|
|
38
|
+
* Each callback receives the previous callback's return value.
|
|
39
|
+
*
|
|
40
|
+
* @template T - The type of value being filtered.
|
|
41
|
+
* @param hook - The name of the hook.
|
|
42
|
+
* @param initialValue - The initial value to filter.
|
|
43
|
+
* @param args - Additional arguments to pass to the callbacks.
|
|
44
|
+
* @returns The final filtered value.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const content = await core.hooks.applyFilters('content', 'hello world');
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
applyFilters<T = unknown>(hook: string, initialValue: T, ...args: unknown[]): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Register an action hook.
|
|
54
|
+
*
|
|
55
|
+
* Actions are for side effects (no return value).
|
|
56
|
+
*
|
|
57
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
58
|
+
* @param hook - The name of the hook.
|
|
59
|
+
* @param callback - The callback function to execute.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* core.hooks.addAction('user_registered', async (user: User) => {
|
|
64
|
+
* await sendWelcomeEmail(user);
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>): void;
|
|
69
|
+
/**
|
|
70
|
+
* Run all registered actions sequentially.
|
|
71
|
+
*
|
|
72
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
73
|
+
* @param hook - The name of the hook.
|
|
74
|
+
* @param args - The arguments to pass to the callbacks.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* await core.hooks.doAction('user_registered', user);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
doAction<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
82
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard logger interface.
|
|
3
|
+
*
|
|
4
|
+
* PSR-3 inspired API for easy swapping (e.g., Winston, Pino).
|
|
5
|
+
*/
|
|
6
|
+
export interface Logger {
|
|
7
|
+
debug(message: string, ...args: unknown[]): void;
|
|
8
|
+
info(message: string, ...args: unknown[]): void;
|
|
9
|
+
warn(message: string, ...args: unknown[]): void;
|
|
10
|
+
error(message: string, ...args: unknown[]): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Default console logger implementation.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConsoleLogger implements Logger {
|
|
16
|
+
debug(message: string, ...args: unknown[]): void;
|
|
17
|
+
info(message: string, ...args: unknown[]): void;
|
|
18
|
+
warn(message: string, ...args: unknown[]): void;
|
|
19
|
+
error(message: string, ...args: unknown[]): void;
|
|
20
|
+
}
|