@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,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core HTTP Types for Gravito Framework
|
|
3
|
+
*
|
|
4
|
+
* These types provide a unified abstraction layer that decouples the framework
|
|
5
|
+
* from any specific HTTP engine (Photon, Express, custom, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @module @gravito/core/http
|
|
8
|
+
* @since 2.0.0
|
|
9
|
+
*/
|
|
10
|
+
declare global {
|
|
11
|
+
interface ExecutionContext {
|
|
12
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
13
|
+
passThroughOnException(): void;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Standard HTTP methods supported by Gravito
|
|
18
|
+
*/
|
|
19
|
+
export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
20
|
+
/**
|
|
21
|
+
* HTTP status codes
|
|
22
|
+
*/
|
|
23
|
+
export type StatusCode = number;
|
|
24
|
+
/**
|
|
25
|
+
* Content-bearing HTTP status codes (excludes 1xx, 204, 304)
|
|
26
|
+
*/
|
|
27
|
+
export type ContentfulStatusCode = Exclude<StatusCode, 100 | 101 | 102 | 103 | 204 | 304>;
|
|
28
|
+
/**
|
|
29
|
+
* Base context variables available in every request
|
|
30
|
+
* Orbits can extend this interface via module augmentation
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Extending variables in your orbit:
|
|
35
|
+
* declare module '@gravito/core' {
|
|
36
|
+
* interface GravitoVariables {
|
|
37
|
+
* myService: MyService
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface GravitoVariables {
|
|
43
|
+
/**
|
|
44
|
+
* The PlanetCore instance
|
|
45
|
+
* @remarks Always available in PlanetCore-managed contexts
|
|
46
|
+
*/
|
|
47
|
+
core?: unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Logger instance
|
|
50
|
+
*/
|
|
51
|
+
logger?: unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Configuration manager
|
|
54
|
+
*/
|
|
55
|
+
config?: unknown;
|
|
56
|
+
/**
|
|
57
|
+
* Cookie jar for managing response cookies
|
|
58
|
+
*/
|
|
59
|
+
cookieJar?: unknown;
|
|
60
|
+
/** @deprecated Use ctx.route() instead */
|
|
61
|
+
route?: unknown;
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Validated request data targets
|
|
66
|
+
*/
|
|
67
|
+
export type ValidationTarget = 'json' | 'query' | 'param' | 'header' | 'form' | 'cookie';
|
|
68
|
+
/**
|
|
69
|
+
* GravitoRequest - Unified request interface
|
|
70
|
+
*
|
|
71
|
+
* Provides a consistent API for accessing request data regardless of
|
|
72
|
+
* the underlying HTTP engine.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const userId = ctx.req.param('id')
|
|
77
|
+
* const search = ctx.req.query('q')
|
|
78
|
+
* const body = await ctx.req.json<CreateUserDto>()
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export interface GravitoRequest {
|
|
82
|
+
/** Full request URL */
|
|
83
|
+
readonly url: string;
|
|
84
|
+
/** HTTP method (uppercase) */
|
|
85
|
+
readonly method: string;
|
|
86
|
+
/** Request path without query string */
|
|
87
|
+
readonly path: string;
|
|
88
|
+
/**
|
|
89
|
+
* Get a route parameter value
|
|
90
|
+
* @param name - Parameter name (e.g., 'id' for route '/users/:id')
|
|
91
|
+
*/
|
|
92
|
+
param(name: string): string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Get all route parameters
|
|
95
|
+
*/
|
|
96
|
+
params(): Record<string, string>;
|
|
97
|
+
/**
|
|
98
|
+
* Get a query string parameter
|
|
99
|
+
* @param name - Query parameter name
|
|
100
|
+
*/
|
|
101
|
+
query(name: string): string | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Get all query parameters
|
|
104
|
+
*/
|
|
105
|
+
queries(): Record<string, string | string[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Get a request header value
|
|
108
|
+
* @param name - Header name (case-insensitive)
|
|
109
|
+
*/
|
|
110
|
+
header(name: string): string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Get all request headers
|
|
113
|
+
*/
|
|
114
|
+
header(): Record<string, string>;
|
|
115
|
+
/**
|
|
116
|
+
* Parse request body as JSON
|
|
117
|
+
* @throws {Error} If body is not valid JSON
|
|
118
|
+
*/
|
|
119
|
+
json<T = unknown>(): Promise<T>;
|
|
120
|
+
/**
|
|
121
|
+
* Parse request body as text
|
|
122
|
+
*/
|
|
123
|
+
text(): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Parse request body as FormData
|
|
126
|
+
*/
|
|
127
|
+
formData(): Promise<FormData>;
|
|
128
|
+
/**
|
|
129
|
+
* Parse request body as ArrayBuffer
|
|
130
|
+
*/
|
|
131
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
132
|
+
/**
|
|
133
|
+
* Parse form data (urlencoded or multipart)
|
|
134
|
+
*/
|
|
135
|
+
parseBody<T = unknown>(): Promise<T>;
|
|
136
|
+
/**
|
|
137
|
+
* Get the raw Request object
|
|
138
|
+
*/
|
|
139
|
+
readonly raw: Request;
|
|
140
|
+
/**
|
|
141
|
+
* Get validated data from a specific source
|
|
142
|
+
* @param target - The validation target
|
|
143
|
+
* @throws {Error} If validation was not performed for this target
|
|
144
|
+
*/
|
|
145
|
+
valid<T = unknown>(target: ValidationTarget): T;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Options for request forwarding (Proxy)
|
|
149
|
+
*/
|
|
150
|
+
export interface ProxyOptions {
|
|
151
|
+
/** Override or add request headers */
|
|
152
|
+
headers?: Record<string, string>;
|
|
153
|
+
/** Whether to keep the original Host header (default: false) */
|
|
154
|
+
preserveHost?: boolean;
|
|
155
|
+
/** Whether to add X-Forwarded-* headers (default: true) */
|
|
156
|
+
addForwardedHeaders?: boolean;
|
|
157
|
+
/** Path rewriting logic */
|
|
158
|
+
rewritePath?: (path: string) => string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* GravitoContext - Unified request context
|
|
162
|
+
*
|
|
163
|
+
* This interface encapsulates all HTTP request/response operations,
|
|
164
|
+
* enabling seamless replacement of the underlying HTTP engine.
|
|
165
|
+
*
|
|
166
|
+
* @typeParam V - Context variables type
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // In a controller
|
|
171
|
+
* async show(ctx: GravitoContext) {
|
|
172
|
+
* const id = ctx.req.param('id')
|
|
173
|
+
* const user = await User.find(id)
|
|
174
|
+
* return ctx.json({ user })
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
|
|
179
|
+
/** The incoming request */
|
|
180
|
+
readonly req: GravitoRequest;
|
|
181
|
+
/**
|
|
182
|
+
* Send a JSON response
|
|
183
|
+
* @param data - Data to serialize as JSON
|
|
184
|
+
* @param status - HTTP status code (default: 200)
|
|
185
|
+
*/
|
|
186
|
+
json<T>(data: T, status?: ContentfulStatusCode): Response;
|
|
187
|
+
/**
|
|
188
|
+
* Send a plain text response
|
|
189
|
+
* @param text - Text content
|
|
190
|
+
* @param status - HTTP status code (default: 200)
|
|
191
|
+
*/
|
|
192
|
+
text(text: string, status?: ContentfulStatusCode): Response;
|
|
193
|
+
/**
|
|
194
|
+
* Send an HTML response
|
|
195
|
+
* @param html - HTML content
|
|
196
|
+
* @param status - HTTP status code (default: 200)
|
|
197
|
+
*/
|
|
198
|
+
html(html: string, status?: ContentfulStatusCode): Response;
|
|
199
|
+
/**
|
|
200
|
+
* Send a redirect response
|
|
201
|
+
* @param url - Target URL
|
|
202
|
+
* @param status - Redirect status code (default: 302)
|
|
203
|
+
*/
|
|
204
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
205
|
+
/**
|
|
206
|
+
* Create a Response with no body
|
|
207
|
+
* @param status - HTTP status code
|
|
208
|
+
*/
|
|
209
|
+
body(data: BodyInit | null, status?: StatusCode): Response;
|
|
210
|
+
/**
|
|
211
|
+
* Stream a response
|
|
212
|
+
* @param stream - ReadableStream to send
|
|
213
|
+
* @param status - HTTP status code (default: 200)
|
|
214
|
+
*/
|
|
215
|
+
stream(stream: ReadableStream, status?: ContentfulStatusCode): Response;
|
|
216
|
+
/**
|
|
217
|
+
* Send a 404 Not Found response
|
|
218
|
+
*/
|
|
219
|
+
notFound(message?: string): Response;
|
|
220
|
+
/**
|
|
221
|
+
* Send a 403 Forbidden response
|
|
222
|
+
*/
|
|
223
|
+
forbidden(message?: string): Response;
|
|
224
|
+
/**
|
|
225
|
+
* Send a 401 Unauthorized response
|
|
226
|
+
*/
|
|
227
|
+
unauthorized(message?: string): Response;
|
|
228
|
+
/**
|
|
229
|
+
* Send a 400 Bad Request response
|
|
230
|
+
*/
|
|
231
|
+
badRequest(message?: string): Response;
|
|
232
|
+
/**
|
|
233
|
+
* Forward the current request to another URL (Reverse Proxy)
|
|
234
|
+
* @param target - Target URL or base URL to forward to
|
|
235
|
+
* @param options - Optional proxy options
|
|
236
|
+
*/
|
|
237
|
+
forward(target: string, options?: ProxyOptions): Promise<Response>;
|
|
238
|
+
/**
|
|
239
|
+
* Set a response header
|
|
240
|
+
* @param name - Header name
|
|
241
|
+
* @param value - Header value
|
|
242
|
+
* @param options - Options (append: true to add multiple values)
|
|
243
|
+
*/
|
|
244
|
+
header(name: string, value: string, options?: {
|
|
245
|
+
append?: boolean;
|
|
246
|
+
}): void;
|
|
247
|
+
/**
|
|
248
|
+
* Get a request header
|
|
249
|
+
* @param name - Header name (case-insensitive)
|
|
250
|
+
*/
|
|
251
|
+
header(name: string): string | undefined;
|
|
252
|
+
/**
|
|
253
|
+
* Set the response status code
|
|
254
|
+
* @param code - HTTP status code
|
|
255
|
+
*/
|
|
256
|
+
status(code: StatusCode): void;
|
|
257
|
+
/**
|
|
258
|
+
* Get a context variable
|
|
259
|
+
* @param key - Variable key
|
|
260
|
+
*/
|
|
261
|
+
get<K extends keyof V>(key: K): V[K];
|
|
262
|
+
/**
|
|
263
|
+
* Set a context variable
|
|
264
|
+
* @param key - Variable key
|
|
265
|
+
* @param value - Variable value
|
|
266
|
+
*/
|
|
267
|
+
set<K extends keyof V>(key: K, value: V[K]): void;
|
|
268
|
+
/**
|
|
269
|
+
* Get the execution context (for Cloudflare Workers, etc.)
|
|
270
|
+
*/
|
|
271
|
+
readonly executionCtx?: ExecutionContext;
|
|
272
|
+
/**
|
|
273
|
+
* Get environment bindings (for Cloudflare Workers, etc.)
|
|
274
|
+
*/
|
|
275
|
+
readonly env?: Record<string, unknown>;
|
|
276
|
+
/**
|
|
277
|
+
* URL generator helper.
|
|
278
|
+
* Generates a URL for a named route.
|
|
279
|
+
*/
|
|
280
|
+
route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
|
|
281
|
+
/**
|
|
282
|
+
* Access the native context object from the underlying HTTP engine.
|
|
283
|
+
*
|
|
284
|
+
* ⚠️ WARNING: Using this ties your code to a specific adapter.
|
|
285
|
+
* Prefer using the abstraction methods when possible.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* // Only when absolutely necessary
|
|
290
|
+
* const photonCtx = ctx.native as Context // Photon Context
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
readonly native: unknown;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Next function for middleware chain
|
|
297
|
+
*/
|
|
298
|
+
export type GravitoNext = () => Promise<Response | undefined>;
|
|
299
|
+
/**
|
|
300
|
+
* GravitoHandler - Standard route handler type
|
|
301
|
+
*
|
|
302
|
+
* @typeParam V - Context variables type
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const handler: GravitoHandler = async (ctx) => {
|
|
307
|
+
* return ctx.json({ message: 'Hello, World!' })
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
export type GravitoHandler<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>) => Response | Promise<Response>;
|
|
312
|
+
/**
|
|
313
|
+
* GravitoMiddleware - Standard middleware type
|
|
314
|
+
*
|
|
315
|
+
* @typeParam V - Context variables type
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const logger: GravitoMiddleware = async (ctx, next) => {
|
|
320
|
+
* console.log(`${ctx.req.method} ${ctx.req.path}`)
|
|
321
|
+
* await next()
|
|
322
|
+
* return undefined
|
|
323
|
+
* }
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
export type GravitoMiddleware<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>, next: GravitoNext) => Response | undefined | Promise<Response | undefined | undefined>;
|
|
327
|
+
/**
|
|
328
|
+
* Error handler type
|
|
329
|
+
*/
|
|
330
|
+
export type GravitoErrorHandler<V extends GravitoVariables = GravitoVariables> = (error: Error, ctx: GravitoContext<V>) => Response | Promise<Response>;
|
|
331
|
+
/**
|
|
332
|
+
* Not found handler type
|
|
333
|
+
*/
|
|
334
|
+
export type GravitoNotFoundHandler<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>) => Response | Promise<Response>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core
|
|
3
|
+
*
|
|
4
|
+
* The core micro-kernel for the Galaxy Architecture.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import type { GravitoConfig } from './PlanetCore';
|
|
9
|
+
/**
|
|
10
|
+
* Current version of @gravito/core.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare const VERSION: string;
|
|
14
|
+
export { GravitoEngineAdapter } from './adapters/GravitoEngineAdapter';
|
|
15
|
+
export { createGravitoAdapter, createPhotonAdapter, GravitoAdapter, PhotonAdapter, PhotonContextWrapper, PhotonRequestWrapper, } from './adapters/PhotonAdapter';
|
|
16
|
+
export type { AdapterConfig, AdapterFactory, HttpAdapter, RouteDefinition } from './adapters/types';
|
|
17
|
+
export { isHttpAdapter } from './adapters/types';
|
|
18
|
+
export type { ContentfulStatusCode, GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNext, GravitoNotFoundHandler, GravitoRequest, GravitoVariables, HttpMethod, StatusCode, ValidationTarget, } from './http/types';
|
|
19
|
+
export { Application, type ApplicationConfig } from './Application';
|
|
20
|
+
export { ConfigManager } from './ConfigManager';
|
|
21
|
+
export { Container, type Factory } from './Container';
|
|
22
|
+
export { codeFromStatus, ErrorHandler, type ErrorHandlerDeps, messageFromStatus, } from './ErrorHandler';
|
|
23
|
+
export { EventManager } from './EventManager';
|
|
24
|
+
export * from './exceptions';
|
|
25
|
+
export { type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, type RegisterGlobalErrorHandlersOptions, registerGlobalErrorHandlers, } from './GlobalErrorHandlers';
|
|
26
|
+
export { type GravitoManifest, GravitoServer } from './GravitoServer';
|
|
27
|
+
export type { ActionCallback, FilterCallback } from './HookManager';
|
|
28
|
+
export { HookManager } from './HookManager';
|
|
29
|
+
export * from './helpers';
|
|
30
|
+
export { CookieJar, type CookieOptions } from './http/CookieJar';
|
|
31
|
+
export { type BodySizeLimitOptions, bodySizeLimit } from './http/middleware/BodySizeLimit';
|
|
32
|
+
export { type CorsOptions, type CorsOrigin, cors } from './http/middleware/Cors';
|
|
33
|
+
export { type CsrfOptions, csrfProtection, getCsrfToken } from './http/middleware/Csrf';
|
|
34
|
+
export { createHeaderGate, type HeaderTokenGateOptions, type RequireHeaderTokenOptions, requireHeaderToken, } from './http/middleware/HeaderTokenGate';
|
|
35
|
+
export { type HstsOptions, type SecurityHeadersOptions, securityHeaders, } from './http/middleware/SecurityHeaders';
|
|
36
|
+
export { ThrottleRequests } from './http/middleware/ThrottleRequests';
|
|
37
|
+
export type { Listener, ShouldQueue } from './Listener';
|
|
38
|
+
export type { Logger } from './Logger';
|
|
39
|
+
export { ConsoleLogger } from './Logger';
|
|
40
|
+
export { type CacheService, type ErrorHandlerContext, type GravitoConfig, type GravitoOrbit, PlanetCore, type ViewService, } from './PlanetCore';
|
|
41
|
+
export { Route } from './Route';
|
|
42
|
+
export { type ControllerClass, FORM_REQUEST_SYMBOL, type FormRequestClass, type FormRequestLike, RouteGroup, type RouteHandler, type RouteOptions, Router, } from './Router';
|
|
43
|
+
export { ServiceProvider } from './ServiceProvider';
|
|
44
|
+
export { Encrypter, type EncrypterOptions } from './security/Encrypter';
|
|
45
|
+
export type { Channel, ShouldBroadcast } from './types/events';
|
|
46
|
+
export { Event } from './types/events';
|
|
47
|
+
export * from './testing';
|
|
48
|
+
export { createSqliteDatabase, getPasswordAdapter, getRuntimeAdapter, getRuntimeEnv, type RuntimeAdapter, type RuntimeFileStat, type RuntimeKind, type RuntimePasswordAdapter, type RuntimeProcess, type RuntimeServeConfig, type RuntimeServer, type RuntimeSpawnOptions, type RuntimeSqliteDatabase, type RuntimeSqliteStatement, } from './runtime';
|
|
49
|
+
export * as engine from './engine';
|
|
50
|
+
/**
|
|
51
|
+
* Configure your Gravito application
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const config = defineConfig({
|
|
56
|
+
* config: {
|
|
57
|
+
* APP_NAME: 'My App',
|
|
58
|
+
* PORT: 3000,
|
|
59
|
+
* },
|
|
60
|
+
* orbits: [], // Add your orbits here
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* const core = await PlanetCore.boot(config)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function defineConfig(config: GravitoConfig): GravitoConfig;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detected Javascript Runtime Environment
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export type RuntimeKind = 'bun' | 'node' | 'deno' | 'unknown';
|
|
6
|
+
/**
|
|
7
|
+
* Options for spawning subprocesses
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface RuntimeSpawnOptions {
|
|
11
|
+
cwd?: string;
|
|
12
|
+
env?: Record<string, string | undefined>;
|
|
13
|
+
stdin?: 'pipe' | 'inherit' | 'ignore';
|
|
14
|
+
stdout?: 'pipe' | 'inherit' | 'ignore';
|
|
15
|
+
stderr?: 'pipe' | 'inherit' | 'ignore';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Abstract subprocess interface
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface RuntimeProcess {
|
|
22
|
+
exited: Promise<number>;
|
|
23
|
+
stdout?: ReadableStream<Uint8Array> | null;
|
|
24
|
+
stderr?: ReadableStream<Uint8Array> | null;
|
|
25
|
+
kill?: (signal?: string | number) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* File statistics abstraction
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface RuntimeFileStat {
|
|
32
|
+
size: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* HTTP Server configuration
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface RuntimeServeConfig {
|
|
39
|
+
port?: number;
|
|
40
|
+
fetch: (req: Request, server?: unknown) => Response | Promise<Response>;
|
|
41
|
+
websocket?: unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* HTTP Server interface
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export interface RuntimeServer {
|
|
48
|
+
stop?: () => void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Abstraction layer for filesystem and process operations across runtimes.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export interface RuntimeAdapter {
|
|
55
|
+
kind: RuntimeKind;
|
|
56
|
+
spawn(command: string[], options?: RuntimeSpawnOptions): RuntimeProcess;
|
|
57
|
+
writeFile(path: string, data: Blob | Buffer | string | ArrayBuffer | Uint8Array): Promise<void>;
|
|
58
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
59
|
+
readFileAsBlob(path: string): Promise<Blob>;
|
|
60
|
+
exists(path: string): Promise<boolean>;
|
|
61
|
+
stat(path: string): Promise<RuntimeFileStat>;
|
|
62
|
+
deleteFile(path: string): Promise<void>;
|
|
63
|
+
serve(config: RuntimeServeConfig): RuntimeServer;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Abstraction layer for password hashing
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface RuntimePasswordAdapter {
|
|
70
|
+
hash(value: string, options: {
|
|
71
|
+
algorithm: 'bcrypt';
|
|
72
|
+
cost?: number;
|
|
73
|
+
} | {
|
|
74
|
+
algorithm: 'argon2id';
|
|
75
|
+
memoryCost?: number;
|
|
76
|
+
timeCost?: number;
|
|
77
|
+
parallelism?: number;
|
|
78
|
+
}): Promise<string>;
|
|
79
|
+
verify(value: string, hashed: string): Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* SQLite Statement abstraction
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export interface RuntimeSqliteStatement {
|
|
86
|
+
run(params?: Record<string, unknown>): void;
|
|
87
|
+
get(params?: Record<string, unknown>): unknown;
|
|
88
|
+
all(params?: Record<string, unknown>): unknown[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* SQLite Database abstraction
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
export interface RuntimeSqliteDatabase {
|
|
95
|
+
run(sql: string): void;
|
|
96
|
+
prepare(sql: string): RuntimeSqliteStatement;
|
|
97
|
+
query(sql: string): RuntimeSqliteStatement;
|
|
98
|
+
close(): void;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get environment variables from the current runtime.
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
export declare const getRuntimeEnv: () => Record<string, string | undefined>;
|
|
105
|
+
/**
|
|
106
|
+
* Get the runtime abstraction adapter (Bun/Node/Deno).
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export declare const getRuntimeAdapter: () => RuntimeAdapter;
|
|
110
|
+
/**
|
|
111
|
+
* Get the password hashing adapter using native optimized implementations if available.
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
export declare const getPasswordAdapter: () => RuntimePasswordAdapter;
|
|
115
|
+
/**
|
|
116
|
+
* Create a SQLite database connection using runtime-native drivers.
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export declare const createSqliteDatabase: (path: string) => Promise<RuntimeSqliteDatabase>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the Encrypter class.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export interface EncrypterOptions {
|
|
6
|
+
key: string;
|
|
7
|
+
cipher?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Service for OpenSSL encryption/decryption.
|
|
11
|
+
* Compatible with Laravel's encryption format.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare class Encrypter {
|
|
15
|
+
private algorithm;
|
|
16
|
+
private key;
|
|
17
|
+
constructor(options: EncrypterOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Encrypt a value
|
|
20
|
+
*/
|
|
21
|
+
encrypt(value: unknown, serialize?: boolean): string;
|
|
22
|
+
/**
|
|
23
|
+
* Decrypt a value
|
|
24
|
+
*/
|
|
25
|
+
decrypt(payload: string, deserialize?: boolean): unknown;
|
|
26
|
+
private hash;
|
|
27
|
+
private validPayload;
|
|
28
|
+
private validMac;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a new key
|
|
31
|
+
*/
|
|
32
|
+
static generateKey(cipher?: string): string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hashing interface
|
|
3
|
+
*/
|
|
4
|
+
export interface Hasher {
|
|
5
|
+
/**
|
|
6
|
+
* Hash the given value
|
|
7
|
+
*/
|
|
8
|
+
make(value: string, options?: Record<string, unknown>): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Check the given plain value against a hash
|
|
11
|
+
*/
|
|
12
|
+
check(value: string, hashedValue: string): Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Check if the given hash has been hashed using the given options
|
|
15
|
+
*/
|
|
16
|
+
needsRehash(hashedValue: string, options?: Record<string, unknown>): boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bun Hasher
|
|
20
|
+
* Uses Bun's native password hashing (bcrypt by default)
|
|
21
|
+
*/
|
|
22
|
+
export declare class BunHasher implements Hasher {
|
|
23
|
+
make(value: string, options?: {
|
|
24
|
+
algorithm?: 'bcrypt' | 'argon2id';
|
|
25
|
+
cost?: number;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
check(value: string, hashedValue: string): Promise<boolean>;
|
|
28
|
+
needsRehash(_hashedValue: string, _options?: Record<string, unknown>): boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PlanetCore } from '../PlanetCore';
|
|
2
|
+
import { TestResponse } from './TestResponse';
|
|
3
|
+
/**
|
|
4
|
+
* HttpTester provides a way to simulate HTTP requests against a PlanetCore instance
|
|
5
|
+
* and returns a TestResponse for assertions.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HttpTester {
|
|
8
|
+
private core;
|
|
9
|
+
private cookies;
|
|
10
|
+
constructor(core: PlanetCore);
|
|
11
|
+
/**
|
|
12
|
+
* Make a GET request
|
|
13
|
+
*/
|
|
14
|
+
get(uri: string, headers?: Record<string, string>): Promise<TestResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* Make a POST request
|
|
17
|
+
*/
|
|
18
|
+
post(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Make a PUT request
|
|
21
|
+
*/
|
|
22
|
+
put(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Make a PATCH request
|
|
25
|
+
*/
|
|
26
|
+
patch(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Make a DELETE request
|
|
29
|
+
*/
|
|
30
|
+
delete(uri: string, data?: any, headers?: Record<string, string>): Promise<TestResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Core call method
|
|
33
|
+
*/
|
|
34
|
+
private call;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Helper to create an HttpTester for a PlanetCore instance
|
|
38
|
+
*/
|
|
39
|
+
export declare function createHttpTester(core: PlanetCore): HttpTester;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TestResponse wraps a standard Fetch Response and provides fluent assertion methods
|
|
3
|
+
* inspired by Laravel's TestResponse.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TestResponse {
|
|
6
|
+
readonly response: Response;
|
|
7
|
+
private _jsonData;
|
|
8
|
+
private _textData;
|
|
9
|
+
constructor(response: Response);
|
|
10
|
+
/**
|
|
11
|
+
* Assert the response status code
|
|
12
|
+
*/
|
|
13
|
+
assertStatus(status: number): this;
|
|
14
|
+
/**
|
|
15
|
+
* Assert that the response has a 200 status code
|
|
16
|
+
*/
|
|
17
|
+
assertOk(): this;
|
|
18
|
+
/**
|
|
19
|
+
* Assert that the response has a 201 status code
|
|
20
|
+
*/
|
|
21
|
+
assertCreated(): this;
|
|
22
|
+
/**
|
|
23
|
+
* Assert that the response has a 404 status code
|
|
24
|
+
*/
|
|
25
|
+
assertNotFound(): this;
|
|
26
|
+
/**
|
|
27
|
+
* Assert that the response has a 403 status code
|
|
28
|
+
*/
|
|
29
|
+
assertForbidden(): this;
|
|
30
|
+
/**
|
|
31
|
+
* Assert that the response has a 401 status code
|
|
32
|
+
*/
|
|
33
|
+
assertUnauthorized(): this;
|
|
34
|
+
/**
|
|
35
|
+
* Assert the response is a redirect
|
|
36
|
+
*/
|
|
37
|
+
assertRedirect(uri?: string): this;
|
|
38
|
+
/**
|
|
39
|
+
* Assert that the response contains the given JSON data.
|
|
40
|
+
*/
|
|
41
|
+
assertJson(data: any): Promise<this>;
|
|
42
|
+
/**
|
|
43
|
+
* Assert that the response contains exactly the given JSON data.
|
|
44
|
+
*/
|
|
45
|
+
assertExactJson(data: any): Promise<this>;
|
|
46
|
+
/**
|
|
47
|
+
* Assert the structure of the JSON response.
|
|
48
|
+
*/
|
|
49
|
+
assertJsonStructure(structure: any): Promise<this>;
|
|
50
|
+
/**
|
|
51
|
+
* Assert that the response contains the given string.
|
|
52
|
+
*/
|
|
53
|
+
assertSee(value: string): Promise<this>;
|
|
54
|
+
/**
|
|
55
|
+
* Assert that the response does not contain the given string.
|
|
56
|
+
*/
|
|
57
|
+
assertDontSee(value: string): Promise<this>;
|
|
58
|
+
/**
|
|
59
|
+
* Assert a header exists and matches value
|
|
60
|
+
*/
|
|
61
|
+
assertHeader(header: string, value: string): this;
|
|
62
|
+
/**
|
|
63
|
+
* Assert a header does not exist
|
|
64
|
+
*/
|
|
65
|
+
assertHeaderMissing(header: string): this;
|
|
66
|
+
/**
|
|
67
|
+
* Get the JSON content
|
|
68
|
+
*/
|
|
69
|
+
getJson(): Promise<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Get the text content
|
|
72
|
+
*/
|
|
73
|
+
getText(): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Alias for getText for standard expectations if needed
|
|
76
|
+
*/
|
|
77
|
+
get body(): Promise<string>;
|
|
78
|
+
}
|