@gravito/echo 3.0.0 → 3.1.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 +211 -0
- package/dist/atlas/src/DB.d.ts +301 -0
- package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
- package/dist/atlas/src/config/defineConfig.d.ts +14 -0
- package/dist/atlas/src/config/index.d.ts +7 -0
- package/dist/atlas/src/config/loadConfig.d.ts +48 -0
- package/dist/atlas/src/connection/Connection.d.ts +108 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
- package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
- package/dist/atlas/src/drivers/types.d.ts +260 -0
- package/dist/atlas/src/errors/index.d.ts +45 -0
- package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
- package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
- package/dist/atlas/src/index.d.ts +67 -0
- package/dist/atlas/src/migration/Migration.d.ts +64 -0
- package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
- package/dist/atlas/src/migration/Migrator.d.ts +110 -0
- package/dist/atlas/src/migration/index.d.ts +6 -0
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
- package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
- package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
- package/dist/atlas/src/observability/index.d.ts +9 -0
- package/dist/atlas/src/orm/index.d.ts +5 -0
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
- package/dist/atlas/src/orm/model/Model.d.ts +449 -0
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
- package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
- package/dist/atlas/src/orm/model/errors.d.ts +52 -0
- package/dist/atlas/src/orm/model/index.d.ts +10 -0
- package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
- package/dist/atlas/src/orm/model/types.d.ts +12 -0
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
- package/dist/atlas/src/orm/schema/index.d.ts +6 -0
- package/dist/atlas/src/orm/schema/types.d.ts +85 -0
- package/dist/atlas/src/query/Expression.d.ts +60 -0
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
- package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
- package/dist/atlas/src/query/clauses/index.d.ts +11 -0
- package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
- package/dist/atlas/src/schema/Schema.d.ts +131 -0
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
- package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
- package/dist/atlas/src/schema/index.d.ts +8 -0
- package/dist/atlas/src/seed/Factory.d.ts +90 -0
- package/dist/atlas/src/seed/Seeder.d.ts +28 -0
- package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
- package/dist/atlas/src/seed/index.d.ts +6 -0
- package/dist/atlas/src/types/index.d.ts +1100 -0
- package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
- package/dist/core/src/Application.d.ts +215 -0
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +26 -0
- package/dist/core/src/Container.d.ts +108 -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 +496 -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 +289 -0
- package/dist/core/src/Route.d.ts +36 -0
- package/dist/core/src/Router.d.ts +284 -0
- package/dist/core/src/ServiceProvider.d.ts +156 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -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 +235 -0
- package/dist/core/src/engine/AOTRouter.d.ts +124 -0
- package/dist/core/src/engine/FastContext.d.ts +100 -0
- package/dist/core/src/engine/Gravito.d.ts +137 -0
- package/dist/core/src/engine/MinimalContext.d.ts +79 -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 +143 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
- package/dist/core/src/events/EventBackend.d.ts +11 -0
- package/dist/core/src/events/EventOptions.d.ts +109 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/index.d.ts +14 -0
- package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
- package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
- package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/index.d.ts +20 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/types.d.ts +75 -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/CircularDependencyException.d.ts +9 -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 +7 -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/cookie.d.ts +29 -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 +355 -0
- package/dist/core/src/index.d.ts +76 -0
- package/dist/core/src/instrumentation/index.d.ts +35 -0
- package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
- package/dist/core/src/instrumentation/types.d.ts +182 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
- package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
- package/dist/core/src/reliability/index.d.ts +6 -0
- package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
- package/dist/core/src/router/RequestValidator.d.ts +20 -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 +115 -0
- package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
- package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
- package/dist/echo/src/dlq/index.d.ts +2 -0
- package/dist/echo/src/index.d.ts +64 -0
- package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
- package/dist/echo/src/middleware/index.d.ts +8 -0
- package/dist/echo/src/observability/index.d.ts +3 -0
- package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
- package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
- package/dist/echo/src/observability/logging/index.d.ts +2 -0
- package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
- package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
- package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
- package/dist/echo/src/observability/metrics/index.d.ts +3 -0
- package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
- package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
- package/dist/echo/src/observability/tracing/index.d.ts +2 -0
- package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
- package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
- package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
- package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
- package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
- package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
- package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
- package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
- package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
- package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
- package/dist/echo/src/providers/index.d.ts +14 -0
- package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
- package/dist/echo/src/receive/index.d.ts +2 -0
- package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
- package/dist/echo/src/replay/index.d.ts +1 -0
- package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
- package/dist/echo/src/resilience/index.d.ts +10 -0
- package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
- package/dist/echo/src/rotation/index.d.ts +10 -0
- package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
- package/dist/echo/src/send/index.d.ts +1 -0
- package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
- package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
- package/dist/echo/src/storage/index.d.ts +2 -0
- package/dist/echo/src/types.d.ts +756 -0
- package/dist/index.js +1332 -190
- package/dist/index.js.map +28 -10
- package/dist/photon/src/index.d.ts +84 -0
- package/dist/photon/src/middleware/binary.d.ts +31 -0
- package/dist/photon/src/middleware/htmx.d.ts +39 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
- package/dist/photon/src/openapi.d.ts +19 -0
- package/package.json +7 -5
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { GravitoContext, GravitoMiddleware } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* HSTS Configuration
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type HstsOptions = {
|
|
7
|
+
maxAge: number;
|
|
8
|
+
includeSubDomains?: boolean;
|
|
9
|
+
preload?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Options for Security Headers middleware
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export type SecurityHeadersOptions = {
|
|
16
|
+
contentSecurityPolicy?: string | false | ((c: GravitoContext) => string | false);
|
|
17
|
+
frameOptions?: string | false;
|
|
18
|
+
referrerPolicy?: string | false;
|
|
19
|
+
noSniff?: boolean;
|
|
20
|
+
hsts?: HstsOptions | false;
|
|
21
|
+
permissionsPolicy?: string | false;
|
|
22
|
+
crossOriginOpenerPolicy?: string | false;
|
|
23
|
+
crossOriginResourcePolicy?: string | false;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Apply common security headers to responses (Helmet-style).
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function securityHeaders(options?: SecurityHeadersOptions): GravitoMiddleware;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GravitoMiddleware } from '../../http/types';
|
|
2
|
+
import type { PlanetCore } from '../../PlanetCore';
|
|
3
|
+
/**
|
|
4
|
+
* Rate Limiting Middleware using Orbit Cache.
|
|
5
|
+
* Requires an active CacheService implementation.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class ThrottleRequests {
|
|
9
|
+
private core;
|
|
10
|
+
private keyCache;
|
|
11
|
+
constructor(core: PlanetCore);
|
|
12
|
+
/**
|
|
13
|
+
* Create the middleware
|
|
14
|
+
* @param maxAttempts - Max requests allowed
|
|
15
|
+
* @param decaySeconds - Time window in seconds
|
|
16
|
+
*/
|
|
17
|
+
handle(maxAttempts?: number, decaySeconds?: number): GravitoMiddleware;
|
|
18
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
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
|
+
/**
|
|
61
|
+
* Middleware scope tracking for Orbit isolation
|
|
62
|
+
* Tracks which Orbit/scope this request belongs to
|
|
63
|
+
* Used to prevent cross-Orbit middleware contamination
|
|
64
|
+
* @since 2.3.0
|
|
65
|
+
*/
|
|
66
|
+
middlewareScope?: string;
|
|
67
|
+
/** @deprecated Use ctx.route() instead */
|
|
68
|
+
route?: unknown;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Validated request data targets
|
|
73
|
+
*/
|
|
74
|
+
export type ValidationTarget = 'json' | 'query' | 'param' | 'header' | 'form' | 'cookie';
|
|
75
|
+
/**
|
|
76
|
+
* GravitoRequest - Unified request interface
|
|
77
|
+
*
|
|
78
|
+
* Provides a consistent API for accessing request data regardless of
|
|
79
|
+
* the underlying HTTP engine.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const userId = ctx.req.param('id')
|
|
84
|
+
* const search = ctx.req.query('q')
|
|
85
|
+
* const body = await ctx.req.json<CreateUserDto>()
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export interface GravitoRequest {
|
|
89
|
+
/** Full request URL */
|
|
90
|
+
readonly url: string;
|
|
91
|
+
/** HTTP method (uppercase) */
|
|
92
|
+
readonly method: string;
|
|
93
|
+
/** Request path without query string */
|
|
94
|
+
readonly path: string;
|
|
95
|
+
/**
|
|
96
|
+
* Route pattern (e.g., /users/:id) for the matched route
|
|
97
|
+
*
|
|
98
|
+
* This provides the parameterized route pattern instead of the concrete path,
|
|
99
|
+
* which is critical for preventing high cardinality issues in metrics systems.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // For request: GET /users/123
|
|
104
|
+
* ctx.req.path // => "/users/123"
|
|
105
|
+
* ctx.req.routePattern // => "/users/:id"
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
readonly routePattern?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Get a route parameter value
|
|
111
|
+
* @param name - Parameter name (e.g., 'id' for route '/users/:id')
|
|
112
|
+
*/
|
|
113
|
+
param(name: string): string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Get all route parameters
|
|
116
|
+
*/
|
|
117
|
+
params(): Record<string, string>;
|
|
118
|
+
/**
|
|
119
|
+
* Get a query string parameter
|
|
120
|
+
* @param name - Query parameter name
|
|
121
|
+
*/
|
|
122
|
+
query(name: string): string | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Get all query parameters
|
|
125
|
+
*/
|
|
126
|
+
queries(): Record<string, string | string[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Get a request header value
|
|
129
|
+
* @param name - Header name (case-insensitive)
|
|
130
|
+
*/
|
|
131
|
+
header(name: string): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Get all request headers
|
|
134
|
+
*/
|
|
135
|
+
header(): Record<string, string>;
|
|
136
|
+
/**
|
|
137
|
+
* Parse request body as JSON
|
|
138
|
+
* @throws {Error} If body is not valid JSON
|
|
139
|
+
*/
|
|
140
|
+
json<T = unknown>(): Promise<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Parse request body as text
|
|
143
|
+
*/
|
|
144
|
+
text(): Promise<string>;
|
|
145
|
+
/**
|
|
146
|
+
* Parse request body as FormData
|
|
147
|
+
*/
|
|
148
|
+
formData(): Promise<FormData>;
|
|
149
|
+
/**
|
|
150
|
+
* Parse request body as ArrayBuffer
|
|
151
|
+
*/
|
|
152
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
153
|
+
/**
|
|
154
|
+
* Parse form data (urlencoded or multipart)
|
|
155
|
+
*/
|
|
156
|
+
parseBody<T = unknown>(): Promise<T>;
|
|
157
|
+
/**
|
|
158
|
+
* Get the raw Request object
|
|
159
|
+
*/
|
|
160
|
+
readonly raw: Request;
|
|
161
|
+
/**
|
|
162
|
+
* Get validated data from a specific source
|
|
163
|
+
* @param target - The validation target
|
|
164
|
+
* @throws {Error} If validation was not performed for this target
|
|
165
|
+
*/
|
|
166
|
+
valid<T = unknown>(target: ValidationTarget): T;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Options for request forwarding (Proxy)
|
|
170
|
+
*/
|
|
171
|
+
export interface ProxyOptions {
|
|
172
|
+
/** Override or add request headers */
|
|
173
|
+
headers?: Record<string, string>;
|
|
174
|
+
/** Whether to keep the original Host header (default: false) */
|
|
175
|
+
preserveHost?: boolean;
|
|
176
|
+
/** Whether to add X-Forwarded-* headers (default: true) */
|
|
177
|
+
addForwardedHeaders?: boolean;
|
|
178
|
+
/** Path rewriting logic */
|
|
179
|
+
rewritePath?: (path: string) => string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* GravitoContext - Unified request context
|
|
183
|
+
*
|
|
184
|
+
* This interface encapsulates all HTTP request/response operations,
|
|
185
|
+
* enabling seamless replacement of the underlying HTTP engine.
|
|
186
|
+
*
|
|
187
|
+
* @typeParam V - Context variables type
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // In a controller
|
|
192
|
+
* async show(ctx: GravitoContext) {
|
|
193
|
+
* const id = ctx.req.param('id')
|
|
194
|
+
* const user = await User.find(id)
|
|
195
|
+
* return ctx.json({ user })
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
|
|
200
|
+
/** The incoming request */
|
|
201
|
+
readonly req: GravitoRequest;
|
|
202
|
+
/**
|
|
203
|
+
* Send a JSON response
|
|
204
|
+
* @param data - Data to serialize as JSON
|
|
205
|
+
* @param status - HTTP status code (default: 200)
|
|
206
|
+
*/
|
|
207
|
+
json<T>(data: T, status?: ContentfulStatusCode): Response;
|
|
208
|
+
/**
|
|
209
|
+
* Send a plain text response
|
|
210
|
+
* @param text - Text content
|
|
211
|
+
* @param status - HTTP status code (default: 200)
|
|
212
|
+
*/
|
|
213
|
+
text(text: string, status?: ContentfulStatusCode): Response;
|
|
214
|
+
/**
|
|
215
|
+
* Send an HTML response
|
|
216
|
+
* @param html - HTML content
|
|
217
|
+
* @param status - HTTP status code (default: 200)
|
|
218
|
+
*/
|
|
219
|
+
html(html: string, status?: ContentfulStatusCode): Response;
|
|
220
|
+
/**
|
|
221
|
+
* Send a redirect response
|
|
222
|
+
* @param url - Target URL
|
|
223
|
+
* @param status - Redirect status code (default: 302)
|
|
224
|
+
*/
|
|
225
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
226
|
+
/**
|
|
227
|
+
* Create a Response with no body
|
|
228
|
+
* @param status - HTTP status code
|
|
229
|
+
*/
|
|
230
|
+
body(data: BodyInit | null, status?: StatusCode): Response;
|
|
231
|
+
/**
|
|
232
|
+
* Stream a response
|
|
233
|
+
* @param stream - ReadableStream to send
|
|
234
|
+
* @param status - HTTP status code (default: 200)
|
|
235
|
+
*/
|
|
236
|
+
stream(stream: ReadableStream, status?: ContentfulStatusCode): Response;
|
|
237
|
+
/**
|
|
238
|
+
* Send a 404 Not Found response
|
|
239
|
+
*/
|
|
240
|
+
notFound(message?: string): Response;
|
|
241
|
+
/**
|
|
242
|
+
* Send a 403 Forbidden response
|
|
243
|
+
*/
|
|
244
|
+
forbidden(message?: string): Response;
|
|
245
|
+
/**
|
|
246
|
+
* Send a 401 Unauthorized response
|
|
247
|
+
*/
|
|
248
|
+
unauthorized(message?: string): Response;
|
|
249
|
+
/**
|
|
250
|
+
* Send a 400 Bad Request response
|
|
251
|
+
*/
|
|
252
|
+
badRequest(message?: string): Response;
|
|
253
|
+
/**
|
|
254
|
+
* Forward the current request to another URL (Reverse Proxy)
|
|
255
|
+
* @param target - Target URL or base URL to forward to
|
|
256
|
+
* @param options - Optional proxy options
|
|
257
|
+
*/
|
|
258
|
+
forward(target: string, options?: ProxyOptions): Promise<Response>;
|
|
259
|
+
/**
|
|
260
|
+
* Set a response header
|
|
261
|
+
* @param name - Header name
|
|
262
|
+
* @param value - Header value
|
|
263
|
+
* @param options - Options (append: true to add multiple values)
|
|
264
|
+
*/
|
|
265
|
+
header(name: string, value: string, options?: {
|
|
266
|
+
append?: boolean;
|
|
267
|
+
}): void;
|
|
268
|
+
/**
|
|
269
|
+
* Get a request header
|
|
270
|
+
* @param name - Header name (case-insensitive)
|
|
271
|
+
*/
|
|
272
|
+
header(name: string): string | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* Set the response status code
|
|
275
|
+
* @param code - HTTP status code
|
|
276
|
+
*/
|
|
277
|
+
status(code: StatusCode): void;
|
|
278
|
+
/**
|
|
279
|
+
* Get a context variable
|
|
280
|
+
* @param key - Variable key
|
|
281
|
+
*/
|
|
282
|
+
get<K extends keyof V>(key: K): V[K];
|
|
283
|
+
/**
|
|
284
|
+
* Set a context variable
|
|
285
|
+
* @param key - Variable key
|
|
286
|
+
* @param value - Variable value
|
|
287
|
+
*/
|
|
288
|
+
set<K extends keyof V>(key: K, value: V[K]): void;
|
|
289
|
+
/**
|
|
290
|
+
* Get the execution context (for Cloudflare Workers, etc.)
|
|
291
|
+
*/
|
|
292
|
+
readonly executionCtx?: ExecutionContext;
|
|
293
|
+
/**
|
|
294
|
+
* Get environment bindings (for Cloudflare Workers, etc.)
|
|
295
|
+
*/
|
|
296
|
+
readonly env?: Record<string, unknown>;
|
|
297
|
+
/**
|
|
298
|
+
* URL generator helper.
|
|
299
|
+
* Generates a URL for a named route.
|
|
300
|
+
*/
|
|
301
|
+
route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
|
|
302
|
+
/**
|
|
303
|
+
* Access the native context object from the underlying HTTP engine.
|
|
304
|
+
*
|
|
305
|
+
* ⚠️ WARNING: Using this ties your code to a specific adapter.
|
|
306
|
+
* Prefer using the abstraction methods when possible.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* // Only when absolutely necessary
|
|
311
|
+
* const photonCtx = ctx.native as Context // Photon Context
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
readonly native: unknown;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Next function for middleware chain
|
|
318
|
+
*/
|
|
319
|
+
export type GravitoNext = () => Promise<Response | undefined>;
|
|
320
|
+
/**
|
|
321
|
+
* GravitoHandler - Standard route handler type
|
|
322
|
+
*
|
|
323
|
+
* @typeParam V - Context variables type
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const handler: GravitoHandler = async (ctx) => {
|
|
328
|
+
* return ctx.json({ message: 'Hello, World!' })
|
|
329
|
+
* }
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export type GravitoHandler<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>) => Response | Promise<Response>;
|
|
333
|
+
/**
|
|
334
|
+
* GravitoMiddleware - Standard middleware type
|
|
335
|
+
*
|
|
336
|
+
* @typeParam V - Context variables type
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const logger: GravitoMiddleware = async (ctx, next) => {
|
|
341
|
+
* console.log(`${ctx.req.method} ${ctx.req.path}`)
|
|
342
|
+
* await next()
|
|
343
|
+
* return undefined
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export type GravitoMiddleware<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>, next: GravitoNext) => Response | undefined | Promise<Response | undefined | undefined>;
|
|
348
|
+
/**
|
|
349
|
+
* Error handler type
|
|
350
|
+
*/
|
|
351
|
+
export type GravitoErrorHandler<V extends GravitoVariables = GravitoVariables> = (error: Error, ctx: GravitoContext<V>) => Response | Promise<Response>;
|
|
352
|
+
/**
|
|
353
|
+
* Not found handler type
|
|
354
|
+
*/
|
|
355
|
+
export type GravitoNotFoundHandler<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>) => Response | Promise<Response>;
|
|
@@ -0,0 +1,76 @@
|
|
|
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 { type CommandHandler, CommandKernel } from './CommandKernel';
|
|
21
|
+
export { ConfigManager } from './ConfigManager';
|
|
22
|
+
export { Container, type Factory, type ServiceKey, type ServiceMap } from './Container';
|
|
23
|
+
export { codeFromStatus, ErrorHandler, type ErrorHandlerDeps, messageFromStatus, } from './ErrorHandler';
|
|
24
|
+
export { EventManager } from './EventManager';
|
|
25
|
+
export type { CircuitBreakerOptions, DLQEntry, DLQFilter, EventBackend, EventOptions, EventTask, } from './events';
|
|
26
|
+
export { CircuitBreaker, CircuitBreakerState, DEFAULT_EVENT_OPTIONS, DeadLetterQueue, EventPriorityQueue, } from './events';
|
|
27
|
+
export type { EventTracingConfig, ObservabilityConfig, QueueDepthCallback, } from './events/observability';
|
|
28
|
+
export { EventMetrics, EventTracer, EventTracing, getEventTracing, ObservableHookManager, OTelEventMetrics, } from './events/observability';
|
|
29
|
+
export * from './exceptions';
|
|
30
|
+
export { type GlobalErrorHandlersMode, type GlobalProcessErrorHandlerContext, type GlobalProcessErrorKind, type RegisterGlobalErrorHandlersOptions, registerGlobalErrorHandlers, } from './GlobalErrorHandlers';
|
|
31
|
+
export { type GravitoManifest, GravitoServer } from './GravitoServer';
|
|
32
|
+
export type { ActionCallback, FilterCallback, ListenerInfo, ListenerOptions } from './HookManager';
|
|
33
|
+
export { HookManager, type HookManagerConfig } from './HookManager';
|
|
34
|
+
export * from './helpers';
|
|
35
|
+
export { CookieJar, type CookieOptions } from './http/CookieJar';
|
|
36
|
+
export { deleteCookie, getCookie, setCookie } from './http/cookie';
|
|
37
|
+
export { type BodySizeLimitOptions, bodySizeLimit } from './http/middleware/BodySizeLimit';
|
|
38
|
+
export { type CorsOptions, type CorsOrigin, cors } from './http/middleware/Cors';
|
|
39
|
+
export { type CsrfOptions, csrfProtection, getCsrfToken } from './http/middleware/Csrf';
|
|
40
|
+
export { createHeaderGate, type HeaderTokenGateOptions, type RequireHeaderTokenOptions, requireHeaderToken, } from './http/middleware/HeaderTokenGate';
|
|
41
|
+
export { type HstsOptions, type SecurityHeadersOptions, securityHeaders, } from './http/middleware/SecurityHeaders';
|
|
42
|
+
export { ThrottleRequests } from './http/middleware/ThrottleRequests';
|
|
43
|
+
export * as instrumentation from './instrumentation';
|
|
44
|
+
export { DEFAULT_CONFIG as OTEL_DEFAULT_CONFIG, getMeter, getOpenTelemetrySDK, getTracer as getOtelTracer, isOpenTelemetryInitialized, type MetricsConfig as OtelMetricsConfig, type MetricsExporter, type OpenTelemetryConfig, type OpenTelemetrySDK, OTEL_ENV_VARS, resetOpenTelemetry, setupOpenTelemetry, shutdownOpenTelemetry, type TracingConfig as OtelTracingConfig, type TracingExporter, } from './instrumentation';
|
|
45
|
+
export type { Listener, ShouldQueue } from './Listener';
|
|
46
|
+
export type { Logger } from './Logger';
|
|
47
|
+
export { ConsoleLogger } from './Logger';
|
|
48
|
+
export { type CacheService, type ErrorHandlerContext, type GravitoConfig, type GravitoOrbit, PlanetCore, type ViewService, } from './PlanetCore';
|
|
49
|
+
export { Route } from './Route';
|
|
50
|
+
export { type ControllerClass, FORM_REQUEST_SYMBOL, type FormRequestClass, type FormRequestLike, RouteGroup, type RouteHandler, type RouteOptions, Router, } from './Router';
|
|
51
|
+
export type { DLQManagerFilter, DLQRecord, DLQStats, RetryPolicy } from './reliability';
|
|
52
|
+
export { DeadLetterQueueManager, getDefaultRetryPolicy, getPresetRetryPolicy, RetryEngine, } from './reliability';
|
|
53
|
+
export { ServiceProvider } from './ServiceProvider';
|
|
54
|
+
export { Encrypter, type EncrypterOptions } from './security/Encrypter';
|
|
55
|
+
export type { Channel, ShouldBroadcast } from './types/events';
|
|
56
|
+
export { Event } from './types/events';
|
|
57
|
+
export * from './testing';
|
|
58
|
+
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';
|
|
59
|
+
export * as engine from './engine';
|
|
60
|
+
/**
|
|
61
|
+
* Configure your Gravito application
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const config = defineConfig({
|
|
66
|
+
* config: {
|
|
67
|
+
* APP_NAME: 'My App',
|
|
68
|
+
* PORT: 3000,
|
|
69
|
+
* },
|
|
70
|
+
* orbits: [], // Add your orbits here
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* const core = await PlanetCore.boot(config)
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function defineConfig(config: GravitoConfig): GravitoConfig;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - Instrumentation Module
|
|
3
|
+
*
|
|
4
|
+
* 提供 OpenTelemetry SDK 集成功能,包括分佈式追蹤與指標收集。
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import {
|
|
9
|
+
* setupOpenTelemetry,
|
|
10
|
+
* getOpenTelemetrySDK,
|
|
11
|
+
* getTracer,
|
|
12
|
+
* getMeter
|
|
13
|
+
* } from '@gravito/core'
|
|
14
|
+
*
|
|
15
|
+
* // 初始化 SDK
|
|
16
|
+
* await setupOpenTelemetry({
|
|
17
|
+
* serviceName: 'my-service',
|
|
18
|
+
* tracing: { enabled: true, exporter: 'jaeger' },
|
|
19
|
+
* metrics: { enabled: true, exporter: 'prometheus' }
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // 獲取 Tracer
|
|
23
|
+
* const tracer = await getTracer('my-module')
|
|
24
|
+
* const span = tracer.startSpan('my-operation')
|
|
25
|
+
*
|
|
26
|
+
* // 獲取 Meter
|
|
27
|
+
* const meter = await getMeter('my-module')
|
|
28
|
+
* const counter = meter.createCounter('request_count')
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @packageDocumentation
|
|
32
|
+
*/
|
|
33
|
+
export { getMeter, getOpenTelemetrySDK, getTracer, isOpenTelemetryInitialized, resetOpenTelemetry, setupOpenTelemetry, shutdownOpenTelemetry, } from './opentelemetry';
|
|
34
|
+
export type { MetricsConfig, MetricsExporter, OpenTelemetryConfig, OpenTelemetrySDK, TracingConfig, TracingExporter, } from './types';
|
|
35
|
+
export { DEFAULT_CONFIG, OTEL_ENV_VARS } from './types';
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gravito/core - OpenTelemetry SDK 集成
|
|
3
|
+
*
|
|
4
|
+
* 提供 OpenTelemetry 的初始化、配置與管理功能。
|
|
5
|
+
* 支援動態導入以實現可選依賴的優雅降級。
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { setupOpenTelemetry } from '@gravito/core'
|
|
10
|
+
*
|
|
11
|
+
* const sdk = await setupOpenTelemetry({
|
|
12
|
+
* serviceName: 'my-service',
|
|
13
|
+
* serviceVersion: '1.0.0',
|
|
14
|
+
* tracing: {
|
|
15
|
+
* enabled: true,
|
|
16
|
+
* exporter: 'jaeger',
|
|
17
|
+
* samplingRate: 0.1
|
|
18
|
+
* },
|
|
19
|
+
* metrics: {
|
|
20
|
+
* enabled: true,
|
|
21
|
+
* exporter: 'prometheus',
|
|
22
|
+
* prometheusPort: 9090
|
|
23
|
+
* }
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
import { type MetricsConfig, type OpenTelemetryConfig, type OpenTelemetrySDK, type TracingConfig } from './types';
|
|
30
|
+
export type { MetricsConfig, OpenTelemetryConfig, OpenTelemetrySDK, TracingConfig };
|
|
31
|
+
/**
|
|
32
|
+
* 初始化 OpenTelemetry SDK
|
|
33
|
+
*
|
|
34
|
+
* @param userConfig - 用戶配置
|
|
35
|
+
* @returns OpenTelemetry SDK 實例或 null(如果禁用或初始化失敗)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // 基本用法
|
|
40
|
+
* const sdk = await setupOpenTelemetry({
|
|
41
|
+
* serviceName: 'my-service'
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
44
|
+
* // 完整配置
|
|
45
|
+
* const sdk = await setupOpenTelemetry({
|
|
46
|
+
* serviceName: 'my-service',
|
|
47
|
+
* serviceVersion: '2.0.0',
|
|
48
|
+
* environment: 'production',
|
|
49
|
+
* tracing: {
|
|
50
|
+
* enabled: true,
|
|
51
|
+
* exporter: 'jaeger',
|
|
52
|
+
* jaegerEndpoint: 'http://jaeger:14268/api/traces',
|
|
53
|
+
* samplingRate: 0.1
|
|
54
|
+
* },
|
|
55
|
+
* metrics: {
|
|
56
|
+
* enabled: true,
|
|
57
|
+
* exporter: 'prometheus',
|
|
58
|
+
* prometheusPort: 9090
|
|
59
|
+
* }
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export declare function setupOpenTelemetry(userConfig?: OpenTelemetryConfig): Promise<OpenTelemetrySDK | null>;
|
|
66
|
+
/**
|
|
67
|
+
* 獲取全局 OpenTelemetry SDK 實例
|
|
68
|
+
*
|
|
69
|
+
* @returns SDK 實例或 null
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const sdk = getOpenTelemetrySDK()
|
|
74
|
+
* if (sdk) {
|
|
75
|
+
* console.log('Service:', sdk.serviceName)
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare function getOpenTelemetrySDK(): OpenTelemetrySDK | null;
|
|
82
|
+
/**
|
|
83
|
+
* 檢查 OpenTelemetry 是否已初始化
|
|
84
|
+
*
|
|
85
|
+
* @returns 初始化狀態
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
export declare function isOpenTelemetryInitialized(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* 關閉 OpenTelemetry SDK
|
|
92
|
+
*
|
|
93
|
+
* 應在應用程序關閉時調用,確保所有 spans 和 metrics 都被導出。
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // 在應用程序退出前
|
|
98
|
+
* process.on('SIGTERM', async () => {
|
|
99
|
+
* await shutdownOpenTelemetry()
|
|
100
|
+
* process.exit(0)
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export declare function shutdownOpenTelemetry(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* 重置 OpenTelemetry SDK(主要用於測試)
|
|
109
|
+
*
|
|
110
|
+
* 關閉現有 SDK 並重置所有狀態,允許重新初始化。
|
|
111
|
+
*
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
export declare function resetOpenTelemetry(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* 獲取 Tracer 實例
|
|
117
|
+
*
|
|
118
|
+
* @param name - Tracer 名稱(預設:@gravito/core)
|
|
119
|
+
* @param version - Tracer 版本
|
|
120
|
+
* @returns Tracer 實例
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const tracer = getTracer('my-module')
|
|
125
|
+
* const span = tracer.startSpan('my-operation')
|
|
126
|
+
* // ... 執行操作
|
|
127
|
+
* span.end()
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
export declare function getTracer(name?: string, version?: string): Promise<import("@opentelemetry/api").Tracer | {
|
|
133
|
+
startSpan: () => {
|
|
134
|
+
end: () => void;
|
|
135
|
+
setAttribute: () => void;
|
|
136
|
+
setStatus: () => void;
|
|
137
|
+
recordException: () => void;
|
|
138
|
+
addEvent: () => void;
|
|
139
|
+
isRecording: () => boolean;
|
|
140
|
+
};
|
|
141
|
+
startActiveSpan: (_name: string, fn: (span: any) => any) => any;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* 獲取 Meter 實例
|
|
145
|
+
*
|
|
146
|
+
* @param name - Meter 名稱(預設:@gravito/core)
|
|
147
|
+
* @param version - Meter 版本
|
|
148
|
+
* @returns Meter 實例
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const meter = getMeter('my-module')
|
|
153
|
+
* const counter = meter.createCounter('my_counter')
|
|
154
|
+
* counter.add(1, { key: 'value' })
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
export declare function getMeter(name?: string, version?: string): Promise<import("@opentelemetry/api").Meter | {
|
|
160
|
+
createCounter: () => {
|
|
161
|
+
add: () => void;
|
|
162
|
+
};
|
|
163
|
+
createHistogram: () => {
|
|
164
|
+
record: () => void;
|
|
165
|
+
};
|
|
166
|
+
createUpDownCounter: () => {
|
|
167
|
+
add: () => void;
|
|
168
|
+
};
|
|
169
|
+
createObservableCounter: () => {
|
|
170
|
+
addCallback: () => void;
|
|
171
|
+
};
|
|
172
|
+
createObservableGauge: () => {
|
|
173
|
+
addCallback: () => void;
|
|
174
|
+
};
|
|
175
|
+
createObservableUpDownCounter: () => {
|
|
176
|
+
addCallback: () => void;
|
|
177
|
+
};
|
|
178
|
+
}>;
|