@gravito/echo 3.1.1 → 4.0.0
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/README.md +24 -9
- package/dist/OrbitEcho.d.ts +76 -60
- package/dist/errors/EchoError.d.ts +29 -0
- package/dist/errors/codes.d.ts +20 -0
- package/dist/index.d.ts +34 -16
- package/dist/index.js +3 -1596
- package/dist/index.js.map +3 -28
- package/dist/{echo/src/middleware → middleware}/RequestBufferMiddleware.d.ts +3 -3
- package/dist/providers/GenericProvider.d.ts +37 -19
- package/dist/providers/GitHubProvider.d.ts +21 -13
- package/dist/providers/StripeProvider.d.ts +20 -13
- package/dist/providers/index.d.ts +14 -4
- package/dist/receive/SignatureValidator.d.ts +33 -1
- package/dist/receive/WebhookReceiver.d.ts +139 -22
- package/dist/receive/index.d.ts +0 -1
- package/dist/resilience/CircuitBreaker.d.ts +6 -0
- package/dist/{echo/src/resilience → resilience}/index.d.ts +2 -1
- package/dist/send/WebhookDispatcher.d.ts +159 -16
- package/dist/send/index.d.ts +0 -1
- package/dist/types.d.ts +671 -57
- package/package.json +9 -3
- package/dist/OrbitEcho.d.ts.map +0 -1
- package/dist/atlas/src/DB.d.ts +0 -348
- package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
- package/dist/atlas/src/config/defineConfig.d.ts +0 -14
- package/dist/atlas/src/config/index.d.ts +0 -7
- package/dist/atlas/src/config/loadConfig.d.ts +0 -41
- package/dist/atlas/src/connection/Connection.d.ts +0 -112
- package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -180
- package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +0 -54
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -79
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -96
- package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
- package/dist/atlas/src/drivers/types.d.ts +0 -260
- package/dist/atlas/src/errors/index.d.ts +0 -45
- package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
- package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
- package/dist/atlas/src/index.d.ts +0 -79
- package/dist/atlas/src/migration/Migration.d.ts +0 -64
- package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
- package/dist/atlas/src/migration/Migrator.d.ts +0 -110
- package/dist/atlas/src/migration/index.d.ts +0 -6
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -33
- package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
- package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
- package/dist/atlas/src/observability/index.d.ts +0 -9
- package/dist/atlas/src/orm/Repository.d.ts +0 -247
- package/dist/atlas/src/orm/index.d.ts +0 -6
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
- package/dist/atlas/src/orm/model/Model.d.ts +0 -458
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -150
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -92
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
- package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
- package/dist/atlas/src/orm/model/decorators.d.ts +0 -138
- package/dist/atlas/src/orm/model/errors.d.ts +0 -52
- package/dist/atlas/src/orm/model/index.d.ts +0 -10
- package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
- package/dist/atlas/src/orm/model/types.d.ts +0 -12
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -124
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
- package/dist/atlas/src/orm/schema/index.d.ts +0 -6
- package/dist/atlas/src/orm/schema/types.d.ts +0 -85
- package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +0 -98
- package/dist/atlas/src/pool/PoolHealthChecker.d.ts +0 -91
- package/dist/atlas/src/pool/PoolStrategy.d.ts +0 -129
- package/dist/atlas/src/pool/PoolWarmer.d.ts +0 -92
- package/dist/atlas/src/query/Expression.d.ts +0 -60
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
- package/dist/atlas/src/query/QueryBuilder.d.ts +0 -643
- package/dist/atlas/src/query/RelationshipResolver.d.ts +0 -23
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
- package/dist/atlas/src/query/clauses/index.d.ts +0 -11
- package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
- package/dist/atlas/src/schema/MigrationGenerator.d.ts +0 -45
- package/dist/atlas/src/schema/Schema.d.ts +0 -131
- package/dist/atlas/src/schema/SchemaDiff.d.ts +0 -73
- package/dist/atlas/src/schema/TypeGenerator.d.ts +0 -57
- package/dist/atlas/src/schema/TypeWriter.d.ts +0 -42
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
- package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
- package/dist/atlas/src/schema/index.d.ts +0 -8
- package/dist/atlas/src/seed/Factory.d.ts +0 -90
- package/dist/atlas/src/seed/Seeder.d.ts +0 -28
- package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
- package/dist/atlas/src/seed/index.d.ts +0 -6
- package/dist/atlas/src/sharding/ShardingManager.d.ts +0 -59
- package/dist/atlas/src/types/index.d.ts +0 -1182
- package/dist/atlas/src/utils/CursorEncoding.d.ts +0 -63
- package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
- package/dist/core/src/Application.d.ts +0 -215
- package/dist/core/src/CommandKernel.d.ts +0 -33
- package/dist/core/src/ConfigManager.d.ts +0 -65
- package/dist/core/src/Container/RequestScopeManager.d.ts +0 -62
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +0 -144
- package/dist/core/src/Container.d.ts +0 -153
- package/dist/core/src/ErrorHandler.d.ts +0 -66
- package/dist/core/src/Event.d.ts +0 -5
- package/dist/core/src/EventManager.d.ts +0 -123
- package/dist/core/src/GlobalErrorHandlers.d.ts +0 -47
- package/dist/core/src/GravitoServer.d.ts +0 -28
- package/dist/core/src/HookManager.d.ts +0 -591
- package/dist/core/src/Listener.d.ts +0 -4
- package/dist/core/src/Logger.d.ts +0 -20
- package/dist/core/src/PlanetCore.d.ts +0 -378
- package/dist/core/src/RequestContext.d.ts +0 -97
- package/dist/core/src/Route.d.ts +0 -36
- package/dist/core/src/Router.d.ts +0 -284
- package/dist/core/src/ServiceProvider.d.ts +0 -178
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +0 -27
- package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -175
- package/dist/core/src/adapters/bun/BunContext.d.ts +0 -49
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +0 -31
- package/dist/core/src/adapters/bun/BunRequest.d.ts +0 -31
- package/dist/core/src/adapters/bun/RadixNode.d.ts +0 -19
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +0 -31
- package/dist/core/src/adapters/bun/types.d.ts +0 -20
- package/dist/core/src/adapters/photon-types.d.ts +0 -73
- package/dist/core/src/adapters/types.d.ts +0 -235
- package/dist/core/src/cli/queue-commands.d.ts +0 -6
- package/dist/core/src/engine/AOTRouter.d.ts +0 -129
- package/dist/core/src/engine/FastContext.d.ts +0 -123
- package/dist/core/src/engine/Gravito.d.ts +0 -136
- package/dist/core/src/engine/MinimalContext.d.ts +0 -100
- package/dist/core/src/engine/analyzer.d.ts +0 -27
- package/dist/core/src/engine/constants.d.ts +0 -23
- package/dist/core/src/engine/index.d.ts +0 -26
- package/dist/core/src/engine/path.d.ts +0 -26
- package/dist/core/src/engine/pool.d.ts +0 -83
- package/dist/core/src/engine/types.d.ts +0 -146
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +0 -126
- package/dist/core/src/events/BackpressureManager.d.ts +0 -215
- package/dist/core/src/events/CircuitBreaker.d.ts +0 -229
- package/dist/core/src/events/DeadLetterQueue.d.ts +0 -219
- package/dist/core/src/events/EventBackend.d.ts +0 -12
- package/dist/core/src/events/EventOptions.d.ts +0 -204
- package/dist/core/src/events/EventPriorityQueue.d.ts +0 -301
- package/dist/core/src/events/FlowControlStrategy.d.ts +0 -109
- package/dist/core/src/events/IdempotencyCache.d.ts +0 -60
- package/dist/core/src/events/MessageQueueBridge.d.ts +0 -184
- package/dist/core/src/events/PriorityEscalationManager.d.ts +0 -82
- package/dist/core/src/events/RetryScheduler.d.ts +0 -104
- package/dist/core/src/events/WorkerPool.d.ts +0 -98
- package/dist/core/src/events/WorkerPoolConfig.d.ts +0 -153
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +0 -65
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +0 -77
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +0 -135
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +0 -108
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +0 -99
- package/dist/core/src/events/aggregation/types.d.ts +0 -117
- package/dist/core/src/events/index.d.ts +0 -25
- package/dist/core/src/events/observability/EventMetrics.d.ts +0 -132
- package/dist/core/src/events/observability/EventTracer.d.ts +0 -68
- package/dist/core/src/events/observability/EventTracing.d.ts +0 -161
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +0 -332
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +0 -108
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +0 -76
- package/dist/core/src/events/observability/index.d.ts +0 -24
- package/dist/core/src/events/observability/metrics-types.d.ts +0 -16
- package/dist/core/src/events/types.d.ts +0 -134
- package/dist/core/src/exceptions/AuthenticationException.d.ts +0 -8
- package/dist/core/src/exceptions/AuthorizationException.d.ts +0 -8
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +0 -9
- package/dist/core/src/exceptions/GravitoException.d.ts +0 -23
- package/dist/core/src/exceptions/HttpException.d.ts +0 -9
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +0 -10
- package/dist/core/src/exceptions/ValidationException.d.ts +0 -22
- package/dist/core/src/exceptions/index.d.ts +0 -7
- package/dist/core/src/health/HealthProvider.d.ts +0 -67
- package/dist/core/src/helpers/Arr.d.ts +0 -19
- package/dist/core/src/helpers/Str.d.ts +0 -23
- package/dist/core/src/helpers/data.d.ts +0 -25
- package/dist/core/src/helpers/errors.d.ts +0 -34
- package/dist/core/src/helpers/response.d.ts +0 -41
- package/dist/core/src/helpers.d.ts +0 -338
- package/dist/core/src/http/CookieJar.d.ts +0 -51
- package/dist/core/src/http/cookie.d.ts +0 -29
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
- package/dist/core/src/http/middleware/Cors.d.ts +0 -24
- package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
- package/dist/core/src/http/types.d.ts +0 -374
- package/dist/core/src/index.d.ts +0 -88
- package/dist/core/src/instrumentation/index.d.ts +0 -35
- package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
- package/dist/core/src/instrumentation/types.d.ts +0 -182
- package/dist/core/src/observability/Metrics.d.ts +0 -244
- package/dist/core/src/observability/QueueDashboard.d.ts +0 -136
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +0 -350
- package/dist/core/src/reliability/RetryPolicy.d.ts +0 -217
- package/dist/core/src/reliability/index.d.ts +0 -6
- package/dist/core/src/router/ControllerDispatcher.d.ts +0 -12
- package/dist/core/src/router/RequestValidator.d.ts +0 -20
- package/dist/core/src/runtime.d.ts +0 -119
- package/dist/core/src/security/Encrypter.d.ts +0 -33
- package/dist/core/src/security/Hasher.d.ts +0 -29
- package/dist/core/src/testing/HttpTester.d.ts +0 -39
- package/dist/core/src/testing/TestResponse.d.ts +0 -78
- package/dist/core/src/testing/index.d.ts +0 -2
- package/dist/core/src/types/events.d.ts +0 -94
- package/dist/echo/src/OrbitEcho.d.ts +0 -115
- package/dist/echo/src/index.d.ts +0 -64
- package/dist/echo/src/providers/GenericProvider.d.ts +0 -53
- package/dist/echo/src/providers/GitHubProvider.d.ts +0 -35
- package/dist/echo/src/providers/StripeProvider.d.ts +0 -38
- package/dist/echo/src/providers/index.d.ts +0 -14
- package/dist/echo/src/receive/SignatureValidator.d.ts +0 -67
- package/dist/echo/src/receive/WebhookReceiver.d.ts +0 -185
- package/dist/echo/src/receive/index.d.ts +0 -2
- package/dist/echo/src/resilience/CircuitBreaker.d.ts +0 -117
- package/dist/echo/src/send/WebhookDispatcher.d.ts +0 -198
- package/dist/echo/src/send/index.d.ts +0 -1
- package/dist/echo/src/types.d.ts +0 -756
- package/dist/index.d.ts.map +0 -1
- package/dist/monitor/src/MonitorOrbit.d.ts +0 -43
- package/dist/monitor/src/config.d.ts +0 -106
- package/dist/monitor/src/health/HealthController.d.ts +0 -28
- package/dist/monitor/src/health/HealthRegistry.d.ts +0 -80
- package/dist/monitor/src/health/index.d.ts +0 -36
- package/dist/monitor/src/index.d.ts +0 -13
- package/dist/monitor/src/metrics/MetricsController.d.ts +0 -22
- package/dist/monitor/src/metrics/MetricsRegistry.d.ts +0 -136
- package/dist/monitor/src/metrics/index.d.ts +0 -11
- package/dist/monitor/src/tracing/TracingManager.d.ts +0 -97
- package/dist/monitor/src/tracing/index.d.ts +0 -10
- package/dist/photon/src/index.d.ts +0 -89
- package/dist/photon/src/middleware/binary.d.ts +0 -31
- package/dist/photon/src/middleware/htmx.d.ts +0 -39
- package/dist/photon/src/middleware/ratelimit-redis.d.ts +0 -50
- package/dist/photon/src/middleware/ratelimit.d.ts +0 -161
- package/dist/photon/src/openapi.d.ts +0 -19
- package/dist/providers/GenericProvider.d.ts.map +0 -1
- package/dist/providers/GitHubProvider.d.ts.map +0 -1
- package/dist/providers/StripeProvider.d.ts.map +0 -1
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/receive/SignatureValidator.d.ts.map +0 -1
- package/dist/receive/WebhookReceiver.d.ts.map +0 -1
- package/dist/receive/index.d.ts.map +0 -1
- package/dist/send/WebhookDispatcher.d.ts.map +0 -1
- package/dist/send/index.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- /package/dist/{echo/src/dlq → dlq}/DeadLetterQueue.d.ts +0 -0
- /package/dist/{echo/src/dlq → dlq}/MemoryDeadLetterQueue.d.ts +0 -0
- /package/dist/{echo/src/dlq → dlq}/index.d.ts +0 -0
- /package/dist/{echo/src/middleware → middleware}/index.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/index.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/logging/ConsoleEchoLogger.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/logging/EchoLogger.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/logging/index.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/metrics/MetricsProvider.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/metrics/NoopMetricsProvider.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/metrics/PrometheusMetricsProvider.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/metrics/index.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/tracing/NoopTracer.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/tracing/Tracer.d.ts +0 -0
- /package/dist/{echo/src/observability → observability}/tracing/index.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/LinearProvider.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/PaddleProvider.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/ShopifyProvider.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/SlackProvider.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/TwilioProvider.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/base/BaseProvider.d.ts +0 -0
- /package/dist/{echo/src/providers → providers}/base/HeaderUtils.d.ts +0 -0
- /package/dist/{echo/src/replay → replay}/WebhookReplayService.d.ts +0 -0
- /package/dist/{echo/src/replay → replay}/index.d.ts +0 -0
- /package/dist/{echo/src/rotation → rotation}/KeyRotationManager.d.ts +0 -0
- /package/dist/{echo/src/rotation → rotation}/index.d.ts +0 -0
- /package/dist/{echo/src/storage → storage}/MemoryWebhookStore.d.ts +0 -0
- /package/dist/{echo/src/storage → storage}/WebhookStore.d.ts +0 -0
- /package/dist/{echo/src/storage → storage}/index.d.ts +0 -0
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { RequestScopeManager } from '../../Container/RequestScopeManager';
|
|
2
|
-
import type { ContentfulStatusCode, GravitoContext, GravitoVariables, ProxyOptions, StatusCode } from '../../http/types';
|
|
3
|
-
import { BunRequest } from './BunRequest';
|
|
4
|
-
/**
|
|
5
|
-
* Bun-optimized implementation of GravitoContext.
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export declare class BunContext<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
|
|
9
|
-
readonly env: Record<string, unknown>;
|
|
10
|
-
readonly req: BunRequest;
|
|
11
|
-
private _variables;
|
|
12
|
-
private _requestScope;
|
|
13
|
-
/**
|
|
14
|
-
* URL generator helper
|
|
15
|
-
*/
|
|
16
|
-
route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
|
|
17
|
-
private _status;
|
|
18
|
-
private _headers;
|
|
19
|
-
private _executionCtx?;
|
|
20
|
-
res: Response | undefined;
|
|
21
|
-
readonly native: unknown;
|
|
22
|
-
constructor(request: Request, env?: Record<string, unknown>, executionCtx?: ExecutionContext);
|
|
23
|
-
/**
|
|
24
|
-
* Create a proxied instance to enable object destructuring of context variables
|
|
25
|
-
* This allows: async list({ userService }: Context)
|
|
26
|
-
*/
|
|
27
|
-
static create<V extends GravitoVariables = GravitoVariables>(request: Request, env?: Record<string, unknown>, executionCtx?: ExecutionContext): GravitoContext<V>;
|
|
28
|
-
json<T>(data: T, status?: ContentfulStatusCode): Response;
|
|
29
|
-
text(text: string, status?: ContentfulStatusCode): Response;
|
|
30
|
-
html(html: string, status?: ContentfulStatusCode): Response;
|
|
31
|
-
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
32
|
-
body(data: BodyInit | null, status?: StatusCode): Response;
|
|
33
|
-
stream(stream: ReadableStream, status?: ContentfulStatusCode): Response;
|
|
34
|
-
notFound(message?: string): Response;
|
|
35
|
-
forbidden(message?: string): Response;
|
|
36
|
-
unauthorized(message?: string): Response;
|
|
37
|
-
badRequest(message?: string): Response;
|
|
38
|
-
forward(target: string, options?: ProxyOptions): Promise<Response>;
|
|
39
|
-
header(name: string, value: string, options?: {
|
|
40
|
-
append?: boolean;
|
|
41
|
-
}): void;
|
|
42
|
-
header(name: string): string | undefined;
|
|
43
|
-
status(code: StatusCode): void;
|
|
44
|
-
get<K extends keyof V>(key: K): V[K];
|
|
45
|
-
set<K extends keyof V>(key: K, value: V[K]): void;
|
|
46
|
-
get executionCtx(): ExecutionContext | undefined;
|
|
47
|
-
requestScope(): RequestScopeManager;
|
|
48
|
-
scoped<T>(key: string | symbol, factory: () => T): T;
|
|
49
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, HttpMethod } from '../../http/types';
|
|
2
|
-
import type { HttpAdapter, RouteDefinition } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Native Bun-optimized HTTP Adapter for Gravito.
|
|
5
|
-
* Uses Bun's standard Request/Response classes and efficient router.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export declare class BunNativeAdapter implements HttpAdapter {
|
|
9
|
-
readonly name = "bun-native";
|
|
10
|
-
readonly version = "0.0.1";
|
|
11
|
-
get native(): unknown;
|
|
12
|
-
private router;
|
|
13
|
-
private middlewares;
|
|
14
|
-
private errorHandler;
|
|
15
|
-
private notFoundHandler;
|
|
16
|
-
route(method: HttpMethod, path: string, ...handlers: (GravitoHandler | GravitoMiddleware)[]): void;
|
|
17
|
-
routes(routes: RouteDefinition[]): void;
|
|
18
|
-
use(path: string, ...middleware: GravitoMiddleware[]): void;
|
|
19
|
-
useGlobal(...middleware: GravitoMiddleware[]): void;
|
|
20
|
-
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware[]): void;
|
|
21
|
-
mount(path: string, subAdapter: HttpAdapter): void;
|
|
22
|
-
createContext(request: Request): GravitoContext;
|
|
23
|
-
onError(handler: GravitoErrorHandler): void;
|
|
24
|
-
onNotFound(handler: GravitoNotFoundHandler): void;
|
|
25
|
-
/**
|
|
26
|
-
* Predictive Route Warming (JIT Optimization)
|
|
27
|
-
*/
|
|
28
|
-
warmup(paths: string[]): Promise<void>;
|
|
29
|
-
fetch(request: Request, _server?: unknown): Promise<Response>;
|
|
30
|
-
private executeChain;
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { GravitoRequest, ValidationTarget } from '../../http/types';
|
|
2
|
-
/**
|
|
3
|
-
* Bun-optimized implementation of GravitoRequest.
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export declare class BunRequest implements GravitoRequest {
|
|
7
|
-
readonly raw: Request;
|
|
8
|
-
private _url;
|
|
9
|
-
private _params;
|
|
10
|
-
private _query;
|
|
11
|
-
private _validated;
|
|
12
|
-
constructor(raw: Request, params?: Record<string, string>);
|
|
13
|
-
setParams(params: Record<string, string>): void;
|
|
14
|
-
get url(): string;
|
|
15
|
-
get method(): string;
|
|
16
|
-
get path(): string;
|
|
17
|
-
param(name: string): string | undefined;
|
|
18
|
-
params(): Record<string, string>;
|
|
19
|
-
query(name: string): string | undefined;
|
|
20
|
-
queries(): Record<string, string | string[]>;
|
|
21
|
-
header(name: string): string | undefined;
|
|
22
|
-
header(): Record<string, string>;
|
|
23
|
-
json<T = unknown>(): Promise<T>;
|
|
24
|
-
text(): Promise<string>;
|
|
25
|
-
formData(): Promise<FormData>;
|
|
26
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
27
|
-
parseBody<T = unknown>(): Promise<T>;
|
|
28
|
-
setValidated(target: ValidationTarget, data: unknown): void;
|
|
29
|
-
valid<T = unknown>(target: ValidationTarget): T;
|
|
30
|
-
private parseQuery;
|
|
31
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { HttpMethod } from '../../http/types';
|
|
2
|
-
import { NodeType, type RouteHandler } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Node in the Radix Router tree.
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare class RadixNode {
|
|
8
|
-
segment: string;
|
|
9
|
-
type: NodeType;
|
|
10
|
-
children: Map<string, RadixNode>;
|
|
11
|
-
paramChild: RadixNode | null;
|
|
12
|
-
wildcardChild: RadixNode | null;
|
|
13
|
-
handlers: Map<HttpMethod, RouteHandler[]>;
|
|
14
|
-
paramName: string | null;
|
|
15
|
-
regex: RegExp | null;
|
|
16
|
-
constructor(segment?: string, type?: NodeType);
|
|
17
|
-
toJSON(): any;
|
|
18
|
-
static fromJSON(json: any): RadixNode;
|
|
19
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { HttpMethod } from '../../http/types';
|
|
2
|
-
import { type RouteHandler, type RouteMatch } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* High-performance Radix Tree Router for Bun
|
|
5
|
-
*/
|
|
6
|
-
export declare class RadixRouter {
|
|
7
|
-
private root;
|
|
8
|
-
private globalConstraints;
|
|
9
|
-
/**
|
|
10
|
-
* Add a generic parameter constraint
|
|
11
|
-
*/
|
|
12
|
-
where(param: string, regex: RegExp): void;
|
|
13
|
-
/**
|
|
14
|
-
* Register a route
|
|
15
|
-
*/
|
|
16
|
-
add(method: HttpMethod, path: string, handlers: RouteHandler[]): void;
|
|
17
|
-
/**
|
|
18
|
-
* Match a request
|
|
19
|
-
*/
|
|
20
|
-
match(method: string, path: string): RouteMatch | null;
|
|
21
|
-
private matchRecursive;
|
|
22
|
-
private splitPath;
|
|
23
|
-
/**
|
|
24
|
-
* Serialize the router to a JSON string
|
|
25
|
-
*/
|
|
26
|
-
serialize(): string;
|
|
27
|
-
/**
|
|
28
|
-
* Restore a router from a serialized JSON string
|
|
29
|
-
*/
|
|
30
|
-
static fromSerialized(json: string): RadixRouter;
|
|
31
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route Handler type (simplified for internal use)
|
|
3
|
-
* In the full framework this will align with GravitoHandler
|
|
4
|
-
*/
|
|
5
|
-
export type RouteHandler = Function;
|
|
6
|
-
/**
|
|
7
|
-
* Route Match Result
|
|
8
|
-
*/
|
|
9
|
-
export interface RouteMatch {
|
|
10
|
-
handlers: RouteHandler[];
|
|
11
|
-
params: Record<string, string>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Radix Node Type
|
|
15
|
-
*/
|
|
16
|
-
export declare enum NodeType {
|
|
17
|
-
STATIC = 0,
|
|
18
|
-
PARAM = 1,
|
|
19
|
-
WILDCARD = 2
|
|
20
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Photon Type Extensions
|
|
3
|
-
*
|
|
4
|
-
* Type definitions for Photon framework extensions and internal properties.
|
|
5
|
-
* These types help maintain type safety when working with Photon's native APIs.
|
|
6
|
-
*
|
|
7
|
-
* @module @gravito/core/adapters/photon-types
|
|
8
|
-
* @since 2.0.0
|
|
9
|
-
*/
|
|
10
|
-
import type { Context } from '@gravito/photon';
|
|
11
|
-
/**
|
|
12
|
-
* Extended Photon Request with additional properties
|
|
13
|
-
*/
|
|
14
|
-
export interface PhotonRequestExtended {
|
|
15
|
-
/**
|
|
16
|
-
* Validate request data against a schema
|
|
17
|
-
* This is typically added by validation middleware
|
|
18
|
-
*/
|
|
19
|
-
valid<T = unknown>(target: string): T;
|
|
20
|
-
/**
|
|
21
|
-
* Allow dynamic property access for middleware extensions
|
|
22
|
-
*/
|
|
23
|
-
[key: string]: unknown;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Extended Photon Context with internal caching
|
|
27
|
-
*/
|
|
28
|
-
export interface PhotonContextExtended extends Context {
|
|
29
|
-
/**
|
|
30
|
-
* Internal cache for parsed JSON body to avoid re-parsing
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
_cachedJsonBody?: unknown;
|
|
34
|
-
/**
|
|
35
|
-
* Extended request object
|
|
36
|
-
*/
|
|
37
|
-
req: Context['req'] & PhotonRequestExtended;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Extended Response with flash message support
|
|
41
|
-
* This is a partial interface since we're adding the method dynamically
|
|
42
|
-
*/
|
|
43
|
-
export interface ResponseWithFlash {
|
|
44
|
-
/**
|
|
45
|
-
* Add flash message to session (for redirect responses)
|
|
46
|
-
* @param key - Flash message key
|
|
47
|
-
* @param value - Flash message value
|
|
48
|
-
* @returns The response for chaining
|
|
49
|
-
*/
|
|
50
|
-
with(key: string, value: unknown): ResponseWithFlash;
|
|
51
|
-
[key: string]: unknown;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Session interface with flash message support
|
|
55
|
-
*/
|
|
56
|
-
export interface SessionWithFlash {
|
|
57
|
-
/**
|
|
58
|
-
* Store a flash message in the session
|
|
59
|
-
*/
|
|
60
|
-
flash(key: string, value: unknown): void;
|
|
61
|
-
/**
|
|
62
|
-
* Allow other session properties
|
|
63
|
-
*/
|
|
64
|
-
[key: string]: unknown;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Type guard to check if context has cached JSON body
|
|
68
|
-
*/
|
|
69
|
-
export declare function hasCachedJsonBody(ctx: Context): ctx is PhotonContextExtended;
|
|
70
|
-
/**
|
|
71
|
-
* Type guard to check if request has valid method
|
|
72
|
-
*/
|
|
73
|
-
export declare function hasValidMethod(req: Context['req']): req is Context['req'] & PhotonRequestExtended;
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview HTTP Adapter Interface for Gravito Framework
|
|
3
|
-
*
|
|
4
|
-
* This module defines the contract that all HTTP adapters must implement.
|
|
5
|
-
* By programming to this interface, Gravito can swap out the underlying
|
|
6
|
-
* HTTP engine without changing application code.
|
|
7
|
-
*
|
|
8
|
-
* @module @gravito/core/adapters
|
|
9
|
-
* @since 2.0.0
|
|
10
|
-
*/
|
|
11
|
-
import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, GravitoVariables, HttpMethod } from '../http/types';
|
|
12
|
-
/**
|
|
13
|
-
* Configuration options for HTTP adapters
|
|
14
|
-
*/
|
|
15
|
-
export interface AdapterConfig {
|
|
16
|
-
/**
|
|
17
|
-
* Base path prefix for all routes
|
|
18
|
-
* @default ''
|
|
19
|
-
*/
|
|
20
|
-
basePath?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Whether to enable strict routing (trailing slashes matter)
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
strictRouting?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Custom options passed to the underlying HTTP engine
|
|
28
|
-
*/
|
|
29
|
-
engineOptions?: Record<string, unknown>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Route definition structure
|
|
33
|
-
*/
|
|
34
|
-
export interface RouteDefinition {
|
|
35
|
-
method: HttpMethod;
|
|
36
|
-
path: string;
|
|
37
|
-
handlers: (GravitoHandler | GravitoMiddleware)[];
|
|
38
|
-
name?: string;
|
|
39
|
-
middleware?: GravitoMiddleware[];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* HttpAdapter - The core interface for HTTP engine abstraction
|
|
43
|
-
*
|
|
44
|
-
* Any HTTP engine (Photon, Express, Fastify, custom Bun implementation)
|
|
45
|
-
* must implement this interface to be usable with Gravito.
|
|
46
|
-
*
|
|
47
|
-
* @typeParam V - Context variables type
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```typescript
|
|
51
|
-
* // Using the default Photon adapter
|
|
52
|
-
* import { PhotonAdapter } from '@gravito/core/adapters'
|
|
53
|
-
*
|
|
54
|
-
* const core = new PlanetCore({
|
|
55
|
-
* adapter: new PhotonAdapter()
|
|
56
|
-
* })
|
|
57
|
-
*
|
|
58
|
-
* // Using a custom adapter
|
|
59
|
-
* import { BunNativeAdapter } from '@gravito/adapter-bun'
|
|
60
|
-
*
|
|
61
|
-
* const core = new PlanetCore({
|
|
62
|
-
* adapter: new BunNativeAdapter()
|
|
63
|
-
* })
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export interface HttpAdapter<V extends GravitoVariables = GravitoVariables> {
|
|
67
|
-
/**
|
|
68
|
-
* Adapter name for identification
|
|
69
|
-
* @example 'photon', 'bun-native', 'express'
|
|
70
|
-
*/
|
|
71
|
-
readonly name: string;
|
|
72
|
-
/**
|
|
73
|
-
* Adapter version
|
|
74
|
-
*/
|
|
75
|
-
readonly version: string;
|
|
76
|
-
/**
|
|
77
|
-
* Access the underlying native HTTP engine instance.
|
|
78
|
-
*
|
|
79
|
-
* ⚠️ WARNING: Using this ties your code to a specific adapter.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* // For Photon adapter
|
|
84
|
-
* const photonApp = adapter.native as Photon
|
|
85
|
-
*
|
|
86
|
-
* // For custom Bun adapter
|
|
87
|
-
* const bunApp = adapter.native as BunApp
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
readonly native: unknown;
|
|
91
|
-
/**
|
|
92
|
-
* Register a route with the adapter
|
|
93
|
-
*
|
|
94
|
-
* @param method - HTTP method
|
|
95
|
-
* @param path - Route path (may include parameters like ':id')
|
|
96
|
-
* @param handlers - One or more handlers for this route (handlers or middleware)
|
|
97
|
-
*/
|
|
98
|
-
route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
|
|
99
|
-
/**
|
|
100
|
-
* Register multiple routes at once
|
|
101
|
-
*
|
|
102
|
-
* @param routes - Array of route definitions
|
|
103
|
-
*/
|
|
104
|
-
routes(routes: RouteDefinition[]): void;
|
|
105
|
-
/**
|
|
106
|
-
* Register a middleware for a path
|
|
107
|
-
*
|
|
108
|
-
* @param path - Path pattern to match
|
|
109
|
-
* @param middleware - One or more middleware functions
|
|
110
|
-
*/
|
|
111
|
-
use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
112
|
-
/**
|
|
113
|
-
* Register a global middleware (applied to all routes)
|
|
114
|
-
*
|
|
115
|
-
* @param middleware - Middleware function
|
|
116
|
-
*/
|
|
117
|
-
useGlobal(...middleware: GravitoMiddleware<V>[]): void;
|
|
118
|
-
/**
|
|
119
|
-
* Register a scoped middleware for Orbit-level isolation
|
|
120
|
-
*
|
|
121
|
-
* Unlike regular `use()`, this method enforces stricter scoping rules:
|
|
122
|
-
* - REJECTS '*' wildcard paths (prevents global middleware in Orbits)
|
|
123
|
-
* - ENFORCES that all middleware paths must include the scope prefix
|
|
124
|
-
* - Throws error if attempting to register global middleware within an Orbit scope
|
|
125
|
-
*
|
|
126
|
-
* This is designed to prevent accidental middleware cross-contamination
|
|
127
|
-
* when multiple Orbits are mounted to a single PlanetCore instance.
|
|
128
|
-
*
|
|
129
|
-
* @param scope - The scope/path prefix (e.g., '/api', '/blog')
|
|
130
|
-
* @param path - Path pattern to match (cannot be '*')
|
|
131
|
-
* @param middleware - One or more middleware functions
|
|
132
|
-
* @throws {Error} If path is '*' when in Orbit scope
|
|
133
|
-
* @since 2.3.0
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* // Correct: Scoped to specific path
|
|
138
|
-
* adapter.useScoped('/api', '/users/*', authMiddleware)
|
|
139
|
-
*
|
|
140
|
-
* // Error: Cannot use wildcard in Orbit scope
|
|
141
|
-
* adapter.useScoped('/api', '*', loggerMiddleware)
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
145
|
-
/**
|
|
146
|
-
* Mount a sub-adapter at a path
|
|
147
|
-
*
|
|
148
|
-
* @param path - Mount path
|
|
149
|
-
* @param subAdapter - The adapter to mount
|
|
150
|
-
*/
|
|
151
|
-
mount(path: string, subAdapter: HttpAdapter<V>): void;
|
|
152
|
-
/**
|
|
153
|
-
* Set the error handler
|
|
154
|
-
*
|
|
155
|
-
* @param handler - Error handler function
|
|
156
|
-
*/
|
|
157
|
-
onError(handler: GravitoErrorHandler<V>): void;
|
|
158
|
-
/**
|
|
159
|
-
* Set the not-found handler
|
|
160
|
-
*
|
|
161
|
-
* @param handler - Not-found handler function
|
|
162
|
-
*/
|
|
163
|
-
onNotFound(handler: GravitoNotFoundHandler<V>): void;
|
|
164
|
-
/**
|
|
165
|
-
* The main fetch handler for serving requests.
|
|
166
|
-
*
|
|
167
|
-
* This is compatible with `Bun.serve()`, Cloudflare Workers,
|
|
168
|
-
* and other fetch-based runtimes.
|
|
169
|
-
*
|
|
170
|
-
* @param request - Incoming HTTP request
|
|
171
|
-
* @param server - Optional server context (Bun.Server, etc.)
|
|
172
|
-
* @returns HTTP response
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* // With Bun.serve
|
|
177
|
-
* Bun.serve({
|
|
178
|
-
* port: 3000,
|
|
179
|
-
* fetch: adapter.fetch
|
|
180
|
-
* })
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
fetch(request: Request, server?: unknown): Response | Promise<Response>;
|
|
184
|
-
/**
|
|
185
|
-
* Predictive Route Warming (JIT Optimization)
|
|
186
|
-
*
|
|
187
|
-
* Simulates requests to specified routes to trigger JIT compilation (FTL)
|
|
188
|
-
* before real traffic arrives.
|
|
189
|
-
*
|
|
190
|
-
* @param paths List of paths to warm up (e.g. ['/api/users', '/health'])
|
|
191
|
-
* @since 2.1.0
|
|
192
|
-
*/
|
|
193
|
-
warmup?(paths: string[]): Promise<void>;
|
|
194
|
-
/**
|
|
195
|
-
* WebSocket Handler for Bun.serve
|
|
196
|
-
*
|
|
197
|
-
* @since 2.2.0
|
|
198
|
-
*/
|
|
199
|
-
websocket?: {
|
|
200
|
-
open?(ws: unknown): void | Promise<void>;
|
|
201
|
-
message?(ws: unknown, message: string | Buffer | Uint8Array): void | Promise<void>;
|
|
202
|
-
close?(ws: unknown, code: number, message: string): void | Promise<void>;
|
|
203
|
-
drain?(ws: unknown): void | Promise<void>;
|
|
204
|
-
[key: string]: unknown;
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Initialize the adapter
|
|
208
|
-
*
|
|
209
|
-
* Called during PlanetCore.boot()
|
|
210
|
-
*/
|
|
211
|
-
init?(): void | Promise<void>;
|
|
212
|
-
/**
|
|
213
|
-
* Cleanup resources
|
|
214
|
-
*
|
|
215
|
-
* Called during graceful shutdown
|
|
216
|
-
*/
|
|
217
|
-
shutdown?(): void | Promise<void>;
|
|
218
|
-
/**
|
|
219
|
-
* Create a GravitoContext from a raw request.
|
|
220
|
-
*
|
|
221
|
-
* This is used internally for testing and advanced scenarios.
|
|
222
|
-
*
|
|
223
|
-
* @param request - Raw HTTP request
|
|
224
|
-
* @returns Gravito context
|
|
225
|
-
*/
|
|
226
|
-
createContext(request: Request): GravitoContext<V>;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Factory function type for creating adapters
|
|
230
|
-
*/
|
|
231
|
-
export type AdapterFactory<V extends GravitoVariables = GravitoVariables> = (config?: AdapterConfig) => HttpAdapter<V>;
|
|
232
|
-
/**
|
|
233
|
-
* Check if a value is an HttpAdapter
|
|
234
|
-
*/
|
|
235
|
-
export declare function isHttpAdapter(value: unknown): value is HttpAdapter;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CommandKernel } from '../CommandKernel';
|
|
2
|
-
import type { QueueDashboard } from '../observability/QueueDashboard';
|
|
3
|
-
/**
|
|
4
|
-
* Register queue management commands with CommandKernel
|
|
5
|
-
*/
|
|
6
|
-
export declare function registerQueueCommands(kernel: CommandKernel, dashboard: QueueDashboard): void;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview AOT (Ahead-of-Time) Router
|
|
3
|
-
*
|
|
4
|
-
* Hybrid routing strategy:
|
|
5
|
-
* - Static routes: O(1) Map lookup
|
|
6
|
-
* - Dynamic routes: Optimized Radix Tree
|
|
7
|
-
*
|
|
8
|
-
* The key optimization is separating static from dynamic routes at registration time,
|
|
9
|
-
* not at match time. This eliminates unnecessary tree traversal for static paths.
|
|
10
|
-
*
|
|
11
|
-
* @module @gravito/core/engine
|
|
12
|
-
*/
|
|
13
|
-
import type { HttpMethod } from '../http/types';
|
|
14
|
-
import type { Handler, Middleware, RouteMatch, RouteMetadata } from './types';
|
|
15
|
-
/**
|
|
16
|
-
* Route definition for re-playing routes (mounting)
|
|
17
|
-
*/
|
|
18
|
-
interface RouteDefinition {
|
|
19
|
-
method: HttpMethod;
|
|
20
|
-
path: string;
|
|
21
|
-
handler: Handler;
|
|
22
|
-
middleware: Middleware[];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* AOT Router - Optimized for Bun
|
|
26
|
-
*/
|
|
27
|
-
export declare class AOTRouter {
|
|
28
|
-
/** @internal */
|
|
29
|
-
readonly staticRoutes: Map<string, RouteMetadata>;
|
|
30
|
-
private dynamicRouter;
|
|
31
|
-
/** @internal */
|
|
32
|
-
readonly routeDefinitions: RouteDefinition[];
|
|
33
|
-
/** @internal */
|
|
34
|
-
readonly globalMiddleware: Middleware[];
|
|
35
|
-
/** @internal */
|
|
36
|
-
readonly pathMiddleware: Map<string, Middleware[]>;
|
|
37
|
-
private dynamicRoutePatterns;
|
|
38
|
-
private middlewareCache;
|
|
39
|
-
private cacheMaxSize;
|
|
40
|
-
private _version;
|
|
41
|
-
/**
|
|
42
|
-
* Get the current version for cache invalidation
|
|
43
|
-
* Incremented whenever middleware or routes are modified
|
|
44
|
-
*/
|
|
45
|
-
get version(): number;
|
|
46
|
-
/**
|
|
47
|
-
* Register a route
|
|
48
|
-
*
|
|
49
|
-
* Automatically determines if route is static or dynamic.
|
|
50
|
-
* Static routes are stored in a Map for O(1) lookup.
|
|
51
|
-
* Dynamic routes use the Radix Tree.
|
|
52
|
-
*
|
|
53
|
-
* @param method - HTTP method
|
|
54
|
-
* @param path - Route path
|
|
55
|
-
* @param handler - Route handler
|
|
56
|
-
* @param middleware - Route-specific middleware
|
|
57
|
-
*/
|
|
58
|
-
add(method: HttpMethod, path: string, handler: Handler, middleware?: Middleware[]): void;
|
|
59
|
-
/**
|
|
60
|
-
* Mount another router at a prefix
|
|
61
|
-
*/
|
|
62
|
-
mount(prefix: string, other: AOTRouter): void;
|
|
63
|
-
/**
|
|
64
|
-
* Add global middleware
|
|
65
|
-
*
|
|
66
|
-
* These run for every request, before route-specific middleware.
|
|
67
|
-
*
|
|
68
|
-
* @param middleware - Middleware functions
|
|
69
|
-
*/
|
|
70
|
-
use(...middleware: Middleware[]): void;
|
|
71
|
-
/**
|
|
72
|
-
* Add path-based middleware
|
|
73
|
-
*
|
|
74
|
-
* Supports wildcard patterns like '/api/*'
|
|
75
|
-
*
|
|
76
|
-
* @param pattern - Path pattern
|
|
77
|
-
* @param middleware - Middleware functions
|
|
78
|
-
*/
|
|
79
|
-
usePattern(pattern: string, ...middleware: Middleware[]): void;
|
|
80
|
-
/**
|
|
81
|
-
* Match a request to a route
|
|
82
|
-
*
|
|
83
|
-
* Returns the handler, params, and all applicable middleware.
|
|
84
|
-
*
|
|
85
|
-
* @param method - HTTP method
|
|
86
|
-
* @param path - Request path
|
|
87
|
-
* @returns Route match or null if not found
|
|
88
|
-
*/
|
|
89
|
-
match(method: string, path: string): RouteMatch;
|
|
90
|
-
/**
|
|
91
|
-
* Public wrapper for collectMiddleware (used by Gravito for optimization)
|
|
92
|
-
*/
|
|
93
|
-
collectMiddlewarePublic(path: string, routeMiddleware: Middleware[]): Middleware[];
|
|
94
|
-
/**
|
|
95
|
-
* Collect all applicable middleware for a path
|
|
96
|
-
*
|
|
97
|
-
* Order: global -> pattern-based -> route-specific
|
|
98
|
-
*
|
|
99
|
-
* @param path - Request path
|
|
100
|
-
* @param routeMiddleware - Route-specific middleware
|
|
101
|
-
* @returns Combined middleware array
|
|
102
|
-
*/
|
|
103
|
-
private collectMiddleware;
|
|
104
|
-
/**
|
|
105
|
-
* Check if a path is static (no parameters or wildcards)
|
|
106
|
-
*/
|
|
107
|
-
private isStaticPath;
|
|
108
|
-
/**
|
|
109
|
-
* Match a pattern against a path
|
|
110
|
-
*
|
|
111
|
-
* Supports:
|
|
112
|
-
* - Exact match: '/api/users'
|
|
113
|
-
* - Wildcard suffix: '/api/*'
|
|
114
|
-
*
|
|
115
|
-
* @param pattern - Pattern to match
|
|
116
|
-
* @param path - Path to test
|
|
117
|
-
* @returns True if pattern matches
|
|
118
|
-
*/
|
|
119
|
-
private matchPattern;
|
|
120
|
-
/**
|
|
121
|
-
* Get all registered routes (for debugging)
|
|
122
|
-
*/
|
|
123
|
-
getRoutes(): Array<{
|
|
124
|
-
method: string;
|
|
125
|
-
path: string;
|
|
126
|
-
type: 'static' | 'dynamic';
|
|
127
|
-
}>;
|
|
128
|
-
}
|
|
129
|
-
export {};
|