@gravito/ripple 4.0.1 → 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 -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 +25 -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/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/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/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/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}/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}/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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ActionCallback } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 負責偵測 callback 函數是否為非同步(async)。
|
|
4
|
+
*
|
|
5
|
+
* 提供靜態偵測(透過函數簽名)和運行時偵測(透過執行函數)兩種方式,
|
|
6
|
+
* 並包含快取機制以提升重複偵測的性能。
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class AsyncDetector {
|
|
11
|
+
/**
|
|
12
|
+
* 快取非同步偵測結果(WeakMap 以自動垃圾回收)。
|
|
13
|
+
*/
|
|
14
|
+
private asyncDetectionCache;
|
|
15
|
+
/**
|
|
16
|
+
* 快取中的項目計數(供測試/偵錯使用)。
|
|
17
|
+
*/
|
|
18
|
+
private asyncDetectionCacheCount;
|
|
19
|
+
/**
|
|
20
|
+
* 儲存 listener type override(callback -> type)。
|
|
21
|
+
*/
|
|
22
|
+
private listenerTypeOverrides;
|
|
23
|
+
/**
|
|
24
|
+
* 設定 listener 的 type override。
|
|
25
|
+
*
|
|
26
|
+
* @param callback - 目標 callback
|
|
27
|
+
* @param type - Type override 值
|
|
28
|
+
*/
|
|
29
|
+
setTypeOverride(callback: ActionCallback, type: 'sync' | 'async' | 'auto'): void;
|
|
30
|
+
/**
|
|
31
|
+
* 取得 listener 的 type override。
|
|
32
|
+
*
|
|
33
|
+
* @param callback - 目標 callback
|
|
34
|
+
* @returns Type override 或 undefined
|
|
35
|
+
*/
|
|
36
|
+
getTypeOverride(callback: ActionCallback): 'sync' | 'async' | 'auto' | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a callback is an async function (with caching).
|
|
39
|
+
*
|
|
40
|
+
* Detection methods:
|
|
41
|
+
* 1. Check cache first
|
|
42
|
+
* 2. Check type override
|
|
43
|
+
* 3. Check constructor.name === 'AsyncFunction'
|
|
44
|
+
* 4. Fallback: Check function string representation
|
|
45
|
+
*
|
|
46
|
+
* @param callback - The callback to check
|
|
47
|
+
* @returns True if the callback is async
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
isAsyncListener(callback: ActionCallback): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Check if a listener is effectively async (considering type override).
|
|
53
|
+
*
|
|
54
|
+
* @param callback - The callback to check
|
|
55
|
+
* @returns True if the listener should be treated as async
|
|
56
|
+
*/
|
|
57
|
+
isEffectivelyAsync(callback: ActionCallback): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Runtime detection for functions that return Promises but aren't declared async.
|
|
60
|
+
*
|
|
61
|
+
* 此方法會實際執行 callback 來檢查是否回傳 Promise,請謹慎使用。
|
|
62
|
+
*
|
|
63
|
+
* @param callback - The callback to check
|
|
64
|
+
* @param testArgs - Arguments to pass to the callback for testing
|
|
65
|
+
* @returns True if the callback returns a Promise
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
isAsyncListenerRuntime<TArgs = unknown>(callback: ActionCallback<TArgs>, testArgs: TArgs): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the size of the async detection cache (for testing/debugging).
|
|
71
|
+
*
|
|
72
|
+
* @returns Number of cached detection results
|
|
73
|
+
*/
|
|
74
|
+
getCacheSize(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Clear the async detection cache.
|
|
77
|
+
*/
|
|
78
|
+
clearCache(): void;
|
|
79
|
+
/**
|
|
80
|
+
* 快取非同步偵測結果。
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
private cacheResult;
|
|
84
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { FilterCallback } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 管理 filter hook 的登記與執行。
|
|
4
|
+
*
|
|
5
|
+
* Filter hook 用於轉換數值:每個 callback 接收前一個 callback 的回傳值,
|
|
6
|
+
* 並返回新的轉換後數值。所有 callback 按登記順序依次執行。
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class FilterManager {
|
|
11
|
+
/**
|
|
12
|
+
* 儲存所有已登記的 filter callbacks。
|
|
13
|
+
* Map key 為 hook 名稱,value 為 callback 陣列。
|
|
14
|
+
*/
|
|
15
|
+
private filters;
|
|
16
|
+
/**
|
|
17
|
+
* Register a filter hook.
|
|
18
|
+
*
|
|
19
|
+
* Filters are used to transform a value (input/output) through a chain of
|
|
20
|
+
* callbacks. Each callback must return the modified value.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The type of value being filtered.
|
|
23
|
+
* @param hook - The unique name of the hook.
|
|
24
|
+
* @param callback - The callback function to execute.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* filterManager.addFilter('content', async (content: string) => {
|
|
29
|
+
* return content.toUpperCase()
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
addFilter<T = unknown>(hook: string, callback: FilterCallback<T>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Apply all registered filters sequentially.
|
|
36
|
+
*
|
|
37
|
+
* Each callback receives the previous callback's return value.
|
|
38
|
+
*
|
|
39
|
+
* @template T - The type of value being filtered.
|
|
40
|
+
* @param hook - The name of the hook.
|
|
41
|
+
* @param initialValue - The initial value to filter.
|
|
42
|
+
* @param args - Additional arguments to pass to the callbacks.
|
|
43
|
+
* @returns The final filtered value.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const content = await filterManager.applyFilters('content', 'hello world')
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
applyFilters<T = unknown>(hook: string, initialValue: T, ...args: unknown[]): Promise<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if any filters are registered for a hook.
|
|
53
|
+
*
|
|
54
|
+
* @param hook - Hook name
|
|
55
|
+
* @returns True if at least one filter is registered
|
|
56
|
+
*/
|
|
57
|
+
hasFilters(hook: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get count of registered filters for a hook.
|
|
60
|
+
*
|
|
61
|
+
* @param hook - Hook name
|
|
62
|
+
* @returns Number of registered filters
|
|
63
|
+
*/
|
|
64
|
+
getFilterCount(hook: string): number;
|
|
65
|
+
/**
|
|
66
|
+
* Remove all filters for a specific hook.
|
|
67
|
+
*
|
|
68
|
+
* @param hook - Hook name
|
|
69
|
+
*/
|
|
70
|
+
removeFilters(hook: string): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration warning manager for deprecation warnings.
|
|
3
|
+
*
|
|
4
|
+
* 管理遷移警告訊息,支援透過環境變數抑制特定事件的警告。
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class MigrationWarner {
|
|
9
|
+
private suppressedWarnings;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* 發出遷移警告訊息。
|
|
13
|
+
*
|
|
14
|
+
* @param eventName - 事件名稱
|
|
15
|
+
* @param message - 警告訊息
|
|
16
|
+
*/
|
|
17
|
+
warn(eventName: string, message: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* 抑制特定事件的遷移警告。
|
|
20
|
+
*
|
|
21
|
+
* @param eventName - 要抑制警告的事件名稱
|
|
22
|
+
*/
|
|
23
|
+
suppress(eventName: string): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DeadLetterQueue } from '../events/DeadLetterQueue';
|
|
2
|
+
import type { EventOptions } from '../events/EventOptions';
|
|
3
|
+
import type { DeadLetterQueueManager } from '../reliability/DeadLetterQueueManager';
|
|
4
|
+
/**
|
|
5
|
+
* DLQ 操作輔助函式模組。
|
|
6
|
+
*
|
|
7
|
+
* 提取自 HookManager 的 DLQ 管理邏輯,以降低 HookManager 複雜度。
|
|
8
|
+
* 這些函式接受所需依賴作為參數,便於測試與重用。
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* 重新加入單一 DLQ 項目到事件佇列。
|
|
14
|
+
*
|
|
15
|
+
* @param dlqEntryId - DLQ 項目 ID
|
|
16
|
+
* @param dlq - 記憶體內 DLQ 實例
|
|
17
|
+
* @param requeue - 重新加入佇列的回調函式
|
|
18
|
+
* @returns 是否成功重新加入
|
|
19
|
+
*/
|
|
20
|
+
export declare function requeueDLQEntry(dlqEntryId: string, dlq: DeadLetterQueue, requeue: (eventName: string, payload: unknown, options: EventOptions) => Promise<void>): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* 批次重新加入指定事件名稱的所有 DLQ 項目。
|
|
23
|
+
*
|
|
24
|
+
* @param eventName - 事件名稱
|
|
25
|
+
* @param dlq - 記憶體內 DLQ 實例
|
|
26
|
+
* @param requeue - 重新加入佇列的回調函式
|
|
27
|
+
* @returns 成功重新加入的項目數
|
|
28
|
+
*/
|
|
29
|
+
export declare function requeueDLQBatch(eventName: string, dlq: DeadLetterQueue, requeue: (entryId: string) => Promise<boolean>): Promise<number>;
|
|
30
|
+
/**
|
|
31
|
+
* 建立 EventPriorityQueue 持久化 DLQ 處理器。
|
|
32
|
+
*
|
|
33
|
+
* @param persistentDlqManager - 持久化 DLQ 管理器
|
|
34
|
+
* @returns 持久化 DLQ 處理器函式
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPersistentDLQHandler(persistentDlqManager: DeadLetterQueueManager): (hook: string, args: unknown, options: EventOptions, error: Error, retryCount: number, _firstFailedAt: number) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* 重新加入持久化 DLQ 單一項目到事件佇列。
|
|
39
|
+
*
|
|
40
|
+
* @param dlqId - 持久化 DLQ 項目 UUID
|
|
41
|
+
* @param persistentDlqManager - 持久化 DLQ 管理器
|
|
42
|
+
* @param doActionAsync - 重新加入佇列的回調函式
|
|
43
|
+
* @returns 是否成功重新加入
|
|
44
|
+
*/
|
|
45
|
+
export declare function requeuePersistentDLQEntry(dlqId: string, persistentDlqManager: DeadLetterQueueManager, doActionAsync: (event: string, args: unknown, options: EventOptions) => Promise<void>): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* 批次重新加入持久化 DLQ 項目。
|
|
48
|
+
*
|
|
49
|
+
* @param filter - 過濾條件
|
|
50
|
+
* @param persistentDlqManager - 持久化 DLQ 管理器
|
|
51
|
+
* @returns 批次操作結果統計
|
|
52
|
+
*/
|
|
53
|
+
export declare function requeuePersistentDLQBatch(filter: {
|
|
54
|
+
eventName?: string;
|
|
55
|
+
status?: 'pending' | 'requeued' | 'resolved' | 'abandoned';
|
|
56
|
+
} | undefined, persistentDlqManager: DeadLetterQueueManager): Promise<{
|
|
57
|
+
total: number;
|
|
58
|
+
succeeded: number;
|
|
59
|
+
failed: number;
|
|
60
|
+
}>;
|