@gravito/ripple 4.0.0 → 4.0.3
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 -2
- package/dist/core/src/Application.d.ts +41 -0
- package/dist/core/src/ConfigManager.d.ts +39 -0
- package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/core/src/Container.d.ts +45 -0
- package/dist/core/src/ErrorHandler.d.ts +3 -0
- package/dist/core/src/HookManager.d.ts +104 -165
- package/dist/core/src/PlanetCore.d.ts +114 -1
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/Router.d.ts +32 -46
- package/dist/core/src/ServiceProvider.d.ts +22 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +10 -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/cli/queue-commands.d.ts +6 -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 +16 -1
- package/dist/core/src/engine/FastContext.d.ts +42 -1
- package/dist/core/src/engine/Gravito.d.ts +13 -19
- package/dist/core/src/engine/MinimalContext.d.ts +23 -0
- package/dist/core/src/engine/analyzer.d.ts +92 -6
- package/dist/core/src/engine/types.d.ts +6 -0
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/core/src/events/BackpressureManager.d.ts +215 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
- package/dist/core/src/events/EventBackend.d.ts +2 -1
- package/dist/core/src/events/EventOptions.d.ts +99 -4
- package/dist/core/src/events/EventPriorityQueue.d.ts +36 -175
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
- package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
- package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/core/src/events/RetryScheduler.d.ts +104 -0
- package/dist/core/src/events/WorkerPool.d.ts +98 -0
- package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/core/src/events/aggregation/types.d.ts +117 -0
- package/dist/core/src/events/index.d.ts +18 -6
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +4 -0
- 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/events/types.d.ts +59 -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/health/HealthProvider.d.ts +67 -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 +43 -3
- package/dist/core/src/index.d.ts +504 -15
- package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
- package/dist/core/src/observability/contracts.d.ts +137 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +36 -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/engines/UWebSocketsEngine.d.ts +97 -0
- package/dist/engines/WsEngine.d.ts +69 -0
- package/dist/{ripple/src/engines → engines}/index.d.ts +4 -0
- package/dist/index.js +1 -7139
- package/dist/index.js.map +3 -69
- package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +1 -1
- package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +1 -1
- package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +6 -3
- package/dist/{ripple/src/types.d.ts → types.d.ts} +11 -0
- package/package.json +7 -2
- package/dist/atlas/src/DB.d.ts +0 -301
- 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 -48
- package/dist/atlas/src/connection/Connection.d.ts +0 -108
- package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -111
- 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 -66
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -83
- 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 -67
- 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 -11
- 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/index.d.ts +0 -5
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
- package/dist/atlas/src/orm/model/Model.d.ts +0 -449
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -136
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -87
- 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 -109
- 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 -123
- 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/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 -573
- 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/Schema.d.ts +0 -131
- 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/types/index.d.ts +0 -1100
- package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
- package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -171
- 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/photon/src/index.d.ts +0 -84
- 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.d.ts +0 -157
- package/dist/photon/src/openapi.d.ts +0 -19
- /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/errors → errors}/RippleError.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}/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/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,4 +1,5 @@
|
|
|
1
1
|
import type { ActionCallback } from '../HookManager';
|
|
2
|
+
import type { BackpressureConfig } from './BackpressureManager';
|
|
2
3
|
import type { EventOptions } from './EventOptions';
|
|
3
4
|
/**
|
|
4
5
|
* Event task for priority queue processing.
|
|
@@ -29,6 +30,12 @@ export interface EventTask {
|
|
|
29
30
|
* Timestamp when the event was created.
|
|
30
31
|
*/
|
|
31
32
|
createdAt: number;
|
|
33
|
+
/**
|
|
34
|
+
* Timestamp when the event was enqueued (added to the queue).
|
|
35
|
+
* Used for priority escalation calculations.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
enqueuedAt: number;
|
|
32
39
|
/**
|
|
33
40
|
* Partition key for ordering (if applicable).
|
|
34
41
|
*/
|
|
@@ -72,4 +79,56 @@ export interface EventQueueConfig {
|
|
|
72
79
|
* @default 'reject'
|
|
73
80
|
*/
|
|
74
81
|
strategy?: BackpressureStrategy;
|
|
82
|
+
/**
|
|
83
|
+
* Advanced backpressure management configuration.
|
|
84
|
+
* When enabled, provides state-based flow control with multi-strategy support.
|
|
85
|
+
* If not provided, falls back to simple strategy-based backpressure.
|
|
86
|
+
* @default undefined (disabled, uses simple strategy)
|
|
87
|
+
*/
|
|
88
|
+
backpressure?: BackpressureConfig;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Multi-priority queue depth snapshot (FS-103)
|
|
92
|
+
* Represents the current queue depth for each priority level.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
export interface MultiPriorityQueueDepth {
|
|
96
|
+
/** Queue depth for CRITICAL priority events */
|
|
97
|
+
critical: number;
|
|
98
|
+
/** Queue depth for HIGH priority events */
|
|
99
|
+
high: number;
|
|
100
|
+
/** Queue depth for NORMAL priority events */
|
|
101
|
+
normal: number;
|
|
102
|
+
/** Queue depth for LOW priority events */
|
|
103
|
+
low: number;
|
|
104
|
+
/** Total queue depth across all priorities */
|
|
105
|
+
total: number;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Window adjustment record for backpressure feedback (FS-103)
|
|
109
|
+
* Records when and why the aggregation window was adjusted.
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export interface WindowAdjustment {
|
|
113
|
+
/** Timestamp of the adjustment */
|
|
114
|
+
timestamp: number;
|
|
115
|
+
/** Previous window size in milliseconds */
|
|
116
|
+
from: number;
|
|
117
|
+
/** New window size in milliseconds */
|
|
118
|
+
to: number;
|
|
119
|
+
/** Backpressure state that triggered the adjustment */
|
|
120
|
+
reason: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Dead letter queue routing decision (FS-103)
|
|
124
|
+
* Determines whether an event should be routed to the DLQ.
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
export interface DeadLetterDecision {
|
|
128
|
+
/** Whether the event should be routed to DLQ */
|
|
129
|
+
shouldRoute: boolean;
|
|
130
|
+
/** Reason for the decision (if applicable) */
|
|
131
|
+
reason?: string;
|
|
132
|
+
/** Suggested retry strategy */
|
|
133
|
+
retryStrategy?: 'immediate' | 'delayed' | 'dlq-only';
|
|
75
134
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 原生加速器統一入口
|
|
3
|
+
* 遵循 Galaxy Architecture 的運行時自適應模式
|
|
4
|
+
* 與 RuntimeAdapter 模式保持一致
|
|
5
|
+
*
|
|
6
|
+
* 📍 FFI 暫時禁用
|
|
7
|
+
* Bun 的構建系統在生成 ffi/index.js 時會產生 CJS compatibility helpers,
|
|
8
|
+
* 這些 helpers 與 ESM export 語句導致模組解析失敗。
|
|
9
|
+
* 即使使用 ESM import 也無法避免此問題(Bun 內部機制)。
|
|
10
|
+
*
|
|
11
|
+
* 解決方案:禁用 FFI,使用 JavaScript fallback(性能影響極小)
|
|
12
|
+
* TODO: 當 Bun 改進其 ESM 模組構建時重新啟用
|
|
13
|
+
*/
|
|
14
|
+
import type { CborAccelerator, NativeAcceleratorStatus } from './types';
|
|
15
|
+
/**
|
|
16
|
+
* 原生加速器類別
|
|
17
|
+
* 提供運行時自適應的 CBOR 編碼/解碼加速
|
|
18
|
+
* - 在 Bun 環境下優先使用 C 編譯器實現(bun:ffi)
|
|
19
|
+
* - 在非 Bun 環境或 FFI 不可用時自動降級到 JavaScript 實現
|
|
20
|
+
*/
|
|
21
|
+
export declare class NativeAccelerator {
|
|
22
|
+
private static readonly DEBUG_ENV;
|
|
23
|
+
/**
|
|
24
|
+
* FFI 可用性緩存
|
|
25
|
+
* null: 未檢測, true: 可用, false: 不可用
|
|
26
|
+
*/
|
|
27
|
+
private static available;
|
|
28
|
+
/**
|
|
29
|
+
* 當前加速器實例緩存
|
|
30
|
+
*/
|
|
31
|
+
private static cborAccelerator;
|
|
32
|
+
/**
|
|
33
|
+
* 當前狀態
|
|
34
|
+
*/
|
|
35
|
+
private static status;
|
|
36
|
+
/**
|
|
37
|
+
* 檢測原生 FFI 是否可用
|
|
38
|
+
* ⚠️ 當前全部返回 false(FFI 已禁用)
|
|
39
|
+
*/
|
|
40
|
+
static isAvailable(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 取得 CBOR 加速器實例
|
|
43
|
+
* 優先使用 Native,失敗則降級到 Fallback
|
|
44
|
+
*/
|
|
45
|
+
static getCborAccelerator(): CborAccelerator;
|
|
46
|
+
/**
|
|
47
|
+
* 取得加速器狀態
|
|
48
|
+
*/
|
|
49
|
+
static getStatus(): NativeAcceleratorStatus;
|
|
50
|
+
/**
|
|
51
|
+
* 重置加速器狀態(用於測試)
|
|
52
|
+
*/
|
|
53
|
+
static reset(): void;
|
|
54
|
+
/**
|
|
55
|
+
* 檢查是否啟用調試模式
|
|
56
|
+
*/
|
|
57
|
+
private static isDebugEnabled;
|
|
58
|
+
/**
|
|
59
|
+
* 更新狀態
|
|
60
|
+
*/
|
|
61
|
+
private static updateStatus;
|
|
62
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 原生雜湊加速器
|
|
3
|
+
* 運行時自適應實現,遵循 Galaxy Architecture 的設計模式
|
|
4
|
+
*
|
|
5
|
+
* 架構:
|
|
6
|
+
* - 在 Bun 環境:使用 Bun.CryptoHasher(C 實現,高效)
|
|
7
|
+
* - 其他環境:自動降級到 node:crypto
|
|
8
|
+
* - 完全相同的 API 和結果保證
|
|
9
|
+
*
|
|
10
|
+
* 性能:
|
|
11
|
+
* - Bun 環境:2-3x 快於 node:crypto(消除 N-API 開銷)
|
|
12
|
+
* - 跨運行時:完全相容性
|
|
13
|
+
*
|
|
14
|
+
* 應用場景:
|
|
15
|
+
* - FileStore.hashKey() 熱路徑
|
|
16
|
+
* - Encrypter.hash() 加密雜湊
|
|
17
|
+
* - 任何需要高效雜湊計算的地方
|
|
18
|
+
*/
|
|
19
|
+
import type { NativeHasherStatus } from './types';
|
|
20
|
+
/**
|
|
21
|
+
* 原生雜湊加速器統一入口
|
|
22
|
+
* 提供運行時自適應的 SHA-256/HMAC-SHA256 計算
|
|
23
|
+
*
|
|
24
|
+
* 使用範例:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // SHA-256
|
|
27
|
+
* const hash = NativeHasher.sha256('data')
|
|
28
|
+
*
|
|
29
|
+
* // HMAC-SHA256
|
|
30
|
+
* const hmac = NativeHasher.hmacSha256('secret', 'message')
|
|
31
|
+
*
|
|
32
|
+
* // 檢查狀態
|
|
33
|
+
* const status = NativeHasher.getStatus()
|
|
34
|
+
* console.log(`使用: ${status.runtime}`)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class NativeHasher {
|
|
38
|
+
/**
|
|
39
|
+
* 當前加速器實例緩存
|
|
40
|
+
*/
|
|
41
|
+
private static accelerator;
|
|
42
|
+
/**
|
|
43
|
+
* 當前狀態緩存
|
|
44
|
+
*/
|
|
45
|
+
private static status;
|
|
46
|
+
/**
|
|
47
|
+
* 取得雜湊加速器實例
|
|
48
|
+
* 優先使用 Bun.CryptoHasher,失敗則降級到 node:crypto
|
|
49
|
+
*
|
|
50
|
+
* @returns 雜湊加速器實例
|
|
51
|
+
*/
|
|
52
|
+
private static getAccelerator;
|
|
53
|
+
/**
|
|
54
|
+
* 檢測 Bun 運行時和 CryptoHasher 可用性
|
|
55
|
+
*
|
|
56
|
+
* @returns Bun.CryptoHasher 是否可用
|
|
57
|
+
*/
|
|
58
|
+
private static isBunAvailable;
|
|
59
|
+
/**
|
|
60
|
+
* 更新狀態
|
|
61
|
+
*
|
|
62
|
+
* @param runtime - 當前使用的運行時
|
|
63
|
+
*/
|
|
64
|
+
private static updateStatus;
|
|
65
|
+
/**
|
|
66
|
+
* 計算 SHA-256 雜湊
|
|
67
|
+
* 支援字串和二進制輸入
|
|
68
|
+
*
|
|
69
|
+
* @param input - 要雜湊的數據(字串或 Uint8Array)
|
|
70
|
+
* @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const hash = NativeHasher.sha256('hello')
|
|
75
|
+
* // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
|
|
76
|
+
*
|
|
77
|
+
* // 支援 Uint8Array
|
|
78
|
+
* const bytes = new TextEncoder().encode('hello')
|
|
79
|
+
* const hash2 = NativeHasher.sha256(bytes)
|
|
80
|
+
* // 相同結果
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
static sha256(input: string | Uint8Array): string;
|
|
84
|
+
/**
|
|
85
|
+
* 計算 HMAC-SHA256
|
|
86
|
+
* 用於認證消息完整性
|
|
87
|
+
*
|
|
88
|
+
* @param key - HMAC 密鑰
|
|
89
|
+
* @param data - 要雜湊的數據
|
|
90
|
+
* @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const hmac = NativeHasher.hmacSha256('secret', 'message')
|
|
95
|
+
* // '8b1a9953c4611296aed9e132b8502cf413b1b881fed3e8d26ab'...
|
|
96
|
+
*
|
|
97
|
+
* // 適用於加密驗證
|
|
98
|
+
* const iv = Buffer.from('...').toString('base64')
|
|
99
|
+
* const encrypted = '...'
|
|
100
|
+
* const mac = NativeHasher.hmacSha256(key, iv + encrypted)
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
static hmacSha256(key: string, data: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* 取得加速器狀態
|
|
106
|
+
* 用於診斷和性能監測
|
|
107
|
+
*
|
|
108
|
+
* @returns 加速器狀態報告
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const status = NativeHasher.getStatus()
|
|
113
|
+
* console.log(`可用: ${status.available}`)
|
|
114
|
+
* console.log(`運行時: ${status.runtime}`)
|
|
115
|
+
*
|
|
116
|
+
* // 條件邏輯
|
|
117
|
+
* if (status.runtime === 'bun-crypto-hasher') {
|
|
118
|
+
* console.log('使用 Bun 原生實現(高效)')
|
|
119
|
+
* } else {
|
|
120
|
+
* console.log('使用 node:crypto(相容性回退)')
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
static getStatus(): NativeHasherStatus;
|
|
125
|
+
/**
|
|
126
|
+
* 重置加速器狀態
|
|
127
|
+
* 主要用於測試目的,允許重新初始化運行時檢測
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // 測試中
|
|
133
|
+
* NativeHasher.reset()
|
|
134
|
+
* // 下一次呼叫會重新偵測運行時
|
|
135
|
+
* const status = NativeHasher.getStatus()
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
static reset(): void;
|
|
139
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript CBOR 回退實現
|
|
3
|
+
* 用於非 Bun 環境或 FFI 不可用的情況
|
|
4
|
+
* 符合 RFC 7049 規範
|
|
5
|
+
*/
|
|
6
|
+
import type { CborAccelerator } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* CBOR 編碼器
|
|
9
|
+
* 將 JavaScript 物件編碼為 CBOR 二進制格式
|
|
10
|
+
*/
|
|
11
|
+
export declare class CborFallbackEncoder implements CborAccelerator {
|
|
12
|
+
private static readonly DEFAULT_BUFFER_SIZE;
|
|
13
|
+
private static readonly MAX_DEPTH;
|
|
14
|
+
private static readonly MAX_BUFFER_SIZE;
|
|
15
|
+
private buffer;
|
|
16
|
+
private offset;
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* 編碼 JavaScript 物件為 CBOR 格式
|
|
20
|
+
*/
|
|
21
|
+
encode(data: Record<string, unknown>): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* 解碼 CBOR 二進制為 JavaScript 物件
|
|
24
|
+
*/
|
|
25
|
+
decode(bytes: Uint8Array): Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* 確保 buffer 有足夠空間
|
|
28
|
+
*/
|
|
29
|
+
private ensureCapacity;
|
|
30
|
+
/**
|
|
31
|
+
* 編寫一個位元組
|
|
32
|
+
*/
|
|
33
|
+
private writeByte;
|
|
34
|
+
/**
|
|
35
|
+
* 編寫多個位元組
|
|
36
|
+
*/
|
|
37
|
+
private writeBytes;
|
|
38
|
+
/**
|
|
39
|
+
* 編寫 CBOR 長度(Major Type + Additional Info)
|
|
40
|
+
*/
|
|
41
|
+
private writeLength;
|
|
42
|
+
/**
|
|
43
|
+
* 遞迴編碼值
|
|
44
|
+
*/
|
|
45
|
+
private encodeValue;
|
|
46
|
+
/**
|
|
47
|
+
* 編碼整數或浮點數
|
|
48
|
+
* 對於超過 uint32 範圍的整數,使用 float64 編碼(JavaScript 精度限制)
|
|
49
|
+
*/
|
|
50
|
+
private encodeNumber;
|
|
51
|
+
/**
|
|
52
|
+
* 編碼字串
|
|
53
|
+
*/
|
|
54
|
+
private encodeString;
|
|
55
|
+
/**
|
|
56
|
+
* 編碼位元組陣列
|
|
57
|
+
*/
|
|
58
|
+
private encodeBytes;
|
|
59
|
+
/**
|
|
60
|
+
* 編碼陣列
|
|
61
|
+
*/
|
|
62
|
+
private encodeArray;
|
|
63
|
+
/**
|
|
64
|
+
* 編碼物件(Map)
|
|
65
|
+
*/
|
|
66
|
+
private encodeMap;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* CBOR 解碼器
|
|
70
|
+
*/
|
|
71
|
+
export declare class CborFallbackDecoder {
|
|
72
|
+
private static readonly MAX_DEPTH;
|
|
73
|
+
private data;
|
|
74
|
+
private offset;
|
|
75
|
+
constructor(data: Uint8Array);
|
|
76
|
+
/**
|
|
77
|
+
* 解碼 CBOR 資料
|
|
78
|
+
*/
|
|
79
|
+
decode(): unknown;
|
|
80
|
+
/**
|
|
81
|
+
* 讀取一個位元組
|
|
82
|
+
*/
|
|
83
|
+
private readByte;
|
|
84
|
+
/**
|
|
85
|
+
* 讀取固定長度的位元組
|
|
86
|
+
*/
|
|
87
|
+
private readBytes;
|
|
88
|
+
/**
|
|
89
|
+
* 讀取 CBOR 長度
|
|
90
|
+
*/
|
|
91
|
+
private readLength;
|
|
92
|
+
/**
|
|
93
|
+
* 遞迴解碼值
|
|
94
|
+
*/
|
|
95
|
+
private decodeValue;
|
|
96
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 雜湊加速器 JavaScript 回退實現
|
|
3
|
+
* 基於 node:crypto 標準庫
|
|
4
|
+
*
|
|
5
|
+
* 使用場景:
|
|
6
|
+
* - 非 Bun 環境(Node.js、Deno 等)
|
|
7
|
+
* - Bun CryptoHasher 不可用的情況
|
|
8
|
+
*
|
|
9
|
+
* 性能特性:
|
|
10
|
+
* - 短 key (<100 bytes):~1-2x 慢於 Bun.CryptoHasher(N-API 橋接開銷)
|
|
11
|
+
* - 長 payload:差異較小(主要計算時間)
|
|
12
|
+
* - 一致性:與 node:crypto 標準行為完全相同
|
|
13
|
+
*/
|
|
14
|
+
import type { HashAccelerator } from './types';
|
|
15
|
+
/**
|
|
16
|
+
* Node.js crypto 回退實現
|
|
17
|
+
* 適用於非 Bun 環境
|
|
18
|
+
*/
|
|
19
|
+
export declare class HashFallback implements HashAccelerator {
|
|
20
|
+
/**
|
|
21
|
+
* SHA-256 計算(回退實現)
|
|
22
|
+
* @param input - 輸入(字串或 Uint8Array)
|
|
23
|
+
* @returns 十六進制編碼的 SHA-256 雜湊值
|
|
24
|
+
*/
|
|
25
|
+
sha256(input: string | Uint8Array): string;
|
|
26
|
+
/**
|
|
27
|
+
* HMAC-SHA256 計算(回退實現)
|
|
28
|
+
* @param key - 密鑰
|
|
29
|
+
* @param data - 要雜湊的數據
|
|
30
|
+
* @returns 十六進制編碼的 HMAC-SHA256 值
|
|
31
|
+
*/
|
|
32
|
+
hmacSha256(key: string, data: string): string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFI (Foreign Function Interface) 模組導出
|
|
3
|
+
* 提供原生加速層支持(CBOR 編碼/解碼、雜湊計算)
|
|
4
|
+
*/
|
|
5
|
+
export { CborFallbackDecoder, CborFallbackEncoder } from './cbor-fallback';
|
|
6
|
+
export { HashFallback } from './hash-fallback';
|
|
7
|
+
export { NativeAccelerator } from './NativeAccelerator';
|
|
8
|
+
export { NativeHasher } from './NativeHasher';
|
|
9
|
+
export type { CborAccelerator, FfiConfig, HashAccelerator, NativeAcceleratorStatus, NativeHasherStatus, } from './types';
|
|
10
|
+
export { CBOR_LENGTH_ENCODING, CBOR_MAJOR_TYPES, CBOR_SIMPLE_VALUES, } from './types';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFI (Foreign Function Interface) 類型定義
|
|
3
|
+
* 支持 bun:ffi 的原生加速層
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* CBOR 編碼/解碼加速器介面
|
|
7
|
+
* 可由原生 C 實現或 JavaScript 回退實現
|
|
8
|
+
*/
|
|
9
|
+
export interface CborAccelerator {
|
|
10
|
+
/**
|
|
11
|
+
* 將任意 JavaScript 物件編碼為 CBOR 二進制格式
|
|
12
|
+
* @param data - 要編碼的物件(支援:map、string、uint、float64、bytes、null、boolean)
|
|
13
|
+
* @returns CBOR 編碼的二進制資料
|
|
14
|
+
*/
|
|
15
|
+
encode(data: Record<string, unknown>): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* 將 CBOR 二進制格式解碼為 JavaScript 物件
|
|
18
|
+
* @param bytes - CBOR 編碼的二進制資料
|
|
19
|
+
* @returns 解碼後的物件
|
|
20
|
+
*/
|
|
21
|
+
decode(bytes: Uint8Array): Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* FFI 加速層狀態報告
|
|
25
|
+
*/
|
|
26
|
+
export interface NativeAcceleratorStatus {
|
|
27
|
+
/**
|
|
28
|
+
* 原生 FFI 加速是否可用
|
|
29
|
+
*/
|
|
30
|
+
readonly available: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 當前使用的運行時實現
|
|
33
|
+
* - 'bun-ffi': Bun C 編譯器(bun:ffi 的 cc())
|
|
34
|
+
* - 'js-fallback': 手寫 JavaScript CBOR 實現
|
|
35
|
+
* - 'cborg': npm 的 cborg 套件(已棄用,僅用於向後相容)
|
|
36
|
+
*/
|
|
37
|
+
readonly runtime: 'bun-ffi' | 'js-fallback' | 'cborg';
|
|
38
|
+
/**
|
|
39
|
+
* 運行時版本或詳細資訊
|
|
40
|
+
*/
|
|
41
|
+
readonly version: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* FFI 層配置選項
|
|
45
|
+
*/
|
|
46
|
+
export interface FfiConfig {
|
|
47
|
+
/**
|
|
48
|
+
* 啟用調試日誌
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
readonly debug?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 最大 buffer 大小(位元組)
|
|
54
|
+
* @default 1048576 (1MB)
|
|
55
|
+
*/
|
|
56
|
+
readonly maxBufferSize?: number;
|
|
57
|
+
/**
|
|
58
|
+
* 強制使用特定的加速器實現
|
|
59
|
+
* - undefined: 自動選擇(優先 bun-ffi,降級到 js-fallback)
|
|
60
|
+
* - 'bun-ffi': 只使用原生 C 實現
|
|
61
|
+
* - 'js-fallback': 只使用 JavaScript 實現
|
|
62
|
+
*/
|
|
63
|
+
readonly forceImplementation?: 'bun-ffi' | 'js-fallback';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* CBOR Major Type 常數
|
|
67
|
+
* 符合 RFC 7049 規範
|
|
68
|
+
*/
|
|
69
|
+
export declare const CBOR_MAJOR_TYPES: {
|
|
70
|
+
readonly UINT: 0;
|
|
71
|
+
readonly NEGINT: 1;
|
|
72
|
+
readonly BYTES: 2;
|
|
73
|
+
readonly TEXT: 3;
|
|
74
|
+
readonly ARRAY: 4;
|
|
75
|
+
readonly MAP: 5;
|
|
76
|
+
readonly TAG: 6;
|
|
77
|
+
readonly SIMPLE: 7;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* CBOR 簡單值常數
|
|
81
|
+
*/
|
|
82
|
+
export declare const CBOR_SIMPLE_VALUES: {
|
|
83
|
+
readonly FALSE: 20;
|
|
84
|
+
readonly TRUE: 21;
|
|
85
|
+
readonly NULL: 22;
|
|
86
|
+
readonly UNDEFINED: 23;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* CBOR 長度編碼的附加資訊
|
|
90
|
+
*/
|
|
91
|
+
export declare const CBOR_LENGTH_ENCODING: {
|
|
92
|
+
readonly SMALL_RANGE_END: 23;
|
|
93
|
+
readonly UINT8: 24;
|
|
94
|
+
readonly UINT16: 25;
|
|
95
|
+
readonly UINT32: 26;
|
|
96
|
+
readonly UINT64: 27;
|
|
97
|
+
readonly FLOAT16: 25;
|
|
98
|
+
readonly FLOAT32: 26;
|
|
99
|
+
readonly FLOAT64: 27;
|
|
100
|
+
readonly INDEFINITE: 31;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 雜湊加速器介面
|
|
104
|
+
* 可由 Bun 原生實現或 Node.js 回退實現
|
|
105
|
+
*/
|
|
106
|
+
export interface HashAccelerator {
|
|
107
|
+
/**
|
|
108
|
+
* SHA-256 雜湊計算
|
|
109
|
+
* @param input - 輸入(字串或二進制)
|
|
110
|
+
* @returns 十六進制編碼的 SHA-256 雜湊值(64 字元)
|
|
111
|
+
*/
|
|
112
|
+
sha256(input: string | Uint8Array): string;
|
|
113
|
+
/**
|
|
114
|
+
* HMAC-SHA256 計算
|
|
115
|
+
* @param key - 密鑰
|
|
116
|
+
* @param data - 要雜湊的數據
|
|
117
|
+
* @returns 十六進制編碼的 HMAC-SHA256 值(64 字元)
|
|
118
|
+
*/
|
|
119
|
+
hmacSha256(key: string, data: string): string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 雜湊加速器狀態報告
|
|
123
|
+
*/
|
|
124
|
+
export interface NativeHasherStatus {
|
|
125
|
+
/**
|
|
126
|
+
* 雜湊加速層是否可用
|
|
127
|
+
*/
|
|
128
|
+
readonly available: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* 當前使用的運行時實現
|
|
131
|
+
* - 'bun-crypto-hasher': Bun 原生 CryptoHasher(C 實現,推薦)
|
|
132
|
+
* - 'node-crypto': node:crypto 回退實現
|
|
133
|
+
*/
|
|
134
|
+
readonly runtime: 'bun-crypto-hasher' | 'node-crypto';
|
|
135
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HealthProvider - Cloud-native health checks
|
|
3
|
+
*
|
|
4
|
+
* Provides liveness and readiness probes for Kubernetes and cloud deployments
|
|
5
|
+
*
|
|
6
|
+
* @module @gravito/core/health
|
|
7
|
+
* @since 2.2.0
|
|
8
|
+
*/
|
|
9
|
+
import type { Container } from '../Container';
|
|
10
|
+
import type { PlanetCore } from '../PlanetCore';
|
|
11
|
+
import { ServiceProvider } from '../ServiceProvider';
|
|
12
|
+
/**
|
|
13
|
+
* Health check result
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export interface HealthCheckResult {
|
|
17
|
+
/** Health status */
|
|
18
|
+
status: 'healthy' | 'unhealthy';
|
|
19
|
+
/** Optional message */
|
|
20
|
+
message?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Health check function interface
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export interface HealthCheck {
|
|
27
|
+
/** Unique name for this check */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Check function that returns health status */
|
|
30
|
+
check(): Promise<HealthCheckResult>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* HealthProvider - Provides /health/liveness and /health/readiness endpoints
|
|
34
|
+
*
|
|
35
|
+
* - Liveness: Always returns 200 OK (just checks if server is running)
|
|
36
|
+
* - Readiness: Returns 200 if all checks are healthy, 503 otherwise
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare class HealthProvider extends ServiceProvider {
|
|
41
|
+
private checks;
|
|
42
|
+
register(container: Container): void;
|
|
43
|
+
/**
|
|
44
|
+
* Register a health check
|
|
45
|
+
*
|
|
46
|
+
* @param check - The health check to register
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const health = core.container.make<HealthProvider>('health')
|
|
51
|
+
* health.registerCheck({
|
|
52
|
+
* name: 'database',
|
|
53
|
+
* check: async () => {
|
|
54
|
+
* try {
|
|
55
|
+
* await db.ping()
|
|
56
|
+
* return { status: 'healthy' }
|
|
57
|
+
* } catch {
|
|
58
|
+
* return { status: 'unhealthy', message: 'DB unreachable' }
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
registerCheck(check: HealthCheck): void;
|
|
65
|
+
boot(core: PlanetCore): void;
|
|
66
|
+
}
|
|
67
|
+
export default HealthProvider;
|
|
@@ -18,6 +18,21 @@ export declare const Str: {
|
|
|
18
18
|
readonly limit: (value: string, limit: number, end?: string) => string;
|
|
19
19
|
readonly slug: (value: string, separator?: string) => string;
|
|
20
20
|
readonly uuid: () => string;
|
|
21
|
+
/**
|
|
22
|
+
* 生成 UUID v7(單調遞增,內含時間戳)。
|
|
23
|
+
*
|
|
24
|
+
* Bun 環境使用原生 Bun.randomUUIDv7() (C++ 實作)。
|
|
25
|
+
* Node.js/Deno 環境使用 RFC 9562 的 JavaScript polyfill。
|
|
26
|
+
*
|
|
27
|
+
* UUID v7 的優勢:
|
|
28
|
+
* - 資料庫主鍵天然有序 → B-tree 索引性能提升 2-10x
|
|
29
|
+
* - 可從 UUID 提取毫秒級時間戳
|
|
30
|
+
* - 仍保持全域唯一性
|
|
31
|
+
*
|
|
32
|
+
* @returns UUID v7 字串
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
readonly uuidv7: () => string;
|
|
21
36
|
readonly random: (length?: number) => string;
|
|
22
37
|
};
|
|
23
38
|
export {};
|