@gravito/radiance 1.0.3 → 1.0.5
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 +30 -7
- package/README.zh-TW.md +238 -3
- package/dist/core/src/Application.d.ts +256 -0
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +65 -0
- package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/core/src/Container.d.ts +153 -0
- package/dist/core/src/ErrorHandler.d.ts +66 -0
- package/dist/core/src/Event.d.ts +5 -0
- package/dist/core/src/EventManager.d.ts +123 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
- package/dist/core/src/GravitoServer.d.ts +28 -0
- package/dist/core/src/HookManager.d.ts +435 -0
- package/dist/core/src/Listener.d.ts +4 -0
- package/dist/core/src/Logger.d.ts +20 -0
- package/dist/core/src/PlanetCore.d.ts +402 -0
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/Route.d.ts +36 -0
- package/dist/core/src/Router.d.ts +270 -0
- package/dist/core/src/ServiceProvider.d.ts +178 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +54 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +66 -0
- package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/core/src/adapters/bun/BunWebSocketHandler.d.ts +48 -0
- package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +32 -0
- package/dist/core/src/adapters/bun/index.d.ts +7 -0
- package/dist/core/src/adapters/bun/types.d.ts +20 -0
- package/dist/core/src/adapters/types.d.ts +235 -0
- package/dist/core/src/binary/BinaryUtils.d.ts +105 -0
- package/dist/core/src/binary/index.d.ts +5 -0
- package/dist/core/src/cli/queue-commands.d.ts +6 -0
- package/dist/core/src/compat/async-local-storage.d.ts +7 -0
- package/dist/core/src/compat/crypto.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +139 -0
- package/dist/core/src/engine/FastContext.d.ts +141 -0
- package/dist/core/src/engine/Gravito.d.ts +131 -0
- package/dist/core/src/engine/MinimalContext.d.ts +102 -0
- package/dist/core/src/engine/analyzer.d.ts +113 -0
- package/dist/core/src/engine/constants.d.ts +23 -0
- package/dist/core/src/engine/index.d.ts +26 -0
- package/dist/core/src/engine/path.d.ts +26 -0
- package/dist/core/src/engine/pool.d.ts +83 -0
- package/dist/core/src/engine/types.d.ts +149 -0
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/core/src/events/BackpressureManager.d.ts +215 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +219 -0
- package/dist/core/src/events/EventBackend.d.ts +12 -0
- package/dist/core/src/events/EventOptions.d.ts +204 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +63 -0
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
- package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/core/src/events/RetryScheduler.d.ts +104 -0
- package/dist/core/src/events/WorkerPool.d.ts +98 -0
- package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/core/src/events/aggregation/types.d.ts +117 -0
- package/dist/core/src/events/index.d.ts +26 -0
- package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
- package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
- package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +332 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +24 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/queue-core.d.ts +77 -0
- package/dist/core/src/events/task-executor.d.ts +51 -0
- package/dist/core/src/events/types.d.ts +134 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
- package/dist/core/src/exceptions/HttpException.d.ts +9 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
- package/dist/core/src/exceptions/index.d.ts +7 -0
- package/dist/core/src/ffi/NativeAccelerator.d.ts +62 -0
- package/dist/core/src/ffi/NativeHasher.d.ts +139 -0
- package/dist/core/src/ffi/cbor-fallback.d.ts +96 -0
- package/dist/core/src/ffi/hash-fallback.d.ts +33 -0
- package/dist/core/src/ffi/index.d.ts +10 -0
- package/dist/core/src/ffi/types.d.ts +135 -0
- package/dist/core/src/health/HealthProvider.d.ts +67 -0
- package/dist/core/src/helpers/Arr.d.ts +19 -0
- package/dist/core/src/helpers/Str.d.ts +38 -0
- package/dist/core/src/helpers/data.d.ts +25 -0
- package/dist/core/src/helpers/errors.d.ts +34 -0
- package/dist/core/src/helpers/response.d.ts +41 -0
- package/dist/core/src/helpers.d.ts +338 -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 +51 -0
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/http/types.d.ts +395 -0
- package/dist/core/src/index.d.ts +565 -0
- package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
- package/dist/core/src/observability/contracts.d.ts +137 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +349 -0
- package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
- package/dist/core/src/reliability/index.d.ts +6 -0
- package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
- package/dist/core/src/router/RequestValidator.d.ts +20 -0
- 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 +11 -0
- package/dist/core/src/security/Encrypter.d.ts +33 -0
- package/dist/core/src/security/Hasher.d.ts +29 -0
- package/dist/core/src/testing/HttpTester.d.ts +40 -0
- package/dist/core/src/testing/TestResponse.d.ts +78 -0
- package/dist/core/src/testing/index.d.ts +2 -0
- package/dist/core/src/transpiler-utils.d.ts +170 -0
- package/dist/core/src/types/events.d.ts +94 -0
- package/dist/index.js +1 -274
- package/dist/index.js.map +3 -10
- package/dist/radiance/src/BroadcastManager.d.ts +124 -0
- package/dist/radiance/src/OrbitRadiance.d.ts +98 -0
- package/dist/radiance/src/channels/Channel.d.ts +86 -0
- package/dist/radiance/src/drivers/AblyDriver.d.ts +73 -0
- package/dist/radiance/src/drivers/BroadcastDriver.d.ts +50 -0
- package/dist/radiance/src/drivers/PusherDriver.d.ts +95 -0
- package/dist/radiance/src/drivers/RedisDriver.d.ts +83 -0
- package/dist/radiance/src/drivers/WebSocketDriver.d.ts +89 -0
- package/dist/radiance/src/index.d.ts +39 -0
- package/package.json +10 -6
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Encrypter } from '../security/Encrypter';
|
|
2
|
+
import type { GravitoContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for setting cookies
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface CookieOptions {
|
|
8
|
+
path?: string;
|
|
9
|
+
domain?: string;
|
|
10
|
+
secure?: boolean;
|
|
11
|
+
httpOnly?: boolean;
|
|
12
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
13
|
+
maxAge?: number;
|
|
14
|
+
expires?: Date;
|
|
15
|
+
encrypt?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Utility for managing cookies (request/response/encryption).
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare class CookieJar {
|
|
22
|
+
private encrypter?;
|
|
23
|
+
private queued;
|
|
24
|
+
constructor(encrypter?: Encrypter | undefined);
|
|
25
|
+
/**
|
|
26
|
+
* Parse cookies from a Cookie header string using Bun's native CookieMap
|
|
27
|
+
* @param header - The Cookie header value
|
|
28
|
+
* @returns Parsed cookies as key-value pairs
|
|
29
|
+
*/
|
|
30
|
+
static parseCookies(header: string): Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Queue a cookie to be sent with the response
|
|
33
|
+
*/
|
|
34
|
+
queue(name: string, value: string, minutes?: number, options?: CookieOptions): void;
|
|
35
|
+
/**
|
|
36
|
+
* Make a cookie that lasts "forever" (5 years)
|
|
37
|
+
*/
|
|
38
|
+
forever(name: string, value: string, options?: CookieOptions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Expire a cookie
|
|
41
|
+
*/
|
|
42
|
+
forget(name: string, options?: CookieOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Serialize a cookie to a Set-Cookie header value using Bun's native Cookie API
|
|
45
|
+
*/
|
|
46
|
+
private serializeCookie;
|
|
47
|
+
/**
|
|
48
|
+
* Attach queued cookies to the context
|
|
49
|
+
*/
|
|
50
|
+
attach(c: GravitoContext): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type CookieOptions } from './CookieJar';
|
|
2
|
+
import type { GravitoContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Get a cookie value from the request
|
|
5
|
+
* @param c - Context object
|
|
6
|
+
* @param name - Cookie name
|
|
7
|
+
* @returns Cookie value or undefined
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare function getCookie(c: GravitoContext, name: string): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Set a cookie in the response
|
|
13
|
+
* @param c - Context object
|
|
14
|
+
* @param name - Cookie name
|
|
15
|
+
* @param value - Cookie value
|
|
16
|
+
* @param options - Cookie options
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare function setCookie(c: GravitoContext, name: string, value: string, options?: CookieOptions & {
|
|
20
|
+
maxAge?: number;
|
|
21
|
+
}): void;
|
|
22
|
+
/**
|
|
23
|
+
* Delete a cookie (expire it)
|
|
24
|
+
* @param c - Context object
|
|
25
|
+
* @param name - Cookie name
|
|
26
|
+
* @param options - Cookie options (path, domain, etc.)
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function deleteCookie(c: GravitoContext, name: string, options?: CookieOptions): void;
|