@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.
Files changed (225) hide show
  1. package/README.md +26 -10
  2. package/dist/{ripple/src/OrbitRipple.d.ts → OrbitRipple.d.ts} +1 -0
  3. package/dist/{ripple/src/RippleServer.d.ts → RippleServer.d.ts} +32 -2
  4. package/dist/core/src/Application.d.ts +41 -0
  5. package/dist/core/src/ConfigManager.d.ts +39 -0
  6. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  7. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  8. package/dist/core/src/Container.d.ts +45 -0
  9. package/dist/core/src/ErrorHandler.d.ts +3 -0
  10. package/dist/core/src/HookManager.d.ts +104 -165
  11. package/dist/core/src/PlanetCore.d.ts +114 -1
  12. package/dist/core/src/RequestContext.d.ts +97 -0
  13. package/dist/core/src/Router.d.ts +32 -46
  14. package/dist/core/src/ServiceProvider.d.ts +22 -0
  15. package/dist/core/src/adapters/bun/BunContext.d.ts +10 -1
  16. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +35 -0
  17. package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
  18. package/dist/core/src/adapters/bun/RadixRouter.d.ts +1 -0
  19. package/dist/core/src/adapters/bun/index.d.ts +7 -0
  20. package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
  21. package/dist/core/src/binary/index.d.ts +5 -0
  22. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  23. package/dist/core/src/compat/async-local-storage.d.ts +7 -0
  24. package/dist/core/src/compat/crypto.d.ts +6 -0
  25. package/dist/core/src/engine/AOTRouter.d.ts +16 -1
  26. package/dist/core/src/engine/FastContext.d.ts +42 -1
  27. package/dist/core/src/engine/Gravito.d.ts +13 -19
  28. package/dist/core/src/engine/MinimalContext.d.ts +23 -0
  29. package/dist/core/src/engine/analyzer.d.ts +92 -6
  30. package/dist/core/src/engine/types.d.ts +6 -0
  31. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  32. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  33. package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
  34. package/dist/core/src/events/EventBackend.d.ts +2 -1
  35. package/dist/core/src/events/EventOptions.d.ts +99 -4
  36. package/dist/core/src/events/EventPriorityQueue.d.ts +36 -175
  37. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  38. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  39. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  40. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  41. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  42. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  43. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  44. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  45. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  46. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  47. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  48. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  49. package/dist/core/src/events/index.d.ts +18 -6
  50. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
  51. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  52. package/dist/core/src/events/observability/index.d.ts +4 -0
  53. package/dist/core/src/events/queue-core.d.ts +77 -0
  54. package/dist/core/src/events/task-executor.d.ts +51 -0
  55. package/dist/core/src/events/types.d.ts +59 -0
  56. package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
  57. package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
  58. package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
  59. package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
  60. package/dist/core/src/ffi/index.d.ts +10 -0
  61. package/dist/core/src/ffi/types.d.ts +135 -0
  62. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  63. package/dist/core/src/helpers/Str.d.ts +15 -0
  64. package/dist/core/src/hooks/ActionManager.d.ts +132 -0
  65. package/dist/core/src/hooks/AsyncDetector.d.ts +84 -0
  66. package/dist/core/src/hooks/FilterManager.d.ts +71 -0
  67. package/dist/core/src/hooks/MigrationWarner.d.ts +24 -0
  68. package/dist/core/src/hooks/dlq-operations.d.ts +60 -0
  69. package/dist/core/src/hooks/types.d.ts +107 -0
  70. package/dist/core/src/http/CookieJar.d.ts +2 -2
  71. package/dist/core/src/http/types.d.ts +43 -3
  72. package/dist/core/src/index.d.ts +504 -15
  73. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  74. package/dist/core/src/observability/contracts.d.ts +137 -0
  75. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +36 -3
  76. package/dist/core/src/runtime/adapter-bun.d.ts +12 -0
  77. package/dist/core/src/runtime/adapter-deno.d.ts +12 -0
  78. package/dist/core/src/runtime/adapter-node.d.ts +12 -0
  79. package/dist/core/src/runtime/adapter-unknown.d.ts +13 -0
  80. package/dist/core/src/runtime/archive.d.ts +17 -0
  81. package/dist/core/src/runtime/compression.d.ts +21 -0
  82. package/dist/core/src/runtime/deep-equals.d.ts +56 -0
  83. package/dist/core/src/runtime/detection.d.ts +22 -0
  84. package/dist/core/src/runtime/escape.d.ts +34 -0
  85. package/dist/core/src/runtime/index.d.ts +44 -0
  86. package/dist/core/src/runtime/markdown.d.ts +44 -0
  87. package/dist/core/src/runtime/types.d.ts +436 -0
  88. package/dist/core/src/runtime-helpers.d.ts +67 -0
  89. package/dist/core/src/runtime.d.ts +10 -118
  90. package/dist/core/src/testing/HttpTester.d.ts +1 -0
  91. package/dist/core/src/transpiler-utils.d.ts +170 -0
  92. package/dist/{ripple/src/engines → engines}/BunEngine.d.ts +11 -0
  93. package/dist/engines/UWebSocketsEngine.d.ts +97 -0
  94. package/dist/engines/WsEngine.d.ts +69 -0
  95. package/dist/{ripple/src/engines → engines}/index.d.ts +4 -0
  96. package/dist/index.js +1 -7139
  97. package/dist/index.js.map +3 -69
  98. package/dist/{ripple/src/serializers → serializers}/ISerializer.d.ts +1 -1
  99. package/dist/{ripple/src/serializers → serializers}/JsonSerializer.d.ts +1 -1
  100. package/dist/{ripple/src/serializers → serializers}/ProtobufSerializer.d.ts +6 -3
  101. package/dist/{ripple/src/types.d.ts → types.d.ts} +11 -0
  102. package/package.json +7 -2
  103. package/dist/atlas/src/DB.d.ts +0 -301
  104. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  105. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  106. package/dist/atlas/src/config/index.d.ts +0 -7
  107. package/dist/atlas/src/config/loadConfig.d.ts +0 -48
  108. package/dist/atlas/src/connection/Connection.d.ts +0 -108
  109. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -111
  110. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  111. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  112. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  113. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -66
  114. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -83
  115. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  116. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  117. package/dist/atlas/src/drivers/types.d.ts +0 -260
  118. package/dist/atlas/src/errors/index.d.ts +0 -45
  119. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  120. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  121. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  122. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  123. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  124. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  125. package/dist/atlas/src/index.d.ts +0 -67
  126. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  127. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  128. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  129. package/dist/atlas/src/migration/index.d.ts +0 -6
  130. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -11
  131. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  132. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  133. package/dist/atlas/src/observability/index.d.ts +0 -9
  134. package/dist/atlas/src/orm/index.d.ts +0 -5
  135. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  136. package/dist/atlas/src/orm/model/Model.d.ts +0 -449
  137. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  138. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -136
  139. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  140. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -87
  141. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  142. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  143. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  144. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  145. package/dist/atlas/src/orm/model/decorators.d.ts +0 -109
  146. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  147. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  148. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  149. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  150. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -123
  151. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  152. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  153. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  154. package/dist/atlas/src/query/Expression.d.ts +0 -60
  155. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  156. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -573
  157. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  158. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  159. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  160. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  161. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  162. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  163. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  164. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  165. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  166. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  167. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  168. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  169. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  170. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  171. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  172. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  173. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  174. package/dist/atlas/src/schema/index.d.ts +0 -8
  175. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  176. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  177. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  178. package/dist/atlas/src/seed/index.d.ts +0 -6
  179. package/dist/atlas/src/types/index.d.ts +0 -1100
  180. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  181. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -171
  182. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  183. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  184. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  185. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  186. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  187. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  188. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  189. package/dist/core/src/instrumentation/index.d.ts +0 -35
  190. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  191. package/dist/core/src/instrumentation/types.d.ts +0 -182
  192. package/dist/photon/src/index.d.ts +0 -84
  193. package/dist/photon/src/middleware/binary.d.ts +0 -31
  194. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  195. package/dist/photon/src/middleware/ratelimit.d.ts +0 -157
  196. package/dist/photon/src/openapi.d.ts +0 -19
  197. /package/dist/{ripple/src/channels → channels}/Channel.d.ts +0 -0
  198. /package/dist/{ripple/src/channels → channels}/ChannelManager.d.ts +0 -0
  199. /package/dist/{ripple/src/channels → channels}/index.d.ts +0 -0
  200. /package/dist/{ripple/src/drivers → drivers}/LocalDriver.d.ts +0 -0
  201. /package/dist/{ripple/src/drivers → drivers}/NATSDriver.d.ts +0 -0
  202. /package/dist/{ripple/src/drivers → drivers}/RedisDriver.d.ts +0 -0
  203. /package/dist/{ripple/src/drivers → drivers}/index.d.ts +0 -0
  204. /package/dist/{ripple/src/engines → engines}/IRippleEngine.d.ts +0 -0
  205. /package/dist/{ripple/src/errors → errors}/RippleError.d.ts +0 -0
  206. /package/dist/{ripple/src/errors → errors}/index.d.ts +0 -0
  207. /package/dist/{ripple/src/events → events}/BroadcastEvent.d.ts +0 -0
  208. /package/dist/{ripple/src/events → events}/BroadcastManager.d.ts +0 -0
  209. /package/dist/{ripple/src/events → events}/Broadcaster.d.ts +0 -0
  210. /package/dist/{ripple/src/events → events}/index.d.ts +0 -0
  211. /package/dist/{ripple/src/health → health}/HealthChecker.d.ts +0 -0
  212. /package/dist/{ripple/src/health → health}/index.d.ts +0 -0
  213. /package/dist/{ripple/src/index.d.ts → index.d.ts} +0 -0
  214. /package/dist/{ripple/src/logging → logging}/Logger.d.ts +0 -0
  215. /package/dist/{ripple/src/logging → logging}/index.d.ts +0 -0
  216. /package/dist/{ripple/src/middleware → middleware}/InterceptorManager.d.ts +0 -0
  217. /package/dist/{ripple/src/observability → observability}/RippleMetrics.d.ts +0 -0
  218. /package/dist/{ripple/src/reliability → reliability}/AckManager.d.ts +0 -0
  219. /package/dist/{ripple/src/serializers → serializers}/index.d.ts +0 -0
  220. /package/dist/{ripple/src/tracking → tracking}/ConnectionTracker.d.ts +0 -0
  221. /package/dist/{ripple/src/tracking → tracking}/SessionManager.d.ts +0 -0
  222. /package/dist/{ripple/src/tracking → tracking}/index.d.ts +0 -0
  223. /package/dist/{ripple/src/utils → utils}/MessageSerializer.d.ts +0 -0
  224. /package/dist/{ripple/src/utils → utils}/TokenBucket.d.ts +0 -0
  225. /package/dist/{ripple/src/utils → utils}/index.d.ts +0 -0
@@ -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
+ }>;
@@ -0,0 +1,107 @@
1
+ import type { CircuitBreakerOptions } from '../events/CircuitBreaker';
2
+ import type { EventBackend } from '../events/EventBackend';
3
+ import type { EventQueueConfig } from '../events/EventPriorityQueue';
4
+ /**
5
+ * Callback function for filters (transforms values).
6
+ * @public
7
+ */
8
+ export type FilterCallback<T = unknown> = (value: T, ...args: unknown[]) => Promise<T> | T;
9
+ /**
10
+ * Callback function for actions (side effects).
11
+ * @public
12
+ */
13
+ export type ActionCallback<TArgs = unknown> = (args: TArgs) => Promise<void> | void;
14
+ /**
15
+ * Options for listener registration.
16
+ * @public
17
+ */
18
+ export interface ListenerOptions {
19
+ /**
20
+ * Explicitly specify the listener type.
21
+ * - 'sync': Force synchronous dispatch for this listener
22
+ * - 'async': Force asynchronous dispatch for this listener
23
+ * - 'auto': Auto-detect based on function signature (default)
24
+ * @default 'auto'
25
+ */
26
+ type?: 'sync' | 'async' | 'auto';
27
+ /**
28
+ * Circuit breaker configuration for this listener.
29
+ */
30
+ circuitBreaker?: CircuitBreakerOptions;
31
+ }
32
+ /**
33
+ * Information about a registered listener.
34
+ * @public
35
+ */
36
+ export interface ListenerInfo {
37
+ /**
38
+ * The callback function.
39
+ */
40
+ callback: ActionCallback;
41
+ /**
42
+ * Whether the listener is considered async.
43
+ */
44
+ isAsync: boolean;
45
+ /**
46
+ * The explicit type override, if any.
47
+ */
48
+ typeOverride?: 'sync' | 'async' | 'auto';
49
+ }
50
+ /**
51
+ * Configuration for HookManager.
52
+ * @public
53
+ */
54
+ export interface HookManagerConfig {
55
+ /**
56
+ * Enable async event dispatch by default.
57
+ * When true, doAction() will automatically use async dispatch if any listener is async.
58
+ * @default false
59
+ */
60
+ asyncByDefault?: boolean;
61
+ /**
62
+ * Migration mode for backward compatibility.
63
+ * - 'sync': All events use synchronous dispatch (legacy mode)
64
+ * - 'hybrid': Auto-detect and use async for async listeners (recommended)
65
+ * - 'async': All events use async dispatch (future mode)
66
+ * @default 'sync'
67
+ */
68
+ migrationMode?: 'sync' | 'hybrid' | 'async';
69
+ /**
70
+ * Enable deprecation warnings for synchronous event dispatch.
71
+ * @default false
72
+ */
73
+ showDeprecationWarnings?: boolean;
74
+ /**
75
+ * Enable Dead Letter Queue for failed events.
76
+ * @default true
77
+ */
78
+ enableDLQ?: boolean;
79
+ /**
80
+ * Configuration for the event priority queue (Backpressure).
81
+ */
82
+ queue?: EventQueueConfig;
83
+ /**
84
+ * Custom event backend for distributed processing.
85
+ */
86
+ backend?: EventBackend;
87
+ /**
88
+ * Database connection for persistent DLQ (optional).
89
+ * If provided, failed events after max retries will be persisted to database.
90
+ */
91
+ db?: any;
92
+ /**
93
+ * Enable persistent DLQ for failed events (requires db).
94
+ * @default false
95
+ */
96
+ enablePersistentDLQ?: boolean;
97
+ /**
98
+ * Message Queue Bridge for distributed event processing via Bull Queue.
99
+ * When provided, enables dispatchQueued() method for routing events to Redis-backed queue.
100
+ */
101
+ messageQueueBridge?: any;
102
+ /**
103
+ * Event aggregation configuration (FS-102).
104
+ * Enables deduplication and micro-batching for improved throughput.
105
+ */
106
+ aggregation?: any;
107
+ }
@@ -23,7 +23,7 @@ export declare class CookieJar {
23
23
  private queued;
24
24
  constructor(encrypter?: Encrypter | undefined);
25
25
  /**
26
- * Parse cookies from a Cookie header string
26
+ * Parse cookies from a Cookie header string using Bun's native CookieMap
27
27
  * @param header - The Cookie header value
28
28
  * @returns Parsed cookies as key-value pairs
29
29
  */
@@ -41,7 +41,7 @@ export declare class CookieJar {
41
41
  */
42
42
  forget(name: string, options?: CookieOptions): void;
43
43
  /**
44
- * Serialize a cookie to a Set-Cookie header value
44
+ * Serialize a cookie to a Set-Cookie header value using Bun's native Cookie API
45
45
  */
46
46
  private serializeCookie;
47
47
  /**
@@ -106,6 +106,11 @@ export interface GravitoRequest {
106
106
  * ```
107
107
  */
108
108
  readonly routePattern?: string;
109
+ /**
110
+ * Alias for routePattern (for Hono/Express compatibility)
111
+ * @deprecated Use `routePattern` instead
112
+ */
113
+ readonly routePath?: string;
109
114
  /**
110
115
  * Get a route parameter value
111
116
  * @param name - Parameter name (e.g., 'id' for route '/users/:id')
@@ -164,6 +169,12 @@ export interface GravitoRequest {
164
169
  * @throws {Error} If validation was not performed for this target
165
170
  */
166
171
  valid<T = unknown>(target: ValidationTarget): T;
172
+ /**
173
+ * Store validated data for a specific source
174
+ * @param target - The validation target
175
+ * @param data - The validated data to store
176
+ */
177
+ setValidated(target: ValidationTarget, data: unknown): void;
167
178
  }
168
179
  /**
169
180
  * Options for request forwarding (Proxy)
@@ -199,6 +210,17 @@ export interface ProxyOptions {
199
210
  export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
200
211
  /** The incoming request */
201
212
  readonly req: GravitoRequest;
213
+ /**
214
+ * The response object (for middleware introspection).
215
+ * Middleware can read response headers and status, or mutate the response.
216
+ *
217
+ * @remarks
218
+ * This property is mutable, allowing middleware to replace the response object.
219
+ * Example: `c.res = new Response(...)`
220
+ *
221
+ * May be undefined until a handler creates a response.
222
+ */
223
+ res?: Response;
202
224
  /**
203
225
  * Send a JSON response
204
226
  * @param data - Data to serialize as JSON
@@ -312,11 +334,30 @@ export interface GravitoContext<V extends GravitoVariables = GravitoVariables> {
312
334
  * ```
313
335
  */
314
336
  readonly native: unknown;
337
+ /**
338
+ * Access the RequestScopeManager for this request
339
+ * Services resolved through this manager are scoped to the HTTP request lifetime.
340
+ */
341
+ requestScope(): any;
342
+ /**
343
+ * Resolve or create a request-scoped service
344
+ *
345
+ * @param key - Service key (string or symbol)
346
+ * @param factory - Factory function to create the service if not cached
347
+ * @returns The cached or newly created service instance
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * // Subsequent calls in the same request return the same instance
352
+ * const cache = ctx.scoped('product:cache', () => new RequestProductCache())
353
+ * ```
354
+ */
355
+ scoped<T>(key: string | symbol, factory: () => T): T;
315
356
  }
316
357
  /**
317
358
  * Next function for middleware chain
318
359
  */
319
- export type GravitoNext = () => Promise<Response | undefined>;
360
+ export type GravitoNext = () => Promise<void>;
320
361
  /**
321
362
  * GravitoHandler - Standard route handler type
322
363
  *
@@ -340,11 +381,10 @@ export type GravitoHandler<V extends GravitoVariables = GravitoVariables> = (ctx
340
381
  * const logger: GravitoMiddleware = async (ctx, next) => {
341
382
  * console.log(`${ctx.req.method} ${ctx.req.path}`)
342
383
  * await next()
343
- * return undefined
344
384
  * }
345
385
  * ```
346
386
  */
347
- export type GravitoMiddleware<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>, next: GravitoNext) => Response | undefined | Promise<Response | undefined | undefined>;
387
+ export type GravitoMiddleware<V extends GravitoVariables = GravitoVariables> = (ctx: GravitoContext<V>, next: GravitoNext) => Response | void | Promise<Response | void>;
348
388
  /**
349
389
  * Error handler type
350
390
  */