@gravito/ripple 4.0.1 → 5.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 +26 -10
- package/dist/{ripple/src/OrbitRipple.d.ts → OrbitRipple.d.ts} +1 -0
- package/dist/{ripple/src/RippleServer.d.ts → RippleServer.d.ts} +32 -1
- package/dist/core/src/Application.d.ts +41 -0
- package/dist/core/src/HookManager.d.ts +33 -189
- package/dist/core/src/PlanetCore.d.ts +31 -1
- package/dist/core/src/Router.d.ts +32 -46
- package/dist/core/src/adapters/bun/BunContext.d.ts +6 -1
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
- package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
- package/dist/core/src/adapters/bun/index.d.ts +7 -0
- package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
- package/dist/core/src/binary/index.d.ts +5 -0
- package/dist/core/src/compat/async-local-storage.d.ts +7 -0
- package/dist/core/src/compat/crypto.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +10 -0
- package/dist/core/src/engine/FastContext.d.ts +19 -1
- package/dist/core/src/engine/Gravito.d.ts +13 -18
- package/dist/core/src/engine/MinimalContext.d.ts +2 -0
- package/dist/core/src/engine/analyzer.d.ts +92 -6
- package/dist/core/src/engine/types.d.ts +3 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +12 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +18 -256
- package/dist/core/src/events/index.d.ts +12 -11
- package/dist/core/src/events/queue-core.d.ts +77 -0
- package/dist/core/src/events/task-executor.d.ts +51 -0
- package/dist/core/src/exceptions/AuthException.d.ts +10 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +2 -2
- package/dist/core/src/exceptions/AuthorizationException.d.ts +2 -2
- package/dist/core/src/exceptions/CacheException.d.ts +9 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +2 -1
- package/dist/core/src/exceptions/ConfigurationException.d.ts +9 -0
- package/dist/core/src/exceptions/DatabaseException.d.ts +9 -0
- package/dist/core/src/exceptions/DomainException.d.ts +9 -0
- package/dist/core/src/exceptions/InfrastructureException.d.ts +17 -0
- package/dist/core/src/exceptions/QueueException.d.ts +9 -0
- package/dist/core/src/exceptions/StorageException.d.ts +9 -0
- package/dist/core/src/exceptions/StreamException.d.ts +9 -0
- package/dist/core/src/exceptions/SystemException.d.ts +9 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +2 -2
- package/dist/core/src/exceptions/index.d.ts +10 -0
- package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
- package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
- package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
- package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
- package/dist/core/src/ffi/index.d.ts +10 -0
- package/dist/core/src/ffi/types.d.ts +135 -0
- package/dist/core/src/helpers/Str.d.ts +15 -0
- package/dist/core/src/hooks/ActionManager.d.ts +132 -0
- package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
- package/dist/core/src/hooks/FilterManager.d.ts +71 -0
- package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
- package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
- package/dist/core/src/hooks/types.d.ts +107 -0
- package/dist/core/src/http/CookieJar.d.ts +2 -2
- package/dist/core/src/http/types.d.ts +24 -3
- package/dist/core/src/index.d.ts +491 -14
- package/dist/core/src/observability/contracts.d.ts +137 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +2 -3
- package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
- package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
- package/dist/core/src/runtime/adapter-node.d.ts +12 -0
- package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
- package/dist/core/src/runtime/archive.d.ts +17 -0
- package/dist/core/src/runtime/compression.d.ts +21 -0
- package/dist/core/src/runtime/deep-equals.d.ts +56 -0
- package/dist/core/src/runtime/detection.d.ts +22 -0
- package/dist/core/src/runtime/escape.d.ts +34 -0
- package/dist/core/src/runtime/index.d.ts +44 -0
- package/dist/core/src/runtime/markdown.d.ts +44 -0
- package/dist/core/src/runtime/types.d.ts +436 -0
- package/dist/core/src/runtime-helpers.d.ts +67 -0
- package/dist/core/src/runtime.d.ts +10 -118
- package/dist/core/src/testing/HttpTester.d.ts +1 -0
- package/dist/core/src/transpiler-utils.d.ts +170 -0
- package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
- package/dist/errors/RippleError.d.ts +66 -0
- package/dist/index.js +1 -7502
- package/dist/index.js.map +3 -71
- package/package.json +6 -2
- 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/adapters/PhotonAdapter.d.ts +0 -175
- package/dist/core/src/adapters/photon-types.d.ts +0 -73
- 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/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/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/ripple/src/errors/RippleError.d.ts +0 -48
- /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
- /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
- /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
- /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
- /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
- /package/dist/{ripple/src/engines → engines}/UWebSocketsEngine.d.ts +0 -0
- /package/dist/{ripple/src/engines → engines}/WsEngine.d.ts +0 -0
- /package/dist/{ripple/src/engines → engines}/index.d.ts +0 -0
- /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
- /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
- /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
- /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
- /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
- /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
- /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
- /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
- /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
- /package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +0 -0
- /package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +0 -0
- /package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +0 -0
- /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
- /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
- /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
- /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
- /package/dist/{ripple/src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
- /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
- /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @gravito/atlas - Cursor Encoding Utility
|
|
3
|
-
* @description Base64 encode/decode for cursor-based pagination cursors.
|
|
4
|
-
*
|
|
5
|
-
* Cursor format: base64(JSON({ id, sortValue, sortColumn, direction }))
|
|
6
|
-
* This enables O(1) pagination using tuple comparison SQL:
|
|
7
|
-
* WHERE (sort_col, id) > (val, id_val)
|
|
8
|
-
*/
|
|
9
|
-
export interface CursorPayload {
|
|
10
|
-
/**
|
|
11
|
-
* Primary key value of the last/first record in the current page
|
|
12
|
-
*/
|
|
13
|
-
id: unknown;
|
|
14
|
-
/**
|
|
15
|
-
* Value of the sort column at the cursor boundary
|
|
16
|
-
*/
|
|
17
|
-
sortValue: unknown;
|
|
18
|
-
/**
|
|
19
|
-
* Column name used for sorting
|
|
20
|
-
*/
|
|
21
|
-
sortColumn: string;
|
|
22
|
-
/**
|
|
23
|
-
* Sort direction
|
|
24
|
-
*/
|
|
25
|
-
direction: 'asc' | 'desc';
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Encode a cursor payload to an opaque base64 string.
|
|
29
|
-
*
|
|
30
|
-
* @param payload - Cursor data to encode
|
|
31
|
-
* @returns Base64-encoded cursor string
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* const cursor = encodeCursor({ id: 42, sortValue: '2026-01-01', sortColumn: 'created_at', direction: 'asc' })
|
|
35
|
-
*/
|
|
36
|
-
export declare function encodeCursor(payload: CursorPayload): string;
|
|
37
|
-
/**
|
|
38
|
-
* Decode a cursor string back to its payload.
|
|
39
|
-
*
|
|
40
|
-
* @param cursor - Base64 cursor string
|
|
41
|
-
* @returns Decoded cursor payload
|
|
42
|
-
* @throws {Error} If the cursor is malformed or tampered with
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* const payload = decodeCursor(cursor)
|
|
46
|
-
* // payload.id, payload.sortValue, etc.
|
|
47
|
-
*/
|
|
48
|
-
export declare function decodeCursor(cursor: string): CursorPayload;
|
|
49
|
-
/**
|
|
50
|
-
* Build the WHERE clause raw SQL and bindings for cursor pagination.
|
|
51
|
-
*
|
|
52
|
-
* For ascending sort: WHERE (sort_col, id) > (sort_val, id_val)
|
|
53
|
-
* For descending sort: WHERE (sort_col, id) < (sort_val, id_val)
|
|
54
|
-
*
|
|
55
|
-
* Uses tuple comparison which is O(1) on indexed columns in Postgres & MySQL.
|
|
56
|
-
*
|
|
57
|
-
* @param payload - Decoded cursor payload
|
|
58
|
-
* @returns { sql, bindings } ready for whereRaw()
|
|
59
|
-
*/
|
|
60
|
-
export declare function buildCursorWhereClause(payload: CursorPayload, idColumn?: string): {
|
|
61
|
-
sql: string;
|
|
62
|
-
bindings: unknown[];
|
|
63
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculate Levenshtein distance between two strings
|
|
3
|
-
* Used for "Did you mean?" suggestions
|
|
4
|
-
*/
|
|
5
|
-
export declare function levenshtein(a: string, b: string): number;
|
|
6
|
-
/**
|
|
7
|
-
* Find similar strings from a list
|
|
8
|
-
*/
|
|
9
|
-
export declare function findSimilar(target: string, candidates: string[], maxDistance?: number, maxResults?: number): string[];
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Photon Adapter Implementation
|
|
3
|
-
*
|
|
4
|
-
* This adapter wraps Photon to implement the Gravito HttpAdapter interface.
|
|
5
|
-
* It serves as the default adapter and reference implementation for others.
|
|
6
|
-
*
|
|
7
|
-
* @module @gravito/core/adapters/photon
|
|
8
|
-
* @since 2.0.0
|
|
9
|
-
*/
|
|
10
|
-
import type { Context, Handler, MiddlewareHandler, Photon } from '@gravito/photon';
|
|
11
|
-
import { RequestScopeManager } from '../Container/RequestScopeManager';
|
|
12
|
-
import type { GravitoContext, GravitoErrorHandler, GravitoHandler, GravitoMiddleware, GravitoNotFoundHandler, GravitoRequest, GravitoVariables, HttpMethod, ProxyOptions, StatusCode } from '../http/types';
|
|
13
|
-
import type { AdapterConfig, HttpAdapter, RouteDefinition } from './types';
|
|
14
|
-
/**
|
|
15
|
-
* Wraps Photon's request object to implement GravitoRequest
|
|
16
|
-
*/
|
|
17
|
-
declare class PhotonRequestWrapper implements GravitoRequest {
|
|
18
|
-
photonCtx: Context;
|
|
19
|
-
/**
|
|
20
|
-
* Reset the wrapper for pooling
|
|
21
|
-
*/
|
|
22
|
-
reset(photonCtx: Context): void;
|
|
23
|
-
/**
|
|
24
|
-
* Create a proxied instance to delegate to Photon's request
|
|
25
|
-
*/
|
|
26
|
-
static create(photonCtx: Context): PhotonRequestWrapper;
|
|
27
|
-
/**
|
|
28
|
-
* Internal proxy wrapper
|
|
29
|
-
*/
|
|
30
|
-
static wrap(instance: PhotonRequestWrapper): PhotonRequestWrapper;
|
|
31
|
-
get url(): string;
|
|
32
|
-
get method(): string;
|
|
33
|
-
get path(): string;
|
|
34
|
-
param(name: string): string | undefined;
|
|
35
|
-
params(): Record<string, string>;
|
|
36
|
-
query(name: string): string | undefined;
|
|
37
|
-
queries(): Record<string, string | string[]>;
|
|
38
|
-
header(name: string): string | undefined;
|
|
39
|
-
header(): Record<string, string>;
|
|
40
|
-
json<T = unknown>(): Promise<T>;
|
|
41
|
-
text(): Promise<string>;
|
|
42
|
-
formData(): Promise<FormData>;
|
|
43
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
44
|
-
parseBody<T = unknown>(): Promise<T>;
|
|
45
|
-
get raw(): Request;
|
|
46
|
-
valid<T = unknown>(target: string): T;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Wraps Photon's context to implement GravitoContext
|
|
50
|
-
*/
|
|
51
|
-
declare class PhotonContextWrapper<V extends GravitoVariables = GravitoVariables> implements GravitoContext<V> {
|
|
52
|
-
private _req;
|
|
53
|
-
private photonCtx;
|
|
54
|
-
private _requestScope;
|
|
55
|
-
route: (name: string, params?: Record<string, any>, query?: Record<string, any>) => string;
|
|
56
|
-
/**
|
|
57
|
-
* Reset the wrapper for pooling
|
|
58
|
-
*/
|
|
59
|
-
reset(photonCtx: Context): void;
|
|
60
|
-
/**
|
|
61
|
-
* Create a proxied instance to enable object destructuring of context variables
|
|
62
|
-
*/
|
|
63
|
-
static create<V extends GravitoVariables = GravitoVariables>(photonCtx: Context): GravitoContext<V>;
|
|
64
|
-
/**
|
|
65
|
-
* Internal proxy wrapper
|
|
66
|
-
*/
|
|
67
|
-
static wrap<V extends GravitoVariables = GravitoVariables>(instance: PhotonContextWrapper<V>): GravitoContext<V>;
|
|
68
|
-
get req(): GravitoRequest;
|
|
69
|
-
get params(): Record<string, string>;
|
|
70
|
-
get query(): Record<string, string | string[]>;
|
|
71
|
-
get data(): unknown;
|
|
72
|
-
set data(value: unknown);
|
|
73
|
-
back(status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
74
|
-
json<T>(data: T, status?: number): Response;
|
|
75
|
-
text(text: string, status?: number): Response;
|
|
76
|
-
html(html: string, status?: number): Response;
|
|
77
|
-
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
78
|
-
body(data: BodyInit | null, status?: number): Response;
|
|
79
|
-
stream(stream: ReadableStream, status?: number): Response;
|
|
80
|
-
notFound(message?: string): Response;
|
|
81
|
-
forbidden(message?: string): Response;
|
|
82
|
-
unauthorized(message?: string): Response;
|
|
83
|
-
badRequest(message?: string): Response;
|
|
84
|
-
header(name: string): string | undefined;
|
|
85
|
-
header(name: string, value: string, options?: {
|
|
86
|
-
append?: boolean;
|
|
87
|
-
}): void;
|
|
88
|
-
status(code: StatusCode): void;
|
|
89
|
-
get<K extends keyof V>(key: K): V[K];
|
|
90
|
-
set<K extends keyof V>(key: K, value: V[K]): void;
|
|
91
|
-
get executionCtx(): ExecutionContext | undefined;
|
|
92
|
-
get env(): Record<string, unknown> | undefined;
|
|
93
|
-
get native(): Context;
|
|
94
|
-
forward(target: string, options?: ProxyOptions): Promise<Response>;
|
|
95
|
-
requestScope(): RequestScopeManager;
|
|
96
|
-
scoped<T>(key: string | symbol, factory: () => T): T;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Convert a GravitoHandler to a Photon Handler
|
|
100
|
-
*/
|
|
101
|
-
declare function toPhotonHandler<V extends GravitoVariables>(handler: GravitoHandler<V>): Handler;
|
|
102
|
-
/**
|
|
103
|
-
* Convert a GravitoMiddleware to a Photon MiddlewareHandler
|
|
104
|
-
*/
|
|
105
|
-
declare function toPhotonMiddleware<V extends GravitoVariables>(middleware: GravitoMiddleware<V>): MiddlewareHandler;
|
|
106
|
-
/**
|
|
107
|
-
* Default HTTP adapter using the optimized Gravito Core Engine.
|
|
108
|
-
*
|
|
109
|
-
* This adapter provides a consistent interface that can be
|
|
110
|
-
* swapped out for other implementations without changing application code.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* import { GravitoAdapter } from '@gravito/core'
|
|
115
|
-
*
|
|
116
|
-
* const adapter = new GravitoAdapter()
|
|
117
|
-
*
|
|
118
|
-
* // Register routes
|
|
119
|
-
* adapter.route('get', '/hello', async (ctx) => {
|
|
120
|
-
* return ctx.json({ message: 'Hello, World!' })
|
|
121
|
-
* })
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
export declare class PhotonAdapter<V extends GravitoVariables = GravitoVariables> implements HttpAdapter<V> {
|
|
125
|
-
private config;
|
|
126
|
-
readonly name = "photon";
|
|
127
|
-
readonly version = "1.0.0";
|
|
128
|
-
private app;
|
|
129
|
-
constructor(config?: AdapterConfig, photonInstance?: unknown);
|
|
130
|
-
/**
|
|
131
|
-
* Get the underlying Photon app instance
|
|
132
|
-
*/
|
|
133
|
-
get native(): Photon;
|
|
134
|
-
/**
|
|
135
|
-
* Set the underlying Photon app instance
|
|
136
|
-
* Used by PlanetCore during initialization
|
|
137
|
-
*/
|
|
138
|
-
setNative(app: Photon): void;
|
|
139
|
-
route(method: HttpMethod, path: string, ...handlers: (GravitoHandler<V> | GravitoMiddleware<V>)[]): void;
|
|
140
|
-
routes(routes: RouteDefinition[]): void;
|
|
141
|
-
use(path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
142
|
-
useGlobal(...middleware: GravitoMiddleware<V>[]): void;
|
|
143
|
-
useScoped(scope: string, path: string, ...middleware: GravitoMiddleware<V>[]): void;
|
|
144
|
-
mount(path: string, subAdapter: HttpAdapter<V>): void;
|
|
145
|
-
onError(handler: GravitoErrorHandler<V>): void;
|
|
146
|
-
onNotFound(handler: GravitoNotFoundHandler<V>): void;
|
|
147
|
-
/**
|
|
148
|
-
* Predictive Route Warming (JIT Optimization)
|
|
149
|
-
*/
|
|
150
|
-
warmup(paths: string[]): Promise<void>;
|
|
151
|
-
fetch: (request: Request, server?: unknown) => Response | Promise<Response>;
|
|
152
|
-
createContext(_request: Request): GravitoContext<V>;
|
|
153
|
-
init(): Promise<void>;
|
|
154
|
-
shutdown(): Promise<void>;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Create a new PhotonAdapter instance
|
|
158
|
-
*/
|
|
159
|
-
export declare function createPhotonAdapter<V extends GravitoVariables = GravitoVariables>(config?: AdapterConfig): PhotonAdapter<V>;
|
|
160
|
-
export { PhotonContextWrapper, PhotonRequestWrapper, toPhotonHandler, toPhotonMiddleware };
|
|
161
|
-
/**
|
|
162
|
-
* Rebranded alias for PhotonAdapter.
|
|
163
|
-
* @category Rebranding
|
|
164
|
-
*/
|
|
165
|
-
export declare const GravitoAdapter: typeof PhotonAdapter;
|
|
166
|
-
/**
|
|
167
|
-
* Rebranded alias for PhotonAdapter type.
|
|
168
|
-
* @category Rebranding
|
|
169
|
-
*/
|
|
170
|
-
export type GravitoAdapter<V extends GravitoVariables = GravitoVariables> = PhotonAdapter<V>;
|
|
171
|
-
/**
|
|
172
|
-
* Rebranded alias for createPhotonAdapter.
|
|
173
|
-
* @category Rebranding
|
|
174
|
-
*/
|
|
175
|
-
export declare const createGravitoAdapter: typeof createPhotonAdapter;
|
|
@@ -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,16 +0,0 @@
|
|
|
1
|
-
import type { GravitoMiddleware } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Options for body size limiting
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export type BodySizeLimitOptions = {
|
|
7
|
-
methods?: string[];
|
|
8
|
-
requireContentLength?: boolean;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Middleware to limit request body size.
|
|
12
|
-
* @param maxBytes - Maximum allowed size in bytes
|
|
13
|
-
* @param options - Configuration options
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export declare function bodySizeLimit(maxBytes: number, options?: BodySizeLimitOptions): GravitoMiddleware;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { GravitoMiddleware } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Allowed origin(s) configuration.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export type CorsOrigin = string | string[] | ((origin: string | undefined) => string | false);
|
|
7
|
-
/**
|
|
8
|
-
* Options for CORS middleware
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export type CorsOptions = {
|
|
12
|
-
origin?: CorsOrigin;
|
|
13
|
-
methods?: string[];
|
|
14
|
-
allowedHeaders?: string[];
|
|
15
|
-
exposedHeaders?: string[];
|
|
16
|
-
credentials?: boolean;
|
|
17
|
-
maxAge?: number;
|
|
18
|
-
optionsSuccessStatus?: number;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Middleware handling Cross-Origin Resource Sharing (CORS).
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export declare function cors(options?: CorsOptions): GravitoMiddleware;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type CookieOptions } from '../CookieJar';
|
|
2
|
-
import type { GravitoContext, GravitoMiddleware } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for CSRF Protection
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export type CsrfOptions = {
|
|
8
|
-
cookieName?: string;
|
|
9
|
-
headerName?: string;
|
|
10
|
-
formFieldName?: string;
|
|
11
|
-
cookie?: CookieOptions;
|
|
12
|
-
safeMethods?: string[];
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Generate (or retrieve existing) CSRF token for the session.
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
export declare function getCsrfToken(c: GravitoContext, options?: CsrfOptions): string;
|
|
19
|
-
/**
|
|
20
|
-
* Middleware that validates CSRF tokens on unsafe requests.
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
export declare function csrfProtection(options?: CsrfOptions): GravitoMiddleware;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { GravitoContext, GravitoMiddleware } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Options for header token gate
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export type HeaderTokenGateOptions = {
|
|
7
|
-
headerName?: string;
|
|
8
|
-
token?: string | ((c: GravitoContext) => string | undefined);
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Options for requireHeaderToken middleware
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export type RequireHeaderTokenOptions = HeaderTokenGateOptions & {
|
|
15
|
-
status?: number;
|
|
16
|
-
message?: string;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Create a simple gate function to check a header token.
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
export declare function createHeaderGate(options?: HeaderTokenGateOptions): (c: GravitoContext) => Promise<boolean>;
|
|
23
|
-
/**
|
|
24
|
-
* Middleware that enforces a specific token in request headers.
|
|
25
|
-
* Useful for internal API authentication.
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export declare function requireHeaderToken(options?: RequireHeaderTokenOptions): GravitoMiddleware;
|
|
@@ -1,29 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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';
|
|
@@ -1,178 +0,0 @@
|
|
|
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
|
-
}>;
|