@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,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Gravito Core Engine Types
|
|
3
|
+
*
|
|
4
|
+
* Minimal, high-performance types for the standalone engine.
|
|
5
|
+
* These are intentionally simpler than the full framework types.
|
|
6
|
+
*
|
|
7
|
+
* @module @gravito/core/engine
|
|
8
|
+
*/
|
|
9
|
+
import type { HttpMethod } from '../http/types';
|
|
10
|
+
/**
|
|
11
|
+
* FastContext - The pooled request context
|
|
12
|
+
*/
|
|
13
|
+
export interface FastContext {
|
|
14
|
+
/** Request accessor */
|
|
15
|
+
readonly req: FastRequest;
|
|
16
|
+
/** Response helpers */
|
|
17
|
+
json<T>(data: T, status?: number): Response;
|
|
18
|
+
text(text: string, status?: number): Response;
|
|
19
|
+
html(html: string, status?: number): Response;
|
|
20
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
21
|
+
body(data: BodyInit | null, status?: number): Response;
|
|
22
|
+
stream(stream: ReadableStream, status?: number): Response;
|
|
23
|
+
notFound(message?: string): Response;
|
|
24
|
+
forbidden(message?: string): Response;
|
|
25
|
+
unauthorized(message?: string): Response;
|
|
26
|
+
badRequest(message?: string): Response;
|
|
27
|
+
forward(target: string, options?: any): Promise<Response>;
|
|
28
|
+
/** Header management */
|
|
29
|
+
header(name: string): string | undefined;
|
|
30
|
+
header(name: string, value: string): void;
|
|
31
|
+
status(code: number): void;
|
|
32
|
+
/** Context Variables */
|
|
33
|
+
get<T>(key: string): T;
|
|
34
|
+
set(key: string, value: any): void;
|
|
35
|
+
/** Lifecycle helpers */
|
|
36
|
+
route: (name: string, params?: any, query?: any) => string;
|
|
37
|
+
readonly native: any;
|
|
38
|
+
/** Internal initialization for pooling */
|
|
39
|
+
init(request: Request, params?: Record<string, string>, path?: string): this;
|
|
40
|
+
/** Internal cleanup for pooling */
|
|
41
|
+
reset(): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* FastRequest - Minimal request interface
|
|
45
|
+
*/
|
|
46
|
+
export interface FastRequest {
|
|
47
|
+
/** Full URL */
|
|
48
|
+
readonly url: string;
|
|
49
|
+
/** HTTP method */
|
|
50
|
+
readonly method: string;
|
|
51
|
+
/** Path without query */
|
|
52
|
+
readonly path: string;
|
|
53
|
+
/** Get route parameter */
|
|
54
|
+
param(name: string): string | undefined;
|
|
55
|
+
/** Get all route parameters */
|
|
56
|
+
params(): Record<string, string>;
|
|
57
|
+
/** Get query parameter */
|
|
58
|
+
query(name: string): string | undefined;
|
|
59
|
+
/** Get all query parameters */
|
|
60
|
+
queries(): Record<string, string | string[]>;
|
|
61
|
+
/** Get header */
|
|
62
|
+
header(name: string): string | undefined;
|
|
63
|
+
/** Get all headers */
|
|
64
|
+
headers(): Record<string, string>;
|
|
65
|
+
/** Parse JSON body */
|
|
66
|
+
json<T = unknown>(): Promise<T>;
|
|
67
|
+
/** Parse text body */
|
|
68
|
+
text(): Promise<string>;
|
|
69
|
+
/** Parse form data */
|
|
70
|
+
formData(): Promise<FormData>;
|
|
71
|
+
/** Raw Request object */
|
|
72
|
+
readonly raw: Request;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Route handler function
|
|
76
|
+
*/
|
|
77
|
+
export type Handler = (ctx: FastContext) => Response | Promise<Response>;
|
|
78
|
+
/**
|
|
79
|
+
* Middleware function
|
|
80
|
+
*/
|
|
81
|
+
export type Middleware = (ctx: FastContext, next: () => Promise<Response | undefined>) => Response | undefined | Promise<Response | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* Error handler function
|
|
84
|
+
*/
|
|
85
|
+
export type ErrorHandler = (error: Error, ctx: FastContext) => Response | Promise<Response>;
|
|
86
|
+
/**
|
|
87
|
+
* Not found handler function
|
|
88
|
+
*/
|
|
89
|
+
export type NotFoundHandler = (ctx: FastContext) => Response | Promise<Response>;
|
|
90
|
+
/**
|
|
91
|
+
* Route metadata for middleware management
|
|
92
|
+
*/
|
|
93
|
+
export interface RouteMetadata {
|
|
94
|
+
handler: Handler;
|
|
95
|
+
middleware: Middleware[];
|
|
96
|
+
compiled?: CompiledHandler;
|
|
97
|
+
useMinimal?: boolean;
|
|
98
|
+
compiledVersion?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Compiled handler function
|
|
102
|
+
*/
|
|
103
|
+
export type CompiledHandler = (ctx: FastContext) => Promise<Response>;
|
|
104
|
+
/**
|
|
105
|
+
* Route match result from router
|
|
106
|
+
*/
|
|
107
|
+
export interface RouteMatch {
|
|
108
|
+
/** Matched handler */
|
|
109
|
+
handler: Handler | null;
|
|
110
|
+
/** Extracted route parameters */
|
|
111
|
+
params: Record<string, string>;
|
|
112
|
+
/** Middleware to execute */
|
|
113
|
+
middleware: Middleware[];
|
|
114
|
+
/** Optional stable route pattern for caching */
|
|
115
|
+
routePattern?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Internal route node
|
|
119
|
+
*/
|
|
120
|
+
export interface RouteNode {
|
|
121
|
+
method: HttpMethod;
|
|
122
|
+
path: string;
|
|
123
|
+
handler: Handler;
|
|
124
|
+
middleware: Middleware[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Engine configuration options
|
|
128
|
+
*/
|
|
129
|
+
export interface EngineOptions {
|
|
130
|
+
/** Context pool size (default: 256) */
|
|
131
|
+
poolSize?: number;
|
|
132
|
+
/** Enable route compilation optimization (default: true) */
|
|
133
|
+
enableAOT?: boolean;
|
|
134
|
+
/** Custom error handler */
|
|
135
|
+
onError?: ErrorHandler;
|
|
136
|
+
/** Custom 404 handler */
|
|
137
|
+
onNotFound?: NotFoundHandler;
|
|
138
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ContentfulStatusCode } from '../http/types';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a GravitoException
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ExceptionOptions {
|
|
7
|
+
message?: string;
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
i18nKey?: string;
|
|
10
|
+
i18nParams?: Record<string, string | number>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Base exception class for consistent error handling.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class GravitoException extends Error {
|
|
17
|
+
readonly status: ContentfulStatusCode;
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly i18nKey?: string;
|
|
20
|
+
readonly i18nParams?: Record<string, string | number>;
|
|
21
|
+
constructor(status: number, code: string, options?: ExceptionOptions);
|
|
22
|
+
getLocalizedMessage(t: (key: string, params?: Record<string, string | number>) => string): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContentfulStatusCode } from '../http/types';
|
|
2
|
+
import { type ExceptionOptions, GravitoException } from './GravitoException';
|
|
3
|
+
/**
|
|
4
|
+
* Generic HTTP Exception
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class HttpException extends GravitoException {
|
|
8
|
+
constructor(status: ContentfulStatusCode, options?: ExceptionOptions);
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GravitoException } from './GravitoException';
|
|
2
|
+
/**
|
|
3
|
+
* Exception thrown when a database model is not found.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class ModelNotFoundException extends GravitoException {
|
|
7
|
+
readonly model: string;
|
|
8
|
+
readonly id?: string | number;
|
|
9
|
+
constructor(model: string, id?: string | number);
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GravitoException } from './GravitoException';
|
|
2
|
+
/**
|
|
3
|
+
* Structure of a validation error
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ValidationError {
|
|
7
|
+
field: string;
|
|
8
|
+
message: string;
|
|
9
|
+
code?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Exception thrown when data validation fails.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare class ValidationException extends GravitoException {
|
|
16
|
+
readonly errors: ValidationError[];
|
|
17
|
+
redirectTo?: string;
|
|
18
|
+
input?: unknown;
|
|
19
|
+
constructor(errors: ValidationError[], message?: string);
|
|
20
|
+
withRedirect(url: string): this;
|
|
21
|
+
withInput(input: unknown): this;
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type DataPath } from './data';
|
|
2
|
+
/**
|
|
3
|
+
* Array and Collection Helpers.
|
|
4
|
+
* Provides utility methods for array manipulation and deep object access.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const Arr: {
|
|
8
|
+
readonly get: <TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault) => unknown | TDefault;
|
|
9
|
+
readonly has: (target: unknown, path: DataPath | null | undefined) => boolean;
|
|
10
|
+
readonly set: (target: unknown, path: DataPath, value: unknown, overwrite?: boolean) => unknown;
|
|
11
|
+
readonly wrap: <T>(value: T | T[] | null | undefined) => T[];
|
|
12
|
+
readonly first: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
|
|
13
|
+
readonly last: <T>(items: readonly T[], callback?: (value: T, index: number) => boolean) => T | undefined;
|
|
14
|
+
readonly only: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
|
|
15
|
+
readonly except: <T extends Record<string, unknown>>(target: T, keys: readonly string[]) => Partial<T>;
|
|
16
|
+
readonly flatten: (items: unknown[], depth?: number) => unknown[];
|
|
17
|
+
readonly pluck: <TItem extends Record<string, unknown>>(items: readonly TItem[], valuePath: DataPath, keyPath?: DataPath) => unknown[] | Record<string, unknown>;
|
|
18
|
+
readonly where: <T>(items: readonly T[], callback: (value: T, index: number) => boolean) => T[];
|
|
19
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type StartsEndsNeedle = string | readonly string[];
|
|
2
|
+
/**
|
|
3
|
+
* String Helper Utilities.
|
|
4
|
+
* Provides methods for string manipulation, case conversion, and UUID generation.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const Str: {
|
|
8
|
+
readonly lower: (value: string) => string;
|
|
9
|
+
readonly upper: (value: string) => string;
|
|
10
|
+
readonly startsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
11
|
+
readonly endsWith: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
12
|
+
readonly contains: (haystack: string, needles: StartsEndsNeedle) => boolean;
|
|
13
|
+
readonly snake: (value: string) => string;
|
|
14
|
+
readonly kebab: (value: string) => string;
|
|
15
|
+
readonly studly: (value: string) => string;
|
|
16
|
+
readonly camel: (value: string) => string;
|
|
17
|
+
readonly title: (value: string) => string;
|
|
18
|
+
readonly limit: (value: string, limit: number, end?: string) => string;
|
|
19
|
+
readonly slug: (value: string, separator?: string) => string;
|
|
20
|
+
readonly uuid: () => string;
|
|
21
|
+
readonly random: (length?: number) => string;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path segment (key) in a data structure.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export type PathSegment = string | number;
|
|
6
|
+
/**
|
|
7
|
+
* Path to a value (dot notation or array of segments).
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type DataPath = string | readonly PathSegment[];
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a value from a deep object using dot notation.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataGet<TDefault = undefined>(target: unknown, path: DataPath | null | undefined, defaultValue?: TDefault): unknown | TDefault;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a key exists in a deep object using dot notation.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function dataHas(target: unknown, path: DataPath | null | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Set a value in a deep object using dot notation.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare function dataSet(target: unknown, path: DataPath, setValue: unknown, overwrite?: boolean): unknown;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GravitoContext } from '../http/types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for displaying validation errors in views.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ErrorBag {
|
|
7
|
+
/** Check if a field has errors */
|
|
8
|
+
has(field: string): boolean;
|
|
9
|
+
/** Get the first error message for a field (or any first error if no field specified) */
|
|
10
|
+
first(field?: string): string | undefined;
|
|
11
|
+
/** Get all error messages for a field */
|
|
12
|
+
get(field: string): string[];
|
|
13
|
+
/** Get all errors for all fields */
|
|
14
|
+
all(): Record<string, string[]>;
|
|
15
|
+
/** Check if there are any errors */
|
|
16
|
+
any(): boolean;
|
|
17
|
+
/** Get total number of error messages */
|
|
18
|
+
count(): number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a new ErrorBag instance from raw errors.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare function createErrorBag(errors: Record<string, string[]>): ErrorBag;
|
|
25
|
+
/**
|
|
26
|
+
* Helper to retrieve the ErrorBag from session flash data.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function errors(c: GravitoContext): ErrorBag;
|
|
30
|
+
/**
|
|
31
|
+
* Helper to retrieve old input value from session flash.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare function old(c: GravitoContext, field: string, defaultValue?: unknown): unknown;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContentfulStatusCode, GravitoContext } from '../http/types';
|
|
2
|
+
/**
|
|
3
|
+
* Standard API Success Response Structure
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type ApiSuccess<T> = {
|
|
7
|
+
success: true;
|
|
8
|
+
data: T;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Standard API Failure Response Structure
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type ApiFailure = {
|
|
15
|
+
success: false;
|
|
16
|
+
error: {
|
|
17
|
+
message: string;
|
|
18
|
+
code?: string;
|
|
19
|
+
details?: unknown;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Create a success response object.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function ok<T>(data: T): ApiSuccess<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a failure response object.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function fail(message: string, code?: string, details?: unknown): ApiFailure;
|
|
32
|
+
/**
|
|
33
|
+
* Return a JSON response with standard success structure.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare function jsonSuccess<T>(c: GravitoContext, data: T, status?: ContentfulStatusCode): Response;
|
|
37
|
+
/**
|
|
38
|
+
* Return a JSON response with standard failure structure.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare function jsonFail(c: GravitoContext, message: string, status?: ContentfulStatusCode, code?: string, details?: unknown): Response;
|