@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.
Files changed (81) hide show
  1. package/dist/core/src/Application.d.ts +189 -0
  2. package/dist/core/src/ConfigManager.d.ts +26 -0
  3. package/dist/core/src/Container.d.ts +44 -0
  4. package/dist/core/src/ErrorHandler.d.ts +63 -0
  5. package/dist/core/src/Event.d.ts +5 -0
  6. package/dist/core/src/EventManager.d.ts +123 -0
  7. package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
  8. package/dist/core/src/GravitoServer.d.ts +28 -0
  9. package/dist/core/src/HookManager.d.ts +82 -0
  10. package/dist/core/src/Listener.d.ts +4 -0
  11. package/dist/core/src/Logger.d.ts +20 -0
  12. package/dist/core/src/PlanetCore.d.ts +244 -0
  13. package/dist/core/src/Route.d.ts +36 -0
  14. package/dist/core/src/Router.d.ts +250 -0
  15. package/dist/core/src/ServiceProvider.d.ts +150 -0
  16. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +26 -0
  17. package/dist/core/src/adapters/PhotonAdapter.d.ts +170 -0
  18. package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
  19. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +30 -0
  20. package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
  21. package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
  22. package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
  23. package/dist/core/src/adapters/bun/types.d.ts +20 -0
  24. package/dist/core/src/adapters/photon-types.d.ts +73 -0
  25. package/dist/core/src/adapters/types.d.ts +196 -0
  26. package/dist/core/src/engine/AOTRouter.d.ts +134 -0
  27. package/dist/core/src/engine/FastContext.d.ts +98 -0
  28. package/dist/core/src/engine/Gravito.d.ts +137 -0
  29. package/dist/core/src/engine/MinimalContext.d.ts +77 -0
  30. package/dist/core/src/engine/analyzer.d.ts +27 -0
  31. package/dist/core/src/engine/constants.d.ts +23 -0
  32. package/dist/core/src/engine/index.d.ts +26 -0
  33. package/dist/core/src/engine/path.d.ts +26 -0
  34. package/dist/core/src/engine/pool.d.ts +83 -0
  35. package/dist/core/src/engine/types.d.ts +138 -0
  36. package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
  37. package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
  38. package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
  39. package/dist/core/src/exceptions/HttpException.d.ts +9 -0
  40. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
  41. package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
  42. package/dist/core/src/exceptions/index.d.ts +6 -0
  43. package/dist/core/src/helpers/Arr.d.ts +19 -0
  44. package/dist/core/src/helpers/Str.d.ts +23 -0
  45. package/dist/core/src/helpers/data.d.ts +25 -0
  46. package/dist/core/src/helpers/errors.d.ts +34 -0
  47. package/dist/core/src/helpers/response.d.ts +41 -0
  48. package/dist/core/src/helpers.d.ts +338 -0
  49. package/dist/core/src/http/CookieJar.d.ts +51 -0
  50. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
  51. package/dist/core/src/http/middleware/Cors.d.ts +24 -0
  52. package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
  53. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
  54. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
  55. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
  56. package/dist/core/src/http/types.d.ts +334 -0
  57. package/dist/core/src/index.d.ts +66 -0
  58. package/dist/core/src/runtime.d.ts +119 -0
  59. package/dist/core/src/security/Encrypter.d.ts +33 -0
  60. package/dist/core/src/security/Hasher.d.ts +29 -0
  61. package/dist/core/src/testing/HttpTester.d.ts +39 -0
  62. package/dist/core/src/testing/TestResponse.d.ts +78 -0
  63. package/dist/core/src/testing/index.d.ts +2 -0
  64. package/dist/core/src/types/events.d.ts +94 -0
  65. package/dist/echo/src/OrbitEcho.d.ts +60 -0
  66. package/dist/echo/src/index.d.ts +48 -0
  67. package/dist/echo/src/providers/GenericProvider.d.ts +34 -0
  68. package/dist/echo/src/providers/GitHubProvider.d.ts +26 -0
  69. package/dist/echo/src/providers/StripeProvider.d.ts +30 -0
  70. package/dist/echo/src/providers/index.d.ts +3 -0
  71. package/dist/echo/src/receive/SignatureValidator.d.ts +34 -0
  72. package/dist/echo/src/receive/WebhookReceiver.d.ts +67 -0
  73. package/dist/echo/src/receive/index.d.ts +2 -0
  74. package/dist/echo/src/send/WebhookDispatcher.d.ts +54 -0
  75. package/dist/echo/src/send/index.d.ts +1 -0
  76. package/dist/echo/src/types.d.ts +164 -0
  77. package/dist/index.js +6 -2
  78. package/dist/index.js.map +3 -3
  79. package/dist/photon/src/index.d.ts +20 -0
  80. package/dist/photon/src/middleware/binary.d.ts +34 -0
  81. package/package.json +1 -1
@@ -0,0 +1,338 @@
1
+ import type { ContentfulStatusCode } from './http/types';
2
+ import type { PlanetCore } from './PlanetCore';
3
+ import type { Router } from './Router';
4
+ export { Arr } from './helpers/Arr';
5
+ export * from './helpers/data';
6
+ export * from './helpers/errors';
7
+ export * from './helpers/response';
8
+ export { Str } from './helpers/Str';
9
+ /**
10
+ * Error subclass used for dump and die functionality.
11
+ * @internal
12
+ */
13
+ export declare class DumpDieError extends Error {
14
+ readonly values: unknown[];
15
+ name: string;
16
+ constructor(values: unknown[]);
17
+ }
18
+ /**
19
+ * Options for dump output
20
+ * @public
21
+ */
22
+ export type DumpOptions = {
23
+ depth?: number | null;
24
+ colors?: boolean;
25
+ };
26
+ /**
27
+ * Dump data to console for debugging.
28
+ *
29
+ * Uses `console.dir` with configurable depth and colors to provide a
30
+ * readable representation of any value.
31
+ *
32
+ * @param values - One or more values to dump to the console.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * dump(user, { meta: 'data' });
37
+ * ```
38
+ *
39
+ * @public
40
+ * @since 3.0.0
41
+ */
42
+ export declare function dump(...values: unknown[]): void;
43
+ /**
44
+ * Dump data to console and exit process (or throw in HTTP context).
45
+ *
46
+ * Short for "Dump and Die". In a CLI environment, it exits the process.
47
+ * In an HTTP context (like a web request), it throws a `DumpDieError`
48
+ * which is caught by the exception handler to display the debug output.
49
+ *
50
+ * @param values - One or more values to dump and then die.
51
+ * @throws {DumpDieError} Always throws this error to halt execution.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * dd(user.permissions);
56
+ * ```
57
+ *
58
+ * @public
59
+ * @since 3.0.0
60
+ */
61
+ export declare function dd(...values: unknown[]): never;
62
+ /**
63
+ * Tap into a value, execute a callback, and return the value.
64
+ *
65
+ * This allows you to perform "side effects" on a value without breaking
66
+ * the chain of operations.
67
+ *
68
+ * @param value - The value to tap into.
69
+ * @param callback - A callback that receives the value.
70
+ * @returns The original value.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const user = tap(new User(), (u) => {
75
+ * u.name = 'Alice';
76
+ * u.save();
77
+ * });
78
+ * ```
79
+ *
80
+ * @public
81
+ * @since 3.0.0
82
+ */
83
+ export declare function tap<T>(value: T, callback: (value: T) => unknown): T;
84
+ /**
85
+ * Return the default value of the given value.
86
+ *
87
+ * If the value is a function, it will be executed with the provided arguments
88
+ * and its result will be returned. Otherwise, the value itself is returned.
89
+ * This is useful for handling optional lazy-loaded values.
90
+ *
91
+ * @param valueOrFactory - The value or a factory function.
92
+ * @param args - Arguments to pass to the factory function if it is a function.
93
+ * @returns The resolved value.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * value(10); // 10
98
+ * value(() => 10); // 10
99
+ * value((name) => `Hello ${name}`, 'World'); // "Hello World"
100
+ * ```
101
+ *
102
+ * @public
103
+ * @since 3.0.0
104
+ */
105
+ export declare function value<TArgs extends readonly unknown[], TResult>(valueOrFactory: TResult | ((...args: TArgs) => TResult), ...args: TArgs): TResult;
106
+ /**
107
+ * Determine if the given value is "blank".
108
+ *
109
+ * A value is considered blank if it is:
110
+ * - `null` or `undefined`
111
+ * - An empty string or a string containing only whitespace
112
+ * - An empty array
113
+ * - An empty object
114
+ * - An empty Map or Set
115
+ *
116
+ * @param value - The value to check.
117
+ * @returns `true` if the value is blank, `false` otherwise.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * blank(''); // true
122
+ * blank(' '); // true
123
+ * blank([]); // true
124
+ * blank({}); // true
125
+ * blank(0); // false
126
+ * ```
127
+ *
128
+ * @public
129
+ * @since 3.0.0
130
+ */
131
+ export declare function blank(value: unknown): boolean;
132
+ /**
133
+ * Determine if the given value is "filled" (not blank).
134
+ *
135
+ * This is the inverse of `blank()`.
136
+ *
137
+ * @param value - The value to check.
138
+ * @returns `true` if the value is not blank, `false` otherwise.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * filled('hello'); // true
143
+ * filled([1, 2, 3]); // true
144
+ * filled(''); // false
145
+ * ```
146
+ *
147
+ * @public
148
+ * @since 3.0.0
149
+ */
150
+ export declare function filled(value: unknown): boolean;
151
+ /**
152
+ * Throw an exception if the given condition is true.
153
+ *
154
+ * @param condition - The condition to evaluate.
155
+ * @param error - The exception to throw, a factory function, or an error message string.
156
+ * @throws {Error} If the condition evaluates to true.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * throwIf(user.isBanned, 'User is banned from the system');
161
+ * throwIf(count > 100, () => new ValidationError('Too many items'));
162
+ * ```
163
+ *
164
+ * @public
165
+ * @since 3.0.0
166
+ */
167
+ export declare function throwIf(condition: unknown, error?: Error | string | (() => Error)): void;
168
+ /**
169
+ * Throw an exception unless the given condition is true.
170
+ *
171
+ * @param condition - The condition to evaluate.
172
+ * @param error - The exception to throw, a factory function, or an error message string.
173
+ * @throws {Error} If the condition evaluates to false.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * throwUnless(user.isAdmin, 'Unauthorized access');
178
+ * ```
179
+ *
180
+ * @public
181
+ * @since 3.0.0
182
+ */
183
+ export declare function throwUnless(condition: unknown, error?: Error | string | (() => Error)): void;
184
+ /**
185
+ * Get the value of an environment variable.
186
+ *
187
+ * Automatically detects the runtime environment (Bun or Node.js) to retrieve
188
+ * the variable.
189
+ *
190
+ * @param key - The environment variable name.
191
+ * @param defaultValue - An optional default value to return if the variable is not defined.
192
+ * @returns The environment variable value or the default value.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const debug = env('DEBUG', 'false');
197
+ * const apiKey = env('API_KEY');
198
+ * ```
199
+ *
200
+ * @public
201
+ * @since 3.0.0
202
+ */
203
+ export declare function env<TDefault = string | undefined>(key: string, defaultValue?: TDefault): string | TDefault;
204
+ /**
205
+ * Set the global application instance.
206
+ *
207
+ * This is used internally during the bootstrap process to provide global
208
+ * access to the application instance via the `app()` helper.
209
+ *
210
+ * @param core - The PlanetCore instance to set as global.
211
+ * @internal
212
+ */
213
+ export declare function setApp(core: PlanetCore | null): void;
214
+ /**
215
+ * Check if the global application instance has been initialized and set.
216
+ *
217
+ * @returns `true` if the application instance is set, `false` otherwise.
218
+ *
219
+ * @public
220
+ * @since 3.0.0
221
+ */
222
+ export declare function hasApp(): boolean;
223
+ /**
224
+ * Get the global application instance.
225
+ *
226
+ * Provides access to the core application container, configuration, and services.
227
+ *
228
+ * @returns The initialized PlanetCore instance.
229
+ * @throws {Error} If the application has not been initialized.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const core = app();
234
+ * console.log(core.version);
235
+ * ```
236
+ *
237
+ * @public
238
+ * @since 3.0.0
239
+ */
240
+ export declare function app(): PlanetCore;
241
+ /**
242
+ * Get a configuration value from the application.
243
+ *
244
+ * Supports dot notation for accessing nested configuration properties.
245
+ *
246
+ * @param key - The configuration key in dot notation (e.g., 'app.name').
247
+ * @param defaultValue - An optional default value to return if the key is not found.
248
+ * @returns The configuration value or the default value.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const appName = config('app.name');
253
+ * const port = config('app.port', 3000);
254
+ * ```
255
+ *
256
+ * @public
257
+ * @since 3.0.0
258
+ */
259
+ export declare function config<T = unknown>(key: string, defaultValue?: T): T;
260
+ /**
261
+ * Get the global logger instance.
262
+ *
263
+ * Shortcut for `app().logger`.
264
+ *
265
+ * @returns The application's logger instance.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * logger().info('Operation completed successfully');
270
+ * ```
271
+ *
272
+ * @public
273
+ * @since 3.0.0
274
+ */
275
+ export declare function logger(): import("@gravito/core").Logger;
276
+ /**
277
+ * Get the application's primary router instance.
278
+ *
279
+ * Shortcut for `app().router`.
280
+ *
281
+ * @returns The router instance.
282
+ *
283
+ * @public
284
+ * @since 3.0.0
285
+ */
286
+ export declare function router(): Router;
287
+ /**
288
+ * Abort the current request with an HTTP exception.
289
+ *
290
+ * Throws an `HttpException` with the specified status code and optional message.
291
+ *
292
+ * @param status - The HTTP status code to return.
293
+ * @param message - An optional custom error message.
294
+ * @throws {HttpException} Always throws this exception.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * abort(403, 'You do not have permission to access this resource');
299
+ * ```
300
+ *
301
+ * @public
302
+ * @since 3.0.0
303
+ */
304
+ export declare function abort(status: ContentfulStatusCode, message?: string): never;
305
+ /**
306
+ * Abort the request if the given condition is true.
307
+ *
308
+ * @param condition - The condition to evaluate.
309
+ * @param status - The HTTP status code to return.
310
+ * @param message - An optional custom error message.
311
+ * @throws {HttpException} If the condition is true.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * abortIf(!user.isActive, 403, 'Account is deactivated');
316
+ * ```
317
+ *
318
+ * @public
319
+ * @since 3.0.0
320
+ */
321
+ export declare function abortIf(condition: unknown, status: ContentfulStatusCode, message?: string): void;
322
+ /**
323
+ * Abort the request unless the given condition is true.
324
+ *
325
+ * @param condition - The condition to evaluate.
326
+ * @param status - The HTTP status code to return.
327
+ * @param message - An optional custom error message.
328
+ * @throws {HttpException} If the condition is false.
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * abortUnless(request.hasValidToken(), 401, 'Invalid authentication token');
333
+ * ```
334
+ *
335
+ * @public
336
+ * @since 3.0.0
337
+ */
338
+ export declare function abortUnless(condition: unknown, status: ContentfulStatusCode, message?: string): void;
@@ -0,0 +1,51 @@
1
+ import type { Encrypter } from '../security/Encrypter';
2
+ import type { GravitoContext } from './types';
3
+ /**
4
+ * Options for setting cookies
5
+ * @public
6
+ */
7
+ export interface CookieOptions {
8
+ path?: string;
9
+ domain?: string;
10
+ secure?: boolean;
11
+ httpOnly?: boolean;
12
+ sameSite?: 'Strict' | 'Lax' | 'None';
13
+ maxAge?: number;
14
+ expires?: Date;
15
+ encrypt?: boolean;
16
+ }
17
+ /**
18
+ * Utility for managing cookies (request/response/encryption).
19
+ * @public
20
+ */
21
+ export declare class CookieJar {
22
+ private encrypter?;
23
+ private queued;
24
+ constructor(encrypter?: Encrypter | undefined);
25
+ /**
26
+ * Parse cookies from a Cookie header string
27
+ * @param header - The Cookie header value
28
+ * @returns Parsed cookies as key-value pairs
29
+ */
30
+ static parseCookies(header: string): Record<string, string>;
31
+ /**
32
+ * Queue a cookie to be sent with the response
33
+ */
34
+ queue(name: string, value: string, minutes?: number, options?: CookieOptions): void;
35
+ /**
36
+ * Make a cookie that lasts "forever" (5 years)
37
+ */
38
+ forever(name: string, value: string, options?: CookieOptions): void;
39
+ /**
40
+ * Expire a cookie
41
+ */
42
+ forget(name: string, options?: CookieOptions): void;
43
+ /**
44
+ * Serialize a cookie to a Set-Cookie header value
45
+ */
46
+ private serializeCookie;
47
+ /**
48
+ * Attach queued cookies to the context
49
+ */
50
+ attach(c: GravitoContext): void;
51
+ }
@@ -0,0 +1,16 @@
1
+ import type { GravitoMiddleware } from '../types';
2
+ /**
3
+ * Options for body size limiting
4
+ * @public
5
+ */
6
+ export type BodySizeLimitOptions = {
7
+ methods?: string[];
8
+ requireContentLength?: boolean;
9
+ };
10
+ /**
11
+ * Middleware to limit request body size.
12
+ * @param maxBytes - Maximum allowed size in bytes
13
+ * @param options - Configuration options
14
+ * @public
15
+ */
16
+ export declare function bodySizeLimit(maxBytes: number, options?: BodySizeLimitOptions): GravitoMiddleware;
@@ -0,0 +1,24 @@
1
+ import type { GravitoMiddleware } from '../types';
2
+ /**
3
+ * Allowed origin(s) configuration.
4
+ * @public
5
+ */
6
+ export type CorsOrigin = string | string[] | ((origin: string | undefined) => string | false);
7
+ /**
8
+ * Options for CORS middleware
9
+ * @public
10
+ */
11
+ export type CorsOptions = {
12
+ origin?: CorsOrigin;
13
+ methods?: string[];
14
+ allowedHeaders?: string[];
15
+ exposedHeaders?: string[];
16
+ credentials?: boolean;
17
+ maxAge?: number;
18
+ optionsSuccessStatus?: number;
19
+ };
20
+ /**
21
+ * Middleware handling Cross-Origin Resource Sharing (CORS).
22
+ * @public
23
+ */
24
+ export declare function cors(options?: CorsOptions): GravitoMiddleware;
@@ -0,0 +1,23 @@
1
+ import { type CookieOptions } from '../CookieJar';
2
+ import type { GravitoContext, GravitoMiddleware } from '../types';
3
+ /**
4
+ * Configuration for CSRF Protection
5
+ * @public
6
+ */
7
+ export type CsrfOptions = {
8
+ cookieName?: string;
9
+ headerName?: string;
10
+ formFieldName?: string;
11
+ cookie?: CookieOptions;
12
+ safeMethods?: string[];
13
+ };
14
+ /**
15
+ * Generate (or retrieve existing) CSRF token for the session.
16
+ * @public
17
+ */
18
+ export declare function getCsrfToken(c: GravitoContext, options?: CsrfOptions): string;
19
+ /**
20
+ * Middleware that validates CSRF tokens on unsafe requests.
21
+ * @public
22
+ */
23
+ export declare function csrfProtection(options?: CsrfOptions): GravitoMiddleware;
@@ -0,0 +1,28 @@
1
+ import type { GravitoContext, GravitoMiddleware } from '../types';
2
+ /**
3
+ * Options for header token gate
4
+ * @public
5
+ */
6
+ export type HeaderTokenGateOptions = {
7
+ headerName?: string;
8
+ token?: string | ((c: GravitoContext) => string | undefined);
9
+ };
10
+ /**
11
+ * Options for requireHeaderToken middleware
12
+ * @public
13
+ */
14
+ export type RequireHeaderTokenOptions = HeaderTokenGateOptions & {
15
+ status?: number;
16
+ message?: string;
17
+ };
18
+ /**
19
+ * Create a simple gate function to check a header token.
20
+ * @public
21
+ */
22
+ export declare function createHeaderGate(options?: HeaderTokenGateOptions): (c: GravitoContext) => Promise<boolean>;
23
+ /**
24
+ * Middleware that enforces a specific token in request headers.
25
+ * Useful for internal API authentication.
26
+ * @public
27
+ */
28
+ export declare function requireHeaderToken(options?: RequireHeaderTokenOptions): GravitoMiddleware;
@@ -0,0 +1,29 @@
1
+ import type { GravitoContext, GravitoMiddleware } from '../types';
2
+ /**
3
+ * HSTS Configuration
4
+ * @public
5
+ */
6
+ export type HstsOptions = {
7
+ maxAge: number;
8
+ includeSubDomains?: boolean;
9
+ preload?: boolean;
10
+ };
11
+ /**
12
+ * Options for Security Headers middleware
13
+ * @public
14
+ */
15
+ export type SecurityHeadersOptions = {
16
+ contentSecurityPolicy?: string | false | ((c: GravitoContext) => string | false);
17
+ frameOptions?: string | false;
18
+ referrerPolicy?: string | false;
19
+ noSniff?: boolean;
20
+ hsts?: HstsOptions | false;
21
+ permissionsPolicy?: string | false;
22
+ crossOriginOpenerPolicy?: string | false;
23
+ crossOriginResourcePolicy?: string | false;
24
+ };
25
+ /**
26
+ * Apply common security headers to responses (Helmet-style).
27
+ * @public
28
+ */
29
+ export declare function securityHeaders(options?: SecurityHeadersOptions): GravitoMiddleware;
@@ -0,0 +1,18 @@
1
+ import type { GravitoMiddleware } from '../../http/types';
2
+ import type { PlanetCore } from '../../PlanetCore';
3
+ /**
4
+ * Rate Limiting Middleware using Orbit Cache.
5
+ * Requires an active CacheService implementation.
6
+ * @public
7
+ */
8
+ export declare class ThrottleRequests {
9
+ private core;
10
+ private keyCache;
11
+ constructor(core: PlanetCore);
12
+ /**
13
+ * Create the middleware
14
+ * @param maxAttempts - Max requests allowed
15
+ * @param decaySeconds - Time window in seconds
16
+ */
17
+ handle(maxAttempts?: number, decaySeconds?: number): GravitoMiddleware;
18
+ }