@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,7 +1,17 @@
|
|
|
1
1
|
export * from './AuthenticationException';
|
|
2
|
+
export * from './AuthException';
|
|
2
3
|
export * from './AuthorizationException';
|
|
4
|
+
export * from './CacheException';
|
|
3
5
|
export * from './CircularDependencyException';
|
|
6
|
+
export * from './ConfigurationException';
|
|
7
|
+
export * from './DatabaseException';
|
|
8
|
+
export * from './DomainException';
|
|
4
9
|
export * from './GravitoException';
|
|
5
10
|
export * from './HttpException';
|
|
11
|
+
export * from './InfrastructureException';
|
|
6
12
|
export * from './ModelNotFoundException';
|
|
13
|
+
export * from './QueueException';
|
|
14
|
+
export * from './StorageException';
|
|
15
|
+
export * from './StreamException';
|
|
16
|
+
export * from './SystemException';
|
|
7
17
|
export * from './ValidationException';
|
|
@@ -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
|
+
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { EventBackend } from '../events/EventBackend';
|
|
2
|
+
import type { EventOptions } from '../events/EventOptions';
|
|
3
|
+
import type { AsyncDetector } from './AsyncDetector';
|
|
4
|
+
import type { MigrationWarner } from './MigrationWarner';
|
|
5
|
+
import type { ActionCallback, HookManagerConfig, ListenerInfo, ListenerOptions } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* 管理 action hook 的登記與執行。
|
|
8
|
+
*
|
|
9
|
+
* Action hook 用於觸發副作用(例如發送 email、記錄日誌)。
|
|
10
|
+
* 支援同步和非同步執行模式,以及透過 EventPriorityQueue 的優先級佇列處理。
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare class ActionManager {
|
|
15
|
+
/**
|
|
16
|
+
* 儲存所有已登記的 action callbacks。
|
|
17
|
+
*/
|
|
18
|
+
private actions;
|
|
19
|
+
private backend;
|
|
20
|
+
private idempotencyCache;
|
|
21
|
+
private config;
|
|
22
|
+
private asyncDetector;
|
|
23
|
+
private migrationWarner;
|
|
24
|
+
private aggregationManager?;
|
|
25
|
+
constructor(backend: EventBackend, config: HookManagerConfig, asyncDetector: AsyncDetector, migrationWarner: MigrationWarner);
|
|
26
|
+
/**
|
|
27
|
+
* 更新設定。
|
|
28
|
+
*/
|
|
29
|
+
updateConfig(config: HookManagerConfig): void;
|
|
30
|
+
/**
|
|
31
|
+
* 更新 backend。
|
|
32
|
+
*/
|
|
33
|
+
setBackend(backend: EventBackend): void;
|
|
34
|
+
/**
|
|
35
|
+
* Register an action hook.
|
|
36
|
+
*
|
|
37
|
+
* Actions are used to trigger side effects (e.g., logging, sending emails)
|
|
38
|
+
* at specific points in the application lifecycle.
|
|
39
|
+
*
|
|
40
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
41
|
+
* @param hook - The unique name of the hook.
|
|
42
|
+
* @param callback - The callback function to execute.
|
|
43
|
+
* @param options - Optional listener options (type override, circuit breaker).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* actionManager.addAction('user_registered', async (user: User) => {
|
|
48
|
+
* await sendWelcomeEmail(user)
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
addAction<TArgs = unknown>(hook: string, callback: ActionCallback<TArgs>, options?: ListenerOptions): void;
|
|
53
|
+
/**
|
|
54
|
+
* 判斷是否需要使用非同步 dispatch,並在需要時發出遷移警告。
|
|
55
|
+
*
|
|
56
|
+
* 此方法僅判斷 dispatch 模式和發出警告,不執行實際的 dispatch。
|
|
57
|
+
* 實際執行由 HookManager.doAction 負責,以確保 ObservableHookManager 等子類別
|
|
58
|
+
* 的多型覆寫(override)能正確攔截 doActionSync / doActionAsync 呼叫。
|
|
59
|
+
*
|
|
60
|
+
* @param hook - Hook name
|
|
61
|
+
* @param args - Event args (unused here, kept for API consistency)
|
|
62
|
+
* @param options - Event options
|
|
63
|
+
* @returns 'async' if async dispatch should be used, 'sync' otherwise
|
|
64
|
+
*/
|
|
65
|
+
resolveDispatchMode<TArgs = unknown>(hook: string, _args: TArgs, options?: EventOptions): 'async' | 'sync';
|
|
66
|
+
/**
|
|
67
|
+
* Run all registered actions synchronously (legacy mode).
|
|
68
|
+
*
|
|
69
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
70
|
+
* @param hook - The name of the hook.
|
|
71
|
+
* @param args - The arguments to pass to the callbacks.
|
|
72
|
+
*/
|
|
73
|
+
doActionSync<TArgs = unknown>(hook: string, args: TArgs): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Run all registered actions asynchronously via priority queue.
|
|
76
|
+
*
|
|
77
|
+
* 透過 EventPriorityQueue 進行非同步 dispatch,支援:
|
|
78
|
+
* - 優先級處理(high > normal > low)
|
|
79
|
+
* - 超時處理
|
|
80
|
+
* - 順序保證(strict、partition、none)
|
|
81
|
+
* - 冪等性
|
|
82
|
+
*
|
|
83
|
+
* @template TArgs - The type of arguments passed to the action.
|
|
84
|
+
* @param hook - The name of the hook.
|
|
85
|
+
* @param args - The arguments to pass to the callbacks.
|
|
86
|
+
* @param options - Event options for async dispatch.
|
|
87
|
+
*/
|
|
88
|
+
doActionAsync<TArgs = unknown>(hook: string, args: TArgs, options?: EventOptions): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Determine if async dispatch should be used.
|
|
91
|
+
*
|
|
92
|
+
* @param callbacks - Callbacks to check
|
|
93
|
+
* @param options - Event options
|
|
94
|
+
* @returns True if async dispatch should be used
|
|
95
|
+
*/
|
|
96
|
+
shouldUseAsyncDispatch(callbacks: ActionCallback[], options?: EventOptions): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Determine the dispatch mode for an event.
|
|
99
|
+
*
|
|
100
|
+
* @param hook - Hook name
|
|
101
|
+
* @param options - Optional event options
|
|
102
|
+
* @returns The dispatch mode: 'sync' or 'async'
|
|
103
|
+
*/
|
|
104
|
+
detectMode(hook: string, options?: EventOptions): 'sync' | 'async';
|
|
105
|
+
/**
|
|
106
|
+
* Check if any listener for a hook is async (including type overrides).
|
|
107
|
+
*
|
|
108
|
+
* @param hook - Hook name
|
|
109
|
+
* @returns True if any listener is async
|
|
110
|
+
*/
|
|
111
|
+
hasAsyncListeners(hook: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Get detailed information about all listeners for a hook.
|
|
114
|
+
*
|
|
115
|
+
* @param hook - Hook name
|
|
116
|
+
* @returns Array of listener info objects
|
|
117
|
+
*/
|
|
118
|
+
getListenerInfo(hook: string): ListenerInfo[];
|
|
119
|
+
/**
|
|
120
|
+
* Get all registered listeners for a hook.
|
|
121
|
+
*
|
|
122
|
+
* @param hook - Hook name
|
|
123
|
+
* @returns Array of callbacks
|
|
124
|
+
*/
|
|
125
|
+
getListeners(hook: string): ActionCallback[];
|
|
126
|
+
/**
|
|
127
|
+
* Remove all listeners for a specific action hook.
|
|
128
|
+
*
|
|
129
|
+
* @param hook - Hook name
|
|
130
|
+
*/
|
|
131
|
+
removeAction(hook: string): void;
|
|
132
|
+
}
|